Skip to content

Commit

Permalink
feat: use discounted liquid transaction size
Browse files Browse the repository at this point in the history
  • Loading branch information
jackstar12 committed Jan 3, 2025
1 parent 29781cb commit 8dfcc13
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 49 deletions.
5 changes: 1 addition & 4 deletions boltz/liquid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"encoding/hex"
"errors"
"fmt"
"math"

"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/txscript"
"github.com/vulpemventures/go-elements/address"
Expand Down Expand Up @@ -79,8 +77,7 @@ func (transaction *LiquidTransaction) VoutValue(vout uint32) (uint64, error) {
}

func (transaction *LiquidTransaction) VSize() uint64 {
witnessSize := transaction.SerializeSize(true, true) - transaction.SerializeSize(false, true)
return uint64(transaction.SerializeSize(false, true)) + uint64(math.Ceil(float64(witnessSize)/4))
return uint64(transaction.DiscountVirtualSize())
}

func liquidTaprootHash(transaction *liquidtx.Transaction, network *Network, outputs []OutputDetails, index int, cooperative bool) []byte {
Expand Down
6 changes: 3 additions & 3 deletions nursery/nursery.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (nursery *Nursery) createTransaction(currency boltz.Currency, outputs []*Ou
return id, err
}

feeSatPerVbyte, err := nursery.onchain.EstimateFee(currency, true)
feeSatPerVbyte, err := nursery.onchain.EstimateFee(currency)
if err != nil {
return handleErr(fmt.Errorf("could not get fee estimation: %w", err))
}
Expand Down Expand Up @@ -372,11 +372,11 @@ func (nursery *Nursery) populateOutputs(outputs []*Output) (valid []*Output, det

func (nursery *Nursery) CheckAmounts(swapType boltz.SwapType, pair boltz.Pair, sendAmount uint64, receiveAmount uint64, serviceFee boltz.Percentage) (err error) {
fees := make(boltz.FeeEstimations)
fees[boltz.CurrencyLiquid], err = nursery.onchain.EstimateFee(boltz.CurrencyLiquid, true)
fees[boltz.CurrencyLiquid], err = nursery.onchain.EstimateFee(boltz.CurrencyLiquid)
if err != nil {
return err
}
fees[boltz.CurrencyBtc], err = nursery.onchain.EstimateFee(boltz.CurrencyBtc, true)
fees[boltz.CurrencyBtc], err = nursery.onchain.EstimateFee(boltz.CurrencyBtc)
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions onchain/onchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ func (onchain *Onchain) GetWallets(checker WalletChecker) []Wallet {
return wallets
}

func (onchain *Onchain) EstimateFee(currency boltz.Currency, allowLowball bool) (float64, error) {
if currency == boltz.CurrencyLiquid && onchain.Network == boltz.MainNet && allowLowball {
if boltzProvider, ok := onchain.Liquid.Tx.(*BoltzTxProvider); ok {
return boltzProvider.GetFeeEstimation(boltz.CurrencyLiquid)
}
}
func (onchain *Onchain) EstimateFee(currency boltz.Currency) (float64, error) {
chain, err := onchain.GetCurrency(currency)
if err != nil {
return 0, err
Expand Down
33 changes: 0 additions & 33 deletions onchain/onchain_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion onchain/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"github.com/BoltzExchange/boltz-client/v2/boltz"
)

const MinFeeRate = 0.01
const MinFeeRate = 0.1
const MaxInputs = uint64(255) // TODO: change back to 256 when gdk is fixed
const DefaultAutoConsolidateThreshold = uint64(200)
const GapLimit = 100
Expand Down
4 changes: 2 additions & 2 deletions rpcserver/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,7 @@ func (server *routedBoltzServer) GetWalletSendFee(ctx context.Context, request *
}
feeRate := request.GetSatPerVbyte()
if feeRate == 0 {
feeRate, err = server.onchain.EstimateFee(ownWallet.Currency, request.GetIsSwapAddress())
feeRate, err = server.onchain.EstimateFee(ownWallet.Currency)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -2237,7 +2237,7 @@ func (server *routedBoltzServer) estimateFee(requested float64, currency boltz.C
logger.Infof("Amount %d exceeds maximal zero conf amount %d, allowing lowball", amount, maxZeroConfAmount)
allowLowball = true
}
feeSatPerVbyte, err := server.onchain.EstimateFee(currency, allowLowball)
feeSatPerVbyte, err := server.onchain.EstimateFee(currency)
if err != nil {
return 0, err
}
Expand Down

0 comments on commit 8dfcc13

Please sign in to comment.