@moonbeam-network/xcm-builder 2.6.1 → 3.0.0

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