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

Commit 0d8d39a

Browse files
added task for setting extensions, upgrading and setting AP
1 parent e1066f5 commit 0d8d39a

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tasks/market/upgrade.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,58 @@ task("market:upgrade:safe", "Upgrades a market's implementation")
114114
);
115115
}
116116
});
117+
118+
task("markets:setAddressesProvider", "Upgrades all pools comptroller implementations whose autoimplementatoins are on")
119+
.addFlag("forceUpgrade", "If the pool upgrade should be forced")
120+
.setAction(async ({ forceUpgrade }, { viem, getChainId, deployments, run }) => {
121+
const publicClient = await viem.getPublicClient();
122+
123+
const poolDirectory = await viem.getContractAt(
124+
"PoolDirectory",
125+
(await deployments.get("PoolDirectory")).address as Address
126+
);
127+
const feeDistributor = await viem.getContractAt(
128+
"FeeDistributor",
129+
(await deployments.get("FeeDistributor")).address as Address
130+
);
131+
132+
await run("market:set-latest");
133+
134+
const [, pools] = await poolDirectory.read.getActivePools();
135+
for (let i = 0; i < pools.length; i++) {
136+
const pool = pools[i];
137+
console.log("pool", { name: pool.name, address: pool.comptroller });
138+
139+
try {
140+
const comptrollerAsExtension = await viem.getContractAt("IonicComptroller", pool.comptroller);
141+
const markets = await comptrollerAsExtension.read.getAllMarkets();
142+
for (let j = 0; j < markets.length; j++) {
143+
const market = markets[j];
144+
console.log(`market address ${market}`);
145+
const cTokenInstance = await viem.getContractAt("ICErc20", market);
146+
const [latestImpl] = await feeDistributor.read.latestCErc20Delegate([
147+
await cTokenInstance.read.delegateType()
148+
]);
149+
await run("market:upgrade:safe", {
150+
marketAddress: market,
151+
implementationAddress: latestImpl,
152+
});
153+
const ap = await viem.getContractAt(
154+
"AddressesProvider",
155+
(await deployments.get("AddressesProvider")).address as Address
156+
);
157+
const ctokenAsExt = await viem.getContractAt("CTokenFirstExtension", market)
158+
const setAPTX = await ctokenAsExt.write._setAddressesProvider(ap);
159+
const receipt = await publicClient.waitForTransactionReceipt({
160+
hash: setAPTX
161+
});
162+
if (receipt.status !== "success") {
163+
throw `Failed to set AddressesProvider`;
164+
}
165+
console.log(`AddressesProvider successfully set to ${ap}`);
166+
}
167+
} catch (e) {
168+
console.error(`error while upgrading the pool ${JSON.stringify(pool)}`, e);
169+
}
170+
}
171+
});

0 commit comments

Comments
 (0)