@@ -15,6 +15,8 @@ import {
1515 IDefiVault ,
1616 ListOperationsOptions ,
1717 ResumeDepositOptions ,
18+ WithdrawFromVaultOptions ,
19+ WithdrawResult ,
1820} from './iDefiVault' ;
1921import { IWallet } from '../wallet' ;
2022import { BitGoBase } from '../bitgoBase' ;
@@ -76,7 +78,6 @@ export class DefiVault implements IDefiVault {
7678 *
7779 * @param params.vaultId - DeFi-service vault identifier
7880 * @param params.amount - amount in base units of the underlying asset
79- * @param params.clientIdempotencyKey - optional client idempotency key
8081 * @param params.walletPassphrase - required for hot wallets, omit for custody
8182 */
8283 async depositToVault ( params : DepositToVaultOptions ) : Promise < DepositResult > {
@@ -139,7 +140,6 @@ export class DefiVault implements IDefiVault {
139140 defiParams : {
140141 vaultId : params . vaultId ,
141142 amount : params . amount ,
142- ...( params . clientIdempotencyKey ? { clientIdempotencyKey : params . clientIdempotencyKey } : { } ) ,
143143 } ,
144144 ...( params . walletPassphrase ? { walletPassphrase : params . walletPassphrase } : { } ) ,
145145 } ) ;
@@ -158,7 +158,6 @@ export class DefiVault implements IDefiVault {
158158 vaultId : params . vaultId ,
159159 amount : params . amount ,
160160 operationId,
161- ...( params . clientIdempotencyKey ? { clientIdempotencyKey : params . clientIdempotencyKey } : { } ) ,
162161 } ,
163162 ...( params . walletPassphrase ? { walletPassphrase : params . walletPassphrase } : { } ) ,
164163 } ) ;
@@ -254,6 +253,44 @@ export class DefiVault implements IDefiVault {
254253 return await this . bitgo . get ( this . bitgo . microservicesUrl ( this . operationsUrl ( ) ) ) . query ( query ) . result ( ) ;
255254 }
256255
256+ /**
257+ * Withdraw vault shares from a DeFi vault.
258+ *
259+ * Issues a single sendMany call (defiWithdraw) and returns the operationId
260+ * and txRequestId. The state machine for withdrawal is simpler than deposit:
261+ * CREATED → WITHDRAW_TX_REQUESTED → WITHDRAW_SIGNED → WITHDRAW_CONFIRMED → COMPLETED
262+ *
263+ * @param params.vaultId - DeFi-service vault identifier
264+ * @param params.amount - amount in base units of the vault share token
265+ * @param params.walletPassphrase - required for hot wallets, omit for custody
266+ */
267+ async withdrawFromVault ( params : WithdrawFromVaultOptions ) : Promise < WithdrawResult > {
268+ if ( ! params . vaultId ) {
269+ throw new Error ( 'vaultId is required' ) ;
270+ }
271+ if ( ! params . amount ) {
272+ throw new Error ( 'amount is required' ) ;
273+ }
274+
275+ const withdrawResult = await this . wallet . sendMany ( {
276+ type : 'defiWithdraw' ,
277+ defiParams : {
278+ vaultId : params . vaultId ,
279+ amount : params . amount ,
280+ } ,
281+ ...( params . walletPassphrase ? { walletPassphrase : params . walletPassphrase } : { } ) ,
282+ } ) ;
283+
284+ const txRequestId = this . extractTxRequestId ( withdrawResult ) ;
285+ const operationId = this . extractOperationId ( withdrawResult ) ;
286+
287+ if ( ! operationId ) {
288+ throw new Error ( 'operationId not found in withdraw txRequest response' ) ;
289+ }
290+
291+ return { operationId, txRequestId } ;
292+ }
293+
257294 // ── Internal helpers ────────────────────────────────────────────────
258295
259296 /**
0 commit comments