@exodus/sui-api 0.1.0
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/README.md +20 -0
- package/package.json +53 -0
- package/src/api.js +198 -0
- package/src/balances.js +22 -0
- package/src/basic-account-state.js +11 -0
- package/src/create-unsigned-tx.js +60 -0
- package/src/get-fee-async.js +62 -0
- package/src/get-fee.js +10 -0
- package/src/index.js +9 -0
- package/src/sui-no-history-monitor.js +277 -0
- package/src/transform-tx.js +100 -0
- package/src/tx-send.js +249 -0
- package/src/vendors/client/client.js +891 -0
- package/src/vendors/client/errors.js +38 -0
- package/src/vendors/client/http-transport.js +108 -0
- package/src/vendors/client/index.js +1 -0
- package/src/vendors/client/rpc-websocket-client.js +178 -0
- package/src/vendors/experimental/cache.js +89 -0
- package/src/vendors/experimental/client.js +27 -0
- package/src/vendors/experimental/core.js +105 -0
- package/src/vendors/experimental/errors.js +32 -0
- package/src/vendors/experimental/index.js +5 -0
- package/src/vendors/experimental/mvr.js +443 -0
- package/src/vendors/experimental/transports/json-rpc-resolver.js +359 -0
- package/src/vendors/experimental/transports/jsonRPC.js +504 -0
- package/src/vendors/experimental/transports/utils.js +90 -0
- package/src/vendors/transactions/Arguments.js +22 -0
- package/src/vendors/transactions/Commands.js +108 -0
- package/src/vendors/transactions/Inputs.js +59 -0
- package/src/vendors/transactions/ObjectCache.js +272 -0
- package/src/vendors/transactions/Transaction.js +843 -0
- package/src/vendors/transactions/TransactionData.js +293 -0
- package/src/vendors/transactions/data/internal.js +218 -0
- package/src/vendors/transactions/data/v1.js +538 -0
- package/src/vendors/transactions/data/v2.js +119 -0
- package/src/vendors/transactions/hash.js +12 -0
- package/src/vendors/transactions/index.js +1 -0
- package/src/vendors/transactions/object.js +22 -0
- package/src/vendors/transactions/plugins/NamedPackagesPlugin.js +49 -0
- package/src/vendors/transactions/pure.js +40 -0
- package/src/vendors/transactions/resolve.js +95 -0
- package/src/vendors/transactions/serializer.js +203 -0
- package/src/vendors/transactions/utils.js +67 -0
- package/src/vendors/valibot.js +7920 -0
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { vendorLib } from '@exodus/sui-lib'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
array,
|
|
5
|
+
bigint,
|
|
6
|
+
boolean,
|
|
7
|
+
check,
|
|
8
|
+
integer,
|
|
9
|
+
is,
|
|
10
|
+
lazy,
|
|
11
|
+
literal,
|
|
12
|
+
nullable,
|
|
13
|
+
nullish,
|
|
14
|
+
number,
|
|
15
|
+
object,
|
|
16
|
+
optional,
|
|
17
|
+
parse,
|
|
18
|
+
pipe,
|
|
19
|
+
string,
|
|
20
|
+
union,
|
|
21
|
+
unknown,
|
|
22
|
+
} from '../../valibot.js'
|
|
23
|
+
import { JsonU64, ObjectID, safeEnum, TransactionData } from './internal.js'
|
|
24
|
+
|
|
25
|
+
const { fromBase64, toBase64 } = vendorLib.utils
|
|
26
|
+
const { TypeTagSerializer } = vendorLib.bcs
|
|
27
|
+
|
|
28
|
+
const ObjectRef = object({
|
|
29
|
+
digest: string(),
|
|
30
|
+
objectId: string(),
|
|
31
|
+
version: union([pipe(number(), integer()), string(), bigint()]),
|
|
32
|
+
})
|
|
33
|
+
const ObjectArg = safeEnum({
|
|
34
|
+
ImmOrOwned: ObjectRef,
|
|
35
|
+
Shared: object({
|
|
36
|
+
objectId: ObjectID,
|
|
37
|
+
initialSharedVersion: JsonU64,
|
|
38
|
+
mutable: boolean(),
|
|
39
|
+
}),
|
|
40
|
+
Receiving: ObjectRef,
|
|
41
|
+
})
|
|
42
|
+
const NormalizedCallArg = safeEnum({
|
|
43
|
+
Object: ObjectArg,
|
|
44
|
+
Pure: array(pipe(number(), integer())),
|
|
45
|
+
})
|
|
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
|
+
const TypeTag = union([
|
|
77
|
+
object({ bool: nullable(literal(true)) }),
|
|
78
|
+
object({ u8: nullable(literal(true)) }),
|
|
79
|
+
object({ u64: nullable(literal(true)) }),
|
|
80
|
+
object({ u128: nullable(literal(true)) }),
|
|
81
|
+
object({ address: nullable(literal(true)) }),
|
|
82
|
+
object({ signer: nullable(literal(true)) }),
|
|
83
|
+
object({ vector: lazy(() => TypeTag) }),
|
|
84
|
+
object({ struct: lazy(() => StructTag) }),
|
|
85
|
+
object({ u16: nullable(literal(true)) }),
|
|
86
|
+
object({ u32: nullable(literal(true)) }),
|
|
87
|
+
object({ u256: nullable(literal(true)) }),
|
|
88
|
+
])
|
|
89
|
+
const StructTag = object({
|
|
90
|
+
address: string(),
|
|
91
|
+
module: string(),
|
|
92
|
+
name: string(),
|
|
93
|
+
typeParams: array(TypeTag),
|
|
94
|
+
})
|
|
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
|
+
|
|
344
|
+
function transactionDataFromV1(data) {
|
|
345
|
+
return parse(TransactionData, {
|
|
346
|
+
version: 2,
|
|
347
|
+
sender: data.sender ?? null,
|
|
348
|
+
expiration: data.expiration
|
|
349
|
+
? 'Epoch' in data.expiration
|
|
350
|
+
? { Epoch: data.expiration.Epoch }
|
|
351
|
+
: { None: true }
|
|
352
|
+
: null,
|
|
353
|
+
gasData: {
|
|
354
|
+
owner: data.gasConfig.owner ?? null,
|
|
355
|
+
budget: data.gasConfig.budget?.toString() ?? null,
|
|
356
|
+
price: data.gasConfig.price?.toString() ?? null,
|
|
357
|
+
payment:
|
|
358
|
+
data.gasConfig.payment?.map((ref) => ({
|
|
359
|
+
digest: ref.digest,
|
|
360
|
+
objectId: ref.objectId,
|
|
361
|
+
version: ref.version.toString(),
|
|
362
|
+
})) ?? null,
|
|
363
|
+
},
|
|
364
|
+
inputs: data.inputs.map((input) => {
|
|
365
|
+
if (input.kind === 'Input') {
|
|
366
|
+
if (is(NormalizedCallArg, input.value)) {
|
|
367
|
+
const value = parse(NormalizedCallArg, input.value)
|
|
368
|
+
if (value.Object) {
|
|
369
|
+
if (value.Object.ImmOrOwned) {
|
|
370
|
+
return {
|
|
371
|
+
Object: {
|
|
372
|
+
ImmOrOwnedObject: {
|
|
373
|
+
objectId: value.Object.ImmOrOwned.objectId,
|
|
374
|
+
version: String(value.Object.ImmOrOwned.version),
|
|
375
|
+
digest: value.Object.ImmOrOwned.digest,
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if (value.Object.Shared) {
|
|
382
|
+
return {
|
|
383
|
+
Object: {
|
|
384
|
+
SharedObject: {
|
|
385
|
+
mutable: value.Object.Shared.mutable ?? null,
|
|
386
|
+
initialSharedVersion: value.Object.Shared.initialSharedVersion,
|
|
387
|
+
objectId: value.Object.Shared.objectId,
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (value.Object.Receiving) {
|
|
394
|
+
return {
|
|
395
|
+
Object: {
|
|
396
|
+
Receiving: {
|
|
397
|
+
digest: value.Object.Receiving.digest,
|
|
398
|
+
version: String(value.Object.Receiving.version),
|
|
399
|
+
objectId: value.Object.Receiving.objectId,
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
throw new Error('Invalid object input')
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return {
|
|
409
|
+
Pure: {
|
|
410
|
+
bytes: toBase64(new Uint8Array(value.Pure)),
|
|
411
|
+
},
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (input.type === 'object') {
|
|
416
|
+
return {
|
|
417
|
+
UnresolvedObject: {
|
|
418
|
+
objectId: input.value,
|
|
419
|
+
},
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
return {
|
|
424
|
+
UnresolvedPure: {
|
|
425
|
+
value: input.value,
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
throw new Error('Invalid input')
|
|
431
|
+
}),
|
|
432
|
+
commands: data.transactions.map((transaction) => {
|
|
433
|
+
switch (transaction.kind) {
|
|
434
|
+
case 'MakeMoveVec':
|
|
435
|
+
return {
|
|
436
|
+
MakeMoveVec: {
|
|
437
|
+
type:
|
|
438
|
+
'Some' in transaction.type
|
|
439
|
+
? TypeTagSerializer.tagToString(transaction.type.Some)
|
|
440
|
+
: null,
|
|
441
|
+
elements: transaction.objects.map((arg) => parseV1TransactionArgument(arg)),
|
|
442
|
+
},
|
|
443
|
+
}
|
|
444
|
+
case 'MergeCoins': {
|
|
445
|
+
return {
|
|
446
|
+
MergeCoins: {
|
|
447
|
+
destination: parseV1TransactionArgument(transaction.destination),
|
|
448
|
+
sources: transaction.sources.map((arg) => parseV1TransactionArgument(arg)),
|
|
449
|
+
},
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
case 'MoveCall': {
|
|
454
|
+
const [pkg, mod, fn] = transaction.target.split('::')
|
|
455
|
+
return {
|
|
456
|
+
MoveCall: {
|
|
457
|
+
package: pkg,
|
|
458
|
+
module: mod,
|
|
459
|
+
function: fn,
|
|
460
|
+
typeArguments: transaction.typeArguments,
|
|
461
|
+
arguments: transaction.arguments.map((arg) => parseV1TransactionArgument(arg)),
|
|
462
|
+
},
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
case 'Publish': {
|
|
467
|
+
return {
|
|
468
|
+
Publish: {
|
|
469
|
+
modules: transaction.modules.map((mod) => toBase64(Uint8Array.from(mod))),
|
|
470
|
+
dependencies: transaction.dependencies,
|
|
471
|
+
},
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
case 'SplitCoins': {
|
|
476
|
+
return {
|
|
477
|
+
SplitCoins: {
|
|
478
|
+
coin: parseV1TransactionArgument(transaction.coin),
|
|
479
|
+
amounts: transaction.amounts.map((arg) => parseV1TransactionArgument(arg)),
|
|
480
|
+
},
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
case 'TransferObjects': {
|
|
485
|
+
return {
|
|
486
|
+
TransferObjects: {
|
|
487
|
+
objects: transaction.objects.map((arg) => parseV1TransactionArgument(arg)),
|
|
488
|
+
address: parseV1TransactionArgument(transaction.address),
|
|
489
|
+
},
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
case 'Upgrade': {
|
|
494
|
+
return {
|
|
495
|
+
Upgrade: {
|
|
496
|
+
modules: transaction.modules.map((mod) => toBase64(Uint8Array.from(mod))),
|
|
497
|
+
dependencies: transaction.dependencies,
|
|
498
|
+
package: transaction.packageId,
|
|
499
|
+
ticket: parseV1TransactionArgument(transaction.ticket),
|
|
500
|
+
},
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
throw new Error(`Unknown transaction ${Object.keys(transaction)}`)
|
|
506
|
+
}),
|
|
507
|
+
})
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function parseV1TransactionArgument(arg) {
|
|
511
|
+
switch (arg.kind) {
|
|
512
|
+
case 'GasCoin': {
|
|
513
|
+
return { GasCoin: true }
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
case 'Result':
|
|
517
|
+
return { Result: arg.index }
|
|
518
|
+
case 'NestedResult': {
|
|
519
|
+
return { NestedResult: [arg.index, arg.resultIndex] }
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
case 'Input': {
|
|
523
|
+
return { Input: arg.index }
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export {
|
|
529
|
+
NormalizedCallArg,
|
|
530
|
+
ObjectRef,
|
|
531
|
+
SerializedTransactionDataV1,
|
|
532
|
+
StructTag,
|
|
533
|
+
TransactionArgument,
|
|
534
|
+
TypeTag,
|
|
535
|
+
serializeV1TransactionData,
|
|
536
|
+
transactionDataFromV1,
|
|
537
|
+
}
|
|
538
|
+
// # sourceMappingURL=v1.js.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
array,
|
|
3
|
+
boolean,
|
|
4
|
+
integer,
|
|
5
|
+
literal,
|
|
6
|
+
nullable,
|
|
7
|
+
nullish,
|
|
8
|
+
number,
|
|
9
|
+
object,
|
|
10
|
+
optional,
|
|
11
|
+
pipe,
|
|
12
|
+
record,
|
|
13
|
+
string,
|
|
14
|
+
tuple,
|
|
15
|
+
union,
|
|
16
|
+
unknown,
|
|
17
|
+
} from '../../valibot.js'
|
|
18
|
+
import { BCSBytes, JsonU64, ObjectID, ObjectRef, SuiAddress } from './internal.js'
|
|
19
|
+
|
|
20
|
+
function enumUnion(options) {
|
|
21
|
+
return union(Object.entries(options).map(([key, value]) => object({ [key]: value })))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const Argument = enumUnion({
|
|
25
|
+
GasCoin: literal(true),
|
|
26
|
+
Input: pipe(number(), integer()),
|
|
27
|
+
Result: pipe(number(), integer()),
|
|
28
|
+
NestedResult: tuple([pipe(number(), integer()), pipe(number(), integer())]),
|
|
29
|
+
})
|
|
30
|
+
const GasData = object({
|
|
31
|
+
budget: nullable(JsonU64),
|
|
32
|
+
price: nullable(JsonU64),
|
|
33
|
+
owner: nullable(SuiAddress),
|
|
34
|
+
payment: nullable(array(ObjectRef)),
|
|
35
|
+
})
|
|
36
|
+
const ProgrammableMoveCall = object({
|
|
37
|
+
package: ObjectID,
|
|
38
|
+
module: string(),
|
|
39
|
+
function: string(),
|
|
40
|
+
// snake case in rust
|
|
41
|
+
typeArguments: array(string()),
|
|
42
|
+
arguments: array(Argument),
|
|
43
|
+
})
|
|
44
|
+
const $Intent = object({
|
|
45
|
+
name: string(),
|
|
46
|
+
inputs: record(string(), union([Argument, array(Argument)])),
|
|
47
|
+
data: record(string(), unknown()),
|
|
48
|
+
})
|
|
49
|
+
const Command = enumUnion({
|
|
50
|
+
MoveCall: ProgrammableMoveCall,
|
|
51
|
+
TransferObjects: object({
|
|
52
|
+
objects: array(Argument),
|
|
53
|
+
address: Argument,
|
|
54
|
+
}),
|
|
55
|
+
SplitCoins: object({
|
|
56
|
+
coin: Argument,
|
|
57
|
+
amounts: array(Argument),
|
|
58
|
+
}),
|
|
59
|
+
MergeCoins: object({
|
|
60
|
+
destination: Argument,
|
|
61
|
+
sources: array(Argument),
|
|
62
|
+
}),
|
|
63
|
+
Publish: object({
|
|
64
|
+
modules: array(BCSBytes),
|
|
65
|
+
dependencies: array(ObjectID),
|
|
66
|
+
}),
|
|
67
|
+
MakeMoveVec: object({
|
|
68
|
+
type: nullable(string()),
|
|
69
|
+
elements: array(Argument),
|
|
70
|
+
}),
|
|
71
|
+
Upgrade: object({
|
|
72
|
+
modules: array(BCSBytes),
|
|
73
|
+
dependencies: array(ObjectID),
|
|
74
|
+
package: ObjectID,
|
|
75
|
+
ticket: Argument,
|
|
76
|
+
}),
|
|
77
|
+
$Intent,
|
|
78
|
+
})
|
|
79
|
+
const ObjectArg = enumUnion({
|
|
80
|
+
ImmOrOwnedObject: ObjectRef,
|
|
81
|
+
SharedObject: object({
|
|
82
|
+
objectId: ObjectID,
|
|
83
|
+
// snake case in rust
|
|
84
|
+
initialSharedVersion: JsonU64,
|
|
85
|
+
mutable: boolean(),
|
|
86
|
+
}),
|
|
87
|
+
Receiving: ObjectRef,
|
|
88
|
+
})
|
|
89
|
+
const CallArg = enumUnion({
|
|
90
|
+
Object: ObjectArg,
|
|
91
|
+
Pure: object({
|
|
92
|
+
bytes: BCSBytes,
|
|
93
|
+
}),
|
|
94
|
+
UnresolvedPure: object({
|
|
95
|
+
value: unknown(),
|
|
96
|
+
}),
|
|
97
|
+
UnresolvedObject: object({
|
|
98
|
+
objectId: ObjectID,
|
|
99
|
+
version: optional(nullable(JsonU64)),
|
|
100
|
+
digest: optional(nullable(string())),
|
|
101
|
+
initialSharedVersion: optional(nullable(JsonU64)),
|
|
102
|
+
}),
|
|
103
|
+
})
|
|
104
|
+
const TransactionExpiration = enumUnion({
|
|
105
|
+
None: literal(true),
|
|
106
|
+
Epoch: JsonU64,
|
|
107
|
+
})
|
|
108
|
+
const SerializedTransactionDataV2 = object({
|
|
109
|
+
version: literal(2),
|
|
110
|
+
sender: nullish(SuiAddress),
|
|
111
|
+
expiration: nullish(TransactionExpiration),
|
|
112
|
+
gasData: GasData,
|
|
113
|
+
inputs: array(CallArg),
|
|
114
|
+
commands: array(Command),
|
|
115
|
+
digest: optional(nullable(string())),
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
export { SerializedTransactionDataV2 }
|
|
119
|
+
// # sourceMappingURL=v2.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { hashSync } from '@exodus/crypto/hash'
|
|
2
|
+
|
|
3
|
+
function hashTypedData(typeTag, data) {
|
|
4
|
+
// eslint-disable-next-line unicorn/prefer-code-point
|
|
5
|
+
const typeTagBytes = [...`${typeTag}::`].map((e) => e.charCodeAt(0))
|
|
6
|
+
const dataWithTag = new Uint8Array(typeTagBytes.length + data.length)
|
|
7
|
+
dataWithTag.set(typeTagBytes)
|
|
8
|
+
dataWithTag.set(data, typeTagBytes.length)
|
|
9
|
+
return hashSync('blake2b256', dataWithTag)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { hashTypedData }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Transaction } from './Transaction.js'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
function createObjectMethods(makeObject) {
|
|
2
|
+
function object(value) {
|
|
3
|
+
return makeObject(value)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
object.system = () => object('0x5')
|
|
7
|
+
object.clock = () => object('0x6')
|
|
8
|
+
object.random = () => object('0x8')
|
|
9
|
+
object.denyList = () => object('0x403')
|
|
10
|
+
object.option =
|
|
11
|
+
({ type, value }) =>
|
|
12
|
+
(tx) =>
|
|
13
|
+
tx.moveCall({
|
|
14
|
+
typeArguments: [type],
|
|
15
|
+
target: `0x1::option::${value === null ? 'none' : 'some'}`,
|
|
16
|
+
arguments: value === null ? [] : [tx.object(value)],
|
|
17
|
+
})
|
|
18
|
+
return object
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { createObjectMethods }
|
|
22
|
+
// # sourceMappingURL=object.js.map
|