Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solana: token router transfer authority and more #65

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions solana/modules/common/src/burn_and_publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub fn burn_and_publish_fill(
&[
Custodian::SIGNER_SEEDS,
&[
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
ctx.accounts.payer.key().as_ref(),
ctx.accounts
.payer_sequence
Expand All @@ -79,7 +79,7 @@ pub fn burn_and_publish_fill(
destination_cctp_domain: order.destination_cctp_domain(),
amount: user_amount,
mint_recipient: ctx.accounts.to_router_endpoint.mint_recipient,
wormhole_message_nonce: common::constants::WORMHOLE_MESSAGE_NONCE,
wormhole_message_nonce: common::WORMHOLE_MESSAGE_NONCE,
payload: fill.to_vec_payload(),
},
)
Expand Down
39 changes: 0 additions & 39 deletions solana/modules/common/src/constants/mod.rs

This file was deleted.

41 changes: 39 additions & 2 deletions solana/modules/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@ pub use wormhole_io;

pub mod admin;

pub mod constants;

pub mod messages;

pub const WORMHOLE_MESSAGE_NONCE: u32 = 0;

pub const CORE_MESSAGE_SEED_PREFIX: &[u8] = b"core-msg";
pub const CCTP_MESSAGE_SEED_PREFIX: &[u8] = b"cctp-msg";

pub const TRANSFER_AUTHORITY_SEED_PREFIX: &[u8] = b"transfer-authority";

pub use wormhole_solana_consts::USDC_MINT;

use solana_program::{pubkey, pubkey::Pubkey};

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
pub const MATCHING_ENGINE_PROGRAM_ID: Pubkey = pubkey!("mPydpGUWxzERTNpyvTKdvS7v8kvw5sgwfiP8WQFrXVS");
pub const TOKEN_ROUTER_PROGRAM_ID: Pubkey = pubkey!("tD8RmtdcV7bzBeuFgyrFc8wvayj988ChccEzRQzo6md");

pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("ucdP9ktgrXgEUnn6roqD2SfdGMR2JSiWHUKv23oXwxt");
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("2sxpm9pvWmNWFzhgWtmxkMsdWk2uSNT9MoKvww53po1M");
} else if #[cfg(feature = "localnet")] {
pub const MATCHING_ENGINE_PROGRAM_ID: Pubkey = pubkey!("MatchingEngine11111111111111111111111111111");
pub const TOKEN_ROUTER_PROGRAM_ID: Pubkey = pubkey!("TokenRouter11111111111111111111111111111111");

pub const UPGRADE_MANAGER_PROGRAM_ID: Pubkey = pubkey!("UpgradeManager11111111111111111111111111111");
pub const UPGRADE_MANAGER_AUTHORITY: Pubkey = pubkey!("9Nu3k9HKFChDcAC8SeCrCeHvsRcdZzZfdQxGaEynFHZ7");
}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn upgrade_manager_authority() {
let (expected, _) =
Pubkey::find_program_address(&[b"upgrade"], &UPGRADE_MANAGER_PROGRAM_ID);
assert_eq!(UPGRADE_MANAGER_AUTHORITY, expected);
}
}
4 changes: 3 additions & 1 deletion solana/package-lock.json

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

1 change: 1 addition & 0 deletions solana/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@solana/web3.js": "^1.87.6",
"dotenv": "^16.4.1",
"ethers": "^5.7.2",
"sha3": "^2.1.4",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion solana/programs/matching-engine/src/cctp_mint_recipient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod test {
super::id(),
anchor_spl::associated_token::get_associated_token_address(
&custodian,
&common::constants::USDC_MINT,
&common::USDC_MINT,
),
"custody ata mismatch"
);
Expand Down
8 changes: 4 additions & 4 deletions solana/programs/matching-engine/src/composite/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use common::{

#[derive(Accounts)]
pub struct Usdc<'info> {
/// CHECK: This address must equal [USDC_MINT](common::constants::USDC_MINT).
#[account(address = common::constants::USDC_MINT)]
/// CHECK: This address must equal [USDC_MINT](common::USDC_MINT).
#[account(address = common::USDC_MINT)]
pub mint: AccountInfo<'info>,
}

Expand Down Expand Up @@ -190,7 +190,7 @@ pub struct LocalTokenRouter<'info> {
pub token_router_emitter: AccountInfo<'info>,

#[account(
associated_token::mint = common::constants::USDC_MINT,
associated_token::mint = common::USDC_MINT,
associated_token::authority = token_router_emitter,
)]
pub token_router_mint_recipient: Account<'info, token::TokenAccount>,
Expand Down Expand Up @@ -370,7 +370,7 @@ pub struct ExecuteOrder<'info> {

