This example demonstrates how to utilize the Money Legos Library to execute a flashloan and perform arbitrage across multiple decentralized exchanges (DEXs).
To facilitate testing of arbitrage smart contracts, this example utilizes two Uniswap exchanges deployed on the Kovan network. These exchanges, maintained by @robsjr and @ggviana, serve as reliable testing grounds. The exchanges are:
Below are step-by-step instructions to replicate this example on the Kovan Testnet.
-
Rename the 'env' file to '.env' and fill in the required values for your project.
-
Connect your Truffle console to the Kovan network:
truffle console --network kovan
Compile and deploy the smart contract to the Kovan network:
compile
migrate --reset
Interact with the deployed contract using the Truffle console:
let f = await FlashloanMoneyLego.deployed()
let assetToFlashLoan = '0xFf795577d9AC8bD7D90Ee22b6C1703490b6512FD' // DAI
let amountToLoan = web3.utils.toWei('1') // 1 unit of the assetToFlashLoan (DAI)
Object.keys(f)
f.addressesProvider()
f.initateFlashLoan(assetToFlashLoan, amountToLoan)
A Typescript file is provided to execute the same arbitrage logic:
Install Typescript and ts-node
:
npm install -g typescript
npm install -g ts-node
Run the script:
ts-node src/execFlashloanMoneyLego.ts
Verify the transaction output on [Kovan Etherscan].