@galacticcouncil/sdk 0.8.0-beta.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var tr=Object.create;var vt=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var rr=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,ir=Object.prototype.hasOwnProperty;var Ot=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),sr=(s,e)=>{for(var t in e)vt(s,t,{get:e[t],enumerable:!0})},Bn=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of rr(e))!ir.call(s,r)&&r!==t&&vt(s,r,{get:()=>e[r],enumerable:!(n=nr(e,r))||n.enumerable});return s};var Bt=(s,e,t)=>(t=s!=null?tr(or(s)):{},Bn(e||!s||!s.__esModule?vt(t,"default",{value:s,enumerable:!0}):t,s)),ar=s=>Bn(vt({},"__esModule",{value:!0}),s);var Fn=Ot((xo,Je)=>{var _r={},R,{TextEncoder:dr,TextDecoder:pr}=require("util"),re=0,At=null;function kt(){return(At===null||At.byteLength===0)&&(At=new Uint8Array(R.memory.buffer)),At}var Et=new dr("utf-8"),gr=typeof Et.encodeInto=="function"?function(s,e){return Et.encodeInto(s,e)}:function(s,e){let t=Et.encode(s);return e.set(t),{read:s.length,written:t.length}};function le(s,e,t){if(t===void 0){let a=Et.encode(s),c=e(a.length,1)>>>0;return kt().subarray(c,c+a.length).set(a),re=a.length,c}let n=s.length,r=e(n,1)>>>0,o=kt(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3,1)>>>0;let a=kt().subarray(r+i,r+n),c=gr(s,a);i+=c.written}return re=i,r}var Ft=null;function Le(){return(Ft===null||Ft.byteLength===0)&&(Ft=new Int32Array(R.memory.buffer)),Ft}var An=new pr("utf-8",{ignoreBOM:!0,fatal:!0});An.decode();function ft(s,e){return s=s>>>0,An.decode(kt().subarray(s,s+e))}Je.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=R.__wbindgen_add_to_stack_pointer(-16),c=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),p=re;R.calculate_pool_trade_fee(a,c,p,e,t);var o=Le()[a/4+0],i=Le()[a/4+1];return n=o,r=i,ft(o,i)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(n,r,1)}};Je.exports.get_spot_price=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),A=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.get_spot_price(p,b,v,B,A,k,M,E,L,x,G);var a=Le()[p/4+0],c=Le()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Je.exports.calculate_out_given_in=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),A=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_out_given_in(p,b,v,B,A,k,M,E,L,x,G);var a=Le()[p/4+0],c=Le()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Je.exports.calculate_in_given_out=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),A=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_in_given_out(p,b,v,B,A,k,M,E,L,x,G);var a=Le()[p/4+0],c=Le()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Je.exports.calculate_linear_weights=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),A=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_linear_weights(p,b,v,B,A,k,M,E,L,x,G);var a=Le()[p/4+0],c=Le()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};var mr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),fr=require("fs").readFileSync(mr),hr=new WebAssembly.Module(fr),br=new WebAssembly.Instance(hr,_r);R=br.exports;Je.exports.__wasm=R});var Dn=Ot((is,ke)=>{var Sr={},O,{TextEncoder:xr,TextDecoder:vr}=require("util"),z=0,qt=null;function bt(){return(qt===null||qt.byteLength===0)&&(qt=new Uint8Array(O.memory.buffer)),qt}var Ht=new xr("utf-8"),Or=typeof Ht.encodeInto=="function"?function(s,e){return Ht.encodeInto(s,e)}:function(s,e){let t=Ht.encode(s);return e.set(t),{read:s.length,written:t.length}};function X(s,e,t){if(t===void 0){let a=Ht.encode(s),c=e(a.length,1)>>>0;return bt().subarray(c,c+a.length).set(a),z=a.length,c}let n=s.length,r=e(n,1)>>>0,o=bt(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3,1)>>>0;let a=bt().subarray(r+i,r+n),c=Or(s,a);i+=c.written}return z=i,r}var Gt=null;function de(){return(Gt===null||Gt.byteLength===0)&&(Gt=new Int32Array(O.memory.buffer)),Gt}var Ln=new vr("utf-8",{ignoreBOM:!0,fatal:!0});Ln.decode();function Xe(s,e){return s=s>>>0,Ln.decode(bt().subarray(s,s+e))}ke.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=O.__wbindgen_add_to_stack_pointer(-16),c=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),p=z;O.calculate_pool_trade_fee(a,c,p,e,t);var o=de()[a/4+0],i=de()[a/4+1];return n=o,r=i,Xe(o,i)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(n,r,1)}};ke.exports.calculate_out_given_in=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,A=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,M=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,L=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z;O.calculate_out_given_in(b,v,B,e,t,A,k,M,E,L,x);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};ke.exports.calculate_in_given_out=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,A=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,M=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,L=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z;O.calculate_in_given_out(b,v,B,e,t,A,k,M,E,L,x);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};ke.exports.calculate_amplification=function(s,e,t,n,r){let o,i;try{let p=O.__wbindgen_add_to_stack_pointer(-16),b=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),v=z,B=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),A=z,k=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),M=z,E=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),L=z,x=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),G=z;O.calculate_amplification(p,b,v,B,A,k,M,E,L,x,G);var a=de()[p/4+0],c=de()[p/4+1];return o=a,i=c,Xe(a,c)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(o,i,1)}};ke.exports.calculate_shares=function(s,e,t,n,r){let o,i;try{let p=O.__wbindgen_add_to_stack_pointer(-16),b=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),v=z,B=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),A=z,k=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),M=z,E=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),L=z,x=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),G=z;O.calculate_shares(p,b,v,B,A,k,M,E,L,x,G);var a=de()[p/4+0],c=de()[p/4+1];return o=a,i=c,Xe(a,c)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(o,i,1)}};ke.exports.calculate_shares_for_amount=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,A=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,M=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,L=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_shares_for_amount(b,v,B,e,A,k,M,E,L,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};ke.exports.calculate_add_one_asset=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,A=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,M=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,L=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_add_one_asset(b,v,B,A,k,t,M,E,L,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};function Br(s,e){return s=s>>>0,bt().subarray(s/1,s/1+e)}ke.exports.pool_account_name=function(s){try{let r=O.__wbindgen_add_to_stack_pointer(-16);O.pool_account_name(r,s);var e=de()[r/4+0],t=de()[r/4+1],n=Br(e,t).slice();return O.__wbindgen_free(e,t*1),n}finally{O.__wbindgen_add_to_stack_pointer(16)}};ke.exports.calculate_liquidity_out_one_asset=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,A=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,M=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,L=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_liquidity_out_one_asset(b,v,B,A,k,t,M,E,L,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};var Ir=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Tr=require("fs").readFileSync(Ir),Nr=new WebAssembly.Module(Tr),Ar=new WebAssembly.Instance(Nr,Sr);O=Ar.exports;ke.exports.__wasm=O});var Qn=Ot((Wa,oe)=>{var Dr={},u,{TextEncoder:Cr,TextDecoder:qr}=require("util"),T=0,Kt=null;function tn(){return(Kt===null||Kt.byteLength===0)&&(Kt=new Uint8Array(u.memory.buffer)),Kt}var nn=new Cr("utf-8"),Gr=typeof nn.encodeInto=="function"?function(s,e){return nn.encodeInto(s,e)}:function(s,e){let t=nn.encode(s);return e.set(t),{read:s.length,written:t.length}};function N(s,e,t){if(t===void 0){let a=nn.encode(s),c=e(a.length)>>>0;return tn().subarray(c,c+a.length).set(a),T=a.length,c}let n=s.length,r=e(n)>>>0,o=tn(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3)>>>0;let a=tn().subarray(r+i,r+n),c=Gr(s,a);i+=c.written}return T=i,r}var en=null;function j(){return(en===null||en.byteLength===0)&&(en=new Int32Array(u.memory.buffer)),en}var Zn=new qr("utf-8",{ignoreBOM:!0,fatal:!0});Zn.decode();function fe(s,e){return s=s>>>0,Zn.decode(tn().subarray(s,s+e))}oe.exports.calculate_shares=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=T,v=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=T,A=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T;u.calculate_shares(c,p,b,v,B,A,k,M,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.calculate_withdrawal_fee=function(s,e,t){let n,r;try{let a=u.__wbindgen_add_to_stack_pointer(-16),c=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),p=T,b=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),v=T,B=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),A=T;u.calculate_withdrawal_fee(a,c,p,b,v,B,A);var o=j()[a/4+0],i=j()[a/4+1];return n=o,r=i,fe(o,i)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(n,r)}};oe.exports.calculate_liquidity_out=function(s,e,t,n,r,o,i,a){let c,p;try{let B=u.__wbindgen_add_to_stack_pointer(-16),A=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T,L=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),x=T,G=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),J=T,te=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=T,H=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),l=T,_=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),d=T,w=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),m=T;u.calculate_liquidity_out(B,A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m);var b=j()[B/4+0],v=j()[B/4+1];return c=b,p=v,fe(b,v)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(c,p)}};oe.exports.calculate_liquidity_lrna_out=function(s,e,t,n,r,o,i,a){let c,p;try{let B=u.__wbindgen_add_to_stack_pointer(-16),A=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T,L=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),x=T,G=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),J=T,te=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=T,H=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),l=T,_=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),d=T,w=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),m=T;u.calculate_liquidity_lrna_out(B,A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m);var b=j()[B/4+0],v=j()[B/4+1];return c=b,p=v,fe(b,v)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(c,p)}};oe.exports.recalculate_asset_fee=function(s,e,t,n,r,o,i,a,c){let p,b;try{let A=u.__wbindgen_add_to_stack_pointer(-16),k=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T,J=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=T,Z=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=T,l=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=T,d=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=T,m=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),h=T,y=N(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=T;u.recalculate_asset_fee(A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m,h,y,g);var v=j()[A/4+0],B=j()[A/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.recalculate_protocol_fee=function(s,e,t,n,r,o,i,a,c){let p,b;try{let A=u.__wbindgen_add_to_stack_pointer(-16),k=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T,J=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=T,Z=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=T,l=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=T,d=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=T,m=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),h=T,y=N(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=T;u.recalculate_protocol_fee(A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m,h,y,g);var v=j()[A/4+0],B=j()[A/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_out_given_in=function(s,e,t,n,r,o,i,a,c){let p,b;try{let A=u.__wbindgen_add_to_stack_pointer(-16),k=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T,J=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=T,Z=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=T,l=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=T,d=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=T,m=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),h=T,y=N(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=T;u.calculate_out_given_in(A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m,h,y,g);var v=j()[A/4+0],B=j()[A/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_out_given_lrna_in=function(s,e,t,n,r){let o,i;try{let p=u.__wbindgen_add_to_stack_pointer(-16),b=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),v=T,B=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),A=T,k=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T;u.calculate_out_given_lrna_in(p,b,v,B,A,k,M,E,L,x,G);var a=j()[p/4+0],c=j()[p/4+1];return o=a,i=c,fe(a,c)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(o,i)}};oe.exports.calculate_in_given_out=function(s,e,t,n,r,o,i,a,c){let p,b;try{let A=u.__wbindgen_add_to_stack_pointer(-16),k=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T,J=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=T,Z=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=T,l=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=T,d=N(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=T,m=N(a,u.__wbindgen_malloc,u.__wbindgen_realloc),h=T,y=N(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=T;u.calculate_in_given_out(A,k,M,E,L,x,G,J,te,Z,H,l,_,d,w,m,h,y,g);var v=j()[A/4+0],B=j()[A/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_lrna_in_given_out=function(s,e,t,n,r){let o,i;try{let p=u.__wbindgen_add_to_stack_pointer(-16),b=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),v=T,B=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),A=T,k=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),M=T,E=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),L=T,x=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),G=T;u.calculate_lrna_in_given_out(p,b,v,B,A,k,M,E,L,x,G);var a=j()[p/4+0],c=j()[p/4+1];return o=a,i=c,fe(a,c)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(o,i)}};oe.exports.calculate_spot_price=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=T,v=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=T,A=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T;u.calculate_spot_price(c,p,b,v,B,A,k,M,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.calculate_lrna_spot_price=function(s,e){let t,n;try{let i=u.__wbindgen_add_to_stack_pointer(-16),a=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),c=T,p=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),b=T;u.calculate_lrna_spot_price(i,a,c,p,b);var r=j()[i/4+0],o=j()[i/4+1];return t=r,n=o,fe(r,o)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(t,n)}};oe.exports.calculate_cap_difference=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=T,v=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=T,A=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T;u.calculate_cap_difference(c,p,b,v,B,A,k,M,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.verify_asset_cap=function(s,e,t,n){let r=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),o=T,i=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),a=T,c=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),p=T,b=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),v=T;return u.verify_asset_cap(r,o,i,a,c,p,b,v)!==0};oe.exports.calculate_tvl_cap_difference=function(s,e,t,n,r,o){let i,a;try{let b=u.__wbindgen_add_to_stack_pointer(-16),v=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),B=T,A=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T,L=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),x=T,G=N(r,u.__wbindgen_malloc,u.__wbindgen_realloc),J=T,te=N(o,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=T;u.calculate_tvl_cap_difference(b,v,B,A,k,M,E,L,x,G,J,te,Z);var c=j()[b/4+0],p=j()[b/4+1];return i=c,a=p,fe(c,p)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(i,a)}};oe.exports.calculate_liquidity_hub_in=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=T,v=N(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=T,A=N(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=T,M=N(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=T;u.calculate_liquidity_hub_in(c,p,b,v,B,A,k,M,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.is_sell_allowed=function(s){return u.is_sell_allowed(s)!==0};oe.exports.is_buy_allowed=function(s){return u.is_buy_allowed(s)!==0};oe.exports.is_add_liquidity_allowed=function(s){return u.is_add_liquidity_allowed(s)!==0};oe.exports.is_remove_liquidity_allowed=function(s){return u.is_remove_liquidity_allowed(s)!==0};oe.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=u.__wbindgen_add_to_stack_pointer(-16),c=N(s,u.__wbindgen_malloc,u.__wbindgen_realloc),p=T;u.calculate_pool_trade_fee(a,c,p,e,t);var o=j()[a/4+0],i=j()[a/4+1];return n=o,r=i,fe(o,i)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(n,r)}};var Hr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Ur=require("fs").readFileSync(Hr),Wr=new WebAssembly.Module(Ur),zr=new WebAssembly.Instance(Wr,Dr);u=zr.exports;oe.exports.__wasm=u});var er=Ot((xl,Ge)=>{var Xr={},F,{TextEncoder:Yr,TextDecoder:$r}=require("util"),K=0,rn=null;function sn(){return(rn===null||rn.buffer!==F.memory.buffer)&&(rn=new Uint8Array(F.memory.buffer)),rn}var an=new Yr("utf-8"),Vr=typeof an.encodeInto=="function"?function(s,e){return an.encodeInto(s,e)}:function(s,e){let t=an.encode(s);return e.set(t),{read:s.length,written:t.length}};function ee(s,e,t){if(t===void 0){let a=an.encode(s),c=e(a.length);return sn().subarray(c,c+a.length).set(a),K=a.length,c}let n=s.length,r=e(n),o=sn(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3);let a=sn().subarray(r+i,r+n),c=Vr(s,a);i+=c.written}return K=i,r}var on=null;function he(){return(on===null||on.buffer!==F.memory.buffer)&&(on=new Int32Array(F.memory.buffer)),on}var Kn=new $r("utf-8",{ignoreBOM:!0,fatal:!0});Kn.decode();function Ve(s,e){return Kn.decode(sn().subarray(s,s+e))}Ge.exports.calculate_pool_trade_fee=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K;F.calculate_pool_trade_fee(o,i,a,e,t);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.get_spot_price=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.get_spot_price(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_out_given_in=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_out_given_in(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_in_given_out=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_in_given_out(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_liquidity_in=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_liquidity_in(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_shares=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_shares(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_liquidity_out_asset_a=function(s,e,t,n){try{let i=F.__wbindgen_add_to_stack_pointer(-16),a=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),c=K,p=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),b=K,v=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),B=K,A=ee(n,F.__wbindgen_malloc,F.__wbindgen_realloc),k=K;F.calculate_liquidity_out_asset_a(i,a,c,p,b,v,B,A,k);var r=he()[i/4+0],o=he()[i/4+1];return Ve(r,o)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(r,o)}};Ge.exports.calculate_liquidity_out_asset_b=function(s,e,t,n){try{let i=F.__wbindgen_add_to_stack_pointer(-16),a=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),c=K,p=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),b=K,v=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),B=K,A=ee(n,F.__wbindgen_malloc,F.__wbindgen_realloc),k=K;F.calculate_liquidity_out_asset_b(i,a,c,p,b,v,B,A,k);var r=he()[i/4+0],o=he()[i/4+1];return Ve(r,o)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(r,o)}};var jr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Jr=require("fs").readFileSync(jr),Zr=new WebAssembly.Module(Jr),Qr=new WebAssembly.Instance(Zr,Xr);F=Qr.exports;Ge.exports.__wasm=F});var eo={};sr(eo,{AssetClient:()=>rt,AssetNotFound:()=>fn,BASILISK_PARACHAIN_ID:()=>yr,BalanceClient:()=>ot,BigNumber:()=>Me,CachingPoolService:()=>Qt,DECIMAL_PLACES:()=>Nn,DENOMINATOR:()=>Mt,HYDRADX_OMNIPOOL_ADDRESS:()=>ht,HYDRADX_PARACHAIN_ID:()=>Pr,HYDRADX_SS58_PREFIX:()=>tt,INFINITY:()=>ur,LbpMath:()=>Te,LbpPool:()=>Ye,ONE:()=>xe,OmniMath:()=>ae,OmniPool:()=>$e,PoolConfigNotFound:()=>mn,PoolError:()=>Ke,PoolFactory:()=>_t,PoolNotFound:()=>wt,PoolService:()=>st,PoolType:()=>ye,ProviderConfigNotFound:()=>wn,RUNTIME_DECIMALS:()=>et,RouteNotFound:()=>it,Router:()=>Ze,SYSTEM_ASSET_DECIMALS:()=>wr,SYSTEM_ASSET_ID:()=>We,StorageConfigNotFound:()=>hn,SubscriptionNotSupported:()=>bn,TRADEABLE_DEFAULT:()=>Rt,TradeRouter:()=>St,TradeType:()=>gn,XykMath:()=>He,XykPool:()=>je,ZERO:()=>W,bnum:()=>C,buildRoute:()=>zt,calculateBuyFee:()=>On,calculateDiffToAvg:()=>Kr,calculateDiffToRef:()=>dt,calculateSellFee:()=>vn,scale:()=>_e});module.exports=ar(eo);var It=class{constructor(e=1/0){this.capacity=e}storage=[];enqueue(e){if(this.size()===this.capacity)throw Error("Queue has reached max capacity, you cannot add more items");this.storage.push(e)}dequeue(){return this.storage.shift()}size(){return this.storage.length}};var lr=4,gt=class{isNotVisited(e,t){let n=!0;return t.forEach(r=>{(r[0]===e[0]||r[1]===e[1])&&(n=!1)}),n}findPaths(e,t,n){let r=[],o=new It,i=[];for(i.push([t,""]),o.enqueue(i);o.size()>0;){let a=o.dequeue();if(a==null||a.length>lr)return r;let c=a[a.length-1];(n===null||c[0]===n)&&r.push(a),e[c[0]].forEach(b=>{if(this.isNotVisited(b,a)){let v=[...a];v.push(b),o.enqueue(v)}})}return r}buildAndPopulateGraph(e,t){let n=e[e.length-1],r=[];for(let o=0;o<=parseInt(n);o++)r.push([]);for(let[o,i,a]of t){let c=parseInt(i),p=parseInt(a);r[c].push([p,o])}return r}};function un(s){let e={};for(let t of s){let n=t.tokens.length;for(let r=0;r<n;r++){e[t.tokens[r].id]||(e[t.tokens[r].id]=[]);for(let o=0;o<n;o++){if(r==o)continue;let i=[t.address,t.tokens[r].id,t.tokens[o].id];e[t.tokens[r].id].push(i)}}}return e}var mt=class{getProposals(e,t,n){let r=un(n),o=Object.keys(r),i=o.map(b=>r[b]).flat(),a=new gt,c=a.buildAndPopulateGraph(o,i),p=a.findPaths(c,parseInt(e),t?parseInt(t):null);return this.parsePaths(p)}parsePaths(e){let t=[];for(let n of e){let r=[];for(let o=0;o<n.length;o++){let i=n[o],a=n[o+1];if(a==null)break;r.push(this.toEdge(i,a))}t.push(r)}return t}toEdge(e,t){return[t[1],e[0].toString(),t[0].toString()]}};var cr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,_n=Math.ceil,Re=Math.floor,Pe="[BigNumber Error] ",In=Pe+"Number primitive has more than 15 significant digits: ",Ae=1e14,U=14,dn=9007199254740991,pn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],ze=1e7,ue=1e9;function Tn(s){var e,t,n,r=x.prototype={constructor:x,toString:null,valueOf:null},o=new x(1),i=20,a=4,c=-7,p=21,b=-1e7,v=1e7,B=!1,A=1,k=0,M={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz",L=!0;function x(l,_){var d,w,m,h,y,g,f,S,P=this;if(!(P instanceof x))return new x(l,_);if(_==null){if(l&&l._isBigNumber===!0){P.s=l.s,!l.c||l.e>v?P.c=P.e=null:l.e<b?P.c=[P.e=0]:(P.e=l.e,P.c=l.c.slice());return}if((g=typeof l=="number")&&l*0==0){if(P.s=1/l<0?(l=-l,-1):1,l===~~l){for(h=0,y=l;y>=10;y/=10,h++);h>v?P.c=P.e=null:(P.e=h,P.c=[l]);return}S=String(l)}else{if(!cr.test(S=String(l)))return n(P,S,g);P.s=S.charCodeAt(0)==45?(S=S.slice(1),-1):1}(h=S.indexOf("."))>-1&&(S=S.replace(".","")),(y=S.search(/e/i))>0?(h<0&&(h=y),h+=+S.slice(y+1),S=S.substring(0,y)):h<0&&(h=S.length)}else{if(ne(_,2,E.length,"Base"),_==10&&L)return P=new x(l),Z(P,i+P.e+1,a);if(S=String(l),g=typeof l=="number"){if(l*0!=0)return n(P,S,g,_);if(P.s=1/l<0?(S=S.slice(1),-1):1,x.DEBUG&&S.replace(/^0\.0*|\./,"").length>15)throw Error(In+l)}else P.s=S.charCodeAt(0)===45?(S=S.slice(1),-1):1;for(d=E.slice(0,_),h=y=0,f=S.length;y<f;y++)if(d.indexOf(w=S.charAt(y))<0){if(w=="."){if(y>h){h=f;continue}}else if(!m&&(S==S.toUpperCase()&&(S=S.toLowerCase())||S==S.toLowerCase()&&(S=S.toUpperCase()))){m=!0,y=-1,h=0;continue}return n(P,String(l),g,_)}g=!1,S=t(S,_,10,P.s),(h=S.indexOf("."))>-1?S=S.replace(".",""):h=S.length}for(y=0;S.charCodeAt(y)===48;y++);for(f=S.length;S.charCodeAt(--f)===48;);if(S=S.slice(y,++f)){if(f-=y,g&&x.DEBUG&&f>15&&(l>dn||l!==Re(l)))throw Error(In+P.s*l);if((h=h-y-1)>v)P.c=P.e=null;else if(h<b)P.c=[P.e=0];else{if(P.e=h,P.c=[],y=(h+1)%U,h<0&&(y+=U),y<f){for(y&&P.c.push(+S.slice(0,y)),f-=U;y<f;)P.c.push(+S.slice(y,y+=U));y=U-(S=S.slice(y)).length}else y-=f;for(;y--;S+="0");P.c.push(+S)}}else P.c=[P.e=0]}x.clone=Tn,x.ROUND_UP=0,x.ROUND_DOWN=1,x.ROUND_CEIL=2,x.ROUND_FLOOR=3,x.ROUND_HALF_UP=4,x.ROUND_HALF_DOWN=5,x.ROUND_HALF_EVEN=6,x.ROUND_HALF_CEIL=7,x.ROUND_HALF_FLOOR=8,x.EUCLID=9,x.config=x.set=function(l){var _,d;if(l!=null)if(typeof l=="object"){if(l.hasOwnProperty(_="DECIMAL_PLACES")&&(d=l[_],ne(d,0,ue,_),i=d),l.hasOwnProperty(_="ROUNDING_MODE")&&(d=l[_],ne(d,0,8,_),a=d),l.hasOwnProperty(_="EXPONENTIAL_AT")&&(d=l[_],d&&d.pop?(ne(d[0],-ue,0,_),ne(d[1],0,ue,_),c=d[0],p=d[1]):(ne(d,-ue,ue,_),c=-(p=d<0?-d:d))),l.hasOwnProperty(_="RANGE"))if(d=l[_],d&&d.pop)ne(d[0],-ue,-1,_),ne(d[1],1,ue,_),b=d[0],v=d[1];else if(ne(d,-ue,ue,_),d)b=-(v=d<0?-d:d);else throw Error(Pe+_+" cannot be zero: "+d);if(l.hasOwnProperty(_="CRYPTO"))if(d=l[_],d===!!d)if(d)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))B=d;else throw B=!d,Error(Pe+"crypto unavailable");else B=d;else throw Error(Pe+_+" not true or false: "+d);if(l.hasOwnProperty(_="MODULO_MODE")&&(d=l[_],ne(d,0,9,_),A=d),l.hasOwnProperty(_="POW_PRECISION")&&(d=l[_],ne(d,0,ue,_),k=d),l.hasOwnProperty(_="FORMAT"))if(d=l[_],typeof d=="object")M=d;else throw Error(Pe+_+" not an object: "+d);if(l.hasOwnProperty(_="ALPHABET"))if(d=l[_],typeof d=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(d))L=d.slice(0,10)=="0123456789",E=d;else throw Error(Pe+_+" invalid: "+d)}else throw Error(Pe+"Object expected: "+l);return{DECIMAL_PLACES:i,ROUNDING_MODE:a,EXPONENTIAL_AT:[c,p],RANGE:[b,v],CRYPTO:B,MODULO_MODE:A,POW_PRECISION:k,FORMAT:M,ALPHABET:E}},x.isBigNumber=function(l){if(!l||l._isBigNumber!==!0)return!1;if(!x.DEBUG)return!0;var _,d,w=l.c,m=l.e,h=l.s;e:if({}.toString.call(w)=="[object Array]"){if((h===1||h===-1)&&m>=-ue&&m<=ue&&m===Re(m)){if(w[0]===0){if(m===0&&w.length===1)return!0;break e}if(_=(m+1)%U,_<1&&(_+=U),String(w[0]).length==_){for(_=0;_<w.length;_++)if(d=w[_],d<0||d>=Ae||d!==Re(d))break e;if(d!==0)return!0}}}else if(w===null&&m===null&&(h===null||h===1||h===-1))return!0;throw Error(Pe+"Invalid BigNumber: "+l)},x.maximum=x.max=function(){return J(arguments,r.lt)},x.minimum=x.min=function(){return J(arguments,r.gt)},x.random=function(){var l=9007199254740992,_=Math.random()*l&2097151?function(){return Re(Math.random()*l)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(d){var w,m,h,y,g,f=0,S=[],P=new x(o);if(d==null?d=i:ne(d,0,ue),y=_n(d/U),B)if(crypto.getRandomValues){for(w=crypto.getRandomValues(new Uint32Array(y*=2));f<y;)g=w[f]*131072+(w[f+1]>>>11),g>=9e15?(m=crypto.getRandomValues(new Uint32Array(2)),w[f]=m[0],w[f+1]=m[1]):(S.push(g%1e14),f+=2);f=y/2}else if(crypto.randomBytes){for(w=crypto.randomBytes(y*=7);f<y;)g=(w[f]&31)*281474976710656+w[f+1]*1099511627776+w[f+2]*4294967296+w[f+3]*16777216+(w[f+4]<<16)+(w[f+5]<<8)+w[f+6],g>=9e15?crypto.randomBytes(7).copy(w,f):(S.push(g%1e14),f+=7);f=y/7}else throw B=!1,Error(Pe+"crypto unavailable");if(!B)for(;f<y;)g=_(),g<9e15&&(S[f++]=g%1e14);for(y=S[--f],d%=U,y&&d&&(g=pn[U-d],S[f]=Re(y/g)*g);S[f]===0;S.pop(),f--);if(f<0)S=[h=0];else{for(h=-1;S[0]===0;S.splice(0,1),h-=U);for(f=1,g=S[0];g>=10;g/=10,f++);f<U&&(h-=U-f)}return P.e=h,P.c=S,P}}(),x.sum=function(){for(var l=1,_=arguments,d=new x(_[0]);l<_.length;)d=d.plus(_[l++]);return d},t=function(){var l="0123456789";function _(d,w,m,h){for(var y,g=[0],f,S=0,P=d.length;S<P;){for(f=g.length;f--;g[f]*=w);for(g[0]+=h.indexOf(d.charAt(S++)),y=0;y<g.length;y++)g[y]>m-1&&(g[y+1]==null&&(g[y+1]=0),g[y+1]+=g[y]/m|0,g[y]%=m)}return g.reverse()}return function(d,w,m,h,y){var g,f,S,P,I,D,q,V,ie=d.indexOf("."),ce=i,$=a;for(ie>=0&&(P=k,k=0,d=d.replace(".",""),V=new x(w),D=V.pow(d.length-ie),k=P,V.c=_(Ue(Be(D.c),D.e,"0"),10,m,l),V.e=V.c.length),q=_(d,w,m,y?(g=E,l):(g=l,E)),S=P=q.length;q[--P]==0;q.pop());if(!q[0])return g.charAt(0);if(ie<0?--S:(D.c=q,D.e=S,D.s=h,D=e(D,V,ce,$,m),q=D.c,I=D.r,S=D.e),f=S+ce+1,ie=q[f],P=m/2,I=I||f<0||q[f+1]!=null,I=$<4?(ie!=null||I)&&($==0||$==(D.s<0?3:2)):ie>P||ie==P&&($==4||I||$==6&&q[f-1]&1||$==(D.s<0?8:7)),f<1||!q[0])d=I?Ue(g.charAt(1),-ce,g.charAt(0)):g.charAt(0);else{if(q.length=f,I)for(--m;++q[--f]>m;)q[f]=0,f||(++S,q=[1].concat(q));for(P=q.length;!q[--P];);for(ie=0,d="";ie<=P;d+=g.charAt(q[ie++]));d=Ue(d,S,g.charAt(0))}return d}}(),e=function(){function l(w,m,h){var y,g,f,S,P=0,I=w.length,D=m%ze,q=m/ze|0;for(w=w.slice();I--;)f=w[I]%ze,S=w[I]/ze|0,y=q*f+S*D,g=D*f+y%ze*ze+P,P=(g/h|0)+(y/ze|0)+q*S,w[I]=g%h;return P&&(w=[P].concat(w)),w}function _(w,m,h,y){var g,f;if(h!=y)f=h>y?1:-1;else for(g=f=0;g<h;g++)if(w[g]!=m[g]){f=w[g]>m[g]?1:-1;break}return f}function d(w,m,h,y){for(var g=0;h--;)w[h]-=g,g=w[h]<m[h]?1:0,w[h]=g*y+w[h]-m[h];for(;!w[0]&&w.length>1;w.splice(0,1));}return function(w,m,h,y,g){var f,S,P,I,D,q,V,ie,ce,$,Q,me,xt,ln,cn,Ee,pt,Oe=w.s==m.s?1:-1,we=w.c,se=m.c;if(!we||!we[0]||!se||!se[0])return new x(!w.s||!m.s||(we?se&&we[0]==se[0]:!se)?NaN:we&&we[0]==0||!se?Oe*0:Oe/0);for(ie=new x(Oe),ce=ie.c=[],S=w.e-m.e,Oe=h+S+1,g||(g=Ae,S=Ie(w.e/U)-Ie(m.e/U),Oe=Oe/U|0),P=0;se[P]==(we[P]||0);P++);if(se[P]>(we[P]||0)&&S--,Oe<0)ce.push(1),I=!0;else{for(ln=we.length,Ee=se.length,P=0,Oe+=2,D=Re(g/(se[0]+1)),D>1&&(se=l(se,D,g),we=l(we,D,g),Ee=se.length,ln=we.length),xt=Ee,$=we.slice(0,Ee),Q=$.length;Q<Ee;$[Q++]=0);pt=se.slice(),pt=[0].concat(pt),cn=se[0],se[1]>=g/2&&cn++;do{if(D=0,f=_(se,$,Ee,Q),f<0){if(me=$[0],Ee!=Q&&(me=me*g+($[1]||0)),D=Re(me/cn),D>1)for(D>=g&&(D=g-1),q=l(se,D,g),V=q.length,Q=$.length;_(q,$,V,Q)==1;)D--,d(q,Ee<V?pt:se,V,g),V=q.length,f=1;else D==0&&(f=D=1),q=se.slice(),V=q.length;if(V<Q&&(q=[0].concat(q)),d($,q,Q,g),Q=$.length,f==-1)for(;_(se,$,Ee,Q)<1;)D++,d($,Ee<Q?pt:se,Q,g),Q=$.length}else f===0&&(D++,$=[0]);ce[P++]=D,$[0]?$[Q++]=we[xt]||0:($=[we[xt]],Q=1)}while((xt++<ln||$[0]!=null)&&Oe--);I=$[0]!=null,ce[0]||ce.splice(0,1)}if(g==Ae){for(P=1,Oe=ce[0];Oe>=10;Oe/=10,P++);Z(ie,h+(ie.e=P+S*U-1)+1,y,I)}else ie.e=S,ie.r=+I;return ie}}();function G(l,_,d,w){var m,h,y,g,f;if(d==null?d=a:ne(d,0,8),!l.c)return l.toString();if(m=l.c[0],y=l.e,_==null)f=Be(l.c),f=w==1||w==2&&(y<=c||y>=p)?Nt(f,y):Ue(f,y,"0");else if(l=Z(new x(l),_,d),h=l.e,f=Be(l.c),g=f.length,w==1||w==2&&(_<=h||h<=c)){for(;g<_;f+="0",g++);f=Nt(f,h)}else if(_-=y,f=Ue(f,h,"0"),h+1>g){if(--_>0)for(f+=".";_--;f+="0");}else if(_+=h-g,_>0)for(h+1==g&&(f+=".");_--;f+="0");return l.s<0&&m?"-"+f:f}function J(l,_){for(var d,w=1,m=new x(l[0]);w<l.length;w++)if(d=new x(l[w]),d.s)_.call(m,d)&&(m=d);else{m=d;break}return m}function te(l,_,d){for(var w=1,m=_.length;!_[--m];_.pop());for(m=_[0];m>=10;m/=10,w++);return(d=w+d*U-1)>v?l.c=l.e=null:d<b?l.c=[l.e=0]:(l.e=d,l.c=_),l}n=function(){var l=/^(-?)0([xbo])(?=\w[\w.]*$)/i,_=/^([^.]+)\.$/,d=/^\.([^.]+)$/,w=/^-?(Infinity|NaN)$/,m=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(h,y,g,f){var S,P=g?y:y.replace(m,"");if(w.test(P))h.s=isNaN(P)?null:P<0?-1:1;else{if(!g&&(P=P.replace(l,function(I,D,q){return S=(q=q.toLowerCase())=="x"?16:q=="b"?2:8,!f||f==S?D:I}),f&&(S=f,P=P.replace(_,"$1").replace(d,"0.$1")),y!=P))return new x(P,S);if(x.DEBUG)throw Error(Pe+"Not a"+(f?" base "+f:"")+" number: "+y);h.s=null}h.c=h.e=null}}();function Z(l,_,d,w){var m,h,y,g,f,S,P,I=l.c,D=pn;if(I){e:{for(m=1,g=I[0];g>=10;g/=10,m++);if(h=_-m,h<0)h+=U,y=_,f=I[S=0],P=f/D[m-y-1]%10|0;else if(S=_n((h+1)/U),S>=I.length)if(w){for(;I.length<=S;I.push(0));f=P=0,m=1,h%=U,y=h-U+1}else break e;else{for(f=g=I[S],m=1;g>=10;g/=10,m++);h%=U,y=h-U+m,P=y<0?0:f/D[m-y-1]%10|0}if(w=w||_<0||I[S+1]!=null||(y<0?f:f%D[m-y-1]),w=d<4?(P||w)&&(d==0||d==(l.s<0?3:2)):P>5||P==5&&(d==4||w||d==6&&(h>0?y>0?f/D[m-y]:0:I[S-1])%10&1||d==(l.s<0?8:7)),_<1||!I[0])return I.length=0,w?(_-=l.e+1,I[0]=D[(U-_%U)%U],l.e=-_||0):I[0]=l.e=0,l;if(h==0?(I.length=S,g=1,S--):(I.length=S+1,g=D[U-h],I[S]=y>0?Re(f/D[m-y]%D[y])*g:0),w)for(;;)if(S==0){for(h=1,y=I[0];y>=10;y/=10,h++);for(y=I[0]+=g,g=1;y>=10;y/=10,g++);h!=g&&(l.e++,I[0]==Ae&&(I[0]=1));break}else{if(I[S]+=g,I[S]!=Ae)break;I[S--]=0,g=1}for(h=I.length;I[--h]===0;I.pop());}l.e>v?l.c=l.e=null:l.e<b&&(l.c=[l.e=0])}return l}function H(l){var _,d=l.e;return d===null?l.toString():(_=Be(l.c),_=d<=c||d>=p?Nt(_,d):Ue(_,d,"0"),l.s<0?"-"+_:_)}return r.absoluteValue=r.abs=function(){var l=new x(this);return l.s<0&&(l.s=1),l},r.comparedTo=function(l,_){return Qe(this,new x(l,_))},r.decimalPlaces=r.dp=function(l,_){var d,w,m,h=this;if(l!=null)return ne(l,0,ue),_==null?_=a:ne(_,0,8),Z(new x(h),l+h.e+1,_);if(!(d=h.c))return null;if(w=((m=d.length-1)-Ie(this.e/U))*U,m=d[m])for(;m%10==0;m/=10,w--);return w<0&&(w=0),w},r.dividedBy=r.div=function(l,_){return e(this,new x(l,_),i,a)},r.dividedToIntegerBy=r.idiv=function(l,_){return e(this,new x(l,_),0,1)},r.exponentiatedBy=r.pow=function(l,_){var d,w,m,h,y,g,f,S,P,I=this;if(l=new x(l),l.c&&!l.isInteger())throw Error(Pe+"Exponent not an integer: "+H(l));if(_!=null&&(_=new x(_)),g=l.e>14,!I.c||!I.c[0]||I.c[0]==1&&!I.e&&I.c.length==1||!l.c||!l.c[0])return P=new x(Math.pow(+H(I),g?l.s*(2-Tt(l)):+H(l))),_?P.mod(_):P;if(f=l.s<0,_){if(_.c?!_.c[0]:!_.s)return new x(NaN);w=!f&&I.isInteger()&&_.isInteger(),w&&(I=I.mod(_))}else{if(l.e>9&&(I.e>0||I.e<-1||(I.e==0?I.c[0]>1||g&&I.c[1]>=24e7:I.c[0]<8e13||g&&I.c[0]<=9999975e7)))return h=I.s<0&&Tt(l)?-0:0,I.e>-1&&(h=1/h),new x(f?1/h:h);k&&(h=_n(k/U+2))}for(g?(d=new x(.5),f&&(l.s=1),S=Tt(l)):(m=Math.abs(+H(l)),S=m%2),P=new x(o);;){if(S){if(P=P.times(I),!P.c)break;h?P.c.length>h&&(P.c.length=h):w&&(P=P.mod(_))}if(m){if(m=Re(m/2),m===0)break;S=m%2}else if(l=l.times(d),Z(l,l.e+1,1),l.e>14)S=Tt(l);else{if(m=+H(l),m===0)break;S=m%2}I=I.times(I),h?I.c&&I.c.length>h&&(I.c.length=h):w&&(I=I.mod(_))}return w?P:(f&&(P=o.div(P)),_?P.mod(_):h?Z(P,k,a,y):P)},r.integerValue=function(l){var _=new x(this);return l==null?l=a:ne(l,0,8),Z(_,_.e+1,l)},r.isEqualTo=r.eq=function(l,_){return Qe(this,new x(l,_))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(l,_){return Qe(this,new x(l,_))>0},r.isGreaterThanOrEqualTo=r.gte=function(l,_){return(_=Qe(this,new x(l,_)))===1||_===0},r.isInteger=function(){return!!this.c&&Ie(this.e/U)>this.c.length-2},r.isLessThan=r.lt=function(l,_){return Qe(this,new x(l,_))<0},r.isLessThanOrEqualTo=r.lte=function(l,_){return(_=Qe(this,new x(l,_)))===-1||_===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(l,_){var d,w,m,h,y=this,g=y.s;if(l=new x(l,_),_=l.s,!g||!_)return new x(NaN);if(g!=_)return l.s=-_,y.plus(l);var f=y.e/U,S=l.e/U,P=y.c,I=l.c;if(!f||!S){if(!P||!I)return P?(l.s=-_,l):new x(I?y:NaN);if(!P[0]||!I[0])return I[0]?(l.s=-_,l):new x(P[0]?y:a==3?-0:0)}if(f=Ie(f),S=Ie(S),P=P.slice(),g=f-S){for((h=g<0)?(g=-g,m=P):(S=f,m=I),m.reverse(),_=g;_--;m.push(0));m.reverse()}else for(w=(h=(g=P.length)<(_=I.length))?g:_,g=_=0;_<w;_++)if(P[_]!=I[_]){h=P[_]<I[_];break}if(h&&(m=P,P=I,I=m,l.s=-l.s),_=(w=I.length)-(d=P.length),_>0)for(;_--;P[d++]=0);for(_=Ae-1;w>g;){if(P[--w]<I[w]){for(d=w;d&&!P[--d];P[d]=_);--P[d],P[w]+=Ae}P[w]-=I[w]}for(;P[0]==0;P.splice(0,1),--S);return P[0]?te(l,P,S):(l.s=a==3?-1:1,l.c=[l.e=0],l)},r.modulo=r.mod=function(l,_){var d,w,m=this;return l=new x(l,_),!m.c||!l.s||l.c&&!l.c[0]?new x(NaN):!l.c||m.c&&!m.c[0]?new x(m):(A==9?(w=l.s,l.s=1,d=e(m,l,0,3),l.s=w,d.s*=w):d=e(m,l,0,A),l=m.minus(d.times(l)),!l.c[0]&&A==1&&(l.s=m.s),l)},r.multipliedBy=r.times=function(l,_){var d,w,m,h,y,g,f,S,P,I,D,q,V,ie,ce,$=this,Q=$.c,me=(l=new x(l,_)).c;if(!Q||!me||!Q[0]||!me[0])return!$.s||!l.s||Q&&!Q[0]&&!me||me&&!me[0]&&!Q?l.c=l.e=l.s=null:(l.s*=$.s,!Q||!me?l.c=l.e=null:(l.c=[0],l.e=0)),l;for(w=Ie($.e/U)+Ie(l.e/U),l.s*=$.s,f=Q.length,I=me.length,f<I&&(V=Q,Q=me,me=V,m=f,f=I,I=m),m=f+I,V=[];m--;V.push(0));for(ie=Ae,ce=ze,m=I;--m>=0;){for(d=0,D=me[m]%ce,q=me[m]/ce|0,y=f,h=m+y;h>m;)S=Q[--y]%ce,P=Q[y]/ce|0,g=q*S+P*D,S=D*S+g%ce*ce+V[h]+d,d=(S/ie|0)+(g/ce|0)+q*P,V[h--]=S%ie;V[h]=d}return d?++w:V.splice(0,1),te(l,V,w)},r.negated=function(){var l=new x(this);return l.s=-l.s||null,l},r.plus=function(l,_){var d,w=this,m=w.s;if(l=new x(l,_),_=l.s,!m||!_)return new x(NaN);if(m!=_)return l.s=-_,w.minus(l);var h=w.e/U,y=l.e/U,g=w.c,f=l.c;if(!h||!y){if(!g||!f)return new x(m/0);if(!g[0]||!f[0])return f[0]?l:new x(g[0]?w:m*0)}if(h=Ie(h),y=Ie(y),g=g.slice(),m=h-y){for(m>0?(y=h,d=f):(m=-m,d=g),d.reverse();m--;d.push(0));d.reverse()}for(m=g.length,_=f.length,m-_<0&&(d=f,f=g,g=d,_=m),m=0;_;)m=(g[--_]=g[_]+f[_]+m)/Ae|0,g[_]=Ae===g[_]?0:g[_]%Ae;return m&&(g=[m].concat(g),++y),te(l,g,y)},r.precision=r.sd=function(l,_){var d,w,m,h=this;if(l!=null&&l!==!!l)return ne(l,1,ue),_==null?_=a:ne(_,0,8),Z(new x(h),l,_);if(!(d=h.c))return null;if(m=d.length-1,w=m*U+1,m=d[m]){for(;m%10==0;m/=10,w--);for(m=d[0];m>=10;m/=10,w++);}return l&&h.e+1>w&&(w=h.e+1),w},r.shiftedBy=function(l){return ne(l,-dn,dn),this.times("1e"+l)},r.squareRoot=r.sqrt=function(){var l,_,d,w,m,h=this,y=h.c,g=h.s,f=h.e,S=i+4,P=new x("0.5");if(g!==1||!y||!y[0])return new x(!g||g<0&&(!y||y[0])?NaN:y?h:1/0);if(g=Math.sqrt(+H(h)),g==0||g==1/0?(_=Be(y),(_.length+f)%2==0&&(_+="0"),g=Math.sqrt(+_),f=Ie((f+1)/2)-(f<0||f%2),g==1/0?_="5e"+f:(_=g.toExponential(),_=_.slice(0,_.indexOf("e")+1)+f),d=new x(_)):d=new x(g+""),d.c[0]){for(f=d.e,g=f+S,g<3&&(g=0);;)if(m=d,d=P.times(m.plus(e(h,m,S,1))),Be(m.c).slice(0,g)===(_=Be(d.c)).slice(0,g))if(d.e<f&&--g,_=_.slice(g-3,g+1),_=="9999"||!w&&_=="4999"){if(!w&&(Z(m,m.e+i+2,0),m.times(m).eq(h))){d=m;break}S+=4,g+=4,w=1}else{(!+_||!+_.slice(1)&&_.charAt(0)=="5")&&(Z(d,d.e+i+2,1),l=!d.times(d).eq(h));break}}return Z(d,d.e+i+1,a,l)},r.toExponential=function(l,_){return l!=null&&(ne(l,0,ue),l++),G(this,l,_,1)},r.toFixed=function(l,_){return l!=null&&(ne(l,0,ue),l=l+this.e+1),G(this,l,_)},r.toFormat=function(l,_,d){var w,m=this;if(d==null)l!=null&&_&&typeof _=="object"?(d=_,_=null):l&&typeof l=="object"?(d=l,l=_=null):d=M;else if(typeof d!="object")throw Error(Pe+"Argument not an object: "+d);if(w=m.toFixed(l,_),m.c){var h,y=w.split("."),g=+d.groupSize,f=+d.secondaryGroupSize,S=d.groupSeparator||"",P=y[0],I=y[1],D=m.s<0,q=D?P.slice(1):P,V=q.length;if(f&&(h=g,g=f,f=h,V-=h),g>0&&V>0){for(h=V%g||g,P=q.substr(0,h);h<V;h+=g)P+=S+q.substr(h,g);f>0&&(P+=S+q.slice(h)),D&&(P="-"+P)}w=I?P+(d.decimalSeparator||"")+((f=+d.fractionGroupSize)?I.replace(new RegExp("\\d{"+f+"}\\B","g"),"$&"+(d.fractionGroupSeparator||"")):I):P}return(d.prefix||"")+w+(d.suffix||"")},r.toFraction=function(l){var _,d,w,m,h,y,g,f,S,P,I,D,q=this,V=q.c;if(l!=null&&(g=new x(l),!g.isInteger()&&(g.c||g.s!==1)||g.lt(o)))throw Error(Pe+"Argument "+(g.isInteger()?"out of range: ":"not an integer: ")+H(g));if(!V)return new x(q);for(_=new x(o),S=d=new x(o),w=f=new x(o),D=Be(V),h=_.e=D.length-q.e-1,_.c[0]=pn[(y=h%U)<0?U+y:y],l=!l||g.comparedTo(_)>0?h>0?_:S:g,y=v,v=1/0,g=new x(D),f.c[0]=0;P=e(g,_,0,1),m=d.plus(P.times(w)),m.comparedTo(l)!=1;)d=w,w=m,S=f.plus(P.times(m=S)),f=m,_=g.minus(P.times(m=_)),g=m;return m=e(l.minus(d),w,0,1),f=f.plus(m.times(S)),d=d.plus(m.times(w)),f.s=S.s=q.s,h=h*2,I=e(S,w,h,a).minus(q).abs().comparedTo(e(f,d,h,a).minus(q).abs())<1?[S,w]:[f,d],v=y,I},r.toNumber=function(){return+H(this)},r.toPrecision=function(l,_){return l!=null&&ne(l,1,ue),G(this,l,_,2)},r.toString=function(l){var _,d=this,w=d.s,m=d.e;return m===null?w?(_="Infinity",w<0&&(_="-"+_)):_="NaN":(l==null?_=m<=c||m>=p?Nt(Be(d.c),m):Ue(Be(d.c),m,"0"):l===10&&L?(d=Z(new x(d),i+m+1,a),_=Ue(Be(d.c),d.e,"0")):(ne(l,2,E.length,"Base"),_=t(Ue(Be(d.c),m,"0"),10,l,w,!0)),w<0&&d.c[0]&&(_="-"+_)),_},r.valueOf=r.toJSON=function(){return H(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,s!=null&&x.set(s),x}function Ie(s){var e=s|0;return s>0||s===e?e:e-1}function Be(s){for(var e,t,n=1,r=s.length,o=s[0]+"";n<r;){for(e=s[n++]+"",t=U-e.length;t--;e="0"+e);o+=e}for(r=o.length;o.charCodeAt(--r)===48;);return o.slice(0,r+1||1)}function Qe(s,e){var t,n,r=s.c,o=e.c,i=s.s,a=e.s,c=s.e,p=e.e;if(!i||!a)return null;if(t=r&&!r[0],n=o&&!o[0],t||n)return t?n?0:-a:i;if(i!=a)return i;if(t=i<0,n=c==p,!r||!o)return n?0:!r^t?1:-1;if(!n)return c>p^t?1:-1;for(a=(c=r.length)<(p=o.length)?c:p,i=0;i<a;i++)if(r[i]!=o[i])return r[i]>o[i]^t?1:-1;return c==p?0:c>p^t?1:-1}function ne(s,e,t,n){if(s<e||s>t||s!==Re(s))throw Error(Pe+(n||"Argument")+(typeof s=="number"?s<e||s>t?" out of range: ":" not an integer: ":" not a primitive number: ")+String(s))}function Tt(s){var e=s.c.length-1;return Ie(s.e/U)==e&&s.c[e]%2!=0}function Nt(s,e){return(s.length>1?s.charAt(0)+"."+s.slice(1):s)+(e<0?"e":"e+")+e}function Ue(s,e,t){var n,r;if(e<0){for(r=t+".";++e;r+=t);s=r+s}else if(n=s.length,++e>n){for(r=t,e-=n;--e;r+=t);s+=r}else e<n&&(s=s.slice(0,e)+"."+s.slice(e));return s}var Me=Tn();var Nn=12;Me.config({EXPONENTIAL_AT:[-100,100],ROUNDING_MODE:4,DECIMAL_PLACES:Nn});var W=C(0),xe=C(1),ur=C("Infinity");function _e(s,e){let t=new Me(e.toString()),n=new Me(10).pow(t);return s.times(n)}function C(s){return new Me(s.toString())}var ye=(r=>(r.XYK="Xyk",r.LBP="Lbp",r.Stable="Stableswap",r.Omni="Omnipool",r))(ye||{}),Ke=(o=>(o.UnknownError="UnknownError",o.InsufficientTradingAmount="InsufficientTradingAmount",o.MaxInRatioExceeded="MaxInRatioExceeded",o.MaxOutRatioExceeded="MaxOutRatioExceeded",o.TradeNotAllowed="TradeNotAllowed",o))(Ke||{}),gn=(t=>(t.Buy="Buy",t.Sell="Sell",t))(gn||{});var De=Bt(Fn()),Te=class{static getSpotPrice(e,t,n,r,o){return(0,De.get_spot_price)(e,t,n,r,o)}static calculateInGivenOut(e,t,n,r,o){return(0,De.calculate_in_given_out)(e,t,n,r,o)}static calculateOutGivenIn(e,t,n,r,o){return(0,De.calculate_out_given_in)(e,t,n,r,o)}static calculateLinearWeights(e,t,n,r,o){return(0,De.calculate_linear_weights)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,De.calculate_pool_trade_fee)(e,t,n)}};var kn=require("@polkadot/util-crypto"),En=require("@polkadot/util"),et=18,Rt=15,We="0",wr=12,Pr=2034,tt=63,yr=2090,Mt=1e3,ht=(0,kn.encodeAddress)((0,En.stringToU8a)("modlomnipool".padEnd(32,"\0")),tt);var Bo=require("@polkadot/types/lookup");var Io=require("@polkadot/api-base/types/consts");var To=require("@polkadot/api-base/types/errors");var No=require("@polkadot/api-base/types/events");var Ao=require("@polkadot/api-base/types/storage");var Fo=require("@polkadot/api-base/types/submittable");var ko=require("@polkadot/rpc-core/types/jsonrpc");var Eo=require("@polkadot/api-base/types/calls");var Ho=require("@polkadot/types/types/registry");var Xo=require("@polkadot/types/lookup");var Yo=require("@polkadot/api-base/types/consts");var $o=require("@polkadot/api-base/types/errors");var Vo=require("@polkadot/api-base/types/events");var jo=require("@polkadot/api-base/types/storage");var Jo=require("@polkadot/api-base/types/submittable");var Zo=require("@polkadot/rpc-core/types/jsonrpc");var Qo=require("@polkadot/api-base/types/calls");var si=require("@polkadot/types/types/registry");var nt=class{api;constructor(e){this.api=e}get chainDecimals(){return this.api.registry.chainDecimals[0]}get chainToken(){return this.api.registry.chainTokens[0]}};var rt=class extends nt{SUPPORTED_TYPES=["StableSwap","Bond","Token"];constructor(e){super(e)}async safeSharesQuery(){try{let e=await this.api.query.stableswap.pools.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}async safeBondsQuery(){try{let e=await this.api.query.bonds.bonds.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}async metadataQuery(){try{let e=await this.api.query.assetRegistry.assetMetadataMap.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}getTokenMetadata(e,t,n){if(e==We){let p=this.api.consts.balances.existentialDeposit;return{id:We,name:this.chainToken,symbol:this.chainToken,decimals:this.chainDecimals,icon:this.chainToken,assetType:"Token",existentialDeposit:p.toString()}}let{name:r,assetType:o,existentialDeposit:i}=t,{symbol:a,decimals:c}=n.get(e);return{id:e,name:r.toHuman(),symbol:a.toHuman(),decimals:c.toNumber(),icon:a.toHuman(),assetType:o.toHuman(),existentialDeposit:i.toString()}}getBondMetadata(e,t,n,r){let[o,i]=r,{assetType:a,existentialDeposit:c}=t,{symbol:p,decimals:b}=this.getTokenMetadata(o.toString(),t,n),v=i.toNumber(),B=new Intl.DateTimeFormat("en-GB"),A=[p,"Bond",B.format(v)].join(" ");return{id:e,name:A,symbol:p+"b",decimals:b,icon:p,assetType:a.toString(),existentialDeposit:c.toString()}}getShareMetadata(e,t,n,r){let{assets:o}=r,{name:i,assetType:a,existentialDeposit:c}=t,b=o.map(A=>A.toString()).map(A=>{let{symbol:k}=this.getTokenMetadata(A,t,n);return[A,k]}),v=Object.fromEntries(b),B=Object.values(v);return{id:e,name:B.join(", "),symbol:i.length>0?i.toHuman():e,decimals:18,icon:B.join("/"),assetType:a.toString(),existentialDeposit:c.toString(),meta:v}}async getOnChainMetadata(){let[e,t,n,r]=await Promise.all([this.api.query.assetRegistry.assets.entries(),this.metadataQuery(),this.safeSharesQuery(),this.safeBondsQuery()]);return e.filter(([o,i])=>this.isSupportedType(i.unwrap())).map(([{args:[o]},i])=>{let a=i.unwrap(),{assetType:c}=a;switch(c.toString()){case"Bond":let p=r.get(o.toString());return this.getBondMetadata(o.toString(),a,t,p);case"StableSwap":let b=n.get(o.toString());return this.getShareMetadata(o.toString(),a,t,b);default:return this.getTokenMetadata(o.toString(),a,t)}})}isSupportedType(e){return this.SUPPORTED_TYPES.includes(e.assetType.toString())}};var ot=class extends nt{constructor(e){super(e)}async getBalance(e,t){return t===We?await this.getSystemBalance(e):await this.getTokenBalance(e,t)}async getSystemBalance(e){let{data:{free:t,miscFrozen:n,feeFrozen:r}}=await this.api.query.system.account(e);return this.calculateFreeBalance(t.toString(),n.toString(),r.toString())}async getTokenBalance(e,t){let{free:n,reserved:r,frozen:o}=await this.api.query.tokens.accounts(e,t);return this.calculateFreeBalance(n.toString(),W.toFixed(),o.toString())}async subscribeBalance(e,t,n){let r=t.filter(o=>o!==We).map(o=>[e,o]);return this.api.query.tokens.accounts.multi(r,o=>{o.forEach(({free:i,reserved:a,frozen:c},p)=>{let b=this.calculateFreeBalance(i.toString(),a.toString(),c.toString()),v=r[p][1];n(v,b)})})}async subscribeTokenBalance(e,t,n){let r=t.filter(o=>o!==We).map(o=>[e,o]);return this.api.query.tokens.accounts.multi(r,o=>{o.forEach(({free:i,frozen:a},c)=>{let p=this.calculateFreeBalance(i.toString(),W.toFixed(),a.toString()),b=r[c][1];n(b,p)})})}async subscribeSystemBalance(e,t){return this.api.query.system.account(e,({data:{free:n,miscFrozen:r,feeFrozen:o}})=>{let i=this.calculateFreeBalance(n.toString(),r.toString(),o.toString());t(We,i)})}calculateFreeBalance(e,t,n){let r=new Me(e),o=new Me(t),i=new Me(n),a=o.gt(i)?o:i;return r.minus(a)}};var Ce=class extends ot{pools=[];subs=[];poolsLoaded=!1;constructor(e){super(e)}async getPools(){return this.poolsLoaded?this.pools:(this.pools=await this.loadPools(),this.subs=await this.subscribe(),this.poolsLoaded=!0,this.pools)}async subscribe(){let e=this.pools.map(async n=>{let r=[await this.subscribePoolChange(n),await this.subscribeTokensPoolBalance(n),await this.subscribeSystemPoolBalance(n)];if(this.hasShareAsset(n)){let o=await this.subscribeSharePoolBalance(n);r.push(o)}return this.subscribeLog(n),r});return(await Promise.all(e)).flat()}subscribeLog(e){let t=e.address.substring(0,10).concat("...");console.log(`${e.type} [${t}] balance subscribed`)}unsubscribe(){this.subs.forEach(e=>{e()})}hasShareAsset(e){return e.type==="Stableswap"&&e.id}subscribeTokensPoolBalance(e){return this.subscribeTokenBalance(e.address,e.tokens.map(t=>t.id),this.updateBalanceCallback(e,(t,n)=>t.id!==n))}subscribeSharePoolBalance(e){return this.subscribeTokenBalance(ht,[e.id],this.updateBalanceCallback(e,()=>!0))}subscribeSystemPoolBalance(e){return this.subscribeSystemBalance(e.address,this.updateBalanceCallback(e,()=>!0))}updateBalanceCallback(e,t){return function(n,r){let o=e.tokens.findIndex(i=>i.id==n);o>=0&&t(e,n)&&(e.tokens[o].balance=r.toString())}}};var Lt=class extends Ce{MAX_FINAL_WEIGHT=_e(C(100),6);poolsData=new Map([]);async loadPools(){let[e,t]=await Promise.all([this.api.query.lbp.poolData.entries(),this.api.query.parachainSystem.validationData()]),{relayParentNumber:n}=t.unwrap(),r=e.filter(([o,i])=>this.isActivePool(i.unwrap(),n)).map(async([{args:[o]},i])=>{let a=i.unwrap(),c=o.toString(),p=await this.getPoolDelta(c,a,n.toString());return this.poolsData.set(o.toString(),a),{address:c,type:"Lbp",fee:a.fee.toJSON(),...p,...this.getPoolLimits()}});return Promise.all(r)}async getPoolFees(e,t){let n=this.pools.find(r=>r.address===t);return{repayFee:this.getRepayFee(),exchangeFee:n.fee}}getPoolType(){return"Lbp"}async subscribePoolChange(e){return this.api.query.parachainSystem.validationData(async t=>{let{relayParentNumber:n}=t.unwrap(),r=this.poolsData.get(e.address);if(this.isActivePool(r,n)){let i=await this.getPoolDelta(e.address,r,n.toString());e={...e,...i}}else{let i=this.pools.findIndex(a=>a.address==e.address);this.pools.splice(i,1)}})}async getPoolDelta(e,t,n){let{start:r,end:o,assets:i,initialWeight:a,finalWeight:c,repayTarget:p,feeCollector:b}=t,v=Te.calculateLinearWeights(r.toString(),o.toString(),a.toString(),c.toString(),n),[B,A]=i,k=B.toString(),M=C(v),E=A.toString(),L=this.MAX_FINAL_WEIGHT.minus(C(M)),[x,G,J]=await Promise.all([this.isRepayFeeApplied(k,p.toString(),b.toString()),this.getBalance(e,k),this.getBalance(e,E)]);return{repayFeeApply:x,tokens:[{id:k,weight:M,balance:G.toString()},{id:E,weight:L,balance:J.toString()}]}}isActivePool(e,t){let n=e.start.unwrap().toNumber(),r=e.end.unwrap().toNumber();return t.toNumber()>=n&&t.toNumber()<r}async isRepayFeeApplied(e,t,n){let r=C(t);if(r.isZero())return!1;try{return(await this.getBalance(e,n)).isLessThan(r)}catch{return!0}}getRepayFee(){return this.api.consts.lbp.repayFee.toJSON()}getPoolLimits(){let e=this.api.consts.lbp.maxInRatio.toJSON(),t=this.api.consts.lbp.maxOutRatio.toJSON(),n=this.api.consts.lbp.minTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Rn=require("@polkadot/util-crypto"),Mn=require("@polkadot/util");function ge(s,e){return s.shiftedBy(-1*e).toString()}function Ne(s){return s[0]/s[1]*100}function Se(s){return s[0]/s[1]}function Fe(s){return[s/Mt,Mt]}var Dt=class extends Ce{async loadPools(){let e=this.api.consts.omnipool.hubAssetId.toString(),t=this.getPoolId(),[n,r,o]=await Promise.all([this.api.query.omnipool.assets.entries(),this.api.query.omnipool.hubAssetTradability(),this.getBalance(t,e)]),i=n.map(async([{args:[c]},p])=>{let{hubReserve:b,shares:v,tradable:B}=p.unwrap(),A=await this.getBalance(t,c.toString());return{id:c.toString(),hubReserves:C(b.toString()),shares:C(v.toString()),tradeable:B.bits.toNumber(),balance:A.toString()}}),a=await Promise.all(i);return a.push({id:e,tradeable:r.bits.toNumber(),balance:o.toString()}),[{address:t,type:"Omnipool",hubAssetId:e,tokens:a,...this.getPoolLimits()}]}async getPoolFees(e,t){let n=await this.api.query.dynamicFees.assetFee(e),r=this.api.consts.dynamicFees.assetFeeParameters,o=this.api.consts.dynamicFees.protocolFeeParameters,i=r.minFee.toNumber()+o.minFee.toNumber(),a=r.maxFee.toNumber()+o.maxFee.toNumber();if(n.isSome){let{assetFee:c,protocolFee:p}=n.unwrap();return{assetFee:Fe(c.toNumber()),protocolFee:Fe(p.toNumber()),min:Fe(i),max:Fe(a)}}else return{assetFee:this.getAssetFee(),protocolFee:this.getProtocolFee(),min:Fe(i),max:Fe(a)}}getPoolType(){return"Omnipool"}async subscribePoolChange(e){let t=e.tokens.map(n=>n.id);return this.api.query.omnipool.assets.multi(t,n=>{e.tokens=n.map((r,o)=>{let i=e.tokens[o];if(r.isNone)return i;let a=r.unwrap();return this.updateTokenState(i,a)})})}updateTokenState(e,t){let{hubReserve:n,shares:r,tradable:o}=t;return{...e,hubReserves:C(n.toString()),shares:C(r.toString()),tradeable:o.bits.toNumber()}}getAssetFee(){let t=this.api.consts.dynamicFees.assetFeeParameters.minFee.toNumber();return Fe(t)}getProtocolFee(){let t=this.api.consts.dynamicFees.protocolFeeParameters.minFee.toNumber();return Fe(t)}getPoolId(){return(0,Rn.encodeAddress)((0,Mn.stringToU8a)("modlomnipool".padEnd(32,"\0")),tt)}getPoolLimits(){let e=this.api.consts.omnipool.maxInRatio.toJSON(),t=this.api.consts.omnipool.maxOutRatio.toJSON(),n=this.api.consts.omnipool.minimumTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Ct=class extends Ce{async loadPools(){let t=(await this.api.query.xyk.poolAssets.entries()).map(async([{args:[n]},r])=>{let o=n.toString(),[i,a]=r.unwrap(),[c,p]=await Promise.all([this.getBalance(o,i.toString()),this.getBalance(o,a.toString())]);return{address:o,type:"Xyk",tokens:[{id:i.toString(),balance:c.toString()},{id:a.toString(),balance:p.toString()}],...this.getPoolLimits()}});return Promise.all(t)}async getPoolFees(e,t){return{exchangeFee:this.getExchangeFee()}}getPoolType(){return"Xyk"}subscribePoolChange(e){return this.api.query.xyk.poolAssets(e.address,t=>{})}getExchangeFee(){return this.api.consts.xyk.getExchangeFee.toJSON()}getPoolLimits(){let e=this.api.consts.xyk.maxInRatio.toJSON(),t=this.api.consts.xyk.maxOutRatio.toJSON(),n=this.api.consts.xyk.minTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Wt=require("@polkadot/util-crypto");var pe=Bt(Dn()),ve=class{static getPoolAddress(e){return(0,pe.pool_account_name)(e)}static calculateAmplification(e,t,n,r,o){return(0,pe.calculate_amplification)(e,t,n,r,o)}static calculateInGivenOut(e,t,n,r,o,i){return(0,pe.calculate_in_given_out)(e,t,n,r,o,i)}static calculateAddOneAsset(e,t,n,r,o,i){return(0,pe.calculate_add_one_asset)(e,t,n,r,o,i)}static calculateSharesForAmount(e,t,n,r,o,i){return(0,pe.calculate_shares_for_amount)(e,t,n,r,o,i)}static calculateOutGivenIn(e,t,n,r,o,i){return(0,pe.calculate_out_given_in)(e,t,n,r,o,i)}static calculateLiquidityOutOneAsset(e,t,n,r,o,i){return(0,pe.calculate_liquidity_out_one_asset)(e,t,n,r,o,i)}static calculateShares(e,t,n,r,o){return(0,pe.calculate_shares)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,pe.calculate_pool_trade_fee)(e,t,n)}};var Ut=class extends Ce{stablePools=new Map([]);async loadPools(){let[e,t]=await Promise.all([this.api.query.stableswap.pools.entries(),this.api.query.system.number()]),n=t.toNumber(),r=e.map(async([{args:[o]},i])=>{let a=i.unwrap(),c=o.toString(),p=this.getPoolAddress(c),[b,v]=await Promise.all([this.getPoolDelta(c,a,n.toString()),this.getPoolTokens(p,c,a)]);return this.stablePools.set(p,a),{address:p,id:c,type:"Stableswap",fee:Fe(a.fee.toNumber()),tokens:v,...b,...this.getPoolLimits()}});return Promise.all(r)}async getPoolFees(e,t){return{fee:this.pools.find(r=>r.address===t).fee}}getPoolType(){return"Stableswap"}async subscribePoolChange(e){return this.api.query.system.number(async t=>{let n=t.toNumber(),r=this.stablePools.get(e.address),o=await this.getPoolDelta(e.id,r,n.toString());e={...e,...o}})}async getPoolDelta(e,t,n){let{initialAmplification:r,finalAmplification:o,initialBlock:i,finalBlock:a}=t,c=ve.calculateAmplification(r.toString(),o.toString(),i.toString(),a.toString(),n),p=await this.api.query.tokens.totalIssuance(e);return{amplification:c,totalIssuance:p.toString()}}async getPoolTokens(e,t,n){let{assets:r}=n,o=r.map(async c=>{let[p,b]=await Promise.all([this.api.query.stableswap.assetTradability(t,c.toString()),this.getBalance(e,c.toString())]);return{id:c.toString(),tradeable:p.bits.toNumber(),balance:b.toString()}}),i=await Promise.all(o),a=await this.api.query.omnipool.assets(t);if(a.isSome){let{tradable:c}=a.unwrap(),p=await this.getBalance(ht,t);i.push({id:t,tradeable:c.bits.toNumber(),balance:p.toString()})}return i}getPoolAddress(e){let t=Number(e),n=ve.getPoolAddress(t);return(0,Wt.encodeAddress)((0,Wt.blake2AsHex)(n),tt)}getPoolLimits(){return{maxInRatio:0,maxOutRatio:0,minTradingLimit:this.api.consts.stableswap.minTradingLimit.toJSON()}}};function zt(s){return s.map(({assetIn:e,assetOut:t,pool:n,poolId:r})=>n==="Stableswap"?{pool:{Stableswap:r},assetIn:e,assetOut:t}:{pool:n,assetIn:e,assetOut:t})}var wt=class extends Error{constructor(e){super(),this.message=`${e} pool invalid`,this.name="PoolNotFound"}},mn=class extends Error{constructor(e,t){super(),this.message=`${e} pool missing ${t}`,this.name="PoolConfigNotFound"}},it=class extends Error{constructor(e,t){super(),this.message=`Route from ${e} to ${t} not found in pool configuration`,this.name="RouteNotFound"}},fn=class extends Error{constructor(e){super(),this.message=`Asset ${e} not available in current network`,this.name="AssetNotFound"}},hn=class extends Error{constructor(e){super(),this.message=`Storage missing ${e}`,this.name="StorageConfigNotFound"}},bn=class extends Error{constructor(e){super(),this.message=`Subscription type "${e}" not supported`,this.name="SubscriptionNotSupported"}},wn=class extends Error{constructor(e){super(),this.message=`${e}`,this.name="ProviderConfigNotFound"}};var st=class{api;assetClient;xykClient;omniClient;lbpClient;stableClient;metadata=[];metadataLoaded=!1;constructor(e){this.api=e,this.assetClient=new rt(this.api),this.xykClient=new Ct(this.api),this.omniClient=new Dt(this.api),this.lbpClient=new Lt(this.api),this.stableClient=new Ut(this.api)}async getPools(e){if(this.metadataLoaded||(this.metadata=await this.assetClient.getOnChainMetadata(),this.metadataLoaded=!0),e.length==0){let i=(await Promise.all([this.xykClient.getPools(),this.omniClient.getPools(),this.lbpClient.getPools(),this.stableClient.getPools()])).flat();return this.withMetadata(i)}let t=[];e.forEach(o=>{switch(o){case"Xyk":t.push(this.xykClient.getPools());break;case"Omnipool":t.push(this.omniClient.getPools());break;case"Lbp":t.push(this.lbpClient.getPools());break;case"Stableswap":t.push(this.stableClient.getPools());break}});let r=(await Promise.all(t)).flat();return this.withMetadata(r)}unsubscribe(){this.xykClient.unsubscribe(),this.omniClient.unsubscribe(),this.lbpClient.unsubscribe(),this.stableClient.unsubscribe()}async withMetadata(e){let t=new Map(this.metadata.map(n=>[n.id,n]));return e.map(n=>{let r=n.tokens.map(o=>{let i=t.get(o.id);return{...o,...i}});return{...n,tokens:r}})}async getPoolFees(e,t){switch(t.type){case"Xyk":return this.xykClient.getPoolFees(e,t.address);case"Omnipool":return this.omniClient.getPoolFees(e,t.address);case"Lbp":return this.lbpClient.getPoolFees(e,t.address);case"Stableswap":return this.stableClient.getPoolFees(e,t.address);default:throw new wt(t.type)}}isDirectOmnipoolTrade(e){return e.length==1&&e[0].pool=="Omnipool"}buildBuyTx(e,t,n,r,o){let i;this.isDirectOmnipoolTrade(o)?i=this.api.tx.omnipool.buy(t,e,n.toFixed(),r.toFixed()):i=this.api.tx.router.buy(e,t,n.toFixed(),r.toFixed(),zt(o));let a=()=>i;return{hex:i.toHex(),name:"RouterBuy",get:a}}buildSellTx(e,t,n,r,o){let i;this.isDirectOmnipoolTrade(o)?i=this.api.tx.omnipool.sell(e,t,n.toFixed(),r.toFixed()):i=this.api.tx.router.sell(e,t,n.toFixed(),r.toFixed(),zt(o));let a=()=>i;return{hex:i.toHex(),name:"RouterSell",get:a}}};var Pt=(s,e)=>s===e?0:s==null?e==null?0:-1:e==null?s==null?0:1:typeof s.compare=="function"?s.compare(e):typeof e.compare=="function"?-e.compare(s):s<e?-1:s>e?1:0;var Xt=(s,e=t=>t!==void 0?": "+t:"")=>class extends Error{constructor(t){super(s(t)+e(t))}};var Fr=Xt(()=>"illegal argument(s)"),Cn=s=>{throw new Fr(s)};var kr=Xt(()=>"index out of bounds"),Pn=s=>{throw new kr(s)},Yt=(s,e,t)=>(s<e||s>=t)&&Pn(s);var qn=23283064365386963e-26,$t=class{float(e=1){return this.int()*qn*e}norm(e=1){return(this.int()*qn-.5)*2*e}normMinMax(e,t){let n=this.minmax(e,t);return this.float()<.5?n:-n}minmax(e,t){return this.float()*(t-e)+e}minmaxInt(e,t){return e|=0,t|=0,e+(this.float()*(t-e)|0)}};var yn=Math.random,Sn=class extends $t{int(){return yn()*4294967296>>>0}float(e=1){return yn()*e}norm(e=1){return(yn()-.5)*2*e}},Gn=new Sn;var Hn=s=>s!=null&&typeof s!="function"&&s.length!==void 0;var Un=Object.getPrototypeOf({}),Vt="function",Wn="string",at=(s,e)=>{let t;if(s===e)return!0;if(s!=null){if(typeof s.equiv===Vt)return s.equiv(e)}else return s==e;if(e!=null){if(typeof e.equiv===Vt)return e.equiv(s)}else return s==e;return typeof s===Wn||typeof e===Wn?!1:(t=Object.getPrototypeOf(s),(t==null||t===Un)&&(t=Object.getPrototypeOf(e),t==null||t===Un)?Lr(s,e):typeof s!==Vt&&s.length!==void 0&&typeof e!==Vt&&e.length!==void 0?Er(s,e):s instanceof Set&&e instanceof Set?Rr(s,e):s instanceof Map&&e instanceof Map?Mr(s,e):s instanceof Date&&e instanceof Date?s.getTime()===e.getTime():s instanceof RegExp&&e instanceof RegExp?s.toString()===e.toString():s!==s&&e!==e)},Er=(s,e,t=at)=>{let n=s.length;if(n===e.length)for(;n-- >0&&t(s[n],e[n]););return n<0},Rr=(s,e,t=at)=>s.size===e.size&&t([...s.keys()].sort(),[...e.keys()].sort()),Mr=(s,e,t=at)=>s.size===e.size&&t([...s].sort(),[...e].sort()),Lr=(s,e,t=at)=>{if(Object.keys(s).length!==Object.keys(e).length)return!1;for(let n in s)if(!e.hasOwnProperty(n)||!t(s[n],e[n]))return!1;return!0};var zn=(s,e)=>s!=null&&typeof s[e]=="function";var Xn=s=>zn(s,"xform")?s.xform():s;var jt=Symbol(),xn=()=>{};var Yn=s=>s!=null&&typeof s[Symbol.iterator]=="function";var Jt=class{constructor(e){this.value=e}deref(){return this.value}};var Zt=s=>s instanceof Jt;var $n=s=>s instanceof Jt?s.deref():s;function*Vn(s,e){let t=Xn(s)([xn,xn,(n,r)=>r])[2];for(let n of e){let r=t(jt,n);if(Zt(r)){r=$n(r.deref()),r!==jt&&(yield r);return}r!==jt&&(yield r)}}var jn=(s,e)=>[s[0],s[1],e];function yt(s,e){return Yn(e)?Vn(yt(s),e):t=>{let n=t[2];return jn(t,(r,o)=>n(r,s(o)))}}var lt=class{constructor(e){this._length=0,e&&this.into(e)}get length(){return this._length}get head(){return this._head}[Symbol.iterator](){return Jn("next",this._head)}reverseIterator(){return Jn("prev",this.tail)}clear(){this.release()}compare(e,t=Pt){let n=this._length;if(n<e._length)return-1;if(n>e._length)return 1;if(n===0)return 0;{let r=this._head,o=e._head,i=0;for(;n-- >0&&i===0;)i=t(r.value,o.value),r=r.next,o=o.next;return i}}concat(...e){let t=this.copy();for(let n of e)t.into(n);return t}equiv(e){if(!(e instanceof lt||Hn(e))||this._length!==e.length)return!1;if(!this._length||this===e)return!0;let t=e[Symbol.iterator](),n=this._head;for(let r=this._length;r-- >0;){if(!at(n.value,t.next().value))return!1;n=n.next}return!0}filter(e){let t=this.empty();return this.traverse(n=>(e(n.value)&&t.append(n.value),!0)),t}find(e){return this.traverse(t=>t.value!==e)}findWith(e){return this.traverse(t=>!e(t.value))}first(){return this._head&&this._head.value}insertSorted(e,t){t=t||Pt;for(let n=this._head,r=this._length;r-- >0;){if(t(e,n.value)<=0)return this.insertBefore(n,e);n=n.next}return this.append(e)}into(e){for(let t of e)this.append(t);return this}nth(e,t){let n=this.nthCell(e);return n?n.value:t}nthCellUnsafe(e){let t,n;for(e<=this._length>>>1?(t=this._head,n="next"):(t=this.tail,n="prev",e=this._length-e-1);e-- >0&&t;)t=t[n];return t}peek(){return this.tail&&this.tail.value}$reduce(e,t){let n=this._head;for(let r=this._length;r-- >0&&!Zt(t);)t=e(t,n.value),n=n.next;return t}reduce(e,t){return this.$reduce(e,t)}release(){let e=this._head;if(!e)return!0;let t;for(let n=this._length;n-- >0;)t=e.next,delete e.value,delete e.prev,delete e.next,e=t;return this._head=void 0,this._length=0,!0}reverse(){let e=this._head,t=this.tail,n=(this._length>>>1)+(this._length&1);for(;e&&t&&n>0;){let r=e.value;e.value=t.value,t.value=r,e=e.next,t=t.prev,n--}return this}setHead(e){let t=this._head;return t?(t.value=e,t):this.prepend(e)}setNth(e,t){let n=this.nthCell(e);return!n&&Pn(e),n.value=t,n}setTail(e){let t=this.tail;return t?(t.value=e,t):this.append(e)}swap(e,t){if(e!==t){let n=e.value;e.value=t.value,t.value=n}return this}toArray(e=[]){return this.traverse(t=>(e.push(t.value),!0)),e}toJSON(){return this.toArray()}toString(){let e=[];return this.traverse(t=>(e.push(String(t.value)),!0)),e.join(", ")}traverse(e,t=this._head,n){if(!this._head)return;let r=t;do{if(!e(r))break;r=r.next}while(r!==n);return r}_map(e,t){return this.traverse(n=>(e.append(t(n.value)),!0)),e}};function*Jn(s,e){for(;e;)yield e.value,e=e[s]}var qe=class extends lt{get tail(){return this._tail}append(e){if(this._tail){let t={value:e,prev:this._tail};return this._tail.next=t,this._tail=t,this._length++,t}else return this.prepend(e)}asHead(e){return e===this._head?this:(this.remove(e),this._head.prev=e,e.next=this._head,e.prev=void 0,this._head=e,this._length++,this)}asTail(e){return e===this._tail?this:(this.remove(e),this._tail.next=e,e.prev=this._tail,e.next=void 0,this._tail=e,this._length++,this)}cons(e){return this.prepend(e),this}copy(){return new qe(this)}*cycle(){for(;;)yield*this}drop(){let e=this._head;if(e)return this._head=e.next,this._head?this._head.prev=void 0:this._tail=void 0,this._length--,e.value}empty(){return new qe}insertAfter(e,t){let n={value:t,next:e.next,prev:e};return e.next?e.next.prev=n:this._tail=n,e.next=n,this._length++,n}insertAfterNth(e,t){return e<0&&(e+=this._length),e>=this._length-1?this.append(t):(Yt(e,0,this._length),this.insertAfter(this.nthCellUnsafe(e),t))}insertBefore(e,t){let n={value:t,next:e,prev:e.prev};return e.prev?e.prev.next=n:this._head=n,e.prev=n,this._length++,n}insertBeforeNth(e,t){return e<0&&(e+=this._length),e<=0?this.prepend(t):(Yt(e,0,this._length),this.insertBefore(this.nthCellUnsafe(e),t))}map(e){return this._map(new qe,e)}nth(e,t){let n=this.nthCell(e);return n?n.value:t}nthCell(e){if(e<0&&(e+=this._length),!(e<0||e>=this._length))return this.nthCellUnsafe(e)}pop(){let e=this._tail;if(e)return this._tail=e.prev,this._tail?this._tail.next=void 0:this._head=void 0,this._length--,e.value}prepend(e){let t={value:e,next:this._head};return this._head?this._head.prev=t:this._tail=t,this._head=t,this._length++,t}push(e){return this.append(e),this}release(){return this._tail=void 0,super.release()}remove(e){return e.prev?e.prev.next=e.next:this._head=e.next,e.next?e.next.prev=e.prev:this._tail=e.prev,this._length--,this}rotateLeft(){switch(this._length){case 0:case 1:return this;case 2:return this.swap(this._head,this._tail);default:return this.push(this.drop())}}rotateRight(){switch(this._length){case 0:case 1:return this;case 2:return this.swap(this._head,this._tail);default:let e=this.peek();return this.pop(),this.prepend(e),this}}seq(e=0,t=this.length){if(e>=t||e<0)return;let n=this.nthCell(e),r=this.nthCell(t-1),o=i=>({first(){return i.value},next(){return i!==r&&i.next?o(i.next):void 0}});return n?o(n):void 0}shuffle(e,t=Gn){if(this._length<2)return this;for(e=e!==void 0?e:Math.ceil(1.5*Math.log2(this._length));e>0;e--){let n=this._head;for(;n;){let r=n.next;t.float()<.5?this.asHead(n):this.asTail(n),n=r}}return this}slice(e=0,t=this.length){let n=e<0?e+this._length:e,r=t<0?t+this._length:t;(n<0||r<0)&&Cn("invalid indices: ${from} / ${to}");let o=new qe,i=this.nthCell(n);for(;i&&++n<=r;)o.push(i.value),i=i.next;return o}sort(e=Pt){if(!this._length)return this;let t=1;for(;;){let n=this._head;this._head=void 0,this._tail=void 0;let r=0;for(;n;){r++;let o=n,i=0;for(let c=0;c<t&&(i++,o=o.next,!!o);c++);let a=t;for(;i>0||a>0&&o;){let c;i===0?(c=o,o=o.next,a--):!o||a===0||e(n.value,o.value)<=0?(c=n,n=n.next,i--):(c=o,o=o.next,a--),this._tail?this._tail.next=c:this._head=c,c.prev=this._tail,this._tail=c}n=o}if(this._tail.next=void 0,r<=1)return this;t*=2}}splice(e,t=0,n){let r;typeof e=="number"?(e<0&&(e+=this._length),Yt(e,0,this._length),r=this.nthCellUnsafe(e)):r=e;let o=new qe;if(t>0)for(;r&&t-- >0;)this.remove(r),o.push(r.value),r=r.next;else r&&(r=r.next);if(n)if(r)for(let i of n)this.insertBefore(r,i);else for(let i of n)this.push(i);return o}};var ct=class{constructor(e,t){let n=Object.assign({maxlen:1/0,maxsize:1/0,map:()=>new Map,ksize:()=>0,vsize:()=>0},t);this.map=n.map(),this.items=new qe,this._size=0,this.opts=n,e&&this.into(e)}get length(){return this.items.length}get size(){return this._size}[Symbol.iterator](){return this.entries()}entries(){return yt(e=>[e.k,e],this.items)}keys(){return yt(e=>e.k,this.items)}values(){return yt(e=>e.v,this.items)}copy(){let e=this.empty();e.items=this.items.copy();let t=e.items.head;for(;t;)e.map.set(t.value.k,t),t=t.next;return e}empty(){return new ct(null,this.opts)}release(){this._size=0,this.map.clear();let e=this.opts.release;if(e){let t;for(;t=this.items.drop();)e(t.k,t.v);return!0}return this.items.release()}has(e){return this.map.has(e)}get(e,t){let n=this.map.get(e);return n?this.resetEntry(n):t}set(e,t){let n=this.opts.ksize(e)+this.opts.vsize(t),r=this.map.get(e);return this._size+=Math.max(0,n-(r?r.value.s:0)),this.ensureSize()&&this.doSetEntry(r,e,t,n),t}into(e){for(let t of e)this.set(t[0],t[1]);return this}getSet(e,t){let n=this.map.get(e);return n?Promise.resolve(this.resetEntry(n)):t().then(r=>this.set(e,r))}delete(e){let t=this.map.get(e);return t?(this.removeEntry(t),!0):!1}resetEntry(e){return this.items.asTail(e),e.value.v}ensureSize(){let e=this.opts.release,t=this.opts.maxsize,n=this.opts.maxlen;for(;this._size>t||this.length>=n;){let r=this.items.drop();if(!r)return!1;this.map.delete(r.k),e&&e(r.k,r.v),this._size-=r.s}return!0}removeEntry(e){let t=e.value;this.map.delete(t.k),this.items.remove(e),this.opts.release&&this.opts.release(t.k,t.v),this._size-=t.s}doSetEntry(e,t,n,r){e?(e.value.v=n,e.value.s=r,this.items.asTail(e)):(this.items.push({k:t,v:n,s:r}),this.map.set(t,this.items.tail))}};var Qt=class extends st{feeCache;disconnectSubscribeNewHeads=null;constructor(e){super(e),this.feeCache=new ct(null),this.api.rpc.chain.subscribeNewHeads(async t=>{this.feeCache.release()}).then(t=>{this.disconnectSubscribeNewHeads=t})}async getPoolFees(e,t){let n=[t.address,e].join("-");if(this.feeCache.has(n))return this.feeCache.get(n);{let o=await super.getPoolFees(e,t);return this.feeCache.set(n,o),o}}async destroy(){console.log(`Destroying pool cache!
2
- Items: [${this.feeCache.length}]`),this.feeCache.release(),this.disconnectSubscribeNewHeads?.()}};var Ye=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;fee;repayFeeApply;static fromPool(e){return new Ye(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.fee,e.repayFeeApply)}constructor(e,t,n,r,o,i,a){this.type="Lbp",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.fee=i,this.repayFeeApply=a}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,balanceIn:i,balanceOut:a,decimalsIn:r.decimals,decimalsOut:o.decimals,weightIn:r.weight,weightOut:o.weight}}validateAndBuy(e,t,n){let r=this.tokens[0].id,o=[];t.isLessThan(this.minTradingLimit)&&o.push("InsufficientTradingAmount");let i=e.balanceOut.div(this.maxOutRatio);if(t.isGreaterThan(i)&&o.push("MaxOutRatioExceeded"),r===e.assetOut){let a=this.calculateTradeFee(t,n),c=Ne(this.repayFeeApply?n.repayFee:n.exchangeFee),p=t.plus(a),b=this.calculateInGivenOut(e,p),v=e.balanceIn.div(this.maxInRatio);return b.isGreaterThan(v)&&o.push("MaxInRatioExceeded"),{amountIn:b,calculatedIn:b,amountOut:t,feePct:c,errors:o}}else{let a=this.calculateInGivenOut(e,t),c=e.balanceIn.div(this.maxInRatio);return a.isGreaterThan(c)&&o.push("MaxInRatioExceeded"),{amountIn:a,calculatedIn:a,amountOut:t,feePct:0,errors:o}}}validateAndSell(e,t,n){let r=this.tokens[0].id,o=[];t.isLessThan(this.minTradingLimit)&&o.push("InsufficientTradingAmount");let i=e.balanceIn.div(this.maxInRatio);if(t.isGreaterThan(i)&&o.push("MaxInRatioExceeded"),r===e.assetIn){let a=this.calculateOutGivenIn(e,t),c=e.balanceOut.div(this.maxOutRatio);return a.isGreaterThan(c)&&o.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:a,amountOut:a,feePct:0,errors:o}}else{let a=this.calculateOutGivenIn(e,t),c=this.calculateTradeFee(a,n),p=Ne(this.repayFeeApply?n.repayFee:n.exchangeFee),b=a.minus(c),v=e.balanceOut.div(this.maxOutRatio);return b.isGreaterThan(v)&&o.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:a,amountOut:b,feePct:p,errors:o}}}calculateInGivenOut(e,t){let n=Te.calculateInGivenOut(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}calculateOutGivenIn(e,t){let n=Te.calculateOutGivenIn(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}spotPriceInGivenOut(e){let t=Te.getSpotPrice(e.balanceOut.toString(),e.balanceIn.toString(),e.weightOut.toString(),e.weightIn.toString(),_e(xe,e.decimalsOut).toString());return C(t)}spotPriceOutGivenIn(e){let t=Te.getSpotPrice(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),_e(xe,e.decimalsIn).toString());return C(t)}calculateTradeFee(e,t){let n=Te.calculatePoolTradeFee(e.toString(),this.repayFeeApply?t.repayFee[0]:t.exchangeFee[0],this.repayFeeApply?t.repayFee[1]:t.exchangeFee[1]);return C(n)}};var Y=Bt(Qn()),ae=class{static calculateSpotPrice(e,t,n,r){return(0,Y.calculate_spot_price)(e,t,n,r)}static calculateLrnaSpotPrice(e,t){return(0,Y.calculate_lrna_spot_price)(e,t)}static calculateInGivenOut(e,t,n,r,o,i,a,c,p){return(0,Y.calculate_in_given_out)(e,t,n,r,o,i,a,c,p)}static calculateLrnaInGivenOut(e,t,n,r,o){return(0,Y.calculate_lrna_in_given_out)(e,t,n,r,o)}static calculateOutGivenIn(e,t,n,r,o,i,a,c,p){return(0,Y.calculate_out_given_in)(e,t,n,r,o,i,a,c,p)}static calculateOutGivenLrnaIn(e,t,n,r,o){return(0,Y.calculate_out_given_lrna_in)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,Y.calculate_pool_trade_fee)(e,t,n)}static calculateShares(e,t,n,r){return(0,Y.calculate_shares)(e,t,n,r)}static calculateLiquidityOut(e,t,n,r,o,i,a,c){return(0,Y.calculate_liquidity_out)(e,t,n,r,o,i,a,c)}static calculateLiquidityLRNAOut(e,t,n,r,o,i,a,c){return(0,Y.calculate_liquidity_lrna_out)(e,t,n,r,o,i,a,c)}static calculateCapDifference(e,t,n,r){return(0,Y.calculate_cap_difference)(e,t,n,r)}static verifyAssetCap(e,t,n,r){return(0,Y.verify_asset_cap)(e,t,n,r)}static calculateLimitHubIn(e,t,n,r){return(0,Y.calculate_liquidity_hub_in)(e,t,n,r)}static isSellAllowed(e){return(0,Y.is_sell_allowed)(e)}static isBuyAllowed(e){return(0,Y.is_buy_allowed)(e)}static isAddLiquidityAllowed(e){return(0,Y.is_add_liquidity_allowed)(e)}static isRemoveLiquidityAllowed(e){return(0,Y.is_remove_liquidity_allowed)(e)}};var $e=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;hubAssetId;static fromPool(e){return new $e(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.hubAssetId)}constructor(e,t,n,r,o,i){this.type="Omnipool",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.hubAssetId=i}validatePair(e,t){return this.hubAssetId!=t}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,hubReservesIn:r.hubReserves,hubReservesOut:o.hubReserves,sharesIn:r.shares,sharesOut:o.shares,decimalsIn:r.decimals,decimalsOut:o.decimals,balanceIn:i,balanceOut:a,tradeableIn:r.tradeable,tradeableOut:o.tradeable}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateInGivenOut(e,t,n),i=o.minus(r),a=r===W?W:i.div(r).multipliedBy(100).decimalPlaces(2),c=[],p=ae.isSellAllowed(e.tradeableIn),b=ae.isBuyAllowed(e.tradeableOut);(!p||!b)&&c.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let v=e.balanceOut.div(this.maxOutRatio);t.isGreaterThan(v)&&c.push("MaxOutRatioExceeded");let B=e.balanceIn.div(this.maxInRatio);return o.isGreaterThan(B)&&c.push("MaxInRatioExceeded"),{amountIn:o,calculatedIn:r,amountOut:t,feePct:a.toNumber(),errors:c}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateOutGivenIn(e,t,n),a=r.minus(o).div(r).multipliedBy(100).decimalPlaces(2),c=[],p=ae.isSellAllowed(e.tradeableIn),b=ae.isBuyAllowed(e.tradeableOut);(!p||!b)&&c.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let v=e.balanceIn.div(this.maxInRatio);t.isGreaterThan(v)&&c.push("MaxInRatioExceeded");let B=e.balanceOut.div(this.maxOutRatio);return o.isGreaterThan(B)&&c.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:r,amountOut:o,feePct:a.toNumber(),errors:c}}calculateInGivenOut(e,t,n){if(e.assetIn==this.hubAssetId)return this.calculateLrnaInGivenOut(e,t,n);let r=ae.calculateInGivenOut(e.balanceIn.toString(),e.hubReservesIn.toString(),e.sharesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString(),n?Se(n.protocolFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateLrnaInGivenOut(e,t,n){let r=ae.calculateLrnaInGivenOut(e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenIn(e,t,n){if(e.assetIn==this.hubAssetId)return this.calculateOutGivenLrnaIn(e,t,n);let r=ae.calculateOutGivenIn(e.balanceIn.toString(),e.hubReservesIn.toString(),e.sharesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString(),n?Se(n.protocolFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenLrnaIn(e,t,n){let r=ae.calculateOutGivenLrnaIn(e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}spotPriceInGivenOut(e){if(e.assetIn==this.hubAssetId)return this.spotPriceLrnaInGivenOut(e);let t=ae.calculateSpotPrice(e.balanceOut.toString(),e.hubReservesOut.toString(),e.balanceIn.toString(),e.hubReservesIn.toString());return C(t).shiftedBy(-1*(et-e.decimalsOut)).decimalPlaces(0,1)}spotPriceLrnaInGivenOut(e){let t=ae.calculateLrnaSpotPrice(e.hubReservesOut.toString(),e.balanceOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsOut)).decimalPlaces(0,1)}spotPriceOutGivenIn(e){if(e.assetIn==this.hubAssetId)return this.spotPriceOutGivenLrnaIn(e);let t=ae.calculateSpotPrice(e.balanceIn.toString(),e.hubReservesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsIn)).decimalPlaces(0,1)}spotPriceOutGivenLrnaIn(e){let t=ae.calculateLrnaSpotPrice(e.balanceOut.toString(),e.hubReservesOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsIn)).decimalPlaces(0,1)}};var ut=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;amplification;id;fee;totalIssuance;static fromPool(e){return new ut(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.amplification,e.id,e.fee,e.totalIssuance)}constructor(e,t,n,r,o,i,a,c,p){this.type="Stableswap",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.amplification=i,this.id=a,this.fee=c,this.totalIssuance=p}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,balanceIn:i,balanceOut:a,decimalsIn:r.decimals,decimalsOut:o.decimals,tradeableIn:this.id===e?Rt:r.tradeable,tradeableOut:this.id===t?Rt:o.tradeable}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateInGivenOut(e,t,n),i=Ne(n.fee),a=[],c=ae.isSellAllowed(e.tradeableIn),p=ae.isBuyAllowed(e.tradeableOut);return(!c||!p)&&a.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&a.push("InsufficientTradingAmount"),{amountIn:o,calculatedIn:r,amountOut:t,feePct:i,errors:a}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateOutGivenIn(e,t,n),i=Ne(n.fee),a=[],c=ae.isSellAllowed(e.tradeableIn),p=ae.isBuyAllowed(e.tradeableOut);return(!c||!p)&&a.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&a.push("InsufficientTradingAmount"),{amountIn:t,calculatedOut:r,amountOut:o,feePct:i,errors:a}}calculateIn(e,t,n){let r=ve.calculateInGivenOut(this.getReserves(),Number(e.assetIn),Number(e.assetOut),t.toFixed(0),this.amplification,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateAddOneAsset(e,t,n){let r=ve.calculateAddOneAsset(this.getReserves(),t.toFixed(0),Number(e.assetIn),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateSharesForAmount(e,t,n){let r=ve.calculateSharesForAmount(this.getReserves(),Number(e.assetOut),t.toFixed(0),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateInGivenOut(e,t,n){return e.assetOut==this.id?this.calculateAddOneAsset(e,t,n):e.assetIn==this.id?this.calculateSharesForAmount(e,t,n):this.calculateIn(e,t,n)}spotPriceInGivenOut(e){let t=_e(xe,e.decimalsOut);return e.assetOut==this.id?this.calculateAddOneAsset(e,t):e.assetIn==this.id?this.calculateSharesForAmount(e,t):this.calculateIn(e,t)}calculateOut(e,t,n){let r=ve.calculateOutGivenIn(this.getReserves(),Number(e.assetIn),Number(e.assetOut),t.toFixed(0),this.amplification,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateWithdrawOneAsset(e,t,n){let r=ve.calculateLiquidityOutOneAsset(this.getReserves(),t.toFixed(0),Number(e.assetOut),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateShares(e,t,n){let r=ve.calculateShares(this.getReserves(),this.getAssets(e.assetIn,t),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenIn(e,t,n){return e.assetIn==this.id?this.calculateWithdrawOneAsset(e,t,n):e.assetOut==this.id?this.calculateShares(e,t,n):this.calculateOut(e,t,n)}spotPriceOutGivenIn(e){let t=_e(xe,e.decimalsIn);return e.assetIn==this.id?this.calculateWithdrawOneAsset(e,t):e.assetOut==this.id?this.calculateShares(e,t):this.calculateOut(e,t)}calculateTradeFee(e,t){let n=ve.calculatePoolTradeFee(e.toString(),t.fee[0],t.fee[1]);return C(n)}getReserves(){let e=this.tokens.filter(t=>t.id!=this.id).map(({id:t,balance:n,decimals:r})=>({asset_id:Number(t),amount:n,decimals:r}));return JSON.stringify(e)}getAssets(e,t){let n={asset_id:Number(e),amount:t.toFixed(0)};return JSON.stringify([n])}};var be=Bt(er()),He=class{static getSpotPrice(e,t,n){return(0,be.get_spot_price)(e,t,n)}static calculateInGivenOut(e,t,n){return(0,be.calculate_in_given_out)(e,t,n)}static calculateOutGivenIn(e,t,n){return(0,be.calculate_out_given_in)(e,t,n)}static calculatePoolTradeFee(e,t,n){return(0,be.calculate_pool_trade_fee)(e,t,n)}static calculateLiquidityIn(e,t,n){return(0,be.calculate_liquidity_in)(e,t,n)}static calculateShares(e,t,n){return(0,be.calculate_shares)(e,t,n)}static calculateLiquidityOutAssetA(e,t,n,r){return(0,be.calculate_liquidity_out_asset_a)(e,t,n,r)}static calculateLiquidityOutAssetB(e,t,n,r){return(0,be.calculate_liquidity_out_asset_b)(e,t,n,r)}};var je=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;static fromPool(e){return new je(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit)}constructor(e,t,n,r,o){this.type="Xyk",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,decimalsIn:r.decimals,decimalsOut:o.decimals,balanceIn:i,balanceOut:a}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateTradeFee(r,n),i=Ne(n.exchangeFee),a=r.plus(o),c=[];t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let p=e.balanceOut.div(this.maxOutRatio);t.isGreaterThan(p)&&c.push("MaxOutRatioExceeded");let b=e.balanceIn.div(this.maxInRatio);return a.isGreaterThan(b)&&c.push("MaxInRatioExceeded"),{amountIn:a,calculatedIn:r,amountOut:t,feePct:i,errors:c}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateTradeFee(r,n),i=Ne(n.exchangeFee),a=r.minus(o),c=[];t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let p=e.balanceIn.div(this.maxInRatio);t.isGreaterThan(p)&&c.push("MaxInRatioExceeded");let b=e.balanceOut.div(this.maxOutRatio);return a.isGreaterThan(b)&&c.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:r,amountOut:a,feePct:i,errors:c}}calculateInGivenOut(e,t){let n=He.calculateInGivenOut(e.balanceIn.toString(),e.balanceOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}calculateOutGivenIn(e,t){let n=He.calculateOutGivenIn(e.balanceIn.toString(),e.balanceOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}spotPriceInGivenOut(e){let t=He.getSpotPrice(e.balanceOut.toString(),e.balanceIn.toString(),_e(xe,e.decimalsOut).toString());return C(t)}spotPriceOutGivenIn(e){let t=He.getSpotPrice(e.balanceIn.toString(),e.balanceOut.toString(),_e(xe,e.decimalsIn).toString());return C(t)}calculateTradeFee(e,t){let n=He.calculatePoolTradeFee(e.toString(),t.exchangeFee[0],t.exchangeFee[1]);return C(n)}};var _t=class{static get(e){switch(e.type){case"Xyk":return je.fromPool(e);case"Omnipool":return $e.fromPool(e);case"Lbp":return Ye.fromPool(e);case"Stableswap":return ut.fromPool(e);default:throw new Error("Pool type "+e.type+" is not supported yet")}}};var Ze=class{routeSuggester;routerOptions;poolService;defaultRouterOptions={includeOnly:[]};constructor(e,t){this.poolService=e,this.routeSuggester=new mt,this.routerOptions={...this.defaultRouterOptions,...t}}async getPools(){let e=this.routerOptions.includeOnly;return await this.poolService.getPools(e)}async getAllAssets(){let e=await this.getPools();if(e.length===0)throw new Error("No pools configured");let t=await this.getAssets(e);return[...new Map(t).values()]}async getAssetPairs(e){let t=await this.getPools();if(t.length===0)throw new Error("No pools configured");let{assets:n,poolsMap:r}=await this.validateToken(e,t),i=this.getPaths(e,null,r,t).map(a=>a[a.length-1].assetOut);return this.toPoolAssets([...new Set(i)],n)}async getAllPaths(e,t){let n=await this.getPools();if(n.length===0)throw new Error("No pools configured");let{poolsMap:r}=await this.validateTokenPair(e,t,n);return this.getPaths(e,t,r,n)}async getAssets(e){let t=e.map(n=>n.tokens).flat();return new Map(t.map(n=>[n.id,n]))}getPaths(e,t,n,r){return this.routeSuggester.getProposals(e,t,r).filter(a=>this.validPath(a,n)).map(a=>this.toHops(a,n))}async validateTokenPair(e,t,n){let r=await this.getAssets(n);if(r.get(e)==null)throw new Error(e+" is not supported token");if(r.get(t)==null)throw new Error(t+" is not supported token");let o=this.getPoolMap(n);return{assets:r,poolsMap:o}}async validateToken(e,t){let n=await this.getAssets(t);if(n.get(e)==null)throw new Error(e+" is not supported token");let r=this.getPoolMap(t);return{assets:n,poolsMap:r}}getPoolMap(e){return new Map(e.map(t=>[t.address,_t.get(t)]))}validPath(e,t){return e.length>0&&e.map(n=>this.validEdge(n,t)).reduce((n,r)=>n&&r)}validEdge([e,t,n],r){return r.get(e)?.validatePair(t,n)||!1}toHops(e,t){return e.map(([n,r,o])=>{let i=t.get(n);return{poolAddress:n,poolId:i?.id,pool:i?.type,assetIn:r,assetOut:o}})}toPoolAssets(e,t){return e.map(n=>t.get(n))}};function Kr(s,e){return s.minus(e).abs().div(s.plus(e).div(2)).multipliedBy(100).decimalPlaces(2)}function dt(s,e){return s.minus(e).div(e).multipliedBy(100).decimalPlaces(2)}function vn(s,e){return xe.minus(e.div(s)).multipliedBy(100).decimalPlaces(2)}function On(s,e){return e.div(s).minus(xe).multipliedBy(100).decimalPlaces(2)}var St=class extends Ze{isDirectTrade(e){return e.length==1}findBestSellRoute(e){let t=e.sort((n,r)=>{let o=n[n.length-1].amountOut,i=r[r.length-1].amountOut;return o.isGreaterThan(i)?-1:1});return t.find(n=>n.every(r=>r.errors.length==0))||t[0]}getRouteFeeRange(e){if(e.filter(n=>n.tradeFeeRange).length>0){let n=e.map(o=>o.tradeFeeRange?.[0]??o.tradeFeePct).reduce((o,i)=>o+i),r=e.map(o=>o.tradeFeeRange?.[1]??o.tradeFeePct).reduce((o,i)=>o+i);return[n,r]}}getPoolFeeRange(e){let t=e.min?Ne(e.min):void 0,n=e.max?Ne(e.max):void 0;if(t&&n)return[t,n]}async getBestSell(e,t,n){let r=await super.getPools();if(r.length===0)throw new Error("No pools configured");let{poolsMap:o}=await super.validateTokenPair(e,t,r),i=super.getPaths(e,t,o,r);if(i.length===0)throw new it(e,t);let a=i.map(async H=>await this.toSellSwaps(n,H,o)),c=await Promise.all(a),p=this.findBestSellRoute(c),b=p[0],v=p[p.length-1],B=this.isDirectTrade(p),A=p.map(H=>H.spotPrice.shiftedBy(-1*H.assetOutDecimals)).reduce((H,l)=>H.multipliedBy(l)),k=_e(A,v.assetOutDecimals).decimalPlaces(0,1),M=b.amountIn.shiftedBy(-1*b.assetInDecimals).multipliedBy(k),E=dt(v.calculatedOut,M),L=B?v.calculatedOut:this.calculateDelta0Y(b.amountIn,p,o),x=v.amountOut,G=B?v.tradeFeePct:vn(L,x).toNumber(),J=L.minus(x),te=this.getRouteFeeRange(p),Z=H=>this.poolService.buildSellTx(e,t,b.amountIn,H,p.map(l=>l));return{type:"Sell",amountIn:b.amountIn,amountOut:v.amountOut,spotPrice:k,tradeFee:J,tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E.toNumber(),swaps:p,toTx:Z,toHuman(){return{type:"Sell",amountIn:ge(b.amountIn,b.assetInDecimals),amountOut:ge(v.amountOut,v.assetOutDecimals),spotPrice:ge(k,v.assetOutDecimals),tradeFee:ge(J,v.assetOutDecimals),tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E.toNumber(),swaps:p.map(H=>H.toHuman())}}}}calculateDelta0Y(e,t,n){let r=[];for(let o=0;o<t.length;o++){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o>0?p=r[o-1]:p=e;let b=a.calculateOutGivenIn(c,p);r.push(b)}return r[r.length-1]}async toSellSwaps(e,t,n){let r=[];for(let o=0;o<t.length;o++){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o>0?p=r[o-1].amountOut:p=_e(C(e),c.decimalsIn).decimalPlaces(0,1);let b=await this.poolService.getPoolFees(c.assetOut,a),{amountOut:v,calculatedOut:B,feePct:A,errors:k}=a.validateAndSell(c,p,b),M=this.getPoolFeeRange(b),E=a.spotPriceOutGivenIn(c),L=p.shiftedBy(-1*c.decimalsIn).multipliedBy(E),x=dt(B,L);r.push({...i,assetInDecimals:c.decimalsIn,assetOutDecimals:c.decimalsOut,amountIn:p,calculatedOut:B,amountOut:v,spotPrice:E,tradeFeePct:A,tradeFeeRange:M,priceImpactPct:x.toNumber(),errors:k,toHuman(){return{...i,amountIn:ge(p,c.decimalsIn),calculatedOut:ge(B,c.decimalsOut),amountOut:ge(v,c.decimalsOut),spotPrice:ge(E,c.decimalsOut),tradeFeePct:A,tradeFeeRange:M,priceImpactPct:x.toNumber(),errors:k}}})}return r}async getBestSpotPrice(e,t){let n=await super.getPools();if(n.length===0)throw new Error("No pools configured");let{poolsMap:r}=await super.validateTokenPair(e,t,n),o=super.getPaths(e,t,r,n);if(o.length===0)return Promise.resolve(void 0);let i=o.map(async B=>await this.toSellSwaps("1",B,r)),a=await Promise.all(i),c=this.findBestSellRoute(a),p=c.map(B=>B.spotPrice.shiftedBy(-1*B.assetOutDecimals)).reduce((B,A)=>B.multipliedBy(A)),b=c[c.length-1].assetOutDecimals;return{amount:_e(p,b).decimalPlaces(0,1),decimals:b}}findBestBuyRoute(e){let t=e.sort((n,r)=>{let o=n[0].amountIn,i=r[0].amountIn;return o.isGreaterThan(i)?1:-1});return t.find(n=>n.every(r=>r.errors.length==0))||t[0]}async getBestBuy(e,t,n){let r=await super.getPools();if(r.length===0)throw new Error("No pools configured");let{poolsMap:o}=await super.validateTokenPair(e,t,r),i=super.getPaths(e,t,o,r);if(i.length===0)throw new it(e,t);let a=i.map(async H=>await this.toBuySwaps(n,H,o)),c=await Promise.all(a),p=this.findBestBuyRoute(c),b=p[p.length-1],v=p[0],B=this.isDirectTrade(p),A=p.map(H=>H.spotPrice.shiftedBy(-1*H.assetInDecimals)).reduce((H,l)=>H.multipliedBy(l)),k=_e(A,v.assetInDecimals).decimalPlaces(0,1),M=b.amountOut.shiftedBy(-1*b.assetOutDecimals).multipliedBy(k),E;v.calculatedIn.isZero()?E=-100:E=dt(M,v.calculatedIn).toNumber();let L=B?v.calculatedIn:this.calculateDelta0X(b.amountOut,p,o),x=v.amountIn,G=B?v.tradeFeePct:On(L,x),J=x.minus(L),te=this.getRouteFeeRange(p),Z=H=>this.poolService.buildBuyTx(e,t,b.amountOut,H,p.map(l=>l));return{type:"Buy",amountOut:b.amountOut,amountIn:v.amountIn,spotPrice:k,tradeFee:J,tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E,swaps:p,toTx:Z,toHuman(){return{type:"Buy",amountOut:ge(b.amountOut,b.assetOutDecimals),amountIn:ge(v.amountIn,v.assetInDecimals),spotPrice:ge(k,v.assetInDecimals),tradeFee:ge(J,v.assetInDecimals),tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E,swaps:p.map(H=>H.toHuman())}}}}calculateDelta0X(e,t,n){let r=[];for(let o=t.length-1;o>=0;o--){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o==t.length-1?p=e:p=r[0];let b=a.calculateInGivenOut(c,p);r.unshift(b)}return r[0]}async toBuySwaps(e,t,n){let r=[];for(let o=t.length-1;o>=0;o--){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o==t.length-1?p=_e(C(e),c.decimalsOut).decimalPlaces(0,1):p=r[0].amountIn;let b=await this.poolService.getPoolFees(c.assetIn,a),{amountIn:v,calculatedIn:B,feePct:A,errors:k}=a.validateAndBuy(c,p,b),M=this.getPoolFeeRange(b),E=a.spotPriceInGivenOut(c),L=p.shiftedBy(-1*c.decimalsOut).multipliedBy(E),x;B.isZero()?x=-100:x=dt(L,B).toNumber(),r.unshift({...i,assetInDecimals:c.decimalsIn,assetOutDecimals:c.decimalsOut,amountOut:p,calculatedIn:B,amountIn:v,spotPrice:E,tradeFeePct:A,tradeFeeRange:M,priceImpactPct:x,errors:k,toHuman(){return{...i,amountOut:ge(p,c.decimalsOut),calculatedIn:ge(B,c.decimalsIn),amountIn:ge(v,c.decimalsIn),spotPrice:ge(E,c.decimalsIn),tradeFeePct:A,tradeFeeRange:M,priceImpactPct:x,errors:k}}})}return r}};0&&(module.exports={AssetClient,AssetNotFound,BASILISK_PARACHAIN_ID,BalanceClient,BigNumber,CachingPoolService,DECIMAL_PLACES,DENOMINATOR,HYDRADX_OMNIPOOL_ADDRESS,HYDRADX_PARACHAIN_ID,HYDRADX_SS58_PREFIX,INFINITY,LbpMath,LbpPool,ONE,OmniMath,OmniPool,PoolConfigNotFound,PoolError,PoolFactory,PoolNotFound,PoolService,PoolType,ProviderConfigNotFound,RUNTIME_DECIMALS,RouteNotFound,Router,SYSTEM_ASSET_DECIMALS,SYSTEM_ASSET_ID,StorageConfigNotFound,SubscriptionNotSupported,TRADEABLE_DEFAULT,TradeRouter,TradeType,XykMath,XykPool,ZERO,bnum,buildRoute,calculateBuyFee,calculateDiffToAvg,calculateDiffToRef,calculateSellFee,scale});
1
+ "use strict";var tr=Object.create;var vt=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var rr=Object.getOwnPropertyNames;var or=Object.getPrototypeOf,ir=Object.prototype.hasOwnProperty;var Ot=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),sr=(s,e)=>{for(var t in e)vt(s,t,{get:e[t],enumerable:!0})},Bn=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of rr(e))!ir.call(s,r)&&r!==t&&vt(s,r,{get:()=>e[r],enumerable:!(n=nr(e,r))||n.enumerable});return s};var Bt=(s,e,t)=>(t=s!=null?tr(or(s)):{},Bn(e||!s||!s.__esModule?vt(t,"default",{value:s,enumerable:!0}):t,s)),ar=s=>Bn(vt({},"__esModule",{value:!0}),s);var Fn=Ot((xo,Ze)=>{var _r={},R,{TextEncoder:dr,TextDecoder:pr}=require("util"),re=0,Nt=null;function kt(){return(Nt===null||Nt.byteLength===0)&&(Nt=new Uint8Array(R.memory.buffer)),Nt}var Et=new dr("utf-8"),gr=typeof Et.encodeInto=="function"?function(s,e){return Et.encodeInto(s,e)}:function(s,e){let t=Et.encode(s);return e.set(t),{read:s.length,written:t.length}};function le(s,e,t){if(t===void 0){let a=Et.encode(s),c=e(a.length,1)>>>0;return kt().subarray(c,c+a.length).set(a),re=a.length,c}let n=s.length,r=e(n,1)>>>0,o=kt(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3,1)>>>0;let a=kt().subarray(r+i,r+n),c=gr(s,a);i+=c.written}return re=i,r}var Ft=null;function Me(){return(Ft===null||Ft.byteLength===0)&&(Ft=new Int32Array(R.memory.buffer)),Ft}var Nn=new pr("utf-8",{ignoreBOM:!0,fatal:!0});Nn.decode();function ft(s,e){return s=s>>>0,Nn.decode(kt().subarray(s,s+e))}Ze.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=R.__wbindgen_add_to_stack_pointer(-16),c=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),p=re;R.calculate_pool_trade_fee(a,c,p,e,t);var o=Me()[a/4+0],i=Me()[a/4+1];return n=o,r=i,ft(o,i)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(n,r,1)}};Ze.exports.get_spot_price=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),N=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.get_spot_price(p,b,v,B,N,k,L,E,M,x,G);var a=Me()[p/4+0],c=Me()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Ze.exports.calculate_out_given_in=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),N=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_out_given_in(p,b,v,B,N,k,L,E,M,x,G);var a=Me()[p/4+0],c=Me()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Ze.exports.calculate_in_given_out=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),N=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_in_given_out(p,b,v,B,N,k,L,E,M,x,G);var a=Me()[p/4+0],c=Me()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};Ze.exports.calculate_linear_weights=function(s,e,t,n,r){let o,i;try{let p=R.__wbindgen_add_to_stack_pointer(-16),b=le(s,R.__wbindgen_malloc,R.__wbindgen_realloc),v=re,B=le(e,R.__wbindgen_malloc,R.__wbindgen_realloc),N=re,k=le(t,R.__wbindgen_malloc,R.__wbindgen_realloc),L=re,E=le(n,R.__wbindgen_malloc,R.__wbindgen_realloc),M=re,x=le(r,R.__wbindgen_malloc,R.__wbindgen_realloc),G=re;R.calculate_linear_weights(p,b,v,B,N,k,L,E,M,x,G);var a=Me()[p/4+0],c=Me()[p/4+1];return o=a,i=c,ft(a,c)}finally{R.__wbindgen_add_to_stack_pointer(16),R.__wbindgen_free(o,i,1)}};var mr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),fr=require("fs").readFileSync(mr),hr=new WebAssembly.Module(fr),br=new WebAssembly.Instance(hr,_r);R=br.exports;Ze.exports.__wasm=R});var Dn=Ot((is,Ee)=>{var Sr={},O,{TextEncoder:xr,TextDecoder:vr}=require("util"),z=0,qt=null;function bt(){return(qt===null||qt.byteLength===0)&&(qt=new Uint8Array(O.memory.buffer)),qt}var Ht=new xr("utf-8"),Or=typeof Ht.encodeInto=="function"?function(s,e){return Ht.encodeInto(s,e)}:function(s,e){let t=Ht.encode(s);return e.set(t),{read:s.length,written:t.length}};function X(s,e,t){if(t===void 0){let a=Ht.encode(s),c=e(a.length,1)>>>0;return bt().subarray(c,c+a.length).set(a),z=a.length,c}let n=s.length,r=e(n,1)>>>0,o=bt(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3,1)>>>0;let a=bt().subarray(r+i,r+n),c=Or(s,a);i+=c.written}return z=i,r}var Gt=null;function de(){return(Gt===null||Gt.byteLength===0)&&(Gt=new Int32Array(O.memory.buffer)),Gt}var Mn=new vr("utf-8",{ignoreBOM:!0,fatal:!0});Mn.decode();function Xe(s,e){return s=s>>>0,Mn.decode(bt().subarray(s,s+e))}Ee.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=O.__wbindgen_add_to_stack_pointer(-16),c=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),p=z;O.calculate_pool_trade_fee(a,c,p,e,t);var o=de()[a/4+0],i=de()[a/4+1];return n=o,r=i,Xe(o,i)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(n,r,1)}};Ee.exports.calculate_out_given_in=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,N=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,L=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,M=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z;O.calculate_out_given_in(b,v,B,e,t,N,k,L,E,M,x);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};Ee.exports.calculate_in_given_out=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,N=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,L=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,M=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z;O.calculate_in_given_out(b,v,B,e,t,N,k,L,E,M,x);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};Ee.exports.calculate_amplification=function(s,e,t,n,r){let o,i;try{let p=O.__wbindgen_add_to_stack_pointer(-16),b=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),v=z,B=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),N=z,k=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),L=z,E=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),M=z,x=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),G=z;O.calculate_amplification(p,b,v,B,N,k,L,E,M,x,G);var a=de()[p/4+0],c=de()[p/4+1];return o=a,i=c,Xe(a,c)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(o,i,1)}};Ee.exports.calculate_shares=function(s,e,t,n,r){let o,i;try{let p=O.__wbindgen_add_to_stack_pointer(-16),b=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),v=z,B=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),N=z,k=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),L=z,E=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),M=z,x=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),G=z;O.calculate_shares(p,b,v,B,N,k,L,E,M,x,G);var a=de()[p/4+0],c=de()[p/4+1];return o=a,i=c,Xe(a,c)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(o,i,1)}};Ee.exports.calculate_shares_for_amount=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,N=X(t,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,L=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,M=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_shares_for_amount(b,v,B,e,N,k,L,E,M,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};Ee.exports.calculate_add_one_asset=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,N=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,L=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,M=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_add_one_asset(b,v,B,N,k,t,L,E,M,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};function Br(s,e){return s=s>>>0,bt().subarray(s/1,s/1+e)}Ee.exports.pool_account_name=function(s){try{let r=O.__wbindgen_add_to_stack_pointer(-16);O.pool_account_name(r,s);var e=de()[r/4+0],t=de()[r/4+1],n=Br(e,t).slice();return O.__wbindgen_free(e,t*1),n}finally{O.__wbindgen_add_to_stack_pointer(16)}};Ee.exports.calculate_liquidity_out_one_asset=function(s,e,t,n,r,o){let i,a;try{let b=O.__wbindgen_add_to_stack_pointer(-16),v=X(s,O.__wbindgen_malloc,O.__wbindgen_realloc),B=z,N=X(e,O.__wbindgen_malloc,O.__wbindgen_realloc),k=z,L=X(n,O.__wbindgen_malloc,O.__wbindgen_realloc),E=z,M=X(r,O.__wbindgen_malloc,O.__wbindgen_realloc),x=z,G=X(o,O.__wbindgen_malloc,O.__wbindgen_realloc),J=z;O.calculate_liquidity_out_one_asset(b,v,B,N,k,t,L,E,M,x,G,J);var c=de()[b/4+0],p=de()[b/4+1];return i=c,a=p,Xe(c,p)}finally{O.__wbindgen_add_to_stack_pointer(16),O.__wbindgen_free(i,a,1)}};var Ir=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Ar=require("fs").readFileSync(Ir),Tr=new WebAssembly.Module(Ar),Nr=new WebAssembly.Instance(Tr,Sr);O=Nr.exports;Ee.exports.__wasm=O});var Qn=Ot((Wa,oe)=>{var Dr={},u,{TextEncoder:Cr,TextDecoder:qr}=require("util"),A=0,Kt=null;function tn(){return(Kt===null||Kt.byteLength===0)&&(Kt=new Uint8Array(u.memory.buffer)),Kt}var nn=new Cr("utf-8"),Gr=typeof nn.encodeInto=="function"?function(s,e){return nn.encodeInto(s,e)}:function(s,e){let t=nn.encode(s);return e.set(t),{read:s.length,written:t.length}};function T(s,e,t){if(t===void 0){let a=nn.encode(s),c=e(a.length)>>>0;return tn().subarray(c,c+a.length).set(a),A=a.length,c}let n=s.length,r=e(n)>>>0,o=tn(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3)>>>0;let a=tn().subarray(r+i,r+n),c=Gr(s,a);i+=c.written}return A=i,r}var en=null;function j(){return(en===null||en.byteLength===0)&&(en=new Int32Array(u.memory.buffer)),en}var Zn=new qr("utf-8",{ignoreBOM:!0,fatal:!0});Zn.decode();function fe(s,e){return s=s>>>0,Zn.decode(tn().subarray(s,s+e))}oe.exports.calculate_shares=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=A,v=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=A,N=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A;u.calculate_shares(c,p,b,v,B,N,k,L,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.calculate_withdrawal_fee=function(s,e,t){let n,r;try{let a=u.__wbindgen_add_to_stack_pointer(-16),c=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),p=A,b=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),v=A,B=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),N=A;u.calculate_withdrawal_fee(a,c,p,b,v,B,N);var o=j()[a/4+0],i=j()[a/4+1];return n=o,r=i,fe(o,i)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(n,r)}};oe.exports.calculate_liquidity_out=function(s,e,t,n,r,o,i,a){let c,p;try{let B=u.__wbindgen_add_to_stack_pointer(-16),N=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A,M=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),x=A,G=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),J=A,te=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=A,H=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),l=A,_=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),d=A,w=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),m=A;u.calculate_liquidity_out(B,N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m);var b=j()[B/4+0],v=j()[B/4+1];return c=b,p=v,fe(b,v)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(c,p)}};oe.exports.calculate_liquidity_lrna_out=function(s,e,t,n,r,o,i,a){let c,p;try{let B=u.__wbindgen_add_to_stack_pointer(-16),N=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A,M=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),x=A,G=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),J=A,te=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=A,H=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),l=A,_=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),d=A,w=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),m=A;u.calculate_liquidity_lrna_out(B,N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m);var b=j()[B/4+0],v=j()[B/4+1];return c=b,p=v,fe(b,v)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(c,p)}};oe.exports.recalculate_asset_fee=function(s,e,t,n,r,o,i,a,c){let p,b;try{let N=u.__wbindgen_add_to_stack_pointer(-16),k=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A,J=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=A,Z=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=A,l=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=A,d=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=A,m=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),f=A,y=T(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=A;u.recalculate_asset_fee(N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m,f,y,g);var v=j()[N/4+0],B=j()[N/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.recalculate_protocol_fee=function(s,e,t,n,r,o,i,a,c){let p,b;try{let N=u.__wbindgen_add_to_stack_pointer(-16),k=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A,J=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=A,Z=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=A,l=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=A,d=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=A,m=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),f=A,y=T(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=A;u.recalculate_protocol_fee(N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m,f,y,g);var v=j()[N/4+0],B=j()[N/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_out_given_in=function(s,e,t,n,r,o,i,a,c){let p,b;try{let N=u.__wbindgen_add_to_stack_pointer(-16),k=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A,J=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=A,Z=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=A,l=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=A,d=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=A,m=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),f=A,y=T(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=A;u.calculate_out_given_in(N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m,f,y,g);var v=j()[N/4+0],B=j()[N/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_out_given_lrna_in=function(s,e,t,n,r){let o,i;try{let p=u.__wbindgen_add_to_stack_pointer(-16),b=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),v=A,B=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),N=A,k=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A;u.calculate_out_given_lrna_in(p,b,v,B,N,k,L,E,M,x,G);var a=j()[p/4+0],c=j()[p/4+1];return o=a,i=c,fe(a,c)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(o,i)}};oe.exports.calculate_in_given_out=function(s,e,t,n,r,o,i,a,c){let p,b;try{let N=u.__wbindgen_add_to_stack_pointer(-16),k=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A,J=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),te=A,Z=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),H=A,l=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),_=A,d=T(i,u.__wbindgen_malloc,u.__wbindgen_realloc),w=A,m=T(a,u.__wbindgen_malloc,u.__wbindgen_realloc),f=A,y=T(c,u.__wbindgen_malloc,u.__wbindgen_realloc),g=A;u.calculate_in_given_out(N,k,L,E,M,x,G,J,te,Z,H,l,_,d,w,m,f,y,g);var v=j()[N/4+0],B=j()[N/4+1];return p=v,b=B,fe(v,B)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(p,b)}};oe.exports.calculate_lrna_in_given_out=function(s,e,t,n,r){let o,i;try{let p=u.__wbindgen_add_to_stack_pointer(-16),b=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),v=A,B=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),N=A,k=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),L=A,E=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),M=A,x=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),G=A;u.calculate_lrna_in_given_out(p,b,v,B,N,k,L,E,M,x,G);var a=j()[p/4+0],c=j()[p/4+1];return o=a,i=c,fe(a,c)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(o,i)}};oe.exports.calculate_spot_price=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=A,v=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=A,N=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A;u.calculate_spot_price(c,p,b,v,B,N,k,L,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.calculate_lrna_spot_price=function(s,e){let t,n;try{let i=u.__wbindgen_add_to_stack_pointer(-16),a=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),c=A,p=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),b=A;u.calculate_lrna_spot_price(i,a,c,p,b);var r=j()[i/4+0],o=j()[i/4+1];return t=r,n=o,fe(r,o)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(t,n)}};oe.exports.calculate_cap_difference=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=A,v=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=A,N=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A;u.calculate_cap_difference(c,p,b,v,B,N,k,L,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.verify_asset_cap=function(s,e,t,n){let r=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),o=A,i=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),a=A,c=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),p=A,b=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),v=A;return u.verify_asset_cap(r,o,i,a,c,p,b,v)!==0};oe.exports.calculate_tvl_cap_difference=function(s,e,t,n,r,o){let i,a;try{let b=u.__wbindgen_add_to_stack_pointer(-16),v=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),B=A,N=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A,M=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),x=A,G=T(r,u.__wbindgen_malloc,u.__wbindgen_realloc),J=A,te=T(o,u.__wbindgen_malloc,u.__wbindgen_realloc),Z=A;u.calculate_tvl_cap_difference(b,v,B,N,k,L,E,M,x,G,J,te,Z);var c=j()[b/4+0],p=j()[b/4+1];return i=c,a=p,fe(c,p)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(i,a)}};oe.exports.calculate_liquidity_hub_in=function(s,e,t,n){let r,o;try{let c=u.__wbindgen_add_to_stack_pointer(-16),p=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),b=A,v=T(e,u.__wbindgen_malloc,u.__wbindgen_realloc),B=A,N=T(t,u.__wbindgen_malloc,u.__wbindgen_realloc),k=A,L=T(n,u.__wbindgen_malloc,u.__wbindgen_realloc),E=A;u.calculate_liquidity_hub_in(c,p,b,v,B,N,k,L,E);var i=j()[c/4+0],a=j()[c/4+1];return r=i,o=a,fe(i,a)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(r,o)}};oe.exports.is_sell_allowed=function(s){return u.is_sell_allowed(s)!==0};oe.exports.is_buy_allowed=function(s){return u.is_buy_allowed(s)!==0};oe.exports.is_add_liquidity_allowed=function(s){return u.is_add_liquidity_allowed(s)!==0};oe.exports.is_remove_liquidity_allowed=function(s){return u.is_remove_liquidity_allowed(s)!==0};oe.exports.calculate_pool_trade_fee=function(s,e,t){let n,r;try{let a=u.__wbindgen_add_to_stack_pointer(-16),c=T(s,u.__wbindgen_malloc,u.__wbindgen_realloc),p=A;u.calculate_pool_trade_fee(a,c,p,e,t);var o=j()[a/4+0],i=j()[a/4+1];return n=o,r=i,fe(o,i)}finally{u.__wbindgen_add_to_stack_pointer(16),u.__wbindgen_free(n,r)}};var Hr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Ur=require("fs").readFileSync(Hr),Wr=new WebAssembly.Module(Ur),zr=new WebAssembly.Instance(Wr,Dr);u=zr.exports;oe.exports.__wasm=u});var er=Ot((Sl,Ge)=>{var Xr={},F,{TextEncoder:Yr,TextDecoder:$r}=require("util"),K=0,rn=null;function sn(){return(rn===null||rn.buffer!==F.memory.buffer)&&(rn=new Uint8Array(F.memory.buffer)),rn}var an=new Yr("utf-8"),Vr=typeof an.encodeInto=="function"?function(s,e){return an.encodeInto(s,e)}:function(s,e){let t=an.encode(s);return e.set(t),{read:s.length,written:t.length}};function ee(s,e,t){if(t===void 0){let a=an.encode(s),c=e(a.length);return sn().subarray(c,c+a.length).set(a),K=a.length,c}let n=s.length,r=e(n),o=sn(),i=0;for(;i<n;i++){let a=s.charCodeAt(i);if(a>127)break;o[r+i]=a}if(i!==n){i!==0&&(s=s.slice(i)),r=t(r,n,n=i+s.length*3);let a=sn().subarray(r+i,r+n),c=Vr(s,a);i+=c.written}return K=i,r}var on=null;function he(){return(on===null||on.buffer!==F.memory.buffer)&&(on=new Int32Array(F.memory.buffer)),on}var Kn=new $r("utf-8",{ignoreBOM:!0,fatal:!0});Kn.decode();function Ve(s,e){return Kn.decode(sn().subarray(s,s+e))}Ge.exports.calculate_pool_trade_fee=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K;F.calculate_pool_trade_fee(o,i,a,e,t);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.get_spot_price=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.get_spot_price(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_out_given_in=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_out_given_in(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_in_given_out=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_in_given_out(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_liquidity_in=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_liquidity_in(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_shares=function(s,e,t){try{let o=F.__wbindgen_add_to_stack_pointer(-16),i=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),a=K,c=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),p=K,b=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),v=K;F.calculate_shares(o,i,a,c,p,b,v);var n=he()[o/4+0],r=he()[o/4+1];return Ve(n,r)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(n,r)}};Ge.exports.calculate_liquidity_out_asset_a=function(s,e,t,n){try{let i=F.__wbindgen_add_to_stack_pointer(-16),a=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),c=K,p=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),b=K,v=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),B=K,N=ee(n,F.__wbindgen_malloc,F.__wbindgen_realloc),k=K;F.calculate_liquidity_out_asset_a(i,a,c,p,b,v,B,N,k);var r=he()[i/4+0],o=he()[i/4+1];return Ve(r,o)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(r,o)}};Ge.exports.calculate_liquidity_out_asset_b=function(s,e,t,n){try{let i=F.__wbindgen_add_to_stack_pointer(-16),a=ee(s,F.__wbindgen_malloc,F.__wbindgen_realloc),c=K,p=ee(e,F.__wbindgen_malloc,F.__wbindgen_realloc),b=K,v=ee(t,F.__wbindgen_malloc,F.__wbindgen_realloc),B=K,N=ee(n,F.__wbindgen_malloc,F.__wbindgen_realloc),k=K;F.calculate_liquidity_out_asset_b(i,a,c,p,b,v,B,N,k);var r=he()[i/4+0],o=he()[i/4+1];return Ve(r,o)}finally{F.__wbindgen_add_to_stack_pointer(16),F.__wbindgen_free(r,o)}};var jr=require("path").join(__dirname,"hydra_dx_wasm_bg.wasm"),Jr=require("fs").readFileSync(jr),Zr=new WebAssembly.Module(Jr),Qr=new WebAssembly.Instance(Zr,Xr);F=Qr.exports;Ge.exports.__wasm=F});var eo={};sr(eo,{AssetClient:()=>rt,AssetNotFound:()=>fn,BASILISK_PARACHAIN_ID:()=>yr,BalanceClient:()=>ot,BigNumber:()=>Le,CachingPoolService:()=>Qt,DECIMAL_PLACES:()=>Tn,DENOMINATOR:()=>Lt,HYDRADX_OMNIPOOL_ADDRESS:()=>ht,HYDRADX_PARACHAIN_ID:()=>Pr,HYDRADX_SS58_PREFIX:()=>tt,INFINITY:()=>ur,LbpMath:()=>Te,LbpPool:()=>Ye,ONE:()=>xe,OmniMath:()=>ae,OmniPool:()=>$e,PoolConfigNotFound:()=>mn,PoolError:()=>Ke,PoolFactory:()=>_t,PoolNotFound:()=>wt,PoolService:()=>st,PoolType:()=>ye,ProviderConfigNotFound:()=>wn,RUNTIME_DECIMALS:()=>et,RouteNotFound:()=>it,Router:()=>Qe,SYSTEM_ASSET_DECIMALS:()=>wr,SYSTEM_ASSET_ID:()=>We,StorageConfigNotFound:()=>hn,SubscriptionNotSupported:()=>bn,TRADEABLE_DEFAULT:()=>Rt,TradeRouter:()=>St,TradeType:()=>gn,XykMath:()=>He,XykPool:()=>je,ZERO:()=>W,bnum:()=>C,buildRoute:()=>zt,calculateBuyFee:()=>On,calculateDiffToAvg:()=>Kr,calculateDiffToRef:()=>dt,calculateSellFee:()=>vn,scale:()=>_e});module.exports=ar(eo);var It=class{constructor(e=1/0){this.capacity=e}storage=[];enqueue(e){if(this.size()===this.capacity)throw Error("Queue has reached max capacity, you cannot add more items");this.storage.push(e)}dequeue(){return this.storage.shift()}size(){return this.storage.length}};var lr=4,gt=class{isNotVisited(e,t){let n=!0;return t.forEach(r=>{(r[0]===e[0]||r[1]===e[1])&&(n=!1)}),n}findPaths(e,t,n){let r=[],o=new It,i=[];for(i.push([t,""]),o.enqueue(i);o.size()>0;){let a=o.dequeue();if(a==null||a.length>lr)return r;let c=a[a.length-1];(n===null||c[0]===n)&&r.push(a),e[c[0]].forEach(b=>{if(this.isNotVisited(b,a)){let v=[...a];v.push(b),o.enqueue(v)}})}return r}buildAndPopulateGraph(e,t){let n=e[e.length-1],r=[];for(let o=0;o<=parseInt(n);o++)r.push([]);for(let[o,i,a]of t){let c=parseInt(i),p=parseInt(a);r[c].push([p,o])}return r}};function un(s){let e={};for(let t of s){let n=t.tokens.length;for(let r=0;r<n;r++){e[t.tokens[r].id]||(e[t.tokens[r].id]=[]);for(let o=0;o<n;o++){if(r==o)continue;let i=[t.address,t.tokens[r].id,t.tokens[o].id];e[t.tokens[r].id].push(i)}}}return e}var mt=class{getProposals(e,t,n){let r=un(n),o=Object.keys(r),i=o.map(b=>r[b]).flat(),a=new gt,c=a.buildAndPopulateGraph(o,i),p=a.findPaths(c,parseInt(e),t?parseInt(t):null);return this.parsePaths(p)}parsePaths(e){let t=[];for(let n of e){let r=[];for(let o=0;o<n.length;o++){let i=n[o],a=n[o+1];if(a==null)break;r.push(this.toEdge(i,a))}t.push(r)}return t}toEdge(e,t){return[t[1],e[0].toString(),t[0].toString()]}};var cr=/^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,_n=Math.ceil,Ie=Math.floor,Pe="[BigNumber Error] ",In=Pe+"Number primitive has more than 15 significant digits: ",Fe=1e14,U=14,dn=9007199254740991,pn=[1,10,100,1e3,1e4,1e5,1e6,1e7,1e8,1e9,1e10,1e11,1e12,1e13],ze=1e7,ue=1e9;function An(s){var e,t,n,r=x.prototype={constructor:x,toString:null,valueOf:null},o=new x(1),i=20,a=4,c=-7,p=21,b=-1e7,v=1e7,B=!1,N=1,k=0,L={prefix:"",groupSize:3,secondaryGroupSize:0,groupSeparator:",",decimalSeparator:".",fractionGroupSize:0,fractionGroupSeparator:"\xA0",suffix:""},E="0123456789abcdefghijklmnopqrstuvwxyz",M=!0;function x(l,_){var d,w,m,f,y,g,h,S,P=this;if(!(P instanceof x))return new x(l,_);if(_==null){if(l&&l._isBigNumber===!0){P.s=l.s,!l.c||l.e>v?P.c=P.e=null:l.e<b?P.c=[P.e=0]:(P.e=l.e,P.c=l.c.slice());return}if((g=typeof l=="number")&&l*0==0){if(P.s=1/l<0?(l=-l,-1):1,l===~~l){for(f=0,y=l;y>=10;y/=10,f++);f>v?P.c=P.e=null:(P.e=f,P.c=[l]);return}S=String(l)}else{if(!cr.test(S=String(l)))return n(P,S,g);P.s=S.charCodeAt(0)==45?(S=S.slice(1),-1):1}(f=S.indexOf("."))>-1&&(S=S.replace(".","")),(y=S.search(/e/i))>0?(f<0&&(f=y),f+=+S.slice(y+1),S=S.substring(0,y)):f<0&&(f=S.length)}else{if(ne(_,2,E.length,"Base"),_==10&&M)return P=new x(l),Z(P,i+P.e+1,a);if(S=String(l),g=typeof l=="number"){if(l*0!=0)return n(P,S,g,_);if(P.s=1/l<0?(S=S.slice(1),-1):1,x.DEBUG&&S.replace(/^0\.0*|\./,"").length>15)throw Error(In+l)}else P.s=S.charCodeAt(0)===45?(S=S.slice(1),-1):1;for(d=E.slice(0,_),f=y=0,h=S.length;y<h;y++)if(d.indexOf(w=S.charAt(y))<0){if(w=="."){if(y>f){f=h;continue}}else if(!m&&(S==S.toUpperCase()&&(S=S.toLowerCase())||S==S.toLowerCase()&&(S=S.toUpperCase()))){m=!0,y=-1,f=0;continue}return n(P,String(l),g,_)}g=!1,S=t(S,_,10,P.s),(f=S.indexOf("."))>-1?S=S.replace(".",""):f=S.length}for(y=0;S.charCodeAt(y)===48;y++);for(h=S.length;S.charCodeAt(--h)===48;);if(S=S.slice(y,++h)){if(h-=y,g&&x.DEBUG&&h>15&&(l>dn||l!==Ie(l)))throw Error(In+P.s*l);if((f=f-y-1)>v)P.c=P.e=null;else if(f<b)P.c=[P.e=0];else{if(P.e=f,P.c=[],y=(f+1)%U,f<0&&(y+=U),y<h){for(y&&P.c.push(+S.slice(0,y)),h-=U;y<h;)P.c.push(+S.slice(y,y+=U));y=U-(S=S.slice(y)).length}else y-=h;for(;y--;S+="0");P.c.push(+S)}}else P.c=[P.e=0]}x.clone=An,x.ROUND_UP=0,x.ROUND_DOWN=1,x.ROUND_CEIL=2,x.ROUND_FLOOR=3,x.ROUND_HALF_UP=4,x.ROUND_HALF_DOWN=5,x.ROUND_HALF_EVEN=6,x.ROUND_HALF_CEIL=7,x.ROUND_HALF_FLOOR=8,x.EUCLID=9,x.config=x.set=function(l){var _,d;if(l!=null)if(typeof l=="object"){if(l.hasOwnProperty(_="DECIMAL_PLACES")&&(d=l[_],ne(d,0,ue,_),i=d),l.hasOwnProperty(_="ROUNDING_MODE")&&(d=l[_],ne(d,0,8,_),a=d),l.hasOwnProperty(_="EXPONENTIAL_AT")&&(d=l[_],d&&d.pop?(ne(d[0],-ue,0,_),ne(d[1],0,ue,_),c=d[0],p=d[1]):(ne(d,-ue,ue,_),c=-(p=d<0?-d:d))),l.hasOwnProperty(_="RANGE"))if(d=l[_],d&&d.pop)ne(d[0],-ue,-1,_),ne(d[1],1,ue,_),b=d[0],v=d[1];else if(ne(d,-ue,ue,_),d)b=-(v=d<0?-d:d);else throw Error(Pe+_+" cannot be zero: "+d);if(l.hasOwnProperty(_="CRYPTO"))if(d=l[_],d===!!d)if(d)if(typeof crypto<"u"&&crypto&&(crypto.getRandomValues||crypto.randomBytes))B=d;else throw B=!d,Error(Pe+"crypto unavailable");else B=d;else throw Error(Pe+_+" not true or false: "+d);if(l.hasOwnProperty(_="MODULO_MODE")&&(d=l[_],ne(d,0,9,_),N=d),l.hasOwnProperty(_="POW_PRECISION")&&(d=l[_],ne(d,0,ue,_),k=d),l.hasOwnProperty(_="FORMAT"))if(d=l[_],typeof d=="object")L=d;else throw Error(Pe+_+" not an object: "+d);if(l.hasOwnProperty(_="ALPHABET"))if(d=l[_],typeof d=="string"&&!/^.?$|[+\-.\s]|(.).*\1/.test(d))M=d.slice(0,10)=="0123456789",E=d;else throw Error(Pe+_+" invalid: "+d)}else throw Error(Pe+"Object expected: "+l);return{DECIMAL_PLACES:i,ROUNDING_MODE:a,EXPONENTIAL_AT:[c,p],RANGE:[b,v],CRYPTO:B,MODULO_MODE:N,POW_PRECISION:k,FORMAT:L,ALPHABET:E}},x.isBigNumber=function(l){if(!l||l._isBigNumber!==!0)return!1;if(!x.DEBUG)return!0;var _,d,w=l.c,m=l.e,f=l.s;e:if({}.toString.call(w)=="[object Array]"){if((f===1||f===-1)&&m>=-ue&&m<=ue&&m===Ie(m)){if(w[0]===0){if(m===0&&w.length===1)return!0;break e}if(_=(m+1)%U,_<1&&(_+=U),String(w[0]).length==_){for(_=0;_<w.length;_++)if(d=w[_],d<0||d>=Fe||d!==Ie(d))break e;if(d!==0)return!0}}}else if(w===null&&m===null&&(f===null||f===1||f===-1))return!0;throw Error(Pe+"Invalid BigNumber: "+l)},x.maximum=x.max=function(){return J(arguments,-1)},x.minimum=x.min=function(){return J(arguments,1)},x.random=function(){var l=9007199254740992,_=Math.random()*l&2097151?function(){return Ie(Math.random()*l)}:function(){return(Math.random()*1073741824|0)*8388608+(Math.random()*8388608|0)};return function(d){var w,m,f,y,g,h=0,S=[],P=new x(o);if(d==null?d=i:ne(d,0,ue),y=_n(d/U),B)if(crypto.getRandomValues){for(w=crypto.getRandomValues(new Uint32Array(y*=2));h<y;)g=w[h]*131072+(w[h+1]>>>11),g>=9e15?(m=crypto.getRandomValues(new Uint32Array(2)),w[h]=m[0],w[h+1]=m[1]):(S.push(g%1e14),h+=2);h=y/2}else if(crypto.randomBytes){for(w=crypto.randomBytes(y*=7);h<y;)g=(w[h]&31)*281474976710656+w[h+1]*1099511627776+w[h+2]*4294967296+w[h+3]*16777216+(w[h+4]<<16)+(w[h+5]<<8)+w[h+6],g>=9e15?crypto.randomBytes(7).copy(w,h):(S.push(g%1e14),h+=7);h=y/7}else throw B=!1,Error(Pe+"crypto unavailable");if(!B)for(;h<y;)g=_(),g<9e15&&(S[h++]=g%1e14);for(y=S[--h],d%=U,y&&d&&(g=pn[U-d],S[h]=Ie(y/g)*g);S[h]===0;S.pop(),h--);if(h<0)S=[f=0];else{for(f=-1;S[0]===0;S.splice(0,1),f-=U);for(h=1,g=S[0];g>=10;g/=10,h++);h<U&&(f-=U-h)}return P.e=f,P.c=S,P}}(),x.sum=function(){for(var l=1,_=arguments,d=new x(_[0]);l<_.length;)d=d.plus(_[l++]);return d},t=function(){var l="0123456789";function _(d,w,m,f){for(var y,g=[0],h,S=0,P=d.length;S<P;){for(h=g.length;h--;g[h]*=w);for(g[0]+=f.indexOf(d.charAt(S++)),y=0;y<g.length;y++)g[y]>m-1&&(g[y+1]==null&&(g[y+1]=0),g[y+1]+=g[y]/m|0,g[y]%=m)}return g.reverse()}return function(d,w,m,f,y){var g,h,S,P,I,D,q,V,ie=d.indexOf("."),ce=i,$=a;for(ie>=0&&(P=k,k=0,d=d.replace(".",""),V=new x(w),D=V.pow(d.length-ie),k=P,V.c=_(Ue(Be(D.c),D.e,"0"),10,m,l),V.e=V.c.length),q=_(d,w,m,y?(g=E,l):(g=l,E)),S=P=q.length;q[--P]==0;q.pop());if(!q[0])return g.charAt(0);if(ie<0?--S:(D.c=q,D.e=S,D.s=f,D=e(D,V,ce,$,m),q=D.c,I=D.r,S=D.e),h=S+ce+1,ie=q[h],P=m/2,I=I||h<0||q[h+1]!=null,I=$<4?(ie!=null||I)&&($==0||$==(D.s<0?3:2)):ie>P||ie==P&&($==4||I||$==6&&q[h-1]&1||$==(D.s<0?8:7)),h<1||!q[0])d=I?Ue(g.charAt(1),-ce,g.charAt(0)):g.charAt(0);else{if(q.length=h,I)for(--m;++q[--h]>m;)q[h]=0,h||(++S,q=[1].concat(q));for(P=q.length;!q[--P];);for(ie=0,d="";ie<=P;d+=g.charAt(q[ie++]));d=Ue(d,S,g.charAt(0))}return d}}(),e=function(){function l(w,m,f){var y,g,h,S,P=0,I=w.length,D=m%ze,q=m/ze|0;for(w=w.slice();I--;)h=w[I]%ze,S=w[I]/ze|0,y=q*h+S*D,g=D*h+y%ze*ze+P,P=(g/f|0)+(y/ze|0)+q*S,w[I]=g%f;return P&&(w=[P].concat(w)),w}function _(w,m,f,y){var g,h;if(f!=y)h=f>y?1:-1;else for(g=h=0;g<f;g++)if(w[g]!=m[g]){h=w[g]>m[g]?1:-1;break}return h}function d(w,m,f,y){for(var g=0;f--;)w[f]-=g,g=w[f]<m[f]?1:0,w[f]=g*y+w[f]-m[f];for(;!w[0]&&w.length>1;w.splice(0,1));}return function(w,m,f,y,g){var h,S,P,I,D,q,V,ie,ce,$,Q,me,xt,ln,cn,Re,pt,Oe=w.s==m.s?1:-1,we=w.c,se=m.c;if(!we||!we[0]||!se||!se[0])return new x(!w.s||!m.s||(we?se&&we[0]==se[0]:!se)?NaN:we&&we[0]==0||!se?Oe*0:Oe/0);for(ie=new x(Oe),ce=ie.c=[],S=w.e-m.e,Oe=f+S+1,g||(g=Fe,S=Ae(w.e/U)-Ae(m.e/U),Oe=Oe/U|0),P=0;se[P]==(we[P]||0);P++);if(se[P]>(we[P]||0)&&S--,Oe<0)ce.push(1),I=!0;else{for(ln=we.length,Re=se.length,P=0,Oe+=2,D=Ie(g/(se[0]+1)),D>1&&(se=l(se,D,g),we=l(we,D,g),Re=se.length,ln=we.length),xt=Re,$=we.slice(0,Re),Q=$.length;Q<Re;$[Q++]=0);pt=se.slice(),pt=[0].concat(pt),cn=se[0],se[1]>=g/2&&cn++;do{if(D=0,h=_(se,$,Re,Q),h<0){if(me=$[0],Re!=Q&&(me=me*g+($[1]||0)),D=Ie(me/cn),D>1)for(D>=g&&(D=g-1),q=l(se,D,g),V=q.length,Q=$.length;_(q,$,V,Q)==1;)D--,d(q,Re<V?pt:se,V,g),V=q.length,h=1;else D==0&&(h=D=1),q=se.slice(),V=q.length;if(V<Q&&(q=[0].concat(q)),d($,q,Q,g),Q=$.length,h==-1)for(;_(se,$,Re,Q)<1;)D++,d($,Re<Q?pt:se,Q,g),Q=$.length}else h===0&&(D++,$=[0]);ce[P++]=D,$[0]?$[Q++]=we[xt]||0:($=[we[xt]],Q=1)}while((xt++<ln||$[0]!=null)&&Oe--);I=$[0]!=null,ce[0]||ce.splice(0,1)}if(g==Fe){for(P=1,Oe=ce[0];Oe>=10;Oe/=10,P++);Z(ie,f+(ie.e=P+S*U-1)+1,y,I)}else ie.e=S,ie.r=+I;return ie}}();function G(l,_,d,w){var m,f,y,g,h;if(d==null?d=a:ne(d,0,8),!l.c)return l.toString();if(m=l.c[0],y=l.e,_==null)h=Be(l.c),h=w==1||w==2&&(y<=c||y>=p)?Tt(h,y):Ue(h,y,"0");else if(l=Z(new x(l),_,d),f=l.e,h=Be(l.c),g=h.length,w==1||w==2&&(_<=f||f<=c)){for(;g<_;h+="0",g++);h=Tt(h,f)}else if(_-=y,h=Ue(h,f,"0"),f+1>g){if(--_>0)for(h+=".";_--;h+="0");}else if(_+=f-g,_>0)for(f+1==g&&(h+=".");_--;h+="0");return l.s<0&&m?"-"+h:h}function J(l,_){for(var d,w,m=1,f=new x(l[0]);m<l.length;m++)w=new x(l[m]),(!w.s||(d=Je(f,w))===_||d===0&&f.s===_)&&(f=w);return f}function te(l,_,d){for(var w=1,m=_.length;!_[--m];_.pop());for(m=_[0];m>=10;m/=10,w++);return(d=w+d*U-1)>v?l.c=l.e=null:d<b?l.c=[l.e=0]:(l.e=d,l.c=_),l}n=function(){var l=/^(-?)0([xbo])(?=\w[\w.]*$)/i,_=/^([^.]+)\.$/,d=/^\.([^.]+)$/,w=/^-?(Infinity|NaN)$/,m=/^\s*\+(?=[\w.])|^\s+|\s+$/g;return function(f,y,g,h){var S,P=g?y:y.replace(m,"");if(w.test(P))f.s=isNaN(P)?null:P<0?-1:1;else{if(!g&&(P=P.replace(l,function(I,D,q){return S=(q=q.toLowerCase())=="x"?16:q=="b"?2:8,!h||h==S?D:I}),h&&(S=h,P=P.replace(_,"$1").replace(d,"0.$1")),y!=P))return new x(P,S);if(x.DEBUG)throw Error(Pe+"Not a"+(h?" base "+h:"")+" number: "+y);f.s=null}f.c=f.e=null}}();function Z(l,_,d,w){var m,f,y,g,h,S,P,I=l.c,D=pn;if(I){e:{for(m=1,g=I[0];g>=10;g/=10,m++);if(f=_-m,f<0)f+=U,y=_,h=I[S=0],P=Ie(h/D[m-y-1]%10);else if(S=_n((f+1)/U),S>=I.length)if(w){for(;I.length<=S;I.push(0));h=P=0,m=1,f%=U,y=f-U+1}else break e;else{for(h=g=I[S],m=1;g>=10;g/=10,m++);f%=U,y=f-U+m,P=y<0?0:Ie(h/D[m-y-1]%10)}if(w=w||_<0||I[S+1]!=null||(y<0?h:h%D[m-y-1]),w=d<4?(P||w)&&(d==0||d==(l.s<0?3:2)):P>5||P==5&&(d==4||w||d==6&&(f>0?y>0?h/D[m-y]:0:I[S-1])%10&1||d==(l.s<0?8:7)),_<1||!I[0])return I.length=0,w?(_-=l.e+1,I[0]=D[(U-_%U)%U],l.e=-_||0):I[0]=l.e=0,l;if(f==0?(I.length=S,g=1,S--):(I.length=S+1,g=D[U-f],I[S]=y>0?Ie(h/D[m-y]%D[y])*g:0),w)for(;;)if(S==0){for(f=1,y=I[0];y>=10;y/=10,f++);for(y=I[0]+=g,g=1;y>=10;y/=10,g++);f!=g&&(l.e++,I[0]==Fe&&(I[0]=1));break}else{if(I[S]+=g,I[S]!=Fe)break;I[S--]=0,g=1}for(f=I.length;I[--f]===0;I.pop());}l.e>v?l.c=l.e=null:l.e<b&&(l.c=[l.e=0])}return l}function H(l){var _,d=l.e;return d===null?l.toString():(_=Be(l.c),_=d<=c||d>=p?Tt(_,d):Ue(_,d,"0"),l.s<0?"-"+_:_)}return r.absoluteValue=r.abs=function(){var l=new x(this);return l.s<0&&(l.s=1),l},r.comparedTo=function(l,_){return Je(this,new x(l,_))},r.decimalPlaces=r.dp=function(l,_){var d,w,m,f=this;if(l!=null)return ne(l,0,ue),_==null?_=a:ne(_,0,8),Z(new x(f),l+f.e+1,_);if(!(d=f.c))return null;if(w=((m=d.length-1)-Ae(this.e/U))*U,m=d[m])for(;m%10==0;m/=10,w--);return w<0&&(w=0),w},r.dividedBy=r.div=function(l,_){return e(this,new x(l,_),i,a)},r.dividedToIntegerBy=r.idiv=function(l,_){return e(this,new x(l,_),0,1)},r.exponentiatedBy=r.pow=function(l,_){var d,w,m,f,y,g,h,S,P,I=this;if(l=new x(l),l.c&&!l.isInteger())throw Error(Pe+"Exponent not an integer: "+H(l));if(_!=null&&(_=new x(_)),g=l.e>14,!I.c||!I.c[0]||I.c[0]==1&&!I.e&&I.c.length==1||!l.c||!l.c[0])return P=new x(Math.pow(+H(I),g?l.s*(2-At(l)):+H(l))),_?P.mod(_):P;if(h=l.s<0,_){if(_.c?!_.c[0]:!_.s)return new x(NaN);w=!h&&I.isInteger()&&_.isInteger(),w&&(I=I.mod(_))}else{if(l.e>9&&(I.e>0||I.e<-1||(I.e==0?I.c[0]>1||g&&I.c[1]>=24e7:I.c[0]<8e13||g&&I.c[0]<=9999975e7)))return f=I.s<0&&At(l)?-0:0,I.e>-1&&(f=1/f),new x(h?1/f:f);k&&(f=_n(k/U+2))}for(g?(d=new x(.5),h&&(l.s=1),S=At(l)):(m=Math.abs(+H(l)),S=m%2),P=new x(o);;){if(S){if(P=P.times(I),!P.c)break;f?P.c.length>f&&(P.c.length=f):w&&(P=P.mod(_))}if(m){if(m=Ie(m/2),m===0)break;S=m%2}else if(l=l.times(d),Z(l,l.e+1,1),l.e>14)S=At(l);else{if(m=+H(l),m===0)break;S=m%2}I=I.times(I),f?I.c&&I.c.length>f&&(I.c.length=f):w&&(I=I.mod(_))}return w?P:(h&&(P=o.div(P)),_?P.mod(_):f?Z(P,k,a,y):P)},r.integerValue=function(l){var _=new x(this);return l==null?l=a:ne(l,0,8),Z(_,_.e+1,l)},r.isEqualTo=r.eq=function(l,_){return Je(this,new x(l,_))===0},r.isFinite=function(){return!!this.c},r.isGreaterThan=r.gt=function(l,_){return Je(this,new x(l,_))>0},r.isGreaterThanOrEqualTo=r.gte=function(l,_){return(_=Je(this,new x(l,_)))===1||_===0},r.isInteger=function(){return!!this.c&&Ae(this.e/U)>this.c.length-2},r.isLessThan=r.lt=function(l,_){return Je(this,new x(l,_))<0},r.isLessThanOrEqualTo=r.lte=function(l,_){return(_=Je(this,new x(l,_)))===-1||_===0},r.isNaN=function(){return!this.s},r.isNegative=function(){return this.s<0},r.isPositive=function(){return this.s>0},r.isZero=function(){return!!this.c&&this.c[0]==0},r.minus=function(l,_){var d,w,m,f,y=this,g=y.s;if(l=new x(l,_),_=l.s,!g||!_)return new x(NaN);if(g!=_)return l.s=-_,y.plus(l);var h=y.e/U,S=l.e/U,P=y.c,I=l.c;if(!h||!S){if(!P||!I)return P?(l.s=-_,l):new x(I?y:NaN);if(!P[0]||!I[0])return I[0]?(l.s=-_,l):new x(P[0]?y:a==3?-0:0)}if(h=Ae(h),S=Ae(S),P=P.slice(),g=h-S){for((f=g<0)?(g=-g,m=P):(S=h,m=I),m.reverse(),_=g;_--;m.push(0));m.reverse()}else for(w=(f=(g=P.length)<(_=I.length))?g:_,g=_=0;_<w;_++)if(P[_]!=I[_]){f=P[_]<I[_];break}if(f&&(m=P,P=I,I=m,l.s=-l.s),_=(w=I.length)-(d=P.length),_>0)for(;_--;P[d++]=0);for(_=Fe-1;w>g;){if(P[--w]<I[w]){for(d=w;d&&!P[--d];P[d]=_);--P[d],P[w]+=Fe}P[w]-=I[w]}for(;P[0]==0;P.splice(0,1),--S);return P[0]?te(l,P,S):(l.s=a==3?-1:1,l.c=[l.e=0],l)},r.modulo=r.mod=function(l,_){var d,w,m=this;return l=new x(l,_),!m.c||!l.s||l.c&&!l.c[0]?new x(NaN):!l.c||m.c&&!m.c[0]?new x(m):(N==9?(w=l.s,l.s=1,d=e(m,l,0,3),l.s=w,d.s*=w):d=e(m,l,0,N),l=m.minus(d.times(l)),!l.c[0]&&N==1&&(l.s=m.s),l)},r.multipliedBy=r.times=function(l,_){var d,w,m,f,y,g,h,S,P,I,D,q,V,ie,ce,$=this,Q=$.c,me=(l=new x(l,_)).c;if(!Q||!me||!Q[0]||!me[0])return!$.s||!l.s||Q&&!Q[0]&&!me||me&&!me[0]&&!Q?l.c=l.e=l.s=null:(l.s*=$.s,!Q||!me?l.c=l.e=null:(l.c=[0],l.e=0)),l;for(w=Ae($.e/U)+Ae(l.e/U),l.s*=$.s,h=Q.length,I=me.length,h<I&&(V=Q,Q=me,me=V,m=h,h=I,I=m),m=h+I,V=[];m--;V.push(0));for(ie=Fe,ce=ze,m=I;--m>=0;){for(d=0,D=me[m]%ce,q=me[m]/ce|0,y=h,f=m+y;f>m;)S=Q[--y]%ce,P=Q[y]/ce|0,g=q*S+P*D,S=D*S+g%ce*ce+V[f]+d,d=(S/ie|0)+(g/ce|0)+q*P,V[f--]=S%ie;V[f]=d}return d?++w:V.splice(0,1),te(l,V,w)},r.negated=function(){var l=new x(this);return l.s=-l.s||null,l},r.plus=function(l,_){var d,w=this,m=w.s;if(l=new x(l,_),_=l.s,!m||!_)return new x(NaN);if(m!=_)return l.s=-_,w.minus(l);var f=w.e/U,y=l.e/U,g=w.c,h=l.c;if(!f||!y){if(!g||!h)return new x(m/0);if(!g[0]||!h[0])return h[0]?l:new x(g[0]?w:m*0)}if(f=Ae(f),y=Ae(y),g=g.slice(),m=f-y){for(m>0?(y=f,d=h):(m=-m,d=g),d.reverse();m--;d.push(0));d.reverse()}for(m=g.length,_=h.length,m-_<0&&(d=h,h=g,g=d,_=m),m=0;_;)m=(g[--_]=g[_]+h[_]+m)/Fe|0,g[_]=Fe===g[_]?0:g[_]%Fe;return m&&(g=[m].concat(g),++y),te(l,g,y)},r.precision=r.sd=function(l,_){var d,w,m,f=this;if(l!=null&&l!==!!l)return ne(l,1,ue),_==null?_=a:ne(_,0,8),Z(new x(f),l,_);if(!(d=f.c))return null;if(m=d.length-1,w=m*U+1,m=d[m]){for(;m%10==0;m/=10,w--);for(m=d[0];m>=10;m/=10,w++);}return l&&f.e+1>w&&(w=f.e+1),w},r.shiftedBy=function(l){return ne(l,-dn,dn),this.times("1e"+l)},r.squareRoot=r.sqrt=function(){var l,_,d,w,m,f=this,y=f.c,g=f.s,h=f.e,S=i+4,P=new x("0.5");if(g!==1||!y||!y[0])return new x(!g||g<0&&(!y||y[0])?NaN:y?f:1/0);if(g=Math.sqrt(+H(f)),g==0||g==1/0?(_=Be(y),(_.length+h)%2==0&&(_+="0"),g=Math.sqrt(+_),h=Ae((h+1)/2)-(h<0||h%2),g==1/0?_="5e"+h:(_=g.toExponential(),_=_.slice(0,_.indexOf("e")+1)+h),d=new x(_)):d=new x(g+""),d.c[0]){for(h=d.e,g=h+S,g<3&&(g=0);;)if(m=d,d=P.times(m.plus(e(f,m,S,1))),Be(m.c).slice(0,g)===(_=Be(d.c)).slice(0,g))if(d.e<h&&--g,_=_.slice(g-3,g+1),_=="9999"||!w&&_=="4999"){if(!w&&(Z(m,m.e+i+2,0),m.times(m).eq(f))){d=m;break}S+=4,g+=4,w=1}else{(!+_||!+_.slice(1)&&_.charAt(0)=="5")&&(Z(d,d.e+i+2,1),l=!d.times(d).eq(f));break}}return Z(d,d.e+i+1,a,l)},r.toExponential=function(l,_){return l!=null&&(ne(l,0,ue),l++),G(this,l,_,1)},r.toFixed=function(l,_){return l!=null&&(ne(l,0,ue),l=l+this.e+1),G(this,l,_)},r.toFormat=function(l,_,d){var w,m=this;if(d==null)l!=null&&_&&typeof _=="object"?(d=_,_=null):l&&typeof l=="object"?(d=l,l=_=null):d=L;else if(typeof d!="object")throw Error(Pe+"Argument not an object: "+d);if(w=m.toFixed(l,_),m.c){var f,y=w.split("."),g=+d.groupSize,h=+d.secondaryGroupSize,S=d.groupSeparator||"",P=y[0],I=y[1],D=m.s<0,q=D?P.slice(1):P,V=q.length;if(h&&(f=g,g=h,h=f,V-=f),g>0&&V>0){for(f=V%g||g,P=q.substr(0,f);f<V;f+=g)P+=S+q.substr(f,g);h>0&&(P+=S+q.slice(f)),D&&(P="-"+P)}w=I?P+(d.decimalSeparator||"")+((h=+d.fractionGroupSize)?I.replace(new RegExp("\\d{"+h+"}\\B","g"),"$&"+(d.fractionGroupSeparator||"")):I):P}return(d.prefix||"")+w+(d.suffix||"")},r.toFraction=function(l){var _,d,w,m,f,y,g,h,S,P,I,D,q=this,V=q.c;if(l!=null&&(g=new x(l),!g.isInteger()&&(g.c||g.s!==1)||g.lt(o)))throw Error(Pe+"Argument "+(g.isInteger()?"out of range: ":"not an integer: ")+H(g));if(!V)return new x(q);for(_=new x(o),S=d=new x(o),w=h=new x(o),D=Be(V),f=_.e=D.length-q.e-1,_.c[0]=pn[(y=f%U)<0?U+y:y],l=!l||g.comparedTo(_)>0?f>0?_:S:g,y=v,v=1/0,g=new x(D),h.c[0]=0;P=e(g,_,0,1),m=d.plus(P.times(w)),m.comparedTo(l)!=1;)d=w,w=m,S=h.plus(P.times(m=S)),h=m,_=g.minus(P.times(m=_)),g=m;return m=e(l.minus(d),w,0,1),h=h.plus(m.times(S)),d=d.plus(m.times(w)),h.s=S.s=q.s,f=f*2,I=e(S,w,f,a).minus(q).abs().comparedTo(e(h,d,f,a).minus(q).abs())<1?[S,w]:[h,d],v=y,I},r.toNumber=function(){return+H(this)},r.toPrecision=function(l,_){return l!=null&&ne(l,1,ue),G(this,l,_,2)},r.toString=function(l){var _,d=this,w=d.s,m=d.e;return m===null?w?(_="Infinity",w<0&&(_="-"+_)):_="NaN":(l==null?_=m<=c||m>=p?Tt(Be(d.c),m):Ue(Be(d.c),m,"0"):l===10&&M?(d=Z(new x(d),i+m+1,a),_=Ue(Be(d.c),d.e,"0")):(ne(l,2,E.length,"Base"),_=t(Ue(Be(d.c),m,"0"),10,l,w,!0)),w<0&&d.c[0]&&(_="-"+_)),_},r.valueOf=r.toJSON=function(){return H(this)},r._isBigNumber=!0,r[Symbol.toStringTag]="BigNumber",r[Symbol.for("nodejs.util.inspect.custom")]=r.valueOf,s!=null&&x.set(s),x}function Ae(s){var e=s|0;return s>0||s===e?e:e-1}function Be(s){for(var e,t,n=1,r=s.length,o=s[0]+"";n<r;){for(e=s[n++]+"",t=U-e.length;t--;e="0"+e);o+=e}for(r=o.length;o.charCodeAt(--r)===48;);return o.slice(0,r+1||1)}function Je(s,e){var t,n,r=s.c,o=e.c,i=s.s,a=e.s,c=s.e,p=e.e;if(!i||!a)return null;if(t=r&&!r[0],n=o&&!o[0],t||n)return t?n?0:-a:i;if(i!=a)return i;if(t=i<0,n=c==p,!r||!o)return n?0:!r^t?1:-1;if(!n)return c>p^t?1:-1;for(a=(c=r.length)<(p=o.length)?c:p,i=0;i<a;i++)if(r[i]!=o[i])return r[i]>o[i]^t?1:-1;return c==p?0:c>p^t?1:-1}function ne(s,e,t,n){if(s<e||s>t||s!==Ie(s))throw Error(Pe+(n||"Argument")+(typeof s=="number"?s<e||s>t?" out of range: ":" not an integer: ":" not a primitive number: ")+String(s))}function At(s){var e=s.c.length-1;return Ae(s.e/U)==e&&s.c[e]%2!=0}function Tt(s,e){return(s.length>1?s.charAt(0)+"."+s.slice(1):s)+(e<0?"e":"e+")+e}function Ue(s,e,t){var n,r;if(e<0){for(r=t+".";++e;r+=t);s=r+s}else if(n=s.length,++e>n){for(r=t,e-=n;--e;r+=t);s+=r}else e<n&&(s=s.slice(0,e)+"."+s.slice(e));return s}var Le=An();var Tn=12;Le.config({EXPONENTIAL_AT:[-100,100],ROUNDING_MODE:4,DECIMAL_PLACES:Tn});var W=C(0),xe=C(1),ur=C("Infinity");function _e(s,e){let t=new Le(e.toString()),n=new Le(10).pow(t);return s.times(n)}function C(s){return new Le(s.toString())}var ye=(r=>(r.XYK="Xyk",r.LBP="Lbp",r.Stable="Stableswap",r.Omni="Omnipool",r))(ye||{}),Ke=(o=>(o.UnknownError="UnknownError",o.InsufficientTradingAmount="InsufficientTradingAmount",o.MaxInRatioExceeded="MaxInRatioExceeded",o.MaxOutRatioExceeded="MaxOutRatioExceeded",o.TradeNotAllowed="TradeNotAllowed",o))(Ke||{}),gn=(t=>(t.Buy="Buy",t.Sell="Sell",t))(gn||{});var De=Bt(Fn()),Te=class{static getSpotPrice(e,t,n,r,o){return(0,De.get_spot_price)(e,t,n,r,o)}static calculateInGivenOut(e,t,n,r,o){return(0,De.calculate_in_given_out)(e,t,n,r,o)}static calculateOutGivenIn(e,t,n,r,o){return(0,De.calculate_out_given_in)(e,t,n,r,o)}static calculateLinearWeights(e,t,n,r,o){return(0,De.calculate_linear_weights)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,De.calculate_pool_trade_fee)(e,t,n)}};var kn=require("@polkadot/util-crypto"),En=require("@polkadot/util"),et=18,Rt=15,We="0",wr=12,Pr=2034,tt=63,yr=2090,Lt=1e3,ht=(0,kn.encodeAddress)((0,En.stringToU8a)("modlomnipool".padEnd(32,"\0")),tt);var Bo=require("@polkadot/types/lookup");var Io=require("@polkadot/api-base/types/consts");var Ao=require("@polkadot/api-base/types/errors");var To=require("@polkadot/api-base/types/events");var No=require("@polkadot/api-base/types/storage");var Fo=require("@polkadot/api-base/types/submittable");var ko=require("@polkadot/rpc-core/types/jsonrpc");var Eo=require("@polkadot/api-base/types/calls");var Ho=require("@polkadot/types/types/registry");var Xo=require("@polkadot/types/lookup");var Yo=require("@polkadot/api-base/types/consts");var $o=require("@polkadot/api-base/types/errors");var Vo=require("@polkadot/api-base/types/events");var jo=require("@polkadot/api-base/types/storage");var Jo=require("@polkadot/api-base/types/submittable");var Zo=require("@polkadot/rpc-core/types/jsonrpc");var Qo=require("@polkadot/api-base/types/calls");var si=require("@polkadot/types/types/registry");var nt=class{api;constructor(e){this.api=e}get chainDecimals(){return this.api.registry.chainDecimals[0]}get chainToken(){return this.api.registry.chainTokens[0]}};var rt=class extends nt{SUPPORTED_TYPES=["StableSwap","Bond","Token"];constructor(e){super(e)}async safeSharesQuery(){try{let e=await this.api.query.stableswap.pools.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}async safeBondsQuery(){try{let e=await this.api.query.bonds.bonds.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}async metadataQuery(){try{let e=await this.api.query.assetRegistry.assetMetadataMap.entries();return new Map(e.map(([{args:[t]},n])=>[t.toString(),n.unwrap()]))}catch{return new Map([])}}getTokens(e,t,n){if(e==We){let p=this.api.consts.balances.existentialDeposit;return{id:We,name:this.chainToken,symbol:this.chainToken,decimals:this.chainDecimals,icon:this.chainToken,type:"Token",existentialDeposit:p.toString()}}let{name:r,assetType:o,existentialDeposit:i}=t,{symbol:a,decimals:c}=n.get(e);return{id:e,name:r.toHuman(),symbol:a.toHuman(),decimals:c.toNumber(),icon:a.toHuman(),type:o.toHuman(),existentialDeposit:i.toString()}}getBonds(e,t,n,r){let[o,i]=r,{assetType:a,existentialDeposit:c}=t,{symbol:p,decimals:b}=this.getTokens(o.toString(),t,n),v=i.toNumber(),B=new Intl.DateTimeFormat("en-GB"),N=[p,"Bond",B.format(v)].join(" ");return{id:e,name:N,symbol:p+"b",decimals:b,icon:p,type:a.toString(),existentialDeposit:c.toString()}}getShares(e,t,n,r){let{assets:o}=r,{name:i,assetType:a,existentialDeposit:c}=t,b=o.map(N=>N.toString()).map(N=>{let{symbol:k}=this.getTokens(N,t,n);return[N,k]}),v=Object.fromEntries(b),B=Object.values(v);return{id:e,name:B.join(", "),symbol:i.length>0?i.toHuman():e,decimals:18,icon:B.join("/"),type:a.toString(),existentialDeposit:c.toString(),meta:v}}async getOnChainAssets(){let[e,t,n,r]=await Promise.all([this.api.query.assetRegistry.assets.entries(),this.metadataQuery(),this.safeSharesQuery(),this.safeBondsQuery()]);return e.filter(([o,i])=>this.isSupportedType(i.unwrap())).map(([{args:[o]},i])=>{let a=i.unwrap(),{assetType:c}=a;switch(c.toString()){case"Bond":let p=r.get(o.toString());return this.getBonds(o.toString(),a,t,p);case"StableSwap":let b=n.get(o.toString());return this.getShares(o.toString(),a,t,b);default:return this.getTokens(o.toString(),a,t)}})}isSupportedType(e){return this.SUPPORTED_TYPES.includes(e.assetType.toString())}};var ot=class extends nt{constructor(e){super(e)}async getBalance(e,t){return t===We?await this.getSystemBalance(e):await this.getTokenBalance(e,t)}async getSystemBalance(e){let{data:{free:t,miscFrozen:n,feeFrozen:r}}=await this.api.query.system.account(e);return this.calculateFreeBalance(t.toString(),n.toString(),r.toString())}async getTokenBalance(e,t){let{free:n,reserved:r,frozen:o}=await this.api.query.tokens.accounts(e,t);return this.calculateFreeBalance(n.toString(),W.toFixed(),o.toString())}async subscribeBalance(e,t,n){let r=t.filter(o=>o!==We).map(o=>[e,o]);return this.api.query.tokens.accounts.multi(r,o=>{o.forEach(({free:i,reserved:a,frozen:c},p)=>{let b=this.calculateFreeBalance(i.toString(),a.toString(),c.toString()),v=r[p][1];n(v,b)})})}async subscribeTokenBalance(e,t,n){let r=t.filter(o=>o!==We).map(o=>[e,o]);return this.api.query.tokens.accounts.multi(r,o=>{o.forEach(({free:i,frozen:a},c)=>{let p=this.calculateFreeBalance(i.toString(),W.toFixed(),a.toString()),b=r[c][1];n(b,p)})})}async subscribeSystemBalance(e,t){return this.api.query.system.account(e,({data:{free:n,miscFrozen:r,feeFrozen:o}})=>{let i=this.calculateFreeBalance(n.toString(),r.toString(),o.toString());t(We,i)})}calculateFreeBalance(e,t,n){let r=new Le(e),o=new Le(t),i=new Le(n),a=o.gt(i)?o:i;return r.minus(a)}};var Ce=class extends ot{pools=[];subs=[];poolsLoaded=!1;constructor(e){super(e)}async getPools(){return this.poolsLoaded?this.pools:(this.pools=await this.loadPools(),this.subs=await this.subscribe(),this.poolsLoaded=!0,this.pools)}async subscribe(){let e=this.pools.map(async n=>{let r=[await this.subscribePoolChange(n),await this.subscribeTokensPoolBalance(n),await this.subscribeSystemPoolBalance(n)];if(this.hasShareAsset(n)){let o=await this.subscribeSharePoolBalance(n);r.push(o)}return this.subscribeLog(n),r});return(await Promise.all(e)).flat()}subscribeLog(e){let t=e.address.substring(0,10).concat("...");console.log(`${e.type} [${t}] balance subscribed`)}unsubscribe(){this.subs.forEach(e=>{e()})}hasShareAsset(e){return e.type==="Stableswap"&&e.id}subscribeTokensPoolBalance(e){return this.subscribeTokenBalance(e.address,e.tokens.map(t=>t.id),this.updateBalanceCallback(e,(t,n)=>t.id!==n))}subscribeSharePoolBalance(e){return this.subscribeTokenBalance(ht,[e.id],this.updateBalanceCallback(e,()=>!0))}subscribeSystemPoolBalance(e){return this.subscribeSystemBalance(e.address,this.updateBalanceCallback(e,()=>!0))}updateBalanceCallback(e,t){return function(n,r){let o=e.tokens.findIndex(i=>i.id==n);o>=0&&t(e,n)&&(e.tokens[o].balance=r.toString())}}};var Mt=class extends Ce{MAX_FINAL_WEIGHT=_e(C(100),6);poolsData=new Map([]);async loadPools(){let[e,t]=await Promise.all([this.api.query.lbp.poolData.entries(),this.api.query.parachainSystem.validationData()]),{relayParentNumber:n}=t.unwrap(),r=e.filter(([o,i])=>this.isActivePool(i.unwrap(),n)).map(async([{args:[o]},i])=>{let a=i.unwrap(),c=o.toString(),p=await this.getPoolDelta(c,a,n.toString());return this.poolsData.set(o.toString(),a),{address:c,type:"Lbp",fee:a.fee.toJSON(),...p,...this.getPoolLimits()}});return Promise.all(r)}async getPoolFees(e,t){let n=this.pools.find(r=>r.address===t);return{repayFee:this.getRepayFee(),exchangeFee:n.fee}}getPoolType(){return"Lbp"}async subscribePoolChange(e){return this.api.query.parachainSystem.validationData(async t=>{let{relayParentNumber:n}=t.unwrap(),r=this.poolsData.get(e.address);if(this.isActivePool(r,n)){let i=await this.getPoolDelta(e.address,r,n.toString());e={...e,...i}}else{let i=this.pools.findIndex(a=>a.address==e.address);this.pools.splice(i,1)}})}async getPoolDelta(e,t,n){let{start:r,end:o,assets:i,initialWeight:a,finalWeight:c,repayTarget:p,feeCollector:b}=t,v=Te.calculateLinearWeights(r.toString(),o.toString(),a.toString(),c.toString(),n),[B,N]=i,k=B.toString(),L=C(v),E=N.toString(),M=this.MAX_FINAL_WEIGHT.minus(C(L)),[x,G,J]=await Promise.all([this.isRepayFeeApplied(k,p.toString(),b.toString()),this.getBalance(e,k),this.getBalance(e,E)]);return{repayFeeApply:x,tokens:[{id:k,weight:L,balance:G.toString()},{id:E,weight:M,balance:J.toString()}]}}isActivePool(e,t){let n=e.start.unwrap().toNumber(),r=e.end.unwrap().toNumber();return t.toNumber()>=n&&t.toNumber()<r}async isRepayFeeApplied(e,t,n){let r=C(t);if(r.isZero())return!1;try{return(await this.getBalance(e,n)).isLessThan(r)}catch{return!0}}getRepayFee(){return this.api.consts.lbp.repayFee.toJSON()}getPoolLimits(){let e=this.api.consts.lbp.maxInRatio.toJSON(),t=this.api.consts.lbp.maxOutRatio.toJSON(),n=this.api.consts.lbp.minTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Rn=require("@polkadot/util-crypto"),Ln=require("@polkadot/util");function ge(s,e){return s.shiftedBy(-1*e).toString()}function Ne(s){return s[0]/s[1]*100}function Se(s){return s[0]/s[1]}function ke(s){return[s/Lt,Lt]}var Dt=class extends Ce{async loadPools(){let e=this.api.consts.omnipool.hubAssetId.toString(),t=this.getPoolId(),[n,r,o]=await Promise.all([this.api.query.omnipool.assets.entries(),this.api.query.omnipool.hubAssetTradability(),this.getBalance(t,e)]),i=n.map(async([{args:[c]},p])=>{let{hubReserve:b,shares:v,tradable:B}=p.unwrap(),N=await this.getBalance(t,c.toString());return{id:c.toString(),hubReserves:C(b.toString()),shares:C(v.toString()),tradeable:B.bits.toNumber(),balance:N.toString()}}),a=await Promise.all(i);return a.push({id:e,tradeable:r.bits.toNumber(),balance:o.toString()}),[{address:t,type:"Omnipool",hubAssetId:e,tokens:a,...this.getPoolLimits()}]}async getPoolFees(e,t){let n=await this.api.query.dynamicFees.assetFee(e),r=this.api.consts.dynamicFees.assetFeeParameters,o=this.api.consts.dynamicFees.protocolFeeParameters,i=r.minFee.toNumber()+o.minFee.toNumber(),a=r.maxFee.toNumber()+o.maxFee.toNumber();if(n.isSome){let{assetFee:c,protocolFee:p}=n.unwrap();return{assetFee:ke(c.toNumber()),protocolFee:ke(p.toNumber()),min:ke(i),max:ke(a)}}else return{assetFee:this.getAssetFee(),protocolFee:this.getProtocolFee(),min:ke(i),max:ke(a)}}getPoolType(){return"Omnipool"}async subscribePoolChange(e){let t=e.tokens.map(n=>n.id);return this.api.query.omnipool.assets.multi(t,n=>{e.tokens=n.map((r,o)=>{let i=e.tokens[o];if(r.isNone)return i;let a=r.unwrap();return this.updateTokenState(i,a)})})}updateTokenState(e,t){let{hubReserve:n,shares:r,tradable:o}=t;return{...e,hubReserves:C(n.toString()),shares:C(r.toString()),tradeable:o.bits.toNumber()}}getAssetFee(){let t=this.api.consts.dynamicFees.assetFeeParameters.minFee.toNumber();return ke(t)}getProtocolFee(){let t=this.api.consts.dynamicFees.protocolFeeParameters.minFee.toNumber();return ke(t)}getPoolId(){return(0,Rn.encodeAddress)((0,Ln.stringToU8a)("modlomnipool".padEnd(32,"\0")),tt)}getPoolLimits(){let e=this.api.consts.omnipool.maxInRatio.toJSON(),t=this.api.consts.omnipool.maxOutRatio.toJSON(),n=this.api.consts.omnipool.minimumTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Ct=class extends Ce{async loadPools(){let t=(await this.api.query.xyk.poolAssets.entries()).map(async([{args:[n]},r])=>{let o=n.toString(),[i,a]=r.unwrap(),[c,p]=await Promise.all([this.getBalance(o,i.toString()),this.getBalance(o,a.toString())]);return{address:o,type:"Xyk",tokens:[{id:i.toString(),balance:c.toString()},{id:a.toString(),balance:p.toString()}],...this.getPoolLimits()}});return Promise.all(t)}async getPoolFees(e,t){return{exchangeFee:this.getExchangeFee()}}getPoolType(){return"Xyk"}subscribePoolChange(e){return this.api.query.xyk.poolAssets(e.address,t=>{})}getExchangeFee(){return this.api.consts.xyk.getExchangeFee.toJSON()}getPoolLimits(){let e=this.api.consts.xyk.maxInRatio.toJSON(),t=this.api.consts.xyk.maxOutRatio.toJSON(),n=this.api.consts.xyk.minTradingLimit.toJSON();return{maxInRatio:e,maxOutRatio:t,minTradingLimit:n}}};var Wt=require("@polkadot/util-crypto");var pe=Bt(Dn()),ve=class{static getPoolAddress(e){return(0,pe.pool_account_name)(e)}static calculateAmplification(e,t,n,r,o){return(0,pe.calculate_amplification)(e,t,n,r,o)}static calculateInGivenOut(e,t,n,r,o,i){return(0,pe.calculate_in_given_out)(e,t,n,r,o,i)}static calculateAddOneAsset(e,t,n,r,o,i){return(0,pe.calculate_add_one_asset)(e,t,n,r,o,i)}static calculateSharesForAmount(e,t,n,r,o,i){return(0,pe.calculate_shares_for_amount)(e,t,n,r,o,i)}static calculateOutGivenIn(e,t,n,r,o,i){return(0,pe.calculate_out_given_in)(e,t,n,r,o,i)}static calculateLiquidityOutOneAsset(e,t,n,r,o,i){return(0,pe.calculate_liquidity_out_one_asset)(e,t,n,r,o,i)}static calculateShares(e,t,n,r,o){return(0,pe.calculate_shares)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,pe.calculate_pool_trade_fee)(e,t,n)}};var Ut=class extends Ce{stablePools=new Map([]);async loadPools(){let[e,t]=await Promise.all([this.api.query.stableswap.pools.entries(),this.api.query.system.number()]),n=t.toNumber(),r=e.map(async([{args:[o]},i])=>{let a=i.unwrap(),c=o.toString(),p=this.getPoolAddress(c),[b,v]=await Promise.all([this.getPoolDelta(c,a,n.toString()),this.getPoolTokens(p,c,a)]);return this.stablePools.set(p,a),{address:p,id:c,type:"Stableswap",fee:ke(a.fee.toNumber()),tokens:v,...b,...this.getPoolLimits()}});return Promise.all(r)}async getPoolFees(e,t){return{fee:this.pools.find(r=>r.address===t).fee}}getPoolType(){return"Stableswap"}async subscribePoolChange(e){return this.api.query.system.number(async t=>{let n=t.toNumber(),r=this.stablePools.get(e.address),o=await this.getPoolDelta(e.id,r,n.toString());e={...e,...o}})}async getPoolDelta(e,t,n){let{initialAmplification:r,finalAmplification:o,initialBlock:i,finalBlock:a}=t,c=ve.calculateAmplification(r.toString(),o.toString(),i.toString(),a.toString(),n),p=await this.api.query.tokens.totalIssuance(e);return{amplification:c,totalIssuance:p.toString()}}async getPoolTokens(e,t,n){let{assets:r}=n,o=r.map(async c=>{let[p,b]=await Promise.all([this.api.query.stableswap.assetTradability(t,c.toString()),this.getBalance(e,c.toString())]);return{id:c.toString(),tradeable:p.bits.toNumber(),balance:b.toString()}}),i=await Promise.all(o),a=await this.api.query.omnipool.assets(t);if(a.isSome){let{tradable:c}=a.unwrap(),p=await this.getBalance(ht,t);i.push({id:t,tradeable:c.bits.toNumber(),balance:p.toString()})}return i}getPoolAddress(e){let t=Number(e),n=ve.getPoolAddress(t);return(0,Wt.encodeAddress)((0,Wt.blake2AsHex)(n),tt)}getPoolLimits(){return{maxInRatio:0,maxOutRatio:0,minTradingLimit:this.api.consts.stableswap.minTradingLimit.toJSON()}}};function zt(s){return s.map(({assetIn:e,assetOut:t,pool:n,poolId:r})=>n==="Stableswap"?{pool:{Stableswap:r},assetIn:e,assetOut:t}:{pool:n,assetIn:e,assetOut:t})}var wt=class extends Error{constructor(e){super(),this.message=`${e} pool invalid`,this.name="PoolNotFound"}},mn=class extends Error{constructor(e,t){super(),this.message=`${e} pool missing ${t}`,this.name="PoolConfigNotFound"}},it=class extends Error{constructor(e,t){super(),this.message=`Route from ${e} to ${t} not found in pool configuration`,this.name="RouteNotFound"}},fn=class extends Error{constructor(e){super(),this.message=`Asset ${e} not available in current network`,this.name="AssetNotFound"}},hn=class extends Error{constructor(e){super(),this.message=`Storage missing ${e}`,this.name="StorageConfigNotFound"}},bn=class extends Error{constructor(e){super(),this.message=`Subscription type "${e}" not supported`,this.name="SubscriptionNotSupported"}},wn=class extends Error{constructor(e){super(),this.message=`${e}`,this.name="ProviderConfigNotFound"}};var st=class{api;assetClient;xykClient;omniClient;lbpClient;stableClient;onChainAssets=[];onChainAssetsLoaded=!1;constructor(e){this.api=e,this.assetClient=new rt(this.api),this.xykClient=new Ct(this.api),this.omniClient=new Dt(this.api),this.lbpClient=new Mt(this.api),this.stableClient=new Ut(this.api)}async getPools(e){if(this.onChainAssetsLoaded||(this.onChainAssets=await this.assetClient.getOnChainAssets(),this.onChainAssetsLoaded=!0),e.length==0){let i=(await Promise.all([this.xykClient.getPools(),this.omniClient.getPools(),this.lbpClient.getPools(),this.stableClient.getPools()])).flat();return this.withMetadata(i)}let t=[];e.forEach(o=>{switch(o){case"Xyk":t.push(this.xykClient.getPools());break;case"Omnipool":t.push(this.omniClient.getPools());break;case"Lbp":t.push(this.lbpClient.getPools());break;case"Stableswap":t.push(this.stableClient.getPools());break}});let r=(await Promise.all(t)).flat();return this.withMetadata(r)}unsubscribe(){this.xykClient.unsubscribe(),this.omniClient.unsubscribe(),this.lbpClient.unsubscribe(),this.stableClient.unsubscribe()}async withMetadata(e){let t=new Map(this.onChainAssets.map(n=>[n.id,n]));return e.map(n=>{let r=n.tokens.map(o=>{let i=t.get(o.id);return{...o,...i}});return{...n,tokens:r}})}async getPoolFees(e,t){switch(t.type){case"Xyk":return this.xykClient.getPoolFees(e,t.address);case"Omnipool":return this.omniClient.getPoolFees(e,t.address);case"Lbp":return this.lbpClient.getPoolFees(e,t.address);case"Stableswap":return this.stableClient.getPoolFees(e,t.address);default:throw new wt(t.type)}}isDirectOmnipoolTrade(e){return e.length==1&&e[0].pool=="Omnipool"}buildBuyTx(e,t,n,r,o){let i;this.isDirectOmnipoolTrade(o)?i=this.api.tx.omnipool.buy(t,e,n.toFixed(),r.toFixed()):i=this.api.tx.router.buy(e,t,n.toFixed(),r.toFixed(),zt(o));let a=()=>i;return{hex:i.toHex(),name:"RouterBuy",get:a}}buildSellTx(e,t,n,r,o){let i;this.isDirectOmnipoolTrade(o)?i=this.api.tx.omnipool.sell(e,t,n.toFixed(),r.toFixed()):i=this.api.tx.router.sell(e,t,n.toFixed(),r.toFixed(),zt(o));let a=()=>i;return{hex:i.toHex(),name:"RouterSell",get:a}}};var Pt=(s,e)=>s===e?0:s==null?e==null?0:-1:e==null?s==null?0:1:typeof s.compare=="function"?s.compare(e):typeof e.compare=="function"?-e.compare(s):s<e?-1:s>e?1:0;var Xt=(s,e=t=>t!==void 0?": "+t:"")=>class extends Error{constructor(t){super(s(t)+e(t))}};var Fr=Xt(()=>"illegal argument(s)"),Cn=s=>{throw new Fr(s)};var kr=Xt(()=>"index out of bounds"),Pn=s=>{throw new kr(s)},Yt=(s,e,t)=>(s<e||s>=t)&&Pn(s);var qn=23283064365386963e-26,$t=class{float(e=1){return this.int()*qn*e}probability(e){return this.float()<e}norm(e=1){return(this.int()*qn-.5)*2*e}normMinMax(e,t){let n=this.minmax(e,t);return this.float()<.5?n:-n}minmax(e,t){return this.float()*(t-e)+e}minmaxInt(e,t){e|=0;let n=(t|0)-e;return n?e+this.int()%n:e}minmaxUint(e,t){e>>>=0;let n=(t>>>0)-e;return n?e+this.int()%n:e}};var yn=Math.random,Sn=class extends $t{int(){return yn()*4294967296>>>0}float(e=1){return yn()*e}norm(e=1){return(yn()-.5)*2*e}},Gn=new Sn;var Hn=s=>s!=null&&typeof s!="function"&&s.length!==void 0;var Un=Object.getPrototypeOf({}),Vt="function",Wn="string",at=(s,e)=>{let t;if(s===e)return!0;if(s!=null){if(typeof s.equiv===Vt)return s.equiv(e)}else return s==e;if(e!=null){if(typeof e.equiv===Vt)return e.equiv(s)}else return s==e;return typeof s===Wn||typeof e===Wn?!1:(t=Object.getPrototypeOf(s),(t==null||t===Un)&&(t=Object.getPrototypeOf(e),t==null||t===Un)?Mr(s,e):typeof s!==Vt&&s.length!==void 0&&typeof e!==Vt&&e.length!==void 0?Er(s,e):s instanceof Set&&e instanceof Set?Rr(s,e):s instanceof Map&&e instanceof Map?Lr(s,e):s instanceof Date&&e instanceof Date?s.getTime()===e.getTime():s instanceof RegExp&&e instanceof RegExp?s.toString()===e.toString():s!==s&&e!==e)},Er=(s,e,t=at)=>{let n=s.length;if(n===e.length)for(;n-- >0&&t(s[n],e[n]););return n<0},Rr=(s,e,t=at)=>s.size===e.size&&t([...s.keys()].sort(),[...e.keys()].sort()),Lr=(s,e,t=at)=>s.size===e.size&&t([...s].sort(),[...e].sort()),Mr=(s,e,t=at)=>{if(Object.keys(s).length!==Object.keys(e).length)return!1;for(let n in s)if(!e.hasOwnProperty(n)||!t(s[n],e[n]))return!1;return!0};var zn=(s,e)=>s!=null&&typeof s[e]=="function";var Xn=s=>zn(s,"xform")?s.xform():s;var jt=Symbol(),xn=()=>{};var Yn=s=>s!=null&&typeof s[Symbol.iterator]=="function";var Jt=class{value;constructor(e){this.value=e}deref(){return this.value}};var Zt=s=>s instanceof Jt;var $n=s=>s instanceof Jt?s.deref():s;function*Vn(s,e){let t=Xn(s)([xn,xn,(n,r)=>r])[2];for(let n of e){let r=t(jt,n);if(Zt(r)){r=$n(r.deref()),r!==jt&&(yield r);return}r!==jt&&(yield r)}}var jn=(s,e)=>[s[0],s[1],e];function yt(s,e){return Yn(e)?Vn(yt(s),e):t=>{let n=t[2];return jn(t,(r,o)=>n(r,s(o)))}}var lt=class{_head;_length=0;constructor(e){e&&this.into(e)}get length(){return this._length}get head(){return this._head}[Symbol.iterator](){return Jn("next",this._head)}reverseIterator(){return Jn("prev",this.tail)}clear(){this.release()}compare(e,t=Pt){let n=this._length;if(n<e._length)return-1;if(n>e._length)return 1;if(n===0)return 0;{let r=this._head,o=e._head,i=0;for(;n-- >0&&i===0;)i=t(r.value,o.value),r=r.next,o=o.next;return i}}concat(...e){let t=this.copy();for(let n of e)t.into(n);return t}equiv(e){if(!(e instanceof lt||Hn(e))||this._length!==e.length)return!1;if(!this._length||this===e)return!0;let t=e[Symbol.iterator](),n=this._head;for(let r=this._length;r-- >0;){if(!at(n.value,t.next().value))return!1;n=n.next}return!0}filter(e){let t=this.empty();return this.traverse(n=>(e(n.value)&&t.append(n.value),!0)),t}find(e){return this.traverse(t=>t.value!==e)}findWith(e){return this.traverse(t=>!e(t.value))}first(){return this._head&&this._head.value}insertSorted(e,t){t=t||Pt;for(let n=this._head,r=this._length;r-- >0;){if(t(e,n.value)<=0)return this.insertBefore(n,e);n=n.next}return this.append(e)}into(e){for(let t of e)this.append(t);return this}nth(e,t){let n=this.nthCell(e);return n?n.value:t}nthCellUnsafe(e){let t,n;for(e<=this._length>>>1?(t=this._head,n="next"):(t=this.tail,n="prev",e=this._length-e-1);e-- >0&&t;)t=t[n];return t}peek(){return this.tail&&this.tail.value}$reduce(e,t){let n=this._head;for(let r=this._length;r-- >0&&!Zt(t);)t=e(t,n.value),n=n.next;return t}reduce(e,t){return this.$reduce(e,t)}release(){let e=this._head;if(!e)return!0;let t;for(let n=this._length;n-- >0;)t=e.next,delete e.value,delete e.prev,delete e.next,e=t;return this._head=void 0,this._length=0,!0}reverse(){let e=this._head,t=this.tail,n=(this._length>>>1)+(this._length&1);for(;e&&t&&n>0;){let r=e.value;e.value=t.value,t.value=r,e=e.next,t=t.prev,n--}return this}setHead(e){let t=this._head;return t?(t.value=e,t):this.prepend(e)}setNth(e,t){let n=this.nthCell(e);return!n&&Pn(e),n.value=t,n}setTail(e){let t=this.tail;return t?(t.value=e,t):this.append(e)}swap(e,t){if(e!==t){let n=e.value;e.value=t.value,t.value=n}return this}toArray(e=[]){return this.traverse(t=>(e.push(t.value),!0)),e}toJSON(){return this.toArray()}toString(){let e=[];return this.traverse(t=>(e.push(String(t.value)),!0)),e.join(", ")}traverse(e,t=this._head,n){if(!this._head)return;let r=t;do{if(!e(r))break;r=r.next}while(r!==n);return r}_map(e,t){return this.traverse(n=>(e.append(t(n.value)),!0)),e}};function*Jn(s,e){for(;e;)yield e.value,e=e[s]}var qe=class extends lt{_tail;constructor(e){super(),e&&this.into(e)}get tail(){return this._tail}append(e){if(this._tail){let t={value:e,prev:this._tail};return this._tail.next=t,this._tail=t,this._length++,t}else return this.prepend(e)}asHead(e){return e===this._head?this:(this.remove(e),this._head.prev=e,e.next=this._head,e.prev=void 0,this._head=e,this._length++,this)}asTail(e){return e===this._tail?this:(this.remove(e),this._tail.next=e,e.prev=this._tail,e.next=void 0,this._tail=e,this._length++,this)}cons(e){return this.prepend(e),this}copy(){return new qe(this)}*cycle(){for(;;)yield*this}drop(){let e=this._head;if(e)return this._head=e.next,this._head?this._head.prev=void 0:this._tail=void 0,this._length--,e.value}empty(){return new qe}insertAfter(e,t){let n={value:t,next:e.next,prev:e};return e.next?e.next.prev=n:this._tail=n,e.next=n,this._length++,n}insertAfterNth(e,t){return e<0&&(e+=this._length),e>=this._length-1?this.append(t):(Yt(e,0,this._length),this.insertAfter(this.nthCellUnsafe(e),t))}insertBefore(e,t){let n={value:t,next:e,prev:e.prev};return e.prev?e.prev.next=n:this._head=n,e.prev=n,this._length++,n}insertBeforeNth(e,t){return e<0&&(e+=this._length),e<=0?this.prepend(t):(Yt(e,0,this._length),this.insertBefore(this.nthCellUnsafe(e),t))}map(e){return this._map(new qe,e)}nth(e,t){let n=this.nthCell(e);return n?n.value:t}nthCell(e){if(e<0&&(e+=this._length),!(e<0||e>=this._length))return this.nthCellUnsafe(e)}pop(){let e=this._tail;if(e)return this._tail=e.prev,this._tail?this._tail.next=void 0:this._head=void 0,this._length--,e.value}prepend(e){let t={value:e,next:this._head};return this._head?this._head.prev=t:this._tail=t,this._head=t,this._length++,t}push(e){return this.append(e),this}release(){return this._tail=void 0,super.release()}remove(e){return e.prev?e.prev.next=e.next:this._head=e.next,e.next?e.next.prev=e.prev:this._tail=e.prev,this._length--,this}rotateLeft(){switch(this._length){case 0:case 1:return this;case 2:return this.swap(this._head,this._tail);default:return this.push(this.drop())}}rotateRight(){switch(this._length){case 0:case 1:return this;case 2:return this.swap(this._head,this._tail);default:let e=this.peek();return this.pop(),this.prepend(e),this}}seq(e=0,t=this.length){if(e>=t||e<0)return;let n=this.nthCell(e),r=this.nthCell(t-1),o=i=>({first(){return i.value},next(){return i!==r&&i.next?o(i.next):void 0}});return n?o(n):void 0}shuffle(e,t=Gn){if(this._length<2)return this;for(e=e!==void 0?e:Math.ceil(1.5*Math.log2(this._length));e>0;e--){let n=this._head;for(;n;){let r=n.next;t.probability(.5)?this.asHead(n):this.asTail(n),n=r}}return this}slice(e=0,t=this.length){let n=e<0?e+this._length:e,r=t<0?t+this._length:t;(n<0||r<0)&&Cn("invalid indices: ${from} / ${to}");let o=new qe,i=this.nthCell(n);for(;i&&++n<=r;)o.push(i.value),i=i.next;return o}sort(e=Pt){if(!this._length)return this;let t=1;for(;;){let n=this._head;this._head=void 0,this._tail=void 0;let r=0;for(;n;){r++;let o=n,i=0;for(let c=0;c<t&&(i++,o=o.next,!!o);c++);let a=t;for(;i>0||a>0&&o;){let c;i===0?(c=o,o=o.next,a--):!o||a===0||e(n.value,o.value)<=0?(c=n,n=n.next,i--):(c=o,o=o.next,a--),this._tail?this._tail.next=c:this._head=c,c.prev=this._tail,this._tail=c}n=o}if(this._tail.next=void 0,r<=1)return this;t*=2}}splice(e,t=0,n){let r;typeof e=="number"?(e<0&&(e+=this._length),Yt(e,0,this._length),r=this.nthCellUnsafe(e)):r=e;let o=new qe;if(t>0)for(;r&&t-- >0;)this.remove(r),o.push(r.value),r=r.next;else r&&(r=r.next);if(n)if(r)for(let i of n)this.insertBefore(r,i);else for(let i of n)this.push(i);return o}};var ct=class{map;items;opts;_size;constructor(e,t){let n=Object.assign({maxlen:1/0,maxsize:1/0,map:()=>new Map,ksize:()=>0,vsize:()=>0},t);this.map=n.map(),this.items=new qe,this._size=0,this.opts=n,e&&this.into(e)}get length(){return this.items.length}get size(){return this._size}[Symbol.iterator](){return this.entries()}entries(){return yt(e=>[e.k,e],this.items)}keys(){return yt(e=>e.k,this.items)}values(){return yt(e=>e.v,this.items)}copy(){let e=this.empty();e.items=this.items.copy();let t=e.items.head;for(;t;)e.map.set(t.value.k,t),t=t.next;return e}empty(){return new ct(null,this.opts)}release(){this._size=0,this.map.clear();let e=this.opts.release;if(e){let t;for(;t=this.items.drop();)e(t.k,t.v);return!0}return this.items.release()}has(e){return this.map.has(e)}get(e,t){let n=this.map.get(e);return n?this.resetEntry(n):t}set(e,t){let n=this.opts.ksize(e)+this.opts.vsize(t),r=this.map.get(e);return this._size+=Math.max(0,n-(r?r.value.s:0)),this.ensureSize()&&this.doSetEntry(r,e,t,n),t}into(e){for(let t of e)this.set(t[0],t[1]);return this}getSet(e,t){let n=this.map.get(e);return n?Promise.resolve(this.resetEntry(n)):t().then(r=>this.set(e,r))}delete(e){let t=this.map.get(e);return t?(this.removeEntry(t),!0):!1}resetEntry(e){return this.items.asTail(e),e.value.v}ensureSize(){let e=this.opts.release,t=this.opts.maxsize,n=this.opts.maxlen;for(;this._size>t||this.length>=n;){let r=this.items.drop();if(!r)return!1;this.map.delete(r.k),e&&e(r.k,r.v),this._size-=r.s}return!0}removeEntry(e){let t=e.value;this.map.delete(t.k),this.items.remove(e),this.opts.release&&this.opts.release(t.k,t.v),this._size-=t.s}doSetEntry(e,t,n,r){e?(e.value.v=n,e.value.s=r,this.items.asTail(e)):(this.items.push({k:t,v:n,s:r}),this.map.set(t,this.items.tail))}};var Qt=class extends st{feeCache;disconnectSubscribeNewHeads=null;constructor(e){super(e),this.feeCache=new ct(null),this.api.rpc.chain.subscribeNewHeads(async t=>{this.feeCache.release()}).then(t=>{this.disconnectSubscribeNewHeads=t})}async getPoolFees(e,t){let n=[t.address,e].join("-");if(this.feeCache.has(n))return this.feeCache.get(n);{let o=await super.getPoolFees(e,t);return this.feeCache.set(n,o),o}}async destroy(){console.log(`Destroying pool cache!
2
+ Items: [${this.feeCache.length}]`),this.feeCache.release(),this.disconnectSubscribeNewHeads?.()}};var Ye=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;fee;repayFeeApply;static fromPool(e){return new Ye(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.fee,e.repayFeeApply)}constructor(e,t,n,r,o,i,a){this.type="Lbp",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.fee=i,this.repayFeeApply=a}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,balanceIn:i,balanceOut:a,decimalsIn:r.decimals,decimalsOut:o.decimals,weightIn:r.weight,weightOut:o.weight}}validateAndBuy(e,t,n){let r=this.tokens[0].id,o=[];t.isLessThan(this.minTradingLimit)&&o.push("InsufficientTradingAmount");let i=e.balanceOut.div(this.maxOutRatio);if(t.isGreaterThan(i)&&o.push("MaxOutRatioExceeded"),r===e.assetOut){let a=this.calculateTradeFee(t,n),c=Ne(this.repayFeeApply?n.repayFee:n.exchangeFee),p=t.plus(a),b=this.calculateInGivenOut(e,p),v=e.balanceIn.div(this.maxInRatio);return b.isGreaterThan(v)&&o.push("MaxInRatioExceeded"),{amountIn:b,calculatedIn:b,amountOut:t,feePct:c,errors:o}}else{let a=this.calculateInGivenOut(e,t),c=e.balanceIn.div(this.maxInRatio);return a.isGreaterThan(c)&&o.push("MaxInRatioExceeded"),{amountIn:a,calculatedIn:a,amountOut:t,feePct:0,errors:o}}}validateAndSell(e,t,n){let r=this.tokens[0].id,o=[];t.isLessThan(this.minTradingLimit)&&o.push("InsufficientTradingAmount");let i=e.balanceIn.div(this.maxInRatio);if(t.isGreaterThan(i)&&o.push("MaxInRatioExceeded"),r===e.assetIn){let a=this.calculateOutGivenIn(e,t),c=e.balanceOut.div(this.maxOutRatio);return a.isGreaterThan(c)&&o.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:a,amountOut:a,feePct:0,errors:o}}else{let a=this.calculateOutGivenIn(e,t),c=this.calculateTradeFee(a,n),p=Ne(this.repayFeeApply?n.repayFee:n.exchangeFee),b=a.minus(c),v=e.balanceOut.div(this.maxOutRatio);return b.isGreaterThan(v)&&o.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:a,amountOut:b,feePct:p,errors:o}}}calculateInGivenOut(e,t){let n=Te.calculateInGivenOut(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}calculateOutGivenIn(e,t){let n=Te.calculateOutGivenIn(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}spotPriceInGivenOut(e){let t=Te.getSpotPrice(e.balanceOut.toString(),e.balanceIn.toString(),e.weightOut.toString(),e.weightIn.toString(),_e(xe,e.decimalsOut).toString());return C(t)}spotPriceOutGivenIn(e){let t=Te.getSpotPrice(e.balanceIn.toString(),e.balanceOut.toString(),e.weightIn.toString(),e.weightOut.toString(),_e(xe,e.decimalsIn).toString());return C(t)}calculateTradeFee(e,t){let n=Te.calculatePoolTradeFee(e.toString(),this.repayFeeApply?t.repayFee[0]:t.exchangeFee[0],this.repayFeeApply?t.repayFee[1]:t.exchangeFee[1]);return C(n)}};var Y=Bt(Qn()),ae=class{static calculateSpotPrice(e,t,n,r){return(0,Y.calculate_spot_price)(e,t,n,r)}static calculateLrnaSpotPrice(e,t){return(0,Y.calculate_lrna_spot_price)(e,t)}static calculateInGivenOut(e,t,n,r,o,i,a,c,p){return(0,Y.calculate_in_given_out)(e,t,n,r,o,i,a,c,p)}static calculateLrnaInGivenOut(e,t,n,r,o){return(0,Y.calculate_lrna_in_given_out)(e,t,n,r,o)}static calculateOutGivenIn(e,t,n,r,o,i,a,c,p){return(0,Y.calculate_out_given_in)(e,t,n,r,o,i,a,c,p)}static calculateOutGivenLrnaIn(e,t,n,r,o){return(0,Y.calculate_out_given_lrna_in)(e,t,n,r,o)}static calculatePoolTradeFee(e,t,n){return(0,Y.calculate_pool_trade_fee)(e,t,n)}static calculateShares(e,t,n,r){return(0,Y.calculate_shares)(e,t,n,r)}static calculateLiquidityOut(e,t,n,r,o,i,a,c){return(0,Y.calculate_liquidity_out)(e,t,n,r,o,i,a,c)}static calculateLiquidityLRNAOut(e,t,n,r,o,i,a,c){return(0,Y.calculate_liquidity_lrna_out)(e,t,n,r,o,i,a,c)}static calculateCapDifference(e,t,n,r){return(0,Y.calculate_cap_difference)(e,t,n,r)}static verifyAssetCap(e,t,n,r){return(0,Y.verify_asset_cap)(e,t,n,r)}static calculateLimitHubIn(e,t,n,r){return(0,Y.calculate_liquidity_hub_in)(e,t,n,r)}static isSellAllowed(e){return(0,Y.is_sell_allowed)(e)}static isBuyAllowed(e){return(0,Y.is_buy_allowed)(e)}static isAddLiquidityAllowed(e){return(0,Y.is_add_liquidity_allowed)(e)}static isRemoveLiquidityAllowed(e){return(0,Y.is_remove_liquidity_allowed)(e)}};var $e=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;hubAssetId;static fromPool(e){return new $e(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.hubAssetId)}constructor(e,t,n,r,o,i){this.type="Omnipool",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.hubAssetId=i}validatePair(e,t){return this.hubAssetId!=t}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,hubReservesIn:r.hubReserves,hubReservesOut:o.hubReserves,sharesIn:r.shares,sharesOut:o.shares,decimalsIn:r.decimals,decimalsOut:o.decimals,balanceIn:i,balanceOut:a,tradeableIn:r.tradeable,tradeableOut:o.tradeable}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateInGivenOut(e,t,n),i=o.minus(r),a=r===W?W:i.div(r).multipliedBy(100).decimalPlaces(2),c=[],p=ae.isSellAllowed(e.tradeableIn),b=ae.isBuyAllowed(e.tradeableOut);(!p||!b)&&c.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let v=e.balanceOut.div(this.maxOutRatio);t.isGreaterThan(v)&&c.push("MaxOutRatioExceeded");let B=e.balanceIn.div(this.maxInRatio);return o.isGreaterThan(B)&&c.push("MaxInRatioExceeded"),{amountIn:o,calculatedIn:r,amountOut:t,feePct:a.toNumber(),errors:c}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateOutGivenIn(e,t,n),a=r.minus(o).div(r).multipliedBy(100).decimalPlaces(2),c=[],p=ae.isSellAllowed(e.tradeableIn),b=ae.isBuyAllowed(e.tradeableOut);(!p||!b)&&c.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let v=e.balanceIn.div(this.maxInRatio);t.isGreaterThan(v)&&c.push("MaxInRatioExceeded");let B=e.balanceOut.div(this.maxOutRatio);return o.isGreaterThan(B)&&c.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:r,amountOut:o,feePct:a.toNumber(),errors:c}}calculateInGivenOut(e,t,n){if(e.assetIn==this.hubAssetId)return this.calculateLrnaInGivenOut(e,t,n);let r=ae.calculateInGivenOut(e.balanceIn.toString(),e.hubReservesIn.toString(),e.sharesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString(),n?Se(n.protocolFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateLrnaInGivenOut(e,t,n){let r=ae.calculateLrnaInGivenOut(e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenIn(e,t,n){if(e.assetIn==this.hubAssetId)return this.calculateOutGivenLrnaIn(e,t,n);let r=ae.calculateOutGivenIn(e.balanceIn.toString(),e.hubReservesIn.toString(),e.sharesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString(),n?Se(n.protocolFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenLrnaIn(e,t,n){let r=ae.calculateOutGivenLrnaIn(e.balanceOut.toString(),e.hubReservesOut.toString(),e.sharesOut.toString(),t.toFixed(0),n?Se(n.assetFee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}spotPriceInGivenOut(e){if(e.assetIn==this.hubAssetId)return this.spotPriceLrnaInGivenOut(e);let t=ae.calculateSpotPrice(e.balanceOut.toString(),e.hubReservesOut.toString(),e.balanceIn.toString(),e.hubReservesIn.toString());return C(t).shiftedBy(-1*(et-e.decimalsOut)).decimalPlaces(0,1)}spotPriceLrnaInGivenOut(e){let t=ae.calculateLrnaSpotPrice(e.hubReservesOut.toString(),e.balanceOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsOut)).decimalPlaces(0,1)}spotPriceOutGivenIn(e){if(e.assetIn==this.hubAssetId)return this.spotPriceOutGivenLrnaIn(e);let t=ae.calculateSpotPrice(e.balanceIn.toString(),e.hubReservesIn.toString(),e.balanceOut.toString(),e.hubReservesOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsIn)).decimalPlaces(0,1)}spotPriceOutGivenLrnaIn(e){let t=ae.calculateLrnaSpotPrice(e.balanceOut.toString(),e.hubReservesOut.toString());return C(t).shiftedBy(-1*(et-e.decimalsIn)).decimalPlaces(0,1)}};var ut=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;amplification;id;fee;totalIssuance;static fromPool(e){return new ut(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit,e.amplification,e.id,e.fee,e.totalIssuance)}constructor(e,t,n,r,o,i,a,c,p){this.type="Stableswap",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o,this.amplification=i,this.id=a,this.fee=c,this.totalIssuance=p}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,balanceIn:i,balanceOut:a,decimalsIn:r.decimals,decimalsOut:o.decimals,tradeableIn:this.id===e?Rt:r.tradeable,tradeableOut:this.id===t?Rt:o.tradeable}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateInGivenOut(e,t,n),i=Ne(n.fee),a=[],c=ae.isSellAllowed(e.tradeableIn),p=ae.isBuyAllowed(e.tradeableOut);return(!c||!p)&&a.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&a.push("InsufficientTradingAmount"),{amountIn:o,calculatedIn:r,amountOut:t,feePct:i,errors:a}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateOutGivenIn(e,t,n),i=Ne(n.fee),a=[],c=ae.isSellAllowed(e.tradeableIn),p=ae.isBuyAllowed(e.tradeableOut);return(!c||!p)&&a.push("TradeNotAllowed"),t.isLessThan(this.minTradingLimit)&&a.push("InsufficientTradingAmount"),{amountIn:t,calculatedOut:r,amountOut:o,feePct:i,errors:a}}calculateIn(e,t,n){let r=ve.calculateInGivenOut(this.getReserves(),Number(e.assetIn),Number(e.assetOut),t.toFixed(0),this.amplification,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateAddOneAsset(e,t,n){let r=ve.calculateAddOneAsset(this.getReserves(),t.toFixed(0),Number(e.assetIn),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateSharesForAmount(e,t,n){let r=ve.calculateSharesForAmount(this.getReserves(),Number(e.assetOut),t.toFixed(0),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateInGivenOut(e,t,n){return e.assetOut==this.id?this.calculateAddOneAsset(e,t,n):e.assetIn==this.id?this.calculateSharesForAmount(e,t,n):this.calculateIn(e,t,n)}spotPriceInGivenOut(e){let t=_e(xe,e.decimalsOut);return e.assetOut==this.id?this.calculateAddOneAsset(e,t):e.assetIn==this.id?this.calculateSharesForAmount(e,t):this.calculateIn(e,t)}calculateOut(e,t,n){let r=ve.calculateOutGivenIn(this.getReserves(),Number(e.assetIn),Number(e.assetOut),t.toFixed(0),this.amplification,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateWithdrawOneAsset(e,t,n){let r=ve.calculateLiquidityOutOneAsset(this.getReserves(),t.toFixed(0),Number(e.assetOut),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateShares(e,t,n){let r=ve.calculateShares(this.getReserves(),this.getAssets(e.assetIn,t),this.amplification,this.totalIssuance,n?Se(n.fee).toString():W.toString()),o=C(r);return o.isNegative()?W:o}calculateOutGivenIn(e,t,n){return e.assetIn==this.id?this.calculateWithdrawOneAsset(e,t,n):e.assetOut==this.id?this.calculateShares(e,t,n):this.calculateOut(e,t,n)}spotPriceOutGivenIn(e){let t=_e(xe,e.decimalsIn);return e.assetIn==this.id?this.calculateWithdrawOneAsset(e,t):e.assetOut==this.id?this.calculateShares(e,t):this.calculateOut(e,t)}calculateTradeFee(e,t){let n=ve.calculatePoolTradeFee(e.toString(),t.fee[0],t.fee[1]);return C(n)}getReserves(){let e=this.tokens.filter(t=>t.id!=this.id).map(({id:t,balance:n,decimals:r})=>({asset_id:Number(t),amount:n,decimals:r}));return JSON.stringify(e)}getAssets(e,t){let n={asset_id:Number(e),amount:t.toFixed(0)};return JSON.stringify([n])}};var be=Bt(er()),He=class{static getSpotPrice(e,t,n){return(0,be.get_spot_price)(e,t,n)}static calculateInGivenOut(e,t,n){return(0,be.calculate_in_given_out)(e,t,n)}static calculateOutGivenIn(e,t,n){return(0,be.calculate_out_given_in)(e,t,n)}static calculatePoolTradeFee(e,t,n){return(0,be.calculate_pool_trade_fee)(e,t,n)}static calculateLiquidityIn(e,t,n){return(0,be.calculate_liquidity_in)(e,t,n)}static calculateShares(e,t,n){return(0,be.calculate_shares)(e,t,n)}static calculateLiquidityOutAssetA(e,t,n,r){return(0,be.calculate_liquidity_out_asset_a)(e,t,n,r)}static calculateLiquidityOutAssetB(e,t,n,r){return(0,be.calculate_liquidity_out_asset_b)(e,t,n,r)}};var je=class{type;address;tokens;maxInRatio;maxOutRatio;minTradingLimit;static fromPool(e){return new je(e.address,e.tokens,e.maxInRatio,e.maxOutRatio,e.minTradingLimit)}constructor(e,t,n,r,o){this.type="Xyk",this.address=e,this.tokens=t,this.maxInRatio=n,this.maxOutRatio=r,this.minTradingLimit=o}validatePair(e,t){return!0}parsePair(e,t){let n=new Map(this.tokens.map(c=>[c.id,c])),r=n.get(e),o=n.get(t);if(r==null)throw new Error("Pool does not contain tokenIn");if(o==null)throw new Error("Pool does not contain tokenOut");let i=C(r.balance),a=C(o.balance);return{assetIn:e,assetOut:t,decimalsIn:r.decimals,decimalsOut:o.decimals,balanceIn:i,balanceOut:a}}validateAndBuy(e,t,n){let r=this.calculateInGivenOut(e,t),o=this.calculateTradeFee(r,n),i=Ne(n.exchangeFee),a=r.plus(o),c=[];t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let p=e.balanceOut.div(this.maxOutRatio);t.isGreaterThan(p)&&c.push("MaxOutRatioExceeded");let b=e.balanceIn.div(this.maxInRatio);return a.isGreaterThan(b)&&c.push("MaxInRatioExceeded"),{amountIn:a,calculatedIn:r,amountOut:t,feePct:i,errors:c}}validateAndSell(e,t,n){let r=this.calculateOutGivenIn(e,t),o=this.calculateTradeFee(r,n),i=Ne(n.exchangeFee),a=r.minus(o),c=[];t.isLessThan(this.minTradingLimit)&&c.push("InsufficientTradingAmount");let p=e.balanceIn.div(this.maxInRatio);t.isGreaterThan(p)&&c.push("MaxInRatioExceeded");let b=e.balanceOut.div(this.maxOutRatio);return a.isGreaterThan(b)&&c.push("MaxOutRatioExceeded"),{amountIn:t,calculatedOut:r,amountOut:a,feePct:i,errors:c}}calculateInGivenOut(e,t){let n=He.calculateInGivenOut(e.balanceIn.toString(),e.balanceOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}calculateOutGivenIn(e,t){let n=He.calculateOutGivenIn(e.balanceIn.toString(),e.balanceOut.toString(),t.toFixed(0)),r=C(n);return r.isNegative()?W:r}spotPriceInGivenOut(e){let t=He.getSpotPrice(e.balanceOut.toString(),e.balanceIn.toString(),_e(xe,e.decimalsOut).toString());return C(t)}spotPriceOutGivenIn(e){let t=He.getSpotPrice(e.balanceIn.toString(),e.balanceOut.toString(),_e(xe,e.decimalsIn).toString());return C(t)}calculateTradeFee(e,t){let n=He.calculatePoolTradeFee(e.toString(),t.exchangeFee[0],t.exchangeFee[1]);return C(n)}};var _t=class{static get(e){switch(e.type){case"Xyk":return je.fromPool(e);case"Omnipool":return $e.fromPool(e);case"Lbp":return Ye.fromPool(e);case"Stableswap":return ut.fromPool(e);default:throw new Error("Pool type "+e.type+" is not supported yet")}}};var Qe=class{routeSuggester;routerOptions;poolService;defaultRouterOptions={includeOnly:[]};constructor(e,t){this.poolService=e,this.routeSuggester=new mt,this.routerOptions={...this.defaultRouterOptions,...t}}async getPools(){let e=this.routerOptions.includeOnly;return await this.poolService.getPools(e)}async getAllAssets(){let e=await this.getPools();if(e.length===0)throw new Error("No pools configured");let t=await this.getAssets(e);return[...new Map(t).values()]}async getAssetPairs(e){let t=await this.getPools();if(t.length===0)throw new Error("No pools configured");let{assets:n,poolsMap:r}=await this.validateToken(e,t),i=this.getPaths(e,null,r,t).map(a=>a[a.length-1].assetOut);return this.toAssets([...new Set(i)],n)}async getAllPaths(e,t){let n=await this.getPools();if(n.length===0)throw new Error("No pools configured");let{poolsMap:r}=await this.validateTokenPair(e,t,n);return this.getPaths(e,t,r,n)}async getAssets(e){let t=e.map(n=>n.tokens.map(r=>({id:r.id,name:r.name,symbol:r.symbol,decimals:r.decimals,icon:r.icon,type:r.type,existentialDeposit:r.existentialDeposit,meta:r.meta}))).flat();return new Map(t.map(n=>[n.id,n]))}getPaths(e,t,n,r){return this.routeSuggester.getProposals(e,t,r).filter(a=>this.validPath(a,n)).map(a=>this.toHops(a,n))}async validateTokenPair(e,t,n){let r=await this.getAssets(n);if(r.get(e)==null)throw new Error(e+" is not supported token");if(r.get(t)==null)throw new Error(t+" is not supported token");let o=this.getPoolMap(n);return{assets:r,poolsMap:o}}async validateToken(e,t){let n=await this.getAssets(t);if(n.get(e)==null)throw new Error(e+" is not supported token");let r=this.getPoolMap(t);return{assets:n,poolsMap:r}}getPoolMap(e){return new Map(e.map(t=>[t.address,_t.get(t)]))}validPath(e,t){return e.length>0&&e.map(n=>this.validEdge(n,t)).reduce((n,r)=>n&&r)}validEdge([e,t,n],r){return r.get(e)?.validatePair(t,n)||!1}toHops(e,t){return e.map(([n,r,o])=>{let i=t.get(n);return{poolAddress:n,poolId:i?.id,pool:i?.type,assetIn:r,assetOut:o}})}toAssets(e,t){return e.map(n=>t.get(n))}};function Kr(s,e){return s.minus(e).abs().div(s.plus(e).div(2)).multipliedBy(100).decimalPlaces(2)}function dt(s,e){return s.minus(e).div(e).multipliedBy(100).decimalPlaces(2)}function vn(s,e){return xe.minus(e.div(s)).multipliedBy(100).decimalPlaces(2)}function On(s,e){return e.div(s).minus(xe).multipliedBy(100).decimalPlaces(2)}var St=class extends Qe{isDirectTrade(e){return e.length==1}findBestSellRoute(e){let t=e.sort((n,r)=>{let o=n[n.length-1].amountOut,i=r[r.length-1].amountOut;return o.isGreaterThan(i)?-1:1});return t.find(n=>n.every(r=>r.errors.length==0))||t[0]}getRouteFeeRange(e){if(e.filter(n=>n.tradeFeeRange).length>0){let n=e.map(o=>o.tradeFeeRange?.[0]??o.tradeFeePct).reduce((o,i)=>o+i),r=e.map(o=>o.tradeFeeRange?.[1]??o.tradeFeePct).reduce((o,i)=>o+i);return[n,r]}}getPoolFeeRange(e){let t=e.min?Ne(e.min):void 0,n=e.max?Ne(e.max):void 0;if(t&&n)return[t,n]}async getBestSell(e,t,n){let r=await super.getPools();if(r.length===0)throw new Error("No pools configured");let{poolsMap:o}=await super.validateTokenPair(e,t,r),i=super.getPaths(e,t,o,r);if(i.length===0)throw new it(e,t);let a=i.map(async H=>await this.toSellSwaps(n,H,o)),c=await Promise.all(a),p=this.findBestSellRoute(c),b=p[0],v=p[p.length-1],B=this.isDirectTrade(p),N=p.map(H=>H.spotPrice.shiftedBy(-1*H.assetOutDecimals)).reduce((H,l)=>H.multipliedBy(l)),k=_e(N,v.assetOutDecimals).decimalPlaces(0,1),L=b.amountIn.shiftedBy(-1*b.assetInDecimals).multipliedBy(k),E=dt(v.calculatedOut,L),M=B?v.calculatedOut:this.calculateDelta0Y(b.amountIn,p,o),x=v.amountOut,G=B?v.tradeFeePct:vn(M,x).toNumber(),J=M.minus(x),te=this.getRouteFeeRange(p),Z=H=>this.poolService.buildSellTx(e,t,b.amountIn,H,p.map(l=>l));return{type:"Sell",amountIn:b.amountIn,amountOut:v.amountOut,spotPrice:k,tradeFee:J,tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E.toNumber(),swaps:p,toTx:Z,toHuman(){return{type:"Sell",amountIn:ge(b.amountIn,b.assetInDecimals),amountOut:ge(v.amountOut,v.assetOutDecimals),spotPrice:ge(k,v.assetOutDecimals),tradeFee:ge(J,v.assetOutDecimals),tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E.toNumber(),swaps:p.map(H=>H.toHuman())}}}}calculateDelta0Y(e,t,n){let r=[];for(let o=0;o<t.length;o++){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o>0?p=r[o-1]:p=e;let b=a.calculateOutGivenIn(c,p);r.push(b)}return r[r.length-1]}async toSellSwaps(e,t,n){let r=[];for(let o=0;o<t.length;o++){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o>0?p=r[o-1].amountOut:p=_e(C(e),c.decimalsIn).decimalPlaces(0,1);let b=await this.poolService.getPoolFees(c.assetOut,a),{amountOut:v,calculatedOut:B,feePct:N,errors:k}=a.validateAndSell(c,p,b),L=this.getPoolFeeRange(b),E=a.spotPriceOutGivenIn(c),M=p.shiftedBy(-1*c.decimalsIn).multipliedBy(E),x=dt(B,M);r.push({...i,assetInDecimals:c.decimalsIn,assetOutDecimals:c.decimalsOut,amountIn:p,calculatedOut:B,amountOut:v,spotPrice:E,tradeFeePct:N,tradeFeeRange:L,priceImpactPct:x.toNumber(),errors:k,toHuman(){return{...i,amountIn:ge(p,c.decimalsIn),calculatedOut:ge(B,c.decimalsOut),amountOut:ge(v,c.decimalsOut),spotPrice:ge(E,c.decimalsOut),tradeFeePct:N,tradeFeeRange:L,priceImpactPct:x.toNumber(),errors:k}}})}return r}async getBestSpotPrice(e,t){let n=await super.getPools();if(n.length===0)throw new Error("No pools configured");let{poolsMap:r}=await super.validateTokenPair(e,t,n),o=super.getPaths(e,t,r,n);if(o.length===0)return Promise.resolve(void 0);let i=o.map(async B=>await this.toSellSwaps("1",B,r)),a=await Promise.all(i),c=this.findBestSellRoute(a),p=c.map(B=>B.spotPrice.shiftedBy(-1*B.assetOutDecimals)).reduce((B,N)=>B.multipliedBy(N)),b=c[c.length-1].assetOutDecimals;return{amount:_e(p,b).decimalPlaces(0,1),decimals:b}}findBestBuyRoute(e){let t=e.sort((n,r)=>{let o=n[0].amountIn,i=r[0].amountIn;return o.isGreaterThan(i)?1:-1});return t.find(n=>n.every(r=>r.errors.length==0))||t[0]}async getBestBuy(e,t,n){let r=await super.getPools();if(r.length===0)throw new Error("No pools configured");let{poolsMap:o}=await super.validateTokenPair(e,t,r),i=super.getPaths(e,t,o,r);if(i.length===0)throw new it(e,t);let a=i.map(async H=>await this.toBuySwaps(n,H,o)),c=await Promise.all(a),p=this.findBestBuyRoute(c),b=p[p.length-1],v=p[0],B=this.isDirectTrade(p),N=p.map(H=>H.spotPrice.shiftedBy(-1*H.assetInDecimals)).reduce((H,l)=>H.multipliedBy(l)),k=_e(N,v.assetInDecimals).decimalPlaces(0,1),L=b.amountOut.shiftedBy(-1*b.assetOutDecimals).multipliedBy(k),E;v.calculatedIn.isZero()?E=-100:E=dt(L,v.calculatedIn).toNumber();let M=B?v.calculatedIn:this.calculateDelta0X(b.amountOut,p,o),x=v.amountIn,G=B?v.tradeFeePct:On(M,x),J=x.minus(M),te=this.getRouteFeeRange(p),Z=H=>this.poolService.buildBuyTx(e,t,b.amountOut,H,p.map(l=>l));return{type:"Buy",amountOut:b.amountOut,amountIn:v.amountIn,spotPrice:k,tradeFee:J,tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E,swaps:p,toTx:Z,toHuman(){return{type:"Buy",amountOut:ge(b.amountOut,b.assetOutDecimals),amountIn:ge(v.amountIn,v.assetInDecimals),spotPrice:ge(k,v.assetInDecimals),tradeFee:ge(J,v.assetInDecimals),tradeFeePct:G,tradeFeeRange:te,priceImpactPct:E,swaps:p.map(H=>H.toHuman())}}}}calculateDelta0X(e,t,n){let r=[];for(let o=t.length-1;o>=0;o--){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o==t.length-1?p=e:p=r[0];let b=a.calculateInGivenOut(c,p);r.unshift(b)}return r[0]}async toBuySwaps(e,t,n){let r=[];for(let o=t.length-1;o>=0;o--){let i=t[o],a=n.get(i.poolAddress);if(a==null)throw new Error("Pool does not exit");let c=a.parsePair(i.assetIn,i.assetOut),p;o==t.length-1?p=_e(C(e),c.decimalsOut).decimalPlaces(0,1):p=r[0].amountIn;let b=await this.poolService.getPoolFees(c.assetIn,a),{amountIn:v,calculatedIn:B,feePct:N,errors:k}=a.validateAndBuy(c,p,b),L=this.getPoolFeeRange(b),E=a.spotPriceInGivenOut(c),M=p.shiftedBy(-1*c.decimalsOut).multipliedBy(E),x;B.isZero()?x=-100:x=dt(M,B).toNumber(),r.unshift({...i,assetInDecimals:c.decimalsIn,assetOutDecimals:c.decimalsOut,amountOut:p,calculatedIn:B,amountIn:v,spotPrice:E,tradeFeePct:N,tradeFeeRange:L,priceImpactPct:x,errors:k,toHuman(){return{...i,amountOut:ge(p,c.decimalsOut),calculatedIn:ge(B,c.decimalsIn),amountIn:ge(v,c.decimalsIn),spotPrice:ge(E,c.decimalsIn),tradeFeePct:N,tradeFeeRange:L,priceImpactPct:x,errors:k}}})}return r}};0&&(module.exports={AssetClient,AssetNotFound,BASILISK_PARACHAIN_ID,BalanceClient,BigNumber,CachingPoolService,DECIMAL_PLACES,DENOMINATOR,HYDRADX_OMNIPOOL_ADDRESS,HYDRADX_PARACHAIN_ID,HYDRADX_SS58_PREFIX,INFINITY,LbpMath,LbpPool,ONE,OmniMath,OmniPool,PoolConfigNotFound,PoolError,PoolFactory,PoolNotFound,PoolService,PoolType,ProviderConfigNotFound,RUNTIME_DECIMALS,RouteNotFound,Router,SYSTEM_ASSET_DECIMALS,SYSTEM_ASSET_ID,StorageConfigNotFound,SubscriptionNotSupported,TRADEABLE_DEFAULT,TradeRouter,TradeType,XykMath,XykPool,ZERO,bnum,buildRoute,calculateBuyFee,calculateDiffToAvg,calculateDiffToRef,calculateSellFee,scale});