@moonbeam-network/xcm-builder 1.0.0-dev.152 → 1.0.0-dev.154

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/build/index.mjs CHANGED
@@ -1,4332 +1,2 @@
1
- // src/index.ts
2
- import "@polkadot/api-augment";
3
-
4
- // src/types/BaseConfig.ts
5
- var BaseConfig = class {
6
- module;
7
- func;
8
- constructor({ module: module5, func }) {
9
- this.module = module5;
10
- this.func = func;
11
- }
12
- };
13
-
14
- // src/types/substrate/SubstrateQueryConfig.ts
15
- var SubstrateQueryConfig = class _SubstrateQueryConfig extends BaseConfig {
16
- args;
17
- transform;
18
- static is(obj) {
19
- return obj instanceof _SubstrateQueryConfig;
20
- }
21
- constructor({
22
- args = [],
23
- transform,
24
- ...other
25
- }) {
26
- super({ ...other });
27
- this.args = args;
28
- this.transform = transform;
29
- }
30
- };
31
-
32
- // src/asset-min/AssetMinBuilder.ts
33
- function AssetMinBuilder() {
34
- return {
35
- assetRegistry,
36
- assets
37
- };
38
- }
39
- function assetRegistry() {
40
- const pallet6 = "assetRegistry";
41
- return {
42
- assetMetadatas: () => ({
43
- build: ({ asset }) => new SubstrateQueryConfig({
44
- module: pallet6,
45
- func: "assetMetadatas",
46
- args: [asset],
47
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
48
- transform: async (response) => response.unwrapOrDefault().minimalBalance.toBigInt()
49
- })
50
- }),
51
- currencyMetadatas: () => ({
52
- build: ({ asset }) => new SubstrateQueryConfig({
53
- module: pallet6,
54
- func: "currencyMetadatas",
55
- args: [asset],
56
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
57
- transform: async (response) => response.unwrapOrDefault().minimalBalance.toBigInt()
58
- })
59
- })
60
- };
61
- }
62
- function assets() {
63
- return {
64
- asset: () => ({
65
- build: ({ asset }) => new SubstrateQueryConfig({
66
- module: "assets",
67
- func: "asset",
68
- args: [asset],
69
- transform: async (response) => response.unwrapOrDefault().minBalance.toBigInt()
70
- })
71
- })
72
- };
73
- }
74
-
75
- // src/balance/BalanceBuilder.ts
76
- import { evmToAddress as evmToAddress2 } from "@polkadot/util-crypto";
77
-
78
- // src/types/evm/ContractConfig.ts
79
- import { encodeFunctionData } from "viem";
80
- var ContractConfig = class _ContractConfig extends BaseConfig {
81
- address;
82
- abi;
83
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
84
- args;
85
- static is(obj) {
86
- return obj instanceof _ContractConfig;
87
- }
88
- constructor({
89
- address,
90
- abi,
91
- args,
92
- ...other
93
- }) {
94
- super({ ...other });
95
- this.address = address;
96
- this.abi = abi;
97
- this.args = args;
98
- }
99
- encodeFunctionData() {
100
- return encodeFunctionData({
101
- abi: this.abi,
102
- functionName: this.func,
103
- args: this.args
104
- });
105
- }
106
- };
107
-
108
- // src/contract/contracts/Xtokens/Xtokens.ts
109
- import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";
110
- import { u8aToHex as u8aToHex2 } from "@polkadot/util";
111
- import { decodeAddress as decodeAddress2, evmToAddress } from "@polkadot/util-crypto";
112
-
113
- // src/builder.utils.ts
114
- import { EvmParachain } from "@moonbeam-network/xcm-types";
115
- import { u8aToHex } from "@polkadot/util";
116
- import { decodeAddress } from "@polkadot/util-crypto";
117
- function getPrecompileDestinationInterior(destination, address) {
118
- if (!address) {
119
- return [`0x0000000${destination.parachainId.toString(16)}`];
120
- }
121
- const accountType = EvmParachain.is(destination) ? "03" : "01";
122
- const acc = `0x${accountType}${u8aToHex(
123
- decodeAddress(address),
124
- -1,
125
- false
126
- )}00`;
127
- return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
128
- }
129
-
130
- // src/contract/contracts/Xtokens/XtokensABI.ts
131
- var XTOKENS_ABI = [
132
- {
133
- inputs: [
134
- {
135
- internalType: "address",
136
- name: "currencyAddress",
137
- type: "address"
138
- },
139
- {
140
- internalType: "uint256",
141
- name: "amount",
142
- type: "uint256"
143
- },
144
- {
145
- components: [
146
- {
147
- internalType: "uint8",
148
- name: "parents",
149
- type: "uint8"
150
- },
151
- {
152
- internalType: "bytes[]",
153
- name: "interior",
154
- type: "bytes[]"
155
- }
156
- ],
157
- internalType: "struct Xtokens.Multilocation",
158
- name: "destination",
159
- type: "tuple"
160
- },
161
- {
162
- internalType: "uint64",
163
- name: "weight",
164
- type: "uint64"
165
- }
166
- ],
167
- name: "transfer",
168
- outputs: [],
169
- stateMutability: "nonpayable",
170
- type: "function"
171
- },
172
- {
173
- inputs: [
174
- {
175
- components: [
176
- {
177
- internalType: "address",
178
- name: "currencyAddress",
179
- type: "address"
180
- },
181
- {
182
- internalType: "uint256",
183
- name: "amount",
184
- type: "uint256"
185
- }
186
- ],
187
- internalType: "struct Xtokens.Currency[]",
188
- name: "currencies",
189
- type: "tuple[]"
190
- },
191
- {
192
- internalType: "uint32",
193
- name: "feeItem",
194
- type: "uint32"
195
- },
196
- {
197
- components: [
198
- {
199
- internalType: "uint8",
200
- name: "parents",
201
- type: "uint8"
202
- },
203
- {
204
- internalType: "bytes[]",
205
- name: "interior",
206
- type: "bytes[]"
207
- }
208
- ],
209
- internalType: "struct Xtokens.Multilocation",
210
- name: "destination",
211
- type: "tuple"
212
- },
213
- {
214
- internalType: "uint64",
215
- name: "weight",
216
- type: "uint64"
217
- }
218
- ],
219
- name: "transferMultiCurrencies",
220
- outputs: [],
221
- stateMutability: "nonpayable",
222
- type: "function"
223
- }
224
- ];
225
-
226
- // src/contract/contracts/Xtokens/Xtokens.ts
227
- var U_64_MAX = 18446744073709551615n;
228
- var XTOKENS_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000804";
229
- function Xtokens() {
230
- return {
231
- transfer: (weight = U_64_MAX) => ({
232
- build: ({ destinationAddress, asset, destination }) => new ContractConfig({
233
- address: XTOKENS_CONTRACT_ADDRESS,
234
- abi: XTOKENS_ABI,
235
- args: [
236
- asset.address ? formatAssetIdToERC20(asset.address) : asset.getAssetId(),
237
- asset.amount,
238
- getDestinationMultilocation(destinationAddress, destination),
239
- weight
240
- ],
241
- func: "transfer",
242
- module: "Xtokens"
243
- })
244
- }),
245
- transferMultiCurrencies: (weight = U_64_MAX) => ({
246
- build: ({ asset, destination, destinationAddress, fee }) => new ContractConfig({
247
- address: XTOKENS_CONTRACT_ADDRESS,
248
- abi: XTOKENS_ABI,
249
- args: [
250
- [
251
- [
252
- asset.address ? formatAssetIdToERC20(asset.address) : asset.getAssetId(),
253
- asset.amount
254
- ],
255
- [
256
- fee.address ? formatAssetIdToERC20(fee.address) : fee.getAssetId(),
257
- fee.amount
258
- ]
259
- ],
260
- 1,
261
- // index of the fee asset
262
- getDestinationMultilocation(destinationAddress, destination),
263
- weight
264
- ],
265
- func: "transferMultiCurrencies",
266
- module: "Xtokens"
267
- })
268
- }),
269
- transferWithEvmTo32: (weight = U_64_MAX) => ({
270
- build: ({ destinationAddress, asset, destination }) => {
271
- const multilocation = getDestinationMultilocationForPrecompileDestination(
272
- destinationAddress,
273
- destination
274
- );
275
- return new ContractConfig({
276
- address: XTOKENS_CONTRACT_ADDRESS,
277
- abi: XTOKENS_ABI,
278
- args: [
279
- asset.address ? formatAssetIdToERC20(asset.address) : asset.getAssetId(),
280
- asset.amount,
281
- multilocation,
282
- weight
283
- ],
284
- func: "transfer",
285
- module: "Xtokens"
286
- });
287
- }
288
- })
289
- };
290
- }
291
- function getDestinationMultilocationForPrecompileDestination(address, destination) {
292
- const accountType = "01";
293
- const substrateAddress = evmToAddress(address);
294
- const acc = `0x${accountType}${u8aToHex2(
295
- decodeAddress2(substrateAddress),
296
- -1,
297
- false
298
- )}00`;
299
- return [
300
- 1,
301
- destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc]
302
- ];
303
- }
304
- function getDestinationMultilocation(address, destination) {
305
- const interior = getPrecompileDestinationInterior(destination, address);
306
- return [1, interior];
307
- }
308
-
309
- // src/contract/ContractBuilder.ts
310
- function ContractBuilder() {
311
- return {
312
- Xtokens
313
- };
314
- }
315
-
316
- // src/types/evm/EvmQueryConfig.ts
317
- var EvmQueryConfig = class _EvmQueryConfig {
318
- args;
319
- func;
320
- static is(obj) {
321
- return obj instanceof _EvmQueryConfig;
322
- }
323
- constructor({ args, func }) {
324
- this.args = args;
325
- this.func = func;
326
- }
327
- };
328
-
329
- // src/balance/Erc20Abi.ts
330
- var ERC20_ABI = [
331
- {
332
- constant: true,
333
- inputs: [],
334
- name: "name",
335
- outputs: [
336
- {
337
- name: "",
338
- type: "string"
339
- }
340
- ],
341
- payable: false,
342
- stateMutability: "view",
343
- type: "function"
344
- },
345
- {
346
- constant: false,
347
- inputs: [
348
- {
349
- name: "_spender",
350
- type: "address"
351
- },
352
- {
353
- name: "_value",
354
- type: "uint256"
355
- }
356
- ],
357
- name: "approve",
358
- outputs: [
359
- {
360
- name: "",
361
- type: "bool"
362
- }
363
- ],
364
- payable: false,
365
- stateMutability: "nonpayable",
366
- type: "function"
367
- },
368
- {
369
- constant: true,
370
- inputs: [],
371
- name: "totalSupply",
372
- outputs: [
373
- {
374
- name: "",
375
- type: "uint256"
376
- }
377
- ],
378
- payable: false,
379
- stateMutability: "view",
380
- type: "function"
381
- },
382
- {
383
- constant: false,
384
- inputs: [
385
- {
386
- name: "_from",
387
- type: "address"
388
- },
389
- {
390
- name: "_to",
391
- type: "address"
392
- },
393
- {
394
- name: "_value",
395
- type: "uint256"
396
- }
397
- ],
398
- name: "transferFrom",
399
- outputs: [
400
- {
401
- name: "",
402
- type: "bool"
403
- }
404
- ],
405
- payable: false,
406
- stateMutability: "nonpayable",
407
- type: "function"
408
- },
409
- {
410
- constant: true,
411
- inputs: [],
412
- name: "decimals",
413
- outputs: [
414
- {
415
- name: "",
416
- type: "uint8"
417
- }
418
- ],
419
- payable: false,
420
- stateMutability: "view",
421
- type: "function"
422
- },
423
- {
424
- constant: true,
425
- inputs: [
426
- {
427
- name: "_owner",
428
- type: "address"
429
- }
430
- ],
431
- name: "balanceOf",
432
- outputs: [
433
- {
434
- name: "balance",
435
- type: "uint256"
436
- }
437
- ],
438
- payable: false,
439
- stateMutability: "view",
440
- type: "function"
441
- },
442
- {
443
- constant: true,
444
- inputs: [],
445
- name: "symbol",
446
- outputs: [
447
- {
448
- name: "",
449
- type: "string"
450
- }
451
- ],
452
- payable: false,
453
- stateMutability: "view",
454
- type: "function"
455
- },
456
- {
457
- constant: false,
458
- inputs: [
459
- {
460
- name: "_to",
461
- type: "address"
462
- },
463
- {
464
- name: "_value",
465
- type: "uint256"
466
- }
467
- ],
468
- name: "transfer",
469
- outputs: [
470
- {
471
- name: "",
472
- type: "bool"
473
- }
474
- ],
475
- payable: false,
476
- stateMutability: "nonpayable",
477
- type: "function"
478
- },
479
- {
480
- constant: true,
481
- inputs: [
482
- {
483
- name: "_owner",
484
- type: "address"
485
- },
486
- {
487
- name: "_spender",
488
- type: "address"
489
- }
490
- ],
491
- name: "allowance",
492
- outputs: [
493
- {
494
- name: "",
495
- type: "uint256"
496
- }
497
- ],
498
- payable: false,
499
- stateMutability: "view",
500
- type: "function"
501
- },
502
- {
503
- payable: true,
504
- stateMutability: "payable",
505
- type: "fallback"
506
- },
507
- {
508
- anonymous: false,
509
- inputs: [
510
- {
511
- indexed: true,
512
- name: "owner",
513
- type: "address"
514
- },
515
- {
516
- indexed: true,
517
- name: "spender",
518
- type: "address"
519
- },
520
- {
521
- indexed: false,
522
- name: "value",
523
- type: "uint256"
524
- }
525
- ],
526
- name: "Approval",
527
- type: "event"
528
- },
529
- {
530
- anonymous: false,
531
- inputs: [
532
- {
533
- indexed: true,
534
- name: "from",
535
- type: "address"
536
- },
537
- {
538
- indexed: true,
539
- name: "to",
540
- type: "address"
541
- },
542
- {
543
- indexed: false,
544
- name: "value",
545
- type: "uint256"
546
- }
547
- ],
548
- name: "Transfer",
549
- type: "event"
550
- }
551
- ];
552
-
553
- // src/balance/BalanceBuilder.ts
554
- function BalanceBuilder() {
555
- return {
556
- evm,
557
- substrate
558
- };
559
- }
560
- function evm() {
561
- return {
562
- erc20,
563
- native
564
- };
565
- }
566
- function erc20() {
567
- return {
568
- build: ({ asset, address }) => {
569
- if (!asset.address) {
570
- throw new Error(`Asset ${asset.key} has no address`);
571
- }
572
- return new ContractConfig({
573
- address: asset.address,
574
- abi: ERC20_ABI,
575
- args: [address],
576
- func: "balanceOf",
577
- module: "Erc20"
578
- });
579
- }
580
- };
581
- }
582
- function native() {
583
- return {
584
- build: ({ address }) => {
585
- return new EvmQueryConfig({
586
- func: "getBalance",
587
- args: [{ address }]
588
- });
589
- }
590
- };
591
- }
592
- function substrate() {
593
- return {
594
- assets: assets2,
595
- system,
596
- tokens
597
- };
598
- }
599
- function assets2() {
600
- return {
601
- account: () => ({
602
- build: ({ address, asset }) => new SubstrateQueryConfig({
603
- module: "assets",
604
- func: "account",
605
- args: [asset.getBalanceAssetId(), address],
606
- transform: async (response) => response.unwrapOrDefault().balance.toBigInt()
607
- })
608
- })
609
- };
610
- }
611
- function system() {
612
- return {
613
- account: () => ({
614
- build: ({ address }) => new SubstrateQueryConfig({
615
- module: "system",
616
- func: "account",
617
- args: [address],
618
- transform: async (response) => calculateSystemAccountBalance(response)
619
- })
620
- }),
621
- accountEquilibrium: () => ({
622
- build: ({ address, asset }) => new SubstrateQueryConfig({
623
- module: "system",
624
- func: "account",
625
- args: [address],
626
- transform: async (response) => {
627
- if (response.data.isEmpty) {
628
- return 0n;
629
- }
630
- const res = response.data.toJSON();
631
- let balances;
632
- if (Array.isArray(res)) {
633
- balances = res;
634
- }
635
- if (Array.isArray(res?.v0?.balance)) {
636
- balances = res.v0.balance;
637
- }
638
- if (!balances) {
639
- throw new Error("Can't get balance from Equilibrium chain");
640
- }
641
- const balance = balances.find(
642
- ([assetId]) => assetId === asset.getBalanceAssetId()
643
- );
644
- if (!balance) {
645
- return 0n;
646
- }
647
- return BigInt(balance[1].positive);
648
- }
649
- })
650
- }),
651
- accountEvmTo32: () => ({
652
- build: ({ address }) => {
653
- const substrateAddress = evmToAddress2(address);
654
- return new SubstrateQueryConfig({
655
- module: "system",
656
- func: "account",
657
- args: [substrateAddress],
658
- transform: async (response) => calculateSystemAccountBalance(response)
659
- });
660
- }
661
- })
662
- };
663
- }
664
- function tokens() {
665
- return {
666
- accounts: () => ({
667
- build: ({ address, asset }) => new SubstrateQueryConfig({
668
- module: "tokens",
669
- func: "accounts",
670
- args: [address, asset.getBalanceAssetId()],
671
- transform: async ({
672
- free,
673
- frozen
674
- }) => BigInt(free.sub(frozen).toString())
675
- })
676
- })
677
- };
678
- }
679
- async function calculateSystemAccountBalance(response) {
680
- const balance = response.data;
681
- const free = BigInt(balance.free.toString());
682
- const frozen = balance.miscFrozen ?? balance.frozen;
683
- const frozenMinusReserved = BigInt(frozen.sub(balance.reserved).toString());
684
- const locked = frozenMinusReserved < 0n ? 0n : frozenMinusReserved;
685
- return free - locked;
686
- }
687
-
688
- // src/types/substrate/ExtrinsicConfig.ts
689
- var ExtrinsicConfig = class _ExtrinsicConfig extends BaseConfig {
690
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
691
- getArgs;
692
- static is(obj) {
693
- return obj instanceof _ExtrinsicConfig;
694
- }
695
- constructor({ getArgs, ...other }) {
696
- super({ ...other });
697
- this.getArgs = getArgs;
698
- }
699
- };
700
-
701
- // src/extrinsic/ExtrinsicBuilder.utils.ts
702
- import { getTypeDef } from "@polkadot/types";
703
- import { u8aToHex as u8aToHex3 } from "@polkadot/util";
704
- import { decodeAddress as decodeAddress3 } from "@polkadot/util-crypto";
705
-
706
- // src/extrinsic/ExtrinsicBuilder.interfaces.ts
707
- var XcmVersion = /* @__PURE__ */ ((XcmVersion2) => {
708
- XcmVersion2["v1"] = "V1";
709
- XcmVersion2["v2"] = "V2";
710
- XcmVersion2["v3"] = "V3";
711
- XcmVersion2["v4"] = "V4";
712
- XcmVersion2["v5"] = "V5";
713
- return XcmVersion2;
714
- })(XcmVersion || {});
715
-
716
- // src/extrinsic/ExtrinsicBuilder.utils.ts
717
- function getExtrinsicArgumentVersion(func, index = 0) {
718
- if (!func) return "V1" /* v1 */;
719
- const { type } = func.meta.args[index];
720
- const instance = func.meta.registry.createType(type.toString());
721
- const raw = getTypeDef(instance?.toRawType());
722
- if (!raw.sub) {
723
- return "V1" /* v1 */;
724
- }
725
- const versions = Array.isArray(raw.sub) ? raw.sub.map((x) => x.name) : [raw.sub.name];
726
- if (versions.includes("V5" /* v5 */)) {
727
- return "V5" /* v5 */;
728
- }
729
- if (versions.includes("V4" /* v4 */)) {
730
- return "V4" /* v4 */;
731
- }
732
- if (versions.includes("V3" /* v3 */)) {
733
- return "V3" /* v3 */;
734
- }
735
- if (versions.includes("V2" /* v2 */)) {
736
- return "V2" /* v2 */;
737
- }
738
- if (versions.includes("V1" /* v1 */)) {
739
- return "V1" /* v1 */;
740
- }
741
- throw new Error("Can't find XCM version");
742
- }
743
- function getExtrinsicAccount(address) {
744
- const isEthAddress = address.length === 42 && address.startsWith("0x");
745
- return isEthAddress ? {
746
- AccountKey20: {
747
- key: address
748
- }
749
- } : {
750
- AccountId32: {
751
- id: u8aToHex3(decodeAddress3(address)),
752
- network: null
753
- }
754
- };
755
- }
756
- function isXcmV4(xcmVersion) {
757
- return xcmVersion >= "V4" /* v4 */;
758
- }
759
- function normalizeX1(xcmVersion, versionedObject) {
760
- if (!isXcmV4(xcmVersion)) return versionedObject;
761
- const normalizedObject = { ...versionedObject };
762
- const interior = normalizedObject.interior;
763
- if ("X1" in interior && interior?.X1 && !Array.isArray(interior.X1)) {
764
- interior.X1 = [interior.X1];
765
- } else if ("x1" in interior && interior?.x1 && !Array.isArray(interior.x1)) {
766
- interior.x1 = [interior.x1];
767
- }
768
- return normalizedObject;
769
- }
770
- function normalizeConcrete(xcmVersion, versionedObject) {
771
- return isXcmV4(xcmVersion) ? versionedObject : applyConcreteWrapper(versionedObject);
772
- }
773
- function applyConcreteWrapper(versionedObject) {
774
- return {
775
- Concrete: { ...versionedObject }
776
- };
777
- }
778
-
779
- // src/extrinsic/pallets/eqBalances/eqBalances.ts
780
- var pallet = "eqBalances";
781
- function eqBalances() {
782
- return {
783
- xcmTransfer: () => ({
784
- build: ({ destinationAddress, asset, destination }) => new ExtrinsicConfig({
785
- module: pallet,
786
- func: "xcmTransfer",
787
- getArgs: () => [
788
- asset.getAssetId(),
789
- asset.amount,
790
- {
791
- parents: 1,
792
- interior: {
793
- X2: [
794
- {
795
- Parachain: destination.parachainId
796
- },
797
- getExtrinsicAccount(destinationAddress)
798
- ]
799
- }
800
- },
801
- "ThisAccWillPay" /* ThisAccWillPay */
802
- ]
803
- })
804
- }),
805
- transferXcm: () => ({
806
- build: ({ destinationAddress: address, asset, destination, fee }) => new ExtrinsicConfig({
807
- module: pallet,
808
- func: "transferXcm",
809
- getArgs: () => {
810
- const amountWithoutFee = asset.amount - fee.amount > 0n ? asset.amount - fee.amount : 0n;
811
- return [
812
- [
813
- asset.getAssetId(),
814
- asset.isSame(fee) ? amountWithoutFee : asset.amount
815
- ],
816
- [fee.getAssetId(), fee.amount],
817
- {
818
- parents: 1,
819
- interior: {
820
- X2: [
821
- {
822
- Parachain: destination.parachainId
823
- },
824
- getExtrinsicAccount(address)
825
- ]
826
- }
827
- }
828
- ];
829
- }
830
- })
831
- })
832
- };
833
- }
834
-
835
- // src/extrinsic/pallets/polkadotXcm/polkadotXcm.util.ts
836
- function getPolkadotXcmExtrinsicArgs({
837
- asset,
838
- destinationAddress,
839
- destination,
840
- func,
841
- parents = 1,
842
- feeIndex = 0
843
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
844
- }) {
845
- const version = getExtrinsicArgumentVersion(func);
846
- return [
847
- {
848
- [version]: normalizeX1(version, {
849
- parents,
850
- interior: {
851
- X1: {
852
- Parachain: destination.parachainId
853
- }
854
- }
855
- })
856
- },
857
- {
858
- [version]: normalizeX1(version, {
859
- parents: 0,
860
- interior: {
861
- X1: getExtrinsicAccount(destinationAddress)
862
- }
863
- })
864
- },
865
- {
866
- [version]: asset
867
- },
868
- feeIndex,
869
- "Unlimited"
870
- ];
871
- }
872
- function shouldFeeAssetPrecedeAsset({
873
- asset,
874
- fee
875
- }) {
876
- const assetIdNumber = Number(asset.getAssetId());
877
- const feeAssetIdNumber = Number(fee.getAssetId());
878
- if (Number.isNaN(assetIdNumber) || Number.isNaN(feeAssetIdNumber)) {
879
- return false;
880
- }
881
- return assetIdNumber > feeAssetIdNumber;
882
- }
883
-
884
- // src/extrinsic/pallets/polkadotXcm/polkadotXcm.ts
885
- var pallet2 = "polkadotXcm";
886
- function polkadotXcm() {
887
- return {
888
- limitedReserveTransferAssets: () => {
889
- const func = "limitedReserveTransferAssets";
890
- return {
891
- here: () => ({
892
- build: (params) => new ExtrinsicConfig({
893
- module: pallet2,
894
- func,
895
- getArgs: (extrinsicFunction) => {
896
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
897
- return getPolkadotXcmExtrinsicArgs({
898
- ...params,
899
- func: extrinsicFunction,
900
- asset: [
901
- {
902
- id: normalizeConcrete(version, {
903
- parents: 0,
904
- interior: "Here"
905
- }),
906
- fun: {
907
- Fungible: params.asset.amount
908
- }
909
- }
910
- ]
911
- });
912
- }
913
- })
914
- }),
915
- X1: () => ({
916
- build: (params) => new ExtrinsicConfig({
917
- module: pallet2,
918
- func,
919
- getArgs: (extrinsicFunction) => {
920
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
921
- return getPolkadotXcmExtrinsicArgs({
922
- ...params,
923
- func: extrinsicFunction,
924
- asset: [
925
- {
926
- id: normalizeConcrete(
927
- version,
928
- normalizeX1(version, {
929
- parents: 0,
930
- interior: {
931
- X1: {
932
- PalletInstance: params.asset.getAssetPalletInstance()
933
- }
934
- }
935
- })
936
- ),
937
- fun: {
938
- Fungible: params.asset.amount
939
- }
940
- }
941
- ]
942
- });
943
- }
944
- })
945
- }),
946
- X2: () => ({
947
- build: (params) => new ExtrinsicConfig({
948
- module: pallet2,
949
- func,
950
- getArgs: (extrinsicFunction) => {
951
- const isAssetDifferent = !params.asset.isSame(params.fee);
952
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
953
- const assets3 = [
954
- {
955
- id: normalizeConcrete(version, {
956
- parents: 0,
957
- interior: {
958
- X2: [
959
- {
960
- PalletInstance: params.asset.getAssetPalletInstance()
961
- },
962
- {
963
- GeneralIndex: params.asset.getAssetId()
964
- }
965
- ]
966
- }
967
- }),
968
- fun: {
969
- Fungible: params.asset.amount
970
- }
971
- }
972
- ];
973
- const shouldFeeAssetPrecede = shouldFeeAssetPrecedeAsset(params);
974
- if (isAssetDifferent) {
975
- const feeAsset = {
976
- id: normalizeConcrete(version, {
977
- parents: 0,
978
- interior: {
979
- X2: [
980
- {
981
- PalletInstance: params.fee.getAssetPalletInstance()
982
- },
983
- {
984
- GeneralIndex: params.fee.getAssetId()
985
- }
986
- ]
987
- }
988
- }),
989
- fun: {
990
- Fungible: params.fee.amount
991
- }
992
- };
993
- if (shouldFeeAssetPrecede) {
994
- assets3.unshift(feeAsset);
995
- } else {
996
- assets3.push(feeAsset);
997
- }
998
- }
999
- return getPolkadotXcmExtrinsicArgs({
1000
- ...params,
1001
- func: extrinsicFunction,
1002
- asset: assets3,
1003
- feeIndex: isAssetDifferent && !shouldFeeAssetPrecede ? 1 : 0
1004
- });
1005
- }
1006
- })
1007
- })
1008
- };
1009
- },
1010
- limitedReserveWithdrawAssets: () => {
1011
- const func = "limitedReserveWithdrawAssets";
1012
- return {
1013
- X2: () => ({
1014
- build: (params) => new ExtrinsicConfig({
1015
- module: pallet2,
1016
- func,
1017
- getArgs: (extrinsicFunction) => {
1018
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
1019
- return getPolkadotXcmExtrinsicArgs({
1020
- ...params,
1021
- func: extrinsicFunction,
1022
- asset: [
1023
- {
1024
- id: normalizeConcrete(version, {
1025
- parents: 1,
1026
- interior: {
1027
- X2: [
1028
- {
1029
- Parachain: params.destination.parachainId
1030
- },
1031
- {
1032
- PalletInstance: params.asset.getAssetPalletInstance()
1033
- }
1034
- ]
1035
- }
1036
- }),
1037
- fun: {
1038
- Fungible: params.asset.amount
1039
- }
1040
- }
1041
- ]
1042
- });
1043
- }
1044
- })
1045
- })
1046
- };
1047
- },
1048
- transferAssets: () => {
1049
- const func = "transferAssets";
1050
- return {
1051
- here: () => ({
1052
- build: (params) => new ExtrinsicConfig({
1053
- module: pallet2,
1054
- func,
1055
- getArgs: (extrinsicFunction) => {
1056
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
1057
- return getPolkadotXcmExtrinsicArgs({
1058
- ...params,
1059
- func: extrinsicFunction,
1060
- asset: [
1061
- {
1062
- id: normalizeConcrete(version, {
1063
- parents: 1,
1064
- interior: "Here"
1065
- }),
1066
- fun: {
1067
- Fungible: params.asset.amount
1068
- }
1069
- }
1070
- ]
1071
- });
1072
- }
1073
- })
1074
- })
1075
- };
1076
- }
1077
- };
1078
- }
1079
-
1080
- // src/extrinsic/pallets/xTokens/xTokens.utils.ts
1081
- function getWeight() {
1082
- return "Unlimited";
1083
- }
1084
- function getDestination(version, address, destination) {
1085
- return {
1086
- [version]: {
1087
- parents: 1,
1088
- interior: {
1089
- X2: [
1090
- {
1091
- Parachain: destination.parachainId
1092
- },
1093
- getExtrinsicAccount(address)
1094
- ]
1095
- }
1096
- }
1097
- };
1098
- }
1099
-
1100
- // src/extrinsic/pallets/xTokens/xTokens.ts
1101
- var pallet3 = "xTokens";
1102
- function xTokens() {
1103
- return {
1104
- transfer: () => ({
1105
- build: ({ destinationAddress, asset, destination }) => new ExtrinsicConfig({
1106
- module: pallet3,
1107
- func: "transfer",
1108
- getArgs: (func) => {
1109
- const destIndex = 2;
1110
- const version = getExtrinsicArgumentVersion(func, destIndex);
1111
- return [
1112
- asset.getAssetId(),
1113
- asset.amount,
1114
- getDestination(version, destinationAddress, destination),
1115
- getWeight()
1116
- ];
1117
- }
1118
- })
1119
- }),
1120
- transferMultiAsset: (originParachainId) => {
1121
- const funcName = "transferMultiasset";
1122
- const destIndex = 1;
1123
- return {
1124
- here: () => ({
1125
- build: ({ destinationAddress: address, asset, destination }) => new ExtrinsicConfig({
1126
- module: pallet3,
1127
- func: funcName,
1128
- getArgs: (func) => {
1129
- const version = getExtrinsicArgumentVersion(func, destIndex);
1130
- return [
1131
- {
1132
- [version]: {
1133
- id: normalizeConcrete(version, {
1134
- parents: 0,
1135
- interior: "Here"
1136
- }),
1137
- fun: {
1138
- Fungible: asset.amount
1139
- }
1140
- }
1141
- },
1142
- getDestination(version, address, destination),
1143
- getWeight()
1144
- ];
1145
- }
1146
- })
1147
- }),
1148
- X1: () => ({
1149
- build: ({ destinationAddress: address, asset, destination }) => new ExtrinsicConfig({
1150
- module: pallet3,
1151
- func: funcName,
1152
- getArgs: (func) => {
1153
- const version = getExtrinsicArgumentVersion(func, destIndex);
1154
- return [
1155
- {
1156
- [version]: {
1157
- id: normalizeConcrete(
1158
- version,
1159
- normalizeX1(version, {
1160
- parents: 1,
1161
- interior: {
1162
- X1: {
1163
- Parachain: originParachainId
1164
- }
1165
- }
1166
- })
1167
- ),
1168
- fun: {
1169
- Fungible: asset.amount
1170
- }
1171
- }
1172
- },
1173
- getDestination(version, address, destination),
1174
- getWeight()
1175
- ];
1176
- }
1177
- })
1178
- }),
1179
- X2: () => ({
1180
- build: ({ destinationAddress: address, asset, destination }) => new ExtrinsicConfig({
1181
- module: pallet3,
1182
- func: funcName,
1183
- getArgs: (func) => {
1184
- const version = getExtrinsicArgumentVersion(func, destIndex);
1185
- return [
1186
- {
1187
- [version]: {
1188
- id: normalizeConcrete(version, {
1189
- parents: 1,
1190
- interior: {
1191
- X2: [
1192
- {
1193
- Parachain: originParachainId
1194
- },
1195
- {
1196
- GeneralKey: asset.getAssetId()
1197
- }
1198
- ]
1199
- }
1200
- }),
1201
- fun: {
1202
- Fungible: asset.amount
1203
- }
1204
- }
1205
- },
1206
- getDestination(version, address, destination),
1207
- getWeight()
1208
- ];
1209
- }
1210
- })
1211
- })
1212
- };
1213
- },
1214
- transferMultiCurrencies: () => ({
1215
- build: ({ destinationAddress: address, asset, destination, fee }) => new ExtrinsicConfig({
1216
- module: pallet3,
1217
- func: "transferMulticurrencies",
1218
- getArgs: () => [
1219
- [
1220
- [asset.getAssetId(), asset.amount],
1221
- [fee.getAssetId(), fee.amount]
1222
- ],
1223
- 1,
1224
- getDestination("V3" /* v3 */, address, destination),
1225
- getWeight()
1226
- ]
1227
- })
1228
- })
1229
- };
1230
- }
1231
-
1232
- // src/extrinsic/pallets/xTransfer/xTransfer.ts
1233
- var pallet4 = "xTransfer";
1234
- function xTransfer() {
1235
- return {
1236
- transfer: () => {
1237
- const method = "transfer";
1238
- return {
1239
- here: () => ({
1240
- build: ({ destinationAddress: address, asset, destination }) => new ExtrinsicConfig({
1241
- module: pallet4,
1242
- func: method,
1243
- getArgs: () => [
1244
- {
1245
- id: {
1246
- Concrete: {
1247
- parents: 0,
1248
- interior: "Here"
1249
- }
1250
- },
1251
- fun: {
1252
- Fungible: asset.amount
1253
- }
1254
- },
1255
- {
1256
- parents: 1,
1257
- interior: {
1258
- X2: [
1259
- {
1260
- Parachain: destination.parachainId
1261
- },
1262
- getExtrinsicAccount(address)
1263
- ]
1264
- }
1265
- },
1266
- {
1267
- refTime: 5e9,
1268
- proofSize: 0
1269
- }
1270
- ]
1271
- })
1272
- }),
1273
- X2: () => ({
1274
- build: ({ destinationAddress, asset, destination }) => new ExtrinsicConfig({
1275
- module: pallet4,
1276
- func: method,
1277
- getArgs: () => [
1278
- {
1279
- id: {
1280
- Concrete: {
1281
- parents: 1,
1282
- interior: {
1283
- X2: [
1284
- {
1285
- Parachain: destination.parachainId
1286
- },
1287
- {
1288
- PalletInstance: asset.getAssetPalletInstance()
1289
- }
1290
- ]
1291
- }
1292
- }
1293
- },
1294
- fun: {
1295
- Fungible: asset.amount || 1n
1296
- }
1297
- },
1298
- {
1299
- parents: 1,
1300
- interior: {
1301
- X2: [
1302
- {
1303
- Parachain: destination.parachainId
1304
- },
1305
- getExtrinsicAccount(destinationAddress)
1306
- ]
1307
- }
1308
- },
1309
- {
1310
- refTime: 5e9,
1311
- proofSize: 0
1312
- }
1313
- ]
1314
- })
1315
- })
1316
- };
1317
- }
1318
- };
1319
- }
1320
-
1321
- // src/extrinsic/pallets/xcmPallet/xcmPallet.ts
1322
- var pallet5 = "xcmPallet";
1323
- function xcmPallet() {
1324
- return {
1325
- limitedReserveTransferAssets: (parents = 1) => {
1326
- const func = "limitedReserveTransferAssets";
1327
- return {
1328
- here: () => ({
1329
- build: (params) => new ExtrinsicConfig({
1330
- module: pallet5,
1331
- func,
1332
- getArgs: (extrinsicFunction) => {
1333
- const version = getExtrinsicArgumentVersion(extrinsicFunction);
1334
- return getPolkadotXcmExtrinsicArgs({
1335
- ...params,
1336
- parents,
1337
- func: extrinsicFunction,
1338
- asset: [
1339
- {
1340
- id: normalizeConcrete(version, {
1341
- parents: 0,
1342
- interior: "Here"
1343
- }),
1344
- fun: {
1345
- Fungible: params.asset.amount
1346
- }
1347
- }
1348
- ]
1349
- });
1350
- }
1351
- })
1352
- })
1353
- };
1354
- },
1355
- transferAssetsUsingTypeAndThen: () => {
1356
- const func = "transferAssetsUsingTypeAndThen";
1357
- return {
1358
- here: () => ({
1359
- build: (params) => new ExtrinsicConfig({
1360
- module: pallet5,
1361
- func,
1362
- getArgs: () => {
1363
- const version = "V4" /* v4 */;
1364
- return [
1365
- {
1366
- [version]: {
1367
- parents: 0,
1368
- interior: {
1369
- X1: [
1370
- {
1371
- Parachain: params.destination.parachainId
1372
- }
1373
- ]
1374
- }
1375
- }
1376
- },
1377
- {
1378
- [version]: [
1379
- {
1380
- id: {
1381
- parents: 0,
1382
- interior: "Here"
1383
- },
1384
- fun: {
1385
- Fungible: params.asset.amount
1386
- }
1387
- }
1388
- ]
1389
- },
1390
- "LocalReserve",
1391
- {
1392
- [version]: {
1393
- parents: 0,
1394
- interior: "Here"
1395
- }
1396
- },
1397
- "LocalReserve",
1398
- {
1399
- [version]: [
1400
- {
1401
- DepositAsset: {
1402
- assets: {
1403
- Wild: { AllCounted: 1 }
1404
- },
1405
- beneficiary: {
1406
- parents: 0,
1407
- interior: {
1408
- X1: [
1409
- getExtrinsicAccount(params.destinationAddress)
1410
- ]
1411
- }
1412
- }
1413
- }
1414
- }
1415
- ]
1416
- },
1417
- "Unlimited"
1418
- ];
1419
- }
1420
- })
1421
- })
1422
- };
1423
- }
1424
- };
1425
- }
1426
-
1427
- // src/extrinsic/ExtrinsicBuilder.ts
1428
- function ExtrinsicBuilder() {
1429
- return {
1430
- eqBalances,
1431
- xTokens,
1432
- xTransfer,
1433
- polkadotXcm,
1434
- xcmPallet
1435
- };
1436
- }
1437
-
1438
- // src/types/substrate/SubstrateCallConfig.ts
1439
- var SubstrateCallConfig = class _SubstrateCallConfig {
1440
- api;
1441
- // biome-ignore lint/suspicious/noExplicitAny: not sure how to fix this
1442
- call;
1443
- static is(obj) {
1444
- return obj instanceof _SubstrateCallConfig;
1445
- }
1446
- constructor({ api, call }) {
1447
- this.api = api;
1448
- this.call = call;
1449
- }
1450
- };
1451
-
1452
- // src/fee/FeeBuilder.utils.ts
1453
- var DEFAULT_AMOUNT = 10 ** 6;
1454
- var DEFAULT_HEX_STRING = "0xabcdef1234567890fedcba0987654321abcdef1234567890fedcba0987654321";
1455
- var XCM_VERSION = "V4" /* v4 */;
1456
- function isXcmV42() {
1457
- return XCM_VERSION === "V4" /* v4 */;
1458
- }
1459
- function getWithdrawAssetInstruction(assetTypes) {
1460
- return {
1461
- WithdrawAsset: assetTypes.map((assetType) => ({
1462
- id: { ...assetType },
1463
- fun: {
1464
- Fungible: DEFAULT_AMOUNT
1465
- }
1466
- }))
1467
- };
1468
- }
1469
- function getReserveAssetDepositedInstruction(assetTypes) {
1470
- return {
1471
- ReserveAssetDeposited: assetTypes.map((assetType) => ({
1472
- id: { ...assetType },
1473
- fun: {
1474
- Fungible: DEFAULT_AMOUNT
1475
- }
1476
- }))
1477
- };
1478
- }
1479
- function getClearOriginInstruction() {
1480
- return {
1481
- ClearOrigin: "NULL"
1482
- };
1483
- }
1484
- function getBuyExecutionInstruction(assetType) {
1485
- return {
1486
- BuyExecution: {
1487
- fees: {
1488
- id: {
1489
- ...assetType
1490
- },
1491
- fun: {
1492
- Fungible: DEFAULT_AMOUNT
1493
- }
1494
- },
1495
- weight_limit: {
1496
- Unlimited: "NULL"
1497
- }
1498
- }
1499
- };
1500
- }
1501
- function getDepositAssetInstruction(address, assets3) {
1502
- const accountKey = {
1503
- AccountKey20: {
1504
- key: address,
1505
- network: null
1506
- }
1507
- };
1508
- return {
1509
- DepositAsset: {
1510
- assets: {
1511
- Wild: {
1512
- AllCounted: assets3.length
1513
- }
1514
- },
1515
- beneficiary: {
1516
- interior: {
1517
- X1: isXcmV42() ? [accountKey] : accountKey
1518
- },
1519
- parents: 0
1520
- },
1521
- max_assets: 0
1522
- }
1523
- };
1524
- }
1525
- function getSetTopicInstruction() {
1526
- return {
1527
- SetTopic: DEFAULT_HEX_STRING
1528
- };
1529
- }
1530
- function getNativeAssetId(palletInstanceNumber) {
1531
- if (!palletInstanceNumber) {
1532
- throw new Error(
1533
- "No pallet instance configured for the native asset for XcmPaymentApi fee calculation"
1534
- );
1535
- }
1536
- const palletInstance = {
1537
- PalletInstance: palletInstanceNumber
1538
- };
1539
- const id = {
1540
- interior: {
1541
- X1: isXcmV42() ? [palletInstance] : palletInstance
1542
- },
1543
- parents: "0"
1544
- };
1545
- return normalizeConcrete(XCM_VERSION, id);
1546
- }
1547
- function getConcreteAssetIdWithAccountKey20(asset, palletInstance) {
1548
- if (!palletInstance) {
1549
- throw new Error(
1550
- `No pallet instance configured for the asset ${asset} for XcmPaymentApi fee calculation`
1551
- );
1552
- }
1553
- const id = {
1554
- interior: {
1555
- X2: [
1556
- {
1557
- PalletInstance: palletInstance
1558
- },
1559
- {
1560
- AccountKey20: {
1561
- key: asset,
1562
- network: null
1563
- }
1564
- }
1565
- ]
1566
- },
1567
- parents: "0"
1568
- };
1569
- return normalizeConcrete(XCM_VERSION, id);
1570
- }
1571
- async function getAssetIdType(api, asset) {
1572
- const type = await api.query.assetManager.assetIdType(asset);
1573
- if (type.isNone || !type.unwrap().isXcm) {
1574
- throw new Error(`No asset type found for asset ${asset}`);
1575
- }
1576
- return type;
1577
- }
1578
- async function getVersionedAssetId(api, asset, chain) {
1579
- const assetId = asset.getAssetId();
1580
- const palletInstance = asset.getAssetPalletInstance();
1581
- if (assetId === chain.nativeAsset.originSymbol) {
1582
- return getNativeAssetId(palletInstance);
1583
- }
1584
- if (asset.hasOnlyAddress()) {
1585
- return getConcreteAssetIdWithAccountKey20(asset.address, palletInstance);
1586
- }
1587
- const assetType = await getAssetIdType(api, assetId);
1588
- const assetTypeObject = assetType.unwrap().asXcm.toJSON();
1589
- const normalizedAssetTypeObject = normalizeX1(XCM_VERSION, assetTypeObject);
1590
- return normalizeConcrete(XCM_VERSION, normalizedAssetTypeObject);
1591
- }
1592
- async function getFeeForXcmInstructionsAndAsset(api, instructions, versionedAssetId) {
1593
- const xcmToWeightResult = await api.call.xcmPaymentApi.queryXcmWeight({
1594
- [XCM_VERSION]: instructions
1595
- });
1596
- if (!xcmToWeightResult.isOk) {
1597
- throw new Error(
1598
- "There was an error trying to get the weight for the xcm instructions (queryXcmWeight)"
1599
- );
1600
- }
1601
- const xcmToWeight = xcmToWeightResult.asOk;
1602
- const weightToForeignAssets = await api.call.xcmPaymentApi.queryWeightToAssetFee(xcmToWeight, {
1603
- [XCM_VERSION]: {
1604
- ...versionedAssetId
1605
- }
1606
- });
1607
- if (!weightToForeignAssets.isOk) {
1608
- throw new Error(
1609
- "There was an error trying to get the fee with the weight and asset (weightToForeignAssets)"
1610
- );
1611
- }
1612
- return weightToForeignAssets.asOk.toBigInt();
1613
- }
1614
-
1615
- // src/fee/FeeBuilder.ts
1616
- function FeeBuilder() {
1617
- return {
1618
- xcmPaymentApi
1619
- };
1620
- }
1621
- function xcmPaymentApi() {
1622
- return {
1623
- xcmPaymentFee: ({
1624
- isAssetReserveChain,
1625
- shouldTransferAssetPrecedeFeeAsset = false
1626
- }) => ({
1627
- build: ({
1628
- address,
1629
- api,
1630
- asset,
1631
- destination,
1632
- feeAsset
1633
- }) => new SubstrateCallConfig({
1634
- api,
1635
- call: async () => {
1636
- const versionedFeeAssetId = await getVersionedAssetId(
1637
- api,
1638
- feeAsset,
1639
- destination
1640
- );
1641
- const versionedTransferAssetId = await getVersionedAssetId(
1642
- api,
1643
- asset,
1644
- destination
1645
- );
1646
- const versionedAssets = shouldTransferAssetPrecedeFeeAsset ? [versionedTransferAssetId, versionedFeeAssetId] : [versionedFeeAssetId, versionedTransferAssetId];
1647
- const assets3 = feeAsset === asset ? [versionedFeeAssetId] : versionedAssets;
1648
- const instructions = [
1649
- isAssetReserveChain ? getWithdrawAssetInstruction(assets3) : getReserveAssetDepositedInstruction(assets3),
1650
- getClearOriginInstruction(),
1651
- getBuyExecutionInstruction(versionedFeeAssetId),
1652
- getDepositAssetInstruction(address, assets3),
1653
- getSetTopicInstruction()
1654
- ];
1655
- return getFeeForXcmInstructionsAndAsset(
1656
- api,
1657
- instructions,
1658
- versionedFeeAssetId
1659
- );
1660
- }
1661
- })
1662
- })
1663
- };
1664
- }
1665
-
1666
- // src/mrl/providers/wormhole/contract/Batch/Batch.ts
1667
- import {
1668
- EvmParachain as EvmParachain2
1669
- } from "@moonbeam-network/xcm-types";
1670
- import { getMultilocationDerivedAddresses as getMultilocationDerivedAddresses2 } from "@moonbeam-network/xcm-utils";
1671
- import { evmToAddress as evmToAddress3 } from "@polkadot/util-crypto";
1672
- import { encodeFunctionData as encodeFunctionData2, maxUint64 } from "viem";
1673
-
1674
- // src/mrl/providers/wormhole/extrinsic/polkadotXcm/polkadotXcm.ts
1675
- import {
1676
- AssetAmount,
1677
- Parachain
1678
- } from "@moonbeam-network/xcm-types";
1679
- import { getMultilocationDerivedAddresses } from "@moonbeam-network/xcm-utils";
1680
- var BUY_EXECUTION_FEE = 100000000000000000n;
1681
- var CROSS_CHAIN_FEE = 100000000000000000n;
1682
- function polkadotXcm2() {
1683
- return {
1684
- send: () => ({
1685
- build: ({
1686
- asset,
1687
- destination,
1688
- destinationAddress,
1689
- fee,
1690
- isAutomatic,
1691
- moonAsset,
1692
- moonChain,
1693
- moonApi,
1694
- source,
1695
- sourceAddress,
1696
- sourceApi,
1697
- transact
1698
- }) => {
1699
- if (!destination.wh?.name) {
1700
- throw new Error("Destination chain does not have a wormhole name");
1701
- }
1702
- if (!sourceApi) {
1703
- throw new Error("Source API needs to be defined");
1704
- }
1705
- if (!Parachain.is(source)) {
1706
- throw new Error("Source chain needs to be a parachain");
1707
- }
1708
- const { address20: computedOriginAccount } = getMultilocationDerivedAddresses({
1709
- address: sourceAddress,
1710
- paraId: source.parachainId,
1711
- isParents: true
1712
- });
1713
- const assetTransferTxs = getAssetTransferTxs({
1714
- asset,
1715
- computedOriginAccount,
1716
- destination,
1717
- destinationAddress,
1718
- fee,
1719
- isAutomatic,
1720
- moonApi,
1721
- moonAsset,
1722
- moonChain,
1723
- source,
1724
- sourceAddress,
1725
- sourceApi
1726
- });
1727
- const send = buildSendExtrinsic({
1728
- asset,
1729
- destination,
1730
- destinationAddress,
1731
- computedOriginAccount,
1732
- fee,
1733
- isAutomatic,
1734
- moonAsset,
1735
- moonChain,
1736
- moonApi,
1737
- source,
1738
- sourceAddress,
1739
- sourceApi,
1740
- transact
1741
- });
1742
- return new ExtrinsicConfig({
1743
- module: "utility",
1744
- func: "batchAll",
1745
- getArgs: () => [[...assetTransferTxs, send]]
1746
- });
1747
- }
1748
- })
1749
- };
1750
- }
1751
- function buildSendExtrinsic({
1752
- computedOriginAccount,
1753
- moonAsset,
1754
- moonChain,
1755
- sourceApi,
1756
- transact
1757
- }) {
1758
- if (!transact) {
1759
- throw new Error("Transact params are required");
1760
- }
1761
- return sourceApi.tx.polkadotXcm.send(
1762
- {
1763
- // TODO apply XCM versioning
1764
- V3: {
1765
- parents: 1,
1766
- interior: { X1: { Parachain: moonChain.parachainId } }
1767
- }
1768
- },
1769
- {
1770
- V3: [
1771
- {
1772
- WithdrawAsset: [
1773
- {
1774
- id: {
1775
- Concrete: {
1776
- parents: 0,
1777
- interior: {
1778
- X1: {
1779
- PalletInstance: moonAsset.getAssetPalletInstance()
1780
- }
1781
- }
1782
- }
1783
- },
1784
- fun: { Fungible: BUY_EXECUTION_FEE }
1785
- }
1786
- ]
1787
- },
1788
- {
1789
- BuyExecution: {
1790
- fees: {
1791
- id: {
1792
- Concrete: {
1793
- parents: 0,
1794
- interior: {
1795
- X1: {
1796
- PalletInstance: moonAsset.getAssetPalletInstance()
1797
- }
1798
- }
1799
- }
1800
- },
1801
- fun: { Fungible: BUY_EXECUTION_FEE }
1802
- },
1803
- weightLimit: "Unlimited"
1804
- }
1805
- },
1806
- {
1807
- Transact: {
1808
- originKind: "SovereignAccount",
1809
- requireWeightAtMost: {
1810
- refTime: transact.txWeight.refTime,
1811
- proofSize: transact.txWeight.proofSize
1812
- },
1813
- call: {
1814
- encoded: transact.call
1815
- }
1816
- }
1817
- },
1818
- {
1819
- SetAppendix: [
1820
- { RefundSurplus: {} },
1821
- {
1822
- DepositAsset: {
1823
- assets: { Wild: { AllCounted: 1 } },
1824
- beneficiary: {
1825
- parents: 0,
1826
- interior: {
1827
- X1: { AccountKey20: { key: computedOriginAccount } }
1828
- }
1829
- }
1830
- }
1831
- }
1832
- ]
1833
- }
1834
- ]
1835
- }
1836
- );
1837
- }
1838
- function getAssetTransferTxs({
1839
- asset,
1840
- computedOriginAccount,
1841
- fee,
1842
- moonApi,
1843
- moonAsset,
1844
- moonChain,
1845
- source,
1846
- sourceAddress,
1847
- sourceApi
1848
- }) {
1849
- const { transfer, transferMulticurrencies } = sourceApi.tx.xTokens;
1850
- const transferBuilder = ExtrinsicBuilder().xTokens().transfer();
1851
- const transferMulticurrenciesBuilder = ExtrinsicBuilder().xTokens().transferMultiCurrencies();
1852
- if (asset.isSame(fee)) {
1853
- const assetTransferTx = transfer(
1854
- ...transferBuilder.build({
1855
- asset: asset.copyWith({
1856
- // TODO for the moment this is only applicable to peaq, AGNG pays for fees and we have to include the cross chain fee
1857
- // for this we have to add a new concept in the config (Cross Chain Fee), and get the value from there
1858
- amount: asset.amount + 10n * CROSS_CHAIN_FEE
1859
- }),
1860
- destination: moonChain,
1861
- destinationAddress: computedOriginAccount,
1862
- destinationApi: moonApi,
1863
- fee,
1864
- source,
1865
- sourceAddress,
1866
- sourceApi
1867
- }).getArgs(transfer)
1868
- );
1869
- const feeAssetTransferTx = transfer(
1870
- ...transferBuilder.build({
1871
- asset: AssetAmount.fromChainAsset(source.getChainAsset(moonAsset), {
1872
- amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE
1873
- }),
1874
- destination: moonChain,
1875
- destinationAddress: computedOriginAccount,
1876
- destinationApi: moonApi,
1877
- fee,
1878
- source,
1879
- sourceAddress,
1880
- sourceApi
1881
- }).getArgs(transfer)
1882
- );
1883
- return [assetTransferTx, feeAssetTransferTx];
1884
- }
1885
- const multiCurrenciesTransferTx = transferMulticurrencies(
1886
- ...transferMulticurrenciesBuilder.build({
1887
- asset,
1888
- destination: moonChain,
1889
- destinationAddress: computedOriginAccount,
1890
- destinationApi: moonApi,
1891
- fee: AssetAmount.fromChainAsset(source.getChainAsset(moonAsset), {
1892
- amount: CROSS_CHAIN_FEE + BUY_EXECUTION_FEE
1893
- }),
1894
- source,
1895
- sourceAddress,
1896
- sourceApi
1897
- }).getArgs(transferMulticurrencies)
1898
- );
1899
- return [multiCurrenciesTransferTx];
1900
- }
1901
-
1902
- // src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqBatchContractAbi.ts
1903
- var PEAQ_BATCH_ABI = [
1904
- {
1905
- anonymous: false,
1906
- inputs: [
1907
- {
1908
- indexed: false,
1909
- internalType: "uint256",
1910
- name: "index",
1911
- type: "uint256"
1912
- }
1913
- ],
1914
- name: "SubcallFailed",
1915
- type: "event"
1916
- },
1917
- {
1918
- anonymous: false,
1919
- inputs: [
1920
- {
1921
- indexed: false,
1922
- internalType: "uint256",
1923
- name: "index",
1924
- type: "uint256"
1925
- }
1926
- ],
1927
- name: "SubcallSucceeded",
1928
- type: "event"
1929
- },
1930
- {
1931
- inputs: [
1932
- {
1933
- internalType: "address[]",
1934
- name: "to",
1935
- type: "address[]"
1936
- },
1937
- {
1938
- internalType: "uint256[]",
1939
- name: "value",
1940
- type: "uint256[]"
1941
- },
1942
- {
1943
- internalType: "bytes[]",
1944
- name: "callData",
1945
- type: "bytes[]"
1946
- },
1947
- {
1948
- internalType: "uint64[]",
1949
- name: "gasLimit",
1950
- type: "uint64[]"
1951
- }
1952
- ],
1953
- name: "batchAll",
1954
- outputs: [],
1955
- stateMutability: "nonpayable",
1956
- type: "function"
1957
- },
1958
- {
1959
- inputs: [
1960
- {
1961
- internalType: "address[]",
1962
- name: "to",
1963
- type: "address[]"
1964
- },
1965
- {
1966
- internalType: "uint256[]",
1967
- name: "value",
1968
- type: "uint256[]"
1969
- },
1970
- {
1971
- internalType: "bytes[]",
1972
- name: "callData",
1973
- type: "bytes[]"
1974
- },
1975
- {
1976
- internalType: "uint64[]",
1977
- name: "gasLimit",
1978
- type: "uint64[]"
1979
- }
1980
- ],
1981
- name: "batchSome",
1982
- outputs: [],
1983
- stateMutability: "nonpayable",
1984
- type: "function"
1985
- },
1986
- {
1987
- inputs: [
1988
- {
1989
- internalType: "address[]",
1990
- name: "to",
1991
- type: "address[]"
1992
- },
1993
- {
1994
- internalType: "uint256[]",
1995
- name: "value",
1996
- type: "uint256[]"
1997
- },
1998
- {
1999
- internalType: "bytes[]",
2000
- name: "callData",
2001
- type: "bytes[]"
2002
- },
2003
- {
2004
- internalType: "uint64[]",
2005
- name: "gasLimit",
2006
- type: "uint64[]"
2007
- }
2008
- ],
2009
- name: "batchSomeUntilFailure",
2010
- outputs: [],
2011
- stateMutability: "nonpayable",
2012
- type: "function"
2013
- }
2014
- ];
2015
-
2016
- // src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqXcmUtilsContractAbi.ts
2017
- var PEAQ_XCM_UTILS_ABI = [
2018
- {
2019
- inputs: [
2020
- {
2021
- components: [
2022
- {
2023
- internalType: "uint8",
2024
- name: "parents",
2025
- type: "uint8"
2026
- },
2027
- {
2028
- internalType: "bytes[]",
2029
- name: "interior",
2030
- type: "bytes[]"
2031
- }
2032
- ],
2033
- internalType: "struct XcmUtils.Multilocation",
2034
- name: "multilocation",
2035
- type: "tuple"
2036
- }
2037
- ],
2038
- name: "getUnitsPerSecond",
2039
- outputs: [
2040
- {
2041
- internalType: "uint256",
2042
- name: "unitsPerSecond",
2043
- type: "uint256"
2044
- }
2045
- ],
2046
- stateMutability: "view",
2047
- type: "function"
2048
- },
2049
- {
2050
- inputs: [
2051
- {
2052
- internalType: "bytes",
2053
- name: "message",
2054
- type: "bytes"
2055
- }
2056
- ],
2057
- name: "weightMessage",
2058
- outputs: [
2059
- {
2060
- internalType: "uint64",
2061
- name: "weight",
2062
- type: "uint64"
2063
- }
2064
- ],
2065
- stateMutability: "view",
2066
- type: "function"
2067
- },
2068
- {
2069
- inputs: [
2070
- {
2071
- internalType: "bytes",
2072
- name: "message",
2073
- type: "bytes"
2074
- },
2075
- {
2076
- internalType: "uint64",
2077
- name: "maxWeight",
2078
- type: "uint64"
2079
- }
2080
- ],
2081
- name: "xcmExecute",
2082
- outputs: [],
2083
- stateMutability: "nonpayable",
2084
- type: "function"
2085
- },
2086
- {
2087
- inputs: [
2088
- {
2089
- components: [
2090
- {
2091
- internalType: "uint8",
2092
- name: "parents",
2093
- type: "uint8"
2094
- },
2095
- {
2096
- internalType: "bytes[]",
2097
- name: "interior",
2098
- type: "bytes[]"
2099
- }
2100
- ],
2101
- internalType: "struct XcmUtils.Multilocation",
2102
- name: "dest",
2103
- type: "tuple"
2104
- },
2105
- {
2106
- internalType: "bytes",
2107
- name: "message",
2108
- type: "bytes"
2109
- }
2110
- ],
2111
- name: "xcmSend",
2112
- outputs: [],
2113
- stateMutability: "nonpayable",
2114
- type: "function"
2115
- }
2116
- ];
2117
-
2118
- // src/mrl/providers/wormhole/contract/Batch/abi/peaq/PeaqXtokensContractAbi.ts
2119
- var PEAQ_XTOKENS_ABI = [
2120
- {
2121
- inputs: [
2122
- {
2123
- internalType: "address",
2124
- name: "currencyAddress",
2125
- type: "address"
2126
- },
2127
- {
2128
- internalType: "uint256",
2129
- name: "amount",
2130
- type: "uint256"
2131
- },
2132
- {
2133
- components: [
2134
- {
2135
- internalType: "uint8",
2136
- name: "parents",
2137
- type: "uint8"
2138
- },
2139
- {
2140
- internalType: "bytes[]",
2141
- name: "interior",
2142
- type: "bytes[]"
2143
- }
2144
- ],
2145
- internalType: "struct Xtokens.Multilocation",
2146
- name: "destination",
2147
- type: "tuple"
2148
- },
2149
- {
2150
- internalType: "uint64",
2151
- name: "weight",
2152
- type: "uint64"
2153
- }
2154
- ],
2155
- name: "transfer",
2156
- outputs: [],
2157
- stateMutability: "nonpayable",
2158
- type: "function"
2159
- },
2160
- {
2161
- inputs: [
2162
- {
2163
- components: [
2164
- {
2165
- components: [
2166
- {
2167
- internalType: "uint8",
2168
- name: "parents",
2169
- type: "uint8"
2170
- },
2171
- {
2172
- internalType: "bytes[]",
2173
- name: "interior",
2174
- type: "bytes[]"
2175
- }
2176
- ],
2177
- internalType: "struct Xtokens.Multilocation",
2178
- name: "location",
2179
- type: "tuple"
2180
- },
2181
- {
2182
- internalType: "uint256",
2183
- name: "amount",
2184
- type: "uint256"
2185
- }
2186
- ],
2187
- internalType: "struct Xtokens.MultiAsset[]",
2188
- name: "assets",
2189
- type: "tuple[]"
2190
- },
2191
- {
2192
- internalType: "uint32",
2193
- name: "feeItem",
2194
- type: "uint32"
2195
- },
2196
- {
2197
- components: [
2198
- {
2199
- internalType: "uint8",
2200
- name: "parents",
2201
- type: "uint8"
2202
- },
2203
- {
2204
- internalType: "bytes[]",
2205
- name: "interior",
2206
- type: "bytes[]"
2207
- }
2208
- ],
2209
- internalType: "struct Xtokens.Multilocation",
2210
- name: "destination",
2211
- type: "tuple"
2212
- },
2213
- {
2214
- internalType: "uint64",
2215
- name: "weight",
2216
- type: "uint64"
2217
- }
2218
- ],
2219
- name: "transferMultiAssets",
2220
- outputs: [],
2221
- stateMutability: "nonpayable",
2222
- type: "function"
2223
- },
2224
- {
2225
- inputs: [
2226
- {
2227
- components: [
2228
- {
2229
- internalType: "address",
2230
- name: "currencyAddress",
2231
- type: "address"
2232
- },
2233
- {
2234
- internalType: "uint256",
2235
- name: "amount",
2236
- type: "uint256"
2237
- }
2238
- ],
2239
- internalType: "struct Xtokens.Currency[]",
2240
- name: "currencies",
2241
- type: "tuple[]"
2242
- },
2243
- {
2244
- internalType: "uint32",
2245
- name: "feeItem",
2246
- type: "uint32"
2247
- },
2248
- {
2249
- components: [
2250
- {
2251
- internalType: "uint8",
2252
- name: "parents",
2253
- type: "uint8"
2254
- },
2255
- {
2256
- internalType: "bytes[]",
2257
- name: "interior",
2258
- type: "bytes[]"
2259
- }
2260
- ],
2261
- internalType: "struct Xtokens.Multilocation",
2262
- name: "destination",
2263
- type: "tuple"
2264
- },
2265
- {
2266
- internalType: "uint64",
2267
- name: "weight",
2268
- type: "uint64"
2269
- }
2270
- ],
2271
- name: "transferMultiCurrencies",
2272
- outputs: [],
2273
- stateMutability: "nonpayable",
2274
- type: "function"
2275
- },
2276
- {
2277
- inputs: [
2278
- {
2279
- components: [
2280
- {
2281
- internalType: "uint8",
2282
- name: "parents",
2283
- type: "uint8"
2284
- },
2285
- {
2286
- internalType: "bytes[]",
2287
- name: "interior",
2288
- type: "bytes[]"
2289
- }
2290
- ],
2291
- internalType: "struct Xtokens.Multilocation",
2292
- name: "asset",
2293
- type: "tuple"
2294
- },
2295
- {
2296
- internalType: "uint256",
2297
- name: "amount",
2298
- type: "uint256"
2299
- },
2300
- {
2301
- components: [
2302
- {
2303
- internalType: "uint8",
2304
- name: "parents",
2305
- type: "uint8"
2306
- },
2307
- {
2308
- internalType: "bytes[]",
2309
- name: "interior",
2310
- type: "bytes[]"
2311
- }
2312
- ],
2313
- internalType: "struct Xtokens.Multilocation",
2314
- name: "destination",
2315
- type: "tuple"
2316
- },
2317
- {
2318
- internalType: "uint64",
2319
- name: "weight",
2320
- type: "uint64"
2321
- }
2322
- ],
2323
- name: "transferMultiasset",
2324
- outputs: [],
2325
- stateMutability: "nonpayable",
2326
- type: "function"
2327
- },
2328
- {
2329
- inputs: [
2330
- {
2331
- components: [
2332
- {
2333
- internalType: "uint8",
2334
- name: "parents",
2335
- type: "uint8"
2336
- },
2337
- {
2338
- internalType: "bytes[]",
2339
- name: "interior",
2340
- type: "bytes[]"
2341
- }
2342
- ],
2343
- internalType: "struct Xtokens.Multilocation",
2344
- name: "asset",
2345
- type: "tuple"
2346
- },
2347
- {
2348
- internalType: "uint256",
2349
- name: "amount",
2350
- type: "uint256"
2351
- },
2352
- {
2353
- internalType: "uint256",
2354
- name: "fee",
2355
- type: "uint256"
2356
- },
2357
- {
2358
- components: [
2359
- {
2360
- internalType: "uint8",
2361
- name: "parents",
2362
- type: "uint8"
2363
- },
2364
- {
2365
- internalType: "bytes[]",
2366
- name: "interior",
2367
- type: "bytes[]"
2368
- }
2369
- ],
2370
- internalType: "struct Xtokens.Multilocation",
2371
- name: "destination",
2372
- type: "tuple"
2373
- },
2374
- {
2375
- internalType: "uint64",
2376
- name: "weight",
2377
- type: "uint64"
2378
- }
2379
- ],
2380
- name: "transferMultiassetWithFee",
2381
- outputs: [],
2382
- stateMutability: "nonpayable",
2383
- type: "function"
2384
- },
2385
- {
2386
- inputs: [
2387
- {
2388
- internalType: "address",
2389
- name: "currencyAddress",
2390
- type: "address"
2391
- },
2392
- {
2393
- internalType: "uint256",
2394
- name: "amount",
2395
- type: "uint256"
2396
- },
2397
- {
2398
- internalType: "uint256",
2399
- name: "fee",
2400
- type: "uint256"
2401
- },
2402
- {
2403
- components: [
2404
- {
2405
- internalType: "uint8",
2406
- name: "parents",
2407
- type: "uint8"
2408
- },
2409
- {
2410
- internalType: "bytes[]",
2411
- name: "interior",
2412
- type: "bytes[]"
2413
- }
2414
- ],
2415
- internalType: "struct Xtokens.Multilocation",
2416
- name: "destination",
2417
- type: "tuple"
2418
- },
2419
- {
2420
- internalType: "uint64",
2421
- name: "weight",
2422
- type: "uint64"
2423
- }
2424
- ],
2425
- name: "transferWithFee",
2426
- outputs: [],
2427
- stateMutability: "nonpayable",
2428
- type: "function"
2429
- }
2430
- ];
2431
-
2432
- // src/mrl/providers/wormhole/contract/Batch/abi/abi.helpers.ts
2433
- function getAbisForChain(chain) {
2434
- return {
2435
- BatchAbi: PEAQ_BATCH_ABI,
2436
- XcmUtilsAbi: PEAQ_XCM_UTILS_ABI,
2437
- XtokensAbi: PEAQ_XTOKENS_ABI
2438
- };
2439
- }
2440
-
2441
- // src/mrl/providers/wormhole/contract/Batch/Batch.ts
2442
- var module = "Batch";
2443
- function Batch() {
2444
- return {
2445
- transferAssetsAndMessage: () => ({
2446
- build: ({
2447
- asset,
2448
- destination,
2449
- destinationAddress,
2450
- fee,
2451
- isAutomatic,
2452
- moonAsset,
2453
- moonChain,
2454
- moonApi,
2455
- source,
2456
- sourceAddress,
2457
- sourceApi,
2458
- transact
2459
- }) => {
2460
- if (!EvmParachain2.is(source)) {
2461
- throw new Error("Source chain needs to be an EVMParachain");
2462
- }
2463
- if (!sourceApi) {
2464
- throw new Error("Source API needs to be defined");
2465
- }
2466
- if (!source.contracts?.Xtokens || !source.contracts?.XcmUtils || !source.contracts?.Batch) {
2467
- throw new Error(
2468
- "Source chain needs to have the Xtokens, XcmUtils and Batch contract addresses configured"
2469
- );
2470
- }
2471
- const subMappedAddress = evmToAddress3(sourceAddress);
2472
- const { BatchAbi, XcmUtilsAbi, XtokensAbi } = getAbisForChain(source);
2473
- const { address20: computedOriginAccount } = getMultilocationDerivedAddresses2({
2474
- address: subMappedAddress,
2475
- paraId: source.parachainId,
2476
- isParents: true
2477
- });
2478
- const send = buildSendExtrinsic({
2479
- asset,
2480
- destination,
2481
- destinationAddress,
2482
- computedOriginAccount,
2483
- fee,
2484
- isAutomatic,
2485
- moonAsset,
2486
- moonChain,
2487
- moonApi,
2488
- source,
2489
- sourceAddress,
2490
- sourceApi,
2491
- transact
2492
- });
2493
- const encodedXcmMessage = send.args[1].toHex();
2494
- const { destinationParachain, destinationParachainAndAddress } = getDestinationInHex(moonChain, computedOriginAccount);
2495
- const { currencies, feeItem } = getCurrencies({
2496
- source,
2497
- moonAsset,
2498
- asset
2499
- });
2500
- const weight = maxUint64;
2501
- const multiTransferTxData = encodeFunctionData2({
2502
- abi: XtokensAbi,
2503
- functionName: "transferMultiCurrencies",
2504
- args: [currencies, feeItem, destinationParachainAndAddress, weight]
2505
- });
2506
- const xcmSendTxData = encodeFunctionData2({
2507
- abi: XcmUtilsAbi,
2508
- functionName: "xcmSend",
2509
- args: [destinationParachain, encodedXcmMessage]
2510
- });
2511
- return new ContractConfig({
2512
- address: source.contracts.Batch,
2513
- abi: BatchAbi,
2514
- args: [
2515
- [source.contracts.Xtokens, source.contracts.XcmUtils],
2516
- [],
2517
- [multiTransferTxData, xcmSendTxData],
2518
- []
2519
- ],
2520
- func: "batchAll",
2521
- module
2522
- });
2523
- }
2524
- })
2525
- };
2526
- }
2527
- function getDestinationInHex(moonChain, computedOriginAccount) {
2528
- const destinationParachain = {
2529
- parents: 1,
2530
- interior: getPrecompileDestinationInterior(moonChain)
2531
- };
2532
- const destinationParachainAndAddress = {
2533
- parents: 1,
2534
- interior: getPrecompileDestinationInterior(
2535
- moonChain,
2536
- computedOriginAccount
2537
- )
2538
- };
2539
- return {
2540
- destinationParachain,
2541
- destinationParachainAndAddress
2542
- };
2543
- }
2544
- function getCurrencies({ source, moonAsset, asset }) {
2545
- const currencies = [
2546
- {
2547
- currencyAddress: source.getChainAsset(moonAsset).address,
2548
- amount: CROSS_CHAIN_FEE
2549
- },
2550
- {
2551
- currencyAddress: asset.address,
2552
- amount: asset.amount
2553
- }
2554
- ];
2555
- const feeItem = 0;
2556
- return { currencies, feeItem };
2557
- }
2558
-
2559
- // src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
2560
- import { u8aToHex as u8aToHex4 } from "@polkadot/util";
2561
-
2562
- // src/mrl/providers/wormhole/contract/Gmp/GmpAbi.ts
2563
- var GMP_ABI = [
2564
- {
2565
- inputs: [
2566
- {
2567
- internalType: "bytes",
2568
- name: "vaa",
2569
- type: "bytes"
2570
- }
2571
- ],
2572
- name: "wormholeTransferERC20",
2573
- outputs: [],
2574
- stateMutability: "nonpayable",
2575
- type: "function"
2576
- }
2577
- ];
2578
-
2579
- // src/mrl/providers/wormhole/contract/Gmp/Gmp.ts
2580
- var module2 = "GMP";
2581
- var GMP_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000816";
2582
- function Gmp() {
2583
- return {
2584
- wormholeTransferERC20: () => ({
2585
- build: ({ bytes }) => {
2586
- const hex = u8aToHex4(bytes);
2587
- return new ContractConfig({
2588
- address: GMP_CONTRACT_ADDRESS,
2589
- abi: GMP_ABI,
2590
- args: [hex],
2591
- func: "wormholeTransferERC20",
2592
- module: module2
2593
- });
2594
- }
2595
- })
2596
- };
2597
- }
2598
-
2599
- // src/mrl/providers/wormhole/contract/TokenBridge/TokenBridge.ts
2600
- import { convertAddressTo32Bytes } from "@moonbeam-network/xcm-utils";
2601
-
2602
- // src/mrl/providers/wormhole/wormhole/wormhole.ts
2603
- import { EvmChain, EvmParachain as EvmParachain3, Parachain as Parachain2 } from "@moonbeam-network/xcm-types";
2604
- import { getMultilocationDerivedAddresses as getMultilocationDerivedAddresses3 } from "@moonbeam-network/xcm-utils";
2605
- import { evmToAddress as evmToAddress4 } from "@polkadot/util-crypto/address";
2606
- import { Wormhole as Wormhole2 } from "@wormhole-foundation/sdk-connect";
2607
-
2608
- // src/mrl/providers/wormhole/wormhole/WormholeConfig.ts
2609
- var WormholeConfig = class _WormholeConfig {
2610
- args;
2611
- func;
2612
- static is(obj) {
2613
- return obj instanceof _WormholeConfig;
2614
- }
2615
- constructor({ args, func }) {
2616
- this.args = args;
2617
- this.func = func;
2618
- }
2619
- };
2620
-
2621
- // src/mrl/providers/wormhole/wormhole/wormholeFactory.ts
2622
- import { Wormhole } from "@wormhole-foundation/sdk-connect";
2623
- import { EvmPlatform } from "@wormhole-foundation/sdk-evm";
2624
- function wormholeFactory(chain) {
2625
- return new Wormhole(chain.isTestChain ? "Testnet" : "Mainnet", [EvmPlatform]);
2626
- }
2627
-
2628
- // src/mrl/providers/wormhole/wormhole/wormhole.ts
2629
- function wormhole() {
2630
- return {
2631
- tokenTransfer: () => ({
2632
- build: ({
2633
- asset,
2634
- destination,
2635
- destinationAddress,
2636
- isAutomatic,
2637
- moonApi,
2638
- moonChain,
2639
- source,
2640
- sourceAddress
2641
- }) => {
2642
- const isSourceParachain = Parachain2.is(source);
2643
- const isDestinationMoonChain = destination.isEqual(moonChain);
2644
- const isDestinationEvmChain = EvmChain.is(destination);
2645
- const isNativeAsset = asset.isSame(
2646
- isDestinationEvmChain ? moonChain.nativeAsset : source.nativeAsset
2647
- );
2648
- const tokenAddress = isNativeAsset ? "native" : isDestinationEvmChain ? moonChain.getChainAsset(asset).address : asset.address;
2649
- const { address20: computedOriginAccount } = getMultilocationDerivedAddresses3({
2650
- address: sourceAddress,
2651
- paraId: isSourceParachain ? source.parachainId : void 0,
2652
- isParents: true
2653
- });
2654
- if (!tokenAddress) {
2655
- throw new Error(`Asset ${asset.key} has no address`);
2656
- }
2657
- const wh = wormholeFactory(source);
2658
- const whSource = isDestinationEvmChain ? wh.getChain(moonChain.getWormholeName()) : wh.getChain(source.getWormholeName());
2659
- const whDestination = isDestinationEvmChain ? wh.getChain(destination.getWormholeName()) : wh.getChain(moonChain.getWormholeName());
2660
- const whAsset = Wormhole2.tokenId(whSource.chain, tokenAddress);
2661
- const whSourceAddress = Wormhole2.chainAddress(
2662
- whSource.chain,
2663
- isDestinationEvmChain ? computedOriginAccount : sourceAddress
2664
- );
2665
- const whDestinationAddress = Wormhole2.chainAddress(
2666
- whDestination.chain,
2667
- isDestinationMoonChain || isDestinationEvmChain ? destinationAddress : GMP_CONTRACT_ADDRESS
2668
- );
2669
- return new WormholeConfig({
2670
- args: [
2671
- whAsset,
2672
- asset.amount,
2673
- whSourceAddress,
2674
- whDestinationAddress,
2675
- isAutomatic,
2676
- isDestinationMoonChain || isDestinationEvmChain ? void 0 : getPayload({ destination, destinationAddress, moonApi })
2677
- ],
2678
- func: "tokenTransfer"
2679
- });
2680
- }
2681
- })
2682
- };
2683
- }
2684
- function getPayload({
2685
- moonApi,
2686
- destination,
2687
- destinationAddress
2688
- }) {
2689
- if (!EvmParachain3.isAnyParachain(destination)) {
2690
- throw new Error(
2691
- `Destination ${destination.name} is not a Parachain or EvmParachain`
2692
- );
2693
- }
2694
- const isPeaqEvm = destination.key === "peaq-evm-Alphanet" || destination.key === "peaq-evm";
2695
- const multilocation = moonApi.createType("XcmVersionedLocation", {
2696
- V3: {
2697
- parents: 1,
2698
- interior: {
2699
- X2: [
2700
- {
2701
- Parachain: destination.parachainId
2702
- },
2703
- getExtrinsicAccount(
2704
- isPeaqEvm ? evmToAddress4(destinationAddress) : destinationAddress
2705
- )
2706
- ]
2707
- }
2708
- }
2709
- });
2710
- const action = moonApi.createType("XcmRoutingUserAction", {
2711
- destination: multilocation
2712
- });
2713
- const versioned = moonApi.createType("VersionedUserAction", {
2714
- V1: action
2715
- });
2716
- return versioned.toU8a();
2717
- }
2718
-
2719
- // src/mrl/providers/wormhole/contract/TokenBridge/TokenBridgeAbi.ts
2720
- var TOKEN_BRIDGE_ABI = [
2721
- {
2722
- anonymous: false,
2723
- inputs: [
2724
- {
2725
- indexed: false,
2726
- internalType: "address",
2727
- name: "previousAdmin",
2728
- type: "address"
2729
- },
2730
- {
2731
- indexed: false,
2732
- internalType: "address",
2733
- name: "newAdmin",
2734
- type: "address"
2735
- }
2736
- ],
2737
- name: "AdminChanged",
2738
- type: "event"
2739
- },
2740
- {
2741
- anonymous: false,
2742
- inputs: [
2743
- {
2744
- indexed: true,
2745
- internalType: "address",
2746
- name: "beacon",
2747
- type: "address"
2748
- }
2749
- ],
2750
- name: "BeaconUpgraded",
2751
- type: "event"
2752
- },
2753
- {
2754
- anonymous: false,
2755
- inputs: [
2756
- {
2757
- indexed: true,
2758
- internalType: "address",
2759
- name: "oldContract",
2760
- type: "address"
2761
- },
2762
- {
2763
- indexed: true,
2764
- internalType: "address",
2765
- name: "newContract",
2766
- type: "address"
2767
- }
2768
- ],
2769
- name: "ContractUpgraded",
2770
- type: "event"
2771
- },
2772
- {
2773
- anonymous: false,
2774
- inputs: [
2775
- {
2776
- indexed: true,
2777
- internalType: "address",
2778
- name: "implementation",
2779
- type: "address"
2780
- }
2781
- ],
2782
- name: "Upgraded",
2783
- type: "event"
2784
- },
2785
- {
2786
- inputs: [],
2787
- name: "WETH",
2788
- outputs: [
2789
- {
2790
- internalType: "contract IWETH",
2791
- name: "",
2792
- type: "address"
2793
- }
2794
- ],
2795
- stateMutability: "view",
2796
- type: "function"
2797
- },
2798
- {
2799
- inputs: [
2800
- {
2801
- internalType: "uint16",
2802
- name: "chainId_",
2803
- type: "uint16"
2804
- }
2805
- ],
2806
- name: "bridgeContracts",
2807
- outputs: [
2808
- {
2809
- internalType: "bytes32",
2810
- name: "",
2811
- type: "bytes32"
2812
- }
2813
- ],
2814
- stateMutability: "view",
2815
- type: "function"
2816
- },
2817
- {
2818
- inputs: [],
2819
- name: "chainId",
2820
- outputs: [
2821
- {
2822
- internalType: "uint16",
2823
- name: "",
2824
- type: "uint16"
2825
- }
2826
- ],
2827
- stateMutability: "view",
2828
- type: "function"
2829
- },
2830
- {
2831
- inputs: [],
2832
- name: "evmChainId",
2833
- outputs: [
2834
- {
2835
- internalType: "uint256",
2836
- name: "",
2837
- type: "uint256"
2838
- }
2839
- ],
2840
- stateMutability: "view",
2841
- type: "function"
2842
- },
2843
- {
2844
- inputs: [],
2845
- name: "finality",
2846
- outputs: [
2847
- {
2848
- internalType: "uint8",
2849
- name: "",
2850
- type: "uint8"
2851
- }
2852
- ],
2853
- stateMutability: "view",
2854
- type: "function"
2855
- },
2856
- {
2857
- inputs: [
2858
- {
2859
- internalType: "bytes32",
2860
- name: "hash",
2861
- type: "bytes32"
2862
- }
2863
- ],
2864
- name: "governanceActionIsConsumed",
2865
- outputs: [
2866
- {
2867
- internalType: "bool",
2868
- name: "",
2869
- type: "bool"
2870
- }
2871
- ],
2872
- stateMutability: "view",
2873
- type: "function"
2874
- },
2875
- {
2876
- inputs: [],
2877
- name: "governanceChainId",
2878
- outputs: [
2879
- {
2880
- internalType: "uint16",
2881
- name: "",
2882
- type: "uint16"
2883
- }
2884
- ],
2885
- stateMutability: "view",
2886
- type: "function"
2887
- },
2888
- {
2889
- inputs: [],
2890
- name: "governanceContract",
2891
- outputs: [
2892
- {
2893
- internalType: "bytes32",
2894
- name: "",
2895
- type: "bytes32"
2896
- }
2897
- ],
2898
- stateMutability: "view",
2899
- type: "function"
2900
- },
2901
- {
2902
- inputs: [],
2903
- name: "isFork",
2904
- outputs: [
2905
- {
2906
- internalType: "bool",
2907
- name: "",
2908
- type: "bool"
2909
- }
2910
- ],
2911
- stateMutability: "view",
2912
- type: "function"
2913
- },
2914
- {
2915
- inputs: [
2916
- {
2917
- internalType: "address",
2918
- name: "impl",
2919
- type: "address"
2920
- }
2921
- ],
2922
- name: "isInitialized",
2923
- outputs: [
2924
- {
2925
- internalType: "bool",
2926
- name: "",
2927
- type: "bool"
2928
- }
2929
- ],
2930
- stateMutability: "view",
2931
- type: "function"
2932
- },
2933
- {
2934
- inputs: [
2935
- {
2936
- internalType: "bytes32",
2937
- name: "hash",
2938
- type: "bytes32"
2939
- }
2940
- ],
2941
- name: "isTransferCompleted",
2942
- outputs: [
2943
- {
2944
- internalType: "bool",
2945
- name: "",
2946
- type: "bool"
2947
- }
2948
- ],
2949
- stateMutability: "view",
2950
- type: "function"
2951
- },
2952
- {
2953
- inputs: [
2954
- {
2955
- internalType: "address",
2956
- name: "token",
2957
- type: "address"
2958
- }
2959
- ],
2960
- name: "isWrappedAsset",
2961
- outputs: [
2962
- {
2963
- internalType: "bool",
2964
- name: "",
2965
- type: "bool"
2966
- }
2967
- ],
2968
- stateMutability: "view",
2969
- type: "function"
2970
- },
2971
- {
2972
- inputs: [
2973
- {
2974
- internalType: "address",
2975
- name: "token",
2976
- type: "address"
2977
- }
2978
- ],
2979
- name: "outstandingBridged",
2980
- outputs: [
2981
- {
2982
- internalType: "uint256",
2983
- name: "",
2984
- type: "uint256"
2985
- }
2986
- ],
2987
- stateMutability: "view",
2988
- type: "function"
2989
- },
2990
- {
2991
- inputs: [
2992
- {
2993
- internalType: "bytes",
2994
- name: "encodedRecoverChainId",
2995
- type: "bytes"
2996
- }
2997
- ],
2998
- name: "parseRecoverChainId",
2999
- outputs: [
3000
- {
3001
- components: [
3002
- {
3003
- internalType: "bytes32",
3004
- name: "module",
3005
- type: "bytes32"
3006
- },
3007
- {
3008
- internalType: "uint8",
3009
- name: "action",
3010
- type: "uint8"
3011
- },
3012
- {
3013
- internalType: "uint256",
3014
- name: "evmChainId",
3015
- type: "uint256"
3016
- },
3017
- {
3018
- internalType: "uint16",
3019
- name: "newChainId",
3020
- type: "uint16"
3021
- }
3022
- ],
3023
- internalType: "struct BridgeStructs.RecoverChainId",
3024
- name: "rci",
3025
- type: "tuple"
3026
- }
3027
- ],
3028
- stateMutability: "pure",
3029
- type: "function"
3030
- },
3031
- {
3032
- inputs: [
3033
- {
3034
- internalType: "bytes",
3035
- name: "encoded",
3036
- type: "bytes"
3037
- }
3038
- ],
3039
- name: "parseRegisterChain",
3040
- outputs: [
3041
- {
3042
- components: [
3043
- {
3044
- internalType: "bytes32",
3045
- name: "module",
3046
- type: "bytes32"
3047
- },
3048
- {
3049
- internalType: "uint8",
3050
- name: "action",
3051
- type: "uint8"
3052
- },
3053
- {
3054
- internalType: "uint16",
3055
- name: "chainId",
3056
- type: "uint16"
3057
- },
3058
- {
3059
- internalType: "uint16",
3060
- name: "emitterChainID",
3061
- type: "uint16"
3062
- },
3063
- {
3064
- internalType: "bytes32",
3065
- name: "emitterAddress",
3066
- type: "bytes32"
3067
- }
3068
- ],
3069
- internalType: "struct BridgeStructs.RegisterChain",
3070
- name: "chain",
3071
- type: "tuple"
3072
- }
3073
- ],
3074
- stateMutability: "pure",
3075
- type: "function"
3076
- },
3077
- {
3078
- inputs: [
3079
- {
3080
- internalType: "bytes",
3081
- name: "encoded",
3082
- type: "bytes"
3083
- }
3084
- ],
3085
- name: "parseUpgrade",
3086
- outputs: [
3087
- {
3088
- components: [
3089
- {
3090
- internalType: "bytes32",
3091
- name: "module",
3092
- type: "bytes32"
3093
- },
3094
- {
3095
- internalType: "uint8",
3096
- name: "action",
3097
- type: "uint8"
3098
- },
3099
- {
3100
- internalType: "uint16",
3101
- name: "chainId",
3102
- type: "uint16"
3103
- },
3104
- {
3105
- internalType: "bytes32",
3106
- name: "newContract",
3107
- type: "bytes32"
3108
- }
3109
- ],
3110
- internalType: "struct BridgeStructs.UpgradeContract",
3111
- name: "chain",
3112
- type: "tuple"
3113
- }
3114
- ],
3115
- stateMutability: "pure",
3116
- type: "function"
3117
- },
3118
- {
3119
- inputs: [
3120
- {
3121
- internalType: "bytes",
3122
- name: "encodedVM",
3123
- type: "bytes"
3124
- }
3125
- ],
3126
- name: "registerChain",
3127
- outputs: [],
3128
- stateMutability: "nonpayable",
3129
- type: "function"
3130
- },
3131
- {
3132
- inputs: [
3133
- {
3134
- internalType: "bytes",
3135
- name: "encodedVM",
3136
- type: "bytes"
3137
- }
3138
- ],
3139
- name: "submitRecoverChainId",
3140
- outputs: [],
3141
- stateMutability: "nonpayable",
3142
- type: "function"
3143
- },
3144
- {
3145
- inputs: [],
3146
- name: "tokenImplementation",
3147
- outputs: [
3148
- {
3149
- internalType: "address",
3150
- name: "",
3151
- type: "address"
3152
- }
3153
- ],
3154
- stateMutability: "view",
3155
- type: "function"
3156
- },
3157
- {
3158
- inputs: [
3159
- {
3160
- internalType: "bytes",
3161
- name: "encodedVM",
3162
- type: "bytes"
3163
- }
3164
- ],
3165
- name: "upgrade",
3166
- outputs: [],
3167
- stateMutability: "nonpayable",
3168
- type: "function"
3169
- },
3170
- {
3171
- inputs: [],
3172
- name: "wormhole",
3173
- outputs: [
3174
- {
3175
- internalType: "contract IWormhole",
3176
- name: "",
3177
- type: "address"
3178
- }
3179
- ],
3180
- stateMutability: "view",
3181
- type: "function"
3182
- },
3183
- {
3184
- inputs: [
3185
- {
3186
- internalType: "uint16",
3187
- name: "tokenChainId",
3188
- type: "uint16"
3189
- },
3190
- {
3191
- internalType: "bytes32",
3192
- name: "tokenAddress",
3193
- type: "bytes32"
3194
- }
3195
- ],
3196
- name: "wrappedAsset",
3197
- outputs: [
3198
- {
3199
- internalType: "address",
3200
- name: "",
3201
- type: "address"
3202
- }
3203
- ],
3204
- stateMutability: "view",
3205
- type: "function"
3206
- },
3207
- {
3208
- stateMutability: "payable",
3209
- type: "receive"
3210
- },
3211
- {
3212
- inputs: [
3213
- {
3214
- internalType: "address",
3215
- name: "tokenAddress",
3216
- type: "address"
3217
- },
3218
- {
3219
- internalType: "uint32",
3220
- name: "nonce",
3221
- type: "uint32"
3222
- }
3223
- ],
3224
- name: "attestToken",
3225
- outputs: [
3226
- {
3227
- internalType: "uint64",
3228
- name: "sequence",
3229
- type: "uint64"
3230
- }
3231
- ],
3232
- stateMutability: "payable",
3233
- type: "function"
3234
- },
3235
- {
3236
- inputs: [
3237
- {
3238
- internalType: "uint16",
3239
- name: "recipientChain",
3240
- type: "uint16"
3241
- },
3242
- {
3243
- internalType: "bytes32",
3244
- name: "recipient",
3245
- type: "bytes32"
3246
- },
3247
- {
3248
- internalType: "uint256",
3249
- name: "arbiterFee",
3250
- type: "uint256"
3251
- },
3252
- {
3253
- internalType: "uint32",
3254
- name: "nonce",
3255
- type: "uint32"
3256
- }
3257
- ],
3258
- name: "wrapAndTransferETH",
3259
- outputs: [
3260
- {
3261
- internalType: "uint64",
3262
- name: "sequence",
3263
- type: "uint64"
3264
- }
3265
- ],
3266
- stateMutability: "payable",
3267
- type: "function"
3268
- },
3269
- {
3270
- inputs: [
3271
- {
3272
- internalType: "uint16",
3273
- name: "recipientChain",
3274
- type: "uint16"
3275
- },
3276
- {
3277
- internalType: "bytes32",
3278
- name: "recipient",
3279
- type: "bytes32"
3280
- },
3281
- {
3282
- internalType: "uint32",
3283
- name: "nonce",
3284
- type: "uint32"
3285
- },
3286
- {
3287
- internalType: "bytes",
3288
- name: "payload",
3289
- type: "bytes"
3290
- }
3291
- ],
3292
- name: "wrapAndTransferETHWithPayload",
3293
- outputs: [
3294
- {
3295
- internalType: "uint64",
3296
- name: "sequence",
3297
- type: "uint64"
3298
- }
3299
- ],
3300
- stateMutability: "payable",
3301
- type: "function"
3302
- },
3303
- {
3304
- inputs: [
3305
- {
3306
- internalType: "address",
3307
- name: "token",
3308
- type: "address"
3309
- },
3310
- {
3311
- internalType: "uint256",
3312
- name: "amount",
3313
- type: "uint256"
3314
- },
3315
- {
3316
- internalType: "uint16",
3317
- name: "recipientChain",
3318
- type: "uint16"
3319
- },
3320
- {
3321
- internalType: "bytes32",
3322
- name: "recipient",
3323
- type: "bytes32"
3324
- },
3325
- {
3326
- internalType: "uint256",
3327
- name: "arbiterFee",
3328
- type: "uint256"
3329
- },
3330
- {
3331
- internalType: "uint32",
3332
- name: "nonce",
3333
- type: "uint32"
3334
- }
3335
- ],
3336
- name: "transferTokens",
3337
- outputs: [
3338
- {
3339
- internalType: "uint64",
3340
- name: "sequence",
3341
- type: "uint64"
3342
- }
3343
- ],
3344
- stateMutability: "payable",
3345
- type: "function"
3346
- },
3347
- {
3348
- inputs: [
3349
- {
3350
- internalType: "address",
3351
- name: "token",
3352
- type: "address"
3353
- },
3354
- {
3355
- internalType: "uint256",
3356
- name: "amount",
3357
- type: "uint256"
3358
- },
3359
- {
3360
- internalType: "uint16",
3361
- name: "recipientChain",
3362
- type: "uint16"
3363
- },
3364
- {
3365
- internalType: "bytes32",
3366
- name: "recipient",
3367
- type: "bytes32"
3368
- },
3369
- {
3370
- internalType: "uint32",
3371
- name: "nonce",
3372
- type: "uint32"
3373
- },
3374
- {
3375
- internalType: "bytes",
3376
- name: "payload",
3377
- type: "bytes"
3378
- }
3379
- ],
3380
- name: "transferTokensWithPayload",
3381
- outputs: [
3382
- {
3383
- internalType: "uint64",
3384
- name: "sequence",
3385
- type: "uint64"
3386
- }
3387
- ],
3388
- stateMutability: "payable",
3389
- type: "function"
3390
- },
3391
- {
3392
- inputs: [
3393
- {
3394
- internalType: "bytes",
3395
- name: "encodedVm",
3396
- type: "bytes"
3397
- }
3398
- ],
3399
- name: "updateWrapped",
3400
- outputs: [
3401
- {
3402
- internalType: "address",
3403
- name: "token",
3404
- type: "address"
3405
- }
3406
- ],
3407
- stateMutability: "nonpayable",
3408
- type: "function"
3409
- },
3410
- {
3411
- inputs: [
3412
- {
3413
- internalType: "bytes",
3414
- name: "encodedVm",
3415
- type: "bytes"
3416
- }
3417
- ],
3418
- name: "createWrapped",
3419
- outputs: [
3420
- {
3421
- internalType: "address",
3422
- name: "token",
3423
- type: "address"
3424
- }
3425
- ],
3426
- stateMutability: "nonpayable",
3427
- type: "function"
3428
- },
3429
- {
3430
- inputs: [
3431
- {
3432
- internalType: "bytes",
3433
- name: "encodedVm",
3434
- type: "bytes"
3435
- }
3436
- ],
3437
- name: "completeTransferWithPayload",
3438
- outputs: [
3439
- {
3440
- internalType: "bytes",
3441
- name: "",
3442
- type: "bytes"
3443
- }
3444
- ],
3445
- stateMutability: "nonpayable",
3446
- type: "function"
3447
- },
3448
- {
3449
- inputs: [
3450
- {
3451
- internalType: "bytes",
3452
- name: "encodedVm",
3453
- type: "bytes"
3454
- }
3455
- ],
3456
- name: "completeTransferAndUnwrapETHWithPayload",
3457
- outputs: [
3458
- {
3459
- internalType: "bytes",
3460
- name: "",
3461
- type: "bytes"
3462
- }
3463
- ],
3464
- stateMutability: "nonpayable",
3465
- type: "function"
3466
- },
3467
- {
3468
- inputs: [
3469
- {
3470
- internalType: "bytes",
3471
- name: "encodedVm",
3472
- type: "bytes"
3473
- }
3474
- ],
3475
- name: "completeTransfer",
3476
- outputs: [],
3477
- stateMutability: "nonpayable",
3478
- type: "function"
3479
- },
3480
- {
3481
- inputs: [
3482
- {
3483
- internalType: "bytes",
3484
- name: "encodedVm",
3485
- type: "bytes"
3486
- }
3487
- ],
3488
- name: "completeTransferAndUnwrapETH",
3489
- outputs: [],
3490
- stateMutability: "nonpayable",
3491
- type: "function"
3492
- },
3493
- {
3494
- inputs: [
3495
- {
3496
- components: [
3497
- {
3498
- internalType: "uint8",
3499
- name: "payloadID",
3500
- type: "uint8"
3501
- },
3502
- {
3503
- internalType: "bytes32",
3504
- name: "tokenAddress",
3505
- type: "bytes32"
3506
- },
3507
- {
3508
- internalType: "uint16",
3509
- name: "tokenChain",
3510
- type: "uint16"
3511
- },
3512
- {
3513
- internalType: "uint8",
3514
- name: "decimals",
3515
- type: "uint8"
3516
- },
3517
- {
3518
- internalType: "bytes32",
3519
- name: "symbol",
3520
- type: "bytes32"
3521
- },
3522
- {
3523
- internalType: "bytes32",
3524
- name: "name",
3525
- type: "bytes32"
3526
- }
3527
- ],
3528
- internalType: "struct BridgeStructs.AssetMeta",
3529
- name: "meta",
3530
- type: "tuple"
3531
- }
3532
- ],
3533
- name: "encodeAssetMeta",
3534
- outputs: [
3535
- {
3536
- internalType: "bytes",
3537
- name: "encoded",
3538
- type: "bytes"
3539
- }
3540
- ],
3541
- stateMutability: "pure",
3542
- type: "function"
3543
- },
3544
- {
3545
- inputs: [
3546
- {
3547
- components: [
3548
- {
3549
- internalType: "uint8",
3550
- name: "payloadID",
3551
- type: "uint8"
3552
- },
3553
- {
3554
- internalType: "uint256",
3555
- name: "amount",
3556
- type: "uint256"
3557
- },
3558
- {
3559
- internalType: "bytes32",
3560
- name: "tokenAddress",
3561
- type: "bytes32"
3562
- },
3563
- {
3564
- internalType: "uint16",
3565
- name: "tokenChain",
3566
- type: "uint16"
3567
- },
3568
- {
3569
- internalType: "bytes32",
3570
- name: "to",
3571
- type: "bytes32"
3572
- },
3573
- {
3574
- internalType: "uint16",
3575
- name: "toChain",
3576
- type: "uint16"
3577
- },
3578
- {
3579
- internalType: "uint256",
3580
- name: "fee",
3581
- type: "uint256"
3582
- }
3583
- ],
3584
- internalType: "struct BridgeStructs.Transfer",
3585
- name: "transfer",
3586
- type: "tuple"
3587
- }
3588
- ],
3589
- name: "encodeTransfer",
3590
- outputs: [
3591
- {
3592
- internalType: "bytes",
3593
- name: "encoded",
3594
- type: "bytes"
3595
- }
3596
- ],
3597
- stateMutability: "pure",
3598
- type: "function"
3599
- },
3600
- {
3601
- inputs: [
3602
- {
3603
- components: [
3604
- {
3605
- internalType: "uint8",
3606
- name: "payloadID",
3607
- type: "uint8"
3608
- },
3609
- {
3610
- internalType: "uint256",
3611
- name: "amount",
3612
- type: "uint256"
3613
- },
3614
- {
3615
- internalType: "bytes32",
3616
- name: "tokenAddress",
3617
- type: "bytes32"
3618
- },
3619
- {
3620
- internalType: "uint16",
3621
- name: "tokenChain",
3622
- type: "uint16"
3623
- },
3624
- {
3625
- internalType: "bytes32",
3626
- name: "to",
3627
- type: "bytes32"
3628
- },
3629
- {
3630
- internalType: "uint16",
3631
- name: "toChain",
3632
- type: "uint16"
3633
- },
3634
- {
3635
- internalType: "bytes32",
3636
- name: "fromAddress",
3637
- type: "bytes32"
3638
- },
3639
- {
3640
- internalType: "bytes",
3641
- name: "payload",
3642
- type: "bytes"
3643
- }
3644
- ],
3645
- internalType: "struct BridgeStructs.TransferWithPayload",
3646
- name: "transfer",
3647
- type: "tuple"
3648
- }
3649
- ],
3650
- name: "encodeTransferWithPayload",
3651
- outputs: [
3652
- {
3653
- internalType: "bytes",
3654
- name: "encoded",
3655
- type: "bytes"
3656
- }
3657
- ],
3658
- stateMutability: "pure",
3659
- type: "function"
3660
- },
3661
- {
3662
- inputs: [
3663
- {
3664
- internalType: "bytes",
3665
- name: "encoded",
3666
- type: "bytes"
3667
- }
3668
- ],
3669
- name: "parsePayloadID",
3670
- outputs: [
3671
- {
3672
- internalType: "uint8",
3673
- name: "payloadID",
3674
- type: "uint8"
3675
- }
3676
- ],
3677
- stateMutability: "pure",
3678
- type: "function"
3679
- },
3680
- {
3681
- inputs: [
3682
- {
3683
- internalType: "bytes",
3684
- name: "encoded",
3685
- type: "bytes"
3686
- }
3687
- ],
3688
- name: "parseAssetMeta",
3689
- outputs: [
3690
- {
3691
- components: [
3692
- {
3693
- internalType: "uint8",
3694
- name: "payloadID",
3695
- type: "uint8"
3696
- },
3697
- {
3698
- internalType: "bytes32",
3699
- name: "tokenAddress",
3700
- type: "bytes32"
3701
- },
3702
- {
3703
- internalType: "uint16",
3704
- name: "tokenChain",
3705
- type: "uint16"
3706
- },
3707
- {
3708
- internalType: "uint8",
3709
- name: "decimals",
3710
- type: "uint8"
3711
- },
3712
- {
3713
- internalType: "bytes32",
3714
- name: "symbol",
3715
- type: "bytes32"
3716
- },
3717
- {
3718
- internalType: "bytes32",
3719
- name: "name",
3720
- type: "bytes32"
3721
- }
3722
- ],
3723
- internalType: "struct BridgeStructs.AssetMeta",
3724
- name: "meta",
3725
- type: "tuple"
3726
- }
3727
- ],
3728
- stateMutability: "pure",
3729
- type: "function"
3730
- },
3731
- {
3732
- inputs: [
3733
- {
3734
- internalType: "bytes",
3735
- name: "encoded",
3736
- type: "bytes"
3737
- }
3738
- ],
3739
- name: "parseTransfer",
3740
- outputs: [
3741
- {
3742
- components: [
3743
- {
3744
- internalType: "uint8",
3745
- name: "payloadID",
3746
- type: "uint8"
3747
- },
3748
- {
3749
- internalType: "uint256",
3750
- name: "amount",
3751
- type: "uint256"
3752
- },
3753
- {
3754
- internalType: "bytes32",
3755
- name: "tokenAddress",
3756
- type: "bytes32"
3757
- },
3758
- {
3759
- internalType: "uint16",
3760
- name: "tokenChain",
3761
- type: "uint16"
3762
- },
3763
- {
3764
- internalType: "bytes32",
3765
- name: "to",
3766
- type: "bytes32"
3767
- },
3768
- {
3769
- internalType: "uint16",
3770
- name: "toChain",
3771
- type: "uint16"
3772
- },
3773
- {
3774
- internalType: "uint256",
3775
- name: "fee",
3776
- type: "uint256"
3777
- }
3778
- ],
3779
- internalType: "struct BridgeStructs.Transfer",
3780
- name: "transfer",
3781
- type: "tuple"
3782
- }
3783
- ],
3784
- stateMutability: "pure",
3785
- type: "function"
3786
- },
3787
- {
3788
- inputs: [
3789
- {
3790
- internalType: "bytes",
3791
- name: "encoded",
3792
- type: "bytes"
3793
- }
3794
- ],
3795
- name: "parseTransferWithPayload",
3796
- outputs: [
3797
- {
3798
- components: [
3799
- {
3800
- internalType: "uint8",
3801
- name: "payloadID",
3802
- type: "uint8"
3803
- },
3804
- {
3805
- internalType: "uint256",
3806
- name: "amount",
3807
- type: "uint256"
3808
- },
3809
- {
3810
- internalType: "bytes32",
3811
- name: "tokenAddress",
3812
- type: "bytes32"
3813
- },
3814
- {
3815
- internalType: "uint16",
3816
- name: "tokenChain",
3817
- type: "uint16"
3818
- },
3819
- {
3820
- internalType: "bytes32",
3821
- name: "to",
3822
- type: "bytes32"
3823
- },
3824
- {
3825
- internalType: "uint16",
3826
- name: "toChain",
3827
- type: "uint16"
3828
- },
3829
- {
3830
- internalType: "bytes32",
3831
- name: "fromAddress",
3832
- type: "bytes32"
3833
- },
3834
- {
3835
- internalType: "bytes",
3836
- name: "payload",
3837
- type: "bytes"
3838
- }
3839
- ],
3840
- internalType: "struct BridgeStructs.TransferWithPayload",
3841
- name: "transfer",
3842
- type: "tuple"
3843
- }
3844
- ],
3845
- stateMutability: "pure",
3846
- type: "function"
3847
- },
3848
- {
3849
- inputs: [
3850
- {
3851
- internalType: "bytes",
3852
- name: "encoded",
3853
- type: "bytes"
3854
- }
3855
- ],
3856
- name: "_parseTransferCommon",
3857
- outputs: [
3858
- {
3859
- components: [
3860
- {
3861
- internalType: "uint8",
3862
- name: "payloadID",
3863
- type: "uint8"
3864
- },
3865
- {
3866
- internalType: "uint256",
3867
- name: "amount",
3868
- type: "uint256"
3869
- },
3870
- {
3871
- internalType: "bytes32",
3872
- name: "tokenAddress",
3873
- type: "bytes32"
3874
- },
3875
- {
3876
- internalType: "uint16",
3877
- name: "tokenChain",
3878
- type: "uint16"
3879
- },
3880
- {
3881
- internalType: "bytes32",
3882
- name: "to",
3883
- type: "bytes32"
3884
- },
3885
- {
3886
- internalType: "uint16",
3887
- name: "toChain",
3888
- type: "uint16"
3889
- },
3890
- {
3891
- internalType: "uint256",
3892
- name: "fee",
3893
- type: "uint256"
3894
- }
3895
- ],
3896
- internalType: "struct BridgeStructs.Transfer",
3897
- name: "transfer",
3898
- type: "tuple"
3899
- }
3900
- ],
3901
- stateMutability: "pure",
3902
- type: "function"
3903
- }
3904
- ];
3905
-
3906
- // src/mrl/providers/wormhole/contract/TokenBridge/TokenBridge.ts
3907
- var module3 = "TokenBridge";
3908
- function TokenBridge() {
3909
- return {
3910
- transferTokens: () => ({
3911
- build: ({ asset, destination, destinationAddress, moonChain }) => {
3912
- const wh = wormholeFactory(moonChain);
3913
- const whDestination = wh.getChain(destination.getWormholeName()).config.chainId;
3914
- const tokenAddressOnMoonChain = moonChain.getChainAsset(asset).address;
3915
- if (!tokenAddressOnMoonChain) {
3916
- throw new Error(
3917
- `Asset ${asset.symbol} does not have a token address on chain ${moonChain.name}`
3918
- );
3919
- }
3920
- const destinationAddress32bytes = convertAddressTo32Bytes(
3921
- destinationAddress
3922
- );
3923
- const tokenAmountOnMoonChain = asset.convertDecimals(
3924
- moonChain.getChainAsset(asset).decimals
3925
- ).amount;
3926
- const contractAddress = wh.getChain("Moonbeam").config.contracts.tokenBridge;
3927
- if (!contractAddress) {
3928
- throw new Error(`Wormhole address not found for ${moonChain.name}`);
3929
- }
3930
- return new ContractConfig({
3931
- address: contractAddress,
3932
- abi: TOKEN_BRIDGE_ABI,
3933
- args: [
3934
- tokenAddressOnMoonChain,
3935
- tokenAmountOnMoonChain,
3936
- whDestination,
3937
- destinationAddress32bytes,
3938
- 0n,
3939
- 0
3940
- ],
3941
- func: "transferTokens",
3942
- module: module3
3943
- });
3944
- }
3945
- })
3946
- };
3947
- }
3948
-
3949
- // src/mrl/providers/wormhole/contract/TokenBridgeRelayer/TokenBridgeRelayer.ts
3950
- import { convertAddressTo32Bytes as convertAddressTo32Bytes2 } from "@moonbeam-network/xcm-utils";
3951
-
3952
- // src/mrl/providers/wormhole/contract/TokenBridgeRelayer/TokenBridgeRelayerAbi.ts
3953
- var TOKEN_BRIDGE_RELAYER_ABI = [
3954
- {
3955
- inputs: [
3956
- {
3957
- internalType: "uint16",
3958
- name: "targetChainId",
3959
- type: "uint16"
3960
- },
3961
- {
3962
- internalType: "address",
3963
- name: "token",
3964
- type: "address"
3965
- },
3966
- {
3967
- internalType: "uint8",
3968
- name: "decimals",
3969
- type: "uint8"
3970
- }
3971
- ],
3972
- name: "calculateRelayerFee",
3973
- outputs: [
3974
- {
3975
- internalType: "uint256",
3976
- name: "feeInTokenDenomination",
3977
- type: "uint256"
3978
- }
3979
- ],
3980
- stateMutability: "view",
3981
- type: "function"
3982
- },
3983
- {
3984
- inputs: [
3985
- {
3986
- internalType: "address",
3987
- name: "token",
3988
- type: "address"
3989
- },
3990
- {
3991
- internalType: "uint256",
3992
- name: "amount",
3993
- type: "uint256"
3994
- },
3995
- {
3996
- internalType: "uint256",
3997
- name: "toNativeTokenAmount",
3998
- type: "uint256"
3999
- },
4000
- {
4001
- internalType: "uint16",
4002
- name: "targetChain",
4003
- type: "uint16"
4004
- },
4005
- {
4006
- internalType: "bytes32",
4007
- name: "targetRecipient",
4008
- type: "bytes32"
4009
- },
4010
- {
4011
- internalType: "uint32",
4012
- name: "batchId",
4013
- type: "uint32"
4014
- }
4015
- ],
4016
- name: "transferTokensWithRelay",
4017
- outputs: [
4018
- {
4019
- internalType: "uint64",
4020
- name: "messageSequence",
4021
- type: "uint64"
4022
- }
4023
- ],
4024
- stateMutability: "payable",
4025
- type: "function"
4026
- },
4027
- {
4028
- inputs: [
4029
- {
4030
- internalType: "uint256",
4031
- name: "toNativeTokenAmount",
4032
- type: "uint256"
4033
- },
4034
- {
4035
- internalType: "uint16",
4036
- name: "targetChain",
4037
- type: "uint16"
4038
- },
4039
- {
4040
- internalType: "bytes32",
4041
- name: "targetRecipient",
4042
- type: "bytes32"
4043
- },
4044
- {
4045
- internalType: "uint32",
4046
- name: "batchId",
4047
- type: "uint32"
4048
- }
4049
- ],
4050
- name: "wrapAndTransferEthWithRelay",
4051
- outputs: [
4052
- {
4053
- internalType: "uint64",
4054
- name: "messageSequence",
4055
- type: "uint64"
4056
- }
4057
- ],
4058
- stateMutability: "payable",
4059
- type: "function"
4060
- }
4061
- ];
4062
-
4063
- // src/mrl/providers/wormhole/contract/TokenBridgeRelayer/TokenBridgeRelayer.ts
4064
- var module4 = "TokenBridgeRelayer";
4065
- function TokenBridgeRelayer() {
4066
- return {
4067
- transferTokensWithRelay: () => ({
4068
- build: ({ asset, destination, destinationAddress, moonChain }) => {
4069
- const wh = wormholeFactory(moonChain);
4070
- const whDestination = wh.getChain(destination.getWormholeName()).config.chainId;
4071
- const tokenAddressOnMoonChain = moonChain.getChainAsset(asset).address;
4072
- if (!tokenAddressOnMoonChain) {
4073
- throw new Error(
4074
- `Asset ${asset.symbol} does not have a token address on chain ${moonChain.name}`
4075
- );
4076
- }
4077
- const destinationAddress32bytes = convertAddressTo32Bytes2(
4078
- destinationAddress
4079
- );
4080
- const tokenAmountOnMoonChain = asset.convertDecimals(
4081
- moonChain.getChainAsset(asset).decimals
4082
- ).amount;
4083
- const contractAddress = wh.getChain("Moonbeam").config.contracts.tokenBridgeRelayer;
4084
- if (!contractAddress) {
4085
- throw new Error(`Wormhole address not found for ${moonChain.name}`);
4086
- }
4087
- return new ContractConfig({
4088
- address: contractAddress,
4089
- abi: TOKEN_BRIDGE_RELAYER_ABI,
4090
- args: [
4091
- tokenAddressOnMoonChain,
4092
- tokenAmountOnMoonChain,
4093
- 0,
4094
- whDestination,
4095
- destinationAddress32bytes,
4096
- 0
4097
- ],
4098
- func: "transferTokensWithRelay",
4099
- module: module4
4100
- });
4101
- }
4102
- })
4103
- };
4104
- }
4105
-
4106
- // src/mrl/providers/wormhole/contract/index.ts
4107
- function contract() {
4108
- return { Batch, Gmp, TokenBridge, TokenBridgeRelayer };
4109
- }
4110
-
4111
- // src/mrl/providers/wormhole/extrinsic/ethereumXcm/ethereumXcm.ts
4112
- import { encodeFunctionData as encodeFunctionData3 } from "viem";
4113
-
4114
- // src/mrl/MrlBuilder.constants.ts
4115
- var BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
4116
-
4117
- // src/mrl/providers/wormhole/extrinsic/ethereumXcm/BatchContractAbi.ts
4118
- var BATCH_CONTRACT_ABI = [
4119
- {
4120
- anonymous: false,
4121
- inputs: [
4122
- {
4123
- indexed: false,
4124
- internalType: "uint256",
4125
- name: "index",
4126
- type: "uint256"
4127
- }
4128
- ],
4129
- name: "SubcallFailed",
4130
- type: "event"
4131
- },
4132
- {
4133
- anonymous: false,
4134
- inputs: [
4135
- {
4136
- indexed: false,
4137
- internalType: "uint256",
4138
- name: "index",
4139
- type: "uint256"
4140
- }
4141
- ],
4142
- name: "SubcallSucceeded",
4143
- type: "event"
4144
- },
4145
- {
4146
- inputs: [
4147
- {
4148
- internalType: "address[]",
4149
- name: "to",
4150
- type: "address[]"
4151
- },
4152
- {
4153
- internalType: "uint256[]",
4154
- name: "value",
4155
- type: "uint256[]"
4156
- },
4157
- {
4158
- internalType: "bytes[]",
4159
- name: "callData",
4160
- type: "bytes[]"
4161
- },
4162
- {
4163
- internalType: "uint64[]",
4164
- name: "gasLimit",
4165
- type: "uint64[]"
4166
- }
4167
- ],
4168
- name: "batchAll",
4169
- outputs: [],
4170
- stateMutability: "nonpayable",
4171
- type: "function"
4172
- },
4173
- {
4174
- inputs: [
4175
- {
4176
- internalType: "address[]",
4177
- name: "to",
4178
- type: "address[]"
4179
- },
4180
- {
4181
- internalType: "uint256[]",
4182
- name: "value",
4183
- type: "uint256[]"
4184
- },
4185
- {
4186
- internalType: "bytes[]",
4187
- name: "callData",
4188
- type: "bytes[]"
4189
- },
4190
- {
4191
- internalType: "uint64[]",
4192
- name: "gasLimit",
4193
- type: "uint64[]"
4194
- }
4195
- ],
4196
- name: "batchSome",
4197
- outputs: [],
4198
- stateMutability: "nonpayable",
4199
- type: "function"
4200
- },
4201
- {
4202
- inputs: [
4203
- {
4204
- internalType: "address[]",
4205
- name: "to",
4206
- type: "address[]"
4207
- },
4208
- {
4209
- internalType: "uint256[]",
4210
- name: "value",
4211
- type: "uint256[]"
4212
- },
4213
- {
4214
- internalType: "bytes[]",
4215
- name: "callData",
4216
- type: "bytes[]"
4217
- },
4218
- {
4219
- internalType: "uint64[]",
4220
- name: "gasLimit",
4221
- type: "uint64[]"
4222
- }
4223
- ],
4224
- name: "batchSomeUntilFailure",
4225
- outputs: [],
4226
- stateMutability: "nonpayable",
4227
- type: "function"
4228
- }
4229
- ];
4230
-
4231
- // src/mrl/providers/wormhole/extrinsic/ethereumXcm/ethereumXcm.ts
4232
- function ethereumXcm() {
4233
- return {
4234
- transact: () => ({
4235
- build: (params) => {
4236
- const { asset, isAutomatic, moonChain, moonGasLimit } = params;
4237
- if (!moonGasLimit) {
4238
- throw new Error("moonGasLimit must be defined");
4239
- }
4240
- const tokenAddressOnMoonChain = moonChain.getChainAsset(asset).address;
4241
- if (!tokenAddressOnMoonChain) {
4242
- throw new Error(
4243
- `Asset ${asset.symbol} does not have a token address on chain ${moonChain.name}`
4244
- );
4245
- }
4246
- const tokenAmountOnMoonChain = asset.convertDecimals(
4247
- moonChain.getChainAsset(asset).decimals
4248
- ).amount;
4249
- const contract2 = isAutomatic ? contract().TokenBridgeRelayer().transferTokensWithRelay().build(params) : contract().TokenBridge().transferTokens().build(params);
4250
- const approveTx = encodeFunctionData3({
4251
- abi: ERC20_ABI,
4252
- functionName: "approve",
4253
- args: [contract2.address, tokenAmountOnMoonChain]
4254
- });
4255
- const batchAll = encodeFunctionData3({
4256
- abi: BATCH_CONTRACT_ABI,
4257
- functionName: "batchAll",
4258
- args: [
4259
- [tokenAddressOnMoonChain, contract2.address],
4260
- [0n, 0n],
4261
- // Value to send for each call
4262
- [approveTx, contract2.encodeFunctionData()],
4263
- // Call data for each call
4264
- []
4265
- // Gas limit for each call
4266
- ]
4267
- });
4268
- return new ExtrinsicConfig({
4269
- module: "ethereumXcm",
4270
- func: "transact",
4271
- getArgs: () => [
4272
- {
4273
- V2: {
4274
- gasLimit: moonGasLimit,
4275
- action: {
4276
- Call: BATCH_CONTRACT_ADDRESS
4277
- },
4278
- value: 0,
4279
- input: batchAll
4280
- }
4281
- }
4282
- ]
4283
- });
4284
- }
4285
- })
4286
- };
4287
- }
4288
-
4289
- // src/mrl/providers/wormhole/extrinsic/index.ts
4290
- function extrinsic() {
4291
- return { ethereumXcm, polkadotXcm: polkadotXcm2 };
4292
- }
4293
-
4294
- // src/mrl/providers/wormhole/index.ts
4295
- function wormhole2() {
4296
- return {
4297
- contract,
4298
- extrinsic,
4299
- wormhole
4300
- };
4301
- }
4302
-
4303
- // src/mrl/MrlBuilder.ts
4304
- function MrlBuilder() {
4305
- return {
4306
- wormhole: wormhole2
4307
- };
4308
- }
4309
- export {
4310
- AssetMinBuilder,
4311
- BATCH_CONTRACT_ABI,
4312
- BATCH_CONTRACT_ADDRESS,
4313
- BalanceBuilder,
4314
- ContractBuilder,
4315
- ContractConfig,
4316
- ERC20_ABI,
4317
- EvmQueryConfig,
4318
- ExtrinsicBuilder,
4319
- ExtrinsicConfig,
4320
- FeeBuilder,
4321
- MrlBuilder,
4322
- SubstrateCallConfig,
4323
- SubstrateQueryConfig,
4324
- WormholeConfig,
4325
- XcmVersion,
4326
- calculateSystemAccountBalance,
4327
- evm,
4328
- substrate,
4329
- wormhole2 as wormhole,
4330
- wormholeFactory
4331
- };
1
+ import"@polkadot/api-augment";import{getTypeDef as tt}from"@polkadot/types";import{u8aToHex as et}from"@polkadot/util";import{decodeAddress as rt}from"@polkadot/util-crypto";var p=(i=>(i.v1="V1",i.v2="V2",i.v3="V3",i.v4="V4",i))(p||{});function d(r,t=0){if(!r)return"V1";let{type:e}=r.meta.args[t],n=r.meta.registry.createType(e.toString()),i=tt(n==null?void 0:n.toRawType());if(!i.sub)return"V1";let o=Array.isArray(i.sub)?i.sub.map(s=>s.name):[i.sub.name];if(o.includes("V1"))return"V1";if(o.includes("V2"))return"V2";if(o.includes("V3"))return"V3";throw new Error("Can't find Xcm version")}function c(r){return r.length===42&&r.startsWith("0x")?{AccountKey20:{key:r}}:{AccountId32:{id:et(rt(r)),network:null}}}var b=(e=>(e.Evm="Evm",e.Substrate="Substrate",e))(b||{});var l=class{module;func;type;constructor({module:t,func:e,type:n}){this.module=t,this.func=e,this.type=n}};var u=class extends l{args;transform;constructor({args:t=[],transform:e,type:n="Substrate",...i}){super({...i,type:n}),this.args=t,this.transform=e}};function Ut(){return{assetRegistry:nt,assets:it,foreignAssets:ot}}function nt(){let r="assetRegistry";return{assetMetadatas:()=>({build:({asset:t})=>new u({module:r,func:"assetMetadatas",args:[t],transform:async e=>e.unwrapOrDefault().minimalBalance.toBigInt()})}),currencyMetadatas:()=>({build:({asset:t})=>new u({module:r,func:"currencyMetadatas",args:[t],transform:async e=>e.unwrapOrDefault().minimalBalance.toBigInt()})})}}function it(){return{asset:()=>({build:({asset:r})=>new u({module:"assets",func:"asset",args:[r],transform:async t=>t.unwrapOrDefault().minBalance.toBigInt()})})}}function ot(){return{asset:()=>({build:({asset:r})=>{let t={parents:2,interior:{X2:[{globalconsensus:{ethereum:{chainId:1}}},c(r)]}};return new u({module:"foreignAssets",func:"asset",args:[t],transform:async e=>e.unwrapOrDefault().minBalance.toBigInt()})}})}}import{isString as ct}from"@polkadot/util";import{evmToAddress as ut}from"@polkadot/util-crypto";import{formatAssetIdToERC20 as P}from"@moonbeam-network/xcm-utils";import{isString as E,u8aToHex as D}from"@polkadot/util";import{decodeAddress as k,evmToAddress as st}from"@polkadot/util-crypto";var f=class extends l{args;address;constructor({args:t,address:e,...n}){super({...n,type:"Evm"}),this.args=t,this.address=e}};var T=18446744073709551615n;function N(){return{transfer:(r=T)=>({build:({address:t,amount:e,asset:n,destination:i})=>new f({args:[E(n)?P(n):n,e,O(t,i),r],func:"transfer",module:"Xtokens"})}),transferMultiCurrencies:(r=T)=>({build:({address:t,amount:e,asset:n,destination:i,fee:o,feeAsset:s})=>new f({args:[[[E(n)?P(n):n,e],[E(s)?P(s):s,o]],1,O(t,i),r],func:"transferMultiCurrencies",module:"Xtokens"})}),transferWithEvmTo32:(r=T)=>({build:({address:t,amount:e,asset:n,destination:i})=>{let o=at(t,i);return new f({args:[E(n)?P(n):n,e,o,r],func:"transfer",module:"Xtokens"})}})}}function at(r,t){let e="01",n=st(r),i=`0x${e}${D(k(n),-1,!1)}00`;return[1,t.parachainId?[`0x0000000${t.parachainId.toString(16)}`,i]:[i]]}function O(r,t){let n=`0x${t.isEvmParachain()?"03":"01"}${D(k(r),-1,!1)}00`;return[1,t.parachainId?[`0x0000000${t.parachainId.toString(16)}`,n]:[n]]}function oe(){return{Xtokens:N}}function Ae(){return{evm:mt,substrate:lt}}function mt(){return{erc20:ft}}function lt(){return{assets:gt,foreignAssets:dt,system:pt,tokens:At}}function ft(){return{build:({address:r,asset:t})=>{if(!t||!ct(t))throw new Error(`Invalid contract address: ${t}`);return new f({address:t,args:[r],func:"balanceOf",module:"Erc20"})}}}function gt(){return{account:()=>({build:({address:r,asset:t})=>new u({module:"assets",func:"account",args:[t,r],transform:async e=>e.unwrapOrDefault().balance.toBigInt()})})}}function dt(){return{account:()=>({build:({address:r,asset:t})=>{let e={parents:2,interior:{X2:[{GlobalConsensus:{ethereum:{chainId:1}}},c(t)]}};return new u({module:"foreignAssets",func:"account",args:[e,r],transform:async n=>n.unwrapOrDefault().balance.toBigInt()})}})}}function pt(){return{account:()=>({build:({address:r})=>new u({module:"system",func:"account",args:[r],transform:async t=>M(t)})}),accountEquilibrium:()=>({build:({address:r,asset:t})=>new u({module:"system",func:"account",args:[r],transform:async e=>{var s;if(e.data.isEmpty)return 0n;let n=e.data.toJSON(),i;if(Array.isArray(n)&&(i=n),Array.isArray((s=n==null?void 0:n.v0)==null?void 0:s.balance)&&(i=n.v0.balance),!i)throw new Error("Can't get balance from Equilibrium chain");let o=i.find(([m])=>m===t);return o?BigInt(o[1].positive):0n}})}),accountEvmTo32:()=>({build:({address:r})=>{let t=ut(r);return new u({module:"system",func:"account",args:[t],transform:async e=>M(e)})}})}}function At(){return{accounts:()=>({build:({address:r,asset:t})=>new u({module:"tokens",func:"accounts",args:[r,t],transform:async({free:e,frozen:n})=>BigInt(e.sub(n).toString())})})}}async function M(r){let t=r.data,e=BigInt(t.free.toString()),n=t.miscFrozen??t.frozen,i=BigInt(n.sub(t.reserved).toString()),o=i<0n?0n:i;return e-o}var a=class extends l{getArgs;constructor({getArgs:t,...e}){super({...e,type:"Substrate"}),this.getArgs=t}};var R="eqBalances";function W(){return{xcmTransfer:()=>({build:({address:r,amount:t,asset:e,destination:n})=>new a({module:R,func:"xcmTransfer",getArgs:()=>[e,t,{parents:1,interior:{X2:[{Parachain:n.parachainId},c(r)]}},"ThisAccWillPay"]})}),transferXcm:()=>({build:({address:r,amount:t,asset:e,destination:n,fee:i,feeAsset:o})=>new a({module:R,func:"transferXcm",getArgs:()=>{let s=t-i>0n?t-i:0n;return[[e,e===o?s:t],[o,i],{parents:1,interior:{X2:[{Parachain:n.parachainId},c(r)]}}]}})})}}function g({asset:r,address:t,destination:e,func:n,parents:i=1,feeIndex:o=0}){let s=d(n);return[{[s]:{parents:i,interior:{X1:{Parachain:e.parachainId}}}},{[s]:{parents:0,interior:{X1:c(t)}}},{[s]:r},o,"Unlimited"]}function _({asset:r,feeAsset:t}){let e=Number(r),n=Number(t);return Number.isNaN(e)||Number.isNaN(n)?!1:e>n}var A="polkadotXcm";function L(){return{limitedReserveTransferAssets:()=>{let r="limitedReserveTransferAssets";return{here:()=>({build:t=>new a({module:A,func:r,getArgs:e=>g({...t,func:e,asset:[{id:{Concrete:{parents:0,interior:"Here"}},fun:{Fungible:t.amount}}]})})}),X1:()=>({build:t=>new a({module:A,func:r,getArgs:e=>g({...t,func:e,asset:[{id:{Concrete:{parents:0,interior:{X1:{PalletInstance:t.palletInstance}}}},fun:{Fungible:t.amount}}]})})}),X2:()=>({build:t=>new a({module:A,func:r,getArgs:e=>{let n=!!t.feeAsset&&t.asset!==t.feeAsset,i=[{id:{Concrete:{parents:0,interior:{X2:[{PalletInstance:t.palletInstance},{GeneralIndex:t.asset}]}}},fun:{Fungible:t.amount}}],o=_(t);if(n){let s={id:{Concrete:{parents:0,interior:{X2:[{PalletInstance:t.palletInstance},{GeneralIndex:t.feeAsset}]}}},fun:{Fungible:t.fee}};o?i.unshift(s):i.push(s)}return g({...t,func:e,asset:i,feeIndex:n&&!o?1:0})}})})}},limitedReserveWithdrawAssets:()=>{let r="limitedReserveWithdrawAssets";return{X2:()=>({build:t=>new a({module:A,func:r,getArgs:e=>g({...t,func:e,asset:[{id:{Concrete:{parents:1,interior:{X2:[{Parachain:t.destination.parachainId},{PalletInstance:t.palletInstance}]}}},fun:{Fungible:t.amount}}]})})})}},trasferAssets:()=>{let r="transferAssets";return{here:()=>({build:t=>new a({module:A,func:r,getArgs:e=>g({...t,func:e,asset:[{id:{Concrete:{parents:1,interior:"Here"}},fun:{Fungible:t.amount}}]})})})}},transferAssetsUsingTypeAndThen:()=>{let r="transferAssetsUsingTypeAndThen";return{globalConcensusEthereum:()=>({build:({destination:t,address:e,amount:n,asset:i})=>{let o="V4";return new a({module:A,func:r,getArgs:()=>[{[o]:{parents:1,interior:{X1:[{Parachain:t.parachainId}]}}},{[o]:[{id:{parents:2,interior:{X2:[{globalConsensus:{Ethereum:{ChainId:1}}},c(i)]}},fun:{fungible:n}}]},"LocalReserve",{[o]:{parents:2,interior:{X2:[{globalConsensus:{Ethereum:{ChainId:1}}},c(i)]}}},"LocalReserve",{[o]:[{DepositAsset:{assets:{Wild:{AllCounted:1}},beneficiary:{parents:0,interior:{X1:[c(e)]}}}}]},"Unlimited"]})}})}}}}function x(){return"Unlimited"}function C(r,t,e){return{[r]:{parents:1,interior:{X2:[{Parachain:e.parachainId},c(t)]}}}}var h="xTokens";function V(){return{transfer:()=>({build:({address:r,amount:t,asset:e,destination:n})=>new a({module:h,func:"transfer",getArgs:i=>{let o=d(i,2);return[e,t,C(o,r,n),x()]}})}),transferMultiAsset:r=>{let t="transferMultiasset";return{here:()=>({build:({address:e,amount:n,destination:i})=>new a({module:h,func:t,getArgs:o=>{let s=d(o,1);return[{[s]:{id:{Concrete:{parents:0,interior:"Here"}},fun:{Fungible:n}}},C(s,e,i),x()]}})}),X1:()=>({build:({address:e,amount:n,destination:i})=>new a({module:h,func:t,getArgs:o=>{let s=d(o,1);return[{[s]:{id:{Concrete:{parents:1,interior:{X1:{Parachain:r}}}},fun:{Fungible:n}}},C(s,e,i),x()]}})}),X2:()=>({build:({address:e,amount:n,asset:i,destination:o})=>new a({module:h,func:t,getArgs:s=>{let m=d(s,1);return[{[m]:{id:{Concrete:{parents:1,interior:{X2:[{Parachain:r},{GeneralKey:i}]}}},fun:{Fungible:n}}},C(m,e,o),x()]}})})}},transferMultiCurrencies:()=>({build:({address:r,amount:t,asset:e,destination:n,fee:i,feeAsset:o})=>new a({module:h,func:"transferMulticurrencies",getArgs:()=>[[[e,t],[o,i]],1,C("V3",r,n),x()]})})}}var U="xTransfer";function H(){return{transfer:()=>{let r="transfer";return{here:()=>({build:({address:t,amount:e,destination:n})=>new a({module:U,func:r,getArgs:()=>[{id:{Concrete:{parents:0,interior:"Here"}},fun:{Fungible:e}},{parents:1,interior:{X2:[{Parachain:n.parachainId},c(t)]}},{refTime:5e9,proofSize:0}]})}),X2:()=>({build:({address:t,amount:e,destination:n,palletInstance:i})=>new a({module:U,func:r,getArgs:()=>[{id:{Concrete:{parents:1,interior:{X2:[{Parachain:n.parachainId},{PalletInstance:i}]}}},fun:{Fungible:e||1n}},{parents:1,interior:{X2:[{Parachain:n.parachainId},c(t)]}},{refTime:5e9,proofSize:0}]})})}}}}var j="xcmPallet";function q(){return{limitedReserveTransferAssets:(r=1)=>{let t="limitedReserveTransferAssets";return{here:()=>({build:e=>new a({module:j,func:t,getArgs:n=>g({...e,parents:r,func:n,asset:[{id:{Concrete:{parents:0,interior:"Here"}},fun:{Fungible:e.amount}}]})})})}},transferAssetsUsingTypeAndThen:()=>{let r="transferAssetsUsingTypeAndThen";return{here:()=>({build:t=>new a({module:j,func:r,getArgs:()=>{let e="V4";return[{[e]:{parents:0,interior:{X1:[{Parachain:t.destination.parachainId}]}}},{[e]:[{id:{parents:0,interior:"Here"},fun:{Fungible:t.amount}}]},"LocalReserve",{[e]:{parents:0,interior:"Here"}},"LocalReserve",{[e]:[{DepositAsset:{assets:{Wild:{AllCounted:1}},beneficiary:{parents:0,interior:{X1:[c(t.address)]}}}}]},"Unlimited"]}})})}}}}function xr(){return{eqBalances:W,xTokens:V,xTransfer:H,polkadotXcm:L,xcmPallet:q}}var B=class{api;call;type="Substrate";constructor({api:t,call:e}){this.api=t,this.call=e}};import{isHexString as xt}from"@moonbeam-network/xcm-utils";var X=10**6,Ct="0xabcdef1234567890fedcba0987654321abcdef1234567890fedcba0987654321",yt="0x0000000000000000000000000000000000000802",bt={moonbeam:"10",moonriver:"10","moonbase-alpha":"3"},ht={moonbeam:"110",moonriver:"110","moonbase-alpha":"48"},w="V4";function y(){return w==="V4"}function Pt(r){if(!y())return r;let t={...r};return t.interior&&typeof t.interior=="object"&&"x1"in t.interior&&(Array.isArray(t.interior.x1)||(t.interior.x1=[t.interior.x1])),t}function z(r){return{WithdrawAsset:r.map(t=>({id:{...t},fun:{Fungible:X}}))}}function $(r){return{ReserveAssetDeposited:r.map(t=>({id:{...t},fun:{Fungible:X}}))}}function G(){return{ClearOrigin:"NULL"}}function K(r){return{BuyExecution:{fees:{id:{...r},fun:{Fungible:X}},weight_limit:{Unlimited:"NULL"}}}}function J(r,t){let e={AccountKey20:{key:r,network:null}};return{DepositAsset:{assets:{Wild:{AllCounted:t.length}},beneficiary:{interior:{X1:y()?[e]:e},parents:0},max_assets:0}}}function Q(){return{SetTopic:Ct}}function v(r){return{Concrete:{...r}}}function Et(r){let t={PalletInstance:bt[r]},e={interior:{X1:y()?[t]:t},parents:"0"};return y()?e:v(e)}function Bt(r,t){let e={interior:{X2:[{PalletInstance:ht[t]},{AccountKey20:{key:r,network:null}}]},parents:"0"};return y()?e:v(e)}async function It(r,t){let e=await r.query.assetManager.assetIdType(t);if(e.isNone||!e.unwrap().isXcm)throw new Error(`No asset type found for asset ${t}`);return e}async function S(r,t,e){if(t===yt)return Et(e.key);if(xt(t))return Bt(t,e.key);let i=(await It(r,t)).unwrap().asXcm.toJSON(),o=Pt(i);return y()?o:v(o)}async function Y(r,t,e){let n=await r.call.xcmPaymentApi.queryXcmWeight({[w]:t});if(!n.isOk)throw new Error("There was an error trying to get the weight for the xcm instructions (queryXcmWeight)");let i=n.asOk,o=await r.call.xcmPaymentApi.queryWeightToAssetFee(i,{[w]:{...e}});if(!o.isOk)throw new Error("There was an error trying to get the fee with the weight and asset (weightToForeingAssets)");return o.asOk.toBigInt()}function Sr(){return{xcmPaymentApi:Tt}}function Tt(){return{xcmPaymentFee:({isAssetReserveChain:r,shouldTransferAssetPrecedeAsset:t=!1})=>({build:({address:e,api:n,feeAsset:i,chain:o,transferAsset:s})=>new B({api:n,call:async()=>{let m=await S(n,i,o),F=await S(n,s,o),I=i===s?[m]:t?[F,m]:[m,F],Z=[r?z(I):$(I),G(),K(m),J(e,I),Q()];return Y(n,Z,m)}})})}}export{Ut as AssetMinBuilder,Ae as BalanceBuilder,l as BaseConfig,b as CallType,oe as ContractBuilder,f as ContractConfig,xr as ExtrinsicBuilder,a as ExtrinsicConfig,Sr as FeeBuilder,u as SubstrateQueryConfig,p as XcmVersion,M as calculateSystemAccountBalance,mt as evm,lt as substrate};
4332
2
  //# sourceMappingURL=index.mjs.map