HyperSwap Docs
  • 🔎| HyperSwap
  • 🔗| Official Links
  • ❓| How to Start ?
    • Create a Wallet
    • How to Bridge on HyperEVM ?
  • PROTOCOL CONCEPTS
    • 🌐| Overview
    • 🏊Liquidity Pool
      • AMM Standard Liquidity Position
      • Concentrated Liquidity Position
      • ⚡Single Asset ZAP
    • 📐| Constant Factor AMM
    • 💲| Dynamic Fees
    • ✉️| Partner Referral
  • Points
    • 💎| Point Program
  • Token Design
    • ⛏️| Liquidity Mining
    • 🔄| Conversion and Redemption
    • 🤝| Revenues Sharing Model
    • 💰| Protocol Earnings
    • 🔥| Deflationary mechanisms
  • TOKENS
    • 🪙| $SWAP
    • 🔓| $xSWAP
  • Contracts
    • 📜| Hyper EVM
      • V2
      • V3
      • 🧰Tools
    • 📜| Testnet
      • V2
      • V3
    • 🖨️| Integrations
      • ⏯️Templates & Use Cases
      • 🏃Quick Start
        • V2
          • Swap with V2
          • Add liquidity with V2
          • Functions
        • V3
          • Swap with V3
        • Single Asset ZAP
          • Provide Liquidity With V2
          • Provide Liquidity With V3
          • Functions
  • REFERENCES
    • | Audits
    • 📖| Glossary
    • 🎨| Media Kit
Powered by GitBook
On this page
  1. Contracts
  2. | Integrations
  3. Quick Start
  4. V2

Functions

Here’s a list of all the functions from our Router ABI with a quick explanation of each function and its parameters:

The WETH() function retrieves the address of the Wrapped Ether (WETH) token used in the contract.

  • Signature: function WETH() external view returns (address)

  • Parameters: None.

  • Returns:

    • The address of the WETH token.


The addLiquidity function allows adding liquidity to a Uniswap pool between two ERC20 tokens.

  • Signature: function addLiquidity(address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) external returns (uint256 amountA, uint256 amountB, uint256 liquidity)

  • Parameters:

    • address tokenA: Address of the first token in the pair.

    • address tokenB: Address of the second token in the pair.

    • uint256 amountADesired: Desired amount of tokenA to add as liquidity.

    • uint256 amountBDesired: Desired amount of tokenB to add as liquidity.

    • uint256 amountAMin: Minimum acceptable amount of tokenA (slippage tolerance).

    • uint256 amountBMin: Minimum acceptable amount of tokenB (slippage tolerance).

    • address to: Address where liquidity (LP) tokens will be sent.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

  • Returns:

    • uint256 amountA: Actual amount of tokenA added to the pool.

    • uint256 amountB: Actual amount of tokenB added to the pool.

    • uint256 liquidity: Amount of liquidity tokens minted.


The addLiquidityETH function allows adding liquidity to a token-ETH pair.

  • Signature: function addLiquidityETH(address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external payable returns (uint256 amountToken, uint256 amountETH, uint256 liquidity)

  • Parameters:

    • address token: Address of the ERC20 token in the pair.

    • uint256 amountTokenDesired: Desired amount of the ERC20 token to add as liquidity.

    • uint256 amountTokenMin: Minimum acceptable amount of the ERC20 token (slippage tolerance).

    • uint256 amountETHMin: Minimum acceptable amount of ETH (slippage tolerance).

    • address to: Address where liquidity (LP) tokens will be sent.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

  • Returns:

    • uint256 amountToken: Actual amount of the ERC20 token added to the pool.

    • uint256 amountETH: Actual amount of ETH added to the pool.

    • uint256 liquidity: Amount of liquidity tokens minted.


The factory() function retrieves the address of the Uniswap factory contract associated with this instance.

  • Signature: function factory() external view returns (address)

  • Parameters: None.

  • Returns:

    • The address of the Uniswap factory contract.


The getAmountsOut function calculates the output token amounts for a given input amount and swap path.

  • Signature: function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts)

  • Parameters:

    • uint256 amountIn: Amount of the input token.

    • address[] path: Array of token addresses defining the swap path.

  • Returns:

    • uint256[] amounts: Array of output amounts for each token in the path.


The getPair function retrieves the address of the liquidity pool (pair) for two given tokens.

  • Signature: function getPair(address token1, address token2) external view returns (address)

  • Parameters:

    • address token1: Address of the first token.

    • address token2: Address of the second token.

  • Returns:

    • The address of the liquidity pool (pair) contract.


The quote function calculates how much of tokenB you would get for a given amount of tokenA based on their reserves.

  • Signature: function quote(uint256 amountA, uint256 reserveA, uint256 reserveB) external pure returns (uint256 amountB)

  • Parameters:

    • uint256 amountA: Amount of tokenA you want to convert.

    • uint256 reserveA: Reserve of tokenA in the liquidity pool.

    • uint256 reserveB: Reserve of tokenB in the liquidity pool.

  • Returns:

    • uint256 amountB: Calculated amount of tokenB.


