@exodus/sui-api 1.0.0 → 1.0.2
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/CHANGELOG.md +18 -0
- package/package.json +3 -3
- package/src/vendors/client/client.js +2 -68
- package/src/vendors/client/errors.js +1 -1
- package/src/vendors/client/http-transport.js +0 -37
- package/src/vendors/experimental/core.js +0 -82
- package/src/vendors/experimental/mvr.js +1 -1
- package/src/vendors/experimental/transports/jsonRPC.js +0 -398
- package/src/vendors/transactions/Commands.js +1 -7
- package/src/vendors/transactions/Transaction.js +0 -14
- package/src/vendors/transactions/data/internal.js +0 -14
- package/src/vendors/transactions/data/v1.js +2 -293
- package/src/vendors/transactions/plugins/NamedPackagesPlugin.js +1 -1
- package/src/vendors/transactions/resolve.js +1 -1
- package/src/vendors/transactions/utils.js +1 -38
- package/src/vendors/valibot.js +357 -7310
- package/src/vendors/client/rpc-websocket-client.js +0 -178
- package/src/vendors/experimental/errors.js +0 -32
- package/src/vendors/experimental/index.js +0 -5
- package/src/vendors/experimental/transports/utils.js +0 -90
- package/src/vendors/transactions/Arguments.js +0 -22
- package/src/vendors/transactions/ObjectCache.js +0 -272
|
@@ -4,25 +4,21 @@ import {
|
|
|
4
4
|
array,
|
|
5
5
|
bigint,
|
|
6
6
|
boolean,
|
|
7
|
-
check,
|
|
8
7
|
integer,
|
|
9
8
|
is,
|
|
10
9
|
lazy,
|
|
11
10
|
literal,
|
|
12
11
|
nullable,
|
|
13
|
-
nullish,
|
|
14
12
|
number,
|
|
15
13
|
object,
|
|
16
|
-
optional,
|
|
17
14
|
parse,
|
|
18
15
|
pipe,
|
|
19
16
|
string,
|
|
20
17
|
union,
|
|
21
|
-
unknown,
|
|
22
18
|
} from '../../valibot.js'
|
|
23
19
|
import { JsonU64, ObjectID, safeEnum, TransactionData } from './internal.js'
|
|
24
20
|
|
|
25
|
-
const {
|
|
21
|
+
const { toBase64 } = vendorLib.utils
|
|
26
22
|
const { TypeTagSerializer } = vendorLib.bcs
|
|
27
23
|
|
|
28
24
|
const ObjectRef = object({
|
|
@@ -43,36 +39,6 @@ const NormalizedCallArg = safeEnum({
|
|
|
43
39
|
Object: ObjectArg,
|
|
44
40
|
Pure: array(pipe(number(), integer())),
|
|
45
41
|
})
|
|
46
|
-
const TransactionInput = union([
|
|
47
|
-
object({
|
|
48
|
-
kind: literal('Input'),
|
|
49
|
-
index: pipe(number(), integer()),
|
|
50
|
-
value: unknown(),
|
|
51
|
-
type: optional(literal('object')),
|
|
52
|
-
}),
|
|
53
|
-
object({
|
|
54
|
-
kind: literal('Input'),
|
|
55
|
-
index: pipe(number(), integer()),
|
|
56
|
-
value: unknown(),
|
|
57
|
-
type: literal('pure'),
|
|
58
|
-
}),
|
|
59
|
-
])
|
|
60
|
-
const TransactionExpiration = union([
|
|
61
|
-
object({ Epoch: pipe(number(), integer()) }),
|
|
62
|
-
object({ None: nullable(literal(true)) }),
|
|
63
|
-
])
|
|
64
|
-
const StringEncodedBigint = pipe(
|
|
65
|
-
union([number(), string(), bigint()]),
|
|
66
|
-
check((val) => {
|
|
67
|
-
if (!['string', 'number', 'bigint'].includes(typeof val)) return false
|
|
68
|
-
try {
|
|
69
|
-
BigInt(val)
|
|
70
|
-
return true
|
|
71
|
-
} catch {
|
|
72
|
-
return false
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
)
|
|
76
42
|
const TypeTag = union([
|
|
77
43
|
object({ bool: nullable(literal(true)) }),
|
|
78
44
|
object({ u8: nullable(literal(true)) }),
|
|
@@ -92,254 +58,6 @@ const StructTag = object({
|
|
|
92
58
|
name: string(),
|
|
93
59
|
typeParams: array(TypeTag),
|
|
94
60
|
})
|
|
95
|
-
const GasConfig = object({
|
|
96
|
-
budget: optional(StringEncodedBigint),
|
|
97
|
-
price: optional(StringEncodedBigint),
|
|
98
|
-
payment: optional(array(ObjectRef)),
|
|
99
|
-
owner: optional(string()),
|
|
100
|
-
})
|
|
101
|
-
const TransactionArgumentTypes = [
|
|
102
|
-
TransactionInput,
|
|
103
|
-
object({ kind: literal('GasCoin') }),
|
|
104
|
-
object({ kind: literal('Result'), index: pipe(number(), integer()) }),
|
|
105
|
-
object({
|
|
106
|
-
kind: literal('NestedResult'),
|
|
107
|
-
index: pipe(number(), integer()),
|
|
108
|
-
resultIndex: pipe(number(), integer()),
|
|
109
|
-
}),
|
|
110
|
-
]
|
|
111
|
-
const TransactionArgument = union([...TransactionArgumentTypes])
|
|
112
|
-
const MoveCallTransaction = object({
|
|
113
|
-
kind: literal('MoveCall'),
|
|
114
|
-
target: pipe(
|
|
115
|
-
string(),
|
|
116
|
-
check((target) => target.split('::').length === 3)
|
|
117
|
-
),
|
|
118
|
-
typeArguments: array(string()),
|
|
119
|
-
arguments: array(TransactionArgument),
|
|
120
|
-
})
|
|
121
|
-
const TransferObjectsTransaction = object({
|
|
122
|
-
kind: literal('TransferObjects'),
|
|
123
|
-
objects: array(TransactionArgument),
|
|
124
|
-
address: TransactionArgument,
|
|
125
|
-
})
|
|
126
|
-
const SplitCoinsTransaction = object({
|
|
127
|
-
kind: literal('SplitCoins'),
|
|
128
|
-
coin: TransactionArgument,
|
|
129
|
-
amounts: array(TransactionArgument),
|
|
130
|
-
})
|
|
131
|
-
const MergeCoinsTransaction = object({
|
|
132
|
-
kind: literal('MergeCoins'),
|
|
133
|
-
destination: TransactionArgument,
|
|
134
|
-
sources: array(TransactionArgument),
|
|
135
|
-
})
|
|
136
|
-
const MakeMoveVecTransaction = object({
|
|
137
|
-
kind: literal('MakeMoveVec'),
|
|
138
|
-
type: union([object({ Some: TypeTag }), object({ None: nullable(literal(true)) })]),
|
|
139
|
-
objects: array(TransactionArgument),
|
|
140
|
-
})
|
|
141
|
-
const PublishTransaction = object({
|
|
142
|
-
kind: literal('Publish'),
|
|
143
|
-
modules: array(array(pipe(number(), integer()))),
|
|
144
|
-
dependencies: array(string()),
|
|
145
|
-
})
|
|
146
|
-
const UpgradeTransaction = object({
|
|
147
|
-
kind: literal('Upgrade'),
|
|
148
|
-
modules: array(array(pipe(number(), integer()))),
|
|
149
|
-
dependencies: array(string()),
|
|
150
|
-
packageId: string(),
|
|
151
|
-
ticket: TransactionArgument,
|
|
152
|
-
})
|
|
153
|
-
const TransactionTypes = [
|
|
154
|
-
MoveCallTransaction,
|
|
155
|
-
TransferObjectsTransaction,
|
|
156
|
-
SplitCoinsTransaction,
|
|
157
|
-
MergeCoinsTransaction,
|
|
158
|
-
PublishTransaction,
|
|
159
|
-
UpgradeTransaction,
|
|
160
|
-
MakeMoveVecTransaction,
|
|
161
|
-
]
|
|
162
|
-
const TransactionType = union([...TransactionTypes])
|
|
163
|
-
const SerializedTransactionDataV1 = object({
|
|
164
|
-
version: literal(1),
|
|
165
|
-
sender: optional(string()),
|
|
166
|
-
expiration: nullish(TransactionExpiration),
|
|
167
|
-
gasConfig: GasConfig,
|
|
168
|
-
inputs: array(TransactionInput),
|
|
169
|
-
transactions: array(TransactionType),
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
function serializeV1TransactionData(transactionData) {
|
|
173
|
-
const inputs = transactionData.inputs.map((input, index) => {
|
|
174
|
-
if (input.Object) {
|
|
175
|
-
return {
|
|
176
|
-
kind: 'Input',
|
|
177
|
-
index,
|
|
178
|
-
value: {
|
|
179
|
-
Object: input.Object.ImmOrOwnedObject
|
|
180
|
-
? {
|
|
181
|
-
ImmOrOwned: input.Object.ImmOrOwnedObject,
|
|
182
|
-
}
|
|
183
|
-
: input.Object.Receiving
|
|
184
|
-
? {
|
|
185
|
-
Receiving: {
|
|
186
|
-
digest: input.Object.Receiving.digest,
|
|
187
|
-
version: input.Object.Receiving.version,
|
|
188
|
-
objectId: input.Object.Receiving.objectId,
|
|
189
|
-
},
|
|
190
|
-
}
|
|
191
|
-
: {
|
|
192
|
-
Shared: {
|
|
193
|
-
mutable: input.Object.SharedObject.mutable,
|
|
194
|
-
initialSharedVersion: input.Object.SharedObject.initialSharedVersion,
|
|
195
|
-
objectId: input.Object.SharedObject.objectId,
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
type: 'object',
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (input.Pure) {
|
|
204
|
-
return {
|
|
205
|
-
kind: 'Input',
|
|
206
|
-
index,
|
|
207
|
-
value: {
|
|
208
|
-
Pure: [...fromBase64(input.Pure.bytes)],
|
|
209
|
-
},
|
|
210
|
-
type: 'pure',
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (input.UnresolvedPure) {
|
|
215
|
-
return {
|
|
216
|
-
kind: 'Input',
|
|
217
|
-
type: 'pure',
|
|
218
|
-
index,
|
|
219
|
-
value: input.UnresolvedPure.value,
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (input.UnresolvedObject) {
|
|
224
|
-
return {
|
|
225
|
-
kind: 'Input',
|
|
226
|
-
type: 'object',
|
|
227
|
-
index,
|
|
228
|
-
value: input.UnresolvedObject.objectId,
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
throw new Error('Invalid input')
|
|
233
|
-
})
|
|
234
|
-
return {
|
|
235
|
-
version: 1,
|
|
236
|
-
sender: transactionData.sender ?? void 0,
|
|
237
|
-
expiration:
|
|
238
|
-
transactionData.expiration?.$kind === 'Epoch'
|
|
239
|
-
? { Epoch: Number(transactionData.expiration.Epoch) }
|
|
240
|
-
: transactionData.expiration
|
|
241
|
-
? { None: true }
|
|
242
|
-
: null,
|
|
243
|
-
gasConfig: {
|
|
244
|
-
owner: transactionData.gasData.owner ?? void 0,
|
|
245
|
-
budget: transactionData.gasData.budget ?? void 0,
|
|
246
|
-
price: transactionData.gasData.price ?? void 0,
|
|
247
|
-
payment: transactionData.gasData.payment ?? void 0,
|
|
248
|
-
},
|
|
249
|
-
inputs,
|
|
250
|
-
transactions: transactionData.commands.map((command) => {
|
|
251
|
-
if (command.MakeMoveVec) {
|
|
252
|
-
return {
|
|
253
|
-
kind: 'MakeMoveVec',
|
|
254
|
-
type:
|
|
255
|
-
command.MakeMoveVec.type === null
|
|
256
|
-
? { None: true }
|
|
257
|
-
: { Some: TypeTagSerializer.parseFromStr(command.MakeMoveVec.type) },
|
|
258
|
-
objects: command.MakeMoveVec.elements.map((arg) =>
|
|
259
|
-
convertTransactionArgument(arg, inputs)
|
|
260
|
-
),
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (command.MergeCoins) {
|
|
265
|
-
return {
|
|
266
|
-
kind: 'MergeCoins',
|
|
267
|
-
destination: convertTransactionArgument(command.MergeCoins.destination, inputs),
|
|
268
|
-
sources: command.MergeCoins.sources.map((arg) => convertTransactionArgument(arg, inputs)),
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (command.MoveCall) {
|
|
273
|
-
return {
|
|
274
|
-
kind: 'MoveCall',
|
|
275
|
-
target: `${command.MoveCall.package}::${command.MoveCall.module}::${command.MoveCall.function}`,
|
|
276
|
-
typeArguments: command.MoveCall.typeArguments,
|
|
277
|
-
arguments: command.MoveCall.arguments.map((arg) =>
|
|
278
|
-
convertTransactionArgument(arg, inputs)
|
|
279
|
-
),
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (command.Publish) {
|
|
284
|
-
return {
|
|
285
|
-
kind: 'Publish',
|
|
286
|
-
modules: command.Publish.modules.map((mod) => [...fromBase64(mod)]),
|
|
287
|
-
dependencies: command.Publish.dependencies,
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
if (command.SplitCoins) {
|
|
292
|
-
return {
|
|
293
|
-
kind: 'SplitCoins',
|
|
294
|
-
coin: convertTransactionArgument(command.SplitCoins.coin, inputs),
|
|
295
|
-
amounts: command.SplitCoins.amounts.map((arg) => convertTransactionArgument(arg, inputs)),
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (command.TransferObjects) {
|
|
300
|
-
return {
|
|
301
|
-
kind: 'TransferObjects',
|
|
302
|
-
objects: command.TransferObjects.objects.map((arg) =>
|
|
303
|
-
convertTransactionArgument(arg, inputs)
|
|
304
|
-
),
|
|
305
|
-
address: convertTransactionArgument(command.TransferObjects.address, inputs),
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (command.Upgrade) {
|
|
310
|
-
return {
|
|
311
|
-
kind: 'Upgrade',
|
|
312
|
-
modules: command.Upgrade.modules.map((mod) => [...fromBase64(mod)]),
|
|
313
|
-
dependencies: command.Upgrade.dependencies,
|
|
314
|
-
packageId: command.Upgrade.package,
|
|
315
|
-
ticket: convertTransactionArgument(command.Upgrade.ticket, inputs),
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
throw new Error(`Unknown transaction ${Object.keys(command)}`)
|
|
320
|
-
}),
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function convertTransactionArgument(arg, inputs) {
|
|
325
|
-
if (arg.$kind === 'GasCoin') {
|
|
326
|
-
return { kind: 'GasCoin' }
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
if (arg.$kind === 'Result') {
|
|
330
|
-
return { kind: 'Result', index: arg.Result }
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (arg.$kind === 'NestedResult') {
|
|
334
|
-
return { kind: 'NestedResult', index: arg.NestedResult[0], resultIndex: arg.NestedResult[1] }
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (arg.$kind === 'Input') {
|
|
338
|
-
return inputs[arg.Input]
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
throw new Error(`Invalid argument ${Object.keys(arg)}`)
|
|
342
|
-
}
|
|
343
61
|
|
|
344
62
|
function transactionDataFromV1(data) {
|
|
345
63
|
return parse(TransactionData, {
|
|
@@ -525,14 +243,5 @@ function parseV1TransactionArgument(arg) {
|
|
|
525
243
|
}
|
|
526
244
|
}
|
|
527
245
|
|
|
528
|
-
export {
|
|
529
|
-
NormalizedCallArg,
|
|
530
|
-
ObjectRef,
|
|
531
|
-
SerializedTransactionDataV1,
|
|
532
|
-
StructTag,
|
|
533
|
-
TransactionArgument,
|
|
534
|
-
TypeTag,
|
|
535
|
-
serializeV1TransactionData,
|
|
536
|
-
transactionDataFromV1,
|
|
537
|
-
}
|
|
246
|
+
export { transactionDataFromV1 }
|
|
538
247
|
// # sourceMappingURL=v1.js.map
|
|
@@ -92,4 +92,4 @@ function normalizeRawArgument(arg, schema, transactionData) {
|
|
|
92
92
|
transactionData.inputs[arg.Input] = Inputs.Pure(schema.serialize(input.UnresolvedPure.value))
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export {
|
|
95
|
+
export { needsTransactionResolution, resolveTransactionPlugin }
|
|
@@ -1,40 +1,7 @@
|
|
|
1
1
|
import { vendorLib } from '@exodus/sui-lib'
|
|
2
2
|
|
|
3
|
-
import { is } from '../valibot.js'
|
|
4
|
-
import { Argument } from './data/internal.js'
|
|
5
|
-
|
|
6
3
|
const { normalizeSuiAddress } = vendorLib.utils
|
|
7
4
|
|
|
8
|
-
function extractMutableReference(normalizedType) {
|
|
9
|
-
return typeof normalizedType === 'object' && 'MutableReference' in normalizedType
|
|
10
|
-
? normalizedType.MutableReference
|
|
11
|
-
: void 0
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function extractReference(normalizedType) {
|
|
15
|
-
return typeof normalizedType === 'object' && 'Reference' in normalizedType
|
|
16
|
-
? normalizedType.Reference
|
|
17
|
-
: void 0
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function extractStructTag(normalizedType) {
|
|
21
|
-
if (typeof normalizedType === 'object' && 'Struct' in normalizedType) {
|
|
22
|
-
return normalizedType
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const ref = extractReference(normalizedType)
|
|
26
|
-
const mutRef = extractMutableReference(normalizedType)
|
|
27
|
-
if (typeof ref === 'object' && 'Struct' in ref) {
|
|
28
|
-
return ref
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (typeof mutRef === 'object' && 'Struct' in mutRef) {
|
|
32
|
-
return mutRef
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return void 0
|
|
36
|
-
}
|
|
37
|
-
|
|
38
5
|
function getIdFromCallArg(arg) {
|
|
39
6
|
if (typeof arg === 'string') {
|
|
40
7
|
return normalizeSuiAddress(arg)
|
|
@@ -59,9 +26,5 @@ function getIdFromCallArg(arg) {
|
|
|
59
26
|
return void 0
|
|
60
27
|
}
|
|
61
28
|
|
|
62
|
-
|
|
63
|
-
return is(Argument, value)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export { extractMutableReference, extractReference, extractStructTag, getIdFromCallArg, isArgument }
|
|
29
|
+
export { getIdFromCallArg }
|
|
67
30
|
// # sourceMappingURL=utils.js.map
|