|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const ethers = require('ethers'); |
| 4 | +const { gray } = require('chalk'); |
| 5 | + |
| 6 | +module.exports = async ({ addressOf, compiled, deployer, network, runStep, useOvm }) => { |
| 7 | + console.log(gray(`\n------ REBUILD LEGACY RESOLVER CACHES ------\n`)); |
| 8 | + |
| 9 | + const { AddressResolver, ReadProxyAddressResolver } = deployer.deployedContracts; |
| 10 | + |
| 11 | + // Legacy contracts. |
| 12 | + if (network === 'mainnet' && !useOvm) { |
| 13 | + console.log(gray('Checking all legacy contracts using isResolverCached() return true')); |
| 14 | + |
| 15 | + const legacyContracts = { |
| 16 | + // v2.35.2 contracts, replaced in v2.36. |
| 17 | + // These still hold some funds, so need to ensure they are up to date |
| 18 | + CollateralEth: '0x3FF5c0A14121Ca39211C95f6cEB221b86A90729E', |
| 19 | + CollateralErc20: '0x3B3812BB9f6151bEb6fa10783F1ae848a77a0d46', // REN |
| 20 | + CollateralShort: '0x188C2274B04Ea392B21487b5De299e382Ff84246', |
| 21 | + |
| 22 | + // Synths deprecated during Wezen (v2.49) |
| 23 | + // It's necessary to keep these up to date as when someone attempts to redeem one, |
| 24 | + // it will invoke the Issuer which will then attempt to call Synth.burn. If the |
| 25 | + // Synth isn't updated to understand the latest Issuer, it will revert the attempted burn |
| 26 | + // Note: the synths with 0 supply have been removed as this is no longer required |
| 27 | + SynthiAAVE: '0x1cB27Ac646afAE192dF9928A2808C0f7f586Af7d', |
| 28 | + SynthiBNB: '0xf7B8dF8b16dA302d85603B8e7F95111a768458Cc', |
| 29 | + SynthiBTC: '0x8350d1b2d6EF5289179fe49E5b0F208165B4e32e', |
| 30 | + SynthiCEX: '0x6Dc6a64724399524184C2c44a526A2cff1BaA507', |
| 31 | + SynthiDASH: '0x947d5656725fB9A8f9c826A91b6082b07E2745B7', |
| 32 | + SynthiDEFI: '0x87eb6e935e3C7E3E3A0E31a5658498bC87dE646E', |
| 33 | + SynthiDOT: '0xF6ce55E09De0F9F97210aAf6DB88Ed6b6792Ca1f', |
| 34 | + SynthiEOS: '0x806A599d60B2FdBda379D5890287D2fba1026cC0', |
| 35 | + SynthiETH: '0x29DD4A59F4D339226867e77aF211724eaBb45c02', |
| 36 | + SynthiOIL: '0x53869BDa4b8d85aEDCC9C6cAcf015AF9447Cade7', |
| 37 | + SynthiXRP: '0x19cC1f63e344D74A87D955E3F3E95B28DDDc61d8', |
| 38 | + Synths1INCH: '0x0E8Fa2339314AB7E164818F26207897bBe29C3af', |
| 39 | + SynthsAAPL: '0x815CeF3b7773f35428B4353073B086ecB658f73C', |
| 40 | + SynthsADA: '0xC22e51FA362654ea453B4018B616ef6f6ab3b779', |
| 41 | + SynthsAMZN: '0x9530FA32a3059114AC20A5812870Da12D97d1174', |
| 42 | + SynthsBNB: '0xda3c83750b1FA31Fda838136ef3f853b41cb7a5a', |
| 43 | + SynthsCEX: '0x2acfe6265D358d982cB1c3B521199973CD443C71', |
| 44 | + SynthsCOIN: '0x249612F641111022f2f48769f3Df5D85cb3E26a2', |
| 45 | + SynthsCOMP: '0x34c76BC146b759E58886e821D62548AC1e0BA7Bc', |
| 46 | + SynthsCRV: '0x13D0F5B8630520eA04f694F17A001fb95eaFD30E', |
| 47 | + SynthsDASH: '0xcb6Cb218D558ae7fF6415f95BDA6616FCFF669Cb', |
| 48 | + SynthsEOS: '0xAf090d6E583C082f2011908cf95c2518BE7A53ac', |
| 49 | + SynthsETC: '0x21ee4afBd6c151fD9A69c1389598170B1d45E0e3', |
| 50 | + SynthsFB: '0xb0e0BA880775B7F2ba813b3800b3979d719F0379', |
| 51 | + SynthsFTSE: '0x3E2dA260B4A85782A629320EB027A3B7c28eA9f1', |
| 52 | + SynthsGOOG: '0x8e082925e78538955bC0e2F363FC5d1Ab3be739b', |
| 53 | + SynthsLTC: '0xA962208CDC8588F9238fae169d0F63306c353F4F', |
| 54 | + SynthsMSFT: '0x04720DbBD4599aD26811545595d97fB813E84964', |
| 55 | + SynthsNFLX: '0x399BA516a6d68d6Ad4D5f3999902D0DeAcaACDdd', |
| 56 | + SynthsNIKKEI: '0xc02DD182Ce029E6d7f78F37492DFd39E4FEB1f8b', |
| 57 | + SynthsOIL: '0x2962EA4E749e54b10CFA557770D597027BA67cB3', |
| 58 | + SynthsREN: '0x4287dac1cC7434991119Eba7413189A66fFE65cF', |
| 59 | + SynthsRUNE: '0xe615Df79AC987193561f37E77465bEC2aEfe9aDb', |
| 60 | + SynthsTRX: '0x47bD14817d7684082E04934878EE2Dd3576Ae19d', |
| 61 | + SynthsTSLA: '0x0d1c4e5C07B071aa4E6A14A604D4F6478cAAC7B4', |
| 62 | + SynthsUNI: '0xAa1b12E3e5F70aBCcd1714F4260A74ca21e7B17b', |
| 63 | + SynthsXAG: '0x9745606DA6e162866DAD7bF80f2AbF145EDD7571', |
| 64 | + SynthsXAU: '0x5eDf7dd83fE2889D264fa9D3b93d0a6e6A45D6C6', |
| 65 | + SynthsXMR: '0x7B29C9e188De18563B19d162374ce6836F31415a', |
| 66 | + SynthsXRP: '0xe3D5E1c1bA874C0fF3BA31b999967F24d5ca04e5', |
| 67 | + SynthsXTZ: '0x6F927644d55E32318629198081923894FbFe5c07', |
| 68 | + SynthsYFI: '0x0F393ce493d8FB0b83915248a21a3104932ed97c', |
| 69 | + }; |
| 70 | + |
| 71 | + const legacyContractsToRebuildCache = []; |
| 72 | + // determine which need resolver caching |
| 73 | + for (const [name, address] of Object.entries(legacyContracts)) { |
| 74 | + const { abi } = compiled['MixinResolver']; |
| 75 | + |
| 76 | + const target = new ethers.Contract(address, abi, deployer.provider); |
| 77 | + |
| 78 | + const response = await target.isResolverCached(); |
| 79 | + |
| 80 | + if (!response) { |
| 81 | + console.log(gray(name, 'is legacy and requires caching', address)); |
| 82 | + legacyContractsToRebuildCache.push(address); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + const addressesChunkSize = 20; |
| 87 | + let batchCounter = 1; |
| 88 | + for (let i = 0; i < legacyContractsToRebuildCache.length; i += addressesChunkSize) { |
| 89 | + const chunk = legacyContractsToRebuildCache.slice(i, i + addressesChunkSize); |
| 90 | + await runStep({ |
| 91 | + gasLimit: 7e6, |
| 92 | + contract: `AddressResolver`, |
| 93 | + target: AddressResolver, |
| 94 | + publiclyCallable: true, // does not require owner |
| 95 | + write: 'rebuildCaches', |
| 96 | + writeArg: [chunk], |
| 97 | + comment: `Rebuild the resolver caches of legacy contracts - batch ${batchCounter++}`, |
| 98 | + // these updates are tricky to Soliditize, and aren't |
| 99 | + // owner required and aren't critical to the core, so |
| 100 | + // let's skip them in the migration script |
| 101 | + // and a re-run of the deploy script will catch them |
| 102 | + skipSolidity: true, |
| 103 | + }); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + const filterTargetsWith = ({ prop }) => |
| 108 | + Object.entries(deployer.deployedContracts).filter(([, target]) => { |
| 109 | + return target.functions[prop] !== undefined; |
| 110 | + }); |
| 111 | + |
| 112 | + // Now perform a sync of legacy contracts that have not been replaced in Shaula (v2.35.x) |
| 113 | + // EtherCollateral, EtherCollateralsUSD |
| 114 | + console.log(gray('Checking all legacy contracts with setResolverAndSyncCache() are rebuilt...')); |
| 115 | + const contractsWithLegacyResolverCaching = filterTargetsWith({ |
| 116 | + prop: 'setResolverAndSyncCache', |
| 117 | + }); |
| 118 | + for (const [contract, target] of contractsWithLegacyResolverCaching) { |
| 119 | + await runStep({ |
| 120 | + gasLimit: 500e3, // higher gas required |
| 121 | + contract, |
| 122 | + target, |
| 123 | + read: 'isResolverCached', |
| 124 | + readArg: addressOf(ReadProxyAddressResolver), |
| 125 | + expected: input => input, |
| 126 | + write: 'setResolverAndSyncCache', |
| 127 | + writeArg: addressOf(ReadProxyAddressResolver), |
| 128 | + comment: |
| 129 | + 'Rebuild the resolver cache of contracts that use the legacy "setResolverAndSyncCache" function', |
| 130 | + }); |
| 131 | + } |
| 132 | + |
| 133 | + // Finally set resolver on contracts even older than legacy (Depot) |
| 134 | + console.log(gray('Checking all legacy contracts with setResolver() are rebuilt...')); |
| 135 | + const contractsWithLegacyResolverNoCache = filterTargetsWith({ |
| 136 | + prop: 'setResolver', |
| 137 | + }); |
| 138 | + for (const [contract, target] of contractsWithLegacyResolverNoCache) { |
| 139 | + await runStep({ |
| 140 | + gasLimit: 500e3, // higher gas required |
| 141 | + contract, |
| 142 | + target, |
| 143 | + read: 'resolver', |
| 144 | + expected: input => addressOf(ReadProxyAddressResolver), |
| 145 | + write: 'setResolver', |
| 146 | + writeArg: addressOf(ReadProxyAddressResolver), |
| 147 | + comment: 'Rebuild the resolver cache of contracts that use the legacy "setResolver" function', |
| 148 | + }); |
| 149 | + } |
| 150 | + |
| 151 | + console.log(gray('All legacy caches are rebuilt. ')); |
| 152 | +}; |
0 commit comments