Skip to content

Commit

Permalink
adjust fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvionied committed Oct 17, 2024
1 parent a410a61 commit fdbcc7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
22 changes: 21 additions & 1 deletion ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ func (b *Apollo) estimateFee() int64 {
return 0
}
fakeTxBytes, _ := fftx.Bytes()
estimatedFee := Utils.Fee(b.Context, len(fakeTxBytes), pExU.Steps, pExU.Mem, fftx.TransactionBody.ReferenceInputs)
fakeTxLength := len([]byte(hex.EncodeToString(fakeTxBytes)))
estimatedFee := Utils.Fee(b.Context, fakeTxLength, pExU.Steps, pExU.Mem, fftx.TransactionBody.ReferenceInputs)
estimatedFee += b.FeePadding
return estimatedFee

Expand Down Expand Up @@ -928,20 +929,26 @@ func (b *Apollo) updateExUnits() *Apollo {
key := fmt.Sprintf("%s:%d", Redeemer.RdeemerTagNames[redeemer.Tag], redeemer.Index)
if _, ok := estimated_execution_units[key]; ok {
redeemer.ExUnits = estimated_execution_units[key]
redeemer.ExUnits.Mem = int64(float32(redeemer.ExUnits.Mem) * 1.2)
redeemer.ExUnits.Steps = int64(float32(redeemer.ExUnits.Steps) * 1.2)
b.redeemersToUTxO[k] = redeemer
}
}
for k, redeemer := range b.stakeRedeemers {
key := fmt.Sprintf("%s:%d", Redeemer.RdeemerTagNames[redeemer.Tag], redeemer.Index)
if _, ok := estimated_execution_units[key]; ok {
redeemer.ExUnits = estimated_execution_units[key]
redeemer.ExUnits.Mem = int64(float32(redeemer.ExUnits.Mem) * 1.2)
redeemer.ExUnits.Steps = int64(float32(redeemer.ExUnits.Steps) * 1.2)
b.stakeRedeemers[k] = redeemer
}
}
for k, redeemer := range b.mintRedeemers {
key := fmt.Sprintf("%s:%d", Redeemer.RdeemerTagNames[redeemer.Tag], redeemer.Index)
if _, ok := estimated_execution_units[key]; ok {
redeemer.ExUnits = estimated_execution_units[key]
redeemer.ExUnits.Mem = int64(float32(redeemer.ExUnits.Mem) * 1.2)
redeemer.ExUnits.Steps = int64(float32(redeemer.ExUnits.Steps) * 1.2)
b.mintRedeemers[k] = redeemer
}
}
Expand Down Expand Up @@ -1914,3 +1921,16 @@ func (b *Apollo) updateExUnitsExact(fee int) *Apollo {
func (b *Apollo) GetPaymentsLength() int {
return len(b.payments)
}

func (b *Apollo) GetRedeemers() map[string]Redeemer.Redeemer {
return b.redeemersToUTxO
}

func (b *Apollo) UpdateRedeemers(newRedeemers map[string]Redeemer.Redeemer) *Apollo {
b.redeemersToUTxO = newRedeemers
return b
}

func (b *Apollo) GetSortedInputs() []UTxO.UTxO {
return SortUtxos(b.preselectedUtxos)
}
7 changes: 4 additions & 3 deletions txBuilding/Utils/Utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ func Fee(context Base.ChainContext, txSize int, steps int64, mem int64, refInput
mult := 1.2
baseFee := 15.0
Range := 25600.0
for refInputsSize > 0 {
for refInputsSize > int(Range) {
cur := Range
curFee := cur * baseFee
addedFee += int(curFee)
refInputsSize -= int(cur)
baseFee = baseFee * mult
}
fee := int64(txSize*pm.MinFeeCoefficient+

fee := int64(((5/2)*txSize)*pm.MinFeeCoefficient+
pm.MinFeeConstant+
int(float32(steps)*pm.PriceStep)+
int(float32(mem)*pm.PriceMem)) + 10_000 + int64(addedFee)
int(float32(mem)*pm.PriceMem)) + int64(addedFee)
return fee
}

Expand Down

0 comments on commit fdbcc7d

Please sign in to comment.