This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -14,3 +14,4 @@ contracts.iml | |
node_modules/ | ||
ionic-contracts.iml | ||
cache_hardhat | ||
transactions.json |
This file contains 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 |
---|---|---|
@@ -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; |
This file contains 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 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 |
---|---|---|
@@ -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(); | ||
} | ||
}); | ||
); |
This file was deleted.
Oops, something went wrong.