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
104
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.47-DEV to 0.0.48-DEV

tests/test-utils.ts

30

dist/abis/types/factories/CarbonController__factory.d.ts

@@ -6,10 +6,2 @@ import { Signer } from "ethers";

static readonly abi: readonly [{
readonly inputs: readonly [];
readonly name: "AccessDenied";
readonly type: "error";
}, {
readonly inputs: readonly [];
readonly name: "InvalidAddress";
readonly type: "error";
}, {
readonly anonymous: false;

@@ -57,3 +49,3 @@ readonly inputs: readonly [{

readonly internalType: "address";
readonly name: "";
readonly name: "admin_";
readonly type: "address";

@@ -68,3 +60,3 @@ }];

readonly internalType: "address";
readonly name: "";
readonly name: "implementation_";
readonly type: "address";

@@ -103,2 +95,6 @@ }];

readonly inputs: readonly [];
readonly name: "AccessDenied";
readonly type: "error";
}, {
readonly inputs: readonly [];
readonly name: "AlreadyInitialized";

@@ -124,2 +120,6 @@ readonly type: "error";

readonly inputs: readonly [];
readonly name: "InvalidAddress";
readonly type: "error";
}, {
readonly inputs: readonly [];
readonly name: "InvalidFee";

@@ -133,2 +133,6 @@ readonly type: "error";

readonly inputs: readonly [];
readonly name: "InvalidRate";
readonly type: "error";
}, {
readonly inputs: readonly [];
readonly name: "InvalidStrategyId";

@@ -1341,11 +1345,11 @@ readonly type: "error";

readonly internalType: "address";
readonly name: "logic";
readonly name: "_logic";
readonly type: "address";
}, {
readonly internalType: "address";
readonly name: "initAdmin";
readonly name: "admin_";
readonly type: "address";
}, {
readonly internalType: "bytes";
readonly name: "data";
readonly name: "_data";
readonly type: "bytes";

@@ -1352,0 +1356,0 @@ }];

@@ -76,2 +76,32 @@ import { Signer } from "ethers";

