Skip to content

Commit 63e4013

Browse files
authored
rename protocol -> router and reorg (#130)
* rename protocol -> router and reorg * reconfigure tilt * added tests for insufficient rent * address comments
1 parent fdb1da5 commit 63e4013

29 files changed

+336
-452
lines changed

Tiltfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ local_resource(
158158
# need to run initialize instructions for the programs one time, script skips if already initialized
159159
local_resource(
160160
"svm-initialize-programs",
161-
"poetry -C per_sdk run python3 -m per_sdk.svm.initialize_programs -v --file-private-key-payer keypairs/searcher.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --dummy-program HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3 --rpc-url %s" % rpc_url_solana,
161+
"poetry -C per_sdk run python3 -m per_sdk.svm.initialize_programs -v --file-private-key-payer keypairs/searcher.json --file-private-key-admin keypairs/admin.json --file-private-key-relayer-signer keypairs/relayer_signer.json --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --rpc-url %s" % rpc_url_solana,
162162
resource_deps=["svm-setup-accounts"]
163163
)
164164

165165
# craft dummy tx, submits as a bid to auction server or submits relayer-signed tx directly to solana cluster
166166
local_resource(
167167
"svm-submit-bid",
168-
"poetry -C per_sdk run python3 -m per_sdk.svm.dummy_tx -v --file-private-key-searcher keypairs/searcher.json --file-private-key-relayer-signer keypairs/relayer_signer.json --bid 100 --auction-server-url http://localhost:9000 --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --dummy-program HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3",
168+
"poetry -C per_sdk run python3 -m per_sdk.svm.dummy_tx -v --file-private-key-searcher keypairs/searcher.json --file-private-key-relayer-signer keypairs/relayer_signer.json --bid 100000000 --auction-server-url http://localhost:9000 --express-relay-program GwEtasTAxdS9neVE4GPUpcwR7DB7AizntQSPcG36ubZM --dummy-program HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3",
169169
resource_deps=["svm-initialize-programs", "auction-server"],
170170
)
Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
use anchor_lang::prelude::*;
22
use anchor_lang::solana_program::sysvar::instructions as sysvar_instructions;
3-
use express_relay::{self, program::ExpressRelay, cpi::accounts::CheckPermission, state::SEED_EXPRESS_RELAY_FEES};
3+
use express_relay::{self, program::ExpressRelay, cpi::accounts::CheckPermission};
44

55
declare_id!("HYCgALnu6CM2gkQVopa1HGaNf8Vzbs9bomWRiKP267P3");
66

77
#[program]
88
pub mod dummy {
99
use super::*;
1010

11-
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
12-
Ok(())
13-
}
14-
1511
pub fn do_nothing(ctx: Context<DoNothing>) -> Result<()> {
1612
// just want to check if the permission is valid, and do nothing else
1713
let cpi_program = ctx.accounts.express_relay.to_account_info();
1814
let cpi_accounts = CheckPermission {
1915
sysvar_instructions: ctx.accounts.sysvar_instructions.to_account_info(),
2016
permission: ctx.accounts.permission.to_account_info(),
21-
protocol: ctx.accounts.protocol.to_account_info(),
17+
router: ctx.accounts.router.to_account_info(),
2218
};
2319
let cpi_ctx = CpiContext::new(cpi_program, cpi_accounts);
2420
express_relay::cpi::check_permission(cpi_ctx)?;
@@ -27,18 +23,6 @@ pub mod dummy {
2723
}
2824
}
2925

30-
#[derive(Accounts)]
31-
pub struct Initialize<'info> {
32-
#[account(mut)]
33-
pub payer: Signer<'info>,
34-
35-
/// CHECK: don't care what this PDA looks like
36-
#[account(init, payer = payer, space = 0, seeds = [SEED_EXPRESS_RELAY_FEES], bump)]
37-
pub fee_receiver_express_relay: UncheckedAccount<'info>,
38-
39-
pub system_program: Program<'info, System>,
40-
}
41-
4226
#[derive(Accounts)]
4327
pub struct DoNothing<'info> {
4428
#[account(mut)]
@@ -53,7 +37,6 @@ pub struct DoNothing<'info> {
5337
/// CHECK: this is the permission key
5438
pub permission: UncheckedAccount<'info>,
5539

56-
/// CHECK: this is the current program
57-
#[account(address = crate::ID)]
58-
pub protocol: UncheckedAccount<'info>,
40+
/// CHECK: this is the address to receive express relay fees at
41+
pub router: UncheckedAccount<'info>,
5942
}

