@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
3 lines • 265 kB
JavaScript
"use strict";var e=require("viem"),t=require("@avalabs/avalanchejs");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"));function o(t){const{key:n="avalancheBase",name:r="Avalanche Base Client"}=t,o=e.createClient({...t,key:n,name:r,type:"avalancheClient"});return Object.assign(o,{extend:function e(t){return n=>{const r=n(t);for(const e in o)delete r[e];const a={...t,...r};return Object.assign(a,{extend:e(a)})}}(o)})}const a={"User-Agent":`${"@avalanche-sdk/client"} ${"0.0.4-alpha.16"}`,"Content-Type":"application/json"};function i(t,n,{apiKey:r,rlToken:o}={},i="public"){switch(t.type){case"http":return e.http(s(n,t.url,i,"http"),{...t.config,fetchOptions:{...t.config?.fetchOptions??{},...r?{headers:{"x-glacier-api-key":r,...a}}:o?{headers:{rlToken:o,...a}}:{}}});case"ws":return e.webSocket(s(n,t.url,i,"webSocket"),t.config);case"custom":return"wallet"!==i?e.http(s(n,void 0,i,"http"),{...t.config,fetchOptions:{...r?{headers:{"x-glacier-api-key":r,...a}}:o?{headers:{rlToken:o,...a}}:{headers:a}}}):e.custom(t.provider,t.config);case"ipc":throw new Error("IPC transport is not available in browser environments. Use HTTP or WebSocket transport instead.");case"fallback":return e.fallback(t.transports,t.config);default:throw new Error("Invalid transport type")}}function s(e,t,n="public",r="http"){if("Avalanche Fuji"!==e?.name&&"Avalanche"!==e?.name)return t??e?.rpcUrls.default[r]?.[0];if(!t&&!e?.rpcUrls?.default?.[r]?.[0])throw new Error("URL is required");t=t??e.rpcUrls.default[r]?.[0];const o=new URL(t).origin;switch(n){case"public":case"wallet":return t;case"pChain":return`${o}/ext/bc/P`;case"xChain":return`${o}/ext/bc/X`;case"cChain":return`${o}/ext/bc/C/avax`;case"admin":return`${o}/ext/admin`;case"info":return`${o}/ext/info`;case"health":return`${o}/ext/health`;case"indexPChainBlock":return`${o}/ext/index/P/block`;case"indexCChainBlock":return`${o}/ext/index/C/block`;case"indexXChainBlock":return`${o}/ext/index/X/block`;case"indexXChainTx":return`${o}/ext/index/X/tx`;default:throw new Error("Invalid client type"+n)}}function f(e){const{key:t="avalancheCore",name:n="Avalanche Core Client",transport:r,chain:a,apiKey:s,rlToken:f,clientType:c="public"}=e,u=i(r,a,{apiKey:s,rlToken:f},c);return o({...e,key:t,name:n,transport:u})}function c(e){return{alias:t=>async function(e,t){return e.request({method:"admin.alias",params:t})}(e,t),aliasChain:t=>async function(e,t){return e.request({method:"admin.aliasChain",params:t})}(e,t),getChainAliases:t=>async function(e,t){return e.request({method:"admin.getChainAliases",params:t})}(e,t),getLoggerLevel:t=>async function(e,t){return e.request({method:"admin.getLoggerLevel",params:t})}(e,t),loadVMs:()=>async function(e){return e.request({method:"admin.loadVMs",params:{}})}(e),lockProfile:()=>async function(e){return e.request({method:"admin.lockProfile",params:{}})}(e),memoryProfile:()=>async function(e){return e.request({method:"admin.memoryProfile",params:{}})}(e),setLoggerLevel:t=>async function(e,t){return e.request({method:"admin.setLoggerLevel",params:t})}(e,t),startCPUProfiler:()=>async function(e){return e.request({method:"admin.startCPUProfiler",params:{}})}(e),stopCPUProfiler:()=>async function(e){return e.request({method:"admin.stopCPUProfiler",params:{}})}(e)}}function u(e){const{key:t="admin",name:n="Admin API Client"}=e;return f({...e,key:t,name:n,clientType:"admin"}).extend(c)}async function d(e,t){return e.request({method:"avax.getAtomicTxStatus",params:t})}async function l(e,t){return e.request({method:"avax.getUTXOs",params:t})}async function b(e,t){return e.request({method:"avax.issueTx",params:t})}function p(e){return{getAtomicTx:t=>async function(e,t){return e.request({method:"avax.getAtomicTx",params:t})}(e,t),getAtomicTxStatus:t=>d(e,t),getUTXOs:t=>l(e,t),issueTx:t=>b(e,t)}}function m(e){const{key:t="cChain",name:n="C-Chain Client"}=e;return f({...e,key:t,name:n,clientType:"cChain"}).extend(p)}function h(e){return{health:t=>async function(e,t){return e.request({method:"health.health",params:t})}(e,t),liveness:()=>async function(e){return e.request({method:"health.liveness",params:{}})}(e),readiness:t=>async function(e,t){return e.request({method:"health.readiness",params:t})}(e,t)}}function g(e){const{key:t="health",name:n="Health API Client"}=e;return f({...e,key:t,name:n,clientType:"health"}).extend(h)}function y(e){return{getContainerByID:t=>async function(e,t){return e.request({method:"index.getContainerByID",params:t})}(e,t),getContainerByIndex:t=>async function(e,t){return e.request({method:"index.getContainerByIndex",params:t})}(e,t),getContainerRange:t=>async function(e,t){return e.request({method:"index.getContainerRange",params:t})}(e,t),getIndex:t=>async function(e,t){return e.request({method:"index.getIndex",params:t})}(e,t),getLastAccepted:t=>async function(e,t){return e.request({method:"index.getLastAccepted",params:t})}(e,t),isAccepted:t=>async function(e,t){return e.request({method:"index.isAccepted",params:t})}(e,t)}}function x(e){const{key:t="index",name:n="Index API Client",clientType:r}=e;return f({...e,key:t,name:n,clientType:r}).extend(y)}async function w(e,t){return e.request({method:"info.getBlockchainID",params:t})}async function P(e){return e.request({method:"info.getNetworkID",params:{}})}function v(e){return{acps:()=>async function(e){const t=await e.request({method:"info.acps",params:{}});return Object.keys(t.acps).reduce((e,n)=>{const r=parseInt(n);return e.acps.set(r,{supportWeight:BigInt(t.acps?.[r]?.supportWeight||0n),supporters:new Set(t.acps?.[r]?.supporters||[]),objectWeight:BigInt(t.acps?.[r]?.objectWeight||0n),objectors:new Set(t.acps?.[r]?.objectors||[]),abstainWeight:BigInt(t.acps?.[r]?.abstainWeight||0n)}),e},{acps:new Map})}(e),getBlockchainID:t=>w(e,t),getNetworkID:()=>P(e),getNetworkName:()=>async function(e){return e.request({method:"info.getNetworkName",params:{}})}(e),getNodeID:()=>async function(e){return e.request({method:"info.getNodeID",params:{}})}(e),getNodeIP:()=>async function(e){return e.request({method:"info.getNodeIP",params:{}})}(e),getNodeVersion:()=>async function(e){return e.request({method:"info.getNodeVersion",params:{}})}(e),getTxFee:()=>async function(e){const t=await e.request({method:"info.getTxFee",params:{}});return{txFee:BigInt(t.txFee),createAssetTxFee:BigInt(t.createAssetTxFee),createSubnetTxFee:BigInt(t.createSubnetTxFee),transformSubnetTxFee:BigInt(t.transformSubnetTxFee),createBlockchainTxFee:BigInt(t.createBlockchainTxFee),addPrimaryNetworkValidatorFee:BigInt(t.addPrimaryNetworkValidatorFee),addPrimaryNetworkDelegatorFee:BigInt(t.addPrimaryNetworkDelegatorFee),addSubnetValidatorFee:BigInt(t.addSubnetValidatorFee),addSubnetDelegatorFee:BigInt(t.addSubnetDelegatorFee)}}(e),getVMs:()=>async function(e){return e.request({method:"info.getVMs",params:{}})}(e),isBootstrapped:t=>async function(e,t){return e.request({method:"info.isBootstrapped",params:t})}(e,t),peers:t=>async function(e,t){return e.request({method:"info.peers",params:t})}(e,t),upgrades:()=>async function(e){return e.request({method:"info.upgrades",params:{}})}(e),uptime:()=>async function(e){return e.request({method:"info.uptime",params:{}})}(e)}}function I(e){const{key:t="info",name:n="Info API Client"}=e;return f({...e,key:t,name:n,clientType:"info"}).extend(v)}async function E(e,t){const n=await e.request({method:"platform.getBalance",params:t});return{...n,balance:BigInt(n.balance),unlocked:BigInt(n.unlocked),lockedNotStakeable:BigInt(n.lockedNotStakeable),lockedStakeable:BigInt(n.lockedStakeable)}}async function O(e){const t=await e.request({method:"platform.getFeeConfig",params:{}});return{...t,maxCapacity:BigInt(t.maxCapacity),maxPerSecond:BigInt(t.maxPerSecond),minPrice:BigInt(t.minPrice),targetPerSecond:BigInt(t.targetPerSecond),excessConversionConstant:BigInt(t.excessConversionConstant)}}async function T(e){const t=await e.request({method:"platform.getFeeState",params:{}});return{...t,capacity:BigInt(t.capacity),excess:BigInt(t.excess),price:BigInt(t.price)}}async function A(e,t){const n=await e.request({method:"platform.getL1Validator",params:t});return{...n,startTime:BigInt(n.startTime),weight:BigInt(n.weight),...n.minNonce&&{minNonce:BigInt(n.minNonce)},...n.balance&&{balance:BigInt(n.balance)},...n.height&&{height:BigInt(n.height)}}}async function j(e,t){return e.request({method:"platform.getTx",params:t})}async function B(e,t){return e.request({method:"platform.getTxStatus",params:t})}async function C(e,t){return e.request({method:"platform.getUTXOs",params:t})}async function k(e,t){return e.request({method:"platform.issueTx",params:t})}function S(e){return{getBalance:t=>E(e,t),getBlock:t=>async function(e,t){return e.request({method:"platform.getBlock",params:t})}(e,t),getBlockByHeight:t=>async function(e,t){return e.request({method:"platform.getBlockByHeight",params:t})}(e,t),getBlockchains:()=>async function(e){return e.request({method:"platform.getBlockchains",params:{}})}(e),getBlockchainStatus:t=>async function(e,t){return e.request({method:"platform.getBlockchainStatus",params:t})}(e,t),getCurrentValidators:t=>async function(e,t){return e.request({method:"platform.getCurrentValidators",params:t})}(e,t),getCurrentSupply:t=>async function(e,t){const n=await e.request({method:"platform.getCurrentSupply",params:t});return{supply:BigInt(n.supply)}}(e,t),getFeeConfig:()=>O(e),getFeeState:()=>T(e),getHeight:()=>async function(e){return e.request({method:"platform.getHeight",params:{}})}(e),getL1Validator:t=>A(e,t),getProposedHeight:()=>async function(e){return e.request({method:"platform.getProposedHeight",params:{}})}(e),getMinStake:t=>async function(e,t){const n=await e.request({method:"platform.getMinStake",params:t});return{minDelegatorStake:BigInt(n.minDelegatorStake),minValidatorStake:BigInt(n.minValidatorStake)}}(e,t),getRewardUTXOs:t=>async function(e,t){return e.request({method:"platform.getRewardUTXOs",params:t})}(e,t),getStake:t=>async function(e,t){return e.request({method:"platform.getStake",params:t})}(e,t),getStakingAssetID:t=>async function(e,t){return e.request({method:"platform.getStakingAssetID",params:t})}(e,t),getSubnet:t=>async function(e,t){return e.request({method:"platform.getSubnet",params:t})}(e,t),getSubnets:t=>async function(e,t){return e.request({method:"platform.getSubnets",params:t})}(e,t),getTimestamp:()=>async function(e){return e.request({method:"platform.getTimestamp",params:{}})}(e),getTotalStake:t=>async function(e,t){return e.request({method:"platform.getTotalStake",params:t})}(e,t),getTx:t=>j(e,t),getTxStatus:t=>B(e,t),getUTXOs:t=>C(e,t),getValidatorsAt:t=>async function(e,t){return e.request({method:"platform.getValidatorsAt",params:t})}(e,t),issueTx:t=>k(e,t),sampleValidators:t=>async function(e,t){return e.request({method:"platform.sampleValidators",params:t})}(e,t),validates:t=>async function(e,t){return e.request({method:"platform.validates",params:t})}(e,t),validatedBy:t=>async function(e,t){return e.request({method:"platform.validatedBy",params:t})}(e,t)}}function $(e){const{key:t="pChain",name:n="P-Chain Client"}=e;return f({...e,key:t,name:n,clientType:"pChain"}).extend(S)}async function F(e,t){return e.request({method:"avm.getAssetDescription",params:t})}async function N(e){return e.request({method:"avm.getTxFee",params:{}})}async function R(e,t){return e.request({method:"avm.getTxStatus",params:t})}async function z(e,t){return e.request({method:"avm.getUTXOs",params:t})}async function U(e,t){return e.request({method:"avm.issueTx",params:t})}function M(e){return{buildGenesis:t=>async function(e,t){return e.request({method:"avm.buildGenesis",params:t})}(e,t),getAllBalances:t=>async function(e,t){return{balances:(await e.request({method:"avm.getAllBalances",params:t})).balances.map(e=>({...e,balance:BigInt(e.balance)}))}}(e,t),getAssetDescription:t=>F(e,t),getBalance:t=>async function(e,t){const n=await e.request({method:"avm.getBalance",params:t});return{...n,balance:BigInt(n.balance)}}(e,t),getBlock:t=>async function(e,t){return e.request({method:"avm.getBlock",params:t})}(e,t),getBlockByHeight:t=>async function(e,t){return e.request({method:"avm.getBlockByHeight",params:t})}(e,t),getHeight:()=>async function(e){return e.request({method:"avm.getHeight",params:{}})}(e),getTx:t=>async function(e,t){return e.request({method:"avm.getTx",params:t})}(e,t),getTxFee:()=>N(e),getTxStatus:t=>R(e,t),getUTXOs:t=>z(e,t),issueTx:t=>U(e,t)}}function q(e){const{key:t="xChain",name:n="X-Chain Client"}=e;return f({...e,key:t,name:n,clientType:"xChain"}).extend(M)}async function L(e){return e.request({method:"eth_baseFee",params:[]})}function D(e){return{baseFee:()=>L(e),getChainConfig:()=>async function(e){return e.request({method:"eth_getChainConfig",params:[]})}(e),maxPriorityFeePerGas:()=>async function(e){return e.request({method:"eth_maxPriorityFeePerGas",params:[]})}(e),feeConfig:t=>async function(e,{blk:t}){return e.request({method:"eth_feeConfig",params:[t??"latest"]})}(e,t),getActiveRulesAt:t=>async function(e,{timestamp:t}){return e.request({method:"eth_getActiveRulesAt",params:[t??"latest"]})}(e,t)}}let H=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,o=n.cause instanceof e&&n.cause.docsPath||n.docsPath;super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...o?[`Docs: https://abitype.dev${o}`]:[],...r?[`Details: ${r}`]:[],"Version: abitype@1.1.0"].join("\n")),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,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiTypeError"}),n.cause&&(this.cause=n.cause),this.details=r,this.docsPath=o,this.metaMessages=n.metaMessages,this.shortMessage=t}};function G(e,t){const n=e.exec(t);return n?.groups}const V=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,_=/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/,W=/^\(.+?\).*?$/,X=/^tuple(?<array>(\[(\d*)\])*)$/;function K(e){let t=e.type;if(X.test(e.type)&&"components"in e){t="(";const n=e.components.length;for(let r=0;r<n;r++){t+=K(e.components[r]),r<n-1&&(t+=", ")}const r=G(X,e.type);return t+=`)${r?.array??""}`,K({...e,type:t})}return"indexed"in e&&e.indexed&&(t=`${t} indexed`),e.name?`${t} ${e.name}`:t}function Z(e){let t="";const n=e.length;for(let r=0;r<n;r++){t+=K(e[r]),r!==n-1&&(t+=", ")}return t}const Y=/^error (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const J=/^event (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)$/;const Q=/^function (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*)\((?<parameters>.*?)\)(?: (?<scope>external|public{1}))?(?: (?<stateMutability>pure|view|nonpayable|payable{1}))?(?: returns\s?\((?<returns>.*?)\))?$/;const ee=/^struct (?<name>[a-zA-Z$_][a-zA-Z0-9$_]*) \{(?<properties>.*?)\}$/;function te(e){return ee.test(e)}function ne(e){return G(ee,e)}const re=/^constructor\((?<parameters>.*?)\)(?:\s(?<stateMutability>payable{1}))?$/;const oe=/^fallback\(\) external(?:\s(?<stateMutability>payable{1}))?$/;const ae=/^receive\(\) external payable$/;const ie=new Set(["indexed"]),se=new Set(["calldata","memory","storage"]);class fe extends H{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type. Perhaps you forgot to include a struct signature?`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownTypeError"})}}class ce extends H{constructor({type:e}){super("Unknown type.",{metaMessages:[`Type "${e}" is not a valid ABI type.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSolidityTypeError"})}}class ue extends H{constructor({param:e}){super("Invalid ABI parameter.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParameterError"})}}class de extends H{constructor({param:e,name:t}){super("Invalid ABI parameter.",{details:e,metaMessages:[`"${t}" is a protected Solidity keyword. More info: https://docs.soliditylang.org/en/latest/cheatsheet.html`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"SolidityProtectedKeywordError"})}}class le extends H{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidModifierError"})}}class be extends H{constructor({param:e,type:t,modifier:n}){super("Invalid ABI parameter.",{details:e,metaMessages:[`Modifier "${n}" not allowed${t?` in "${t}" type`:""}.`,`Data location can only be specified for array, struct, or mapping types, but "${n}" was given.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidFunctionModifierError"})}}class pe extends H{constructor({abiParameter:e}){super("Invalid ABI parameter.",{details:JSON.stringify(e,null,2),metaMessages:["ABI parameter type is invalid."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidAbiTypeParameterError"})}}class me extends H{constructor({signature:e,type:t}){super(`Invalid ${t} signature.`,{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidSignatureError"})}}class he extends H{constructor({signature:e}){super("Unknown signature.",{details:e}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"UnknownSignatureError"})}}class ge extends H{constructor({signature:e}){super("Invalid struct signature.",{details:e,metaMessages:["No properties exist."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidStructSignatureError"})}}class ye extends H{constructor({type:e}){super("Circular reference detected.",{metaMessages:[`Struct "${e}" is a circular reference.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"CircularReferenceError"})}}class xe extends H{constructor({current:e,depth:t}){super("Unbalanced parentheses.",{metaMessages:[`"${e.trim()}" has too many ${t>0?"opening":"closing"} parentheses.`],details:`Depth "${t}"`}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"InvalidParenthesisError"})}}const we=new Map([["address",{type:"address"}],["bool",{type:"bool"}],["bytes",{type:"bytes"}],["bytes32",{type:"bytes32"}],["int",{type:"int256"}],["int256",{type:"int256"}],["string",{type:"string"}],["uint",{type:"uint256"}],["uint8",{type:"uint8"}],["uint16",{type:"uint16"}],["uint24",{type:"uint24"}],["uint32",{type:"uint32"}],["uint64",{type:"uint64"}],["uint96",{type:"uint96"}],["uint112",{type:"uint112"}],["uint160",{type:"uint160"}],["uint192",{type:"uint192"}],["uint256",{type:"uint256"}],["address owner",{type:"address",name:"owner"}],["address to",{type:"address",name:"to"}],["bool approved",{type:"bool",name:"approved"}],["bytes _data",{type:"bytes",name:"_data"}],["bytes data",{type:"bytes",name:"data"}],["bytes signature",{type:"bytes",name:"signature"}],["bytes32 hash",{type:"bytes32",name:"hash"}],["bytes32 r",{type:"bytes32",name:"r"}],["bytes32 root",{type:"bytes32",name:"root"}],["bytes32 s",{type:"bytes32",name:"s"}],["string name",{type:"string",name:"name"}],["string symbol",{type:"string",name:"symbol"}],["string tokenURI",{type:"string",name:"tokenURI"}],["uint tokenId",{type:"uint256",name:"tokenId"}],["uint8 v",{type:"uint8",name:"v"}],["uint256 balance",{type:"uint256",name:"balance"}],["uint256 tokenId",{type:"uint256",name:"tokenId"}],["uint256 value",{type:"uint256",name:"value"}],["event:address indexed from",{type:"address",name:"from",indexed:!0}],["event:address indexed to",{type:"address",name:"to",indexed:!0}],["event:uint indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}],["event:uint256 indexed tokenId",{type:"uint256",name:"tokenId",indexed:!0}]]);function Pe(e,t={}){if(function(e){return Q.test(e)}(e))return function(e,t={}){const n=function(e){return G(Q,e)}(e);if(!n)throw new me({signature:e,type:"function"});const r=Te(n.parameters),o=[],a=r.length;for(let e=0;e<a;e++)o.push(Oe(r[e],{modifiers:se,structs:t,type:"function"}));const i=[];if(n.returns){const e=Te(n.returns),r=e.length;for(let n=0;n<r;n++)i.push(Oe(e[n],{modifiers:se,structs:t,type:"function"}))}return{name:n.name,type:"function",stateMutability:n.stateMutability??"nonpayable",inputs:o,outputs:i}}(e,t);if(function(e){return J.test(e)}(e))return function(e,t={}){const n=function(e){return G(J,e)}(e);if(!n)throw new me({signature:e,type:"event"});const r=Te(n.parameters),o=[],a=r.length;for(let e=0;e<a;e++)o.push(Oe(r[e],{modifiers:ie,structs:t,type:"event"}));return{name:n.name,type:"event",inputs:o}}(e,t);if(function(e){return Y.test(e)}(e))return function(e,t={}){const n=function(e){return G(Y,e)}(e);if(!n)throw new me({signature:e,type:"error"});const r=Te(n.parameters),o=[],a=r.length;for(let e=0;e<a;e++)o.push(Oe(r[e],{structs:t,type:"error"}));return{name:n.name,type:"error",inputs:o}}(e,t);if(function(e){return re.test(e)}(e))return function(e,t={}){const n=function(e){return G(re,e)}(e);if(!n)throw new me({signature:e,type:"constructor"});const r=Te(n.parameters),o=[],a=r.length;for(let e=0;e<a;e++)o.push(Oe(r[e],{structs:t,type:"constructor"}));return{type:"constructor",stateMutability:n.stateMutability??"nonpayable",inputs:o}}(e,t);if(function(e){return oe.test(e)}(e))return function(e){const t=function(e){return G(oe,e)}(e);if(!t)throw new me({signature:e,type:"fallback"});return{type:"fallback",stateMutability:t.stateMutability??"nonpayable"}}(e);if(function(e){return ae.test(e)}(e))return{type:"receive",stateMutability:"payable"};throw new he({signature:e})}const ve=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*(?:\spayable)?)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Ie=/^\((?<type>.+?)\)(?<array>(?:\[\d*?\])+?)?(?:\s(?<modifier>calldata|indexed|memory|storage{1}))?(?:\s(?<name>[a-zA-Z$_][a-zA-Z0-9$_]*))?$/,Ee=/^u?int$/;function Oe(e,t){const n=function(e,t,n){let r="";if(n)for(const e of Object.entries(n)){if(!e)continue;let t="";for(const n of e[1])t+=`[${n.type}${n.name?`:${n.name}`:""}]`;r+=`(${e[0]}{${t}})`}return t?`${t}:${e}${r}`:e}(e,t?.type,t?.structs);if(we.has(n))return we.get(n);const r=W.test(e),o=G(r?Ie:ve,e);if(!o)throw new ue({param:e});if(o.name&&function(e){return"address"===e||"bool"===e||"function"===e||"string"===e||"tuple"===e||V.test(e)||_.test(e)||je.test(e)}(o.name))throw new de({param:e,name:o.name});const a=o.name?{name:o.name}:{},i="indexed"===o.modifier?{indexed:!0}:{},s=t?.structs??{};let f,c={};if(r){f="tuple";const e=Te(o.type),t=[],n=e.length;for(let r=0;r<n;r++)t.push(Oe(e[r],{structs:s}));c={components:t}}else if(o.type in s)f="tuple",c={components:s[o.type]};else if(Ee.test(o.type))f=`${o.type}256`;else if("address payable"===o.type)f="address";else if(f=o.type,"struct"!==t?.type&&!Ae(f))throw new ce({type:f});if(o.modifier){if(!t?.modifiers?.has?.(o.modifier))throw new le({param:e,type:t?.type,modifier:o.modifier});if(se.has(o.modifier)&&!function(e,t){return t||"bytes"===e||"string"===e||"tuple"===e}(f,!!o.array))throw new be({param:e,type:t?.type,modifier:o.modifier})}const u={type:`${f}${o.array??""}`,...a,...i,...c};return we.set(n,u),u}function Te(e,t=[],n="",r=0){const o=e.trim().length;for(let a=0;a<o;a++){const o=e[a],i=e.slice(a+1);switch(o){case",":return 0===r?Te(i,[...t,n.trim()]):Te(i,t,`${n}${o}`,r);case"(":return Te(i,t,`${n}${o}`,r+1);case")":return Te(i,t,`${n}${o}`,r-1);default:return Te(i,t,`${n}${o}`,r)}}if(""===n)return t;if(0!==r)throw new xe({current:n,depth:r});return t.push(n.trim()),t}function Ae(e){return"address"===e||"bool"===e||"function"===e||"string"===e||V.test(e)||_.test(e)}const je=/^(?:after|alias|anonymous|apply|auto|byte|calldata|case|catch|constant|copyof|default|defined|error|event|external|false|final|function|immutable|implements|in|indexed|inline|internal|let|mapping|match|memory|mutable|null|of|override|partial|private|promise|public|pure|reference|relocatable|return|returns|sizeof|static|storage|struct|super|supports|switch|this|true|try|typedef|typeof|var|view|virtual)$/;const Be=/^(?<type>[a-zA-Z$_][a-zA-Z0-9$_]*)(?<array>(?:\[\d*?\])+?)?$/;function Ce(e,t,n=new Set){const r=[],o=e.length;for(let a=0;a<o;a++){const o=e[a];if(W.test(o.type))r.push(o);else{const e=G(Be,o.type);if(!e?.type)throw new pe({abiParameter:o});const{array:a,type:i}=e;if(i in t){if(n.has(i))throw new ye({type:i});r.push({...o,type:`tuple${a??""}`,components:Ce(t[i]??[],t,new Set([...n,i]))})}else{if(!Ae(i))throw new fe({type:i});r.push(o)}}}return r}function ke(e){const t=function(e){const t={},n=e.length;for(let r=0;r<n;r++){const n=e[r];if(!te(n))continue;const o=ne(n);if(!o)throw new me({signature:n,type:"struct"});const a=o.properties.split(";"),i=[],s=a.length;for(let e=0;e<s;e++){const t=a[e].trim();if(!t)continue;const n=Oe(t,{type:"struct"});i.push(n)}if(!i.length)throw new ge({signature:n});t[o.name]=i}const r={},o=Object.entries(t),a=o.length;for(let e=0;e<a;e++){const[n,a]=o[e];r[n]=Ce(a,t)}return r}(e),n=[],r=e.length;for(let o=0;o<r;o++){const r=e[o];te(r)||n.push(Pe(r,t))}return n}function Se(e){return"string"==typeof e?{address:e,type:"json-rpc"}:e}const $e="2.38.2";let Fe=({docsBaseUrl:e,docsPath:t="",docsSlug:n})=>t?`${e??"https://viem.sh"}${t}${n?`#${n}`:""}`:void 0,Ne=`viem@${$e}`,Re=class e extends Error{constructor(t,n={}){const r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,o=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=Fe?.({...n,docsPath:o});super([t||"An error occurred.","",...n.metaMessages?[...n.metaMessages,""]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...Ne?[`Version: ${Ne}`]:[]].join("\n"),n.cause?{cause:n.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=r,this.docsPath=o,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=$e}walk(e){return ze(this,e)}};function ze(e,t){return t?.(e)?e:e&&"object"==typeof e&&"cause"in e&&void 0!==e.cause?ze(e.cause,t):t?null:e}class Ue extends Re{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"})}}function Me(e,{strict:t=!0}={}){return!!e&&("string"==typeof e&&(t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith("0x")))}class qe extends Re{constructor({offset:e,position:t,size:n}){super(`Slice ${"start"===t?"starting":"ending"} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:"SliceOffsetOutOfBoundsError"})}}let Le=class extends Re{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 De extends Re{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 He(e,{dir:t,size:n=32}={}){return"string"==typeof e?Ge(e,{dir:t,size:n}):function(e,{dir:t,size:n=32}={}){if(null===n)return e;if(e.length>n)throw new Le({size:e.length,targetSize:n,type:"bytes"});const r=new Uint8Array(n);for(let o=0;o<n;o++){const a="right"===t;r[a?o:n-o-1]=e[a?o:e.length-o-1]}return r}(e,{dir:t,size:n})}function Ge(e,{dir:t,size:n=32}={}){if(null===n)return e;const r=e.replace("0x","");if(r.length>2*n)throw new Le({size:Math.ceil(r.length/2),targetSize:n,type:"hex"});return`0x${r["right"===t?"padEnd":"padStart"](2*n,"0")}`}let Ve=class extends Re{constructor({max:e,min:t,signed:n,size:r,value:o}){super(`Number "${o}" is not in safe ${r?`${8*r}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:"IntegerOutOfRangeError"})}};class _e extends Re{constructor(e){super(`Bytes value "${e}" is not a valid boolean. The bytes array must contain a single byte of either a 0 or 1 value.`,{name:"InvalidBytesBooleanError"})}}class We extends Re{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Xe(e){return Me(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}function Ke(e,{dir:t="left"}={}){let n="string"==typeof e?e.replace("0x",""):e,r=0;for(let e=0;e<n.length-1&&"0"===n["left"===t?e:n.length-e-1].toString();e++)r++;return n="left"===t?n.slice(r):n.slice(0,n.length-r),"string"==typeof e?(1===n.length&&"right"===t&&(n=`${n}0`),`0x${n.length%2==1?`0${n}`:n}`):n}function Ze(e,{size:t}){if(Xe(e)>t)throw new We({givenSize:Xe(e),maxSize:t})}function Ye(e,t={}){const{signed:n}=t;t.size&&Ze(e,{size:t.size});const r=BigInt(e);if(!n)return r;const o=(e.length-2)/2;return r<=(1n<<8n*BigInt(o)-1n)-1n?r:r-BigInt(`0x${"f".padStart(2*o,"f")}`)-1n}function Je(e,t={}){return Number(Ye(e,t))}const Qe=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function et(e,t={}){return"number"==typeof e||"bigint"==typeof e?rt(e,t):"string"==typeof e?at(e,t):"boolean"==typeof e?tt(e,t):nt(e,t)}function tt(e,t={}){const n=`0x${Number(e)}`;return"number"==typeof t.size?(Ze(n,{size:t.size}),He(n,{size:t.size})):n}function nt(e,t={}){let n="";for(let t=0;t<e.length;t++)n+=Qe[e[t]];const r=`0x${n}`;return"number"==typeof t.size?(Ze(r,{size:t.size}),He(r,{dir:"right",size:t.size})):r}function rt(e,t={}){const{signed:n,size:r}=t,o=BigInt(e);let a;r?a=n?(1n<<8n*BigInt(r)-1n)-1n:2n**(8n*BigInt(r))-1n:"number"==typeof e&&(a=BigInt(Number.MAX_SAFE_INTEGER));const i="bigint"==typeof a&&n?-a-1n:0;if(a&&o>a||o<i){const t="bigint"==typeof e?"n":"";throw new Ve({max:a?`${a}${t}`:void 0,min:`${i}${t}`,signed:n,size:r,value:`${e}${t}`})}const s=`0x${(n&&o<0?(1n<<BigInt(8*r))+BigInt(o):o).toString(16)}`;return r?He(s,{size:r}):s}const ot=new TextEncoder;function at(e,t={}){return nt(ot.encode(e),t)}const it=new TextEncoder;function st(e,t={}){return"number"==typeof e||"bigint"==typeof e?function(e,t){const n=rt(e,t);return ut(n)}(e,t):"boolean"==typeof e?function(e,t={}){const n=new Uint8Array(1);if(n[0]=Number(e),"number"==typeof t.size)return Ze(n,{size:t.size}),He(n,{size:t.size});return n}(e,t):Me(e)?ut(e,t):dt(e,t)}const ft={zero:48,nine:57,A:65,F:70,a:97,f:102};function ct(e){return e>=ft.zero&&e<=ft.nine?e-ft.zero:e>=ft.A&&e<=ft.F?e-(ft.A-10):e>=ft.a&&e<=ft.f?e-(ft.a-10):void 0}function ut(e,t={}){let n=e;t.size&&(Ze(n,{size:t.size}),n=He(n,{dir:"right",size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);const o=r.length/2,a=new Uint8Array(o);for(let e=0,t=0;e<o;e++){const n=ct(r.charCodeAt(t++)),o=ct(r.charCodeAt(t++));if(void 0===n||void 0===o)throw new Re(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=16*n+o}return a}function dt(e,t={}){const n=it.encode(e);return"number"==typeof t.size?(Ze(n,{size:t.size}),He(n,{dir:"right",size:t.size})):n}const lt=BigInt(2**32-1),bt=BigInt(32);function pt(e,t=!1){return t?{h:Number(e<),l:Number(e>>bt<)}:{h:0|Number(e>>bt<),l:0|Number(e<)}}const mt=r&&"object"==typeof r&&"webcrypto"in r?r.webcrypto:r&&"object"==typeof r&&"randomBytes"in r?r:void 0;function ht(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function gt(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 yt(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 xt(e,t){gt(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function wt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Pt(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}function It(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}const Et=(()=>68===new Uint8Array(new Uint32Array([287454020]).buffer)[0])()?e=>e:function(e){for(let t=0;t<e.length;t++)e[t]=It(e[t]);return e};function Ot(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)),gt(e),e}class Tt{}function At(e){const t=t=>e().update(Ot(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function jt(e=32){if(mt&&"function"==typeof mt.getRandomValues)return mt.getRandomValues(new Uint8Array(e));if(mt&&"function"==typeof mt.randomBytes)return Uint8Array.from(mt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}const Bt=BigInt(0),Ct=BigInt(1),kt=BigInt(2),St=BigInt(7),$t=BigInt(256),Ft=BigInt(113),Nt=[],Rt=[],zt=[];for(let e=0,t=Ct,n=1,r=0;e<24;e++){[n,r]=[r,(2*n+3*r)%5],Nt.push(2*(5*r+n)),Rt.push((e+1)*(e+2)/2%64);let o=Bt;for(let e=0;e<7;e++)t=(t<<Ct^(t>>St)*Ft)%$t,t&kt&&(o^=Ct<<(Ct<<BigInt(e))-Ct);zt.push(o)}const Ut=function(e,t=!1){const n=e.length;let r=new Uint32Array(n),o=new Uint32Array(n);for(let a=0;a<n;a++){const{h:n,l:i}=pt(e[a],t);[r[a],o[a]]=[n,i]}return[r,o]}(zt,!0),Mt=Ut[0],qt=Ut[1],Lt=(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),Dt=(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 Ht extends Tt{constructor(e,t,n,r=!1,o=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=o,ht(n),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");var a;this.state=new Uint8Array(200),this.state32=(a=this.state,new Uint32Array(a.buffer,a.byteOffset,Math.floor(a.byteLength/4)))}clone(){return this._cloneInto()}keccak(){Et(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,o=(t+2)%10,a=n[o],i=n[o+1],s=Lt(a,i,1)^n[r],f=Dt(a,i,1)^n[r+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=f}let t=e[2],o=e[3];for(let n=0;n<24;n++){const r=Rt[n],a=Lt(t,o,r),i=Dt(t,o,r),s=Nt[n];t=e[s],o=e[s+1],e[s]=a,e[s+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]^=Mt[r],e[1]^=qt[r]}wt(n)}(this.state32,this.rounds),Et(this.state32),this.posOut=0,this.pos=0}update(e){yt(this),gt(e=Ot(e));const{blockLen:t,state:n}=this,r=e.length;for(let o=0;o<r;){const a=Math.min(t-this.pos,r-o);for(let t=0;t<a;t++)n[this.pos++]^=e[o++];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){yt(this,!1),gt(e),this.finish();const t=this.state,{blockLen:n}=this;for(let r=0,o=e.length;r<o;){this.posOut>=n&&this.keccak();const a=Math.min(n-this.posOut,o-r);e.set(t.subarray(this.posOut,this.posOut+a),r),this.posOut+=a,r+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return ht(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(xt(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,wt(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:a}=this;return e||(e=new Ht(t,n,r,a,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=a,e.destroyed=this.destroyed,e}}const Gt=(()=>{return e=1,t=136,n=32,At(()=>new Ht(t,e,n));var e,t,n})();function Vt(e,t){const n=t||"hex",r=Gt(Me(e,{strict:!1})?st(e):e);return"bytes"===n?r:et(r)}class _t 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 Wt=/^0x[a-fA-F0-9]{40}$/,Xt=new _t(8192);function Kt(e,t){const{strict:n=!0}=t??{},r=`${e}.${n}`;if(Xt.has(r))return Xt.get(r);const o=!(!Wt.test(e)||e.toLowerCase()!==e&&n&&Yt(e)!==e);return Xt.set(r,o),o}const Zt=new _t(8192);function Yt(e,t){if(Zt.has(`${e}.${t}`))return Zt.get(`${e}.${t}`);const n=e.substring(2).toLowerCase(),r=Vt(dt(n),"bytes"),o=n.split("");for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&o[e]&&(o[e]=o[e].toUpperCase()),(15&r[e>>1])>=8&&o[e+1]&&(o[e+1]=o[e+1].toUpperCase());const a=`0x${o.join("")}`;return Zt.set(`${e}.${t}`,a),a}function Jt(e,{includeName:t=!1}={}){if("function"!==e.type&&"event"!==e.type&&"error"!==e.type)throw new yn(e.type);return`${e.name}(${Qt(e.inputs,{includeName:t})})`}function Qt(e,{includeName:t=!1}={}){return e?e.map(e=>function(e,{includeName:t}){if(e.type.startsWith("tuple"))return`(${Qt(e.components,{includeName:t})})${e.type.slice(5)}`;return e.type+(t&&e.name?` ${e.name}`:"")}(e,{includeName:t})).join(t?", ":","):""}class en extends Re{constructor({docsPath:e}){super(["A constructor was not found on the ABI.","Make sure you are using the correct ABI and that the constructor exists on it."].join("\n"),{docsPath:e,name:"AbiConstructorNotFoundError"})}}class tn extends Re{constructor({docsPath:e}){super(["Constructor arguments were provided (`args`), but a constructor parameters (`inputs`) were not found on the ABI.","Make sure you are using the correct ABI, and that the `inputs` attribute on the constructor exists."].join("\n"),{docsPath:e,name:"AbiConstructorParamsNotFoundError"})}}class nn extends Re{constructor({data:e,params:t,size:n}){super([`Data size of ${n} bytes is too small for given parameters.`].join("\n"),{metaMessages:[`Params: (${Qt(t,{includeName:!0})})`,`Data: ${e} (${n} bytes)`],name:"AbiDecodingDataSizeTooSmallError"}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"params",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"size",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.data=e,this.params=t,this.size=n}}class rn extends Re{constructor(){super('Cannot decode zero data ("0x") with ABI parameters.',{name:"AbiDecodingZeroDataError"})}}class on extends Re{constructor({expectedLength:e,givenLength:t,type:n}){super([`ABI encoding array length mismatch for type ${n}.`,`Expected length: ${e}`,`Given length: ${t}`].join("\n"),{name:"AbiEncodingArrayLengthMismatchError"})}}class an extends Re{constructor({expectedSize:e,value:t}){super(`Size of bytes "${t}" (bytes${Xe(t)}) does not match expected size (bytes${e}).`,{name:"AbiEncodingBytesSizeMismatchError"})}}class sn extends Re{constructor({expectedLength:e,givenLength:t}){super(["ABI encoding params/values length mismatch.",`Expected length (params): ${e}`,`Given length (values): ${t}`].join("\n"),{name:"AbiEncodingLengthMismatchError"})}}class fn extends Re{constructor(e,{docsPath:t}){super([`Arguments (\`args\`) were provided to "${e}", but "${e}" on the ABI does not contain any parameters (\`inputs\`).`,"Cannot encode error result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the inputs exist on it."].join("\n"),{docsPath:t,name:"AbiErrorInputsNotFoundError"})}}class cn extends Re{constructor(e,{docsPath:t}={}){super([`Error ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it."].join("\n"),{docsPath:t,name:"AbiErrorNotFoundError"})}}class un extends Re{constructor(e,{docsPath:t}){super([`Encoded error signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the error exists on it.",`You can look up the decoded signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiErrorSignatureNotFoundError"}),Object.defineProperty(this,"signature",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.signature=e}}class dn extends Re{constructor(e,{docsPath:t}={}){super([`Function ${e?`"${e}" `:""}not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionNotFoundError"})}}class ln extends Re{constructor(e,{docsPath:t}){super([`Function "${e}" does not contain any \`outputs\` on ABI.`,"Cannot decode function result without knowing what the parameter types are.","Make sure you are using the correct ABI and that the function exists on it."].join("\n"),{docsPath:t,name:"AbiFunctionOutputsNotFoundError"})}}class bn extends Re{constructor(e,{docsPath:t}){super([`Encoded function signature "${e}" not found on ABI.`,"Make sure you are using the correct ABI and that the function exists on it.",`You can look up the signature here: https://openchain.xyz/signatures?query=${e}.`].join("\n"),{docsPath:t,name:"AbiFunctionSignatureNotFoundError"})}}class pn extends Re{constructor(e,t){super("Found ambiguous types in overloaded ABI items.",{metaMessages:[`\`${e.type}\` in \`${Jt(e.abiItem)}\`, and`,`\`${t.type}\` in \`${Jt(t.abiItem)}\``,"","These types encode differently and cannot be distinguished at runtime.","Remove one of the ambiguous items in the ABI."],name:"AbiItemAmbiguityError"})}}class mn extends Re{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid encoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiEncodingType"})}}class hn extends Re{constructor(e,{docsPath:t}){super([`Type "${e}" is not a valid decoding type.`,"Please provide a valid ABI type."].join("\n"),{docsPath:t,name:"InvalidAbiDecodingType"})}}class gn extends Re{constructor(e){super([`Value "${e}" is not a valid array.`].join("\n"),{name:"InvalidArrayError"})}}class yn extends Re{constructor(e){super([`"${e}" is not a valid definition type.`,'Valid types: "function", "event", "error"'].join("\n"),{name:"InvalidDefinitionTypeError"})}}class xn extends Re{constructor({offset:e}){super(`Offset \`${e}\` cannot be negative.`,{name:"NegativeOffsetError"})}}class wn extends Re{constructor({length:e,position:t}){super(`Position \`${t}\` is out of bounds (\`0 < position < ${e}\`).`,{name:"PositionOutOfBoundsError"})}}class Pn extends Re{constructor({count:e,limit:t}){super(`Recursive read limit of \`${t}\` exceeded (recursive read count: \`${e}\`).`,{name:"RecursiveReadLimitExceededError"})}}const vn={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 Pn({count:this.recursiveReadCount+1,limit:this.recursiveReadLimit})},assertPosition(e){if(e<0||e>this.bytes.length-1)throw new wn({length:this.bytes.length,position:e})},decrementPosition(e){if(e<0)throw new xn({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 xn({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 In(e,{recursiveReadLimit:t=8192}={}){const n=Object.create(vn);return n.bytes=e,n.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength),n.positionReadCount=new Map,n.recursiveReadLimit=t,n}function En(e,t,n,{strict:r}={}){return Me(e,{strict:!1})?function(e,t,n,{strict:r}={}){On(e,t);const o=`0x${e.replace("0x","").slice(2*(t??0),2*(n??e.length))}`;r&&Tn(o,t,n);return o}(e,t,n,{strict:r}):An(e,t,n,{strict:r})}function On(e,t){if("number"==typeof t&&t>0&&t>Xe(e)-1)throw new qe({offset:t,position:"start",size:Xe(e)})}function Tn(e,t,n){if("number"==typeof t&&"number"==typeof n&&Xe(e)!==n-t)throw new qe({offset:n,position:"end",size:Xe(e)})}function An(e,t,n,{strict:r}={}){On(e,t);const o=e.slice(t,n);return r&&Tn(o,t,n),o}function jn(e,t={}){void 0!==t.size&&Ze(e,{size:t.size});return Ye(nt(e,t),t)}function Bn(e,t={}){let n=e;if(void 0!==t.size&&(Ze(n,{size:t.size}),n=Ke(n)),n.length>1||n[0]>1)throw new _e(n);return Boolean(n[0])}function Cn(e,t={}){void 0!==t.size&&Ze(e,{size:t.size});return Je(nt(e,t),t)}function kn(e){return"string"==typeof e[0]?Sn(e):function(e){let t=0;for(const n of e)t+=n.length;const n=new Uint8Array(t);let r=0;for(const t of e)n.set(t,r),r+=t.length;return n}(e)}function Sn(e){return`0x${e.reduce((e,t)=>e+t.replace("0x",""),"")}`}const $n=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Fn(e,t){if(e.length!==t.length)throw new sn({expectedLength:e.length,givenLength:t.length});const n=function({params:e,values:t}){const n=[];for(let r=0;r<e.length;r++)n.push(Nn({param:e[r],value:t[r]}));return n}({params:e,values:t}),r=Rn(n);return 0===r.length?"0x":r}function Nn({param:e,value:t}){const n=zn(e.type);if(n){const[r,o]=n;return function(e,{length:t,param:n}){const r=null===t;if(!Array.isArray(e))throw new gn(e);if(!r&&e.length!==t)throw new on({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let o=!1;const a=[];for(let t=0;t<e.length;t++){const r=Nn({param:n,value:e[t]});r.dynamic&&(o=!0),a.push(r)}if(r||o){const e=Rn(a);if(r){const t=rt(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?kn([t,e]):t}}if(o)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:kn(a.map(({encoded:e})=>e))}}(t,{length:r,param:{...e,type:o}})}if("tuple"===e.type)return function(e,{param:t}){let n=!1;const r=[];for(let o=0;o<t.components.length;o++){const a=t.components[o],i=Nn({param:a,value:e[Array.isArray(e)?o:a.name]});r.push(i),i.dynamic&&(n=!0)}return{dynamic:n,encoded:n?Rn(r):kn(r.map(({encoded:e})=>e))}}(t,{param:e});if("address"===e.type)return function(e){if(!Kt(e))throw new Ue({address:e});return{dynamic:!1,encoded:Ge(e.toLowerCase())}}(t);if("bool"===e.type)return function(e){if("boolean"!=typeof e)throw new Re(`Invalid boolean value: "${e}" (t