UNPKG

@bancor/carbon-sdk

Version:

The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfi

2 lines (1 loc) 20.7 kB
"use strict";var e=require("./encoders-DBOv0ukp.cjs"),t=require("./match-BtbxSR0V.cjs"),r=require("./decimals-DbQULq1R.cjs"),a=require("./utils-Dk1Vz9Yd.cjs"),i=require("./logger-BbRNJAwH.cjs"),c=require("./serializers-gTido5tE.cjs");function s(t,r){const a=t.map((t=>{const r=new e.Decimal(t.lowestRate).sqrt(),a=new e.Decimal(t.marginalRate).sqrt();return{liq:new e.Decimal(t.liquidity),min:r,mid:a,midMinusMin:a.sub(r)}}));return r.map((t=>{const r=t.sqrt();return a.reduce(((t,a)=>t.add(function(t,r){if(r.lte(t.min))return t.liq;if(r.gte(t.mid))return new e.Decimal(0);return t.liq.sub(t.liq.mul(r.sub(t.min)).div(t.midMinusMin))}(a,r))),new e.Decimal(0))}))}const o=new i.Logger("utils.ts");function n(t,r,a){return new e.Decimal(t.toString()).times(e.tenPow(r,a)).toFixed()}function d(t,r,a){return 0==+t.toString()?"0":new e.Decimal(1).div(t.toString()).times(e.tenPow(a,r)).toFixed()}const l=t=>{const[r,a]=e.encodeOrders([t.order0,t.order1]);return{token0:t.token0,token1:t.token1,order0:r,order1:a}},g=t=>({id:t.id,token0:t.token0,token1:t.token1,order0:e.decodeOrder(t.order0),order1:e.decodeOrder(t.order1),encoded:t});async function u(t,r){o.debug("parseStrategy called",arguments);const{id:a,token0:i,token1:s,order0:l,order1:g,encoded:u}=t,m=await r.fetchDecimals(i),y=await r.fetchDecimals(s),h=n(g.lowestRate,m,y),p=n(g.marginalRate,m,y),S=n(g.highestRate,m,y),B=d(l.highestRate,y,m),P=d(l.marginalRate,y,m),w=d(l.lowestRate,y,m),D=e.formatUnits(l.liquidity,m),b=e.formatUnits(g.liquidity,y),f=a.toString(),T=c.encodedStrategyBigIntToStr(u);return o.debug("parseStrategy info:",{id:f,token0:i,token1:s,order0:l,order1:g,decimals0:m,decimals1:y,baseToken:i,quoteToken:s,buyPriceLow:h,buyPriceMarginal:p,buyPriceHigh:S,buyBudget:b,sellPriceLow:B,sellPriceMarginal:P,sellPriceHigh:w,sellBudget:D,encoded:T}),{id:f,baseToken:i,quoteToken:s,buyPriceLow:h,buyPriceMarginal:p,buyPriceHigh:S,buyBudget:b,sellPriceLow:B,sellPriceMarginal:P,sellPriceHigh:w,sellBudget:D,encoded:T}}function m(t,r,a,i,c,s,n,d,l,g,u,m){if(o.debug("buildStrategyObject called",arguments),new e.Decimal(c).isNegative()||new e.Decimal(s).isNegative()||new e.Decimal(n).isNegative()||new e.Decimal(l).isNegative()||new e.Decimal(g).isNegative()||new e.Decimal(u).isNegative())throw new Error("prices cannot be negative");if(new e.Decimal(c).gt(s)||new e.Decimal(c).gt(n)||new e.Decimal(s).gt(n)||new e.Decimal(l).gt(g)||new e.Decimal(l).gt(u)||new e.Decimal(g).gt(u))throw new Error("low/marginal price must be lower than or equal to marginal/high price");if(new e.Decimal(d).isNegative()||new e.Decimal(m).isNegative())throw new Error("budgets cannot be negative");const{order0:y,order1:h}=p(a,i,c,s,n,d,l,g,u,m);return o.debug("buildStrategyObject info:",{token0:t,token1:r,order0:y,order1:h}),{token0:t,token1:r,order0:y,order1:h}}function y(t,r,a,i,c,s){o.debug("createFromBuyOrder called",arguments);const d=e.parseUnits(s,r),l=n(a,r,t),g=n(i,r,t),u=n(c,r,t),m={liquidity:d.toString(),lowestRate:l,highestRate:u,marginalRate:g};return o.debug("createFromBuyOrder info:",{order:m}),m}function h(t,r,a,i,c,s){o.debug("createFromSellOrder called",arguments);const n=e.parseUnits(s,t),l=d(c,r,t),g=d(i,r,t),u=d(a,r,t),m={liquidity:n.toString(),lowestRate:l,highestRate:u,marginalRate:g};return o.debug("createFromSellOrder info:",{order:m}),m}function p(e,t,r,a,i,c,s,n,d,l){o.debug("createOrders called",arguments);const g=h(e,t,s,n,d,l),u=y(e,t,r,a,i,c);return o.debug("createOrders info:",{order0:g,order1:u}),{order0:g,order1:u}}const S=1e6;function B(t,r){return new e.Decimal(t.toString()).mul(S).div(S-r).ceil()}function P(t,r){return new e.Decimal(t.toString()).mul(S-r).div(S).floor()}function w(e,t,r){return r.lte(e)?e:r.gte(t)?t:r}function D(t,r){return{minBuyPrice:n(e.lowestPossibleRate.toString(),t,r),maxSellPrice:d(e.lowestPossibleRate.toString(),r,t)}}function b(t,r,a,i){o.debug("calculateOverlappingPrices called",arguments);const c=new e.Decimal(i).div(100).plus(1),s=new e.Decimal(r).div(c),n=new e.Decimal(t).mul(c),d=w(new e.Decimal(t),s,new e.Decimal(a).div(c.sqrt())),l=w(n,new e.Decimal(r),new e.Decimal(a).mul(c.sqrt())),g={buyPriceHigh:s.toString(),buyPriceMarginal:d.toString(),sellPriceLow:n.toString(),sellPriceMarginal:l.toString(),buyPriceLow:t,sellPriceHigh:r,marketPrice:a};return o.debug("calculateOverlappingPrices info:",{prices:g}),g}function f(t,r,a,i,c,s,n){if(o.debug("calculateOverlappingSellBudget called",arguments),"0"===n)return"0";const{buyPriceHigh:d,sellPriceLow:l,sellPriceMarginal:g,buyPriceMarginal:u}=b(a,i,c,s);if(new e.Decimal(g).gte(i))return"0";if(new e.Decimal(u).lte(a))throw new Error("calculateOverlappingSellBudget called with zero buy range and non zero buy budget");const m=y(t,r,a,u,d,n),p=h(t,r,l,g,i,"0"),S=e.calculateRequiredLiquidity(m,p),B=e.formatUnits(S,t);return o.debug("calculateOverlappingSellBudget info:",{sellBudget:B}),B}function T(t,r,a,i,c,s,n){if(o.debug("calculateOverlappingBuyBudget called",arguments),"0"===n)return"0";const{sellPriceLow:d,buyPriceHigh:l,sellPriceMarginal:g,buyPriceMarginal:u}=b(a,i,c,s);if(new e.Decimal(u).lte(a))return"0";if(new e.Decimal(g).gte(i))throw new Error("calculateOverlappingBuyBudget called with zero sell range and non zero sell budget");const m=y(t,r,a,u,l,"0"),p=h(t,r,d,g,i,n),S=e.calculateRequiredLiquidity(p,m),B=e.formatUnits(S,r);return o.debug("calculateOverlappingBuyBudget info:",{buyBudget:B}),B}const M=new i.Logger("Toolkit.ts");var v;function O(e){return void 0!==e&&e!==exports.MarginalPriceOptions.reset&&e!==exports.MarginalPriceOptions.maintain}exports.MarginalPriceOptions=void 0,(v=exports.MarginalPriceOptions||(exports.MarginalPriceOptions={})).reset="RESET",v.maintain="MAINTAIN";class _{_api;_decimals;_cache;constructor(e,t,a){M.debug("SDK class constructor called with",arguments),this._api=e,this._cache=t;this._decimals=new r.Decimals((async e=>await(a?.(e))??await this._api.reader.getDecimalsByAddress(e)))}async getMinMaxPricesByAddresses(e,t){const r=this._decimals;return D(await r.fetchDecimals(e),await r.fetchDecimals(t))}static getMatchActions(e,r,a,i=t.MatchType.Fast,s){const o=c.ordersMapStrToBN(a);let n;return n=r?t.matchByTargetAmount(BigInt(e),o,[i],s):t.matchBySourceAmount(BigInt(e),o,[i],s),n[i]?.map(c.matchActionBNToStr)??[]}static getTradeDataFromActionsStatic({isTradeByTarget:t,actionsWei:r,sourceDecimals:a,targetDecimals:i,tradingFeePPM:c}){const s=[],o=[];let n,d,l,g=0n,u=0n;if(r.forEach((r=>{s.push({strategyId:r.id,amount:r.input}),t?o.push({id:r.id,sourceAmount:e.formatUnits(B(r.output,c).floor().toFixed(0),a),targetAmount:e.formatUnits(r.input,i)}):o.push({id:r.id,sourceAmount:e.formatUnits(r.input,a),targetAmount:e.formatUnits(P(r.output,c).floor().toFixed(0),i)}),u+=BigInt(r.input),g+=BigInt(r.output)})),t?(n=B(g,c).floor().toFixed(0),d=u.toString()):(n=u.toString(),d=P(g,c).floor().toFixed(0)),new e.Decimal(n).isZero()||new e.Decimal(d).isZero())l={tradeActions:s,actionsTokenRes:o,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:r};else{const t=new e.Decimal(d).div(n).times(e.tenPow(a,i)).toString();l={tradeActions:s,actionsTokenRes:o,totalSourceAmount:e.formatUnits(n,a),totalTargetAmount:e.formatUnits(d,i),effectiveRate:t,actionsWei:r}}return M.debug("getTradeDataFromActionsStatic info:",{sourceDecimals:a,targetDecimals:i,actionsWei:r,totalInput:u,totalOutput:g,tradingFeePPM:c,res:l}),l}static getTradeOrdersFromStrategies(e,t,r){const i={};for(const s of r){const r=c.encodedStrategyStrToBN(s);let o;if(e===r.token0&&t===r.token1)o=r.order1;else{if(e!==r.token1||t!==r.token0)continue;o=r.order0}a.isOrderTradable(o)&&(i[r.id.toString()]=o)}return c.ordersMapBNToStr(i)}static resolveTradeOrders(e){return"orders"in e?e.orders:_.getTradeOrdersFromStrategies(e.sourceToken,e.targetToken,e.strategies)}static hasLiquidityByPairStatic(e){const t=_.resolveTradeOrders(e);return Object.keys(t).length>0}static getLiquidityByPairStatic({targetDecimals:t,...r}){const a=c.ordersMapStrToBN(_.resolveTradeOrders(r)),i=Object.values(a).reduce(((e,{y:t})=>e+t),0n);return e.formatUnits(i,t)}static getMaxSourceAmountByPairStatic({sourceDecimals:r,...a}){const i=c.ordersMapStrToBN(_.resolveTradeOrders(a)),s=Object.values(i).reduce(((e,r)=>e+t.getEncodedTradeSourceAmount(r.y,r)),0n);return e.formatUnits(s,r)}static getMinRateByPairStatic({sourceDecimals:t,targetDecimals:r,...a}){const i=function(t){return t.reduce(((t,r)=>e.Decimal.min(t,r.lowestRate)),new e.Decimal(1/0))}(Object.values(c.ordersMapStrToBN(_.resolveTradeOrders(a))).map(e.decodeOrder)).toString();return n(i,t,r)}static getMaxRateByPairStatic({sourceDecimals:t,targetDecimals:r,...a}){const i=function(t){return t.reduce(((t,r)=>e.Decimal.max(t,r.marginalRate)),new e.Decimal(-1/0))}(Object.values(c.ordersMapStrToBN(_.resolveTradeOrders(a))).map(e.decodeOrder)).toString();return n(i,t,r)}static getRateLiquidityDepthsByPairStatic({rates:t,sourceDecimals:r,targetDecimals:a,...i}){return s(Object.values(c.ordersMapStrToBN(_.resolveTradeOrders(i))).map(e.decodeOrder),t.map((t=>new e.Decimal(n(t,a,r))))).map((e=>e.floor().toFixed(0))).map((t=>e.formatUnits(t,a)))}static getTradeDataStatic(r){M.debug("getTradeDataStatic called",arguments);const{amount:a,isTradeByTarget:i,sourceDecimals:c,targetDecimals:s,tradingFeePPM:o,matchType:n=t.MatchType.Fast,filter:d}=r,l=_.resolveTradeOrders(r),g=e.parseUnits(a,i?s:c).toString(),u=_.getMatchActions(g,i,l,n,d),m=_.getTradeDataFromActionsStatic({isTradeByTarget:i,actionsWei:u,sourceDecimals:c,targetDecimals:s,tradingFeePPM:o});return M.debug("getTradeDataStatic info:",{orders:l,amount:a,amountWei:g,sourceDecimals:c,targetDecimals:s,tradingFeePPM:o,res:m}),m}async hasLiquidityByPair(e,t){M.debug("hasLiquidityByPair called",arguments);const r=await this._cache.getOrdersByPair(e,t),a=_.hasLiquidityByPairStatic({orders:c.ordersMapBNToStr(r)});return M.debug("hasLiquidityByPair info:",{orders:r,hasLiquidity:a}),a}async getLiquidityByPair(e,t){M.debug("getLiquidityByPair called",arguments);const r=await this._cache.getOrdersByPair(e,t),a=await this._decimals.fetchDecimals(t),i=_.getLiquidityByPairStatic({orders:c.ordersMapBNToStr(r),targetDecimals:a});return M.debug("getLiquidityByPair info:",{orders:r,targetToken:t,decimals:a,liquidity:i}),i}async getMaxSourceAmountByPair(e,t){M.debug("getMaxSourceAmountByPair called",arguments);const r=await this._cache.getOrdersByPair(e,t),a=await this._decimals.fetchDecimals(e),i=_.getMaxSourceAmountByPairStatic({orders:c.ordersMapBNToStr(r),sourceDecimals:a});return M.debug("getMaxSourceAmountByPair info:",{orders:r,sourceToken:e,decimals:a,maxSourceAmount:i}),i}async getStrategyById(e){let t;M.debug("getStrategyById called",arguments),this._cache.isCacheInitialized()&&(t=this._cache.getStrategyById(e)),t?M.debug("getStrategyById fetched from cache"):(M.debug("getStrategyById fetching from chain"),t=await this._api.reader.strategy(BigInt(e)));const r=g(t),a=await u(r,this._decimals);return M.debug("getStrategyById info:",{id:e,encodedStrategy:t,decodedStrategy:r,strategy:a}),a}async getStrategiesByPair(e,t){let r;M.debug("getStrategiesByPair called",arguments),this._cache.isCacheInitialized()&&(r=await this._cache.getStrategiesByPair(e,t)),r?M.debug("getStrategiesByPair fetched from cache"):(M.debug("getStrategiesByPair fetching from chain"),r=await this._api.reader.strategiesByPair(e,t));const a=r.map(g),i=await Promise.all(a.map((async e=>await u(e,this._decimals))));return M.debug("getStrategiesByPair info:",{token0:e,token1:t,encodedStrategies:r,decodedStrategies:a,strategies:i}),i}async getStrategiesByPairs(e){M.debug("getStrategiesByPairs called",arguments);let t,r=e;r||(r=this._cache.isCacheInitialized()?this._cache.getCachedPairs():await this._api.reader.pairs()),this._cache.isCacheInitialized()?(t=await this._cache.getStrategiesByPairs(r),M.debug("getStrategiesByPairs fetched from cache")):(M.debug("getStrategiesByPairs fetching from chain"),t=await this._api.reader.strategiesByPairs(r));const a=t.map((({pair:e,strategies:t})=>({pair:e,strategies:t.map(g)}))),i=await Promise.all(a.map((async({pair:e,strategies:t})=>({pair:e,strategies:await Promise.all(t.map((async e=>await u(e,this._decimals))))}))));return M.debug("getStrategiesByPairs info:",{pairs:e,pairsToFetch:r,encodedStrategies:t,decodedStrategies:a,strategies:i}),i}async getUserStrategies(e){M.debug("getUserStrategies called",arguments);const t=await this._api.reader.tokensByOwner(e);let r=[],a=t;if(this._cache.isCacheInitialized()&&(a=t.reduce(((e,t)=>{const a=this._cache.getStrategyById(t);return a?r.push(a):e.push(t),e}),[])),a.length>0){const e=await this._api.reader.strategies(a);r=[...r,...e]}const i=r.map(g),c=await Promise.all(i.map((async e=>await u(e,this._decimals))));return M.debug("getUserStrategies info:",{ids:t,encodedStrategies:r,decodedStrategies:i,strategies:c}),c}async getMatchParams(t,r,a,i){M.debug("getMatchParams called",arguments);const s=this._decimals,o=await s.fetchDecimals(t),n=await s.fetchDecimals(r),d=await this._cache.getOrdersByPair(t,r),l=e.parseUnits(a,i?n:o);return{orders:c.ordersMapBNToStr(d),amountWei:l.toString(),sourceDecimals:o,targetDecimals:n}}async getTradeData(e,r,a,i,c=t.MatchType.Fast,s){M.debug("getTradeData called",arguments);const{orders:o,amountWei:n,sourceDecimals:d,targetDecimals:l}=await this.getMatchParams(e,r,a,i),g=await this._cache.getTradingFeePPMByPair(e,r);if(void 0===g)throw new Error(`tradingFeePPM is undefined for this pair: ${e}-${r}`);const u=_.getTradeDataStatic({amount:a,isTradeByTarget:i,orders:o,sourceDecimals:d,targetDecimals:l,tradingFeePPM:g,matchType:c,filter:s});return M.debug("getTradeData info:",{orders:o,amount:a,amountWei:n,res:u}),u}async getTradeDataFromActions(e,t,r,a){M.debug("getTradeDataFromActions called",arguments);const i=await this._cache.getTradingFeePPMByPair(e,t);if(void 0===i)throw new Error(`tradingFeePPM is undefined for this pair: ${e}-${t}`);const c=this._decimals,s=await c.fetchDecimals(e),o=await c.fetchDecimals(t),n=_.getTradeDataFromActionsStatic({isTradeByTarget:r,actionsWei:a,sourceDecimals:s,targetDecimals:o,tradingFeePPM:i});return M.debug("getTradeDataFromActions info:",{sourceToken:e,targetToken:t,isTradeByTarget:r,actionsWei:a,sourceDecimals:s,targetDecimals:o,tradingFeePPM:i,res:n}),n}async composeTradeByTargetTransaction(t,r,a,i,s,o){M.debug("composeTradeByTargetTransaction called",arguments);const n=await this._decimals.fetchDecimals(t);return this._api.composer.tradeByTargetAmount(t,r,a.map(c.tradeActionStrToBN),i,e.parseUnits(s,n),o)}async composeTradeBySourceTransaction(t,r,a,i,s,o){M.debug("composeTradeBySourceTransaction called",arguments);const n=await this._decimals.fetchDecimals(r);return this._api.composer.tradeBySourceAmount(t,r,a.map(c.tradeActionStrToBN),i,e.parseUnits(s,n),o)}async calculateOverlappingStrategySellBudget(e,t,r,a,i,c,s){M.debug("calculateOverlappingStrategySellBudget called",arguments);const o=this._decimals,n=await o.fetchDecimals(e),d=f(n,await o.fetchDecimals(t),r,a,i,c,s);return M.debug("calculateOverlappingStrategySellBudget info:",{baseDecimals:n,budget:d}),d}async calculateOverlappingStrategyBuyBudget(e,t,r,a,i,c,s){M.debug("calculateOverlappingStrategyBuyBudget called",arguments);const o=this._decimals,n=await o.fetchDecimals(e),d=await o.fetchDecimals(t),l=T(n,d,r,a,i,c,s);return M.debug("calculateOverlappingStrategyBuyBudget info:",{quoteDecimals:d,budget:l}),l}async createBuySellStrategy(e,t,r,a,i,c,s,o,n,d,g){M.debug("createBuySellStrategy called",arguments);const u=this._decimals,y=m(e,t,await u.fetchDecimals(e),await u.fetchDecimals(t),r,a,i,c,s,o,n,d),h=l(y);return M.debug("createBuySellStrategy info:",{strategy:y,encStrategy:h}),this._api.composer.createStrategy(h.token0,h.token1,h.order0,h.order1,g)}async batchCreateBuySellStrategies(e,t){M.debug("batchCreateBuySellStrategies called",arguments);const r=this._decimals,a=await Promise.all(e.map((async e=>{const t=await r.fetchDecimals(e.baseToken),a=await r.fetchDecimals(e.quoteToken),i=m(e.baseToken,e.quoteToken,t,a,e.buyPriceLow,e.buyPriceMarginal,e.buyPriceHigh,e.buyBudget,e.sellPriceLow,e.sellPriceMarginal,e.sellPriceHigh,e.sellBudget),c=l(i);return{token0:c.token0,token1:c.token1,order0:c.order0,order1:c.order1}})));return M.debug("batchCreateBuySellStrategies info:",{encStrategies:a}),this._api.composer.batchCreateStrategies(a,t)}async updateStrategy(t,r,{buyPriceLow:a,buyPriceHigh:i,buyBudget:s,sellPriceLow:o,sellPriceHigh:n,sellBudget:d},y,h,p){M.debug("updateStrategy called",arguments);const S=g(c.encodedStrategyStrToBN(r)),B=await u(S,this._decimals),P=this._decimals,w=await P.fetchDecimals(B.baseToken),D=await P.fetchDecimals(B.quoteToken),b=m(B.baseToken,B.quoteToken,w,D,a??B.buyPriceLow,O(y)?y:i??B.buyPriceHigh,i??B.buyPriceHigh,s??B.buyBudget,o??B.sellPriceLow,O(h)?h:o??B.sellPriceLow,n??B.sellPriceHigh,d??B.sellBudget),f=l(b),T=c.encodedStrategyStrToBN(r);return void 0===s&&void 0===a&&void 0===i&&void 0===y&&(f.order1.y=T.order1.y,f.order1.z=T.order1.z,f.order1.A=T.order1.A,f.order1.B=T.order1.B),void 0===d&&void 0===o&&void 0===n&&void 0===h&&(f.order0.y=T.order0.y,f.order0.z=T.order0.z,f.order0.A=T.order0.A,f.order0.B=T.order0.B),void 0===s&&(f.order1.y=T.order1.y),void 0===d&&(f.order0.y=T.order0.y),void 0===a&&void 0===i&&(f.order1.A=T.order1.A,f.order1.B=T.order1.B),void 0===o&&void 0===n&&(f.order0.A=T.order0.A,f.order0.B=T.order0.B),void 0!==s&&(O(y)||(y===exports.MarginalPriceOptions.maintain?0n===T.order1.y?f.order1.z=e.BigNumberMax(T.order1.z,f.order1.y):f.order1.z=e.mulDiv(T.order1.z,f.order1.y,T.order1.y):f.order1.z=f.order1.y)),void 0!==d&&(O(h)||(h===exports.MarginalPriceOptions.maintain?0n===T.order0.y?f.order0.z=e.BigNumberMax(T.order0.z,f.order0.y):f.order0.z=e.mulDiv(T.order0.z,f.order0.y,T.order0.y):f.order0.z=f.order0.y)),void 0===a&&void 0===i||y!==exports.MarginalPriceOptions.reset&&void 0!==y||(f.order1.z=f.order1.y),void 0===o&&void 0===n||h!==exports.MarginalPriceOptions.reset&&void 0!==h||(f.order0.z=f.order0.y),M.debug("updateStrategy info:",{baseDecimals:w,quoteDecimals:D,decodedOriginal:S,originalStrategy:B,newStrategy:b,newEncodedStrategy:f}),this._api.composer.updateStrategy(BigInt(t),f.token0,f.token1,[T.order0,T.order1],[f.order0,f.order1],p)}async deleteStrategy(e){return M.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(BigInt(e))}async getRateLiquidityDepthsByPair(e,t,r){M.debug("getRateLiquidityDepthByPair called",arguments);const a=await this._cache.getOrdersByPair(e,t),i=this._decimals,s=await i.fetchDecimals(e),o=await i.fetchDecimals(t),n=_.getRateLiquidityDepthsByPairStatic({rates:r,orders:c.ordersMapBNToStr(a),sourceDecimals:s,targetDecimals:o});return M.debug("getRateLiquidityDepthByPair info:",{orders:a,sourceDecimals:s,targetDecimals:o,depthsInTargetDecimals:n}),n}async getMinRateByPair(e,t){M.debug("getMinRateByPair called",arguments);const r=await this._cache.getOrdersByPair(e,t),a=this._decimals,i=await a.fetchDecimals(e),s=await a.fetchDecimals(t),o=_.getMinRateByPairStatic({orders:c.ordersMapBNToStr(r),sourceDecimals:i,targetDecimals:s});return M.debug("getMinRateByPair info:",{orders:r,sourceDecimals:i,targetDecimals:s,normalizedRate:o}),o}async getMaxRateByPair(e,t){M.debug("getMaxRateByPair called",arguments);const r=await this._cache.getOrdersByPair(e,t),a=this._decimals,i=await a.fetchDecimals(e),s=await a.fetchDecimals(t),o=_.getMaxRateByPairStatic({orders:c.ordersMapBNToStr(r),sourceDecimals:i,targetDecimals:s});return M.debug("getMaxRateByPair info:",{orders:r,sourceDecimals:i,targetDecimals:s,normalizedRate:o}),o}}var k=Object.freeze({__proto__:null,get MarginalPriceOptions(){return exports.MarginalPriceOptions},PPM_RESOLUTION:S,Toolkit:_,addFee:B,buildStrategyObject:m,calculateOverlappingBuyBudget:T,calculateOverlappingPrices:b,calculateOverlappingSellBudget:f,createFromBuyOrder:y,createFromSellOrder:h,createOrders:p,decodeStrategy:g,encodeStrategy:l,enforcePriceRange:w,getMinMaxPricesByDecimals:D,isMarginalPriceValue:O,normalizeInvertedRate:d,normalizeRate:n,parseStrategy:u,subtractFee:P});exports.PPM_RESOLUTION=S,exports.Toolkit=_,exports.addFee=B,exports.buildStrategyObject=m,exports.calculateOverlappingBuyBudget=T,exports.calculateOverlappingPrices=b,exports.calculateOverlappingSellBudget=f,exports.createFromBuyOrder=y,exports.createFromSellOrder=h,exports.createOrders=p,exports.decodeStrategy=g,exports.encodeStrategy=l,exports.enforcePriceRange=w,exports.getMinMaxPricesByDecimals=D,exports.index=k,exports.isMarginalPriceValue=O,exports.normalizeInvertedRate=d,exports.normalizeRate=n,exports.parseStrategy=u,exports.subtractFee=P;