-
Notifications
You must be signed in to change notification settings - Fork 2
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
refactor deposit_and_call
and deposit_spl_token_and_call
#35
Changes from all commits
5abfbaf
6f4eccd
acbd25c
b0318bb
0e18af4
f352dc3
f9151ac
0d81e93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// admin function to pause or unpause deposit | ||
pub fn set_deposit_paused(ctx: Context<UpdatePaused>, deposit_paused: bool) -> Result<()> { | ||
let pda = &mut ctx.accounts.pda; | ||
require!( | ||
|
@@ -84,7 +85,15 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
pub fn deposit(ctx: Context<Deposit>, amount: u64, receiver: [u8; 20]) -> Result<()> { | ||
// deposit SOL into this program and the `receiver` on ZetaChain zEVM | ||
// will get corresponding ZRC20 credit. | ||
// amount: amount of lamports (10^-9 SOL) to deposit | ||
// receiver: ethereum address (20Bytes) of the receiver on ZetaChain zEVM | ||
pub fn deposit( | ||
ctx: Context<Deposit>, | ||
amount: u64, | ||
receiver: [u8; 20], // not used in this program; for directing zetachain protocol only | ||
) -> Result<()> { | ||
let pda = &mut ctx.accounts.pda; | ||
require!(!pda.deposit_paused, Errors::DepositPaused); | ||
|
||
|
@@ -106,43 +115,31 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// deposit SOL into this program and the `receiver` on ZetaChain zEVM | ||
// will get corresponding ZRC20 credit. The `receiver` should be a contract | ||
// on zEVM and the `message` will be used as input data for the contract call. | ||
// The `receiver` contract on zEVM will get the SOL ZRC20 credit and receive the `message`. | ||
pub fn deposit_and_call( | ||
ctx: Context<Deposit>, | ||
amount: u64, | ||
receiver: [u8; 20], | ||
message: Vec<u8>, | ||
) -> Result<()> { | ||
require!(message.len() <= 512, Errors::MemoLengthExceeded); | ||
|
||
let pda = &mut ctx.accounts.pda; | ||
require!(!pda.deposit_paused, Errors::DepositPaused); | ||
|
||
let cpi_context = CpiContext::new( | ||
ctx.accounts.system_program.to_account_info(), | ||
system_program::Transfer { | ||
from: ctx.accounts.signer.to_account_info().clone(), | ||
to: ctx.accounts.pda.to_account_info().clone(), | ||
}, | ||
); | ||
system_program::transfer(cpi_context, amount)?; | ||
msg!( | ||
"{:?} deposits {:?} lamports to PDA and call contract {:?} with message {:?}", | ||
ctx.accounts.signer.key(), | ||
amount, | ||
receiver, | ||
message, | ||
); | ||
|
||
deposit(ctx, amount, receiver)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How/where do we emit the message so zEVM receives it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the function parameter |
||
Ok(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also why some methods have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we want to get rid of the Ok(()) at the end, it would look something like:
at the end; not sure i like this better than with the Ok(()) at the end; natuarally all instructions should have Ok(()) at the end. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, thanks for info |
||
} | ||
|
||
// deposit SPL token into this program and the `receiver` on ZetaChain zEVM | ||
// will get corresponding ZRC20 credit. | ||
// amount: amount of SPL token to deposit | ||
// receiver: ethereum address (20Bytes) of the receiver on ZetaChain zEVM | ||
#[allow(unused)] | ||
pub fn deposit_spl_token( | ||
ctx: Context<DepositSplToken>, | ||
amount: u64, | ||
memo: Vec<u8>, | ||
receiver: [u8; 20], // unused in this program; for directing zetachain protocol only | ||
) -> Result<()> { | ||
require!(memo.len() >= 20, Errors::MemoLengthTooShort); | ||
require!(memo.len() <= 512, Errors::MemoLengthExceeded); | ||
let token = &ctx.accounts.token_program; | ||
let from = &ctx.accounts.from; | ||
|
||
|
@@ -174,7 +171,25 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// only tss address stored in PDA can call this instruction | ||
// like `deposit_spl_token` instruction, | ||
// deposit SPL token into this program and the `receiver` on ZetaChain zEVM | ||
// will get corresponding ZRC20 credit. The `receiver` should be a contract | ||
// on zEVM and the `message` will be used as input data for the contract call. | ||
// The `receiver` contract on zEVM will get the SPL token ZRC20 credit and receive the `message`. | ||
#[allow(unused)] | ||
pub fn deposit_spl_token_and_call( | ||
ctx: Context<DepositSplToken>, | ||
amount: u64, | ||
receiver: [u8; 20], | ||
message: Vec<u8>, | ||
) -> Result<()> { | ||
require!(message.len() <= 512, Errors::MemoLengthExceeded); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want old memo.len() >= 20 condition as well? if not and MemoLengthTooShort is not used anymore we can remove it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also is this message length check something we need on GatewayEVM as well, to be compatible or is it solana specific? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. message could be less than 20 bytes. I guess we could remove the error MemoLengthTooShort There is a restriction on size of Solana tx (1023B??). Might as well have a limit in the instruction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, yes limit is 1232 |
||
deposit_spl_token(ctx, amount, receiver)?; | ||
Ok(()) | ||
} | ||
|
||
// require tss address signature on the internal message defined in the following | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can add issue to write comments in same format for all functions, something like // description... in solidity there is natspec, but couldnt find same for solana contracts, but we can make some format There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea. let me try something. |
||
// concatenated_buffer vec. | ||
pub fn withdraw( | ||
ctx: Context<Withdraw>, | ||
amount: u64, | ||
|
@@ -216,7 +231,8 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// only tss address stored in PDA can call this instruction | ||
// require tss address signature on the internal message defined in the following | ||
// concatenated_buffer vec. | ||
pub fn withdraw_spl_token( | ||
ctx: Context<WithdrawSPLToken>, | ||
amount: u64, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check also for message.len too short?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is comment above saying it can be smaller than 20, but maybe we can check for 0 value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 size message seems to be no problem; the app contract can expect empty message; maybe there is use case for that. Let's not be too pedantic here.