module Cooked.Skeleton.Option
  ( BalanceOutputPolicy (..),
    FeePolicy (..),
    BalancingPolicy (..),
    BalancingUtxos (..),
    RawModTx (..),
    EmulatorParamsModification (..),
    CollateralUtxos (..),
    AnchorResolution (..),
    applyEmulatorParamsModification,
    applyRawModOnBalancedTx,
    TxOpts (..),
    txOptUnsafeModTxL,
    txOptAutoSlotIncreaseL,
    txOptBalancingPolicyL,
    txOptBalanceOutputPolicyL,
    txOptFeePolicyL,
    txOptBalancingUtxosL,
    txOptEmulatorParamsModificationL,
    txOptCollateralUtxosL,
    txOptAnchorResolutionL,
    txOptAutoReferenceScriptsL,
  )
where

import Cardano.Api qualified as Cardano
import Cardano.Node.Emulator qualified as Emulator
import Cooked.Wallet
import Data.ByteString (ByteString)
import Data.Default
import Data.List (foldl')
import Data.Map (Map)
import Data.Map qualified as Map
import Data.Set (Set)
import Optics.TH
import PlutusLedgerApi.V3 qualified as Api

-- | What fee policy to use in the transaction.
data FeePolicy
  = -- | Use automatic fee computation. If balancing is activated, an optimal
    -- fee will be computed based on the transaction and existing utxos in the
    -- balancing wallet. Otherwise, the maximum transaction fee will be applied.
    AutoFeeComputation
  | -- | Provide a fee to the transaction. If the autobalancing is activated, it
    -- will be attempted around this fee, which might lead to failure if it is
    -- too low, otherwise, this fee will be given to transaction generation.
    ManualFee Integer
  deriving (FeePolicy -> FeePolicy -> Bool
(FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool) -> Eq FeePolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: FeePolicy -> FeePolicy -> Bool
== :: FeePolicy -> FeePolicy -> Bool
$c/= :: FeePolicy -> FeePolicy -> Bool
/= :: FeePolicy -> FeePolicy -> Bool
Eq, Eq FeePolicy
Eq FeePolicy =>
(FeePolicy -> FeePolicy -> Ordering)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> Bool)
-> (FeePolicy -> FeePolicy -> FeePolicy)
-> (FeePolicy -> FeePolicy -> FeePolicy)
-> Ord FeePolicy
FeePolicy -> FeePolicy -> Bool
FeePolicy -> FeePolicy -> Ordering
FeePolicy -> FeePolicy -> FeePolicy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: FeePolicy -> FeePolicy -> Ordering
compare :: FeePolicy -> FeePolicy -> Ordering
$c< :: FeePolicy -> FeePolicy -> Bool
< :: FeePolicy -> FeePolicy -> Bool
$c<= :: FeePolicy -> FeePolicy -> Bool
<= :: FeePolicy -> FeePolicy -> Bool
$c> :: FeePolicy -> FeePolicy -> Bool
> :: FeePolicy -> FeePolicy -> Bool
$c>= :: FeePolicy -> FeePolicy -> Bool
>= :: FeePolicy -> FeePolicy -> Bool
$cmax :: FeePolicy -> FeePolicy -> FeePolicy
max :: FeePolicy -> FeePolicy -> FeePolicy
$cmin :: FeePolicy -> FeePolicy -> FeePolicy
min :: FeePolicy -> FeePolicy -> FeePolicy
Ord, Int -> FeePolicy -> ShowS
[FeePolicy] -> ShowS
FeePolicy -> String
(Int -> FeePolicy -> ShowS)
-> (FeePolicy -> String)
-> ([FeePolicy] -> ShowS)
-> Show FeePolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FeePolicy -> ShowS
showsPrec :: Int -> FeePolicy -> ShowS
$cshow :: FeePolicy -> String
show :: FeePolicy -> String
$cshowList :: [FeePolicy] -> ShowS
showList :: [FeePolicy] -> ShowS
Show)

instance Default FeePolicy where
  def :: FeePolicy
def = FeePolicy
AutoFeeComputation

