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.
>>> 0x0000000000000000000000000000000000000000

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.
>>> 0x0000000000000000000000000000000000000000

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.
>>> [0x0000000000000000000000000000000000000000, 0x0000000000000000000000000000000000000000]

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)

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: 0x0000000000000000000000000000000000000000, amount: 0 }

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.
>>> 0

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.
>>> 0

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: 0x0000000000000000000000000000000000000000, amount: 0 }, TokenAmount { token: 0x0000000000000000000000000000000000000000, amount: 0 }]

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: 0x0000000000000000000000000000000000000000, amount: 0 }

Last updated