@sentio/sdk 1.37.0-rc.1 → 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.
Files changed (136) hide show
  1. package/lib/builtin/index.d.ts +0 -2
  2. package/lib/builtin/index.js +1 -3
  3. package/lib/builtin/index.js.map +1 -1
  4. package/lib/core/eth-plugin.js +12 -15
  5. package/lib/core/eth-plugin.js.map +1 -1
  6. package/lib/core/index.d.ts +0 -4
  7. package/lib/core/index.js +1 -9
  8. package/lib/core/index.js.map +1 -1
  9. package/lib/core/numberish.d.ts +1 -1
  10. package/lib/core/numberish.js +5 -13
  11. package/lib/core/numberish.js.map +1 -1
  12. package/lib/core/sui-plugin.js +1 -1
  13. package/lib/core/sui-plugin.js.map +1 -1
  14. package/lib/index.d.ts +1 -1
  15. package/lib/index.js +3 -14
  16. package/lib/index.js.map +1 -1
  17. package/lib/service.d.ts +0 -4
  18. package/lib/service.js +40 -71
  19. package/lib/service.js.map +1 -1
  20. package/package.json +5 -15
  21. package/src/builtin/index.ts +1 -4
  22. package/src/core/eth-plugin.ts +5 -8
  23. package/src/core/index.ts +0 -5
  24. package/src/core/numberish.ts +8 -15
  25. package/src/core/sui-plugin.ts +2 -2
  26. package/src/index.ts +3 -1
  27. package/src/service.ts +13 -71
  28. package/lib/aptos/api.d.ts +0 -2
  29. package/lib/aptos/api.js +0 -14
  30. package/lib/aptos/api.js.map +0 -1
  31. package/lib/aptos/aptos-plugin.d.ts +0 -14
  32. package/lib/aptos/aptos-plugin.js +0 -185
  33. package/lib/aptos/aptos-plugin.js.map +0 -1
  34. package/lib/aptos/aptos-processor.d.ts +0 -75
  35. package/lib/aptos/aptos-processor.js +0 -193
  36. package/lib/aptos/aptos-processor.js.map +0 -1
  37. package/lib/aptos/context.d.ts +0 -22
  38. package/lib/aptos/context.js +0 -65
  39. package/lib/aptos/context.js.map +0 -1
  40. package/lib/aptos/index.d.ts +0 -9
  41. package/lib/aptos/index.js +0 -34
  42. package/lib/aptos/index.js.map +0 -1
  43. package/lib/aptos/models.d.ts +0 -23
  44. package/lib/aptos/models.js +0 -3
  45. package/lib/aptos/models.js.map +0 -1
  46. package/lib/aptos/network.d.ts +0 -14
  47. package/lib/aptos/network.js +0 -46
  48. package/lib/aptos/network.js.map +0 -1
  49. package/lib/aptos/runtime.d.ts +0 -2
  50. package/lib/aptos/runtime.js +0 -16
  51. package/lib/aptos/runtime.js.map +0 -1
  52. package/lib/aptos/type-registry.d.ts +0 -21
  53. package/lib/aptos/type-registry.js +0 -156
  54. package/lib/aptos/type-registry.js.map +0 -1
  55. package/lib/aptos/types.d.ts +0 -9
  56. package/lib/aptos/types.js +0 -135
  57. package/lib/aptos/types.js.map +0 -1
  58. package/lib/aptos/types.test.d.ts +0 -1
  59. package/lib/aptos/types.test.js.map +0 -1
  60. package/lib/aptos/utils.d.ts +0 -7
  61. package/lib/aptos/utils.js +0 -27
  62. package/lib/aptos/utils.js.map +0 -1
  63. package/lib/aptos-codegen/codegen.d.ts +0 -23
  64. package/lib/aptos-codegen/codegen.js +0 -364
  65. package/lib/aptos-codegen/codegen.js.map +0 -1
  66. package/lib/aptos-codegen/typegen.d.ts +0 -17
  67. package/lib/aptos-codegen/typegen.js +0 -142
  68. package/lib/aptos-codegen/typegen.js.map +0 -1
  69. package/lib/builtin/aptos/0x1.d.ts +0 -1913
  70. package/lib/builtin/aptos/0x1.js +0 -2748
  71. package/lib/builtin/aptos/0x1.js.map +0 -1
  72. package/lib/builtin/aptos/0x3.d.ts +0 -482
  73. package/lib/builtin/aptos/0x3.js +0 -526
  74. package/lib/builtin/aptos/0x3.js.map +0 -1
  75. package/lib/builtin/aptos/index.d.ts +0 -2
  76. package/lib/builtin/aptos/index.js +0 -29
  77. package/lib/builtin/aptos/index.js.map +0 -1
  78. package/lib/builtin/solana/index.d.ts +0 -2
  79. package/lib/builtin/solana/index.js +0 -19
  80. package/lib/builtin/solana/index.js.map +0 -1
  81. package/lib/builtin/solana/spl-token-processor.d.ts +0 -39
  82. package/lib/builtin/solana/spl-token-processor.js +0 -258
  83. package/lib/builtin/solana/spl-token-processor.js.map +0 -1
  84. package/lib/builtin/solana/types.d.ts +0 -427
  85. package/lib/builtin/solana/types.js +0 -203
  86. package/lib/builtin/solana/types.js.map +0 -1
  87. package/lib/builtin/solana/wormhole-processor.d.ts +0 -16
  88. package/lib/builtin/solana/wormhole-processor.js +0 -195
  89. package/lib/builtin/solana/wormhole-processor.js.map +0 -1
  90. package/lib/core/solana-context.d.ts +0 -11
  91. package/lib/core/solana-context.js +0 -34
  92. package/lib/core/solana-context.js.map +0 -1
  93. package/lib/core/solana-options.d.ts +0 -8
  94. package/lib/core/solana-options.js +0 -13
  95. package/lib/core/solana-options.js.map +0 -1
  96. package/lib/core/solana-plugin.d.ts +0 -9
  97. package/lib/core/solana-plugin.js +0 -79
  98. package/lib/core/solana-plugin.js.map +0 -1
  99. package/lib/core/solana-processor.d.ts +0 -40
  100. package/lib/core/solana-processor.js +0 -80
  101. package/lib/core/solana-processor.js.map +0 -1
  102. package/lib/solana-codegen/codegen.d.ts +0 -1
  103. package/lib/solana-codegen/codegen.js +0 -113
  104. package/lib/solana-codegen/codegen.js.map +0 -1
  105. package/lib/test-abi-code-gen.d.ts +0 -2
  106. package/lib/test-abi-code-gen.js +0 -20
  107. package/lib/test-abi-code-gen.js.map +0 -1
  108. package/src/abis/aptos/0x1.json +0 -9205
  109. package/src/abis/aptos/0x3.json +0 -1515
  110. package/src/aptos/api.ts +0 -11
  111. package/src/aptos/aptos-plugin.ts +0 -216
  112. package/src/aptos/aptos-processor.ts +0 -305
  113. package/src/aptos/context.ts +0 -74
  114. package/src/aptos/index.ts +0 -10
  115. package/src/aptos/models.ts +0 -34
  116. package/src/aptos/network.ts +0 -42
  117. package/src/aptos/runtime.ts +0 -13
  118. package/src/aptos/type-registry.ts +0 -187
  119. package/src/aptos/types.ts +0 -149
  120. package/src/aptos/utils.ts +0 -26
  121. package/src/aptos-codegen/codegen.ts +0 -428
  122. package/src/aptos-codegen/tsconfig.json +0 -9
  123. package/src/aptos-codegen/typegen.ts +0 -153
  124. package/src/builtin/aptos/0x1.ts +0 -4210
  125. package/src/builtin/aptos/0x3.ts +0 -888
  126. package/src/builtin/aptos/index.ts +0 -2
  127. package/src/builtin/solana/index.ts +0 -2
  128. package/src/builtin/solana/spl-token-processor.ts +0 -298
  129. package/src/builtin/solana/types.ts +0 -279
  130. package/src/builtin/solana/wormhole-processor.ts +0 -178
  131. package/src/core/solana-context.ts +0 -34
  132. package/src/core/solana-options.ts +0 -8
  133. package/src/core/solana-plugin.ts +0 -97
  134. package/src/core/solana-processor.ts +0 -102
  135. package/src/solana-codegen/codegen.ts +0 -116
  136. package/src/test-abi-code-gen.ts +0 -16
