Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bancor/carbon-sdk

Package Overview
Dependencies
Maintainers
2
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bancor/carbon-sdk - npm Package Compare versions

Comparing version 0.0.53-DEV to 0.0.54-DEV

4

dist/chain/utils.d.ts

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

import { PayableOverrides } from 'ethers';
import { BigNumberish, PayableOverrides } from 'ethers';
import { TradeActionStruct } from '../abis/types/CarbonController';
export declare const isETHAddress: (address: string) => boolean;
export declare const buildTradeOverrides: (token: string, tradeActions: TradeActionStruct[], overrides?: PayableOverrides) => PayableOverrides;
export declare const buildTradeOverrides: (sourceToken: string, tradeActions: TradeActionStruct[], byTarget: boolean, maxInput: BigNumberish, overrides?: PayableOverrides) => PayableOverrides;
//# sourceMappingURL=utils.d.ts.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):t((e||self).carbonSdk={},e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,r,a,i){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=/*#__PURE__*/o(r);function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(a=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?a:String(a),r)}var a}function p(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function y(){return y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},y.apply(this,arguments)}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function l(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 d(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)?d(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 c=function(e,t){return e.localeCompare(t)},m="->-<-",f=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]);return e.join(m)},g=function(e,t){return f([e,t].sort(c))},b=function(e){var t=e.split(m);return[t[0],t[1]]},h=function(e,t){return f([e,t])},T=function(e,t,n){if(0!==n.size){var r,a;0===t?(r=e.order0,a=h(e.token1,e.token0)):(r=e.order1,a=h(e.token0,e.token1));var i,o=n.get(a);o?o[e.id.toString()]=r:(console.warn("Should not be here, modified order is supposed to already be cached"),n.set(a,((i={})[e.id.toString()]=r,i)))}},v=/*#__PURE__*/function(){function e(e,t){this._pairToStrategies=void 0,this._strategyById=void 0,this._fetcher=void 0,this._cachedOrders=void 0,this._onChange=void 0,this._fetcher=e,this._pairToStrategies=new Map,this._strategyById=new Map,this._cachedOrders=new Map,this._onChange=t}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,r=0;r<t.length;r++){var a=t[r],i=e[r],o=g(a[0],a[1]);n.set(o,i)}return n})})}catch(e){return Promise.reject(e)}}(e._fetcher)).then(function(t){e._pairToStrategies=t;for(var n,r=l(e._pairToStrategies.values());!(n=r()).done;){var a=n.value;if(a&&a.length>0)for(var i=0;i<a.length;i++)e._strategyById.set(a[i].id.toString(),a[i])}e._fetcher.onStrategyCreated(function(t){!function(e,t,n,r){if(!n.has(e.id.toString())){n.set(e.id.toString(),e);var a=g(e.token0,e.token1);if(t.has(a)?t.get(a).push(e):t.set(a,[e]),0!==r.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u,s=o[i],p=h(s[0],s[1]),y=s[0]===e.token0?e.order1:e.order0,d=r.get(p);d?d[e.id.toString()]=y:r.set(p,((u={})[e.id.toString()]=y,u))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()}),e._fetcher.onStrategyUpdated(function(t){!function(e,t,n,r){n.set(e.id.toString(),e);var a=g(e.token0,e.token1);t.has(a)?t.set(a,t.get(a).map(function(t){return t.id===e.id?e:t})):t.set(a,[e]),T(e,0,r),T(e,1,r)}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()}),e._fetcher.onStrategyDeleted(function(t){!function(e,t,n,r){if(n.has(e.id.toString())){n.delete(e.id.toString());var a=g(e.token0,e.token1);if(t.has(a)&&t.set(a,t.get(a).filter(function(t){return t.id!==e.id})),0===t.get(a).length&&t.delete(a),0!==r.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u=o[i],s=h(u[0],u[1]),p=r.get(s);p&&(delete p[e.id.toString()],0===Object.keys(p).length&&r.delete(s))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()})})}catch(e){return Promise.reject(e)}},t.getOrders=function(e,t,n){var r;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,r=l(e.values());!(n=r()).done;){var a=n.value;if(a.length>0){for(var i=a[0].token0,o=a[0].token1,u={},s={},p=0;p<a.length;p++)a[p].token0===i?(u[a[p].id.toString()]=a[p].order0,s[a[p].id.toString()]=a[p].order1):(u[a[p].id.toString()]=a[p].order1,s[a[p].id.toString()]=a[p].order0);t.set(h(i,o),s),t.set(h(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var a=h(e,t),i=null!=(r=this._cachedOrders.get(a))?r:{};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())},p(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys()).map(b)}}]),e}(),w=function(e,t){return e.lt(t)?e:t},P=function(e,t){return e.gt(t)?e:t};u.default.set({precision:100,rounding:u.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var k=Math.pow(2,48),_=new u.default(10),S=function(e,t){return _.pow(e-t)},M=function(e){return new u.default(e.toString())},B=function(e){return n.BigNumber.from(e.toFixed())},A=function(e,t,n){return t.eq(n)?e:e.mul(t).div(n)},x="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),C=function(e){return e.toLowerCase()===x},D=function(e,t,r){var a=y({},r);return C(e)&&(a.value=t.reduce(function(e,t){return e.add(t.amount)},n.BigNumber.from(0))),a},I=console.log;function O(e){return e instanceof n.BigNumber?e.toString():Array.isArray(e)?e.map(O):"object"==typeof e?Object.fromEntries(Object.entries(e).map(function(e){return[e[0],O(e[1])]})):e}console.debug=function(){var e=[].slice.call(arguments).map(O);I.apply(console,e)};var R=/*#__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).debug.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),E=new R("Composer.ts"),j=/*#__PURE__*/function(){function e(e){this._contracts=void 0,this._contracts=e}var t=e.prototype;return t.tradeByTargetAmount=function(e,t,n,r,a,i){E.debug("tradeByTargetAmount called",arguments);var o=D(e,n,i);return E.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,r,a,o)},t.tradeBySourceAmount=function(e,t,n,r,a,i){E.debug("tradeBySourceAmount called",arguments);var o=D(e,n,i);return E.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,r,a,o)},t.createStrategy=function(e,t,n,r,a){E.debug("createStrategy called",arguments);var i=y({},a);return C(e)?i.value=n.y:C(t)&&(i.value=r.y),E.debug("createStrategy overrides",i),this._contracts.carbonController.populateTransaction.createStrategy(e,t,[n,r],i)},t.deleteStrategy=function(e){return this._contracts.carbonController.populateTransaction.deleteStrategy(e)},t.updateStrategy=function(e,t,n,r,a,i){var o=y({},i);return C(t)&&a[0].y.gt(r[0].y)?o.value=a[0].y.sub(r[0].y):C(n)&&a[1].y.gt(r[1].y)&&(o.value=a[1].y.sub(r[1].y)),E.debug("updateStrategy overrides",o),this._contracts.carbonController.populateTransaction.updateStrategy(e,r,a,i)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),F=[{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:"admin_",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"implementation",outputs:[{internalType:"address",name:"implementation_",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:"AccessDenied",type:"error"},{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:"InsufficientLiquidity",type:"error"},{inputs:[],name:"InsufficientNativeTokenReceived",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{inputs:[],name:"InvalidFee",type:"error"},{inputs:[],name:"InvalidIndices",type:"error"},{inputs:[],name:"InvalidRate",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:"PoolDoesNotExist",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:"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:!0,internalType:"uint256",name:"id",type:"uint256"},{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:"contract Token[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:"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"},{internalType:"contract Token[2]",name:"tokens",type:"address[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:"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"},{internalType:"contract Token[2]",name:"tokens",type:"address[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:"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:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"_logic",type:"address"},{internalType:"address",name:"admin_",type:"address"},{internalType:"bytes",name:"_data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],N=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(F)},e.connect=function(e,t){return new a.Contract(e,F,t)},e}();N.abi=F;var U=[{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"}],q=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(U)},e.connect=function(e,t){return new a.Contract(e,U,t)},e}();q.abi=U;var z=[{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"}],L=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(z)},e.connect=function(e,t){return new a.Contract(e,z,t)},e}();L.abi=z;var H=[{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:!1,internalType:"string",name:"newBaseExtension",type:"string"}],name:"BaseExtensionUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"string",name:"newBaseURI",type:"string"}],name:"BaseURIUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"contract CarbonController",name:"carbonController",type:"address"}],name:"CarbonControllerUpdated",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"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"newUseGlobalURI",type:"bool"}],name:"UseGlobalURIUpdated",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"}],W=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(H)},e.connect=function(e,t){return new a.Contract(e,H,t)},e}();W.abi=H;var G={carbonControllerAddress:"0x955a85437664fE809563dd0fA91B1590b159e1e6",multiCallAddress:"0x5ba1e12693dc8f9c48aad8770482f4739beed696",voucherAddress:"0x31051bCd26B8EaEFE4EfA54E0668B133ee7C44c0"},Z=/*#__PURE__*/function(){function e(e,t){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._config=G,this._provider=e,this._config.carbonControllerAddress=(null==t?void 0:t.carbonControllerAddress)||G.carbonControllerAddress,this._config.multiCallAddress=(null==t?void 0:t.multiCallAddress)||G.multiCallAddress,this._config.voucherAddress=(null==t?void 0:t.voucherAddress)||G.voucherAddress}return e.prototype.token=function(e){return L.connect(e,this._provider)},p(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=N.connect(this._config.carbonControllerAddress,this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=q.connect(this._config.multiCallAddress,this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=W.connect(this._config.voucherAddress,this._provider)),this._voucher}}]),e}(),K=new R("Reader.ts");function V(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 J(e,t){function n(n,r,a,i,o){K.debug(e+" fired with",arguments);var u={id:n,token0:r,token1:a,order0:{y:i.y,z:i.z,A:i.A,B:i.B},order1:{y:o.y,z:o.z,A:o.A,B:o.B}};K.debug(e+" parsed strategy:",u),t(u)}return"StrategyUpdated"===e?function(e,t,r,a,i){n(e,t,r,a,i)}:function(e,t,r,a,i,o){n(e,r,a,i,o)}}var $=/*#__PURE__*/function(){function e(e){var t=this,n=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return C(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this.getLatestTradeByPair=function(e,t){try{K.debug("getLatestTradeByPair",e,t);var r=n._contracts.carbonController.filters.TokensTraded(null,e,t,null,null,null,null);return Promise.resolve(n._contracts.carbonController.queryFilter(r,-1e3)).then(function(e){if(K.debug("getLatestTradeByPair logs",e),0!==e.length){var t=e[0];return K.debug("getLatestTradeByPair latestLog",t),t.args}})}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(r,a){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(V)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=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:"strategy",methodParameters:[e]}}))).then(function(e){return e&&0!==e.length?e.map(function(e){return V(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 V(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 V(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 r=Array.from(Array(n.toNumber()),function(n,r){return{contractAddress:t._contracts.voucher.address,interface:t._contracts.voucher.interface,methodName:"tokenOfOwnerByIndex",methodParameters:[e,r]}});return Promise.resolve(t.multicall(r)).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){K.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",J("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",J("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",J("StrategyUpdated",e))},e}(),Q=/*#__PURE__*/function(){function e(e,t){this._reader=void 0,this._composer=void 0;var n=new Z(e,t);this._reader=new $(n),this._composer=new j(n)}return p(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),X=function(e,t){var n=e.output.mul(t.input),r=t.output.mul(e.input),a=n.lt(r),i=n.gt(r),o=!a&&!i;return+(a||o&&e.output.lt(t.output))-+(i||o&&e.output.gt(t.output))},Y=function(e,t){return X(t,e)},ee=/*#__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,r=n._cachedDecimals.get(t);return void 0!==r?Promise.resolve(r):Promise.resolve(e._fetcher(t)).then(function(e){if(void 0===(r=e))throw new Error("Could not fetch decimals for token "+t);return n._cachedDecimals.set(t,r),r})}catch(e){return Promise.reject(e)}},p(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();function te(e,t){var n,r,a,o=(r=t,-1!==(a=(n=e).indexOf("."))?n.slice(0,a+r+1):n);return i.parseUnits(o,t).toString()}function ne(e,t){var n=i.formatUnits(e,t);return new u.default(n).toFixed()}ee._instance=void 0,ee._fetcher=void 0;var re=1e6;function ae(e,t){return new u.default(e.toString()).mul(re).div(re-t).ceil()}function ie(e,t){return new u.default(e.toString()).mul(re-t).div(re).floor()}function oe(e,t,n){return new u.default(e.toString()).times(S(t,n)).toFixed()}function ue(e,t,n){return 0==+e.toString()?"0":new u.default(1).div(e.toString()).times(S(n,t)).toFixed()}var se=function(e){try{var t=arguments;pe.debug("decodeStrategy called",t);var n=e.id,r=e.token0,a=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=ee.getInstance();return Promise.resolve(s.fetchDecimals(r)).then(function(e){return Promise.resolve(s.fetchDecimals(a)).then(function(t){var s=oe(o.lowestRate,e,t),p=oe(o.highestRate,e,t),y=ue(i.highestRate,t,e),d=ue(i.lowestRate,t,e),l=ne(i.liquidity,e),c=ne(o.liquidity,t);return pe.debug("decodeStrategy info:",{id:n,token0:r,token1:a,order0:i,order1:o,decimals0:e,decimals1:t,baseToken:r,quoteToken:a,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l}),{id:n,baseToken:r,quoteToken:a,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l,encoded:u}})})}catch(e){return Promise.reject(e)}},pe=new R("encoders.ts");function ye(e){return e.gt(0)?u.default.log2(e.toString()).add(1).floor().toNumber():0}var de=function(e){var t=B(e.sqrt().mul(k).floor()),n=ye(t.div(k));return M(t.shr(n).shl(n))},le=function(e){return e.div(k).pow(2)},ce=function(e){var t=ye(e.div(k)),r=e.shr(t);return n.BigNumber.from(k).mul(t).or(r)},me=function(e){return e.mod(k).shl(e.div(k).toNumber())},fe=function(e){var t=new u.default(e.liquidity),n=new u.default(e.lowestRate),r=new u.default(e.highestRate),a=new u.default(e.marginalRate);if(!(r.gte(a)&&a.gt(n)||r.eq(a)&&a.eq(n)))throw new Error("Either one of the following must hold:\n- highestRate >= marginalRate > lowestRate\n- highestRate == marginalRate == lowestRate\n(highestRate = "+r+", marginalRate = "+a+", lowestRate = "+n+")");var i=B(t),o=B(de(n)),s=B(de(r)),p=B(de(a));return{y:i,z:s.eq(p)?i:i.mul(s.sub(o)).div(p.sub(o)),A:ce(s.sub(o)),B:ce(o)}},ge=function(e){var t=M(e.y),n=M(e.z),r=M(me(e.A)),a=M(me(e.B));return{liquidity:t.toString(),lowestRate:le(a).toString(),highestRate:le(a.add(r)).toString(),marginalRate:le(t.eq(n)?a.add(r):a.add(r.mul(t).div(n))).toString()}},be=function(e){return{token0:e.token0,token1:e.token1,order0:fe(e.order0),order1:fe(e.order1)}},he=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:ge(e.order0),order1:ge(e.order1),encoded:e}};function Te(e,t,n,r,a,i,o,s,p,y){if(pe.debug("buildStrategyObject called",arguments),new u.default(a).isNegative()||new u.default(i).isNegative()||new u.default(s).isNegative()||new u.default(p).isNegative())throw new Error("prices cannot be negative");if(new u.default(a).gt(i)||new u.default(s).gt(p))throw new Error("low price must be lower than or equal to high price");if(new u.default(o).isNegative()||new u.default(y).isNegative())throw new Error("budgets cannot be negative");var d=ve(n,r,a,i,o,s,p,y),l=d.order0,c=d.order1;return pe.debug("buildStrategyObject info:",{token0:e,token1:t,order0:l,order1:c}),{token0:e,token1:t,order0:l,order1:c}}function ve(e,t,n,r,a,i,o,u){pe.debug("createOrders called",arguments);var s=te(u,e),p=ue(o,t,e),y=ue(i,t,e),d=te(a,t),l=oe(n,t,e),c=oe(r,t,e),m={liquidity:s,lowestRate:p,highestRate:y,marginalRate:y},f={liquidity:d,lowestRate:l,highestRate:c,marginalRate:c};return pe.debug("createOrders info:",{order0:m,order1:f}),{order0:m,order1:f}}var we=n.BigNumber.from(k),Pe=n.BigNumber.from(2).pow(128).sub(1),ke=n.BigNumber.from(2).pow(256).sub(1);function _e(e,t){if(e.gte(0)&&e.lte(t))return e;throw null}var Se=function(e){return _e(e,Pe)},Me=function(e,t){return _e(e.add(t),ke)},Be=function(e,t){return _e(e.mul(t),ke)},Ae=function(e,t,n){return _e(e.mul(t).div(n),ke)},xe=function(e,t,n){return _e(e.mul(t).add(n).sub(1).div(n),ke)},Ce=function(e,t){var n=e,r=t.y,a=t.z,i=me(t.A),o=me(t.B);try{return Se(function(e,t,n,r,a){if(r.eq(0))return xe(e,Be(we,we),Be(a,a));var i,o,u=Be(n,we),s=Me(Be(t,r),Be(n,a)),p=(i=s,o=Be(e,r),_e(i.sub(o),ke)),y=xe(u,u,ke),d=xe(s,p,ke),l=P(y,d),c=xe(u,u,l),m=Ae(s,p,l);return xe(e,c,m)}(n,r,a,i,o))}catch(e){return ke}},De=function(e,t){var r=w(function(e,t){var r=e,a=t.y,i=t.z,o=me(t.A),u=me(t.B);try{return Se(function(e,t,n,r,a){if(r.eq(0))return Ae(e,Be(a,a),Be(we,we));var i=Be(n,we),o=Me(Be(t,r),Be(n,a)),u=Be(o,e),s=xe(i,i,ke),p=xe(u,r,ke),y=P(s,p),d=xe(i,i,y),l=xe(u,r,y);return Ae(o,u.div(y),Me(d,l))}(r,a,i,o,u))}catch(e){return n.BigNumber.from(0)}}(e,t),t.y);return{input:Ce(r,t),output:r}},Ie=function(e,t){var n=w(e,t.y);return{input:n,output:Ce(n,t)}},Oe=function(e,t,r,a,i){for(var o,u=[],s=l(Object.keys(t).map(function(n){return{id:n,rate:a(e,t[n])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,y=p.id,d=p.rate;if(!e.gt(d.input)){if(e.eq(d.input)){r(d)&&u.push({id:n.BigNumber.from(y),input:d.input,output:d.output});break}var c={input:e,output:a(e,t[y]).output};r(c)&&u.push({id:n.BigNumber.from(y),input:c.input,output:c.output});break}r(d)&&(u.push({id:n.BigNumber.from(y),input:d.input,output:d.output}),e=e.sub(d.input))}return u},Re=function(e){return e.input.gt(0)&&e.output.gt(0)};function Ee(e){return e.reduce(function(e,t){return u.default.min(e,t.lowestRate)},new u.default(Infinity))}function je(e){return e.reduce(function(e,t){return u.default.max(e,t.highestRate)},new u.default(-Infinity))}function Fe(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new u.default(e.liquidity);if(t.gte(e.marginalRate))return new u.default(0);var n=new u.default(e.liquidity),r=new u.default(e.lowestRate).sqrt(),a=new u.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(r)).div(a.sub(r)))}(n,t))},new u.default(0))}var Ne,Ue=new R("index.ts");e.MarginalPriceOptions=void 0,(Ne=e.MarginalPriceOptions||(e.MarginalPriceOptions={})).reset="RESET",Ne.maintain="MAINTAIN";var qe=/*#__PURE__*/function(){function r(e,n){var r=this;this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,this._onChangeCallbacks=[],Ue.debug("SDK class constructor called with",arguments);var a=new t.StaticJsonRpcProvider({url:e.rpcUrl,skipFetchSetup:!0},1);this._api=new Q(a,e.contractAddresses);var i=function(e){return Promise.resolve(null==n?void 0:n(e)).then(function(t){return void 0!==t?t:r._api.reader.getDecimalsByAddress(e)})};ee.init(i)}r.getMatchActions=function(e,t,r){return t?function(e,t,n){return void 0===n&&(n=Re),Oe(e,t,n,Ie,Y)}(n.BigNumber.from(e),r):function(e,t,n){return void 0===n&&(n=Re),Oe(e,t,n,De,X)}(n.BigNumber.from(e),r)};var a=r.prototype;return a._fireOnChange=function(){Ue.debug("firing onChange callbacks"),this._onChangeCallbacks.forEach(function(e){return e()})},a.onChange=function(e){var t=this;if(Ue.debug("onChange called with",arguments),"function"!=typeof e)throw new Error("onChange callback must be a function");return this._onChangeCallbacks.push(e),function(){t._onChangeCallbacks=t._onChangeCallbacks.filter(function(t){return t!==e})}},a.startDataSync=function(){try{var e=this;return Ue.debug("startDataSync called"),e._cache?(Ue.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new v(e._api.reader,e._fireOnChange.bind(e)),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){Ue.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),Ue.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},a.hasLiquidityByPair=function(e,t){if(Ue.debug("hasLiquidityByPair called",arguments),!this._cache)throw Ue.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return Ue.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},a.getLiquidityByPair=function(e,t){try{var r=arguments,a=this;if(Ue.debug("getLiquidityByPair called",r),!a._cache)throw Ue.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=a._cache.getOrders(e,t),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},n.BigNumber.from(0));return Promise.resolve(ee.getInstance().fetchDecimals(t)).then(function(e){var n=ne(o,e);return Ue.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:t,decimals:e,liquidity:n}),n})}catch(e){return Promise.reject(e)}},a.getUserStrategies=function(e){try{var t=arguments,n=this;return Ue.debug("getUserStrategies called",t),Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){function t(){var t=r.map(he);return Promise.resolve(Promise.all(t.map(function(e){try{return Promise.resolve(se(e))}catch(e){return Promise.reject(e)}}))).then(function(n){return Ue.debug("getUserStrategies info:",{ids:e,encodedStrategies:r,decodedStrategies:t,strategies:n}),n})}var r,a=function(){if(!n._cache)return Ue.log("getUserStrategies called before startDataSync - fetching from chain"),Promise.resolve(n._api.reader.getStrategiesByIds(e)).then(function(e){r=e});r=e.map(function(e){var t;return null==(t=n._cache)?void 0:t.getStrategyById(e)}).filter(function(e){return!!e})}();return a&&a.then?a.then(t):t()})}catch(e){return Promise.reject(e)}},a.getMatchParams=function(e,t,r,a){try{var i=arguments,o=this;if(Ue.debug("getMatchParams called",i),!o._cache)throw Ue.log("getMatchParams called before startDataSync"),new Error("startDataSync must be called prior to this action");var u=ee.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(i){return Promise.resolve(u.fetchDecimals(t)).then(function(u){return{orders:o._cache.getOrders(e,t),amountWei:n.BigNumber.from(te(r,a?u:i)).toString(),sourceDecimals:i,targetDecimals:u}})})}catch(e){return Promise.reject(e)}},a.getTradeData=function(e,t,n,a,i){try{var o=arguments,u=this;return Ue.debug("getTradeData called",o),Promise.resolve(u.getMatchParams(e,t,n,a)).then(function(i){var o=i.orders,s=i.amountWei,p=r.getMatchActions(s,a,o);return Promise.resolve(u.getTradeDataFromActions(e,t,a,p)).then(function(e){return Ue.debug("getTradeData info:",{orders:o,amount:n,amountWei:s,res:e}),e})})}catch(e){return Promise.reject(e)}},a.getTradeDataFromActions=function(e,t,r,a){try{var i=arguments,o=this;Ue.debug("getTradeDataFromActions called",i);var s=ee.getInstance();return Promise.resolve(s.fetchDecimals(e)).then(function(e){return Promise.resolve(s.fetchDecimals(t)).then(function(t){var i,s,p,y=[],d=[],l=n.BigNumber.from(0),c=n.BigNumber.from(0);if(a.forEach(function(n){y.push({strategyId:n.id,amount:n.input}),d.push({id:n.id,sourceAmount:ne(r?n.output:n.input,e),targetAmount:ne(r?n.input:n.output,t)}),c=c.add(n.input),l=l.add(n.output)}),null==o._tradingFeePPM)throw new Error("tradingFeePPM is undefined");if(r?(i=ae(l,o._tradingFeePPM).floor().toFixed(0),s=c.toString()):(i=c.toString(),s=ie(l,o._tradingFeePPM).floor().toFixed(0)),new u.default(i).isZero()||new u.default(s).isZero())p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:a};else{var m=new u.default(s).div(i).times(S(e,t)).toString();p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:ne(i,e),totalTargetAmount:ne(s,t),effectiveRate:m,actionsWei:a}}return Ue.debug("getTradeDataFromActions info:",{sourceDecimals:e,targetDecimals:t,actionsWei:a,totalInput:c,totalOutput:l,tradingFeePPM:o._tradingFeePPM,res:p}),p})})}catch(e){return Promise.reject(e)}},a.composeTradeByTargetTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return Ue.debug("composeTradeByTargetTransaction called",o),Promise.resolve(ee.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,r,te(a,o),i)})}catch(e){return Promise.reject(e)}},a.composeTradeBySourceTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return Ue.debug("composeTradeBySourceTransaction called",o),Promise.resolve(ee.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,r,te(a,o),i)})}catch(e){return Promise.reject(e)}},a.createBuySellStrategy=function(e,t,n,r,a,i,o,u,s){try{var p=arguments,y=this;Ue.debug("createBuySellStrategy called",p);var d=ee.getInstance();return Promise.resolve(d.fetchDecimals(e)).then(function(p){return Promise.resolve(d.fetchDecimals(t)).then(function(d){var l=Te(e,t,p,d,n,r,a,i,o,u),c=be(l);return Ue.debug("createBuySellStrategy info:",{strategy:l,encStrategy:c}),y._api.composer.createStrategy(c.token0,c.token1,c.order0,c.order1,s)})})}catch(e){return Promise.reject(e)}},a.updateStrategy=function(t,r,a,i,o,u,s,p){var y=o.buyPriceLow,d=o.buyPriceHigh,l=o.buyBudget,c=o.sellPriceLow,m=o.sellPriceHigh,f=o.sellBudget;try{var g=arguments,b=this;Ue.debug("updateStrategy called",g);var h=ee.getInstance();return Promise.resolve(h.fetchDecimals(a)).then(function(o){return Promise.resolve(h.fetchDecimals(i)).then(function(g){var h=he(r);return Promise.resolve(se(h)).then(function(T){var v=Te(a,i,o,g,null!=y?y:T.buyPriceLow,null!=d?d:T.buyPriceHigh,null!=l?l:T.buyBudget,null!=c?c:T.sellPriceLow,null!=m?m:T.sellPriceHigh,null!=f?f:T.sellBudget),w=be(v);if(void 0===l&&(w.order1.y=r.order1.y),void 0===f&&(w.order0.y=r.order0.y),void 0===y&&void 0===d&&(w.order1.A=r.order1.A,w.order1.B=r.order1.B),void 0===c&&void 0===m&&(w.order0.A=r.order0.A,w.order0.B=r.order0.B),void 0!==l&&(void 0===u||u===e.MarginalPriceOptions.reset||r.order1.y.isZero()?w.order1.z=w.order1.y:u===e.MarginalPriceOptions.maintain&&(w.order1.z=A(r.order1.z,w.order1.y,r.order1.y))),void 0!==f&&(void 0===s||s===e.MarginalPriceOptions.reset||r.order0.y.isZero()?w.order0.z=w.order0.y:s===e.MarginalPriceOptions.maintain&&(w.order0.z=A(r.order0.z,w.order0.y,r.order0.y))),void 0===y&&void 0===d||(w.order1.z=w.order1.y),void 0===c&&void 0===m||(w.order0.z=w.order0.y),void 0!==u&&u!==e.MarginalPriceOptions.reset&&u!==e.MarginalPriceOptions.maintain)throw new Error("Support for custom marginal price is not implemented yet");if(void 0!==s&&s!==e.MarginalPriceOptions.reset&&s!==e.MarginalPriceOptions.maintain)throw new Error("Support for custom marginal price is not implemented yet");return Ue.debug("updateStrategy info:",{baseDecimals:o,quoteDecimals:g,decodedOriginal:h,originalStrategy:T,newStrategy:v,newEncodedStrategy:w}),b._api.composer.updateStrategy(n.BigNumber.from(t),w.token0,w.token1,[r.order0,r.order1],[w.order0,w.order1],p)})})})}catch(e){return Promise.reject(e)}},a.deleteStrategy=function(e){return Ue.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(n.BigNumber.from(e))},a.getRateLiquidityDepthByPair=function(e,t,n){try{var r=arguments,a=this;if(Ue.debug("getRateLiquidityDepthByPair called",r),!a._cache)throw Ue.log("getRateLiquidityDepthByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=Object.values(a._cache.getOrders(e,t)).map(ge),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var r=oe(n,t,e),a=Fe(i,new u.default(r)).toFixed(0),o=ne(a,t);return Ue.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:a,targetDecimals:t,depthInTargetDecimals:o}),o})})}catch(e){return Promise.reject(e)}},a.getMinRateByPair=function(e,t){try{var n=arguments,r=this;if(Ue.debug("getMinRateByPair called",n),!r._cache)throw Ue.log("getMinRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var a=Object.values(r._cache.getOrders(e,t)).map(ge),i=Ee(a).toString(),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=oe(i,e,t);return Ue.debug("getMinRateByPair info:",{orders:a,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getMaxRateByPair=function(e,t){try{var n=arguments,r=this;if(Ue.debug("getMaxRateByPair called",n),!r._cache)throw Ue.log("getMaxRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var a=Object.values(r._cache.getOrders(e,t)).map(ge),i=je(a).toString(),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=oe(i,e,t);return Ue.debug("getMaxRateByPair info:",{orders:a,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getLastTradeByPair=function(e,t){try{var n=arguments,r=this;return Ue.debug("getLastTradeByPair called",n),Promise.resolve(r._api.reader.getLatestTradeByPair(e,t)).then(function(n){return Ue.debug("getLastTradeByPair info:",{sourceToken:e,targetToken:t,lastTrade:n}),n})}catch(e){return Promise.reject(e)}},p(r,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(Ue.debug("pairs called"),!this._cache)throw Ue.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),r}();e.Sdk=qe});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["exports","@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):t((e||self).carbonSdk={},e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,r,a,i){function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=/*#__PURE__*/o(r);function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,"symbol"==typeof(a=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(r.key))?a:String(a),r)}var a}function p(e,t,n){return t&&s(e.prototype,t),n&&s(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d.apply(this,arguments)}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function l(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 r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 c=function(e,t){return e.localeCompare(t)},m="->-<-",f=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]);return e.join(m)},g=function(e,t){return f([e,t].sort(c))},b=function(e){var t=e.split(m);return[t[0],t[1]]},h=function(e,t){return f([e,t])},T=function(e,t,n){if(0!==n.size){var r,a;0===t?(r=e.order0,a=h(e.token1,e.token0)):(r=e.order1,a=h(e.token0,e.token1));var i,o=n.get(a);o?o[e.id.toString()]=r:(console.warn("Should not be here, modified order is supposed to already be cached"),n.set(a,((i={})[e.id.toString()]=r,i)))}},v=/*#__PURE__*/function(){function e(e,t){this._pairToStrategies=void 0,this._strategyById=void 0,this._fetcher=void 0,this._cachedOrders=void 0,this._onChange=void 0,this._fetcher=e,this._pairToStrategies=new Map,this._strategyById=new Map,this._cachedOrders=new Map,this._onChange=t}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,r=0;r<t.length;r++){var a=t[r],i=e[r],o=g(a[0],a[1]);n.set(o,i)}return n})})}catch(e){return Promise.reject(e)}}(e._fetcher)).then(function(t){e._pairToStrategies=t;for(var n,r=l(e._pairToStrategies.values());!(n=r()).done;){var a=n.value;if(a&&a.length>0)for(var i=0;i<a.length;i++)e._strategyById.set(a[i].id.toString(),a[i])}e._fetcher.onStrategyCreated(function(t){!function(e,t,n,r){if(!n.has(e.id.toString())){n.set(e.id.toString(),e);var a=g(e.token0,e.token1);if(t.has(a)?t.get(a).push(e):t.set(a,[e]),0!==r.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u,s=o[i],p=h(s[0],s[1]),d=s[0]===e.token0?e.order1:e.order0,y=r.get(p);y?y[e.id.toString()]=d:r.set(p,((u={})[e.id.toString()]=d,u))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()}),e._fetcher.onStrategyUpdated(function(t){!function(e,t,n,r){n.set(e.id.toString(),e);var a=g(e.token0,e.token1);t.has(a)?t.set(a,t.get(a).map(function(t){return t.id===e.id?e:t})):t.set(a,[e]),T(e,0,r),T(e,1,r)}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()}),e._fetcher.onStrategyDeleted(function(t){!function(e,t,n,r){if(n.has(e.id.toString())){n.delete(e.id.toString());var a=g(e.token0,e.token1);if(t.has(a)&&t.set(a,t.get(a).filter(function(t){return t.id!==e.id})),0===t.get(a).length&&t.delete(a),0!==r.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u=o[i],s=h(u[0],u[1]),p=r.get(s);p&&(delete p[e.id.toString()],0===Object.keys(p).length&&r.delete(s))}}}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()})})}catch(e){return Promise.reject(e)}},t.getOrders=function(e,t,n){var r;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,r=l(e.values());!(n=r()).done;){var a=n.value;if(a.length>0){for(var i=a[0].token0,o=a[0].token1,u={},s={},p=0;p<a.length;p++)a[p].token0===i?(u[a[p].id.toString()]=a[p].order0,s[a[p].id.toString()]=a[p].order1):(u[a[p].id.toString()]=a[p].order1,s[a[p].id.toString()]=a[p].order0);t.set(h(i,o),s),t.set(h(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var a=h(e,t),i=null!=(r=this._cachedOrders.get(a))?r:{};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())},p(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys()).map(b)}}]),e}(),w=function(e,t){return e.lt(t)?e:t},P=function(e,t){return e.gt(t)?e:t};u.default.set({precision:100,rounding:u.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var k=Math.pow(2,48),_=new u.default(10),S=function(e,t){return _.pow(e-t)},M=function(e){return new u.default(e.toString())},B=function(e){return n.BigNumber.from(e.toFixed())},A=function(e,t,n){return t.eq(n)?e:e.mul(t).div(n)},x="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),C=function(e){return e.toLowerCase()===x},D=function(e,t,r,a,i){var o=d({},i);return C(e)&&(o.value=r?n.BigNumber.from(a):t.reduce(function(e,t){return e.add(t.amount)},n.BigNumber.from(0))),o},I=console.log;function O(e){return e instanceof n.BigNumber?e.toString():Array.isArray(e)?e.map(O):"object"==typeof e?Object.fromEntries(Object.entries(e).map(function(e){return[e[0],O(e[1])]})):e}console.debug=function(){var e=[].slice.call(arguments).map(O);I.apply(console,e)};var R=/*#__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).debug.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),E=new R("Composer.ts"),j=/*#__PURE__*/function(){function e(e){this._contracts=void 0,this._contracts=e}var t=e.prototype;return t.tradeByTargetAmount=function(e,t,n,r,a,i){E.debug("tradeByTargetAmount called",arguments);var o=D(e,n,!0,a,i);return E.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,r,a,o)},t.tradeBySourceAmount=function(e,t,n,r,a,i){E.debug("tradeBySourceAmount called",arguments);var o=D(e,n,!1,-1,i);return E.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,r,a,o)},t.createStrategy=function(e,t,n,r,a){E.debug("createStrategy called",arguments);var i=d({},a);return C(e)?i.value=n.y:C(t)&&(i.value=r.y),E.debug("createStrategy overrides",i),this._contracts.carbonController.populateTransaction.createStrategy(e,t,[n,r],i)},t.deleteStrategy=function(e){return this._contracts.carbonController.populateTransaction.deleteStrategy(e)},t.updateStrategy=function(e,t,n,r,a,i){var o=d({},i);return C(t)&&a[0].y.gt(r[0].y)?o.value=a[0].y.sub(r[0].y):C(n)&&a[1].y.gt(r[1].y)&&(o.value=a[1].y.sub(r[1].y)),E.debug("updateStrategy overrides",o),this._contracts.carbonController.populateTransaction.updateStrategy(e,r,a,i)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),N=[{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:"admin_",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"implementation",outputs:[{internalType:"address",name:"implementation_",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:"AccessDenied",type:"error"},{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:"InsufficientLiquidity",type:"error"},{inputs:[],name:"InsufficientNativeTokenReceived",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{inputs:[],name:"InvalidFee",type:"error"},{inputs:[],name:"InvalidIndices",type:"error"},{inputs:[],name:"InvalidRate",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:"PoolDoesNotExist",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:"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:!0,internalType:"uint256",name:"id",type:"uint256"},{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:"contract Token[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:"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"},{internalType:"contract Token[2]",name:"tokens",type:"address[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:"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"},{internalType:"contract Token[2]",name:"tokens",type:"address[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:"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:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"_logic",type:"address"},{internalType:"address",name:"admin_",type:"address"},{internalType:"bytes",name:"_data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],F=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(N)},e.connect=function(e,t){return new a.Contract(e,N,t)},e}();F.abi=N;var U=[{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"}],q=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(U)},e.connect=function(e,t){return new a.Contract(e,U,t)},e}();q.abi=U;var z=[{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"}],L=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(z)},e.connect=function(e,t){return new a.Contract(e,z,t)},e}();L.abi=z;var H=[{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:!1,internalType:"string",name:"newBaseExtension",type:"string"}],name:"BaseExtensionUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"string",name:"newBaseURI",type:"string"}],name:"BaseURIUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"contract CarbonController",name:"carbonController",type:"address"}],name:"CarbonControllerUpdated",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"},{anonymous:!1,inputs:[{indexed:!1,internalType:"bool",name:"newUseGlobalURI",type:"bool"}],name:"UseGlobalURIUpdated",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"}],W=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(H)},e.connect=function(e,t){return new a.Contract(e,H,t)},e}();W.abi=H;var G={carbonControllerAddress:"0x955a85437664fE809563dd0fA91B1590b159e1e6",multiCallAddress:"0x5ba1e12693dc8f9c48aad8770482f4739beed696",voucherAddress:"0x31051bCd26B8EaEFE4EfA54E0668B133ee7C44c0"},Z=/*#__PURE__*/function(){function e(e,t){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._config=G,this._provider=e,this._config.carbonControllerAddress=(null==t?void 0:t.carbonControllerAddress)||G.carbonControllerAddress,this._config.multiCallAddress=(null==t?void 0:t.multiCallAddress)||G.multiCallAddress,this._config.voucherAddress=(null==t?void 0:t.voucherAddress)||G.voucherAddress}return e.prototype.token=function(e){return L.connect(e,this._provider)},p(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=F.connect(this._config.carbonControllerAddress,this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=q.connect(this._config.multiCallAddress,this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=W.connect(this._config.voucherAddress,this._provider)),this._voucher}}]),e}(),K=new R("Reader.ts");function V(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 J(e,t){function n(n,r,a,i,o){K.debug(e+" fired with",arguments);var u={id:n,token0:r,token1:a,order0:{y:i.y,z:i.z,A:i.A,B:i.B},order1:{y:o.y,z:o.z,A:o.A,B:o.B}};K.debug(e+" parsed strategy:",u),t(u)}return"StrategyUpdated"===e?function(e,t,r,a,i){n(e,t,r,a,i)}:function(e,t,r,a,i,o){n(e,r,a,i,o)}}var $=/*#__PURE__*/function(){function e(e){var t=this,n=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return C(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this.getLatestTradeByPair=function(e,t){try{K.debug("getLatestTradeByPair",e,t);var r=n._contracts.carbonController.filters.TokensTraded(null,e,t,null,null,null,null);return Promise.resolve(n._contracts.carbonController.queryFilter(r,-1e3)).then(function(e){if(K.debug("getLatestTradeByPair logs",e),0!==e.length){var t=e[0];return K.debug("getLatestTradeByPair latestLog",t),t.args}})}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(r,a){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(V)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=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:"strategy",methodParameters:[e]}}))).then(function(e){return e&&0!==e.length?e.map(function(e){return V(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 V(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 V(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 r=Array.from(Array(n.toNumber()),function(n,r){return{contractAddress:t._contracts.voucher.address,interface:t._contracts.voucher.interface,methodName:"tokenOfOwnerByIndex",methodParameters:[e,r]}});return Promise.resolve(t.multicall(r)).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){K.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",J("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",J("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",J("StrategyUpdated",e))},e}(),Q=/*#__PURE__*/function(){function e(e,t){this._reader=void 0,this._composer=void 0;var n=new Z(e,t);this._reader=new $(n),this._composer=new j(n)}return p(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),X=function(e,t){var n=e.output.mul(t.input),r=t.output.mul(e.input),a=n.lt(r),i=n.gt(r),o=!a&&!i;return+(a||o&&e.output.lt(t.output))-+(i||o&&e.output.gt(t.output))},Y=function(e,t){return X(t,e)},ee=/*#__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,r=n._cachedDecimals.get(t);return void 0!==r?Promise.resolve(r):Promise.resolve(e._fetcher(t)).then(function(e){if(void 0===(r=e))throw new Error("Could not fetch decimals for token "+t);return n._cachedDecimals.set(t,r),r})}catch(e){return Promise.reject(e)}},p(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();function te(e,t){var n,r,a,o=(r=t,-1!==(a=(n=e).indexOf("."))?n.slice(0,a+r+1):n);return i.parseUnits(o,t).toString()}function ne(e,t){var n=i.formatUnits(e,t);return new u.default(n).toFixed()}ee._instance=void 0,ee._fetcher=void 0;var re=1e6;function ae(e,t){return new u.default(e.toString()).mul(re).div(re-t).ceil()}function ie(e,t){return new u.default(e.toString()).mul(re-t).div(re).floor()}function oe(e,t,n){return new u.default(e.toString()).times(S(t,n)).toFixed()}function ue(e,t,n){return 0==+e.toString()?"0":new u.default(1).div(e.toString()).times(S(n,t)).toFixed()}var se=function(e){try{var t=arguments;pe.debug("decodeStrategy called",t);var n=e.id,r=e.token0,a=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=ee.getInstance();return Promise.resolve(s.fetchDecimals(r)).then(function(e){return Promise.resolve(s.fetchDecimals(a)).then(function(t){var s=oe(o.lowestRate,e,t),p=oe(o.highestRate,e,t),d=ue(i.highestRate,t,e),y=ue(i.lowestRate,t,e),l=ne(i.liquidity,e),c=ne(o.liquidity,t);return pe.debug("decodeStrategy info:",{id:n,token0:r,token1:a,order0:i,order1:o,decimals0:e,decimals1:t,baseToken:r,quoteToken:a,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:d,sellPriceHigh:y,sellBudget:l}),{id:n,baseToken:r,quoteToken:a,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:d,sellPriceHigh:y,sellBudget:l,encoded:u}})})}catch(e){return Promise.reject(e)}},pe=new R("encoders.ts");function de(e){return e.gt(0)?u.default.log2(e.toString()).add(1).floor().toNumber():0}var ye=function(e){var t=B(e.sqrt().mul(k).floor()),n=de(t.div(k));return M(t.shr(n).shl(n))},le=function(e){return e.div(k).pow(2)},ce=function(e){var t=de(e.div(k)),r=e.shr(t);return n.BigNumber.from(k).mul(t).or(r)},me=function(e){return e.mod(k).shl(e.div(k).toNumber())},fe=function(e){var t=new u.default(e.liquidity),n=new u.default(e.lowestRate),r=new u.default(e.highestRate),a=new u.default(e.marginalRate);if(!(r.gte(a)&&a.gt(n)||r.eq(a)&&a.eq(n)))throw new Error("Either one of the following must hold:\n- highestRate >= marginalRate > lowestRate\n- highestRate == marginalRate == lowestRate\n(highestRate = "+r+", marginalRate = "+a+", lowestRate = "+n+")");var i=B(t),o=B(ye(n)),s=B(ye(r)),p=B(ye(a));return{y:i,z:s.eq(p)?i:i.mul(s.sub(o)).div(p.sub(o)),A:ce(s.sub(o)),B:ce(o)}},ge=function(e){var t=M(e.y),n=M(e.z),r=M(me(e.A)),a=M(me(e.B));return{liquidity:t.toString(),lowestRate:le(a).toString(),highestRate:le(a.add(r)).toString(),marginalRate:le(t.eq(n)?a.add(r):a.add(r.mul(t).div(n))).toString()}},be=function(e){return{token0:e.token0,token1:e.token1,order0:fe(e.order0),order1:fe(e.order1)}},he=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:ge(e.order0),order1:ge(e.order1),encoded:e}};function Te(e,t,n,r,a,i,o,s,p,d){if(pe.debug("buildStrategyObject called",arguments),new u.default(a).isNegative()||new u.default(i).isNegative()||new u.default(s).isNegative()||new u.default(p).isNegative())throw new Error("prices cannot be negative");if(new u.default(a).gt(i)||new u.default(s).gt(p))throw new Error("low price must be lower than or equal to high price");if(new u.default(o).isNegative()||new u.default(d).isNegative())throw new Error("budgets cannot be negative");var y=ve(n,r,a,i,o,s,p,d),l=y.order0,c=y.order1;return pe.debug("buildStrategyObject info:",{token0:e,token1:t,order0:l,order1:c}),{token0:e,token1:t,order0:l,order1:c}}function ve(e,t,n,r,a,i,o,u){pe.debug("createOrders called",arguments);var s=te(u,e),p=ue(o,t,e),d=ue(i,t,e),y=te(a,t),l=oe(n,t,e),c=oe(r,t,e),m={liquidity:s,lowestRate:p,highestRate:d,marginalRate:d},f={liquidity:y,lowestRate:l,highestRate:c,marginalRate:c};return pe.debug("createOrders info:",{order0:m,order1:f}),{order0:m,order1:f}}var we=n.BigNumber.from(k),Pe=n.BigNumber.from(2).pow(128).sub(1),ke=n.BigNumber.from(2).pow(256).sub(1);function _e(e,t){if(e.gte(0)&&e.lte(t))return e;throw null}var Se=function(e){return _e(e,Pe)},Me=function(e,t){return _e(e.add(t),ke)},Be=function(e,t){return _e(e.mul(t),ke)},Ae=function(e,t,n){return _e(e.mul(t).div(n),ke)},xe=function(e,t,n){return _e(e.mul(t).add(n).sub(1).div(n),ke)},Ce=function(e,t){var n=e,r=t.y,a=t.z,i=me(t.A),o=me(t.B);try{return Se(function(e,t,n,r,a){if(r.eq(0))return xe(e,Be(we,we),Be(a,a));var i,o,u=Be(n,we),s=Me(Be(t,r),Be(n,a)),p=(i=s,o=Be(e,r),_e(i.sub(o),ke)),d=xe(u,u,ke),y=xe(s,p,ke),l=P(d,y),c=xe(u,u,l),m=Ae(s,p,l);return xe(e,c,m)}(n,r,a,i,o))}catch(e){return ke}},De=function(e,t){var r=w(function(e,t){var r=e,a=t.y,i=t.z,o=me(t.A),u=me(t.B);try{return Se(function(e,t,n,r,a){if(r.eq(0))return Ae(e,Be(a,a),Be(we,we));var i=Be(n,we),o=Me(Be(t,r),Be(n,a)),u=Be(o,e),s=xe(i,i,ke),p=xe(u,r,ke),d=P(s,p),y=xe(i,i,d),l=xe(u,r,d);return Ae(o,u.div(d),Me(y,l))}(r,a,i,o,u))}catch(e){return n.BigNumber.from(0)}}(e,t),t.y);return{input:Ce(r,t),output:r}},Ie=function(e,t){var n=w(e,t.y);return{input:n,output:Ce(n,t)}},Oe=function(e,t,r,a,i){for(var o,u=[],s=l(Object.keys(t).map(function(n){return{id:n,rate:a(e,t[n])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,d=p.id,y=p.rate;if(!e.gt(y.input)){if(e.eq(y.input)){r(y)&&u.push({id:n.BigNumber.from(d),input:y.input,output:y.output});break}var c={input:e,output:a(e,t[d]).output};r(c)&&u.push({id:n.BigNumber.from(d),input:c.input,output:c.output});break}r(y)&&(u.push({id:n.BigNumber.from(d),input:y.input,output:y.output}),e=e.sub(y.input))}return u},Re=function(e){return e.input.gt(0)&&e.output.gt(0)};function Ee(e){return e.reduce(function(e,t){return u.default.min(e,t.lowestRate)},new u.default(Infinity))}function je(e){return e.reduce(function(e,t){return u.default.max(e,t.highestRate)},new u.default(-Infinity))}function Ne(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new u.default(e.liquidity);if(t.gte(e.marginalRate))return new u.default(0);var n=new u.default(e.liquidity),r=new u.default(e.lowestRate).sqrt(),a=new u.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(r)).div(a.sub(r)))}(n,t))},new u.default(0))}var Fe,Ue=new R("index.ts");e.MarginalPriceOptions=void 0,(Fe=e.MarginalPriceOptions||(e.MarginalPriceOptions={})).reset="RESET",Fe.maintain="MAINTAIN";var qe=/*#__PURE__*/function(){function r(e,n){var r=this;this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,this._onChangeCallbacks=[],Ue.debug("SDK class constructor called with",arguments);var a=new t.StaticJsonRpcProvider({url:e.rpcUrl,skipFetchSetup:!0},1);this._api=new Q(a,e.contractAddresses);var i=function(e){return Promise.resolve(null==n?void 0:n(e)).then(function(t){return void 0!==t?t:r._api.reader.getDecimalsByAddress(e)})};ee.init(i)}r.getMatchActions=function(e,t,r){return t?function(e,t,n){return void 0===n&&(n=Re),Oe(e,t,n,Ie,Y)}(n.BigNumber.from(e),r):function(e,t,n){return void 0===n&&(n=Re),Oe(e,t,n,De,X)}(n.BigNumber.from(e),r)};var a=r.prototype;return a._fireOnChange=function(){Ue.debug("firing onChange callbacks"),this._onChangeCallbacks.forEach(function(e){return e()})},a.onChange=function(e){var t=this;if(Ue.debug("onChange called with",arguments),"function"!=typeof e)throw new Error("onChange callback must be a function");return this._onChangeCallbacks.push(e),function(){t._onChangeCallbacks=t._onChangeCallbacks.filter(function(t){return t!==e})}},a.startDataSync=function(){try{var e=this;return Ue.debug("startDataSync called"),e._cache?(Ue.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new v(e._api.reader,e._fireOnChange.bind(e)),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){Ue.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),Ue.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},a.hasLiquidityByPair=function(e,t){if(Ue.debug("hasLiquidityByPair called",arguments),!this._cache)throw Ue.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return Ue.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},a.getLiquidityByPair=function(e,t){try{var r=arguments,a=this;if(Ue.debug("getLiquidityByPair called",r),!a._cache)throw Ue.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=a._cache.getOrders(e,t),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},n.BigNumber.from(0));return Promise.resolve(ee.getInstance().fetchDecimals(t)).then(function(e){var n=ne(o,e);return Ue.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:t,decimals:e,liquidity:n}),n})}catch(e){return Promise.reject(e)}},a.getUserStrategies=function(e){try{var t=arguments,n=this;return Ue.debug("getUserStrategies called",t),Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){function t(){var t=r.map(he);return Promise.resolve(Promise.all(t.map(function(e){try{return Promise.resolve(se(e))}catch(e){return Promise.reject(e)}}))).then(function(n){return Ue.debug("getUserStrategies info:",{ids:e,encodedStrategies:r,decodedStrategies:t,strategies:n}),n})}var r,a=function(){if(!n._cache)return Ue.log("getUserStrategies called before startDataSync - fetching from chain"),Promise.resolve(n._api.reader.getStrategiesByIds(e)).then(function(e){r=e});r=e.map(function(e){var t;return null==(t=n._cache)?void 0:t.getStrategyById(e)}).filter(function(e){return!!e})}();return a&&a.then?a.then(t):t()})}catch(e){return Promise.reject(e)}},a.getMatchParams=function(e,t,r,a){try{var i=arguments,o=this;if(Ue.debug("getMatchParams called",i),!o._cache)throw Ue.log("getMatchParams called before startDataSync"),new Error("startDataSync must be called prior to this action");var u=ee.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(i){return Promise.resolve(u.fetchDecimals(t)).then(function(u){return{orders:o._cache.getOrders(e,t),amountWei:n.BigNumber.from(te(r,a?u:i)).toString(),sourceDecimals:i,targetDecimals:u}})})}catch(e){return Promise.reject(e)}},a.getTradeData=function(e,t,n,a,i){try{var o=arguments,u=this;return Ue.debug("getTradeData called",o),Promise.resolve(u.getMatchParams(e,t,n,a)).then(function(i){var o=i.orders,s=i.amountWei,p=r.getMatchActions(s,a,o);return Promise.resolve(u.getTradeDataFromActions(e,t,a,p)).then(function(e){return Ue.debug("getTradeData info:",{orders:o,amount:n,amountWei:s,res:e}),e})})}catch(e){return Promise.reject(e)}},a.getTradeDataFromActions=function(e,t,r,a){try{var i=arguments,o=this;if(Ue.debug("getTradeDataFromActions called",i),null==o._tradingFeePPM)throw new Error("tradingFeePPM is undefined");var s=o._tradingFeePPM,p=ee.getInstance();return Promise.resolve(p.fetchDecimals(e)).then(function(e){return Promise.resolve(p.fetchDecimals(t)).then(function(t){var i,o,p,d=[],y=[],l=n.BigNumber.from(0),c=n.BigNumber.from(0);if(a.forEach(function(n){d.push({strategyId:n.id,amount:n.input}),y.push(r?{id:n.id,sourceAmount:ne(ae(n.output,s).floor().toFixed(0),e),targetAmount:ne(n.input,t)}:{id:n.id,sourceAmount:ne(n.input,e),targetAmount:ne(ie(n.output,s).floor().toFixed(0),t)}),c=c.add(n.input),l=l.add(n.output)}),r?(i=ae(l,s).floor().toFixed(0),o=c.toString()):(i=c.toString(),o=ie(l,s).floor().toFixed(0)),new u.default(i).isZero()||new u.default(o).isZero())p={tradeActions:d,actionsTokenRes:y,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0",actionsWei:a};else{var m=new u.default(o).div(i).times(S(e,t)).toString();p={tradeActions:d,actionsTokenRes:y,totalSourceAmount:ne(i,e),totalTargetAmount:ne(o,t),effectiveRate:m,actionsWei:a}}return Ue.debug("getTradeDataFromActions info:",{sourceDecimals:e,targetDecimals:t,actionsWei:a,totalInput:c,totalOutput:l,tradingFeePPM:s,res:p}),p})})}catch(e){return Promise.reject(e)}},a.composeTradeByTargetTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return Ue.debug("composeTradeByTargetTransaction called",o),Promise.resolve(ee.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,r,te(a,o),i)})}catch(e){return Promise.reject(e)}},a.composeTradeBySourceTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return Ue.debug("composeTradeBySourceTransaction called",o),Promise.resolve(ee.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,r,te(a,o),i)})}catch(e){return Promise.reject(e)}},a.createBuySellStrategy=function(e,t,n,r,a,i,o,u,s){try{var p=arguments,d=this;Ue.debug("createBuySellStrategy called",p);var y=ee.getInstance();return Promise.resolve(y.fetchDecimals(e)).then(function(p){return Promise.resolve(y.fetchDecimals(t)).then(function(y){var l=Te(e,t,p,y,n,r,a,i,o,u),c=be(l);return Ue.debug("createBuySellStrategy info:",{strategy:l,encStrategy:c}),d._api.composer.createStrategy(c.token0,c.token1,c.order0,c.order1,s)})})}catch(e){return Promise.reject(e)}},a.updateStrategy=function(t,r,a,i,o,u,s,p){var d=o.buyPriceLow,y=o.buyPriceHigh,l=o.buyBudget,c=o.sellPriceLow,m=o.sellPriceHigh,f=o.sellBudget;try{var g=arguments,b=this;Ue.debug("updateStrategy called",g);var h=ee.getInstance();return Promise.resolve(h.fetchDecimals(a)).then(function(o){return Promise.resolve(h.fetchDecimals(i)).then(function(g){var h=he(r);return Promise.resolve(se(h)).then(function(T){var v=Te(a,i,o,g,null!=d?d:T.buyPriceLow,null!=y?y:T.buyPriceHigh,null!=l?l:T.buyBudget,null!=c?c:T.sellPriceLow,null!=m?m:T.sellPriceHigh,null!=f?f:T.sellBudget),w=be(v);if(void 0===l&&(w.order1.y=r.order1.y),void 0===f&&(w.order0.y=r.order0.y),void 0===d&&void 0===y&&(w.order1.A=r.order1.A,w.order1.B=r.order1.B),void 0===c&&void 0===m&&(w.order0.A=r.order0.A,w.order0.B=r.order0.B),void 0!==l&&(void 0===u||u===e.MarginalPriceOptions.reset||r.order1.y.isZero()?w.order1.z=w.order1.y:u===e.MarginalPriceOptions.maintain&&(w.order1.z=A(r.order1.z,w.order1.y,r.order1.y))),void 0!==f&&(void 0===s||s===e.MarginalPriceOptions.reset||r.order0.y.isZero()?w.order0.z=w.order0.y:s===e.MarginalPriceOptions.maintain&&(w.order0.z=A(r.order0.z,w.order0.y,r.order0.y))),void 0===d&&void 0===y||(w.order1.z=w.order1.y),void 0===c&&void 0===m||(w.order0.z=w.order0.y),void 0!==u&&u!==e.MarginalPriceOptions.reset&&u!==e.MarginalPriceOptions.maintain)throw new Error("Support for custom marginal price is not implemented yet");if(void 0!==s&&s!==e.MarginalPriceOptions.reset&&s!==e.MarginalPriceOptions.maintain)throw new Error("Support for custom marginal price is not implemented yet");return Ue.debug("updateStrategy info:",{baseDecimals:o,quoteDecimals:g,decodedOriginal:h,originalStrategy:T,newStrategy:v,newEncodedStrategy:w}),b._api.composer.updateStrategy(n.BigNumber.from(t),w.token0,w.token1,[r.order0,r.order1],[w.order0,w.order1],p)})})})}catch(e){return Promise.reject(e)}},a.deleteStrategy=function(e){return Ue.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(n.BigNumber.from(e))},a.getRateLiquidityDepthByPair=function(e,t,n){try{var r=arguments,a=this;if(Ue.debug("getRateLiquidityDepthByPair called",r),!a._cache)throw Ue.log("getRateLiquidityDepthByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=Object.values(a._cache.getOrders(e,t)).map(ge),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var r=oe(n,t,e),a=Ne(i,new u.default(r)).toFixed(0),o=ne(a,t);return Ue.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:a,targetDecimals:t,depthInTargetDecimals:o}),o})})}catch(e){return Promise.reject(e)}},a.getMinRateByPair=function(e,t){try{var n=arguments,r=this;if(Ue.debug("getMinRateByPair called",n),!r._cache)throw Ue.log("getMinRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var a=Object.values(r._cache.getOrders(e,t)).map(ge),i=Ee(a).toString(),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=oe(i,e,t);return Ue.debug("getMinRateByPair info:",{orders:a,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getMaxRateByPair=function(e,t){try{var n=arguments,r=this;if(Ue.debug("getMaxRateByPair called",n),!r._cache)throw Ue.log("getMaxRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var a=Object.values(r._cache.getOrders(e,t)).map(ge),i=je(a).toString(),o=ee.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=oe(i,e,t);return Ue.debug("getMaxRateByPair info:",{orders:a,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getLastTradeByPair=function(e,t){try{var n=arguments,r=this;return Ue.debug("getLastTradeByPair called",n),Promise.resolve(r._api.reader.getLatestTradeByPair(e,t)).then(function(n){return Ue.debug("getLastTradeByPair info:",{sourceToken:e,targetToken:t,lastTrade:n}),n})}catch(e){return Promise.reject(e)}},p(r,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(Ue.debug("pairs called"),!this._cache)throw Ue.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),r}();e.Sdk=qe});
//# sourceMappingURL=sdk.umd.js.map

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

