@moonbeam-network/xcm-utils 2.2.5 → 3.0.1
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/LICENSE +1 -1
- package/README.md +16 -5
- package/build/index.d.ts +29 -37
- package/build/index.mjs +158 -1
- package/build/index.mjs.map +1 -1
- package/package.json +19 -28
- package/build/index.cjs +0 -2
- package/build/index.cjs.map +0 -1
- package/build/index.d.cts +0 -27
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 Moonbeam Foundation
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
The Utils package contains the utility functions for the Moonbeam XCM SDK and MRL SDK.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# Documentation for the Moonbeam XCM SDK
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## v3 (current)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
### Usage
|
|
8
8
|
|
|
9
|
-
-
|
|
9
|
+
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/example-usage/xcm)
|
|
10
|
+
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/example-usage/mrl)
|
|
11
|
+
|
|
12
|
+
### References
|
|
13
|
+
|
|
14
|
+
- [XCM SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/reference/xcm)
|
|
15
|
+
- [MRL SDK](https://moonbeam-foundation.github.io/xcm-sdk/latest/reference/mrl)
|
|
16
|
+
|
|
17
|
+
## v2 (previous)
|
|
18
|
+
|
|
19
|
+
- [usage](https://moonbeam-foundation.github.io/xcm-sdk/v2/example-usage)
|
|
20
|
+
- [references](https://moonbeam-foundation.github.io/xcm-sdk/v2/reference/interfaces)
|
package/build/index.d.ts
CHANGED
|
@@ -4,49 +4,41 @@ import { ApiPromise } from '@polkadot/api';
|
|
|
4
4
|
declare function isHexString(asset: unknown): boolean;
|
|
5
5
|
|
|
6
6
|
declare function formatAssetIdToERC20(id: string): string;
|
|
7
|
+
declare function convertAddressTo32Bytes(address: string): string;
|
|
7
8
|
|
|
8
|
-
declare function toDecimal(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
roundType?: RoundingMode,
|
|
13
|
-
): string;
|
|
14
|
-
declare function toBigInt(
|
|
15
|
-
amount: bigint | string | number,
|
|
16
|
-
decimals: number,
|
|
17
|
-
): bigint;
|
|
18
|
-
declare function convertDecimals(
|
|
19
|
-
number: string | bigint,
|
|
20
|
-
decimals: number,
|
|
21
|
-
targetDecimals: number,
|
|
22
|
-
): bigint;
|
|
23
|
-
declare function hasDecimalOverflow(
|
|
24
|
-
fl: number | string,
|
|
25
|
-
maxDecimal: number,
|
|
26
|
-
): boolean;
|
|
9
|
+
declare function toDecimal(number: bigint | number | string, decimals: number, maxDecimal?: number, roundType?: RoundingMode): string;
|
|
10
|
+
declare function toBigInt(amount: bigint | string | number, decimals: number): bigint;
|
|
11
|
+
declare function convertDecimals(number: string | bigint, decimals: number, targetDecimals: number): bigint;
|
|
12
|
+
declare function hasDecimalOverflow(fl: number | string, maxDecimal: number): boolean;
|
|
27
13
|
|
|
28
14
|
declare enum MRLTypes {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
XcmVersionedMultiLocation = "XcmVersionedMultiLocation",
|
|
16
|
+
XcmVersionedLocation = "XcmVersionedLocation",
|
|
17
|
+
XcmRoutingUserAction = "XcmRoutingUserAction",
|
|
18
|
+
VersionedUserAction = "VersionedUserAction"
|
|
33
19
|
}
|
|
34
20
|
declare function getPolkadotApi(ws: string | string[]): Promise<ApiPromise>;
|
|
35
21
|
|
|
22
|
+
declare function getPolkadotAppsUrl(ws: string): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* reference: https://github.com/Moonsong-Labs/xcm-tools/blob/main/scripts/calculate-sovereign-account.ts
|
|
26
|
+
*/
|
|
36
27
|
declare function getSovereignAccountAddresses(paraId: number): {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
generic: string;
|
|
29
|
+
moonbeam: string;
|
|
30
|
+
relay: string;
|
|
40
31
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
toDecimal,
|
|
32
|
+
/**
|
|
33
|
+
* reference: https://github.com/Moonsong-Labs/xcm-tools/blob/main/scripts/calculate-multilocation-derivative-account.ts
|
|
34
|
+
*/
|
|
35
|
+
declare function getMultilocationDerivedAddresses({ paraId, address, isParents, }: {
|
|
36
|
+
paraId?: number;
|
|
37
|
+
address: string;
|
|
38
|
+
isParents?: boolean;
|
|
39
|
+
}): {
|
|
40
|
+
address20: `0x${string}`;
|
|
41
|
+
address32: `0x${string}`;
|
|
52
42
|
};
|
|
43
|
+
|
|
44
|
+
export { MRLTypes, convertAddressTo32Bytes, convertDecimals, formatAssetIdToERC20, getMultilocationDerivedAddresses, getPolkadotApi, getPolkadotAppsUrl, getSovereignAccountAddresses, hasDecimalOverflow, isHexString, toBigInt, toDecimal };
|
package/build/index.mjs
CHANGED
|
@@ -1,2 +1,159 @@
|
|
|
1
|
-
|
|
1
|
+
// src/format/address.ts
|
|
2
|
+
function isHexString(asset) {
|
|
3
|
+
return typeof asset === "string" && asset.startsWith("0x");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
// src/format/asset.ts
|
|
7
|
+
function formatAssetIdToERC20(id) {
|
|
8
|
+
if (id.startsWith("0x")) {
|
|
9
|
+
return id;
|
|
10
|
+
}
|
|
11
|
+
if (!/^\d{38,39}$/.test(id)) {
|
|
12
|
+
throw new Error(`Asset id: ${id} must be a string and have 38-39 digits`);
|
|
13
|
+
}
|
|
14
|
+
return `0xffffffff${BigInt(id).toString(16).padStart(32, "0")}`;
|
|
15
|
+
}
|
|
16
|
+
function convertAddressTo32Bytes(address) {
|
|
17
|
+
if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {
|
|
18
|
+
throw new Error(`Invalid address: ${address}`);
|
|
19
|
+
}
|
|
20
|
+
return `0x000000000000000000000000${address.substring(2)}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/numbers/decimals.ts
|
|
24
|
+
import Big from "big.js";
|
|
25
|
+
Big.NE = -18;
|
|
26
|
+
function toDecimal(number, decimals, maxDecimal = 6, roundType) {
|
|
27
|
+
const dividend = Big(number.toString().replace(/[^0-9]/g, ""));
|
|
28
|
+
const divisor = Big(10).pow(decimals);
|
|
29
|
+
const result = dividend.div(divisor).round(maxDecimal, roundType);
|
|
30
|
+
return result.toString();
|
|
31
|
+
}
|
|
32
|
+
function toBigInt(amount, decimals) {
|
|
33
|
+
if (typeof amount === "bigint") {
|
|
34
|
+
return amount;
|
|
35
|
+
}
|
|
36
|
+
const multiplier = Big(10).pow(decimals);
|
|
37
|
+
const result = Big(amount).mul(multiplier);
|
|
38
|
+
return BigInt(result.toFixed(0, Big.roundDown));
|
|
39
|
+
}
|
|
40
|
+
function convertDecimals(number, decimals, targetDecimals) {
|
|
41
|
+
const decimalNumber = toDecimal(number, decimals, decimals);
|
|
42
|
+
return toBigInt(decimalNumber.toString(), targetDecimals);
|
|
43
|
+
}
|
|
44
|
+
function hasDecimalOverflow(fl, maxDecimal) {
|
|
45
|
+
const parts = fl.toString().split(".");
|
|
46
|
+
return parts.length > 1 && parts[1].length > maxDecimal;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/polkadot/polkadot.api.ts
|
|
50
|
+
import { ApiPromise, WsProvider } from "@polkadot/api";
|
|
51
|
+
import { typesBundle } from "@polkadot/apps-config";
|
|
52
|
+
import { LRUCache } from "lru-cache";
|
|
53
|
+
var MRLTypes = /* @__PURE__ */ ((MRLTypes2) => {
|
|
54
|
+
MRLTypes2["XcmVersionedMultiLocation"] = "XcmVersionedMultiLocation";
|
|
55
|
+
MRLTypes2["XcmVersionedLocation"] = "XcmVersionedLocation";
|
|
56
|
+
MRLTypes2["XcmRoutingUserAction"] = "XcmRoutingUserAction";
|
|
57
|
+
MRLTypes2["VersionedUserAction"] = "VersionedUserAction";
|
|
58
|
+
return MRLTypes2;
|
|
59
|
+
})(MRLTypes || {});
|
|
60
|
+
var cache = new LRUCache({
|
|
61
|
+
max: 20,
|
|
62
|
+
dispose: async (promise) => {
|
|
63
|
+
const api = await promise;
|
|
64
|
+
if (api.isConnected) {
|
|
65
|
+
api.disconnect();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
async function getPolkadotApi(ws) {
|
|
70
|
+
const key = Array.isArray(ws) ? ws.join(";") : ws;
|
|
71
|
+
const promise = cache.get(key) || ApiPromise.create({
|
|
72
|
+
noInitWarn: true,
|
|
73
|
+
provider: new WsProvider(ws),
|
|
74
|
+
types: {
|
|
75
|
+
["XcmRoutingUserAction" /* XcmRoutingUserAction */]: {
|
|
76
|
+
destination: "XcmVersionedLocation" /* XcmVersionedLocation */
|
|
77
|
+
},
|
|
78
|
+
["VersionedUserAction" /* VersionedUserAction */]: {
|
|
79
|
+
_enum: { V1: "XcmRoutingUserAction" /* XcmRoutingUserAction */ }
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
typesBundle
|
|
83
|
+
});
|
|
84
|
+
cache.set(key, promise);
|
|
85
|
+
const api = await promise;
|
|
86
|
+
await api.isReady;
|
|
87
|
+
return api;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/polkadot/polkadot.apps.ts
|
|
91
|
+
function getPolkadotAppsUrl(ws) {
|
|
92
|
+
return `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(ws)}#/explorer/query`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/polkadot/polkadot.address.ts
|
|
96
|
+
import {
|
|
97
|
+
bnToU8a,
|
|
98
|
+
compactToU8a,
|
|
99
|
+
hexToU8a,
|
|
100
|
+
stringToU8a,
|
|
101
|
+
u8aToHex
|
|
102
|
+
} from "@polkadot/util";
|
|
103
|
+
import { blake2AsU8a, decodeAddress } from "@polkadot/util-crypto";
|
|
104
|
+
function getSovereignAccountAddresses(paraId) {
|
|
105
|
+
const paraIdU8a = bnToU8a(paraId, { bitLength: 32 });
|
|
106
|
+
const relay = u8aToHex(
|
|
107
|
+
new Uint8Array([...stringToU8a("para"), ...paraIdU8a])
|
|
108
|
+
).padEnd(66, "0");
|
|
109
|
+
const generic = u8aToHex(
|
|
110
|
+
new Uint8Array([...stringToU8a("sibl"), ...paraIdU8a])
|
|
111
|
+
).padEnd(66, "0");
|
|
112
|
+
const moonbeam = generic.slice(0, 42);
|
|
113
|
+
return {
|
|
114
|
+
generic,
|
|
115
|
+
moonbeam,
|
|
116
|
+
relay
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function getMultilocationDerivedAddresses({
|
|
120
|
+
paraId,
|
|
121
|
+
address,
|
|
122
|
+
isParents = false
|
|
123
|
+
}) {
|
|
124
|
+
const parents = isParents ? 1 : 0;
|
|
125
|
+
const isEthAddress = address.length === 42 && address.startsWith("0x");
|
|
126
|
+
const accType = isEthAddress ? "AccountKey20" : "AccountId32";
|
|
127
|
+
const decodedAddress = isEthAddress ? hexToU8a(address) : decodeAddress(address);
|
|
128
|
+
const family = parents === 0 && paraId ? "ChildChain" : parents === 1 && !paraId ? "ParentChain" : "SiblingChain";
|
|
129
|
+
const blake = blake2AsU8a(
|
|
130
|
+
new Uint8Array([
|
|
131
|
+
...stringToU8a(family),
|
|
132
|
+
...paraId ? compactToU8a(paraId) : [],
|
|
133
|
+
...compactToU8a(accType.length + (isEthAddress ? 20 : 32)),
|
|
134
|
+
...stringToU8a(accType),
|
|
135
|
+
...decodedAddress
|
|
136
|
+
])
|
|
137
|
+
);
|
|
138
|
+
const address20 = u8aToHex(blake.slice(0, 20));
|
|
139
|
+
const address32 = u8aToHex(blake.slice(0, 32));
|
|
140
|
+
return {
|
|
141
|
+
address20,
|
|
142
|
+
address32
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
MRLTypes,
|
|
147
|
+
convertAddressTo32Bytes,
|
|
148
|
+
convertDecimals,
|
|
149
|
+
formatAssetIdToERC20,
|
|
150
|
+
getMultilocationDerivedAddresses,
|
|
151
|
+
getPolkadotApi,
|
|
152
|
+
getPolkadotAppsUrl,
|
|
153
|
+
getSovereignAccountAddresses,
|
|
154
|
+
hasDecimalOverflow,
|
|
155
|
+
isHexString,
|
|
156
|
+
toBigInt,
|
|
157
|
+
toDecimal
|
|
158
|
+
};
|
|
2
159
|
//# sourceMappingURL=index.mjs.map
|
package/build/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/format/address.ts","../src/format/asset.ts","../src/numbers/decimals.ts","../src/polkadot/polkadot.api.ts","../src/polkadot/polkadot.address.ts"],"sourcesContent":["export function isHexString(asset: unknown): boolean {\n return typeof asset === 'string' && asset.startsWith('0x');\n}\n","export function formatAssetIdToERC20(id: string) {\n if (id.startsWith('0x')) {\n return id;\n }\n\n if (!/^\\d{38,39}$/.test(id)) {\n throw new Error(`Asset id: ${id} must be a string and have 38-39 digits`);\n }\n\n return `0xffffffff${BigInt(id).toString(16).padStart(32, '0')}`;\n}\n","import Big, { RoundingMode } from 'big.js';\n\nBig.NE = -18;\n\nexport function toDecimal(\n number: bigint | number | string,\n decimals: number,\n maxDecimal = 6,\n roundType?: RoundingMode,\n): string {\n const dividend = Big(number.toString().replace(/[^0-9]/g, ''));\n const divisor = Big(10).pow(decimals);\n const result = dividend.div(divisor).round(maxDecimal, roundType);\n\n return result.toString();\n}\n\nexport function toBigInt(\n amount: bigint | string | number,\n decimals: number,\n): bigint {\n if (typeof amount === 'bigint') {\n return amount;\n }\n\n const multiplier = Big(10).pow(decimals);\n const result = Big(amount).mul(multiplier);\n\n return BigInt(result.toFixed(0, Big.roundDown));\n}\n\nexport function convertDecimals(\n number: string | bigint,\n decimals: number,\n targetDecimals: number,\n): bigint {\n const decimalNumber = toDecimal(number, decimals, decimals);\n\n return toBigInt(decimalNumber.toString(), targetDecimals);\n}\n\nexport function hasDecimalOverflow(fl: number | string, maxDecimal: number) {\n const parts = fl.toString().split('.');\n return parts.length > 1 && parts[1].length > maxDecimal;\n}\n","import { ApiPromise, WsProvider } from '@polkadot/api';\nimport { typesBundle } from '@polkadot/apps-config';\nimport { LRUCache } from 'lru-cache';\n\nexport enum MRLTypes {\n // TODO handle both types according to RT version\n XcmVersionedMultiLocation = 'XcmVersionedMultiLocation',\n XcmVersionedLocation = 'XcmVersionedLocation',\n XcmRoutingUserAction = 'XcmRoutingUserAction',\n VersionedUserAction = 'VersionedUserAction',\n}\n\nconst cache = new LRUCache<string, Promise<ApiPromise>>({\n max: 20,\n
|
|
1
|
+
{"version":3,"sources":["../src/format/address.ts","../src/format/asset.ts","../src/numbers/decimals.ts","../src/polkadot/polkadot.api.ts","../src/polkadot/polkadot.apps.ts","../src/polkadot/polkadot.address.ts"],"sourcesContent":["export function isHexString(asset: unknown): boolean {\n return typeof asset === 'string' && asset.startsWith('0x');\n}\n","export function formatAssetIdToERC20(id: string) {\n if (id.startsWith('0x')) {\n return id;\n }\n\n if (!/^\\d{38,39}$/.test(id)) {\n throw new Error(`Asset id: ${id} must be a string and have 38-39 digits`);\n }\n\n return `0xffffffff${BigInt(id).toString(16).padStart(32, '0')}`;\n}\n\nexport function convertAddressTo32Bytes(address: string): string {\n if (!/^0x[a-fA-F0-9]{40}$/.test(address)) {\n throw new Error(`Invalid address: ${address}`);\n }\n\n return `0x000000000000000000000000${address.substring(2)}`;\n}\n","import Big, { type RoundingMode } from 'big.js';\n\nBig.NE = -18;\n\nexport function toDecimal(\n number: bigint | number | string,\n decimals: number,\n maxDecimal = 6,\n roundType?: RoundingMode,\n): string {\n const dividend = Big(number.toString().replace(/[^0-9]/g, ''));\n const divisor = Big(10).pow(decimals);\n const result = dividend.div(divisor).round(maxDecimal, roundType);\n\n return result.toString();\n}\n\nexport function toBigInt(\n amount: bigint | string | number,\n decimals: number,\n): bigint {\n if (typeof amount === 'bigint') {\n return amount;\n }\n\n const multiplier = Big(10).pow(decimals);\n const result = Big(amount).mul(multiplier);\n\n return BigInt(result.toFixed(0, Big.roundDown));\n}\n\nexport function convertDecimals(\n number: string | bigint,\n decimals: number,\n targetDecimals: number,\n): bigint {\n const decimalNumber = toDecimal(number, decimals, decimals);\n\n return toBigInt(decimalNumber.toString(), targetDecimals);\n}\n\nexport function hasDecimalOverflow(fl: number | string, maxDecimal: number) {\n const parts = fl.toString().split('.');\n return parts.length > 1 && parts[1].length > maxDecimal;\n}\n","import { ApiPromise, WsProvider } from '@polkadot/api';\nimport { typesBundle } from '@polkadot/apps-config';\nimport { LRUCache } from 'lru-cache';\n\nexport enum MRLTypes {\n // TODO handle both types according to RT version\n XcmVersionedMultiLocation = 'XcmVersionedMultiLocation',\n XcmVersionedLocation = 'XcmVersionedLocation',\n XcmRoutingUserAction = 'XcmRoutingUserAction',\n VersionedUserAction = 'VersionedUserAction',\n}\n\nconst cache = new LRUCache<string, Promise<ApiPromise>>({\n max: 20,\n dispose: async (promise: Promise<ApiPromise>) => {\n const api = await promise;\n\n if (api.isConnected) {\n api.disconnect();\n }\n },\n});\n\nexport async function getPolkadotApi(\n ws: string | string[],\n): Promise<ApiPromise> {\n const key = Array.isArray(ws) ? ws.join(';') : ws;\n const promise =\n cache.get(key) ||\n ApiPromise.create({\n noInitWarn: true,\n provider: new WsProvider(ws),\n types: {\n [MRLTypes.XcmRoutingUserAction]: {\n destination: MRLTypes.XcmVersionedLocation,\n },\n [MRLTypes.VersionedUserAction]: {\n _enum: { V1: MRLTypes.XcmRoutingUserAction },\n },\n },\n typesBundle,\n });\n\n cache.set(key, promise);\n\n const api = await promise;\n\n await api.isReady;\n\n return api;\n}\n","export function getPolkadotAppsUrl(ws: string) {\n return `https://polkadot.js.org/apps/?rpc=${encodeURIComponent(ws)}#/explorer/query`;\n}\n","import {\n bnToU8a,\n compactToU8a,\n hexToU8a,\n stringToU8a,\n u8aToHex,\n} from '@polkadot/util';\nimport { blake2AsU8a, decodeAddress } from '@polkadot/util-crypto';\n\n/**\n * reference: https://github.com/Moonsong-Labs/xcm-tools/blob/main/scripts/calculate-sovereign-account.ts\n */\n\nexport function getSovereignAccountAddresses(paraId: number) {\n const paraIdU8a = bnToU8a(paraId, { bitLength: 32 });\n const relay = u8aToHex(\n new Uint8Array([...stringToU8a('para'), ...paraIdU8a]),\n ).padEnd(66, '0');\n const generic = u8aToHex(\n new Uint8Array([...stringToU8a('sibl'), ...paraIdU8a]),\n ).padEnd(66, '0');\n const moonbeam = generic.slice(0, 42);\n\n return {\n generic,\n moonbeam,\n relay,\n };\n}\n\n/**\n * reference: https://github.com/Moonsong-Labs/xcm-tools/blob/main/scripts/calculate-multilocation-derivative-account.ts\n */\n\nexport function getMultilocationDerivedAddresses({\n paraId,\n address,\n isParents = false,\n}: {\n paraId?: number;\n address: string;\n isParents?: boolean;\n}) {\n const parents = isParents ? 1 : 0;\n const isEthAddress = address.length === 42 && address.startsWith('0x');\n const accType = isEthAddress ? 'AccountKey20' : 'AccountId32';\n const decodedAddress = isEthAddress\n ? hexToU8a(address)\n : decodeAddress(address);\n\n // Describe Family\n // https://github.com/paritytech/polkadot/blob/master/xcm/xcm-builder/src/location_conversion.rs#L96-L118\n const family =\n parents === 0 && paraId\n ? 'ChildChain'\n : parents === 1 && !paraId\n ? 'ParentChain'\n : 'SiblingChain';\n\n const blake = blake2AsU8a(\n new Uint8Array([\n ...stringToU8a(family),\n ...(paraId ? compactToU8a(paraId) : []),\n ...compactToU8a(accType.length + (isEthAddress ? 20 : 32)),\n ...stringToU8a(accType),\n ...decodedAddress,\n ]),\n );\n\n const address20 = u8aToHex(blake.slice(0, 20));\n const address32 = u8aToHex(blake.slice(0, 32));\n\n return {\n address20,\n address32,\n };\n}\n"],"mappings":";AAAO,SAAS,YAAY,OAAyB;AACnD,SAAO,OAAO,UAAU,YAAY,MAAM,WAAW,IAAI;AAC3D;;;ACFO,SAAS,qBAAqB,IAAY;AAC/C,MAAI,GAAG,WAAW,IAAI,GAAG;AACvB,WAAO;AAAA,EACT;AAEA,MAAI,CAAC,cAAc,KAAK,EAAE,GAAG;AAC3B,UAAM,IAAI,MAAM,aAAa,EAAE,yCAAyC;AAAA,EAC1E;AAEA,SAAO,aAAa,OAAO,EAAE,EAAE,SAAS,EAAE,EAAE,SAAS,IAAI,GAAG,CAAC;AAC/D;AAEO,SAAS,wBAAwB,SAAyB;AAC/D,MAAI,CAAC,sBAAsB,KAAK,OAAO,GAAG;AACxC,UAAM,IAAI,MAAM,oBAAoB,OAAO,EAAE;AAAA,EAC/C;AAEA,SAAO,6BAA6B,QAAQ,UAAU,CAAC,CAAC;AAC1D;;;AClBA,OAAO,SAAgC;AAEvC,IAAI,KAAK;AAEF,SAAS,UACd,QACA,UACA,aAAa,GACb,WACQ;AACR,QAAM,WAAW,IAAI,OAAO,SAAS,EAAE,QAAQ,WAAW,EAAE,CAAC;AAC7D,QAAM,UAAU,IAAI,EAAE,EAAE,IAAI,QAAQ;AACpC,QAAM,SAAS,SAAS,IAAI,OAAO,EAAE,MAAM,YAAY,SAAS;AAEhE,SAAO,OAAO,SAAS;AACzB;AAEO,SAAS,SACd,QACA,UACQ;AACR,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,IAAI,EAAE,EAAE,IAAI,QAAQ;AACvC,QAAM,SAAS,IAAI,MAAM,EAAE,IAAI,UAAU;AAEzC,SAAO,OAAO,OAAO,QAAQ,GAAG,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C7C,QAAM,YAAY,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["MRLTypes"]}
|
package/package.json
CHANGED
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbeam-network/xcm-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Moonbeam XCM utilities",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"build": "tsup",
|
|
7
|
-
"dev": "npm run build -- --watch",
|
|
8
|
-
"link": "npm ln",
|
|
9
|
-
"lint": "eslint . --ext .js,.ts",
|
|
10
|
-
"lint:fix": "npm run lint -- --fix",
|
|
11
|
-
"typecheck": "tsc --noEmit",
|
|
12
|
-
"test": "vitest --run",
|
|
13
|
-
"test:watch": "vitest",
|
|
14
|
-
"test:update": "vitest -u",
|
|
15
|
-
"prepack": "prettier --write build/index.d.ts"
|
|
16
|
-
},
|
|
17
5
|
"author": "moonbeam-foundation",
|
|
18
6
|
"license": "MIT",
|
|
19
7
|
"repository": {
|
|
@@ -36,19 +24,12 @@
|
|
|
36
24
|
],
|
|
37
25
|
"type": "module",
|
|
38
26
|
"exports": {
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"default": "./build/index.mjs"
|
|
43
|
-
},
|
|
44
|
-
"require": {
|
|
45
|
-
"types": "./build/index.d.ts",
|
|
46
|
-
"default": "./build/index.cjs"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
27
|
+
"import": "./build/index.mjs",
|
|
28
|
+
"types": "./build/index.d.ts",
|
|
29
|
+
"default": "./build/index.mjs"
|
|
49
30
|
},
|
|
50
31
|
"types": "./build/index.d.ts",
|
|
51
|
-
"main": "./build/index.
|
|
32
|
+
"main": "./build/index.mjs",
|
|
52
33
|
"dependencies": {
|
|
53
34
|
"big.js": "^6.2.1",
|
|
54
35
|
"lru-cache": "^10.2.2"
|
|
@@ -57,8 +38,18 @@
|
|
|
57
38
|
"@types/big.js": "^6.2.2"
|
|
58
39
|
},
|
|
59
40
|
"peerDependencies": {
|
|
60
|
-
"@polkadot/api": "
|
|
61
|
-
"@polkadot/apps-config": "
|
|
62
|
-
"@polkadot/util": "
|
|
41
|
+
"@polkadot/api": "14.3.1",
|
|
42
|
+
"@polkadot/apps-config": "0.146.1",
|
|
43
|
+
"@polkadot/util": "13.2.3",
|
|
44
|
+
"@polkadot/util-crypto": "13.2.3"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsup",
|
|
48
|
+
"dev": "tsup --watch",
|
|
49
|
+
"link": "pnpm ln --global",
|
|
50
|
+
"typecheck": "tsc --noEmit",
|
|
51
|
+
"test": "vitest --run",
|
|
52
|
+
"test:watch": "vitest",
|
|
53
|
+
"test:update": "vitest -u"
|
|
63
54
|
}
|
|
64
|
-
}
|
|
55
|
+
}
|
package/build/index.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var l=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var h=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},a=(t,n,r,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of y(n))!w.call(t,e)&&e!==r&&c(t,e,{get:()=>n[e],enumerable:!(o=A(n,e))||o.enumerable});return t};var v=(t,n,r)=>(r=t!=null?l(U(t)):{},a(n||!t||!t.__esModule?c(r,"default",{value:t,enumerable:!0}):r,t)),P=t=>a(c({},"__esModule",{value:!0}),t);var B={};h(B,{MRLTypes:()=>x,convertDecimals:()=>X,formatAssetIdToERC20:()=>V,getPolkadotApi:()=>L,getSovereignAccountAddresses:()=>I,hasDecimalOverflow:()=>S,isHexString:()=>R,toBigInt:()=>p,toDecimal:()=>u});module.exports=P(B);function R(t){return typeof t=="string"&&t.startsWith("0x")}function V(t){if(t.startsWith("0x"))return t;if(!/^\d{38,39}$/.test(t))throw new Error(`Asset id: ${t} must be a string and have 38-39 digits`);return`0xffffffff${BigInt(t).toString(16).padStart(32,"0")}`}var s=v(require("big.js"),1);s.default.NE=-18;function u(t,n,r=6,o){let e=(0,s.default)(t.toString().replace(/[^0-9]/g,"")),b=(0,s.default)(10).pow(n);return e.div(b).round(r,o).toString()}function p(t,n){if(typeof t=="bigint")return t;let r=(0,s.default)(10).pow(n),o=(0,s.default)(t).mul(r);return BigInt(o.toFixed(0,s.default.roundDown))}function X(t,n,r){let o=u(t,n,n);return p(o.toString(),r)}function S(t,n){let r=t.toString().split(".");return r.length>1&&r[1].length>n}var m=require("@polkadot/api"),d=require("@polkadot/apps-config"),f=require("lru-cache"),x=(e=>(e.XcmVersionedMultiLocation="XcmVersionedMultiLocation",e.XcmVersionedLocation="XcmVersionedLocation",e.XcmRoutingUserAction="XcmRoutingUserAction",e.VersionedUserAction="VersionedUserAction",e))(x||{}),g=new f.LRUCache({max:20,dispose:async t=>{let n=await t;n.isConnected&&n.disconnect()}});async function L(t){let n=Array.isArray(t)?t.join(";"):t,r=g.get(n)||m.ApiPromise.create({noInitWarn:!0,provider:new m.WsProvider(t),types:{XcmRoutingUserAction:{destination:"XcmVersionedLocation"},VersionedUserAction:{_enum:{V1:"XcmRoutingUserAction"}}},typesBundle:d.typesBundle});g.set(n,r);let o=await r;return await o.isReady,o}var i=require("@polkadot/util");function I(t){let n=(0,i.bnToU8a)(t,{bitLength:32}),r=(0,i.u8aToHex)(new Uint8Array([...(0,i.stringToU8a)("para"),...n])).padEnd(66,"0"),o=(0,i.u8aToHex)(new Uint8Array([...(0,i.stringToU8a)("sibl"),...n])).padEnd(66,"0"),e=o.slice(0,42);return{generic:o,moonbeam:e,relay:r}}0&&(module.exports={MRLTypes,convertDecimals,formatAssetIdToERC20,getPolkadotApi,getSovereignAccountAddresses,hasDecimalOverflow,isHexString,toBigInt,toDecimal});
|
|
2
|
-
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/format/address.ts","../src/format/asset.ts","../src/numbers/decimals.ts","../src/polkadot/polkadot.api.ts","../src/polkadot/polkadot.address.ts"],"sourcesContent":["export * from './format';\nexport * from './numbers';\nexport * from './polkadot';\n","export function isHexString(asset: unknown): boolean {\n return typeof asset === 'string' && asset.startsWith('0x');\n}\n","export function formatAssetIdToERC20(id: string) {\n if (id.startsWith('0x')) {\n return id;\n }\n\n if (!/^\\d{38,39}$/.test(id)) {\n throw new Error(`Asset id: ${id} must be a string and have 38-39 digits`);\n }\n\n return `0xffffffff${BigInt(id).toString(16).padStart(32, '0')}`;\n}\n","import Big, { RoundingMode } from 'big.js';\n\nBig.NE = -18;\n\nexport function toDecimal(\n number: bigint | number | string,\n decimals: number,\n maxDecimal = 6,\n roundType?: RoundingMode,\n): string {\n const dividend = Big(number.toString().replace(/[^0-9]/g, ''));\n const divisor = Big(10).pow(decimals);\n const result = dividend.div(divisor).round(maxDecimal, roundType);\n\n return result.toString();\n}\n\nexport function toBigInt(\n amount: bigint | string | number,\n decimals: number,\n): bigint {\n if (typeof amount === 'bigint') {\n return amount;\n }\n\n const multiplier = Big(10).pow(decimals);\n const result = Big(amount).mul(multiplier);\n\n return BigInt(result.toFixed(0, Big.roundDown));\n}\n\nexport function convertDecimals(\n number: string | bigint,\n decimals: number,\n targetDecimals: number,\n): bigint {\n const decimalNumber = toDecimal(number, decimals, decimals);\n\n return toBigInt(decimalNumber.toString(), targetDecimals);\n}\n\nexport function hasDecimalOverflow(fl: number | string, maxDecimal: number) {\n const parts = fl.toString().split('.');\n return parts.length > 1 && parts[1].length > maxDecimal;\n}\n","import { ApiPromise, WsProvider } from '@polkadot/api';\nimport { typesBundle } from '@polkadot/apps-config';\nimport { LRUCache } from 'lru-cache';\n\nexport enum MRLTypes {\n // TODO handle both types according to RT version\n XcmVersionedMultiLocation = 'XcmVersionedMultiLocation',\n XcmVersionedLocation = 'XcmVersionedLocation',\n XcmRoutingUserAction = 'XcmRoutingUserAction',\n VersionedUserAction = 'VersionedUserAction',\n}\n\nconst cache = new LRUCache<string, Promise<ApiPromise>>({\n max: 20,\n // eslint-disable-next-line sort-keys\n dispose: async (promise: Promise<ApiPromise>) => {\n const api = await promise;\n\n if (api.isConnected) {\n api.disconnect();\n }\n },\n});\n\nexport async function getPolkadotApi(\n ws: string | string[],\n): Promise<ApiPromise> {\n const key = Array.isArray(ws) ? ws.join(';') : ws;\n const promise =\n cache.get(key) ||\n ApiPromise.create({\n noInitWarn: true,\n provider: new WsProvider(ws),\n types: {\n [MRLTypes.XcmRoutingUserAction]: {\n destination: MRLTypes.XcmVersionedLocation,\n },\n [MRLTypes.VersionedUserAction]: {\n _enum: { V1: MRLTypes.XcmRoutingUserAction },\n },\n },\n typesBundle,\n });\n\n cache.set(key, promise);\n\n const api = await promise;\n\n await api.isReady;\n\n return api;\n}\n","import { bnToU8a, u8aToHex, stringToU8a } from '@polkadot/util';\n\nexport function getSovereignAccountAddresses(paraId: number) {\n const paraIdU8a = bnToU8a(paraId, { bitLength: 32 });\n const relay = u8aToHex(\n new Uint8Array([...stringToU8a('para'), ...paraIdU8a]),\n ).padEnd(66, '0');\n const generic = u8aToHex(\n new Uint8Array([...stringToU8a('sibl'), ...paraIdU8a]),\n ).padEnd(66, '0');\n const moonbeam = generic.slice(0, 42);\n\n return {\n generic,\n moonbeam,\n relay,\n };\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,oBAAAC,EAAA,yBAAAC,EAAA,mBAAAC,EAAA,iCAAAC,EAAA,uBAAAC,EAAA,gBAAAC,EAAA,aAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAX,GCAO,SAASY,EAAYC,EAAyB,CACnD,OAAO,OAAOA,GAAU,UAAYA,EAAM,WAAW,IAAI,CAC3D,CCFO,SAASC,E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ZA,OAAA,IAQNC,EAAQ,IAAI,WAAsC,CACtD,IAAK,GAEL,QAAS,MAAOC,GAAiC,CAC/C,IAAMC,EAAM,MAAMD,EAEdC,EAAI,aACNA,EAAI,WAAW,CAEnB,CACF,CAAC,EAED,eAAsBC,EACpBC,EACqB,CACrB,IAAMC,EAAM,MAAM,QAAQD,CAAE,EAAIA,EAAG,KAAK,GAAG,EAAIA,EACzCH,EACJD,EAAM,IAAIK,CAAG,GACb,aAAW,OAAO,CAChB,WAAY,GACZ,SAAU,IAAI,aAAWD,CAAE,EAC3B,MAAO,CACJ,qBAAgC,CAC/B,YAAa,sBACf,EACC,oBAA+B,CAC9B,MAAO,CAAE,GAAI,sBAA8B,CAC7C,CACF,EACA,yBACF,CAAC,EAEHJ,EAAM,IAAIK,EAAKJ,CAAO,EAEtB,IAAMC,EAAM,MAAMD,EAElB,aAAMC,EAAI,QAEHA,CACT,CCnDA,IAAAI,EAA+C,0BAExC,SAASC,EAA6BC,EAAgB,CAC3D,IAAMC,KAAY,WAAQD,EAAQ,CAAE,UAAW,EAAG,CAAC,EAC7CE,KAAQ,YACZ,IAAI,WAAW,CAAC,MAAG,eAAY,MAAM,EAAG,GAAGD,CAAS,CAAC,CACvD,EAAE,OAAO,GAAI,GAAG,EACVE,KAAU,YACd,IAAI,WAAW,CAAC,MAAG,eAAY,MAAM,EAAG,GAAGF,CAAS,CAAC,CACvD,EAAE,OAAO,GAAI,GAAG,EACVG,EAAWD,EAAQ,MAAM,EAAG,EAAE,EAEpC,MAAO,CACL,QAAAA,EACA,SAAAC,EACA,MAAAF,CACF,CACF","names":["src_exports","__export","MRLTypes","convertDecimals","formatAssetIdToERC20","getPolkadotApi","getSovereignAccountAddresses","hasDecimalOverflow","isHexString","toBigInt","toDecimal","__toCommonJS","isHexString","asset","formatAssetIdToERC20","id","import_big","Big","toDecimal","number","decimals","maxDecimal","roundType","dividend","divisor","toBigInt","amount","multiplier","result","convertDecimals","targetDecimals","decimalNumber","hasDecimalOverflow","fl","parts","import_api","import_apps_config","import_lru_cache","MRLTypes","cache","promise","api","getPolkadotApi","ws","key","import_util","getSovereignAccountAddresses","paraId","paraIdU8a","relay","generic","moonbeam"]}
|
package/build/index.d.cts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { RoundingMode } from 'big.js';
|
|
2
|
-
import { ApiPromise } from '@polkadot/api';
|
|
3
|
-
|
|
4
|
-
declare function isHexString(asset: unknown): boolean;
|
|
5
|
-
|
|
6
|
-
declare function formatAssetIdToERC20(id: string): string;
|
|
7
|
-
|
|
8
|
-
declare function toDecimal(number: bigint | number | string, decimals: number, maxDecimal?: number, roundType?: RoundingMode): string;
|
|
9
|
-
declare function toBigInt(amount: bigint | string | number, decimals: number): bigint;
|
|
10
|
-
declare function convertDecimals(number: string | bigint, decimals: number, targetDecimals: number): bigint;
|
|
11
|
-
declare function hasDecimalOverflow(fl: number | string, maxDecimal: number): boolean;
|
|
12
|
-
|
|
13
|
-
declare enum MRLTypes {
|
|
14
|
-
XcmVersionedMultiLocation = "XcmVersionedMultiLocation",
|
|
15
|
-
XcmVersionedLocation = "XcmVersionedLocation",
|
|
16
|
-
XcmRoutingUserAction = "XcmRoutingUserAction",
|
|
17
|
-
VersionedUserAction = "VersionedUserAction"
|
|
18
|
-
}
|
|
19
|
-
declare function getPolkadotApi(ws: string | string[]): Promise<ApiPromise>;
|
|
20
|
-
|
|
21
|
-
declare function getSovereignAccountAddresses(paraId: number): {
|
|
22
|
-
generic: string;
|
|
23
|
-
moonbeam: string;
|
|
24
|
-
relay: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { MRLTypes, convertDecimals, formatAssetIdToERC20, getPolkadotApi, getSovereignAccountAddresses, hasDecimalOverflow, isHexString, toBigInt, toDecimal };
|