Skip to content

Commit

Permalink
checkpoint: wormhole gateway still broken
Browse files Browse the repository at this point in the history
  • Loading branch information
a5-pickle committed Aug 1, 2023
1 parent 89f4a0b commit f58a45d
Show file tree
Hide file tree
Showing 22 changed files with 431 additions and 252 deletions.
11 changes: 11 additions & 0 deletions cross-chain/solana/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cross-chain/solana/programs/tbtc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ use anchor_lang::prelude::*;

declare_id!("HksEtDgsXJV1BqcuhzbLRTmXp5gHgHJktieJCtQd3pG");

#[derive(Clone)]
pub struct Tbtc;

impl Id for Tbtc {
fn id() -> Pubkey {
ID
}
}

#[program]
pub mod tbtc {
use super::*;
Expand Down
10 changes: 9 additions & 1 deletion cross-chain/solana/programs/tbtc/src/processor/admin/pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub struct Pause<'info> {
mut,
seeds = [Config::SEED_PREFIX],
bump,
constraint = !config.paused @ TbtcError::IsPaused
)]
config: Account<'info, Config>,

Expand All @@ -24,6 +23,15 @@ pub struct Pause<'info> {
guardian: Signer<'info>,
}

impl<'info> Pause<'info> {
fn constraints(ctx: &Context<Self>) -> Result<()> {
require!(!ctx.accounts.config.paused, TbtcError::IsPaused);

Ok(())
}
}

#[access_control(Pause::constraints(&ctx))]
pub fn pause(ctx: Context<Pause>) -> Result<()> {
ctx.accounts.config.paused = true;
Ok(())
Expand Down
12 changes: 10 additions & 2 deletions cross-chain/solana/programs/tbtc/src/processor/admin/unpause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@ use anchor_lang::prelude::*;
pub struct Unpause<'info> {
#[account(
mut,
has_one = authority @ TbtcError::IsNotAuthority,
seeds = [Config::SEED_PREFIX],
bump,
has_one = authority @ TbtcError::IsNotAuthority,
constraint = config.paused @ TbtcError::IsNotPaused
)]
config: Account<'info, Config>,

authority: Signer<'info>,
}

impl<'info> Unpause<'info> {
fn constraints(ctx: &Context<Self>) -> Result<()> {
require!(ctx.accounts.config.paused, TbtcError::IsNotPaused);

Ok(())
}
}

#[access_control(Unpause::constraints(&ctx))]
pub fn unpause(ctx: Context<Unpause>) -> Result<()> {
ctx.accounts.config.paused = false;
Ok(())
Expand Down
16 changes: 13 additions & 3 deletions cross-chain/solana/programs/tbtc/src/processor/mint/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ pub struct Mint<'info> {
)]
mint: Account<'info, token::Mint>,

// Can not mint when paused.
#[account(
constraint = !config.paused @ TbtcError::IsPaused
seeds = [Config::SEED_PREFIX],
bump = config.bump,
)]
config: Account<'info, Config>,

Expand All @@ -30,6 +30,7 @@ pub struct Mint<'info> {
bump = minter_info.bump,
)]
minter_info: Account<'info, MinterInfo>,

minter: Signer<'info>,

// Use the associated token account for the recipient.
Expand All @@ -40,9 +41,18 @@ pub struct Mint<'info> {
recipient_token: Account<'info, token::TokenAccount>,

token_program: Program<'info, token::Token>,
system_program: Program<'info, System>,
}

impl<'info> Mint<'info> {
fn constraints(ctx: &Context<Self>) -> Result<()> {
// Can not mint when paused.
require!(!ctx.accounts.config.paused, TbtcError::IsPaused);

Ok(())
}
}