"source": "src/index.ts",
"version": "0.0.53-DEV",
"version": "0.0.54-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",

@@ -47,3 +47,3 @@ "main": "dist/sdk.umd.js",

"@types/mocha": "^10.0.0",
"@types/node": "^18.14.6",
"@types/node": "^18.15.2",
"@types/proxyquire": "^1.3.28",

@@ -55,3 +55,3 @@ "@types/sinon": "^10.0.13",

"proxyquire": "^2.1.3",
"sinon": "^15.0.1",
"sinon": "^15.0.2",
"ts-node": "^10.9.1",

@@ -58,0 +58,0 @@ "typechain": "^8.1.1",

@@ -30,2 +30,4 @@ import { BigNumber } from '../numerics';

tradeActions,
true,
maxInput,
overrides

@@ -59,2 +61,4 @@ );

tradeActions,
false,
-1,
overrides

@@ -61,0 +65,0 @@ );

import { BigNumber } from '../numerics';
import { PayableOverrides } from 'ethers';
import { BigNumberish, PayableOverrides } from 'ethers';
import { TradeActionStruct } from '../abis/types/CarbonController';

@@ -12,14 +12,20 @@

export const buildTradeOverrides = (
token: string,
sourceToken: string,
tradeActions: TradeActionStruct[],
byTarget: boolean,
maxInput: BigNumberish,
overrides?: PayableOverrides
): PayableOverrides => {
const customOverrides = { ...overrides };
if (isETHAddress(token)) {
customOverrides.value = tradeActions.reduce(
(acc, cur) => acc.add(cur.amount as BigNumber),
BigNumber.from(0)
);
if (isETHAddress(sourceToken)) {
if (byTarget) {
customOverrides.value = BigNumber.from(maxInput);
} else {
customOverrides.value = tradeActions.reduce(
(acc, cur) => acc.add(cur.amount as BigNumberish),
BigNumber.from(0)
);
}
}
return customOverrides;
};

@@ -432,3 +432,8 @@ import { PopulatedTransaction } from '@ethersproject/contracts';

logger.debug('getTradeDataFromActions called', arguments);
// intentional == instead of ===
if (this._tradingFeePPM == undefined)
throw new Error('tradingFeePPM is undefined');
const feePPM = this._tradingFeePPM;
const decimals = Decimals.getInstance();

@@ -447,13 +452,22 @@ const sourceDecimals = await decimals.fetchDecimals(sourceToken);

});
actionsTokenRes.push({
id: action.id,
sourceAmount: formatUnits(
tradeByTargetAmount ? action.output : action.input,
sourceDecimals
),
targetAmount: formatUnits(
tradeByTargetAmount ? action.input : action.output,
targetDecimals
),
});
if (tradeByTargetAmount) {
actionsTokenRes.push({
id: action.id,
sourceAmount: formatUnits(
addFee(action.output, feePPM).floor().toFixed(0),
sourceDecimals
),
targetAmount: formatUnits(action.input, targetDecimals),
});
} else {
actionsTokenRes.push({
id: action.id,
sourceAmount: formatUnits(action.input, sourceDecimals),
targetAmount: formatUnits(
subtractFee(action.output, feePPM).floor().toFixed(0),
targetDecimals
),
});
}
totalInput = totalInput.add(action.input);

