-
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
feat: whitelist and unwhitelist SPL tokens #41
Changes from 9 commits
9555f86
46cecb2
f156723
64e914f
b0d3184
03d757c
b20cf35
b7a4d63
1317d1c
e905e67
75ac812
4e2688c
7388e00
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 |
---|---|---|
|
@@ -34,7 +34,6 @@ declare_id!("ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis"); | |
|
||
#[program] | ||
pub mod gateway { | ||
|
||
use super::*; | ||
|
||
pub fn initialize( | ||
|
@@ -89,6 +88,15 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// whitelisting SPL tokens | ||
pub fn whitelist_spl_mint(_ctx: Context<AddToWhitelist>) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
pub fn de_whitelist_spl_mint(_ctx: Context<DeleteFromWhitelist>) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
// 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 | ||
|
@@ -338,8 +346,9 @@ pub struct Deposit<'info> { | |
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
|
||
#[account(mut)] | ||
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
|
@@ -348,8 +357,14 @@ pub struct DepositSplToken<'info> { | |
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
|
||
#[account(mut, seeds = [b"meta"], bump)] | ||
#[account(seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
|
||
#[account(seeds=[b"whitelist", mint_account.key().as_ref()], bump)] | ||
pub whitelist_entry: Account<'info, WhitelistEntry>, // attach whitelist entry to show the mint_account is whitelisted | ||
|
||
pub mint_account: Account<'info, Mint>, | ||
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. What does mint mean? There should be no minting involved since we lock/unlock SPL tokens? 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. according to description 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.
mint (short for mint account) is the Solana equivalent for ERC20 contract address. |
||
|
||
pub token_program: Program<'info, Token>, | ||
|
||
#[account(mut)] | ||
|
@@ -363,7 +378,7 @@ pub struct Withdraw<'info> { | |
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
|
||
#[account(mut)] | ||
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
/// CHECK: to account is not read so no need to check its owners; the program neither knows nor cares who the owner is. | ||
#[account(mut)] | ||
|
@@ -378,10 +393,9 @@ pub struct WithdrawSPLToken<'info> { | |
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
|
||
#[account(mut)] | ||
#[account(mut, token::mint = mint_account, token::authority = pda)] | ||
pub pda_ata: Account<'info, TokenAccount>, // associated token address of PDA | ||
|
||
#[account()] | ||
pub mint_account: Account<'info, Mint>, | ||
|
||
#[account(mut)] | ||
|
@@ -392,28 +406,73 @@ pub struct WithdrawSPLToken<'info> { | |
|
||
#[derive(Accounts)] | ||
pub struct UpdateTss<'info> { | ||
#[account(mut)] | ||
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct UpdateAuthority<'info> { | ||
#[account(mut)] | ||
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct UpdatePaused<'info> { | ||
#[account(mut)] | ||
#[account(mut, seeds = [b"meta"], bump)] | ||
pub pda: Account<'info, Pda>, | ||
#[account(mut)] | ||
pub signer: Signer<'info>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct AddToWhitelist<'info> { | ||
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. We should use consistent terminology with Solidity contracts:
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. changed to whitelist/unwhitelist across the board |
||
#[account( | ||
init, | ||
space=8, | ||
payer=authority, | ||
seeds=[ | ||
b"whitelist", | ||
whitelist_candidate.key().as_ref() | ||
], | ||
bump | ||
)] | ||
pub whitelist_entry: Account<'info, WhitelistEntry>, | ||
pub whitelist_candidate: Account<'info, Mint>, | ||
|
||
#[account(mut, seeds = [b"meta"], bump, has_one = authority)] | ||
pub pda: Account<'info, Pda>, | ||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
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. It means the signer (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. yes, |
||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct DeleteFromWhitelist<'info> { | ||
#[account( | ||
mut, | ||
seeds=[ | ||
b"whitelist", | ||
whitelist_candidate.key().as_ref() | ||
], | ||
bump, | ||
close = authority, | ||
)] | ||
pub whitelist_entry: Account<'info, WhitelistEntry>, | ||
pub whitelist_candidate: Account<'info, Mint>, | ||
|
||
#[account(mut, seeds = [b"meta"], bump, has_one = authority)] | ||
pub pda: Account<'info, Pda>, | ||
#[account(mut)] | ||
pub authority: Signer<'info>, | ||
|
||
pub system_program: Program<'info, System>, | ||
} | ||
|
||
#[account] | ||
pub struct Pda { | ||
nonce: u64, // ensure that each signature can only be used once | ||
|
@@ -423,6 +482,9 @@ pub struct Pda { | |
deposit_paused: bool, | ||
} | ||
|
||
#[account] | ||
pub struct WhitelistEntry {} | ||
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. just curious if is there a pros/cons for whitelisting in 2 following ways:
is it because having long lived pda in solana is not efficient if not needed because of rent, or something else? 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 whitelisting we really need is a mapping like Ethereum address=>bool But Solana does not have mapping as a data structure like Ethereum mapping.
The PDA for each key-value pair is the idiomatic way to do Ethereum mapping on Solana. 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 explanation |
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
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.
Unclear what these are for
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.
i think all logic for this is in the accounts definition, when you whitelist new one is created (with
init
), when you unwhitelist its closed (withclose
)