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

@rainbow-me/swaps

Package Overview
Dependencies
Maintainers
10
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rainbow-me/swaps - npm Package Compare versions

Comparing version 0.1.14 to 0.1.15

28

dist/quotes.d.ts
import { StaticJsonRpcProvider } from '@ethersproject/providers';
import { Transaction } from '@ethersproject/transactions';
import { Wallet } from '@ethersproject/wallet';
import { ChainId, Quote, QuoteError, QuoteExecutionDetails, QuoteParams, TransactionOptions } from './types';
import { ChainId, CrosschainQuote, CrosschainQuoteExecutionDetails, Quote, QuoteError, QuoteExecutionDetails, QuoteParams, TransactionOptions } from './types';
/**

@@ -17,2 +17,3 @@ * Function to get a quote from rainbow's swap aggregator backend

* @param {number} params.slippage
* @param {number} params.feePercentageBasisPoints
* @returns {Promise<Quote | null>}

@@ -22,2 +23,17 @@ */

/**
* Function to get a crosschain swap quote from rainbow's swap aggregator backend
*
* @param {QuoteParams} params
* @param {ChainId} params.chainId
* @param {ChainId} params.toChainId
* @param {EthereumAddress} params.fromAddress
* @param {EthereumAddress} params.sellTokenAddress
* @param {EthereumAddress} params.buyTokenAddress
* @param {BigNumberish} params.sellAmount
* @param {number} params.slippage
* @param {boolean} params.refuel
* @returns {Promise<CrosschainQuote | null>}
*/
export declare const getCrosschainQuote: (params: QuoteParams) => Promise<CrosschainQuote | QuoteError | null>;
/**
* Function that fills a quote onchain via rainbow's swap aggregator smart contract

@@ -33,2 +49,12 @@ *

export declare const fillQuote: (quote: Quote, transactionOptions: TransactionOptions, wallet: Wallet, permit: boolean, chainId: ChainId) => Promise<Transaction>;
/**
* Function that fills a crosschain swap quote onchain via rainbow's swap aggregator smart contract
*
* @param {CrosschainQuote} quote
* @param {TransactionOptions} transactionOptions
* @param {Wallet} wallet
* @returns {Promise<Transaction>}
*/
export declare const fillCrosschainQuote: (quote: CrosschainQuote, transactionOptions: TransactionOptions, wallet: Wallet) => Promise<Transaction>;
export declare const getQuoteExecutionDetails: (quote: Quote, transactionOptions: TransactionOptions, provider: StaticJsonRpcProvider) => QuoteExecutionDetails;
export declare const getCrosschainQuoteExecutionDetails: (quote: CrosschainQuote, transactionOptions: TransactionOptions, provider: StaticJsonRpcProvider) => CrosschainQuoteExecutionDetails;

2

