Skip to content

feat(sdk-core): add withdrawFromVault() to DefiVault#9229

Open
sachinBitgo wants to merge 1 commit into
masterfrom
sachinroy936/defi-237-bitgojs-add-withdrawfromvault-to-sdk-defivault
Open

feat(sdk-core): add withdrawFromVault() to DefiVault#9229
sachinBitgo wants to merge 1 commit into
masterfrom
sachinroy936/defi-237-bitgojs-add-withdrawfromvault-to-sdk-defivault

Conversation

@sachinBitgo

@sachinBitgo sachinBitgo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Adds withdrawFromVault() to the DefiVault SDK class, completing the ERC-4626 vault lifecycle alongside the existing depositToVault() / resumeDeposit() methods.

What changed:

  • DefiVault.withdrawFromVault(params) — issues a single sendMany call with type: 'defiWithdraw' and returns { operationId, txRequestId }. The withdrawal state machine is simpler than deposit (no approve step): CREATED → WITHDRAW_TX_REQUESTED → WITHDRAW_SIGNED → WITHDRAW_CONFIRMED → COMPLETED.
  • IDefiVault — new withdrawFromVault method signature; new WithdrawFromVaultOptions and WithdrawResult types exported from iDefiVault.ts.
  • mpcUtils.ts — added defi-withdraw intent case. Maps SDK amountshareTokenAmount per the DefiWithdrawIntent schema in public-types (vault share tokens, not underlying asset units).
  • recipientUtils.ts — added defiWithdraw to NO_RECIPIENT_TX_TYPES (recipients/calldata are built server-side from defiParams).
  • wallet.ts — added defiWithdraw case in sendMany intent dispatch.
  • baseTypes.ts — added shareTokenAmount?: string to DefiIntentFields; removed clientIdempotencyKey (cleanup).
  • commitlint.config.js — added DEFI- to recognized issue prefixes.
  • Examples — added examples/ts/defi-vault-deposit.ts and examples/ts/defi-vault-withdraw.ts for manual staging tests.

Removed: clientIdempotencyKey from the deposit flow (not used server-side, cleaned up to reduce surface area).

Issue

DEFI-237

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Unit tests added in modules/sdk-core/test/unit/bitgo/defi/defiVault.ts covering:
    • Happy path: sendMany called with correct defiWithdraw args; operationId + txRequestId returned
    • Lite apiVersion (unsignedTxs) operationId extraction path
    • Missing operationId in response throws
    • walletPassphrase forwarded correctly
    • Guard throws for missing vaultId / amount
  • Manual end-to-end verified on staging using the example script (examples/ts/defi-vault-withdraw.ts)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My commits follow Conventional Commits
  • The ticket DEFI-237 was included in the commit message as a reference
  • I have added tests that prove my feature works
  • New and existing unit tests pass locally with my changes

@sachinBitgo sachinBitgo requested review from a team as code owners July 10, 2026 08:38
@linear-code

linear-code Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

DEFI-237

Ticket: DEFI-237

Single sendMany call (defiWithdraw → defi-withdraw intent) returns
{ operationId, txRequestId }. Maps SDK-level amount to shareTokenAmount
per the DefiWithdrawIntent schema in public-types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sachinBitgo sachinBitgo force-pushed the sachinroy936/defi-237-bitgojs-add-withdrawfromvault-to-sdk-defivault branch from db0f2a6 to 948347d Compare July 10, 2026 09:28
/** DeFi-service vault identifier */
vaultId: string;
/** Amount in base units of the vault share token */
amount: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigint

vaultId?: string;
amount?: { value: string; symbol: string } | string;
/** Vault share token amount for defi-withdraw intent (base units) */
shareTokenAmount?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bigint

Comment on lines +4474 to 4477
defiParams: params.defiParams as {
vaultId: string;
amount: string;
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't cast, validate (ideally using io-ts)

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.

2 participants