#[access_control(Mint::constraints(&ctx))]
pub fn mint(ctx: Context<Mint>, amount: u64) -> Result<()> {
token::mint_to(
CpiContext::new_with_signer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub struct GuardianInfo {
}

impl GuardianInfo {
pub const SEED_PREFIX: &'static [u8; 13] = b"guardian-info";
pub const SEED_PREFIX: &'static [u8] = b"guardian-info";
}
11 changes: 8 additions & 3 deletions cross-chain/solana/programs/wormhole-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ crate-type = ["cdylib", "lib"]
name = "wormhole_gateway"

[features]
default = ["mainnet"]
mainnet = ["wormhole-anchor-sdk/mainnet"]
solana-devnet = ["wormhole-anchor-sdk/solana-devnet"]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { version="0.28.0", features = ["init-if-needed"]}
anchor-lang = { version = "0.28.0", features = ["init-if-needed"]}
anchor-spl = "0.28.0"
tbtc = { path = "../tbtc" }

wormhole-anchor-sdk = { git = "https://github.com/wormhole-foundation/wormhole-scaffolding", rev = "f8d5ba04bfd449ab3693b15c818fd3e85e30f758", features = ["token-bridge"], default-features = false }

tbtc = { path = "../tbtc", features = ["cpi"] }
14 changes: 14 additions & 0 deletions cross-chain/solana/programs/wormhole-gateway/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub const TBTC_FOREIGN_TOKEN_CHAIN: u8 = 2;

#[cfg(feature = "mainnet")]
pub const TBTC_FOREIGN_TOKEN_ADDRESS: [u8; 32] = [
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8d, 0xae, 0xba, 0xde, 0x92, 0x2d,
0xf7, 0x35, 0xc3, 0x8c, 0x80, 0xc7, 0xeb, 0xd7, 0x08, 0xaf, 0x50, 0x81, 0x5f, 0xaa,
];

/// TODO: Fix this to reflect testnet contract address.
#[cfg(feature = "solana-devnet")]
pub const TBTC_FOREIGN_TOKEN_ADDRESS: [u8; 32] = [
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8d, 0xae, 0xba, 0xde, 0x92, 0x2d,
0xf7, 0x35, 0xc3, 0x8c, 0x80, 0xc7, 0xeb, 0xd7, 0x08, 0xaf, 0x50, 0x81, 0x5f, 0xaa,
];
19 changes: 17 additions & 2 deletions cross-chain/solana/programs/wormhole-gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ use anchor_lang::prelude::error_code;

#[error_code]
pub enum WormholeGatewayError {
MintingLimitExceeded,
IsNotAuthority,
#[msg("Cannot mint more than the minting limit.")]
MintingLimitExceeded = 0x10,

#[msg("Only custodian authority is permitted for this action.")]
IsNotAuthority = 0x20,

#[msg("0x0 recipient not allowed")]
ZeroRecipient = 0x30,

#[msg("Not enough wormhole tBTC in the gateway to bridge")]
NotEnoughWrappedTbtc = 0x40,

#[msg("Amount must not be 0")]
ZeroAmount = 0x50,

#[msg("Amount too low to bridge")]
TruncatedZeroAmount = 0x60,
}
29 changes: 14 additions & 15 deletions cross-chain/solana/programs/wormhole-gateway/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod constants;
pub use constants::*;

pub mod error;

mod processor;
Expand All @@ -22,35 +25,31 @@ pub mod wormhole_gateway {
pub fn update_gateway_address(
ctx: Context<UpdateGatewayAddress>,
chain_id: u16,
gateway_address: [u8; 32]
gateway_address: [u8; 32],
) -> Result<()> {
processor::update_gateway_address(ctx, chain_id, gateway_address)
}

pub fn update_minting_limit(
ctx: Context<UpdateMintingLimit>,
new_limit: u64,
) -> Result<()> {
pub fn update_minting_limit(ctx: Context<UpdateMintingLimit>, new_limit: u64) -> Result<()> {
processor::update_minting_limit(ctx, new_limit)
}

pub fn receive_tbtc(
ctx: Context<ReceiveTbtc>,
) -> Result<()> {
processor::receive_tbtc(ctx)
}
// pub fn receive_tbtc(ctx: Context<ReceiveTbtc>) -> Result<()> {
// processor::receive_tbtc(ctx)
// }

pub fn send_tbtc(
ctx: Context<SendTbtc>,
amount: u64,
pub fn send_tbtc_to_gateway(
ctx: Context<SendTbtcToGateway>,
recipient_chain: u16,
recipient: [u8; 32],
amount: u64,
arbiter_fee: u64,
nonce: u32,
) -> Result<()> {
processor::send_tbtc(ctx, amount, recipient_chain, arbiter_fee, nonce)
processor::send_tbtc_to_gateway(ctx, recipient_chain, recipient, amount, arbiter_fee, nonce)
}

pub fn deposit_wormhole_tbtc(ctx: Context<DepositWormholeTbtc>, amount: u64) -> Result<()> {
processor::deposit_wormhole_tbtc(ctx, amount)
}
}
}
Loading

0 comments on commit f58a45d

Please sign in to comment.