pub fn build_unwrap_bundle(
_signer: Pubkey,
_mint_stable: Pubkey,
_amount: u64,
_protocols: &[ProtocolAllocation],
) -> Vec<Instruction>Expand description
Builds a bundle of unwrap instructions for withdrawing across multiple protocols.
For large withdrawals that span multiple protocols, this function calculates the optimal split and returns multiple instructions that should be submitted as a Jito bundle for atomic execution.
§Arguments
signer- The user’s wallet addressmint_stable- The stablecoin mint addressamount- Total amount of stablecoins to unwrapprotocols- List of protocols with their available USDC balances
§Returns
A vector of instructions, one per protocol that needs to be withdrawn from. Submit these as a Jito bundle for atomic execution.
§Example
ⓘ
let protocols = vec![
ProtocolAllocation { protocol_id: PROTOCOL_KAMINO, usdc_available: 1000_000000 },
ProtocolAllocation { protocol_id: PROTOCOL_PERENA, usdc_available: 500_000000 },
];
let bundle = build_unwrap_bundle(signer, mint, 1200_000000, &protocols);
// bundle[0] = unwrap 1000 USDC from Kamino
// bundle[1] = unwrap 200 USDC from Perena