Socket
Socket
Sign inDemoInstall

@cowprotocol/cow-sdk

Package Overview
Dependencies
Maintainers
8
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cowprotocol/cow-sdk - npm Package Compare versions

Comparing version 0.0.9 to 0.0.10

1

dist/api/cow/types.d.ts

@@ -74,1 +74,2 @@ import { OrderKind } from '@gnosis.pm/gp-v2-contracts';

};
export { FeeQuoteParams, PriceQuoteParams, QuoteParams, FeeInformation, PriceInformation, SimpleGetQuoteResponse, } from '../../utils/price';

8

dist/index.js

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

var e=require("loglevel"),t=require("cross-fetch"),r=require("@gnosis.pm/gp-v2-contracts"),o=require("@gnosis.pm/gp-v2-contracts/networks.json"),n=require("graphql-request"),i=require("ajv");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var u=/*#__PURE__*/s(e),c=/*#__PURE__*/s(t),d=/*#__PURE__*/s(o),l=/*#__PURE__*/s(i);class h extends Error{constructor(e,t){super(e),this.error_code=void 0,this.error_code=t}}function p(e){if(!e)return"";const t=new URLSearchParams;for(const r of Object.keys(e)){const o=e[r];o&&t.append(r,o)}const r=t.toString();return r?`?${r}`:""}const m="cow-sdk:";var f;exports.SupportedChainId=void 0,(f=exports.SupportedChainId||(exports.SupportedChainId={}))[f.MAINNET=1]="MAINNET",f[f.RINKEBY=4]="RINKEBY",f[f.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const g=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.RINKEBY,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:E}=d.default,T={[exports.SupportedChainId.MAINNET]:E[exports.SupportedChainId.MAINNET].address,[exports.SupportedChainId.RINKEBY]:E[exports.SupportedChainId.RINKEBY].address,[exports.SupportedChainId.GNOSIS_CHAIN]:E[exports.SupportedChainId.GNOSIS_CHAIN].address},v=function(e,t,o,n="v4"){try{let s;function i(e){return s?e:{signature:d.data.toString(),signingScheme:a}}const a="eth_sign"===n?r.SigningScheme.ETHSIGN:r.SigningScheme.EIP712;let c,d=null;try{switch(n){case"v3":c=new r.TypedDataV3Signer(o);break;case"int_v4":c=new r.IntChainIdTypedDataV4Signer(o);break;default:c=o}}catch(p){throw u.default.error(m,"Wallet not supported:",p),new h("Wallet not supported")}const l=function(r,o){try{var n=Promise.resolve(t({...e,signer:c,signingScheme:a})).then(function(e){d=e})}catch(e){return o(e)}return n&&n.then?n.then(void 0,o):n}(0,function(r){if(void 0===(i=r).code&&void 0===i.message)throw u.default.error(m,r),r;var i;if(r.code===A||S.test(r.message))switch(n){case"v4":const n=v(e,t,o,"v3");return s=1,n;case"v3":const i=v(e,t,o,"eth_sign");return s=1,i;default:throw r}else{if(k.test(r.message)){const r=v(e,t,o,"int_v4");return s=1,r}if(r.code===I){const r=v(e,t,o,"eth_sign");return s=1,r}if(w.test(r.message)){const r=v(e,t,o,"v3");return s=1,r}if(N.test(r.message)){const r=v(e,t,o,"eth_sign");return s=1,r}}});return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(f){return Promise.reject(f)}},y=function(e){try{const{chainId:t,signer:o,signingScheme:n,orderId:i}=e,s=C(t);return Promise.resolve(r.signOrderCancellation(s,i,o,x(n)))}catch(e){return Promise.reject(e)}},P=function(e){try{const{chainId:t,signer:o,order:n,signingScheme:i}=e,s=C(t);return Promise.resolve(r.signOrder(s,n,o,x(i)))}catch(e){return Promise.reject(e)}},I=-32603,A=-32601,w=/eth_signTypedData_v4 does not exist/i,N=/eth_signTypedData_v3 does not exist/i,S=/RPC request failed/i,k=/provided chainid .* must match the active chainid/i,D=new Map([[r.SigningScheme.EIP712,{libraryValue:0,apiValue:"eip712"}],[r.SigningScheme.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[r.SigningScheme.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[r.SigningScheme.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function O(e){const t=D.get(e);if(void 0===t)throw new h("Unknown schema "+e);return t}function _(e){return O(e).apiValue}function x(e){return O(e).libraryValue}function C(e){const t=T[e];if(!t)throw new h("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var U,b,R,L;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(U||(U={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Token pair selected has insufficient liquidity",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(b||(b={}));class j extends h{static getErrorMessage(e,t){try{return Promise.resolve(function(t,r){try{var o=Promise.resolve(e.json()).then(function(e){return e.errorType?j.apiErrorDetails[e.errorType]||e.errorType:(u.default.error(m,"Unknown reason for bad order submission",e),e.description)})}catch(e){return r()}return o&&o.then?o.then(void 0,r):o}(0,function(){return u.default.error(m,"Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return b.UNHANDLED_GET_ERROR;case"create":return b.UNHANDLED_CREATE_ERROR;case"delete":return b.UNHANDLED_DELETE_ERROR;default:return u.default.error(m,"[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(t)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e,t){try{const r=this;switch(e.status){case 400:case 404:return Promise.resolve(r.getErrorMessage(e,t));case 403:return Promise.resolve(`The order cannot be ${"create"===t?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===t?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return u.default.error(m,`[OperatorError::getErrorFromStatusCode] Error ${"create"===t?"creating":"cancelling"} the order, status code:`,e.status||"unknown"),Promise.resolve(`Error ${"create"===t?"creating":"cancelling"} the order`)}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=b[e.errorType]}}j.apiErrorDetails=b,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(R||(R={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(L||(L={}));class H extends h{static getErrorMessage(e){try{return Promise.resolve(function(t,r){try{var o=Promise.resolve(e.json()).then(function(e){return e.errorType?H.quoteErrorDetails[e.errorType]||e.errorType:(u.default.error(m,"Unknown reason for bad quote fetch",e),e.description)})}catch(e){return r()}return o&&o.then?o.then(void 0,r):o}(0,function(){return u.default.error(m,"Error handling 400/404 error. Likely a problem deserialising the JSON response"),H.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const t=this;switch(e.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(e));default:return u.default.error(m,"[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=H.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}H.quoteErrorDetails=L;class V{constructor(e,t){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=t}}const F={[exports.SupportedChainId.MAINNET]:new V("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[exports.SupportedChainId.RINKEBY]:new V("WETH","0xc778417E063141139Fce010982780140Aa0cD5Ab"),[exports.SupportedChainId.GNOSIS_CHAIN]:new V("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},B={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.RINKEBY]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function $(e,t){let r=e;return e===B[t]&&(r=F[t].address),r}function q(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}const M=function(e,t){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.json()).then(function(e){const r=function(e){switch(null==e?void 0:e.errorType){case U.NotFound:case U.NoLiquidity:return{errorType:R.InsufficientLiquidity,description:L.InsufficientLiquidity};case U.SellAmountDoesNotCoverFee:return{errorType:R.FeeExceedsFrom,description:L.FeeExceedsFrom,data:null==e?void 0:e.data};case U.UnsupportedToken:return{errorType:R.UnsupportedToken,description:e.description};case U.SellAmountDoesNotCoverFee:return{errorType:R.FeeExceedsFrom,description:e.description};default:return{errorType:R.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR}}}(e),o=new H(r);if(t){const{sellToken:e,buyToken:r}=t;u.default.error(m,`Error querying fee from API - sellToken: ${e}, buyToken: ${r}`)}throw o})}catch(e){return Promise.reject(e)}},G={errorType:R.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR},K={errorType:U.UNHANDLED_CREATE_ERROR,description:b.UNHANDLED_CREATE_ERROR};class Q{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol",this.context=e}get DEFAULT_HEADERS(){return{"Content-Type":"application/json","X-AppId":this.context.appDataHash}}get API_BASE_URL(){return this.context.isDevEnvironment?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"}:{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://api.cow.fi/rinkeby/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}get PROFILE_API_BASE_URL(){return this.context.isDevEnvironment?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"}:{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}getProfileData(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(m,`[api:${t.API_NAME}] Get profile data for`,r,e),r!==exports.SupportedChainId.MAINNET?(u.default.info(m,"Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${e}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw u.default.error(m,e),new h(null==e?void 0:e.description)})})})}catch(e){return Promise.reject(e)}}getTrades(e){try{const t=this,{owner:r,limit:o,offset:n}=e,i=p({owner:r,limit:o,offset:n});return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,"[util:operator] Get trades for",e,r,{limit:o,offset:n}),q(function(){return Promise.resolve(t.get(`/trades${i}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting trades:",e),e instanceof j)throw e;throw new h("Error getting trades: "+e)})})}catch(e){return Promise.reject(e)}}getOrders(e){try{const t=this,{owner:r,limit:o=1e3,offset:n=0}=e,i=p({limit:o,offset:n});return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Get orders for `,e,r,o,n),q(function(){return Promise.resolve(t.get(`/account/${r}/orders/${i}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting orders information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getTxOrders(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[api:${t.API_NAME}] Get tx orders for `,r,e),q(function(){return Promise.resolve(t.get(`/transactions/${e}/orders`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error("Error getting transaction orders information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getOrder(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(m,`[api:${t.API_NAME}] Get order for `,r,e),q(function(){return Promise.resolve(t.get(`/orders/${e}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting order information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getPriceQuoteLegacy(e){try{const t=this,{baseToken:r,quoteToken:o,amount:n,kind:i}=e;return Promise.resolve(t.context.chainId).then(function(s){return u.default.debug(m,`[api:${t.API_NAME}] Get price from API`,e,"for",s),Promise.resolve(t.get(`/markets/${$(r,s)}-${$(o,s)}/${i}/${n}`).catch(e=>{throw u.default.error(m,"Error getting price quote:",e),new H(G)})).then(M)})}catch(e){return Promise.reject(e)}}getQuote(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){const o=t.mapNewToLegacyParams(e,r);return Promise.resolve(t.post("/quote",o)).then(M)})}catch(e){return Promise.reject(e)}}sendSignedOrderCancellation(e){try{const t=this,{cancellation:r,owner:o}=e;return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Delete signed order for network`,e,r),Promise.resolve(t.delete(`/orders/${r.orderUid}`,{signature:r.signature,signingScheme:_(r.signingScheme),from:o})).then(function(o){function n(o){u.default.debug(m,`[api:${t.API_NAME}] Cancelled order`,r.orderUid,e)}const i=function(){if(!o.ok)return Promise.resolve(j.getErrorFromStatusCode(o,"delete")).then(function(e){throw new h(e)})}();return i&&i.then?i.then(n):n()})})}catch(e){return Promise.reject(e)}}sendOrder(e){try{const t=this,r={...e.order,appData:t.context.appDataHash};return Promise.resolve(t.context.chainId).then(function(o){const{owner:n}=e;return u.default.debug(m,`[api:${t.API_NAME}] Post signed order for network`,o,r),Promise.resolve(t.post("/orders",{...r,signingScheme:_(r.signingScheme),from:n})).then(function(e){function r(r){return Promise.resolve(e.json()).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Success posting the signed order`,e),e})}const o=function(){if(!e.ok)return Promise.resolve(j.getErrorFromStatusCode(e,"create")).then(function(e){throw new h(e)})}();return o&&o.then?o.then(r):r()})})}catch(e){return Promise.reject(e)}}getOrderLink(e){return this.getApiBaseUrl()+`/orders/${e}`}mapNewToLegacyParams(e,t){const{amount:o,kind:n,userAddress:i,receiver:s,validTo:a,sellToken:u,buyToken:c}=e,d=i||"0x0000000000000000000000000000000000000000",l={sellToken:$(u,t),buyToken:$(c,t),from:d,receiver:s||d,appData:this.context.appDataHash,validTo:a,partiallyFillable:!1};return n===r.OrderKind.SELL?{kind:r.OrderKind.SELL,sellAmountBeforeFee:o,...l}:{kind:r.OrderKind.BUY,buyAmountAfterFee:o,...l}}getApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){const r=e.API_BASE_URL[t];if(r)return r+"/v1";throw new h(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}getProfileApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){const r=e.PROFILE_API_BASE_URL[t];if(r)return r+"/v1";throw new h(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}fetch(e,t,r){try{const o=this;return Promise.resolve(o.getApiBaseUrl()).then(function(n){return c.default(n+e,{headers:o.DEFAULT_HEADERS,method:t,body:void 0!==r?JSON.stringify(r):r})})}catch(e){return Promise.reject(e)}}fetchProfile(e,t,r){try{const o=this;return Promise.resolve(o.getProfileApiBaseUrl()).then(function(n){return c.default(n+e,{headers:o.DEFAULT_HEADERS,method:t,body:void 0!==r?JSON.stringify(r):r})})}catch(e){return Promise.reject(e)}}post(e,t){return this.fetch(e,"POST",t)}get(e){return this.fetch(e,"GET")}getProfile(e){return this.fetchProfile(e,"GET")}delete(e,t){return this.fetch(e,"DELETE",t)}}const Y=n.gql`
var e=require("loglevel"),t=require("cross-fetch"),r=require("@gnosis.pm/gp-v2-contracts"),n=require("@gnosis.pm/gp-v2-contracts/networks.json"),o=require("graphql-request"),i=require("ajv");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var u=/*#__PURE__*/s(e),c=/*#__PURE__*/s(t),d=/*#__PURE__*/s(n),l=/*#__PURE__*/s(i);class h extends Error{constructor(e,t){super(e),this.error_code=void 0,this.error_code=t}}function p(e){if(!e)return"";const t=new URLSearchParams;for(const r of Object.keys(e)){const n=e[r];n&&t.append(r,n)}const r=t.toString();return r?`?${r}`:""}const m="cow-sdk:";var f;exports.SupportedChainId=void 0,(f=exports.SupportedChainId||(exports.SupportedChainId={}))[f.MAINNET=1]="MAINNET",f[f.RINKEBY=4]="RINKEBY",f[f.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const g=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.RINKEBY,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:E}=d.default,T={[exports.SupportedChainId.MAINNET]:E[exports.SupportedChainId.MAINNET].address,[exports.SupportedChainId.RINKEBY]:E[exports.SupportedChainId.RINKEBY].address,[exports.SupportedChainId.GNOSIS_CHAIN]:E[exports.SupportedChainId.GNOSIS_CHAIN].address},v=function(e,t,n,o="v4"){try{let s;function i(e){return s?e:{signature:d.data.toString(),signingScheme:a}}const a="eth_sign"===o?r.SigningScheme.ETHSIGN:r.SigningScheme.EIP712;let c,d=null;try{switch(o){case"v3":c=new r.TypedDataV3Signer(n);break;case"int_v4":c=new r.IntChainIdTypedDataV4Signer(n);break;default:c=n}}catch(p){throw u.default.error(m,"Wallet not supported:",p),new h("Wallet not supported")}const l=function(r,n){try{var o=Promise.resolve(t({...e,signer:c,signingScheme:a})).then(function(e){d=e})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(r){if(void 0===(i=r).code&&void 0===i.message)throw u.default.error(m,r),r;var i;if(r.code===A||S.test(r.message))switch(o){case"v4":const o=v(e,t,n,"v3");return s=1,o;case"v3":const i=v(e,t,n,"eth_sign");return s=1,i;default:throw r}else{if(k.test(r.message)){const r=v(e,t,n,"int_v4");return s=1,r}if(r.code===I){const r=v(e,t,n,"eth_sign");return s=1,r}if(w.test(r.message)){const r=v(e,t,n,"v3");return s=1,r}if(N.test(r.message)){const r=v(e,t,n,"eth_sign");return s=1,r}}});return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(f){return Promise.reject(f)}},y=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderId:i}=e,s=C(t);return Promise.resolve(r.signOrderCancellation(s,i,n,x(o)))}catch(e){return Promise.reject(e)}},P=function(e){try{const{chainId:t,signer:n,order:o,signingScheme:i}=e,s=C(t);return Promise.resolve(r.signOrder(s,o,n,x(i)))}catch(e){return Promise.reject(e)}},I=-32603,A=-32601,w=/eth_signTypedData_v4 does not exist/i,N=/eth_signTypedData_v3 does not exist/i,S=/RPC request failed/i,k=/provided chainid .* must match the active chainid/i,D=new Map([[r.SigningScheme.EIP712,{libraryValue:0,apiValue:"eip712"}],[r.SigningScheme.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[r.SigningScheme.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[r.SigningScheme.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function O(e){const t=D.get(e);if(void 0===t)throw new h("Unknown schema "+e);return t}function _(e){return O(e).apiValue}function x(e){return O(e).libraryValue}function C(e){const t=T[e];if(!t)throw new h("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var U,b,R,L;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(U||(U={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Token pair selected has insufficient liquidity",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(b||(b={}));class j extends h{static getErrorMessage(e,t){try{return Promise.resolve(function(t,r){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?j.apiErrorDetails[e.errorType]||e.errorType:(u.default.error(m,"Unknown reason for bad order submission",e),e.description)})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){return u.default.error(m,"Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return b.UNHANDLED_GET_ERROR;case"create":return b.UNHANDLED_CREATE_ERROR;case"delete":return b.UNHANDLED_DELETE_ERROR;default:return u.default.error(m,"[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(t)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e,t){try{const r=this;switch(e.status){case 400:case 404:return Promise.resolve(r.getErrorMessage(e,t));case 403:return Promise.resolve(`The order cannot be ${"create"===t?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===t?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return u.default.error(m,`[OperatorError::getErrorFromStatusCode] Error ${"create"===t?"creating":"cancelling"} the order, status code:`,e.status||"unknown"),Promise.resolve(`Error ${"create"===t?"creating":"cancelling"} the order`)}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=b[e.errorType]}}j.apiErrorDetails=b,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(R||(R={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(L||(L={}));class H extends h{static getErrorMessage(e){try{return Promise.resolve(function(t,r){try{var n=Promise.resolve(e.json()).then(function(e){return e.errorType?H.quoteErrorDetails[e.errorType]||e.errorType:(u.default.error(m,"Unknown reason for bad quote fetch",e),e.description)})}catch(e){return r()}return n&&n.then?n.then(void 0,r):n}(0,function(){return u.default.error(m,"Error handling 400/404 error. Likely a problem deserialising the JSON response"),H.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const t=this;switch(e.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(e));default:return u.default.error(m,"[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=H.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}H.quoteErrorDetails=L;class V{constructor(e,t){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=t}}const F={[exports.SupportedChainId.MAINNET]:new V("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[exports.SupportedChainId.RINKEBY]:new V("WETH","0xc778417E063141139Fce010982780140Aa0cD5Ab"),[exports.SupportedChainId.GNOSIS_CHAIN]:new V("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},B={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.RINKEBY]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function $(e,t){let r=e;return e===B[t]&&(r=F[t].address),r}function q(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}const M=function(e,t){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.json()).then(function(e){const r=function(e){switch(null==e?void 0:e.errorType){case U.NotFound:case U.NoLiquidity:return{errorType:R.InsufficientLiquidity,description:L.InsufficientLiquidity};case U.SellAmountDoesNotCoverFee:return{errorType:R.FeeExceedsFrom,description:L.FeeExceedsFrom,data:null==e?void 0:e.data};case U.UnsupportedToken:return{errorType:R.UnsupportedToken,description:e.description};case U.SellAmountDoesNotCoverFee:return{errorType:R.FeeExceedsFrom,description:e.description};default:return{errorType:R.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR}}}(e),n=new H(r);if(t){const{sellToken:e,buyToken:r}=t;u.default.error(m,`Error querying fee from API - sellToken: ${e}, buyToken: ${r}`)}throw n})}catch(e){return Promise.reject(e)}},G={errorType:R.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR},K={errorType:U.UNHANDLED_CREATE_ERROR,description:b.UNHANDLED_CREATE_ERROR};class Q{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol",this.context=e}get DEFAULT_HEADERS(){return{"Content-Type":"application/json","X-AppId":this.context.appDataHash}}get API_BASE_URL(){return this.context.isDevEnvironment?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"}:{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://api.cow.fi/rinkeby/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}get PROFILE_API_BASE_URL(){return this.context.isDevEnvironment?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"}:{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}getProfileData(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(m,`[api:${t.API_NAME}] Get profile data for`,r,e),r!==exports.SupportedChainId.MAINNET?(u.default.info(m,"Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${e}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw u.default.error(m,e),new h(null==e?void 0:e.description)})})})}catch(e){return Promise.reject(e)}}getTrades(e){try{const t=this,{owner:r,limit:n,offset:o}=e,i=p({owner:r,limit:n,offset:o});return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,"[util:operator] Get trades for",e,r,{limit:n,offset:o}),q(function(){return Promise.resolve(t.get(`/trades${i}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting trades:",e),e instanceof j)throw e;throw new h("Error getting trades: "+e)})})}catch(e){return Promise.reject(e)}}getOrders(e){try{const t=this,{owner:r,limit:n=1e3,offset:o=0}=e,i=p({limit:n,offset:o});return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Get orders for `,e,r,n,o),q(function(){return Promise.resolve(t.get(`/account/${r}/orders/${i}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting orders information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getTxOrders(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[api:${t.API_NAME}] Get tx orders for `,r,e),q(function(){return Promise.resolve(t.get(`/transactions/${e}/orders`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error("Error getting transaction orders information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getOrder(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(m,`[api:${t.API_NAME}] Get order for `,r,e),q(function(){return Promise.resolve(t.get(`/orders/${e}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(u.default.error(m,"Error getting order information:",e),e instanceof j)throw e;throw new j(K)})})}catch(e){return Promise.reject(e)}}getPriceQuoteLegacy(e){try{const t=this,{baseToken:r,quoteToken:n,amount:o,kind:i}=e;return Promise.resolve(t.context.chainId).then(function(s){return u.default.debug(m,`[api:${t.API_NAME}] Get price from API`,e,"for",s),Promise.resolve(t.get(`/markets/${$(r,s)}-${$(n,s)}/${i}/${o}`).catch(e=>{throw u.default.error(m,"Error getting price quote:",e),new H(G)})).then(M)})}catch(e){return Promise.reject(e)}}getQuote(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){const n=t.mapNewToLegacyParams(e,r);return Promise.resolve(t.post("/quote",n)).then(M)})}catch(e){return Promise.reject(e)}}sendSignedOrderCancellation(e){try{const t=this,{cancellation:r,owner:n}=e;return Promise.resolve(t.context.chainId).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Delete signed order for network`,e,r),Promise.resolve(t.delete(`/orders/${r.orderUid}`,{signature:r.signature,signingScheme:_(r.signingScheme),from:n})).then(function(n){function o(n){u.default.debug(m,`[api:${t.API_NAME}] Cancelled order`,r.orderUid,e)}const i=function(){if(!n.ok)return Promise.resolve(j.getErrorFromStatusCode(n,"delete")).then(function(e){throw new h(e)})}();return i&&i.then?i.then(o):o()})})}catch(e){return Promise.reject(e)}}sendOrder(e){try{const t=this,r={...e.order,appData:t.context.appDataHash};return Promise.resolve(t.context.chainId).then(function(n){const{owner:o}=e;return u.default.debug(m,`[api:${t.API_NAME}] Post signed order for network`,n,r),Promise.resolve(t.post("/orders",{...r,signingScheme:_(r.signingScheme),from:o})).then(function(e){function r(r){return Promise.resolve(e.json()).then(function(e){return u.default.debug(m,`[api:${t.API_NAME}] Success posting the signed order`,e),e})}const n=function(){if(!e.ok)return Promise.resolve(j.getErrorFromStatusCode(e,"create")).then(function(e){throw new h(e)})}();return n&&n.then?n.then(r):r()})})}catch(e){return Promise.reject(e)}}getOrderLink(e){return this.getApiBaseUrl()+`/orders/${e}`}mapNewToLegacyParams(e,t){const{amount:n,kind:o,userAddress:i,receiver:s,validTo:a,sellToken:u,buyToken:c}=e,d=i||"0x0000000000000000000000000000000000000000",l={sellToken:$(u,t),buyToken:$(c,t),from:d,receiver:s||d,appData:this.context.appDataHash,validTo:a,partiallyFillable:!1};return o===r.OrderKind.SELL?{kind:r.OrderKind.SELL,sellAmountBeforeFee:n,...l}:{kind:r.OrderKind.BUY,buyAmountAfterFee:n,...l}}getApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){const r=e.API_BASE_URL[t];if(r)return r+"/v1";throw new h(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}getProfileApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){const r=e.PROFILE_API_BASE_URL[t];if(r)return r+"/v1";throw new h(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}fetch(e,t,r){try{const n=this;return Promise.resolve(n.getApiBaseUrl()).then(function(o){return c.default(o+e,{headers:n.DEFAULT_HEADERS,method:t,body:void 0!==r?JSON.stringify(r):r})})}catch(e){return Promise.reject(e)}}fetchProfile(e,t,r){try{const n=this;return Promise.resolve(n.getProfileApiBaseUrl()).then(function(o){return c.default(o+e,{headers:n.DEFAULT_HEADERS,method:t,body:void 0!==r?JSON.stringify(r):r})})}catch(e){return Promise.reject(e)}}post(e,t){return this.fetch(e,"POST",t)}get(e){return this.fetch(e,"GET")}getProfile(e){return this.fetchProfile(e,"GET")}delete(e,t){return this.fetch(e,"DELETE",t)}}const Y=o.gql`
query Totals {

@@ -14,3 +14,3 @@ totals {

}
`,W=n.gql`
`,W=o.gql`
query LastDaysVolume($days: Int!) {

@@ -22,3 +22,3 @@ dailyTotals(orderBy: timestamp, orderDirection: desc, first: $days) {

}
`,J=n.gql`
`,J=o.gql`
query LastHoursVolume($hours: Int!) {

@@ -30,3 +30,3 @@ hourlyTotals(orderBy: timestamp, orderDirection: desc, first: $hours) {

}
`,Z={[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[exports.SupportedChainId.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class z{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[exports.SupportedChainId.MAINNET]:new n.GraphQLClient(Z[exports.SupportedChainId.MAINNET],{fetch:c.default}),[exports.SupportedChainId.RINKEBY]:new n.GraphQLClient(Z[exports.SupportedChainId.RINKEBY],{fetch:c.default}),[exports.SupportedChainId.GNOSIS_CHAIN]:new n.GraphQLClient(Z[exports.SupportedChainId.GNOSIS_CHAIN],{fetch:c.default})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return Z[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){return u.default.debug(`[subgraph:${e.API_NAME}] Get totals for:`,t),Promise.resolve(e.runQuery(Y)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} days volume for:`,r),t.runQuery(W,{days:e})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} hours volume for:`,r),t.runQuery(J,{hours:e})})}catch(e){return Promise.reject(e)}}runQuery(e,t){try{const r=this;return Promise.resolve(function(o,n){try{var i=Promise.resolve(r.context.chainId).then(function(o){return Promise.resolve(r.clients[o].request(e,t))})}catch(e){return n(e)}return i&&i.then?i.then(void 0,n):i}(0,function(o){return u.default.error(o),Promise.resolve(r.getBaseUrl()).then(function(r){throw new h(`Error running query: ${e}. Variables: ${JSON.stringify(t)}. API: ${r}. Inner Error: ${o}`)})}))}catch(e){return Promise.reject(e)}}}const X=function(e){return Promise.resolve(te()).then(function({ajv:t,validate:r}){var o;return{result:!!r(e),errors:null!==(o=t.errors)&&void 0!==o?o:void 0}})},ee=function(e){try{const t=1,r=112,o=18,n=32,i=function(e){const t=e.match(/.{1,2}/g);if(t)return new Uint8Array(t.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!i)return Promise.resolve();const s=Uint8Array.from([t,r,o,n,...i]);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:e}){return e.decode(s).toV0().toString()})}catch(e){return Promise.reject(e)}},te=function(){try{function e(){return{ajv:oe,validate:re}}oe||(oe=new l.default);const t=function(){if(!re)return Promise.resolve(Promise.resolve().then(function(){return require("./appData.schema-d44994e0.js")})).then(function(e){re=oe.compile(e)})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(r){return Promise.reject(r)}};let re,oe;class ne{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},t="CowSwap"){return{version:"0.1.0",appCode:t,metadata:{...e}}}decodeAppData(e){try{return Promise.resolve(function(t,r){try{var o=Promise.resolve(ee(e)).then(function(e){if(!e)throw new h("Error getting serialized CID");return function(e,t="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:r}){return Promise.resolve(r(`${t}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})}catch(e){return r(e)}return o&&o.then?o.then(void 0,r):o}(0,function(e){const t=e;throw u.default.error("Error decoding AppData:",t),new h("Error decoding AppData: "+t.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:t}){const{digest:r}=t.parse(e).multihash;return`0x${Buffer.from(r).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(ee(e)).then(function(e){if(!e)throw new h("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const t=this;return Promise.resolve(function(e,{uri:t,pinataApiKey:r="",pinataApiSecret:o=""}){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:n}){if(!r||!o)throw new h("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}});return Promise.resolve(n(`${t}/pinning/pinJSONToIPFS`,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:r,pinata_secret_api_key:o}})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error(t.error.details||t.error);return t})})})}catch(e){return Promise.reject(e)}}(e,t.context.ipfs)).then(function({IpfsHash:e}){return t.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var ie=0;function se(e){return"__private_"+ie+++"_"+e}function ae(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}const ue={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var ce,de,le,he,pe,me,fe,ge,Ee,Te,ve,ye,Pe,Ie,Ae,we,Ne,Se,ke=/*#__PURE__*/se("context"),De=/*#__PURE__*/se("chainId");class Oe{constructor(e,t){Object.defineProperty(this,ke,{writable:!0,value:void 0}),Object.defineProperty(this,De,{writable:!0,value:void 0}),ae(this,De)[De]=this.updateChainId(e),ae(this,ke)[ke]={...ue,...t}}updateChainId(e){if(!exports.SupportedChainId[e])throw new h(`Invalid chainId: ${e}`);return u.default.debug(m,`Updating chainId to: ${e}`),ae(this,De)[De]=e,e}get chainId(){const e=this;var t;const r=null==(t=ae(this,ke)[ke].signer)?void 0:t.provider;return r?(u.default.debug(m,"Getting chainId from provider"),function(){try{return Promise.resolve(r.getNetwork()).then(function(t){const r=t.chainId;return r!==ae(e,De)[De]&&(u.default.debug(m,`ChainId mismatch: Provider's chainId: ${r} vs Context's chainId: ${ae(e,De)[De]}. Updating Context's chainId`),e.updateChainId(r)),r})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ae(this,De)[De])}get appDataHash(){var e;return null!==(e=ae(this,ke)[ke].appDataHash)&&void 0!==e?e:ue.appDataHash}get isDevEnvironment(){var e;return null!==(e=ae(this,ke)[ke].isDevEnvironment)&&void 0!==e?e:ue.isDevEnvironment}get signer(){return ae(this,ke)[ke].signer}get ipfs(){var e;return null!==(e=ae(this,ke)[ke].ipfs)&&void 0!==e?e:ue.ipfs}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(ce||(ce={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(de||(de={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(le||(le={})),function(e){e.Asc="asc",e.Desc="desc"}(he||(he={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(pe||(pe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(me||(me={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(fe||(fe={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ge||(ge={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Ee||(Ee={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Te||(Te={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(ye||(ye={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Pe||(Pe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ie||(Ie={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Ae||(Ae={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(we||(we={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(Ne||(Ne={})),function(e){e.Allow="allow",e.Deny="deny"}(Se||(Se={}));var _e={__proto__:null,get Bundle_OrderBy(){return ce},get DailyTotal_OrderBy(){return de},get HourlyTotal_OrderBy(){return le},get OrderDirection(){return he},get Order_OrderBy(){return pe},get PairDaily_OrderBy(){return me},get PairHourly_OrderBy(){return fe},get Pair_OrderBy(){return ge},get Settlement_OrderBy(){return Ee},get TokenDailyTotal_OrderBy(){return Te},get TokenHourlyTotal_OrderBy(){return ve},get TokenTradingEvent_OrderBy(){return ye},get Token_OrderBy(){return Pe},get Total_OrderBy(){return Ie},get Trade_OrderBy(){return Ae},get UniswapPool_OrderBy(){return we},get User_OrderBy(){return Ne},get _SubgraphErrorPolicy_(){return Se}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=g,exports.CowError=h,exports.CowSdk=class{constructor(e,t={},r={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=X,this.context=new Oe(e,{...t}),this.cowApi=new Q(this.context),this.cowSubgraphApi=new z(this.context),this.metadataApi=new ne(this.context),u.default.setLevel(r.loglevel||"error")}signOrder(e){try{const t=this,r=t._checkSigner();return Promise.resolve(t.context.chainId).then(function(o){return function(e,t,r){return v({order:e,chainId:t},P,r)}({...e,appData:t.context.appDataHash},o,r)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const t=this,r=t._checkSigner();return Promise.resolve(t.context.chainId).then(function(t){return function(e,t,r){return v({orderId:e,chainId:t},y,r)}(e,t,r)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new h("No signer available");return e}},exports.GraphQL=_e,exports.Token=V;
`,Z={[exports.SupportedChainId.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[exports.SupportedChainId.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class z{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[exports.SupportedChainId.MAINNET]:new o.GraphQLClient(Z[exports.SupportedChainId.MAINNET],{fetch:c.default}),[exports.SupportedChainId.RINKEBY]:new o.GraphQLClient(Z[exports.SupportedChainId.RINKEBY],{fetch:c.default}),[exports.SupportedChainId.GNOSIS_CHAIN]:new o.GraphQLClient(Z[exports.SupportedChainId.GNOSIS_CHAIN],{fetch:c.default})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return Z[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){return u.default.debug(`[subgraph:${e.API_NAME}] Get totals for:`,t),Promise.resolve(e.runQuery(Y)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} days volume for:`,r),t.runQuery(W,{days:e})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return u.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} hours volume for:`,r),t.runQuery(J,{hours:e})})}catch(e){return Promise.reject(e)}}runQuery(e,t){try{const r=this;return Promise.resolve(function(n,o){try{var i=Promise.resolve(r.context.chainId).then(function(n){return Promise.resolve(r.clients[n].request(e,t))})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(n){return u.default.error(n),Promise.resolve(r.getBaseUrl()).then(function(r){throw new h(`Error running query: ${e}. Variables: ${JSON.stringify(t)}. API: ${r}. Inner Error: ${n}`)})}))}catch(e){return Promise.reject(e)}}}const X=function(e){return Promise.resolve(te()).then(function({ajv:t,validate:r}){var n;return{result:!!r(e),errors:null!==(n=t.errors)&&void 0!==n?n:void 0}})},ee=function(e){try{const t=1,r=112,n=18,o=32,i=function(e){const t=e.match(/.{1,2}/g);if(t)return new Uint8Array(t.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!i)return Promise.resolve();const s=Uint8Array.from([t,r,n,o,...i]);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:e}){return e.decode(s).toV0().toString()})}catch(e){return Promise.reject(e)}},te=function(){try{function e(){return{ajv:ne,validate:re}}ne||(ne=new l.default);const t=function(){if(!re)return Promise.resolve(Promise.resolve().then(function(){return require("./appData.schema-d44994e0.js")})).then(function(e){re=ne.compile(e)})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(r){return Promise.reject(r)}};let re,ne;class oe{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},t="CowSwap"){return{version:"0.1.0",appCode:t,metadata:{...e}}}decodeAppData(e){try{return Promise.resolve(function(t,r){try{var n=Promise.resolve(ee(e)).then(function(e){if(!e)throw new h("Error getting serialized CID");return function(e,t="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:r}){return Promise.resolve(r(`${t}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})}catch(e){return r(e)}return n&&n.then?n.then(void 0,r):n}(0,function(e){const t=e;throw u.default.error("Error decoding AppData:",t),new h("Error decoding AppData: "+t.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("multiformats/cid"))})).then(function({CID:t}){const{digest:r}=t.parse(e).multihash;return`0x${Buffer.from(r).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(ee(e)).then(function(e){if(!e)throw new h("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const t=this;return Promise.resolve(function(e,{uri:t,pinataApiKey:r="",pinataApiSecret:n=""}){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("cross-fetch"))})).then(function({default:o}){if(!r||!n)throw new h("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}});return Promise.resolve(o(`${t}/pinning/pinJSONToIPFS`,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:r,pinata_secret_api_key:n}})).then(function(e){return Promise.resolve(e.json()).then(function(t){if(200!==e.status)throw new Error(t.error.details||t.error);return t})})})}catch(e){return Promise.reject(e)}}(e,t.context.ipfs)).then(function({IpfsHash:e}){return t.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var ie=0;function se(e){return"__private_"+ie+++"_"+e}function ae(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}const ue={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var ce,de,le,he,pe,me,fe,ge,Ee,Te,ve,ye,Pe,Ie,Ae,we,Ne,Se,ke=/*#__PURE__*/se("context"),De=/*#__PURE__*/se("chainId");class Oe{constructor(e,t){Object.defineProperty(this,ke,{writable:!0,value:void 0}),Object.defineProperty(this,De,{writable:!0,value:void 0}),ae(this,De)[De]=this.updateChainId(e),ae(this,ke)[ke]={...ue,...t}}updateChainId(e){if(!exports.SupportedChainId[e])throw new h(`Invalid chainId: ${e}`);return u.default.debug(m,`Updating chainId to: ${e}`),ae(this,De)[De]=e,e}get chainId(){const e=this;var t;const r=null==(t=ae(this,ke)[ke].signer)?void 0:t.provider;return r?(u.default.debug(m,"Getting chainId from provider"),function(){try{return Promise.resolve(r.getNetwork()).then(function(t){const r=t.chainId;return r!==ae(e,De)[De]&&(u.default.debug(m,`ChainId mismatch: Provider's chainId: ${r} vs Context's chainId: ${ae(e,De)[De]}. Updating Context's chainId`),e.updateChainId(r)),r})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ae(this,De)[De])}get appDataHash(){var e;return null!==(e=ae(this,ke)[ke].appDataHash)&&void 0!==e?e:ue.appDataHash}get isDevEnvironment(){var e;return null!==(e=ae(this,ke)[ke].isDevEnvironment)&&void 0!==e?e:ue.isDevEnvironment}get signer(){return ae(this,ke)[ke].signer}get ipfs(){var e;return null!==(e=ae(this,ke)[ke].ipfs)&&void 0!==e?e:ue.ipfs}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(ce||(ce={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(de||(de={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(le||(le={})),function(e){e.Asc="asc",e.Desc="desc"}(he||(he={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsSigned="isSigned",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(pe||(pe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(me||(me={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(fe||(fe={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ge||(ge={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Ee||(Ee={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Te||(Te={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(ye||(ye={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Pe||(Pe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ie||(Ie={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Ae||(Ae={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(we||(we={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(Ne||(Ne={})),function(e){e.Allow="allow",e.Deny="deny"}(Se||(Se={}));var _e={__proto__:null,get Bundle_OrderBy(){return ce},get DailyTotal_OrderBy(){return de},get HourlyTotal_OrderBy(){return le},get OrderDirection(){return he},get Order_OrderBy(){return pe},get PairDaily_OrderBy(){return me},get PairHourly_OrderBy(){return fe},get Pair_OrderBy(){return ge},get Settlement_OrderBy(){return Ee},get TokenDailyTotal_OrderBy(){return Te},get TokenHourlyTotal_OrderBy(){return ve},get TokenTradingEvent_OrderBy(){return ye},get Token_OrderBy(){return Pe},get Total_OrderBy(){return Ie},get Trade_OrderBy(){return Ae},get UniswapPool_OrderBy(){return we},get User_OrderBy(){return Ne},get _SubgraphErrorPolicy_(){return Se}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=g,exports.CowError=h,exports.CowSdk=class{constructor(e,t={},r={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=X,this.context=new Oe(e,{...t}),this.cowApi=new Q(this.context),this.cowSubgraphApi=new z(this.context),this.metadataApi=new oe(this.context),u.default.setLevel(r.loglevel||"error")}signOrder(e){try{const t=this,r=t._checkSigner();return Promise.resolve(t.context.chainId).then(function(n){return function(e,t,r){return v({order:e,chainId:t},P,r)}({...e,appData:t.context.appDataHash},n,r)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const t=this,r=t._checkSigner();return Promise.resolve(t.context.chainId).then(function(t){return function(e,t,r){return v({orderId:e,chainId:t},y,r)}(e,t,r)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new h("No signer available");return e}},exports.GraphQL=_e,exports.Token=V;
//# sourceMappingURL=index.js.map

@@ -28,3 +28,3 @@ import e from"loglevel";import t from"cross-fetch";import{IntChainIdTypedDataV4Signer as r,TypedDataV3Signer as o,SigningScheme as n,domain as i,signOrder as a,signOrderCancellation as s,OrderKind as c}from"@gnosis.pm/gp-v2-contracts";export{OrderKind}from"@gnosis.pm/gp-v2-contracts";import d from"@gnosis.pm/gp-v2-contracts/networks.json";import{gql as u,GraphQLClient as l}from"graphql-request";import h from"ajv";function p(){return p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},p.apply(this,arguments)}var m=0;function f(e){return"__private_"+m+++"_"+e}function g(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}class E extends Error{constructor(e,t){super(e),this.error_code=void 0,this.error_code=t}}function T(e){if(!e)return"";const t=new URLSearchParams;for(const r of Object.keys(e)){const o=e[r];o&&t.append(r,o)}const r=t.toString();return r?`?${r}`:""}const y="cow-sdk:";var w;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GNOSIS_CHAIN=100]="GNOSIS_CHAIN"}(w||(w={}));const A=[w.MAINNET,w.RINKEBY,w.GNOSIS_CHAIN],{GPv2Settlement:I}=d,N={[w.MAINNET]:I[w.MAINNET].address,[w.RINKEBY]:I[w.RINKEBY].address,[w.GNOSIS_CHAIN]:I[w.GNOSIS_CHAIN].address},v=/eth_signTypedData_v4 does not exist/i,k=/eth_signTypedData_v3 does not exist/i,D=/RPC request failed/i,_=/provided chainid .* must match the active chainid/i,O=new Map([[n.EIP712,{libraryValue:0,apiValue:"eip712"}],[n.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[n.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[n.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function P(e){const t=O.get(e);if(void 0===t)throw new E("Unknown schema "+e);return t}function S(e){return P(e).apiValue}function U(e){return P(e).libraryValue}function R(e){const t=N[e];if(!t)throw new E("Unsupported network. Settlement contract is not deployed");return i(e,t)}async function b(e){const{chainId:t,signer:r,order:o,signingScheme:n}=e,i=R(t);return a(i,o,r,U(n))}async function x(e){const{chainId:t,signer:r,signingScheme:o,orderId:n}=e,i=R(t);return s(i,n,r,U(o))}async function C(t,i,a,s="v4"){const c="eth_sign"===s?n.ETHSIGN:n.EIP712;let d,u=null;try{switch(s){case"v3":d=new o(a);break;case"int_v4":d=new r(a);break;default:d=a}}catch(t){throw e.error(y,"Wallet not supported:",t),new E("Wallet not supported")}try{u=await i(p({},t,{signer:d,signingScheme:c}))}catch(r){if(void 0===(l=r).code&&void 0===l.message)throw e.error(y,r),r;if(-32601===r.code||D.test(r.message))switch(s){case"v4":return C(t,i,a,"v3");case"v3":return C(t,i,a,"eth_sign");default:throw r}else{if(_.test(r.message))return C(t,i,a,"int_v4");if(-32603===r.code)return C(t,i,a,"eth_sign");if(v.test(r.message))return C(t,i,a,"v3");if(k.test(r.message))return C(t,i,a,"eth_sign")}}var l;return{signature:u.data.toString(),signingScheme:c}}var L,H,F,V;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(L||(L={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Token pair selected has insufficient liquidity",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(H||(H={}));class B extends E{static async getErrorMessage(t,r){try{const r=await t.json();return r.errorType?B.apiErrorDetails[r.errorType]||r.errorType:(e.error(y,"Unknown reason for bad order submission",r),r.description)}catch(t){return e.error(y,"Error handling a 400 error. Likely a problem deserialising the JSON response"),function(t){switch(t){case"get":return H.UNHANDLED_GET_ERROR;case"create":return H.UNHANDLED_CREATE_ERROR;case"delete":return H.UNHANDLED_DELETE_ERROR;default:return e.error(y,"[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(r)}}static async getErrorFromStatusCode(t,r){switch(t.status){case 400:case 404:return this.getErrorMessage(t,r);case 403:return`The order cannot be ${"create"===r?"accepted":"cancelled"}. Your account is deny-listed.`;case 429:return`The order cannot be ${"create"===r?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`;default:return e.error(y,`[OperatorError::getErrorFromStatusCode] Error ${"create"===r?"creating":"cancelling"} the order, status code:`,t.status||"unknown"),`Error ${"create"===r?"creating":"cancelling"} the order`}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=H[e.errorType]}}B.apiErrorDetails=H,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(F||(F={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(V||(V={}));class $ extends E{static async getErrorMessage(t){try{const r=await t.json();return r.errorType?$.quoteErrorDetails[r.errorType]||r.errorType:(e.error(y,"Unknown reason for bad quote fetch",r),r.description)}catch(t){return e.error(y,"Error handling 400/404 error. Likely a problem deserialising the JSON response"),$.quoteErrorDetails.UNHANDLED_ERROR}}static async getErrorFromStatusCode(t){switch(t.status){case 400:case 404:return this.getErrorMessage(t);default:return e.error(y,"[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",t.status||"unknown"),"Error fetching quote"}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=$.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}$.quoteErrorDetails=V;class M{constructor(e,t){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=t}}const q={[w.MAINNET]:new M("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[w.RINKEBY]:new M("WETH","0xc778417E063141139Fce010982780140Aa0cD5Ab"),[w.GNOSIS_CHAIN]:new M("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},G={[w.MAINNET]:"ETH",[w.RINKEBY]:"ETH",[w.GNOSIS_CHAIN]:"XDAI"};function j(e,t){let r=e;return e===G[t]&&(r=q[t].address),r}const K={errorType:F.UNHANDLED_ERROR,description:V.UNHANDLED_ERROR},Y={errorType:L.UNHANDLED_CREATE_ERROR,description:H.UNHANDLED_CREATE_ERROR};async function Q(t,r){if(t.ok)return t.json();{const o=function(e){switch(null==e?void 0:e.errorType){case L.NotFound:case L.NoLiquidity:return{errorType:F.InsufficientLiquidity,description:V.InsufficientLiquidity};case L.SellAmountDoesNotCoverFee:return{errorType:F.FeeExceedsFrom,description:V.FeeExceedsFrom,data:null==e?void 0:e.data};case L.UnsupportedToken:return{errorType:F.UnsupportedToken,description:e.description};case L.SellAmountDoesNotCoverFee:return{errorType:F.FeeExceedsFrom,description:e.description};default:return{errorType:F.UNHANDLED_ERROR,description:V.UNHANDLED_ERROR}}}(await t.json()),n=new $(o);if(r){const{sellToken:t,buyToken:o}=r;e.error(y,`Error querying fee from API - sellToken: ${t}, buyToken: ${o}`)}throw n}}class W{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol",this.context=e}get DEFAULT_HEADERS(){return{"Content-Type":"application/json","X-AppId":this.context.appDataHash}}get API_BASE_URL(){return this.context.isDevEnvironment?{[w.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[w.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[w.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"}:{[w.MAINNET]:"https://api.cow.fi/mainnet/api",[w.RINKEBY]:"https://api.cow.fi/rinkeby/api",[w.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}get PROFILE_API_BASE_URL(){return this.context.isDevEnvironment?{[w.MAINNET]:"https://barn.api.cow.fi/affiliate/api"}:{[w.MAINNET]:"https://api.cow.fi/affiliate/api"}}async getProfileData(t){const r=await this.context.chainId;if(e.debug(y,`[api:${this.API_NAME}] Get profile data for`,r,t),r!==w.MAINNET)return e.info(y,"Profile data is only available for mainnet"),null;const o=await this.getProfile(`/profile/${t}`);if(o.ok)return o.json();{const t=await o.json();throw e.error(y,t),new E(null==t?void 0:t.description)}}async getTrades(t){const{owner:r,limit:o,offset:n}=t,i=T({owner:r,limit:o,offset:n}),a=await this.context.chainId;e.debug(y,"[util:operator] Get trades for",a,r,{limit:o,offset:n});try{const e=await this.get(`/trades${i}`);if(e.ok)return e.json();{const t=await e.json();throw new B(t)}}catch(t){if(e.error(y,"Error getting trades:",t),t instanceof B)throw t;throw new E("Error getting trades: "+t)}}async getOrders(t){const{owner:r,limit:o=1e3,offset:n=0}=t,i=T({limit:o,offset:n}),a=await this.context.chainId;e.debug(y,`[api:${this.API_NAME}] Get orders for `,a,r,o,n);try{const e=await this.get(`/account/${r}/orders/${i}`);if(e.ok)return e.json();{const t=await e.json();throw new B(t)}}catch(t){if(e.error(y,"Error getting orders information:",t),t instanceof B)throw t;throw new B(Y)}}async getTxOrders(t){const r=await this.context.chainId;e.debug(`[api:${this.API_NAME}] Get tx orders for `,r,t);try{const e=await this.get(`/transactions/${t}/orders`);if(e.ok)return e.json();{const t=await e.json();throw new B(t)}}catch(t){if(e.error("Error getting transaction orders information:",t),t instanceof B)throw t;throw new B(Y)}}async getOrder(t){const r=await this.context.chainId;e.debug(y,`[api:${this.API_NAME}] Get order for `,r,t);try{const e=await this.get(`/orders/${t}`);if(e.ok)return e.json();{const t=await e.json();throw new B(t)}}catch(t){if(e.error(y,"Error getting order information:",t),t instanceof B)throw t;throw new B(Y)}}async getPriceQuoteLegacy(t){const{baseToken:r,quoteToken:o,amount:n,kind:i}=t,a=await this.context.chainId;return e.debug(y,`[api:${this.API_NAME}] Get price from API`,t,"for",a),Q(await this.get(`/markets/${j(r,a)}-${j(o,a)}/${i}/${n}`).catch(t=>{throw e.error(y,"Error getting price quote:",t),new $(K)}))}async getQuote(e){const t=await this.context.chainId,r=this.mapNewToLegacyParams(e,t);return Q(await this.post("/quote",r))}async sendSignedOrderCancellation(t){const{cancellation:r,owner:o}=t,n=await this.context.chainId;e.debug(y,`[api:${this.API_NAME}] Delete signed order for network`,n,r);const i=await this.delete(`/orders/${r.orderUid}`,{signature:r.signature,signingScheme:S(r.signingScheme),from:o});if(!i.ok){const e=await B.getErrorFromStatusCode(i,"delete");throw new E(e)}e.debug(y,`[api:${this.API_NAME}] Cancelled order`,r.orderUid,n)}async sendOrder(t){const r=p({},t.order,{appData:this.context.appDataHash}),o=await this.context.chainId,{owner:n}=t;e.debug(y,`[api:${this.API_NAME}] Post signed order for network`,o,r);const i=await this.post("/orders",p({},r,{signingScheme:S(r.signingScheme),from:n}));if(!i.ok){const e=await B.getErrorFromStatusCode(i,"create");throw new E(e)}const a=await i.json();return e.debug(y,`[api:${this.API_NAME}] Success posting the signed order`,a),a}getOrderLink(e){return this.getApiBaseUrl()+`/orders/${e}`}mapNewToLegacyParams(e,t){const{amount:r,kind:o,userAddress:n,receiver:i,validTo:a,sellToken:s,buyToken:d}=e,u=n||"0x0000000000000000000000000000000000000000",l={sellToken:j(s,t),buyToken:j(d,t),from:u,receiver:i||u,appData:this.context.appDataHash,validTo:a,partiallyFillable:!1};return p(o===c.SELL?{kind:c.SELL,sellAmountBeforeFee:r}:{kind:c.BUY,buyAmountAfterFee:r},l)}async getApiBaseUrl(){const e=await this.context.chainId,t=this.API_BASE_URL[e];if(t)return t+"/v1";throw new E(`Unsupported Network. The ${this.API_NAME} API is not deployed in the Network `+e)}async getProfileApiBaseUrl(){const e=await this.context.chainId,t=this.PROFILE_API_BASE_URL[e];if(t)return t+"/v1";throw new E(`Unsupported Network. The ${this.API_NAME} API is not deployed in the Network `+e)}async fetch(e,r,o){const n=await this.getApiBaseUrl();return t(n+e,{headers:this.DEFAULT_HEADERS,method:r,body:void 0!==o?JSON.stringify(o):o})}async fetchProfile(e,r,o){const n=await this.getProfileApiBaseUrl();return t(n+e,{headers:this.DEFAULT_HEADERS,method:r,body:void 0!==o?JSON.stringify(o):o})}post(e,t){return this.fetch(e,"POST",t)}get(e){return this.fetch(e,"GET")}getProfile(e){return this.fetchProfile(e,"GET")}delete(e,t){return this.fetch(e,"DELETE",t)}}let J,Z,z,X=e=>e;const ee=u(J||(J=X`

}
`)),oe={[w.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[w.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[w.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class ne{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[w.MAINNET]:new l(oe[w.MAINNET],{fetch:t}),[w.RINKEBY]:new l(oe[w.RINKEBY],{fetch:t}),[w.GNOSIS_CHAIN]:new l(oe[w.GNOSIS_CHAIN],{fetch:t})}}async getBaseUrl(){const e=await this.context.chainId;return oe[e]}async getTotals(){const t=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get totals for:`,t),(await this.runQuery(ee)).totals[0]}async getLastDaysVolume(t){const r=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get last ${t} days volume for:`,r),this.runQuery(te,{days:t})}async getLastHoursVolume(t){const r=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get last ${t} hours volume for:`,r),this.runQuery(re,{hours:t})}async runQuery(t,r){try{const e=await this.context.chainId,o=this.clients[e];return await o.request(t,r)}catch(o){e.error(o);const n=await this.getBaseUrl();throw new E(`Error running query: ${t}. Variables: ${JSON.stringify(r)}. API: ${n}. Inner Error: ${o}`)}}}let ie,ae;async function se(){if(ae||(ae=new h),!ie){const e=await import("./appData.schema-fb2df827.js");ie=ae.compile(e)}return{ajv:ae,validate:ie}}async function ce(e){const t=function(e){const t=e.match(/.{1,2}/g);if(t)return new Uint8Array(t.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!t)return;const r=Uint8Array.from([1,112,18,32,...t]),{CID:o}=await import("multiformats/cid");return o.decode(r).toV0().toString()}async function de(e){var t;const{ajv:r,validate:o}=await se();return{result:!!o(e),errors:null!==(t=r.errors)&&void 0!==t?t:void 0}}class ue{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},t="CowSwap"){return{version:"0.1.0",appCode:t,metadata:p({},e)}}async decodeAppData(t){try{const e=await ce(t);if(!e)throw new E("Error getting serialized CID");return async function(e,t="https://gnosis.mypinata.cloud/ipfs"){const{default:r}=await import("cross-fetch"),o=await r(`${t}/${e}`);return await o.json()}(e)}catch(t){const r=t;throw e.error("Error decoding AppData:",r),new E("Error decoding AppData: "+r.message)}}async cidToAppDataHex(e){const{CID:t}=await import("multiformats/cid"),{digest:r}=t.parse(e).multihash;return`0x${Buffer.from(r).toString("hex")}`}async appDataHexToCid(e){const t=await ce(e);if(!t)throw new E("Error getting serialized CID");return t}async uploadMetadataDocToIpfs(e){const{IpfsHash:t}=await async function(e,{uri:t,pinataApiKey:r="",pinataApiSecret:o=""}){const{default:n}=await import("cross-fetch");if(!r||!o)throw new E("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}}),a=`${t}/pinning/pinJSONToIPFS`,s=await n(a,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:r,pinata_secret_api_key:o}}),c=await s.json();if(200!==s.status)throw new Error(c.error.details||c.error);return c}(e,this.context.ipfs);return this.cidToAppDataHex(t)}}const le={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var he,pe,me,fe,ge,Ee,Te,ye,we,Ae,Ie,Ne,ve,ke,De,_e,Oe,Pe,Se=/*#__PURE__*/f("context"),Ue=/*#__PURE__*/f("chainId");class Re{constructor(e,t){Object.defineProperty(this,Se,{writable:!0,value:void 0}),Object.defineProperty(this,Ue,{writable:!0,value:void 0}),g(this,Ue)[Ue]=this.updateChainId(e),g(this,Se)[Se]=p({},le,t)}updateChainId(t){if(!w[t])throw new E(`Invalid chainId: ${t}`);return e.debug(y,`Updating chainId to: ${t}`),g(this,Ue)[Ue]=t,t}get chainId(){var t,r=this;const o=null==(t=g(this,Se)[Se].signer)?void 0:t.provider;return o?(e.debug(y,"Getting chainId from provider"),async function(){const t=(await o.getNetwork()).chainId;return t!==g(r,Ue)[Ue]&&(e.debug(y,`ChainId mismatch: Provider's chainId: ${t} vs Context's chainId: ${g(r,Ue)[Ue]}. Updating Context's chainId`),r.updateChainId(t)),t}()):Promise.resolve(g(this,Ue)[Ue])}get appDataHash(){var e;return null!==(e=g(this,Se)[Se].appDataHash)&&void 0!==e?e:le.appDataHash}get isDevEnvironment(){var e;return null!==(e=g(this,Se)[Se].isDevEnvironment)&&void 0!==e?e:le.isDevEnvironment}get signer(){return g(this,Se)[Se].signer}get ipfs(){var e;return null!==(e=g(this,Se)[Se].ipfs)&&void 0!==e?e:le.ipfs}}class be{constructor(t,r={},o={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=de,this.context=new Re(t,p({},r)),this.cowApi=new W(this.context),this.cowSubgraphApi=new ne(this.context),this.metadataApi=new ue(this.context),e.setLevel(o.loglevel||"error")}async signOrder(e){const t=this._checkSigner(),r=await this.context.chainId;return async function(e,t,r){return C({order:e,chainId:t},b,r)}(p({},e,{appData:this.context.appDataHash}),r,t)}async signOrderCancellation(e){const t=this._checkSigner();return async function(e,t,r){return C({orderId:e,chainId:t},x,r)}(e,await this.context.chainId,t)}_checkSigner(e=this.context.signer){if(!e)throw new E("No signer available");return e}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(he||(he={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(pe||(pe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(me||(me={})),function(e){e.Asc="asc",e.Desc="desc"}(fe||(fe={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(ge||(ge={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ee||(Ee={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Te||(Te={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ye||(ye={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(we||(we={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ae||(Ae={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ie||(Ie={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(Ne||(Ne={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(ke||(ke={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(De||(De={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(_e||(_e={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(Oe||(Oe={})),function(e){e.Allow="allow",e.Deny="deny"}(Pe||(Pe={}));var xe={__proto__:null,get Bundle_OrderBy(){return he},get DailyTotal_OrderBy(){return pe},get HourlyTotal_OrderBy(){return me},get OrderDirection(){return fe},get Order_OrderBy(){return ge},get PairDaily_OrderBy(){return Ee},get PairHourly_OrderBy(){return Te},get Pair_OrderBy(){return ye},get Settlement_OrderBy(){return we},get TokenDailyTotal_OrderBy(){return Ae},get TokenHourlyTotal_OrderBy(){return Ie},get TokenTradingEvent_OrderBy(){return Ne},get Token_OrderBy(){return ve},get Total_OrderBy(){return ke},get Trade_OrderBy(){return De},get UniswapPool_OrderBy(){return _e},get User_OrderBy(){return Oe},get _SubgraphErrorPolicy_(){return Pe}};export{A as ALL_SUPPORTED_CHAIN_IDS,E as CowError,be as CowSdk,xe as GraphQL,w as SupportedChainId,M as Token};
`)),oe={[w.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[w.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[w.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class ne{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[w.MAINNET]:new l(oe[w.MAINNET],{fetch:t}),[w.RINKEBY]:new l(oe[w.RINKEBY],{fetch:t}),[w.GNOSIS_CHAIN]:new l(oe[w.GNOSIS_CHAIN],{fetch:t})}}async getBaseUrl(){const e=await this.context.chainId;return oe[e]}async getTotals(){const t=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get totals for:`,t),(await this.runQuery(ee)).totals[0]}async getLastDaysVolume(t){const r=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get last ${t} days volume for:`,r),this.runQuery(te,{days:t})}async getLastHoursVolume(t){const r=await this.context.chainId;return e.debug(`[subgraph:${this.API_NAME}] Get last ${t} hours volume for:`,r),this.runQuery(re,{hours:t})}async runQuery(t,r){try{const e=await this.context.chainId,o=this.clients[e];return await o.request(t,r)}catch(o){e.error(o);const n=await this.getBaseUrl();throw new E(`Error running query: ${t}. Variables: ${JSON.stringify(r)}. API: ${n}. Inner Error: ${o}`)}}}let ie,ae;async function se(){if(ae||(ae=new h),!ie){const e=await import("./appData.schema-fb2df827.js");ie=ae.compile(e)}return{ajv:ae,validate:ie}}async function ce(e){const t=function(e){const t=e.match(/.{1,2}/g);if(t)return new Uint8Array(t.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!t)return;const r=Uint8Array.from([1,112,18,32,...t]),{CID:o}=await import("multiformats/cid");return o.decode(r).toV0().toString()}async function de(e){var t;const{ajv:r,validate:o}=await se();return{result:!!o(e),errors:null!==(t=r.errors)&&void 0!==t?t:void 0}}class ue{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},t="CowSwap"){return{version:"0.1.0",appCode:t,metadata:p({},e)}}async decodeAppData(t){try{const e=await ce(t);if(!e)throw new E("Error getting serialized CID");return async function(e,t="https://gnosis.mypinata.cloud/ipfs"){const{default:r}=await import("cross-fetch"),o=await r(`${t}/${e}`);return await o.json()}(e)}catch(t){const r=t;throw e.error("Error decoding AppData:",r),new E("Error decoding AppData: "+r.message)}}async cidToAppDataHex(e){const{CID:t}=await import("multiformats/cid"),{digest:r}=t.parse(e).multihash;return`0x${Buffer.from(r).toString("hex")}`}async appDataHexToCid(e){const t=await ce(e);if(!t)throw new E("Error getting serialized CID");return t}async uploadMetadataDocToIpfs(e){const{IpfsHash:t}=await async function(e,{uri:t,pinataApiKey:r="",pinataApiSecret:o=""}){const{default:n}=await import("cross-fetch");if(!r||!o)throw new E("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}}),a=`${t}/pinning/pinJSONToIPFS`,s=await n(a,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:r,pinata_secret_api_key:o}}),c=await s.json();if(200!==s.status)throw new Error(c.error.details||c.error);return c}(e,this.context.ipfs);return this.cidToAppDataHex(t)}}const le={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var he,pe,me,fe,ge,Ee,Te,ye,we,Ae,Ie,Ne,ve,ke,De,_e,Oe,Pe,Se=/*#__PURE__*/f("context"),Ue=/*#__PURE__*/f("chainId");class Re{constructor(e,t){Object.defineProperty(this,Se,{writable:!0,value:void 0}),Object.defineProperty(this,Ue,{writable:!0,value:void 0}),g(this,Ue)[Ue]=this.updateChainId(e),g(this,Se)[Se]=p({},le,t)}updateChainId(t){if(!w[t])throw new E(`Invalid chainId: ${t}`);return e.debug(y,`Updating chainId to: ${t}`),g(this,Ue)[Ue]=t,t}get chainId(){var t,r=this;const o=null==(t=g(this,Se)[Se].signer)?void 0:t.provider;return o?(e.debug(y,"Getting chainId from provider"),async function(){const t=(await o.getNetwork()).chainId;return t!==g(r,Ue)[Ue]&&(e.debug(y,`ChainId mismatch: Provider's chainId: ${t} vs Context's chainId: ${g(r,Ue)[Ue]}. Updating Context's chainId`),r.updateChainId(t)),t}()):Promise.resolve(g(this,Ue)[Ue])}get appDataHash(){var e;return null!==(e=g(this,Se)[Se].appDataHash)&&void 0!==e?e:le.appDataHash}get isDevEnvironment(){var e;return null!==(e=g(this,Se)[Se].isDevEnvironment)&&void 0!==e?e:le.isDevEnvironment}get signer(){return g(this,Se)[Se].signer}get ipfs(){var e;return null!==(e=g(this,Se)[Se].ipfs)&&void 0!==e?e:le.ipfs}}class be{constructor(t,r={},o={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=de,this.context=new Re(t,p({},r)),this.cowApi=new W(this.context),this.cowSubgraphApi=new ne(this.context),this.metadataApi=new ue(this.context),e.setLevel(o.loglevel||"error")}async signOrder(e){const t=this._checkSigner(),r=await this.context.chainId;return async function(e,t,r){return C({order:e,chainId:t},b,r)}(p({},e,{appData:this.context.appDataHash}),r,t)}async signOrderCancellation(e){const t=this._checkSigner();return async function(e,t,r){return C({orderId:e,chainId:t},x,r)}(e,await this.context.chainId,t)}_checkSigner(e=this.context.signer){if(!e)throw new E("No signer available");return e}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(he||(he={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(pe||(pe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(me||(me={})),function(e){e.Asc="asc",e.Desc="desc"}(fe||(fe={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsSigned="isSigned",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(ge||(ge={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ee||(Ee={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Te||(Te={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ye||(ye={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(we||(we={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ae||(Ae={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ie||(Ie={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(Ne||(Ne={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(ke||(ke={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(De||(De={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(_e||(_e={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(Oe||(Oe={})),function(e){e.Allow="allow",e.Deny="deny"}(Pe||(Pe={}));var xe={__proto__:null,get Bundle_OrderBy(){return he},get DailyTotal_OrderBy(){return pe},get HourlyTotal_OrderBy(){return me},get OrderDirection(){return fe},get Order_OrderBy(){return ge},get PairDaily_OrderBy(){return Ee},get PairHourly_OrderBy(){return Te},get Pair_OrderBy(){return ye},get Settlement_OrderBy(){return we},get TokenDailyTotal_OrderBy(){return Ae},get TokenHourlyTotal_OrderBy(){return Ie},get TokenTradingEvent_OrderBy(){return Ne},get Token_OrderBy(){return ve},get Total_OrderBy(){return ke},get Trade_OrderBy(){return De},get UniswapPool_OrderBy(){return _e},get User_OrderBy(){return Oe},get _SubgraphErrorPolicy_(){return Pe}};export{A as ALL_SUPPORTED_CHAIN_IDS,E as CowError,be as CowSdk,xe as GraphQL,w as SupportedChainId,M as Token};
//# sourceMappingURL=index.modern.js.map

@@ -28,3 +28,3 @@ import e from"loglevel";import r from"cross-fetch";import{SigningScheme as t,IntChainIdTypedDataV4Signer as o,TypedDataV3Signer as n,domain as i,signOrderCancellation as s,signOrder as a,OrderKind as c}from"@gnosis.pm/gp-v2-contracts";export{OrderKind}from"@gnosis.pm/gp-v2-contracts";import u from"@gnosis.pm/gp-v2-contracts/networks.json";import{gql as d,GraphQLClient as l}from"graphql-request";import h from"ajv";class m extends Error{constructor(e,r){super(e),this.error_code=void 0,this.error_code=r}}function p(e){if(!e)return"";const r=new URLSearchParams;for(const t of Object.keys(e)){const o=e[t];o&&r.append(t,o)}const t=r.toString();return t?`?${t}`:""}const f="cow-sdk:";var g;!function(e){e[e.MAINNET=1]="MAINNET",e[e.RINKEBY=4]="RINKEBY",e[e.GNOSIS_CHAIN=100]="GNOSIS_CHAIN"}(g||(g={}));const E=[g.MAINNET,g.RINKEBY,g.GNOSIS_CHAIN],{GPv2Settlement:T}=u,v={[g.MAINNET]:T[g.MAINNET].address,[g.RINKEBY]:T[g.RINKEBY].address,[g.GNOSIS_CHAIN]:T[g.GNOSIS_CHAIN].address},y=function(r,i,s,a="v4"){try{let u;function c(e){return u?e:{signature:h.data.toString(),signingScheme:d}}const d="eth_sign"===a?t.ETHSIGN:t.EIP712;let l,h=null;try{switch(a){case"v3":l=new n(s);break;case"int_v4":l=new o(s);break;default:l=s}}catch(g){throw e.error(f,"Wallet not supported:",g),new m("Wallet not supported")}const p=function(e,t){try{var o=Promise.resolve(i({...r,signer:l,signingScheme:d})).then(function(e){h=e})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(t){if(void 0===(o=t).code&&void 0===o.message)throw e.error(f,t),t;var o;if(t.code===N||D.test(t.message))switch(a){case"v4":const e=y(r,i,s,"v3");return u=1,e;case"v3":const o=y(r,i,s,"eth_sign");return u=1,o;default:throw t}else{if(_.test(t.message)){const e=y(r,i,s,"int_v4");return u=1,e}if(t.code===I){const e=y(r,i,s,"eth_sign");return u=1,e}if(w.test(t.message)){const e=y(r,i,s,"v3");return u=1,e}if(k.test(t.message)){const e=y(r,i,s,"eth_sign");return u=1,e}}});return Promise.resolve(p&&p.then?p.then(c):c(p))}catch(E){return Promise.reject(E)}},P=function(e){try{const{chainId:r,signer:t,signingScheme:o,orderId:n}=e,i=b(r);return Promise.resolve(s(i,n,t,R(o)))}catch(e){return Promise.reject(e)}},A=function(e){try{const{chainId:r,signer:t,order:o,signingScheme:n}=e,i=b(r);return Promise.resolve(a(i,o,t,R(n)))}catch(e){return Promise.reject(e)}},I=-32603,N=-32601,w=/eth_signTypedData_v4 does not exist/i,k=/eth_signTypedData_v3 does not exist/i,D=/RPC request failed/i,_=/provided chainid .* must match the active chainid/i,O=new Map([[t.EIP712,{libraryValue:0,apiValue:"eip712"}],[t.ETHSIGN,{libraryValue:1,apiValue:"ethsign"}],[t.EIP1271,{libraryValue:2,apiValue:"eip1271"}],[t.PRESIGN,{libraryValue:3,apiValue:"presign"}]]);function S(e){const r=O.get(e);if(void 0===r)throw new m("Unknown schema "+e);return r}function U(e){return S(e).apiValue}function R(e){return S(e).libraryValue}function b(e){const r=v[e];if(!r)throw new m("Unsupported network. Settlement contract is not deployed");return i(e,r)}var x,C,L,H;!function(e){e.DuplicateOrder="DuplicateOrder",e.InvalidSignature="InvalidSignature",e.MissingOrderData="MissingOrderData",e.InsufficientValidTo="InsufficientValidTo",e.InsufficientAllowance="InsufficientAllowance",e.InsufficientBalance="InsufficientBalance",e.InsufficientFee="InsufficientFee",e.WrongOwner="WrongOwner",e.NotFound="NotFound",e.OrderNotFound="OrderNotFound",e.AlreadyCancelled="AlreadyCancelled",e.OrderFullyExecuted="OrderFullyExecuted",e.OrderExpired="OrderExpired",e.NoLiquidity="NoLiquidity",e.UnsupportedToken="UnsupportedToken",e.AmountIsZero="AmountIsZero",e.SellAmountDoesNotCoverFee="SellAmountDoesNotCoverFee",e.TransferEthToContract="TransferEthToContract",e.UNHANDLED_GET_ERROR="UNHANDLED_GET_ERROR",e.UNHANDLED_CREATE_ERROR="UNHANDLED_CREATE_ERROR",e.UNHANDLED_DELETE_ERROR="UNHANDLED_DELETE_ERROR"}(x||(x={})),function(e){e.DuplicateOrder="There was another identical order already submitted. Please try again.",e.InsufficientFee="The signed fee is insufficient. It's possible that is higher now due to a change in the gas price, ether price, or the sell token price. Please try again to get an updated fee quote.",e.InvalidSignature="The order signature is invalid. Check whether your Wallet app supports off-chain signing.",e.MissingOrderData="The order has missing information",e.InsufficientValidTo="The order you are signing is already expired. This can happen if you set a short expiration in the settings and waited too long before signing the transaction. Please try again.",e.InsufficientAllowance="The account doesn't have enough funds",e.InsufficientBalance="The account needs to approve the selling token in order to trade",e.WrongOwner="The signature is invalid.\n\nIt's likely that the signing method provided by your wallet doesn't comply with the standards required by CowSwap.\n\nCheck whether your Wallet app supports off-chain signing (EIP-712 or ETHSIGN).",e.NotFound="Token pair selected has insufficient liquidity",e.OrderNotFound="The order you are trying to cancel does not exist",e.AlreadyCancelled="Order is already cancelled",e.OrderFullyExecuted="Order is already filled",e.OrderExpired="Order is expired",e.NoLiquidity="Token pair selected has insufficient liquidity",e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.AmountIsZero="Amount is zero",e.SellAmountDoesNotCoverFee="Sell amount does not sufficiently cover the current fee",e.TransferEthToContract="Sending the native currency to smart contract wallets is not currently supported",e.UNHANDLED_GET_ERROR="Order fetch failed. This may be due to a server or network connectivity issue. Please try again later.",e.UNHANDLED_CREATE_ERROR="The order was not accepted by the network",e.UNHANDLED_DELETE_ERROR="The order cancellation was not accepted by the network"}(C||(C={}));class j extends m{static getErrorMessage(r,t){try{return Promise.resolve(function(t,o){try{var n=Promise.resolve(r.json()).then(function(r){return r.errorType?j.apiErrorDetails[r.errorType]||r.errorType:(e.error(f,"Unknown reason for bad order submission",r),r.description)})}catch(e){return o()}return n&&n.then?n.then(void 0,o):n}(0,function(){return e.error(f,"Error handling a 400 error. Likely a problem deserialising the JSON response"),function(r){switch(r){case"get":return C.UNHANDLED_GET_ERROR;case"create":return C.UNHANDLED_CREATE_ERROR;case"delete":return C.UNHANDLED_DELETE_ERROR;default:return e.error(f,"[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(t)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(r,t){try{const o=this;switch(r.status){case 400:case 404:return Promise.resolve(o.getErrorMessage(r,t));case 403:return Promise.resolve(`The order cannot be ${"create"===t?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===t?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return e.error(f,`[OperatorError::getErrorFromStatusCode] Error ${"create"===t?"creating":"cancelling"} the order, status code:`,r.status||"unknown"),Promise.resolve(`Error ${"create"===t?"creating":"cancelling"} the order`)}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="OperatorError",this.description=void 0,this.description=e.description,this.message=C[e.errorType]}}j.apiErrorDetails=C,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(L||(L={})),function(e){e.UnsupportedToken="One of the tokens you are trading is unsupported. Please read the FAQ for more info.",e.InsufficientLiquidity="Token pair selected has insufficient liquidity",e.FeeExceedsFrom='Current fee exceeds entered "from" amount',e.ZeroPrice="Quoted price is zero. This is likely due to a significant price difference between the two tokens. Please try increasing amounts.",e.UNHANDLED_ERROR="Quote fetch failed. This may be due to a server or network connectivity issue. Please try again later."}(H||(H={}));class F extends m{static getErrorMessage(r){try{return Promise.resolve(function(t,o){try{var n=Promise.resolve(r.json()).then(function(r){return r.errorType?F.quoteErrorDetails[r.errorType]||r.errorType:(e.error(f,"Unknown reason for bad quote fetch",r),r.description)})}catch(e){return o()}return n&&n.then?n.then(void 0,o):n}(0,function(){return e.error(f,"Error handling 400/404 error. Likely a problem deserialising the JSON response"),F.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(r){try{const t=this;switch(r.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(r));default:return e.error(f,"[QuoteError::getErrorFromStatusCode] Error fetching quote, status code:",r.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){super(e.description,e.errorType),this.name="QuoteErrorObject",this.description=void 0,this.data=void 0,this.description=e.description,this.message=F.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}F.quoteErrorDetails=H;class V{constructor(e,r){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=r}}const B={[g.MAINNET]:new V("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[g.RINKEBY]:new V("WETH","0xc778417E063141139Fce010982780140Aa0cD5Ab"),[g.GNOSIS_CHAIN]:new V("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},$={[g.MAINNET]:"ETH",[g.RINKEBY]:"ETH",[g.GNOSIS_CHAIN]:"XDAI"};function M(e,r){let t=e;return e===$[r]&&(t=B[r].address),t}function q(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}const G=function(r,t){try{return r.ok?Promise.resolve(r.json()):Promise.resolve(r.json()).then(function(r){const o=function(e){switch(null==e?void 0:e.errorType){case x.NotFound:case x.NoLiquidity:return{errorType:L.InsufficientLiquidity,description:H.InsufficientLiquidity};case x.SellAmountDoesNotCoverFee:return{errorType:L.FeeExceedsFrom,description:H.FeeExceedsFrom,data:null==e?void 0:e.data};case x.UnsupportedToken:return{errorType:L.UnsupportedToken,description:e.description};case x.SellAmountDoesNotCoverFee:return{errorType:L.FeeExceedsFrom,description:e.description};default:return{errorType:L.UNHANDLED_ERROR,description:H.UNHANDLED_ERROR}}}(r),n=new F(o);if(t){const{sellToken:r,buyToken:o}=t;e.error(f,`Error querying fee from API - sellToken: ${r}, buyToken: ${o}`)}throw n})}catch(e){return Promise.reject(e)}},K={errorType:L.UNHANDLED_ERROR,description:H.UNHANDLED_ERROR},Y={errorType:x.UNHANDLED_CREATE_ERROR,description:C.UNHANDLED_CREATE_ERROR};class Q{constructor(e){this.context=void 0,this.API_NAME="CoW Protocol",this.context=e}get DEFAULT_HEADERS(){return{"Content-Type":"application/json","X-AppId":this.context.appDataHash}}get API_BASE_URL(){return this.context.isDevEnvironment?{[g.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[g.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[g.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"}:{[g.MAINNET]:"https://api.cow.fi/mainnet/api",[g.RINKEBY]:"https://api.cow.fi/rinkeby/api",[g.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}get PROFILE_API_BASE_URL(){return this.context.isDevEnvironment?{[g.MAINNET]:"https://barn.api.cow.fi/affiliate/api"}:{[g.MAINNET]:"https://api.cow.fi/affiliate/api"}}getProfileData(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(f,`[api:${t.API_NAME}] Get profile data for`,o,r),o!==g.MAINNET?(e.info(f,"Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${r}`)).then(function(r){return r.ok?r.json():Promise.resolve(r.json()).then(function(r){throw e.error(f,r),new m(null==r?void 0:r.description)})})})}catch(e){return Promise.reject(e)}}getTrades(r){try{const t=this,{owner:o,limit:n,offset:i}=r,s=p({owner:o,limit:n,offset:i});return Promise.resolve(t.context.chainId).then(function(r){return e.debug(f,"[util:operator] Get trades for",r,o,{limit:n,offset:i}),q(function(){return Promise.resolve(t.get(`/trades${s}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(r){if(e.error(f,"Error getting trades:",r),r instanceof j)throw r;throw new m("Error getting trades: "+r)})})}catch(e){return Promise.reject(e)}}getOrders(r){try{const t=this,{owner:o,limit:n=1e3,offset:i=0}=r,s=p({limit:n,offset:i});return Promise.resolve(t.context.chainId).then(function(r){return e.debug(f,`[api:${t.API_NAME}] Get orders for `,r,o,n,i),q(function(){return Promise.resolve(t.get(`/account/${o}/orders/${s}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(r){if(e.error(f,"Error getting orders information:",r),r instanceof j)throw r;throw new j(Y)})})}catch(e){return Promise.reject(e)}}getTxOrders(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(`[api:${t.API_NAME}] Get tx orders for `,o,r),q(function(){return Promise.resolve(t.get(`/transactions/${r}/orders`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(r){if(e.error("Error getting transaction orders information:",r),r instanceof j)throw r;throw new j(Y)})})}catch(e){return Promise.reject(e)}}getOrder(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(f,`[api:${t.API_NAME}] Get order for `,o,r),q(function(){return Promise.resolve(t.get(`/orders/${r}`)).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(r){if(e.error(f,"Error getting order information:",r),r instanceof j)throw r;throw new j(Y)})})}catch(e){return Promise.reject(e)}}getPriceQuoteLegacy(r){try{const t=this,{baseToken:o,quoteToken:n,amount:i,kind:s}=r;return Promise.resolve(t.context.chainId).then(function(a){return e.debug(f,`[api:${t.API_NAME}] Get price from API`,r,"for",a),Promise.resolve(t.get(`/markets/${M(o,a)}-${M(n,a)}/${s}/${i}`).catch(r=>{throw e.error(f,"Error getting price quote:",r),new F(K)})).then(G)})}catch(e){return Promise.reject(e)}}getQuote(e){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){const o=r.mapNewToLegacyParams(e,t);return Promise.resolve(r.post("/quote",o)).then(G)})}catch(e){return Promise.reject(e)}}sendSignedOrderCancellation(r){try{const t=this,{cancellation:o,owner:n}=r;return Promise.resolve(t.context.chainId).then(function(r){return e.debug(f,`[api:${t.API_NAME}] Delete signed order for network`,r,o),Promise.resolve(t.delete(`/orders/${o.orderUid}`,{signature:o.signature,signingScheme:U(o.signingScheme),from:n})).then(function(n){function i(n){e.debug(f,`[api:${t.API_NAME}] Cancelled order`,o.orderUid,r)}const s=function(){if(!n.ok)return Promise.resolve(j.getErrorFromStatusCode(n,"delete")).then(function(e){throw new m(e)})}();return s&&s.then?s.then(i):i()})})}catch(e){return Promise.reject(e)}}sendOrder(r){try{const t=this,o={...r.order,appData:t.context.appDataHash};return Promise.resolve(t.context.chainId).then(function(n){const{owner:i}=r;return e.debug(f,`[api:${t.API_NAME}] Post signed order for network`,n,o),Promise.resolve(t.post("/orders",{...o,signingScheme:U(o.signingScheme),from:i})).then(function(r){function o(o){return Promise.resolve(r.json()).then(function(r){return e.debug(f,`[api:${t.API_NAME}] Success posting the signed order`,r),r})}const n=function(){if(!r.ok)return Promise.resolve(j.getErrorFromStatusCode(r,"create")).then(function(e){throw new m(e)})}();return n&&n.then?n.then(o):o()})})}catch(e){return Promise.reject(e)}}getOrderLink(e){return this.getApiBaseUrl()+`/orders/${e}`}mapNewToLegacyParams(e,r){const{amount:t,kind:o,userAddress:n,receiver:i,validTo:s,sellToken:a,buyToken:u}=e,d=n||"0x0000000000000000000000000000000000000000",l={sellToken:M(a,r),buyToken:M(u,r),from:d,receiver:i||d,appData:this.context.appDataHash,validTo:s,partiallyFillable:!1};return o===c.SELL?{kind:c.SELL,sellAmountBeforeFee:t,...l}:{kind:c.BUY,buyAmountAfterFee:t,...l}}getApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(r){const t=e.API_BASE_URL[r];if(t)return t+"/v1";throw new m(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+r)})}catch(e){return Promise.reject(e)}}getProfileApiBaseUrl(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(r){const t=e.PROFILE_API_BASE_URL[r];if(t)return t+"/v1";throw new m(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+r)})}catch(e){return Promise.reject(e)}}fetch(e,t,o){try{const n=this;return Promise.resolve(n.getApiBaseUrl()).then(function(i){return r(i+e,{headers:n.DEFAULT_HEADERS,method:t,body:void 0!==o?JSON.stringify(o):o})})}catch(e){return Promise.reject(e)}}fetchProfile(e,t,o){try{const n=this;return Promise.resolve(n.getProfileApiBaseUrl()).then(function(i){return r(i+e,{headers:n.DEFAULT_HEADERS,method:t,body:void 0!==o?JSON.stringify(o):o})})}catch(e){return Promise.reject(e)}}post(e,r){return this.fetch(e,"POST",r)}get(e){return this.fetch(e,"GET")}getProfile(e){return this.fetchProfile(e,"GET")}delete(e,r){return this.fetch(e,"DELETE",r)}}const W=d`

}
`,z={[g.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[g.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[g.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class X{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[g.MAINNET]:new l(z[g.MAINNET],{fetch:r}),[g.RINKEBY]:new l(z[g.RINKEBY],{fetch:r}),[g.GNOSIS_CHAIN]:new l(z[g.GNOSIS_CHAIN],{fetch:r})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return z[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return e.debug(`[subgraph:${r.API_NAME}] Get totals for:`,t),Promise.resolve(r.runQuery(W)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(`[subgraph:${t.API_NAME}] Get last ${r} days volume for:`,o),t.runQuery(J,{days:r})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(`[subgraph:${t.API_NAME}] Get last ${r} hours volume for:`,o),t.runQuery(Z,{hours:r})})}catch(e){return Promise.reject(e)}}runQuery(r,t){try{const o=this;return Promise.resolve(function(e,n){try{var i=Promise.resolve(o.context.chainId).then(function(e){return Promise.resolve(o.clients[e].request(r,t))})}catch(e){return n(e)}return i&&i.then?i.then(void 0,n):i}(0,function(n){return e.error(n),Promise.resolve(o.getBaseUrl()).then(function(e){throw new m(`Error running query: ${r}. Variables: ${JSON.stringify(t)}. API: ${e}. Inner Error: ${n}`)})}))}catch(e){return Promise.reject(e)}}}const ee=function(e){return Promise.resolve(te()).then(function({ajv:r,validate:t}){var o;return{result:!!t(e),errors:null!==(o=r.errors)&&void 0!==o?o:void 0}})},re=function(e){try{const r=1,t=112,o=18,n=32,i=function(e){const r=e.match(/.{1,2}/g);if(r)return new Uint8Array(r.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!i)return Promise.resolve();const s=Uint8Array.from([r,t,o,n,...i]);return Promise.resolve(import("multiformats/cid")).then(function({CID:e}){return e.decode(s).toV0().toString()})}catch(e){return Promise.reject(e)}},te=function(){try{function e(){return{ajv:ne,validate:oe}}ne||(ne=new h);const r=function(){if(!oe)return Promise.resolve(import("./appData.schema-fb2df827.js")).then(function(e){oe=ne.compile(e)})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(t){return Promise.reject(t)}};let oe,ne;class ie{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},r="CowSwap"){return{version:"0.1.0",appCode:r,metadata:{...e}}}decodeAppData(r){try{return Promise.resolve(function(e,t){try{var o=Promise.resolve(re(r)).then(function(e){if(!e)throw new m("Error getting serialized CID");return function(e,r="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(import("cross-fetch")).then(function({default:t}){return Promise.resolve(t(`${r}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(r){const t=r;throw e.error("Error decoding AppData:",t),new m("Error decoding AppData: "+t.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(import("multiformats/cid")).then(function({CID:r}){const{digest:t}=r.parse(e).multihash;return`0x${Buffer.from(t).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(re(e)).then(function(e){if(!e)throw new m("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const r=this;return Promise.resolve(function(e,{uri:r,pinataApiKey:t="",pinataApiSecret:o=""}){try{return Promise.resolve(import("cross-fetch")).then(function({default:n}){if(!t||!o)throw new m("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}});return Promise.resolve(n(`${r}/pinning/pinJSONToIPFS`,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:t,pinata_secret_api_key:o}})).then(function(e){return Promise.resolve(e.json()).then(function(r){if(200!==e.status)throw new Error(r.error.details||r.error);return r})})})}catch(e){return Promise.reject(e)}}(e,r.context.ipfs)).then(function({IpfsHash:e}){return r.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var se=0;function ae(e){return"__private_"+se+++"_"+e}function ce(e,r){if(!Object.prototype.hasOwnProperty.call(e,r))throw new TypeError("attempted to use private field on non-instance");return e}const ue={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var de,le,he,me,pe,fe,ge,Ee,Te,ve,ye,Pe,Ae,Ie,Ne,we,ke,De,_e=/*#__PURE__*/ae("context"),Oe=/*#__PURE__*/ae("chainId");class Se{constructor(e,r){Object.defineProperty(this,_e,{writable:!0,value:void 0}),Object.defineProperty(this,Oe,{writable:!0,value:void 0}),ce(this,Oe)[Oe]=this.updateChainId(e),ce(this,_e)[_e]={...ue,...r}}updateChainId(r){if(!g[r])throw new m(`Invalid chainId: ${r}`);return e.debug(f,`Updating chainId to: ${r}`),ce(this,Oe)[Oe]=r,r}get chainId(){const r=this;var t;const o=null==(t=ce(this,_e)[_e].signer)?void 0:t.provider;return o?(e.debug(f,"Getting chainId from provider"),function(){try{return Promise.resolve(o.getNetwork()).then(function(t){const o=t.chainId;return o!==ce(r,Oe)[Oe]&&(e.debug(f,`ChainId mismatch: Provider's chainId: ${o} vs Context's chainId: ${ce(r,Oe)[Oe]}. Updating Context's chainId`),r.updateChainId(o)),o})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ce(this,Oe)[Oe])}get appDataHash(){var e;return null!==(e=ce(this,_e)[_e].appDataHash)&&void 0!==e?e:ue.appDataHash}get isDevEnvironment(){var e;return null!==(e=ce(this,_e)[_e].isDevEnvironment)&&void 0!==e?e:ue.isDevEnvironment}get signer(){return ce(this,_e)[_e].signer}get ipfs(){var e;return null!==(e=ce(this,_e)[_e].ipfs)&&void 0!==e?e:ue.ipfs}}class Ue{constructor(r,t={},o={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=ee,this.context=new Se(r,{...t}),this.cowApi=new Q(this.context),this.cowSubgraphApi=new X(this.context),this.metadataApi=new ie(this.context),e.setLevel(o.loglevel||"error")}signOrder(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(o){return function(e,r,t){return y({order:e,chainId:r},A,t)}({...e,appData:r.context.appDataHash},o,t)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(r){return function(e,r,t){return y({orderId:e,chainId:r},P,t)}(e,r,t)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new m("No signer available");return e}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(de||(de={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(le||(le={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(he||(he={})),function(e){e.Asc="asc",e.Desc="desc"}(me||(me={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(pe||(pe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(fe||(fe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ge||(ge={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ee||(Ee={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Te||(Te={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ye||(ye={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(Pe||(Pe={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ae||(Ae={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ie||(Ie={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Ne||(Ne={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(we||(we={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(ke||(ke={})),function(e){e.Allow="allow",e.Deny="deny"}(De||(De={}));var Re={__proto__:null,get Bundle_OrderBy(){return de},get DailyTotal_OrderBy(){return le},get HourlyTotal_OrderBy(){return he},get OrderDirection(){return me},get Order_OrderBy(){return pe},get PairDaily_OrderBy(){return fe},get PairHourly_OrderBy(){return ge},get Pair_OrderBy(){return Ee},get Settlement_OrderBy(){return Te},get TokenDailyTotal_OrderBy(){return ve},get TokenHourlyTotal_OrderBy(){return ye},get TokenTradingEvent_OrderBy(){return Pe},get Token_OrderBy(){return Ae},get Total_OrderBy(){return Ie},get Trade_OrderBy(){return Ne},get UniswapPool_OrderBy(){return we},get User_OrderBy(){return ke},get _SubgraphErrorPolicy_(){return De}};export{E as ALL_SUPPORTED_CHAIN_IDS,m as CowError,Ue as CowSdk,Re as GraphQL,g as SupportedChainId,V as Token};
`,z={[g.MAINNET]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow",[g.RINKEBY]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-rinkeby",[g.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class X{constructor(e){this.context=void 0,this.clients=void 0,this.API_NAME="CoW Protocol Subgraph",this.context=e,this.clients=this.createClients()}createClients(){return{[g.MAINNET]:new l(z[g.MAINNET],{fetch:r}),[g.RINKEBY]:new l(z[g.RINKEBY],{fetch:r}),[g.GNOSIS_CHAIN]:new l(z[g.GNOSIS_CHAIN],{fetch:r})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return z[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return e.debug(`[subgraph:${r.API_NAME}] Get totals for:`,t),Promise.resolve(r.runQuery(W)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(`[subgraph:${t.API_NAME}] Get last ${r} days volume for:`,o),t.runQuery(J,{days:r})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(r){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){return e.debug(`[subgraph:${t.API_NAME}] Get last ${r} hours volume for:`,o),t.runQuery(Z,{hours:r})})}catch(e){return Promise.reject(e)}}runQuery(r,t){try{const o=this;return Promise.resolve(function(e,n){try{var i=Promise.resolve(o.context.chainId).then(function(e){return Promise.resolve(o.clients[e].request(r,t))})}catch(e){return n(e)}return i&&i.then?i.then(void 0,n):i}(0,function(n){return e.error(n),Promise.resolve(o.getBaseUrl()).then(function(e){throw new m(`Error running query: ${r}. Variables: ${JSON.stringify(t)}. API: ${e}. Inner Error: ${n}`)})}))}catch(e){return Promise.reject(e)}}}const ee=function(e){return Promise.resolve(te()).then(function({ajv:r,validate:t}){var o;return{result:!!t(e),errors:null!==(o=r.errors)&&void 0!==o?o:void 0}})},re=function(e){try{const r=1,t=112,o=18,n=32,i=function(e){const r=e.match(/.{1,2}/g);if(r)return new Uint8Array(r.map(e=>parseInt(e,16)))}(e.replace(/(^0x)/,""));if(!i)return Promise.resolve();const s=Uint8Array.from([r,t,o,n,...i]);return Promise.resolve(import("multiformats/cid")).then(function({CID:e}){return e.decode(s).toV0().toString()})}catch(e){return Promise.reject(e)}},te=function(){try{function e(){return{ajv:ne,validate:oe}}ne||(ne=new h);const r=function(){if(!oe)return Promise.resolve(import("./appData.schema-fb2df827.js")).then(function(e){oe=ne.compile(e)})}();return Promise.resolve(r&&r.then?r.then(e):e())}catch(t){return Promise.reject(t)}};let oe,ne;class ie{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},r="CowSwap"){return{version:"0.1.0",appCode:r,metadata:{...e}}}decodeAppData(r){try{return Promise.resolve(function(e,t){try{var o=Promise.resolve(re(r)).then(function(e){if(!e)throw new m("Error getting serialized CID");return function(e,r="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(import("cross-fetch")).then(function({default:t}){return Promise.resolve(t(`${r}/${e}`)).then(function(e){return Promise.resolve(e.json())})})}catch(e){return Promise.reject(e)}}(e)})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(r){const t=r;throw e.error("Error decoding AppData:",t),new m("Error decoding AppData: "+t.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(import("multiformats/cid")).then(function({CID:r}){const{digest:t}=r.parse(e).multihash;return`0x${Buffer.from(t).toString("hex")}`})}catch(e){return Promise.reject(e)}}appDataHexToCid(e){try{return Promise.resolve(re(e)).then(function(e){if(!e)throw new m("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const r=this;return Promise.resolve(function(e,{uri:r,pinataApiKey:t="",pinataApiSecret:o=""}){try{return Promise.resolve(import("cross-fetch")).then(function({default:n}){if(!t||!o)throw new m("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData-affiliate"}});return Promise.resolve(n(`${r}/pinning/pinJSONToIPFS`,{method:"POST",body:i,headers:{"Content-Type":"application/json",pinata_api_key:t,pinata_secret_api_key:o}})).then(function(e){return Promise.resolve(e.json()).then(function(r){if(200!==e.status)throw new Error(r.error.details||r.error);return r})})})}catch(e){return Promise.reject(e)}}(e,r.context.ipfs)).then(function({IpfsHash:e}){return r.cidToAppDataHex(e)})}catch(e){return Promise.reject(e)}}}var se=0;function ae(e){return"__private_"+se+++"_"+e}function ce(e,r){if(!Object.prototype.hasOwnProperty.call(e,r))throw new TypeError("attempted to use private field on non-instance");return e}const ue={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{uri:"https://gnosis.mypinata.cloud/ipfs",apiKey:void 0,apiSecret:void 0}};var de,le,he,me,pe,fe,ge,Ee,Te,ve,ye,Pe,Ae,Ie,Ne,we,ke,De,_e=/*#__PURE__*/ae("context"),Oe=/*#__PURE__*/ae("chainId");class Se{constructor(e,r){Object.defineProperty(this,_e,{writable:!0,value:void 0}),Object.defineProperty(this,Oe,{writable:!0,value:void 0}),ce(this,Oe)[Oe]=this.updateChainId(e),ce(this,_e)[_e]={...ue,...r}}updateChainId(r){if(!g[r])throw new m(`Invalid chainId: ${r}`);return e.debug(f,`Updating chainId to: ${r}`),ce(this,Oe)[Oe]=r,r}get chainId(){const r=this;var t;const o=null==(t=ce(this,_e)[_e].signer)?void 0:t.provider;return o?(e.debug(f,"Getting chainId from provider"),function(){try{return Promise.resolve(o.getNetwork()).then(function(t){const o=t.chainId;return o!==ce(r,Oe)[Oe]&&(e.debug(f,`ChainId mismatch: Provider's chainId: ${o} vs Context's chainId: ${ce(r,Oe)[Oe]}. Updating Context's chainId`),r.updateChainId(o)),o})}catch(e){return Promise.reject(e)}}()):Promise.resolve(ce(this,Oe)[Oe])}get appDataHash(){var e;return null!==(e=ce(this,_e)[_e].appDataHash)&&void 0!==e?e:ue.appDataHash}get isDevEnvironment(){var e;return null!==(e=ce(this,_e)[_e].isDevEnvironment)&&void 0!==e?e:ue.isDevEnvironment}get signer(){return ce(this,_e)[_e].signer}get ipfs(){var e;return null!==(e=ce(this,_e)[_e].ipfs)&&void 0!==e?e:ue.ipfs}}class Ue{constructor(r,t={},o={}){this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.validateAppDataDocument=ee,this.context=new Se(r,{...t}),this.cowApi=new Q(this.context),this.cowSubgraphApi=new X(this.context),this.metadataApi=new ie(this.context),e.setLevel(o.loglevel||"error")}signOrder(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(o){return function(e,r,t){return y({order:e,chainId:r},A,t)}({...e,appData:r.context.appDataHash},o,t)})}catch(e){return Promise.reject(e)}}signOrderCancellation(e){try{const r=this,t=r._checkSigner();return Promise.resolve(r.context.chainId).then(function(r){return function(e,r,t){return y({orderId:e,chainId:r},P,t)}(e,r,t)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new m("No signer available");return e}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(de||(de={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(le||(le={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(he||(he={})),function(e){e.Asc="asc",e.Desc="desc"}(me||(me={})),function(e){e.Id="id",e.InvalidateTimestamp="invalidateTimestamp",e.IsSigned="isSigned",e.IsValid="isValid",e.Owner="owner",e.PresignTimestamp="presignTimestamp",e.Trades="trades",e.TradesTimestamp="tradesTimestamp"}(pe||(pe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(fe||(fe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(ge||(ge={})),function(e){e.Id="id",e.Token0="token0",e.Token1="token1",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ee||(Ee={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Te||(Te={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ve||(ve={})),function(e){e.AveragePrice="averagePrice",e.ClosePrice="closePrice",e.HigherPrice="higherPrice",e.Id="id",e.LowerPrice="lowerPrice",e.OpenPrice="openPrice",e.Timestamp="timestamp",e.Token="token",e.TotalTrades="totalTrades",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(ye||(ye={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(Pe||(Pe={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.Id="id",e.Name="name",e.NumberOfTrades="numberOfTrades",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol",e.TotalVolume="totalVolume",e.TotalVolumeEth="totalVolumeEth",e.TotalVolumeUsd="totalVolumeUsd"}(Ae||(Ae={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ie||(Ie={})),function(e){e.BuyAmount="buyAmount",e.BuyAmountEth="buyAmountEth",e.BuyAmountUsd="buyAmountUsd",e.BuyToken="buyToken",e.FeeAmount="feeAmount",e.GasPrice="gasPrice",e.Id="id",e.Order="order",e.SellAmount="sellAmount",e.SellAmountEth="sellAmountEth",e.SellAmountUsd="sellAmountUsd",e.SellToken="sellToken",e.Settlement="settlement",e.Timestamp="timestamp",e.TxHash="txHash"}(Ne||(Ne={})),function(e){e.Id="id",e.Liquidity="liquidity",e.Tick="tick",e.Token0="token0",e.Token0Price="token0Price",e.Token1="token1",e.Token1Price="token1Price",e.TotalValueLockedToken0="totalValueLockedToken0",e.TotalValueLockedToken1="totalValueLockedToken1"}(we||(we={})),function(e){e.Address="address",e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.IsSolver="isSolver",e.NumberOfTrades="numberOfTrades",e.OrdersPlaced="ordersPlaced",e.SolvedAmountEth="solvedAmountEth",e.SolvedAmountUsd="solvedAmountUsd",e.TradedAmountEth="tradedAmountEth",e.TradedAmountUsd="tradedAmountUsd"}(ke||(ke={})),function(e){e.Allow="allow",e.Deny="deny"}(De||(De={}));var Re={__proto__:null,get Bundle_OrderBy(){return de},get DailyTotal_OrderBy(){return le},get HourlyTotal_OrderBy(){return he},get OrderDirection(){return me},get Order_OrderBy(){return pe},get PairDaily_OrderBy(){return fe},get PairHourly_OrderBy(){return ge},get Pair_OrderBy(){return Ee},get Settlement_OrderBy(){return Te},get TokenDailyTotal_OrderBy(){return ve},get TokenHourlyTotal_OrderBy(){return ye},get TokenTradingEvent_OrderBy(){return Pe},get Token_OrderBy(){return Ae},get Total_OrderBy(){return Ie},get Trade_OrderBy(){return Ne},get UniswapPool_OrderBy(){return we},get User_OrderBy(){return ke},get _SubgraphErrorPolicy_(){return De}};export{E as ALL_SUPPORTED_CHAIN_IDS,m as CowError,Ue as CowSdk,Re as GraphQL,g as SupportedChainId,V as Token};
//# sourceMappingURL=index.module.js.map
{
"name": "@cowprotocol/cow-sdk",
"version": "0.0.9",
"version": "0.0.10",
"license": "(MIT OR Apache-2.0)",

@@ -60,2 +60,6 @@ "source": "src/index.ts",

"./setupTests.js"
],
"collectCoverageFrom": [
"src/**/*.{ts,tsx}",
"!src/api/cow/errors/*.{ts,tsx}"
]

@@ -71,2 +75,2 @@ },

]
}
}

@@ -187,18 +187,25 @@ <p align="center">

// Get Cow Protocol totals
const { totals } = await cowSdk.cowSubgraphApi.getTotals()
const { tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth } = totals
const { tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth } = await cowSdk.cowSubgraphApi.getTotals()
console.log({ tokens, orders, traders, settlements, volumeUsd, volumeEth, feesUsd, feesEth })
// Get last 24 hours volume in usd
const { hourlyTotals } = await cowSdk.cowSubgraphApi.getLastHoursVolume(24)
console.log(hourlyTotals)
// Get last week volume in usd
const { dailyTotals } = await cowSdk.cowSubgraphApi.getLastDaysVolume(7)
console.log(dailyTotals)
// Get the last 5 batches
const query = `
query LastBatches($n: Int!) {
settlements(orderBy: timestamp, orderDirection: desc, first: $n) {
txHash
timestamp
query LastBatches($n: Int!) {
settlements(orderBy: firstTradeTimestamp, orderDirection: desc, first: $n) {
txHash
firstTradeTimestamp
}
}
}
`
const variables = { n: 5 }
const response = await cowSdk.cowSubgraphApi.runQuery(query, variables)
console.log(response.data.settlements)
console.log(response)
```

@@ -205,0 +212,0 @@

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 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