- /src/strategies/IMX.sol
- /src/mixins/IIMXFarm.sol
- /src/implementations/USDCimxWEVE.sol
- /src/adapters/IMXFarm.sol
- /test/imx-integration.sol
install deps
yarn
init submodules
git submodule update --init --recursive
install foundry
foundry tests:
yarn test
hardhat integrations tests:
yarn test:hardhat
hardhat integration coverage:
yarn cover // alias for npx hardhat coverage
limited forge test coverage (cannot do abstract contracts yet, so strategy doesn't have stats):
yarn coverage <Contract.sol>
fork and deploy fesh contracts to local network:
yarn fork <network_name>
fork and use already deployed contracts:
yarn fork <network_name> --no-reset
This is a wrapper that provides an interface for the vault to interact with and tracks shares and totalSupply. Only vault is allowed to deposit or withdraw from the strategy so we don't have a need for an ERC20 to track shares.
(inherits from is BaseStrategy)
This is our first strategy, it takes deposits in underlying, sends a portion to a lending protocol as collateral, borrows short and provides underlying/short as liquidity to a Uniswap dex. On each deposit or withdrawal we increase or decrease our position.
When the price of the short asset moves wrt the underlying our shortLP position will begin to diverge from our borrowedPosition. A rebalance is required to restore the the balance. This usually involves in either trading some of the underlying for short and repaying a portion of the loan, or borrowing more in order to buy more underlying. This function is performed by the manager role.
The strategy manager is also responsible for harvesting the LP farm. This is done by calling the harvest method and providing appropriate slippage parameters.
A public rebalanceLoan method is available for anyone to call if the loan position gets close to liquidation. This will enable an external keeper network like Gelato to ensure the safty of the position.
HedgedLP uses abstract mixins to interact with lending and dex protocols. These mixina are agnostic to the concrete implementation of the protocol.
Adapters are contrete implementations of the lending and dex mixins for specific protocols.
underlying/short swaps that happen as part of deposit, withdraw, rebalance and closePosition are protected against flash-swap attacks by the checkPrice modifier. This modifier queries the prices via the oracle used by the lending protocol (usually chainlink) and checks them against the current dex spot price.
VaultUpgradable.sol implements LockedProfit (like in yearn vaults) and additionally LockedLoss. This prevents a flashwap or sandwich attack where an attacker may potentially manipulate the value of one of the strategies to either inflate or deflate the price of shares.
lossSinceHarvest is implemented to compute losses incurred in strategies since last harvest. This is to prevent withdrawal frontrunning where user who withdraw before the next harvest do not incur any losses. This mechanism is missing from the original Rari code and the exploit is outline in the following audits:
- https://github.com/Rari-Capital/vaults/blob/main/audits/yAcademy/Dhurv.Kat.Amanusk.pdf
- https://github.com/Rari-Capital/vaults/blob/main/audits/yAcademy/Nibbler.Bebis.Zokunei.Carl.pdf
Swaps necessary as part of harvest operations take a min output amount computed externally.
- Public - can call
rebalanceLoanwhen strategy is close to liquidation - Vault - can deposit (
mint) and withdraw (redeemUnderlying) from the strategy - Owner - can set critical parameters & set manager
- Manager -
closePosition,setMaxTvl,rebalance(not as critical) andharvest- critical because of the ability to set slippage params for swaps
- Public - can call
deposit,withdraw,pushToWithdrawalQueueValidatedandcleanWithdrawalQueue - Owner - can add new strategies, set critical parameters, & set manager
- Manager
harvestvault- manage assets via
depositIntoStrategyandwithdrawFromStrategy - set non-critcal configs like
maxTvl - manage
withdrawalQueue seizeStrategycan withdraw any tokens from the strategy and send them to theowner(Timelock contract)
