@bancor/carbon-sdk
Advanced tools
Comparing version 0.0.96-TEST to 0.0.97-DEV
@@ -1,1 +0,1 @@ | ||
import"../../utils/numerics/index.js";import{BigNumber as e}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";const r=(()=>{try{return self}catch(e){try{return window}catch(e){return global}}})();const o=void 0!==r&&Number(r.CARBON_DEFI_SDK_VERBOSITY)||0;const t=console.log;function n(r){return r instanceof e?r.toString():Array.isArray(r)?r.map(n):"object"==typeof r?Object.fromEntries(Object.entries(r).map((([e,r])=>[e,n(r)]))):r}o>=2&&(console.debug=(...e)=>{const r=e.map(n);t.apply(console,r)});class s{_prefix;constructor(e){this._prefix=`[SDK][${e}]:`}error(...e){console.error(this._prefix,...e)}log(...e){console.log(this._prefix,...e)}debug(...e){o>=1&&console.debug(this._prefix,...e)}}export{s as Logger}; | ||
import"../../utils/numerics/index.js";import{getRuntimeConfig as e}from"../../runtime-config/index.js";import{BigNumber as o}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";const r=e().logVerbosityLevel;const i=console.log;function s(e){return e instanceof o?e.toString():Array.isArray(e)?e.map(s):"object"==typeof e?Object.fromEntries(Object.entries(e).map((([e,o])=>[e,s(o)]))):e}r>=2&&(console.debug=(...e)=>{const o=e.map(s);i.apply(console,o)});class t{_prefix;constructor(e){this._prefix=`[SDK][${e}]:`}error(...e){console.error(this._prefix,...e)}log(...e){console.log(this._prefix,...e)}debug(...e){r>=1&&console.debug(this._prefix,...e)}}export{t as Logger}; |
@@ -63,2 +63,11 @@ import { PopulatedTransaction } from '@ethersproject/contracts'; | ||
/** | ||
* Gets the strategy by its id | ||
* | ||
* If the cache is synced, it will return the strategy from the cache. | ||
* Otherwise, it will fetch the strategy from the chain. | ||
* | ||
* @param {string} id - ID of the strategy to fetch. | ||
*/ | ||
getStrategyById(id: string): Promise<Strategy>; | ||
/** | ||
* Gets all the strategies that belong to the given pair | ||
@@ -65,0 +74,0 @@ * |
@@ -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 s}from"../../common/types/index.js";import{Decimals as o}from"../../utils/decimals/index.js";import{matchByTargetAmount as c,matchBySourceAmount as d}from"../../trade-matcher/match/index.js";import{getEncodedTradeSourceAmount as n}from"../../trade-matcher/trade/index.js";import{getDepths as l,getMinRate as u,getMaxRate as g}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 w,buildStrategyObject as b,encodeStrategy as S,normalizeRate as P}from"../utils/index.js";import{decodeOrder as D}from"../../utils/encoders/index.js";import{ordersMapStrToBN as _,matchActionBNToStr as T,ordersMapBNToStr as v,tradeActionStrToBN as A,encodedStrategyStrToBN as x}from"../../utils/serializers/index.js";import{BigNumber as O}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";import{Decimal as j}from"../../node_modules/decimal.js/decimal/index.js";const M=new m("Toolkit.ts");var R;function k(e){return void 0!==e&&e!==R.reset&&e!==R.maintain}!function(e){e.reset="RESET",e.maintain="MAINTAIN"}(R||(R={}));class q{_api;_decimals;_cache;constructor(e,t,a){M.debug("SDK class constructor called with",arguments),this._api=e,this._cache=t;this._decimals=new o((async e=>await(a?.(e))??await this._api.reader.getDecimalsByAddress(e)))}static getMatchActions(e,t,a,r=s.Fast,i){const o=_(a);let n;return n=t?c(O.from(e),o,[r],i):d(O.from(e),o,[r],i),n[r]?.map(T)??[]}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)),O.from(0)),s=await this._decimals.fetchDecimals(a),o=e(i,s);return M.debug("getLiquidityByPair info:",{orders:r,liquidityWei:i,targetToken:a,decimals:s,liquidity:o}),o}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(n(t.y,t))),O.from(0)),s=await this._decimals.fetchDecimals(t),o=e(i,s);return M.debug("getMaxSourceAmountByPair info:",{orders:r,maxSourceAmountWei:i,sourceToken:t,decimals:s,maxSourceAmount:o}),o}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(y),i=await Promise.all(r.map((async e=>await h(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(y),s=await Promise.all(i.map((async e=>await h(e,this._decimals))));return M.debug("getUserStrategies info:",{ids:t,encodedStrategies:a,decodedStrategies:i,strategies:s}),s}async getMatchParams(e,a,r,i){M.debug("getMatchParams called",arguments);const s=this._decimals,o=await s.fetchDecimals(e),c=await s.fetchDecimals(a),d=await this._cache.getOrdersByPair(e,a),n=t(r,i?c:o);return{orders:v(d),amountWei:n.toString(),sourceDecimals:o,targetDecimals:c}}async getTradeData(e,t,a,r,i=s.Fast,o){M.debug("getTradeData called",arguments);const{orders:c,amountWei:d}=await this.getMatchParams(e,t,a,r),n=q.getMatchActions(d,r,c,i,o),l=await this.getTradeDataFromActions(e,t,r,n);return M.debug("getTradeData info:",{orders:c,amount:a,amountWei:d,res:l}),l}async getTradeDataFromActions(t,r,i,s){M.debug("getTradeDataFromActions called",arguments);const o=await this._cache.getTradingFeePPMByPair(t,r);if(void 0===o)throw new Error(`tradingFeePPM is undefined for this pair: ${t}-${r}`);const c=this._decimals,d=await c.fetchDecimals(t),n=await c.fetchDecimals(r),l=[],u=[];let g,m,y,h=O.from(0),B=O.from(0);if(s.forEach((t=>{l.push({strategyId:t.id,amount:t.input}),i?u.push({id:t.id,sourceAmount:e(p(t.output,o).floor().toFixed(0),d),targetAmount:e(t.input,n)}):u.push({id:t.id,sourceAmount:e(t.input,d),targetAmount:e(f(t.output,o).floor().toFixed(0),n)}),B=B.add(t.input),h=h.add(t.output)})),i?(g=p(h,o).floor().toFixed(0),m=B.toString()):(g=B.toString(),m=f(h,o).floor().toFixed(0)),new j(g).isZero()||new j(m).isZero())y={tradeActions:l,actionsTokenRes:u,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:s};else{const t=new j(m).div(g).times(a(d,n)).toString();y={tradeActions:l,actionsTokenRes:u,totalSourceAmount:e(g,d),totalTargetAmount:e(m,n),effectiveRate:t,actionsWei:s}}return M.debug("getTradeDataFromActions info:",{sourceDecimals:d,targetDecimals:n,actionsWei:s,totalInput:B,totalOutput:h,tradingFeePPM:o,res:y}),y}async composeTradeByTargetTransaction(e,a,r,i,s,o){M.debug("composeTradeByTargetTransaction called",arguments);const c=await this._decimals.fetchDecimals(e);return this._api.composer.tradeByTargetAmount(e,a,r.map(A),i,t(s,c),o)}async composeTradeBySourceTransaction(e,a,r,i,s,o){M.debug("composeTradeBySourceTransaction called",arguments);const c=await this._decimals.fetchDecimals(a);return this._api.composer.tradeBySourceAmount(e,a,r.map(A),i,t(s,c),o)}async calculateOverlappingStrategySellBudget(e,t,a,r,i,s,o){M.debug("calculateOverlappingStrategySellBudget called",arguments);const c=this._decimals,d=await c.fetchDecimals(e),n=await c.fetchDecimals(t),l=B(d,n,a,r,i,s,o);return M.debug("calculateOverlappingStrategySellBudget info:",{baseDecimals:d,budget:l}),l}async calculateOverlappingStrategyBuyBudget(e,t,a,r,i,s,o){M.debug("calculateOverlappingStrategyBuyBudget called",arguments);const c=this._decimals,d=await c.fetchDecimals(e),n=await c.fetchDecimals(t),l=w(d,n,a,r,i,s,o);return M.debug("calculateOverlappingStrategyBuyBudget info:",{quoteDecimals:n,budget:l}),l}async createBuySellStrategy(e,t,a,r,i,s,o,c,d,n,l){M.debug("createBuySellStrategy called",arguments);const u=this._decimals,g=await u.fetchDecimals(e),m=await u.fetchDecimals(t),y=b(e,t,g,m,a,r,i,s,o,c,d,n),h=S(y);return M.debug("createBuySellStrategy info:",{strategy:y,encStrategy:h}),this._api.composer.createStrategy(h.token0,h.token1,h.order0,h.order1,l)}async updateStrategy(e,t,{buyPriceLow:a,buyPriceHigh:s,buyBudget:o,sellPriceLow:c,sellPriceHigh:d,sellBudget:n},l,u,g){M.debug("updateStrategy called",arguments);const m=y(x(t)),p=await h(m,this._decimals),f=this._decimals,B=await f.fetchDecimals(p.baseToken),w=await f.fetchDecimals(p.quoteToken),P=b(p.baseToken,p.quoteToken,B,w,a??p.buyPriceLow,k(l)?l:s??p.buyPriceHigh,s??p.buyPriceHigh,o??p.buyBudget,c??p.sellPriceLow,k(u)?u:c??p.sellPriceLow,d??p.sellPriceHigh,n??p.sellBudget),D=S(P),_=x(t);return void 0===o&&(D.order1.y=_.order1.y),void 0===n&&(D.order0.y=_.order0.y),void 0===a&&void 0===s&&(D.order1.A=_.order1.A,D.order1.B=_.order1.B),void 0===c&&void 0===d&&(D.order0.A=_.order0.A,D.order0.B=_.order0.B),void 0!==o&&(k(l)||(l===R.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&&(k(u)||(u===R.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===s||l!==R.reset&&void 0!==l||(D.order1.z=D.order1.y),void 0===c&&void 0===d||u!==R.reset&&void 0!==u||(D.order0.z=D.order0.y),M.debug("updateStrategy info:",{baseDecimals:B,quoteDecimals:w,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],g)}async deleteStrategy(e){return M.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(O.from(e))}async getRateLiquidityDepthsByPair(t,a,r){M.debug("getRateLiquidityDepthByPair called",arguments);const i=Object.values(await this._cache.getOrdersByPair(t,a)).map(D),s=this._decimals,o=await s.fetchDecimals(t),c=await s.fetchDecimals(a),d=r.map((e=>new j(P(e,c,o)))),n=l(i,d).map((e=>e.floor().toFixed(0))),u=n.map((t=>e(t,c)));return M.debug("getRateLiquidityDepthByPair info:",{orders:i,depthsWei:n,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(D),r=u(a).toString(),i=this._decimals,s=await i.fetchDecimals(e),o=await i.fetchDecimals(t),c=P(r,s,o);return M.debug("getMinRateByPair info:",{orders:a,minRate:r,sourceDecimals:s,targetDecimals:o,normalizedRate:c}),c}async getMaxRateByPair(e,t){M.debug("getMaxRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(D),r=g(a).toString(),i=this._decimals,s=await i.fetchDecimals(e),o=await i.fetchDecimals(t),c=P(r,s,o);return M.debug("getMaxRateByPair info:",{orders:a,maxRate:r,sourceDecimals:s,targetDecimals:o,normalizedRate:c}),c}}export{R as MarginalPriceOptions,q as Toolkit,k as isMarginalPriceValue}; | ||
import{formatUnits as e,parseUnits as t,tenPow as a,BigNumberMax as r,mulDiv as i}from"../../utils/numerics/index.js";import{MatchType as s}from"../../common/types/index.js";import{Decimals as o}from"../../utils/decimals/index.js";import{matchByTargetAmount as c,matchBySourceAmount as d}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 b,encodeStrategy as w,normalizeRate as P}from"../utils/index.js";import{decodeOrder as _}from"../../utils/encoders/index.js";import{ordersMapStrToBN as D,matchActionBNToStr as T,ordersMapBNToStr as v,tradeActionStrToBN as A,encodedStrategyStrToBN as x}from"../../utils/serializers/index.js";import{BigNumber as O}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";import{Decimal as j}from"../../node_modules/decimal.js/decimal/index.js";const M=new m("Toolkit.ts");var R;function k(e){return void 0!==e&&e!==R.reset&&e!==R.maintain}!function(e){e.reset="RESET",e.maintain="MAINTAIN"}(R||(R={}));class q{_api;_decimals;_cache;constructor(e,t,a){M.debug("SDK class constructor called with",arguments),this._api=e,this._cache=t;this._decimals=new o((async e=>await(a?.(e))??await this._api.reader.getDecimalsByAddress(e)))}static getMatchActions(e,t,a,r=s.Fast,i){const o=D(a);let n;return n=t?c(O.from(e),o,[r],i):d(O.from(e),o,[r],i),n[r]?.map(T)??[]}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)),O.from(0)),s=await this._decimals.fetchDecimals(a),o=e(i,s);return M.debug("getLiquidityByPair info:",{orders:r,liquidityWei:i,targetToken:a,decimals:s,liquidity:o}),o}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(n(t.y,t))),O.from(0)),s=await this._decimals.fetchDecimals(t),o=e(i,s);return M.debug("getMaxSourceAmountByPair info:",{orders:r,maxSourceAmountWei:i,sourceToken:t,decimals:s,maxSourceAmount:o}),o}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(O.from(e)));const a=y(t),r=await h(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(y),i=await Promise.all(r.map((async e=>await h(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(y),s=await Promise.all(i.map((async e=>await h(e,this._decimals))));return M.debug("getUserStrategies info:",{ids:t,encodedStrategies:a,decodedStrategies:i,strategies:s}),s}async getMatchParams(e,a,r,i){M.debug("getMatchParams called",arguments);const s=this._decimals,o=await s.fetchDecimals(e),c=await s.fetchDecimals(a),d=await this._cache.getOrdersByPair(e,a),n=t(r,i?c:o);return{orders:v(d),amountWei:n.toString(),sourceDecimals:o,targetDecimals:c}}async getTradeData(e,t,a,r,i=s.Fast,o){M.debug("getTradeData called",arguments);const{orders:c,amountWei:d}=await this.getMatchParams(e,t,a,r),n=q.getMatchActions(d,r,c,i,o),g=await this.getTradeDataFromActions(e,t,r,n);return M.debug("getTradeData info:",{orders:c,amount:a,amountWei:d,res:g}),g}async getTradeDataFromActions(t,r,i,s){M.debug("getTradeDataFromActions called",arguments);const o=await this._cache.getTradingFeePPMByPair(t,r);if(void 0===o)throw new Error(`tradingFeePPM is undefined for this pair: ${t}-${r}`);const c=this._decimals,d=await c.fetchDecimals(t),n=await c.fetchDecimals(r),g=[],l=[];let u,m,y,h=O.from(0),B=O.from(0);if(s.forEach((t=>{g.push({strategyId:t.id,amount:t.input}),i?l.push({id:t.id,sourceAmount:e(p(t.output,o).floor().toFixed(0),d),targetAmount:e(t.input,n)}):l.push({id:t.id,sourceAmount:e(t.input,d),targetAmount:e(f(t.output,o).floor().toFixed(0),n)}),B=B.add(t.input),h=h.add(t.output)})),i?(u=p(h,o).floor().toFixed(0),m=B.toString()):(u=B.toString(),m=f(h,o).floor().toFixed(0)),new j(u).isZero()||new j(m).isZero())y={tradeActions:g,actionsTokenRes:l,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:s};else{const t=new j(m).div(u).times(a(d,n)).toString();y={tradeActions:g,actionsTokenRes:l,totalSourceAmount:e(u,d),totalTargetAmount:e(m,n),effectiveRate:t,actionsWei:s}}return M.debug("getTradeDataFromActions info:",{sourceDecimals:d,targetDecimals:n,actionsWei:s,totalInput:B,totalOutput:h,tradingFeePPM:o,res:y}),y}async composeTradeByTargetTransaction(e,a,r,i,s,o){M.debug("composeTradeByTargetTransaction called",arguments);const c=await this._decimals.fetchDecimals(e);return this._api.composer.tradeByTargetAmount(e,a,r.map(A),i,t(s,c),o)}async composeTradeBySourceTransaction(e,a,r,i,s,o){M.debug("composeTradeBySourceTransaction called",arguments);const c=await this._decimals.fetchDecimals(a);return this._api.composer.tradeBySourceAmount(e,a,r.map(A),i,t(s,c),o)}async calculateOverlappingStrategySellBudget(e,t,a,r,i,s,o){M.debug("calculateOverlappingStrategySellBudget called",arguments);const c=this._decimals,d=await c.fetchDecimals(e),n=await c.fetchDecimals(t),g=B(d,n,a,r,i,s,o);return M.debug("calculateOverlappingStrategySellBudget info:",{baseDecimals:d,budget:g}),g}async calculateOverlappingStrategyBuyBudget(e,t,a,r,i,s,o){M.debug("calculateOverlappingStrategyBuyBudget called",arguments);const c=this._decimals,d=await c.fetchDecimals(e),n=await c.fetchDecimals(t),g=S(d,n,a,r,i,s,o);return M.debug("calculateOverlappingStrategyBuyBudget info:",{quoteDecimals:n,budget:g}),g}async createBuySellStrategy(e,t,a,r,i,s,o,c,d,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,s,o,c,d,n),h=w(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:s,buyBudget:o,sellPriceLow:c,sellPriceHigh:d,sellBudget:n},g,l,u){M.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=b(p.baseToken,p.quoteToken,B,S,a??p.buyPriceLow,k(g)?g:s??p.buyPriceHigh,s??p.buyPriceHigh,o??p.buyBudget,c??p.sellPriceLow,k(l)?l:c??p.sellPriceLow,d??p.sellPriceHigh,n??p.sellBudget),_=w(P),D=x(t);return void 0===o&&(_.order1.y=D.order1.y),void 0===n&&(_.order0.y=D.order0.y),void 0===a&&void 0===s&&(_.order1.A=D.order1.A,_.order1.B=D.order1.B),void 0===c&&void 0===d&&(_.order0.A=D.order0.A,_.order0.B=D.order0.B),void 0!==o&&(k(g)||(g===R.maintain?D.order1.y.isZero()?_.order1.z=r(D.order1.z,_.order1.y):_.order1.z=i(D.order1.z,_.order1.y,D.order1.y):_.order1.z=_.order1.y)),void 0!==n&&(k(l)||(l===R.maintain?D.order0.y.isZero()?_.order0.z=r(D.order0.z,_.order0.y):_.order0.z=i(D.order0.z,_.order0.y,D.order0.y):_.order0.z=_.order0.y)),void 0===a&&void 0===s||g!==R.reset&&void 0!==g||(_.order1.z=_.order1.y),void 0===c&&void 0===d||l!==R.reset&&void 0!==l||(_.order0.z=_.order0.y),M.debug("updateStrategy info:",{baseDecimals:B,quoteDecimals:S,decodedOriginal:m,originalStrategy:p,newStrategy:P,newEncodedStrategy:_}),this._api.composer.updateStrategy(O.from(e),_.token0,_.token1,[D.order0,D.order1],[_.order0,_.order1],u)}async deleteStrategy(e){return M.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(O.from(e))}async getRateLiquidityDepthsByPair(t,a,r){M.debug("getRateLiquidityDepthByPair called",arguments);const i=Object.values(await this._cache.getOrdersByPair(t,a)).map(_),s=this._decimals,o=await s.fetchDecimals(t),c=await s.fetchDecimals(a),d=r.map((e=>new j(P(e,c,o)))),n=g(i,d).map((e=>e.floor().toFixed(0))),l=n.map((t=>e(t,c)));return M.debug("getRateLiquidityDepthByPair info:",{orders:i,depthsWei:n,targetDecimals:c,depthsInTargetDecimals:l}),l}async getMinRateByPair(e,t){M.debug("getMinRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(_),r=l(a).toString(),i=this._decimals,s=await i.fetchDecimals(e),o=await i.fetchDecimals(t),c=P(r,s,o);return M.debug("getMinRateByPair info:",{orders:a,minRate:r,sourceDecimals:s,targetDecimals:o,normalizedRate:c}),c}async getMaxRateByPair(e,t){M.debug("getMaxRateByPair called",arguments);const a=Object.values(await this._cache.getOrdersByPair(e,t)).map(_),r=u(a).toString(),i=this._decimals,s=await i.fetchDecimals(e),o=await i.fetchDecimals(t),c=P(r,s,o);return M.debug("getMaxRateByPair info:",{orders:a,maxRate:r,sourceDecimals:s,targetDecimals:o,normalizedRate:c}),c}}export{R as MarginalPriceOptions,q as Toolkit,k as isMarginalPriceValue}; |
@@ -1,1 +0,1 @@ | ||
import{ONE as r,BigNumberMax as t}from"../../utils/numerics/index.js";import{decodeFloat as e}from"../../utils/encoders/index.js";import{BigNumber as n}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";const o=n.from(r),u=n.from(2).pow(128).sub(1),s=n.from(2).pow(256).sub(1);function i(r,t){if(r.gte(0)&&r.lte(t))return r;throw null}const d=r=>i(r,u),m=(r,t)=>i(r.add(t),s),c=(r,t)=>i(r.mul(t),s),f=(r,t,e)=>i(r.mul(t).div(e),s),l=(r,t,e)=>i(r.mul(t).add(e).sub(1).div(e),s),b=(r,e,n,u,d)=>{if(u.eq(0))return l(r,c(o,o),c(d,d));const b=c(n,o),a=m(c(e,u),c(n,d)),p=(v=a,h=c(r,u),i(v.sub(h),s));var v,h;const j=l(b,b,s),x=l(a,p,s),y=t(j,x),g=l(b,b,y),w=f(a,p,y);return l(r,g,w)},a=(r,u)=>{const i=r,b=u.y,a=u.z,p=e(u.A),v=e(u.B);try{return d(((r,e,n,u,i)=>{if(u.eq(0))return f(r,c(i,i),c(o,o));const d=c(n,o),b=m(c(e,u),c(n,i)),a=c(b,r),p=l(d,d,s),v=l(a,u,s),h=t(p,v),j=l(d,d,h),x=l(a,u,h);return j.add(x).lte(s)?f(b,a.div(h),j.add(x)):b.div(m(u,l(d,d,a)))})(i,b,a,p,v))}catch(r){return n.from(0)}},p=(r,t)=>{const n=r,o=t.y,s=t.z,i=e(t.A),m=e(t.B);try{return d(b(n,o,s,i,m))}catch(r){return u}};export{p as getEncodedTradeSourceAmount,a as getEncodedTradeTargetAmount}; | ||
import{ONE as r,BigNumberMax as t}from"../../utils/numerics/index.js";import{decodeFloat as e}from"../../utils/encoders/index.js";import{getRuntimeConfig as n}from"../../runtime-config/index.js";import{BigNumber as o}from"../../node_modules/@ethersproject/bignumber/lib.esm/bignumber/index.js";const u=n().legacyTradeBySourceRange,i=o.from(r),s=o.from(2).pow(128).sub(1),m=o.from(2).pow(256).sub(1);function d(r,t){if(r.gte(0)&&r.lte(t))return r;throw null}const c=r=>d(r,s),f=(r,t)=>d(r.add(t),m),l=(r,t)=>d(r.mul(t),m),a=(r,t,e)=>d(r.mul(t).div(e),m),b=(r,t,e)=>d(r.mul(t).add(e).sub(1).div(e),m),p=(r,e,n,o,u)=>{if(o.eq(0))return b(r,l(i,i),l(u,u));const s=l(n,i),c=f(l(e,o),l(n,u)),p=(g=c,y=l(r,o),d(g.sub(y),m));var g,y;const j=b(s,s,m),v=b(c,p,m),x=t(j,v),h=b(s,s,x),w=a(c,p,x);return b(r,h,w)},g=(r,n)=>{const s=r,d=n.y,p=n.z,g=e(n.A),y=e(n.B);try{return c(((r,e,n,o,s,d=!1)=>{const c=d||u;if(o.eq(0))return a(r,l(s,s),l(i,i));const p=l(n,i),g=f(l(e,o),l(n,s)),y=l(g,r),j=b(p,p,m),v=b(y,o,m),x=t(j,v),h=b(p,p,x),w=b(y,o,x);return c||h.add(w).lte(m)?a(g,y.div(x),h.add(w)):g.div(f(o,b(p,p,y)))})(s,d,p,g,y))}catch(r){return o.from(0)}},y=(r,t)=>{const n=r,o=t.y,u=t.z,i=e(t.A),m=e(t.B);try{return c(p(n,o,u,i,m))}catch(r){return s}};export{y as getEncodedTradeSourceAmount,g as getEncodedTradeTargetAmount}; |
@@ -5,3 +5,3 @@ { | ||
"source": "src/index.ts", | ||
"version": "0.0.96-TEST", | ||
"version": "0.0.97-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", | ||
@@ -11,7 +11,7 @@ "main": "dist/index.cjs", | ||
"exports": { | ||
".":{ | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./contracts-api":{ | ||
"./contracts-api": { | ||
"import": "./dist/contracts-api/index.js", | ||
@@ -18,0 +18,0 @@ "require": "./dist/contracts-api/index.cjs" |
@@ -82,3 +82,3 @@ # Carbon SDK | ||
- The SDK Logger supports 3 verbosity levels: | ||
### 1. The SDK Logger supports 3 verbosity levels: | ||
- `0` (default) only prints errors and important logs. | ||
@@ -95,2 +95,8 @@ - `1` (debug) prints highly verbose logs. | ||
### 2. For usage with contracts version < 5, without the enhanced range for trade by source: | ||
```js | ||
window.LEGACY_TRADE_BY_SOURCE_RANGE = true; | ||
``` | ||
## Authors | ||
@@ -97,0 +103,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 3 instances in 1 package
921331
184
7723
116