Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed May 6, 2024
1 parent 97c5a3a commit cb9db39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
28 changes: 8 additions & 20 deletions src/clients/InventoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,26 +777,14 @@ export class InventoryClient {
// RPC's returning slowly, leading to concurrent/overlapping instances of the bot running.
const tokenContract = new Contract(l1Token, ERC20.abi, this.hubPoolClient.hubPool.signer);
const currentBalance = await tokenContract.balanceOf(this.relayer);
if (!balance.eq(currentBalance)) {
this.logger.warn({
at: "InventoryClient",
message: "🚧 Token balance on Ethereum changed before sending transaction, skipping rebalance",
l1Token,
l2Token,
l2ChainId: chainId,
balance,
currentBalance,
});
continue;
} else {
this.logger.debug({
at: "InventoryClient",
message: "Token balance in relayer on Ethereum is as expected, sending cross chain transfer",
l1Token,
l2Token,
l2ChainId: chainId,
balance,
});

const balanceChanged = !balance.eq(currentBalance);
const [message, log] = balanceChanged
? ["🚧 Token balance on mainnet changed, skipping rebalance", this.logger.warn]
: ["Token balance in relayer on mainnet is as expected, sending cross chain transfer", this.logger.debug];
log({ at: "InventoryClient", message, l1Token, l2Token, l2ChainId: chainId, balance, currentBalance });

if (!balanceChanged) {
possibleRebalances.push(rebalance);
// Decrement token balance in client for this chain and increment cross chain counter.
this.trackCrossChainTransfer(l1Token, amount, chainId);
Expand Down
2 changes: 1 addition & 1 deletion test/InventoryClient.InventoryRebalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ describe("InventoryClient: Rebalancing inventory", async function () {
.whenCalledWith(owner.address)
.returns(initialAllocation[1][mainnetUsdc].sub(toMegaWei(1)));
await inventoryClient.rebalanceInventoryIfNeeded();
expect(spyLogIncludes(spy, -2, "Token balance on Ethereum changed")).to.be.true;
expect(spyLogIncludes(spy, -2, "Token balance on mainnet changed")).to.be.true;

// Reset and check again.
mainnetUsdcContract.balanceOf.whenCalledWith(owner.address).returns(initialAllocation[1][mainnetUsdc]);
Expand Down

0 comments on commit cb9db39

Please sign in to comment.