func (t *AccountTally) CalcMakerDelta(feeSchedule terms.FeeSchedule,
	price FixedRatePremium, totalSats btcutil.Amount,
	duration uint32) btcutil.Amount {
	balanceDelta, makerFeesAccrued, executionFee := makerDelta(
		feeSchedule, price, totalSats, duration,
	)
	t.EndingBalance += balanceDelta
	t.TotalMakerFeesAccrued += makerFeesAccrued
	t.TotalExecutionFeesPaid += executionFee
	return executionFee
}
CalcMakerDelta calculates an account's balance and fee difference for a
single order where the account is involved on the maker side. It returns the
execution fee that is collected by the auctioneer.
package order
import (
	"github.com/btcsuite/btcd/blockchain"
	"github.com/btcsuite/btcutil"
	"github.com/lightninglabs/pool/poolscript"
	"github.com/lightninglabs/pool/terms"
	"github.com/lightningnetwork/lnd/input"
	"github.com/lightningnetwork/lnd/lnwallet"
	"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)
var (
	FeeRateTotalParts = 1e9
	dustLimitP2WPKH = lnwallet.DustLimitForSize(
		input.P2WPKHSize,
	)
	MinNoDustAccountSize = minNoDustAccountSize()
)
type FixedRatePremium uint32
func (f FixedRatePremium) LumpSumPremium(amt btcutil.Amount,
	durationBlocks uint32) btcutil.Amount {
	premiumPerBlock := PerBlockPremium(amt, uint32(f))
	return btcutil.Amount(premiumPerBlock * float64(durationBlocks))
}
func PerBlockPremium(amt btcutil.Amount, fixedRate uint32) float64 {
	return float64(amt) * float64(fixedRate) / FeeRateTotalParts
}
func EstimateTraderFee(numTraderChans uint32,
	feeRate chainfee.SatPerKWeight) btcutil.Amount {
	var weightEstimate int64
	weightEstimate += input.P2WSHOutputSize
	weightEstimate += input.InputSize
	chanOutputSize := uint32(input.P2WSHOutputSize)
	weightEstimate += int64(chanOutputSize*numTraderChans+1) / 2
	weightEstimate *= blockchain.WitnessScaleFactor
	weightEstimate += poolscript.MultiSigWitnessSize
	return feeRate.FeeForWeight(weightEstimate)
}
type Quote struct {
	TotalPremium btcutil.Amount
	RatePerBlock float64
	TotalExecutionFee btcutil.Amount
	WorstCaseChainFee btcutil.Amount
}
func NewQuote(amt, minChanAmt btcutil.Amount, rate FixedRatePremium,
	leaseDuration uint32, maxBatchFeeRate chainfee.SatPerKWeight,
	schedule terms.FeeSchedule) *Quote {
	exeFee := schedule.BaseFee() + schedule.ExecutionFee(amt)
	maxNumMatches := amt / minChanAmt
	chainFee := maxNumMatches * EstimateTraderFee(1, maxBatchFeeRate)
	return &Quote{
		TotalPremium:      rate.LumpSumPremium(amt, leaseDuration),
		RatePerBlock:      float64(rate) / FeeRateTotalParts,
		TotalExecutionFee: exeFee,
		WorstCaseChainFee: chainFee,
	}
}
type AccountTally struct {
	EndingBalance btcutil.Amount
	TotalExecutionFeesPaid btcutil.Amount
	TotalTakerFeesPaid btcutil.Amount
	TotalMakerFeesAccrued btcutil.Amount
	NumChansCreated uint32
}
func makerDelta(feeSchedule terms.FeeSchedule, price FixedRatePremium,
	totalSats btcutil.Amount, duration uint32) (btcutil.Amount,
	btcutil.Amount, btcutil.Amount) {
	balanceDelta := -totalSats
	satsPremium := price.LumpSumPremium(totalSats, duration)
	balanceDelta += satsPremium
	makerFeesAccrued := satsPremium
	executionFee := executionFee(totalSats, feeSchedule)
	balanceDelta -= executionFee
	return balanceDelta, makerFeesAccrued, executionFee
}