- If not enough profit after calling liquidate once, next time liquidate up to 49%, then liquidate again Helpful resource: https://github.com/haydenshively/Nantucket/blob/master/contracts/Liquidator.sol
- Start docker desktop
git clone https://github.com/AlbertSu123/defi-mooc-lab.git
- In the first terminal, run
docker build -t defi-mooc-lab2 .
- Then run,
docker run -e ALCHE_API="https://eth-mainnet.alchemyapi.io/v2/HJ_i2RGc4L49NXkuwuST53fMYye2LGeB" -it defi-mooc-lab2 /bin/sh
- Open a second terminal, run
docker exec -it CONTAINER_ID /bin/bash
. You can get CONTAINER_ID by runningdocker ps
in your first terminal - To run tests, go to your second terminal and run
npm test
- To copy files to your second terminal, run
docker cp path/to/file CONTAINER_ID:/destination/path
. iedocker cp test/liquidation.js 46409c5f36f0:/lab2/test
-
You need to register an account on https://www.alchemy.com/ for access to an archive Ethereum node.
-
You need to prepare the nodeJS environment for the project yourself, or have docker installed on your machine.
-
The smart contract should allow you to perform a flash loan, a liquidation, and an asset exchange in one blockchain transaction.
-
To ease marking, we require your contract to provide a unified interface
operate
. By callingoperate
, the flash loan, liquidation, and exchange should be executed properly. You are allowed to "hardcode" the execution logic and parameters in theoperate
function.
function operate() external;
You are expected to liquidate 0x59CE4a2AC5bC3f5F225439B2993b86B42f6d3e9F
on Aave V2 which was liquidated at block 12489620
. Check out the original liquidation transaction.
To test your contract:
docker build -t defi-mooc-lab2 .
docker run -e ALCHE_API="$YOUR ALCHEMY ETHEREUM MAINNET API" -it defi-mooc-lab2 npm test
We provide the following background information for this exercise.
To trigger a liquidation on Aave, you need to call a public function liquidationCall
provided by the Aave smart contracts. In the function, you can specify user
representing the borrowing position you would like to liquidate, debtAsset
, the cryptocurrency you would like to repay (let's say token D), and collateralAsset
, the collateral cryptocurrency you would like claim from the borrowing position (let's say token C). You also specify the amount of debt you want to repay, debtToCover
.
function liquidationCall(
address collateralAsset,
address debtAsset,
address user,
uint256 debtToCover,
bool receiveAToken
) external;
By calling this function, you then repay some amount of token D to Aave and in return, some token C is sent to your account.
You should make sure that the user is in a liquidatable state. Otherwise, the aave smart contract would revert your transaction and you would pay transaction fees for an unsuccessful liquidation.