From e94d538ad3a6e175c91c3a65a6f6b866105dd9e5 Mon Sep 17 00:00:00 2001 From: Duy Do Date: Thu, 16 Nov 2023 22:23:17 +0700 Subject: [PATCH] Stop checking for rent exemption --- .../src/associated_token_account.rs | 7 ---- .../src/compression/create_tree.rs | 12 +----- crates/cmds-solana/src/create_mint_account.rs | 5 +-- .../cmds-solana/src/create_token_account.rs | 2 +- crates/cmds-solana/src/mint_token.rs | 1 - .../cmds-solana/src/nft/arweave_nft_upload.rs | 2 +- .../nft/candy_machine_v3/add_config_lines.rs | 8 ---- .../src/nft/candy_machine_v3/initialize.rs | 8 ---- .../initialize_candy_guard.rs | 8 ---- .../src/nft/candy_machine_v3/mint.rs | 8 ---- .../src/nft/candy_machine_v3/wrap.rs | 8 ---- .../src/nft/create_master_edition.rs | 8 ---- .../src/nft/create_metadata_account.rs | 8 ---- .../src/nft/update_metadata_account.rs | 2 +- crates/cmds-solana/src/nft/v1/create_v1.rs | 8 ---- crates/cmds-solana/src/nft/v1/delegate_v1.rs | 6 --- crates/cmds-solana/src/nft/v1/mint_v1.rs | 8 ---- crates/cmds-solana/src/nft/v1/update_v1.rs | 6 --- .../src/nft/v1/verify_collection_v1.rs | 8 ---- .../src/nft/v1/verify_creator_v1.rs | 12 +----- crates/cmds-solana/src/transfer_sol.rs | 2 +- crates/cmds-solana/src/transfer_token.rs | 42 +++++++------------ crates/cmds-solana/src/utils.rs | 9 ---- .../wormhole/nft_bridge/complete_native.rs | 8 ---- .../wormhole/nft_bridge/complete_wrapped.rs | 8 ---- .../nft_bridge/complete_wrapped_meta.rs | 8 ---- .../wormhole/nft_bridge/transfer_native.rs | 8 ---- .../wormhole/nft_bridge/transfer_wrapped.rs | 8 ---- .../cmds-solana/src/wormhole/post_message.rs | 8 ---- crates/cmds-solana/src/wormhole/post_vaa.rs | 8 ---- .../src/wormhole/token_bridge/attest.rs | 8 ---- .../wormhole/token_bridge/complete_native.rs | 8 ---- .../token_bridge/complete_transfer_wrapped.rs | 8 ---- .../wormhole/token_bridge/create_wrapped.rs | 8 ---- .../src/wormhole/token_bridge/initialize.rs | 9 ---- .../wormhole/token_bridge/transfer_native.rs | 8 ---- .../wormhole/token_bridge/transfer_wrapped.rs | 8 ---- .../src/wormhole/verify_signatures.rs | 8 ---- crates/flow-server/src/api/mod.rs | 2 +- crates/flow-server/src/db_worker/mod.rs | 2 +- lib/flow-lib/src/solana.rs | 12 ------ 41 files changed, 28 insertions(+), 297 deletions(-) diff --git a/crates/cmds-solana/src/associated_token_account.rs b/crates/cmds-solana/src/associated_token_account.rs index 5ef6cf56..a98f3994 100644 --- a/crates/cmds-solana/src/associated_token_account.rs +++ b/crates/cmds-solana/src/associated_token_account.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use solana_program::program_pack::Pack; use spl_associated_token_account::instruction::create_associated_token_account; const SOLANA_ASSOCIATED_TOKEN_ACCOUNT: &str = "associated_token_account"; @@ -39,11 +38,6 @@ pub struct Output { } async fn run(mut ctx: Context, input: Input) -> Result { - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(spl_token::state::Account::LEN) - .await?; - let instruction = create_associated_token_account( &input.fee_payer.pubkey(), &input.owner, @@ -57,7 +51,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { Instructions { fee_payer: input.fee_payer.pubkey(), signers: [input.fee_payer.clone_keypair()].into(), - minimum_balance_for_rent_exemption, instructions: [instruction].into(), } } else { diff --git a/crates/cmds-solana/src/compression/create_tree.rs b/crates/cmds-solana/src/compression/create_tree.rs index 3d3562e8..6a805d55 100644 --- a/crates/cmds-solana/src/compression/create_tree.rs +++ b/crates/cmds-solana/src/compression/create_tree.rs @@ -10,8 +10,7 @@ use std::mem::size_of; // Command Name const CREATE_TREE: &str = "create_tree"; -const DEFINITION: &str = - flow_lib::node_definition!("solana/compression/create_tree.json"); +const DEFINITION: &str = flow_lib::node_definition!("solana/compression/create_tree.json"); fn build() -> BuildResult { use once_cell::sync::Lazy; @@ -254,13 +253,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { } .data(); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -278,7 +270,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { }, ] .into(), - minimum_balance_for_rent_exemption, + }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/create_mint_account.rs b/crates/cmds-solana/src/create_mint_account.rs index 43cf371f..3dbf56b3 100644 --- a/crates/cmds-solana/src/create_mint_account.rs +++ b/crates/cmds-solana/src/create_mint_account.rs @@ -44,7 +44,7 @@ pub struct Output { } async fn run(mut ctx: Context, input: Input) -> Result { - let minimum_balance_for_rent_exemption = ctx + let lamports = ctx .solana_client .get_minimum_balance_for_rent_exemption(Mint::LEN) .await?; @@ -61,7 +61,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { system_instruction::create_account( &input.fee_payer.pubkey(), &input.mint_account.pubkey(), - minimum_balance_for_rent_exemption, + lamports, Mint::LEN as u64, &spl_token::id(), ), @@ -75,7 +75,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { spl_memo::build_memo(input.memo.as_bytes(), &[&input.fee_payer.pubkey()]), ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/create_token_account.rs b/crates/cmds-solana/src/create_token_account.rs index ad28aae0..eed6f456 100644 --- a/crates/cmds-solana/src/create_token_account.rs +++ b/crates/cmds-solana/src/create_token_account.rs @@ -88,7 +88,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { input.token_account.clone_keypair(), ] .into(), - minimum_balance_for_rent_exemption, + instructions, } } else { diff --git a/crates/cmds-solana/src/mint_token.rs b/crates/cmds-solana/src/mint_token.rs index 18ab43a5..bbef36f9 100644 --- a/crates/cmds-solana/src/mint_token.rs +++ b/crates/cmds-solana/src/mint_token.rs @@ -72,7 +72,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { decimals, )?] .into(), - minimum_balance_for_rent_exemption: 0, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/arweave_nft_upload.rs b/crates/cmds-solana/src/nft/arweave_nft_upload.rs index bea17420..096be8a1 100644 --- a/crates/cmds-solana/src/nft/arweave_nft_upload.rs +++ b/crates/cmds-solana/src/nft/arweave_nft_upload.rs @@ -328,7 +328,7 @@ impl Uploader { let instruction = solana_sdk::system_instruction::transfer(&self.fee_payer.pubkey(), &recipient, amount); let (mut tx, recent_blockhash) = - execute(&self.client, &self.fee_payer.pubkey(), &[instruction], 0).await?; + execute(&self.client, &self.fee_payer.pubkey(), &[instruction]).await?; try_sign_wallet(signer, &mut tx, &[&self.fee_payer], recent_blockhash).await?; diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/add_config_lines.rs b/crates/cmds-solana/src/nft/candy_machine_v3/add_config_lines.rs index b1a652ff..e4aedc7d 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/add_config_lines.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/add_config_lines.rs @@ -57,13 +57,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { } .data(); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_candy_machine_core::accounts::AddConfigLines, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair(), input.authority.clone_keypair()].into(), @@ -73,7 +66,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data, }] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs b/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs index 820490ca..ef2ec3be 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/initialize.rs @@ -135,13 +135,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { &mpl_candy_machine_core::id(), ); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_candy_machine_core::accounts::Initialize, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -159,7 +152,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { }, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/initialize_candy_guard.rs b/crates/cmds-solana/src/nft/candy_machine_v3/initialize_candy_guard.rs index dc127925..38a350d6 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/initialize_candy_guard.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/initialize_candy_guard.rs @@ -69,13 +69,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { } .data(); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_candy_guard::accounts::Initialize, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair(), input.base.clone_keypair()].into(), @@ -85,7 +78,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data, }] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs b/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs index f2ffcc28..ae50eefd 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/mint.rs @@ -156,13 +156,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { } .data(); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_candy_machine_core::accounts::MintV2, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -180,7 +173,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { }, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/candy_machine_v3/wrap.rs b/crates/cmds-solana/src/nft/candy_machine_v3/wrap.rs index 6391e009..23b5ba51 100644 --- a/crates/cmds-solana/src/nft/candy_machine_v3/wrap.rs +++ b/crates/cmds-solana/src/nft/candy_machine_v3/wrap.rs @@ -53,13 +53,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { let data = mpl_candy_guard::instruction::Wrap {}.data(); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption( - std::mem::size_of::(), - ) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -74,7 +67,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data, }] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/create_master_edition.rs b/crates/cmds-solana/src/nft/create_master_edition.rs index 0d2d2a4e..6027e302 100644 --- a/crates/cmds-solana/src/nft/create_master_edition.rs +++ b/crates/cmds-solana/src/nft/create_master_edition.rs @@ -47,13 +47,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { let (master_edition_account, _) = MasterEdition::find_pda(&input.mint_account); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::MasterEdition, - >()) - .await?; - let create_ix = mpl_token_metadata::instructions::CreateMasterEditionV3 { edition: master_edition_account, mint: input.mint_account, @@ -80,7 +73,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [create_ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/create_metadata_account.rs b/crates/cmds-solana/src/nft/create_metadata_account.rs index b1c32bbc..879c2a2f 100644 --- a/crates/cmds-solana/src/nft/create_metadata_account.rs +++ b/crates/cmds-solana/src/nft/create_metadata_account.rs @@ -51,13 +51,6 @@ pub struct Output { async fn run(mut ctx: Context, input: Input) -> Result { let (metadata_account, _) = Metadata::find_pda(&input.mint_account); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::Metadata, - >()) - .await?; - let create_ix = mpl_token_metadata::instructions::CreateMetadataAccountV3 { metadata: metadata_account, mint: input.mint_account, @@ -85,7 +78,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [ins].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/update_metadata_account.rs b/crates/cmds-solana/src/nft/update_metadata_account.rs index 2de96402..66bacb15 100644 --- a/crates/cmds-solana/src/nft/update_metadata_account.rs +++ b/crates/cmds-solana/src/nft/update_metadata_account.rs @@ -53,7 +53,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { input.update_authority.clone_keypair(), ] .into(), - minimum_balance_for_rent_exemption: 0, + instructions: [ mpl_token_metadata::instruction::update_metadata_accounts_v2( mpl_token_metadata::id(), diff --git a/crates/cmds-solana/src/nft/v1/create_v1.rs b/crates/cmds-solana/src/nft/v1/create_v1.rs index e5d0843d..205e44a6 100644 --- a/crates/cmds-solana/src/nft/v1/create_v1.rs +++ b/crates/cmds-solana/src/nft/v1/create_v1.rs @@ -69,13 +69,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { // &input.mint_account.pubkey(), // ); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::MasterEdition, - >()) - .await?; - let create_ix = mpl_token_metadata::instructions::CreateV1 { metadata: metadata_account, master_edition: Some(master_edition_account), @@ -161,7 +154,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [create_ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/v1/delegate_v1.rs b/crates/cmds-solana/src/nft/v1/delegate_v1.rs index b602c800..0c3e64da 100644 --- a/crates/cmds-solana/src/nft/v1/delegate_v1.rs +++ b/crates/cmds-solana/src/nft/v1/delegate_v1.rs @@ -114,11 +114,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { DelegateType::Token(..) => TokenRecord::find_pda(&input.mint_account, &token_account).0, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::()) - .await?; - let delegate_v1 = DelegateV1 { delegate_record: Some(delegate_record), delegate: input.delegate.pubkey(), @@ -147,7 +142,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [create_ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/v1/mint_v1.rs b/crates/cmds-solana/src/nft/v1/mint_v1.rs index d3d2874c..c34829fa 100644 --- a/crates/cmds-solana/src/nft/v1/mint_v1.rs +++ b/crates/cmds-solana/src/nft/v1/mint_v1.rs @@ -64,13 +64,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { let token_record = TokenRecord::find_pda(&input.mint_account, &token_account).0; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::MasterEdition, - >()) - .await?; - let create_ix = mpl_token_metadata::instructions::MintV1 { metadata: metadata_account, master_edition: Some(master_edition_account), @@ -104,7 +97,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [create_ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/v1/update_v1.rs b/crates/cmds-solana/src/nft/v1/update_v1.rs index 5e34a028..94081319 100644 --- a/crates/cmds-solana/src/nft/v1/update_v1.rs +++ b/crates/cmds-solana/src/nft/v1/update_v1.rs @@ -78,11 +78,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { .expect("update_authority field must be set") }); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::()) - .await?; - let delegate_v1 = UpdateAsDelegateV1 { authority: authority_or_delegate.pubkey(), delegate_record: input.delegate_record, @@ -109,7 +104,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [create_ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/v1/verify_collection_v1.rs b/crates/cmds-solana/src/nft/v1/verify_collection_v1.rs index f294805c..6443af6b 100644 --- a/crates/cmds-solana/src/nft/v1/verify_collection_v1.rs +++ b/crates/cmds-solana/src/nft/v1/verify_collection_v1.rs @@ -46,13 +46,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { let (collection_master_edition, _) = MasterEdition::find_pda(&input.collection_mint_account); - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::MasterEdition, - >()) - .await?; - let accounts = mpl_token_metadata::instructions::VerifyCollectionV1 { authority: input.collection_authority.pubkey(), delegate_record: input.delegate_record, @@ -74,7 +67,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [ins].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/nft/v1/verify_creator_v1.rs b/crates/cmds-solana/src/nft/v1/verify_creator_v1.rs index 63f5d196..3d8e0eee 100644 --- a/crates/cmds-solana/src/nft/v1/verify_creator_v1.rs +++ b/crates/cmds-solana/src/nft/v1/verify_creator_v1.rs @@ -52,20 +52,13 @@ async fn run(mut ctx: Context, input: Input) -> Result { collection_master_edition = Some(master_edition); } - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_token_metadata::accounts::MasterEdition, - >()) - .await?; - let accounts = mpl_token_metadata::instructions::VerifyCreatorV1 { authority: input.authority.pubkey(), delegate_record: input.delegate_record, metadata: input.metadata, collection_mint: input.collection_mint_account, - collection_metadata: collection_metadata, - collection_master_edition: collection_master_edition, + collection_metadata, + collection_master_edition, system_program: system_program::id(), sysvar_instructions: sysvar::instructions::id(), }; @@ -80,7 +73,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [ins].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/transfer_sol.rs b/crates/cmds-solana/src/transfer_sol.rs index 789af931..858fbe8d 100644 --- a/crates/cmds-solana/src/transfer_sol.rs +++ b/crates/cmds-solana/src/transfer_sol.rs @@ -42,7 +42,7 @@ async fn run(mut ctx: Context, input: Input) -> Result { Instructions { fee_payer: input.sender.pubkey(), signers: vec![input.sender.clone_keypair()], - minimum_balance_for_rent_exemption: 0, + instructions: [instruction].into(), } } else { diff --git a/crates/cmds-solana/src/transfer_token.rs b/crates/cmds-solana/src/transfer_token.rs index c3055e87..e9c77c62 100644 --- a/crates/cmds-solana/src/transfer_token.rs +++ b/crates/cmds-solana/src/transfer_token.rs @@ -44,7 +44,7 @@ async fn command_transfer_token( allow_unfunded_recipient: bool, fund_recipient: bool, memo: String, -) -> crate::Result<(u64, Vec, Pubkey)> { +) -> crate::Result<(Vec, Pubkey)> { let sender = if let Some(sender) = sender { sender } else { @@ -78,7 +78,6 @@ async fn command_transfer_token( }; let mut recipient_token_account = recipient; - let mut minimum_balance_for_rent_exemption = 0; let recipient_is_token_account = { let recipient_account_info = client @@ -123,9 +122,6 @@ async fn command_transfer_token( if needs_funding { if fund_recipient { - minimum_balance_for_rent_exemption += client - .get_minimum_balance_for_rent_exemption(spl_token::state::Account::LEN) - .await?; instructions.push(instruction::create_associated_token_account( fee_payer, &recipient, @@ -152,11 +148,7 @@ async fn command_transfer_token( instructions.push(spl_memo::build_memo(memo.as_bytes(), &[fee_payer])); - Ok(( - minimum_balance_for_rent_exemption, - instructions, - recipient_token_account, - )) + Ok((instructions, recipient_token_account)) } #[derive(Serialize, Deserialize, Debug)] @@ -191,21 +183,20 @@ pub struct Output { } async fn run(mut ctx: Context, input: Input) -> Result { - let (minimum_balance_for_rent_exemption, instructions, recipient_token_account) = - command_transfer_token( - &ctx.solana_client, - &input.fee_payer.pubkey(), - input.mint_account, - input.amount, - input.decimals, - input.recipient, - input.sender_token_account, - input.sender_owner.pubkey(), - input.allow_unfunded, - input.fund_recipient, - input.memo, - ) - .await?; + let (instructions, recipient_token_account) = command_transfer_token( + &ctx.solana_client, + &input.fee_payer.pubkey(), + input.mint_account, + input.amount, + input.decimals, + input.recipient, + input.sender_token_account, + input.sender_owner.pubkey(), + input.allow_unfunded, + input.fund_recipient, + input.memo, + ) + .await?; let instructions = if input.submit { Instructions { @@ -215,7 +206,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { input.sender_owner.clone_keypair(), ] .into(), - minimum_balance_for_rent_exemption, instructions, } } else { diff --git a/crates/cmds-solana/src/utils.rs b/crates/cmds-solana/src/utils.rs index 2e468dbc..ebd058ad 100644 --- a/crates/cmds-solana/src/utils.rs +++ b/crates/cmds-solana/src/utils.rs @@ -21,20 +21,11 @@ pub async fn execute( client: &RpcClient, fee_payer: &Pubkey, instructions: &[Instruction], - minimum_balance_for_rent_exemption: u64, ) -> crate::Result<(Transaction, Hash)> { let recent_blockhash = client.get_latest_blockhash().await?; let message = Message::new_with_blockhash(instructions, Some(fee_payer), &recent_blockhash); - let balance = client.get_balance(fee_payer).await?; - - let needed = minimum_balance_for_rent_exemption + client.get_fee_for_message(&message).await?; - - if balance < needed { - return Err(crate::Error::InsufficientSolanaBalance { balance, needed }); - } - let transaction = Transaction::new_unsigned(message); Ok((transaction, recent_blockhash)) diff --git a/crates/cmds-solana/src/wormhole/nft_bridge/complete_native.rs b/crates/cmds-solana/src/wormhole/nft_bridge/complete_native.rs index 404f9336..82fcc8f7 100644 --- a/crates/cmds-solana/src/wormhole/nft_bridge/complete_native.rs +++ b/crates/cmds-solana/src/wormhole/nft_bridge/complete_native.rs @@ -138,18 +138,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (NFTBridgeInstructions::CompleteNative, CompleteNativeData {}).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped.rs b/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped.rs index 80040a7c..5b3bb17a 100644 --- a/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped.rs +++ b/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped.rs @@ -168,18 +168,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped_meta.rs b/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped_meta.rs index 25ad0ae2..2c341c79 100644 --- a/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped_meta.rs +++ b/crates/cmds-solana/src/wormhole/nft_bridge/complete_wrapped_meta.rs @@ -149,18 +149,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/nft_bridge/transfer_native.rs b/crates/cmds-solana/src/wormhole/nft_bridge/transfer_native.rs index 737d3127..063156f1 100644 --- a/crates/cmds-solana/src/wormhole/nft_bridge/transfer_native.rs +++ b/crates/cmds-solana/src/wormhole/nft_bridge/transfer_native.rs @@ -127,13 +127,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (NFTBridgeInstructions::TransferNative, data).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair(), input.message.clone_keypair()].into(), @@ -150,7 +143,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ix, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/nft_bridge/transfer_wrapped.rs b/crates/cmds-solana/src/wormhole/nft_bridge/transfer_wrapped.rs index 12a6b4d3..97c8e4a6 100644 --- a/crates/cmds-solana/src/wormhole/nft_bridge/transfer_wrapped.rs +++ b/crates/cmds-solana/src/wormhole/nft_bridge/transfer_wrapped.rs @@ -148,13 +148,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (NFTBridgeInstructions::TransferWrapped, wrapped_data).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -164,7 +157,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/post_message.rs b/crates/cmds-solana/src/wormhole/post_message.rs index c6532f1c..9c79f070 100644 --- a/crates/cmds-solana/src/wormhole/post_message.rs +++ b/crates/cmds-solana/src/wormhole/post_message.rs @@ -86,13 +86,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - // Get message fee let bridge_config_account = ctx.solana_client.get_account(&bridge).await?; let bridge_config = BridgeData::try_from_slice(bridge_config_account.data.as_slice())?; @@ -111,7 +104,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ix, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/post_vaa.rs b/crates/cmds-solana/src/wormhole/post_vaa.rs index de7b1d83..afe71e9a 100644 --- a/crates/cmds-solana/src/wormhole/post_vaa.rs +++ b/crates/cmds-solana/src/wormhole/post_vaa.rs @@ -73,18 +73,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (WormholeInstructions::PostVAA, vaa).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/attest.rs b/crates/cmds-solana/src/wormhole/token_bridge/attest.rs index f9f4b7a1..8ecd4ef8 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/attest.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/attest.rs @@ -107,18 +107,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair(), input.message.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/complete_native.rs b/crates/cmds-solana/src/wormhole/token_bridge/complete_native.rs index 7e32b344..f97f93f6 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/complete_native.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/complete_native.rs @@ -140,18 +140,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/complete_transfer_wrapped.rs b/crates/cmds-solana/src/wormhole/token_bridge/complete_transfer_wrapped.rs index 4acc3ed9..22b5455b 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/complete_transfer_wrapped.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/complete_transfer_wrapped.rs @@ -152,18 +152,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/create_wrapped.rs b/crates/cmds-solana/src/wormhole/token_bridge/create_wrapped.rs index 2ca80afd..de6831c3 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/create_wrapped.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/create_wrapped.rs @@ -149,18 +149,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (TokenBridgeInstructions::CreateWrapped, CreateWrappedData {}).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/initialize.rs b/crates/cmds-solana/src/wormhole/token_bridge/initialize.rs index 7f6ac43b..7c386eef 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/initialize.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/initialize.rs @@ -61,19 +61,10 @@ async fn run(mut ctx: Context, input: Input) -> Result { .try_to_vec()?, }; - //FIXME fix all sizes - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair()].into(), instructions: [ix].into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/transfer_native.rs b/crates/cmds-solana/src/wormhole/token_bridge/transfer_native.rs index 25e9cbd1..0db2a434 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/transfer_native.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/transfer_native.rs @@ -120,13 +120,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (TokenBridgeInstructions::TransferNative, wrapped_data).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [input.payer.clone_keypair(), input.message.clone_keypair()].into(), @@ -143,7 +136,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ix, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/token_bridge/transfer_wrapped.rs b/crates/cmds-solana/src/wormhole/token_bridge/transfer_wrapped.rs index 88c16a52..754885b1 100644 --- a/crates/cmds-solana/src/wormhole/token_bridge/transfer_wrapped.rs +++ b/crates/cmds-solana/src/wormhole/token_bridge/transfer_wrapped.rs @@ -128,13 +128,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { data: (TokenBridgeInstructions::TransferWrapped, wrapped_data).try_to_vec()?, }; - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -156,7 +149,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ix, ] .into(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/cmds-solana/src/wormhole/verify_signatures.rs b/crates/cmds-solana/src/wormhole/verify_signatures.rs index 4eaadbba..3acb5a7c 100644 --- a/crates/cmds-solana/src/wormhole/verify_signatures.rs +++ b/crates/cmds-solana/src/wormhole/verify_signatures.rs @@ -129,13 +129,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { verify_txs.push(vec![secp_ix, verify_ix]) } - let minimum_balance_for_rent_exemption = ctx - .solana_client - .get_minimum_balance_for_rent_exemption(std::mem::size_of::< - mpl_bubblegum::accounts::CreateTree, - >()) - .await?; - let ins = Instructions { fee_payer: input.payer.pubkey(), signers: [ @@ -144,7 +137,6 @@ async fn run(mut ctx: Context, input: Input) -> Result { ] .into(), instructions: verify_txs.concat(), - minimum_balance_for_rent_exemption, }; let ins = input.submit.then_some(ins).unwrap_or_default(); diff --git a/crates/flow-server/src/api/mod.rs b/crates/flow-server/src/api/mod.rs index f0def000..be641603 100644 --- a/crates/flow-server/src/api/mod.rs +++ b/crates/flow-server/src/api/mod.rs @@ -3,8 +3,8 @@ pub mod confirm_auth; pub mod init_auth; pub mod start_flow; -pub mod stop_flow; pub mod start_flow_shared; +pub mod stop_flow; pub mod clone_flow; diff --git a/crates/flow-server/src/db_worker/mod.rs b/crates/flow-server/src/db_worker/mod.rs index da4770b3..5b68e6ec 100644 --- a/crates/flow-server/src/db_worker/mod.rs +++ b/crates/flow-server/src/db_worker/mod.rs @@ -12,9 +12,9 @@ use utils::address_book::{AddressBook, ManagableActor}; pub mod flow_run_worker; pub mod messages; +pub mod signer; pub mod token_worker; pub mod user_worker; -pub mod signer; pub use flow_run_worker::FlowRunWorker; pub use user_worker::UserWorker; diff --git a/lib/flow-lib/src/solana.rs b/lib/flow-lib/src/solana.rs index f0ab867a..8b60d5f8 100644 --- a/lib/flow-lib/src/solana.rs +++ b/lib/flow-lib/src/solana.rs @@ -84,7 +84,6 @@ impl KeypairExt for Keypair { pub struct Instructions { pub fee_payer: Pubkey, pub signers: Vec, - pub minimum_balance_for_rent_exemption: u64, pub instructions: Vec, } @@ -94,9 +93,6 @@ impl Instructions { return Err(next); } - // TODO: is += the right operation - self.minimum_balance_for_rent_exemption += next.minimum_balance_for_rent_exemption; - // TODO: sort and dedup? self.signers.extend(next.signers); @@ -107,7 +103,6 @@ impl Instructions { pub async fn execute(self, rpc: &RpcClient, signer: signer::Svc) -> Result { let recent_blockhash = rpc.get_latest_blockhash().await?; - let balance: u64 = rpc.get_balance(&self.fee_payer).await?; let message = Message::new_with_blockhash( &self.instructions, @@ -115,13 +110,6 @@ impl Instructions { &recent_blockhash, ); - let needed = - self.minimum_balance_for_rent_exemption + rpc.get_fee_for_message(&message).await?; - - if balance < needed { - return Err(Error::InsufficientSolanaBalance { balance, needed }); - } - let mut tx = Transaction::new_unsigned(message); let msg: Bytes = tx.message_data().into();