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

Commit bcf9506

Browse files
committed
fix: scripts
1 parent d16701e commit bcf9506

File tree

4 files changed

+104
-64
lines changed

4 files changed

+104
-64
lines changed

tasks/chain-specific/mode/market.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { task } from "hardhat/config";
2-
import { Address, formatUnits } from "viem";
2+
import { Address, formatUnits, zeroAddress } from "viem";
33

44
import { assets as modeAssets } from "../../../../monorepo/packages/chains/src/mode/assets";
55
import { assetSymbols } from "../../../../monorepo/packages/types";
@@ -8,29 +8,34 @@ import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
88
const COMPTROLLER = "0xfb3323e24743caf4add0fdccfb268565c0685556";
99

1010
task("markets:deploy:mode:new", "deploy new mode assets").setAction(async (_, { viem, run }) => {
11-
const assetsToDeploy: string[] = [assetSymbols.USDe];
11+
const assetsToDeploy: string[] = ["sUSDe"];
1212
for (const asset of modeAssets.filter((asset) => assetsToDeploy.includes(asset.symbol))) {
13+
const name = `Ionic ${asset.name}`;
14+
const symbol = "ion" + asset.symbol;
15+
console.log(`Deploying ctoken ${name} with symbol ${symbol}`);
1316
await run("market:deploy", {
1417
signer: "deployer",
1518
cf: "0",
1619
underlying: asset.underlying,
1720
comptroller: COMPTROLLER,
18-
symbol: "ion" + asset.symbol,
19-
name: `Ionic ${asset.name}`
21+
symbol,
22+
name
2023
});
2124
const pool = await viem.getContractAt("IonicComptroller", COMPTROLLER);
2225
const cToken = await pool.read.cTokensByUnderlying([asset.underlying]);
2326
console.log(`Deployed ${asset.symbol} at ${cToken}`);
2427

25-
await run("market:set-supply-cap", {
26-
market: cToken,
27-
maxSupply: asset.initialSupplyCap
28-
});
28+
if (cToken !== zeroAddress) {
29+
await run("market:set-supply-cap", {
30+
market: cToken,
31+
maxSupply: asset.initialSupplyCap
32+
});
2933

30-
await run("market:set-borrow-cap", {
31-
market: cToken,
32-
maxBorrow: asset.initialBorrowCap
33-
});
34+
await run("market:set-borrow-cap", {
35+
market: cToken,
36+
maxBorrow: asset.initialBorrowCap
37+
});
38+
}
3439
}
3540
});
3641

