@cowprotocol/permit-utils 0.1.1-RC.1 → 0.2.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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * ABIs for fetching the version of different permit flavours
3
+ */
4
+ export declare const VERSION_ABIS: {
5
+ constant: boolean;
6
+ inputs: never[];
7
+ name: string;
8
+ outputs: {
9
+ name: string;
10
+ type: string;
11
+ }[];
12
+ payable: boolean;
13
+ stateMutability: string;
14
+ type: string;
15
+ }[][];
package/const.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Wallet } from '@ethersproject/wallet';
2
2
  export declare const PERMIT_SIGNER: Wallet;
3
- export declare const PERMIT_GAS_LIMIT_MIN: Record<number, number>;
3
+ export declare const DEFAULT_MIN_GAS_LIMIT = 55000;
4
4
  export declare const DEFAULT_PERMIT_GAS_LIMIT = "80000";
5
5
  export declare const DEFAULT_PERMIT_VALUE: string;
6
6
  export declare const DEFAULT_PERMIT_DURATION: number;
7
- export declare const TOKENS_TO_SKIP_VERSION: Set<string>;
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("@ethersproject/constants"),O=require("@ethersproject/wallet"),p=require("@1inch/permit-signed-approvals-utils"),C=require("@ethersproject/abi"),F=require("@ethersproject/bignumber"),x=require("@ethersproject/contracts"),v=require("@ethersproject/address"),G="0x4dae303b820e9878cafeb0f84edcc015e8a81b1bff510e824e4fc27544e458dd",I=new O.Wallet(G),h=55e3,q={1:h,100:h,11155111:h,5:36e3},T="80000",S=H.MaxUint256.toString(),K=157788e6,V=new Set(["0x6b175474e89094c44da98b954eedeac495271d0f"]);async function B(r,t,e,a,n,o,{version:c,type:s,name:l}){const d=l||n;if(s==="unsupported")return!1;if(!d)throw new Error(`No token name for ${a}`);const m={chainId:t,tokenName:d,tokenAddress:a,callData:o,version:c};let u;if(o.startsWith(p.EIP_2612_PERMIT_SELECTOR)?u=e.recoverPermitOwnerFromCallData({...m,callData:o.replace(p.EIP_2612_PERMIT_SELECTOR,"0x")}):o.startsWith(p.DAI_PERMIT_SELECTOR)&&(u=e.recoverDaiLikePermitOwnerFromCallData({...m,callData:o.replace(p.DAI_PERMIT_SELECTOR,"0x")})),!!u)try{return(await u).toLowerCase()===r.toLowerCase()}catch(i){return console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${r} with callData ${o}`,i),!1}}async function L({eip2162Utils:r,callDataParams:t}){const[e,a,n,...o]=t;return(await r.buildPermitCallData(e,a,n,...o)).replace("0x",p.EIP_2612_PERMIT_SELECTOR)}async function R({eip2162Utils:r,callDataParams:t}){return(await r.buildDaiLikePermitCallData(...t)).replace("0x",p.DAI_PERMIT_SELECTOR)}function y(){return Math.ceil((Date.now()+K)/1e3)}function $(r){return!!r&&r.type!=="unsupported"}const g={};async function j(r){const t=Y(r),e=g[t];if(e)try{return await e}catch(n){console.debug("[generatePermitHookWith] cached request failed",n),delete g[t]}const a=W(r).then(n=>(delete g[t],n));return g[t]=a,a}async function W(r){const{inputToken:t,spender:e,chainId:a,permitInfo:n,provider:o,account:c,eip2162Utils:s,nonce:l}=r,d=t.address,m=n.name||t.name;if(!$(n))throw new Error(`Trying to generate permit hook for unsupported token: ${d}`);if(!m)throw new Error(`No token name for token: ${d}`);const u=c||I.address,i=l===void 0?await s.getTokenNonce(d,u):l,f=y(),w=S,k=n.type==="eip-2612"?await L({eip2162Utils:s,callDataParams:[{owner:u,spender:e,value:w,nonce:i,deadline:f},a,m,d,n.version]}):await R({eip2162Utils:s,callDataParams:[{holder:u,spender:e,allowed:!0,value:w,nonce:i,expiry:f},a,m,d,n.version]}),U=await Q(k,u,d,o,!!c);return{target:d,callData:k,gasLimit:U}}async function Q(r,t,e,a,n){try{const o=await a.estimateGas({data:r,from:t,to:e}),c=n?o:o.add(o.div(10));return c.gt(T)?c.toString():T}catch(o){return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default",o),T}}function Y(r){const{inputToken:t,chainId:e,account:a}=r;return`${t.address.toLowerCase()}-${e}${a?`-${a.toLowerCase()}`:""}`}function E(r,t,e){return new x.Contract(r,t,e)}class z{constructor(t,e){this.provider=t,this.walletSigner=e}contractEncodeABI(t,e,a,n){return E(e||"",t,this.provider).interface.encodeFunctionData(a,n)}signTypedData(t,e,a){const n=Object.keys(e.types).reduce((c,s)=>(s!=="EIP712Domain"&&(c[s]=e.types[s]),c),{});return(this.walletSigner||this.provider.getSigner())._signTypedData(e.domain,n,e.message)}ethCall(t,e){return this.provider.call({to:t,data:e})}decodeABIParameter(t,e){return C.defaultAbiCoder.decode([t],e)[0]}decodeABIParameters(t,e){const a=C.defaultAbiCoder.decode(t,e);if(a&&typeof a=="object"){const n={};return Object.keys(a).forEach(o=>{const c=a[o];F.BigNumber.isBigNumber(c)?n[o]=c.toHexString():n[o]=c}),n}return a}}const b=new Map,_=new Map;function M(r,t,e){const a=b.get(r);if(!e&&a)return a;const n=`${r}-${e}`,o=_.get(n);if(o)return o;const c=new z(t,e?void 0:I),s=new p.Eip2612PermitUtils(c);return e?(console.log(`[getPermitUtilsInstance] Set cached provider utils for chain ${r}-${e}`,s),_.set(n,s)):(console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${r}`,s),b.set(r,s)),s}const N=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"}];async function J(r,t,e){const a=v.getAddress(r),o=await E(a,N,e).callStatic.eip712Domain();return X(o,t,r)}async function X(r,t,e){const{extensions:a,...n}=r;if(a.length>0)throw Error("Extensions not implemented");if(n.chainId&&t!==parseInt(n.chainId,16))throw Error(`ChainId mismatch. Received: '${n.chainId}', expected: '${t}'`);if(n.verifyingContract&&e.toLowerCase()!==n.verifyingContract.toLowerCase())throw Error(`Address mismatch. Received: '${n.verifyingContract}', expected: '${e}'`);return ee(n)}const Z=["name","version","chainId","verifyingContract","salt"];function ee(r){const t=parseInt(r.fields,16);return Z.reduce((e,a,n)=>(t&1<<n&&(e[a]=r[a]),e),{})}async function te(r,t,e){const a=v.getAddress(r);return E(a,N,e).callStatic.name()}const ne={value:S,nonce:0,deadline:y()},re={allowed:!0,nonce:0,expiry:y()},A={},P={type:"unsupported"};async function ae(r){const{tokenAddress:t,chainId:e}=r,a=`${e}-${t.toLowerCase()}`,n=A[a];if(n)return n;const o=oe(r);return A[a]=o,o}async function oe(r){const{spender:t,tokenAddress:e,chainId:a,provider:n}=r,o=M(a,n),c=I.address;let s;try{s=await J(e,a,n)}catch(i){console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${e}`,i)}let l=s==null?void 0:s.name;try{l||(l=await te(e,a,n))}catch(i){if(/ETIMEDOUT/.test(i)&&!l)return{error:"Failed to fetch token name from contract. RPC connection error"};console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${e}, using provided '${l}'`,i)}if(!l)return{error:`Token name could not be determined for ${e}`};let d;try{d=await o.getTokenNonce(e,c)}catch(i){return i==="nonce not supported"||i.message==="nonce is NaN"?(console.debug(`[checkTokenIsPermittable] Not a permittable token ${e} - ${l}`,(i==null?void 0:i.message)||i),{...P,name:l}):(console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${e} - ${l}`,i),{error:i.message||i.toString()})}let m=s==null?void 0:s.version;if(!V.has(e)&&m===void 0)try{m=await o.getTokenVersion(e)}catch(i){console.debug(`[checkTokenIsPermittable] Failed to get version for ${e} - ${l}`,i)}const u={chainId:a,eip2612PermitUtils:o,nonce:d,spender:t,tokenAddress:e,tokenName:l,walletAddress:c,version:m};try{return await D({...u,type:"eip-2612",provider:n})}catch(i){try{return await se(e,o)?await D({...u,type:"dai-like",provider:n}):/invalid signature/.test(i)||(i==null?void 0:i.code)==="UNPREDICTABLE_GAS_LIMIT"?(console.debug(`[checkTokenIsPermittable] Token ${e} - ${l} might be permittable, but it's not supported for now. Reason:`,i==null?void 0:i.reason),{...P,name:l}):(console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${e} - ${l}`,i),{error:i.message||i.toString()})}catch(f){return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${e} - ${l}`,f),{error:f.message||f.toString()}}}}async function D(r){const{provider:t,chainId:e,walletAddress:a,tokenAddress:n,tokenName:o,type:c,version:s}=r,d=await(c==="eip-2612"?ie:ce)(r);return d?(await t.estimateGas({data:d,from:a,to:n})).toNumber()>q[e]?{type:c,version:s,name:o}:{...P,name:o}:{...P,name:o}}async function ie(r){const{eip2612PermitUtils:t,walletAddress:e,spender:a,nonce:n,chainId:o,tokenName:c,tokenAddress:s,version:l}=r;return L({eip2162Utils:t,callDataParams:[{...ne,owner:e,spender:a,nonce:n},+o,c,s,l]})}async function se(r,t){return await t.getPermitTypeHash(r)===p.DAI_LIKE_PERMIT_TYPEHASH}async function ce(r){const{eip2612PermitUtils:t,tokenAddress:e,walletAddress:a,spender:n,nonce:o,chainId:c,tokenName:s,version:l}=r;return await t.getPermitTypeHash(e)===p.DAI_LIKE_PERMIT_TYPEHASH?R({eip2162Utils:t,callDataParams:[{...re,holder:a,spender:n,nonce:o},c,s,e,l]}):!1}exports.PERMIT_SIGNER=I;exports.checkIsCallDataAValidPermit=B;exports.generatePermitHook=j;exports.getPermitUtilsInstance=M;exports.getTokenPermitInfo=ae;exports.isSupportedPermitInfo=$;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("@ethersproject/constants"),O=require("@ethersproject/wallet"),p=require("@1inch/permit-signed-approvals-utils"),E=require("@ethersproject/abi"),x=require("@ethersproject/bignumber"),G=require("@ethersproject/contracts"),A=require("@ethersproject/address"),q="0x1b80501ea68b883241ac5b9f92e8635aa3df23c89b7bbb87e762be65b8c6eb75",P=new O.Wallet(q),v=55e3,T="80000",S=F.MaxUint256.toString(),V=157788e6;async function B(r,n,e,a,t,i,{version:o,type:l,name:u}){const c=u||t;if(l==="unsupported")return!1;if(!c)throw new Error(`No token name for ${a}`);const m={chainId:n,tokenName:c,tokenAddress:a,callData:i,version:o};let d;if(i.startsWith(p.EIP_2612_PERMIT_SELECTOR)?d=e.recoverPermitOwnerFromCallData({...m,callData:i.replace(p.EIP_2612_PERMIT_SELECTOR,"0x")}):i.startsWith(p.DAI_PERMIT_SELECTOR)&&(d=e.recoverDaiLikePermitOwnerFromCallData({...m,callData:i.replace(p.DAI_PERMIT_SELECTOR,"0x")})),!!d)try{return(await d).toLowerCase()===r.toLowerCase()}catch(f){return console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${r} with callData ${i}`,f),!1}}async function L({eip2162Utils:r,callDataParams:n}){const[e,a,t,...i]=n;return(await r.buildPermitCallData(e,a,t,...i)).replace("0x",p.EIP_2612_PERMIT_SELECTOR)}async function R({eip2162Utils:r,callDataParams:n}){return(await r.buildDaiLikePermitCallData(...n)).replace("0x",p.DAI_PERMIT_SELECTOR)}function b(){return Math.ceil((Date.now()+V)/1e3)}function $(r){return!!r&&r.type!=="unsupported"}const y={};async function K(r){const n=Q(r),e=y[n];if(e)try{return await e}catch(t){console.debug("[generatePermitHookWith] cached request failed",t),delete y[n]}const a=W(r).then(t=>(delete y[n],t));return y[n]=a,a}async function W(r){const{inputToken:n,spender:e,chainId:a,permitInfo:t,provider:i,account:o,eip2162Utils:l,nonce:u}=r,c=n.address,m=t.name||n.name;if(!$(t))throw new Error(`Trying to generate permit hook for unsupported token: ${c}`);if(!m)throw new Error(`No token name for token: ${c}`);const d=o||P.address,f=u===void 0?await l.getTokenNonce(c,d):u,s=b(),g=S,w=t.type==="eip-2612"?await L({eip2162Utils:l,callDataParams:[{owner:d,spender:e,value:g,nonce:f,deadline:s},a,m,c,t.version]}):await R({eip2162Utils:l,callDataParams:[{holder:d,spender:e,allowed:!0,value:g,nonce:f,expiry:s},a,m,c,t.version]}),H=await j(w,d,c,i,!!o);return{target:c,callData:w,gasLimit:H}}async function j(r,n,e,a,t){try{const i=await a.estimateGas({data:r,from:n,to:e}),o=t?i:i.add(i.div(10));return o.gt(T)?o.toString():T}catch(i){return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default",i),T}}function Q(r){const{inputToken:n,chainId:e,account:a}=r;return`${n.address.toLowerCase()}-${e}${a?`-${a.toLowerCase()}`:""}`}function h(r,n,e){return new G.Contract(r,n,e)}class Y{constructor(n,e){this.provider=n,this.walletSigner=e}contractEncodeABI(n,e,a,t){return h(e||"",n,this.provider).interface.encodeFunctionData(a,t)}signTypedData(n,e,a){const t=Object.keys(e.types).reduce((o,l)=>(l!=="EIP712Domain"&&(o[l]=e.types[l]),o),{});return(this.walletSigner||this.provider.getSigner())._signTypedData(e.domain,t,e.message)}ethCall(n,e){return this.provider.call({to:n,data:e})}decodeABIParameter(n,e){return E.defaultAbiCoder.decode([n],e)[0]}decodeABIParameters(n,e){const a=E.defaultAbiCoder.decode(n,e);if(a&&typeof a=="object"){const t={};return Object.keys(a).forEach(i=>{const o=a[i];x.BigNumber.isBigNumber(o)?t[i]=o.toHexString():t[i]=o}),t}return a}}const k=new Map,C=new Map;function M(r,n,e){const a=k.get(r);if(!e&&a)return a;const t=`${r}-${e}`,i=C.get(t);if(i)return i;const o=new Y(n,e?void 0:P),l=new p.Eip2612PermitUtils(o);return e?(console.log(`[getPermitUtilsInstance] Set cached provider utils for chain ${r}-${e}`,l),C.set(t,l)):(console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${r}`,l),k.set(r,l)),l}const N=[{constant:!0,inputs:[],name:"name",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"},{inputs:[],name:"eip712Domain",outputs:[{internalType:"bytes1",name:"fields",type:"bytes1"},{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"version",type:"string"},{internalType:"uint256",name:"chainId",type:"uint256"},{internalType:"address",name:"verifyingContract",type:"address"},{internalType:"bytes32",name:"salt",type:"bytes32"},{internalType:"uint256[]",name:"extensions",type:"uint256[]"}],stateMutability:"view",type:"function"}];async function z(r,n,e){const a=A.getAddress(r),i=await h(a,N,e).callStatic.eip712Domain();return J(i,n,r)}async function J(r,n,e){const{extensions:a,...t}=r;if(a.length>0)throw Error("Extensions not implemented");if(t.chainId&&n!==parseInt(t.chainId,16))throw Error(`ChainId mismatch. Received: '${t.chainId}', expected: '${n}'`);if(t.verifyingContract&&e.toLowerCase()!==t.verifyingContract.toLowerCase())throw Error(`Address mismatch. Received: '${t.verifyingContract}', expected: '${e}'`);return Z(t)}const X=["name","version","chainId","verifyingContract","salt"];function Z(r){const n=parseInt(r.fields,16);return X.reduce((e,a,t)=>(n&1<<t&&(e[a]=r[a]),e),{})}async function ee(r,n,e){const a=A.getAddress(r);return h(a,N,e).callStatic.name()}const te=[[{constant:!0,inputs:[],name:"version",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"}],[{constant:!0,inputs:[],name:"ERC712_VERSION",outputs:[{name:"",type:"string"}],payable:!1,stateMutability:"view",type:"function"}]];async function U(r,n,e=0){const a=te[e];if(!a)return"1";try{const i=h(r,a,n).interface.encodeFunctionData(a[0].name),o=await n.call({to:r,data:i});return o==="0x"||Number.isNaN(Number(o))?"1":o.startsWith("0x")?E.defaultAbiCoder.decode(["string"],o).toString():o}catch{return U(r,n,e+1)}}const ne={value:S,nonce:0,deadline:b()},re={allowed:!0,nonce:0,expiry:b()},_={},I={type:"unsupported"};async function ae(r){const{tokenAddress:n,chainId:e}=r,a=`${e}-${n.toLowerCase()}`,t=_[a];if(t)return t;const i=ie(r);return _[a]=i,i}async function ie(r){const{spender:n,tokenAddress:e,chainId:a,provider:t,minGasLimit:i}=r,o=M(a,t),l=P.address;let u;try{u=await z(e,a,t)}catch{console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${e}`)}let c=u==null?void 0:u.name;try{c||(c=await ee(e,a,t))}catch(s){if(/ETIMEDOUT/.test(s)&&!c)return{error:"Failed to fetch token name from contract. RPC connection error"};console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${e}, using provided '${c}'`,s)}if(!c)return{error:`Token name could not be determined for ${e}`};let m;try{m=await o.getTokenNonce(e,l)}catch(s){return s==="nonce not supported"||s.message==="nonce is NaN"?(console.debug(`[checkTokenIsPermittable] Not a permittable token ${e} - ${c}`,(s==null?void 0:s.message)||s),{...I,name:c}):(console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${e} - ${c}`,s),{error:s.message||s.toString()})}let d=u==null?void 0:u.version;if(d===void 0)try{d=await U(e,t)}catch(s){console.debug(`[checkTokenIsPermittable] Failed to get version for ${e} - ${c}`,s)}const f={chainId:a,eip2612PermitUtils:o,nonce:m,spender:n,tokenAddress:e,tokenName:c,walletAddress:l,version:d,minGasLimit:i};try{return await D({...f,type:"eip-2612",provider:t})}catch(s){try{return await se(e,o)?await D({...f,type:"dai-like",provider:t}):/invalid signature/.test(s)||(s==null?void 0:s.code)==="UNPREDICTABLE_GAS_LIMIT"?(console.debug(`[checkTokenIsPermittable] Token ${e} - ${c} might be permittable, but it's not supported for now. Reason:`,s==null?void 0:s.reason),{...I,name:c}):(console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${e} - ${c}`,s),{error:s.message||s.toString()})}catch(g){return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${e} - ${c}`,g),{error:g.message||g.toString()}}}}async function D(r){const{provider:n,walletAddress:e,tokenAddress:a,tokenName:t,type:i,version:o,minGasLimit:l=v}=r,c=await(i==="eip-2612"?oe:ce)(r);return c?(await n.estimateGas({data:c,from:e,to:a})).toNumber()>l?{type:i,version:o,name:t}:{...I,name:t}:{...I,name:t}}async function oe(r){const{eip2612PermitUtils:n,walletAddress:e,spender:a,nonce:t,chainId:i,tokenName:o,tokenAddress:l,version:u}=r;return L({eip2162Utils:n,callDataParams:[{...ne,owner:e,spender:a,nonce:t},+i,o,l,u]})}async function se(r,n){return await n.getPermitTypeHash(r)===p.DAI_LIKE_PERMIT_TYPEHASH}async function ce(r){const{eip2612PermitUtils:n,tokenAddress:e,walletAddress:a,spender:t,nonce:i,chainId:o,tokenName:l,version:u}=r;return await n.getPermitTypeHash(e)===p.DAI_LIKE_PERMIT_TYPEHASH?R({eip2162Utils:n,callDataParams:[{...re,holder:a,spender:t,nonce:i},o,l,e,u]}):!1}exports.DEFAULT_MIN_GAS_LIMIT=v;exports.PERMIT_SIGNER=P;exports.checkIsCallDataAValidPermit=B;exports.generatePermitHook=K;exports.getPermitUtilsInstance=M;exports.getTokenPermitInfo=ae;exports.isSupportedPermitInfo=$;
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { PERMIT_SIGNER } from './const';
1
+ export { PERMIT_SIGNER, DEFAULT_MIN_GAS_LIMIT } from './const';
2
2
  export { checkIsCallDataAValidPermit } from './lib/checkIsCallDataAValidPermit';
