Skip to content

Commit 7d3eab1

Browse files
authored
feat: add todos from first code reading session (#662)
* feat: add todos from first code reading session Signed-off-by: Pablo Maldonado <[email protected]> * refactor: todo Signed-off-by: Pablo Maldonado <[email protected]> * fix: lint Signed-off-by: Pablo Maldonado <[email protected]> --------- Signed-off-by: Pablo Maldonado <[email protected]>
1 parent d86f727 commit 7d3eab1

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

programs/svm-spoke/src/instructions/admin.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use anchor_lang::prelude::*;
22

3+
// TODO: standardize imports across all files
34
use anchor_spl::associated_token::AssociatedToken;
45
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
56

7+
// TODO: check that the discriminator size is used everywhere
68
use crate::constants::DISCRIMINATOR_SIZE;
79
use crate::constraints::is_local_or_remote_owner;
810

@@ -13,15 +15,13 @@ use crate::{
1315
state::{RootBundle, Route, State},
1416
};
1517

16-
//TODO: there is too much in this file now and it should be split up somewhat.
17-
1818
#[derive(Accounts)]
1919
#[instruction(seed: u64)]
2020
pub struct Initialize<'info> {
2121
#[account(init, // Use init, not init_if_needed to prevent re-initialization.
2222
payer = signer,
23-
space = DISCRIMINATOR_SIZE + State::INIT_SPACE,
24-
seeds = [b"state", seed.to_le_bytes().as_ref()],
23+
space = DISCRIMINATOR_SIZE + State::INIT_SPACE, // TODO: check that INIT_SPACE is used everywhere
24+
seeds = [b"state", seed.to_le_bytes().as_ref()], // TODO: can we set a blank seed? or something better?
2525
bump)]
2626
pub state: Account<'info, State>,
2727

@@ -107,11 +107,12 @@ pub struct TransferOwnership<'info> {
107107

108108
#[account(
109109
mut,
110-
address = state.owner @ CustomError::NotOwner
110+
address = state.owner @ CustomError::NotOwner // TODO: test permissioning with a multi-sig and Squads
111111
)]
112112
pub signer: Signer<'info>,
113113
}
114114

115+
// TODO: check that the recovery flow is similar to the one in EVM
115116
pub fn transfer_ownership(ctx: Context<TransferOwnership>, new_owner: Pubkey) -> Result<()> {
116117
let state = &mut ctx.accounts.state;
117118
state.owner = new_owner;
@@ -138,6 +139,7 @@ pub fn set_cross_domain_admin(
138139
let state = &mut ctx.accounts.state;
139140
state.cross_domain_admin = cross_domain_admin;
140141

142+
// TODO: add lint to make this a 1-liner
141143
emit_cpi!(SetXDomainAdmin {
142144
new_admin: cross_domain_admin,
143145
});
@@ -147,7 +149,7 @@ pub fn set_cross_domain_admin(
147149

148150
#[event_cpi]
149151
#[derive(Accounts)]
150-
#[instruction(origin_token: [u8; 32], destination_chain_id: u64)]
152+
#[instruction(origin_token: [u8; 32], destination_chain_id: u64)] // TODO: is it possible to replace origin_token with Pubkey?
151153
pub struct SetEnableRoute<'info> {
152154
#[account(
153155
mut,
@@ -158,6 +160,7 @@ pub struct SetEnableRoute<'info> {
158160
#[account(mut)]
159161
pub payer: Signer<'info>,
160162

163+
// TODO: check if state needs to be mut here and in other places
161164
#[account(mut, seeds = [b"state", state.seed.to_le_bytes().as_ref()], bump)]
162165
pub state: Account<'info, State>,
163166

@@ -216,11 +219,12 @@ pub struct RelayRootBundle<'info> {
216219
)]
217220
pub signer: Signer<'info>,
218221

222+
// TODO: standardize usage of state.seed vs state.key()
219223
#[account(mut, seeds = [b"state", state.seed.to_le_bytes().as_ref()], bump)]
220224
pub state: Account<'info, State>,
221225

222226
// TODO: consider deriving seed from state.seed instead of state.key() as this could be cheaper (need to verify).
223-
#[account(init,
227+
#[account(init, // TODO: add comment explaining why init
224228
payer = signer,
225229
space = DISCRIMINATOR_SIZE + RootBundle::INIT_SPACE,
226230
seeds =[b"root_bundle", state.key().as_ref(), state.root_bundle_id.to_le_bytes().as_ref()],
@@ -240,5 +244,9 @@ pub fn relay_root_bundle(
240244
root_bundle.relayer_refund_root = relayer_refund_root;
241245
root_bundle.slow_relay_root = slow_relay_root;
242246
state.root_bundle_id += 1;
247+
248+
// TODO: add event
243249
Ok(())
244250
}
251+
252+
// TODO: add emergency_delete_root_bundle

programs/svm-spoke/src/instructions/deposit.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use anchor_spl::token_interface::{
2020
output_token: Pubkey,
2121
input_amount: u64,
2222
output_amount: u64,
23-
destination_chain_id: u64,
23+
destination_chain_id: u64, // TODO: we can remove some of these instructions props
2424
exclusive_relayer: Pubkey,
2525
quote_timestamp: u32,
2626
fill_deadline: u32,
@@ -36,6 +36,7 @@ pub struct DepositV3<'info> {
3636
)]
3737
pub state: Account<'info, State>,
3838

