Skip to content

feat(sdk): PTB composition support for all transaction methods#57

Merged
jangid merged 2 commits intomainfrom
feature/ptb-composable
Mar 31, 2026
Merged

feat(sdk): PTB composition support for all transaction methods#57
jangid merged 2 commits intomainfrom
feature/ptb-composable

Conversation

@jangid
Copy link
Copy Markdown
Contributor

@jangid jangid commented Mar 31, 2026

Summary

  • All transaction-building SDK methods now accept an optional tx parameter that lets callers pass in an existing Transaction to append operations to
  • Enables composing multiple AlphaFi operations into a single Programmable Transaction Block (PTB)
  • Fully backward-compatible — omitting tx preserves existing behavior (creates a fresh transaction)

Motivation

Community request: bot developers and integrators need to compose multiple AlphaFi SDK calls (deposit, withdraw, claim, swap, etc.) into a single PTB for atomic execution, lower gas costs, and tighter integration with other Sui protocols.

Changes

src/core/types.ts — Added optional tx?: Transaction field to all options interfaces:

  • DepositOptions, WithdrawOptions, ZapDepositOptions
  • ClaimOptions, ClaimAirdropOptions
  • ClaimWithdrawAlphaOptions, ClaimWithdrawSlushOptions (and CancelWithdrawSlushOptions via type alias)
  • CetusSwapOptions

src/core/index.ts — Updated all methods to use options.tx ?? new Transaction():

  • deposit, withdraw, initiateWithdrawAlpha
  • claimWithdrawAlpha, claimWithdrawSlush, cancelWithdrawSlush
  • claimAirdrop, claim
  • cetusSwapTxb, zapDepositTxb
  • vote, updatePool (positional existingTx? parameter)

Usage

// Before: each call creates its own transaction
const depositTx = await sdk.deposit({ poolId, address, amount: 100n });
const withdrawTx = await sdk.withdraw({ poolId: otherPool, address, amount: '50', withdrawMax: false });
// Two separate transactions to sign and execute

// After: compose into a single PTB
const tx = new Transaction();
await sdk.deposit({ tx, poolId, address, amount: 100n });
await sdk.withdraw({ tx, poolId: otherPool, address, amount: '50', withdrawMax: false });
// One atomic transaction to sign and execute
await client.signAndExecuteTransaction({ transaction: tx, signer });

Test plan

  • npm run build — clean compilation (CJS + ESM)
  • Pre-commit hooks pass (Prettier, ESLint, TypeScript type check, build check)
  • Manual test: compose deposit + withdraw into single PTB and execute on testnet
  • Verify omitting tx still works identically to current behavior

All transaction-building methods now accept an optional `tx` parameter
(or `existingTx` for positional-arg methods). When provided, operations
are appended to the caller's transaction instead of creating a new one,
enabling multi-operation PTBs (e.g. deposit + withdraw in one tx).

Fully backward-compatible — omitting `tx` preserves existing behavior.
alphafi-sdk is no longer a dependency — all deps come from npm
(@alphafi/alphalend-sdk, @alphafi/stsui-sdk). Removes 3 GH_PAT
checkouts, 3 npm ci runs, and 2 build steps that did nothing.

Also simplifies checkout to use default path since only one repo
is needed, removing the working-directory indirection.
@jangid jangid merged commit 8b035ff into main Mar 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants