From 43e7fa9be245a6ddb6edefc9e8e91d87c6b3f6ed Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Tue, 19 May 2026 17:54:25 +0300 Subject: [PATCH] fix(wallet): no sign option added --- wallet/src/account_manager.rs | 15 ++++- wallet/src/program_facades/amm.rs | 84 ++++++++++++++++++++-------- wallet/src/program_facades/ata.rs | 12 ++-- wallet/src/program_facades/pinata.rs | 4 +- wallet/src/program_facades/token.rs | 2 +- 5 files changed, 85 insertions(+), 32 deletions(-) diff --git a/wallet/src/account_manager.rs b/wallet/src/account_manager.rs index 0f43baf2..5a209d27 100644 --- a/wallet/src/account_manager.rs +++ b/wallet/src/account_manager.rs @@ -13,6 +13,8 @@ use crate::{ExecutionFailureKind, WalletCore}; #[derive(Clone)] pub enum AccountManagerAccountIdentity { Public(AccountId), + /// A public account without signing. Would not try to sign, even if account is owned. + PublicNoSign(AccountId), PrivateOwned(AccountId), PrivateForeign { npk: NullifierPublicKey, @@ -53,7 +55,7 @@ pub enum AccountManagerAccountIdentity { impl AccountManagerAccountIdentity { #[must_use] pub const fn is_public(&self) -> bool { - matches!(&self, Self::Public(_)) + matches!(&self, Self::Public(_) | Self::PublicNoSign(_)) } #[must_use] @@ -109,6 +111,17 @@ impl AccountManager { State::Public { account, sk } } + AccountManagerAccountIdentity::PublicNoSign(account_id) => { + let acc = wallet + .get_account_public(account_id) + .await + .map_err(ExecutionFailureKind::SequencerError)?; + + let sk = None; + let account = AccountWithMetadata::new(acc.clone(), sk.is_some(), account_id); + + State::Public { account, sk } + } AccountManagerAccountIdentity::PrivateOwned(account_id) => { let pre = private_key_tree_acc_preparation(wallet, account_id, false).await?; diff --git a/wallet/src/program_facades/amm.rs b/wallet/src/program_facades/amm.rs index 189c79f1..43352386 100644 --- a/wallet/src/program_facades/amm.rs +++ b/wallet/src/program_facades/amm.rs @@ -51,10 +51,10 @@ impl Amm<'_> { 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::PublicNoSign(amm_pool), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_a), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_b), + AccountManagerAccountIdentity::PublicNoSign(pool_lp), AccountManagerAccountIdentity::Public(user_holding_a), AccountManagerAccountIdentity::Public(user_holding_b), AccountManagerAccountIdentity::Public(user_holding_lp), @@ -105,14 +105,34 @@ impl Amm<'_> { let instruction_data = Program::serialize_instruction(instruction).expect("Instruction should serialize"); + if (token_definition_id_in != definition_token_a_id) + && (token_definition_id_in != definition_token_b_id) + { + return Err(ExecutionFailureKind::AccountDataError( + token_definition_id_in, + )); + } + + let user_a_signing_indentity = if token_definition_id_in == definition_token_a_id { + AccountManagerAccountIdentity::Public(user_holding_a) + } else { + AccountManagerAccountIdentity::PublicNoSign(user_holding_a) + }; + + let user_b_signing_indentity = if token_definition_id_in == definition_token_b_id { + AccountManagerAccountIdentity::Public(user_holding_b) + } else { + AccountManagerAccountIdentity::PublicNoSign(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(user_holding_a), - AccountManagerAccountIdentity::Public(user_holding_b), + AccountManagerAccountIdentity::PublicNoSign(amm_pool), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_a), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_b), + user_a_signing_indentity, + user_b_signing_indentity, ], instruction_data, &program.into(), @@ -160,14 +180,34 @@ impl Amm<'_> { let instruction_data = Program::serialize_instruction(instruction).expect("Instruction should serialize"); + if (token_definition_id_in != definition_token_a_id) + && (token_definition_id_in != definition_token_b_id) + { + return Err(ExecutionFailureKind::AccountDataError( + token_definition_id_in, + )); + } + + let user_a_signing_indentity = if token_definition_id_in == definition_token_a_id { + AccountManagerAccountIdentity::Public(user_holding_a) + } else { + AccountManagerAccountIdentity::PublicNoSign(user_holding_a) + }; + + let user_b_signing_indentity = if token_definition_id_in == definition_token_b_id { + AccountManagerAccountIdentity::Public(user_holding_b) + } else { + AccountManagerAccountIdentity::PublicNoSign(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(user_holding_a), - AccountManagerAccountIdentity::Public(user_holding_b), + user_a_signing_indentity, + user_b_signing_indentity, ], instruction_data, &program.into(), @@ -220,13 +260,13 @@ impl Amm<'_> { 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::PublicNoSign(amm_pool), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_a), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_b), + AccountManagerAccountIdentity::PublicNoSign(pool_lp), AccountManagerAccountIdentity::Public(user_holding_a), AccountManagerAccountIdentity::Public(user_holding_b), - AccountManagerAccountIdentity::Public(user_holding_lp), + AccountManagerAccountIdentity::PublicNoSign(user_holding_lp), ], instruction_data, &program.into(), @@ -279,12 +319,12 @@ impl Amm<'_> { 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::PublicNoSign(amm_pool), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_a), + AccountManagerAccountIdentity::PublicNoSign(vault_holding_b), + AccountManagerAccountIdentity::PublicNoSign(pool_lp), + AccountManagerAccountIdentity::PublicNoSign(user_holding_a), + AccountManagerAccountIdentity::PublicNoSign(user_holding_b), AccountManagerAccountIdentity::Public(user_holding_lp), ], instruction_data, diff --git a/wallet/src/program_facades/ata.rs b/wallet/src/program_facades/ata.rs index d6e3fea8..e7131b39 100644 --- a/wallet/src/program_facades/ata.rs +++ b/wallet/src/program_facades/ata.rs @@ -31,8 +31,8 @@ impl Ata<'_> { .send_pub_tx( vec![ AccountManagerAccountIdentity::Public(owner_id), - AccountManagerAccountIdentity::Public(definition_id), - AccountManagerAccountIdentity::Public(ata_id), + AccountManagerAccountIdentity::PublicNoSign(definition_id), + AccountManagerAccountIdentity::PublicNoSign(ata_id), ], instruction_data, &program.into(), @@ -64,8 +64,8 @@ impl Ata<'_> { .send_pub_tx( vec![ AccountManagerAccountIdentity::Public(owner_id), - AccountManagerAccountIdentity::Public(sender_ata_id), - AccountManagerAccountIdentity::Public(recipient_id), + AccountManagerAccountIdentity::PublicNoSign(sender_ata_id), + AccountManagerAccountIdentity::PublicNoSign(recipient_id), ], instruction_data, &program.into(), @@ -96,8 +96,8 @@ impl Ata<'_> { .send_pub_tx( vec![ AccountManagerAccountIdentity::Public(owner_id), - AccountManagerAccountIdentity::Public(holder_ata_id), - AccountManagerAccountIdentity::Public(definition_id), + AccountManagerAccountIdentity::PublicNoSign(holder_ata_id), + AccountManagerAccountIdentity::PublicNoSign(definition_id), ], instruction_data, &program.into(), diff --git a/wallet/src/program_facades/pinata.rs b/wallet/src/program_facades/pinata.rs index e933787d..0c3a599b 100644 --- a/wallet/src/program_facades/pinata.rs +++ b/wallet/src/program_facades/pinata.rs @@ -21,8 +21,8 @@ impl Pinata<'_> { self.0 .send_pub_tx( vec![ - AccountManagerAccountIdentity::Public(pinata_account_id), - AccountManagerAccountIdentity::Public(winner_account_id), + AccountManagerAccountIdentity::PublicNoSign(pinata_account_id), + AccountManagerAccountIdentity::PublicNoSign(winner_account_id), ], instruction_data, &program.into(), diff --git a/wallet/src/program_facades/token.rs b/wallet/src/program_facades/token.rs index 96ed5338..2de2b796 100644 --- a/wallet/src/program_facades/token.rs +++ b/wallet/src/program_facades/token.rs @@ -345,7 +345,7 @@ impl Token<'_> { self.0 .send_pub_tx( vec![ - AccountManagerAccountIdentity::Public(definition_account_id), + AccountManagerAccountIdentity::PublicNoSign(definition_account_id), AccountManagerAccountIdentity::Public(holder_account_id), ], instruction_data,