@sentio/sdk 2.12.3 → 2.13.0-rc.10
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/aptos/aptos-chain-adapter.d.ts +14 -0
- package/lib/aptos/aptos-chain-adapter.js +69 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -0
- package/lib/aptos/aptos-plugin.js +2 -0
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +7 -7
- package/lib/aptos/aptos-processor.js +27 -26
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/builtin/0x1.d.ts +1244 -599
- package/lib/aptos/builtin/0x1.js +1939 -1458
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +241 -118
- package/lib/aptos/builtin/0x3.js +373 -333
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts +1 -1
- package/lib/aptos/codegen/codegen.js +6 -47
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/codegen/run.js +1 -1
- package/lib/aptos/codegen/run.js.map +1 -1
- package/lib/aptos/context.d.ts +5 -1
- package/lib/aptos/context.js +9 -2
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.d.ts +2 -1
- package/lib/aptos/ext/aptos-dex.js +1 -2
- package/lib/aptos/ext/aptos-dex.js.map +1 -1
- package/lib/aptos/index.d.ts +1 -0
- package/lib/aptos/index.js +1 -0
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +3 -11
- package/lib/aptos/models.js.map +1 -1
- package/lib/aptos/module-client.js +1 -1
- package/lib/aptos/module-client.js.map +1 -1
- package/lib/aptos/move-coder.d.ts +10 -10
- package/lib/aptos/move-coder.js +37 -18
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +4 -3
- package/lib/eth/base-processor-template.js +7 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +9 -8
- package/lib/eth/base-processor.js +13 -11
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/eth-plugin.js +2 -0
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +7 -2
- package/lib/eth/eth.js +8 -1
- package/lib/eth/eth.js.map +1 -1
- package/lib/move/abstract-codegen.d.ts +11 -11
- package/lib/move/abstract-codegen.js +60 -23
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +19 -25
- package/lib/move/abstract-move-coder.js +74 -51
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +11 -0
- package/lib/move/chain-adapter.js +3 -0
- package/lib/move/chain-adapter.js.map +1 -0
- package/lib/move/index.d.ts +1 -0
- package/lib/move/index.js +1 -0
- package/lib/move/index.js.map +1 -1
- package/lib/move/types.d.ts +28 -1
- package/lib/move/types.js +65 -16
- package/lib/move/types.js.map +1 -1
- package/lib/sui/builtin/0x1.d.ts +37 -18
- package/lib/sui/builtin/0x1.js +58 -32
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +299 -149
- package/lib/sui/builtin/0x2.js +463 -322
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +169 -94
- package/lib/sui/builtin/0x3.js +229 -272
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts +1 -1
- package/lib/sui/codegen/codegen.js +10 -36
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/codegen/run.js +1 -1
- package/lib/sui/codegen/run.js.map +1 -1
- package/lib/sui/context.d.ts +5 -1
- package/lib/sui/context.js +8 -1
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/index.d.ts +1 -0
- package/lib/sui/index.js +1 -0
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +3 -11
- package/lib/sui/models.js.map +1 -1
- package/lib/sui/move-coder.d.ts +15 -15
- package/lib/sui/move-coder.js +43 -39
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +14 -0
- package/lib/sui/sui-chain-adapter.js +69 -0
- package/lib/sui/sui-chain-adapter.js.map +1 -0
- package/lib/sui/sui-plugin.js +1 -0
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +8 -5
- package/lib/sui/sui-processor.js +23 -14
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +0 -2
- package/lib/sui/utils.js +0 -6
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/aptos-facet.d.ts +2 -2
- package/lib/testing/aptos-facet.js +14 -21
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +2 -2
- package/lib/testing/sui-facet.js +16 -26
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +81 -0
- package/src/aptos/aptos-plugin.ts +2 -0
- package/src/aptos/aptos-processor.ts +58 -43
- package/src/aptos/builtin/0x1.ts +2858 -616
- package/src/aptos/builtin/0x3.ts +543 -120
- package/src/aptos/codegen/codegen.ts +13 -57
- package/src/aptos/codegen/run.ts +1 -1
- package/src/aptos/context.ts +10 -2
- package/src/aptos/ext/aptos-dex.ts +4 -12
- package/src/aptos/index.ts +2 -0
- package/src/aptos/models.ts +3 -13
- package/src/aptos/module-client.ts +1 -1
- package/src/aptos/move-coder.ts +48 -25
- package/src/eth/base-processor-template.ts +20 -10
- package/src/eth/base-processor.ts +45 -25
- package/src/eth/eth-plugin.ts +2 -0
- package/src/eth/eth.ts +15 -2
- package/src/move/abstract-codegen.ts +75 -38
- package/src/move/abstract-move-coder.ts +87 -75
- package/src/move/chain-adapter.ts +17 -0
- package/src/move/index.ts +1 -0
- package/src/move/types.ts +83 -17
- package/src/sui/builtin/0x1.ts +75 -20
- package/src/sui/builtin/0x2.ts +694 -150
- package/src/sui/builtin/0x3.ts +360 -95
- package/src/sui/codegen/codegen.ts +17 -43
- package/src/sui/codegen/run.ts +1 -1
- package/src/sui/context.ts +9 -1
- package/src/sui/index.ts +1 -0
- package/src/sui/models.ts +3 -13
- package/src/sui/move-coder.ts +58 -53
- package/src/sui/sui-chain-adapter.ts +86 -0
- package/src/sui/sui-plugin.ts +1 -0
- package/src/sui/sui-processor.ts +41 -28
- package/src/sui/utils.ts +0 -8
- package/src/testing/aptos-facet.ts +13 -27
- package/src/testing/sui-facet.ts +15 -30
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.js +0 -10
- package/lib/aptos/utils.js.map +0 -1
- package/src/aptos/utils.ts +0 -11
@@ -0,0 +1,81 @@
|
|
1
|
+
import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'
|
2
|
+
import { Event, MoveModuleBytecode, MoveResource, toInternalModule } from './move-types.js'
|
3
|
+
import { AptosNetwork } from './network.js'
|
4
|
+
import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'
|
5
|
+
import { AptosClient } from 'aptos-sdk'
|
6
|
+
|
7
|
+
export class AptosChainAdapter extends ChainAdapter<AptosNetwork, MoveModuleBytecode, Event | MoveResource> {
|
8
|
+
static INSTANCE = new AptosChainAdapter()
|
9
|
+
|
10
|
+
async fetchModules(account: string, network: AptosNetwork): Promise<MoveModuleBytecode[]> {
|
11
|
+
const client = getRpcClient(network)
|
12
|
+
return await client.getAccountModules(account)
|
13
|
+
}
|
14
|
+
|
15
|
+
async fetchModule(account: string, module: string, network: AptosNetwork): Promise<MoveModuleBytecode> {
|
16
|
+
const client = getRpcClient(network)
|
17
|
+
return await client.getAccountModule(account, module)
|
18
|
+
}
|
19
|
+
|
20
|
+
toInternalModules(modules: MoveModuleBytecode[]): InternalMoveModule[] {
|
21
|
+
return modules.flatMap((m) => (m.abi ? [toInternalModule(m)] : []))
|
22
|
+
}
|
23
|
+
|
24
|
+
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
25
|
+
if (params.length === 0) {
|
26
|
+
return params
|
27
|
+
}
|
28
|
+
if (params[0].qname === 'signer' && params[0].reference) {
|
29
|
+
params = params.slice(1)
|
30
|
+
}
|
31
|
+
return params
|
32
|
+
}
|
33
|
+
|
34
|
+
getEventStructs(module: InternalMoveModule) {
|
35
|
+
const qname = moduleQname(module)
|
36
|
+
const structMap = new Map<string, InternalMoveStruct>()
|
37
|
+
const eventMap = new Map<string, InternalMoveStruct>()
|
38
|
+
|
39
|
+
for (const struct of module.structs) {
|
40
|
+
structMap.set(qname + SPLITTER + struct.name, struct)
|
41
|
+
}
|
42
|
+
|
43
|
+
for (const struct of module.structs) {
|
44
|
+
for (const field of struct.fields) {
|
45
|
+
const t = field.type
|
46
|
+
if (t.qname === '0x1::event::EventHandle') {
|
47
|
+
const event = t.typeArgs[0].qname
|
48
|
+
const eventStruct = structMap.get(event)
|
49
|
+
if (eventStruct) {
|
50
|
+
eventMap.set(event, eventStruct)
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
return eventMap
|
57
|
+
}
|
58
|
+
|
59
|
+
getType(data: Event | MoveResource): string {
|
60
|
+
return data.type
|
61
|
+
}
|
62
|
+
|
63
|
+
getData(data: Event | MoveResource) {
|
64
|
+
if ('data' in data && 'type' in data) {
|
65
|
+
return data.data
|
66
|
+
}
|
67
|
+
return data
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
function getRpcClient(network: AptosNetwork): AptosClient {
|
72
|
+
return new AptosClient(getRpcEndpoint(network))
|
73
|
+
}
|
74
|
+
|
75
|
+
function getRpcEndpoint(network: AptosNetwork): string {
|
76
|
+
switch (network) {
|
77
|
+
case AptosNetwork.TEST_NET:
|
78
|
+
return 'https://testnet.aptoslabs.com/'
|
79
|
+
}
|
80
|
+
return 'https://mainnet.aptoslabs.com/'
|
81
|
+
}
|
@@ -96,6 +96,7 @@ export class AptosPlugin extends Plugin {
|
|
96
96
|
minutesInterval: handler.timeIntervalInMinutes,
|
97
97
|
slot: 0,
|
98
98
|
slotInterval: handler.versionInterval,
|
99
|
+
fetchConfig: undefined,
|
99
100
|
},
|
100
101
|
type: handler.type || '',
|
101
102
|
})
|
@@ -107,6 +108,7 @@ export class AptosPlugin extends Plugin {
|
|
107
108
|
minutesInterval: handler.timeIntervalInMinutes,
|
108
109
|
slot: 0,
|
109
110
|
slotInterval: handler.versionInterval,
|
111
|
+
fetchConfig: undefined,
|
110
112
|
},
|
111
113
|
type: handler.type || '',
|
112
114
|
ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { MoveResource, Transaction_UserTransaction, TransactionPayload_EntryFunctionPayload } from './move-types.js'
|
2
2
|
|
3
|
-
import {
|
3
|
+
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
4
4
|
import { AptosBindOptions, AptosNetwork, getChainId } from './network.js'
|
5
5
|
import { AptosContext, AptosResourcesContext } from './context.js'
|
6
6
|
import { EventInstance } from './models.js'
|
7
|
-
import { ListStateStorage } from '@sentio/runtime'
|
7
|
+
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
|
8
8
|
import {
|
9
9
|
MoveFetchConfig,
|
10
10
|
Data_AptResource,
|
@@ -14,7 +14,13 @@ import {
|
|
14
14
|
Data_AptCall,
|
15
15
|
} from '@sentio/protos'
|
16
16
|
import { ServerError, Status } from 'nice-grpc'
|
17
|
-
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
|
17
|
+
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'
|
18
|
+
import { PromiseOrVoid } from '../core/index.js'
|
19
|
+
|
20
|
+
const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
|
21
|
+
resourceChanges: false,
|
22
|
+
allEvents: true,
|
23
|
+
}
|
18
24
|
|
19
25
|
type IndexConfigure = {
|
20
26
|
address: string
|
@@ -39,12 +45,14 @@ export class AptosBaseProcessor {
|
|
39
45
|
config: IndexConfigure
|
40
46
|
eventHandlers: EventHandler<Data_AptEvent>[] = []
|
41
47
|
callHandlers: CallHandler<Data_AptCall>[] = []
|
48
|
+
coder: MoveCoder
|
42
49
|
|
43
50
|
constructor(moduleName: string, options: AptosBindOptions) {
|
44
51
|
this.moduleName = moduleName
|
45
52
|
this.config = configure(options)
|
46
53
|
AptosProcessorState.INSTANCE.addValue(this)
|
47
|
-
this.
|
54
|
+
this.coder = defaultMoveCoder(this.config.network)
|
55
|
+
// this.loadTypes(this.coder)
|
48
56
|
}
|
49
57
|
|
50
58
|
// getABI(): MoveModule | undefined {
|
@@ -52,11 +60,11 @@ export class AptosBaseProcessor {
|
|
52
60
|
// }
|
53
61
|
|
54
62
|
public onTransaction(
|
55
|
-
handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) =>
|
63
|
+
handler: (transaction: Transaction_UserTransaction, ctx: AptosContext) => PromiseOrVoid,
|
56
64
|
includedFailed = false,
|
57
|
-
fetchConfig?: MoveFetchConfig
|
65
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
58
66
|
): this {
|
59
|
-
const _fetchConfig =
|
67
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
60
68
|
|
61
69
|
// const address = this.config.address
|
62
70
|
// const moduleName = this.moduleName
|
@@ -72,7 +80,8 @@ export class AptosBaseProcessor {
|
|
72
80
|
processor.config.network,
|
73
81
|
processor.config.address,
|
74
82
|
BigInt(data.transaction.version),
|
75
|
-
call
|
83
|
+
call,
|
84
|
+
0
|
76
85
|
)
|
77
86
|
await handler(call, ctx)
|
78
87
|
return ctx.getProcessResult()
|
@@ -86,10 +95,10 @@ export class AptosBaseProcessor {
|
|
86
95
|
public onMoveEvent(
|
87
96
|
handler: (event: EventInstance, ctx: AptosContext) => void,
|
88
97
|
filter: EventFilter | EventFilter[],
|
89
|
-
fetchConfig?: MoveFetchConfig
|
98
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
90
99
|
): this {
|
91
100
|
let _filters: EventFilter[] = []
|
92
|
-
const _fetchConfig =
|
101
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
93
102
|
|
94
103
|
if (Array.isArray(filter)) {
|
95
104
|
_filters = filter
|
@@ -97,10 +106,10 @@ export class AptosBaseProcessor {
|
|
97
106
|
_filters.push(filter)
|
98
107
|
}
|
99
108
|
|
100
|
-
// const address = this.config.address
|
101
109
|
// const moduleName = this.moduleName
|
102
110
|
|
103
111
|
const processor = this
|
112
|
+
const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))
|
104
113
|
|
105
114
|
this.eventHandlers.push({
|
106
115
|
handler: async function (data) {
|
@@ -112,23 +121,28 @@ export class AptosBaseProcessor {
|
|
112
121
|
throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')
|
113
122
|
}
|
114
123
|
|
115
|
-
const
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
124
|
+
const processResults = []
|
125
|
+
for (const [idx, evt] of txn.events.entries()) {
|
126
|
+
const typeQname = parseMoveType(evt.type).qname
|
127
|
+
if (!allEventType.has(typeQname)) {
|
128
|
+
continue
|
129
|
+
}
|
130
|
+
|
131
|
+
const ctx = new AptosContext(
|
132
|
+
processor.moduleName,
|
133
|
+
processor.config.network,
|
134
|
+
processor.config.address,
|
135
|
+
BigInt(txn.version),
|
136
|
+
txn,
|
137
|
+
idx
|
138
|
+
)
|
126
139
|
const eventInstance = evt as EventInstance
|
127
|
-
const decoded =
|
140
|
+
const decoded = await processor.coder.decodeEvent<any>(eventInstance)
|
128
141
|
await handler(decoded || eventInstance, ctx)
|
142
|
+
processResults.push(ctx.getProcessResult())
|
129
143
|
}
|
130
144
|
|
131
|
-
return
|
145
|
+
return mergeProcessResults(processResults)
|
132
146
|
},
|
133
147
|
filters: _filters,
|
134
148
|
fetchConfig: _fetchConfig,
|
@@ -137,12 +151,12 @@ export class AptosBaseProcessor {
|
|
137
151
|
}
|
138
152
|
|
139
153
|
public onEntryFunctionCall(
|
140
|
-
handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) =>
|
154
|
+
handler: (call: TransactionPayload_EntryFunctionPayload, ctx: AptosContext) => PromiseOrVoid,
|
141
155
|
filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
|
142
|
-
fetchConfig?: MoveFetchConfig
|
156
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
143
157
|
): this {
|
144
158
|
let _filters: FunctionNameAndCallFilter[] = []
|
145
|
-
const _fetchConfig =
|
159
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
146
160
|
|
147
161
|
if (Array.isArray(filter)) {
|
148
162
|
_filters = filter
|
@@ -166,11 +180,12 @@ export class AptosBaseProcessor {
|
|
166
180
|
processor.config.network,
|
167
181
|
processor.config.address,
|
168
182
|
BigInt(tx.version),
|
169
|
-
tx
|
183
|
+
tx,
|
184
|
+
0
|
170
185
|
)
|
171
186
|
if (tx) {
|
172
187
|
const payload = tx.payload as TransactionPayload_EntryFunctionPayload
|
173
|
-
const decoded =
|
188
|
+
const decoded = await processor.coder.decodeFunctionPayload(payload)
|
174
189
|
await handler(decoded, ctx)
|
175
190
|
}
|
176
191
|
return ctx.getProcessResult()
|
@@ -185,17 +200,17 @@ export class AptosBaseProcessor {
|
|
185
200
|
return getChainId(this.config.network)
|
186
201
|
}
|
187
202
|
|
188
|
-
loadTypes(registry: MoveCoder) {
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
}
|
194
|
-
|
195
|
-
protected loadTypesInternal(registry: MoveCoder) {
|
196
|
-
|
197
|
-
|
198
|
-
}
|
203
|
+
// loadTypes(registry: MoveCoder) {
|
204
|
+
// if (registry.contains(this.config.address, this.moduleName)) {
|
205
|
+
// return
|
206
|
+
// }
|
207
|
+
// this.loadTypesInternal(registry)
|
208
|
+
// }
|
209
|
+
//
|
210
|
+
// protected loadTypesInternal(registry: MoveCoder) {
|
211
|
+
// // should be override by subclass
|
212
|
+
// console.log('')
|
213
|
+
// }
|
199
214
|
}
|
200
215
|
|
201
216
|
export class AptosAccountProcessorState extends ListStateStorage<AptosResourcesProcessor> {
|
@@ -221,7 +236,7 @@ export class AptosResourcesProcessor {
|
|
221
236
|
}
|
222
237
|
|
223
238
|
private onInterval(
|
224
|
-
handler: (resources: MoveResource[], ctx: AptosResourcesContext) =>
|
239
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
|
225
240
|
timeInterval: HandleInterval | undefined,
|
226
241
|
versionInterval: HandleInterval | undefined,
|
227
242
|
type: string | undefined
|
@@ -251,7 +266,7 @@ export class AptosResourcesProcessor {
|
|
251
266
|
}
|
252
267
|
|
253
268
|
public onTimeInterval(
|
254
|
-
handler: (resources: MoveResource[], ctx: AptosResourcesContext) =>
|
269
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
|
255
270
|
timeIntervalInMinutes = 60,
|
256
271
|
backfillTimeIntervalInMinutes = 240,
|
257
272
|
type?: string
|
@@ -268,7 +283,7 @@ export class AptosResourcesProcessor {
|
|
268
283
|
}
|
269
284
|
|
270
285
|
public onVersionInterval(
|
271
|
-
handler: (resources: MoveResource[], ctx: AptosResourcesContext) =>
|
286
|
+
handler: (resources: MoveResource[], ctx: AptosResourcesContext) => PromiseOrVoid,
|
272
287
|
versionInterval = 100000,
|
273
288
|
backfillVersionInterval = 400000,
|
274
289
|
typePrefix?: string
|