-- | Whether to adjust a potentially existing output to the balancing wallet
-- with the change during transaction balancing.
data BalanceOutputPolicy
  = -- | Try to adjust an existing public key output with the change. If no
    -- suitable output can be found, create a new change output.
    AdjustExistingOutput
  | -- | Do not change the existing outputs, always create a new change output.
    DontAdjustExistingOutput
  deriving (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
(BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> Eq BalanceOutputPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
== :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c/= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
/= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
Eq, Eq BalanceOutputPolicy
Eq BalanceOutputPolicy =>
(BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy -> BalanceOutputPolicy -> Bool)
-> (BalanceOutputPolicy
    -> BalanceOutputPolicy -> BalanceOutputPolicy)
-> (BalanceOutputPolicy
    -> BalanceOutputPolicy -> BalanceOutputPolicy)
-> Ord BalanceOutputPolicy
BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
compare :: BalanceOutputPolicy -> BalanceOutputPolicy -> Ordering
$c< :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
< :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c<= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
<= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c> :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
> :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$c>= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
>= :: BalanceOutputPolicy -> BalanceOutputPolicy -> Bool
$cmax :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
max :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
$cmin :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
min :: BalanceOutputPolicy -> BalanceOutputPolicy -> BalanceOutputPolicy
Ord, Int -> BalanceOutputPolicy -> ShowS
[BalanceOutputPolicy] -> ShowS
BalanceOutputPolicy -> String
(Int -> BalanceOutputPolicy -> ShowS)
-> (BalanceOutputPolicy -> String)
-> ([BalanceOutputPolicy] -> ShowS)
-> Show BalanceOutputPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalanceOutputPolicy -> ShowS
showsPrec :: Int -> BalanceOutputPolicy -> ShowS
$cshow :: BalanceOutputPolicy -> String
show :: BalanceOutputPolicy -> String
$cshowList :: [BalanceOutputPolicy] -> ShowS
showList :: [BalanceOutputPolicy] -> ShowS
Show)

instance Default BalanceOutputPolicy where
  def :: BalanceOutputPolicy
def = BalanceOutputPolicy
AdjustExistingOutput

-- | Which UTxOs to use when balancing. Note that utxos that are already known
-- by the skeleton being balanced (in the sense of `txSkelKnownTxOutRefs`,
-- i.e. inputs and reference inputs) will be filtered out during balancing.
data BalancingUtxos
  = -- | Use all UTxOs containing only a Value (no datum, no staking credential,
    -- and no reference script) belonging to the balancing wallet.
    BalancingUtxosFromBalancingWallet
  | -- | Use the provided UTxOs. UTxOs belonging to scripts will be filtered out
    BalancingUtxosFromSet (Set Api.TxOutRef)
  deriving (BalancingUtxos -> BalancingUtxos -> Bool
(BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool) -> Eq BalancingUtxos
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalancingUtxos -> BalancingUtxos -> Bool
== :: BalancingUtxos -> BalancingUtxos -> Bool
$c/= :: BalancingUtxos -> BalancingUtxos -> Bool
/= :: BalancingUtxos -> BalancingUtxos -> Bool
Eq, Eq BalancingUtxos
Eq BalancingUtxos =>
(BalancingUtxos -> BalancingUtxos -> Ordering)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> Bool)
-> (BalancingUtxos -> BalancingUtxos -> BalancingUtxos)
-> (BalancingUtxos -> BalancingUtxos -> BalancingUtxos)
-> Ord BalancingUtxos
BalancingUtxos -> BalancingUtxos -> Bool
BalancingUtxos -> BalancingUtxos -> Ordering
BalancingUtxos -> BalancingUtxos -> BalancingUtxos
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BalancingUtxos -> BalancingUtxos -> Ordering
compare :: BalancingUtxos -> BalancingUtxos -> Ordering
$c< :: BalancingUtxos -> BalancingUtxos -> Bool
< :: BalancingUtxos -> BalancingUtxos -> Bool
$c<= :: BalancingUtxos -> BalancingUtxos -> Bool
<= :: BalancingUtxos -> BalancingUtxos -> Bool
$c> :: BalancingUtxos -> BalancingUtxos -> Bool
> :: BalancingUtxos -> BalancingUtxos -> Bool
$c>= :: BalancingUtxos -> BalancingUtxos -> Bool
>= :: BalancingUtxos -> BalancingUtxos -> Bool
$cmax :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
max :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
$cmin :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
min :: BalancingUtxos -> BalancingUtxos -> BalancingUtxos
Ord, Int -> BalancingUtxos -> ShowS
[BalancingUtxos] -> ShowS
BalancingUtxos -> String
(Int -> BalancingUtxos -> ShowS)
-> (BalancingUtxos -> String)
-> ([BalancingUtxos] -> ShowS)
-> Show BalancingUtxos
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalancingUtxos -> ShowS
showsPrec :: Int -> BalancingUtxos -> ShowS
$cshow :: BalancingUtxos -> String
show :: BalancingUtxos -> String
$cshowList :: [BalancingUtxos] -> ShowS
showList :: [BalancingUtxos] -> ShowS
Show)

