Skip to content

Commit

Permalink
feat: include new relayer address override (#886)
Browse files Browse the repository at this point in the history
* feat: include new relayer address override

* improve: embed new relayer defaults into routes

* fix: bug

* chore: include checksummed address
  • Loading branch information
james-a-morris authored Nov 1, 2023
1 parent a955c42 commit 13e8ae0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
10 changes: 10 additions & 0 deletions api/_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ const defaultRelayerFeeCapitalCostConfig: {
},
};

export const defaultRelayerAddressOverride: Record<
string,
{ relayer: string; destinationChains: number[] }
> = {
SNX: {
relayer: "0x19cDc2b23AF0cC791ca64dda5BFc094Cddda31Cd",
destinationChains: [1, 10],
},
};

const relayerFeeCapitalCostOverrides: Record<
string,
Record<string, Record<string, relayFeeCalculator.CapitalCostConfig>>
Expand Down
20 changes: 20 additions & 0 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
maxRelayFeePct,
relayerFeeCapitalCostConfig,
BLOCK_TAG_LAG,
defaultRelayerAddressOverride,
} from "./_constants";
import { PoolStateResult } from "./_types";

Expand Down Expand Up @@ -1226,3 +1227,22 @@ export async function getBalancerV2TokenPrice(

return Number((totalValue / floatTotalSupply).toFixed(18));
}

/**
* Returns the EOA that will serve as the default relayer address
* @param symbol A valid token symbol
* @param destinationChainId The destination chain that a bridge operation will transfer to
* @returns A valid EOA address
*/
export function getDefaultRelayerAddress(
symbol: string,
destinationChainId: number
) {
// All symbols are uppercase in this record.
const result = defaultRelayerAddressOverride[symbol.toUpperCase()];
if (result?.destinationChains.includes(destinationChainId)) {
return result.relayer;
} else {
return sdk.constants.DEFAULT_SIMULATED_RELAYER_ADDRESS;
}
}
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 @@ -154,7 +157,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
15 changes: 15 additions & 0 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { type, assert, Infer, optional, string } from "superstruct";
import {
disabledL1Tokens,
DEFAULT_QUOTE_TIMESTAMP_BUFFER,
TOKEN_SYMBOLS_MAP,
DEFAULT_SIMULATED_RECIPIENT_ADDRESS,
} from "./_constants";
import { TypedVercelRequest } from "./_types";
Expand All @@ -29,6 +30,7 @@ import {
ENABLED_ROUTES,
getSpokePoolAddress,
getCachedTokenBalance,
getDefaultRelayerAddress,
} from "./_utils";

const SuggestedFeesQueryParamsSchema = type({
Expand Down Expand Up @@ -92,6 +94,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");
}

relayer ??= 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

2 comments on commit 13e8ae0

@vercel
Copy link

@vercel vercel bot commented on 13e8ae0 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 13e8ae0 Nov 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

goerli-frontend-v2 – ./

goerli-frontend-v2.vercel.app
goerli-frontend-v2-uma.vercel.app
goerli-frontend-v2-git-master-uma.vercel.app

Please sign in to comment.