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

feat: universal bridge adapter #233

Merged
merged 9 commits into from
Feb 17, 2023
Merged

feat: universal bridge adapter #233

merged 9 commits into from
Feb 17, 2023

Conversation

mrice32
Copy link
Contributor

@mrice32 mrice32 commented Feb 14, 2023

This modifies the SpokePool to support incentives to move tokens to other chains. This is done by establishing a defined ordering of deposits and fills on each chain and rewarding depositors and relayers for moving the tokens towards the right running balance.

Specific changes:

  • To avoid frontrunning and allow depositors and relayers to lock in their reward, a running count of the aggregate amount of funds is tracked for both deposits and fills. Depositors and relayers can then pass in a maxCount to cap the amount of capital coming in ahead of them that they did not anticipate.
  • Both LP fees and relayer fees can now be negative.
  • The slow fill process/struct includes a new value, called payoutAdjustment. This enables the fees/rewards that would typically be passed on to a relayer to be passed on to the end-user in the case of a slow fill.
  • When relayers take refunds on other chains, their impact is not considered on this chain or the other chain. This means that the dataworker will need to "deprioritize" their ordering and give them the least favored positioning within the bundle.

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@mrice32 mrice32 requested a review from nicholaspai February 14, 2023 19:11
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@socket-security
Copy link

Socket Security Pull Request Report

👍 No new dependency issues detected in pull request

Pull request report summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script confusion ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues
Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@2.4.2

Powered by socket.dev

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@mrice32 mrice32 marked this pull request as ready for review February 16, 2023 12:30
@mrice32 mrice32 changed the title DRAFT: initial version of universal bridge adapter feat: initial version of universal bridge adapter Feb 16, 2023
@mrice32 mrice32 requested a review from pxrl February 16, 2023 12:36
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

meta level comment: I think it'd be useful to draft the UMIP changes that would lead to this implementation change. I recall when writing the original UMIP that we wish we had made changes to the contract to make the UMIP easier to write

@@ -706,7 +750,16 @@ abstract contract SpokePool is
// Note: use relayAmount as the max amount to send, so the relay is always completely filled by the contract's
// funds in all cases. As this is a slow relay we set the relayerFeePct to 0. This effectively refunds the
// relayer component of the relayerFee thereby only charging the depositor the LpFee.
uint256 fillAmountPreFees = _fillRelay(relayHash, relayData, relayData.amount, 0, true);
uint256 fillAmountPreFees = _fillRelay(
Copy link
Member

@nicholaspai nicholaspai Feb 16, 2023

Choose a reason for hiding this comment

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

Does _fillRelay have any new divide by zero or underflow/overflow checks we need to add now that the fees can be negative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't think of any -- can you? The total fees cannot be 100% or -100%. They are capped at +-50%, so I think the remaining amount is guaranteed to always be >0.

Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

Did a first pass review, haven't reviewed tests yet only solidity files

Signed-off-by: Matt Rice <matthewcrice32@gmail.com>
@mrice32 mrice32 changed the title feat: initial version of universal bridge adapter feat: universal bridge adapter Feb 16, 2023
@mrice32 mrice32 requested a review from nicholaspai February 16, 2023 17:21
// Update fill counter.
_updateCountFromFill(
relayFills[relayHash],
relayFills[relayHash] + fillAmountPreFees,
Copy link
Member

Choose a reason for hiding this comment

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

just curious, why fillAmountPreFees here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the method is responsible for removing the LP fee from that to compute the "liabilities" that this chain will have to pay out as a refund. Does that make sense?

Copy link
Member

@nicholaspai nicholaspai left a comment

Choose a reason for hiding this comment

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

This LGTM but can you explain the following new params:

  • local repayment: can repayment chain still be set to any chain? When is this true vs false? What's the purpose?
  • payoutAdjustment: How will this be used by dataworker?

@mrice32
Copy link
Contributor Author

mrice32 commented Feb 17, 2023

This LGTM but can you explain the following new params:

  • local repayment: can repayment chain still be set to any chain? When is this true vs false? What's the purpose?
  • payoutAdjustment: How will this be used by dataworker?

I added explanations in the description. Will also look into adding more comments about this in a follow up!

@mrice32 mrice32 requested a review from nicholaspai February 17, 2023 00:18
@mrice32 mrice32 merged commit 1edd45b into master Feb 17, 2023
@mrice32 mrice32 deleted the uba branch February 17, 2023 00:36
Comment on lines +980 to +985
if (startingFillAmount == 0 && totalFillAmount - endingFillAmount > 0) {
fillCounter[token] += _computeAmountPostFees(totalFillAmount - endingFillAmount, realizedLPFeePct);
}

// If this is not the first fill, remove the partial fill that was previously assumed.
if (startingFillAmount != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is premature, but is there a gas optimisation by making these two if statements mutually exclusive? For example:

        if (startingFillAmount == 0) {
            if (totalFillAmount - endingFillAmount > 0) {
                fillCounter[token] += _computeAmountPostFees(totalFillAmount - endingFillAmount, realizedLPFeePct);
            }
        } else {
        // If this is not the first fill, remove the partial fill that was previously assumed (startingFillAmount > 0).

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