diff --git a/solana/bridge/program/src/types.rs b/solana/bridge/program/src/types.rs index 2a26f5c01..530445aac 100644 --- a/solana/bridge/program/src/types.rs +++ b/solana/bridge/program/src/types.rs @@ -94,12 +94,21 @@ pub struct BridgeData { pub config: BridgeConfig, } +#[cfg(not(feature = "cpi"))] impl Owned for BridgeData { fn owner(&self) -> AccountOwner { AccountOwner::This } } +#[cfg(feature = "cpi")] +impl Owned for BridgeData { + fn owner(&self) -> AccountOwner { + use std::str::FromStr; + AccountOwner::Other(Pubkey::from_str(env!("BRIDGE_ADDRESS")).unwrap()) + } +} + #[derive(Default, BorshSerialize, BorshDeserialize)] pub struct SignatureSet { /// Signatures of validators diff --git a/solana/modules/token_bridge/program/src/api/attest.rs b/solana/modules/token_bridge/program/src/api/attest.rs index 69ff7fc78..f0113bd2e 100644 --- a/solana/modules/token_bridge/program/src/api/attest.rs +++ b/solana/modules/token_bridge/program/src/api/attest.rs @@ -18,6 +18,7 @@ use crate::{ }, }; use bridge::{ + accounts::Bridge, api::{ PostMessage, PostMessageData, @@ -76,7 +77,7 @@ pub struct AttestToken<'b> { pub spl_metadata: SplTokenMeta<'b>, /// CPI Context - pub bridge: Mut>, + pub bridge: Mut>, /// Account to store the posted message pub message: Signer>>, @@ -123,8 +124,11 @@ pub fn attest_token( data: AttestTokenData, ) -> Result<()> { // Pay fee - let transfer_ix = - solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); + let transfer_ix = solana_program::system_instruction::transfer( + accs.payer.key, + accs.fee_collector.key, + accs.bridge.config.fee, + ); invoke(&transfer_ix, ctx.accounts)?; @@ -171,7 +175,7 @@ pub fn attest_token( accs.config.wormhole_bridge, params.try_to_vec()?.as_slice(), vec![ - AccountMeta::new(*accs.bridge.key, false), + AccountMeta::new(*accs.bridge.info().key, false), AccountMeta::new(*accs.message.key, true), AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new(*accs.sequence.key, false), diff --git a/solana/modules/token_bridge/program/src/api/transfer.rs b/solana/modules/token_bridge/program/src/api/transfer.rs index fa12d68c7..eeb6c2b3f 100644 --- a/solana/modules/token_bridge/program/src/api/transfer.rs +++ b/solana/modules/token_bridge/program/src/api/transfer.rs @@ -18,6 +18,7 @@ use crate::{ TokenBridgeError::WrongAccountOwner, }; use bridge::{ + accounts::Bridge, api::{ PostMessage, PostMessageData, @@ -80,7 +81,7 @@ pub struct TransferNative<'b> { pub custody_signer: CustodySigner<'b>, /// CPI Context - pub bridge: Mut>, + pub bridge: Mut>, /// Account to store the posted message pub message: Signer>>, @@ -171,8 +172,11 @@ pub fn transfer_native( invoke_seeded(&transfer_ix, ctx, &accs.authority_signer, None)?; // Pay fee - let transfer_ix = - solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); + let transfer_ix = solana_program::system_instruction::transfer( + accs.payer.key, + accs.fee_collector.key, + accs.bridge.config.fee, + ); invoke(&transfer_ix, ctx.accounts)?; // Post message @@ -197,7 +201,7 @@ pub fn transfer_native( accs.config.wormhole_bridge, params.try_to_vec()?.as_slice(), vec![ - AccountMeta::new(*accs.bridge.key, false), + AccountMeta::new(*accs.bridge.info().key, false), AccountMeta::new(*accs.message.key, true), AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new(*accs.sequence.key, false), @@ -226,7 +230,7 @@ pub struct TransferWrapped<'b> { pub authority_signer: AuthoritySigner<'b>, /// CPI Context - pub bridge: Mut>, + pub bridge: Mut>, /// Account to store the posted message pub message: Signer>>, @@ -304,8 +308,12 @@ pub fn transfer_wrapped( invoke_seeded(&burn_ix, ctx, &accs.authority_signer, None)?; // Pay fee - let transfer_ix = - solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); + let transfer_ix = solana_program::system_instruction::transfer( + accs.payer.key, + accs.fee_collector.key, + accs.bridge.config.fee, + ); + invoke(&transfer_ix, ctx.accounts)?; // Post message @@ -330,7 +338,7 @@ pub fn transfer_wrapped( accs.config.wormhole_bridge, params.try_to_vec()?.as_slice(), vec![ - AccountMeta::new(*accs.bridge.key, false), + AccountMeta::new(*accs.bridge.info().key, false), AccountMeta::new(*accs.message.key, true), AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new(*accs.sequence.key, false),