import{u as w,N as m,O as E,l as T,P as B,Q as g,_,f as v,y as D,R as O,T as z,V as A,W as L}from"./thirdweb-Co3M1EyP.js";function l(a){if(["string","number"].includes(typeof a)&&!Number.isInteger(Number(a)))throw new Error(`Expected value to be an integer to convert to a bigint, got ${a} of type ${typeof a}`);return a instanceof Uint8Array?BigInt(w(a)):BigInt(a)}const x=(a,e)=>typeof a=="bigint"?e(a):Array.isArray(a)?a.map(t=>x(t,e)):a&&typeof a=="object"?Object.fromEntries(Object.entries(a).map(([t,n])=>[t,x(n,e)])):a,b=50000n,R=a=>{const e=S(a);return{domain:{chainId:a.chainId,name:"zkSync",version:"2"},message:e,primaryType:"Transaction",types:{Transaction:[{name:"txType",type:"uint256"},{name:"from",type:"uint256"},{name:"to",type:"uint256"},{name:"gasLimit",type:"uint256"},{name:"gasPerPubdataByteLimit",type:"uint256"},{name:"maxFeePerGas",type:"uint256"},{name:"maxPriorityFeePerGas",type:"uint256"},{name:"paymaster",type:"uint256"},{name:"nonce",type:"uint256"},{name:"value",type:"uint256"},{name:"data",type:"bytes"},{name:"factoryDeps",type:"bytes32[]"},{name:"paymasterInput",type:"bytes"}]}}};function S(a){const{gas:e,nonce:t,to:n,from:r,value:i,maxFeePerGas:s,maxPriorityFeePerGas:o,paymaster:u,paymasterInput:y,gasPerPubdata:p,data:P,factoryDeps:d}=a;return{data:P||"0x0",factoryDeps:(d==null?void 0:d.map(c=>m(E(c))))??[],from:BigInt(r),gasLimit:e??0n,gasPerPubdataByteLimit:p??b,maxFeePerGas:s??0n,maxPriorityFeePerGas:o??0n,nonce:t?BigInt(t):0n,paymaster:u?BigInt(u):0n,paymasterInput:y||"0x",to:n?BigInt(n):0n,txType:113n,value:i??0n}}async function k(a){const{account:e,transaction:t}=a,n=await G(a),r=await F({account:e,chainId:t.chain.id,eip712Transaction:n}),i=T(t),s=await B(i,r);return{chain:t.chain,client:t.client,transactionHash:s}}async function F(a){const{account:e,eip712Transaction:t,chainId:n}=a,r=R(t),i=await e.signTypedData({...r});return H({...t,chainId:n,customSignature:i})}async function G(a){const{account:e,transaction:t}=a,{gas:n,maxFeePerGas:r,maxPriorityFeePerGas:i,gasPerPubdata:s}=await h({from:v(e.address),transaction:t});return{...await D({from:e.address,transaction:{...t,gas:n,maxFeePerGas:r,maxPriorityFeePerGas:i}}),...t.eip712,from:e.address,gasPerPubdata:s}}function H(a){const{chainId:e,gas:t,nonce:n,to:r,from:i,value:s,maxFeePerGas:o,maxPriorityFeePerGas:u,customSignature:y,factoryDeps:p,paymaster:P,paymasterInput:d,gasPerPubdata:c,data:f}=a,I=[n?m(n):"0x",u?m(u):"0x",o?m(o):"0x",t?m(t):"0x",r??"0x",s?m(s):"0x",f??"0x0",m(e),m(""),m(""),m(e),i??"0x",c?m(c):m(b),p??[],y??"0x",P&&d?[P,d]:[]];return A(["0x71",L(I)])}async function h(a){const{transaction:e,from:t}=a;let[n,r,i,s]=await Promise.all([g(e.gas),g(e.maxFeePerGas),g(e.maxPriorityFeePerGas),g(e.eip712)]),o=s==null?void 0:s.gasPerPubdata;if(n===void 0||r===void 0||i===void 0){const u=T(e),y=await V({from:t,transaction:e});try{const p=await u({method:"zks_estimateFee",params:[x(y,m)]});n=l(p.gas_limit)*2n,r=l(p.max_fee_per_gas)*2n,i=l(p.max_priority_fee_per_gas)||1n,o=l(p.gas_per_pubdata_limit)*2n,o<50000n&&(o=50000n)}catch{const[{estimateGas:p},{getDefaultGasOverrides:P}]=await Promise.all([_(()=>import("./thirdweb-Co3M1EyP.js").then(f=>f.ck),[]),_(()=>import("./thirdweb-Co3M1EyP.js").then(f=>f.ci),[])]),[d,c]=await Promise.all([n===void 0?p({transaction:e,from:t}):Promise.resolve(n),P(e.client,e.chain)]);n=d*2n,"maxFeePerGas"in c&&c.maxFeePerGas?r=c.maxFeePerGas*2n:"gasPrice"in c&&c.gasPrice&&(r=c.gasPrice*2n),"maxPriorityFeePerGas"in c&&c.maxPriorityFeePerGas?i=c.maxPriorityFeePerGas:i=1n,o=100000n}}return{gas:n,gasPerPubdata:o,maxFeePerGas:r,maxPriorityFeePerGas:i}}async function V(a){var u;const{transaction:e,from:t}=a,[n,r,i,s]=await Promise.all([O(e),g(e.to),g(e.value),g(e.eip712)]),o=s==null?void 0:s.gasPerPubdata;return{data:n,eip712Meta:{...s,factoryDeps:(u=s==null?void 0:s.factoryDeps)==null?void 0:u.map(y=>Array.from(z(y))),gasPerPubdata:o||50000n},from:t,gasPerPubdata:o,to:r,type:"0x71",value:i}}const N=Object.freeze(Object.defineProperty({__proto__:null,getZkGasFees:h,populateEip712Transaction:G,sendEip712Transaction:k,signEip712Transaction:F},Symbol.toStringTag,{value:"Module"}));export{N as a,G as p,F as s,l as t};
