tbtcpg

package
v1.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateDepositsSweepFee

func EstimateDepositsSweepFee(
	chain Chain,
	btcChain bitcoin.Chain,
	depositsCount int,
) (
	map[int]struct {
		TotalFee       int64
		SatPerVByteFee int64
	},
	error,
)

EstimateDepositsSweepFee computes the total fee for the Bitcoin deposits sweep transaction for the given depositsCount. If the provided depositsCount is 0, this function computes the total fee for Bitcoin deposits sweep transactions containing a various number of input deposits, from 1 up to the maximum count allowed by the WalletProposalValidator contract. Computed fees for specific deposits counts are returned as a map.

While making estimations, this function assumes a sweep transaction consists of:

  • 1 P2WPKH input being the current wallet main UTXO. That means the produced fees may be overestimated for the very first sweep transaction of each wallet.
  • N P2WSH inputs representing the deposits. Worth noting that real transactions may contain legacy P2SH deposits as well so produced fees may be underestimated in some rare cases.
  • 1 P2WPKH output

If any of the estimated fees exceed the maximum fee allowed by the Bridge contract, an error is returned as result.

func EstimateRedemptionFee

func EstimateRedemptionFee(
	btcChain bitcoin.Chain,
	redeemersOutputScripts []bitcoin.Script,
) (int64, error)

EstimateRedemptionFee estimates fee for the redemption transaction that pays the provided redeemers output scripts.

Types

type Chain

type Chain interface {
	tbtc.BridgeChain

	// PastNewWalletRegisteredEvents fetches past new wallet registered events
	// according to the provided filter or unfiltered if the filter is nil. Returned
	// events are sorted by the block number in the ascending order, i.e. the
	// latest event is at the end of the slice.
	PastNewWalletRegisteredEvents(
		filter *tbtc.NewWalletRegisteredEventFilter,
	) ([]*tbtc.NewWalletRegisteredEvent, error)

	// BuildDepositKey calculates a deposit key for the given funding transaction
	// which is a unique identifier for a deposit on-chain.
	BuildDepositKey(fundingTxHash bitcoin.Hash, fundingOutputIndex uint32) *big.Int

	// GetDepositParameters gets the current value of parameters relevant
	// for the depositing process.
	GetDepositParameters() (
		dustThreshold uint64,
		treasuryFeeDivisor uint64,
		txMaxFee uint64,
		revealAheadPeriod uint32,
		err error,
	)

	// PastRedemptionRequestedEvents fetches past redemption requested events according
	// to the provided filter or unfiltered if the filter is nil. Returned
	// events are sorted by the block number in the ascending order, i.e. the
	// latest event is at the end of the slice.
	PastRedemptionRequestedEvents(
		filter *tbtc.RedemptionRequestedEventFilter,
	) ([]*tbtc.RedemptionRequestedEvent, error)

	// BuildRedemptionKey calculates a redemption key for the given redemption
	// request which is an identifier for a redemption at the given time
	// on-chain.
	BuildRedemptionKey(
		walletPublicKeyHash [20]byte,
		redeemerOutputScript bitcoin.Script,
	) (*big.Int, error)

	// GetRedemptionParameters gets the current value of parameters relevant
	// for the redemption process.
	GetRedemptionParameters() (
		dustThreshold uint64,
		treasuryFeeDivisor uint64,
		txMaxFee uint64,
		txMaxTotalFee uint64,
		timeout uint32,
		timeoutSlashingAmount *big.Int,
		timeoutNotifierRewardMultiplier uint32,
		err error,
	)

	// GetRedemptionMaxSize gets the maximum number of redemption requests that
	// can be a part of a redemption sweep proposal.
	GetRedemptionMaxSize() (uint16, error)

	// GetRedemptionRequestMinAge get the  minimum time that must elapse since
	// the redemption request creation before a request becomes eligible for
	// a processing.
	GetRedemptionRequestMinAge() (uint32, error)

	// ValidateDepositSweepProposal validates the given deposit sweep proposal
	// against the chain. It requires some additional data about the deposits
	// that must be fetched externally. Returns an error if the proposal is
	// not valid or nil otherwise.
	ValidateDepositSweepProposal(
		walletPublicKeyHash [20]byte,
		proposal *tbtc.DepositSweepProposal,
		depositsExtraInfo []struct {
			*tbtc.Deposit
			FundingTx *bitcoin.Transaction
		},
	) error

	// ValidateRedemptionProposal validates the given redemption proposal
	// against the chain. Returns an error if the proposal is not valid or
	// nil otherwise.
	ValidateRedemptionProposal(
		walletPublicKeyHash [20]byte,
		proposal *tbtc.RedemptionProposal,
	) error

	// GetDepositSweepMaxSize gets the maximum number of deposits that can
	// be part of a deposit sweep proposal.
	GetDepositSweepMaxSize() (uint16, error)

	BlockCounter() (chain.BlockCounter, error)

	AverageBlockTime() time.Duration

	// ValidateHeartbeatProposal validates the given heartbeat proposal
	// against the chain. Returns an error if the proposal is not valid or
	// nil otherwise.
	ValidateHeartbeatProposal(
		walletPublicKeyHash [20]byte,
		proposal *tbtc.HeartbeatProposal,
	) error
}

Chain represents the interface that the wallet maintainer module expects to interact with the anchoring blockchain on.

type Deposit

type Deposit struct {
	DepositReference

	WalletPublicKeyHash [20]byte
	ScriptType          bitcoin.ScriptType
	DepositKey          string
	IsSwept             bool
	AmountBtc           float64
	Confirmations       uint
}

