-
Notifications
You must be signed in to change notification settings - Fork 7
feature: Frax USD Module Support #82
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/frax-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
dd74333
created frax module
shinchann221 d59050d
added validation for usdc withdrawal amount
shinchann221 01b7350
added test cases
shinchann221 1c4a7f4
removed test.txt
shinchann221 82a0085
added deploy script for dev
shinchann221 0e4a986
added usdt price oracle for frax
shinchann221 ba64f82
frax module deployed
shivam-ef 477dad6
fix: test for frax
shivam-ef 61f7010
updated fraxmodule for async withdrawal
shinchann221 e88332c
updated async withdrawals
shinchann221 aa74276
resolved decimal
shinchann221 bfe994c
Merge branch 'master' into feature/frax-support
shinchann221 e0a75b4
resolved review comments
shinchann221 e5afcf7
fix: bytes32 coversion
shinchann221 84b33d3
fix: audit issues & updated test cases
shinchann221 da81d2c
feat: added gnosis scripts
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
| 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,93 @@ | ||
| // 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 { FraxModule } from "../src/modules/frax/FraxModule.sol"; | ||
| import { IAggregatorV3, PriceProvider } from "../src/oracle/PriceProvider.sol"; | ||
| import { Utils } from "./utils/Utils.sol"; | ||
|
|
||
| contract DeployFraxModule is Utils { | ||
| address fraxusd = 0x397F939C3b91A74C321ea7129396492bA9Cdce82; | ||
| address custodian = 0x05bF905356fbeA7E59500f904b908402dB7A53DD; | ||
| address fraxUsdPriceOracle = 0x7be4f8b373853b74CDf48FE817bC2eB2272eBe45; | ||
| address remoteHop = 0xF6f45CCB5E85D1400067ee66F9e168f83e86124E; | ||
|
|
||
| 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"))); | ||
|
|
||
| //deploy frax module | ||
| FraxModule fraxModule = new FraxModule(dataProvider, fraxusd, custodian, remoteHop); | ||
|
|
||
| address[] memory modules = new address[](1); | ||
| modules[0] = address(fraxModule); | ||
|
|
||
| bool[] memory shouldWhitelist = new bool[](1); | ||
| shouldWhitelist[0] = true; | ||
|
|
||
| //configure default module in data provider | ||
| EtherFiDataProvider(dataProvider).configureDefaultModules(modules, shouldWhitelist); | ||
|
|
||
| address[] memory tokens = new address[](1); | ||
| tokens[0] = fraxusd; | ||
|
|
||
| PriceProvider.Config memory fraxUsdConfig = PriceProvider.Config({ | ||
| oracle: fraxUsdPriceOracle, | ||
| priceFunctionCalldata: "", | ||
| isChainlinkType: true, | ||
| oraclePriceDecimals: IAggregatorV3(fraxUsdPriceOracle).decimals(), | ||
| maxStaleness: 2 days, | ||
| dataType: PriceProvider.ReturnType.Int256, | ||
| isBaseTokenEth: false, | ||
| isStableToken: true, //Stable coin | ||
| isBaseTokenBtc: false | ||
| }); | ||
| PriceProvider.Config[] memory fraxUsdConfigs = new PriceProvider.Config[](1); | ||
| fraxUsdConfigs[0] = fraxUsdConfig; | ||
|
|
||
| //price provider set oracle | ||
| PriceProvider(priceProvider).setTokenConfig(tokens, fraxUsdConfigs); | ||
|
|
||
| IDebtManager.CollateralTokenConfig memory collateralConfig = IDebtManager.CollateralTokenConfig({ | ||
| ltv: 90e18, //confirmed | ||
| liquidationThreshold: 95e18, | ||
| liquidationBonus: 1e18 | ||
| }); | ||
|
|
||
| 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(fraxusd), collateralConfig); | ||
| debtManager.supportBorrowToken(address(fraxusd), borrowApy, minShares); | ||
|
|
||
| address[] memory withdrawableAssets = new address[](1); | ||
| withdrawableAssets[0] = address(fraxusd); | ||
|
|
||
| ICashModule(cashModule).configureModulesCanRequestWithdraw(modules, shouldWhitelist); | ||
|
|
||
| //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,32 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { stdJson } from "forge-std/StdJson.sol"; | ||
| import { console } from "forge-std/console.sol"; | ||
|
|
||
| import { FraxModule } from "../../src/modules/frax/FraxModule.sol"; | ||
| import { Utils } from "../utils/Utils.sol"; | ||
|
|
||
| contract DeployFraxModule is Utils { | ||
| address fraxusd = 0x397F939C3b91A74C321ea7129396492bA9Cdce82; | ||
| address usdc = 0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4; | ||
| address custodian = 0x05bF905356fbeA7E59500f904b908402dB7A53DD; | ||
| address remoteHop = 0xF6f45CCB5E85D1400067ee66F9e168f83e86124E; | ||
|
|
||
| function run() public { | ||
| string memory deployments = readDeploymentFile(); | ||
|
|
||
| address dataProvider = stdJson.readAddress(deployments, string(abi.encodePacked(".", "addresses", ".", "EtherFiDataProvider"))); | ||
|
|
||
| uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); | ||
|
|
||
| vm.startBroadcast(deployerPrivateKey); | ||
|
|
||
| // Deploy frax module | ||
| FraxModule fraxModule = new FraxModule(dataProvider, fraxusd, custodian, remoteHop); | ||
|
|
||
| console.log("FraxModule deployed at:", address(fraxModule)); | ||
|
|
||
| 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,101 @@ | ||
| // 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 { IAggregatorV3, PriceProvider } from "../../src/oracle/PriceProvider.sol"; | ||
| import { GnosisHelpers } from "../utils/GnosisHelpers.sol"; | ||
| import { Utils } from "../utils/Utils.sol"; | ||
|
|
||
| contract SetFraxModuleConfig is GnosisHelpers, Utils { | ||
| address cashControllerSafe = 0xA6cf33124cb342D1c604cAC87986B965F428AAC4; | ||
|
|
||
| address fraxusd = 0x397F939C3b91A74C321ea7129396492bA9Cdce82; | ||
| address fraxUsdPriceOracle = 0x7be4f8b373853b74CDf48FE817bC2eB2272eBe45; | ||
|
|
||
| function run() public { | ||
| string memory deployments = readDeploymentFile(); | ||
| string memory chainId = vm.toString(block.chainid); | ||
|
|
||
| address fraxModule = stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "FraxModule")); | ||
|
|
||
| address dataProvider = stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "EtherFiDataProvider")); | ||
|
|
||
| address priceProvider = stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "PriceProvider")); | ||
|
|
||
| address debtManager = stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "DebtManager")); | ||
|
|
||
| address cashModule = stdJson.readAddress(deployments, string.concat(".", "addresses", ".", "CashModule")); | ||
|
|
||
| string memory txs = _getGnosisHeader(chainId, addressToHex(cashControllerSafe)); | ||
|
|
||
| // Configure data provider - default modules | ||
| address[] memory modules = new address[](1); | ||
| modules[0] = fraxModule; | ||
|
|
||
| bool[] memory shouldWhitelist = new bool[](1); | ||
| shouldWhitelist[0] = true; | ||
|
|
||
| string memory configureDefaultModules = iToHex(abi.encodeWithSelector(EtherFiDataProvider.configureDefaultModules.selector, modules, shouldWhitelist)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(dataProvider), configureDefaultModules, "0", false))); | ||
|
|
||
| // Configure price provider | ||
| address[] memory tokens = new address[](1); | ||
| tokens[0] = fraxusd; | ||
|
|
||
| PriceProvider.Config memory fraxUsdConfig = PriceProvider.Config({ | ||
| oracle: fraxUsdPriceOracle, | ||
| priceFunctionCalldata: "", | ||
| isChainlinkType: true, | ||
| oraclePriceDecimals: IAggregatorV3(fraxUsdPriceOracle).decimals(), | ||
| maxStaleness: 5 days, //confirmed with V & showtime | ||
| dataType: PriceProvider.ReturnType.Int256, | ||
| isBaseTokenEth: false, | ||
| isStableToken: true, // Stable coin | ||
| isBaseTokenBtc: false | ||
| }); | ||
| PriceProvider.Config[] memory fraxUsdConfigs = new PriceProvider.Config[](1); | ||
| fraxUsdConfigs[0] = fraxUsdConfig; | ||
|
|
||
| string memory setTokenConfig = iToHex(abi.encodeWithSelector(PriceProvider.setTokenConfig.selector, tokens, fraxUsdConfigs)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(priceProvider), setTokenConfig, "0", false))); | ||
|
|
||
| // Configure debt manager - collateral token | ||
| IDebtManager.CollateralTokenConfig memory collateralConfig = IDebtManager.CollateralTokenConfig({ | ||
| ltv: 90e18, // confirmed | ||
| liquidationThreshold: 95e18, | ||
| liquidationBonus: 1e18 | ||
| }); | ||
|
|
||
| string memory supportCollateralToken = iToHex(abi.encodeWithSelector(IDebtManager.supportCollateralToken.selector, address(fraxusd), collateralConfig)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(debtManager), supportCollateralToken, "0", false))); | ||
|
|
||
| // Configure debt manager - borrow token | ||
| uint64 borrowApy = 1; // ~0% | ||
| uint128 minShares = type(uint128).max; // Since we dont want to use it in borrow mode | ||
|
|
||
| string memory supportBorrowToken = iToHex(abi.encodeWithSelector(IDebtManager.supportBorrowToken.selector, address(fraxusd), borrowApy, minShares)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(debtManager), supportBorrowToken, "0", false))); | ||
|
|
||
| // Configure cash module - modules can request withdraw | ||
|
|
||
| string memory configureModulesCanRequestWithdraw = iToHex(abi.encodeWithSelector(ICashModule.configureModulesCanRequestWithdraw.selector, modules, shouldWhitelist)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(cashModule), configureModulesCanRequestWithdraw, "0", false))); | ||
|
|
||
| // Configure cash module - withdrawable assets | ||
| address[] memory withdrawableAssets = new address[](1); | ||
| withdrawableAssets[0] = address(fraxusd); | ||
|
|
||
| string memory configureWithdrawAssets = iToHex(abi.encodeWithSelector(ICashModule.configureWithdrawAssets.selector, withdrawableAssets, shouldWhitelist)); | ||
| txs = string(abi.encodePacked(txs, _getGnosisTransaction(addressToHex(cashModule), configureWithdrawAssets, "0", true))); | ||
|
|
||
| vm.createDir("./output", true); | ||
| string memory path = "./output/SetFraxModuleConfig.json"; | ||
| vm.writeFile(path, txs); | ||
|
|
||
| executeGnosisTransactionBundle(path); | ||
| } | ||
| } |
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,9 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
|
||
| interface IFraxCustodian { | ||
| function deposit(uint256 amountIn, address reciever) external payable returns (uint256 shares); | ||
| function redeem(uint256 sharesIn, address reciever, address owner) external returns (uint256 amountOut); | ||
| } |
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,12 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.28; | ||
|
|
||
| struct MessagingFee { | ||
| uint256 nativeFee; | ||
| uint256 lzTokenFee; | ||
| } | ||
|
|
||
| interface IFraxRemoteHop { | ||
| function sendOFT(address _oft, uint32 _dstEid, bytes32 _to, uint256 _amountLD) external payable; | ||
| function quote(address _oft, uint32 _dstEid, bytes32 _to, uint256 _amountLD) external view returns (MessagingFee memory fee); | ||
| } |
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.