@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
@@ -1,38 +1,31 @@
|
|
1
|
-
import {
|
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'
|
5
5
|
import chalk from 'chalk'
|
6
6
|
import { InternalMoveModule, InternalMoveStruct } from '../../move/internal-models.js'
|
7
7
|
import { AbstractCodegen } from '../../move/abstract-codegen.js'
|
8
|
-
import {
|
9
|
-
import { moduleQname, SPLITTER, structQname, TypeDescriptor } from '../../move/index.js'
|
10
|
-
import { getMeaningfulFunctionParams } from '../utils.js'
|
8
|
+
import { structQname } from '../../move/index.js'
|
11
9
|
import { join } from 'path'
|
10
|
+
import { SuiChainAdapter } from '../sui-chain-adapter.js'
|
12
11
|
|
13
|
-
export async function codegen(
|
12
|
+
export async function codegen(
|
13
|
+
abisDir: string,
|
14
|
+
outDir = join('src', 'types', 'sui'),
|
15
|
+
genExample = false,
|
16
|
+
builtin = false
|
17
|
+
) {
|
14
18
|
if (!fs.existsSync(abisDir)) {
|
15
19
|
return
|
16
20
|
}
|
17
21
|
const gen = new SuiCodegen()
|
18
|
-
const numFiles = await gen.generate(abisDir, outDir)
|
22
|
+
const numFiles = await gen.generate(abisDir, outDir, builtin)
|
19
23
|
console.log(chalk.green(`Generated ${numFiles} for Sui`))
|
20
24
|
}
|
21
25
|
|
22
|
-
|
23
|
-
switch (network) {
|
24
|
-
case SuiNetwork.TEST_NET:
|
25
|
-
return 'https://fullnode.testnet.sui.io/'
|
26
|
-
}
|
27
|
-
return 'https://fullnode.mainnet.sui.io/'
|
28
|
-
}
|
29
|
-
|
30
|
-
function getRpcClient(network: SuiNetwork): JsonRpcProvider {
|
31
|
-
return new JsonRpcProvider(new Connection({ fullnode: getRpcEndpoint(network) }))
|
32
|
-
}
|
33
|
-
|
34
|
-
class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
26
|
+
class SuiCodegen extends AbstractCodegen<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
35
27
|
ADDRESS_TYPE = 'SuiAddress'
|
28
|
+
// ADDRESS_TYPE = 'string'
|
36
29
|
MAIN_NET = SuiNetwork.MAIN_NET
|
37
30
|
TEST_NET = SuiNetwork.TEST_NET
|
38
31
|
PREFIX = 'Sui'
|
@@ -40,30 +33,8 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
40
33
|
// GENERATE_ON_ENTRY = true
|
41
34
|
PAYLOAD_OPTIONAL = true
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
return await client.getNormalizedMoveModulesByPackage({ package: account })
|
46
|
-
}
|
47
|
-
|
48
|
-
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
49
|
-
return getMeaningfulFunctionParams(params)
|
50
|
-
}
|
51
|
-
|
52
|
-
toInternalModules(modules: SuiMoveNormalizedModules): InternalMoveModule[] {
|
53
|
-
return Object.values(modules).map(toInternalModule)
|
54
|
-
}
|
55
|
-
|
56
|
-
getEventStructs(module: InternalMoveModule) {
|
57
|
-
const qname = moduleQname(module)
|
58
|
-
const eventMap = new Map<string, InternalMoveStruct>()
|
59
|
-
|
60
|
-
for (const struct of module.structs) {
|
61
|
-
const abilities = new Set(struct.abilities)
|
62
|
-
if (abilities.has('Drop') && abilities.has('Copy')) {
|
63
|
-
eventMap.set(qname + SPLITTER + struct.name, struct)
|
64
|
-
}
|
65
|
-
}
|
66
|
-
return eventMap
|
36
|
+
constructor() {
|
37
|
+
super(new SuiChainAdapter())
|
67
38
|
}
|
68
39
|
|
69
40
|
readModulesFile(fullPath: string) {
|
@@ -80,6 +51,8 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
80
51
|
return `export type ${struct.name} = string`
|
81
52
|
case '0x2::coin::Coin':
|
82
53
|
return `export type ${struct.name}<T> = string`
|
54
|
+
case '0x2::balance::Balance':
|
55
|
+
return `export type ${struct.name}<T> = string`
|
83
56
|
case '0x1::option::Option':
|
84
57
|
return `export type Option<T> = T | undefined`
|
85
58
|
}
|
@@ -91,6 +64,7 @@ class SuiCodegen extends AbstractCodegen<SuiMoveNormalizedModules, SuiNetwork> {
|
|
91
64
|
case '0x2::object::ID':
|
92
65
|
case '0x2::coin::Coin':
|
93
66
|
case '0x1::option::Option':
|
67
|
+
case '0x2::balance::Balance':
|
94
68
|
return ''
|
95
69
|
}
|
96
70
|
return super.generateOnEvents(module, struct)
|
package/src/sui/codegen/run.ts
CHANGED
package/src/sui/context.ts
CHANGED
@@ -2,6 +2,7 @@ import { RecordMetaData } from '@sentio/protos'
|
|
2
2
|
import { type Labels, BaseContext, normalizeLabels } from '../index.js'
|
3
3
|
import { SuiNetwork, getChainId } from './network.js'
|
4
4
|
import { SuiTransactionBlockResponse } from '@mysten/sui.js'
|
5
|
+
import { MoveCoder, defaultMoveCoder } from './move-coder.js'
|
5
6
|
|
6
7
|
export class SuiContext extends BaseContext {
|
7
8
|
address: string
|
@@ -10,6 +11,8 @@ export class SuiContext extends BaseContext {
|
|
10
11
|
timestamp: Date
|
11
12
|
slot: bigint
|
12
13
|
transaction: SuiTransactionBlockResponse
|
14
|
+
eventIndex: number
|
15
|
+
coder: MoveCoder
|
13
16
|
|
14
17
|
constructor(
|
15
18
|
moduleName: string,
|
@@ -17,7 +20,8 @@ export class SuiContext extends BaseContext {
|
|
17
20
|
address: string,
|
18
21
|
timestamp: Date,
|
19
22
|
slot: bigint,
|
20
|
-
transaction
|
23
|
+
transaction: SuiTransactionBlockResponse,
|
24
|
+
eventIndex: number
|
21
25
|
) {
|
22
26
|
super()
|
23
27
|
this.address = address.toLowerCase()
|
@@ -25,6 +29,8 @@ export class SuiContext extends BaseContext {
|
|
25
29
|
this.moduleName = moduleName
|
26
30
|
this.timestamp = timestamp
|
27
31
|
this.slot = slot
|
32
|
+
this.eventIndex = eventIndex
|
33
|
+
this.coder = defaultMoveCoder(network)
|
28
34
|
if (transaction) {
|
29
35
|
this.transaction = transaction
|
30
36
|
}
|
@@ -54,6 +60,7 @@ export class SuiObjectsContext extends BaseContext {
|
|
54
60
|
network: SuiNetwork
|
55
61
|
slot: bigint
|
56
62
|
timestamp: Date
|
63
|
+
coder: MoveCoder
|
57
64
|
|
58
65
|
constructor(network: SuiNetwork, address: string, slot: bigint, timestamp: Date) {
|
59
66
|
super()
|
@@ -61,6 +68,7 @@ export class SuiObjectsContext extends BaseContext {
|
|
61
68
|
this.network = network
|
62
69
|
this.slot = slot
|
63
70
|
this.timestamp = timestamp
|
71
|
+
this.coder = defaultMoveCoder(network)
|
64
72
|
}
|
65
73
|
|
66
74
|
getChainId(): string {
|
package/src/sui/index.ts
CHANGED
package/src/sui/models.ts
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
import type { SuiEvent, MoveCallSuiTransaction, SuiMoveObject } from '@mysten/sui.js'
|
2
|
+
import { DecodedStruct } from '../move/types.js'
|
2
3
|
|
3
|
-
export type TypedEventInstance<T> = SuiEvent
|
4
|
-
|
5
|
-
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
6
|
-
*/
|
7
|
-
data_decoded: T
|
8
|
-
|
9
|
-
type_arguments: string[]
|
10
|
-
}
|
4
|
+
export type TypedEventInstance<T> = DecodedStruct<SuiEvent, T>
|
5
|
+
export type TypedSuiMoveObject<T> = DecodedStruct<SuiMoveObject, T>
|
11
6
|
|
12
7
|
export type TypedFunctionPayload<T extends Array<any>> = MoveCallSuiTransaction & {
|
13
8
|
/**
|
@@ -15,8 +10,3 @@ export type TypedFunctionPayload<T extends Array<any>> = MoveCallSuiTransaction
|
|
15
10
|
*/
|
16
11
|
arguments_decoded: T
|
17
12
|
}
|
18
|
-
|
19
|
-
export type TypedSuiMoveObject<T> = SuiMoveObject & {
|
20
|
-
data_decoded: T
|
21
|
-
type_arguments: string[]
|
22
|
-
}
|
package/src/sui/move-coder.ts
CHANGED
@@ -1,78 +1,79 @@
|
|
1
|
-
import { TypedEventInstance, TypedFunctionPayload
|
2
|
-
import { AbstractMoveCoder
|
3
|
-
import {
|
4
|
-
MoveCallSuiTransaction,
|
5
|
-
SuiEvent,
|
6
|
-
SuiMoveNormalizedModule,
|
7
|
-
SuiCallArg,
|
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
|
-
import { SPLITTER, TypeDescriptor } from '../move/index.js'
|
13
|
-
import {
|
5
|
+
import { ANY_TYPE, DecodedStruct, parseMoveType, SPLITTER, TypeDescriptor } from '../move/index.js'
|
6
|
+
import { SuiNetwork } from './network.js'
|
7
|
+
import { SuiChainAdapter } from './sui-chain-adapter.js'
|
8
|
+
import { InternalMoveModule } from '../move/internal-models.js'
|
14
9
|
import { dynamic_field } from './builtin/0x2.js'
|
15
10
|
|
16
|
-
export class MoveCoder extends AbstractMoveCoder<SuiEvent | SuiMoveObject> {
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
export class MoveCoder extends AbstractMoveCoder<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
12
|
+
constructor(network: SuiNetwork) {
|
13
|
+
super(network)
|
14
|
+
this.adapter = new SuiChainAdapter()
|
15
|
+
}
|
16
|
+
|
17
|
+
load(module: SuiMoveNormalizedModule): InternalMoveModule {
|
18
|
+
let m = this.moduleMapping.get(module.address + '::' + module.name)
|
19
|
+
if (m) {
|
20
|
+
return m
|
20
21
|
}
|
21
|
-
|
22
|
+
m = toInternalModule(module)
|
23
|
+
this.loadInternal(m)
|
24
|
+
return m
|
22
25
|
}
|
23
26
|
|
24
27
|
decode(data: any, type: TypeDescriptor): any {
|
25
28
|
switch (type.qname) {
|
26
29
|
case '0x2::object::ID':
|
27
30
|
case '0x2::coin::Coin':
|
31
|
+
case '0x2::balance::Balance':
|
28
32
|
return data
|
29
33
|
case '0x1::option::Option':
|
30
|
-
|
31
|
-
|
34
|
+
if (data === null) {
|
35
|
+
return data
|
36
|
+
}
|
37
|
+
return this.decode(data, type.typeArgs[0])
|
32
38
|
default:
|
33
39
|
return super.decode(data, type)
|
34
40
|
}
|
35
41
|
}
|
36
42
|
|
37
|
-
|
38
|
-
if (SuiEvent.is(val)) {
|
39
|
-
return {
|
40
|
-
...val,
|
41
|
-
data: val.parsedJson as any,
|
42
|
-
}
|
43
|
-
}
|
44
|
-
if (SuiRawData.is(val)) {
|
45
|
-
return {
|
46
|
-
...val,
|
47
|
-
data: val.fields as any,
|
48
|
-
}
|
49
|
-
}
|
50
|
-
return val as any
|
51
|
-
}
|
52
|
-
|
53
|
-
decodeEvent<T>(event: SuiEvent): TypedEventInstance<T> | undefined {
|
43
|
+
decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {
|
54
44
|
return this.decodedStruct<T>(event) as any
|
55
45
|
}
|
56
|
-
filterAndDecodeEvents<T>(
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
return this.filterAndDecodeObjects(`0x2::dynamic_field::Field`, objects).map((o) => o.data_decoded) as any
|
46
|
+
filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {
|
47
|
+
if (typeof type === 'string') {
|
48
|
+
type = parseMoveType(type)
|
49
|
+
}
|
50
|
+
return this.filterAndDecodeStruct(type, resources) as any
|
62
51
|
}
|
63
52
|
|
64
|
-
|
65
|
-
|
53
|
+
async getDynamicFields<T1, T2>(
|
54
|
+
objects: SuiMoveObject[],
|
55
|
+
keyType: TypeDescriptor<T1> = ANY_TYPE,
|
56
|
+
valueType: TypeDescriptor<T2> = ANY_TYPE
|
57
|
+
): Promise<dynamic_field.Field<T1, T2>[]> {
|
58
|
+
// const type = dynamic_field.Field.TYPE
|
59
|
+
// Not using the code above to avoid cycle initialize failed
|
60
|
+
const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')
|
61
|
+
type.typeArgs = [keyType, valueType]
|
62
|
+
const res = await this.filterAndDecodeObjects(type, objects)
|
63
|
+
return res.map((o) => o.data_decoded)
|
66
64
|
}
|
67
65
|
|
68
|
-
|
69
|
-
|
66
|
+
filterAndDecodeObjects<T>(
|
67
|
+
type: TypeDescriptor<T>,
|
68
|
+
objects: SuiMoveObject[]
|
69
|
+
): Promise<DecodedStruct<SuiMoveObject, T>[]> {
|
70
|
+
return this.filterAndDecodeStruct(type, objects) as any
|
70
71
|
}
|
71
72
|
|
72
|
-
decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): MoveCallSuiTransaction {
|
73
|
+
async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {
|
73
74
|
const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)
|
74
|
-
const func = this.getMoveFunction(functionType)
|
75
|
-
const params = getMeaningfulFunctionParams(func.params)
|
75
|
+
const func = await this.getMoveFunction(functionType)
|
76
|
+
const params = this.adapter.getMeaningfulFunctionParams(func.params)
|
76
77
|
const args = []
|
77
78
|
for (const value of payload.arguments || []) {
|
78
79
|
const argValue = value as any
|
@@ -93,7 +94,7 @@ export class MoveCoder extends AbstractMoveCoder<SuiEvent | SuiMoveObject> {
|
|
93
94
|
}
|
94
95
|
}
|
95
96
|
|
96
|
-
const argumentsTyped = this.decodeArray(args, params)
|
97
|
+
const argumentsTyped = await this.decodeArray(args, params)
|
97
98
|
return {
|
98
99
|
...payload,
|
99
100
|
arguments_decoded: argumentsTyped,
|
@@ -101,8 +102,12 @@ export class MoveCoder extends AbstractMoveCoder<SuiEvent | SuiMoveObject> {
|
|
101
102
|
}
|
102
103
|
}
|
103
104
|
|
104
|
-
|
105
|
+
const MOVE_CODER = new MoveCoder(SuiNetwork.MAIN_NET)
|
106
|
+
const TESTNET_MOVE_CODER = new MoveCoder(SuiNetwork.TEST_NET)
|
105
107
|
|
106
|
-
export function defaultMoveCoder(): MoveCoder {
|
107
|
-
|
108
|
+
export function defaultMoveCoder(network: SuiNetwork = SuiNetwork.MAIN_NET): MoveCoder {
|
109
|
+
if (network == SuiNetwork.MAIN_NET) {
|
110
|
+
return MOVE_CODER
|
111
|
+
}
|
112
|
+
return TESTNET_MOVE_CODER
|
108
113
|
}
|
@@ -0,0 +1,86 @@
|
|
1
|
+
import { ChainAdapter, moduleQname, SPLITTER, TypeDescriptor } from '../move/index.js'
|
2
|
+
import { toInternalModule } from './move-types.js'
|
3
|
+
import { SuiNetwork } from './network.js'
|
4
|
+
import { InternalMoveModule, InternalMoveStruct } from '../move/internal-models.js'
|
5
|
+
import {
|
6
|
+
Connection,
|
7
|
+
JsonRpcProvider,
|
8
|
+
SuiMoveNormalizedModule,
|
9
|
+
SuiEvent,
|
10
|
+
SuiMoveObject,
|
11
|
+
SuiParsedData,
|
12
|
+
} from '@mysten/sui.js'
|
13
|
+
|
14
|
+
export class SuiChainAdapter extends ChainAdapter<SuiNetwork, SuiMoveNormalizedModule, SuiEvent | SuiMoveObject> {
|
15
|
+
static INSTANCE = new SuiChainAdapter()
|
16
|
+
|
17
|
+
async fetchModule(account: string, module: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule> {
|
18
|
+
const client = getRpcClient(network)
|
19
|
+
return await client.getNormalizedMoveModule({ package: account, module })
|
20
|
+
}
|
21
|
+
|
22
|
+
async fetchModules(account: string, network: SuiNetwork): Promise<SuiMoveNormalizedModule[]> {
|
23
|
+
const client = getRpcClient(network)
|
24
|
+
const modules = await client.getNormalizedMoveModulesByPackage({ package: account })
|
25
|
+
return Object.values(modules)
|
26
|
+
}
|
27
|
+
|
28
|
+
getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
29
|
+
if (params.length === 0) {
|
30
|
+
return params
|
31
|
+
}
|
32
|
+
return params.slice(0, params.length - 1)
|
33
|
+
}
|
34
|
+
|
35
|
+
toInternalModules(modules: SuiMoveNormalizedModule[]): InternalMoveModule[] {
|
36
|
+
return Object.values(modules).map(toInternalModule)
|
37
|
+
}
|
38
|
+
|
39
|
+
getEventStructs(module: InternalMoveModule) {
|
40
|
+
const qname = moduleQname(module)
|
41
|
+
const eventMap = new Map<string, InternalMoveStruct>()
|
42
|
+
|
43
|
+
for (const struct of module.structs) {
|
44
|
+
const abilities = new Set(struct.abilities)
|
45
|
+
if (abilities.has('Drop') && abilities.has('Copy')) {
|
46
|
+
eventMap.set(qname + SPLITTER + struct.name, struct)
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return eventMap
|
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
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
function getRpcEndpoint(network: SuiNetwork): string {
|
77
|
+
switch (network) {
|
78
|
+
case SuiNetwork.TEST_NET:
|
79
|
+
return 'https://fullnode.testnet.sui.io/'
|
80
|
+
}
|
81
|
+
return 'https://fullnode.mainnet.sui.io/'
|
82
|
+
}
|
83
|
+
|
84
|
+
function getRpcClient(network: SuiNetwork): JsonRpcProvider {
|
85
|
+
return new JsonRpcProvider(new Connection({ fullnode: getRpcEndpoint(network) }))
|
86
|
+
}
|
package/src/sui/sui-plugin.ts
CHANGED
package/src/sui/sui-processor.ts
CHANGED
@@ -7,7 +7,7 @@ import {
|
|
7
7
|
MoveOnIntervalConfig_OwnerType,
|
8
8
|
ProcessResult,
|
9
9
|
} from '@sentio/protos'
|
10
|
-
import { ListStateStorage } from '@sentio/runtime'
|
10
|
+
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
|
11
11
|
import { getChainId, SuiNetwork } from './network.js'
|
12
12
|
import { ServerError, Status } from 'nice-grpc'
|
13
13
|
import { SuiContext, SuiObjectsContext } from './context.js'
|
@@ -19,11 +19,17 @@ import {
|
|
19
19
|
SuiMoveObject,
|
20
20
|
SuiTransactionBlockResponse,
|
21
21
|
} from '@mysten/sui.js'
|
22
|
-
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js'
|
22
|
+
import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter, parseMoveType } from '../move/index.js'
|
23
23
|
import { getMoveCalls } from './utils.js'
|
24
|
-
import { defaultMoveCoder } from './move-coder.js'
|
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
|
@@ -52,11 +58,13 @@ export class SuiBaseProcessor {
|
|
52
58
|
|
53
59
|
eventHandlers: EventHandler<Data_SuiEvent>[] = []
|
54
60
|
callHandlers: CallHandler<Data_SuiCall>[] = []
|
61
|
+
coder: MoveCoder
|
55
62
|
|
56
63
|
constructor(name: string, options: SuiBindOptions) {
|
57
64
|
this.moduleName = name
|
58
65
|
this.config = configure(options)
|
59
66
|
SuiProcessorState.INSTANCE.addValue(this)
|
67
|
+
this.coder = defaultMoveCoder(this.config.network)
|
60
68
|
}
|
61
69
|
|
62
70
|
getChainId(): string {
|
@@ -66,10 +74,10 @@ export class SuiBaseProcessor {
|
|
66
74
|
public onMoveEvent(
|
67
75
|
handler: (event: SuiEvent, ctx: SuiContext) => void,
|
68
76
|
filter: EventFilter | EventFilter[],
|
69
|
-
fetchConfig?: MoveFetchConfig
|
77
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
70
78
|
): SuiBaseProcessor {
|
71
79
|
let _filters: EventFilter[] = []
|
72
|
-
const _fetchConfig =
|
80
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
73
81
|
|
74
82
|
if (Array.isArray(filter)) {
|
75
83
|
_filters = filter
|
@@ -81,6 +89,7 @@ export class SuiBaseProcessor {
|
|
81
89
|
// const moduleName = this.moduleName
|
82
90
|
|
83
91
|
const processor = this
|
92
|
+
const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))
|
84
93
|
|
85
94
|
this.eventHandlers.push({
|
86
95
|
handler: async function (data) {
|
@@ -92,26 +101,29 @@ export class SuiBaseProcessor {
|
|
92
101
|
throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')
|
93
102
|
}
|
94
103
|
|
95
|
-
const
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
txn
|
102
|
-
)
|
104
|
+
const processResults = []
|
105
|
+
for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {
|
106
|
+
const typeQname = parseMoveType(evt.type).qname
|
107
|
+
if (!allEventType.has(typeQname)) {
|
108
|
+
continue
|
109
|
+
}
|
103
110
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
111
|
+
const ctx = new SuiContext(
|
112
|
+
processor.moduleName,
|
113
|
+
processor.config.network,
|
114
|
+
processor.config.address,
|
115
|
+
data.timestamp || new Date(0),
|
116
|
+
data.slot,
|
117
|
+
txn,
|
118
|
+
idx
|
119
|
+
)
|
120
|
+
|
121
|
+
const decoded = await processor.coder.decodeEvent<any>(evt)
|
110
122
|
await handler(decoded || evt, ctx)
|
111
|
-
|
123
|
+
processResults.push(ctx.getProcessResult())
|
112
124
|
}
|
113
125
|
|
114
|
-
return
|
126
|
+
return mergeProcessResults(processResults)
|
115
127
|
},
|
116
128
|
filters: _filters,
|
117
129
|
fetchConfig: _fetchConfig,
|
@@ -122,10 +134,10 @@ export class SuiBaseProcessor {
|
|
122
134
|
public onEntryFunctionCall(
|
123
135
|
handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,
|
124
136
|
filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],
|
125
|
-
fetchConfig?: MoveFetchConfig
|
137
|
+
fetchConfig?: Partial<MoveFetchConfig>
|
126
138
|
): SuiBaseProcessor {
|
127
139
|
let _filters: FunctionNameAndCallFilter[] = []
|
128
|
-
const _fetchConfig =
|
140
|
+
const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })
|
129
141
|
|
130
142
|
if (Array.isArray(filter)) {
|
131
143
|
_filters = filter
|
@@ -150,7 +162,8 @@ export class SuiBaseProcessor {
|
|
150
162
|
processor.config.address,
|
151
163
|
data.timestamp || new Date(0),
|
152
164
|
data.slot,
|
153
|
-
tx
|
165
|
+
tx,
|
166
|
+
0
|
154
167
|
)
|
155
168
|
if (tx) {
|
156
169
|
const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)
|
@@ -164,7 +177,7 @@ export class SuiBaseProcessor {
|
|
164
177
|
const programmableTx = getProgrammableTransaction(txKind)
|
165
178
|
|
166
179
|
const payload = calls[0]
|
167
|
-
const decoded =
|
180
|
+
const decoded = await processor.coder.decodeFunctionPayload(payload, programmableTx?.inputs || [])
|
168
181
|
await handler(decoded, ctx)
|
169
182
|
}
|
170
183
|
return ctx.getProcessResult()
|
@@ -214,7 +227,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
214
227
|
protected abstract transformObjects(objects: SuiMoveObject[]): HandlerType[]
|
215
228
|
|
216
229
|
protected onInterval(
|
217
|
-
handler: (resources: HandlerType[], ctx: SuiObjectsContext) =>
|
230
|
+
handler: (resources: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
218
231
|
timeInterval: HandleInterval | undefined,
|
219
232
|
versionInterval: HandleInterval | undefined,
|
220
233
|
type: string | undefined
|
@@ -239,7 +252,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
239
252
|
}
|
240
253
|
|
241
254
|
public onTimeInterval(
|
242
|
-
handler: (objects: HandlerType[], ctx: SuiObjectsContext) =>
|
255
|
+
handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
243
256
|
timeIntervalInMinutes = 60,
|
244
257
|
backfillTimeIntervalInMinutes = 240,
|
245
258
|
type?: string
|
@@ -256,7 +269,7 @@ abstract class SuiBaseObjectsProcessor<HandlerType> {
|
|
256
269
|
}
|
257
270
|
|
258
271
|
public onSlotInterval(
|
259
|
-
handler: (objects: HandlerType[], ctx: SuiObjectsContext) =>
|
272
|
+
handler: (objects: HandlerType[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
260
273
|
slotInterval = 100000,
|
261
274
|
backfillSlotInterval = 400000,
|
262
275
|
type?: string
|
package/src/sui/utils.ts
CHANGED
@@ -6,7 +6,6 @@ import {
|
|
6
6
|
ProgrammableTransaction,
|
7
7
|
SuiTransaction,
|
8
8
|
} from '@mysten/sui.js'
|
9
|
-
import { TypeDescriptor } from '../move/index.js'
|
10
9
|
|
11
10
|
export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
|
12
11
|
const txKind = getTransactionKind(txBlock)
|
@@ -33,10 +32,3 @@ export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
|
|
33
32
|
return []
|
34
33
|
})
|
35
34
|
}
|
36
|
-
|
37
|
-
export function getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
|
38
|
-
if (params.length === 0) {
|
39
|
-
return params
|
40
|
-
}
|
41
|
-
return params.slice(0, params.length - 1)
|
42
|
-
}
|