@typemove/sui 1.0.0-rc.19 → 1.0.0-rc.21

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 (61) hide show
  1. package/dist/builtin/0x1.d.ts +211 -10870
  2. package/dist/builtin/0x1.d.ts.map +1 -1
  3. package/dist/builtin/0x1.js +166 -165
  4. package/dist/builtin/0x1.js.map +1 -1
  5. package/dist/builtin/0x2.d.ts +1163 -46532
  6. package/dist/builtin/0x2.d.ts.map +1 -1
  7. package/dist/builtin/0x2.js +700 -699
  8. package/dist/builtin/0x2.js.map +1 -1
  9. package/dist/builtin/0x3.d.ts +476 -13475
  10. package/dist/builtin/0x3.d.ts.map +1 -1
  11. package/dist/builtin/0x3.js +202 -201
  12. package/dist/builtin/0x3.js.map +1 -1
  13. package/dist/codegen/codegen.js +9 -8
  14. package/dist/codegen/codegen.js.map +1 -1
  15. package/dist/models.d.ts +1 -1
  16. package/dist/models.d.ts.map +1 -1
  17. package/dist/models.js.map +1 -1
  18. package/dist/move-coder.d.ts +1 -1
  19. package/dist/move-coder.d.ts.map +1 -1
  20. package/dist/move-coder.js +1 -5
  21. package/dist/move-coder.js.map +1 -1
  22. package/dist/sui-chain-adapter.d.ts +1 -1
  23. package/dist/sui-chain-adapter.d.ts.map +1 -1
  24. package/dist/sui-chain-adapter.js +10 -4
  25. package/dist/sui-chain-adapter.js.map +1 -1
  26. package/dist/tests/move-call.test.d.ts.map +1 -1
  27. package/dist/tests/move-call.test.js.map +1 -1
  28. package/dist/tests/move-coder.test.js.map +1 -1
  29. package/dist/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.d.ts +25 -544
  30. package/dist/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.d.ts.map +1 -1
  31. package/dist/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.js +10 -9
  32. package/dist/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.js.map +1 -1
  33. package/dist/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.d.ts +250 -6489
  34. package/dist/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.d.ts.map +1 -1
  35. package/dist/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.js +98 -97
  36. package/dist/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.js.map +1 -1
  37. package/dist/tests/types/testnet/0xdee9.d.ts +289 -6398
  38. package/dist/tests/types/testnet/0xdee9.d.ts.map +1 -1
  39. package/dist/tests/types/testnet/0xdee9.js +96 -95
  40. package/dist/tests/types/testnet/0xdee9.js.map +1 -1
  41. package/dist/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.d.ts +977 -21126
  42. package/dist/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.d.ts.map +1 -1
  43. package/dist/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.js +312 -311
  44. package/dist/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.js.map +1 -1
  45. package/dist/to-internal.d.ts +1 -1
  46. package/dist/to-internal.d.ts.map +1 -1
  47. package/dist/to-internal.js +2 -8
  48. package/dist/to-internal.js.map +1 -1
  49. package/package.json +5 -12
  50. package/src/builtin/0x1.ts +293 -297
  51. package/src/builtin/0x2.ts +1483 -1490
  52. package/src/builtin/0x3.ts +582 -589
  53. package/src/codegen/codegen.ts +10 -9
  54. package/src/models.ts +8 -14
  55. package/src/move-coder.ts +6 -20
  56. package/src/sui-chain-adapter.ts +13 -15
  57. package/src/tests/types/testnet/0x1e2b124f746a339b3cf99b9f969393a96594519aafb1d06517aacfeeae20e7a5.ts +27 -31
  58. package/src/tests/types/testnet/0x6c4a21e3e7e6b6d51c4604021633e1d97e24e37a696f8c082cd48f37503e602a.ts +276 -280
  59. package/src/tests/types/testnet/0xdee9.ts +303 -307
  60. package/src/tests/types/testnet/0xebaa2ad3eacc230f309cd933958cc52684df0a41ae7ac214d186b80f830867d2.ts +1064 -1068
  61. package/src/to-internal.ts +12 -32
@@ -1,4 +1,4 @@
1
- import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject } from '@mysten/sui.js'
1
+ import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject } from '@mysten/sui.js/client'
2
2
 
3
3
  import * as fs from 'fs'
4
4
  import chalk from 'chalk'
@@ -35,9 +35,8 @@ class SuiCodegen extends AbstractCodegen<
35
35
  SuiMoveNormalizedModule,
