@0xobelisk/sui-client 0.5.17 → 0.5.19
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.
- package/dist/index.d.ts +9 -8
- package/dist/index.js +309 -208
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -201
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +2 -2
- package/dist/libs/multiSig/publickey.d.ts +1 -1
- package/dist/libs/suiAccountManager/index.d.ts +1 -1
- package/dist/libs/suiAccountManager/keypair.d.ts +1 -1
- package/dist/libs/suiContractFactory/index.d.ts +1 -1
- package/dist/libs/suiContractFactory/types.d.ts +1 -1
- package/dist/libs/suiInteractor/suiInteractor.d.ts +5 -5
- package/dist/libs/suiModel/suiOwnedObject.d.ts +2 -2
- package/dist/libs/suiModel/suiSharedObject.d.ts +1 -1
- package/dist/libs/suiTxBuilder/index.d.ts +365 -160
- package/dist/libs/suiTxBuilder/util.d.ts +8 -17
- package/dist/metadata/index.d.ts +1 -1
- package/dist/obelisk.d.ts +16 -12
- package/dist/types/index.d.ts +65 -15
- package/package.json +11 -8
- package/src/index.ts +9 -8
- package/src/libs/multiSig/client.ts +2 -2
- package/src/libs/multiSig/publickey.ts +3 -3
- package/src/libs/suiAccountManager/index.ts +2 -2
- package/src/libs/suiAccountManager/keypair.ts +1 -1
- package/src/libs/suiAccountManager/util.ts +1 -1
- package/src/libs/suiContractFactory/index.ts +1 -1
- package/src/libs/suiContractFactory/types.ts +1 -1
- package/src/libs/suiInteractor/index.ts +0 -1
- package/src/libs/suiInteractor/suiInteractor.ts +4 -4
- package/src/libs/suiModel/suiOwnedObject.ts +5 -3
- package/src/libs/suiModel/suiSharedObject.ts +4 -2
- package/src/libs/suiTxBuilder/index.ts +120 -108
- package/src/libs/suiTxBuilder/util.ts +55 -48
- package/src/metadata/index.ts +2 -3
- package/src/obelisk.ts +199 -90
- package/src/types/index.ts +82 -44
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui
|
|
3
|
-
import {
|
|
4
|
-
import type { SuiClient, SuiObjectRef } from '@mysten/sui.js/client';
|
|
5
|
-
import type { TransactionObjectArgument } from '@mysten/sui.js/transactions';
|
|
1
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
+
import { SUI_SYSTEM_STATE_OBJECT_ID } from '@mysten/sui/utils';
|
|
3
|
+
import type { SuiClient, SuiObjectRef } from '@mysten/sui/client';
|
|
6
4
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '@mysten/sui
|
|
10
|
-
import type { Keypair } from '@mysten/sui
|
|
5
|
+
TransactionObjectArgument,
|
|
6
|
+
TransactionObjectInput,
|
|
7
|
+
} from '@mysten/sui/transactions';
|
|
8
|
+
import type { Keypair } from '@mysten/sui/cryptography';
|
|
9
|
+
import { SerializedBcs } from '@mysten/bcs';
|
|
10
|
+
|
|
11
11
|
import type {
|
|
12
12
|
ObjectCallArg,
|
|
13
13
|
TransactionType,
|
|
@@ -15,68 +15,91 @@ import type {
|
|
|
15
15
|
SuiAddressArg,
|
|
16
16
|
SuiObjectArg,
|
|
17
17
|
SuiVecTxArg,
|
|
18
|
+
SuiAmountsArg,
|
|
18
19
|
} from '../../types';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
import type { bcs } from '@mysten/sui/bcs';
|
|
22
|
+
import {
|
|
23
|
+
convertArgs,
|
|
24
|
+
convertAddressArg,
|
|
25
|
+
convertObjArg,
|
|
26
|
+
convertAmounts,
|
|
27
|
+
} from './util';
|
|
28
|
+
export class SuiTx {
|
|
29
|
+
public tx: Transaction;
|
|
22
30
|
|
|
23
|
-
constructor(transaction?:
|
|
24
|
-
|
|
31
|
+
constructor(transaction?: Transaction) {
|
|
32
|
+
if (transaction !== undefined) {
|
|
33
|
+
this.tx = Transaction.from(transaction);
|
|
34
|
+
} else {
|
|
35
|
+
this.tx = new Transaction();
|
|
36
|
+
}
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/* Directly wrap methods and properties of TransactionBlock */
|
|
28
40
|
get gas() {
|
|
29
|
-
return this.
|
|
41
|
+
return this.tx.gas;
|
|
30
42
|
}
|
|
31
43
|
get blockData() {
|
|
32
|
-
return this.
|
|
44
|
+
return this.tx.blockData;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
autoPure(value: SuiTxArg, type?: string) {
|
|
48
|
+
if (type === undefined) {
|
|
49
|
+
return convertArgs(this.tx, [value]);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return;
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
address(value: string) {
|
|
36
|
-
return this.
|
|
56
|
+
return this.tx.pure.address(value);
|
|
37
57
|
}
|
|
38
|
-
pure(
|
|
39
|
-
return this.
|
|
58
|
+
get pure() {
|
|
59
|
+
return this.tx.pure.bind(this.tx);
|
|
40
60
|
}
|
|
41
|
-
object(value: string |
|
|
42
|
-
return this.
|
|
61
|
+
object(value: string | TransactionObjectInput) {
|
|
62
|
+
return this.tx.object(value);
|
|
43
63
|
}
|
|
44
64
|
objectRef(ref: SuiObjectRef) {
|
|
45
|
-
return this.
|
|
65
|
+
return this.tx.objectRef(ref);
|
|
46
66
|
}
|
|
47
|
-
sharedObjectRef(ref: SharedObjectRef) {
|
|
48
|
-
return this.
|
|
67
|
+
sharedObjectRef(ref: typeof bcs.SharedObjectRef.$inferType) {
|
|
68
|
+
return this.tx.sharedObjectRef(ref);
|
|
49
69
|
}
|
|
50
70
|
setSender(sender: string) {
|
|
51
|
-
return this.
|
|
71
|
+
return this.tx.setSender(sender);
|
|
52
72
|
}
|
|
53
73
|
setSenderIfNotSet(sender: string) {
|
|
54
|
-
return this.
|
|
74
|
+
return this.tx.setSenderIfNotSet(sender);
|
|
55
75
|
}
|
|
56
|
-
setExpiration(expiration?:
|
|
57
|
-
return this.
|
|
76
|
+
setExpiration(expiration?: Parameters<typeof this.tx.setExpiration>[0]) {
|
|
77
|
+
return this.tx.setExpiration(expiration);
|
|
58
78
|
}
|
|
59
79
|
setGasPrice(price: number | bigint) {
|
|
60
|
-
return this.
|
|
80
|
+
return this.tx.setGasPrice(price);
|
|
61
81
|
}
|
|
62
82
|
setGasBudget(budget: number | bigint) {
|
|
63
|
-
return this.
|
|
83
|
+
return this.tx.setGasBudget(budget);
|
|
64
84
|
}
|
|
65
85
|
setGasOwner(owner: string) {
|
|
66
|
-
return this.
|
|
86
|
+
return this.tx.setGasOwner(owner);
|
|
67
87
|
}
|
|
68
88
|
setGasPayment(payments: SuiObjectRef[]) {
|
|
69
|
-
return this.
|
|
89
|
+
return this.tx.setGasPayment(payments);
|
|
70
90
|
}
|
|
71
91
|
serialize() {
|
|
72
|
-
return this.
|
|
92
|
+
return this.tx.serialize();
|
|
93
|
+
}
|
|
94
|
+
toJSON() {
|
|
95
|
+
return this.tx.toJSON();
|
|
73
96
|
}
|
|
74
97
|
sign(params: {
|
|
75
98
|
signer: Keypair;
|
|
76
99
|
client?: SuiClient;
|
|
77
100
|
onlyTransactionKind?: boolean;
|
|
78
101
|
}) {
|
|
79
|
-
return this.
|
|
102
|
+
return this.tx.sign(params);
|
|
80
103
|
}
|
|
81
104
|
build(
|
|
82
105
|
params: {
|
|
@@ -84,13 +107,13 @@ export class SuiTxBlock {
|
|
|
84
107
|
onlyTransactionKind?: boolean;
|
|
85
108
|
} = {}
|
|
86
109
|
) {
|
|
87
|
-
return this.
|
|
110
|
+
return this.tx.build(params);
|
|
88
111
|
}
|
|
89
112
|
getDigest(params: { client?: SuiClient } = {}) {
|
|
90
|
-
return this.
|
|
113
|
+
return this.tx.getDigest(params);
|
|
91
114
|
}
|
|
92
|
-
add(...args:
|
|
93
|
-
return this.
|
|
115
|
+
add(...args: Parameters<typeof this.tx.add>) {
|
|
116
|
+
return this.tx.add(...args);
|
|
94
117
|
}
|
|
95
118
|
publish({
|
|
96
119
|
modules,
|
|
@@ -99,54 +122,38 @@ export class SuiTxBlock {
|
|
|
99
122
|
modules: number[][] | string[];
|
|
100
123
|
dependencies: string[];
|
|
101
124
|
}) {
|
|
102
|
-
return this.
|
|
125
|
+
return this.tx.publish({ modules, dependencies });
|
|
103
126
|
}
|
|
104
|
-
upgrade({
|
|
105
|
-
|
|
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 });
|
|
127
|
+
upgrade(...args: Parameters<typeof this.tx.upgrade>) {
|
|
128
|
+
return this.tx.upgrade(...args);
|
|
116
129
|
}
|
|
117
|
-
makeMoveVec({
|
|
118
|
-
|
|
119
|
-
type,
|
|
120
|
-
}: {
|
|
121
|
-
objects: (TransactionObjectArgument | string)[];
|
|
122
|
-
type?: string;
|
|
123
|
-
}) {
|
|
124
|
-
return this.txBlock.makeMoveVec({ objects, type });
|
|
130
|
+
makeMoveVec(...args: Parameters<typeof this.tx.makeMoveVec>) {
|
|
131
|
+
return this.tx.makeMoveVec(...args);
|
|
125
132
|
}
|
|
126
133
|
|
|
127
134
|
/* Override methods of TransactionBlock */
|
|
128
135
|
|
|
129
136
|
transferObjects(objects: SuiObjectArg[], address: SuiAddressArg) {
|
|
130
|
-
return this.
|
|
131
|
-
objects.map((object) => convertObjArg(this.
|
|
132
|
-
convertAddressArg(this.
|
|
137
|
+
return this.tx.transferObjects(
|
|
138
|
+
objects.map((object) => convertObjArg(this.tx, object)),
|
|
139
|
+
convertAddressArg(this.tx, address)
|
|
133
140
|
);
|
|
134
141
|
}
|
|
135
142
|
|
|
136
143
|
splitCoins(coin: SuiObjectArg, amounts: SuiTxArg[]) {
|
|
137
|
-
const res = this.
|
|
138
|
-
convertObjArg(this.
|
|
139
|
-
convertArgs(this.
|
|
144
|
+
const res = this.tx.splitCoins(
|
|
145
|
+
convertObjArg(this.tx, coin),
|
|
146
|
+
convertArgs(this.tx, amounts)
|
|
140
147
|
);
|
|
141
148
|
return amounts.map((_, i) => res[i]);
|
|
142
149
|
}
|
|
143
150
|
|
|
144
151
|
mergeCoins(destination: SuiObjectArg, sources: SuiObjectArg[]) {
|
|
145
|
-
const destinationObject = convertObjArg(this.
|
|
152
|
+
const destinationObject = convertObjArg(this.tx, destination);
|
|
146
153
|
const sourceObjects = sources.map((source) =>
|
|
147
|
-
convertObjArg(this.
|
|
154
|
+
convertObjArg(this.tx, source)
|
|
148
155
|
);
|
|
149
|
-
return this.
|
|
156
|
+
return this.tx.mergeCoins(destinationObject, sourceObjects);
|
|
150
157
|
}
|
|
151
158
|
|
|
152
159
|
/**
|
|
@@ -168,8 +175,8 @@ export class SuiTxBlock {
|
|
|
168
175
|
throw new Error(
|
|
169
176
|
'Invalid target format. Expected `${string}::${string}::${string}`'
|
|
170
177
|
);
|
|
171
|
-
const convertedArgs = convertArgs(this.
|
|
172
|
-
return this.
|
|
178
|
+
const convertedArgs = convertArgs(this.tx, args);
|
|
179
|
+
return this.tx.moveCall({
|
|
173
180
|
target: target as `${string}::${string}::${string}`,
|
|
174
181
|
arguments: convertedArgs,
|
|
175
182
|
typeArguments: typeArgs,
|
|
@@ -178,59 +185,67 @@ export class SuiTxBlock {
|
|
|
178
185
|
|
|
179
186
|
/* Enhance methods of TransactionBlock */
|
|
180
187
|
|
|
181
|
-
transferSuiToMany(
|
|
188
|
+
transferSuiToMany(
|
|
189
|
+
recipients: SuiAddressArg[],
|
|
190
|
+
amounts: (SuiTxArg | number | bigint)[]
|
|
191
|
+
) {
|
|
182
192
|
// require recipients.length === amounts.length
|
|
183
193
|
if (recipients.length !== amounts.length) {
|
|
184
194
|
throw new Error(
|
|
185
195
|
'transferSuiToMany: recipients.length !== amounts.length'
|
|
186
196
|
);
|
|
187
197
|
}
|
|
188
|
-
const coins = this.
|
|
189
|
-
this.
|
|
190
|
-
|
|
198
|
+
const coins = this.tx.splitCoins(
|
|
199
|
+
this.tx.gas,
|
|
200
|
+
amounts.map((amount) =>
|
|
201
|
+
typeof amount === 'number' || typeof amount === 'bigint'
|
|
202
|
+
? amount
|
|
203
|
+
: convertArgs(this.tx, [amount])[0]
|
|
204
|
+
)
|
|
191
205
|
);
|
|
192
206
|
const recipientObjects = recipients.map((recipient) =>
|
|
193
|
-
convertAddressArg(this.
|
|
207
|
+
convertAddressArg(this.tx, recipient)
|
|
194
208
|
);
|
|
195
209
|
recipientObjects.forEach((address, index) => {
|
|
196
|
-
this.
|
|
210
|
+
this.tx.transferObjects([coins[index]], address);
|
|
197
211
|
});
|
|
198
212
|
return this;
|
|
199
213
|
}
|
|
200
214
|
|
|
201
|
-
transferSui(address: SuiAddressArg, amount: SuiTxArg) {
|
|
215
|
+
transferSui(address: SuiAddressArg, amount: SuiTxArg | number | bigint) {
|
|
202
216
|
return this.transferSuiToMany([address], [amount]);
|
|
203
217
|
}
|
|
204
218
|
|
|
205
|
-
takeAmountFromCoins(
|
|
206
|
-
|
|
219
|
+
takeAmountFromCoins(
|
|
220
|
+
coins: SuiObjectArg[],
|
|
221
|
+
amount: SuiTxArg | number | bigint
|
|
222
|
+
) {
|
|
223
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
207
224
|
const mergedCoin = coinObjects[0];
|
|
208
225
|
if (coins.length > 1) {
|
|
209
|
-
this.
|
|
226
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
210
227
|
}
|
|
211
|
-
const [sendCoin] = this.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
228
|
+
const [sendCoin] = this.tx.splitCoins(mergedCoin, [
|
|
229
|
+
typeof amount === 'number' || typeof amount === 'bigint'
|
|
230
|
+
? amount
|
|
231
|
+
: convertArgs(this.tx, [amount])[0],
|
|
232
|
+
]);
|
|
215
233
|
return [sendCoin, mergedCoin];
|
|
216
234
|
}
|
|
217
235
|
|
|
218
236
|
splitSUIFromGas(amounts: SuiTxArg[]) {
|
|
219
|
-
return this.
|
|
220
|
-
this.txBlock.gas,
|
|
221
|
-
convertArgs(this.txBlock, amounts)
|
|
222
|
-
);
|
|
237
|
+
return this.tx.splitCoins(this.tx.gas, convertArgs(this.tx, amounts));
|
|
223
238
|
}
|
|
224
239
|
|
|
225
|
-
splitMultiCoins(coins: SuiObjectArg[], amounts:
|
|
226
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
240
|
+
splitMultiCoins(coins: SuiObjectArg[], amounts: SuiAmountsArg[]) {
|
|
241
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
227
242
|
const mergedCoin = coinObjects[0];
|
|
228
243
|
if (coins.length > 1) {
|
|
229
|
-
this.
|
|
244
|
+
this.tx.mergeCoins(mergedCoin, coinObjects.slice(1));
|
|
230
245
|
}
|
|
231
|
-
const splitedCoins = this.
|
|
246
|
+
const splitedCoins = this.tx.splitCoins(
|
|
232
247
|
mergedCoin,
|
|
233
|
-
|
|
248
|
+
convertAmounts(this.tx, amounts)
|
|
234
249
|
);
|
|
235
250
|
return { splitedCoins, mergedCoin };
|
|
236
251
|
}
|
|
@@ -239,7 +254,7 @@ export class SuiTxBlock {
|
|
|
239
254
|
coins: SuiObjectArg[],
|
|
240
255
|
sender: SuiAddressArg,
|
|
241
256
|
recipients: SuiAddressArg[],
|
|
242
|
-
amounts:
|
|
257
|
+
amounts: SuiAmountsArg[]
|
|
243
258
|
) {
|
|
244
259
|
// require recipients.length === amounts.length
|
|
245
260
|
if (recipients.length !== amounts.length) {
|
|
@@ -247,21 +262,18 @@ export class SuiTxBlock {
|
|
|
247
262
|
'transferSuiToMany: recipients.length !== amounts.length'
|
|
248
263
|
);
|
|
249
264
|
}
|
|
250
|
-
const coinObjects = coins.map((coin) => convertObjArg(this.
|
|
265
|
+
const coinObjects = coins.map((coin) => convertObjArg(this.tx, coin));
|
|
251
266
|
const { splitedCoins, mergedCoin } = this.splitMultiCoins(
|
|
252
267
|
coinObjects,
|
|
253
268
|
amounts
|
|
254
269
|
);
|
|
255
270
|
const recipientObjects = recipients.map((recipient) =>
|
|
256
|
-
convertAddressArg(this.
|
|
271
|
+
convertAddressArg(this.tx, recipient)
|
|
257
272
|
);
|
|
258
273
|
recipientObjects.forEach((address, index) => {
|
|
259
|
-
this.
|
|
274
|
+
this.tx.transferObjects([splitedCoins[index]], address);
|
|
260
275
|
});
|
|
261
|
-
this.
|
|
262
|
-
[mergedCoin],
|
|
263
|
-
convertAddressArg(this.txBlock, sender)
|
|
264
|
-
);
|
|
276
|
+
this.tx.transferObjects([mergedCoin], convertAddressArg(this.tx, sender));
|
|
265
277
|
return this;
|
|
266
278
|
}
|
|
267
279
|
|
|
@@ -274,17 +286,17 @@ export class SuiTxBlock {
|
|
|
274
286
|
return this.transferCoinToMany(coins, sender, [recipient], [amount]);
|
|
275
287
|
}
|
|
276
288
|
|
|
277
|
-
stakeSui(amount: SuiTxArg, validatorAddr: SuiAddressArg) {
|
|
278
|
-
const [stakeCoin] = this.
|
|
279
|
-
this.
|
|
280
|
-
|
|
289
|
+
stakeSui(amount: SuiTxArg | number | bigint, validatorAddr: SuiAddressArg) {
|
|
290
|
+
const [stakeCoin] = this.tx.splitCoins(
|
|
291
|
+
this.tx.gas,
|
|
292
|
+
convertAmounts(this.tx, [amount])
|
|
281
293
|
);
|
|
282
|
-
return this.
|
|
294
|
+
return this.tx.moveCall({
|
|
283
295
|
target: '0x3::sui_system::request_add_stake',
|
|
284
|
-
arguments: convertArgs(this.
|
|
285
|
-
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
296
|
+
arguments: convertArgs(this.tx, [
|
|
297
|
+
this.tx.object(SUI_SYSTEM_STATE_OBJECT_ID),
|
|
286
298
|
stakeCoin,
|
|
287
|
-
this.
|
|
299
|
+
convertAddressArg(this.tx, validatorAddr),
|
|
288
300
|
]),
|
|
289
301
|
});
|
|
290
302
|
}
|
|
@@ -3,26 +3,25 @@ import {
|
|
|
3
3
|
normalizeSuiAddress,
|
|
4
4
|
isValidSuiObjectId,
|
|
5
5
|
isValidSuiAddress,
|
|
6
|
-
} from '@mysten/sui
|
|
7
|
-
import { Inputs } from '@mysten/sui
|
|
8
|
-
import {
|
|
9
|
-
import { isSerializedBcs } from '@mysten/bcs';
|
|
6
|
+
} from '@mysten/sui/utils';
|
|
7
|
+
import { Inputs, getPureBcsSchema } from '@mysten/sui/transactions';
|
|
8
|
+
import { SerializedBcs, bcs, isSerializedBcs } from '@mysten/bcs';
|
|
10
9
|
import type {
|
|
11
10
|
TransactionArgument,
|
|
12
|
-
|
|
11
|
+
Transaction,
|
|
13
12
|
TransactionObjectArgument,
|
|
14
|
-
} from '@mysten/sui
|
|
13
|
+
} from '@mysten/sui/transactions';
|
|
15
14
|
import type {
|
|
16
|
-
SuiInputTypes,
|
|
17
15
|
SuiObjectArg,
|
|
18
16
|
SuiAddressArg,
|
|
19
17
|
SuiTxArg,
|
|
20
18
|
SuiVecTxArg,
|
|
21
|
-
|
|
19
|
+
SuiInputTypes,
|
|
20
|
+
} from 'src/types';
|
|
22
21
|
|
|
23
22
|
export const getDefaultSuiInputType = (
|
|
24
23
|
value: SuiTxArg
|
|
25
|
-
):
|
|
24
|
+
): 'u64' | 'bool' | 'object' | undefined => {
|
|
26
25
|
if (typeof value === 'string' && isValidSuiObjectId(value)) {
|
|
27
26
|
return 'object';
|
|
28
27
|
} else if (typeof value === 'number' || typeof value === 'bigint') {
|
|
@@ -48,7 +47,7 @@ export const getDefaultSuiInputType = (
|
|
|
48
47
|
* @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer' | 'object' | string
|
|
49
48
|
*/
|
|
50
49
|
export function makeVecParam(
|
|
51
|
-
txBlock:
|
|
50
|
+
txBlock: Transaction,
|
|
52
51
|
args: SuiTxArg[],
|
|
53
52
|
type?: SuiInputTypes
|
|
54
53
|
): TransactionArgument {
|
|
@@ -62,23 +61,24 @@ export function makeVecParam(
|
|
|
62
61
|
type = type || defaultSuiType;
|
|
63
62
|
|
|
64
63
|
if (type === 'object') {
|
|
65
|
-
const
|
|
64
|
+
const elements = args.map((arg) =>
|
|
66
65
|
typeof arg === 'string' && isValidSuiObjectId(arg)
|
|
67
66
|
? txBlock.object(normalizeSuiObjectId(arg))
|
|
68
67
|
: convertObjArg(txBlock, arg as SuiObjectArg)
|
|
69
68
|
);
|
|
70
|
-
return txBlock.makeMoveVec({
|
|
69
|
+
return txBlock.makeMoveVec({ elements });
|
|
71
70
|
} else if (
|
|
72
71
|
typeof type === 'string' &&
|
|
73
72
|
!VECTOR_REGEX.test(type) &&
|
|
74
73
|
!STRUCT_REGEX.test(type)
|
|
75
74
|
) {
|
|
76
|
-
|
|
75
|
+
const bcsSchema = getPureBcsSchema(type)!;
|
|
76
|
+
return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
|
|
77
77
|
} else {
|
|
78
|
-
const
|
|
78
|
+
const elements = args.map((arg) =>
|
|
79
79
|
convertObjArg(txBlock, arg as SuiObjectArg)
|
|
80
80
|
);
|
|
81
|
-
return txBlock.makeMoveVec({
|
|
81
|
+
return txBlock.makeMoveVec({ elements, type });
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -105,29 +105,22 @@ export function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
|
|
|
105
105
|
* @returns The converted array of TransactionArgument.
|
|
106
106
|
*/
|
|
107
107
|
export function convertArgs(
|
|
108
|
-
txBlock:
|
|
108
|
+
txBlock: Transaction,
|
|
109
109
|
args: (SuiTxArg | SuiVecTxArg)[]
|
|
110
|
-
) {
|
|
110
|
+
): TransactionArgument[] {
|
|
111
111
|
return args.map((arg) => {
|
|
112
|
-
if (
|
|
113
|
-
return txBlock.
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
!isPureArg(arg) &&
|
|
118
|
-
!isMoveVecArg(arg)
|
|
119
|
-
) {
|
|
120
|
-
return convertObjArg(txBlock, arg as SuiObjectArg);
|
|
121
|
-
} else if (isMoveVecArg(arg)) {
|
|
112
|
+
if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
|
|
113
|
+
return txBlock.pure(arg);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isMoveVecArg(arg)) {
|
|
122
117
|
const vecType = 'vecType' in arg;
|
|
123
118
|
return vecType
|
|
124
119
|
? makeVecParam(txBlock, arg.value, arg.vecType)
|
|
125
120
|
: makeVecParam(txBlock, arg);
|
|
126
|
-
} else if (isSerializedBcs(arg)) {
|
|
127
|
-
return arg;
|
|
128
|
-
} else {
|
|
129
|
-
return txBlock.pure(arg);
|
|
130
121
|
}
|
|
122
|
+
|
|
123
|
+
return arg;
|
|
131
124
|
});
|
|
132
125
|
}
|
|
133
126
|
|
|
@@ -139,21 +132,13 @@ export function convertArgs(
|
|
|
139
132
|
* @returns The converted TransactionArgument.
|
|
140
133
|
*/
|
|
141
134
|
export function convertAddressArg(
|
|
142
|
-
txBlock:
|
|
135
|
+
txBlock: Transaction,
|
|
143
136
|
arg: SuiAddressArg
|
|
144
|
-
) {
|
|
137
|
+
): TransactionArgument {
|
|
145
138
|
if (typeof arg === 'string' && isValidSuiAddress(arg)) {
|
|
146
139
|
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
140
|
} else {
|
|
156
|
-
return arg;
|
|
141
|
+
return convertArgs(txBlock, [arg])[0];
|
|
157
142
|
}
|
|
158
143
|
}
|
|
159
144
|
|
|
@@ -165,7 +150,7 @@ export function convertAddressArg(
|
|
|
165
150
|
* @returns The converted TransactionArgument.
|
|
166
151
|
*/
|
|
167
152
|
export function convertObjArg(
|
|
168
|
-
txb:
|
|
153
|
+
txb: Transaction,
|
|
169
154
|
arg: SuiObjectArg
|
|
170
155
|
): TransactionObjectArgument {
|
|
171
156
|
if (typeof arg === 'string') {
|
|
@@ -181,18 +166,40 @@ export function convertObjArg(
|
|
|
181
166
|
}
|
|
182
167
|
|
|
183
168
|
if ('Object' in arg) {
|
|
184
|
-
if ('
|
|
185
|
-
return txb.object(Inputs.ObjectRef(arg.Object.
|
|
186
|
-
} else if ('
|
|
187
|
-
return txb.object(Inputs.SharedObjectRef(arg.Object.
|
|
169
|
+
if ('ImmOrOwnedObject' in arg.Object) {
|
|
170
|
+
return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
|
|
171
|
+
} else if ('SharedObject' in arg.Object) {
|
|
172
|
+
return txb.object(Inputs.SharedObjectRef(arg.Object.SharedObject));
|
|
188
173
|
} else {
|
|
189
174
|
throw new Error('Invalid argument type');
|
|
190
175
|
}
|
|
191
176
|
}
|
|
192
177
|
|
|
193
|
-
if ('
|
|
178
|
+
if (typeof arg === 'function') {
|
|
179
|
+
return arg;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (
|
|
183
|
+
'GasCoin' in arg ||
|
|
184
|
+
'Input' in arg ||
|
|
185
|
+
'Result' in arg ||
|
|
186
|
+
'NestedResult' in arg
|
|
187
|
+
) {
|
|
194
188
|
return arg;
|
|
195
189
|
}
|
|
196
190
|
|
|
197
191
|
throw new Error('Invalid argument type');
|
|
198
192
|
}
|
|
193
|
+
|
|
194
|
+
export function convertAmounts(
|
|
195
|
+
txBlock: Transaction,
|
|
196
|
+
amounts: (SuiTxArg | number | bigint)[]
|
|
197
|
+
): (TransactionArgument | number | bigint)[] {
|
|
198
|
+
return amounts.map((amount) => {
|
|
199
|
+
if (typeof amount === 'number' || typeof amount === 'bigint') {
|
|
200
|
+
return amount;
|
|
201
|
+
} else {
|
|
202
|
+
return convertArgs(txBlock, [amount])[0];
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
package/src/metadata/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { SuiMoveNormalizedModules } from '@mysten/sui
|
|
2
|
-
import { getFullnodeUrl } from '@mysten/sui
|
|
1
|
+
import { SuiMoveNormalizedModules } from '@mysten/sui/client';
|
|
2
|
+
import { getFullnodeUrl } from '@mysten/sui/client';
|
|
3
3
|
|
|
4
4
|
import { SuiInteractor } from '../libs/suiInteractor';
|
|
5
|
-
|
|
6
5
|
import { NetworkType } from '../types';
|
|
7
6
|
|
|
8
7
|
export async function loadMetadata(
|