FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

105
node_modules/viem/_esm/actions/ens/getEnsAddress.js generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import { addressResolverAbi, universalResolverResolveAbi, } from '../../constants/abis.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { trim } from '../../utils/data/trim.js';
import { toHex } from '../../utils/encoding/toHex.js';
import { isNullUniversalResolverError } from '../../utils/ens/errors.js';
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js';
import { namehash } from '../../utils/ens/namehash.js';
import { packetToBytes, } from '../../utils/ens/packetToBytes.js';
import { getAction } from '../../utils/getAction.js';
import { readContract, } from '../public/readContract.js';
/**
* Gets address for ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsAddress
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsAddressParameters}
* @returns Address for ENS name or `null` if not found. {@link GetEnsAddressReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsAddress, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensAddress = await getEnsAddress(client, {
* name: normalize('wevm.eth'),
* })
* // '0xd2135CfB216b74109775236E36d4b433F1DF507B'
*/
export async function getEnsAddress(client, parameters) {
const { blockNumber, blockTag, coinType, name, gatewayUrls, strict } = parameters;
const { chain } = client;
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress;
if (!chain)
throw new Error('client chain not configured. universalResolverAddress is required.');
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
});
})();
const tlds = chain?.ensTlds;
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
return null;
const args = (() => {
if (coinType != null)
return [namehash(name), BigInt(coinType)];
return [namehash(name)];
})();
try {
const functionData = encodeFunctionData({
abi: addressResolverAbi,
functionName: 'addr',
args,
});
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverResolveAbi,
functionName: 'resolveWithGateways',
args: [
toHex(packetToBytes(name)),
functionData,
gatewayUrls ?? [localBatchGatewayUrl],
],
blockNumber,
blockTag,
};
const readContractAction = getAction(client, readContract, 'readContract');
const res = await readContractAction(readContractParameters);
if (res[0] === '0x')
return null;
const address = decodeFunctionResult({
abi: addressResolverAbi,
args,
functionName: 'addr',
data: res[0],
});
if (address === '0x')
return null;
if (trim(address) === '0x00')
return null;
return address;
}
catch (err) {
if (strict)
throw err;
if (isNullUniversalResolverError(err))
return null;
throw err;
}
}
//# sourceMappingURL=getEnsAddress.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getEnsAddress.js","sourceRoot":"","sources":["../../../actions/ens/getEnsAddress.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,kBAAkB,EAClB,2BAA2B,GAC5B,MAAM,yBAAyB,CAAA;AAIhC,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAEL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA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,EAAE,CAAC;QACb,IAAI,MAAM;YAAE,MAAM,GAAG,CAAA;QACrB,IAAI,4BAA4B,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QAClD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC"}

54
node_modules/viem/_esm/actions/ens/getEnsAvatar.js generated vendored Normal file
View File

@@ -0,0 +1,54 @@
import { parseAvatarRecord, } from '../../utils/ens/avatar/parseAvatarRecord.js';
import { getAction } from '../../utils/getAction.js';
import { getEnsText, } from './getEnsText.js';
/**
* Gets the avatar of an ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsAvatar
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls [`getEnsText`](https://viem.sh/docs/ens/actions/getEnsText) with `key` set to `'avatar'`.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsAvatarParameters}
* @returns Avatar URI or `null` if not found. {@link GetEnsAvatarReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsAvatar, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensAvatar = await getEnsAvatar(client, {
* name: normalize('wevm.eth'),
* })
* // 'https://ipfs.io/ipfs/Qma8mnp6xV3J2cRNf3mTth5C8nV11CAnceVinc3y8jSbio'
*/
export async function getEnsAvatar(client, { blockNumber, blockTag, assetGatewayUrls, name, gatewayUrls, strict, universalResolverAddress, }) {
const record = await getAction(client, getEnsText, 'getEnsText')({
blockNumber,
blockTag,
key: 'avatar',
name,
universalResolverAddress,
gatewayUrls,
strict,
});
if (!record)
return null;
try {
return await parseAvatarRecord(client, {
record,
gatewayUrls: assetGatewayUrls,
});
}
catch {
return null;
}
}
//# sourceMappingURL=getEnsAvatar.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getEnsAvatar.js","sourceRoot":"","sources":["../../../actions/ens/getEnsAvatar.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,iBAAiB,GAClB,MAAM,6CAA6C,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAGL,UAAU,GACX,MAAM,iBAAiB,CAAA;AAgBxB;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAgC,EAChC,EACE,WAAW,EACX,QAAQ,EACR,gBAAgB,EAChB,IAAI,EACJ,WAAW,EACX,MAAM,EACN,wBAAwB,GACD;IAEzB,MAAM,MAAM,GAAG,MAAM,SAAS,CAC5B,MAAM,EACN,UAAU,EACV,YAAY,CACb,CAAC;QACA,WAAW;QACX,QAAQ;QACR,GAAG,EAAE,QAAQ;QACb,IAAI;QACJ,wBAAwB;QACxB,WAAW;QACX,MAAM;KACP,CAAC,CAAA;IACF,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,CAAC;QACH,OAAO,MAAM,iBAAiB,CAAC,MAAM,EAAE;YACrC,MAAM;YACN,WAAW,EAAE,gBAAgB;SAC9B,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}

68
node_modules/viem/_esm/actions/ens/getEnsName.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
import { universalResolverReverseAbi } from '../../constants/abis.js';
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { isNullUniversalResolverError } from '../../utils/ens/errors.js';
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js';
import { getAction } from '../../utils/getAction.js';
import { readContract, } from '../public/readContract.js';
/**
* Gets primary name for specified address.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsName
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `reverse(bytes)` on ENS Universal Resolver Contract to "reverse resolve" the address to the primary ENS name.
*
* @param client - Client to use
* @param parameters - {@link GetEnsNameParameters}
* @returns Name or `null` if not found. {@link GetEnsNameReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsName } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const ensName = await getEnsName(client, {
* address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
* })
* // 'wevm.eth'
*/
export async function getEnsName(client, parameters) {
const { address, blockNumber, blockTag, coinType = 60n, gatewayUrls, strict, } = parameters;
const { chain } = client;
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress;
if (!chain)
throw new Error('client chain not configured. universalResolverAddress is required.');
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
});
})();
try {
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverReverseAbi,
args: [address, coinType, gatewayUrls ?? [localBatchGatewayUrl]],
functionName: 'reverseWithGateways',
blockNumber,
blockTag,
};
const readContractAction = getAction(client, readContract, 'readContract');
const [name] = await readContractAction(readContractParameters);
return name || null;
}
catch (err) {
if (strict)
throw err;
if (isNullUniversalResolverError(err))
return null;
throw err;
}
}
//# sourceMappingURL=getEnsName.js.map

1
node_modules/viem/_esm/actions/ens/getEnsName.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"getEnsName.js","sourceRoot":"","sources":["../../../actions/ens/getEnsName.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAIrE,OAAO,EAEL,uBAAuB,GACxB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA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QACb,IAAI,MAAM;YAAE,MAAM,GAAG,CAAA;QACrB,IAAI,4BAA4B,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QAClD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC"}

73
node_modules/viem/_esm/actions/ens/getEnsResolver.js generated vendored Normal file
View File

@@ -0,0 +1,73 @@
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { toHex } from '../../utils/encoding/toHex.js';
import { packetToBytes, } from '../../utils/ens/packetToBytes.js';
import { getAction } from '../../utils/getAction.js';
import { readContract, } from '../public/readContract.js';
/**
* Gets resolver for ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsResolver
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `findResolver(bytes)` on ENS Universal Resolver Contract to retrieve the resolver of an ENS name.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsResolverParameters}
* @returns Address for ENS resolver. {@link GetEnsResolverReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsResolver, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const resolverAddress = await getEnsResolver(client, {
* name: normalize('wevm.eth'),
* })
* // '0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41'
*/
export async function getEnsResolver(client, parameters) {
const { blockNumber, blockTag, name } = parameters;
const { chain } = client;
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress;
if (!chain)
throw new Error('client chain not configured. universalResolverAddress is required.');
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
});
})();
const tlds = chain?.ensTlds;
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
throw new Error(`${name} is not a valid ENS TLD (${tlds?.join(', ')}) for chain "${chain.name}" (id: ${chain.id}).`);
const [resolverAddress] = await getAction(client, readContract, 'readContract')({
address: universalResolverAddress,
abi: [
{
inputs: [{ type: 'bytes' }],
name: 'findResolver',
outputs: [
{ type: 'address' },
{ type: 'bytes32' },
{ type: 'uint256' },
],
stateMutability: 'view',
type: 'function',
},
],
functionName: 'findResolver',
args: [toHex(packetToBytes(name))],
blockNumber,
blockTag,
});
return resolverAddress;
}
//# sourceMappingURL=getEnsResolver.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getEnsResolver.js","sourceRoot":"","sources":["../../../actions/ens/getEnsResolver.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,uBAAuB,GACxB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAAuB,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,EAEL,aAAa,GACd,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAEL,YAAY,GACb,MAAM,2BAA2B,CAAA;AAmBlC;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAgC,EAChC,UAAoC;IAEpC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,UAAU,CAAA;IAClD,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAExB,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE;QACrC,IAAI,UAAU,CAAC,wBAAwB;YACrC,OAAO,UAAU,CAAC,wBAAwB,CAAA;QAC5C,IAAI,CAAC,KAAK;YACR,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAA;QACH,OAAO,uBAAuB,CAAC;YAC7B,WAAW;YACX,KAAK;YACL,QAAQ,EAAE,sBAAsB;SACjC,CAAC,CAAA;IACJ,CAAC,CAAC,EAAE,CAAA;IAEJ,MAAM,IAAI,GAAG,KAAK,EAAE,OAAO,CAAA;IAC3B,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACjD,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,4BAA4B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,gBAAgB,KAAK,CAAC,IAAI,UAAU,KAAK,CAAC,EAAE,IAAI,CACpG,CAAA;IAEH,MAAM,CAAC,eAAe,CAAC,GAAG,MAAM,SAAS,CACvC,MAAM,EACN,YAAY,EACZ,cAAc,CACf,CAAC;QACA,OAAO,EAAE,wBAAwB;QACjC,GAAG,EAAE;YACH;gBACE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gBAC3B,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE;oBACP,EAAE,IAAI,EAAE,SAAS,EAAE;oBACnB,EAAE,IAAI,EAAE,SAAS,EAAE;oBACnB,EAAE,IAAI,EAAE,SAAS,EAAE;iBACpB;gBACD,eAAe,EAAE,MAAM;gBACvB,IAAI,EAAE,UAAU;aACjB;SACF;QACD,YAAY,EAAE,cAAc;QAC5B,IAAI,EAAE,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,WAAW;QACX,QAAQ;KACT,CAAC,CAAA;IACF,OAAO,eAAe,CAAA;AACxB,CAAC"}

94
node_modules/viem/_esm/actions/ens/getEnsText.js generated vendored Normal file
View File

@@ -0,0 +1,94 @@
import { textResolverAbi, universalResolverResolveAbi, } from '../../constants/abis.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { toHex } from '../../utils/encoding/toHex.js';
import { isNullUniversalResolverError } from '../../utils/ens/errors.js';
import { localBatchGatewayUrl } from '../../utils/ens/localBatchGatewayRequest.js';
import { namehash } from '../../utils/ens/namehash.js';
import { packetToBytes, } from '../../utils/ens/packetToBytes.js';
import { getAction } from '../../utils/getAction.js';
import { readContract, } from '../public/readContract.js';
/**
* Gets a text record for specified ENS name.
*
* - Docs: https://viem.sh/docs/ens/actions/getEnsResolver
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/ens
*
* Calls `resolve(bytes, bytes)` on ENS Universal Resolver Contract.
*
* Since ENS names prohibit certain forbidden characters (e.g. underscore) and have other validation rules, you likely want to [normalize ENS names](https://docs.ens.domains/contract-api-reference/name-processing#normalising-names) with [UTS-46 normalization](https://unicode.org/reports/tr46) before passing them to `getEnsAddress`. You can use the built-in [`normalize`](https://viem.sh/docs/ens/utilities/normalize) function for this.
*
* @param client - Client to use
* @param parameters - {@link GetEnsTextParameters}
* @returns Address for ENS resolver. {@link GetEnsTextReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getEnsText, normalize } from 'viem/ens'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const twitterRecord = await getEnsText(client, {
* name: normalize('wevm.eth'),
* key: 'com.twitter',
* })
* // 'wevm_dev'
*/
export async function getEnsText(client, parameters) {
const { blockNumber, blockTag, key, name, gatewayUrls, strict } = parameters;
const { chain } = client;
const universalResolverAddress = (() => {
if (parameters.universalResolverAddress)
return parameters.universalResolverAddress;
if (!chain)
throw new Error('client chain not configured. universalResolverAddress is required.');
return getChainContractAddress({
blockNumber,
chain,
contract: 'ensUniversalResolver',
});
})();
const tlds = chain?.ensTlds;
if (tlds && !tlds.some((tld) => name.endsWith(tld)))
return null;
try {
const readContractParameters = {
address: universalResolverAddress,
abi: universalResolverResolveAbi,
args: [
toHex(packetToBytes(name)),
encodeFunctionData({
abi: textResolverAbi,
functionName: 'text',
args: [namehash(name), key],
}),
gatewayUrls ?? [localBatchGatewayUrl],
],
functionName: 'resolveWithGateways',
blockNumber,
blockTag,
};
const readContractAction = getAction(client, readContract, 'readContract');
const res = await readContractAction(readContractParameters);
if (res[0] === '0x')
return null;
const record = decodeFunctionResult({
abi: textResolverAbi,
functionName: 'text',
data: res[0],
});
return record === '' ? null : record;
}
catch (err) {
if (strict)
throw err;
if (isNullUniversalResolverError(err))
return null;
throw err;
}
}
//# sourceMappingURL=getEnsText.js.map

1
node_modules/viem/_esm/actions/ens/getEnsText.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"getEnsText.js","sourceRoot":"","sources":["../../../actions/ens/getEnsText.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,eAAe,EACf,2BAA2B,GAC5B,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAEL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAEL,uBAAuB,GACxB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAAuB,KAAK,EAAE,MAAM,+BAA+B,CAAA;AAC1E,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAA;AAClF,OAAO,EAA0B,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAEL,aAAa,GACd,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAGL,YAAY,GACb,MAAM,2BAA2B,CAAA;AA4BlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAAgC,EAChC,UAAgC;IAEhC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,WAAW,E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O,IAAI,CAAA;QAEhC,MAAM,MAAM,GAAG,oBAAoB,CAAC;YAClC,GAAG,EAAE,eAAe;YACpB,YAAY,EAAE,MAAM;YACpB,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;SACb,CAAC,CAAA;QAEF,OAAO,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAA;IACtC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,MAAM;YAAE,MAAM,GAAG,CAAA;QACrB,IAAI,4BAA4B,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAA;QAClD,MAAM,GAAG,CAAA;IACX,CAAC;AACH,CAAC"}

214
node_modules/viem/_esm/actions/getContract.js generated vendored Normal file
View File

@@ -0,0 +1,214 @@
import { getAction } from '../utils/getAction.js';
import { createContractEventFilter, } from './public/createContractEventFilter.js';
import { estimateContractGas, } from './public/estimateContractGas.js';
import { getContractEvents, } from './public/getContractEvents.js';
import { readContract, } from './public/readContract.js';
import { simulateContract, } from './public/simulateContract.js';
import { watchContractEvent, } from './public/watchContractEvent.js';
import { writeContract, } from './wallet/writeContract.js';
/**
* Gets type-safe interface for performing contract-related actions with a specific `abi` and `address`.
*
* - Docs https://viem.sh/docs/contract/getContract
*
* Using Contract Instances can make it easier to work with contracts if you don't want to pass the `abi` and `address` properties every time you perform contract actions, e.g. [`readContract`](https://viem.sh/docs/contract/readContract), [`writeContract`](https://viem.sh/docs/contract/writeContract), [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas), etc.
*
* @example
* import { createPublicClient, getContract, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
*
* const publicClient = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const contract = getContract({
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi: parseAbi([
* 'function balanceOf(address owner) view returns (uint256)',
* 'function ownerOf(uint256 tokenId) view returns (address)',
* 'function totalSupply() view returns (uint256)',
* ]),
* client: publicClient,
* })
*/
export function getContract({ abi, address, client: client_, }) {
const client = client_;
const [publicClient, walletClient] = (() => {
if (!client)
return [undefined, undefined];
if ('public' in client && 'wallet' in client)
return [client.public, client.wallet];
if ('public' in client)
return [client.public, undefined];
if ('wallet' in client)
return [undefined, client.wallet];
return [client, client];
})();
const hasPublicClient = publicClient !== undefined && publicClient !== null;
const hasWalletClient = walletClient !== undefined && walletClient !== null;
const contract = {};
let hasReadFunction = false;
let hasWriteFunction = false;
let hasEvent = false;
for (const item of abi) {
if (item.type === 'function')
if (item.stateMutability === 'view' || item.stateMutability === 'pure')
hasReadFunction = true;
else
hasWriteFunction = true;
else if (item.type === 'event')
hasEvent = true;
// Exit early if all flags are `true`
if (hasReadFunction && hasWriteFunction && hasEvent)
break;
}
if (hasPublicClient) {
if (hasReadFunction)
contract.read = new Proxy({}, {
get(_, functionName) {
return (...parameters) => {
const { args, options } = getFunctionParameters(parameters);
return getAction(publicClient, readContract, 'readContract')({
abi,
address,
functionName,
args,
...options,
});
};
},
});
if (hasWriteFunction)
contract.simulate = new Proxy({}, {
get(_, functionName) {
return (...parameters) => {
const { args, options } = getFunctionParameters(parameters);
return getAction(publicClient, simulateContract, 'simulateContract')({
abi,
address,
functionName,
args,
...options,
});
};
},
});
if (hasEvent) {
contract.createEventFilter = new Proxy({}, {
get(_, eventName) {
return (...parameters) => {
const abiEvent = abi.find((x) => x.type === 'event' && x.name === eventName);
const { args, options } = getEventParameters(parameters, abiEvent);
return getAction(publicClient, createContractEventFilter, 'createContractEventFilter')({
abi,
address,
eventName,
args,
...options,
});
};
},
});
contract.getEvents = new Proxy({}, {
get(_, eventName) {
return (...parameters) => {
const abiEvent = abi.find((x) => x.type === 'event' && x.name === eventName);
const { args, options } = getEventParameters(parameters, abiEvent);
return getAction(publicClient, getContractEvents, 'getContractEvents')({
abi,
address,
eventName,
args,
...options,
});
};
},
});
contract.watchEvent = new Proxy({}, {
get(_, eventName) {
return (...parameters) => {
const abiEvent = abi.find((x) => x.type === 'event' && x.name === eventName);
const { args, options } = getEventParameters(parameters, abiEvent);
return getAction(publicClient, watchContractEvent, 'watchContractEvent')({
abi,
address,
eventName,
args,
...options,
});
};
},
});
}
}
if (hasWalletClient) {
if (hasWriteFunction)
contract.write = new Proxy({}, {
get(_, functionName) {
return (...parameters) => {
const { args, options } = getFunctionParameters(parameters);
return getAction(walletClient, writeContract, 'writeContract')({
abi,
address,
functionName,
args,
...options,
});
};
},
});
}
if (hasPublicClient || hasWalletClient)
if (hasWriteFunction)
contract.estimateGas = new Proxy({}, {
get(_, functionName) {
return (...parameters) => {
const { args, options } = getFunctionParameters(parameters);
const client = (publicClient ?? walletClient);
return getAction(client, estimateContractGas, 'estimateContractGas')({
abi,
address,
functionName,
args,
...options,
account: options.account ??
walletClient.account,
});
};
},
});
contract.address = address;
contract.abi = abi;
return contract;
}
/**
* @internal exporting for testing only
*/
export function getFunctionParameters(values) {
const hasArgs = values.length && Array.isArray(values[0]);
const args = hasArgs ? values[0] : [];
const options = (hasArgs ? values[1] : values[0]) ?? {};
return { args, options };
}
/**
* @internal exporting for testing only
*/
export function getEventParameters(values, abiEvent) {
let hasArgs = false;
// If first item is array, must be `args`
if (Array.isArray(values[0]))
hasArgs = true;
// Check if first item is `args` or `options`
else if (values.length === 1) {
// if event has indexed inputs, must have `args`
hasArgs = abiEvent.inputs.some((x) => x.indexed);
// If there are two items in array, must have `args`
}
else if (values.length === 2) {
hasArgs = true;
}
const args = hasArgs ? values[0] : undefined;
const options = (hasArgs ? values[1] : values[0]) ?? {};
return { args, options };
}
//# sourceMappingURL=getContract.js.map

