@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
import{utils as e,secp256k1 as t,Credential as n,Utxo as r,TypeSymbols as s,Address as o,avaxSerial as i,pvmSerial as a,PChainOwner as c,Int as u,TransferableOutput as l,Id as d,evm as h,pvm as f,Signature as p,UnsignedTx as m}from"@avalabs/avalanchejs";import{isAddress as g}from"viem";import*as w from"node:crypto";async function b(e){return e.request({method:"avalanche_getAccountPubKey",params:{}})}function y(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}function x(e){return y(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}const v="2.38.6";let P=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,B=`viem@${v}`;class E extends Error{constructor(e,t={}){const n=t.cause instanceof E?t.cause.details:t.cause?.message?t.cause.message:t.details,r=t.cause instanceof E&&t.cause.docsPath||t.docsPath,s=P?.({...t,docsPath:r});super([e||"An error occurred.","",...t.metaMessages?[...t.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...B?[`Version: ${B}`]:[]].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=v}walk(e){return I(this,e)}}function I(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?I(e.cause,t):t?null:e}class A extends E{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 T extends E{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 k extends E{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 F(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 T({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 T({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let s=0;s<n;s++){const o="right"===t;r[o?s:n-s-1]=e[o?s:e.length-s-1]}return r}(e,{dir:t,size:n})}class C extends E{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 N extends E{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function S(e,{size:t}){if(x(e)>t)throw new N({givenSize:x(e),maxSize:t})}function O(e,t={}){const{signed:n}=t;t.size&&S(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 $(e,t={}){return Number(O(e,t))}const z=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function G(e,t={}){return"number"==typeof e||"bigint"==typeof e?R(e,t):"string"==typeof e?function(e,t={}){const n=H.encode(e);return U(n,t)}(e,t):"boolean"==typeof e?function(e,t={}){const n=`0x${Number(e)}`;if("number"==typeof t.size)return S(n,{size:t.size}),F(n,{size:t.size});return n}(e,t):U(e,t)}function U(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=z[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(S(r,{size:t.size}),F(r,{dir:"right",size:t.size})):r}function R(e,t={}){const{signed:n,size:r}=t,s=BigInt(e);let o;r?o=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(o=BigInt(Number.MAX_SAFE_INTEGER));const i="bigint"==typeof o&&n?-o-1n:0;if(o&&s>o||s<i){const t="bigint"==typeof e?"n":"";throw new C({max:o?`${o}${t}`:void 0,min:`${i}${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?F(a,{size:r}):a}const H=new TextEncoder;const q=new TextEncoder;function L(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=R(e,t);return j(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return S(n,{size:t.size}),F(n,{size:t.size});return n}(e,t):y(e)?j(e,t):D(e,t)}const M={zero:48,nine:57,A:65,F:70,a:97,f:102};function V(e){return e>=M.zero&&e<=M.nine?e-M.zero:e>=M.A&&e<=M.F?e-(M.A-10):e>=M.a&&e<=M.f?e-(M.a-10):void 0}function j(e,t={}){let n=e;t.size&&(S(n,{size:t.size}),n=F(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const s=r.length/2,o=new Uint8Array(s);for(let e=0,t=0;e<s;e++){const n=V(r.charCodeAt(t++)),s=V(r.charCodeAt(t++));if(void 0===n||void 0===s)throw new E(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);o[e]=16*n+s}return o}function D(e,t={}){const n=q.encode(e);return"number"==typeof t.size?(S(n,{size:t.size}),F(n,{dir:"right",size:t.size})):n}const _=BigInt(2**32-1),X=BigInt(32);function Z(e,t=!1){return t?{h:Number(e&_),l:Number(e>>X&_)}:{h:0|Number(e>>X&_),l:0|Number(e&_)}}const K=w&&"object"==typeof w&&"webcrypto"in w?w.webcrypto:w&&"object"==typeof w&&"randomBytes"in w?w:void 0;function W(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function Y(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 J(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 Q(e,t){Y(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ee(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function te(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function ne(e,t){return e<<32-t|e>>>t}function re(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const se=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=re(e[t]);return e};function oe(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)),Y(e),e}class ie{}function ae(e){const t=t=>e().update(oe(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function ce(e=32){if(K&&"function"==typeof K.getRandomValues)return K.getRandomValues(new Uint8Array(e));if(K&&"function"==typeof K.randomBytes)return Uint8Array.from(K.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const ue=BigInt(0),le=BigInt(1),de=BigInt(2),he=BigInt(7),fe=BigInt(256),pe=BigInt(113),me=[],ge=[],we=[];for(let e=0,t=le,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],me.push(2*(5*r+n)),ge.push((e+1)*(e+2)/2%64);let s=ue;for(let e=0;e<7;e++)t=(t<<le^(t>>he)*pe)%fe,t&de&&(s^=le<<(le<<BigInt(e))-le);we.push(s)}const be=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),s=new Uint32Array(n);for(let o=0;o<n;o++){const{h:n,l:i}=Z(e[o],t);[r[o],s[o]]=[n,i]}return[r,s]}(we,!0),ye=be[0],xe=be[1],ve=(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),Pe=(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 Be extends ie{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,W(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var o;this.state=new Uint8Array(200),this.state32=(o=this.state,new Uint32Array(o.buffer,o.byteOffset,Math.floor(o.byteLength/4)))}clone(){return this._cloneInto()}keccak(){se(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,o=n[s],i=n[s+1],a=ve(o,i,1)^n[r],c=Pe(o,i,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=ge[n],o=ve(t,s,r),i=Pe(t,s,r),a=me[n];t=e[a],s=e[a+1],e[a]=o,e[a+1]=i}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]^=ye[r],e[1]^=xe[r]}ee(n)}(this.state32,this.rounds),se(this.state32),this.posOut=0,this.pos=0}update(e){J(this),Y(e=oe(e));const{blockLen:t,state:n}=this,r=e.length;for(let s=0;s<r;){const o=Math.min(t-this.pos,r-s);for(let t=0;t<o;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){J(this,!1),Y(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 o=Math.min(n-this.posOut,s-r);e.set(t.subarray(this.posOut,this.posOut+o),r),this.posOut+=o,r+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return W(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Q(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,ee(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:s,enableXOF:o}=this;return e||(e=new Be(t,n,r,o,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=o,e.destroyed=this.destroyed,e}}const Ee=(()=>{return e=1,t=136,n=32,ae(()=>new Be(t,e,n));var e,t,n})();function Ie(e,t){const n=t||"hex",r=Ee(y(e,{strict:!1})?L(e):e);return"bytes"===n?r:G(r)}class Ae 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 Te=/^0x[a-fA-F0-9]{40}$/,ke=new Ae(8192);function Fe(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(ke.has(r))return ke.get(r);const s=!(!Te.test(e)||e.toLowerCase()!==e&&n&&Ne(e)!==e);return ke.set(r,s),s}const Ce=new Ae(8192);function Ne(e,t){if(Ce.has(`${e}.${t}`))return Ce.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=Ie(D(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 o=`0x${s.join("")}`;return Ce.set(`${e}.${t}`,o),o}class Se extends E{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class Oe extends E{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class $e extends E{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const ze={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 $e({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new Oe({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new Se({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 Se({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 Ge(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(ze);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}class Ue extends E{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 Re extends E{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 He(e){return"string"==typeof e?{address:e,type:"json-rpc"}:e}const qe=(e,t,n)=>JSON.stringify(e,(e,t)=>"bigint"==typeof t?t.toString():t,n),Le={gwei:9,wei:18},Me={ether:-9,wei:9};function Ve(e,t){let n=e.toString();const r=n.startsWith("-");r&&(n=n.slice(1)),n=n.padStart(t,"0");let[s,o]=[n.slice(0,n.length-t),n.slice(n.length-t)];return o=o.replace(/(0+)$/,""),`${r?"-":""}${s||"0"}${o?`.${o}`:""}`}function je(e,t="wei"){return Ve(e,Le[t])}function De(e,t="wei"){return Ve(e,Me[t])}class _e extends E{constructor({address:e}){super(`State for account "${e}" is set multiple times.`,{name:"AccountStateConflictError"})}}class Xe extends E{constructor(){super("state and stateDiff are set on the same account.",{name:"StateAssignmentConflictError"})}}function Ze(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 Ke extends E{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 We extends E{constructor({transaction:e}){super("Cannot infer a transaction type from provided transaction.",{metaMessages:["Provided Transaction:","{",Ze(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 Ye extends E{constructor(e,{account:t,docsPath:n,chain:r,data:s,gas:o,gasPrice:i,maxFeePerGas:a,maxPriorityFeePerGas:c,nonce:u,to:l,value:d}){const h=Ze({chain:r&&`${r?.name} (id: ${r?.id})`,from:t?.address,to:l,value:void 0!==d&&`${je(d)} ${r?.nativeCurrency?.symbol||"ETH"}`,data:s,gas:o,gasPrice:void 0!==i&&`${De(i)} gwei`,maxFeePerGas:void 0!==a&&`${De(a)} gwei`,maxPriorityFeePerGas:void 0!==c&&`${De(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 Je extends E{constructor({blockHash:e,blockNumber:t,blockTag:n,hash:r,index:s}){let o="Transaction";n&&void 0!==s&&(o=`Transaction at block time "${n}" at index "${s}"`),e&&void 0!==s&&(o=`Transaction at block hash "${e}" at index "${s}"`),t&&void 0!==s&&(o=`Transaction at block number "${t}" at index "${s}"`),r&&(o=`Transaction with hash "${r}"`),super(`${o} could not be found.`,{name:"TransactionNotFoundError"})}}class Qe extends E{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 et extends E{constructor({hash:e}){super(`Timed out while waiting for transaction with hash "${e}" to be confirmed.`,{name:"WaitForTransactionReceiptTimeoutError"})}}function tt(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 nt extends E{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(nt,"code",{enumerable:!0,configurable:!0,writable:!0,value:3}),Object.defineProperty(nt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/execution reverted/});class rt extends E{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${De(t)} gwei`:""}) cannot be higher than the maximum allowed value (2^256-1).`,{cause:e,name:"FeeCapTooHighError"})}}Object.defineProperty(rt,"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 st extends E{constructor({cause:e,maxFeePerGas:t}={}){super(`The fee cap (\`maxFeePerGas\`${t?` = ${De(t)}`:""} gwei) cannot be lower than the block base fee.`,{cause:e,name:"FeeCapTooLowError"})}}Object.defineProperty(st,"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 ot extends E{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(ot,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too high/});class it extends E{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(it,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce too low|transaction already imported|already known/});class at extends E{constructor({cause:e,nonce:t}={}){super(`Nonce provided for the transaction ${t?`(${t}) `:""}exceeds the maximum allowed nonce.`,{cause:e,name:"NonceMaxValueError"})}}Object.defineProperty(at,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/nonce has max value/});class ct extends E{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(ct,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/insufficient funds|exceeds transaction sender account balance/});class ut extends E{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(ut,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too high|gas limit reached/});class lt extends E{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(lt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/intrinsic gas too low/});class dt extends E{constructor({cause:e}){super("The transaction type is not supported for this chain.",{cause:e,name:"TransactionTypeNotSupportedError"})}}Object.defineProperty(dt,"nodeMessage",{enumerable:!0,configurable:!0,writable:!0,value:/transaction type not valid/});class ht extends E{constructor({cause:e,maxPriorityFeePerGas:t,maxFeePerGas:n}={}){super([`The provided tip (\`maxPriorityFeePerGas\`${t?` = ${De(t)} gwei`:""}) cannot be higher than the fee cap (\`maxFeePerGas\`${n?` = ${De(n)} gwei`:""}).`].join("\n"),{cause:e,name:"TipAboveFeeCapError"})}}Object.defineProperty(ht,"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 ft extends E{constructor({cause:e}){super(`An error occurred while executing: ${e?.shortMessage}`,{cause:e,name:"UnknownNodeError"})}}function pt(e,t){const n=(e.details||"").toLowerCase(),r=e instanceof E?e.walk(e=>e?.code===nt.code):e;return r instanceof E?new nt({cause:e,message:r.details}):nt.nodeMessage.test(n)?new nt({cause:e,message:e.details}):rt.nodeMessage.test(n)?new rt({cause:e,maxFeePerGas:t?.maxFeePerGas}):st.nodeMessage.test(n)?new st({cause:e,maxFeePerGas:t?.maxFeePerGas}):ot.nodeMessage.test(n)?new ot({cause:e,nonce:t?.nonce}):it.nodeMessage.test(n)?new it({cause:e,nonce:t?.nonce}):at.nodeMessage.test(n)?new at({cause:e,nonce:t?.nonce}):ct.nodeMessage.test(n)?new ct({cause:e}):ut.nodeMessage.test(n)?new ut({cause:e,gas:t?.gas}):lt.nodeMessage.test(n)?new lt({cause:e,gas:t?.gas}):dt.nodeMessage.test(n)?new dt({cause:e}):ht.nodeMessage.test(n)?new ht({cause:e,maxFeePerGas:t?.maxFeePerGas,maxPriorityFeePerGas:t?.maxPriorityFeePerGas}):new ft({cause:e})}function mt(e,{format:t}){if(!t)return{};const n={};return function t(r){const s=Object.keys(r);for(const o of s)o in e&&(n[o]=e[o]),r[o]&&"object"==typeof r[o]&&!Array.isArray(r[o])&&t(r[o])}(t(e||{})),n}const gt={legacy:"0x0",eip2930:"0x1",eip1559:"0x2",eip4844:"0x3",eip7702:"0x4"};function wt(e,t){const n={};return void 0!==e.authorizationList&&(n.authorizationList=e.authorizationList.map(e=>({address:e.address,r:e.r?R(BigInt(e.r)):e.r,s:e.s?R(BigInt(e.s)):e.s,chainId:R(e.chainId),nonce:R(e.nonce),...void 0!==e.yParity?{yParity:R(e.yParity)}:{},...void 0!==e.v&&void 0===e.yParity?{v:R(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=>U(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=R(e.gas)),void 0!==e.gasPrice&&(n.gasPrice=R(e.gasPrice)),void 0!==e.maxFeePerBlobGas&&(n.maxFeePerBlobGas=R(e.maxFeePerBlobGas)),void 0!==e.maxFeePerGas&&(n.maxFeePerGas=R(e.maxFeePerGas)),void 0!==e.maxPriorityFeePerGas&&(n.maxPriorityFeePerGas=R(e.maxPriorityFeePerGas)),void 0!==e.nonce&&(n.nonce=R(e.nonce)),void 0!==e.to&&(n.to=e.to),void 0!==e.type&&(n.type=gt[e.type]),void 0!==e.value&&(n.value=R(e.value)),n}function bt(e){if(e&&0!==e.length)return e.reduce((e,{slot:t,value:n})=>{if(66!==t.length)throw new k({size:t.length,targetSize:66,type:"hex"});if(66!==n.length)throw new k({size:n.length,targetSize:66,type:"hex"});return e[t]=n,e},{})}function yt(e){const{balance:t,nonce:n,state:r,stateDiff:s,code:o}=e,i={};if(void 0!==o&&(i.code=o),void 0!==t&&(i.balance=R(t)),void 0!==n&&(i.nonce=R(n)),void 0!==r&&(i.state=bt(r)),void 0!==s){if(i.state)throw new Xe;i.stateDiff=bt(s)}return i}const xt=2n**256n-1n;function vt(e){const{account:t,gasPrice:n,maxFeePerGas:r,maxPriorityFeePerGas:s,to:o}=e,i=t?He(t):void 0;if(i&&!Fe(i.address))throw new A({address:i.address});if(o&&!Fe(o))throw new A({address:o});if(void 0!==n&&(void 0!==r||void 0!==s))throw new Ke;if(r&&r>xt)throw new rt({maxFeePerGas:r});if(s&&r&&s>r)throw new ht({maxFeePerGas:r,maxPriorityFeePerGas:s})}function Pt(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 Bt({hash:e,signature:t}){return n=await async function({hash:e,signature:t}){const n=y(e)?e:G(e),{secp256k1:r}=await Promise.resolve().then(function(){return es});return`0x${(()=>{if("object"==typeof t&&"r"in t&&"s"in t){const{r:e,s:n,v:s,yParity:o}=t,i=Pt(Number(o??s));return new r.Signature(O(e),O(n)).addRecoveryBit(i)}const e=y(t)?t:G(t);if(65!==x(e))throw new Error("invalid signature length");const n=Pt($(`0x${e.slice(130)}`));return r.Signature.fromCompact(e.substring(2,130)).addRecoveryBit(n)})().recoverPublicKey(n.substring(2)).toHex(!1)}`}({hash:e,signature:t}),Ne(`0x${Ie(`0x${n.substring(4)}`).substring(26)}`);var n}function Et(e,t="hex"){const n=It(e),r=Ge(new Uint8Array(n.length));return n.encode(r),"hex"===t?U(r.bytes):r.bytes}function It(e){return Array.isArray(e)?function(e){const t=e.reduce((e,t)=>e+t.length,0),n=At(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=>It(e))):function(e){const t="string"==typeof e?j(e):e,n=At(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 At(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 E("Length is too large.")}function Tt(e){const{chainId:t,nonce:n,to:r}=e,s=e.contractAddress??e.address,o=Ie(`0x${["0x05",Et([t?R(t):"0x",s,n?R(n):"0x"])].reduce((e,t)=>e+t.replace("0x",""),"")}`);return"bytes"===r?j(o):o}async function kt(e){const{authorization:t,signature:n}=e;return Bt({hash:Tt(t),signature:n??t})}class Ft extends E{constructor(e,{account:t,docsPath:n,chain:r,data:s,gas:o,gasPrice:i,maxFeePerGas:a,maxPriorityFeePerGas:c,nonce:u,to:l,value:d}){const h=Ze({from:t?.address,to:l,value:void 0!==d&&`${je(d)} ${r?.nativeCurrency?.symbol||"ETH"}`,data:s,gas:o,gasPrice:void 0!==i&&`${De(i)} gwei`,maxFeePerGas:void 0!==a&&`${De(a)} gwei`,maxPriorityFeePerGas:void 0!==c&&`${De(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 Ct extends E{constructor(){super("`baseFeeMultiplier` must be greater than 1.",{name:"BaseFeeScalarError"})}}class Nt extends E{constructor(){super("Chain does not support EIP-1559 fees.",{name:"Eip1559FeesNotSupportedError"})}}class St extends E{constructor({maxPriorityFeePerGas:e}){super(`\`maxFeePerGas\` cannot be less than the \`maxPriorityFeePerGas\` (${De(e)} gwei).`,{name:"MaxFeePerGasTooLowError"})}}class Ot extends E{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 $t={"0x0":"legacy","0x1":"eip2930","0x2":"eip1559","0x3":"eip4844","0x4":"eip7702"};function zt(e,t){const n={...e,blockHash:e.blockHash?e.blockHash:null,blockNumber:e.blockNumber?BigInt(e.blockNumber):null,chainId:e.chainId?$(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?$(e.nonce):void 0,to:e.to?e.to:null,transactionIndex:e.transactionIndex?Number(e.transactionIndex):null,type:e.type?$t[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 Gt(e,t){const n=(e.transactions??[]).map(e=>"string"==typeof e?e:zt(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 Ut(e,{blockHash:t,blockNumber:n,blockTag:r=e.experimental_blockTag??"latest",includeTransactions:s}={}){const o=s??!1,i=void 0!==n?R(n):void 0;let a=null;if(a=t?await e.request({method:"eth_getBlockByHash",params:[t,o]},{dedupe:!0}):await e.request({method:"eth_getBlockByNumber",params:[i||r,o]},{dedupe:Boolean(i)}),!a)throw new Ot({blockHash:t,blockNumber:n});return(e.chain?.formatters?.block?.format||Gt)(a,"getBlock")}async function Rt(e){const t=await e.request({method:"eth_gasPrice"});return BigInt(t)}async function Ht(e,t){const{block:n,chain:r=e.chain,request:s,type:o="eip1559"}=t||{},i=await(async()=>"function"==typeof r?.fees?.baseFeeMultiplier?r.fees.baseFeeMultiplier({block:n,client:e,request:s}):r?.fees?.baseFeeMultiplier??1.2)();if(i<1)throw new Ct;const a=10**(i.toString().split(".")[1]?.length??0),c=e=>e*BigInt(Math.ceil(i*a))/BigInt(a),u=n||await tt(e,Ut,"getBlock")({});if("function"==typeof r?.fees?.estimateFeesPerGas){const t=await r.fees.estimateFeesPerGas({block:n,client:e,multiply:c,request:s,type:o});if(null!==t)return t}if("eip1559"===o){if("bigint"!=typeof u.baseFeePerGas)throw new Nt;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 tt(e,Ut,"getBlock")({}),o=await t({block:r,client:e,request:s});if(null===o)throw new Error;return o}return void 0!==t?t:O(await e.request({method:"eth_maxPriorityFeePerGas"}))}catch{const[t,r]=await Promise.all([n?Promise.resolve(n):tt(e,Ut,"getBlock")({}),tt(e,Rt,"getGasPrice")({})]);if("bigint"!=typeof t.baseFeePerGas)throw new Nt;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 tt(e,Rt,"getGasPrice")({}))}}async function qt(e,{address:t,blockTag:n="latest",blockNumber:r}){return $(await e.request({method:"eth_getTransactionCount",params:[t,"bigint"==typeof r?R(r):n]},{dedupe:Boolean(r)}))}function Lt(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=>j(e)):e.blobs,s=[];for(const e of r)s.push(Uint8Array.from(t.blobToKzgCommitment(e)));return"bytes"===n?s:s.map(e=>U(e))}function Mt(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=>j(e)):e.blobs,s="string"==typeof e.commitments[0]?e.commitments.map(e=>j(e)):e.commitments,o=[];for(let e=0;e<r.length;e++){const n=r[e],i=s[e];o.push(Uint8Array.from(t.computeBlobKzgProof(n,i)))}return"bytes"===n?o:o.map(e=>U(e))}function Vt(e,t,n){return e&t^~e&n}function jt(e,t,n){return e&t^e&n^t&n}class Dt extends ie{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=te(this.buffer)}update(e){J(this),Y(e=oe(e));const{view:t,buffer:n,blockLen:r}=this,s=e.length;for(let o=0;o<s;){const i=Math.min(r-this.pos,s-o);if(i===r){const t=te(e);for(;r<=s-o;o+=r)this.process(t,o);continue}n.set(e.subarray(o,o+i),this.pos),this.pos+=i,o+=i,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){J(this),Q(e,this),this.finished=!0;const{buffer:t,view:n,blockLen:r,isLE:s}=this;let{pos:o}=this;t[o++]=128,ee(this.buffer.subarray(o)),this.padOffset>r-o&&(this.process(n,0),o=0);for(let e=o;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),o=BigInt(4294967295),i=Number(n>>s&o),a=Number(n&o),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,a,r)}(n,r-8,BigInt(8*this.length),s),this.process(n,0);const i=te(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++)i.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:o,pos:i}=this;return e.destroyed=o,e.finished=s,e.length=r,e.pos=i,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}const _t=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Xt=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]),Zt=new Uint32Array(64);class Kt extends Dt{constructor(e=32){super(64,e,8,!1),this.A=0|_t[0],this.B=0|_t[1],this.C=0|_t[2],this.D=0|_t[3],this.E=0|_t[4],this.F=0|_t[5],this.G=0|_t[6],this.H=0|_t[7]}get(){const{A:e,B:t,C:n,D:r,E:s,F:o,G:i,H:a}=this;return[e,t,n,r,s,o,i,a]}set(e,t,n,r,s,o,i,a){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|s,this.F=0|o,this.G=0|i,this.H=0|a}process(e,t){for(let n=0;n<16;n++,t+=4)Zt[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){const t=Zt[e-15],n=Zt[e-2],r=ne(t,7)^ne(t,18)^t>>>3,s=ne(n,17)^ne(n,19)^n>>>10;Zt[e]=s+Zt[e-7]+r+Zt[e-16]|0}let{A:n,B:r,C:s,D:o,E:i,F:a,G:c,H:u}=this;for(let e=0;e<64;e++){const t=u+(ne(i,6)^ne(i,11)^ne(i,25))+Vt(i,a,c)+Xt[e]+Zt[e]|0,l=(ne(n,2)^ne(n,13)^ne(n,22))+jt(n,r,s)|0;u=c,c=a,a=i,i=o+t|0,o=s,s=r,r=n,n=t+l|0}n=n+this.A|0,r=r+this.B|0,s=s+this.C|0,o=o+this.D|0,i=i+this.E|0,a=a+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,r,s,o,i,a,c,u)}roundClean(){ee(Zt)}destroy(){this.set(0,0,0,0,0,0,0,0),ee(this.buffer)}}const Wt=ae(()=>new Kt),Yt=Wt;function Jt(e){const{commitment:t,version:n=1}=e,r=e.to??("string"==typeof t?"hex":"bytes"),s=Yt(y(o=t,{strict:!1})?L(o):o);var o;return s.set([n],0),"bytes"===r?s:U(s)}const Qt=4096,en=131072,tn=761855;class nn extends E{constructor({maxSize:e,size:t}){super("Blob size is too large.",{metaMessages:[`Max: ${e} bytes`,`Given: ${t} bytes`],name:"BlobSizeTooLargeError"})}}class rn extends E{constructor(){super("Blob data must not be empty.",{name:"EmptyBlobError"})}}function sn(e){const{data:t,kzg:n,to:r}=e,s=e.blobs??function(e){const t="string"==typeof e.data?j(e.data):e.data,n=x(t);if(!n)throw new rn;if(n>tn)throw new nn({maxSize:tn,size:n});const r=[];let s=!0,o=0;for(;s;){const e=Ge(new Uint8Array(en));let n=0;for(;n<Qt;){const r=t.slice(o,o+31);if(e.pushByte(0),e.pushBytes(r),r.length<31){e.pushByte(128),s=!1;break}n++,o+=31}r.push(e)}return r.map(e=>U(e.bytes))}({data:t}),o=e.commitments??Lt({blobs:s,kzg:n,to:r}),i=e.proofs??Mt({blobs:s,commitments:o,kzg:n,to:r}),a=[];for(let e=0;e<s.length;e++)a.push({blob:s[e],commitment:o[e],proof:i[e]});return a}async function on(e){return $(await e.request({method:"eth_chainId"},{dedupe:!0}))}const an=["blobVersionedHashes","chainId","fees","gas","nonce","type"],cn=new Map;async function un(e,t){const{account:n=e.account,blobs:r,chain:s,gas:o,kzg:i,nonce:a,nonceManager:c,parameters:u=an,type:l}=t,d=n?He(n):n,h={...t,...d?{from:d?.address}:{}};let f,p;async function m(){return f||(f=await tt(e,Ut,"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 tt(e,on,"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 tt(e,qt,"getTransactionCount")({address:d.address,blockTag:"pending"});if((u.includes("blobVersionedHashes")||u.includes("sidecars"))&&r&&i){const e=Lt({blobs:r,kzg:i});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(Jt({commitment:e,to:r,version:n}));return s}({commitments:e,to:"hex"});h.blobVersionedHashes=t}if(u.includes("sidecars")){const t=sn({blobs:r,commitments:e,proofs:Mt({blobs:r,commitments:e,kzg:i}),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 We({transaction:e})}(h)}catch{let t=cn.get(e.uid);if(void 0===t){const n=await m();t="bigint"==typeof n?.baseFeePerGas,cn.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:o}=await Ht(e,{block:n,chain:s,request:h});if(void 0===t.maxPriorityFeePerGas&&t.maxFeePerGas&&t.maxFeePerGas<o)throw new St({maxPriorityFeePerGas:o});h.maxPriorityFeePerGas=o,h.maxFeePerGas=r}}else{if(void 0!==t.maxFeePerGas||void 0!==t.maxPriorityFeePerGas)throw new Nt;if(void 0===t.gasPrice){const t=await m(),{gasPrice:n}=await Ht(e,{block:t,chain:s,request:h,type:"legacy"});h.gasPrice=n}}return u.includes("gas")&&void 0===o&&(h.gas=await tt(e,ln,"estimateGas")({...h,account:d,prepare:"local"===d?.type?[]:["blobVersionedHashes"]})),vt(h),delete h.parameters,h}async function ln(e,t){const{account:n=e.account,prepare:r=!0}=t,s=n?He(n):void 0,o=Array.isArray(r)?r:"local"!==s?.type?["blobVersionedHashes"]:void 0;try{const{accessList:n,authorizationList:i,blobs:a,blobVersionedHashes:c,blockNumber:u,blockTag:l,data:d,gas:h,gasPrice:f,maxFeePerBlobGas:p,maxFeePerGas:m,maxPriorityFeePerGas:g,nonce:w,value:b,stateOverride:y,...x}=r?await un(e,{...t,parameters:o}):t,v=("bigint"==typeof u?R(u):void 0)||l,P=function(e){if(!e)return;const t={};for(const{address:n,...r}of e){if(!Fe(n,{strict:!1}))throw new A({address:n});if(t[n])throw new _e({address:n});t[n]=yt(r)}return t}(y),B=await(async()=>x.to?x.to:i&&i.length>0?await kt({authorization:i[0]}).catch(()=>{throw new E("`to` is required. Could not infer from `authorizationList`")}):void 0)();vt(t);const I=e.chain?.formatters?.transactionRequest?.format,T=(I||wt)({...mt(x,{format:I}),account:s,accessList:n,authorizationList:i,blobs:a,blobVersionedHashes:c,data:d,gas:h,gasPrice:f,maxFeePerBlobGas:p,maxFeePerGas:m,maxPriorityFeePerGas:g,nonce:w,to:B,value:b},"estimateGas");return BigInt(await e.request({method:"eth_estimateGas",params:P?[T,v??e.experimental_blockTag??"latest",P]:v?[T,v]:[T]}))}catch(n){throw function(e,{docsPath:t,...n}){const r=(()=>{const t=pt(e,n);return t instanceof ft?e:t})();return new Ft(r,{docsPath:t,...n})}(n,{...t,account:s,chain:e.chain})}}async function dn(e,{address:t,blockNumber:n,blockTag:r=e.experimental_blockTag??"latest"}){const s="bigint"==typeof n?R(n):void 0,o=await e.request({method:"eth_getBalance",params:[t,s||r]});return BigInt(o)}const hn=new Map,fn=new Map;async function pn(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,hn),r=t(e,fn);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 o=r.promise.get();o||(o=e(),r.promise.set(o));try{const e=await o;return r.response.set({created:new Date,data:e}),e}finally{r.promise.clear()}}async function mn(e,{cacheTime:t=e.cacheTime}={}){const n=await pn(()=>e.request({method:"eth_blockNumber"}),{cacheKey:(r=e.uid,`blockNumber.${r}`),cacheTime:t});var r;return BigInt(n)}async function gn(e){return new Promise(t=>setTimeout(t,e))}function wn(e,{delay:t=100,retryCount:n=2,shouldRetry:r=()=>!0}={}){return new Promise((s,o)=>{const i=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 gn(n),i({count:a+1})})({error:e});o(e)}};i()})}function bn({chain:e,currentChainId:t}){if(!e)throw new Re;if(t!==e.id)throw new Ue({chain:e,currentChainId:t})}const yn={"0x0":"reverted","0x1":"success"};function xn(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?$(e.transactionIndex):null,status:e.status?yn[e.status]:null,type:e.type?$t[e.type]||e.type:null};return e.blobGasPrice&&(n.blobGasPrice=BigInt(e.blobGasPrice)),e.blobGasUsed&&(n.blobGasUsed=BigInt(e.blobGasUsed)),n}async function vn(e,{blockHash:t,blockNumber:n,blockTag:r,hash:s,index:o}){const i=r||"latest",a=void 0!==n?R(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,R(o)]},{dedupe:!0}):await e.request({method:"eth_getTransactionByBlockNumberAndIndex",params:[a||i,R(o)]},{dedupe:Boolean(a)}),!c)throw new Je({blockHash:t,blockNumber:n,blockTag:i,hash:s,index:o});return(e.chain?.formatters?.transaction?.format||zt)(c,"getTransaction")}async function Pn(e,{hash:t}){const n=await e.request({method:"eth_getTransactionReceipt",params:[t]},{dedupe:!0});if(!n)throw new Qe({hash:t});return(e.chain?.formatters?.transactionReceipt?.format||xn)(n,"getTransactionReceipt")}class Bn extends ie{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");W(e.outputLen),W(e.blockLen)}(e);const n=oe(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),ee(s)}update(e){return J(this),this.iHash.update(e),this}digestInto(e){J(this),Y(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:o,outputLen:i}=this;return e.finished=r,e.destroyed=s,e.blockLen=o,e.outputLen=i,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 En=(e,t,n)=>new Bn(e,t).update(n).digest();En.create=(e,t)=>new Bn(e,t);
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
const In=BigInt(0),An=BigInt(1);function Tn(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function kn(e){if(!Tn(e))throw new Error("Uint8Array expected")}function Fn(e,t){if("boolean"!=typeof t)throw new Error(e+" boolean expected, got "+t)}function Cn(e){const t=e.toString(16);return 1&t.length?"0"+t:t}function Nn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);return""===e?In:BigInt("0x"+e)}const Sn="function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex,On=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function $n(e){if(kn(e),Sn)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=On[e[n]];return t}const zn=48,Gn=57,Un=65,Rn=70,Hn=97,qn=102;function Ln(e){return e>=zn&&e<=Gn?e-zn:e>=Un&&e<=Rn?e-(Un-10):e>=Hn&&e<=qn?e-(Hn-10):void 0}function Mn(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(Sn)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=Ln(e.charCodeAt(s)),o=Ln(e.charCodeAt(s+1));if(void 0===n||void 0===o){const t=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+t+'