@@ -465,16 +479,8 @@ totalOutput = totalOutput.add(action.output);

// intentional == instead of ===
if (this._tradingFeePPM == undefined)
throw new Error('tradingFeePPM is undefined');
if (tradeByTargetAmount) {
totalSourceAmount = addFee(totalOutput, this._tradingFeePPM)
.floor()
.toFixed(0);
totalSourceAmount = addFee(totalOutput, feePPM).floor().toFixed(0);
totalTargetAmount = totalInput.toString();
} else {
totalSourceAmount = totalInput.toString();
totalTargetAmount = subtractFee(totalOutput, this._tradingFeePPM)
.floor()
.toFixed(0);
totalTargetAmount = subtractFee(totalOutput, feePPM).floor().toFixed(0);
}

@@ -518,3 +524,3 @@

totalOutput,
tradingFeePPM: this._tradingFeePPM,
tradingFeePPM: feePPM,
res,

@@ -521,0 +527,0 @@ });

@@ -20,2 +20,4 @@ import { BigNumber, PayableOverrides } from 'ethers';

tradeActions as TradeActionStruct[],
false,
-1,
overrides

@@ -28,2 +30,4 @@ ).value?.toString()

tradeActions as TradeActionStruct[],
false,
-1,
overrides

@@ -30,0 +34,0 @@ ).value?.toString()

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc