Wrapper Program
Description of Wrapper program along with it's functions
Overview
The EWrapper program is a token wrapper that enables users to wrap regular SPL tokens and receive encrypted tokens in return. It acts as a bridge between public tokens and encrypted tokens.
Core Functionality
The program facilitates
- Deposit: Users wraps their regular SPL tokens into encrypted tokens.
- Mint: Program mints equivalent encrypted tokens (pointers)
- Burn: Users burn pointers (reduce them to zero) to request withdrawal
- Withdraw: Users receives regular tokens back after decryption.
The EWrapper program is a token wrapper that enables users to wrap regular SPL tokens and receive encrypted tokens in return. It acts as a bridge between public tokens and encrypted tokens.
Core Functionality
The program facilitates
- Deposit: Users wraps their regular SPL tokens into encrypted tokens.
- Mint: Program mints equivalent encrypted tokens (pointers)
- Burn: Users burn pointers (reduce them to zero) to request withdrawal
- Withdraw: Users receives regular tokens back after decryption.
Functions and Use Cases
1. Initialization Functions
initialize()
- Params:
- None
- Purpose: Initialize the wrapper program with a whitelisted relayer address for controlled decryption for now.
- Use Case: Set up the wrapper account with a designated relayer
- Key Features:
- Creates a WrapperAccount PDA
- Sets the authorized relayer for withdrawal callbacks
- Prevents double initialization
2. Deposit Functions
deposit_and_mint()
- Params:
- amount:
u64
- amount:
- Purpose: Deposit regular tokens and mint encrypted tokens
- Use Case: Convert regular SPL tokens into encrypted tokens.
- Process:
- Transfers regular tokens from user to program's token account
- Mints equivalent encrypted token pointers to user's e-token account
- Uses the e-token program for minting
deposit_and_mint_2022()
- Params
- amount:
u64
- amount:
- Purpose: Same as above but for Token-2022 standard
- Use Case: Support for newer token standards
- Key Difference: Uses Associated Token Program for token account creation
- Process:
- Same as above
3. Withdrawal Functions
burn_and_withdraw()
- Params
- to:
Pubkey - amount:
Einput - amount_pt:
u64
- to:
- Purpose: Burn e-tokens and initiate withdrawal process.
- Use Case: Initiate conversion of eToken back to regular tokens.
- Process:
- Burns the specified amount of e-tokens
- Calculated request id based on the decryption request parameters.
- Creates a PDA with request_id being the seed and store token decryption into it.
- Calls the PET executor to fire the transaction/event for decryption of requested pointer.
withdraw_callback()
- Params:
- amount:
Einput - pt_amount:
u64 - signature:
[u8; 64] - recovery_id:
u8
- amount:
- Purpose: Complete withdrawal process after verification of withdraw request.
- Use Case: Final step of withdrawal process by which receiver gets his funds.
- Process:
- Verifies the request id is valid and it exists.
- Validates the signature over the request id by the coprocessor.
- Transfers regular tokens to the mentioned address.
withdraw_callback_2022()
- Params:
- amount:
Einput - pt_amount:
u64 - signature:
[u8; 64] - recovery_id:
u8
- amount:
- Purpose: Same as above but for Token-2022 standard tokens.
Account Types
- WrapperAccount: Stores relayer info and initialization status
pub struct WrapperAccount {
pub is_initialized: bool,
pub relayer: Pubkey, // whitelisted relayer for the first phase of deployment
}- DecryptionRequest: Stores and tracks withdrawal’s info
pub struct DecryptionRequest {
pub request_id: [u8; 32],
pub token_mint: Pubkey, // token mint address
pub to_token_account: Pubkey, // receiver address
pub pt_amount: u64, // plaintext amount address
pub is_processed: bool, // status of request completion
}