/simple-swap

SimpleSwap is a Solidity smart contract that facilitates token swaps using the Uniswap V3 protocol, allowing users to exchange tokens.

Primary LanguageSolidity

SimpleSwap

SimpleSwap is a Solidity smart contract that enables token swaps using the Uniswap V3 protocol. It allows users to swap a fixed amount of a spend token for a maximum possible amount of a received token or swap a fixed amount of a received token for a minimum possible amount of a spend token.

Prerequisites

Installation

  1. Clone the repository:

    git clone https://github.com/mohitchandel/simple-swap.git
  2. Install the dependencies:

    npm i or yarn
  3. Compile the contracts:

    npx hardhat compile

Usage

  1. Deploy the contract by providing the address of the Uniswap V3 SwapRouter as a constructor argument.

  2. Call the inputSwap function to swap a fixed amount of a spend token for a maximum possible amount of a receive token.

function inputSwap(IERC20 spendToken, IERC20 receiveToken, uint256 amountIn) public returns (uint256)
  1. Call the outputSwap function to swap a fixed amount of a receive token for a minimum possible amount of a spend token.
function outputSwap(IERC20 spendToken, IERC20 receiveToken, uint256 amountInMax, uint256 amountOut) public returns (uint256)

Testing

Run the contract tests:

npx hardhat test