From 963065d8048b49bcb3591d805c00756b48b55bc3 Mon Sep 17 00:00:00 2001 From: Rahul Sethuram Date: Thu, 18 Jul 2024 13:40:43 +0400 Subject: [PATCH] fix: remappings --- .gitignore | 1 + chains/mode/leveragePairs.ts | 89 +++++++++++++++++++++++++++- remappings.txt | 1 + tasks/leverage/configurePair.ts | 102 ++++++++++++++++++++------------ transactions.json | 14 ----- 5 files changed, 154 insertions(+), 53 deletions(-) delete mode 100644 transactions.json diff --git a/.gitignore b/.gitignore index 5543ed90..edd8e777 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ contracts.iml node_modules/ ionic-contracts.iml cache_hardhat +transactions.json diff --git a/chains/mode/leveragePairs.ts b/chains/mode/leveragePairs.ts index e6fa9b44..1328cfd5 100644 --- a/chains/mode/leveragePairs.ts +++ b/chains/mode/leveragePairs.ts @@ -1,5 +1,92 @@ +import { Address } from "viem"; import { LeveragePoolConfig } from "../types"; -const leveragePairs: LeveragePoolConfig[] = []; +const leveragePairs: LeveragePoolConfig[] = [ + { + pool: "Main" as Address, + pairs: [ + // ezETH + { + collateral: "0x59e710215d45F584f44c0FEe83DA6d43D762D857", + borrow: "0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038" + }, // usdc + { + collateral: "0x59e710215d45F584f44c0FEe83DA6d43D762D857", + borrow: "0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3" + }, // usdt + { + collateral: "0x59e710215d45F584f44c0FEe83DA6d43D762D857", + borrow: "0xd70254C3baD29504789714A7c69d60Ec1127375C" + }, // wbtc + { + collateral: "0x59e710215d45F584f44c0FEe83DA6d43D762D857", + borrow: "0x19f245782b1258cf3e11eda25784a378cc18c108" + }, // mbtc + { + collateral: "0x59e710215d45F584f44c0FEe83DA6d43D762D857", + borrow: "0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2" + }, // weth + + // wrsETH + { + collateral: "0x49950319aBE7CE5c3A6C90698381b45989C99b46", + borrow: "0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038" + }, // usdc + { + collateral: "0x49950319aBE7CE5c3A6C90698381b45989C99b46", + borrow: "0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3" + }, // usdt + { + collateral: "0x49950319aBE7CE5c3A6C90698381b45989C99b46", + borrow: "0xd70254C3baD29504789714A7c69d60Ec1127375C" + }, // wbtc + { + collateral: "0x49950319aBE7CE5c3A6C90698381b45989C99b46", + borrow: "0x19f245782b1258cf3e11eda25784a378cc18c108" + }, // mbtc + { + collateral: "0x49950319aBE7CE5c3A6C90698381b45989C99b46", + borrow: "0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2" + }, // weth + + // weETH.mode + { + collateral: "0xA0D844742B4abbbc43d8931a6Edb00C56325aA18", + borrow: "0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038" + }, // usdc + { + collateral: "0xA0D844742B4abbbc43d8931a6Edb00C56325aA18", + borrow: "0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3" + }, // usdt + { + collateral: "0xA0D844742B4abbbc43d8931a6Edb00C56325aA18", + borrow: "0xd70254C3baD29504789714A7c69d60Ec1127375C" + }, // wbtc + { + collateral: "0xA0D844742B4abbbc43d8931a6Edb00C56325aA18", + borrow: "0x19f245782b1258cf3e11eda25784a378cc18c108" + }, // mbtc + { + collateral: "0xA0D844742B4abbbc43d8931a6Edb00C56325aA18", + borrow: "0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2" + }, // weth + + // mbtc + { + collateral: "0x19f245782b1258cf3e11eda25784a378cc18c108", + borrow: "0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038" + }, // usdc + { + collateral: "0x19f245782b1258cf3e11eda25784a378cc18c108", + borrow: "0x94812F2eEa03A49869f95e1b5868C6f3206ee3D3" + }, // usdt + { + collateral: "0x19f245782b1258cf3e11eda25784a378cc18c108", + borrow: "0xd70254C3baD29504789714A7c69d60Ec1127375C" + }, // wbtc + { collateral: "0x19f245782b1258cf3e11eda25784a378cc18c108", borrow: "0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2" } // mbtc + ] + } +]; export default leveragePairs; diff --git a/remappings.txt b/remappings.txt index 8d9204c8..7d02f86f 100644 --- a/remappings.txt +++ b/remappings.txt @@ -3,3 +3,4 @@ solidity-bytes-utils/=lib/solidity-bytes-utils/ @openzeppelin=lib/openzeppelin-contracts/ @pythnetwork/pyth-sdk-solidity/=lib/pyth-sdk-solidity/ @pythnetwork/express-relay-sdk-solidity/=node_modules/@pythnetwork/express-relay-sdk-solidity + diff --git a/tasks/leverage/configurePair.ts b/tasks/leverage/configurePair.ts index 3e5c3159..b47ac218 100644 --- a/tasks/leverage/configurePair.ts +++ b/tasks/leverage/configurePair.ts @@ -1,54 +1,80 @@ import { task } from "hardhat/config"; import { chainIdToConfig } from "../../chains"; -import { Address } from "viem"; +import { Address, encodeFunctionData } from "viem"; +import { addTransaction, writeTransactionsToFile } from "../../chainDeploy/helpers/logging"; -export default task("levered-positions:configure-pairs").setAction(async ({}, { viem, getChainId, deployments }) => { - const publicClient = await viem.getPublicClient(); - const chainId = parseInt(await getChainId()); - const leveredPairsConfig = chainIdToConfig[chainId].leveragePairs; +export default task("levered-positions:configure-pairs").setAction( + async ({}, { viem, getChainId, deployments, getNamedAccounts }) => { + const { deployer } = await getNamedAccounts(); + console.log("deployer: ", deployer); + const publicClient = await viem.getPublicClient(); + const walletClient = await viem.getWalletClient(deployer as Address); + const chainId = parseInt(await getChainId()); + const leveredPairsConfig = chainIdToConfig[chainId].leveragePairs; - const factory = await viem.getContractAt( - "ILeveredPositionFactory", - (await deployments.get("LeveredPositionFactory")).address as Address - ); - const configuredCollateralMarkets = await factory.read.getWhitelistedCollateralMarkets(); + const factory = await viem.getContractAt( + "ILeveredPositionFactory", + (await deployments.get("LeveredPositionFactory")).address as Address + ); + const configuredCollateralMarkets = await factory.read.getWhitelistedCollateralMarkets(); - console.log(`Collateral markets already configured: ${configuredCollateralMarkets.join(", ")}`); + console.log(`Collateral markets already configured: ${configuredCollateralMarkets.join(", ")}`); - for (const pool of leveredPairsConfig) { - console.log(`Configuring pairs for pool: ${pool.pool}`); + for (const pool of leveredPairsConfig) { + console.log(`Configuring pairs for pool: ${pool.pool}`); - for (const pair of pool.pairs) { - const { collateral, borrow } = pair; + for (const pair of pool.pairs) { + const { collateral, borrow } = pair; - const collateralMarket = await viem.getContractAt("CErc20Delegate", collateral); - const borrowMarket = await viem.getContractAt("CErc20Delegate", borrow); + const collateralMarket = await viem.getContractAt("CErc20Delegate", collateral); + const borrowMarket = await viem.getContractAt("CErc20Delegate", borrow); - const collateralToken = await collateralMarket.read.underlying(); - const borrowToken = await borrowMarket.read.underlying(); + const collateralToken = await collateralMarket.read.underlying(); + const borrowToken = await borrowMarket.read.underlying(); - const configuredBorrowableMarkets = await factory.read.getBorrowableMarketsByCollateral([collateral]); - console.log( - `Borrow markets already configured for collateral ${collateral}: ${configuredBorrowableMarkets.join(", ")}` - ); - - // check if borrow market is already configured - if (configuredBorrowableMarkets.includes(borrow) && configuredCollateralMarkets.includes(collateral)) { - console.log( - `Borrow (market: ${borrow}, underlying: ${borrowToken}) is already configured for collateral (market: ${collateral}, underlying: ${collateralToken})` - ); - continue; - } else { + const configuredBorrowableMarkets = await factory.read.getBorrowableMarketsByCollateral([collateral]); console.log( - `Configuring pair:\n - BORROW (market: ${borrow}, underlying: ${borrowToken})\n - COLLATERAL: (market: ${collateral}, underlying: ${collateralToken})` + `Borrow markets already configured for collateral ${collateral}: ${configuredBorrowableMarkets.join(", ")}` ); - const tx = await factory.write._setPairWhitelisted([collateral, borrow, true]); - await publicClient.waitForTransactionReceipt({ hash: tx }); - console.log( - `configured the markets pair:\n - BORROW (market: ${borrow}, underlying: ${borrowToken})\n - COLLATERAL: (market: ${collateral}, underlying: ${collateralToken}) as whitelisted for levered positions` - ); + // check if borrow market is already configured + if (configuredBorrowableMarkets.includes(borrow) && configuredCollateralMarkets.includes(collateral)) { + console.log( + `Borrow (market: ${borrow}, underlying: ${borrowToken}) is already configured for collateral (market: ${collateral}, underlying: ${collateralToken})` + ); + continue; + } else { + console.log( + `Configuring pair:\n - BORROW (market: ${borrow}, underlying: ${borrowToken})\n - COLLATERAL: (market: ${collateral}, underlying: ${collateralToken})` + ); + + const owner = await factory.read.owner(); + if (owner.toLowerCase() !== deployer.toLowerCase()) { + console.log( + `adding transaction to set pair as whitelisted: BORROW (market: ${borrow}, underlying: ${borrowToken}) - COLLATERAL: (market: ${collateral}, underlying: ${collateralToken})` + ); + addTransaction({ + to: factory.address, + value: "0", + data: encodeFunctionData({ + abi: factory.abi, + functionName: "_setPairWhitelisted", + args: [collateral, borrow, true] + }), + contractMethod: null, + contractInputsValues: null + }); + } else { + const tx = await factory.write._setPairWhitelisted([collateral, borrow, true]); + await publicClient.waitForTransactionReceipt({ hash: tx }); + console.log( + `configured the markets pair:\n - BORROW (market: ${borrow}, underlying: ${borrowToken})\n - COLLATERAL: (market: ${collateral}, underlying: ${collateralToken}) as whitelisted for levered positions` + ); + } + } } } + + await writeTransactionsToFile(); } -}); +); diff --git a/transactions.json b/transactions.json deleted file mode 100644 index da8a5c93..00000000 --- a/transactions.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": "1.0", - "chainId": "34443", - "createdAt": 1721101567, - "meta": { - "name": "Transactions Batch", - "description": "", - "txBuilderVersion": "1.16.5", - "createdFromSafeAddress": "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2", - "createdFromOwnerAddress": "", - "checksum": "0x" - }, - "transactions": [] -} \ No newline at end of file