Skip to content

massun-onibakuchi/grim-reaper

Repository files navigation

Reaper • ci license solidity

Getting Started

This is grim-reaper: EVM-based on-chain liquidation bot for Aave V3 built with Huff language. Optimized for gas efficiency. This repo doesn't include any off-chain architecture.

Requirements

The following will need to be installed. Please follow the links and instructions.

Quickstart

  1. Install dependencies

Once you've cloned and entered into your repository, you need to install the necessary dependencies. In order to do so, simply run:

pnpm install
forge install
  1. Build & Test

To build and test your contracts, you can run:

forge build
forge test

For more information on how to use Foundry, check out the Foundry Github Repository and the foundry-huff library repository.

Single Liquidation (Optimizer runs: 200) Gas Used Bytecode Size (kB)
Solidity Contract 98783 1.005
Assembly 97679 0.303
Assembly (GrimReaper V2) 97648 0.317
Huff Contract 97597 0.231
Single Liquidation (Optimizer runs: 10_000_000) Gas Used Bytecode Size (kB)
Solidity Contract 98127 1.308
Assembly 97089 0.330
Assembly (GrimReaper V2) 97058 0.344
Huff Contract 97019 0.231

66270 gas is used for the liquidation logic itself on mock Aave v3 pool.

Note: Optimizer runs affects how well the compiler optimizes tests contract as well. So, it affects measurements.

  • solc version: 0.8.24, evm version: cancun with bytecode_hash = "none" and cbor_metadata = false.
  • forge snapshot --fuzz-seed=111 -vv

Further Optimization Ideas

  • Support limited kinds of collateral tokens and remove collateral parameter from main entrypoint
    • O(1) selector table for token addresses. (GrimReaper V2)
    • Approve once on contract deployment instead of every liquidation
  • Replace jumpi with other operations
    • Use mload(type(uint256).max) for jumpi if-else-revert pattern (GrimReaperHuff)
  • Abuse returndatasize, calldatasize, chainid and msize for push operations (GrimReaperHuff)

Acknowledgements

Disclaimer

These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. The creators are not liable for any of the foregoing. Users should proceed with caution and use at their own risk.

About

on-chain liquidation bot built with Huff language

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published