@cowprotocol/cow-sdk 0.0.15 → 1.0.0-RC.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -103
- package/dist/CowSdk.d.ts +4 -0
- package/dist/api/0x/error/index.d.ts +21 -0
- package/dist/api/0x/index.d.ts +11 -0
- package/dist/api/0x/utils.d.ts +17 -0
- package/dist/api/base/index.d.ts +25 -0
- package/dist/api/cow/index.d.ts +4 -16
- package/dist/api/cow/types.d.ts +4 -1
- package/dist/api/cow-subgraph/graphql.d.ts +24 -2
- package/dist/api/metadata/index.d.ts +11 -5
- package/dist/api/metadata/types.d.ts +8 -21
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +4 -4
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +4 -4
- package/dist/index.module.js.map +1 -1
- package/dist/utils/appData.d.ts +3 -3
- package/dist/utils/context.d.ts +5 -9
- package/dist/utils/ipfs.d.ts +2 -2
- package/dist/utils/market.d.ts +16 -0
- package/package.json +2 -1
- package/dist/appData.schema-42d10730.js +0 -2
- package/dist/appData.schema-42d10730.js.map +0 -1
- package/dist/appData.schema-b8f018d7.js +0 -2
- package/dist/appData.schema-b8f018d7.js.map +0 -1
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Context } from '../../utils/context';
|
|
2
|
-
import {
|
|
2
|
+
import { AnyAppDataDocVersion, LatestAppDataDocVersion, IpfsHashInfo, GenerateAppDataDocParams } from './types';
|
|
3
3
|
export declare class MetadataApi {
|
|
4
4
|
context: Context;
|
|
5
5
|
constructor(context: Context);
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Creates an appDataDoc with the latest version format
|
|
8
|
+
*
|
|
9
|
+
* Without params creates a default minimum appData doc
|
|
10
|
+
* Optionally creates metadata docs
|
|
11
|
+
*/
|
|
12
|
+
generateAppDataDoc(params?: GenerateAppDataDocParams): LatestAppDataDocVersion;
|
|
13
|
+
decodeAppData(hash: string): Promise<void | AnyAppDataDocVersion>;
|
|
8
14
|
cidToAppDataHex(ipfsHash: string): Promise<string | void>;
|
|
9
15
|
appDataHexToCid(hash: string): Promise<string | void>;
|
|
10
16
|
/**
|
|
@@ -33,6 +39,6 @@ export declare class MetadataApi {
|
|
|
33
39
|
*
|
|
34
40
|
* @param appData
|
|
35
41
|
*/
|
|
36
|
-
calculateAppDataHash(appData:
|
|
37
|
-
uploadMetadataDocToIpfs(appDataDoc:
|
|
42
|
+
calculateAppDataHash(appData: AnyAppDataDocVersion): Promise<IpfsHashInfo | void>;
|
|
43
|
+
uploadMetadataDocToIpfs(appDataDoc: AnyAppDataDocVersion): Promise<string | void>;
|
|
38
44
|
}
|
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createAppDataDoc, createQuoteMetadata, createReferrerMetadata } from '@cowprotocol/app-data';
|
|
2
|
+
export { AnyAppDataDocVersion, LatestAppDataDocVersion } from '@cowprotocol/app-data';
|
|
3
|
+
export declare type GenerateAppDataDocParams = {
|
|
4
|
+
appDataParams?: Omit<Parameters<typeof createAppDataDoc>[0], 'metadata'>;
|
|
5
|
+
metadataParams?: {
|
|
6
|
+
referrerParams?: Parameters<typeof createReferrerMetadata>[0];
|
|
7
|
+
quoteParams?: Parameters<typeof createQuoteMetadata>[0];
|
|
8
|
+
};
|
|
3
9
|
};
|
|
4
|
-
export declare type ReferralMetadata = Metadata & {
|
|
5
|
-
address: string;
|
|
6
|
-
};
|
|
7
|
-
export declare type QuoteMetadata = Metadata & {
|
|
8
|
-
slippageBips: string;
|
|
9
|
-
};
|
|
10
|
-
export declare type MetadataDoc = {
|
|
11
|
-
referrer?: ReferralMetadata;
|
|
12
|
-
quote?: QuoteMetadata;
|
|
13
|
-
};
|
|
14
|
-
export declare type OptionalAppDataProperties = {
|
|
15
|
-
appCode?: string;
|
|
16
|
-
environment?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare type AppDataDoc = {
|
|
19
|
-
version: string;
|
|
20
|
-
metadata: MetadataDoc;
|
|
21
|
-
} & OptionalAppDataProperties;
|
|
22
10
|
export declare type IpfsHashInfo = {
|
|
23
11
|
/**
|
|
24
12
|
* IPFS's content identifier v0
|
|
@@ -31,4 +19,3 @@ export declare type IpfsHashInfo = {
|
|
|
31
19
|
*/
|
|
32
20
|
appDataHash: string;
|
|
33
21
|
};
|
|
34
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=require("loglevel"),t=require("cross-fetch"),r=require("@cowprotocol/contracts"),n=require("@cowprotocol/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 c=/*#__PURE__*/s(e),u=/*#__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.toString())}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.GOERLI=5]="GOERLI",f[f.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const v=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.RINKEBY,exports.SupportedChainId.GOERLI,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:g}=d.default,E={[exports.SupportedChainId.MAINNET]:g[exports.SupportedChainId.MAINNET].address,[exports.SupportedChainId.RINKEBY]:g[exports.SupportedChainId.RINKEBY].address,[exports.SupportedChainId.GOERLI]:g[exports.SupportedChainId.GOERLI].address,[exports.SupportedChainId.GNOSIS_CHAIN]:g[exports.SupportedChainId.GNOSIS_CHAIN].address},T=function(e,t,n,o="v4"){try{let s;function i(e){var t;return s?e:{signature:null==(t=d)?void 0:t.data.toString(),signingScheme:a}}const a="eth_sign"===o?r.SigningScheme.ETHSIGN:r.SigningScheme.EIP712;let u,d=null;try{switch(o){case"v3":u=new r.TypedDataV3Signer(n);break;case"int_v4":u=new r.IntChainIdTypedDataV4Signer(n);break;default:u=n}}catch(p){throw c.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:u,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 c.default.error(m,r),r;var i;if(r.code===A||N.test(r.message))switch(o){case"v4":const o=T(e,t,n,"v3");return s=1,o;case"v3":const i=T(e,t,n,"eth_sign");return s=1,i;default:throw r}else{if(k.test(r.message)){const r=T(e,t,n,"int_v4");return s=1,r}if(r.code===y){const r=T(e,t,n,"eth_sign");return s=1,r}if(w.test(r.message)){const r=T(e,t,n,"v3");return s=1,r}if(S.test(r.message)){const r=T(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)}},P=function(e){try{const{chainId:t,signer:n,signingScheme:o,orderId:i}=e,s=_(t);return Promise.resolve(r.signOrderCancellation(s,i,n,C(o)))}catch(e){return Promise.reject(e)}},I=function(e){try{const{chainId:t,signer:n,order:o,signingScheme:i}=e,s=_(t);return Promise.resolve(r.signOrder(s,o,n,C(i)))}catch(e){return Promise.reject(e)}},y=-32603,A=-32601,w=/eth_signTypedData_v4 does not exist/i,S=/eth_signTypedData_v3 does not exist/i,N=/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 x(e){return O(e).apiValue}function C(e){return O(e).libraryValue}function _(e){const t=E[e];if(!t)throw new h("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var b,R,U,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"}(b||(b={})),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"}(R||(R={}));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:(c.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 c.default.error(m,"Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return R.UNHANDLED_GET_ERROR;case"create":return R.UNHANDLED_CREATE_ERROR;case"delete":return R.UNHANDLED_DELETE_ERROR;default:return c.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 c.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=R[e.errorType]}}j.apiErrorDetails=R,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(U||(U={})),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:(c.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 c.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 c.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.GOERLI]:new V("WETH","0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"),[exports.SupportedChainId.GNOSIS_CHAIN]:new V("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},$={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.RINKEBY]:"ETH",[exports.SupportedChainId.GOERLI]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function G(e,t){let r=e;return e===$[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}function B(e){return e?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[exports.SupportedChainId.GOERLI]:"https://barn.api.cow.fi/goerli/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.GOERLI]:"https://api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}function M(e){return e?{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"}:{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}const K=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 b.NotFound:case b.NoLiquidity:return{errorType:U.InsufficientLiquidity,description:L.InsufficientLiquidity};case b.SellAmountDoesNotCoverFee:return{errorType:U.FeeExceedsFrom,description:L.FeeExceedsFrom,data:null==e?void 0:e.data};case b.UnsupportedToken:return{errorType:U.UnsupportedToken,description:e.description};case b.SellAmountDoesNotCoverFee:return{errorType:U.FeeExceedsFrom,description:e.description};default:return{errorType:U.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR}}}(e),n=new H(r);if(t){const{sellToken:e,buyToken:r}=t;c.default.error(m,`Error querying fee from API - sellToken: ${e}, buyToken: ${r}`)}throw n})}catch(e){return Promise.reject(e)}},Q={errorType:U.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR},Y={errorType:b.UNHANDLED_CREATE_ERROR,description:R.UNHANDLED_CREATE_ERROR};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 B(this.context.isDevEnvironment)}getProfileData(e,t={}){try{const r=this;function n(t){return c.default.debug(m,`[api:${r.API_NAME}] Get profile data for`,t,e),t!==exports.SupportedChainId.MAINNET?(c.default.info(m,"Profile data is only available for mainnet"),null):Promise.resolve(r.getProfile(`/profile/${e}`,{chainId:t,isDevEnvironment:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw c.default.error(m,e),new h(null==e?void 0:e.description)})})}const{chainId:o,isDevEnvironment:i}=t;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(s){return Promise.reject(s)}}getTrades(e,t={}){try{const r=this;function n(e){return c.default.debug(m,"[util:operator] Get trades for",e,{owner:s,orderId:a,limit:u,offset:d}),q(function(){return Promise.resolve(r.get(`/trades${l}`,{chainId:e,isDevEnvironment:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(c.default.error(m,"Error getting trades:",e),e instanceof j)throw e;throw new h("Error getting trades: "+e)})}const{chainId:o,isDevEnvironment:i=r.context.isDevEnvironment}=t,{owner:s,orderId:a,limit:u,offset:d}=e;if(s&&a)throw new h("Cannot specify both owner and orderId");const l=p({owner:s,orderUid:a,limit:u,offset:d});return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(f){return Promise.reject(f)}}getOrders(e,t={}){try{const r=this;function n(e){return c.default.debug(m,`[api:${r.API_NAME}] Get orders for `,e,s,a,u),q(function(){return Promise.resolve(r.get(`/account/${s}/orders/${d}`,{chainId:e,isDevEnvironment:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(c.default.error(m,"Error getting orders information:",e),e instanceof j)throw e;throw new j(Y)})}const{chainId:o,isDevEnvironment:i=r.context.isDevEnvironment}=t,{owner:s,limit:a=1e3,offset:u=0}=e,d=p({limit:a,offset:u});return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getTxOrders(e,t={}){try{const r=this;function n(t){return c.default.debug(`[api:${r.API_NAME}] Get tx orders for `,t,e),q(function(){return Promise.resolve(r.get(`/transactions/${e}/orders`,{chainId:t,isDevEnvironment:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(c.default.error("Error getting transaction orders information:",e),e instanceof j)throw e;throw new j(Y)})}const{chainId:o,isDevEnvironment:i}=t;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(s){return Promise.reject(s)}}getOrder(e,t={}){try{const r=this;function n(t){return c.default.debug(m,`[api:${r.API_NAME}] Get order for `,t,e),q(function(){return Promise.resolve(r.get(`/orders/${e}`,{chainId:t,isDevEnvironment:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new j(e)})})},function(e){if(c.default.error(m,"Error getting order information:",e),e instanceof j)throw e;throw new j(Y)})}const{chainId:o,isDevEnvironment:i}=t;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(s){return Promise.reject(s)}}getPriceQuoteLegacy(e,t={}){try{const r=this;function n(t){return c.default.debug(m,`[api:${r.API_NAME}] Get price from API`,e,"for",t),Promise.resolve(r.get(`/markets/${G(s,t)}-${G(a,t)}/${d}/${u}`,{chainId:t,isDevEnvironment:i}).catch(e=>{throw c.default.error(m,"Error getting price quote:",e),new H(Q)})).then(K)}const{chainId:o,isDevEnvironment:i}=t,{baseToken:s,quoteToken:a,amount:u,kind:d}=e;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(l){return Promise.reject(l)}}getQuote(e,t={}){try{const r=this;function n(t){const n=r.mapNewToLegacyParams(e,t);return Promise.resolve(r.post("/quote",n,{chainId:t,isDevEnvironment:i})).then(K)}const{chainId:o,isDevEnvironment:i}=t;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(s){return Promise.reject(s)}}sendSignedOrderCancellation(e,t={}){try{const r=this;function n(e){return c.default.debug(m,`[api:${r.API_NAME}] Delete signed order for network`,e,s),Promise.resolve(r.delete(`/orders/${s.orderUid}`,{signature:s.signature,signingScheme:x(s.signingScheme),from:a},{chainId:e,isDevEnvironment:i})).then(function(t){function n(t){c.default.debug(m,`[api:${r.API_NAME}] Cancelled order`,s.orderUid,e)}const o=function(){if(!t.ok)return Promise.resolve(j.getErrorFromStatusCode(t,"delete")).then(function(e){throw new h(e)})}();return o&&o.then?o.then(n):n()})}const{chainId:o,isDevEnvironment:i}=t,{cancellation:s,owner:a}=e;return Promise.resolve(o?n(o):Promise.resolve(r.context.chainId).then(n))}catch(u){return Promise.reject(u)}}sendOrder(e,t={}){try{const r=this;function n(t){const{owner:n}=e;return c.default.debug(m,`[api:${r.API_NAME}] Post signed order for network`,t,o),Promise.resolve(r.post("/orders",{...o,signingScheme:x(o.signingScheme),from:n},{chainId:t,isDevEnvironment:s})).then(function(e){function t(t){return Promise.resolve(e.json()).then(function(e){return c.default.debug(m,`[api:${r.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(t):t()})}const o={...e.order,appData:r.context.appDataHash},{chainId:i,isDevEnvironment:s}=t;return Promise.resolve(i?n(i):Promise.resolve(r.context.chainId).then(n))}catch(a){return Promise.reject(a)}}getOrderLink(e){try{return Promise.resolve(this.getApiBaseUrl()).then(function(t){return t+`/orders/${e}`})}catch(e){return Promise.reject(e)}}mapNewToLegacyParams(e,t){const{amount:n,kind:o,userAddress:i,receiver:s,validTo:a,sellToken:c,buyToken:u}=e,d=i||"0x0000000000000000000000000000000000000000",l={sellToken:G(c,t),buyToken:G(u,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)}}fetch(e,t,r,n){try{return Promise.resolve(u.default(r+e,{headers:this.DEFAULT_HEADERS,method:t,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}fetchProfile(e,t,r,n){try{return Promise.resolve(u.default(r+e,{headers:this.DEFAULT_HEADERS,method:t,body:void 0!==n?JSON.stringify(n):n}))}catch(e){return Promise.reject(e)}}post(e,t,r={}){return this.handleMethod(e,"POST",this.fetch.bind(this),B,r,t)}get(e,t={}){return this.handleMethod(e,"GET",this.fetch.bind(this),B,t)}getProfile(e,t={}){return this.handleMethod(e,"GET",this.fetchProfile.bind(this),M,t)}delete(e,t,r={}){return this.handleMethod(e,"DELETE",this.fetch.bind(this),B,r,t)}handleMethod(e,t,r,n,o={},i){try{const s=this;function a(n){let o;const s=function(){if(void 0!==u)return Promise.resolve(r(e,t,`${(u?l:d)[n]}/v1`,i)).then(function(e){o=e});{const s=q(function(){return Promise.resolve(r(e,t,`${d[n]}/v1`,i)).then(function(e){o=e})},function(){return Promise.resolve(r(e,t,`${l[n]}/v1`,i)).then(function(e){o=e})});if(s&&s.then)return s.then(function(){})}}();return s&&s.then?s.then(function(){return o}):o}const{chainId:c,isDevEnvironment:u}=o,d=n(!1),l=n(!0);return Promise.resolve(c?a(c):Promise.resolve(s.context.chainId).then(a))}catch(h){return Promise.reject(h)}}}const J=o.gql`
|
|
1
|
+
var e=require("loglevel"),r=require("@cowprotocol/contracts"),t=require("@cowprotocol/contracts/networks.json"),o=require("cross-fetch"),n=require("graphql-request"),i=require("@cowprotocol/app-data"),s=require("ajv");function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function c(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var d,u=/*#__PURE__*/a(e),l=/*#__PURE__*/a(t),h=/*#__PURE__*/a(o),p=/*#__PURE__*/a(s);class f extends Error{constructor(e,r){super(e),this.error_code=void 0,this.error_code=r}}function m(e){if(!e)return"";const r=new URLSearchParams;for(const t of Object.keys(e)){const o=e[t];o&&r.append(t,o.toString())}const t=r.toString();return t?`?${t}`:""}exports.SupportedChainId=void 0,(d=exports.SupportedChainId||(exports.SupportedChainId={}))[d.MAINNET=1]="MAINNET",d[d.RINKEBY=4]="RINKEBY",d[d.GOERLI=5]="GOERLI",d[d.GNOSIS_CHAIN=100]="GNOSIS_CHAIN";const v=[exports.SupportedChainId.MAINNET,exports.SupportedChainId.RINKEBY,exports.SupportedChainId.GOERLI,exports.SupportedChainId.GNOSIS_CHAIN],{GPv2Settlement:T}=l.default,g={[exports.SupportedChainId.MAINNET]:T[exports.SupportedChainId.MAINNET].address,[exports.SupportedChainId.RINKEBY]:T[exports.SupportedChainId.RINKEBY].address,[exports.SupportedChainId.GOERLI]:T[exports.SupportedChainId.GOERLI].address,[exports.SupportedChainId.GNOSIS_CHAIN]:T[exports.SupportedChainId.GNOSIS_CHAIN].address},P=function(e,t,o,n="v4"){try{let s;function i(e){var r;return s?e:{signature:null==(r=d)?void 0:r.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(h){throw u.default.error("cow-sdk:","Wallet not supported:",h),new f("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("cow-sdk:",r),r;var i;if(r.code===A||S.test(r.message))switch(n){case"v4":const n=P(e,t,o,"v3");return s=1,n;case"v3":const i=P(e,t,o,"eth_sign");return s=1,i;default:throw r}else{if(N.test(r.message)){const r=P(e,t,o,"int_v4");return s=1,r}if(r.code===y){const r=P(e,t,o,"eth_sign");return s=1,r}if(k.test(r.message)){const r=P(e,t,o,"v3");return s=1,r}if(w.test(r.message)){const r=P(e,t,o,"eth_sign");return s=1,r}}});return Promise.resolve(l&&l.then?l.then(i):i(l))}catch(p){return Promise.reject(p)}},I=function(e){try{const{chainId:t,signer:o,signingScheme:n,orderId:i}=e,s=D(t);return Promise.resolve(r.signOrderCancellation(s,i,o,C(n)))}catch(e){return Promise.reject(e)}},E=function(e){try{const{chainId:t,signer:o,order:n,signingScheme:i}=e,s=D(t);return Promise.resolve(r.signOrder(s,n,o,C(i)))}catch(e){return Promise.reject(e)}},y=-32603,A=-32601,k=/eth_signTypedData_v4 does not exist/i,w=/eth_signTypedData_v3 does not exist/i,S=/RPC request failed/i,N=/provided chainid .* must match the active chainid/i,O=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 x(e){const r=O.get(e);if(void 0===r)throw new f("Unknown schema "+e);return r}function _(e){return x(e).apiValue}function C(e){return x(e).libraryValue}function D(e){const t=g[e];if(!t)throw new f("Unsupported network. Settlement contract is not deployed");return r.domain(e,t)}var b,R,U,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"}(b||(b={})),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"}(R||(R={}));class H extends f{static getErrorMessage(e,r){try{return Promise.resolve(function(r,t){try{var o=Promise.resolve(e.json()).then(function(e){return e.errorType?H.apiErrorDetails[e.errorType]||e.errorType:(u.default.error("cow-sdk:","Unknown reason for bad order submission",e),e.description)})}catch(e){return t()}return o&&o.then?o.then(void 0,t):o}(0,function(){return u.default.error("cow-sdk:","Error handling a 400 error. Likely a problem deserialising the JSON response"),function(e){switch(e){case"get":return R.UNHANDLED_GET_ERROR;case"create":return R.UNHANDLED_CREATE_ERROR;case"delete":return R.UNHANDLED_DELETE_ERROR;default:return u.default.error("cow-sdk:","[OperatorError::_mapActionToErrorDetails] Uncaught error mapping error action type to server error. Please try again later."),"Something failed. Please try again later."}}(r)}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e,r){try{const t=this;switch(e.status){case 400:case 404:return Promise.resolve(t.getErrorMessage(e,r));case 403:return Promise.resolve(`The order cannot be ${"create"===r?"accepted":"cancelled"}. Your account is deny-listed.`);case 429:return Promise.resolve(`The order cannot be ${"create"===r?"accepted. Too many order placements":"cancelled. Too many order cancellations"}. Please, retry in a minute`);default:return u.default.error("cow-sdk:",`[OperatorError::getErrorFromStatusCode] Error ${"create"===r?"creating":"cancelling"} the order, status code:`,e.status||"unknown"),Promise.resolve(`Error ${"create"===r?"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=R[e.errorType]}}H.apiErrorDetails=R,function(e){e.UnsupportedToken="UnsupportedToken",e.InsufficientLiquidity="InsufficientLiquidity",e.FeeExceedsFrom="FeeExceedsFrom",e.ZeroPrice="ZeroPrice",e.UNHANDLED_ERROR="UNHANDLED_ERROR"}(U||(U={})),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 j extends f{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var o=Promise.resolve(e.json()).then(function(e){return e.errorType?j.quoteErrorDetails[e.errorType]||e.errorType:(u.default.error("cow-sdk:","Unknown reason for bad quote fetch",e),e.description)})}catch(e){return t()}return o&&o.then?o.then(void 0,t):o}(0,function(){return u.default.error("cow-sdk:","Error handling 400/404 error. Likely a problem deserialising the JSON response"),j.quoteErrorDetails.UNHANDLED_ERROR}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:case 404:return Promise.resolve(r.getErrorMessage(e));default:return u.default.error("cow-sdk:","[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=j.quoteErrorDetails[e.errorType],this.data=null==e?void 0:e.data}}j.quoteErrorDetails=L;class M{constructor(e,r){this.symbol=void 0,this.address=void 0,this.symbol=e,this.address=r}}const V={[exports.SupportedChainId.MAINNET]:new M("WETH","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),[exports.SupportedChainId.RINKEBY]:new M("WETH","0xc778417E063141139Fce010982780140Aa0cD5Ab"),[exports.SupportedChainId.GOERLI]:new M("WETH","0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6"),[exports.SupportedChainId.GNOSIS_CHAIN]:new M("WXDAI","0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d")},q={[exports.SupportedChainId.MAINNET]:"ETH",[exports.SupportedChainId.RINKEBY]:"ETH",[exports.SupportedChainId.GOERLI]:"ETH",[exports.SupportedChainId.GNOSIS_CHAIN]:"XDAI"};function F(e,r){let t=e;return e===q[r]&&(t=V[r].address),t}const $={"Content-Type":"application/json"};class G{constructor({context:e,name:r,getApiUrl:t,defaultHeaders:o=$,apiVersion:n="v1"}){this.context=void 0,this.API_NAME=void 0,this.API_VERSION=void 0,this.API_URL_GETTER=void 0,this.DEFAULT_HEADERS=void 0,this.context=e,this.API_NAME=r,this.API_VERSION=n,this.API_URL_GETTER=t,this.DEFAULT_HEADERS=o}getApiBaseUrl(){try{const e=this,r=arguments;return Promise.resolve(e.context.chainId).then(function(t){const o=e.API_URL_GETTER(...[].slice.call(r))[t];if(o)return o+"/"+e.API_VERSION;throw new f(`Unsupported Network. The ${e.API_NAME} API is not deployed in the Network `+t)})}catch(e){return Promise.reject(e)}}post(e,r,t={}){return this.handleMethod(e,"POST",this.fetch.bind(this),this.API_URL_GETTER,t,r)}get(e,r={}){return this.handleMethod(e,"GET",this.fetch.bind(this),this.API_URL_GETTER,r)}delete(e,r,t={}){return this.handleMethod(e,"DELETE",this.fetch.bind(this),this.API_URL_GETTER,t,r)}handleMethod(e,r,t,o,n={},i){try{const s=this;function a(n){let a;const c=function(){if(void 0!==d){const c=o(d);return Promise.resolve(t(e,r,`${c[n]}/${s.API_VERSION}`,i,u)).then(function(e){a=e})}{const o=function(o,c){try{var d=Promise.resolve(t(e,r,`${l[n]}/${s.API_VERSION}`,i,u)).then(function(e){a=e})}catch(e){return c()}return d&&d.then?d.then(void 0,c):d}(0,function(){return Promise.resolve(t(e,r,`${h[n]}/${s.API_VERSION}`,i,u)).then(function(e){a=e})});if(o&&o.then)return o.then(function(){})}}();return c&&c.then?c.then(function(){return a}):a}const{chainId:c,env:d,requestOptions:u}=n,l=o("prod"),h=o("staging");return Promise.resolve(c?a(c):Promise.resolve(s.context.chainId).then(a))}catch(p){return Promise.reject(p)}}fetch(e,r,t,o,n){try{return Promise.resolve(fetch(t+e,{headers:this.DEFAULT_HEADERS,...n,method:r,body:void 0!==o?JSON.stringify(o):o}))}catch(e){return Promise.reject(e)}}}function B(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}const K=function(e,r){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.json()).then(function(e){const t=function(e){switch(null==e?void 0:e.errorType){case b.NotFound:case b.NoLiquidity:return{errorType:U.InsufficientLiquidity,description:L.InsufficientLiquidity};case b.SellAmountDoesNotCoverFee:return{errorType:U.FeeExceedsFrom,description:L.FeeExceedsFrom,data:null==e?void 0:e.data};case b.UnsupportedToken:return{errorType:U.UnsupportedToken,description:e.description};case b.SellAmountDoesNotCoverFee:return{errorType:U.FeeExceedsFrom,description:e.description};default:return{errorType:U.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR}}}(e),o=new j(t);if(r){const{sellToken:e,buyToken:t}=r;u.default.error("cow-sdk:",`Error querying fee from API - sellToken: ${e}, buyToken: ${t}`)}throw o})}catch(e){return Promise.reject(e)}};function Q(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://barn.api.cow.fi/rinkeby/api",[exports.SupportedChainId.GOERLI]:"https://barn.api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/mainnet/api",[exports.SupportedChainId.RINKEBY]:"https://api.cow.fi/rinkeby/api",[exports.SupportedChainId.GOERLI]:"https://api.cow.fi/goerli/api",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.cow.fi/xdai/api"}}}function Y(e){switch(e){case"staging":return{[exports.SupportedChainId.MAINNET]:"https://barn.api.cow.fi/affiliate/api"};case"prod":return{[exports.SupportedChainId.MAINNET]:"https://api.cow.fi/affiliate/api"}}}const W={errorType:U.UNHANDLED_ERROR,description:L.UNHANDLED_ERROR},J={errorType:b.UNHANDLED_CREATE_ERROR,description:R.UNHANDLED_CREATE_ERROR};class Z extends G{constructor(e){super({context:e,name:"CoW Protocol",apiVersion:"v1",getApiUrl:Q})}getProfileData(e,r={}){try{const t=this;function o(r){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get profile data for`,r,e),r!==exports.SupportedChainId.MAINNET?(u.default.info("cow-sdk:","Profile data is only available for mainnet"),null):Promise.resolve(t.getProfile(`/profile/${e}`,{chainId:r,env:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw u.default.error("cow-sdk:",e),new f(null==e?void 0:e.description)})})}const{chainId:n,env:i}=r;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(s){return Promise.reject(s)}}getTrades(e,r={}){try{const t=this;function o(e){return u.default.debug("cow-sdk:","[util:operator] Get trades for",e,{owner:s,orderId:a,limit:c,offset:d}),B(function(){return Promise.resolve(t.get(`/trades${l}`,{chainId:e,env:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new H(e)})})},function(e){if(u.default.error("cow-sdk:","Error getting trades:",e),e instanceof H)throw e;throw new f("Error getting trades: "+e)})}const{chainId:n,env:i=t.context.env}=r,{owner:s,orderId:a,limit:c,offset:d}=e;if(s&&a)throw new f("Cannot specify both owner and orderId");const l=m({owner:s,orderUid:a,limit:c,offset:d});return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(h){return Promise.reject(h)}}getOrders(e,r={}){try{const t=this;function o(e){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get orders for `,e,s,a,c),B(function(){return Promise.resolve(t.get(`/account/${s}/orders/${d}`,{chainId:e,env:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new H(e)})})},function(e){if(u.default.error("cow-sdk:","Error getting orders information:",e),e instanceof H)throw e;throw new H(J)})}const{chainId:n,env:i=t.context.env}=r,{owner:s,limit:a=1e3,offset:c=0}=e,d=m({limit:a,offset:c});return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(l){return Promise.reject(l)}}getTxOrders(e,r={}){try{const t=this;function o(r){return u.default.debug(`[api:${t.API_NAME}] Get tx orders for `,r,e),B(function(){return Promise.resolve(t.get(`/transactions/${e}/orders`,{chainId:r,env:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new H(e)})})},function(e){if(u.default.error("Error getting transaction orders information:",e),e instanceof H)throw e;throw new H(J)})}const{chainId:n,env:i}=r;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(s){return Promise.reject(s)}}getOrder(e,r={}){try{const t=this;function o(r){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get order for `,r,e),B(function(){return Promise.resolve(t.get(`/orders/${e}`,{chainId:r,env:i})).then(function(e){return e.ok?e.json():Promise.resolve(e.json()).then(function(e){throw new H(e)})})},function(e){if(u.default.error("cow-sdk:","Error getting order information:",e),e instanceof H)throw e;throw new H(J)})}const{chainId:n,env:i}=r;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(s){return Promise.reject(s)}}getPriceQuoteLegacy(e,r={}){try{const t=this;function o(r){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Get price from API`,e,"for",r),Promise.resolve(t.get(`/markets/${F(s,r)}-${F(a,r)}/${d}/${c}`,{chainId:r,env:i}).catch(e=>{throw u.default.error("cow-sdk:","Error getting price quote:",e),new j(W)})).then(K)}const{chainId:n,env:i}=r,{baseToken:s,quoteToken:a,amount:c,kind:d}=e;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(l){return Promise.reject(l)}}getQuote(e,r={}){try{const t=this;function o(r){const o=t.mapNewToLegacyParams(e,r);return Promise.resolve(t.post("/quote",o,{chainId:r,env:i})).then(K)}const{chainId:n,env:i}=r;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(s){return Promise.reject(s)}}sendSignedOrderCancellation(e,r={}){try{const t=this;function o(e){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Delete signed order for network`,e,s),Promise.resolve(t.delete(`/orders/${s.orderUid}`,{signature:s.signature,signingScheme:_(s.signingScheme),from:a},{chainId:e,env:i})).then(function(r){function o(r){u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Cancelled order`,s.orderUid,e)}const n=function(){if(!r.ok)return Promise.resolve(H.getErrorFromStatusCode(r,"delete")).then(function(e){throw new f(e)})}();return n&&n.then?n.then(o):o()})}const{chainId:n,env:i}=r,{cancellation:s,owner:a}=e;return Promise.resolve(n?o(n):Promise.resolve(t.context.chainId).then(o))}catch(c){return Promise.reject(c)}}sendOrder(e,r={}){try{const t=this;function o(r){const{owner:o}=e;return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Post signed order for network`,r,n),Promise.resolve(t.post("/orders",{...n,signingScheme:_(n.signingScheme),from:o},{chainId:r,env:s})).then(function(e){function r(r){return Promise.resolve(e.json()).then(function(e){return u.default.debug("cow-sdk:",`[api:${t.API_NAME}] Success posting the signed order`,e),e})}const o=function(){if(!e.ok)return Promise.resolve(H.getErrorFromStatusCode(e,"create")).then(function(e){throw new f(e)})}();return o&&o.then?o.then(r):r()})}const n={...e.order,appData:t.context.appDataHash},{chainId:i,env:s}=r;return Promise.resolve(i?o(i):Promise.resolve(t.context.chainId).then(o))}catch(a){return Promise.reject(a)}}getOrderLink(e){try{return Promise.resolve(this.getApiBaseUrl()).then(function(r){return r+`/orders/${e}`})}catch(e){return Promise.reject(e)}}getProfile(e,r={}){return this.handleMethod(e,"GET",this.fetchProfile.bind(this),Y,r)}mapNewToLegacyParams(e,t){const{amount:o,kind:n,userAddress:i,receiver:s,validTo:a,sellToken:c,buyToken:d}=e,u=i||"0x0000000000000000000000000000000000000000",l={sellToken:F(c,t),buyToken:F(d,t),from:u,receiver:s||u,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(){return super.getApiBaseUrl(this.context.env)}fetchProfile(e,r,t,o){try{return Promise.resolve(fetch(t+e,{headers:this.DEFAULT_HEADERS,method:r,body:void 0!==o?JSON.stringify(o):o}))}catch(e){return Promise.reject(e)}}}const z=n.gql`
|
|
2
2
|
query Totals {
|
|
3
3
|
totals {
|
|
4
4
|
tokens
|
|
@@ -11,19 +11,19 @@ var e=require("loglevel"),t=require("cross-fetch"),r=require("@cowprotocol/contr
|
|
|
11
11
|
feesEth
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
`,
|
|
14
|
+
`,X=n.gql`
|
|
15
15
|
query LastDaysVolume($days: Int!) {
|
|
16
16
|
dailyTotals(orderBy: timestamp, orderDirection: desc, first: $days) {
|
|
17
17
|
timestamp
|
|
18
18
|
volumeUsd
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
`,
|
|
21
|
+
`,ee=n.gql`
|
|
22
22
|
query LastHoursVolume($hours: Int!) {
|
|
23
23
|
hourlyTotals(orderBy: timestamp, orderDirection: desc, first: $hours) {
|
|
24
24
|
timestamp
|
|
25
25
|
volumeUsd
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
`,X={[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.GOERLI]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-goerli",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class ee{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(X[exports.SupportedChainId.MAINNET],{fetch:u.default}),[exports.SupportedChainId.RINKEBY]:new o.GraphQLClient(X[exports.SupportedChainId.RINKEBY],{fetch:u.default}),[exports.SupportedChainId.GOERLI]:new o.GraphQLClient(X[exports.SupportedChainId.GOERLI],{fetch:u.default}),[exports.SupportedChainId.GNOSIS_CHAIN]:new o.GraphQLClient(X[exports.SupportedChainId.GNOSIS_CHAIN],{fetch:u.default})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return X[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(t){return c.default.debug(`[subgraph:${e.API_NAME}] Get totals for:`,t),Promise.resolve(e.runQuery(J)).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 c.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} days volume for:`,r),t.runQuery(Z,{days:e})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e){try{const t=this;return Promise.resolve(t.context.chainId).then(function(r){return c.default.debug(`[subgraph:${t.API_NAME}] Get last ${e} hours volume for:`,r),t.runQuery(z,{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 c.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 te=function(e){return Promise.resolve(ne()).then(function({ajv:t,validate:r}){return{result:!!r(e),errors:t.errors?t.errorsText(t.errors):void 0}})},re=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)}},ne=function(){try{function e(){return{ajv:ie,validate:oe}}ie||(ie=new l.default);const t=function(){if(!oe)return Promise.resolve(Promise.resolve().then(function(){return require("./appData.schema-42d10730.js")})).then(function(e){oe=ie.compile(e)})}();return Promise.resolve(t&&t.then?t.then(e):e())}catch(r){return Promise.reject(r)}};let oe,ie;function se(e,t){try{var r=e()}catch(e){return t(e)}return r&&r.then?r.then(void 0,t):r}const ae="CowSwap";class ce{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e={},t){const{appCode:r=ae,environment:n}=t||{};return{version:"0.4.0",appCode:r,environment:n,metadata:{...e}}}decodeAppData(e){try{return Promise.resolve(se(function(){return Promise.resolve(re(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)})},function(e){const t=e;throw c.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(re(e)).then(function(e){if(!e)throw new h("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}calculateAppDataHash(e){try{const t=this;return Promise.resolve(te(e)).then(function(r){if(null==r||!r.result)throw new h("Invalid appData provided",null==r?void 0:r.errors);return se(function(){return Promise.resolve(function(e){try{const t=JSON.stringify(e);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return a(require("ipfs-only-hash"))})).then(function({of:e}){return e(t,{cidVersion:0})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(t.cidToAppDataHex(e)).then(function(t){if(!t)throw new h(`Could not extract appDataHash from calculated cidV0 ${e}`);return{cidV0:e,appDataHash:t}})})},function(e){throw new h("Failed to calculate appDataHash",e.message)})})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const t=this;return Promise.resolve(function(e,{writeUri:t="https://api.pinata.cloud",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"}});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 ue=0;function de(e){return"__private_"+ue+++"_"+e}function le(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))throw new TypeError("attempted to use private field on non-instance");return e}const he={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",isDevEnvironment:!1,ipfs:{readUri:"https://gnosis.mypinata.cloud/ipfs",writeUri:"https://api.pinata.cloud",apiKey:void 0,apiSecret:void 0}};var pe,me,fe,ve,ge,Ee,Te,Pe,Ie,ye,Ae,we,Se,Ne,ke,De,Oe,xe,Ce,_e=/*#__PURE__*/de("context"),be=/*#__PURE__*/de("chainId");class Re{updateContext(e,t){this.setParams(t,e)}constructor(e,t){Object.defineProperty(this,_e,{writable:!0,value:{}}),Object.defineProperty(this,be,{writable:!0,value:exports.SupportedChainId.MAINNET}),this.setParams(e,t)}setParams(e,t){le(this,be)[be]=this.updateChainId(e),le(this,_e)[_e]={...he,...t,ipfs:{...he.ipfs,...t.ipfs}}}updateChainId(e){if(!exports.SupportedChainId[e])throw new h(`Invalid chainId: ${e}`);return c.default.debug(m,`Updating chainId to: ${e}`),le(this,be)[be]=e,e}get chainId(){const e=this;var t;const r=null==(t=le(this,_e)[_e].signer)?void 0:t.provider;return r?(c.default.debug(m,"Getting chainId from provider"),function(){try{return Promise.resolve(r.getNetwork()).then(function(t){const r=t.chainId;return r!==le(e,be)[be]&&(c.default.debug(m,`ChainId mismatch: Provider's chainId: ${r} vs Context's chainId: ${le(e,be)[be]}. Updating Context's chainId`),e.updateChainId(r)),r})}catch(e){return Promise.reject(e)}}()):Promise.resolve(le(this,be)[be])}get appDataHash(){var e;return null!==(e=le(this,_e)[_e].appDataHash)&&void 0!==e?e:he.appDataHash}get isDevEnvironment(){var e;return null!==(e=le(this,_e)[_e].isDevEnvironment)&&void 0!==e?e:he.isDevEnvironment}get signer(){return le(this,_e)[_e].signer}get ipfs(){var e;return null!==(e=le(this,_e)[_e].ipfs)&&void 0!==e?e:he.ipfs}}!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(pe||(pe={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",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.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(fe||(fe={})),function(e){e.Asc="asc",e.Desc="desc"}(ve||(ve={})),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.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",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.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Te||(Te={})),function(e){e.Id="id",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Pe||(Pe={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(Ie||(Ie={})),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.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.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(we||(we={})),function(e){e.Address="address",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"}(Se||(Se={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ne||(Ne={})),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"}(ke||(ke={})),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"}(De||(De={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.Id="id",e.Name="name",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol"}(Oe||(Oe={})),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"}(xe||(xe={})),function(e){e.Allow="allow",e.Deny="deny"}(Ce||(Ce={}));var Ue={__proto__:null,get Bundle_OrderBy(){return pe},get DailyTotal_OrderBy(){return me},get HourlyTotal_OrderBy(){return fe},get OrderDirection(){return ve},get Order_OrderBy(){return ge},get PairDaily_OrderBy(){return Ee},get PairHourly_OrderBy(){return Te},get Pair_OrderBy(){return Pe},get Settlement_OrderBy(){return Ie},get TokenDailyTotal_OrderBy(){return ye},get TokenHourlyTotal_OrderBy(){return Ae},get TokenTradingEvent_OrderBy(){return we},get Token_OrderBy(){return Se},get Total_OrderBy(){return Ne},get Trade_OrderBy(){return ke},get UniswapPool_OrderBy(){return De},get UniswapToken_OrderBy(){return Oe},get User_OrderBy(){return xe},get _SubgraphErrorPolicy_(){return Ce}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=v,exports.CowError=h,exports.CowSdk=class{constructor(e=exports.SupportedChainId.MAINNET,t={},r={}){const n=this;this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.updateContext=function(e,t){try{return Promise.resolve(n.context.chainId).then(function(r){n.context.updateContext(e,t||r)})}catch(e){return Promise.reject(e)}},this.validateAppDataDocument=te,this.context=new Re(e,{...t}),this.cowApi=new W(this.context),this.cowSubgraphApi=new ee(this.context),this.metadataApi=new ce(this.context),c.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 T({order:e,chainId:t},I,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 T({orderId:e,chainId:t},P,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=Ue,exports.Token=V;
|
|
28
|
+
`,re={[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.GOERLI]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-goerli",[exports.SupportedChainId.GNOSIS_CHAIN]:"https://api.thegraph.com/subgraphs/name/cowprotocol/cow-gc"};class te{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(re[exports.SupportedChainId.MAINNET],{fetch:h.default}),[exports.SupportedChainId.RINKEBY]:new n.GraphQLClient(re[exports.SupportedChainId.RINKEBY],{fetch:h.default}),[exports.SupportedChainId.GOERLI]:new n.GraphQLClient(re[exports.SupportedChainId.GOERLI],{fetch:h.default}),[exports.SupportedChainId.GNOSIS_CHAIN]:new n.GraphQLClient(re[exports.SupportedChainId.GNOSIS_CHAIN],{fetch:h.default})}}getBaseUrl(){try{return Promise.resolve(this.context.chainId).then(function(e){return re[e]})}catch(e){return Promise.reject(e)}}getTotals(){try{const e=this;return Promise.resolve(e.context.chainId).then(function(r){return u.default.debug(`[subgraph:${e.API_NAME}] Get totals for:`,r),Promise.resolve(e.runQuery(z)).then(function(e){return e.totals[0]})})}catch(e){return Promise.reject(e)}}getLastDaysVolume(e){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return u.default.debug(`[subgraph:${r.API_NAME}] Get last ${e} days volume for:`,t),r.runQuery(X,{days:e})})}catch(e){return Promise.reject(e)}}getLastHoursVolume(e){try{const r=this;return Promise.resolve(r.context.chainId).then(function(t){return u.default.debug(`[subgraph:${r.API_NAME}] Get last ${e} hours volume for:`,t),r.runQuery(ee,{hours:e})})}catch(e){return Promise.reject(e)}}runQuery(e,r){try{const t=this;return Promise.resolve(function(o,n){try{var i=Promise.resolve(t.context.chainId).then(function(o){return Promise.resolve(t.clients[o].request(e,r))})}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(t.getBaseUrl()).then(function(t){throw new f(`Error running query: ${e}. Variables: ${JSON.stringify(r)}. API: ${t}. Inner Error: ${o}`)})}))}catch(e){return Promise.reject(e)}}}const oe=function(e,r){return Promise.resolve(ie(r)).then(function({ajv:r,validate:t}){return{result:!!t(e),errors:r.errors?r.errorsText(r.errors):void 0}})},ne=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(Promise.resolve().then(function(){/*#__PURE__*/return c(require("multiformats/cid"))})).then(function({CID:e}){return e.decode(s).toV0().toString()})}catch(e){return Promise.reject(e)}},ie=function(e){try{function r(){return{ajv:ae,validate:se}}ae||(ae=new p.default),se=ae.getSchema(e);const t=function(){if(!se)return Promise.resolve((r=`@cowprotocol/app-data/schemas/v${e}.json`,Promise.resolve().then(function(){/*#__PURE__*/return c(require(r))}))).then(function(r){ae.addSchema(r,e),se=ae.getSchema(e)});var r}();return Promise.resolve(t&&t.then?t.then(r):r())}catch(o){return Promise.reject(o)}};let se,ae;function ce(e,r){try{var t=e()}catch(e){return r(e)}return t&&t.then?t.then(void 0,r):t}class de{constructor(e){this.context=void 0,this.context=e}generateAppDataDoc(e){const{appDataParams:r,metadataParams:t}=e||{},{referrerParams:o,quoteParams:n}=t||{},s={};o&&(s.referrer=i.createReferrerMetadata(o)),n&&(s.quote=i.createQuoteMetadata(n));const a=(null==r?void 0:r.appCode)||"CowSwap";return i.createAppDataDoc({...r,appCode:a,metadata:s})}decodeAppData(e){try{return Promise.resolve(ce(function(){return Promise.resolve(ne(e)).then(function(e){if(!e)throw new f("Error getting serialized CID");return function(e,r="https://gnosis.mypinata.cloud/ipfs"){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return c(require("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)})},function(e){const r=e;throw u.default.error("Error decoding AppData:",r),new f("Error decoding AppData: "+r.message)}))}catch(e){return Promise.reject(e)}}cidToAppDataHex(e){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return c(require("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(ne(e)).then(function(e){if(!e)throw new f("Error getting serialized CID");return e})}catch(e){return Promise.reject(e)}}calculateAppDataHash(e){try{const r=this;return Promise.resolve(oe(e,e.version)).then(function(t){if(null==t||!t.result)throw new f("Invalid appData provided",null==t?void 0:t.errors);return ce(function(){return Promise.resolve(function(e){try{const r=JSON.stringify(e);return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return c(require("ipfs-only-hash"))})).then(function({of:e}){return e(r,{cidVersion:0})})}catch(e){return Promise.reject(e)}}(e)).then(function(e){return Promise.resolve(r.cidToAppDataHex(e)).then(function(r){if(!r)throw new f(`Could not extract appDataHash from calculated cidV0 ${e}`);return{cidV0:e,appDataHash:r}})})},function(e){throw new f("Failed to calculate appDataHash",e.message)})})}catch(e){return Promise.reject(e)}}uploadMetadataDocToIpfs(e){try{const r=this;return Promise.resolve(function(e,{writeUri:r="https://api.pinata.cloud",pinataApiKey:t="",pinataApiSecret:o=""}){try{return Promise.resolve(Promise.resolve().then(function(){/*#__PURE__*/return c(require("cross-fetch"))})).then(function({default:n}){if(!t||!o)throw new f("You need to pass IPFS api credentials.");const i=JSON.stringify({pinataContent:e,pinataMetadata:{name:"appData"}});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 ue=0;function le(e){return"__private_"+ue+++"_"+e}function he(e,r){if(!Object.prototype.hasOwnProperty.call(e,r))throw new TypeError("attempted to use private field on non-instance");return e}const pe={appDataHash:"0x0000000000000000000000000000000000000000000000000000000000000000",env:"prod",ipfs:{readUri:"https://gnosis.mypinata.cloud/ipfs",writeUri:"https://api.pinata.cloud",pinataApiKey:"",pinataApiSecret:""}};var fe=/*#__PURE__*/le("chainId"),me=/*#__PURE__*/le("context");class ve{updateContext(e,r){this.setParams(r,e)}constructor(e,r){Object.defineProperty(this,fe,{writable:!0,value:exports.SupportedChainId.MAINNET}),Object.defineProperty(this,me,{writable:!0,value:pe}),this.setParams(e,r)}setParams(e,r){he(this,fe)[fe]=this.updateChainId(e),he(this,me)[me]={...pe,...r,ipfs:{...pe.ipfs,...r.ipfs}}}updateChainId(e){if(!exports.SupportedChainId[e])throw new f(`Invalid chainId: ${e}`);return u.default.debug("cow-sdk:",`Updating chainId to: ${e}`),he(this,fe)[fe]=e,e}get chainId(){const e=this;var r;const t=null==(r=he(this,me)[me].signer)?void 0:r.provider;return t?(u.default.debug("cow-sdk:","Getting chainId from provider"),function(){try{return Promise.resolve(t.getNetwork()).then(function(r){const t=r.chainId;return t!==he(e,fe)[fe]&&(u.default.debug("cow-sdk:",`ChainId mismatch: Provider's chainId: ${t} vs Context's chainId: ${he(e,fe)[fe]}. Updating Context's chainId`),e.updateChainId(t)),t})}catch(e){return Promise.reject(e)}}()):Promise.resolve(he(this,fe)[fe])}get appDataHash(){var e;return null!==(e=he(this,me)[me].appDataHash)&&void 0!==e?e:pe.appDataHash}get env(){return he(this,me)[me].env||pe.env}get signer(){return he(this,me)[me].signer}get ipfs(){var e;return null!==(e=he(this,me)[me].ipfs)&&void 0!==e?e:pe.ipfs}}class Te extends f{static getErrorMessage(e){try{return Promise.resolve(function(r,t){try{var o=Promise.resolve(e.json()).then(function(e){var r,t;if(null!=(r=e.validationErrors)&&r.length)return(null==(t=e.validationErrors)?void 0:t[0].reason)||e.reason;if(null!=e&&e.reason)return u.default.error("0x-sdk:","Unknown validation reason for bad price request",e),e.reason;throw new Error('Error response body properties "reason" and "validationErrors" missing.')})}catch(e){return t(e)}return o&&o.then?o.then(void 0,t):o}(0,function(e){const r=e instanceof Error;return u.default.error("0x-sdk:","Error handling a 4xx error. Likely a problem deserialising the JSON response.",r&&(null==e?void 0:e.message)),r?null==e?void 0:e.message:"Price fetch failed. This may be due to a server or network connectivity issue. Please try again later."}))}catch(e){return Promise.reject(e)}}static getErrorFromStatusCode(e){try{const r=this;switch(e.status){case 400:return Promise.resolve(r.getErrorMessage(e));case 404:return Promise.resolve("Not found");case 429:return Promise.resolve("Too many requests - Rate limit exceeded");case 500:return Promise.resolve("Internal server error");case 501:return Promise.resolve("Not Implemented");case 503:return Promise.resolve("Server Error - Too many open connections");default:return u.default.error("0x-sdk:","Error fetching quote, status code:",e.status||"unknown"),Promise.resolve("Error fetching quote")}return Promise.resolve()}catch(e){return Promise.reject(e)}}constructor(e){var r;super(e.reason,e.code.toString()),this.name="ZeroXError",this.description=void 0,this.message=void 0,this.description=(null==(r=e.validationErrors)?void 0:r[0].reason)||e.reason,this.message=e.reason}}const ge=function(e,r){try{return e.ok?Promise.resolve(e.json()):Promise.resolve(e.clone().json()).then(function(t){function o(){if(r){const{quoteToken:e,baseToken:t}=r;u.default.error("0x-sdk:",`Error querying fee from API - quoteToken: ${e}, baseToken: ${t}`)}throw n}let n;const i=function(){if(null==t||!t.code||null==t||!t.reason)return Promise.resolve(Te.getErrorFromStatusCode(e.clone())).then(function(r){n=new Te({code:e.status,reason:r})});n=new Te(t)}();return i&&i.then?i.then(o):o()})}catch(e){return Promise.reject(e)}};function Pe(){return{[exports.SupportedChainId.MAINNET]:"https://api.0x.org/swap"}}function Ie({excludedSources:e,affiliateAddress:r}){return m({excludedSources:ye({excludedSources:e}),affiliateAddress:r})}function Ee({affiliateAddressMap:e,chainId:r}){const t=e[r];if(!t)throw new f(`Invalid affiliate address! Parameters passed: ${JSON.stringify({affiliateAddressMap:e,chainId:r},null,2)}`);return t}function ye({excludedSources:e}){return e.length>0?e.join(","):""}const Ae=[];class ke extends G{constructor(e,{affiliateAddressMap:r,excludedSources:t}={affiliateAddressMap:g,excludedSources:Ae}){super({context:new ve(e,{}),name:"0x",apiVersion:"v1",getApiUrl:Pe}),this.MATCHA_OPTIONS=void 0,this.MATCHA_OPTIONS_URL=void 0;const o=Ee({affiliateAddressMap:r,chainId:e});this.MATCHA_OPTIONS={affiliateAddressMap:r,excludedSources:t},this.MATCHA_OPTIONS_URL=Ie({excludedSources:t,affiliateAddress:o})}getQuote(e,t={}){try{const o=this;function n(t){const n=function(e){return e===exports.SupportedChainId.MAINNET?e:null}(t);if(null==n)return u.default.debug("0x-sdk:","Network not supported"),null;u.default.debug("0x-sdk:",`Get price from ${o.API_NAME}`,e,o.MATCHA_OPTIONS);const{sellToken:d,buyToken:h}=function({quoteToken:e,baseToken:t,kind:o}){return o===r.OrderKind.SELL?{sellToken:t,buyToken:e}:{buyToken:t,sellToken:e}}({baseToken:F(s,t),quoteToken:F(a,t),kind:c}),p=Ee({affiliateAddressMap:o.MATCHA_OPTIONS.affiliateAddressMap,chainId:t});return Promise.resolve(o.get(`/price${m({sellToken:d,buyToken:h,[c===r.OrderKind.BUY?"buyAmount":"sellAmount"]:i,affiliateAddress:p,excludedSources:ye(o.MATCHA_OPTIONS)})}`,{chainId:t,env:l}).catch(e=>{throw u.default.error(`Error getting ${o.API_NAME} price quote:`,e),new Error(e)})).then(ge)}const{amount:i,baseToken:s,quoteToken:a,kind:c}=e,{chainId:d,env:l=o.context.env}=t;return Promise.resolve(d?n(d):Promise.resolve(o.context.chainId).then(n))}catch(h){return Promise.reject(h)}}updateOptions({affiliateAddressMap:e,excludedSources:r}){try{const t=this;return Promise.resolve(t.context.chainId).then(function(o){e&&(u.default.debug("0x-sdk:","Updating 0x options affiliate address to",e),t.MATCHA_OPTIONS.affiliateAddressMap=e),r&&(u.default.debug("0x-sdk:","Updating 0x options excludedSources to",r),t.MATCHA_OPTIONS.excludedSources=r);const n=Ee({affiliateAddressMap:t.MATCHA_OPTIONS.affiliateAddressMap,chainId:o});t.MATCHA_OPTIONS_URL=Ie({...t.MATCHA_OPTIONS,affiliateAddress:n})})}catch(e){return Promise.reject(e)}}}var we,Se,Ne,Oe,xe,_e,Ce,De,be,Re,Ue,Le,He,je,Me,Ve,qe,Fe,$e;!function(e){e.EthPriceUsd="ethPriceUSD",e.Id="id"}(we||(we={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Se||(Se={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Timestamp="timestamp",e.Tokens="tokens",e.TotalTokens="totalTokens",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(Ne||(Ne={})),function(e){e.Asc="asc",e.Desc="desc"}(Oe||(Oe={})),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"}(xe||(xe={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(_e||(_e={})),function(e){e.Id="id",e.Timestamp="timestamp",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(Ce||(Ce={})),function(e){e.Id="id",e.Token0="token0",e.Token0Price="token0Price",e.Token0relativePrice="token0relativePrice",e.Token1="token1",e.Token1Price="token1Price",e.Token1relativePrice="token1relativePrice",e.VolumeToken0="volumeToken0",e.VolumeToken1="volumeToken1",e.VolumeTradedEth="volumeTradedEth",e.VolumeTradedUsd="volumeTradedUsd"}(De||(De={})),function(e){e.FirstTradeTimestamp="firstTradeTimestamp",e.Id="id",e.Solver="solver",e.Trades="trades",e.TxHash="txHash"}(be||(be={})),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"}(Re||(Re={})),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"}(Ue||(Ue={})),function(e){e.AmountEth="amountEth",e.AmountUsd="amountUsd",e.Id="id",e.Timestamp="timestamp",e.Token="token",e.Trade="trade"}(Le||(Le={})),function(e){e.Address="address",e.DailyTotals="dailyTotals",e.Decimals="decimals",e.FirstTradeTimestamp="firstTradeTimestamp",e.History="history",e.HourlyTotals="hourlyTotals",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"}(He||(He={})),function(e){e.FeesEth="feesEth",e.FeesUsd="feesUsd",e.Id="id",e.NumberOfTrades="numberOfTrades",e.Orders="orders",e.Settlements="settlements",e.Tokens="tokens",e.Traders="traders",e.VolumeEth="volumeEth",e.VolumeUsd="volumeUsd"}(je||(je={})),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"}(Me||(Me={})),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"}(Ve||(Ve={})),function(e){e.Address="address",e.AllowedPools="allowedPools",e.Decimals="decimals",e.Id="id",e.Name="name",e.PriceEth="priceEth",e.PriceUsd="priceUsd",e.Symbol="symbol"}(qe||(qe={})),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"}(Fe||(Fe={})),function(e){e.Allow="allow",e.Deny="deny"}($e||($e={}));var Ge={__proto__:null,get Bundle_OrderBy(){return we},get DailyTotal_OrderBy(){return Se},get HourlyTotal_OrderBy(){return Ne},get OrderDirection(){return Oe},get Order_OrderBy(){return xe},get PairDaily_OrderBy(){return _e},get PairHourly_OrderBy(){return Ce},get Pair_OrderBy(){return De},get Settlement_OrderBy(){return be},get TokenDailyTotal_OrderBy(){return Re},get TokenHourlyTotal_OrderBy(){return Ue},get TokenTradingEvent_OrderBy(){return Le},get Token_OrderBy(){return He},get Total_OrderBy(){return je},get Trade_OrderBy(){return Me},get UniswapPool_OrderBy(){return Ve},get UniswapToken_OrderBy(){return qe},get User_OrderBy(){return Fe},get _SubgraphErrorPolicy_(){return $e}};Object.defineProperty(exports,"OrderKind",{enumerable:!0,get:function(){return r.OrderKind}}),exports.ALL_SUPPORTED_CHAIN_IDS=v,exports.CowError=f,exports.CowSdk=class{constructor(e=exports.SupportedChainId.MAINNET,r={},t={}){const o=this;this.context=void 0,this.cowApi=void 0,this.metadataApi=void 0,this.cowSubgraphApi=void 0,this.zeroXApi=void 0,this.updateChainId=e=>{this.context.updateChainId(e)},this.updateContext=function(e,r){try{return Promise.resolve(o.context.chainId).then(function(t){o.context.updateContext(e,r||t)})}catch(e){return Promise.reject(e)}},this.validateAppDataDocument=oe,this.context=new ve(e,{...r}),this.cowApi=new Z(this.context),this.cowSubgraphApi=new te(this.context),this.metadataApi=new de(this.context),this.zeroXApi=new ke(e,t.matchaOptions),u.default.setLevel(t.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 P({order:e,chainId:r},E,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 P({orderId:e,chainId:r},I,t)}(e,r,t)})}catch(e){return Promise.reject(e)}}_checkSigner(e=this.context.signer){if(!e)throw new f("No signer available");return e}},exports.GraphQL=Ge,exports.Token=M;
|
|
29
29
|
//# sourceMappingURL=index.js.map
|