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(inventory-manager): Check ERC20 balance before submitting cross chain bridge #972

Merged
merged 13 commits into from
Oct 9, 2023

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Oct 8, 2023

The TokenClient fetches ERC20 balances for the relayer prior to carrying out Relayer duties. This means that there could be a multiple minute delay between balances between fetched and the inventory
manager executing, exposing the relayer to the risk of sending a duplicate rebalance.

This PR adds a simple check for the ERC20 balance as close to sending the inventory rebalance as possible. The downside is a slower inventory manager run, which is mitigated by a side effect of allowing the bot-runner to refactor the inventory manager out of the relayer. This can be done by setting the new environment variable SKIP_RELAYS which will skip the relayer portion of the relayer/index.ts run.

Signed-off-by: nicholaspai [email protected]

Fixes ACX1595

@nicholaspai nicholaspai marked this pull request as ready for review October 8, 2023 01:32
src/clients/InventoryClient.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to double check, the skipRelays flag is really a secondary change to permit the InventoryClient to run in a standalone instance, right? I otherwise don't think this change should add any noticeable delay to the existing relayer run (as I read the commit message, it seems to indicate that this change slows the bot down).

Copy link
Contributor

Choose a reason for hiding this comment

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

(So basically, I think it'd be sufficient to just have the final erc20.balanceOf() check before submitting any rebalance transactions, as a mitigation for the fact that we don't know whether there are concurrent relayer instances running)

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to double check, the skipRelays flag is really a secondary change to permit the InventoryClient to run in a standalone instance, right?

Yes exactly, it should not add any delay to the existing relayer run. The slowdown is moreso related to the ERC20.balanceOf check added in the inventory manager

src/clients/InventoryClient.ts Outdated Show resolved Hide resolved
@@ -131,7 +133,8 @@ export class RelayerConfig extends CommonConfig {
}
this.debugProfitability = DEBUG_PROFITABILITY === "true";
this.relayerGasMultiplier = toBNWei(RELAYER_GAS_MULTIPLIER || Constants.DEFAULT_RELAYER_GAS_MULTIPLIER);
this.sendingRelaysEnabled = SEND_RELAYS === "true";
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW I think it's worth calling this out in the commit message and I probably think it's better to just do it in a separate commit, since it is a breaking change for existing relayer configs.

Copy link
Member Author

Choose a reason for hiding this comment

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

fair point reverted here 9818120

@nicholaspai nicholaspai requested a review from pxrl October 9, 2023 15:01
Copy link
Contributor

@pxrl pxrl left a comment

Choose a reason for hiding this comment

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

LGTM

@nicholaspai nicholaspai merged commit 459f787 into master Oct 9, 2023
2 checks passed
@pxrl pxrl deleted the npai/inventory-client-protection branch October 9, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants