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

improve(relayer): Clear out token data explicitly and log token balances #983

Merged
merged 3 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/clients/InventoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,9 @@ export class InventoryClient {
}

async wrapL2EthIfAboveThreshold(): Promise<void> {
if (!this.isInventoryManagementEnabled()) {
// If inventoryConfig is defined, there will be a default wrapEtherTarget and wrapEtherThreshold
// set by RelayerConfig.ts
if (!this?.inventoryConfig) {
return;
}
this.log("Checking ETH->WETH Wrap status");
Expand Down
19 changes: 18 additions & 1 deletion src/clients/TokenClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export class TokenClient {
this.tokenShortfall = {};
}

clearTokenData(): void {
this.tokenData = {};
}

async setOriginTokenApprovals(): Promise<void> {
const tokensToApprove: { chainId: number; token: string }[] = [];
Object.entries(this.tokenData).forEach(([_chainId, tokenMap]) => {
Expand Down Expand Up @@ -191,7 +195,20 @@ export class TokenClient {
}
}

this.logger.debug({ at: "TokenBalanceClient", message: "TokenBalance client updated!" });
// Remove allowance from token data when logging.
const balanceData = Object.fromEntries(
Object.entries(this.tokenData).map(([chainId, tokenData]) => {
return [
chainId,
Object.fromEntries(
Object.entries(tokenData).map(([token, { balance }]) => {
return [token, balance];
})
),
];
})
);
this.logger.debug({ at: "TokenBalanceClient", message: "TokenBalance client updated!", balanceData });
}

async fetchTokenData(spokePoolClient: SpokePoolClient): Promise<{
Expand Down
7 changes: 7 additions & 0 deletions src/clients/bridges/ArbitrumAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ export class ArbitrumAdapter extends BaseAdapter {
const value = ethBalance.sub(target);
this.logger.debug({ at: this.getName(), message: "Wrapping ETH", threshold, target, value, ethBalance });
return await this._wrapEthIfAboveThreshold(threshold, contract, value, simMode);
} else {
this.logger.debug({
at: this.getName(),
message: "ETH balance below threhsold",
threshold,
ethBalance,
});
}
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions src/clients/bridges/ZKSyncAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ export class ZKSyncAdapter extends BaseAdapter {
const value = ethBalance.sub(target);
this.logger.debug({ at: this.getName(), message: "Wrapping ETH", threshold, target, value, ethBalance });
return await this._wrapEthIfAboveThreshold(threshold, contract, value, simMode);
} else {
this.logger.debug({
at: this.getName(),
message: "ETH balance below threhsold",
threshold,
ethBalance,
});
}
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions src/clients/bridges/op-stack/OpStackAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ export class OpStackAdapter extends BaseAdapter {
const value = ethBalance.sub(target);
this.logger.debug({ at: this.getName(), message: "Wrapping ETH", threshold, target, value, ethBalance });
return await this._wrapEthIfAboveThreshold(threshold, contract, value, simMode);
} else {
this.logger.debug({
at: this.getName(),
message: "ETH balance below threhsold",
threshold,
ethBalance,
});
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions src/relayer/RelayerClientHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export async function updateRelayerClients(clients: RelayerClients, config: Rela

// Update the token client after the inventory client has done its wrapping of L2 ETH to ensure latest WETH ballance.
// The token client needs route data, so wait for update before checking approvals.
clients.tokenClient.clearTokenData();
await clients.tokenClient.update();
if (config.sendingRelaysEnabled) {
await clients.tokenClient.setOriginTokenApprovals();
Expand Down
2 changes: 1 addition & 1 deletion src/relayer/RelayerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class RelayerConfig extends CommonConfig {
);
}
});
Object.keys(this.inventoryConfig.tokenConfig).forEach((l1Token) => {
Object.keys(this.inventoryConfig?.tokenConfig ?? {}).forEach((l1Token) => {
Object.keys(this.inventoryConfig.tokenConfig[l1Token]).forEach((chainId) => {
const { targetPct, thresholdPct, unwrapWethThreshold, unwrapWethTarget } =
this.inventoryConfig.tokenConfig[l1Token][chainId];
Expand Down