Deposit holds some detailed data about a deposit.

func FindDeposits

func FindDeposits(
	chain Chain,
	btcChain bitcoin.Chain,
	walletPublicKeyHash [20]byte,
	maxNumberOfDeposits int,
	skipSwept bool,
	skipUnconfirmed bool,
) ([]*Deposit, error)

FindDeposits finds deposits according to the given criteria.

type DepositReference

type DepositReference struct {
	FundingTxHash      bitcoin.Hash
	FundingOutputIndex uint32
	RevealBlock        uint64
}

DepositReference holds some data allowing to identify and refer to a deposit.

type DepositSweepTask

type DepositSweepTask struct {
	// contains filtered or unexported fields
}

DepositSweepTask is a task that may produce a deposit sweep proposal.

func NewDepositSweepTask

func NewDepositSweepTask(
	chain Chain,
	btcChain bitcoin.Chain,
) *DepositSweepTask

func (*DepositSweepTask) ActionType

func (dst *DepositSweepTask) ActionType() tbtc.WalletActionType

func (*DepositSweepTask) FindDepositsToSweep

func (dst *DepositSweepTask) FindDepositsToSweep(
	taskLogger log.StandardLogger,
	walletPublicKeyHash [20]byte,
	maxNumberOfDeposits uint16,
) ([]*DepositReference, error)

FindDepositsToSweep finds deposits that can be swept. maxNumberOfDeposits is used as a ceiling for the number of deposits in the result. If number of discovered deposits meets the maxNumberOfDeposits the function will stop fetching more deposits. This function will return a list of deposits from the wallet that can be swept. Deposits with insufficient number of funding transaction confirmations will not be taken into consideration for sweeping.

TODO: Cache immutable data

func (*DepositSweepTask) ProposeDepositsSweep

func (dst *DepositSweepTask) ProposeDepositsSweep(
	taskLogger log.StandardLogger,
	walletPublicKeyHash [20]byte,
	deposits []*DepositReference,
	fee int64,
) (*tbtc.DepositSweepProposal, error)

ProposeDepositsSweep returns a deposit sweep proposal.

func (*DepositSweepTask) Run

type HeartbeatTask

type HeartbeatTask struct {
	// contains filtered or unexported fields
}

HeartbeatTask is a task that may produce a heartbeat proposal.

func NewHeartbeatTask

func NewHeartbeatTask(chain Chain) *HeartbeatTask

func (*HeartbeatTask) ActionType

func (ht *HeartbeatTask) ActionType() tbtc.WalletActionType

func (*HeartbeatTask) Run

type ProposalGenerator

type ProposalGenerator struct {
	// contains filtered or unexported fields
}

ProposalGenerator is a component responsible for generating coordination proposals for tbtc wallets.

func NewProposalGenerator

func NewProposalGenerator(
	chain Chain,
	btcChain bitcoin.Chain,
) *ProposalGenerator

NewProposalGenerator returns a new proposal generator.

func (*ProposalGenerator) Generate

Generate generates a coordination proposal based on the given checklist of possible wallet actions. The checklist is a list of actions that should be checked for the given coordination window. This function returns a proposal for the first action from the checklist that is valid for the given wallet's state. If none of the actions are valid, the generator returns a no-op proposal.

type ProposalTask

type ProposalTask interface {
	// Run executes the task and returns a proposal, a boolean flag indicating
	// whether the proposal was generated and an error if any.
	Run(
		request *tbtc.CoordinationProposalRequest,
	) (tbtc.CoordinationProposal, bool, error)

	// ActionType returns the type of the action proposal.
	ActionType() tbtc.WalletActionType
}

ProposalTask encapsulates logic used to generate an action proposal of the given type.

type RedemptionRequest

type RedemptionRequest struct {
	WalletPublicKeyHash  [20]byte
	RedemptionKey        string
	RedeemerOutputScript bitcoin.Script
	RequestedAt          time.Time
	RequestedAmount      uint64
}

RedemptionRequest represents a redemption request.

type RedemptionTask

type RedemptionTask struct {
	// contains filtered or unexported fields
}

RedemptionTask is a task that may produce a redemption proposal.

func NewRedemptionTask

func NewRedemptionTask(
	chain Chain,
	btcChain bitcoin.Chain,
) *RedemptionTask

func (*RedemptionTask) ActionType

func (rt *RedemptionTask) ActionType() tbtc.WalletActionType

func (*RedemptionTask) FindPendingRedemptions

func (rt *RedemptionTask) FindPendingRedemptions(
	taskLogger log.StandardLogger,
	walletPublicKeyHash [20]byte,
	maxNumberOfRequests uint16,
) ([]bitcoin.Script, error)

FindPendingRedemptions finds pending redemptions requests for the provided wallet. The returned value is a list of redeemers output scripts that come from detected pending requests targeting this wallet. The maxNumberOfRequests parameter is used as a ceiling for the number of requests in the result. If number of discovered requests meets the maxNumberOfRequests the function will stop fetching more requests.

func (*RedemptionTask) ProposeRedemption

func (rt *RedemptionTask) ProposeRedemption(
	taskLogger log.StandardLogger,
	walletPublicKeyHash [20]byte,
	redeemersOutputScripts []bitcoin.Script,
	fee int64,
) (*tbtc.RedemptionProposal, error)

ProposeRedemption returns a redemption proposal.

func (*RedemptionTask) Run

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL