New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bancor/carbon-sdk

Package Overview
Dependencies
Maintainers
0
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bancor/carbon-sdk - npm Package Compare versions

Comparing version 0.0.102-DEV to 0.0.103-DEV

dist/encoders-BAZgI6tQ.cjs

2

dist/strategy-management/stats/index.js

@@ -1,1 +0,1 @@

import"../../utils/numerics/index.js";import n from"decimal.js";function i(i){return i.reduce(((i,e)=>n.min(i,e.lowestRate)),new n(1/0))}function e(i){return i.reduce(((i,e)=>n.max(i,e.marginalRate)),new n(-1/0))}function t(i,e){const t=i.map((i=>{const e=new n(i.lowestRate).sqrt(),t=new n(i.marginalRate).sqrt();return{liq:new n(i.liquidity),min:e,mid:t,midMinusMin:t.sub(e)}}));return e.map((i=>{const e=i.sqrt();return t.reduce(((i,t)=>i.add(function(i,e){if(e.lte(i.min))return i.liq;if(e.gte(i.mid))return new n(0);return i.liq.sub(i.liq.mul(e.sub(i.min)).div(i.midMinusMin))}(t,e))),new n(0))}))}export{t as getDepths,e as getMaxRate,i as getMinRate};
import{Decimal as n}from"../../utils/numerics/index.js";function e(e){return e.reduce(((e,i)=>n.min(e,i.lowestRate)),new n(1/0))}function i(e){return e.reduce(((e,i)=>n.max(e,i.marginalRate)),new n(-1/0))}function t(e,i){const t=e.map((e=>{const i=new n(e.lowestRate).sqrt(),t=new n(e.marginalRate).sqrt();return{liq:new n(e.liquidity),min:i,mid:t,midMinusMin:t.sub(i)}}));return i.map((e=>{const i=e.sqrt();return t.reduce(((e,t)=>e.add(function(e,i){if(i.lte(e.min))return e.liq;if(i.gte(e.mid))return new n(0);return e.liq.sub(e.liq.mul(i.sub(e.min)).div(e.midMinusMin))}(t,i))),new n(0))}))}export{t as getDepths,i as getMaxRate,e as getMinRate};

@@ -1,1 +0,1 @@

