From 4ce1883cf6dcde41b3f8f679244c20da72354a42 Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Mon, 14 Jul 2025 15:42:08 -0700 Subject: [PATCH] withdraw --- api/src/sdk.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/api/src/sdk.rs b/api/src/sdk.rs index 4dfc43e..8eb229e 100644 --- a/api/src/sdk.rs +++ b/api/src/sdk.rs @@ -234,6 +234,31 @@ pub fn deposit(signer: Pubkey, id: u64, amount: u64) -> Instruction { } } +pub fn withdraw(signer: Pubkey, id: u64, amount: u64) -> Instruction { + let block_adddress = block_pda(id).0; + let collateral_address = collateral_pda(id).0; + let stake_address = stake_pda(signer, id).0; + let recipient_address = get_associated_token_address(&signer, &MINT_ADDRESS); + Instruction { + program_id: crate::ID, + accounts: vec![ + AccountMeta::new(signer, true), + AccountMeta::new(block_adddress, false), + AccountMeta::new(collateral_address, false), + AccountMeta::new(MINT_ADDRESS, false), + AccountMeta::new(recipient_address, false), + AccountMeta::new(stake_address, false), + AccountMeta::new_readonly(system_program::ID, false), + AccountMeta::new_readonly(spl_token::ID, false), + AccountMeta::new_readonly(crate::ID, false), + ], + data: Withdraw { + amount: amount.to_le_bytes(), + } + .to_bytes(), + } +} + pub fn swap( signer: Pubkey, id: u64,