Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(relayer): Post-process external inventory config #1333

Merged
merged 12 commits into from
Mar 25, 2024
1 change: 1 addition & 0 deletions src/relayer/RelayerClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export async function constructRelayerClients(
const msg = typeguards.isError(err) ? err.message : (err as Record<string, unknown>)?.code;
throw new Error(`Inventory config error in ${config.externalInventoryConfig} (${msg ?? "unknown error"})`);
}
config.parseInventoryConfig();
james-a-morris marked this conversation as resolved.
Show resolved Hide resolved
logger.debug({
at: "Relayer#constructRelayerClients",
message: "Updated Inventory config.",
Expand Down
61 changes: 33 additions & 28 deletions src/relayer/RelayerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,42 @@ export class RelayerConfig extends CommonConfig {
);
this.externalInventoryConfig = RELAYER_EXTERNAL_INVENTORY_CONFIG;
this.inventoryConfig = JSON.parse(RELAYER_INVENTORY_CONFIG ?? "{}");
this.parseInventoryConfig();

this.minRelayerFeePct = toBNWei(MIN_RELAYER_FEE_PCT || Constants.RELAYER_MIN_FEE_PCT);

this.debugProfitability = DEBUG_PROFITABILITY === "true";
this.relayerGasPadding = toBNWei(RELAYER_GAS_PADDING || Constants.DEFAULT_RELAYER_GAS_PADDING);
this.relayerGasMultiplier = toBNWei(RELAYER_GAS_MULTIPLIER || Constants.DEFAULT_RELAYER_GAS_MULTIPLIER);
this.relayerMessageGasMultiplier = toBNWei(
RELAYER_GAS_MESSAGE_MULTIPLIER || Constants.DEFAULT_RELAYER_GAS_MESSAGE_MULTIPLIER
);
this.sendingRelaysEnabled = SEND_RELAYS === "true";
this.sendingRebalancesEnabled = SEND_REBALANCES === "true";
this.sendingMessageRelaysEnabled = SEND_MESSAGE_RELAYS === "true";
this.skipRelays = SKIP_RELAYS === "true";
this.skipRebalancing = SKIP_REBALANCING === "true";
this.sendingSlowRelaysEnabled = SEND_SLOW_RELAYS === "true";
this.acceptInvalidFills = ACCEPT_INVALID_FILLS === "true";
(this.minDepositConfirmations = MIN_DEPOSIT_CONFIRMATIONS
? JSON.parse(MIN_DEPOSIT_CONFIRMATIONS)
: Constants.MIN_DEPOSIT_CONFIRMATIONS),
Object.keys(this.minDepositConfirmations).forEach((threshold) => {
Object.keys(this.minDepositConfirmations[threshold]).forEach((chainId) => {
const nBlocks: number = this.minDepositConfirmations[threshold][chainId];
assert(
!isNaN(nBlocks) && nBlocks >= 0,
`Chain ${chainId} minimum deposit confirmations for "${threshold}" threshold missing or invalid (${nBlocks}).`
);
});
});
// Force default thresholds in MDC config.
this.minDepositConfirmations["default"] = Constants.DEFAULT_MIN_DEPOSIT_CONFIRMATIONS;
this.ignoreLimits = RELAYER_IGNORE_LIMITS === "true";
}

// Post-process the imported JSON to scale the configured values to 18 decimals.
parseInventoryConfig(): void {
if (Object.keys(this.inventoryConfig).length > 0) {
this.inventoryConfig = replaceAddressCase(this.inventoryConfig); // Cast any non-address case addresses.
this.inventoryConfig.wrapEtherThreshold = this.inventoryConfig.wrapEtherThreshold
Expand Down Expand Up @@ -141,33 +174,5 @@ export class RelayerConfig extends CommonConfig {
});
});
}
this.debugProfitability = DEBUG_PROFITABILITY === "true";
this.relayerGasPadding = toBNWei(RELAYER_GAS_PADDING || Constants.DEFAULT_RELAYER_GAS_PADDING);
this.relayerGasMultiplier = toBNWei(RELAYER_GAS_MULTIPLIER || Constants.DEFAULT_RELAYER_GAS_MULTIPLIER);
this.relayerMessageGasMultiplier = toBNWei(
RELAYER_GAS_MESSAGE_MULTIPLIER || Constants.DEFAULT_RELAYER_GAS_MESSAGE_MULTIPLIER
);
this.sendingRelaysEnabled = SEND_RELAYS === "true";
this.sendingRebalancesEnabled = SEND_REBALANCES === "true";
this.sendingMessageRelaysEnabled = SEND_MESSAGE_RELAYS === "true";
this.skipRelays = SKIP_RELAYS === "true";
this.skipRebalancing = SKIP_REBALANCING === "true";
this.sendingSlowRelaysEnabled = SEND_SLOW_RELAYS === "true";
this.acceptInvalidFills = ACCEPT_INVALID_FILLS === "true";
(this.minDepositConfirmations = MIN_DEPOSIT_CONFIRMATIONS
? JSON.parse(MIN_DEPOSIT_CONFIRMATIONS)
: Constants.MIN_DEPOSIT_CONFIRMATIONS),
Object.keys(this.minDepositConfirmations).forEach((threshold) => {
Object.keys(this.minDepositConfirmations[threshold]).forEach((chainId) => {
const nBlocks: number = this.minDepositConfirmations[threshold][chainId];
assert(
!isNaN(nBlocks) && nBlocks >= 0,
`Chain ${chainId} minimum deposit confirmations for "${threshold}" threshold missing or invalid (${nBlocks}).`
);
});
});
// Force default thresholds in MDC config.
this.minDepositConfirmations["default"] = Constants.DEFAULT_MIN_DEPOSIT_CONFIRMATIONS;
this.ignoreLimits = RELAYER_IGNORE_LIMITS === "true";
}
}
Loading