Skip to content

Commit a546d3f

Browse files
committed
Merge branch 'deployer-eip1559' of https://github.com/Synthetixio/synthetix into deployer-eip1559
2 parents 1a57aee + f212d6d commit a546d3f

File tree

4 files changed

+177
-88
lines changed

4 files changed

+177
-88
lines changed

publish/src/commands/deploy/configure-loans.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ module.exports = async ({
174174
comment: 'Ensure the CollateralShort contract has its issue fee rate set',
175175
});
176176

177-
if (SystemSettings) {
178-
const interactionDelay = (await getDeployParameter('COLLATERAL_SHORT'))['INTERACTION_DELAY'];
177+
const interactionDelay = (await getDeployParameter('COLLATERAL_SHORT'))['INTERACTION_DELAY'];
178+
if (SystemSettings.interactionDelay) {
179179
await runStep({
180180
contract: 'SystemSettings',
181181
target: SystemSettings,
@@ -186,6 +186,17 @@ module.exports = async ({
186186
writeArg: [CollateralShort.address, interactionDelay],
187187
comment: 'Ensure the CollateralShort contract has an interaction delay of zero on the OVM',
188188
});
189+
} else {
190+
await runStep({
191+
contract: 'CollateralShort',
192+
target: CollateralShort,
193+
read: 'interactionDelay',
194+
expected: input => input !== '0', // only change if zero
195+
write: 'setInteractionDelay',
196+
writeArg: interactionDelay,
197+
comment:
198+
'Ensure the CollateralShort contract has an interaction delay to prevent frontrunning',
199+
});
189200
}
190201

191202
if (SystemSettings.collapseFeeRate) {

publish/src/commands/deploy/index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const importAddresses = require('./import-addresses');
3838
const importFeePeriods = require('./import-fee-periods');
3939
const performSafetyChecks = require('./perform-safety-checks');
4040
const rebuildResolverCaches = require('./rebuild-resolver-caches');
41+
const rebuildLegacyResolverCaches = require('./rebuild-legacy-resolver-caches');
4142
const systemAndParameterCheck = require('./system-and-parameter-check');
4243
const takeDebtSnapshotWhenRequired = require('./take-debt-snapshot-when-required');
4344

@@ -312,17 +313,23 @@ const deploy = async ({
312313
});
313314

314315
await rebuildResolverCaches({
315-
addressOf,
316-
compiled,
317316
deployer,
318317
generateSolidity,
319318
limitPromise,
320-
network,
321319
newContractsBeingAdded,
322320
runStep,
323321
useOvm,
324322
});
325323

324+
await rebuildLegacyResolverCaches({
325+
addressOf,
326+
compiled,
327+
deployer,
328+
network,
329+
runStep,
330+
useOvm,
331+
});
332+
326333
await configureLegacySettings({
327334
account,
328335
addressOf,
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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+
};

publish/src/commands/deploy/rebuild-resolver-caches.js

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,16 @@ const {
88
} = require('../../../..');
99

1010
module.exports = async ({
11-
addressOf,
12-
compiled,
1311
deployer,
1412
generateSolidity,
1513
limitPromise,
16-
network,
1714
newContractsBeingAdded,
1815
runStep,
1916
useOvm,
2017
}) => {
21-
const { AddressResolver, ReadProxyAddressResolver } = deployer.deployedContracts;
18+
console.log(gray(`\n------ REBUILD RESOLVER CACHES ------\n`));
2219

23-
// Legacy contracts.
24-
if (network === 'mainnet' && !useOvm) {
25-
// v2.35.2 contracts.
26-
// TODO -fetch these from getVersions()
27-
const CollateralEth = '0x3FF5c0A14121Ca39211C95f6cEB221b86A90729E';
28-
const CollateralErc20 = '0x3B3812BB9f6151bEb6fa10783F1ae848a77a0d46'; // REN
29-
const CollateralShort = '0x188C2274B04Ea392B21487b5De299e382Ff84246';
30-
31-
const legacyContracts = Object.entries({
32-
CollateralEth,
33-
CollateralErc20,
34-
CollateralShort,
35-
}).map(([name, address]) => {
36-
// Conbine MixinResolver + Owned abis
37-
const abi1 = compiled['MixinResolver'].abi;
38-
const abi2 = compiled['Owned'].abi.filter(e => e.type !== 'constructor'); // Avoid duplicate constructor entries
39-
const abi = [...abi1, ...abi2];
40-
41-
const target = new ethers.Contract(address, abi, deployer.provider);
42-
target.source = name;
43-
return [`legacy_${name}`, target];
44-
});
45-
46-
for (const [name, target] of legacyContracts) {
47-
await runStep({
48-
gasLimit: 7e6,
49-
contract: name,
50-
target,
51-
read: 'isResolverCached',
52-
expected: input => input,
53-
publiclyCallable: true, // does not require owner
54-
write: 'rebuildCache',
55-
// these updates are tricky to Soliditize, and aren't
56-
// owner required and aren't critical to the core, so
57-
// let's skip them in the migration script
58-
// and a re-run of the deploy script will catch them
59-
skipSolidity: true,
60-
});
61-
}
62-
}
20+
const { AddressResolver } = deployer.deployedContracts;
6321

6422
const filterTargetsWith = ({ prop }) =>
6523
Object.entries(deployer.deployedContracts).filter(([, target]) => {
@@ -200,44 +158,5 @@ module.exports = async ({
200158
}
201159
}
202160

203-
// Now perform a sync of legacy contracts that have not been replaced in Shaula (v2.35.x)
204-
// EtherCollateral, EtherCollateralsUSD
205-
console.log(gray('Checking all legacy contracts with setResolverAndSyncCache() are rebuilt...'));
206-
const contractsWithLegacyResolverCaching = filterTargetsWith({
207-
prop: 'setResolverAndSyncCache',
208-
});
209-
for (const [contract, target] of contractsWithLegacyResolverCaching) {
210-
await runStep({
211-
gasLimit: 500e3, // higher gas required
212-
contract,
213-
target,
214-
read: 'isResolverCached',
215-
readArg: addressOf(ReadProxyAddressResolver),
216-
expected: input => input,
217-
write: 'setResolverAndSyncCache',
218-
writeArg: addressOf(ReadProxyAddressResolver),
219-
comment:
220-
'Rebuild the resolver cache of contracts that use the legacy "setResolverAndSyncCache" function',
221-
});
222-
}
223-
224-
// Finally set resolver on contracts even older than legacy (Depot)
225-
console.log(gray('Checking all legacy contracts with setResolver() are rebuilt...'));
226-
const contractsWithLegacyResolverNoCache = filterTargetsWith({
227-
prop: 'setResolver',
228-
});
229-
for (const [contract, target] of contractsWithLegacyResolverNoCache) {
230-
await runStep({
231-
gasLimit: 500e3, // higher gas required
232-
contract,
233-
target,
234-
read: 'resolver',
235-
expected: input => addressOf(ReadProxyAddressResolver),
236-
write: 'setResolver',
237-
writeArg: addressOf(ReadProxyAddressResolver),
238-
comment: 'Rebuild the resolver cache of contracts that use the legacy "setResolver" function',
239-
});
240-
}
241-
242161
console.log(gray('All caches are rebuilt. '));
243162
};

0 commit comments

Comments
 (0)