import{formatUnits as e,parseUnits as t,tenPow as a,BigNumberMax as r,mulDiv as i}from"../../utils/numerics/index.js";import{MatchType as o}from"../../common/types/index.js";import{Decimals as s}from"../../utils/decimals/index.js";import{matchByTargetAmount as d,matchBySourceAmount as c}from"../../trade-matcher/match/index.js";import{getEncodedTradeSourceAmount as n}from"../../trade-matcher/trade/index.js";import{getDepths as g,getMinRate as l,getMaxRate as u}from"../stats/index.js";import{Logger as m}from"../../common/logger/index.js";import{decodeStrategy as y,parseStrategy as h,addFee as p,subtractFee as f,calculateOverlappingSellBudget as B,calculateOverlappingBuyBudget as S,buildStrategyObject as w,encodeStrategy as b,normalizeRate as P}from"../utils/index.js";import{decodeOrder as D}from"../../utils/encoders/index.js";import{ordersMapStrToBN as _,matchActionBNToStr as v,ordersMapBNToStr as A,tradeActionStrToBN as T,encodedStrategyStrToBN as x}from"../../utils/serializers/index.js";import{BigNumber as O}from"@ethersproject/bignumber";import z from"decimal.js";const j=new m("Toolkit.ts");var M;function R(e){return void 0!==e&&e!==M.reset&&e!==M.maintain}!function(e){e.reset="RESET",e.maintain="MAINTAIN"}(M||(M={}));class k{_api;_decimals;_cache;constructor(e,t,a){j.debug("SDK class constructor called with",arguments),this._api=e,this._cache=t;this._decimals=new s((async e=>await(a?.(e))??await this._api.reader.getDecimalsByAddress(e)))}static getMatchActions(e,t,a,r=o.Fast,i){const s=_(a);let n;return n=t?d(O.from(e),s,[r],i):c(O.from(e),s,[r],i),n[r]?.map(v)??[]}async hasLiquidityByPair(e,t){j.debug("hasLiquidityByPair called",arguments);const a=await this._cache.getOrdersByPair(e,t);return j.debug("hasLiquidityByPair info:",{orders:a}),Object.keys(a).length>0}async getLiquidityByPair(t,a){j.debug("getLiquidityByPair called",arguments);const r=await this._cache.getOrdersByPair(t,a),i=Object.values(r).reduce(((e,{y:t})=>e.add(t)),O.from(0)),o=await this._decimals.fetchDecimals(a),s=e(i,o);return j.debug("getLiquidityByPair info:",{orders:r,liquidityWei:i,targetToken:a,decimals:o,liquidity:s}),s}async getMaxSourceAmountByPair(t,a){j.debug("getMaxSourceAmountByPair called",arguments);const r=await this._cache.getOrdersByPair(t,a),i=Object.values(r).reduce(((e,t)=>e.add(n(t.y,t))),O.from(0)),o=await this._decimals.fetchDecimals(t),s=e(i,o);return j.debug("getMaxSourceAmountByPair info:",{orders:r,maxSourceAmountWei:i,sourceToken:t,decimals:o,maxSourceAmount:s}),s}async getStrategyById(e){let t;j.debug("getStrategyById called",arguments),this._cache&&(t=await this._cache.getStrategyById(e)),t?j.debug("getStrategyById fetched from cache"):(j.debug("getStrategyById fetching from chain"),t=await this._api.reader.strategy(O.from(e)));const a=y(t),r=await h(a,this._decimals);return j.debug("getStrategyById info:",{id:e,encodedStrategy:t,decodedStrategy:a,strategy:r}),r}async getStrategiesByPair(e,t){let a;j.debug("getStrategiesByPair called",arguments),this._cache&&(a=await this._cache.getStrategiesByPair(e,t)),a?j.debug("getStrategiesByPair fetched from cache"):(j.debug("getStrategiesByPair fetching from chain"),a=await this._api.reader.strategiesByPair(e,t));const r=a.map(y),i=await Promise.all(r.map((async e=>await h(e,this._decimals))));return j.debug("getStrategiesByPair info:",{token0:e,token1:t,encodedStrategies:a,decodedStrategies:r,strategies:i}),i}async getUserStrategies(e){j.debug("getUserStrategies called",arguments);const t=await this._api.reader.tokensByOwner(e);let a=[],r=t;if(this._cache&&(r=t.reduce(((e,t)=>{const r=this._cache.getStrategyById(t);return r?a.push(r):e.push(t),e}),[])),r.length>0){const e=await this._api.reader.strategies(r);a=[...a,...e]}const i=a.map(y),o=await Promise.all(i.map((async e=>await h(e,this._decimals))));return j.debug("getUserStrategies info:",{ids:t,encodedStrategies:a,decodedStrategies:i,strategies:o}),o}async getMatchParams(e,a,r,i){j.debug("getMatchParams called",arguments);const o=this._decimals,s=await o.fetchDecimals(e),d=await o.fetchDecimals(a),c=await this._cache.getOrdersByPair(e,a),n=t(r,i?d:s);return{orders:A(c),amountWei:n.toString(),sourceDecimals:s,targetDecimals:d}}async getTradeData(e,t,a,r,i=o.Fast,s){j.debug("getTradeData called",arguments);const{orders:d,amountWei:c}=await this.getMatchParams(e,t,a,r),n=k.getMatchActions(c,r,d,i,s),g=await this.getTradeDataFromActions(e,t,r,n);return j.debug("getTradeData info:",{orders:d,amount:a,amountWei:c,res:g}),g}async getTradeDataFromActions(t,r,i,o){j.debug("getTradeDataFromActions called",arguments);const s=await this._cache.getTradingFeePPMByPair(t,r);if(void 0===s)throw new Error(`tradingFeePPM is undefined for this pair: ${t}-${r}`);const d=this._decimals,c=await d.fetchDecimals(t),n=await d.fetchDecimals(r),g=[],l=[];let u,m,y,h=O.from(0),B=O.from(0);if(o.forEach((t=>{g.push({strategyId:t.id,amount:t.input}),i?l.push({id:t.id,sourceAmount:e(p(t.output,s).floor().toFixed(0),c),targetAmount:e(t.input,n)}):l.push({id:t.id,sourceAmount:e(t.input,c),targetAmount:e(f(t.output,s).floor().toFixed(0),n)}),B=B.add(t.input),h=h.add(t.output)})),i?(u=p(h,s).floor().toFixed(0),m=B.toString()):(u=B.toString(),m=f(h,s).floor().toFixed(0)),new z(u).isZero()||new z(m).isZero())y={tradeActions:g,actionsTokenRes:l,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:o};else{const t=new z(m).div(u).times(a(c,n)).toString();y={tradeActions:g,actionsTokenRes:l,totalSourceAmount:e(u,c),totalTargetAmount:e(m,n),effectiveRate:t,actionsWei:o}}return j.debug("getTradeDataFromActions info:",{sourceDecimals:c,targetDecimals:n,actionsWei:o,totalInput:B,totalOutput:h,tradingFeePPM:s,res:y}),y}async composeTradeByTargetTransaction(e,a,r,i,o,s){j.debug("composeTradeByTargetTransaction called",arguments);const d=await this._decimals.fetchDecimals(e);return this._api.composer.tradeByTargetAmount(e,a,r.map(T),i,t(o,d),s)}async composeTradeBySourceTransaction(e,a,r,i,o,s){j.debug("composeTradeBySourceTransaction called",arguments);const d=await this._decimals.fetchDecimals(a);return this._api.composer.tradeBySourceAmount(e,a,r.map(T),i,t(o,d),s)}async calculateOverlappingStrategySellBudget(e,t,a,r,i,o,s){j.debug("calculateOverlappingStrategySellBudget called",arguments);const d=this._decimals,c=await d.fetchDecimals(e),n=await d.fetchDecimals(t),g=B(c,n,a,r,i,o,s);return j.debug("calculateOverlappingStrategySellBudget info:",{baseDecimals:c,budget:g}),g}async calculateOverlappingStrategyBuyBudget(e,t,a,r,i,o,s){j.debug("calculateOverlappingStrategyBuyBudget called",arguments);const d=this._decimals,c=await d.fetchDecimals(e),n=await d.fetchDecimals(t),g=S(c,n,a,r,i,o,s);return j.debug("calculateOverlappingStrategyBuyBudget info:",{quoteDecimals:n,budget:g}),g}async createBuySellStrategy(e,t,a,r,i,o,s,d,c,n,g){j.debug("createBuySellStrategy called",arguments);const l=this._decimals,u=await l.fetchDecimals(e),m=await l.fetchDecimals(t),y=w(e,t,u,m,a,r,i,o,s,d,c,n),h=b(y);return j.debug("createBuySellStrategy info:",{strategy:y,encStrategy:h}),this._api.composer.createStrategy(h.token0,h.token1,h.order0,h.order1,g)}async updateStrategy(e,t,{buyPriceLow:a,buyPriceHigh:o,buyBudget:s,sellPriceLow:d,sellPriceHigh:c,sellBudget:n},g,l,u){j.debug("updateStrategy called",arguments);const m=y(x(t)),p=await h(m,this._decimals),f=this._decimals,B=await f.fetchDecimals(p.baseToken),S=await f.fetchDecimals(p.quoteToken),P=w(p.baseToken,p.quoteToken,B,S,a??p.buyPriceLow,R(g)?g:o??p.buyPriceHigh,o??p.buyPriceHigh,s??p.buyBudget,d??p.sellPriceLow,R(l)?l:d??p.sellPriceLow,c??p.sellPriceHigh,n??p.sellBudget),D=b(P),_=x(t);return void 0===s&&void 0===a&&void 0===o&&void 0===g&&(D.order1.y=_.order1.y,D.order1.z=_.order1.z,D.order1.A=_.order1.A,D.order1.B=_.order1.B),void 0===n&&void 0===d&&void 0===c&&void 0===l&&(D.order0.y=_.order0.y,D.order0.z=_.order0.z,D.order0.A=_.order0.A,D.order0.B=_.order0.B),void 0===s&&(D.order1.y=_.order1.y),void 0===n&&(D.order0.y=_.order0.y),void 0===a&&void 0===o&&(D.order1.A=_.order1.A,D.order1.B=_.order1.B),void 0===d&&void 0===c&&(D.order0.A=_.order0.A,D.order0.B=_.order0.B),void 0!==s&&(R(g)||(g===M.maintain?_.order1.y.isZero()?D.order1.z=r(_.order1.z,D.order1.y):D.order1.z=i(_.order1.z,D.order1.y,_.order1.y):D.order1.z=D.order1.y)),void 0!==n&&(R(l)||(l===M.maintain?_.order0.y.isZero()?D.order0.z=r(_.order0.z,D.order0.y):D.order0.z=i(_.order0.z,D.order0.y,_.order0.y):D.order0.z=D.order0.y)),void 0===a&&void 0===o||g!==M.reset&&void 0!==g||(D.order1.z=D.order1.y),void 0===d&&void 0===c||l!==M.reset&&void 0!==l||(D.order0.z=D.order0.y),j.debug("updateStrategy info:",{baseDecimals:B,quoteDecimals:S,decodedOriginal:m,originalStrategy:p,newStrategy:P,newEncodedStrategy:D}),this._api.composer.updateStrategy(O.from(e),D.token0,D.token1,[_.order0,_.order1],[D.order0,D.order1],u)}async deleteStrategy(e){return j.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(O.from(e))}async getRateLiquidityDepthsByPair(t,a,r){j.debug("getRateLiquidityDepthByPair called",arguments);const i=Object.values(await this._cache.getOrdersByPair(t,a)).map(D),o=this._decimals,s=await o.fetchDecimals(t),d=await o.fetchDecimals(a),c=r.map((e=>new z(P(e,d,s)))),n=g(i,c).map((e=>e.floor().toFixed(0))),l=n.map((t=>e(t,d)));return j.debug("getRateLiquidityDepthByPair info:",{orders:i,depthsWei:n,targetDecimals:d,depthsInTargetDecimals:l}),l}async getMinRateByPair(e,t){j.debug("getMinRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(D),r=l(a).toString(),i=this._decimals,o=await i.fetchDecimals(e),s=await i.fetchDecimals(t),d=P(r,o,s);return j.debug("getMinRateByPair info:",{orders:a,minRate:r,sourceDecimals:o,targetDecimals:s,normalizedRate:d}),d}async getMaxRateByPair(e,t){j.debug("getMaxRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(D),r=u(a).toString(),i=this._decimals,o=await i.fetchDecimals(e),s=await i.fetchDecimals(t),d=P(r,o,s);return j.debug("getMaxRateByPair info:",{orders:a,maxRate:r,sourceDecimals:o,targetDecimals:s,normalizedRate:d}),d}}export{M as MarginalPriceOptions,k as Toolkit,R as isMarginalPriceValue};
import{formatUnits as e,parseUnits as t,Decimal as a,tenPow as r,BigNumberMax as i,mulDiv as o}from"../../utils/numerics/index.js";import{MatchType as s}from"../../common/types/index.js";import{Decimals as d}from"../../utils/decimals/index.js";import{matchByTargetAmount as c,matchBySourceAmount as n}from"../../trade-matcher/match/index.js";import{getEncodedTradeSourceAmount as g}from"../../trade-matcher/trade/index.js";import{getDepths as l,getMinRate as u,getMaxRate as m}from"../stats/index.js";import{Logger as y}from"../../common/logger/index.js";import{decodeStrategy as h,parseStrategy as p,addFee as f,subtractFee as B,calculateOverlappingSellBudget as S,calculateOverlappingBuyBudget as w,buildStrategyObject as b,encodeStrategy as P,normalizeRate as D}from"../utils/index.js";import{decodeOrder as _}from"../../utils/encoders/index.js";import{ordersMapStrToBN as v,matchActionBNToStr as A,ordersMapBNToStr as T,tradeActionStrToBN as x,encodedStrategyStrToBN as O}from"../../utils/serializers/index.js";import{BigNumber as z}from"@ethersproject/bignumber";const M=new y("Toolkit.ts");var R;function j(e){return void 0!==e&&e!==R.reset&&e!==R.maintain}!function(e){e.reset="RESET",e.maintain="MAINTAIN"}(R||(R={}));class k{_api;_decimals;_cache;constructor(e,t,a){M.debug("SDK class constructor called with",arguments),this._api=e,this._cache=t;this._decimals=new d((async e=>await(a?.(e))??await this._api.reader.getDecimalsByAddress(e)))}static getMatchActions(e,t,a,r=s.Fast,i){const o=v(a);let d;return d=t?c(z.from(e),o,[r],i):n(z.from(e),o,[r],i),d[r]?.map(A)??[]}async hasLiquidityByPair(e,t){M.debug("hasLiquidityByPair called",arguments);const a=await this._cache.getOrdersByPair(e,t);return M.debug("hasLiquidityByPair info:",{orders:a}),Object.keys(a).length>0}async getLiquidityByPair(t,a){M.debug("getLiquidityByPair called",arguments);const r=await this._cache.getOrdersByPair(t,a),i=Object.values(r).reduce(((e,{y:t})=>e.add(t)),z.from(0)),o=await this._decimals.fetchDecimals(a),s=e(i,o);return M.debug("getLiquidityByPair info:",{orders:r,liquidityWei:i,targetToken:a,decimals:o,liquidity:s}),s}async getMaxSourceAmountByPair(t,a){M.debug("getMaxSourceAmountByPair called",arguments);const r=await this._cache.getOrdersByPair(t,a),i=Object.values(r).reduce(((e,t)=>e.add(g(t.y,t))),z.from(0)),o=await this._decimals.fetchDecimals(t),s=e(i,o);return M.debug("getMaxSourceAmountByPair info:",{orders:r,maxSourceAmountWei:i,sourceToken:t,decimals:o,maxSourceAmount:s}),s}async getStrategyById(e){let t;M.debug("getStrategyById called",arguments),this._cache&&(t=await this._cache.getStrategyById(e)),t?M.debug("getStrategyById fetched from cache"):(M.debug("getStrategyById fetching from chain"),t=await this._api.reader.strategy(z.from(e)));const a=h(t),r=await p(a,this._decimals);return M.debug("getStrategyById info:",{id:e,encodedStrategy:t,decodedStrategy:a,strategy:r}),r}async getStrategiesByPair(e,t){let a;M.debug("getStrategiesByPair called",arguments),this._cache&&(a=await this._cache.getStrategiesByPair(e,t)),a?M.debug("getStrategiesByPair fetched from cache"):(M.debug("getStrategiesByPair fetching from chain"),a=await this._api.reader.strategiesByPair(e,t));const r=a.map(h),i=await Promise.all(r.map((async e=>await p(e,this._decimals))));return M.debug("getStrategiesByPair info:",{token0:e,token1:t,encodedStrategies:a,decodedStrategies:r,strategies:i}),i}async getUserStrategies(e){M.debug("getUserStrategies called",arguments);const t=await this._api.reader.tokensByOwner(e);let a=[],r=t;if(this._cache&&(r=t.reduce(((e,t)=>{const r=this._cache.getStrategyById(t);return r?a.push(r):e.push(t),e}),[])),r.length>0){const e=await this._api.reader.strategies(r);a=[...a,...e]}const i=a.map(h),o=await Promise.all(i.map((async e=>await p(e,this._decimals))));return M.debug("getUserStrategies info:",{ids:t,encodedStrategies:a,decodedStrategies:i,strategies:o}),o}async getMatchParams(e,a,r,i){M.debug("getMatchParams called",arguments);const o=this._decimals,s=await o.fetchDecimals(e),d=await o.fetchDecimals(a),c=await this._cache.getOrdersByPair(e,a),n=t(r,i?d:s);return{orders:T(c),amountWei:n.toString(),sourceDecimals:s,targetDecimals:d}}async getTradeData(e,t,a,r,i=s.Fast,o){M.debug("getTradeData called",arguments);const{orders:d,amountWei:c}=await this.getMatchParams(e,t,a,r),n=k.getMatchActions(c,r,d,i,o),g=await this.getTradeDataFromActions(e,t,r,n);return M.debug("getTradeData info:",{orders:d,amount:a,amountWei:c,res:g}),g}async getTradeDataFromActions(t,i,o,s){M.debug("getTradeDataFromActions called",arguments);const d=await this._cache.getTradingFeePPMByPair(t,i);if(void 0===d)throw new Error(`tradingFeePPM is undefined for this pair: ${t}-${i}`);const c=this._decimals,n=await c.fetchDecimals(t),g=await c.fetchDecimals(i),l=[],u=[];let m,y,h,p=z.from(0),S=z.from(0);if(s.forEach((t=>{l.push({strategyId:t.id,amount:t.input}),o?u.push({id:t.id,sourceAmount:e(f(t.output,d).floor().toFixed(0),n),targetAmount:e(t.input,g)}):u.push({id:t.id,sourceAmount:e(t.input,n),targetAmount:e(B(t.output,d).floor().toFixed(0),g)}),S=S.add(t.input),p=p.add(t.output)})),o?(m=f(p,d).floor().toFixed(0),y=S.toString()):(m=S.toString(),y=B(p,d).floor().toFixed(0)),new a(m).isZero()||new a(y).isZero())h={tradeActions:l,actionsTokenRes:u,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:s};else{const t=new a(y).div(m).times(r(n,g)).toString();h={tradeActions:l,actionsTokenRes:u,totalSourceAmount:e(m,n),totalTargetAmount:e(y,g),effectiveRate:t,actionsWei:s}}return M.debug("getTradeDataFromActions info:",{sourceDecimals:n,targetDecimals:g,actionsWei:s,totalInput:S,totalOutput:p,tradingFeePPM:d,res:h}),h}async composeTradeByTargetTransaction(e,a,r,i,o,s){M.debug("composeTradeByTargetTransaction called",arguments);const d=await this._decimals.fetchDecimals(e);return this._api.composer.tradeByTargetAmount(e,a,r.map(x),i,t(o,d),s)}async composeTradeBySourceTransaction(e,a,r,i,o,s){M.debug("composeTradeBySourceTransaction called",arguments);const d=await this._decimals.fetchDecimals(a);return this._api.composer.tradeBySourceAmount(e,a,r.map(x),i,t(o,d),s)}async calculateOverlappingStrategySellBudget(e,t,a,r,i,o,s){M.debug("calculateOverlappingStrategySellBudget called",arguments);const d=this._decimals,c=await d.fetchDecimals(e),n=await d.fetchDecimals(t),g=S(c,n,a,r,i,o,s);return M.debug("calculateOverlappingStrategySellBudget info:",{baseDecimals:c,budget:g}),g}async calculateOverlappingStrategyBuyBudget(e,t,a,r,i,o,s){M.debug("calculateOverlappingStrategyBuyBudget called",arguments);const d=this._decimals,c=await d.fetchDecimals(e),n=await d.fetchDecimals(t),g=w(c,n,a,r,i,o,s);return M.debug("calculateOverlappingStrategyBuyBudget info:",{quoteDecimals:n,budget:g}),g}async createBuySellStrategy(e,t,a,r,i,o,s,d,c,n,g){M.debug("createBuySellStrategy called",arguments);const l=this._decimals,u=await l.fetchDecimals(e),m=await l.fetchDecimals(t),y=b(e,t,u,m,a,r,i,o,s,d,c,n),h=P(y);return M.debug("createBuySellStrategy info:",{strategy:y,encStrategy:h}),this._api.composer.createStrategy(h.token0,h.token1,h.order0,h.order1,g)}async updateStrategy(e,t,{buyPriceLow:a,buyPriceHigh:r,buyBudget:s,sellPriceLow:d,sellPriceHigh:c,sellBudget:n},g,l,u){M.debug("updateStrategy called",arguments);const m=h(O(t)),y=await p(m,this._decimals),f=this._decimals,B=await f.fetchDecimals(y.baseToken),S=await f.fetchDecimals(y.quoteToken),w=b(y.baseToken,y.quoteToken,B,S,a??y.buyPriceLow,j(g)?g:r??y.buyPriceHigh,r??y.buyPriceHigh,s??y.buyBudget,d??y.sellPriceLow,j(l)?l:d??y.sellPriceLow,c??y.sellPriceHigh,n??y.sellBudget),D=P(w),_=O(t);return void 0===s&&void 0===a&&void 0===r&&void 0===g&&(D.order1.y=_.order1.y,D.order1.z=_.order1.z,D.order1.A=_.order1.A,D.order1.B=_.order1.B),void 0===n&&void 0===d&&void 0===c&&void 0===l&&(D.order0.y=_.order0.y,D.order0.z=_.order0.z,D.order0.A=_.order0.A,D.order0.B=_.order0.B),void 0===s&&(D.order1.y=_.order1.y),void 0===n&&(D.order0.y=_.order0.y),void 0===a&&void 0===r&&(D.order1.A=_.order1.A,D.order1.B=_.order1.B),void 0===d&&void 0===c&&(D.order0.A=_.order0.A,D.order0.B=_.order0.B),void 0!==s&&(j(g)||(g===R.maintain?_.order1.y.isZero()?D.order1.z=i(_.order1.z,D.order1.y):D.order1.z=o(_.order1.z,D.order1.y,_.order1.y):D.order1.z=D.order1.y)),void 0!==n&&(j(l)||(l===R.maintain?_.order0.y.isZero()?D.order0.z=i(_.order0.z,D.order0.y):D.order0.z=o(_.order0.z,D.order0.y,_.order0.y):D.order0.z=D.order0.y)),void 0===a&&void 0===r||g!==R.reset&&void 0!==g||(D.order1.z=D.order1.y),void 0===d&&void 0===c||l!==R.reset&&void 0!==l||(D.order0.z=D.order0.y),M.debug("updateStrategy info:",{baseDecimals:B,quoteDecimals:S,decodedOriginal:m,originalStrategy:y,newStrategy:w,newEncodedStrategy:D}),this._api.composer.updateStrategy(z.from(e),D.token0,D.token1,[_.order0,_.order1],[D.order0,D.order1],u)}async deleteStrategy(e){return M.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(z.from(e))}async getRateLiquidityDepthsByPair(t,r,i){M.debug("getRateLiquidityDepthByPair called",arguments);const o=Object.values(await this._cache.getOrdersByPair(t,r)).map(_),s=this._decimals,d=await s.fetchDecimals(t),c=await s.fetchDecimals(r),n=i.map((e=>new a(D(e,c,d)))),g=l(o,n).map((e=>e.floor().toFixed(0))),u=g.map((t=>e(t,c)));return M.debug("getRateLiquidityDepthByPair info:",{orders:o,depthsWei:g,targetDecimals:c,depthsInTargetDecimals:u}),u}async getMinRateByPair(e,t){M.debug("getMinRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(_),r=u(a).toString(),i=this._decimals,o=await i.fetchDecimals(e),s=await i.fetchDecimals(t),d=D(r,o,s);return M.debug("getMinRateByPair info:",{orders:a,minRate:r,sourceDecimals:o,targetDecimals:s,normalizedRate:d}),d}async getMaxRateByPair(e,t){M.debug("getMaxRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(_),r=m(a).toString(),i=this._decimals,o=await i.fetchDecimals(e),s=await i.fetchDecimals(t),d=D(r,o,s);return M.debug("getMaxRateByPair info:",{orders:a,maxRate:r,sourceDecimals:o,targetDecimals:s,normalizedRate:d}),d}}export{R as MarginalPriceOptions,k as Toolkit,j as isMarginalPriceValue};

@@ -39,3 +39,3 @@ import { BigNumber, BigNumberish, Decimal } from '../utils/numerics';

export declare function subtractFee(amount: BigNumberish, tradingFeePPM: number): Decimal;
export declare function enforcePriceRange(minPrice: Decimal, maxPrice: Decimal, marginalPrice: Decimal): Decimal;
export declare function enforcePriceRange(minPrice: Decimal, maxPrice: Decimal, marginalPrice: Decimal): import("decimal.js").default;
/**

@@ -42,0 +42,0 @@ * Calculate the overlapping strategy prices. Returns it with correct decimals

@@ -1,1 +0,1 @@

import{tenPow as e,formatUnits as r,parseUnits as t}from"../../utils/numerics/index.js";import{Logger as i}from"../../common/logger/index.js";import{encodeOrders as n,decodeOrder as o,calculateRequiredLiquidity as l}from"../../utils/encoders/index.js";import{encodedStrategyBNToStr as a}from"../../utils/serializers/index.js";import u from"decimal.js";const c=new i("utils.ts");function d(r,t,i){return new u(r.toString()).times(e(t,i)).toFixed()}function g(r,t,i){return 0==+r.toString()?"0":new u(1).div(r.toString()).times(e(i,t)).toFixed()}const s=e=>{const[r,t]=n([e.order0,e.order1]);return{token0:e.token0,token1:e.token1,order0:r,order1:t}},w=e=>({id:e.id,token0:e.token0,token1:e.token1,order0:o(e.order0),order1:o(e.order1),encoded:e});async function b(e,t){c.debug("parseStrategy called",arguments);const{id:i,token0:n,token1:o,order0:l,order1:u,encoded:s}=e,w=await t.fetchDecimals(n),b=await t.fetchDecimals(o),f=d(u.lowestRate,w,b),m=d(u.marginalRate,w,b),y=d(u.highestRate,w,b),p=g(l.highestRate,b,w),P=g(l.marginalRate,b,w),h=g(l.lowestRate,b,w),v=r(l.liquidity,w),k=r(u.liquidity,b),S=i.toString(),B=a(s);return c.debug("parseStrategy info:",{id:S,token0:n,token1:o,order0:l,order1:u,decimals0:w,decimals1:b,baseToken:n,quoteToken:o,buyPriceLow:f,buyPriceMarginal:m,buyPriceHigh:y,buyBudget:k,sellPriceLow:p,sellPriceMarginal:P,sellPriceHigh:h,sellBudget:v,encoded:B}),{id:S,baseToken:n,quoteToken:o,buyPriceLow:f,buyPriceMarginal:m,buyPriceHigh:y,buyBudget:k,sellPriceLow:p,sellPriceMarginal:P,sellPriceHigh:h,sellBudget:v,encoded:B}}function f(e,r,t,i,n,o,l,a,d,g,s,w){if(c.debug("buildStrategyObject called",arguments),new u(n).isNegative()||new u(o).isNegative()||new u(l).isNegative()||new u(d).isNegative()||new u(g).isNegative()||new u(s).isNegative())throw new Error("prices cannot be negative");if(new u(n).gt(o)||new u(n).gt(l)||new u(o).gt(l)||new u(d).gt(g)||new u(d).gt(s)||new u(g).gt(s))throw new Error("low/marginal price must be lower than or equal to marginal/high price");if(new u(a).isNegative()||new u(w).isNegative())throw new Error("budgets cannot be negative");const{order0:b,order1:f}=p(t,i,n,o,l,a,d,g,s,w);return c.debug("buildStrategyObject info:",{token0:e,token1:r,order0:b,order1:f}),{token0:e,token1:r,order0:b,order1:f}}function m(e,r,i,n,o,l){c.debug("createFromBuyOrder called",arguments);const a=t(l,r),u=d(i,r,e),g=d(n,r,e),s=d(o,r,e),w={liquidity:a.toString(),lowestRate:u,highestRate:s,marginalRate:g};return c.debug("createFromBuyOrder info:",{order:w}),w}function y(e,r,i,n,o,l){c.debug("createFromSellOrder called",arguments);const a=t(l,e),u=g(o,r,e),d=g(n,r,e),s=g(i,r,e),w={liquidity:a.toString(),lowestRate:u,highestRate:s,marginalRate:d};return c.debug("createFromSellOrder info:",{order:w}),w}function p(e,r,t,i,n,o,l,a,u,d){c.debug("createOrders called",arguments);const g=y(e,r,l,a,u,d),s=m(e,r,t,i,n,o);return c.debug("createOrders info:",{order0:g,order1:s}),{order0:g,order1:s}}const P=1e6;function h(e,r){return new u(e.toString()).mul(P).div(P-r).ceil()}function v(e,r){return new u(e.toString()).mul(P-r).div(P).floor()}function k(e,r,t){return t.lte(e)?e:t.gte(r)?r:t}function S(e,r,t,i){c.debug("calculateOverlappingPrices called",arguments);const n=new u(i).div(100).plus(1),o=new u(r).div(n),l=new u(e).mul(n),a=k(new u(e),o,new u(t).div(n.sqrt())),d=k(l,new u(r),new u(t).mul(n.sqrt())),g={buyPriceHigh:o.toString(),buyPriceMarginal:a.toString(),sellPriceLow:l.toString(),sellPriceMarginal:d.toString(),buyPriceLow:e,sellPriceHigh:r,marketPrice:t};return c.debug("calculateOverlappingPrices info:",{prices:g}),g}function B(e,t,i,n,o,a,d){if(c.debug("calculateOverlappingSellBudget called",arguments),"0"===d)return"0";const{buyPriceHigh:g,sellPriceLow:s,sellPriceMarginal:w,buyPriceMarginal:b}=S(i,n,o,a);if(new u(w).gte(n))return"0";if(new u(b).lte(i))throw new Error("calculateOverlappingSellBudget called with zero buy range and non zero buy budget");const f=m(e,t,i,b,g,d),p=y(e,t,s,w,n,"0"),P=l(f,p),h=r(P,e);return c.debug("calculateOverlappingSellBudget info:",{sellBudget:h}),h}function O(e,t,i,n,o,a,d){if(c.debug("calculateOverlappingBuyBudget called",arguments),"0"===d)return"0";const{sellPriceLow:g,buyPriceHigh:s,sellPriceMarginal:w,buyPriceMarginal:b}=S(i,n,o,a);if(new u(b).lte(i))return"0";if(new u(w).gte(n))throw new Error("calculateOverlappingBuyBudget called with zero sell range and non zero sell budget");const f=m(e,t,i,b,s,"0"),p=y(e,t,g,w,n,d),P=l(p,f),h=r(P,t);return c.debug("calculateOverlappingBuyBudget info:",{buyBudget:h}),h}export{P as PPM_RESOLUTION,h as addFee,f as buildStrategyObject,O as calculateOverlappingBuyBudget,S as calculateOverlappingPrices,B as calculateOverlappingSellBudget,m as createFromBuyOrder,y as createFromSellOrder,p as createOrders,w as decodeStrategy,s as encodeStrategy,k as enforcePriceRange,g as normalizeInvertedRate,d as normalizeRate,b as parseStrategy,v as subtractFee};
import{Decimal as e,tenPow as r,formatUnits as t,parseUnits as n}from"../../utils/numerics/index.js";import{Logger as i}from"../../common/logger/index.js";import{encodeOrders as o,decodeOrder as l,calculateRequiredLiquidity as a}from"../../utils/encoders/index.js";import{encodedStrategyBNToStr as u}from"../../utils/serializers/index.js";const c=new i("utils.ts");function d(t,n,i){return new e(t.toString()).times(r(n,i)).toFixed()}function g(t,n,i){return 0==+t.toString()?"0":new e(1).div(t.toString()).times(r(i,n)).toFixed()}const s=e=>{const[r,t]=o([e.order0,e.order1]);return{token0:e.token0,token1:e.token1,order0:r,order1:t}},w=e=>({id:e.id,token0:e.token0,token1:e.token1,order0:l(e.order0),order1:l(e.order1),encoded:e});async function b(e,r){c.debug("parseStrategy called",arguments);const{id:n,token0:i,token1:o,order0:l,order1:a,encoded:s}=e,w=await r.fetchDecimals(i),b=await r.fetchDecimals(o),f=d(a.lowestRate,w,b),m=d(a.marginalRate,w,b),y=d(a.highestRate,w,b),P=g(l.highestRate,b,w),h=g(l.marginalRate,b,w),p=g(l.lowestRate,b,w),v=t(l.liquidity,w),k=t(a.liquidity,b),S=n.toString(),B=u(s);return c.debug("parseStrategy info:",{id:S,token0:i,token1:o,order0:l,order1:a,decimals0:w,decimals1:b,baseToken:i,quoteToken:o,buyPriceLow:f,buyPriceMarginal:m,buyPriceHigh:y,buyBudget:k,sellPriceLow:P,sellPriceMarginal:h,sellPriceHigh:p,sellBudget:v,encoded:B}),{id:S,baseToken:i,quoteToken:o,buyPriceLow:f,buyPriceMarginal:m,buyPriceHigh:y,buyBudget:k,sellPriceLow:P,sellPriceMarginal:h,sellPriceHigh:p,sellBudget:v,encoded:B}}function f(r,t,n,i,o,l,a,u,d,g,s,w){if(c.debug("buildStrategyObject called",arguments),new e(o).isNegative()||new e(l).isNegative()||new e(a).isNegative()||new e(d).isNegative()||new e(g).isNegative()||new e(s).isNegative())throw new Error("prices cannot be negative");if(new e(o).gt(l)||new e(o).gt(a)||new e(l).gt(a)||new e(d).gt(g)||new e(d).gt(s)||new e(g).gt(s))throw new Error("low/marginal price must be lower than or equal to marginal/high price");if(new e(u).isNegative()||new e(w).isNegative())throw new Error("budgets cannot be negative");const{order0:b,order1:f}=P(n,i,o,l,a,u,d,g,s,w);return c.debug("buildStrategyObject info:",{token0:r,token1:t,order0:b,order1:f}),{token0:r,token1:t,order0:b,order1:f}}function m(e,r,t,i,o,l){c.debug("createFromBuyOrder called",arguments);const a=n(l,r),u=d(t,r,e),g=d(i,r,e),s=d(o,r,e),w={liquidity:a.toString(),lowestRate:u,highestRate:s,marginalRate:g};return c.debug("createFromBuyOrder info:",{order:w}),w}function y(e,r,t,i,o,l){c.debug("createFromSellOrder called",arguments);const a=n(l,e),u=g(o,r,e),d=g(i,r,e),s=g(t,r,e),w={liquidity:a.toString(),lowestRate:u,highestRate:s,marginalRate:d};return c.debug("createFromSellOrder info:",{order:w}),w}function P(e,r,t,n,i,o,l,a,u,d){c.debug("createOrders called",arguments);const g=y(e,r,l,a,u,d),s=m(e,r,t,n,i,o);return c.debug("createOrders info:",{order0:g,order1:s}),{order0:g,order1:s}}const h=1e6;function p(r,t){return new e(r.toString()).mul(h).div(h-t).ceil()}function v(r,t){return new e(r.toString()).mul(h-t).div(h).floor()}function k(e,r,t){return t.lte(e)?e:t.gte(r)?r:t}function S(r,t,n,i){c.debug("calculateOverlappingPrices called",arguments);const o=new e(i).div(100).plus(1),l=new e(t).div(o),a=new e(r).mul(o),u=k(new e(r),l,new e(n).div(o.sqrt())),d=k(a,new e(t),new e(n).mul(o.sqrt())),g={buyPriceHigh:l.toString(),buyPriceMarginal:u.toString(),sellPriceLow:a.toString(),sellPriceMarginal:d.toString(),buyPriceLow:r,sellPriceHigh:t,marketPrice:n};return c.debug("calculateOverlappingPrices info:",{prices:g}),g}function B(r,n,i,o,l,u,d){if(c.debug("calculateOverlappingSellBudget called",arguments),"0"===d)return"0";const{buyPriceHigh:g,sellPriceLow:s,sellPriceMarginal:w,buyPriceMarginal:b}=S(i,o,l,u);if(new e(w).gte(o))return"0";if(new e(b).lte(i))throw new Error("calculateOverlappingSellBudget called with zero buy range and non zero buy budget");const f=m(r,n,i,b,g,d),P=y(r,n,s,w,o,"0"),h=a(f,P),p=t(h,r);return c.debug("calculateOverlappingSellBudget info:",{sellBudget:p}),p}function O(r,n,i,o,l,u,d){if(c.debug("calculateOverlappingBuyBudget called",arguments),"0"===d)return"0";const{sellPriceLow:g,buyPriceHigh:s,sellPriceMarginal:w,buyPriceMarginal:b}=S(i,o,l,u);if(new e(b).lte(i))return"0";if(new e(w).gte(o))throw new Error("calculateOverlappingBuyBudget called with zero sell range and non zero sell budget");const f=m(r,n,i,b,s,"0"),P=y(r,n,g,w,o,d),h=a(P,f),p=t(h,n);return c.debug("calculateOverlappingBuyBudget info:",{buyBudget:p}),p}export{h as PPM_RESOLUTION,p as addFee,f as buildStrategyObject,O as calculateOverlappingBuyBudget,S as calculateOverlappingPrices,B as calculateOverlappingSellBudget,m as createFromBuyOrder,y as createFromSellOrder,P as createOrders,w as decodeStrategy,s as encodeStrategy,k as enforcePriceRange,g as normalizeInvertedRate,d as normalizeRate,b as parseStrategy,v as subtractFee};
import { BigNumber, Decimal } from './numerics';
import { DecodedOrder, EncodedOrder } from '../common/types';
export declare const encodeRate: (value: Decimal) => BigNumber;
export declare const decodeRate: (value: Decimal) => Decimal;
export declare const decodeRate: (value: Decimal) => import("decimal.js").default;
export declare const encodeFloat: (value: BigNumber) => BigNumber;

@@ -6,0 +6,0 @@ export declare const decodeFloat: (value: BigNumber) => BigNumber;

@@ -1,1 +0,1 @@

import{DecToBn as t,ONE as e,BnToDec as r}from"../numerics/index.js";import{BigNumber as i}from"@ethersproject/bignumber";import n from"decimal.js";function o(t){return t.gt(0)?n.log2(t.toString()).add(1).floor().toNumber():0}const a=r=>{const i=t(r.sqrt().mul(e).floor()),n=o(i.div(e));return i.shr(n).shl(n)},s=t=>t.div(e).pow(2),l=t=>{const r=o(t.div(e)),n=t.shr(r);return i.from(e).mul(r).or(n)},g=t=>t.mod(e).shl(t.div(e).toNumber()),u=([t,e])=>{const r=new n(t.liquidity),i=new n(t.lowestRate),o=new n(t.highestRate),a=new n(e.liquidity),s=new n(e.lowestRate),l=new n(e.highestRate);return r.eq(0)&&a.gt(0)&&s.gt(0)&&l.gt(0)?[d(t,q(e)),d(e)]:a.eq(0)&&r.gt(0)&&i.gt(0)&&o.gt(0)?[d(t),d(e,q(t))]:[d(t),d(e)]},w=t=>{try{return d(t),!0}catch(t){return!1}},h=(t,e)=>{const r=new n(t),i=new n(e),o=a(r),s=a(i);return o.eq(s)},d=(e,r)=>{const i=new n(e.liquidity),o=new n(e.lowestRate),s=new n(e.highestRate),g=new n(e.marginalRate),u=t(i),w=a(o),h=a(s),d=a(g);if(!(h.gte(d)&&d.gt(w)||h.eq(d)&&d.eq(w)||h.gt(d)&&d.eq(w)&&u.isZero()))throw new Error(`Either one of the following must hold:\n- highestRate >= marginalRate > lowestRate\n- highestRate == marginalRate == lowestRate\n- (highestRate > marginalRate == lowestRate) AND liquidity == 0\n(highestRate = ${s}, marginalRate = ${g}, lowestRate = ${o}), liquidity = ${i}`);return{y:u,z:void 0!==r?r:h.eq(d)||u.isZero()?u:u.mul(h.sub(w)).div(d.sub(w)),A:l(h.sub(w)),B:l(w)}},m=t=>{const e=r(t.y),i=r(t.z),n=r(g(t.A)),o=r(g(t.B));return{liquidity:e.toString(),lowestRate:s(o).toString(),highestRate:s(o.add(n)).toString(),marginalRate:s(e.eq(i)?o.add(n):o.add(n.mul(e).div(i))).toString()}},R=(t,e)=>{const r=q(t),i=a(new n(e.lowestRate)),o=a(new n(e.highestRate)),s=a(new n(e.marginalRate));return r.mul(s.sub(i)).div(o.sub(i)).toString()},q=e=>{const i=r(d(e).z),o=new n(e.lowestRate),a=new n(e.highestRate),s=o.mul(a).sqrt();return t(i.div(s).floor())};export{h as areScaledRatesEqual,q as calculateCorrelatedZ,R as calculateRequiredLiquidity,g as decodeFloat,m as decodeOrder,s as decodeRate,l as encodeFloat,d as encodeOrder,u as encodeOrders,a as encodeRate,w as isOrderEncodable};
import{DecToBn as t,ONE as e,Decimal as r,BnToDec as n}from"../numerics/index.js";import{BigNumber as i}from"@ethersproject/bignumber";function o(t){return t.gt(0)?r.log2(t.toString()).add(1).floor().toNumber():0}const a=r=>{const n=t(r.sqrt().mul(e).floor()),i=o(n.div(e));return n.shr(i).shl(i)},s=t=>t.div(e).pow(2),l=t=>{const r=o(t.div(e)),n=t.shr(r);return i.from(e).mul(r).or(n)},g=t=>t.mod(e).shl(t.div(e).toNumber()),u=([t,e])=>{const n=new r(t.liquidity),i=new r(t.lowestRate),o=new r(t.highestRate),a=new r(e.liquidity),s=new r(e.lowestRate),l=new r(e.highestRate);return n.eq(0)&&a.gt(0)&&s.gt(0)&&l.gt(0)?[R(t,q(e)),R(e)]:a.eq(0)&&n.gt(0)&&i.gt(0)&&o.gt(0)?[R(t),R(e,q(t))]:[R(t),R(e)]},w=t=>{try{return R(t),!0}catch(t){return!1}},h=(t,e)=>{const n=new r(t),i=new r(e),o=a(n),s=a(i);return o.eq(s)},R=(e,n)=>{const i=new r(e.liquidity),o=new r(e.lowestRate),s=new r(e.highestRate),g=new r(e.marginalRate),u=t(i),w=a(o),h=a(s),R=a(g);if(!(h.gte(R)&&R.gt(w)||h.eq(R)&&R.eq(w)||h.gt(R)&&R.eq(w)&&u.isZero()))throw new Error(`Either one of the following must hold:\n- highestRate >= marginalRate > lowestRate\n- highestRate == marginalRate == lowestRate\n- (highestRate > marginalRate == lowestRate) AND liquidity == 0\n(highestRate = ${s}, marginalRate = ${g}, lowestRate = ${o}), liquidity = ${i}`);return{y:u,z:void 0!==n?n:h.eq(R)||u.isZero()?u:u.mul(h.sub(w)).div(R.sub(w)),A:l(h.sub(w)),B:l(w)}},d=t=>{const e=n(t.y),r=n(t.z),i=n(g(t.A)),o=n(g(t.B));return{liquidity:e.toString(),lowestRate:s(o).toString(),highestRate:s(o.add(i)).toString(),marginalRate:s(e.eq(r)?o.add(i):o.add(i.mul(e).div(r))).toString()}},m=(t,e)=>{const n=q(t),i=a(new r(e.lowestRate)),o=a(new r(e.highestRate)),s=a(new r(e.marginalRate));return n.mul(s.sub(i)).div(o.sub(i)).toString()},q=e=>{const i=n(R(e).z),o=new r(e.lowestRate),a=new r(e.highestRate),s=o.mul(a).sqrt();return t(i.div(s).floor())};export{h as areScaledRatesEqual,q as calculateCorrelatedZ,m as calculateRequiredLiquidity,g as decodeFloat,d as decodeOrder,s as decodeRate,l as encodeFloat,R as encodeOrder,u as encodeOrders,a as encodeRate,w as isOrderEncodable};

@@ -1,1 +0,1 @@

export{Decimals}from"./decimals/index.js";export{areScaledRatesEqual,calculateCorrelatedZ,calculateRequiredLiquidity,decodeFloat,decodeOrder,decodeRate,encodeFloat,encodeOrder,encodeOrders,encodeRate,isOrderEncodable}from"./encoders/index.js";export{encodedOrderBNToStr,encodedOrderStrToBN,encodedStrategyBNToStr,encodedStrategyStrToBN,matchActionBNToStr,ordersMapBNToStr,ordersMapStrToBN,replaceBigNumbersWithStrings,tradeActionStrToBN}from"./serializers/index.js";export{BigNumberMax,BigNumberMin,BnToDec,DecToBn,ONE,TEN,formatUnits,mulDiv,parseUnits,tenPow,trimDecimal}from"./numerics/index.js";export{default as Decimal}from"decimal.js";export{BigNumber}from"@ethersproject/bignumber";
export{Decimals}from"./decimals/index.js";export{areScaledRatesEqual,calculateCorrelatedZ,calculateRequiredLiquidity,decodeFloat,decodeOrder,decodeRate,encodeFloat,encodeOrder,encodeOrders,encodeRate,isOrderEncodable}from"./encoders/index.js";export{encodedOrderBNToStr,encodedOrderStrToBN,encodedStrategyBNToStr,encodedStrategyStrToBN,matchActionBNToStr,ordersMapBNToStr,ordersMapStrToBN,replaceBigNumbersWithStrings,tradeActionStrToBN}from"./serializers/index.js";export{BigNumberMax,BigNumberMin,BnToDec,DecToBn,Decimal,ONE,TEN,formatUnits,mulDiv,parseUnits,tenPow,trimDecimal}from"./numerics/index.js";export{BigNumber}from"@ethersproject/bignumber";
import { BigNumber, BigNumberish } from '@ethersproject/bignumber';
import Decimal from 'decimal.js';
import DecimalJS from 'decimal.js';
declare const Decimal: typeof DecimalJS;
export { Decimal, BigNumber, BigNumberish };
export type Decimal = DecimalJS;
export declare const BigNumberMin: (a: BigNumber, b: BigNumber) => BigNumber;
export declare const BigNumberMax: (a: BigNumber, b: BigNumber) => BigNumber;
export declare const ONE: number;
export declare const TEN: Decimal;
export declare const tenPow: (dec0: number, dec1: number) => Decimal;
export declare const BnToDec: (x: BigNumber) => Decimal;
export declare const TEN: DecimalJS;
export declare const tenPow: (dec0: number, dec1: number) => DecimalJS;
export declare const BnToDec: (x: BigNumber) => DecimalJS;
export declare const DecToBn: (x: Decimal) => BigNumber;

@@ -11,0 +13,0 @@ export declare const mulDiv: (x: BigNumber, y: BigNumber, z: BigNumber) => BigNumber;

@@ -1,1 +0,1 @@

import{BigNumber as t}from"@ethersproject/bignumber";export{BigNumber}from"@ethersproject/bignumber";import{parseUnits as e,formatUnits as r}from"@ethersproject/units";import o from"decimal.js";export{default as Decimal}from"decimal.js";o.set({precision:100,rounding:o.ROUND_HALF_DOWN,toExpNeg:-300,toExpPos:300});const n=(t,e)=>t.lt(e)?t:e,i=(t,e)=>t.gt(e)?t:e,s=2**48,m=new o(10),c=(t,e)=>{const r=t-e;return m.pow(r)},p=t=>new o(t.toString()),u=e=>t.from(e.toFixed()),f=(t,e,r)=>e.eq(r)?t:t.mul(e).div(r);function a(t,e){return new o(t).toFixed(e,o.ROUND_DOWN).replace(/(\.\d*?[1-9])0+$|\.0*$/,"$1")}function d(t,r){const o=a(t,r);return e(o,r)}function x(t,e){const n=r(t,e);return new o(n).toFixed()}export{i as BigNumberMax,n as BigNumberMin,p as BnToDec,u as DecToBn,s as ONE,m as TEN,x as formatUnits,f as mulDiv,d as parseUnits,c as tenPow,a as trimDecimal};
import{BigNumber as t}from"@ethersproject/bignumber";export{BigNumber}from"@ethersproject/bignumber";import{parseUnits as e,formatUnits as o}from"@ethersproject/units";import r from"decimal.js";const n=r.clone();n.set({precision:100,rounding:n.ROUND_HALF_DOWN,toExpNeg:-300,toExpPos:300});const i=(t,e)=>t.lt(e)?t:e,s=(t,e)=>t.gt(e)?t:e,c=2**48,m=new n(10),p=(t,e)=>{const o=t-e;return m.pow(o)},u=t=>new n(t.toString()),f=e=>t.from(e.toFixed()),d=(t,e,o)=>e.eq(o)?t:t.mul(e).div(o);function g(t,e){return new n(t).toFixed(e,n.ROUND_DOWN).replace(/(\.\d*?[1-9])0+$|\.0*$/,"$1")}function x(t,o){const r=g(t,o);return e(r,o)}function a(t,e){const r=o(t,e);return new n(r).toFixed()}export{s as BigNumberMax,i as BigNumberMin,u as BnToDec,f as DecToBn,n as Decimal,c as ONE,m as TEN,a as formatUnits,d as mulDiv,x as parseUnits,p as tenPow,g as trimDecimal};

@@ -5,3 +5,3 @@ {

"source": "src/index.ts",
"version": "0.0.102-DEV",
"version": "0.0.103-DEV",
"description": "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 fulfill trades",

@@ -98,14 +98,14 @@ "main": "dist/index.cjs",

"@typechain/ethers-v5": "^11.1.2",
"@types/chai": "^4.3.11",
"@types/chai": "^5.0.1",
"@types/mocha": "^10.0.0",
"@types/node": "^18.19.17",
"@types/node": "^22.10.1",
"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^6.21.0",
"chai": "^4.3.10",
"chai": "^5.1.2",
"eslint": "^8.57.0",
"mocha": "^10.1.0",
"rollup": "^4.21.2",
"mocha": "^11.0.1",
"rollup": "^4.28.1",
"rollup-plugin-terser": "^7.0.2",
"sinon": "^16.0.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",

@@ -112,0 +112,0 @@ "tslib": "^2.7.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc