@moonbeam-network/xcm-utils 2.2.5 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2022 PureStake
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
 
@@ -4,6 +4,7 @@ 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
9
  declare function toDecimal(number: bigint | number | string, decimals: number, maxDecimal?: number, roundType?: RoundingMode): string;
9
10
  declare function toBigInt(amount: bigint | string | number, decimals: number): bigint;
@@ -18,10 +19,26 @@ declare enum MRLTypes {
18
19
  }
19
20
  declare function getPolkadotApi(ws: string | string[]): Promise<ApiPromise>;
20
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
+ */
21
27
  declare function getSovereignAccountAddresses(paraId: number): {
22
28
  generic: string;
23
29
  moonbeam: string;
24
30
  relay: string;
25
31
  };
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}`;
42
+ };
26
43
 
27
- export { MRLTypes, convertDecimals, formatAssetIdToERC20, getPolkadotApi, getSovereignAccountAddresses, hasDecimalOverflow, isHexString, toBigInt, toDecimal };
44
+ export { MRLTypes, convertAddressTo32Bytes, convertDecimals, formatAssetIdToERC20, getMultilocationDerivedAddresses, getPolkadotApi, getPolkadotAppsUrl, getSovereignAccountAddresses, hasDecimalOverflow, isHexString, toBigInt, toDecimal };
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
- number: bigint | number | string,
10
- decimals: number,
11
- maxDecimal?: number,
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
- XcmVersionedMultiLocation = 'XcmVersionedMultiLocation',
30
- XcmVersionedLocation = 'XcmVersionedLocation',
31
- XcmRoutingUserAction = 'XcmRoutingUserAction',
32
- VersionedUserAction = 'VersionedUserAction',
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
- generic: string;
38
- moonbeam: string;
39
- relay: string;
28
+ generic: string;
29
+ moonbeam: string;
30
+ relay: string;
40
31
  };
41
-
42
- export {
43
- MRLTypes,
44
- convertDecimals,
45
- formatAssetIdToERC20,
46
- getPolkadotApi,
47
- getSovereignAccountAddresses,
48
- hasDecimalOverflow,
49
- isHexString,
50
- toBigInt,
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
- function y(t){return typeof t=="string"&&t.startsWith("0x")}function w(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")}`}import i from"big.js";i.NE=-18;function u(t,n,r=6,o){let e=i(t.toString().replace(/[^0-9]/g,"")),a=i(10).pow(n);return e.div(a).round(r,o).toString()}function p(t,n){if(typeof t=="bigint")return t;let r=i(10).pow(n),o=i(t).mul(r);return BigInt(o.toFixed(0,i.roundDown))}function S(t,n,r){let o=u(t,n,n);return p(o.toString(),r)}function L(t,n){let r=t.toString().split(".");return r.length>1&&r[1].length>n}import{ApiPromise as g,WsProvider as d}from"@polkadot/api";import{typesBundle as f}from"@polkadot/apps-config";import{LRUCache as x}from"lru-cache";var b=(e=>(e.XcmVersionedMultiLocation="XcmVersionedMultiLocation",e.XcmVersionedLocation="XcmVersionedLocation",e.XcmRoutingUserAction="XcmRoutingUserAction",e.VersionedUserAction="VersionedUserAction",e))(b||{}),s=new x({max:20,dispose:async t=>{let n=await t;n.isConnected&&n.disconnect()}});async function W(t){let n=Array.isArray(t)?t.join(";"):t,r=s.get(n)||g.create({noInitWarn:!0,provider:new d(t),types:{XcmRoutingUserAction:{destination:"XcmVersionedLocation"},VersionedUserAction:{_enum:{V1:"XcmRoutingUserAction"}}},typesBundle:f});s.set(n,r);let o=await r;return await o.isReady,o}import{bnToU8a as l,u8aToHex as c,stringToU8a as m}from"@polkadot/util";function $(t){let n=l(t,{bitLength:32}),r=c(new Uint8Array([...m("para"),...n])).padEnd(66,"0"),o=c(new Uint8Array([...m("sibl"),...n])).padEnd(66,"0"),e=o.slice(0,42);return{generic:o,moonbeam:e,relay:r}}export{b as MRLTypes,S as convertDecimals,w as formatAssetIdToERC20,W as getPolkadotApi,$ as getSovereignAccountAddresses,L as hasDecimalOverflow,y as isHexString,p as toBigInt,u as toDecimal};
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
@@ -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 // 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, '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atAssetIdToERC20","id","Big","toDecimal","number","decimals","maxDecimal","roundType","dividend","divisor","toBigInt","amount","multiplier","result","convertDecimals","targetDecimals","decimalNumber","hasDecimalOverflow","fl","parts","ApiPromise","WsProvider","typesBundle","LRUCache","MRLTypes","cache","promise","api","getPolkadotApi","ws","key","bnToU8a","u8aToHex","stringToU8a","getSovereignAccountAddresses","paraId","paraIdU8a","relay","generic","moonbeam"]}
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,EAA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AE,OAAO,IAAI,GAAG;AAChB,QAAM,WAAW,QAAQ,MAAM,GAAG,EAAE;AAEpC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAMO,SAAS,iCAAiC;AAAA,EAC/C;AAAA,EACA;AAAA,EACA,YAAY;AACd,GAIG;AACD,QAAM,UAAU,YAAY,IAAI;AAChC,QAAM,eAAe,QAAQ,WAAW,MAAM,QAAQ,WAAW,IAAI;AACrE,QAAM,UAAU,eAAe,iBAAiB;AAChD,QAAM,iBAAiB,eACnB,SAAS,OAAO,IAChB,cAAc,OAAO;AAIzB,QAAM,SACJ,YAAY,KAAK,SACb,eACA,YAAY,KAAK,CAAC,SAChB,gBACA;AAER,QAAM,QAAQ;AAAA,IACZ,IAAI,WAAW;AAAA,MACb,GAAG,YAAY,MAAM;AAAA,MACrB,GAAI,SAAS,aAAa,MAAM,IAAI,CAAC;AAAA,MACrC,GAAG,aAAa,QAAQ,UAAU,eAAe,KAAK,GAAG;AAAA,MACzD,GAAG,YAAY,OAAO;AAAA,MACtB,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AAEA,QAAM,YAAY,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC;AAC7C,QAAM,YAAY,SAAS,MAAM,MAAM,GAAG,EAAE,CAAC;AAE7C,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":["MRLTypes"]}
package/package.json CHANGED
@@ -1,18 +1,15 @@
1
1
  {
2
2
  "name": "@moonbeam-network/xcm-utils",
3
- "version": "2.2.5",
3
+ "version": "3.0.0",
4
4
  "description": "Moonbeam XCM utilities",
5
5
  "scripts": {
6
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",
7
+ "dev": "tsup --watch",
8
+ "link": "pnpm ln --global",
11
9
  "typecheck": "tsc --noEmit",
12
10
  "test": "vitest --run",
13
11
  "test:watch": "vitest",
14
- "test:update": "vitest -u",
15
- "prepack": "prettier --write build/index.d.ts"
12
+ "test:update": "vitest -u"
16
13
  },
17
14
  "author": "moonbeam-foundation",
18
15
  "license": "MIT",
@@ -21,34 +18,20 @@
21
18
  "type": "git",
22
19
  "url": "git+https://github.com/moonbeam-foundation/xcm-sdk.git"
23
20
  },
