Copyright | (c) 2025 GYELD GMBH |
---|---|
License | Apache 2.0 |
Maintainer | [email protected] |
Stability | develop |
Safe Haskell | None |
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 {
- valueSizeAssessor :: ValueSizeAssessor
- computeMinimumAdaQuantity :: GYAddress -> GYValue -> Natural
- computeMinimumCost :: SelectionSkeleton -> Natural
- changeAddress :: GYAddress
- maximumOutputAdaQuantity :: Natural
- maximumOutputTokenQuantity :: Natural
- nullAddress :: GYAddress
- data SelectionParams (f :: Type -> Type) = SelectionParams {
- outputsToCover :: !(f (GYAddress, GYValue))
- utxoAvailable :: !(UTxOSelection UTxO)
- extraCoinSource :: !Natural
- extraCoinSink :: !Natural
- assetsToMint :: !GYValue
- assetsToBurn :: !GYValue
- selectionStrategy :: SelectionStrategy
- data SelectionResult (f :: Type -> Type) = 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 {
- requiredCost :: !Natural
- shortfall :: !Natural
- performSelection :: (HasCallStack, MonadRandom m) => PerformSelection m []
- selectionHasValidSurplus :: forall (f :: Type -> Type). Foldable f => SelectionConstraints -> SelectionResult f -> Bool
- selectionDeltaCoin :: forall (f :: Type -> Type). Foldable f => SelectionResult f -> SelectionDelta Natural
- selectionSurplusCoin :: forall (f :: Type -> Type). 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
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
Bounded SelectionStrategy # | |
Enum SelectionStrategy # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods succ :: SelectionStrategy -> SelectionStrategy # pred :: SelectionStrategy -> SelectionStrategy # toEnum :: Int -> SelectionStrategy # fromEnum :: SelectionStrategy -> Int # enumFrom :: SelectionStrategy -> [SelectionStrategy] # enumFromThen :: SelectionStrategy -> SelectionStrategy -> [SelectionStrategy] # enumFromTo :: SelectionStrategy -> SelectionStrategy -> [SelectionStrategy] # enumFromThenTo :: SelectionStrategy -> SelectionStrategy -> SelectionStrategy -> [SelectionStrategy] # | |
Show SelectionStrategy # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec :: Int -> SelectionStrategy -> ShowS # show :: SelectionStrategy -> String # showList :: [SelectionStrategy] -> ShowS # | |
Eq SelectionStrategy # | |
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods (==) :: SelectionStrategy -> SelectionStrategy -> Bool # (/=) :: SelectionStrategy -> SelectionStrategy -> Bool # |
data SelectionConstraints #
Specifies all constraints required for coin selection.
Constructors
SelectionConstraints | |
Fields
|
Instances
Generic SelectionConstraints # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types
Methods from :: SelectionConstraints -> Rep SelectionConstraints x # to :: Rep SelectionConstraints x -> SelectionConstraints # | |||||
type Rep SelectionConstraints # | |||||
data SelectionParams (f :: Type -> Type) #
Specifies all parameters that are specific to a given selection.
Constructors
SelectionParams | |
Fields
|
Instances
Generic (SelectionParams f) # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types
Methods from :: SelectionParams f -> Rep (SelectionParams f) x # to :: Rep (SelectionParams f) x -> SelectionParams f # | |||||
type Rep (SelectionParams f) # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep (SelectionParams f) = D1 ('MetaData "SelectionParams" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.14.0-inplace" 'False) (C1 ('MetaCons "SelectionParams" 'PrefixI 'True) ((S1 ('MetaSel ('Just "outputsToCover") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (f (GYAddress, GYValue))) :*: (S1 ('MetaSel ('Just "utxoAvailable") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (UTxOSelection UTxO)) :*: S1 ('MetaSel ('Just "extraCoinSource") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural))) :*: ((S1 ('MetaSel ('Just "extraCoinSink") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural) :*: S1 ('MetaSel ('Just "assetsToMint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue)) :*: (S1 ('MetaSel ('Just "assetsToBurn") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue) :*: S1 ('MetaSel ('Just "selectionStrategy") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SelectionStrategy))))) |
data SelectionResult (f :: Type -> Type) #
The result of performing a successful selection.
Constructors
SelectionResult | |
Fields
|
Instances
Generic (SelectionResult f) # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types
Methods from :: SelectionResult f -> Rep (SelectionResult f) x # to :: Rep (SelectionResult f) x -> SelectionResult f # | |||||
type Rep (SelectionResult f) # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep (SelectionResult f) = D1 ('MetaData "SelectionResult" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.14.0-inplace" 'False) (C1 ('MetaCons "SelectionResult" 'PrefixI 'True) ((S1 ('MetaSel ('Just "inputsSelected") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (NonEmpty (UTxO, GYValue))) :*: (S1 ('MetaSel ('Just "extraCoinSource") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural) :*: S1 ('MetaSel ('Just "extraCoinSink") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Natural))) :*: ((S1 ('MetaSel ('Just "outputsCovered") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (f (GYAddress, GYValue))) :*: S1 ('MetaSel ('Just "changeGenerated") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 [GYValue])) :*: (S1 ('MetaSel ('Just "assetsToMint") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue) :*: S1 ('MetaSel ('Just "assetsToBurn") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 GYValue))))) |
data SelectionBalanceError #
Represents the set of errors that may occur while performing a selection.
Constructors
BalanceInsufficient BalanceInsufficientError | |
UnableToConstructChange UnableToConstructChangeError | |
EmptyUTxO |
Instances
Generic SelectionBalanceError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Associated Types
Methods from :: SelectionBalanceError -> Rep SelectionBalanceError x # to :: Rep SelectionBalanceError x -> SelectionBalanceError # | |||||
Show SelectionBalanceError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec :: Int -> SelectionBalanceError -> ShowS # show :: SelectionBalanceError -> String # showList :: [SelectionBalanceError] -> ShowS # | |||||
Eq SelectionBalanceError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods (==) :: SelectionBalanceError -> SelectionBalanceError -> Bool # (/=) :: SelectionBalanceError -> SelectionBalanceError -> Bool # | |||||
type Rep SelectionBalanceError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep SelectionBalanceError = D1 ('MetaData "SelectionBalanceError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.14.0-inplace" 'False) (C1 ('MetaCons "BalanceInsufficient" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BalanceInsufficientError)) :+: (C1 ('MetaCons "UnableToConstructChange" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UnableToConstructChangeError)) :+: C1 ('MetaCons "EmptyUTxO" 'PrefixI 'False) (U1 :: Type -> Type))) |
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
Methods from :: BalanceInsufficientError -> Rep BalanceInsufficientError x # to :: Rep BalanceInsufficientError x -> BalanceInsufficientError # | |||||
Show BalanceInsufficientError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec :: Int -> BalanceInsufficientError -> ShowS # show :: BalanceInsufficientError -> String # showList :: [BalanceInsufficientError] -> ShowS # | |||||
Eq BalanceInsufficientError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods (==) :: BalanceInsufficientError -> BalanceInsufficientError -> Bool # (/=) :: BalanceInsufficientError -> BalanceInsufficientError -> Bool # | |||||
type Rep BalanceInsufficientError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep BalanceInsufficientError = D1 ('MetaData "BalanceInsufficientError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.14.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
| |||||
Show UnableToConstructChangeError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods showsPrec :: Int -> UnableToConstructChangeError -> ShowS # show :: UnableToConstructChangeError -> String # showList :: [UnableToConstructChangeError] -> ShowS # | |||||
Eq UnableToConstructChangeError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance Methods (==) :: UnableToConstructChangeError -> UnableToConstructChangeError -> Bool # (/=) :: UnableToConstructChangeError -> UnableToConstructChangeError -> Bool # | |||||
type Rep UnableToConstructChangeError # | |||||
Defined in GeniusYield.Transaction.CoinSelection.Balance type Rep UnableToConstructChangeError = D1 ('MetaData "UnableToConstructChangeError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.14.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 :: (HasCallStack, MonadRandom m) => PerformSelection m [] #
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 :: forall (f :: Type -> Type). Foldable f => SelectionConstraints -> SelectionResult f -> Bool #
Indicates whether or not a selection result has a valid surplus.
selectionDeltaCoin :: forall (f :: Type -> Type). Foldable f => SelectionResult f -> SelectionDelta Natural #
Calculates the ada selection delta.
See SelectionDelta
.
selectionSurplusCoin :: forall (f :: Type -> Type). 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 #