Pool Contract

Info Methods

token0

Returns the address of the first token in the pool.

Example Usage:

Copy

address firstToken = pool.token0();
// Returns the address of the first token in the pool.
>>> 0x1234567890abcdef1234567890abcdef12345678

token1

Returns the address of the second token in the pool.

Example Usage:

Copy

address secondToken = pool.token1();
// Returns the address of the second token in the pool.
>>> 0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4

reserve0

Returns the reserve of the first token in the pool.

Example Usage:

Copy

uint reserveFirstToken = pool.reserve0();
// Returns the reserve amount of the first token in the pool.
>>> 0x0

reserve1

Returns the reserve of the second token in the pool.

Example Usage:

Copy

uint reserveSecondToken = pool.reserve1();
// Returns the reserve amount of the second token in the pool.
>>> 0x0

getAssets

Returns the addresses of the assets in the pool.

Example Usage:

Copy

address[] memory assets = pool.getAssets();
// Returns an array containing the addresses of the pool's assets.
>>> [0x1234567890abcdef1234567890abcdef12345678, 0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4]

getReserves

Returns the current reserves of the tokens in the pool.

Example Usage:

Copy

(uint reserve0, uint reserve1) = pool.getReserves();
// Returns the reserve amount of the first token and the second token in the pool.
>>> (0x0, 0x0)

getA

Returns the current amplification coefficient of the pool.

Example Usage:

Copy

uint64 amplificationCoefficient = pool.getA();
// Returns the current amplification coefficient of the pool.
>>> 2000

Swap Methods

swap

Swaps one token for another within the pool. The function calculates the output amount based on the input amount and the current reserves, applies the swap fee, and updates the reserves accordingly.

Example Usage:

Copy

bytes memory data = abi.encode(token0, userAddress, 0); // Encode the swap data
address sender = userAddress; // The address of the user initiating the swap
address callback = address(0); // No callback in this example
bytes memory callbackData = ""; // No callback data

TokenAmount memory result = pool.swap(data, sender, callback, callbackData);
// Returns the amount of tokens received after the swap as a TokenAmount struct.
>>> TokenAmount { token: 0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4, amount: 990 }

getAmountOut

Calculates the amount of output tokens received for a given input amount.

Example Usage:

Copy

address tokenIn = token0;
uint amountIn = 1000;
address sender = userAddress;

uint amountOut = pool.getAmountOut(tokenIn, amountIn, sender);
// Returns the amount of output tokens for the given input amount.
>>> 990

Add/Remove Liquidity Methods

mint

Mints LP tokens in exchange for adding liquidity to the pool.

Example Usage:

Copy

bytes memory data = abi.encode(userAddress); // Encode the mint data
address sender = userAddress; // The address of the user initiating the mint
address callback = address(0); // No callback in this example
bytes memory callbackData = ""; // No callback data

uint lpTokensMinted = pool.mint(data, sender, callback, callbackData);
// Returns the amount of LP tokens minted.
>>> 500

burn

Burns LP tokens in exchange for removing liquidity from the pool.

Example Usage:

Copy

bytes memory data = abi.encode(userAddress, 0); // Encode the burn data
address sender = userAddress; // The address of the user initiating the burn
address callback = address(0); // No callback in this example
bytes memory callbackData = ""; // No callback data

TokenAmount[] memory amounts = pool.burn(data, sender, callback, callbackData);
// Returns the amounts of tokens returned to the user as an array of TokenAmount structs.
>>> [TokenAmount { token: 0x1234567890abcdef1234567890abcdef12345678, amount: 500 }, TokenAmount { token: 0x3355df6d4c9c3035724fd0e3914de96a5a83aaf4, amount: 1000 }]

burnSingle

Burns LP tokens and swaps one of the output tokens for another, allowing the user to receive a single token.

Example Usage:

Copy

bytes memory data = abi.encode(token0, userAddress, 0); // Encode the burn single data
address sender = userAddress; // The address of the user initiating the burn
address callback = address(0); // No callback in this example
bytes memory callbackData = ""; // No callback data

TokenAmount memory tokenAmount = pool.burnSingle(data, sender, callback, callbackData);
// Returns the amount of tokens received after the swap and burn as a TokenAmount struct.
>>> TokenAmount { token: 0x1234567890abcdef1234567890abcdef12345678, amount: 1500 }

Last updated