Use bridge config to decide fee payer.

Change-Id: I5eb7601737eb5cbc687dee07567a6fab4e5ca4c5
This commit is contained in:
Reisen 2021-08-23 09:13:55 +00:00 committed by Hendrik Hofstadt
parent 3ec4ad6ad3
commit 254f1c8674
3 changed files with 33 additions and 12 deletions

View File

@ -94,12 +94,21 @@ pub struct BridgeData {
pub config: BridgeConfig, pub config: BridgeConfig,
} }
#[cfg(not(feature = "cpi"))]
impl Owned for BridgeData { impl Owned for BridgeData {
fn owner(&self) -> AccountOwner { fn owner(&self) -> AccountOwner {
AccountOwner::This 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)] #[derive(Default, BorshSerialize, BorshDeserialize)]
pub struct SignatureSet { pub struct SignatureSet {
/// Signatures of validators /// Signatures of validators

View File

@ -18,6 +18,7 @@ use crate::{
}, },
}; };
use bridge::{ use bridge::{
accounts::Bridge,
api::{ api::{
PostMessage, PostMessage,
PostMessageData, PostMessageData,
@ -76,7 +77,7 @@ pub struct AttestToken<'b> {
pub spl_metadata: SplTokenMeta<'b>, pub spl_metadata: SplTokenMeta<'b>,
/// CPI Context /// CPI Context
pub bridge: Mut<Info<'b>>, pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// Account to store the posted message /// Account to store the posted message
pub message: Signer<Mut<Info<'b>>>, pub message: Signer<Mut<Info<'b>>>,
@ -123,8 +124,11 @@ pub fn attest_token(
data: AttestTokenData, data: AttestTokenData,
) -> Result<()> { ) -> Result<()> {
// Pay fee // Pay fee
let transfer_ix = let transfer_ix = solana_program::system_instruction::transfer(
solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); accs.payer.key,
accs.fee_collector.key,
accs.bridge.config.fee,
);
invoke(&transfer_ix, ctx.accounts)?; invoke(&transfer_ix, ctx.accounts)?;
@ -171,7 +175,7 @@ pub fn attest_token(
accs.config.wormhole_bridge, accs.config.wormhole_bridge,
params.try_to_vec()?.as_slice(), params.try_to_vec()?.as_slice(),
vec![ vec![
AccountMeta::new(*accs.bridge.key, false), AccountMeta::new(*accs.bridge.info().key, false),
AccountMeta::new(*accs.message.key, true), AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false), AccountMeta::new(*accs.sequence.key, false),

View File

@ -18,6 +18,7 @@ use crate::{
TokenBridgeError::WrongAccountOwner, TokenBridgeError::WrongAccountOwner,
}; };
use bridge::{ use bridge::{
accounts::Bridge,
api::{ api::{
PostMessage, PostMessage,
PostMessageData, PostMessageData,
@ -80,7 +81,7 @@ pub struct TransferNative<'b> {
pub custody_signer: CustodySigner<'b>, pub custody_signer: CustodySigner<'b>,
/// CPI Context /// CPI Context
pub bridge: Mut<Info<'b>>, pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// Account to store the posted message /// Account to store the posted message
pub message: Signer<Mut<Info<'b>>>, pub message: Signer<Mut<Info<'b>>>,
@ -171,8 +172,11 @@ pub fn transfer_native(
invoke_seeded(&transfer_ix, ctx, &accs.authority_signer, None)?; invoke_seeded(&transfer_ix, ctx, &accs.authority_signer, None)?;
// Pay fee // Pay fee
let transfer_ix = let transfer_ix = solana_program::system_instruction::transfer(
solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); accs.payer.key,
accs.fee_collector.key,
accs.bridge.config.fee,
);
invoke(&transfer_ix, ctx.accounts)?; invoke(&transfer_ix, ctx.accounts)?;
// Post message // Post message
@ -197,7 +201,7 @@ pub fn transfer_native(
accs.config.wormhole_bridge, accs.config.wormhole_bridge,
params.try_to_vec()?.as_slice(), params.try_to_vec()?.as_slice(),
vec![ vec![
AccountMeta::new(*accs.bridge.key, false), AccountMeta::new(*accs.bridge.info().key, false),
AccountMeta::new(*accs.message.key, true), AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false), AccountMeta::new(*accs.sequence.key, false),
@ -226,7 +230,7 @@ pub struct TransferWrapped<'b> {
pub authority_signer: AuthoritySigner<'b>, pub authority_signer: AuthoritySigner<'b>,
/// CPI Context /// CPI Context
pub bridge: Mut<Info<'b>>, pub bridge: Mut<Bridge<'b, { AccountState::Initialized }>>,
/// Account to store the posted message /// Account to store the posted message
pub message: Signer<Mut<Info<'b>>>, pub message: Signer<Mut<Info<'b>>>,
@ -304,8 +308,12 @@ pub fn transfer_wrapped(
invoke_seeded(&burn_ix, ctx, &accs.authority_signer, None)?; invoke_seeded(&burn_ix, ctx, &accs.authority_signer, None)?;
// Pay fee // Pay fee
let transfer_ix = let transfer_ix = solana_program::system_instruction::transfer(
solana_program::system_instruction::transfer(accs.payer.key, accs.fee_collector.key, 1000); accs.payer.key,
accs.fee_collector.key,
accs.bridge.config.fee,
);
invoke(&transfer_ix, ctx.accounts)?; invoke(&transfer_ix, ctx.accounts)?;
// Post message // Post message
@ -330,7 +338,7 @@ pub fn transfer_wrapped(
accs.config.wormhole_bridge, accs.config.wormhole_bridge,
params.try_to_vec()?.as_slice(), params.try_to_vec()?.as_slice(),
vec![ vec![
AccountMeta::new(*accs.bridge.key, false), AccountMeta::new(*accs.bridge.info().key, false),
AccountMeta::new(*accs.message.key, true), AccountMeta::new(*accs.message.key, true),
AccountMeta::new_readonly(*accs.emitter.key, true), AccountMeta::new_readonly(*accs.emitter.key, true),
AccountMeta::new(*accs.sequence.key, false), AccountMeta::new(*accs.sequence.key, false),