instance Default BalancingUtxos where
  def :: BalancingUtxos
def = BalancingUtxos
BalancingUtxosFromBalancingWallet

-- | Whether to balance the transaction or not, and which wallet to use to
-- provide outputs for balancing.
data BalancingPolicy
  = -- | Balance with the first signer of the list of signers
    BalanceWithFirstSigner
  | -- | Balance using a given wallet
    BalanceWith Wallet
  | -- | Do not perform balancing at all
    DoNotBalance
  deriving (BalancingPolicy -> BalancingPolicy -> Bool
(BalancingPolicy -> BalancingPolicy -> Bool)
-> (BalancingPolicy -> BalancingPolicy -> Bool)
-> Eq BalancingPolicy
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalancingPolicy -> BalancingPolicy -> Bool
== :: BalancingPolicy -> BalancingPolicy -> Bool
$c/= :: BalancingPolicy -> BalancingPolicy -> Bool
/= :: BalancingPolicy -> BalancingPolicy -> Bool
Eq, Eq BalancingPolicy
Eq BalancingPolicy =>
(BalancingPolicy -> BalancingPolicy -> Ordering)
-> (BalancingPolicy -> BalancingPolicy -> Bool)
-> (BalancingPolicy -> BalancingPolicy -> Bool)
-> (BalancingPolicy -> BalancingPolicy -> Bool)
-> (BalancingPolicy -> BalancingPolicy -> Bool)
-> (BalancingPolicy -> BalancingPolicy -> BalancingPolicy)
-> (BalancingPolicy -> BalancingPolicy -> BalancingPolicy)
-> Ord BalancingPolicy
BalancingPolicy -> BalancingPolicy -> Bool
BalancingPolicy -> BalancingPolicy -> Ordering
BalancingPolicy -> BalancingPolicy -> BalancingPolicy
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BalancingPolicy -> BalancingPolicy -> Ordering
compare :: BalancingPolicy -> BalancingPolicy -> Ordering
$c< :: BalancingPolicy -> BalancingPolicy -> Bool
< :: BalancingPolicy -> BalancingPolicy -> Bool
$c<= :: BalancingPolicy -> BalancingPolicy -> Bool
<= :: BalancingPolicy -> BalancingPolicy -> Bool
$c> :: BalancingPolicy -> BalancingPolicy -> Bool
> :: BalancingPolicy -> BalancingPolicy -> Bool
$c>= :: BalancingPolicy -> BalancingPolicy -> Bool
>= :: BalancingPolicy -> BalancingPolicy -> Bool
$cmax :: BalancingPolicy -> BalancingPolicy -> BalancingPolicy
max :: BalancingPolicy -> BalancingPolicy -> BalancingPolicy
$cmin :: BalancingPolicy -> BalancingPolicy -> BalancingPolicy
min :: BalancingPolicy -> BalancingPolicy -> BalancingPolicy
Ord, Int -> BalancingPolicy -> ShowS
[BalancingPolicy] -> ShowS
BalancingPolicy -> String
(Int -> BalancingPolicy -> ShowS)
-> (BalancingPolicy -> String)
-> ([BalancingPolicy] -> ShowS)
-> Show BalancingPolicy
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalancingPolicy -> ShowS
showsPrec :: Int -> BalancingPolicy -> ShowS
$cshow :: BalancingPolicy -> String
show :: BalancingPolicy -> String
$cshowList :: [BalancingPolicy] -> ShowS
showList :: [BalancingPolicy] -> ShowS
Show)

instance Default BalancingPolicy where
  def :: BalancingPolicy
def = BalancingPolicy
BalanceWithFirstSigner

-- | Wraps a function that will be applied to a Cardano transaction after it has
-- been generated from this skeleton (and thus, after balancing has been
-- performed since it operates on skeletons).
newtype RawModTx
  = RawModTx (Cardano.Tx Cardano.ConwayEra -> Cardano.Tx Cardano.ConwayEra)

-- This instance always returns @False@, which is no problem, because 'Eq
-- TxSkel' is only used for tests that never depend on this comparison
instance Eq RawModTx where
  RawModTx
_ == :: RawModTx -> RawModTx -> Bool
== RawModTx
_ = Bool
False

instance Show RawModTx where
  show :: RawModTx -> String
