|
| 1 | +const { |
| 2 | + isMainnet, |
| 3 | + isFork, |
| 4 | + isRinkeby, |
| 5 | + isSmokeTest, |
| 6 | +} = require("../test/helpers.js"); |
| 7 | +const { |
| 8 | + log, |
| 9 | + deployWithConfirmation, |
| 10 | + withConfirmation, |
| 11 | + executeProposal, |
| 12 | + sendProposal, |
| 13 | +} = require("../utils/deploy"); |
| 14 | +const { proposeArgs } = require("../utils/governor"); |
| 15 | +const { getTxOpts } = require("../utils/tx"); |
| 16 | + |
| 17 | +const deployName = "013_upgrades"; |
| 18 | + |
| 19 | +/** |
| 20 | + * Deploys the vault trustee feature: |
| 21 | + * - upgrade VaultCore |
| 22 | + * - set trusteeAdress and trusteeFeeBps |
| 23 | + * @returns {Promise<boolean>} |
| 24 | + */ |
| 25 | +const trustee = async (hre) => { |
| 26 | + console.log(`Running ${deployName} deployment...`); |
| 27 | + |
| 28 | + const { governorAddr } = await hre.getNamedAccounts(); |
| 29 | + |
| 30 | + // Signers |
| 31 | + const sGovernor = await ethers.provider.getSigner(governorAddr); |
| 32 | + |
| 33 | + const cVaultProxy = await ethers.getContract("VaultProxy"); |
| 34 | + const cvaultAdmin = await ethers.getContractAt( |
| 35 | + "VaultAdmin", |
| 36 | + cVaultProxy.address |
| 37 | + ); |
| 38 | + |
| 39 | + // Deploy a new VaultCore contract. |
| 40 | + const dVaultCore = await deployWithConfirmation("VaultCore"); |
| 41 | + |
| 42 | + // Proposal for the governor to do the upgrades. |
| 43 | + const propDescription = "Trustee deploy and config"; |
| 44 | + const trusteeAddress = "0xF14BBdf064E3F67f51cd9BD646aE3716aD938FDC"; // Strategist multi-sig |
| 45 | + const trusteeFeeBps = 1000; // 1000 bps = 10% |
| 46 | + const propArgs = await proposeArgs([ |
| 47 | + { |
| 48 | + contract: cVaultProxy, |
| 49 | + signature: "upgradeTo(address)", |
| 50 | + args: [dVaultCore.address], |
| 51 | + }, |
| 52 | + { |
| 53 | + contract: cvaultAdmin, |
| 54 | + signature: "setTrusteeAddress(address)", |
| 55 | + args: [trusteeAddress], |
| 56 | + }, |
| 57 | + { |
| 58 | + contract: cvaultAdmin, |
| 59 | + signature: "setTrusteeFeeBps(uint256)", |
| 60 | + args: [trusteeFeeBps], |
| 61 | + }, |
| 62 | + ]); |
| 63 | + |
| 64 | + if (isMainnet) { |
| 65 | + // On Mainnet, only propose. The enqueue and execution are handled manually via multi-sig. |
| 66 | + log("Sending proposal to governor..."); |
| 67 | + await sendProposal(propArgs, propDescription); |
| 68 | + log("Proposal sent."); |
| 69 | + } else if (isFork) { |
| 70 | + // On Fork we can send the proposal then impersonate the guardian to execute it. |
| 71 | + log("Sending and executing proposal..."); |
| 72 | + await executeProposal(propArgs, propDescription); |
| 73 | + log("Proposal executed."); |
| 74 | + } else { |
| 75 | + // Hardcoding gas estimate on Rinkeby since it fails for an undetermined reason... |
| 76 | + const gasLimit = isRinkeby ? 1000000 : null; |
| 77 | + |
| 78 | + await withConfirmation( |
| 79 | + cVaultProxy |
| 80 | + .connect(sGovernor) |
| 81 | + .upgradeTo(dVaultCore.address, await getTxOpts(gasLimit)) |
| 82 | + ); |
| 83 | + log("Upgraded VaultCore to new implementation"); |
| 84 | + |
| 85 | + await withConfirmation( |
| 86 | + cvaultAdmin |
| 87 | + .connect(sGovernor) |
| 88 | + .setTrusteeAddress(trusteeAddress, await getTxOpts(gasLimit)) |
| 89 | + ); |
| 90 | + log("Trustee address set"); |
| 91 | + |
| 92 | + await withConfirmation( |
| 93 | + cvaultAdmin |
| 94 | + .connect(sGovernor) |
| 95 | + .setTrusteeFeeBps(trusteeFeeBps, await getTxOpts(gasLimit)) |
| 96 | + ); |
| 97 | + log("Trustee fee bps set"); |
| 98 | + } |
| 99 | + |
| 100 | + return true; |
| 101 | +}; |
| 102 | + |
| 103 | +const main = async (hre) => { |
| 104 | + console.log(`Running ${deployName} deployment...`); |
| 105 | + if (!hre) { |
| 106 | + hre = require("hardhat"); |
| 107 | + } |
| 108 | + await trustee(hre); |
| 109 | + console.log(`${deployName} deploy done.`); |
| 110 | + return true; |
| 111 | +}; |
| 112 | + |
| 113 | +main.id = deployName; |
| 114 | +main.dependencies = ["012_upgrades"]; |
| 115 | +main.skip = () => !(isMainnet || isRinkeby || isFork) || isSmokeTest; |
| 116 | + |
| 117 | +module.exports = main; |
0 commit comments