1
node_modules/viem/_esm/actions/getContract.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

114
node_modules/viem/_esm/actions/index.js generated vendored Normal file
View File

@@ -0,0 +1,114 @@
// biome-ignore lint/performance/noBarrelFile: entrypoint module
export { getEnsAddress, } from './ens/getEnsAddress.js';
export { getEnsAvatar, } from './ens/getEnsAvatar.js';
export { getEnsName, } from './ens/getEnsName.js';
export { getEnsResolver, } from './ens/getEnsResolver.js';
export { getEnsText, } from './ens/getEnsText.js';
export { call, } from './public/call.js';
export { createAccessList, } from './public/createAccessList.js';
export { createBlockFilter, } from './public/createBlockFilter.js';
export { createContractEventFilter, } from './public/createContractEventFilter.js';
export { createEventFilter, } from './public/createEventFilter.js';
export { createPendingTransactionFilter, } from './public/createPendingTransactionFilter.js';
export { estimateContractGas, } from './public/estimateContractGas.js';
export { estimateFeesPerGas, } from './public/estimateFeesPerGas.js';
export { estimateGas, } from './public/estimateGas.js';
export { estimateMaxPriorityFeePerGas, } from './public/estimateMaxPriorityFeePerGas.js';
export { fillTransaction, } from './public/fillTransaction.js';
export { getBalance, } from './public/getBalance.js';
export { getBlobBaseFee, } from './public/getBlobBaseFee.js';
export { getBlock, } from './public/getBlock.js';
export { getBlockNumber, } from './public/getBlockNumber.js';
export { getBlockTransactionCount, } from './public/getBlockTransactionCount.js';
export { getChainId, } from './public/getChainId.js';
export {
/** @deprecated Use `getCode` instead */
getCode as getBytecode, getCode, } from './public/getCode.js';
export { getContractEvents, } from './public/getContractEvents.js';
export { getDelegation, } from './public/getDelegation.js';
export { getEip712Domain, } from './public/getEip712Domain.js';
export { getFeeHistory, } from './public/getFeeHistory.js';
export { getFilterChanges, } from './public/getFilterChanges.js';
export { getFilterLogs, } from './public/getFilterLogs.js';
export { getGasPrice, } from './public/getGasPrice.js';
export { getLogs, } from './public/getLogs.js';
export { getProof, } from './public/getProof.js';
export { getStorageAt, } from './public/getStorageAt.js';
export { getTransaction, } from './public/getTransaction.js';
export { getTransactionConfirmations, } from './public/getTransactionConfirmations.js';
export { getTransactionCount, } from './public/getTransactionCount.js';
export { getTransactionReceipt, } from './public/getTransactionReceipt.js';
export { multicall, } from './public/multicall.js';
export { readContract, } from './public/readContract.js';
export { simulateBlocks,
/** @deprecated Use `simulateBlocks` instead */
simulateBlocks as simulate, } from './public/simulateBlocks.js';
export { simulateCalls, } from './public/simulateCalls.js';
export { simulateContract, } from './public/simulateContract.js';
export { uninstallFilter, } from './public/uninstallFilter.js';
export { verifyHash, } from './public/verifyHash.js';
export { verifyMessage, } from './public/verifyMessage.js';
export { verifyTypedData, } from './public/verifyTypedData.js';
export { waitForTransactionReceipt, } from './public/waitForTransactionReceipt.js';
export { watchBlockNumber, } from './public/watchBlockNumber.js';
export { watchBlocks, } from './public/watchBlocks.js';
export { watchContractEvent, } from './public/watchContractEvent.js';
export { watchEvent, } from './public/watchEvent.js';
export { watchPendingTransactions, } from './public/watchPendingTransactions.js';
export { dropTransaction, } from './test/dropTransaction.js';
export { dumpState, } from './test/dumpState.js';
export { getAutomine, } from './test/getAutomine.js';
export { getTxpoolContent, } from './test/getTxpoolContent.js';
export { getTxpoolStatus, } from './test/getTxpoolStatus.js';
export { impersonateAccount, } from './test/impersonateAccount.js';
export { increaseTime, } from './test/increaseTime.js';
export { inspectTxpool, } from './test/inspectTxpool.js';
export { loadState, } from './test/loadState.js';
export { mine, } from './test/mine.js';
export { removeBlockTimestampInterval, } from './test/removeBlockTimestampInterval.js';
export { reset, } from './test/reset.js';
export { revert, } from './test/revert.js';
export { sendUnsignedTransaction, } from './test/sendUnsignedTransaction.js';
export { setAutomine } from './test/setAutomine.js';
export { setBalance, } from './test/setBalance.js';
export { setBlockGasLimit, } from './test/setBlockGasLimit.js';
export { setBlockTimestampInterval, } from './test/setBlockTimestampInterval.js';
export { setCode, } from './test/setCode.js';
export { setCoinbase, } from './test/setCoinbase.js';
export { setIntervalMining, } from './test/setIntervalMining.js';
export { setLoggingEnabled, } from './test/setLoggingEnabled.js';
export { setMinGasPrice, } from './test/setMinGasPrice.js';
export { setNextBlockBaseFeePerGas, } from './test/setNextBlockBaseFeePerGas.js';
export { setNextBlockTimestamp, } from './test/setNextBlockTimestamp.js';
export { setNonce, } from './test/setNonce.js';
export { setRpcUrl } from './test/setRpcUrl.js';
export { setStorageAt, } from './test/setStorageAt.js';
export { snapshot } from './test/snapshot.js';
export { stopImpersonatingAccount, } from './test/stopImpersonatingAccount.js';
export { addChain, } from './wallet/addChain.js';
export { deployContract, } from './wallet/deployContract.js';
export { getAddresses, } from './wallet/getAddresses.js';
export { getCallsStatus, } from './wallet/getCallsStatus.js';
export { getCapabilities, } from './wallet/getCapabilities.js';
export { getPermissions, } from './wallet/getPermissions.js';
export { prepareAuthorization, } from './wallet/prepareAuthorization.js';
export { defaultParameters as defaultPrepareTransactionRequestParameters, prepareTransactionRequest, } from './wallet/prepareTransactionRequest.js';
export { requestAddresses, } from './wallet/requestAddresses.js';
export { requestPermissions, } from './wallet/requestPermissions.js';
export { sendCalls, } from './wallet/sendCalls.js';
export { sendCallsSync, } from './wallet/sendCallsSync.js';
export { sendRawTransaction, } from './wallet/sendRawTransaction.js';
export { sendRawTransactionSync, } from './wallet/sendRawTransactionSync.js';
export { sendTransaction, } from './wallet/sendTransaction.js';
export { sendTransactionSync, } from './wallet/sendTransactionSync.js';
export { showCallsStatus, } from './wallet/showCallsStatus.js';
export { signAuthorization, } from './wallet/signAuthorization.js';
export { signMessage, } from './wallet/signMessage.js';
export { signTransaction, } from './wallet/signTransaction.js';
export { signTypedData, } from './wallet/signTypedData.js';
export { switchChain, } from './wallet/switchChain.js';
export { waitForCallsStatus, } from './wallet/waitForCallsStatus.js';
export { watchAsset, } from './wallet/watchAsset.js';
export { writeContract, } from './wallet/writeContract.js';
export { writeContractSync, } from './wallet/writeContractSync.js';
//# sourceMappingURL=index.js.map

1
node_modules/viem/_esm/actions/index.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../actions/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,OAAO,EAIL,aAAa,GACd,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAIL,YAAY,GACb,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAIL,UAAU,GACX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAIL,cAAc,GACf,MAAM,yBAAyB,CAAA;AAChC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B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAIL,eAAe,GAChB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAIL,iBAAiB,GAClB,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAIL,WAAW,GACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAIL,eAAe,GAChB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAIL,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAGL,WAAW,GACZ,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAKL,kBAAkB,GACnB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAIL,UAAU,GACX,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAIL,aAAa,GACd,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAIL,iBAAiB,GAClB,MAAM,+BAA+B,CAAA"}

264
node_modules/viem/_esm/actions/public/call.js generated vendored Normal file
View File

@@ -0,0 +1,264 @@
import { parseAbi } from 'abitype';
import * as BlockOverrides from 'ox/BlockOverrides';
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { multicall3Abi } from '../../constants/abis.js';
import { aggregate3Signature } from '../../constants/contract.js';
import { deploylessCallViaBytecodeBytecode, deploylessCallViaFactoryBytecode, multicall3Bytecode, } from '../../constants/contracts.js';
import { BaseError } from '../../errors/base.js';
import { ChainDoesNotSupportContract, ClientChainNotConfiguredError, } from '../../errors/chain.js';
import { CounterfactualDeploymentFailedError, RawContractError, } from '../../errors/contract.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeDeployData, } from '../../utils/abi/encodeDeployData.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { getCallError, } from '../../utils/errors/getCallError.js';
import { extract } from '../../utils/formatters/extract.js';
import { formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js';
import { createBatchScheduler, } from '../../utils/promise/createBatchScheduler.js';
import { serializeStateOverride, } from '../../utils/stateOverride.js';
import { assertRequest } from '../../utils/transaction/assertRequest.js';
/**
* Executes a new message call immediately without submitting a transaction to the network.
*
* - Docs: https://viem.sh/docs/actions/public/call
* - JSON-RPC Methods: [`eth_call`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_call)
*
* @param client - Client to use
* @param parameters - {@link CallParameters}
* @returns The call data. {@link CallReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { call } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const data = await call(client, {
* account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
* data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* })
*/
export async function call(client, args) {
const { account: account_ = client.account, authorizationList, batch = Boolean(client.batch?.multicall), blockNumber, blockTag = client.experimental_blockTag ?? 'latest', accessList, blobs, blockOverrides, code, data: data_, factory, factoryData, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce, to, value, stateOverride, ...rest } = args;
const account = account_ ? parseAccount(account_) : undefined;
if (code && (factory || factoryData))
throw new BaseError('Cannot provide both `code` & `factory`/`factoryData` as parameters.');
if (code && to)
throw new BaseError('Cannot provide both `code` & `to` as parameters.');
// Check if the call is deployless via bytecode.
const deploylessCallViaBytecode = code && data_;
// Check if the call is deployless via a factory.
const deploylessCallViaFactory = factory && factoryData && to && data_;
const deploylessCall = deploylessCallViaBytecode || deploylessCallViaFactory;
const data = (() => {
if (deploylessCallViaBytecode)
return toDeploylessCallViaBytecodeData({
code,
data: data_,
});
if (deploylessCallViaFactory)
return toDeploylessCallViaFactoryData({
data: data_,
factory,
factoryData,
to,
});
return data_;
})();
try {
assertRequest(args);
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const block = blockNumberHex || blockTag;
const rpcBlockOverrides = blockOverrides
? BlockOverrides.toRpc(blockOverrides)
: undefined;
const rpcStateOverride = serializeStateOverride(stateOverride);
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
const format = chainFormat || formatTransactionRequest;
const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format: chainFormat }),
accessList,
account,
authorizationList,
blobs,
data,
gas,
gasPrice,
maxFeePerBlobGas,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to: deploylessCall ? undefined : to,
value,
}, 'call');
if (batch &&
shouldPerformMulticall({ request }) &&
!rpcStateOverride &&
!rpcBlockOverrides) {
try {
return await scheduleMulticall(client, {
...request,
blockNumber,
blockTag,
});
}
catch (err) {
if (!(err instanceof ClientChainNotConfiguredError) &&
!(err instanceof ChainDoesNotSupportContract))
throw err;
}
}
const params = (() => {
const base = [
request,
block,
];
if (rpcStateOverride && rpcBlockOverrides)
return [...base, rpcStateOverride, rpcBlockOverrides];
if (rpcStateOverride)
return [...base, rpcStateOverride];
if (rpcBlockOverrides)
return [...base, {}, rpcBlockOverrides];
return base;
})();
const response = await client.request({
method: 'eth_call',
params,
});
if (response === '0x')
return { data: undefined };
return { data: response };
}
catch (err) {
const data = getRevertErrorData(err);
// Check for CCIP-Read offchain lookup signature.
const { offchainLookup, offchainLookupSignature } = await import('../../utils/ccip.js');
if (client.ccipRead !== false &&
data?.slice(0, 10) === offchainLookupSignature &&
to)
return { data: await offchainLookup(client, { data, to }) };
// Check for counterfactual deployment error.
if (deploylessCall && data?.slice(0, 10) === '0x101bb98d')
throw new CounterfactualDeploymentFailedError({ factory });
throw getCallError(err, {
...args,
account,
chain: client.chain,
});
}
}
// We only want to perform a scheduled multicall if:
// - The request has calldata,
// - The request has a target address,
// - The target address is not already the aggregate3 signature,
// - The request has no other properties (`nonce`, `gas`, etc cannot be sent with a multicall).
function shouldPerformMulticall({ request }) {
const { data, to, ...request_ } = request;
if (!data)
return false;
if (data.startsWith(aggregate3Signature))
return false;
if (!to)
return false;
if (Object.values(request_).filter((x) => typeof x !== 'undefined').length > 0)
return false;
return true;
}
async function scheduleMulticall(client, args) {
const { batchSize = 1024, deployless = false, wait = 0, } = typeof client.batch?.multicall === 'object' ? client.batch.multicall : {};
const { blockNumber, blockTag = client.experimental_blockTag ?? 'latest', data, to, } = args;
const multicallAddress = (() => {
if (deployless)
return null;
if (args.multicallAddress)
return args.multicallAddress;
if (client.chain) {
return getChainContractAddress({
blockNumber,
chain: client.chain,
contract: 'multicall3',
});
}
throw new ClientChainNotConfiguredError();
})();
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const block = blockNumberHex || blockTag;
const { schedule } = createBatchScheduler({
id: `${client.uid}.${block}`,
wait,
shouldSplitBatch(args) {
const size = args.reduce((size, { data }) => size + (data.length - 2), 0);
return size > batchSize * 2;
},
fn: async (requests) => {
const calls = requests.map((request) => ({
allowFailure: true,
callData: request.data,
target: request.to,
}));
const calldata = encodeFunctionData({
abi: multicall3Abi,
args: [calls],
functionName: 'aggregate3',
});
const data = await client.request({
method: 'eth_call',
params: [
{
...(multicallAddress === null
? {
data: toDeploylessCallViaBytecodeData({
code: multicall3Bytecode,
data: calldata,
}),
}
: { to: multicallAddress, data: calldata }),
},
block,
],
});
return decodeFunctionResult({
abi: multicall3Abi,
args: [calls],
functionName: 'aggregate3',
data: data || '0x',
});
},
});
const [{ returnData, success }] = await schedule({ data, to });
if (!success)
throw new RawContractError({ data: returnData });
if (returnData === '0x')
return { data: undefined };
return { data: returnData };
}
function toDeploylessCallViaBytecodeData(parameters) {
const { code, data } = parameters;
return encodeDeployData({
abi: parseAbi(['constructor(bytes, bytes)']),
bytecode: deploylessCallViaBytecodeBytecode,
args: [code, data],
});
}
function toDeploylessCallViaFactoryData(parameters) {
const { data, factory, factoryData, to } = parameters;
return encodeDeployData({
abi: parseAbi(['constructor(address, bytes, address, bytes)']),
bytecode: deploylessCallViaFactoryBytecode,
args: [to, data, factory, factoryData],
});
}
/** @internal */
export function getRevertErrorData(err) {
if (!(err instanceof BaseError))
return undefined;
const error = err.walk();
return typeof error?.data === 'object' ? error.data?.data : error.data;
}
//# sourceMappingURL=call.js.map

1
node_modules/viem/_esm/actions/public/call.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,72 @@
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { getCallError, } from '../../utils/errors/getCallError.js';
import { extract } from '../../utils/formatters/extract.js';
import { formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js';
import { assertRequest } from '../../utils/transaction/assertRequest.js';
/**
* Creates an EIP-2930 access list.
*
* - Docs: https://viem.sh/docs/actions/public/createAccessList
* - JSON-RPC Methods: `eth_createAccessList`
*
* @param client - Client to use
* @param parameters - {@link CreateAccessListParameters}
* @returns The access list. {@link CreateAccessListReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createAccessList } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const data = await createAccessList(client, {
* account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
* data: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* })
*/
export async function createAccessList(client, args) {
const { account: account_ = client.account, blockNumber, blockTag = 'latest', blobs, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, to, value, ...rest } = args;
const account = account_ ? parseAccount(account_) : undefined;
try {
assertRequest(args);
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const block = blockNumberHex || blockTag;
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
const format = chainFormat || formatTransactionRequest;
const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format: chainFormat }),
account,
blobs,
data,
gas,
gasPrice,
maxFeePerBlobGas,
maxFeePerGas,
maxPriorityFeePerGas,
to,
value,
}, 'createAccessList');
const response = await client.request({
method: 'eth_createAccessList',
params: [request, block],
});
return {
accessList: response.accessList,
gasUsed: BigInt(response.gasUsed),
};
}
catch (err) {
throw getCallError(err, {
...args,
account,
chain: client.chain,
});
}
}
//# sourceMappingURL=createAccessList.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createAccessList.js","sourceRoot":"","sources":["../../../actions/public/createAccessList.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,YAAY,GACb,MAAM,sCAAsC,CAAA;AAU7C,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,YAAY,GACb,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAC3D,OAAO,EAGL,wBAAwB,GACzB,MAAM,8CAA8C,CAAA;AAKrD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAA;AAuCxE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAgC,EAChC,IAAuC;IAEvC,MAAM,EACJ,OAAO,EAAE,QAAQ,GAAG,MAAM,CAAC,OAAO,EAClC,WAAW,EACX,QAAQ,GAAG,QAAQ,EACnB,KAAK,EACL,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACpB,EAAE,EACF,KAAK,EACL,GAAG,IAAI,EACR,GAAG,IAAI,CAAA;IACR,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAE7D,IAAI,CAAC;QACH,aAAa,CAAC,IAA+B,CAAC,CAAA;QAE9C,MAAM,cAAc,GAClB,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACxE,MAAM,KAAK,GAAG,cAAc,IAAI,QAAQ,CAAA;QAExC,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,CAAA;QACxE,MAAM,MAAM,GAAG,WAAW,IAAI,wBAAwB,CAAA;QAEtD,MAAM,OAAO,GAAG,MAAM,CACpB;YACE,gFAAgF;YAChF,GAAG,OAAO,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;YACzC,OAAO;YACP,KAAK;YACL,IAAI;YACJ,GAAG;YACH,QAAQ;YACR,gBAAgB;YAChB,YAAY;YACZ,oBAAoB;YACpB,EAAE;YACF,KAAK;SACgB,EACvB,kBAAkB,CACG,CAAA;QAEvB,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;YACpC,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE,CAAC,OAA8C,EAAE,KAAK,CAAC;SAChE,CAAC,CAAA;QACF,OAAO;YACL,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC;SAClC,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,YAAY,CAAC,GAAgB,EAAE;YACnC,GAAG,IAAI;YACP,OAAO;YACP,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,32 @@
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js';
/**
* Creates a [`Filter`](https://viem.sh/docs/glossary/types#filter) to listen for new block hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
*
* - Docs: https://viem.sh/docs/actions/public/createBlockFilter
* - JSON-RPC Methods: [`eth_newBlockFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newBlockFilter)
*
* @param client - Client to use
* @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateBlockFilterReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createBlockFilter } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createBlockFilter(client)
* // { id: "0x345a6572337856574a76364e457a4366", type: 'block' }
*/
export async function createBlockFilter(client) {
const getRequest = createFilterRequestScope(client, {
method: 'eth_newBlockFilter',
});
const id = await client.request({
method: 'eth_newBlockFilter',
});
return { id, request: getRequest(id), type: 'block' };
}
//# sourceMappingURL=createBlockFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createBlockFilter.js","sourceRoot":"","sources":["../../../actions/public/createBlockFilter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAM1F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAgC;IAEhC,MAAM,UAAU,GAAG,wBAAwB,CAAC,MAAM,EAAE;QAClD,MAAM,EAAE,oBAAoB;KAC7B,CAAC,CAAA;IACF,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9B,MAAM,EAAE,oBAAoB;KAC7B,CAAC,CAAA;IACF,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AACvD,CAAC"}

