Skip to content

Latest commit

 

History

History
111 lines (79 loc) · 6.88 KB

README.md

File metadata and controls

111 lines (79 loc) · 6.88 KB

Execute FlashSwap using Uniswap V3

Perform a Flashloan in a pool , and use the funds to make swaps on other pools as Arbitrage to gain profit.

⚠️ Code is not Audited and yet to be tested extensively.

Installation Instruction

npm install

Execution Instructions

After installing all dependencies involving hardhat,ethers,waffle,etc Follow steps below:-

Start a localhost node

npx hardhat node

image

Paralelly open a new terminal and Start executing scripts

01_deploy.js

 npx hardhat run --network localhost .\scripts\01_deploy.js

image

02_tokenDeploy.js

 npx hardhat run --network localhost .\scripts\02_tokenDeploy.js

image

03_PoolsDeploy.js

 npx hardhat run --network localhost .\scripts\03_PoolsDeploy.js

image

04_LiquidityAddition.js

 npx hardhat run --network localhost .\scripts\04_LiquidityAddition.js

image

05_LiquidityCheck.js

 npx hardhat run --network localhost .\scripts\05_LiquidityCheck.js

image

06_FlashSwap.js

 npx hardhat run --network localhost .\scripts\06_FlashSwap.js

image

EXPLANATION AND ALGORITHM

image

Factory Contract :-

The Uniswap V3 Factory is a core contract in the Uniswap V3 protocol. It is responsible for creating and managing Uniswap V3 pools. The factory also provides a number of other functions, such as: Listing pools on the Uniswap V3 exchange Retiring pools from the exchange Managing the protocol fees The factory is a decentralized contract, meaning that it is not controlled by any single entity. This makes it a reliable and secure way to create and manage Uniswap V3 pools.

SWAP ROUTER

The SwapRouter contract is a smart contract that is used to execute swaps between tokens on Uniswap V3. It is a stateless contract, which means that it does not hold any token balances. This makes it more efficient and scalable than other types of contracts. The SwapRouter contract is used to execute swaps in two ways:

  1. Direct swaps: This is the simplest way to use the SwapRouter contract. You simply specify the tokens that you want to swap, the amount of each token that you want to swap, and the slippage tolerance. The SwapRouter contract will then execute the swap and return the amount of tokens that you received.
  2. Router swaps: This is a more complex way to use the SwapRouter contract. You can use router swaps to swap tokens between pools that are not directly connected. To do this, you specify the source pool, the destination pool, the amount of tokens that you want to swap, and the slippage tolerance. The SwapRouter contract will then execute the swap by first swapping your tokens to the pool token of the source pool. Then, it will swap the pool token of the source pool to the pool token of the destination pool.

NFT token Position

The NonfungibleTokenPositionDescriptor contract is used to describe NFT token positions in Uniswap V3. It provides a way to generate a string containing the data URI for a JSON metadata string. This metadata string can be used to display information about the NFT token position, such as the token ID, the token type, and the pool address.

image

image

TVL

TVL stands for Total Value Locked. It is a metric used to measure the amount of cryptocurrency that is deposited in a decentralized finance (DeFi) protocol. TVL is calculated by taking the sum of the value of all assets that are deposited in a protocol. TVL is a useful metric for measuring the popularity and health of a DeFi protocol. A high TVL indicates that a large amount of value is being locked up in the protocol, which suggests that users are confident in the protocol and its ability to provide liquidity. A low TVL, on the other hand, may indicate that users are not confident in the protocol or that the protocol is not offering attractive yields. TVL is also a useful metric for comparing different DeFi protocols. A protocol with a higher TVL is generally considered to be more popular and secure than a protocol with a lower TVL.

image

POSITION_MANAGER_ADDRESS

The POSITION_MANAGER_ADDRESS in Uniswap V3 is the address of the contract that manages positions. A position is a record of the tokens that you have provided as liquidity to a Uniswap V3 pool. The position manager contract is responsible for storing the state of all positions, including the tokens that are in the position, the price range of the position, and the fees that have been earned.

Tick and tickspace

A tick is a unit of price in Uniswap V3. The tick spacing is the distance between two ticks. The code first calculates the nearest usable tick to the given tick by rounding the tick down to the nearest multiple of the tick spacing. Then, it adds and subtracts 100 tick spacings from the nearest usable tick to calculate the lower and upper bounds of the nearest usable tick range. In Uniswap V3, the nearest usable tick range is used to determine which liquidity providers are eligible to participate in a trade. Only liquidity providers who have their liquidity within the nearest usable tick range of the trade will be able to earn fees from the trade. For example, if the given tick is 1000 and the tick spacing is 100, then the nearest usable tick range would be 900 to 1100. This means that only liquidity providers who have their liquidity within the range of 900 to 1100 will be able to earn fees from a trade that occurs at a price of 1000.

image

image

image

Thank you !!