show (RawModTx Tx ConwayEra -> Tx ConwayEra
_) = String
"RawModTxAfterBalancing"

-- | Applies a list of modifications right before the transaction is
-- submitted. The leftmost function in the argument list is applied first.
applyRawModOnBalancedTx :: [RawModTx] -> Cardano.Tx Cardano.ConwayEra -> Cardano.Tx Cardano.ConwayEra
applyRawModOnBalancedTx :: [RawModTx] -> Tx ConwayEra -> Tx ConwayEra
applyRawModOnBalancedTx = ((Tx ConwayEra -> Tx ConwayEra)
 -> RawModTx -> Tx ConwayEra -> Tx ConwayEra)
-> (Tx ConwayEra -> Tx ConwayEra)
-> [RawModTx]
-> Tx ConwayEra
-> Tx ConwayEra
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Tx ConwayEra -> Tx ConwayEra
acc (RawModTx Tx ConwayEra -> Tx ConwayEra
f) -> Tx ConwayEra -> Tx ConwayEra
acc (Tx ConwayEra -> Tx ConwayEra)
-> (Tx ConwayEra -> Tx ConwayEra) -> Tx ConwayEra -> Tx ConwayEra
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Tx ConwayEra -> Tx ConwayEra
f) Tx ConwayEra -> Tx ConwayEra
forall a. a -> a
id

-- | Wraps a function that will temporarily change the emulator parameters for
-- the transaction's balancing and submission.
newtype EmulatorParamsModification = EmulatorParamsModification (Emulator.Params -> Emulator.Params)

-- This instance always returns @False@, which is no problem, because 'Eq
-- TxSkel' is only used for tests that never depend on this comparison
instance Eq EmulatorParamsModification where
  EmulatorParamsModification
_ == :: EmulatorParamsModification -> EmulatorParamsModification -> Bool
== EmulatorParamsModification
_ = Bool
False

instance Show EmulatorParamsModification where
  show :: EmulatorParamsModification -> String
show EmulatorParamsModification {} = String
"EmulatorParamsModification <function>"

applyEmulatorParamsModification :: Maybe EmulatorParamsModification -> Emulator.Params -> Emulator.Params
applyEmulatorParamsModification :: Maybe EmulatorParamsModification -> Params -> Params
applyEmulatorParamsModification (Just (EmulatorParamsModification Params -> Params
f)) = Params -> Params
f
applyEmulatorParamsModification Maybe EmulatorParamsModification
Nothing = Params -> Params
forall a. a -> a
id

-- | Describe which UTxOs to use as collaterals
data CollateralUtxos
  = -- | Rely on automated computation with only-value UTxOs from the balancing
    -- wallet. Return collaterals will be sent to this wallet.
    CollateralUtxosFromBalancingWallet
  | -- | Rely on automated computation with only-value UTxOs from a given
    -- wallet. Return collaterals will be sent to this wallet.
    CollateralUtxosFromWallet Wallet
  | -- | Manually provide a set of candidate UTxOs to be used as collaterals
    -- alongside a wallet to send return collaterals back to.
    CollateralUtxosFromSet (Set Api.TxOutRef) Wallet
  deriving (CollateralUtxos -> CollateralUtxos -> Bool
(CollateralUtxos -> CollateralUtxos -> Bool)
-> (CollateralUtxos -> CollateralUtxos -> Bool)
-> Eq CollateralUtxos
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: CollateralUtxos -> CollateralUtxos -> Bool
== :: CollateralUtxos -> CollateralUtxos -> Bool
$c/= :: CollateralUtxos -> CollateralUtxos -> Bool
/= :: CollateralUtxos -> CollateralUtxos -> Bool
Eq, Int -> CollateralUtxos -> ShowS
[CollateralUtxos] -> ShowS
CollateralUtxos -> String
(Int -> CollateralUtxos -> ShowS)
-> (CollateralUtxos -> String)
-> ([CollateralUtxos] -> ShowS)
-> Show CollateralUtxos
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> CollateralUtxos -> ShowS
showsPrec :: Int -> CollateralUtxos -> ShowS
$cshow :: CollateralUtxos -> String
show :: CollateralUtxos -> String
$cshowList :: [CollateralUtxos] -> ShowS
showList :: [CollateralUtxos] -> ShowS
Show)

instance Default CollateralUtxos where
  def :: CollateralUtxos
def = CollateralUtxos
CollateralUtxosFromBalancingWallet

