Skip to main content

Liquidity.sol

An embedded solidity library for performing liquidity operations against the AMM of your choice. By providing the necessay parameters, you can easily do an addLiquidity or a removeLiquidity operation, without worrying about the necessary steps you need to code.

Usage

// Some method from your contract that calls ExchangeLiquidity to get the pool address for 2 tokensfunction getPoolAddress(address tokenA, address tokenB) external view returns (address) {    return ExchangeLiquidity.getPoolAddress(tokenA, tokenB);}
// Remove liquidity function removeLiquidityETH(    address token,    uint256 liquidity,    uint256 amountTokenMin,    uint256 amountETHMin,    address to,    uint256 deadline) external returns (uint256 amountToken, uint256 amountETH) {    return ExchangeLiquidity.removeLiquidityETH(token, liquidity, amountTokenMin, amountETHMin, to, deadline);}

Methods


// Remove liquidity for Token-ETH pair; the exchange is choosen automatically based on the layer you are calling it fromfunction removeLiquidityETH(    address token,    uint256 liquidity,    uint256 amountTokenMin,    uint256 amountETHMin,    address to,    uint256 deadline) internal returns (uint256 amountToken, uint256 amountETH)
// Remove liquidity for Token-ETH pair by using a specific exchange, identified by `_exchangeId`function removeLiquidityETH(    bytes32 _exchangeId,    address token,    uint256 liquidity,    uint256 amountTokenMin,    uint256 amountETHMin,    address to,    uint256 deadline) internal returns (uint256 amountToken, uint256 amountETH) 
// Remove liquidity for Token1-Token2 pair; the exchange is choosen automatically based on the layer you are calling it fromfunction removeLiquidity(    address tokenA,    address tokenB,    uint256 liquidity,    uint256 amountAMin,    uint256 amountBMin,    address to,    uint256 deadline) internal returns (uint256 amountA, uint256 amountB)
// Remove liquidity for Token1-Token2 pair by using a specific exchange, identified by `_exchangeId`function removeLiquidity(    bytes32 _exchangeId,    address tokenA,    address tokenB,    uint256 liquidity,    uint256 amountAMin,    uint256 amountBMin,    address to,    uint256 deadline) internal returns (uint256 amountA, uint256 amountB)

// Add liquidity for Token-ETH pair; the exchange is choosen automatically based on the layer you are calling it fromfunction addLiquidityETH(    address token,    uint256 amountTokenDesired,    uint256 amountTokenMin,    uint256 amountETHDesired,    uint256 amountETHMin,    address to,    uint256 deadline)    internal    returns (        uint256 amountToken,        uint256 amountETH,        uint256 liquidity    )
// Add liquidity for Token-ETH pair by using a specific exchange, identified by `_exchangeId`function addLiquidityETH(    bytes32 _exchangeId,    address token,    uint256 amountTokenDesired,    uint256 amountTokenMin,    uint256 amountETHDesired,    uint256 amountETHMin,    address to,    uint256 deadline)    internal    returns (        uint256 amountToken,        uint256 amountETH,        uint256 liquidity    )
// Add liquidity for Token1-Token2 pair; the exchange is choosen automatically based on the layer you are calling it fromfunction addLiquidity(    address tokenA,    address tokenB,    uint256 amountADesired,    uint256 amountBDesired,    uint256 amountAMin,    uint256 amountBMin,    address to,    uint256 deadline)    internal    returns (        uint256 amountA,        uint256 amountB,        uint256 liquidity    )
// Add liquidity for Token1-Token2 pair by using a specific exchange, identified by `_exchangeId`function addLiquidity(    bytes32 _exchangeId,    address tokenA,    address tokenB,    uint256 amountADesired,    uint256 amountBDesired,    uint256 amountAMin,    uint256 amountBMin,    address to,    uint256 deadline)    internal    returns (        uint256 amountA,        uint256 amountB,        uint256 liquidity    )
// Returns pool address for Token1-Token2 pairfunction getPoolAddress(address tokenA, address tokenB) internal view returns (address) 

All data like: chain id, exchange id and addresses can be retrieved from the Config contract