readonly inputs: readonly [{
readonly indexed: false;
readonly internalType: "string";
readonly name: "newBaseExtension";
readonly type: "string";
}];
readonly name: "BaseExtensionUpdated";
readonly type: "event";
}, {
readonly anonymous: false;
readonly inputs: readonly [{
readonly indexed: false;
readonly internalType: "string";
readonly name: "newBaseURI";
readonly type: "string";
}];
readonly name: "BaseURIUpdated";
readonly type: "event";
}, {
readonly anonymous: false;
readonly inputs: readonly [{
readonly indexed: false;
readonly internalType: "contract CarbonController";
readonly name: "carbonController";
readonly type: "address";
}];
readonly name: "CarbonControllerUpdated";
readonly type: "event";
}, {
readonly anonymous: false;
readonly inputs: readonly [{
readonly indexed: true;

@@ -110,3 +140,13 @@ readonly internalType: "address";

}, {
readonly anonymous: false;
readonly inputs: readonly [{
readonly indexed: false;
readonly internalType: "bool";
readonly name: "newUseGlobalURI";
readonly type: "bool";
}];
readonly name: "UseGlobalURIUpdated";
readonly type: "event";
}, {
readonly inputs: readonly [{
readonly internalType: "address";

@@ -113,0 +153,0 @@ readonly name: "to";

@@ -100,9 +100,17 @@ import type { BaseContract, BigNumber, BigNumberish, BytesLike, CallOverrides, ContractTransaction, Overrides, PopulatedTransaction, Signer, utils } from "ethers";

"ApprovalForAll(address,address,bool)": EventFragment;
"BaseExtensionUpdated(string)": EventFragment;
"BaseURIUpdated(string)": EventFragment;
"CarbonControllerUpdated(address)": EventFragment;
"OwnershipTransferred(address,address)": EventFragment;
"Transfer(address,address,uint256)": EventFragment;
"UseGlobalURIUpdated(bool)": EventFragment;
};
getEvent(nameOrSignatureOrTopic: "Approval"): EventFragment;
getEvent(nameOrSignatureOrTopic: "ApprovalForAll"): EventFragment;
getEvent(nameOrSignatureOrTopic: "BaseExtensionUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "BaseURIUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "CarbonControllerUpdated"): EventFragment;
getEvent(nameOrSignatureOrTopic: "OwnershipTransferred"): EventFragment;
getEvent(nameOrSignatureOrTopic: "Transfer"): EventFragment;
getEvent(nameOrSignatureOrTopic: "UseGlobalURIUpdated"): EventFragment;
}

@@ -131,2 +139,23 @@ export interface ApprovalEventObject {

export type ApprovalForAllEventFilter = TypedEventFilter<ApprovalForAllEvent>;
export interface BaseExtensionUpdatedEventObject {
newBaseExtension: string;
}
export type BaseExtensionUpdatedEvent = TypedEvent<[
string
], BaseExtensionUpdatedEventObject>;
export type BaseExtensionUpdatedEventFilter = TypedEventFilter<BaseExtensionUpdatedEvent>;
export interface BaseURIUpdatedEventObject {
newBaseURI: string;
}
export type BaseURIUpdatedEvent = TypedEvent<[
string
], BaseURIUpdatedEventObject>;
export type BaseURIUpdatedEventFilter = TypedEventFilter<BaseURIUpdatedEvent>;
export interface CarbonControllerUpdatedEventObject {
carbonController: string;
}
export type CarbonControllerUpdatedEvent = TypedEvent<[
string
], CarbonControllerUpdatedEventObject>;
export type CarbonControllerUpdatedEventFilter = TypedEventFilter<CarbonControllerUpdatedEvent>;
export interface OwnershipTransferredEventObject {

@@ -152,2 +181,9 @@ previousOwner: string;

export type TransferEventFilter = TypedEventFilter<TransferEvent>;
export interface UseGlobalURIUpdatedEventObject {
newUseGlobalURI: boolean;
}
export type UseGlobalURIUpdatedEvent = TypedEvent<[
boolean
], UseGlobalURIUpdatedEventObject>;
export type UseGlobalURIUpdatedEventFilter = TypedEventFilter<UseGlobalURIUpdatedEvent>;
export interface Voucher extends BaseContract {

@@ -303,2 +339,8 @@ connect(signerOrProvider: Signer | Provider | string): this;

ApprovalForAll(owner?: PromiseOrValue<string> | null, operator?: PromiseOrValue<string> | null, approved?: null): ApprovalForAllEventFilter;
"BaseExtensionUpdated(string)"(newBaseExtension?: null): BaseExtensionUpdatedEventFilter;
BaseExtensionUpdated(newBaseExtension?: null): BaseExtensionUpdatedEventFilter;
"BaseURIUpdated(string)"(newBaseURI?: null): BaseURIUpdatedEventFilter;
BaseURIUpdated(newBaseURI?: null): BaseURIUpdatedEventFilter;
"CarbonControllerUpdated(address)"(carbonController?: null): CarbonControllerUpdatedEventFilter;
CarbonControllerUpdated(carbonController?: null): CarbonControllerUpdatedEventFilter;
"OwnershipTransferred(address,address)"(previousOwner?: PromiseOrValue<string> | null, newOwner?: PromiseOrValue<string> | null): OwnershipTransferredEventFilter;

@@ -308,2 +350,4 @@ OwnershipTransferred(previousOwner?: PromiseOrValue<string> | null, newOwner?: PromiseOrValue<string> | null): OwnershipTransferredEventFilter;

Transfer(from?: PromiseOrValue<string> | null, to?: PromiseOrValue<string> | null, tokenId?: PromiseOrValue<BigNumberish> | null): TransferEventFilter;
"UseGlobalURIUpdated(bool)"(newUseGlobalURI?: null): UseGlobalURIUpdatedEventFilter;
UseGlobalURIUpdated(newUseGlobalURI?: null): UseGlobalURIUpdatedEventFilter;
};

@@ -310,0 +354,0 @@ estimateGas: {

@@ -1,3 +0,7 @@

import { BigNumber } from './numerics';
import { BigNumber, Decimal } from './numerics';
import { DecodedOrder, DecodedStrategy, EncodedOrder, EncodedStrategy, Strategy } from './types';
export declare const encodeRate: (value: Decimal) => Decimal;
export declare const decodeRate: (value: Decimal) => Decimal;
export declare const encodeFloat: (value: BigNumber) => BigNumber;
export declare const decodeFloat: (value: BigNumber) => BigNumber;
export declare const encodeOrder: (order: DecodedOrder) => EncodedOrder;

@@ -4,0 +8,0 @@ export declare const decodeOrder: (order: EncodedOrder) => DecodedOrder;

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

import { EncodedOrder, Rate, MatchAction, Filter } from '../types';
import { EncodedOrder, MatchAction, Filter } from '../types';
import { BigNumber } from '../numerics';

@@ -6,7 +6,4 @@ export type OrdersMap = {

};
export declare const getRateBySourceAmount: (sourceAmount: BigNumber, order: EncodedOrder) => Rate;
export declare const getRateByTargetAmount: (targetAmount: BigNumber, order: EncodedOrder) => Rate;
export declare const match: (amount: BigNumber, orders: OrdersMap, filter: Filter, trade: (amount: BigNumber, order: EncodedOrder) => Rate, cmp: (x: Rate, y: Rate) => number) => MatchAction[];
export declare const matchBySourceAmount: (amount: BigNumber, orders: OrdersMap, filter?: Filter) => MatchAction[];
export declare const matchByTargetAmount: (amount: BigNumber, orders: OrdersMap, filter?: Filter) => MatchAction[];
//# sourceMappingURL=match.d.ts.map

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

import { BigNumber, Decimal } from '../numerics';
import { Decimal, BigNumber } from '../numerics';
import { EncodedOrder, DecodedOrder } from '../types';

@@ -3,0 +3,0 @@ export declare const getEncodedTradeTargetAmount: (amount: BigNumber, order: EncodedOrder) => BigNumber;

import { BigNumber } from '@ethersproject/bignumber';
import Decimal from 'decimal.js';
declare const BigNumberMin: (a: BigNumber, b: BigNumber) => BigNumber;
declare const BigNumberMax: (a: BigNumber, b: BigNumber) => BigNumber;
declare const ONE: number;
declare const TEN: Decimal;
declare const tenPow: (dec0: number, dec1: number) => Decimal;
export { Decimal, BigNumber, ONE, TEN, tenPow };
declare const BnToDec: (x: BigNumber) => Decimal;
declare const DecToBn: (x: Decimal) => BigNumber;
export { Decimal, BigNumber, BigNumberMin, BigNumberMax, ONE, TEN, tenPow, BnToDec, DecToBn, };
//# sourceMappingURL=numerics.d.ts.map

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):(e||self).carbonSdk=t(e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,a,r){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/i(n);function u(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,"symbol"==typeof(r=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var a=n.call(e,"string");if("object"!=typeof a)return a;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(a.key))?r:String(r),a)}var r}function s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var a in n)Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a])}return e},p.apply(this,arguments)}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,a=new Array(t);n<t;n++)a[n]=e[n];return a}function d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var l=function(e,t){return e.localeCompare(t)},c="->-<-",m=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(c)},f=function(e,t){return m([e,t].sort(l))},g=function(e){var t=e.split(c);return[t[0],t[1]]},b=function(e,t){return m([e,t])},T=function(e,t,n){if(0!==n.size){var a,r;0===t?(a=e.order0,r=b(e.token1,e.token0)):(a=e.order1,r=b(e.token0,e.token1));var i,o=n.get(r);o?o[e.id.toString()]=a:(console.warn("Should not be here, modified order is supposed to already be cached"),n.set(r,((i={})[e.id.toString()]=a,i)))}},h=/*#__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,a=0;a<t.length;a++){var r=t[a],i=e[a],o=f(r[0],r[1]);n.set(o,i)}return n})})}catch(e){return Promise.reject(e)}}(e._fetcher)).then(function(t){e._pairToStrategies=t;for(var n,a=d(e._pairToStrategies.values());!(n=a()).done;){var r=n.value;if(r&&r.length>0)for(var i=0;i<r.length;i++)e._strategyById.set(r[i].id.toString(),r[i])}e._fetcher.onStrategyCreated(function(t){!function(e,t,n,a){if(!n.has(e.id.toString())){n.set(e.id.toString(),e);var r=f(e.token0,e.token1);if(t.has(r)?t.get(r).push(e):t.set(r,[e]),0!==a.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u,s=o[i],p=b(s[0],s[1]),y=s[0]===e.token0?e.order1:e.order0,d=a.get(p);d?d[e.id.toString()]=y:a.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,a){n.set(e.id.toString(),e);var r=f(e.token0,e.token1);t.has(r)?t.set(r,t.get(r).map(function(t){return t.id===e.id?e:t})):t.set(r,[e]),T(e,0,a),T(e,1,a)}(t,e._pairToStrategies,e._strategyById,e._cachedOrders),null==e._onChange||e._onChange()}),e._fetcher.onStrategyDeleted(function(t){!function(e,t,n,a){if(n.has(e.id.toString())){n.delete(e.id.toString());var r=f(e.token0,e.token1);if(t.has(r)&&t.set(r,t.get(r).filter(function(t){return t.id!==e.id})),0===t.get(r).length&&t.delete(r),0!==a.size)for(var i=0,o=[[e.token0,e.token1],[e.token1,e.token0]];i<o.length;i++){var u=o[i],s=b(u[0],u[1]),p=a.get(s);p&&(delete p[e.id.toString()],0===Object.keys(p).length&&a.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 a;if(void 0===n&&(n=!1),0===this._pairToStrategies.size)return console.warn("getOrders was called when no strategies are cached, did you call init?"),{};0===this._cachedOrders.size&&function(e,t){t.clear();for(var n,a=d(e.values());!(n=a()).done;){var r=n.value;if(r.length>0){for(var i=r[0].token0,o=r[0].token1,u={},s={},p=0;p<r.length;p++)r[p].token0===i?(u[r[p].id.toString()]=r[p].order0,s[r[p].id.toString()]=r[p].order1):(u[r[p].id.toString()]=r[p].order1,s[r[p].id.toString()]=r[p].order0);t.set(b(i,o),s),t.set(b(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var r=b(e,t),i=null!=(a=this._cachedOrders.get(r))?a:{};if(n)return i;var o=Object.entries(i).filter(function(e){return e[1].y.gt(0)&&(e[1].A.gt(0)||e[1].B.gt(0))});return Object.fromEntries(o)},t.getStrategyById=function(e){return this._strategyById.get(e.toString())},s(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys()).map(g)}}]),e}();o.default.set({precision:50,rounding:o.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var v=Math.pow(2,32),w=new o.default(10),k=function(e,t){return w.pow(e-t)},_="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),P=function(e){return e.toLowerCase()===_},S=function(e,n,a){var r=p({},a);return P(e)&&(r.value=n.reduce(function(e,t){return e.add(t.amount)},t.BigNumber.from(0))),r},M=/*#__PURE__*/function(){function e(e){this._prefix=void 0,this._prefix="[SDK]["+e+"]:"}var t=e.prototype;return t.log=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},t.debug=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),A=new M("Composer.ts"),B=/*#__PURE__*/function(){function e(e){this._contracts=void 0,this._contracts=e}var t=e.prototype;return t.tradeByTargetAmount=function(e,t,n,a,r,i){A.debug("tradeByTargetAmount called",arguments);var o=S(e,n,i);return A.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,a,r,o)},t.tradeBySourceAmount=function(e,t,n,a,r,i){A.debug("tradeBySourceAmount called",arguments);var o=S(e,n,i);return A.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,a,r,o)},t.createStrategy=function(e,t,n,a,r){A.debug("createStrategy called",arguments);var i=p({},r);return P(e)?i.value=n.y:P(t)&&(i.value=a.y),A.debug("createStrategy overrides",i),this._contracts.carbonController.populateTransaction.createStrategy(e,t,[n,a],i)},t.deleteStrategy=function(e){return this._contracts.carbonController.populateTransaction.deleteStrategy(e)},t.updateStrategy=function(e,t,n,a){return this._contracts.carbonController.populateTransaction.updateStrategy(e,t,n,a)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),x=[{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"previousAdmin",type:"address"},{indexed:!1,internalType:"address",name:"newAdmin",type:"address"}],name:"AdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"beacon",type:"address"}],name:"BeaconUpgraded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"implementation",type:"address"}],name:"Upgraded",type:"event"},{stateMutability:"payable",type:"fallback"},{inputs:[],name:"admin",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"implementation",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"}],name:"upgradeTo",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newImplementation",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"upgradeToAndCall",outputs:[],stateMutability:"payable",type:"function"},{stateMutability:"payable",type:"receive"},{inputs:[],name:"AlreadyInitialized",type:"error"},{inputs:[],name:"DeadlineExpired",type:"error"},{inputs:[],name:"GreaterThanMaxInput",type:"error"},{inputs:[],name:"IdenticalAddresses",type:"error"},{inputs:[],name:"InsufficientCapacity",type:"error"},{inputs:[],name:"InvalidFee",type:"error"},{inputs:[],name:"InvalidIndices",type:"error"},{inputs:[],name:"InvalidStrategyId",type:"error"},{inputs:[],name:"InvalidTradeActionAmount",type:"error"},{inputs:[],name:"LowerThanMinReturn",type:"error"},{inputs:[],name:"NativeAmountMismatch",type:"error"},{inputs:[],name:"NoIdsProvided",type:"error"},{inputs:[],name:"OutDated",type:"error"},{inputs:[],name:"Overflow",type:"error"},{inputs:[],name:"PoolAlreadyExists",type:"error"},{inputs:[],name:"PoolDoesNotExists",type:"error"},{inputs:[],name:"StrategyDoesNotExist",type:"error"},{inputs:[],name:"TokensMismatch",type:"error"},{inputs:[],name:"UnknownDelegator",type:"error"},{inputs:[],name:"UnnecessaryNativeTokenReceived",type:"error"},{inputs:[],name:"UnsetDelegator",type:"error"},{inputs:[],name:"ZeroLiquidityProvided",type:"error"},{inputs:[],name:"ZeroValue",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"poolId",type:"uint256"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"}],name:"PoolCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyDeleted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"trader",type:"address"},{indexed:!0,internalType:"address",name:"sourceToken",type:"address"},{indexed:!0,internalType:"address",name:"targetToken",type:"address"},{indexed:!1,internalType:"uint256",name:"sourceAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"targetAmount",type:"uint256"},{indexed:!1,internalType:"uint128",name:"tradingFeeAmount",type:"uint128"},{indexed:!1,internalType:"bool",name:"byTargetAmount",type:"bool"}],name:"TokensTraded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"prevFeePPM",type:"uint32"},{indexed:!1,internalType:"uint32",name:"newFeePPM",type:"uint32"}],name:"TradingFeePPMUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"accumulatedFees",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"controllerType",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"createPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],name:"createStrategy",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"deleteStrategy",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pairs",outputs:[{internalType:"address[2][]",name:"",type:"address[2][]"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"pool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"}],name:"postUpgrade",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"roleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[],name:"roleEmergencyStopper",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint32",name:"newTradingFeePPM",type:"uint32"}],name:"setTradingFeePPM",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256[]",name:"ids",type:"uint256[]"}],name:"strategiesByIds",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"endIndex",type:"uint256"}],name:"strategiesByPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"strategiesByPoolCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"}],name:"strategy",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"minReturn",type:"uint128"}],name:"tradeBySourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"maxInput",type:"uint128"}],name:"tradeByTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeSourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"tradingFeePPM",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"currentOrders",type:"tuple[2]"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"newOrders",type:"tuple[2]"}],name:"updateStrategy",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"address",name:"newOwner",type:"address"}],name:"updateStrategyOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"logic",type:"address"},{internalType:"address",name:"initAdmin",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],D=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(x)},e.connect=function(e,t){return new a.Contract(e,x,t)},e}();D.abi=x;var I=[{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"}],C=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(I)},e.connect=function(e,t){return new a.Contract(e,I,t)},e}();C.abi=I;var O=[{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"}],R=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(O)},e.connect=function(e,t){return new a.Contract(e,O,t)},e}();R.abi=O;var j=[{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"},{internalType:"string",name:"newBaseURI",type:"string"},{internalType:"string",name:"newBaseExtension",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"AccessDenied",type:"error"},{inputs:[],name:"CarbonControllerNotSet",type:"error"},{inputs:[],name:"InvalidAddress",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"approved",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"operator",type:"address"},{indexed:!1,internalType:"bool",name:"approved",type:"bool"}],name:"ApprovalForAll",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!0,internalType:"uint256",name:"tokenId",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"approve",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"getApproved",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"operator",type:"address"}],name:"isApprovedForAll",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"provider",type:"address"},{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"ownerOf",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],name:"safeTransferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"operator",type:"address"},{internalType:"bool",name:"approved",type:"bool"}],name:"setApprovalForAll",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseExtension",type:"string"}],name:"setBaseExtension",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"string",name:"newBaseURI",type:"string"}],name:"setBaseURI",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract CarbonController",name:"carbonController",type:"address"}],name:"setCarbonController",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"index",type:"uint256"}],name:"tokenOfOwnerByIndex",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"tokenURI",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"tokenId",type:"uint256"}],name:"transferFrom",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"newUseGlobalURI",type:"bool"}],name:"useGlobalURI",outputs:[],stateMutability:"nonpayable",type:"function"}],F=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new a.utils.Interface(j)},e.connect=function(e,t){return new a.Contract(e,j,t)},e}();F.abi=j;var E={carbonControllerAddress:"0x8b604f9d7f96fa5b9f635f27bfabdcb152015742",multiCallAddress:"0x5ba1e12693dc8f9c48aad8770482f4739beed696",voucherAddress:"0x78d59e4e207572b506788e57bd0823be21a3a373"},N=/*#__PURE__*/function(){function e(e,t){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._config=E,this._provider=e,this._config.carbonControllerAddress=(null==t?void 0:t.carbonControllerAddress)||E.carbonControllerAddress,this._config.multiCallAddress=(null==t?void 0:t.multiCallAddress)||E.multiCallAddress,this._config.voucherAddress=(null==t?void 0:t.voucherAddress)||E.voucherAddress}return e.prototype.token=function(e){return R.connect(e,this._provider)},s(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=D.connect(this._config.carbonControllerAddress,this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=C.connect(this._config.multiCallAddress,this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=F.connect(this._config.voucherAddress,this._provider)),this._voucher}}]),e}(),q=new M("Reader.ts");function U(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 z(e,t){return function(n,a,r,i,o,u){q.debug(e+" fired with",arguments);var s={id:n,token0:r,token1:i,order0:{y:o.y,z:o.z,A:o.A,B:o.B},order1:{y:u.y,z:u.z,A:u.A,B:u.B}};q.debug(e+" parsed strategy:",s),t(s)}}var L=/*#__PURE__*/function(){function e(e){var t=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return P(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this._contracts=e}var t=e.prototype;return t.multicall=function(e,t){return function(e,t,n){return Promise.resolve(function(a,r){try{var i=(o=e.map(function(e){return{target:e.contractAddress.toLocaleLowerCase(),callData:e.interface.encodeFunctionData(e.methodName,e.methodParameters)}}),Promise.resolve(t.tryAggregate(!1,o,{blockTag:n})).then(function(t){return t.map(function(t,n){return t.success?e[n].interface.decodeFunctionResult(e[n].methodName,t.returnData):[]})}))}catch(e){return}var o;return i&&i.then?i.then(void 0,function(){}):i}())}(e,this._contracts.multicall,t)},t.getStrategyById=function(e){try{return Promise.resolve(this._contracts.carbonController.strategy(e)).then(U)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=function(e){try{return Promise.resolve(this._contracts.carbonController.strategiesByIds(e)).then(function(e){return e.map(function(e){return U(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 U(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 U(e)})}):[]})}catch(e){return Promise.reject(e)}},t.getUserStrategyIds=function(e){try{var t=this;return e?Promise.resolve(t._contracts.voucher.balanceOf(e)).then(function(n){var a=Array.from(Array(n.toNumber()),function(n,a){return{contractAddress:t._contracts.voucher.address,interface:t._contracts.voucher.interface,methodName:"tokenOfOwnerByIndex",methodParameters:[e,a]}});return Promise.resolve(t.multicall(a)).then(function(e){return e?e.map(function(e){return e[0]}):[]})}):Promise.resolve([])}catch(e){return Promise.reject(e)}},t.tradingFeePPM=function(){return this._contracts.carbonController.tradingFeePPM()},t.onTradingFeePPMUpdated=function(e){return this._contracts.carbonController.on("TradingFeePPMUpdated",function(t,n){q.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",z("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",z("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",z("StrategyUpdated",e))},e}(),H=/*#__PURE__*/function(){function e(e,t){this._reader=void 0,this._composer=void 0;var n=new N(e,t);this._reader=new L(n),this._composer=new B(n)}return s(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),G=function(e,t){var n=e.output.mul(t.input),a=t.output.mul(e.input),r=n.lt(a),i=n.gt(a),o=!r&&!i;return+(r||o&&e.output.lt(t.output))-+(i||o&&e.output.gt(t.output))},Z=function(e,t){return G(t,e)},W=t.BigNumber.from(0),K=t.BigNumber.from(2).pow(128).sub(1),V=function(e,t){var n=e,a=t.y,r=t.z,i=t.A,o=t.B,u=r.mul(v),s=a.mul(i).add(r.mul(o)),p=s.sub(n.mul(i)),y=function(e,t,n){return e.mul(t).add(n).sub(1).div(n)}(n.mul(u),u,s.mul(p));return y.lt(W)?K:y},J=function(e,t){var n=function(e,t){var n=e,a=t.z,r=t.A,i=t.B,o=t.y.mul(r).add(a.mul(i)),u=o.mul(n).div(v),s=u.mul(r).add(a.mul(a).mul(v)),p=function(e,t,n){return e.mul(t).div(n)}(o,u,s);return p.gt(K)?W:p}(e,t),a=n.lt(t.y)?n:t.y;return{input:V(a,t),output:a}},$=function(e,t){var n=e.lt(t.y)?e:t.y;return{input:n,output:V(n,t)}},Q=function(e,n,a,r,i){for(var o,u=[],s=d(Object.keys(n).map(function(t){return{id:t,rate:r(e,n[t])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,y=p.id,l=p.rate;if(!e.gt(l.input)){if(e.eq(l.input)){a(l)&&u.push({id:t.BigNumber.from(y),input:l.input,output:l.output});break}var c={input:e,output:r(e,n[y]).output};a(c)&&u.push({id:t.BigNumber.from(y),input:c.input,output:c.output});break}a(l)&&(u.push({id:t.BigNumber.from(y),input:l.input,output:l.output}),e=e.sub(l.input))}return u},X=function(e,t,n){return void 0===n&&(n=function(e){return!0}),Q(e,t,n,J,G)},Y=function(e,t,n){return void 0===n&&(n=function(e){return!0}),Q(e,t,n,$,Z)};function ee(e,t){var n,a,i,o=(a=t,-1!==(i=(n=e).indexOf("."))?n.slice(0,i+a+1):n);return r.parseUnits(o,t).toString()}function te(e,t){var n=r.formatUnits(e,t);return new o.default(n).toFixed()}var ne=1e6;function ae(e,t){return new o.default(e.toString()).mul(ne).div(ne-t).ceil()}function re(e,t){return new o.default(e.toString()).mul(ne-t).div(ne).floor()}function ie(e,t,n){return new o.default(e.toString()).times(k(t,n)).toFixed()}function oe(e,t,n){return 0==+e.toString()?"0":new o.default(1).div(e.toString()).times(k(n,t)).toFixed()}var ue=/*#__PURE__*/function(){function e(){this._cachedDecimals=void 0,this._cachedDecimals=new Map}return e.init=function(t){e._fetcher=t,e.getInstance().cachedDecimals.clear()},e.getInstance=function(){if(!e._instance){if(!e._fetcher)throw new Error("Decimals has not been initialized with a fetcher function");e._instance=new e}return e._instance},e.prototype.fetchDecimals=function(t){try{var n=this,a=n._cachedDecimals.get(t);return void 0!==a?Promise.resolve(a):Promise.resolve(e._fetcher(t)).then(function(e){if(void 0===(a=e))throw new Error("Could not fetch decimals for token "+t);return n._cachedDecimals.set(t,a),a})}catch(e){return Promise.reject(e)}},s(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();ue._instance=void 0,ue._fetcher=void 0;var se=function(e){try{var t=arguments;pe.debug("decodeStrategy called",t);var n=e.id,a=e.token0,r=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=ue.getInstance();return Promise.resolve(s.fetchDecimals(a)).then(function(e){return Promise.resolve(s.fetchDecimals(r)).then(function(t){var s=ie(o.lowestRate,e,t),p=ie(o.highestRate,e,t),y=oe(i.highestRate,t,e),d=oe(i.lowestRate,t,e),l=te(i.liquidity,e),c=te(o.liquidity,t);return pe.debug("decodeStrategy info:",{id:n,token0:a,token1:r,order0:i,order1:o,decimals0:e,decimals1:t,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l}),{id:n,baseToken:a,quoteToken:r,buyPriceLow:s,buyPriceHigh:p,buyBudget:c,sellPriceLow:y,sellPriceHigh:d,sellBudget:l,encoded:u}})})}catch(e){return Promise.reject(e)}},pe=new M("encoders.ts"),ye=function(e){return e.sqrt().mul(v)},de=function(e){return e.div(v).pow(2)},le=function(e){var n=t.BigNumber.from(new o.default(e.liquidity).toFixed()),a=t.BigNumber.from(ye(new o.default(e.lowestRate)).floor().toFixed()),r=t.BigNumber.from(ye(new o.default(e.highestRate)).floor().toFixed()),i=t.BigNumber.from(ye(new o.default(e.marginalRate)).floor().toFixed());if(!(r.gte(i)&&i.gt(a)||r.eq(i)&&i.eq(a)))throw new Error("Invalid order: max must be greater than or equal to mid, and mid must be greater than min \n - or the three should be equal (highestRate: "+e.highestRate+", \n marginalRate: "+e.marginalRate+", lowestRate: "+e.lowestRate+")");var u=r.sub(a);return{y:n,z:u.isZero()?n:n.mul(u).div(i.sub(a)),A:u,B:a}},ce=function(e){var t=new o.default(e.y.toString()),n=new o.default(e.z.toString()),a=new o.default(e.A.toString()),r=new o.default(e.B.toString()),i=t.eq(n)?new o.default(1):t.div(n);return{liquidity:t.toString(),lowestRate:de(r).toString(),highestRate:de(r.add(a)).toString(),marginalRate:de(r.add(a.mul(i))).toString()}},me=function(e){return{token0:e.token0,token1:e.token1,order0:le(e.order0),order1:le(e.order1)}},fe=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:ce(e.order0),order1:ce(e.order1),encoded:e}};function ge(e,t,n,a,r,i,u,s){if(pe.debug("buildStrategyObject called",arguments),new o.default(n).isNegative()||new o.default(a).isNegative()||new o.default(i).isNegative()||new o.default(u).isNegative())throw new Error("prices cannot be negative");if(new o.default(n).gt(a)||new o.default(i).gt(u))throw new Error("low price must be lower than or equal to high price");if(new o.default(r).isNegative()||new o.default(s).isNegative())throw new Error("budgets cannot be negative");var p=be(e.decimals,t.decimals,n,a,r,i,u,s),y=p.order0,d=p.order1;return pe.debug("buildStrategyObject info:",{token0:e.address,token1:t.address,order0:y,order1:d}),{token0:e.address,token1:t.address,order0:y,order1:d}}function be(e,t,n,a,r,i,o,u){pe.debug("createOrders called",arguments);var s=ee(u,e),p=oe(o,t,e),y=oe(i,t,e),d=ee(r,t),l=ie(n,t,e),c=ie(a,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}}function Te(e){return e.reduce(function(e,t){return o.default.min(e,t.lowestRate)},new o.default(Infinity))}function he(e){return e.reduce(function(e,t){return o.default.max(e,t.highestRate)},new o.default(-Infinity))}function ve(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new o.default(e.liquidity);if(t.gte(e.marginalRate))return new o.default(0);var n=new o.default(e.liquidity),a=new o.default(e.lowestRate).sqrt(),r=new o.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(a)).div(r.sub(a)))}(n,t))},new o.default(0))}var we=new M("index.ts"),ke=/*#__PURE__*/function(){function n(t,n){var a=this;this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,this._onChangeCallbacks=[],we.debug("SDK class constructor called with",arguments);var r=new e.StaticJsonRpcProvider({url:t.rpcUrl,skipFetchSetup:!0},1);this._api=new H(r,t.contractAddresses);var i=function(e){return Promise.resolve(null==n?void 0:n(e)).then(function(t){return void 0!==t?t:a._api.reader.getDecimalsByAddress(e)})};ue.init(i)}var a=n.prototype;return a._fireOnChange=function(){we.debug("firing onChange callbacks"),this._onChangeCallbacks.forEach(function(e){return e()})},a.onChange=function(e){var t=this;if(we.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 we.debug("startDataSync called"),e._cache?(we.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new h(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){we.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),we.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},a.hasLiquidityByPair=function(e,t){if(we.debug("hasLiquidityByPair called",arguments),!this._cache)throw we.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return we.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},a.getLiquidityByPair=function(e,n){try{var a=arguments,r=this;if(we.debug("getLiquidityByPair called",a),!r._cache)throw we.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=r._cache.getOrders(e,n),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},t.BigNumber.from(0));return Promise.resolve(ue.getInstance().fetchDecimals(n)).then(function(e){var t=te(o,e);return we.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:n,decimals:e,liquidity:t}),t})}catch(e){return Promise.reject(e)}},a.getUserStrategies=function(e){try{var t=arguments,n=this;return we.debug("getUserStrategies called",t),Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){function t(){var t=a.map(fe);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 we.debug("getUserStrategies info:",{ids:e,encodedStrategies:a,decodedStrategies:t,strategies:n}),n})}var a,r=function(){if(!n._cache)return we.log("getUserStrategies called before startDataSync - fetching from chain"),Promise.resolve(n._api.reader.getStrategiesByIds(e)).then(function(e){a=e});a=e.map(function(e){var t;return null==(t=n._cache)?void 0:t.getStrategyById(e)}).filter(function(e){return!!e})}();return r&&r.then?r.then(t):t()})}catch(e){return Promise.reject(e)}},a.getTradeData=function(e,n,a,r,i){try{var o=arguments,u=this;if(we.debug("getTradeData called",o),!u._cache)throw we.log("getTradeData called before startDataSync"),new Error("startDataSync must be called prior to this action");var s=ue.getInstance();return Promise.resolve(s.fetchDecimals(e)).then(function(o){return Promise.resolve(s.fetchDecimals(n)).then(function(s){var p,y=u._cache.getOrders(e,n),d=t.BigNumber.from(ee(a,r?s:o));(p=r?Y(d,y,i):X(d,y,i)).length>1&&p.at(-1).output.isZero()&&p.pop();var l=u.getTradeDataFromActions(e,n,r,p);return we.debug("getTradeData info:",{orders:y,amount:a,amountWei:d,res:l}),l})})}catch(e){return Promise.reject(e)}},a.getTradeDataFromActions=function(e,n,a,r){try{var i=arguments,u=this;we.debug("getTradeDataFromActions called",i);var s=ue.getInstance();return Promise.resolve(s.fetchDecimals(e)).then(function(e){return Promise.resolve(s.fetchDecimals(n)).then(function(n){var i,s,p,y=[],d=[],l=t.BigNumber.from(0),c=t.BigNumber.from(0);if(r.forEach(function(t){y.push({strategyId:t.id,amount:t.input}),d.push({id:t.id,sourceAmount:te(a?t.output:t.input,e),targetAmount:te(a?t.input:t.output,n)}),c=c.add(t.input),l=l.add(t.output)}),null==u._tradingFeePPM)throw new Error("tradingFeePPM is undefined");if(a?(i=ae(l,u._tradingFeePPM),s=new o.default(c.toString())):(i=new o.default(c.toString()),s=re(l,u._tradingFeePPM)),i.isZero()||s.isZero())p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0"};else{var m=new o.default(s.toString()).div(i.toString()).times(k(e,n)).toString();p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:te(i.toFixed(0),e),totalTargetAmount:te(s.toFixed(0),n),effectiveRate:m}}return we.debug("getTradeDataFromActions info:",{sourceDecimals:e,targetDecimals:n,actionsWei:r,totalInput:c,totalOutput:l,tradingFeePPM:u._tradingFeePPM,res:p}),p})})}catch(e){return Promise.reject(e)}},a.composeTradeByTargetTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return we.debug("composeTradeByTargetTransaction called",o),Promise.resolve(ue.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,a,ee(r,o),i)})}catch(e){return Promise.reject(e)}},a.composeTradeBySourceTransaction=function(e,t,n,a,r,i){try{var o=arguments,u=this;return we.debug("composeTradeBySourceTransaction called",o),Promise.resolve(ue.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,a,ee(r,o),i)})}catch(e){return Promise.reject(e)}},a.createBuySellStrategy=function(e,t,n,a,r,i,o,u,s){we.debug("createBuySellStrategy called",arguments);var p=ge(e,t,n,a,r,i,o,u),y=me(p);return we.debug("createBuySellStrategy info:",{strategy:p,encStrategy:y}),this._api.composer.createStrategy(y.token0,y.token1,y.order0,y.order1,s)},a.updateStrategy=function(e,n,a,r,i,o,u,s,p,y,d){try{var l=arguments,c=this;we.debug("updateStrategy called",l);var m=ge(a,r,i,o,u,s,p,y),f=me(m);return we.debug("updateStrategy info:",{strategy:m,encStrategy:f}),Promise.resolve(c._api.composer.updateStrategy(t.BigNumber.from(e),[n.order0,n.order1],[f.order0,f.order1],d))}catch(e){return Promise.reject(e)}},a.deleteStrategy=function(e){return we.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(t.BigNumber.from(e))},a.getRateLiquidityDepthByPair=function(e,t,n){try{var a=arguments,r=this;if(we.debug("getRateLiquidityDepthByPair called",a),!r._cache)throw we.log("getRateLiquidityDepthByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=Object.values(r._cache.getOrders(e,t)).map(ce),u=ue.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(e){return Promise.resolve(u.fetchDecimals(t)).then(function(t){var a=ie(n,t,e),r=ve(i,new o.default(a)).toFixed(0),u=te(r,t);return we.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:r,targetDecimals:t,depthInTargetDecimals:u}),u})})}catch(e){return Promise.reject(e)}},a.getMinRateByPair=function(e,t){try{var n=arguments,a=this;if(we.debug("getMinRateByPair called",n),!a._cache)throw we.log("getMinRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(ce),i=Te(r).toString(),o=ue.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=ie(i,e,t);return we.debug("getMinRateByPair info:",{orders:r,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},a.getMaxRateByPair=function(e,t){try{var n=arguments,a=this;if(we.debug("getMaxRateByPair called",n),!a._cache)throw we.log("getMaxRateByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var r=Object.values(a._cache.getOrders(e,t)).map(ce),i=he(r).toString(),o=ue.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=ie(i,e,t);return we.debug("getMaxRateByPair info:",{orders:r,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},s(n,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(we.debug("pairs called"),!this._cache)throw we.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),n}();return ke});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@ethersproject/providers"),require("@ethersproject/bignumber"),require("decimal.js"),require("ethers"),require("@ethersproject/units")):"function"==typeof define&&define.amd?define(["@ethersproject/providers","@ethersproject/bignumber","decimal.js","ethers","@ethersproject/units"],t):(e||self).carbonSdk=t(e.providers,e.bignumber,e.Decimal,e.ethers,e.units)}(this,function(e,t,n,r,a){function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=/*#__PURE__*/i(n);function u(e,t){for(var n=0;n<t.length;n++){var 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 s(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},p.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 d(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return y(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?y(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var 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 l=function(e,t){return e.localeCompare(t)},c="->-<-",m=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(c)},f=function(e,t){return m([e,t].sort(l))},g=function(e){var t=e.split(c);return[t[0],t[1]]},b=function(e,t){return m([e,t])},T=function(e,t,n){if(0!==n.size){var r,a;0===t?(r=e.order0,a=b(e.token1,e.token0)):(r=e.order1,a=b(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)))}},h=/*#__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=f(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=d(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=f(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=b(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=f(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=f(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=b(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=d(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(b(i,o),s),t.set(b(o,i),u)}}}(this._pairToStrategies,this._cachedOrders);var a=b(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())},s(e,[{key:"pairs",get:function(){return Array.from(this._pairToStrategies.keys()).map(g)}}]),e}(),v=function(e,t){return e.lt(t)?e:t},w=function(e,t){return e.gt(t)?e:t};o.default.set({precision:100,rounding:o.default.ROUND_HALF_DOWN,toExpNeg:-30,toExpPos:30});var k=Math.pow(2,48),_=new o.default(10),P=function(e,t){return _.pow(e-t)},S=function(e){return new o.default(e.toString())},A=function(e){return t.BigNumber.from(e.toFixed())},M="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE".toLowerCase(),B=function(e){return e.toLowerCase()===M},x=function(e,n,r){var a=p({},r);return B(e)&&(a.value=n.reduce(function(e,t){return e.add(t.amount)},t.BigNumber.from(0))),a},C=/*#__PURE__*/function(){function e(e){this._prefix=void 0,this._prefix="[SDK]["+e+"]:"}var t=e.prototype;return t.log=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},t.debug=function(){var e;(e=console).log.apply(e,[this._prefix].concat([].slice.call(arguments)))},e}(),I=new C("Composer.ts"),D=/*#__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){I.debug("tradeByTargetAmount called",arguments);var o=x(e,n,i);return I.debug("tradeByTargetAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeByTargetAmount(e,t,n,r,a,o)},t.tradeBySourceAmount=function(e,t,n,r,a,i){I.debug("tradeBySourceAmount called",arguments);var o=x(e,n,i);return I.debug("tradeBySourceAmount overrides",o),this._contracts.carbonController.populateTransaction.tradeBySourceAmount(e,t,n,r,a,o)},t.createStrategy=function(e,t,n,r,a){I.debug("createStrategy called",arguments);var i=p({},a);return B(e)?i.value=n.y:B(t)&&(i.value=r.y),I.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){return this._contracts.carbonController.populateTransaction.updateStrategy(e,t,n,r)},t.transferVoucherOwnership=function(e,t){return this._contracts.voucher.populateTransaction.transferOwnership(e,t)},e}(),R=[{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:"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:"PoolDoesNotExists",type:"error"},{inputs:[],name:"StrategyDoesNotExist",type:"error"},{inputs:[],name:"TokensMismatch",type:"error"},{inputs:[],name:"UnknownDelegator",type:"error"},{inputs:[],name:"UnnecessaryNativeTokenReceived",type:"error"},{inputs:[],name:"UnsetDelegator",type:"error"},{inputs:[],name:"ZeroLiquidityProvided",type:"error"},{inputs:[],name:"ZeroValue",type:"error"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint8",name:"version",type:"uint8"}],name:"Initialized",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Paused",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"uint256",name:"poolId",type:"uint256"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"}],name:"PoolCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"previousAdminRole",type:"bytes32"},{indexed:!0,internalType:"bytes32",name:"newAdminRole",type:"bytes32"}],name:"RoleAdminChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleGranted",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes32",name:"role",type:"bytes32"},{indexed:!0,internalType:"address",name:"account",type:"address"},{indexed:!0,internalType:"address",name:"sender",type:"address"}],name:"RoleRevoked",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyDeleted",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"id",type:"uint256"},{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"contract Token",name:"token0",type:"address"},{indexed:!0,internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order0",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],indexed:!1,internalType:"struct Order",name:"order1",type:"tuple"}],name:"StrategyUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"trader",type:"address"},{indexed:!0,internalType:"address",name:"sourceToken",type:"address"},{indexed:!0,internalType:"address",name:"targetToken",type:"address"},{indexed:!1,internalType:"uint256",name:"sourceAmount",type:"uint256"},{indexed:!1,internalType:"uint256",name:"targetAmount",type:"uint256"},{indexed:!1,internalType:"uint128",name:"tradingFeeAmount",type:"uint128"},{indexed:!1,internalType:"bool",name:"byTargetAmount",type:"bool"}],name:"TokensTraded",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint32",name:"prevFeePPM",type:"uint32"},{indexed:!1,internalType:"uint32",name:"newFeePPM",type:"uint32"}],name:"TradingFeePPMUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"address",name:"account",type:"address"}],name:"Unpaused",type:"event"},{inputs:[],name:"DEFAULT_ADMIN_ROLE",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"}],name:"accumulatedFees",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"controllerType",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"createPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],name:"createStrategy",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"}],name:"deleteStrategy",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"uint256",name:"index",type:"uint256"}],name:"getRoleMember",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"}],name:"getRoleMemberCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"grantRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"hasRole",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[],name:"initialize",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"pairs",outputs:[{internalType:"address[2][]",name:"",type:"address[2][]"}],stateMutability:"view",type:"function"},{inputs:[],name:"pause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"paused",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"pool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pool",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"data",type:"bytes"}],name:"postUpgrade",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"renounceRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"role",type:"bytes32"},{internalType:"address",name:"account",type:"address"}],name:"revokeRole",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"roleAdmin",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[],name:"roleEmergencyStopper",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"uint32",name:"newTradingFeePPM",type:"uint32"}],name:"setTradingFeePPM",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256[]",name:"ids",type:"uint256[]"}],name:"strategiesByIds",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"},{internalType:"uint256",name:"startIndex",type:"uint256"},{internalType:"uint256",name:"endIndex",type:"uint256"}],name:"strategiesByPool",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy[]",name:"",type:"tuple[]"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],name:"strategiesByPoolCount",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"id",type:"uint256"}],name:"strategy",outputs:[{components:[{internalType:"uint256",name:"id",type:"uint256"},{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract Token",name:"token0",type:"address"},{internalType:"contract Token",name:"token1",type:"address"}],internalType:"struct Pair",name:"pair",type:"tuple"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"orders",type:"tuple[2]"}],internalType:"struct Strategy",name:"",type:"tuple"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"minReturn",type:"uint128"}],name:"tradeBySourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint128",name:"maxInput",type:"uint128"}],name:"tradeByTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeSourceAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Token",name:"sourceToken",type:"address"},{internalType:"contract Token",name:"targetToken",type:"address"},{components:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"uint128",name:"amount",type:"uint128"}],internalType:"struct TradeAction[]",name:"tradeActions",type:"tuple[]"}],name:"tradeTargetAmount",outputs:[{internalType:"uint128",name:"",type:"uint128"}],stateMutability:"view",type:"function"},{inputs:[],name:"tradingFeePPM",outputs:[{internalType:"uint32",name:"",type:"uint32"}],stateMutability:"view",type:"function"},{inputs:[],name:"unpause",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"currentOrders",type:"tuple[2]"},{components:[{internalType:"uint128",name:"y",type:"uint128"},{internalType:"uint128",name:"z",type:"uint128"},{internalType:"uint64",name:"A",type:"uint64"},{internalType:"uint64",name:"B",type:"uint64"}],internalType:"struct Order[2]",name:"newOrders",type:"tuple[2]"}],name:"updateStrategy",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"uint256",name:"strategyId",type:"uint256"},{internalType:"address",name:"newOwner",type:"address"}],name:"updateStrategyOwner",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"uint16",name:"",type:"uint16"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"_logic",type:"address"},{internalType:"address",name:"admin_",type:"address"},{internalType:"bytes",name:"_data",type:"bytes"}],stateMutability:"payable",type:"constructor"}],O=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new r.utils.Interface(R)},e.connect=function(e,t){return new r.Contract(e,R,t)},e}();O.abi=R;var E=[{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"}],j=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new r.utils.Interface(E)},e.connect=function(e,t){return new r.Contract(e,E,t)},e}();j.abi=E;var F=[{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"}],U=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new r.utils.Interface(F)},e.connect=function(e,t){return new r.Contract(e,F,t)},e}();U.abi=F;var N=[{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"}],q=/*#__PURE__*/function(){function e(){}return e.createInterface=function(){return new r.utils.Interface(N)},e.connect=function(e,t){return new r.Contract(e,N,t)},e}();q.abi=N;var z={carbonControllerAddress:"0x2FdE9E0cE83769E88eAA9FB7BE27cb26c385d1b2",multiCallAddress:"0x5ba1e12693dc8f9c48aad8770482f4739beed696",voucherAddress:"0x08dA389a1400e3699f58843484B0513AA065461c"},L=/*#__PURE__*/function(){function e(e,t){this._provider=void 0,this._carbonController=void 0,this._multiCall=void 0,this._voucher=void 0,this._config=z,this._provider=e,this._config.carbonControllerAddress=(null==t?void 0:t.carbonControllerAddress)||z.carbonControllerAddress,this._config.multiCallAddress=(null==t?void 0:t.multiCallAddress)||z.multiCallAddress,this._config.voucherAddress=(null==t?void 0:t.voucherAddress)||z.voucherAddress}return e.prototype.token=function(e){return U.connect(e,this._provider)},s(e,[{key:"carbonController",get:function(){return this._carbonController||(this._carbonController=O.connect(this._config.carbonControllerAddress,this._provider)),this._carbonController}},{key:"multicall",get:function(){return this._multiCall||(this._multiCall=j.connect(this._config.multiCallAddress,this._provider)),this._multiCall}},{key:"voucher",get:function(){return this._voucher||(this._voucher=q.connect(this._config.voucherAddress,this._provider)),this._voucher}}]),e}(),H=new C("Reader.ts");function G(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 W(e,t){return function(n,r,a,i,o,u){H.debug(e+" fired with",arguments);var s={id:n,token0:a,token1:i,order0:{y:o.y,z:o.z,A:o.A,B:o.B},order1:{y:u.y,z:u.z,A:u.A,B:u.B}};H.debug(e+" parsed strategy:",s),t(s)}}var Z=/*#__PURE__*/function(){function e(e){var t=this;this._contracts=void 0,this.getDecimalsByAddress=function(e){try{return B(e)?Promise.resolve(18):Promise.resolve(t._contracts.token(e).decimals())}catch(e){return Promise.reject(e)}},this._contracts=e}var t=e.prototype;return t.multicall=function(e,t){return function(e,t,n){return Promise.resolve(function(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(G)}catch(e){return Promise.reject(e)}},t.getStrategiesByIds=function(e){try{return Promise.resolve(this._contracts.carbonController.strategiesByIds(e)).then(function(e){return e.map(function(e){return G(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 G(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 G(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){H.debug("TradingFeePPMUpdated fired with",arguments),e(t,n)})},t.onStrategyDeleted=function(e){return this._contracts.carbonController.on("StrategyDeleted",W("StrategyDeleted",e))},t.onStrategyCreated=function(e){return this._contracts.carbonController.on("StrategyCreated",W("StrategyCreated",e))},t.onStrategyUpdated=function(e){return this._contracts.carbonController.on("StrategyUpdated",W("StrategyUpdated",e))},e}(),K=/*#__PURE__*/function(){function e(e,t){this._reader=void 0,this._composer=void 0;var n=new L(e,t);this._reader=new Z(n),this._composer=new D(n)}return s(e,[{key:"reader",get:function(){return this._reader}},{key:"composer",get:function(){return this._composer}}]),e}(),V=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))},J=function(e,t){return V(t,e)},$=/*#__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)}},s(e,[{key:"cachedDecimals",get:function(){return this._cachedDecimals}}]),e}();function Q(e,t){var n,r,i,o=(r=t,-1!==(i=(n=e).indexOf("."))?n.slice(0,i+r+1):n);return a.parseUnits(o,t).toString()}function X(e,t){var n=a.formatUnits(e,t);return new o.default(n).toFixed()}$._instance=void 0,$._fetcher=void 0;var Y=1e6;function ee(e,t){return new o.default(e.toString()).mul(Y).div(Y-t).ceil()}function te(e,t){return new o.default(e.toString()).mul(Y-t).div(Y).floor()}function ne(e,t,n){return new o.default(e.toString()).times(P(t,n)).toFixed()}function re(e,t,n){return 0==+e.toString()?"0":new o.default(1).div(e.toString()).times(P(n,t)).toFixed()}var ae=function(e){try{var t=arguments;ie.debug("decodeStrategy called",t);var n=e.id,r=e.token0,a=e.token1,i=e.order0,o=e.order1,u=e.encoded,s=$.getInstance();return Promise.resolve(s.fetchDecimals(r)).then(function(e){return Promise.resolve(s.fetchDecimals(a)).then(function(t){var s=ne(o.lowestRate,e,t),p=ne(o.highestRate,e,t),y=re(i.highestRate,t,e),d=re(i.lowestRate,t,e),l=X(i.liquidity,e),c=X(o.liquidity,t);return ie.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)}},ie=new C("encoders.ts");function oe(e){return e.gt(0)?o.default.log2(e.toString()).add(1).floor().toNumber():0}var ue=function(e){var t=A(e.sqrt().mul(k).floor()),n=oe(t.div(k));return S(t.shr(n).shl(n))},se=function(e){return e.div(k).pow(2)},pe=function(e){var n=oe(e.div(k)),r=e.shr(n);return t.BigNumber.from(k).mul(n).or(r)},ye=function(e){return e.mod(k).shl(e.div(k).toNumber())},de=function(e){var t=new o.default(e.liquidity),n=new o.default(e.lowestRate),r=new o.default(e.highestRate),a=new o.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=A(t),u=A(ue(n)),s=A(ue(r)),p=A(ue(a));return{y:i,z:s.eq(p)?i:i.mul(s.sub(u)).div(p.sub(u)),A:pe(s.sub(u)),B:pe(u)}},le=function(e){var t=S(e.y),n=S(e.z),r=S(ye(e.A)),a=S(ye(e.B));return{liquidity:t.toString(),lowestRate:se(a).toString(),highestRate:se(a.add(r)).toString(),marginalRate:se(t.eq(n)?a.add(r):a.add(r.mul(t).div(n))).toString()}},ce=function(e){return{token0:e.token0,token1:e.token1,order0:de(e.order0),order1:de(e.order1)}},me=function(e){return{id:e.id,token0:e.token0,token1:e.token1,order0:le(e.order0),order1:le(e.order1),encoded:e}};function fe(e,t,n,r,a,i,u,s){if(ie.debug("buildStrategyObject called",arguments),new o.default(n).isNegative()||new o.default(r).isNegative()||new o.default(i).isNegative()||new o.default(u).isNegative())throw new Error("prices cannot be negative");if(new o.default(n).gt(r)||new o.default(i).gt(u))throw new Error("low price must be lower than or equal to high price");if(new o.default(a).isNegative()||new o.default(s).isNegative())throw new Error("budgets cannot be negative");var p=ge(e.decimals,t.decimals,n,r,a,i,u,s),y=p.order0,d=p.order1;return ie.debug("buildStrategyObject info:",{token0:e.address,token1:t.address,order0:y,order1:d}),{token0:e.address,token1:t.address,order0:y,order1:d}}function ge(e,t,n,r,a,i,o,u){ie.debug("createOrders called",arguments);var s=Q(u,e),p=re(o,t,e),y=re(i,t,e),d=Q(a,t),l=ne(n,t,e),c=ne(r,t,e),m={liquidity:s,lowestRate:p,highestRate:y,marginalRate:y},f={liquidity:d,lowestRate:l,highestRate:c,marginalRate:c};return ie.debug("createOrders info:",{order0:m,order1:f}),{order0:m,order1:f}}var be=t.BigNumber.from(k),Te=t.BigNumber.from(2).pow(128).sub(1),he=t.BigNumber.from(2).pow(256).sub(1);function ve(e,t){if(e.gte(0)&&e.lte(t))return e;throw null}var we=function(e){return ve(e,Te)},ke=function(e,t){return ve(e.add(t),he)},_e=function(e,t){return ve(e.mul(t),he)},Pe=function(e,t,n){return ve(e.mul(t).div(n),he)},Se=function(e,t,n){return ve(e.mul(t).add(n).sub(1).div(n),he)},Ae=function(e,t){var n=e,r=t.y,a=t.z,i=ye(t.A),o=ye(t.B);try{return we(function(e,t,n,r,a){if(r.eq(0))return Se(e,_e(be,be),_e(a,a));var i,o,u=_e(n,be),s=ke(_e(t,r),_e(n,a)),p=(i=s,o=_e(e,r),ve(i.sub(o),he)),y=Se(u,u,he),d=Se(s,p,he),l=w(y,d),c=Se(u,u,l),m=Pe(s,p,l);return Se(e,c,m)}(n,r,a,i,o))}catch(e){return he}},Me=function(e,n){var r=v(function(e,n){var r=e,a=n.y,i=n.z,o=ye(n.A),u=ye(n.B);try{return we(function(e,t,n,r,a){if(r.eq(0))return Pe(e,_e(a,a),_e(be,be));var i=_e(n,be),o=ke(_e(t,r),_e(n,a)),u=_e(o,e),s=Se(i,i,he),p=Se(u,r,he),y=w(s,p),d=Se(i,i,y),l=Se(u,r,y);return Pe(o,u.div(y),ke(d,l))}(r,a,i,o,u))}catch(e){return t.BigNumber.from(0)}}(e,n),n.y);return{input:Ae(r,n),output:r}},Be=function(e,t){var n=v(e,t.y);return{input:n,output:Ae(n,t)}},xe=function(e,n,r,a,i){for(var o,u=[],s=d(Object.keys(n).map(function(t){return{id:t,rate:a(e,n[t])}}).sort(function(e,t){return i(e.rate,t.rate)}));!(o=s()).done;){var p=o.value,y=p.id,l=p.rate;if(!e.gt(l.input)){if(e.eq(l.input)){r(l)&&u.push({id:t.BigNumber.from(y),input:l.input,output:l.output});break}var c={input:e,output:a(e,n[y]).output};r(c)&&u.push({id:t.BigNumber.from(y),input:c.input,output:c.output});break}r(l)&&(u.push({id:t.BigNumber.from(y),input:l.input,output:l.output}),e=e.sub(l.input))}return u},Ce=function(e){return e.input.gt(0)&&e.output.gt(0)},Ie=function(e,t,n){return void 0===n&&(n=Ce),xe(e,t,n,Me,V)},De=function(e,t,n){return void 0===n&&(n=Ce),xe(e,t,n,Be,J)};function Re(e){return e.reduce(function(e,t){return o.default.min(e,t.lowestRate)},new o.default(Infinity))}function Oe(e){return e.reduce(function(e,t){return o.default.max(e,t.highestRate)},new o.default(-Infinity))}function Ee(e,t){return e.reduce(function(e,n){return e.add(function(e,t){if(t.lte(e.lowestRate))return new o.default(e.liquidity);if(t.gte(e.marginalRate))return new o.default(0);var n=new o.default(e.liquidity),r=new o.default(e.lowestRate).sqrt(),a=new o.default(e.marginalRate).sqrt();return n.sub(n.mul(t.sqrt().sub(r)).div(a.sub(r)))}(n,t))},new o.default(0))}var je=new C("index.ts"),Fe=/*#__PURE__*/function(){function n(t,n){var r=this;this._api=void 0,this._cache=void 0,this._tradingFeePPM=void 0,this._onChangeCallbacks=[],je.debug("SDK class constructor called with",arguments);var a=new e.StaticJsonRpcProvider({url:t.rpcUrl,skipFetchSetup:!0},1);this._api=new K(a,t.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)})};$.init(i)}var r=n.prototype;return r._fireOnChange=function(){je.debug("firing onChange callbacks"),this._onChangeCallbacks.forEach(function(e){return e()})},r.onChange=function(e){var t=this;if(je.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})}},r.startDataSync=function(){try{var e=this;return je.debug("startDataSync called"),e._cache?(je.debug("startDataSync was already called before"),Promise.resolve()):(e._cache=new h(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){je.debug("tradingFeePPM updated",t),e._tradingFeePPM=t}),je.debug("tradeFeePPM",e._tradingFeePPM)})}))}catch(e){return Promise.reject(e)}},r.hasLiquidityByPair=function(e,t){if(je.debug("hasLiquidityByPair called",arguments),!this._cache)throw je.log("hasLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var n=this._cache.getOrders(e,t);return je.debug("hasLiquidityByPair info:",{orders:n}),Object.keys(n).length>0},r.getLiquidityByPair=function(e,n){try{var r=arguments,a=this;if(je.debug("getLiquidityByPair called",r),!a._cache)throw je.log("getLiquidityByPair called before startDataSync"),new Error("startDataSync must be called prior to this action");var i=a._cache.getOrders(e,n),o=Object.values(i).reduce(function(e,t){return e.add(t.y)},t.BigNumber.from(0));return Promise.resolve($.getInstance().fetchDecimals(n)).then(function(e){var t=X(o,e);return je.debug("getLiquidityByPair info:",{orders:i,liquidityWei:o,targetToken:n,decimals:e,liquidity:t}),t})}catch(e){return Promise.reject(e)}},r.getUserStrategies=function(e){try{var t=arguments,n=this;return je.debug("getUserStrategies called",t),Promise.resolve(n._api.reader.getUserStrategyIds(e)).then(function(e){function t(){var t=r.map(me);return Promise.resolve(Promise.all(t.map(function(e){try{return Promise.resolve(ae(e))}catch(e){return Promise.reject(e)}}))).then(function(n){return je.debug("getUserStrategies info:",{ids:e,encodedStrategies:r,decodedStrategies:t,strategies:n}),n})}var r,a=function(){if(!n._cache)return je.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)}},r.getTradeData=function(e,n,r,a,i){try{var o=arguments,u=this;if(je.debug("getTradeData called",o),!u._cache)throw je.log("getTradeData called before startDataSync"),new Error("startDataSync must be called prior to this action");var s=$.getInstance();return Promise.resolve(s.fetchDecimals(e)).then(function(o){return Promise.resolve(s.fetchDecimals(n)).then(function(s){var p,y=u._cache.getOrders(e,n),d=t.BigNumber.from(Q(r,a?s:o));(p=a?De(d,y,i):Ie(d,y,i)).length>1&&p.at(-1).output.isZero()&&p.pop();var l=u.getTradeDataFromActions(e,n,a,p);return je.debug("getTradeData info:",{orders:y,amount:r,amountWei:d,res:l}),l})})}catch(e){return Promise.reject(e)}},r.getTradeDataFromActions=function(e,n,r,a){try{var i=arguments,u=this;je.debug("getTradeDataFromActions called",i);var s=$.getInstance();return Promise.resolve(s.fetchDecimals(e)).then(function(e){return Promise.resolve(s.fetchDecimals(n)).then(function(n){var i,s,p,y=[],d=[],l=t.BigNumber.from(0),c=t.BigNumber.from(0);if(a.forEach(function(t){y.push({strategyId:t.id,amount:t.input}),d.push({id:t.id,sourceAmount:X(r?t.output:t.input,e),targetAmount:X(r?t.input:t.output,n)}),c=c.add(t.input),l=l.add(t.output)}),null==u._tradingFeePPM)throw new Error("tradingFeePPM is undefined");if(r?(i=ee(l,u._tradingFeePPM),s=new o.default(c.toString())):(i=new o.default(c.toString()),s=te(l,u._tradingFeePPM)),i.isZero()||s.isZero())p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:"0",totalTargetAmount:"0",effectiveRate:"0"};else{var m=new o.default(s.toString()).div(i.toString()).times(P(e,n)).toString();p={tradeActions:y,actionsTokenRes:d,totalSourceAmount:X(i.toFixed(0),e),totalTargetAmount:X(s.toFixed(0),n),effectiveRate:m}}return je.debug("getTradeDataFromActions info:",{sourceDecimals:e,targetDecimals:n,actionsWei:a,totalInput:c,totalOutput:l,tradingFeePPM:u._tradingFeePPM,res:p}),p})})}catch(e){return Promise.reject(e)}},r.composeTradeByTargetTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return je.debug("composeTradeByTargetTransaction called",o),Promise.resolve($.getInstance().fetchDecimals(e)).then(function(o){return u._api.composer.tradeByTargetAmount(e,t,n,r,Q(a,o),i)})}catch(e){return Promise.reject(e)}},r.composeTradeBySourceTransaction=function(e,t,n,r,a,i){try{var o=arguments,u=this;return je.debug("composeTradeBySourceTransaction called",o),Promise.resolve($.getInstance().fetchDecimals(t)).then(function(o){return u._api.composer.tradeBySourceAmount(e,t,n,r,Q(a,o),i)})}catch(e){return Promise.reject(e)}},r.createBuySellStrategy=function(e,t,n,r,a,i,o,u,s){je.debug("createBuySellStrategy called",arguments);var p=fe(e,t,n,r,a,i,o,u),y=ce(p);return je.debug("createBuySellStrategy info:",{strategy:p,encStrategy:y}),this._api.composer.createStrategy(y.token0,y.token1,y.order0,y.order1,s)},r.updateStrategy=function(e,n,r,a,i,o,u,s,p,y,d){try{var l=arguments,c=this;je.debug("updateStrategy called",l);var m=fe(r,a,i,o,u,s,p,y),f=ce(m);return je.debug("updateStrategy info:",{strategy:m,encStrategy:f}),Promise.resolve(c._api.composer.updateStrategy(t.BigNumber.from(e),[n.order0,n.order1],[f.order0,f.order1],d))}catch(e){return Promise.reject(e)}},r.deleteStrategy=function(e){return je.debug("deleteStrategy called",arguments),this._api.composer.deleteStrategy(t.BigNumber.from(e))},r.getRateLiquidityDepthByPair=function(e,t,n){try{var r=arguments,a=this;if(je.debug("getRateLiquidityDepthByPair called",r),!a._cache)throw je.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(le),u=$.getInstance();return Promise.resolve(u.fetchDecimals(e)).then(function(e){return Promise.resolve(u.fetchDecimals(t)).then(function(t){var r=ne(n,t,e),a=Ee(i,new o.default(r)).toFixed(0),u=X(a,t);return je.debug("getRateLiquidityDepthByPair info:",{orders:i,depthWei:a,targetDecimals:t,depthInTargetDecimals:u}),u})})}catch(e){return Promise.reject(e)}},r.getMinRateByPair=function(e,t){try{var n=arguments,r=this;if(je.debug("getMinRateByPair called",n),!r._cache)throw je.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(le),i=Re(a).toString(),o=$.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=ne(i,e,t);return je.debug("getMinRateByPair info:",{orders:a,minRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},r.getMaxRateByPair=function(e,t){try{var n=arguments,r=this;if(je.debug("getMaxRateByPair called",n),!r._cache)throw je.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(le),i=Oe(a).toString(),o=$.getInstance();return Promise.resolve(o.fetchDecimals(e)).then(function(e){return Promise.resolve(o.fetchDecimals(t)).then(function(t){var n=ne(i,e,t);return je.debug("getMaxRateByPair info:",{orders:a,maxRate:i,sourceDecimals:e,targetDecimals:t,normalizedRate:n}),n})})}catch(e){return Promise.reject(e)}},s(n,[{key:"isInitialized",get:function(){return void 0!==this._cache}},{key:"pairs",get:function(){if(je.debug("pairs called"),!this._cache)throw je.log("pairs called before startDataSync"),new Error("startDataSync must be called prior to this action");return this._cache.pairs}}]),n}();return Fe});
//# sourceMappingURL=sdk.umd.js.map

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

"source": "src/index.ts",
"version": "0.0.47-DEV",
"version": "0.0.48-DEV",
"description": "The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfill trades",

@@ -8,0 +8,0 @@ "main": "dist/sdk.umd.js",

{
"address": "0x483309B60A7f5A097aE09Cf5811773431a9E8d1B",
"address": "0x2FdE9E0cE83769E88eAA9FB7BE27cb26c385d1b2",
"abi": [
{
"inputs": [],
"name": "AccessDenied",
"type": "error"
},
{
"inputs": [],
"name": "InvalidAddress",
"type": "error"
},
{
"anonymous": false,

@@ -69,3 +59,3 @@ "inputs": [

"internalType": "address",
"name": "",
"name": "admin_",
"type": "address"

@@ -83,3 +73,3 @@ }

"internalType": "address",
"name": "",
"name": "implementation_",
"type": "address"

@@ -128,2 +118,7 @@ }

"inputs": [],
"name": "AccessDenied",
"type": "error"
},
{
"inputs": [],
"name": "AlreadyInitialized",

@@ -154,2 +149,7 @@ "type": "error"

"inputs": [],
"name": "InvalidAddress",
"type": "error"
},
{
"inputs": [],
"name": "InvalidFee",

@@ -165,2 +165,7 @@ "type": "error"

"inputs": [],
"name": "InvalidRate",
"type": "error"
},
{
"inputs": [],
"name": "InvalidStrategyId",

@@ -1724,3 +1729,3 @@ "type": "error"

"internalType": "address",
"name": "logic",
"name": "_logic",
"type": "address"

@@ -1730,3 +1735,3 @@ },

"internalType": "address",
"name": "initAdmin",
"name": "admin_",
"type": "address"

@@ -1736,3 +1741,3 @@ },

"internalType": "bytes",
"name": "data",
"name": "_data",
"type": "bytes"

@@ -1739,0 +1744,0 @@ }

{
"address": "0x2fB666c75ec98462852c66D4981e1B3a0E668593",
"address": "0x08dA389a1400e3699f58843484B0513AA065461c",
"abi": [

@@ -94,2 +94,41 @@ {

{
"indexed": false,
"internalType": "string",
"name": "newBaseExtension",
"type": "string"
}
],
"name": "BaseExtensionUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "newBaseURI",
"type": "string"
}
],
"name": "BaseURIUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "contract CarbonController",
"name": "carbonController",
"type": "address"
}
],
"name": "CarbonControllerUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,

@@ -136,4 +175,17 @@ "internalType": "address",

{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "bool",
"name": "newUseGlobalURI",
"type": "bool"
}
],
"name": "UseGlobalURIUpdated",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",

@@ -140,0 +192,0 @@ "name": "to",

import { ContractsConfig } from '../types';
export const config: Required<ContractsConfig> = {
carbonControllerAddress: '0x8b604f9d7f96fa5b9f635f27bfabdcb152015742',
carbonControllerAddress: '0x2FdE9E0cE83769E88eAA9FB7BE27cb26c385d1b2',
multiCallAddress: '0x5ba1e12693dc8f9c48aad8770482f4739beed696',
voucherAddress: '0x78d59e4e207572b506788e57bd0823be21a3a373',
voucherAddress: '0x08dA389a1400e3699f58843484B0513AA065461c',
};

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

import { Decimal, ONE, BigNumber } from './numerics';
import { BigNumber, Decimal, BnToDec, DecToBn, ONE } from './numerics';
import {

@@ -17,34 +17,58 @@ DecodedOrder,

} from './utils';
const logger = new Logger('encoders.ts');
const encodeRate = (x: Decimal): Decimal => x.sqrt().mul(ONE);
function bitLength(value: BigNumber) {
return value.gt(0)
? Decimal.log2(value.toString()).add(1).floor().toNumber()
: 0;
}
const decodeRate = (x: Decimal): Decimal => x.div(ONE).pow(2);
export const encodeRate = (value: Decimal) => {
const data = DecToBn(value.sqrt().mul(ONE).floor());
const length = bitLength(data.div(ONE));
return BnToDec(data.shr(length).shl(length));
};
export const decodeRate = (value: Decimal) => {
return value.div(ONE).pow(2);
};
export const encodeFloat = (value: BigNumber) => {
const exponent = bitLength(value.div(ONE));
const mantissa = value.shr(exponent);
return BigNumber.from(ONE).mul(exponent).or(mantissa);
};
export const decodeFloat = (value: BigNumber) => {
return value.mod(ONE).shl(value.div(ONE).toNumber());
};
export const encodeOrder = (order: DecodedOrder): EncodedOrder => {
const liq = BigNumber.from(new Decimal(order.liquidity).toFixed());
const min = BigNumber.from(
encodeRate(new Decimal(order.lowestRate)).floor().toFixed()
);
const max = BigNumber.from(
encodeRate(new Decimal(order.highestRate)).floor().toFixed()
);
const mid = BigNumber.from(
encodeRate(new Decimal(order.marginalRate)).floor().toFixed()
);
if (!((max.gte(mid) && mid.gt(min)) || (max.eq(mid) && mid.eq(min)))) {
const liquidity = new Decimal(order.liquidity);
const lowestRate = new Decimal(order.lowestRate);
const highestRate = new Decimal(order.highestRate);
const marginalRate = new Decimal(order.marginalRate);
if (
!(
(highestRate.gte(marginalRate) && marginalRate.gt(lowestRate)) ||
(highestRate.eq(marginalRate) && marginalRate.eq(lowestRate))
)
) {
throw new Error(
`Invalid order: max must be greater than or equal to mid, and mid must be greater than min
- or the three should be equal (highestRate: ${order.highestRate},
marginalRate: ${order.marginalRate}, lowestRate: ${order.lowestRate})`
'Either one of the following must hold:\n' +
'- highestRate >= marginalRate > lowestRate\n' +
'- highestRate == marginalRate == lowestRate\n' +
`(highestRate = ${highestRate}, marginalRate = ${marginalRate}, lowestRate = ${lowestRate})`
);
}
const maxSubMin = max.sub(min);
const y = DecToBn(liquidity);
const L = DecToBn(encodeRate(lowestRate));
const H = DecToBn(encodeRate(highestRate));
const M = DecToBn(encodeRate(marginalRate));
return {
y: liq,
z: maxSubMin.isZero() ? liq : liq.mul(maxSubMin).div(mid.sub(min)),
A: maxSubMin,
B: min,
y: y,
z: H.eq(M) ? y : y.mul(H.sub(L)).div(M.sub(L)),
A: encodeFloat(H.sub(L)),
B: encodeFloat(L),
};

@@ -54,7 +78,6 @@ };

export const decodeOrder = (order: EncodedOrder): DecodedOrder => {
const y = new Decimal(order.y.toString());
const z = new Decimal(order.z.toString());
const A = new Decimal(order.A.toString());
const B = new Decimal(order.B.toString());
const yOverZ = y.eq(z) ? new Decimal(1) : y.div(z);
const y = BnToDec(order.y);
const z = BnToDec(order.z);
const A = BnToDec(decodeFloat(order.A));
const B = BnToDec(decodeFloat(order.B));
return {

@@ -64,3 +87,5 @@ liquidity: y.toString(),

highestRate: decodeRate(B.add(A)).toString(),
marginalRate: decodeRate(B.add(A.mul(yOverZ))).toString(),
marginalRate: decodeRate(
y.eq(z) ? B.add(A) : B.add(A.mul(y).div(z))
).toString(),
};

@@ -67,0 +92,0 @@ };

import { EncodedOrder, Rate, MatchAction, Filter } from '../types';
import { BigNumber, BigNumberMin } from '../numerics';
import { cmpMin, cmpMax } from './utils';
import { BigNumber } from '../numerics';
import {
getEncodedTradeTargetAmount,
getEncodedTradeSourceAmount,
getEncodedTradeTargetAmount as getTradeTargetAmount,
getEncodedTradeSourceAmount as getTradeSourceAmount,
} from './trade';

@@ -14,22 +14,24 @@

export const getRateBySourceAmount = (
const getRateBySourceAmount = (
sourceAmount: BigNumber,
order: EncodedOrder
): Rate => {
const targetAmount = getEncodedTradeTargetAmount(sourceAmount, order);
const output = targetAmount.lt(order.y) ? targetAmount : order.y;
const input = getEncodedTradeSourceAmount(output, order);
const output = BigNumberMin(
getTradeTargetAmount(sourceAmount, order),
order.y
);
const input = getTradeSourceAmount(output, order);
return { input, output };
};
export const getRateByTargetAmount = (
const getRateByTargetAmount = (
targetAmount: BigNumber,
order: EncodedOrder
): Rate => {
const input = targetAmount.lt(order.y) ? targetAmount : order.y;
const output = getEncodedTradeSourceAmount(input, order);
const input = BigNumberMin(targetAmount, order.y);
const output = getTradeSourceAmount(input, order);
return { input, output };
};
export const match = (
const match = (
amount: BigNumber,

@@ -83,6 +85,9 @@ orders: OrdersMap,

const defaultFilter: Filter = (rate: Rate) =>
rate.input.gt(0) && rate.output.gt(0);
export const matchBySourceAmount = (
amount: BigNumber,
orders: OrdersMap,
filter: Filter = (_: Rate) => true
filter: Filter = defaultFilter
): MatchAction[] => {

@@ -95,5 +100,5 @@ return match(amount, orders, filter, getRateBySourceAmount, cmpMin);

orders: OrdersMap,
filter: Filter = (_: Rate) => true
filter: Filter = defaultFilter
): MatchAction[] => {
return match(amount, orders, filter, getRateByTargetAmount, cmpMax);
};

@@ -1,13 +0,26 @@

import { ONE, BigNumber, Decimal } from '../numerics';
import { ONE, Decimal, BigNumber, BigNumberMax } from '../numerics';
import { EncodedOrder, DecodedOrder } from '../types';
import { decodeFloat } from '../encoders';
const MIN = BigNumber.from(0);
const MAX = BigNumber.from(2).pow(128).sub(1);
const C = BigNumber.from(ONE);
const mulDivF = (x: BigNumber, y: BigNumber, z: BigNumber): BigNumber =>
x.mul(y).div(z);
const MAX_UINT128 = BigNumber.from(2).pow(128).sub(1);
const MAX_UINT256 = BigNumber.from(2).pow(256).sub(1);
const mulDivC = (x: BigNumber, y: BigNumber, z: BigNumber): BigNumber =>
x.mul(y).add(z).sub(1).div(z);
function check(val: BigNumber, max: BigNumber) {
if (val.gte(0) && val.lte(max)) {
return val;
}
throw null;
}
const uint128 = (n: BigNumber) => check(n, MAX_UINT128);
const add = (a: BigNumber, b: BigNumber) => check(a.add(b), MAX_UINT256);
const sub = (a: BigNumber, b: BigNumber) => check(a.sub(b), MAX_UINT256);
const mul = (a: BigNumber, b: BigNumber) => check(a.mul(b), MAX_UINT256);
const mulDivF = (a: BigNumber, b: BigNumber, c: BigNumber) =>
check(a.mul(b).div(c), MAX_UINT256);
const mulDivC = (a: BigNumber, b: BigNumber, c: BigNumber) =>
check(a.mul(b).add(c).sub(1).div(c), MAX_UINT256);
//

@@ -18,18 +31,24 @@ // x * (A * y + B * z) ^ 2

//
export const getEncodedTradeTargetAmount = (
amount: BigNumber,
order: EncodedOrder
const getEncodedTradeBySourceAmount = (
x: BigNumber,
y: BigNumber,
z: BigNumber,
A: BigNumber,
B: BigNumber
): BigNumber => {
const x = amount;
const y = order.y;
const z = order.z;
const A = order.A;
const B = order.B;
if (A.eq(0)) {
return mulDivF(x, mul(B, B), mul(C, C));
}
const temp1 = y.mul(A).add(z.mul(B));
const temp2 = temp1.mul(x).div(ONE);
const temp3 = temp2.mul(A).add(z.mul(z).mul(ONE));
const res = mulDivF(temp1, temp2, temp3);
const temp1 = mul(z, C);
const temp2 = add(mul(y, A), mul(z, B));
const temp3 = mul(temp2, x);
return res.gt(MAX) ? MIN : res;
const factor1 = mulDivC(temp1, temp1, MAX_UINT256);
const factor2 = mulDivC(temp3, A, MAX_UINT256);
const factor = BigNumberMax(factor1, factor2);
const temp4 = mulDivC(temp1, temp1, factor);
const temp5 = mulDivC(temp3, A, factor);
return mulDivF(temp2, temp3.div(factor), add(temp4, temp5));
};

@@ -42,2 +61,74 @@

//
const getEncodedTradeByTargetAmount = (
x: BigNumber,
y: BigNumber,
z: BigNumber,
A: BigNumber,
B: BigNumber
): BigNumber => {
if (A.eq(0)) {
return mulDivC(x, mul(C, C), mul(B, B));
}
const temp1 = mul(z, C);
const temp2 = add(mul(y, A), mul(z, B));
const temp3 = sub(temp2, mul(x, A));
const factor1 = mulDivC(temp1, temp1, MAX_UINT256);
const factor2 = mulDivC(temp2, temp3, MAX_UINT256);
const factor = BigNumberMax(factor1, factor2);
const temp4 = mulDivC(temp1, temp1, factor);
const temp5 = mulDivF(temp2, temp3, factor);
return mulDivC(x, temp4, temp5);
};
//
// M * M * x * y
// ---------------------
// M * (M - L) * x + y
//
const getDecodedTradeBySourceAmount = (
x: Decimal,
y: Decimal,
L: Decimal,
M: Decimal
): Decimal => {
const n = M.mul(M).mul(x).mul(y);
const d = M.mul(M.sub(L)).mul(x).add(y);
return n.div(d);
};
//
// x * y
// -----------------------------
// M * (L - M) * x + M * M * y
//
const getDecodedTradeByTargetAmount = (
x: Decimal,
y: Decimal,
L: Decimal,
M: Decimal
): Decimal => {
const n = x.mul(y);
const d = M.mul(L.sub(M)).mul(x).add(M.mul(M).mul(y));
return n.div(d);
};
export const getEncodedTradeTargetAmount = (
amount: BigNumber,
order: EncodedOrder
): BigNumber => {
const x = amount;
const y = order.y;
const z = order.z;
const A = decodeFloat(order.A);
const B = decodeFloat(order.B);
try {
return uint128(getEncodedTradeBySourceAmount(x, y, z, A, B));
} catch (error) {
return BigNumber.from(0); /* rate = zero / amount = zero */
}
};
export const getEncodedTradeSourceAmount = (

@@ -50,18 +141,11 @@ amount: BigNumber,

const z = order.z;
const A = order.A;
const B = order.B;
const temp1 = z.mul(ONE);
const temp2 = y.mul(A).add(z.mul(B));
const temp3 = temp2.sub(x.mul(A));
const res = mulDivC(x.mul(temp1), temp1, temp2.mul(temp3));
return res.lt(MIN) ? MAX : res;
const A = decodeFloat(order.A);
const B = decodeFloat(order.B);
try {
return uint128(getEncodedTradeByTargetAmount(x, y, z, A, B));
} catch (error) {
return MAX_UINT256; /* rate = amount / infinity = zero */
}
};
//
// M * x * y
// ---------------------------
// (M - sqrt(M * L)) * x + y
//
export const getDecodedTradeTargetAmount = (

@@ -73,17 +157,7 @@ amount: Decimal,

const y = new Decimal(order.liquidity);
const L = new Decimal(order.lowestRate);
const M = new Decimal(order.marginalRate);
const P = M.sub(M.mul(L).sqrt());
const n = y.mul(x).mul(M);
const d = y.add(x.mul(P));
return n.div(d);
const L = new Decimal(order.lowestRate).sqrt();
const M = new Decimal(order.marginalRate).sqrt();
return getDecodedTradeBySourceAmount(x, y, L, M);
};
//
// x * y
// -------------------------------
// (sqrt(M * L) - M) * x + M * y
//
export const getDecodedTradeSourceAmount = (

@@ -95,10 +169,5 @@ amount: Decimal,

const y = new Decimal(order.liquidity);
const L = new Decimal(order.lowestRate);
const M = new Decimal(order.marginalRate);
const P = M.sub(M.mul(L).sqrt());
const n = y.mul(x);
const d = y.mul(M).sub(x.mul(P));
return n.div(d);
const L = new Decimal(order.lowestRate).sqrt();
const M = new Decimal(order.marginalRate).sqrt();
return getDecodedTradeByTargetAmount(x, y, L, M);
};
import { BigNumber } from '@ethersproject/bignumber';
import Decimal from 'decimal.js';
const BigNumberMin = (a: BigNumber, b: BigNumber) => (a.lt(b) ? a : b);
const BigNumberMax = (a: BigNumber, b: BigNumber) => (a.gt(b) ? a : b);
Decimal.set({
precision: 50,
precision: 100,
rounding: Decimal.ROUND_HALF_DOWN,

@@ -11,3 +14,3 @@ toExpNeg: -30,

const ONE = 2 ** 32;
const ONE = 2 ** 48;
const TEN = new Decimal(10);

@@ -20,2 +23,15 @@

export { Decimal, BigNumber, ONE, TEN, tenPow };
const BnToDec = (x: BigNumber) => new Decimal(x.toString());
const DecToBn = (x: Decimal) => BigNumber.from(x.toFixed());
export {
Decimal,
BigNumber,
BigNumberMin,
BigNumberMax,
ONE,
TEN,
tenPow,
BnToDec,
DecToBn,
};

@@ -64,4 +64,4 @@ [

"id": "8",
"input": "41039999999370054965",
"output": "61438348689"
"input": "41039999999612613913",
"output": "61438622968"
}

@@ -133,3 +133,3 @@ ]

"input": "41040000000",
"output": "27396204250677462932"
"output": "27396082137220999023"
}

@@ -201,3 +201,3 @@ ]

"input": "41040000000",
"output": "40986019178566685116"
"output": "40986019178566978850"
}

@@ -335,4 +335,4 @@ ]

"id": "8",
"input": "164159999999584945655",
"output": "244308268527"
"input": "164159999999818711097",
"output": "244309387287"
}

@@ -404,3 +404,3 @@ ]

"input": "164160000000",
"output": "110020108199692881965"
"output": "110019607294006757921"
}

@@ -472,3 +472,3 @@ ]

"input": "164160000000",
"output": "163299701565856627403"
"output": "163299701565857702164"
}

@@ -606,4 +606,4 @@ ]

