@avalanche-sdk/client
Version:
A TypeScript SDK for interacting with the Avalanche network through JSON-RPC APIs. This SDK provides a comprehensive set of tools to interact with all Avalanche chains (P-Chain, X-Chain, C-Chain) and various APIs, including wallet functionality for transa
5 lines • 105 kB
JavaScript
"use strict";var e=require("@avalabs/avalanchejs"),t=require("viem");function n(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}}),t.default=e,Object.freeze(t)}var r=n(require("node:crypto"));async function s(e){return e.request({method:"avalanche_getAccountPubKey",params:{}})}function i(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function o(e){return i(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const a="2.38.6";let c=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,u=`viem@${a}`;class l extends Error{constructor(e,t={}){const n=t.cause instanceof l?t.cause.details:t.cause?.message?t.cause.message:t.details,r=t.cause instanceof l&&t.cause.docsPath||t.docsPath,s=c?.({...t,docsPath:r});super([e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...u?[`Version: ${u}`]:[]].join("\n"),t.cause?{cause:t.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=r,this.metaMessages=t.metaMessages,this.name=t.name??this.name,this.shortMessage=e,this.version=a}walk(e){return d(this,e)}}function d(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?d(e.cause,t):t?null:e}class h extends l{constructor({address:e}){super(`Address "${e}" is invalid.`,{metaMessages:["- Address must be a hex value of 20 bytes (40 hex characters).","- Address must match its checksum counterpart."],name:"InvalidAddressError"})}}class f extends l{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:"SizeExceedsPaddingSizeError"})}}class p extends l{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} is expected to be ${t} ${n} long, but is ${e} ${n} long.`,{name:"InvalidBytesLengthError"})}}function m(e,{dir:t,size:n=32}={}){return"string"==typeof e?function(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new f({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new f({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const i="right"===t;r[i?s:n-s-1]=e[i?s:e.length-s-1]}return r}(e,{dir:t,size:n})}class g extends l{constructor({max:e,min:t,signed:n,size:r,value:s}){super(`Number "${s}" is not in safe ${r?`${8*r}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}}class w extends l{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function y(e,{size:t}){if(o(e)>t)throw new w({givenSize:o(e),maxSize:t})}function b(e,t={}){const{signed:n}=t;t.size&&y(e,{size:t.size});const r=BigInt(e);if(!n)return r;const s=(e.length-2)/2;return r<=(1n<<8n*BigInt(s)-1n)-1n?r:r-BigInt(`0x${"f".padStart(2*s,"f")}`)-1n}function x(e,t={}){return Number(b(e,t))}const v=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function P(e,t={}){return"number"==typeof e||"bigint"==typeof e?E(e,t):"string"==typeof e?function(e,t={}){const n=I.encode(e);return B(n,t)}(e,t):"boolean"==typeof e?function(e,t={}){const n=`0x${Number(e)}`;if("number"==typeof t.size)return y(n,{size:t.size}),m(n,{size:t.size});return n}(e,t):B(e,t)}function B(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=v[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(y(r,{size:t.size}),m(r,{dir:"right",size:t.size})):r}function E(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let i;r?i=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(i=BigInt(Number.MAX_SAFE_INTEGER));const o="bigint"==typeof i&&n?-i-1n:0;if(i&&s>i||s<o){const t="bigint"==typeof e?"n":"";throw new g({max:i?`${i}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}const a=`0x${(n&&s<0?(1n<<BigInt(8*r))+BigInt(s):s).toString(16)}`;return r?m(a,{size:r}):a}const I=new TextEncoder;const A=new TextEncoder;function T(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=E(e,t);return F(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return y(n,{size:t.size}),m(n,{size:t.size});return n}(e,t):i(e)?F(e,t):S(e,t)}const k={zero:48,nine:57,A:65,F:70,a:97,f:102};function C(e){return e>=k.zero&&e<=k.nine?e-k.zero:e>=k.A&&e<=k.F?e-(k.A-10):e>=k.a&&e<=k.f?e-(k.a-10):void 0}function F(e,t={}){let n=e;t.size&&(y(n,{size:t.size}),n=m(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,i=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=C(r.charCodeAt(t++)),s=C(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new l(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);i[e]=16*n+s}return i}function S(e,t={}){const n=A.encode(e);return"number"==typeof t.size?(y(n,{size:t.size}),m(n,{dir:"right",size:t.size})):n}const O=BigInt(2**32-1),N=BigInt(32);function $(e,t=!1){return t?{h:Number(e&O),l:Number(e>>N&O)}:{h:0|Number(e>>N&O),l:0|Number(e&O)}}const z=r&&"object"==typeof r&&"webcrypto"in r?r.webcrypto:r&&"object"==typeof r&&"randomBytes"in r?r:void 0;function G(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function U(e,...t){if(!((n=e)instanceof Uint8Array||ArrayBuffer.isView(n)&&"Uint8Array"===n.constructor.name))throw new Error("Uint8Array expected");
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
var n;if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function R(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function H(e,t){U(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function q(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function L(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function M(e,t){return e<<32-t|e>>>t}function V(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const j=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=V(e[t]);return e};function D(e){return"string"==typeof e&&(e=function(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}(e)),U(e),e}class _{}function X(e){const t=t=>e().update(D(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function K(e=32){if(z&&"function"==typeof z.getRandomValues)return z.getRandomValues(new Uint8Array(e));if(z&&"function"==typeof z.randomBytes)return Uint8Array.from(z.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Z=BigInt(0),W=BigInt(1),Y=BigInt(2),J=BigInt(7),Q=BigInt(256),ee=BigInt(113),te=[],ne=[],re=[];for(let e=0,t=W,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],te.push(2*(5*r+n)),ne.push((e+1)*(e+2)/2%64);let s=Z;for(let e=0;e<7;e++)t=(t<<W^(t>>J)*ee)%Q,t&Y&&(s^=W<<(W<<BigInt(e))-W);re.push(s)}const se=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let i=0;i<n;i++){const{h:n,l:o}=$(e[i],t);[r[i],s[i]]=[n,o]}return[r,s]}(re,!0),ie=se[0],oe=se[1],ae=(e,t,n)=>n>32?((e,t,n)=>t<<n-32|e>>>64-n)(e,t,n):((e,t,n)=>e<<n|t>>>32-n)(e,t,n),ce=(e,t,n)=>n>32?((e,t,n)=>e<<n-32|t>>>64-n)(e,t,n):((e,t,n)=>t<<n|e>>>32-n)(e,t,n);class ue extends _{constructor(e,t,n,r=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=t,this.outputLen=n,this.enableXOF=r,this.rounds=s,G(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var i;this.state=new Uint8Array(200),this.state32=(i=this.state,new Uint32Array(i.buffer,i.byteOffset,Math.floor(i.byteLength/4)))}clone(){return this._cloneInto()}keccak(){j(this.state32),function(e,t=24){const n=new Uint32Array(10);for(let r=24-t;r<24;r++){for(let t=0;t<10;t++)n[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const r=(t+8)%10,s=(t+2)%10,i=n[s],o=n[s+1],a=ae(i,o,1)^n[r],c=ce(i,o,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=a,e[t+n+1]^=c}let t=e[2],s=e[3];for(let n=0;n<24;n++){const r=ne[n],i=ae(t,s,r),o=ce(t,s,r),a=te[n];t=e[a],s=e[a+1],e[a]=i,e[a+1]=o}for(let t=0;t<50;t+=10){for(let r=0;r<10;r++)n[r]=e[t+r];for(let r=0;r<10;r++)e[t+r]^=~n[(r+2)%10]&n[(r+4)%10]}e[0]^=ie[r],e[1]^=oe[r]}q(n)}(this.state32,this.rounds),j(this.state32),this.posOut=0,this.pos=0}update(e){R(this),U(e=D(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const i=Math.min(t-this.pos,r-s);for(let t=0;t<i;t++)n[this.pos++]^=e[s++];this.pos===t&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){R(this,!1),U(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,s=e.length;r<s;){this.posOut>=n&&this.keccak();const i=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+i),r),this.posOut+=i,r+=i}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return G(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(H(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,q(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:i}=this;return e||(e=new ue(t,n,r,i,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=r,e.enableXOF=i,e.destroyed=this.destroyed,e}}const le=(()=>{return e=1,t=136,n=32,X(()=>new ue(t,e,n));var e,t,n})();function de(e,t){const n=t||"hex",r=le(i(e,{strict:!1})?T(e):e);return"bytes"===n?r:P(r)}class he extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const t=super.get(e);return super.has(e)&&void 0!==t&&(this.delete(e),super.set(e,t)),t}set(e,t){if(super.set(e,t),this.maxSize&&this.size>this.maxSize){const e=this.keys().next().value;e&&this.delete(e)}return this}}const fe=/^0x[a-fA-F0-9]{40}$/,pe=new he(8192);function me(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(pe.has(r))return pe.get(r);const s=!(!fe.test(e)||e.toLowerCase()!==e&&n&&we(e)!==e);return pe.set(r,s),s}const ge=new he(8192);function we(e,t){if(ge.has(`${e}.${t}`))return ge.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=de(S(n),"bytes"),s=n.split("");for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&s[e]&&(s[e]=s[e].toUpperCase()),(15&r[e>>1])>=8&&s[e+1]&&(s[e+1]=s[e+1].toUpperCase());const i=`0x${s.join("")}`;return ge.set(`${e}.${t}`,i),i}class ye extends l{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class be extends l{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class xe extends l{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const ve={bytes:new Uint8Array,dataView:new DataView(new ArrayBuffer(0)),position:0,positionReadCount:new Map,recursiveReadCount:0,recursiveReadLimit:Number.POSITIVE_INFINITY,assertReadLimit(){if(this.recursiveReadCount>=this.recursiveReadLimit)throw new xe({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new be({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new ye({offset:e});const t=this.position-e;this.assertPosition(t),this.position=t},getReadCount(e){return this.positionReadCount.get(e||this.position)||0},incrementPosition(e){if(e<0)throw new ye({offset:e});const t=this.position+e;this.assertPosition(t),this.position=t},inspectByte(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectBytes(e,t){const n=t??this.position;return this.assertPosition(n+e-1),this.bytes.subarray(n,n+e)},inspectUint8(e){const t=e??this.position;return this.assertPosition(t),this.bytes[t]},inspectUint16(e){const t=e??this.position;return this.assertPosition(t+1),this.dataView.getUint16(t)},inspectUint24(e){const t=e??this.position;return this.assertPosition(t+2),(this.dataView.getUint16(t)<<8)+this.dataView.getUint8(t+2)},inspectUint32(e){const t=e??this.position;return this.assertPosition(t+3),this.dataView.getUint32(t)},pushByte(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushBytes(e){this.assertPosition(this.position+e.length-1),this.bytes.set(e,this.position),this.position+=e.length},pushUint8(e){this.assertPosition(this.position),this.bytes[this.position]=e,this.position++},pushUint16(e){this.assertPosition(this.position+1),this.dataView.setUint16(this.position,e),this.position+=2},pushUint24(e){this.assertPosition(this.position+2),this.dataView.setUint16(this.position,e>>8),this.dataView.setUint8(this.position+2,255&e),this.position+=3},pushUint32(e){this.assertPosition(this.position+3),this.dataView.setUint32(this.position,e),this.position+=4},readByte(){this.assertReadLimit(),this._touch();const e=this.inspectByte();return this.position++,e},readBytes(e,t){this.assertReadLimit(),this._touch();const n=this.inspectBytes(e);return this.position+=t??e,n},readUint8(){this.assertReadLimit(),this._touch();const e=this.inspectUint8();return this.position+=1,e},readUint16(){this.assertReadLimit(),this._touch();const e=this.inspectUint16();return this.position+=2,e},readUint24(){this.assertReadLimit(),this._touch();const e=this.inspectUint24();return this.position+=3,e},readUint32(){this.assertReadLimit(),this._touch();const e=this.inspectUint32();return this.position+=4,e},get remaining(){return this.bytes.length-this.position},setPosition(e){const t=this.position;return this.assertPosition(e),this.position=e,()=>this.position=t},_touch(){if(this.recursiveReadLimit===Number.POSITIVE_INFINITY)return;const e=this.getReadCount();this.positionReadCount.set(this.position,e+1),e>0&&this.recursiveReadCount++}};function Pe(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(ve);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}class Be extends l{constructor({chain:e,currentChainId:t}){super(`The current chain of the wallet (id: ${t}) does not match the target chain for the transaction (id: ${e.id} – ${e.name}).`,{metaMessages:[`Current Chain ID: ${t}`,`Expected Chain ID: ${e.id} – ${e.name}`],name:"ChainMismatchError"})}}class Ee extends l{constructor(){super(["No chain was provided to the request.","Please provide a chain with the `chain` argument on the Action, or by supplying a `chain` to WalletClient."].join("\n"),{name:"ChainNotFoundError"})}}function Ie(e){return"string"==typeof e?{address:e,type:"json-rpc"}:e}const Ae=(e,t,n)=>JSON.stringify(e,(e,t)=>"bigint"==typeof t?t.toString():t,n),Te={gwei:9,wei:18},ke={ether:-9,wei:9};function Ce(e,t){let n=e.toString();const r=n.startsWith("-");r&&(n=n.slice(1)),n=n.padStart(t,"0");let[s,i]=[n.slice(0,n.length-t),n.slice(n.length-t)];return i=i.replace(/(0+)$/,""),`${r?"-":""}${s||"0"}${i?`.${i}`:""}`}function Fe(e,t="wei"){return Ce(e,Te[t])}function Se(e,t="wei"){return Ce(e,ke[t])}class Oe extends l{constructor({address:e}){super(`State for account "${e}" is set multiple times.`,{name:"AccountStateConflictError"})}}class Ne extends l{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function $e(e){const t=Object.entries(e).map(([e,t])=>void 0===t||!1===t?null:[e,t]).filter(Boolean),n=t.reduce((e,[t])=>Math.max(e,t.length),0);return t.map(([e,t])=>` ${`${e}:`.padEnd(n+1)} ${t}`).join("\n")}class ze extends l{constructor(){super(["Cannot specify both a `gasPrice` and a `maxFeePerGas`/`maxPriorityFeePerGas`.","Use `maxFeePerGas`/`maxPriorityFeePerGas` for EIP-1559 compatible networks, and `gasPrice` for others."].join("\n"),{name:"FeeConflictError"})}}class Ge extends l{constructor({transaction:e}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",$e(e),"}","","To infer the type, either provide:","- a `type` to the Transaction, or","- an EIP-1559 Transaction with `maxFeePerGas`, or","- an EIP-2930 Transaction with `gasPrice` & `accessList`, or","- an EIP-4844 Transaction with `blobs`, `blobVersionedHashes`, `sidecars`, or","- an EIP-7702 Transaction with `authorizationList`, or","- a Legacy Transaction with `gasPrice`"],name:"InvalidSerializableTransactionError"})}}class Ue extends l{constructor(e,{account:t,docsPath:n,chain:r,data:s,gas:i,gasPrice:o,maxFeePerGas:a,maxPriorityFeePerGas:c,nonce:u,to:l,value:d}){const h=$e({chain:r&&`${r?.name} (id: ${r?.id})`,from:t?.address,to:l,value:void 0!==d&&`${Fe(d)} ${r?.nativeCurrency?.symbol||"ETH"}`,data:s,gas:i,gasPrice:void 0!==o&&`${Se(o)} gwei`,maxFeePerGas:void 0!==a&&`${Se(a)} gwei`,maxPriorityFeePerGas:void 0!==c&&`${Se(c)} gwei`,nonce:u});super(e.shortMessage,{cause:e,docsPath:n,metaMessages:[...e.metaMessages?[...e.metaMessages," "]:[],"Request Arguments:",h].filter(Boolean),name:"TransactionExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=e}}class Re extends l{constructor({blockHash:e,blockNumber:t,blockTag:n,hash:r,index:s}){let i="Transaction";n&&void 0!==s&&(i=`Transaction at block time "${n}" at index "${s}"`),e&&void 0!==s&&(i=`Transaction at block hash "${e}" at index "${s}"`),t&&void 0!==s&&(i=`Transaction at block number "${t}" at index "${s}"`),r&&(i=`Transaction with hash "${r}"`),super(`${i} could not be found.`,{name:"TransactionNotFoundError"})}}class He extends l{constructor({hash:e}){super(`Transaction receipt with hash "${e}" could not be found. The Transaction may not be processed on a block yet.`,{name:"TransactionReceiptNotFoundError"})}}class qe extends l{constructor({hash:e}){super(`Timed out while waiting for transaction with hash "${e}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}}function Le(e,t,n){const r=e[t.name];if("function"==typeof r)return r;const s=e[n];return"function"==typeof s?s:n=>t(e,n)}class Me extends l{constructor({cause:e,message:t}={}){const n=t?.replace("execution reverted: ","")?.replace("execution reverted","");super(`Execution reverted ${n?`with reason: ${n}`:"for an unknown reason"}.`,{cause:e,name:"ExecutionRevertedError"})}}Object.defineProperty(Me,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(Me,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class Ve extends l{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${Se(t)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:e,name:"FeeCapTooHighError"})}}Object.defineProperty(Ve,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas higher than 2\^256-1|fee cap higher than 2\^256-1/});class je extends l{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${Se(t)}`:""} gwei) cannot be lower than the block base fee.`,{cause:e,name:"FeeCapTooLowError"})}}Object.defineProperty(je,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max fee per gas less than block base fee|fee cap less than block base fee|transaction is outdated/});class De extends l{constructor({cause:e,nonce:t}={}){super(`Nonce provided for the transaction ${t?`(${t}) `:""}is higher than the next one expected.`,{cause:e,name:"NonceTooHighError"})}}Object.defineProperty(De,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class _e extends l{constructor({cause:e,nonce:t}={}){super([`Nonce provided for the transaction ${t?`(${t}) `:""}is lower than the current nonce of the account.`,"Try increasing the nonce or find the latest nonce with `getTransactionCount`."].join("\n"),{cause:e,name:"NonceTooLowError"})}}Object.defineProperty(_e,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class Xe extends l{constructor({cause:e,nonce:t}={}){super(`Nonce provided for the transaction ${t?`(${t}) `:""}exceeds the maximum allowed nonce.`,{cause:e,name:"NonceMaxValueError"})}}Object.defineProperty(Xe,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class Ke extends l{constructor({cause:e}={}){super(["The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account."].join("\n"),{cause:e,metaMessages:["This error could arise when the account does not have enough funds to:"," - pay for the total gas fee,"," - pay for the value to send."," ","The cost of the transaction is calculated as `gas * gas fee + value`, where:"," - `gas` is the amount of gas needed for transaction to execute,"," - `gas fee` is the gas fee,"," - `value` is the amount of ether to send to the recipient."],name:"InsufficientFundsError"})}}Object.defineProperty(Ke,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class Ze extends l{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:""}provided for the transaction exceeds the limit allowed for the block.`,{cause:e,name:"IntrinsicGasTooHighError"})}}Object.defineProperty(Ze,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class We extends l{constructor({cause:e,gas:t}={}){super(`The amount of gas ${t?`(${t}) `:""}provided for the transaction is too low.`,{cause:e,name:"IntrinsicGasTooLowError"})}}Object.defineProperty(We,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class Ye extends l{constructor({cause:e}){super("The transaction type is not supported for this chain.",{cause:e,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(Ye,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class Je extends l{constructor({cause:e,maxPriorityFeePerGas:t,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${t?` = ${Se(t)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${Se(n)} gwei`:""}).`].join("\n"),{cause:e,name:"TipAboveFeeCapError"})}}Object.defineProperty(Je,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/max priority fee per gas higher than max fee per gas|tip higher than fee cap/});class Qe extends l{constructor({cause:e}){super(`An error occurred while executing: ${e?.shortMessage}`,{cause:e,name:"UnknownNodeError"})}}function et(e,t){const n=(e.details||"").toLowerCase(),r=e instanceof l?e.walk(e=>e?.code===Me.code):e;return r instanceof l?new Me({cause:e,message:r.details}):Me.nodeMessage.test(n)?new Me({cause:e,message:e.details}):Ve.nodeMessage.test(n)?new Ve({cause:e,maxFeePerGas:t?.maxFeePerGas}):je.nodeMessage.test(n)?new je({cause:e,maxFeePerGas:t?.maxFeePerGas}):De.nodeMessage.test(n)?new De({cause:e,nonce:t?.nonce}):_e.nodeMessage.test(n)?new _e({cause:e,nonce:t?.nonce}):Xe.nodeMessage.test(n)?new Xe({cause:e,nonce:t?.nonce}):Ke.nodeMessage.test(n)?new Ke({cause:e}):Ze.nodeMessage.test(n)?new Ze({cause:e,gas:t?.gas}):We.nodeMessage.test(n)?new We({cause:e,gas:t?.gas}):Ye.nodeMessage.test(n)?new Ye({cause:e}):Je.nodeMessage.test(n)?new Je({cause:e,maxFeePerGas:t?.maxFeePerGas,maxPriorityFeePerGas:t?.maxPriorityFeePerGas}):new Qe({cause:e})}function tt(e,{format:t}){if(!t)return{};const n={};return function t(r){const s=Object.keys(r);for(const i of s)i in e&&(n[i]=e[i]),r[i]&&"object"==typeof r[i]&&!Array.isArray(r[i])&&t(r[i])}(t(e||{})),n}const nt={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function rt(e,t){const n={};return void 0!==e.authorizationList&&(n.authorizationList=e.authorizationList.map(e=>({address:e.address,r:e.r?E(BigInt(e.r)):e.r,s:e.s?E(BigInt(e.s)):e.s,chainId:E(e.chainId),nonce:E(e.nonce),...void 0!==e.yParity?{yParity:E(e.yParity)}:{},...void 0!==e.v&&void 0===e.yParity?{v:E(e.v)}:{}}))),void 0!==e.accessList&&(n.accessList=e.accessList),void 0!==e.blobVersionedHashes&&(n.blobVersionedHashes=e.blobVersionedHashes),void 0!==e.blobs&&("string"!=typeof e.blobs[0]?n.blobs=e.blobs.map(e=>B(e)):n.blobs=e.blobs),void 0!==e.data&&(n.data=e.data),e.account&&(n.from=e.account.address),void 0!==e.from&&(n.from=e.from),void 0!==e.gas&&(n.gas=E(e.gas)),void 0!==e.gasPrice&&(n.gasPrice=E(e.gasPrice)),void 0!==e.maxFeePerBlobGas&&(n.maxFeePerBlobGas=E(e.maxFeePerBlobGas)),void 0!==e.maxFeePerGas&&(n.maxFeePerGas=E(e.maxFeePerGas)),void 0!==e.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=E(e.maxPriorityFeePerGas)),void 0!==e.nonce&&(n.nonce=E(e.nonce)),void 0!==e.to&&(n.to=e.to),void 0!==e.type&&(n.type=nt[e.type]),void 0!==e.value&&(n.value=E(e.value)),n}function st(e){if(e&&0!==e.length)return e.reduce((e,{slot:t,value:n})=>{if(66!==t.length)throw new p({size:t.length,targetSize:66,type:"hex"});if(66!==n.length)throw new p({size:n.length,targetSize:66,type:"hex"});return e[t]=n,e},{})}function it(e){const{balance:t,nonce:n,state:r,stateDiff:s,code:i}=e,o={};if(void 0!==i&&(o.code=i),void 0!==t&&(o.balance=E(t)),void 0!==n&&(o.nonce=E(n)),void 0!==r&&(o.state=st(r)),void 0!==s){if(o.state)throw new Ne;o.stateDiff=st(s)}return o}const ot=2n**256n-1n;function at(e){const{account:t,gasPrice:n,maxFeePerGas:r,maxPriorityFeePerGas:s,to:i}=e,o=t?Ie(t):void 0;if(o&&!me(o.address))throw new h({address:o.address});if(i&&!me(i))throw new h({address:i});if(void 0!==n&&(void 0!==r||void 0!==s))throw new ze;if(r&&r>ot)throw new Ve({maxFeePerGas:r});if(s&&r&&s>r)throw new Je({maxFeePerGas:r,maxPriorityFeePerGas:s})}function ct(e){if(0===e||1===e)return e;if(27===e)return 0;if(28===e)return 1;throw new Error("Invalid yParityOrV value")}async function ut({hash:e,signature:t}){return n=await async function({hash:e,signature:t}){const n=i(e)?e:P(e),{secp256k1:r}=await Promise.resolve().then(function(){return qr});return`0x${(()=>{if("object"==typeof t&&"r"in t&&"s"in t){const{r:e,s:n,v:s,yParity:i}=t,o=ct(Number(i??s));return new r.Signature(b(e),b(n)).addRecoveryBit(o)}const e=i(t)?t:P(t);if(65!==o(e))throw new Error("invalid signature length");const n=ct(x(`0x${e.slice(130)}`));return r.Signature.fromCompact(e.substring(2,130)).addRecoveryBit(n)})().recoverPublicKey(n.substring(2)).toHex(!1)}`}({hash:e,signature:t}),we(`0x${de(`0x${n.substring(4)}`).substring(26)}`);var n}function lt(e,t="hex"){const n=dt(e),r=Pe(new Uint8Array(n.length));return n.encode(r),"hex"===t?B(r.bytes):r.bytes}function dt(e){return Array.isArray(e)?function(e){const t=e.reduce((e,t)=>e+t.length,0),n=ht(t);return{length:t<=55?1+t:1+n+t,encode(r){t<=55?r.pushByte(192+t):(r.pushByte(247+n),1===n?r.pushUint8(t):2===n?r.pushUint16(t):3===n?r.pushUint24(t):r.pushUint32(t));for(const{encode:t}of e)t(r)}}}(e.map(e=>dt(e))):function(e){const t="string"==typeof e?F(e):e,n=ht(t.length),r=1===t.length&&t[0]<128?1:t.length<=55?1+t.length:1+n+t.length;return{length:r,encode(e){1===t.length&&t[0]<128?e.pushBytes(t):t.length<=55?(e.pushByte(128+t.length),e.pushBytes(t)):(e.pushByte(183+n),1===n?e.pushUint8(t.length):2===n?e.pushUint16(t.length):3===n?e.pushUint24(t.length):e.pushUint32(t.length),e.pushBytes(t))}}}(e)}function ht(e){if(e<256)return 1;if(e<65536)return 2;if(e<2**24)return 3;if(e<2**32)return 4;throw new l("Length is too large.")}function ft(e){const{chainId:t,nonce:n,to:r}=e,s=e.contractAddress??e.address,i=de(`0x${["0x05",lt([t?E(t):"0x",s,n?E(n):"0x"])].reduce((e,t)=>e+t.replace("0x",""),"")}`);return"bytes"===r?F(i):i}async function pt(e){const{authorization:t,signature:n}=e;return ut({hash:ft(t),signature:n??t})}class mt extends l{constructor(e,{account:t,docsPath:n,chain:r,data:s,gas:i,gasPrice:o,maxFeePerGas:a,maxPriorityFeePerGas:c,nonce:u,to:l,value:d}){const h=$e({from:t?.address,to:l,value:void 0!==d&&`${Fe(d)} ${r?.nativeCurrency?.symbol||"ETH"}`,data:s,gas:i,gasPrice:void 0!==o&&`${Se(o)} gwei`,maxFeePerGas:void 0!==a&&`${Se(a)} gwei`,maxPriorityFeePerGas:void 0!==c&&`${Se(c)} gwei`,nonce:u});super(e.shortMessage,{cause:e,docsPath:n,metaMessages:[...e.metaMessages?[...e.metaMessages," "]:[],"Estimate Gas Arguments:",h].filter(Boolean),name:"EstimateGasExecutionError"}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cause=e}}class gt extends l{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class wt extends l{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class yt extends l{constructor({maxPriorityFeePerGas:e}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${Se(e)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class bt extends l{constructor({blockHash:e,blockNumber:t}){let n="Block";e&&(n=`Block at hash "${e}"`),t&&(n=`Block at number "${t}"`),super(`${n} could not be found.`,{name:"BlockNotFoundError"})}}const xt={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function vt(e,t){const n={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?x(e.chainId):void 0,gas:e.gas?BigInt(e.gas):void 0,gasPrice:e.gasPrice?BigInt(e.gasPrice):void 0,maxFeePerBlobGas:e.maxFeePerBlobGas?BigInt(e.maxFeePerBlobGas):void 0,maxFeePerGas:e.maxFeePerGas?BigInt(e.maxFeePerGas):void 0,maxPriorityFeePerGas:e.maxPriorityFeePerGas?BigInt(e.maxPriorityFeePerGas):void 0,nonce:e.nonce?x(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?xt[e.type]:void 0,typeHex:e.type?e.type:void 0,value:e.value?BigInt(e.value):void 0,v:e.v?BigInt(e.v):void 0};return e.authorizationList&&(n.authorizationList=e.authorizationList.map(e=>({address:e.address,chainId:Number(e.chainId),nonce:Number(e.nonce),r:e.r,s:e.s,yParity:Number(e.yParity)}))),n.yParity=(()=>{if(e.yParity)return Number(e.yParity);if("bigint"==typeof n.v){if(0n===n.v||27n===n.v)return 0;if(1n===n.v||28n===n.v)return 1;if(n.v>=35n)return n.v%2n==0n?1:0}})(),"legacy"===n.type&&(delete n.accessList,delete n.maxFeePerBlobGas,delete n.maxFeePerGas,delete n.maxPriorityFeePerGas,delete n.yParity),"eip2930"===n.type&&(delete n.maxFeePerBlobGas,delete n.maxFeePerGas,delete n.maxPriorityFeePerGas),"eip1559"===n.type&&delete n.maxFeePerBlobGas,n}function Pt(e,t){const n=(e.transactions??[]).map(e=>"string"==typeof e?e:vt(e));return{...e,baseFeePerGas:e.baseFeePerGas?BigInt(e.baseFeePerGas):null,blobGasUsed:e.blobGasUsed?BigInt(e.blobGasUsed):void 0,difficulty:e.difficulty?BigInt(e.difficulty):void 0,excessBlobGas:e.excessBlobGas?BigInt(e.excessBlobGas):void 0,gasLimit:e.gasLimit?BigInt(e.gasLimit):void 0,gasUsed:e.gasUsed?BigInt(e.gasUsed):void 0,hash:e.hash?e.hash:null,logsBloom:e.logsBloom?e.logsBloom:null,nonce:e.nonce?e.nonce:null,number:e.number?BigInt(e.number):null,size:e.size?BigInt(e.size):void 0,timestamp:e.timestamp?BigInt(e.timestamp):void 0,transactions:n,totalDifficulty:e.totalDifficulty?BigInt(e.totalDifficulty):null}}async function Bt(e,{blockHash:t,blockNumber:n,blockTag:r=e.experimental_blockTag??"latest",includeTransactions:s}={}){const i=s??!1,o=void 0!==n?E(n):void 0;let a=null;if(a=t?await e.request({method:"eth_getBlockByHash",params:[t,i]},{dedupe:!0}):await e.request({method:"eth_getBlockByNumber",params:[o||r,i]},{dedupe:Boolean(o)}),!a)throw new bt({blockHash:t,blockNumber:n});return(e.chain?.formatters?.block?.format||Pt)(a,"getBlock")}async function Et(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function It(e,t){const{block:n,chain:r=e.chain,request:s,type:i="eip1559"}=t||{},o=await(async()=>"function"==typeof r?.fees?.baseFeeMultiplier?r.fees.baseFeeMultiplier({block:n,client:e,request:s}):r?.fees?.baseFeeMultiplier??1.2)();if(o<1)throw new gt;const a=10**(o.toString().split(".")[1]?.length??0),c=e=>e*BigInt(Math.ceil(o*a))/BigInt(a),u=n||await Le(e,Bt,"getBlock")({});if("function"==typeof r?.fees?.estimateFeesPerGas){const t=await r.fees.estimateFeesPerGas({block:n,client:e,multiply:c,request:s,type:i});if(null!==t)return t}if("eip1559"===i){if("bigint"!=typeof u.baseFeePerGas)throw new wt;const t="bigint"==typeof s?.maxPriorityFeePerGas?s.maxPriorityFeePerGas:await async function(e,t){const{block:n,chain:r=e.chain,request:s}=t||{};try{const t=r?.fees?.maxPriorityFeePerGas??r?.fees?.defaultPriorityFee;if("function"==typeof t){const r=n||await Le(e,Bt,"getBlock")({}),i=await t({block:r,client:e,request:s});if(null===i)throw new Error;return i}return void 0!==t?t:b(await e.request({method:"eth_maxPriorityFeePerGas"}))}catch{const[t,r]=await Promise.all([n?Promise.resolve(n):Le(e,Bt,"getBlock")({}),Le(e,Et,"getGasPrice")({})]);if("bigint"!=typeof t.baseFeePerGas)throw new wt;const s=r-t.baseFeePerGas;return s<0n?0n:s}}(e,{block:u,chain:r,request:s}),n=c(u.baseFeePerGas);return{maxFeePerGas:s?.maxFeePerGas??n+t,maxPriorityFeePerGas:t}}return{gasPrice:s?.gasPrice??c(await Le(e,Et,"getGasPrice")({}))}}async function At(e,{address:t,blockTag:n="latest",blockNumber:r}){return x(await e.request({method:"eth_getTransactionCount",params:[t,"bigint"==typeof r?E(r):n]},{dedupe:Boolean(r)}))}function Tt(e){const{kzg:t}=e,n=e.to??("string"==typeof e.blobs[0]?"hex":"bytes"),r="string"==typeof e.blobs[0]?e.blobs.map(e=>F(e)):e.blobs,s=[];for(const e of r)s.push(Uint8Array.from(t.blobToKzgCommitment(e)));return"bytes"===n?s:s.map(e=>B(e))}function kt(e){const{kzg:t}=e,n=e.to??("string"==typeof e.blobs[0]?"hex":"bytes"),r="string"==typeof e.blobs[0]?e.blobs.map(e=>F(e)):e.blobs,s="string"==typeof e.commitments[0]?e.commitments.map(e=>F(e)):e.commitments,i=[];for(let e=0;e<r.length;e++){const n=r[e],o=s[e];i.push(Uint8Array.from(t.computeBlobKzgProof(n,o)))}return"bytes"===n?i:i.map(e=>B(e))}function Ct(e,t,n){return e&t^~e&n}function Ft(e,t,n){return e&t^e&n^t&n}class St extends _{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=L(this.buffer)}update(e){R(this),U(e=D(e));const{view:t,buffer:n,blockLen:r}=this,s=e.length;for(let i=0;i<s;){const o=Math.min(r-this.pos,s-i);if(o===r){const t=L(e);for(;r<=s-i;i+=r)this.process(t,i);continue}n.set(e.subarray(i,i+o),this.pos),this.pos+=o,i+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){R(this),H(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:i}=this;t[i++]=128,q(this.buffer.subarray(i)),this.padOffset>r-i&&(this.process(n,0),i=0);for(let e=i;e<r;e++)t[e]=0;!function(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const s=BigInt(32),i=BigInt(4294967295),o=Number(n>>s&i),a=Number(n&i),c=r?4:0,u=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const o=L(e),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=a/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<c;e++)o.setUint32(4*e,u[e],s)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:s,destroyed:i,pos:o}=this;return e.destroyed=i,e.finished=s,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Nt=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$t=new Uint32Array(64);class zt extends St{constructor(e=32){super(64,e,8,!1),this.A=0|Ot[0],this.B=0|Ot[1],this.C=0|Ot[2],this.D=0|Ot[3],this.E=0|Ot[4],this.F=0|Ot[5],this.G=0|Ot[6],this.H=0|Ot[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:i,G:o,H:a}=this;return[e,t,n,r,s,i,o,a]}set(e,t,n,r,s,i,o,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|i,this.G=0|o,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)$t[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=$t[e-15],n=$t[e-2],r=M(t,7)^M(t,18)^t>>>3,s=M(n,17)^M(n,19)^n>>>10;$t[e]=s+$t[e-7]+r+$t[e-16]|0}let{A:n,B:r,C:s,D:i,E:o,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(M(o,6)^M(o,11)^M(o,25))+Ct(o,a,c)+Nt[e]+$t[e]|0,l=(M(n,2)^M(n,13)^M(n,22))+Ft(n,r,s)|0;u=c,c=a,a=o,o=i+t|0,i=s,s=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,i=i+this.D|0,o=o+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,s,i,o,a,c,u)}roundClean(){q($t)}destroy(){this.set(0,0,0,0,0,0,0,0),q(this.buffer)}}const Gt=X(()=>new zt),Ut=Gt;function Rt(e){const{commitment:t,version:n=1}=e,r=e.to??("string"==typeof t?"hex":"bytes"),s=Ut(i(o=t,{strict:!1})?T(o):o);var o;return s.set([n],0),"bytes"===r?s:B(s)}const Ht=4096,qt=131072,Lt=761855;class Mt extends l{constructor({maxSize:e,size:t}){super("Blob size is too large.",{metaMessages:[`Max: ${e} bytes`,`Given: ${t} bytes`],name:"BlobSizeTooLargeError"})}}class Vt extends l{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}function jt(e){const{data:t,kzg:n,to:r}=e,s=e.blobs??function(e){const t="string"==typeof e.data?F(e.data):e.data,n=o(t);if(!n)throw new Vt;if(n>Lt)throw new Mt({maxSize:Lt,size:n});const r=[];let s=!0,i=0;for(;s;){const e=Pe(new Uint8Array(qt));let n=0;for(;n<Ht;){const r=t.slice(i,i+31);if(e.pushByte(0),e.pushBytes(r),r.length<31){e.pushByte(128),s=!1;break}n++,i+=31}r.push(e)}return r.map(e=>B(e.bytes))}({data:t}),i=e.commitments??Tt({blobs:s,kzg:n,to:r}),a=e.proofs??kt({blobs:s,commitments:i,kzg:n,to:r}),c=[];for(let e=0;e<s.length;e++)c.push({blob:s[e],commitment:i[e],proof:a[e]});return c}async function Dt(e){return x(await e.request({method:"eth_chainId"},{dedupe:!0}))}const _t=["blobVersionedHashes","chainId","fees","gas","nonce","type"],Xt=new Map;async function Kt(e,t){const{account:n=e.account,blobs:r,chain:s,gas:i,kzg:o,nonce:a,nonceManager:c,parameters:u=_t,type:l}=t,d=n?Ie(n):n,h={...t,...d?{from:d?.address}:{}};let f,p;async function m(){return f||(f=await Le(e,Bt,"getBlock")({blockTag:"latest"}),f)}async function g(){if(p)return p;if(s)return s.id;if(void 0!==t.chainId)return t.chainId;const n=await Le(e,Dt,"getChainId")({});return p=n,p}if(u.includes("nonce")&&void 0===a&&d)if(c){const t=await g();h.nonce=await c.consume({address:d.address,chainId:t,client:e})}else h.nonce=await Le(e,At,"getTransactionCount")({address:d.address,blockTag:"pending"});if((u.includes("blobVersionedHashes")||u.includes("sidecars"))&&r&&o){const e=Tt({blobs:r,kzg:o});if(u.includes("blobVersionedHashes")){const t=function(e){const{commitments:t,version:n}=e,r=e.to,s=[];for(const e of t)s.push(Rt({commitment:e,to:r,version:n}));return s}({commitments:e,to:"hex"});h.blobVersionedHashes=t}if(u.includes("sidecars")){const t=jt({blobs:r,commitments:e,proofs:kt({blobs:r,commitments:e,kzg:o}),to:"hex"});h.sidecars=t}}if(u.includes("chainId")&&(h.chainId=await g()),(u.includes("fees")||u.includes("type"))&&void 0===l)try{h.type=function(e){if(e.type)return e.type;if(void 0!==e.authorizationList)return"eip7702";if(void 0!==e.blobs||void 0!==e.blobVersionedHashes||void 0!==e.maxFeePerBlobGas||void 0!==e.sidecars)return"eip4844";if(void 0!==e.maxFeePerGas||void 0!==e.maxPriorityFeePerGas)return"eip1559";if(void 0!==e.gasPrice)return void 0!==e.accessList?"eip2930":"legacy";throw new Ge({transaction:e})}(h)}catch{let t=Xt.get(e.uid);if(void 0===t){const n=await m();t="bigint"==typeof n?.baseFeePerGas,Xt.set(e.uid,t)}h.type=t?"eip1559":"legacy"}if(u.includes("fees"))if("legacy"!==h.type&&"eip2930"!==h.type){if(void 0===h.maxFeePerGas||void 0===h.maxPriorityFeePerGas){const n=await m(),{maxFeePerGas:r,maxPriorityFeePerGas:i}=await It(e,{block:n,chain:s,request:h});if(void 0===t.maxPriorityFeePerGas&&t.maxFeePerGas&&t.maxFeePerGas<i)throw new yt({maxPriorityFeePerGas:i});h.maxPriorityFeePerGas=i,h.maxFeePerGas=r}}else{if(void 0!==t.maxFeePerGas||void 0!==t.maxPriorityFeePerGas)throw new wt;if(void 0===t.gasPrice){const t=await m(),{gasPrice:n}=await It(e,{block:t,chain:s,request:h,type:"legacy"});h.gasPrice=n}}return u.includes("gas")&&void 0===i&&(h.gas=await Le(e,Zt,"estimateGas")({...h,account:d,prepare:"local"===d?.type?[]:["blobVersionedHashes"]})),at(h),delete h.parameters,h}async function Zt(e,t){const{account:n=e.account,prepare:r=!0}=t,s=n?Ie(n):void 0,i=Array.isArray(r)?r:"local"!==s?.type?["blobVersionedHashes"]:void 0;try{const{accessList:n,authorizationList:o,blobs:a,blobVersionedHashes:c,blockNumber:u,blockTag:d,data:f,gas:p,gasPrice:m,maxFeePerBlobGas:g,maxFeePerGas:w,maxPriorityFeePerGas:y,nonce:b,value:x,stateOverride:v,...P}=r?await Kt(e,{...t,parameters:i}):t,B=("bigint"==typeof u?E(u):void 0)||d,I=function(e){if(!e)return;const t={};for(const{address:n,...r}of e){if(!me(n,{strict:!1}))throw new h({address:n});if(t[n])throw new Oe({address:n});t[n]=it(r)}return t}(v),A=await(async()=>P.to?P.to:o&&o.length>0?await pt({authorization:o[0]}).catch(()=>{throw new l("`to` is required. Could not infer from `authorizationList`")}):void 0)();at(t);const T=e.chain?.formatters?.transactionRequest?.format,k=(T||rt)({...tt(P,{format:T}),account:s,accessList:n,authorizationList:o,blobs:a,blobVersionedHashes:c,data:f,gas:p,gasPrice:m,maxFeePerBlobGas:g,maxFeePerGas:w,maxPriorityFeePerGas:y,nonce:b,to:A,value:x},"estimateGas");return BigInt(await e.request({method:"eth_estimateGas",params:I?[k,B??e.experimental_blockTag??"latest",I]:B?[k,B]:[k]}))}catch(n){throw function(e,{docsPath:t,...n}){const r=(()=>{const t=et(e,n);return t instanceof Qe?e:t})();return new mt(r,{docsPath:t,...n})}(n,{...t,account:s,chain:e.chain})}}async function Wt(e,{address:t,blockNumber:n,blockTag:r=e.experimental_blockTag??"latest"}){const s="bigint"==typeof n?E(n):void 0,i=await e.request({method:"eth_getBalance",params:[t,s||r]});return BigInt(i)}const Yt=new Map,Jt=new Map;async function Qt(e,{cacheKey:t,cacheTime:n=Number.POSITIVE_INFINITY}){const r=function(e){const t=(e,t)=>({clear:()=>t.delete(e),get:()=>t.get(e),set:n=>t.set(e,n)}),n=t(e,Yt),r=t(e,Jt);return{clear:()=>{n.clear(),r.clear()},promise:n,response:r}}(t),s=r.response.get();if(s&&n>0){if(Date.now()-s.created.getTime()<n)return s.data}let i=r.promise.get();i||(i=e(),r.promise.set(i));try{const e=await i;return r.response.set({created:new Date,data:e}),e}finally{r.promise.clear()}}async function en(e,{cacheTime:t=e.cacheTime}={}){const n=await Qt(()=>e.request({method:"eth_blockNumber"}),{cacheKey:(r=e.uid,`blockNumber.${r}`),cacheTime:t});var r;return BigInt(n)}async function tn(e){return new Promise(t=>setTimeout(t,e))}function nn(e,{delay:t=100,retryCount:n=2,shouldRetry:r=()=>!0}={}){return new Promise((s,i)=>{const o=async({count:a=0}={})=>{try{const t=await e();s(t)}catch(e){if(a<n&&await r({count:a,error:e}))return(async({error:e})=>{const n="function"==typeof t?t({count:a,error:e}):t;n&&await tn(n),o({count:a+1})})({error:e});i(e)}};o()})}function rn({chain:e,currentChainId:t}){if(!e)throw new Ee;if(t!==e.id)throw new Be({chain:e,currentChainId:t})}const sn={"0x0":"reverted","0x1":"success"};function on(e,t){const n={...e,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,contractAddress:e.contractAddress?e.contractAddress:null,cumulativeGasUsed:e.cumulativeGasUsed?BigInt(e.cumulativeGasUsed):null,effectiveGasPrice:e.effectiveGasPrice?BigInt(e.effectiveGasPrice):null,gasUsed:e.gasUsed?BigInt(e.gasUsed):null,logs:e.logs?e.logs.map(e=>function(e,{args:t,eventName:n}={}){return{...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,logIndex:e.logIndex?Number(e.logIndex):null,transactionHash:e.transactionHash?e.transactionHash:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,...n?{args:t,eventName:n}:{}}}(e)):null,to:e.to?e.to:null,transactionIndex:e.transactionIndex?x(e.transactionIndex):null,status:e.status?sn[e.status]:null,type:e.type?xt[e.type]||e.type:null};return e.blobGasPrice&&(n.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(n.blobGasUsed=BigInt(e.blobGasUsed)),n}async function an(e,{blockHash:t,blockNumber:n,blockTag:r,hash:s,index:i}){const o=r||"latest",a=void 0!==n?E(n):void 0;let c=null;if(c=s?await e.request({method:"eth_getTransactionByHash",params:[s]},{dedupe:!0}):t?await e.request({method:"eth_getTransactionByBlockHashAndIndex",params:[t,E(i)]},{dedupe:!0}):await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[a||o,E(i)]},{dedupe:Boolean(a)}),!c)throw new Re({blockHash:t,blockNumber:n,blockTag:o,hash:s,index:i});return(e.chain?.formatters?.transaction?.format||vt)(c,"getTransaction")}async function cn(e,{hash:t}){const n=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!n)throw new He({hash:t});return(e.chain?.formatters?.transactionReceipt?.format||on)(n,"getTransactionReceipt")}class un extends _{constructor(e,t){super(),this.finished=!1,this.destroyed=!1,function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");G(e.outputLen),G(e.blockLen)}(e);const n=D(t);if(this.iHash=e.create(),"function"!=typeof this.iHash.update)throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const r=this.blockLen,s=new Uint8Array(r);s.set(n.length>r?e.create().update(n).digest():n);for(let e=0;e<s.length;e++)s[e]^=54;this.iHash.update(s),this.oHash=e.create();for(let e=0;e<s.length;e++)s[e]^=106;this.oHash.update(s),q(s)}update(e){return R(this),this.iHash.update(e),this}digestInto(e){R(this),U(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:t,iHash:n,finished:r,destroyed:s,blockLen:i,outputLen:o}=this;return e.finished=r,e.destroyed=s,e.blockLen=i,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const ln=(e,t,n)=>new un(e,t).update(n).digest();ln.create=(e,t)=>new un(e,t);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const dn=BigInt(0),hn=BigInt(1);function fn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function pn(e){if(!fn(e))throw new Error("Uint8Array expected")}function mn(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function gn(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function wn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?dn:BigInt("0x"+e)}const yn="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,bn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function xn(e){if(pn(e),yn)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=bn[e[n]];return t}const vn=48,Pn=57,Bn=65,En=70,In=97,An=102;function Tn(e){return e>=vn&&e<=Pn?e-vn:e>=Bn&&e<=En?e-(Bn-10):e>=In&&e<=An?e-(In-10):void 0}function kn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(yn)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,s=0;t<n;t++,s+=2){const n=Tn(e.charCodeAt(s)),i=Tn(e.charCodeAt(s+1));if(void 0===n||void 0===i){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+