24
- "keywords": [
25
- "moonbeam",
26
- "moonriver",
27
- "xcm",
28
- "utils"
29
- ],
21
+ "keywords": ["moonbeam", "moonriver", "xcm", "utils"],
30
22
  "bugs": {
31
23
  "url": "https://github.com/moonbeam-foundation/xcm-sdk/issues"
32
24
  },
33
25
  "homepage": "https://moonbeam-foundation.github.io/xcm-sdk/latest",
34
- "files": [
35
- "build"
36
- ],
26
+ "files": ["build"],
37
27
  "type": "module",
38
28
  "exports": {
39
- ".": {
40
- "import": {
41
- "types": "./build/index.d.ts",
42
- "default": "./build/index.mjs"
43
- },
44
- "require": {
45
- "types": "./build/index.d.ts",
46
- "default": "./build/index.cjs"
47
- }
48
- }
29
+ "import": "./build/index.mjs",
30
+ "types": "./build/index.d.ts",
31
+ "default": "./build/index.mjs"
49
32
  },
50
33
  "types": "./build/index.d.ts",
51
- "main": "./build/index.cjs",
34
+ "main": "./build/index.mjs",
52
35
  "dependencies": {
53
36
  "big.js": "^6.2.1",
54
37
  "lru-cache": "^10.2.2"
@@ -57,8 +40,9 @@
57
40
  "@types/big.js": "^6.2.2"
58
41
  },
59
42
  "peerDependencies": {
60
- "@polkadot/api": "^12.4.2",
61
- "@polkadot/apps-config": "^0.143.2",
62
- "@polkadot/util": "^13.1.1"
43
+ "@polkadot/api": "14.3.1",
44
+ "@polkadot/apps-config": "0.146.1",
45
+ "@polkadot/util": "13.2.3",
46
+ "@polkadot/util-crypto": "13.2.3"
63
47
  }
64
48
  }
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
@@ -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,EAAqBC,EAAY,CAC/C,GAAIA,EAAG,WAAW,IAAI,EACpB,OAAOA,EAGT,GAAI,CAAC,cAAc,KAAKA,CAAE,EACxB,MAAM,IAAI,MAAM,aAAaA,CAAE,yCAAyC,EAG1E,MAAO,aAAa,OAAOA,CAAE,EAAE,SAAS,EAAE,EAAE,SAAS,GAAI,GAAG,CAAC,EAC/D,CCVA,IAAAC,EAAkC,uBAElC,EAAAC,QAAI,GAAK,IAEF,SAASC,EACdC,EACAC,EACAC,EAAa,EACbC,EACQ,CACR,IAAMC,KAAW,EAAAN,SAAIE,EAAO,SAAS,EAAE,QAAQ,UAAW,EAAE,CAAC,EACvDK,KAAU,EAAAP,SAAI,EAAE,EAAE,IAAIG,CAAQ,EAGpC,OAFeG,EAAS,IAAIC,CAAO,EAAE,MAAMH,EAAYC,CAAS,EAElD,SAAS,CACzB,CAEO,SAASG,EACdC,EACAN,EACQ,CACR,GAAI,OAAOM,GAAW,SACpB,OAAOA,EAGT,IAAMC,KAAa,EAAAV,SAAI,EAAE,EAAE,IAAIG,CAAQ,EACjCQ,KAAS,EAAAX,SAAIS,CAAM,EAAE,IAAIC,CAAU,EAEzC,OAAO,OAAOC,EAAO,QAAQ,EAAG,EAAAX,QAA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E,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"]}