-- | Describes how to resolve anchors in proposal procedures
data AnchorResolution
  = -- | Provide a map between urls and page content as Bytestring
    AnchorResolutionLocal (Map String ByteString)
  | -- | Allow online fetch of pages from a given URL. Important note: using
    -- this option is unsafe, as it requires a web connection and inherently
    -- prevents guarantees of reproducibily. Use at your own discretion.
    AnchorResolutionHttp
  deriving (AnchorResolution -> AnchorResolution -> Bool
(AnchorResolution -> AnchorResolution -> Bool)
-> (AnchorResolution -> AnchorResolution -> Bool)
-> Eq AnchorResolution
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AnchorResolution -> AnchorResolution -> Bool
== :: AnchorResolution -> AnchorResolution -> Bool
$c/= :: AnchorResolution -> AnchorResolution -> Bool
/= :: AnchorResolution -> AnchorResolution -> Bool
Eq, Int -> AnchorResolution -> ShowS
[AnchorResolution] -> ShowS
AnchorResolution -> String
(Int -> AnchorResolution -> ShowS)
-> (AnchorResolution -> String)
-> ([AnchorResolution] -> ShowS)
-> Show AnchorResolution
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AnchorResolution -> ShowS
showsPrec :: Int -> AnchorResolution -> ShowS
$cshow :: AnchorResolution -> String
show :: AnchorResolution -> String
$cshowList :: [AnchorResolution] -> ShowS
showList :: [AnchorResolution] -> ShowS
Show)

instance Default AnchorResolution where
  def :: AnchorResolution
def = Map String ByteString -> AnchorResolution
AnchorResolutionLocal Map String ByteString
forall k a. Map k a
Map.empty

-- | Set of options to modify the behavior of generating and validating some
-- transaction.
data TxOpts = TxOpts
  { -- | Whether to increase the slot counter automatically on transaction
    -- submission.  This is useful for modelling transactions that could be
    -- submitted in parallel in reality, so there should be no explicit ordering
    -- of what comes first.
    --
    -- Default is @True@.
    TxOpts -> Bool
txOptAutoSlotIncrease :: Bool,
    -- | Applies an arbitrary modification to a transaction after it has been
    -- potentially adjusted ('txOptEnsureMinAda') and balanced. The name of this
    -- option contains /unsafe/ to draw attention to the fact that modifying a
    -- transaction at that stage might make it invalid. Still, this offers a
    -- hook for being able to alter a transaction in unforeseen ways. It is
    -- mostly used to test contracts that have been written for custom PABs.
    --
    -- One interesting use of this function is to observe a transaction just
    -- before it is being sent for validation, with
    --
    -- > txOptUnsafeModTx = [RawModTxAfterBalancing Debug.Trace.traceShowId]
    --
    -- The leftmost function in the list is applied first.
    --
    -- Default is @[]@.
    TxOpts -> [RawModTx]
txOptUnsafeModTx :: [RawModTx],
    -- | Whether to balance the transaction or not, and which wallet should
    -- provide/reclaim the missing and surplus value. Balancing ensures that
    --
    -- > input + mints == output + fees + burns
    --
    -- If you decide to set @txOptBalance = DoNotBalance@ you will have trouble
    -- satisfying that equation by hand unless you use @ManualFee@. You will
    -- likely see a error about value preservation.
    --
    -- Default is 'BalanceWithFirstSigner'
    TxOpts -> BalancingPolicy
txOptBalancingPolicy :: BalancingPolicy,
    -- | The fee to use when balancing the transaction
    --
    -- Default is 'AutomaticFeeComputation'
    TxOpts -> FeePolicy
txOptFeePolicy :: FeePolicy,
    -- | The 'BalanceOutputPolicy' to apply when balancing the transaction.
    --
    -- Default is 'AdjustExistingOutput'.
    TxOpts -> BalanceOutputPolicy
txOptBalanceOutputPolicy :: BalanceOutputPolicy,
    -- | Which UTxOs to use during balancing. This can either be a precise list,
    -- or rely on automatic searches for utxos with values only belonging to the
    -- balancing wallet.
    --
    -- Default is 'BalancingUtxosFromBalancingWallet'.
    TxOpts -> BalancingUtxos
txOptBalancingUtxos :: BalancingUtxos,
    -- | Apply an arbitrary modification to the protocol parameters that are
    -- used to balance and submit the transaction. This is obviously a very
    -- unsafe thing to do if you want to preserve compatibility with the actual
    -- chain. It is useful mainly for testing purposes, when you might want to
    -- use extremely big transactions or transactions that exhaust the maximum
    -- execution budget. Such a thing could be accomplished with
    --
    -- > txOptEmulatorParamsModification = Just $ EmulatorParamsModification increaseTransactionLimits
    --
    -- for example.
    --
    -- Default is 'Nothing'.
    TxOpts -> Maybe EmulatorParamsModification
txOptEmulatorParamsModification :: Maybe EmulatorParamsModification,
    -- | Which utxos to use as collaterals. They can be given manually, or
    -- computed automatically from a given, or the balancing, wallet.
    --
    -- Default is 'CollateralUtxosFromBalancingWallet'
    TxOpts -> CollateralUtxos
txOptCollateralUtxos :: CollateralUtxos,
    -- | How to resolve anchor in proposal procedures
    --
    -- Default is 'AnchorResolutionLocal Map.Empty'
    TxOpts -> AnchorResolution
txOptAnchorResolution :: AnchorResolution,
    -- | Whether to automatically fill up reference inputs in redeemers when
    -- they contain the right reference script. This will imply going through
    -- all the known utxos with reference scripts and compare their hashes, thus
    -- will slightly reduce performance.
    --
    -- Defaut is 'False'.
    TxOpts -> Bool
txOptAutoReferenceScripts :: Bool
  }
  deriving (TxOpts -> TxOpts -> Bool
(TxOpts -> TxOpts -> Bool)
-> (TxOpts -> TxOpts -> Bool) -> Eq TxOpts
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TxOpts -> TxOpts -> Bool
== :: TxOpts -> TxOpts -> Bool
$c/= :: TxOpts -> TxOpts -> Bool
/= :: TxOpts -> TxOpts -> Bool
Eq, Int -> TxOpts -> ShowS
[TxOpts] -> ShowS
TxOpts -> String
(Int -> TxOpts -> ShowS)
-> (TxOpts -> String) -> ([TxOpts] -> ShowS) -> Show TxOpts
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TxOpts -> ShowS
showsPrec :: Int -> TxOpts -> ShowS
$cshow :: TxOpts -> String
show :: TxOpts -> String
$cshowList :: [TxOpts] -> ShowS
showList :: [TxOpts] -> ShowS
Show)

