@sentio/sdk 2.13.0-rc.5 → 2.13.0-rc.7
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 +4 -2
- package/lib/aptos/aptos-chain-adapter.js +9 -0
- package/lib/aptos/aptos-chain-adapter.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +5 -4
- package/lib/aptos/aptos-processor.js +9 -5
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/ext/aptos-dex.js +1 -1
- package/lib/aptos/ext/aptos-dex.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 +6 -6
- package/lib/aptos/move-coder.js +12 -6
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/eth/base-processor.d.ts +8 -8
- package/lib/eth/base-processor.js +0 -1
- package/lib/eth/base-processor.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 +6 -6
- package/lib/move/abstract-codegen.js.map +1 -1
- package/lib/move/abstract-move-coder.d.ts +15 -20
- package/lib/move/abstract-move-coder.js +68 -51
- package/lib/move/abstract-move-coder.js.map +1 -1
- package/lib/move/chain-adapter.d.ts +3 -1
- package/lib/move/chain-adapter.js.map +1 -1
- package/lib/move/types.d.ts +6 -0
- package/lib/move/types.js +20 -0
- package/lib/move/types.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +1 -4
- package/lib/sui/builtin/0x2.js +0 -5
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/codegen/codegen.js +3 -0
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +1 -0
- package/lib/sui/context.js +2 -0
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/move-coder.d.ts +9 -9
- package/lib/sui/move-coder.js +19 -28
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/sui-chain-adapter.d.ts +4 -2
- package/lib/sui/sui-chain-adapter.js +22 -1
- package/lib/sui/sui-chain-adapter.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +4 -3
- package/lib/sui/sui-processor.js +8 -4
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -4
- package/src/aptos/aptos-chain-adapter.ts +13 -2
- package/src/aptos/aptos-processor.ts +16 -10
- package/src/aptos/codegen/codegen.ts +2 -2
- package/src/aptos/ext/aptos-dex.ts +4 -1
- package/src/aptos/module-client.ts +1 -1
- package/src/aptos/move-coder.ts +20 -12
- package/src/eth/base-processor.ts +8 -9
- package/src/eth/eth.ts +15 -2
- package/src/move/abstract-codegen.ts +6 -6
- package/src/move/abstract-move-coder.ts +77 -67
- package/src/move/chain-adapter.ts +4 -1
- package/src/move/types.ts +21 -0
- package/src/sui/builtin/0x2.ts +1 -4
- package/src/sui/codegen/codegen.ts +5 -2
- package/src/sui/context.ts +2 -0
- package/src/sui/move-coder.ts +34 -42
- package/src/sui/sui-chain-adapter.ts +32 -2
- package/src/sui/sui-processor.ts +13 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
import { SuiMoveNormalizedModule } from '@mysten/sui.js'
|
1
|
+
import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject } from '@mysten/sui.js'
|
2
2
|
|
3
3
|
import { SuiNetwork } from '../network.js'
|
4
4
|
import * as fs from 'fs'
|
@@ -18,7 +18,7 @@ export async function codegen(abisDir: string, outDir = join('src', 'types', 'su
|
|
18
18
|
console.log(chalk.green(`Generated ${numFiles} for Sui`))
|
19
19
|
}
|
20
20
|
|
21
|
-
class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModule,
|
21
|
+
class SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
22
22
|
ADDRESS_TYPE = 'SuiAddress'
|
23
23
|
MAIN_NET = SuiNetwork.MAIN_NET
|
24
24
|
TEST_NET = SuiNetwork.TEST_NET
|
@@ -45,6 +45,8 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModule, SuiNetwork> {
|
|
45
45
|
return `export type ${struct.name} = string`
|
46
46
|
case '0x2::coin::Coin':
|
47
47
|
return `export type ${struct.name}<T> = string`
|
48
|
+
case '0x2::balance::Balance':
|
49
|
+
return `export type ${struct.name}<T> = string`
|
48
50
|
case '0x1::option::Option':
|
49
51
|
return `export type Option<T> = T | undefined`
|
50
52
|
}
|
@@ -56,6 +58,7 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModule, SuiNetwork> {
|
|
56
58
|
case '0x2::object::ID':
|
57
59
|
case '0x2::coin::Coin':
|
58
60
|
case '0x1::option::Option':
|
61
|
+
case '0x2::balance::Balance':
|
59
62
|
return ''
|
60
63
|
}
|
61
64
|
return super.generateOnEvents(module, struct)
|
package/src/sui/context.ts
CHANGED
@@ -60,6 +60,7 @@ export class SuiObjectsContext extends BaseContext {
|
|
60
60
|
network: SuiNetwork
|
61
61
|
slot: bigint
|
62
62
|
timestamp: Date
|
63
|
+
coder: MoveCoder
|
63
64
|
|
64
65
|
constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date) {
|
65
66
|
super()
|
@@ -67,6 +68,7 @@ export class SuiObjectsContext extends BaseContext {
|
|
67
68
|
this.network = network
|
68
69
|
this.slot = slot
|
69
70
|
this.timestamp = timestamp
|
71
|
+
this.coder = defaultMoveCoder(network)
|
70
72
|
}
|
71
73
|
|
72
74
|
getChainId(): string {
|
package/src/sui/move-coder.ts
CHANGED
@@ -1,18 +1,12 @@
|
|
1
|
-
import { TypedEventInstance, TypedFunctionPayload
|
2
|
-
import { AbstractMoveCoder
|
3
|
-
import {
|
4
|
-
MoveCallSuiTransaction,
|
5
|
-
SuiCallArg,
|
6
|
-
SuiEvent,
|
7
|
-
SuiMoveNormalizedModule,
|
8
|
-
SuiMoveObject,
|
9
|
-
SuiRawData,
|
10
|
-
} from '@mysten/sui.js'
|
1
|
+
import { TypedEventInstance, TypedFunctionPayload } from './models.js'
|
2
|
+
import { AbstractMoveCoder } from '../move/abstract-move-coder.js'
|
3
|
+
import { MoveCallSuiTransaction, SuiCallArg, SuiEvent, SuiMoveNormalizedModule, SuiMoveObject } from '@mysten/sui.js'
|
11
4
|
import { toInternalModule } from './move-types.js'
|
12
5
|
import { SPLITTER, TypeDescriptor } from '../move/index.js'
|
13
6
|
import { dynamic_field } from './builtin/0x2.js'
|
14
7
|
import { SuiNetwork } from './network.js'
|
15
8
|
import { SuiChainAdapter } from './sui-chain-adapter.js'
|
9
|
+
import { InternalMoveModule } from '../move/internal-models.js'
|
16
10
|
|
17
11
|
export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
18
12
|
constructor(network: SuiNetwork) {
|
@@ -20,60 +14,58 @@ export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedMo
|
|
20
14
|
this.adapter = new SuiChainAdapter()
|
21
15
|
}
|
22
16
|
|
23
|
-
load(module: SuiMoveNormalizedModule) {
|
24
|
-
|
25
|
-
|
17
|
+
load(module: SuiMoveNormalizedModule): InternalMoveModule {
|
18
|
+
let m = this.moduleMapping.get(module.address + '::' + module.name)
|
19
|
+
if (m) {
|
20
|
+
return m
|
26
21
|
}
|
27
|
-
|
22
|
+
m = toInternalModule(module)
|
23
|
+
this.loadInternal(m)
|
24
|
+
return m
|
28
25
|
}
|
29
26
|
|
30
27
|
decode(data: any, type: TypeDescriptor): any {
|
31
28
|
switch (type.qname) {
|
32
29
|
case '0x2::object::ID':
|
33
30
|
case '0x2::coin::Coin':
|
31
|
+
case '0x2::balance::Balance':
|
34
32
|
return data
|
35
33
|
case '0x1::option::Option':
|
36
|
-
|
37
|
-
|
34
|
+
if (data === null) {
|
35
|
+
return data
|
36
|
+
}
|
37
|
+
return this.decode(data, type.typeArgs[0])
|
38
38
|
default:
|
39
39
|
return super.decode(data, type)
|
40
40
|
}
|
41
41
|
}
|
42
42
|
|
43
|
-
|
44
|
-
if (SuiEvent.is(val)) {
|
45
|
-
return {
|
46
|
-
...val,
|
47
|
-
data: val.parsedJson as any,
|
48
|
-
}
|
49
|
-
}
|
50
|
-
if (SuiRawData.is(val)) {
|
51
|
-
return {
|
52
|
-
...val,
|
53
|
-
data: val.fields as any,
|
54
|
-
}
|
55
|
-
}
|
56
|
-
return val as any
|
57
|
-
}
|
58
|
-
|
59
|
-
decodeEvent<T>(event: SuiEvent): TypedEventInstance<T> | undefined {
|
43
|
+
decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {
|
60
44
|
return this.decodedStruct<T>(event) as any
|
61
45
|
}
|
62
|
-
filterAndDecodeEvents<T>(typeQname: string, resources: SuiEvent[]): TypedEventInstance<T>[] {
|
63
|
-
return this.filterAndDecodeStruct(typeQname, resources)
|
46
|
+
filterAndDecodeEvents<T>(typeQname: string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {
|
47
|
+
return this.filterAndDecodeStruct(typeQname, resources) as any
|
64
48
|
}
|
65
49
|
|
66
|
-
|
67
|
-
|
50
|
+
async getDynamicFields(
|
51
|
+
objects: SuiMoveObject[],
|
52
|
+
keyTypeMatcher: string = 'any',
|
53
|
+
valueTypeMatcher: string = 'any'
|
54
|
+
): Promise<dynamic_field.Field<any, any>[]> {
|
55
|
+
const res = (await this.filterAndDecodeObjects(
|
56
|
+
`0x2::dynamic_field::Field<${keyTypeMatcher}, ${valueTypeMatcher}>`,
|
57
|
+
objects
|
58
|
+
)) as any[]
|
59
|
+
return res.map((o) => o.data_decoded) as any
|
68
60
|
}
|
69
61
|
|
70
|
-
filterAndDecodeObjects
|
71
|
-
return this.filterAndDecodeStruct(
|
62
|
+
filterAndDecodeObjects(typeMatcher: string, objects: SuiMoveObject[]): Promise<any[]> {
|
63
|
+
return this.filterAndDecodeStruct(typeMatcher, objects) as any
|
72
64
|
}
|
73
65
|
|
74
|
-
decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): MoveCallSuiTransaction {
|
66
|
+
async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {
|
75
67
|
const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)
|
76
|
-
const func = this.getMoveFunction(functionType)
|
68
|
+
const func = await this.getMoveFunction(functionType)
|
77
69
|
const params = this.adapter.getMeaningfulFunctionParams(func.params)
|
78
70
|
const args = []
|
79
71
|
for (const value of payload.arguments || []) {
|
@@ -95,7 +87,7 @@ export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedMo
|
|
95
87
|
}
|
96
88
|
}
|
97
89
|
|
98
|
-
const argumentsTyped = this.decodeArray(args, params)
|
90
|
+
const argumentsTyped = await this.decodeArray(args, params)
|
99
91
|
return {
|
100
92
|
...payload,
|
101
93
|
arguments_decoded: argumentsTyped,
|
@@ -2,9 +2,16 @@ import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/ind
|
|
2
2
|
import { toInternalModule } from './move-types.js'
|
3
3
|
import { SuiNetwork } from './network.js'
|
4
4
|
import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
Connection,
|
7
|
+
JsonRpcProvider,
|
8
|
+
SuiMoveNormalizedModule,
|
9
|
+
SuiEvent,
|
10
|
+
SuiMoveObject,
|
11
|
+
SuiParsedData,
|
12
|
+
} from '@mysten/sui.js'
|
6
13
|
|
7
|
-
export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule> {
|
14
|
+
export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
8
15
|
static INSTANCE = new SuiChainAdapter()
|
9
16
|
|
10
17
|
async fetchModule(account: string, module: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule> {
|
@@ -41,6 +48,29 @@ export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedM
|
|
41
48
|
}
|
42
49
|
return eventMap
|
43
50
|
}
|
51
|
+
|
52
|
+
getType(base: SuiEvent | SuiMoveObject): string {
|
53
|
+
return base.type
|
54
|
+
}
|
55
|
+
|
56
|
+
getData(val: SuiEvent | SuiMoveObject) {
|
57
|
+
if (SuiEvent.is(val)) {
|
58
|
+
return val.parsedJson as any
|
59
|
+
}
|
60
|
+
if (SuiParsedData.is(val)) {
|
61
|
+
return val.fields as any
|
62
|
+
}
|
63
|
+
// if (SuiMoveObject.is(val)) {
|
64
|
+
// return val.fields as any
|
65
|
+
// }
|
66
|
+
// This may not be perfect, just think everything has
|
67
|
+
if ('fields' in val) {
|
68
|
+
if ('type' in val && Object.keys(val).length === 2) {
|
69
|
+
return val.fields as any
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return val as any
|
73
|
+
}
|
44
74
|
}
|
45
75
|
|
46
76
|
function getRpcEndpoint(network: SuiNetwork): string {
|
package/src/sui/sui-processor.ts
CHANGED
@@ -22,8 +22,14 @@ import {
|
|
22
22
|
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'
|
23
23
|
import { getMoveCalls } from './utils.js'
|
24
24
|
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
25
|
+
import { PromiseOrVoid } from '../core/index.js'
|
25
26
|
// import { dynamic_field } from './builtin/0x2.js'
|
26
27
|
|
28
|
+
const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
|
29
|
+
resourceChanges: false,
|
30
|
+
allEvents: true,
|
31
|
+
}
|
32
|
+
|
27
33
|
class IndexConfigure {
|
28
34
|
address: string
|
29
35
|
network: SuiNetwork
|
@@ -71,7 +77,7 @@ export class SuiBaseProcessor {
|
|
71
77
|
fetchConfig?: Partial<MoveFetchConfig>
|
72
78
|
): SuiBaseProcessor {
|
73
79
|
let _filters: EventFilter[] = []
|
74
|
-
const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig
|
80
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
75
81
|
|
76
82
|
if (Array.isArray(filter)) {
|
77
83
|
_filters = filter
|
@@ -112,7 +118,7 @@ export class SuiBaseProcessor {
|
|
112
118
|
idx
|
113
119
|
)
|
114
120
|
|
115
|
-
const decoded = processor.coder.decodeEvent<any>(evt)
|
121
|
+
const decoded = await processor.coder.decodeEvent<any>(evt)
|
116
122
|
await handler(decoded || evt, ctx)
|
117
123
|
processResults.push(ctx.getProcessResult())
|
118
124
|
}
|
@@ -131,7 +137,7 @@ export class SuiBaseProcessor {
|
|
131
137
|
fetchConfig?: Partial<MoveFetchConfig>
|
132
138
|
): SuiBaseProcessor {
|
133
139
|
let _filters: FunctionNameAndCallFilter[] = []
|
134
|
-
const _fetchConfig = MoveFetchConfig.fromPartial(fetchConfig
|
140
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
135
141
|
|
136
142
|
if (Array.isArray(filter)) {
|
137
143
|
_filters = filter
|
@@ -171,7 +177,7 @@ export class SuiBaseProcessor {
|
|
171
177
|
const programmableTx = getProgrammableTransaction(txKind)
|
172
178
|
|
173
179
|
const payload = calls[0]
|
174
|
-
const decoded = processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])
|
180
|
+
const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])
|
175
181
|
await handler(decoded, ctx)
|
176
182
|
}
|
177
183
|
return ctx.getProcessResult()
|
@@ -221,7 +227,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
221
227
|
protected abstract transformObjects(objects: SuiMoveObject[]): HandlerType[]
|
222
228
|
|
223
229
|
protected onInterval(
|
224
|
-
handler: (resources: HandlerType[], ctx: SuiObjectsContext) =>
|
230
|
+
handler: (resources: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
225
231
|
timeInterval: HandleInterval | undefined,
|
226
232
|
versionInterval: HandleInterval | undefined,
|
227
233
|
type: string | undefined
|
@@ -246,7 +252,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
246
252
|
}
|
247
253
|
|
248
254
|
public onTimeInterval(
|
249
|
-
handler: (objects: HandlerType[], ctx: SuiObjectsContext) =>
|
255
|
+
handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
250
256
|
timeIntervalInMinutes = 60,
|
251
257
|
backfillTimeIntervalInMinutes = 240,
|
252
258
|
type?: string
|
@@ -263,7 +269,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
263
269
|
}
|
264
270
|
|
265
271
|
public onSlotInterval(
|
266
|
-
handler: (objects: HandlerType[], ctx: SuiObjectsContext) =>
|
272
|
+
handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
267
273
|
slotInterval = 100000,
|
268
274
|
backfillSlotInterval = 400000,
|
269
275
|
type?: string
|