diff --git a/wallet/src/program_facades/amm.rs b/wallet/src/program_facades/amm.rs index 2ac2ab79..189c79f1 100644 --- a/wallet/src/program_facades/amm.rs +++ b/wallet/src/program_facades/amm.rs @@ -1,10 +1,9 @@ use amm_core::{compute_liquidity_token_pda, compute_pool_pda, compute_vault_pda}; -use common::{HashType, transaction::NSSATransaction}; +use common::HashType; use nssa::{AccountId, program::Program}; -use sequencer_service_rpc::RpcClient as _; use token_core::TokenHolding; -use crate::{ExecutionFailureKind, WalletCore}; +use crate::{AccountManagerAccountIdentity, ExecutionFailureKind, WalletCore}; pub struct Amm<'wallet>(pub &'wallet WalletCore); impl Amm<'_> { @@ -18,12 +17,6 @@ impl Amm<'_> { ) -> Result { let program = Program::amm(); let amm_program_id = Program::amm().id(); - let instruction = amm_core::Instruction::NewDefinition { - token_a_amount: balance_a, - token_b_amount: balance_b, - amm_program_id, - }; - let user_a_acc = self .0 .get_account_public(user_holding_a) @@ -47,78 +40,29 @@ impl Amm<'_> { let vault_holding_a = compute_vault_pda(amm_program_id, amm_pool, definition_token_a_id); let vault_holding_b = compute_vault_pda(amm_program_id, amm_pool, definition_token_b_id); let pool_lp = compute_liquidity_token_pda(amm_program_id, amm_pool); + let instruction = amm_core::Instruction::NewDefinition { + token_a_amount: balance_a, + token_b_amount: balance_b, + amm_program_id, + }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let account_ids = vec![ - amm_pool, - vault_holding_a, - vault_holding_b, - pool_lp, - user_holding_a, - user_holding_b, - user_holding_lp, - ]; - - let mut nonces = self - .0 - .get_accounts_nonces(vec![user_holding_a, user_holding_b]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(amm_pool), + AccountManagerAccountIdentity::Public(vault_holding_a), + AccountManagerAccountIdentity::Public(vault_holding_b), + AccountManagerAccountIdentity::Public(pool_lp), + AccountManagerAccountIdentity::Public(user_holding_a), + AccountManagerAccountIdentity::Public(user_holding_b), + AccountManagerAccountIdentity::Public(user_holding_lp), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let mut private_keys = Vec::new(); - - let signing_key_a = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_a) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - private_keys.push(signing_key_a); - - let signing_key_b = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_b) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - private_keys.push(signing_key_b); - - if let Some(signing_key_lp) = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_lp) - { - private_keys.push(signing_key_lp); - let lp_nonces = self - .0 - .get_accounts_nonces(vec![user_holding_lp]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - nonces.extend(lp_nonces); - } else { - println!( - "Liquidity pool tokens receiver's account ({user_holding_lp}) private key not found in wallet. Proceeding with only liquidity provider's keys." - ); - } - - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &private_keys); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_swap_exact_input( @@ -129,14 +73,8 @@ impl Amm<'_> { min_amount_out: u128, token_definition_id_in: AccountId, ) -> Result { - let instruction = amm_core::Instruction::SwapExactInput { - swap_amount_in, - min_amount_out, - token_definition_id_in, - }; let program = Program::amm(); let amm_program_id = Program::amm().id(); - let user_a_acc = self .0 .get_account_public(user_holding_a) @@ -159,56 +97,27 @@ impl Amm<'_> { compute_pool_pda(amm_program_id, definition_token_a_id, definition_token_b_id); let vault_holding_a = compute_vault_pda(amm_program_id, amm_pool, definition_token_a_id); let vault_holding_b = compute_vault_pda(amm_program_id, amm_pool, definition_token_b_id); - - let account_ids = vec![ - amm_pool, - vault_holding_a, - vault_holding_b, - user_holding_a, - user_holding_b, - ]; - - let account_id_auth = if definition_token_a_id == token_definition_id_in { - user_holding_a - } else if definition_token_b_id == token_definition_id_in { - user_holding_b - } else { - return Err(ExecutionFailureKind::AccountDataError( - token_definition_id_in, - )); + let instruction = amm_core::Instruction::SwapExactInput { + swap_amount_in, + min_amount_out, + token_definition_id_in, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let nonces = self - .0 - .get_accounts_nonces(vec![account_id_auth]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(amm_pool), + AccountManagerAccountIdentity::Public(vault_holding_a), + AccountManagerAccountIdentity::Public(vault_holding_b), + AccountManagerAccountIdentity::Public(user_holding_a), + AccountManagerAccountIdentity::Public(user_holding_b), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let signing_key = self - .0 - .storage - .key_chain() - .pub_account_signing_key(account_id_auth) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_swap_exact_output( @@ -219,14 +128,8 @@ impl Amm<'_> { max_amount_in: u128, token_definition_id_in: AccountId, ) -> Result { - let instruction = amm_core::Instruction::SwapExactOutput { - exact_amount_out, - max_amount_in, - token_definition_id_in, - }; let program = Program::amm(); let amm_program_id = Program::amm().id(); - let user_a_acc = self .0 .get_account_public(user_holding_a) @@ -249,56 +152,27 @@ impl Amm<'_> { compute_pool_pda(amm_program_id, definition_token_a_id, definition_token_b_id); let vault_holding_a = compute_vault_pda(amm_program_id, amm_pool, definition_token_a_id); let vault_holding_b = compute_vault_pda(amm_program_id, amm_pool, definition_token_b_id); - - let account_ids = vec![ - amm_pool, - vault_holding_a, - vault_holding_b, - user_holding_a, - user_holding_b, - ]; - - let account_id_auth = if definition_token_a_id == token_definition_id_in { - user_holding_a - } else if definition_token_b_id == token_definition_id_in { - user_holding_b - } else { - return Err(ExecutionFailureKind::AccountDataError( - token_definition_id_in, - )); + let instruction = amm_core::Instruction::SwapExactOutput { + exact_amount_out, + max_amount_in, + token_definition_id_in, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let nonces = self - .0 - .get_accounts_nonces(vec![account_id_auth]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(amm_pool), + AccountManagerAccountIdentity::Public(vault_holding_a), + AccountManagerAccountIdentity::Public(vault_holding_b), + AccountManagerAccountIdentity::Public(user_holding_a), + AccountManagerAccountIdentity::Public(user_holding_b), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let signing_key = self - .0 - .storage - .key_chain() - .pub_account_signing_key(account_id_auth) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_add_liquidity( @@ -310,14 +184,8 @@ impl Amm<'_> { max_amount_to_add_token_a: u128, max_amount_to_add_token_b: u128, ) -> Result { - let instruction = amm_core::Instruction::AddLiquidity { - min_amount_liquidity, - max_amount_to_add_token_a, - max_amount_to_add_token_b, - }; let program = Program::amm(); let amm_program_id = Program::amm().id(); - let user_a_acc = self .0 .get_account_public(user_holding_a) @@ -341,57 +209,29 @@ impl Amm<'_> { let vault_holding_a = compute_vault_pda(amm_program_id, amm_pool, definition_token_a_id); let vault_holding_b = compute_vault_pda(amm_program_id, amm_pool, definition_token_b_id); let pool_lp = compute_liquidity_token_pda(amm_program_id, amm_pool); + let instruction = amm_core::Instruction::AddLiquidity { + min_amount_liquidity, + max_amount_to_add_token_a, + max_amount_to_add_token_b, + }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let account_ids = vec![ - amm_pool, - vault_holding_a, - vault_holding_b, - pool_lp, - user_holding_a, - user_holding_b, - user_holding_lp, - ]; - - let nonces = self - .0 - .get_accounts_nonces(vec![user_holding_a, user_holding_b]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(amm_pool), + AccountManagerAccountIdentity::Public(vault_holding_a), + AccountManagerAccountIdentity::Public(vault_holding_b), + AccountManagerAccountIdentity::Public(pool_lp), + AccountManagerAccountIdentity::Public(user_holding_a), + AccountManagerAccountIdentity::Public(user_holding_b), + AccountManagerAccountIdentity::Public(user_holding_lp), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let signing_key_a = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_a) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let signing_key_b = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_b) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let witness_set = nssa::public_transaction::WitnessSet::for_message( - &message, - &[signing_key_a, signing_key_b], - ); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_remove_liquidity( @@ -403,14 +243,8 @@ impl Amm<'_> { min_amount_to_remove_token_a: u128, min_amount_to_remove_token_b: u128, ) -> Result { - let instruction = amm_core::Instruction::RemoveLiquidity { - remove_liquidity_amount, - min_amount_to_remove_token_a, - min_amount_to_remove_token_b, - }; let program = Program::amm(); let amm_program_id = Program::amm().id(); - let user_a_acc = self .0 .get_account_public(user_holding_a) @@ -434,47 +268,28 @@ impl Amm<'_> { let vault_holding_a = compute_vault_pda(amm_program_id, amm_pool, definition_token_a_id); let vault_holding_b = compute_vault_pda(amm_program_id, amm_pool, definition_token_b_id); let pool_lp = compute_liquidity_token_pda(amm_program_id, amm_pool); + let instruction = amm_core::Instruction::RemoveLiquidity { + remove_liquidity_amount, + min_amount_to_remove_token_a, + min_amount_to_remove_token_b, + }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let account_ids = vec![ - amm_pool, - vault_holding_a, - vault_holding_b, - pool_lp, - user_holding_a, - user_holding_b, - user_holding_lp, - ]; - - let nonces = self - .0 - .get_accounts_nonces(vec![user_holding_lp]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(amm_pool), + AccountManagerAccountIdentity::Public(vault_holding_a), + AccountManagerAccountIdentity::Public(vault_holding_b), + AccountManagerAccountIdentity::Public(pool_lp), + AccountManagerAccountIdentity::Public(user_holding_a), + AccountManagerAccountIdentity::Public(user_holding_b), + AccountManagerAccountIdentity::Public(user_holding_lp), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let signing_key_lp = self - .0 - .storage - .key_chain() - .pub_account_signing_key(user_holding_lp) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key_lp]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } } diff --git a/wallet/src/program_facades/ata.rs b/wallet/src/program_facades/ata.rs index 0a6a4eba..d6e3fea8 100644 --- a/wallet/src/program_facades/ata.rs +++ b/wallet/src/program_facades/ata.rs @@ -1,12 +1,11 @@ use std::collections::HashMap; use ata_core::{compute_ata_seed, get_associated_token_account_id}; -use common::{HashType, transaction::NSSATransaction}; +use common::HashType; use nssa::{ AccountId, privacy_preserving_transaction::circuit::ProgramWithDependencies, program::Program, }; use nssa_core::SharedSecretKey; -use sequencer_service_rpc::RpcClient as _; use crate::{AccountManagerAccountIdentity, ExecutionFailureKind, WalletCore}; @@ -24,38 +23,21 @@ impl Ata<'_> { &ata_program_id, &compute_ata_seed(owner_id, definition_id), ); - - let account_ids = vec![owner_id, definition_id, ata_id]; - - let nonces = self - .0 - .get_accounts_nonces(vec![owner_id]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let Some(signing_key) = self.0.storage.key_chain().pub_account_signing_key(owner_id) else { - return Err(ExecutionFailureKind::KeyNotFoundError); - }; - let instruction = ata_core::Instruction::Create { ata_program_id }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - )?; - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(owner_id), + AccountManagerAccountIdentity::Public(definition_id), + AccountManagerAccountIdentity::Public(ata_id), + ], + instruction_data, + &program.into(), + ) + .await } pub async fn send_transfer( @@ -71,41 +53,24 @@ impl Ata<'_> { &ata_program_id, &compute_ata_seed(owner_id, definition_id), ); - - let account_ids = vec![owner_id, sender_ata_id, recipient_id]; - - let nonces = self - .0 - .get_accounts_nonces(vec![owner_id]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let Some(signing_key) = self.0.storage.key_chain().pub_account_signing_key(owner_id) else { - return Err(ExecutionFailureKind::KeyNotFoundError); - }; - let instruction = ata_core::Instruction::Transfer { ata_program_id, amount, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - )?; - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(owner_id), + AccountManagerAccountIdentity::Public(sender_ata_id), + AccountManagerAccountIdentity::Public(recipient_id), + ], + instruction_data, + &program.into(), + ) + .await } pub async fn send_burn( @@ -120,41 +85,24 @@ impl Ata<'_> { &ata_program_id, &compute_ata_seed(owner_id, definition_id), ); - - let account_ids = vec![owner_id, holder_ata_id, definition_id]; - - let nonces = self - .0 - .get_accounts_nonces(vec![owner_id]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let Some(signing_key) = self.0.storage.key_chain().pub_account_signing_key(owner_id) else { - return Err(ExecutionFailureKind::KeyNotFoundError); - }; - let instruction = ata_core::Instruction::Burn { ata_program_id, amount, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let message = nssa::public_transaction::Message::try_new( - program.id(), - account_ids, - nonces, - instruction, - )?; - - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(owner_id), + AccountManagerAccountIdentity::Public(holder_ata_id), + AccountManagerAccountIdentity::Public(definition_id), + ], + instruction_data, + &program.into(), + ) + .await } pub async fn send_create_private_owner( diff --git a/wallet/src/program_facades/native_token_transfer/public.rs b/wallet/src/program_facades/native_token_transfer/public.rs index 93d0f42d..6054383c 100644 --- a/wallet/src/program_facades/native_token_transfer/public.rs +++ b/wallet/src/program_facades/native_token_transfer/public.rs @@ -9,73 +9,6 @@ use crate::{ }; impl NativeTokenTransfer<'_> { - // pub async fn send_public_transfer( - // &self, - // from: AccountId, - // to: AccountId, - // balance_to_move: u128, - // ) -> Result { - // let balance = self - // .0 - // .get_account_balance(from) - // .await - // .map_err(ExecutionFailureKind::SequencerError)?; - - // if balance >= balance_to_move { - // let account_ids = vec![from, to]; - // let program_id = Program::authenticated_transfer_program().id(); - - // let mut nonces = self - // .0 - // .get_accounts_nonces(vec![from]) - // .await - // .map_err(ExecutionFailureKind::SequencerError)?; - - // let mut private_keys = Vec::new(); - // let from_signing_key = self.0.storage.key_chain().pub_account_signing_key(from); - // let Some(from_signing_key) = from_signing_key else { - // return Err(ExecutionFailureKind::KeyNotFoundError); - // }; - // private_keys.push(from_signing_key); - - // let to_signing_key = self.0.storage.key_chain().pub_account_signing_key(to); - // if let Some(to_signing_key) = to_signing_key { - // private_keys.push(to_signing_key); - // let to_nonces = self - // .0 - // .get_accounts_nonces(vec![to]) - // .await - // .map_err(ExecutionFailureKind::SequencerError)?; - // nonces.extend(to_nonces); - // } else { - // println!( - // "Receiver's account ({to}) private key not found in wallet. Proceeding with - // only sender's key." ); - // } - - // let message = Message::try_new( - // program_id, - // account_ids, - // nonces, - // AuthTransferInstruction::Transfer { - // amount: balance_to_move, - // }, - // ) - // .unwrap(); - // let witness_set = WitnessSet::for_message(&message, &private_keys); - - // let tx = PublicTransaction::new(message, witness_set); - - // Ok(self - // .0 - // .sequencer_client - // .send_transaction(NSSATransaction::Public(tx)) - // .await?) - // } else { - // Err(ExecutionFailureKind::InsufficientFundsError) - // } - // } - pub async fn send_public_transfer( &self, from: AccountId, @@ -97,43 +30,6 @@ impl NativeTokenTransfer<'_> { .await } - // pub async fn register_account( - // &self, - // from: AccountId, - // ) -> Result { - // let nonces = self - // .0 - // .get_accounts_nonces(vec![from]) - // .await - // .map_err(ExecutionFailureKind::SequencerError)?; - - // let account_ids = vec![from]; - // let program_id = Program::authenticated_transfer_program().id(); - // let message = Message::try_new( - // program_id, - // account_ids, - // nonces, - // AuthTransferInstruction::Initialize, - // ) - // .unwrap(); - - // let signing_key = self.0.storage.key_chain().pub_account_signing_key(from); - - // let Some(signing_key) = signing_key else { - // return Err(ExecutionFailureKind::KeyNotFoundError); - // }; - - // let witness_set = WitnessSet::for_message(&message, &[signing_key]); - - // let tx = PublicTransaction::new(message, witness_set); - - // Ok(self - // .0 - // .sequencer_client - // .send_transaction(NSSATransaction::Public(tx)) - // .await?) - // } - pub async fn register_account( &self, from: AccountId, diff --git a/wallet/src/program_facades/pinata.rs b/wallet/src/program_facades/pinata.rs index 28767366..e933787d 100644 --- a/wallet/src/program_facades/pinata.rs +++ b/wallet/src/program_facades/pinata.rs @@ -1,7 +1,6 @@ -use common::{HashType, transaction::NSSATransaction}; -use nssa::AccountId; +use common::HashType; +use nssa::{AccountId, program::Program}; use nssa_core::{MembershipProof, SharedSecretKey}; -use sequencer_service_rpc::RpcClient as _; use crate::{AccountManagerAccountIdentity, ExecutionFailureKind, WalletCore}; @@ -14,20 +13,21 @@ impl Pinata<'_> { winner_account_id: AccountId, solution: u128, ) -> Result { - let account_ids = vec![pinata_account_id, winner_account_id]; - let program_id = nssa::program::Program::pinata().id(); - let message = - nssa::public_transaction::Message::try_new(program_id, account_ids, vec![], solution) - .unwrap(); + let program = Program::pinata(); + let instruction = solution; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let witness_set = nssa::public_transaction::WitnessSet::for_message(&message, &[]); - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(pinata_account_id), + AccountManagerAccountIdentity::Public(winner_account_id), + ], + instruction_data, + &program.into(), + ) + .await } /// Claim a pinata reward using a privacy-preserving transaction for an already-initialized diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index 096ea40c..96ed5338 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -1,7 +1,6 @@ -use common::{HashType, transaction::NSSATransaction}; +use common::HashType; use nssa::{AccountId, program::Program}; use nssa_core::{Identifier, NullifierPublicKey, SharedSecretKey, encryption::ViewingPublicKey}; -use sequencer_service_rpc::RpcClient as _; use token_core::Instruction; use crate::{AccountManagerAccountIdentity, ExecutionFailureKind, WalletCore}; @@ -16,47 +15,21 @@ impl Token<'_> { name: String, total_supply: u128, ) -> Result { - let account_ids = vec![definition_account_id, supply_account_id]; - let program_id = nssa::program::Program::token().id(); + let program = Program::token(); let instruction = Instruction::NewFungibleDefinition { name, total_supply }; - let nonces = self - .0 - .get_accounts_nonces(account_ids.clone()) + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); + + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(definition_account_id), + AccountManagerAccountIdentity::Public(supply_account_id), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - let message = nssa::public_transaction::Message::try_new( - program_id, - account_ids, - nonces, - instruction, - ) - .unwrap(); - - let def_private_key = self - .0 - .storage - .key_chain() - .pub_account_signing_key(definition_account_id) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - let supply_private_key = self - .0 - .storage - .key_chain() - .pub_account_signing_key(supply_account_id) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - - let witness_set = nssa::public_transaction::WitnessSet::for_message( - &message, - &[def_private_key, supply_private_key], - ); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_new_definition_private_owned_supply( @@ -162,62 +135,23 @@ impl Token<'_> { recipient_account_id: AccountId, amount: u128, ) -> Result { - let account_ids = vec![sender_account_id, recipient_account_id]; - let program_id = nssa::program::Program::token().id(); + let program = Program::token(); let instruction = Instruction::Transfer { amount_to_transfer: amount, }; - let mut nonces = self - .0 - .get_accounts_nonces(vec![sender_account_id]) + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); + + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(sender_account_id), + AccountManagerAccountIdentity::Public(recipient_account_id), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let mut private_keys = Vec::new(); - let sender_sk = self - .0 - .storage - .key_chain() - .pub_account_signing_key(sender_account_id) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - private_keys.push(sender_sk); - - if let Some(recipient_sk) = self - .0 - .storage - .key_chain() - .pub_account_signing_key(recipient_account_id) - { - private_keys.push(recipient_sk); - let recipient_nonces = self - .0 - .get_accounts_nonces(vec![recipient_account_id]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - nonces.extend(recipient_nonces); - } else { - println!( - "Receiver's account ({recipient_account_id}) private key not found in wallet. Proceeding with only sender's key." - ); - } - - let message = nssa::public_transaction::Message::try_new( - program_id, - account_ids, - nonces, - instruction, - ) - .unwrap(); - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &private_keys); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_transfer_transaction_private_owned_account( @@ -401,40 +335,23 @@ impl Token<'_> { holder_account_id: AccountId, amount: u128, ) -> Result { - let account_ids = vec![definition_account_id, holder_account_id]; + let program = Program::token(); let instruction = Instruction::Burn { amount_to_burn: amount, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let nonces = self - .0 - .get_accounts_nonces(vec![holder_account_id]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(definition_account_id), + AccountManagerAccountIdentity::Public(holder_account_id), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - let message = nssa::public_transaction::Message::try_new( - Program::token().id(), - account_ids, - nonces, - instruction, - ) - .expect("Instruction should serialize"); - - let signing_key = self - .0 - .storage - .key_chain() - .pub_account_signing_key(holder_account_id) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &[signing_key]); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_burn_transaction_private_owned_account( @@ -543,62 +460,23 @@ impl Token<'_> { holder_account_id: AccountId, amount: u128, ) -> Result { - let account_ids = vec![definition_account_id, holder_account_id]; + let program = Program::token(); let instruction = Instruction::Mint { amount_to_mint: amount, }; + let instruction_data = + Program::serialize_instruction(instruction).expect("Instruction should serialize"); - let mut nonces = self - .0 - .get_accounts_nonces(vec![definition_account_id]) + self.0 + .send_pub_tx( + vec![ + AccountManagerAccountIdentity::Public(definition_account_id), + AccountManagerAccountIdentity::Public(holder_account_id), + ], + instruction_data, + &program.into(), + ) .await - .map_err(ExecutionFailureKind::SequencerError)?; - - let mut private_keys = Vec::new(); - let definition_sk = self - .0 - .storage - .key_chain() - .pub_account_signing_key(definition_account_id) - .ok_or(ExecutionFailureKind::KeyNotFoundError)?; - private_keys.push(definition_sk); - - if let Some(holder_sk) = self - .0 - .storage - .key_chain() - .pub_account_signing_key(holder_account_id) - { - private_keys.push(holder_sk); - let recipient_nonces = self - .0 - .get_accounts_nonces(vec![holder_account_id]) - .await - .map_err(ExecutionFailureKind::SequencerError)?; - nonces.extend(recipient_nonces); - } else { - println!( - "Holder's account ({holder_account_id}) private key not found in wallet. Proceeding with only definition's key." - ); - } - - let message = nssa::public_transaction::Message::try_new( - Program::token().id(), - account_ids, - nonces, - instruction, - ) - .unwrap(); - let witness_set = - nssa::public_transaction::WitnessSet::for_message(&message, &private_keys); - - let tx = nssa::PublicTransaction::new(message, witness_set); - - Ok(self - .0 - .sequencer_client - .send_transaction(NSSATransaction::Public(tx)) - .await?) } pub async fn send_mint_transaction_private_owned_account(