DeFi strategy to invest USDC in Compound in a loop in order to earn COMP rewards for approx x7 of the initial investment.
The tests are explained here. Run them on a mainnet fork with Hardhat:
npm install
npm run test
It's recommended to use Remix to deploy the contract using Trezor. Instructions:
-
Create a clean Remix project and upload
/contracts/*.sol
into the Remix/contracts
directory -
Fix OpenZepplin imports in all files by replacing
@openzeppelin
withhttps://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.3.0
-
Under Solidity Compiler tab:
- Set
Enable optimization: 200
- Click
Compile CompoundLoop.sol
- After compilation, copy its ABI by clicking
ABI
below
- Set
-
Under Deploy & run transactions tab:
- Set
Environment: Injected Web3
- Set
Gas limit: 4000000
- Near deploy, set
address _manager
to your Trezor address - Click
Deploy
- Set
- Owner can withdraw funds
- Manager can enter/exit the position in Compound
For simplicity, you can leave both roles as the deployer Trezor account since handling the contract can be manual (no bot needed).
It's recommended to take the ABI created during deployment and upload it as private custom ABI to Etherscan and this way we can easily use Etherscan's read/write interface (with Trezor) without publishing the contract source.
- Entering/exiting with $1M inside (with $10K minimum) takes ~5.5M gas
- Entering/exiting with $5M inside (with $50K minimum) also takes ~5.5M gas
- Claim COMP takes ~1M gas
- Call
getAccountLiquidity
to see that the liquidity is not dropping to zero (approaching liquidation). The liquidity should usually increase over time since combined interest rate should be positive. - For more exact results, it's better to static call (from a script)
getAccountLiquidityWithInterest
since this takes the latest interest into account too.
If exitPosition
fails, exit can be done manually:
-
Using multiple manual rollback transactions, see test #3
-
The owner of the contract can also execute an arbitrary transaction using
emergencySubmitTransaction
-
By sending more USDC to the contract before running
exitPosition
again, this will reduce the numebr of exit iterations -
By limiting the number of allowed iterations in
exitPosition
or reducing redeemRatio below 1