dequanto 0.2.13 → 0.2.19
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/contracts/ContractBase.js +11 -0
- package/lib/cjs/contracts/ContractBase.js.map +1 -1
- package/lib/cjs/hardhat/HardhatProvider.js +8 -2
- package/lib/cjs/hardhat/HardhatProvider.js.map +1 -1
- package/lib/cjs/txs/TxDataBuilder.js +5 -3
- package/lib/cjs/txs/TxDataBuilder.js.map +1 -1
- package/lib/cjs/utils/$abiProvider.js +39 -0
- package/lib/cjs/utils/$abiProvider.js.map +1 -0
- package/lib/cjs/utils/$contract.js +12 -0
- package/lib/cjs/utils/$contract.js.map +1 -1
- package/lib/cjs/utils/$traces.js +8 -4
- package/lib/cjs/utils/$traces.js.map +1 -1
- package/lib/esm/contracts/ContractBase.js.map +1 -1
- package/lib/esm/contracts/ContractBase.mjs +11 -0
- package/lib/esm/hardhat/HardhatProvider.js.map +1 -1
- package/lib/esm/hardhat/HardhatProvider.mjs +8 -2
- package/lib/esm/txs/TxDataBuilder.js.map +1 -1
- package/lib/esm/txs/TxDataBuilder.mjs +5 -3
- package/lib/esm/utils/$abiProvider.js.map +1 -0
- package/lib/esm/utils/$abiProvider.mjs +36 -0
- package/lib/esm/utils/$contract.js.map +1 -1
- package/lib/esm/utils/$contract.mjs +12 -0
- package/lib/esm/utils/$traces.js.map +1 -1
- package/lib/esm/utils/$traces.mjs +8 -4
- package/lib/types/txs/ITxBuilderOptions.d.ts +1 -0
- package/lib/types/utils/$abiProvider.d.ts +11 -0
- package/lib/types/utils/$contract.d.ts +11 -8
- package/package.json +1 -1
- package/src/contracts/ContractBase.ts +14 -4
- package/src/hardhat/HardhatProvider.ts +8 -2
- package/src/txs/ITxBuilderOptions.ts +3 -0
- package/src/txs/TxDataBuilder.ts +5 -3
- package/src/utils/$abiProvider.ts +40 -0
- package/src/utils/$contract.ts +14 -2
- package/src/utils/$traces.ts +9 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { TEth } from '@dequanto/models/TEth';
|
|
2
|
+
import { $contract } from './$contract';
|
|
3
|
+
import { TPlatform } from '@dequanto/models/TPlatform';
|
|
4
|
+
import { BlockchainExplorerFactory } from '@dequanto/explorer/BlockchainExplorerFactory';
|
|
5
|
+
import { l } from './$logger';
|
|
6
|
+
|
|
7
|
+
export namespace $abiProvider {
|
|
8
|
+
interface IContractMeta {
|
|
9
|
+
name?: string
|
|
10
|
+
address?: TEth.Address
|
|
11
|
+
abi: TEth.Abi.Item[]
|
|
12
|
+
}
|
|
13
|
+
export async function getAbi(address: TEth.Address, network: TPlatform): Promise<IContractMeta> {
|
|
14
|
+
let local = $contract.store.getContract(address);
|
|
15
|
+
if (local) {
|
|
16
|
+
return local;
|
|
17
|
+
}
|
|
18
|
+
if (network !== 'hardhat') {
|
|
19
|
+
let explorer = await BlockchainExplorerFactory.getAsync(network);
|
|
20
|
+
try {
|
|
21
|
+
let info = await explorer.getContractAbi(address);
|
|
22
|
+
if (info) {
|
|
23
|
+
l`Loading contracts meta for bold<${address}>...`;
|
|
24
|
+
let abi = typeof info.abi === 'string'
|
|
25
|
+
? JSON.parse(info.abi)
|
|
26
|
+
: info.abi;
|
|
27
|
+
return {
|
|
28
|
+
abi,
|
|
29
|
+
name: `${address.slice(0, 6)}__${address.slice(-4)}`,
|
|
30
|
+
address,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
// ignore
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/utils/$contract.ts
CHANGED
|
@@ -294,11 +294,13 @@ export namespace $contract {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
export namespace store {
|
|
297
|
-
|
|
297
|
+
interface IContractMeta {
|
|
298
298
|
name?: string
|
|
299
299
|
address?: TEth.Address
|
|
300
300
|
abi: TAbiItem[]
|
|
301
|
-
}
|
|
301
|
+
}
|
|
302
|
+
const knownContracts = [] as IContractMeta[];
|
|
303
|
+
const knownContractsAddresses = {} as Record<string, IContractMeta>
|
|
302
304
|
|
|
303
305
|
export function getFlattened() {
|
|
304
306
|
return alot(knownContracts).mapMany(x => x.abi).toArray();
|
|
@@ -308,8 +310,18 @@ export namespace $contract {
|
|
|
308
310
|
name?: string
|
|
309
311
|
abi: TAbiItem[]
|
|
310
312
|
}) {
|
|
313
|
+
if (contract.address != null) {
|
|
314
|
+
contract.address = contract.address.toLowerCase() as TEth.Address;
|
|
315
|
+
if (contract.address in knownContractsAddresses) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
knownContractsAddresses[contract.address] = contract;
|
|
319
|
+
}
|
|
311
320
|
knownContracts.push(contract)
|
|
312
321
|
}
|
|
322
|
+
export function has (address: TEth.Address) {
|
|
323
|
+
return address.toLowerCase() in knownContractsAddresses;
|
|
324
|
+
}
|
|
313
325
|
|
|
314
326
|
export function getContract(address: TEth.Address) {
|
|
315
327
|
return knownContracts.find(x => x.address === address);
|
package/src/utils/$traces.ts
CHANGED
|
@@ -98,16 +98,20 @@ export namespace $traces {
|
|
|
98
98
|
|
|
99
99
|
let lines: string[] = [];
|
|
100
100
|
let entryLine = formatEntrypointLabel(params.tx, params.traces, entryAbiMeta?.contractName ?? entryAbiMeta?.name, entryAbiItem, params);
|
|
101
|
-
lines.push(`${entryLine}${params.traces.failed ? ' [FAILED]' : ''}`);
|
|
101
|
+
lines.push(`${entryLine}${params.traces.failed ? color('red', ' [FAILED]', params) : ''}`);
|
|
102
102
|
|
|
103
103
|
let root = frames[0];
|
|
104
104
|
if (root != null) {
|
|
105
105
|
appendEntries(root, 1, lines);
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
let addresses = alot
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
let addresses = alot
|
|
109
|
+
.fromObject(params.addresses ?? {})
|
|
110
|
+
.sortByLocalCompare(x => x.value, 'asc')
|
|
111
|
+
.map(x => {
|
|
112
|
+
return `${x.key} <=> ${x.value}`;
|
|
113
|
+
})
|
|
114
|
+
.toArray();
|
|
111
115
|
|
|
112
116
|
lines.push('\n', ...addresses);
|
|
113
117
|
|
|
@@ -130,7 +134,7 @@ export namespace $traces {
|
|
|
130
134
|
|
|
131
135
|
for (let entry of entries) {
|
|
132
136
|
if (entry.kind === 'frame') {
|
|
133
|
-
out.push(`${indent}${entry.frame.label}${entry.frame.failed ? ' [FAILED]' : ''}`);
|
|
137
|
+
out.push(`${indent}${entry.frame.label}${entry.frame.failed ? color('red', ' [FAILED]', params) : ''}`);
|
|
134
138
|
appendEntries(entry.frame, level + 1, out);
|
|
135
139
|
continue;
|
|
136
140
|
}
|