@sentio/sdk 1.37.0-rc.2 → 1.37.0-rc.3
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/builtin/index.d.ts +0 -2
- package/lib/builtin/index.js +1 -3
- package/lib/builtin/index.js.map +1 -1
- package/lib/core/eth-plugin.js +12 -15
- package/lib/core/eth-plugin.js.map +1 -1
- package/lib/core/index.d.ts +0 -4
- package/lib/core/index.js +1 -9
- package/lib/core/index.js.map +1 -1
- package/lib/core/sui-plugin.js +1 -1
- package/lib/core/sui-plugin.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -14
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +0 -4
- package/lib/service.js +40 -71
- package/lib/service.js.map +1 -1
- package/package.json +5 -16
- package/src/builtin/index.ts +1 -4
- package/src/core/eth-plugin.ts +5 -8
- package/src/core/index.ts +0 -5
- package/src/core/sui-plugin.ts +2 -2
- package/src/index.ts +3 -1
- package/src/service.ts +13 -71
- package/lib/aptos/api.d.ts +0 -2
- package/lib/aptos/api.js +0 -14
- package/lib/aptos/api.js.map +0 -1
- package/lib/aptos/aptos-plugin.d.ts +0 -14
- package/lib/aptos/aptos-plugin.js +0 -185
- package/lib/aptos/aptos-plugin.js.map +0 -1
- package/lib/aptos/aptos-processor.d.ts +0 -75
- package/lib/aptos/aptos-processor.js +0 -193
- package/lib/aptos/aptos-processor.js.map +0 -1
- package/lib/aptos/context.d.ts +0 -22
- package/lib/aptos/context.js +0 -65
- package/lib/aptos/context.js.map +0 -1
- package/lib/aptos/index.d.ts +0 -9
- package/lib/aptos/index.js +0 -34
- package/lib/aptos/index.js.map +0 -1
- package/lib/aptos/models.d.ts +0 -23
- package/lib/aptos/models.js +0 -3
- package/lib/aptos/models.js.map +0 -1
- package/lib/aptos/network.d.ts +0 -14
- package/lib/aptos/network.js +0 -46
- package/lib/aptos/network.js.map +0 -1
- package/lib/aptos/runtime.d.ts +0 -2
- package/lib/aptos/runtime.js +0 -16
- package/lib/aptos/runtime.js.map +0 -1
- package/lib/aptos/type-registry.d.ts +0 -21
- package/lib/aptos/type-registry.js +0 -156
- package/lib/aptos/type-registry.js.map +0 -1
- package/lib/aptos/types.d.ts +0 -9
- package/lib/aptos/types.js +0 -135
- package/lib/aptos/types.js.map +0 -1
- package/lib/aptos/types.test.d.ts +0 -1
- package/lib/aptos/types.test.js.map +0 -1
- package/lib/aptos/utils.d.ts +0 -7
- package/lib/aptos/utils.js +0 -27
- package/lib/aptos/utils.js.map +0 -1
- package/lib/aptos-codegen/codegen.d.ts +0 -23
- package/lib/aptos-codegen/codegen.js +0 -364
- package/lib/aptos-codegen/codegen.js.map +0 -1
- package/lib/aptos-codegen/typegen.d.ts +0 -17
- package/lib/aptos-codegen/typegen.js +0 -142
- package/lib/aptos-codegen/typegen.js.map +0 -1
- package/lib/builtin/aptos/0x1.d.ts +0 -1913
- package/lib/builtin/aptos/0x1.js +0 -2748
- package/lib/builtin/aptos/0x1.js.map +0 -1
- package/lib/builtin/aptos/0x3.d.ts +0 -482
- package/lib/builtin/aptos/0x3.js +0 -526
- package/lib/builtin/aptos/0x3.js.map +0 -1
- package/lib/builtin/aptos/index.d.ts +0 -2
- package/lib/builtin/aptos/index.js +0 -29
- package/lib/builtin/aptos/index.js.map +0 -1
- package/lib/builtin/solana/index.d.ts +0 -2
- package/lib/builtin/solana/index.js +0 -19
- package/lib/builtin/solana/index.js.map +0 -1
- package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
- package/lib/builtin/solana/spl-token-processor.js +0 -258
- package/lib/builtin/solana/spl-token-processor.js.map +0 -1
- package/lib/builtin/solana/types.d.ts +0 -427
- package/lib/builtin/solana/types.js +0 -203
- package/lib/builtin/solana/types.js.map +0 -1
- package/lib/builtin/solana/wormhole-processor.d.ts +0 -12
- package/lib/builtin/solana/wormhole-processor.js +0 -268
- package/lib/builtin/solana/wormhole-processor.js.map +0 -1
- package/lib/core/solana-context.d.ts +0 -11
- package/lib/core/solana-context.js +0 -34
- package/lib/core/solana-context.js.map +0 -1
- package/lib/core/solana-options.d.ts +0 -8
- package/lib/core/solana-options.js +0 -13
- package/lib/core/solana-options.js.map +0 -1
- package/lib/core/solana-plugin.d.ts +0 -9
- package/lib/core/solana-plugin.js +0 -79
- package/lib/core/solana-plugin.js.map +0 -1
- package/lib/core/solana-processor.d.ts +0 -40
- package/lib/core/solana-processor.js +0 -80
- package/lib/core/solana-processor.js.map +0 -1
- package/lib/solana-codegen/codegen.d.ts +0 -1
- package/lib/solana-codegen/codegen.js +0 -124
- package/lib/solana-codegen/codegen.js.map +0 -1
- package/lib/test-abi-code-gen.d.ts +0 -2
- package/lib/test-abi-code-gen.js +0 -20
- package/lib/test-abi-code-gen.js.map +0 -1
- package/src/abis/aptos/0x1.json +0 -9205
- package/src/abis/aptos/0x3.json +0 -1515
- package/src/aptos/api.ts +0 -11
- package/src/aptos/aptos-plugin.ts +0 -216
- package/src/aptos/aptos-processor.ts +0 -305
- package/src/aptos/context.ts +0 -74
- package/src/aptos/index.ts +0 -10
- package/src/aptos/models.ts +0 -34
- package/src/aptos/network.ts +0 -42
- package/src/aptos/runtime.ts +0 -13
- package/src/aptos/type-registry.ts +0 -187
- package/src/aptos/types.ts +0 -149
- package/src/aptos/utils.ts +0 -26
- package/src/aptos-codegen/codegen.ts +0 -428
- package/src/aptos-codegen/tsconfig.json +0 -9
- package/src/aptos-codegen/typegen.ts +0 -153
- package/src/builtin/aptos/0x1.ts +0 -4210
- package/src/builtin/aptos/0x3.ts +0 -888
- package/src/builtin/aptos/index.ts +0 -2
- package/src/builtin/solana/index.ts +0 -2
- package/src/builtin/solana/spl-token-processor.ts +0 -298
- package/src/builtin/solana/types.ts +0 -279
- package/src/builtin/solana/wormhole-processor.ts +0 -269
- package/src/core/solana-context.ts +0 -34
- package/src/core/solana-options.ts +0 -8
- package/src/core/solana-plugin.ts +0 -97
- package/src/core/solana-processor.ts +0 -102
- package/src/solana-codegen/codegen.ts +0 -129
- package/src/test-abi-code-gen.ts +0 -16
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from '@sentio/sdk'
|
|
2
|
-
import { Instruction } from '@project-serum/anchor'
|
|
3
|
-
import bs58 from 'bs58'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
deserialize,
|
|
7
|
-
field,
|
|
8
|
-
vec, fixedArray, option,
|
|
9
|
-
} from "@dao-xyz/borsh";
|
|
10
|
-
|
|
11
|
-
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/lib.rs#L100
|
|
12
|
-
enum TokenBridgeInstruction {
|
|
13
|
-
Initialize = 0,
|
|
14
|
-
AttestToken,
|
|
15
|
-
CompleteNative, // no args
|
|
16
|
-
CompleteWrapped, // no args
|
|
17
|
-
TransferWrapped,
|
|
18
|
-
TransferNative,
|
|
19
|
-
RegisterChain, // no args
|
|
20
|
-
CreateWrapped, // no args
|
|
21
|
-
UpgradeContract, // no args
|
|
22
|
-
CompleteNativeWithPayload, // no args
|
|
23
|
-
CompleteWrappedWithPayload, // no args
|
|
24
|
-
TransferWrappedWithPayload,
|
|
25
|
-
TransferNativeWithPayload,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
class TransferDataValues {
|
|
29
|
-
@field({ type: 'u32' })
|
|
30
|
-
nonce: number
|
|
31
|
-
|
|
32
|
-
@field({type: 'u64'})
|
|
33
|
-
amount: bigint
|
|
34
|
-
|
|
35
|
-
@field({type: 'u64'})
|
|
36
|
-
fee: bigint
|
|
37
|
-
|
|
38
|
-
@field({ type: fixedArray('u8', 32) })
|
|
39
|
-
target_address: number[];
|
|
40
|
-
|
|
41
|
-
@field({ type: 'u16' })
|
|
42
|
-
target_chain: number
|
|
43
|
-
|
|
44
|
-
constructor(data?: TransferDataValues) {
|
|
45
|
-
if(data){
|
|
46
|
-
Object.assign(this,data)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class TransferNativeWithPayloadData {
|
|
52
|
-
@field({ type: 'u32' })
|
|
53
|
-
nonce: number
|
|
54
|
-
|
|
55
|
-
@field({type: 'u64'})
|
|
56
|
-
amount: bigint
|
|
57
|
-
|
|
58
|
-
@field({type: 'u64'})
|
|
59
|
-
fee: bigint
|
|
60
|
-
|
|
61
|
-
@field({ type: fixedArray('u8', 32) })
|
|
62
|
-
target_address: number[];
|
|
63
|
-
|
|
64
|
-
@field({ type: 'u16' })
|
|
65
|
-
target_chain: number
|
|
66
|
-
|
|
67
|
-
@field({ type: vec('u8') })
|
|
68
|
-
payload: number[];
|
|
69
|
-
|
|
70
|
-
@field({type: option(fixedArray('u8', 32) )})
|
|
71
|
-
cpi_program_id?: number[]
|
|
72
|
-
|
|
73
|
-
constructor(data?: TransferNativeWithPayloadData) {
|
|
74
|
-
if(data){
|
|
75
|
-
Object.assign(this,data)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
class AttestTokenValues {
|
|
81
|
-
@field({ type: 'u32' })
|
|
82
|
-
nonce: number
|
|
83
|
-
|
|
84
|
-
constructor(data?: AttestTokenValues) {
|
|
85
|
-
if(data){
|
|
86
|
-
Object.assign(this,data)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
class InitializeDataValues {
|
|
92
|
-
@field({type: fixedArray('u8', 32) })
|
|
93
|
-
bridge: number[]
|
|
94
|
-
|
|
95
|
-
constructor(data?: InitializeDataValues) {
|
|
96
|
-
if(data){
|
|
97
|
-
Object.assign(this,data)
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export class TokenBridgeProcessor extends SolanaBaseProcessor {
|
|
103
|
-
|
|
104
|
-
// private readonly transferDataValues = [
|
|
105
|
-
// borsh.u32('nonce'),
|
|
106
|
-
// borsh.u64('amount'),
|
|
107
|
-
// borsh.u64('fee'),
|
|
108
|
-
// borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
109
|
-
// borsh.u16('target_chain')
|
|
110
|
-
// ]
|
|
111
|
-
// https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer_payload.rs#L170
|
|
112
|
-
// private readonly transferDataWithPayloadValues = [
|
|
113
|
-
// borsh.u32('nonce'),
|
|
114
|
-
// borsh.u64('amount'),
|
|
115
|
-
// borsh.array(borsh.u8(undefined), 32, 'target_address'),
|
|
116
|
-
// borsh.u16('target_chain'),
|
|
117
|
-
// borsh.vecU8('payload'),
|
|
118
|
-
// borsh.option(borsh.publicKey(undefined), 'cpi_program_id')
|
|
119
|
-
// ]
|
|
120
|
-
// private readonly attestTokenValues = [
|
|
121
|
-
// borsh.u32('nonce')
|
|
122
|
-
// ]
|
|
123
|
-
// private readonly initializeDataValues = [
|
|
124
|
-
// borsh.publicKey('bridge')
|
|
125
|
-
// ]
|
|
126
|
-
|
|
127
|
-
static bind(options: SolanaBindOptions): TokenBridgeProcessor {
|
|
128
|
-
if (options && !options.name) {
|
|
129
|
-
options.name = 'WormholeTokenBridge'
|
|
130
|
-
}
|
|
131
|
-
return new TokenBridgeProcessor(options)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
decodeInstruction: (rawInstruction: string) => Instruction | null = (ins) => {
|
|
135
|
-
const u8Arr = bs58.decode(ins)
|
|
136
|
-
if (u8Arr.length === 0) {
|
|
137
|
-
return null
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
let data: any
|
|
141
|
-
// wormhole pass intruction's enum value as its first instrcution data
|
|
142
|
-
switch (u8Arr[0]) {
|
|
143
|
-
case TokenBridgeInstruction.Initialize:
|
|
144
|
-
return {
|
|
145
|
-
data: '',
|
|
146
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
|
|
147
|
-
}
|
|
148
|
-
case TokenBridgeInstruction.TransferNative:
|
|
149
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), TransferDataValues)
|
|
150
|
-
|
|
151
|
-
// struct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
152
|
-
// data = borsh.struct(this.transferDataValues, 'TransferNativeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
153
|
-
return {
|
|
154
|
-
data,
|
|
155
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNative]
|
|
156
|
-
}
|
|
157
|
-
case TokenBridgeInstruction.TransferWrapped:
|
|
158
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), TransferDataValues)
|
|
159
|
-
|
|
160
|
-
// stuct is defined at: https://github.com/certusone/wormhole/blob/8818d4b8f0471095dd48fa6f5da9c315cbfc9b52/solana/modules/token_bridge/program/src/api/transfer.rs#L295
|
|
161
|
-
// data = borsh.struct(this.transferDataValues, 'TransferWrappedData').decode(Buffer.from(u8Arr.slice(1)))
|
|
162
|
-
return {
|
|
163
|
-
data,
|
|
164
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrapped]
|
|
165
|
-
}
|
|
166
|
-
case TokenBridgeInstruction.TransferNativeWithPayload:
|
|
167
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData)
|
|
168
|
-
|
|
169
|
-
// data = borsh.struct(this.transferDataWithPayloadValues, 'TransferNativeWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
170
|
-
return {
|
|
171
|
-
data,
|
|
172
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferNativeWithPayload]
|
|
173
|
-
}
|
|
174
|
-
case TokenBridgeInstruction.TransferWrappedWithPayload:
|
|
175
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), TransferNativeWithPayloadData)
|
|
176
|
-
|
|
177
|
-
// data = borsh.struct(this.transferDataWithPayloadValues, 'TransferWrappedWithPayloadData').decode(Buffer.from(u8Arr.slice(1)))
|
|
178
|
-
return {
|
|
179
|
-
data,
|
|
180
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.TransferWrappedWithPayload]
|
|
181
|
-
}
|
|
182
|
-
case TokenBridgeInstruction.Initialize:
|
|
183
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), InitializeDataValues)
|
|
184
|
-
|
|
185
|
-
// data = borsh.struct(this.initializeDataValues, 'InitializeData').decode(Buffer.from(u8Arr.slice(1)))
|
|
186
|
-
return {
|
|
187
|
-
data,
|
|
188
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.Initialize]
|
|
189
|
-
}
|
|
190
|
-
case TokenBridgeInstruction.AttestToken:
|
|
191
|
-
data = deserialize(Buffer.from(u8Arr.slice(1)), AttestTokenValues)
|
|
192
|
-
|
|
193
|
-
// data = borsh.struct(this.attestTokenValues, 'AttestTokenData').decode(Buffer.from(u8Arr.slice(1)))
|
|
194
|
-
return {
|
|
195
|
-
data,
|
|
196
|
-
name: TokenBridgeInstruction[TokenBridgeInstruction.AttestToken]
|
|
197
|
-
}
|
|
198
|
-
case TokenBridgeInstruction.CompleteNative:
|
|
199
|
-
case TokenBridgeInstruction.CompleteNativeWithPayload:
|
|
200
|
-
case TokenBridgeInstruction.CompleteWrapped:
|
|
201
|
-
case TokenBridgeInstruction.CompleteWrappedWithPayload:
|
|
202
|
-
case TokenBridgeInstruction.CreateWrapped:
|
|
203
|
-
case TokenBridgeInstruction.UpgradeContract:
|
|
204
|
-
case TokenBridgeInstruction.RegisterChain:
|
|
205
|
-
return {
|
|
206
|
-
data: '',
|
|
207
|
-
name: TokenBridgeInstruction[u8Arr[0]]
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
default:
|
|
211
|
-
return null
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
onInitialize(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
216
|
-
this.onInstruction('Initialize', (ins: Instruction, ctx, accounts: string[]) => {
|
|
217
|
-
if (ins) {
|
|
218
|
-
handler(ins.data, accounts, ctx)
|
|
219
|
-
}
|
|
220
|
-
})
|
|
221
|
-
return this
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
onAttestToken(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
225
|
-
this.onInstruction('AttestToken', (ins: Instruction, ctx, accounts: string[]) => {
|
|
226
|
-
if (ins) {
|
|
227
|
-
handler(ins.data, accounts, ctx)
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
return this
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
onTransferWrapped(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
235
|
-
this.onInstruction('TransferWrapped', (ins: Instruction, ctx, accounts: string[]) => {
|
|
236
|
-
if (ins) {
|
|
237
|
-
handler(ins.data, accounts, ctx)
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
return this
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
onTransferNativeWithPayload(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
244
|
-
this.onInstruction('TransferNativeWithPayload', (ins: Instruction, ctx, accounts: string[]) => {
|
|
245
|
-
if (ins) {
|
|
246
|
-
handler(ins.data, accounts, ctx)
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
return this
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
onTransferWrappedWithPaylod(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
253
|
-
this.onInstruction('TransferWrappedWithPaylod', (ins: Instruction, ctx, accounts: string[]) => {
|
|
254
|
-
if (ins) {
|
|
255
|
-
handler(ins.data, accounts, ctx)
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
return this
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
onTransferNative(handler: (args: any, accounts: string[], ctx: SolanaContext) => void): TokenBridgeProcessor {
|
|
262
|
-
this.onInstruction('TransferNative', (ins: Instruction, ctx, accounts: string[]) => {
|
|
263
|
-
if (ins) {
|
|
264
|
-
handler(ins.data, accounts, ctx)
|
|
265
|
-
}
|
|
266
|
-
})
|
|
267
|
-
return this
|
|
268
|
-
}
|
|
269
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { BaseContext } from './base-context'
|
|
2
|
-
import { Labels } from './metadata'
|
|
3
|
-
import { RecordMetaData } from '@sentio/sdk'
|
|
4
|
-
import { CHAIN_IDS } from '../utils/chain'
|
|
5
|
-
import { normalizeLabels } from './meter'
|
|
6
|
-
|
|
7
|
-
export class SolanaContext extends BaseContext {
|
|
8
|
-
network: string
|
|
9
|
-
address: string
|
|
10
|
-
programName: string
|
|
11
|
-
blockNumber: bigint
|
|
12
|
-
|
|
13
|
-
constructor(programName: string, network: string, address: string, slot: bigint) {
|
|
14
|
-
super()
|
|
15
|
-
this.network = network || CHAIN_IDS.SOLANA_MAINNET
|
|
16
|
-
this.programName = programName
|
|
17
|
-
this.address = address
|
|
18
|
-
this.blockNumber = slot
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getMetaData(name: string, labels: Labels): RecordMetaData {
|
|
22
|
-
return {
|
|
23
|
-
address: this.address,
|
|
24
|
-
contractName: this.programName,
|
|
25
|
-
blockNumber: this.blockNumber,
|
|
26
|
-
transactionIndex: 0,
|
|
27
|
-
transactionHash: '', // TODO add
|
|
28
|
-
logIndex: 0,
|
|
29
|
-
chainId: this.network,
|
|
30
|
-
name: name,
|
|
31
|
-
labels: normalizeLabels(labels),
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { Plugin, PluginManager } from '@sentio/base'
|
|
2
|
-
import {
|
|
3
|
-
ContractConfig,
|
|
4
|
-
Data_SolInstruction,
|
|
5
|
-
DataBinding,
|
|
6
|
-
HandlerType,
|
|
7
|
-
ProcessConfigResponse,
|
|
8
|
-
ProcessResult,
|
|
9
|
-
} from '@sentio/protos'
|
|
10
|
-
import { DEFAULT_MAX_BLOCK, mergeProcessResults, USER_PROCESSOR } from '../service'
|
|
11
|
-
|
|
12
|
-
import { ServerError, Status } from 'nice-grpc'
|
|
13
|
-
|
|
14
|
-
import { SolanaProcessorState } from './solana-processor'
|
|
15
|
-
import { Instruction as SolInstruction } from '@project-serum/anchor/dist/cjs/coder/borsh/instruction'
|
|
16
|
-
|
|
17
|
-
export class SolanaPlugin implements Plugin {
|
|
18
|
-
name: string = 'SolanaPlugin'
|
|
19
|
-
|
|
20
|
-
configure(config: ProcessConfigResponse): void {
|
|
21
|
-
// Part 2, prepare solana constractors
|
|
22
|
-
for (const solanaProcessor of SolanaProcessorState.INSTANCE.getValues()) {
|
|
23
|
-
const contractConfig: ContractConfig = {
|
|
24
|
-
processorType: USER_PROCESSOR,
|
|
25
|
-
contract: {
|
|
26
|
-
name: solanaProcessor.contractName,
|
|
27
|
-
chainId: solanaProcessor.network,
|
|
28
|
-
address: solanaProcessor.address,
|
|
29
|
-
abi: '',
|
|
30
|
-
},
|
|
31
|
-
logConfigs: [],
|
|
32
|
-
traceConfigs: [],
|
|
33
|
-
intervalConfigs: [],
|
|
34
|
-
startBlock: solanaProcessor.config.startSlot,
|
|
35
|
-
endBlock: DEFAULT_MAX_BLOCK,
|
|
36
|
-
instructionConfig: {
|
|
37
|
-
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
38
|
-
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
39
|
-
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
40
|
-
},
|
|
41
|
-
aptosEventConfigs: [],
|
|
42
|
-
aptosCallConfigs: [],
|
|
43
|
-
}
|
|
44
|
-
config.contractConfigs.push(contractConfig)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
supportedHandlers = [HandlerType.SOL_INSTRUCTION]
|
|
49
|
-
|
|
50
|
-
processBinding(request: DataBinding): Promise<ProcessResult> {
|
|
51
|
-
switch (request.handlerType) {
|
|
52
|
-
case HandlerType.SOL_INSTRUCTION:
|
|
53
|
-
return this.processSolInstruction(request)
|
|
54
|
-
default:
|
|
55
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async processSolInstruction(request: DataBinding): Promise<ProcessResult> {
|
|
60
|
-
if (!request.data) {
|
|
61
|
-
throw new ServerError(Status.INVALID_ARGUMENT, 'instruction data cannot be empty')
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const instruction = request.data.solInstruction || Data_SolInstruction.decode(request.data.raw) // JSON.parse(jsonString)
|
|
65
|
-
const promises: Promise<ProcessResult>[] = []
|
|
66
|
-
|
|
67
|
-
// Only have instruction handlers for solana processors
|
|
68
|
-
for (const processor of SolanaProcessorState.INSTANCE.getValues()) {
|
|
69
|
-
if (processor.address === instruction.programAccountId) {
|
|
70
|
-
let parsedInstruction: SolInstruction | null = null
|
|
71
|
-
if (instruction.parsed) {
|
|
72
|
-
parsedInstruction = processor.getParsedInstruction(instruction.parsed as { type: string; info: any })
|
|
73
|
-
} else if (instruction.instructionData) {
|
|
74
|
-
parsedInstruction = processor.getParsedInstruction(instruction.instructionData)
|
|
75
|
-
}
|
|
76
|
-
if (parsedInstruction == null) {
|
|
77
|
-
continue
|
|
78
|
-
}
|
|
79
|
-
const insHandler = processor.getInstructionHandler(parsedInstruction)
|
|
80
|
-
if (insHandler == null) {
|
|
81
|
-
continue
|
|
82
|
-
}
|
|
83
|
-
const res = await processor.handleInstruction(
|
|
84
|
-
parsedInstruction,
|
|
85
|
-
instruction.accounts,
|
|
86
|
-
insHandler,
|
|
87
|
-
instruction.slot
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
promises.push(Promise.resolve(res))
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return mergeProcessResults(await Promise.all(promises))
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
PluginManager.INSTANCE.register(new SolanaPlugin())
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { ProcessResult } from '@sentio/protos'
|
|
2
|
-
import { SolanaContext } from './solana-context'
|
|
3
|
-
import { Instruction } from '@project-serum/anchor'
|
|
4
|
-
import { SolanaBindOptions } from './solana-options'
|
|
5
|
-
import { ListStateStorage } from '@sentio/base'
|
|
6
|
-
import { CHAIN_IDS } from '../utils/chain'
|
|
7
|
-
|
|
8
|
-
type IndexConfigure = {
|
|
9
|
-
startSlot: bigint
|
|
10
|
-
endSlot?: bigint
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type SolanaInstructionHandler = (instruction: Instruction, ctx: SolanaContext, accounts?: string[]) => void
|
|
14
|
-
|
|
15
|
-
export class SolanaProcessorState extends ListStateStorage<SolanaBaseProcessor> {
|
|
16
|
-
static INSTANCE: SolanaProcessorState = new SolanaProcessorState()
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class SolanaBaseProcessor {
|
|
20
|
-
public instructionHandlerMap: Map<string, SolanaInstructionHandler> = new Map()
|
|
21
|
-
address: string
|
|
22
|
-
endpoint: string
|
|
23
|
-
contractName: string
|
|
24
|
-
network: string
|
|
25
|
-
processInnerInstruction: boolean
|
|
26
|
-
config: IndexConfigure = { startSlot: 0n }
|
|
27
|
-
decodeInstruction: (rawInstruction: string) => Instruction | null
|
|
28
|
-
fromParsedInstruction: (instruction: { type: string; info: any }) => Instruction | null
|
|
29
|
-
|
|
30
|
-
constructor(options: SolanaBindOptions) {
|
|
31
|
-
if (options) {
|
|
32
|
-
this.bind(options)
|
|
33
|
-
}
|
|
34
|
-
SolanaProcessorState.INSTANCE.addValue(this)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
bind(options: SolanaBindOptions) {
|
|
38
|
-
this.address = options.address
|
|
39
|
-
this.contractName = options.name || ''
|
|
40
|
-
this.processInnerInstruction = options.processInnerInstruction || false
|
|
41
|
-
this.network = options.network || CHAIN_IDS.SOLANA_MAINNET
|
|
42
|
-
if (options.startBlock) {
|
|
43
|
-
this.startSlot(options.startBlock)
|
|
44
|
-
}
|
|
45
|
-
if (options.endBlock) {
|
|
46
|
-
this.endBlock(options.endBlock)
|
|
47
|
-
}
|
|
48
|
-
this.endpoint = options.network || 'https://api.mainnet-beta.solana.com'
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public onInstruction(instructionName: string, handler: SolanaInstructionHandler) {
|
|
52
|
-
if (!this.isBind()) {
|
|
53
|
-
throw new Error("Processor doesn't bind to an address")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.instructionHandlerMap.set(instructionName, handler)
|
|
57
|
-
|
|
58
|
-
return this
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public getParsedInstruction(ins: string | { type: string; info: any }): Instruction | null {
|
|
62
|
-
if (ins) {
|
|
63
|
-
if ((ins as { type: string; info: any }).info) {
|
|
64
|
-
return this.fromParsedInstruction ? this.fromParsedInstruction(ins as { type: string; info: any }) : null
|
|
65
|
-
}
|
|
66
|
-
if (this.decodeInstruction != null) {
|
|
67
|
-
return this.decodeInstruction(ins as string)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return null
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public getInstructionHandler(parsedInstruction: Instruction): SolanaInstructionHandler | undefined {
|
|
74
|
-
return this.instructionHandlerMap.get(parsedInstruction.name)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// TODO this should be a async function
|
|
78
|
-
public handleInstruction(
|
|
79
|
-
parsedInstruction: Instruction,
|
|
80
|
-
accounts: string[],
|
|
81
|
-
handler: SolanaInstructionHandler,
|
|
82
|
-
slot: bigint
|
|
83
|
-
): ProcessResult {
|
|
84
|
-
const ctx = new SolanaContext(this.contractName, this.network, this.address, slot)
|
|
85
|
-
handler(parsedInstruction, ctx, accounts)
|
|
86
|
-
return ctx.getProcessResult()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public isBind() {
|
|
90
|
-
return this.address !== null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public startSlot(startSlot: bigint | number) {
|
|
94
|
-
this.config.startSlot = BigInt(startSlot)
|
|
95
|
-
return this
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public endBlock(endBlock: bigint | number) {
|
|
99
|
-
this.config.endSlot = BigInt(endBlock)
|
|
100
|
-
return this
|
|
101
|
-
}
|
|
102
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
|
-
import fs from 'fs'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
|
|
5
|
-
export function codeGenSolanaProcessor(abisDir: string, targetPath = path.join('src', 'types', 'solana')) {
|
|
6
|
-
if (!fs.existsSync(abisDir)) {
|
|
7
|
-
return
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const abisFiles = fs.readdirSync(abisDir)
|
|
11
|
-
|
|
12
|
-
if (abisFiles.length > 0) {
|
|
13
|
-
console.log(chalk.green('Generated Types for Solana'))
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
for (const file of abisFiles) {
|
|
17
|
-
if (path.extname(file) === '.json') {
|
|
18
|
-
if (!fs.existsSync(targetPath)) {
|
|
19
|
-
fs.mkdirSync(targetPath, { recursive: true })
|
|
20
|
-
}
|
|
21
|
-
const idlContent = fs.readFileSync(path.join(abisDir, file), 'utf-8')
|
|
22
|
-
const idlObj = JSON.parse(idlContent)
|
|
23
|
-
const idlName = idlObj.name
|
|
24
|
-
const idlFile = path.join(targetPath, idlName + '.ts')
|
|
25
|
-
fs.writeFileSync(idlFile, `export const ${idlName}_idl = ${idlContent}`)
|
|
26
|
-
fs.writeFileSync(path.join(targetPath, `${idlName}_processor.ts`), codeGenSolanaIdlProcessor(idlObj))
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function codeGenSolanaIdlProcessor(idlObj: any): string {
|
|
32
|
-
const idlName = idlObj.name
|
|
33
|
-
const idlNamePascalCase = toPascalCase(idlName)
|
|
34
|
-
const instructions: any[] = idlObj.instructions
|
|
35
|
-
return `import { BorshInstructionCoder, Instruction, Idl } from '@project-serum/anchor'
|
|
36
|
-
import { SolanaBaseProcessor, SolanaContext, SolanaBindOptions } from "@sentio/sdk"
|
|
37
|
-
import { ${idlName}_idl } from "./${idlName}"
|
|
38
|
-
import bs58 from 'bs58'
|
|
39
|
-
import { PublicKey } from '@solana/web3.js'
|
|
40
|
-
|
|
41
|
-
export class ${idlNamePascalCase}Processor extends SolanaBaseProcessor {
|
|
42
|
-
static bind(options: SolanaBindOptions): ${idlNamePascalCase}Processor {
|
|
43
|
-
if (options && !options.name) {
|
|
44
|
-
options.name = '${idlNamePascalCase}'
|
|
45
|
-
}
|
|
46
|
-
return new ${idlNamePascalCase}Processor(options)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
decodeInstruction: (rawInstruction: string) => Instruction | null = (rawInstruction) => {
|
|
50
|
-
const instructionCoder = new BorshInstructionCoder(${idlName}_idl as Idl)
|
|
51
|
-
const decodedIns = instructionCoder.decode(Buffer.from(bs58.decode(rawInstruction)))
|
|
52
|
-
return decodedIns
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
${instructions.map((ins) => codeGenSolanaInstruction(idlNamePascalCase, ins)).join('')}
|
|
56
|
-
}
|
|
57
|
-
`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function codeGenSolanaInstruction(idlName: string, ins: any): string {
|
|
61
|
-
const instructionName = ins.name
|
|
62
|
-
return `
|
|
63
|
-
on${instructionName.charAt(0).toUpperCase() + instructionName.slice(1)}(handler: (args: ${codeGenInstructionArgsType(
|
|
64
|
-
ins.args
|
|
65
|
-
)}, accounts: string[], ctx: SolanaContext) => void): ${idlName}Processor {
|
|
66
|
-
this.onInstruction('${instructionName}', (ins: Instruction, ctx, accounts: string[]) => {
|
|
67
|
-
const origin = ins.data as any
|
|
68
|
-
const data = ${codeGenInstructionArgs(ins.args)}
|
|
69
|
-
if (ins) {
|
|
70
|
-
handler(data, accounts, ctx)
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
return this
|
|
74
|
-
}
|
|
75
|
-
`
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function codeGenInstructionArgs(args: { name: string; type: string }[]): string {
|
|
79
|
-
return `{ ${args.map((arg) => codeGenInstructionArg(arg.name, arg.type)).join(', ')} }`
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function codeGenInstructionArg(name: string, type: string): string {
|
|
83
|
-
const mType = mapType(type)
|
|
84
|
-
if (mType === 'bigint') {
|
|
85
|
-
return `${name}: BigInt(origin.${name}.toString())`
|
|
86
|
-
}
|
|
87
|
-
return `${name}: origin.${name} as ${mType}`
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function codeGenInstructionArgsType(args: { name: string; type: string }[]): string {
|
|
91
|
-
return `{ ${args.map((arg) => arg.name + ': ' + mapType(arg.type)).join(', ')} }`
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Reference: https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/ts/src/program/namespace/types.ts#L104
|
|
95
|
-
function mapType(tpe: string): string {
|
|
96
|
-
switch (tpe) {
|
|
97
|
-
case 'publicKey':
|
|
98
|
-
return 'PublicKey'
|
|
99
|
-
case 'bool':
|
|
100
|
-
return 'boolean'
|
|
101
|
-
case 'string':
|
|
102
|
-
return 'string'
|
|
103
|
-
case 'u8':
|
|
104
|
-
case 'i8':
|
|
105
|
-
case 'u16':
|
|
106
|
-
case 'i16':
|
|
107
|
-
case 'u32':
|
|
108
|
-
case 'i32':
|
|
109
|
-
case 'f32':
|
|
110
|
-
case 'f64':
|
|
111
|
-
return 'number'
|
|
112
|
-
case 'u64':
|
|
113
|
-
case 'i64':
|
|
114
|
-
case 'u128':
|
|
115
|
-
case 'i128':
|
|
116
|
-
return 'bigint'
|
|
117
|
-
default:
|
|
118
|
-
return 'any'
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function toPascalCase(str: string) {
|
|
123
|
-
return `${str}`
|
|
124
|
-
.toLowerCase()
|
|
125
|
-
.replace(new RegExp(/[-_]+/, 'g'), ' ')
|
|
126
|
-
.replace(new RegExp(/[^\w\s]/, 'g'), '')
|
|
127
|
-
.replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${$2.toUpperCase() + $3}`)
|
|
128
|
-
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
|
|
129
|
-
}
|
package/src/test-abi-code-gen.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import path from 'path'
|
|
4
|
-
import { codeGenSolanaProcessor } from './solana-codegen/codegen'
|
|
5
|
-
import { codeGenAptosProcessor } from './aptos-codegen/codegen'
|
|
6
|
-
|
|
7
|
-
if (process.argv.length > 3) {
|
|
8
|
-
const abisDir = process.argv[2]
|
|
9
|
-
const targetDir = process.argv[3]
|
|
10
|
-
|
|
11
|
-
codeGenAptosProcessor(path.join(abisDir, 'aptos'), path.join(targetDir, 'aptos'))
|
|
12
|
-
codeGenSolanaProcessor(path.join(abisDir, 'solana'), path.join(targetDir, 'solana'))
|
|
13
|
-
} else {
|
|
14
|
-
console.error('Not enough argument')
|
|
15
|
-
process.exit(1)
|
|
16
|
-
}
|