@typemove/iota 2.0.0 → 2.0.1-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 (68) hide show
  1. package/dist/esm/builtin/0x1.d.ts +733 -0
  2. package/dist/esm/builtin/0x1.d.ts.map +1 -0
  3. package/dist/esm/builtin/0x1.js +4293 -0
  4. package/dist/esm/builtin/0x1.js.map +1 -0
  5. package/dist/esm/builtin/0x2.d.ts +4607 -0
  6. package/dist/esm/builtin/0x2.d.ts.map +1 -0
  7. package/dist/esm/builtin/0x2.js +19016 -0
  8. package/dist/esm/builtin/0x2.js.map +1 -0
  9. package/dist/esm/builtin/0x3.d.ts +1901 -0
  10. package/dist/esm/builtin/0x3.d.ts.map +1 -0
  11. package/dist/esm/builtin/0x3.js +6165 -0
  12. package/dist/esm/builtin/0x3.js.map +1 -0
  13. package/dist/esm/builtin/index.d.ts +4 -0
  14. package/dist/esm/builtin/index.d.ts.map +1 -0
  15. package/dist/esm/builtin/index.js +7 -0
  16. package/dist/esm/builtin/index.js.map +1 -0
  17. package/dist/esm/codegen/codegen.d.ts +20 -0
  18. package/dist/esm/codegen/codegen.d.ts.map +1 -0
  19. package/dist/esm/codegen/codegen.js +245 -0
  20. package/dist/esm/codegen/codegen.js.map +1 -0
  21. package/dist/esm/codegen/index.d.ts +2 -0
  22. package/dist/esm/codegen/index.d.ts.map +1 -0
  23. package/dist/esm/codegen/index.js +2 -0
  24. package/dist/esm/codegen/index.js.map +1 -0
  25. package/dist/esm/codegen/run.d.ts +3 -0
  26. package/dist/esm/codegen/run.d.ts.map +1 -0
  27. package/dist/esm/codegen/run.js.map +1 -0
  28. package/dist/esm/index.d.ts +4 -0
  29. package/dist/esm/index.d.ts.map +1 -0
  30. package/dist/esm/index.js +4 -0
  31. package/dist/esm/index.js.map +1 -0
  32. package/dist/esm/models.d.ts +18 -0
  33. package/dist/esm/models.d.ts.map +1 -0
  34. package/dist/esm/models.js +2 -0
  35. package/dist/esm/models.js.map +1 -0
  36. package/dist/esm/move-coder.d.ts +26 -0
  37. package/dist/esm/move-coder.d.ts.map +1 -0
  38. package/dist/esm/move-coder.js +266 -0
  39. package/dist/esm/move-coder.js.map +1 -0
  40. package/dist/esm/sui-chain-adapter.d.ts +15 -0
  41. package/dist/esm/sui-chain-adapter.d.ts.map +1 -0
  42. package/dist/esm/sui-chain-adapter.js +84 -0
  43. package/dist/esm/sui-chain-adapter.js.map +1 -0
  44. package/dist/esm/to-internal.d.ts +4 -0
  45. package/dist/esm/to-internal.d.ts.map +1 -0
  46. package/dist/esm/to-internal.js +96 -0
  47. package/dist/esm/to-internal.js.map +1 -0
  48. package/dist/esm/transaction.d.ts +15 -0
  49. package/dist/esm/transaction.d.ts.map +1 -0
  50. package/dist/esm/transaction.js +83 -0
  51. package/dist/esm/transaction.js.map +1 -0
  52. package/package.json +6 -6
  53. package/src/abis/0x1.json +4213 -0
  54. package/src/abis/0x2.json +30623 -0
  55. package/src/abis/0x3.json +10691 -0
  56. package/src/builtin/0x1.ts +6065 -0
  57. package/src/builtin/0x2.ts +28181 -0
  58. package/src/builtin/0x3.ts +9666 -0
  59. package/src/builtin/index.ts +6 -0
  60. package/src/codegen/codegen.ts +288 -0
  61. package/src/codegen/index.ts +1 -0
  62. package/src/codegen/run.ts +57 -0
  63. package/src/index.ts +4 -0
  64. package/src/models.ts +21 -0
  65. package/src/move-coder.ts +316 -0
  66. package/src/sui-chain-adapter.ts +113 -0
  67. package/src/to-internal.ts +127 -0
  68. package/src/transaction.ts +127 -0
