@moonbeam-network/xcm-builder 1.0.0-dev.153 → 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.d.ts +12 -0
- package/build/index.mjs +234 -87
- package/build/index.mjs.map +1 -1
- package/package.json +8 -8
package/build/index.d.ts
CHANGED
|
@@ -44,12 +44,14 @@ declare class SubstrateQueryConfig extends BaseConfig {
|
|
|
44
44
|
|
|
45
45
|
type AssetMinConfigBuilder = ConfigBuilder<SubstrateQueryConfig, AssetMinConfigBuilderParams>;
|
|
46
46
|
interface AssetMinConfigBuilderParams {
|
|
47
|
+
address?: string;
|
|
47
48
|
asset: ChainAssetId;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
declare function AssetMinBuilder(): {
|
|
51
52
|
assetRegistry: typeof assetRegistry;
|
|
52
53
|
assets: typeof assets$1;
|
|
54
|
+
foreignAssets: typeof foreignAssets$1;
|
|
53
55
|
};
|
|
54
56
|
declare function assetRegistry(): {
|
|
55
57
|
assetMetadatas: () => AssetMinConfigBuilder;
|
|
@@ -58,6 +60,9 @@ declare function assetRegistry(): {
|
|
|
58
60
|
declare function assets$1(): {
|
|
59
61
|
asset: () => AssetMinConfigBuilder;
|
|
60
62
|
};
|
|
63
|
+
declare function foreignAssets$1(): {
|
|
64
|
+
asset: () => AssetMinConfigBuilder;
|
|
65
|
+
};
|
|
61
66
|
|
|
62
67
|
interface ContractConfigConstructorParams extends BaseConfigConstructorParams {
|
|
63
68
|
address: string;
|
|
@@ -133,12 +138,16 @@ declare function erc20(): BalanceConfigBuilder;
|
|
|
133
138
|
declare function native(): BalanceConfigBuilder;
|
|
134
139
|
declare function substrate(): {
|
|
135
140
|
assets: typeof assets;
|
|
141
|
+
foreignAssets: typeof foreignAssets;
|
|
136
142
|
system: typeof system;
|
|
137
143
|
tokens: typeof tokens;
|
|
138
144
|
};
|
|
139
145
|
declare function assets(): {
|
|
140
146
|
account: () => BalanceConfigBuilder;
|
|
141
147
|
};
|
|
148
|
+
declare function foreignAssets(): {
|
|
149
|
+
account: () => BalanceConfigBuilder;
|
|
150
|
+
};
|
|
142
151
|
declare function system(): {
|
|
143
152
|
account: () => BalanceConfigBuilder;
|
|
144
153
|
accountEquilibrium: () => BalanceConfigBuilder;
|
|
@@ -354,6 +363,9 @@ declare function polkadotXcm$1(): {
|
|
|
354
363
|
transferAssets: () => {
|
|
355
364
|
here: () => ExtrinsicConfigBuilder;
|
|
356
365
|
};
|
|
366
|
+
transferAssetsUsingTypeAndThen: () => {
|
|
367
|
+
globalConsensusEthereum: () => ExtrinsicConfigBuilder;
|
|
368
|
+
};
|
|
357
369
|
};
|
|
358
370
|
|
|
359
371
|
declare function xTokens(): {
|
package/build/index.mjs
CHANGED
|
@@ -1,6 +1,84 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import "@polkadot/api-augment";
|
|
3
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
|
+
|
|
4
82
|
// src/types/BaseConfig.ts
|
|
5
83
|
var BaseConfig = class {
|
|
6
84
|
module;
|
|
@@ -33,7 +111,8 @@ var SubstrateQueryConfig = class _SubstrateQueryConfig extends BaseConfig {
|
|
|
33
111
|
function AssetMinBuilder() {
|
|
34
112
|
return {
|
|
35
113
|
assetRegistry,
|
|
36
|
-
assets
|
|
114
|
+
assets,
|
|
115
|
+
foreignAssets
|
|
37
116
|
};
|
|
38
117
|
}
|
|
39
118
|
function assetRegistry() {
|
|
@@ -71,6 +150,40 @@ function assets() {
|
|
|
71
150
|
})
|
|
72
151
|
};
|
|
73
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
|
+
}
|
|
74
187
|
|
|
75
188
|
// src/balance/BalanceBuilder.ts
|
|
76
189
|
import { evmToAddress as evmToAddress2 } from "@polkadot/util-crypto";
|
|
@@ -107,20 +220,20 @@ var ContractConfig = class _ContractConfig extends BaseConfig {
|
|
|
107
220
|
|
|
108
221
|
// src/contract/contracts/Xtokens/Xtokens.ts
|
|
109
222
|
import { formatAssetIdToERC20 } from "@moonbeam-network/xcm-utils";
|
|
110
|
-
import { u8aToHex as
|
|
111
|
-
import { decodeAddress as
|
|
223
|
+
import { u8aToHex as u8aToHex3 } from "@polkadot/util";
|
|
224
|
+
import { decodeAddress as decodeAddress3, evmToAddress } from "@polkadot/util-crypto";
|
|
112
225
|
|
|
113
226
|
// src/builder.utils.ts
|
|
114
227
|
import { EvmParachain } from "@moonbeam-network/xcm-types";
|
|
115
|
-
import { u8aToHex } from "@polkadot/util";
|
|
116
|
-
import { decodeAddress } from "@polkadot/util-crypto";
|
|
228
|
+
import { u8aToHex as u8aToHex2 } from "@polkadot/util";
|
|
229
|
+
import { decodeAddress as decodeAddress2 } from "@polkadot/util-crypto";
|
|
117
230
|
function getPrecompileDestinationInterior(destination, address) {
|
|
118
231
|
if (!address) {
|
|
119
232
|
return [`0x0000000${destination.parachainId.toString(16)}`];
|
|
120
233
|
}
|
|
121
234
|
const accountType = EvmParachain.is(destination) ? "03" : "01";
|
|
122
|
-
const acc = `0x${accountType}${
|
|
123
|
-
|
|
235
|
+
const acc = `0x${accountType}${u8aToHex2(
|
|
236
|
+
decodeAddress2(address),
|
|
124
237
|
-1,
|
|
125
238
|
false
|
|
126
239
|
)}00`;
|
|
@@ -291,8 +404,8 @@ function Xtokens() {
|
|
|
291
404
|
function getDestinationMultilocationForPrecompileDestination(address, destination) {
|
|
292
405
|
const accountType = "01";
|
|
293
406
|
const substrateAddress = evmToAddress(address);
|
|
294
|
-
const acc = `0x${accountType}${
|
|
295
|
-
|
|
407
|
+
const acc = `0x${accountType}${u8aToHex3(
|
|
408
|
+
decodeAddress3(substrateAddress),
|
|
296
409
|
-1,
|
|
297
410
|
false
|
|
298
411
|
)}00`;
|
|
@@ -592,6 +705,7 @@ function native() {
|
|
|
592
705
|
function substrate() {
|
|
593
706
|
return {
|
|
594
707
|
assets: assets2,
|
|
708
|
+
foreignAssets: foreignAssets2,
|
|
595
709
|
system,
|
|
596
710
|
tokens
|
|
597
711
|
};
|
|
@@ -608,6 +722,34 @@ function assets2() {
|
|
|
608
722
|
})
|
|
609
723
|
};
|
|
610
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
|
+
}
|
|
611
753
|
function system() {
|
|
612
754
|
return {
|
|
613
755
|
account: () => ({
|
|
@@ -698,84 +840,6 @@ var ExtrinsicConfig = class _ExtrinsicConfig extends BaseConfig {
|
|
|
698
840
|
}
|
|
699
841
|
};
|
|
700
842
|
|
|
701
|
-
// src/extrinsic/ExtrinsicBuilder.utils.ts
|
|
702
|
-
import { getTypeDef } from "@polkadot/types";
|
|
703
|
-
import { u8aToHex as u8aToHex3 } from "@polkadot/util";
|
|
704
|
-
import { decodeAddress as decodeAddress3 } from "@polkadot/util-crypto";
|
|
705
|
-
|
|
706
|
-
// src/extrinsic/ExtrinsicBuilder.interfaces.ts
|
|
707
|
-
var XcmVersion = /* @__PURE__ */ ((XcmVersion2) => {
|
|
708
|
-
XcmVersion2["v1"] = "V1";
|
|
709
|
-
XcmVersion2["v2"] = "V2";
|
|
710
|
-
XcmVersion2["v3"] = "V3";
|
|
711
|
-
XcmVersion2["v4"] = "V4";
|
|
712
|
-
XcmVersion2["v5"] = "V5";
|
|
713
|
-
return XcmVersion2;
|
|
714
|
-
})(XcmVersion || {});
|
|
715
|
-
|
|
716
|
-
// src/extrinsic/ExtrinsicBuilder.utils.ts
|
|
717
|
-
function getExtrinsicArgumentVersion(func, index = 0) {
|
|
718
|
-
if (!func) return "V1" /* v1 */;
|
|
719
|
-
const { type } = func.meta.args[index];
|
|
720
|
-
const instance = func.meta.registry.createType(type.toString());
|
|
721
|
-
const raw = getTypeDef(instance?.toRawType());
|
|
722
|
-
if (!raw.sub) {
|
|
723
|
-
return "V1" /* v1 */;
|
|
724
|
-
}
|
|
725
|
-
const versions = Array.isArray(raw.sub) ? raw.sub.map((x) => x.name) : [raw.sub.name];
|
|
726
|
-
if (versions.includes("V5" /* v5 */)) {
|
|
727
|
-
return "V5" /* v5 */;
|
|
728
|
-
}
|
|
729
|
-
if (versions.includes("V4" /* v4 */)) {
|
|
730
|
-
return "V4" /* v4 */;
|
|
731
|
-
}
|
|
732
|
-
if (versions.includes("V3" /* v3 */)) {
|
|
733
|
-
return "V3" /* v3 */;
|
|
734
|
-
}
|
|
735
|
-
if (versions.includes("V2" /* v2 */)) {
|
|
736
|
-
return "V2" /* v2 */;
|
|
737
|
-
}
|
|
738
|
-
if (versions.includes("V1" /* v1 */)) {
|
|
739
|
-
return "V1" /* v1 */;
|
|
740
|
-
}
|
|
741
|
-
throw new Error("Can't find XCM version");
|
|
742
|
-
}
|
|
743
|
-
function getExtrinsicAccount(address) {
|
|
744
|
-
const isEthAddress = address.length === 42 && address.startsWith("0x");
|
|
745
|
-
return isEthAddress ? {
|
|
746
|
-
AccountKey20: {
|
|
747
|
-
key: address
|
|
748
|
-
}
|
|
749
|
-
} : {
|
|
750
|
-
AccountId32: {
|
|
751
|
-
id: u8aToHex3(decodeAddress3(address)),
|
|
752
|
-
network: null
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
function isXcmV4(xcmVersion) {
|
|
757
|
-
return xcmVersion >= "V4" /* v4 */;
|
|
758
|
-
}
|
|
759
|
-
function normalizeX1(xcmVersion, versionedObject) {
|
|
760
|
-
if (!isXcmV4(xcmVersion)) return versionedObject;
|
|
761
|
-
const normalizedObject = { ...versionedObject };
|
|
762
|
-
const interior = normalizedObject.interior;
|
|
763
|
-
if ("X1" in interior && interior?.X1 && !Array.isArray(interior.X1)) {
|
|
764
|
-
interior.X1 = [interior.X1];
|
|
765
|
-
} else if ("x1" in interior && interior?.x1 && !Array.isArray(interior.x1)) {
|
|
766
|
-
interior.x1 = [interior.x1];
|
|
767
|
-
}
|
|
768
|
-
return normalizedObject;
|
|
769
|
-
}
|
|
770
|
-
function normalizeConcrete(xcmVersion, versionedObject) {
|
|
771
|
-
return isXcmV4(xcmVersion) ? versionedObject : applyConcreteWrapper(versionedObject);
|
|
772
|
-
}
|
|
773
|
-
function applyConcreteWrapper(versionedObject) {
|
|
774
|
-
return {
|
|
775
|
-
Concrete: { ...versionedObject }
|
|
776
|
-
};
|
|
777
|
-
}
|
|
778
|
-
|
|
779
843
|
// src/extrinsic/pallets/eqBalances/eqBalances.ts
|
|
780
844
|
var pallet = "eqBalances";
|
|
781
845
|
function eqBalances() {
|
|
@@ -1073,6 +1137,89 @@ function polkadotXcm() {
|
|
|
1073
1137
|
})
|
|
1074
1138
|
})
|
|
1075
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
|
+
};
|
|
1076
1223
|
}
|
|
1077
1224
|
};
|
|
1078
1225
|
}
|