Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ts/sdk/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ program
.addOption(new Option("--vault-address <address>", "Address of the vault to deposit into").makeOptionMandatory(false))
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
.addOption(new Option("--amount <amount>", "Amount of shares to withdraw (raw format, as expected in the program)").makeOptionMandatory(true))
.option("--simulate", "Simulate the transaction instead of sending it")
.action((opts) => requestWithdraw(program, opts));
program
.command("withdraw")
.description("Initiate the withdraw, after the redeem period has passed")
.addOption(new Option("--vault-depositor-address <vaultDepositorAddress>", "VaultDepositor address").makeOptionMandatory(false))
.addOption(new Option("--vault-address <address>", "Address of the vault to deposit into").makeOptionMandatory(false))
.addOption(new Option("--authority <vaultDepositorAuthority>", "VaultDepositor authority address").makeOptionMandatory(false))
.option("--simulate", "Simulate the transaction instead of sending it")
.action((opts) => withdraw(program, opts));
program
.command("force-withdraw")
Expand Down
21 changes: 19 additions & 2 deletions ts/sdk/cli/commands/requestWithdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ export const requestWithdraw = async (program: Command, cmdOpts: OptionValues) =

const withdrawAmountBN = new BN(cmdOpts.amount);

const tx = await driftVault.requestWithdraw(vaultDepositorAddress, withdrawAmountBN, WithdrawUnit.SHARES);
console.log(`Requested to withdraw ${cmdOpts.amount} shares from the vault: https://solana.fm/tx/${tx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
if (cmdOpts.simulate) {
// Simulate the transaction
const authority = cmdOpts.authority ? new PublicKey(cmdOpts.authority) : driftVault.driftClient.wallet.publicKey;
console.log(`\nSimulating request withdraw as authority: ${authority}`);
console.log(`Amount: ${cmdOpts.amount} shares`);

try {
await driftVault.requestWithdraw(vaultDepositorAddress, withdrawAmountBN, WithdrawUnit.SHARES, {
simulateTransaction: true,
simulationAuthority: authority
});
} catch (error) {
// Error details are already logged by vaultClient
process.exit(1);
}
} else {
const tx = await driftVault.requestWithdraw(vaultDepositorAddress, withdrawAmountBN, WithdrawUnit.SHARES);
console.log(`Requested to withdraw ${cmdOpts.amount} shares from the vault: https://solana.fm/tx/${tx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
}
};
20 changes: 18 additions & 2 deletions ts/sdk/cli/commands/withdraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ export const withdraw = async (program: Command, cmdOpts: OptionValues) => {
vaultDepositorAddress = getVaultDepositorAddressSync(VAULT_PROGRAM_ID, vaultAddress, authority);
}

const tx = await driftVault.withdraw(vaultDepositorAddress);
console.log(`Withdrew from vault: https://solana.fm/tx/${tx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
if (cmdOpts.simulate) {
// Simulate the transaction
const authority = cmdOpts.authority ? new PublicKey(cmdOpts.authority) : driftVault.driftClient.wallet.publicKey;
console.log(`\nSimulating withdraw as authority: ${authority}`);

try {
await driftVault.withdraw(vaultDepositorAddress, {
simulateTransaction: true,
simulationAuthority: authority
});
} catch (error) {
// Error details are already logged by vaultClient
process.exit(1);
}
} else {
const tx = await driftVault.withdraw(vaultDepositorAddress);
console.log(`Withdrew from vault: https://solana.fm/tx/${tx}${driftClient.env === "devnet" ? "?cluster=devnet-solana" : ""}`);
}
};
Loading
Loading