tasks/market/admin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ task("market:set:ltv", "Set the LTV (loan to value / collateral factor) of a mar
2626
console.log(`will set the LTV of market ${marketAddress} to ${ltvMantissa}`);
2727

2828
if ((await pool.read.admin()).toLowerCase() !== deployer.toLowerCase()) {
29-
prepareAndLogTransaction({
29+
await prepareAndLogTransaction({
3030
contractInstance: pool,
3131
functionName: "_setCollateralFactor",
3232
args: [marketAddress, ltvMantissa],

tasks/market/risk/borrow-caps.ts

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { task, types } from "hardhat/config";
2+
import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
23

34
export default task("market:set-borrow-cap", "Set borrow cap on market")
45
.addParam("admin", "Named account from which to set the borrow caps", "deployer", types.string)
56
.addParam("market", "The address of the CToken", undefined, types.string)
67
.addParam("maxBorrow", "Maximum amount of tokens that can be borrowed", undefined, types.string)
7-
.setAction(async ({ market, maxBorrow }, { viem }) => {
8+
.setAction(async ({ market, maxBorrow }, { viem, getNamedAccounts }) => {
9+
const { deployer } = await getNamedAccounts();
810
const publicClient = await viem.getPublicClient();
911
const cToken = await viem.getContractAt("ICErc20", market);
1012
const comptroller = await cToken.read.comptroller();
@@ -20,59 +22,75 @@ export default task("market:set-borrow-cap", "Set borrow cap on market")
2022
return;
2123
}
2224

23-
const tx = await pool.write._setMarketBorrowCaps([[cToken.address], [newBorrowCap]]);
24-
await publicClient.waitForTransactionReceipt({ hash: tx });
25-
console.log("tx: ", tx);
26-
const newBorrowCapSet = await pool.read.borrowCaps([cToken.address]);
27-
console.log(`New borrow cap set: ${newBorrowCapSet.toString()}`);
25+
const feeDistributor = await viem.getContractAt("FeeDistributor", await pool.read.ionicAdmin());
26+
const owner = await feeDistributor.read.owner();
27+
28+
if (owner.toLowerCase() !== deployer.toLowerCase()) {
29+
await prepareAndLogTransaction({
30+
contractInstance: pool,
31+
functionName: "_setMarketBorrowCaps",
32+
args: [[cToken.address], [newBorrowCap]],
33+
description: `Set borrow cap of ${await cToken.read.underlying()} to ${newBorrowCap}`,
34+
inputs: [
35+
{ internalType: "address[]", name: "cTokens", type: "address[]" },
36+
{ internalType: "uint256[]", name: "newBorrowCaps", type: "uint256[]" }
37+
]
38+
});
39+
} else {
40+
const tx = await pool.write._setMarketBorrowCaps([[cToken.address], [newBorrowCap]]);
41+
await publicClient.waitForTransactionReceipt({ hash: tx });
42+
console.log("tx: ", tx);
43+
const newBorrowCapSet = await pool.read.borrowCaps([cToken.address]);
44+
console.log(`New borrow cap set: ${newBorrowCapSet.toString()}`);
45+
}
2846
});
2947

30-
task("market:set-borrow-cap-whitelist", "Pauses borrowing on a market")
31-
.addParam("admin", "Named account from which to set the borrow cap whitelist", "deployer", types.string)
32-
.addParam("market", "The address of the CToken", undefined, types.string)
33-
.addParam("account", "Account to be whitelisted / removed from whitelist", undefined, types.string)
34-
.addOptionalParam("whitelist", "Set whitelist to true ot false", true, types.boolean)
35-
.setAction(async ({ admin, market, account, whitelist }, { ethers }) => {
36-
const signer = await ethers.getNamedSigner(admin);
48+
// task("market:set-borrow-cap-whitelist", "Pauses borrowing on a market")
49+
// .addParam("admin", "Named account from which to set the borrow cap whitelist", "deployer", types.string)
50+
// .addParam("market", "The address of the CToken", undefined, types.string)
51+
// .addParam("account", "Account to be whitelisted / removed from whitelist", undefined, types.string)
52+
// .addOptionalParam("whitelist", "Set whitelist to true ot false", true, types.boolean)
53+
// .setAction(async ({ admin, market, account, whitelist }, { ethers }) => {
54+
// const signer = await ethers.getNamedSigner(admin);
3755

38-
const ionicSdkModule = await import("../../ionicSdk");
39-
const sdk = await ionicSdkModule.getOrCreateIonic(signer);
56+
// const ionicSdkModule = await import("../../ionicSdk");
57+
// const sdk = await ionicSdkModule.getOrCreateIonic(signer);
4058

41-
const cToken = sdk.createICErc20(market, signer);
42-
const comptroller = await cToken.callStatic.comptroller();
43-
const pool = sdk.createComptroller(comptroller, signer);
59+
// const cToken = sdk.createICErc20(market, signer);
60+
// const comptroller = await cToken.callStatic.comptroller();
61+
// const pool = sdk.createComptroller(comptroller, signer);
4462

45-
const currentBorrowCap = await pool.callStatic.supplyCaps(cToken.address);
46-
console.log(`Current borrow cap is ${currentBorrowCap}`);
63+
// const currentBorrowCap = await pool.callStatic.supplyCaps(cToken.address);
64+
// console.log(`Current borrow cap is ${currentBorrowCap}`);
4765

48-
const whitelistStatus = await pool.callStatic.supplyCapWhitelist(market, account);
49-
if (whitelistStatus == whitelist) {
50-
console.log(`Whitelist status is already ${whitelist}`);
51-
return;
52-
} else {
53-
console.log(`Whitelist status is ${whitelistStatus}, setting to ${whitelist}`);
54-
const tx: providers.TransactionResponse = await pool._supplyCapWhitelist(market, account, whitelist);
55-
await tx.wait();
56-
console.log(`Whitelist status for ${account} set: ${await pool.callStatic.supplyCapWhitelist(market, account)}`);
57-
}
58-
});
66+
// const whitelistStatus = await pool.callStatic.supplyCapWhitelist(market, account);
67+
// if (whitelistStatus == whitelist) {
68+
// console.log(`Whitelist status is already ${whitelist}`);
69+
// return;
70+
// } else {
71+
// console.log(`Whitelist status is ${whitelistStatus}, setting to ${whitelist}`);
72+
// const tx: providers.TransactionResponse = await pool._supplyCapWhitelist(market, account, whitelist);
73+
// await tx.wait();
74+
// console.log(`Whitelist status for ${account} set: ${await pool.callStatic.supplyCapWhitelist(market, account)}`);
75+
// }
76+
// });
5977

60-
task("market:set-borrow-cap-guardian", "Set borrow cap guardian on market")
61-
.addParam("poolAddress", "The address of the pool", undefined, types.string)
62-
.addParam("borrowGuardian", "The address of the borrow cap guardian", undefined, types.string)
63-
.setAction(async ({ poolAddress, borrowGuardian }, { ethers, getNamedAccounts }) => {
64-
const { deployer } = await getNamedAccounts();
65-
console.log("signer: ", deployer);
78+
// task("market:set-borrow-cap-guardian", "Set borrow cap guardian on market")
79+
// .addParam("poolAddress", "The address of the pool", undefined, types.string)
80+
// .addParam("borrowGuardian", "The address of the borrow cap guardian", undefined, types.string)
81+
// .setAction(async ({ poolAddress, borrowGuardian }, { ethers, getNamedAccounts }) => {
82+
// const { deployer } = await getNamedAccounts();
83+
// console.log("signer: ", deployer);
6684

67-
const signer = await ethers.getSigner(deployer);
85+
// const signer = await ethers.getSigner(deployer);
6886

69-
const ionicSdkModule = await import("../../ionicSdk");
70-
const sdk = await ionicSdkModule.getOrCreateIonic(signer);
87+
// const ionicSdkModule = await import("../../ionicSdk");
88+
// const sdk = await ionicSdkModule.getOrCreateIonic(signer);
7189

72-
const pool = sdk.createComptroller(poolAddress, signer);
90+
// const pool = sdk.createComptroller(poolAddress, signer);
7391

74-
const tx: providers.TransactionResponse = await pool._setBorrowCapGuardian(borrowGuardian);
75-
await tx.wait();
92+
// const tx: providers.TransactionResponse = await pool._setBorrowCapGuardian(borrowGuardian);
93+
// await tx.wait();
7694

77-
console.log(`Configured the borrow cap guardian to : ${borrowGuardian}`);
78-
});
95+
// console.log(`Configured the borrow cap guardian to : ${borrowGuardian}`);
96+
// });

tasks/market/risk/supply-caps.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { task, types } from "hardhat/config";
2+
import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging";
23

34
export default task("market:set-supply-cap", "Sets supply cap on a market")
45
.addParam("admin", "Deployer account", "deployer", types.string)
56
.addParam("market", "The address of the CToken", undefined, types.string)
67
.addParam("maxSupply", "Maximum amount of tokens that can be supplied", undefined, types.string)
7-
.setAction(async ({ market, maxSupply }, { viem }) => {
8+
.setAction(async ({ market, maxSupply }, { viem, getNamedAccounts }) => {
9+
const { deployer } = await getNamedAccounts();
810
const publicClient = await viem.getPublicClient();
911
const cToken = await viem.getContractAt("ICErc20", market);
1012
const comptroller = await cToken.read.comptroller();
@@ -19,11 +21,26 @@ export default task("market:set-supply-cap", "Sets supply cap on a market")
1921
return;
2022
}
2123

22-
const tx = await pool.write._setMarketSupplyCaps([[cToken.address], [newSupplyCap]]);
23-
await publicClient.waitForTransactionReceipt({ hash: tx });
24-
console.log("tx: ", tx);
25-
const newSupplyCapSet = await pool.read.supplyCaps([cToken.address]);
26-
console.log(`New supply cap set: ${newSupplyCapSet.toString()}`);
24+
const feeDistributor = await viem.getContractAt("FeeDistributor", await pool.read.ionicAdmin());
25+
const owner = await feeDistributor.read.owner();
26+
if (owner.toLowerCase() !== deployer.toLowerCase()) {
27+
await prepareAndLogTransaction({
28+
contractInstance: pool,
29+
functionName: "_setMarketSupplyCaps",
30+
args: [[cToken.address], [newSupplyCap]],
31+
description: `Set supply cap of ${await cToken.read.underlying()} to ${newSupplyCap}`,
32+
inputs: [
33+
{ internalType: "address[]", name: "cTokens", type: "address[]" },
34+
{ internalType: "uint256[]", name: "newSupplyCaps", type: "uint256[]" }
35+
]
36+
});
37+
} else {
38+
const tx = await pool.write._setMarketSupplyCaps([[cToken.address], [newSupplyCap]]);
39+
await publicClient.waitForTransactionReceipt({ hash: tx });
40+
console.log("tx: ", tx);
41+
const newSupplyCapSet = await pool.read.supplyCaps([cToken.address]);
42+
console.log(`New supply cap set: ${newSupplyCapSet.toString()}`);
43+
}
2744
});
2845

2946
task("market:set-supply-cap-whitelist", "Sets supply whitelist on a market")

0 commit comments

Comments
 (0)