Skip to content

Commit

Permalink
update inclusionFee()
Browse files Browse the repository at this point in the history
  • Loading branch information
chowbao committed Jan 22, 2025
1 parent b6851fc commit 24fcd92
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 12 additions & 4 deletions ingest/ledger_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (t *LedgerTransaction) SorobanResourcesWriteBytes() (uint32, bool) {
return uint32(sorobanData.Resources.WriteBytes), true
}

func (t *LedgerTransaction) InclusionFeeBid() (int64, bool) {
func (t *LedgerTransaction) SorobanInclusionFeeBid() (int64, bool) {
resourceFee, ok := t.SorobanResourceFee()
if !ok {
return 0, false
Expand Down Expand Up @@ -410,13 +410,21 @@ func (t *LedgerTransaction) InclusionFeeCharged() (int64, bool) {
return inclusionFee, ok
}

// Inclusion fee for classic is just the base 100 stroops + surge pricing if surging
inclusionFee, ok = t.FeeCharged()
// Inclusion fee can be calculated from the equation:
// Fee charged = inclusion fee * (operation count + if(feeBumpAccount is not null, 1, 0))
// or inclusionFee = feeCharged/(operation count + if(feeBumpAccount is not null, 1, 0))
operationCount := t.OperationCount()
if t.Envelope.Type == 5 { // xdr.EnvelopeTypeEnvelopeTypeTxFeeBump
operationCount += 1
}

var feeCharged int64
feeCharged, ok = t.FeeCharged()
if !ok {
return 0, false
}

return inclusionFee, true
return feeCharged / int64(operationCount), true
}

func getAccountBalanceFromLedgerEntryChanges(changes xdr.LedgerEntryChanges, sourceAccountAddress string) (int64, int64) {
Expand Down
2 changes: 1 addition & 1 deletion ingest/ledger_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ func TestTransactionHelperFunctions(t *testing.T) {
assert.Equal(t, uint32(789), sorobanResourcesWriteBytes)

var inclusionFeeBid int64
inclusionFeeBid, ok = transaction.InclusionFeeBid()
inclusionFeeBid, ok = transaction.SorobanInclusionFeeBid()
assert.Equal(t, true, ok)
assert.Equal(t, int64(3326), inclusionFeeBid)

Expand Down

0 comments on commit 24fcd92

Please sign in to comment.