@galacticcouncil/sdk-next 1.5.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/client/index.cjs +1 -1
- package/build/client/index.mjs +1 -1
- package/build/index.cjs +1 -1
- package/build/index.mjs +1 -1
- package/build/pool/index.cjs +1 -1
- package/build/pool/index.mjs +1 -1
- package/build/sor/index.cjs +1 -1
- package/build/sor/index.mjs +1 -1
- package/build/tx/index.cjs +1 -1
- package/build/tx/index.mjs +1 -1
- package/package.json +1 -1
package/build/client/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var M=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var R=(p,e)=>{for(var t in e)M(p,t,{get:e[t],enumerable:!0})},N=(p,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of I(e))!L.call(p,n)&&n!==t&&M(p,n,{get:()=>e[n],enumerable:!(s=O(e,n))||s.enumerable});return p};var z=p=>N(M({},"__esModule",{value:!0}),p);var $={};R($,{AssetClient:()=>S,BalanceClient:()=>x,ChainParams:()=>_});module.exports=z($);var k=require("polkadot-api");var T=require("@galacticcouncil/descriptors");var C=require("@galacticcouncil/common"),B=require("rxjs");var b=require("rxjs"),c=require("rxjs/operators");function v(p,{intervalMs:e=5e3,rpcTimeoutMs:t=1e4}={}){let s=()=>(0,b.defer)(()=>(0,b.from)(p._request("system_health",[]))).pipe((0,c.timeout)({first:t}),(0,c.map)(()=>"online"),(0,c.catchError)(()=>(0,b.of)("offline")));return(0,b.of)({state:"offline",delayMs:0}).pipe((0,c.expand)(a=>(0,b.timer)(a.delayMs).pipe((0,c.switchMap)(s),(0,c.map)(r=>({state:r,delayMs:e})))),(0,c.skip)(1),(0,c.map)(a=>a.state),(0,c.distinctUntilChanged)(),(0,c.shareReplay)({bufferSize:1,refCount:!0}))}var{logger:H}=C.log,P=class p{static instance=null;bestBlock$;finalizedBlock$;connection$;constructor(e){this.bestBlock$=this.watched("watcher(bestBlock)",e.getUnsafeApi().query.System.Number.watchValue({at:"best"}).pipe((0,B.map)(({value:t})=>t))),this.finalizedBlock$=this.watched("watcher(finalizedBlock)",e.finalizedBlock$),this.connection$=this.watched("watcher(connection)",v(e))}static getInstance(e){return this.instance||(this.instance=new p(e)),this.instance}watched(e,t){return t.pipe((0,B.tap)({error:s=>H.error(e,s)}),(0,B.shareReplay)({bufferSize:1,refCount:!0}))}};var h=class{client;api;apiNext;apiIce;watcher;at;constructor(e,t){this.client=e,this.api=this.client.getTypedApi(T.hydration),this.apiNext=this.client.getTypedApi(T.hydrationNext),this.apiIce=this.client.getTypedApi(T.hydrationIce),this.watcher=P.getInstance(this.client),this.at=t??"best"}};var V=require("polkadot-api/ws"),W=require("polkadot-api/logs-provider");var S=class extends h{SUPPORTED_TYPES=["StableSwap","Bond","Token","External","Erc20"];constructor(e){super(e)}async queryShares(){let t=await this.api.query.Stableswap.Pools.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryBonds(){let t=await this.api.query.Bonds.Bonds.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssets(){let t=await this.api.query.AssetRegistry.Assets.getEntries();return new Map(t.filter(({value:s})=>{let{asset_type:n}=s;return this.SUPPORTED_TYPES.includes(n.type)}).map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssetLocations(){let t=await this.api.query.AssetRegistry.AssetLocations.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async mapToken(e,t,s,n){let{name:a,asset_type:r,is_sufficient:i,existential_deposit:m}=t,{symbol:l,decimals:u}=s.get(e)??{};return{id:e,name:a?k.Binary.toText(a):void 0,symbol:l,decimals:u,icon:l,type:r.type,isSufficient:i,location:n,existentialDeposit:m}}async mapBond(e,t,s,n){let[a,r]=n,{asset_type:i,is_sufficient:m,existential_deposit:l}=t,{symbol:u,decimals:A}=await this.mapToken(a,t,s),f=Number(r),y=new Intl.DateTimeFormat("en-GB"),g=[u,"Bond",y.format(f)].join(" ");return{id:e,name:g,symbol:u+"b",decimals:A,icon:u,type:i.type,isSufficient:m,existentialDeposit:l,underlyingAssetId:a,maturity:f}}async mapShares(e,t,s,n){let{assets:a}=n,{name:r,symbol:i,asset_type:m,is_sufficient:l,existential_deposit:u}=t,A=await Promise.all(a.map(async g=>{let{symbol:E}=await this.mapToken(g,t,s);return[g,E]})),f=Object.fromEntries(A),y=Object.values(f);return{id:e,name:y.join(", "),symbol:i&&k.Binary.toText(i)||r&&k.Binary.toText(r),decimals:18,icon:y.join("/"),type:m.type,isSufficient:l,existentialDeposit:u,meta:f}}async mapExternal(e,t,s,n){let a=await this.mapToken(e,t,new Map,n),r=s?.find(i=>i.internalId===a.id);return r?{...a,decimals:r.decimals,name:r.name,symbol:r.symbol,icon:r.symbol,isWhiteListed:r.isWhiteListed}:a}parseMetadata(e){return new Map(Array.from(e,([t,s])=>[t,{symbol:s.symbol?k.Binary.toText(s.symbol):void 0,decimals:s.decimals}]))}async getSupported(e,t){let[s,n,a,r]=await Promise.all([this.queryAssets(),this.queryAssetLocations(),this.queryShares(),this.queryBonds()]),i=this.parseMetadata(s),m=[];for(let[l,u]of Array.from(s)){let A=n.get(l),{asset_type:f}=u,y;switch(f.type){case"Bond":let g=r.get(l);y=await this.mapBond(l,u,i,g);break;case"StableSwap":let E=a.get(l);y=await this.mapShares(l,u,i,E);break;case"External":y=await this.mapExternal(l,u,t,A);break;default:y=await this.mapToken(l,u,i,A)}m.push(y)}return e?m:m.filter(l=>this.isValidAsset(l))}isValidAsset(e){let t=Math.sign(e.decimals);return!!e.symbol&&(t===0||t===1)}};var D=require("@galacticcouncil/common"),d=require("rxjs"),o=require("rxjs/operators");var{logger:w}=D.log,x=class extends h{erc20Ids=null;constructor(e,t){super(e,t)}async getBalance(e,t){return t===0?this.getSystemBalance(e):this.getBalanceData(e,t)}async getSystemBalance(e){let t=this.api.query.System.Account,{data:s}=await t.getValue(e,{at:this.at});return this.getBreakdown(s)}async getTokenBalance(e,t){let n=await this.api.query.Tokens.Accounts.getValue(e,t,{at:this.at});return this.getBreakdown(n)}async getErc20Balance(e,t){return this.getBalanceData(e,t)}watchBalance(e){return(0,d.defer)(()=>{let t=this.watchSystemBalance(e),s=this.watchTokensBalance(e),n=this.watchErc20Balance(e);return(0,d.combineLatest)([t,s,n]).pipe((0,o.connect)(a=>(0,d.concat)(a.pipe((0,o.take)(1)),a.pipe((0,o.skip)(1),(0,o.debounceTime)(250)))))}).pipe((0,o.map)(t=>t.flat()),(0,o.startWith)([]),(0,o.bufferCount)(2,1),(0,o.map)(([t,s],n)=>n===0?s:this.getDeltas(t,s))).pipe((0,o.tap)({subscribe:()=>w.debug("balance: subscribe",e),error:t=>w.error("balance",t)}),(0,o.retry)({delay:1e3}))}watchSystemBalance(e){let t=this.api.query.System.Account;return(0,d.defer)(()=>t.watchValue(e,{at:"best"})).pipe((0,o.map)(({value:s})=>({id:0,balance:this.getBreakdown(s.data)})),(0,o.tap)({error:s=>w.error("balance(system)",s)}))}watchTokenBalance(e,t){let s=this.api.query.Tokens.Accounts;return(0,d.defer)(()=>s.watchValue(e,t,{at:"best"})).pipe((0,o.map)(({value:n})=>({id:t,balance:this.getBreakdown(n)})),(0,o.tap)({error:n=>w.error("balance(token)",n)}))}watchTokensBalance(e){let t=this.api.query.Tokens.Accounts;return(0,d.defer)(()=>t.watchEntries(e,{at:"best"})).pipe((0,o.distinctUntilChanged)((s,n)=>!n.deltas),(0,o.map)(({deltas:s})=>{let n=[];return s?.deleted.forEach(a=>{let[r,i]=a.args;n.push({id:i,balance:this.getBreakdown({free:0n,reserved:0n,frozen:0n})})}),s?.upserted.forEach(a=>{let[r,i]=a.args;n.push({id:i,balance:this.getBreakdown(a.value)})}),n}),(0,o.tap)({error:s=>w.error("balance(tokens)",s)}))}watchErc20Balance(e,t){let s=async()=>{if(this.erc20Ids)return this.erc20Ids;let a=await this.api.query.AssetRegistry.Assets.getEntries({at:"best"});return this.erc20Ids=a.filter(({value:r})=>r.asset_type.type==="Erc20").map(({keyArgs:r})=>{let[i]=r;return i}),this.erc20Ids},n=async a=>(await Promise.all(a.map(async i=>[i,await this.getBalanceData(e,i)]))).map(([i,m])=>({id:i,balance:m}));return(0,d.defer)(()=>(0,d.from)(t?Promise.resolve(t):s()).pipe((0,o.switchMap)(a=>this.watcher.bestBlock$.pipe((0,o.switchMap)(()=>(0,d.from)(n(a))))),(0,o.startWith)([]),(0,o.bufferCount)(2,1),(0,o.map)(([a,r],i)=>i===0?r.filter(m=>m.balance.total>0n):this.getDeltas(a,r)),(0,o.distinctUntilChanged)((a,r)=>r.length===0),(0,o.tap)({error:a=>w.error("balance(erc20)",a)})))}async getBalanceData(e,t){let s=await this.api.apis.CurrenciesApi.account(t,e,{at:this.at});return this.getBreakdown(s)}getBreakdown(e){let t=e.frozen-e.reserved,s=t>0n?t:0n,n=e.free>=s?e.free-s:0n,a=e.free+e.reserved;return{free:e.free,reserved:e.reserved,frozen:e.frozen,total:a,transferable:n}}getDeltas(e,t){let s=(a,r)=>a!==void 0&&r!==void 0&&a.transferable===r.transferable&&a.total===r.total,n=e.reduce((a,r)=>(a.set(r.id,r.balance),a),new Map);return t.filter(a=>!s(a.balance,n.get(a.id)))}};var _=class extends h{_minOrderBudget;_blockTime;constructor(e){super(e)}async getBlockTime(){if(this._blockTime===void 0){let e=await this.api.constants.Aura.SlotDuration();this._blockTime=Number(e)}return this._blockTime}async getMinOrderBudget(){return this._minOrderBudget===void 0&&(this._minOrderBudget=await this.api.constants.DCA.MinBudgetInNativeCurrency()),this._minOrderBudget}};0&&(module.exports={AssetClient,BalanceClient,ChainParams});
|
package/build/client/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import I from"buffer";typeof window<"u"&&(window.Buffer=I.Buffer);import{Binary as w}from"polkadot-api";import{hydration as J,hydrationNext as K,hydrationIce as Z}from"@galacticcouncil/descriptors";import{log as Y}from"@galacticcouncil/common";import{map as j,shareReplay as F,tap as G}from"rxjs";import{defer as L,from as R,of as _,timer as N}from"rxjs";import{catchError as z,distinctUntilChanged as H,expand as V,map as k,shareReplay as W,skip as $,switchMap as Q,timeout as U}from"rxjs/operators";function
|
|
1
|
+
import I from"buffer";typeof window<"u"&&(window.Buffer=I.Buffer);import{Binary as w}from"polkadot-api";import{hydration as J,hydrationNext as K,hydrationIce as Z}from"@galacticcouncil/descriptors";import{log as Y}from"@galacticcouncil/common";import{map as j,shareReplay as F,tap as G}from"rxjs";import{defer as L,from as R,of as _,timer as N}from"rxjs";import{catchError as z,distinctUntilChanged as H,expand as V,map as k,shareReplay as W,skip as $,switchMap as Q,timeout as U}from"rxjs/operators";function E(u,{intervalMs:e=5e3,rpcTimeoutMs:t=1e4}={}){let s=()=>L(()=>R(u._request("system_health",[]))).pipe(U({first:t}),k(()=>"online"),z(()=>_("offline")));return _({state:"offline",delayMs:0}).pipe(V(a=>N(a.delayMs).pipe(Q(s),k(r=>({state:r,delayMs:e})))),$(1),k(a=>a.state),H(),W({bufferSize:1,refCount:!0}))}var{logger:X}=Y,g=class u{static instance=null;bestBlock$;finalizedBlock$;connection$;constructor(e){this.bestBlock$=this.watched("watcher(bestBlock)",e.getUnsafeApi().query.System.Number.watchValue({at:"best"}).pipe(j(({value:t})=>t))),this.finalizedBlock$=this.watched("watcher(finalizedBlock)",e.finalizedBlock$),this.connection$=this.watched("watcher(connection)",E(e))}static getInstance(e){return this.instance||(this.instance=new u(e)),this.instance}watched(e,t){return t.pipe(G({error:s=>X.error(e,s)}),F({bufferSize:1,refCount:!0}))}};var m=class{client;api;apiNext;apiIce;watcher;at;constructor(e,t){this.client=e,this.api=this.client.getTypedApi(J),this.apiNext=this.client.getTypedApi(K),this.apiIce=this.client.getTypedApi(Z),this.watcher=g.getInstance(this.client),this.at=t??"best"}};import{getWsProvider as Se}from"polkadot-api/ws";import{withLogsRecorder as _e}from"polkadot-api/logs-provider";var P=class extends m{SUPPORTED_TYPES=["StableSwap","Bond","Token","External","Erc20"];constructor(e){super(e)}async queryShares(){let t=await this.api.query.Stableswap.Pools.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryBonds(){let t=await this.api.query.Bonds.Bonds.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssets(){let t=await this.api.query.AssetRegistry.Assets.getEntries();return new Map(t.filter(({value:s})=>{let{asset_type:n}=s;return this.SUPPORTED_TYPES.includes(n.type)}).map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async queryAssetLocations(){let t=await this.api.query.AssetRegistry.AssetLocations.getEntries();return new Map(t.map(({keyArgs:s,value:n})=>{let[a]=s;return[a,n]}))}async mapToken(e,t,s,n){let{name:a,asset_type:r,is_sufficient:o,existential_deposit:c}=t,{symbol:i,decimals:l}=s.get(e)??{};return{id:e,name:a?w.toText(a):void 0,symbol:i,decimals:l,icon:i,type:r.type,isSufficient:o,location:n,existentialDeposit:c}}async mapBond(e,t,s,n){let[a,r]=n,{asset_type:o,is_sufficient:c,existential_deposit:i}=t,{symbol:l,decimals:y}=await this.mapToken(a,t,s),d=Number(r),p=new Intl.DateTimeFormat("en-GB"),b=[l,"Bond",p.format(d)].join(" ");return{id:e,name:b,symbol:l+"b",decimals:y,icon:l,type:o.type,isSufficient:c,existentialDeposit:i,underlyingAssetId:a,maturity:d}}async mapShares(e,t,s,n){let{assets:a}=n,{name:r,symbol:o,asset_type:c,is_sufficient:i,existential_deposit:l}=t,y=await Promise.all(a.map(async b=>{let{symbol:T}=await this.mapToken(b,t,s);return[b,T]})),d=Object.fromEntries(y),p=Object.values(d);return{id:e,name:p.join(", "),symbol:o&&w.toText(o)||r&&w.toText(r),decimals:18,icon:p.join("/"),type:c.type,isSufficient:i,existentialDeposit:l,meta:d}}async mapExternal(e,t,s,n){let a=await this.mapToken(e,t,new Map,n),r=s?.find(o=>o.internalId===a.id);return r?{...a,decimals:r.decimals,name:r.name,symbol:r.symbol,icon:r.symbol,isWhiteListed:r.isWhiteListed}:a}parseMetadata(e){return new Map(Array.from(e,([t,s])=>[t,{symbol:s.symbol?w.toText(s.symbol):void 0,decimals:s.decimals}]))}async getSupported(e,t){let[s,n,a,r]=await Promise.all([this.queryAssets(),this.queryAssetLocations(),this.queryShares(),this.queryBonds()]),o=this.parseMetadata(s),c=[];for(let[i,l]of Array.from(s)){let y=n.get(i),{asset_type:d}=l,p;switch(d.type){case"Bond":let b=r.get(i);p=await this.mapBond(i,l,o,b);break;case"StableSwap":let T=a.get(i);p=await this.mapShares(i,l,o,T);break;case"External":p=await this.mapExternal(i,l,t,y);break;default:p=await this.mapToken(i,l,o,y)}c.push(p)}return e?c:c.filter(i=>this.isValidAsset(i))}isValidAsset(e){let t=Math.sign(e.decimals);return!!e.symbol&&(t===0||t===1)}};import{log as ee}from"@galacticcouncil/common";import{combineLatest as te,concat as se,defer as A,from as v}from"rxjs";import{bufferCount as C,distinctUntilChanged as q,debounceTime as ae,map as h,retry as ne,startWith as D,switchMap as O,tap as B,take as re,skip as oe,connect as ie}from"rxjs/operators";var{logger:f}=ee,S=class extends m{erc20Ids=null;constructor(e,t){super(e,t)}async getBalance(e,t){return t===0?this.getSystemBalance(e):this.getBalanceData(e,t)}async getSystemBalance(e){let t=this.api.query.System.Account,{data:s}=await t.getValue(e,{at:this.at});return this.getBreakdown(s)}async getTokenBalance(e,t){let n=await this.api.query.Tokens.Accounts.getValue(e,t,{at:this.at});return this.getBreakdown(n)}async getErc20Balance(e,t){return this.getBalanceData(e,t)}watchBalance(e){return A(()=>{let t=this.watchSystemBalance(e),s=this.watchTokensBalance(e),n=this.watchErc20Balance(e);return te([t,s,n]).pipe(ie(a=>se(a.pipe(re(1)),a.pipe(oe(1),ae(250)))))}).pipe(h(t=>t.flat()),D([]),C(2,1),h(([t,s],n)=>n===0?s:this.getDeltas(t,s))).pipe(B({subscribe:()=>f.debug("balance: subscribe",e),error:t=>f.error("balance",t)}),ne({delay:1e3}))}watchSystemBalance(e){let t=this.api.query.System.Account;return A(()=>t.watchValue(e,{at:"best"})).pipe(h(({value:s})=>({id:0,balance:this.getBreakdown(s.data)})),B({error:s=>f.error("balance(system)",s)}))}watchTokenBalance(e,t){let s=this.api.query.Tokens.Accounts;return A(()=>s.watchValue(e,t,{at:"best"})).pipe(h(({value:n})=>({id:t,balance:this.getBreakdown(n)})),B({error:n=>f.error("balance(token)",n)}))}watchTokensBalance(e){let t=this.api.query.Tokens.Accounts;return A(()=>t.watchEntries(e,{at:"best"})).pipe(q((s,n)=>!n.deltas),h(({deltas:s})=>{let n=[];return s?.deleted.forEach(a=>{let[r,o]=a.args;n.push({id:o,balance:this.getBreakdown({free:0n,reserved:0n,frozen:0n})})}),s?.upserted.forEach(a=>{let[r,o]=a.args;n.push({id:o,balance:this.getBreakdown(a.value)})}),n}),B({error:s=>f.error("balance(tokens)",s)}))}watchErc20Balance(e,t){let s=async()=>{if(this.erc20Ids)return this.erc20Ids;let a=await this.api.query.AssetRegistry.Assets.getEntries({at:"best"});return this.erc20Ids=a.filter(({value:r})=>r.asset_type.type==="Erc20").map(({keyArgs:r})=>{let[o]=r;return o}),this.erc20Ids},n=async a=>(await Promise.all(a.map(async o=>[o,await this.getBalanceData(e,o)]))).map(([o,c])=>({id:o,balance:c}));return A(()=>v(t?Promise.resolve(t):s()).pipe(O(a=>this.watcher.bestBlock$.pipe(O(()=>v(n(a))))),D([]),C(2,1),h(([a,r],o)=>o===0?r.filter(c=>c.balance.total>0n):this.getDeltas(a,r)),q((a,r)=>r.length===0),B({error:a=>f.error("balance(erc20)",a)})))}async getBalanceData(e,t){let s=await this.api.apis.CurrenciesApi.account(t,e,{at:this.at});return this.getBreakdown(s)}getBreakdown(e){let t=e.frozen-e.reserved,s=t>0n?t:0n,n=e.free>=s?e.free-s:0n,a=e.free+e.reserved;return{free:e.free,reserved:e.reserved,frozen:e.frozen,total:a,transferable:n}}getDeltas(e,t){let s=(a,r)=>a!==void 0&&r!==void 0&&a.transferable===r.transferable&&a.total===r.total,n=e.reduce((a,r)=>(a.set(r.id,r.balance),a),new Map);return t.filter(a=>!s(a.balance,n.get(a.id)))}};var x=class extends m{_minOrderBudget;_blockTime;constructor(e){super(e)}async getBlockTime(){if(this._blockTime===void 0){let e=await this.api.constants.Aura.SlotDuration();this._blockTime=Number(e)}return this._blockTime}async getMinOrderBudget(){return this._minOrderBudget===void 0&&(this._minOrderBudget=await this.api.constants.DCA.MinBudgetInNativeCurrency()),this._minOrderBudget}};export{P as AssetClient,S as BalanceClient,x as ChainParams};
|