View File

@@ -0,0 +1,59 @@
import { encodeEventTopics, } from '../../utils/abi/encodeEventTopics.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js';
/**
* Creates a Filter to retrieve event logs that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges) or [`getFilterLogs`](https://viem.sh/docs/actions/public/getFilterLogs).
*
* - Docs: https://viem.sh/docs/contract/createContractEventFilter
*
* @param client - Client to use
* @param parameters - {@link CreateContractEventFilterParameters}
* @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateContractEventFilterReturnType}
*
* @example
* import { createPublicClient, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createContractEventFilter } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createContractEventFilter(client, {
* abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']),
* })
*/
export async function createContractEventFilter(client, parameters) {
const { address, abi, args, eventName, fromBlock, strict, toBlock } = parameters;
const getRequest = createFilterRequestScope(client, {
method: 'eth_newFilter',
});
const topics = eventName
? encodeEventTopics({
abi,
args,
eventName,
})
: undefined;
const id = await client.request({
method: 'eth_newFilter',
params: [
{
address,
fromBlock: typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
topics,
},
],
});
return {
abi,
args,
eventName,
id,
request: getRequest(id),
strict: Boolean(strict),
type: 'event',
};
}
//# sourceMappingURL=createContractEventFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createContractEventFilter.js","sourceRoot":"","sources":["../../../actions/public/createContractEventFilter.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,iBAAiB,GAClB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAsD1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAS7C,MAAgC,EAChC,UAOC;IAWD,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GACjE,UAAiD,CAAA;IAEnD,MAAM,UAAU,GAAG,wBAAwB,CAAC,MAAM,EAAE;QAClD,MAAM,EAAE,eAAe;KACxB,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,SAAS;QACtB,CAAC,CAAC,iBAAiB,CAAC;YAChB,GAAG;YACH,IAAI;YACJ,SAAS;SACgC,CAAC;QAC9C,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,EAAE,GAAQ,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,eAAe;QACvB,MAAM,EAAE;YACN;gBACE,OAAO;gBACP,SAAS,EACP,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS;gBACpE,OAAO,EAAE,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO;gBACrE,MAAM;aACP;SACF;KACF,CAAC,CAAA;IAEF,OAAO;QACL,GAAG;QACH,IAAI;QACJ,SAAS;QACT,EAAE;QACF,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;QACvB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC;QACvB,IAAI,EAAE,OAAO;KAQd,CAAA;AACH,CAAC"}

View File

@@ -0,0 +1,67 @@
import { encodeEventTopics, } from '../../utils/abi/encodeEventTopics.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js';
/**
* Creates a [`Filter`](https://viem.sh/docs/glossary/types#filter) to listen for new events that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
*
* - Docs: https://viem.sh/docs/actions/public/createEventFilter
* - JSON-RPC Methods: [`eth_newFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter)
*
* @param client - Client to use
* @param parameters - {@link CreateEventFilterParameters}
* @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateEventFilterReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createEventFilter } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createEventFilter(client, {
* address: '0xfba3912ca04dd458c843e2ee08967fc04f3579c2',
* })
*/
export async function createEventFilter(client, { address, args, event, events: events_, fromBlock, strict, toBlock, } = {}) {
const events = events_ ?? (event ? [event] : undefined);
const getRequest = createFilterRequestScope(client, {
method: 'eth_newFilter',
});
let topics = [];
if (events) {
const encoded = events.flatMap((event) => encodeEventTopics({
abi: [event],
eventName: event.name,
args,
}));
// TODO: Clean up type casting
topics = [encoded];
if (event)
topics = topics[0];
}
const id = await client.request({
method: 'eth_newFilter',
params: [
{
address,
fromBlock: typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
...(topics.length ? { topics } : {}),
},
],
});
return {
abi: events,
args,
eventName: event ? event.name : undefined,
fromBlock,
id,
request: getRequest(id),
strict: Boolean(strict),
toBlock,
type: 'event',
};
}
//# sourceMappingURL=createEventFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createEventFilter.js","sourceRoot":"","sources":["../../../actions/public/createEventFilter.ts"],"names":[],"mappings":"AAcA,OAAO,EAGL,iBAAiB,GAClB,MAAM,sCAAsC,CAAA;AAE7C,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AA6F1F;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAerC,MAAgC,EAChC,EACE,OAAO,EACP,IAAI,EACJ,KAAK,EACL,MAAM,EAAE,OAAO,EACf,SAAS,EACT,MAAM,EACN,OAAO,MASL,EAAS;IAYb,MAAM,MAAM,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SA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ACP,IAAI,EAAE,OAAO;KASd,CAAA;AACH,CAAC"}

View File

@@ -0,0 +1,32 @@
import { createFilterRequestScope } from '../../utils/filters/createFilterRequestScope.js';
/**
* Creates a Filter to listen for new pending transaction hashes that can be used with [`getFilterChanges`](https://viem.sh/docs/actions/public/getFilterChanges).
*
* - Docs: https://viem.sh/docs/actions/public/createPendingTransactionFilter
* - JSON-RPC Methods: [`eth_newPendingTransactionFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newpendingtransactionfilter)
*
* @param client - Client to use
* @returns [`Filter`](https://viem.sh/docs/glossary/types#filter). {@link CreateBlockFilterReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createPendingTransactionFilter } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createPendingTransactionFilter(client)
* // { id: "0x345a6572337856574a76364e457a4366", type: 'transaction' }
*/
export async function createPendingTransactionFilter(client) {
const getRequest = createFilterRequestScope(client, {
method: 'eth_newPendingTransactionFilter',
});
const id = await client.request({
method: 'eth_newPendingTransactionFilter',
});
return { id, request: getRequest(id), type: 'transaction' };
}
//# sourceMappingURL=createPendingTransactionFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"createPendingTransactionFilter.js","sourceRoot":"","sources":["../../../actions/public/createPendingTransactionFilter.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAA;AAQ1F;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,8BAA8B,CAIlD,MAAgC;IAEhC,MAAM,UAAU,GAAG,wBAAwB,CAAC,MAAM,EAAE;QAClD,MAAM,EAAE,iCAAiC;KAC1C,CAAC,CAAA;IACF,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAC9B,MAAM,EAAE,iCAAiC;KAC1C,CAAC,CAAA;IACF,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAA;AAC7D,CAAC"}

View File

