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

Add relayer signer to ER swap #377

Merged
merged 6 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ local_resource(
# need to run initialize instructions for the programs one time, script skips if already initialized
local_resource(
"svm-initialize-programs",
"poetry -C tilt-scripts run python3 -m tilt-scripts.svm.initialize_programs -v --file-private-key-payer keypairs/searcher_py.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --express-relay-program PytERJFhAKuNNuaiXkApLfWzwNwSNDACpigT3LwQfou --rpc-url %s" % rpc_url_solana,
"poetry -C tilt-scripts run python3 -m tilt-scripts.svm.initialize_programs -v --file-private-key-payer keypairs/searcher_py.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --file-private-key-fee-receiver-relayer keypairs/fee_receiver_relayer.json --express-relay-program PytERJFhAKuNNuaiXkApLfWzwNwSNDACpigT3LwQfou --rpc-url %s" % rpc_url_solana,
resource_deps=["svm-setup-accounts"]
)

Expand Down
2 changes: 1 addition & 1 deletion auction-server/src/auction/service/auction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ impl AuctionManager<Evm> for Service<Evm> {
/// This is to make sure we are not missing any transaction.
/// We run this once every minute (150 * 0.4).
const CONCLUSION_TRIGGER_INTERVAL_SVM: u64 = 150;
const BID_MAXIMUM_LIFE_TIME_SVM: Duration = Duration::from_secs(10);
const BID_MAXIMUM_LIFE_TIME_SVM: Duration = Duration::from_secs(120);
const TRIGGER_DURATION_SVM: Duration = Duration::from_millis(400);

pub struct TriggerStreamSvm {
Expand Down
4 changes: 1 addition & 3 deletions auction-server/src/auction/service/submit_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ impl Service<Svm> {
.position(|p| p.eq(&user_wallet))
.expect("User wallet not found in transaction");
bid.chain_data.transaction.signatures[user_signature_pos] = input.user_signature;

// TODO add relayer signature after program update
// self.add_relayer_signature(&mut bid);
self.add_relayer_signature(&mut bid);

if bid.chain_data.bid_payment_instruction_type != entities::BidPaymentInstructionType::Swap
{
Expand Down
10 changes: 4 additions & 6 deletions auction-server/src/auction/service/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,12 +933,10 @@ impl Service<Svm> {
opportunity.check_fee_payer(accounts).map_err(|e| {
RestError::BadParameters(format!("Invalid first signer: {:?}", e))
})?;
self.all_signatures_exists(
&message_bytes,
accounts,
&signatures,
&opportunity.get_missing_signers(),
)
let mut missing_signers = opportunity.get_missing_signers();
missing_signers.push(self.config.chain_config.express_relay.relayer.pubkey());
self.relayer_signer_exists(accounts, &signatures)?;
self.all_signatures_exists(&message_bytes, accounts, &signatures, &missing_signers)
}
SubmitType::ByServer => {
self.relayer_signer_exists(accounts, &signatures)?;
Expand Down
2 changes: 1 addition & 1 deletion contracts/svm/Cargo.lock

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

2 changes: 1 addition & 1 deletion contracts/svm/programs/express_relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "express-relay"
version = "0.5.0"
version = "0.6.0"
description = "Pyth Express Relay program for handling permissioning and bid distribution"
repository = "https://github.com/pyth-network/per"
license = "Apache-2.0"
Expand Down
24 changes: 13 additions & 11 deletions contracts/svm/programs/express_relay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ pub struct Swap<'info> {
token::authority = searcher,
token::token_program = token_program_searcher
)]
pub searcher_ta_mint_searcher: InterfaceAccount<'info, TokenAccount>,
pub searcher_ta_mint_searcher: Box<InterfaceAccount<'info, TokenAccount>>,
danimhr marked this conversation as resolved.
Show resolved Hide resolved

#[account(
mut,
token::mint = mint_user,
token::authority = searcher,
token::token_program = token_program_user
)]
pub searcher_ta_mint_user: InterfaceAccount<'info, TokenAccount>,
pub searcher_ta_mint_user: Box<InterfaceAccount<'info, TokenAccount>>,

// User accounts
#[account(
Expand All @@ -420,15 +420,15 @@ pub struct Swap<'info> {
associated_token::authority = user,
associated_token::token_program = token_program_searcher
)]
pub user_ata_mint_searcher: InterfaceAccount<'info, TokenAccount>,
pub user_ata_mint_searcher: Box<InterfaceAccount<'info, TokenAccount>>,

#[account(
mut,
associated_token::mint = mint_user,
associated_token::authority = user,
associated_token::token_program = token_program_user
)]
pub user_ata_mint_user: InterfaceAccount<'info, TokenAccount>,
pub user_ata_mint_user: Box<InterfaceAccount<'info, TokenAccount>>,

