In this example we will use the Money Legos Library to create a flashloan and arbitrage accross several DEXs.
This example uses a couple of exchanges set up and maintained by @robsjr and @ggviana. The are forks of Uniswap and published on the Kovan network to help test arbitrage smart contracts like this one. The two exchanges are:
I have made a video turtorial over on the DevBootstrap YouTube channel. Enjoy and don't forget to Like!
Below are high level instructions to try out this example using the Kovan Testnet.
Rename env to '.env' and complete the missing values for your project.
Connect your truffle console to the Kovan network like so:
truffle console --network kovan
Compile and deploy the contract to the Kovan network. From within your truffle console instance do the following:
compile
migrate --reset
Interact with the contract via 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)
There is a Typescript file that runs the same above arbitrage. This can be run as folllows.
Install Typescript and ts-node
npm install -g typescript
npm install -g ts-node
Now run the script as follows:
ts-node src/execFlashloanMoneyLego.ts
Confirm the transaction output in Kovan Etherscan.