@moonbeam-network/xcm-utils 0.0.7 → 1.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/README.md +8 -2
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +10 -58
- package/build/index.mjs +1 -1
- package/build/index.mjs.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Moonbeam XCM SDK enables developers to easily deposit and withdraw assets to Moonbeam/Moonriver from the relay chain and other parachains in the Polkadot/Kusama ecosystem. With the SDK, you don't need to worry about determining the multilocation of the origin or destination assets or which extrinsics are used on which networks to send XCM transfers. To deposit or withdraw assets, you simply define the asset and origin chain you want to deposit from or withdraw back to, along with the sending account's signer, and the amount to send.
|
|
4
|
+
|
|
5
|
+
# Documentation
|
|
6
|
+
|
|
7
|
+
## v1 (current)
|
|
8
|
+
|
|
9
|
+
- TODO: (coming soon)
|
package/build/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var l=Object.create;var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var P=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var h=(t,r)=>{for(var i in r)s(t,i,{get:r[i],enumerable:!0})},p=(t,r,i,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of w(r))!v.call(t,o)&&o!==i&&s(t,o,{get:()=>r[o],enumerable:!(n=x(r,o))||n.enumerable});return t};var g=(t,r,i)=>(i=t!=null?l(P(t)):{},p(r||!t||!t.__esModule?s(i,"default",{value:t,enumerable:!0}):i,t)),A=t=>p(s({},"__esModule",{value:!0}),t);var D={};h(D,{convertDecimals:()=>y,formatAssetIdToERC20:()=>S,getPolkadotApi:()=>R,hasDecimalOverflow:()=>B,toBigInt:()=>f,toDecimal:()=>u});module.exports=A(D);function S(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 e=g(require("big.js"),1);e.default.NE=-18;function u(t,r,i=6,n){let o=(0,e.default)(t.toString().replace(/[^0-9]/g,"")),b=(0,e.default)(10).pow(r);return o.div(b).round(i,n).toString()}function f(t,r){if(typeof t=="bigint")return t;let i=(0,e.default)(10).pow(r),n=(0,e.default)(t).mul(i);return BigInt(n.toFixed(0,e.default.roundDown))}function y(t,r,i){let n=u(t,r,r);return f(n.toString(),i)}function B(t,r){let i=t.toString().split(".");return i.length>1&&i[1].length>r}var m=require("@polkadot/api"),a=require("@polkadot/apps-config"),d=g(require("lru-cache"),1),c=new d.default({max:20,dispose:async t=>{let r=await t;r.isConnected&&r.disconnect()}});async function R(t){let r=c.get(t)||m.ApiPromise.create({provider:new m.WsProvider(t),typesBundle:a.typesBundle});c.set(t,r);let i=await r;return await i.isReady,i}0&&(module.exports={convertDecimals,formatAssetIdToERC20,getPolkadotApi,hasDecimalOverflow,toBigInt,toDecimal});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/build/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/format/asset.ts","../src/numbers/decimals.ts","../src/polkadot/polkadot.api.ts"],"sourcesContent":["export * from './format';\nexport * from './numbers';\nexport * from './polkadot';\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 LRU from 'lru-cache';\n\nconst cache = new LRU<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(ws: string): Promise<ApiPromise> {\n const promise =\n cache.get(ws) ||\n ApiPromise.create({\n provider: new WsProvider(ws),\n typesBundle,\n });\n\n cache.set(ws, promise);\n\n const api = await promise;\n\n await api.isReady;\n\n return api;\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,qBAAAE,EAAA,yBAAAC,EAAA,mBAAAC,EAAA,uBAAAC,EAAA,aAAAC,EAAA,cAAAC,IAAA,eAAAC,EAAAR,GCAO,SAASS,EAAqBC,EAAY,CAC/C,GAAIA,EAAG,WAAW,IAAI,EACpB,OAAOA,EAGT,GAAI,CAAC,cAAc,KAAKA,CAAE,EACxB,MAAM,IAAI,MAA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O,CAChB,SAAU,IAAI,aAAWA,CAAE,EAC3B,yBACF,CAAC,EAEHL,EAAM,IAAIK,EAAIH,CAAO,EAErB,IAAMC,EAAM,MAAMD,EAElB,aAAMC,EAAI,QAEHA,CACT","names":["src_exports","__export","convertDecimals","formatAssetIdToERC20","getPolkadotApi","hasDecimalOverflow","toBigInt","toDecimal","__toCommonJS","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","cache","LRU","promise","api","getPolkadotApi","ws"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,60 +1,18 @@
|
|
|
1
|
+
import { RoundingMode } from 'big.js';
|
|
1
2
|
import { ApiPromise } from '@polkadot/api';
|
|
2
|
-
import { ISubmittableResult } from '@polkadot/types/types';
|
|
3
|
-
import { Signer } from 'ethers';
|
|
4
|
-
import Big, { RoundingMode } from 'big.js';
|
|
5
3
|
|
|
6
|
-
declare function
|
|
7
|
-
ws: string,
|
|
8
|
-
onDisconnect?: VoidFunction,
|
|
9
|
-
): Promise<ApiPromise>;
|
|
10
|
-
|
|
11
|
-
type Hash = string;
|
|
12
|
-
type ExtrinsicEventsCallback = (event: ExtrinsicEvent) => void;
|
|
13
|
-
type ExtrinsicEvent =
|
|
14
|
-
| ExtrinsicFailedEvent
|
|
15
|
-
| ExtrinsicSentEvent
|
|
16
|
-
| ExtrinsicSuccessEvent;
|
|
17
|
-
interface ExtrinsicFailedEvent {
|
|
18
|
-
blockHash: Hash;
|
|
19
|
-
message?: string;
|
|
20
|
-
status: ExtrinsicStatus.Failed;
|
|
21
|
-
txHash: Hash;
|
|
22
|
-
}
|
|
23
|
-
interface ExtrinsicSentEvent {
|
|
24
|
-
status: ExtrinsicStatus.Sent;
|
|
25
|
-
txHash: Hash;
|
|
26
|
-
}
|
|
27
|
-
interface ExtrinsicSuccessEvent {
|
|
28
|
-
blockHash: Hash;
|
|
29
|
-
status: ExtrinsicStatus.Success;
|
|
30
|
-
txHash: Hash;
|
|
31
|
-
}
|
|
32
|
-
declare enum ExtrinsicStatus {
|
|
33
|
-
Failed = 'Failed',
|
|
34
|
-
Sent = 'Sent',
|
|
35
|
-
Success = 'Success',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
declare function createExtrinsicEventHandler(
|
|
39
|
-
pallet: string,
|
|
40
|
-
successEvent: string,
|
|
41
|
-
cb: ExtrinsicEventsCallback,
|
|
42
|
-
): ({ events, status, txHash }: ISubmittableResult) => void;
|
|
43
|
-
|
|
44
|
-
declare function createTxEventHandler(
|
|
45
|
-
ethersSigner: Signer,
|
|
46
|
-
txHash: Hash,
|
|
47
|
-
cb: ExtrinsicEventsCallback,
|
|
48
|
-
skipSentEvent?: boolean,
|
|
49
|
-
): Promise<void>;
|
|
4
|
+
declare function formatAssetIdToERC20(id: string): string;
|
|
50
5
|
|
|
51
6
|
declare function toDecimal(
|
|
52
7
|
number: bigint | number | string,
|
|
53
8
|
decimals: number,
|
|
54
9
|
maxDecimal?: number,
|
|
55
10
|
roundType?: RoundingMode,
|
|
56
|
-
):
|
|
57
|
-
declare function toBigInt(
|
|
11
|
+
): string;
|
|
12
|
+
declare function toBigInt(
|
|
13
|
+
amount: bigint | string | number,
|
|
14
|
+
decimals: number,
|
|
15
|
+
): bigint;
|
|
58
16
|
declare function convertDecimals(
|
|
59
17
|
number: string | bigint,
|
|
60
18
|
decimals: number,
|
|
@@ -65,17 +23,11 @@ declare function hasDecimalOverflow(
|
|
|
65
23
|
maxDecimal: number,
|
|
66
24
|
): boolean;
|
|
67
25
|
|
|
26
|
+
declare function getPolkadotApi(ws: string): Promise<ApiPromise>;
|
|
27
|
+
|
|
68
28
|
export {
|
|
69
|
-
ExtrinsicEvent,
|
|
70
|
-
ExtrinsicEventsCallback,
|
|
71
|
-
ExtrinsicFailedEvent,
|
|
72
|
-
ExtrinsicSentEvent,
|
|
73
|
-
ExtrinsicStatus,
|
|
74
|
-
ExtrinsicSuccessEvent,
|
|
75
|
-
Hash,
|
|
76
29
|
convertDecimals,
|
|
77
|
-
|
|
78
|
-
createTxEventHandler,
|
|
30
|
+
formatAssetIdToERC20,
|
|
79
31
|
getPolkadotApi,
|
|
80
32
|
hasDecimalOverflow,
|
|
81
33
|
toBigInt,
|
package/build/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
function b(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 n from"big.js";n.NE=-18;function p(t,r,i=6,o){let s=n(t.toString().replace(/[^0-9]/g,"")),m=n(10).pow(r);return s.div(m).round(i,o).toString()}function g(t,r){if(typeof t=="bigint")return t;let i=n(10).pow(r),o=n(t).mul(i);return BigInt(o.toFixed(0,n.roundDown))}function h(t,r,i){let o=p(t,r,r);return g(o.toString(),i)}function A(t,r){let i=t.toString().split(".");return i.length>1&&i[1].length>r}import{ApiPromise as u,WsProvider as f}from"@polkadot/api";import{typesBundle as c}from"@polkadot/apps-config";import a from"lru-cache";var e=new a({max:20,dispose:async t=>{let r=await t;r.isConnected&&r.disconnect()}});async function E(t){let r=e.get(t)||u.create({provider:new f(t),typesBundle:c});e.set(t,r);let i=await r;return await i.isReady,i}export{h as convertDecimals,b as formatAssetIdToERC20,E as getPolkadotApi,A as hasDecimalOverflow,g as toBigInt,p as toDecimal};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/build/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/format/asset.ts","../src/numbers/decimals.ts","../src/polkadot/polkadot.api.ts"],"sourcesContent":["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 LRU from 'lru-cache';\n\nconst cache = new LRU<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(ws: string): Promise<ApiPromise> {\n const promise =\n cache.get(ws) ||\n ApiPromise.create({\n provider: new WsProvider(ws),\n typesBundle,\n });\n\n cache.set(ws, promise);\n\n const api = await promise;\n\n await api.isReady;\n\n return api;\n}\n"],"mappings":"AAAO,SAASA,EAAqBC,EAAY,CAC/C,GAAIA,EAAG,WAAW,IAAI,EACpB,OAAOA,EAGT,GAAI,CAAC,cAAc,KAAKA,CAAE,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,GACZR,EAAW,OAAO,CAChB,SAAU,IAAIC,EAAWO,CAAE,EAC3B,YAAAN,CACF,CAAC,EAEHE,EAAM,IAAII,EAAIH,CAAO,EAErB,IAAMC,EAAM,MAAMD,EAElB,aAAMC,EAAI,QAEHA,CACT","names":["formatAssetIdToERC20","id","Big","toDecimal","number","decimals","maxDecimal","roundType","dividend","divisor","toBigInt","amount","multiplier","result","convertDecimals","targetDecimals","decimalNumber","hasDecimalOverflow","fl","parts","ApiPromise","WsProvider","typesBundle","LRU","cache","promise","api","getPolkadotApi","ws"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbeam-network/xcm-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Moonbeam XCM utilities",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "tsup",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@types/big.js": "^6.1.6"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"@polkadot/
|
|
60
|
+
"@polkadot/apps-config": "^0.132.1",
|
|
61
|
+
"@polkadot/api": "^10.8.1"
|
|
61
62
|
}
|
|
62
63
|
}
|