-
Notifications
You must be signed in to change notification settings - Fork 305
feat(sdk-core): add withdrawFromVault() to DefiVault #9229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sachinBitgo
wants to merge
1
commit into
master
Choose a base branch
from
sachinroy936/defi-237-bitgojs-add-withdrawfromvault-to-sdk-defivault
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Deposit into a DeFi ERC-4626 vault on staging. | ||
| * | ||
| * Usage: | ||
| * STAGING_ACCESS_TOKEN=<token> \ | ||
| * STAGING_WALLET_ID=<walletId> \ | ||
| * STAGING_WALLET_PASSPHRASE=<passphrase> \ | ||
| * DEFI_VAULT_ID=<vaultId> \ | ||
| * DEFI_DEPOSIT_AMOUNT=<amountInBaseUnits> \ | ||
| * npx ts-node examples/ts/defi-vault-deposit.ts | ||
| * | ||
| * Copyright 2026, BitGo, Inc. All Rights Reserved. | ||
| */ | ||
| import { BitGo } from 'bitgo'; | ||
|
|
||
| require('dotenv').config({ path: '../../.env' }); | ||
|
|
||
| const config = { | ||
| accessToken: '', | ||
| env: 'staging', | ||
| walletId: '', | ||
| vaultId: 'tbaseeth-usdc-test', | ||
| amount: 1000000, // 1 USDC | ||
| passphrase: '', | ||
| coin: 'tbaseeth', | ||
| otp: '000000', | ||
| }; | ||
|
|
||
| const bitgoTest = new BitGo({ | ||
| env: 'staging', | ||
| }); | ||
|
|
||
| //bitgo.register('tbaseeth', TethLikeCoin.createInstance); | ||
|
|
||
| async function main() { | ||
| console.log('Connecting to staging...'); | ||
| bitgoTest.authenticateWithAccessToken({ accessToken: config.accessToken }); | ||
| //await bitgoTest.unlock({ otp: config.otp, duration: 3600 }); | ||
| const wallet = await bitgoTest.coin('tbaseeth').wallets().get({ id: config.walletId }); | ||
| console.log('Wallet ID :', wallet.id()); | ||
| console.log('Vault ID :', config.vaultId); | ||
| console.log('Amount :', config.amount, '(base units)'); | ||
|
|
||
| console.log('\nStarting deposit...'); | ||
| const result = await wallet.defi.depositToVault({ | ||
| vaultId: config.vaultId, | ||
| amount: config.amount.toString(), | ||
| ...(config.passphrase ? { walletPassphrase: config.passphrase } : {}), | ||
| }); | ||
|
|
||
| console.log('\nDeposit complete:'); | ||
| console.log(' operationId :', result.operationId); | ||
| console.log(' approve txRequestId :', result.txRequestIds.approve); | ||
| console.log(' deposit txRequestId :', result.txRequestIds.deposit); | ||
| console.log('\nFull result:', JSON.stringify(result, null, 2)); | ||
| } | ||
|
|
||
| main().catch((e) => { | ||
| console.error('Error:', e.message); | ||
| if (e.stack) console.error(e.stack); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * Withdraw vault shares from a DeFi ERC-4626 vault on staging. | ||
| * | ||
| * Run the deposit script first, then use this to withdraw. | ||
| * | ||
| * Usage: | ||
| * STAGING_ACCESS_TOKEN=<token> \ | ||
| * STAGING_WALLET_ID=<walletId> \ | ||
| * STAGING_WALLET_PASSPHRASE=<passphrase> \ | ||
| * DEFI_VAULT_ID=<vaultId> \ | ||
| * DEFI_WITHDRAW_AMOUNT=<shareTokenAmountInBaseUnits> \ | ||
| * npx ts-node examples/ts/defi-vault-withdraw.ts | ||
| * | ||
| * Copyright 2026, BitGo, Inc. All Rights Reserved. | ||
| */ | ||
| import { BitGo } from 'bitgo'; | ||
|
|
||
| require('dotenv').config({ path: '../../.env' }); | ||
|
|
||
| const config = { | ||
| accessToken: '', | ||
| env: 'staging', | ||
| walletId: '', | ||
| vaultId: 'tbaseeth-usdc-test', | ||
| amount: 1000000, // vault share base units | ||
| passphrase: '', | ||
| coin: 'tbaseeth', | ||
| otp: '000000', | ||
| }; | ||
|
|
||
| const bitgoTest = new BitGo({ | ||
| env: 'staging', | ||
| }); | ||
|
|
||
| //bitgo.register('tbaseeth', TethLikeCoin.createInstance); | ||
|
|
||
| async function main() { | ||
| console.log('Connecting to staging...'); | ||
| bitgoTest.authenticateWithAccessToken({ accessToken: config.accessToken }); | ||
| //await bitgoTest.unlock({ otp: config.otp, duration: 3600 }); | ||
| const wallet = await bitgoTest.coin('tbaseeth').wallets().get({ id: config.walletId }); | ||
| console.log('Wallet ID :', wallet.id()); | ||
| console.log('Vault ID :', config.vaultId); | ||
| console.log('Amount :', config.amount, '(vault share base units)'); | ||
|
|
||
| console.log('\nStarting withdrawal...'); | ||
| const result = await wallet.defi.withdrawFromVault({ | ||
| vaultId: config.vaultId, | ||
| amount: config.amount.toString(), | ||
| ...(config.passphrase ? { walletPassphrase: config.passphrase } : {}), | ||
| }); | ||
|
|
||
| console.log('\nWithdrawal complete:'); | ||
| console.log(' operationId :', result.operationId); | ||
| console.log(' txRequestId :', result.txRequestId); | ||
| console.log('\nFull result:', JSON.stringify(result, null, 2)); | ||
| } | ||
|
|
||
| main().catch((e) => { | ||
| console.error('Error:', e.message); | ||
| if (e.stack) console.error(e.stack); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,16 +287,16 @@ interface IntentOptionsBase { | |
| export interface DefiIntentFields { | ||
| vaultId?: string; | ||
| amount?: { value: string; symbol: string } | string; | ||
| /** Vault share token amount for defi-withdraw intent (base units) */ | ||
| shareTokenAmount?: string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| operationId?: string; | ||
| clientIdempotencyKey?: string; | ||
| } | ||
|
|
||
| /** DeFi-specific intent parameters (input container for defiParams). */ | ||
| export interface DefiIntentParams { | ||
| vaultId: string; | ||
| amount: string; | ||
| operationId?: string; | ||
| clientIdempotencyKey?: string; | ||
| } | ||
|
|
||
| export interface IntentOptionsForMessage extends IntentOptionsBase { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4445,7 +4445,6 @@ export class Wallet implements IWallet { | |
| defiParams: params.defiParams as { | ||
| vaultId: string; | ||
| amount: string; | ||
| clientIdempotencyKey?: string; | ||
| }, | ||
| }, | ||
| apiVersion, | ||
|
|
@@ -4461,7 +4460,20 @@ export class Wallet implements IWallet { | |
| vaultId: string; | ||
| amount: string; | ||
| operationId?: string; | ||
| clientIdempotencyKey?: string; | ||
| }, | ||
| }, | ||
| apiVersion, | ||
| params.preview | ||
| ); | ||
| break; | ||
| case 'defiWithdraw': | ||
| txRequest = await this.tssUtils!.prebuildTxWithIntent( | ||
| { | ||
| reqId, | ||
| intentType: 'defi-withdraw', | ||
| defiParams: params.defiParams as { | ||
| vaultId: string; | ||
| amount: string; | ||
| }, | ||
|
Comment on lines
+4474
to
4477
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't cast, validate (ideally using io-ts) |
||
| }, | ||
| apiVersion, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bigint