diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ebc9417..b2c8445 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,38 +14,20 @@ 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 @@ -53,42 +35,20 @@ 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: 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 @@ -96,46 +56,24 @@ 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: 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 diff --git a/src/core/index.ts b/src/core/index.ts index 4328fdf..1781224 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -81,11 +81,11 @@ export class AlphaFiSDK { const strategy = await this.protocol.getSinglePoolStrategy(poolId); return strategy.getData(); } - async updatePool(poolId: string): Promise { + async updatePool(poolId: string, existingTx?: Transaction): Promise { const strategy = (await this.protocol.getSinglePoolStrategy( poolId, )) as SingleAssetLoopingStrategy; - const tx = new Transaction(); + const tx = existingTx ?? new Transaction(); return strategy.updatePool(tx); } /** @@ -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; @@ -161,7 +161,7 @@ export class AlphaFiSDK { * @returns Transaction object ready for signing and execution */ async withdraw(options: WithdrawOptions): Promise { - 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; @@ -175,7 +175,7 @@ export class AlphaFiSDK { * @returns Transaction to create withdrawal ticket */ async initiateWithdrawAlpha(options: WithdrawOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const strategy = (await this.portfolio.getPoolStrategy( options.address, '0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8', @@ -191,7 +191,7 @@ export class AlphaFiSDK { * @returns Transaction to claim the withdrawn ALPHA tokens */ async claimWithdrawAlpha(options: ClaimWithdrawAlphaOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const strategy = (await this.portfolio.getPoolStrategy( options.address, '0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8', @@ -207,7 +207,7 @@ export class AlphaFiSDK { * @returns Transaction to claim the withdrawn tokens */ async claimWithdrawSlush(options: ClaimWithdrawSlushOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const strategy = (await this.portfolio.getPoolStrategy( options.address, options.poolId, @@ -223,7 +223,7 @@ export class AlphaFiSDK { * @returns Transaction to cancel the withdrawal */ async cancelWithdrawSlush(options: CancelWithdrawSlushOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const strategy = (await this.portfolio.getPoolStrategy( options.address, options.poolId, @@ -239,7 +239,7 @@ export class AlphaFiSDK { * @returns Transaction to claim airdrop rewards */ async claimAirdrop(options: ClaimAirdropOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const strategy = (await this.portfolio.getPoolStrategy( options.address, '0x06a4922346ae433e9a2fff4db900d760e0cbfdef748f48385f430ef4d042a6f8', @@ -260,7 +260,7 @@ export class AlphaFiSDK { * @returns Transaction to claim all available rewards */ async claim(options: ClaimOptions): Promise { - const tx = new Transaction(); + const tx = options.tx ?? new Transaction(); const alphaReceipt = tx.moveCall({ target: `0x1::option::none`, typeArguments: [LEGACY_ALPHA_POOL_RECEIPT], @@ -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 { - const tx = new Transaction(); + async vote( + voteIndex: number, + proposalId: string, + existingTx?: Transaction, + ): Promise { + const tx = existingTx ?? new Transaction(); if (voteIndex === undefined) { console.error('Vote index is undefined'); return undefined; @@ -332,7 +336,7 @@ export class AlphaFiSDK { */ async cetusSwapTxb(options: CetusSwapOptions): Promise { 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); } /** @@ -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); } } diff --git a/src/core/types.ts b/src/core/types.ts index 47d3146..a773481 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -4,6 +4,7 @@ */ import { SuiClient } from '@mysten/sui/client'; +import { Transaction } from '@mysten/sui/transactions'; import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk'; /** @@ -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; } /** @@ -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; } /** @@ -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; } /** @@ -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; } /** @@ -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; } /** @@ -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; } /** @@ -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; @@ -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