You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[derive(BorshSerialize)]pubenumInstruction{// order of the instruction mattersMake{id:u64,deposit:u64,recieve:u64},Take{},Refund{}}// serialize the instructionletmut instr_in_bytes:Vec<u8> = Vec::new();let id:u64 = 23424;// random number can be used only oncelet init_data = Instructions::Init{
id,deposit:10_000_000_000,receive:20_000_000_000,};
init_data.serialize(&mut instr_in_bytes)?;// accounts must be in the same orderlet accounts:Vec<AccountMeta> = vec![AccountMeta::new(maker,true),AccountMeta::new(token_mint_a,false),AccountMeta::new(token_mint_b,false),AccountMeta::new(maker_token_account_a,false),AccountMeta::new(escrow,false),AccountMeta::new(escrow_token_ata,false),AccountMeta::new_readonly(token_program,false),AccountMeta::new_readonly(associated_token_program,false),AccountMeta::new_readonly(system_program,false),];let maker_keypair:Keypair = Keypair::from_base58_string("private bs58 string");sign_and_send_tx(instr_in_bytes, accounts,&maker_keypair);
Take Instruction
let take_accounts:Vec<AccountMeta> = vec![AccountMeta::new(maker,false),AccountMeta::new(taker_key,true),AccountMeta::new(token_mint_a,false),AccountMeta::new(token_mint_b,false),AccountMeta::new(escrow,false),AccountMeta::new(escrow_token_ata,false),AccountMeta::new(taker_token_account_a,false),AccountMeta::new(taker_token_account_b,false),AccountMeta::new(maker_token_account_b,false),AccountMeta::new_readonly(token_program,false),AccountMeta::new_readonly(associated_token_program,false),AccountMeta::new_readonly(system_program,false),];let take = Instructions::Take{};letmut take_ix_data:Vec<u8> = Vec::new();
take.serialize(&mut take_ix_data).unwrap();let taker = Keypair::from_base58_string("taker private key");sign_and_send_tx(take_ix_data, take_accounts,&taker);