express_relay/programs/express_relay/src/error.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub enum ErrorCode {
1616
MultiplePermissions,
1717
#[msg("Insufficient Searcher Funds")]
1818
InsufficientSearcherFunds,
19-
#[msg("Insufficient protocol fee receiver funds for rent")]
20-
InsufficientProtocolFeeReceiverRent,
21-
#[msg("Insufficient relayer fee receiver funds for rent")]
22-
InsufficientRelayerFeeReceiverRent,
23-
#[msg("Invalid PDA provided")]
24-
InvalidPDAProvided,
19+
#[msg("Insufficient funds for rent")]
20+
InsufficientRent,
2521
}

express_relay/programs/express_relay/src/lib.rs

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ pub mod express_relay {
1818
use super::*;
1919

2020
pub fn initialize(ctx: Context<Initialize>, data: InitializeArgs) -> Result<()> {
21-
validate_fee_split(data.split_protocol_default)?;
21+
validate_fee_split(data.split_router_default)?;
2222
validate_fee_split(data.split_relayer)?;
2323

2424
let express_relay_metadata_data = &mut ctx.accounts.express_relay_metadata;
2525

2626
express_relay_metadata_data.admin = *ctx.accounts.admin.key;
2727
express_relay_metadata_data.relayer_signer = *ctx.accounts.relayer_signer.key;
2828
express_relay_metadata_data.fee_receiver_relayer = *ctx.accounts.fee_receiver_relayer.key;
29-
express_relay_metadata_data.split_protocol_default = data.split_protocol_default;
29+
express_relay_metadata_data.split_router_default = data.split_router_default;
3030
express_relay_metadata_data.split_relayer = data.split_relayer;
3131

3232
Ok(())
@@ -50,27 +50,27 @@ pub mod express_relay {
5050
}
5151

5252
pub fn set_splits(ctx: Context<SetSplits>, data: SetSplitsArgs) -> Result<()> {
53-
validate_fee_split(data.split_protocol_default)?;
53+
validate_fee_split(data.split_router_default)?;
5454
validate_fee_split(data.split_relayer)?;
5555

5656
let express_relay_metadata_data = &mut ctx.accounts.express_relay_metadata;
5757

58-
express_relay_metadata_data.split_protocol_default = data.split_protocol_default;
58+
express_relay_metadata_data.split_router_default = data.split_router_default;
5959
express_relay_metadata_data.split_relayer = data.split_relayer;
6060

6161
Ok(())
6262
}
6363

64-
pub fn set_protocol_split(ctx: Context<SetProtocolSplit>, data: SetProtocolSplitArgs) -> Result<()> {
65-
validate_fee_split(data.split_protocol)?;
64+
pub fn set_router_split(ctx: Context<SetRouterSplit>, data: SetRouterSplitArgs) -> Result<()> {
65+
validate_fee_split(data.split_router)?;
6666

67-
ctx.accounts.protocol_config.protocol = *ctx.accounts.protocol.key;
68-
ctx.accounts.protocol_config.split = data.split_protocol;
67+
ctx.accounts.router_config.router = *ctx.accounts.router.key;
68+
ctx.accounts.router_config.split = data.split_router;
6969

7070
Ok(())
7171
}
7272

73-
// Submits a bid for a particular (protocol, permission) pair and distributes bids according to splits
73+
// Submits a bid for a particular (permission, router) pair and distributes bids according to splits
7474
pub fn submit_bid(ctx: Context<SubmitBid>, data: SubmitBidArgs) -> Result<()> {
7575
if data.deadline < Clock::get()?.unix_timestamp {
7676
return err!(ErrorCode::DeadlinePassed);
@@ -84,18 +84,18 @@ pub mod express_relay {
8484
// check "no reentrancy"--submit_bid instruction only used once in transaction
8585
// this is done to prevent an exploit where a searcher submits a transaction with multiple submit_bid instructions with different permission keys
8686
// that would allow the searcher to win the right to perform the transaction if they won just one of the auctions
87-
let permission_count = num_permissions_in_tx(ctx.accounts.sysvar_instructions.clone(), None, None)?;
87+
let permission_count = num_permissions_in_tx(ctx.accounts.sysvar_instructions.clone(), None)?;
8888
if permission_count > 1 {
8989
return err!(ErrorCode::MultiplePermissions);
9090
}
9191

9292
handle_bid_payment(ctx, data.bid_amount)
9393
}
9494

95-
// Checks if permissioning exists for a particular (protocol, permission) pair within the same transaction
96-
// Permissioning takes the form of a submit_bid instruction with matching protocol and permission accounts
95+
// Checks if permissioning exists for a particular (permission, router) pair within the same transaction
96+
// Permissioning takes the form of a submit_bid instruction with matching permission and router accounts
9797
pub fn check_permission(ctx: Context<CheckPermission>) -> Result<()> {
98-
let num_permissions = num_permissions_in_tx(ctx.accounts.sysvar_instructions.clone(), Some(*ctx.accounts.permission.key), Some(*ctx.accounts.protocol.key))?;
98+
let num_permissions = num_permissions_in_tx(ctx.accounts.sysvar_instructions.clone(), Some(PermissionInfo {permission: *ctx.accounts.permission.key, router: *ctx.accounts.router.key}))?;
9999

100100
if num_permissions == 0 {
101101
return err!(ErrorCode::MissingPermission);
@@ -121,7 +121,7 @@ pub mod express_relay {
121121

122122
#[derive(AnchorSerialize, AnchorDeserialize, Eq, PartialEq, Clone, Copy, Debug)]
123123
pub struct InitializeArgs {
124-
pub split_protocol_default: u64,
124+
pub split_router_default: u64,
125125
pub split_relayer: u64
126126
}
127127

@@ -174,7 +174,7 @@ pub struct SetRelayer<'info> {
174174

175175
#[derive(AnchorSerialize, AnchorDeserialize, Eq, PartialEq, Clone, Copy, Debug)]
176176
pub struct SetSplitsArgs {
177-
pub split_protocol_default: u64,
177+
pub split_router_default: u64,
178178
pub split_relayer: u64,
179179
}
180180

@@ -188,23 +188,23 @@ pub struct SetSplits<'info> {
188188
}
189189

190190
#[derive(AnchorSerialize, AnchorDeserialize, Eq, PartialEq, Clone, Copy, Debug)]
191-
pub struct SetProtocolSplitArgs {
192-
pub split_protocol: u64,
191+
pub struct SetRouterSplitArgs {
192+
pub split_router: u64,
193193
}
194194

195195
#[derive(Accounts)]
196-
pub struct SetProtocolSplit<'info> {
196+
pub struct SetRouterSplit<'info> {
197197
#[account(mut)]
198198
pub admin: Signer<'info>,
199199

200-
#[account(init_if_needed, payer = admin, space = RESERVE_EXPRESS_RELAY_CONFIG_PROTOCOL, seeds = [SEED_CONFIG_PROTOCOL, protocol.key().as_ref()], bump)]
201-
pub protocol_config: Account<'info, ConfigProtocol>,
200+
#[account(init_if_needed, payer = admin, space = RESERVE_EXPRESS_RELAY_CONFIG_ROUTER, seeds = [SEED_CONFIG_ROUTER, router.key().as_ref()], bump)]
201+
pub router_config: Account<'info, ConfigRouter>,
202202

203203
#[account(seeds = [SEED_METADATA], bump, has_one = admin)]
204204
pub express_relay_metadata: Account<'info, ExpressRelayMetadata>,
205205

206-
/// CHECK: this is just the protocol fee receiver PK
207-
pub protocol: UncheckedAccount<'info>,
206+
/// CHECK: this is just the router fee receiver PK
207+
pub router: UncheckedAccount<'info>,
208208

209209
pub system_program: Program<'info, System>,
210210
}
@@ -225,21 +225,18 @@ pub struct SubmitBid<'info> {
225225
/// CHECK: this is the permission_key
226226
pub permission: UncheckedAccount<'info>,
227227

228-
/// CHECK: this is the protocol/router address
229-
pub protocol: UncheckedAccount<'info>,
228+
/// CHECK: don't care what this looks like
229+
#[account(mut)]
230+
pub router: UncheckedAccount<'info>,
230231

231-
/// CHECK: this cannot be checked against ConfigProtocol bc it may not be initialized bc anchor. we need to check this config even when unused to make sure unique fee splits don't exist
232-
#[account(seeds = [SEED_CONFIG_PROTOCOL, protocol.key().as_ref()], bump)]
233-
pub protocol_config: UncheckedAccount<'info>,
232+
/// CHECK: this cannot be checked against ConfigRouter bc it may not be initialized bc anchor. we need to check this config even when unused to make sure unique fee splits don't exist
233+
#[account(seeds = [SEED_CONFIG_ROUTER, router.key().as_ref()], bump)]
234+
pub router_config: UncheckedAccount<'info>,
234235

235236
/// CHECK: this is just a PK for the relayer to receive fees at
236237
#[account(mut)]
237238
pub fee_receiver_relayer: UncheckedAccount<'info>,
238239

239-
/// CHECK: don't care what this looks like; if PDA, validate within program logic
240-
#[account(mut)]
241-
pub fee_receiver_protocol: UncheckedAccount<'info>,
242-
243240
#[account(mut, seeds = [SEED_METADATA], bump, has_one = relayer_signer, has_one = fee_receiver_relayer)]
244241
pub express_relay_metadata: Account<'info, ExpressRelayMetadata>,
245242

@@ -259,8 +256,8 @@ pub struct CheckPermission<'info> {
259256
/// CHECK: this is the permission_key
260257
pub permission: UncheckedAccount<'info>,
261258

262-
/// CHECK: this is the protocol/router address
263-
pub protocol: UncheckedAccount<'info>,
259+
/// CHECK: this is the router address
260+
pub router: UncheckedAccount<'info>,
264261
}
265262

266263
#[derive(Accounts)]

express_relay/programs/express_relay/src/state.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use anchor_lang::prelude::*;
22

33
pub const FEE_SPLIT_PRECISION: u64 = 10_000;
44

5-
pub const SEED_EXPRESS_RELAY_FEES: &[u8] = b"express_relay_fees";
6-
75
pub const RESERVE_EXPRESS_RELAY_METADATA: usize = 8+112+300;
86
pub const SEED_METADATA: &[u8] = b"metadata";
97

@@ -13,18 +11,18 @@ pub struct ExpressRelayMetadata {
1311
pub admin: Pubkey,
1412
pub relayer_signer: Pubkey,
1513
pub fee_receiver_relayer: Pubkey,
16-
// the portion of the bid that goes to the protocol, in bps
17-
pub split_protocol_default: u64,
18-
// the portion of the remaining bid (after protocol fees) that goes to the relayer, in bps
14+
// the portion of the bid that goes to the router, in bps
15+
pub split_router_default: u64,
16+
// the portion of the remaining bid (after router fees) that goes to the relayer, in bps
1917
pub split_relayer: u64,
2018
}
2119

22-
pub const RESERVE_EXPRESS_RELAY_CONFIG_PROTOCOL: usize = 8+40+200;
23-
pub const SEED_CONFIG_PROTOCOL: &[u8] = b"config_protocol";
20+
pub const RESERVE_EXPRESS_RELAY_CONFIG_ROUTER: usize = 8+40+200;
21+
pub const SEED_CONFIG_ROUTER: &[u8] = b"config_router";
2422

2523
#[account]
2624
#[derive(Default)]
27-
pub struct ConfigProtocol {
28-
pub protocol: Pubkey,
25+
pub struct ConfigRouter {
26+
pub router: Pubkey,
2927
pub split: u64,
3028
}

0 commit comments

Comments
 (0)