pub active_auction: ActiveAuction<'info>,

/// CHECK: Must be a token account, whose mint is [common::constants::USDC_MINT].
/// CHECK: Must be a token account, whose mint is [common::USDC_MINT].
#[account(mut)]
pub executor_token: AccountInfo<'info>,

Expand Down
3 changes: 1 addition & 2 deletions solana/programs/matching-engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use utils::admin::AddCctpRouterEndpointArgs;

use anchor_lang::prelude::*;

declare_id!(common::constants::MATCHING_ENGINE_PROGRAM_ID);
declare_id!(common::MATCHING_ENGINE_PROGRAM_ID);

cfg_if::cfg_if! {
if #[cfg(feature = "testnet")] {
Expand All @@ -32,7 +32,6 @@ cfg_if::cfg_if! {
const AUCTION_CUSTODY_TOKEN_SEED_PREFIX: &[u8] = b"auction-custody";
const LOCAL_CUSTODY_TOKEN_SEED_PREFIX: &[u8] = b"local-custody";
const PREPARED_CUSTODY_TOKEN_SEED_PREFIX: &[u8] = b"prepared-custody";
const TRANSFER_AUTHORITY_SEED_PREFIX: &[u8] = b"transfer-authority";

const FEE_PRECISION_MAX: u32 = 1_000_000;
const VAA_AUCTION_EXPIRATION_TIME: i64 = 2 * 60 * 60; // 2 hours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ pub struct Initialize<'info> {
program_data: Account<'info, ProgramData>,

/// CHECK: This program PDA will be the upgrade authority for the Token Router program.
#[account(address = common::constants::UPGRADE_MANAGER_AUTHORITY)]
#[account(address = common::UPGRADE_MANAGER_AUTHORITY)]
upgrade_manager_authority: AccountInfo<'info>,

/// CHECK: This program must exist.
#[account(
executable,
address = common::constants::UPGRADE_MANAGER_PROGRAM_ID,
address = common::UPGRADE_MANAGER_PROGRAM_ID,
)]
upgrade_manager_program: AccountInfo<'info>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct UpdateFeeRecipient<'info> {
admin: AdminMut<'info>,

#[account(
associated_token::mint = common::constants::USDC_MINT,
associated_token::mint = common::USDC_MINT,
associated_token::authority = new_fee_recipient,
)]
new_fee_recipient_token: Account<'info, token::TokenAccount>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ExecuteFastOrderCctp<'info> {
#[account(
mut,
seeds = [
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
&payer_sequence.value.to_be_bytes(),
],
Expand All @@ -41,7 +41,7 @@ pub struct ExecuteFastOrderCctp<'info> {
#[account(
mut,
seeds = [
common::constants::CCTP_MESSAGE_SEED_PREFIX,
common::CCTP_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
&payer_sequence.value.to_be_bytes(),
],
Expand Down Expand Up @@ -92,6 +92,7 @@ pub fn handle_execute_fast_order_cctp(

let auction_custody_token = &ctx.accounts.execute_order.active_auction.custody_token;
let payer = &ctx.accounts.payer;
let system_program = &ctx.accounts.system_program;

// Send the CCTP message to the destination chain.
wormhole_cctp_solana::cpi::burn_and_publish(
Expand Down Expand Up @@ -136,7 +137,7 @@ pub fn handle_execute_fast_order_cctp(
.token_messenger_minter_program
.to_account_info(),
token_program: token_program.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
system_program: system_program.to_account_info(),
event_authority: ctx
.accounts
.cctp
Expand All @@ -146,7 +147,7 @@ pub fn handle_execute_fast_order_cctp(
&[
Custodian::SIGNER_SEEDS,
&[
common::constants::CCTP_MESSAGE_SEED_PREFIX,
common::CCTP_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
sequence_seed.as_ref(),
&[ctx.bumps.cctp_message],
Expand All @@ -162,14 +163,14 @@ pub fn handle_execute_fast_order_cctp(
config: ctx.accounts.wormhole.config.to_account_info(),
emitter_sequence: ctx.accounts.wormhole.emitter_sequence.to_account_info(),
fee_collector: ctx.accounts.wormhole.fee_collector.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
system_program: system_program.to_account_info(),
clock: ctx.accounts.sysvars.clock.to_account_info(),
rent: ctx.accounts.sysvars.rent.to_account_info(),
},
&[
Custodian::SIGNER_SEEDS,
&[
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
sequence_seed.as_ref(),
&[ctx.bumps.core_message],
Expand All @@ -182,7 +183,7 @@ pub fn handle_execute_fast_order_cctp(
destination_cctp_domain,
amount,
mint_recipient: ctx.accounts.to_router_endpoint.mint_recipient,
wormhole_message_nonce: common::constants::WORMHOLE_MESSAGE_NONCE,
wormhole_message_nonce: common::WORMHOLE_MESSAGE_NONCE,
payload: fill.to_vec_payload(),
},
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct ExecuteFastOrderLocal<'info> {
#[account(
mut,
seeds = [
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
&payer_sequence.value.to_be_bytes(),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
composite::*, error::MatchingEngineError, state::Auction, utils, TRANSFER_AUTHORITY_SEED_PREFIX,
};
use crate::{composite::*, error::MatchingEngineError, state::Auction, utils};
use anchor_lang::prelude::*;
use anchor_spl::token;
use common::TRANSFER_AUTHORITY_SEED_PREFIX;

#[derive(Accounts)]
#[instruction(offer_price: u64)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{
composite::*,
error::MatchingEngineError,
state::{Auction, AuctionConfig, AuctionInfo, AuctionStatus},
utils, TRANSFER_AUTHORITY_SEED_PREFIX,
utils,
};
use anchor_lang::prelude::*;
use anchor_spl::token;
use common::messages::raw::LiquidityLayerMessage;
use common::{messages::raw::LiquidityLayerMessage, TRANSFER_AUTHORITY_SEED_PREFIX};

#[derive(Accounts)]
#[instruction(offer_price: u64)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct SettleAuctionNoneCctp<'info> {
#[account(
mut,
seeds = [
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
&payer_sequence.value.to_be_bytes(),
],
Expand All @@ -42,7 +42,7 @@ pub struct SettleAuctionNoneCctp<'info> {
#[account(
mut,
seeds = [
common::constants::CCTP_MESSAGE_SEED_PREFIX,
common::CCTP_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
&payer_sequence.value.to_be_bytes(),
],
Expand Down Expand Up @@ -138,6 +138,7 @@ fn handle_settle_auction_none_cctp(
} = ctx.accounts.fast_order_path.to_endpoint.as_ref();

let payer = &ctx.accounts.payer;
let system_program = &ctx.accounts.system_program;

// This returns the CCTP nonce, but we do not need it.
wormhole_cctp_solana::cpi::burn_and_publish(
Expand Down Expand Up @@ -177,7 +178,7 @@ fn handle_settle_auction_none_cctp(
.token_messenger_minter_program
.to_account_info(),
token_program: token_program.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
system_program: system_program.to_account_info(),
event_authority: ctx
.accounts
.cctp
Expand All @@ -187,7 +188,7 @@ fn handle_settle_auction_none_cctp(
&[
Custodian::SIGNER_SEEDS,
&[
common::constants::CCTP_MESSAGE_SEED_PREFIX,
common::CCTP_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
sequence_seed.as_ref(),
&[ctx.bumps.cctp_message],
Expand All @@ -203,14 +204,14 @@ fn handle_settle_auction_none_cctp(
config: ctx.accounts.wormhole.config.to_account_info(),
emitter_sequence: ctx.accounts.wormhole.emitter_sequence.to_account_info(),
fee_collector: ctx.accounts.wormhole.fee_collector.to_account_info(),
system_program: ctx.accounts.system_program.to_account_info(),
system_program: system_program.to_account_info(),
clock: ctx.accounts.sysvars.clock.to_account_info(),
rent: ctx.accounts.sysvars.rent.to_account_info(),
},
&[
Custodian::SIGNER_SEEDS,
&[
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
sequence_seed.as_ref(),
&[ctx.bumps.core_message],
Expand All @@ -223,7 +224,7 @@ fn handle_settle_auction_none_cctp(
destination_cctp_domain,
amount,
mint_recipient: *mint_recipient,
wormhole_message_nonce: common::constants::WORMHOLE_MESSAGE_NONCE,
wormhole_message_nonce: common::WORMHOLE_MESSAGE_NONCE,
payload: fill.to_vec_payload(),
},
)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct SettleAuctionNoneLocal<'info> {
#[account(
mut,
seeds = [
common::constants::CORE_MESSAGE_SEED_PREFIX,
common::CORE_MESSAGE_SEED_PREFIX,
payer.key().as_ref(),
payer_sequence.value.to_be_bytes().as_ref(),
],
Expand Down
Loading
Loading