"id": "8",
"input": "410399999999500199667",
"output": "603671027078"
"input": "410399999999727871389",
"output": "603673927895"
}

@@ -675,3 +675,3 @@ ]

"input": "410400000000",
"output": "277252870037498880096"
"output": "277251554129756653576"
}

@@ -743,3 +743,3 @@ ]

"input": "410400000000",
"output": "405065072195570531442"
"output": "405065072195572728884"
}

@@ -746,0 +746,0 @@ ]

@@ -10,7 +10,14 @@ import { expect } from 'chai';

} from '../src/encoders';
import { BigNumber, Decimal } from '../src/numerics';
import { DecodedStrategy, EncodedStrategy } from '../src/types';
import sinon from 'sinon';
import { BigNumber, Decimal } from '../src/numerics';
import { Decimals } from '../src/decimals';
import { isAlmostEqual } from './test-utils';
// (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
const LOWEST_RATE = new Decimal(10)
.pow(18 - 6)
.div('0.6')
.toFixed();
describe('encoders', () => {

@@ -28,4 +35,4 @@ describe('encodeOrder', () => {

expect(encodedOrder.z.toString()).to.equal('100');
expect(encodedOrder.A.toString()).to.equal('1257966797');
expect(encodedOrder.B.toString()).to.equal('3037000499');
expect(encodedOrder.A.toString()).to.equal('82442111944226');
expect(encodedOrder.B.toString()).to.equal('199032864766430');
});

@@ -44,3 +51,3 @@

expect(encodedOrder.A.toString()).to.equal('0');
expect(encodedOrder.B.toString()).to.equal('3037000499');
expect(encodedOrder.B.toString()).to.equal('199032864766430');
});