makeLensesFor
  [ ("txOptAutoSlotIncrease", "txOptAutoSlotIncreaseL"),
    ("txOptUnsafeModTx", "txOptUnsafeModTxL"),
    ("txOptBalancingPolicy", "txOptBalancingPolicyL"),
    ("txOptFeePolicy", "txOptFeePolicyL"),
    ("txOptBalanceOutputPolicy", "txOptBalanceOutputPolicyL"),
    ("txOptBalancingUtxos", "txOptBalancingUtxosL"),
    ("txOptEmulatorParamsModification", "txOptEmulatorParamsModificationL"),
    ("txOptCollateralUtxos", "txOptCollateralUtxosL"),
    ("txOptAnchorResolution", "txOptAnchorResolutionL"),
    ("txOptAutoReferenceScripts", "txOptAutoReferenceScriptsL")
  ]
  ''TxOpts

instance Default TxOpts where
  def :: TxOpts
def =
    TxOpts
      { txOptAutoSlotIncrease :: Bool
txOptAutoSlotIncrease = Bool
True,
        txOptUnsafeModTx :: [RawModTx]
txOptUnsafeModTx = [],
        txOptBalancingPolicy :: BalancingPolicy
txOptBalancingPolicy = BalancingPolicy
forall a. Default a => a
def,
        txOptBalanceOutputPolicy :: BalanceOutputPolicy
txOptBalanceOutputPolicy = BalanceOutputPolicy
forall a. Default a => a
def,
        txOptFeePolicy :: FeePolicy
txOptFeePolicy = FeePolicy
forall a. Default a => a
def,
        txOptBalancingUtxos :: BalancingUtxos
txOptBalancingUtxos = BalancingUtxos
forall a. Default a => a
def,
        txOptEmulatorParamsModification :: Maybe EmulatorParamsModification
txOptEmulatorParamsModification = Maybe EmulatorParamsModification
forall a. Maybe a
Nothing,
        txOptCollateralUtxos :: CollateralUtxos
txOptCollateralUtxos = CollateralUtxos
forall a. Default a => a
def,
        txOptAnchorResolution :: AnchorResolution
txOptAnchorResolution = AnchorResolution
forall a. Default a => a
def,
        txOptAutoReferenceScripts :: Bool
txOptAutoReferenceScripts = Bool
False
      }