Skip to content

Commit 788321d

Browse files
committed
Modernizing the squid
new file: abi/erc20.json modified: commands.json modified: src/abi/abi.support.ts modified: src/abi/erc20.abi.ts modified: src/abi/erc20.ts new file: src/abi/multicall.ts new file: src/main.ts modified: src/processor.ts
1 parent 56dd0c5 commit 788321d

File tree

8 files changed

+529
-71
lines changed

8 files changed

+529
-71
lines changed

abi/erc20.json

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
[
2+
{
3+
"constant": true,
4+
"inputs": [],
5+
"name": "name",
6+
"outputs": [
7+
{
8+
"name": "",
9+
"type": "string"
10+
}
11+
],
12+
"payable": false,
13+
"stateMutability": "view",
14+
"type": "function"
15+
},
16+
{
17+
"constant": false,
18+
"inputs": [
19+
{
20+
"name": "_spender",
21+
"type": "address"
22+
},
23+
{
24+
"name": "_value",
25+
"type": "uint256"
26+
}
27+
],
28+
"name": "approve",
29+
"outputs": [
30+
{
31+
"name": "",
32+
"type": "bool"
33+
}
34+
],
35+
"payable": false,
36+
"stateMutability": "nonpayable",
37+
"type": "function"
38+
},
39+
{
40+
"constant": true,
41+
"inputs": [],
42+
"name": "totalSupply",
43+
"outputs": [
44+
{
45+
"name": "",
46+
"type": "uint256"
47+
}
48+
],
49+
"payable": false,
50+
"stateMutability": "view",
51+
"type": "function"
52+
},
53+
{
54+
"constant": false,
55+
"inputs": [
56+
{
57+
"name": "_from",
58+
"type": "address"
59+
},
60+
{
61+
"name": "_to",
62+
"type": "address"
63+
},
64+
{
65+
"name": "_value",
66+
"type": "uint256"
67+
}
68+
],
69+
"name": "transferFrom",
70+
"outputs": [
71+
{
72+
"name": "",
73+
"type": "bool"
74+
}
75+
],
76+
"payable": false,
77+
"stateMutability": "nonpayable",
78+
"type": "function"
79+
},
80+
{
81+
"constant": true,
82+
"inputs": [],
83+
"name": "decimals",
84+
"outputs": [
85+
{
86+
"name": "",
87+
"type": "uint8"
88+
}
89+
],
90+
"payable": false,
91+
"stateMutability": "view",
92+
"type": "function"
93+
},
94+
{
95+
"constant": true,
96+
"inputs": [
97+
{
98+
"name": "_owner",
99+
"type": "address"
100+
}
101+
],
102+
"name": "balanceOf",
103+
"outputs": [
104+
{
105+
"name": "balance",
106+
"type": "uint256"
107+
}
108+
],
109+
"payable": false,
110+
"stateMutability": "view",
111+
"type": "function"
112+
},
113+
{
114+
"constant": true,
115+
"inputs": [],
116+
"name": "symbol",
117+
"outputs": [
118+
{
119+
"name": "",
120+
"type": "string"
121+
}
122+
],
123+
"payable": false,
124+
"stateMutability": "view",
125+
"type": "function"
126+
},
127+
{
128+
"constant": false,
129+
"inputs": [
130+
{
131+
"name": "_to",
132+
"type": "address"
133+
},
134+
{
135+
"name": "_value",
136+
"type": "uint256"
137+
}
138+
],
139+
"name": "transfer",
140+
"outputs": [
141+
{
142+
"name": "",
143+
"type": "bool"
144+
}
145+
],
146+
"payable": false,
147+
"stateMutability": "nonpayable",
148+
"type": "function"
149+
},
150+
{
151+
"constant": true,
152+
"inputs": [
153+
{
154+
"name": "_owner",
155+
"type": "address"
156+
},
157+
{
158+
"name": "_spender",
159+
"type": "address"
160+
}
161+
],
162+
"name": "allowance",
163+
"outputs": [
164+
{
165+
"name": "",
166+
"type": "uint256"
167+
}
168+
],
169+
"payable": false,
170+
"stateMutability": "view",
171+
"type": "function"
172+
},
173+
{
174+
"payable": true,
175+
"stateMutability": "payable",
176+
"type": "fallback"
177+
},
178+
{
179+
"anonymous": false,
180+
"inputs": [
181+
{
182+
"indexed": true,
183+
"name": "owner",
184+
"type": "address"
185+
},
186+
{
187+
"indexed": true,
188+
"name": "spender",
189+
"type": "address"
190+
},
191+
{
192+
"indexed": false,
193+
"name": "value",
194+
"type": "uint256"
195+
}
196+
],
197+
"name": "Approval",
198+
"type": "event"
199+
},
200+
{
201+
"anonymous": false,
202+
"inputs": [
203+
{
204+
"indexed": true,
205+
"name": "from",
206+
"type": "address"
207+
},
208+
{
209+
"indexed": true,
210+
"name": "to",
211+
"type": "address"
212+
},
213+
{
214+
"indexed": false,
215+
"name": "value",
216+
"type": "uint256"
217+
}
218+
],
219+
"name": "Transfer",
220+
"type": "event"
221+
}
222+
]

