@sentio/sdk 3.2.0 → 3.3.0-rc.2
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/solana/builtin/spl-token-processor.d.ts +31 -30
- package/lib/solana/builtin/spl-token-processor.d.ts.map +1 -1
- package/lib/solana/builtin/spl-token-processor.js +61 -61
- package/lib/solana/builtin/spl-token-processor.js.map +1 -1
- package/lib/solana/solana-context.d.ts +3 -1
- package/lib/solana/solana-context.d.ts.map +1 -1
- package/lib/solana/solana-context.js +4 -2
- package/lib/solana/solana-context.js.map +1 -1
- package/lib/solana/solana-options.d.ts +3 -0
- package/lib/solana/solana-options.d.ts.map +1 -1
- package/lib/solana/solana-options.js +3 -0
- package/lib/solana/solana-options.js.map +1 -1
- package/lib/solana/solana-plugin.d.ts +1 -0
- package/lib/solana/solana-plugin.d.ts.map +1 -1
- package/lib/solana/solana-plugin.js +45 -9
- package/lib/solana/solana-plugin.js.map +1 -1
- package/lib/solana/solana-processor.d.ts +23 -6
- package/lib/solana/solana-processor.d.ts.map +1 -1
- package/lib/solana/solana-processor.js +42 -2
- package/lib/solana/solana-processor.js.map +1 -1
- package/package.json +3 -3
- package/src/solana/builtin/spl-token-processor.ts +140 -62
- package/src/solana/solana-context.ts +6 -2
- package/src/solana/solana-options.ts +4 -0
- package/src/solana/solana-plugin.ts +50 -7
- package/src/solana/solana-processor.ts +89 -7
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "../index.js"
|
|
1
|
+
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions, SolanaFetchConfig } from "../index.js"
|
|
2
2
|
import { Instruction } from '@coral-xyz/anchor'
|
|
3
3
|
import { AmountToUiAmount, Approve, ApproveChecked, Burn, BurnChecked, CloseAccount, CreateNativeMint, DefaultAccountStateExtension, FreezeAccount, GetAccountDataSize, InitializeAccount, InitializeAccount2, InitializeAccount3, InitializeImmutableOwner, InitializeMint, InitializeMintCloseAuthority, InitializeMultisig, MemoTransferExtension, MintTo, MintToChecked, Reallocate, Revoke, SyncNative, ThawAccount, Transfer, TransferChecked, TransferFeeExtension, UiAmountToAmount } from './types.js';
|
|
4
|
+
import { HandlerOptions } from '../../core/handler-options.js'
|
|
4
5
|
|
|
5
6
|
export class SPLTokenProcessor extends SolanaBaseProcessor {
|
|
6
7
|
static bind(options: SolanaBindOptions): SPLTokenProcessor {
|
|
@@ -24,273 +25,350 @@ export class SPLTokenProcessor extends SolanaBaseProcessor {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
public onInitializeMint(
|
|
27
|
-
handler: (data: InitializeMint, ctx: SolanaContext) => void
|
|
28
|
+
handler: (data: InitializeMint, ctx: SolanaContext) => void,
|
|
29
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
28
30
|
): SPLTokenProcessor {
|
|
29
31
|
this.onInstruction('initializeMint', (ins: Instruction, ctx) => {
|
|
30
32
|
if (ins) {
|
|
31
33
|
handler(ins.data as InitializeMint, ctx)
|
|
32
34
|
}
|
|
33
|
-
})
|
|
35
|
+
}, handlerOptions)
|
|
34
36
|
return this
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
public onInitializeAccount(
|
|
38
|
-
|
|
40
|
+
handler: (data: InitializeAccount, ctx: SolanaContext) => void,
|
|
41
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
39
42
|
): SPLTokenProcessor {
|
|
40
43
|
this.onInstruction('initializeAccount', (ins: Instruction, ctx) => {
|
|
41
44
|
if (ins) {
|
|
42
|
-
|
|
45
|
+
handler(ins.data as InitializeAccount, ctx)
|
|
43
46
|
}
|
|
44
|
-
})
|
|
47
|
+
}, handlerOptions)
|
|
45
48
|
return this
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
public onInitializeAccount2(
|
|
49
|
-
|
|
52
|
+
handler: (data: InitializeAccount2, ctx: SolanaContext) => void,
|
|
53
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
50
54
|
): SPLTokenProcessor {
|
|
51
55
|
this.onInstruction('initializeAccount2', (ins: Instruction, ctx) => {
|
|
52
56
|
if (ins) {
|
|
53
|
-
|
|
57
|
+
handler(ins.data as InitializeAccount2, ctx)
|
|
54
58
|
}
|
|
55
|
-
})
|
|
59
|
+
}, handlerOptions)
|
|
56
60
|
return this
|
|
57
61
|
}
|
|
58
62
|
|
|
59
63
|
public onInitializeAccount3(
|
|
60
|
-
|
|
64
|
+
handler: (data: InitializeAccount3, ctx: SolanaContext) => void,
|
|
65
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
61
66
|
): SPLTokenProcessor {
|
|
62
67
|
this.onInstruction('initializeAccount3', (ins: Instruction, ctx) => {
|
|
63
68
|
if (ins) {
|
|
64
|
-
|
|
69
|
+
handler(ins.data as InitializeAccount3, ctx)
|
|
65
70
|
}
|
|
66
|
-
})
|
|
71
|
+
}, handlerOptions)
|
|
67
72
|
return this
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
public onInitializeMultisig(
|
|
71
|
-
handler: (data: InitializeMultisig, ctx: SolanaContext) => void
|
|
76
|
+
handler: (data: InitializeMultisig, ctx: SolanaContext) => void,
|
|
77
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
72
78
|
): SPLTokenProcessor {
|
|
73
79
|
this.onInstruction('initializeMultisig', (ins: Instruction, ctx) => {
|
|
74
80
|
if (ins) {
|
|
75
81
|
handler(ins.data as InitializeMultisig, ctx)
|
|
76
82
|
}
|
|
77
|
-
})
|
|
83
|
+
}, handlerOptions)
|
|
78
84
|
return this
|
|
79
85
|
}
|
|
80
86
|
|
|
81
|
-
public onTransfer(
|
|
87
|
+
public onTransfer(
|
|
88
|
+
handler: (data: Transfer, ctx: SolanaContext) => void,
|
|
89
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
90
|
+
): SPLTokenProcessor {
|
|
82
91
|
this.onInstruction('transfer', (ins: Instruction, ctx) => {
|
|
83
92
|
if (ins) {
|
|
84
93
|
handler(ins.data as Transfer, ctx)
|
|
85
94
|
}
|
|
86
|
-
})
|
|
95
|
+
}, handlerOptions)
|
|
87
96
|
return this
|
|
88
97
|
}
|
|
89
98
|
|
|
90
|
-
public
|
|
99
|
+
public onApprove(
|
|
100
|
+
handler: (data: Approve, ctx: SolanaContext) => void,
|
|
101
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
102
|
+
): SPLTokenProcessor {
|
|
91
103
|
this.onInstruction('approve', (ins: Instruction, ctx) => {
|
|
92
104
|
if (ins) {
|
|
93
105
|
handler(ins.data as Approve, ctx)
|
|
94
106
|
}
|
|
95
|
-
})
|
|
107
|
+
}, handlerOptions)
|
|
96
108
|
return this
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
public onRevoke(
|
|
111
|
+
public onRevoke(
|
|
112
|
+
handler: (data: Revoke, ctx: SolanaContext) => void,
|
|
113
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
114
|
+
): SPLTokenProcessor {
|
|
100
115
|
this.onInstruction('revoke', (ins: Instruction, ctx) => {
|
|
101
116
|
if (ins) {
|
|
102
117
|
handler(ins.data as Revoke, ctx)
|
|
103
118
|
}
|
|
104
|
-
})
|
|
119
|
+
}, handlerOptions)
|
|
105
120
|
return this
|
|
106
121
|
}
|
|
107
122
|
|
|
108
|
-
public onSetAuthority(
|
|
123
|
+
public onSetAuthority(
|
|
124
|
+
handler: (data: any, ctx: SolanaContext) => void,
|
|
125
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
126
|
+
): SPLTokenProcessor {
|
|
109
127
|
this.onInstruction('setAuthority', (ins: Instruction, ctx) => {
|
|
110
128
|
if (ins) {
|
|
111
129
|
handler(ins.data as any, ctx)
|
|
112
130
|
}
|
|
113
|
-
})
|
|
131
|
+
}, handlerOptions)
|
|
114
132
|
return this
|
|
115
133
|
}
|
|
116
134
|
|
|
117
|
-
public onMintTo(
|
|
135
|
+
public onMintTo(
|
|
136
|
+
handler: (data: MintTo, ctx: SolanaContext) => void,
|
|
137
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
138
|
+
): SPLTokenProcessor {
|
|
118
139
|
this.onInstruction('mintTo', (ins: Instruction, ctx) => {
|
|
119
140
|
if (ins) {
|
|
120
141
|
handler(ins.data as MintTo, ctx)
|
|
121
142
|
}
|
|
122
|
-
})
|
|
143
|
+
}, handlerOptions)
|
|
123
144
|
return this
|
|
124
145
|
}
|
|
125
146
|
|
|
126
|
-
public onBurn(
|
|
147
|
+
public onBurn(
|
|
148
|
+
handler: (data: Burn, ctx: SolanaContext) => void,
|
|
149
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
150
|
+
): SPLTokenProcessor {
|
|
127
151
|
this.onInstruction('burn', (ins: Instruction, ctx) => {
|
|
128
152
|
if (ins) {
|
|
129
153
|
handler(ins.data as Burn, ctx)
|
|
130
154
|
}
|
|
131
|
-
})
|
|
155
|
+
}, handlerOptions)
|
|
132
156
|
return this
|
|
133
157
|
}
|
|
134
158
|
|
|
135
|
-
public onCloseAccount(
|
|
159
|
+
public onCloseAccount(
|
|
160
|
+
handler: (data: CloseAccount, ctx: SolanaContext) => void,
|
|
161
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
162
|
+
): SPLTokenProcessor {
|
|
136
163
|
this.onInstruction('closeAccount', (ins: Instruction, ctx) => {
|
|
137
164
|
if (ins) {
|
|
138
165
|
handler(ins.data as CloseAccount, ctx)
|
|
139
166
|
}
|
|
140
|
-
})
|
|
167
|
+
}, handlerOptions)
|
|
141
168
|
return this
|
|
142
169
|
}
|
|
143
170
|
|
|
144
|
-
public onFreezeAccount(
|
|
171
|
+
public onFreezeAccount(
|
|
172
|
+
handler: (data: FreezeAccount, ctx: SolanaContext) => void,
|
|
173
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
174
|
+
): SPLTokenProcessor {
|
|
145
175
|
this.onInstruction('freezeAccount', (ins: Instruction, ctx) => {
|
|
146
176
|
if (ins) {
|
|
147
177
|
handler(ins.data as FreezeAccount, ctx)
|
|
148
178
|
}
|
|
149
|
-
})
|
|
179
|
+
}, handlerOptions)
|
|
150
180
|
return this
|
|
151
181
|
}
|
|
152
182
|
|
|
153
|
-
public onThawAccount(
|
|
183
|
+
public onThawAccount(
|
|
184
|
+
handler: (data: ThawAccount, ctx: SolanaContext) => void,
|
|
185
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
186
|
+
): SPLTokenProcessor {
|
|
154
187
|
this.onInstruction('thawAccount', (ins: Instruction, ctx) => {
|
|
155
188
|
if (ins) {
|
|
156
189
|
handler(ins.data as ThawAccount, ctx)
|
|
157
190
|
}
|
|
158
|
-
})
|
|
191
|
+
}, handlerOptions)
|
|
159
192
|
return this
|
|
160
193
|
}
|
|
161
194
|
|
|
162
|
-
public onTransferChecked(
|
|
195
|
+
public onTransferChecked(
|
|
196
|
+
handler: (data: TransferChecked, ctx: SolanaContext) => void,
|
|
197
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
198
|
+
): SPLTokenProcessor {
|
|
163
199
|
this.onInstruction('transferChecked', (ins: Instruction, ctx) => {
|
|
164
200
|
if (ins) {
|
|
165
201
|
handler(ins.data as TransferChecked, ctx)
|
|
166
202
|
}
|
|
167
|
-
})
|
|
203
|
+
}, handlerOptions)
|
|
168
204
|
return this
|
|
169
205
|
}
|
|
170
206
|
|
|
171
|
-
public onApproveChecked(
|
|
207
|
+
public onApproveChecked(
|
|
208
|
+
handler: (data: ApproveChecked, ctx: SolanaContext) => void,
|
|
209
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
210
|
+
): SPLTokenProcessor {
|
|
172
211
|
this.onInstruction('approveChecked', (ins: Instruction, ctx) => {
|
|
173
212
|
if (ins) {
|
|
174
213
|
handler(ins.data as ApproveChecked, ctx)
|
|
175
214
|
}
|
|
176
|
-
})
|
|
215
|
+
}, handlerOptions)
|
|
177
216
|
return this
|
|
178
217
|
}
|
|
179
218
|
|
|
180
|
-
public onMintToChecked(
|
|
219
|
+
public onMintToChecked(
|
|
220
|
+
handler: (data: MintToChecked, ctx: SolanaContext) => void,
|
|
221
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
222
|
+
): SPLTokenProcessor {
|
|
181
223
|
this.onInstruction('mintToChecked', (ins: Instruction, ctx) => {
|
|
182
224
|
if (ins) {
|
|
183
225
|
handler(ins.data as MintToChecked, ctx)
|
|
184
226
|
}
|
|
185
|
-
})
|
|
227
|
+
}, handlerOptions)
|
|
186
228
|
return this
|
|
187
229
|
}
|
|
188
230
|
|
|
189
|
-
public onBurnChecked(
|
|
231
|
+
public onBurnChecked(
|
|
232
|
+
handler: (data: BurnChecked, ctx: SolanaContext) => void,
|
|
233
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
234
|
+
): SPLTokenProcessor {
|
|
190
235
|
this.onInstruction('burnChecked', (ins: Instruction, ctx) => {
|
|
191
236
|
if (ins) {
|
|
192
237
|
handler(ins.data as BurnChecked, ctx)
|
|
193
238
|
}
|
|
194
|
-
})
|
|
239
|
+
}, handlerOptions)
|
|
195
240
|
return this
|
|
196
241
|
}
|
|
197
242
|
|
|
198
|
-
public onSyncNative(
|
|
243
|
+
public onSyncNative(
|
|
244
|
+
handler: (data: SyncNative, ctx: SolanaContext) => void,
|
|
245
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
246
|
+
): SPLTokenProcessor {
|
|
199
247
|
this.onInstruction('syncNative', (ins: Instruction, ctx) => {
|
|
200
248
|
if (ins) {
|
|
201
249
|
handler(ins.data as SyncNative, ctx)
|
|
202
250
|
}
|
|
203
|
-
})
|
|
251
|
+
}, handlerOptions)
|
|
204
252
|
return this
|
|
205
253
|
}
|
|
206
254
|
|
|
207
|
-
public onGetAccountDataSize(
|
|
255
|
+
public onGetAccountDataSize(
|
|
256
|
+
handler: (data: GetAccountDataSize, ctx: SolanaContext) => void,
|
|
257
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
258
|
+
): SPLTokenProcessor {
|
|
208
259
|
this.onInstruction('getAccountDataSize', (ins: Instruction, ctx) => {
|
|
209
260
|
if (ins) {
|
|
210
261
|
handler(ins.data as GetAccountDataSize, ctx)
|
|
211
262
|
}
|
|
212
|
-
})
|
|
263
|
+
}, handlerOptions)
|
|
213
264
|
return this
|
|
214
265
|
}
|
|
215
266
|
|
|
216
|
-
public onInitializeImmutableOwner(
|
|
267
|
+
public onInitializeImmutableOwner(
|
|
268
|
+
handler: (data: InitializeImmutableOwner, ctx: SolanaContext) => void,
|
|
269
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
270
|
+
): SPLTokenProcessor {
|
|
217
271
|
this.onInstruction('initializeImmutableOwner', (ins: Instruction, ctx) => {
|
|
218
272
|
if (ins) {
|
|
219
273
|
handler(ins.data as InitializeImmutableOwner, ctx)
|
|
220
274
|
}
|
|
221
|
-
})
|
|
275
|
+
}, handlerOptions)
|
|
222
276
|
return this
|
|
223
277
|
}
|
|
224
278
|
|
|
225
|
-
public onAmountToUiAmount(
|
|
279
|
+
public onAmountToUiAmount(
|
|
280
|
+
handler: (data: AmountToUiAmount, ctx: SolanaContext) => void,
|
|
281
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
282
|
+
): SPLTokenProcessor {
|
|
226
283
|
this.onInstruction('amountToUiAmount', (ins: Instruction, ctx) => {
|
|
227
284
|
if (ins) {
|
|
228
285
|
handler(ins.data as AmountToUiAmount, ctx)
|
|
229
286
|
}
|
|
230
|
-
})
|
|
287
|
+
}, handlerOptions)
|
|
231
288
|
return this
|
|
232
289
|
}
|
|
233
290
|
|
|
234
|
-
public onUiAmountToAmount(
|
|
291
|
+
public onUiAmountToAmount(
|
|
292
|
+
handler: (data: UiAmountToAmount, ctx: SolanaContext) => void,
|
|
293
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
294
|
+
): SPLTokenProcessor {
|
|
235
295
|
this.onInstruction('uiAmountToAmount', (ins: Instruction, ctx) => {
|
|
236
296
|
if (ins) {
|
|
237
297
|
handler(ins.data as UiAmountToAmount, ctx)
|
|
238
298
|
}
|
|
239
|
-
})
|
|
299
|
+
}, handlerOptions)
|
|
240
300
|
return this
|
|
241
301
|
}
|
|
242
302
|
|
|
243
|
-
public onInitializeMintCloseAuthority(
|
|
303
|
+
public onInitializeMintCloseAuthority(
|
|
304
|
+
handler: (data: InitializeMintCloseAuthority, ctx: SolanaContext) => void,
|
|
305
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
306
|
+
): SPLTokenProcessor {
|
|
244
307
|
this.onInstruction('initializeMintCloseAuthority', (ins: Instruction, ctx) => {
|
|
245
308
|
if (ins) {
|
|
246
309
|
handler(ins.data as InitializeMintCloseAuthority, ctx)
|
|
247
310
|
}
|
|
248
|
-
})
|
|
311
|
+
}, handlerOptions)
|
|
249
312
|
return this
|
|
250
313
|
}
|
|
251
314
|
|
|
252
|
-
public onTransferFeeExtension(
|
|
315
|
+
public onTransferFeeExtension(
|
|
316
|
+
handler: (data: TransferFeeExtension, ctx: SolanaContext) => void,
|
|
317
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
318
|
+
): SPLTokenProcessor {
|
|
253
319
|
this.onInstruction('transferFeeExtension', (ins: Instruction, ctx) => {
|
|
254
320
|
if (ins) {
|
|
255
321
|
handler(ins.data as TransferFeeExtension, ctx)
|
|
256
322
|
}
|
|
257
|
-
})
|
|
323
|
+
}, handlerOptions)
|
|
258
324
|
return this
|
|
259
325
|
}
|
|
260
326
|
|
|
261
|
-
public onDefaultAccountStateExtension(
|
|
327
|
+
public onDefaultAccountStateExtension(
|
|
328
|
+
handler: (data: DefaultAccountStateExtension, ctx: SolanaContext) => void,
|
|
329
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
330
|
+
): SPLTokenProcessor {
|
|
262
331
|
this.onInstruction('defaultAccountStateExtension', (ins: Instruction, ctx) => {
|
|
263
332
|
if (ins) {
|
|
264
333
|
handler(ins.data as DefaultAccountStateExtension, ctx)
|
|
265
334
|
}
|
|
266
|
-
})
|
|
335
|
+
}, handlerOptions)
|
|
267
336
|
return this
|
|
268
337
|
}
|
|
269
338
|
|
|
270
|
-
public onReallocate(
|
|
339
|
+
public onReallocate(
|
|
340
|
+
handler: (data: Reallocate, ctx: SolanaContext) => void,
|
|
341
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
342
|
+
): SPLTokenProcessor {
|
|
271
343
|
this.onInstruction('reallocate', (ins: Instruction, ctx) => {
|
|
272
344
|
if (ins) {
|
|
273
345
|
handler(ins.data as Reallocate, ctx)
|
|
274
346
|
}
|
|
275
|
-
})
|
|
347
|
+
}, handlerOptions)
|
|
276
348
|
return this
|
|
277
349
|
}
|
|
278
350
|
|
|
279
|
-
public onMemoTransferExtension(
|
|
351
|
+
public onMemoTransferExtension(
|
|
352
|
+
handler: (data: MemoTransferExtension, ctx: SolanaContext) => void,
|
|
353
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
354
|
+
): SPLTokenProcessor {
|
|
280
355
|
this.onInstruction('memoTransferExtension', (ins: Instruction, ctx) => {
|
|
281
356
|
if (ins) {
|
|
282
357
|
handler(ins.data as MemoTransferExtension, ctx)
|
|
283
358
|
}
|
|
284
|
-
})
|
|
359
|
+
}, handlerOptions)
|
|
285
360
|
return this
|
|
286
361
|
}
|
|
287
362
|
|
|
288
|
-
public onCreateNativeMint(
|
|
363
|
+
public onCreateNativeMint(
|
|
364
|
+
handler: (data: CreateNativeMint, ctx: SolanaContext) => void,
|
|
365
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, Instruction>
|
|
366
|
+
): SPLTokenProcessor {
|
|
289
367
|
this.onInstruction('createNativeMint', (ins: Instruction, ctx) => {
|
|
290
368
|
if (ins) {
|
|
291
369
|
handler(ins.data as CreateNativeMint, ctx)
|
|
292
370
|
}
|
|
293
|
-
})
|
|
371
|
+
}, handlerOptions)
|
|
294
372
|
return this
|
|
295
373
|
}
|
|
296
374
|
|
|
@@ -1,24 +1,28 @@
|
|
|
1
1
|
import { normalizeLabels, Labels, BaseContext, RecordMetaData } from '../index.js'
|
|
2
2
|
import { SolanaChainId } from '@sentio/chain'
|
|
3
|
+
import { TransactionResponse } from '@solana/web3.js'
|
|
3
4
|
|
|
4
5
|
export class SolanaContext extends BaseContext {
|
|
5
6
|
network: SolanaChainId
|
|
6
7
|
address: string
|
|
7
8
|
programName: string
|
|
8
9
|
blockNumber: bigint
|
|
10
|
+
transaction?: TransactionResponse
|
|
9
11
|
|
|
10
12
|
constructor(
|
|
11
13
|
programName: string,
|
|
12
14
|
network: SolanaChainId,
|
|
13
15
|
address: string,
|
|
14
16
|
slot: bigint,
|
|
15
|
-
baseLabels: Labels | undefined
|
|
17
|
+
baseLabels: Labels | undefined,
|
|
18
|
+
transaction?: TransactionResponse
|
|
16
19
|
) {
|
|
17
20
|
super(baseLabels)
|
|
18
21
|
this.network = network || SolanaChainId.SOLANA_MAINNET
|
|
19
22
|
this.programName = programName
|
|
20
23
|
this.address = address
|
|
21
24
|
this.blockNumber = slot
|
|
25
|
+
this.transaction = transaction
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
getChainId() {
|
|
@@ -31,7 +35,7 @@ export class SolanaContext extends BaseContext {
|
|
|
31
35
|
contractName: this.programName,
|
|
32
36
|
blockNumber: this.blockNumber,
|
|
33
37
|
transactionIndex: 0,
|
|
34
|
-
transactionHash: '',
|
|
38
|
+
transactionHash: this.transaction?.transaction.signatures[0] || '',
|
|
35
39
|
logIndex: 0,
|
|
36
40
|
chainId: this.getChainId(),
|
|
37
41
|
name: name,
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
DataBinding,
|
|
5
5
|
HandlerType,
|
|
6
6
|
InitResponse,
|
|
7
|
+
OnIntervalConfig,
|
|
7
8
|
ProcessConfigResponse,
|
|
8
9
|
ProcessResult
|
|
9
10
|
} from '@sentio/protos'
|
|
@@ -30,6 +31,7 @@ export class SolanaPlugin extends Plugin {
|
|
|
30
31
|
if (forChainId !== undefined && forChainId !== chainId.toString()) {
|
|
31
32
|
continue
|
|
32
33
|
}
|
|
34
|
+
|
|
33
35
|
const contractConfig = ContractConfig.fromPartial({
|
|
34
36
|
processorType: USER_PROCESSOR,
|
|
35
37
|
contract: {
|
|
@@ -38,23 +40,47 @@ export class SolanaPlugin extends Plugin {
|
|
|
38
40
|
address: solanaProcessor.address,
|
|
39
41
|
abi: ''
|
|
40
42
|
},
|
|
41
|
-
startBlock: solanaProcessor.config.startSlot
|
|
42
|
-
|
|
43
|
+
startBlock: solanaProcessor.config.startSlot
|
|
44
|
+
})
|
|
45
|
+
if (solanaProcessor.address && solanaProcessor.address != '*') {
|
|
46
|
+
let fetchTx = false
|
|
47
|
+
for (const fetchConfig of solanaProcessor.instructionHandlerMap.values()) {
|
|
48
|
+
if (fetchConfig.handlerOptions?.fetchTx) {
|
|
49
|
+
fetchTx = true
|
|
50
|
+
break
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
contractConfig.instructionConfig = {
|
|
43
54
|
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
44
55
|
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
45
|
-
rawDataInstruction: solanaProcessor.decodeInstruction !== null
|
|
56
|
+
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
57
|
+
fetchTx: fetchTx
|
|
46
58
|
}
|
|
47
|
-
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const [idx, handler] of solanaProcessor.blockHandlers.entries()) {
|
|
62
|
+
contractConfig.intervalConfigs.push(
|
|
63
|
+
OnIntervalConfig.fromPartial({
|
|
64
|
+
handlerId: idx,
|
|
65
|
+
minutesInterval: handler.timeIntervalInMinutes,
|
|
66
|
+
slotInterval: handler.slotInterval,
|
|
67
|
+
handlerName: handler.handlerName
|
|
68
|
+
})
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
48
72
|
config.contractConfigs.push(contractConfig)
|
|
49
73
|
}
|
|
50
74
|
}
|
|
51
75
|
|
|
52
|
-
supportedHandlers = [HandlerType.SOL_INSTRUCTION]
|
|
76
|
+
supportedHandlers = [HandlerType.SOL_INSTRUCTION, HandlerType.SOL_BLOCK]
|
|
53
77
|
|
|
54
78
|
processBinding(request: DataBinding): Promise<ProcessResult> {
|
|
55
79
|
switch (request.handlerType) {
|
|
56
80
|
case HandlerType.SOL_INSTRUCTION:
|
|
57
81
|
return this.processSolInstruction(request)
|
|
82
|
+
case HandlerType.SOL_BLOCK:
|
|
83
|
+
return this.processSolBlock(request)
|
|
58
84
|
default:
|
|
59
85
|
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
60
86
|
}
|
|
@@ -73,7 +99,7 @@ export class SolanaPlugin extends Plugin {
|
|
|
73
99
|
|
|
74
100
|
// Only have instruction handlers for solana processors
|
|
75
101
|
for (const processor of SolanaProcessorState.INSTANCE.getValues()) {
|
|
76
|
-
if (processor.address === instruction.programAccountId) {
|
|
102
|
+
if (processor.address === instruction.programAccountId || processor.address === '*') {
|
|
77
103
|
let parsedInstruction: SolInstruction | null = null
|
|
78
104
|
|
|
79
105
|
try {
|
|
@@ -96,7 +122,7 @@ export class SolanaPlugin extends Plugin {
|
|
|
96
122
|
continue
|
|
97
123
|
}
|
|
98
124
|
const res = processor
|
|
99
|
-
.handleInstruction(parsedInstruction, instruction.accounts, insHandler, instruction
|
|
125
|
+
.handleInstruction(parsedInstruction, instruction.accounts, insHandler, instruction)
|
|
100
126
|
.catch((e) => {
|
|
101
127
|
throw new ServerError(
|
|
102
128
|
Status.INTERNAL,
|
|
@@ -109,6 +135,23 @@ export class SolanaPlugin extends Plugin {
|
|
|
109
135
|
}
|
|
110
136
|
return mergeProcessResults(await Promise.all(promises))
|
|
111
137
|
}
|
|
138
|
+
|
|
139
|
+
async processSolBlock(request: DataBinding): Promise<ProcessResult> {
|
|
140
|
+
if (!request.data?.solBlock) {
|
|
141
|
+
throw new ServerError(Status.INVALID_ARGUMENT, 'block data cannot be empty')
|
|
142
|
+
}
|
|
143
|
+
const block = request.data.solBlock
|
|
144
|
+
const promises: Promise<ProcessResult>[] = []
|
|
145
|
+
for (const processor of SolanaProcessorState.INSTANCE.getValues()) {
|
|
146
|
+
for (const handlerId of request.handlerIds) {
|
|
147
|
+
const handler = processor.blockHandlers[handlerId]
|
|
148
|
+
if (handler) {
|
|
149
|
+
promises.push(processor.handleBlock(block, handler))
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return mergeProcessResults(await Promise.all(promises))
|
|
154
|
+
}
|
|
112
155
|
}
|
|
113
156
|
|
|
114
157
|
PluginManager.INSTANCE.register(new SolanaPlugin())
|