@galacticcouncil/common 0.5.2-pr302-7a922f2 → 0.7.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.
@@ -0,0 +1 @@
1
+ "use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var _=(i,e)=>{for(var t in e)d(i,t,{get:e[t],enumerable:!0})},S=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of v(e))!x.call(i,n)&&n!==t&&d(i,n,{get:()=>e[n],enumerable:!(r=y(e,n))||r.enumerable});return i};var H=i=>S(d({},"__esModule",{value:!0}),i);var w={};_(w,{SubstrateApis:()=>u,blockProbe$:()=>h,detectLegacyRpc:()=>k,wsToHttp:()=>M});module.exports=H(w);var g=require("polkadot-api"),P=require("polkadot-api/ws-provider"),m=require("lru-cache");var l=require("rxjs"),o=require("rxjs/operators");function h(i,{intervalMs:e=5e3,timeoutMs:t=5e3,staleThreshold:r=3,initialDelayMs:n=0}={}){let s=c=>(0,l.defer)(()=>(0,l.from)(i._request("chain_getHeader",[]))).pipe((0,o.timeout)({first:t}),(0,o.map)(p=>{let f=parseInt(p.number,16),C=c.blockNumber!==void 0&&f<=c.blockNumber?c.staleCount+1:0;return{state:C>=r?"stale":"healthy",blockNumber:f,staleCount:C,delayMs:e}}),(0,o.catchError)(()=>{let p=c.staleCount+1;return(0,l.of)({state:p>=r?"stale":"healthy",staleCount:p,delayMs:e})}));return(0,l.of)({state:"healthy",staleCount:0,delayMs:n}).pipe((0,o.expand)(c=>(0,l.timer)(c.delayMs).pipe((0,o.switchMap)(()=>s(c)))),(0,o.skip)(1),(0,o.map)(c=>c.state),(0,o.distinctUntilChanged)(),(0,o.shareReplay)({bufferSize:1,refCount:!0}))}var u=class i{static _instance=new i;_cache=new m.LRUCache({max:40});_metadataCache;constructor(){if(i._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");i._instance=this}static getInstance(){return i._instance}configureMetadataCache(e){this._metadataCache=e}createCacheKey(e){return e.join(",")}findCacheKey(e){let t=e.find(n=>this._cache.has(n));if(t)return t;let r=this.createCacheKey(e);return this._cache.has(r)?r:null}createClient(e,t){let r=(0,P.getWsProvider)(e,t?.wsProviderOpts),n=(0,g.createClient)(r,this._metadataCache),s=this.createCacheKey(e);console.log(`Created PAPI client for ${s}`);let a={client:n,provider:r,endpoints:e,currentEndpointIndex:0};return this._cache.set(s,a,{noDisposeOnSet:!0}),t?.probeConfig?.enabled!==!1&&this.startHealthProbe(a,t?.probeConfig),n}api(e,t){let r=typeof e=="string"?e.split(","):e,n=this.findCacheKey(r);return n?this._cache.get(n).client:this.createClient(r,t)}release(){for(let[e,t]of this._cache.entries())this.stopHealthProbe(t),console.log("Releasing "+e),t.client.destroy();this._cache.clear()}configureHealthProbe(e,t){let r=typeof e=="string"?e.split(","):e,n=this.findCacheKey(r);if(n){let s=this._cache.get(n);this.stopHealthProbe(s),t.enabled!==!1&&this.startHealthProbe(s,t)}}startHealthProbe(e,t={}){let r=n=>{if(e.endpoints.length>1){let s=(e.currentEndpointIndex+1)%e.endpoints.length,a=e.endpoints[s];console.log(`${n} on ${e.endpoints[e.currentEndpointIndex]}, switching to ${a}`),e.provider.switch(a),e.currentEndpointIndex=s,this.stopHealthProbe(e),this.startHealthProbe(e,{...t,initialDelayMs:t.intervalMs??5e3})}};e.probeSubscription=h(e.client,t).subscribe({next:n=>{n==="stale"&&r("RPC stale")}})}stopHealthProbe(e){e.probeSubscription&&(e.probeSubscription.unsubscribe(),e.probeSubscription=void 0)}getWs(e){let t=typeof e=="string"?e.split(","):e,r=this.findCacheKey(t);if(r)return this._cache.get(r)?.provider}};function M(i){return i.replace(/^(ws)(s)?:\/\//,(e,t,r)=>r?"https://":"http://")}var b=new Map;async function k(i,e){let t=b.get(i);if(t!==void 0)return t;try{let r=await fetch(i,{signal:e,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!r.ok)return!1;let s=(await r.json())?.result?.methods??[];if(s.includes("dev_newBlock"))return b.set(i,!0),!0;let a=!s.includes("chainHead_v1_follow");return b.set(i,a),a}catch{return!1}}0&&(module.exports={SubstrateApis,blockProbe$,detectLegacyRpc,wsToHttp});
@@ -0,0 +1 @@
1
+ import{createClient as M}from"polkadot-api";import{getWsProvider as k}from"polkadot-api/ws-provider";import{LRUCache as w}from"lru-cache";import{defer as C,from as g,of as h,timer as P}from"rxjs";import{catchError as m,distinctUntilChanged as y,expand as v,map as u,shareReplay as x,skip as _,switchMap as S,timeout as H}from"rxjs/operators";function b(o,{intervalMs:e=5e3,timeoutMs:t=5e3,staleThreshold:r=3,initialDelayMs:n=0}={}){let i=a=>C(()=>g(o._request("chain_getHeader",[]))).pipe(H({first:t}),u(c=>{let p=parseInt(c.number,16),d=a.blockNumber!==void 0&&p<=a.blockNumber?a.staleCount+1:0;return{state:d>=r?"stale":"healthy",blockNumber:p,staleCount:d,delayMs:e}}),m(()=>{let c=a.staleCount+1;return h({state:c>=r?"stale":"healthy",staleCount:c,delayMs:e})}));return h({state:"healthy",staleCount:0,delayMs:n}).pipe(v(a=>P(a.delayMs).pipe(S(()=>i(a)))),_(1),u(a=>a.state),y(),x({bufferSize:1,refCount:!0}))}var f=class o{static _instance=new o;_cache=new w({max:40});_metadataCache;constructor(){if(o._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");o._instance=this}static getInstance(){return o._instance}configureMetadataCache(e){this._metadataCache=e}createCacheKey(e){return e.join(",")}findCacheKey(e){let t=e.find(n=>this._cache.has(n));if(t)return t;let r=this.createCacheKey(e);return this._cache.has(r)?r:null}createClient(e,t){let r=k(e,t?.wsProviderOpts),n=M(r,this._metadataCache),i=this.createCacheKey(e);console.log(`Created PAPI client for ${i}`);let s={client:n,provider:r,endpoints:e,currentEndpointIndex:0};return this._cache.set(i,s,{noDisposeOnSet:!0}),t?.probeConfig?.enabled!==!1&&this.startHealthProbe(s,t?.probeConfig),n}api(e,t){let r=typeof e=="string"?e.split(","):e,n=this.findCacheKey(r);return n?this._cache.get(n).client:this.createClient(r,t)}release(){for(let[e,t]of this._cache.entries())this.stopHealthProbe(t),console.log("Releasing "+e),t.client.destroy();this._cache.clear()}configureHealthProbe(e,t){let r=typeof e=="string"?e.split(","):e,n=this.findCacheKey(r);if(n){let i=this._cache.get(n);this.stopHealthProbe(i),t.enabled!==!1&&this.startHealthProbe(i,t)}}startHealthProbe(e,t={}){let r=n=>{if(e.endpoints.length>1){let i=(e.currentEndpointIndex+1)%e.endpoints.length,s=e.endpoints[i];console.log(`${n} on ${e.endpoints[e.currentEndpointIndex]}, switching to ${s}`),e.provider.switch(s),e.currentEndpointIndex=i,this.stopHealthProbe(e),this.startHealthProbe(e,{...t,initialDelayMs:t.intervalMs??5e3})}};e.probeSubscription=b(e.client,t).subscribe({next:n=>{n==="stale"&&r("RPC stale")}})}stopHealthProbe(e){e.probeSubscription&&(e.probeSubscription.unsubscribe(),e.probeSubscription=void 0)}getWs(e){let t=typeof e=="string"?e.split(","):e,r=this.findCacheKey(t);if(r)return this._cache.get(r)?.provider}};function q(o){return o.replace(/^(ws)(s)?:\/\//,(e,t,r)=>r?"https://":"http://")}var l=new Map;async function z(o,e){let t=l.get(o);if(t!==void 0)return t;try{let r=await fetch(o,{signal:e,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!r.ok)return!1;let i=(await r.json())?.result?.methods??[];if(i.includes("dev_newBlock"))return l.set(o,!0),!0;let s=!i.includes("chainHead_v1_follow");return l.set(o,s),s}catch{return!1}}export{f as SubstrateApis,b as blockProbe$,z as detectLegacyRpc,q as wsToHttp};
@@ -0,0 +1 @@
1
+ "use strict";var re=Object.create;var w=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},M=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ne(t))!ie.call(e,o)&&o!==r&&w(e,o,{get:()=>t[o],enumerable:!(n=te(t,o))||n.enumerable});return e};var se=(e,t,r)=>(r=e!=null?re(oe(e)):{},M(t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r,e)),ce=e=>M(w({},"__esModule",{value:!0}),e);var he={};c(he,{acc:()=>R,big:()=>S,encodeAssetId:()=>P,encodeLocation:()=>O,enums:()=>L,erc20:()=>C,h160:()=>T,hex:()=>U,log:()=>F,meta:()=>G,transform:()=>s,xc:()=>K,xcm:()=>_});module.exports=ce(he);var R={};c(R,{getMultilocationDerivatedAccount:()=>ue,getSovereignAccounts:()=>fe});var f=require("@polkadot-api/substrate-bindings"),m=require("@polkadot-api/utils");function ue(e,t,r,n=!1){let o=t.length===42,u=o?"AccountKey20":"AccountId32",i;if(o)i=(0,m.fromHex)(t.slice(2));else{let g=(0,f.getSs58AddressInfo)(t);if(!g.isValid)throw new Error("Invalid SS58 address");i=g.publicKey}let x="SiblingChain";r==0&&e?x="ChildChain":r==1&&!e&&(x="ParentChain");let p=f.compactNumber.enc,A=new Uint8Array([...new TextEncoder().encode(x),...e?p(e):[],...p(u.length+(o?20:32)),...new TextEncoder().encode(u),...i]),h=(0,f.Blake2256)(A);return n?(0,m.toHex)(h.slice(0,20)):(0,f.AccountId)().dec(h)}function fe(e){let t=f.u32.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=(0,m.toHex)(new Uint8Array([...r,...t])).padEnd(66,"0"),u=(0,m.toHex)(new Uint8Array([...n,...t])).padEnd(66,"0"),i=u.slice(0,42);return{generic:u,moonbeam:i,relay:o}}var S={};c(S,{asBigInt:()=>ae,convertDecimals:()=>de,pow10:()=>le,toBigInt:()=>V,toDecimal:()=>X});var d=se(require("big.js"));d.default.NE=-18;function X(e,t,r){let n=(0,d.default)(e.toString().replace(/[^0-9]/g,"")),o=(0,d.default)(10).pow(t);return n.div(o).round(t,r).toString()}function V(e,t){if(typeof e=="bigint")return e;let r=(0,d.default)(10).pow(t),n=(0,d.default)(e).mul(r);return BigInt(n.toFixed(0,d.default.roundDown))}function ae(e){return BigInt(e.round(0,d.default.roundDown).toFixed(0))}function de(e,t,r){let n=X(e,t);return V(n.toString(),r)}function le(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var L={};c(L,{enumPath:()=>pe});function pe(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var C={};c(C,{ERC20:()=>k});var k=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 T={};c(T,{H160:()=>N,isEvmAccount:()=>$,isEvmAddress:()=>j,isSs58Address:()=>q});var y=require("polkadot-api"),H=require("@polkadot-api/utils"),a=require("buffer");var D="ETH\0";function $(e){if(!e)return!1;try{let t=(0,y.AccountId)().enc(e),r=a.Buffer.from(D);return a.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function j(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function q(e){try{return(0,y.AccountId)(63).enc(e),!0}catch{return!1}}var N=class e{static toAccount=t=>{let r=a.Buffer.from(t.slice(2),"hex"),n=a.Buffer.from(D),o=Uint8Array.from(a.Buffer.concat([n,r,a.Buffer.alloc(8)])),u=(0,H.toHex)(o);return(0,y.AccountId)(63).dec(u)};static fromAccount=t=>{let r=(0,y.AccountId)().enc(t),n=a.Buffer.from(D),o=r.slice(n.length,-8);return"0x"+a.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,y.AccountId)().enc(t).slice(0,20);return(0,H.toHex)(n)};static fromAny=t=>{if(j(t))return t;if($(t))return e.fromAccount(t);if(q(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var U={};c(U,{assertHexLen:()=>xe,ensureHexPrefix:()=>Y,hexNormalize:()=>ye,isHex:()=>z,stripHexPrefix:()=>me});var ge=/^0x[0-9a-fA-F]*$/;function z(e,t=!1){return e==="0x"?!0:!ge.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function me(e){return e.startsWith("0x")?e.slice(2):e}function Y(e){return e.startsWith("0x")?e:`0x${e}`}function ye(e){return Y(e.toLowerCase())}function xe(e,t){if(!z(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var F={};c(F,{logger:()=>Ee});var v={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function E(e){return e.padEnd(11)}var b={TRACE:E("[GC][TRACE]"),DEBUG:E("[GC][DEBUG]"),INFO:E("[GC][INFO]"),WARN:E("[GC][WARN]"),ERROR:E("[GC][ERROR]")};function Ae(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in v)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in v)return e}return"silent"}function B(e){let t=Ae();return v[e]>=v[t]}var Ee={trace(...e){B("trace")&&console.debug(b.TRACE,...e)},debug(...e){B("debug")&&console.debug(b.DEBUG,...e)},info(...e){B("info")&&console.info(b.INFO,...e)},warn(...e){B("warn")&&console.warn(b.WARN,...e)},error(...e){if(!B("error"))return;e.some(r=>r instanceof Error)?console.error(b.ERROR,...e):this.warn(...e)}};var G={};c(G,{ErrorDecoder:()=>be});var I=require("@polkadot-api/substrate-bindings");function be(e){let{metadata:t}=I.metadata.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(i=>[i.index,i])),u=new Map(n.map(i=>[i.id,i]));return{decode(i,x){let p=o.get(i);if(!p?.errors)return;let A=u.get(p.errors);if(!A||A.def.tag!=="variant")return;let h=I.u32.dec(x),g=A.def.value.find(ee=>ee.index===h);if(g)return{pallet:p.name,error:g.name,desc:g.docs[0]}}}}var _={};c(_,{encodeAssetId:()=>P,encodeLocation:()=>O,toAccountId32:()=>J,toAccountKey20:()=>Q,transform:()=>s});var l=require("polkadot-api"),J=e=>{let t=(0,l.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:l.FixedSizeBinary.fromBytes(t)}}},Q=e=>({type:"AccountKey20",value:{network:void 0,key:l.FixedSizeBinary.fromHex(e)}}),s=e=>{if(Array.isArray(e))return e.map(s);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=Q(n.key);return n.network&&(o.value.network=s(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=J(n.id);return n.network&&(o.value.network=s(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?l.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?s(n[0]):n.map(s)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:s(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=s(o)}return r}}else return e};function O(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:s(r)}}function P(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?s(e):e}var K={};c(K,{convertToId:()=>Be});var Z=require("buffer");function Be(e){let r=Z.Buffer.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}0&&(module.exports={acc,big,encodeAssetId,encodeLocation,enums,erc20,h160,hex,log,meta,transform,xc,xcm});
@@ -0,0 +1 @@
1
+ var Y=Object.defineProperty;var u=(e,t)=>{for(var r in t)Y(e,r,{get:t[r],enumerable:!0})};var I={};u(I,{getMultilocationDerivatedAccount:()=>ne,getSovereignAccounts:()=>oe});import{AccountId as J,Blake2256 as Q,compactNumber as Z,getSs58AddressInfo as ee,u32 as re}from"@polkadot-api/substrate-bindings";import{toHex as B,fromHex as te}from"@polkadot-api/utils";function ne(e,t,r,n=!1){let o=t.length===42,c=o?"AccountKey20":"AccountId32",i;if(o)i=te(t.slice(2));else{let l=ee(t);if(!l.isValid)throw new Error("Invalid SS58 address");i=l.publicKey}let p="SiblingChain";r==0&&e?p="ChildChain":r==1&&!e&&(p="ParentChain");let d=Z.enc,g=new Uint8Array([...new TextEncoder().encode(p),...e?d(e):[],...d(c.length+(o?20:32)),...new TextEncoder().encode(c),...i]),E=Q(g);return n?B(E.slice(0,20)):J().dec(E)}function oe(e){let t=re.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=B(new Uint8Array([...r,...t])).padEnd(66,"0"),c=B(new Uint8Array([...n,...t])).padEnd(66,"0"),i=c.slice(0,42);return{generic:c,moonbeam:i,relay:o}}var L={};u(L,{asBigInt:()=>ie,convertDecimals:()=>se,pow10:()=>ce,toBigInt:()=>S,toDecimal:()=>R});import a from"big.js";a.NE=-18;function R(e,t,r){let n=a(e.toString().replace(/[^0-9]/g,"")),o=a(10).pow(t);return n.div(o).round(t,r).toString()}function S(e,t){if(typeof e=="bigint")return e;let r=a(10).pow(t),n=a(e).mul(r);return BigInt(n.toFixed(0,a.roundDown))}function ie(e){return BigInt(e.round(0,a.roundDown).toFixed(0))}function se(e,t,r){let n=R(e,t);return S(n.toString(),r)}function ce(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var k={};u(k,{enumPath:()=>ue});function ue(e){let t=[],r=e;for(;r&&typeof r=="object"&&"type"in r;)t.push(r.type),r=r.value;return t.join(".")}var C={};u(C,{ERC20:()=>h});var h=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={};u(F,{H160:()=>v,isEvmAccount:()=>N,isEvmAddress:()=>T,isSs58Address:()=>U});import{AccountId as m}from"polkadot-api";import{toHex as H}from"@polkadot-api/utils";import{Buffer as f}from"buffer";var w="ETH\0";function N(e){if(!e)return!1;try{let t=m().enc(e),r=f.from(w);return f.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function T(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function U(e){try{return m(63).enc(e),!0}catch{return!1}}var v=class e{static toAccount=t=>{let r=f.from(t.slice(2),"hex"),n=f.from(w),o=Uint8Array.from(f.concat([n,r,f.alloc(8)])),c=H(o);return m(63).dec(c)};static fromAccount=t=>{let r=m().enc(t),n=f.from(w),o=r.slice(n.length,-8);return"0x"+f.from(o).toString("hex")};static fromSS58=t=>{let n=m().enc(t).slice(0,20);return H(n)};static fromAny=t=>{if(T(t))return t;if(N(t))return e.fromAccount(t);if(U(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var P={};u(P,{assertHexLen:()=>le,ensureHexPrefix:()=>O,hexNormalize:()=>de,isHex:()=>G,stripHexPrefix:()=>ae});var fe=/^0x[0-9a-fA-F]*$/;function G(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 O(e){return e.startsWith("0x")?e:`0x${e}`}function de(e){return O(e.toLowerCase())}function le(e,t){if(!G(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var _={};u(_,{logger:()=>ge});var b={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function y(e){return e.padEnd(11)}var x={TRACE:y("[GC][TRACE]"),DEBUG:y("[GC][DEBUG]"),INFO:y("[GC][INFO]"),WARN:y("[GC][WARN]"),ERROR:y("[GC][ERROR]")};function pe(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in b)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in b)return e}return"silent"}function A(e){let t=pe();return b[e]>=b[t]}var ge={trace(...e){A("trace")&&console.debug(x.TRACE,...e)},debug(...e){A("debug")&&console.debug(x.DEBUG,...e)},info(...e){A("info")&&console.info(x.INFO,...e)},warn(...e){A("warn")&&console.warn(x.WARN,...e)},error(...e){if(!A("error"))return;e.some(r=>r instanceof Error)?console.error(x.ERROR,...e):this.warn(...e)}};var K={};u(K,{ErrorDecoder:()=>xe});import{metadata as me,u32 as ye}from"@polkadot-api/substrate-bindings";function xe(e){let{metadata:t}=me.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(i=>[i.index,i])),c=new Map(n.map(i=>[i.id,i]));return{decode(i,p){let d=o.get(i);if(!d?.errors)return;let g=c.get(d.errors);if(!g||g.def.tag!=="variant")return;let E=ye.dec(p),l=g.def.value.find(z=>z.index===E);if(l)return{pallet:d.name,error:l.name,desc:l.docs[0]}}}}var j={};u(j,{encodeAssetId:()=>$,encodeLocation:()=>W,toAccountId32:()=>X,toAccountKey20:()=>V,transform:()=>s});import{AccountId as Ae,Binary as Ee,FixedSizeBinary as M}from"polkadot-api";var X=e=>{let t=Ae().enc(e);return{type:"AccountId32",value:{network:void 0,id:M.fromBytes(t)}}},V=e=>({type:"AccountKey20",value:{network:void 0,key:M.fromHex(e)}}),s=e=>{if(Array.isArray(e))return e.map(s);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=s(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=X(n.id);return n.network&&(o.value.network=s(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?Ee.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?s(n[0]):n.map(s)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:s(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=s(o)}return r}}else return e};function W(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:s(r)}}function $(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?s(e):e}var q={};u(q,{convertToId:()=>Be});import{Buffer as be}from"buffer";function Be(e){let r=be.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}export{I as acc,L as big,$ as encodeAssetId,W as encodeLocation,k as enums,C as erc20,F as h160,P as hex,_ as log,K as meta,s as transform,q as xc,j as xcm};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/common",
3
- "version": "0.5.2-pr302-7a922f2",
3
+ "version": "0.7.0",
4
4
  "description": "Common utilities shared across Galactic SDK packages",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {
@@ -21,11 +21,28 @@
21
21
  ],
22
22
  "main": "./build/index.cjs",
23
23
  "module": "./build/index.mjs",
24
- "types": "./build/types/index.d.ts",
24
+ "types": "./build/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./build/index.d.ts",
28
+ "import": "./build/index.mjs",
29
+ "require": "./build/index.cjs"
30
+ },
31
+ "./utils": {
32
+ "types": "./build/utils/index.d.ts",
33
+ "import": "./build/utils/index.mjs",
34
+ "require": "./build/utils/index.cjs"
35
+ },
36
+ "./substrate": {
37
+ "types": "./build/substrate/index.d.ts",
38
+ "import": "./build/substrate/index.mjs",
39
+ "require": "./build/substrate/index.cjs"
40
+ }
41
+ },
25
42
  "scripts": {
26
43
  "build": "npm run clean && node ./esbuild.dist.mjs",
27
44
  "build:watch": "node ./esbuild.dev.mjs",
28
- "postbuild": "tsc --emitDeclarationOnly --outDir build/types/",
45
+ "postbuild": "tsc --emitDeclarationOnly --outDir build",
29
46
  "clean": "rimraf build",
30
47
  "link": "npm ln",
31
48
  "test": "NODE_NO_WARNINGS=1 NODE_OPTIONS=--experimental-vm-modules jest"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes