From 6d2eb7a8f44998f8094b58b7daa23c164d9a6522 Mon Sep 17 00:00:00 2001 From: Alex Kit Date: Wed, 22 Nov 2023 14:55:30 +0100 Subject: [PATCH] fix (StorageDump) pass the contract name --- dequanto | 2 +- lib/0xweb.js | 29 ++++++++++++++++++++++++++--- lib/cli.js | 29 ++++++++++++++++++++++++++--- src/services/ContractDumpService.ts | 3 ++- src/services/PackageService.ts | 1 + 5 files changed, 56 insertions(+), 8 deletions(-) diff --git a/dequanto b/dequanto index 12e266b..5af1e27 160000 --- a/dequanto +++ b/dequanto @@ -1 +1 @@ -Subproject commit 12e266b7c2cfe3340e2552059be927edf482b149 +Subproject commit 5af1e27b473559c0612024c5bf05b531c69ed0be diff --git a/lib/0xweb.js b/lib/0xweb.js index b353476..a7b5ca7 100644 --- a/lib/0xweb.js +++ b/lib/0xweb.js @@ -10421,6 +10421,9 @@ var Ast; if (isNumberLiteral(node)) { return node.number; } + if (isStringLiteral(node)) { + return `"${node.value?.replace(/"/g, '\\"')}"`; + } throw new Error(`Unknown node ${JSON.stringify(node)}`); } Ast.serialize = serialize; @@ -10526,7 +10529,11 @@ var Ast; return a >> b; } } - throw new Error(`Unknown node ${JSON.stringify(node)}`); + if (isStringLiteral(node)) { + return node.value; + } + console.error(`Skip unknown node ${JSON.stringify(node)}`); + return null; } Ast.evaluate = evaluate; })(Ast = exports.Ast || (exports.Ast = {})); @@ -33860,7 +33867,13 @@ var BlockChainExplorerFactory; } if (_address_1.$address.isEmpty(uint256Hex) === false) { let hex = _address_1.$address.fromBytes32(uint256Hex); - return this.getContractAbi(hex); + try { + return await this.getContractAbi(hex); + } + catch (err) { + err.message += `. Proxy ${hex}`; + throw err; + } } } if (hasImplementationSlot(abiJson)) { @@ -43857,6 +43870,7 @@ class PackageService { platformPkgs[pkg.address] = { name: pkg.name, main: pkg.main, + contractName: pkg.contractName, implementation: pkg.implementation }; } @@ -46054,6 +46068,7 @@ class MappingKeysLoader { _require_1.$require.Address(params?.address); this.address = params.address; this.implementation = params.implementation; + this.contractName = params.contractName; this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth'); this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform); this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer); @@ -46095,6 +46110,7 @@ class MappingKeysLoader { } async loadSourceCode() { let source = await this.sourceCodeProvider.getSourceCode({ + contractName: this.contractName, address: this.address, implementation: this.implementation, }); @@ -46175,6 +46191,7 @@ class SlotsDump { _require_1.$require.Address(params?.address); this.address = params.address; this.implementation = params.implementation; + this.contractName = params.contractName; this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth'); this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform); this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer); @@ -46182,6 +46199,7 @@ class SlotsDump { this.keysLoader = new MappingKeysLoader_1.MappingKeysLoader({ address: this.address, implementation: this.implementation, + contractName: this.contractName, client: this.client, explorer: this.explorer, logger: this.logger, @@ -46235,6 +46253,7 @@ class SlotsDump { let sources = await this.sourceCodeProvider.getSourceCode({ address: this.address, implementation: this.implementation, + contractName: this.contractName, sources: this.params.sources?.files }); let slots = await SlotsParser_1.SlotsParser.slots({ @@ -46281,6 +46300,9 @@ class BatchLoader { this.isBusy = false; } getStorageAt(slot) { + if (slot in this.queueHash) { + return this.queueHash[slot]; + } let dfr = new atma_utils_1.class_Dfr(); this.total++; this.queueArr.push(slot); @@ -46377,12 +46399,13 @@ class ContractDumpService { this.app = app; } async dump(nameOrAddress, params) { - let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params); + let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params); _require_1.$require.String(_output, 'Output file not defined'); _require_1.$require.notNull(this.app.chain, `--chain not specified`); let dump = new SlotsDump_1.SlotsDump({ address: _address, implementation: _implementation, + contractName: _contractName, client: this.app.chain.client, explorer: this.app.chain.explorer, fields: params.fields?.split(',').map(x => x.trim()), diff --git a/lib/cli.js b/lib/cli.js index 0b633d5..39600e7 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -10431,6 +10431,9 @@ var Ast; if (isNumberLiteral(node)) { return node.number; } + if (isStringLiteral(node)) { + return `"${node.value?.replace(/"/g, '\\"')}"`; + } throw new Error(`Unknown node ${JSON.stringify(node)}`); } Ast.serialize = serialize; @@ -10536,7 +10539,11 @@ var Ast; return a >> b; } } - throw new Error(`Unknown node ${JSON.stringify(node)}`); + if (isStringLiteral(node)) { + return node.value; + } + console.error(`Skip unknown node ${JSON.stringify(node)}`); + return null; } Ast.evaluate = evaluate; })(Ast = exports.Ast || (exports.Ast = {})); @@ -33870,7 +33877,13 @@ var BlockChainExplorerFactory; } if (_address_1.$address.isEmpty(uint256Hex) === false) { let hex = _address_1.$address.fromBytes32(uint256Hex); - return this.getContractAbi(hex); + try { + return await this.getContractAbi(hex); + } + catch (err) { + err.message += `. Proxy ${hex}`; + throw err; + } } } if (hasImplementationSlot(abiJson)) { @@ -43867,6 +43880,7 @@ class PackageService { platformPkgs[pkg.address] = { name: pkg.name, main: pkg.main, + contractName: pkg.contractName, implementation: pkg.implementation }; } @@ -46064,6 +46078,7 @@ class MappingKeysLoader { _require_1.$require.Address(params?.address); this.address = params.address; this.implementation = params.implementation; + this.contractName = params.contractName; this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth'); this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform); this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer); @@ -46105,6 +46120,7 @@ class MappingKeysLoader { } async loadSourceCode() { let source = await this.sourceCodeProvider.getSourceCode({ + contractName: this.contractName, address: this.address, implementation: this.implementation, }); @@ -46185,6 +46201,7 @@ class SlotsDump { _require_1.$require.Address(params?.address); this.address = params.address; this.implementation = params.implementation; + this.contractName = params.contractName; this.client = params.client ?? Web3ClientFactory_1.Web3ClientFactory.get(params.platform ?? 'eth'); this.explorer = params.explorer ?? BlockChainExplorerProvider_1.BlockChainExplorerProvider.get(this.client.platform); this.sourceCodeProvider = params.sourceCodeProvider ?? new SourceCodeProvider_1.SourceCodeProvider(this.client, this.explorer); @@ -46192,6 +46209,7 @@ class SlotsDump { this.keysLoader = new MappingKeysLoader_1.MappingKeysLoader({ address: this.address, implementation: this.implementation, + contractName: this.contractName, client: this.client, explorer: this.explorer, logger: this.logger, @@ -46245,6 +46263,7 @@ class SlotsDump { let sources = await this.sourceCodeProvider.getSourceCode({ address: this.address, implementation: this.implementation, + contractName: this.contractName, sources: this.params.sources?.files }); let slots = await SlotsParser_1.SlotsParser.slots({ @@ -46291,6 +46310,9 @@ class BatchLoader { this.isBusy = false; } getStorageAt(slot) { + if (slot in this.queueHash) { + return this.queueHash[slot]; + } let dfr = new atma_utils_1.class_Dfr(); this.total++; this.queueArr.push(slot); @@ -46387,12 +46409,13 @@ class ContractDumpService { this.app = app; } async dump(nameOrAddress, params) { - let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params); + let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params); _require_1.$require.String(_output, 'Output file not defined'); _require_1.$require.notNull(this.app.chain, `--chain not specified`); let dump = new SlotsDump_1.SlotsDump({ address: _address, implementation: _implementation, + contractName: _contractName, client: this.app.chain.client, explorer: this.app.chain.explorer, fields: params.fields?.split(',').map(x => x.trim()), diff --git a/src/services/ContractDumpService.ts b/src/services/ContractDumpService.ts index 1bd4874..d3001d4 100644 --- a/src/services/ContractDumpService.ts +++ b/src/services/ContractDumpService.ts @@ -28,7 +28,7 @@ export class ContractDumpService { async dump (nameOrAddress: string | TAddress, params: IContractDumpServiceParams) { - let { _address, _output, _implementation, _sources } = await this.getContractData(nameOrAddress, params); + let { _address, _output, _implementation, _sources, _contractName } = await this.getContractData(nameOrAddress, params); $require.String(_output, 'Output file not defined'); $require.notNull(this.app.chain, `--chain not specified`); @@ -36,6 +36,7 @@ export class ContractDumpService { let dump = new SlotsDump({ address: _address, implementation: _implementation, + contractName: _contractName, client: this.app.chain.client, explorer: this.app.chain.explorer, fields: params.fields?.split(',').map(x => x.trim()), diff --git a/src/services/PackageService.ts b/src/services/PackageService.ts index 7496347..8e42c84 100644 --- a/src/services/PackageService.ts +++ b/src/services/PackageService.ts @@ -69,6 +69,7 @@ export class PackageService { platformPkgs[pkg.address] = { name: pkg.name, main: pkg.main, + contractName: pkg.contractName, implementation: pkg.implementation }; } else {