UNPKG

@cowprotocol/cow-sdk

Version:

## 📚 [Docs website](https://docs.cow.fi/)

3 lines (2 loc) • 2.66 kB
import{C as e,_ as t,a as r,E as n}from"./index-67580d8b.js";import{domain as i,hashOrder as o,packOrderUidParams as s,IntChainIdTypedDataV4Signer as a,TypedDataVersionedSigner as c,signOrder as d,signOrderCancellation as l,signOrderCancellations as u,SigningScheme as g}from"@cowprotocol/contracts";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"ethers";import"@ethersproject/abstract-signer";import"@cowprotocol/app-data";import"ethers/lib/utils";import"deepmerge";import"@weiroll/weiroll.js";import"graphql-request";import"@openzeppelin/merkle-tree";const h=-32603,p=-32601,m=/Method not found/i,f=/eth_signTypedData_v4 does not exist/i,v=/eth_signTypedData_v3 does not exist/i,w=/RPC request failed/i,y=/provided chainid .* must match the active chainid/i,I={[n.EIP712]:g.EIP712,[n.ETHSIGN]:g.ETHSIGN};async function S(e){const{chainId:t,signer:r,order:n,signingScheme:i}=e,o=U(t);return d(o,n,r,I[i])}async function _(e){const{chainId:t,signer:r,signingScheme:n,orderUid:i}=e,o=U(t);return l(o,i,r,I[n])}async function E(e){const{chainId:t,signer:r,signingScheme:n,orderUids:i}=e,o=U(t);return u(o,i,r,I[n])}async function T(r,i,o,s="v4"){var d;const l="eth_sign"===s?n.ETHSIGN:n.EIP712;let u,g=null;try{switch(s){case"default":case"v3":u=new c(o);break;case"int_v4":u=new a(o);break;default:u=o}}catch(t){throw console.error("Wallet not supported:",t),new e("Wallet not supported")}try{g=await i(t({},r,{signer:u,signingScheme:l}))}catch(e){if(void 0===(I=e).code&&void 0===I.message)throw console.error(e),e;const t=[m,w].some(t=>[e.message,e.toString()].some(e=>t.test(e)));if(e.code!==p&&!t){if(y.test(e.message))return T(r,i,o,"int_v4");if(e.code===h)return T(r,i,o,"eth_sign");if(f.test(e.message))return T(r,i,o,"v3");if(v.test(e.message))return T(r,i,o,"eth_sign");throw console.error(e),e}switch(s){case"v4":return T(r,i,o,"default");case"default":return T(r,i,o,"v3");case"v3":return T(r,i,o,"eth_sign");default:throw e}}var I;const S=null==(d=g)?void 0:d.data;return{signature:(null==S?void 0:S.toString())||"",signingScheme:l}}async function b(e,t,r){return T({order:e,chainId:t},S,r)}async function k(e,t,r){return T({orderUid:e,chainId:t},_,r)}async function x(e,t,r){return T({orderUids:e,chainId:t},E,r)}function U(t){const n=r[t];if(!n)throw new e("Unsupported network. Settlement contract is not deployed");return i(t,n)}async function C(e,r,n){const i=await U(e),a=o(i,r);return{orderId:s(t({},n,{orderDigest:a,validTo:r.validTo})),orderDigest:a}}export{C as generateOrderId,U as getDomain,b as signOrder,k as signOrderCancellation,x as signOrderCancellations}; //# sourceMappingURL=utils-6e8340a0.js.map