@0xobelisk/sui-client 0.5.3 → 0.5.4

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 (42) hide show
  1. package/dist/index.d.ts +3 -1
  2. package/dist/index.js +343 -238
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +331 -245
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/libs/multiSig/client.d.ts +15 -0
  7. package/dist/libs/multiSig/index.d.ts +1 -0
  8. package/dist/libs/multiSig/publickey.d.ts +2 -0
  9. package/dist/libs/suiAccountManager/index.d.ts +1 -1
  10. package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
  11. package/dist/libs/suiContractFactory/index.d.ts +1 -1
  12. package/dist/libs/suiContractFactory/types.d.ts +1 -1
  13. package/dist/libs/suiInteractor/index.d.ts +0 -1
  14. package/dist/libs/suiInteractor/suiInteractor.d.ts +17 -177
  15. package/dist/libs/suiModel/suiOwnedObject.d.ts +4 -4
  16. package/dist/libs/suiModel/suiSharedObject.d.ts +4 -5
  17. package/dist/libs/suiTxBuilder/index.d.ts +178 -374
  18. package/dist/libs/suiTxBuilder/util.d.ts +41 -59
  19. package/dist/metadata/index.d.ts +2 -33
  20. package/dist/obelisk.d.ts +20 -2454
  21. package/dist/types/index.d.ts +28 -6
  22. package/package.json +22 -19
  23. package/src/index.ts +3 -1
  24. package/src/libs/multiSig/client.ts +44 -0
  25. package/src/libs/multiSig/index.ts +1 -0
  26. package/src/libs/multiSig/publickey.ts +11 -0
  27. package/src/libs/suiAccountManager/index.ts +1 -1
  28. package/src/libs/suiAccountManager/keypair.ts +1 -1
  29. package/src/libs/suiAccountManager/util.ts +1 -1
  30. package/src/libs/suiContractFactory/index.ts +1 -1
  31. package/src/libs/suiContractFactory/types.ts +2 -2
  32. package/src/libs/suiInteractor/index.ts +1 -1
  33. package/src/libs/suiInteractor/suiInteractor.ts +106 -111
  34. package/src/libs/suiModel/suiOwnedObject.ts +5 -10
  35. package/src/libs/suiModel/suiSharedObject.ts +4 -7
  36. package/src/libs/suiTxBuilder/index.ts +146 -100
  37. package/src/libs/suiTxBuilder/util.ts +145 -31
  38. package/src/metadata/index.ts +5 -3
  39. package/src/obelisk.ts +52 -37
  40. package/src/types/index.ts +53 -24
  41. package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
  42. package/src/libs/suiInteractor/defaultConfig.ts +0 -32
