The Liquidity Hook Money Market -- Lend, Borrow, and Access Yield Strategies with Liquidity Hook.
Platform: Code4rena
Start Date: 26/01/2024
End Date: 02/02/2024
Period: 7 days
Status: Completed
Pot Size: $25,000 USDC
Participants: 5
Reporter: PaperParachute
Judge: hansfriese
Id: 325
League: ETH
said | 1/5 | $0.00 | 5 | 3 | 0 | 2 | 0 | 0 | 0 | 0 |
0x73696d616f | 2/5 | $0.00 | 0 | 0 | 0 | 0 | 0 | Grade A | 0 | 0 |
ladboy233 | 3/5 | $0.00 | 4 | 2 | 0 | 2 | 0 | Grade A | 0 | 0 |
rvierdiiev | 4/5 | $0.00 | 4 | 2 | 0 | 2 | 0 | Grade B | 0 | 0 |
sashik_eth | 5/5 | $0.00 | 3 | 1 | 0 | 2 | 1 | Grade B | 0 | 0 |
Auditor per page
*For this contest, we will be adding Bytecode Size award for Bytecode Size optimizations for reduction of InitCore.sol
and MarginTradingHook.sol
contracts, since they are close to reaching the bytecode size limit.
The 4naly3er report can be found here.
Note for C4 wardens: Anything included in this Automated Findings / Publicly Known Issues
section is considered a publicly known issue and is ineligible for awards.
Known issues:
burnTo
may block users from closing the position, so we plan to create a new collateral pool that will only allow only lending and no borrowing.safeMint
, so it is possible for contracts to receive ERC721 even if it does not implement ERC721Holder.totalInterest
may slightly overestimate the actual interest accrual due to rounding up (in the order of wei).INIT Capital is a composable liquidity hook money market that allows any DeFi protocols to permissionlessly build liquidity hook plugins and borrow liquidity to execute various DeFi strategies from simple to complex strategies. Additionally, end users on INIT Capital have access to all hooks, which are yield generating strategies, in a few clicks without having to use and manage many accounts and positions on multiple DeFi applications.
More overview is provided in the following document (password: Audit)
INIT Key features include:
InitCore - The primary entrypoint for most interactions. Users can perform actions directly to each function or utilize multicall to batch several actions together. Key actions include:
LendingPool - Manages the supply and the total debt share.
PosManager - Manages each position, including the debt shares of each borrowed token, and also the collaterals
LiqIncentiveCalculator - Handles liquidation incentive calculation. It is currently based on how unhealthy the position is.
MoneyMarketHook - Hook implementation for regular money market actions: deposit, withdraw, borrow, repay.
WLp - Wrapped LP contract (currently not in scope, since this is pending integration with certain DEXs). This should also handle reward calculations.
InitOracle - Aggregate underlying oracle prices by using primary & secondary sources.
RiskManager - Handles potential risk that may arise in the money market, for example, large price impact from having too much concentration of collateralization (currently handled by the introduction of debt ceiling per mode).
NEW: MarginTradingHook - Hook implementation for margin trading actions. Some features include margin trading, stop loss, and take profit actions.
WLpMoeMasterChef - Wrapped LP contract implementation for Merchant Moe DEX (with MasterChef staking contract).
MoeSwapHelper - Helper contract for swapping tokens on Merchant Moe DEX.
Part 1 scope: new contracts
Contract | SLOC | Purpose |
---|---|---|
contracts/wrapper/WLpMoeMasterChef.sol | 209 | Wrapped LP for Merchant Moe integration |
contracts/hook/MarginTradingHook.sol | 468 | Hook implementation for margin trading actions |
contracts/common/library/InitErrors.sol | 58 (most lines are just trivial constants, which can be ignored) | Error library |
contracts/helper/swap_helper/MoeSwapHelper.sol | 33 | Swap helper for Merchant Moe DEX |
contracts/hook/BaseMappingIdHook.sol | 21 | Base implementation for hook |
Part 2 scope: mitigation reviews + minor changes to the previous code4rena contest
Contract | SLOC | Purpose |
---|---|---|
contracts/common/library/UncheckedIncrement.sol | 8 | Unchecked Increment for uint iterators |
contracts/common/AccessControlManager.sol | 9 | Manage access controls |
contracts/common/UnderACM.sol | 8 | Extensible contract for access control manager |
contracts/core/Config.sol | 106 | Config manager |
contracts/core/InitCore.sol | 423 | Main contract for most interactions to INIT |
contracts/core/LiqIncentiveCalculator.sol | 80 | Liquidation incentive calculation |
contracts/core/PosManager.sol | 263 | Position manager |
contracts/hook/MoneyMarketHook.sol | 180 | Hook for regular money market actions, for example, deposit, withdraw, borrow, repay |
contracts/lending_pool/DoubleSlopeIRM.sol | 29 | Interest rate model utilizing a 2-slope mechanism |
contracts/lending_pool/LendingPool.sol | 183 | ERC20 lending pool |
contracts/oracle/Api3OracleReader.sol | 55 | API3 oracle integration |
contracts/oracle/InitOracle.sol | 77 | Oracle source manager contract |
contracts/risk_manager/RiskManager.sol | 61 | Risk manager contract |
contracts/helper/rebase_helper/mUSDUSDYHelper.sol | 23 | Wrapper contract helper for wrapping/unwrapping mUSD to/from USDY |
contracts/helper/rebase_helper/BaseRebaseHelper.sol | 11 | Base wrapper contract helper for wrapping/unwrapping rebase tokens |
contracts/common/TransparentUpgradeableProxyReceiveETH.sol | 9 | Transparent upgradeable proxy that allows receiving ETH at the proxy level to avoid out-of-gas errors |
contracts/common/Multicall.sol | 20 | Extensible multicall base logic |
contracts/interfaces/*
contracts/mock/*
contracts/oracle/PythOracleReader.sol
tests/
contracts/helper/InitLens.sol
contracts/helper/MarginTradingLens.sol
ERC721
.multicall
- If you have a public code repo, please share it here: - - How many contracts are in scope?: 5 new + mitigations & minor changes to previous contracts - Total SLoC for these contracts?: 729 new + <100 line diff from part2 - How many external imports are there?: Many (most are OpenZeppelin's library) - How many separate interfaces and struct definitions are there for the contracts within scope?: 30 interfaces, 23 structs - Does most of your code generally use composition or inheritance?: Composition - How many external calls?: major one is via InitCore's callback - What is the overall line coverage percentage provided by your tests?: 90%+ - Is this an upgrade of an existing system?: It is a modification of the previous contracts - Check all that apply (e.g. timelock, NFT, AMM, ERC20, rollups, etc.): ERC-20 Token, Multi-Chain - Is there a need to understand a separate part of the codebase / get context in order to audit this part of the protocol?: True (merchant moe) - Please describe required context: see documentation above. - Does it use an oracle?: Yes, currently using API3. - Describe any novel or unique curve logic or mathematical models your code uses: - - Is this either a fork of or an alternate implementation of another project?: False - Does it use a side-chain?: No - Describe any specific areas you would like addressed: -
ape plugins install . ape compile forge install foundry-rs/forge-std --no-commit
(To compile the code, you can use either ape compile
or forge build
after installing the libraries)
Spin up an anvil fork node
anvil -f https://rpc.mantle.xyz --chain-id 5000
Run tests
forge test
For coverage testing, run the following intead of step 3, and a new window will pop up on your browser.
NOTE: Make sure you have an up-to-date lcov
installed.
sh run_coverage.sh