@bancor/carbon-sdk
Advanced tools
Comparing version 0.0.39-DEV to 0.0.40-DEV
@@ -1,9 +0,9 @@ | ||
import { EncodedOrder, EncodedStrategy } from '../types'; | ||
import { EncodedStrategy } from '../types'; | ||
import { Fetcher, PairToDirectedOrdersMap, PairToStrategiesMap, StrategyById } from './types'; | ||
import { BigNumber } from '../numerics'; | ||
export declare const createPairToStrategiesMap: (fetcher: Fetcher) => Promise<PairToStrategiesMap>; | ||
export declare const populateCachedOrdersCache: (pairToStrategies: PairToStrategiesMap, cachedOrders: PairToDirectedOrdersMap) => void; | ||
export declare const removeDeletedStrategyFromCache: (strategy: EncodedStrategy, pairToStrategies: PairToStrategiesMap, strategyById: StrategyById, ordersCache: PairToDirectedOrdersMap) => void; | ||
export declare const addNewStrategyToMap: (strategy: EncodedStrategy, pairToStrategies: PairToStrategiesMap, strategyById: StrategyById, ordersCache: PairToDirectedOrdersMap) => void; | ||
export declare const applyModifiedOrderToCache: (strategyId: BigNumber, orderIndex: number, order: EncodedOrder, pairToStrategies: PairToStrategiesMap, strategyById: StrategyById, ordersCache: PairToDirectedOrdersMap) => void; | ||
export declare const applyModifiedOrderToCache: (strategy: EncodedStrategy, orderIndex: number, ordersCache: PairToDirectedOrdersMap) => void; | ||
export declare const applyModifiedStrategyToCache: (strategy: EncodedStrategy, pairToStrategies: PairToStrategiesMap, strategyById: StrategyById, ordersCache: PairToDirectedOrdersMap) => void; | ||
//# sourceMappingURL=cache-ops.d.ts.map |
@@ -8,2 +8,3 @@ import { OrdersMap } from '../match'; | ||
onStrategyUpdated(listener: (strategy: EncodedStrategy) => void): void; | ||
onStrategyDeleted(listener: (strategy: EncodedStrategy) => void): void; | ||
} | ||
@@ -10,0 +11,0 @@ export type PairToStrategiesMap = Map<TokenPair, EncodedStrategy[]>; |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):(e||self).carbonSdk=t(e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,a,r){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/i(n);function u(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,"symbol"==typeof(r=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,"string");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(a.key))?r:String(r),a)}var r}function s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},p.apply(this,arguments)}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=function(e,t){return e.localeCompare(t)},c=function(e){if(2!==e.length)throw new Error("Invalid number of tokens: expected 2, got "+e.length);if(e[0]===e[1])throw new Error("Cannot create key for identical tokens: "+e[0])},m=function(e,t){return c([e,t]),[e,t].sort(l)},f=function(e,t){return c([e,t]),e+"-"+t},g=function(e,t,n,a,r,i){for(var o,u=d(a.entries());!(o=u()).done;)for(var s=o.value[1],p=0;p<s.length;p++)if(s[p].id===e){if(s[p][0===t?"order0":"order1"]=n,r.set(e.toString(),s[p]),0===i.size)return;var y=[s[p].token0,s[p].token1];0===t&&y.reverse();var l,c=f(y[0],y[1]),m=i.get(c);return void(m?m[s[p].id.toString()]=n:(console.warn("Should not be here, modified order is supposed to already be cached"),i.set(c,((l={})[s[p].id.toString()]=n,l))))}},b=/*#__PURE__*/function(){function e(e){this._pairToStrategies=void 0,this._strategyById=void 0,this._fetcher=void 0,this._cachedOrders=void 0,this._fetcher=e,this._pairToStrategies=new Map,this._strategyById=new Map,this._cachedOrders=new Map}var t=e.prototype;return t.init=function(){try{var e=this;return Promise.resolve(function(e){try{return Promise.resolve(e.getAllTokenPairs()).then(function(t){return Promise.resolve(e.getStrategiesByTokenPairs(t)).then(function(e){for(var n=new Map,a=0;a<t.length;a++){var r=t[a],i=e[a],o=m(r[0],r[1]);n.set(o,i)}return n})})}catch(e){return Promise.reject(e)}}(e._fetcher)).then(function(t){e._pairToStrategies=t,e._fetcher.onStrategyCreated(function(t){return function(e,t,n,a){if(!n.has(e.id.toString())){n.set(e.id.toString(),e);var r=m(e.token0,e.token1);if(t.has(r)?t.get(r).push(e):t.set(r,[e]),0!==a.size)for(var i=[e.token0,e.token1],o=0,u=[i,i.reverse()];o<u.length;o++){var s,p=u[o],y=f(p[0],p[1]),d=p[0]===e.token0?e.order1:e.order0,l=a.get(y);l?l[e.id.toString()]=d:a.set(y,((s={})[e.id.toString()]=d,s))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders)}),e._fetcher.onStrategyUpdated(function(t){return function(e,t,n,a){g(e.id,0,e.order0,t,n,a),g(e.id,1,e.order1,t,n,a)}(t,e._pairToStrategies,e._strategyById,e._cachedOrders)});for(var n,a=d(e._pairToStrategies.values());!(n=a()).done;){var r=n.value;if(r&&r.length>0)for(var i=0;i<r.length;i++)e._strategyById.set(r[i].id.toString(),r[i])}})}catch(e){return Promise.reject(e)}},t.getOrders=function(e,t,n){var a;if(void 0===n&&(n=!1),0===this._pairToStrategies.size)return console.warn("getOrders was called when no strategies are cached, did you call init?"),{};0===this._cachedOrders.size&&function(e,t){t.clear();for(var n,a=d(e.values());!(n=a()).done;){var r=n.value;if(r.length>0){for(var i=r[0].token0,o=r[0].token1,u={},s={},p=0;p<r.length;p++)r[p].token0===i?(u[r[p].id.toString()]=r[p].order0,s[r[p].id.toString()]=r[p].order1):(u[r[p].id.toString()]=r[p].order1,s[r[p].id.toString()]=r[p].order0);t.set(f(i,o),s),t.set(f(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var r=f(e,t),i=null!=(a=this._cachedOrders.get(r))?a:{};if(n)return i;var o=Object.entries(i).filter(function(e){return e[1].y.gt(0)&&(e[1].A.gt(0)||e[1].B.gt(0))});return Object.fromEntries(o)},t.getStrategyById=function(e){return this._strategyById.get(e.toString())},s(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys())}}]),e}();o.default.set({precision:50,rounding:o.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var T=Math.pow(2,32),h=new o.default(10),v=function(e,t){return h.pow(e-t)},w="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),k=function(e){return e.toLowerCase()===w},_=function(e,n,a){var r=p({},a);return k(e)&&(r.value=n.reduce(function(e,t){return e.add(t.amount)},t.BigNumber.from(0))),r},P=/*#__PURE__*/function(){function e(e){this._prefix=void 0,this._prefix="[SDK]["+e+"]:"}var t=e.prototype;return t.log=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},t.debug=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),S=new P("Composer.ts"),M=/*#__PURE__*/function(){function e(e){this._contracts=void 0,this._contracts=e}var t=e.prototype;return t.tradeByTargetAmount=function(e,t,n,a,r,i){S.debug("tradeByTargetAmount called",arguments);var o=_(e,n,i);return S.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,a,r,o)},t.tradeBySourceAmount=function(e,t,n,a,r,i){S.debug("tradeBySourceAmount called",arguments);var o=_(e,n,i);return S.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,a,r,o)},t.createStrategy=function(e,t,n,a,r){S.debug("createStrategy called",arguments);var i=p({},r);return k(e)?i.value=n.y:k(t)&&(i.value=a.y),S.debug("createStrategy overrides",i),this._contracts.carbonController.populateTransaction.createStrategy(e,t,[n,a],i)},t.deleteStrategy=function(e){return this._contracts.carbonController.populateTransaction.deleteStrategy(e)},t.updateStrategy=function(e,t,n,a){return this._contracts.carbonController.populateTransaction.updateStrategy(e,t,n,a)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),B=[{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"previousAdmin",type:"address"},{indexed:!1,internalType:"address",name:"newAdmin",type:"address"}],name:"AdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"beacon",type:"address"}],name:"BeaconUpgraded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{stateMutability:"payable",type:"fallback"},{inputs:[],name:"admin",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"implementation",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"}],name:"upgradeTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"},{inputs:[],name:"AlreadyInitialized",type:"error"},{inputs:[],name:"DeadlineExpired",type:"error"},{inputs:[],name:"GreaterThanMaxInput",type:"error"},{inputs:[],name:"IdenticalAddresses",type:"error"},{inputs:[],name:"InsufficientCapacity",type:"error"},{inputs:[],name:"InvalidFee",type:"error"},{inputs:[],name:"InvalidIndices",type:"error"},{inputs:[],name:"InvalidStrategyId",type:"error"},{inputs:[],name:"InvalidTradeActionAmount",type:"error"},{inputs:[],name:"LowerThanMinReturn",type:"error"},{inputs:[],name:"NativeAmountMismatch",type:"error"},{inputs:[],name:"NoIdsProvided",type:"error"},{inputs:[],name:"OutDated",type:"error"},{inputs:[],name:"Overflow",type:"error"},{inputs:[],name:"PoolAlreadyExists",type:"error"},{inputs:[],name:"PoolDoesNotExists",type:"error"},{inputs:[],name:"StrategyDoesNotExist",type:"error"},{inputs:[],name:"TokensMismatch",type:"error"},{inputs:[],name:"UnknownDelegator",type:"error"},{inputs:[],name:"UnnecessaryNativeTokenReceived",type:"error"},{inputs:[],name:"UnsetDelegator",type:"error"},{inputs:[],name:"ZeroLiquidityProvided",type:"error"},{inputs:[],name:"ZeroValue",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"poolId",type:"uint256"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"}],name:"PoolCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyDeleted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"trader",type:"address"},{indexed:!0,internalType:"address",name:"sourceToken",type:"address"},{indexed:!0,internalType:"address",name:"targetToken",type:"address"},{indexed:!1,internalType:"uint256",name:"sourceAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"targetAmount",type:"uint256"},{indexed:!1,internalType:"uint128",name:"tradingFeeAmount",type:"uint128"},{indexed:!1,internalType:"bool",name:"byTargetAmount",type:"bool"}],name:"TokensTraded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"prevFeePPM",type:"uint32"},{indexed:!1,internalType:"uint32",name:"newFeePPM",type:"uint32"}],name:"TradingFeePPMUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"accumulatedFees",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"controllerType",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"createPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],name:"createStrategy",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"deleteStrategy",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pairs",outputs:[{internalType:"address[2][]",name:"",type:"address[2][]"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"pool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"}],name:"postUpgrade",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"roleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[],name:"roleEmergencyStopper",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint32",name:"newTradingFeePPM",type:"uint32"}],name:"setTradingFeePPM",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256[]",name:"ids",type:"uint256[]"}],name:"strategiesByIds",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"endIndex",type:"uint256"}],name:"strategiesByPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"strategiesByPoolCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"}],name:"strategy",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"minReturn",type:"uint128"}],name:"tradeBySourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"maxInput",type:"uint128"}],name:"tradeByTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeSourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"tradingFeePPM",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"currentOrders",type:"tuple[2]"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"newOrders",type:"tuple[2]"}],name:"updateStrategy",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"address",name:"newOwner",type:"address"}],name:"updateStrategyOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"logic",type:"address"},{internalType:"address",name:"initAdmin",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],x=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(B)},e.connect=function(e,t){return new a.Contract(e,B,t)},e}();x.abi=B;var A=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"blockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBlockNumber",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockCoinbase",outputs:[{internalType:"address",name:"coinbase",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockDifficulty",outputs:[{internalType:"uint256",name:"difficulty",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockGasLimit",outputs:[{internalType:"uint256",name:"gaslimit",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"}],name:"getEthBalance",outputs:[{internalType:"uint256",name:"balance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryAggregate",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryBlockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"}],I=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(A)},e.connect=function(e,t){return new a.Contract(e,A,t)},e}();I.abi=A;var D=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_disable",type:"bool"}],name:"disableTransfers",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"version",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"standard",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_token",type:"address"},{name:"_to",type:"address"},{name:"_amount",type:"uint256"}],name:"withdrawTokens",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[],name:"acceptOwnership",outputs:[],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_amount",type:"uint256"}],name:"issue",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[],name:"owner",outputs:[{name:"",type:"address"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_amount",type:"uint256"}],name:"destroy",outputs:[],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"transfersEnabled",outputs:[{name:"",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"newOwner",outputs:[{name:"",type:"address"}],payable:!1,type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_newOwner",type:"address"}],name:"transferOwnership",outputs:[],payable:!1,type:"function"},{inputs:[{name:"_name",type:"string"},{name:"_symbol",type:"string"},{name:"_decimals",type:"uint8"}],payable:!1,type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,name:"_token",type:"address"}],name:"NewSmartToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_amount",type:"uint256"}],name:"Issuance",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_amount",type:"uint256"}],name:"Destruction",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_prevOwner",type:"address"},{indexed:!1,name:"_newOwner",type:"address"}],name:"OwnerUpdate",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"_from",type:"address"},{indexed:!0,name:"_to",type:"address"},{indexed:!1,name:"_value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"_owner",type:"address"},{indexed:!0,name:"_spender",type:"address"},{indexed:!1,name:"_value",type:"uint256"}],name:"Approval",type:"event"}],O=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(D)},e.connect=function(e,t){return new a.Contract(e,D,t)},e}();O.abi=D;var R=[{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"},{internalType:"string",name:"newBaseURI",type:"string"},{internalType:"string",name:"newBaseExtension",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"CarbonControllerNotSet",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"approved",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"operator",type:"address"},{indexed:!1,internalType:"bool",name:"approved",type:"bool"}],name:"ApprovalForAll",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"approve",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"getApproved",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"operator",type:"address"}],name:"isApprovedForAll",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"provider",type:"address"},{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"ownerOf",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"operator",type:"address"},{internalType:"bool",name:"approved",type:"bool"}],name:"setApprovalForAll",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseExtension",type:"string"}],name:"setBaseExtension",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseURI",type:"string"}],name:"setBaseURI",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract CarbonController",name:"carbonController",type:"address"}],name:"setCarbonController",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenOfOwnerByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"tokenURI",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"transferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"}],name:"useGlobalURI",outputs:[],stateMutability:"nonpayable",type:"function"}],C=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(R)},e.connect=function(e,t){return new a.Contract(e,R,t)},e}();C.abi=R;var j=/*#__PURE__*/function(){function e(e){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._provider=e}return e.prototype.token=function(e){return O.connect(e,this._provider)},s(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=x.connect("0x483309B60A7f5A097aE09Cf5811773431a9E8d1B",this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=I.connect("0x5ba1e12693dc8f9c48aad8770482f4739beed696",this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=C.connect("0x2fB666c75ec98462852c66D4981e1B3a0E668593",this._provider)),this._voucher}}]),e}(),E=new P("Reader.ts");function F(e){return{id:e[0],token0:e[2][0],token1:e[2][1],order0:{y:e[3][0][0],z:e[3][0][1],A:e[3][0][2],B:e[3][0][3]},order1:{y:e[3][1][0],z:e[3][1][1],A:e[3][1][2],B:e[3][1][3]}}}function N(e,t){return function(n,a,r,i,o,u){E.debug(e+" fired with",arguments);var s={id:n,token0:r,token1:i,order0:{y:o.y,z:o.z,A:o.A,B:o.B},order1:{y:u.y,z:u.z,A:u.A,B:u.B}};E.debug(e+" parsed strategy:",s),t(s)}}var q=/*#__PURE__*/function(){function e(e){var t=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return k(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this._contracts=e}var t=e.prototype;return t.multicall=function(e,t){return function(e,t,n){return Promise.resolve(function(a,r){try{var i=(o=e.map(function(e){return{target:e.contractAddress.toLocaleLowerCase(),callData:e.interface.encodeFunctionData(e.methodName,e.methodParameters)}}),Promise.resolve(t.tryAggregate(!1,o,{blockTag:n})).then(function(t){return t.map(function(t,n){return t.success?e[n].interface.decodeFunctionResult(e[n].methodName,t.returnData):[]})}))}catch(e){return}var o;return i&&i.then?i.then(void 0,function(){}):i}())}(e,this._contracts.multicall,t)},t.getStrategyById=function(e){try{return Promise.resolve(this._contracts.carbonController.strategy(e)).then(F)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=function(e){try{return Promise.resolve(this._contracts.carbonController.strategiesByIds(e)).then(function(e){return e.map(function(e){return F(e)})})}catch(e){return Promise.reject(e)}},t.getAllTokenPairs=function(){return this._contracts.carbonController.pairs()},t.getStrategiesByTokenPair=function(e,t){try{return Promise.resolve(this._contracts.carbonController.strategiesByPool(e,t,0,0)).then(function(e){return e.map(function(e){return F(e)})})}catch(e){return Promise.reject(e)}},t.getStrategiesByTokenPairs=function(e){try{var t=this;return Promise.resolve(t.multicall(e.map(function(e){return{contractAddress:t._contracts.carbonController.address,interface:t._contracts.carbonController.interface,methodName:"strategiesByPool",methodParameters:[e[0],e[1],0,0]}}))).then(function(e){return e&&0!==e.length?e.map(function(e){return e[0].map(function(e){return F(e)})}):[]})}catch(e){return Promise.reject(e)}},t.getUserStrategyIds=function(e){try{var t=this;return e?Promise.resolve(t._contracts.voucher.balanceOf(e)).then(function(n){var a=Array.from(Array(n.toNumber()),function(n,a){return{contractAddress:t._contracts.voucher.address,interface:t._contracts.voucher.interface,methodName:"tokenOfOwnerByIndex",methodParameters:[e,a]}});return Promise.resolve(t.multicall(a)).then(function(e){return e?e.map(function(e){return e[0]}):[]})}):Promise.resolve([])}catch(e){return Promise.reject(e)}},t.tradingFeePPM=function(){return this._contracts.carbonController.tradingFeePPM()},t.onTradingFeePPMUpdated=function(e){return this._contracts.carbonController.on("TradingFeePPMUpdated",function(t,n){E.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",N("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",N("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",N("StrategyUpdated",e))},e}(),U=/*#__PURE__*/function(){function e(e){this._reader=void 0,this._composer=void 0;var t=new j(e);this._reader=new q(t),this._composer=new M(t)}return s(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),z=function(e,t){var n=e.output.mul(t.input),a=t.output.mul(e.input),r=n.lt(a),i=n.gt(a),o=!r&&!i;return+(r||o&&e.output.lt(t.output))-+(i||o&&e.output.gt(t.output))},L=function(e,t){return z(t,e)},H=t.BigNumber.from(0),G=t.BigNumber.from(2).pow(128).sub(1),W=function(e,t){var n=e,a=t.y,r=t.z,i=t.A,o=t.B,u=r.mul(T),s=a.mul(i).add(r.mul(o)),p=s.sub(n.mul(i)),y=function(e,t,n){return e.mul(t).add(n).sub(1).div(n)}(n.mul(u),u,s.mul(p));return y.lt(H)?G:y},Z=function(e,t){var n=function(e,t){var n=e,a=t.z,r=t.A,i=t.B,o=t.y.mul(r).add(a.mul(i)),u=o.mul(n).div(T),s=u.mul(r).add(a.mul(a).mul(T)),p=function(e,t,n){return e.mul(t).div(n)}(o,u,s);return p.gt(G)?H:p}(e,t),a=n.lt(t.y)?n:t.y;return{input:W(a,t),output:a}},K=function(e,t){var n=e.lt(t.y)?e:t.y;return{input:n,output:W(n,t)}},V=function(e,n,a,r,i){for(var o,u=[],s=d(Object.keys(n).map(function(t){return{id:t,rate:r(e,n[t])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,y=p.id,l=p.rate;if(!e.gt(l.input)){if(e.eq(l.input)){a(l)&&u.push({id:t.BigNumber.from(y),input:l.input,output:l.output});break}var c={input:e,output:r(e,n[y]).output};a(c)&&u.push({id:t.BigNumber.from(y),input:c.input,output:c.output});break}a(l)&&(u.push({id:t.BigNumber.from(y),input:l.input,output:l.output}),e=e.sub(l.input))}return u},J=function(e,t,n){return void 0===n&&(n=function(e){return!0}),V(e,t,n,Z,z)},$=function(e,t,n){return void 0===n&&(n=function(e){return!0}),V(e,t,n,K,L)},Q=/*#__PURE__*/function(){function e(){this._cachedDecimals=void 0,this._cachedDecimals=new Map}return e.init=function(t){e._fetcher=t,e.getInstance().cachedDecimals.clear()},e.getInstance=function(){if(!e._instance){if(!e._fetcher)throw new Error("Decimals has not been initialized with a fetcher function");e._instance=new e}return e._instance},e.prototype.fetchDecimals=function(t){try{var n=this,a=n._cachedDecimals.get(t);return void 0!==a?Promise.resolve(a):Promise.resolve(e._fetcher(t)).then(function(e){return n._cachedDecimals.set(t,a=e),a})}catch(e){return Promise.reject(e)}},s(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();Q._instance=void 0,Q._fetcher=void 0;var X=function(e){try{var t=arguments;Y.debug("formatStrategy called",t);var n=e.id,a=e.token0,r=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=Q.getInstance();return Promise.resolve(s.fetchDecimals(a)).then(function(e){return Promise.resolve(s.fetchDecimals(r)).then(function(t){var s=te(o.lowestRate,e,t),p=te(o.highestRate,e,t),y=ne(i.highestRate,t,e),d=ne(i.lowestRate,t,e),l=ie(i.liquidity,e),c=ie(o.liquidity,t);return Y.debug("formatStrategy info:",{id:n,token0:a,token1:r,order0:i,order1:o,decimals0:e,decimals1:t,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l}),{id:n,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l,encoded:u}})})}catch(e){return Promise.reject(e)}},Y=new P("friendlyUtils.ts");function ee(e,t,n,a,r,i,u,s){if(Y.debug("buildStrategyObject called",arguments),new o.default(n).isNegative()||new o.default(a).isNegative()||new o.default(i).isNegative()||new o.default(u).isNegative())throw new Error("prices cannot be negative");if(new o.default(n).gt(a)||new o.default(i).gt(u))throw new Error("low price must be lower than or equal to high price");if(new o.default(r).isNegative()||new o.default(s).isNegative())throw new Error("budgets cannot be negative");var p=ae(e.decimals,t.decimals,n,a,r,i,u,s),y=p.order0,d=p.order1;return Y.debug("buildStrategyObject info:",{token0:e.address,token1:t.address,order0:y,order1:d}),{token0:e.address,token1:t.address,order0:y,order1:d}}function te(e,t,n){return new o.default(e).times(v(t,n)).toFixed()}function ne(e,t,n){return 0==+e?"0":new o.default(1).div(e).times(v(n,t)).toFixed()}function ae(e,t,n,a,r,i,o,u){Y.debug("createOrders called",arguments);var s=re(u,e),p=ne(o,t,e),y=ne(i,t,e),d=re(r,t),l=te(n,t,e),c=te(a,t,e),m={liquidity:s,lowestRate:p,highestRate:y,marginalRate:y},f={liquidity:d,lowestRate:l,highestRate:c,marginalRate:c};return Y.debug("createOrders info:",{order0:m,order1:f}),{order0:m,order1:f}}function re(e,t){var n,a,i,o=(a=t,-1!==(i=(n=e).indexOf("."))?n.slice(0,i+a+1):n);return r.parseUnits(o,t).toString()}function ie(e,t){var n=r.formatUnits(e,t);return new o.default(n).toFixed()}var oe=1e6;function ue(e,t){return new o.default(e.toString()).mul(oe).div(oe-t).ceil()}function se(e,t){return new o.default(e.toString()).mul(oe-t).div(oe).floor()}var pe=function(e){return e.sqrt().mul(T)},ye=function(e){return e.div(T).pow(2)},de=function(e){var n=t.BigNumber.from(new o.default(e.liquidity).toFixed()),a=t.BigNumber.from(pe(new o.default(e.lowestRate)).floor().toFixed()),r=t.BigNumber.from(pe(new o.default(e.highestRate)).floor().toFixed()),i=t.BigNumber.from(pe(new o.default(e.marginalRate)).floor().toFixed());if(!(r.gte(i)&&i.gt(a)||r.eq(i)&&i.eq(a)))throw new Error("Invalid order: max must be greater than or equal to mid, and mid must be greater than min \n - or the three should be equal (highestRate: "+e.highestRate+", \n marginalRate: "+e.marginalRate+", lowestRate: "+e.lowestRate+")");var u=r.sub(a);return{y:n,z:u.isZero()?n:n.mul(u).div(i.sub(a)),A:u,B:a}},le=function(e){var t=new o.default(e.y.toString()),n=new o.default(e.z.toString()),a=new o.default(e.A.toString()),r=new o.default(e.B.toString()),i=t.eq(n)?new o.default(1):t.div(n);return{liquidity:t.toString(),lowestRate:ye(r).toString(),highestRate:ye(r.add(a)).toString(),marginalRate:ye(r.add(a.mul(i))).toString()}},ce=function(e){return{token0:e.token0,token1:e.token1,order0:de(e.order0),order1:de(e.order1)}},me=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:le(e.order0),order1:le(e.order1),encoded:e}};function fe(e){return e.reduce(function(e,t){return o.default.min(e,t.lowestRate)},new o.default(Infinity))}function ge(e){return e.reduce(function(e,t){return o.default.max(e,t.highestRate)},new o.default(-Infinity))}function be(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new o.default(e.liquidity);if(t.gte(e.marginalRate))return new o.default(0);var n=new o.default(e.liquidity),a=new o.default(e.lowestRate).sqrt(),r=new o.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(a)).div(r.sub(a)))}(n,t))},new o.default(0))}var Te=new P("index.ts"),he=/*#__PURE__*/function(){function n(t,n){this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,Te.debug("SDK class constructor called with",arguments);var a=new e.StaticJsonRpcProvider(t,1);this._api=new U(a),Q.init(null!=n?n:this._api.reader.getDecimalsByAddress)}var a=n.prototype;return a.startDataSync=function(){try{var e=this;return Te.debug("startDataSync called"),e._cache?(Te.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new b(e._api.reader),Promise.resolve(e._cache.init()).then(function(){return Promise.resolve(e._api.reader.tradingFeePPM()).then(function(t){e._tradingFeePPM=t,e._api.reader.onTradingFeePPMUpdated(function(t){Te.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),Te.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},a.hasLiquidityByPair=function(e,t){if(Te.debug("hasLiquidityByPair called",arguments),!this._cache)throw Te.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return Te.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},a.getLiquidityByPair=function(e,n){try{var a=arguments,r=this;if(Te.debug("getLiquidityByPair called",a),!r._cache)throw Te.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=r._cache.getOrders(e,n),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},t.BigNumber.from(0));return Promise.resolve(Q.getInstance().fetchDecimals(n)).then(function(e){var t=ie(o,e);return Te.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:n,decimals:e,liquidity:t}),t})}catch(e){return Promise.reject(e)}},a.getUserStrategies=function(e){try{var t=arguments,n=this;if(Te.debug("getUserStrategies called",t),!n._cache)throw Te.log("getUserStrategies called before startDataSync"),new Error("startDataSync must be called prior to this action");return Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){var t=e.map(function(e){var t;return null==(t=n._cache)?void 0:t.getStrategyById(e)}).filter(function(e){return!!e}),a=t.map(me);return Promise.resolve(Promise.all(a.map(function(e){try{return Promise.resolve(X(e))}catch(e){return Promise.reject(e)}}))).then(function(n){return Te.debug("getUserStrategies info:",{ids:e,encodedStrategies:t,decodedStrategies:a,strategies:n}),n})})}catch(e){return Promise.reject(e)}},a.getTradeData=function(e,n,a,r,i){try{var u=arguments,s=this;if(Te.debug("getTradeData called",u),!s._cache)throw Te.log("getTradeData called before startDataSync"),new Error("startDataSync must be called prior to this action");var p=Q.getInstance();return Promise.resolve(p.fetchDecimals(e)).then(function(u){return Promise.resolve(p.fetchDecimals(n)).then(function(p){var y,d=s._cache.getOrders(e,n),l=t.BigNumber.from(re(a,r?p:u));y=r?$(l,d,i):J(l,d,i);var c,m,f,g=[],b=[],T=t.BigNumber.from(0),h=t.BigNumber.from(0);if(y.forEach(function(e){g.push({strategyId:e.id,amount:e.input}),b.push({id:e.id,sourceAmount:ie(r?e.output:e.input,u),targetAmount:ie(r?e.input:e.output,p)}),h=h.add(e.input),T=T.add(e.output)}),null==s._tradingFeePPM)throw new Error("tradingFeePPM is undefined");if(r?(c=ue(T,s._tradingFeePPM),m=new o.default(h.toString())):(c=new o.default(h.toString()),m=se(T,s._tradingFeePPM)),c.isZero()||m.isZero())f={tradeActions:g,actionsTokenRes:b,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0"};else{var w=new o.default(m.toString()).div(c.toString()).times(v(u,p)).toString();f={tradeActions:g,actionsTokenRes:b,totalSourceAmount:ie(c.toFixed(0),u),totalTargetAmount:ie(m.toFixed(0),p),effectiveRate:w}}return Te.debug("getTradeData info:",{sourceDecimals:u,targetDecimals:p,orders:d,amount:a,amountWei:l,actionsWei:y,totalInput:h,totalOutput:T,tradingFeePPM:s._tradingFeePPM,res:f}),f})})}catch(e){return Promise.reject(e)}},a.composeTradeByTargetTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return Te.debug("composeTradeByTargetTransaction called",o),Promise.resolve(Q.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,a,re(r,o),i)})}catch(e){return Promise.reject(e)}},a.composeTradeBySourceTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return Te.debug("composeTradeBySourceTransaction called",o),Promise.resolve(Q.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,a,re(r,o),i)})}catch(e){return Promise.reject(e)}},a.createBuySellStrategy=function(e,t,n,a,r,i,o,u,s){Te.debug("createBuySellStrategy called",arguments);var p=ee(e,t,n,a,r,i,o,u),y=ce(p);return Te.debug("createBuySellStrategy info:",{strategy:p,encStrategy:y}),this._api.composer.createStrategy(y.token0,y.token1,y.order0,y.order1,s)},a.updateStrategy=function(e,n,a,r,i,o,u,s,p,y,d){try{var l=arguments,c=this;Te.debug("updateStrategy called",l);var m=ee(a,r,i,o,u,s,p,y),f=ce(m);return Te.debug("updateStrategy info:",{strategy:m,encStrategy:f}),Promise.resolve(c._api.composer.updateStrategy(t.BigNumber.from(e),[n.order0,n.order1],[f.order0,f.order1],d))}catch(e){return Promise.reject(e)}},a.deleteStrategy=function(e){return Te.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(t.BigNumber.from(e))},a.getRateLiquidityDepthByPair=function(e,t,n){try{var a=arguments,r=this;if(Te.debug("getRateLiquidityDepthByPair called",a),!r._cache)throw Te.log("getRateLiquidityDepthByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=Object.values(r._cache.getOrders(e,t)).map(le),u=Q.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(e){return Promise.resolve(u.fetchDecimals(t)).then(function(t){var a=te(n,t,e),r=be(i,new o.default(a)).toFixed(0),u=ie(r,t);return Te.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:r,targetDecimals:t,depthInTargetDecimals:u}),u})})}catch(e){return Promise.reject(e)}},a.getMinRateByPair=function(e,t){try{var n=arguments,a=this;if(Te.debug("getMinRateByPair called",n),!a._cache)throw Te.log("getMinRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(le),i=fe(r).toString(),o=Q.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=te(i,e,t);return Te.debug("getMinRateByPair info:",{orders:r,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getMaxRateByPair=function(e,t){try{var n=arguments,a=this;if(Te.debug("getMaxRateByPair called",n),!a._cache)throw Te.log("getMaxRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(le),i=ge(r).toString(),o=Q.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=te(i,e,t);return Te.debug("getMaxRateByPair info:",{orders:r,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},s(n,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(Te.debug("pairs called"),!this._cache)throw Te.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),n}();return he}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):(e||self).carbonSdk=t(e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,a,r){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/i(n);function u(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,"symbol"==typeof(r=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,"string");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(a.key))?r:String(r),a)}var r}function s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},p.apply(this,arguments)}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=function(e,t){return e.localeCompare(t)},c=function(e){if(2!==e.length)throw new Error("Invalid number of tokens: expected 2, got "+e.length);if(e[0]===e[1])throw new Error("Cannot create key for identical tokens: "+e[0])},m=function(e,t){return c([e,t]),[e,t].sort(l)},f=function(e,t){return c([e,t]),e+"-"+t},g=function(e,t,n){if(0!==n.size){var a,r;0===t?(a=e.order0,r=f(e.token1,e.token0)):(a=e.order1,r=f(e.token0,e.token1));var i,o=n.get(r);o?o[e.id.toString()]=a:(console.warn("Should not be here, modified order is supposed to already be cached"),n.set(r,((i={})[e.id.toString()]=a,i)))}},b=/*#__PURE__*/function(){function e(e){this._pairToStrategies=void 0,this._strategyById=void 0,this._fetcher=void 0,this._cachedOrders=void 0,this._fetcher=e,this._pairToStrategies=new Map,this._strategyById=new Map,this._cachedOrders=new Map}var t=e.prototype;return t.init=function(){try{var e=this;return Promise.resolve(function(e){try{return Promise.resolve(e.getAllTokenPairs()).then(function(t){return Promise.resolve(e.getStrategiesByTokenPairs(t)).then(function(e){for(var n=new Map,a=0;a<t.length;a++){var r=t[a],i=e[a],o=m(r[0],r[1]);n.set(o,i)}return n})})}catch(e){return Promise.reject(e)}}(e._fetcher)).then(function(t){e._pairToStrategies=t,e._fetcher.onStrategyCreated(function(t){return function(e,t,n,a){if(!n.has(e.id.toString())){n.set(e.id.toString(),e);var r=m(e.token0,e.token1);if(t.has(r)?t.get(r).push(e):t.set(r,[e]),0!==a.size)for(var i=[e.token0,e.token1],o=0,u=[i,i.reverse()];o<u.length;o++){var s,p=u[o],y=f(p[0],p[1]),d=p[0]===e.token0?e.order1:e.order0,l=a.get(y);l?l[e.id.toString()]=d:a.set(y,((s={})[e.id.toString()]=d,s))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders)}),e._fetcher.onStrategyUpdated(function(t){return function(e,t,n,a){n.set(e.id.toString(),e);var r=m(e.token0,e.token1);t.has(r)?t.set(r,t.get(r).map(function(t){return t.id===e.id?e:t})):t.set(r,[e]),g(e,0,a),g(e,1,a)}(t,e._pairToStrategies,e._strategyById,e._cachedOrders)}),e._fetcher.onStrategyDeleted(function(t){!function(e,t,n,a){if(n.has(e.id.toString())){n.delete(e.id.toString());var r=m(e.token0,e.token1);if(t.has(r)&&t.set(r,t.get(r).filter(function(t){return t.id!==e.id})),0===t.get(r).length&&t.delete(r),0!==a.size)for(var i=[e.token0,e.token1],o=0,u=[i,i.reverse()];o<u.length;o++){var s=u[o],p=f(s[0],s[1]),y=a.get(p);y&&(delete y[e.id.toString()],0===Object.keys(y).length&&a.delete(p))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders)});for(var n,a=d(e._pairToStrategies.values());!(n=a()).done;){var r=n.value;if(r&&r.length>0)for(var i=0;i<r.length;i++)e._strategyById.set(r[i].id.toString(),r[i])}})}catch(e){return Promise.reject(e)}},t.getOrders=function(e,t,n){var a;if(void 0===n&&(n=!1),0===this._pairToStrategies.size)return console.warn("getOrders was called when no strategies are cached, did you call init?"),{};0===this._cachedOrders.size&&function(e,t){t.clear();for(var n,a=d(e.values());!(n=a()).done;){var r=n.value;if(r.length>0){for(var i=r[0].token0,o=r[0].token1,u={},s={},p=0;p<r.length;p++)r[p].token0===i?(u[r[p].id.toString()]=r[p].order0,s[r[p].id.toString()]=r[p].order1):(u[r[p].id.toString()]=r[p].order1,s[r[p].id.toString()]=r[p].order0);t.set(f(i,o),s),t.set(f(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var r=f(e,t),i=null!=(a=this._cachedOrders.get(r))?a:{};if(n)return i;var o=Object.entries(i).filter(function(e){return e[1].y.gt(0)&&(e[1].A.gt(0)||e[1].B.gt(0))});return Object.fromEntries(o)},t.getStrategyById=function(e){return this._strategyById.get(e.toString())},s(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys())}}]),e}();o.default.set({precision:50,rounding:o.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var T=Math.pow(2,32),h=new o.default(10),v=function(e,t){return h.pow(e-t)},w="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),k=function(e){return e.toLowerCase()===w},_=function(e,n,a){var r=p({},a);return k(e)&&(r.value=n.reduce(function(e,t){return e.add(t.amount)},t.BigNumber.from(0))),r},P=/*#__PURE__*/function(){function e(e){this._prefix=void 0,this._prefix="[SDK]["+e+"]:"}var t=e.prototype;return t.log=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},t.debug=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),S=new P("Composer.ts"),M=/*#__PURE__*/function(){function e(e){this._contracts=void 0,this._contracts=e}var t=e.prototype;return t.tradeByTargetAmount=function(e,t,n,a,r,i){S.debug("tradeByTargetAmount called",arguments);var o=_(e,n,i);return S.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,a,r,o)},t.tradeBySourceAmount=function(e,t,n,a,r,i){S.debug("tradeBySourceAmount called",arguments);var o=_(e,n,i);return S.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,a,r,o)},t.createStrategy=function(e,t,n,a,r){S.debug("createStrategy called",arguments);var i=p({},r);return k(e)?i.value=n.y:k(t)&&(i.value=a.y),S.debug("createStrategy overrides",i),this._contracts.carbonController.populateTransaction.createStrategy(e,t,[n,a],i)},t.deleteStrategy=function(e){return this._contracts.carbonController.populateTransaction.deleteStrategy(e)},t.updateStrategy=function(e,t,n,a){return this._contracts.carbonController.populateTransaction.updateStrategy(e,t,n,a)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),B=[{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"previousAdmin",type:"address"},{indexed:!1,internalType:"address",name:"newAdmin",type:"address"}],name:"AdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"beacon",type:"address"}],name:"BeaconUpgraded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{stateMutability:"payable",type:"fallback"},{inputs:[],name:"admin",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"implementation",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"}],name:"upgradeTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"},{inputs:[],name:"AlreadyInitialized",type:"error"},{inputs:[],name:"DeadlineExpired",type:"error"},{inputs:[],name:"GreaterThanMaxInput",type:"error"},{inputs:[],name:"IdenticalAddresses",type:"error"},{inputs:[],name:"InsufficientCapacity",type:"error"},{inputs:[],name:"InvalidFee",type:"error"},{inputs:[],name:"InvalidIndices",type:"error"},{inputs:[],name:"InvalidStrategyId",type:"error"},{inputs:[],name:"InvalidTradeActionAmount",type:"error"},{inputs:[],name:"LowerThanMinReturn",type:"error"},{inputs:[],name:"NativeAmountMismatch",type:"error"},{inputs:[],name:"NoIdsProvided",type:"error"},{inputs:[],name:"OutDated",type:"error"},{inputs:[],name:"Overflow",type:"error"},{inputs:[],name:"PoolAlreadyExists",type:"error"},{inputs:[],name:"PoolDoesNotExists",type:"error"},{inputs:[],name:"StrategyDoesNotExist",type:"error"},{inputs:[],name:"TokensMismatch",type:"error"},{inputs:[],name:"UnknownDelegator",type:"error"},{inputs:[],name:"UnnecessaryNativeTokenReceived",type:"error"},{inputs:[],name:"UnsetDelegator",type:"error"},{inputs:[],name:"ZeroLiquidityProvided",type:"error"},{inputs:[],name:"ZeroValue",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"poolId",type:"uint256"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"}],name:"PoolCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyDeleted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"trader",type:"address"},{indexed:!0,internalType:"address",name:"sourceToken",type:"address"},{indexed:!0,internalType:"address",name:"targetToken",type:"address"},{indexed:!1,internalType:"uint256",name:"sourceAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"targetAmount",type:"uint256"},{indexed:!1,internalType:"uint128",name:"tradingFeeAmount",type:"uint128"},{indexed:!1,internalType:"bool",name:"byTargetAmount",type:"bool"}],name:"TokensTraded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"prevFeePPM",type:"uint32"},{indexed:!1,internalType:"uint32",name:"newFeePPM",type:"uint32"}],name:"TradingFeePPMUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"accumulatedFees",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"controllerType",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"createPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],name:"createStrategy",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"deleteStrategy",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pairs",outputs:[{internalType:"address[2][]",name:"",type:"address[2][]"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"pool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"}],name:"postUpgrade",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"roleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[],name:"roleEmergencyStopper",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint32",name:"newTradingFeePPM",type:"uint32"}],name:"setTradingFeePPM",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256[]",name:"ids",type:"uint256[]"}],name:"strategiesByIds",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"endIndex",type:"uint256"}],name:"strategiesByPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"strategiesByPoolCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"}],name:"strategy",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"minReturn",type:"uint128"}],name:"tradeBySourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"maxInput",type:"uint128"}],name:"tradeByTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeSourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"tradingFeePPM",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"currentOrders",type:"tuple[2]"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"newOrders",type:"tuple[2]"}],name:"updateStrategy",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"address",name:"newOwner",type:"address"}],name:"updateStrategyOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"logic",type:"address"},{internalType:"address",name:"initAdmin",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],x=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(B)},e.connect=function(e,t){return new a.Contract(e,B,t)},e}();x.abi=B;var A=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"blockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBlockNumber",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockCoinbase",outputs:[{internalType:"address",name:"coinbase",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockDifficulty",outputs:[{internalType:"uint256",name:"difficulty",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockGasLimit",outputs:[{internalType:"uint256",name:"gaslimit",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"}],name:"getEthBalance",outputs:[{internalType:"uint256",name:"balance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryAggregate",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryBlockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"view",type:"function"}],I=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(A)},e.connect=function(e,t){return new a.Contract(e,A,t)},e}();I.abi=A;var D=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_spender",type:"address"},{name:"_value",type:"uint256"}],name:"approve",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_disable",type:"bool"}],name:"disableTransfers",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transferFrom",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"version",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"standard",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_token",type:"address"},{name:"_to",type:"address"},{name:"_amount",type:"uint256"}],name:"withdrawTokens",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[],name:"acceptOwnership",outputs:[],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_amount",type:"uint256"}],name:"issue",outputs:[],payable:!1,type:"function"},{constant:!0,inputs:[],name:"owner",outputs:[{name:"",type:"address"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"symbol",outputs:[{name:"",type:"string"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_from",type:"address"},{name:"_amount",type:"uint256"}],name:"destroy",outputs:[],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_to",type:"address"},{name:"_value",type:"uint256"}],name:"transfer",outputs:[{name:"success",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"transfersEnabled",outputs:[{name:"",type:"bool"}],payable:!1,type:"function"},{constant:!0,inputs:[],name:"newOwner",outputs:[{name:"",type:"address"}],payable:!1,type:"function"},{constant:!0,inputs:[{name:"",type:"address"},{name:"",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],payable:!1,type:"function"},{constant:!1,inputs:[{name:"_newOwner",type:"address"}],name:"transferOwnership",outputs:[],payable:!1,type:"function"},{inputs:[{name:"_name",type:"string"},{name:"_symbol",type:"string"},{name:"_decimals",type:"uint8"}],payable:!1,type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,name:"_token",type:"address"}],name:"NewSmartToken",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_amount",type:"uint256"}],name:"Issuance",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_amount",type:"uint256"}],name:"Destruction",type:"event"},{anonymous:!1,inputs:[{indexed:!1,name:"_prevOwner",type:"address"},{indexed:!1,name:"_newOwner",type:"address"}],name:"OwnerUpdate",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"_from",type:"address"},{indexed:!0,name:"_to",type:"address"},{indexed:!1,name:"_value",type:"uint256"}],name:"Transfer",type:"event"},{anonymous:!1,inputs:[{indexed:!0,name:"_owner",type:"address"},{indexed:!0,name:"_spender",type:"address"},{indexed:!1,name:"_value",type:"uint256"}],name:"Approval",type:"event"}],O=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(D)},e.connect=function(e,t){return new a.Contract(e,D,t)},e}();O.abi=D;var R=[{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"},{internalType:"string",name:"newBaseURI",type:"string"},{internalType:"string",name:"newBaseExtension",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"CarbonControllerNotSet",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"approved",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"operator",type:"address"},{indexed:!1,internalType:"bool",name:"approved",type:"bool"}],name:"ApprovalForAll",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"approve",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"getApproved",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"operator",type:"address"}],name:"isApprovedForAll",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"provider",type:"address"},{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"ownerOf",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"operator",type:"address"},{internalType:"bool",name:"approved",type:"bool"}],name:"setApprovalForAll",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseExtension",type:"string"}],name:"setBaseExtension",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseURI",type:"string"}],name:"setBaseURI",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract CarbonController",name:"carbonController",type:"address"}],name:"setCarbonController",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenOfOwnerByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"tokenURI",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"transferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"}],name:"useGlobalURI",outputs:[],stateMutability:"nonpayable",type:"function"}],C=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(R)},e.connect=function(e,t){return new a.Contract(e,R,t)},e}();C.abi=R;var j=/*#__PURE__*/function(){function e(e){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._provider=e}return e.prototype.token=function(e){return O.connect(e,this._provider)},s(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=x.connect("0x483309B60A7f5A097aE09Cf5811773431a9E8d1B",this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=I.connect("0x5ba1e12693dc8f9c48aad8770482f4739beed696",this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=C.connect("0x2fB666c75ec98462852c66D4981e1B3a0E668593",this._provider)),this._voucher}}]),e}(),E=new P("Reader.ts");function F(e){return{id:e[0],token0:e[2][0],token1:e[2][1],order0:{y:e[3][0][0],z:e[3][0][1],A:e[3][0][2],B:e[3][0][3]},order1:{y:e[3][1][0],z:e[3][1][1],A:e[3][1][2],B:e[3][1][3]}}}function N(e,t){return function(n,a,r,i,o,u){E.debug(e+" fired with",arguments);var s={id:n,token0:r,token1:i,order0:{y:o.y,z:o.z,A:o.A,B:o.B},order1:{y:u.y,z:u.z,A:u.A,B:u.B}};E.debug(e+" parsed strategy:",s),t(s)}}var q=/*#__PURE__*/function(){function e(e){var t=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return k(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this._contracts=e}var t=e.prototype;return t.multicall=function(e,t){return function(e,t,n){return Promise.resolve(function(a,r){try{var i=(o=e.map(function(e){return{target:e.contractAddress.toLocaleLowerCase(),callData:e.interface.encodeFunctionData(e.methodName,e.methodParameters)}}),Promise.resolve(t.tryAggregate(!1,o,{blockTag:n})).then(function(t){return t.map(function(t,n){return t.success?e[n].interface.decodeFunctionResult(e[n].methodName,t.returnData):[]})}))}catch(e){return}var o;return i&&i.then?i.then(void 0,function(){}):i}())}(e,this._contracts.multicall,t)},t.getStrategyById=function(e){try{return Promise.resolve(this._contracts.carbonController.strategy(e)).then(F)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=function(e){try{return Promise.resolve(this._contracts.carbonController.strategiesByIds(e)).then(function(e){return e.map(function(e){return F(e)})})}catch(e){return Promise.reject(e)}},t.getAllTokenPairs=function(){return this._contracts.carbonController.pairs()},t.getStrategiesByTokenPair=function(e,t){try{return Promise.resolve(this._contracts.carbonController.strategiesByPool(e,t,0,0)).then(function(e){return e.map(function(e){return F(e)})})}catch(e){return Promise.reject(e)}},t.getStrategiesByTokenPairs=function(e){try{var t=this;return Promise.resolve(t.multicall(e.map(function(e){return{contractAddress:t._contracts.carbonController.address,interface:t._contracts.carbonController.interface,methodName:"strategiesByPool",methodParameters:[e[0],e[1],0,0]}}))).then(function(e){return e&&0!==e.length?e.map(function(e){return e[0].map(function(e){return F(e)})}):[]})}catch(e){return Promise.reject(e)}},t.getUserStrategyIds=function(e){try{var t=this;return e?Promise.resolve(t._contracts.voucher.balanceOf(e)).then(function(n){var a=Array.from(Array(n.toNumber()),function(n,a){return{contractAddress:t._contracts.voucher.address,interface:t._contracts.voucher.interface,methodName:"tokenOfOwnerByIndex",methodParameters:[e,a]}});return Promise.resolve(t.multicall(a)).then(function(e){return e?e.map(function(e){return e[0]}):[]})}):Promise.resolve([])}catch(e){return Promise.reject(e)}},t.tradingFeePPM=function(){return this._contracts.carbonController.tradingFeePPM()},t.onTradingFeePPMUpdated=function(e){return this._contracts.carbonController.on("TradingFeePPMUpdated",function(t,n){E.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",N("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",N("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",N("StrategyUpdated",e))},e}(),U=/*#__PURE__*/function(){function e(e){this._reader=void 0,this._composer=void 0;var t=new j(e);this._reader=new q(t),this._composer=new M(t)}return s(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),z=function(e,t){var n=e.output.mul(t.input),a=t.output.mul(e.input),r=n.lt(a),i=n.gt(a),o=!r&&!i;return+(r||o&&e.output.lt(t.output))-+(i||o&&e.output.gt(t.output))},L=function(e,t){return z(t,e)},H=t.BigNumber.from(0),G=t.BigNumber.from(2).pow(128).sub(1),W=function(e,t){var n=e,a=t.y,r=t.z,i=t.A,o=t.B,u=r.mul(T),s=a.mul(i).add(r.mul(o)),p=s.sub(n.mul(i)),y=function(e,t,n){return e.mul(t).add(n).sub(1).div(n)}(n.mul(u),u,s.mul(p));return y.lt(H)?G:y},Z=function(e,t){var n=function(e,t){var n=e,a=t.z,r=t.A,i=t.B,o=t.y.mul(r).add(a.mul(i)),u=o.mul(n).div(T),s=u.mul(r).add(a.mul(a).mul(T)),p=function(e,t,n){return e.mul(t).div(n)}(o,u,s);return p.gt(G)?H:p}(e,t),a=n.lt(t.y)?n:t.y;return{input:W(a,t),output:a}},K=function(e,t){var n=e.lt(t.y)?e:t.y;return{input:n,output:W(n,t)}},V=function(e,n,a,r,i){for(var o,u=[],s=d(Object.keys(n).map(function(t){return{id:t,rate:r(e,n[t])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,y=p.id,l=p.rate;if(!e.gt(l.input)){if(e.eq(l.input)){a(l)&&u.push({id:t.BigNumber.from(y),input:l.input,output:l.output});break}var c={input:e,output:r(e,n[y]).output};a(c)&&u.push({id:t.BigNumber.from(y),input:c.input,output:c.output});break}a(l)&&(u.push({id:t.BigNumber.from(y),input:l.input,output:l.output}),e=e.sub(l.input))}return u},J=function(e,t,n){return void 0===n&&(n=function(e){return!0}),V(e,t,n,Z,z)},$=function(e,t,n){return void 0===n&&(n=function(e){return!0}),V(e,t,n,K,L)},Q=/*#__PURE__*/function(){function e(){this._cachedDecimals=void 0,this._cachedDecimals=new Map}return e.init=function(t){e._fetcher=t,e.getInstance().cachedDecimals.clear()},e.getInstance=function(){if(!e._instance){if(!e._fetcher)throw new Error("Decimals has not been initialized with a fetcher function");e._instance=new e}return e._instance},e.prototype.fetchDecimals=function(t){try{var n=this,a=n._cachedDecimals.get(t);return void 0!==a?Promise.resolve(a):Promise.resolve(e._fetcher(t)).then(function(e){return n._cachedDecimals.set(t,a=e),a})}catch(e){return Promise.reject(e)}},s(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();Q._instance=void 0,Q._fetcher=void 0;var X=function(e){try{var t=arguments;Y.debug("formatStrategy called",t);var n=e.id,a=e.token0,r=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=Q.getInstance();return Promise.resolve(s.fetchDecimals(a)).then(function(e){return Promise.resolve(s.fetchDecimals(r)).then(function(t){var s=te(o.lowestRate,e,t),p=te(o.highestRate,e,t),y=ne(i.highestRate,t,e),d=ne(i.lowestRate,t,e),l=ie(i.liquidity,e),c=ie(o.liquidity,t);return Y.debug("formatStrategy info:",{id:n,token0:a,token1:r,order0:i,order1:o,decimals0:e,decimals1:t,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l}),{id:n,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l,encoded:u}})})}catch(e){return Promise.reject(e)}},Y=new P("friendlyUtils.ts");function ee(e,t,n,a,r,i,u,s){if(Y.debug("buildStrategyObject called",arguments),new o.default(n).isNegative()||new o.default(a).isNegative()||new o.default(i).isNegative()||new o.default(u).isNegative())throw new Error("prices cannot be negative");if(new o.default(n).gt(a)||new o.default(i).gt(u))throw new Error("low price must be lower than or equal to high price");if(new o.default(r).isNegative()||new o.default(s).isNegative())throw new Error("budgets cannot be negative");var p=ae(e.decimals,t.decimals,n,a,r,i,u,s),y=p.order0,d=p.order1;return Y.debug("buildStrategyObject info:",{token0:e.address,token1:t.address,order0:y,order1:d}),{token0:e.address,token1:t.address,order0:y,order1:d}}function te(e,t,n){return new o.default(e).times(v(t,n)).toFixed()}function ne(e,t,n){return 0==+e?"0":new o.default(1).div(e).times(v(n,t)).toFixed()}function ae(e,t,n,a,r,i,o,u){Y.debug("createOrders called",arguments);var s=re(u,e),p=ne(o,t,e),y=ne(i,t,e),d=re(r,t),l=te(n,t,e),c=te(a,t,e),m={liquidity:s,lowestRate:p,highestRate:y,marginalRate:y},f={liquidity:d,lowestRate:l,highestRate:c,marginalRate:c};return Y.debug("createOrders info:",{order0:m,order1:f}),{order0:m,order1:f}}function re(e,t){var n,a,i,o=(a=t,-1!==(i=(n=e).indexOf("."))?n.slice(0,i+a+1):n);return r.parseUnits(o,t).toString()}function ie(e,t){var n=r.formatUnits(e,t);return new o.default(n).toFixed()}var oe=1e6;function ue(e,t){return new o.default(e.toString()).mul(oe).div(oe-t).ceil()}function se(e,t){return new o.default(e.toString()).mul(oe-t).div(oe).floor()}var pe=function(e){return e.sqrt().mul(T)},ye=function(e){return e.div(T).pow(2)},de=function(e){var n=t.BigNumber.from(new o.default(e.liquidity).toFixed()),a=t.BigNumber.from(pe(new o.default(e.lowestRate)).floor().toFixed()),r=t.BigNumber.from(pe(new o.default(e.highestRate)).floor().toFixed()),i=t.BigNumber.from(pe(new o.default(e.marginalRate)).floor().toFixed());if(!(r.gte(i)&&i.gt(a)||r.eq(i)&&i.eq(a)))throw new Error("Invalid order: max must be greater than or equal to mid, and mid must be greater than min \n - or the three should be equal (highestRate: "+e.highestRate+", \n marginalRate: "+e.marginalRate+", lowestRate: "+e.lowestRate+")");var u=r.sub(a);return{y:n,z:u.isZero()?n:n.mul(u).div(i.sub(a)),A:u,B:a}},le=function(e){var t=new o.default(e.y.toString()),n=new o.default(e.z.toString()),a=new o.default(e.A.toString()),r=new o.default(e.B.toString()),i=t.eq(n)?new o.default(1):t.div(n);return{liquidity:t.toString(),lowestRate:ye(r).toString(),highestRate:ye(r.add(a)).toString(),marginalRate:ye(r.add(a.mul(i))).toString()}},ce=function(e){return{token0:e.token0,token1:e.token1,order0:de(e.order0),order1:de(e.order1)}},me=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:le(e.order0),order1:le(e.order1),encoded:e}};function fe(e){return e.reduce(function(e,t){return o.default.min(e,t.lowestRate)},new o.default(Infinity))}function ge(e){return e.reduce(function(e,t){return o.default.max(e,t.highestRate)},new o.default(-Infinity))}function be(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new o.default(e.liquidity);if(t.gte(e.marginalRate))return new o.default(0);var n=new o.default(e.liquidity),a=new o.default(e.lowestRate).sqrt(),r=new o.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(a)).div(r.sub(a)))}(n,t))},new o.default(0))}var Te=new P("index.ts"),he=/*#__PURE__*/function(){function n(t,n){this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,Te.debug("SDK class constructor called with",arguments);var a=new e.StaticJsonRpcProvider(t,1);this._api=new U(a),Q.init(null!=n?n:this._api.reader.getDecimalsByAddress)}var a=n.prototype;return a.startDataSync=function(){try{var e=this;return Te.debug("startDataSync called"),e._cache?(Te.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new b(e._api.reader),Promise.resolve(e._cache.init()).then(function(){return Promise.resolve(e._api.reader.tradingFeePPM()).then(function(t){e._tradingFeePPM=t,e._api.reader.onTradingFeePPMUpdated(function(t){Te.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),Te.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},a.hasLiquidityByPair=function(e,t){if(Te.debug("hasLiquidityByPair called",arguments),!this._cache)throw Te.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return Te.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},a.getLiquidityByPair=function(e,n){try{var a=arguments,r=this;if(Te.debug("getLiquidityByPair called",a),!r._cache)throw Te.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=r._cache.getOrders(e,n),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},t.BigNumber.from(0));return Promise.resolve(Q.getInstance().fetchDecimals(n)).then(function(e){var t=ie(o,e);return Te.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:n,decimals:e,liquidity:t}),t})}catch(e){return Promise.reject(e)}},a.getUserStrategies=function(e){try{var t=arguments,n=this;if(Te.debug("getUserStrategies called",t),!n._cache)throw Te.log("getUserStrategies called before startDataSync"),new Error("startDataSync must be called prior to this action");return Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){var t=e.map(function(e){var t;return null==(t=n._cache)?void 0:t.getStrategyById(e)}).filter(function(e){return!!e}),a=t.map(me);return Promise.resolve(Promise.all(a.map(function(e){try{return Promise.resolve(X(e))}catch(e){return Promise.reject(e)}}))).then(function(n){return Te.debug("getUserStrategies info:",{ids:e,encodedStrategies:t,decodedStrategies:a,strategies:n}),n})})}catch(e){return Promise.reject(e)}},a.getTradeData=function(e,n,a,r,i){try{var u=arguments,s=this;if(Te.debug("getTradeData called",u),!s._cache)throw Te.log("getTradeData called before startDataSync"),new Error("startDataSync must be called prior to this action");var p=Q.getInstance();return Promise.resolve(p.fetchDecimals(e)).then(function(u){return Promise.resolve(p.fetchDecimals(n)).then(function(p){var y,d=s._cache.getOrders(e,n),l=t.BigNumber.from(re(a,r?p:u));y=r?$(l,d,i):J(l,d,i);var c,m,f,g=[],b=[],T=t.BigNumber.from(0),h=t.BigNumber.from(0);if(y.forEach(function(e){g.push({strategyId:e.id,amount:e.input}),b.push({id:e.id,sourceAmount:ie(r?e.output:e.input,u),targetAmount:ie(r?e.input:e.output,p)}),h=h.add(e.input),T=T.add(e.output)}),null==s._tradingFeePPM)throw new Error("tradingFeePPM is undefined");if(r?(c=ue(T,s._tradingFeePPM),m=new o.default(h.toString())):(c=new o.default(h.toString()),m=se(T,s._tradingFeePPM)),c.isZero()||m.isZero())f={tradeActions:g,actionsTokenRes:b,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0"};else{var w=new o.default(m.toString()).div(c.toString()).times(v(u,p)).toString();f={tradeActions:g,actionsTokenRes:b,totalSourceAmount:ie(c.toFixed(0),u),totalTargetAmount:ie(m.toFixed(0),p),effectiveRate:w}}return Te.debug("getTradeData info:",{sourceDecimals:u,targetDecimals:p,orders:d,amount:a,amountWei:l,actionsWei:y,totalInput:h,totalOutput:T,tradingFeePPM:s._tradingFeePPM,res:f}),f})})}catch(e){return Promise.reject(e)}},a.composeTradeByTargetTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return Te.debug("composeTradeByTargetTransaction called",o),Promise.resolve(Q.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,a,re(r,o),i)})}catch(e){return Promise.reject(e)}},a.composeTradeBySourceTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return Te.debug("composeTradeBySourceTransaction called",o),Promise.resolve(Q.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,a,re(r,o),i)})}catch(e){return Promise.reject(e)}},a.createBuySellStrategy=function(e,t,n,a,r,i,o,u,s){Te.debug("createBuySellStrategy called",arguments);var p=ee(e,t,n,a,r,i,o,u),y=ce(p);return Te.debug("createBuySellStrategy info:",{strategy:p,encStrategy:y}),this._api.composer.createStrategy(y.token0,y.token1,y.order0,y.order1,s)},a.updateStrategy=function(e,n,a,r,i,o,u,s,p,y,d){try{var l=arguments,c=this;Te.debug("updateStrategy called",l);var m=ee(a,r,i,o,u,s,p,y),f=ce(m);return Te.debug("updateStrategy info:",{strategy:m,encStrategy:f}),Promise.resolve(c._api.composer.updateStrategy(t.BigNumber.from(e),[n.order0,n.order1],[f.order0,f.order1],d))}catch(e){return Promise.reject(e)}},a.deleteStrategy=function(e){return Te.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(t.BigNumber.from(e))},a.getRateLiquidityDepthByPair=function(e,t,n){try{var a=arguments,r=this;if(Te.debug("getRateLiquidityDepthByPair called",a),!r._cache)throw Te.log("getRateLiquidityDepthByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=Object.values(r._cache.getOrders(e,t)).map(le),u=Q.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(e){return Promise.resolve(u.fetchDecimals(t)).then(function(t){var a=te(n,t,e),r=be(i,new o.default(a)).toFixed(0),u=ie(r,t);return Te.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:r,targetDecimals:t,depthInTargetDecimals:u}),u})})}catch(e){return Promise.reject(e)}},a.getMinRateByPair=function(e,t){try{var n=arguments,a=this;if(Te.debug("getMinRateByPair called",n),!a._cache)throw Te.log("getMinRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(le),i=fe(r).toString(),o=Q.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=te(i,e,t);return Te.debug("getMinRateByPair info:",{orders:r,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getMaxRateByPair=function(e,t){try{var n=arguments,a=this;if(Te.debug("getMaxRateByPair called",n),!a._cache)throw Te.log("getMaxRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(le),i=ge(r).toString(),o=Q.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=te(i,e,t);return Te.debug("getMaxRateByPair info:",{orders:r,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},s(n,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(Te.debug("pairs called"),!this._cache)throw Te.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),n}();return he}); | ||
//# sourceMappingURL=sdk.umd.js.map |
@@ -5,3 +5,3 @@ { | ||
"source": "src/index.ts", | ||
"version": "0.0.39-DEV", | ||
"version": "0.0.40-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", | ||
@@ -8,0 +8,0 @@ "main": "dist/sdk.umd.js", |
@@ -76,2 +76,48 @@ import { EncodedOrder, EncodedStrategy, TokenPair } from '../types'; | ||
export const removeDeletedStrategyFromCache = ( | ||
strategy: EncodedStrategy, | ||
pairToStrategies: PairToStrategiesMap, | ||
strategyById: StrategyById, | ||
ordersCache: PairToDirectedOrdersMap | ||
): void => { | ||
if (!strategyById.has(strategy.id.toString())) { | ||
return; | ||
} | ||
strategyById.delete(strategy.id.toString()); | ||
// Remove the strategy from the pairToStrategies map | ||
const pairId = toPairKey(strategy.token0, strategy.token1); | ||
if (pairToStrategies.has(pairId)) { | ||
pairToStrategies.set( | ||
pairId, | ||
pairToStrategies.get(pairId)!.filter((s) => s.id !== strategy.id) | ||
); | ||
} | ||
// if it was the last strategy for this pair, remove the pair from the map | ||
if (pairToStrategies.get(pairId)!.length === 0) { | ||
pairToStrategies.delete(pairId); | ||
} | ||
// ordersCache is lazy - if it wasn't populated let's skip | ||
if (ordersCache.size === 0) { | ||
return; | ||
} | ||
// remove the strategy's orders from the orders cache | ||
const tokens = [strategy.token0, strategy.token1]; | ||
for (const tokenOrder of [tokens, tokens.reverse()]) { | ||
// Include the order of the tokens in the cache key | ||
const cacheKey = toDirectionKey(tokenOrder[0], tokenOrder[1]); | ||
// find orders with this strategy ID and remove them. If there are no more orders clear the cache key | ||
const orders = ordersCache.get(cacheKey); | ||
if (orders) { | ||
delete orders[strategy.id.toString()]; | ||
if (Object.keys(orders).length === 0) { | ||
ordersCache.delete(cacheKey); | ||
} | ||
} | ||
} | ||
}; | ||
export const addNewStrategyToMap = ( | ||
@@ -123,47 +169,32 @@ strategy: EncodedStrategy, | ||
export const applyModifiedOrderToCache = ( | ||
strategyId: BigNumber, | ||
strategy: EncodedStrategy, | ||
orderIndex: number, | ||
order: EncodedOrder, | ||
pairToStrategies: PairToStrategiesMap, | ||
strategyById: StrategyById, | ||
ordersCache: PairToDirectedOrdersMap | ||
): void => { | ||
// Find the strategy with the given id in the pairToStrategies map | ||
for (const [pairId, strategies] of pairToStrategies.entries()) { | ||
for (let i = 0; i < strategies.length; i++) { | ||
if (strategies[i].id === strategyId) { | ||
// Update the strategy with the modified order | ||
strategies[i][orderIndex === 0 ? 'order0' : 'order1'] = order; | ||
// ordersCache is lazy - if it wasn't populated let's skip | ||
if (ordersCache.size === 0) { | ||
return; | ||
} | ||
strategyById.set(strategyId.toString(), strategies[i]); | ||
// find order in the ordersCache and update it | ||
let order, cacheKey; | ||
if (orderIndex === 0) { | ||
order = strategy.order0; | ||
cacheKey = toDirectionKey(strategy.token1, strategy.token0); | ||
} else { | ||
order = strategy.order1; | ||
cacheKey = toDirectionKey(strategy.token0, strategy.token1); | ||
} | ||
// ordersCache is lazy - if it wasn't populated let's skip | ||
if (ordersCache.size === 0) { | ||
return; | ||
} | ||
// If order0 was updated, we need to cache it under token1-token0 and vice versa | ||
const tokens = [strategies[i].token0, strategies[i].token1]; | ||
if (orderIndex === 0) { | ||
tokens.reverse(); | ||
} | ||
// Include the order of the tokens in the cache key | ||
const cacheKey = toDirectionKey(tokens[0], tokens[1]); | ||
const existingOrders = ordersCache.get(cacheKey); | ||
// Check if there are already cached orders for the given token pair (there should be) | ||
if (existingOrders) { | ||
// Update the ordersCache map with the modified orders | ||
existingOrders[strategies[i].id.toString()] = order; | ||
} else { | ||
// We shouldn't get here. If the order was modified it was already cached. | ||
console.warn( | ||
'Should not be here, modified order is supposed to already be cached' | ||
); | ||
ordersCache.set(cacheKey, { [strategies[i].id.toString()]: order }); | ||
} | ||
return; | ||
} | ||
} | ||
const existingOrders = ordersCache.get(cacheKey); | ||
// Check if there are already cached orders for the given token pair (there should be) | ||
if (existingOrders) { | ||
// Update the ordersCache map with the modified orders | ||
existingOrders[strategy.id.toString()] = order; | ||
} else { | ||
// We shouldn't get here. If the order was modified it was already cached. | ||
console.warn( | ||
'Should not be here, modified order is supposed to already be cached' | ||
); | ||
ordersCache.set(cacheKey, { [strategy.id.toString()]: order }); | ||
} | ||
@@ -178,19 +209,19 @@ }; | ||
): void => { | ||
// We actually only care about the orders so... | ||
applyModifiedOrderToCache( | ||
strategy.id, | ||
0, | ||
strategy.order0, | ||
pairToStrategies, | ||
strategyById, | ||
ordersCache | ||
); | ||
applyModifiedOrderToCache( | ||
strategy.id, | ||
1, | ||
strategy.order1, | ||
pairToStrategies, | ||
strategyById, | ||
ordersCache | ||
); | ||
strategyById.set(strategy.id.toString(), strategy); | ||
// add or overwrite the strategy in the pairToStrategies map | ||
const pairId = toPairKey(strategy.token0, strategy.token1); | ||
if (!pairToStrategies.has(pairId)) { | ||
pairToStrategies.set(pairId, [strategy]); | ||
} else { | ||
pairToStrategies.set( | ||
pairId, | ||
pairToStrategies | ||
.get(pairId)! | ||
.map((s) => (s.id === strategy.id ? strategy : s)) | ||
); | ||
} | ||
applyModifiedOrderToCache(strategy, 0, ordersCache); | ||
applyModifiedOrderToCache(strategy, 1, ordersCache); | ||
}; |
@@ -9,2 +9,3 @@ import { BigNumber } from '../numerics'; | ||
applyModifiedStrategyToCache, | ||
removeDeletedStrategyFromCache, | ||
} from './cache-ops'; | ||
@@ -50,2 +51,10 @@ import { | ||
); | ||
this._fetcher.onStrategyDeleted((strategy: EncodedStrategy) => { | ||
removeDeletedStrategyFromCache( | ||
strategy, | ||
this._pairToStrategies, | ||
this._strategyById, | ||
this._cachedOrders | ||
); | ||
}); | ||
@@ -52,0 +61,0 @@ for (const strategies of this._pairToStrategies.values()) { |
@@ -9,2 +9,3 @@ import { OrdersMap } from '../match'; | ||
onStrategyUpdated(listener: (strategy: EncodedStrategy) => void): void; | ||
onStrategyDeleted(listener: (strategy: EncodedStrategy) => void): void; | ||
} | ||
@@ -11,0 +12,0 @@ |
@@ -178,4 +178,2 @@ import { BigNumber } from '../numerics'; | ||
// TODO: DRY parsing event strategy | ||
public onStrategyDeleted(listener: (strategy: EncodedStrategy) => void) { | ||
@@ -182,0 +180,0 @@ return this._contracts.carbonController.on( |
@@ -28,2 +28,3 @@ import { assert, expect } from 'chai'; | ||
onStrategyUpdated: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
onStrategyDeleted: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
}; | ||
@@ -47,2 +48,3 @@ | ||
onStrategyUpdated: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
onStrategyDeleted: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
}; | ||
@@ -63,2 +65,3 @@ | ||
onStrategyUpdated: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
onStrategyDeleted: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
}; | ||
@@ -109,2 +112,3 @@ | ||
onStrategyUpdated: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
onStrategyDeleted: (listener: (strategy: EncodedStrategy) => void) => {}, | ||
}; | ||
@@ -180,131 +184,12 @@ | ||
// Initialize the pairToStrategies map and ordersCache map | ||
const pairToStrategies: PairToStrategiesMap = new Map(); | ||
const strategyById: StrategyById = new Map(); | ||
// Initialize the ordersCache map | ||
const ordersCache = new Map<string, OrdersMap>(); | ||
// Add the sample strategy to the pairToStrategies map | ||
const pairId = [strategy.token0, strategy.token1] as TokenPair; | ||
pairToStrategies.set(pairId, [strategy]); | ||
strategyById.set(strategy.id.toString(), strategy); | ||
// Call the onOrderModified function with the sample strategy id, order index, and order | ||
applyModifiedOrderToCache( | ||
strategy.id, | ||
0, | ||
order, | ||
pairToStrategies, | ||
strategyById, | ||
ordersCache | ||
); | ||
applyModifiedOrderToCache(strategy, 0, ordersCache); | ||
// Check that the strategy and orders cache were updated correctly | ||
expect(pairToStrategies.get(pairId)![0].order0).to.deep.equal(order); | ||
expect(ordersCache.get(`${strategy.token0}-${strategy.token1}`)).to.be | ||
.undefined; | ||
}); | ||
it('should not update the cache if the strategy with the given id is not found', () => { | ||
// Create a sample Strategy and Order objects | ||
const strategy = { | ||
id: BigNumber.from('123456'), | ||
token0: 'token0', | ||
token1: 'token1', | ||
order0: { | ||
y: BigNumber.from('1'), | ||
z: BigNumber.from('2'), | ||
A: BigNumber.from('3'), | ||
B: BigNumber.from('4'), | ||
}, | ||
order1: { | ||
y: BigNumber.from('5'), | ||
z: BigNumber.from('6'), | ||
A: BigNumber.from('7'), | ||
B: BigNumber.from('8'), | ||
}, | ||
}; | ||
const order = { | ||
y: BigNumber.from('9'), | ||
z: BigNumber.from('10'), | ||
A: BigNumber.from('11'), | ||
B: BigNumber.from('12'), | ||
}; | ||
// Initialize the pairToStrategies map and ordersCache map | ||
const pairToStrategies: PairToStrategiesMap = new Map(); | ||
const strategyById: StrategyById = new Map(); | ||
const ordersCache: PairToDirectedOrdersMap = new Map(); | ||
// Add the sample strategy to the pairToStrategies map | ||
const pairId = [strategy.token0, strategy.token1] as TokenPair; | ||
pairToStrategies.set(pairId, [strategy]); | ||
strategyById.set(strategy.id.toString(), strategy); | ||
// Call the onOrderModified function with a different strategy id | ||
applyModifiedOrderToCache( | ||
BigNumber.from('111111'), | ||
0, | ||
order, | ||
pairToStrategies, | ||
strategyById, | ||
ordersCache | ||
); | ||
// Check that the strategy and orders cache were not updated | ||
expect(pairToStrategies.get(pairId)![0].order0).to.not.deep.equal(order); | ||
expect(ordersCache.get(`${strategy.token0}-${strategy.token1}`)).to.be | ||
.undefined; | ||
}); | ||
it('should not update the cache if the order index is not 0 or 1', () => { | ||
// Create a sample Strategy and Order objects | ||
const strategy = { | ||
id: BigNumber.from('123456'), | ||
token0: 'token0', | ||
token1: 'token1', | ||
order0: { | ||
y: BigNumber.from('1'), | ||
z: BigNumber.from('2'), | ||
A: BigNumber.from('3'), | ||
B: BigNumber.from('4'), | ||
}, | ||
order1: { | ||
y: BigNumber.from('5'), | ||
z: BigNumber.from('6'), | ||
A: BigNumber.from('7'), | ||
B: BigNumber.from('8'), | ||
}, | ||
}; | ||
const order = { | ||
y: BigNumber.from('9'), | ||
z: BigNumber.from('10'), | ||
A: BigNumber.from('11'), | ||
B: BigNumber.from('12'), | ||
}; | ||
// Initialize the pairToStrategies map and ordersCache map | ||
const pairToStrategies: PairToStrategiesMap = new Map(); | ||
const strategyById: StrategyById = new Map(); | ||
const ordersCache: PairToDirectedOrdersMap = new Map(); | ||
// Add the sample strategy to the pairToStrategies map | ||
const pairId = [strategy.token0, strategy.token1] as TokenPair; | ||
pairToStrategies.set(pairId, [strategy]); | ||
strategyById.set(strategy.id.toString(), strategy); | ||
// Call the onOrderModified function with a different order index | ||
applyModifiedOrderToCache( | ||
strategy.id, | ||
2, | ||
order, | ||
pairToStrategies, | ||
strategyById, | ||
ordersCache | ||
); | ||
// Check that the strategy and orders cache were not updated | ||
expect(pairToStrategies.get(pairId)![0].order0).to.not.deep.equal(order); | ||
expect(ordersCache.get(`${strategy.token0}-${strategy.token1}`)).to.be | ||
.undefined; | ||
}); | ||
}); |
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
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
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
2099800
36617