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(l2): track locked balance in L2 integration test #1582

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fborello-lambda
Copy link
Contributor

@fborello-lambda fborello-lambda commented Dec 30, 2024

Motivation

The total amount of tokens present in the L2 has to match the balance of the CommonBridge contract at all times.

Description

There are some things to consider:

  • A deposit [L1 → L2] implies sending tokens to the CommonBridge → emits an event.
  • The l1_watcher will "read" the event and will create a transaction on the L2.
    1. This transaction, which is a PrivilegedL2 transaction and works the same as an EIP1559 when it comes to gas calculations, implies that some fees are sent to the coinbase_address. At the moment, the deposit PrivilegedL2 transactions are created by an L2 rich account, we may change this in the future. Moreover, the gas used on the L2 by the deposit has to come from the L1.
  • Once we have the deposit, we can send some transactions on the L2 itself. These transactions have "burned" and "recoverable" gas/tokens. (docs)
    • The recoverable tokens are sent to the coinbase_address, we can withdraw them if we want to, the burned fees are unrecoverable. Taken this into account, the total locked value should equal the CommonBridge balance minus the burned fees, without taking into account the L2's rich_accounts.

With such introduction, this PR aims to add some calculations inside the L2 integration test. The idea is to keep track of the fees and the CommonBridge balance. The final output of the test is:

L1 balance after claim: 999999099999859143375000000
L2 balance after claim: 899999961882800000000
Recoverable Fees Balance: 21135955316160
Common Bridge Locked Balance: 900000000000000000000
TOTAL Locked L2 value: 899999961892800000000
TOTAL Locked L2 value with recoverable fees: 899999978091880316160
BURNED FEES L2: 21908119683840

and if we do TOTAL Locked L2 value with recoverable fees: 899999978091880316160 + BURNED FEES L2: 21908119683840 we get the Common Bridge Locked Balance: 900000000000000000000 as expected.

The test subtracts the fees that comes from the first deposit (1.).
Closes #1043

@fborello-lambda fborello-lambda self-assigned this Dec 30, 2024
@fborello-lambda fborello-lambda marked this pull request as ready for review December 30, 2024 21:12
@fborello-lambda fborello-lambda requested a review from a team as a code owner December 30, 2024 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant