@swapkit/toolboxes 1.0.0-beta.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.
Files changed (89) hide show
  1. package/dist/chunk-fazw0jvt.js +3 -0
  2. package/dist/chunk-fazw0jvt.js.map +9 -0
  3. package/dist/chunk-tvrdndbw.js +4 -0
  4. package/dist/chunk-tvrdndbw.js.map +9 -0
  5. package/dist/cosmos/index.cjs +3 -0
  6. package/dist/cosmos/index.cjs.map +19 -0
  7. package/dist/cosmos/index.js +3 -0
  8. package/dist/cosmos/index.js.map +19 -0
  9. package/dist/evm/index.cjs +3 -0
  10. package/dist/evm/index.cjs.map +24 -0
  11. package/dist/evm/index.js +3 -0
  12. package/dist/evm/index.js.map +24 -0
  13. package/dist/index.cjs +3 -0
  14. package/dist/index.cjs.map +9 -0
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +9 -0
  17. package/dist/radix/index.cjs +3 -0
  18. package/dist/radix/index.cjs.map +10 -0
  19. package/dist/radix/index.js +3 -0
  20. package/dist/radix/index.js.map +10 -0
  21. package/dist/solana/index.cjs +3 -0
  22. package/dist/solana/index.cjs.map +10 -0
  23. package/dist/solana/index.js +3 -0
  24. package/dist/solana/index.js.map +10 -0
  25. package/dist/substrate/index.cjs +3 -0
  26. package/dist/substrate/index.cjs.map +12 -0
  27. package/dist/substrate/index.js +3 -0
  28. package/dist/substrate/index.js.map +12 -0
  29. package/dist/utxo/index.cjs +3 -0
  30. package/dist/utxo/index.cjs.map +18 -0
  31. package/dist/utxo/index.js +3 -0
  32. package/dist/utxo/index.js.map +18 -0
  33. package/package.json +105 -0
  34. package/src/cosmos/index.ts +11 -0
  35. package/src/cosmos/thorchainUtils/addressFormat.ts +24 -0
  36. package/src/cosmos/thorchainUtils/index.ts +4 -0
  37. package/src/cosmos/thorchainUtils/messages.ts +244 -0
  38. package/src/cosmos/thorchainUtils/registry.ts +47 -0
  39. package/src/cosmos/thorchainUtils/types/client-types.ts +80 -0
  40. package/src/cosmos/thorchainUtils/types/index.ts +1 -0
  41. package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.js +2806 -0
  42. package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.ts +2802 -0
  43. package/src/cosmos/thorchainUtils/util.ts +46 -0
  44. package/src/cosmos/toolbox/BaseCosmosToolbox.ts +254 -0
  45. package/src/cosmos/toolbox/gaia.ts +39 -0
  46. package/src/cosmos/toolbox/getToolboxByChain.ts +29 -0
  47. package/src/cosmos/toolbox/kujira.ts +61 -0
  48. package/src/cosmos/toolbox/thorchain.ts +321 -0
  49. package/src/cosmos/types.ts +31 -0
  50. package/src/cosmos/util.ts +230 -0
  51. package/src/evm/__tests__/ethereum.test.ts +147 -0
  52. package/src/evm/api.ts +157 -0
  53. package/src/evm/contracts/eth/multicall.ts +165 -0
  54. package/src/evm/contracts/op/gasOracle.ts +151 -0
  55. package/src/evm/helpers.ts +145 -0
  56. package/src/evm/index.ts +20 -0
  57. package/src/evm/provider.ts +6 -0
  58. package/src/evm/toolbox/EVMToolbox.ts +662 -0
  59. package/src/evm/toolbox/arb.ts +61 -0
  60. package/src/evm/toolbox/avax.ts +36 -0
  61. package/src/evm/toolbox/base.ts +42 -0
  62. package/src/evm/toolbox/bsc.ts +34 -0
  63. package/src/evm/toolbox/eth.ts +44 -0
  64. package/src/evm/toolbox/getToolboxByChain.ts +42 -0
  65. package/src/evm/toolbox/matic.ts +42 -0
  66. package/src/evm/toolbox/op.ts +163 -0
  67. package/src/evm/types.ts +118 -0
  68. package/src/index.ts +0 -0
  69. package/src/radix/index.ts +151 -0
  70. package/src/radix/toolbox.ts +693 -0
  71. package/src/solana/index.ts +49 -0
  72. package/src/solana/toolbox.ts +272 -0
  73. package/src/substrate/index.ts +3 -0
  74. package/src/substrate/toolbox/baseSubstrateToolbox.ts +286 -0
  75. package/src/substrate/toolbox/index.ts +40 -0
  76. package/src/substrate/types/index.ts +2 -0
  77. package/src/substrate/types/network.ts +42 -0
  78. package/src/substrate/types/wallet.ts +78 -0
  79. package/src/utxo/helpers/api.ts +431 -0
  80. package/src/utxo/helpers/bchaddrjs.ts +177 -0
  81. package/src/utxo/helpers/coinselect.ts +96 -0
  82. package/src/utxo/helpers/index.ts +5 -0
  83. package/src/utxo/helpers/txSize.ts +104 -0
  84. package/src/utxo/helpers/utils.ts +45 -0
  85. package/src/utxo/index.ts +9 -0
  86. package/src/utxo/toolbox/bitcoinCash.ts +281 -0
  87. package/src/utxo/toolbox/index.ts +37 -0
  88. package/src/utxo/toolbox/utxo.ts +360 -0
  89. package/src/utxo/types.ts +70 -0
@@ -0,0 +1,693 @@
1
+ // import {
2
+ // type FungibleResourcesCollectionItem,
3
+ // GatewayApiClient,
4
+ // type StateEntityDetailsVaultResponseItem,
5
+ // type StateEntityFungiblesPageRequest,
6
+ // type StateEntityFungiblesPageResponse,
7
+ // } from "@radixdlt/babylon-gateway-api-sdk";
8
+ // import { RadixDappToolkit } from "@radixdlt/radix-dapp-toolkit";
9
+ // import { AssetValue, Chain, type SKConfigIntegrations } from "@swapkit/helpers";
10
+
11
+ // // import {
12
+ // // Convert,
13
+ // // type Instructions,
14
+ // // type Intent,
15
+ // // LTSRadixEngineToolkit,
16
+ // // ManifestBuilder,
17
+ // // type Message,
18
+ // // type NotarizedTransaction,
19
+ // // PrivateKey,
20
+ // // type PublicKey,
21
+ // // RadixEngineToolkit,
22
+ // // type Signature,
23
+ // // type SignatureWithPublicKey,
24
+ // // TransactionBuilder,
25
+ // // type TransactionManifest,
26
+ // // address,
27
+ // // bucket,
28
+ // // decimal,
29
+ // // enumeration,
30
+ // // generateRandomNonce,
31
+ // // } from "@radixdlt/radix-engine-toolkit";
32
+
33
+ // type RadixGetBalanceParams = {
34
+ // address: string;
35
+ // networkApi: GatewayApiClient;
36
+ // };
37
+ // // #endregion
38
+
39
+ // // async function fetchNFTBalances(address: string): Promise<Balance[]> {
40
+ // // const nonFungibleResources = await this.fetchNonFungibleResources(address);
41
+ // // const nonFungibleBalances = this.convertResourcesToBalances(nonFungibleResources);
42
+ // // return nonFungibleBalances;
43
+ // // }
44
+
45
+ // // async function fetchNonFungibleResources(
46
+ // // address: string,
47
+ // // ): Promise<NonFungibleResourcesCollectionItem[]> {
48
+ // // let hasNextPage = true;
49
+ // // let nextCursor = undefined;
50
+ // // const stateVersion = await currentStateVersion();
51
+ // // let nonFungibleResources: NonFungibleResourcesCollectionItem[] = [];
52
+
53
+ // // while (hasNextPage) {
54
+ // // const stateEntityNonFungiblesPageRequest: StateEntityNonFungiblesPageRequest = {
55
+ // // address: address,
56
+ // // limit_per_page: 5,
57
+ // // cursor: nextCursor,
58
+ // // at_ledger_state: {
59
+ // // state_version: stateVersion,
60
+ // // },
61
+ // // };
62
+
63
+ // // const stateEntityNonFungiblesPageResponse: StateEntityNonFungiblesPageResponse =
64
+ // // await gatewayClient.state.innerClient.entityNonFungiblesPage({
65
+ // // stateEntityNonFungiblesPageRequest: stateEntityNonFungiblesPageRequest,
66
+ // // });
67
+ // // nonFungibleResources = nonFungibleResources.concat(stateEntityNonFungiblesPageResponse.items);
68
+ // // if (stateEntityNonFungiblesPageResponse.next_cursor) {
69
+ // // nextCursor = stateEntityNonFungiblesPageResponse.next_cursor;
70
+ // // } else {
71
+ // // hasNextPage = false;
72
+ // // }
73
+ // // }
74
+ // // return nonFungibleResources;
75
+ // // }
76
+
77
+ // // #endregion Public Methods
78
+
79
+ // // #region Private Methods
80
+ // // function createGatewayClient(network: number): GatewayApiClient {
81
+ // // const applicationName = "xchainjs";
82
+ // // return GatewayApiClient.initialize({
83
+ // // networkId: network,
84
+ // // applicationName,
85
+ // // });
86
+ // // }
87
+
88
+ // // async function previewIntent({
89
+ // // intent,
90
+ // // network,
91
+ // // networkApi,
92
+ // // }: {
93
+ // // intent: Intent;
94
+ // // network: RadixNetwork;
95
+ // // networkApi: GatewayApiClient;
96
+ // // }): Promise<TransactionPreviewResponse> {
97
+ // // // Translate the RET models to the gateway models for preview.
98
+ // // const request: TransactionPreviewOperationRequest = {
99
+ // // transactionPreviewRequest: {
100
+ // // manifest: await RadixEngineToolkit.Instructions.convert(
101
+ // // intent.manifest.instructions,
102
+ // // network.networkId,
103
+ // // "String",
104
+ // // ).then((instructions) => instructions.value as string),
105
+ // // blobs_hex: [],
106
+ // // start_epoch_inclusive: intent.header.startEpochInclusive,
107
+ // // end_epoch_exclusive: intent.header.endEpochExclusive,
108
+ // // notary_public_key: retPublicKeyToGatewayPublicKey(intent.header.notaryPublicKey),
109
+ // // notary_is_signatory: intent.header.notaryIsSignatory,
110
+ // // tip_percentage: intent.header.tipPercentage,
111
+ // // nonce: intent.header.nonce,
112
+ // // signer_public_keys: [retPublicKeyToGatewayPublicKey(intent.header.notaryPublicKey)],
113
+
114
+ // // flags: {
115
+ // // assume_all_signature_proofs: false,
116
+ // // skip_epoch_check: false,
117
+ // // use_free_credit: false,
118
+ // // },
119
+ // // },
120
+ // // };
121
+
122
+ // // return networkApi.transaction.innerClient.transactionPreview(request);
123
+ // // }
124
+
125
+ // // function retPublicKeyToGatewayPublicKey(publicKey: PublicKey): GatewayPublicKey {
126
+ // // switch (publicKey.curve) {
127
+ // // case "Secp256k1":
128
+ // // return {
129
+ // // key_type: "EcdsaSecp256k1",
130
+ // // key_hex: publicKey.hex(),
131
+ // // };
132
+ // // case "Ed25519":
133
+ // // return {
134
+ // // key_type: "EddsaEd25519",
135
+ // // key_hex: publicKey.hex(),
136
+ // // };
137
+ // // }
138
+ // // }
139
+
140
+ // // export type RadixSigner = {
141
+ // // getAddress?: () => Promise<string>;
142
+ // // publicKey(): PublicKey;
143
+ // // publicKeyBytes(): Uint8Array;
144
+ // // publicKeyHex(): string;
145
+ // // sign(messageHash: Uint8Array): Uint8Array;
146
+ // // signToSignature(messageHash: Uint8Array): Signature;
147
+ // // signToSignatureWithPublicKey(messageHash: Uint8Array): SignatureWithPublicKey;
148
+ // // };
149
+
150
+ // // export async function createPrivateKey(phrase: string) {
151
+ // // const seed = await mnemonicToSeed(phrase);
152
+
153
+ // // return new PrivateKey.Ed25519(seed.slice(0, 32));
154
+ // // }
155
+
156
+ // // function getAddress(signer: RadixSigner, network: RadixNetwork) {
157
+ // // return LTSRadixEngineToolkit.Derive.virtualAccountAddress(signer.publicKey(), network.networkId);
158
+ // // }
159
+
160
+ // // Could not find anything sync in SDK, ask Radix team
161
+ // export function validateAddress(address: string) {
162
+ // return address.startsWith("account_rdx1") && address.length === 66;
163
+ // }
164
+
165
+ // function getBalance({ networkApi }: { networkApi: GatewayApiClient }) {
166
+ // return async function getBalance(address: string) {
167
+ // const fungibleResources = await fetchFungibleResources({ address, networkApi });
168
+ // const fungibleBalances = convertResourcesToBalances({
169
+ // resources: fungibleResources,
170
+ // networkApi,
171
+ // });
172
+ // return fungibleBalances;
173
+ // };
174
+ // }
175
+
176
+ // async function fetchFungibleResources({
177
+ // address,
178
+ // networkApi,
179
+ // }: RadixGetBalanceParams): Promise<FungibleResourcesCollectionItem[]> {
180
+ // let hasNextPage = true;
181
+ // let nextCursor = undefined;
182
+ // let fungibleResources: FungibleResourcesCollectionItem[] = [];
183
+ // const stateVersion = await currentStateVersion(networkApi);
184
+ // while (hasNextPage) {
185
+ // const stateEntityFungiblesPageRequest: StateEntityFungiblesPageRequest = {
186
+ // address: address,
187
+ // limit_per_page: 100,
188
+ // cursor: nextCursor,
189
+ // at_ledger_state: {
190
+ // state_version: stateVersion,
191
+ // },
192
+ // };
193
+
194
+ // const stateEntityFungiblesPageResponse: StateEntityFungiblesPageResponse =
195
+ // await networkApi.state.innerClient.entityFungiblesPage({
196
+ // stateEntityFungiblesPageRequest: stateEntityFungiblesPageRequest,
197
+ // });
198
+
199
+ // fungibleResources = fungibleResources.concat(stateEntityFungiblesPageResponse.items);
200
+ // if (stateEntityFungiblesPageResponse.next_cursor) {
201
+ // nextCursor = stateEntityFungiblesPageResponse.next_cursor;
202
+ // } else {
203
+ // hasNextPage = false;
204
+ // }
205
+ // }
206
+ // return fungibleResources;
207
+ // }
208
+
209
+ // // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
210
+ // async function convertResourcesToBalances({
211
+ // resources,
212
+ // networkApi,
213
+ // }: {
214
+ // resources: FungibleResourcesCollectionItem[]; //| NonFungibleResourcesCollectionItem[];
215
+ // networkApi: GatewayApiClient;
216
+ // }): Promise<AssetValue[]> {
217
+ // const balances: AssetValue[] = [];
218
+ // const BATCH_SIZE = 50;
219
+
220
+ // // Split resources into batches of up to 50 items
221
+ // const resourceBatches = [];
222
+ // for (let i = 0; i < resources.length; i += BATCH_SIZE) {
223
+ // resourceBatches.push(resources.slice(i, i + BATCH_SIZE));
224
+ // }
225
+
226
+ // for (const batch of resourceBatches) {
227
+ // const addresses = batch.map((item) => item.resource_address);
228
+ // const response: StateEntityDetailsVaultResponseItem[] =
229
+ // await networkApi.state.getEntityDetailsVaultAggregated(addresses);
230
+
231
+ // const divisibilities = new Map<string, { decimals: number; symbol: string }>();
232
+
233
+ // for (const result of response) {
234
+ // if (result.details !== undefined) {
235
+ // const metaDataSymbol = result.metadata?.items.find((item) => item.key === "symbol");
236
+ // const symbol =
237
+ // metaDataSymbol?.value.typed.type === "String" ? metaDataSymbol.value.typed.value : "?";
238
+
239
+ // if (result.details.type === "FungibleResource") {
240
+ // divisibilities.set(result.address, {
241
+ // decimals: result.details.divisibility,
242
+ // symbol,
243
+ // });
244
+ // }
245
+ // }
246
+ // }
247
+
248
+ // for (const item of batch) {
249
+ // if (item.aggregation_level === "Global") {
250
+ // const assetInfo = divisibilities.get(item.resource_address) || { decimals: 0, symbol: "?" };
251
+
252
+ // const balance = AssetValue.from({
253
+ // asset:
254
+ // assetInfo.symbol !== Chain.Radix
255
+ // ? `${Chain.Radix}.${assetInfo.symbol}-${item.resource_address}`
256
+ // : "XRD.XRD",
257
+ // value: item.amount,
258
+ // });
259
+ // balances.push(balance);
260
+ // }
261
+ // }
262
+ // }
263
+ // // Iterate through resources
264
+ // return balances;
265
+ // }
266
+
267
+ // // function getCurrentEpoch(networkApi: GatewayApiClient) {
268
+ // // return networkApi.status.getCurrent().then((status) => status.ledger_state.epoch);
269
+ // // }
270
+
271
+ // async function currentStateVersion(networkApi: GatewayApiClient) {
272
+ // return networkApi.status.getCurrent().then((status) => status.ledger_state.state_version);
273
+ // }
274
+
275
+ // // function constructSimpleTransferIntent({
276
+ // // networkApi,
277
+ // // network = RadixMainnet,
278
+ // // }: {
279
+ // // networkApi: GatewayApiClient;
280
+ // // network: RadixNetwork;
281
+ // // }) {
282
+ // // // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
283
+ // // return async function constructSimpleTransferIntent(
284
+ // // params:
285
+ // // | {
286
+ // // from: string;
287
+ // // recipient: string;
288
+ // // assetValue: AssetValue;
289
+ // // notaryPublicKey: PublicKey;
290
+ // // memo: string;
291
+ // // }
292
+ // // | { manifest: string | TransactionManifest; notaryPublicKey: PublicKey },
293
+ // // ): Promise<{ intent: Intent; fees: number }> {
294
+ // // const nonce = generateRandomNonce();
295
+
296
+ // // const { notaryPublicKey } = params;
297
+
298
+ // // const from = "from" in params ? params.from : undefined;
299
+ // // const recipient = "recipient" in params ? params.recipient : undefined;
300
+ // // const assetValue = "assetValue" in params ? params.assetValue : undefined;
301
+ // // const memo = "memo" in params ? params.memo : undefined;
302
+ // // // Construct the intent with a random fee lock, say 5 XRD and then create a transaction intent
303
+ // // // from it.
304
+
305
+ // // const manifestWithHardcodedFee =
306
+ // // "manifest" in params
307
+ // // ? typeof params.manifest === "string"
308
+ // // ? ({
309
+ // // instructions: await convertManifestToInstructions({ network })(params.manifest),
310
+ // // blobs: [],
311
+ // // } as TransactionManifest)
312
+ // // : params.manifest
313
+ // // : from && recipient && assetValue
314
+ // // ? simpleTransferManifest({
315
+ // // from,
316
+ // // recipient,
317
+ // // assetValue,
318
+ // // fees: AssetValue.from({
319
+ // // asset: "XRD.XRD",
320
+ // // value: "5",
321
+ // // }),
322
+ // // })
323
+ // // : undefined;
324
+
325
+ // // if (!manifestWithHardcodedFee) {
326
+ // // throw new Error("Manifest is required");
327
+ // // }
328
+
329
+ // // const intentWithHardcodedFee = await constructIntent({
330
+ // // manifest: manifestWithHardcodedFee,
331
+ // // message: memo
332
+ // // ? {
333
+ // // kind: "PlainText",
334
+ // // value: { mimeType: "text/plain", message: { kind: "String", value: memo } },
335
+ // // }
336
+ // // : { kind: "None" },
337
+ // // nonce,
338
+ // // notaryPublicKey,
339
+ // // networkApi,
340
+ // // network,
341
+ // // });
342
+
343
+ // // const previewReceipt = await previewIntent({
344
+ // // intent: intentWithHardcodedFee,
345
+ // // network,
346
+ // // networkApi,
347
+ // // });
348
+ // // // Ensure that the preview was successful.
349
+ // // // @ts-expect-error
350
+ // // if (previewReceipt.receipt.status !== "Succeeded") {
351
+ // // throw new Error("Preview for fees was not successful");
352
+ // // }
353
+
354
+ // // // Calculate the total fees
355
+ // // const totalFees = [
356
+ // // // @ts-expect-error
357
+ // // previewReceipt.receipt.fee_summary.xrd_total_execution_cost,
358
+ // // // @ts-expect-error
359
+ // // previewReceipt.receipt.fee_summary.xrd_total_finalization_cost,
360
+ // // // @ts-expect-error
361
+ // // previewReceipt.receipt.fee_summary.xrd_total_royalty_cost,
362
+ // // // @ts-expect-error
363
+ // // previewReceipt.receipt.fee_summary.xrd_total_storage_cost,
364
+ // // // @ts-expect-error
365
+ // // previewReceipt.receipt.fee_summary.xrd_total_tipping_cost,
366
+ // // ]
367
+ // // .map(Number.parseFloat)
368
+ // // .reduce((acc, item) => acc + item, 0);
369
+
370
+ // // // We need to add another 10% to the fees as the preview response does not include everything needed
371
+ // // // to actually submit the transaction, ie: signature validation
372
+
373
+ // // // Construct a new intent with the calculated fees.
374
+ // // const manifest =
375
+ // // "manifest" in params
376
+ // // ? typeof params.manifest === "string"
377
+ // // ? ({
378
+ // // instructions: await convertManifestToInstructions({ network })(params.manifest),
379
+ // // blobs: [],
380
+ // // } as TransactionManifest)
381
+ // // : params.manifest
382
+ // // : from && recipient && assetValue
383
+ // // ? simpleTransferManifest({
384
+ // // from,
385
+ // // recipient,
386
+ // // assetValue,
387
+ // // fees: new SwapKitNumber(totalFees).mul(1.1),
388
+ // // })
389
+ // // : undefined;
390
+
391
+ // // if (!manifest) {
392
+ // // throw new Error("Manifest is required");
393
+ // // }
394
+
395
+ // // const intent = await constructIntent({
396
+ // // manifest,
397
+ // // message: memo
398
+ // // ? {
399
+ // // kind: "PlainText",
400
+ // // value: {
401
+ // // mimeType: "text/plain",
402
+ // // message: { kind: "String", value: memo },
403
+ // // },
404
+ // // }
405
+ // // : { kind: "None" },
406
+ // // nonce,
407
+ // // notaryPublicKey,
408
+ // // network,
409
+ // // networkApi,
410
+ // // });
411
+
412
+ // // return {
413
+ // // intent,
414
+ // // fees: totalFees,
415
+ // // };
416
+ // // };
417
+ // // }
418
+
419
+ // // function simpleTransferManifest({
420
+ // // from,
421
+ // // recipient,
422
+ // // assetValue,
423
+ // // fees,
424
+ // // }: {
425
+ // // from: string;
426
+ // // recipient: string;
427
+ // // assetValue: AssetValue;
428
+ // // fees: SwapKitNumber;
429
+ // // }): TransactionManifest {
430
+ // // if (assetValue.address === undefined) {
431
+ // // throw new Error("Asset value must have an address");
432
+ // // }
433
+
434
+ // // return new ManifestBuilder()
435
+ // // .callMethod(from, "lock_fee", [decimal(fees.getValue("string"))])
436
+ // // .callMethod(from, "withdraw", [
437
+ // // address(assetValue.address),
438
+ // // decimal(assetValue.getValue("string")),
439
+ // // ])
440
+ // // .takeFromWorktop(
441
+ // // assetValue.address,
442
+ // // decimal(assetValue.getValue("string")).value,
443
+ // // (builder, bucketId) => {
444
+ // // return builder.callMethod(recipient, "try_deposit_or_abort", [
445
+ // // bucket(bucketId),
446
+ // // enumeration(0),
447
+ // // ]);
448
+ // // },
449
+ // // )
450
+ // // .build();
451
+ // // }
452
+
453
+ // // async function constructIntent({
454
+ // // manifest,
455
+ // // message,
456
+ // // nonce,
457
+ // // notaryPublicKey,
458
+ // // networkApi,
459
+ // // network,
460
+ // // }: {
461
+ // // manifest: TransactionManifest;
462
+ // // message: Message;
463
+ // // nonce: number;
464
+ // // notaryPublicKey: PublicKey;
465
+ // // networkApi: GatewayApiClient;
466
+ // // network: RadixNetwork;
467
+ // // }): Promise<Intent> {
468
+ // // const epoch = await getCurrentEpoch(networkApi);
469
+ // // return {
470
+ // // header: {
471
+ // // networkId: network.networkId,
472
+ // // startEpochInclusive: epoch,
473
+ // // endEpochExclusive: epoch + 10,
474
+ // // nonce,
475
+ // // notaryPublicKey,
476
+ // // notaryIsSignatory: true,
477
+ // // tipPercentage: 0,
478
+ // // },
479
+ // // manifest,
480
+ // // message,
481
+ // // };
482
+ // // }
483
+
484
+ // // function transfer({
485
+ // // signer,
486
+ // // networkApi,
487
+ // // network = RadixMainnet,
488
+ // // }: {
489
+ // // signer?: RadixSigner;
490
+ // // networkApi: GatewayApiClient;
491
+ // // network?: RadixNetwork;
492
+ // // }) {
493
+ // // return async function transfer({
494
+ // // assetValue: unsafeAssetValue,
495
+ // // from,
496
+ // // recipient,
497
+ // // memo = "",
498
+ // // }: { assetValue: AssetValue; from: string; recipient: string; memo?: string }) {
499
+ // // if (!signer) throw new SwapKitError("toolbox_radix_signer_not_defined");
500
+
501
+ // // const assetValue =
502
+ // // unsafeAssetValue.toString() === "XRD.XRD"
503
+ // // ? AssetValue.from({
504
+ // // asset: "XRD.XRD-resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd",
505
+ // // value: unsafeAssetValue.getValue("string"),
506
+ // // })
507
+ // // : unsafeAssetValue;
508
+
509
+ // // if (!assetValue.address) throw new Error("Asset value must have an address");
510
+
511
+ // // const publicKey = signer.publicKey();
512
+ // // const intent = (
513
+ // // await constructSimpleTransferIntent({
514
+ // // network,
515
+ // // networkApi,
516
+ // // })({ from, recipient, assetValue, memo, notaryPublicKey: publicKey })
517
+ // // ).intent;
518
+
519
+ // // const compiledIntent = await RadixEngineToolkit.Intent.compile(intent);
520
+
521
+ // // const notarySignature = signer.signToSignature(compiledIntent);
522
+
523
+ // // const notarizedTransaction = await TransactionBuilder.new().then((builder) => {
524
+ // // return builder
525
+ // // .header(intent.header)
526
+ // // .message(intent.message)
527
+ // // .manifest(intent.manifest)
528
+ // // .notarize(notarySignature);
529
+ // // });
530
+
531
+ // // const notarizedTransactionBytes =
532
+ // // await RadixEngineToolkit.NotarizedTransaction.compile(notarizedTransaction);
533
+ // // const hash = await broadcastTransaction({
534
+ // // networkApi,
535
+ // // })(Convert.Uint8Array.toHexString(notarizedTransactionBytes));
536
+ // // return hash;
537
+ // // };
538
+
539
+ // // const constructionMetadata = await net.LTS.getConstructionMetadata();
540
+ // // const builder = await SimpleTransactionBuilder.new({
541
+ // // networkId: network.networkId,
542
+ // // validFromEpoch: constructionMetadata.current_epoch,
543
+ // // fromAccount: from,
544
+ // // signerPublicKey: signer.publicKey(),
545
+ // // });
546
+
547
+ // // const unsignedTransaction = builder
548
+ // // .transferFungible({
549
+ // // toAccount: recipient,
550
+ // // resourceAddress: assetValue.address,
551
+ // // amount: assetValue.getBaseValue("number"),
552
+ // // })
553
+ // // .compileIntent();
554
+
555
+ // // const intentHashTransactionId = notarizedTransaction.transactionId.id;
556
+
557
+ // // try {
558
+ // // await api.LTS.submitTransaction({
559
+ // // notarized_transaction_hex: notarizedTransaction.toHex(),
560
+ // // });
561
+ // // } catch (error) {
562
+ // // throw new Error(`Failed to submit transaction: ${error}`);
563
+ // // }
564
+
565
+ // // return intentHashTransactionId;
566
+ // // };
567
+ // // }
568
+
569
+ // // function broadcastTransaction({
570
+ // // networkApi,
571
+ // // }: {
572
+ // // networkApi: GatewayApiClient;
573
+ // // }) {
574
+ // // return async function broadcastTransaction(tx: NotarizedTransaction | string) {
575
+ // // const txToBroadcast: NotarizedTransaction =
576
+ // // typeof tx === "string"
577
+ // // ? await RadixEngineToolkit.NotarizedTransaction.decompile(
578
+ // // Convert.HexString.toUint8Array(tx),
579
+ // // )
580
+ // // : tx;
581
+ // // const intentHash = await RadixEngineToolkit.NotarizedTransaction.intentHash(txToBroadcast);
582
+ // // const transactionHex = await RadixEngineToolkit.NotarizedTransaction.compile(
583
+ // // txToBroadcast,
584
+ // // ).then(Convert.Uint8Array.toHexString);
585
+ // // await networkApi.transaction.innerClient.transactionSubmit({
586
+ // // transactionSubmitRequest: { notarized_transaction_hex: transactionHex },
587
+ // // });
588
+
589
+ // // return intentHash.id;
590
+ // // };
591
+ // // }
592
+
593
+ // // export function convertManifestToInstructions({ network }: { network: RadixNetwork }) {
594
+ // // return function convertManifestToInstructions(transactionManifest: string) {
595
+ // // return RadixEngineToolkit.Instructions.convert(
596
+ // // {
597
+ // // kind: "String",
598
+ // // value: transactionManifest,
599
+ // // },
600
+ // // network.networkId,
601
+ // // "Parsed",
602
+ // // );
603
+ // // };
604
+ // // }
605
+
606
+ // // export function convertInstructionsToManifest({ network }: { network: RadixNetwork }) {
607
+ // // return function convertInstructionsToManifest(transactionManifest: Instructions) {
608
+ // // return RadixEngineToolkit.Instructions.convert(
609
+ // // transactionManifest,
610
+ // // network.networkId,
611
+ // // "String",
612
+ // // );
613
+ // // };
614
+ // // }
615
+
616
+ // // function signAndBroadcast({
617
+ // // signer,
618
+ // // networkApi,
619
+ // // network = RadixMainnet,
620
+ // // }: {
621
+ // // signer?: RadixSigner;
622
+ // // networkApi: GatewayApiClient;
623
+ // // network?: RadixNetwork;
624
+ // // }) {
625
+ // // return async function signAndBroadcast({ manifest }: { manifest: string | TransactionManifest }) {
626
+ // // if (!signer) throw new SwapKitError("toolbox_radix_signer_not_defined");
627
+ // // const publicKey = signer.publicKey();
628
+ // // const intent = (
629
+ // // await constructSimpleTransferIntent({
630
+ // // network,
631
+ // // networkApi,
632
+ // // })({ manifest, notaryPublicKey: publicKey })
633
+ // // ).intent;
634
+
635
+ // // const compiledIntent = await RadixEngineToolkit.Intent.compile(intent);
636
+
637
+ // // const notarySignature = signer.signToSignature(compiledIntent);
638
+
639
+ // // const notarizedTransaction = await TransactionBuilder.new().then((builder) => {
640
+ // // return builder
641
+ // // .header(intent.header)
642
+ // // .message(intent.message)
643
+ // // .manifest(intent.manifest)
644
+ // // .notarize(notarySignature);
645
+ // // });
646
+
647
+ // // const notarizedTransactionBytes =
648
+ // // await RadixEngineToolkit.NotarizedTransaction.compile(notarizedTransaction);
649
+ // // const transactionId = await broadcastTransaction({
650
+ // // networkApi,
651
+ // // })(Convert.Uint8Array.toHexString(notarizedTransactionBytes));
652
+ // // return transactionId;
653
+ // // };
654
+ // // }
655
+
656
+ // export const RadixToolbox = async ({
657
+ // dappConfig,
658
+ // }: { dappConfig: SKConfigIntegrations["radix"] }) => {
659
+ // const radixToolkit = RadixDappToolkit({
660
+ // ...dappConfig,
661
+ // networkId: dappConfig.network?.networkId || 1,
662
+ // });
663
+
664
+ // const networkApi = GatewayApiClient.initialize(radixToolkit.gatewayApi.clientConfig);
665
+
666
+ // return {
667
+ // networkApi,
668
+ // getBalance: getBalance({ networkApi }),
669
+ // getAddress: () => {
670
+ // return "";
671
+ // },
672
+ // validateAddress,
673
+ // signAndBroadcast: (() => {
674
+ // throw new Error("Not implemented");
675
+ // }) as (params: any) => Promise<string>,
676
+ // };
677
+ // };
678
+
679
+ // // function signMessage(_signer?: RadixSigner) {
680
+ // // return function signMessage(_message: string) {
681
+ // // throw new SwapKitError("not_implemented", { method: "signMessage", toolbox: "radix" });
682
+
683
+ // // // return signer.signToSignatureWithPublicKey(message);
684
+ // // };
685
+ // // }
686
+
687
+ // // function validateSignature(_signer?: RadixSigner) {
688
+ // // return function validateSignature(_signature: SignatureWithPublicKey) {
689
+ // // throw new SwapKitError("not_implemented", { method: "validateSignature", toolbox: "radix" });
690
+
691
+ // // // return
692
+ // // };
693
+ // // }