UNPKG

@plasma-fi/sdk

Version:

đź›  An SDK for building dapp on PlasmaSwap.

1 lines • 114 kB
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t,n,a,r,i,o,s,u,p,d,y,m,l,c,f,T,h,b,k,x,v,w,A,g,S=e(require("jsbi")),I=e(require("big.js")),E=e(require("tiny-invariant")),C=e(require("toformat")),P=require("@ethersproject/address"),O=(e(require("tiny-warning")),e(require("decimal.js-light"))),M=require("@ethersproject/solidity"),L=require("@ethersproject/keccak256"),q=require("@ethersproject/bytes"),N=require("@ethersproject/bignumber"),F=require("@ethersproject/abi");I.NE=-18,I.PE=32,(x=exports.ChainId||(exports.ChainId={}))[x.MAINNET=1]="MAINNET",x[x.ROPSTEN=3]="ROPSTEN",x[x.RINKEBY=4]="RINKEBY",x[x["GÖRLI"]=5]="GÖRLI",x[x.KOVAN=42]="KOVAN",x[x.MATIC=137]="MATIC",x[x.BSC=56]="BSC",x[x.BSC_TEST=97]="BSC_TEST",(v=exports.LiquidityProvider||(exports.LiquidityProvider={}))[v.PLASMA=0]="PLASMA",v[v.UNISWAP=1]="UNISWAP",v[v.SUSHISWAP=2]="SUSHISWAP",v[v.PANCAKESWAP=3]="PANCAKESWAP",v[v.QUICKSWAP=4]="QUICKSWAP",(w=exports.Trade0xLiquiditySource||(exports.Trade0xLiquiditySource={})).Native="Native",w.Uniswap="Uniswap",w.UniswapV2="Uniswap_V2",w.Eth2Dai="Eth2Dai",w.Kyber="Kyber",w.Curve="Curve",w.LiquidityProvider="LiquidityProvider",w.MultiBridge="MultiBridge",w.Balancer="Balancer",w.BalancerV2="Balancer_V2",w.Cream="CREAM",w.Bancor="Bancor",w.MakerPsm="MakerPsm",w.MStable="mStable",w.Mooniswap="Mooniswap",w.MultiHop="MultiHop",w.Shell="Shell",w.Swerve="Swerve",w.SnowSwap="SnowSwap",w.SushiSwap="SushiSwap",w.Dodo="DODO",w.DodoV2="DODO_V2",w.CryptoCom="CryptoCom",w.Linkswap="Linkswap",w.KyberDmm="KyberDMM",w.Smoothy="Smoothy",w.Component="Component",w.Saddle="Saddle",w.XSigma="xSigma",w.UniswapV3="Uniswap_V3",w.CurveV2="Curve_V2",w.Lido="Lido",w.ShibaSwap="ShibaSwap",w.Clipper="Clipper",w.PancakeSwap="PancakeSwap",w.PancakeSwapV2="PancakeSwap_V2",w.BakerySwap="BakerySwap",w.Nerve="Nerve",w.Belt="Belt",w.Ellipsis="Ellipsis",w.ApeSwap="ApeSwap",w.CafeSwap="CafeSwap",w.CheeseSwap="CheeseSwap",w.JulSwap="JulSwap",w.ACryptos="ACryptoS",w.QuickSwap="QuickSwap",w.ComethSwap="ComethSwap",w.Dfyn="Dfyn",w.WaultSwap="WaultSwap",w.Polydex="Polydex",w.FirebirdOneSwap="FirebirdOneSwap",w.JetSwap="JetSwap",w.IronSwap="IronSwap",(A=exports.TradeType||(exports.TradeType={}))[A.LIMIT=0]="LIMIT",A[A.EXACT_INPUT=1]="EXACT_INPUT",A[A.EXACT_OUTPUT=2]="EXACT_OUTPUT",(g=exports.Rounding||(exports.Rounding={}))[g.ROUND_DOWN=0]="ROUND_DOWN",g[g.ROUND_HALF_UP=1]="ROUND_HALF_UP",g[g.ROUND_UP=2]="ROUND_UP";var B,R="0x0000000000000000000000000000000000000000",_=["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x0000000000000000000000000000000000001010"],D=((t={})[exports.ChainId.MAINNET]="Ethereum",t[exports.ChainId.RINKEBY]="Rinkeby",t[exports.ChainId.ROPSTEN]="Ropsten",t[exports.ChainId.GÖRLI]="Görli",t[exports.ChainId.KOVAN]="Kovan",t[exports.ChainId.MATIC]="Polygon",t[exports.ChainId.BSC]="Binance",t[exports.ChainId.BSC_TEST]="Binance Test",t),U=((n={})[exports.ChainId.MAINNET]="Ethereum Mainnet",n[exports.ChainId.RINKEBY]="Rinkeby Test Network",n[exports.ChainId.ROPSTEN]="Ropsten Test Network",n[exports.ChainId.GÖRLI]="Goerli Test Network",n[exports.ChainId.KOVAN]="Kovan Test Network",n[exports.ChainId.MATIC]="Polygon Matic",n[exports.ChainId.BSC]="Binance Smart Chain",n[exports.ChainId.BSC_TEST]="Binance Smart Chain Test",n),H=((a={})[exports.ChainId.MAINNET]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a[exports.ChainId.ROPSTEN]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a[exports.ChainId.RINKEBY]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a[exports.ChainId.KOVAN]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a[exports.ChainId.MATIC]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a[exports.ChainId.BSC]="0xdef1c0ded9bec7f1a1670819833240f027b25eff",a),W=((r={})[exports.ChainId.MAINNET]="0x0019f661c0798affea4dd0949a526b873511a9f5",r[exports.ChainId.BSC]="0x77a9f45dd68142221cdcb06df1a67307399b8aae",r[exports.ChainId.MATIC]="0xe0c4c4e104615dbcbc3718b79de803f2fffe680c",r[exports.ChainId.ROPSTEN]="0x34fb8116b7add1441d7197cf71a2ec48f3b055bd",r[exports.ChainId.KOVAN]="0x9abb6b05734b3a8422a4ee50a5ddd76764424734",r),V=((l={})[exports.ChainId.MAINNET]=((i={})[exports.LiquidityProvider.UNISWAP]={factory:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",router:"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1588610042,createdBlockNumber:10000835,graphUrl:"https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2",graphWs:"wss://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2"},i[exports.LiquidityProvider.PLASMA]={factory:"0xd87Ad19db2c4cCbf897106dE034D52e3DD90ea60",router:"0x5ec243F1F7ECFC137e98365C30c9A28691d86132",initCodeHash:"0x611ee9501fb19c9df82695e66f6c58d69d86907b531dfbed652231515ae84081",createdTimestamp:1611490369,createdBlockNumber:11718234,graphUrl:"https://api.thegraph.com/subgraphs/name/itsib/plasmaswap-v2",graphWs:"https://sg.plasma.finance/subgraphs/name/plasmaswap/mainnet"},i[exports.LiquidityProvider.SUSHISWAP]={factory:"0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac",router:"0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f",initCodeHash:"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",createdTimestamp:1599214239,createdBlockNumber:10794229,graphUrl:"https://api.thegraph.com/subgraphs/name/sushiswap/exchange",graphWs:"wss://api.thegraph.com/subgraphs/name/sushiswap/exchange"},i),l[exports.ChainId.ROPSTEN]=((o={})[exports.LiquidityProvider.UNISWAP]={factory:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",router:"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1588609929,createdBlockNumber:7842777},o),l[exports.ChainId.RINKEBY]=((s={})[exports.LiquidityProvider.UNISWAP]={factory:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",router:"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1588609623,createdBlockNumber:6430279},s),l[exports.ChainId.GÖRLI]=((u={})[exports.LiquidityProvider.UNISWAP]={factory:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",router:"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1616151422,createdBlockNumber:4467712},u),l[exports.ChainId.KOVAN]=((p={})[exports.LiquidityProvider.UNISWAP]={factory:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",router:"0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1588609788,createdBlockNumber:18344859,graphUrl:"https://api.thegraph.com/subgraphs/name/maurodelazeri/uniswapv2-kovan",graphWs:"wss://api.thegraph.com/subgraphs/name/maurodelazeri/uniswapv2-kovan"},p[exports.LiquidityProvider.PLASMA]={factory:"0x7A6521ba7Ba45C908be726D719ACd547D4a8E246",router:"0x905df0e2cd022bc1a67bf15df485b18ea631d304",initCodeHash:"0xe60eb03e61b5fbeba179f6defb71bb00c5db9dab3b10d39c3985d66081de6d3d",createdTimestamp:1606861200,createdBlockNumber:22379351,graphUrl:"https://sg.plasma.finance/subgraphs/name/plasmaswap/kovan",graphWs:"wss://sg.plasma.finance/ws/subgraphs/name/plasmaswap/kovan"},p[exports.LiquidityProvider.SUSHISWAP]={factory:"0x8D4FD620CB7Ed677870b8b62f22c166cC76fb519",router:"0x4A0b3a56ECb360924639F57Cd41d0358Aed9aCDd",initCodeHash:"0xa0f8210a4091231cb34588d36a21ac73a6681adda0d825bf06c963da5ff4af47",createdTimestamp:1612524980,createdBlockNumber:23322618},p),l[exports.ChainId.MATIC]=((d={})[exports.LiquidityProvider.PLASMA]={factory:"0x745c475CC101cA5580eFf6F723976480881BC008",router:"0x5D5BADeF6F69cBafDF443D6226dC00B24626367E",initCodeHash:"0xb19b1e3807140bf48c498cb50370e129d9bd9e5e333bf0e67d9ce7507e634b72",createdTimestamp:1623075489,createdBlockNumber:15441546,graphUrl:"https://sg.plasma.finance/subgraphs/name/plasmaswap/matic",graphWs:"wss://sg.plasma.finance/ws/subgraphs/name/plasmaswap/matic"},d[exports.LiquidityProvider.SUSHISWAP]={factory:"0xc35DADB65012eC5796536bD9864eD8773aBc74C4",router:"0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",initCodeHash:"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",createdTimestamp:1614311449,createdBlockNumber:11333218,graphUrl:"https://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange",graphWs:"wss://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange"},d[exports.LiquidityProvider.QUICKSWAP]={factory:"0x5757371414417b8c6caad45baef941abc7d3ab32",router:"0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff",initCodeHash:"0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",createdTimestamp:1615266493,createdBlockNumber:11799756,graphUrl:"https://sg.plasma.finance/subgraphs/name/quickswap/matic",graphWs:"wss://sg.plasma.finance/ws/subgraphs/name/quickswap/matic"},d),l[exports.ChainId.BSC]=((y={})[exports.LiquidityProvider.PLASMA]={factory:"0x0A0f1abd7eC4c2AbF92F8e33382fA77863154628",router:"0xBFBc891E6C707243Bb1949A92A1DcBc9ba160DE7",initCodeHash:"0x8614648fda2cedabe024f773fb6929fd773c7db2d1bfc6dc92f716b47c2b7047",createdTimestamp:1629711966,createdBlockNumber:10276490,graphUrl:"https://sg.plasma.finance/subgraphs/name/plasmaswap/bsc",graphWs:"wss://sg.plasma.finance/ws/subgraphs/name/plasmaswap/bsc"},y[exports.LiquidityProvider.SUSHISWAP]={factory:"0xc35DADB65012eC5796536bD9864eD8773aBc74C4",router:"0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506",initCodeHash:"0xe18a34eb0e04b04f7a0ac29a6e80748dca96319b42c54d679cb821dca90c6303",createdTimestamp:1614313236,createdBlockNumber:5205069,graphUrl:"https://api.thegraph.com/subgraphs/name/sushiswap/bsc-exchange",graphWs:"wss://api.thegraph.com/subgraphs/name/sushiswap/bsc-exchange"},y[exports.LiquidityProvider.PANCAKESWAP]={factory:"0xca143ce32fe78f1f7019d7d551a6402fc5350c73",router:"0x10ed43c718714eb63d5aa57b78b54704e256024e",initCodeHash:"0x00fb7f630766e6a796048ea87d01acd3068e8ff67d078148a3fa3f4a84f69bd5",createdTimestamp:1619164516,createdBlockNumber:6809737,graphUrl:"https://api.thegraph.com/subgraphs/name/itsib/pancakeswap-v2",graphWs:"wss://api.thegraph.com/subgraphs/name/itsib/pancakeswap-v2"},y),l[exports.ChainId.BSC_TEST]=((m={})[exports.LiquidityProvider.PLASMA]={factory:"0x06AC9D070bD01a42a198373F34547cFF26FBDbdC",router:"0xB8bc629c49c293d0F9e6C03134F681348076AE46",initCodeHash:"0x3881dfd3256e5d121350fe797cb9f3e28704ee8656f3522205fac47519f3a9f4",createdTimestamp:1629645320,createdBlockNumber:11703645},m[exports.LiquidityProvider.PANCAKESWAP]={factory:"0xb7926c0430afb07aa7defde6da862ae0bde767bc",router:"0x9ac64cc6e4415144c455bd8e4837fea55603e5c3",initCodeHash:"0xecba335299a6693cb2ebc4782e74669b84290b6378ea3a3873c7231a8d7d1074",createdTimestamp:1621968819,createdBlockNumber:9158270},m),l),j=S.BigInt(1e3),K=((c={})[exports.LiquidityProvider.UNISWAP]="Uniswap V2",c[exports.LiquidityProvider.PLASMA]="Plasmaswap",c[exports.LiquidityProvider.SUSHISWAP]="SushiSwap LP Token",c[exports.LiquidityProvider.PANCAKESWAP]="Pancake LPs",c[exports.LiquidityProvider.QUICKSWAP]="Uniswap V2",c),X=((f={})[exports.LiquidityProvider.UNISWAP]="UNI-V2",f[exports.LiquidityProvider.PLASMA]="P-LP",f[exports.LiquidityProvider.SUSHISWAP]="SLP",f[exports.LiquidityProvider.PANCAKESWAP]="Cake-LP",f[exports.LiquidityProvider.QUICKSWAP]="UNI-V2",f),G=((T={})[exports.LiquidityProvider.PLASMA]="PLASMA",T[exports.LiquidityProvider.UNISWAP]="UNISWAP",T[exports.LiquidityProvider.SUSHISWAP]="SUSHISWAP",T[exports.LiquidityProvider.PANCAKESWAP]="PANCAKESWAP",T[exports.LiquidityProvider.QUICKSWAP]="QUICKSWAP",T),Y=((h={})[exports.LiquidityProvider.PLASMA]="PlasmaSwap",h[exports.LiquidityProvider.UNISWAP]="Uniswap V2",h[exports.LiquidityProvider.SUSHISWAP]="SushiSwap",h[exports.LiquidityProvider.PANCAKESWAP]="PancakeSwap",h[exports.LiquidityProvider.QUICKSWAP]="Quickswap",h),Q=[exports.ChainId.MAINNET,exports.ChainId.MATIC,exports.ChainId.BSC,exports.ChainId.ROPSTEN,exports.ChainId.KOVAN],J=((b={})[exports.Trade0xLiquiditySource.Native]="Native",b[exports.Trade0xLiquiditySource.Uniswap]="Uniswap",b[exports.Trade0xLiquiditySource.UniswapV2]="Uniswap V2",b[exports.Trade0xLiquiditySource.UniswapV3]="Uniswap V3",b[exports.Trade0xLiquiditySource.Eth2Dai]="ETH to DAI",b[exports.Trade0xLiquiditySource.Kyber]="Kyber",b[exports.Trade0xLiquiditySource.Curve]="Curve",b[exports.Trade0xLiquiditySource.CurveV2]="Curve V2",b[exports.Trade0xLiquiditySource.LiquidityProvider]="Liquidity Provider",b[exports.Trade0xLiquiditySource.MultiBridge]="MultiBridge",b[exports.Trade0xLiquiditySource.Balancer]="Balancer",b[exports.Trade0xLiquiditySource.BalancerV2]="Balancer V2",b[exports.Trade0xLiquiditySource.Cream]="CREAM",b[exports.Trade0xLiquiditySource.Bancor]="Bancor",b[exports.Trade0xLiquiditySource.MakerPsm]="MakerPSM",b[exports.Trade0xLiquiditySource.MStable]="mStable",b[exports.Trade0xLiquiditySource.Mooniswap]="Mooniswap",b[exports.Trade0xLiquiditySource.MultiHop]="HyperDEX",b[exports.Trade0xLiquiditySource.Shell]="Shell",b[exports.Trade0xLiquiditySource.Swerve]="Swerve",b[exports.Trade0xLiquiditySource.SnowSwap]="SnowSwap",b[exports.Trade0xLiquiditySource.SushiSwap]="SushiSwap",b[exports.Trade0xLiquiditySource.Dodo]="DODO",b[exports.Trade0xLiquiditySource.DodoV2]="DODO V2",b[exports.Trade0xLiquiditySource.CryptoCom]="CryptoCom",b[exports.Trade0xLiquiditySource.Linkswap]="Linkswap",b[exports.Trade0xLiquiditySource.KyberDmm]="KyberDMM",b[exports.Trade0xLiquiditySource.Smoothy]="Smoothy",b[exports.Trade0xLiquiditySource.Component]="Component",b[exports.Trade0xLiquiditySource.Saddle]="Saddle",b[exports.Trade0xLiquiditySource.XSigma]="xSigma",b[exports.Trade0xLiquiditySource.Lido]="Lido",b[exports.Trade0xLiquiditySource.ShibaSwap]="ShibaSwap",b[exports.Trade0xLiquiditySource.Clipper]="Clipper",b[exports.Trade0xLiquiditySource.PancakeSwap]="PancakeSwap",b[exports.Trade0xLiquiditySource.PancakeSwapV2]="PancakeSwap V2",b[exports.Trade0xLiquiditySource.BakerySwap]="BakerySwap",b[exports.Trade0xLiquiditySource.Nerve]="Nerve",b[exports.Trade0xLiquiditySource.Belt]="Belt",b[exports.Trade0xLiquiditySource.Ellipsis]="Ellipsis",b[exports.Trade0xLiquiditySource.ApeSwap]="ApeSwap",b[exports.Trade0xLiquiditySource.CafeSwap]="CafeSwap",b[exports.Trade0xLiquiditySource.CheeseSwap]="CheeseSwap",b[exports.Trade0xLiquiditySource.JulSwap]="JulSwap",b[exports.Trade0xLiquiditySource.ACryptos]="ACryptoS",b[exports.Trade0xLiquiditySource.QuickSwap]="QuickSwap",b[exports.Trade0xLiquiditySource.ComethSwap]="ComethSwap",b[exports.Trade0xLiquiditySource.Dfyn]="Dfyn",b[exports.Trade0xLiquiditySource.WaultSwap]="WaultSwap",b[exports.Trade0xLiquiditySource.Polydex]="Polydex",b[exports.Trade0xLiquiditySource.FirebirdOneSwap]="FirebirdOneSwap",b[exports.Trade0xLiquiditySource.JetSwap]="JetSwap",b[exports.Trade0xLiquiditySource.IronSwap]="IronSwap",b),Z=S.BigInt(0),z=S.BigInt(1),$=S.BigInt(2),ee=S.BigInt(3),te=S.BigInt(5),ne=S.BigInt(10),ae=S.BigInt(100),re=S.BigInt(997),ie=S.BigInt(1e3);!function(e){e.uint8="uint8",e.uint256="uint256"}(B||(B={}));var oe=((k={})[B.uint8]=S.BigInt("0xff"),k[B.uint256]=S.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),k);function se(e,t,n,a,r,i,o){try{var s=e[i](o),u=s.value}catch(e){return void n(e)}s.done?t(u):Promise.resolve(u).then(a,r)}function ue(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var i=e.apply(t,n);function o(e){se(i,a,r,o,s,"next",e)}function s(e){se(i,a,r,o,s,"throw",e)}o(void 0)}))}}function pe(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,a.key,a)}}function de(e,t,n){return t&&pe(e.prototype,t),n&&pe(e,n),e}function ye(){return(ye=Object.assign||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}).apply(this,arguments)}function me(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function le(e){return(le=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ce(e,t){return(ce=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function fe(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function Te(e,t,n){return(Te=fe()?Reflect.construct:function(e,t,n){var a=[null];a.push.apply(a,t);var r=new(Function.bind.apply(e,a));return n&&ce(r,n.prototype),r}).apply(null,arguments)}function he(e){var t="function"==typeof Map?new Map:void 0;return(he=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return Te(e,arguments,le(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),ce(n,e)})(e)}function be(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ke(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 xe(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return ke(e,void 0);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)?ke(e,void 0):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.")}return(n=e[Symbol.iterator]()).next.bind(n)}var ve,we,Ae="setPrototypeOf"in Object,ge=function(e){function t(){var n;return(n=e.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,Ae&&Object.setPrototypeOf(be(n),(this instanceof t?this.constructor:void 0).prototype),n}return me(t,e),t}(he(Error)),Se=function(e){function t(){var n;return(n=e.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,Ae&&Object.setPrototypeOf(be(n),(this instanceof t?this.constructor:void 0).prototype),n}return me(t,e),t}(he(Error)),Ie=function(e){function t(n,a){var r;return void 0===n&&(n="Validation Error"),void 0===a&&(a=[]),(r=e.call(this,n)||this).name=r.constructor.name,r.fields=a,Ae&&Object.setPrototypeOf(be(r),(this instanceof t?this.constructor:void 0).prototype),r}return me(t,e),t}(he(Error));function Ee(e){try{return P.getAddress(e)}catch(e){E(!1)}}var Ce=function(e,t,n,a){Number.isSafeInteger(e)||E(!1),t>=0&&t<255&&Number.isInteger(t)||E(!1),this.chainId=e,this.decimals=t,this.symbol=n,this.name=a},Pe=function(e){function t(t,n,a,r){var i;return(i=e.call(this,t,n,a,r)||this).isNative=!0,i.isToken=!1,i}me(t,e);var n=t.prototype;return n.equals=function(e){return e.isNative&&e.chainId===this.chainId},n.wrapped=function(){var e=Ne[this.chainId];return e||E(!1),e},n.unwrapped=function(){return this},t}(Ce);Pe.NATIVE=((ve={})[exports.ChainId.MAINNET]=new Pe(exports.ChainId.MAINNET,18,"ETH","Ethereum"),ve[exports.ChainId.KOVAN]=new Pe(exports.ChainId.KOVAN,18,"ETH","Ethereum"),ve[exports.ChainId.ROPSTEN]=new Pe(exports.ChainId.ROPSTEN,18,"ETH","Ethereum"),ve[exports.ChainId.RINKEBY]=new Pe(exports.ChainId.RINKEBY,18,"ETH","Ethereum"),ve[exports.ChainId.GÖRLI]=new Pe(exports.ChainId.GÖRLI,18,"ETH","Ethereum"),ve[exports.ChainId.MATIC]=new Pe(exports.ChainId.MATIC,18,"MATIC","Matic"),ve[exports.ChainId.BSC]=new Pe(exports.ChainId.BSC,18,"BNB","BNB"),ve[exports.ChainId.BSC_TEST]=new Pe(exports.ChainId.BSC_TEST,18,"BNB","BNB"),ve);var Oe,Me,Le=function(e){function t(t,n,a,r,i){var o;return(o=e.call(this,t,a,r,i)||this).isNative=!1,o.isToken=!0,o.address=Ee(n),o}me(t,e);var n=t.prototype;return n.equals=function(e){return e.isToken&&this.chainId===e.chainId&&this.address===e.address},n.sortsBefore=function(e){return this.chainId!==e.chainId&&E(!1),this.address===e.address&&E(!1),this.address.toLowerCase()<e.address.toLowerCase()},n.wrapped=function(){return this},n.unwrapped=function(){return this.equals(Ne[this.chainId])?qe[this.chainId]:this},t}(Ce),qe=Pe.NATIVE,Ne=((we={})[exports.ChainId.MAINNET]=new Le(exports.ChainId.MAINNET,"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",18,"WETH","Wrapped Ether"),we[exports.ChainId.ROPSTEN]=new Le(exports.ChainId.ROPSTEN,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),we[exports.ChainId.RINKEBY]=new Le(exports.ChainId.RINKEBY,"0xc778417E063141139Fce010982780140Aa0cD5Ab",18,"WETH","Wrapped Ether"),we[exports.ChainId.GÖRLI]=new Le(exports.ChainId.GÖRLI,"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6",18,"WETH","Wrapped Ether"),we[exports.ChainId.KOVAN]=new Le(exports.ChainId.KOVAN,"0xd0A1E359811322d97991E03f863a0C30C2cF029C",18,"WETH","Wrapped Ether"),we[exports.ChainId.MATIC]=new Le(exports.ChainId.MATIC,"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",18,"WMATIC","Wrapped Matic"),we[exports.ChainId.BSC]=new Le(exports.ChainId.BSC,"0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",18,"WBNB","Wrapped BNB"),we[exports.ChainId.BSC_TEST]=new Le(exports.ChainId.BSC_TEST,"0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",18,"WBNB","Wrapped BNB"),we);function Fe(e){return!(!e&&"object"!=typeof e)&&(e instanceof Pe||e instanceof Le)}function Be(e){return e instanceof S?e:S.BigInt("bigint"==typeof e?e.toString():e)}function Re(e,t){S.greaterThanOrEqual(e,Z)||E(!1),S.lessThanOrEqual(e,oe[t])||E(!1)}var _e=C(O),De=C(I),Ue=((Oe={})[exports.Rounding.ROUND_DOWN]=_e.ROUND_DOWN,Oe[exports.Rounding.ROUND_HALF_UP]=_e.ROUND_HALF_UP,Oe[exports.Rounding.ROUND_UP]=_e.ROUND_UP,Oe),He=((Me={})[exports.Rounding.ROUND_DOWN]=0,Me[exports.Rounding.ROUND_HALF_UP]=1,Me[exports.Rounding.ROUND_UP]=3,Me),We=function(){function e(e,t){void 0===t&&(t=z),this.numerator=Be(e),this.denominator=Be(t)}var t=e.prototype;return t.invert=function(){return new e(this.denominator,this.numerator)},t.add=function(t){var n=t instanceof e?t:new e(Be(t));return S.equal(this.denominator,n.denominator)?new e(S.add(this.numerator,n.numerator),this.denominator):new e(S.add(S.multiply(this.numerator,n.denominator),S.multiply(n.numerator,this.denominator)),S.multiply(this.denominator,n.denominator))},t.subtract=function(t){var n=t instanceof e?t:new e(Be(t));return S.equal(this.denominator,n.denominator)?new e(S.subtract(this.numerator,n.numerator),this.denominator):new e(S.subtract(S.multiply(this.numerator,n.denominator),S.multiply(n.numerator,this.denominator)),S.multiply(this.denominator,n.denominator))},t.lessThan=function(t){var n=t instanceof e?t:new e(Be(t));return S.lessThan(S.multiply(this.numerator,n.denominator),S.multiply(n.numerator,this.denominator))},t.equalTo=function(t){var n=t instanceof e?t:new e(Be(t));return S.equal(S.multiply(this.numerator,n.denominator),S.multiply(n.numerator,this.denominator))},t.greaterThan=function(t){var n=t instanceof e?t:new e(Be(t));return S.greaterThan(S.multiply(this.numerator,n.denominator),S.multiply(n.numerator,this.denominator))},t.multiply=function(t){var n=t instanceof e?t:new e(Be(t));return new e(S.multiply(this.numerator,n.numerator),S.multiply(this.denominator,n.denominator))},t.divide=function(t){var n=t instanceof e?t:new e(Be(t));return new e(S.multiply(this.numerator,n.denominator),S.multiply(this.denominator,n.numerator))},t.toSignificant=function(e,t,n){void 0===t&&(t={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(e)||E(!1),e>0||E(!1),_e.set({precision:e+1,rounding:Ue[n]});var a=new _e(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(e);return a.toFormat(a.decimalPlaces(),t)},t.toFixed=function(e,t,n){return void 0===t&&(t={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(e)||E(!1),e>=0||E(!1),De.DP=e,De.RM=He[n],new De(this.numerator.toString()).div(this.denominator.toString()).toFormat(e,t)},de(e,[{key:"quotient",get:function(){return S.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new e(S.remainder(this.numerator,this.denominator),this.denominator)}}]),e}(),Ve=C(I),je=function(e){function t(t,n){var a,r=Be(n);return Re(r,B.uint256),(a=e.call(this,r,S.exponentiate(ne,S.BigInt(t.decimals)))||this).currency=t,a}me(t,e);var n=t.prototype;return n.wrapped=function(){return this instanceof Xe?this:new Xe(Ne[this.currency.chainId],this.raw)},n.unwrapped=function(){return this.currency.equals(Ne[this.currency.chainId])?Ke.native(this.currency.chainId,this.raw):this},n.toSignificant=function(t,n,a){return void 0===t&&(t=6),void 0===a&&(a=exports.Rounding.ROUND_DOWN),e.prototype.toSignificant.call(this,t,n,a)},n.toFixed=function(t,n,a){return void 0===t&&(t=this.currency.decimals),void 0===a&&(a=exports.Rounding.ROUND_DOWN),t<=this.currency.decimals||E(!1),e.prototype.toFixed.call(this,t,n,a)},n.toExact=function(e){return void 0===e&&(e={groupSeparator:""}),Ve.DP=this.currency.decimals,new Ve(this.numerator.toString()).div(this.denominator.toString()).toFormat(e)},de(t,[{key:"raw",get:function(){return this.numerator}}]),t}(We),Ke=function(e){function t(t,n){return e.call(this,t,n)||this}me(t,e),t.native=function(e,n){return new t(e instanceof Pe?e:Pe.NATIVE[e],n)};var n=t.prototype;return n.add=function(e){return this.currency.equals(e.currency)||E(!1),new t(this.currency,S.add(this.raw,e.raw))},n.subtract=function(e){return this.currency.equals(e.currency)||E(!1),new t(this.currency,S.subtract(this.raw,e.raw))},t}(je),Xe=function(e){function t(t,n){var a;return(a=e.call(this,t,n)||this).token=t,a}me(t,e);var n=t.prototype;return n.add=function(e){return this.token.equals(e.token)||E(!1),new t(this.token,S.add(this.raw,e.raw))},n.subtract=function(e){return this.token.equals(e.token)||E(!1),new t(this.token,S.subtract(this.raw,e.raw))},t}(je);function Ge(e){return!(!e&&"object"!=typeof e)&&(e instanceof Ke||e instanceof Xe)}var Ye=new We(ae),Qe=function(e){function t(){return e.apply(this,arguments)||this}me(t,e);var n=t.prototype;return n.toSignificant=function(e,t,n){return void 0===e&&(e=5),this.multiply(Ye).toSignificant(e,t,n)},n.toFixed=function(e,t,n){return void 0===e&&(e=2),this.multiply(Ye).toFixed(e,t,n)},n.toExact=function(){return new I(this.numerator.toString()).div(this.denominator.toString()).toString()},t}(We);function Je(e,t){return e instanceof Le?new Xe(e,t):Ke.native(e,t)}var Ze=function(e){function t(t,n,a,r){var i;return(i=e.call(this,r,a)||this).baseCurrency=t,i.quoteCurrency=n,i.scalar=new We(S.exponentiate(ne,S.BigInt(t.decimals)),S.exponentiate(ne,S.BigInt(n.decimals))),i}me(t,e),t.fromRoute=function(e){for(var n,a=[],r=xe(e.pairs.entries());!(n=r()).done;){var i=n.value,o=i[1];a.push(e.path[i[0]].equals(o.token0)?new t(o.reserve0.currency,o.reserve1.currency,o.reserve0.raw,o.reserve1.raw):new t(o.reserve1.currency,o.reserve0.currency,o.reserve1.raw,o.reserve0.raw))}return a.slice(1).reduce((function(e,t){return e.multiply(t)}),a[0])};var n=t.prototype;return n.invert=function(){return new t(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){this.quoteCurrency.equals(n.baseCurrency)||E(!1);var a=e.prototype.multiply.call(this,n);return new t(this.baseCurrency,n.quoteCurrency,a.denominator,a.numerator)},n.quote=function(t){return t.currency.equals(this.baseCurrency)||E(!1),Je(this.quoteCurrency,e.prototype.multiply.call(this,t.raw).quotient)},n.quotePerOne=function(){var t=S.exponentiate(S.BigInt(10),S.BigInt(this.baseCurrency.decimals)),n=Je(this.baseCurrency,t);return Je(this.quoteCurrency,e.prototype.multiply.call(this,n.raw).quotient)},n.toSignificant=function(e,t,n){return void 0===e&&(e=6),this.adjusted.toSignificant(e,t,n)},n.toFixed=function(e,t,n){return void 0===e&&(e=4),this.adjusted.toFixed(e,t,n)},de(t,[{key:"raw",get:function(){return new We(this.numerator,this.denominator)}},{key:"adjusted",get:function(){return e.prototype.multiply.call(this,this.scalar)}}]),t}(We);function ze(e,t){var n;return void 0===e||void 0===t?null:null!=(n=V[e][t])?n:null}function $e(e){Re(e,B.uint256);var t,n=Z;if(S.greaterThan(e,ee))for(n=e,t=S.add(S.divide(e,$),z);S.lessThan(t,n);)n=t,t=S.divide(S.add(S.divide(e,t),t),$);else S.notEqual(e,Z)&&(n=z);return n}var et,tt={},nt=function(){function e(t,n,a){var r=t.token.sortsBefore(n.token)?[t,n]:[n,t];this.liquidityProvider=a,this.liquidityToken=e.toTokenOfLiquidity(r[0].token,r[1].token,a),this.tokenAmounts=r}e.getAddress=function(e,t,n){var a,r,i=e.sortsBefore(t)?[e,t]:[t,e],o=ze(e.chainId,n);if(!o)throw new Error("Unsupported liquidity provider "+Y[n]+" in network "+D[e.chainId]);if(null==tt||null==(a=tt[n])||null==(r=a[i[0].address])||!r[i[1].address]){var s=P.getCreate2Address(o.factory,M.keccak256(["bytes"],[M.pack(["address","address"],[i[0].address,i[1].address])]),o.initCodeHash);tt[n]||(tt[n]={}),tt[n][i[0].address]||(tt[n][i[0].address]={}),tt[n][i[0].address][i[1].address]=s}return tt[n][i[0].address][i[1].address]},e.toTokenOfLiquidity=function(t,n,a){return new Le(t.chainId,e.getAddress(t,n,a),18,X[a],K[a])};var t=e.prototype;return t.involvesToken=function(e){return e.equals(this.token0)||e.equals(this.token1)},t.priceOf=function(e){return this.involvesToken(e)||E(!1),e.equals(this.token0)?this.token0Price:this.token1Price},t.reserveOf=function(e){return this.involvesToken(e)||E(!1),e.equals(this.token0)?this.reserve0:this.reserve1},t.getOutputAmount=function(t){if(this.involvesToken(t.token)||E(!1),S.equal(this.reserve0.raw,Z)||S.equal(this.reserve1.raw,Z))throw new ge;var n=this.reserveOf(t.token),a=this.reserveOf(t.token.equals(this.token0)?this.token1:this.token0),r=S.multiply(t.raw,re),i=S.multiply(r,a.raw),o=S.add(S.multiply(n.raw,ie),r),s=new Xe(t.token.equals(this.token0)?this.token1:this.token0,S.divide(i,o));if(S.equal(s.raw,Z))throw new Se;return[s,new e(n.add(t),a.subtract(s),this.liquidityProvider)]},t.getInputAmount=function(t){if(this.involvesToken(t.token)||E(!1),S.equal(this.reserve0.raw,Z)||S.equal(this.reserve1.raw,Z)||S.greaterThanOrEqual(t.raw,this.reserveOf(t.token).raw))throw new ge;var n=this.reserveOf(t.token),a=this.reserveOf(t.token.equals(this.token0)?this.token1:this.token0),r=S.multiply(S.multiply(a.raw,t.raw),ie),i=S.multiply(S.subtract(n.raw,t.raw),re),o=new Xe(t.token.equals(this.token0)?this.token1:this.token0,S.add(S.divide(r,i),z));return[o,new e(a.add(o),n.subtract(t),this.liquidityProvider)]},t.getLiquidityMinted=function(e,t,n){e.token.equals(this.liquidityToken)||E(!1);var a,r=t.token.sortsBefore(n.token)?[t,n]:[n,t];if(r[0].token.equals(this.token0)&&r[1].token.equals(this.token1)||E(!1),S.equal(e.raw,Z))a=S.subtract($e(S.multiply(r[0].raw,r[1].raw)),j);else{var i=S.divide(S.multiply(r[0].raw,e.raw),this.reserve0.raw),o=S.divide(S.multiply(r[1].raw,e.raw),this.reserve1.raw);a=S.lessThanOrEqual(i,o)?i:o}if(!S.greaterThan(a,Z))throw new Se;return new Xe(this.liquidityToken,a)},t.getLiquidityValue=function(e,t,n,a,r){var i;if(void 0===a&&(a=!1),this.involvesToken(e)||E(!1),t.token.equals(this.liquidityToken)||E(!1),n.token.equals(this.liquidityToken)||E(!1),S.lessThanOrEqual(n.raw,t.raw)||E(!1),a){r||E(!1);var o=Be(r);if(S.equal(o,Z))i=t;else{var s=$e(S.multiply(this.reserve0.raw,this.reserve1.raw)),u=$e(o);if(S.greaterThan(s,u)){var p=S.multiply(t.raw,S.subtract(s,u)),d=S.add(S.multiply(s,te),u),y=S.divide(p,d);i=t.add(new Xe(this.liquidityToken,y))}else i=t}}else i=t;return new Xe(e,S.divide(S.multiply(n.raw,this.reserveOf(e).raw),i.raw))},de(e,[{key:"token0Price",get:function(){return new Ze(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new Ze(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].token}},{key:"token1",get:function(){return this.tokenAmounts[1].token}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),e}(),at=function(){function e(e,t,n){var a=e[0].chainId;e.length>0||E(!1),e.every((function(e){return e.chainId===a}))||E(!1),t instanceof Le&&e[0].involvesToken(t)||t===qe[a]&&e[0].involvesToken(Ne[a])||E(!1),void 0===n||n instanceof Le&&e[e.length-1].involvesToken(n)||n===qe[a]&&e[e.length-1].involvesToken(Ne[a])||E(!1);for(var r,i=[t instanceof Le?t:Ne[a]],o=xe(e.entries());!(r=o()).done;){var s=r.value,u=s[1],p=i[s[0]];p.equals(u.token0)||p.equals(u.token1)||E(!1);var d=p.equals(u.token0)?u.token1:u.token0;i.push(d)}this.pairs=e,this.path=i,this.midPrice=Ze.fromRoute(this),this.input=t,this.output=null!=n?n:i[i.length-1]}return de(e,[{key:"chainId",get:function(){return this.pairs[0].chainId}}]),e}();function rt(e,t,n,a){if(n>0||E(!1),e.length<=n||E(!1),0===e.length)return e.push(t),null;var r=e.length===n;if(r&&a(e[e.length-1],t)<=0)return t;for(var i=0,o=e.length;i<o;){var s=i+o>>>1;a(e[s],t)<=0?i=s+1:o=s}return e.splice(i,0,t),r?e.pop():null}var it=((et={})[exports.ChainId.MAINNET]="https://api.0x.org",et[exports.ChainId.BSC]="https://bsc.api.0x.org",et[exports.ChainId.MATIC]="https://polygon.api.0x.org",et[exports.ChainId.KOVAN]="https://kovan.api.0x.org",et[exports.ChainId.ROPSTEN]="https://ropsten.api.0x.org",et);function ot(e,t){void 0===t&&(t=!1),Q.includes(e)||E(!1);var n=it[e];try{var a,r;null!=(a=process)&&null!=(r=a.env)&&r.ZERO_EX_API_HOST&&(n=process.env.ZERO_EX_API_HOST)}catch(e){}try{var i;null!=(i=window)&&i.ZERO_EX_API_HOST&&(n=window.ZERO_EX_API_HOST)}catch(e){}return t&&(n=n.replace(/^http(s?)/,"ws$1")),n}function st(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&void 0!==e[n]&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(""+e[n]));return t.join("&")}var ut=[{type:"string",name:"name"},{type:"string",name:"version"},{type:"uint256",name:"chainId"},{type:"address",name:"verifyingContract"}],pt=L.keccak256(Buffer.from(["EIP712Domain(",ut.map((function(e){return e.type+" "+e.name})).join(","),")"].join(""),"utf8")),dt=[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}],yt=[{type:"address",name:"makerToken"},{type:"address",name:"takerToken"},{type:"uint128",name:"makerAmount"},{type:"uint128",name:"takerAmount"},{type:"uint128",name:"takerTokenFeeAmount"},{type:"address",name:"maker"},{type:"address",name:"taker"},{type:"address",name:"sender"},{type:"address",name:"feeRecipient"},{type:"bytes32",name:"pool"},{type:"uint64",name:"expiry"},{type:"uint256",name:"salt"}],mt=L.keccak256(Buffer.from(["LimitOrder(",yt.map((function(e){return e.type+" "+e.name})).join(","),")"].join(""),"utf8"));function lt(e,t){return{types:{EIP712Domain:ut,LimitOrder:yt},domain:e,primaryType:"LimitOrder",message:t}}function ct(e,t){if(void 0===t&&(t=32),/^\d+$/.test(e)&&(e=q.hexValue(BigInt(e))),!q.isHexString(e))throw new Error("Invalid value format");return q.hexDataLength(e)<t?q.hexZeroPad(e,t):q.hexDataSlice(e,0,t)}function ft(e){return"0x"+e.raw.toString(16)}var Tt=function(){function e(){}return e.swapCallParameters=function(e,t){var n=e.inputAmount.currency.isNative,a=e.outputAmount.currency.isNative;n&&a&&E(!1),!("ttl"in t)||t.ttl>0||E(!1);var r,i,o,s=Ee(t.recipient),u=ft(e.maximumAmountIn(t.allowedSlippage)),p=ft(e.minimumAmountOut(t.allowedSlippage)),d=e.route.path.map((function(e){return e.address})),y="ttl"in t?"0x"+(Math.floor((new Date).getTime()/1e3)+t.ttl).toString(16):"0x"+t.deadline.toString(16),m=Boolean(t.feeOnTransfer);switch(e.tradeType){case exports.TradeType.EXACT_INPUT:n?(r=m?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[p,d,s,y],o=u):a?(r=m?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[u,p,d,s,y],o="0x0"):(r=m?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[u,p,d,s,y],o="0x0");break;case exports.TradeType.EXACT_OUTPUT:m&&E(!1),n?(r="swapETHForExactTokens",i=[p,d,s,y],o=u):a?(r="swapTokensForExactETH",i=[p,u,d,s,y],o="0x0"):(r="swapTokensForExactTokens",i=[p,u,d,s,y],o="0x0");break;case exports.TradeType.LIMIT:throw new Error("Unsupported call for limit trade")}return{methodName:r,args:i,value:o}},e}();function ht(e,t){for(var n=0;n<10;n++){var a=0===n?0:Math.ceil(n/2)*(n%2==1?1:-1),r=N.BigNumber.from(e).add(""+a),i=r.toHexString().substr(2);if(t.includes(i))return r.toString()}return I(e).times("1.0001").toFixed(0)}var bt,kt=function(){function e(e,t,n){this.tradeType=e,this.inputAmount=t,this.outputAmount=n,this.executionPrice=new Ze(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw)}var t=e.prototype;return t.minimumAmountOut=function(e){if(e.lessThan(Z)&&E(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT||this.tradeType===exports.TradeType.LIMIT)return this.outputAmount;var t=new We(z).add(e).invert().multiply(this.outputAmount.raw).quotient;return Je(this.outputAmount.currency,t)},t.maximumAmountIn=function(e){if(e.lessThan(Z)&&E(!1),this.tradeType===exports.TradeType.EXACT_INPUT||this.tradeType===exports.TradeType.LIMIT)return this.inputAmount;var t=new We(z).add(e).multiply(this.inputAmount.raw).quotient;return Je(this.inputAmount.currency,t)},e}();function xt(e,t){return e.inputAmount.currency.equals(t.inputAmount.currency)||E(!1),e.outputAmount.currency.equals(t.outputAmount.currency)||E(!1),e.outputAmount.equalTo(t.outputAmount)?e.inputAmount.equalTo(t.inputAmount)?0:e.inputAmount.lessThan(t.inputAmount)?-1:1:e.outputAmount.lessThan(t.outputAmount)?1:-1}function vt(e,t){var n=xt(e,t);return 0!==n?n:e.priceImpact.lessThan(t.priceImpact)?-1:e.priceImpact.greaterThan(t.priceImpact)?1:e.route.path.length-t.route.path.length}(bt=exports.Signed0xOrderStatus||(exports.Signed0xOrderStatus={}))[bt.INVALID=0]="INVALID",bt[bt.FILLABLE=1]="FILLABLE",bt[bt.FILLED=2]="FILLED",bt[bt.CANCELLED=3]="CANCELLED",bt[bt.EXPIRED=4]="EXPIRED";var wt,At=function(e){function t(t,n,a){var r;a!==exports.TradeType.EXACT_INPUT&&a!==exports.TradeType.EXACT_OUTPUT&&E(!1);var i=new Array(t.path.length),o=new Array(t.pairs.length);if(a===exports.TradeType.EXACT_INPUT){n.currency.equals(t.input)||E(!1),i[0]=n.wrapped();for(var s=0;s<t.path.length-1;s++){var u=t.pairs[s].getOutputAmount(i[s]),p=u[1];i[s+1]=u[0],o[s]=p}}else{n.currency.equals(t.output)||E(!1),i[i.length-1]=n.wrapped();for(var d=t.path.length-1;d>0;d--){var y=t.pairs[d-1].getInputAmount(i[d]),m=y[1];i[d-1]=y[0],o[d-1]=m}}var l=a===exports.TradeType.EXACT_INPUT?n:t.input.isNative?Ke.native(t.chainId,i[0].raw):i[0],c=a===exports.TradeType.EXACT_OUTPUT?n:t.output.isNative?Ke.native(t.chainId,i[i.length-1].raw):i[i.length-1];return(r=e.call(this,a,l,c)||this).route=t,r.nextMidPrice=Ze.fromRoute(new at(o,t.input)),r.priceImpact=function(e,t,n){var a=e.raw.multiply(t.raw),r=a.subtract(n.raw).divide(a);return new Qe(r.numerator,r.denominator)}(t.midPrice,r.inputAmount,r.outputAmount),r}return me(t,e),t.exactIn=function(e,n){return new t(e,n,exports.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,exports.TradeType.EXACT_OUTPUT)},t.bestTradeExactIn=function(e,n,a,r,i,o,s){var u=void 0===r?{}:r,p=u.maxNumResults,d=void 0===p?3:p,y=u.maxHops,m=void 0===y?3:y;void 0===i&&(i=[]),void 0===o&&(o=n),void 0===s&&(s=[]),e.length>0||E(!1),m>0||E(!1),o===n||i.length>0||E(!1);for(var l=n.wrapped(),c=a.wrapped(),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(l.token)||T.token1.equals(l.token))&&!T.reserve0.equalTo(Z)&&!T.reserve1.equalTo(Z)){var h=void 0;try{h=T.getOutputAmount(l)[0]}catch(e){if(e.isInsufficientInputAmountError)continue;throw e}if(h.token.equals(c))rt(s,new t(new at([].concat(i,[T]),o.currency,a),o,exports.TradeType.EXACT_INPUT),d,vt);else if(m>1&&e.length>1){var b=e.slice(0,f).concat(e.slice(f+1,e.length));t.bestTradeExactIn(b,h,a,{maxNumResults:d,maxHops:m-1},[].concat(i,[T]),o,s)}}}return s},t.bestTradeExactOut=function(e,n,a,r,i,o,s){var u=void 0===r?{}:r,p=u.maxNumResults,d=void 0===p?3:p,y=u.maxHops,m=void 0===y?3:y;void 0===i&&(i=[]),void 0===o&&(o=a),void 0===s&&(s=[]),e.length>0||E(!1),m>0||E(!1),o===a||i.length>0||E(!1);for(var l=a.wrapped(),c=n.wrapped(),f=0;f<e.length;f++){var T=e[f];if((T.token0.equals(l.token)||T.token1.equals(l.token))&&!T.reserve0.equalTo(Z)&&!T.reserve1.equalTo(Z)){var h=void 0;try{h=T.getInputAmount(l)[0]}catch(e){if(e.isInsufficientReservesError)continue;throw e}if(h.token.equals(c))rt(s,new t(new at([T].concat(i),n,o.currency),o,exports.TradeType.EXACT_OUTPUT),d,vt);else if(m>1&&e.length>1){var b=e.slice(0,f).concat(e.slice(f+1,e.length));t.bestTradeExactOut(b,n,h,{maxNumResults:d,maxHops:m-1},[T].concat(i),o,s)}}}return s},t}(kt),gt=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},r=a.iterator||"@@iterator",i=a.asyncIterator||"@@asyncIterator",o=a.toStringTag||"@@toStringTag";function s(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,n){return e[t]=n}}function u(e,t,n,a){var r=Object.create((t&&t.prototype instanceof y?t:y).prototype),i=new A(a||[]);return r._invoke=function(e,t,n){var a="suspendedStart";return function(r,i){if("executing"===a)throw new Error("Generator is already running");if("completed"===a){if("throw"===r)throw i;return{value:void 0,done:!0}}for(n.method=r,n.arg=i;;){var o=n.delegate;if(o){var s=x(o,n);if(s){if(s===d)continue;return s}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===a)throw a="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);a="executing";var u=p(e,t,n);if("normal"===u.type){if(a=n.done?"completed":"suspendedYield",u.arg===d)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(a="completed",n.method="throw",n.arg=u.arg)}}}(e,n,i),r}function p(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var d={};function y(){}function m(){}function l(){}var c={};c[r]=function(){return this};var f=Object.getPrototypeOf,T=f&&f(f(g([])));T&&T!==t&&n.call(T,r)&&(c=T);var h=l.prototype=y.prototype=Object.create(c);function b(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,t){var a;this._invoke=function(r,i){function o(){return new t((function(a,o){!function a(r,i,o,s){var u=p(e[r],e,i);if("throw"!==u.type){var d=u.arg,y=d.value;return y&&"object"==typeof y&&n.call(y,"__await")?t.resolve(y.__await).then((function(e){a("next",e,o,s)}),(function(e){a("throw",e,o,s)})):t.resolve(y).then((function(e){d.value=e,o(d)}),(function(e){return a("throw",e,o,s)}))}s(u.arg)}(r,i,a,o)}))}return a=a?a.then(o,o):o()}}function x(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,x(e,t),"throw"===t.method))return d;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var a=p(n,e.iterator,t.arg);if("throw"===a.type)return t.method="throw",t.arg=a.arg,t.delegate=null,d;var r=a.arg;return r?r.done?(t[e.resultName]=r.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,d):r:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,d)}function v(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function w(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function A(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(v,this),this.reset(!0)}function g(e){if(e){var t=e[r];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var a=-1,i=function t(){for(;++a<e.length;)if(n.call(e,a))return t.value=e[a],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:S}}function S(){return{value:void 0,done:!0}}return m.prototype=h.constructor=l,l.constructor=m,m.displayName=s(l,o,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,s(e,o,"GeneratorFunction")),e.prototype=Object.create(h),e},e.awrap=function(e){return{__await:e}},b(k.prototype),k.prototype[i]=function(){return this},e.AsyncIterator=k,e.async=function(t,n,a,r,i){void 0===i&&(i=Promise);var o=new k(u(t,n,a,r),i);return e.isGeneratorFunction(n)?o:o.next().then((function(e){return e.done?e.value:o.next()}))},b(h),s(h,o,"Generator"),h[r]=function(){return this},h.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var a=t.pop();if(a in e)return n.value=a,n.done=!1,n}return n.done=!0,n}},e.values=g,A.prototype={constructor:A,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function a(n,a){return o.type="throw",o.arg=e,t.next=n,a&&(t.method="next",t.arg=void 0),!!a}for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r],o=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return a(i.finallyLoc)}}}},abrupt:function(e,t){for(var a=this.tryEntries.length-1;a>=0;--a){var r=this.tryEntries[a];if(r.tryLoc<=this.prev&&n.call(r,"finallyLoc")&&this.prev<r.finallyLoc){var i=r;break}}i&&("break"===e||"continue"===e)&&i.tryLoc<=t&&t<=i.finallyLoc&&(i=null);var o=i?i.completion:{};return o.type=e,o.arg=t,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),d},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),w(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var a=n.completion;if("throw"===a.type){var r=a.arg;w(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:g(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(wt={exports:{}}),wt.exports);function St(e,t,n,a){return It.apply(this,arguments)}function It(){return(It=ue(gt.mark((function e(t,n,a,r){var i,o,s,u,p,d,y;return gt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=ot(t),o=st(a),s=i+"/swap/v1/"+(n?"price":"quote")+"?"+o,e.next=5,fetch(s,{method:"GET",mode:"cors",signal:r,headers:{"Content-Type":"application/json"}});case 5:if((u=e.sent).ok){e.next=17;break}if(400!==u.status){e.next=16;break}return e.next=10,u.json();case 10:if(null==(p=(d=e.sent).validationErrors)||!p.some((function(e){return"INSUFFICIENT_ASSET_LIQUIDITY"===e.reason}))){e.next=15;break}throw new ge;case 15:throw new Ie(d.reason,null==(y=d.validationErrors)?void 0:y.map((function(e){return{name:e.field,message:e.reason,code:e.code}})));case 16:throw new Error("Fetch quote error, try again later.");case 17:return e.next=19,u.json();case 19:return e.abrupt("return",e.sent);case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Et(e,t){return Ct.apply(this,arguments)}function Ct(){return(Ct=ue(gt.mark((function e(t,n){var a,r,i,o,s;return gt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ot(t.chainId),e.next=3,fetch(a+"/sra/v4/order",{method:"POST",mode:"cors",body:JSON.stringify(t),signal:n,headers:{"Content-Type":"application/json"}});case 3:if((r=e.sent).ok){e.next=11;break}if(400!==r.status){e.next=10;break}return e.next=8,r.json();case 8:throw s=e.sent,new Error((null==(i=s.validationErrors)||null==(o=i[0])?void 0:o.reason)||s.reason||"Unknown validation error");case 10:throw new Error("Send signed order error");case 11:return e.next=13,r.text();case 13:return e.abrupt("return",e.sent);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pt(){return(Pt=ue(gt.mark((function e(t,n,a){var r,i,o,s;return gt.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=ot(t),i=st(n),o=r+"/sra/v4/orders?"+i,e.next=5,fetch(o,{method:"GET",mode:"cors",signal:a,headers:{"Content-Type":"application/json"}});case 5:if((s=e.sent).ok){e.next=8;break}throw new Error("Fetch orders list error, try again later.");case 8:return e.next=10,s.json();case 10:return e.abrupt("return",e.sent);case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ot