viem 0.0.1-alpha.0 → 0.0.1-alpha.1
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/README.md +16 -0
- package/dist/actions/index.d.ts +3 -7
- package/dist/actions/index.js +4 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chains.js +1 -1
- package/dist/{chunk-JSYJDK4W.js → chunk-LLYFXUSV.js} +99 -33
- package/dist/{chunk-OPR6LKYX.js → chunk-OQTFTQTO.js} +43 -17
- package/dist/{chunk-GI67STNV.js → chunk-Z6LRV6XI.js} +534 -25
- package/dist/clients/index.d.ts +2 -2
- package/dist/clients/index.js +6 -4
- package/dist/{createWalletClient-c40fef16.d.ts → createWalletClient-915223f3.d.ts} +5 -5
- package/dist/index.d.ts +5 -4
- package/dist/index.js +17 -5
- package/dist/{parseGwei-a7d0bcb2.d.ts → parseGwei-bbc055e4.d.ts} +60 -9
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +5 -1
- package/dist/{watchAsset-bb30848d.d.ts → watchAsset-04ab8db5.d.ts} +20 -22
- package/dist/{webSocket-14584a7e.d.ts → webSocket-c6e0d26f.d.ts} +25 -14
- package/package.json +61 -10
@@ -9,15 +9,29 @@ var __publicField = (obj, key, value) => {
|
|
9
9
|
var package_default = {
|
10
10
|
name: "viem",
|
11
11
|
description: "TypeScript (& JavaScript) Interface for Ethereum",
|
12
|
-
version: "0.0.1-alpha.
|
12
|
+
version: "0.0.1-alpha.1",
|
13
13
|
scripts: {
|
14
|
+
anvil: "source .env && anvil --fork-url $ANVIL_FORK_URL --fork-block-number $VITE_ANVIL_BLOCK_NUMBER --block-time $VITE_ANVIL_BLOCK_TIME",
|
15
|
+
bench: "vitest bench --no-threads",
|
16
|
+
"bench:ci": "CI=true vitest bench --no-threads",
|
14
17
|
build: "tsup",
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
"
|
20
|
-
|
18
|
+
changeset: "changeset",
|
19
|
+
"changeset:release": "pnpm build && changeset publish",
|
20
|
+
"changeset:version": "changeset version && pnpm install --lockfile-only",
|
21
|
+
dev: "DEV=true tsup",
|
22
|
+
"dev:docs": "pnpm -r --filter site dev",
|
23
|
+
format: "rome format src/ test/ --write",
|
24
|
+
lint: "rome check .",
|
25
|
+
"lint:fix": "pnpm lint --apply-suggested",
|
26
|
+
playground: "pnpm --filter playground-dev dev",
|
27
|
+
"playground:benchmark": "pnpm --filter playground-benchmark dev",
|
28
|
+
postinstall: "pnpm dev",
|
29
|
+
preinstall: "npx only-allow pnpm",
|
30
|
+
prepare: "npx simple-git-hooks",
|
31
|
+
test: "vitest dev --coverage --no-threads",
|
32
|
+
"test:ci": "CI=true vitest --coverage --no-threads",
|
33
|
+
"test:ui": "vitest dev --ui --no-threads",
|
34
|
+
typecheck: "tsc --noEmit"
|
21
35
|
},
|
22
36
|
files: [
|
23
37
|
"/actions",
|
@@ -59,17 +73,60 @@ var package_default = {
|
|
59
73
|
main: "dist/index.js",
|
60
74
|
types: "dist/index.d.ts",
|
61
75
|
sideEffects: false,
|
62
|
-
|
76
|
+
dependencies: {
|
77
|
+
"@noble/hashes": "^1.1.2",
|
78
|
+
"@wagmi/chains": "^0.1.0",
|
79
|
+
abitype: "^0.2.5"
|
80
|
+
},
|
81
|
+
devDependencies: {
|
82
|
+
"@actions/core": "^1.10.0",
|
83
|
+
"@actions/github": "^5.1.1",
|
84
|
+
"@changesets/changelog-github": "^0.4.5",
|
85
|
+
"@changesets/cli": "^2.23.2",
|
86
|
+
"@testing-library/jest-dom": "^5.16.5",
|
87
|
+
"@types/dedent": "^0.7.0",
|
88
|
+
"@types/fs-extra": "^9.0.13",
|
89
|
+
"@types/node": "^17.0.45",
|
90
|
+
"@vitest/coverage-c8": "^0.24.3",
|
91
|
+
"@vitest/ui": "^0.19.1",
|
92
|
+
bundlewatch: "^0.3.3",
|
93
|
+
dedent: "^0.7.0",
|
94
|
+
esbuild: "^0.16.12",
|
95
|
+
"esbuild-register": "^3.4.2",
|
96
|
+
"essential-eth": "^0.6.2",
|
97
|
+
ethers: "^5.7.2",
|
98
|
+
execa: "^6.1.0",
|
99
|
+
"fs-extra": "^10.1.0",
|
100
|
+
jsdom: "^20.0.0",
|
101
|
+
rome: "^11.0.0",
|
102
|
+
"simple-git-hooks": "^2.8.1",
|
103
|
+
tsup: "^6.5.0",
|
104
|
+
typescript: "^4.9.3",
|
105
|
+
vite: "^3.0.4",
|
106
|
+
vitest: "^0.25.2",
|
107
|
+
web3: "^1.8.1"
|
108
|
+
},
|
109
|
+
license: "MIT",
|
63
110
|
repository: "wagmi-dev/viem",
|
64
|
-
|
65
|
-
|
111
|
+
authors: [
|
112
|
+
"awkweb.eth",
|
113
|
+
"jxom.eth"
|
114
|
+
],
|
66
115
|
keywords: [
|
67
116
|
"eth",
|
68
117
|
"ethereum",
|
69
118
|
"dapps",
|
70
119
|
"wallet",
|
71
120
|
"web3"
|
72
|
-
]
|
121
|
+
],
|
122
|
+
"simple-git-hooks": {
|
123
|
+
"pre-commit": "pnpm format & pnpm lint:fix"
|
124
|
+
},
|
125
|
+
pnpm: {
|
126
|
+
patchedDependencies: {
|
127
|
+
"vitepress@1.0.0-alpha.34": "patches/vitepress@1.0.0-alpha.34.patch"
|
128
|
+
}
|
129
|
+
}
|
73
130
|
};
|
74
131
|
|
75
132
|
// src/utils/BaseError.ts
|
@@ -80,11 +137,11 @@ var BaseError = class extends Error {
|
|
80
137
|
const docsPath = args.cause instanceof BaseError ? args.cause.docsPath || args.docsPath : args.docsPath;
|
81
138
|
const message = [
|
82
139
|
humanMessage,
|
83
|
-
...docsPath ? ["",
|
140
|
+
...docsPath ? ["", `Docs: https://viem.sh${docsPath}`] : [],
|
84
141
|
"",
|
85
|
-
...details ? [
|
86
|
-
|
87
|
-
...args.cause && !(args.cause instanceof BaseError) && Object.keys(args.cause).length > 0 ? [
|
142
|
+
...details ? [`Details: ${details}`] : [],
|
143
|
+
`Version: viem@${version}`,
|
144
|
+
...args.cause && !(args.cause instanceof BaseError) && Object.keys(args.cause).length > 0 ? [`Internal Error: ${JSON.stringify(args.cause)}`] : []
|
88
145
|
].join("\n");
|
89
146
|
super(message);
|
90
147
|
__publicField(this, "humanMessage");
|
@@ -157,7 +214,10 @@ function padHex(hex_, { dir, size: size2 = 32 } = {}) {
|
|
157
214
|
targetSize: size2,
|
158
215
|
type: "hex"
|
159
216
|
});
|
160
|
-
return
|
217
|
+
return `0x${hex[dir === "right" ? "padEnd" : "padStart"](
|
218
|
+
size2 * 2,
|
219
|
+
"0"
|
220
|
+
)}`;
|
161
221
|
}
|
162
222
|
function padBytes(bytes, { dir, size: size2 = 32 } = {}) {
|
163
223
|
if (bytes.length > size2)
|
@@ -199,7 +259,7 @@ function trim(hexOrBytes, { dir = "left" } = {}) {
|
|
199
259
|
data = dir === "left" ? data.slice(sliceLength) : data.slice(0, data.length - sliceLength);
|
200
260
|
if (typeof hexOrBytes === "string") {
|
201
261
|
if (data.length === 1 && dir === "right")
|
202
|
-
data = data
|
262
|
+
data = `${data}0`;
|
203
263
|
return `0x${data}`;
|
204
264
|
}
|
205
265
|
return data;
|
@@ -312,7 +372,7 @@ function encodeBytes(value) {
|
|
312
372
|
function hexToBytes(hex_) {
|
313
373
|
let hex = hex_.slice(2);
|
314
374
|
if (hex.length % 2)
|
315
|
-
hex =
|
375
|
+
hex = `0${hex}`;
|
316
376
|
const bytes = new Uint8Array(hex.length / 2);
|
317
377
|
for (let index = 0; index < bytes.length; index++) {
|
318
378
|
const start = index * 2;
|
@@ -372,18 +432,26 @@ function decodeHex(hex, to) {
|
|
372
432
|
return hexToBool(hex);
|
373
433
|
return hexToBytes(hex);
|
374
434
|
}
|
375
|
-
function hexToBigInt(hex) {
|
376
|
-
|
435
|
+
function hexToBigInt(hex, opts = {}) {
|
436
|
+
const { signed } = opts;
|
437
|
+
const value = BigInt(hex);
|
438
|
+
if (!signed)
|
439
|
+
return value;
|
440
|
+
const size2 = (hex.length - 2) / 2;
|
441
|
+
const max = (1n << BigInt(size2) * 8n - 1n) - 1n;
|
442
|
+
if (value <= max)
|
443
|
+
return value;
|
444
|
+
return value - BigInt(`0x${"f".padStart(size2 * 2, "f")}`) - 1n;
|
377
445
|
}
|
378
446
|
function hexToBool(hex) {
|
379
|
-
if (hex === "0x0")
|
447
|
+
if (trim(hex) === "0x0")
|
380
448
|
return false;
|
381
|
-
if (hex === "0x1")
|
449
|
+
if (trim(hex) === "0x1")
|
382
450
|
return true;
|
383
451
|
throw new InvalidHexBooleanError(hex);
|
384
452
|
}
|
385
|
-
function hexToNumber(hex) {
|
386
|
-
return Number(
|
453
|
+
function hexToNumber(hex, opts = {}) {
|
454
|
+
return Number(hexToBigInt(hex, opts));
|
387
455
|
}
|
388
456
|
function hexToString(hex) {
|
389
457
|
const bytes = hexToBytes(hex);
|
@@ -639,7 +707,7 @@ function getCreateAddress(opts) {
|
|
639
707
|
if (nonce[0] === 0)
|
640
708
|
nonce = new Uint8Array([]);
|
641
709
|
return getAddress(
|
642
|
-
|
710
|
+
`0x${keccak256(encodeRlp([from, nonce], "bytes")).slice(26)}`
|
643
711
|
);
|
644
712
|
}
|
645
713
|
function getCreate2Address(opts) {
|
@@ -675,6 +743,445 @@ function isAddressEqual(a, b) {
|
|
675
743
|
return getAddress(a) === getAddress(b);
|
676
744
|
}
|
677
745
|
|
746
|
+
// src/utils/abi/encodeAbi.ts
|
747
|
+
function encodeAbi({
|
748
|
+
params,
|
749
|
+
values
|
750
|
+
}) {
|
751
|
+
if (params.length !== values.length)
|
752
|
+
throw new AbiEncodingLengthMismatchError({
|
753
|
+
expectedLength: params.length,
|
754
|
+
givenLength: values.length
|
755
|
+
});
|
756
|
+
const preparedParams = prepareParams({ params, values });
|
757
|
+
return encodeParams(preparedParams);
|
758
|
+
}
|
759
|
+
function prepareParams({
|
760
|
+
params,
|
761
|
+
values
|
762
|
+
}) {
|
763
|
+
let preparedParams = [];
|
764
|
+
for (let i = 0; i < params.length; i++) {
|
765
|
+
preparedParams.push(prepareParam({ param: params[i], value: values[i] }));
|
766
|
+
}
|
767
|
+
return preparedParams;
|
768
|
+
}
|
769
|
+
function prepareParam({
|
770
|
+
param,
|
771
|
+
value
|
772
|
+
}) {
|
773
|
+
const arrayComponents = getArrayComponents(param.type);
|
774
|
+
if (arrayComponents) {
|
775
|
+
const [length, type] = arrayComponents;
|
776
|
+
return encodeArray(value, { length, param: { ...param, type } });
|
777
|
+
}
|
778
|
+
if (param.type === "tuple") {
|
779
|
+
return encodeTuple(value, {
|
780
|
+
param
|
781
|
+
});
|
782
|
+
}
|
783
|
+
if (param.type === "address") {
|
784
|
+
return encodeAddress(value);
|
785
|
+
}
|
786
|
+
if (param.type === "bool") {
|
787
|
+
return encodeBool(value);
|
788
|
+
}
|
789
|
+
if (param.type.startsWith("uint") || param.type.startsWith("int")) {
|
790
|
+
const signed = param.type.startsWith("int");
|
791
|
+
return encodeNumber(value, { signed });
|
792
|
+
}
|
793
|
+
if (param.type.startsWith("bytes")) {
|
794
|
+
return encodeBytes2(value, { param });
|
795
|
+
}
|
796
|
+
if (param.type === "string") {
|
797
|
+
return encodeString(value);
|
798
|
+
}
|
799
|
+
throw new InvalidAbiEncodingTypeError(param.type);
|
800
|
+
}
|
801
|
+
function encodeParams(preparedParams) {
|
802
|
+
let staticSize = 0;
|
803
|
+
for (let i = 0; i < preparedParams.length; i++) {
|
804
|
+
const { dynamic, encoded } = preparedParams[i];
|
805
|
+
if (dynamic)
|
806
|
+
staticSize += 32;
|
807
|
+
else
|
808
|
+
staticSize += size(encoded);
|
809
|
+
}
|
810
|
+
let staticParams = [];
|
811
|
+
let dynamicParams = [];
|
812
|
+
let dynamicSize = 0;
|
813
|
+
for (let i = 0; i < preparedParams.length; i++) {
|
814
|
+
const { dynamic, encoded } = preparedParams[i];
|
815
|
+
if (dynamic) {
|
816
|
+
staticParams.push(numberToHex(staticSize + dynamicSize, { size: 32 }));
|
817
|
+
dynamicParams.push(encoded);
|
818
|
+
dynamicSize += size(encoded);
|
819
|
+
} else {
|
820
|
+
staticParams.push(encoded);
|
821
|
+
}
|
822
|
+
}
|
823
|
+
return concat([...staticParams, ...dynamicParams]);
|
824
|
+
}
|
825
|
+
function encodeArray(value, {
|
826
|
+
length,
|
827
|
+
param
|
828
|
+
}) {
|
829
|
+
let dynamic = length === null;
|
830
|
+
if (!Array.isArray(value))
|
831
|
+
throw new InvalidArrayError(value);
|
832
|
+
if (!dynamic && value.length !== length)
|
833
|
+
throw new AbiEncodingArrayLengthMismatchError({
|
834
|
+
expectedLength: length,
|
835
|
+
givenLength: value.length,
|
836
|
+
type: `${param.type}[${length}]`
|
837
|
+
});
|
838
|
+
let dynamicChild = false;
|
839
|
+
let preparedParams = [];
|
840
|
+
for (let i = 0; i < value.length; i++) {
|
841
|
+
const preparedParam = prepareParam({ param, value: value[i] });
|
842
|
+
if (preparedParam.dynamic)
|
843
|
+
dynamicChild = true;
|
844
|
+
preparedParams.push(preparedParam);
|
845
|
+
}
|
846
|
+
if (dynamic || dynamicChild) {
|
847
|
+
const data = encodeParams(preparedParams);
|
848
|
+
if (dynamic) {
|
849
|
+
const length2 = numberToHex(preparedParams.length, { size: 32 });
|
850
|
+
return {
|
851
|
+
dynamic: true,
|
852
|
+
encoded: preparedParams.length > 0 ? concat([length2, data]) : length2
|
853
|
+
};
|
854
|
+
}
|
855
|
+
if (dynamicChild)
|
856
|
+
return { dynamic: true, encoded: data };
|
857
|
+
}
|
858
|
+
return {
|
859
|
+
dynamic: false,
|
860
|
+
encoded: concat(preparedParams.map(({ encoded }) => encoded))
|
861
|
+
};
|
862
|
+
}
|
863
|
+
function encodeTuple(value, { param }) {
|
864
|
+
let dynamic = false;
|
865
|
+
let preparedParams = [];
|
866
|
+
for (let i = 0; i < param.components.length; i++) {
|
867
|
+
const param_ = param.components[i];
|
868
|
+
const index = Array.isArray(value) ? i : param_.name;
|
869
|
+
const preparedParam = prepareParam({
|
870
|
+
param: param_,
|
871
|
+
value: value[index]
|
872
|
+
});
|
873
|
+
preparedParams.push(preparedParam);
|
874
|
+
dynamic = preparedParam.dynamic;
|
875
|
+
}
|
876
|
+
return {
|
877
|
+
dynamic,
|
878
|
+
encoded: dynamic ? encodeParams(preparedParams) : concat(preparedParams.map(({ encoded }) => encoded))
|
879
|
+
};
|
880
|
+
}
|
881
|
+
function encodeAddress(value) {
|
882
|
+
return { dynamic: false, encoded: padHex(value.toLowerCase()) };
|
883
|
+
}
|
884
|
+
function encodeBytes2(value, { param }) {
|
885
|
+
const [_, size_] = param.type.split("bytes");
|
886
|
+
if (!size_)
|
887
|
+
return {
|
888
|
+
dynamic: true,
|
889
|
+
encoded: concat([
|
890
|
+
padHex(numberToHex(size(value), { size: 32 })),
|
891
|
+
padHex(value, { dir: "right" })
|
892
|
+
])
|
893
|
+
};
|
894
|
+
return { dynamic: false, encoded: padHex(value, { dir: "right" }) };
|
895
|
+
}
|
896
|
+
function encodeBool(value) {
|
897
|
+
return { dynamic: false, encoded: padHex(boolToHex(value)) };
|
898
|
+
}
|
899
|
+
function encodeNumber(value, { signed }) {
|
900
|
+
return {
|
901
|
+
dynamic: false,
|
902
|
+
encoded: numberToHex(value, {
|
903
|
+
size: 32,
|
904
|
+
signed
|
905
|
+
})
|
906
|
+
};
|
907
|
+
}
|
908
|
+
function encodeString(value) {
|
909
|
+
return {
|
910
|
+
dynamic: true,
|
911
|
+
encoded: concat([
|
912
|
+
padHex(numberToHex(value.length, { size: 32 })),
|
913
|
+
padHex(stringToHex(value), { dir: "right" })
|
914
|
+
])
|
915
|
+
};
|
916
|
+
}
|
917
|
+
function getArrayComponents(type) {
|
918
|
+
const matches = type.match(/^(.*)\[(\d+)?\]$/);
|
919
|
+
return matches ? [matches[2] ? Number(matches[2]) : null, matches[1]] : void 0;
|
920
|
+
}
|
921
|
+
var AbiEncodingArrayLengthMismatchError = class extends BaseError {
|
922
|
+
constructor({
|
923
|
+
expectedLength,
|
924
|
+
givenLength,
|
925
|
+
type
|
926
|
+
}) {
|
927
|
+
super(
|
928
|
+
[
|
929
|
+
`ABI encoding array length mismatch for type ${type}.`,
|
930
|
+
`Expected length: ${expectedLength}`,
|
931
|
+
`Given length: ${givenLength}`
|
932
|
+
].join("\n")
|
933
|
+
);
|
934
|
+
__publicField(this, "name", "AbiEncodingArrayLengthMismatchError");
|
935
|
+
}
|
936
|
+
};
|
937
|
+
var AbiEncodingLengthMismatchError = class extends BaseError {
|
938
|
+
constructor({
|
939
|
+
expectedLength,
|
940
|
+
givenLength
|
941
|
+
}) {
|
942
|
+
super(
|
943
|
+
[
|
944
|
+
"ABI encoding params/values length mismatch.",
|
945
|
+
`Expected length (params): ${expectedLength}`,
|
946
|
+
`Given length (values): ${givenLength}`
|
947
|
+
].join("\n")
|
948
|
+
);
|
949
|
+
__publicField(this, "name", "AbiEncodingLengthMismatchError");
|
950
|
+
}
|
951
|
+
};
|
952
|
+
var InvalidAbiEncodingTypeError = class extends BaseError {
|
953
|
+
constructor(type) {
|
954
|
+
super(
|
955
|
+
[
|
956
|
+
`Type "${type}" is not a valid encoding type.`,
|
957
|
+
"Please provide a valid ABI type."
|
958
|
+
].join("\n"),
|
959
|
+
{ docsPath: "/docs/contract/encodeAbi#params" }
|
960
|
+
);
|
961
|
+
__publicField(this, "name", "InvalidAbiEncodingType");
|
962
|
+
}
|
963
|
+
};
|
964
|
+
var InvalidArrayError = class extends BaseError {
|
965
|
+
constructor(value) {
|
966
|
+
super([`Value "${value}" is not a valid array.`].join("\n"));
|
967
|
+
__publicField(this, "name", "InvalidArrayError");
|
968
|
+
}
|
969
|
+
};
|
970
|
+
|
971
|
+
// src/utils/abi/decodeAbi.ts
|
972
|
+
function decodeAbi({
|
973
|
+
data,
|
974
|
+
params
|
975
|
+
}) {
|
976
|
+
if (size(data) % 32 !== 0)
|
977
|
+
throw new AbiDecodingDataSizeInvalidError(size(data));
|
978
|
+
return decodeParams({
|
979
|
+
data,
|
980
|
+
params
|
981
|
+
});
|
982
|
+
}
|
983
|
+
function decodeParams({
|
984
|
+
data,
|
985
|
+
params
|
986
|
+
}) {
|
987
|
+
let decodedValues = [];
|
988
|
+
let position = 0;
|
989
|
+
for (let i = 0; i < params.length; i++) {
|
990
|
+
const param = params[i];
|
991
|
+
const { consumed, value } = decodeParam({ data, param, position });
|
992
|
+
decodedValues.push(value);
|
993
|
+
position += consumed;
|
994
|
+
}
|
995
|
+
return decodedValues;
|
996
|
+
}
|
997
|
+
function decodeParam({
|
998
|
+
data,
|
999
|
+
param,
|
1000
|
+
position
|
1001
|
+
}) {
|
1002
|
+
const arrayComponents = getArrayComponents(param.type);
|
1003
|
+
if (arrayComponents) {
|
1004
|
+
const [length, type] = arrayComponents;
|
1005
|
+
return decodeArray(data, {
|
1006
|
+
length,
|
1007
|
+
param: { ...param, type },
|
1008
|
+
position
|
1009
|
+
});
|
1010
|
+
}
|
1011
|
+
if (param.type === "tuple") {
|
1012
|
+
return decodeTuple(data, { param, position });
|
1013
|
+
}
|
1014
|
+
if (param.type === "string") {
|
1015
|
+
return decodeString(data, { position });
|
1016
|
+
}
|
1017
|
+
if (param.type.startsWith("bytes")) {
|
1018
|
+
return decodeBytes2(data, { param, position });
|
1019
|
+
}
|
1020
|
+
let value = slice(data, position, position + 32);
|
1021
|
+
if (param.type.startsWith("uint") || param.type.startsWith("int")) {
|
1022
|
+
return decodeNumber(value, { param });
|
1023
|
+
}
|
1024
|
+
if (param.type === "address") {
|
1025
|
+
return decodeAddress(value);
|
1026
|
+
}
|
1027
|
+
if (param.type === "bool") {
|
1028
|
+
return decodeBool(value);
|
1029
|
+
}
|
1030
|
+
throw new InvalidAbiDecodingTypeError(param.type);
|
1031
|
+
}
|
1032
|
+
function decodeArray(data, {
|
1033
|
+
param,
|
1034
|
+
length,
|
1035
|
+
position
|
1036
|
+
}) {
|
1037
|
+
if (!length) {
|
1038
|
+
const offset = hexToNumber(slice(data, position, position + 32));
|
1039
|
+
const length2 = hexToNumber(slice(data, offset, offset + 32));
|
1040
|
+
let consumed2 = 0;
|
1041
|
+
let value2 = [];
|
1042
|
+
for (let i = 0; i < length2; ++i) {
|
1043
|
+
const decodedChild = decodeParam({
|
1044
|
+
data: slice(data, offset + 32),
|
1045
|
+
param,
|
1046
|
+
position: consumed2
|
1047
|
+
});
|
1048
|
+
consumed2 += decodedChild.consumed;
|
1049
|
+
value2.push(decodedChild.value);
|
1050
|
+
}
|
1051
|
+
return { value: value2, consumed: 32 };
|
1052
|
+
}
|
1053
|
+
if (hasDynamicChild(param)) {
|
1054
|
+
const arrayComponents = getArrayComponents(param.type);
|
1055
|
+
const dynamicChild = !arrayComponents?.[0];
|
1056
|
+
let consumed2 = 0;
|
1057
|
+
let value2 = [];
|
1058
|
+
for (let i = 0; i < length; ++i) {
|
1059
|
+
const offset = hexToNumber(slice(data, position, position + 32));
|
1060
|
+
const decodedChild = decodeParam({
|
1061
|
+
data: slice(data, offset),
|
1062
|
+
param,
|
1063
|
+
position: dynamicChild ? consumed2 : i * 32
|
1064
|
+
});
|
1065
|
+
consumed2 += decodedChild.consumed;
|
1066
|
+
value2.push(decodedChild.value);
|
1067
|
+
}
|
1068
|
+
return { value: value2, consumed: consumed2 };
|
1069
|
+
}
|
1070
|
+
let consumed = 0;
|
1071
|
+
let value = [];
|
1072
|
+
for (let i = 0; i < length; ++i) {
|
1073
|
+
const decodedChild = decodeParam({
|
1074
|
+
data,
|
1075
|
+
param,
|
1076
|
+
position: position + consumed
|
1077
|
+
});
|
1078
|
+
consumed += decodedChild.consumed;
|
1079
|
+
value.push(decodedChild.value);
|
1080
|
+
}
|
1081
|
+
return { value, consumed };
|
1082
|
+
}
|
1083
|
+
function decodeAddress(value) {
|
1084
|
+
return { consumed: 32, value: checksumAddress(trim(value)) };
|
1085
|
+
}
|
1086
|
+
function decodeBool(value) {
|
1087
|
+
return { consumed: 32, value: hexToBool(value) };
|
1088
|
+
}
|
1089
|
+
function decodeBytes2(data, { param, position }) {
|
1090
|
+
const [_, size2] = param.type.split("bytes");
|
1091
|
+
if (!size2) {
|
1092
|
+
const offset = hexToNumber(slice(data, position, position + 32));
|
1093
|
+
const length = hexToNumber(slice(data, offset, offset + 32));
|
1094
|
+
const value2 = slice(data, offset + 32, offset + 32 + length);
|
1095
|
+
return { consumed: 32, value: value2 };
|
1096
|
+
}
|
1097
|
+
const value = slice(data, position, position + parseInt(size2));
|
1098
|
+
return { consumed: 32, value };
|
1099
|
+
}
|
1100
|
+
function decodeNumber(value, { param }) {
|
1101
|
+
const signed = param.type.startsWith("int");
|
1102
|
+
const size2 = parseInt(param.type.split("int")[1] || "256");
|
1103
|
+
return {
|
1104
|
+
consumed: 32,
|
1105
|
+
value: size2 > 48 ? hexToBigInt(value, { signed }) : hexToNumber(value, { signed })
|
1106
|
+
};
|
1107
|
+
}
|
1108
|
+
function decodeString(data, { position }) {
|
1109
|
+
const offset = hexToNumber(slice(data, position, position + 32));
|
1110
|
+
const length = hexToNumber(slice(data, offset, offset + 32));
|
1111
|
+
const value = hexToString(
|
1112
|
+
trim(slice(data, offset + 32, offset + 32 + length))
|
1113
|
+
);
|
1114
|
+
return { consumed: 32, value };
|
1115
|
+
}
|
1116
|
+
function decodeTuple(data, { param, position }) {
|
1117
|
+
const hasUnnamedChild = param.components.length === 0 || param.components.some(({ name }) => !name);
|
1118
|
+
let value = hasUnnamedChild ? [] : {};
|
1119
|
+
let consumed = 0;
|
1120
|
+
if (hasDynamicChild(param)) {
|
1121
|
+
const offset = hexToNumber(slice(data, position, position + 32));
|
1122
|
+
for (let i = 0; i < param.components.length; ++i) {
|
1123
|
+
const component = param.components[i];
|
1124
|
+
const decodedChild = decodeParam({
|
1125
|
+
data: slice(data, offset),
|
1126
|
+
param: component,
|
1127
|
+
position: consumed
|
1128
|
+
});
|
1129
|
+
consumed += decodedChild.consumed;
|
1130
|
+
value[hasUnnamedChild ? i : component?.name] = decodedChild.value;
|
1131
|
+
}
|
1132
|
+
return { consumed: 32, value };
|
1133
|
+
}
|
1134
|
+
for (let i = 0; i < param.components.length; ++i) {
|
1135
|
+
const component = param.components[i];
|
1136
|
+
const decodedChild = decodeParam({
|
1137
|
+
data,
|
1138
|
+
param: component,
|
1139
|
+
position: position + consumed
|
1140
|
+
});
|
1141
|
+
consumed += decodedChild.consumed;
|
1142
|
+
value[hasUnnamedChild ? i : component?.name] = decodedChild.value;
|
1143
|
+
}
|
1144
|
+
return { consumed, value };
|
1145
|
+
}
|
1146
|
+
function hasDynamicChild(param) {
|
1147
|
+
const { type } = param;
|
1148
|
+
if (type === "string")
|
1149
|
+
return true;
|
1150
|
+
if (type === "bytes")
|
1151
|
+
return true;
|
1152
|
+
if (type.endsWith("[]"))
|
1153
|
+
return true;
|
1154
|
+
if (type === "tuple")
|
1155
|
+
return param.components?.some(hasDynamicChild);
|
1156
|
+
const arrayComponents = getArrayComponents(param.type);
|
1157
|
+
if (arrayComponents && hasDynamicChild({ ...param, type: arrayComponents[1] }))
|
1158
|
+
return true;
|
1159
|
+
return false;
|
1160
|
+
}
|
1161
|
+
var AbiDecodingDataSizeInvalidError = class extends BaseError {
|
1162
|
+
constructor(size2) {
|
1163
|
+
super(
|
1164
|
+
[
|
1165
|
+
`Data size of ${size2} bytes is invalid.`,
|
1166
|
+
"Size must be in increments of 32 bytes (size % 32 === 0)."
|
1167
|
+
].join("\n")
|
1168
|
+
);
|
1169
|
+
__publicField(this, "name", "AbiDecodingDataSizeInvalidError");
|
1170
|
+
}
|
1171
|
+
};
|
1172
|
+
var InvalidAbiDecodingTypeError = class extends BaseError {
|
1173
|
+
constructor(type) {
|
1174
|
+
super(
|
1175
|
+
[
|
1176
|
+
`Type "${type}" is not a valid decoding type.`,
|
1177
|
+
"Please provide a valid ABI type."
|
1178
|
+
].join("\n"),
|
1179
|
+
{ docsPath: "/docs/contract/decodeAbi#params" }
|
1180
|
+
);
|
1181
|
+
__publicField(this, "name", "InvalidAbiDecodingType");
|
1182
|
+
}
|
1183
|
+
};
|
1184
|
+
|
678
1185
|
// src/utils/buildRequest.ts
|
679
1186
|
function buildRequest(request) {
|
680
1187
|
return async (args) => {
|
@@ -1427,6 +1934,8 @@ export {
|
|
1427
1934
|
getCreate2Address,
|
1428
1935
|
isAddress,
|
1429
1936
|
isAddressEqual,
|
1937
|
+
encodeAbi,
|
1938
|
+
decodeAbi,
|
1430
1939
|
buildRequest,
|
1431
1940
|
RpcRequestError,
|
1432
1941
|
ParseRpcError,
|
package/dist/clients/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
export { C as Client, a as ClientConfig, P as PublicClient, b as PublicClientConfig, T as TestClient, c as TestClientConfig, d as Transport, e as TransportConfig, W as WalletClient, f as WalletClientConfig, g as createClient, h as createPublicClient, i as createTestClient, j as createTransport, k as createWalletClient } from '../createWalletClient-
|
2
|
-
export {
|
1
|
+
export { C as Client, a as ClientConfig, P as PublicClient, b as PublicClientConfig, T as TestClient, c as TestClientConfig, d as Transport, e as TransportConfig, W as WalletClient, f as WalletClientConfig, g as createClient, h as createPublicClient, i as createTestClient, j as createTransport, k as createWalletClient } from '../createWalletClient-915223f3.js';
|
2
|
+
export { C as CustomTransport, a as CustomTransportConfig, F as FallbackTransport, b as FallbackTransportConfig, H as HttpTransport, c as HttpTransportConfig, U as UrlRequiredError, W as WebSocketTransport, d as WebSocketTransportConfig, e as custom, f as fallback, h as http, w as webSocket } from '../webSocket-c6e0d26f.js';
|
3
3
|
import '../chains.js';
|
4
4
|
import '../rpc-655c0ba4.js';
|
5
5
|
import '@wagmi/chains';
|
package/dist/clients/index.js
CHANGED
@@ -5,11 +5,12 @@ import {
|
|
5
5
|
createTestClient,
|
6
6
|
createTransport,
|
7
7
|
createWalletClient,
|
8
|
-
|
8
|
+
custom,
|
9
|
+
fallback,
|
9
10
|
http,
|
10
11
|
webSocket
|
11
|
-
} from "../chunk-
|
12
|
-
import "../chunk-
|
12
|
+
} from "../chunk-OQTFTQTO.js";
|
13
|
+
import "../chunk-Z6LRV6XI.js";
|
13
14
|
export {
|
14
15
|
UrlRequiredError,
|
15
16
|
createClient,
|
@@ -17,7 +18,8 @@ export {
|
|
17
18
|
createTestClient,
|
18
19
|
createTransport,
|
19
20
|
createWalletClient,
|
20
|
-
|
21
|
+
custom,
|
22
|
+
fallback,
|
21
23
|
http,
|
22
24
|
webSocket
|
23
25
|
};
|