Skip to content

Commit

Permalink
improve: embed new relayer defaults into routes
Browse files Browse the repository at this point in the history
  • Loading branch information
james-a-morris committed Oct 26, 2023
1 parent d1a1874 commit e81bec4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 7 additions & 2 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getProvider,
HUB_POOL_CHAIN_ID,
ENABLED_ROUTES,
getDefaultRelayerAddress,
} from "./_utils";

const LimitsQueryParamsSchema = object({
Expand Down Expand Up @@ -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([
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 19 additions & 2 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +29,7 @@ import {
ENABLED_ROUTES,
getSpokePoolAddress,
getCachedTokenBalance,
getDefaultRelayerAddress,
} from "./_utils";

const SuggestedFeesQueryParamsSchema = type({
Expand Down Expand Up @@ -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);

Expand All @@ -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");
Expand Down

0 comments on commit e81bec4

Please sign in to comment.