@@ -57,6 +64,8 @@

encodeOrder(order);
}).to
.throw(`Invalid order: max must be greater than or equal to mid, and mid must be greater than min
- or the three should be equal (highestRate: ${order.highestRate},
marginalRate: ${order.marginalRate}, lowestRate: ${order.lowestRate})`);
}).to.throw(
'Either one of the following must hold:\n' +
'- highestRate >= marginalRate > lowestRate\n' +
'- highestRate == marginalRate == lowestRate\n' +
`(highestRate = ${order.highestRate}, marginalRate = ${order.marginalRate}, lowestRate = ${order.lowestRate})`
);
});

@@ -67,3 +76,3 @@

liquidity: '100000000000000000000',
lowestRate: '1666666666666.6666666666666666666666666666666666667',
lowestRate: LOWEST_RATE,
highestRate: '2000000000000',

@@ -75,26 +84,33 @@ marginalRate: '2000000000000',

const tolerance = new Decimal(0.001);
expect(
new Decimal(originalOrder.liquidity)
.sub(new Decimal(decodedOrder.liquidity))
.abs()
.lte(tolerance)
...isAlmostEqual(
decodedOrder.liquidity,
originalOrder.liquidity,
'0',
'0'
)
).to.be.true;
expect(
new Decimal(originalOrder.lowestRate)
.sub(new Decimal(decodedOrder.lowestRate))
.abs()
.lte(tolerance)
...isAlmostEqual(
decodedOrder.lowestRate,
originalOrder.lowestRate,
'0',
'0.000000000000004'
)
).to.be.true;
expect(
new Decimal(originalOrder.highestRate)
.sub(new Decimal(decodedOrder.highestRate))
.abs()
.lte(tolerance)
...isAlmostEqual(
decodedOrder.highestRate,
originalOrder.highestRate,
'0',
'0.000000000000002'
)
).to.be.true;
expect(
new Decimal(originalOrder.marginalRate)
.sub(new Decimal(decodedOrder.marginalRate))
.abs()
.lte(tolerance)
...isAlmostEqual(
decodedOrder.marginalRate,
originalOrder.marginalRate,
'0',
'0.000000000000002'
)
).to.be.true;

