@cowprotocol/cow-sdk
Version:
<p align="center"> <img width="400" src="https://github.com/cowprotocol/cow-sdk/raw/main/docs/images/CoW.png" /> </p>
3 lines (2 loc) • 3.17 kB
JavaScript
import{hashOrder as e,packOrderUidParams as t,IntChainIdTypedDataV4Signer as r,TypedDataVersionedSigner as n,signOrderCancellations as o,signOrderCancellation as i,signOrder as s,SigningScheme as c,domain as a}from"@cowprotocol/contracts";import{EcdsaSigningScheme as d,CowError as u,COW_PROTOCOL_SETTLEMENT_CONTRACT_ADDRESS as h}from"./index.module.js";import"cross-fetch/polyfill";import"limiter";import"exponential-backoff";import"graphql-request";import"ethers";import"@openzeppelin/merkle-tree";import"ethers/lib/utils";import"@ethersproject/abstract-signer";import"@cowprotocol/app-data";const l=function(r,n,o){try{return Promise.resolve(k(r)).then(function(r){const i=e(r,n);return{orderId:t({...o,orderDigest:i,validTo:n.validTo}),orderDigest:i}})}catch(e){return Promise.reject(e)}},m=function(e,t,r){return p({orderUids:e,chainId:t},v,r)},f=function(e,t,r){return p({orderUid:e,chainId:t},P,r)},g=function(e,t,r){return p({order:e,chainId:t},w,r)},p=function(e,t,o,i="v4"){try{let c;function s(e){if(c)return e;const t=l?.data;return{signature:t?.toString()||"",signingScheme:a}}const a="eth_sign"===i?d.ETHSIGN:d.EIP712;let h,l=null;try{switch(i){case"default":case"v3":h=new n(o);break;case"int_v4":h=new r(o);break;default:h=o}}catch(f){throw console.error("Wallet not supported:",f),new u("Wallet not supported")}const m=function(r,n){try{var o=Promise.resolve(t({...e,signer:h,signingScheme:a})).then(function(e){l=e})}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,function(r){if(void 0===(n=r).code&&void 0===n.message)throw console.error(r),r;var n;const s=[S,T].some(e=>[r.message,r.toString()].some(t=>e.test(t)));if(r.code!==y&&!s){if(E.test(r.message)){const r=p(e,t,o,"int_v4");return c=1,r}if(r.code===I){const r=p(e,t,o,"eth_sign");return c=1,r}if(_.test(r.message)){const r=p(e,t,o,"v3");return c=1,r}if(j.test(r.message)){const r=p(e,t,o,"eth_sign");return c=1,r}throw console.error(r),r}switch(i){case"v4":const n=p(e,t,o,"default");return c=1,n;case"default":const i=p(e,t,o,"v3");return c=1,i;case"v3":const s=p(e,t,o,"eth_sign");return c=1,s;default:throw r}});return Promise.resolve(m&&m.then?m.then(s):s(m))}catch(g){return Promise.reject(g)}},v=function(e){try{const{chainId:t,signer:r,signingScheme:n,orderUids:i}=e,s=k(t);return Promise.resolve(o(s,i,r,b[n]))}catch(e){return Promise.reject(e)}},P=function(e){try{const{chainId:t,signer:r,signingScheme:n,orderUid:o}=e,s=k(t);return Promise.resolve(i(s,o,r,b[n]))}catch(e){return Promise.reject(e)}},w=function(e){try{const{chainId:t,signer:r,order:n,signingScheme:o}=e,i=k(t);return Promise.resolve(s(i,n,r,b[o]))}catch(e){return Promise.reject(e)}},I=-32603,y=-32601,S=/Method not found/i,_=/eth_signTypedData_v4 does not exist/i,j=/eth_signTypedData_v3 does not exist/i,T=/RPC request failed/i,E=/provided chainid .* must match the active chainid/i,b={[d.EIP712]:c.EIP712,[d.ETHSIGN]:c.ETHSIGN};function k(e){const t=h[e];if(!t)throw new u("Unsupported network. Settlement contract is not deployed");return a(e,t)}export{l as generateOrderId,k as getDomain,g as signOrder,f as signOrderCancellation,m as signOrderCancellations};
//# sourceMappingURL=utils-fbaee37f.js.map