viem 0.2.0-0-2-0.20230330T023229 → 0.2.0-0-2-0.20230403T055238
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abi.d.ts +3 -3
- package/dist/abi.js +2 -2
- package/dist/abi.mjs +1 -1
- package/dist/accounts/index.d.ts +4 -4
- package/dist/accounts/index.js +16 -16
- package/dist/accounts/index.mjs +2 -2
- package/dist/{chain-9da1e6b6.d.ts → chain-5507c6f0.d.ts} +25 -14
- package/dist/{chain-b53ed5d9.d.ts → chain-fe47467d.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +89 -89
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-S4GWZ3LJ.mjs → chunk-EMXJKA5P.mjs} +2 -2
- package/dist/{chunk-B7WOV4RY.mjs → chunk-KILBOPDD.mjs} +738 -19
- package/dist/chunk-KILBOPDD.mjs.map +1 -0
- package/dist/{chunk-GNHXOZCH.js → chunk-KQOOAYBY.js} +6 -6
- package/dist/{chunk-2ESQNALV.js → chunk-PWUNCH5G.js} +762 -43
- package/dist/chunk-PWUNCH5G.js.map +1 -0
- package/dist/contract.d.ts +8 -8
- package/dist/contract.js +2 -2
- package/dist/contract.mjs +1 -1
- package/dist/{createTransport-e031366b.d.ts → createTransport-21a0d2b3.d.ts} +2 -2
- package/dist/{eip1193-e79469af.d.ts → eip1193-2f3a9cd2.d.ts} +1 -1
- package/dist/{encodeFunctionResult-d206ceb9.d.ts → encodeFunctionResult-c5185b98.d.ts} +1 -1
- package/dist/{encodePacked-b36ce88a.d.ts → encodePacked-98f67d09.d.ts} +1 -1
- package/dist/ens.d.ts +5 -5
- package/dist/ens.js +8 -3
- package/dist/ens.js.map +1 -1
- package/dist/ens.mjs +7 -2
- package/dist/ens.mjs.map +1 -1
- package/dist/ethers.d.ts +2 -2
- package/dist/ethers.js +4 -4
- package/dist/ethers.mjs +2 -2
- package/dist/{formatAbiItem-a7a3fb0f.d.ts → formatAbiItem-56dff508.d.ts} +1 -1
- package/dist/{getAbiItem-5e8b01de.d.ts → getAbiItem-bfba73d1.d.ts} +1 -1
- package/dist/{watchPendingTransactions-53449c4e.d.ts → getEnsResolver-9e26c596.d.ts} +177 -127
- package/dist/index.d.ts +126 -17
- package/dist/index.js +100 -92
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -7
- package/dist/index.mjs.map +1 -1
- package/dist/{parseGwei-7678c2fa.d.ts → parseGwei-d2147f8b.d.ts} +5 -5
- package/dist/public.d.ts +5 -5
- package/dist/public.js +2 -2
- package/dist/public.mjs +1 -1
- package/dist/{publicKeyToAddress-87b9856c.d.ts → publicKeyToAddress-623eb398.d.ts} +2 -2
- package/dist/{test-68dbda5b.d.ts → test-b67569fe.d.ts} +3 -3
- package/dist/test.d.ts +5 -5
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/dist/{typedData-8b24374d.d.ts → typedData-46b4d81f.d.ts} +1 -1
- package/dist/utils/index.d.ts +15 -15
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.mjs +1 -1
- package/dist/wallet.d.ts +5 -5
- package/dist/wallet.js +2 -2
- package/dist/wallet.mjs +1 -1
- package/dist/window.d.ts +2 -2
- package/package.json +3 -2
- package/dist/chunk-2ESQNALV.js.map +0 -1
- package/dist/chunk-ASAFFZMD.js +0 -186
- package/dist/chunk-ASAFFZMD.js.map +0 -1
- package/dist/chunk-B7WOV4RY.mjs.map +0 -1
- package/dist/chunk-RFOQRRYW.mjs +0 -186
- package/dist/chunk-RFOQRRYW.mjs.map +0 -1
- /package/dist/{chunk-S4GWZ3LJ.mjs.map → chunk-EMXJKA5P.mjs.map} +0 -0
- /package/dist/{chunk-GNHXOZCH.js.map → chunk-KQOOAYBY.js.map} +0 -0
@@ -20,7 +20,7 @@ import "abitype";
|
|
20
20
|
var package_default = {
|
21
21
|
name: "viem",
|
22
22
|
description: "TypeScript Interface for Ethereum",
|
23
|
-
version: "0.1.
|
23
|
+
version: "0.1.26",
|
24
24
|
scripts: {
|
25
25
|
anvil: "source .env && anvil --fork-url $VITE_ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
26
26
|
bench: "vitest bench --no-threads",
|
@@ -147,8 +147,9 @@ var package_default = {
|
|
147
147
|
types: "dist/index.d.ts",
|
148
148
|
sideEffects: false,
|
149
149
|
dependencies: {
|
150
|
-
"@
|
150
|
+
"@ensdomains/address-encoder": "^0.2.21",
|
151
151
|
"@noble/curves": "^0.9.0",
|
152
|
+
"@noble/hashes": "^1.1.2",
|
152
153
|
"@scure/bip32": "^1.2.0",
|
153
154
|
"@scure/bip39": "^1.1.1",
|
154
155
|
"@wagmi/chains": "~0.2.15",
|
@@ -209,6 +210,9 @@ var package_default = {
|
|
209
210
|
"pre-commit": "pnpm format && pnpm lint:fix"
|
210
211
|
},
|
211
212
|
pnpm: {
|
213
|
+
overrides: {
|
214
|
+
viem: "workspace:*"
|
215
|
+
},
|
212
216
|
patchedDependencies: {
|
213
217
|
"vitepress@1.0.0-alpha.61": "patches/vitepress@1.0.0-alpha.61.patch"
|
214
218
|
},
|
@@ -680,6 +684,42 @@ var multicall3Abi = [
|
|
680
684
|
type: "function"
|
681
685
|
}
|
682
686
|
];
|
687
|
+
var universalResolverAbi = [
|
688
|
+
{
|
689
|
+
name: "resolve",
|
690
|
+
type: "function",
|
691
|
+
stateMutability: "view",
|
692
|
+
inputs: [
|
693
|
+
{ name: "name", type: "bytes" },
|
694
|
+
{ name: "data", type: "bytes" }
|
695
|
+
],
|
696
|
+
outputs: [
|
697
|
+
{ name: "", type: "bytes" },
|
698
|
+
{ name: "address", type: "address" }
|
699
|
+
]
|
700
|
+
}
|
701
|
+
];
|
702
|
+
var textResolverAbi = [
|
703
|
+
{
|
704
|
+
name: "text",
|
705
|
+
type: "function",
|
706
|
+
stateMutability: "view",
|
707
|
+
inputs: [
|
708
|
+
{ name: "name", type: "bytes32" },
|
709
|
+
{ name: "key", type: "string" }
|
710
|
+
],
|
711
|
+
outputs: [{ name: "", type: "string" }]
|
712
|
+
}
|
713
|
+
];
|
714
|
+
var singleAddressResolverAbi = [
|
715
|
+
{
|
716
|
+
name: "addr",
|
717
|
+
type: "function",
|
718
|
+
stateMutability: "view",
|
719
|
+
inputs: [{ name: "name", type: "bytes32" }],
|
720
|
+
outputs: [{ name: "", type: "address" }]
|
721
|
+
}
|
722
|
+
];
|
683
723
|
|
684
724
|
// src/constants/solidity.ts
|
685
725
|
var panicReasons = {
|
@@ -1132,6 +1172,45 @@ var OffsetOutOfBoundsError = class extends BaseError {
|
|
1132
1172
|
}
|
1133
1173
|
};
|
1134
1174
|
|
1175
|
+
// src/errors/ens.ts
|
1176
|
+
var EnsAvatarInvalidMetadataError = class extends BaseError {
|
1177
|
+
constructor({ data }) {
|
1178
|
+
super(
|
1179
|
+
"Unable to extract image from metadata. The metadata may be malformed or invalid.",
|
1180
|
+
{
|
1181
|
+
metaMessages: [
|
1182
|
+
"- Metadata must be a JSON object with at least an `image`, `image_url` or `image_data` property.",
|
1183
|
+
"",
|
1184
|
+
`Provided data: ${JSON.stringify(data)}`
|
1185
|
+
]
|
1186
|
+
}
|
1187
|
+
);
|
1188
|
+
__publicField(this, "name", "EnsAvatarInvalidMetadataError");
|
1189
|
+
}
|
1190
|
+
};
|
1191
|
+
var EnsAvatarInvalidNftUriError = class extends BaseError {
|
1192
|
+
constructor({ reason }) {
|
1193
|
+
super(`ENS NFT avatar URI is invalid. ${reason}`);
|
1194
|
+
__publicField(this, "name", "EnsAvatarInvalidNftUriError");
|
1195
|
+
}
|
1196
|
+
};
|
1197
|
+
var EnsAvatarUriResolutionError = class extends BaseError {
|
1198
|
+
constructor({ uri }) {
|
1199
|
+
super(
|
1200
|
+
`Unable to resolve ENS avatar URI "${uri}". The URI may be malformed, invalid, or does not respond with a valid image.`
|
1201
|
+
);
|
1202
|
+
__publicField(this, "name", "EnsAvatarUriResolutionError");
|
1203
|
+
}
|
1204
|
+
};
|
1205
|
+
var EnsAvatarUnsupportedNamespaceError = class extends BaseError {
|
1206
|
+
constructor({ namespace }) {
|
1207
|
+
super(
|
1208
|
+
`ENS NFT avatar namespace "${namespace}" is not supported. Must be "erc721" or "erc1155".`
|
1209
|
+
);
|
1210
|
+
__publicField(this, "name", "EnsAvatarUnsupportedNamespaceError");
|
1211
|
+
}
|
1212
|
+
};
|
1213
|
+
|
1135
1214
|
// src/errors/estimateGas.ts
|
1136
1215
|
var EstimateGasExecutionError = class extends BaseError {
|
1137
1216
|
constructor(cause, {
|
@@ -2421,7 +2500,7 @@ function decodeArray(data, {
|
|
2421
2500
|
consumed2 += decodedChild.consumed;
|
2422
2501
|
value2.push(decodedChild.value);
|
2423
2502
|
}
|
2424
|
-
return { value: value2, consumed:
|
2503
|
+
return { value: value2, consumed: 32 };
|
2425
2504
|
}
|
2426
2505
|
let consumed = 0;
|
2427
2506
|
let value = [];
|
@@ -2627,7 +2706,7 @@ function decodeFunctionData({
|
|
2627
2706
|
}) {
|
2628
2707
|
const signature = slice(data, 0, 4);
|
2629
2708
|
const description = abi.find(
|
2630
|
-
(x) => signature === getFunctionSelector(formatAbiItem(x))
|
2709
|
+
(x) => x.type === "function" && signature === getFunctionSelector(formatAbiItem(x))
|
2631
2710
|
);
|
2632
2711
|
if (!description)
|
2633
2712
|
throw new AbiFunctionSignatureNotFoundError(signature, {
|
@@ -3958,6 +4037,272 @@ function getTransactionType(transaction) {
|
|
3958
4037
|
throw new InvalidSerializableTransactionError({ transaction });
|
3959
4038
|
}
|
3960
4039
|
|
4040
|
+
// src/utils/ens/avatar/utils.ts
|
4041
|
+
var networkRegex = /(?<protocol>https?:\/\/[^\/]*|ipfs:\/|ipns:\/|ar:\/)?(?<root>\/)?(?<subpath>ipfs\/|ipns\/)?(?<target>[\w\-.]+)(?<subtarget>\/.*)?/;
|
4042
|
+
var ipfsHashRegex = /^(Qm[1-9A-HJ-NP-Za-km-z]{44,}|b[A-Za-z2-7]{58,}|B[A-Z2-7]{58,}|z[1-9A-HJ-NP-Za-km-z]{48,}|F[0-9A-F]{50,})(\/(?<target>[\w\-.]+))?(?<subtarget>\/.*)?$/;
|
4043
|
+
var base64Regex = /^data:([a-zA-Z\-/+]*);base64,([^"].*)/;
|
4044
|
+
var dataURIRegex = /^data:([a-zA-Z\-/+]*)?(;[a-zA-Z0-9].*?)?(,)/;
|
4045
|
+
async function isImageUri(uri) {
|
4046
|
+
try {
|
4047
|
+
const res = await fetch(uri, { method: "HEAD" });
|
4048
|
+
if (res.status === 200) {
|
4049
|
+
const contentType = res.headers.get("content-type");
|
4050
|
+
return contentType?.startsWith("image/");
|
4051
|
+
}
|
4052
|
+
return false;
|
4053
|
+
} catch (error) {
|
4054
|
+
if (typeof error === "object" && typeof error.response !== "undefined") {
|
4055
|
+
return false;
|
4056
|
+
}
|
4057
|
+
if (!globalThis.hasOwnProperty("Image"))
|
4058
|
+
return false;
|
4059
|
+
return new Promise((resolve) => {
|
4060
|
+
const img = new Image();
|
4061
|
+
img.onload = () => {
|
4062
|
+
resolve(true);
|
4063
|
+
};
|
4064
|
+
img.onerror = () => {
|
4065
|
+
resolve(false);
|
4066
|
+
};
|
4067
|
+
img.src = uri;
|
4068
|
+
});
|
4069
|
+
}
|
4070
|
+
}
|
4071
|
+
function getGateway(custom, defaultGateway) {
|
4072
|
+
if (!custom)
|
4073
|
+
return defaultGateway;
|
4074
|
+
if (custom.endsWith("/"))
|
4075
|
+
return custom.slice(0, -1);
|
4076
|
+
return custom;
|
4077
|
+
}
|
4078
|
+
function resolveAvatarUri({
|
4079
|
+
uri,
|
4080
|
+
gatewayUrls
|
4081
|
+
}) {
|
4082
|
+
const isEncoded = base64Regex.test(uri);
|
4083
|
+
if (isEncoded)
|
4084
|
+
return { uri, isOnChain: true, isEncoded };
|
4085
|
+
const ipfsGateway = getGateway(gatewayUrls?.ipfs, "https://ipfs.io");
|
4086
|
+
const arweaveGateway = getGateway(gatewayUrls?.arweave, "https://arweave.net");
|
4087
|
+
const networkRegexMatch = uri.match(networkRegex);
|
4088
|
+
const {
|
4089
|
+
protocol,
|
4090
|
+
subpath,
|
4091
|
+
target,
|
4092
|
+
subtarget = ""
|
4093
|
+
} = networkRegexMatch?.groups || {};
|
4094
|
+
const isIPNS = protocol === "ipns:/" || subpath === "ipns/";
|
4095
|
+
const isIPFS = protocol === "ipfs:/" || subpath === "ipfs/" || ipfsHashRegex.test(uri);
|
4096
|
+
if (uri.startsWith("http") && !isIPNS && !isIPFS) {
|
4097
|
+
let replacedUri = uri;
|
4098
|
+
if (gatewayUrls?.arweave)
|
4099
|
+
replacedUri = uri.replace(/https:\/\/arweave.net/g, gatewayUrls?.arweave);
|
4100
|
+
return { uri: replacedUri, isOnChain: false, isEncoded: false };
|
4101
|
+
}
|
4102
|
+
if ((isIPNS || isIPFS) && target) {
|
4103
|
+
return {
|
4104
|
+
uri: `${ipfsGateway}/${isIPNS ? "ipns" : "ipfs"}/${target}${subtarget}`,
|
4105
|
+
isOnChain: false,
|
4106
|
+
isEncoded: false
|
4107
|
+
};
|
4108
|
+
} else if (protocol === "ar:/" && target) {
|
4109
|
+
return {
|
4110
|
+
uri: `${arweaveGateway}/${target}${subtarget || ""}`,
|
4111
|
+
isOnChain: false,
|
4112
|
+
isEncoded: false
|
4113
|
+
};
|
4114
|
+
}
|
4115
|
+
let parsedUri = uri.replace(dataURIRegex, "");
|
4116
|
+
if (parsedUri.startsWith("<svg")) {
|
4117
|
+
parsedUri = `data:image/svg+xml;base64,${btoa(parsedUri)}`;
|
4118
|
+
}
|
4119
|
+
if (parsedUri.startsWith("data:") || parsedUri.startsWith("{")) {
|
4120
|
+
return {
|
4121
|
+
uri: parsedUri,
|
4122
|
+
isOnChain: true,
|
4123
|
+
isEncoded: false
|
4124
|
+
};
|
4125
|
+
}
|
4126
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
4127
|
+
}
|
4128
|
+
function getJsonImage(data) {
|
4129
|
+
if (typeof data !== "object" || !("image" in data) && !("image_url" in data) && !("image_data" in data)) {
|
4130
|
+
throw new EnsAvatarInvalidMetadataError({ data });
|
4131
|
+
}
|
4132
|
+
return data.image || data.image_url || data.image_data;
|
4133
|
+
}
|
4134
|
+
async function getMetadataAvatarUri({
|
4135
|
+
gatewayUrls,
|
4136
|
+
uri
|
4137
|
+
}) {
|
4138
|
+
try {
|
4139
|
+
const res = await fetch(uri).then((res2) => res2.json());
|
4140
|
+
const image = await parseAvatarUri({
|
4141
|
+
gatewayUrls,
|
4142
|
+
uri: getJsonImage(res)
|
4143
|
+
});
|
4144
|
+
return image;
|
4145
|
+
} catch {
|
4146
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
4147
|
+
}
|
4148
|
+
}
|
4149
|
+
async function parseAvatarUri({
|
4150
|
+
gatewayUrls,
|
4151
|
+
uri
|
4152
|
+
}) {
|
4153
|
+
const { uri: resolvedURI, isOnChain } = resolveAvatarUri({ uri, gatewayUrls });
|
4154
|
+
if (isOnChain)
|
4155
|
+
return resolvedURI;
|
4156
|
+
const isImage = await isImageUri(resolvedURI);
|
4157
|
+
if (isImage)
|
4158
|
+
return resolvedURI;
|
4159
|
+
throw new EnsAvatarUriResolutionError({ uri });
|
4160
|
+
}
|
4161
|
+
function parseNftUri(uri) {
|
4162
|
+
if (uri.startsWith("did:nft:")) {
|
4163
|
+
uri = uri.replace("did:nft:", "").replace(/_/g, "/");
|
4164
|
+
}
|
4165
|
+
const [reference, asset_namespace, tokenID] = uri.split("/");
|
4166
|
+
const [eip_namespace, chainID] = reference.split(":");
|
4167
|
+
const [erc_namespace, contractAddress] = asset_namespace.split(":");
|
4168
|
+
if (!eip_namespace || eip_namespace.toLowerCase() !== "eip155")
|
4169
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Only EIP-155 supported" });
|
4170
|
+
if (!chainID)
|
4171
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Chain ID not found" });
|
4172
|
+
if (!contractAddress)
|
4173
|
+
throw new EnsAvatarInvalidNftUriError({
|
4174
|
+
reason: "Contract address not found"
|
4175
|
+
});
|
4176
|
+
if (!tokenID)
|
4177
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "Token ID not found" });
|
4178
|
+
if (!erc_namespace)
|
4179
|
+
throw new EnsAvatarInvalidNftUriError({ reason: "ERC namespace not found" });
|
4180
|
+
return {
|
4181
|
+
chainID: parseInt(chainID),
|
4182
|
+
namespace: erc_namespace.toLowerCase(),
|
4183
|
+
contractAddress,
|
4184
|
+
tokenID
|
4185
|
+
};
|
4186
|
+
}
|
4187
|
+
async function getNftTokenUri(client, { nft }) {
|
4188
|
+
if (nft.namespace === "erc721") {
|
4189
|
+
return readContract(client, {
|
4190
|
+
address: nft.contractAddress,
|
4191
|
+
abi: [
|
4192
|
+
{
|
4193
|
+
name: "tokenURI",
|
4194
|
+
type: "function",
|
4195
|
+
stateMutability: "view",
|
4196
|
+
inputs: [{ name: "tokenId", type: "uint256" }],
|
4197
|
+
outputs: [{ name: "", type: "string" }]
|
4198
|
+
}
|
4199
|
+
],
|
4200
|
+
functionName: "tokenURI",
|
4201
|
+
args: [BigInt(nft.tokenID)]
|
4202
|
+
});
|
4203
|
+
}
|
4204
|
+
if (nft.namespace === "erc1155") {
|
4205
|
+
return readContract(client, {
|
4206
|
+
address: nft.contractAddress,
|
4207
|
+
abi: [
|
4208
|
+
{
|
4209
|
+
name: "uri",
|
4210
|
+
type: "function",
|
4211
|
+
stateMutability: "view",
|
4212
|
+
inputs: [{ name: "_id", type: "uint256" }],
|
4213
|
+
outputs: [{ name: "", type: "string" }]
|
4214
|
+
}
|
4215
|
+
],
|
4216
|
+
functionName: "uri",
|
4217
|
+
args: [BigInt(nft.tokenID)]
|
4218
|
+
});
|
4219
|
+
}
|
4220
|
+
throw new EnsAvatarUnsupportedNamespaceError({ namespace: nft.namespace });
|
4221
|
+
}
|
4222
|
+
|
4223
|
+
// src/utils/ens/avatar/parseAvatarRecord.ts
|
4224
|
+
async function parseAvatarRecord(client, {
|
4225
|
+
gatewayUrls,
|
4226
|
+
record
|
4227
|
+
}) {
|
4228
|
+
if (/eip155:/i.test(record))
|
4229
|
+
return parseNftAvatarUri(client, { gatewayUrls, record });
|
4230
|
+
return parseAvatarUri({ uri: record, gatewayUrls });
|
4231
|
+
}
|
4232
|
+
async function parseNftAvatarUri(client, {
|
4233
|
+
gatewayUrls,
|
4234
|
+
record
|
4235
|
+
}) {
|
4236
|
+
const nft = parseNftUri(record);
|
4237
|
+
const nftUri = await getNftTokenUri(client, { nft });
|
4238
|
+
const {
|
4239
|
+
uri: resolvedNftUri,
|
4240
|
+
isOnChain,
|
4241
|
+
isEncoded
|
4242
|
+
} = resolveAvatarUri({ uri: nftUri, gatewayUrls });
|
4243
|
+
if (isOnChain && (resolvedNftUri.includes("data:application/json;base64,") || resolvedNftUri.startsWith("{"))) {
|
4244
|
+
const encodedJson = isEncoded ? (
|
4245
|
+
// if it is encoded, decode it
|
4246
|
+
atob(resolvedNftUri.replace("data:application/json;base64,", ""))
|
4247
|
+
) : (
|
4248
|
+
// if it isn't encoded assume it is a JSON string, but it could be anything (it will error if it is)
|
4249
|
+
resolvedNftUri
|
4250
|
+
);
|
4251
|
+
const decoded = JSON.parse(encodedJson);
|
4252
|
+
return parseAvatarUri({ uri: getJsonImage(decoded), gatewayUrls });
|
4253
|
+
}
|
4254
|
+
let uriTokenId = nft.tokenID;
|
4255
|
+
if (nft.namespace === "erc1155")
|
4256
|
+
uriTokenId = uriTokenId.replace("0x", "").padStart(64, "0");
|
4257
|
+
return getMetadataAvatarUri({
|
4258
|
+
gatewayUrls,
|
4259
|
+
uri: resolvedNftUri.replace(/(?:0x)?{id}/, uriTokenId)
|
4260
|
+
});
|
4261
|
+
}
|
4262
|
+
|
4263
|
+
// src/utils/ens/labelhash.ts
|
4264
|
+
function labelhash(label) {
|
4265
|
+
let result = new Uint8Array(32).fill(0);
|
4266
|
+
if (!label)
|
4267
|
+
return bytesToHex(result);
|
4268
|
+
return keccak256(stringToBytes(label));
|
4269
|
+
}
|
4270
|
+
|
4271
|
+
// src/utils/ens/namehash.ts
|
4272
|
+
function namehash(name) {
|
4273
|
+
let result = new Uint8Array(32).fill(0);
|
4274
|
+
if (!name)
|
4275
|
+
return bytesToHex(result);
|
4276
|
+
const labels = name.split(".");
|
4277
|
+
for (let i = labels.length - 1; i >= 0; i -= 1) {
|
4278
|
+
const hashed = keccak256(stringToBytes(labels[i]), "bytes");
|
4279
|
+
result = keccak256(concat([result, hashed]), "bytes");
|
4280
|
+
}
|
4281
|
+
return bytesToHex(result);
|
4282
|
+
}
|
4283
|
+
|
4284
|
+
// src/utils/ens/packetToBytes.ts
|
4285
|
+
function packetToBytes(packet) {
|
4286
|
+
function length(value2) {
|
4287
|
+
if (value2 === "." || value2 === "..")
|
4288
|
+
return 1;
|
4289
|
+
return toBytes(value2.replace(/^\.|\.$/gm, "")).length + 2;
|
4290
|
+
}
|
4291
|
+
const bytes = new Uint8Array(length(packet));
|
4292
|
+
const value = packet.replace(/^\.|\.$/gm, "");
|
4293
|
+
if (!value.length)
|
4294
|
+
return bytes;
|
4295
|
+
let offset = 0;
|
4296
|
+
const list = value.split(".");
|
4297
|
+
for (let i = 0; i < list.length; i++) {
|
4298
|
+
const encoded = toBytes(list[i]);
|
4299
|
+
bytes[offset] = encoded.length;
|
4300
|
+
bytes.set(encoded, offset + 1);
|
4301
|
+
offset += encoded.length + 1;
|
4302
|
+
}
|
4303
|
+
return bytes;
|
4304
|
+
}
|
4305
|
+
|
3961
4306
|
// src/actions/public/call.ts
|
3962
4307
|
async function call(client, args) {
|
3963
4308
|
const {
|
@@ -5235,6 +5580,202 @@ function watchPendingTransactions(client, {
|
|
5235
5580
|
return enablePolling ? pollPendingTransactions() : subscribePendingTransactions();
|
5236
5581
|
}
|
5237
5582
|
|
5583
|
+
// src/actions/ens/getEnsAddress.ts
|
5584
|
+
async function getEnsAddress(client, {
|
5585
|
+
blockNumber,
|
5586
|
+
blockTag,
|
5587
|
+
name,
|
5588
|
+
universalResolverAddress: universalResolverAddress_
|
5589
|
+
}) {
|
5590
|
+
let universalResolverAddress = universalResolverAddress_;
|
5591
|
+
if (!universalResolverAddress) {
|
5592
|
+
if (!client.chain)
|
5593
|
+
throw new Error(
|
5594
|
+
"client chain not configured. universalResolverAddress is required."
|
5595
|
+
);
|
5596
|
+
universalResolverAddress = getChainContractAddress({
|
5597
|
+
blockNumber,
|
5598
|
+
chain: client.chain,
|
5599
|
+
contract: "ensUniversalResolver"
|
5600
|
+
});
|
5601
|
+
}
|
5602
|
+
const res = await readContract(client, {
|
5603
|
+
address: universalResolverAddress,
|
5604
|
+
abi: universalResolverAbi,
|
5605
|
+
functionName: "resolve",
|
5606
|
+
args: [
|
5607
|
+
toHex(packetToBytes(name)),
|
5608
|
+
encodeFunctionData({
|
5609
|
+
abi: singleAddressResolverAbi,
|
5610
|
+
functionName: "addr",
|
5611
|
+
args: [namehash(name)]
|
5612
|
+
})
|
5613
|
+
],
|
5614
|
+
blockNumber,
|
5615
|
+
blockTag
|
5616
|
+
});
|
5617
|
+
return decodeFunctionResult({
|
5618
|
+
abi: singleAddressResolverAbi,
|
5619
|
+
functionName: "addr",
|
5620
|
+
data: res[0]
|
5621
|
+
});
|
5622
|
+
}
|
5623
|
+
|
5624
|
+
// src/actions/ens/getEnsText.ts
|
5625
|
+
async function getEnsText(client, {
|
5626
|
+
blockNumber,
|
5627
|
+
blockTag,
|
5628
|
+
name,
|
5629
|
+
key,
|
5630
|
+
universalResolverAddress: universalResolverAddress_
|
5631
|
+
}) {
|
5632
|
+
let universalResolverAddress = universalResolverAddress_;
|
5633
|
+
if (!universalResolverAddress) {
|
5634
|
+
if (!client.chain)
|
5635
|
+
throw new Error(
|
5636
|
+
"client chain not configured. universalResolverAddress is required."
|
5637
|
+
);
|
5638
|
+
universalResolverAddress = getChainContractAddress({
|
5639
|
+
blockNumber,
|
5640
|
+
chain: client.chain,
|
5641
|
+
contract: "ensUniversalResolver"
|
5642
|
+
});
|
5643
|
+
}
|
5644
|
+
const res = await readContract(client, {
|
5645
|
+
address: universalResolverAddress,
|
5646
|
+
abi: universalResolverAbi,
|
5647
|
+
functionName: "resolve",
|
5648
|
+
args: [
|
5649
|
+
toHex(packetToBytes(name)),
|
5650
|
+
encodeFunctionData({
|
5651
|
+
abi: textResolverAbi,
|
5652
|
+
functionName: "text",
|
5653
|
+
args: [namehash(name), key]
|
5654
|
+
})
|
5655
|
+
],
|
5656
|
+
blockNumber,
|
5657
|
+
blockTag
|
5658
|
+
});
|
5659
|
+
const record = decodeFunctionResult({
|
5660
|
+
abi: textResolverAbi,
|
5661
|
+
functionName: "text",
|
5662
|
+
data: res[0]
|
5663
|
+
});
|
5664
|
+
return record === "" ? null : record;
|
5665
|
+
}
|
5666
|
+
|
5667
|
+
// src/actions/ens/getEnsAvatar.ts
|
5668
|
+
async function getEnsAvatar(client, {
|
5669
|
+
blockNumber,
|
5670
|
+
blockTag,
|
5671
|
+
gatewayUrls,
|
5672
|
+
name,
|
5673
|
+
universalResolverAddress
|
5674
|
+
}) {
|
5675
|
+
const record = await getEnsText(client, {
|
5676
|
+
blockNumber,
|
5677
|
+
blockTag,
|
5678
|
+
key: "avatar",
|
5679
|
+
name,
|
5680
|
+
universalResolverAddress
|
5681
|
+
});
|
5682
|
+
if (!record)
|
5683
|
+
return null;
|
5684
|
+
try {
|
5685
|
+
return await parseAvatarRecord(client, { record, gatewayUrls });
|
5686
|
+
} catch {
|
5687
|
+
return null;
|
5688
|
+
}
|
5689
|
+
}
|
5690
|
+
|
5691
|
+
// src/actions/ens/getEnsName.ts
|
5692
|
+
async function getEnsName(client, {
|
5693
|
+
address,
|
5694
|
+
blockNumber,
|
5695
|
+
blockTag,
|
5696
|
+
universalResolverAddress: universalResolverAddress_
|
5697
|
+
}) {
|
5698
|
+
let universalResolverAddress = universalResolverAddress_;
|
5699
|
+
if (!universalResolverAddress) {
|
5700
|
+
if (!client.chain)
|
5701
|
+
throw new Error(
|
5702
|
+
"client chain not configured. universalResolverAddress is required."
|
5703
|
+
);
|
5704
|
+
universalResolverAddress = getChainContractAddress({
|
5705
|
+
blockNumber,
|
5706
|
+
chain: client.chain,
|
5707
|
+
contract: "ensUniversalResolver"
|
5708
|
+
});
|
5709
|
+
}
|
5710
|
+
const reverseNode = `${address.toLowerCase().substring(2)}.addr.reverse`;
|
5711
|
+
try {
|
5712
|
+
const res = await readContract(client, {
|
5713
|
+
address: universalResolverAddress,
|
5714
|
+
abi: [
|
5715
|
+
{
|
5716
|
+
name: "reverse",
|
5717
|
+
type: "function",
|
5718
|
+
stateMutability: "view",
|
5719
|
+
inputs: [{ type: "bytes", name: "reverseName" }],
|
5720
|
+
outputs: [
|
5721
|
+
{ type: "string", name: "resolvedName" },
|
5722
|
+
{ type: "address", name: "resolvedAddress" },
|
5723
|
+
{ type: "address", name: "reverseResolver" },
|
5724
|
+
{ type: "address", name: "resolver" }
|
5725
|
+
]
|
5726
|
+
}
|
5727
|
+
],
|
5728
|
+
functionName: "reverse",
|
5729
|
+
args: [toHex(packetToBytes(reverseNode))],
|
5730
|
+
blockNumber,
|
5731
|
+
blockTag
|
5732
|
+
});
|
5733
|
+
return res[0];
|
5734
|
+
} catch (error) {
|
5735
|
+
if (error instanceof ContractFunctionExecutionError && error.cause.reason === panicReasons[50])
|
5736
|
+
return null;
|
5737
|
+
throw error;
|
5738
|
+
}
|
5739
|
+
}
|
5740
|
+
|
5741
|
+
// src/actions/ens/getEnsResolver.ts
|
5742
|
+
async function getEnsResolver(client, {
|
5743
|
+
blockNumber,
|
5744
|
+
blockTag,
|
5745
|
+
name,
|
5746
|
+
universalResolverAddress: universalResolverAddress_
|
5747
|
+
}) {
|
5748
|
+
let universalResolverAddress = universalResolverAddress_;
|
5749
|
+
if (!universalResolverAddress) {
|
5750
|
+
if (!client.chain)
|
5751
|
+
throw new Error(
|
5752
|
+
"client chain not configured. universalResolverAddress is required."
|
5753
|
+
);
|
5754
|
+
universalResolverAddress = getChainContractAddress({
|
5755
|
+
blockNumber,
|
5756
|
+
chain: client.chain,
|
5757
|
+
contract: "ensUniversalResolver"
|
5758
|
+
});
|
5759
|
+
}
|
5760
|
+
const [resolverAddress] = await readContract(client, {
|
5761
|
+
address: universalResolverAddress,
|
5762
|
+
abi: [
|
5763
|
+
{
|
5764
|
+
inputs: [{ type: "bytes" }],
|
5765
|
+
name: "findResolver",
|
5766
|
+
outputs: [{ type: "address" }, { type: "bytes32" }],
|
5767
|
+
stateMutability: "view",
|
5768
|
+
type: "function"
|
5769
|
+
}
|
5770
|
+
],
|
5771
|
+
functionName: "findResolver",
|
5772
|
+
args: [toHex(packetToBytes(name))],
|
5773
|
+
blockNumber,
|
5774
|
+
blockTag
|
5775
|
+
});
|
5776
|
+
return resolverAddress;
|
5777
|
+
}
|
5778
|
+
|
5238
5779
|
// src/actions/test/dropTransaction.ts
|
5239
5780
|
async function dropTransaction(client, { hash: hash2 }) {
|
5240
5781
|
return await client.request({
|
@@ -5719,6 +6260,176 @@ async function writeContract(client, {
|
|
5719
6260
|
return hash2;
|
5720
6261
|
}
|
5721
6262
|
|
6263
|
+
// src/actions/getContract.ts
|
6264
|
+
function getContract({
|
6265
|
+
abi,
|
6266
|
+
address,
|
6267
|
+
publicClient,
|
6268
|
+
walletClient
|
6269
|
+
}) {
|
6270
|
+
const hasPublicClient = publicClient !== void 0 && publicClient !== null;
|
6271
|
+
const hasWalletClient = walletClient !== void 0 && walletClient !== null;
|
6272
|
+
const contract = {};
|
6273
|
+
let hasReadFunction = false;
|
6274
|
+
let hasWriteFunction = false;
|
6275
|
+
let hasEvent = false;
|
6276
|
+
for (const item of abi) {
|
6277
|
+
if (item.type === "function")
|
6278
|
+
if (item.stateMutability === "view" || item.stateMutability === "pure")
|
6279
|
+
hasReadFunction = true;
|
6280
|
+
else
|
6281
|
+
hasWriteFunction = true;
|
6282
|
+
else if (item.type === "event")
|
6283
|
+
hasEvent = true;
|
6284
|
+
if (hasReadFunction && hasWriteFunction && hasEvent)
|
6285
|
+
break;
|
6286
|
+
}
|
6287
|
+
if (hasPublicClient) {
|
6288
|
+
if (hasReadFunction)
|
6289
|
+
contract.read = new Proxy(
|
6290
|
+
{},
|
6291
|
+
{
|
6292
|
+
get(_, functionName) {
|
6293
|
+
return (...parameters) => {
|
6294
|
+
const { args, options } = getFunctionParameters(parameters);
|
6295
|
+
return readContract(publicClient, {
|
6296
|
+
abi,
|
6297
|
+
address,
|
6298
|
+
functionName,
|
6299
|
+
args,
|
6300
|
+
...options
|
6301
|
+
});
|
6302
|
+
};
|
6303
|
+
}
|
6304
|
+
}
|
6305
|
+
);
|
6306
|
+
if (hasWriteFunction) {
|
6307
|
+
contract.estimateGas = new Proxy(
|
6308
|
+
{},
|
6309
|
+
{
|
6310
|
+
get(_, functionName) {
|
6311
|
+
return (...parameters) => {
|
6312
|
+
const { args, options } = getFunctionParameters(parameters);
|
6313
|
+
return estimateContractGas(publicClient, {
|
6314
|
+
abi,
|
6315
|
+
address,
|
6316
|
+
functionName,
|
6317
|
+
args,
|
6318
|
+
...options
|
6319
|
+
});
|
6320
|
+
};
|
6321
|
+
}
|
6322
|
+
}
|
6323
|
+
);
|
6324
|
+
contract.simulate = new Proxy(
|
6325
|
+
{},
|
6326
|
+
{
|
6327
|
+
get(_, functionName) {
|
6328
|
+
return (...parameters) => {
|
6329
|
+
const { args, options } = getFunctionParameters(parameters);
|
6330
|
+
return simulateContract(publicClient, {
|
6331
|
+
abi,
|
6332
|
+
address,
|
6333
|
+
functionName,
|
6334
|
+
args,
|
6335
|
+
...options
|
6336
|
+
});
|
6337
|
+
};
|
6338
|
+
}
|
6339
|
+
}
|
6340
|
+
);
|
6341
|
+
}
|
6342
|
+
if (hasEvent) {
|
6343
|
+
contract.createEventFilter = new Proxy(
|
6344
|
+
{},
|
6345
|
+
{
|
6346
|
+
get(_, eventName) {
|
6347
|
+
return (...parameters) => {
|
6348
|
+
const abiEvent = abi.find(
|
6349
|
+
(x) => x.type === "event" && x.name === eventName
|
6350
|
+
);
|
6351
|
+
const { args, options } = getEventParameters(
|
6352
|
+
parameters,
|
6353
|
+
abiEvent
|
6354
|
+
);
|
6355
|
+
return createContractEventFilter(publicClient, {
|
6356
|
+
abi,
|
6357
|
+
address,
|
6358
|
+
eventName,
|
6359
|
+
args,
|
6360
|
+
...options
|
6361
|
+
});
|
6362
|
+
};
|
6363
|
+
}
|
6364
|
+
}
|
6365
|
+
);
|
6366
|
+
contract.watchEvent = new Proxy(
|
6367
|
+
{},
|
6368
|
+
{
|
6369
|
+
get(_, eventName) {
|
6370
|
+
return (...parameters) => {
|
6371
|
+
const abiEvent = abi.find(
|
6372
|
+
(x) => x.type === "event" && x.name === eventName
|
6373
|
+
);
|
6374
|
+
const { args, options } = getEventParameters(
|
6375
|
+
parameters,
|
6376
|
+
abiEvent
|
6377
|
+
);
|
6378
|
+
return watchContractEvent(publicClient, {
|
6379
|
+
abi,
|
6380
|
+
address,
|
6381
|
+
eventName,
|
6382
|
+
args,
|
6383
|
+
...options
|
6384
|
+
});
|
6385
|
+
};
|
6386
|
+
}
|
6387
|
+
}
|
6388
|
+
);
|
6389
|
+
}
|
6390
|
+
}
|
6391
|
+
if (hasWalletClient) {
|
6392
|
+
if (hasWriteFunction)
|
6393
|
+
contract.write = new Proxy(
|
6394
|
+
{},
|
6395
|
+
{
|
6396
|
+
get(_, functionName) {
|
6397
|
+
return (...parameters) => {
|
6398
|
+
const { args, options } = getFunctionParameters(parameters);
|
6399
|
+
return writeContract(walletClient, {
|
6400
|
+
abi,
|
6401
|
+
address,
|
6402
|
+
functionName,
|
6403
|
+
args,
|
6404
|
+
...options
|
6405
|
+
});
|
6406
|
+
};
|
6407
|
+
}
|
6408
|
+
}
|
6409
|
+
);
|
6410
|
+
}
|
6411
|
+
return contract;
|
6412
|
+
}
|
6413
|
+
function getFunctionParameters(values) {
|
6414
|
+
const hasArgs = values.length && Array.isArray(values[0]);
|
6415
|
+
const args = hasArgs ? values[0] : [];
|
6416
|
+
const options = (hasArgs ? values[1] : values[0]) ?? {};
|
6417
|
+
return { args, options };
|
6418
|
+
}
|
6419
|
+
function getEventParameters(values, abiEvent) {
|
6420
|
+
let hasArgs = false;
|
6421
|
+
if (Array.isArray(values[0]))
|
6422
|
+
hasArgs = true;
|
6423
|
+
else if (values.length === 1) {
|
6424
|
+
hasArgs = abiEvent.inputs.some((x) => x.indexed);
|
6425
|
+
} else if (values.length === 2) {
|
6426
|
+
hasArgs = true;
|
6427
|
+
}
|
6428
|
+
const args = hasArgs ? values[0] : void 0;
|
6429
|
+
const options = (hasArgs ? values[1] : values[0]) ?? {};
|
6430
|
+
return { args, options };
|
6431
|
+
}
|
6432
|
+
|
5722
6433
|
// src/utils/unit/parseUnits.ts
|
5723
6434
|
function parseUnits(value, decimals) {
|
5724
6435
|
let [integer, fraction = "0"] = value.split(".");
|
@@ -6221,6 +6932,7 @@ function parseEther(ether, unit = "wei") {
|
|
6221
6932
|
}
|
6222
6933
|
|
6223
6934
|
export {
|
6935
|
+
multicall3Abi,
|
6224
6936
|
BaseError,
|
6225
6937
|
AbiConstructorNotFoundError,
|
6226
6938
|
AbiConstructorParamsNotFoundError,
|
@@ -6246,8 +6958,6 @@ export {
|
|
6246
6958
|
BlockNotFoundError,
|
6247
6959
|
ChainDoesNotSupportContract,
|
6248
6960
|
InvalidChainIdError,
|
6249
|
-
multicall3Abi,
|
6250
|
-
panicReasons,
|
6251
6961
|
etherUnits,
|
6252
6962
|
gweiUnits,
|
6253
6963
|
weiUnits,
|
@@ -6268,6 +6978,7 @@ export {
|
|
6268
6978
|
InvalidHexBooleanError,
|
6269
6979
|
InvalidHexValueError,
|
6270
6980
|
OffsetOutOfBoundsError,
|
6981
|
+
EnsAvatarUriResolutionError,
|
6271
6982
|
EstimateGasExecutionError,
|
6272
6983
|
FilterTypeNotSupportedError,
|
6273
6984
|
ExecutionRevertedError,
|
@@ -6413,6 +7124,20 @@ export {
|
|
6413
7124
|
assertRequest,
|
6414
7125
|
getSerializedTransactionType,
|
6415
7126
|
getTransactionType,
|
7127
|
+
parseUnits,
|
7128
|
+
parseGwei,
|
7129
|
+
prepareRequest,
|
7130
|
+
assertTransactionEIP1559,
|
7131
|
+
assertTransactionEIP2930,
|
7132
|
+
assertTransactionLegacy,
|
7133
|
+
parseTransaction,
|
7134
|
+
serializeTransaction,
|
7135
|
+
formatUnits,
|
7136
|
+
formatEther,
|
7137
|
+
formatGwei,
|
7138
|
+
parseEther,
|
7139
|
+
labelhash,
|
7140
|
+
namehash,
|
6416
7141
|
call,
|
6417
7142
|
simulateContract,
|
6418
7143
|
createPendingTransactionFilter,
|
@@ -6447,6 +7172,11 @@ export {
|
|
6447
7172
|
watchContractEvent,
|
6448
7173
|
watchEvent,
|
6449
7174
|
watchPendingTransactions,
|
7175
|
+
getEnsAddress,
|
7176
|
+
getEnsText,
|
7177
|
+
getEnsAvatar,
|
7178
|
+
getEnsName,
|
7179
|
+
getEnsResolver,
|
6450
7180
|
dropTransaction,
|
6451
7181
|
getAutomine,
|
6452
7182
|
getTxpoolContent,
|
@@ -6487,17 +7217,6 @@ export {
|
|
6487
7217
|
switchChain,
|
6488
7218
|
watchAsset,
|
6489
7219
|
writeContract,
|
6490
|
-
|
6491
|
-
parseGwei,
|
6492
|
-
prepareRequest,
|
6493
|
-
assertTransactionEIP1559,
|
6494
|
-
assertTransactionEIP2930,
|
6495
|
-
assertTransactionLegacy,
|
6496
|
-
parseTransaction,
|
6497
|
-
serializeTransaction,
|
6498
|
-
formatUnits,
|
6499
|
-
formatEther,
|
6500
|
-
formatGwei,
|
6501
|
-
parseEther
|
7220
|
+
getContract
|
6502
7221
|
};
|
6503
|
-
//# sourceMappingURL=chunk-
|
7222
|
+
//# sourceMappingURL=chunk-KILBOPDD.mjs.map
|