@cowprotocol/cow-sdk 5.3.3 → 5.4.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.
@@ -1,4 +1,4 @@
1
- import"cross-fetch/polyfill";import{RateLimiter as e}from"limiter";import{backOff as t}from"exponential-backoff";import{gql as n,request as r}from"graphql-request";import{utils as a,Contract as s,ethers as i,constants as o,BigNumber as p}from"ethers";import{OrderBalance as u,OrderKind as d}from"@cowprotocol/contracts";import{StandardMerkleTree as l}from"@openzeppelin/merkle-tree";var y;!function(e){e[e.MAINNET=1]="MAINNET",e[e.GNOSIS_CHAIN=100]="GNOSIS_CHAIN",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.SEPOLIA=11155111]="SEPOLIA"}(y||(y={}));const c=["prod","staging"],m={env:"prod",chainId:y.MAINNET};class T extends Error{constructor(e,t){super(e),this.error_code=void 0,this.error_code=t}}const f="cow-sdk:",h="https://gnosis.mypinata.cloud/ipfs",b="https://api.pinata.cloud";function I(){return I=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},I.apply(this,arguments)}function A(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)t.indexOf(n=s[r])>=0||(a[n]=e[n]);return a}const E="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",O="0x2f55e8b20D0B9FEFA187AA7d00B6Cbe563605bF5",g="0xfdaFc9d1902f4e0b84f65F49f244b32b31013b74",S=Object.values(y).filter(e=>"number"==typeof e);function N(e){return S.reduce((t,n)=>I({},t,{[n]:"function"==typeof e?e(n):e}),{})}function w(e){return N(e)}const v=w("0x9008D19f58AAbD9eD0D60971565AA8510560ab41"),_=w("0xC92E8bdf79f0507f65a392b0ab4667716BFE0110"),P=w(O),R=w(g);class C extends Error{constructor(e,t){super("string"==typeof t?t:e.statusText),this.response=void 0,this.body=void 0,this.response=e,this.body=t}}const D=[408,425,429,500,502,503,504],M={numOfAttempts:10,maxDelay:Infinity,jitter:"none",retry:e=>!(e instanceof C)||D.includes(e.response.status)},x={tokensPerInterval:5,interval:"second"},U=async e=>{if(204!==e.status)try{const t=e.headers.get("Content-Type");if(t)return t.toLowerCase().startsWith("application/json")?await e.json():await e.text()}catch(e){console.error(e)}};async function L(e,{path:n,query:r,method:a,body:s},i,o){const p=`${e}${n}${r?"?"+r:""}`,u={method:a,body:(()=>{if(s)return"string"==typeof s?s:JSON.stringify(s)})(),headers:{Accept:"application/json","Content-Type":"application/json"}};return t(async()=>{await i.removeTokens(1);const e=await fetch(p,u),t=await U(e);return e.status>=200&&e.status<300?t:Promise.reject(new C(e,t))},o)}function k(e){return function(e){const{ethflowData:t}=e;if(!t)return e;const{userValidTo:n}=t;return I({},e,{validTo:n,owner:e.onchainUser||e.owner,sellToken:E})}(function(e){const{executedFeeAmount:t,executedSurplusFee:n}=e,r=BigInt(t||"0"),a=BigInt(n||"0");return I({},e,{totalFee:String(r+a)})}(e))}const B={[y.MAINNET]:"https://api.cow.fi/mainnet",[y.GNOSIS_CHAIN]:"https://api.cow.fi/xdai",[y.ARBITRUM_ONE]:"https://api.cow.fi/arbitrum_one",[y.SEPOLIA]:"https://api.cow.fi/sepolia"},F={[y.MAINNET]:"https://barn.api.cow.fi/mainnet",[y.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai",[y.ARBITRUM_ONE]:"https://barn.api.cow.fi/arbitrum_one",[y.SEPOLIA]:"https://barn.api.cow.fi/sepolia"};function V(e){return Object.keys(e).reduce((t,n)=>{const r=e[n];return void 0!==r&&(t[n]=r),t},{})}class ${constructor(t={}){this.context=void 0,this.rateLimiter=void 0,this.context=I({},m,t),this.rateLimiter=new e(t.limiterOpts||x)}getVersion(e={}){return this.fetch({path:"/api/v1/version",method:"GET"},e)}getTrades(e,t={}){if(e.owner&&e.orderUid)return Promise.reject(new T("Cannot specify both owner and orderId"));if(!e.owner&&!e.orderUid)return Promise.reject(new T("Must specify either owner or orderId"));const n=new URLSearchParams(V(e));return this.fetch({path:"/api/v1/trades",method:"GET",query:n},t)}getOrders({owner:e,offset:t=0,limit:n=1e3},r={}){const a=new URLSearchParams(V({offset:t.toString(),limit:n.toString()}));return this.fetch({path:`/api/v1/account/${e}/orders`,method:"GET",query:a},r).then(e=>e.map(k))}getTxOrders(e,t={}){return this.fetch({path:`/api/v1/transactions/${e}/orders`,method:"GET"},t).then(e=>e.map(k))}getOrder(e,t={}){return this.fetch({path:`/api/v1/orders/${e}`,method:"GET"},t).then(e=>k(e))}getOrderMultiEnv(e,t={}){const{env:n}=this.getContextWithOverride(t),r=c.filter(e=>e!==n);let a=0;const s=n=>{const i=r[a];return n instanceof C&&404===n.response.status&&i?(a++,this.getOrder(e,I({},t,{env:i})).catch(s)):Promise.reject(n)};return this.getOrder(e,I({},t,{env:n})).catch(s)}getQuote(e,t={}){return this.fetch({path:"/api/v1/quote",method:"POST",body:e},t)}sendSignedOrderCancellations(e,t={}){return this.fetch({path:"/api/v1/orders",method:"DELETE",body:e},t)}sendOrder(e,t={}){return this.fetch({path:"/api/v1/orders",method:"POST",body:e},t)}getNativePrice(e,t={}){return this.fetch({path:`/api/v1/token/${e}/native_price`,method:"GET"},t)}getTotalSurplus(e,t={}){return this.fetch({path:`/api/v1/users/${e}/total_surplus`,method:"GET"},t)}getAppData(e,t={}){return this.fetch({path:`/api/v1/app_data/${e}`,method:"GET"},t)}uploadAppData(e,t,n={}){return this.fetch({path:`/api/v1/app_data/${e}`,method:"PUT",body:{fullAppData:t}},n)}getSolverCompetition(e,t={}){return this.fetch({path:`/api/v1/solver_competition${"string"==typeof e?"/by_tx_hash":""}/${e}`,method:"GET"},t)}getOrderLink(e,t){const{chainId:n,env:r}=this.getContextWithOverride(t);return this.getApiBaseUrls(r)[n]+`/api/v1/orders/${e}`}getContextWithOverride(e={}){return I({},this.context,e)}getApiBaseUrls(e){return this.context.baseUrls?this.context.baseUrls:"prod"===e?B:F}fetch(t,n={}){const{chainId:r,env:a,backoffOpts:s}=this.getContextWithOverride(n),i=this.getApiBaseUrls(a)[r],o=s||M;return L(i,t,n.limiterOpts?new e(n.limiterOpts):this.rateLimiter,o)}}var G,W,H,Y,j,Z,K,X,q,z,J,Q,ee,te;!function(e){e.ERC20="erc20",e.INTERNAL="internal"}(G||(G={})),function(e){e.EIP712="eip712",e.ETHSIGN="ethsign"}(W||(W={})),function(e){var t;(t=e.placementError||(e.placementError={})).QUOTE_NOT_FOUND="QuoteNotFound",t.VALID_TO_TOO_FAR_IN_FUTURE="ValidToTooFarInFuture",t.PRE_VALIDATION_ERROR="PreValidationError"}(H||(H={})),function(e){var t;(t=e.errorType||(e.errorType={})).INVALID_SIGNATURE="InvalidSignature",t.WRONG_OWNER="WrongOwner",t.ORDER_NOT_FOUND="OrderNotFound",t.ALREADY_CANCELLED="AlreadyCancelled",t.ORDER_FULLY_EXECUTED="OrderFullyExecuted",t.ORDER_EXPIRED="OrderExpired",t.ON_CHAIN_ORDER="OnChainOrder"}(Y||(Y={})),function(e){e.MARKET="market",e.LIMIT="limit",e.LIQUIDITY="liquidity"}(j||(j={})),function(e){e.BUY="buy",e.SELL="sell"}(Z||(Z={})),function(e){var t;(t=e.errorType||(e.errorType={})).DUPLICATED_ORDER="DuplicatedOrder",t.QUOTE_NOT_FOUND="QuoteNotFound",t.INVALID_QUOTE="InvalidQuote",t.MISSING_FROM="MissingFrom",t.WRONG_OWNER="WrongOwner",t.INVALID_EIP1271SIGNATURE="InvalidEip1271Signature",t.INSUFFICIENT_BALANCE="InsufficientBalance",t.INSUFFICIENT_ALLOWANCE="InsufficientAllowance",t.INVALID_SIGNATURE="InvalidSignature",t.SELL_AMOUNT_OVERFLOW="SellAmountOverflow",t.TRANSFER_SIMULATION_FAILED="TransferSimulationFailed",t.ZERO_AMOUNT="ZeroAmount",t.INCOMPATIBLE_SIGNING_SCHEME="IncompatibleSigningScheme",t.TOO_MANY_LIMIT_ORDERS="TooManyLimitOrders",t.TOO_MUCH_GAS="TooMuchGas",t.UNSUPPORTED_BUY_TOKEN_DESTINATION="UnsupportedBuyTokenDestination",t.UNSUPPORTED_SELL_TOKEN_SOURCE="UnsupportedSellTokenSource",t.UNSUPPORTED_ORDER_TYPE="UnsupportedOrderType",t.INSUFFICIENT_VALID_TO="InsufficientValidTo",t.EXCESSIVE_VALID_TO="ExcessiveValidTo",t.INVALID_NATIVE_SELL_TOKEN="InvalidNativeSellToken",t.SAME_BUY_AND_SELL_TOKEN="SameBuyAndSellToken",t.UNSUPPORTED_TOKEN="UnsupportedToken",t.INVALID_APP_DATA="InvalidAppData",t.APP_DATA_HASH_MISMATCH="AppDataHashMismatch",t.APPDATA_FROM_MISMATCH="AppdataFromMismatch"}(K||(K={})),function(e){e.BUY="buy"}(X||(X={})),function(e){e.SELL="sell"}(q||(q={})),function(e){e.PRESIGNATURE_PENDING="presignaturePending",e.OPEN="open",e.FULFILLED="fulfilled",e.CANCELLED="cancelled",e.EXPIRED="expired"}(z||(z={})),function(e){var t;(t=e.errorType||(e.errorType={})).UNSUPPORTED_TOKEN="UnsupportedToken",t.ZERO_AMOUNT="ZeroAmount",t.UNSUPPORTED_ORDER_TYPE="UnsupportedOrderType"}(J||(J={})),function(e){e.FAST="fast",e.OPTIMAL="optimal",e.VERIFIED="verified"}(Q||(Q={})),function(e){e.ERC20="erc20",e.INTERNAL="internal",e.EXTERNAL="external"}(ee||(ee={})),function(e){e.EIP712="eip712",e.ETHSIGN="ethsign",e.PRESIGN="presign",e.EIP1271="eip1271"}(te||(te={}));const ne=BigInt(1e4);function re(e){var t;const{orderParams:n,sellDecimals:r,buyDecimals:a,slippagePercentBps:s}=e,i=null!==(t=e.partnerFeeBps)&&void 0!==t?t:0,o=n.kind===Z.SELL,p=ae(n.feeAmount,r),u=ae(n.sellAmount,r),d=ae(n.buyAmount,a),l=d.num/u.num,y=ae(u.big+p.big,r),c=ae(l*y.num,a),m=i>0?(o?c.big:u.big)*BigInt(i)/ne:BigInt(0),T=o?{sellAmount:y.big,buyAmount:d.big-m}:{sellAmount:y.big+m,buyAmount:d.big},f=e=>e*BigInt(s)/ne,h=o?{sellAmount:T.sellAmount,buyAmount:T.buyAmount-f(T.buyAmount)}:{sellAmount:T.sellAmount+f(T.sellAmount),buyAmount:T.buyAmount};return{isSell:o,costs:{networkFee:{amountInSellCurrency:p.big,amountInBuyCurrency:ae(l*p.num,a).big},partnerFee:{amount:m,bps:i}},beforeNetworkCosts:{sellAmount:u.big,buyAmount:c.big},afterNetworkCosts:{sellAmount:y.big,buyAmount:d.big},afterPartnerFees:T,afterSlippage:h}}function ae(e,t){if("number"==typeof e){const n=e*10**t,r=n.toFixed();return{big:BigInt(r.includes("e")?n:r),num:e}}const n=BigInt(e);return{big:n,num:Number(n)/10**t}}let se,ie,oe,pe=e=>e;const ue=n(se||(se=pe`
1
+ import"cross-fetch/polyfill";import{RateLimiter as e}from"limiter";import{backOff as t}from"exponential-backoff";import{gql as n,request as r}from"graphql-request";import{utils as a,Contract as s,ethers as i,constants as o,BigNumber as p}from"ethers";import{OrderBalance as u,OrderKind as d}from"@cowprotocol/contracts";import{StandardMerkleTree as l}from"@openzeppelin/merkle-tree";var y;!function(e){e[e.MAINNET=1]="MAINNET",e[e.GNOSIS_CHAIN=100]="GNOSIS_CHAIN",e[e.ARBITRUM_ONE=42161]="ARBITRUM_ONE",e[e.SEPOLIA=11155111]="SEPOLIA"}(y||(y={}));const c=["prod","staging"],m={env:"prod",chainId:y.MAINNET};class T extends Error{constructor(e,t){super(e),this.error_code=void 0,this.error_code=t}}const f="cow-sdk:",h="https://gnosis.mypinata.cloud/ipfs",b="https://api.pinata.cloud";function I(){return I=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},I.apply(this,arguments)}function E(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)t.indexOf(n=s[r])>=0||(a[n]=e[n]);return a}const A="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",O="0x2f55e8b20D0B9FEFA187AA7d00B6Cbe563605bF5",g="0xfdaFc9d1902f4e0b84f65F49f244b32b31013b74",S=Object.values(y).filter(e=>"number"==typeof e);function N(e){return S.reduce((t,n)=>I({},t,{[n]:"function"==typeof e?e(n):e}),{})}function v(e){return N(e)}const w=v("0x9008D19f58AAbD9eD0D60971565AA8510560ab41"),_=v("0xC92E8bdf79f0507f65a392b0ab4667716BFE0110"),P=v(O),R=v(g);class C extends Error{constructor(e,t){super("string"==typeof t?t:e.statusText),this.response=void 0,this.body=void 0,this.response=e,this.body=t}}const D=[408,425,429,500,502,503,504],M={numOfAttempts:10,maxDelay:Infinity,jitter:"none",retry:e=>!(e instanceof C)||D.includes(e.response.status)},U={tokensPerInterval:5,interval:"second"},x=async e=>{if(204!==e.status)try{const t=e.headers.get("Content-Type");if(t)return t.toLowerCase().startsWith("application/json")?await e.json():await e.text()}catch(e){console.error(e)}};async function L(e,{path:n,query:r,method:a,body:s},i,o){const p=`${e}${n}${r?"?"+r:""}`,u={method:a,body:(()=>{if(s)return"string"==typeof s?s:JSON.stringify(s)})(),headers:{Accept:"application/json","Content-Type":"application/json"}};return t(async()=>{await i.removeTokens(1);const e=await fetch(p,u),t=await x(e);return e.status>=200&&e.status<300?t:Promise.reject(new C(e,t))},o)}function k(e){return function(e){const{ethflowData:t}=e;if(!t)return e;const{userValidTo:n}=t;return I({},e,{validTo:n,owner:e.onchainUser||e.owner,sellToken:A})}(function(e){const{executedFeeAmount:t,executedSurplusFee:n}=e,r=BigInt(t||"0"),a=BigInt(n||"0");return I({},e,{totalFee:String(r+a)})}(e))}const B={[y.MAINNET]:"https://api.cow.fi/mainnet",[y.GNOSIS_CHAIN]:"https://api.cow.fi/xdai",[y.ARBITRUM_ONE]:"https://api.cow.fi/arbitrum_one",[y.SEPOLIA]:"https://api.cow.fi/sepolia"},V={[y.MAINNET]:"https://barn.api.cow.fi/mainnet",[y.GNOSIS_CHAIN]:"https://barn.api.cow.fi/xdai",[y.ARBITRUM_ONE]:"https://barn.api.cow.fi/arbitrum_one",[y.SEPOLIA]:"https://barn.api.cow.fi/sepolia"};function F(e){return Object.keys(e).reduce((t,n)=>{const r=e[n];return void 0!==r&&(t[n]=r),t},{})}class G{constructor(t={}){this.context=void 0,this.rateLimiter=void 0,this.context=I({},m,t),this.rateLimiter=new e(t.limiterOpts||U)}getVersion(e={}){return this.fetch({path:"/api/v1/version",method:"GET"},e)}getTrades(e,t={}){if(e.owner&&e.orderUid)return Promise.reject(new T("Cannot specify both owner and orderId"));if(!e.owner&&!e.orderUid)return Promise.reject(new T("Must specify either owner or orderId"));const n=new URLSearchParams(F(e));return this.fetch({path:"/api/v1/trades",method:"GET",query:n},t)}getOrders({owner:e,offset:t=0,limit:n=1e3},r={}){const a=new URLSearchParams(F({offset:t.toString(),limit:n.toString()}));return this.fetch({path:`/api/v1/account/${e}/orders`,method:"GET",query:a},r).then(e=>e.map(k))}getTxOrders(e,t={}){return this.fetch({path:`/api/v1/transactions/${e}/orders`,method:"GET"},t).then(e=>e.map(k))}getOrder(e,t={}){return this.fetch({path:`/api/v1/orders/${e}`,method:"GET"},t).then(e=>k(e))}getOrderCompetitionStatus(e,t={}){return this.fetch({path:`/api/v1/orders/${e}/status`,method:"GET"},t)}getOrderMultiEnv(e,t={}){const{env:n}=this.getContextWithOverride(t),r=c.filter(e=>e!==n);let a=0;const s=n=>{const i=r[a];return n instanceof C&&404===n.response.status&&i?(a++,this.getOrder(e,I({},t,{env:i})).catch(s)):Promise.reject(n)};return this.getOrder(e,I({},t,{env:n})).catch(s)}getQuote(e,t={}){return this.fetch({path:"/api/v1/quote",method:"POST",body:e},t)}sendSignedOrderCancellations(e,t={}){return this.fetch({path:"/api/v1/orders",method:"DELETE",body:e},t)}sendOrder(e,t={}){return this.fetch({path:"/api/v1/orders",method:"POST",body:e},t)}getNativePrice(e,t={}){return this.fetch({path:`/api/v1/token/${e}/native_price`,method:"GET"},t)}getTotalSurplus(e,t={}){return this.fetch({path:`/api/v1/users/${e}/total_surplus`,method:"GET"},t)}getAppData(e,t={}){return this.fetch({path:`/api/v1/app_data/${e}`,method:"GET"},t)}uploadAppData(e,t,n={}){return this.fetch({path:`/api/v1/app_data/${e}`,method:"PUT",body:{fullAppData:t}},n)}getSolverCompetition(e,t={}){return this.fetch({path:`/api/v1/solver_competition${"string"==typeof e?"/by_tx_hash":""}/${e}`,method:"GET"},t)}getOrderLink(e,t){const{chainId:n,env:r}=this.getContextWithOverride(t);return this.getApiBaseUrls(r)[n]+`/api/v1/orders/${e}`}getContextWithOverride(e={}){return I({},this.context,e)}getApiBaseUrls(e){return this.context.baseUrls?this.context.baseUrls:"prod"===e?B:V}fetch(t,n={}){const{chainId:r,env:a,backoffOpts:s}=this.getContextWithOverride(n),i=this.getApiBaseUrls(a)[r],o=s||M;return L(i,t,n.limiterOpts?new e(n.limiterOpts):this.rateLimiter,o)}}var $,W,H,Y,j,Z,K,Q,X,q,z,J,ee,te,ne;!function(e){e.ERC20="erc20",e.INTERNAL="internal"}($||($={})),function(e){var t;(t=e.type||(e.type={})).OPEN="Open",t.SCHEDULED="Scheduled",t.ACTIVE="Active",t.SOLVED="Solved",t.EXECUTING="Executing",t.TRADED="Traded",t.CANCELLED="Cancelled"}(W||(W={})),function(e){e.EIP712="eip712",e.ETHSIGN="ethsign"}(H||(H={})),function(e){var t;(t=e.placementError||(e.placementError={})).QUOTE_NOT_FOUND="QuoteNotFound",t.VALID_TO_TOO_FAR_IN_FUTURE="ValidToTooFarInFuture",t.PRE_VALIDATION_ERROR="PreValidationError"}(Y||(Y={})),function(e){var t;(t=e.errorType||(e.errorType={})).INVALID_SIGNATURE="InvalidSignature",t.WRONG_OWNER="WrongOwner",t.ORDER_NOT_FOUND="OrderNotFound",t.ALREADY_CANCELLED="AlreadyCancelled",t.ORDER_FULLY_EXECUTED="OrderFullyExecuted",t.ORDER_EXPIRED="OrderExpired",t.ON_CHAIN_ORDER="OnChainOrder"}(j||(j={})),function(e){e.MARKET="market",e.LIMIT="limit",e.LIQUIDITY="liquidity"}(Z||(Z={})),function(e){e.BUY="buy",e.SELL="sell"}(K||(K={})),function(e){var t;(t=e.errorType||(e.errorType={})).DUPLICATED_ORDER="DuplicatedOrder",t.QUOTE_NOT_FOUND="QuoteNotFound",t.QUOTE_NOT_VERIFIED="QuoteNotVerified",t.INVALID_QUOTE="InvalidQuote",t.MISSING_FROM="MissingFrom",t.WRONG_OWNER="WrongOwner",t.INVALID_EIP1271SIGNATURE="InvalidEip1271Signature",t.INSUFFICIENT_BALANCE="InsufficientBalance",t.INSUFFICIENT_ALLOWANCE="InsufficientAllowance",t.INVALID_SIGNATURE="InvalidSignature",t.SELL_AMOUNT_OVERFLOW="SellAmountOverflow",t.TRANSFER_SIMULATION_FAILED="TransferSimulationFailed",t.ZERO_AMOUNT="ZeroAmount",t.INCOMPATIBLE_SIGNING_SCHEME="IncompatibleSigningScheme",t.TOO_MANY_LIMIT_ORDERS="TooManyLimitOrders",t.TOO_MUCH_GAS="TooMuchGas",t.UNSUPPORTED_BUY_TOKEN_DESTINATION="UnsupportedBuyTokenDestination",t.UNSUPPORTED_SELL_TOKEN_SOURCE="UnsupportedSellTokenSource",t.UNSUPPORTED_ORDER_TYPE="UnsupportedOrderType",t.INSUFFICIENT_VALID_TO="InsufficientValidTo",t.EXCESSIVE_VALID_TO="ExcessiveValidTo",t.INVALID_NATIVE_SELL_TOKEN="InvalidNativeSellToken",t.SAME_BUY_AND_SELL_TOKEN="SameBuyAndSellToken",t.UNSUPPORTED_TOKEN="UnsupportedToken",t.INVALID_APP_DATA="InvalidAppData",t.APP_DATA_HASH_MISMATCH="AppDataHashMismatch",t.APPDATA_FROM_MISMATCH="AppdataFromMismatch"}(Q||(Q={})),function(e){e.BUY="buy"}(X||(X={})),function(e){e.SELL="sell"}(q||(q={})),function(e){e.PRESIGNATURE_PENDING="presignaturePending",e.OPEN="open",e.FULFILLED="fulfilled",e.CANCELLED="cancelled",e.EXPIRED="expired"}(z||(z={})),function(e){var t;(t=e.errorType||(e.errorType={})).QUOTE_NOT_VERIFIED="QuoteNotVerified",t.UNSUPPORTED_TOKEN="UnsupportedToken",t.ZERO_AMOUNT="ZeroAmount",t.UNSUPPORTED_ORDER_TYPE="UnsupportedOrderType"}(J||(J={})),function(e){e.FAST="fast",e.OPTIMAL="optimal",e.VERIFIED="verified"}(ee||(ee={})),function(e){e.ERC20="erc20",e.INTERNAL="internal",e.EXTERNAL="external"}(te||(te={})),function(e){e.EIP712="eip712",e.ETHSIGN="ethsign",e.PRESIGN="presign",e.EIP1271="eip1271"}(ne||(ne={}));const re=BigInt(1e4);function ae(e){var t;const{orderParams:n,sellDecimals:r,buyDecimals:a,slippagePercentBps:s}=e,i=null!==(t=e.partnerFeeBps)&&void 0!==t?t:0,o=n.kind===K.SELL,p=se(n.feeAmount,r),u=se(n.sellAmount,r),d=se(n.buyAmount,a),l=d.num/u.num,y=se(u.big+p.big,r),c=se(l*y.num,a),m=i>0?(o?c.big:u.big)*BigInt(i)/re:BigInt(0),T=o?{sellAmount:y.big,buyAmount:d.big-m}:{sellAmount:y.big+m,buyAmount:d.big},f=e=>e*BigInt(s)/re,h=o?{sellAmount:T.sellAmount,buyAmount:T.buyAmount-f(T.buyAmount)}:{sellAmount:T.sellAmount+f(T.sellAmount),buyAmount:T.buyAmount};return{isSell:o,costs:{networkFee:{amountInSellCurrency:p.big,amountInBuyCurrency:se(l*p.num,a).big},partnerFee:{amount:m,bps:i}},beforeNetworkCosts:{sellAmount:u.big,buyAmount:c.big},afterNetworkCosts:{sellAmount:y.big,buyAmount:d.big},afterPartnerFees:T,afterSlippage:h}}function se(e,t){if("number"==typeof e){const n=e*10**t,r=n.toFixed();return{big:BigInt(r.includes("e")?n:r),num:e}}const n=BigInt(e);return{big:n,num:Number(n)/10**t}}let ie,oe,pe,ue=e=>e;const de=n(ie||(ie=ue`
2
2
  query Totals {
3
3
  totals {
4
4
  tokens
@@ -11,19 +11,19 @@ import"cross-fetch/polyfill";import{RateLimiter as e}from"limiter";import{backOf
11
11
  feesEth
12
12
  }
13
13
  }
14
- `)),de=n(ie||(ie=pe`
14
+ `)),le=n(oe||(oe=ue`
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
- `)),le=n(oe||(oe=pe`
21
+ `)),ye=n(pe||(pe=ue`
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
- `)),ye="https://api.thegraph.com/subgraphs/name/cowprotocol",ce={[y.MAINNET]:ye+"/cow",[y.GNOSIS_CHAIN]:ye+"/cow-gc",[y.ARBITRUM_ONE]:null,[y.SEPOLIA]:null},me={[y.MAINNET]:ye+"/cow-staging",[y.GNOSIS_CHAIN]:ye+"/cow-gc-staging",[y.ARBITRUM_ONE]:null,[y.SEPOLIA]:null};class Te{constructor(e={}){this.API_NAME="CoW Protocol Subgraph",this.context=void 0,this.context=I({},m,e)}async getTotals(e={}){return(await this.runQuery(ue,void 0,e)).totals[0]}async getLastDaysVolume(e,t={}){return this.runQuery(de,{days:e},t)}async getLastHoursVolume(e,t={}){return this.runQuery(le,{hours:e},t)}async runQuery(e,t=undefined,n={}){const{chainId:a,env:s}=this.getContextWithOverride(n),i=this.getEnvConfigs(s)[a];if(null===i)throw new Error("Unsupported Network. The subgraph API is not available in the Network "+a);try{return await r(i,e,t)}catch(n){throw console.error(`[subgraph:${this.API_NAME}]`,n),new T(`Error running query: ${e}. Variables: ${JSON.stringify(t)}. API: ${i}. Inner Error: ${n}`)}}getContextWithOverride(e={}){return I({},this.context,e)}getEnvConfigs(e){return this.context.baseUrls?this.context.baseUrls:"prod"===e?ce:me}}const fe=()=>import("./utils-4846d038.js");class he{static async signOrder(e,t,n){const{signOrder:r}=await fe();return r(e,t,n)}static async signOrderCancellation(e,t,n){const{signOrderCancellation:r}=await fe();return r(e,t,n)}static async signOrderCancellations(e,t,n){const{signOrderCancellations:r}=await fe();return r(e,t,n)}static async getDomain(e){const{getDomain:t}=await fe();return t(e)}static async getDomainSeparator(e){const{getDomain:t}=await fe(),{_TypedDataEncoder:n}=await import("ethers/lib/utils");return n.hashDomain(t(e))}static getEIP712Types(){return{Order:[{name:"sellToken",type:"address"},{name:"buyToken",type:"address"},{name:"receiver",type:"address"},{name:"sellAmount",type:"uint256"},{name:"buyAmount",type:"uint256"},{name:"validTo",type:"uint32"},{name:"appData",type:"bytes32"},{name:"feeAmount",type:"uint256"},{name:"kind",type:"string"},{name:"partiallyFillable",type:"bool"},{name:"sellTokenBalance",type:"string"},{name:"buyTokenBalance",type:"string"}]}}}var be,Ie;!function(e){e[e.PRIVATE=0]="PRIVATE",e[e.EMITTED=1]="EMITTED",e[e.SWARM=2]="SWARM",e[e.WAKU=3]="WAKU",e[e.RESERVED=4]="RESERVED",e[e.IPFS=5]="IPFS"}(be||(be={})),function(e){e.SUCCESS="SUCCESS",e.UNEXPECTED_ERROR="UNEXPECTED_ERROR",e.TRY_NEXT_BLOCK="TRY_NEXT_BLOCK",e.TRY_ON_BLOCK="TRY_ON_BLOCK",e.TRY_AT_EPOCH="TRY_AT_EPOCH",e.DONT_TRY_AGAIN="DONT_TRY_AGAIN"}(Ie||(Ie={}));const Ae=[{inputs:[{internalType:"address",name:"_settlement",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InterfaceNotSupported",type:"error"},{inputs:[],name:"InvalidHandler",type:"error"},{inputs:[],name:"ProofNotAuthed",type:"error"},{inputs:[],name:"SingleOrderNotAuthed",type:"error"},{inputs:[],name:"SwapGuardRestricted",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],indexed:!1,internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"}],name:"ConditionalOrderCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!1,internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],indexed:!1,internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"}],name:"MerkleRootSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!1,internalType:"contract ISwapGuard",name:"swapGuard",type:"address"}],name:"SwapGuardSet",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"cabinet",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"bool",name:"dispatch",type:"bool"}],name:"create",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"contract IValueFactory",name:"factory",type:"address"},{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bool",name:"dispatch",type:"bool"}],name:"createWithContext",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"domainSeparator",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"bytes",name:"offchainInput",type:"bytes"},{internalType:"bytes32[]",name:"proof",type:"bytes32[]"}],name:"getTradeableOrderWithSignature",outputs:[{components:[{internalType:"contract IERC20",name:"sellToken",type:"address"},{internalType:"contract IERC20",name:"buyToken",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"buyAmount",type:"uint256"},{internalType:"uint32",name:"validTo",type:"uint32"},{internalType:"bytes32",name:"appData",type:"bytes32"},{internalType:"uint256",name:"feeAmount",type:"uint256"},{internalType:"bytes32",name:"kind",type:"bytes32"},{internalType:"bool",name:"partiallyFillable",type:"bool"},{internalType:"bytes32",name:"sellTokenBalance",type:"bytes32"},{internalType:"bytes32",name:"buyTokenBalance",type:"bytes32"}],internalType:"struct GPv2Order.Data",name:"order",type:"tuple"},{internalType:"bytes",name:"signature",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"}],name:"hash",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract Safe",name:"safe",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"bytes32",name:"_hash",type:"bytes32"},{internalType:"bytes32",name:"_domainSeparator",type:"bytes32"},{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"bytes",name:"encodeData",type:"bytes"},{internalType:"bytes",name:"payload",type:"bytes"}],name:"isValidSafeSignature",outputs:[{internalType:"bytes4",name:"magic",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"singleOrderHash",type:"bytes32"}],name:"remove",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"roots",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"}],name:"setRoot",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"},{internalType:"contract IValueFactory",name:"factory",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"setRootWithContext",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract ISwapGuard",name:"swapGuard",type:"address"}],name:"setSwapGuard",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"singleOrders",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"swapGuards",outputs:[{internalType:"contract ISwapGuard",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Ee{static createInterface(){return new a.Interface(Ae)}static connect(e,t){return new s(e,Ae,t)}}Ee.abi=Ae;const Oe=[{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"verifier",type:"address"}],name:"AddedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"AddedInterface",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"},{indexed:!1,internalType:"bytes32",name:"method",type:"bytes32"}],name:"AddedSafeMethod",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"oldVerifier",type:"address"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"newVerifier",type:"address"}],name:"ChangedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"},{indexed:!1,internalType:"bytes32",name:"oldMethod",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"newMethod",type:"bytes32"}],name:"ChangedSafeMethod",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"}],name:"RemovedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"RemovedInterface",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"}],name:"RemovedSafeMethod",type:"event"},{stateMutability:"nonpayable",type:"fallback"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"domainVerifiers",outputs:[{internalType:"contract ISafeSignatureVerifier",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_hash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"isValidSignature",outputs:[{internalType:"bytes4",name:"magic",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155BatchReceived",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155Received",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC721Received",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes4",name:"",type:"bytes4"}],name:"safeInterfaces",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes4",name:"",type:"bytes4"}],name:"safeMethods",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{internalType:"contract ISafeSignatureVerifier",name:"newVerifier",type:"address"}],name:"setDomainVerifier",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"},{internalType:"bytes32",name:"newMethod",type:"bytes32"}],name:"setSafeMethod",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"},{internalType:"bool",name:"supported",type:"bool"}],name:"setSupportedInterface",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"_interfaceId",type:"bytes4"},{internalType:"bytes32[]",name:"handlerWithSelectors",type:"bytes32[]"}],name:"setSupportedInterfaceBatch",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}];class ge{static createInterface(){return new a.Interface(Oe)}static connect(e,t){return new s(e,Oe,t)}}ge.abi=Oe;const Se=["erc20","0x5a28e9363bb942b639270062aa6bb295f434bcdfc42c97267bf003f272060dc9"],Ne=["external","0xabee3b73373acd583a130924aad6dc38cfdc44ba0555ba94ce2ff63980ea0632"],we=["internal","0x4ac99ace14ee0a5ef932dc609df0943ab7ac16b7583634612f8dc35a4289a6ce"],ve=["sell","0xf3b277728b3fee749481eb3e0b3b48980dbbab78658fc419025cb16eee346775"],_e=["buy","0x6ed88e868af0a1983e3886d5f3e95a2fafbd6c3450bc229e27342283dc429ccc"],Pe=["tuple(address handler, bytes32 salt, bytes staticInput)"],Re=(e,t)=>`${t}@${e}`;function Ce(e,t){return e===P[t]}function De(e,t){return e===R[t]}async function Me(e,t,n,r){const a=ge.connect(P[n],r);return await a.callStatic.domainVerifiers(e,t)}function xe(e,t){return ge.createInterface().encodeFunctionData("setDomainVerifier",[e,t])}function Ue(e){return a.defaultAbiCoder.encode(Pe,[e])}function Le(e){const{handler:t,salt:n,staticInput:r}=a.defaultAbiCoder.decode(Pe,e)[0];return{handler:t,salt:n,staticInput:r}}function ke(e,t){try{a.defaultAbiCoder.encode(e,t)}catch(e){return!1}return!0}async function Be(e){const t=await e.getBlock("latest");return{blockNumber:t.number,blockTimestamp:t.timestamp}}function Fe(e){return new Date(1e3*e).toISOString()}function Ve(e){if(Se.includes(e))return u.ERC20;if(Ne.includes(e))return u.EXTERNAL;if(we.includes(e))return u.INTERNAL;throw new Error(`Unknown balance type: ${e}`)}function $e(e){if(ve.includes(e))return d.SELL;if(_e.includes(e))return d.BUY;throw new Error(`Unknown kind: ${e}`)}function Ge(e){const{sellToken:t,sellAmount:n,buyToken:r,buyAmount:a,buyTokenBalance:s,sellTokenBalance:i,feeAmount:o,kind:p,receiver:u,validTo:d,partiallyFillable:l,appData:y}=e;return{sellToken:t,sellAmount:n,buyToken:r,buyAmount:a,feeAmount:o,receiver:u,partiallyFillable:l,appData:y,validTo:Number(d),kind:$e(p.toString()),sellTokenBalance:Ve(i.toString()),buyTokenBalance:Ve(s.toString())}}let We,He;function Ye(){return We||(We=Ee.createInterface()),We}function je(e,t){return He||(He=Ee.connect(R[e],t)),He}class Ze{constructor(e){this.handler=void 0,this.salt=void 0,this.data=void 0,this.staticInput=void 0,this.hasOffChainInput=void 0;const{handler:t,salt:n=a.keccak256(a.randomBytes(32)),data:r,hasOffChainInput:s=!1}=e;if(!i.utils.isAddress(t))throw new Error(`Invalid handler: ${t}`);if(!i.utils.isHexString(n)||32!==i.utils.hexDataLength(n))throw new Error(`Invalid salt: ${n}`);this.handler=t,this.salt=n,this.data=r,this.staticInput=this.transformDataToStruct(r),this.hasOffChainInput=s}get context(){}assertIsValid(){const e=this.isValid();if(!e.isValid)throw new Error(`Invalid order: ${e.reason}`)}get createCalldata(){this.assertIsValid();const e=this.context,t=Ye(),n={handler:this.handler,salt:this.salt,staticInput:this.encodeStaticInput()};if(e){const r=e.factoryArgs?a.defaultAbiCoder.encode(e.factoryArgs.argsType,e.factoryArgs.args):"0x";return t.encodeFunctionData("createWithContext",[n,e.address,r,!0])}return t.encodeFunctionData("create",[n,!0])}get removeCalldata(){return this.assertIsValid(),Ye().encodeFunctionData("remove",[this.id])}get id(){return a.keccak256(this.serialize())}get ctx(){return this.isSingleOrder?this.id:o.HashZero}get leaf(){return{handler:this.handler,salt:this.salt,staticInput:this.encodeStaticInput()}}static leafToId(e){return a.keccak256(Ue(e))}get offChainInput(){return"0x"}encodeStaticInputHelper(e,t){return a.defaultAbiCoder.encode(e,[t])}async poll(e){const{chainId:t,owner:n,provider:r,orderBookApi:a}=e,s=je(t,r);try{const r=this.isValid();if(!r.isValid)return{result:Ie.DONT_TRY_AGAIN,reason:`InvalidConditionalOrder. Reason: ${r.reason}`};const i=await this.pollValidate(e);if(i)return i;if(!await this.isAuthorized(e))return{result:Ie.DONT_TRY_AGAIN,reason:`NotAuthorized: Order ${this.id} is not authorized for ${n} on chain ${t}`};const[o,p]=await s.getTradeableOrderWithSignature(n,this.leaf,this.offChainInput,[]),u=await async function(e,t,n){const{computeOrderUid:r}=await import("@cowprotocol/contracts");return r(await he.getDomain(e),n,t)}(t,n,Ge(o));return await a.getOrder(u).then(()=>!0).catch(()=>!1)?await this.handlePollFailedAlreadyPresent(u,o,e)||{result:Ie.TRY_NEXT_BLOCK,reason:"Order already in orderbook"}:{result:Ie.SUCCESS,order:o,signature:p}}catch(e){return{result:Ie.UNEXPECTED_ERROR,error:e}}}isAuthorized(e){const{chainId:t,owner:n,provider:r}=e;return je(t,r).callStatic.singleOrders(n,this.id)}cabinet(e){const{chainId:t,owner:n,provider:r}=e;return je(t,r).callStatic.cabinet(n,this.ctx)}static deserializeHelper(e,t,n,r){try{const{handler:s,salt:i,staticInput:o}=Le(e);if(s!=t)throw new Error("HandlerMismatch");const[p]=a.defaultAbiCoder.decode(n,o);return r(p,i)}catch(e){throw"HandlerMismatch"===e.message?e:new Error("InvalidSerializedConditionalOrder")}}}const Ke=["orderType"],Xe=["address","bytes32","bytes"],qe=["tuple(bytes32[] proof, tuple(address handler, bytes32 salt, bytes staticInput) params)[]"];class ze{constructor(e,t,n,r=be.PRIVATE){if(this.chain=void 0,this.location=void 0,this.orders={},this.tree=void 0,this.ctx=void 0,this.chain=e,this.location=r,t&&0===Object.keys(t).length)throw new Error("orders must have non-zero length");if(t&&!n||!t&&n)throw new Error("orders cannot have undefined root");for(const e in t)if(t.hasOwnProperty(e)){const n=t[e];if(!ze.orderTypeRegistry.hasOwnProperty(n.orderType))throw new Error(`Unknown order type: ${n.orderType}`)}if(t&&(this.orders=t,this.getOrGenerateTree().root!==n))throw new Error("root mismatch")}static fromJSON(e){const{chain:t,orders:n,root:r,location:a}=JSON.parse(e,(e,t)=>{if("orders"===e&&"object"==typeof t&&null!==t){const e={};for(const n in t)if(t.hasOwnProperty(n)){const r=t[n],{orderType:a}=r,s=A(r,Ke);if(!ze.orderTypeRegistry.hasOwnProperty(a))throw new Error(`Unknown order type: ${a}`);e[n]=new(0,ze.orderTypeRegistry[a])(s)}return e}return"object"==typeof t&&null!==t&&t.hasOwnProperty("type")&&t.hasOwnProperty("hex")&&"BigNumber"===t.type?p.from(t):t}),s=new ze(t,n,r);return s.location=a,s}toJSON(){const e=this.getOrGenerateTree().root;return JSON.stringify(I({},this,{root:e}),(e,t)=>{if("tree"!==e)return"object"==typeof t&&null!==t&&"orderType"in t?I({},t,{orderType:t.orderType}):t})}add(e){e.assertIsValid(),this.orders[e.id]=e,this.reset()}remove(e){delete this.orders[e],this.reset()}update(e,t){const n=t(this.orders[e],this.ctx);delete this.orders[e],this.orders[n.id]=n,this.reset()}getById(e){return this.orders[e]}getByIndex(e){return this.orders[this.orderIds[e]]}get orderIds(){return Object.keys(this.orders)}get root(){return this.getOrGenerateTree().root}getOrGenerateTree(){return this.tree||(this.tree=l.of(Object.values(this.orders).map(e=>[...Object.values(e.leaf)]),Xe)),this.tree}static decodeFromJSON(e){return JSON.parse(e)}async prepareProofStruct(e=this.location,t,n){var r=this;return await async function(){switch(e){case be.PRIVATE:return"0x";case be.EMITTED:return r.encodeToABI(t);case be.SWARM:case be.WAKU:case be.IPFS:if(!n)throw new Error("Must provide an uploader function");try{return await n(r.encodeToJSON(t))}catch(t){throw new Error(`Error uploading to decentralized storage ${e}: ${t}`)}default:throw new Error("Unsupported location")}}().then(t=>{try{return a.hexlify(a.arrayify(t)),this.location=e,{location:e,data:t}}catch(e){throw new Error("data returned by uploader is invalid")}}).catch(e=>{throw new Error(`Error preparing proof struct: ${e}`)})}static async poll(e,t,n,r,a){const s=je(n,r),i=a?await a(e,t.params):"0x";return await s.getTradeableOrderWithSignature(e,t.params,i,t.proof)}dumpProofs(e){return this.encodeToJSON(e)}dumpProofsAndParams(e){return this.getProofs(e)}getProofs(e){return[...this.getOrGenerateTree().entries()].map(([t,n])=>e&&e(n)||void 0===e?{idx:t,value:n}:void 0).reduce((e,t)=>{if(t){const n={handler:t.value[0],salt:t.value[1],staticInput:t.value[2]};e.push({proof:this.getOrGenerateTree().getProof(t.idx),params:n})}return e},[])}encodeToABI(e){return a.defaultAbiCoder.encode(qe,[this.getProofs(e)])}encodeToJSON(e){return JSON.stringify(this.getProofs(e))}reset(){this.tree=void 0}static registerOrderType(e,t){ze.orderTypeRegistry[e]=t}static resetOrderTypeRegistry(){ze.orderTypeRegistry={}}}ze.orderTypeRegistry={};class Je{constructor(e){this.knownOrderTypes=void 0,this.knownOrderTypes=e}fromParams(e){const{handler:t}=e,n=this.knownOrderTypes[t];if(n)return n(e)}}const Qe=["sellAmount","buyAmount","numberOfParts","startTime","timeBetweenParts","durationOfPart"],et=["n","partSellAmount","minPartLimit","t","t0","span"],tt="0x6cF1e9cA41f7611dEf408122793c358a3d11E5a5",nt="0x52eD56Da04309Aca4c3FECC595298d80C2f16BAc",rt=p.from(2).pow(32).sub(1),at=p.from(31536e3),st=["tuple(address sellToken, address buyToken, address receiver, uint256 partSellAmount, uint256 minPartLimit, uint256 t0, uint256 n, uint256 t, uint256 span, bytes32 appData)"];var it,ot;!function(e){e.AUTO="AUTO",e.LIMIT_DURATION="LIMIT_DURATION"}(it||(it={})),function(e){e.AT_MINING_TIME="AT_MINING_TIME",e.AT_EPOCH="AT_EPOCH"}(ot||(ot={}));const pt={startType:ot.AT_MINING_TIME},ut={durationType:it.AUTO};class dt extends Ze{constructor(e){const{handler:t,salt:n,data:r,hasOffChainInput:a}=e;if(t!==tt)throw new Error(`InvalidHandler: Expected: ${tt}, provided: ${t}`);super({handler:tt,salt:n,data:r,hasOffChainInput:a}),this.isSingleOrder=!0}static fromData(e,t){return new dt({handler:tt,data:e,salt:t})}static fromParams(e){return dt.deserialize(Ue(e))}get context(){return this.staticInput.t0.gt(0)?super.context:{address:nt,factoryArgs:void 0}}get orderType(){return"twap"}isValid(){const e=(()=>{const{sellToken:e,sellAmount:t,buyToken:n,buyAmount:r,startTime:a=pt,numberOfParts:s,timeBetweenParts:i,durationOfPart:p=ut}=this.data;if(e==n)return"InvalidSameToken";if(e==o.AddressZero||n==o.AddressZero)return"InvalidToken";if(!t.gt(o.Zero))return"InvalidSellAmount";if(!r.gt(o.Zero))return"InvalidMinBuyAmount";if(a.startType===ot.AT_EPOCH){const e=a.epoch;if(!e.gte(o.Zero)||!e.lt(rt))return"InvalidStartTime"}return s.gt(o.One)&&s.lte(rt)?i.gt(o.Zero)&&i.lte(at)?p.durationType!==it.LIMIT_DURATION||p.duration.lte(i)?ke(st,[this.staticInput])?void 0:"InvalidData":"InvalidSpan":"InvalidFrequency":"InvalidNumParts"})();return e?{isValid:!1,reason:e}:{isValid:!0}}async startTimestamp(e){const{startTime:t}=this.data;if((null==t?void 0:t.startType)===ot.AT_EPOCH)return t.epoch.toNumber();const n=await this.cabinet(e),r=a.defaultAbiCoder.decode(["uint256"],n)[0];if(r.gt(rt))throw new Error(`Cabinet epoch out of range: ${r.toString()}`);const s=r.toNumber();if(0===s)throw new Error("Cabinet is not set. Required for TWAP orders that start at mining time.");return s}endTimestamp(e){const{numberOfParts:t,timeBetweenParts:n,durationOfPart:r}=this.data;return r&&r.durationType===it.LIMIT_DURATION?e+t.sub(1).mul(n).add(r.duration).toNumber():e+t.mul(n).toNumber()}async pollValidate(e){const{blockInfo:t=await Be(e.provider)}=e,{blockTimestamp:n}=t;try{const t=await this.startTimestamp(e);if(t>n)return{result:Ie.TRY_AT_EPOCH,epoch:t,reason:`TWAP hasn't started yet. Starts at ${t} (${Fe(t)})`};const r=this.endTimestamp(t);return n>=r?{result:Ie.DONT_TRY_AGAIN,reason:`TWAP has expired. Expired at ${r} (${Fe(r)})`}:void 0}catch(e){var r,a;return null!=e&&null!=(r=e.message)&&r.includes("Cabinet is not set")?{result:Ie.DONT_TRY_AGAIN,reason:`${null==e?void 0:e.message}. User likely removed the order.`}:null!=e&&null!=(a=e.message)&&a.includes("Cabinet epoch out of range")?{result:Ie.DONT_TRY_AGAIN,reason:`${null==e?void 0:e.message}`}:{result:Ie.UNEXPECTED_ERROR,reason:`Unexpected error: ${e.message}`,error:e}}}async handlePollFailedAlreadyPresent(e,t,n){const{blockInfo:r=await Be(n.provider)}=n,{blockTimestamp:a}=r,s=this.data.timeBetweenParts.toNumber(),{numberOfParts:i}=this.data,o=await this.startTimestamp(n);if(a<o)return{result:Ie.UNEXPECTED_ERROR,reason:`TWAP part hash't started. First TWAP part start at ${o} (${Fe(o)})`,error:void 0};const p=i.mul(s).add(o).toNumber();if(a>=p)return{result:Ie.UNEXPECTED_ERROR,reason:`TWAP is expired. Expired at ${p} (${Fe(p)})`,error:void 0};const u=Math.floor((a-o)/s);if(u===i.toNumber()-1)return{result:Ie.DONT_TRY_AGAIN,reason:`Current active TWAP part (${u+1}/${i}) is already in the Order Book. This was the last TWAP part, no more orders need to be placed`};const d=o+(u+1)*s;return{result:Ie.TRY_AT_EPOCH,epoch:d,reason:`Current active TWAP part (${u+1}/${i}) is already in the Order Book. TWAP part ${u+2} doesn't start until ${d} (${Fe(d)})`}}serialize(){return Ue(this.leaf)}encodeStaticInput(){return super.encodeStaticInputHelper(st,this.staticInput)}static deserialize(e){return super.deserializeHelper(e,tt,st,(e,t)=>new dt({handler:tt,salt:t,data:yt(e)}))}toString(){const{sellAmount:e,sellToken:t,buyAmount:n,buyToken:r,numberOfParts:a,startTime:s=pt,timeBetweenParts:i,durationOfPart:o=ut,receiver:p,appData:u}=this.data,d=s.startType===ot.AT_MINING_TIME?"AT_MINING_TIME":s.epoch.toNumber(),l=o.durationType===it.AUTO?"AUTO":o.duration.toNumber(),y={sellAmount:e.toString(),sellToken:t,buyAmount:n.toString(),buyToken:r,numberOfParts:a.toString(),startTime:d,timeBetweenParts:i.toNumber(),durationOfPart:l,receiver:p,appData:u};return`${this.orderType} (${this.id}): ${JSON.stringify(y)}`}transformDataToStruct(e){return lt(e)}transformStructToData(e){return yt(e)}}function lt(e){const{sellAmount:t,buyAmount:n,numberOfParts:r,startTime:a=pt,timeBetweenParts:s,durationOfPart:i=ut}=e,p=A(e,Qe),{partSellAmount:u,minPartLimit:d}=r&&!r.isZero()?{partSellAmount:t.div(r),minPartLimit:n.div(r)}:{partSellAmount:o.Zero,minPartLimit:o.Zero};return I({partSellAmount:u,minPartLimit:d,t0:a.startType===ot.AT_MINING_TIME?o.Zero:a.epoch,n:r,t:s,span:i.durationType===it.AUTO?o.Zero:i.duration},p)}function yt(e){const{n:t,partSellAmount:n,minPartLimit:r,t:a,t0:s,span:i}=e,o=A(e,et),p=i.isZero()?{durationType:it.AUTO}:{durationType:it.LIMIT_DURATION,duration:i},u=i.isZero()?{startType:ot.AT_MINING_TIME}:{startType:ot.AT_EPOCH,epoch:s};return I({sellAmount:n.mul(t),buyAmount:r.mul(t),startTime:u,numberOfParts:t,timeBetweenParts:a,durationOfPart:p},o)}const ct={[tt]:e=>dt.fromParams(e)};export{Le as $,S as A,E as B,T as C,m as D,W as E,C as F,M as G,x as H,L as I,re as J,ce as K,me as L,Te as M,he as N,B as O,J as P,be as Q,Ie as R,y as S,Pe as T,Re as U,Ce as V,De as W,Me as X,xe as Y,Ue as Z,I as _,v as a,ke as a0,Be as a1,Fe as a2,Ge as a3,Ze as a4,ze as a5,Je as a6,ct as a7,tt as a8,nt as a9,rt as aa,at as ab,it as ac,ot as ad,dt as ae,lt as af,yt as ag,c as b,h as c,b as d,O as e,g as f,w as g,_ as h,P as i,R as j,F as k,f as l,N as m,$ as n,G as o,H as p,Y as q,j as r,Z as s,K as t,X as u,q as v,z as w,Q as x,ee as y,te as z};
29
- //# sourceMappingURL=index-41ff23de.js.map
28
+ `)),ce="https://api.thegraph.com/subgraphs/name/cowprotocol",me={[y.MAINNET]:ce+"/cow",[y.GNOSIS_CHAIN]:ce+"/cow-gc",[y.ARBITRUM_ONE]:null,[y.SEPOLIA]:null},Te={[y.MAINNET]:ce+"/cow-staging",[y.GNOSIS_CHAIN]:ce+"/cow-gc-staging",[y.ARBITRUM_ONE]:null,[y.SEPOLIA]:null};class fe{constructor(e={}){this.API_NAME="CoW Protocol Subgraph",this.context=void 0,this.context=I({},m,e)}async getTotals(e={}){return(await this.runQuery(de,void 0,e)).totals[0]}async getLastDaysVolume(e,t={}){return this.runQuery(le,{days:e},t)}async getLastHoursVolume(e,t={}){return this.runQuery(ye,{hours:e},t)}async runQuery(e,t=undefined,n={}){const{chainId:a,env:s}=this.getContextWithOverride(n),i=this.getEnvConfigs(s)[a];if(null===i)throw new Error("Unsupported Network. The subgraph API is not available in the Network "+a);try{return await r(i,e,t)}catch(n){throw console.error(`[subgraph:${this.API_NAME}]`,n),new T(`Error running query: ${e}. Variables: ${JSON.stringify(t)}. API: ${i}. Inner Error: ${n}`)}}getContextWithOverride(e={}){return I({},this.context,e)}getEnvConfigs(e){return this.context.baseUrls?this.context.baseUrls:"prod"===e?me:Te}}const he=()=>import("./utils-8c04641d.js");class be{static async signOrder(e,t,n){const{signOrder:r}=await he();return r(e,t,n)}static async signOrderCancellation(e,t,n){const{signOrderCancellation:r}=await he();return r(e,t,n)}static async signOrderCancellations(e,t,n){const{signOrderCancellations:r}=await he();return r(e,t,n)}static async getDomain(e){const{getDomain:t}=await he();return t(e)}static async getDomainSeparator(e){const{getDomain:t}=await he(),{_TypedDataEncoder:n}=await import("ethers/lib/utils");return n.hashDomain(t(e))}static getEIP712Types(){return{Order:[{name:"sellToken",type:"address"},{name:"buyToken",type:"address"},{name:"receiver",type:"address"},{name:"sellAmount",type:"uint256"},{name:"buyAmount",type:"uint256"},{name:"validTo",type:"uint32"},{name:"appData",type:"bytes32"},{name:"feeAmount",type:"uint256"},{name:"kind",type:"string"},{name:"partiallyFillable",type:"bool"},{name:"sellTokenBalance",type:"string"},{name:"buyTokenBalance",type:"string"}]}}}var Ie,Ee;!function(e){e[e.PRIVATE=0]="PRIVATE",e[e.EMITTED=1]="EMITTED",e[e.SWARM=2]="SWARM",e[e.WAKU=3]="WAKU",e[e.RESERVED=4]="RESERVED",e[e.IPFS=5]="IPFS"}(Ie||(Ie={})),function(e){e.SUCCESS="SUCCESS",e.UNEXPECTED_ERROR="UNEXPECTED_ERROR",e.TRY_NEXT_BLOCK="TRY_NEXT_BLOCK",e.TRY_ON_BLOCK="TRY_ON_BLOCK",e.TRY_AT_EPOCH="TRY_AT_EPOCH",e.DONT_TRY_AGAIN="DONT_TRY_AGAIN"}(Ee||(Ee={}));const Ae=[{inputs:[{internalType:"address",name:"_settlement",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{inputs:[],name:"InterfaceNotSupported",type:"error"},{inputs:[],name:"InvalidHandler",type:"error"},{inputs:[],name:"ProofNotAuthed",type:"error"},{inputs:[],name:"SingleOrderNotAuthed",type:"error"},{inputs:[],name:"SwapGuardRestricted",type:"error"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],indexed:!1,internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"}],name:"ConditionalOrderCreated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!1,internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],indexed:!1,internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"}],name:"MerkleRootSet",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!1,internalType:"contract ISwapGuard",name:"swapGuard",type:"address"}],name:"SwapGuardSet",type:"event"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"cabinet",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"bool",name:"dispatch",type:"bool"}],name:"create",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"contract IValueFactory",name:"factory",type:"address"},{internalType:"bytes",name:"data",type:"bytes"},{internalType:"bool",name:"dispatch",type:"bool"}],name:"createWithContext",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"domainSeparator",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"owner",type:"address"},{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"},{internalType:"bytes",name:"offchainInput",type:"bytes"},{internalType:"bytes32[]",name:"proof",type:"bytes32[]"}],name:"getTradeableOrderWithSignature",outputs:[{components:[{internalType:"contract IERC20",name:"sellToken",type:"address"},{internalType:"contract IERC20",name:"buyToken",type:"address"},{internalType:"address",name:"receiver",type:"address"},{internalType:"uint256",name:"sellAmount",type:"uint256"},{internalType:"uint256",name:"buyAmount",type:"uint256"},{internalType:"uint32",name:"validTo",type:"uint32"},{internalType:"bytes32",name:"appData",type:"bytes32"},{internalType:"uint256",name:"feeAmount",type:"uint256"},{internalType:"bytes32",name:"kind",type:"bytes32"},{internalType:"bool",name:"partiallyFillable",type:"bool"},{internalType:"bytes32",name:"sellTokenBalance",type:"bytes32"},{internalType:"bytes32",name:"buyTokenBalance",type:"bytes32"}],internalType:"struct GPv2Order.Data",name:"order",type:"tuple"},{internalType:"bytes",name:"signature",type:"bytes"}],stateMutability:"view",type:"function"},{inputs:[{components:[{internalType:"contract IConditionalOrder",name:"handler",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"bytes",name:"staticInput",type:"bytes"}],internalType:"struct IConditionalOrder.ConditionalOrderParams",name:"params",type:"tuple"}],name:"hash",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract Safe",name:"safe",type:"address"},{internalType:"address",name:"sender",type:"address"},{internalType:"bytes32",name:"_hash",type:"bytes32"},{internalType:"bytes32",name:"_domainSeparator",type:"bytes32"},{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"bytes",name:"encodeData",type:"bytes"},{internalType:"bytes",name:"payload",type:"bytes"}],name:"isValidSafeSignature",outputs:[{internalType:"bytes4",name:"magic",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"singleOrderHash",type:"bytes32"}],name:"remove",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"roots",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"}],name:"setRoot",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes32",name:"root",type:"bytes32"},{components:[{internalType:"uint256",name:"location",type:"uint256"},{internalType:"bytes",name:"data",type:"bytes"}],internalType:"struct ComposableCoW.Proof",name:"proof",type:"tuple"},{internalType:"contract IValueFactory",name:"factory",type:"address"},{internalType:"bytes",name:"data",type:"bytes"}],name:"setRootWithContext",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"contract ISwapGuard",name:"swapGuard",type:"address"}],name:"setSwapGuard",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"singleOrders",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"}],name:"swapGuards",outputs:[{internalType:"contract ISwapGuard",name:"",type:"address"}],stateMutability:"view",type:"function"}];class Oe{static createInterface(){return new a.Interface(Ae)}static connect(e,t){return new s(e,Ae,t)}}Oe.abi=Ae;const ge=[{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"verifier",type:"address"}],name:"AddedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"AddedInterface",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"},{indexed:!1,internalType:"bytes32",name:"method",type:"bytes32"}],name:"AddedSafeMethod",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"oldVerifier",type:"address"},{indexed:!1,internalType:"contract ISafeSignatureVerifier",name:"newVerifier",type:"address"}],name:"ChangedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"},{indexed:!1,internalType:"bytes32",name:"oldMethod",type:"bytes32"},{indexed:!1,internalType:"bytes32",name:"newMethod",type:"bytes32"}],name:"ChangedSafeMethod",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes32",name:"domainSeparator",type:"bytes32"}],name:"RemovedDomainVerifier",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"RemovedInterface",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"contract Safe",name:"safe",type:"address"},{indexed:!1,internalType:"bytes4",name:"selector",type:"bytes4"}],name:"RemovedSafeMethod",type:"event"},{stateMutability:"nonpayable",type:"fallback"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes32",name:"",type:"bytes32"}],name:"domainVerifiers",outputs:[{internalType:"contract ISafeSignatureVerifier",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"_hash",type:"bytes32"},{internalType:"bytes",name:"signature",type:"bytes"}],name:"isValidSignature",outputs:[{internalType:"bytes4",name:"magic",type:"bytes4"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"uint256[]",name:"",type:"uint256[]"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155BatchReceived",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC1155Received",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"address",name:"",type:"address"},{internalType:"address",name:"",type:"address"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"bytes",name:"",type:"bytes"}],name:"onERC721Received",outputs:[{internalType:"bytes4",name:"",type:"bytes4"}],stateMutability:"pure",type:"function"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes4",name:"",type:"bytes4"}],name:"safeInterfaces",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"contract Safe",name:"",type:"address"},{internalType:"bytes4",name:"",type:"bytes4"}],name:"safeMethods",outputs:[{internalType:"bytes32",name:"",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes32",name:"domainSeparator",type:"bytes32"},{internalType:"contract ISafeSignatureVerifier",name:"newVerifier",type:"address"}],name:"setDomainVerifier",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"selector",type:"bytes4"},{internalType:"bytes32",name:"newMethod",type:"bytes32"}],name:"setSafeMethod",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"},{internalType:"bool",name:"supported",type:"bool"}],name:"setSupportedInterface",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"_interfaceId",type:"bytes4"},{internalType:"bytes32[]",name:"handlerWithSelectors",type:"bytes32[]"}],name:"setSupportedInterfaceBatch",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes4",name:"interfaceId",type:"bytes4"}],name:"supportsInterface",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"view",type:"function"}];class Se{static createInterface(){return new a.Interface(ge)}static connect(e,t){return new s(e,ge,t)}}Se.abi=ge;const Ne=["erc20","0x5a28e9363bb942b639270062aa6bb295f434bcdfc42c97267bf003f272060dc9"],ve=["external","0xabee3b73373acd583a130924aad6dc38cfdc44ba0555ba94ce2ff63980ea0632"],we=["internal","0x4ac99ace14ee0a5ef932dc609df0943ab7ac16b7583634612f8dc35a4289a6ce"],_e=["sell","0xf3b277728b3fee749481eb3e0b3b48980dbbab78658fc419025cb16eee346775"],Pe=["buy","0x6ed88e868af0a1983e3886d5f3e95a2fafbd6c3450bc229e27342283dc429ccc"],Re=["tuple(address handler, bytes32 salt, bytes staticInput)"],Ce=(e,t)=>`${t}@${e}`;function De(e,t){return e===P[t]}function Me(e,t){return e===R[t]}async function Ue(e,t,n,r){const a=Se.connect(P[n],r);return await a.callStatic.domainVerifiers(e,t)}function xe(e,t){return Se.createInterface().encodeFunctionData("setDomainVerifier",[e,t])}function Le(e){return a.defaultAbiCoder.encode(Re,[e])}function ke(e){const{handler:t,salt:n,staticInput:r}=a.defaultAbiCoder.decode(Re,e)[0];return{handler:t,salt:n,staticInput:r}}function Be(e,t){try{a.defaultAbiCoder.encode(e,t)}catch(e){return!1}return!0}async function Ve(e){const t=await e.getBlock("latest");return{blockNumber:t.number,blockTimestamp:t.timestamp}}function Fe(e){return new Date(1e3*e).toISOString()}function Ge(e){if(Ne.includes(e))return u.ERC20;if(ve.includes(e))return u.EXTERNAL;if(we.includes(e))return u.INTERNAL;throw new Error(`Unknown balance type: ${e}`)}function $e(e){if(_e.includes(e))return d.SELL;if(Pe.includes(e))return d.BUY;throw new Error(`Unknown kind: ${e}`)}function We(e){const{sellToken:t,sellAmount:n,buyToken:r,buyAmount:a,buyTokenBalance:s,sellTokenBalance:i,feeAmount:o,kind:p,receiver:u,validTo:d,partiallyFillable:l,appData:y}=e;return{sellToken:t,sellAmount:n,buyToken:r,buyAmount:a,feeAmount:o,receiver:u,partiallyFillable:l,appData:y,validTo:Number(d),kind:$e(p.toString()),sellTokenBalance:Ge(i.toString()),buyTokenBalance:Ge(s.toString())}}let He,Ye;function je(){return He||(He=Oe.createInterface()),He}function Ze(e,t){return Ye||(Ye=Oe.connect(R[e],t)),Ye}class Ke{constructor(e){this.handler=void 0,this.salt=void 0,this.data=void 0,this.staticInput=void 0,this.hasOffChainInput=void 0;const{handler:t,salt:n=a.keccak256(a.randomBytes(32)),data:r,hasOffChainInput:s=!1}=e;if(!i.utils.isAddress(t))throw new Error(`Invalid handler: ${t}`);if(!i.utils.isHexString(n)||32!==i.utils.hexDataLength(n))throw new Error(`Invalid salt: ${n}`);this.handler=t,this.salt=n,this.data=r,this.staticInput=this.transformDataToStruct(r),this.hasOffChainInput=s}get context(){}assertIsValid(){const e=this.isValid();if(!e.isValid)throw new Error(`Invalid order: ${e.reason}`)}get createCalldata(){this.assertIsValid();const e=this.context,t=je(),n={handler:this.handler,salt:this.salt,staticInput:this.encodeStaticInput()};if(e){const r=e.factoryArgs?a.defaultAbiCoder.encode(e.factoryArgs.argsType,e.factoryArgs.args):"0x";return t.encodeFunctionData("createWithContext",[n,e.address,r,!0])}return t.encodeFunctionData("create",[n,!0])}get removeCalldata(){return this.assertIsValid(),je().encodeFunctionData("remove",[this.id])}get id(){return a.keccak256(this.serialize())}get ctx(){return this.isSingleOrder?this.id:o.HashZero}get leaf(){return{handler:this.handler,salt:this.salt,staticInput:this.encodeStaticInput()}}static leafToId(e){return a.keccak256(Le(e))}get offChainInput(){return"0x"}encodeStaticInputHelper(e,t){return a.defaultAbiCoder.encode(e,[t])}async poll(e){const{chainId:t,owner:n,provider:r,orderBookApi:a}=e,s=Ze(t,r);try{const r=this.isValid();if(!r.isValid)return{result:Ee.DONT_TRY_AGAIN,reason:`InvalidConditionalOrder. Reason: ${r.reason}`};const i=await this.pollValidate(e);if(i)return i;if(!await this.isAuthorized(e))return{result:Ee.DONT_TRY_AGAIN,reason:`NotAuthorized: Order ${this.id} is not authorized for ${n} on chain ${t}`};const[o,p]=await s.getTradeableOrderWithSignature(n,this.leaf,this.offChainInput,[]),u=await async function(e,t,n){const{computeOrderUid:r}=await import("@cowprotocol/contracts");return r(await be.getDomain(e),n,t)}(t,n,We(o));return await a.getOrder(u).then(()=>!0).catch(()=>!1)?await this.handlePollFailedAlreadyPresent(u,o,e)||{result:Ee.TRY_NEXT_BLOCK,reason:"Order already in orderbook"}:{result:Ee.SUCCESS,order:o,signature:p}}catch(e){return{result:Ee.UNEXPECTED_ERROR,error:e}}}isAuthorized(e){const{chainId:t,owner:n,provider:r}=e;return Ze(t,r).callStatic.singleOrders(n,this.id)}cabinet(e){const{chainId:t,owner:n,provider:r}=e;return Ze(t,r).callStatic.cabinet(n,this.ctx)}static deserializeHelper(e,t,n,r){try{const{handler:s,salt:i,staticInput:o}=ke(e);if(s!=t)throw new Error("HandlerMismatch");const[p]=a.defaultAbiCoder.decode(n,o);return r(p,i)}catch(e){throw"HandlerMismatch"===e.message?e:new Error("InvalidSerializedConditionalOrder")}}}const Qe=["orderType"],Xe=["address","bytes32","bytes"],qe=["tuple(bytes32[] proof, tuple(address handler, bytes32 salt, bytes staticInput) params)[]"];class ze{constructor(e,t,n,r=Ie.PRIVATE){if(this.chain=void 0,this.location=void 0,this.orders={},this.tree=void 0,this.ctx=void 0,this.chain=e,this.location=r,t&&0===Object.keys(t).length)throw new Error("orders must have non-zero length");if(t&&!n||!t&&n)throw new Error("orders cannot have undefined root");for(const e in t)if(t.hasOwnProperty(e)){const n=t[e];if(!ze.orderTypeRegistry.hasOwnProperty(n.orderType))throw new Error(`Unknown order type: ${n.orderType}`)}if(t&&(this.orders=t,this.getOrGenerateTree().root!==n))throw new Error("root mismatch")}static fromJSON(e){const{chain:t,orders:n,root:r,location:a}=JSON.parse(e,(e,t)=>{if("orders"===e&&"object"==typeof t&&null!==t){const e={};for(const n in t)if(t.hasOwnProperty(n)){const r=t[n],{orderType:a}=r,s=E(r,Qe);if(!ze.orderTypeRegistry.hasOwnProperty(a))throw new Error(`Unknown order type: ${a}`);e[n]=new(0,ze.orderTypeRegistry[a])(s)}return e}return"object"==typeof t&&null!==t&&t.hasOwnProperty("type")&&t.hasOwnProperty("hex")&&"BigNumber"===t.type?p.from(t):t}),s=new ze(t,n,r);return s.location=a,s}toJSON(){const e=this.getOrGenerateTree().root;return JSON.stringify(I({},this,{root:e}),(e,t)=>{if("tree"!==e)return"object"==typeof t&&null!==t&&"orderType"in t?I({},t,{orderType:t.orderType}):t})}add(e){e.assertIsValid(),this.orders[e.id]=e,this.reset()}remove(e){delete this.orders[e],this.reset()}update(e,t){const n=t(this.orders[e],this.ctx);delete this.orders[e],this.orders[n.id]=n,this.reset()}getById(e){return this.orders[e]}getByIndex(e){return this.orders[this.orderIds[e]]}get orderIds(){return Object.keys(this.orders)}get root(){return this.getOrGenerateTree().root}getOrGenerateTree(){return this.tree||(this.tree=l.of(Object.values(this.orders).map(e=>[...Object.values(e.leaf)]),Xe)),this.tree}static decodeFromJSON(e){return JSON.parse(e)}async prepareProofStruct(e=this.location,t,n){var r=this;return await async function(){switch(e){case Ie.PRIVATE:return"0x";case Ie.EMITTED:return r.encodeToABI(t);case Ie.SWARM:case Ie.WAKU:case Ie.IPFS:if(!n)throw new Error("Must provide an uploader function");try{return await n(r.encodeToJSON(t))}catch(t){throw new Error(`Error uploading to decentralized storage ${e}: ${t}`)}default:throw new Error("Unsupported location")}}().then(t=>{try{return a.hexlify(a.arrayify(t)),this.location=e,{location:e,data:t}}catch(e){throw new Error("data returned by uploader is invalid")}}).catch(e=>{throw new Error(`Error preparing proof struct: ${e}`)})}static async poll(e,t,n,r,a){const s=Ze(n,r),i=a?await a(e,t.params):"0x";return await s.getTradeableOrderWithSignature(e,t.params,i,t.proof)}dumpProofs(e){return this.encodeToJSON(e)}dumpProofsAndParams(e){return this.getProofs(e)}getProofs(e){return[...this.getOrGenerateTree().entries()].map(([t,n])=>e&&e(n)||void 0===e?{idx:t,value:n}:void 0).reduce((e,t)=>{if(t){const n={handler:t.value[0],salt:t.value[1],staticInput:t.value[2]};e.push({proof:this.getOrGenerateTree().getProof(t.idx),params:n})}return e},[])}encodeToABI(e){return a.defaultAbiCoder.encode(qe,[this.getProofs(e)])}encodeToJSON(e){return JSON.stringify(this.getProofs(e))}reset(){this.tree=void 0}static registerOrderType(e,t){ze.orderTypeRegistry[e]=t}static resetOrderTypeRegistry(){ze.orderTypeRegistry={}}}ze.orderTypeRegistry={};class Je{constructor(e){this.knownOrderTypes=void 0,this.knownOrderTypes=e}fromParams(e){const{handler:t}=e,n=this.knownOrderTypes[t];if(n)return n(e)}}const et=["sellAmount","buyAmount","numberOfParts","startTime","timeBetweenParts","durationOfPart"],tt=["n","partSellAmount","minPartLimit","t","t0","span"],nt="0x6cF1e9cA41f7611dEf408122793c358a3d11E5a5",rt="0x52eD56Da04309Aca4c3FECC595298d80C2f16BAc",at=p.from(2).pow(32).sub(1),st=p.from(31536e3),it=["tuple(address sellToken, address buyToken, address receiver, uint256 partSellAmount, uint256 minPartLimit, uint256 t0, uint256 n, uint256 t, uint256 span, bytes32 appData)"];var ot,pt;!function(e){e.AUTO="AUTO",e.LIMIT_DURATION="LIMIT_DURATION"}(ot||(ot={})),function(e){e.AT_MINING_TIME="AT_MINING_TIME",e.AT_EPOCH="AT_EPOCH"}(pt||(pt={}));const ut={startType:pt.AT_MINING_TIME},dt={durationType:ot.AUTO};class lt extends Ke{constructor(e){const{handler:t,salt:n,data:r,hasOffChainInput:a}=e;if(t!==nt)throw new Error(`InvalidHandler: Expected: ${nt}, provided: ${t}`);super({handler:nt,salt:n,data:r,hasOffChainInput:a}),this.isSingleOrder=!0}static fromData(e,t){return new lt({handler:nt,data:e,salt:t})}static fromParams(e){return lt.deserialize(Le(e))}get context(){return this.staticInput.t0.gt(0)?super.context:{address:rt,factoryArgs:void 0}}get orderType(){return"twap"}isValid(){const e=(()=>{const{sellToken:e,sellAmount:t,buyToken:n,buyAmount:r,startTime:a=ut,numberOfParts:s,timeBetweenParts:i,durationOfPart:p=dt}=this.data;if(e==n)return"InvalidSameToken";if(e==o.AddressZero||n==o.AddressZero)return"InvalidToken";if(!t.gt(o.Zero))return"InvalidSellAmount";if(!r.gt(o.Zero))return"InvalidMinBuyAmount";if(a.startType===pt.AT_EPOCH){const e=a.epoch;if(!e.gte(o.Zero)||!e.lt(at))return"InvalidStartTime"}return s.gt(o.One)&&s.lte(at)?i.gt(o.Zero)&&i.lte(st)?p.durationType!==ot.LIMIT_DURATION||p.duration.lte(i)?Be(it,[this.staticInput])?void 0:"InvalidData":"InvalidSpan":"InvalidFrequency":"InvalidNumParts"})();return e?{isValid:!1,reason:e}:{isValid:!0}}async startTimestamp(e){const{startTime:t}=this.data;if((null==t?void 0:t.startType)===pt.AT_EPOCH)return t.epoch.toNumber();const n=await this.cabinet(e),r=a.defaultAbiCoder.decode(["uint256"],n)[0];if(r.gt(at))throw new Error(`Cabinet epoch out of range: ${r.toString()}`);const s=r.toNumber();if(0===s)throw new Error("Cabinet is not set. Required for TWAP orders that start at mining time.");return s}endTimestamp(e){const{numberOfParts:t,timeBetweenParts:n,durationOfPart:r}=this.data;return r&&r.durationType===ot.LIMIT_DURATION?e+t.sub(1).mul(n).add(r.duration).toNumber():e+t.mul(n).toNumber()}async pollValidate(e){const{blockInfo:t=await Ve(e.provider)}=e,{blockTimestamp:n}=t;try{const t=await this.startTimestamp(e);if(t>n)return{result:Ee.TRY_AT_EPOCH,epoch:t,reason:`TWAP hasn't started yet. Starts at ${t} (${Fe(t)})`};const r=this.endTimestamp(t);return n>=r?{result:Ee.DONT_TRY_AGAIN,reason:`TWAP has expired. Expired at ${r} (${Fe(r)})`}:void 0}catch(e){var r,a;return null!=e&&null!=(r=e.message)&&r.includes("Cabinet is not set")?{result:Ee.DONT_TRY_AGAIN,reason:`${null==e?void 0:e.message}. User likely removed the order.`}:null!=e&&null!=(a=e.message)&&a.includes("Cabinet epoch out of range")?{result:Ee.DONT_TRY_AGAIN,reason:`${null==e?void 0:e.message}`}:{result:Ee.UNEXPECTED_ERROR,reason:`Unexpected error: ${e.message}`,error:e}}}async handlePollFailedAlreadyPresent(e,t,n){const{blockInfo:r=await Ve(n.provider)}=n,{blockTimestamp:a}=r,s=this.data.timeBetweenParts.toNumber(),{numberOfParts:i}=this.data,o=await this.startTimestamp(n);if(a<o)return{result:Ee.UNEXPECTED_ERROR,reason:`TWAP part hash't started. First TWAP part start at ${o} (${Fe(o)})`,error:void 0};const p=i.mul(s).add(o).toNumber();if(a>=p)return{result:Ee.UNEXPECTED_ERROR,reason:`TWAP is expired. Expired at ${p} (${Fe(p)})`,error:void 0};const u=Math.floor((a-o)/s);if(u===i.toNumber()-1)return{result:Ee.DONT_TRY_AGAIN,reason:`Current active TWAP part (${u+1}/${i}) is already in the Order Book. This was the last TWAP part, no more orders need to be placed`};const d=o+(u+1)*s;return{result:Ee.TRY_AT_EPOCH,epoch:d,reason:`Current active TWAP part (${u+1}/${i}) is already in the Order Book. TWAP part ${u+2} doesn't start until ${d} (${Fe(d)})`}}serialize(){return Le(this.leaf)}encodeStaticInput(){return super.encodeStaticInputHelper(it,this.staticInput)}static deserialize(e){return super.deserializeHelper(e,nt,it,(e,t)=>new lt({handler:nt,salt:t,data:ct(e)}))}toString(){const{sellAmount:e,sellToken:t,buyAmount:n,buyToken:r,numberOfParts:a,startTime:s=ut,timeBetweenParts:i,durationOfPart:o=dt,receiver:p,appData:u}=this.data,d=s.startType===pt.AT_MINING_TIME?"AT_MINING_TIME":s.epoch.toNumber(),l=o.durationType===ot.AUTO?"AUTO":o.duration.toNumber(),y={sellAmount:e.toString(),sellToken:t,buyAmount:n.toString(),buyToken:r,numberOfParts:a.toString(),startTime:d,timeBetweenParts:i.toNumber(),durationOfPart:l,receiver:p,appData:u};return`${this.orderType} (${this.id}): ${JSON.stringify(y)}`}transformDataToStruct(e){return yt(e)}transformStructToData(e){return ct(e)}}function yt(e){const{sellAmount:t,buyAmount:n,numberOfParts:r,startTime:a=ut,timeBetweenParts:s,durationOfPart:i=dt}=e,p=E(e,et),{partSellAmount:u,minPartLimit:d}=r&&!r.isZero()?{partSellAmount:t.div(r),minPartLimit:n.div(r)}:{partSellAmount:o.Zero,minPartLimit:o.Zero};return I({partSellAmount:u,minPartLimit:d,t0:a.startType===pt.AT_MINING_TIME?o.Zero:a.epoch,n:r,t:s,span:i.durationType===ot.AUTO?o.Zero:i.duration},p)}function ct(e){const{n:t,partSellAmount:n,minPartLimit:r,t:a,t0:s,span:i}=e,o=E(e,tt),p=i.isZero()?{durationType:ot.AUTO}:{durationType:ot.LIMIT_DURATION,duration:i},u=i.isZero()?{startType:pt.AT_MINING_TIME}:{startType:pt.AT_EPOCH,epoch:s};return I({sellAmount:n.mul(t),buyAmount:r.mul(t),startTime:u,numberOfParts:t,timeBetweenParts:a,durationOfPart:p},o)}const mt={[nt]:e=>lt.fromParams(e)};export{Le as $,S as A,A as B,T as C,m as D,H as E,ne as F,C as G,M as H,U as I,L as J,ae as K,me as L,Te as M,fe as N,B as O,J as P,be as Q,Ie as R,y as S,Ee as T,Re as U,Ce as V,De as W,Me as X,Ue as Y,xe as Z,I as _,w as a,ke as a0,Be as a1,Ve as a2,Fe as a3,We as a4,Ke as a5,ze as a6,Je as a7,mt as a8,nt as a9,rt as aa,at as ab,st as ac,ot as ad,pt as ae,lt as af,yt as ag,ct as ah,c as b,h as c,b as d,O as e,g as f,v as g,_ as h,P as i,R as j,V as k,f as l,N as m,G as n,$ as o,W as p,Y as q,j as r,Z as s,K as t,Q as u,X as v,q as w,z as x,ee as y,te as z};
29
+ //# sourceMappingURL=index-18d1e1e2.js.map