Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
fix: remappings
Browse files Browse the repository at this point in the history
  • Loading branch information
rhlsthrm authored and antisaa committed Jul 18, 2024
1 parent 6b1a16c commit 963065d
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ contracts.iml
node_modules/
ionic-contracts.iml
cache_hardhat
transactions.json
89 changes: 88 additions & 1 deletion chains/mode/leveragePairs.ts
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;
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

102 changes: 64 additions & 38 deletions tasks/leverage/configurePair.ts
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();
}
});
);
14 changes: 0 additions & 14 deletions transactions.json

This file was deleted.

0 comments on commit 963065d

Please sign in to comment.