Skip to content

Commit

Permalink
Merge #2325
Browse files Browse the repository at this point in the history
2325: Expose `calcMinimumDeposit` from cardano-api r=Jimbo4350 a=Jimbo4350

Expose `calcMinimumDeposit` to calculate the creation cost of a UTxO entry given a `Value`


Co-authored-by: Jordan Millar <jordan.millar@iohk.io>
  • Loading branch information
iohk-bors[bot] and Jimbo4350 committed Mar 4, 2021
2 parents 0c52f7d + 308de8f commit f8b616e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions cardano-api/src/Cardano/Api/Shelley.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ module Cardano.Api.Shelley
fromShelleyLovelace,
toMaryValue,
fromMaryValue,
calcMinimumDeposit,

-- * Signing transactions
-- | Creating transaction witnesses one by one, or all in one go.
Expand Down
7 changes: 7 additions & 0 deletions cardano-api/src/Cardano/Api/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Cardano.Api.Value
, valueToList
, filterValue
, negateValue
, calcMinimumDeposit

-- ** Ada \/ Lovelace specifically
, quantityToLovelace
Expand Down Expand Up @@ -66,6 +67,7 @@ import qualified Data.Text.Encoding as Text
import qualified Cardano.Chain.Common as Byron

import qualified Cardano.Ledger.Mary.Value as Mary
import qualified Cardano.Ledger.ShelleyMA.Rules.Utxo as Shelley
import qualified Shelley.Spec.Ledger.Coin as Shelley

import Ouroboros.Consensus.Shelley.Protocol.Crypto (StandardCrypto)
Expand Down Expand Up @@ -283,6 +285,11 @@ fromMaryValue (Mary.Value lovelace other) =
fromMaryAssetName :: Mary.AssetName -> AssetName
fromMaryAssetName (Mary.AssetName n) = AssetName n

-- | Calculate cost of making a UTxO entry for a given 'Value' and
-- mininimum UTxO value derived from the 'ProtocolParameters'
calcMinimumDeposit :: Value -> Lovelace -> Lovelace
calcMinimumDeposit v minUTxo =
fromShelleyLovelace $ Shelley.scaledMinDeposit (toMaryValue v) (toShelleyLovelace minUTxo)

-- ----------------------------------------------------------------------------
-- An alternative nested representation
Expand Down

0 comments on commit f8b616e

Please sign in to comment.