dist/swaps.cjs.production.min.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ethersproject/contracts"),t=require("@ethersproject/bignumber"),n=require("@ethersproject/bytes"),a=require("@metamask/eth-sig-util"),r=require("ethereumjs-util");function i(e,t,n,a,r,i,s){try{var o=e[i](s),p=o.value}catch(e){return void n(e)}o.done?t(p):Promise.resolve(p).then(a,r)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var s=e.apply(t,n);function o(e){i(s,a,r,o,p,"next",e)}function p(e){i(s,a,r,o,p,"throw",e)}o(void 0)}))}}function o(){return(o=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)}var p,u,y,d,l,c=(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",s=a.toStringTag||"@@toStringTag";function o(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{o({},"")}catch(e){o=function(e,t,n){return e[t]=n}}function p(e,t,n,a){var r=Object.create((t&&t.prototype instanceof d?t:d).prototype),i=new E(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 s=n.delegate;if(s){var o=w(s,n);if(o){if(o===y)continue;return o}}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 p=u(e,t,n);if("normal"===p.type){if(a=n.done?"completed":"suspendedYield",p.arg===y)continue;return{value:p.arg,done:n.done}}"throw"===p.type&&(a="completed",n.method="throw",n.arg=p.arg)}}}(e,n,i),r}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=p;var y={};function d(){}function l(){}function c(){}var m={};o(m,r,(function(){return this}));var f=Object.getPrototypeOf,b=f&&f(f(g([])));b&&b!==t&&n.call(b,r)&&(m=b);var T=c.prototype=d.prototype=Object.create(m);function h(e){["next","throw","return"].forEach((function(t){o(e,t,(function(e){return this._invoke(t,e)}))}))}function v(e,t){var a;this._invoke=function(r,i){function s(){return new t((function(a,s){!function a(r,i,s,o){var p=u(e[r],e,i);if("throw"!==p.type){var y=p.arg,d=y.value;return d&&"object"==typeof d&&n.call(d,"__await")?t.resolve(d.__await).then((function(e){a("next",e,s,o)}),(function(e){a("throw",e,s,o)})):t.resolve(d).then((function(e){y.value=e,s(y)}),(function(e){return a("throw",e,s,o)}))}o(p.arg)}(r,i,a,s)}))}return a=a?a.then(s,s):s()}}function w(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,w(e,t),"throw"===t.method))return y;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var a=u(n,e.iterator,t.arg);if("throw"===a.type)return t.method="throw",t.arg=a.arg,t.delegate=null,y;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,y):r:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,y)}function S(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,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:A}}function A(){return{value:void 0,done:!0}}return l.prototype=c,o(T,"constructor",c),o(c,"constructor",l),l.displayName=o(c,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,o(e,s,"GeneratorFunction")),e.prototype=Object.create(T),e},e.awrap=function(e){return{__await:e}},h(v.prototype),o(v.prototype,i,(function(){return this})),e.AsyncIterator=v,e.async=function(t,n,a,r,i){void 0===i&&(i=Promise);var s=new v(p(t,n,a,r),i);return e.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},h(T),o(T,s,"Generator"),o(T,r,(function(){return this})),o(T,"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,E.prototype={constructor:E,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(x),!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 s.type="throw",s.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],s=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var o=n.call(i,"catchLoc"),p=n.call(i,"finallyLoc");if(o&&p){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(o){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!p)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 s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(s)},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),y},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),x(n),y}},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;x(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),y}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(l={exports:{}}),l.exports),m=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"deposit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];(p=exports.ChainId||(exports.ChainId={}))[p.mainnet=1]="mainnet",p[p.ropsten=3]="ropsten",p[p.kovan=42]="kovan",p[p.goerli=5]="goerli",p[p.rinkeby=4]="rinkeby",p[p.optimism=10]="optimism",p[p.polygon=137]="polygon",p[p.arbitrum=42161]="arbitrum",(u=exports.Source||(exports.Source={})).Aggregator0x="0x",u.Aggregotor1inch="1inch";var f="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",b=((y={})[""+exports.ChainId.arbitrum]="0x82af49447d8a07e3bd95bd0d56f35241523fbab1",y[""+exports.ChainId.mainnet]="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",y[""+exports.ChainId.optimism]="0x4200000000000000000000000000000000000006",y[""+exports.ChainId.polygon]="0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",y),T=((d={})[""+exports.ChainId.mainnet]="0x6b175474e89094c44da98b954eedeac495271d0f",d),h="0x77777feddddffc19ff86db637967013e6c6a116c",v="0x0d438f3b5175bebc262bf23753c1e53d03432bde",w="0x1b40183efb4dd766f11bda7a7c3ad8982e998421",S=t.BigNumber.from("2").pow("256").sub("1").toString(),x=function(){var t=s(c.mark((function t(n,a,r,i){var s;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=exports.ChainId.mainnet),void 0===i&&(i={}),s=new e.Contract(b[r],JSON.stringify(m),a),t.abrupt("return",s.deposit(o({},i,{value:n})));case 4:case"end":return t.stop()}}),t)})));return function(e,n,a,r){return t.apply(this,arguments)}}(),E=function(){var t=s(c.mark((function t(n,a,r,i){var s;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=exports.ChainId.mainnet),void 0===i&&(i={}),s=new e.Contract(b[r],JSON.stringify(m),a),t.abrupt("return",s.withdraw(n,i));case 4:case"end":return t.stop()}}),t)})));return function(e,n,a,r){return t.apply(this,arguments)}}(),g=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"EthWithdrawn",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newOwner",type:"address"},{indexed:!0,internalType:"address",name:"oldOwner",type:"address"}],name:"OwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"}],name:"SwapTargetAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"}],name:"SwapTargetRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"token",type:"address"},{indexed:!0,internalType:"address",name:"target",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"TokenWithdrawn",type:"event"},{inputs:[{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"feeAmount",type:"uint256"}],name:"fillQuoteEthToToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feePercentageBasisPoints",type:"uint256"}],name:"fillQuoteTokenToEth",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feePercentageBasisPoints",type:"uint256"},{components:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"isDaiStylePermit",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],internalType:"struct PermitHelper.Permit",name:"permitData",type:"tuple"}],name:"fillQuoteTokenToEthWithPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feeAmount",type:"uint256"}],name:"fillQuoteTokenToToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feeAmount",type:"uint256"},{components:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"isDaiStylePermit",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],internalType:"struct PermitHelper.Permit",name:"permitData",type:"tuple"}],name:"fillQuoteTokenToTokenWithPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"swapTargets",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"add",type:"bool"}],name:"updateSwapTargets",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdrawEth",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdrawToken",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],A=function(){var e=s(c.mark((function e(t){var n,a,r,i,s,o,p,u,y,d,l,m,T,h,v,w,S,x,E;return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=t.source,i=void 0===(r=t.chainId)?exports.ChainId.mainnet:r,s=t.fromAddress,p=t.buyTokenAddress,u=t.sellAmount,y=t.buyAmount,d=t.slippage,l=(o=t.sellTokenAddress).toLowerCase(),m=p.toLowerCase(),T=f.toLowerCase(),h=null==(n=b[i])?void 0:n.toLowerCase(),w=l===h&&m===T,!(v=l===T&&m===h)&&!w){e.next=9;break}return e.abrupt("return",{buyAmount:u||y,buyTokenAddress:p,defaultGasLimit:v?"30000":"40000",fee:0,feePercentageBasisPoints:0,from:s,inputTokenDecimals:18,outputTokenDecimals:18,sellAmount:u||y,sellAmountMinusFees:u||y,sellTokenAddress:o});case 9:if(S="https://swap.p.rainbow.me/quote?chainId="+i+"&fromAddress="+s+"&buyToken="+p+"&sellToken="+o+"&slippage="+d,a&&(S+="&source="+a),u?S+="&sellAmount="+u:y&&(S+="&buyAmount="+y),!isNaN(Number(u))||!isNaN(Number(y))){e.next=14;break}return e.abrupt("return",null);case 14:return p===f&&(S+="&destReceiver=0x00000000009726632680fb29d3f7a9734e3010e2"),void 0!==t.feePercentageBasisPoints&&(S+="&feePercentageBasisPoints="+t.feePercentageBasisPoints),e.next=18,fetch(S);case 18:return x=e.sent,e.next=21,x.json();case 21:if(!(E=e.sent).error){e.next=24;break}return e.abrupt("return",E);case 24:return e.abrupt("return",E);case 25:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),_=function(){var e=s(c.mark((function e(t){return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.provider.getBlock("latest");case 2:return e.abrupt("return",e.sent.timestamp+3600);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),M=function(){var t=s(c.mark((function t(n,a,r,i,s){var p,u,y,d,l,m,b,T,h,v,w,x,E,A,M;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p=new e.Contract("0x00000000009726632680fb29d3f7a9734e3010e2",g,r),y=n.sellTokenAddress,d=n.buyTokenAddress,l=n.to,m=n.data,b=n.fee,T=n.value,h=n.sellAmount,v=n.feePercentageBasisPoints,w=f.toLowerCase(),(null==y?void 0:y.toLowerCase())!==w){t.next=9;break}return t.next=6,p.fillQuoteEthToToken(d,l,m,b,o({},a,{value:T}));case 6:u=t.sent,t.next=42;break;case 9:if((null==d?void 0:d.toLowerCase())!==w){t.next=27;break}if(!i){t.next=22;break}return t.next=13,_(r);case 13:return x=t.sent,t.next=16,V(r,y,n.from,p.address,S,x,s);case 16:return E=t.sent,t.next=19,p.fillQuoteTokenToEthWithPermit(y,l,m,h,v,E,o({},a,{value:T}));case 19:u=t.sent,t.next=25;break;case 22:return t.next=24,p.fillQuoteTokenToEth(y,l,m,h,v,o({},a,{value:T}));case 24:u=t.sent;case 25:t.next=42;break;case 27:if(!i){t.next=39;break}return t.next=30,_(r);case 30:return A=t.sent,t.next=33,V(r,y,n.from,p.address,S,A,s);case 33:return M=t.sent,t.next=36,p.fillQuoteTokenToTokenWithPermit(y,d,l,m,h,b,M,o({},a,{value:T}));case 36:u=t.sent,t.next=42;break;case 39:return t.next=41,p.fillQuoteTokenToToken(y,d,l,m,h,b,o({},a,{value:T}));case 41:u=t.sent;case 42:return t.abrupt("return",u);case 43:case"end":return t.stop()}}),t)})));return function(e,n,a,r,i){return t.apply(this,arguments)}}(),C=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"holder",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],P=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"_nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],k=[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],I=function(){var e=s(c.mark((function e(t,n,r,i){return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return","0x"+a.TypedDataUtils.hashStruct("EIP712Domain",{chainId:r,name:t,verifyingContract:i,version:n},{EIP712Domain:k},a.SignTypedDataVersion.V4).toString("hex"));case 1:case"end":return e.stop()}}),e)})));return function(t,n,a,r){return e.apply(this,arguments)}}(),L=function(){var e=s(c.mark((function e(t,n,a,r){var i,s;return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.version();case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),i="1",e.prev=10,e.next=13,t.DOMAIN_SEPARATOR();case 13:return s=e.sent,e.next=16,I(n,i,a,r);case 16:if(s!==e.sent){e.next=19;break}return e.abrupt("return",i);case 19:e.next=26;break;case 21:if(e.prev=21,e.t1=e.catch(10),1!==a||-1===[h,v,w].map((function(e){return e.toLowerCase()})).indexOf(t.address.toLowerCase())){e.next=25;break}return e.abrupt("return","1");case 25:case 26:return e.abrupt("return",null);case 27:case"end":return e.stop()}}),e,null,[[0,7],[10,21]])})));return function(t,n,a,r){return e.apply(this,arguments)}}(),N=function(){var e=s(c.mark((function e(t,n){return c.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.nonces(n);case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),e.prev=9,e.next=12,t._nonces(n);case 12:return e.abrupt("return",e.sent);case 16:return e.prev=16,e.t1=e.catch(9),e.abrupt("return",0);case 19:case"end":return e.stop()}}),e,null,[[0,7],[9,16]])})));return function(t,n){return e.apply(this,arguments)}}(),O=[{name:"name",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],R=[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}],D=[{name:"holder",type:"address"},{name:"spender",type:"address"},{name:"nonce",type:"uint256"},{name:"expiry",type:"uint256"},{name:"allowed",type:"bool"}];function V(e,t,n,a,r,i,s){return U.apply(this,arguments)}function U(){return(U=s(c.mark((function i(s,o,p,u,y,d,l){var m,f,b,h,v,w,S,x,E,g,A,_,M;return c.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return f=o.toLowerCase()===(null==(m=T[l])?void 0:m.toLowerCase()),b=new e.Contract(o,f?C:P,s),i.next=4,b.name();case 4:return h=i.sent,i.next=7,Promise.all([N(b,p),L(b,h,l,b.address)]);case 7:return w=(v=i.sent)[0],S=v[1],x={nonce:Number(w.toString()),spender:u},f?(x.holder=p,x.allowed=!0,x.expiry=Number(d.toString())):(x.value=t.BigNumber.from(y).toHexString(),x.deadline=Number(d.toString()),x.owner=p),E={chainId:l,name:h,verifyingContract:b.address},null!==S&&(E.version=S),g={domain:E,message:x,primaryType:"Permit",types:{EIP712Domain:null!==S?k:O,Permit:f?D:R}},A=r.toBuffer(r.addHexPrefix(s.privateKey)),_=a.signTypedData({data:g,privateKey:A,version:a.SignTypedDataVersion.V4}),M=n.splitSignature(_),i.abrupt("return",{deadline:d,isDaiStylePermit:f,nonce:w,r:M.r,s:M.s,v:M.v,value:x.value||t.BigNumber.from("0").toHexString()});case 20:case"end":return i.stop()}}),i)})))).apply(this,arguments)}exports.ALLOWS_PERMIT={"0x0d438f3b5175bebc262bf23753c1e53d03432bde":!0,"0x111111111117dc0aa78b770fa6a738034120c302":!0,"0x1b40183efb4dd766f11bda7a7c3ad8982e998421":!0,"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984":!0,"0x31c8eacbffdd875c74b94b077895bd78cf1e64a3":!0,"0x6b175474e89094c44da98b954eedeac495271d0f":!0,"0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d":!0,"0x77777feddddffc19ff86db637967013e6c6a116c":!0,"0x888888435fde8e7d4c54cab67f206e4199454c60":!0,"0x888888888889c00c67689029d7856aac1065ec11":!0,"0x88acdd2a6425c3faae4bc9650fd7e27e0bebb7ab":!0,"0x956f47f50a910163d8bf957cf5846d573e7f87ca":!0,"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48":!0,"0xba100000625a3754423978a60c9317c58a424e3d":!0,"0xc7283b66eb1eb5fb86327f08e1b5816b0720212b":!0},exports.API_BASE_URL="https://swap.p.rainbow.me",exports.DAI=T,exports.ETH_ADDRESS=f,exports.MAX_INT=S,exports.PERMIT_EXPIRATION_TS=3600,exports.RAINBOW_ROUTER_CONTRACT_ADDRESS="0x00000000009726632680fb29d3f7a9734e3010e2",exports.TORN_ADDRESS=h,exports.USDC_ADDRESS="0x111111111117dc0aa78b770fa6a738034120c302",exports.VSP_ADDRESS=w,exports.WNXM_ADDRESS=v,exports.WRAPPED_ASSET=b,exports.fillQuote=M,exports.getQuote=A,exports.getQuoteExecutionDetails=function(t,n,a){var r=new e.Contract("0x00000000009726632680fb29d3f7a9734e3010e2",g,a),i=t.sellTokenAddress,s=t.buyTokenAddress,p=t.to,u=t.data,y=t.fee,d=t.value,l=t.sellAmount,c=t.feePercentageBasisPoints,m=f.toLowerCase();return(null==i?void 0:i.toLowerCase())===m?{method:r.estimateGas.fillQuoteEthToToken,methodArgs:[s,p,u,y],methodName:"fillQuoteEthToToken",params:o({},n,{value:d}),router:r}:(null==s?void 0:s.toLowerCase())===m?{method:r.estimateGas.fillQuoteTokenToEth,methodArgs:[i,p,u,l,c],methodName:"fillQuoteTokenToEth",params:o({},n,{value:d}),router:r}:{method:r.estimateGas.fillQuoteTokenToToken,methodArgs:[i,s,p,u,l,y],methodName:"fillQuoteTokenToToken",params:o({},n,{value:d}),router:r}},exports.getWrappedAssetMethod=function(t,n,a){return void 0===a&&(a=exports.ChainId.mainnet),new e.Contract(b[a],JSON.stringify(m),n).estimateGas[t]},exports.signPermit=V,exports.sources={AAVE:"Aave",AAVE_LIQUIDATOR:"Aave Liquidator",AAVE_V2:"Aave V2",BALANCER:"Balancer",BALANCER_V2:"Balancer V2",BANCOR:"Bancor",BLACKHOLESWAP:"Blackholeswap",CHAI:"Chai",CLIPPER:"Clipper",COFIX:"CoFix",COMPOUND:"Compound",CONVERGENCE_X:"Convergence X",CREAM_LENDING:"Creamswap Lending",CREAMSWAP:"Creamswap",CURVE:"Curve",CURVE_V2:"Curve V2",CURVE_V2_ETH_CRV:"CURVE V2 ETH CRV",CURVE_V2_ETH_CVX:"CURVE V2 ETH CVX",CURVE_V2_EURS_2_ASSET:"Curve V2 EURS",CURVE_V2_EURT_2_ASSET:"CURVE V2 EURT",CURVE_V2_SPELL_2_ASSET:"Curve Spell",CURVE_V2_THRESHOLDNETWORK_2_ASSET:"Curve Threshold",CURVE_V2_XAUT_2_ASSET:"CURVE V2 XAUt",CURVE_V2_YFI_2_ASSET:"Curve Yfi",DEFI_PLAZA:"DeFi Plaza",DEFISWAP:"DeFi Swap",DFX_FINANCE:"Dfx Finance",DODO:"DODO",DODO_V2:"DODO v2",DXSWAP:"Swapr",FIXED_FEE_SWAP:"Fixed Fee Swap",FIXED_FEE_SWAP_V3:"Fixed Rate Swap",IEARN:"yEarn",INDEXED_FINANCE:"Indexed Finance",KYBER:"Kyber",KYBER_DMM:"Kyber DMM",LINKSWAP:"Link Swap",LUASWAP:"Lua Swap",MINISWAP:"Mini Swap",MOONISWAP:"Mooniswap",MSTABLE:"mStable",OASIS:"Oasis",ONE_INCH_LIMIT_ORDER:"1inch Limit Order Protocol",ONE_INCH_LIMIT_ORDER_V2:"1inch Limit Order Protocol V2",ONE_INCH_LP:"1inch LP v1.0",ONE_INCH_LP_1_1:"1inch LP v1.1",ONE_INCH_LP_MIGRATOR:"Mooniswap Migrator",ONE_INCH_LP_MIGRATOR_V1_1:"1inch LP v1.0 Migrator",PMM1:"PMM1",PMM2:"PMM2",PMM3:"PMM3",PMM4:"PMM4",PMMX:"LiqPool X",POWERINDEX:"POWERINDEX",PSM:"PSM",S_FINANCE:"sFinance",SADDLE:"Saddle Finance",SAKESWAP:"Sake Swap",SETH_WRAPPER:"sETH Wrapper",SHELL:"Shell",SHIBASWAP:"Shiba Swap",SMOOTHY_FINANCE:"Smoothy Finance",ST_ETH:"stETH",SUSHI:"Sushiswap",SUSHISWAP_MIGRATOR:"SushiSwap Migrator",SWERVE:"Swerve",SYNAPSE:"Synapse",SYNTHETIX:"Synthetix",SYNTHETIX_WRAPPER:"Synthetix Wrapper",UNIFI:"Unifi",UNISWAP_V1:"Uniswap V1",UNISWAP_V2:"Uniswap V2",UNISWAP_V2_MIGRATOR:"Uniswap Migrator",UNISWAP_V3:"UNISWAP V3",VALUELIQUID:"Value Liquid",WETH:"WETH",WSTETH:"wstETH",XSIGMA:"xSigma",ZRX:"0x",Native:"Native",Uniswap:"Uniswap",UniswapV2:"Uniswap_V2",Eth2Dai:"Eth2Dai",Kyber:"Kyber",Curve:"Curve",LiquidityProvider:"LiquidityProvider",MultiBridge:"MultiBridge",Balancer:"Balancer",BalancerV2:"Balancer_V2",Cream:"CREAM",Bancor:"Bancor",MakerPsm:"MakerPsm",MStable:"mStable",Mooniswap:"Mooniswap",MultiHop:"MultiHop",Shell:"Shell",Swerve:"Swerve",SnowSwap:"SnowSwap",SushiSwap:"SushiSwap",Dodo:"DODO",DodoV2:"DODO_V2",CryptoCom:"CryptoCom",Linkswap:"Linkswap",KyberDmm:"KyberDMM",Smoothy:"Smoothy",Component:"Component",Saddle:"Saddle",XSigma:"xSigma",UniswapV3:"Uniswap_V3",CurveV2:"Curve_V2",Lido:"Lido",ShibaSwap:"ShibaSwap",Clipper:"Clipper",PancakeSwap:"PancakeSwap",PancakeSwapV2:"PancakeSwap_V2",BakerySwap:"BakerySwap",Nerve:"Nerve",Belt:"Belt",Ellipsis:"Ellipsis",ApeSwap:"ApeSwap",CafeSwap:"CafeSwap",CheeseSwap:"CheeseSwap",JulSwap:"JulSwap",ACryptos:"ACryptoS",QuickSwap:"QuickSwap",ComethSwap:"ComethSwap",Dfyn:"Dfyn",WaultSwap:"WaultSwap",Polydex:"Polydex",FirebirdOneSwap:"FirebirdOneSwap",JetSwap:"JetSwap",IronSwap:"IronSwap"},exports.unwrapNativeAsset=E,exports.wrapNativeAsset=x;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@ethersproject/contracts"),t=require("@ethersproject/bignumber"),n=require("@ethersproject/bytes"),a=require("@metamask/eth-sig-util"),r=require("ethereumjs-util");function i(e,t,n,a,r,i,s){try{var o=e[i](s),p=o.value}catch(e){return void n(e)}o.done?t(p):Promise.resolve(p).then(a,r)}function s(e){return function(){var t=this,n=arguments;return new Promise((function(a,r){var s=e.apply(t,n);function o(e){i(s,a,r,o,p,"next",e)}function p(e){i(s,a,r,o,p,"throw",e)}o(void 0)}))}}function o(){return(o=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)}var p,u,d,y,l,c,m=(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",s=a.toStringTag||"@@toStringTag";function o(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{o({},"")}catch(e){o=function(e,t,n){return e[t]=n}}function p(e,t,n,a){var r=Object.create((t&&t.prototype instanceof y?t:y).prototype),i=new g(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 s=n.delegate;if(s){var o=w(s,n);if(o){if(o===d)continue;return o}}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 p=u(e,t,n);if("normal"===p.type){if(a=n.done?"completed":"suspendedYield",p.arg===d)continue;return{value:p.arg,done:n.done}}"throw"===p.type&&(a="completed",n.method="throw",n.arg=p.arg)}}}(e,n,i),r}function u(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=p;var d={};function y(){}function l(){}function c(){}var m={};o(m,r,(function(){return this}));var f=Object.getPrototypeOf,b=f&&f(f(E([])));b&&b!==t&&n.call(b,r)&&(m=b);var T=c.prototype=y.prototype=Object.create(m);function h(e){["next","throw","return"].forEach((function(t){o(e,t,(function(e){return this._invoke(t,e)}))}))}function v(e,t){var a;this._invoke=function(r,i){function s(){return new t((function(a,s){!function a(r,i,s,o){var p=u(e[r],e,i);if("throw"!==p.type){var d=p.arg,y=d.value;return y&&"object"==typeof y&&n.call(y,"__await")?t.resolve(y.__await).then((function(e){a("next",e,s,o)}),(function(e){a("throw",e,s,o)})):t.resolve(y).then((function(e){d.value=e,s(d)}),(function(e){return a("throw",e,s,o)}))}o(p.arg)}(r,i,a,s)}))}return a=a?a.then(s,s):s()}}function w(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,w(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=u(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 S(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 x(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function g(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function E(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:A}}function A(){return{value:void 0,done:!0}}return l.prototype=c,o(T,"constructor",c),o(c,"constructor",l),l.displayName=o(c,s,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,c):(e.__proto__=c,o(e,s,"GeneratorFunction")),e.prototype=Object.create(T),e},e.awrap=function(e){return{__await:e}},h(v.prototype),o(v.prototype,i,(function(){return this})),e.AsyncIterator=v,e.async=function(t,n,a,r,i){void 0===i&&(i=Promise);var s=new v(p(t,n,a,r),i);return e.isGeneratorFunction(n)?s:s.next().then((function(e){return e.done?e.value:s.next()}))},h(T),o(T,s,"Generator"),o(T,r,(function(){return this})),o(T,"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=E,g.prototype={constructor:g,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(x),!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 s.type="throw",s.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],s=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var o=n.call(i,"catchLoc"),p=n.call(i,"finallyLoc");if(o&&p){if(this.prev<i.catchLoc)return a(i.catchLoc,!0);if(this.prev<i.finallyLoc)return a(i.finallyLoc)}else if(o){if(this.prev<i.catchLoc)return a(i.catchLoc,!0)}else{if(!p)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 s=i?i.completion:{};return s.type=e,s.arg=t,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(s)},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),x(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;x(n)}return r}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}(c={exports:{}}),c.exports),f=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"deposit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"",type:"uint256"}],name:"withdraw",outputs:[],stateMutability:"nonpayable",type:"function"}];(p=exports.ChainId||(exports.ChainId={}))[p.mainnet=1]="mainnet",p[p.ropsten=3]="ropsten",p[p.kovan=42]="kovan",p[p.goerli=5]="goerli",p[p.rinkeby=4]="rinkeby",p[p.optimism=10]="optimism",p[p.polygon=137]="polygon",p[p.arbitrum=42161]="arbitrum",(u=exports.Source||(exports.Source={})).Aggregator0x="0x",u.Aggregotor1inch="1inch",(d=exports.SwapType||(exports.SwapType={})).normal="normal",d.crossChain="cross-chain";var b="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",T="https://swap.p.rainbow.me",h=((y={})[""+exports.ChainId.arbitrum]="0x82af49447d8a07e3bd95bd0d56f35241523fbab1",y[""+exports.ChainId.mainnet]="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",y[""+exports.ChainId.optimism]="0x4200000000000000000000000000000000000006",y[""+exports.ChainId.polygon]="0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270",y),v=((l={})[""+exports.ChainId.mainnet]="0x6b175474e89094c44da98b954eedeac495271d0f",l),w="0x77777feddddffc19ff86db637967013e6c6a116c",S="0x0d438f3b5175bebc262bf23753c1e53d03432bde",x="0x1b40183efb4dd766f11bda7a7c3ad8982e998421",g=t.BigNumber.from("2").pow("256").sub("1").toString(),E=function(){var t=s(m.mark((function t(n,a,r,i){var s;return m.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=exports.ChainId.mainnet),void 0===i&&(i={}),s=new e.Contract(h[r],JSON.stringify(f),a),t.abrupt("return",s.deposit(o({},i,{value:n})));case 4:case"end":return t.stop()}}),t)})));return function(e,n,a,r){return t.apply(this,arguments)}}(),A=function(){var t=s(m.mark((function t(n,a,r,i){var s;return m.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=exports.ChainId.mainnet),void 0===i&&(i={}),s=new e.Contract(h[r],JSON.stringify(f),a),t.abrupt("return",s.withdraw(n,i));case 4:case"end":return t.stop()}}),t)})));return function(e,n,a,r){return t.apply(this,arguments)}}(),C=[{inputs:[],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"EthWithdrawn",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"newOwner",type:"address"},{indexed:!0,internalType:"address",name:"oldOwner",type:"address"}],name:"OwnerChanged",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"}],name:"SwapTargetAdded",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"target",type:"address"}],name:"SwapTargetRemoved",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"token",type:"address"},{indexed:!0,internalType:"address",name:"target",type:"address"},{indexed:!1,internalType:"uint256",name:"amount",type:"uint256"}],name:"TokenWithdrawn",type:"event"},{inputs:[{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"feeAmount",type:"uint256"}],name:"fillQuoteEthToToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feePercentageBasisPoints",type:"uint256"}],name:"fillQuoteTokenToEth",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feePercentageBasisPoints",type:"uint256"},{components:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"isDaiStylePermit",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],internalType:"struct PermitHelper.Permit",name:"permitData",type:"tuple"}],name:"fillQuoteTokenToEthWithPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feeAmount",type:"uint256"}],name:"fillQuoteTokenToToken",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"sellTokenAddress",type:"address"},{internalType:"address",name:"buyTokenAddress",type:"address"},{internalType:"address payable",name:"target",type:"address"},{internalType:"bytes",name:"swapCallData",type:"bytes"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"feeAmount",type:"uint256"},{components:[{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"isDaiStylePermit",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],internalType:"struct PermitHelper.Permit",name:"permitData",type:"tuple"}],name:"fillQuoteTokenToTokenWithPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"swapTargets",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"add",type:"bool"}],name:"updateSwapTargets",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdrawEth",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"withdrawToken",outputs:[],stateMutability:"nonpayable",type:"function"},{stateMutability:"payable",type:"receive"}],_=function(e){var t=e.sellTokenAddress,n=e.buyTokenAddress,a=e.buyAmount,r=e.sellAmount,i=e.fromAddress,s=e.source,p=e.feePercentageBasisPoints,u=e.slippage,d=new URLSearchParams(o({buyToken:n,chainId:String(e.chainId),fromAddress:i,sellToken:t,slippage:String(u),swapType:exports.SwapType.normal},s?{source:s}:{},r?{sellAmount:String(r)}:{buyAmount:String(a)},n===b?{destReceiver:"0x00000000009726632680fb29d3f7a9734e3010e2"}:{},void 0!==p?{feePercentageBasisPoints:String(p)}:{}));return T+"/quote?"+d.toString()},P=function(e){var t=e.toChainId,n=e.sellTokenAddress,a=e.sellAmount,r=e.fromAddress,i=e.slippage,s=e.refuel,o=new URLSearchParams({buyToken:e.buyTokenAddress,chainId:String(e.chainId),fromAddress:r,refuel:String(s),sellAmount:String(a),sellToken:n,slippage:String(i),swapType:exports.SwapType.crossChain,toChainId:String(t)});return T+"/quote?"+o.toString()},M=function(){var e=s(m.mark((function e(t){var n,a,r,i,s,o,p,u,d,y,l,c,f,T,v,w,S,x,g,E;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=t.source,i=void 0===(r=t.chainId)?exports.ChainId.mainnet:r,s=t.fromAddress,p=t.buyTokenAddress,u=t.sellAmount,d=t.buyAmount,y=t.slippage,l=t.feePercentageBasisPoints,c=(o=t.sellTokenAddress).toLowerCase(),f=p.toLowerCase(),T=b.toLowerCase(),v=null==(n=h[i])?void 0:n.toLowerCase(),S=c===v&&f===T,!(w=c===T&&f===v)&&!S){e.next=9;break}return e.abrupt("return",{buyAmount:u||d,buyTokenAddress:p,defaultGasLimit:w?"30000":"40000",fee:0,feePercentageBasisPoints:0,from:s,inputTokenDecimals:18,outputTokenDecimals:18,sellAmount:u||d,sellAmountMinusFees:u||d,sellTokenAddress:o});case 9:if(!isNaN(Number(u))||!isNaN(Number(d))){e.next=11;break}return e.abrupt("return",null);case 11:return x=_({buyAmount:d,buyTokenAddress:p,chainId:i,feePercentageBasisPoints:l,fromAddress:s,sellAmount:u,sellTokenAddress:o,slippage:y,source:a}),e.next=14,fetch(x);case 14:return g=e.sent,e.next=17,g.json();case 17:if(!(E=e.sent).error){e.next=20;break}return e.abrupt("return",E);case 20:return e.abrupt("return",E);case 21:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),k=function(){var e=s(m.mark((function e(t){var n,a,r,i,s,o,p,u,d,y,l,c,f;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a=void 0===(n=t.chainId)?exports.ChainId.mainnet:n,r=t.toChainId,i=t.fromAddress,s=t.sellTokenAddress,o=t.buyTokenAddress,u=t.slippage,y=void 0!==(d=t.refuel)&&d,(p=t.sellAmount)&&r){e.next=3;break}return e.abrupt("return",null);case 3:return l=P({buyTokenAddress:o,chainId:a,fromAddress:i,refuel:y,sellAmount:p,sellTokenAddress:s,slippage:u,toChainId:r}),e.next=6,fetch(l);case 6:return c=e.sent,e.next=9,c.json();case 9:if(!(f=e.sent).error){e.next=12;break}return e.abrupt("return",f);case 12:return e.abrupt("return",f);case 13:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),I=function(){var e=s(m.mark((function e(t){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.provider.getBlock("latest");case 2:return e.abrupt("return",e.sent.timestamp+3600);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),L=function(){var t=s(m.mark((function t(n,a,r,i,s){var p,u,d,y,l,c,f,T,h,v,w,S,x,E,A;return m.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(p=new e.Contract("0x00000000009726632680fb29d3f7a9734e3010e2",C,r),d=n.sellTokenAddress,y=n.buyTokenAddress,l=n.to,c=n.data,f=n.fee,T=n.value,h=n.sellAmount,v=n.feePercentageBasisPoints,w=b.toLowerCase(),(null==d?void 0:d.toLowerCase())!==w){t.next=9;break}return t.next=6,p.fillQuoteEthToToken(y,l,c,f,o({},a,{value:T}));case 6:u=t.sent,t.next=42;break;case 9:if((null==y?void 0:y.toLowerCase())!==w){t.next=27;break}if(!i){t.next=22;break}return t.next=13,I(r);case 13:return S=t.sent,t.next=16,Q(r,d,n.from,p.address,g,S,s);case 16:return x=t.sent,t.next=19,p.fillQuoteTokenToEthWithPermit(d,l,c,h,v,x,o({},a,{value:T}));case 19:u=t.sent,t.next=25;break;case 22:return t.next=24,p.fillQuoteTokenToEth(d,l,c,h,v,o({},a,{value:T}));case 24:u=t.sent;case 25:t.next=42;break;case 27:if(!i){t.next=39;break}return t.next=30,I(r);case 30:return E=t.sent,t.next=33,Q(r,d,n.from,p.address,g,E,s);case 33:return A=t.sent,t.next=36,p.fillQuoteTokenToTokenWithPermit(d,y,l,c,h,f,A,o({},a,{value:T}));case 36:u=t.sent,t.next=42;break;case 39:return t.next=41,p.fillQuoteTokenToToken(d,y,l,c,h,f,o({},a,{value:T}));case 41:u=t.sent;case 42:return t.abrupt("return",u);case 43:case"end":return t.stop()}}),t)})));return function(e,n,a,r,i){return t.apply(this,arguments)}}(),R=function(){var e=s(m.mark((function e(t,n,a){var r,i,s,p;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.to,i=t.data,s=t.from,p=t.value,e.next=3,a.sendTransaction(o({data:i,from:s,to:r},o({},n,{value:p})));case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})));return function(t,n,a){return e.apply(this,arguments)}}(),N=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"PERMIT_TYPEHASH",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"holder",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],O=[{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"_nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"}],name:"nonces",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"permit",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"symbol",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:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"sender",type:"address"},{internalType:"address",name:"recipient",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"version",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"}],D=[{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],V=function(){var e=s(m.mark((function e(t,n,r,i){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return","0x"+a.TypedDataUtils.hashStruct("EIP712Domain",{chainId:r,name:t,verifyingContract:i,version:n},{EIP712Domain:D},a.SignTypedDataVersion.V4).toString("hex"));case 1:case"end":return e.stop()}}),e)})));return function(t,n,a,r){return e.apply(this,arguments)}}(),U=function(){var e=s(m.mark((function e(t,n,a,r){var i,s;return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.version();case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),i="1",e.prev=10,e.next=13,t.DOMAIN_SEPARATOR();case 13:return s=e.sent,e.next=16,V(n,i,a,r);case 16:if(s!==e.sent){e.next=19;break}return e.abrupt("return",i);case 19:e.next=26;break;case 21:if(e.prev=21,e.t1=e.catch(10),1!==a||-1===[w,S,x].map((function(e){return e.toLowerCase()})).indexOf(t.address.toLowerCase())){e.next=25;break}return e.abrupt("return","1");case 25:case 26:return e.abrupt("return",null);case 27:case"end":return e.stop()}}),e,null,[[0,7],[10,21]])})));return function(t,n,a,r){return e.apply(this,arguments)}}(),B=function(){var e=s(m.mark((function e(t,n){return m.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.nonces(n);case 3:return e.abrupt("return",e.sent);case 7:return e.prev=7,e.t0=e.catch(0),e.prev=9,e.next=12,t._nonces(n);case 12:return e.abrupt("return",e.sent);case 16:return e.prev=16,e.t1=e.catch(9),e.abrupt("return",0);case 19:case"end":return e.stop()}}),e,null,[[0,7],[9,16]])})));return function(t,n){return e.apply(this,arguments)}}(),W=[{name:"name",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"}],H=[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}],F=[{name:"holder",type:"address"},{name:"spender",type:"address"},{name:"nonce",type:"uint256"},{name:"expiry",type:"uint256"},{name:"allowed",type:"bool"}];function Q(e,t,n,a,r,i,s){return X.apply(this,arguments)}function X(){return(X=s(m.mark((function i(s,o,p,u,d,y,l){var c,f,b,T,h,w,S,x,g,E,A,C,_;return m.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return f=o.toLowerCase()===(null==(c=v[l])?void 0:c.toLowerCase()),b=new e.Contract(o,f?N:O,s),i.next=4,b.name();case 4:return T=i.sent,i.next=7,Promise.all([B(b,p),U(b,T,l,b.address)]);case 7:return w=(h=i.sent)[0],S=h[1],x={nonce:Number(w.toString()),spender:u},f?(x.holder=p,x.allowed=!0,x.expiry=Number(y.toString())):(x.value=t.BigNumber.from(d).toHexString(),x.deadline=Number(y.toString()),x.owner=p),g={chainId:l,name:T,verifyingContract:b.address},null!==S&&(g.version=S),E={domain:g,message:x,primaryType:"Permit",types:{EIP712Domain:null!==S?D:W,Permit:f?F:H}},A=r.toBuffer(r.addHexPrefix(s.privateKey)),C=a.signTypedData({data:E,privateKey:A,version:a.SignTypedDataVersion.V4}),_=n.splitSignature(C),i.abrupt("return",{deadline:y,isDaiStylePermit:f,nonce:w,r:_.r,s:_.s,v:_.v,value:x.value||t.BigNumber.from("0").toHexString()});case 20:case"end":return i.stop()}}),i)})))).apply(this,arguments)}exports.ALLOWS_PERMIT={"0x0d438f3b5175bebc262bf23753c1e53d03432bde":!0,"0x111111111117dc0aa78b770fa6a738034120c302":!0,"0x1b40183efb4dd766f11bda7a7c3ad8982e998421":!0,"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984":!0,"0x31c8eacbffdd875c74b94b077895bd78cf1e64a3":!0,"0x6b175474e89094c44da98b954eedeac495271d0f":!0,"0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d":!0,"0x77777feddddffc19ff86db637967013e6c6a116c":!0,"0x888888435fde8e7d4c54cab67f206e4199454c60":!0,"0x888888888889c00c67689029d7856aac1065ec11":!0,"0x88acdd2a6425c3faae4bc9650fd7e27e0bebb7ab":!0,"0x956f47f50a910163d8bf957cf5846d573e7f87ca":!0,"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48":!0,"0xba100000625a3754423978a60c9317c58a424e3d":!0,"0xc7283b66eb1eb5fb86327f08e1b5816b0720212b":!0},exports.API_BASE_URL=T,exports.DAI=v,exports.ETH_ADDRESS=b,exports.MAX_INT=g,exports.PERMIT_EXPIRATION_TS=3600,exports.RAINBOW_ROUTER_CONTRACT_ADDRESS="0x00000000009726632680fb29d3f7a9734e3010e2",exports.SOCKET_REGISTRY_CONTRACT_ADDRESSESS="0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0",exports.TORN_ADDRESS=w,exports.USDC_ADDRESS="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",exports.VSP_ADDRESS=x,exports.WNXM_ADDRESS=S,exports.WRAPPED_ASSET=h,exports.fillCrosschainQuote=R,exports.fillQuote=L,exports.getCrosschainQuote=k,exports.getCrosschainQuoteExecutionDetails=function(e,t,n){var a=e.value;return{method:n.estimateGas({data:e.data,from:e.from,to:e.to,value:a}),params:o({},t,{value:a})}},exports.getQuote=M,exports.getQuoteExecutionDetails=function(t,n,a){var r=new e.Contract("0x00000000009726632680fb29d3f7a9734e3010e2",C,a),i=t.sellTokenAddress,s=t.buyTokenAddress,p=t.to,u=t.data,d=t.fee,y=t.value,l=t.sellAmount,c=t.feePercentageBasisPoints,m=b.toLowerCase();return(null==i?void 0:i.toLowerCase())===m?{method:r.estimateGas.fillQuoteEthToToken,methodArgs:[s,p,u,d],methodName:"fillQuoteEthToToken",params:o({},n,{value:y}),router:r}:(null==s?void 0:s.toLowerCase())===m?{method:r.estimateGas.fillQuoteTokenToEth,methodArgs:[i,p,u,l,c],methodName:"fillQuoteTokenToEth",params:o({},n,{value:y}),router:r}:{method:r.estimateGas.fillQuoteTokenToToken,methodArgs:[i,s,p,u,l,d],methodName:"fillQuoteTokenToToken",params:o({},n,{value:y}),router:r}},exports.getWrappedAssetMethod=function(t,n,a){return void 0===a&&(a=exports.ChainId.mainnet),new e.Contract(h[a],JSON.stringify(f),n).estimateGas[t]},exports.signPermit=Q,exports.sources={AAVE:"Aave",AAVE_LIQUIDATOR:"Aave Liquidator",AAVE_V2:"Aave V2",BALANCER:"Balancer",BALANCER_V2:"Balancer V2",BANCOR:"Bancor",BLACKHOLESWAP:"Blackholeswap",CHAI:"Chai",CLIPPER:"Clipper",COFIX:"CoFix",COMPOUND:"Compound",CONVERGENCE_X:"Convergence X",CREAM_LENDING:"Creamswap Lending",CREAMSWAP:"Creamswap",CURVE:"Curve",CURVE_V2:"Curve V2",CURVE_V2_ETH_CRV:"CURVE V2 ETH CRV",CURVE_V2_ETH_CVX:"CURVE V2 ETH CVX",CURVE_V2_EURS_2_ASSET:"Curve V2 EURS",CURVE_V2_EURT_2_ASSET:"CURVE V2 EURT",CURVE_V2_SPELL_2_ASSET:"Curve Spell",CURVE_V2_THRESHOLDNETWORK_2_ASSET:"Curve Threshold",CURVE_V2_XAUT_2_ASSET:"CURVE V2 XAUt",CURVE_V2_YFI_2_ASSET:"Curve Yfi",DEFI_PLAZA:"DeFi Plaza",DEFISWAP:"DeFi Swap",DFX_FINANCE:"Dfx Finance",DODO:"DODO",DODO_V2:"DODO v2",DXSWAP:"Swapr",FIXED_FEE_SWAP:"Fixed Fee Swap",FIXED_FEE_SWAP_V3:"Fixed Rate Swap",IEARN:"yEarn",INDEXED_FINANCE:"Indexed Finance",KYBER:"Kyber",KYBER_DMM:"Kyber DMM",LINKSWAP:"Link Swap",LUASWAP:"Lua Swap",MINISWAP:"Mini Swap",MOONISWAP:"Mooniswap",MSTABLE:"mStable",OASIS:"Oasis",ONE_INCH_LIMIT_ORDER:"1inch Limit Order Protocol",ONE_INCH_LIMIT_ORDER_V2:"1inch Limit Order Protocol V2",ONE_INCH_LP:"1inch LP v1.0",ONE_INCH_LP_1_1:"1inch LP v1.1",ONE_INCH_LP_MIGRATOR:"Mooniswap Migrator",ONE_INCH_LP_MIGRATOR_V1_1:"1inch LP v1.0 Migrator",PMM1:"PMM1",PMM2:"PMM2",PMM3:"PMM3",PMM4:"PMM4",PMMX:"LiqPool X",POWERINDEX:"POWERINDEX",PSM:"PSM",S_FINANCE:"sFinance",SADDLE:"Saddle Finance",SAKESWAP:"Sake Swap",SETH_WRAPPER:"sETH Wrapper",SHELL:"Shell",SHIBASWAP:"Shiba Swap",SMOOTHY_FINANCE:"Smoothy Finance",ST_ETH:"stETH",SUSHI:"Sushiswap",SUSHISWAP_MIGRATOR:"SushiSwap Migrator",SWERVE:"Swerve",SYNAPSE:"Synapse",SYNTHETIX:"Synthetix",SYNTHETIX_WRAPPER:"Synthetix Wrapper",UNIFI:"Unifi",UNISWAP_V1:"Uniswap V1",UNISWAP_V2:"Uniswap V2",UNISWAP_V2_MIGRATOR:"Uniswap Migrator",UNISWAP_V3:"UNISWAP V3",VALUELIQUID:"Value Liquid",WETH:"WETH",WSTETH:"wstETH",XSIGMA:"xSigma",ZRX:"0x",Native:"Native",Uniswap:"Uniswap",UniswapV2:"Uniswap_V2",Eth2Dai:"Eth2Dai",Kyber:"Kyber",Curve:"Curve",LiquidityProvider:"LiquidityProvider",MultiBridge:"MultiBridge",Balancer:"Balancer",BalancerV2:"Balancer_V2",Cream:"CREAM",Bancor:"Bancor",MakerPsm:"MakerPsm",MStable:"mStable",Mooniswap:"Mooniswap",MultiHop:"MultiHop",Shell:"Shell",Swerve:"Swerve",SnowSwap:"SnowSwap",SushiSwap:"SushiSwap",Dodo:"DODO",DodoV2:"DODO_V2",CryptoCom:"CryptoCom",Linkswap:"Linkswap",KyberDmm:"KyberDMM",Smoothy:"Smoothy",Component:"Component",Saddle:"Saddle",XSigma:"xSigma",UniswapV3:"Uniswap_V3",CurveV2:"Curve_V2",Lido:"Lido",ShibaSwap:"ShibaSwap",Clipper:"Clipper",PancakeSwap:"PancakeSwap",PancakeSwapV2:"PancakeSwap_V2",BakerySwap:"BakerySwap",Nerve:"Nerve",Belt:"Belt",Ellipsis:"Ellipsis",ApeSwap:"ApeSwap",CafeSwap:"CafeSwap",CheeseSwap:"CheeseSwap",JulSwap:"JulSwap",ACryptos:"ACryptoS",QuickSwap:"QuickSwap",ComethSwap:"ComethSwap",Dfyn:"Dfyn",WaultSwap:"WaultSwap",Polydex:"Polydex",FirebirdOneSwap:"FirebirdOneSwap",JetSwap:"JetSwap",IronSwap:"IronSwap"},exports.unwrapNativeAsset=A,exports.wrapNativeAsset=E;
//# sourceMappingURL=swaps.cjs.production.min.js.map

@@ -17,2 +17,6 @@ import { BigNumberish } from '@ethersproject/bignumber';

}
export declare enum SwapType {
normal = "normal",
crossChain = "cross-chain"
}
export declare type EthereumAddress = string;

@@ -29,2 +33,6 @@ export interface QuoteParams {

destReceiver?: EthereumAddress;
refuel?: boolean;
swapType: SwapType;
feePercentageBasisPoints?: number;
toChainId?: number;
}

@@ -57,3 +65,112 @@ export interface ProtocolShare {

defaultGasLimit?: string;
swapType?: string;
}
interface SocketGasFees {
gasAmount: BigNumberish;
gasLimit: string;
asset: SocketAsset;
feesInUsd: number;
}
interface SocketProtocol {
name: string;
displayName: string;
icon: string;
securityScore: number;
robustnessScore: number;
}
interface SocketProtocolFees {
amount: BigNumberish;
asset: SocketAsset;
feesInUsd: number;
}
interface SocketRoute {
chainGasBalances: {
[chainId: string]: {
minGasBalance: string;
hasGasBalance: boolean;
};
};
routeId: string;
isOnlySwapRoute: boolean;
fromAmount: BigNumberish;
toAmount: BigNumberish;
usedBridgeNames: string[];
minimumGasBalances: {
[chaind: string]: BigNumberish;
};
totalUserTx: number;
sender: EthereumAddress;
recipient: EthereumAddress;
totalGasFeesInUsd: BigNumberish;
userTxs: {
userTxType: string;
txType: string;
chainId: number;
toAmount: BigNumberish;
toAsset: SocketAsset;
stepCount: number;
routePath: string;
sender: EthereumAddress;
approvalData: {
minimumApprovalAmount: number;
approvalTokenAddress: EthereumAddress;
allowanceTarget: EthereumAddress;
owner: EthereumAddress;
} | null;
steps: {
type: string;
protocol: SocketProtocol;
fromChainId: number;
fromAsset: SocketAsset;
fromAmount: BigNumberish;
toChainId: number;
toAsset: SocketAsset;
toAmount: BigNumberish;
minAmountOut: BigNumberish;
bridgeSlippage: number;
protocolFees: SocketProtocolFees;
gasFees: SocketGasFees;
serviceTime: number;
maxServiceTime: number;
}[];
gasFees: SocketGasFees;
serviceTime: number;
maxServiceTime: number;
recipient: EthereumAddress;
bridgeSlippage: number;
userTxIndex: number;
}[];
serviceTime: number;
maxServiceTime: number;
}
interface SocketRefuelData {
fromAmount: string;
toAmount: string;
gasFees: SocketGasFees;
recipient: EthereumAddress;
serviceTime: number;
fromAsset: SocketAsset;
toAsset: SocketAsset;
fromChainId: number;
toChainId: number;
}
interface SocketAsset {
address: EthereumAddress;
chainAgnosticId: number | null;
chainId: number;
decimals: number;
icon: string;
logoURI: string;
name: string;
symbol: string;
}
export interface CrosschainQuote extends Quote {
fromAsset: SocketAsset;
fromChainId: number;
toAsset: SocketAsset;
toChainId: number;
allowanceTarget?: string;
routes: SocketRoute[];
refuel: SocketRefuelData | null;
}
export interface TransactionOptions {

@@ -74,1 +191,6 @@ gasLimit?: string;

}
export interface CrosschainQuoteExecutionDetails {
method: any;
params: TransactionOptions;
}
export {};

@@ -5,2 +5,3 @@ import { EthereumAddress } from '../types';

export declare const RAINBOW_ROUTER_CONTRACT_ADDRESS = "0x00000000009726632680fb29d3f7a9734e3010e2";
export declare const SOCKET_REGISTRY_CONTRACT_ADDRESSESS = "0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0";
export declare type MultiChainAsset = {

@@ -11,3 +12,3 @@ [key: string]: EthereumAddress;

export declare const DAI: MultiChainAsset;
export declare const USDC_ADDRESS = "0x111111111117dc0aa78b770fa6a738034120c302";
export declare const USDC_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
export declare const TORN_ADDRESS = "0x77777feddddffc19ff86db637967013e6c6a116c";

@@ -14,0 +15,0 @@ export declare const WNXM_ADDRESS = "0x0d438f3b5175bebc262bf23753c1e53d03432bde";

{
"version": "0.1.14",
"version": "0.1.15",
"name": "@rainbow-me/swaps",

@@ -4,0 +4,0 @@ "license": "GPL-3.0",

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

## 🌈 Rainbow Swap Aggregator JS SDK
## 🌈 Rainbow Swap Aggregator JS SDK [![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

@@ -3,0 +3,0 @@ This SDK handles

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

import { BigNumberish } from '@ethersproject/bignumber';
import { Contract } from '@ethersproject/contracts';

@@ -8,2 +9,5 @@ import { StaticJsonRpcProvider } from '@ethersproject/providers';

ChainId,
CrosschainQuote,
CrosschainQuoteExecutionDetails,
EthereumAddress,
Quote,

@@ -13,2 +17,4 @@ QuoteError,

QuoteParams,
Source,
SwapType,
TransactionOptions,

@@ -27,2 +33,107 @@ } from './types';

/**
* Function to get a swap formatted quote url to use with backend
*
* @param {ChainId} params.chainId
* @param {EthereumAddress} params.sellTokenAddress
* @param {EthereumAddress} params.buyTokenAddress
* @param {BigNumberish} params.buyAmount
* @param {BigNumberish} params.sellAmount
* @param {EthereumAddress} params.fromAddress
* @param {string} params.source
* @param {number} params.feePercentageBasisPoints
* @param {number} params.slippage
* @returns {string}
*/
const buildRainbowQuoteUrl = ({
chainId,
sellTokenAddress,
buyTokenAddress,
buyAmount,
sellAmount,
fromAddress,
source,
feePercentageBasisPoints,
slippage,
}: {
chainId: number;
toChainId?: number;
sellTokenAddress: EthereumAddress;
buyTokenAddress: EthereumAddress;
buyAmount?: BigNumberish;
sellAmount?: BigNumberish;
fromAddress: EthereumAddress;
feePercentageBasisPoints?: number;
source?: Source;
slippage: number;
}) => {
const searchParams = new URLSearchParams({
buyToken: buyTokenAddress,
chainId: String(chainId),
fromAddress,
sellToken: sellTokenAddress,
slippage: String(slippage),
swapType: SwapType.normal,
...(source ? { source } : {}),
...(sellAmount
? { sellAmount: String(sellAmount) }
: { buyAmount: String(buyAmount) }),
// When buying ETH, we need to tell the aggregator
// to return the funds to the contract if we need to take a fee
...(buyTokenAddress === ETH_ADDRESS
? { destReceiver: RAINBOW_ROUTER_CONTRACT_ADDRESS }
: {}),
...(feePercentageBasisPoints !== undefined
? { feePercentageBasisPoints: String(feePercentageBasisPoints) }
: {}),
});
return API_BASE_URL + '/quote?' + searchParams.toString();
};
/**
* Function to get a crosschain swap formatted quote url to use with backend
*
* @param {ChainId} params.chainId
* @param {ChainId} params.toChainId
* @param {EthereumAddress} params.sellTokenAddress
* @param {EthereumAddress} params.buyTokenAddress
* @param {BigNumberish} params.sellAmount
* @param {EthereumAddress} params.fromAddress
* @param {number} params.slippage
* @param {boolean} params.refuel
* @returns {string}
*/
const buildRainbowCrosschainQuoteUrl = ({
chainId,
toChainId,
sellTokenAddress,
buyTokenAddress,
sellAmount,
fromAddress,
slippage,
refuel,
}: {
chainId: number;
toChainId?: number;
sellTokenAddress: EthereumAddress;
buyTokenAddress: EthereumAddress;
sellAmount?: BigNumberish;
fromAddress: EthereumAddress;
slippage: number;
refuel?: boolean;
}) => {
const searchParams = new URLSearchParams({
buyToken: buyTokenAddress,
chainId: String(chainId),
fromAddress,
refuel: String(refuel),
sellAmount: String(sellAmount),
sellToken: sellTokenAddress,
slippage: String(slippage),
swapType: SwapType.crossChain,
toChainId: String(toChainId),
});
return API_BASE_URL + '/quote?' + searchParams.toString();
};
/**
* Function to get a quote from rainbow's swap aggregator backend

@@ -39,2 +150,3 @@ *

* @param {number} params.slippage
* @param {number} params.feePercentageBasisPoints
* @returns {Promise<Quote | null>}

@@ -54,2 +166,3 @@ */

slippage,
feePercentageBasisPoints,
} = params;

@@ -85,11 +198,2 @@ // When wrapping or unwrapping ETH, the quote is always 1:1

let url = `${API_BASE_URL}/quote?chainId=${chainId}&fromAddress=${fromAddress}&buyToken=${buyTokenAddress}&sellToken=${sellTokenAddress}&slippage=${slippage}`;
if (source) {
url += `&source=${source}`;
}
if (sellAmount) {
url += `&sellAmount=${sellAmount}`;
} else if (buyAmount) {
url += `&buyAmount=${buyAmount}`;
}
if (isNaN(Number(sellAmount)) && isNaN(Number(buyAmount))) {

@@ -99,14 +203,65 @@ return null;

// When buying ETH, we need to tell the aggregator
// to return the funds to the contract if we need to take a fee
if (buyTokenAddress === ETH_ADDRESS) {
url += `&destReceiver=${RAINBOW_ROUTER_CONTRACT_ADDRESS}`;
const url = buildRainbowQuoteUrl({
buyAmount,
buyTokenAddress,
chainId,
feePercentageBasisPoints,
fromAddress,
sellAmount,
sellTokenAddress,
slippage,
source,
});
const response = await fetch(url);
const quote = await response.json();
if (quote.error) {
return quote as QuoteError;
}
return quote as Quote;
};
// @ts-ignore
if (params.feePercentageBasisPoints !== undefined) {
// @ts-ignore
url += `&feePercentageBasisPoints=${params.feePercentageBasisPoints}`;
/**
* Function to get a crosschain swap quote from rainbow's swap aggregator backend
*
* @param {QuoteParams} params
* @param {ChainId} params.chainId
* @param {ChainId} params.toChainId
* @param {EthereumAddress} params.fromAddress
* @param {EthereumAddress} params.sellTokenAddress
* @param {EthereumAddress} params.buyTokenAddress
* @param {BigNumberish} params.sellAmount
* @param {number} params.slippage
* @param {boolean} params.refuel
* @returns {Promise<CrosschainQuote | null>}
*/
export const getCrosschainQuote = async (
params: QuoteParams
): Promise<CrosschainQuote | QuoteError | null> => {
const {
chainId = ChainId.mainnet,
toChainId,
fromAddress,
sellTokenAddress,
buyTokenAddress,
sellAmount,
slippage,
refuel = false,
} = params;
if (!sellAmount || !toChainId) {
return null;
}
const url = buildRainbowCrosschainQuoteUrl({
buyTokenAddress,
chainId,
fromAddress,
refuel,
sellAmount,
sellTokenAddress,
slippage,
toChainId,
});
const response = await fetch(url);

@@ -117,3 +272,3 @@ const quote = await response.json();

}
return quote as Quote;
return quote as CrosschainQuote;
};

@@ -254,2 +409,29 @@

/**
* Function that fills a crosschain swap quote onchain via rainbow's swap aggregator smart contract
*
* @param {CrosschainQuote} quote
* @param {TransactionOptions} transactionOptions
* @param {Wallet} wallet
* @returns {Promise<Transaction>}
*/
export const fillCrosschainQuote = async (
quote: CrosschainQuote,
transactionOptions: TransactionOptions,
wallet: Wallet
): Promise<Transaction> => {
const { to, data, from, value } = quote;
const swapTx = await wallet.sendTransaction({
data,
from,
to,
...{
...transactionOptions,
value,
},
});
return swapTx;
};
export const getQuoteExecutionDetails = (

@@ -327,1 +509,21 @@ quote: Quote,

};
export const getCrosschainQuoteExecutionDetails = (
quote: CrosschainQuote,
transactionOptions: TransactionOptions,
provider: StaticJsonRpcProvider
): CrosschainQuoteExecutionDetails => {
const { to, from, data, value } = quote;
return {
method: provider.estimateGas({
data,
from,
to,
value,
}),
params: {
...transactionOptions,
value,
},
};
};

@@ -20,2 +20,7 @@ import { BigNumberish } from '@ethersproject/bignumber';

export enum SwapType {
normal = 'normal',
crossChain = 'cross-chain',
}
export type EthereumAddress = string;

@@ -33,2 +38,6 @@

destReceiver?: EthereumAddress;
refuel?: boolean;
swapType: SwapType;
feePercentageBasisPoints?: number;
toChainId?: number;
}

@@ -64,4 +73,119 @@

defaultGasLimit?: string;
swapType?: string;
}
interface SocketGasFees {
gasAmount: BigNumberish;
gasLimit: string;
asset: SocketAsset;
feesInUsd: number;
}
interface SocketProtocol {
name: string;
displayName: string;
icon: string;
securityScore: number;
robustnessScore: number;
}
interface SocketProtocolFees {
amount: BigNumberish;
asset: SocketAsset;
feesInUsd: number;
}
interface SocketRoute {
chainGasBalances: {
[chainId: string]: {
minGasBalance: string;
hasGasBalance: boolean;
};
};
routeId: string;
isOnlySwapRoute: boolean;
fromAmount: BigNumberish;
toAmount: BigNumberish;
usedBridgeNames: string[];
minimumGasBalances: {
[chaind: string]: BigNumberish;
};
totalUserTx: number;
sender: EthereumAddress;
recipient: EthereumAddress;
totalGasFeesInUsd: BigNumberish;
userTxs: {
userTxType: string;
txType: string;
chainId: number;
toAmount: BigNumberish;
toAsset: SocketAsset;
stepCount: number;
routePath: string;
sender: EthereumAddress;
approvalData: {
minimumApprovalAmount: number;
approvalTokenAddress: EthereumAddress;
allowanceTarget: EthereumAddress;
owner: EthereumAddress;
} | null;
steps: {
type: string;
protocol: SocketProtocol;
fromChainId: number;
fromAsset: SocketAsset;
fromAmount: BigNumberish;
toChainId: number;
toAsset: SocketAsset;
toAmount: BigNumberish;
minAmountOut: BigNumberish;
bridgeSlippage: number;
protocolFees: SocketProtocolFees;
gasFees: SocketGasFees;
serviceTime: number;
maxServiceTime: number;
}[];
gasFees: SocketGasFees;
serviceTime: number;
maxServiceTime: number;
recipient: EthereumAddress;
bridgeSlippage: number;
userTxIndex: number;
}[];
serviceTime: number;
maxServiceTime: number;
}
interface SocketRefuelData {
fromAmount: string;
toAmount: string;
gasFees: SocketGasFees;
recipient: EthereumAddress;
serviceTime: number;
fromAsset: SocketAsset;
toAsset: SocketAsset;
fromChainId: number;
toChainId: number;
}
interface SocketAsset {
address: EthereumAddress;
chainAgnosticId: number | null;
chainId: number;
decimals: number;
icon: string;
logoURI: string;
name: string;
symbol: string;
}
export interface CrosschainQuote extends Quote {
fromAsset: SocketAsset;
fromChainId: number;
toAsset: SocketAsset;
toChainId: number;
allowanceTarget?: string;
routes: SocketRoute[];
refuel: SocketRefuelData | null;
}
export interface TransactionOptions {

@@ -83,1 +207,6 @@ gasLimit?: string;

}
export interface CrosschainQuoteExecutionDetails {
method: any;
params: TransactionOptions;
}

@@ -7,2 +7,4 @@ import { BigNumber } from '@ethersproject/bignumber';

'0x00000000009726632680fb29d3f7a9734e3010e2';
export const SOCKET_REGISTRY_CONTRACT_ADDRESSESS =
'0xc30141B657f4216252dc59Af2e7CdB9D8792e1B0';

@@ -23,3 +25,3 @@ export type MultiChainAsset = {

};
export const USDC_ADDRESS = '0x111111111117dc0aa78b770fa6a738034120c302';
export const USDC_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48';
export const TORN_ADDRESS = '0x77777feddddffc19ff86db637967013e6c6a116c';

@@ -26,0 +28,0 @@ export const WNXM_ADDRESS = '0x0d438f3b5175bebc262bf23753c1e53d03432bde';

Sorry, the diff of this file is too big to display

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc