diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/balance_reader.go b/op-acceptance-tests/tests/isthmus/operator_fee/balance_reader.go deleted file mode 100644 index 83ca3f94b030c..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/balance_reader.go +++ /dev/null @@ -1,69 +0,0 @@ -package operatorfee - -import ( - "context" - "math/big" - - "github.com/ethereum-optimism/optimism/op-devstack/devtest" - "github.com/ethereum-optimism/optimism/op-service/predeploys" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/log" - "github.com/stretchr/testify/require" -) - -// BalanceReader provides methods to read balances from the chain -type BalanceReader struct { - client *ethclient.Client - t devtest.T - logger log.Logger -} - -// NewBalanceReader creates a new BalanceReader instance -func NewBalanceReader(t devtest.T, client *ethclient.Client, logger log.Logger) *BalanceReader { - return &BalanceReader{ - client: client, - t: t, - logger: logger, - } -} - -// SampleBalances reads all the relevant balances at the given block number -// and returns a BalanceSnapshot containing the results -func (br *BalanceReader) SampleBalances(ctx context.Context, blockNumber *big.Int, walletAddr common.Address) *BalanceSnapshot { - br.logger.Debug("Sampling balances", - "block", blockNumber, - "wallet", walletAddr.Hex()) - - // Read all balances - baseFeeVaultBalance, err := br.client.BalanceAt(ctx, predeploys.BaseFeeVaultAddr, blockNumber) - require.NoError(br.t, err) - - l1FeeVaultBalance, err := br.client.BalanceAt(ctx, predeploys.L1FeeVaultAddr, blockNumber) - require.NoError(br.t, err) - - sequencerFeeVaultBalance, err := br.client.BalanceAt(ctx, predeploys.SequencerFeeVaultAddr, blockNumber) - require.NoError(br.t, err) - - operatorFeeVaultBalance, err := br.client.BalanceAt(ctx, predeploys.OperatorFeeVaultAddr, blockNumber) - require.NoError(br.t, err) - - walletBalance, err := br.client.BalanceAt(ctx, walletAddr, blockNumber) - require.NoError(br.t, err) - - br.logger.Debug("Sampled balances", - "baseFee", baseFeeVaultBalance, - "l1Fee", l1FeeVaultBalance, - "sequencerFee", sequencerFeeVaultBalance, - "operatorFee", operatorFeeVaultBalance, - "wallet", walletBalance) - - return &BalanceSnapshot{ - BlockNumber: blockNumber, - BaseFeeVaultBalance: baseFeeVaultBalance, - L1FeeVaultBalance: l1FeeVaultBalance, - SequencerFeeVault: sequencerFeeVaultBalance, - OperatorFeeVault: operatorFeeVaultBalance, - FromBalance: walletBalance, - } -} diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot.go b/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot.go deleted file mode 100644 index 8f582564fac56..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot.go +++ /dev/null @@ -1,112 +0,0 @@ -package operatorfee - -import ( - "fmt" - "math/big" - - "github.com/ethereum-optimism/optimism/op-devstack/devtest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -type BalanceSnapshot struct { - BlockNumber *big.Int - BaseFeeVaultBalance *big.Int - L1FeeVaultBalance *big.Int - SequencerFeeVault *big.Int - OperatorFeeVault *big.Int - FromBalance *big.Int -} - -// String returns a formatted string representation of the balance snapshot -func (bs *BalanceSnapshot) String() string { - if bs == nil { - return "nil" - } - - return fmt.Sprintf( - "BalanceSnapshot{Block: %v, BaseFeeVault: %v, L1FeeVault: %v, SequencerFeeVault: %v, "+ - "OperatorFeeVault: %v, WalletBalance: %v}", - bs.BlockNumber, - bs.BaseFeeVaultBalance, - bs.L1FeeVaultBalance, - bs.SequencerFeeVault, - bs.OperatorFeeVault, - bs.FromBalance, - ) -} - -// Add adds this snapshot's balances to another snapshot and returns a new snapshot -// This is typically used to apply changes to a starting balance snapshot -func (bs *BalanceSnapshot) Add(start *BalanceSnapshot) *BalanceSnapshot { - if bs == nil || start == nil { - return nil - } - - return &BalanceSnapshot{ - BlockNumber: bs.BlockNumber, // Use the target block number from changes - BaseFeeVaultBalance: new(big.Int).Add(start.BaseFeeVaultBalance, bs.BaseFeeVaultBalance), - L1FeeVaultBalance: new(big.Int).Add(start.L1FeeVaultBalance, bs.L1FeeVaultBalance), - SequencerFeeVault: new(big.Int).Add(start.SequencerFeeVault, bs.SequencerFeeVault), - OperatorFeeVault: new(big.Int).Add(start.OperatorFeeVault, bs.OperatorFeeVault), - FromBalance: new(big.Int).Add(start.FromBalance, bs.FromBalance), - } -} - -// Sub returns a new BalanceSnapshot containing the differences between this snapshot and another -// This snapshot is considered the "end" and the parameter is the "start" -// Positive values indicate increases, negative values indicate decreases -func (bs *BalanceSnapshot) Sub(start *BalanceSnapshot) *BalanceSnapshot { - if bs == nil || start == nil { - return nil - } - - return &BalanceSnapshot{ - BlockNumber: bs.BlockNumber, - BaseFeeVaultBalance: new(big.Int).Sub(bs.BaseFeeVaultBalance, start.BaseFeeVaultBalance), - L1FeeVaultBalance: new(big.Int).Sub(bs.L1FeeVaultBalance, start.L1FeeVaultBalance), - SequencerFeeVault: new(big.Int).Sub(bs.SequencerFeeVault, start.SequencerFeeVault), - OperatorFeeVault: new(big.Int).Sub(bs.OperatorFeeVault, start.OperatorFeeVault), - FromBalance: new(big.Int).Sub(bs.FromBalance, start.FromBalance), - } -} - -// AssertSnapshotsEqual compares two balance snapshots and reports differences -func AssertSnapshotsEqual(t devtest.T, expected, actual *BalanceSnapshot) { - require.NotNil(t, expected, "Expected snapshot should not be nil") - require.NotNil(t, actual, "Actual snapshot should not be nil") - - // Check base fee vault balance - assert.True(t, expected.BaseFeeVaultBalance.Cmp(actual.BaseFeeVaultBalance) == 0, - "BaseFeeVaultBalance mismatch: expected %v, got %v (diff: %v)", expected.BaseFeeVaultBalance, actual.BaseFeeVaultBalance, new(big.Int).Sub(actual.BaseFeeVaultBalance, expected.BaseFeeVaultBalance)) - - // Check L1 fee vault balance - assert.True(t, expected.L1FeeVaultBalance.Cmp(actual.L1FeeVaultBalance) == 0, - "L1FeeVaultBalance mismatch: expected %v, got %v (diff: %v)", expected.L1FeeVaultBalance, actual.L1FeeVaultBalance, new(big.Int).Sub(actual.L1FeeVaultBalance, expected.L1FeeVaultBalance)) - - // Check sequencer fee vault balance - assert.True(t, expected.SequencerFeeVault.Cmp(actual.SequencerFeeVault) == 0, - "SequencerFeeVault mismatch: expected %v, got %v (diff: %v)", expected.SequencerFeeVault, actual.SequencerFeeVault, new(big.Int).Sub(actual.SequencerFeeVault, expected.SequencerFeeVault)) - - // Check operator fee vault balance - assert.True(t, expected.OperatorFeeVault.Cmp(actual.OperatorFeeVault) == 0, - "OperatorFeeVault mismatch: expected %v, got %v (diff: %v)", expected.OperatorFeeVault, actual.OperatorFeeVault, new(big.Int).Sub(actual.OperatorFeeVault, expected.OperatorFeeVault)) - - // Check wallet balance - assert.True(t, expected.FromBalance.Cmp(actual.FromBalance) == 0, - "WalletBalance mismatch: expected %v, got %v (diff: %v)", expected.FromBalance, actual.FromBalance, new(big.Int).Sub(actual.FromBalance, expected.FromBalance)) -} - -// SnapshotsEqual compares two balance snapshots and returns true if they are equal -// This is a non-asserting version for unit tests -func SnapshotsEqual(expected, actual *BalanceSnapshot) bool { - if expected == nil || actual == nil { - return expected == actual - } - - return expected.BaseFeeVaultBalance.Cmp(actual.BaseFeeVaultBalance) == 0 && - expected.L1FeeVaultBalance.Cmp(actual.L1FeeVaultBalance) == 0 && - expected.SequencerFeeVault.Cmp(actual.SequencerFeeVault) == 0 && - expected.OperatorFeeVault.Cmp(actual.OperatorFeeVault) == 0 && - expected.FromBalance.Cmp(actual.FromBalance) == 0 -} diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot_test.go b/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot_test.go deleted file mode 100644 index 1e55e703c1fa6..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/balance_snapshot_test.go +++ /dev/null @@ -1,227 +0,0 @@ -package operatorfee - -import ( - "math/big" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -// Helper function to create a BalanceSnapshot with specified values -func newTestSnapshot(block, baseFee, l1Fee, seqFee, opFee, from *big.Int) *BalanceSnapshot { - return &BalanceSnapshot{ - BlockNumber: block, - BaseFeeVaultBalance: baseFee, - L1FeeVaultBalance: l1Fee, - SequencerFeeVault: seqFee, - OperatorFeeVault: opFee, - FromBalance: from, - } -} - -func TestBalanceSnapshot_String(t *testing.T) { - t.Run("NilSnapshot", func(t *testing.T) { - var bs *BalanceSnapshot - assert.Equal(t, "nil", bs.String()) - }) - - t.Run("ZeroValues", func(t *testing.T) { - bs := newTestSnapshot( - big.NewInt(0), - big.NewInt(0), - big.NewInt(0), - big.NewInt(0), - big.NewInt(0), - big.NewInt(0), - ) - expected := "BalanceSnapshot{Block: 0, BaseFeeVault: 0, L1FeeVault: 0, SequencerFeeVault: 0, OperatorFeeVault: 0, WalletBalance: 0}" - assert.Equal(t, expected, bs.String()) - }) - - t.Run("NonZeroValues", func(t *testing.T) { - bs := newTestSnapshot( - big.NewInt(100), - big.NewInt(10), - big.NewInt(20), - big.NewInt(30), - big.NewInt(40), - big.NewInt(50), - ) - expected := "BalanceSnapshot{Block: 100, BaseFeeVault: 10, L1FeeVault: 20, SequencerFeeVault: 30, OperatorFeeVault: 40, WalletBalance: 50}" - assert.Equal(t, expected, bs.String()) - }) -} - -func TestBalanceSnapshot_Add(t *testing.T) { - start := newTestSnapshot( - big.NewInt(100), - big.NewInt(10), - big.NewInt(20), - big.NewInt(30), - big.NewInt(40), - big.NewInt(500), - ) - delta := newTestSnapshot( - big.NewInt(101), // Block number should come from delta - big.NewInt(5), - big.NewInt(10), - big.NewInt(15), - big.NewInt(20), - big.NewInt(100), - ) - expected := newTestSnapshot( - big.NewInt(101), // Expected block is from delta - big.NewInt(15), - big.NewInt(30), - big.NewInt(45), - big.NewInt(60), - big.NewInt(600), - ) - - t.Run("AddNonNil", func(t *testing.T) { - result := delta.Add(start) - require.NotNil(t, result) - // Direct comparison instead of AssertSnapshotsEqual - assert.True(t, expected.BlockNumber.Cmp(result.BlockNumber) == 0, "BlockNumber mismatch: expected %v, got %v", expected.BlockNumber, result.BlockNumber) - assert.True(t, expected.BaseFeeVaultBalance.Cmp(result.BaseFeeVaultBalance) == 0, "BaseFeeVaultBalance mismatch: expected %v, got %v", expected.BaseFeeVaultBalance, result.BaseFeeVaultBalance) - assert.True(t, expected.L1FeeVaultBalance.Cmp(result.L1FeeVaultBalance) == 0, "L1FeeVaultBalance mismatch: expected %v, got %v", expected.L1FeeVaultBalance, result.L1FeeVaultBalance) - assert.True(t, expected.SequencerFeeVault.Cmp(result.SequencerFeeVault) == 0, "SequencerFeeVault mismatch: expected %v, got %v", expected.SequencerFeeVault, result.SequencerFeeVault) - assert.True(t, expected.OperatorFeeVault.Cmp(result.OperatorFeeVault) == 0, "OperatorFeeVault mismatch: expected %v, got %v", expected.OperatorFeeVault, result.OperatorFeeVault) - assert.True(t, expected.FromBalance.Cmp(result.FromBalance) == 0, "FromBalance mismatch: expected %v, got %v", expected.FromBalance, result.FromBalance) - }) - - t.Run("AddNilStart", func(t *testing.T) { - result := delta.Add(nil) - assert.Nil(t, result) - }) - - t.Run("AddNilDelta", func(t *testing.T) { - var nilDelta *BalanceSnapshot - result := nilDelta.Add(start) - assert.Nil(t, result) - }) - - t.Run("AddNilToNil", func(t *testing.T) { - var nilDelta *BalanceSnapshot - result := nilDelta.Add(nil) - assert.Nil(t, result) - }) -} - -func TestBalanceSnapshot_Sub(t *testing.T) { - start := newTestSnapshot( - big.NewInt(100), - big.NewInt(10), - big.NewInt(20), - big.NewInt(30), - big.NewInt(40), - big.NewInt(500), - ) - end := newTestSnapshot( - big.NewInt(101), // Block number should come from 'end' (bs) - big.NewInt(15), - big.NewInt(30), - big.NewInt(45), - big.NewInt(60), - big.NewInt(600), - ) - expectedDelta := newTestSnapshot( - big.NewInt(101), // Expected block is from end (bs) - big.NewInt(5), - big.NewInt(10), - big.NewInt(15), - big.NewInt(20), - big.NewInt(100), - ) - - t.Run("SubNonNil", func(t *testing.T) { - delta := end.Sub(start) - require.NotNil(t, delta) - // Direct comparison - assert.True(t, expectedDelta.BlockNumber.Cmp(delta.BlockNumber) == 0, "BlockNumber mismatch: expected %v, got %v", expectedDelta.BlockNumber, delta.BlockNumber) - assert.True(t, expectedDelta.BaseFeeVaultBalance.Cmp(delta.BaseFeeVaultBalance) == 0, "BaseFeeVaultBalance mismatch: expected %v, got %v", expectedDelta.BaseFeeVaultBalance, delta.BaseFeeVaultBalance) - assert.True(t, expectedDelta.L1FeeVaultBalance.Cmp(delta.L1FeeVaultBalance) == 0, "L1FeeVaultBalance mismatch: expected %v, got %v", expectedDelta.L1FeeVaultBalance, delta.L1FeeVaultBalance) - assert.True(t, expectedDelta.SequencerFeeVault.Cmp(delta.SequencerFeeVault) == 0, "SequencerFeeVault mismatch: expected %v, got %v", expectedDelta.SequencerFeeVault, delta.SequencerFeeVault) - assert.True(t, expectedDelta.OperatorFeeVault.Cmp(delta.OperatorFeeVault) == 0, "OperatorFeeVault mismatch: expected %v, got %v", expectedDelta.OperatorFeeVault, delta.OperatorFeeVault) - assert.True(t, expectedDelta.FromBalance.Cmp(delta.FromBalance) == 0, "FromBalance mismatch: expected %v, got %v", expectedDelta.FromBalance, delta.FromBalance) - }) - - t.Run("SubNilStart", func(t *testing.T) { - delta := end.Sub(nil) - assert.Nil(t, delta) - }) - - t.Run("SubNilEnd", func(t *testing.T) { - var nilEnd *BalanceSnapshot - delta := nilEnd.Sub(start) - assert.Nil(t, delta) - }) - - t.Run("SubNilFromNil", func(t *testing.T) { - var nilEnd *BalanceSnapshot - delta := nilEnd.Sub(nil) - assert.Nil(t, delta) - }) - - t.Run("SubNegativeResult", func(t *testing.T) { - // Swapping start and end should result in negative delta - expectedNegativeDelta := newTestSnapshot( - big.NewInt(100), // Block number from start (now acting as 'bs') - big.NewInt(-5), - big.NewInt(-10), - big.NewInt(-15), - big.NewInt(-20), - big.NewInt(-100), - ) - delta := start.Sub(end) - require.NotNil(t, delta) - // Direct comparison - assert.True(t, expectedNegativeDelta.BlockNumber.Cmp(delta.BlockNumber) == 0, "BlockNumber mismatch: expected %v, got %v", expectedNegativeDelta.BlockNumber, delta.BlockNumber) - assert.True(t, expectedNegativeDelta.BaseFeeVaultBalance.Cmp(delta.BaseFeeVaultBalance) == 0, "BaseFeeVaultBalance mismatch: expected %v, got %v", expectedNegativeDelta.BaseFeeVaultBalance, delta.BaseFeeVaultBalance) - assert.True(t, expectedNegativeDelta.L1FeeVaultBalance.Cmp(delta.L1FeeVaultBalance) == 0, "L1FeeVaultBalance mismatch: expected %v, got %v", expectedNegativeDelta.L1FeeVaultBalance, delta.L1FeeVaultBalance) - assert.True(t, expectedNegativeDelta.SequencerFeeVault.Cmp(delta.SequencerFeeVault) == 0, "SequencerFeeVault mismatch: expected %v, got %v", expectedNegativeDelta.SequencerFeeVault, delta.SequencerFeeVault) - assert.True(t, expectedNegativeDelta.OperatorFeeVault.Cmp(delta.OperatorFeeVault) == 0, "OperatorFeeVault mismatch: expected %v, got %v", expectedNegativeDelta.OperatorFeeVault, delta.OperatorFeeVault) - assert.True(t, expectedNegativeDelta.FromBalance.Cmp(delta.FromBalance) == 0, "FromBalance mismatch: expected %v, got %v", expectedNegativeDelta.FromBalance, delta.FromBalance) - }) -} - -func TestSnapshotsEqual(t *testing.T) { - snap1 := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50)) - snap2 := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50)) - - t.Run("EqualSnapshots", func(t *testing.T) { - assert.True(t, SnapshotsEqual(snap1, snap2), "Equal snapshots should return true") - }) - - t.Run("DifferentBaseFee", func(t *testing.T) { - diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(99), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(50)) - assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different BaseFeeVaultBalance should return false") - }) - - t.Run("DifferentL1Fee", func(t *testing.T) { - diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(99), big.NewInt(30), big.NewInt(40), big.NewInt(50)) - assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different L1FeeVaultBalance should return false") - }) - - t.Run("DifferentSequencerFee", func(t *testing.T) { - diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(99), big.NewInt(40), big.NewInt(50)) - assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different SequencerFeeVault should return false") - }) - - t.Run("DifferentOperatorFee", func(t *testing.T) { - diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(99), big.NewInt(50)) - assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different OperatorFeeVault should return false") - }) - - t.Run("DifferentFromBalance", func(t *testing.T) { - diffSnap := newTestSnapshot(big.NewInt(1), big.NewInt(10), big.NewInt(20), big.NewInt(30), big.NewInt(40), big.NewInt(99)) - assert.False(t, SnapshotsEqual(snap1, diffSnap), "Different FromBalance should return false") - }) - - t.Run("NilSnapshots", func(t *testing.T) { - assert.True(t, SnapshotsEqual(nil, nil), "Both nil should return true") - assert.False(t, SnapshotsEqual(snap1, nil), "One nil should return false") - assert.False(t, SnapshotsEqual(nil, snap1), "One nil should return false") - }) -} diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/fee_checker.go b/op-acceptance-tests/tests/isthmus/operator_fee/fee_checker.go deleted file mode 100644 index 296460cc082bf..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/fee_checker.go +++ /dev/null @@ -1,144 +0,0 @@ -package operatorfee - -import ( - "context" - "math/big" - - "github.com/ethereum-optimism/optimism/op-devstack/devtest" - "github.com/ethereum/go-ethereum/common" - gethTypes "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethclient" - "github.com/ethereum/go-ethereum/log" - "github.com/ethereum/go-ethereum/params" - "github.com/stretchr/testify/require" -) - -type stateGetterAdapterFactory struct { - t devtest.T - client *ethclient.Client -} - -// stateGetterAdapter adapts the ethclient to implement the StateGetter interface -type stateGetterAdapter struct { - t devtest.T - client *ethclient.Client - ctx context.Context - blockNumber *big.Int -} - -func (f *stateGetterAdapterFactory) NewStateGetterAdapter(blockNumber *big.Int) *stateGetterAdapter { - return &stateGetterAdapter{ - t: f.t, - client: f.client, - ctx: f.t.Ctx(), - blockNumber: blockNumber, - } -} - -// GetState implements the StateGetter interface -func (sga *stateGetterAdapter) GetState(addr common.Address, key common.Hash) common.Hash { - var result common.Hash - val, err := sga.client.StorageAt(sga.ctx, addr, key, sga.blockNumber) - require.NoError(sga.t, err) - copy(result[:], val) - return result -} - -// FeeChecker provides methods to calculate various types of fees -type FeeChecker struct { - config *params.ChainConfig - logger log.Logger - sgaFactory *stateGetterAdapterFactory -} - -// NewFeeChecker creates a new FeeChecker instance -func NewFeeChecker(t devtest.T, client *ethclient.Client, chainConfig *params.ChainConfig, logger log.Logger) *FeeChecker { - logger.Debug("Creating fee checker", "chainID", chainConfig.ChainID) - - // Create state getter adapter factory - sgaFactory := &stateGetterAdapterFactory{ - t: t, - client: client, - } - - return &FeeChecker{ - config: chainConfig, - sgaFactory: sgaFactory, - logger: logger, - } -} - -// L1Cost calculates the L1 fee for a transaction -func (fc *FeeChecker) L1Cost(rcd gethTypes.RollupCostData, blockTime uint64, blockNumber *big.Int) *big.Int { - - // Create L1 cost function - l1CostFn := gethTypes.NewL1CostFunc(fc.config, fc.sgaFactory.NewStateGetterAdapter(blockNumber)) - return l1CostFn(rcd, blockTime) -} - -// OperatorFee calculates the operator fee for a transaction -func (fc *FeeChecker) OperatorFee(gasUsed uint64, blockTime uint64, blockNumber *big.Int) *big.Int { - operatorFeeFn := gethTypes.NewOperatorCostFunc(fc.config, fc.sgaFactory.NewStateGetterAdapter(blockNumber)) - return operatorFeeFn(gasUsed, blockTime).ToBig() -} - -// CalculateExpectedBalanceChanges creates a BalanceSnapshot containing expected fee movements -// Calculates all fees internally from raw inputs -func (fc *FeeChecker) CalculateExpectedBalanceChanges( - gasUsedUint64 uint64, - header *gethTypes.Header, - tx *gethTypes.Transaction, -) *BalanceSnapshot { - // Convert the gas used (uint64) to a big.Int. - gasUsed := new(big.Int).SetUint64(gasUsedUint64) - - // 1. Base Fee Burned: header.BaseFee * gasUsed - baseFee := new(big.Int).Mul(header.BaseFee, gasUsed) - - // 2. Calculate the effective tip. - // Effective tip is the minimum of: - // a) tx.GasTipCap() and - // b) tx.GasFeeCap() - header.BaseFee - tipCap := tx.GasTipCap() // maximum priority fee per gas offered by the user - feeCap := tx.GasFeeCap() // maximum fee per gas the user is willing to pay - - // Compute feeCap minus the base fee. - diff := new(big.Int).Sub(feeCap, header.BaseFee) - - // effectiveTip = min(tipCap, diff) - effectiveTip := new(big.Int) - if tipCap.Cmp(diff) < 0 { - effectiveTip.Set(tipCap) - } else { - effectiveTip.Set(diff) - } - - // 3. Coinbase Fee Credit: effectiveTip * gasUsed. - l2Fee := new(big.Int).Mul(effectiveTip, gasUsed) - - // Calculate L1 fee - - fc.logger.Debug("Calculating L1 fee", "rollupCostData", tx.RollupCostData(), "blockTime", header.Time) - l1Fee := fc.L1Cost(tx.RollupCostData(), header.Time, header.Number) - - // Calculate operator fee - fc.logger.Debug("Calculating operator fee", "gasUsed", gasUsedUint64, "blockTime", header.Time) - operatorFee := fc.OperatorFee(gasUsedUint64, header.Time, header.Number) - - txFeesAndValue := new(big.Int).Set(baseFee) - txFeesAndValue.Add(txFeesAndValue, l2Fee) - txFeesAndValue.Add(txFeesAndValue, l1Fee) - txFeesAndValue.Add(txFeesAndValue, operatorFee) - txFeesAndValue.Add(txFeesAndValue, tx.Value()) - - // Create a changes snapshot with expected fee movements - changes := &BalanceSnapshot{ - BaseFeeVaultBalance: baseFee, - L1FeeVaultBalance: l1Fee, - SequencerFeeVault: l2Fee, - OperatorFeeVault: operatorFee, // Operator fee is withdrawn - FromBalance: new(big.Int).Neg(txFeesAndValue), - } - - return changes -} diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/system_config_contract_utils.go b/op-acceptance-tests/tests/isthmus/operator_fee/system_config_contract_utils.go deleted file mode 100644 index bb5c54780a6f8..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/system_config_contract_utils.go +++ /dev/null @@ -1,103 +0,0 @@ -package operatorfee - -// NOTE: These utility functions have been converted from devnet-sdk to op-devstack types -// but are currently unused by tests. They would need implementation updates if used. - -import ( - "fmt" - - "github.com/ethereum-optimism/optimism/op-devstack/dsl" - "github.com/ethereum-optimism/optimism/op-e2e/bindings" - "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - gethTypes "github.com/ethereum/go-ethereum/core/types" -) - -type TestParams struct { - ID string - OperatorFeeScalar uint32 - OperatorFeeConstant uint64 - L1BaseFeeScalar uint32 - L1BlobBaseFeeScalar uint32 -} - -func GetFeeParamsL1(systemConfig *bindings.SystemConfig, systemConfigAddress common.Address, l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA) (tc TestParams, err error) { - operatorFeeConstant, err := systemConfig.OperatorFeeConstant(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get operator fee constant: %w", err) - } - operatorFeeScalar, err := systemConfig.OperatorFeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get operator fee scalar: %w", err) - } - l1BaseFeeScalar, err := systemConfig.BasefeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get l1 base fee scalar: %w", err) - } - l1BlobBaseFeeScalar, err := systemConfig.BlobbasefeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get l1 blob base fee scalar: %w", err) - } - return TestParams{ - OperatorFeeConstant: operatorFeeConstant, - OperatorFeeScalar: operatorFeeScalar, - L1BaseFeeScalar: l1BaseFeeScalar, - L1BlobBaseFeeScalar: l1BlobBaseFeeScalar, - }, nil -} - -func GetFeeParamsL2(l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA) (tc TestParams, err error) { - operatorFeeConstant, err := l2L1BlockContract.OperatorFeeConstant(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get operator fee constant: %w", err) - } - operatorFeeScalar, err := l2L1BlockContract.OperatorFeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get operator fee scalar: %w", err) - } - l1BaseFeeScalar, err := l2L1BlockContract.BaseFeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get l1 base fee scalar: %w", err) - } - l1BlobBaseFeeScalar, err := l2L1BlockContract.BlobBaseFeeScalar(&bind.CallOpts{BlockNumber: nil}) - if err != nil { - return TestParams{}, fmt.Errorf("failed to get l1 blob base fee scalar: %w", err) - } - return TestParams{ - OperatorFeeConstant: operatorFeeConstant, - OperatorFeeScalar: operatorFeeScalar, - L1BaseFeeScalar: l1BaseFeeScalar, - L1BlobBaseFeeScalar: l1BlobBaseFeeScalar, - }, nil -} - -func EnsureFeeParams(systemConfig *bindings.SystemConfig, systemConfigAddress common.Address, l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA, tc TestParams) (err error, reset func() error) { - preFeeParams, err := GetFeeParamsL1(systemConfig, systemConfigAddress, l2L1BlockContract, wallet) - if err != nil { - return fmt.Errorf("failed to get L1 fee parameters: %w", err), nil - } - preFeeParams.ID = tc.ID - - if preFeeParams == tc { - // No need to update - return nil, nil - } - - return UpdateFeeParams(systemConfig, systemConfigAddress, l2L1BlockContract, wallet, tc), func() error { - return UpdateFeeParams(systemConfig, systemConfigAddress, l2L1BlockContract, wallet, preFeeParams) - } -} - -func UpdateFeeParams(systemConfig *bindings.SystemConfig, systemConfigAddress common.Address, l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA, tc TestParams) (err error) { - return fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} - -// UpdateOperatorFeeParams updates the operator fee parameters in the SystemConfig contract. -// It constructs and sends a transaction using txplan and returns the signed transaction, the receipt, or an error. -func UpdateOperatorFeeParams(systemConfig *bindings.SystemConfig, systemConfigAddress common.Address, l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA, operatorFeeConstant uint64, operatorFeeScalar uint32) (receipt *gethTypes.Receipt, err error) { - return nil, fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} - -func UpdateL1FeeParams(systemConfig *bindings.SystemConfig, systemConfigAddress common.Address, l2L1BlockContract *bindings.L1Block, wallet *dsl.EOA, l1BaseFeeScalar uint32, l1BlobBaseFeeScalar uint32) (receipt *gethTypes.Receipt, err error) { - return nil, fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} diff --git a/op-acceptance-tests/tests/isthmus/operator_fee/tx_utils.go b/op-acceptance-tests/tests/isthmus/operator_fee/tx_utils.go deleted file mode 100644 index 2763596cc9c0e..0000000000000 --- a/op-acceptance-tests/tests/isthmus/operator_fee/tx_utils.go +++ /dev/null @@ -1,30 +0,0 @@ -package operatorfee - -// NOTE: These utility functions have been converted from devnet-sdk to op-devstack types -// but are currently unused by tests. They would need implementation updates if used. - -import ( - "context" - "fmt" - - "github.com/ethereum-optimism/optimism/op-devstack/dsl" - "github.com/ethereum-optimism/optimism/op-service/eth" - "github.com/ethereum/go-ethereum/common" - gethTypes "github.com/ethereum/go-ethereum/core/types" -) - -func EnsureSufficientBalance(wallet *dsl.EOA, to common.Address, value eth.ETH) (err error) { - return fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} - -func SendValueTx(wallet *dsl.EOA, to common.Address, value eth.ETH) (tx *gethTypes.Transaction, receipt *gethTypes.Receipt, err error) { - return nil, nil, fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} - -func ReturnRemainingFunds(wallet *dsl.EOA, to common.Address) (receipt *gethTypes.Receipt, err error) { - return nil, fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -} - -func NewTestWallet(ctx context.Context, el dsl.ELNode) (*dsl.EOA, error) { - return nil, fmt.Errorf("not implemented for op-devstack - utility function not used by tests") -}