Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(InventoryClient): Map outstanding crosschain transfers to correct…
… relayer address (#1457) * improve(InventoryClient): Track L2 WETH Deposit events when computing outstanding crosschain transfers ## Summary The rebalancer is designed to [wrap any excess ETH into WETH](https://github.com/across-protocol/relayer-v3/blob/dd5e20ec4538c8c3e7bfb923187f521f92d85882/src/relayer/RelayerClientHelper.ts#L216) before [updating the `TokenClient`](https://github.com/across-protocol/relayer-v3/blob/dd5e20ec4538c8c3e7bfb923187f521f92d85882/src/relayer/RelayerClientHelper.ts#L223) and eventually proceeding to the [rebalancing inventory step](https://github.com/across-protocol/relayer-v3/blob/dd5e20ec4538c8c3e7bfb923187f521f92d85882/src/relayer/index.ts#L118). However, in practice we've seen that the rebalancer is not able to detect these wrapped ETH events in time to prevent a duplicate rebalance. This PR adds safety to the chain adapters where we bridge ETH via the AtomicDepositor and expect to receive ETH on the L2 side and subsequently expect to wrap it into WETH. We now only mark a deposit as finalized in the inventory client when the L2 deposit event is followed by a wrap event. This algorithm can clearly fall prey to false positives where an unrelated ETH unwrap leads to the rebalancer falsely detecting that an L1 to L2 WETH transfer has finalized. However, for the most part, WETH wraps should only be triggered by the rebalancer, and even if wrapping ETH was unrelated to the specific L1 to L2 transfer we care about, it should still convert the ETH into WETH balance which is what we care about and would prevent WETH duplicate cross chain transfers. ## Additional Fixes - This PR fixes a bug in the ZkSyncAdapter where the `initiatedQueryResult` for WETH were not being properly loaded into the cross chain outstanding transfers object. This caused the inventory manager to NEVER identify outstanding zksync deposits, leading to possible duplicate rebalances until the cross chain transferred ETH was wrapped into WETH on the L2 side. - This PR fixes a bug in the Optimism Adapter where outstanding ETH cross chain transfer amounts are being credited to the atomic depositor address and therefore don't factor into the optimism/base relayer address. This similarly causes issues where the relayer's balance will look off by the amount of ETH transferred until it gets wrapped into WETH on the L2 side and would get picked up by the TokenClient at that point * Add early exits to adapters * Refactor constructor * Update ArbitrumAdapter.ts * Update PolygonAdapter.ts * Refactor * ? atomicDepositor * comments, remove getL1Weth() * Update OpStackAdapter.ts * Update utils.ts * Fix Arbitrum Adapter and Polygon adapter bugs * Restore adapter logic without weth wrapping tracking * Update LineaAdapter.ts * Fix monitor * Add delayed token client update * Fix * remove floor() * FIx OP adapter * fix zksync bridge and weth adapter * Filter out other spoke pool addresses + fix weth bridge * zksync * Update WethBridge.ts * Update ZKSyncAdapter.ts * Update WethBridge.ts * Update BaseAdapter.ts * Update LineaAdapter.ts * Add WETH checking to ZkSync * Update OpStackAdapter.ts * Fix Linea filters * Linea refactor + unit tested * Linea refactored + unit tested * fix polygon * Update PolygonAdapter.ts * Update ZKSyncAdapter.ts * WETH op stack works * Unit test op stack weth bridge * Refactors * lint * polygon and zk optimizations * fix(bridges): Ensure l1Tokens and bridges are same length ## OpStackAdapter fix: - If `bridges` is type string, we can't call .length on it otherwise we'll inadvertently use the char count of the string ## PolygonAdapter fix: - Must add WETH to l1Token list before early exiting * rename l1Gateway to l1Gateways --------- Co-authored-by: Paul <[email protected]>
- Loading branch information