con_dex_v2 (Router) Smart Contract Reference
The con_dex_v2 contract is the main entry point for all user interactions with the SNAKexchange protocol. It provides a comprehensive set of functions that simplify the process of swapping tokens and managing liquidity, while also performing essential safety checks.
Exported Methods
Below is a detailed description of the exported methods available in the con_dex_v2 contract.
addLiquidity(...)
Adds liquidity to a token pair, creating the pair if it does not already exist. It calculates the optimal amounts of tokens to deposit to match the current price ratio and mints LP tokens for the user.
-
tokenA: The contract address of the first token. -
tokenB: The contract address of the second token. -
amountADesired: The amount of tokenA the user wishes to deposit. -
amountBDesired: The amount of tokenB the user wishes to deposit. -
amountAMin: The minimum amount of tokenA the user is willing to deposit (for slippage protection). -
amountBMin: The minimum amount of tokenB the user is willing to deposit (for slippage protection). -
to: The address that will receive the LP tokens. -
deadline: A timestamp after which the transaction will revert.
removeLiquidity(...)
Removes liquidity from a pair by burning a user's LP tokens and returning their share of the underlying assets.
-
tokenA: The contract address of the first token in the pair. -
tokenB: The contract address of the second token in the pair. -
liquidity: The amount of LP tokens to burn. -
amountAMin: The minimum amount of tokenA the user is willing to receive. -
amountBMin: The minimum amount of tokenB the user is willing to receive. -
to: The address that will receive the withdrawn tokens. -
deadline: A timestamp after which the transaction will revert.
getAmountOut(amountIn, reserveIn, reserveOut)
A view function that calculates how many output tokens would be received for a given input amount in a single-hop swap.
-
amountIn: The amount of the input token. -
reserveIn: The reserve of the input token in the pair. -
reserveOut: The reserve of the output token in the pair.
getAmountsOut(amountIn, src, path)
A view function that calculates the resulting output amounts for each step of a multi-hop trade path.
-
amountIn: The initial amount of the input token. -
src: The contract address of the initial input token. -
path: A list of the numerical IDs of the pairs to trade through in sequence.
swapExactTokenForToken(...)
Swaps an exact amount of an input token for another token through a single pair.
-
amountIn: The exact amount of the input token to be swapped. -
amountOutMin: The minimum amount of output tokens the user is willing to accept. -
pair: The ID of the pair to trade through. -
src: The contract address of the input token. -
to: The address that will receive the output tokens. -
deadline: A timestamp after which the transaction will revert.
swapExactTokensForTokens(...)
Swaps an exact amount of an input token for another token, routing the trade through a specified path of multiple pairs.
-
amountIn: The exact amount of the input token to be swapped. -
amountOutMin: The minimum amount of the final output token the user is willing to accept. -
path: A list of the numerical IDs of the pairs to trade through in sequence. -
src: The contract address of the input token. -
to: The address that will receive the final output tokens. -
deadline: A timestamp after which the transaction will revert.
swapExactTokenForTokenSupportingFeeOnTransferTokens(...)
A specialized swap function for trading tokens that have a "fee-on-transfer" mechanism. It ensures the correct amount is swapped even if the token contract takes a fee during the transfer_from call.
Parameters: Same as swapExactTokenForToken.
swapExactTokensForTokensSupportingFeeOnTransferTokens(...)
A specialized multi-hop swap function for trading tokens that have a "fee-on-transfer" mechanism.
Parameters: Same as swapExactTokensForTokens.