From e81bec4e5221cb94786dfcccae3aa83205456b38 Mon Sep 17 00:00:00 2001 From: james-a-morris Date: Thu, 26 Oct 2023 16:21:44 -0400 Subject: [PATCH] improve: embed new relayer defaults into routes --- api/limits.ts | 9 +++++++-- api/suggested-fees.ts | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/api/limits.ts b/api/limits.ts index a040435ba..5ae331677 100644 --- a/api/limits.ts +++ b/api/limits.ts @@ -30,6 +30,7 @@ import { getProvider, HUB_POOL_CHAIN_ID, ENABLED_ROUTES, + getDefaultRelayerAddress, } from "./_utils"; const LimitsQueryParamsSchema = object({ @@ -99,8 +100,10 @@ const handler = async ( const tokenDetails = Object.values(TOKEN_SYMBOLS_MAP).find( (details) => details.addresses[HUB_POOL_CHAIN_ID] === l1Token ); - if (tokenDetails === undefined) + + if (tokenDetails === undefined) { throw new InputError("Unsupported token address"); + } const symbol = tokenDetails.symbol; const [tokenDetailsResult, routeEnabledResult] = await Promise.allSettled([ @@ -151,7 +154,9 @@ const handler = async ( computedOriginChainId, Number(destinationChainId), DEFAULT_SIMULATED_RECIPIENT_ADDRESS, - tokenPriceNative + tokenPriceNative, + undefined, + getDefaultRelayerAddress(symbol, Number(destinationChainId)) ), hubPool.callStatic.multicall(multicallInput, { blockTag: BLOCK_TAG_LAG }), Promise.all( diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts index 6c7d7b13c..9bf03a01e 100644 --- a/api/suggested-fees.ts +++ b/api/suggested-fees.ts @@ -6,7 +6,11 @@ import { BlockFinder } from "@uma/sdk"; import { VercelResponse } from "@vercel/node"; import { ethers } from "ethers"; import { type, assert, Infer, optional, string } from "superstruct"; -import { disabledL1Tokens, DEFAULT_QUOTE_TIMESTAMP_BUFFER } from "./_constants"; +import { + disabledL1Tokens, + DEFAULT_QUOTE_TIMESTAMP_BUFFER, + TOKEN_SYMBOLS_MAP, +} from "./_constants"; import { TypedVercelRequest } from "./_types"; import { getLogger, @@ -25,6 +29,7 @@ import { ENABLED_ROUTES, getSpokePoolAddress, getCachedTokenBalance, + getDefaultRelayerAddress, } from "./_utils"; const SuggestedFeesQueryParamsSchema = type({ @@ -77,7 +82,6 @@ const handler = async ( throw new InputError("Origin and destination chains cannot be the same"); } - relayerAddress ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS; recipientAddress ??= sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS; token = ethers.utils.getAddress(token); @@ -87,6 +91,19 @@ const handler = async ( ]); const { l1Token, hubPool, chainId: computedOriginChainId } = tokenDetails; + const tokenInformation = Object.values(TOKEN_SYMBOLS_MAP).find( + (details) => details.addresses[HUB_POOL_CHAIN_ID] === l1Token + ); + + if (!sdk.utils.isDefined(tokenInformation)) { + throw new InputError("Unsupported token address"); + } + + relayerAddress ??= getDefaultRelayerAddress( + tokenInformation.symbol, + Number(destinationChainId) + ); + if (sdk.utils.isDefined(message) && !sdk.utils.isMessageEmpty(message)) { if (!ethers.utils.isHexString(message)) { throw new InputError("Message must be a hex string");