-
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 all 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 |
---|---|---|
|
@@ -88,6 +88,15 @@ pub mod gateway { | |
Ok(()) | ||
} | ||
|
||
// whitelisting SPL tokens | ||
pub fn whitelist_spl_mint(_ctx: Context<Whitelist>) -> Result<()> { | ||
Ok(()) | ||
} | ||
|
||
pub fn unwhitelist_spl_mint(_ctx: Context<Unwhitelist>) -> 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 | ||
|
@@ -351,6 +360,11 @@ pub struct DepositSplToken<'info> { | |
#[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>, | ||
|
||
pub token_program: Program<'info, Token>, | ||
|
||
#[account(mut)] | ||
|
@@ -414,6 +428,51 @@ pub struct UpdatePaused<'info> { | |
pub signer: Signer<'info>, | ||
} | ||
|
||
#[derive(Accounts)] | ||
pub struct Whitelist<'info> { | ||
#[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 Unwhitelist<'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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
according to description
Whitelisting is implemented as a special PDA for each mint account (SPL token id).
is needed to create pda for mint account and existence of that pda marks that token is whitelistedThere 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.
mint (short for mint account) is the Solana equivalent for ERC20 contract address.
This is Solana jargon.