@galacticcouncil/common 0.3.0 → 0.4.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/build/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var W=Object.create;var g=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var M=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var s=(e,t)=>{for(var r in t)g(e,r,{get:t[r],enumerable:!0})},G=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of j(t))!q.call(e,o)&&o!==r&&g(e,o,{get:()=>t[o],enumerable:!(n=$(t,o))||n.enumerable});return e};var z=(e,t,r)=>(r=e!=null?W(M(e)):{},G(t||!e||!e.__esModule?g(r,"default",{value:e,enumerable:!0}):r,e)),Y=e=>G(g({},"__esModule",{value:!0}),e);var ue={};s(ue,{HYDRATION_SS58_PREFIX:()=>m,RUNTIME_DECIMALS:()=>ce,big:()=>x,encodeAssetId:()=>S,encodeLocation:()=>L,enums:()=>A,erc20:()=>b,h160:()=>w,hex:()=>I,log:()=>R,transform:()=>i,xc:()=>N,xcm:()=>k});module.exports=Y(ue);var ce=18,m=63;var x={};s(x,{asBigInt:()=>V,convertDecimals:()=>J,pow10:()=>Q,toBigInt:()=>C,toDecimal:()=>H});var f=z(require("big.js"));f.default.NE=-18;function H(e,t,r){let n=(0,f.default)(e.toString().replace(/[^0-9]/g,"")),o=(0,f.default)(10).pow(t);return n.div(o).round(t,r).toString()}function C(e,t){if(typeof e=="bigint")return e;let r=(0,f.default)(10).pow(t),n=(0,f.default)(e).mul(r);return BigInt(n.toFixed(0,f.default.roundDown))}function V(e){return BigInt(e.round(0,f.default.roundDown).toFixed(0))}function J(e,t,r){let n=H(e,t);return C(n.toString(),r)}function Q(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var A={};s(A,{enumPath:()=>Z});function Z(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var b={};s(b,{ERC20:()=>B});var B=class{static fromAssetId(t){let r=Buffer.alloc(20,0);return r[15]=1,r.writeUInt32BE(t,16),"0x"+r.toString("hex")}static toAssetId(t){let r=Buffer.from(t.replace("0x",""),"hex");return r.length!==20||!this.isAssetAddress(t)?null:r.readUInt32BE(16)}static isAssetAddress(t){let r=Buffer.from("0000000000000000000000000000000100000000","hex"),n=Buffer.from(t.replace("0x",""),"hex");return n.length!==20?!1:n.subarray(0,16).equals(r.subarray(0,16))}};var w={};s(w,{H160:()=>v,isEvmAccount:()=>O,isEvmAddress:()=>D,isSs58Address:()=>T});var a=require("polkadot-api"),E=require("@polkadot-api/utils"),u=require("buffer");var h="ETH\0";function O(e){if(!e)return!1;try{let t=(0,a.AccountId)().enc(e),r=u.Buffer.from(h);return u.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function D(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function T(e){try{return(0,a.AccountId)(63).enc(e),!0}catch{return!1}}var v=class e{static toAccount=t=>{let r=u.Buffer.from(t.slice(2),"hex"),n=u.Buffer.from(h),o=Uint8Array.from(u.Buffer.concat([n,r,u.Buffer.alloc(8)])),F=(0,E.toHex)(o);return(0,a.AccountId)(63).dec(F)};static fromAccount=t=>{let r=(0,a.AccountId)().enc(t),n=u.Buffer.from(h),o=r.slice(n.length,-8);return"0x"+u.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,a.AccountId)().enc(t).slice(0,20);return(0,E.toHex)(n)};static fromAny=t=>{if(D(t))return t;if(O(t))return e.fromAccount(t);if(T(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var I={};s(I,{assertHexLen:()=>ne,ensureHexPrefix:()=>_,hexNormalize:()=>te,isHex:()=>U,stripHexPrefix:()=>re});var ee=/^0x[0-9a-fA-F]*$/;function U(e,t=!1){return e==="0x"?!0:!ee.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function re(e){return e.startsWith("0x")?e.slice(2):e}function _(e){return e.startsWith("0x")?e:`0x${e}`}function te(e){return _(e.toLowerCase())}function ne(e,t){if(!U(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var R={};s(R,{logger:()=>ie});var y={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function l(e){return e.padEnd(11)}var p={TRACE:l("[GC][TRACE]"),DEBUG:l("[GC][DEBUG]"),INFO:l("[GC][INFO]"),WARN:l("[GC][WARN]"),ERROR:l("[GC][ERROR]")};function oe(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in y)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in y)return e}return"silent"}function d(e){let t=oe();return y[e]>=y[t]}var ie={trace(...e){d("trace")&&console.debug(p.TRACE,...e)},debug(...e){d("debug")&&console.debug(p.DEBUG,...e)},info(...e){d("info")&&console.info(p.INFO,...e)},warn(...e){d("warn")&&console.warn(p.WARN,...e)},error(...e){if(!d("error"))return;e.some(r=>r instanceof Error)?console.error(p.ERROR,...e):this.warn(...e)}};var k={};s(k,{encodeAssetId:()=>S,encodeLocation:()=>L,toAccountId32:()=>P,toAccountKey20:()=>X,transform:()=>i});var c=require("polkadot-api"),P=e=>{let t=(0,c.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:c.FixedSizeBinary.fromBytes(t)}}},X=e=>({type:"AccountKey20",value:{network:void 0,key:c.FixedSizeBinary.fromHex(e)}}),i=e=>{if(Array.isArray(e))return e.map(i);if(typeof e=="object"&&e!==null){let t=Object.keys(e);if(t.length===1){let r=t[0],n=e[r];if(r==="AccountKey20"&&typeof n=="object"){let o=X(n.key);return n.network&&(o.value.network=i(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=P(n.id);return n.network&&(o.value.network=i(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?c.Binary.fromHex(n.data):n.data}}:r==="GlobalConsensus"&&typeof n=="object"&&("Polkadot"in n||"Kusama"in n)?{type:r,value:n}:r==="Ethereum"?{type:r,value:{chain_id:BigInt("chainId"in n?n.chainId:n.chain_id)}}:r==="PalletInstance"?{type:r,value:n}:r==="GeneralIndex"?{type:r,value:BigInt(n)}:r==="X1"&&Array.isArray(n)?{type:r,value:n.length===1?i(n[0]):n.map(i)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:i(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=i(o)}return r}}else return e};function L(e){if(!e||typeof e!="object")return e;let{parents:t,interior:r}=e;return!r||r==="Here"?{parents:t,interior:{type:"Here"}}:{parents:t,interior:i(r)}}function S(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?i(e):e}var N={};s(N,{convertToId:()=>se});var K=require("buffer");function se(e){let r=K.Buffer.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}0&&(module.exports={HYDRATION_SS58_PREFIX,RUNTIME_DECIMALS,big,encodeAssetId,encodeLocation,enums,erc20,h160,hex,log,transform,xc,xcm});
1
+ "use strict";var Q=Object.create;var y=Object.defineProperty;var Z=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var s=(e,t)=>{for(var r in t)y(e,r,{get:t[r],enumerable:!0})},U=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ee(t))!te.call(e,o)&&o!==r&&y(e,o,{get:()=>t[o],enumerable:!(n=Z(t,o))||n.enumerable});return e};var ne=(e,t,r)=>(r=e!=null?Q(re(e)):{},U(t||!e||!e.__esModule?y(r,"default",{value:e,enumerable:!0}):r,e)),oe=e=>U(y({},"__esModule",{value:!0}),e);var xe={};s(xe,{HYDRATION_SS58_PREFIX:()=>h,RUNTIME_DECIMALS:()=>Ae,big:()=>v,encodeAssetId:()=>C,encodeLocation:()=>H,enums:()=>w,erc20:()=>R,h160:()=>D,hex:()=>N,log:()=>F,meta:()=>G,transform:()=>i,xc:()=>T,xcm:()=>O});module.exports=oe(xe);var Ae=18,h=63;var v={};s(v,{asBigInt:()=>ie,convertDecimals:()=>se,pow10:()=>ue,toBigInt:()=>P,toDecimal:()=>_});var c=ne(require("big.js"));c.default.NE=-18;function _(e,t,r){let n=(0,c.default)(e.toString().replace(/[^0-9]/g,"")),o=(0,c.default)(10).pow(t);return n.div(o).round(t,r).toString()}function P(e,t){if(typeof e=="bigint")return e;let r=(0,c.default)(10).pow(t),n=(0,c.default)(e).mul(r);return BigInt(n.toFixed(0,c.default.roundDown))}function ie(e){return BigInt(e.round(0,c.default.roundDown).toFixed(0))}function se(e,t,r){let n=_(e,t);return P(n.toString(),r)}function ue(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var w={};s(w,{enumPath:()=>ce});function ce(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var R={};s(R,{ERC20:()=>I});var I=class{static fromAssetId(t){let r=Buffer.alloc(20,0);return r[15]=1,r.writeUInt32BE(t,16),"0x"+r.toString("hex")}static toAssetId(t){let r=Buffer.from(t.replace("0x",""),"hex");return r.length!==20||!this.isAssetAddress(t)?null:r.readUInt32BE(16)}static isAssetAddress(t){let r=Buffer.from("0000000000000000000000000000000100000000","hex"),n=Buffer.from(t.replace("0x",""),"hex");return n.length!==20?!1:n.subarray(0,16).equals(r.subarray(0,16))}};var D={};s(D,{H160:()=>S,isEvmAccount:()=>M,isEvmAddress:()=>X,isSs58Address:()=>K});var d=require("polkadot-api"),L=require("@polkadot-api/utils"),u=require("buffer");var k="ETH\0";function M(e){if(!e)return!1;try{let t=(0,d.AccountId)().enc(e),r=u.Buffer.from(k);return u.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function X(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function K(e){try{return(0,d.AccountId)(63).enc(e),!0}catch{return!1}}var S=class e{static toAccount=t=>{let r=u.Buffer.from(t.slice(2),"hex"),n=u.Buffer.from(k),o=Uint8Array.from(u.Buffer.concat([n,r,u.Buffer.alloc(8)])),m=(0,L.toHex)(o);return(0,d.AccountId)(63).dec(m)};static fromAccount=t=>{let r=(0,d.AccountId)().enc(t),n=u.Buffer.from(k),o=r.slice(n.length,-8);return"0x"+u.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,d.AccountId)().enc(t).slice(0,20);return(0,L.toHex)(n)};static fromAny=t=>{if(X(t))return t;if(M(t))return e.fromAccount(t);if(K(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var N={};s(N,{assertHexLen:()=>le,ensureHexPrefix:()=>$,hexNormalize:()=>de,isHex:()=>W,stripHexPrefix:()=>ae});var fe=/^0x[0-9a-fA-F]*$/;function W(e,t=!1){return e==="0x"?!0:!fe.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function ae(e){return e.startsWith("0x")?e.slice(2):e}function $(e){return e.startsWith("0x")?e:`0x${e}`}function de(e){return $(e.toLowerCase())}function le(e,t){if(!W(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var F={};s(F,{logger:()=>ge});var x={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function l(e){return e.padEnd(11)}var p={TRACE:l("[GC][TRACE]"),DEBUG:l("[GC][DEBUG]"),INFO:l("[GC][INFO]"),WARN:l("[GC][WARN]"),ERROR:l("[GC][ERROR]")};function pe(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in x)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in x)return e}return"silent"}function g(e){let t=pe();return x[e]>=x[t]}var ge={trace(...e){g("trace")&&console.debug(p.TRACE,...e)},debug(...e){g("debug")&&console.debug(p.DEBUG,...e)},info(...e){g("info")&&console.info(p.INFO,...e)},warn(...e){g("warn")&&console.warn(p.WARN,...e)},error(...e){if(!g("error"))return;e.some(r=>r instanceof Error)?console.error(p.ERROR,...e):this.warn(...e)}};var G={};s(G,{ErrorDecoder:()=>me});var B=require("@polkadot-api/substrate-bindings");function me(e){let{metadata:t}=B.metadata.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(f=>[f.index,f])),m=new Map(n.map(f=>[f.id,f]));return{decode(f,z){let A=o.get(f);if(!A?.errors)return;let E=m.get(A.errors);if(!E||E.def.tag!=="variant")return;let Y=B.u32.dec(z),b=E.def.value.find(J=>J.index===Y);if(b)return{pallet:A.name,error:b.name,desc:b.docs[0]}}}}var O={};s(O,{encodeAssetId:()=>C,encodeLocation:()=>H,toAccountId32:()=>j,toAccountKey20:()=>V,transform:()=>i});var a=require("polkadot-api"),j=e=>{let t=(0,a.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:a.FixedSizeBinary.fromBytes(t)}}},V=e=>({type:"AccountKey20",value:{network:void 0,key:a.FixedSizeBinary.fromHex(e)}}),i=e=>{if(Array.isArray(e))return e.map(i);if(typeof e=="object"&&e!==null){let t=Object.keys(e);if(t.length===1){let r=t[0],n=e[r];if(r==="AccountKey20"&&typeof n=="object"){let o=V(n.key);return n.network&&(o.value.network=i(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=j(n.id);return n.network&&(o.value.network=i(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?a.Binary.fromHex(n.data):n.data}}:r==="GlobalConsensus"&&typeof n=="object"&&("Polkadot"in n||"Kusama"in n)?{type:r,value:n}:r==="Ethereum"?{type:r,value:{chain_id:BigInt("chainId"in n?n.chainId:n.chain_id)}}:r==="PalletInstance"?{type:r,value:n}:r==="GeneralIndex"?{type:r,value:BigInt(n)}:r==="X1"&&Array.isArray(n)?{type:r,value:n.length===1?i(n[0]):n.map(i)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:i(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=i(o)}return r}}else return e};function H(e){if(!e||typeof e!="object")return e;let{parents:t,interior:r}=e;return!r||r==="Here"?{parents:t,interior:{type:"Here"}}:{parents:t,interior:i(r)}}function C(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?i(e):e}var T={};s(T,{convertToId:()=>ye});var q=require("buffer");function ye(e){let r=q.Buffer.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}0&&(module.exports={HYDRATION_SS58_PREFIX,RUNTIME_DECIMALS,big,encodeAssetId,encodeLocation,enums,erc20,h160,hex,log,meta,transform,xc,xcm});
package/build/index.mjs CHANGED
@@ -1 +1 @@
1
- var P=Object.defineProperty;var s=(e,t)=>{for(var r in t)P(e,r,{get:t[r],enumerable:!0})};var te=18,g=63;var E={};s(E,{asBigInt:()=>X,convertDecimals:()=>K,pow10:()=>W,toBigInt:()=>b,toDecimal:()=>B});import f from"big.js";f.NE=-18;function B(e,t,r){let n=f(e.toString().replace(/[^0-9]/g,"")),o=f(10).pow(t);return n.div(o).round(t,r).toString()}function b(e,t){if(typeof e=="bigint")return e;let r=f(10).pow(t),n=f(e).mul(r);return BigInt(n.toFixed(0,f.roundDown))}function X(e){return BigInt(e.round(0,f.roundDown).toFixed(0))}function K(e,t,r){let n=B(e,t);return b(n.toString(),r)}function W(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var h={};s(h,{enumPath:()=>$});function $(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var v={};s(v,{ERC20:()=>y});var y=class{static fromAssetId(t){let r=Buffer.alloc(20,0);return r[15]=1,r.writeUInt32BE(t,16),"0x"+r.toString("hex")}static toAssetId(t){let r=Buffer.from(t.replace("0x",""),"hex");return r.length!==20||!this.isAssetAddress(t)?null:r.readUInt32BE(16)}static isAssetAddress(t){let r=Buffer.from("0000000000000000000000000000000100000000","hex"),n=Buffer.from(t.replace("0x",""),"hex");return n.length!==20?!1:n.subarray(0,16).equals(r.subarray(0,16))}};var S={};s(S,{H160:()=>x,isEvmAccount:()=>I,isEvmAddress:()=>R,isSs58Address:()=>L});import{AccountId as c}from"polkadot-api";import{toHex as w}from"@polkadot-api/utils";import{Buffer as u}from"buffer";var m="ETH\0";function I(e){if(!e)return!1;try{let t=c().enc(e),r=u.from(m);return u.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function R(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function L(e){try{return c(63).enc(e),!0}catch{return!1}}var x=class e{static toAccount=t=>{let r=u.from(t.slice(2),"hex"),n=u.from(m),o=Uint8Array.from(u.concat([n,r,u.alloc(8)])),A=w(o);return c(63).dec(A)};static fromAccount=t=>{let r=c().enc(t),n=u.from(m),o=r.slice(n.length,-8);return"0x"+u.from(o).toString("hex")};static fromSS58=t=>{let n=c().enc(t).slice(0,20);return w(n)};static fromAny=t=>{if(R(t))return t;if(I(t))return e.fromAccount(t);if(L(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var F={};s(F,{assertHexLen:()=>z,ensureHexPrefix:()=>N,hexNormalize:()=>q,isHex:()=>k,stripHexPrefix:()=>M});var j=/^0x[0-9a-fA-F]*$/;function k(e,t=!1){return e==="0x"?!0:!j.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function M(e){return e.startsWith("0x")?e.slice(2):e}function N(e){return e.startsWith("0x")?e:`0x${e}`}function q(e){return N(e.toLowerCase())}function z(e,t){if(!k(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var G={};s(G,{logger:()=>V});var d={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function a(e){return e.padEnd(11)}var l={TRACE:a("[GC][TRACE]"),DEBUG:a("[GC][DEBUG]"),INFO:a("[GC][INFO]"),WARN:a("[GC][WARN]"),ERROR:a("[GC][ERROR]")};function Y(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in d)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in d)return e}return"silent"}function p(e){let t=Y();return d[e]>=d[t]}var V={trace(...e){p("trace")&&console.debug(l.TRACE,...e)},debug(...e){p("debug")&&console.debug(l.DEBUG,...e)},info(...e){p("info")&&console.info(l.INFO,...e)},warn(...e){p("warn")&&console.warn(l.WARN,...e)},error(...e){if(!p("error"))return;e.some(r=>r instanceof Error)?console.error(l.ERROR,...e):this.warn(...e)}};var U={};s(U,{encodeAssetId:()=>T,encodeLocation:()=>D,toAccountId32:()=>C,toAccountKey20:()=>O,transform:()=>i});import{AccountId as J,Binary as Q,FixedSizeBinary as H}from"polkadot-api";var C=e=>{let t=J().enc(e);return{type:"AccountId32",value:{network:void 0,id:H.fromBytes(t)}}},O=e=>({type:"AccountKey20",value:{network:void 0,key:H.fromHex(e)}}),i=e=>{if(Array.isArray(e))return e.map(i);if(typeof e=="object"&&e!==null){let t=Object.keys(e);if(t.length===1){let r=t[0],n=e[r];if(r==="AccountKey20"&&typeof n=="object"){let o=O(n.key);return n.network&&(o.value.network=i(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=C(n.id);return n.network&&(o.value.network=i(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?Q.fromHex(n.data):n.data}}:r==="GlobalConsensus"&&typeof n=="object"&&("Polkadot"in n||"Kusama"in n)?{type:r,value:n}:r==="Ethereum"?{type:r,value:{chain_id:BigInt("chainId"in n?n.chainId:n.chain_id)}}:r==="PalletInstance"?{type:r,value:n}:r==="GeneralIndex"?{type:r,value:BigInt(n)}:r==="X1"&&Array.isArray(n)?{type:r,value:n.length===1?i(n[0]):n.map(i)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:i(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=i(o)}return r}}else return e};function D(e){if(!e||typeof e!="object")return e;let{parents:t,interior:r}=e;return!r||r==="Here"?{parents:t,interior:{type:"Here"}}:{parents:t,interior:i(r)}}function T(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?i(e):e}var _={};s(_,{convertToId:()=>ee});import{Buffer as Z}from"buffer";function ee(e){let r=Z.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}export{g as HYDRATION_SS58_PREFIX,te as RUNTIME_DECIMALS,E as big,T as encodeAssetId,D as encodeLocation,h as enums,v as erc20,S as h160,F as hex,G as log,i as transform,_ as xc,U as xcm};
1
+ var q=Object.defineProperty;var s=(e,t)=>{for(var r in t)q(e,r,{get:t[r],enumerable:!0})};var pe=18,A=63;var I={};s(I,{asBigInt:()=>z,convertDecimals:()=>Y,pow10:()=>J,toBigInt:()=>w,toDecimal:()=>v});import f from"big.js";f.NE=-18;function v(e,t,r){let n=f(e.toString().replace(/[^0-9]/g,"")),o=f(10).pow(t);return n.div(o).round(t,r).toString()}function w(e,t){if(typeof e=="bigint")return e;let r=f(10).pow(t),n=f(e).mul(r);return BigInt(n.toFixed(0,f.roundDown))}function z(e){return BigInt(e.round(0,f.roundDown).toFixed(0))}function Y(e,t,r){let n=v(e,t);return w(n.toString(),r)}function J(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var R={};s(R,{enumPath:()=>Q});function Q(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var L={};s(L,{ERC20:()=>E});var E=class{static fromAssetId(t){let r=Buffer.alloc(20,0);return r[15]=1,r.writeUInt32BE(t,16),"0x"+r.toString("hex")}static toAssetId(t){let r=Buffer.from(t.replace("0x",""),"hex");return r.length!==20||!this.isAssetAddress(t)?null:r.readUInt32BE(16)}static isAssetAddress(t){let r=Buffer.from("0000000000000000000000000000000100000000","hex"),n=Buffer.from(t.replace("0x",""),"hex");return n.length!==20?!1:n.subarray(0,16).equals(r.subarray(0,16))}};var F={};s(F,{H160:()=>h,isEvmAccount:()=>S,isEvmAddress:()=>D,isSs58Address:()=>N});import{AccountId as a}from"polkadot-api";import{toHex as k}from"@polkadot-api/utils";import{Buffer as u}from"buffer";var b="ETH\0";function S(e){if(!e)return!1;try{let t=a().enc(e),r=u.from(b);return u.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function D(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function N(e){try{return a(63).enc(e),!0}catch{return!1}}var h=class e{static toAccount=t=>{let r=u.from(t.slice(2),"hex"),n=u.from(b),o=Uint8Array.from(u.concat([n,r,u.alloc(8)])),g=k(o);return a(63).dec(g)};static fromAccount=t=>{let r=a().enc(t),n=u.from(b),o=r.slice(n.length,-8);return"0x"+u.from(o).toString("hex")};static fromSS58=t=>{let n=a().enc(t).slice(0,20);return k(n)};static fromAny=t=>{if(D(t))return t;if(S(t))return e.fromAccount(t);if(N(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var C={};s(C,{assertHexLen:()=>te,ensureHexPrefix:()=>H,hexNormalize:()=>re,isHex:()=>G,stripHexPrefix:()=>ee});var Z=/^0x[0-9a-fA-F]*$/;function G(e,t=!1){return e==="0x"?!0:!Z.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function ee(e){return e.startsWith("0x")?e.slice(2):e}function H(e){return e.startsWith("0x")?e:`0x${e}`}function re(e){return H(e.toLowerCase())}function te(e,t){if(!G(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var O={};s(O,{logger:()=>oe});var m={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function d(e){return e.padEnd(11)}var l={TRACE:d("[GC][TRACE]"),DEBUG:d("[GC][DEBUG]"),INFO:d("[GC][INFO]"),WARN:d("[GC][WARN]"),ERROR:d("[GC][ERROR]")};function ne(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in m)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in m)return e}return"silent"}function p(e){let t=ne();return m[e]>=m[t]}var oe={trace(...e){p("trace")&&console.debug(l.TRACE,...e)},debug(...e){p("debug")&&console.debug(l.DEBUG,...e)},info(...e){p("info")&&console.info(l.INFO,...e)},warn(...e){p("warn")&&console.warn(l.WARN,...e)},error(...e){if(!p("error"))return;e.some(r=>r instanceof Error)?console.error(l.ERROR,...e):this.warn(...e)}};var T={};s(T,{ErrorDecoder:()=>ue});import{metadata as ie,u32 as se}from"@polkadot-api/substrate-bindings";function ue(e){let{metadata:t}=ie.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(c=>[c.index,c])),g=new Map(n.map(c=>[c.id,c]));return{decode(c,$){let y=o.get(c);if(!y?.errors)return;let x=g.get(y.errors);if(!x||x.def.tag!=="variant")return;let j=se.dec($),B=x.def.value.find(V=>V.index===j);if(B)return{pallet:y.name,error:B.name,desc:B.docs[0]}}}}var K={};s(K,{encodeAssetId:()=>X,encodeLocation:()=>M,toAccountId32:()=>_,toAccountKey20:()=>P,transform:()=>i});import{AccountId as ce,Binary as fe,FixedSizeBinary as U}from"polkadot-api";var _=e=>{let t=ce().enc(e);return{type:"AccountId32",value:{network:void 0,id:U.fromBytes(t)}}},P=e=>({type:"AccountKey20",value:{network:void 0,key:U.fromHex(e)}}),i=e=>{if(Array.isArray(e))return e.map(i);if(typeof e=="object"&&e!==null){let t=Object.keys(e);if(t.length===1){let r=t[0],n=e[r];if(r==="AccountKey20"&&typeof n=="object"){let o=P(n.key);return n.network&&(o.value.network=i(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=_(n.id);return n.network&&(o.value.network=i(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?fe.fromHex(n.data):n.data}}:r==="GlobalConsensus"&&typeof n=="object"&&("Polkadot"in n||"Kusama"in n)?{type:r,value:n}:r==="Ethereum"?{type:r,value:{chain_id:BigInt("chainId"in n?n.chainId:n.chain_id)}}:r==="PalletInstance"?{type:r,value:n}:r==="GeneralIndex"?{type:r,value:BigInt(n)}:r==="X1"&&Array.isArray(n)?{type:r,value:n.length===1?i(n[0]):n.map(i)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:i(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=i(o)}return r}}else return e};function M(e){if(!e||typeof e!="object")return e;let{parents:t,interior:r}=e;return!r||r==="Here"?{parents:t,interior:{type:"Here"}}:{parents:t,interior:i(r)}}function X(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?i(e):e}var W={};s(W,{convertToId:()=>de});import{Buffer as ae}from"buffer";function de(e){let r=ae.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}export{A as HYDRATION_SS58_PREFIX,pe as RUNTIME_DECIMALS,I as big,X as encodeAssetId,M as encodeLocation,R as enums,L as erc20,F as h160,C as hex,O as log,T as meta,i as transform,W as xc,K as xcm};
@@ -4,6 +4,7 @@ export * as erc20 from './erc20';
4
4
  export * as h160 from './h160';
5
5
  export * as hex from './hex';
6
6
  export * as log from './log';
7
+ export * as meta from './meta';
7
8
  export * as xcm from './xcm';
8
9
  export * as xc from './xc';
9
10
  export { encodeAssetId, encodeLocation, transform } from './xcm';
@@ -0,0 +1,8 @@
1
+ export type DecodedError = {
2
+ pallet: string;
3
+ error: string;
4
+ desc: string;
5
+ };
6
+ export declare function ErrorDecoder(metadataBytes: Uint8Array): {
7
+ decode(palletIndex: number, errorHex: string): DecodedError | undefined;
8
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/common",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Common utilities shared across Galactic SDK packages",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {