Skip to content

improve: Handle deposits referencing input/output/repayment tokens that do not map to PoolRebalanceRoutes #970

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Apr 8, 2025

Prerequisite changes needed to prepare for SpokePool that do not enforce deposit route whitelist checking. In this upcoming paradigm, deposits can be sent where the inputToken does not correspond to a PoolRebalanceRoute mapping. Implements this UMIP change

This change should be backwards compatible as all tokens that can be deposited are mapped to PoolRebalanceRoutes

The changes include:

  • changing the bundle data client's choice of repayment chain for a deposit where the inputToken and originChain, or outputToken and destinationChain, do not map to a PoolRebalanceRoute. These cases should switch repayment to the originChain.
  • building running balances based on refunds for a token that isn't mapped to a pool rebalance route
  • SpokePoolClient should gracefully handle deposits where the outputToken = 0x0 but there are not sufficient PoolRebalanceRoutes to resolve the outputToken

…ap to PoolRebalanceRoutes

Prerequisite changes needed to prepare for SpokePool that do not enforce deposit route whitelist checking

The changes include:
- changing the bundle data client's choice of repayment chain for a deposit where the inputToken and originChain do not map to a PoolRebalanceRoute
- building running balances based on refunds for a token that isn't mapped to a pool rebalance route
@nicholaspai nicholaspai requested review from pxrl and bmzig April 9, 2025 16:32
@nicholaspai nicholaspai marked this pull request as ready for review April 10, 2025 13:48
@nicholaspai nicholaspai marked this pull request as draft April 10, 2025 14:53
@nicholaspai nicholaspai removed request for bmzig and pxrl April 10, 2025 14:53
@nicholaspai nicholaspai requested a review from pxrl April 10, 2025 18:14
@nicholaspai nicholaspai changed the title improve(BundleDataClient): Ignore refunds for L2 tokens that do not map to PoolRebalanceRoutes improve: Handle deposits referencing tokens that do not map to PoolRebalanceRoutes Apr 10, 2025
@nicholaspai nicholaspai changed the title improve: Handle deposits referencing tokens that do not map to PoolRebalanceRoutes improve: Handle deposits referencing input/output/repayment tokens that do not map to PoolRebalanceRoutes Apr 10, 2025
@nicholaspai nicholaspai marked this pull request as ready for review April 11, 2025 17:08
@nicholaspai nicholaspai requested a review from bmzig April 11, 2025 18:55
@@ -372,7 +373,8 @@ export class BundleDataClient {
if (
fill.blockNumber < blockRanges[chainIndex][0] ||
fill.blockNumber > blockRanges[chainIndex][1] ||
isZeroValueFillOrSlowFillRequest(fill)
isZeroValueFillOrSlowFillRequest(fill) ||
invalidOutputToken(fill)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the intention with this check? invalidOutputToken() is only checking against 0x0, but no fill should ever set that.

Copy link
Member Author

@nicholaspai nicholaspai Apr 15, 2025

Choose a reason for hiding this comment

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

My thinking was that technically you can send a fill with an output token equal to the zero address (contract allows it) and now it can match with a deposit with the zero address-- and we don't want that. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this check even be in getApproximateRefundsForBlockRange? Would this not filter out valid deposits with 0x0 as the output token?

Copy link
Member Author

Choose a reason for hiding this comment

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

@bmzig my thinking was that in getApproximateRefundsForBlockRange like in this loadDataFromScratch function, there is a possibility to match a fill with an outputToken = 0x0 with a deposit.

So that's why this check exists there now. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep. That makes sense. I think we do want this here, then.

@@ -208,6 +208,11 @@ export function isZeroValueDeposit(deposit: Pick<Deposit, "inputAmount" | "messa
return deposit.inputAmount.eq(0) && isMessageEmpty(deposit.message);
}

export function invalidOutputToken(deposit: Pick<DepositWithBlock, "outputToken">): boolean {
// If the output token is zero address, then it is invalid.
return deposit.outputToken === ZERO_ADDRESS;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be ZERO_BYTES ? I think fwiw we already have a similar function (isZeroAddress()) used by the SpokePoolClient to determine whether it needs to sub in a valid address.

Copy link
Member Author

Choose a reason for hiding this comment

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

@nicholaspai nicholaspai requested a review from pxrl April 15, 2025 22:18
Copy link
Contributor

@bmzig bmzig left a comment

Choose a reason for hiding this comment

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

This looks good to me. I couldn't see anything wrong. A minor note: it seems like getL1TokenForDeposit and getL2TokenForDeposit will break with the contract upgrade, but the only time we use it is when calculating lp fees, which is addressed by the changes here.

@nicholaspai
Copy link
Member Author

Yeah I think this PR catches all instances where we use getL1TokenForDeposit and getL2TokenForDeposit but that's definitely a worry of mine. Thanks for reviewing

@nicholaspai nicholaspai requested a review from bmzig April 16, 2025 00:25
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.

3 participants