@@ -1,24 +1,36 @@
1
- import {
2
- TransactionBlock,
3
- SUI_SYSTEM_STATE_OBJECT_ID,
1
+ import { TransactionBlock } from '@mysten/sui.js/transactions';
2
+ import { SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui.js/utils';
3
+ import { convertArgs, convertAddressArg, convertObjArg } from './util';
4
+ import type { SuiClient, SuiObjectRef } from '@mysten/sui.js/client';
5
+ import type { TransactionObjectArgument } from '@mysten/sui.js/transactions';
6
+ import type {
4
7
  TransactionExpiration,
5
- SuiObjectRef,
6
8
  SharedObjectRef,
7
- JsonRpcProvider,
8
- TransactionType,
9
- Transactions,
9
+ } from '@mysten/sui.js/bcs';
10
+ import type { Keypair } from '@mysten/sui.js/cryptography';
11
+ import type {
10
12
  ObjectCallArg,
11
- } from '@mysten/sui.js';
12
- import { convertArgs } from './util';
13
- import type { SuiTxArg, SuiObjectArg, SuiVecTxArg } from '../../types';
13
+ TransactionType,
14
+ SuiTxArg,
15
+ SuiAddressArg,
16
+ SuiObjectArg,
17
+ SuiVecTxArg,
18
+ } from 'src/types';
14
19
 
15
20
  export class SuiTxBlock {
16
21
  public txBlock: TransactionBlock;
22
+
17
23
  constructor(transaction?: TransactionBlock) {
18
24
  this.txBlock = new TransactionBlock(transaction);
19
25
  }
20
26
 
21
- //======== override methods of TransactionBlock ============
27
+ /* Directly wrap methods and properties of TransactionBlock */
28
+ get gas() {
29
+ return this.txBlock.gas;
30
+ }
31
+ get blockData() {
32
+ return this.txBlock.blockData;
33
+ }
22
34
 
23
35
  address(value: string) {
24
36
  return this.txBlock.pure(value, 'address');
@@ -56,71 +68,97 @@ export class SuiTxBlock {
56
68
  setGasPayment(payments: SuiObjectRef[]) {
57
69
  return this.txBlock.setGasPayment(payments);
58
70
  }
59
-
60
- add(transaction: TransactionType) {
61
- return this.txBlock.add(transaction);
62
- }
63
71
  serialize() {
64
72
  return this.txBlock.serialize();
65
73
  }
74
+ sign(params: {
75
+ signer: Keypair;
76
+ client?: SuiClient;
77
+ onlyTransactionKind?: boolean;
78
+ }) {
79
+ return this.txBlock.sign(params);
80
+ }
66
81
  build(
67
82
  params: {
68
- provider?: JsonRpcProvider;
83
+ client?: SuiClient;
69
84
  onlyTransactionKind?: boolean;
70
85
  } = {}
71
86
  ) {
72
87
  return this.txBlock.build(params);
73
88
  }
74
- getDigest({ provider }: { provider?: JsonRpcProvider } = {}) {
75
- return this.txBlock.getDigest({ provider });
89
+ getDigest(params: { client?: SuiClient } = {}) {
90
+ return this.txBlock.getDigest(params);
91
+ }
92
+ add(...args: TransactionType) {
93
+ return this.txBlock.add(...args);
94
+ }
95
+ publish({
96
+ modules,
97
+ dependencies,
98
+ }: {
99
+ modules: number[][] | string[];
100
+ dependencies: string[];
101
+ }) {
102
+ return this.txBlock.publish({ modules, dependencies });
103
+ }
104
+ upgrade({
105
+ modules,
106
+ dependencies,
107
+ packageId,
108
+ ticket,
109
+ }: {
110
+ modules: number[][] | string[];
111
+ dependencies: string[];
112
+ packageId: string;
113
+ ticket: TransactionObjectArgument | string;
114
+ }) {
115
+ return this.txBlock.upgrade({ modules, dependencies, packageId, ticket });
116
+ }
117
+ makeMoveVec({
118
+ objects,
119
+ type,
120
+ }: {
121
+ objects: (TransactionObjectArgument | string)[];
122
+ type?: string;
123
+ }) {
124
+ return this.txBlock.makeMoveVec({ objects, type });
76
125
  }
77
126
 
78
- get gas() {
79
- return this.txBlock.gas;
80
- }
81
- get blockData() {
82
- return this.txBlock.blockData;
83
- }
127
+ /* Override methods of TransactionBlock */
84
128
 
85
- transferObjects(objects: SuiObjectArg[], recipient: string) {
86
- const tx = this.txBlock;
87
- tx.transferObjects(convertArgs(this.txBlock, objects), tx.pure(recipient));
88
- return this;
129
+ transferObjects(objects: SuiObjectArg[], address: SuiAddressArg) {
130
+ return this.txBlock.transferObjects(
131
+ objects.map((object) => convertObjArg(this.txBlock, object)),
132
+ convertAddressArg(this.txBlock, address)
133
+ );
89
134
  }
90
- splitCoins(coin: SuiObjectArg, amounts: number[]) {
91
- const tx = this.txBlock;
92
- const coinObject = convertArgs(this.txBlock, [coin])[0];
93
- const res = tx.splitCoins(
94
- coinObject,
95
- amounts.map((m) => tx.pure(m))
135
+
136
+ splitCoins(coin: SuiObjectArg, amounts: SuiTxArg[]) {
137
+ const res = this.txBlock.splitCoins(
138
+ convertObjArg(this.txBlock, coin),
139
+ convertArgs(this.txBlock, amounts)
96
140
  );
97
141
  return amounts.map((_, i) => res[i]);
98
142
  }
143
+
99
144
  mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {
100
- const destinationObject = convertArgs(this.txBlock, [destination])[0];
101
- const sourceObjects = convertArgs(this.txBlock, sources);
145
+ const destinationObject = convertObjArg(this.txBlock, destination);
146
+ const sourceObjects = sources.map((source) =>
147
+ convertObjArg(this.txBlock, source)
148
+ );
102
149
  return this.txBlock.mergeCoins(destinationObject, sourceObjects);
103
150
  }
104
- publish(...args: Parameters<(typeof Transactions)['Publish']>) {
105
- return this.txBlock.publish(...args);
106
- }
107
- upgrade(...args: Parameters<(typeof Transactions)['Upgrade']>) {
108
- return this.txBlock.upgrade(...args);
109
- }
110
- makeMoveVec(...args: Parameters<(typeof Transactions)['MakeMoveVec']>) {
111
- return this.txBlock.makeMoveVec(...args);
112
- }
113
151
 
114
152
  /**
115
153
  * @description Move call
116
154
  * @param target `${string}::${string}::${string}`, e.g. `0x3::sui_system::request_add_stake`
117
155
  * @param args the arguments of the move call, such as `['0x1', '0x2']`
118
- * @param typeArguments the type arguments of the move call, such as `['0x2::sui::SUI']`
156
+ * @param typeArgs the type arguments of the move call, such as `['0x2::sui::SUI']`
119
157
  */
120
158
  moveCall(
121
159
  target: string,
122
160
  args: (SuiTxArg | SuiVecTxArg)[] = [],
123
- typeArguments: string[] = []
161
+ typeArgs: string[] = []
124
162
  ) {
125
163
  // a regex for pattern `${string}::${string}::${string}`
126
164
  const regex =
@@ -131,76 +169,77 @@ export class SuiTxBlock {
131
169
  'Invalid target format. Expected `${string}::${string}::${string}`'
132
170
  );
133
171
  const convertedArgs = convertArgs(this.txBlock, args);
134
- const tx = this.txBlock;
135
- return tx.moveCall({
172
+ return this.txBlock.moveCall({
136
173
  target: target as `${string}::${string}::${string}`,
137
174
  arguments: convertedArgs,
138
- typeArguments,
175
+ typeArguments: typeArgs,
139
176
  });
140
177
  }
141
178
 
142
- //======== enhance methods ============
143
- transferSuiToMany(recipients: string[], amounts: number[]) {
179
+ /* Enhance methods of TransactionBlock */
180
+
181
+ transferSuiToMany(recipients: SuiAddressArg[], amounts: SuiTxArg[]) {
144
182
  // require recipients.length === amounts.length
145
183
  if (recipients.length !== amounts.length) {
146
184
  throw new Error(
147
185
  'transferSuiToMany: recipients.length !== amounts.length'
148
186
  );
149
187
  }
150
-
151
- const tx = this.txBlock;
152
- const coins = tx.splitCoins(
153
- tx.gas,
154
- amounts.map((amount) => tx.pure(amount))
188
+ const coins = this.txBlock.splitCoins(
189
+ this.txBlock.gas,
190
+ convertArgs(this.txBlock, amounts)
155
191
  );
156
- recipients.forEach((recipient, index) => {
157
- tx.transferObjects([coins[index]], tx.pure(recipient));
192
+ const recipientObjects = recipients.map((recipient) =>
193
+ convertAddressArg(this.txBlock, recipient)
194
+ );
195
+ recipientObjects.forEach((address, index) => {
196
+ this.txBlock.transferObjects([coins[index]], address);
158
197
  });
159
198
  return this;
160
199
  }
161
200
 
162
- transferSui(recipient: string, amount: number) {
163
- return this.transferSuiToMany([recipient], [amount]);
201
+ transferSui(address: SuiAddressArg, amount: SuiTxArg) {
202
+ return this.transferSuiToMany([address], [amount]);
164
203
  }
165
204
 
166
- takeAmountFromCoins(coins: SuiObjectArg[], amount: number) {
167
- const tx = this.txBlock;
168
- const coinObjects = convertArgs(this.txBlock, coins);
205
+ takeAmountFromCoins(coins: SuiObjectArg[], amount: SuiTxArg) {
206
+ const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
169
207
  const mergedCoin = coinObjects[0];
170
208
  if (coins.length > 1) {
171
- tx.mergeCoins(mergedCoin, coinObjects.slice(1));
209
+ this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
172
210
  }
173
- const [sendCoin] = tx.splitCoins(mergedCoin, [tx.pure(amount)]);
211
+ const [sendCoin] = this.txBlock.splitCoins(
212
+ mergedCoin,
213
+ convertArgs(this.txBlock, [amount])
214
+ );
174
215
  return [sendCoin, mergedCoin];
175
216
  }
176
217
 
177
- splitSUIFromGas(amounts: number[]) {
178
- const tx = this.txBlock;
179
- return tx.splitCoins(
180
- tx.gas,
181
- amounts.map((m) => tx.pure(m))
218
+ splitSUIFromGas(amounts: SuiTxArg[]) {
219
+ return this.txBlock.splitCoins(
220
+ this.txBlock.gas,
221
+ convertArgs(this.txBlock, amounts)
182
222
  );
183
223
  }
184
224
 
185
- splitMultiCoins(coins: SuiObjectArg[], amounts: number[]) {
186
- const tx = this.txBlock;
187
- const coinObjects = convertArgs(this.txBlock, coins);
225
+ splitMultiCoins(coins: SuiObjectArg[], amounts: SuiTxArg[]) {
226
+ const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
188
227
  const mergedCoin = coinObjects[0];
189
228
  if (coins.length > 1) {
190
- tx.mergeCoins(mergedCoin, coinObjects.slice(1));
229
+ this.txBlock.mergeCoins(mergedCoin, coinObjects.slice(1));
191
230
  }
192
- const splitedCoins = tx.splitCoins(
231
+ const splitedCoins = this.txBlock.splitCoins(
193
232
  mergedCoin,
194
- amounts.map((m) => tx.pure(m))
233
+ convertArgs(this.txBlock, amounts)
195
234
  );
196
235
  return { splitedCoins, mergedCoin };
197
236
  }
198
237
 
199
238
  transferCoinToMany(
200
- inputCoins: SuiObjectArg[],
201
- sender: string,
202
- recipients: string[],
203
- amounts: number[]
239
+ coins: SuiObjectArg[],
240
+ sender: SuiAddressArg,
241
+ recipients: SuiAddressArg[],
242
+ amounts: SuiTxArg[]
204
243
  ) {
205
244
  // require recipients.length === amounts.length
206
245
  if (recipients.length !== amounts.length) {
@@ -208,38 +247,45 @@ export class SuiTxBlock {
208
247
  'transferSuiToMany: recipients.length !== amounts.length'
209
248
  );
210
249
  }
211
- const tx = this.txBlock;
250
+ const coinObjects = coins.map((coin) => convertObjArg(this.txBlock, coin));
212
251
  const { splitedCoins, mergedCoin } = this.splitMultiCoins(
213
- inputCoins,
252
+ coinObjects,
214
253
  amounts
215
254
  );
216
- recipients.forEach((recipient, index) => {
217
- tx.transferObjects([splitedCoins[index]], tx.pure(recipient));
255
+ const recipientObjects = recipients.map((recipient) =>
256
+ convertAddressArg(this.txBlock, recipient)
257
+ );
258
+ recipientObjects.forEach((address, index) => {
259
+ this.txBlock.transferObjects([splitedCoins[index]], address);
218
260
  });
219
- tx.transferObjects([mergedCoin], tx.pure(sender));
261
+ this.txBlock.transferObjects(
262
+ [mergedCoin],
263
+ convertAddressArg(this.txBlock, sender)
264
+ );
220
265
  return this;
221
266
  }
222
267
 
223
268
  transferCoin(
224
- inputCoins: SuiObjectArg[],
225
- sender: string,
226
- recipient: string,
227
- amount: number
269
+ coins: SuiObjectArg[],
270
+ sender: SuiAddressArg,
271
+ recipient: SuiAddressArg,
272
+ amount: SuiTxArg
228
273
  ) {
229
- return this.transferCoinToMany(inputCoins, sender, [recipient], [amount]);
274
+ return this.transferCoinToMany(coins, sender, [recipient], [amount]);
230
275
  }
231
276
 
232
- stakeSui(amount: number, validatorAddr: string) {
233
- const tx = this.txBlock;
234
- const [stakeCoin] = tx.splitCoins(tx.gas, [tx.pure(amount)]);
235
- tx.moveCall({
277
+ stakeSui(amount: SuiTxArg, validatorAddr: SuiAddressArg) {
278
+ const [stakeCoin] = this.txBlock.splitCoins(
279
+ this.txBlock.gas,
280
+ convertArgs(this.txBlock, [amount])
281
+ );
282
+ return this.txBlock.moveCall({
236
283
  target: '0x3::sui_system::request_add_stake',
237
- arguments: [
238
- tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
284
+ arguments: convertArgs(this.txBlock, [
285
+ SUI_SYSTEM_STATE_OBJECT_ID,
239
286
  stakeCoin,
240
- tx.pure(validatorAddr),
241
- ],
287
+ this.txBlock.pure(validatorAddr),
288
+ ]),
242
289
  });
243
- return tx;
244
290
  }
245
291
  }
@@ -1,19 +1,36 @@
1
1
  import {
2
2
  normalizeSuiObjectId,
3
+ normalizeSuiAddress,
4
+ isValidSuiObjectId,
5
+ isValidSuiAddress,
6
+ } from '@mysten/sui.js/utils';
7
+ import { Inputs } from '@mysten/sui.js/transactions';
8
+ import { isPureArg } from '@mysten/sui.js/bcs';
9
+ import { isSerializedBcs } from '@mysten/bcs';
10
+ import type {
3
11
  TransactionArgument,
4
12
  TransactionBlock,
5
- } from '@mysten/sui.js';
6
- import { SuiTxArg, SuiInputTypes } from '../../types';
13
+ TransactionObjectArgument,
14
+ } from '@mysten/sui.js/transactions';
15
+ import type {
16
+ SuiInputTypes,
17
+ SuiObjectArg,
18
+ SuiAddressArg,
19
+ SuiTxArg,
20
+ SuiVecTxArg,
21
+ } from 'src/types';
7
22
 
8
- export const getDefaultSuiInputType = (value: any): SuiInputTypes => {
9
- if (typeof value === 'string' && value.startsWith('0x')) {
23
+ export const getDefaultSuiInputType = (
24
+ value: SuiTxArg
25
+ ): SuiInputTypes | undefined => {
26
+ if (typeof value === 'string' && isValidSuiObjectId(value)) {
10
27
  return 'object';
11
28
  } else if (typeof value === 'number' || typeof value === 'bigint') {
12
29
  return 'u64';
13
30
  } else if (typeof value === 'boolean') {
14
31
  return 'bool';
15
32
  } else {
16
- return 'object';
33
+ return undefined;
17
34
  }
18
35
  };
19
36
 
@@ -22,63 +39,160 @@ export const getDefaultSuiInputType = (value: any): SuiInputTypes => {
22
39
  * If type is not provided, we will try to infer the type from the first element
23
40
  * By default,
24
41
  *
25
- * string starting with `0x` =====> object id
42
+ * string is hex and its length equal to 32 =====> object id
26
43
  * number, bigint ====> u64
27
44
  * boolean =====> bool
28
45
  *
29
- *
30
46
  * If type is provided, we will use the type to convert the array
31
47
  * @param args
32
- * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'object'
48
+ * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer' | 'object' | string
33
49
  */
34
50
  export function makeVecParam(
35
51
  txBlock: TransactionBlock,
36
52
  args: SuiTxArg[],
37
53
  type?: SuiInputTypes
38
- ) {
54
+ ): TransactionArgument {
39
55
  if (args.length === 0)
40
56
  throw new Error('Transaction builder error: Empty array is not allowed');
57
+ // Using first element value as default type
41
58
  const defaultSuiType = getDefaultSuiInputType(args[0]);
42
- if (type === 'object' || (!type && defaultSuiType === 'object')) {
59
+ const VECTOR_REGEX = /^vector<(.+)>$/;
60
+ const STRUCT_REGEX = /^([^:]+)::([^:]+)::([^<]+)(<(.+)>)?/;
61
+
62
+ type = type || defaultSuiType;
63
+
64
+ if (type === 'object') {
43
65
  const objects = args.map((arg) =>
44
- typeof arg === 'string'
66
+ typeof arg === 'string' && isValidSuiObjectId(arg)
45
67
  ? txBlock.object(normalizeSuiObjectId(arg))
46
- : (arg as any)
68
+ : convertObjArg(txBlock, arg as SuiObjectArg)
47
69
  );
48
70
  return txBlock.makeMoveVec({ objects });
71
+ } else if (
72
+ typeof type === 'string' &&
73
+ !VECTOR_REGEX.test(type) &&
74
+ !STRUCT_REGEX.test(type)
75
+ ) {
76
+ return txBlock.pure(args, `vector<${type}>`);
49
77
  } else {
50
- const vecType = type || defaultSuiType;
51
- return txBlock.pure(args, `vector<${vecType}>`);
78
+ const objects = args.map((arg) =>
79
+ convertObjArg(txBlock, arg as SuiObjectArg)
80
+ );
81
+ return txBlock.makeMoveVec({ objects, type });
52
82
  }
53
83
  }
54
84
 
55
- export function isMoveVecArg(arg: any) {
56
- const isFullMoveVecArg =
57
- arg && arg.value && Array.isArray(arg.value) && arg.vecType;
58
- const isSimpleMoveVecArg = Array.isArray(arg);
59
- return isFullMoveVecArg || isSimpleMoveVecArg;
85
+ /**
86
+ * Check whether it is an valid move vec input.
87
+ *
88
+ * @param arg The argument to check.
89
+ * @returns boolean.
90
+ */
91
+ export function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
92
+ if (typeof arg === 'object' && 'vecType' in arg && 'value' in arg) {
93
+ return true;
94
+ } else if (Array.isArray(arg)) {
95
+ return true;
96
+ }
97
+ return false;
60
98
  }
61
99
 
100
+ /**
101
+ * Convert any valid input into array of TransactionArgument.
102
+ *
103
+ * @param txb The Transaction Block
104
+ * @param args The array of argument to convert.
105
+ * @returns The converted array of TransactionArgument.
106
+ */
62
107
  export function convertArgs(
63
108
  txBlock: TransactionBlock,
64
- args: any[]
65
- ): TransactionArgument[] {
109
+ args: (SuiTxArg | SuiVecTxArg)[]
110
+ ) {
66
111
  return args.map((arg) => {
67
- if (typeof arg === 'string' && arg.startsWith('0x')) {
68
- // We always treat string starting with `0x` as object id
112
+ if (typeof arg === 'string' && isValidSuiObjectId(arg)) {
69
113
  return txBlock.object(normalizeSuiObjectId(arg));
114
+ } else if (
115
+ typeof arg == 'object' &&
116
+ !isSerializedBcs(arg) &&
117
+ !isPureArg(arg) &&
118
+ !isMoveVecArg(arg)
119
+ ) {
120
+ return convertObjArg(txBlock, arg as SuiObjectArg);
70
121
  } else if (isMoveVecArg(arg)) {
71
- // if it's an array arg, we will convert it to move vec
72
- const vecType = arg.vecType || undefined;
122
+ const vecType = 'vecType' in arg;
73
123
  return vecType
74
- ? makeVecParam(txBlock, arg.value, vecType)
124
+ ? makeVecParam(txBlock, arg.value, arg.vecType)
75
125
  : makeVecParam(txBlock, arg);
76
- } else if (typeof arg !== 'object') {
77
- // Other basic types such as string, number, boolean are converted to pure value
78
- return txBlock.pure(arg);
79
- } else {
80
- // We do nothing, because it's most likely already a move value
126
+ } else if (isSerializedBcs(arg)) {
81
127
  return arg;
128
+ } else {
129
+ return txBlock.pure(arg);
82
130
  }
83
131
  });
84
132
  }
133
+
134
+ /**
135
+ * Convert any valid address input into a TransactionArgument.
136
+ *
137
+ * @param txb The Transaction Block
138
+ * @param arg The address argument to convert.
139
+ * @returns The converted TransactionArgument.
140
+ */
141
+ export function convertAddressArg(
142
+ txBlock: TransactionBlock,
143
+ arg: SuiAddressArg
144
+ ) {
145
+ if (typeof arg === 'string' && isValidSuiAddress(arg)) {
146
+ return txBlock.pure.address(normalizeSuiAddress(arg));
147
+ } else if (
148
+ typeof arg == 'object' &&
149
+ !isSerializedBcs(arg) &&
150
+ !isPureArg(arg)
151
+ ) {
152
+ return convertObjArg(txBlock, arg as SuiObjectArg);
153
+ } else if (isPureArg(arg)) {
154
+ return txBlock.pure(arg);
155
+ } else {
156
+ return arg;
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Convert any valid object input into a TransactionArgument.
162
+ *
163
+ * @param txb The Transaction Block
164
+ * @param arg The object argument to convert.
165
+ * @returns The converted TransactionArgument.
166
+ */
167
+ export function convertObjArg(
168
+ txb: TransactionBlock,
169
+ arg: SuiObjectArg
170
+ ): TransactionObjectArgument {
171
+ if (typeof arg === 'string') {
172
+ return txb.object(arg);
173
+ }
174
+
175
+ if ('digest' in arg && 'version' in arg && 'objectId' in arg) {
176
+ return txb.objectRef(arg);
177
+ }
178
+
179
+ if ('objectId' in arg && 'initialSharedVersion' in arg && 'mutable' in arg) {
180
+ return txb.sharedObjectRef(arg);
181
+ }
182
+
183
+ if ('Object' in arg) {
184
+ if ('ImmOrOwned' in arg.Object) {
185
+ return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwned));
186
+ } else if ('Shared' in arg.Object) {
187
+ return txb.object(Inputs.SharedObjectRef(arg.Object.Shared));
188
+ } else {
189
+ throw new Error('Invalid argument type');
190
+ }
191
+ }
192
+
193
+ if ('kind' in arg) {
194
+ return arg;
195
+ }
196
+
197
+ throw new Error('Invalid argument type');
198
+ }
@@ -1,5 +1,7 @@
1
- import { SuiMoveNormalizedModules } from '@mysten/sui.js';
2
- import { SuiInteractor, getDefaultConnection } from '../libs/suiInteractor';
1
+ import { SuiMoveNormalizedModules } from '@mysten/sui.js/client';
2
+ import { getFullnodeUrl } from '@mysten/sui.js/client';
3
+
4
+ import { SuiInteractor } from '../libs/suiInteractor';
3
5
 
4
6
  import { NetworkType } from '../types';
5
7
 
@@ -8,7 +10,7 @@ export async function loadMetadata(
8
10
  packageId: string
9
11
  ) {
10
12
  // Init the rpc provider
11
- const fullnodeUrls = [getDefaultConnection(networkType).fullnode];
13
+ const fullnodeUrls = [getFullnodeUrl(networkType)];
12
14
  const suiInteractor = new SuiInteractor(fullnodeUrls);
13
15
  if (packageId !== undefined) {
14
16
  const jsonData = await suiInteractor.getNormalizedMoveModulesByPackage(