Skip to content

Commit

Permalink
Fixed resolving ENS addresses used as from parameters (ethers-io#3961).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 5cede27 commit 3575476
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions src.ts/contract/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "./wrappers.js";

import type { EventFragment, FunctionFragment, InterfaceAbi, ParamType, Result } from "../abi/index.js";
import type { Addressable } from "../address/index.js";
import type { Addressable, NameResolver } from "../address/index.js";
import type { EventEmitterable, Listener } from "../utils/index.js";
import type {
BlockTag, ContractRunner, Provider, TransactionRequest, TopicFilter
Expand Down Expand Up @@ -68,6 +68,14 @@ function canSend(value: any): value is ContractRunnerSender {
return (value && typeof(value.sendTransaction) === "function");
}

function getResolver(value: any): undefined | NameResolver {
if (value != null) {
if (canResolve(value)) { return value; }
if (value.provider) { return value.provider; }
}
return undefined;
}

class PreparedTopicFilter implements DeferredTopicFilter {
#filter: Promise<TopicFilter>;
readonly fragment!: EventFragment;
Expand Down Expand Up @@ -146,9 +154,7 @@ export async function copyOverrides<O extends string = "data" | "to">(arg: any,
"cannot override data", "overrides.data", overrides.data);

// Resolve any from
if (overrides.from) {
overrides.from = await resolveAddress(overrides.from);
}
if (overrides.from) { overrides.from = overrides.from; }

return <Omit<ContractTransaction, O>>overrides;
}
Expand Down Expand Up @@ -177,6 +183,10 @@ function buildWrappedFallback(contract: BaseContract): WrappedFallback {
const tx: ContractTransaction = <any>(await copyOverrides<"data">(overrides, [ "data" ]));
tx.to = await contract.getAddress();

if (tx.from) {
tx.from = await resolveAddress(tx.from, getResolver(contract.runner));
}

const iface = contract.interface;

const noValue = (getBigInt((tx.value || BN_0), "overrides.value") === BN_0);
Expand Down Expand Up @@ -271,6 +281,10 @@ function buildWrappedMethod<A extends Array<any> = Array<any>, R = any, D extend
let overrides: Omit<ContractTransaction, "data" | "to"> = { };
if (fragment.inputs.length + 1 === args.length) {
overrides = await copyOverrides(args.pop());

if (overrides.from) {
overrides.from = await resolveAddress(overrides.from, getResolver(contract.runner));
}
}

if (fragment.inputs.length !== args.length) {
Expand Down
2 changes: 1 addition & 1 deletion src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export class AbstractProvider implements Provider {
[ "to", "from" ].forEach((key) => {
if ((<any>request)[key] == null) { return; }

const addr = resolveAddress((<any>request)[key]);
const addr = resolveAddress((<any>request)[key], this);
if (isPromise(addr)) {
promises.push((async function() { (<any>request)[key] = await addr; })());
} else {
Expand Down

0 comments on commit 3575476

Please sign in to comment.