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.
- Solidity v0.8.18 or compatible version
- OpenZeppelin Contracts v4.9.2 or compatible version
- Uniswap V3 Periphery v1.4.3 or compatible version
-
Clone the repository:
git clone https://github.com/mohitchandel/simple-swap.git
-
Install the dependencies:
npm i or yarn
-
Compile the contracts:
npx hardhat compile
-
Deploy the contract by providing the address of the Uniswap V3 SwapRouter as a constructor argument.
-
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)
- 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)
Run the contract tests:
npx hardhat test