3
3
  export { generatePermitHook } from './lib/generatePermitHook';
4
4
  export { getPermitUtilsInstance } from './lib/getPermitUtilsInstance';
package/index.js CHANGED
@@ -1,190 +1,185 @@
1
1
  import { MaxUint256 as H } from "@ethersproject/constants";
2
2
  import { Wallet as F } from "@ethersproject/wallet";
3
- import { EIP_2612_PERMIT_SELECTOR as P, DAI_PERMIT_SELECTOR as I, Eip2612PermitUtils as x, DAI_LIKE_PERMIT_TYPEHASH as L } from "@1inch/permit-signed-approvals-utils";
4
- import { defaultAbiCoder as b } from "@ethersproject/abi";
3
+ import { EIP_2612_PERMIT_SELECTOR as w, DAI_PERMIT_SELECTOR as I, Eip2612PermitUtils as x, DAI_LIKE_PERMIT_TYPEHASH as _ } from "@1inch/permit-signed-approvals-utils";
4
+ import { defaultAbiCoder as T } from "@ethersproject/abi";
5
5
  import { BigNumber as O } from "@ethersproject/bignumber";
6
6
  import { Contract as G } from "@ethersproject/contracts";
7
- import { getAddress as $ } from "@ethersproject/address";
8
- const K = "0x4dae303b820e9878cafeb0f84edcc015e8a81b1bff510e824e4fc27544e458dd", T = new F(K), h = 55e3, B = {
9
- 1: h,
10
- 100: h,
11
- 11155111: h,
12
- 5: 36e3
13
- }, y = "80000", S = H.toString(), V = 157788e6, q = /* @__PURE__ */ new Set(["0x6b175474e89094c44da98b954eedeac495271d0f"]);
14
- async function he(r, t, e, a, n, o, {
15
- version: c,
16
- type: s,
17
- name: l
7
+ import { getAddress as L } from "@ethersproject/address";
8
+ const B = "0x1b80501ea68b883241ac5b9f92e8635aa3df23c89b7bbb87e762be65b8c6eb75", b = new F(B), V = 55e3, P = "80000", $ = H.toString(), K = 157788e6;
9
+ async function ye(r, n, e, a, t, o, {
10
+ version: i,
11
+ type: l,
12
+ name: u
18
13
  }) {
19
- const d = l || n;
20
- if (s === "unsupported")
14
+ const c = u || t;
15
+ if (l === "unsupported")
21
16
  return !1;
22
- if (!d)
17
+ if (!c)
23
18
  throw new Error(`No token name for ${a}`);
24
- const u = {
25
- chainId: t,
26
- tokenName: d,
19
+ const m = {
20
+ chainId: n,
21
+ tokenName: c,
27
22
  tokenAddress: a,
28
23
  callData: o,
29
- version: c
24
+ version: i
30
25
  };
31
- let m;
32
- if (o.startsWith(P) ? m = e.recoverPermitOwnerFromCallData({
33
- ...u,
26
+ let d;
27
+ if (o.startsWith(w) ? d = e.recoverPermitOwnerFromCallData({
28
+ ...m,
34
29
  // I don't know why this was removed, ok?
35
30
  // We added it back on buildPermitCallData.ts
36
31
  // But it looks like this is needed 🤷
37
32
  // Check the test for this method https://github.com/1inch/permit-signed-approvals-utils/blob/master/src/eip-2612-permit.test.ts#L85-L106
38
- callData: o.replace(P, "0x")
39
- }) : o.startsWith(I) && (m = e.recoverDaiLikePermitOwnerFromCallData({
40
- ...u,
33
+ callData: o.replace(w, "0x")
34
+ }) : o.startsWith(I) && (d = e.recoverDaiLikePermitOwnerFromCallData({
35
+ ...m,
41
36
  callData: o.replace(I, "0x")
42
- })), !!m)
37
+ })), !!d)
43
38
  try {
44
- return (await m).toLowerCase() === r.toLowerCase();
45
- } catch (i) {
46
- return console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${r} with callData ${o}`, i), !1;
39
+ return (await d).toLowerCase() === r.toLowerCase();
40
+ } catch (p) {
41
+ return console.debug(`[checkHasValidPendingPermit] Failed to check permit validity for owner ${r} with callData ${o}`, p), !1;
47
42
  }
48
43
  }
49
- async function R({
44
+ async function S({
50
45
  eip2162Utils: r,
51
- callDataParams: t
46
+ callDataParams: n
52
47
  }) {
53
- const [e, a, n, ...o] = t;
54
- return (await r.buildPermitCallData(e, a, n, ...o)).replace("0x", P);
48
+ const [e, a, t, ...o] = n;
49
+ return (await r.buildPermitCallData(e, a, t, ...o)).replace("0x", w);
55
50
  }
56
51
  async function N({
57
52
  eip2162Utils: r,
58
- callDataParams: t
53
+ callDataParams: n
59
54
  }) {
60
- return (await r.buildDaiLikePermitCallData(...t)).replace("0x", I);
55
+ return (await r.buildDaiLikePermitCallData(...n)).replace("0x", I);
61
56
  }
62
- function w() {
63
- return Math.ceil((Date.now() + V) / 1e3);
57
+ function k() {
58
+ return Math.ceil((Date.now() + K) / 1e3);
64
59
  }
65
60
  function W(r) {
66
61
  return !!r && r.type !== "unsupported";
67
62
  }
68
- const f = {};
69
- async function ye(r) {
70
- const t = Y(r), e = f[t];
63
+ const g = {};
64
+ async function he(r) {
65
+ const n = Q(r), e = g[n];
71
66
  if (e)
72
67
  try {
73
68
  return await e;
74
- } catch (n) {
75
- console.debug("[generatePermitHookWith] cached request failed", n), delete f[t];
69
+ } catch (t) {
70
+ console.debug("[generatePermitHookWith] cached request failed", t), delete g[n];
76
71
  }
77
- const a = j(r).then((n) => (delete f[t], n));
78
- return f[t] = a, a;
72
+ const a = q(r).then((t) => (delete g[n], t));
73
+ return g[n] = a, a;
79
74
  }
80
- async function j(r) {
75
+ async function q(r) {
81
76
  const {
82
- inputToken: t,
77
+ inputToken: n,
83
78
  spender: e,
84
79
  chainId: a,
85
- permitInfo: n,
80
+ permitInfo: t,
86
81
  provider: o,
87
- account: c,
88
- eip2162Utils: s,
89
- nonce: l
90
- } = r, d = t.address, u = n.name || t.name;
91
- if (!W(n))
92
- throw new Error(`Trying to generate permit hook for unsupported token: ${d}`);
93
- if (!u)
94
- throw new Error(`No token name for token: ${d}`);
95
- const m = c || T.address, i = l === void 0 ? await s.getTokenNonce(d, m) : l, p = w(), E = S, C = n.type === "eip-2612" ? await R({
96
- eip2162Utils: s,
82
+ account: i,
83
+ eip2162Utils: l,
84
+ nonce: u
85
+ } = r, c = n.address, m = t.name || n.name;
86
+ if (!W(t))
87
+ throw new Error(`Trying to generate permit hook for unsupported token: ${c}`);
88
+ if (!m)
89
+ throw new Error(`No token name for token: ${c}`);
90
+ const d = i || b.address, p = u === void 0 ? await l.getTokenNonce(c, d) : u, s = k(), f = $, E = t.type === "eip-2612" ? await S({
91
+ eip2162Utils: l,
97
92
  callDataParams: [{
98
- owner: m,
93
+ owner: d,
99
94
  spender: e,
100
- value: E,
101
- nonce: i,
102
- deadline: p
103
- }, a, u, d, n.version]
95
+ value: f,
96
+ nonce: p,
97
+ deadline: s
98
+ }, a, m, c, t.version]
104
99
  }) : await N({
105
- eip2162Utils: s,
100
+ eip2162Utils: l,
106
101
  callDataParams: [{
107
- holder: m,
102
+ holder: d,
108
103
  spender: e,
109
104
  allowed: !0,
110
- value: E,
111
- nonce: i,
112
- expiry: p
113
- }, a, u, d, n.version]
114
- }), U = await Q(C, m, d, o, !!c);
105
+ value: f,
106
+ nonce: p,
107
+ expiry: s
108
+ }, a, m, c, t.version]
109
+ }), U = await j(E, d, c, o, !!i);
115
110
  return {
116
- target: d,
117
- callData: C,
111
+ target: c,
112
+ callData: E,
118
113
  gasLimit: U
119
114
  };
120
115
  }
121
- async function Q(r, t, e, a, n) {
116
+ async function j(r, n, e, a, t) {
122
117
  try {
123
118
  const o = await a.estimateGas({
124
119
  data: r,
125
- from: t,
120
+ from: n,
126
121
  to: e
127
- }), c = n ? o : o.add(o.div(10));
128
- return c.gt(y) ? c.toString() : y;
122
+ }), i = t ? o : o.add(o.div(10));
123
+ return i.gt(P) ? i.toString() : P;
129
124
  } catch (o) {
130
- return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default", o), y;
125
+ return console.debug("[calculatePermitGasLimit] Failed to estimateGas, using default", o), P;
131
126
  }
132
127
  }
133
- function Y(r) {
128
+ function Q(r) {
134
129
  const {
135
- inputToken: t,
130
+ inputToken: n,
136
131
  chainId: e,
137
132
  account: a
138
133
  } = r;
139
- return `${t.address.toLowerCase()}-${e}${a ? `-${a.toLowerCase()}` : ""}`;
134
+ return `${n.address.toLowerCase()}-${e}${a ? `-${a.toLowerCase()}` : ""}`;
140
135
  }
141
- function k(r, t, e) {
142
- return new G(r, t, e);
136
+ function h(r, n, e) {
137
+ return new G(r, n, e);
143
138
  }
144
- class z {
145
- constructor(t, e) {
146
- this.provider = t, this.walletSigner = e;
139
+ class Y {
140
+ constructor(n, e) {
141
+ this.provider = n, this.walletSigner = e;
147
142
  }
148
- contractEncodeABI(t, e, a, n) {
149
- return k(e || "", t, this.provider).interface.encodeFunctionData(a, n);
143
+ contractEncodeABI(n, e, a, t) {
144
+ return h(e || "", n, this.provider).interface.encodeFunctionData(a, t);
150
145
  }
151
- signTypedData(t, e, a) {
152
- const n = Object.keys(e.types).reduce((c, s) => (s !== "EIP712Domain" && (c[s] = e.types[s]), c), {});
153
- return (this.walletSigner || this.provider.getSigner())._signTypedData(e.domain, n, e.message);
146
+ signTypedData(n, e, a) {
147
+ const t = Object.keys(e.types).reduce((i, l) => (l !== "EIP712Domain" && (i[l] = e.types[l]), i), {});
148
+ return (this.walletSigner || this.provider.getSigner())._signTypedData(e.domain, t, e.message);
154
149
  }
155
- ethCall(t, e) {
150
+ ethCall(n, e) {
156
151
  return this.provider.call({
157
- to: t,
152
+ to: n,
158
153
  data: e
159
154
  });
160
155
  }
161
- decodeABIParameter(t, e) {
162
- return b.decode([t], e)[0];
156
+ decodeABIParameter(n, e) {
157
+ return T.decode([n], e)[0];
163
158
  }
164
- decodeABIParameters(t, e) {
165
- const a = b.decode(t, e);
159
+ decodeABIParameters(n, e) {
160
+ const a = T.decode(n, e);
166
161
  if (a && typeof a == "object") {
167
- const n = {};
162
+ const t = {};
168
163
  return Object.keys(a).forEach((o) => {
169
- const c = a[o];
170
- O.isBigNumber(c) ? n[o] = c.toHexString() : n[o] = c;
171
- }), n;
164
+ const i = a[o];
165
+ O.isBigNumber(i) ? t[o] = i.toHexString() : t[o] = i;
166
+ }), t;
172
167
  }
173
168
  return a;
174
169
  }
175
170
  }
176
- const v = /* @__PURE__ */ new Map(), D = /* @__PURE__ */ new Map();
177
- function J(r, t, e) {
178
- const a = v.get(r);
171
+ const C = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map();
172
+ function z(r, n, e) {
173
+ const a = C.get(r);
179
174
  if (!e && a)
180
175
  return a;
181
- const n = `${r}-${e}`, o = D.get(n);
176
+ const t = `${r}-${e}`, o = v.get(t);
182
177
  if (o)
183
178
  return o;
184
- const c = new z(t, e ? void 0 : T), s = new x(c);
185
- return e ? (console.log(`[getPermitUtilsInstance] Set cached provider utils for chain ${r}-${e}`, s), D.set(n, s)) : (console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${r}`, s), v.set(r, s)), s;
179
+ const i = new Y(n, e ? void 0 : b), l = new x(i);
180
+ return e ? (console.log(`[getPermitUtilsInstance] Set cached provider utils for chain ${r}-${e}`, l), v.set(t, l)) : (console.log(`[getPermitUtilsInstance] Set cached chain utils for chain ${r}`, l), C.set(r, l)), l;
186
181
  }
187
- const M = [
182
+ const R = [
188
183
  {
189
184
  constant: !0,
190
185
  inputs: [],
@@ -243,209 +238,249 @@ const M = [
243
238
  type: "function"
244
239
  }
245
240
  ];
246
- async function X(r, t, e) {
247
- const a = $(r), o = await k(a, M, e).callStatic.eip712Domain();
248
- return Z(o, t, r);
241
+ async function J(r, n, e) {
242
+ const a = L(r), o = await h(a, R, e).callStatic.eip712Domain();
243
+ return X(o, n, r);
249
244
  }
250
- async function Z(r, t, e) {
245
+ async function X(r, n, e) {
251
246
  const {
252
247
  extensions: a,
253
- ...n
248
+ ...t
254
249
  } = r;
255
250
  if (a.length > 0)
256
251
  throw Error("Extensions not implemented");
257
- if (n.chainId && t !== parseInt(n.chainId, 16))
258
- throw Error(`ChainId mismatch. Received: '${n.chainId}', expected: '${t}'`);
259
- if (n.verifyingContract && e.toLowerCase() !== n.verifyingContract.toLowerCase())
260
- throw Error(`Address mismatch. Received: '${n.verifyingContract}', expected: '${e}'`);
261
- return te(n);
252
+ if (t.chainId && n !== parseInt(t.chainId, 16))
253
+ throw Error(`ChainId mismatch. Received: '${t.chainId}', expected: '${n}'`);
254
+ if (t.verifyingContract && e.toLowerCase() !== t.verifyingContract.toLowerCase())
255
+ throw Error(`Address mismatch. Received: '${t.verifyingContract}', expected: '${e}'`);
256
+ return ee(t);
262
257
  }
263
- const ee = ["name", "version", "chainId", "verifyingContract", "salt"];
264
- function te(r) {
265
- const t = parseInt(r.fields, 16);
266
- return ee.reduce((e, a, n) => (t & 1 << n && (e[a] = r[a]), e), {});
258
+ const Z = ["name", "version", "chainId", "verifyingContract", "salt"];
259
+ function ee(r) {
260
+ const n = parseInt(r.fields, 16);
261
+ return Z.reduce((e, a, t) => (n & 1 << t && (e[a] = r[a]), e), {});
267
262
  }
268
- async function ne(r, t, e) {
269
- const a = $(r);
270
- return k(a, M, e).callStatic.name();
263
+ async function te(r, n, e) {
264
+ const a = L(r);
265
+ return h(a, R, e).callStatic.name();
266
+ }
267
+ const ne = [[{
268
+ constant: !0,
269
+ inputs: [],
270
+ name: "version",
271
+ outputs: [{
272
+ name: "",
273
+ type: "string"
274
+ }],
275
+ payable: !1,
276
+ stateMutability: "view",
277
+ type: "function"
278
+ }], [{
279
+ constant: !0,
280
+ inputs: [],
281
+ name: "ERC712_VERSION",
282
+ outputs: [{
283
+ name: "",
284
+ type: "string"
285
+ }],
286
+ payable: !1,
287
+ stateMutability: "view",
288
+ type: "function"
289
+ }]];
290
+ async function M(r, n, e = 0) {
291
+ const a = ne[e];
292
+ if (!a)
293
+ return "1";
294
+ try {
295
+ const o = h(r, a, n).interface.encodeFunctionData(a[0].name), i = await n.call({
296
+ to: r,
297
+ data: o
298
+ });
299
+ return i === "0x" || Number.isNaN(Number(i)) ? "1" : i.startsWith("0x") ? T.decode(["string"], i).toString() : i;
300
+ } catch {
301
+ return M(r, n, e + 1);
302
+ }
271
303
  }
272
304
  const re = {
273
- value: S,
305
+ value: $,
274
306
  nonce: 0,
275
- deadline: w()
307
+ deadline: k()
276
308
  }, ae = {
277
309
  allowed: !0,
278
310
  nonce: 0,
279
- expiry: w()
280
- }, A = {}, g = {
311
+ expiry: k()
312
+ }, D = {}, y = {
281
313
  type: "unsupported"
282
314
  };
283
315
  async function Pe(r) {
284
316
  const {
285
- tokenAddress: t,
317
+ tokenAddress: n,
286
318
  chainId: e
287
- } = r, a = `${e}-${t.toLowerCase()}`, n = A[a];
288
- if (n)
289
- return n;
319
+ } = r, a = `${e}-${n.toLowerCase()}`, t = D[a];
320
+ if (t)
321
+ return t;
290
322
  const o = oe(r);
291
- return A[a] = o, o;
323
+ return D[a] = o, o;
292
324
  }
293
325
  async function oe(r) {
294
326
  const {
295
- spender: t,
327
+ spender: n,
296
328
  tokenAddress: e,
297
329
  chainId: a,
298
- provider: n
299
- } = r, o = J(a, n), c = T.address;
300
- let s;
330
+ provider: t,
331
+ minGasLimit: o
332
+ } = r, i = z(a, t), l = b.address;
333
+ let u;
301
334
  try {
302
- s = await X(e, a, n);
303
- } catch (i) {
304
- console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${e}`, i);
335
+ u = await J(e, a, t);
336
+ } catch {
337
+ console.debug(`[checkTokenIsPermittable] Couldn't fetch eip712domain for token ${e}`);
305
338
  }
306
- let l = s == null ? void 0 : s.name;
339
+ let c = u == null ? void 0 : u.name;
307
340
  try {
308
- l || (l = await ne(e, a, n));
309
- } catch (i) {
310
- if (/ETIMEDOUT/.test(i) && !l)
341
+ c || (c = await te(e, a, t));
342
+ } catch (s) {
343
+ if (/ETIMEDOUT/.test(s) && !c)
311
344
  return {
312
345
  error: "Failed to fetch token name from contract. RPC connection error"
313
346
  };
314
- console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${e}, using provided '${l}'`, i);
347
+ console.debug(`[checkTokenIsPermittable] Couldn't fetch token name from the contract for token ${e}, using provided '${c}'`, s);
315
348
  }
316
- if (!l)
349
+ if (!c)
317
350
  return {
318
351
  error: `Token name could not be determined for ${e}`
319
352
  };
320
- let d;
353
+ let m;
321
354
  try {
322
- d = await o.getTokenNonce(e, c);
323
- } catch (i) {
324
- return i === "nonce not supported" || i.message === "nonce is NaN" ? (console.debug(`[checkTokenIsPermittable] Not a permittable token ${e} - ${l}`, (i == null ? void 0 : i.message) || i), {
325
- ...g,
326
- name: l
327
- }) : (console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${e} - ${l}`, i), {
328
- error: i.message || i.toString()
355
+ m = await i.getTokenNonce(e, l);
356
+ } catch (s) {
357
+ return s === "nonce not supported" || s.message === "nonce is NaN" ? (console.debug(`[checkTokenIsPermittable] Not a permittable token ${e} - ${c}`, (s == null ? void 0 : s.message) || s), {
358
+ ...y,
359
+ name: c
360
+ }) : (console.debug(`[checkTokenIsPermittable] Failed to get nonce for ${e} - ${c}`, s), {
361
+ error: s.message || s.toString()
329
362
  });
330
363
  }
331
- let u = s == null ? void 0 : s.version;
332
- if (!q.has(e) && u === void 0)
364
+ let d = u == null ? void 0 : u.version;
365
+ if (d === void 0)
333
366
  try {
334
- u = await o.getTokenVersion(e);
335
- } catch (i) {
336
- console.debug(`[checkTokenIsPermittable] Failed to get version for ${e} - ${l}`, i);
367
+ d = await M(e, t);
368
+ } catch (s) {
369
+ console.debug(`[checkTokenIsPermittable] Failed to get version for ${e} - ${c}`, s);
337
370
  }
338
- const m = {
371
+ const p = {
339
372
  chainId: a,
340
- eip2612PermitUtils: o,
341
- nonce: d,
342
- spender: t,
373
+ eip2612PermitUtils: i,
374
+ nonce: m,
375
+ spender: n,
343
376
  tokenAddress: e,
344
- tokenName: l,
345
- walletAddress: c,
346
- version: u
377
+ tokenName: c,
378
+ walletAddress: l,
379
+ version: d,
380
+ minGasLimit: o
347
381
  };
348
382
  try {
349
- return await _({
350
- ...m,
383
+ return await A({
384
+ ...p,
351
385
  type: "eip-2612",
352
- provider: n
386
+ provider: t
353
387
  });
354
- } catch (i) {
388
+ } catch (s) {
355
389
  try {
356
- return await se(e, o) ? await _({
357
- ...m,
390
+ return await se(e, i) ? await A({
391
+ ...p,
358
392
  type: "dai-like",
359
- provider: n
360
- }) : /invalid signature/.test(i) || (i == null ? void 0 : i.code) === "UNPREDICTABLE_GAS_LIMIT" ? (console.debug(`[checkTokenIsPermittable] Token ${e} - ${l} might be permittable, but it's not supported for now. Reason:`, i == null ? void 0 : i.reason), {
361
- ...g,
362
- name: l
363
- }) : (console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${e} - ${l}`, i), {
364
- error: i.message || i.toString()
393
+ provider: t
394
+ }) : /invalid signature/.test(s) || (s == null ? void 0 : s.code) === "UNPREDICTABLE_GAS_LIMIT" ? (console.debug(`[checkTokenIsPermittable] Token ${e} - ${c} might be permittable, but it's not supported for now. Reason:`, s == null ? void 0 : s.reason), {
395
+ ...y,
396
+ name: c
397
+ }) : (console.debug(`[checkTokenIsPermittable] Failed to estimate eip-2612 permit for ${e} - ${c}`, s), {
398
+ error: s.message || s.toString()
365
399
  });
366
- } catch (p) {
367
- return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${e} - ${l}`, p), {
368
- error: p.message || p.toString()
400
+ } catch (f) {
401
+ return console.debug(`[checkTokenIsPermittable] Failed to estimate dai-like permit for ${e} - ${c}`, f), {
402
+ error: f.message || f.toString()
369
403
  };
370
404
  }
371
405
  }
372
406
  }
373
- async function _(r) {
407
+ async function A(r) {
374
408
  const {
375
- provider: t,
376
- chainId: e,
377
- walletAddress: a,
378
- tokenAddress: n,
379
- tokenName: o,
380
- type: c,
381
- version: s
382
- } = r, d = await (c === "eip-2612" ? ie : ce)(r);
383
- return d ? (await t.estimateGas({
384
- data: d,
385
- from: a,
386
- to: n
387
- })).toNumber() > B[e] ? {
388
- type: c,
389
- version: s,
390
- name: o
409
+ provider: n,
410
+ walletAddress: e,
411
+ tokenAddress: a,
412
+ tokenName: t,
413
+ type: o,
414
+ version: i,
415
+ minGasLimit: l = V
416
+ } = r, c = await (o === "eip-2612" ? ie : ce)(r);
417
+ return c ? (await n.estimateGas({
418
+ data: c,
419
+ from: e,
420
+ to: a
421
+ })).toNumber() > l ? {
422
+ type: o,
423
+ version: i,
424
+ name: t
391
425
  } : {
392
- ...g,
393
- name: o
426
+ ...y,
427
+ name: t
394
428
  } : {
395
- ...g,
396
- name: o
429
+ ...y,
430
+ name: t
397
431
  };
398
432
  }
399
433
  async function ie(r) {
400
434
  const {
401
- eip2612PermitUtils: t,
435
+ eip2612PermitUtils: n,
402
436
  walletAddress: e,
403
437
  spender: a,
404
- nonce: n,
438
+ nonce: t,
405
439
  chainId: o,
406
- tokenName: c,
407
- tokenAddress: s,
408
- version: l
440
+ tokenName: i,
441
+ tokenAddress: l,
442
+ version: u
409
443
  } = r;
410
- return R({
411
- eip2162Utils: t,
444
+ return S({
445
+ eip2162Utils: n,
412
446
  callDataParams: [{
413
447
  ...re,
414
448
  owner: e,
415
449
  spender: a,
416
- nonce: n
417
- }, +o, c, s, l]
450
+ nonce: t
451
+ }, +o, i, l, u]
418
452
  });
419
453
  }
420
- async function se(r, t) {
421
- return await t.getPermitTypeHash(r) === L;
454
+ async function se(r, n) {
455
+ return await n.getPermitTypeHash(r) === _;
422
456
  }
423
457
  async function ce(r) {
424
458
  const {
425
- eip2612PermitUtils: t,
459
+ eip2612PermitUtils: n,
426
460
  tokenAddress: e,
427
461
  walletAddress: a,
428
- spender: n,
462
+ spender: t,
429
463
  nonce: o,
430
- chainId: c,
431
- tokenName: s,
432
- version: l
464
+ chainId: i,
465
+ tokenName: l,
466
+ version: u
433
467
  } = r;
434
- return await t.getPermitTypeHash(e) === L ? N({
435
- eip2162Utils: t,
468
+ return await n.getPermitTypeHash(e) === _ ? N({
469
+ eip2162Utils: n,
436
470
  callDataParams: [{
437
471
  ...ae,
438
472
  holder: a,
439
- spender: n,
473
+ spender: t,
440
474
  nonce: o
441
- }, c, s, e, l]
475
+ }, i, l, e, u]
442
476
  }) : !1;
443
477
  }
444
478
  export {
445
- T as PERMIT_SIGNER,
446
- he as checkIsCallDataAValidPermit,
447
- ye as generatePermitHook,
448
- J as getPermitUtilsInstance,
479
+ V as DEFAULT_MIN_GAS_LIMIT,
480
+ b as PERMIT_SIGNER,
481
+ ye as checkIsCallDataAValidPermit,
482
+ he as generatePermitHook,
483
+ z as getPermitUtilsInstance,
449
484
  Pe as getTokenPermitInfo,
450
485
  W as isSupportedPermitInfo
451
486
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cowprotocol/permit-utils",
3
- "version": "0.1.1-RC.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "ethers": "^5.7.2",
package/types.d.ts CHANGED
@@ -40,5 +40,6 @@ export type GetTokenPermitInfoParams = {
40
40
  tokenAddress: string;
41
41
  chainId: number;
42
42
  provider: JsonRpcProvider;
43
+ minGasLimit?: number | undefined;
43
44
  };
44
45
  export {};
@@ -0,0 +1,2 @@
1
+ import type { JsonRpcProvider } from '@ethersproject/providers';
2
+ export declare function getTokenPermitVersion(tokenAddress: string, provider: JsonRpcProvider, index?: number): Promise<string>;