Skip to content

Commit

Permalink
improve(RelayerConfig): Permit symbol-based token config (#1460)
Browse files Browse the repository at this point in the history
This change permits the InventoryConfig to be specified in either
HubPool token address or token symbol. Token symbol is preferred because
it's simpler to configure and reduces the chance of mistakes.

During parsing, any symbols are resolved to their underlying token
addresses on the HubPool chain, so no subsequent changes are required
for any accesses into the post-processed inventory config.
  • Loading branch information
pxrl authored May 1, 2024
1 parent e4b70b6 commit 79be346
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/relayer/RelayerConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { utils as ethersUtils } from "ethers";
import { typeguards } from "@across-protocol/sdk-v2";
import {
BigNumber,
Expand Down Expand Up @@ -145,11 +146,23 @@ export class RelayerConfig extends CommonConfig {
}
});

Object.keys(inventoryConfig?.tokenConfig ?? {}).forEach((l1Token) => {
Object.keys(inventoryConfig.tokenConfig[l1Token]).forEach((chainId) => {
const tokenConfig = inventoryConfig.tokenConfig[l1Token][chainId];
const rawTokenConfigs = inventoryConfig?.tokenConfig ?? {};
const tokenConfigs = (inventoryConfig.tokenConfig = {});
Object.keys(rawTokenConfigs).forEach((l1Token) => {
// If the l1Token is a symbol, resolve the correct address.
const effectiveL1Token = ethersUtils.isAddress(l1Token)
? l1Token
: TOKEN_SYMBOLS_MAP[l1Token]?.addresses[this.hubPoolChainId];
assert(effectiveL1Token !== undefined, `No token identified for ${l1Token}`);

Object.keys(rawTokenConfigs[l1Token]).forEach((chainId) => {
const { targetPct, thresholdPct, unwrapWethThreshold, unwrapWethTarget, targetOverageBuffer } =
rawTokenConfigs[l1Token][chainId];

tokenConfigs[effectiveL1Token] ??= {};
tokenConfigs[effectiveL1Token][chainId] ??= { targetPct, thresholdPct, targetOverageBuffer };
const tokenConfig = tokenConfigs[effectiveL1Token][chainId];

const { targetPct, thresholdPct, unwrapWethThreshold, unwrapWethTarget, targetOverageBuffer } = tokenConfig;
assert(
targetPct !== undefined && thresholdPct !== undefined,
`Bad config. Must specify targetPct, thresholdPct for ${l1Token} on ${chainId}`
Expand All @@ -167,7 +180,7 @@ export class RelayerConfig extends CommonConfig {
tokenConfig.targetOverageBuffer = toBNWei(targetOverageBuffer ?? "1.5");

// For WETH, also consider any unwrap target/threshold.
if (l1Token === TOKEN_SYMBOLS_MAP.WETH.addresses[this.hubPoolChainId]) {
if (effectiveL1Token === TOKEN_SYMBOLS_MAP.WETH.addresses[this.hubPoolChainId]) {
if (unwrapWethThreshold !== undefined) {
tokenConfig.unwrapWethThreshold = toBNWei(unwrapWethThreshold);
}
Expand Down

0 comments on commit 79be346

Please sign in to comment.