@@ -111,3 +127,3 @@ });

liquidity: '100000000000000000000', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -132,8 +148,8 @@ marginalRate: '2000000000000', // same as highest rate

);
expect(encodedStrategy.order0.A.toString()).to.equal('529222063314266');
expect(encodedStrategy.order0.B.toString()).to.equal('5544778936637833');
expect(encodedStrategy.order0.A.toString()).to.equal('5049685635738288');
expect(encodedStrategy.order0.B.toString()).to.equal('6084248852693708');
expect(encodedStrategy.order1.y.toString()).to.equal('200000000');
expect(encodedStrategy.order1.z.toString()).to.equal('200000000');
expect(encodedStrategy.order1.A.toString()).to.equal('814');
expect(encodedStrategy.order1.B.toString()).to.equal('5260');
expect(encodedStrategy.order1.A.toString()).to.equal('53330695');
expect(encodedStrategy.order1.B.toString()).to.equal('344735034');
});

@@ -147,3 +163,3 @@

liquidity: '0', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -164,8 +180,8 @@ marginalRate: '2000000000000', // same as highest rate

expect(encodedStrategy.order0.z.toString()).to.equal('0');
expect(encodedStrategy.order0.A.toString()).to.equal('529222063314266');
expect(encodedStrategy.order0.B.toString()).to.equal('5544778936637833');
expect(encodedStrategy.order0.A.toString()).to.equal('5049685635738288');
expect(encodedStrategy.order0.B.toString()).to.equal('6084248852693708');
expect(encodedStrategy.order1.y.toString()).to.equal('0');
expect(encodedStrategy.order1.z.toString()).to.equal('0');
expect(encodedStrategy.order1.A.toString()).to.equal('814');
expect(encodedStrategy.order1.B.toString()).to.equal('5260');
expect(encodedStrategy.order1.A.toString()).to.equal('53330695');
expect(encodedStrategy.order1.B.toString()).to.equal('344735034');
});

@@ -197,3 +213,3 @@ });

liquidity: '100000000000000000000', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -244,3 +260,3 @@ marginalRate: '2000000000000', // same as highest rate

liquidity: '100000000000000000000', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -466,3 +482,3 @@ marginalRate: '2000000000000', // same as highest rate

liquidity: '100000000000000000000', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -540,3 +556,3 @@ marginalRate: '2000000000000', // same as highest rate

liquidity: '100000000000000000000', // 100 (sellBudget) in base tkn converted to wei
lowestRate: '1666666666666.6666666666666666666666666666666666667', // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
lowestRate: LOWEST_RATE, // (1/0.6) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei
highestRate: '2000000000000', // (1/0.5) * 10^18 / 10^6 in base tkn per 1 quote tkn converted to wei

@@ -543,0 +559,0 @@ marginalRate: '2000000000000', // same as highest rate

@@ -79,5 +79,5 @@ import { expect } from 'chai';

}
});
}).timeout(3000);
}
}
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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 too big to display

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