Skip to content

Commit

Permalink
fix(proxy): propagate value function bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Apr 2, 2023
1 parent 4e780eb commit 0301cb2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 54 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@
"conventional-changelog-conventionalcommits": "^5.0.0",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.3",
"eslint": "^8.36.0",
"eslint": "^8.37.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.0",
"prettier": "^2.8.7",
"ts-jest": "^29.0.5",
"ts-jest": "^29.1.0",
"typechain": "^8.1.1",
"typescript": "^5.0.2"
"typescript": "^5.0.3"
},
"peerDependencies": {
"@ethersproject/providers": "^5.0.0",
Expand Down
30 changes: 17 additions & 13 deletions src/multicall-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,21 @@ export class MulticallWrapper {
multicallProvider,
Object.fromEntries(
Object.entries(Object.getOwnPropertyDescriptors(prototype)).map(
([name, { value, get, set, ...descriptor }]) => [
name,
{
...descriptor,
...(value !== undefined && { value }),
...(get != null && { get: get.bind(provider) }),
...(set != null && { set: set.bind(provider) }),
},
]
([name, { value, get, set, ...descriptor }]) => {
// console.log(name, value);

return [
name,
{
...descriptor,
...(value !== undefined && {
value: typeof value === "function" ? value.bind(provider) : value,
}),
...(get != null && { get: get.bind(provider) }),
...(set != null && { set: set.bind(provider) }),
},
];
}
)
)
);
Expand Down Expand Up @@ -202,10 +208,8 @@ export class MulticallWrapper {

// Overload `BaseProvider.perform`

const _perform = provider.perform.bind(provider);

multicallProvider.perform = async function (method: string, params: any): Promise<string> {
if (method !== "call") return _perform(method, params);
if (method !== "call") return this._provider.perform(method, params);

const {
transaction: { to, data },
Expand All @@ -219,7 +223,7 @@ export class MulticallWrapper {
const multicallVersion = getMulticallVersion(blockNumber, this.network.chainId);

if (!to || !data || multicallVersion == null || multicallAddresses.has(to.toLowerCase()))
return _perform(method, params);
return this._provider.perform(method, params);

this._debouncedPerformMulticall();

Expand Down
19 changes: 11 additions & 8 deletions test/multicall-provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ describe("ethers-multicall-provider", () => {
const result = await Promise.all([uni.name(), uni.symbol(), uni.decimals()]);

expect(result).toEqual(["Uniswap", "UNI", 18]);
expect(provider.send).toHaveBeenCalledTimes(2);
expect(provider.send).toHaveBeenCalledTimes(3);
expect(provider.send).toHaveBeenNthCalledWith(1, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_call", [
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(3, "eth_call", [
{
data: "0xbce38bd7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001600000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004313ce567000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000495d89b41000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000406fdde0300000000000000000000000000000000000000000000000000000000",
to: "0xca11bde05977b3631167028862be2a173976ca11",
Expand All @@ -144,9 +145,10 @@ describe("ethers-multicall-provider", () => {
expect(uni.symbol()).resolves.toEqual("UNI");
expect(await uni.decimals()).toEqual(18);

expect(provider.send).toHaveBeenCalledTimes(2);
expect(provider.send).toHaveBeenCalledTimes(3);
expect(provider.send).toHaveBeenNthCalledWith(1, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_call", [
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(3, "eth_call", [
{
data: "0xbce38bd7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001600000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004313ce567000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000495d89b41000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000406fdde0300000000000000000000000000000000000000000000000000000000",
to: multicall3Address.toLowerCase(),
Expand All @@ -165,9 +167,10 @@ describe("ethers-multicall-provider", () => {
]);

expect(result).toEqual(["Uniswap", "UNI", 18]);
expect(provider.send).toHaveBeenCalledTimes(2);
expect(provider.send).toHaveBeenCalledTimes(3);
expect(provider.send).toHaveBeenNthCalledWith(1, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_call", [
expect(provider.send).toHaveBeenNthCalledWith(2, "eth_chainId", []);
expect(provider.send).toHaveBeenNthCalledWith(3, "eth_call", [
{
data: "0xbce38bd7000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001600000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000004313ce567000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000495d89b41000000000000000000000000000000000000000000000000000000000000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f9840000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000406fdde0300000000000000000000000000000000000000000000000000000000",
to: multicall2Address.toLowerCase(),
Expand All @@ -186,7 +189,7 @@ describe("ethers-multicall-provider", () => {
]);

expect(result).toEqual(["Uniswap", "UNI", 18]);
expect(provider.send).toHaveBeenCalledTimes(3);
expect(provider.send).toHaveBeenCalledTimes(4);
});

it("should not batch calls at earliest block", async () => {
Expand All @@ -199,7 +202,7 @@ describe("ethers-multicall-provider", () => {
]);

expect(result).toEqual(["Uniswap", "UNI", 18]);
expect(provider.send).toHaveBeenCalledTimes(3);
expect(provider.send).toHaveBeenCalledTimes(4);
});

it("should throw a descriptive Error when querying unknown contract", async () => {
Expand Down
65 changes: 35 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -403,25 +403,25 @@
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.4.0.tgz#3e61c564fcd6b921cb789838631c5ee44df09403"
integrity sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ==

"@eslint/eslintrc@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.1.tgz#7888fe7ec8f21bc26d646dbd2c11cd776e21192d"
integrity sha512-eFRmABvW2E5Ho6f5fHLqgena46rOj7r7OKHYfLElqcBfGFHHpjBhivyi5+jOEQuSpdc/1phIZJlbC2te+tZNIw==
"@eslint/eslintrc@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.2.tgz#01575e38707add677cf73ca1589abba8da899a02"
integrity sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
espree "^9.5.0"
espree "^9.5.1"
globals "^13.19.0"
ignore "^5.2.0"
import-fresh "^3.2.1"
js-yaml "^4.1.0"
minimatch "^3.1.2"
strip-json-comments "^3.1.1"

"@eslint/js@8.36.0":
version "8.36.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.36.0.tgz#9837f768c03a1e4a30bd304a64fb8844f0e72efe"
integrity sha512-lxJ9R5ygVm8ZWgYdUweoq5ownDlJ4upvoWmO4eLxBYHdMo+vZ/Rx0EN6MbKWDJOSUGrqJy2Gt+Dyv/VKml0fjg==
"@eslint/js@8.37.0":
version "8.37.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.37.0.tgz#cf1b5fa24217fe007f6487a26d765274925efa7d"
integrity sha512-x5vzdtOOGgFVDCUs81QRB2+liax8rFg3+7hqM+QhBG0/G3F1ZsoYl97UrqgHgQ9KKT7G6c4V+aTUCgu/n22v1A==

"@ethersproject/[email protected]", "@ethersproject/abi@^5.0.0", "@ethersproject/abi@^5.7.0":
version "5.7.0"
Expand Down Expand Up @@ -2126,15 +2126,20 @@ eslint-visitor-keys@^3.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==

eslint@^8.36.0:
version "8.36.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.36.0.tgz#1bd72202200a5492f91803b113fb8a83b11285cf"
integrity sha512-Y956lmS7vDqomxlaaQAHVmeb4tNMp2FWIvU/RnU5BD3IKMD/MJPr76xdyr68P8tV1iNMvN2mRK0yy3c+UjL+bw==
eslint-visitor-keys@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz#c7f0f956124ce677047ddbc192a68f999454dedc"
integrity sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==

eslint@^8.37.0:
version "8.37.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.37.0.tgz#1f660ef2ce49a0bfdec0b0d698e0b8b627287412"
integrity sha512-NU3Ps9nI05GUoVMxcZx1J8CNR6xOvUT4jAUMH5+z8lpp3aEdPVCImKw6PWG4PY+Vfkpr+jvMpxs/qoE7wq0sPw==
dependencies:
"@eslint-community/eslint-utils" "^4.2.0"
"@eslint-community/regexpp" "^4.4.0"
"@eslint/eslintrc" "^2.0.1"
"@eslint/js" "8.36.0"
"@eslint/eslintrc" "^2.0.2"
"@eslint/js" "8.37.0"
"@humanwhocodes/config-array" "^0.11.8"
"@humanwhocodes/module-importer" "^1.0.1"
"@nodelib/fs.walk" "^1.2.8"
Expand All @@ -2145,8 +2150,8 @@ eslint@^8.36.0:
doctrine "^3.0.0"
escape-string-regexp "^4.0.0"
eslint-scope "^7.1.1"
eslint-visitor-keys "^3.3.0"
espree "^9.5.0"
eslint-visitor-keys "^3.4.0"
espree "^9.5.1"
esquery "^1.4.2"
esutils "^2.0.2"
fast-deep-equal "^3.1.3"
Expand All @@ -2172,14 +2177,14 @@ eslint@^8.36.0:
strip-json-comments "^3.1.0"
text-table "^0.2.0"

espree@^9.5.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.5.0.tgz#3646d4e3f58907464edba852fa047e6a27bdf113"
integrity sha512-JPbJGhKc47++oo4JkEoTe2wjy4fmMwvFpgJT9cQzmfXKp22Dr6Hf1tdCteLz1h0P3t+mGvWZ+4Uankvh8+c6zw==
espree@^9.5.1:
version "9.5.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.5.1.tgz#4f26a4d5f18905bf4f2e0bd99002aab807e96dd4"
integrity sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==
dependencies:
acorn "^8.8.0"
acorn-jsx "^5.3.2"
eslint-visitor-keys "^3.3.0"
eslint-visitor-keys "^3.4.0"

esprima@^4.0.0:
version "4.0.1"
Expand Down Expand Up @@ -4229,10 +4234,10 @@ ts-essentials@^7.0.1:
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38"
integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ==

ts-jest@^29.0.5:
version "29.0.5"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.0.5.tgz#c5557dcec8fe434fcb8b70c3e21c6b143bfce066"
integrity sha512-PL3UciSgIpQ7f6XjVOmbi96vmDHUqAyqDr8YxzopDqX3kfgYtX1cuNeBjP+L9sFXi6nzsGGA6R3fP3DDDJyrxA==
ts-jest@^29.1.0:
version "29.1.0"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.0.tgz#4a9db4104a49b76d2b368ea775b6c9535c603891"
integrity sha512-ZhNr7Z4PcYa+JjMl62ir+zPiNJfXJN6E8hSLnaUKhOgqcn8vb3e537cpkd0FuAfRK3sR1LSqM1MOhliXNgOFPA==
dependencies:
bs-logger "0.x"
fast-json-stable-stringify "2.x"
Expand Down Expand Up @@ -4322,10 +4327,10 @@ typescript@^4.6.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.2.tgz#891e1a90c5189d8506af64b9ef929fca99ba1ee5"
integrity sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==
typescript@^5.0.3:
version "5.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.3.tgz#fe976f0c826a88d0a382007681cbb2da44afdedf"
integrity sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==

typical@^4.0.0:
version "4.0.0"
Expand Down

0 comments on commit 0301cb2

Please sign in to comment.