@@ -0,0 +1,113 @@
1
+ import { toInternalModule } from './to-internal.js'
2
+ import {
3
+ InternalMoveModule,
4
+ InternalMoveStruct,
5
+ ChainAdapter,
6
+ moduleQname,
7
+ SPLITTER,
8
+ TypeDescriptor
9
+ } from '@typemove/move'
10
+
11
+ import { IotaMoveNormalizedModule, IotaEvent, IotaMoveObject, IotaClient } from '@iota/iota-sdk/client'
12
+
13
+ export class IotaChainAdapter extends ChainAdapter<
14
+ // IotaNetwork,
15
+ IotaMoveNormalizedModule,
16
+ IotaEvent | IotaMoveObject
17
+ > {
18
+ async getChainId() {
19
+ return this.client.getChainIdentifier()
20
+ }
21
+ // static INSTANCE = new IotaChainAdapter()
22
+
23
+ client: IotaClient
24
+ constructor(client: IotaClient) {
25
+ super()
26
+ this.client = client
27
+ }
28
+
29
+ async fetchModule(
30
+ account: string,
31
+ module: string
32
+ // network: IotaNetwork
33
+ ): Promise<IotaMoveNormalizedModule> {
34
+ return await this.client.getNormalizedMoveModule({ package: account, module })
35
+ }
36
+
37
+ async fetchModules(
38
+ account: string
39
+ // network: IotaNetwork
40
+ ): Promise<IotaMoveNormalizedModule[]> {
41
+ const modules = await this.client.getNormalizedMoveModulesByPackage({
42
+ package: account
43
+ })
44
+ return Object.values(modules)
45
+ }
46
+
47
+ getMeaningfulFunctionParams(params: TypeDescriptor[]): TypeDescriptor[] {
48
+ return params
49
+ // if (params.length === 0) {
50
+ // return params
51
+ // }
52
+ // return params.slice(0, params.length - 1)
53
+ }
54
+
55
+ toInternalModules(modules: IotaMoveNormalizedModule[]): InternalMoveModule[] {
56
+ return Object.values(modules).map(toInternalModule)
57
+ }
58
+
59
+ getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
60
+ const eventMap = new Map<string, InternalMoveStruct>()
61
+
62
+ for (const module of modules) {
63
+ const qname = moduleQname(module)
64
+
65
+ for (const struct of module.structs) {
66
+ const abilities = new Set(struct.abilities)
67
+ if (abilities.has('Drop') && abilities.has('Copy')) {
68
+ eventMap.set(qname + SPLITTER + struct.name, struct)
69
+ }
70
+ }
71
+ }
72
+ return eventMap
73
+ }
74
+
75
+ getType(base: IotaEvent | IotaMoveObject): string {
76
+ return base.type
77
+ }
78
+
79
+ getData(val: IotaEvent | IotaMoveObject) {
80
+ // if (val.parsedJson) {
81
+ // return val.parsedJson as any
82
+ // }
83
+ if (val === undefined) {
84
+ throw Error('val is undefined')
85
+ }
86
+ if ('parsedJson' in val) {
87
+ return val.parsedJson as any
88
+ }
89
+ // if (IotaParsedData.is(val)) {
90
+ // return val.fields as any
91
+ // }
92
+ if (val.dataType === 'moveObject') {
93
+ return val.fields as any
94
+ }
95
+ // if (IotaMoveObject.is(val)) {
96
+ // return val.fields as any
97
+ // }
98
+ // This may not be perfect, just think everything has
99
+ if ('fields' in val) {
100
+ if ('type' in val && Object.keys(val).length === 2) {
101
+ return val.fields as any
102
+ }
103
+ }
104
+ return val as any
105
+ }
106
+ // validateAndNormalizeAddress(address: string) {
107
+ // return validateAndNormalizeAddress(address)
108
+ // }
109
+ }
110
+
111
+ function getRpcClient(endpoint: string): IotaClient {
112
+ return new IotaClient({ url: endpoint })
113
+ }
@@ -0,0 +1,127 @@
1
+ import type {
2
+ IotaMoveNormalizedEnum,
3
+ IotaMoveNormalizedField,
4
+ IotaMoveNormalizedFunction,
5
+ IotaMoveNormalizedModule,
6
+ IotaMoveNormalizedStruct,
7
+ IotaMoveNormalizedType
8
+ } from '@iota/iota-sdk/client'
9
+ import {
10
+ InternalMoveEnum,
11
+ InternalMoveFunction,
12
+ InternalMoveFunctionVisibility,
13
+ InternalMoveModule,
14
+ InternalMoveStruct,
15
+ InternalMoveStructField,
16
+ SPLITTER,
17
+ TypeDescriptor
18
+ } from '@typemove/move'
19
+
20
+ export function toInternalModule(module: IotaMoveNormalizedModule): InternalMoveModule {
21
+ return {
22
+ address: module.address,
23
+ exposedFunctions: Object.entries(module.exposedFunctions).map(([n, f]) => toInternalFunction(n, f)),
24
+ name: module.name,
25
+ structs: Object.entries(module.structs).map(([n, s]) => toInternalStruct(n, s)),
26
+ enums: Object.entries(module.enums || {}).map(([n, e]) => toInternalEnum(n, e))
27
+ }
28
+ }
29
+
30
+ function toInternalFunction(name: string, func: IotaMoveNormalizedFunction): InternalMoveFunction {
31
+ let visibility
32
+ switch (func.visibility) {
33
+ case 'Private':
34
+ visibility = InternalMoveFunctionVisibility.PRIVATE
35
+ break
36
+ case 'Public':
37
+ visibility = InternalMoveFunctionVisibility.PUBLIC
38
+ break
39
+ case 'Friend':
40
+ visibility = InternalMoveFunctionVisibility.FRIEND
41
+ break
42
+ default:
43
+ throw Error('No visibility for function' + name)
44
+ }
45
+ return {
46
+ typeParams: func.typeParameters.map((p: any) => {
47
+ return { constraints: p.abilities }
48
+ }),
49
+ isEntry: func.isEntry,
50
+ name: name,
51
+ params: func.parameters.map(toTypeDescriptor),
52
+ return: func.return.map(toTypeDescriptor),
53
+ visibility: visibility
54
+ }
55
+ }
56
+
57
+ function toInternalStruct(name: string, struct: IotaMoveNormalizedStruct): InternalMoveStruct {
58
+ return {
59
+ abilities: struct.abilities.abilities,
60
+ fields: struct.fields.map(toInternalField),
61
+ typeParams: struct.typeParameters.map((p: any) => {
62
+ return { constraints: p.constraints.abilities }
63
+ }),
64
+ isNative: false,
65
+ isEvent: false,
66
+ name: name
67
+ }
68
+ }
69
+
70
+ function toInternalEnum(name: string, enumType: IotaMoveNormalizedEnum): InternalMoveEnum {
71
+ return {
72
+ name: name,
73
+ abilities: enumType.abilities.abilities,
74
+ typeParams: enumType.typeParameters.map((p: any) => {
75
+ return { constraints: p.constraints.abilities }
76
+ }),
77
+ variants: Object.entries(enumType.variants).reduce((acc: { [key: string]: InternalMoveStructField[] }, [k, v]) => {
78
+ acc[k] = v.map(toInternalField)
79
+ return acc
80
+ }, {})
81
+ }
82
+ }
83
+
84
+ function toInternalField(module: IotaMoveNormalizedField): InternalMoveStructField {
85
+ return {
86
+ name: module.name,
87
+ type: toTypeDescriptor(module.type)
88
+ }
89
+ }
90
+
91
+ function toTypeDescriptor(normalizedType: IotaMoveNormalizedType): TypeDescriptor {
92
+ if (typeof normalizedType === 'string') {
93
+ return new TypeDescriptor(normalizedType)
94
+ }
95
+
96
+ if ('Struct' in normalizedType) {
97
+ const qname = [normalizedType.Struct.address, normalizedType.Struct.module, normalizedType.Struct.name].join(
98
+ SPLITTER
99
+ )
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', [toTypeDescriptor(normalizedType.Vector)])
108
+ }
109
+ if ('TypeParameter' in normalizedType) {
110
+ return new TypeDescriptor('T' + normalizedType.TypeParameter)
111
+ }
112
+
113
+ if ('Reference' in normalizedType) {
114
+ const res = toTypeDescriptor(normalizedType.Reference)
115
+ res.reference = true
116
+ return res
117
+ }
118
+
119
+ if ('MutableReference' in normalizedType) {
120
+ const res = toTypeDescriptor(normalizedType.MutableReference)
121
+ res.reference = true
122
+ res.mutable = true
123
+ return res
124
+ }
125
+
126
+ throw new Error('Unexpected sui type')
127
+ }
@@ -0,0 +1,127 @@
1
+ import { Transaction, TransactionArgument, TransactionObjectInput } from '@iota/iota-sdk/transactions'
2
+
3
+ export function isTransactionArgument(value: any): boolean {
4
+ if (typeof value !== 'object') return false
5
+ if (value === null || value === undefined) return false
6
+
7
+ return (
8
+ value.$kind === 'GasCoin' || value.$kind === 'Result' || value.$kind === 'NestedResult' || value.$kind === 'Input'
9
+ )
10
+ }
11
+
12
+ export function transactionArgumentOrObject(
13
+ value: TransactionObjectInput,
14
+ transactionBlock: Transaction
15
+ ): TransactionArgument {
16
+ // if (isTransactionArgument(value)) {
17
+ // return value as TransactionArgument
18
+ // }
19
+ return transactionBlock.object(value)
20
+ }
21
+
22
+ export function transactionArgumentOrPure(value: any, transactionBlock: Transaction): any {
23
+ if (isTransactionArgument(value)) {
24
+ return value
25
+ }
26
+ return typeof value == 'string' ? transactionBlock.pure.string(value) : transactionBlock.pure.u64(value)
27
+ }
28
+
29
+ export function transactionArgumentOrPureString(
30
+ value: TransactionArgument | string,
31
+ transactionBlock: Transaction
32
+ ): TransactionArgument {
33
+ if (isTransactionArgument(value)) {
34
+ return value as TransactionArgument
35
+ }
36
+ return transactionBlock.pure.string(value as string)
37
+ }
38
+
39
+ export function transactionArgumentOrPureAddress(
40
+ value: TransactionArgument | string,
41
+ transactionBlock: Transaction
42
+ ): TransactionArgument {
43
+ if (isTransactionArgument(value)) {
44
+ return value as TransactionArgument
45
+ }
46
+ return transactionBlock.pure.address(value as string)
47
+ }
48
+
49
+ export function transactionArgumentOrPureU8(
50
+ value: TransactionArgument | number,
51
+ transactionBlock: Transaction
52
+ ): TransactionArgument {
53
+ if (isTransactionArgument(value)) {
54
+ return value as TransactionArgument
55
+ }
56
+ return transactionBlock.pure.u8(value as number)
57
+ }
58
+
59
+ export function transactionArgumentOrPureU16(
60
+ value: TransactionArgument | number,
61
+ transactionBlock: Transaction
62
+ ): TransactionArgument {
63
+ if (isTransactionArgument(value)) {
64
+ return value as TransactionArgument
65
+ }
66
+ return transactionBlock.pure.u16(value as number)
67
+ }
68
+
69
+ export function transactionArgumentOrPureU32(
70
+ value: TransactionArgument | number,
71
+ transactionBlock: Transaction
72
+ ): TransactionArgument {
73
+ if (isTransactionArgument(value)) {
74
+ return value as TransactionArgument
75
+ }
76
+ return transactionBlock.pure.u32(value as number)
77
+ }
78
+
79
+ export function transactionArgumentOrPureU64(
80
+ value: TransactionArgument | bigint | number | string,
81
+ transactionBlock: Transaction
82
+ ): TransactionArgument {
83
+ if (isTransactionArgument(value)) {
84
+ return value as TransactionArgument
85
+ }
86
+ return transactionBlock.pure.u64(value as number)
87
+ }
88
+
89
+ export function transactionArgumentOrPureU128(
90
+ value: TransactionArgument | bigint | number | string,
91
+ transactionBlock: Transaction
92
+ ): TransactionArgument {
93
+ if (isTransactionArgument(value)) {
94
+ return value as TransactionArgument
95
+ }
96
+ return transactionBlock.pure.u128(value as number)
97
+ }
98
+
99
+ export function transactionArgumentOrPureU256(
100
+ value: TransactionArgument | bigint | number | string,
101
+ transactionBlock: Transaction
102
+ ): TransactionArgument {
103
+ if (isTransactionArgument(value)) {
104
+ return value as TransactionArgument
105
+ }
106
+ return transactionBlock.pure.u256(value as number)
107
+ }
108
+
109
+ export function transactionArgumentOrPureBool(
110
+ value: TransactionArgument | boolean,
111
+ transactionBlock: Transaction
112
+ ): TransactionArgument {
113
+ if (isTransactionArgument(value)) {
114
+ return value as TransactionArgument
115
+ }
116
+ return transactionBlock.pure.bool(value as boolean)
117
+ }
118
+
119
+ // TODO vector might be nested
120
+ export function transactionArgumentOrVec(value: any, transactionBlock: Transaction): any {
121
+ if (isTransactionArgument(value)) {
122
+ return value
123
+ }
124
+ return transactionBlock.makeMoveVec({
125
+ elements: value.map((a: any) => transactionBlock.object(a))
126
+ })
127
+ }