Skip to content

samarth9201/UniswapFlashSwap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniswapFlashSwap

An abstraction for UniswapV2 flash swaps. Enables the user to borrow any token and repay using any other token. Abstracts away most of the nitty-gritty details of the UniswapV2 core contracts.

How to use

  1. Deploy the FlashSwapContract the parameters to Constructor are two addresses. _WETH, _DAI and UniswapFactory are the parameters which are addresses of WETH, DAI and UniswapV2Factory on respective network.
  2. You need some tokens in the contract before executing a flash swap. You can do this by simply sending the token from the wallet to the address of contract. In order to understand how much balance is required, please check fees section.
  3. In order to execute a Flash Swap, call the flashSwap() function. The parameters of this function are:
  • _tokenBorrow The address of the token you want to flash-borrow, use 0x0000000000000000000000000000000000000000 for ETH.
  • _amount The amount of _tokenBorrow you will borrow.
  • _tokenPay The address of the token you want to use to payback the flash-borrow, use 0x0000000000000000000000000000000000000000 for ETH.
  • _userData Data that will be passed to the execute function for the user. You can send some value like 'flash'.
  1. You can see the flash swap on the network.
  2. In order to withdraw the Token, call withdraw() function. This function takes address of token as input. If you want to withdraw ETH, pass 0x0000000000000000000000000000000000000000 as parameter.

Address

The contract is deployed on Ropsten Testnet. The address is 0x936f988CdD068C9e2e94800Cf712515c2E3F78C5

Sample Transactions:

Flash Swap
Withdraw

Fees

Each UniswapV2 pair charges a 0.3% fee.

  • If you are doing a traditional "flash loan", where you repay using the same token that you borrowed, you'll be charged a 0.3% fee.
  • If you are borrowing ETH or WETH and repaying with a non-{ETH, WETH} token, you'll be charged a 0.3% fee.
  • If you are borrowing a non-{ETH, WETH} token and repaying with ETH or WETH, then you'll be charged a 0.3% fee.
  • If you are swapping a non-{ETH, WETH} token for another non-{ETH, WETH} token, then you'll be charged a 0.6% fee because your swap will touch two UniswapV2 pairs (they are routed through the WETH).

Reference

https://github.com/Austin-Williams/uniswap-flash-swapper

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published