@sentio/sdk 2.23.0-rc.1 → 2.24.0-rc.1

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 (228) hide show
  1. package/lib/aptos/aptos-processor.d.ts +1 -2
  2. package/lib/aptos/aptos-processor.d.ts.map +1 -1
  3. package/lib/aptos/aptos-processor.js +11 -11
  4. package/lib/aptos/aptos-processor.js.map +1 -1
  5. package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
  6. package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
  7. package/lib/aptos/aptos-resource-processor-template.js +6 -6
  8. package/lib/aptos/builtin/0x1.d.ts +342 -339
  9. package/lib/aptos/builtin/0x1.d.ts.map +1 -1
  10. package/lib/aptos/builtin/0x1.js +65 -188
  11. package/lib/aptos/builtin/0x1.js.map +1 -1
  12. package/lib/aptos/builtin/0x3.d.ts +73 -54
  13. package/lib/aptos/builtin/0x3.d.ts.map +1 -1
  14. package/lib/aptos/builtin/0x3.js +24 -65
  15. package/lib/aptos/builtin/0x3.js.map +1 -1
  16. package/lib/aptos/codegen/codegen.d.ts.map +1 -1
  17. package/lib/aptos/codegen/codegen.js +40 -10
  18. package/lib/aptos/codegen/codegen.js.map +1 -1
  19. package/lib/aptos/context.d.ts +1 -2
  20. package/lib/aptos/context.d.ts.map +1 -1
  21. package/lib/aptos/context.js +2 -2
  22. package/lib/aptos/context.js.map +1 -1
  23. package/lib/aptos/ext/coin-event.js +1 -1
  24. package/lib/aptos/ext/coin.js +193 -193
  25. package/lib/aptos/ext/coin.js.map +1 -1
  26. package/lib/aptos/index.d.ts +4 -4
  27. package/lib/aptos/index.d.ts.map +1 -1
  28. package/lib/aptos/index.js +3 -4
  29. package/lib/aptos/index.js.map +1 -1
  30. package/lib/aptos/models.d.ts +2 -2
  31. package/lib/aptos/models.d.ts.map +1 -1
  32. package/lib/aptos/move-coder.d.ts +1 -13
  33. package/lib/aptos/move-coder.d.ts.map +1 -1
  34. package/lib/aptos/move-coder.js +4 -55
  35. package/lib/aptos/move-coder.js.map +1 -1
  36. package/lib/aptos/network.d.ts +1 -0
  37. package/lib/aptos/network.d.ts.map +1 -1
  38. package/lib/aptos/network.js +8 -1
  39. package/lib/aptos/network.js.map +1 -1
  40. package/lib/eth/codegen/codegen.d.ts.map +1 -1
  41. package/lib/eth/codegen/codegen.js +4 -3
  42. package/lib/eth/codegen/codegen.js.map +1 -1
  43. package/lib/move/ext/move-dex.d.ts +1 -1
  44. package/lib/move/ext/move-dex.d.ts.map +1 -1
  45. package/lib/move/ext/move-dex.js +4 -4
  46. package/lib/move/index.d.ts +1 -4
  47. package/lib/move/index.d.ts.map +1 -1
  48. package/lib/move/index.js +1 -4
  49. package/lib/move/index.js.map +1 -1
  50. package/lib/move/move-context.d.ts +3 -3
  51. package/lib/move/move-context.d.ts.map +1 -1
  52. package/lib/move/move-context.js.map +1 -1
  53. package/lib/move/shared-network-codegen.d.ts +14 -0
  54. package/lib/move/shared-network-codegen.d.ts.map +1 -0
  55. package/lib/move/shared-network-codegen.js +116 -0
  56. package/lib/move/shared-network-codegen.js.map +1 -0
  57. package/lib/sui/builtin/0x1.d.ts +4 -2
  58. package/lib/sui/builtin/0x1.d.ts.map +1 -1
  59. package/lib/sui/builtin/0x1.js +7 -14
  60. package/lib/sui/builtin/0x1.js.map +1 -1
  61. package/lib/sui/builtin/0x2.d.ts +52 -168
  62. package/lib/sui/builtin/0x2.d.ts.map +1 -1
  63. package/lib/sui/builtin/0x2.js +24 -65
  64. package/lib/sui/builtin/0x2.js.map +1 -1
  65. package/lib/sui/builtin/0x3.d.ts +113 -331
  66. package/lib/sui/builtin/0x3.d.ts.map +1 -1
  67. package/lib/sui/builtin/0x3.js +13 -32
  68. package/lib/sui/builtin/0x3.js.map +1 -1
  69. package/lib/sui/codegen/codegen.d.ts.map +1 -1
  70. package/lib/sui/codegen/codegen.js +72 -51
  71. package/lib/sui/codegen/codegen.js.map +1 -1
  72. package/lib/sui/context.d.ts +4 -4
  73. package/lib/sui/context.d.ts.map +1 -1
  74. package/lib/sui/context.js +2 -2
  75. package/lib/sui/context.js.map +1 -1
  76. package/lib/sui/ext/coin.js +74 -74
  77. package/lib/sui/ext/move-dex.d.ts +2 -3
  78. package/lib/sui/ext/move-dex.d.ts.map +1 -1
  79. package/lib/sui/index.d.ts +4 -4
  80. package/lib/sui/index.d.ts.map +1 -1
  81. package/lib/sui/index.js +4 -4
  82. package/lib/sui/index.js.map +1 -1
  83. package/lib/sui/models.d.ts +2 -2
  84. package/lib/sui/models.d.ts.map +1 -1
  85. package/lib/sui/move-coder.d.ts +1 -16
  86. package/lib/sui/move-coder.d.ts.map +1 -1
  87. package/lib/sui/move-coder.js +4 -93
  88. package/lib/sui/move-coder.js.map +1 -1
  89. package/lib/sui/network.d.ts +3 -2
  90. package/lib/sui/network.d.ts.map +1 -1
  91. package/lib/sui/network.js +10 -3
  92. package/lib/sui/network.js.map +1 -1
  93. package/lib/sui/sui-object-processor-template.d.ts +1 -1
  94. package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
  95. package/lib/sui/sui-object-processor-template.js +7 -7
  96. package/lib/sui/sui-object-processor-template.js.map +1 -1
  97. package/lib/sui/sui-object-processor.d.ts +1 -1
  98. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  99. package/lib/sui/sui-object-processor.js +5 -5
  100. package/lib/sui/sui-processor.d.ts +2 -2
  101. package/lib/sui/sui-processor.d.ts.map +1 -1
  102. package/lib/sui/sui-processor.js +10 -10
  103. package/lib/sui/sui-processor.js.map +1 -1
  104. package/lib/sui/utils.d.ts +2 -2
  105. package/lib/sui/utils.d.ts.map +1 -1
  106. package/lib/sui/utils.js +3 -4
  107. package/lib/sui/utils.js.map +1 -1
  108. package/lib/testing/aptos-facet.d.ts.map +1 -1
  109. package/lib/testing/aptos-facet.js +8 -9
  110. package/lib/testing/aptos-facet.js.map +1 -1
  111. package/lib/testing/sui-facet.d.ts +1 -1
  112. package/lib/testing/sui-facet.d.ts.map +1 -1
  113. package/lib/testing/sui-facet.js +8 -9
  114. package/lib/testing/sui-facet.js.map +1 -1
  115. package/package.json +10 -7
  116. package/src/aptos/aptos-processor.ts +13 -12
  117. package/src/aptos/aptos-resource-processor-template.ts +7 -7
  118. package/src/aptos/builtin/0x1.ts +970 -1168
  119. package/src/aptos/builtin/0x3.ts +205 -249
  120. package/src/aptos/codegen/codegen.ts +50 -11
  121. package/src/aptos/context.ts +4 -4
  122. package/src/aptos/ext/coin-event.ts +2 -2
  123. package/src/aptos/ext/coin.ts +193 -193
  124. package/src/aptos/index.ts +15 -4
  125. package/src/aptos/models.ts +2 -2
  126. package/src/aptos/move-coder.ts +4 -73
  127. package/src/aptos/network.ts +9 -1
  128. package/src/eth/codegen/codegen.ts +5 -4
  129. package/src/move/ext/move-dex.ts +5 -5
  130. package/src/move/index.ts +2 -4
  131. package/src/move/move-context.ts +3 -3
  132. package/src/move/shared-network-codegen.ts +160 -0
  133. package/src/sui/builtin/0x1.ts +17 -41
  134. package/src/sui/builtin/0x2.ts +196 -410
  135. package/src/sui/builtin/0x3.ts +271 -479
  136. package/src/sui/codegen/codegen.ts +80 -54
  137. package/src/sui/context.ts +8 -7
  138. package/src/sui/ext/coin.ts +75 -75
  139. package/src/sui/ext/move-dex.ts +3 -3
  140. package/src/sui/index.ts +5 -5
  141. package/src/sui/models.ts +2 -2
  142. package/src/sui/move-coder.ts +4 -108
  143. package/src/sui/network.ts +12 -4
  144. package/src/sui/sui-object-processor-template.ts +8 -8
  145. package/src/sui/sui-object-processor.ts +6 -6
  146. package/src/sui/sui-processor.ts +12 -16
  147. package/src/sui/utils.ts +6 -7
  148. package/src/testing/aptos-facet.ts +8 -9
  149. package/src/testing/sui-facet.ts +9 -10
  150. package/lib/aptos/aptos-chain-adapter.d.ts +0 -15
  151. package/lib/aptos/aptos-chain-adapter.d.ts.map +0 -1
  152. package/lib/aptos/aptos-chain-adapter.js +0 -72
  153. package/lib/aptos/aptos-chain-adapter.js.map +0 -1
  154. package/lib/aptos/module-client.d.ts +0 -7
  155. package/lib/aptos/module-client.d.ts.map +0 -1
  156. package/lib/aptos/module-client.js +0 -25
  157. package/lib/aptos/module-client.js.map +0 -1
  158. package/lib/aptos/module-client.test.d.ts +0 -2
  159. package/lib/aptos/module-client.test.d.ts.map +0 -1
  160. package/lib/aptos/module-client.test.js.map +0 -1
  161. package/lib/aptos/move-types.d.ts +0 -17
  162. package/lib/aptos/move-types.d.ts.map +0 -1
  163. package/lib/aptos/move-types.js +0 -53
  164. package/lib/aptos/move-types.js.map +0 -1
  165. package/lib/aptos/utils.d.ts +0 -2
  166. package/lib/aptos/utils.d.ts.map +0 -1
  167. package/lib/aptos/utils.js +0 -16
  168. package/lib/aptos/utils.js.map +0 -1
  169. package/lib/move/abstract-codegen.d.ts +0 -50
  170. package/lib/move/abstract-codegen.d.ts.map +0 -1
  171. package/lib/move/abstract-codegen.js +0 -489
  172. package/lib/move/abstract-codegen.js.map +0 -1
  173. package/lib/move/abstract-move-coder.d.ts +0 -29
  174. package/lib/move/abstract-move-coder.d.ts.map +0 -1
  175. package/lib/move/abstract-move-coder.js +0 -301
  176. package/lib/move/abstract-move-coder.js.map +0 -1
  177. package/lib/move/account.d.ts +0 -16
  178. package/lib/move/account.d.ts.map +0 -1
  179. package/lib/move/account.js +0 -71
  180. package/lib/move/account.js.map +0 -1
  181. package/lib/move/chain-adapter.d.ts +0 -13
  182. package/lib/move/chain-adapter.d.ts.map +0 -1
  183. package/lib/move/chain-adapter.js +0 -7
  184. package/lib/move/chain-adapter.js.map +0 -1
  185. package/lib/move/internal-models.d.ts +0 -35
  186. package/lib/move/internal-models.d.ts.map +0 -1
  187. package/lib/move/internal-models.js +0 -7
  188. package/lib/move/internal-models.js.map +0 -1
  189. package/lib/move/ts-type.test.d.ts +0 -2
  190. package/lib/move/ts-type.test.d.ts.map +0 -1
  191. package/lib/move/ts-type.test.js.map +0 -1
  192. package/lib/move/types.d.ts +0 -42
  193. package/lib/move/types.d.ts.map +0 -1
  194. package/lib/move/types.js +0 -205
  195. package/lib/move/types.js.map +0 -1
  196. package/lib/move/utils.d.ts +0 -16
  197. package/lib/move/utils.d.ts.map +0 -1
  198. package/lib/move/utils.js +0 -53
  199. package/lib/move/utils.js.map +0 -1
  200. package/lib/move/utils.test.d.ts +0 -2
  201. package/lib/move/utils.test.d.ts.map +0 -1
  202. package/lib/move/utils.test.js.map +0 -1
  203. package/lib/sui/module-client.d.ts +0 -4
  204. package/lib/sui/module-client.d.ts.map +0 -1
  205. package/lib/sui/module-client.js +0 -7
  206. package/lib/sui/module-client.js.map +0 -1
  207. package/lib/sui/move-types.d.ts +0 -9
  208. package/lib/sui/move-types.d.ts.map +0 -1
  209. package/lib/sui/move-types.js +0 -82
  210. package/lib/sui/move-types.js.map +0 -1
  211. package/lib/sui/sui-chain-adapter.d.ts +0 -15
  212. package/lib/sui/sui-chain-adapter.d.ts.map +0 -1
  213. package/lib/sui/sui-chain-adapter.js +0 -71
  214. package/lib/sui/sui-chain-adapter.js.map +0 -1
  215. package/src/aptos/aptos-chain-adapter.ts +0 -86
  216. package/src/aptos/module-client.ts +0 -30
  217. package/src/aptos/move-types.ts +0 -73
  218. package/src/aptos/utils.ts +0 -15
  219. package/src/move/abstract-codegen.ts +0 -596
  220. package/src/move/abstract-move-coder.ts +0 -337
  221. package/src/move/account.ts +0 -81
  222. package/src/move/chain-adapter.ts +0 -24
  223. package/src/move/internal-models.ts +0 -40
  224. package/src/move/types.ts +0 -241
  225. package/src/move/utils.ts +0 -69
  226. package/src/sui/module-client.ts +0 -7
  227. package/src/sui/move-types.ts +0 -108
  228. 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
- }
@@ -1,7 +0,0 @@
1
- // import { JsonRpcProvider } from "@mysten/sui.js";
2
-
3
- export class ModuleClient {
4
- public async viewDecoded(func: string, typeArguments: string[], args: any[], ledger_version?: bigint) {
5
- throw Error('not implemented')
6
- }
7
- }
@@ -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
- }