The removeLiquidity function removes liquidity from a pool of two ERC20 tokens.

  • Signature: function removeLiquidity(address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline) external returns (uint256 amountA, uint256 amountB)

  • Parameters:

    • address tokenA: Address of the first token in the pair.

    • address tokenB: Address of the second token in the pair.

    • uint256 liquidity: Amount of liquidity tokens to burn.

    • uint256 amountAMin: Minimum acceptable amount of tokenA.

    • uint256 amountBMin: Minimum acceptable amount of tokenB.

    • address to: Address to send the withdrawn tokens.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

  • Returns:

    • uint256 amountA: Amount of tokenA returned.

    • uint256 amountB: Amount of tokenB returned.


The removeLiquidityETH function removes liquidity from a token-ETH pair.

  • Signature: function removeLiquidityETH(address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline) external returns (uint256 amountToken, uint256 amountETH)

  • Parameters:

    • address token: Address of the ERC20 token in the pair.

    • uint256 liquidity: Amount of liquidity tokens to burn.

    • uint256 amountTokenMin: Minimum acceptable amount of the token.

    • uint256 amountETHMin: Minimum acceptable amount of ETH.

    • address to: Address to send the withdrawn tokens.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

  • Returns:

    • uint256 amountToken: Amount of the token returned.

    • uint256 amountETH: Amount of ETH returned.

The removeLiquidityETHWithPermit function removes liquidity from a token-ETH pair, allowing token approval through an off-chain signature.

  • Signature: function removeLiquidityETHWithPermit(address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint256 amountToken, uint256 amountETH)

  • Parameters:

    • address token: Address of the ERC20 token in the pair.

    • uint256 liquidity: Amount of liquidity tokens to burn.

    • uint256 amountTokenMin: Minimum acceptable amount of the token.

    • uint256 amountETHMin: Minimum acceptable amount of ETH.

    • address to: Address to send the withdrawn tokens.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

    • bool approveMax: If true, the max amount of liquidity will be approved.

    • uint8 v, bytes32 r, bytes32 s: Signature components for the permit (used for off-chain approval).

  • Returns:

    • uint256 amountToken: Amount of the token returned.

    • uint256 amountETH: Amount of ETH returned.


The removeLiquidityETHWithPermitSupportingFeeOnTransferTokens function removes liquidity from a token-ETH pair while supporting tokens with transfer fees, and uses a permit for token approvals.

  • Signature: function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint256 amountETH)

  • Parameters:

    • Same as removeLiquidityETHWithPermit.

  • Returns:

    • uint256 amountETH: Amount of ETH returned.


The removeLiquidityWithPermit function removes liquidity from a token-token pair, allowing token approval through an off-chain signature.

  • Signature: function removeLiquidityWithPermit(address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s) external returns (uint256 amountA, uint256 amountB)

  • Parameters:

    • address tokenA: Address of the first token in the pair.

    • address tokenB: Address of the second token in the pair.

    • uint256 liquidity: Amount of liquidity tokens to burn.

    • uint256 amountAMin: Minimum acceptable amount of tokenA.

    • uint256 amountBMin: Minimum acceptable amount of tokenB.

    • address to: Address to send the withdrawn tokens.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.

    • bool approveMax: If true, the max amount of liquidity will be approved.

    • uint8 v, bytes32 r, bytes32 s: Signature components for the permit (used for off-chain approval).

  • Returns:

    • uint256 amountA: Amount of tokenA returned.

    • uint256 amountB: Amount of tokenB returned.


The swapExactETHForTokensSupportingFeeOnTransferTokens function swaps an exact amount of ETH for tokens, supporting tokens with transfer fees.

  • Signature: function swapExactETHForTokensSupportingFeeOnTransferTokens(uint256 amountOutMin, address[] calldata path, address to, address referrer, uint256 deadline) external payable

  • Parameters:

    • uint256 amountOutMin: Minimum acceptable amount of output tokens (slippage tolerance).

    • address[] path: Array of token addresses representing the swap path, starting with WETH and ending with the desired token.

    • address to: Address to receive the output tokens.

    • address referrer: Address of the referrer, if applicable (optional for referral programs).

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.


The swapExactTokensForETHSupportingFeeOnTransferTokens function swaps an exact amount of tokens for ETH, supporting tokens with transfer fees.

  • Signature: function swapExactTokensForETHSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, address referrer, uint256 deadline) external

  • Parameters:

    • uint256 amountIn: Exact amount of input tokens to swap.

    • uint256 amountOutMin: Minimum acceptable amount of ETH to receive (slippage tolerance).

    • address[] path: Array of token addresses representing the swap path, starting with the input token and ending with WETH.

    • address to: Address to receive the ETH.

    • address referrer: Address of the referrer, if applicable.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.


The swapExactTokensForTokensSupportingFeeOnTransferTokens function swaps an exact amount of tokens for another token, supporting tokens with transfer fees.

  • Signature: function swapExactTokensForTokensSupportingFeeOnTransferTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, address referrer, uint256 deadline) external

  • Parameters:

    • uint256 amountIn: Exact amount of input tokens to swap.

    • uint256 amountOutMin: Minimum acceptable amount of output tokens (slippage tolerance).

    • address[] path: Array of token addresses representing the swap path, starting with the input token and ending with the output token.

    • address to: Address to receive the output tokens.

    • address referrer: Address of the referrer, if applicable.

    • uint256 deadline: Unix timestamp after which the transaction will revert if not executed.


The receive() function allows the contract to accept ETH directly.

  • Signature: receive() external payable

  • Parameters: None.

  • Functionality: The contract can receive ETH without requiring any specific method call.


PreviousAdd liquidity with V2NextV3

Last updated 3 months ago

🖨️
🏃