@galacticcouncil/common 0.7.0 → 0.8.0-pr311-1281cfa

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 ue=Object.create;var w=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},z=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of le(t))!pe.call(e,o)&&o!==r&&w(e,o,{get:()=>t[o],enumerable:!(n=fe(t,o))||n.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?ue(de(e)):{},z(t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r,e)),me=e=>z(w({},"__esModule",{value:!0}),e);var _e={};l(_e,{HYDRATION_SS58_PREFIX:()=>S,RUNTIME_DECIMALS:()=>Oe,SubstrateApis:()=>X,acc:()=>R,big:()=>H,blockProbe$:()=>j,detectLegacyRpc:()=>ke,encodeAssetId:()=>G,encodeLocation:()=>F,enums:()=>k,erc20:()=>L,h160:()=>K,hex:()=>T,log:()=>D,meta:()=>U,transform:()=>u,wsToHttp:()=>He,xc:()=>$,xcm:()=>W});module.exports=me(_e);var Oe=18,S=63;var R={};l(R,{getMultilocationDerivatedAccount:()=>he,getSovereignAccounts:()=>ye});var d=require("@polkadot-api/substrate-bindings"),x=require("@polkadot-api/utils");function he(e,t,r,n=!1){let o=t.length===42,i=o?"AccountKey20":"AccountId32",s;if(o)s=(0,x.fromHex)(t.slice(2));else{let p=(0,d.getSs58AddressInfo)(t);if(!p.isValid)throw new Error("Invalid SS58 address");s=p.publicKey}let c="SiblingChain";r==0&&e?c="ChildChain":r==1&&!e&&(c="ParentChain");let f=d.compactNumber.enc,h=new Uint8Array([...new TextEncoder().encode(c),...e?f(e):[],...f(i.length+(o?20:32)),...new TextEncoder().encode(i),...s]),v=(0,d.Blake2256)(h);return n?(0,x.toHex)(v.slice(0,20)):(0,d.AccountId)().dec(v)}function ye(e){let t=d.u32.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=(0,x.toHex)(new Uint8Array([...r,...t])).padEnd(66,"0"),i=(0,x.toHex)(new Uint8Array([...n,...t])).padEnd(66,"0"),s=i.slice(0,42);return{generic:i,moonbeam:s,relay:o}}var H={};l(H,{asBigInt:()=>be,convertDecimals:()=>xe,pow10:()=>Ce,toBigInt:()=>J,toDecimal:()=>Y});var y=ge(require("big.js"));y.default.NE=-18;function Y(e,t,r){let n=(0,y.default)(e.toString().replace(/[^0-9]/g,"")),o=(0,y.default)(10).pow(t);return n.div(o).round(t,r).toString()}function J(e,t){if(typeof e=="bigint")return e;let r=(0,y.default)(10).pow(t),n=(0,y.default)(e).mul(r);return BigInt(n.toFixed(0,y.default.roundDown))}function be(e){return BigInt(e.round(0,y.default.roundDown).toFixed(0))}function xe(e,t,r){let n=Y(e,t);return J(n.toString(),r)}function Ce(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var k={};l(k,{enumPath:()=>ve});function ve(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={};l(L,{ERC20:()=>_});var _=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 K={};l(K,{H160:()=>N,isEvmAccount:()=>Q,isEvmAddress:()=>Z,isSs58Address:()=>ee});var C=require("polkadot-api"),O=require("@polkadot-api/utils"),g=require("buffer");var M="ETH\0";function Q(e){if(!e)return!1;try{let t=(0,C.AccountId)().enc(e),r=g.Buffer.from(M);return g.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function Z(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function ee(e){try{return(0,C.AccountId)(63).enc(e),!0}catch{return!1}}var N=class e{static toAccount=t=>{let r=g.Buffer.from(t.slice(2),"hex"),n=g.Buffer.from(M),o=Uint8Array.from(g.Buffer.concat([n,r,g.Buffer.alloc(8)])),i=(0,O.toHex)(o);return(0,C.AccountId)(63).dec(i)};static fromAccount=t=>{let r=(0,C.AccountId)().enc(t),n=g.Buffer.from(M),o=r.slice(n.length,-8);return"0x"+g.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,C.AccountId)().enc(t).slice(0,20);return(0,O.toHex)(n)};static fromAny=t=>{if(Z(t))return t;if(Q(t))return e.fromAccount(t);if(ee(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var T={};l(T,{assertHexLen:()=>we,ensureHexPrefix:()=>re,hexNormalize:()=>Ee,isHex:()=>te,stripHexPrefix:()=>Pe});var Ae=/^0x[0-9a-fA-F]*$/;function te(e,t=!1){return e==="0x"?!0:!Ae.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function Pe(e){return e.startsWith("0x")?e.slice(2):e}function re(e){return e.startsWith("0x")?e:`0x${e}`}function Ee(e){return re(e.toLowerCase())}function we(e,t){if(!te(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var D={};l(D,{logger:()=>Ie});var B={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function A(e){return e.padEnd(11)}var P={TRACE:A("[GC][TRACE]"),DEBUG:A("[GC][DEBUG]"),INFO:A("[GC][INFO]"),WARN:A("[GC][WARN]"),ERROR:A("[GC][ERROR]")};function Be(){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 E(e){let t=Be();return B[e]>=B[t]}var Ie={trace(...e){E("trace")&&console.debug(P.TRACE,...e)},debug(...e){E("debug")&&console.debug(P.DEBUG,...e)},info(...e){E("info")&&console.info(P.INFO,...e)},warn(...e){E("warn")&&console.warn(P.WARN,...e)},error(...e){if(!E("error"))return;e.some(r=>r instanceof Error)?console.error(P.ERROR,...e):this.warn(...e)}};var U={};l(U,{ErrorDecoder:()=>Se});var I=require("@polkadot-api/substrate-bindings");function Se(e){let{metadata:t}=I.metadata.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(s=>[s.index,s])),i=new Map(n.map(s=>[s.id,s]));return{decode(s,c){let f=o.get(s);if(!f?.errors)return;let h=i.get(f.errors);if(!h||h.def.tag!=="variant")return;let v=I.u32.dec(c),p=h.def.value.find(q=>q.index===v);if(p)return{pallet:f.name,error:p.name,desc:p.docs[0]}}}}var W={};l(W,{encodeAssetId:()=>G,encodeLocation:()=>F,toAccountId32:()=>ne,toAccountKey20:()=>oe,transform:()=>u});var b=require("polkadot-api"),ne=e=>{let t=(0,b.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:b.FixedSizeBinary.fromBytes(t)}}},oe=e=>({type:"AccountKey20",value:{network:void 0,key:b.FixedSizeBinary.fromHex(e)}}),u=e=>{if(Array.isArray(e))return e.map(u);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=oe(n.key);return n.network&&(o.value.network=u(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=ne(n.id);return n.network&&(o.value.network=u(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?b.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?u(n[0]):n.map(u)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:u(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=u(o)}return r}}else return e};function F(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:u(r)}}function G(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?u(e):e}var $={};l($,{convertToId:()=>Re});var ie=require("buffer");function Re(e){let r=ie.Buffer.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}var se=require("polkadot-api"),ae=require("polkadot-api/ws-provider"),ce=require("lru-cache");var m=require("rxjs"),a=require("rxjs/operators");function j(e,{intervalMs:t=5e3,timeoutMs:r=5e3,staleThreshold:n=3,initialDelayMs:o=0}={}){let i=c=>(0,m.defer)(()=>(0,m.from)(e._request("chain_getHeader",[]))).pipe((0,a.timeout)({first:r}),(0,a.map)(f=>{let h=parseInt(f.number,16),p=c.blockNumber!==void 0&&h<=c.blockNumber?c.staleCount+1:0;return{state:p>=n?"stale":"healthy",blockNumber:h,staleCount:p,delayMs:t}}),(0,a.catchError)(()=>{let f=c.staleCount+1;return(0,m.of)({state:f>=n?"stale":"healthy",staleCount:f,delayMs:t})}));return(0,m.of)({state:"healthy",staleCount:0,delayMs:o}).pipe((0,a.expand)(c=>(0,m.timer)(c.delayMs).pipe((0,a.switchMap)(()=>i(c)))),(0,a.skip)(1),(0,a.map)(c=>c.state),(0,a.distinctUntilChanged)(),(0,a.shareReplay)({bufferSize:1,refCount:!0}))}var X=class e{static _instance=new e;_cache=new ce.LRUCache({max:40});_metadataCache;constructor(){if(e._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");e._instance=this}static getInstance(){return e._instance}configureMetadataCache(t){this._metadataCache=t}createCacheKey(t){return t.join(",")}findCacheKey(t){let r=t.find(o=>this._cache.has(o));if(r)return r;let n=this.createCacheKey(t);return this._cache.has(n)?n:null}createClient(t,r){let n=(0,ae.getWsProvider)(t,r?.wsProviderOpts),o=(0,se.createClient)(n,this._metadataCache),i=this.createCacheKey(t);console.log(`Created PAPI client for ${i}`);let s={client:o,provider:n,endpoints:t,currentEndpointIndex:0};return this._cache.set(i,s,{noDisposeOnSet:!0}),r?.probeConfig?.enabled!==!1&&this.startHealthProbe(s,r?.probeConfig),o}api(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);return o?this._cache.get(o).client:this.createClient(n,r)}release(){for(let[t,r]of this._cache.entries())this.stopHealthProbe(r),console.log("Releasing "+t),r.client.destroy();this._cache.clear()}configureHealthProbe(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);if(o){let i=this._cache.get(o);this.stopHealthProbe(i),r.enabled!==!1&&this.startHealthProbe(i,r)}}startHealthProbe(t,r={}){let n=o=>{if(t.endpoints.length>1){let i=(t.currentEndpointIndex+1)%t.endpoints.length,s=t.endpoints[i];console.log(`${o} on ${t.endpoints[t.currentEndpointIndex]}, switching to ${s}`),t.provider.switch(s),t.currentEndpointIndex=i,this.stopHealthProbe(t),this.startHealthProbe(t,{...r,initialDelayMs:r.intervalMs??5e3})}};t.probeSubscription=j(t.client,r).subscribe({next:o=>{o==="stale"&&n("RPC stale")}})}stopHealthProbe(t){t.probeSubscription&&(t.probeSubscription.unsubscribe(),t.probeSubscription=void 0)}getWs(t){let r=typeof t=="string"?t.split(","):t,n=this.findCacheKey(r);if(n)return this._cache.get(n)?.provider}};function He(e){return e.replace(/^(ws)(s)?:\/\//,(t,r,n)=>n?"https://":"http://")}var V=new Map;async function ke(e,t){let r=V.get(e);if(r!==void 0)return r;try{let n=await fetch(e,{signal:t,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!n.ok)return!1;let i=(await n.json())?.result?.methods??[];if(i.includes("dev_newBlock"))return V.set(e,!0),!0;let s=!i.includes("chainHead_v1_follow");return V.set(e,s),s}catch{return!1}}0&&(module.exports={HYDRATION_SS58_PREFIX,RUNTIME_DECIMALS,SubstrateApis,acc,big,blockProbe$,detectLegacyRpc,encodeAssetId,encodeLocation,enums,erc20,h160,hex,log,meta,transform,wsToHttp,xc,xcm});
1
+ "use strict";var ue=Object.create;var w=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var le=Object.getOwnPropertyNames;var de=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var l=(e,t)=>{for(var r in t)w(e,r,{get:t[r],enumerable:!0})},q=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of le(t))!pe.call(e,o)&&o!==r&&w(e,o,{get:()=>t[o],enumerable:!(n=fe(t,o))||n.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?ue(de(e)):{},q(t||!e||!e.__esModule?w(r,"default",{value:e,enumerable:!0}):r,e)),me=e=>q(w({},"__esModule",{value:!0}),e);var _e={};l(_e,{HYDRATION_SS58_PREFIX:()=>I,RUNTIME_DECIMALS:()=>Oe,SubstrateApis:()=>z,acc:()=>H,big:()=>R,blockProbe$:()=>j,detectLegacyRpc:()=>ke,encodeAssetId:()=>W,encodeLocation:()=>G,enums:()=>k,erc20:()=>L,h160:()=>K,hex:()=>T,log:()=>D,meta:()=>U,transform:()=>u,wsToHttp:()=>Re,xc:()=>$,xcm:()=>F});module.exports=me(_e);var Oe=18,I=63;var H={};l(H,{getMultilocationDerivatedAccount:()=>he,getSovereignAccounts:()=>ye});var d=require("@polkadot-api/substrate-bindings"),b=require("@polkadot-api/utils");function he(e,t,r,n=!1){let o=t.length===42,i=o?"AccountKey20":"AccountId32",s;if(o)s=(0,b.fromHex)(t.slice(2));else{let p=(0,d.getSs58AddressInfo)(t);if(!p.isValid)throw new Error("Invalid SS58 address");s=p.publicKey}let c="SiblingChain";r==0&&e?c="ChildChain":r==1&&!e&&(c="ParentChain");let f=d.compactNumber.enc,h=new Uint8Array([...new TextEncoder().encode(c),...e?f(e):[],...f(i.length+(o?20:32)),...new TextEncoder().encode(i),...s]),C=(0,d.Blake2256)(h);return n?(0,b.toHex)(C.slice(0,20)):(0,d.AccountId)().dec(C)}function ye(e){let t=d.u32.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=(0,b.toHex)(new Uint8Array([...r,...t])).padEnd(66,"0"),i=(0,b.toHex)(new Uint8Array([...n,...t])).padEnd(66,"0"),s=i.slice(0,42);return{generic:i,moonbeam:s,relay:o}}var R={};l(R,{asBigInt:()=>be,convertDecimals:()=>xe,pow10:()=>Ce,toBigInt:()=>J,toDecimal:()=>Y});var y=ge(require("big.js"));y.default.NE=-18;function Y(e,t,r){let n=(0,y.default)(e.toString().replace(/[^0-9]/g,"")),o=(0,y.default)(10).pow(t);return n.div(o).round(t,r).toString()}function J(e,t){if(typeof e=="bigint")return e;let r=(0,y.default)(10).pow(t),n=(0,y.default)(e).mul(r);return BigInt(n.toFixed(0,y.default.roundDown))}function be(e){return BigInt(e.round(0,y.default.roundDown).toFixed(0))}function xe(e,t,r){let n=Y(e,t);return J(n.toString(),r)}function Ce(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var k={};l(k,{enumPath:()=>ve});function ve(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={};l(L,{ERC20:()=>_});var _=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 K={};l(K,{H160:()=>N,isEvmAccount:()=>Q,isEvmAddress:()=>Z,isSs58Address:()=>ee});var x=require("polkadot-api"),O=require("@polkadot-api/utils"),g=require("buffer");var M="ETH\0";function Q(e){if(!e)return!1;try{let t=(0,x.AccountId)().enc(e),r=g.Buffer.from(M);return g.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function Z(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function ee(e){try{return(0,x.AccountId)(63).enc(e),!0}catch{return!1}}var N=class e{static toAccount=t=>{let r=g.Buffer.from(t.slice(2),"hex"),n=g.Buffer.from(M),o=Uint8Array.from(g.Buffer.concat([n,r,g.Buffer.alloc(8)])),i=(0,O.toHex)(o);return(0,x.AccountId)(63).dec(i)};static fromAccount=t=>{let r=(0,x.AccountId)().enc(t),n=g.Buffer.from(M),o=r.slice(n.length,-8);return"0x"+g.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,x.AccountId)().enc(t).slice(0,20);return(0,O.toHex)(n)};static fromAny=t=>{if(Z(t))return t;if(Q(t))return e.fromAccount(t);if(ee(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var T={};l(T,{assertHexLen:()=>we,ensureHexPrefix:()=>re,hexNormalize:()=>Ee,isHex:()=>te,stripHexPrefix:()=>Pe});var Ae=/^0x[0-9a-fA-F]*$/;function te(e,t=!1){return e==="0x"?!0:!Ae.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function Pe(e){return e.startsWith("0x")?e.slice(2):e}function re(e){return e.startsWith("0x")?e:`0x${e}`}function Ee(e){return re(e.toLowerCase())}function we(e,t){if(!te(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var D={};l(D,{logger:()=>Se});var B={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function v(e){return e.padEnd(11)}var A={TRACE:v("[GC][TRACE]"),DEBUG:v("[GC][DEBUG]"),INFO:v("[GC][INFO]"),WARN:v("[GC][WARN]"),ERROR:v("[GC][ERROR]")};function Be(){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 P(e){let t=Be();return B[e]>=B[t]}var Se={trace(...e){P("trace")&&console.debug(A.TRACE,...e)},debug(...e){P("debug")&&console.debug(A.DEBUG,...e)},info(...e){P("info")&&console.info(A.INFO,...e)},warn(...e){P("warn")&&console.warn(A.WARN,...e)},error(...e){if(!P("error"))return;e.some(r=>r instanceof Error)?console.error(A.ERROR,...e):this.warn(...e)}};var U={};l(U,{ErrorDecoder:()=>Ie});var S=require("@polkadot-api/substrate-bindings");function Ie(e){let{metadata:t}=S.metadata.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(s=>[s.index,s])),i=new Map(n.map(s=>[s.id,s]));return{decode(s,c){let f=o.get(s);if(!f?.errors)return;let h=i.get(f.errors);if(!h||h.def.tag!=="variant")return;let C=S.u32.dec(c),p=h.def.value.find(V=>V.index===C);if(p)return{pallet:f.name,error:p.name,desc:p.docs[0]}}}}var F={};l(F,{encodeAssetId:()=>W,encodeLocation:()=>G,toAccountId32:()=>ne,toAccountKey20:()=>oe,transform:()=>u});var E=require("polkadot-api"),ne=e=>{let t=(0,E.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:E.Binary.toHex(t)}}},oe=e=>({type:"AccountKey20",value:{network:void 0,key:e}}),u=e=>{if(Array.isArray(e))return e.map(u);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=oe(n.key);return n.network&&(o.value.network=u(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=ne(n.id);return n.network&&(o.value.network=u(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?n.data:E.Binary.toHex(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?u(n[0]):n.map(u)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:u(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=u(o)}return r}}else return e};function G(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:u(r)}}function W(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?u(e):e}var $={};l($,{convertToId:()=>He});var ie=require("buffer");function He(e){let r=ie.Buffer.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}var se=require("polkadot-api"),ae=require("polkadot-api/ws"),ce=require("lru-cache");var m=require("rxjs"),a=require("rxjs/operators");function j(e,{intervalMs:t=5e3,timeoutMs:r=5e3,staleThreshold:n=3,initialDelayMs:o=0}={}){let i=c=>(0,m.defer)(()=>(0,m.from)(e._request("chain_getHeader",[]))).pipe((0,a.timeout)({first:r}),(0,a.map)(f=>{let h=parseInt(f.number,16),p=c.blockNumber!==void 0&&h<=c.blockNumber?c.staleCount+1:0;return{state:p>=n?"stale":"healthy",blockNumber:h,staleCount:p,delayMs:t}}),(0,a.catchError)(()=>{let f=c.staleCount+1;return(0,m.of)({state:f>=n?"stale":"healthy",staleCount:f,delayMs:t})}));return(0,m.of)({state:"healthy",staleCount:0,delayMs:o}).pipe((0,a.expand)(c=>(0,m.timer)(c.delayMs).pipe((0,a.switchMap)(()=>i(c)))),(0,a.skip)(1),(0,a.map)(c=>c.state),(0,a.distinctUntilChanged)(),(0,a.shareReplay)({bufferSize:1,refCount:!0}))}var z=class e{static _instance=new e;_cache=new ce.LRUCache({max:40});_metadataCache;constructor(){if(e._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");e._instance=this}static getInstance(){return e._instance}configureMetadataCache(t){this._metadataCache=t}createCacheKey(t){return t.join(",")}findCacheKey(t){let r=t.find(o=>this._cache.has(o));if(r)return r;let n=this.createCacheKey(t);return this._cache.has(n)?n:null}createClient(t,r){let n=(0,ae.getWsProvider)(t,r?.wsProviderOpts),o=(0,se.createClient)(n,this._metadataCache),i=this.createCacheKey(t);console.log(`Created PAPI client for ${i}`);let s={client:o,provider:n,endpoints:t,currentEndpointIndex:0};return this._cache.set(i,s,{noDisposeOnSet:!0}),r?.probeConfig?.enabled!==!1&&this.startHealthProbe(s,r?.probeConfig),o}api(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);return o?this._cache.get(o).client:this.createClient(n,r)}release(){for(let[t,r]of this._cache.entries())this.stopHealthProbe(r),console.log("Releasing "+t),r.client.destroy();this._cache.clear()}configureHealthProbe(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);if(o){let i=this._cache.get(o);this.stopHealthProbe(i),r.enabled!==!1&&this.startHealthProbe(i,r)}}startHealthProbe(t,r={}){let n=o=>{if(t.endpoints.length>1){let i=(t.currentEndpointIndex+1)%t.endpoints.length,s=t.endpoints[i];console.log(`${o} on ${t.endpoints[t.currentEndpointIndex]}, switching to ${s}`),t.provider.switch(s),t.currentEndpointIndex=i,this.stopHealthProbe(t),this.startHealthProbe(t,{...r,initialDelayMs:r.intervalMs??5e3})}};t.probeSubscription=j(t.client,r).subscribe({next:o=>{o==="stale"&&n("RPC stale")}})}stopHealthProbe(t){t.probeSubscription&&(t.probeSubscription.unsubscribe(),t.probeSubscription=void 0)}getWs(t){let r=typeof t=="string"?t.split(","):t,n=this.findCacheKey(r);if(n)return this._cache.get(n)?.provider}};function Re(e){return e.replace(/^(ws)(s)?:\/\//,(t,r,n)=>n?"https://":"http://")}var X=new Map;async function ke(e,t){let r=X.get(e);if(r!==void 0)return r;try{let n=await fetch(e,{signal:t,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!n.ok)return!1;let i=(await n.json())?.result?.methods??[];if(i.includes("dev_newBlock"))return X.set(e,!0),!0;let s=!i.includes("chainHead_v1_follow");return X.set(e,s),s}catch{return!1}}0&&(module.exports={HYDRATION_SS58_PREFIX,RUNTIME_DECIMALS,SubstrateApis,acc,big,blockProbe$,detectLegacyRpc,encodeAssetId,encodeLocation,enums,erc20,h160,hex,log,meta,transform,wsToHttp,xc,xcm});
package/build/index.mjs CHANGED
@@ -1 +1 @@
1
- var te=Object.defineProperty;var f=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})};var Fe=18,v=63;var S={};f(S,{getMultilocationDerivatedAccount:()=>ce,getSovereignAccounts:()=>ue});import{AccountId as re,Blake2256 as ne,compactNumber as oe,getSs58AddressInfo as ie,u32 as se}from"@polkadot-api/substrate-bindings";import{toHex as A,fromHex as ae}from"@polkadot-api/utils";function ce(e,t,r,n=!1){let o=t.length===42,i=o?"AccountKey20":"AccountId32",s;if(o)s=ae(t.slice(2));else{let l=ie(t);if(!l.isValid)throw new Error("Invalid SS58 address");s=l.publicKey}let a="SiblingChain";r==0&&e?a="ChildChain":r==1&&!e&&(a="ParentChain");let c=oe.enc,d=new Uint8Array([...new TextEncoder().encode(a),...e?c(e):[],...c(i.length+(o?20:32)),...new TextEncoder().encode(i),...s]),m=ne(d);return n?A(m.slice(0,20)):re().dec(m)}function ue(e){let t=se.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=A(new Uint8Array([...r,...t])).padEnd(66,"0"),i=A(new Uint8Array([...n,...t])).padEnd(66,"0"),s=i.slice(0,42);return{generic:i,moonbeam:s,relay:o}}var k={};f(k,{asBigInt:()=>fe,convertDecimals:()=>le,pow10:()=>de,toBigInt:()=>H,toDecimal:()=>R});import g from"big.js";g.NE=-18;function R(e,t,r){let n=g(e.toString().replace(/[^0-9]/g,"")),o=g(10).pow(t);return n.div(o).round(t,r).toString()}function H(e,t){if(typeof e=="bigint")return e;let r=g(10).pow(t),n=g(e).mul(r);return BigInt(n.toFixed(0,g.roundDown))}function fe(e){return BigInt(e.round(0,g.roundDown).toFixed(0))}function le(e,t,r){let n=R(e,t);return H(n.toString(),r)}function de(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var _={};f(_,{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 L={};f(L,{ERC20:()=>P});var P=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={};f(T,{H160:()=>w,isEvmAccount:()=>M,isEvmAddress:()=>N,isSs58Address:()=>K});import{AccountId as h}from"polkadot-api";import{toHex as O}from"@polkadot-api/utils";import{Buffer as p}from"buffer";var E="ETH\0";function M(e){if(!e)return!1;try{let t=h().enc(e),r=p.from(E);return p.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function N(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function K(e){try{return h(63).enc(e),!0}catch{return!1}}var w=class e{static toAccount=t=>{let r=p.from(t.slice(2),"hex"),n=p.from(E),o=Uint8Array.from(p.concat([n,r,p.alloc(8)])),i=O(o);return h(63).dec(i)};static fromAccount=t=>{let r=h().enc(t),n=p.from(E),o=r.slice(n.length,-8);return"0x"+p.from(o).toString("hex")};static fromSS58=t=>{let n=h().enc(t).slice(0,20);return O(n)};static fromAny=t=>{if(N(t))return t;if(M(t))return e.fromAccount(t);if(K(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var F={};f(F,{assertHexLen:()=>ye,ensureHexPrefix:()=>U,hexNormalize:()=>he,isHex:()=>D,stripHexPrefix:()=>me});var ge=/^0x[0-9a-fA-F]*$/;function D(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 U(e){return e.startsWith("0x")?e:`0x${e}`}function he(e){return U(e.toLowerCase())}function ye(e,t){if(!D(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var G={};f(G,{logger:()=>xe});var C={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function y(e){return e.padEnd(11)}var b={TRACE:y("[GC][TRACE]"),DEBUG:y("[GC][DEBUG]"),INFO:y("[GC][INFO]"),WARN:y("[GC][WARN]"),ERROR:y("[GC][ERROR]")};function be(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in C)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in C)return e}return"silent"}function x(e){let t=be();return C[e]>=C[t]}var xe={trace(...e){x("trace")&&console.debug(b.TRACE,...e)},debug(...e){x("debug")&&console.debug(b.DEBUG,...e)},info(...e){x("info")&&console.info(b.INFO,...e)},warn(...e){x("warn")&&console.warn(b.WARN,...e)},error(...e){if(!x("error"))return;e.some(r=>r instanceof Error)?console.error(b.ERROR,...e):this.warn(...e)}};var W={};f(W,{ErrorDecoder:()=>Ae});import{metadata as Ce,u32 as ve}from"@polkadot-api/substrate-bindings";function Ae(e){let{metadata:t}=Ce.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(s=>[s.index,s])),i=new Map(n.map(s=>[s.id,s]));return{decode(s,a){let c=o.get(s);if(!c?.errors)return;let d=i.get(c.errors);if(!d||d.def.tag!=="variant")return;let m=ve.dec(a),l=d.def.value.find(I=>I.index===m);if(l)return{pallet:c.name,error:l.name,desc:l.docs[0]}}}}var z={};f(z,{encodeAssetId:()=>q,encodeLocation:()=>V,toAccountId32:()=>j,toAccountKey20:()=>X,transform:()=>u});import{AccountId as Pe,Binary as Ee,FixedSizeBinary as $}from"polkadot-api";var j=e=>{let t=Pe().enc(e);return{type:"AccountId32",value:{network:void 0,id:$.fromBytes(t)}}},X=e=>({type:"AccountKey20",value:{network:void 0,key:$.fromHex(e)}}),u=e=>{if(Array.isArray(e))return e.map(u);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=u(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=j(n.id);return n.network&&(o.value.network=u(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?u(n[0]):n.map(u)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:u(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=u(o)}return r}}else return e};function V(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:u(r)}}function q(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?u(e):e}var Y={};f(Y,{convertToId:()=>Be});import{Buffer as we}from"buffer";function Be(e){let r=we.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}import{createClient as Ke}from"polkadot-api";import{getWsProvider as Te}from"polkadot-api/ws-provider";import{LRUCache as De}from"lru-cache";import{defer as Ie,from as Se,of as J,timer as Re}from"rxjs";import{catchError as He,distinctUntilChanged as ke,expand as _e,map as Q,shareReplay as Le,skip as Oe,switchMap as Me,timeout as Ne}from"rxjs/operators";function Z(e,{intervalMs:t=5e3,timeoutMs:r=5e3,staleThreshold:n=3,initialDelayMs:o=0}={}){let i=a=>Ie(()=>Se(e._request("chain_getHeader",[]))).pipe(Ne({first:r}),Q(c=>{let d=parseInt(c.number,16),l=a.blockNumber!==void 0&&d<=a.blockNumber?a.staleCount+1:0;return{state:l>=n?"stale":"healthy",blockNumber:d,staleCount:l,delayMs:t}}),He(()=>{let c=a.staleCount+1;return J({state:c>=n?"stale":"healthy",staleCount:c,delayMs:t})}));return J({state:"healthy",staleCount:0,delayMs:o}).pipe(_e(a=>Re(a.delayMs).pipe(Me(()=>i(a)))),Oe(1),Q(a=>a.state),ke(),Le({bufferSize:1,refCount:!0}))}var ee=class e{static _instance=new e;_cache=new De({max:40});_metadataCache;constructor(){if(e._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");e._instance=this}static getInstance(){return e._instance}configureMetadataCache(t){this._metadataCache=t}createCacheKey(t){return t.join(",")}findCacheKey(t){let r=t.find(o=>this._cache.has(o));if(r)return r;let n=this.createCacheKey(t);return this._cache.has(n)?n:null}createClient(t,r){let n=Te(t,r?.wsProviderOpts),o=Ke(n,this._metadataCache),i=this.createCacheKey(t);console.log(`Created PAPI client for ${i}`);let s={client:o,provider:n,endpoints:t,currentEndpointIndex:0};return this._cache.set(i,s,{noDisposeOnSet:!0}),r?.probeConfig?.enabled!==!1&&this.startHealthProbe(s,r?.probeConfig),o}api(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);return o?this._cache.get(o).client:this.createClient(n,r)}release(){for(let[t,r]of this._cache.entries())this.stopHealthProbe(r),console.log("Releasing "+t),r.client.destroy();this._cache.clear()}configureHealthProbe(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);if(o){let i=this._cache.get(o);this.stopHealthProbe(i),r.enabled!==!1&&this.startHealthProbe(i,r)}}startHealthProbe(t,r={}){let n=o=>{if(t.endpoints.length>1){let i=(t.currentEndpointIndex+1)%t.endpoints.length,s=t.endpoints[i];console.log(`${o} on ${t.endpoints[t.currentEndpointIndex]}, switching to ${s}`),t.provider.switch(s),t.currentEndpointIndex=i,this.stopHealthProbe(t),this.startHealthProbe(t,{...r,initialDelayMs:r.intervalMs??5e3})}};t.probeSubscription=Z(t.client,r).subscribe({next:o=>{o==="stale"&&n("RPC stale")}})}stopHealthProbe(t){t.probeSubscription&&(t.probeSubscription.unsubscribe(),t.probeSubscription=void 0)}getWs(t){let r=typeof t=="string"?t.split(","):t,n=this.findCacheKey(r);if(n)return this._cache.get(n)?.provider}};function mt(e){return e.replace(/^(ws)(s)?:\/\//,(t,r,n)=>n?"https://":"http://")}var B=new Map;async function ht(e,t){let r=B.get(e);if(r!==void 0)return r;try{let n=await fetch(e,{signal:t,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!n.ok)return!1;let i=(await n.json())?.result?.methods??[];if(i.includes("dev_newBlock"))return B.set(e,!0),!0;let s=!i.includes("chainHead_v1_follow");return B.set(e,s),s}catch{return!1}}export{v as HYDRATION_SS58_PREFIX,Fe as RUNTIME_DECIMALS,ee as SubstrateApis,S as acc,k as big,Z as blockProbe$,ht as detectLegacyRpc,q as encodeAssetId,V as encodeLocation,_ as enums,L as erc20,T as h160,F as hex,G as log,W as meta,u as transform,mt as wsToHttp,Y as xc,z as xcm};
1
+ var te=Object.defineProperty;var f=(e,t)=>{for(var r in t)te(e,r,{get:t[r],enumerable:!0})};var Ue=18,v=63;var I={};f(I,{getMultilocationDerivatedAccount:()=>ce,getSovereignAccounts:()=>ue});import{AccountId as re,Blake2256 as ne,compactNumber as oe,getSs58AddressInfo as ie,u32 as se}from"@polkadot-api/substrate-bindings";import{toHex as A,fromHex as ae}from"@polkadot-api/utils";function ce(e,t,r,n=!1){let o=t.length===42,i=o?"AccountKey20":"AccountId32",s;if(o)s=ae(t.slice(2));else{let l=ie(t);if(!l.isValid)throw new Error("Invalid SS58 address");s=l.publicKey}let a="SiblingChain";r==0&&e?a="ChildChain":r==1&&!e&&(a="ParentChain");let c=oe.enc,d=new Uint8Array([...new TextEncoder().encode(a),...e?c(e):[],...c(i.length+(o?20:32)),...new TextEncoder().encode(i),...s]),m=ne(d);return n?A(m.slice(0,20)):re().dec(m)}function ue(e){let t=se.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=A(new Uint8Array([...r,...t])).padEnd(66,"0"),i=A(new Uint8Array([...n,...t])).padEnd(66,"0"),s=i.slice(0,42);return{generic:i,moonbeam:s,relay:o}}var k={};f(k,{asBigInt:()=>fe,convertDecimals:()=>le,pow10:()=>de,toBigInt:()=>R,toDecimal:()=>H});import g from"big.js";g.NE=-18;function H(e,t,r){let n=g(e.toString().replace(/[^0-9]/g,"")),o=g(10).pow(t);return n.div(o).round(t,r).toString()}function R(e,t){if(typeof e=="bigint")return e;let r=g(10).pow(t),n=g(e).mul(r);return BigInt(n.toFixed(0,g.roundDown))}function fe(e){return BigInt(e.round(0,g.roundDown).toFixed(0))}function le(e,t,r){let n=H(e,t);return R(n.toString(),r)}function de(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var _={};f(_,{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 L={};f(L,{ERC20:()=>P});var P=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={};f(T,{H160:()=>w,isEvmAccount:()=>M,isEvmAddress:()=>N,isSs58Address:()=>K});import{AccountId as h}from"polkadot-api";import{toHex as O}from"@polkadot-api/utils";import{Buffer as p}from"buffer";var E="ETH\0";function M(e){if(!e)return!1;try{let t=h().enc(e),r=p.from(E);return p.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function N(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function K(e){try{return h(63).enc(e),!0}catch{return!1}}var w=class e{static toAccount=t=>{let r=p.from(t.slice(2),"hex"),n=p.from(E),o=Uint8Array.from(p.concat([n,r,p.alloc(8)])),i=O(o);return h(63).dec(i)};static fromAccount=t=>{let r=h().enc(t),n=p.from(E),o=r.slice(n.length,-8);return"0x"+p.from(o).toString("hex")};static fromSS58=t=>{let n=h().enc(t).slice(0,20);return O(n)};static fromAny=t=>{if(N(t))return t;if(M(t))return e.fromAccount(t);if(K(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var G={};f(G,{assertHexLen:()=>ye,ensureHexPrefix:()=>U,hexNormalize:()=>he,isHex:()=>D,stripHexPrefix:()=>me});var ge=/^0x[0-9a-fA-F]*$/;function D(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 U(e){return e.startsWith("0x")?e:`0x${e}`}function he(e){return U(e.toLowerCase())}function ye(e,t){if(!D(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var W={};f(W,{logger:()=>xe});var C={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function y(e){return e.padEnd(11)}var b={TRACE:y("[GC][TRACE]"),DEBUG:y("[GC][DEBUG]"),INFO:y("[GC][INFO]"),WARN:y("[GC][WARN]"),ERROR:y("[GC][ERROR]")};function be(){if(typeof window<"u")try{let e=window.localStorage.getItem("gc.log");if(e&&e in C)return e}catch{}if(typeof process<"u"){let e=process.env.GC_LOG;if(e&&e in C)return e}return"silent"}function x(e){let t=be();return C[e]>=C[t]}var xe={trace(...e){x("trace")&&console.debug(b.TRACE,...e)},debug(...e){x("debug")&&console.debug(b.DEBUG,...e)},info(...e){x("info")&&console.info(b.INFO,...e)},warn(...e){x("warn")&&console.warn(b.WARN,...e)},error(...e){if(!x("error"))return;e.some(r=>r instanceof Error)?console.error(b.ERROR,...e):this.warn(...e)}};var F={};f(F,{ErrorDecoder:()=>Ae});import{metadata as Ce,u32 as ve}from"@polkadot-api/substrate-bindings";function Ae(e){let{metadata:t}=Ce.dec(e),{pallets:r,lookup:n}=t.value,o=new Map(r.map(s=>[s.index,s])),i=new Map(n.map(s=>[s.id,s]));return{decode(s,a){let c=o.get(s);if(!c?.errors)return;let d=i.get(c.errors);if(!d||d.def.tag!=="variant")return;let m=ve.dec(a),l=d.def.value.find(S=>S.index===m);if(l)return{pallet:c.name,error:l.name,desc:l.docs[0]}}}}var q={};f(q,{encodeAssetId:()=>V,encodeLocation:()=>X,toAccountId32:()=>j,toAccountKey20:()=>z,transform:()=>u});import{AccountId as Pe,Binary as $}from"polkadot-api";var j=e=>{let t=Pe().enc(e);return{type:"AccountId32",value:{network:void 0,id:$.toHex(t)}}},z=e=>({type:"AccountKey20",value:{network:void 0,key:e}}),u=e=>{if(Array.isArray(e))return e.map(u);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=z(n.key);return n.network&&(o.value.network=u(n.network)),o}if(r==="AccountId32"&&typeof n=="object"){let o=j(n.id);return n.network&&(o.value.network=u(n.network)),o}return r==="GeneralKey"&&typeof n=="object"&&"data"in n?{type:r,value:{length:n.length,data:typeof n.data=="string"?n.data:$.toHex(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?u(n[0]):n.map(u)}:typeof n=="string"?{type:r,value:{type:n}}:typeof n=="number"?{type:r,value:n}:{type:r,value:u(n)}}else{let r={};for(let n of t){let o=e[n];r[n]=u(o)}return r}}else return e};function X(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:u(r)}}function V(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?u(e):e}var Y={};f(Y,{convertToId:()=>we});import{Buffer as Ee}from"buffer";function we(e){let r=Ee.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}import{createClient as Ne}from"polkadot-api";import{getWsProvider as Ke}from"polkadot-api/ws";import{LRUCache as Te}from"lru-cache";import{defer as Be,from as Se,of as J,timer as Ie}from"rxjs";import{catchError as He,distinctUntilChanged as Re,expand as ke,map as Q,shareReplay as _e,skip as Le,switchMap as Oe,timeout as Me}from"rxjs/operators";function Z(e,{intervalMs:t=5e3,timeoutMs:r=5e3,staleThreshold:n=3,initialDelayMs:o=0}={}){let i=a=>Be(()=>Se(e._request("chain_getHeader",[]))).pipe(Me({first:r}),Q(c=>{let d=parseInt(c.number,16),l=a.blockNumber!==void 0&&d<=a.blockNumber?a.staleCount+1:0;return{state:l>=n?"stale":"healthy",blockNumber:d,staleCount:l,delayMs:t}}),He(()=>{let c=a.staleCount+1;return J({state:c>=n?"stale":"healthy",staleCount:c,delayMs:t})}));return J({state:"healthy",staleCount:0,delayMs:o}).pipe(ke(a=>Ie(a.delayMs).pipe(Oe(()=>i(a)))),Le(1),Q(a=>a.state),Re(),_e({bufferSize:1,refCount:!0}))}var ee=class e{static _instance=new e;_cache=new Te({max:40});_metadataCache;constructor(){if(e._instance)throw new Error("Use SubstrateApis.getInstance() instead of new.");e._instance=this}static getInstance(){return e._instance}configureMetadataCache(t){this._metadataCache=t}createCacheKey(t){return t.join(",")}findCacheKey(t){let r=t.find(o=>this._cache.has(o));if(r)return r;let n=this.createCacheKey(t);return this._cache.has(n)?n:null}createClient(t,r){let n=Ke(t,r?.wsProviderOpts),o=Ne(n,this._metadataCache),i=this.createCacheKey(t);console.log(`Created PAPI client for ${i}`);let s={client:o,provider:n,endpoints:t,currentEndpointIndex:0};return this._cache.set(i,s,{noDisposeOnSet:!0}),r?.probeConfig?.enabled!==!1&&this.startHealthProbe(s,r?.probeConfig),o}api(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);return o?this._cache.get(o).client:this.createClient(n,r)}release(){for(let[t,r]of this._cache.entries())this.stopHealthProbe(r),console.log("Releasing "+t),r.client.destroy();this._cache.clear()}configureHealthProbe(t,r){let n=typeof t=="string"?t.split(","):t,o=this.findCacheKey(n);if(o){let i=this._cache.get(o);this.stopHealthProbe(i),r.enabled!==!1&&this.startHealthProbe(i,r)}}startHealthProbe(t,r={}){let n=o=>{if(t.endpoints.length>1){let i=(t.currentEndpointIndex+1)%t.endpoints.length,s=t.endpoints[i];console.log(`${o} on ${t.endpoints[t.currentEndpointIndex]}, switching to ${s}`),t.provider.switch(s),t.currentEndpointIndex=i,this.stopHealthProbe(t),this.startHealthProbe(t,{...r,initialDelayMs:r.intervalMs??5e3})}};t.probeSubscription=Z(t.client,r).subscribe({next:o=>{o==="stale"&&n("RPC stale")}})}stopHealthProbe(t){t.probeSubscription&&(t.probeSubscription.unsubscribe(),t.probeSubscription=void 0)}getWs(t){let r=typeof t=="string"?t.split(","):t,n=this.findCacheKey(r);if(n)return this._cache.get(n)?.provider}};function mt(e){return e.replace(/^(ws)(s)?:\/\//,(t,r,n)=>n?"https://":"http://")}var B=new Map;async function ht(e,t){let r=B.get(e);if(r!==void 0)return r;try{let n=await fetch(e,{signal:t,method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:1,jsonrpc:"2.0",method:"rpc_methods",params:[]})});if(!n.ok)return!1;let i=(await n.json())?.result?.methods??[];if(i.includes("dev_newBlock"))return B.set(e,!0),!0;let s=!i.includes("chainHead_v1_follow");return B.set(e,s),s}catch{return!1}}export{v as HYDRATION_SS58_PREFIX,Ue as RUNTIME_DECIMALS,ee as SubstrateApis,I as acc,k as big,Z as blockProbe$,ht as detectLegacyRpc,V as encodeAssetId,X as encodeLocation,_ as enums,L as erc20,T as h160,G as hex,W as log,F as meta,u as transform,mt as wsToHttp,Y as xc,q as xcm};
@@ -1,5 +1,5 @@
1
1
  import { PolkadotClient } from 'polkadot-api';
2
- import { getWsProvider } from 'polkadot-api/ws-provider';
2
+ import { getWsProvider } from 'polkadot-api/ws';
3
3
  import { HealthProbeConfig } from './probe';
4
4
  export interface MetadataCache {
5
5
  getMetadata: (codeHash: string) => Promise<Uint8Array | null>;
@@ -1 +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});
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"),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});
@@ -1 +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};
1
+ import{createClient as M}from"polkadot-api";import{getWsProvider as k}from"polkadot-api/ws";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};
@@ -1 +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});
1
+ "use strict";var re=Object.create;var B=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)B(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&&B(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?B(r,"default",{value:e,enumerable:!0}):r,e)),ce=e=>M(B({},"__esModule",{value:!0}),e);var we={};c(we,{acc:()=>R,big:()=>S,encodeAssetId:()=>P,encodeLocation:()=>O,enums:()=>H,erc20:()=>k,h160:()=>T,hex:()=>U,log:()=>G,meta:()=>F,transform:()=>s,xc:()=>K,xcm:()=>_});module.exports=ce(we);var R={};c(R,{getMultilocationDerivatedAccount:()=>ue,getSovereignAccounts:()=>ae});var a=require("@polkadot-api/substrate-bindings"),g=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,g.fromHex)(t.slice(2));else{let p=(0,a.getSs58AddressInfo)(t);if(!p.isValid)throw new Error("Invalid SS58 address");i=p.publicKey}let y="SiblingChain";r==0&&e?y="ChildChain":r==1&&!e&&(y="ParentChain");let l=a.compactNumber.enc,x=new Uint8Array([...new TextEncoder().encode(y),...e?l(e):[],...l(u.length+(o?20:32)),...new TextEncoder().encode(u),...i]),w=(0,a.Blake2256)(x);return n?(0,g.toHex)(w.slice(0,20)):(0,a.AccountId)().dec(w)}function ae(e){let t=a.u32.enc(e),r=new TextEncoder().encode("para"),n=new TextEncoder().encode("sibl"),o=(0,g.toHex)(new Uint8Array([...r,...t])).padEnd(66,"0"),u=(0,g.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:()=>fe,convertDecimals:()=>de,pow10:()=>le,toBigInt:()=>z,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 z(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 fe(e){return BigInt(e.round(0,d.default.roundDown).toFixed(0))}function de(e,t,r){let n=X(e,t);return z(n.toString(),r)}function le(e){if(e<0)throw new Error(`pow10: negative exp ${e}`);return 10n**BigInt(e)}var H={};c(H,{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 k={};c(k,{ERC20:()=>L});var L=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:()=>W,isEvmAddress:()=>$,isSs58Address:()=>j});var m=require("polkadot-api"),C=require("@polkadot-api/utils"),f=require("buffer");var D="ETH\0";function W(e){if(!e)return!1;try{let t=(0,m.AccountId)().enc(e),r=f.Buffer.from(D);return f.Buffer.from(t.subarray(0,r.length)).equals(r)}catch{return!1}}function $(e){return!!/^0x[a-fA-F0-9]{40}$/.test(e)}function j(e){try{return(0,m.AccountId)(63).enc(e),!0}catch{return!1}}var N=class e{static toAccount=t=>{let r=f.Buffer.from(t.slice(2),"hex"),n=f.Buffer.from(D),o=Uint8Array.from(f.Buffer.concat([n,r,f.Buffer.alloc(8)])),u=(0,C.toHex)(o);return(0,m.AccountId)(63).dec(u)};static fromAccount=t=>{let r=(0,m.AccountId)().enc(t),n=f.Buffer.from(D),o=r.slice(n.length,-8);return"0x"+f.Buffer.from(o).toString("hex")};static fromSS58=t=>{let n=(0,m.AccountId)().enc(t).slice(0,20);return(0,C.toHex)(n)};static fromAny=t=>{if($(t))return t;if(W(t))return e.fromAccount(t);if(j(t))return e.fromSS58(t);throw new Error("Unknown address type")}};var U={};c(U,{assertHexLen:()=>xe,ensureHexPrefix:()=>Y,hexNormalize:()=>ye,isHex:()=>q,stripHexPrefix:()=>me});var ge=/^0x[0-9a-fA-F]*$/;function q(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(!q(e)||e.length-2!==t*2)throw new Error(`Expected 0x hex of ${t} bytes`)}var G={};c(G,{logger:()=>Ee});var v={all:0,trace:1,debug:2,info:3,warn:4,error:5,silent:6};function A(e){return e.padEnd(11)}var E={TRACE:A("[GC][TRACE]"),DEBUG:A("[GC][DEBUG]"),INFO:A("[GC][INFO]"),WARN:A("[GC][WARN]"),ERROR:A("[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(E.TRACE,...e)},debug(...e){b("debug")&&console.debug(E.DEBUG,...e)},info(...e){b("info")&&console.info(E.INFO,...e)},warn(...e){b("warn")&&console.warn(E.WARN,...e)},error(...e){if(!b("error"))return;e.some(r=>r instanceof Error)?console.error(E.ERROR,...e):this.warn(...e)}};var F={};c(F,{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,y){let l=o.get(i);if(!l?.errors)return;let x=u.get(l.errors);if(!x||x.def.tag!=="variant")return;let w=I.u32.dec(y),p=x.def.value.find(ee=>ee.index===w);if(p)return{pallet:l.name,error:p.name,desc:p.docs[0]}}}}var _={};c(_,{encodeAssetId:()=>P,encodeLocation:()=>O,toAccountId32:()=>J,toAccountKey20:()=>Q,transform:()=>s});var h=require("polkadot-api"),J=e=>{let t=(0,h.AccountId)().enc(e);return{type:"AccountId32",value:{network:void 0,id:h.Binary.toHex(t)}}},Q=e=>({type:"AccountKey20",value:{network:void 0,key: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"?n.data:h.Binary.toHex(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:()=>he});var Z=require("buffer");function he(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});
@@ -1 +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};
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 h,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?h(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=h(new Uint8Array([...r,...t])).padEnd(66,"0"),c=h(new Uint8Array([...n,...t])).padEnd(66,"0"),i=c.slice(0,42);return{generic:c,moonbeam:i,relay:o}}var H={};u(H,{asBigInt:()=>ie,convertDecimals:()=>se,pow10:()=>ce,toBigInt:()=>S,toDecimal:()=>R});import f from"big.js";f.NE=-18;function R(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 S(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 ie(e){return BigInt(e.round(0,f.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 L={};u(L,{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 k={};u(k,{ERC20:()=>w});var w=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 G={};u(G,{H160:()=>v,isEvmAccount:()=>N,isEvmAddress:()=>T,isSs58Address:()=>U});import{AccountId as m}from"polkadot-api";import{toHex as C}from"@polkadot-api/utils";import{Buffer as a}from"buffer";var B="ETH\0";function N(e){if(!e)return!1;try{let t=m().enc(e),r=a.from(B);return a.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=a.from(t.slice(2),"hex"),n=a.from(B),o=Uint8Array.from(a.concat([n,r,a.alloc(8)])),c=C(o);return m(63).dec(c)};static fromAccount=t=>{let r=m().enc(t),n=a.from(B),o=r.slice(n.length,-8);return"0x"+a.from(o).toString("hex")};static fromSS58=t=>{let n=m().enc(t).slice(0,20);return C(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:()=>F,stripHexPrefix:()=>fe});var ae=/^0x[0-9a-fA-F]*$/;function F(e,t=!1){return e==="0x"?!0:!ae.test(e)||!t&&e.length<4?!1:t||e.length%2===0}function fe(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(!F(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(q=>q.index===E);if(l)return{pallet:d.name,error:l.name,desc:l.docs[0]}}}}var $={};u($,{encodeAssetId:()=>W,encodeLocation:()=>V,toAccountId32:()=>X,toAccountKey20:()=>z,transform:()=>s});import{AccountId as Ae,Binary as M}from"polkadot-api";var X=e=>{let t=Ae().enc(e);return{type:"AccountId32",value:{network:void 0,id:M.toHex(t)}}},z=e=>({type:"AccountKey20",value:{network:void 0,key: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=z(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"?n.data:M.toHex(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 V(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 W(e){return e==null?e:typeof e=="string"?BigInt(e):typeof e=="object"&&!Array.isArray(e)?s(e):e}var j={};u(j,{convertToId:()=>be});import{Buffer as Ee}from"buffer";function be(e){let r=Ee.from(e.replace("0x",""),"hex").subarray(16);return r.readUIntBE(0,r.length)}export{I as acc,H as big,W as encodeAssetId,V as encodeLocation,L as enums,k as erc20,G as h160,P as hex,_ as log,K as meta,s as transform,j as xc,$ as xcm};
@@ -1,16 +1,16 @@
1
- import { Binary } from 'polkadot-api';
1
+ import { SizedHex } from 'polkadot-api';
2
2
  export declare const toAccountId32: (address: string) => {
3
3
  type: string;
4
4
  value: {
5
5
  network: undefined;
6
- id: Binary;
6
+ id: SizedHex<32>;
7
7
  };
8
8
  };
9
9
  export declare const toAccountKey20: (address: string) => {
10
10
  type: string;
11
11
  value: {
12
12
  network: undefined;
13
- key: Binary;
13
+ key: SizedHex<20>;
14
14
  };
15
15
  };
16
16
  export declare const transform: (obj: any) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/common",
3
- "version": "0.7.0",
3
+ "version": "0.8.0-pr311-1281cfa",
4
4
  "description": "Common utilities shared across Galactic SDK packages",
5
5
  "author": "GalacticCouncil",
6
6
  "repository": {
@@ -55,6 +55,6 @@
55
55
  "@types/big.js": "^6.2.2"
56
56
  },
57
57
  "peerDependencies": {
58
- "polkadot-api": "^1.23.3"
58
+ "polkadot-api": "^2.0.0"
59
59
  }
60
60
  }