-
Notifications
You must be signed in to change notification settings - Fork 7
feature: Midas Liquid Reserve Vault Support #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
shinchann221
wants to merge
16
commits into
master
Choose a base branch
from
feature/midas-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a1e7f43
created Midas Vault contract
shinchann221 edeb630
Midas deploy script
shinchann221 0792f60
added test cases
shinchann221 e8c8f91
updated module to support multiple vaults
shinchann221 3e74b57
fix: added recipient for async withdraw
shinchann221 a7ce4d7
removed supportedAssets
shinchann221 9daccfb
feat: changed withdraw implementation and fixed audit issues
shinchann221 e58fb30
deploy: midas module on dev
shinchann221 76624f7
feat: create midas deploy & set config script
shinchann221 568984a
Merge branch 'master' into feature/midas-support
shinchann221 4bea39a
changed staleness threshold to 6 days
shinchann221 5add4bc
deploy: midas module prod
shinchann221 f3022fb
feat: generated midas config 3cp output
shinchann221 bcc68a4
feat: updated collateral config
shinchann221 0e43e58
verify bytecode
shinchann221 17031fe
fix: test cases
shinchann221 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "chainId": "534352", | ||
| "safeAddress": "0xa6cf33124cb342d1c604cac87986b965f428aac4", | ||
| "meta": { | ||
| "txBuilderVersion": "1.16.5" | ||
| }, | ||
| "transactions": [ | ||
| { | ||
| "to": "0xdc515cb479a64552c5a11a57109c314e40a1a778", | ||
| "value": "0", | ||
| "data": "0x54ddbe26000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000ee3fb6914105ba01196ab26191c3bb744801646700000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" | ||
| }, | ||
| { | ||
| "to": "0x44dd2372fe7b97c4b4d6a7d4decf72466485bacb", | ||
| "value": "0", | ||
| "data": "0x90883ac5000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b7fb3768caac98354eadf514b48f28f2fe822bf000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000b2a4ec4c9b95d7a87ba3989d0fd38dffdd944a24000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000007e90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | ||
| }, | ||
| { | ||
| "to": "0x0078c5a459132e279056b2371fe8a8ec973a9553", | ||
| "value": "0", | ||
| "data": "0xe5dbbeeb000000000000000000000000b7fb3768caac98354eadf514b48f28f2fe822bf0000000000000000000000000000000000000000000000004563918244f400000000000000000000000000000000000000000000000000004e1003b28d92800000000000000000000000000000000000000000000000000001bc16d674ec80000" | ||
| }, | ||
| { | ||
| "to": "0x0078c5a459132e279056b2371fe8a8ec973a9553", | ||
| "value": "0", | ||
| "data": "0x36394bd1000000000000000000000000b7fb3768caac98354eadf514b48f28f2fe822bf0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000ffffffffffffffffffffffffffffffff" | ||
| }, | ||
| { | ||
| "to": "0x7ca0b75e67e33c0014325b739a8d019c4fe445f0", | ||
| "value": "0", | ||
| "data": "0xd74286f5000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000b7fb3768caac98354eadf514b48f28f2fe822bf000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/ | ||
| @openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
| forge-std/=lib/forge-std/src/ | ||
| openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/ | ||
| openzeppelin-contracts/=lib/openzeppelin-contracts/ | ||
| solady/=lib/solady/src/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { stdJson } from "forge-std/StdJson.sol"; | ||
|
|
||
| import { EtherFiDataProvider } from "../src/data-provider/EtherFiDataProvider.sol"; | ||
| import { ICashModule } from "../src/interfaces/ICashModule.sol"; | ||
| import { IDebtManager } from "../src/interfaces/IDebtManager.sol"; | ||
| import { MidasModule } from "../src/modules/midas/MidasModule.sol"; | ||
| import { IAggregatorV3, PriceProvider } from "../src/oracle/PriceProvider.sol"; | ||
| import { ChainConfig, Utils } from "./utils/Utils.sol"; | ||
|
|
||
| contract DeployMidasModule is Utils { | ||
| address midasToken = 0xb7Fb3768CAAC98354EaDF514b48f28F2fE822bF0; | ||
| address usdc = 0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4; | ||
| address usdt = 0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df; | ||
|
|
||
| address depositVault = 0xcA1C871f8ae2571Cb126A46861fc06cB9E645152; | ||
| address redemptionVault = 0x904EA8d7FcaB7351758fAC82bDbc738E2010BC25; | ||
|
|
||
| address midasPriceOracle = 0xB2a4eC4C9b95D7a87bA3989d0FD38dFfDd944A24; | ||
|
|
||
| IDebtManager debtManager; | ||
| PriceProvider priceProvider; | ||
| ICashModule cashModule; | ||
| address dataProvider; | ||
|
|
||
| function run() public { | ||
| uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
|
||
| vm.startBroadcast(deployerPrivateKey); | ||
|
|
||
| string memory deployments = readDeploymentFile(); | ||
| dataProvider = stdJson.readAddress(deployments, string(abi.encodePacked(".", "addresses", ".", "EtherFiDataProvider"))); | ||
|
|
||
| priceProvider = PriceProvider(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "PriceProvider"))); | ||
|
|
||
| debtManager = IDebtManager(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "DebtManager"))); | ||
|
|
||
| cashModule = ICashModule(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "CashModule"))); | ||
|
|
||
| // Prepare arrays for Midas module deployment | ||
| address[] memory midasTokens = new address[](1); | ||
| midasTokens[0] = midasToken; | ||
|
|
||
| address[] memory depositVaults = new address[](1); | ||
| depositVaults[0] = depositVault; | ||
|
|
||
| address[] memory redemptionVaults = new address[](1); | ||
| redemptionVaults[0] = redemptionVault; | ||
|
|
||
| //deploy Midas module | ||
| MidasModule midasModule = new MidasModule( | ||
| dataProvider, | ||
| midasTokens, | ||
| depositVaults, | ||
| redemptionVaults | ||
| ); | ||
|
|
||
| address[] memory defaultModules = new address[](1); | ||
| defaultModules[0] = address(midasModule); | ||
|
|
||
| bool[] memory shouldWhitelist = new bool[](1); | ||
| shouldWhitelist[0] = true; | ||
|
|
||
| //configure default module in data provider | ||
| EtherFiDataProvider(dataProvider).configureDefaultModules(defaultModules, shouldWhitelist); | ||
|
|
||
| address[] memory tokens = new address[](1); | ||
| tokens[0] = midasToken; | ||
|
|
||
| PriceProvider.Config memory midasConfig = PriceProvider.Config({ | ||
| oracle: midasPriceOracle, | ||
| priceFunctionCalldata: "", | ||
| isChainlinkType: true, //chainlink type oracle | ||
| oraclePriceDecimals: IAggregatorV3(midasPriceOracle).decimals(), | ||
| maxStaleness: 30 days, | ||
| dataType: PriceProvider.ReturnType.Int256, | ||
| isBaseTokenEth: false, | ||
| isStableToken: true, | ||
| isBaseTokenBtc: false | ||
| }); | ||
| PriceProvider.Config[] memory midasConfigs = new PriceProvider.Config[](1); | ||
| midasConfigs[0] = midasConfig; | ||
|
|
||
| //price provider set oracle | ||
| PriceProvider(priceProvider).setTokenConfig(tokens, midasConfigs); | ||
|
|
||
| IDebtManager.CollateralTokenConfig memory collateralConfig = IDebtManager.CollateralTokenConfig({ | ||
| ltv: 90e18, | ||
| liquidationThreshold: 95e18, | ||
| liquidationBonus: 1e18 //confirmed with team | ||
| }); | ||
|
|
||
| uint64 borrowApy = 1; // ~0% | ||
| uint128 minShares = type(uint128).max; // Since we dont want to use it in borrow mode | ||
|
|
||
| //debt manager set collateral and borrow config | ||
| debtManager.supportCollateralToken(address(midasToken), collateralConfig); | ||
| debtManager.supportBorrowToken(address(midasToken), borrowApy, minShares); | ||
|
|
||
| address[] memory withdrawableAssets = new address[](1); | ||
| withdrawableAssets[0] = address(midasToken); | ||
|
|
||
| //cash module set withdrawable asset | ||
| ICashModule(cashModule).configureWithdrawAssets(withdrawableAssets, shouldWhitelist); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { stdJson } from "forge-std/StdJson.sol"; | ||
|
|
||
| import { MidasModule } from "../../src/modules/midas/MidasModule.sol"; | ||
| import { Utils } from "../utils/Utils.sol"; | ||
|
|
||
| contract DeployMidasModule is Utils { | ||
| address midasToken = 0xb7Fb3768CAAC98354EaDF514b48f28F2fE822bF0; | ||
| address depositVault = 0xcA1C871f8ae2571Cb126A46861fc06cB9E645152; | ||
| address redemptionVault = 0x904EA8d7FcaB7351758fAC82bDbc738E2010BC25; | ||
|
|
||
| function run() public { | ||
| string memory deployments = readDeploymentFile(); | ||
|
|
||
| address dataProvider = stdJson.readAddress(deployments, string(abi.encodePacked(".", "addresses", ".", "EtherFiDataProvider"))); | ||
|
|
||
| vm.startBroadcast(); | ||
|
|
||
| // Prepare arrays for Midas module deployment | ||
| address[] memory midasTokens = new address[](1); | ||
| midasTokens[0] = midasToken; | ||
|
|
||
| address[] memory depositVaults = new address[](1); | ||
| depositVaults[0] = depositVault; | ||
|
|
||
| address[] memory redemptionVaults = new address[](1); | ||
| redemptionVaults[0] = redemptionVault; | ||
|
|
||
| // Deploy Midas module | ||
| MidasModule midasModule = new MidasModule(dataProvider, midasTokens, depositVaults, redemptionVaults); | ||
|
|
||
| vm.stopBroadcast(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { stdJson } from "forge-std/StdJson.sol"; | ||
| import { Test } from "forge-std/Test.sol"; | ||
|
|
||
| import { EtherFiDataProvider } from "../../src/data-provider/EtherFiDataProvider.sol"; | ||
| import { ICashModule } from "../../src/interfaces/ICashModule.sol"; | ||
| import { IDebtManager } from "../../src/interfaces/IDebtManager.sol"; | ||
| import { IAggregatorV3, PriceProvider } from "../../src/oracle/PriceProvider.sol"; | ||
| import { GnosisHelpers } from "../utils/GnosisHelpers.sol"; | ||
| import { Utils } from "../utils/Utils.sol"; | ||
|
|
||
| contract SetMidasConfig is GnosisHelpers, Utils, Test { | ||
| address cashControllerSafe = 0xA6cf33124cb342D1c604cAC87986B965F428AAC4; | ||
|
|
||
| address midasToken = 0xb7Fb3768CAAC98354EaDF514b48f28F2fE822bF0; | ||
| address midasPriceOracle = 0xB2a4eC4C9b95D7a87bA3989d0FD38dFfDd944A24; | ||
|
|
||
| // Set this to the deployed MidasModule address after deployment | ||
| // If the address is in the deployments file under "MidasModule", it will be read automatically | ||
| address midasModule = 0xEE3Fb6914105BA01196ab26191C3BB7448016467; | ||
|
|
||
| IDebtManager debtManager; | ||
| PriceProvider priceProvider; | ||
| ICashModule cashModule; | ||
| address dataProvider; | ||
|
|
||
| function run() public { | ||
| string memory chainId = vm.toString(block.chainid); | ||
| string memory deployments = readDeploymentFile(); | ||
|
|
||
| dataProvider = stdJson.readAddress(deployments, string(abi.encodePacked(".", "addresses", ".", "EtherFiDataProvider"))); | ||
|
|
||
| priceProvider = PriceProvider(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "PriceProvider"))); | ||
|
|
||
| debtManager = IDebtManager(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "DebtManager"))); | ||
|
|
||
| cashModule = ICashModule(stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "CashModule"))); | ||
|
|
||
| // Generate Gnosis transactions | ||
| string memory txs = _getGnosisHeader(chainId, addressToHex(cashControllerSafe)); | ||
|
|
||
| // Configure default module in data provider | ||
| address[] memory defaultModules = new address[](1); | ||
| defaultModules[0] = midasModule; | ||
|
|
||
| bool[] memory shouldWhitelist = new bool[](1); | ||
| shouldWhitelist[0] = true; | ||
|
|
||
| string memory configureDefaultModules = iToHex(abi.encodeWithSelector(EtherFiDataProvider.configureDefaultModules.selector, defaultModules, shouldWhitelist)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(dataProvider), configureDefaultModules, "0", false))); | ||
|
|
||
| // Set price provider config | ||
| address[] memory tokens = new address[](1); | ||
| tokens[0] = midasToken; | ||
|
|
||
| PriceProvider.Config memory midasConfig = PriceProvider.Config({ | ||
| oracle: midasPriceOracle, | ||
| priceFunctionCalldata: "", | ||
| isChainlinkType: true, // chainlink type oracle | ||
| oraclePriceDecimals: IAggregatorV3(midasPriceOracle).decimals(), | ||
| maxStaleness: 6 days, | ||
| dataType: PriceProvider.ReturnType.Int256, | ||
| isBaseTokenEth: false, | ||
| isStableToken: false, | ||
| isBaseTokenBtc: false | ||
| }); | ||
| PriceProvider.Config[] memory midasConfigs = new PriceProvider.Config[](1); | ||
| midasConfigs[0] = midasConfig; | ||
|
|
||
| string memory setTokenConfig = iToHex(abi.encodeWithSelector(PriceProvider.setTokenConfig.selector, tokens, midasConfigs)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(address(priceProvider)), setTokenConfig, "0", false))); | ||
|
|
||
| // Set collateral and borrow config in debt manager | ||
| IDebtManager.CollateralTokenConfig memory collateralConfig = IDebtManager.CollateralTokenConfig({ | ||
| ltv: 80e18, | ||
| liquidationThreshold: 90e18, | ||
| liquidationBonus: 2e18 // same as liquid USD | ||
| }); | ||
|
|
||
| uint64 borrowApy = 1; // ~0% | ||
| uint128 minShares = type(uint128).max; // Since we dont want to use it in borrow mode | ||
|
|
||
| string memory supportCollateralToken = iToHex(abi.encodeWithSelector(IDebtManager.supportCollateralToken.selector, midasToken, collateralConfig)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(address(debtManager)), supportCollateralToken, "0", false))); | ||
|
|
||
| string memory supportBorrowToken = iToHex(abi.encodeWithSelector(IDebtManager.supportBorrowToken.selector, midasToken, borrowApy, minShares)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(address(debtManager)), supportBorrowToken, "0", false))); | ||
|
|
||
| // Configure withdrawable assets in cash module | ||
| address[] memory withdrawableAssets = new address[](1); | ||
| withdrawableAssets[0] = midasToken; | ||
|
|
||
| string memory configureWithdrawAssets = iToHex(abi.encodeWithSelector(ICashModule.configureWithdrawAssets.selector, withdrawableAssets, shouldWhitelist)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(address(cashModule)), configureWithdrawAssets, "0", true))); | ||
|
|
||
| vm.createDir("./output", true); | ||
| string memory path = "./output/SetMidasConfig.json"; | ||
| vm.writeFile(path, txs); | ||
|
|
||
| // Test execution | ||
| executeGnosisTransactionBundle(path); | ||
|
|
||
| assert(EtherFiDataProvider(dataProvider).isDefaultModule(midasModule) == true); | ||
| assert(IDebtManager(debtManager).isCollateralToken(midasToken) == true); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
|
||
| interface IMidasVault { | ||
| /** | ||
| * @notice depositing proccess with auto mint if | ||
| * account fit daily limit and token allowance. | ||
| * Transfers token from the user. | ||
| * Transfers fee in tokenIn to feeReceiver. | ||
| * Mints mToken to user. | ||
| * @param tokenIn address of tokenIn | ||
| * @param amountToken amount of `tokenIn` that will be taken from user (decimals 18) | ||
| * @param minReceiveAmount minimum expected amount of mToken to receive (decimals 18) | ||
| * @param referrerId referrer id | ||
| */ | ||
| function depositInstant(address tokenIn, uint256 amountToken, uint256 minReceiveAmount, bytes32 referrerId) external; | ||
|
|
||
| /** | ||
| * @notice redeem mToken to tokenOut if daily limit and allowance not exceeded | ||
| * Burns mToken from the user. | ||
| * Transfers fee in mToken to feeReceiver | ||
| * Transfers tokenOut to user. | ||
| * @param tokenOut stable coin token address to redeem to | ||
| * @param amountMTokenIn amount of mToken to redeem (decimals 18) | ||
| * @param minReceiveAmount minimum expected amount of tokenOut to receive (decimals 18) | ||
| */ | ||
| function redeemInstant(address tokenOut, uint256 amountMTokenIn, uint256 minReceiveAmount) external; | ||
|
|
||
| /** | ||
| * @notice creating redeem request if tokenOut not fiat | ||
| * Transfers amount in mToken to contract | ||
| * Transfers fee in mToken to feeReceiver | ||
| * @param tokenOut stable coin token address to redeem to | ||
| * @param amountMTokenIn amount of mToken to redeem (decimals 18) | ||
| * @param recipient address to receive the redeemed tokens | ||
| * @return request id | ||
| */ | ||
| function redeemRequest(address tokenOut, uint256 amountMTokenIn, address recipient) external returns (uint256); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.