|
| 1 | +const { parseEther } = require("ethers/lib/utils"); |
| 2 | + |
| 3 | +const { deployOnSonic } = require("../../utils/deploy-l2.js"); |
| 4 | +const { |
| 5 | + deployWithConfirmation, |
| 6 | + withConfirmation, |
| 7 | +} = require("../../utils/deploy.js"); |
| 8 | +const addresses = require("../../utils/addresses.js"); |
| 9 | + |
| 10 | +module.exports = deployOnSonic( |
| 11 | + { |
| 12 | + deployName: "001_vault_and_token", |
| 13 | + forceSkip: false, |
| 14 | + }, |
| 15 | + async ({ ethers }) => { |
| 16 | + const { deployerAddr, strategistAddr } = await getNamedAccounts(); |
| 17 | + console.log(`Deployer: ${deployerAddr}`); |
| 18 | + const sDeployer = await ethers.provider.getSigner(deployerAddr); |
| 19 | + |
| 20 | + const cWS = await ethers.getContractAt("IWrappedSonic", addresses.sonic.wS); |
| 21 | + |
| 22 | + // Proxies |
| 23 | + const dOSonicProxy = await deployWithConfirmation("OSonicProxy"); |
| 24 | + console.log(`Deployed Origin S proxy to ${dOSonicProxy.address}`); |
| 25 | + |
| 26 | + const dWOSonicProxy = await deployWithConfirmation("WOSonicProxy"); |
| 27 | + console.log(`Deployed Wrapped Origin S proxy to ${dWOSonicProxy.address}`); |
| 28 | + |
| 29 | + const dOSonicVaultProxy = await deployWithConfirmation("OSonicVaultProxy"); |
| 30 | + console.log(`Deployed Vault proxy to ${dOSonicVaultProxy.address}`); |
| 31 | + |
| 32 | + const cOSonicProxy = await ethers.getContract("OSonicProxy"); |
| 33 | + const cWOSonicProxy = await ethers.getContract("WOSonicProxy"); |
| 34 | + const cOSonicVaultProxy = await ethers.getContract("OSonicVaultProxy"); |
| 35 | + |
| 36 | + // Core contracts |
| 37 | + const dOSonic = await deployWithConfirmation("OSonic"); |
| 38 | + console.log(`Deployed Origin S to ${dOSonic.address}`); |
| 39 | + |
| 40 | + const dWOSonic = await deployWithConfirmation("WOSonic", [ |
| 41 | + cOSonicProxy.address, // Base token |
| 42 | + "Wrapped Origin S", // Token Name |
| 43 | + "wOS", // Token Symbol |
| 44 | + ]); |
| 45 | + console.log(`Deployed Wrapped Origin S to ${dWOSonic.address}`); |
| 46 | + |
| 47 | + const dOSonicVaultCore = await deployWithConfirmation("OSonicVaultCore", [ |
| 48 | + cWS.address, |
| 49 | + ]); |
| 50 | + console.log(`Deployed Vault Core to ${dOSonicVaultCore.address}`); |
| 51 | + |
| 52 | + const dOSonicVaultAdmin = await deployWithConfirmation("OSonicVaultAdmin", [ |
| 53 | + cWS.address, |
| 54 | + ]); |
| 55 | + console.log(`Deployed Vault Admin to ${dOSonicVaultAdmin.address}`); |
| 56 | + |
| 57 | + // Get contract instances |
| 58 | + const cOSonic = await ethers.getContractAt("OSonic", cOSonicProxy.address); |
| 59 | + const cWOSonic = await ethers.getContractAt( |
| 60 | + "WOSonic", |
| 61 | + cWOSonicProxy.address |
| 62 | + ); |
| 63 | + const cOSonicVault = await ethers.getContractAt( |
| 64 | + "IVault", |
| 65 | + cOSonicVaultProxy.address |
| 66 | + ); |
| 67 | + |
| 68 | + // Init OSonic |
| 69 | + const resolution = ethers.utils.parseUnits("1", 27); |
| 70 | + const initDataOSonic = cOSonic.interface.encodeFunctionData( |
| 71 | + "initialize(address,uint256)", |
| 72 | + [ |
| 73 | + cOSonicVaultProxy.address, // Origin Sonic Vault |
| 74 | + resolution, // HighRes |
| 75 | + ] |
| 76 | + ); |
| 77 | + |
| 78 | + // prettier-ignore |
| 79 | + await cOSonicProxy |
| 80 | + .connect(sDeployer)["initialize(address,address,bytes)"]( |
| 81 | + dOSonic.address, |
| 82 | + addresses.sonic.timelock, |
| 83 | + initDataOSonic |
| 84 | + ); |
| 85 | + console.log("Initialized Origin S"); |
| 86 | + |
| 87 | + // Init OSonicVault |
| 88 | + const initDataOSonicVault = cOSonicVault.interface.encodeFunctionData( |
| 89 | + "initialize(address,address)", |
| 90 | + [ |
| 91 | + addresses.dead, // OracleRouter |
| 92 | + cOSonicProxy.address, // OSonic |
| 93 | + ] |
| 94 | + ); |
| 95 | + // prettier-ignore |
| 96 | + await cOSonicVaultProxy |
| 97 | + .connect(sDeployer)["initialize(address,address,bytes)"]( |
| 98 | + dOSonicVaultCore.address, |
| 99 | + addresses.sonic.timelock, |
| 100 | + initDataOSonicVault |
| 101 | + ); |
| 102 | + console.log("Initialized Origin S Vault"); |
| 103 | + |
| 104 | + // Init WOSonic |
| 105 | + const initDataWOSonic = cWOSonic.interface.encodeFunctionData( |
| 106 | + "initialize()", |
| 107 | + [] |
| 108 | + ); |
| 109 | + // prettier-ignore |
| 110 | + await cWOSonicProxy |
| 111 | + .connect(sDeployer)["initialize(address,address,bytes)"]( |
| 112 | + dWOSonic.address, |
| 113 | + addresses.sonic.timelock, |
| 114 | + initDataWOSonic |
| 115 | + ) |
| 116 | + console.log("Initialized Wrapper Origin S"); |
| 117 | + |
| 118 | + // Deploy the Dripper |
| 119 | + const dOSonicDripperProxy = await deployWithConfirmation( |
| 120 | + "OSonicDripperProxy" |
| 121 | + ); |
| 122 | + console.log( |
| 123 | + `Deployed Origin Sonic Dripper Proxy to ${dOSonicDripperProxy.address}` |
| 124 | + ); |
| 125 | + const cOSonicDripperProxy = await ethers.getContract("OSonicDripperProxy"); |
| 126 | + |
| 127 | + const dFixedRateDripper = await deployWithConfirmation("FixedRateDripper", [ |
| 128 | + cOSonicVaultProxy.address, // VaultAddress |
| 129 | + cWS.address, |
| 130 | + ]); |
| 131 | + console.log(`Deployed Fixed Rate Dripper to ${dFixedRateDripper.address}`); |
| 132 | + |
| 133 | + // Init the Dripper proxy |
| 134 | + // prettier-ignore |
| 135 | + await withConfirmation( |
| 136 | + cOSonicDripperProxy |
| 137 | + .connect(sDeployer)["initialize(address,address,bytes)"]( |
| 138 | + dFixedRateDripper.address, |
| 139 | + addresses.sonic.timelock, |
| 140 | + "0x" |
| 141 | + ) |
| 142 | + ); |
| 143 | + |
| 144 | + // Deploy the Zapper |
| 145 | + const dOSonicZapper = await deployWithConfirmation("OSonicZapper", [ |
| 146 | + cOSonic.address, |
| 147 | + cWOSonic.address, |
| 148 | + cOSonicVault.address, |
| 149 | + ]); |
| 150 | + console.log(`Deployed Origin Sonic Zapper to ${dOSonicZapper.address}`); |
| 151 | + |
| 152 | + // Deploy the VaultValueChecker |
| 153 | + await deployWithConfirmation("VaultValueChecker", [ |
| 154 | + cOSonicVault.address, // Origin Sonic Vault |
| 155 | + cOSonic.address, // Origin Sonic token |
| 156 | + ]); |
| 157 | + const vaultValueChecker = await ethers.getContract("VaultValueChecker"); |
| 158 | + console.log(`Deployed Vault Value Checker to ${vaultValueChecker.address}`); |
| 159 | + |
| 160 | + return { |
| 161 | + name: "Config Tokens and Vault", |
| 162 | + actions: [ |
| 163 | + // 1. Upgrade Vault proxy to VaultCore |
| 164 | + { |
| 165 | + contract: cOSonicVaultProxy, |
| 166 | + signature: "upgradeTo(address)", |
| 167 | + args: [dOSonicVaultCore.address], |
| 168 | + }, |
| 169 | + // 2. Set the VaultAdmin |
| 170 | + { |
| 171 | + contract: cOSonicVault, |
| 172 | + signature: "setAdminImpl(address)", |
| 173 | + args: [dOSonicVaultAdmin.address], |
| 174 | + }, |
| 175 | + // 3. Support wrapped S |
| 176 | + { |
| 177 | + contract: cOSonicVault, |
| 178 | + signature: "supportAsset(address,uint8)", |
| 179 | + args: [cWS.address, 0], // 0 -> UnitConversion.DECIMALS |
| 180 | + }, |
| 181 | + // 4. Unpause capital |
| 182 | + { |
| 183 | + contract: cOSonicVault, |
| 184 | + signature: "unpauseCapital()", |
| 185 | + args: [], |
| 186 | + }, |
| 187 | + // 5. withdrawal claim delay set to 1 day |
| 188 | + { |
| 189 | + contract: cOSonicVault, |
| 190 | + signature: "setWithdrawalClaimDelay(uint256)", |
| 191 | + args: [86400], |
| 192 | + }, |
| 193 | + // 6. Configure the Vault |
| 194 | + { |
| 195 | + contract: cOSonicVault, |
| 196 | + signature: "setRebaseThreshold(uint256)", |
| 197 | + args: [parseEther("10")], // 10 OS |
| 198 | + }, |
| 199 | + // 7. set setAutoAllocateThreshold |
| 200 | + { |
| 201 | + contract: cOSonicVault, |
| 202 | + signature: "setMaxSupplyDiff(uint256)", |
| 203 | + args: [parseEther("1")], // 1 OS |
| 204 | + }, |
| 205 | + // 8. set guardian / strategist |
| 206 | + { |
| 207 | + contract: cOSonicVault, |
| 208 | + signature: "setStrategistAddr(address)", |
| 209 | + args: [strategistAddr], |
| 210 | + }, |
| 211 | + // 9. set the trustee address |
| 212 | + { |
| 213 | + contract: cOSonicVault, |
| 214 | + signature: "setTrusteeAddress(address)", |
| 215 | + args: [strategistAddr], |
| 216 | + }, |
| 217 | + // 10. set the trustee fee |
| 218 | + { |
| 219 | + contract: cOSonicVault, |
| 220 | + signature: "setTrusteeFeeBps(uint256)", |
| 221 | + args: [2000], // 20% |
| 222 | + }, |
| 223 | + // 11. Set the Dripper on the Vault |
| 224 | + { |
| 225 | + contract: cOSonicVault, |
| 226 | + signature: "setDripper(address)", |
| 227 | + args: [cOSonicDripperProxy.address], |
| 228 | + }, |
| 229 | + ], |
| 230 | + }; |
| 231 | + } |
| 232 | +); |
0 commit comments