@typemove/iota 2.0.0 → 2.0.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,245 @@
1
+ import { IotaClient } from '@iota/iota-sdk/client';
2
+ import * as fs from 'fs';
3
+ import chalk from 'chalk';
4
+ import { structQname, InternalMoveFunctionVisibility, normalizeToJSName, camel } from '@typemove/move';
5
+ import { AbstractCodegen } from '@typemove/move/codegen';
6
+ import { join } from 'path';
7
+ import { IotaChainAdapter } from '../sui-chain-adapter.js';
8
+ export async function codegen(abisDir, outDir = join('src', 'types', 'sui'), endpoint, genExample = false, builtin = false) {
9
+ if (!fs.existsSync(abisDir)) {
10
+ console.error(chalk.red(`ABIs directory ${abisDir} does not exist`));
11
+ return 0;
12
+ }
13
+ try {
14
+ const gen = new IotaCodegen(endpoint);
15
+ const numFiles = await gen.generate(abisDir, outDir, builtin);
16
+ if (numFiles > 0) {
17
+ console.log(chalk.green(`Generated for ${numFiles} accounts for Iota to ${outDir}`));
18
+ }
19
+ else {
20
+ console.error(chalk.red(`No account found`));
21
+ }
22
+ return numFiles;
23
+ }
24
+ catch (e) {
25
+ console.error(chalk.red(`Failed to generate for ${abisDir}, please check if ABI json files are valid`));
26
+ console.log(e);
27
+ return 0;
28
+ }
29
+ }
30
+ export class IotaCodegen extends AbstractCodegen {
31
+ ADDRESS_TYPE = 'string';
32
+ SYSTEM_PACKAGE = '@typemove/iota';
33
+ // ADDRESS_TYPE = 'string'
34
+ // MAIN_NET = IotaNetwork.MAIN_NET
35
+ // TEST_NET = IotaNetwork.TEST_NET
36
+ PREFIX = 'Iota';
37
+ // STRUCT_FIELD_NAME = 'fields'
38
+ // GENERATE_ON_ENTRY = true
39
+ PAYLOAD_OPTIONAL = true;
40
+ constructor(endpoint) {
41
+ super(new IotaChainAdapter(new IotaClient({ url: endpoint })));
42
+ }
43
+ readModulesFile(fullPath) {
44
+ const res = super.readModulesFile(fullPath);
45
+ if (res.result) {
46
+ return res.result;
47
+ }
48
+ return res;
49
+ }
50
+ generateStructs(module, struct, events) {
51
+ let content = '';
52
+ switch (structQname(module, struct)) {
53
+ // TODO they should still have module code generated
54
+ case '0x1::ascii::Char':
55
+ case '0x1::ascii::String':
56
+ case '0x2::object::ID':
57
+ content += `export type ${struct.name} = string`;
58
+ break;
59
+ case '0x2::coin::Coin':
60
+ content += `export type ${struct.name}<T> = string`;
61
+ break;
62
+ case '0x2::balance::Balance':
63
+ content += `export type ${struct.name}<T> = bigint`;
64
+ break;
65
+ case '0x1::option::Option':
66
+ content += `export type Option<T> = T | undefined`;
67
+ break;
68
+ }
69
+ return content + super.generateStructs(module, struct, events, content !== '');
70
+ }
71
+ generateForEvents(module, struct) {
72
+ switch (structQname(module, struct)) {
73
+ case '0x1::ascii::Char':
74
+ case '0x1::ascii::String':
75
+ case '0x2::object::ID':
76
+ case '0x2::coin::Coin':
77
+ case '0x1::option::Option':
78
+ case '0x2::balance::Balance':
79
+ return '';
80
+ }
81
+ return super.generateForEvents(module, struct);
82
+ }
83
+ generateExtra(address, module) {
84
+ const funcs = module.exposedFunctions.map((f) => this.generateBuilderForFunction(address || module.address, module, f));
85
+ const viewFuncs = module.exposedFunctions.map((f) => this.generateViewFunction(module, f));
86
+ return `
87
+ export namespace builder {
88
+ ${funcs.join('\n')}
89
+ }
90
+ export namespace view {
91
+ ${viewFuncs.join('\n')}
92
+ }
93
+ `;
94
+ }
95
+ generateArgs(module, func, isView) {
96
+ const args = [];
97
+ const argsLen = func.params.length;
98
+ for (const [idx, arg] of func.params.entries()) {
99
+ if (idx === argsLen - 1 && arg.qname === '0x2::tx_context::TxContext') {
100
+ // no op
101
+ }
102
+ else if (arg.reference) {
103
+ args.push({
104
+ paramType: isView ? this.ADDRESS_TYPE : `${this.ADDRESS_TYPE} | TransactionObjectArgument`,
105
+ callValue: `_args.push(transactionArgumentOrObject(args[${idx}], tx))`
106
+ });
107
+ }
108
+ else if (arg.isVector()) {
109
+ // TODO fix pure vector
110
+ args.push({
111
+ paramType: isView
112
+ ? `${this.ADDRESS_TYPE}[]`
113
+ : `(${this.ADDRESS_TYPE} | TransactionObjectArgument)[] | TransactionArgument`,
114
+ callValue: `_args.push(transactionArgumentOrVec(args[${idx}], tx))`
115
+ });
116
+ }
117
+ else {
118
+ // Handle pure type
119
+ let pureFunction = '';
120
+ const paramType = isView
121
+ ? this.generateTypeForDescriptor(arg, module.address)
122
+ : `${this.generateTypeForDescriptor(arg, module.address)} | TransactionArgument`;
123
+ switch (arg.qname.toLowerCase()) {
124
+ case 'u8':
125
+ pureFunction = `transactionArgumentOrPureU8`;
126
+ break;
127
+ case 'u16':
128
+ pureFunction = `transactionArgumentOrPureU16`;
129
+ break;
130
+ case 'u32':
131
+ pureFunction = `transactionArgumentOrPureU32`;
132
+ break;
133
+ case 'u64':
134
+ pureFunction = `transactionArgumentOrPureU64`;
135
+ break;
136
+ case 'u128':
137
+ pureFunction = `transactionArgumentOrPureU128`;
138
+ break;
139
+ case 'u256':
140
+ pureFunction = `transactionArgumentOrPureU256`;
141
+ break;
142
+ case 'bool':
143
+ pureFunction = `transactionArgumentOrPureBool`;
144
+ break;
145
+ case 'string':
146
+ pureFunction = `transactionArgumentOrPureString`;
147
+ break;
148
+ case 'address':
149
+ pureFunction = `transactionArgumentOrPureAddress`;
150
+ break;
151
+ // case 'vector':
152
+ // case 'option':
153
+ default:
154
+ pureFunction = `transactionArgumentOrPure`;
155
+ // paramType = 'TransactionArgument'
156
+ }
157
+ const callValue = pureFunction ? `_args.push(${pureFunction}(args[${idx}], tx))` : `_args.push(args[${idx}])`;
158
+ args.push({
159
+ paramType,
160
+ callValue
161
+ });
162
+ }
163
+ }
164
+ return args;
165
+ }
166
+ generateViewFunction(module, func) {
167
+ if (func.visibility === InternalMoveFunctionVisibility.PRIVATE) {
168
+ return '';
169
+ }
170
+ const genericString = this.generateFunctionTypeParameters(func);
171
+ const typeParamArg = func.typeParams
172
+ .map((v, idx) => {
173
+ return `TypeDescriptor<T${idx}> | string`;
174
+ })
175
+ .join(',');
176
+ const args = this.generateArgs(module, func, true);
177
+ const returnType = `${this.generateFunctionReturnTypeParameters(func, module.address)}`;
178
+ return `export async function ${camel(normalizeToJSName(func.name))}${genericString}(
179
+ client: IotaClient,
180
+ args: [${args.map((a) => a.paramType).join(',')}],
181
+ ${typeParamArg.length > 0 ? `typeArguments: [${typeParamArg}]` : ``} ): Promise<TypedDevInspectResults<${returnType}>> {
182
+ const tx = new Transaction()
183
+ builder.${camel(normalizeToJSName(func.name))}(tx, args ${typeParamArg.length > 0 ? `, typeArguments` : ''})
184
+ const inspectRes = await client.devInspectTransactionBlock({
185
+ transactionBlock: tx,
186
+ sender: ZERO_ADDRESS
187
+ })
188
+
189
+ return (await getMoveCoder(client)).decodeDevInspectResult<${returnType}>(inspectRes)
190
+ }`;
191
+ }
192
+ generateBuilderForFunction(address, module, func) {
193
+ if (func.visibility === InternalMoveFunctionVisibility.PRIVATE && func.isEntry !== true) {
194
+ return '';
195
+ }
196
+ const args = this.generateArgs(module, func, false);
197
+ const genericString = this.generateFunctionTypeParameters(func);
198
+ const typeParamArg = func.typeParams
199
+ .map((v, idx) => {
200
+ return `TypeDescriptor<T${idx}> | string`;
201
+ })
202
+ .join(',');
203
+ const typeParamToString = func.typeParams
204
+ .map((v, idx) => {
205
+ return `typeof typeArguments[${idx}] === 'string' ? typeArguments[${idx}] : typeArguments[${idx}].getSignature()`;
206
+ })
207
+ .join(',');
208
+ return `export function ${camel(normalizeToJSName(func.name))}${genericString}(tx: Transaction,
209
+ args: [${args.map((a) => a.paramType).join(',')}],
210
+ ${typeParamArg.length > 0 ? `typeArguments: [${typeParamArg}]` : ``} ):
211
+ TransactionArgument & [ ${'TransactionArgument,'.repeat(args.length)} ] {
212
+ const _args: any[] = []
213
+ ${args.map((a) => a.callValue).join('\n')}
214
+
215
+ // @ts-ignore
216
+ return tx.moveCall({
217
+ target: "${address}::${module.name}::${func.name}",
218
+ arguments: _args,
219
+ ${typeParamArg.length > 0 ? `typeArguments: [${typeParamToString}]` : ``}
220
+ })
221
+ }`;
222
+ }
223
+ generateImports() {
224
+ return `
225
+ ${super.generateImports()}
226
+ import { ZERO_ADDRESS, TypedDevInspectResults, getMoveCoder } from '@typemove/iota'
227
+ import { Transaction, TransactionArgument, TransactionObjectArgument } from '@iota/iota-sdk/transactions'
228
+ import { IotaClient } from '@iota/iota-sdk/client'
229
+ import { transactionArgumentOrObject,
230
+ transactionArgumentOrVec,
231
+ transactionArgumentOrPure,
232
+ transactionArgumentOrPureU8,
233
+ transactionArgumentOrPureU16,
234
+ transactionArgumentOrPureU32,
235
+ transactionArgumentOrPureU64,
236
+ transactionArgumentOrPureU128,
237
+ transactionArgumentOrPureU256,
238
+ transactionArgumentOrPureBool,
239
+ transactionArgumentOrPureString,
240
+ transactionArgumentOrPureAddress,
241
+ } from '@typemove/iota'
242
+ `;
243
+ }
244
+ }
245
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuD,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvG,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAGL,WAAW,EAEX,8BAA8B,EAC9B,iBAAiB,EACjB,KAAK,EACN,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE1D,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,OAAe,EACf,MAAM,GAAG,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EACpC,QAAgB,EAChB,UAAU,GAAG,KAAK,EAClB,OAAO,GAAG,KAAK;IAEf,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,OAAO,iBAAiB,CAAC,CAAC,CAAA;QACpE,OAAO,CAAC,CAAA;IACV,CAAC;IACD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7D,IAA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AC,CAAC,EAAE;;MAE1E,CAAA;IACJ,CAAC;IAED,eAAe;QACb,OAAO;QACH,KAAK,CAAC,eAAe,EAAE;;;;;;;;;;;;;;;;;KAiB1B,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from './codegen.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './codegen.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/codegen/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/codegen/run.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/codegen/run.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC9C,IAAI,GAAG,GAAG,SAAS,CAAA;AACnB,IAAI,CAAC;IACH,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAA;AACrC,CAAC;AAAC,OAAO,CA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CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QAC5C,CAAC;QACD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IAC1F,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;IACrE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAChC,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './models.js';
2
+ export * from './transaction.js';
3
+ export { MoveCoder, defaultMoveCoder, getMoveCoder } from './move-coder.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,4 @@
1
+ export * from './models.js';
2
+ export * from './transaction.js';
3
+ export { MoveCoder, defaultMoveCoder, getMoveCoder } from './move-coder.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAEhC,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,18 @@
1
+ import type { IotaEvent, MoveCallIotaTransaction, IotaMoveObject, DevInspectResults } from '@iota/iota-sdk/client';
2
+ import { DecodedStruct } from '@typemove/move';
3
+ export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000000";
4
+ export type TypedEventInstance<T> = DecodedStruct<IotaEvent, T>;
5
+ export type TypedIotaMoveObject<T> = DecodedStruct<IotaMoveObject, T>;
6
+ export type TypedFunctionPayload<T extends Array<any>> = MoveCallIotaTransaction & {
7
+ /**
8
+ * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
9
+ */
10
+ arguments_decoded: T;
11
+ };
12
+ export type TypedDevInspectResults<T extends Array<any>> = DevInspectResults & {
13
+ /**
14
+ * Decoded return values using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
15
+ */
16
+ results_decoded?: T;
17
+ };
18
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAClH,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAE9C,eAAO,MAAM,YAAY,uEAAuE,CAAA;AAEhG,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;AAC/D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,aAAa,CAAC,cAAc,EAAE,CAAC,CAAC,CAAA;AAErE,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAAI,uBAAuB,GAAG;IACjF;;OAEG;IACH,iBAAiB,EAAE,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,sBAAsB,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,IAAI,iBAAiB,GAAG;IAC7E;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,CAAA;CACpB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000000000000000000000000000';
2
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,YAAY,GAAG,oEAAoE,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { TypedDevInspectResults, TypedEventInstance } from './models.js';
2
+ import { AbstractMoveCoder, DecodedStruct, TypeDescriptor, InternalMoveModule } from '@typemove/move';
3
+ import { MoveCallIotaTransaction, IotaCallArg, IotaEvent, IotaMoveNormalizedModule, IotaMoveObject, DevInspectResults, IotaClient } from '@iota/iota-sdk/client';
4
+ import { dynamic_field } from './builtin/0x2.js';
5
+ import { BcsType } from '@iota/iota-sdk/bcs';
6
+ export type Encoding = 'base58' | 'base64' | 'hex';
7
+ export declare class MoveCoder extends AbstractMoveCoder<IotaMoveNormalizedModule, IotaEvent | IotaMoveObject> {
8
+ constructor(client: IotaClient);
9
+ load(module: IotaMoveNormalizedModule, address: string): InternalMoveModule;
10
+ protected decode(data: any, type: TypeDescriptor): Promise<any>;
11
+ decodeEvent<T>(event: IotaEvent): Promise<TypedEventInstance<T> | undefined>;
12
+ filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: IotaEvent[]): Promise<TypedEventInstance<T>[]>;
13
+ getDynamicFields<T1, T2>(objects: IotaMoveObject[], keyType?: TypeDescriptor<T1>, valueType?: TypeDescriptor<T2>): Promise<dynamic_field.Field<T1, T2>[]>;
14
+ filterAndDecodeObjects<T>(type: TypeDescriptor<T>, objects: IotaMoveObject[]): Promise<DecodedStruct<IotaMoveObject, T>[]>;
15
+ decodeFunctionPayload(payload: MoveCallIotaTransaction, inputs: IotaCallArg[]): Promise<MoveCallIotaTransaction>;
16
+ private bcsRegistered;
17
+ private bcsRegistry;
18
+ private getBCSTypeWithArgs;
19
+ getBCSType(type: TypeDescriptor): Promise<BcsType<any>>;
20
+ registerBCSTypes(type: TypeDescriptor): Promise<void>;
21
+ decodeBCS(type: TypeDescriptor, data: Uint8Array | string, encoding?: Encoding): Promise<any>;
22
+ decodeDevInspectResult<T extends any[]>(inspectRes: DevInspectResults): Promise<TypedDevInspectResults<T>>;
23
+ }
24
+ export declare function defaultMoveCoder(endpoint?: string): MoveCoder;
25
+ export declare function getMoveCoder(client: IotaClient): Promise<MoveCoder>;
26
+ //# sourceMappingURL=move-coder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"move-coder.d.ts","sourceRoot":"","sources":["../../src/move-coder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAwB,MAAM,aAAa,CAAA;AAC9F,OAAO,EACL,iBAAiB,EAEjB,aAAa,EAIb,cAAc,EACd,kBAAkB,EACnB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,uBAAuB,EACvB,WAAW,EACX,SAAS,EACT,wBAAwB,EACxB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAO,MAAM,oBAAoB,CAAA;AAGjD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,KAAK,CAAA;AAIlD,qBAAa,SAAU,SAAQ,iBAAiB,CAE9C,wBAAwB,EACxB,SAAS,GAAG,cAAc,CAC3B;gBACa,MAAM,EAAE,UAAU;IAI9B,IAAI,CAAC,MAAM,EAAE,wBAAwB,EAAE,OAAO,EAAE,MAAM,GAAG,kBAAkB;cAa3D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC;IAkErE,WAAW,CAAC,CAAC,EAA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CAAC,CAAC,CAAC;CAkBjH;AAMD,wBAAgB,gBAAgB,CAAC,QAAQ,GAAE,MAAyB,GAAG,SAAS,CAO/E;AAMD,wBAAsB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAiBzE"}
@@ -0,0 +1,266 @@
1
+ import { AbstractMoveCoder, ANY_TYPE, accountTypeString, parseMoveType, SPLITTER, TypeDescriptor } from '@typemove/move';
2
+ import { IotaClient } from '@iota/iota-sdk/client';
3
+ import { toInternalModule } from './to-internal.js';
4
+ import { IotaChainAdapter } from './sui-chain-adapter.js';
5
+ import { bcs } from '@iota/iota-sdk/bcs';
6
+ import { normalizeIotaObjectId, normalizeIotaAddress } from '@iota/iota-sdk/utils';
7
+ export class MoveCoder extends AbstractMoveCoder {
8
+ constructor(client) {
9
+ super(new IotaChainAdapter(client));
10
+ }
11
+ load(module, address) {
12
+ address = accountTypeString(address);
13
+ let m = this.moduleMapping.get(module.address + '::' + module.name);
14
+ const mDeclared = this.moduleMapping.get(address + '::' + module.name);
15
+ if (m && mDeclared) {
16
+ return m;
17
+ }
18
+ this.accounts.add(module.address);
19
+ m = toInternalModule(module);
20
+ this.loadInternal(m, address);
21
+ return m;
22
+ }
23
+ async decode(data, type) {
24
+ switch (type.qname) {
25
+ case '0x1::ascii::Char':
26
+ if (data !== undefined && typeof data !== 'string') {
27
+ // bcs
28
+ const byte = (await super.decode(data, type)).byte;
29
+ return String.fromCharCode(byte);
30
+ }
31
+ case '0x1::ascii::String':
32
+ if (data !== undefined && typeof data !== 'string') {
33
+ // bcs verified
34
+ const bytes = (await super.decode(data, type)).bytes;
35
+ return new TextDecoder().decode(new Uint8Array(bytes));
36
+ }
37
+ case '0x2::object::ID':
38
+ if (data !== undefined && typeof data !== 'string') {
39
+ // bcs verified
40
+ const bytes = (await super.decode(data, type)).bytes;
41
+ return normalizeIotaObjectId(bytes);
42
+ }
43
+ case '0x2::url::Url':
44
+ if (data !== undefined && typeof data !== 'string') {
45
+ // bcs
46
+ return (await super.decode(data, type)).url;
47
+ }
48
+ case '0x2::coin::Coin':
49
+ if (data !== undefined && typeof data !== 'string') {
50
+ // bcs
51
+ const bytes = (await super.decode(data, type)).id.id.bytes;
52
+ return new TextDecoder().decode(new Uint8Array(bytes));
53
+ }
54
+ return data;
55
+ case '0x2::balance::Balance':
56
+ if (data.value) {
57
+ // bcs verfied
58
+ const balance = await super.decode(data, type);
59
+ return balance.value;
60
+ }
61
+ return BigInt(data);
62
+ case '0x1::option::Option':
63
+ if (data === null) {
64
+ return data;
65
+ }
66
+ if (data.vec) {
67
+ // bcs verifed
68
+ let vec = await super.decode(data, type);
69
+ vec = vec.vec;
70
+ if (vec.length === 0) {
71
+ return null;
72
+ }
73
+ return vec[0];
74
+ }
75
+ return this.decode(data, type.typeArgs[0]);
76
+ case 'Address':
77
+ const str = data;
78
+ return normalizeIotaAddress(str);
79
+ case '0x1::string::String':
80
+ if (typeof data !== 'string') {
81
+ // bcs
82
+ return new TextDecoder().decode(new Uint8Array(data.bytes));
83
+ }
84
+ default:
85
+ return super.decode(data, type);
86
+ }
87
+ }
88
+ decodeEvent(event) {
89
+ return this.decodedStruct(event);
90
+ }
91
+ filterAndDecodeEvents(type, resources) {
92
+ if (typeof type === 'string') {
93
+ type = parseMoveType(type);
94
+ }
95
+ return this.filterAndDecodeStruct(type, resources);
96
+ }
97
+ async getDynamicFields(objects, keyType = ANY_TYPE, valueType = ANY_TYPE) {
98
+ // const type = dynamic_field.Field.TYPE
99
+ // Not using the code above to avoid cycle initialize failed
100
+ const type = new TypeDescriptor('0x2::dynamic_field::Field');
101
+ type.typeArgs = [keyType, valueType];
102
+ const res = await this.filterAndDecodeObjects(type, objects);
103
+ return res.map((o) => o.data_decoded);
104
+ }
105
+ filterAndDecodeObjects(type, objects) {
106
+ return this.filterAndDecodeStruct(type, objects);
107
+ }
108
+ async decodeFunctionPayload(payload, inputs) {
109
+ const functionType = [payload.package, payload.module, payload.function].join(SPLITTER);
110
+ const func = await this.getMoveFunction(functionType);
111
+ const params = this.adapter.getMeaningfulFunctionParams(func.params);
112
+ const args = [];
113
+ for (const value of payload.arguments || []) {
114
+ const argValue = value;
115
+ if ('Input' in argValue) {
116
+ const idx = argValue.Input;
117
+ const arg = inputs[idx];
118
+ if (arg.type === 'pure') {
119
+ args.push(arg.value);
120
+ }
121
+ else if (arg.type === 'object') {
122
+ // object is not there
123
+ args.push(undefined);
124
+ }
125
+ else {
126
+ console.error('unexpected function arg value');
127
+ args.push(undefined);
128
+ }
129
+ // args.push(arg) // TODO check why ts not work using arg.push(arg)
130
+ }
131
+ else {
132
+ args.push(undefined);
133
+ }
134
+ }
135
+ const argumentsTyped = await this.decodeArray(args, params, false);
136
+ return {
137
+ ...payload,
138
+ arguments_decoded: argumentsTyped
139
+ };
140
+ }
141
+ bcsRegistered = new Set();
142
+ bcsRegistry = new Map();
143
+ async getBCSTypeWithArgs(type, args = []) {
144
+ const qname = type.qname;
145
+ const sig = type.getNormalizedSignature();
146
+ const cached = this.bcsRegistry.get(sig);
147
+ if (cached) {
148
+ return cached;
149
+ }
150
+ const lowerQname = qname.toLowerCase();
151
+ switch (lowerQname) {
152
+ case 'u8':
153
+ case 'u16':
154
+ case 'u32':
155
+ case 'u64':
156
+ case 'u128':
157
+ case 'u256':
158
+ case 'bool':
159
+ return bcs[lowerQname]();
160
+ case 'address':
161
+ return bcs.Address;
162
+ case 'vector':
163
+ return bcs.vector(args[0]);
164
+ default:
165
+ if (!qname.includes('::')) {
166
+ throw `Unimplemented builtin type ${qname}`;
167
+ }
168
+ }
169
+ let moveStruct;
170
+ try {
171
+ moveStruct = await this.getMoveStruct(qname);
172
+ }
173
+ catch (e) {
174
+ console.error('Invalid move address', qname);
175
+ throw e;
176
+ }
177
+ const structDef = {};
178
+ for (const field of moveStruct.fields) {
179
+ if (field.type.qname.startsWith('T') && args.length) {
180
+ const index = +field.type.qname.slice(1);
181
+ structDef[field.name] = args[index];
182
+ }
183
+ else if (field.type.typeArgs.length && args.length) {
184
+ structDef[field.name] = await this.getBCSTypeWithArgs(field.type, args);
185
+ }
186
+ else {
187
+ structDef[field.name] = await this.getBCSType(field.type);
188
+ }
189
+ }
190
+ return bcs.struct(qname, structDef);
191
+ }
192
+ async getBCSType(type) {
193
+ const args = await Promise.all(type.typeArgs.map((x) => this.getBCSType(x)));
194
+ const bcsType = await this.getBCSTypeWithArgs(type, args);
195
+ this.bcsRegistry.set(type.getNormalizedSignature(), bcsType);
196
+ return bcsType;
197
+ }
198
+ async registerBCSTypes(type) {
199
+ const sig = type.getNormalizedSignature();
200
+ if (this.bcsRegistered.has(sig)) {
201
+ return;
202
+ }
203
+ this.bcsRegistered.add(sig);
204
+ const bcsType = await this.getBCSType(type);
205
+ this.bcsRegistry.set(type.getNormalizedSignature(), bcsType);
206
+ }
207
+ async decodeBCS(type, data, encoding) {
208
+ await this.registerBCSTypes(type);
209
+ if (typeof data == 'string') {
210
+ const buf = Buffer.from(data, encoding);
211
+ data = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
212
+ }
213
+ const bcsType = this.bcsRegistry.get(type.getNormalizedSignature());
214
+ return bcsType?.parse(data);
215
+ }
216
+ async decodeDevInspectResult(inspectRes) {
217
+ const returnValues = [];
218
+ if (inspectRes.results != null) {
219
+ for (const r of inspectRes.results) {
220
+ if (r.returnValues) {
221
+ for (const returnValue of r.returnValues) {
222
+ const type = parseMoveType(returnValue[1]);
223
+ const bcsDecoded = await this.decodeBCS(type, new Uint8Array(returnValue[0]));
224
+ const decoded = await this.decodeType(bcsDecoded, type);
225
+ returnValues.push(decoded);
226
+ }
227
+ }
228
+ else {
229
+ returnValues.push(null);
230
+ }
231
+ }
232
+ }
233
+ return { ...inspectRes, results_decoded: returnValues };
234
+ }
235
+ }
236
+ const DEFAULT_ENDPOINT = 'https://api.mainnet.iota.cafe/';
237
+ const CODER_MAP = new Map();
238
+ const CHAIN_ID_CODER_MAP = new Map();
239
+ export function defaultMoveCoder(endpoint = DEFAULT_ENDPOINT) {
240
+ let coder = CODER_MAP.get(endpoint);
241
+ if (!coder) {
242
+ coder = new MoveCoder(new IotaClient({ url: endpoint }));
243
+ CODER_MAP.set(endpoint, coder);
244
+ }
245
+ return coder;
246
+ }
247
+ const PROVIDER_CODER_MAP = new Map();
248
+ let DEFAULT_CHAIN_ID;
249
+ export async function getMoveCoder(client) {
250
+ let coder = PROVIDER_CODER_MAP.get(client);
251
+ if (!coder) {
252
+ coder = new MoveCoder(client);
253
+ // TODO how to dedup
254
+ const id = await client.getChainIdentifier();
255
+ const defaultCoder = defaultMoveCoder();
256
+ if (!DEFAULT_CHAIN_ID) {
257
+ DEFAULT_CHAIN_ID = await defaultCoder.adapter.getChainId();
258
+ }
259
+ if (id === DEFAULT_CHAIN_ID) {
260
+ coder = defaultCoder;
261
+ }
262
+ PROVIDER_CODER_MAP.set(client, coder);
263
+ }
264
+ return coder;
265
+ }
266
+ //# sourceMappingURL=move-coder.js.map