@@ -0,0 +1,62 @@
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getContractError, } from '../../utils/errors/getContractError.js';
import { getAction } from '../../utils/getAction.js';
import { estimateGas, } from './estimateGas.js';
/**
* Estimates the gas required to successfully execute a contract write function call.
*
* - Docs: https://viem.sh/docs/contract/estimateContractGas
*
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`estimateGas` action](https://viem.sh/docs/actions/public/estimateGas) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
*
* @param client - Client to use
* @param parameters - {@link EstimateContractGasParameters}
* @returns The gas estimate (in wei). {@link EstimateContractGasReturnType}
*
* @example
* import { createPublicClient, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
* import { estimateContractGas } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const gas = await estimateContractGas(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi: parseAbi(['function mint() public']),
* functionName: 'mint',
* account: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
* })
*/
export async function estimateContractGas(client, parameters) {
const { abi, address, args, functionName, dataSuffix = typeof client.dataSuffix === 'string'
? client.dataSuffix
: client.dataSuffix?.value, ...request } = parameters;
const data = encodeFunctionData({
abi,
args,
functionName,
});
try {
const gas = await getAction(client, estimateGas, 'estimateGas')({
data: `${data}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
to: address,
...request,
});
return gas;
}
catch (error) {
const account = request.account ? parseAccount(request.account) : undefined;
throw getContractError(error, {
abi,
address,
args,
docsPath: '/docs/contract/estimateContractGas',
functionName,
sender: account?.address,
});
}
}
//# sourceMappingURL=estimateContractGas.js.map

View File

@@ -0,0 +1 @@
{"version":3,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AAC,CAAC,CAAC,SAAS,CAAA;QAC3E,MAAM,gBAAgB,CAAC,KAAkB,EAAE;YACzC,GAAG;YACH,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,oCAAoC;YAC9C,YAAY;YACZ,MAAM,EAAE,OAAO,EAAE,OAAO;SACzB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,86 @@
import { BaseFeeScalarError, Eip1559FeesNotSupportedError, } from '../../errors/fee.js';
import { getAction } from '../../utils/getAction.js';
import { internal_estimateMaxPriorityFeePerGas, } from './estimateMaxPriorityFeePerGas.js';
import { getBlock } from './getBlock.js';
import { getGasPrice } from './getGasPrice.js';
/**
* Returns an estimate for the fees per gas (in wei) for a
* transaction to be likely included in the next block.
* Defaults to [`chain.fees.estimateFeesPerGas`](/docs/clients/chains#fees-estimatefeespergas) if set.
*
* - Docs: https://viem.sh/docs/actions/public/estimateFeesPerGas
*
* @param client - Client to use
* @param parameters - {@link EstimateFeesPerGasParameters}
* @returns An estimate (in wei) for the fees per gas. {@link EstimateFeesPerGasReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { estimateFeesPerGas } from 'viem/actions'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const maxPriorityFeePerGas = await estimateFeesPerGas(client)
* // { maxFeePerGas: ..., maxPriorityFeePerGas: ... }
*/
export async function estimateFeesPerGas(client, args) {
return internal_estimateFeesPerGas(client, args);
}
export async function internal_estimateFeesPerGas(client, args) {
const { block: block_, chain = client.chain, request, type = 'eip1559', } = args || {};
const baseFeeMultiplier = await (async () => {
if (typeof chain?.fees?.baseFeeMultiplier === 'function')
return chain.fees.baseFeeMultiplier({
block: block_,
client,
request,
});
return chain?.fees?.baseFeeMultiplier ?? 1.2;
})();
if (baseFeeMultiplier < 1)
throw new BaseFeeScalarError();
const decimals = baseFeeMultiplier.toString().split('.')[1]?.length ?? 0;
const denominator = 10 ** decimals;
const multiply = (base) => (base * BigInt(Math.ceil(baseFeeMultiplier * denominator))) /
BigInt(denominator);
const block = block_
? block_
: await getAction(client, getBlock, 'getBlock')({});
if (typeof chain?.fees?.estimateFeesPerGas === 'function') {
const fees = (await chain.fees.estimateFeesPerGas({
block: block_,
client,
multiply,
request,
type,
}));
if (fees !== null)
return fees;
}
if (type === 'eip1559') {
if (typeof block.baseFeePerGas !== 'bigint')
throw new Eip1559FeesNotSupportedError();
const maxPriorityFeePerGas = typeof request?.maxPriorityFeePerGas === 'bigint'
? request.maxPriorityFeePerGas
: await internal_estimateMaxPriorityFeePerGas(client, {
block: block,
chain,
request,
});
const baseFeePerGas = multiply(block.baseFeePerGas);
const maxFeePerGas = request?.maxFeePerGas ?? baseFeePerGas + maxPriorityFeePerGas;
return {
maxFeePerGas,
maxPriorityFeePerGas,
};
}
const gasPrice = request?.gasPrice ??
multiply(await getAction(client, getGasPrice, 'getGasPrice')({}));
return {
gasPrice,
};
}
//# sourceMappingURL=estimateFeesPerGas.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estimateFeesPerGas.js","sourceRoot":"","sources":["../../../actions/public/estimateFeesPerGas.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,kBAAkB,EAElB,4BAA4B,GAE7B,MAAM,qBAAqB,CAAA;AAe5B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAEL,qCAAqC,GACtC,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAA6B,WAAW,EAAE,MAAM,kBAAkB,CAAA;AA+BzE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAKtC,MAAgC,EAChC,IAA2E;IAE3E,OAAO,2BAA2B,CAAC,MAAM,EAAE,IAAW,CAAC,CAAA;AACzD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAK/C,MAAgC,E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AAK,EAAE,MAAe;YACtB,MAAM;YACN,QAAQ;YACR,OAAO;YACP,IAAI;SACkC,CAAC,CAAkD,CAAA;QAE3F,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;IAChC,CAAC;IAED,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,IAAI,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ;YACzC,MAAM,IAAI,4BAA4B,EAAE,CAAA;QAE1C,MAAM,oBAAoB,GACxB,OAAO,OAAO,EAAE,oBAAoB,KAAK,QAAQ;YAC/C,CAAC,CAAC,OAAO,CAAC,oBAAoB;YAC9B,CAAC,CAAC,MAAM,qCAAqC,CACzC,MAAkC,EAClC;gBACE,KAAK,EAAE,KAAc;gBACrB,KAAK;gBACL,OAAO;aACR,CACF,CAAA;QAEP,MAAM,aAAa,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QACnD,MAAM,YAAY,GAChB,OAAO,EAAE,YAAY,IAAI,aAAa,GAAG,oBAAoB,CAAA;QAE/D,OAAO;YACL,YAAY;YACZ,oBAAoB;SACiB,CAAA;IACzC,CAAC;IAED,MAAM,QAAQ,GACZ,OAAO,EAAE,QAAQ;QACjB,QAAQ,CAAC,MAAM,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACnE,OAAO;QACL,QAAQ;KAC6B,CAAA;AACzC,CAAC"}

121
node_modules/viem/_esm/actions/public/estimateGas.js generated vendored Normal file
View File

@@ -0,0 +1,121 @@
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { BaseError } from '../../errors/base.js';
import { recoverAuthorizationAddress, } from '../../utils/authorization/recoverAuthorizationAddress.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { getEstimateGasError, } from '../../utils/errors/getEstimateGasError.js';
import { extract } from '../../utils/formatters/extract.js';
import { formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js';
import { serializeStateOverride } from '../../utils/stateOverride.js';
import { assertRequest, } from '../../utils/transaction/assertRequest.js';
import { prepareTransactionRequest, } from '../wallet/prepareTransactionRequest.js';
/**
* Estimates the gas necessary to complete a transaction without submitting it to the network.
*
* - Docs: https://viem.sh/docs/actions/public/estimateGas
* - JSON-RPC Methods: [`eth_estimateGas`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_estimategas)
*
* @param client - Client to use
* @param parameters - {@link EstimateGasParameters}
* @returns The gas estimate (in gas units). {@link EstimateGasReturnType}
*
* @example
* import { createPublicClient, http, parseEther } from 'viem'
* import { mainnet } from 'viem/chains'
* import { estimateGas } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const gasEstimate = await estimateGas(client, {
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* })
*/
export async function estimateGas(client, args) {
const { account: account_ = client.account, prepare = true } = args;
const account = account_ ? parseAccount(account_) : undefined;
const parameters = (() => {
if (Array.isArray(prepare))
return prepare;
// Some RPC Providers do not compute versioned hashes from blobs. We will need
// to compute them.
if (account?.type !== 'local')
return ['blobVersionedHashes'];
return undefined;
})();
try {
const to = await (async () => {
// If `to` exists on the parameters, use that.
if (args.to)
return args.to;
// If no `to` exists, and we are sending a EIP-7702 transaction, use the
// address of the first authorization in the list.
if (args.authorizationList && args.authorizationList.length > 0)
return await recoverAuthorizationAddress({
authorization: args.authorizationList[0],
}).catch(() => {
throw new BaseError('`to` is required. Could not infer from `authorizationList`');
});
// Otherwise, we are sending a deployment transaction.
return undefined;
})();
const { accessList, authorizationList, blobs, blobVersionedHashes, blockNumber, blockTag, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce, value, stateOverride, ...rest } = prepare
? (await prepareTransactionRequest(client, {
...args,
parameters,
to,
}))
: args;
// If we get `gas` back from the prepared transaction request, which is
// different from the `gas` we provided, it was likely filled by other means
// during request preparation (e.g. `eth_fillTransaction` or `chain.transactionRequest.prepare`).
// (e.g. `eth_fillTransaction` or `chain.transactionRequest.prepare`).
if (gas && args.gas !== gas)
return gas;
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const block = blockNumberHex || blockTag;
const rpcStateOverride = serializeStateOverride(stateOverride);
assertRequest(args);
const chainFormat = client.chain?.formatters?.transactionRequest?.format;
const format = chainFormat || formatTransactionRequest;
const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format: chainFormat }),
account,
accessList,
authorizationList,
blobs,
blobVersionedHashes,
data,
gasPrice,
maxFeePerBlobGas,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
value,
}, 'estimateGas');
return BigInt(await client.request({
method: 'eth_estimateGas',
params: rpcStateOverride
? [
request,
block ?? client.experimental_blockTag ?? 'latest',
rpcStateOverride,
]
: block
? [request, block]
: [request],
}));
}
catch (err) {
throw getEstimateGasError(err, {
...args,
account,
chain: client.chain,
});
}
}
//# sourceMappingURL=estimateGas.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estimateGas.js","sourceRoot":"","sources":["../../../actions/public/estimateGas.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,GACb,MAAM,sCAAsC,CAAA;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAMhD,OAAO,EAEL,2BAA2B,GAC5B,MAAM,0DAA0D,CAAA;AAEjE,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,mBAAmB,GACpB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAC3D,OAAO,EAEL,wBAAwB,GACzB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACrE,OAAO,EAGL,aAAa,GACd,MAAM,0CAA0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AM,CACX,MAAM,MAAM,CAAC,OAAO,CAAC;YACnB,MAAM,EAAE,iBAAiB;YACzB,MAAM,EAAE,gBAAgB;gBACtB,CAAC,CAAC;oBACE,OAAO;oBACP,KAAK,IAAI,MAAM,CAAC,qBAAqB,IAAI,QAAQ;oBACjD,gBAAgB;iBACjB;gBACH,CAAC,CAAC,KAAK;oBACL,CAAC,CAAC,CAAC,OAAO,EAAE,KAAK,CAAC;oBAClB,CAAC,CAAC,CAAC,OAAO,CAAC;SAChB,CAAC,CACH,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,mBAAmB,CAAC,GAAgB,EAAE;YAC1C,GAAG,IAAI;YACP,OAAO;YACP,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,71 @@
import { Eip1559FeesNotSupportedError, } from '../../errors/fee.js';
import { hexToBigInt, } from '../../utils/encoding/fromHex.js';
import { getAction } from '../../utils/getAction.js';
import { getBlock } from './getBlock.js';
import { getGasPrice } from './getGasPrice.js';
/**
* Returns an estimate for the max priority fee per gas (in wei) for a
* transaction to be likely included in the next block.
* Defaults to [`chain.fees.defaultPriorityFee`](/docs/clients/chains#fees-defaultpriorityfee) if set.
*
* - Docs: https://viem.sh/docs/actions/public/estimateMaxPriorityFeePerGas
*
* @param client - Client to use
* @returns An estimate (in wei) for the max priority fee per gas. {@link EstimateMaxPriorityFeePerGasReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { estimateMaxPriorityFeePerGas } from 'viem/actions'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const maxPriorityFeePerGas = await estimateMaxPriorityFeePerGas(client)
* // 10000000n
*/
export async function estimateMaxPriorityFeePerGas(client, args) {
return internal_estimateMaxPriorityFeePerGas(client, args);
}
export async function internal_estimateMaxPriorityFeePerGas(client, args) {
const { block: block_, chain = client.chain, request } = args || {};
try {
const maxPriorityFeePerGas = chain?.fees?.maxPriorityFeePerGas ?? chain?.fees?.defaultPriorityFee;
if (typeof maxPriorityFeePerGas === 'function') {
const block = block_ || (await getAction(client, getBlock, 'getBlock')({}));
const maxPriorityFeePerGas_ = await maxPriorityFeePerGas({
block,
client,
request,
});
if (maxPriorityFeePerGas_ === null)
throw new Error();
return maxPriorityFeePerGas_;
}
if (typeof maxPriorityFeePerGas !== 'undefined')
return maxPriorityFeePerGas;
const maxPriorityFeePerGasHex = await client.request({
method: 'eth_maxPriorityFeePerGas',
});
return hexToBigInt(maxPriorityFeePerGasHex);
}
catch {
// If the RPC Provider does not support `eth_maxPriorityFeePerGas`
// fall back to calculating it manually via `gasPrice - baseFeePerGas`.
// See: https://github.com/ethereum/pm/issues/328#:~:text=eth_maxPriorityFeePerGas%20after%20London%20will%20effectively%20return%20eth_gasPrice%20%2D%20baseFee
const [block, gasPrice] = await Promise.all([
block_
? Promise.resolve(block_)
: getAction(client, getBlock, 'getBlock')({}),
getAction(client, getGasPrice, 'getGasPrice')({}),
]);
if (typeof block.baseFeePerGas !== 'bigint')
throw new Eip1559FeesNotSupportedError();
const maxPriorityFeePerGas = gasPrice - block.baseFeePerGas;
if (maxPriorityFeePerGas < 0n)
return 0n;
return maxPriorityFeePerGas;
}
}
//# sourceMappingURL=estimateMaxPriorityFeePerGas.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estimateMaxPriorityFeePerGas.js","sourceRoot":"","sources":["../../../actions/public/estimateMaxPriorityFeePerGas.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,GAE7B,MAAM,qBAAqB,CAAA;AAU5B,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAA0B,QAAQ,EAAE,MAAM,eAAe,CAAA;AAChE,OAAO,EAA6B,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAkBzE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AAM;gBACJ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC;gBACzB,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC;YAC/C,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC;SAClD,CAAC,CAAA;QAEF,IAAI,OAAO,KAAK,CAAC,aAAa,KAAK,QAAQ;YACzC,MAAM,IAAI,4BAA4B,EAAE,CAAA;QAE1C,MAAM,oBAAoB,GAAG,QAAQ,GAAG,KAAK,CAAC,aAAa,CAAA;QAE3D,IAAI,oBAAoB,GAAG,EAAE;YAAE,OAAO,EAAE,CAAA;QACxC,OAAO,oBAAoB,CAAA;IAC7B,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,150 @@
import { parseAccount } from '../../accounts/utils/parseAccount.js';
import { BaseFeeScalarError } from '../../errors/fee.js';
import { getTransactionError, } from '../../utils/errors/getTransactionError.js';
import { extract } from '../../utils/formatters/extract.js';
import { formatTransaction, } from '../../utils/formatters/transaction.js';
import { formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js';
import { getAction } from '../../utils/getAction.js';
import { assertRequest } from '../../utils/transaction/assertRequest.js';
import { getBlock } from './getBlock.js';
import { getChainId as getChainId_ } from './getChainId.js';
/**
* Fills a transaction request with the necessary fields to be signed over.
*
* - Docs: https://viem.sh/docs/actions/public/fillTransaction
*
* @param client - Client to use
* @param parameters - {@link FillTransactionParameters}
* @returns The filled transaction. {@link FillTransactionReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { fillTransaction } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const result = await fillTransaction(client, {
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* })
*/
export async function fillTransaction(client, parameters) {
const { account = client.account, accessList, authorizationList, chain = client.chain, blobVersionedHashes, blobs, data, gas, gasPrice, maxFeePerBlobGas, maxFeePerGas, maxPriorityFeePerGas, nonce: nonce_, nonceManager, to, type, value, ...rest } = parameters;
const nonce = await (async () => {
if (!account)
return nonce_;
if (!nonceManager)
return nonce_;
if (typeof nonce_ !== 'undefined')
return nonce_;
const account_ = parseAccount(account);
const chainId = chain
? chain.id
: await getAction(client, getChainId_, 'getChainId')({});
return await nonceManager.consume({
address: account_.address,
chainId,
client,
});
})();
assertRequest(parameters);
const chainFormat = chain?.formatters?.transactionRequest?.format;
const format = chainFormat || formatTransactionRequest;
const request = format({
// Pick out extra data that might exist on the chain's transaction request type.
...extract(rest, { format: chainFormat }),
account: account ? parseAccount(account) : undefined,
accessList,
authorizationList,
blobs,
blobVersionedHashes,
data,
gas,
gasPrice,
maxFeePerBlobGas,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
to,
type,
value,
}, 'fillTransaction');
try {
const response = await client.request({
method: 'eth_fillTransaction',
params: [request],
});
const format = chain?.formatters?.transaction?.format || formatTransaction;
const transaction = format(response.tx);
// Remove unnecessary fields.
delete transaction.blockHash;
delete transaction.blockNumber;
delete transaction.r;
delete transaction.s;
delete transaction.transactionIndex;
delete transaction.v;
delete transaction.yParity;
// Rewrite fields.
transaction.data = transaction.input;
// Preference supplied fees (some nodes do not take these preferences).
if (transaction.gas)
transaction.gas = parameters.gas ?? transaction.gas;
if (transaction.gasPrice)
transaction.gasPrice = parameters.gasPrice ?? transaction.gasPrice;
if (transaction.maxFeePerBlobGas)
transaction.maxFeePerBlobGas =
parameters.maxFeePerBlobGas ?? transaction.maxFeePerBlobGas;
if (transaction.maxFeePerGas)
transaction.maxFeePerGas =
parameters.maxFeePerGas ?? transaction.maxFeePerGas;
if (transaction.maxPriorityFeePerGas)
transaction.maxPriorityFeePerGas =
parameters.maxPriorityFeePerGas ?? transaction.maxPriorityFeePerGas;
if (typeof transaction.nonce !== 'undefined')
transaction.nonce = parameters.nonce ?? transaction.nonce;
// Build fee multiplier function.
const feeMultiplier = await (async () => {
if (typeof chain?.fees?.baseFeeMultiplier === 'function') {
const block = await getAction(client, getBlock, 'getBlock')({});
return chain.fees.baseFeeMultiplier({
block,
client,
request: parameters,
});
}
return chain?.fees?.baseFeeMultiplier ?? 1.2;
})();
if (feeMultiplier < 1)
throw new BaseFeeScalarError();
const decimals = feeMultiplier.toString().split('.')[1]?.length ?? 0;
const denominator = 10 ** decimals;
const multiplyFee = (base) => (base * BigInt(Math.ceil(feeMultiplier * denominator))) /
BigInt(denominator);
// Apply fee multiplier.
if (!transaction.feePayerSignature) {
if (transaction.maxFeePerGas && !parameters.maxFeePerGas)
transaction.maxFeePerGas = multiplyFee(transaction.maxFeePerGas);
if (transaction.gasPrice && !parameters.gasPrice)
transaction.gasPrice = multiplyFee(transaction.gasPrice);
}
return {
raw: response.raw,
transaction: {
from: request.from,
...transaction,
},
...(response.capabilities ? { capabilities: response.capabilities } : {}),
};
}
catch (err) {
throw getTransactionError(err, {
...parameters,
chain: client.chain,
});
}
}
//# sourceMappingURL=fillTransaction.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fillTransaction.js","sourceRoot":"","sources":["../../../actions/public/fillTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,sCAAsC,CAAA;AAInE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAaxD,OAAO,EAEL,mBAAmB,GACpB,MAAM,2CAA2C,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAC3D,OAAO,EAEL,iBAAiB,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAEL,wBAAwB,GACzB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAA;AACxE,OAAO,EAAE,QAAQ,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AI,CAAC,CAAA;QACpE,MAAM,WAAW,GAAG,EAAE,IAAI,QAAQ,CAAA;QAClC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,EAAE,CACnC,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,GAAG,WAAW,CAAC,CAAC,CAAC;YACvD,MAAM,CAAC,WAAW,CAAC,CAAA;QAErB,wBAAwB;QACxB,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACnC,IAAI,WAAW,CAAC,YAAY,IAAI,CAAC,UAAU,CAAC,YAAY;gBACtD,WAAW,CAAC,YAAY,GAAG,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;YAClE,IAAI,WAAW,CAAC,QAAQ,IAAI,CAAC,UAAU,CAAC,QAAQ;gBAC9C,WAAW,CAAC,QAAQ,GAAG,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;QAC5D,CAAC;QAED,OAAO;YACL,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,WAAW,EAAE;gBACX,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,GAAG,WAAW;aACf;YACD,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1E,CAAA;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,mBAAmB,CACvB,GAAgB,EAChB;YACE,GAAG,UAAU;YACb,KAAK,EAAE,MAAM,CAAC,KAAK;SACX,CACX,CAAA;IACH,CAAC;AACH,CAAC"}

70
node_modules/viem/_esm/actions/public/getBalance.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import { multicall3Abi } from '../../constants/abis.js';
import { decodeFunctionResult } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData } from '../../utils/abi/encodeFunctionData.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { getAction } from '../../utils/getAction.js';
import { call } from './call.js';
/**
* Returns the balance of an address in wei.
*
* - Docs: https://viem.sh/docs/actions/public/getBalance
* - JSON-RPC Methods: [`eth_getBalance`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getbalance)
*
* You can convert the balance to ether units with [`formatEther`](https://viem.sh/docs/utilities/formatEther).
*
* ```ts
* const balance = await getBalance(client, {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* blockTag: 'safe'
* })
* const balanceAsEther = formatEther(balance)
* // "6.942"
* ```
*
* @param client - Client to use
* @param parameters - {@link GetBalanceParameters}
* @returns The balance of the address in wei. {@link GetBalanceReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getBalance } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const balance = await getBalance(client, {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
* // 10000000000000000000000n (wei)
*/
export async function getBalance(client, { address, blockNumber, blockTag = client.experimental_blockTag ?? 'latest', }) {
if (client.batch?.multicall && client.chain?.contracts?.multicall3) {
const multicall3Address = client.chain.contracts.multicall3.address;
const calldata = encodeFunctionData({
abi: multicall3Abi,
functionName: 'getEthBalance',
args: [address],
});
const { data } = await getAction(client, call, 'call')({
to: multicall3Address,
data: calldata,
blockNumber,
blockTag,
});
return decodeFunctionResult({
abi: multicall3Abi,
functionName: 'getEthBalance',
args: [address],
data: data || '0x',
});
}
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const balance = await client.request({
method: 'eth_getBalance',
params: [address, blockNumberHex || blockTag],
});
return BigInt(balance);
}
//# sourceMappingURL=getBalance.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getBalance.js","sourceRoot":"","sources":["../../../actions/public/getBalance.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAIvD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AAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAExE,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,gBAAgB;QACxB,MAAM,EAAE,CAAC,OAAO,EAAE,cAAc,IAAI,QAAQ,CAAC;KAC9C,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC"}

View File

@@ -0,0 +1,27 @@
/**
* Returns the base fee per blob gas in wei.
*
* - Docs: https://viem.sh/docs/actions/public/getBlobBaseFee
* - JSON-RPC Methods: [`eth_blobBaseFee`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blobBaseFee)
*
* @param client - Client to use
* @returns The blob base fee (in wei). {@link GetBlobBaseFeeReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getBlobBaseFee } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const blobBaseFee = await getBlobBaseFee(client)
*/
export async function getBlobBaseFee(client) {
const baseFee = await client.request({
method: 'eth_blobBaseFee',
});
return BigInt(baseFee);
}
//# sourceMappingURL=getBlobBaseFee.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getBlobBaseFee.js","sourceRoot":"","sources":["../../../actions/public/getBlobBaseFee.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAIlC,MAAyC;IAEzC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACnC,MAAM,EAAE,iBAAiB;KAC1B,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,CAAA;AACxB,CAAC"}

49
node_modules/viem/_esm/actions/public/getBlock.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
import { BlockNotFoundError, } from '../../errors/block.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { formatBlock, } from '../../utils/formatters/block.js';
/**
* Returns information about a block at a block number, hash, or tag.
*
* - Docs: https://viem.sh/docs/actions/public/getBlock
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_fetching-blocks
* - JSON-RPC Methods:
* - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) for `blockNumber` & `blockTag`.
* - Calls [`eth_getBlockByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash) for `blockHash`.
*
* @param client - Client to use
* @param parameters - {@link GetBlockParameters}
* @returns Information about the block. {@link GetBlockReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getBlock } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const block = await getBlock(client)
*/
export async function getBlock(client, { blockHash, blockNumber, blockTag = client.experimental_blockTag ?? 'latest', includeTransactions: includeTransactions_, } = {}) {
const includeTransactions = includeTransactions_ ?? false;
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
let block = null;
if (blockHash) {
block = await client.request({
method: 'eth_getBlockByHash',
params: [blockHash, includeTransactions],
}, { dedupe: true });
}
else {
block = await client.request({
method: 'eth_getBlockByNumber',
params: [blockNumberHex || blockTag, includeTransactions],
}, { dedupe: Boolean(blockNumberHex) });
}
if (!block)
throw new BlockNotFoundError({ blockHash, blockNumber });
const format = client.chain?.formatters?.block?.format || formatBlock;
return format(block, 'getBlock');
}
//# sourceMappingURL=getBlock.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getBlock.js","sourceRoot":"","sources":["../../../actions/public/getBlock.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,GAEnB,MAAM,uBAAuB,CAAA;AAQ9B,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AA4CxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAM5B,MAAyC,EACzC,EACE,SAAS,EACT,WAAW,EACX,QAAQ,GAAG,MAAM,CAAC,qBAAqB,IAAI,QAAQ,EACnD,mBAAmB,EAAE,oBAAoB,MACY,EAAE;IAEzD,MAAM,mBAAmB,GAAG,oBAAoB,IAAI,KAAK,CAAA;IAEzD,MAAM,cAAc,GAClB,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAElE,IAAI,KAAK,GAAoB,IAAI,CAAA;IACjC,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAC1B;YACE,MAAM,EAAE,oBAAoB;YAC5B,MAAM,EAAE,CAAC,SAAS,EAAE,mBAAmB,CAAC;SACzC,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAA;IACH,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAC1B;YACE,MAAM,EAAE,sBAAsB;YAC9B,MAAM,EAAE,CAAC,cAAc,IAAI,QAAQ,EAAE,mBAAmB,CAAC;SAC1D,EACD,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,CACpC,CAAA;IACH,CAAC;IAED,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,kBAAkB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAA;IAEpE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,IAAI,WAAW,CAAA;IACrE,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAA;AAClC,CAAC"}

View File

@@ -0,0 +1,36 @@
import { getCache, withCache, } from '../../utils/promise/withCache.js';
const cacheKey = (id) => `blockNumber.${id}`;
/** @internal */
export function getBlockNumberCache(id) {
return getCache(cacheKey(id));
}
/**
* Returns the number of the most recent block seen.
*
* - Docs: https://viem.sh/docs/actions/public/getBlockNumber
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_fetching-blocks
* - JSON-RPC Methods: [`eth_blockNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blocknumber)
*
* @param client - Client to use
* @param parameters - {@link GetBlockNumberParameters}
* @returns The number of the block. {@link GetBlockNumberReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getBlockNumber } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const blockNumber = await getBlockNumber(client)
* // 69420n
*/
export async function getBlockNumber(client, { cacheTime = client.cacheTime } = {}) {
const blockNumberHex = await withCache(() => client.request({
method: 'eth_blockNumber',
}), { cacheKey: cacheKey(client.uid), cacheTime });
return BigInt(blockNumberHex);
}
//# sourceMappingURL=getBlockNumber.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getBlockNumber.js","sourceRoot":"","sources":["../../../actions/public/getBlockNumber.ts"],"names":[],"mappings":"AAKA,OAAO,EAEL,QAAQ,EACR,SAAS,GACV,MAAM,kCAAkC,CAAA;AAWzC,MAAM,QAAQ,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE,CAAA;AAKpD,gBAAgB;AAChB,MAAM,UAAU,mBAAmB,CAAC,EAAU;IAC5C,OAAO,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;AAC/B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAAgC,EAChC,EAAE,SAAS,GAAG,MAAM,CAAC,SAAS,KAA+B,EAAE;IAE/D,MAAM,cAAc,GAAG,MAAM,SAAS,CACpC,GAAG,EAAE,CACH,MAAM,CAAC,OAAO,CAAC;QACb,MAAM,EAAE,iBAAiB;KAC1B,CAAC,EACJ,EAAE,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,CAC9C,CAAA;IACD,OAAO,MAAM,CAAC,cAAc,CAAC,CAAA;AAC/B,CAAC"}

View File

@@ -0,0 +1,43 @@
import { hexToNumber, } from '../../utils/encoding/fromHex.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
/**
* Returns the number of Transactions at a block number, hash, or tag.
*
* - Docs: https://viem.sh/docs/actions/public/getBlockTransactionCount
* - JSON-RPC Methods:
* - Calls [`eth_getBlockTransactionCountByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblocktransactioncountbynumber) for `blockNumber` & `blockTag`.
* - Calls [`eth_getBlockTransactionCountByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblocktransactioncountbyhash) for `blockHash`.
*
* @param client - Client to use
* @param parameters - {@link GetBlockTransactionCountParameters}
* @returns The block transaction count. {@link GetBlockTransactionCountReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getBlockTransactionCount } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const count = await getBlockTransactionCount(client)
*/
export async function getBlockTransactionCount(client, { blockHash, blockNumber, blockTag = 'latest', } = {}) {
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
let count;
if (blockHash) {
count = await client.request({
method: 'eth_getBlockTransactionCountByHash',
params: [blockHash],
}, { dedupe: true });
}
else {
count = await client.request({
method: 'eth_getBlockTransactionCountByNumber',
params: [blockNumberHex || blockTag],
}, { dedupe: Boolean(blockNumberHex) });
}
return hexToNumber(count);
}
//# sourceMappingURL=getBlockTransactionCount.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getBlockTransactionCount.js","sourceRoot":"","sources":["../../../actions/public/getBlockTransactionCount.ts"],"names":[],"mappings":"AAQA,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AA8BtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC5C,MAAgC,EAChC,EACE,SAAS,EACT,WAAW,EACX,QAAQ,GAAG,QAAQ,MACmB,EAAE;IAE1C,MAAM,cAAc,GAClB,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAElE,IAAI,KAAe,CAAA;IACnB,IAAI,SAAS,EAAE,CAAC;QACd,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAC1B;YACE,MAAM,EAAE,oCAAoC;YAC5C,MAAM,EAAE,CAAC,SAAS,CAAC;SACpB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAA;IACH,CAAC;SAAM,CAAC;QACN,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAC1B;YACE,MAAM,EAAE,sCAAsC;YAC9C,MAAM,EAAE,CAAC,cAAc,IAAI,QAAQ,CAAC;SACrC,EACD,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,CACpC,CAAA;IACH,CAAC;IAED,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC"}

29
node_modules/viem/_esm/actions/public/getChainId.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
import { hexToNumber, } from '../../utils/encoding/fromHex.js';
/**
* Returns the chain ID associated with the current network.
*
* - Docs: https://viem.sh/docs/actions/public/getChainId
* - JSON-RPC Methods: [`eth_chainId`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid)
*
* @param client - Client to use
* @returns The current chain ID. {@link GetChainIdReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getChainId } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const chainId = await getChainId(client)
* // 1
*/
export async function getChainId(client) {
const chainIdHex = await client.request({
method: 'eth_chainId',
}, { dedupe: true });
return hexToNumber(chainIdHex);
}
//# sourceMappingURL=getChainId.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getChainId.js","sourceRoot":"","sources":["../../../actions/public/getChainId.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AASxC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAG9B,MAAyC;IACzC,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CACrC;QACE,MAAM,EAAE,aAAa;KACtB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAA;IACD,OAAO,WAAW,CAAC,UAAU,CAAC,CAAA;AAChC,CAAC"}

35
node_modules/viem/_esm/actions/public/getCode.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
import { numberToHex, } from '../../utils/encoding/toHex.js';
/**
* Retrieves the bytecode at an address.
*
* - Docs: https://viem.sh/docs/contract/getCode
* - JSON-RPC Methods: [`eth_getCode`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getcode)
*
* @param client - Client to use
* @param parameters - {@link GetCodeParameters}
* @returns The contract's bytecode. {@link GetCodeReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getCode } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const code = await getCode(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* })
*/
export async function getCode(client, { address, blockNumber, blockTag = 'latest' }) {
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
const hex = await client.request({
method: 'eth_getCode',
params: [address, blockNumberHex || blockTag],
}, { dedupe: Boolean(blockNumberHex) });
if (hex === '0x')
return undefined;
return hex;
}
//# sourceMappingURL=getCode.js.map

1
node_modules/viem/_esm/actions/public/getCode.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"getCode.js","sourceRoot":"","sources":["../../../actions/public/getCode.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AAsBtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC3B,MAAgC,EAChC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,QAAQ,EAAqB;IAEhE,MAAM,cAAc,GAClB,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,OAAO,CAC9B;QACE,MAAM,EAAE,aAAa;QACrB,MAAM,EAAE,CAAC,OAAO,EAAE,cAAc,IAAI,QAAQ,CAAC;KAC9C,EACD,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,CACpC,CAAA;IACD,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,SAAS,CAAA;IAClC,OAAO,GAAG,CAAA;AACZ,CAAC"}

View File

@@ -0,0 +1,49 @@
import { getAbiItem, } from '../../utils/abi/getAbiItem.js';
import { getAction } from '../../utils/getAction.js';
import { getLogs, } from './getLogs.js';
/**
* Returns a list of event logs emitted by a contract.
*
* - Docs: https://viem.sh/docs/contract/getContractEvents#getcontractevents
* - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
*
* @param client - Client to use
* @param parameters - {@link GetContractEventsParameters}
* @returns A list of event logs. {@link GetContractEventsReturnType}
*
* @example
* import { createClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getContractEvents } from 'viem/public'
* import { wagmiAbi } from './abi'
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
* const logs = await getContractEvents(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi: wagmiAbi,
* eventName: 'Transfer'
* })
*/
export async function getContractEvents(client, parameters) {
const { abi, address, args, blockHash, eventName, fromBlock, toBlock, strict, } = parameters;
const event = eventName
? getAbiItem({ abi, name: eventName })
: undefined;
const events = !event
? abi.filter((x) => x.type === 'event')
: undefined;
return getAction(client, getLogs, 'getLogs')({
address,
args,
blockHash,
event,
events,
fromBlock,
toBlock,
strict,
});
}
//# sourceMappingURL=getContractEvents.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getContractEvents.js","sourceRoot":"","sources":["../../../actions/public/getContractEvents.ts"],"names":[],"mappings":"AAaA,OAAO,EAGL,UAAU,GACX,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAGL,OAAO,GACR,MAAM,cAAc,CAAA;AAiErB;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAQrC,MAAgC,EAChC,UAMC;IAID,MAAM,EACJ,GAAG,EACH,OAAO,EACP,IAAI,EACJ,SAAS,EACT,SAAS,EACT,SAAS,EACT,OAAO,EACP,MAAM,GACP,GAAG,UAAU,CAAA;IACd,MAAM,KAAK,GAAG,SAAS;QACrB,CAAC,CAAC,UAAU,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,EAA0B,CAAC;QAC9D,CAAC,CAAC,SAAS,CAAA;IACb,MAAM,MAAM,GAAG,CAAC,KAAK;QACnB,CAAC,CAAE,GAAW,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC;QAChD,CAAC,CAAC,SAAS,CAAA;IACb,OAAO,SAAS,CACd,MAAM,EACN,OAAO,EACP,SAAS,CACV,CAAC;QACA,OAAO;QACP,IAAI;QACJ,SAAS;QACT,KAAK;QACL,MAAM;QACN,SAAS;QACT,OAAO;QACP,MAAM;KACoB,CAM3B,CAAA;AACH,CAAC"}

43
node_modules/viem/_esm/actions/public/getDelegation.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import { getAddress, } from '../../utils/address/getAddress.js';
import { size } from '../../utils/data/size.js';
import { slice } from '../../utils/data/slice.js';
import { getCode } from './getCode.js';
/**
* Returns the address that an account has delegated to via EIP-7702.
*
* - Docs: https://viem.sh/docs/actions/public/getDelegation
*
* @param client - Client to use
* @param parameters - {@link GetDelegationParameters}
* @returns The delegated address, or undefined if not delegated. {@link GetDelegationReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getDelegation } from 'viem/actions'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const delegation = await getDelegation(client, {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
*/
export async function getDelegation(client, { address, blockNumber, blockTag = 'latest' }) {
const code = await getCode(client, {
address,
...(blockNumber !== undefined ? { blockNumber } : { blockTag }),
});
if (!code)
return undefined;
// EIP-7702 delegation designator: 0xef0100 prefix (3 bytes) + address (20 bytes) = 23 bytes
if (size(code) !== 23)
return undefined;
// Check for EIP-7702 delegation designator prefix
if (!code.startsWith('0xef0100'))
return undefined;
// Extract the delegated address (bytes 3-23) and checksum it
return getAddress(slice(code, 3, 23));
}
//# sourceMappingURL=getDelegation.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getDelegation.js","sourceRoot":"","sources":["../../../actions/public/getDelegation.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,UAAU,GACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,EAAsB,IAAI,EAAE,MAAM,0BAA0B,CAAA;AACnE,OAAO,EAAuB,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtE,OAAO,EAAyB,OAAO,EAAE,MAAM,cAAc,CAAA;AAyB7D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAgC,EAChC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,QAAQ,EAA2B;IAEtE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,MAAM,EAAE;QACjC,OAAO;QACP,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;KACrC,CAAC,CAAA;IAE7B,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAE3B,4FAA4F;IAC5F,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,SAAS,CAAA;IAEvC,kDAAkD;IAClD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC;QAAE,OAAO,SAAS,CAAA;IAElD,6DAA6D;IAC7D,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AACvC,CAAC"}

View File

@@ -0,0 +1,84 @@
import { Eip712DomainNotFoundError, } from '../../errors/eip712.js';
import { getAction } from '../../utils/getAction.js';
import { readContract, } from './readContract.js';
/**
* Reads the EIP-712 domain from a contract, based on the ERC-5267 specification.
*
* @param client - A {@link Client} instance.
* @param parameters - The parameters of the action. {@link GetEip712DomainParameters}
* @returns The EIP-712 domain, fields, and extensions. {@link GetEip712DomainReturnType}
*
* @example
* ```ts
* import { createPublicClient, http, getEip712Domain } from 'viem'
* import { mainnet } from 'viem/chains'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
*
* const domain = await getEip712Domain(client, {
* address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
* })
* // {
* // domain: {
* // name: 'ExampleContract',
* // version: '1',
* // chainId: 1,
* // verifyingContract: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
* // },
* // fields: '0x0f',
* // extensions: [],
* // }
* ```
*/
export async function getEip712Domain(client, parameters) {
const { address, factory, factoryData } = parameters;
try {
const [fields, name, version, chainId, verifyingContract, salt, extensions,] = await getAction(client, readContract, 'readContract')({
abi,
address,
functionName: 'eip712Domain',
factory,
factoryData,
});
return {
domain: {
name,
version,
chainId: Number(chainId),
verifyingContract,
salt,
},
extensions,
fields,
};
}
catch (e) {
const error = e;
if (error.name === 'ContractFunctionExecutionError' &&
error.cause.name === 'ContractFunctionZeroDataError') {
throw new Eip712DomainNotFoundError({ address });
}
throw error;
}
}
const abi = [
{
inputs: [],
name: 'eip712Domain',
outputs: [
{ name: 'fields', type: 'bytes1' },
{ name: 'name', type: 'string' },
{ name: 'version', type: 'string' },
{ name: 'chainId', type: 'uint256' },
{ name: 'verifyingContract', type: 'address' },
{ name: 'salt', type: 'bytes32' },
{ name: 'extensions', type: 'uint256[]' },
],
stateMutability: 'view',
type: 'function',
},
];
//# sourceMappingURL=getEip712Domain.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getEip712Domain.js","sourceRoot":"","sources":["../../../actions/public/getEip712Domain.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,yBAAyB,GAE1B,MAAM,wBAAwB,CAAA;AAI/B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAGL,YAAY,GACb,MAAM,mBAAmB,CAAA;AAoB1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAyB,EACzB,UAAqC;IAErC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,UAAU,CAAA;IAEpD,IAAI,CAAC;QACH,MAAM,CACJ,MAAM,EACN,IAAI,EACJ,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,IAAI,EACJ,UAAU,EACX,GAAG,MAAM,SAAS,CACjB,MAAM,EACN,YAAY,EACZ,cAAc,CACf,CAAC;YACA,GAAG;YACH,OAAO;YACP,YAAY,EAAE,cAAc;YAC5B,OAAO;YACP,WAAW;SACZ,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE;gBACN,IAAI;gBACJ,OAAO;gBACP,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;gBACxB,iBAAiB;gBACjB,IAAI;aACL;YACD,UAAU;YACV,MAAM;SACP,CAAA;IACH,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,KAAK,GAAG,CAA0B,CAAA;QACxC,IACE,KAAK,CAAC,IAAI,KAAK,gCAAgC;YAC/C,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,+BAA+B,EACpD,CAAC;YACD,MAAM,IAAI,yBAAyB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QAClD,CAAC;QACD,MAAM,KAAK,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,GAAG,GAAG;IACV;QACE,MAAM,EAAE,EAAE;QACV,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE;YACP,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;YAClC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;YAChC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;YACnC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;YACpC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;YAC9C,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;YACjC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE;SAC1C;QACD,eAAe,EAAE,MAAM;QACvB,IAAI,EAAE,UAAU;KACjB;CACO,CAAA"}

39
node_modules/viem/_esm/actions/public/getFeeHistory.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { formatFeeHistory, } from '../../utils/formatters/feeHistory.js';
/**
* Returns a collection of historical gas information.
*
* - Docs: https://viem.sh/docs/actions/public/getFeeHistory
* - JSON-RPC Methods: [`eth_feeHistory`](https://docs.alchemy.com/reference/eth-feehistory)
*
* @param client - Client to use
* @param parameters - {@link GetFeeHistoryParameters}
* @returns The gas estimate (in wei). {@link GetFeeHistoryReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getFeeHistory } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const feeHistory = await getFeeHistory(client, {
* blockCount: 4,
* rewardPercentiles: [25, 75],
* })
*/
export async function getFeeHistory(client, { blockCount, blockNumber, blockTag = 'latest', rewardPercentiles, }) {
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const feeHistory = await client.request({
method: 'eth_feeHistory',
params: [
numberToHex(blockCount),
blockNumberHex || blockTag,
rewardPercentiles,
],
}, { dedupe: Boolean(blockNumberHex) });
return formatFeeHistory(feeHistory);
}
//# sourceMappingURL=getFeeHistory.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getFeeHistory.js","sourceRoot":"","sources":["../../../actions/public/getFeeHistory.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,gBAAgB,GACjB,MAAM,sCAAsC,CAAA;AAiC7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAgC,EAChC,EACE,UAAU,EACV,WAAW,EACX,QAAQ,GAAG,QAAQ,EACnB,iBAAiB,GACO;IAE1B,MAAM,cAAc,GAClB,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACxE,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,OAAO,CACrC;QACE,MAAM,EAAE,gBAAgB;QACxB,MAAM,EAAE;YACN,WAAW,CAAC,UAAU,CAAC;YACvB,cAAc,IAAI,QAAQ;YAC1B,iBAAiB;SAClB;KACF,EACD,EAAE,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,CACpC,CAAA;IACD,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAA;AACrC,CAAC"}

View File

@@ -0,0 +1,102 @@
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
import { formatLog, } from '../../utils/formatters/log.js';
/**
* Returns a list of logs or hashes based on a [Filter](/docs/glossary/terms#filter) since the last time it was called.
*
* - Docs: https://viem.sh/docs/actions/public/getFilterChanges
* - JSON-RPC Methods: [`eth_getFilterChanges`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterchanges)
*
* A Filter can be created from the following actions:
*
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
* - [`createContractEventFilter`](https://viem.sh/docs/contract/createContractEventFilter)
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
*
* Depending on the type of filter, the return value will be different:
*
* - If the filter was created with `createContractEventFilter` or `createEventFilter`, it returns a list of logs.
* - If the filter was created with `createPendingTransactionFilter`, it returns a list of transaction hashes.
* - If the filter was created with `createBlockFilter`, it returns a list of block hashes.
*
* @param client - Client to use
* @param parameters - {@link GetFilterChangesParameters}
* @returns Logs or hashes. {@link GetFilterChangesReturnType}
*
* @example
* // Blocks
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createBlockFilter, getFilterChanges } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createBlockFilter(client)
* const hashes = await getFilterChanges(client, { filter })
*
* @example
* // Contract Events
* import { createPublicClient, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createContractEventFilter, getFilterChanges } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createContractEventFilter(client, {
* address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
* abi: parseAbi(['event Transfer(address indexed, address indexed, uint256)']),
* eventName: 'Transfer',
* })
* const logs = await getFilterChanges(client, { filter })
*
* @example
* // Raw Events
* import { createPublicClient, http, parseAbiItem } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createEventFilter, getFilterChanges } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createEventFilter(client, {
* address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
* event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'),
* })
* const logs = await getFilterChanges(client, { filter })
*
* @example
* // Transactions
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createPendingTransactionFilter, getFilterChanges } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createPendingTransactionFilter(client)
* const hashes = await getFilterChanges(client, { filter })
*/
export async function getFilterChanges(_client, { filter, }) {
const strict = 'strict' in filter && filter.strict;
const logs = await filter.request({
method: 'eth_getFilterChanges',
params: [filter.id],
});
if (typeof logs[0] === 'string')
return logs;
const formattedLogs = logs.map((log) => formatLog(log));
if (!('abi' in filter) || !filter.abi)
return formattedLogs;
return parseEventLogs({
abi: filter.abi,
logs: formattedLogs,
strict,
});
}
//# sourceMappingURL=getFilterChanges.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getFilterChanges.js","sourceRoot":"","sources":["../../../actions/public/getFilterChanges.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,EAEL,SAAS,GACV,MAAM,+BAA+B,CAAA;AAsCtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiFG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAUpC,OAAiC,EACjC,EACE,MAAM,GAQP;IAWD,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,CAAA;IAElD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,sBAAsB;QAC9B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;KACpB,CAAC,CAAA;IAEF,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;QAC7B,OAAO,IAON,CAAA;IAEH,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAa,CAAC,CAAC,CAAA;IACjE,IAAI,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG;QACnC,OAAO,aAON,CAAA;IACH,OAAO,cAAc,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,IAAI,EAAE,aAAa;QACnB,MAAM;KACP,CAOA,CAAA;AACH,CAAC"}

45
node_modules/viem/_esm/actions/public/getFilterLogs.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
import { formatLog, } from '../../utils/formatters/log.js';
/**
* Returns a list of event logs since the filter was created.
*
* - Docs: https://viem.sh/docs/actions/public/getFilterLogs
* - JSON-RPC Methods: [`eth_getFilterLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getfilterlogs)
*
* `getFilterLogs` is only compatible with **event filters**.
*
* @param client - Client to use
* @param parameters - {@link GetFilterLogsParameters}
* @returns A list of event logs. {@link GetFilterLogsReturnType}
*
* @example
* import { createPublicClient, http, parseAbiItem } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createEventFilter, getFilterLogs } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const filter = await createEventFilter(client, {
* address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
* event: parseAbiItem('event Transfer(address indexed, address indexed, uint256)'),
* })
* const logs = await getFilterLogs(client, { filter })
*/
export async function getFilterLogs(_client, { filter, }) {
const strict = filter.strict ?? false;
const logs = await filter.request({
method: 'eth_getFilterLogs',
params: [filter.id],
});
const formattedLogs = logs.map((log) => formatLog(log));
if (!filter.abi)
return formattedLogs;
return parseEventLogs({
abi: filter.abi,
logs: formattedLogs,
strict,
});
}
//# sourceMappingURL=getFilterLogs.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getFilterLogs.js","sourceRoot":"","sources":["../../../actions/public/getFilterLogs.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,EAEL,SAAS,GACV,MAAM,+BAA+B,CAAA;AAiCtC;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAQjC,OAAiC,EACjC,EACE,MAAM,GAC8D;IAItE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,KAAK,CAAA;IAErC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,mBAAmB;QAC3B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;KACpB,CAAC,CAAA;IAEF,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,IAAI,CAAC,MAAM,CAAC,GAAG;QACb,OAAO,aAMN,CAAA;IACH,OAAO,cAAc,CAAC;QACpB,GAAG,EAAE,MAAM,CAAC,GAAG;QACf,IAAI,EAAE,aAAa;QACnB,MAAM;KACP,CAMA,CAAA;AACH,CAAC"}

27
node_modules/viem/_esm/actions/public/getGasPrice.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
/**
* Returns the current price of gas (in wei).
*
* - Docs: https://viem.sh/docs/actions/public/getGasPrice
* - JSON-RPC Methods: [`eth_gasPrice`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gasprice)
*
* @param client - Client to use
* @returns The gas price (in wei). {@link GetGasPriceReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getGasPrice } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const gasPrice = await getGasPrice(client)
*/
export async function getGasPrice(client) {
const gasPrice = await client.request({
method: 'eth_gasPrice',
});
return BigInt(gasPrice);
}
//# sourceMappingURL=getGasPrice.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getGasPrice.js","sourceRoot":"","sources":["../../../actions/public/getGasPrice.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAG/B,MAAyC;IACzC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACpC,MAAM,EAAE,cAAc;KACvB,CAAC,CAAA;IACF,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAA;AACzB,CAAC"}

72
node_modules/viem/_esm/actions/public/getLogs.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
import { encodeEventTopics, } from '../../utils/abi/encodeEventTopics.js';
import { parseEventLogs } from '../../utils/abi/parseEventLogs.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { formatLog, } from '../../utils/formatters/log.js';
/**
* Returns a list of event logs matching the provided parameters.
*
* - Docs: https://viem.sh/docs/actions/public/getLogs
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/logs_event-logs
* - JSON-RPC Methods: [`eth_getLogs`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getlogs)
*
* @param client - Client to use
* @param parameters - {@link GetLogsParameters}
* @returns A list of event logs. {@link GetLogsReturnType}
*
* @example
* import { createPublicClient, http, parseAbiItem } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getLogs } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const logs = await getLogs(client)
*/
export async function getLogs(client, { address, blockHash, fromBlock, toBlock, event, events: events_, args, strict: strict_, } = {}) {
const strict = strict_ ?? false;
const events = events_ ?? (event ? [event] : undefined);
let topics = [];
if (events) {
const encoded = events.flatMap((event) => encodeEventTopics({
abi: [event],
eventName: event.name,
args: events_ ? undefined : args,
}));
// TODO: Clean up type casting
topics = [encoded];
if (event)
topics = topics[0];
}
let logs;
if (blockHash) {
logs = await client.request({
method: 'eth_getLogs',
params: [{ address, topics, blockHash }],
});
}
else {
logs = await client.request({
method: 'eth_getLogs',
params: [
{
address,
topics,
fromBlock: typeof fromBlock === 'bigint' ? numberToHex(fromBlock) : fromBlock,
toBlock: typeof toBlock === 'bigint' ? numberToHex(toBlock) : toBlock,
},
],
});
}
const formattedLogs = logs.map((log) => formatLog(log));
if (!events)
return formattedLogs;
return parseEventLogs({
abi: events,
args: args,
logs: formattedLogs,
strict,
});
}
//# sourceMappingURL=getLogs.js.map

1
node_modules/viem/_esm/actions/public/getLogs.js.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"getLogs.js","sourceRoot":"","sources":["../../../actions/public/getLogs.ts"],"names":[],"mappings":"AAeA,OAAO,EAGL,iBAAiB,GAClB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAElE,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,SAAS,GACV,MAAM,+BAA+B,CAAA;AAoFtC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAW3B,MAAgC,EAChC,EACE,OAAO,EACP,SAAS,EACT,SAAS,EACT,OAAO,EACP,KAAK,EACL,MAAM,EAAE,OAAO,EACf,IAAI,EACJ,MAAM,EAAE,OAAO,MACuD,EAAE;IA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CAAC,CAAA;IACJ,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IACvD,IAAI,CAAC,MAAM;QACT,OAAO,aAMN,CAAA;IACH,OAAO,cAAc,CAAC;QACpB,GAAG,EAAE,MAAM;QACX,IAAI,EAAE,IAAW;QACjB,IAAI,EAAE,aAAa;QACnB,MAAM;KACP,CAMA,CAAA;AACH,CAAC"}

37
node_modules/viem/_esm/actions/public/getProof.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { formatProof, } from '../../utils/formatters/proof.js';
/**
* Returns the account and storage values of the specified account including the Merkle-proof.
*
* - Docs: https://viem.sh/docs/actions/public/getProof
* - JSON-RPC Methods:
* - Calls [`eth_getProof`](https://eips.ethereum.org/EIPS/eip-1186)
*
* @param client - Client to use
* @param parameters - {@link GetProofParameters}
* @returns Proof data. {@link GetProofReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getProof } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const block = await getProof(client, {
* address: '0x...',
* storageKeys: ['0x...'],
* })
*/
export async function getProof(client, { address, blockNumber, blockTag: blockTag_, storageKeys, }) {
const blockTag = blockTag_ ?? 'latest';
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
const proof = await client.request({
method: 'eth_getProof',
params: [address, storageKeys, blockNumberHex || blockTag],
});
return formatProof(proof);
}
//# sourceMappingURL=getProof.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getProof.js","sourceRoot":"","sources":["../../../actions/public/getProof.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AA+BxC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,MAAgC,EAChC,EACE,OAAO,EACP,WAAW,EACX,QAAQ,EAAE,SAAS,EACnB,WAAW,GACQ;IAErB,MAAM,QAAQ,GAAG,SAAS,IAAI,QAAQ,CAAA;IAEtC,MAAM,cAAc,GAClB,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAElE,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QACjC,MAAM,EAAE,cAAc;QACtB,MAAM,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,cAAc,IAAI,QAAQ,CAAC;KAC3D,CAAC,CAAA;IAEF,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC"}

34
node_modules/viem/_esm/actions/public/getStorageAt.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
import { numberToHex, } from '../../utils/encoding/toHex.js';
/**
* Returns the value from a storage slot at a given address.
*
* - Docs: https://viem.sh/docs/contract/getStorageAt
* - JSON-RPC Methods: [`eth_getStorageAt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getstorageat)
*
* @param client - Client to use
* @param parameters - {@link GetStorageAtParameters}
* @returns The value of the storage slot. {@link GetStorageAtReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getStorageAt } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const code = await getStorageAt(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* slot: toHex(0),
* })
*/
export async function getStorageAt(client, { address, blockNumber, blockTag = 'latest', slot }) {
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
const data = await client.request({
method: 'eth_getStorageAt',
params: [address, slot, blockNumberHex || blockTag],
});
return data;
}
//# sourceMappingURL=getStorageAt.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getStorageAt.js","sourceRoot":"","sources":["../../../actions/public/getStorageAt.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AAuBtC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAgC,EAChC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,GAAG,QAAQ,EAAE,IAAI,EAA0B;IAE3E,MAAM,cAAc,GAClB,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAClE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC;QAChC,MAAM,EAAE,kBAAkB;QAC1B,MAAM,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE,cAAc,IAAI,QAAQ,CAAC;KACpD,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC"}

View File

@@ -0,0 +1,67 @@
import { TransactionNotFoundError, } from '../../errors/transaction.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { formatTransaction, } from '../../utils/formatters/transaction.js';
/**
* Returns information about a [Transaction](https://viem.sh/docs/glossary/terms#transaction) given a hash or block identifier.
*
* - Docs: https://viem.sh/docs/actions/public/getTransaction
* - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions
* - JSON-RPC Methods: [`eth_getTransactionByHash`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionByHash)
*
* @param client - Client to use
* @param parameters - {@link GetTransactionParameters}
* @returns The transaction information. {@link GetTransactionReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getTransaction } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const transaction = await getTransaction(client, {
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
* })
*/
export async function getTransaction(client, { blockHash, blockNumber, blockTag: blockTag_, hash, index, sender, nonce, }) {
const blockTag = blockTag_ || 'latest';
const blockNumberHex = blockNumber !== undefined ? numberToHex(blockNumber) : undefined;
let transaction = null;
if (hash) {
transaction = await client.request({
method: 'eth_getTransactionByHash',
params: [hash],
}, { dedupe: true });
}
else if (blockHash) {
transaction = await client.request({
method: 'eth_getTransactionByBlockHashAndIndex',
params: [blockHash, numberToHex(index)],
}, { dedupe: true });
}
else if ((blockNumberHex || blockTag) && typeof index === 'number') {
transaction = await client.request({
method: 'eth_getTransactionByBlockNumberAndIndex',
params: [blockNumberHex || blockTag, numberToHex(index)],
}, { dedupe: Boolean(blockNumberHex) });
}
else if (sender && typeof nonce === 'number') {
transaction = await client.request({
method: 'eth_getTransactionBySenderAndNonce',
params: [sender, numberToHex(nonce)],
}, { dedupe: true });
}
if (!transaction)
throw new TransactionNotFoundError({
blockHash,
blockNumber,
blockTag,
hash,
index,
});
const format = client.chain?.formatters?.transaction?.format || formatTransaction;
return format(transaction, 'getTransaction');
}
//# sourceMappingURL=getTransaction.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getTransaction.js","sourceRoot":"","sources":["../../../actions/public/getTransaction.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,wBAAwB,GAEzB,MAAM,6BAA6B,CAAA;AAQpC,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAEL,iBAAiB,GAClB,MAAM,uCAAuC,CAAA;AAkD9C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAIlC,MAAgC,EAChC,EACE,SAAS,EACT,WAAW,EACX,QAAQ,EAAE,SAAS,EACnB,IAAI,EACJ,KAAK,EACL,MAAM,EACN,KAAK,GAC8B;IAErC,MAAM,QAAQ,GAAG,SAAS,IAAI,QAAQ,CAAA;IAEtC,MAAM,cAAc,GAClB,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X,QAAQ;YACR,IAAI;YACJ,KAAK;SACN,CAAC,CAAA;IAEJ,MAAM,MAAM,GACV,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,IAAI,iBAAiB,CAAA;IACpE,OAAO,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAA;AAC9C,CAAC"}

View File

@@ -0,0 +1,40 @@
import { getAction } from '../../utils/getAction.js';
import { getBlockNumber, } from './getBlockNumber.js';
import { getTransaction, } from './getTransaction.js';
/**
* Returns the number of blocks passed (confirmations) since the transaction was processed on a block.
*
* - Docs: https://viem.sh/docs/actions/public/getTransactionConfirmations
* - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions
* - JSON-RPC Methods: [`eth_getTransactionConfirmations`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionConfirmations)
*
* @param client - Client to use
* @param parameters - {@link GetTransactionConfirmationsParameters}
* @returns The number of blocks passed since the transaction was processed. If confirmations is 0, then the Transaction has not been confirmed & processed yet. {@link GetTransactionConfirmationsReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getTransactionConfirmations } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const confirmations = await getTransactionConfirmations(client, {
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
* })
*/
export async function getTransactionConfirmations(client, { hash, transactionReceipt }) {
const [blockNumber, transaction] = await Promise.all([
getAction(client, getBlockNumber, 'getBlockNumber')({}),
hash
? getAction(client, getTransaction, 'getTransaction')({ hash })
: undefined,
]);
const transactionBlockNumber = transactionReceipt?.blockNumber || transaction?.blockNumber;
if (!transactionBlockNumber)
return 0n;
return blockNumber - transactionBlockNumber + 1n;
}
//# sourceMappingURL=getTransactionConfirmations.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getTransactionConfirmations.js","sourceRoot":"","sources":["../../../actions/public/getTransactionConfirmations.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAEL,cAAc,GACf,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAEL,cAAc,GACf,MAAM,qBAAqB,CAAA;AAuB5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAG/C,MAAgC,EAChC,EAAE,IAAI,EAAE,kBAAkB,EAAgD;IAE1E,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACnD,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC,EAAE,CAAC;QACvD,IAAI;YACF,CAAC,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,EAAE,gBAAgB,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;YAC/D,CAAC,CAAC,SAAS;KACd,CAAC,CAAA;IACF,MAAM,sBAAsB,GAC1B,kBAAkB,EAAE,WAAW,IAAI,WAAW,EAAE,WAAW,CAAA;IAC7D,IAAI,CAAC,sBAAsB;QAAE,OAAO,EAAE,CAAA;IACtC,OAAO,WAAW,GAAG,sBAAuB,GAAG,EAAE,CAAA;AACnD,CAAC"}

View File

@@ -0,0 +1,38 @@
import { hexToNumber, } from '../../utils/encoding/fromHex.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
/**
* Returns the number of [Transactions](https://viem.sh/docs/glossary/terms#transaction) an Account has sent.
*
* - Docs: https://viem.sh/docs/actions/public/getTransactionCount
* - JSON-RPC Methods: [`eth_getTransactionCount`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount)
*
* @param client - Client to use
* @param parameters - {@link GetTransactionCountParameters}
* @returns The number of transactions an account has sent. {@link GetTransactionCountReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getTransactionCount } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const transactionCount = await getTransactionCount(client, {
* address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
*/
export async function getTransactionCount(client, { address, blockTag = 'latest', blockNumber }) {
const count = await client.request({
method: 'eth_getTransactionCount',
params: [
address,
typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : blockTag,
],
}, {
dedupe: Boolean(blockNumber),
});
return hexToNumber(count);
}
//# sourceMappingURL=getTransactionCount.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getTransactionCount.js","sourceRoot":"","sources":["../../../actions/public/getTransactionCount.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AAyBtC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAIvC,MAAyC,EACzC,EAAE,OAAO,EAAE,QAAQ,GAAG,QAAQ,EAAE,WAAW,EAAiC;IAE5E,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,OAAO,CAChC;QACE,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE;YACN,OAAO;YACP,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ;SACtE;KACF,EACD;QACE,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC;KAC7B,CACF,CAAA;IACD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAA;AAC3B,CAAC"}

View File

@@ -0,0 +1,38 @@
import { TransactionReceiptNotFoundError, } from '../../errors/transaction.js';
import { formatTransactionReceipt, } from '../../utils/formatters/transactionReceipt.js';
/**
* Returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms#transaction-receipt) given a [Transaction](https://viem.sh/docs/glossary/terms#transaction) hash.
*
* - Docs: https://viem.sh/docs/actions/public/getTransactionReceipt
* - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_fetching-transactions
* - JSON-RPC Methods: [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt)
*
* @param client - Client to use
* @param parameters - {@link GetTransactionReceiptParameters}
* @returns The transaction receipt. {@link GetTransactionReceiptReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { getTransactionReceipt } from 'viem/public'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const transactionReceipt = await getTransactionReceipt(client, {
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
* })
*/
export async function getTransactionReceipt(client, { hash }) {
const receipt = await client.request({
method: 'eth_getTransactionReceipt',
params: [hash],
}, { dedupe: true });
if (!receipt)
throw new TransactionReceiptNotFoundError({ hash });
const format = client.chain?.formatters?.transactionReceipt?.format ||
formatTransactionReceipt;
return format(receipt, 'getTransactionReceipt');
}
//# sourceMappingURL=getTransactionReceipt.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"getTransactionReceipt.js","sourceRoot":"","sources":["../../../actions/public/getTransactionReceipt.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,+BAA+B,GAEhC,MAAM,6BAA6B,CAAA;AAKpC,OAAO,EAEL,wBAAwB,GACzB,MAAM,8CAA8C,CAAA;AAgBrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,MAAgC,EAChC,EAAE,IAAI,EAAmC;IAEzC,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAClC;QACE,MAAM,EAAE,2BAA2B;QACnC,MAAM,EAAE,CAAC,IAAI,CAAC;KACf,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAA;IAED,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,+BAA+B,CAAC,EAAE,IAAI,EAAE,CAAC,CAAA;IAEjE,MAAM,MAAM,GACV,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM;QACpD,wBAAwB,CAAA;IAC1B,OAAO,MAAM,CACX,OAAO,EACP,uBAAuB,CACkB,CAAA;AAC7C,CAAC"}

191
node_modules/viem/_esm/actions/public/multicall.js generated vendored Normal file
View File

@@ -0,0 +1,191 @@
import { multicall3Abi } from '../../constants/abis.js';
import { multicall3Bytecode } from '../../constants/contracts.js';
import { AbiDecodingZeroDataError } from '../../errors/abi.js';
import { BaseError } from '../../errors/base.js';
import { RawContractError } from '../../errors/contract.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getChainContractAddress, } from '../../utils/chain/getChainContractAddress.js';
import { getContractError, } from '../../utils/errors/getContractError.js';
import { getAction } from '../../utils/getAction.js';
import { readContract } from './readContract.js';
/**
* Similar to [`readContract`](https://viem.sh/docs/contract/readContract), but batches up multiple functions on a contract in a single RPC call via the [`multicall3` contract](https://github.com/mds1/multicall).
*
* - Docs: https://viem.sh/docs/contract/multicall
*
* @param client - Client to use
* @param parameters - {@link MulticallParameters}
* @returns An array of results with accompanying status. {@link MulticallReturnType}
*
* @example
* import { createPublicClient, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
* import { multicall } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const abi = parseAbi([
* 'function balanceOf(address) view returns (uint256)',
* 'function totalSupply() view returns (uint256)',
* ])
* const results = await multicall(client, {
* contracts: [
* {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi,
* functionName: 'balanceOf',
* args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
* },
* {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi,
* functionName: 'totalSupply',
* },
* ],
* })
* // [{ result: 424122n, status: 'success' }, { result: 1000000n, status: 'success' }]
*/
export async function multicall(client, parameters) {
const { account, authorizationList, allowFailure = true, blockNumber, blockOverrides, blockTag, stateOverride, } = parameters;
const contracts = parameters.contracts;
const { batchSize = parameters.batchSize ?? 1024, deployless = parameters.deployless ?? false, } = typeof client.batch?.multicall === 'object' ? client.batch.multicall : {};
const multicallAddress = (() => {
if (parameters.multicallAddress)
return parameters.multicallAddress;
if (deployless)
return null;
if (client.chain) {
return getChainContractAddress({
blockNumber,
chain: client.chain,
contract: 'multicall3',
});
}
throw new Error('client chain not configured. multicallAddress is required.');
})();
const chunkedCalls = [[]];
let currentChunk = 0;
let currentChunkSize = 0;
for (let i = 0; i < contracts.length; i++) {
const { abi, address, args, functionName } = contracts[i];
try {
const callData = encodeFunctionData({ abi, args, functionName });
currentChunkSize += (callData.length - 2) / 2;
// Check to see if we need to create a new chunk.
if (
// Check if batching is enabled.
batchSize > 0 &&
// Check if the current size of the batch exceeds the size limit.
currentChunkSize > batchSize &&
// Check if the current chunk is not already empty.
chunkedCalls[currentChunk].length > 0) {
currentChunk++;
currentChunkSize = (callData.length - 2) / 2;
chunkedCalls[currentChunk] = [];
}
chunkedCalls[currentChunk] = [
...chunkedCalls[currentChunk],
{
allowFailure: true,
callData,
target: address,
},
];
}
catch (err) {
const error = getContractError(err, {
abi,
address,
args,
docsPath: '/docs/contract/multicall',
functionName,
sender: account,
});
if (!allowFailure)
throw error;
chunkedCalls[currentChunk] = [
...chunkedCalls[currentChunk],
{
allowFailure: true,
callData: '0x',
target: address,
},
];
}
}
const aggregate3Results = await Promise.allSettled(chunkedCalls.map((calls) => getAction(client, readContract, 'readContract')({
...(multicallAddress === null
? { code: multicall3Bytecode }
: { address: multicallAddress }),
abi: multicall3Abi,
account,
args: [calls],
authorizationList,
blockNumber,
blockOverrides,
blockTag,
functionName: 'aggregate3',
stateOverride,
})));
const results = [];
for (let i = 0; i < aggregate3Results.length; i++) {
const result = aggregate3Results[i];
// If an error occurred in a `readContract` invocation (ie. network error),
// then append the failure reason to each contract result.
if (result.status === 'rejected') {
if (!allowFailure)
throw result.reason;
for (let j = 0; j < chunkedCalls[i].length; j++) {
results.push({
status: 'failure',
error: result.reason,
result: undefined,
});
}
continue;
}
// If the `readContract` call was successful, then decode the results.
const aggregate3Result = result.value;
for (let j = 0; j < aggregate3Result.length; j++) {
// Extract the response from `readContract`
const { returnData, success } = aggregate3Result[j];
// Extract the request call data from the original call.
const { callData } = chunkedCalls[i][j];
// Extract the contract config for this call from the `contracts` argument
// for decoding.
const { abi, address, functionName, args } = contracts[results.length];
try {
if (callData === '0x')
throw new AbiDecodingZeroDataError();
if (!success)
throw new RawContractError({ data: returnData });
const result = decodeFunctionResult({
abi,
args,
data: returnData,
functionName,
});
results.push(allowFailure ? { result, status: 'success' } : result);
}
catch (err) {
const error = getContractError(err, {
abi,
address,
args,
docsPath: '/docs/contract/multicall',
functionName,
});
if (!allowFailure)
throw error;
results.push({ error, result: undefined, status: 'failure' });
}
}
}
if (results.length !== contracts.length)
throw new BaseError('multicall results mismatch');
return results;
}
//# sourceMappingURL=multicall.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"multicall.js","sourceRoot":"","sources":["../../../actions/public/multicall.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAS3D,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAEL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAEL,uBAAuB,GACxB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAEL,gBAAgB,GAC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C9B,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAA;YAC/D,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,MAAM;QACrC,MAAM,IAAI,SAAS,CAAC,4BAA4B,CAAC,CAAA;IACnD,OAAO,OAAuD,CAAA;AAChE,CAAC"}

67
node_modules/viem/_esm/actions/public/readContract.js generated vendored Normal file
View File

@@ -0,0 +1,67 @@
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getContractError, } from '../../utils/errors/getContractError.js';
import { getAction } from '../../utils/getAction.js';
import { call } from './call.js';
/**
* Calls a read-only function on a contract, and returns the response.
*
* - Docs: https://viem.sh/docs/contract/readContract
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts_reading-contracts
*
* A "read-only" function (constant function) on a Solidity contract is denoted by a `view` or `pure` keyword. They can only read the state of the contract, and cannot make any changes to it. Since read-only methods do not change the state of the contract, they do not require any gas to be executed, and can be called by any user without the need to pay for gas.
*
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
*
* @param client - Client to use
* @param parameters - {@link ReadContractParameters}
* @returns The response from the contract. Type is inferred. {@link ReadContractReturnType}
*
* @example
* import { createPublicClient, http, parseAbi } from 'viem'
* import { mainnet } from 'viem/chains'
* import { readContract } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const result = await readContract(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi: parseAbi(['function balanceOf(address) view returns (uint256)']),
* functionName: 'balanceOf',
* args: ['0xA0Cf798816D4b9b9866b5330EEa46a18382f251e'],
* })
* // 424122n
*/
export async function readContract(client, parameters) {
const { abi, address, args, functionName, ...rest } = parameters;
const calldata = encodeFunctionData({
abi,
args,
functionName,
});
try {
const { data } = await getAction(client, call, 'call')({
...rest,
data: calldata,
to: address,
});
return decodeFunctionResult({
abi,
args,
functionName,
data: data || '0x',
});
}
catch (error) {
throw getContractError(error, {
abi,
address,
args,
docsPath: '/docs/contract/readContract',
functionName,
});
}
}
//# sourceMappingURL=readContract.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"readContract.js","sourceRoot":"","sources":["../../../actions/public/readContract.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAGL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAEL,gBAAgB,GACjB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAA2C,IAAI,EAAE,MAAM,WAAW,CAAA;AA6CzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAMhC,MAAgC,EAChC,UAA2D;IAE3D,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GACjD,UAAoC,CAAA;IACtC,MAAM,QAAQ,GAAG,kBAAkB,CAAC;QAClC,GAAG;QACH,IAAI;QACJ,YAAY;KACmB,CAAC,CAAA;IAClC,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,SAAS,CAC9B,MAAM,EACN,IAAI,EACJ,MAAM,CACP,CAAC;YACA,GAAI,IAAuB;YAC3B,IAAI,EAAE,QAAQ;YACd,EAAE,EAAE,OAAQ;SACb,CAAC,CAAA;QACF,OAAO,oBAAoB,CAAC;YAC1B,GAAG;YACH,IAAI;YACJ,YAAY;YACZ,IAAI,EAAE,IAAI,IAAI,IAAI;SACnB,CAA8C,CAAA;IACjD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,gBAAgB,CAAC,KAAkB,EAAE;YACzC,GAAG;YACH,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,6BAA6B;YACvC,YAAY;SACb,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}

157
node_modules/viem/_esm/actions/public/simulateBlocks.js generated vendored Normal file
View File

@@ -0,0 +1,157 @@
import * as BlockOverrides from 'ox/BlockOverrides';
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { AbiDecodingZeroDataError } from '../../errors/abi.js';
import { RawContractError } from '../../errors/contract.js';
import { UnknownNodeError } from '../../errors/node.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { concat } from '../../utils/data/concat.js';
import { numberToHex, } from '../../utils/encoding/toHex.js';
import { getContractError } from '../../utils/errors/getContractError.js';
import { getNodeError, } from '../../utils/errors/getNodeError.js';
import { formatBlock, } from '../../utils/formatters/block.js';
import { formatLog } from '../../utils/formatters/log.js';
import { formatTransactionRequest, } from '../../utils/formatters/transactionRequest.js';
import { serializeStateOverride, } from '../../utils/stateOverride.js';
import { assertRequest, } from '../../utils/transaction/assertRequest.js';
/**
* Simulates a set of calls on block(s) with optional block and state overrides.
*
* @example
* ```ts
* import { createClient, http, parseEther } from 'viem'
* import { simulate } from 'viem/actions'
* import { mainnet } from 'viem/chains'
*
* const client = createClient({
* chain: mainnet,
* transport: http(),
* })
*
* const result = await simulate(client, {
* blocks: [{
* blockOverrides: {
* number: 69420n,
* },
* calls: [{
* {
* account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* {
* account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* },
* }],
* stateOverrides: [{
* address: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
* balance: parseEther('10'),
* }],
* }]
* })
* ```
*
* @param client - Client to use.
* @param parameters - {@link SimulateBlocksParameters}
* @returns Simulated blocks. {@link SimulateBlocksReturnType}
*/
export async function simulateBlocks(client, parameters) {
const { blockNumber, blockTag = client.experimental_blockTag ?? 'latest', blocks, returnFullTransactions, traceTransfers, validation, } = parameters;
try {
const blockStateCalls = [];
for (const block of blocks) {
const blockOverrides = block.blockOverrides
? BlockOverrides.toRpc(block.blockOverrides)
: undefined;
const calls = block.calls.map((call_) => {
const call = call_;
const account = call.account ? parseAccount(call.account) : undefined;
const data = call.abi ? encodeFunctionData(call) : call.data;
const request = {
...call,
account,
data: call.dataSuffix
? concat([data || '0x', call.dataSuffix])
: data,
from: call.from ?? account?.address,
};
assertRequest(request);
return formatTransactionRequest(request);
});
const stateOverrides = block.stateOverrides
? serializeStateOverride(block.stateOverrides)
: undefined;
blockStateCalls.push({
blockOverrides,
calls,
stateOverrides,
});
}
const blockNumberHex = typeof blockNumber === 'bigint' ? numberToHex(blockNumber) : undefined;
const block = blockNumberHex || blockTag;
const result = await client.request({
method: 'eth_simulateV1',
params: [
{ blockStateCalls, returnFullTransactions, traceTransfers, validation },
block,
],
});
return result.map((block, i) => ({
...formatBlock(block),
calls: block.calls.map((call, j) => {
const { abi, args, functionName, to } = blocks[i].calls[j];
const data = call.error?.data ?? call.returnData;
const gasUsed = BigInt(call.gasUsed);
const logs = call.logs?.map((log) => formatLog(log));
const status = call.status === '0x1' ? 'success' : 'failure';
const result = abi && status === 'success' && data !== '0x'
? decodeFunctionResult({
abi,
data,
functionName,
})
: null;
const error = (() => {
if (status === 'success')
return undefined;
let error;
if (data === '0x')
error = new AbiDecodingZeroDataError();
else if (data)
error = new RawContractError({ data });
if (!error)
return undefined;
return getContractError(error, {
abi: (abi ?? []),
address: to ?? '0x',
args,
functionName: functionName ?? '<unknown>',
});
})();
return {
data,
gasUsed,
logs,
status,
...(status === 'success'
? {
result,
}
: {
error,
}),
};
}),
}));
}
catch (e) {
const cause = e;
const error = getNodeError(cause, {});
if (error instanceof UnknownNodeError)
throw cause;
throw error;
}
}
//# sourceMappingURL=simulateBlocks.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"simulateBlocks.js","sourceRoot":"","sources":["../../../actions/public/simulateBlocks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,cAAc,MAAM,mBAAmB,CAAA;AAEnD,OAAO,EAEL,YAAY,GACb,MAAM,sCAAsC,CAAA;AAG7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAYvD,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAEL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAEL,WAAW,GACZ,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AACzE,OAAO,EAEL,YAAY,GACb,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EAEL,WAAW,GACZ,MAAM,iCAAiC,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAEL,wBAAwB,GACzB,MAAM,8CAA8C,CAAA;AACrD,OAAO,EAEL,sBAAsB,GACvB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAEL,aAAa,GACd,MAAM,0CAA0C,CAAA;AA8EjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAIlC,MAAgC,EAChC,UAA2C;IAE3C,MAAM,EACJ,WAA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AAA;IACb,CAAC;AACH,CAAC"}

255
node_modules/viem/_esm/actions/public/simulateCalls.js generated vendored Normal file
View File

@@ -0,0 +1,255 @@
import * as AbiConstructor from 'ox/AbiConstructor';
import * as AbiFunction from 'ox/AbiFunction';
import { parseAccount } from '../../accounts/utils/parseAccount.js';
import { ethAddress, zeroAddress } from '../../constants/address.js';
import { deploylessCallViaBytecodeBytecode } from '../../constants/contracts.js';
import { BaseError } from '../../errors/base.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { hexToBigInt } from '../../utils/index.js';
import { createAccessList, } from './createAccessList.js';
import { simulateBlocks, } from './simulateBlocks.js';
const getBalanceCode = '0x6080604052348015600e575f80fd5b5061016d8061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610029575f3560e01c8063f8b2cb4f1461002d575b5f80fd5b610047600480360381019061004291906100db565b61005d565b604051610054919061011e565b60405180910390f35b5f8173ffffffffffffffffffffffffffffffffffffffff16319050919050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6100aa82610081565b9050919050565b6100ba816100a0565b81146100c4575f80fd5b50565b5f813590506100d5816100b1565b92915050565b5f602082840312156100f0576100ef61007d565b5b5f6100fd848285016100c7565b91505092915050565b5f819050919050565b61011881610106565b82525050565b5f6020820190506101315f83018461010f565b9291505056fea26469706673582212203b9fe929fe995c7cf9887f0bdba8a36dd78e8b73f149b17d2d9ad7cd09d2dc6264736f6c634300081a0033';
/**
* Simulates execution of a batch of calls.
*
* @param client - Client to use
* @param parameters - {@link SimulateCallsParameters}
* @returns Results. {@link SimulateCallsReturnType}
*
* @example
* ```ts
* import { createPublicClient, http, parseEther } from 'viem'
* import { mainnet } from 'viem/chains'
* import { simulateCalls } from 'viem/actions'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
*
* const result = await simulateCalls(client, {
* account: '0x5a0b54d5dc17e482fe8b0bdca5320161b95fb929',
* calls: [{
* {
* data: '0xdeadbeef',
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* },
* {
* to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
* value: parseEther('1'),
* },
* ]
* })
* ```
*/
export async function simulateCalls(client, parameters) {
const { blockNumber, blockTag, calls, stateOverrides, traceAssetChanges, traceTransfers, validation, } = parameters;
const account = parameters.account
? parseAccount(parameters.account)
: undefined;
if (traceAssetChanges && !account)
throw new BaseError('`account` is required when `traceAssetChanges` is true');
// Derive bytecode to extract ETH balance via a contract call.
const getBalanceData = account
? AbiConstructor.encode(AbiConstructor.from('constructor(bytes, bytes)'), {
bytecode: deploylessCallViaBytecodeBytecode,
args: [
getBalanceCode,
AbiFunction.encodeData(AbiFunction.from('function getBalance(address)'), [account.address]),
],
})
: undefined;
// Fetch ERC20/721 addresses that were "touched" from the calls.
const assetAddresses = traceAssetChanges
? await Promise.all(parameters.calls.map(async (call) => {
if (!call.data && !call.abi)
return;
const { accessList } = await createAccessList(client, {
account: account.address,
...call,
data: call.abi ? encodeFunctionData(call) : call.data,
});
return accessList.map(({ address, storageKeys }) => storageKeys.length > 0 ? address : null);
})).then((x) => x.flat().filter(Boolean))
: [];
const blocks = await simulateBlocks(client, {
blockNumber,
blockTag: blockTag,
blocks: [
...(traceAssetChanges
? [
// ETH pre balances
{
calls: [{ data: getBalanceData }],
stateOverrides,
},
// Asset pre balances
{
calls: assetAddresses.map((address, i) => ({
abi: [
AbiFunction.from('function balanceOf(address) returns (uint256)'),
],
functionName: 'balanceOf',
args: [account.address],
to: address,
from: zeroAddress,
nonce: i,
})),
stateOverrides: [
{
address: zeroAddress,
nonce: 0,
},
],
},
]
: []),
{
calls: [...calls, { to: zeroAddress }].map((call) => ({
...call,
from: account?.address,
})),
stateOverrides,
},
...(traceAssetChanges
? [
// ETH post balances
{
calls: [{ data: getBalanceData }],
},
// Asset post balances
{
calls: assetAddresses.map((address, i) => ({
abi: [
AbiFunction.from('function balanceOf(address) returns (uint256)'),
],
functionName: 'balanceOf',
args: [account.address],
to: address,
from: zeroAddress,
nonce: i,
})),
stateOverrides: [
{
address: zeroAddress,
nonce: 0,
},
],
},
// Decimals
{
calls: assetAddresses.map((address, i) => ({
to: address,
abi: [
AbiFunction.from('function decimals() returns (uint256)'),
],
functionName: 'decimals',
from: zeroAddress,
nonce: i,
})),
stateOverrides: [
{
address: zeroAddress,
nonce: 0,
},
],
},
// Token URI
{
calls: assetAddresses.map((address, i) => ({
to: address,
abi: [
AbiFunction.from('function tokenURI(uint256) returns (string)'),
],
functionName: 'tokenURI',
args: [0n],
from: zeroAddress,
nonce: i,
})),
stateOverrides: [
{
address: zeroAddress,
nonce: 0,
},
],
},
// Symbols
{
calls: assetAddresses.map((address, i) => ({
to: address,
abi: [AbiFunction.from('function symbol() returns (string)')],
functionName: 'symbol',
from: zeroAddress,
nonce: i,
})),
stateOverrides: [
{
address: zeroAddress,
nonce: 0,
},
],
},
]
: []),
],
traceTransfers,
validation,
});
const block_results = traceAssetChanges ? blocks[2] : blocks[0];
const [block_ethPre, block_assetsPre, , block_ethPost, block_assetsPost, block_decimals, block_tokenURI, block_symbols,] = traceAssetChanges ? blocks : [];
// Extract call results from the simulation.
const { calls: block_calls, ...block } = block_results;
const results = block_calls.slice(0, -1) ?? [];
// Extract pre-execution ETH and asset balances.
const ethPre = block_ethPre?.calls ?? [];
const assetsPre = block_assetsPre?.calls ?? [];
const balancesPre = [...ethPre, ...assetsPre].map((call) => call.status === 'success' ? hexToBigInt(call.data) : null);
// Extract post-execution ETH and asset balances.
const ethPost = block_ethPost?.calls ?? [];
const assetsPost = block_assetsPost?.calls ?? [];
const balancesPost = [...ethPost, ...assetsPost].map((call) => call.status === 'success' ? hexToBigInt(call.data) : null);
// Extract asset symbols & decimals.
const decimals = (block_decimals?.calls ?? []).map((x) => x.status === 'success' ? x.result : null);
const symbols = (block_symbols?.calls ?? []).map((x) => x.status === 'success' ? x.result : null);
const tokenURI = (block_tokenURI?.calls ?? []).map((x) => x.status === 'success' ? x.result : null);
const changes = [];
for (const [i, balancePost] of balancesPost.entries()) {
const balancePre = balancesPre[i];
if (typeof balancePost !== 'bigint')
continue;
if (typeof balancePre !== 'bigint')
continue;
const decimals_ = decimals[i - 1];
const symbol_ = symbols[i - 1];
const tokenURI_ = tokenURI[i - 1];
const token = (() => {
if (i === 0)
return {
address: ethAddress,
decimals: 18,
symbol: 'ETH',
};
return {
address: assetAddresses[i - 1],
decimals: tokenURI_ || decimals_ ? Number(decimals_ ?? 1) : undefined,
symbol: symbol_ ?? undefined,
};
})();
if (changes.some((change) => change.token.address === token.address))
continue;
changes.push({
token,
value: {
pre: balancePre,
post: balancePost,
diff: balancePost - balancePre,
},
});
}
return {
assetChanges: changes,
block,
results,
};
}
//# sourceMappingURL=simulateCalls.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,85 @@
import { parseAccount, } from '../../accounts/utils/parseAccount.js';
import { decodeFunctionResult, } from '../../utils/abi/decodeFunctionResult.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getContractError, } from '../../utils/errors/getContractError.js';
import { getAction } from '../../utils/getAction.js';
import { call } from './call.js';
/**
* Simulates/validates a contract interaction. This is useful for retrieving **return data** and **revert reasons** of contract write functions.
*
* - Docs: https://viem.sh/docs/contract/simulateContract
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/contracts_writing-to-contracts
*
* This function does not require gas to execute and _**does not**_ change the state of the blockchain. It is almost identical to [`readContract`](https://viem.sh/docs/contract/readContract), but also supports contract write functions.
*
* Internally, uses a [Public Client](https://viem.sh/docs/clients/public) to call the [`call` action](https://viem.sh/docs/actions/public/call) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData).
*
* @param client - Client to use
* @param parameters - {@link SimulateContractParameters}
* @returns The simulation result and write request. {@link SimulateContractReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { simulateContract } from 'viem/contract'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const result = await simulateContract(client, {
* address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2',
* abi: parseAbi(['function mint(uint32) view returns (uint32)']),
* functionName: 'mint',
* args: ['69420'],
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
* })
*/
export async function simulateContract(client, parameters) {
const { abi, address, args, functionName, dataSuffix = typeof client.dataSuffix === 'string'
? client.dataSuffix
: client.dataSuffix?.value, ...callRequest } = parameters;
const account = callRequest.account
? parseAccount(callRequest.account)
: client.account;
const calldata = encodeFunctionData({ abi, args, functionName });
try {
const { data } = await getAction(client, call, 'call')({
batch: false,
data: `${calldata}${dataSuffix ? dataSuffix.replace('0x', '') : ''}`,
to: address,
...callRequest,
account,
});
const result = decodeFunctionResult({
abi,
args,
functionName,
data: data || '0x',
});
const minimizedAbi = abi.filter((abiItem) => 'name' in abiItem && abiItem.name === parameters.functionName);
return {
result,
request: {
abi: minimizedAbi,
address,
args,
dataSuffix,
functionName,
...callRequest,
account,
},
};
}
catch (error) {
throw getContractError(error, {
abi,
address,
args,
docsPath: '/docs/contract/simulateContract',
functionName,
sender: account?.address,
});
}
}
//# sourceMappingURL=simulateContract.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"simulateContract.js","sourceRoot":"","sources":["../../../actions/public/simulateContract.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,YAAY,GACb,MAAM,sCAAsC,CAAA;AAuB7C,OAAO,EAEL,oBAAoB,GACrB,MAAM,yCAAyC,CAAA;AAChD,OAAO,EAEL,kBAAkB,GACnB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAEL,gBAAgB,GACjB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAA2C,IAAI,EAAE,MAAM,WAAW,CAAA;AAsJzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAapC,MAAy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,GAAG,WAAW;gBACd,OAAO;aACR;SASF,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,gBAAgB,CAAC,KAAkB,EAAE;YACzC,GAAG;YACH,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,iCAAiC;YAC3C,YAAY;YACZ,MAAM,EAAE,OAAO,EAAE,OAAO;SACzB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC"}

View File

@@ -0,0 +1,31 @@
/**
* Destroys a [`Filter`](https://viem.sh/docs/glossary/types#filter).
*
* - Docs: https://viem.sh/docs/actions/public/uninstallFilter
* - JSON-RPC Methods: [`eth_uninstallFilter`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_uninstallFilter)
*
* Destroys a Filter that was created from one of the following Actions:
* - [`createBlockFilter`](https://viem.sh/docs/actions/public/createBlockFilter)
* - [`createEventFilter`](https://viem.sh/docs/actions/public/createEventFilter)
* - [`createPendingTransactionFilter`](https://viem.sh/docs/actions/public/createPendingTransactionFilter)
*
* @param client - Client to use
* @param parameters - {@link UninstallFilterParameters}
* @returns A boolean indicating if the Filter was successfully uninstalled. {@link UninstallFilterReturnType}
*
* @example
* import { createPublicClient, http } from 'viem'
* import { mainnet } from 'viem/chains'
* import { createPendingTransactionFilter, uninstallFilter } from 'viem/public'
*
* const filter = await createPendingTransactionFilter(client)
* const uninstalled = await uninstallFilter(client, { filter })
* // true
*/
export async function uninstallFilter(_client, { filter }) {
return filter.request({
method: 'eth_uninstallFilter',
params: [filter.id],
});
}
//# sourceMappingURL=uninstallFilter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"uninstallFilter.js","sourceRoot":"","sources":["../../../actions/public/uninstallFilter.ts"],"names":[],"mappings":"AAcA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAInC,OAAiC,EACjC,EAAE,MAAM,EAA6B;IAErC,OAAO,MAAM,CAAC,OAAO,CAAC;QACpB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;KACpB,CAAC,CAAA;AACJ,CAAC"}

221
node_modules/viem/_esm/actions/public/verifyHash.js generated vendored Normal file
View File

@@ -0,0 +1,221 @@
import { SignatureErc6492 } from 'ox/erc6492';
import { SignatureErc8010 } from 'ox/erc8010';
import { erc1271Abi, erc6492SignatureValidatorAbi, multicall3Abi, } from '../../constants/abis.js';
import { erc6492SignatureValidatorByteCode, multicall3Bytecode, } from '../../constants/contracts.js';
import { CallExecutionError, ContractFunctionExecutionError, } from '../../errors/contract.js';
import { encodeDeployData, } from '../../utils/abi/encodeDeployData.js';
import { encodeFunctionData, } from '../../utils/abi/encodeFunctionData.js';
import { getAddress, } from '../../utils/address/getAddress.js';
import { isAddressEqual, } from '../../utils/address/isAddressEqual.js';
import { verifyAuthorization } from '../../utils/authorization/verifyAuthorization.js';
import { concatHex } from '../../utils/data/concat.js';
import { isHex } from '../../utils/data/isHex.js';
import { hexToBool } from '../../utils/encoding/fromHex.js';
import { bytesToHex, numberToHex, } from '../../utils/encoding/toHex.js';
import { getAction } from '../../utils/getAction.js';
import { recoverAddress, } from '../../utils/signature/recoverAddress.js';
import { serializeSignature, } from '../../utils/signature/serializeSignature.js';
import { call } from './call.js';
import { getCode } from './getCode.js';
import { readContract } from './readContract.js';
/**
* Verifies a message hash onchain using ERC-6492.
*
* @param client - Client to use.
* @param parameters - {@link VerifyHashParameters}
* @returns Whether or not the signature is valid. {@link VerifyHashReturnType}
*/
export async function verifyHash(client, parameters) {
const { address, chain = client.chain, hash, erc6492VerifierAddress: verifierAddress = parameters.universalSignatureVerifierAddress ??
chain?.contracts?.erc6492Verifier?.address, multicallAddress = parameters.multicallAddress ??
chain?.contracts?.multicall3?.address, mode = 'auto', } = parameters;
if (chain?.verifyHash)
return await chain.verifyHash(client, parameters);
const signature = (() => {
const signature = parameters.signature;
if (isHex(signature))
return signature;
if (typeof signature === 'object' && 'r' in signature && 's' in signature)
return serializeSignature(signature);
return bytesToHex(signature);
})();
try {
if (mode === 'eoa') {
try {
const verified = isAddressEqual(getAddress(address), await recoverAddress({ hash, signature }));
if (verified)
return true;
}
catch { }
}
if (SignatureErc8010.validate(signature))
return await verifyErc8010(client, {
...parameters,
multicallAddress,
signature,
});
return await verifyErc6492(client, {
...parameters,
verifierAddress,
signature,
});
}
catch (error) {
if (mode !== 'eoa') {
// Fallback attempt to verify the signature via ECDSA recovery.
try {
const verified = isAddressEqual(getAddress(address), await recoverAddress({ hash, signature }));
if (verified)
return true;
}
catch { }
}
if (error instanceof VerificationError) {
// if the execution fails, the signature was not valid and an internal method inside of the validator reverted
// this can happen for many reasons, for example if signer can not be recovered from the signature
// or if the signature has no valid format
return false;
}
throw error;
}
}
/** @internal */
export async function verifyErc8010(client, parameters) {
const { address, blockNumber, blockTag, hash, multicallAddress } = parameters;
const { authorization: authorization_ox, data: initData, signature, to, } = SignatureErc8010.unwrap(parameters.signature);
// Check if already delegated
const code = await getCode(client, {
address,
blockNumber,
blockTag,
});
// If already delegated, perform standard ERC-1271 verification.
if (code === concatHex(['0xef0100', authorization_ox.address]))
return await verifyErc1271(client, {
address,
blockNumber,
blockTag,
hash,
signature,
});
const authorization = {
address: authorization_ox.address,
chainId: Number(authorization_ox.chainId),
nonce: Number(authorization_ox.nonce),
r: numberToHex(authorization_ox.r, { size: 32 }),
s: numberToHex(authorization_ox.s, { size: 32 }),
yParity: authorization_ox.yParity,
};
const valid = await verifyAuthorization({
address,
authorization,
});
if (!valid)
throw new VerificationError();
// Deployless verification.
const results = await getAction(client, readContract, 'readContract')({
...(multicallAddress
? { address: multicallAddress }
: { code: multicall3Bytecode }),
authorizationList: [authorization],
abi: multicall3Abi,
blockNumber,
blockTag: 'pending',
functionName: 'aggregate3',
args: [
[
...(initData
? [
{
allowFailure: true,
target: to ?? address,
callData: initData,
},
]
: []),
{
allowFailure: true,
target: address,
callData: encodeFunctionData({
abi: erc1271Abi,
functionName: 'isValidSignature',
args: [hash, signature],
}),
},
],
],
});
const data = results[results.length - 1]?.returnData;
if (data?.startsWith('0x1626ba7e'))
return true;
throw new VerificationError();
}
/** @internal */
// biome-ignore lint/correctness/noUnusedVariables: _
async function verifyErc6492(client, parameters) {
const { address, factory, factoryData, hash, signature, verifierAddress, ...rest } = parameters;
const wrappedSignature = await (async () => {
// If no `factory` or `factoryData` is provided, it is assumed that the
// address is not a Smart Account, or the Smart Account is already deployed.
if (!factory && !factoryData)
return signature;
// If the signature is already wrapped, return the signature.
if (SignatureErc6492.validate(signature))
return signature;
// If the Smart Account is not deployed, wrap the signature with a 6492 wrapper
// to perform counterfactual validation.
return SignatureErc6492.wrap({
data: factoryData,
signature,
to: factory,
});
})();
const args = verifierAddress
? {
to: verifierAddress,
data: encodeFunctionData({
abi: erc6492SignatureValidatorAbi,
functionName: 'isValidSig',
args: [address, hash, wrappedSignature],
}),
...rest,
}
: {
data: encodeDeployData({
abi: erc6492SignatureValidatorAbi,
args: [address, hash, wrappedSignature],
bytecode: erc6492SignatureValidatorByteCode,
}),
...rest,
};
const { data } = await getAction(client, call, 'call')(args).catch((error) => {
if (error instanceof CallExecutionError)
throw new VerificationError();
throw error;
});
if (hexToBool(data ?? '0x0'))
return true;
throw new VerificationError();
}
/** @internal */
export async function verifyErc1271(client, parameters) {
const { address, blockNumber, blockTag, hash, signature } = parameters;
const result = await getAction(client, readContract, 'readContract')({
address,
abi: erc1271Abi,
args: [hash, signature],
blockNumber,
blockTag,
functionName: 'isValidSignature',
}).catch((error) => {
if (error instanceof ContractFunctionExecutionError)
throw new VerificationError();
throw error;
});
if (result.startsWith('0x1626ba7e'))
return true;
throw new VerificationError();
}
class VerificationError extends Error {
}
//# sourceMappingURL=verifyHash.js.map

File diff suppressed because one or more lines are too long

26
node_modules/viem/_esm/actions/public/verifyMessage.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import { getAction } from '../../utils/getAction.js';
import { hashMessage } from '../../utils/signature/hashMessage.js';
import { verifyHash, } from './verifyHash.js';
/**
* Verify that a message was signed by the provided address.
*
* Compatible with Smart Contract Accounts & Externally Owned Accounts via [ERC-6492](https://eips.ethereum.org/EIPS/eip-6492).
*
* - Docs {@link https://viem.sh/docs/actions/public/verifyMessage}
*
* @param client - Client to use.
* @param parameters - {@link VerifyMessageParameters}
* @returns Whether or not the signature is valid. {@link VerifyMessageReturnType}
*/
export async function verifyMessage(client, { address, message, factory, factoryData, signature, ...callRequest }) {
const hash = hashMessage(message);
return getAction(client, verifyHash, 'verifyHash')({
address,
factory: factory,
factoryData: factoryData,
hash,
signature,
...callRequest,
});
}
//# sourceMappingURL=verifyMessage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"verifyMessage.js","sourceRoot":"","sources":["../../../actions/public/verifyMessage.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAA;AAClE,OAAO,EAGL,UAAU,GACX,MAAM,iBAAiB,CAAA;AAoBxB;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,MAAgC,EAChC,EACE,OAAO,EACP,OAAO,EACP,OAAO,EACP,WAAW,EACX,SAAS,EACT,GAAG,WAAW,EACU;IAE1B,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACjC,OAAO,SAAS,CACd,MAAM,EACN,UAAU,EACV,YAAY,CACb,CAAC;QACA,OAAO;QACP,OAAO,EAAE,OAAQ;QACjB,WAAW,EAAE,WAAY;QACzB,IAAI;QACJ,SAAS;QACT,GAAG,WAAW;KACf,CAAC,CAAA;AACJ,CAAC"}

View File

@@ -0,0 +1,25 @@
import { getAction } from '../../utils/getAction.js';
import { hashTypedData, } from '../../utils/signature/hashTypedData.js';
import { verifyHash, } from './verifyHash.js';
/**
* Verify that typed data was signed by the provided address.
*
* - Docs {@link https://viem.sh/docs/actions/public/verifyTypedData}
*
* @param client - Client to use.
* @param parameters - {@link VerifyTypedDataParameters}
* @returns Whether or not the signature is valid. {@link VerifyTypedDataReturnType}
*/
export async function verifyTypedData(client, parameters) {
const { address, factory, factoryData, signature, message, primaryType, types, domain, ...callRequest } = parameters;
const hash = hashTypedData({ message, primaryType, types, domain });
return getAction(client, verifyHash, 'verifyHash')({
address,
factory: factory,
factoryData: factoryData,
hash,
signature,
...callRequest,
});
}
//# sourceMappingURL=verifyTypedData.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"verifyTypedData.js","sourceRoot":"","sources":["../../../actions/public/verifyTypedData.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAEL,aAAa,GACd,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAGL,UAAU,GACX,MAAM,iBAAiB,CAAA;AAoBxB;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAKnC,MAAgC,EAChC,UAA6D;IAE7D,MAAM,EACJ,OAAO,EACP,OAAO,EACP,WAAW,EACX,SAAS,EACT,OAAO,EACP,WAAW,EACX,KAAK,EACL,MAAM,EACN,GAAG,WAAW,EACf,GAAG,UAAuC,CAAA;IAC3C,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;IACnE,OAAO,SAAS,CACd,MAAM,EACN,UAAU,EACV,YAAY,CACb,CAAC;QACA,OAAO;QACP,OAAO,EAAE,OAAQ;QACjB,WAAW,EAAE,WAAY;QACzB,IAAI;QACJ,SAAS;QACT,GAAG,WAAW;KACf,CAAC,CAAA;AACJ,CAAC"}

View File

@@ -0,0 +1,204 @@
import { BlockNotFoundError } from '../../errors/block.js';
import { TransactionNotFoundError, TransactionReceiptNotFoundError, WaitForTransactionReceiptTimeoutError, } from '../../errors/transaction.js';
import { getAction } from '../../utils/getAction.js';
import { observe } from '../../utils/observe.js';
import { withResolvers } from '../../utils/promise/withResolvers.js';
import { withRetry, } from '../../utils/promise/withRetry.js';
import { stringify } from '../../utils/stringify.js';
import { getBlock } from './getBlock.js';
import { getTransaction, } from './getTransaction.js';
import { getTransactionReceipt, } from './getTransactionReceipt.js';
import { watchBlockNumber, } from './watchBlockNumber.js';
/**
* Waits for the [Transaction](https://viem.sh/docs/glossary/terms#transaction) to be included on a [Block](https://viem.sh/docs/glossary/terms#block) (one confirmation), and then returns the [Transaction Receipt](https://viem.sh/docs/glossary/terms#transaction-receipt).
*
* - Docs: https://viem.sh/docs/actions/public/waitForTransactionReceipt
* - Example: https://stackblitz.com/github/wevm/viem/tree/main/examples/transactions_sending-transactions
* - JSON-RPC Methods:
* - Polls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt) on each block until it has been processed.
* - If a Transaction has been replaced:
* - Calls [`eth_getBlockByNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber) and extracts the transactions
* - Checks if one of the Transactions is a replacement
* - If so, calls [`eth_getTransactionReceipt`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getTransactionReceipt).
*
* The `waitForTransactionReceipt` action additionally supports Replacement detection (e.g. sped up Transactions).
*
* Transactions can be replaced when a user modifies their transaction in their wallet (to speed up or cancel). Transactions are replaced when they are sent from the same nonce.
*
* There are 3 types of Transaction Replacement reasons:
*
* - `repriced`: The gas price has been modified (e.g. different `maxFeePerGas`)
* - `cancelled`: The Transaction has been cancelled (e.g. `value === 0n`)
* - `replaced`: The Transaction has been replaced (e.g. different `value` or `data`)
*
* @param client - Client to use
* @param parameters - {@link WaitForTransactionReceiptParameters}
* @returns The transaction receipt. {@link WaitForTransactionReceiptReturnType}
*
* @example
* import { createPublicClient, waitForTransactionReceipt, http } from 'viem'
* import { mainnet } from 'viem/chains'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const transactionReceipt = await waitForTransactionReceipt(client, {
* hash: '0x4ca7ee652d57678f26e887c149ab0735f41de37bcad58c9f6d3ed5824f15b74d',
* })
*/
export async function waitForTransactionReceipt(client, parameters) {
const { checkReplacement = true, confirmations = 1, hash, onReplaced, retryCount = 6, retryDelay = ({ count }) => ~~(1 << count) * 200, // exponential backoff
timeout = 180_000, } = parameters;
const observerId = stringify(['waitForTransactionReceipt', client.uid, hash]);
const pollingInterval = (() => {
if (parameters.pollingInterval)
return parameters.pollingInterval;
if (client.chain?.experimental_preconfirmationTime)
return client.chain.experimental_preconfirmationTime;
return client.pollingInterval;
})();
let transaction;
let replacedTransaction;
let receipt;
let retrying = false;
let _unobserve;
let _unwatch;
const { promise, resolve, reject } = withResolvers();
const timer = timeout
? setTimeout(() => {
_unwatch?.();
_unobserve?.();
reject(new WaitForTransactionReceiptTimeoutError({ hash }));
}, timeout)
: undefined;
_unobserve = observe(observerId, { onReplaced, resolve, reject }, async (emit) => {
receipt = await getAction(client, getTransactionReceipt, 'getTransactionReceipt')({ hash }).catch(() => undefined);
if (receipt && confirmations <= 1) {
clearTimeout(timer);
emit.resolve(receipt);
_unobserve?.();
return;
}
_unwatch = getAction(client, watchBlockNumber, 'watchBlockNumber')({
emitMissed: true,
emitOnBegin: true,
poll: true,
pollingInterval,
async onBlockNumber(blockNumber_) {
const done = (fn) => {
clearTimeout(timer);
_unwatch?.();
fn();
_unobserve?.();
};
let blockNumber = blockNumber_;
if (retrying)
return;
try {
// If we already have a valid receipt, let's check if we have enough
// confirmations. If we do, then we can resolve.
if (receipt) {
if (confirmations > 1 &&
(!receipt.blockNumber ||
blockNumber - receipt.blockNumber + 1n < confirmations))
return;
done(() => emit.resolve(receipt));
return;
}
// Get the transaction to check if it's been replaced.
// We need to retry as some RPC Providers may be slow to sync
// up mined transactions.
if (checkReplacement && !transaction) {
retrying = true;
await withRetry(async () => {
transaction = (await getAction(client, getTransaction, 'getTransaction')({ hash }));
if (transaction.blockNumber)
blockNumber = transaction.blockNumber;
}, {
delay: retryDelay,
retryCount,
});
retrying = false;
}
// Get the receipt to check if it's been processed.
receipt = await getAction(client, getTransactionReceipt, 'getTransactionReceipt')({ hash });
// Check if we have enough confirmations. If not, continue polling.
if (confirmations > 1 &&
(!receipt.blockNumber ||
blockNumber - receipt.blockNumber + 1n < confirmations))
return;
done(() => emit.resolve(receipt));
}
catch (err) {
// If the receipt is not found, the transaction will be pending.
// We need to check if it has potentially been replaced.
if (err instanceof TransactionNotFoundError ||
err instanceof TransactionReceiptNotFoundError) {
if (!transaction) {
retrying = false;
return;
}
try {
replacedTransaction = transaction;
// Let's retrieve the transactions from the current block.
// We need to retry as some RPC Providers may be slow to sync
// up mined blocks.
retrying = true;
const block = await withRetry(() => getAction(client, getBlock, 'getBlock')({
blockNumber,
includeTransactions: true,
}), {
delay: retryDelay,
retryCount,
shouldRetry: ({ error }) => error instanceof BlockNotFoundError,
});
retrying = false;
const replacementTransaction = block.transactions.find(({ from, nonce }) => from === replacedTransaction.from &&
nonce === replacedTransaction.nonce);
// If we couldn't find a replacement transaction, continue polling.
if (!replacementTransaction)
return;
// If we found a replacement transaction, return it's receipt.
receipt = await getAction(client, getTransactionReceipt, 'getTransactionReceipt')({
hash: replacementTransaction.hash,
});
// Check if we have enough confirmations. If not, continue polling.
if (confirmations > 1 &&
(!receipt.blockNumber ||
blockNumber - receipt.blockNumber + 1n < confirmations))
return;
let reason = 'replaced';
if (replacementTransaction.to === replacedTransaction.to &&
replacementTransaction.value === replacedTransaction.value &&
replacementTransaction.input === replacedTransaction.input) {
reason = 'repriced';
}
else if (replacementTransaction.from === replacementTransaction.to &&
replacementTransaction.value === 0n) {
reason = 'cancelled';
}
done(() => {
emit.onReplaced?.({
reason,
replacedTransaction: replacedTransaction,
transaction: replacementTransaction,
transactionReceipt: receipt,
});
emit.resolve(receipt);
});
}
catch (err_) {
done(() => emit.reject(err_));
}
}
else {
done(() => emit.reject(err));
}
}
},
});
});
return promise;
}
//# sourceMappingURL=waitForTransactionReceipt.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,135 @@
import { hexToBigInt } from '../../utils/encoding/fromHex.js';
import { getAction } from '../../utils/getAction.js';
import { observe } from '../../utils/observe.js';
import { poll } from '../../utils/poll.js';
import { stringify } from '../../utils/stringify.js';
import { getBlockNumber, } from './getBlockNumber.js';
/**
* Watches and returns incoming block numbers.
*
* - Docs: https://viem.sh/docs/actions/public/watchBlockNumber
* - Examples: https://stackblitz.com/github/wevm/viem/tree/main/examples/blocks_watching-blocks
* - JSON-RPC Methods:
* - When `poll: true`, calls [`eth_blockNumber`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blocknumber) on a polling interval.
* - When `poll: false` & WebSocket Transport, uses a WebSocket subscription via [`eth_subscribe`](https://docs.alchemy.com/reference/eth-subscribe-polygon) and the `"newHeads"` event.
*
* @param client - Client to use
* @param parameters - {@link WatchBlockNumberParameters}
* @returns A function that can be invoked to stop watching for new block numbers. {@link WatchBlockNumberReturnType}
*
* @example
* import { createPublicClient, watchBlockNumber, http } from 'viem'
* import { mainnet } from 'viem/chains'
*
* const client = createPublicClient({
* chain: mainnet,
* transport: http(),
* })
* const unwatch = watchBlockNumber(client, {
* onBlockNumber: (blockNumber) => console.log(blockNumber),
* })
*/
export function watchBlockNumber(client, { emitOnBegin = false, emitMissed = false, onBlockNumber, onError, poll: poll_, pollingInterval = client.pollingInterval, }) {
const enablePolling = (() => {
if (typeof poll_ !== 'undefined')
return poll_;
if (client.transport.type === 'webSocket' ||
client.transport.type === 'ipc')
return false;
if (client.transport.type === 'fallback' &&
(client.transport.transports[0].config.type === 'webSocket' ||
client.transport.transports[0].config.type === 'ipc'))
return false;
return true;
})();
let prevBlockNumber;
const pollBlockNumber = () => {
const observerId = stringify([
'watchBlockNumber',
client.uid,
emitOnBegin,
emitMissed,
pollingInterval,
]);
return observe(observerId, { onBlockNumber, onError }, (emit) => poll(async () => {
try {
const blockNumber = await getAction(client, getBlockNumber, 'getBlockNumber')({ cacheTime: 0 });
if (prevBlockNumber !== undefined) {
// If the current block number is the same as the previous,
// we can skip.
if (blockNumber === prevBlockNumber)
return;
// If we have missed out on some previous blocks, and the
// `emitMissed` flag is truthy, let's emit those blocks.
if (blockNumber - prevBlockNumber > 1 && emitMissed) {
for (let i = prevBlockNumber + 1n; i < blockNumber; i++) {
emit.onBlockNumber(i, prevBlockNumber);
prevBlockNumber = i;
}
}
}
// If the next block number is greater than the previous,
// it is not in the past, and we can emit the new block number.
if (prevBlockNumber === undefined ||
blockNumber > prevBlockNumber) {
emit.onBlockNumber(blockNumber, prevBlockNumber);
prevBlockNumber = blockNumber;
}
}
catch (err) {
emit.onError?.(err);
}
}, {
emitOnBegin,
interval: pollingInterval,
}));
};
const subscribeBlockNumber = () => {
const observerId = stringify([
'watchBlockNumber',
client.uid,
emitOnBegin,
emitMissed,
]);
return observe(observerId, { onBlockNumber, onError }, (emit) => {
let active = true;
let unsubscribe = () => (active = false);
(async () => {
try {
const transport = (() => {
if (client.transport.type === 'fallback') {
const transport = client.transport.transports.find((transport) => transport.config.type === 'webSocket' ||
transport.config.type === 'ipc');
if (!transport)
return client.transport;
return transport.value;
}
return client.transport;
})();
const { unsubscribe: unsubscribe_ } = await transport.subscribe({
params: ['newHeads'],
onData(data) {
if (!active)
return;
const blockNumber = hexToBigInt(data.result?.number);
emit.onBlockNumber(blockNumber, prevBlockNumber);
prevBlockNumber = blockNumber;
},
onError(error) {
emit.onError?.(error);
},
});
unsubscribe = unsubscribe_;
if (!active)
unsubscribe();
}
catch (err) {
onError?.(err);
}
})();
return () => unsubscribe();
});
};
return enablePolling ? pollBlockNumber() : subscribeBlockNumber();
}
//# sourceMappingURL=watchBlockNumber.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"watchBlockNumber.js","sourceRoot":"","sources":["../../../actions/public/watchBlockNumber.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACp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