39+
// TODO: linter to format this line
3940
#[account(mut, seeds = [b"route", input_token.as_ref(), state.key().as_ref(), destination_chain_id.to_le_bytes().as_ref()], bump)]
4041
pub route: Account<'info, Route>,
4142

@@ -58,6 +59,7 @@ pub struct DepositV3<'info> {
5859
)]
5960
pub vault: InterfaceAccount<'info, TokenAccount>,
6061

62+
// TODO: why are we using mint::token_program,token::token_program and associated_token::token_program?
6163
#[account(
6264
mut,
6365
mint::token_program = token_program,
@@ -133,3 +135,5 @@ pub fn deposit_v3(
133135

134136
Ok(())
135137
}
138+
139+
// TODO: do we need other flavours of deposit? like speed up deposit

programs/svm-spoke/src/instructions/fill.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::{
2020
pub struct FillV3Relay<'info> {
2121
#[account(
2222
mut,
23-
seeds = [b"state", state.seed.to_le_bytes().as_ref()],
23+
seeds = [b"state", state.seed.to_le_bytes().as_ref()], // TODO: make consistent decision where to put owner constraints
2424
bump,
2525
constraint = !state.paused_fills @ CustomError::FillsArePaused
2626
)]
@@ -40,14 +40,14 @@ pub struct FillV3Relay<'info> {
4040

4141
#[account(
4242
mut,
43-
token::token_program = token_program,
43+
token::token_program = token_program, // TODO: consistent token imports
4444
address = relay_data.output_token @ CustomError::InvalidMint
4545
)]
4646
pub mint_account: InterfaceAccount<'info, Mint>,
4747

4848
#[account(
4949
mut,
50-
associated_token::mint = mint_account,
50+
associated_token::mint = mint_account, // TODO: consistent token imports
5151
associated_token::authority = relayer,
5252
associated_token::token_program = token_program
5353
)]
@@ -65,7 +65,7 @@ pub struct FillV3Relay<'info> {
6565
init_if_needed,
6666
payer = signer,
6767
space = DISCRIMINATOR_SIZE + FillStatusAccount::INIT_SPACE,
68-
seeds = [b"fills", relay_hash.as_ref()],
68+
seeds = [b"fills", relay_hash.as_ref()], // TODO: can we calculate the relay_hash from the state and relay_data?
6969
bump,
7070
// Make sure caller provided relay_hash used in PDA seeds is valid.
7171
constraint = is_relay_hash_valid(&relay_hash, &relay_data, &state) @ CustomError::InvalidRelayHash
@@ -77,7 +77,9 @@ pub struct FillV3Relay<'info> {
7777
pub system_program: Program<'info, System>,
7878
}
7979

80-
#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
80+
#[derive(AnchorSerialize, AnchorDeserialize, Clone)] // TODO: do we need all of these?
81+
82+
// TODO: should we move this data structure to a common module?
8183
pub struct V3RelayData {
8284
pub depositor: Pubkey,
8385
pub recipient: Pubkey,
@@ -126,6 +128,7 @@ pub fn fill_v3_relay(
126128

127129
// Invoke the transfer_checked instruction on the token program
128130
let transfer_accounts = TransferChecked {
131+
// TODO: check what happens if the relayer and recipient are the same
129132
from: ctx.accounts.relayer_token_account.to_account_info(),
130133
mint: ctx.accounts.mint_account.to_account_info(),
131134
to: ctx.accounts.recipient_token_account.to_account_info(),
@@ -145,8 +148,10 @@ pub fn fill_v3_relay(
145148
fill_status_account.status = FillStatus::Filled;
146149
fill_status_account.relayer = *ctx.accounts.signer.key;
147150

151+
// TODO: remove msg! everywhere
148152
msg!("Tokens transferred successfully.");
149153

154+
// TODO: there might be a better way to do this
150155
// Emit the FilledV3Relay event
151156
let message_clone = relay_data.message.clone(); // Clone the message before it is moved
152157

@@ -184,7 +189,7 @@ pub struct CloseFillPda<'info> {
184189

185190
#[account(
186191
mut,
187-
address = fill_status.relayer @ CustomError::NotRelayer
192+
address = fill_status.relayer @ CustomError::NotRelayer // TODO: check that this doesn't break PR 653
188193
)]
189194
pub signer: Signer<'info>,
190195

0 commit comments

Comments
 (0)