commands.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"process": {
1818
"description": "Load .env and start the squid processor",
1919
"deps": ["build"],
20-
"cmd": ["node", "--require=dotenv/config", "lib/processor.js"]
20+
"cmd": ["node", "--require=dotenv/config", "lib/main.js"]
2121
},
2222
"process:prod": {
2323
"description": "Start the squid processor",
24-
"cmd": ["node", "lib/processor.js"],
24+
"cmd": ["node", "lib/main.js"],
2525
"hidden": true
2626
},
2727
"check-updates": {

src/abi/abi.support.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from 'assert'
12
import * as ethers from 'ethers'
23

34

@@ -8,10 +9,12 @@ export interface LogRecord {
89

910

1011
export class LogEvent<Args> {
11-
private fragment: ethers.utils.EventFragment
12+
private fragment: ethers.EventFragment
1213

13-
constructor(private abi: ethers.utils.Interface, public readonly topic: string) {
14-
this.fragment = abi.getEvent(topic)
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
1518
}
1619

1720
decode(rec: LogRecord): Args {
@@ -21,26 +24,28 @@ export class LogEvent<Args> {
2124

2225

2326
export class Func<Args extends any[], FieldArgs, Result> {
24-
private fragment: ethers.utils.FunctionFragment
27+
private fragment: ethers.FunctionFragment
2528

26-
constructor(private abi: ethers.utils.Interface, public readonly sighash: string) {
27-
this.fragment = abi.getFunction(sighash)
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
2833
}
2934

30-
decode(input: ethers.utils.BytesLike): Args & FieldArgs {
35+
decode(input: ethers.BytesLike): Args & FieldArgs {
3136
return this.abi.decodeFunctionData(this.fragment, input) as any as Args & FieldArgs
3237
}
3338

3439
encode(args: Args): string {
3540
return this.abi.encodeFunctionData(this.fragment, args)
3641
}
3742

38-
decodeResult(output: ethers.utils.BytesLike): Result {
43+
decodeResult(output: ethers.BytesLike): Result {
3944
const decoded = this.abi.decodeFunctionResult(this.fragment, output)
4045
return decoded.length > 1 ? decoded : decoded[0]
4146
}
4247

43-
tryDecodeResult(output: ethers.utils.BytesLike): Result | undefined {
48+
tryDecodeResult(output: ethers.BytesLike): Result | undefined {
4449
try {
4550
return this.decodeResult(output)
4651
} catch(err: any) {
@@ -94,13 +99,13 @@ export class ContractBase {
9499
this._chain = ctx._chain
95100
if (typeof blockOrAddress === 'string') {
96101
this.blockHeight = ctx.block.height
97-
this.address = ethers.utils.getAddress(blockOrAddress)
102+
this.address = ethers.getAddress(blockOrAddress)
98103
} else {
99104
if (address == null) {
100105
throw new Error('missing contract address')
101106
}
102107
this.blockHeight = blockOrAddress.height
103-
this.address = ethers.utils.getAddress(address)
108+
this.address = ethers.getAddress(address)
104109
}
105110
}
106111

src/abi/erc20.abi.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ export const ABI_JSON = [
88
"inputs": [],
99
"outputs": [
1010
{
11-
"type": "string"
11+
"type": "string",
12+
"name": ""
1213
}
1314
]
1415
},
@@ -29,7 +30,8 @@ export const ABI_JSON = [
2930
],
3031
"outputs": [
3132
{
32-
"type": "bool"
33+
"type": "bool",
34+
"name": ""
3335
}
3436
]
3537
},
@@ -42,7 +44,8 @@ export const ABI_JSON = [
4244
"inputs": [],
4345
"outputs": [
4446
{
45-
"type": "uint256"
47+
"type": "uint256",
48+
"name": ""
4649
}
4750
]
4851
},
@@ -67,7 +70,8 @@ export const ABI_JSON = [
6770
],
6871
"outputs": [
6972
{
70-
"type": "bool"
73+
"type": "bool",
74+
"name": ""
7175
}
7276
]
7377
},
@@ -80,7 +84,8 @@ export const ABI_JSON = [
8084
"inputs": [],
8185
"outputs": [
8286
{
83-
"type": "uint8"
87+
"type": "uint8",
88+
"name": ""
8489
}
8590
]
8691
},
@@ -112,7 +117,8 @@ export const ABI_JSON = [
112117
"inputs": [],
113118
"outputs": [
114119
{
115-
"type": "string"
120+
"type": "string",
121+
"name": ""
116122
}
117123
]
118124
},
@@ -133,7 +139,8 @@ export const ABI_JSON = [
133139
],
134140
"outputs": [
135141
{
136-
"type": "bool"
142+
"type": "bool",
143+
"name": ""
137144
}
138145
]
139146
},
@@ -155,10 +162,15 @@ export const ABI_JSON = [
155162
],
156163
"outputs": [
157164
{
158-
"type": "uint256"
165+
"type": "uint256",
166+
"name": ""
159167
}
160168
]
161169
},
170+
{
171+
"type": "fallback",
172+
"stateMutability": "payable"
173+
},
162174
{
163175
"type": "event",
164176
"anonymous": false,

0 commit comments

Comments
 (0)