@moonbeam-network/xcm-builder 4.2.1 → 4.2.2
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.d.ts +41 -1
- package/build/index.mjs +119 -25
- package/build/index.mjs.map +1 -1
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -81,11 +81,51 @@ declare class ContractConfig extends BaseConfig {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
type ContractConfigBuilder = ConfigBuilder<ContractConfig>;
|
|
84
|
+
type DestinationMultilocation = [
|
|
85
|
+
/**
|
|
86
|
+
* 1 - if transaction is going through or to a relay chain
|
|
87
|
+
*/
|
|
88
|
+
1,
|
|
89
|
+
([
|
|
90
|
+
/**
|
|
91
|
+
* example '0x00000007DC'
|
|
92
|
+
* 7DC - parachain id in hex
|
|
93
|
+
* can be found here:
|
|
94
|
+
* - https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fkusama-rpc.polkadot.io#/parachains
|
|
95
|
+
* - https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/parachains
|
|
96
|
+
*/
|
|
97
|
+
string,
|
|
98
|
+
/**
|
|
99
|
+
* example '0x01%account%00',
|
|
100
|
+
* enum = 01 (AccountId32)
|
|
101
|
+
* networkId = 00 (any)
|
|
102
|
+
*/
|
|
103
|
+
string
|
|
104
|
+
] | [
|
|
105
|
+
/**
|
|
106
|
+
* example '0x01%account%00',
|
|
107
|
+
* enum = 01 (AccountId32)
|
|
108
|
+
* networkId = 00 (any)
|
|
109
|
+
*/
|
|
110
|
+
string
|
|
111
|
+
]
|
|
112
|
+
/**
|
|
113
|
+
* example 'Here',
|
|
114
|
+
*/
|
|
115
|
+
| [])
|
|
116
|
+
];
|
|
117
|
+
type AssetAddressFormat = (string | bigint | undefined)[];
|
|
118
|
+
declare enum TransferType {
|
|
119
|
+
Teleport = 0,
|
|
120
|
+
LocalReserve = 1,
|
|
121
|
+
DestinationReserve = 2
|
|
122
|
+
}
|
|
84
123
|
|
|
85
124
|
declare function XcmPrecompile(): {
|
|
86
125
|
transferAssetsToPara20: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
87
126
|
transferAssetsToPara32: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
88
127
|
transferAssetsToRelay: () => ContractConfigBuilder;
|
|
128
|
+
transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset?: boolean) => ContractConfigBuilder;
|
|
89
129
|
};
|
|
90
130
|
|
|
91
131
|
declare function Xtokens(): {
|
|
@@ -712,4 +752,4 @@ declare function MrlBuilder(): {
|
|
|
712
752
|
|
|
713
753
|
declare const BATCH_CONTRACT_ADDRESS = "0x0000000000000000000000000000000000000808";
|
|
714
754
|
|
|
715
|
-
export { AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, Protocols, type QueryConfigConstructorParams, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
|
|
755
|
+
export { type AssetAddressFormat, AssetMinBuilder, type AssetMinConfigBuilder, type AssetMinConfigBuilderParams, BATCH_CONTRACT_ABI, BATCH_CONTRACT_ADDRESS, BalanceBuilder, type BalanceBuilderParams, type BalanceConfigBuilder, type BuilderParams, type ConfigBuilder, ContractBuilder, ContractConfig, type ContractConfigBuilder, type ContractConfigConstructorParams, type DestinationMultilocation, ERC20_ABI, type EquilibriumSystemBalanceData, type EventMonitoringConfig, type EvmFunctionArgs, EvmQueryConfig, type EvmQueryConfigParams, type EvmQueryFunctions, ExtrinsicBuilder, ExtrinsicConfig, type ExtrinsicConfigBuilder, type ExtrinsicConfigConstructorParams, FeeBuilder, type FeeConfigBuilder, type FeeConfigBuilderParams, type GetVersionedAssetId, MonitoringBuilder, type MonitoringBuilderConfig, type MoonbeamRuntimeXcmConfigAssetType, MrlBuilder, type MrlBuilderParams, type MrlConfigBuilder, type MrlExecuteBuilderParams, type MrlExecuteConfigBuilder, type PalletBalancesAccountDataOld, type Parents, Protocols, type QueryConfigConstructorParams, SubstrateCallConfig, type SubstrateCallConfigConstructorParams, SubstrateQueryConfig, type TokensPalletAccountData, type Transact, TransferType, WormholeConfig, type WormholeConfigConstructorParams, type WormholeFunctionArgs, type WormholeTransferFunctions, type XcmPaymentFeeProps, XcmVersion, calculateSystemAccountBalance, evm, substrate, wormhole, wormholeFactory };
|
package/build/index.mjs
CHANGED
|
@@ -228,8 +228,8 @@ var ContractConfig = class _ContractConfig extends BaseConfig {
|
|
|
228
228
|
};
|
|
229
229
|
|
|
230
230
|
// src/contract/contracts/XcmPrecompile/XcmPrecompile.ts
|
|
231
|
-
import { u8aToHex as
|
|
232
|
-
import { decodeAddress as
|
|
231
|
+
import { u8aToHex as u8aToHex3 } from "@polkadot/util";
|
|
232
|
+
import { decodeAddress as decodeAddress3 } from "@polkadot/util-crypto";
|
|
233
233
|
|
|
234
234
|
// src/types/evm/EvmQueryConfig.ts
|
|
235
235
|
var EvmQueryConfig = class _EvmQueryConfig {
|
|
@@ -271,6 +271,53 @@ var SubstrateCallConfig = class _SubstrateCallConfig {
|
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
// src/contract/ContractBuilder.interfaces.ts
|
|
275
|
+
var TransferType = /* @__PURE__ */ ((TransferType2) => {
|
|
276
|
+
TransferType2[TransferType2["Teleport"] = 0] = "Teleport";
|
|
277
|
+
TransferType2[TransferType2["LocalReserve"] = 1] = "LocalReserve";
|
|
278
|
+
TransferType2[TransferType2["DestinationReserve"] = 2] = "DestinationReserve";
|
|
279
|
+
return TransferType2;
|
|
280
|
+
})(TransferType || {});
|
|
281
|
+
|
|
282
|
+
// src/contract/ContractBuilder.utils.ts
|
|
283
|
+
import { EvmParachain } from "@moonbeam-network/xcm-types";
|
|
284
|
+
import { u8aToHex as u8aToHex2 } from "@polkadot/util";
|
|
285
|
+
import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
|
|
286
|
+
function getPrecompileDestinationInterior(destination, address) {
|
|
287
|
+
if (!address) {
|
|
288
|
+
return [`0x0000000${destination.parachainId.toString(16)}`];
|
|
289
|
+
}
|
|
290
|
+
const accountType = EvmParachain.is(destination) ? "03" : "01";
|
|
291
|
+
const acc = `0x${accountType}${u8aToHex2(
|
|
292
|
+
decodeAddress2(address),
|
|
293
|
+
-1,
|
|
294
|
+
false
|
|
295
|
+
)}00`;
|
|
296
|
+
return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
|
|
297
|
+
}
|
|
298
|
+
function getDestinationMultilocation(address, destination) {
|
|
299
|
+
const interior = getPrecompileDestinationInterior(destination, address);
|
|
300
|
+
return [1, interior];
|
|
301
|
+
}
|
|
302
|
+
function getDestinationParachainMultilocation(destination) {
|
|
303
|
+
if (destination.isRelay) {
|
|
304
|
+
return [1, []];
|
|
305
|
+
}
|
|
306
|
+
return [1, [`0x00${destination.parachainId.toString(16).padStart(8, "0")}`]];
|
|
307
|
+
}
|
|
308
|
+
function encodeXcmMessageToBytes(xcmMessage, api) {
|
|
309
|
+
if (!api) {
|
|
310
|
+
throw new Error("API is required to encode XCM message");
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
const versionedXcm = api.createType("XcmVersionedXcm", xcmMessage);
|
|
314
|
+
return versionedXcm.toHex();
|
|
315
|
+
} catch (error) {
|
|
316
|
+
console.error("Failed to encode XCM message:", error);
|
|
317
|
+
throw error;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
274
321
|
// src/contract/contracts/XcmPrecompile/XcmPrecompileAbi.ts
|
|
275
322
|
var XCM_ABI = [
|
|
276
323
|
{
|
|
@@ -784,7 +831,7 @@ function XcmPrecompile() {
|
|
|
784
831
|
abi: XCM_ABI,
|
|
785
832
|
args: [
|
|
786
833
|
destination.parachainId,
|
|
787
|
-
|
|
834
|
+
u8aToHex3(decodeAddress3(destinationAddress)),
|
|
788
835
|
assets3,
|
|
789
836
|
0
|
|
790
837
|
],
|
|
@@ -799,7 +846,7 @@ function XcmPrecompile() {
|
|
|
799
846
|
address: XCM_PRECOMPILE_ADDRESS,
|
|
800
847
|
abi: XCM_ABI,
|
|
801
848
|
args: [
|
|
802
|
-
|
|
849
|
+
u8aToHex3(decodeAddress3(destinationAddress)),
|
|
803
850
|
[[asset.address, asset.amount]],
|
|
804
851
|
0
|
|
805
852
|
],
|
|
@@ -807,6 +854,47 @@ function XcmPrecompile() {
|
|
|
807
854
|
module: "Xcm"
|
|
808
855
|
});
|
|
809
856
|
}
|
|
857
|
+
}),
|
|
858
|
+
transferAssetsUsingTypeAndThenAddress: (shouldTransferAssetPrecedeFeeAsset = false) => ({
|
|
859
|
+
build: ({
|
|
860
|
+
destinationAddress,
|
|
861
|
+
asset,
|
|
862
|
+
fee,
|
|
863
|
+
destination,
|
|
864
|
+
destinationApi,
|
|
865
|
+
sourceApi
|
|
866
|
+
}) => {
|
|
867
|
+
const assets3 = getAssets(
|
|
868
|
+
asset,
|
|
869
|
+
fee,
|
|
870
|
+
shouldTransferAssetPrecedeFeeAsset
|
|
871
|
+
);
|
|
872
|
+
const destLocation = getDestinationParachainMultilocation(destination);
|
|
873
|
+
const xcmMessage = buildXcmMessage(
|
|
874
|
+
assets3,
|
|
875
|
+
destinationAddress,
|
|
876
|
+
sourceApi
|
|
877
|
+
);
|
|
878
|
+
const customXcmOnDest = encodeXcmMessageToBytes(
|
|
879
|
+
xcmMessage,
|
|
880
|
+
destinationApi
|
|
881
|
+
);
|
|
882
|
+
const feeIndex = shouldTransferAssetPrecedeFeeAsset ? 1 : 0;
|
|
883
|
+
return new ContractConfig({
|
|
884
|
+
address: XCM_PRECOMPILE_ADDRESS,
|
|
885
|
+
abi: XCM_ABI,
|
|
886
|
+
args: [
|
|
887
|
+
destLocation,
|
|
888
|
+
assets3,
|
|
889
|
+
2 /* DestinationReserve */,
|
|
890
|
+
feeIndex,
|
|
891
|
+
2 /* DestinationReserve */,
|
|
892
|
+
customXcmOnDest
|
|
893
|
+
],
|
|
894
|
+
func: "transferAssetsUsingTypeAndThenAddress",
|
|
895
|
+
module: "Xcm"
|
|
896
|
+
});
|
|
897
|
+
}
|
|
810
898
|
})
|
|
811
899
|
};
|
|
812
900
|
}
|
|
@@ -822,29 +910,38 @@ function getAssets(asset, feeAsset, shouldTransferAssetPrecedeFeeAsset) {
|
|
|
822
910
|
[asset.address, asset.amount]
|
|
823
911
|
];
|
|
824
912
|
}
|
|
913
|
+
function buildXcmMessage(assets3, destinationAddress, sourceApi) {
|
|
914
|
+
const xcmVersion = getExtrinsicArgumentVersion(
|
|
915
|
+
sourceApi?.tx.polkadotXcm?.send || sourceApi?.tx.xcmPallet?.send
|
|
916
|
+
);
|
|
917
|
+
const instruction = {
|
|
918
|
+
DepositAsset: {
|
|
919
|
+
assets: { Wild: { AllCounted: assets3.length } },
|
|
920
|
+
beneficiary: {
|
|
921
|
+
parents: 0,
|
|
922
|
+
interior: {
|
|
923
|
+
X1: [
|
|
924
|
+
{
|
|
925
|
+
AccountId32: {
|
|
926
|
+
id: u8aToHex3(decodeAddress3(destinationAddress)),
|
|
927
|
+
network: null
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
]
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
return {
|
|
936
|
+
[xcmVersion]: [instruction]
|
|
937
|
+
};
|
|
938
|
+
}
|
|
825
939
|
|
|
826
940
|
// src/contract/contracts/Xtokens/Xtokens.ts
|
|
827
941
|
import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";
|
|
828
942
|
import { u8aToHex as u8aToHex4 } from "@polkadot/util";
|
|
829
943
|
import { decodeAddress as decodeAddress4, evmToAddress } from "@polkadot/util-crypto";
|
|
830
944
|
|
|
831
|
-
// src/builder.utils.ts
|
|
832
|
-
import { EvmParachain } from "@moonbeam-network/xcm-types";
|
|
833
|
-
import { u8aToHex as u8aToHex3 } from "@polkadot/util";
|
|
834
|
-
import { decodeAddress as decodeAddress3 } from "@polkadot/util-crypto";
|
|
835
|
-
function getPrecompileDestinationInterior(destination, address) {
|
|
836
|
-
if (!address) {
|
|
837
|
-
return [`0x0000000${destination.parachainId.toString(16)}`];
|
|
838
|
-
}
|
|
839
|
-
const accountType = EvmParachain.is(destination) ? "03" : "01";
|
|
840
|
-
const acc = `0x${accountType}${u8aToHex3(
|
|
841
|
-
decodeAddress3(address),
|
|
842
|
-
-1,
|
|
843
|
-
false
|
|
844
|
-
)}00`;
|
|
845
|
-
return destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc];
|
|
846
|
-
}
|
|
847
|
-
|
|
848
945
|
// src/contract/contracts/Xtokens/XtokensABI.ts
|
|
849
946
|
var XTOKENS_ABI = [
|
|
850
947
|
{
|
|
@@ -1021,10 +1118,6 @@ function getDestinationMultilocationForPrecompileDestination(address, destinatio
|
|
|
1021
1118
|
destination.parachainId ? [`0x0000000${destination.parachainId.toString(16)}`, acc] : [acc]
|
|
1022
1119
|
];
|
|
1023
1120
|
}
|
|
1024
|
-
function getDestinationMultilocation(address, destination) {
|
|
1025
|
-
const interior = getPrecompileDestinationInterior(destination, address);
|
|
1026
|
-
return [1, interior];
|
|
1027
|
-
}
|
|
1028
1121
|
|
|
1029
1122
|
// src/contract/ContractBuilder.ts
|
|
1030
1123
|
function ContractBuilder() {
|
|
@@ -6229,6 +6322,7 @@ export {
|
|
|
6229
6322
|
Protocols,
|
|
6230
6323
|
SubstrateCallConfig,
|
|
6231
6324
|
SubstrateQueryConfig,
|
|
6325
|
+
TransferType,
|
|
6232
6326
|
WormholeConfig,
|
|
6233
6327
|
XcmVersion,
|
|
6234
6328
|
calculateSystemAccountBalance,
|