Copyright | (c) 2025 GYELD GMBH |
---|---|
License | Apache 2.0 |
Maintainer | [email protected] |
Stability | develop |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
GeniusYield.Transaction.CoinSelection.Balance
Description
Largely a simplified version of Cardano.CoinSelection.Balance
.
Synopsis
- type UTxO = GYTxOutRef
- data ValueSizeAssessment
- type ValueSizeAssessor = GYValue → ValueSizeAssessment
- data SelectionStrategy
- data SelectionConstraints = SelectionConstraints {}
- data SelectionParams f = SelectionParams {}
- data SelectionResult f = SelectionResult {
- inputsSelected ∷ !(NonEmpty (UTxO, GYValue))
- extraCoinSource ∷ !Natural
- extraCoinSink ∷ !Natural
- outputsCovered ∷ !(f (GYAddress, GYValue))
- changeGenerated ∷ ![GYValue]
- assetsToMint ∷ !GYValue
- assetsToBurn ∷ !GYValue
- data SelectionBalanceError
- data BalanceInsufficientError = BalanceInsufficientError {}
- data UnableToConstructChangeError = UnableToConstructChangeError {}
- performSelection ∷ ∀ m. (HasCallStack, MonadRandom m) ⇒ PerformSelection m List
- selectionHasValidSurplus ∷ Foldable f ⇒ SelectionConstraints → SelectionResult f → Bool
- selectionDeltaCoin ∷ Foldable f ⇒ SelectionResult f → SelectionDelta Natural
- selectionSurplusCoin ∷ Foldable f ⇒ SelectionResult f → Natural
- runRoundRobin ∷ s → (s' → s) → [s → Maybe s'] → s
Documentation
type UTxO = GYTxOutRef #
data ValueSizeAssessment #
Constructors
ValueSizeWithinLimit | Indicates that the size of a value does not exceed the maximum size that can be included in a transaction output. |
ValueSizeExceedsLimit | Indicates that the size of a value exceeds the maximum size that can be included in a transaction output. |
Instances
Generic ValueSizeAssessment # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types type Rep ValueSizeAssessment ∷ Type → Type # Methods | |
Show ValueSizeAssessment # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec ∷ Int → ValueSizeAssessment → ShowS # show ∷ ValueSizeAssessment → String # showList ∷ [ValueSizeAssessment] → ShowS # | |
Eq ValueSizeAssessment # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods | |
type Rep ValueSizeAssessment # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep ValueSizeAssessment = D1 ('MetaData "ValueSizeAssessment" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.0-inplace" 'False) (C1 ('MetaCons "ValueSizeWithinLimit" 'PrefixI 'False) (U1 ∷ Type → Type) :+: C1 ('MetaCons "ValueSizeExceedsLimit" 'PrefixI 'False) (U1 ∷ Type → Type)) |
type ValueSizeAssessor = GYValue → ValueSizeAssessment #
data SelectionStrategy #
Indicates a choice of selection strategy.
A SelectionStrategy
determines how much of each asset the selection
algorithm will attempt to select from the available UTxO set, relative to
the minimum amount necessary to make the selection balance.
The default SelectionStrategy
is SelectionStrategyOptimal
, which when
specified will cause the selection algorithm to attempt to select around
twice the minimum possible amount of each asset from the available
UTxO set, making it possible to generate change outputs that are roughly
the same sizes and shapes as the user-specified outputs.
Specifying SelectionStrategyMinimal
will cause the selection algorithm to
only select just enough of each asset from the available UTxO set to
meet the minimum amount. The selection process will terminate as soon as
the minimum amount of each asset is covered.
The "optimal" strategy is recommended for most situations, as using this strategy will help to ensure that a wallet's UTxO distribution can evolve over time to resemble the typical distribution of payments made by the wallet owner. This increases the likelihood that future selections will succeed, and lowers the amortized cost of future transactions.
The "minimal" strategy is recommended only for situations where it is not possible to create a selection with the "optimal" strategy. It is advised to use this strategy only when necessary, as it increases the likelihood of generating change outputs that are much smaller than user-specified outputs. If this strategy is used regularly, the UTxO set can evolve to a state where the distribution no longer resembles the typical distribution of payments made by the user. This increases the likelihood that future selections will not succeed, and increases the amortized cost of future transactions.
Constructors
SelectionStrategyMinimal | |
SelectionStrategyOptimal |
Instances
data SelectionConstraints #
Specifies all constraints required for coin selection.
Constructors
SelectionConstraints | |
Fields
|
Instances
Generic SelectionConstraints # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types type Rep SelectionConstraints ∷ Type → Type # Methods | |
type Rep SelectionConstraints # | |
data SelectionParams f #
Specifies all parameters that are specific to a given selection.
Constructors
SelectionParams | |
Fields
|
Instances
data SelectionResult f #
The result of performing a successful selection.
Constructors
SelectionResult | |
Fields
|
Instances
data SelectionBalanceError #
Represents the set of errors that may occur while performing a selection.
Constructors
BalanceInsufficient BalanceInsufficientError | |
UnableToConstructChange UnableToConstructChangeError | |
EmptyUTxO |
Instances
data BalanceInsufficientError #
Indicates that the balance of available UTxO entries is insufficient to cover the balance required.
See computeUTxOBalanceSufficiency
.
Constructors
BalanceInsufficientError | |
Fields
|
Instances
Generic BalanceInsufficientError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types type Rep BalanceInsufficientError ∷ Type → Type # | |
Show BalanceInsufficientError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec ∷ Int → BalanceInsufficientError → ShowS # | |
Eq BalanceInsufficientError # | |
type Rep BalanceInsufficientError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep BalanceInsufficientError = D1 ('MetaData "BalanceInsufficientError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.0-inplace" 'False) (C1 ('MetaCons "BalanceInsufficientError" 'PrefixI 'True) (S1 ('MetaSel ('Just "utxoBalanceAvailable") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue) :*: (S1 ('MetaSel ('Just "utxoBalanceRequired") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue) :*: S1 ('MetaSel ('Just "utxoBalanceShortfall") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue)))) |
data UnableToConstructChangeError #
Constructors
UnableToConstructChangeError | |
Fields
|
Instances
Generic UnableToConstructChangeError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types type Rep UnableToConstructChangeError ∷ Type → Type # | |
Show UnableToConstructChangeError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec ∷ Int → UnableToConstructChangeError → ShowS # | |
Eq UnableToConstructChangeError # | |
type Rep UnableToConstructChangeError # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep UnableToConstructChangeError = D1 ('MetaData "UnableToConstructChangeError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.0-inplace" 'False) (C1 ('MetaCons "UnableToConstructChangeError" 'PrefixI 'True) (S1 ('MetaSel ('Just "requiredCost") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural) :*: S1 ('MetaSel ('Just "shortfall") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural))) |
performSelection ∷ ∀ m. (HasCallStack, MonadRandom m) ⇒ PerformSelection m List #
Performs a coin selection and generates change values in one step.
Provided that isUTxOBalanceSufficient
returns True
for the given
selection criteria, this function guarantees to return a SelectionResult
for which selectionHasValidSurplus
returns True
.
selectionHasValidSurplus ∷ Foldable f ⇒ SelectionConstraints → SelectionResult f → Bool #
Indicates whether or not a selection result has a valid surplus.
selectionDeltaCoin ∷ Foldable f ⇒ SelectionResult f → SelectionDelta Natural #
Calculates the ada selection delta.
See SelectionDelta
.
selectionSurplusCoin ∷ Foldable f ⇒ SelectionResult f → Natural #
Calculates the ada selection surplus, assuming there is a surplus.
If there is a surplus, then this function returns that surplus. If there is a deficit, then this function returns zero.
Use selectionDeltaCoin
if you wish to handle the case where there is
a deficit.
runRoundRobin ∷ s → (s' → s) → [s → Maybe s'] → s #