Skip to content

Commit 1ed8a5e

Browse files
authored
Deploy script for OUSD and VaultCore upgrade. (#606)
1 parent cbf377d commit 1ed8a5e

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { deploymentWithProposal } = require("../utils/deploy");
2+
3+
module.exports = deploymentWithProposal(
4+
{ deployName: "019_resolution_and_savings" },
5+
async ({ ethers, deployWithConfirmation }) => {
6+
// Deployments
7+
const dOUSD = await deployWithConfirmation("OUSD");
8+
const dVaultCore = await deployWithConfirmation("VaultCore");
9+
10+
// Governance proposal
11+
const cOUSDProxy = await ethers.getContract("OUSDProxy");
12+
const cVaultProxy = await ethers.getContract("VaultProxy");
13+
return {
14+
name: "Upgrade OUSD resolution for new contracts, redeem gas savings",
15+
actions: [
16+
{
17+
contract: cOUSDProxy,
18+
signature: "upgradeTo(address)",
19+
args: [dOUSD.address],
20+
},
21+
{
22+
contract: cVaultProxy,
23+
signature: "upgradeTo(address)",
24+
args: [dVaultCore.address],
25+
},
26+
],
27+
};
28+
}
29+
);

contracts/utils/deploy.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,65 @@ const sendProposal = async (proposalArgs, description, opts = {}) => {
244244
log("Done");
245245
};
246246

247+
/**
248+
* Shortcut to create a deployment for hardhat to use
249+
* @param {Object} options for deployment
250+
* @param {Promise<Object>} fn to deploy contracts and return needed proposals
251+
* @returns {Object} main object used by hardhat
252+
*/
253+
function deploymentWithProposal(opts, fn) {
254+
const { deployName, dependencies } = opts;
255+
const runDeployment = async (hre) => {
256+
const tools = {
257+
ethers,
258+
deployWithConfirmation,
259+
};
260+
const proposal = await fn(tools);
261+
262+
const propDescription = proposal.name;
263+
const propArgs = await proposeArgs(proposal.actions);
264+
265+
if (isMainnet) {
266+
// On Mainnet, only propose. The enqueue and execution are handled manually via multi-sig.
267+
log("Sending proposal to governor...");
268+
await sendProposal(propArgs, propDescription);
269+
log("Proposal sent.");
270+
} else if (isFork) {
271+
// On Fork we can send the proposal then impersonate the guardian to execute it.
272+
log("Sending and executing proposal...");
273+
await executeProposal(propArgs, propDescription);
274+
log("Proposal executed.");
275+
} else {
276+
// Hardcoding gas estimate on Rinkeby since it fails for an undetermined reason...
277+
const gasLimit = isRinkeby ? 1000000 : null;
278+
for (const proposal of proposals) {
279+
const { contract, signature, args } = proposal;
280+
log(`Sending goverance action ${signature} to ${address}`);
281+
await withConfirmation(
282+
contract
283+
.connect(sGovernor)
284+
[signature](...args, await getTxOpts(gasLimit))
285+
);
286+
console.log(`... ${signature} completed`);
287+
}
288+
}
289+
};
290+
291+
const main = async (hre) => {
292+
console.log(`Running ${deployName} deployment...`);
293+
if (!hre) {
294+
hre = require("hardhat");
295+
}
296+
await runDeployment(hre);
297+
console.log(`${deployName} deploy done.`);
298+
return true;
299+
};
300+
main.id = deployName;
301+
main.dependencies = dependencies;
302+
main.skip = () => !(isMainnet || isRinkeby || isFork) || isSmokeTest;
303+
return main;
304+
}
305+
247306
module.exports = {
248307
log,
249308
sleep,
@@ -253,4 +312,5 @@ module.exports = {
253312
executeProposal,
254313
executeProposalOnFork,
255314
sendProposal,
315+
deploymentWithProposal,
256316
};

0 commit comments

Comments
 (0)