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

Commit 8aac12a

Browse files
made upgrade task attempt direct upgrade if deployer is pool admin
1 parent ee3feb3 commit 8aac12a

File tree

5 files changed

+65
-38
lines changed

5 files changed

+65
-38
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ ionic-contracts.iml
1616
cache_hardhat
1717
transactions.json
1818
*transactions.json
19+
deployments/local

hardhat.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const config: HardhatUserConfig = {
2929
}
3030
]
3131
},
32+
external: {
33+
contracts: [{ artifacts: "./out" }]
34+
},
3235
paths: {
3336
sources: "./contracts",
3437
tests: "./contracts/test",

lib/flywheel-v2

Submodule flywheel-v2 added at 5ac5d31

tasks/market/upgrade.ts

+59-37
Original file line numberDiff line numberDiff line change
@@ -64,49 +64,87 @@ task("market:upgrade:safe", "Upgrades a market's implementation")
6464
let { pluginAddress } = taskArgs;
6565

6666
const cTokenDelegator = await viem.getContractAt("CErc20Delegator", marketAddress);
67-
6867
const cfe = await viem.getContractAt(
6968
"CTokenFirstExtension",
7069
(await deployments.get("CTokenFirstExtension")).address as Address
7170
);
71+
const ap = await viem.getContractAt(
72+
"AddressesProvider",
73+
(await deployments.get("AddressesProvider")).address as Address
74+
);
75+
7276
const impl = await cTokenDelegator.read.implementation();
7377
const extensions = await cTokenDelegator.read._listExtensions();
74-
78+
const comptroller = await cTokenDelegator.read.comptroller();
79+
const comptrollerAsExt = await viem.getContractAt("IonicComptroller", comptroller as Address);
80+
const ctokenAsExt = await viem.getContractAt("CTokenFirstExtension", marketAddress)
81+
7582
if (
7683
impl.toLowerCase() != implementationAddress.toLowerCase() ||
7784
extensions.length == 0 ||
78-
extensions[0].toLowerCase() != cfe.address.toLowerCase()
85+
extensions[1].toLowerCase() != cfe.address.toLowerCase()
7986
) {
8087
if (!pluginAddress) {
8188
pluginAddress = zeroAddress;
8289
}
83-
84-
console.log(extensions.length)
85-
console.log(extensions[0].toLowerCase())
86-
console.log(cfe.address.toLowerCase())
87-
8890
const implementationData = encodeAbiParameters(parseAbiParameters("address"), [pluginAddress]);
89-
9091
console.log(`Setting implementation to ${implementationAddress} with plugin ${pluginAddress}`);
9192

92-
await prepareAndLogTransaction({
93-
contractInstance: cTokenDelegator,
94-
functionName: "_setImplementationSafe",
95-
args: [implementationAddress, implementationData],
96-
description: `Setting new implementation on ${cTokenDelegator.address}`,
97-
inputs: [
98-
{ internalType: "address", name: "implementation_", type: "address" },
99-
{ internalType: "bytes", name: "implementationData", type: "bytes" }
100-
]
101-
});
93+
const comptrollerAdmin = await comptrollerAsExt.read.admin()
94+
if(comptrollerAdmin.toLowerCase() !== deployer.toLowerCase()) {
95+
await prepareAndLogTransaction({
96+
contractInstance: cTokenDelegator,
97+
functionName: "_setImplementationSafe",
98+
args: [implementationAddress, implementationData],
99+
description: `Setting new implementation on ${cTokenDelegator.address}`,
100+
inputs: [
101+
{ internalType: "address", name: "implementation_", type: "address" },
102+
{ internalType: "bytes", name: "implementationData", type: "bytes" }
103+
]
104+
});
105+
await prepareAndLogTransaction({
106+
contractInstance: ctokenAsExt,
107+
functionName: "_setAddressesProvider",
108+
args: [ap.address],
109+
description: `Setting AddressesProvider on ${marketAddress}`,
110+
inputs: [
111+
{ internalType: "address", name: "_ap", type: "address" }
112+
]
113+
});
114+
} else {
115+
console.log(`Setting implementation to ${implementationAddress}`);
116+
const setImplementationTx = await cTokenDelegator.write._setImplementationSafe([
117+
implementationAddress,
118+
implementationData
119+
]);
120+
const receipt = await publicClient.waitForTransactionReceipt({
121+
hash: setImplementationTx
122+
});
123+
if (receipt.status !== "success") {
124+
throw `Failed set implementation to ${implementationAddress}`;
125+
}
126+
console.log(
127+
`Implementation successfully set to ${implementationAddress}: ${setImplementationTx}`
128+
);
129+
130+
console.log(`Setting AP to to ${ap.address}`);
131+
const setAPTX = await ctokenAsExt.write._setAddressesProvider([ap.address]);
132+
const receiptAP = await publicClient.waitForTransactionReceipt({
133+
hash: setAPTX
134+
});
135+
if (receiptAP.status !== "success") {
136+
throw `Failed set AP to ${ap.address}`;
137+
}
138+
console.log(`AP successfully set to ${ap.address}`);
139+
}
102140

103141
if (pluginAddress != zeroAddress) {
104142
const cTokenPluginInstance = await viem.getContractAt("ICErc20Plugin", marketAddress);
105143
console.log(`with plugin ${await cTokenPluginInstance.read.plugin()}`);
106144
}
107145
} else {
108146
console.log(
109-
`market ${marketAddress} impl ${impl} already eq ${implementationAddress} and extension ${cfe.address} eq ${extensions[0]}`
147+
`market ${marketAddress} impl ${impl} already eq ${implementationAddress} and extension ${cfe.address} eq ${extensions[1]}`
110148
);
111149
}
112150
});
@@ -126,7 +164,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
126164
"FeeDistributor",
127165
(await deployments.get("FeeDistributor")).address as Address
128166
);
129-
130167
const ionicUniV3Liquidator = await viem.getContractAt(
131168
"IonicUniV3Liquidator",
132169
(await deployments.get("IonicUniV3Liquidator")).address as Address
@@ -163,24 +200,9 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
163200
marketAddress: market,
164201
implementationAddress: latestImpl,
165202
});
166-
const ap = await viem.getContractAt(
167-
"AddressesProvider",
168-
(await deployments.get("AddressesProvider")).address as Address
169-
);
170-
const ctokenAsExt = await viem.getContractAt("CTokenFirstExtension", market)
171-
172-
await prepareAndLogTransaction({
173-
contractInstance: ctokenAsExt,
174-
functionName: "_setAddressesProvider",
175-
args: [ap.address],
176-
description: `Setting AddressesProvider on ${market}`,
177-
inputs: [
178-
{ internalType: "address", name: "_ap", type: "address" }
179-
]
180-
});
181203
}
182204
} catch (e) {
183-
console.error(`error while upgrading the pool ${JSON.stringify(pool)}`, e);
205+
console.error(`error while upgrading the pool`, e);
184206
}
185207
}
186208
});

tasks/pool/admin/create.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
encodePacked
1111
} from "viem";
1212

13-
import UnitrollerArtifact from "../../../artifacts/contracts/compound/Unitroller.sol/Unitroller.json";
13+
import UnitrollerArtifact from "../../../artifacts/Unitroller.sol/Unitroller.json";
1414
import { Address } from "viem";
1515

1616
task("pool:create:mode").setAction(async ({}, { run }) => {

0 commit comments

Comments
 (0)