From 2616f4c30c82bd45449b73fa37ef269d60a07d80 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Mon, 9 Oct 2023 19:34:58 -0400 Subject: [PATCH] Fixed resolving ENS addresses used as from parameters (#3961). --- src.ts/contract/contract.ts | 22 ++++++++++++++++++---- src.ts/providers/abstract-provider.ts | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src.ts/contract/contract.ts b/src.ts/contract/contract.ts index 5895367105..2370602a41 100644 --- a/src.ts/contract/contract.ts +++ b/src.ts/contract/contract.ts @@ -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 @@ -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; readonly fragment!: EventFragment; @@ -146,9 +154,7 @@ export async function copyOverrides(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 >overrides; } @@ -177,6 +183,10 @@ function buildWrappedFallback(contract: BaseContract): WrappedFallback { const tx: ContractTransaction = (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); @@ -271,6 +281,10 @@ function buildWrappedMethod = Array, R = any, D extend let overrides: Omit = { }; 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) { diff --git a/src.ts/providers/abstract-provider.ts b/src.ts/providers/abstract-provider.ts index deb59c1829..19ef00f5f6 100644 --- a/src.ts/providers/abstract-provider.ts +++ b/src.ts/providers/abstract-provider.ts @@ -817,7 +817,7 @@ export class AbstractProvider implements Provider { [ "to", "from" ].forEach((key) => { if ((request)[key] == null) { return; } - const addr = resolveAddress((request)[key]); + const addr = resolveAddress((request)[key], this); if (isPromise(addr)) { promises.push((async function() { (request)[key] = await addr; })()); } else {