Depositing Funds

EVM-Compatible Networks

Native Coin Deposit

function deposit(address ephemeralL2Address, TradeInput calldata input, TradeDetail calldata data) external payable;

πŸ” Permissionless Execution

  • Callable by any user initiating a native coin trade.

  • Requires msg.value to match the expected deposit amount.

πŸ”Ž Trade Validation

  • Ensures the caller matches the expected sender in TradeInput.

  • Checks whether the tradeId derived from the input has already been used.

  • Prevents replay attacks or duplicate trade submissions.

πŸ” Trade State Transition

  • Records the hash of TradeDetail for future verification and process continuity.

πŸ“’ Event Emission

  • Emits a Deposited event with metadata required for off-chain monitoring and processing.

ERC-20 Token Deposit

function deposit(address ephemeralL2Address, TradeInput calldata input, TradeDetail calldata data) external;

πŸ” Permissionless Execution

  • Callable by any user initiating an ERC-20 token trade.

πŸ”Ž Trade Validation

  • Ensures the deposited token matches the configured LOCKING_TOKEN.

  • Ensures the caller matches the expected sender in TradeInput.

  • Checks whether the tradeId derived from the input has already been used.

  • Prevents replay or re-submission of the same trade.

πŸ’Έ Token Transfer

  • Uses safeTransferFrom to securely transfer tokens into the Vault contract.

  • The caller must approve the Vault to spend tokens prior to calling.

πŸ” Trade State Transition

  • Records the hash of TradeDetail for future verification and process continuity.

πŸ“’ Event Emission

  • Emits a Deposited event with metadata required for off-chain monitoring and processing.

Bitcoin Network

Solana Network

Native SOL and SPL-token deposit

Unlike EVM networks, we use a single function for depositing both native SOL and SPL tokens. The distinction between them is made using arguments and the list of accounts.

pub struct TradeInput {
    /// The sessionId, unique identifier for the trade.
    pub session_id: [u8; 32],  
    /// The solver address, the address of the solver.
    pub solver: [u8; 20],      
    /// The trade information, contains the information about the origin and destination of the trade.
    pub trade_info: TradeInfo, 
}

pub struct TradeDetailInput {
    pub timeout: i64,
    pub mpc_pubkey: Pubkey,
    pub refund_pubkey: Pubkey,
}
pub struct DepositArgs {
    /// Input trade information.
    pub input: TradeInput,
    /// Detailed trade data.
    pub data: TradeDetailInput,
    /// The tradeId, unique identifier for the trade.
    pub trade_id: [u8; 32],
}
pub fn handler_deposit<'c: 'info, 'info>(
    ctx: Context<'_, '_, 'c, 'info, DepositAccounts<'info>>,
    deposit_args: DepositArgs,
) -> Result<()>

πŸ” Permissionless Execution

  • Callable by any user initiating a trade.

πŸ”Ž Trade Validation

  • Ensures that the ephemeral_account is not associated with any active trades.

  • Ensures signer matches the expected spender in TradeInput .

  • Ensures the asset matches the expected value in the TradeInput. For native SOL, the asset is marked as native; otherwise, it is the public key of the SPL token.

  • Ensures the deposited amount is at least equal to the whitelisted minimum set by the operators.

  • Checks whether the tradeId derived from the input has already been used.

  • Check whether the asset was whitelisted by the operators beforehand.

  • Prevents replay attacks or duplicate trade submissions.

  • Ensures the deposited vault address matches the expected vault PDA uniquely derived for the trade.

πŸ’Έ Token Transfer

  • Use spl_token::transfer_checked instruction to securely transfer SPL-token with the correct accounts.

  • Use system_program::transfer instruction to transfer native SOL with the correct accounts.

πŸ” Trade State Transition

  • Creates a TradeDetail PDA account to store trade information for future verification and process continuity, state of the TradeDetail will be Deposited

Last updated