Skip to content

Commit

Permalink
feat: whitelist and unwhitelist SPL tokens (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 authored Oct 8, 2024
1 parent 74c9d81 commit 705831d
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 116 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ The PDA account address (derived from seeds `b"meta"` and canonical bump) is
2f9SLuUNb7TNeM6gzBwT4ZjbL5ZyKzzHg1Ce9yiquEjj
```


# Introduction


This repository hosts the smart contract (program) deployed on the Solana network to enable ZetaChain's cross-chain functionality. It consists of a single program that supports the following actions:

1. Users on the Solana network can send SOL to the program to deposit into ZetaChain, with the option to invoke a ZetaChain EVM contract.
Expand Down Expand Up @@ -112,4 +110,4 @@ brew install gnu-tar
# Put this in ~/.zshrc
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
```
see https://solana.stackexchange.com/questions/4499/blockstore-error-when-starting-solana-test-validator-on-macos-13-0-1/16319#16319
see https://solana.stackexchange.com/questions/4499/blockstore-error-when-starting-solana-test-validator-on-macos-13-0-1/16319#16319
62 changes: 62 additions & 0 deletions programs/protocol-contracts-solana/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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>,

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
Expand All @@ -423,6 +482,9 @@ pub struct Pda {
deposit_paused: bool,
}

#[account]
pub struct WhitelistEntry {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit 705831d

Please sign in to comment.