@sentio/sdk 2.23.0 → 2.24.0-rc.2
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-processor.d.ts +1 -2
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +11 -11
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.js +6 -6
- package/lib/aptos/builtin/0x1.d.ts +850 -339
- package/lib/aptos/builtin/0x1.d.ts.map +1 -1
- package/lib/aptos/builtin/0x1.js +652 -189
- package/lib/aptos/builtin/0x1.js.map +1 -1
- package/lib/aptos/builtin/0x3.d.ts +73 -54
- package/lib/aptos/builtin/0x3.d.ts.map +1 -1
- package/lib/aptos/builtin/0x3.js +25 -66
- package/lib/aptos/builtin/0x3.js.map +1 -1
- package/lib/aptos/codegen/codegen.d.ts.map +1 -1
- package/lib/aptos/codegen/codegen.js +40 -10
- package/lib/aptos/codegen/codegen.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -2
- package/lib/aptos/context.d.ts.map +1 -1
- package/lib/aptos/context.js +2 -2
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/ext/coin-event.js +1 -1
- package/lib/aptos/ext/coin.js +193 -193
- package/lib/aptos/ext/coin.js.map +1 -1
- package/lib/aptos/index.d.ts +4 -4
- package/lib/aptos/index.d.ts.map +1 -1
- package/lib/aptos/index.js +3 -4
- package/lib/aptos/index.js.map +1 -1
- package/lib/aptos/models.d.ts +2 -2
- package/lib/aptos/models.d.ts.map +1 -1
- package/lib/aptos/move-coder.d.ts +1 -13
- package/lib/aptos/move-coder.d.ts.map +1 -1
- package/lib/aptos/move-coder.js +4 -55
- package/lib/aptos/move-coder.js.map +1 -1
- package/lib/aptos/network.d.ts +1 -0
- package/lib/aptos/network.d.ts.map +1 -1
- package/lib/aptos/network.js +8 -1
- package/lib/aptos/network.js.map +1 -1
- package/lib/eth/codegen/codegen.d.ts.map +1 -1
- package/lib/eth/codegen/codegen.js +4 -3
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/move/ext/move-dex.d.ts +1 -1
- package/lib/move/ext/move-dex.d.ts.map +1 -1
- package/lib/move/ext/move-dex.js +4 -4
- package/lib/move/index.d.ts +1 -4
- package/lib/move/index.d.ts.map +1 -1
- package/lib/move/index.js +1 -4
- package/lib/move/index.js.map +1 -1
- package/lib/move/move-context.d.ts +3 -3
- package/lib/move/move-context.d.ts.map +1 -1
- package/lib/move/move-context.js.map +1 -1
- package/lib/move/shared-network-codegen.d.ts +14 -0
- package/lib/move/shared-network-codegen.d.ts.map +1 -0
- package/lib/move/shared-network-codegen.js +116 -0
- package/lib/move/shared-network-codegen.js.map +1 -0
- package/lib/sui/builtin/0x1.d.ts +4 -2
- package/lib/sui/builtin/0x1.d.ts.map +1 -1
- package/lib/sui/builtin/0x1.js +7 -14
- package/lib/sui/builtin/0x1.js.map +1 -1
- package/lib/sui/builtin/0x2.d.ts +52 -168
- package/lib/sui/builtin/0x2.d.ts.map +1 -1
- package/lib/sui/builtin/0x2.js +24 -65
- package/lib/sui/builtin/0x2.js.map +1 -1
- package/lib/sui/builtin/0x3.d.ts +113 -331
- package/lib/sui/builtin/0x3.d.ts.map +1 -1
- package/lib/sui/builtin/0x3.js +13 -32
- package/lib/sui/builtin/0x3.js.map +1 -1
- package/lib/sui/codegen/codegen.d.ts.map +1 -1
- package/lib/sui/codegen/codegen.js +72 -51
- package/lib/sui/codegen/codegen.js.map +1 -1
- package/lib/sui/context.d.ts +4 -4
- package/lib/sui/context.d.ts.map +1 -1
- package/lib/sui/context.js +2 -2
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/ext/coin.js +74 -74
- package/lib/sui/ext/move-dex.d.ts +2 -3
- package/lib/sui/ext/move-dex.d.ts.map +1 -1
- package/lib/sui/index.d.ts +4 -4
- package/lib/sui/index.d.ts.map +1 -1
- package/lib/sui/index.js +4 -4
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/models.d.ts +2 -2
- package/lib/sui/models.d.ts.map +1 -1
- package/lib/sui/move-coder.d.ts +1 -16
- package/lib/sui/move-coder.d.ts.map +1 -1
- package/lib/sui/move-coder.js +4 -93
- package/lib/sui/move-coder.js.map +1 -1
- package/lib/sui/network.d.ts +3 -2
- package/lib/sui/network.d.ts.map +1 -1
- package/lib/sui/network.js +10 -3
- package/lib/sui/network.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +1 -1
- package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
- package/lib/sui/sui-object-processor-template.js +7 -7
- package/lib/sui/sui-object-processor-template.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +1 -1
- package/lib/sui/sui-object-processor.d.ts.map +1 -1
- package/lib/sui/sui-object-processor.js +5 -5
- package/lib/sui/sui-processor.d.ts +2 -2
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +10 -10
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/sui/utils.d.ts +2 -2
- package/lib/sui/utils.d.ts.map +1 -1
- package/lib/sui/utils.js +3 -4
- package/lib/sui/utils.js.map +1 -1
- package/lib/testing/aptos-facet.d.ts.map +1 -1
- package/lib/testing/aptos-facet.js +8 -9
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/sui-facet.d.ts +1 -1
- package/lib/testing/sui-facet.d.ts.map +1 -1
- package/lib/testing/sui-facet.js +8 -9
- package/lib/testing/sui-facet.js.map +1 -1
- package/package.json +10 -7
- package/src/aptos/abis/0x1.json +4533 -710
- package/src/aptos/abis/0x3.json +147 -2
- package/src/aptos/aptos-processor.ts +13 -12
- package/src/aptos/aptos-resource-processor-template.ts +7 -7
- package/src/aptos/builtin/0x1.ts +2243 -1187
- package/src/aptos/builtin/0x3.ts +205 -249
- package/src/aptos/codegen/codegen.ts +50 -11
- package/src/aptos/context.ts +4 -4
- package/src/aptos/ext/coin-event.ts +2 -2
- package/src/aptos/ext/coin.ts +193 -193
- package/src/aptos/index.ts +15 -4
- package/src/aptos/models.ts +2 -2
- package/src/aptos/move-coder.ts +4 -73
- package/src/aptos/network.ts +9 -1
- package/src/eth/codegen/codegen.ts +5 -4
- package/src/move/ext/move-dex.ts +5 -5
- package/src/move/index.ts +2 -4
- package/src/move/move-context.ts +3 -3
- package/src/move/shared-network-codegen.ts +160 -0
- package/src/sui/builtin/0x1.ts +17 -41
- package/src/sui/builtin/0x2.ts +196 -410
- package/src/sui/builtin/0x3.ts +271 -479
- package/src/sui/codegen/codegen.ts +80 -54
- package/src/sui/context.ts +8 -7
- package/src/sui/ext/coin.ts +75 -75
- package/src/sui/ext/move-dex.ts +3 -3
- package/src/sui/index.ts +5 -5
- package/src/sui/models.ts +2 -2
- package/src/sui/move-coder.ts +4 -108
- package/src/sui/network.ts +12 -4
- package/src/sui/sui-object-processor-template.ts +8 -8
- package/src/sui/sui-object-processor.ts +6 -6
- package/src/sui/sui-processor.ts +12 -16
- package/src/sui/utils.ts +6 -7
- package/src/testing/aptos-facet.ts +8 -9
- package/src/testing/sui-facet.ts +9 -10
- package/lib/aptos/aptos-chain-adapter.d.ts +0 -15
- package/lib/aptos/aptos-chain-adapter.d.ts.map +0 -1
- package/lib/aptos/aptos-chain-adapter.js +0 -72
- package/lib/aptos/aptos-chain-adapter.js.map +0 -1
- package/lib/aptos/module-client.d.ts +0 -7
- package/lib/aptos/module-client.d.ts.map +0 -1
- package/lib/aptos/module-client.js +0 -25
- package/lib/aptos/module-client.js.map +0 -1
- package/lib/aptos/module-client.test.d.ts +0 -2
- package/lib/aptos/module-client.test.d.ts.map +0 -1
- package/lib/aptos/module-client.test.js.map +0 -1
- package/lib/aptos/move-types.d.ts +0 -17
- package/lib/aptos/move-types.d.ts.map +0 -1
- package/lib/aptos/move-types.js +0 -53
- package/lib/aptos/move-types.js.map +0 -1
- package/lib/aptos/utils.d.ts +0 -2
- package/lib/aptos/utils.d.ts.map +0 -1
- package/lib/aptos/utils.js +0 -16
- package/lib/aptos/utils.js.map +0 -1
- package/lib/move/abstract-codegen.d.ts +0 -50
- package/lib/move/abstract-codegen.d.ts.map +0 -1
- package/lib/move/abstract-codegen.js +0 -489
- package/lib/move/abstract-codegen.js.map +0 -1
- package/lib/move/abstract-move-coder.d.ts +0 -29
- package/lib/move/abstract-move-coder.d.ts.map +0 -1
- package/lib/move/abstract-move-coder.js +0 -301
- package/lib/move/abstract-move-coder.js.map +0 -1
- package/lib/move/account.d.ts +0 -16
- package/lib/move/account.d.ts.map +0 -1
- package/lib/move/account.js +0 -71
- package/lib/move/account.js.map +0 -1
- package/lib/move/chain-adapter.d.ts +0 -13
- package/lib/move/chain-adapter.d.ts.map +0 -1
- package/lib/move/chain-adapter.js +0 -7
- package/lib/move/chain-adapter.js.map +0 -1
- package/lib/move/internal-models.d.ts +0 -35
- package/lib/move/internal-models.d.ts.map +0 -1
- package/lib/move/internal-models.js +0 -7
- package/lib/move/internal-models.js.map +0 -1
- package/lib/move/ts-type.test.d.ts +0 -2
- package/lib/move/ts-type.test.d.ts.map +0 -1
- package/lib/move/ts-type.test.js.map +0 -1
- package/lib/move/types.d.ts +0 -42
- package/lib/move/types.d.ts.map +0 -1
- package/lib/move/types.js +0 -205
- package/lib/move/types.js.map +0 -1
- package/lib/move/utils.d.ts +0 -16
- package/lib/move/utils.d.ts.map +0 -1
- package/lib/move/utils.js +0 -53
- package/lib/move/utils.js.map +0 -1
- package/lib/move/utils.test.d.ts +0 -2
- package/lib/move/utils.test.d.ts.map +0 -1
- package/lib/move/utils.test.js.map +0 -1
- package/lib/sui/module-client.d.ts +0 -4
- package/lib/sui/module-client.d.ts.map +0 -1
- package/lib/sui/module-client.js +0 -7
- package/lib/sui/module-client.js.map +0 -1
- package/lib/sui/move-types.d.ts +0 -9
- package/lib/sui/move-types.d.ts.map +0 -1
- package/lib/sui/move-types.js +0 -82
- package/lib/sui/move-types.js.map +0 -1
- package/lib/sui/sui-chain-adapter.d.ts +0 -15
- package/lib/sui/sui-chain-adapter.d.ts.map +0 -1
- package/lib/sui/sui-chain-adapter.js +0 -71
- package/lib/sui/sui-chain-adapter.js.map +0 -1
- package/src/aptos/aptos-chain-adapter.ts +0 -86
- package/src/aptos/module-client.ts +0 -30
- package/src/aptos/move-types.ts +0 -73
- package/src/aptos/utils.ts +0 -15
- package/src/move/abstract-codegen.ts +0 -596
- package/src/move/abstract-move-coder.ts +0 -337
- package/src/move/account.ts +0 -81
- package/src/move/chain-adapter.ts +0 -24
- package/src/move/internal-models.ts +0 -40
- package/src/move/types.ts +0 -241
- package/src/move/utils.ts +0 -69
- package/src/sui/module-client.ts +0 -7
- package/src/sui/move-types.ts +0 -108
- package/src/sui/sui-chain-adapter.ts +0 -93
package/src/move/types.ts
DELETED
@@ -1,241 +0,0 @@
|
|
1
|
-
import { accountTypeString, SPLITTER, VECTOR_STR } from './utils.js'
|
2
|
-
|
3
|
-
export type DecodedStruct<B, T> = B & {
|
4
|
-
/**
|
5
|
-
* decoded data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
|
6
|
-
*/
|
7
|
-
data_decoded: T
|
8
|
-
type_arguments: string[]
|
9
|
-
}
|
10
|
-
|
11
|
-
export class TypeDescriptor<T = any> {
|
12
|
-
qname: string
|
13
|
-
reference: boolean
|
14
|
-
mutable: boolean
|
15
|
-
typeArgs: TypeDescriptor[]
|
16
|
-
|
17
|
-
constructor(symbol: string, typeParams?: TypeDescriptor[]) {
|
18
|
-
this.qname = symbol
|
19
|
-
this.reference = false
|
20
|
-
this.mutable = false
|
21
|
-
this.typeArgs = typeParams || []
|
22
|
-
}
|
23
|
-
|
24
|
-
apply(...typeArgs: TypeDescriptor[]): TypeDescriptor {
|
25
|
-
const newObj = this.clone()
|
26
|
-
newObj.typeArgs = typeArgs
|
27
|
-
return newObj
|
28
|
-
}
|
29
|
-
|
30
|
-
clone(): this {
|
31
|
-
const newObj = new TypeDescriptor(this.qname, this.typeArgs)
|
32
|
-
newObj.reference = this.reference
|
33
|
-
newObj.mutable = this.mutable
|
34
|
-
return newObj as any
|
35
|
-
}
|
36
|
-
|
37
|
-
// compare qname without consider case for system type
|
38
|
-
compareQname(t: TypeDescriptor): boolean {
|
39
|
-
let t1 = this.qname
|
40
|
-
if (BUILTIN_TYPES_SET.has(this.qname.toLowerCase())) {
|
41
|
-
t1 = this.qname.toLowerCase()
|
42
|
-
}
|
43
|
-
let t2 = t.qname
|
44
|
-
if (BUILTIN_TYPES_SET.has(t.qname.toLowerCase())) {
|
45
|
-
t2 = t.qname
|
46
|
-
}
|
47
|
-
return t1 === t2
|
48
|
-
}
|
49
|
-
|
50
|
-
getSignature(): string {
|
51
|
-
if (this.typeArgs.length > 0) {
|
52
|
-
return this.qname + '<' + this.typeArgs.map((t) => t.getSignature()).join(', ') + '>'
|
53
|
-
}
|
54
|
-
return this.qname
|
55
|
-
}
|
56
|
-
|
57
|
-
// Replace T0, T1 with more concrete type
|
58
|
-
applyTypeArgs(ctx: Map<string, TypeDescriptor>): TypeDescriptor {
|
59
|
-
const replace = ctx.get(this.qname)
|
60
|
-
if (replace) {
|
61
|
-
return replace
|
62
|
-
}
|
63
|
-
if (ctx.size === 0 || this.typeArgs.length === 0) {
|
64
|
-
return this
|
65
|
-
}
|
66
|
-
|
67
|
-
const typeArgs: TypeDescriptor[] = []
|
68
|
-
for (const arg of this.typeArgs) {
|
69
|
-
const replace = ctx.get(arg.qname)
|
70
|
-
if (replace) {
|
71
|
-
typeArgs.push(replace)
|
72
|
-
} else {
|
73
|
-
typeArgs.push(arg.applyTypeArgs(ctx))
|
74
|
-
}
|
75
|
-
}
|
76
|
-
return new TypeDescriptor(this.qname, typeArgs)
|
77
|
-
}
|
78
|
-
|
79
|
-
// all depended types including itself, not include system type
|
80
|
-
dependedTypes(): string[] {
|
81
|
-
if (this.qname.startsWith('&')) {
|
82
|
-
console.error('Not expected &')
|
83
|
-
return []
|
84
|
-
}
|
85
|
-
|
86
|
-
if (this.qname.toLowerCase() === VECTOR_STR) {
|
87
|
-
return this.typeArgs[0].dependedTypes()
|
88
|
-
}
|
89
|
-
|
90
|
-
if (BUILTIN_TYPES_SET.has(this.qname.toLowerCase())) {
|
91
|
-
return []
|
92
|
-
}
|
93
|
-
switch (this.qname) {
|
94
|
-
case 'signer':
|
95
|
-
case '0x1::string::String':
|
96
|
-
return []
|
97
|
-
}
|
98
|
-
|
99
|
-
// Type parameters are not depended
|
100
|
-
if (this.qname.indexOf(SPLITTER) == -1) {
|
101
|
-
if (this.qname.startsWith('T')) {
|
102
|
-
return []
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
const types = new Set<string>()
|
107
|
-
for (const param of this.typeArgs) {
|
108
|
-
param.dependedTypes().forEach((t) => types.add(t))
|
109
|
-
}
|
110
|
-
|
111
|
-
types.add(this.qname)
|
112
|
-
|
113
|
-
return Array.from(types)
|
114
|
-
}
|
115
|
-
}
|
116
|
-
|
117
|
-
export function parseMoveType(type: string): TypeDescriptor {
|
118
|
-
const stack: TypeDescriptor[] = [new TypeDescriptor('')]
|
119
|
-
let buffer = []
|
120
|
-
|
121
|
-
// xxx:asdf<g1<a,<c,d>>, b, g2<a,b>, e>
|
122
|
-
for (let i = 0; i < type.length; i++) {
|
123
|
-
const ch = type[i]
|
124
|
-
if (ch === ' ') {
|
125
|
-
continue
|
126
|
-
}
|
127
|
-
if (ch === '<') {
|
128
|
-
// const symbol = type.slice(symbolStart, i)
|
129
|
-
// symbolStart =
|
130
|
-
const symbol = buffer.join('')
|
131
|
-
buffer = []
|
132
|
-
stack[stack.length - 1].qname = symbol
|
133
|
-
adjustType(stack[stack.length - 1])
|
134
|
-
stack.push(new TypeDescriptor(''))
|
135
|
-
continue
|
136
|
-
}
|
137
|
-
if (ch === '>' || ch === ',') {
|
138
|
-
const typeParam = stack.pop()
|
139
|
-
if (!typeParam) {
|
140
|
-
throw Error('Unexpected stack size')
|
141
|
-
}
|
142
|
-
if (buffer.length > 0) {
|
143
|
-
typeParam.qname = buffer.join('')
|
144
|
-
buffer = []
|
145
|
-
}
|
146
|
-
adjustType(typeParam)
|
147
|
-
stack[stack.length - 1].typeArgs.push(typeParam)
|
148
|
-
if (ch === ',') {
|
149
|
-
stack.push(new TypeDescriptor(''))
|
150
|
-
}
|
151
|
-
continue
|
152
|
-
}
|
153
|
-
buffer.push(ch)
|
154
|
-
}
|
155
|
-
|
156
|
-
if (buffer.length > 0) {
|
157
|
-
stack[stack.length - 1].qname = buffer.join('')
|
158
|
-
}
|
159
|
-
adjustType(stack[stack.length - 1])
|
160
|
-
|
161
|
-
const res = stack.pop()
|
162
|
-
if (!res || stack.length > 0) {
|
163
|
-
throw Error('Unexpected stack size')
|
164
|
-
}
|
165
|
-
return res
|
166
|
-
}
|
167
|
-
|
168
|
-
function adjustType(type: TypeDescriptor) {
|
169
|
-
if (type.qname.startsWith('&')) {
|
170
|
-
type.reference = true
|
171
|
-
type.qname = type.qname.slice(1)
|
172
|
-
}
|
173
|
-
if (type.qname.startsWith('mut')) {
|
174
|
-
type.mutable = true
|
175
|
-
type.qname = type.qname.slice(3)
|
176
|
-
}
|
177
|
-
const parts = type.qname.split(SPLITTER)
|
178
|
-
if (parts.length > 1) {
|
179
|
-
const [account, module, name] = parts
|
180
|
-
type.qname = [accountTypeString(account), module, name].join(SPLITTER)
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
export const ANY_TYPE = new TypeDescriptor<any>('any')
|
185
|
-
|
186
|
-
export function vectorType<T>(t: TypeDescriptor<T> = ANY_TYPE): TypeDescriptor<T[]> {
|
187
|
-
return BUILTIN_TYPES.VECTOR_TYPE_ANY.apply(t)
|
188
|
-
}
|
189
|
-
|
190
|
-
export const BUILTIN_TYPES = {
|
191
|
-
ADDRESS_TYPE: new TypeDescriptor<string>('address'),
|
192
|
-
// export const Address = new TypeDescriptor<string>("Address")
|
193
|
-
|
194
|
-
VECTOR_TYPE_ANY: new TypeDescriptor<any[]>('vector'),
|
195
|
-
VECTOR_TYPE: vectorType,
|
196
|
-
|
197
|
-
BOOL_TYPE: new TypeDescriptor<number>('bool'),
|
198
|
-
|
199
|
-
U8_TYPE: new TypeDescriptor<number>('u8'),
|
200
|
-
// export const U8 = new TypeDescriptor<number>("U8")
|
201
|
-
U16_TYPE: new TypeDescriptor<number>('u16'),
|
202
|
-
// export const U16 = new TypeDescriptor<number>("U16")
|
203
|
-
U32_TYPE: new TypeDescriptor<number>('u32'),
|
204
|
-
// export const U32 = new TypeDescriptor<number>("U32")
|
205
|
-
U64_TYPE: new TypeDescriptor<number>('u64'),
|
206
|
-
// export const U64 = new TypeDescriptor<number>("U64")
|
207
|
-
U128_TYPE: new TypeDescriptor<number>('u128'),
|
208
|
-
// export const U128 = new TypeDescriptor<number>("U128")
|
209
|
-
U256_TYPE: new TypeDescriptor<number>('u256'),
|
210
|
-
// export const U256 = new TypeDescriptor<number>("U256")
|
211
|
-
}
|
212
|
-
|
213
|
-
const BUILTIN_TYPES_SET = new Set(
|
214
|
-
Object.values(BUILTIN_TYPES).flatMap((t) => {
|
215
|
-
if (typeof t === 'object') {
|
216
|
-
return [t.qname.toLowerCase()]
|
217
|
-
}
|
218
|
-
return []
|
219
|
-
})
|
220
|
-
)
|
221
|
-
|
222
|
-
/**
|
223
|
-
*
|
224
|
-
* @param matcher
|
225
|
-
* @param type
|
226
|
-
*/
|
227
|
-
export function matchType(matcher: TypeDescriptor, type: TypeDescriptor): boolean {
|
228
|
-
if (matcher.qname === 'any') {
|
229
|
-
return true
|
230
|
-
}
|
231
|
-
if (!matcher.compareQname(type)) {
|
232
|
-
return false
|
233
|
-
}
|
234
|
-
for (const [idx, matcherTarg] of matcher.typeArgs.entries()) {
|
235
|
-
const targ = type.typeArgs[idx]
|
236
|
-
if (!matchType(matcherTarg, targ)) {
|
237
|
-
return false
|
238
|
-
}
|
239
|
-
}
|
240
|
-
return true
|
241
|
-
}
|
package/src/move/utils.ts
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
import { InternalMoveModule, InternalMoveStruct } from './internal-models.js'
|
2
|
-
|
3
|
-
export const SPLITTER = '::'
|
4
|
-
|
5
|
-
export const VECTOR_STR = 'vector'
|
6
|
-
|
7
|
-
export function isFrameworkAccount(account: string) {
|
8
|
-
const n = parseInt(account, 16)
|
9
|
-
if (Number.isNaN(n)) {
|
10
|
-
return false
|
11
|
-
}
|
12
|
-
return n >= 0 && n < 16
|
13
|
-
}
|
14
|
-
|
15
|
-
// strip any lead 0
|
16
|
-
export function accountTypeString(account: string): string {
|
17
|
-
const withoutPrefix = account.toLowerCase().replace(/^(0x)/, '')
|
18
|
-
return '0x' + withoutPrefix.replace(/^0*/, '')
|
19
|
-
}
|
20
|
-
|
21
|
-
const MOVE_ADDRESS_LENGTH = 32
|
22
|
-
|
23
|
-
function isHex(value: string): boolean {
|
24
|
-
return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
|
25
|
-
}
|
26
|
-
|
27
|
-
function getHexByteLength(value: string): number {
|
28
|
-
return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
|
29
|
-
}
|
30
|
-
|
31
|
-
export function isValidMoveAddress(value: string): boolean {
|
32
|
-
return isHex(value) && getHexByteLength(value) <= MOVE_ADDRESS_LENGTH
|
33
|
-
}
|
34
|
-
|
35
|
-
// Get full address with 32 bytes
|
36
|
-
export function accountAddressString(account: string): string {
|
37
|
-
if (!isValidMoveAddress(account)) {
|
38
|
-
throw Error('Not valid move address')
|
39
|
-
}
|
40
|
-
|
41
|
-
const address = account.toLowerCase().replace(/^(0x)/, '')
|
42
|
-
return `0x${address.padStart(MOVE_ADDRESS_LENGTH * 2, '0')}`
|
43
|
-
}
|
44
|
-
|
45
|
-
const KEYWORDS = new Set(['package', 'namespace', 'volatile', 'object', 'string', 'number', 'bigint', 'any'])
|
46
|
-
|
47
|
-
export function normalizeToJSName(name: string) {
|
48
|
-
if (KEYWORDS.has(name)) {
|
49
|
-
return name + '_'
|
50
|
-
}
|
51
|
-
return name
|
52
|
-
}
|
53
|
-
|
54
|
-
export function moduleQnameForType(type: string): [string, string] {
|
55
|
-
const parts = type.split(SPLITTER).slice(0, 2)
|
56
|
-
return [parts[0], parts[1]]
|
57
|
-
}
|
58
|
-
|
59
|
-
export function moduleQname(module: { address: string; name: string }): string {
|
60
|
-
return accountTypeString(module.address) + SPLITTER + module.name
|
61
|
-
}
|
62
|
-
|
63
|
-
export function structQname(module: InternalMoveModule, struct: InternalMoveStruct): string {
|
64
|
-
return [accountTypeString(module.address), module.name, struct.name].join(SPLITTER)
|
65
|
-
}
|
66
|
-
|
67
|
-
export function upperFirst(str: string): string {
|
68
|
-
return str.charAt(0).toUpperCase() + str.slice(1)
|
69
|
-
}
|
package/src/sui/module-client.ts
DELETED
package/src/sui/move-types.ts
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
import type {
|
2
|
-
SuiMoveNormalizedField,
|
3
|
-
SuiMoveNormalizedFunction,
|
4
|
-
SuiMoveNormalizedModule,
|
5
|
-
SuiMoveNormalizedStruct,
|
6
|
-
SuiMoveNormalizedType,
|
7
|
-
} from '@mysten/sui.js'
|
8
|
-
import {
|
9
|
-
InternalMoveFunction,
|
10
|
-
InternalMoveFunctionVisibility,
|
11
|
-
InternalMoveModule,
|
12
|
-
InternalMoveStruct,
|
13
|
-
InternalMoveStructField,
|
14
|
-
} from '../move/internal-models.js'
|
15
|
-
import { SPLITTER, TypeDescriptor } from '../move/index.js'
|
16
|
-
|
17
|
-
export function toInternalModule(module: SuiMoveNormalizedModule): InternalMoveModule {
|
18
|
-
return {
|
19
|
-
address: module.address,
|
20
|
-
exposedFunctions: Object.entries(module.exposedFunctions).map(([n, f]) => toInternalFunction(n, f)),
|
21
|
-
name: module.name,
|
22
|
-
structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
export function toInternalFunction(name: string, func: SuiMoveNormalizedFunction): InternalMoveFunction {
|
27
|
-
let visibility
|
28
|
-
switch (func.visibility) {
|
29
|
-
case 'Private':
|
30
|
-
visibility = InternalMoveFunctionVisibility.PRIVATE
|
31
|
-
break
|
32
|
-
case 'Public':
|
33
|
-
visibility = InternalMoveFunctionVisibility.PUBLIC
|
34
|
-
break
|
35
|
-
case 'Friend':
|
36
|
-
visibility = InternalMoveFunctionVisibility.FRIEND
|
37
|
-
break
|
38
|
-
default:
|
39
|
-
throw Error('No visibility for function' + name)
|
40
|
-
}
|
41
|
-
return {
|
42
|
-
typeParams: func.typeParameters.map((p: any) => {
|
43
|
-
return { constraints: p.abilities }
|
44
|
-
}),
|
45
|
-
isEntry: func.isEntry,
|
46
|
-
name: name,
|
47
|
-
params: func.parameters.map(toTypeDescriptor),
|
48
|
-
return: func.return.map(toTypeDescriptor),
|
49
|
-
visibility: visibility,
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
export function toInternalStruct(name: string, struct: SuiMoveNormalizedStruct): InternalMoveStruct {
|
54
|
-
return {
|
55
|
-
abilities: struct.abilities.abilities,
|
56
|
-
fields: struct.fields.map(toInternalField),
|
57
|
-
typeParams: struct.typeParameters.map((p: any) => {
|
58
|
-
return { constraints: p.constraints.abilities }
|
59
|
-
}),
|
60
|
-
isNative: false,
|
61
|
-
name: name,
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
export function toInternalField(module: SuiMoveNormalizedField): InternalMoveStructField {
|
66
|
-
return {
|
67
|
-
name: module.name,
|
68
|
-
type: toTypeDescriptor(module.type),
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
export function toTypeDescriptor(normalizedType: SuiMoveNormalizedType): TypeDescriptor {
|
73
|
-
if (typeof normalizedType === 'string') {
|
74
|
-
return new TypeDescriptor(normalizedType)
|
75
|
-
}
|
76
|
-
|
77
|
-
if ('Struct' in normalizedType) {
|
78
|
-
const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(
|
79
|
-
SPLITTER
|
80
|
-
)
|
81
|
-
|
82
|
-
const args = normalizedType.Struct.typeArguments.map(toTypeDescriptor)
|
83
|
-
|
84
|
-
return new TypeDescriptor(qname, args)
|
85
|
-
}
|
86
|
-
|
87
|
-
if ('Vector' in normalizedType) {
|
88
|
-
return new TypeDescriptor('Vector', [toTypeDescriptor(normalizedType.Vector)])
|
89
|
-
}
|
90
|
-
if ('TypeParameter' in normalizedType) {
|
91
|
-
return new TypeDescriptor('T' + normalizedType.TypeParameter)
|
92
|
-
}
|
93
|
-
|
94
|
-
if ('Reference' in normalizedType) {
|
95
|
-
const res = toTypeDescriptor(normalizedType.Reference)
|
96
|
-
res.reference = true
|
97
|
-
return res
|
98
|
-
}
|
99
|
-
|
100
|
-
if ('MutableReference' in normalizedType) {
|
101
|
-
const res = toTypeDescriptor(normalizedType.MutableReference)
|
102
|
-
res.reference = true
|
103
|
-
res.mutable = true
|
104
|
-
return res
|
105
|
-
}
|
106
|
-
|
107
|
-
throw new Error('Unexpected sui type')
|
108
|
-
}
|
@@ -1,93 +0,0 @@
|
|
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
|
-
return params
|
30
|
-
// if (params.length === 0) {
|
31
|
-
// return params
|
32
|
-
// }
|
33
|
-
// return params.slice(0, params.length - 1)
|
34
|
-
}
|
35
|
-
|
36
|
-
toInternalModules(modules: SuiMoveNormalizedModule[]): InternalMoveModule[] {
|
37
|
-
return Object.values(modules).map(toInternalModule)
|
38
|
-
}
|
39
|
-
|
40
|
-
getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
|
41
|
-
const eventMap = new Map<string, InternalMoveStruct>()
|
42
|
-
|
43
|
-
for (const module of modules) {
|
44
|
-
const qname = moduleQname(module)
|
45
|
-
|
46
|
-
for (const struct of module.structs) {
|
47
|
-
const abilities = new Set(struct.abilities)
|
48
|
-
if (abilities.has('Drop') && abilities.has('Copy')) {
|
49
|
-
eventMap.set(qname + SPLITTER + struct.name, struct)
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
return eventMap
|
54
|
-
}
|
55
|
-
|
56
|
-
getType(base: SuiEvent | SuiMoveObject): string {
|
57
|
-
return base.type
|
58
|
-
}
|
59
|
-
|
60
|
-
getData(val: SuiEvent | SuiMoveObject) {
|
61
|
-
if (SuiEvent.is(val)) {
|
62
|
-
return val.parsedJson as any
|
63
|
-
}
|
64
|
-
if (SuiParsedData.is(val)) {
|
65
|
-
return val.fields as any
|
66
|
-
}
|
67
|
-
// if (SuiMoveObject.is(val)) {
|
68
|
-
// return val.fields as any
|
69
|
-
// }
|
70
|
-
// This may not be perfect, just think everything has
|
71
|
-
if ('fields' in val) {
|
72
|
-
if ('type' in val && Object.keys(val).length === 2) {
|
73
|
-
return val.fields as any
|
74
|
-
}
|
75
|
-
}
|
76
|
-
return val as any
|
77
|
-
}
|
78
|
-
// validateAndNormalizeAddress(address: string) {
|
79
|
-
// return validateAndNormalizeAddress(address)
|
80
|
-
// }
|
81
|
-
}
|
82
|
-
|
83
|
-
function getRpcEndpoint(network: SuiNetwork): string {
|
84
|
-
switch (network) {
|
85
|
-
case SuiNetwork.TEST_NET:
|
86
|
-
return 'https://fullnode.testnet.sui.io/'
|
87
|
-
}
|
88
|
-
return 'https://fullnode.mainnet.sui.io/'
|
89
|
-
}
|
90
|
-
|
91
|
-
function getRpcClient(network: SuiNetwork): JsonRpcProvider {
|
92
|
-
return new JsonRpcProvider(new Connection({ fullnode: getRpcEndpoint(network) }))
|
93
|
-
}
|