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

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