@typemove/sui 1.0.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.
Files changed (30) hide show
  1. package/LICENSE +201 -0
  2. package/dist/codegen/run.js +19 -0
  3. package/dist/index.js +5 -0
  4. package/package.json +43 -0
  5. package/src/abis/0x1.json +2063 -0
  6. package/src/abis/0x2.json +13410 -0
  7. package/src/abis/0x3.json +8645 -0
  8. package/src/builtin/0x1.ts +2909 -0
  9. package/src/builtin/0x2.ts +14389 -0
  10. package/src/builtin/0x3.ts +4385 -0
  11. package/src/builtin/index.ts +6 -0
  12. package/src/codegen/codegen.ts +244 -0
  13. package/src/codegen/index.ts +1 -0
  14. package/src/codegen/run.ts +20 -0
  15. package/src/index.ts +8 -0
  16. package/src/models.ts +24 -0
  17. package/src/module-client.ts +23 -0
  18. package/src/move-coder.ts +147 -0
  19. package/src/sui-chain-adapter.ts +113 -0
  20. package/src/tests/abis/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.json +265 -0
  21. package/src/tests/abis/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.json +2429 -0
  22. package/src/tests/abis/testnet/0xdee9.json +5523 -0
  23. package/src/tests/abis/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.json +10060 -0
  24. package/src/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.ts +295 -0
  25. package/src/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.ts +2745 -0
  26. package/src/tests/types/testnet/0xdee9.ts +3148 -0
  27. package/src/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.ts +10516 -0
  28. package/src/tests/types/testnet/index.ts +7 -0
  29. package/src/to-internal.ts +129 -0
  30. package/src/utils.ts +62 -0
