Pool

A Pool describes a specific AMM trading algorithm and enables the storage and transfer of funds through the Vault.

Currently, there are two types of pools.

  • Classic Pool for general purpose

  • Stable Pool for efficient stablecoin exchange

Prefund the Pool with Vault

Like Uniswap V2 pools, the pool must be prefund before executing swapping. However, different from directly transferring tokens to the pool contract, caller have to prefund the pool via Vault deposit.

Here is an example.

// ...

// Transfer tokens from user and prefund the pool.
if (token == NATIVE_ETH) {
    // Deposit ETH to the vault.
    IVault(vault).deposit{value: amount}(token, pool);
} else {
    // Transfer tokens to the vault.
    TransferHelper.safeTransferFrom(token, msg.sender, vault, amount);

    // Notify the vault to deposit.
    IVault(vault).deposit(token, pool);
}

// Execute swap with the pool.
IBasePool(pool).swap(data);

Withdraw Tokens to Recipient

The withdrawMode on swapping will determine how to send the swapped tokens.

A withdrawMode of 0 will do an internal transfer. Please specify a withdraw mode, no matter whether the token is ETH, if you want to send the swapped tokens to the user account instead of leaving them in the vault. The withdraw mode has no effects on ERC20 tokens.

The following is the transfer implementation of pools.

Interface

The sender needs to be equal to msg.sender or sent from a trusted forwarder (the router), otherwise will be set to address(0) when passing to the callback.

Last updated