Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix(wrap): don't clone deep
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 25, 2022
1 parent 8815964 commit 54d0fb4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/ethers.ts
@@ -1,7 +1,7 @@
import DataLoader from "dataloader";
import { Contract, ethers } from "ethers";
import { BaseContract, Contract, ethers } from "ethers";
import { FunctionFragment, Interface } from "ethers/lib/utils";
import _cloneDeep from "lodash/cloneDeep";
import _clone from "lodash/clone";

import MulticallAbi from "./abi.json";
import { Multicall, IMulticallWrapper, CallStruct } from "./interface";
Expand All @@ -14,8 +14,6 @@ export type ContractCall = {
stack?: string;
};

type TargetContract = Pick<Contract, "functions" | "interface" | "callStatic" | "address">;

export const isMulticallUnderlyingError = (err: Error) =>
err.message.includes("Multicall call failed for");

Expand Down Expand Up @@ -133,8 +131,10 @@ export class EthersMulticall implements IMulticallWrapper {
return result;
}

wrap<T extends TargetContract>(contract: T) {
const copy = Object.setPrototypeOf(_cloneDeep(contract), Object.getPrototypeOf(contract)) as T;
wrap<T extends BaseContract>(contract: T) {
const copy = Object.setPrototypeOf(_clone(contract), Object.getPrototypeOf(contract));
copy.callStatic = _clone(contract.callStatic);
copy.functions = _clone(contract.functions);

(
contract.interface.fragments.filter(
Expand All @@ -161,7 +161,7 @@ export class EthersMulticall implements IMulticallWrapper {
Object.defineProperty(copy.functions, fragment.name, descriptor);
});

return copy;
return copy as T;
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/interface.ts
Expand Up @@ -4,7 +4,6 @@ import type {
BigNumberish,
BytesLike,
CallOverrides,
Contract,
ContractTransaction,
Overrides,
PopulatedTransaction,
Expand All @@ -17,8 +16,6 @@ import type {
import type { FunctionFragment, Result } from "@ethersproject/abi";
import type { Listener } from "@ethersproject/providers";

export type TargetContract = Pick<Contract, "functions" | "interface" | "callStatic" | "address">;

export type CallStruct = { target: string; callData: BytesLike };

export type CallStructOutput = [string, string] & {
Expand Down Expand Up @@ -255,5 +252,5 @@ export interface Multicall extends BaseContract {

export interface IMulticallWrapper {
get contract(): Multicall;
wrap<T extends TargetContract>(contract: T): T;
wrap<T extends BaseContract>(contract: T): T;
}

0 comments on commit 54d0fb4

Please sign in to comment.