36
36
  SuiEvent | SuiMoveObject
37
37
  > {
38
- ADDRESS_TYPE = 'SuiAddress'
39
- REFERENCE_TYPE = 'ObjectId'
40
- SYSTEM_PACKAGE = '@mysten/sui.js'
38
+ ADDRESS_TYPE = 'string'
39
+ SYSTEM_PACKAGE = '@typemove/sui'
41
40
  // ADDRESS_TYPE = 'string'
42
41
  // MAIN_NET = SuiNetwork.MAIN_NET
43
42
  // TEST_NET = SuiNetwork.TEST_NET
@@ -113,12 +112,12 @@ class SuiCodegen extends AbstractCodegen<
113
112
  for (const [idx, arg] of func.params.entries()) {
114
113
  if (arg.reference) {
115
114
  args.push({
116
- paramType: 'ObjectId | ObjectCallArg | TransactionArgument',
115
+ paramType: `${this.ADDRESS_TYPE} | ObjectCallArg | TransactionArgument`,
117
116
  callValue: `_args.push(TransactionArgument.is(args[${idx}]) ? args[${idx}] : tx.object(args[${idx}]))`,
118
117
  })
119
118
  } else if (arg.isVector()) {
120
119
  args.push({
121
- paramType: '(ObjectId | ObjectCallArg)[] | TransactionArgument',
120
+ paramType: `(${this.ADDRESS_TYPE} | ObjectCallArg)[] | TransactionArgument`,
122
121
  callValue: `_args.push(TransactionArgument.is(args[${idx}]) ? args[${idx}] : tx.makeMoveVec({
123
122
  objects: args[${idx}].map((a: any) => tx.object(a))
124
123
  // type: TODO
@@ -149,12 +148,12 @@ class SuiCodegen extends AbstractCodegen<
149
148
  const args = this.generateArgs(module, func)
150
149
 
151
150
  return `export async function ${camel(normalizeToJSName(func.name))}${genericString}(
152
- provider: JsonRpcProvider,
151
+ client: SuiClient,
153
152
  args: [${args.map((a) => a.paramType).join(',')}],
154
153
  ${typeParamArg.length > 0 ? `typeArguments: [${typeParamArg}]` : ``} ) {
155
154
  const tx = new TransactionBlock()
156
155
  builder.${camel(normalizeToJSName(func.name))}(tx, args ${typeParamArg.length > 0 ? `, typeArguments` : ''})
157
- const res = await provider.devInspectTransactionBlock({
156
+ const res = await client.devInspectTransactionBlock({
158
157
  transactionBlock: tx,
159
158
  sender: ZERO_ADDRESS
160
159
  })
@@ -202,7 +201,9 @@ class SuiCodegen extends AbstractCodegen<
202
201
  return `
203
202
  ${super.generateImports()}
204
203
  import { ZERO_ADDRESS } from '@typemove/sui'
205
- import { TransactionBlock, TransactionArgument, ObjectCallArg, JsonRpcProvider } from '@mysten/sui.js'
204
+ import { TransactionBlock } from '@mysten/sui.js/transactions'
205
+ import { ObjectCallArg, TransactionArgument } from '@mysten/sui.js'
206
+ import { SuiClient } from '@mysten/sui.js/client'
206
207
  `
207
208
  }
208
209
  }
package/src/models.ts CHANGED
@@ -1,23 +1,17 @@
1
- import type {
2
- SuiEvent,
3
- MoveCallSuiTransaction,
4
- SuiMoveObject,
5
- } from '@mysten/sui.js'
1
+ import type { SuiEvent, MoveCallSuiTransaction, SuiMoveObject } from '@mysten/sui.js/client'
6
2
  import { DecodedStruct } from '@typemove/move'
7
3
 
8
- export const ZERO_ADDRESS =
9
- '0x0000000000000000000000000000000000000000000000000000000000000000'
4
+ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000000000000000000000000000'
10
5
 
11
6
  export type TypedEventInstance<T> = DecodedStruct<SuiEvent, T>
12
7
  export type TypedSuiMoveObject<T> = DecodedStruct<SuiMoveObject, T>
13
8
 
14
- export type TypedFunctionPayload<T extends Array<any>> =
15
- MoveCallSuiTransaction & {
16
- /**
17
- * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
18
- */
19
- arguments_decoded: T
20
- }
9
+ export type TypedFunctionPayload<T extends Array<any>> = MoveCallSuiTransaction & {
10
+ /**
11
+ * decoded argument data using ABI, undefined if there is decoding error, usually because the ABI/data mismatch
12
+ */
13
+ arguments_decoded: T
14
+ }
21
15
 
22
16
  // export interface TypedExecutionResultType<T> extends ExecutionResultType {
23
17
  //
package/src/move-coder.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  SuiEvent,
15
15
  SuiMoveNormalizedModule,
16
16
  SuiMoveObject,
17
- } from '@mysten/sui.js'
17
+ } from '@mysten/sui.js/client'
18
18
  import { toInternalModule } from './to-internal.js'
19
19
  import { SuiChainAdapter } from './sui-chain-adapter.js'
20
20
  import { dynamic_field } from './builtin/0x2.js'
@@ -60,10 +60,7 @@ export class MoveCoder extends AbstractMoveCoder<
60
60
  decodeEvent<T>(event: SuiEvent): Promise<TypedEventInstance<T> | undefined> {
61
61
  return this.decodedStruct(event)
62
62
  }
63
- filterAndDecodeEvents<T>(
64
- type: TypeDescriptor<T> | string,
65
- resources: SuiEvent[]
66
- ): Promise<TypedEventInstance<T>[]> {
63
+ filterAndDecodeEvents<T>(type: TypeDescriptor<T> | string, resources: SuiEvent[]): Promise<TypedEventInstance<T>[]> {
67
64
  if (typeof type === 'string') {
68
65
  type = parseMoveType(type)
69
66
  }
@@ -77,9 +74,7 @@ export class MoveCoder extends AbstractMoveCoder<
77
74
  ): Promise<dynamic_field.Field<T1, T2>[]> {
78
75
  // const type = dynamic_field.Field.TYPE
79
76
  // Not using the code above to avoid cycle initialize failed
80
- const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>(
81
- '0x2::dynamic_field::Field'
82
- )
77
+ const type = new TypeDescriptor<dynamic_field.Field<T1, T2>>('0x2::dynamic_field::Field')
83
78
  type.typeArgs = [keyType, valueType]
84
79
  const res = await this.filterAndDecodeObjects(type, objects)
85
80
  return res.map((o) => o.data_decoded)
@@ -92,15 +87,8 @@ export class MoveCoder extends AbstractMoveCoder<
92
87
  return this.filterAndDecodeStruct(type, objects)
93
88
  }
94
89
 
95
- async decodeFunctionPayload(
96
- payload: MoveCallSuiTransaction,
97
- inputs: SuiCallArg[]
98
- ): Promise<MoveCallSuiTransaction> {
99
- const functionType = [
100
- payload.package,
101
- payload.module,
102
- payload.function,
103
- ].join(SPLITTER)
90
+ async decodeFunctionPayload(payload: MoveCallSuiTransaction, inputs: SuiCallArg[]): Promise<MoveCallSuiTransaction> {
91
+ const functionType = [payload.package, payload.module, payload.function].join(SPLITTER)
104
92
  const func = await this.getMoveFunction(functionType)
105
93
  const params = this.adapter.getMeaningfulFunctionParams(func.params)
106
94
  const args = []
@@ -135,9 +123,7 @@ export class MoveCoder extends AbstractMoveCoder<
135
123
  const DEFAULT_ENDPOINT = 'https://fullnode.mainnet.sui.io/'
136
124
  const CODER_MAP = new Map<string, MoveCoder>()
137
125
 
138
- export function defaultMoveCoder(
139
- endpoint: string = DEFAULT_ENDPOINT
140
- ): MoveCoder {
126
+ export function defaultMoveCoder(endpoint: string = DEFAULT_ENDPOINT): MoveCoder {
141
127
  let coder = CODER_MAP.get(endpoint)
142
128
  if (!coder) {
143
129
  coder = new MoveCoder(DEFAULT_ENDPOINT)
@@ -7,14 +7,8 @@ import {
7
7
  SPLITTER,
8
8
  TypeDescriptor,
9
9
  } from '@typemove/move'
10
- import {
11
- Connection,
12
- JsonRpcProvider,
13
- SuiMoveNormalizedModule,
14
- SuiEvent,
15
- SuiMoveObject,
16
- SuiParsedData,
17
- } from '@mysten/sui.js'
10
+
11
+ import { SuiMoveNormalizedModule, SuiEvent, SuiMoveObject, SuiClient } from '@mysten/sui.js/client'
18
12
 
19
13
  export class SuiChainAdapter extends ChainAdapter<
20
14
  // SuiNetwork,
@@ -55,9 +49,7 @@ export class SuiChainAdapter extends ChainAdapter<
55
49
  return Object.values(modules).map(toInternalModule)
56
50
  }
57
51
 
58
- getAllEventStructs(
59
- modules: InternalMoveModule[]
60
- ): Map<string, InternalMoveStruct> {
52
+ getAllEventStructs(modules: InternalMoveModule[]): Map<string, InternalMoveStruct> {
61
53
  const eventMap = new Map<string, InternalMoveStruct>()
62
54
 
63
55
  for (const module of modules) {
@@ -78,10 +70,16 @@ export class SuiChainAdapter extends ChainAdapter<
78
70
  }
79
71
 
80
72
  getData(val: SuiEvent | SuiMoveObject) {
81
- if (SuiEvent.is(val)) {
73
+ // if (val.parsedJson) {
74
+ // return val.parsedJson as any
75
+ // }
76
+ if ('parsedJson' in val) {
82
77
  return val.parsedJson as any
83
78
  }
84
- if (SuiParsedData.is(val)) {
79
+ // if (SuiParsedData.is(val)) {
80
+ // return val.fields as any
81
+ // }
82
+ if (val.dataType === 'moveObject') {
85
83
  return val.fields as any
86
84
  }
87
85
  // if (SuiMoveObject.is(val)) {
@@ -108,6 +106,6 @@ export class SuiChainAdapter extends ChainAdapter<
108
106
  // return 'https://fullnode.mainnet.sui.io/'
109
107
  // }
110
108
 
111
- function getRpcClient(endpoint: string): JsonRpcProvider {
112
- return new JsonRpcProvider(new Connection({ fullnode: endpoint }))
109
+ function getRpcClient(endpoint: string): SuiClient {
110
+ return new SuiClient({ url: endpoint })
113
111
  }
@@ -6,15 +6,11 @@
6
6
 
7
7
  import { TypeDescriptor, ANY_TYPE } from "@typemove/move";
8
8
  import { MoveCoder, defaultMoveCoder, TypedEventInstance } from "@typemove/sui";
9
- import { SuiAddress, ObjectId } from "@mysten/sui.js";
10
9
 
11
10
  import { ZERO_ADDRESS } from "@typemove/sui";
12
- import {
13
- TransactionBlock,
14
- TransactionArgument,
15
- ObjectCallArg,
16
- JsonRpcProvider,
17
- } from "@mysten/sui.js";
11
+ import { TransactionBlock } from "@mysten/sui.js/transactions";
12
+ import { ObjectCallArg, TransactionArgument } from "@mysten/sui.js";
13
+ import { SuiClient } from "@mysten/sui.js/client";
18
14
 
19
15
  import { _0x2 } from "@typemove/sui/builtin";
20
16
  import { _0x1 } from "@typemove/sui/builtin";
@@ -87,9 +83,9 @@ export namespace oracle {
87
83
  export function copyKey<T0 = any>(
88
84
  tx: TransactionBlock,
89
85
  args: [
90
- ObjectId | ObjectCallArg | TransactionArgument,
91
- SuiAddress | TransactionArgument,
92
- ObjectId | ObjectCallArg | TransactionArgument
86
+ string | ObjectCallArg | TransactionArgument,
87
+ string | TransactionArgument,
88
+ string | ObjectCallArg | TransactionArgument
93
89
  ],
94
90
  typeArguments: [TypeDescriptor<T0> | string]
95
91
  ): TransactionArgument &
@@ -117,7 +113,7 @@ export namespace oracle {
117
113
  }
118
114
  export function getOracle<T0 = any>(
119
115
  tx: TransactionBlock,
120
- args: [ObjectId | ObjectCallArg | TransactionArgument],
116
+ args: [string | ObjectCallArg | TransactionArgument],
121
117
  typeArguments: [TypeDescriptor<T0> | string]
122
118
  ): TransactionArgument & [TransactionArgument] {
123
119
  const _args: any[] = [];
@@ -141,7 +137,7 @@ export namespace oracle {
141
137
  tx: TransactionBlock,
142
138
  args: [
143
139
  bigint | TransactionArgument,
144
- ObjectId | ObjectCallArg | TransactionArgument
140
+ string | ObjectCallArg | TransactionArgument
145
141
  ],
146
142
  typeArguments: [TypeDescriptor<T0> | string]
147
143
  ): TransactionArgument & [TransactionArgument, TransactionArgument] {
@@ -166,12 +162,12 @@ export namespace oracle {
166
162
  export function update<T0 = any>(
167
163
  tx: TransactionBlock,
168
164
  args: [
169
- ObjectId | ObjectCallArg | TransactionArgument,
170
- ObjectId | ObjectCallArg | TransactionArgument,
165
+ string | ObjectCallArg | TransactionArgument,
166
+ string | ObjectCallArg | TransactionArgument,
171
167
  bigint | TransactionArgument,
172
168
  bigint | TransactionArgument,
173
169
  bigint | TransactionArgument,
174
- ObjectId | ObjectCallArg | TransactionArgument
170
+ string | ObjectCallArg | TransactionArgument
175
171
  ],
176
172
  typeArguments: [TypeDescriptor<T0> | string]
177
173
  ): TransactionArgument &
@@ -212,66 +208,66 @@ export namespace oracle {
212
208
  }
213
209
  export namespace view {
214
210
  export async function copyKey<T0 = any>(
215
- provider: JsonRpcProvider,
211
+ client: SuiClient,
216
212
  args: [
217
- ObjectId | ObjectCallArg | TransactionArgument,
218
- SuiAddress | TransactionArgument,
219
- ObjectId | ObjectCallArg | TransactionArgument
213
+ string | ObjectCallArg | TransactionArgument,
214
+ string | TransactionArgument,
215
+ string | ObjectCallArg | TransactionArgument
220
216
  ],
221
217
  typeArguments: [TypeDescriptor<T0> | string]
222
218
  ) {
223
219
  const tx = new TransactionBlock();
224
220
  builder.copyKey(tx, args, typeArguments);
225
- const res = await provider.devInspectTransactionBlock({
221
+ const res = await client.devInspectTransactionBlock({
226
222
  transactionBlock: tx,
227
223
  sender: ZERO_ADDRESS,
228
224
  });
229
225
  return res;
230
226
  }
231
227
  export async function getOracle<T0 = any>(
232
- provider: JsonRpcProvider,
233
- args: [ObjectId | ObjectCallArg | TransactionArgument],
228
+ client: SuiClient,
229
+ args: [string | ObjectCallArg | TransactionArgument],
234
230
  typeArguments: [TypeDescriptor<T0> | string]
235
231
  ) {
236
232
  const tx = new TransactionBlock();
237
233
  builder.getOracle(tx, args, typeArguments);
238
- const res = await provider.devInspectTransactionBlock({
234
+ const res = await client.devInspectTransactionBlock({
239
235
  transactionBlock: tx,
240
236
  sender: ZERO_ADDRESS,
241
237
  });
242
238
  return res;
243
239
  }
244
240
  export async function newOracle<T0 = any>(
245
- provider: JsonRpcProvider,
241
+ client: SuiClient,
246
242
  args: [
247
243
  bigint | TransactionArgument,
248
- ObjectId | ObjectCallArg | TransactionArgument
244
+ string | ObjectCallArg | TransactionArgument
249
245
  ],
250
246
  typeArguments: [TypeDescriptor<T0> | string]
251
247
  ) {
252
248
  const tx = new TransactionBlock();
253
249
  builder.newOracle(tx, args, typeArguments);
254
- const res = await provider.devInspectTransactionBlock({
250
+ const res = await client.devInspectTransactionBlock({
255
251
  transactionBlock: tx,
256
252
  sender: ZERO_ADDRESS,
257
253
  });
258
254
  return res;
259
255
  }
260
256
  export async function update<T0 = any>(
261
- provider: JsonRpcProvider,
257
+ client: SuiClient,
262
258
  args: [
263
- ObjectId | ObjectCallArg | TransactionArgument,
264
- ObjectId | ObjectCallArg | TransactionArgument,
259
+ string | ObjectCallArg | TransactionArgument,
260
+ string | ObjectCallArg | TransactionArgument,
265
261
  bigint | TransactionArgument,
266
262
  bigint | TransactionArgument,
267
263
  bigint | TransactionArgument,
268
- ObjectId | ObjectCallArg | TransactionArgument
264
+ string | ObjectCallArg | TransactionArgument
269
265
  ],
270
266
  typeArguments: [TypeDescriptor<T0> | string]
271
267
  ) {
272
268
  const tx = new TransactionBlock();
273
269
  builder.update(tx, args, typeArguments);
274
- const res = await provider.devInspectTransactionBlock({
270
+ const res = await client.devInspectTransactionBlock({
275
271
  transactionBlock: tx,
276
272
  sender: ZERO_ADDRESS,
277
273
  });