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

Commit 4888e78

Browse files
committed
Merge branch 'feat/liquidate-borrow-permissioning' of github.com:ionicprotocol/contracts into feat/liquidate-borrow-permissioning
2 parents 1cd6f3f + 04f3144 commit 4888e78

File tree

8 files changed

+780
-61
lines changed

8 files changed

+780
-61
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ contracts.iml
1414
node_modules/
1515
ionic-contracts.iml
1616
cache_hardhat
17+
transactions.json

chainDeploy/helpers/logging.ts

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ interface PrepareAndLogTransactionParams {
66
functionName: string;
77
args: any[];
88
description: string;
9+
inputs: {
10+
internalType: string;
11+
name: string;
12+
type: string;
13+
}[];
914
}
1015

1116
export const logTransaction = (description: string, data: string) => {
@@ -23,60 +28,66 @@ export const addTransaction = async (tx: any) => {
2328
const writeSingleTransactionToFile = async (tx: any) => {
2429
const filePath = "./transactions.json";
2530
try {
26-
const fileContent = await fs.readFile(filePath, "utf8");
27-
const batch = JSON.parse(fileContent);
31+
let batch;
32+
try {
33+
const fileContent = await fs.readFile(filePath, "utf8");
34+
batch = JSON.parse(fileContent);
35+
} catch (error) {
36+
if (error.code === "ENOENT" || error.message === "Unexpected end of JSON input") {
37+
batch = {
38+
version: "1.0",
39+
chainId: "34443",
40+
createdAt: Math.floor(Date.now() / 1000),
41+
meta: {
42+
name: "Transactions Batch",
43+
description: "",
44+
txBuilderVersion: "1.16.5",
45+
createdFromSafeAddress: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
46+
createdFromOwnerAddress: "",
47+
checksum: "0x"
48+
},
49+
transactions: []
50+
};
51+
} else {
52+
throw error;
53+
}
54+
}
2855

2956
batch.transactions.push(tx);
3057

3158
await fs.writeFile(filePath, JSON.stringify(batch, null, 2));
3259
console.log(`Transaction added and written to ${filePath}`);
3360
} catch (error) {
34-
if (error.code === "ENOENT") {
35-
const batch = {
36-
version: "1.0",
37-
chainId: "34443",
38-
createdAt: Math.floor(Date.now() / 1000),
39-
meta: {
40-
name: "Transactions Batch",
41-
description: "",
42-
txBuilderVersion: "1.16.5",
43-
createdFromSafeAddress: "0x8Fba84867Ba458E7c6E2c024D2DE3d0b5C3ea1C2",
44-
createdFromOwnerAddress: "",
45-
checksum: "0x"
46-
},
47-
transactions: [tx]
48-
};
49-
50-
await fs.writeFile(filePath, JSON.stringify(batch, null, 2));
51-
console.log(`Transaction added and file created at ${filePath}`);
52-
} else {
53-
console.error(`Failed to write transaction to ${filePath}`, error);
54-
}
61+
console.error(`Failed to write transaction to ${filePath}`, error);
5562
}
5663
};
5764

5865
export const prepareAndLogTransaction = async ({
5966
contractInstance,
6067
functionName,
6168
args,
62-
description
69+
description,
70+
inputs
6371
}: PrepareAndLogTransactionParams) => {
6472
const data = encodeFunctionData({
6573
abi: contractInstance.abi,
6674
functionName,
6775
args
6876
});
6977

70-
addTransaction({
78+
await addTransaction({
7179
to: contractInstance.address,
7280
value: "0",
73-
data: encodeFunctionData({
74-
abi: contractInstance.abi,
75-
functionName,
76-
args
77-
}),
78-
contractMethod: null,
79-
contractInputsValues: null
81+
data,
82+
contractMethod: {
83+
inputs,
84+
name: functionName,
85+
payable: false
86+
},
87+
contractInputsValues: args.reduce((acc: any, arg: any, index: number) => {
88+
acc[inputs[index].name] = arg;
89+
return acc;
90+
}, {})
8091
});
8192

8293
logTransaction(description, data);

deploy/03-deploy-ctokens-set-extensions.ts

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
6969
contractInstance: fuseFeeDistributor,
7070
functionName: "_setCErc20DelegateExtensions",
7171
args: [erc20Del.address as Address, [erc20Del.address as Address, cTokenFirstExtension.address as Address]],
72-
description: "Set CErc20Delegate Extensions"
72+
description: "Set CErc20Delegate Extensions",
73+
inputs: [
74+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
75+
{ internalType: "address[]", name: "extensions", type: "address[]" }
76+
]
7377
});
7478
} else {
7579
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
@@ -84,12 +88,17 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
8488
}
8589
const [latestCErc20Delegate] = await fuseFeeDistributor.read.latestCErc20Delegate([1]);
8690
if (latestCErc20Delegate === zeroAddress || latestCErc20Delegate !== erc20Del.address) {
87-
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
91+
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
8892
await prepareAndLogTransaction({
8993
contractInstance: fuseFeeDistributor,
9094
functionName: "_setLatestCErc20Delegate",
9195
args: [1, erc20Del.address as Address, becomeImplementationData],
92-
description: "Set Latest CErc20Delegate"
96+
description: "Set Latest CErc20Delegate",
97+
inputs: [
98+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
99+
{ internalType: "address", name: "newImplementation", type: "address" },
100+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
101+
]
93102
});
94103
} else {
95104
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
@@ -111,15 +120,19 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
111120
erc20PluginDel.address as Address
112121
]);
113122
if (erc20PluginDelExtensions.length == 0 || erc20PluginDelExtensions[0] != erc20PluginDel.address) {
114-
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
123+
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
115124
await prepareAndLogTransaction({
116125
contractInstance: fuseFeeDistributor,
117126
functionName: "_setCErc20DelegateExtensions",
118127
args: [
119128
erc20PluginDel.address as Address,
120129
[erc20PluginDel.address as Address, cTokenFirstExtension.address as Address]
121130
],
122-
description: "Set CErc20PluginDelegate Extensions"
131+
description: "Set CErc20PluginDelegate Extensions",
132+
inputs: [
133+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
134+
{ internalType: "address[]", name: "extensions", type: "address[]" }
135+
]
123136
});
124137
} else {
125138
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
@@ -135,12 +148,17 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
135148

136149
const [latestCErc20PluginDelegate] = await fuseFeeDistributor.read.latestCErc20Delegate([2]);
137150
if (latestCErc20PluginDelegate === zeroAddress || latestCErc20PluginDelegate !== erc20PluginDel.address) {
138-
if (multisig && (await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
151+
if ((await fuseFeeDistributor.read.owner()).toLowerCase() !== deployer.toLowerCase()) {
139152
await prepareAndLogTransaction({
140153
contractInstance: fuseFeeDistributor,
141154
functionName: "_setLatestCErc20Delegate",
142155
args: [2, erc20PluginDel.address as Address, becomeImplementationData],
143-
description: "Set Latest CErc20PluginDelegate"
156+
description: "Set Latest CErc20PluginDelegate",
157+
inputs: [
158+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
159+
{ internalType: "address", name: "newImplementation", type: "address" },
160+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
161+
]
144162
});
145163
} else {
146164
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
@@ -172,7 +190,11 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
172190
erc20RewardsDel.address as Address,
173191
[erc20RewardsDel.address as Address, cTokenFirstExtension.address as Address]
174192
],
175-
description: "Set CErc20RewardsDelegate Extensions"
193+
description: "Set CErc20RewardsDelegate Extensions",
194+
inputs: [
195+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
196+
{ internalType: "address[]", name: "extensions", type: "address[]" }
197+
]
176198
});
177199
} else {
178200
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
@@ -192,7 +214,12 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
192214
contractInstance: fuseFeeDistributor,
193215
functionName: "_setLatestCErc20Delegate",
194216
args: [3, erc20RewardsDel.address as Address, becomeImplementationData],
195-
description: "Set Latest CErc20RewardsDelegate"
217+
description: "Set Latest CErc20RewardsDelegate",
218+
inputs: [
219+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
220+
{ internalType: "address", name: "newImplementation", type: "address" },
221+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
222+
]
196223
});
197224
} else {
198225
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([
@@ -227,7 +254,11 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
227254
erc20PluginRewardsDel.address as Address,
228255
[erc20PluginRewardsDel.address as Address, cTokenFirstExtension.address as Address]
229256
],
230-
description: "Set CErc20PluginRewardsDelegate Extensions"
257+
description: "Set CErc20PluginRewardsDelegate Extensions",
258+
inputs: [
259+
{ internalType: "address", name: "cErc20Delegate", type: "address" },
260+
{ internalType: "address[]", name: "extensions", type: "address[]" }
261+
]
231262
});
232263
} else {
233264
tx = await fuseFeeDistributor.write._setCErc20DelegateExtensions([
@@ -250,7 +281,12 @@ const func: DeployFunction = async ({ viem, getNamedAccounts, deployments }) =>
250281
contractInstance: fuseFeeDistributor,
251282
functionName: "_setLatestCErc20Delegate",
252283
args: [4, erc20PluginRewardsDel.address as Address, becomeImplementationData],
253-
description: "Set Latest CErc20PluginRewardsDelegate"
284+
description: "Set Latest CErc20PluginRewardsDelegate",
285+
inputs: [
286+
{ internalType: "uint8", name: "delegateType", type: "uint8" },
287+
{ internalType: "address", name: "newImplementation", type: "address" },
288+
{ internalType: "bytes", name: "becomeImplementationData", type: "bytes" }
289+
]
254290
});
255291
} else {
256292
tx = await fuseFeeDistributor.write._setLatestCErc20Delegate([

hardhat.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ const config: HardhatUserConfig = {
2929
}
3030
]
3131
},
32+
external: {
33+
contracts: [{ artifacts: "./out" }]
34+
},
35+
paths: {
36+
sources: "./contracts",
37+
tests: "./contracts/test",
38+
artifacts: "./out"
39+
},
3240
networks: {
3341
local: {
3442
accounts: [process.env.DEPLOYER!],

tasks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ import "./irm";
55
import "./leverage/configurePair";
66
import "./plugin";
77
import "./pool";
8+
import "./market";

tasks/market/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "./set-plugin";
22
import "./admin";
3-
import "./fund";
43
import "./risk";
54
import "./upgrade";
65
import "./upgrade-all";

tasks/market/upgrade.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,12 @@ task("market:upgrade:safe", "Upgrades a market's implementation")
9595
const implementationData = encodeAbiParameters(parseAbiParameters("address"), [pluginAddress]);
9696

9797
console.log(`Setting implementation to ${implementationAddress} with plugin ${pluginAddress}`);
98-
const setImplementationTx = await cTokenDelegator.write._setImplementationSafe([
99-
implementationAddress,
100-
implementationData
101-
]);
102-
103-
const receipt = await publicClient.waitForTransactionReceipt({
104-
hash: setImplementationTx
105-
});
106-
if (receipt.status !== "success") {
107-
throw `Failed set implementation to ${implementationAddress}`;
108-
}
109-
console.log(`Implementation successfully set to ${implementationAddress}`);
11098

11199
await prepareAndLogTransaction({
112100
contractInstance: cTokenDelegator,
113101
functionName: "_setImplementationSafe",
114102
args: [implementationAddress, implementationData],
115103
description: `Setting new implementation on ${cTokenDelegator.address}`,
116-
walletClient,
117104
inputs: [
118105
{ internalType: "address", name: "implementation_", type: "address" },
119106
{ internalType: "bytes", name: "implementationData", type: "bytes" }
@@ -151,6 +138,23 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
151138
"AddressesProvider",
152139
(await deployments.get("AddressesProvider")).address as Address
153140
);
141+
142+
const ionicUniV3Liquidator = await viem.getContractAt(
143+
"IonicUniV3Liquidator",
144+
(await deployments.get("IonicUniV3Liquidator")).address as Address
145+
);
146+
147+
await prepareAndLogTransaction({
148+
contractInstance: ionicUniV3Liquidator,
149+
functionName: "setHealthFactorThreshold",
150+
args: [
151+
BigInt("990000000000000000").toString() // 0.99e18 as a BigInt
152+
],
153+
description: `Setting Liquidator Health Factor Threshold`,
154+
inputs: [
155+
{ internalType: "uint256", name: "_healthFactorThreshold", type: "uint256" }
156+
]
157+
});
154158

155159
await prepareAndLogTransaction({
156160
contractInstance: addressProvider,
@@ -160,7 +164,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
160164
(await deployments.get("PoolLens")).address as Address
161165
],
162166
description: `Setting PoolLens id on AddressProvider`,
163-
walletClient,
164167
inputs: [
165168
{ internalType: "string", name: "id", type: "string" },
166169
{ internalType: "address", name: "newAddress", type: "address" }
@@ -197,7 +200,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
197200
functionName: "_setAddressesProvider",
198201
args: [ap.address],
199202
description: `Setting AddressesProvider on ${market}`,
200-
walletClient,
201203
inputs: [
202204
{ internalType: "address", name: "_ap", type: "address" }
203205
]

0 commit comments

Comments
 (0)