atlas-cardano-0.13.0: Application backend for Plutus smart contracts on Cardano
Copyright(c) 2025 GYELD GMBH
LicenseApache 2.0
Maintainer[email protected]
Stabilitydevelop
Safe HaskellSafe-Inferred
LanguageGHC2021

GeniusYield.Transaction.CoinSelection.Balance

Description

Largely a simplified version of Cardano.CoinSelection.Balance.

Synopsis

Documentation

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

Instances details
Generic ValueSizeAssessment # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Associated Types

type Rep ValueSizeAssessmentTypeType #

Show ValueSizeAssessment # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Eq ValueSizeAssessment # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep ValueSizeAssessment # 
Instance details

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) (U1TypeType) :+: C1 ('MetaCons "ValueSizeExceedsLimit" 'PrefixI 'False) (U1TypeType))

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.

data SelectionConstraints #

Specifies all constraints required for coin selection.

Constructors

SelectionConstraints 

Fields

  • valueSizeAssessorValueSizeAssessor

    Assesses the size of a value relative to the upper limit of what can be included in a transaction output. TODO: Get rid of "bundle" keyword as we "value" (instead of tokenbundle) to denote it...

  • computeMinimumAdaQuantityGYAddressGYValueNatural

    Computes the minimum ada quantity required for a given output.

  • computeMinimumCost ∷ SelectionSkeleton → Natural

    Computes the minimum cost of a given selection skeleton. TODO: This can be cleverly used to not make use of logarithmic overestimation function. To study if it's only for fees or also for min deposits, if min deposit then which one? TODO: Whether I can be precise here also depends upon how many times is this called. Our initial implementation had logarithmic iteration.

  • changeAddressGYAddress
     
  • maximumOutputAdaQuantityNatural

    Specifies the largest ada quantity that can appear in the token bundle of an output.

  • maximumOutputTokenQuantityNatural

    Specifies the largest non-ada quantity that can appear in the token bundle of an output.

  • nullAddressGYAddress
     

data SelectionParams f #

Specifies all parameters that are specific to a given selection.

Constructors

SelectionParams 

Fields

  • outputsToCover ∷ !(f (GYAddress, GYValue))

    The complete set of outputs to be covered. TODO: Shall I be changing it's representation to say GYTxOut v? Or just GYValue?

  • utxoAvailable ∷ !(UTxOSelection UTxO)

    Specifies a set of UTxOs that are available for selection as inputs and optionally, a subset that has already been selected.

    Further entries from this set will be selected to cover any deficit.

  • extraCoinSource ∷ !Natural

    An extra source of ada.

  • extraCoinSink ∷ !Natural

    An extra sink for ada.

  • assetsToMint ∷ !GYValue

    Assets to mint: these provide input value to a transaction.

    By minting tokens, we generally decrease the burden of the selection algorithm, allowing it to select fewer UTxO entries in order to cover the required outputs.

  • assetsToBurn ∷ !GYValue

    Assets to burn: these consume output value from a transaction.

    By burning tokens, we generally increase the burden of the selection algorithm, requiring it to select more UTxO entries in order to cover the burn.

    Note that it contains positive entries only.

  • selectionStrategySelectionStrategy

    Specifies which selection strategy to use. See SelectionStrategy.

Instances

Instances details
Generic (SelectionParams f) # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Associated Types

type Rep (SelectionParams f) ∷ TypeType #

type Rep (SelectionParams f) # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep (SelectionParams f) = D1 ('MetaData "SelectionParams" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.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 #

The result of performing a successful selection.

Constructors

SelectionResult 

Fields

Instances

Instances details
Generic (SelectionResult f) # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Associated Types

type Rep (SelectionResult f) ∷ TypeType #

type Rep (SelectionResult f) # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep (SelectionResult f) = D1 ('MetaData "SelectionResult" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.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.

Instances

Instances details
Generic SelectionBalanceError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Associated Types

type Rep SelectionBalanceErrorTypeType #

Show SelectionBalanceError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Eq SelectionBalanceError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep SelectionBalanceError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep SelectionBalanceError = D1 ('MetaData "SelectionBalanceError" "GeniusYield.Transaction.CoinSelection.Balance" "atlas-cardano-0.13.0-inplace" 'False) (C1 ('MetaCons "BalanceInsufficient" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 BalanceInsufficientError)) :+: (C1 ('MetaCons "UnableToConstructChange" 'PrefixI 'False) (S1 ('MetaSel ('NothingMaybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 UnableToConstructChangeError)) :+: C1 ('MetaCons "EmptyUTxO" 'PrefixI 'False) (U1TypeType)))

data BalanceInsufficientError #

Indicates that the balance of available UTxO entries is insufficient to cover the balance required.

See computeUTxOBalanceSufficiency.

Instances

Instances details
Generic BalanceInsufficientError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Associated Types

type Rep BalanceInsufficientErrorTypeType #

Show BalanceInsufficientError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

Eq BalanceInsufficientError # 
Instance details

Defined in GeniusYield.Transaction.CoinSelection.Balance

type Rep BalanceInsufficientError # 
Instance details

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

  • requiredCost ∷ !Natural

    The minimal required cost needed for the transaction to be considered valid. This does not include min Ada values.

  • shortfall ∷ !Natural

    The additional coin quantity that would be required to cover the selection cost and minimum coin quantity of each change output.

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.

selectionHasValidSurplusFoldable f ⇒ SelectionConstraintsSelectionResult f → Bool #

Indicates whether or not a selection result has a valid surplus.

selectionDeltaCoinFoldable f ⇒ SelectionResult f → SelectionDelta Natural #

Calculates the ada selection delta.

See SelectionDelta.

selectionSurplusCoinFoldable 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 #