Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 8 additions & 70 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,128 +14,66 @@ jobs:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository

steps:
- name: Checkout alphafi-sdk-js
- name: Checkout
uses: actions/checkout@v4
with:
path: alphafi-sdk-js
token: ${{ secrets.GH_PAT }}

- name: Checkout alphafi-sdk dependency
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/alphafi-sdk
ref: main
path: alphafi-sdk
token: ${{ secrets.GH_PAT }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: alphafi-sdk-js/package-lock.json

- name: Install alphafi-sdk dependencies
run: npm ci
working-directory: alphafi-sdk

- name: Install alphafi-sdk-js dependencies
- name: Install dependencies
run: npm ci
working-directory: alphafi-sdk-js

- name: Run linter
run: npm run lint
working-directory: alphafi-sdk-js

test:
name: test
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository

steps:
- name: Checkout alphafi-sdk-js
- name: Checkout
uses: actions/checkout@v4
with:
path: alphafi-sdk-js
token: ${{ secrets.GH_PAT }}

- name: Checkout alphafi-sdk dependency
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/alphafi-sdk
ref: main
path: alphafi-sdk
token: ${{ secrets.GH_PAT }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: alphafi-sdk-js/package-lock.json

- name: Install alphafi-sdk dependencies
run: npm ci
working-directory: alphafi-sdk

- name: Build alphafi-sdk
run: npm run build
working-directory: alphafi-sdk

- name: Install alphafi-sdk-js dependencies
- name: Install dependencies
run: npm ci
working-directory: alphafi-sdk-js

- name: Run tests
run: npm run test -- --passWithNoTests
working-directory: alphafi-sdk-js

build:
name: build
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository

steps:
- name: Checkout alphafi-sdk-js
- name: Checkout
uses: actions/checkout@v4
with:
path: alphafi-sdk-js
token: ${{ secrets.GH_PAT }}

- name: Checkout alphafi-sdk dependency
uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/alphafi-sdk
ref: main
path: alphafi-sdk
token: ${{ secrets.GH_PAT }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
cache-dependency-path: alphafi-sdk-js/package-lock.json

- name: Install alphafi-sdk dependencies
run: npm ci
working-directory: alphafi-sdk

- name: Build alphafi-sdk
run: npm run build
working-directory: alphafi-sdk

- name: Install alphafi-sdk-js dependencies
- name: Install dependencies
run: npm ci
working-directory: alphafi-sdk-js

- name: Build application
- name: Build
run: npm run build
working-directory: alphafi-sdk-js

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: alphafi-sdk-js/dist/
path: dist/
retention-days: 7
32 changes: 18 additions & 14 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ export class AlphaFiSDK {
const strategy = await this.protocol.getSinglePoolStrategy(poolId);
return strategy.getData();
}
async updatePool(poolId: string): Promise<Transaction> {
async updatePool(poolId: string, existingTx?: Transaction): Promise<Transaction> {
const strategy = (await this.protocol.getSinglePoolStrategy(
poolId,
)) as SingleAssetLoopingStrategy;
const tx = new Transaction();
const tx = existingTx ?? new Transaction();
return strategy.updatePool(tx);
}
/**
Expand Down Expand Up @@ -130,7 +130,7 @@ export class AlphaFiSDK {
throw new Error(`Pool with ID ${options.poolId} not found`);
}

const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = await this.portfolio.getPoolStrategy(options.address, options.poolId);
await strategy.deposit(tx, options);
return tx;
Expand Down Expand Up @@ -161,7 +161,7 @@ export class AlphaFiSDK {
* @returns Transaction object ready for signing and execution
*/
async withdraw(options: WithdrawOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = await this.portfolio.getPoolStrategy(options.address, options.poolId);
await strategy.withdraw(tx, options);
return tx;
Expand All @@ -175,7 +175,7 @@ export class AlphaFiSDK {
* @returns Transaction to create withdrawal ticket
*/
async initiateWithdrawAlpha(options: WithdrawOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = (await this.portfolio.getPoolStrategy(
options.address,
'0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8',
Expand All @@ -191,7 +191,7 @@ export class AlphaFiSDK {
* @returns Transaction to claim the withdrawn ALPHA tokens
*/
async claimWithdrawAlpha(options: ClaimWithdrawAlphaOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = (await this.portfolio.getPoolStrategy(
options.address,
'0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8',
Expand All @@ -207,7 +207,7 @@ export class AlphaFiSDK {
* @returns Transaction to claim the withdrawn tokens
*/
async claimWithdrawSlush(options: ClaimWithdrawSlushOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = (await this.portfolio.getPoolStrategy(
options.address,
options.poolId,
Expand All @@ -223,7 +223,7 @@ export class AlphaFiSDK {
* @returns Transaction to cancel the withdrawal
*/
async cancelWithdrawSlush(options: CancelWithdrawSlushOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = (await this.portfolio.getPoolStrategy(
options.address,
options.poolId,
Expand All @@ -239,7 +239,7 @@ export class AlphaFiSDK {
* @returns Transaction to claim airdrop rewards
*/
async claimAirdrop(options: ClaimAirdropOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const strategy = (await this.portfolio.getPoolStrategy(
options.address,
'0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8',
Expand All @@ -260,7 +260,7 @@ export class AlphaFiSDK {
* @returns Transaction to claim all available rewards
*/
async claim(options: ClaimOptions): Promise<Transaction> {
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
const alphaReceipt = tx.moveCall({
target: `0x1::option::none`,
typeArguments: [LEGACY_ALPHA_POOL_RECEIPT],
Expand Down Expand Up @@ -294,8 +294,12 @@ export class AlphaFiSDK {
* @param proposalId - The ID of the proposal to vote on
* @returns Transaction object ready for signing and execution
*/
async vote(voteIndex: number, proposalId: string): Promise<Transaction | undefined> {
const tx = new Transaction();
async vote(
voteIndex: number,
proposalId: string,
existingTx?: Transaction,
): Promise<Transaction | undefined> {
const tx = existingTx ?? new Transaction();
if (voteIndex === undefined) {
console.error('Vote index is undefined');
return undefined;
Expand Down Expand Up @@ -332,7 +336,7 @@ export class AlphaFiSDK {
*/
async cetusSwapTxb(options: CetusSwapOptions): Promise<Transaction> {
const swap = new CetusSwap(this.config.network);
return await swap.cetusSimpleSwapTokensTxb(options.router, options.slippage);
return await swap.cetusSimpleSwapTokensTxb(options.router, options.slippage, options.tx);
}

/**
Expand Down Expand Up @@ -424,7 +428,7 @@ export class AlphaFiSDK {

// // Create ZapDepositStrategy instance
const zapDeposit = new ZapDepositStrategy(lpStrategy, this.strategyContext, cetusSwap);
const tx = new Transaction();
const tx = options.tx ?? new Transaction();
return await zapDeposit.zapDepositTxb(tx, options);
}
}
17 changes: 17 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { SuiClient } from '@mysten/sui/client';
import { Transaction } from '@mysten/sui/transactions';
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';

/**
Expand All @@ -30,6 +31,8 @@ export interface DepositOptions {
amount: bigint;
/** For LP pools: true to deposit token A, false for token B */
isAmountA?: boolean;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand Down Expand Up @@ -59,6 +62,8 @@ export interface WithdrawOptions {
isAmountA?: boolean;
/** If true, withdraw entire position regardless of amount */
withdrawMax: boolean;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand All @@ -76,6 +81,8 @@ export interface ZapDepositOptions {
address: string;
/** Maximum acceptable slippage as decimal (e.g., 0.005 = 0.5%) */
slippage: number;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand All @@ -101,6 +108,8 @@ export interface ClaimOptions {
poolId?: string;
/** User's wallet address */
address: string;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand All @@ -111,6 +120,8 @@ export interface ClaimAirdropOptions {
address: string;
/** Whether to transfer tokens directly to wallet */
transferToWallet: boolean;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand All @@ -121,6 +132,8 @@ export interface ClaimWithdrawAlphaOptions {
ticketId: string;
/** User's wallet address */
address: string;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

/**
Expand All @@ -133,6 +146,8 @@ export interface ClaimWithdrawSlushOptions {
poolId: string;
/** User's wallet address */
address: string;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

export type CancelWithdrawSlushOptions = ClaimWithdrawSlushOptions;
Expand All @@ -159,6 +174,8 @@ export interface CetusSwapOptions {
router: RouterDataV3;
/** Maximum acceptable slippage as decimal (e.g., 0.01 = 1%) */
slippage: number;
/** Optional existing transaction to append to (for PTB composition) */
tx?: Transaction;
}

// Re-export domain types for external consumers
Expand Down
Loading