@@ -0,0 +1,7 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export * as _0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5 from './0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.js'
5
+ export * as _0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a from './0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.js'
6
+ export * as _0xdee9 from './0xdee9.js'
7
+ export * as _0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2 from './0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.js'
@@ -0,0 +1,129 @@
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
+ SPLITTER,
15
+ TypeDescriptor,
16
+ } from '@typemove/move'
17
+
18
+ export function toInternalModule(
19
+ module: SuiMoveNormalizedModule
20
+ ): InternalMoveModule {
21
+ return {
22
+ address: module.address,
23
+ exposedFunctions: Object.entries(module.exposedFunctions).map(([n, f]) =>
24
+ toInternalFunction(n, f)
25
+ ),
26
+ name: module.name,
27
+ structs: Object.entries(module.structs).map(([n, s]) =>
28
+ toInternalStruct(n, s)
29
+ ),
30
+ }
31
+ }
32
+
33
+ function toInternalFunction(
34
+ name: string,
35
+ func: SuiMoveNormalizedFunction
36
+ ): InternalMoveFunction {
37
+ let visibility
38
+ switch (func.visibility) {
39
+ case 'Private':
40
+ visibility = InternalMoveFunctionVisibility.PRIVATE
41
+ break
42
+ case 'Public':
43
+ visibility = InternalMoveFunctionVisibility.PUBLIC
44
+ break
45
+ case 'Friend':
46
+ visibility = InternalMoveFunctionVisibility.FRIEND
47
+ break
48
+ default:
49
+ throw Error('No visibility for function' + name)
50
+ }
51
+ return {
52
+ typeParams: func.typeParameters.map((p: any) => {
53
+ return { constraints: p.abilities }
54
+ }),
55
+ isEntry: func.isEntry,
56
+ name: name,
57
+ params: func.parameters.map(toTypeDescriptor),
58
+ return: func.return.map(toTypeDescriptor),
59
+ visibility: visibility,
60
+ }
61
+ }
62
+
63
+ function toInternalStruct(
64
+ name: string,
65
+ struct: SuiMoveNormalizedStruct
66
+ ): InternalMoveStruct {
67
+ return {
68
+ abilities: struct.abilities.abilities,
69
+ fields: struct.fields.map(toInternalField),
70
+ typeParams: struct.typeParameters.map((p: any) => {
71
+ return { constraints: p.constraints.abilities }
72
+ }),
73
+ isNative: false,
74
+ name: name,
75
+ }
76
+ }
77
+
78
+ function toInternalField(
79
+ module: SuiMoveNormalizedField
80
+ ): InternalMoveStructField {
81
+ return {
82
+ name: module.name,
83
+ type: toTypeDescriptor(module.type),
84
+ }
85
+ }
86
+
87
+ function toTypeDescriptor(
88
+ normalizedType: SuiMoveNormalizedType
89
+ ): TypeDescriptor {
90
+ if (typeof normalizedType === 'string') {
91
+ return new TypeDescriptor(normalizedType)
92
+ }
93
+
94
+ if ('Struct' in normalizedType) {
95
+ const qname = [
96
+ normalizedType.Struct.address,
97
+ normalizedType.Struct.module,
98
+ normalizedType.Struct.name,
99
+ ].join(SPLITTER)
100
+
101
+ const args = normalizedType.Struct.typeArguments.map(toTypeDescriptor)
102
+
103
+ return new TypeDescriptor(qname, args)
104
+ }
105
+
106
+ if ('Vector' in normalizedType) {
107
+ return new TypeDescriptor('Vector', [
108
+ toTypeDescriptor(normalizedType.Vector),
109
+ ])
110
+ }
111
+ if ('TypeParameter' in normalizedType) {
112
+ return new TypeDescriptor('T' + normalizedType.TypeParameter)
113
+ }
114
+
115
+ if ('Reference' in normalizedType) {
116
+ const res = toTypeDescriptor(normalizedType.Reference)
117
+ res.reference = true
118
+ return res
119
+ }
120
+
121
+ if ('MutableReference' in normalizedType) {
122
+ const res = toTypeDescriptor(normalizedType.MutableReference)
123
+ res.reference = true
124
+ res.mutable = true
125
+ return res
126
+ }
127
+
128
+ throw new Error('Unexpected sui type')
129
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,62 @@
1
+ import {
2
+ SuiTransactionBlockResponse,
3
+ MoveCallSuiTransaction,
4
+ getTransactionKind,
5
+ getProgrammableTransaction,
6
+ ProgrammableTransaction,
7
+ SuiTransaction,
8
+ } from '@mysten/sui.js'
9
+
10
+ export function getMoveCalls(txBlock: SuiTransactionBlockResponse) {
11
+ const txKind = getTransactionKind(txBlock)
12
+ if (!txKind) {
13
+ return []
14
+ }
15
+ const programmableTx: ProgrammableTransaction | undefined =
16
+ getProgrammableTransaction(txKind)
17
+ if (!programmableTx) {
18
+ return []
19
+ }
20
+
21
+ return programmableTx.transactions.flatMap((tx: SuiTransaction) => {
22
+ if ('MoveCall' in tx) {
23
+ const call = tx.MoveCall as MoveCallSuiTransaction
24
+
25
+ let pkg: string = call.package
26
+ if (
27
+ call.package.startsWith(
28
+ '0x000000000000000000000000000000000000000000000000000000000000000'
29
+ )
30
+ ) {
31
+ pkg = '0x' + pkg[pkg.length - 1]
32
+ }
33
+ call.package = pkg
34
+
35
+ return [call]
36
+ }
37
+ return []
38
+ })
39
+ }
40
+
41
+ // function isHex(value: string): boolean {
42
+ // return /^(0x|0X)?[a-fA-F0-9]+$/.test(value)
43
+ // }
44
+ //
45
+ // function getHexByteLength(value: string): number {
46
+ // return /^(0x|0X)/.test(value) ? (value.length - 2) / 2 : value.length / 2
47
+ // }
48
+ //
49
+ // export function isValidSuiAddress(value: string): value is SuiAddress {
50
+ // return isHex(value) && getHexByteLength(value) <= SUI_ADDRESS_LENGTH
51
+ // }
52
+
53
+ // export function validateAndNormalizeAddress(address: string): string {
54
+ // // if (isFrameworkAccount(address)) {
55
+ // // const n = parseInt(address, 16)
56
+ // // return `0x${n.toString(16)}`
57
+ // // }
58
+ // if (!isValidSuiAddress(address)) {
59
+ // throw Error('Not valid Address')
60
+ // }
61
+ // return normalizeSuiAddress(address)
62
+ // }