Encifher

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

  1. Deposit: Users wraps their regular SPL tokens into encrypted tokens.
  2. Mint: Program mints equivalent encrypted tokens (pointers)
  3. Burn: Users burn pointers (reduce them to zero) to request withdrawal
  4. 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

  1. Deposit: Users wraps their regular SPL tokens into encrypted tokens.
  2. Mint: Program mints equivalent encrypted tokens (pointers)
  3. Burn: Users burn pointers (reduce them to zero) to request withdrawal
  4. 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
  • Purpose: Deposit regular tokens and mint encrypted tokens
  • Use Case: Convert regular SPL tokens into encrypted tokens.
  • Process:
    1. Transfers regular tokens from user to program's token account
    2. Mints equivalent encrypted token pointers to user's e-token account
    3. Uses the e-token program for minting

deposit_and_mint_2022()

  • Params
    • amount: u64
  • 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
  • Purpose: Burn e-tokens and initiate withdrawal process.
  • Use Case: Initiate conversion of eToken back to regular tokens.
  • Process:
    1. Burns the specified amount of e-tokens
    2. Calculated request id based on the decryption request parameters.
    3. Creates a PDA with request_id being the seed and store token decryption into it.
    4. 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
  • Purpose: Complete withdrawal process after verification of withdraw request.
  • Use Case: Final step of withdrawal process by which receiver gets his funds.
  • Process:
    1. Verifies the request id is valid and it exists.
    2. Validates the signature over the request id by the coprocessor.
    3. Transfers regular tokens to the mentioned address.

withdraw_callback_2022()

  • Params:
    • amount: Einput
    • pt_amount: u64
    • signature: [u8; 64]
    • recovery_id: u8
  • 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
}