@0xobelisk/sui-client 0.5.18 → 0.5.20
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 +15 -0
- package/dist/index.js +340 -233
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +337 -230
- package/dist/index.mjs.map +1 -1
- package/dist/libs/multiSig/client.d.ts +15 -0
- package/dist/libs/multiSig/index.d.ts +1 -0
- package/dist/libs/multiSig/publickey.d.ts +2 -0
- package/dist/libs/suiAccountManager/crypto.d.ts +1 -0
- package/dist/libs/suiAccountManager/index.d.ts +39 -0
- package/dist/libs/suiAccountManager/keypair.d.ts +21 -0
- package/dist/libs/suiAccountManager/util.d.ts +29 -0
- package/dist/libs/suiContractFactory/index.d.ts +20 -0
- package/dist/libs/suiContractFactory/types.d.ts +49 -0
- package/dist/libs/suiInteractor/index.d.ts +1 -0
- package/dist/libs/suiInteractor/suiInteractor.d.ts +50 -0
- package/dist/libs/suiInteractor/util.d.ts +1 -0
- package/dist/libs/suiModel/index.d.ts +2 -0
- package/dist/libs/suiModel/suiOwnedObject.d.ts +24 -0
- package/dist/libs/suiModel/suiSharedObject.d.ts +11 -0
- package/dist/libs/suiTxBuilder/index.d.ts +538 -0
- package/dist/libs/suiTxBuilder/util.d.ts +49 -0
- package/dist/metadata/index.d.ts +3 -0
- package/dist/obelisk.d.ts +140 -0
- package/dist/types/index.d.ts +199 -0
- package/dist/utils/index.d.ts +3 -0
- package/package.json +2 -5
- package/src/libs/multiSig/client.ts +1 -1
- package/src/libs/suiAccountManager/index.ts +4 -5
- package/src/libs/suiInteractor/index.ts +0 -1
- package/src/libs/suiModel/suiOwnedObject.ts +2 -2
- package/src/libs/suiModel/suiSharedObject.ts +2 -2
- package/src/libs/suiTxBuilder/index.ts +43 -49
- package/src/libs/suiTxBuilder/util.ts +65 -129
- package/src/obelisk.ts +329 -139
- package/src/types/index.ts +60 -44
|
@@ -4,26 +4,24 @@ import {
|
|
|
4
4
|
isValidSuiObjectId,
|
|
5
5
|
isValidSuiAddress,
|
|
6
6
|
} from '@mysten/sui/utils';
|
|
7
|
-
import { Inputs } from '@mysten/sui/transactions';
|
|
8
|
-
import {
|
|
7
|
+
import { Inputs, getPureBcsSchema } from '@mysten/sui/transactions';
|
|
8
|
+
import { SerializedBcs, bcs, isSerializedBcs } from '@mysten/bcs';
|
|
9
9
|
import type {
|
|
10
10
|
TransactionArgument,
|
|
11
11
|
Transaction,
|
|
12
12
|
TransactionObjectArgument,
|
|
13
13
|
} from '@mysten/sui/transactions';
|
|
14
|
-
import { bcs } from '@mysten/sui/bcs';
|
|
15
14
|
import type {
|
|
16
|
-
SuiInputTypes,
|
|
17
15
|
SuiObjectArg,
|
|
18
16
|
SuiAddressArg,
|
|
19
17
|
SuiTxArg,
|
|
20
18
|
SuiVecTxArg,
|
|
21
|
-
|
|
22
|
-
} from '
|
|
23
|
-
|
|
19
|
+
SuiInputTypes,
|
|
20
|
+
} from 'src/types';
|
|
21
|
+
|
|
24
22
|
export const getDefaultSuiInputType = (
|
|
25
23
|
value: SuiTxArg
|
|
26
|
-
):
|
|
24
|
+
): 'u64' | 'bool' | 'object' | undefined => {
|
|
27
25
|
if (typeof value === 'string' && isValidSuiObjectId(value)) {
|
|
28
26
|
return 'object';
|
|
29
27
|
} else if (typeof value === 'number' || typeof value === 'bigint') {
|
|
@@ -35,15 +33,6 @@ export const getDefaultSuiInputType = (
|
|
|
35
33
|
}
|
|
36
34
|
};
|
|
37
35
|
|
|
38
|
-
/**
|
|
39
|
-
* A pure argument.
|
|
40
|
-
*/
|
|
41
|
-
export type PureArg = { Pure: Array<number> };
|
|
42
|
-
|
|
43
|
-
export function isPureArg(arg: any): arg is PureArg {
|
|
44
|
-
return (arg as PureArg).Pure !== undefined;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
36
|
/**
|
|
48
37
|
* Since we know the elements in the array are the same type
|
|
49
38
|
* If type is not provided, we will try to infer the type from the first element
|
|
@@ -58,7 +47,7 @@ export function isPureArg(arg: any): arg is PureArg {
|
|
|
58
47
|
* @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer' | 'object' | string
|
|
59
48
|
*/
|
|
60
49
|
export function makeVecParam(
|
|
61
|
-
|
|
50
|
+
txBlock: Transaction,
|
|
62
51
|
args: SuiTxArg[],
|
|
63
52
|
type?: SuiInputTypes
|
|
64
53
|
): TransactionArgument {
|
|
@@ -74,38 +63,22 @@ export function makeVecParam(
|
|
|
74
63
|
if (type === 'object') {
|
|
75
64
|
const elements = args.map((arg) =>
|
|
76
65
|
typeof arg === 'string' && isValidSuiObjectId(arg)
|
|
77
|
-
?
|
|
78
|
-
: convertObjArg(
|
|
66
|
+
? txBlock.object(normalizeSuiObjectId(arg))
|
|
67
|
+
: convertObjArg(txBlock, arg as SuiObjectArg)
|
|
79
68
|
);
|
|
80
|
-
return
|
|
69
|
+
return txBlock.makeMoveVec({ elements });
|
|
81
70
|
} else if (
|
|
82
71
|
typeof type === 'string' &&
|
|
83
72
|
!VECTOR_REGEX.test(type) &&
|
|
84
73
|
!STRUCT_REGEX.test(type)
|
|
85
74
|
) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} else if (type === 'bool') {
|
|
89
|
-
return tx.pure(bcs.vector(bcs.Bool).serialize(args as boolean[]));
|
|
90
|
-
} else if (type === 'u8') {
|
|
91
|
-
return tx.pure(bcs.vector(bcs.U8).serialize(args as number[]));
|
|
92
|
-
} else if (type === 'u16') {
|
|
93
|
-
return tx.pure(bcs.vector(bcs.U16).serialize(args as number[]));
|
|
94
|
-
} else if (type === 'u32') {
|
|
95
|
-
return tx.pure(bcs.vector(bcs.U32).serialize(args as number[]));
|
|
96
|
-
} else if (type === 'u64') {
|
|
97
|
-
return tx.pure(bcs.vector(bcs.U64).serialize(args as string[]));
|
|
98
|
-
} else if (type === 'u128') {
|
|
99
|
-
return tx.pure(bcs.vector(bcs.U128).serialize(args as string[]));
|
|
100
|
-
} else if (type === 'u256') {
|
|
101
|
-
return tx.pure(bcs.vector(bcs.U256).serialize(args as string[]));
|
|
102
|
-
} else {
|
|
103
|
-
return tx.pure(bcs.vector(bcs.U8).serialize(args as number[]));
|
|
104
|
-
}
|
|
105
|
-
// return tx.pure(args, `vector<${type}>`);
|
|
75
|
+
const bcsSchema = getPureBcsSchema(type)!;
|
|
76
|
+
return txBlock.pure(bcs.vector(bcsSchema).serialize(args));
|
|
106
77
|
} else {
|
|
107
|
-
const elements = args.map((arg) =>
|
|
108
|
-
|
|
78
|
+
const elements = args.map((arg) =>
|
|
79
|
+
convertObjArg(txBlock, arg as SuiObjectArg)
|
|
80
|
+
);
|
|
81
|
+
return txBlock.makeMoveVec({ elements, type });
|
|
109
82
|
}
|
|
110
83
|
}
|
|
111
84
|
|
|
@@ -131,68 +104,26 @@ export function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
|
|
|
131
104
|
* @param args The array of argument to convert.
|
|
132
105
|
* @returns The converted array of TransactionArgument.
|
|
133
106
|
*/
|
|
134
|
-
export function convertArgs(
|
|
107
|
+
export function convertArgs(
|
|
108
|
+
txBlock: Transaction,
|
|
109
|
+
args: (SuiTxArg | SuiVecTxArg)[]
|
|
110
|
+
): TransactionArgument[] {
|
|
135
111
|
return args.map((arg) => {
|
|
136
|
-
if (
|
|
137
|
-
return
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
!isPureArg(arg) &&
|
|
142
|
-
!isMoveVecArg(arg)
|
|
143
|
-
) {
|
|
144
|
-
return convertObjArg(tx, arg as SuiObjectArg);
|
|
145
|
-
} else if (isMoveVecArg(arg)) {
|
|
112
|
+
if (arg instanceof SerializedBcs || isSerializedBcs(arg)) {
|
|
113
|
+
return txBlock.pure(arg);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (isMoveVecArg(arg)) {
|
|
146
117
|
const vecType = 'vecType' in arg;
|
|
147
118
|
return vecType
|
|
148
|
-
? makeVecParam(
|
|
149
|
-
: makeVecParam(
|
|
150
|
-
} else if (isSerializedBcs(arg)) {
|
|
151
|
-
return arg;
|
|
152
|
-
} else {
|
|
153
|
-
let argType = getDefaultSuiInputType(arg);
|
|
154
|
-
if (argType === 'address') {
|
|
155
|
-
return tx.pure.address(arg as string);
|
|
156
|
-
} else if (argType === 'u64') {
|
|
157
|
-
return tx.pure.u64(arg as string);
|
|
158
|
-
} else if (argType === 'bool') {
|
|
159
|
-
return tx.pure.bool(arg as boolean);
|
|
160
|
-
} else {
|
|
161
|
-
return tx.pure.u64(arg as string);
|
|
162
|
-
}
|
|
119
|
+
? makeVecParam(txBlock, arg.value, arg.vecType)
|
|
120
|
+
: makeVecParam(txBlock, arg);
|
|
163
121
|
}
|
|
122
|
+
|
|
123
|
+
return arg;
|
|
164
124
|
});
|
|
165
125
|
}
|
|
166
126
|
|
|
167
|
-
// /**
|
|
168
|
-
// * Convert any valid input into array of TransactionArgument.
|
|
169
|
-
// *
|
|
170
|
-
// * @param txb The Transaction Block
|
|
171
|
-
// * @param args The array of argument to convert.z
|
|
172
|
-
// * @returns The converted array of TransactionArgument.
|
|
173
|
-
// */
|
|
174
|
-
// export function convertReturnValue(values: DryTxReturnValues) {
|
|
175
|
-
// return values.map(([value, type]) => {
|
|
176
|
-
// if (type === 'address') {
|
|
177
|
-
// return tx.pure.address(value);
|
|
178
|
-
// } else if (type === 'bool') {
|
|
179
|
-
// return tx.pure.bool(value);
|
|
180
|
-
// } else if (type === 'u8') {
|
|
181
|
-
// return tx.pure(bcs.vector(bcs.U8).serialize(args));
|
|
182
|
-
// } else if (type === 'u16') {
|
|
183
|
-
// return tx.pure(bcs.vector(bcs.U16).serialize(args));
|
|
184
|
-
// } else if (type === 'u32') {
|
|
185
|
-
// return tx.pure(bcs.vector(bcs.U32).serialize(args));
|
|
186
|
-
// } else if (type === 'u64') {
|
|
187
|
-
// return tx.pure(bcs.vector(bcs.U64).serialize(args));
|
|
188
|
-
// } else if (type === 'u128') {
|
|
189
|
-
// return tx.pure(bcs.vector(bcs.U128).serialize(args));
|
|
190
|
-
// } else if (type === 'u256') {
|
|
191
|
-
// return tx.pure(bcs.vector(bcs.U256).serialize(args));
|
|
192
|
-
// }
|
|
193
|
-
// });
|
|
194
|
-
// }
|
|
195
|
-
|
|
196
127
|
/**
|
|
197
128
|
* Convert any valid address input into a TransactionArgument.
|
|
198
129
|
*
|
|
@@ -200,70 +131,75 @@ export function convertArgs(tx: Transaction, args: (SuiTxArg | SuiVecTxArg)[]) {
|
|
|
200
131
|
* @param arg The address argument to convert.
|
|
201
132
|
* @returns The converted TransactionArgument.
|
|
202
133
|
*/
|
|
203
|
-
export function convertAddressArg(
|
|
134
|
+
export function convertAddressArg(
|
|
135
|
+
txBlock: Transaction,
|
|
136
|
+
arg: SuiAddressArg
|
|
137
|
+
): TransactionArgument {
|
|
204
138
|
if (typeof arg === 'string' && isValidSuiAddress(arg)) {
|
|
205
|
-
return
|
|
206
|
-
} else if (
|
|
207
|
-
typeof arg == 'object' &&
|
|
208
|
-
!isSerializedBcs(arg) &&
|
|
209
|
-
!isPureArg(arg)
|
|
210
|
-
) {
|
|
211
|
-
return convertObjArg(tx, arg as SuiObjectArg);
|
|
212
|
-
} else if (isPureArg(arg)) {
|
|
213
|
-
return tx.pure(Uint8Array.from(arg.Pure));
|
|
139
|
+
return txBlock.pure.address(normalizeSuiAddress(arg));
|
|
214
140
|
} else {
|
|
215
|
-
return arg;
|
|
141
|
+
return convertArgs(txBlock, [arg])[0];
|
|
216
142
|
}
|
|
217
143
|
}
|
|
218
144
|
|
|
219
145
|
/**
|
|
220
146
|
* Convert any valid object input into a TransactionArgument.
|
|
221
147
|
*
|
|
222
|
-
* @param
|
|
148
|
+
* @param txb The Transaction Block
|
|
223
149
|
* @param arg The object argument to convert.
|
|
224
150
|
* @returns The converted TransactionArgument.
|
|
225
151
|
*/
|
|
226
152
|
export function convertObjArg(
|
|
227
|
-
|
|
153
|
+
txb: Transaction,
|
|
228
154
|
arg: SuiObjectArg
|
|
229
155
|
): TransactionObjectArgument {
|
|
230
156
|
if (typeof arg === 'string') {
|
|
231
|
-
return
|
|
157
|
+
return txb.object(arg);
|
|
232
158
|
}
|
|
233
159
|
|
|
234
160
|
if ('digest' in arg && 'version' in arg && 'objectId' in arg) {
|
|
235
|
-
return
|
|
161
|
+
return txb.objectRef(arg);
|
|
236
162
|
}
|
|
237
163
|
|
|
238
164
|
if ('objectId' in arg && 'initialSharedVersion' in arg && 'mutable' in arg) {
|
|
239
|
-
return
|
|
165
|
+
return txb.sharedObjectRef(arg);
|
|
240
166
|
}
|
|
241
167
|
|
|
242
168
|
if ('Object' in arg) {
|
|
243
169
|
if ('ImmOrOwnedObject' in arg.Object) {
|
|
244
|
-
return
|
|
245
|
-
Inputs.ObjectRef(arg.Object.ImmOrOwnedObject as ObjectRef)
|
|
246
|
-
);
|
|
170
|
+
return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwnedObject));
|
|
247
171
|
} else if ('SharedObject' in arg.Object) {
|
|
248
|
-
return
|
|
249
|
-
Inputs.SharedObjectRef(
|
|
250
|
-
arg.Object.SharedObject as {
|
|
251
|
-
objectId: string;
|
|
252
|
-
mutable: boolean;
|
|
253
|
-
initialSharedVersion: number | string;
|
|
254
|
-
}
|
|
255
|
-
)
|
|
256
|
-
);
|
|
257
|
-
} else if ('Receiving' in arg.Object) {
|
|
258
|
-
return tx.object(Inputs.ReceivingRef(arg.Object.Receiving as ObjectRef));
|
|
172
|
+
return txb.object(Inputs.SharedObjectRef(arg.Object.SharedObject));
|
|
259
173
|
} else {
|
|
260
174
|
throw new Error('Invalid argument type');
|
|
261
175
|
}
|
|
262
176
|
}
|
|
263
177
|
|
|
264
|
-
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
|
+
) {
|
|
265
188
|
return arg;
|
|
266
189
|
}
|
|
267
190
|
|
|
268
191
|
throw new Error('Invalid argument type');
|
|
269
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
|
+
}
|