@openzeppelin/upgrades-core 1.44.2 → 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/validate/build-info-file.js +95 -20
- package/dist/cli/validate/build-info-file.js.map +1 -1
- package/dist/impl-address.d.ts +2 -1
- package/dist/impl-address.d.ts.map +1 -1
- package/dist/impl-address.js +8 -2
- package/dist/impl-address.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/validate/build-info-file.ts +127 -23
- package/src/impl-address.ts +7 -2
|
@@ -91,42 +91,109 @@ async function exists(dir) {
|
|
|
91
91
|
}
|
|
92
92
|
async function getJsonFiles(dir) {
|
|
93
93
|
const files = await fs_1.promises.readdir(dir);
|
|
94
|
-
const jsonFiles = files.filter(file => file.endsWith('.json'));
|
|
94
|
+
const jsonFiles = files.filter(file => file.endsWith('.json') && !file.endsWith('.output.json'));
|
|
95
95
|
return jsonFiles.map(file => path_1.default.join(dir, file));
|
|
96
96
|
}
|
|
97
97
|
async function readBuildInfo(buildInfoFilePaths, dirShortName) {
|
|
98
98
|
const buildInfoFiles = [];
|
|
99
99
|
for (const buildInfoFilePath of buildInfoFilePaths) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
100
|
+
const buildInfo = await loadBuildInfo(buildInfoFilePath);
|
|
101
|
+
checkOutputSelection(buildInfo.input, buildInfoFilePath);
|
|
102
|
+
buildInfoFiles.push({
|
|
103
|
+
input: buildInfo.input,
|
|
104
|
+
output: buildInfo.output,
|
|
105
|
+
solcVersion: buildInfo.solcVersion,
|
|
106
|
+
dirShortName,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
return buildInfoFiles;
|
|
110
|
+
}
|
|
111
|
+
async function loadBuildInfo(buildInfoFilePath) {
|
|
112
|
+
const buildInfoJson = await readJSON(buildInfoFilePath);
|
|
113
|
+
if (buildInfoJson.input !== undefined &&
|
|
114
|
+
buildInfoJson.output !== undefined &&
|
|
115
|
+
buildInfoJson.solcVersion !== undefined) {
|
|
116
|
+
return {
|
|
117
|
+
input: buildInfoJson.input,
|
|
118
|
+
output: buildInfoJson.output,
|
|
119
|
+
solcVersion: buildInfoJson.solcVersion,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const format = buildInfoJson._format;
|
|
123
|
+
if (typeof format === 'string' &&
|
|
124
|
+
(format.startsWith('hh3-sol-build-info') || format.startsWith('hh-sol-build-info'))) {
|
|
125
|
+
if (buildInfoJson.input !== undefined && buildInfoJson.solcVersion !== undefined) {
|
|
126
|
+
let inputData = buildInfoJson.input;
|
|
127
|
+
let outputData = buildInfoJson.output;
|
|
128
|
+
if (outputData === undefined) {
|
|
129
|
+
const { dir, name } = path_1.default.parse(buildInfoFilePath);
|
|
130
|
+
const outputFilePath = path_1.default.join(dir, `${name}.output.json`);
|
|
131
|
+
try {
|
|
132
|
+
const outputJson = await readJSON(outputFilePath);
|
|
133
|
+
outputData = outputJson.output ?? outputJson;
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} does not contain output, and output file ${outputFilePath} could not be read.`);
|
|
137
|
+
}
|
|
138
|
+
if (outputData === undefined) {
|
|
139
|
+
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} does not contain output, and output file ${outputFilePath} is missing Solidity compiler output.`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const userSourceNameMap = buildInfoJson.userSourceNameMap;
|
|
143
|
+
if (userSourceNameMap !== undefined) {
|
|
144
|
+
const canonicalToUser = {};
|
|
145
|
+
for (const [userSource, canonicalSource] of Object.entries(userSourceNameMap)) {
|
|
146
|
+
canonicalToUser[canonicalSource] = userSource;
|
|
147
|
+
}
|
|
148
|
+
if (inputData.sources !== undefined) {
|
|
149
|
+
inputData = {
|
|
150
|
+
...inputData,
|
|
151
|
+
sources: remapKeys(inputData.sources, canonicalToUser),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (outputData.sources !== undefined) {
|
|
155
|
+
outputData = {
|
|
156
|
+
...outputData,
|
|
157
|
+
sources: remapKeys(outputData.sources, canonicalToUser),
|
|
158
|
+
contracts: outputData.contracts !== undefined
|
|
159
|
+
? remapKeys(outputData.contracts, canonicalToUser)
|
|
160
|
+
: outputData.contracts,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
else if (outputData.contracts !== undefined) {
|
|
164
|
+
outputData = {
|
|
165
|
+
...outputData,
|
|
166
|
+
contracts: remapKeys(outputData.contracts, canonicalToUser),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
input: inputData,
|
|
172
|
+
output: outputData,
|
|
111
173
|
solcVersion: buildInfoJson.solcVersion,
|
|
112
|
-
|
|
113
|
-
});
|
|
174
|
+
};
|
|
114
175
|
}
|
|
115
176
|
}
|
|
116
|
-
|
|
177
|
+
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} must contain Solidity compiler input, output, and solcVersion. Got format: ${format ?? 'unknown'}.`);
|
|
117
178
|
}
|
|
118
179
|
/**
|
|
119
180
|
* Gives an error if there is empty output selection for any contract, or a contract does not have storage layout.
|
|
120
181
|
*/
|
|
121
|
-
function checkOutputSelection(
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
182
|
+
function checkOutputSelection(input, buildInfoFilePath) {
|
|
183
|
+
const outputSelection = input.settings?.outputSelection;
|
|
184
|
+
if (outputSelection === undefined) {
|
|
185
|
+
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} does not define compiler outputSelection.`, () => STORAGE_LAYOUT_HELP);
|
|
186
|
+
}
|
|
187
|
+
Object.keys(outputSelection).forEach(item => {
|
|
188
|
+
const selection = outputSelection[item] ?? {};
|
|
189
|
+
const unnamed = Array.isArray(selection['']) ? selection[''] : [];
|
|
190
|
+
const wildcard = Array.isArray(selection['*']) ? selection['*'] : [];
|
|
191
|
+
if (unnamed.length === 0 && wildcard.length === 0) {
|
|
125
192
|
// No outputs at all for this contract e.g. if there were no changes since the last compile in Foundry.
|
|
126
193
|
// This is not supported for now, since it leads to AST nodes that reference node ids in other build-info files.
|
|
127
194
|
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} is not from a full compilation.`, () => PARTIAL_COMPILE_HELP);
|
|
128
195
|
}
|
|
129
|
-
else if (!
|
|
196
|
+
else if (!wildcard.includes('storageLayout')) {
|
|
130
197
|
throw new error_1.ValidateCommandError(`Build info file ${buildInfoFilePath} does not contain storage layout for all contracts.`, () => STORAGE_LAYOUT_HELP);
|
|
131
198
|
}
|
|
132
199
|
});
|
|
@@ -134,4 +201,12 @@ function checkOutputSelection(buildInfoJson, buildInfoFilePath) {
|
|
|
134
201
|
async function readJSON(path) {
|
|
135
202
|
return JSON.parse(await fs_1.promises.readFile(path, 'utf8'));
|
|
136
203
|
}
|
|
204
|
+
function remapKeys(original, canonicalToUser) {
|
|
205
|
+
const remapped = {};
|
|
206
|
+
for (const [key, value] of Object.entries(original)) {
|
|
207
|
+
const mappedKey = canonicalToUser[key] ?? key;
|
|
208
|
+
remapped[mappedKey] = value;
|
|
209
|
+
}
|
|
210
|
+
return remapped;
|
|
211
|
+
}
|
|
137
212
|
//# sourceMappingURL=build-info-file.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-info-file.js","sourceRoot":"","sources":["../../../src/cli/validate/build-info-file.ts"],"names":[],"mappings":";;;;;AAgEA,8CAMC;AApED,2BAAoC;AACpC,gDAAwB;AACxB,mCAA+C;AAE/C,MAAM,uBAAuB,GAAG,0CAA0C,CAAC;AAC3E,MAAM,uBAAuB,GAAG,4BAA4B,CAAC;AAC7D,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;sCAaU,uB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;AAED,SAAS,SAAS,CAAI,QAA2B,EAAE,eAAuC;IACxF,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC;QAC9C,QAAQ,CAAC,SAAS,CAAC,GAAG,KAAK,CAAC;IAC9B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/impl-address.d.ts
CHANGED
|
@@ -9,7 +9,8 @@ export declare class InvalidBeacon extends UpgradesError {
|
|
|
9
9
|
* @returns The implementation address.
|
|
10
10
|
* @throws {InvalidBeacon} If the implementation() function could not be called or does not return an address.
|
|
11
11
|
*/
|
|
12
|
-
export declare function getImplementationAddressFromBeacon(provider: EthereumProvider,
|
|
12
|
+
export declare function getImplementationAddressFromBeacon(provider: EthereumProvider, // v2 may differ from v3
|
|
13
|
+
beaconAddress: string): Promise<string>;
|
|
13
14
|
/**
|
|
14
15
|
* Gets the implementation address from a UUPS/Transparent/Beacon proxy.
|
|
15
16
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-address.d.ts","sourceRoot":"","sources":["../src/impl-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EACd,MAAM,GAAG,CAAC;AAGX,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,qBAAa,aAAc,SAAQ,aAAa;CAAG;AAEnD;;;;;;GAMG;AACH,wBAAsB,kCAAkC,CACtD,QAAQ,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"impl-address.d.ts","sourceRoot":"","sources":["../src/impl-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EACd,MAAM,GAAG,CAAC;AAGX,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG9C,qBAAa,aAAc,SAAQ,aAAa;CAAG;AAEnD;;;;;;GAMG;AACH,wBAAsB,kCAAkC,CACtD,QAAQ,EAAE,gBAAgB,EAAE,wBAAwB;AACpD,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;;;;GAIG;AACH,wBAAsB,iCAAiC,CACrD,QAAQ,EAAE,gBAAgB,EAC1B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAmB7B"}
|
package/dist/impl-address.js
CHANGED
|
@@ -16,11 +16,17 @@ exports.InvalidBeacon = InvalidBeacon;
|
|
|
16
16
|
* @returns The implementation address.
|
|
17
17
|
* @throws {InvalidBeacon} If the implementation() function could not be called or does not return an address.
|
|
18
18
|
*/
|
|
19
|
-
async function getImplementationAddressFromBeacon(provider,
|
|
19
|
+
async function getImplementationAddressFromBeacon(provider, // v2 may differ from v3
|
|
20
|
+
beaconAddress) {
|
|
20
21
|
const impl = await (0, call_optional_signature_1.callOptionalSignature)(provider, beaconAddress, 'implementation()');
|
|
21
22
|
let parsedImplAddress;
|
|
22
23
|
if (impl !== undefined) {
|
|
23
|
-
|
|
24
|
+
try {
|
|
25
|
+
parsedImplAddress = (0, address_1.parseAddress)(impl);
|
|
26
|
+
}
|
|
27
|
+
catch (parseErr) {
|
|
28
|
+
throw new InvalidBeacon(`Contract at ${beaconAddress} doesn't look like a beacon`);
|
|
29
|
+
}
|
|
24
30
|
}
|
|
25
31
|
if (parsedImplAddress === undefined) {
|
|
26
32
|
throw new InvalidBeacon(`Contract at ${beaconAddress} doesn't look like a beacon`);
|
package/dist/impl-address.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"impl-address.js","sourceRoot":"","sources":["../src/impl-address.ts"],"names":[],"mappings":";;;AAqBA,
|
|
1
|
+
{"version":3,"file":"impl-address.js","sourceRoot":"","sources":["../src/impl-address.ts"],"names":[],"mappings":";;;AAqBA,g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AAqB,EAAE,CAAC;oBACvC,OAAO,SAAS,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,MAAM,CAAC,CAAC;gBACV,CAAC;YACH,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -129,7 +129,7 @@ async function exists(dir: string) {
|
|
|
129
129
|
|
|
130
130
|
async function getJsonFiles(dir: string): Promise<string[]> {
|
|
131
131
|
const files = await fs.readdir(dir);
|
|
132
|
-
const jsonFiles = files.filter(file => file.endsWith('.json'));
|
|
132
|
+
const jsonFiles = files.filter(file => file.endsWith('.json') && !file.endsWith('.output.json'));
|
|
133
133
|
return jsonFiles.map(file => path.join(dir, file));
|
|
134
134
|
}
|
|
135
135
|
|
|
@@ -137,44 +137,139 @@ async function readBuildInfo(buildInfoFilePaths: string[], dirShortName: string)
|
|
|
137
137
|
const buildInfoFiles: BuildInfoFile[] = [];
|
|
138
138
|
|
|
139
139
|
for (const buildInfoFilePath of buildInfoFilePaths) {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
140
|
+
const buildInfo = await loadBuildInfo(buildInfoFilePath);
|
|
141
|
+
|
|
142
|
+
checkOutputSelection(buildInfo.input, buildInfoFilePath);
|
|
143
|
+
|
|
144
|
+
buildInfoFiles.push({
|
|
145
|
+
input: buildInfo.input,
|
|
146
|
+
output: buildInfo.output,
|
|
147
|
+
solcVersion: buildInfo.solcVersion,
|
|
148
|
+
dirShortName,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return buildInfoFiles;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function loadBuildInfo(buildInfoFilePath: string): Promise<{
|
|
155
|
+
input: SolcInput;
|
|
156
|
+
output: SolcOutput;
|
|
157
|
+
solcVersion: string;
|
|
158
|
+
}> {
|
|
159
|
+
const buildInfoJson = await readJSON(buildInfoFilePath);
|
|
160
|
+
|
|
161
|
+
if (
|
|
162
|
+
buildInfoJson.input !== undefined &&
|
|
163
|
+
buildInfoJson.output !== undefined &&
|
|
164
|
+
buildInfoJson.solcVersion !== undefined
|
|
165
|
+
) {
|
|
166
|
+
return {
|
|
167
|
+
input: buildInfoJson.input,
|
|
168
|
+
output: buildInfoJson.output,
|
|
169
|
+
solcVersion: buildInfoJson.solcVersion,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const format = buildInfoJson._format as string | undefined;
|
|
174
|
+
|
|
175
|
+
if (
|
|
176
|
+
typeof format === 'string' &&
|
|
177
|
+
(format.startsWith('hh3-sol-build-info') || format.startsWith('hh-sol-build-info'))
|
|
178
|
+
) {
|
|
179
|
+
if (buildInfoJson.input !== undefined && buildInfoJson.solcVersion !== undefined) {
|
|
180
|
+
let inputData: SolcInput = buildInfoJson.input;
|
|
181
|
+
let outputData: SolcOutput | undefined = buildInfoJson.output;
|
|
182
|
+
|
|
183
|
+
if (outputData === undefined) {
|
|
184
|
+
const { dir, name } = path.parse(buildInfoFilePath);
|
|
185
|
+
const outputFilePath = path.join(dir, `${name}.output.json`);
|
|
151
186
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
187
|
+
try {
|
|
188
|
+
const outputJson = await readJSON(outputFilePath);
|
|
189
|
+
outputData = outputJson.output ?? outputJson;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw new ValidateCommandError(
|
|
192
|
+
`Build info file ${buildInfoFilePath} does not contain output, and output file ${outputFilePath} could not be read.`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (outputData === undefined) {
|
|
197
|
+
throw new ValidateCommandError(
|
|
198
|
+
`Build info file ${buildInfoFilePath} does not contain output, and output file ${outputFilePath} is missing Solidity compiler output.`,
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const userSourceNameMap: Record<string, string> | undefined = buildInfoJson.userSourceNameMap;
|
|
204
|
+
if (userSourceNameMap !== undefined) {
|
|
205
|
+
const canonicalToUser: Record<string, string> = {};
|
|
206
|
+
for (const [userSource, canonicalSource] of Object.entries(userSourceNameMap)) {
|
|
207
|
+
canonicalToUser[canonicalSource] = userSource;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (inputData.sources !== undefined) {
|
|
211
|
+
inputData = {
|
|
212
|
+
...inputData,
|
|
213
|
+
sources: remapKeys(inputData.sources, canonicalToUser),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (outputData.sources !== undefined) {
|
|
218
|
+
outputData = {
|
|
219
|
+
...outputData,
|
|
220
|
+
sources: remapKeys(outputData.sources, canonicalToUser),
|
|
221
|
+
contracts:
|
|
222
|
+
outputData.contracts !== undefined
|
|
223
|
+
? remapKeys(outputData.contracts, canonicalToUser)
|
|
224
|
+
: outputData.contracts,
|
|
225
|
+
};
|
|
226
|
+
} else if (outputData.contracts !== undefined) {
|
|
227
|
+
outputData = {
|
|
228
|
+
...outputData,
|
|
229
|
+
contracts: remapKeys(outputData.contracts, canonicalToUser),
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
input: inputData,
|
|
236
|
+
output: outputData,
|
|
155
237
|
solcVersion: buildInfoJson.solcVersion,
|
|
156
|
-
|
|
157
|
-
});
|
|
238
|
+
};
|
|
158
239
|
}
|
|
159
240
|
}
|
|
160
|
-
|
|
241
|
+
|
|
242
|
+
throw new ValidateCommandError(
|
|
243
|
+
`Build info file ${buildInfoFilePath} must contain Solidity compiler input, output, and solcVersion. Got format: ${format ?? 'unknown'}.`,
|
|
244
|
+
);
|
|
161
245
|
}
|
|
162
246
|
|
|
163
247
|
/**
|
|
164
248
|
* Gives an error if there is empty output selection for any contract, or a contract does not have storage layout.
|
|
165
249
|
*/
|
|
166
|
-
function checkOutputSelection(
|
|
167
|
-
const
|
|
250
|
+
function checkOutputSelection(input: SolcInput, buildInfoFilePath: string) {
|
|
251
|
+
const outputSelection = input.settings?.outputSelection;
|
|
168
252
|
|
|
169
|
-
|
|
170
|
-
|
|
253
|
+
if (outputSelection === undefined) {
|
|
254
|
+
throw new ValidateCommandError(
|
|
255
|
+
`Build info file ${buildInfoFilePath} does not define compiler outputSelection.`,
|
|
256
|
+
() => STORAGE_LAYOUT_HELP,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Object.keys(outputSelection).forEach(item => {
|
|
261
|
+
const selection = outputSelection[item] ?? {};
|
|
262
|
+
const unnamed = Array.isArray(selection['']) ? selection[''] : [];
|
|
263
|
+
const wildcard = Array.isArray(selection['*']) ? selection['*'] : [];
|
|
264
|
+
|
|
265
|
+
if (unnamed.length === 0 && wildcard.length === 0) {
|
|
171
266
|
// No outputs at all for this contract e.g. if there were no changes since the last compile in Foundry.
|
|
172
267
|
// This is not supported for now, since it leads to AST nodes that reference node ids in other build-info files.
|
|
173
268
|
throw new ValidateCommandError(
|
|
174
269
|
`Build info file ${buildInfoFilePath} is not from a full compilation.`,
|
|
175
270
|
() => PARTIAL_COMPILE_HELP,
|
|
176
271
|
);
|
|
177
|
-
} else if (!
|
|
272
|
+
} else if (!wildcard.includes('storageLayout')) {
|
|
178
273
|
throw new ValidateCommandError(
|
|
179
274
|
`Build info file ${buildInfoFilePath} does not contain storage layout for all contracts.`,
|
|
180
275
|
() => STORAGE_LAYOUT_HELP,
|
|
@@ -186,3 +281,12 @@ function checkOutputSelection(buildInfoJson: any, buildInfoFilePath: string) {
|
|
|
186
281
|
async function readJSON(path: string) {
|
|
187
282
|
return JSON.parse(await fs.readFile(path, 'utf8'));
|
|
188
283
|
}
|
|
284
|
+
|
|
285
|
+
function remapKeys<T>(original: Record<string, T>, canonicalToUser: Record<string, string>): Record<string, T> {
|
|
286
|
+
const remapped: Record<string, T> = {};
|
|
287
|
+
for (const [key, value] of Object.entries(original)) {
|
|
288
|
+
const mappedKey = canonicalToUser[key] ?? key;
|
|
289
|
+
remapped[mappedKey] = value;
|
|
290
|
+
}
|
|
291
|
+
return remapped;
|
|
292
|
+
}
|
package/src/impl-address.ts
CHANGED
|
@@ -20,13 +20,18 @@ export class InvalidBeacon extends UpgradesError {}
|
|
|
20
20
|
* @throws {InvalidBeacon} If the implementation() function could not be called or does not return an address.
|
|
21
21
|
*/
|
|
22
22
|
export async function getImplementationAddressFromBeacon(
|
|
23
|
-
provider: EthereumProvider,
|
|
23
|
+
provider: EthereumProvider, // v2 may differ from v3
|
|
24
24
|
beaconAddress: string,
|
|
25
25
|
): Promise<string> {
|
|
26
26
|
const impl = await callOptionalSignature(provider, beaconAddress, 'implementation()');
|
|
27
|
+
|
|
27
28
|
let parsedImplAddress;
|
|
28
29
|
if (impl !== undefined) {
|
|
29
|
-
|
|
30
|
+
try {
|
|
31
|
+
parsedImplAddress = parseAddress(impl);
|
|
32
|
+
} catch (parseErr) {
|
|
33
|
+
throw new InvalidBeacon(`Contract at ${beaconAddress} doesn't look like a beacon`);
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
if (parsedImplAddress === undefined) {
|