// Fee receivers
/// Router fee receiver token account: the referrer can provide an arbitrary receiver for the router fee
Expand All @@ -437,36 +437,36 @@ pub struct Swap<'info> {
token::mint = mint_fee,
token::token_program = token_program_fee
)]
pub router_fee_receiver_ta: InterfaceAccount<'info, TokenAccount>,
pub router_fee_receiver_ta: Box<InterfaceAccount<'info, TokenAccount>>,

#[account(
mut,
associated_token::mint = mint_fee,
associated_token::authority = express_relay_metadata.fee_receiver_relayer,
associated_token::token_program = token_program_fee
)]
pub relayer_fee_receiver_ata: InterfaceAccount<'info, TokenAccount>,
pub relayer_fee_receiver_ata: Box<InterfaceAccount<'info, TokenAccount>>,

#[account(
mut,
associated_token::mint = mint_fee,
associated_token::authority = express_relay_metadata.key(),
associated_token::token_program = token_program_fee
)]
pub express_relay_fee_receiver_ata: InterfaceAccount<'info, TokenAccount>,
pub express_relay_fee_receiver_ata: Box<InterfaceAccount<'info, TokenAccount>>,

// Mints
#[account(mint::token_program = token_program_searcher)]
pub mint_searcher: InterfaceAccount<'info, Mint>,
pub mint_searcher: Box<InterfaceAccount<'info, Mint>>,

#[account(mint::token_program = token_program_user)]
pub mint_user: InterfaceAccount<'info, Mint>,
pub mint_user: Box<InterfaceAccount<'info, Mint>>,

#[account(
mint::token_program = token_program_fee,
constraint = mint_fee.key() == if data.fee_token == FeeToken::Searcher { mint_searcher.key() } else { mint_user.key() }
)]
pub mint_fee: InterfaceAccount<'info, Mint>,
pub mint_fee: Box<InterfaceAccount<'info, Mint>>,

// Token programs
pub token_program_searcher: Interface<'info, TokenInterface>,
Expand All @@ -478,6 +478,8 @@ pub struct Swap<'info> {
pub token_program_fee: Interface<'info, TokenInterface>,

/// Express relay configuration
#[account(seeds = [SEED_METADATA], bump)]
#[account(seeds = [SEED_METADATA], bump, has_one = relayer_signer)]
pub express_relay_metadata: Box<Account<'info, ExpressRelayMetadata>>,

pub relayer_signer: Signer<'info>,
}
6 changes: 4 additions & 2 deletions contracts/svm/programs/express_relay/src/sdk/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub fn create_swap_instruction(
token_program_searcher: Pubkey,
token_program_user: Pubkey,
swap_args: SwapArgs,
relayer_signer: Pubkey,
) -> Instruction {
let express_relay_metadata =
Pubkey::find_program_address(&[SEED_METADATA], &express_relay_pid).0;
Expand All @@ -119,7 +120,7 @@ pub fn create_swap_instruction(
FeeToken::User => (mint_user, token_program_user),
};

let accounts_submit_bid = accounts::Swap {
let accounts_swap = accounts::Swap {
searcher,
user,
searcher_ta_mint_searcher: searcher_ta_mint_searcher.unwrap_or(
Expand Down Expand Up @@ -164,13 +165,14 @@ pub fn create_swap_instruction(
token_program_user,
token_program_fee,
express_relay_metadata,
relayer_signer,
}
.to_account_metas(None);
let data_submit_bid = instruction::Swap { data: swap_args }.data();

Instruction {
program_id: express_relay_pid,
accounts: accounts_submit_bid,
accounts: accounts_swap,
data: data_submit_bid,
}
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/svm/testing/src/express_relay/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub fn create_swap_instruction(
swap_args: SwapArgs,
user_ata_mint_user_override: Option<Pubkey>,
mint_fee_override: Option<Pubkey>,
relayer_signer: Pubkey,
) -> Instruction {
let express_relay_metadata = get_express_relay_metadata_key();

Expand Down Expand Up @@ -100,6 +101,7 @@ pub fn create_swap_instruction(
token_program_user,
token_program_fee,
express_relay_metadata,
relayer_signer,
}
.to_account_metas(None);

Expand Down Expand Up @@ -127,6 +129,7 @@ pub fn build_swap_instructions(
swap_args: SwapArgs,
user_ata_mint_user_override: Option<Pubkey>,
mint_fee_override: Option<Pubkey>,
relayer_signer: Pubkey,
) -> Vec<Instruction> {
let mut instructions: Vec<Instruction> = vec![];

Expand Down Expand Up @@ -183,6 +186,7 @@ pub fn build_swap_instructions(
swap_args,
user_ata_mint_user_override,
mint_fee_override,
relayer_signer,
));

instructions
Expand Down
Loading
Loading