Skip to content

Commit 55b1c78

Browse files
authored
fix: minor comment and structure fixes (#100)
1 parent b5990ee commit 55b1c78

File tree

8 files changed

+64
-61
lines changed

8 files changed

+64
-61
lines changed

programs/gateway/src/errors.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,3 @@ pub enum Errors {
2424
#[msg("InvalidInstructionData")]
2525
InvalidInstructionData,
2626
}
27-
28-
/// Enumeration for instruction identifiers in message hashes.
29-
#[repr(u8)]
30-
pub enum InstructionId {
31-
Withdraw = 1,
32-
WithdrawSplToken = 2,
33-
WhitelistSplToken = 3,
34-
UnwhitelistSplToken = 4,
35-
Execute = 5,
36-
ExecuteSplToken = 6,
37-
IncrementNonce = 7,
38-
}

programs/gateway/src/instructions/admin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
contexts::{Initialize, Unwhitelist, UpdateAuthority, UpdatePaused, UpdateTss, Whitelist},
3-
errors::InstructionId,
3+
state::InstructionId,
44
utils::{
55
recover_and_verify_eth_address, validate_message_hash, verify_and_update_nonce,
66
verify_authority,
@@ -31,7 +31,7 @@ pub fn initialize(ctx: Context<Initialize>, tss_address: [u8; 20], chain_id: u64
3131
Ok(())
3232
}
3333

34-
/// Updates the TSS address. Caller is authority stored in PDA.
34+
// Updates the TSS address. Caller is authority stored in PDA.
3535
pub fn update_tss(ctx: Context<UpdateTss>, tss_address: [u8; 20]) -> Result<()> {
3636
verify_authority(&ctx.accounts.signer.key(), &ctx.accounts.pda)?;
3737
let pda = &mut ctx.accounts.pda;

programs/gateway/src/instructions/execute.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{
22
contexts::{Execute, ExecuteSPLToken, IncrementNonce},
3-
errors::InstructionId,
43
state::CallableInstruction,
4+
state::InstructionId,
55
utils::{prepare_account_metas, validate_message, verify_ata_match},
66
};
77
use anchor_lang::prelude::*;
@@ -92,7 +92,7 @@ pub fn handle_sol(
9292
Ok(())
9393
}
9494

95-
// Execute with SPL tokens. Caller is TSS.
95+
// Withdraws amount of SPL tokens to destination program pda, and calls on_call on destination program
9696
pub fn handle_spl_token(
9797
ctx: Context<ExecuteSPLToken>,
9898
decimals: u8,

programs/gateway/src/instructions/withdraw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
contexts::{Withdraw, WithdrawSPLToken},
3-
errors::InstructionId,
3+
state::InstructionId,
44
utils::{validate_message, verify_ata_match, DEFAULT_GAS_COST},
55
};
66
use anchor_lang::prelude::*;

programs/gateway/src/lib.rs

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ pub mod gateway {
3535
}
3636

3737
/// Increments nonce, used by TSS in case outbound fails.
38-
/// # Arguments:
38+
/// # Arguments
3939
/// * `ctx` - The instruction context.
40-
/// * `amount` - The amount of lamports to increment.
41-
/// * `signature` - The signature of the message.
42-
/// * `recovery_id` - The recovery ID of the signature.
43-
/// * `message_hash` - The hash of the message.
44-
/// * `nonce` - The nonce of the message.
40+
/// * `amount` - The amount in original outbound.
41+
/// * `signature` - The TSS signature.
42+
/// * `recovery_id` - The recovery ID for signature verification.
43+
/// * `message_hash` - Message hash for signature verification.
44+
/// * `nonce` - The current nonce value.
4545
pub fn increment_nonce(
4646
ctx: Context<IncrementNonce>,
4747
amount: u64,
@@ -61,14 +61,15 @@ pub mod gateway {
6161
}
6262

6363
/// Withdraws amount to destination program pda, and calls on_call on destination program
64-
/// # Arguments:
65-
/// * `amount`: Amount of SOL to transfer
66-
/// * `sender`: Sender's address
67-
/// * `data`: Arbitrary data to pass to the destination program
68-
/// * `signature`: Signature of the message
69-
/// * `recovery_id`: Recovery ID of the signature
70-
/// * `message_hash`: Hash of the message
71-
/// * `nonce`: Nonce of the message
64+
/// # Arguments
65+
/// * `ctx` - The instruction context.
66+
/// * `amount` - Amount of SOL to transfer.
67+
/// * `sender` - Sender's address.
68+
/// * `data` - Arbitrary data to pass to the destination program.
69+
/// * `signature` - Signature of the message.
70+
/// * `recovery_id` - Recovery ID of the signature.
71+
/// * `message_hash` - Hash of the message.
72+
/// * `nonce` - Nonce of the message.
7273
pub fn execute(
7374
ctx: Context<Execute>,
7475
amount: u64,
@@ -91,16 +92,17 @@ pub mod gateway {
9192
)
9293
}
9394

94-
/// Execute with SPL tokens. Caller is TSS.
95-
/// # Arguments:
96-
/// * `decimals`: Decimals of the token
97-
/// * `amount`: Amount of tokens to transfer
98-
/// * `sender`: Sender's Ethereum address
99-
/// * `data`: Arbitrary data to pass to the destination program
100-
/// * `signature`: Signature of the message
101-
/// * `recovery_id`: Recovery ID of the signature
102-
/// * `message_hash`: Hash of the message
103-
/// * `nonce`: Nonce of the message
95+
/// Withdraws amount of SPL tokens to destination program pda, and calls on_call on destination program
96+
/// # Arguments
97+
/// * `ctx` - The instruction context.
98+
/// * `decimals` - Token decimals for precision.
99+
/// * `amount` - The amount of tokens to withdraw.
100+
/// * `sender` - Sender from ZEVM.
101+
/// * `data` - Data to pass to destination program.
102+
/// * `signature` - The TSS signature.
103+
/// * `recovery_id` - The recovery ID for signature verification.
104+
/// * `message_hash` - Message hash for signature verification.
105+
/// * `nonce` - The current nonce value.
104106
pub fn execute_spl_token(
105107
ctx: Context<ExecuteSPLToken>,
106108
decimals: u8,
@@ -191,7 +193,7 @@ pub mod gateway {
191193
/// * `ctx` - The instruction context.
192194
/// * `amount` - The amount of lamports to deposit.
193195
/// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
194-
/// * `deposit_fee` - The fee to be deducted from the deposited amount.
196+
/// * `revert_options` - The revert options created by the caller.
195197
pub fn deposit(
196198
ctx: Context<Deposit>,
197199
amount: u64,
@@ -204,7 +206,7 @@ pub mod gateway {
204206
/// Deposits SOL and calls a contract on ZetaChain zEVM.
205207
/// # Arguments
206208
/// * `ctx` - The instruction context.
207-
/// * `amount` - The amount of SPL tokens to deposit.
209+
/// * `amount` - The amount of lamports to deposit.
208210
/// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
209211
/// * `message` - The message passed to the contract.
210212
/// * `revert_options` - The revert options created by the caller.
@@ -230,6 +232,7 @@ pub mod gateway {
230232
/// * `ctx` - The instruction context.
231233
/// * `amount` - The amount of SPL tokens to deposit.
232234
/// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
235+
/// * `revert_options` - The revert options created by the caller.
233236
pub fn deposit_spl_token(
234237
ctx: Context<DepositSplToken>,
235238
amount: u64,
@@ -245,8 +248,7 @@ pub mod gateway {
245248
/// * `amount` - The amount of SPL tokens to deposit.
246249
/// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
247250
/// * `message` - The message passed to the contract.
248-
/// * `deposit_fee` - The fee to be deducted from the deposited amount.
249-
/// * `max_message_size` - The maximum allowed message size.
251+
/// * `revert_options` - The revert options created by the caller.
250252
pub fn deposit_spl_token_and_call(
251253
ctx: Context<DepositSplToken>,
252254
amount: u64,
@@ -268,7 +270,7 @@ pub mod gateway {
268270
/// # Arguments
269271
/// * `receiver` - The Ethereum address of the receiver on ZetaChain zEVM.
270272
/// * `message` - The message passed to the contract.
271-
/// * `max_message_size` - The maximum allowed message size.
273+
/// * `revert_options` - The revert options created by the caller.
272274
pub fn call(
273275
ctx: Context<Call>,
274276
receiver: [u8; 20],
@@ -279,13 +281,13 @@ pub mod gateway {
279281
}
280282

281283
/// Withdraws SOL. Caller is TSS.
282-
/// Arguments:
284+
/// # Arguments
283285
/// * `ctx` - The instruction context.
284-
/// * `amount` - The amount of lamports to withdraw.
285-
/// * `signature` - The signature of the message.
286-
/// * `recovery_id` - The recovery ID of the signature.
287-
/// * `message_hash` - The hash of the message.
288-
/// * `nonce` - The nonce of the message.
286+
/// * `amount` - The amount of SOL to withdraw.
287+
/// * `signature` - The TSS signature.
288+
/// * `recovery_id` - The recovery ID for signature verification.
289+
/// * `message_hash` - Message hash for signature verification.
290+
/// * `nonce` - The current nonce value.
289291
pub fn withdraw(
290292
ctx: Context<Withdraw>,
291293
amount: u64,
@@ -298,14 +300,14 @@ pub mod gateway {
298300
}
299301

300302
/// Withdraws SPL tokens. Caller is TSS.
301-
/// Arguments:
303+
/// # Arguments
302304
/// * `ctx` - The instruction context.
303-
/// * `decimals` - The decimals of the token.
304-
/// * `amount` - The amount of tokens to transfer.
305-
/// * `signature` - The signature of the message.
306-
/// * `recovery_id` - The recovery ID of the signature.
307-
/// * `message_hash` - The hash of the message.
308-
/// * `nonce` - The nonce of the message.
305+
/// * `decimals` - Token decimals for precision.
306+
/// * `amount` - The amount of tokens to withdraw.
307+
/// * `signature` - The TSS signature.
308+
/// * `recovery_id` - The recovery ID for signature verification.
309+
/// * `message_hash` - Message hash for signature verification.
310+
/// * `nonce` - The current nonce value.
309311
pub fn withdraw_spl_token(
310312
ctx: Context<WithdrawSPLToken>,
311313
decimals: u8,

programs/gateway/src/state.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,15 @@ pub struct RevertOptions {
7979
pub revert_message: Vec<u8>,
8080
pub on_revert_gas_limit: u64,
8181
}
82+
83+
/// Enumeration for instruction identifiers in message hashes.
84+
#[repr(u8)]
85+
pub enum InstructionId {
86+
Withdraw = 1,
87+
WithdrawSplToken = 2,
88+
WhitelistSplToken = 3,
89+
UnwhitelistSplToken = 4,
90+
Execute = 5,
91+
ExecuteSplToken = 6,
92+
IncrementNonce = 7,
93+
}

programs/gateway/src/utils/validate_message.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use anchor_lang::prelude::*;
33
use super::recover_and_verify_eth_address::recover_and_verify_eth_address;
44
use super::validate_message_hash::validate_message_hash;
55
use super::verify_and_update_nonce::verify_and_update_nonce;
6-
use crate::errors::InstructionId;
6+
use crate::state::InstructionId;
77
use crate::state::Pda;
88

99
/// Perform common cross-chain verification steps

programs/gateway/src/utils/validate_message_hash.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use anchor_lang::prelude::*;
22
use solana_program::keccak::hash;
33

44
use super::constants::ZETACHAIN_PREFIX;
5-
use crate::errors::{Errors, InstructionId};
5+
use crate::errors::Errors;
6+
use crate::state::InstructionId;
67

78
/// Creates and validates a message hash for cross-chain instruction verification
89
/// with optional amount inclusion

0 commit comments

Comments
 (0)