@@ -1,13 +0,0 @@
1
- import { MoveStruct } from 'aptos-sdk/src/generated'
2
-
3
- export function decode<T>(struct: MoveStruct, args: any[]): T | undefined {
4
- if (args.length != struct.fields.length) {
5
- console.log('type mismatch actually data for', struct.name)
6
- return undefined
7
- }
8
- const res: any = {}
9
- for (const [i, field] of struct.fields.entries()) {
10
- res[field.name] = args[i]
11
- }
12
- return res as T
13
- }
@@ -1,187 +0,0 @@
1
- import {
2
- Event,
3
- MoveFunction,
4
- MoveModule,
5
- MoveResource,
6
- MoveStruct,
7
- TransactionPayload_EntryFunctionPayload,
8
- } from 'aptos-sdk/src/generated'
9
- import { getMeaningfulFunctionParams, moduleQname, SPLITTER, VECTOR_STR } from './utils'
10
- import { parseMoveType, TypeDescriptor } from './types'
11
- import {
12
- TypedEventInstance,
13
- TypedMoveResource,
14
- StructWithTag,
15
- StructWithType,
16
- TypedEntryFunctionPayload,
17
- } from './models'
18
-
19
- export class TypeRegistry {
20
- moduleMapping = new Map<string, MoveModule>()
21
- typeMapping = new Map<string, MoveStruct>()
22
- funcMapping = new Map<string, MoveFunction>()
23
-
24
- contains(account: string, name: string) {
25
- return this.moduleMapping.has(account + '::' + name)
26
- }
27
-
28
- load(module: MoveModule) {
29
- if (this.contains(module.address, module.name)) {
30
- return
31
- }
32
- this.moduleMapping.set(moduleQname(module), module)
33
-
34
- for (const struct of module.structs) {
35
- // TODO move to util
36
- const key = [module.address, module.name, struct.name].join(SPLITTER)
37
- this.typeMapping.set(key, struct)
38
- }
39
-
40
- for (const func of module.exposed_functions) {
41
- if (!func.is_entry) {
42
- continue
43
- }
44
- const key = [module.address, module.name, func.name].join(SPLITTER)
45
- this.funcMapping.set(key, func)
46
- }
47
- }
48
-
49
- getMoveStruct(type: string): MoveStruct {
50
- const struct = this.typeMapping.get(type)
51
- if (!struct) {
52
- throw new Error('Failed to load type' + type)
53
- }
54
- return struct
55
- }
56
-
57
- getMoveFunction(type: string): MoveFunction {
58
- const func = this.funcMapping.get(type)
59
- if (!func) {
60
- throw new Error('Failed to load function' + type)
61
- }
62
- return func
63
- }
64
-
65
- decode(data: any, type: TypeDescriptor): any {
66
- // process simple type
67
- if (type.qname.startsWith('&')) {
68
- return data
69
- }
70
- switch (type.qname) {
71
- case 'signer': // TODO check this
72
- case 'address':
73
- case '0x1::string::String':
74
- case 'bool':
75
- case 'u8':
76
- case 'u16':
77
- case 'u32':
78
- return data
79
- case 'u64':
80
- case 'u128':
81
- return BigInt(data)
82
- }
83
-
84
- // process vector
85
- if (type.qname === VECTOR_STR) {
86
- // vector<u8> as hex string
87
- if (type.typeArgs[0].qname === 'u8') {
88
- return data
89
- }
90
-
91
- const res = []
92
- for (const entry of data) {
93
- res.push(this.decode(entry, type.typeArgs[0]))
94
- }
95
- return res
96
- }
97
-
98
- // Process complex type
99
- const struct = this.getMoveStruct(type.qname)
100
-
101
- const typeCtx = new Map<string, TypeDescriptor>()
102
- for (const [idx, typeArg] of type.typeArgs.entries()) {
103
- typeCtx.set('T' + idx, typeArg)
104
- }
105
-
106
- const typedData: any = {}
107
-
108
- for (const field of struct.fields) {
109
- let filedType = parseMoveType(field.type)
110
- filedType = filedType.applyTypeArgs(typeCtx)
111
- const value = this.decode(data[field.name], filedType)
112
- typedData[field.name] = value
113
- }
114
- return typedData
115
- }
116
-
117
- decodeEvent<T>(event: Event): TypedEventInstance<T> | undefined {
118
- return this.decodedInternal<T>(event) as TypedEventInstance<T>
119
- }
120
- filterAndDecodeEvents<T>(typeQname: string, resources: Event[]): TypedEventInstance<T>[] {
121
- return this.filterAndDecodeInternal(typeQname, resources) as TypedEventInstance<T>[]
122
- }
123
- decodeResource<T>(res: MoveResource): TypedMoveResource<T> | undefined {
124
- return this.decodedInternal<T>(res)
125
- }
126
- filterAndDecodeResources<T>(typeQname: string, resources: MoveResource[]): TypedMoveResource<T>[] {
127
- return this.filterAndDecodeInternal(typeQname, resources)
128
- }
129
-
130
- private filterAndDecodeInternal<T>(typeQname: string, structs: StructWithTag[]): StructWithType<T>[] {
131
- if (!structs) {
132
- return []
133
- }
134
- const results: StructWithType<T>[] = []
135
- for (const resource of structs) {
136
- if (resource.type.split('<')[0] !== typeQname) {
137
- continue
138
- }
139
- const result = this.decodedInternal(resource)
140
- if (result) {
141
- results.push(result as StructWithType<T>)
142
- }
143
- }
144
- return results
145
- }
146
-
147
- private decodedInternal<T>(typeStruct: StructWithTag): StructWithType<T> | undefined {
148
- const registry = TYPE_REGISTRY
149
- // this.loadTypes(registry)
150
- // TODO check if module is not loaded
151
-
152
- const typeDescriptor = parseMoveType(typeStruct.type)
153
- const typeArguments = typeDescriptor.typeArgs.map((t) => t.getSignature())
154
-
155
- let dataTyped = undefined
156
- try {
157
- dataTyped = registry.decode(typeStruct.data, typeDescriptor)
158
- } catch (e) {
159
- console.error('Decoding error for ', JSON.stringify(typeStruct), e)
160
- return undefined
161
- }
162
- return { ...typeStruct, data_typed: dataTyped, type_arguments: typeArguments } as StructWithType<T>
163
- }
164
-
165
- decodeFunctionPayload(payload: TransactionPayload_EntryFunctionPayload): TransactionPayload_EntryFunctionPayload {
166
- const registry = TYPE_REGISTRY
167
- // this.loadTypes(registry)
168
- const argumentsTyped: any[] = []
169
-
170
- try {
171
- const func = registry.getMoveFunction(payload.function)
172
- const params = getMeaningfulFunctionParams(func)
173
- for (const [idx, arg] of payload.arguments.entries()) {
174
- // TODO consider apply payload.type_arguments, but this might be hard since we don't code gen for them
175
- const argType = parseMoveType(params[idx])
176
- argumentsTyped.push(registry.decode(arg, argType))
177
- }
178
- } catch (e) {
179
- console.error('Decoding error for ', JSON.stringify(payload), e)
180
- return payload
181
- }
182
-
183
- return { ...payload, arguments_typed: argumentsTyped } as TypedEntryFunctionPayload<any>
184
- }
185
- }
186
-
187
- export const TYPE_REGISTRY = new TypeRegistry()
@@ -1,149 +0,0 @@
1
- import { SPLITTER, VECTOR_STR } from './utils'
2
-
3
- export class TypeDescriptor {
4
- // type: string
5
-
6
- // qualified name without type parameters
7
- qname: string
8
- // account?: string
9
- // module?: string
10
-
11
- typeArgs: TypeDescriptor[]
12
-
13
- constructor(symbol: string, typeParams?: TypeDescriptor[]) {
14
- this.qname = symbol
15
- this.typeArgs = typeParams || []
16
- }
17
-
18
- getSignature(): string {
19
- if (this.typeArgs.length > 0) {
20
- return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'
21
- }
22
- return this.qname
23
- }
24
-
25
- // Replace T0, T1 with more concrete type
26
- applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {
27
- const replace = ctx.get(this.qname)
28
- if (replace) {
29
- return replace
30
- }
31
- if (ctx.size === 0 || this.typeArgs.length === 0) {
32
- return this
33
- }
34
-
35
- const typeArgs: TypeDescriptor[] = []
36
- for (const arg of this.typeArgs) {
37
- const replace = ctx.get(arg.qname)
38
- if (replace) {
39
- typeArgs.push(replace)
40
- } else {
41
- typeArgs.push(arg.applyTypeArgs(ctx))
42
- }
43
- }
44
- return new TypeDescriptor(this.qname, typeArgs)
45
- }
46
-
47
- // all depended types including itself, not include system type
48
- dependedTypes(): string[] {
49
- if (this.qname.startsWith('&')) {
50
- return []
51
- }
52
- switch (this.qname) {
53
- case 'signer':
54
- case 'address':
55
- case '0x1::string::String':
56
- case 'bool':
57
- case 'u8':
58
- case 'u16':
59
- case 'u32':
60
- case 'u64':
61
- case 'u128':
62
- return []
63
- }
64
-
65
- // Type parameters are not depended
66
- if (this.qname.indexOf(SPLITTER) == -1) {
67
- if (this.qname.startsWith('T')) {
68
- return []
69
- }
70
- }
71
-
72
- const types = new Set<string>()
73
- for (const param of this.typeArgs) {
74
- param.dependedTypes().forEach((t) => types.add(t))
75
- }
76
-
77
- if (this.qname !== VECTOR_STR) {
78
- types.add(this.qname)
79
- }
80
-
81
- return Array.from(types)
82
- }
83
- }
84
-
85
- export function parseMoveType(type: string): TypeDescriptor {
86
- // type = type.replace('&', '')
87
-
88
- type = type.replaceAll('&mut ', '&')
89
- type = type.replaceAll('mut ', '')
90
-
91
- // TODO replace ' ' is not exactly safe, need to double check this
92
- type = type.replaceAll(' ', '')
93
-
94
- const stack: TypeDescriptor[] = [new TypeDescriptor('')]
95
- let buffer = []
96
-
97
- // xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
98
- for (let i = 0; i < type.length; i++) {
99
- const ch = type[i]
100
- if (ch === '<') {
101
- // const symbol = type.slice(symbolStart, i)
102
- // symbolStart =
103
- const symbol = buffer.join('')
104
- buffer = []
105
- stack[stack.length - 1].qname = symbol
106
- stack.push(new TypeDescriptor(''))
107
- continue
108
- }
109
- if (ch === '>') {
110
- const typeParam = stack.pop()
111
- if (!typeParam) {
112
- throw Error('Uxpectecd stack size')
113
- }
114
- if (buffer.length > 0) {
115
- typeParam.qname = buffer.join('')
116
- buffer = []
117
- }
118
- stack[stack.length - 1].typeArgs.push(typeParam)
119
- continue
120
- }
121
- if (ch === ',') {
122
- const typeParam = stack.pop()
123
- if (!typeParam) {
124
- throw Error('Uxpectecd stack size')
125
- }
126
- if (buffer.length > 0) {
127
- typeParam.qname = buffer.join('')
128
- buffer = []
129
- }
130
-
131
- stack[stack.length - 1].typeArgs.push(typeParam)
132
- // continue parse next param
133
- stack.push(new TypeDescriptor(''))
134
- continue
135
- }
136
-
137
- buffer.push(ch)
138
- }
139
-
140
- if (buffer.length > 0) {
141
- stack[stack.length - 1].qname = buffer.join('')
142
- }
143
-
144
- const res = stack.pop()
145
- if (!res || stack.length > 0) {
146
- throw Error('Uxpectecd stack size')
147
- }
148
- return res
149
- }
@@ -1,26 +0,0 @@
1
- import { MoveFunction, MoveModule } from 'aptos-sdk/src/generated'
2
-
3
- export const SPLITTER = '::'
4
-
5
- export const VECTOR_STR = 'vector'
6
-
7
- export function isFrameworkAccount(account: string) {
8
- return account === '0x1' || account === '0x2' || account === '0x3'
9
- }
10
-
11
- export function moduleQname(module: MoveModule): string {
12
- return module.address.toLowerCase() + SPLITTER + module.name
13
- }
14
-
15
- export function moduleQnameForType(type: string): [string, string] {
16
- const parts = type.split(SPLITTER).slice(0, 2)
17
- return [parts[0], parts[1]]
18
- }
19
-
20
- export function getMeaningfulFunctionParams(func: MoveFunction): string[] {
21
- let params = func.params
22
- if (func.params[0] === '&signer') {
23
- params = params.slice(1)
24
- }
25
- return params
26
- }