@subsquid/evm-typegen 3.2.4 → 4.0.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/lib/main.js +13 -12
- package/lib/main.js.map +1 -1
- package/lib/multicall.d.ts +212 -26
- package/lib/multicall.d.ts.map +1 -1
- package/lib/multicall.js +142 -100
- package/lib/multicall.js.map +1 -1
- package/lib/typegen.d.ts +15 -7
- package/lib/typegen.d.ts.map +1 -1
- package/lib/typegen.js +117 -68
- package/lib/typegen.js.map +1 -1
- package/lib/util/fetch.d.ts.map +1 -1
- package/lib/util/fetch.js +1 -1
- package/lib/util/fetch.js.map +1 -1
- package/lib/util/types.d.ts +2 -6
- package/lib/util/types.d.ts.map +1 -1
- package/lib/util/types.js +39 -60
- package/lib/util/types.js.map +1 -1
- package/package.json +8 -8
- package/src/main.ts +148 -135
- package/src/multicall.ts +3 -0
- package/src/typegen.ts +228 -111
- package/src/util/fetch.ts +6 -8
- package/src/util/types.ts +44 -62
- package/lib/abi.support.d.ts +0 -49
- package/lib/abi.support.d.ts.map +0 -1
- package/lib/abi.support.js +0 -108
- package/lib/abi.support.js.map +0 -1
- package/src/abi.support.ts +0 -120
package/lib/abi.support.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"abi.support.js","sourceRoot":"","sources":["../src/abi.support.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAA2B;AAC3B,+CAAgC;AAShC,MAAa,QAAQ;IAGjB,YAAoB,GAAqB,EAAkB,KAAa;QAApD,QAAG,GAAH,GAAG,CAAkB;QAAkB,UAAK,GAAL,KAAK,CAAQ;QACpE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QAClC,IAAA,gBAAM,EAAC,QAAQ,IAAI,IAAI,EAAE,kBAAkB,CAAC,CAAA;QAC5C,IAAI,CAAC,QAAQ,GAAG,QAAQ,C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,CAAC,EAAE,CAAC;SACrC,CAAC,CAAA;QACF,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IACpC,CAAC;CACJ;AA7BD,oCA6BC"}
|
package/src/abi.support.ts
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import assert from 'assert'
|
|
2
|
-
import * as ethers from 'ethers'
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export interface LogRecord {
|
|
6
|
-
topics: string[]
|
|
7
|
-
data: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export class LogEvent<Args> {
|
|
12
|
-
private fragment: ethers.EventFragment
|
|
13
|
-
|
|
14
|
-
constructor(private abi: ethers.Interface, public readonly topic: string) {
|
|
15
|
-
let fragment = abi.getEvent(topic)
|
|
16
|
-
assert(fragment != null, 'Missing fragment')
|
|
17
|
-
this.fragment = fragment
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
decode(rec: LogRecord): Args {
|
|
21
|
-
return this.abi.decodeEventLog(this.fragment, rec.data, rec.topics) as any as Args
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export class Func<Args extends any[], FieldArgs, Result> {
|
|
27
|
-
private fragment: ethers.FunctionFragment
|
|
28
|
-
|
|
29
|
-
constructor(private abi: ethers.Interface, public readonly sighash: string) {
|
|
30
|
-
let fragment = abi.getFunction(sighash)
|
|
31
|
-
assert(fragment != null, 'Missing fragment')
|
|
32
|
-
this.fragment = fragment
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
decode(input: ethers.BytesLike): Args & FieldArgs {
|
|
36
|
-
return this.abi.decodeFunctionData(this.fragment, input) as any as Args & FieldArgs
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
encode(args: Args): string {
|
|
40
|
-
return this.abi.encodeFunctionData(this.fragment, args)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
decodeResult(output: ethers.BytesLike): Result {
|
|
44
|
-
const decoded = this.abi.decodeFunctionResult(this.fragment, output)
|
|
45
|
-
return decoded.length > 1 ? decoded : decoded[0]
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
tryDecodeResult(output: ethers.BytesLike): Result | undefined {
|
|
49
|
-
try {
|
|
50
|
-
return this.decodeResult(output)
|
|
51
|
-
} catch(err: any) {
|
|
52
|
-
return undefined
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
export function isFunctionResultDecodingError(val: unknown): val is Error & {data: string} {
|
|
59
|
-
if (!(val instanceof Error)) return false
|
|
60
|
-
let err = val as any
|
|
61
|
-
return err.code == 'CALL_EXCEPTION'
|
|
62
|
-
&& typeof err.data == 'string'
|
|
63
|
-
&& !err.errorArgs
|
|
64
|
-
&& !err.errorName
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
export interface ChainContext {
|
|
69
|
-
_chain: Chain
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export interface BlockContext {
|
|
74
|
-
_chain: Chain
|
|
75
|
-
block: Block
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
export interface Block {
|
|
80
|
-
height: number
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
export interface Chain {
|
|
85
|
-
client: {
|
|
86
|
-
call: <T=any>(method: string, params?: unknown[]) => Promise<T>
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
export class ContractBase {
|
|
92
|
-
private readonly _chain: Chain
|
|
93
|
-
private readonly blockHeight: number
|
|
94
|
-
readonly address: string
|
|
95
|
-
|
|
96
|
-
constructor(ctx: BlockContext, address: string)
|
|
97
|
-
constructor(ctx: ChainContext, block: Block, address: string)
|
|
98
|
-
constructor(ctx: BlockContext, blockOrAddress: Block | string, address?: string) {
|
|
99
|
-
this._chain = ctx._chain
|
|
100
|
-
if (typeof blockOrAddress === 'string') {
|
|
101
|
-
this.blockHeight = ctx.block.height
|
|
102
|
-
this.address = ethers.getAddress(blockOrAddress)
|
|
103
|
-
} else {
|
|
104
|
-
if (address == null) {
|
|
105
|
-
throw new Error('missing contract address')
|
|
106
|
-
}
|
|
107
|
-
this.blockHeight = blockOrAddress.height
|
|
108
|
-
this.address = ethers.getAddress(address)
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async eth_call<Args extends any[], FieldArgs, Result>(func: Func<Args, FieldArgs, Result>, args: Args): Promise<Result> {
|
|
113
|
-
let data = func.encode(args)
|
|
114
|
-
let result = await this._chain.client.call('eth_call', [
|
|
115
|
-
{to: this.address, data},
|
|
116
|
-
'0x'+this.blockHeight.toString(16)
|
|
117
|
-
])
|
|
118
|
-
return func.decodeResult(result)
|
|
119
|
-
}
|
|
120
|
-
}
|