dequanto 0.1.39 → 0.1.45
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/lib/cjs/clients/ClientPool.js +23 -2
- package/lib/cjs/clients/ClientPool.js.map +1 -1
- package/lib/cjs/clients/WalletClient.js +98 -0
- package/lib/cjs/clients/WalletClient.js.map +1 -0
- package/lib/cjs/clients/Web3Client.js +39 -10
- package/lib/cjs/clients/Web3Client.js.map +1 -1
- package/lib/cjs/clients/Web3ClientFactory.js +7 -37
- package/lib/cjs/clients/Web3ClientFactory.js.map +1 -1
- package/lib/cjs/config/Config.js +4 -1
- package/lib/cjs/config/Config.js.map +1 -1
- package/lib/cjs/config/ConfigDefaults.js +3 -6
- package/lib/cjs/config/ConfigDefaults.js.map +1 -1
- package/lib/cjs/config/ConfigProvider.js +5 -1
- package/lib/cjs/config/ConfigProvider.js.map +1 -1
- package/lib/cjs/contracts/ContractWriter.js.map +1 -1
- package/lib/cjs/contracts/deploy/storage/DeploymentsStorage.js +10 -1
- package/lib/cjs/contracts/deploy/storage/DeploymentsStorage.js.map +1 -1
- package/lib/cjs/explorer/BlockchainExplorer.js +65 -43
- package/lib/cjs/explorer/BlockchainExplorer.js.map +1 -1
- package/lib/cjs/explorer/BlockchainExplorerFactory.js +6 -4
- package/lib/cjs/explorer/BlockchainExplorerFactory.js.map +1 -1
- package/lib/cjs/explorer/verifiers/FsHtmlVerifier.js +5 -5
- package/lib/cjs/explorer/verifiers/FsHtmlVerifier.js.map +1 -1
- package/lib/cjs/json/JsonArrayMultiStore.js.map +1 -1
- package/lib/cjs/json/JsonArrayStore.js +1 -1
- package/lib/cjs/json/JsonArrayStore.js.map +1 -1
- package/lib/cjs/json/JsonObjectStore.js +2 -1
- package/lib/cjs/json/JsonObjectStore.js.map +1 -1
- package/lib/cjs/json/JsonStoreFs.js +84 -18
- package/lib/cjs/json/JsonStoreFs.js.map +1 -1
- package/lib/cjs/models/TChain.js +4 -0
- package/lib/cjs/models/TChain.js.map +1 -0
- package/lib/cjs/models/TExplorer.js +4 -0
- package/lib/cjs/models/TExplorer.js.map +1 -0
- package/lib/cjs/models/TPlatform.js +1 -0
- package/lib/cjs/models/TPlatform.js.map +1 -1
- package/lib/cjs/rpc/transports/ITransport.js.map +1 -1
- package/lib/cjs/rpc/transports/RpcTransport.js +4 -0
- package/lib/cjs/rpc/transports/RpcTransport.js.map +1 -1
- package/lib/cjs/rpc/transports/compatibility/EIP1193Transport.js +14 -2
- package/lib/cjs/rpc/transports/compatibility/EIP1193Transport.js.map +1 -1
- package/lib/cjs/rpc/transports/compatibility/IEIP6963Provider.js +4 -0
- package/lib/cjs/rpc/transports/compatibility/IEIP6963Provider.js.map +1 -0
- package/lib/cjs/safe/GnosisSafeHandler.js.map +1 -1
- package/lib/cjs/tokens/TokenProviders/TPChain.js +5 -1
- package/lib/cjs/tokens/TokenProviders/TPChain.js.map +1 -1
- package/lib/cjs/txs/TxWriter.js +8 -1
- package/lib/cjs/txs/TxWriter.js.map +1 -1
- package/lib/cjs/utils/$buffer.js.map +1 -1
- package/lib/cjs/utils/$config.js +67 -2
- package/lib/cjs/utils/$config.js.map +1 -1
- package/lib/cjs/utils/$dependency.js +4 -0
- package/lib/cjs/utils/$dependency.js.map +1 -1
- package/lib/cjs/utils/$path.js +9 -0
- package/lib/cjs/utils/$path.js.map +1 -1
- package/lib/cjs/utils/$ref.js +30 -0
- package/lib/cjs/utils/$ref.js.map +1 -0
- package/lib/cjs/utils/$secret.js +15 -2
- package/lib/cjs/utils/$secret.js.map +1 -1
- package/lib/cjs/utils/$sig.js +18 -9
- package/lib/cjs/utils/$sig.js.map +1 -1
- package/lib/cjs/wallets/EIP6963ProviderFactory.js +192 -0
- package/lib/cjs/wallets/EIP6963ProviderFactory.js.map +1 -0
- package/lib/cjs/wallets/Signer.js +30 -0
- package/lib/cjs/wallets/Signer.js.map +1 -0
- package/lib/esm/clients/ClientPool.js.map +1 -1
- package/lib/esm/clients/ClientPool.mjs +23 -2
- package/lib/esm/clients/WalletClient.js.map +1 -0
- package/lib/esm/clients/WalletClient.mjs +91 -0
- package/lib/esm/clients/Web3Client.js.map +1 -1
- package/lib/esm/clients/Web3Client.mjs +39 -10
- package/lib/esm/clients/Web3ClientFactory.js.map +1 -1
- package/lib/esm/clients/Web3ClientFactory.mjs +7 -37
- package/lib/esm/config/Config.js.map +1 -1
- package/lib/esm/config/Config.mjs +4 -1
- package/lib/esm/config/ConfigDefaults.js.map +1 -1
- package/lib/esm/config/ConfigDefaults.mjs +3 -6
- package/lib/esm/config/ConfigProvider.js.map +1 -1
- package/lib/esm/config/ConfigProvider.mjs +5 -1
- package/lib/esm/contracts/ContractWriter.js.map +1 -1
- package/lib/esm/contracts/deploy/storage/DeploymentsStorage.js.map +1 -1
- package/lib/esm/contracts/deploy/storage/DeploymentsStorage.mjs +10 -1
- package/lib/esm/explorer/BlockchainExplorer.js.map +1 -1
- package/lib/esm/explorer/BlockchainExplorer.mjs +65 -43
- package/lib/esm/explorer/BlockchainExplorerFactory.js.map +1 -1
- package/lib/esm/explorer/BlockchainExplorerFactory.mjs +6 -4
- package/lib/esm/explorer/verifiers/FsHtmlVerifier.js.map +1 -1
- package/lib/esm/explorer/verifiers/FsHtmlVerifier.mjs +5 -5
- package/lib/esm/json/JsonArrayMultiStore.js.map +1 -1
- package/lib/esm/json/JsonArrayStore.js.map +1 -1
- package/lib/esm/json/JsonArrayStore.mjs +1 -1
- package/lib/esm/json/JsonObjectStore.js.map +1 -1
- package/lib/esm/json/JsonObjectStore.mjs +2 -1
- package/lib/esm/json/JsonStoreFs.js.map +1 -1
- package/lib/esm/json/JsonStoreFs.mjs +84 -18
- package/lib/esm/models/TChain.js.map +1 -0
- package/lib/esm/models/TChain.mjs +3 -0
- package/lib/esm/models/TExplorer.js.map +1 -0
- package/lib/esm/models/TExplorer.mjs +3 -0
- package/lib/esm/models/TPlatform.js.map +1 -1
- package/lib/esm/models/TPlatform.mjs +1 -0
- package/lib/esm/rpc/transports/ITransport.js.map +1 -1
- package/lib/esm/rpc/transports/RpcTransport.js.map +1 -1
- package/lib/esm/rpc/transports/RpcTransport.mjs +4 -0
- package/lib/esm/rpc/transports/compatibility/EIP1193Transport.js.map +1 -1
- package/lib/esm/rpc/transports/compatibility/EIP1193Transport.mjs +14 -2
- package/lib/esm/rpc/transports/compatibility/IEIP6963Provider.js.map +1 -0
- package/lib/esm/rpc/transports/compatibility/IEIP6963Provider.mjs +3 -0
- package/lib/esm/safe/GnosisSafeHandler.js.map +1 -1
- package/lib/esm/tokens/TokenProviders/TPChain.js.map +1 -1
- package/lib/esm/tokens/TokenProviders/TPChain.mjs +5 -1
- package/lib/esm/txs/TxWriter.js.map +1 -1
- package/lib/esm/txs/TxWriter.mjs +8 -1
- package/lib/esm/utils/$buffer.js.map +1 -1
- package/lib/esm/utils/$config.js.map +1 -1
- package/lib/esm/utils/$config.mjs +64 -2
- package/lib/esm/utils/$dependency.js.map +1 -1
- package/lib/esm/utils/$dependency.mjs +4 -0
- package/lib/esm/utils/$path.js.map +1 -1
- package/lib/esm/utils/$path.mjs +9 -0
- package/lib/esm/utils/$ref.js.map +1 -0
- package/lib/esm/utils/$ref.mjs +27 -0
- package/lib/esm/utils/$secret.js.map +1 -1
- package/lib/esm/utils/$secret.mjs +15 -2
- package/lib/esm/utils/$sig.js.map +1 -1
- package/lib/esm/utils/$sig.mjs +18 -9
- package/lib/esm/wallets/EIP6963ProviderFactory.js.map +1 -0
- package/lib/esm/wallets/EIP6963ProviderFactory.mjs +185 -0
- package/lib/esm/wallets/Signer.js.map +1 -0
- package/lib/esm/wallets/Signer.mjs +26 -0
- package/lib/types/clients/ClientPool.d.ts +13 -5
- package/lib/types/clients/WalletClient.d.ts +28 -0
- package/lib/types/clients/Web3Client.d.ts +7 -4
- package/lib/types/clients/Web3ClientFactory.d.ts +1 -1
- package/lib/types/clients/interfaces/IWeb3Client.d.ts +2 -5
- package/lib/types/config/AConfigBase.d.ts +0 -7
- package/lib/types/config/interface/IConfigData.d.ts +5 -2
- package/lib/types/explorer/BlockchainExplorer.d.ts +7 -4
- package/lib/types/explorer/BlockchainExplorerFactory.d.ts +7 -3
- package/lib/types/explorer/verifiers/FsHtmlVerifier.d.ts +3 -3
- package/lib/types/json/JsonArrayMultiStore.d.ts +2 -2
- package/lib/types/json/JsonArrayStore.d.ts +4 -3
- package/lib/types/json/JsonObjectStore.d.ts +5 -3
- package/lib/types/json/JsonStoreFs.d.ts +3 -2
- package/lib/types/models/TAccount.d.ts +9 -0
- package/lib/types/models/TChain.d.ts +45 -0
- package/lib/types/models/TEth.d.ts +8 -0
- package/lib/types/models/TExplorer.d.ts +31 -0
- package/lib/types/rpc/transports/ITransport.d.ts +2 -1
- package/lib/types/rpc/transports/compatibility/EIP1193Transport.d.ts +5 -1
- package/lib/types/rpc/transports/compatibility/IEIP6963Provider.d.ts +21 -0
- package/lib/types/utils/$config.d.ts +5 -0
- package/lib/types/utils/$ref.d.ts +11 -0
- package/lib/types/utils/$secret.d.ts +1 -0
- package/lib/types/utils/$sig.d.ts +1 -0
- package/lib/types/wallets/EIP6963ProviderFactory.d.ts +47 -0
- package/lib/types/wallets/Signer.d.ts +15 -0
- package/package.json +1 -1
- package/src/clients/ClientPool.ts +49 -15
- package/src/clients/WalletClient.ts +115 -0
- package/src/clients/Web3Client.ts +47 -16
- package/src/clients/Web3ClientFactory.ts +8 -39
- package/src/clients/interfaces/IWeb3Client.ts +2 -7
- package/src/config/AConfigBase.ts +3 -11
- package/src/config/Config.ts +6 -1
- package/src/config/ConfigDefaults.ts +3 -6
- package/src/config/ConfigProvider.ts +5 -1
- package/src/config/interface/IConfigData.ts +9 -4
- package/src/contracts/ContractWriter.ts +1 -0
- package/src/contracts/deploy/storage/DeploymentsStorage.ts +13 -3
- package/src/explorer/BlockchainExplorer.ts +82 -51
- package/src/explorer/BlockchainExplorerFactory.ts +19 -6
- package/src/explorer/verifiers/FsHtmlVerifier.ts +8 -8
- package/src/json/JsonArrayMultiStore.ts +2 -2
- package/src/json/JsonArrayStore.ts +5 -2
- package/src/json/JsonObjectStore.ts +7 -4
- package/src/json/JsonStoreFs.ts +103 -18
- package/src/models/TAccount.ts +10 -2
- package/src/models/TChain.ts +56 -0
- package/src/models/TEth.ts +9 -3
- package/src/models/TExplorer.ts +35 -0
- package/src/models/TPlatform.ts +1 -0
- package/src/rpc/transports/ITransport.ts +2 -1
- package/src/rpc/transports/RpcTransport.ts +4 -0
- package/src/rpc/transports/compatibility/EIP1193Transport.ts +19 -6
- package/src/rpc/transports/compatibility/IEIP6963Provider.ts +22 -0
- package/src/safe/GnosisSafeHandler.ts +1 -1
- package/src/tokens/TokenProviders/TPChain.ts +5 -1
- package/src/txs/TxWriter.ts +8 -2
- package/src/utils/$buffer.ts +1 -1
- package/src/utils/$config.ts +73 -2
- package/src/utils/$dependency.ts +5 -0
- package/src/utils/$path.ts +9 -0
- package/src/utils/$ref.ts +40 -0
- package/src/utils/$secret.ts +16 -3
- package/src/utils/$sig.ts +19 -10
- package/src/wallets/EIP6963ProviderFactory.ts +252 -0
- package/src/wallets/Signer.ts +32 -0
- package/lib/cjs/wallets/WalletBsc.js +0 -19
- package/lib/cjs/wallets/WalletBsc.js.map +0 -1
- package/lib/esm/wallets/WalletBsc.js.map +0 -1
- package/lib/esm/wallets/WalletBsc.mjs +0 -12
- package/lib/types/wallets/WalletBsc.d.ts +0 -10
- package/src/wallets/WalletBsc.ts +0 -13
|
@@ -233,14 +233,13 @@ export class DeploymentsStorage {
|
|
|
233
233
|
path = class_Uri.combine(directory, `${filenamePrefix}${platformPathNormalized}-${upstreamPlatformNormalized}.json`);
|
|
234
234
|
|
|
235
235
|
let upstreamDeploymentExists = await File.existsAsync(upstreamDeploymentsPath);
|
|
236
|
-
|
|
236
|
+
let upstreamDeployments: IDeployment[];
|
|
237
237
|
let shouldCopy = true;
|
|
238
238
|
if (await File.existsAsync(path)) {
|
|
239
239
|
// forked deployments path already exists, check if stale
|
|
240
240
|
let blockNumber = await this.client.getBlockNumber();
|
|
241
241
|
if (upstreamDeploymentExists) {
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
upstreamDeployments = await File.readAsync<IDeployment[]>(upstreamDeploymentsPath);
|
|
244
243
|
// 1. Check if the original(upstream) network has more recent deployments
|
|
245
244
|
let hasNewDeployments = upstreamDeployments.some(x => x.block > blockNumber);
|
|
246
245
|
shouldCopy = hasNewDeployments;
|
|
@@ -248,6 +247,8 @@ export class DeploymentsStorage {
|
|
|
248
247
|
shouldCopy = false;
|
|
249
248
|
}
|
|
250
249
|
|
|
250
|
+
|
|
251
|
+
|
|
251
252
|
if (shouldCopy === false) {
|
|
252
253
|
let deployments = await File.readAsync<IDeployment[]>(path);
|
|
253
254
|
// 2. Always copy if forked deployments are empty
|
|
@@ -271,6 +272,15 @@ export class DeploymentsStorage {
|
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
274
|
}
|
|
275
|
+
if (shouldCopy === false && upstreamDeployments?.length > 0) {
|
|
276
|
+
// 5. Just-in-case, if there are upstream deployments with lower block number, as the current HEAD, but not in the current forked network
|
|
277
|
+
let deploymentIds = alot(deployments).toDictionary(x => x.id);
|
|
278
|
+
let hasNewDeployments = upstreamDeployments
|
|
279
|
+
.filter(x => x.block <= blockNumber)
|
|
280
|
+
.some(x => x.id in deploymentIds === false)
|
|
281
|
+
|
|
282
|
+
shouldCopy = hasNewDeployments;
|
|
283
|
+
}
|
|
274
284
|
}
|
|
275
285
|
}
|
|
276
286
|
if (shouldCopy) {
|
|
@@ -10,7 +10,6 @@ import { TPlatform } from '@dequanto/models/TPlatform';
|
|
|
10
10
|
import { $address } from '@dequanto/utils/$address';
|
|
11
11
|
import { $require } from '@dequanto/utils/$require';
|
|
12
12
|
import { Web3ClientFactory } from '@dequanto/clients/Web3ClientFactory';
|
|
13
|
-
import { $config } from '@dequanto/utils/$config';
|
|
14
13
|
import { $str } from '@dequanto/solidity/utils/$str';
|
|
15
14
|
import { $platform } from '@dequanto/utils/$platform';
|
|
16
15
|
import type { TAbiItem } from '@dequanto/types/TAbi';
|
|
@@ -19,8 +18,10 @@ import { $is } from '@dequanto/utils/$is';
|
|
|
19
18
|
import { $http } from '@dequanto/utils/$http';
|
|
20
19
|
import { IVerifier } from './verifiers/IVerifier';
|
|
21
20
|
import { FsHtmlVerifier } from './verifiers/FsHtmlVerifier';
|
|
21
|
+
import { TExplorer, TExplorerDefinition } from '@dequanto/models/TExplorer';
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
/** @deprecated use TExplorerDefinition instead */
|
|
24
25
|
export interface IBlockchainExplorerConfig {
|
|
25
26
|
key?: string
|
|
26
27
|
api?: string
|
|
@@ -34,6 +35,7 @@ export interface IBlockchainExplorerConfig {
|
|
|
34
35
|
}[]
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/** @deprecated use TExplorerDefinition instead */
|
|
37
39
|
export interface IBlockchainExplorerFactoryParams extends IBlockchainExplorerConfig {
|
|
38
40
|
|
|
39
41
|
platform?: string
|
|
@@ -56,35 +58,65 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
56
58
|
|
|
57
59
|
|
|
58
60
|
inMemoryDb: IContractDetails[]
|
|
59
|
-
config: IBlockchainExplorerConfig;
|
|
60
61
|
fsVerification: IVerifier
|
|
61
|
-
opts: IBlockchainExplorerFactoryParams;
|
|
62
|
-
platform: TPlatform;
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
config: TExplorer
|
|
64
|
+
platform: TPlatform
|
|
65
|
+
// opts: IBlockchainExplorerFactoryParams;
|
|
67
66
|
|
|
68
|
-
|
|
69
|
-
? { platform: mix }
|
|
70
|
-
: mix;
|
|
67
|
+
getWeb3: (platform) => Web3Client
|
|
71
68
|
|
|
72
|
-
this.opts = ensureDefaults(opts);
|
|
73
|
-
this.config = opts.getConfig(this.platform)
|
|
74
|
-
this.inMemoryDb = this.opts.CONTRACTS ?? [];
|
|
75
|
-
this.platform =this.opts.platform;
|
|
76
69
|
|
|
77
|
-
|
|
70
|
+
constructor(config: TExplorerDefinition)
|
|
71
|
+
constructor(opts: IBlockchainExplorerFactoryParams)
|
|
72
|
+
constructor(mix: TExplorerDefinition | IBlockchainExplorerFactoryParams) {
|
|
73
|
+
|
|
74
|
+
$require.notNull(mix.platform, `BlockchainExplorer: Platform is required`);
|
|
75
|
+
|
|
76
|
+
let ABI_CACHE = mix.ABI_CACHE ?? `./cache/${$platform.toPath(mix.platform)}/abis.json`;
|
|
77
|
+
let CONTRACTS = mix.CONTRACTS ?? [];
|
|
78
|
+
|
|
79
|
+
let source = mix as TExplorerDefinition & IBlockchainExplorerFactoryParams;
|
|
80
|
+
let config = {
|
|
81
|
+
platform: mix.platform,
|
|
82
|
+
url: source.url ?? source.www ?? source.host,
|
|
83
|
+
api: (() => {
|
|
84
|
+
if (source.api == null) {
|
|
85
|
+
let host = source.url ?? source.host ?? source.www;
|
|
86
|
+
return {
|
|
87
|
+
url: `${host}/api`,
|
|
88
|
+
key: source.key
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (typeof source.api === 'string') {
|
|
92
|
+
return {
|
|
93
|
+
url: source.api,
|
|
94
|
+
key: source.key
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return source.api;
|
|
98
|
+
})(),
|
|
99
|
+
name: source.name ,
|
|
100
|
+
verification: source.verification ?? true,
|
|
101
|
+
standard: source.standard,
|
|
102
|
+
} satisfies TExplorer;
|
|
103
|
+
|
|
104
|
+
this.inMemoryDb = CONTRACTS ?? [];
|
|
105
|
+
this.config = config;
|
|
106
|
+
this.platform = config.platform;
|
|
107
|
+
this.getWeb3 = mix.getWeb3 ?? ((platform) => Web3ClientFactory.get(platform));
|
|
108
|
+
|
|
109
|
+
if ($str.isNullOrWhiteSpace(ABI_CACHE) === false) {
|
|
78
110
|
this.getContractAbi = memd.fn.memoize(this.getContractAbi, {
|
|
79
111
|
trackRef: true,
|
|
80
112
|
persistence: new memd.FsTransport({
|
|
81
|
-
path:
|
|
113
|
+
path: ABI_CACHE
|
|
82
114
|
})
|
|
83
115
|
});
|
|
84
116
|
this.getContractSource = memd.fn.memoize(this.getContractSource, {
|
|
85
117
|
trackRef: true,
|
|
86
118
|
persistence: new memd.FsTransport({
|
|
87
|
-
path:
|
|
119
|
+
path: ABI_CACHE.replace('.json', '-source.json')
|
|
88
120
|
})
|
|
89
121
|
});
|
|
90
122
|
}
|
|
@@ -101,8 +133,8 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
101
133
|
}
|
|
102
134
|
|
|
103
135
|
async getContractCreation(address: TAddress): Promise<{ creator: TAddress, txHash: TEth.Hex }> {
|
|
104
|
-
let apiUrl = this.config.api
|
|
105
|
-
let url = `${apiUrl}?module=contract&action=getcontractcreation&contractaddresses=${address}&apikey=${this.config.key}`;
|
|
136
|
+
let apiUrl = this.config.api.url;
|
|
137
|
+
let url = `${apiUrl}?module=contract&action=getcontractcreation&contractaddresses=${address}&apikey=${this.config.api.key}`;
|
|
106
138
|
let result = await this.client.get(url);
|
|
107
139
|
let json = Array.isArray(result) ? result[0] : result;
|
|
108
140
|
if (json == null) {
|
|
@@ -131,8 +163,8 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
131
163
|
return { abi: info.abi, implementation: address }
|
|
132
164
|
}
|
|
133
165
|
|
|
134
|
-
let apiUrl = this.config.api
|
|
135
|
-
let url = `${apiUrl}?module=contract&action=getabi&address=${address}&apikey=${this.config.key}`;
|
|
166
|
+
let apiUrl = this.config.api.url;
|
|
167
|
+
let url = `${apiUrl}?module=contract&action=getabi&address=${address}&apikey=${this.config.api.key}`;
|
|
136
168
|
let abi: string;
|
|
137
169
|
|
|
138
170
|
try {
|
|
@@ -149,7 +181,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
149
181
|
let abiJson = JSON.parse(abi);
|
|
150
182
|
if (params?.implementation) {
|
|
151
183
|
if ($is.HexBytes32(params.implementation)) {
|
|
152
|
-
let web3 = this.
|
|
184
|
+
let web3 = this.getWeb3(this.platform);
|
|
153
185
|
let uin256Hex = await web3.getStorageAt(
|
|
154
186
|
address,
|
|
155
187
|
params.implementation
|
|
@@ -160,7 +192,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
160
192
|
throw new Error(`Implement ${params.implementation} support`);
|
|
161
193
|
}
|
|
162
194
|
if (isOpenZeppelinProxy(abiJson) || mightBeProxy(abiJson)) {
|
|
163
|
-
let web3 = this.
|
|
195
|
+
let web3 = this.getWeb3(this.platform);
|
|
164
196
|
// (BigInt($contract.keccak256("eip1967.proxy.implementation")) - 1n).toString(16);
|
|
165
197
|
let uint256Hex = await web3.getStorageAt(address, `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`);
|
|
166
198
|
if ($address.isEmpty(uint256Hex)) {
|
|
@@ -179,7 +211,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
179
211
|
}
|
|
180
212
|
|
|
181
213
|
if (hasImplementationSlot(abiJson)) {
|
|
182
|
-
let web3 = this.
|
|
214
|
+
let web3 = this.getWeb3(this.platform);
|
|
183
215
|
let implAddress = await web3.readContract({
|
|
184
216
|
address: address,
|
|
185
217
|
abi: abiJson,
|
|
@@ -189,7 +221,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
189
221
|
return this.getContractAbi(implAddress);
|
|
190
222
|
}
|
|
191
223
|
if (hasTargetSlot(abiJson)) {
|
|
192
|
-
let web3 = this.
|
|
224
|
+
let web3 = this.getWeb3(this.platform);
|
|
193
225
|
let implAddress = await web3.readContract({
|
|
194
226
|
address: address,
|
|
195
227
|
abi: abiJson,
|
|
@@ -214,9 +246,9 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
214
246
|
}) {
|
|
215
247
|
await this.fsVerification.submitContractVerification(contractData);
|
|
216
248
|
|
|
217
|
-
let url = this.config.api
|
|
249
|
+
let url = this.config.api.url;
|
|
218
250
|
let body = {
|
|
219
|
-
apikey: this.config.key,
|
|
251
|
+
apikey: this.config.api.key,
|
|
220
252
|
module: 'contract',
|
|
221
253
|
action: 'verifysourcecode',
|
|
222
254
|
contractaddress: contractData.address,
|
|
@@ -240,9 +272,9 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
240
272
|
}
|
|
241
273
|
|
|
242
274
|
async checkContractVerificationSubmission(submission: { guid }) {
|
|
243
|
-
let url = this.config.api
|
|
275
|
+
let url = this.config.api.url;
|
|
244
276
|
let result = await this.client.get<string>(url, {
|
|
245
|
-
apikey: this.config.key,
|
|
277
|
+
apikey: this.config.api.key,
|
|
246
278
|
module: "contract",
|
|
247
279
|
action: "checkverifystatus",
|
|
248
280
|
guid: submission.guid
|
|
@@ -256,10 +288,10 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
256
288
|
}): Promise<string> {
|
|
257
289
|
await this.fsVerification.submitContractProxyVerification(contractData);
|
|
258
290
|
|
|
259
|
-
let url = this.config.api
|
|
291
|
+
let url = this.config.api.url;
|
|
260
292
|
let guid = await this.client.post(url, {
|
|
261
293
|
body: {
|
|
262
|
-
apikey: this.config.key,
|
|
294
|
+
apikey: this.config.api.key,
|
|
263
295
|
module: "contract",
|
|
264
296
|
action: "verifyproxycontract",
|
|
265
297
|
address: contractData.address,
|
|
@@ -269,9 +301,9 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
269
301
|
return guid;
|
|
270
302
|
}
|
|
271
303
|
async checkContractProxyVerificationSubmission(submission: { guid: any; }): Promise<string> {
|
|
272
|
-
let url = this.config.api
|
|
304
|
+
let url = this.config.api.url;
|
|
273
305
|
let result = await this.client.get<string>(url, {
|
|
274
|
-
apikey: this.config.key,
|
|
306
|
+
apikey: this.config.api.key,
|
|
275
307
|
module: "contract",
|
|
276
308
|
action: "checkproxyverification",
|
|
277
309
|
guid: submission.guid
|
|
@@ -292,8 +324,8 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
292
324
|
ContractName: string
|
|
293
325
|
ABI: string
|
|
294
326
|
}> {
|
|
295
|
-
let apiUrl = this.config.api
|
|
296
|
-
let url = `${apiUrl}?module=contract&action=getsourcecode&address=${address}&apikey=${this.config.key}`;
|
|
327
|
+
let apiUrl = this.config.api.url;
|
|
328
|
+
let url = `${apiUrl}?module=contract&action=getsourcecode&address=${address}&apikey=${this.config.api.key}`;
|
|
297
329
|
let result = await this.client.get(url);
|
|
298
330
|
let json = Array.isArray(result) ? result[0] : result;
|
|
299
331
|
|
|
@@ -400,7 +432,7 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
400
432
|
}
|
|
401
433
|
|
|
402
434
|
async getSimilarContract(address: TAddress) {
|
|
403
|
-
let url = `${this.config.
|
|
435
|
+
let url = `${this.config.url}/address/${address}#code`;
|
|
404
436
|
let html = await this.client.getHtml(url);
|
|
405
437
|
let rgx = /This contract matches/ig;
|
|
406
438
|
let match = rgx.exec(html);
|
|
@@ -426,8 +458,8 @@ export class BlockchainExplorer implements IBlockchainExplorer {
|
|
|
426
458
|
size?: number,
|
|
427
459
|
sort?: 'asc' | 'desc'
|
|
428
460
|
}) {
|
|
429
|
-
let apiUrl = this.config.api
|
|
430
|
-
let url = `${apiUrl}?module=account&action=${type}&address=${address}&sort=${params.sort ?? 'desc'}&apikey=${this.config.key}`;
|
|
461
|
+
let apiUrl = this.config.api.url;
|
|
462
|
+
let url = `${apiUrl}?module=account&action=${type}&address=${address}&sort=${params.sort ?? 'desc'}&apikey=${this.config.api.key}`;
|
|
431
463
|
if (params.fromBlockNumber != null) {
|
|
432
464
|
url += `&startblock=${params.fromBlockNumber}`
|
|
433
465
|
}
|
|
@@ -515,25 +547,24 @@ function hasMethod(abi: TAbiItem[], name: string) {
|
|
|
515
547
|
return abi.some(item => item.type === 'function' && item.name === name);
|
|
516
548
|
}
|
|
517
549
|
|
|
518
|
-
function ensureDefaults(opts:
|
|
519
|
-
opts ??= {};
|
|
550
|
+
function ensureDefaults(opts: TExplorerDefinition) {
|
|
520
551
|
|
|
521
552
|
let platform = opts.platform;
|
|
522
553
|
$require.notNull(platform, `Generic Blockchain Explorer Config should contain platform name`);
|
|
523
554
|
|
|
524
555
|
opts.ABI_CACHE ??= `./cache/${$platform.toPath(platform)}/abis.json`
|
|
525
556
|
opts.CONTRACTS ??= [];
|
|
526
|
-
opts.getWeb3 ??= (_) => {
|
|
527
|
-
|
|
528
|
-
};
|
|
529
|
-
opts.getConfig ??= () => {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
};
|
|
557
|
+
// opts.getWeb3 ??= (_) => {
|
|
558
|
+
// return Web3ClientFactory.get(platform);
|
|
559
|
+
// };
|
|
560
|
+
// opts.getConfig ??= () => {
|
|
561
|
+
// let config = $config.get(`blockchainExplorer.${platform}`);
|
|
562
|
+
|
|
563
|
+
// return {
|
|
564
|
+
// ...(config ?? {}),
|
|
565
|
+
// ...opts,
|
|
566
|
+
// };
|
|
567
|
+
// };
|
|
537
568
|
return opts;
|
|
538
569
|
}
|
|
539
570
|
|
|
@@ -4,6 +4,10 @@ import { BlockchainExplorer, IBlockchainExplorerConfig, IBlockchainExplorerFacto
|
|
|
4
4
|
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
5
5
|
import { $config } from '@dequanto/utils/$config';
|
|
6
6
|
import { Config } from '@dequanto/config/Config';
|
|
7
|
+
import { TExplorer, TExplorerDefinition } from '@dequanto/models/TExplorer';
|
|
8
|
+
import { IConfigData } from '@dequanto/config/interface/IConfigData';
|
|
9
|
+
import { TChain } from '@dequanto/models/TChain';
|
|
10
|
+
import { $require } from '@dequanto/utils/$require';
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
|
|
@@ -18,14 +22,23 @@ export namespace BlockchainExplorerFactory {
|
|
|
18
22
|
registry[platform] = explorer;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
export function get (platform: TPlatform |
|
|
25
|
+
export function get (platform: TPlatform | number)
|
|
26
|
+
export function get (config: TExplorerDefinition)
|
|
27
|
+
/** @obsolete */
|
|
28
|
+
export function get (platform: TPlatform | number, opts: IBlockchainExplorerFactoryParams)
|
|
29
|
+
export function get (mix: TPlatform | number | TExplorerDefinition, opts?: IBlockchainExplorerFactoryParams) {
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
$require.notNull(mix, `ArgumentException: no platform in BlockchainExplorerFactory`);
|
|
32
|
+
|
|
33
|
+
let platform = typeof mix === 'object' ? mix.platform : mix;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
let cfg = $config.getExplorerOptions(platform);
|
|
24
37
|
let params = {
|
|
25
|
-
platform ,
|
|
26
38
|
...(opts ?? {}),
|
|
27
|
-
...(cfg?? {})
|
|
28
|
-
};
|
|
39
|
+
...(cfg ?? {}),
|
|
40
|
+
} as any;
|
|
41
|
+
|
|
29
42
|
let Ctor = registry[platform];
|
|
30
43
|
if (Ctor != null) {
|
|
31
44
|
if (typeof Ctor === 'function') {
|
|
@@ -38,7 +51,7 @@ export namespace BlockchainExplorerFactory {
|
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
/** Same as sync variation, but ensures the config is being fetched */
|
|
41
|
-
export async function getAsync (platform: TPlatform
|
|
54
|
+
export async function getAsync (platform: TPlatform, opts?: IBlockchainExplorerFactoryParams) {
|
|
42
55
|
await Config.get();
|
|
43
56
|
return get(platform, opts);
|
|
44
57
|
}
|
|
@@ -5,7 +5,7 @@ import { IVerifier } from './IVerifier';
|
|
|
5
5
|
import { IBlockchainTransferEvent } from '../IBlockchainExplorer';
|
|
6
6
|
import { $platform } from '@dequanto/utils/$platform';
|
|
7
7
|
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
8
|
-
import {
|
|
8
|
+
import { TExplorer, TExplorerDefinition } from '@dequanto/models/TExplorer';
|
|
9
9
|
|
|
10
10
|
const PATH_ROOT = `./data/0xc/verification`;
|
|
11
11
|
const PATH_TEMPLATE = `${PATH_ROOT}/template.html`;
|
|
@@ -66,7 +66,7 @@ export class FsHtmlVerifier implements IVerifier {
|
|
|
66
66
|
private key: string;
|
|
67
67
|
private enabled: boolean;
|
|
68
68
|
|
|
69
|
-
constructor (public platform: TPlatform, public config:
|
|
69
|
+
constructor (public platform: TPlatform, public config: TExplorer) {
|
|
70
70
|
$require.notEmpty(platform, `Argument platform is required`);
|
|
71
71
|
$require.notNull(config, `Config is required for ${platform}`);
|
|
72
72
|
this.enabled = Boolean(config.api);
|
|
@@ -105,12 +105,12 @@ export class FsHtmlVerifier implements IVerifier {
|
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
let html = template
|
|
108
|
-
.replace('__host__', this.config.api)
|
|
108
|
+
.replace('__host__', this.config.api.url)
|
|
109
109
|
.replace('__name__', contractData.contractName)
|
|
110
110
|
.replace('__JSON__', contractData.sourceCode)
|
|
111
111
|
.replace('__contractaddress__', contractData.address)
|
|
112
112
|
.replace('__contractname__', contractData.contractName)
|
|
113
|
-
.replace('__apikey__', this.config.key ?? '')
|
|
113
|
+
.replace('__apikey__', this.config.api.key ?? '')
|
|
114
114
|
.replace('__constructorArguements__', contractData.arguments?.replace(/^0x/, '') || '');
|
|
115
115
|
|
|
116
116
|
|
|
@@ -162,9 +162,9 @@ export class FsHtmlVerifier implements IVerifier {
|
|
|
162
162
|
|
|
163
163
|
|
|
164
164
|
let html = template
|
|
165
|
-
.replace('__host__', this.config.api)
|
|
165
|
+
.replace('__host__', this.config.api.url)
|
|
166
166
|
.replace('__contractaddress__', contractData.address)
|
|
167
|
-
.replace('__apikey__', this.config.key ?? '')
|
|
167
|
+
.replace('__apikey__', this.config.api.key ?? '')
|
|
168
168
|
.replace('__expectedImplementation__', contractData.expectedImplementation ?? '')
|
|
169
169
|
;
|
|
170
170
|
|
|
@@ -197,8 +197,8 @@ export class FsHtmlVerifier implements IVerifier {
|
|
|
197
197
|
throw new Error('Method not implemented.');
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
private extractHostKey (config:
|
|
201
|
-
let hostKey = /\.(?<
|
|
200
|
+
private extractHostKey (config: TExplorer) {
|
|
201
|
+
let hostKey = /\.(?<hostKey>[\w\-]+)\.\w+($|\/)/.exec(config.api.url).groups.hostKey;
|
|
202
202
|
return hostKey;
|
|
203
203
|
}
|
|
204
204
|
private extractContractName (contractData: { address: `0x${string}`; contractName?: string; }, defaultPfx?: string) {
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Store data across multiple files for cases, that could contain thousands of entries
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { IArrayStoreOptions, JsonArrayStore } from './JsonArrayStore';
|
|
6
6
|
import { Directory } from 'atma-io';
|
|
7
7
|
import memd from 'memd';
|
|
8
8
|
import alot from 'alot';
|
|
9
9
|
import type { Alot } from 'alot/alot';
|
|
10
10
|
import { $require } from '@dequanto/utils/$require';
|
|
11
11
|
|
|
12
|
-
export interface IMultiStoreOptions<T> extends
|
|
12
|
+
export interface IMultiStoreOptions<T> extends IArrayStoreOptions<T> {
|
|
13
13
|
groupKey: (x: T) => number
|
|
14
14
|
groupSize: number
|
|
15
15
|
}
|
|
@@ -4,7 +4,7 @@ import { Alot } from 'alot/alot'
|
|
|
4
4
|
import { JsonStoreFs } from './JsonStoreFs'
|
|
5
5
|
import { Constructor } from '@dequanto/utils/types'
|
|
6
6
|
|
|
7
|
-
export interface
|
|
7
|
+
export interface IArrayStoreOptions<T, TStorage = T> {
|
|
8
8
|
path: string
|
|
9
9
|
watchFs?: boolean
|
|
10
10
|
onFsChanged?: () => any
|
|
@@ -14,6 +14,8 @@ export interface IStoreOptions<T, TStorage = T> {
|
|
|
14
14
|
serialize? (x: T): TStorage
|
|
15
15
|
Type?: Constructor
|
|
16
16
|
format?: boolean
|
|
17
|
+
|
|
18
|
+
transport?: 'file' | 'localStorage'
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export class JsonArrayStore<T> {
|
|
@@ -22,7 +24,7 @@ export class JsonArrayStore<T> {
|
|
|
22
24
|
|
|
23
25
|
private fs: JsonStoreFs<T[]>;
|
|
24
26
|
|
|
25
|
-
constructor (public options:
|
|
27
|
+
constructor (public options: IArrayStoreOptions<T>) {
|
|
26
28
|
let keyFn = this.options.key;
|
|
27
29
|
if (keyFn == null) {
|
|
28
30
|
throw new Error('Key getter must be defined');
|
|
@@ -34,6 +36,7 @@ export class JsonArrayStore<T> {
|
|
|
34
36
|
, this.options.format
|
|
35
37
|
, []
|
|
36
38
|
, this.options.serialize as any
|
|
39
|
+
, this.options.transport
|
|
37
40
|
);
|
|
38
41
|
if (this.options?.watchFs) {
|
|
39
42
|
this.fs.watch(() => this.onStoreChanged());
|
|
@@ -2,7 +2,7 @@ import type { Constructor } from 'atma-utils'
|
|
|
2
2
|
import { JsonConvert } from 'class-json'
|
|
3
3
|
import { JsonStoreFs } from './JsonStoreFs';
|
|
4
4
|
|
|
5
|
-
export interface
|
|
5
|
+
export interface IObjectStoreOptions<T, TOut = T> {
|
|
6
6
|
path: string
|
|
7
7
|
map? (x: T): TOut
|
|
8
8
|
serialize? (x: T): any
|
|
@@ -10,6 +10,9 @@ export interface IStoreOptions<T, TOut = T> {
|
|
|
10
10
|
format?: boolean
|
|
11
11
|
default?: TOut
|
|
12
12
|
watchFs?: boolean
|
|
13
|
+
onFsChanged?: () => any
|
|
14
|
+
|
|
15
|
+
transport?: 'file' | 'localStorage'
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
export class JsonObjectStore<T> {
|
|
@@ -20,7 +23,7 @@ export class JsonObjectStore<T> {
|
|
|
20
23
|
private fs: JsonStoreFs<T>;
|
|
21
24
|
|
|
22
25
|
|
|
23
|
-
constructor (public options:
|
|
26
|
+
constructor (public options: IObjectStoreOptions<T>) {
|
|
24
27
|
this.fs = new JsonStoreFs<T>(
|
|
25
28
|
this.options.path
|
|
26
29
|
, this.options.Type
|
|
@@ -28,6 +31,7 @@ export class JsonObjectStore<T> {
|
|
|
28
31
|
, this.options.format
|
|
29
32
|
, this.options.default ?? {} as any
|
|
30
33
|
, this.options.serialize as any
|
|
34
|
+
, this.options.transport
|
|
31
35
|
);
|
|
32
36
|
|
|
33
37
|
if (this.options?.watchFs) {
|
|
@@ -35,8 +39,6 @@ export class JsonObjectStore<T> {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
42
|
async get(opts?: { cloned?: boolean }): Promise<this['options']['default']> {
|
|
41
43
|
if (this.fs.errored != null) {
|
|
42
44
|
throw this.fs.errored;
|
|
@@ -64,6 +66,7 @@ export class JsonObjectStore<T> {
|
|
|
64
66
|
private onStoreChanged () {
|
|
65
67
|
this.data = null;
|
|
66
68
|
this.fs.cleanCache();
|
|
69
|
+
this.options.onFsChanged?.();
|
|
67
70
|
}
|
|
68
71
|
|
|
69
72
|
private async restore () {
|