@@ -41,7 +41,6 @@ import Control.Monad.Trans.Except (throwE)
4141import Data.Bifunctor (bimap )
4242import Data.Coerce (coerce )
4343import Data.Kind (Type )
44- import Data.List ((\\) )
4544import Data.List qualified as List
4645import Data.Map (Map )
4746import Data.Map qualified as Map
@@ -152,7 +151,7 @@ balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx =
152151
153152 -- Get current Ada change
154153 let adaChange = getAdaChange utxoIndex balancedTx
155- bTx = fst <$> balanceTxLoop utxoIndex privKeys minUtxos (addOutput changeAddr balancedTx)
154+ bTx = balanceTxLoop utxoIndex privKeys (addOutput changeAddr balancedTx)
156155
157156 -- Checks if there's ada change left, if there is then we check
158157 -- if `bcSeparateChange` is true, if this is the case then we create a new UTxO at
@@ -188,16 +187,9 @@ balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx =
188187 Map TxOutRef TxOut ->
189188 Map PubKeyHash DummyPrivKey ->
190189 Tx ->
191- EitherT Text (Eff effs ) ( Tx , [( TxOut , Integer )])
192- balanceTxLoop utxoIndex privKeys prevMinUtxos tx = do
190+ EitherT Text (Eff effs ) Tx
191+ balanceTxLoop utxoIndex privKeys tx = do
193192 void $ lift $ Files. writeAll @ w pabConf tx
194- nextMinUtxos <-
195- newEitherT $
196- calculateMinUtxos @ w pabConf (Tx. txData tx) $ Tx. txOutputs tx \\ map fst prevMinUtxos
197-
198- let minUtxos = prevMinUtxos ++ nextMinUtxos
199-
200- lift $ printBpiLog @ w (Debug [TxBalancingLog ]) $ " Min utxos:" <+> pretty minUtxos
201193
202194 -- Calculate fees by pre-balancing the tx, building it, and running the CLI on result
203195 txWithoutFees <-
@@ -212,11 +204,11 @@ balanceTxIO' balanceCfg pabConf ownPkh unbalancedTx =
212204 lift $ printBpiLog @ w (Debug [TxBalancingLog ]) $ " Fees:" <+> pretty fees
213205
214206 -- Rebalance the initial tx with the above fees
215- balancedTx <- newEitherT $ balanceTxStep @ w balanceCfg minUtxos utxoIndex changeAddr $ tx `withFee` fees
207+ balancedTx <- newEitherT $ balanceTxStep @ w balanceCfg utxoIndex changeAddr $ tx `withFee` fees
216208
217209 if balancedTx == tx
218- then pure ( balancedTx, minUtxos)
219- else balanceTxLoop utxoIndex privKeys minUtxos balancedTx
210+ then pure balancedTx
211+ else balanceTxLoop utxoIndex privKeys balancedTx
220212
221213-- `utxosAndCollateralAtAddress` returns all the utxos that can be used as an input of a `Tx`,
222214-- i.e. we filter out `CollateralUtxo` present at the user's address, so it can't be used as input of a `Tx`.
@@ -275,14 +267,13 @@ balanceTxStep ::
275267 forall (w :: Type ) (effs :: [Type -> Type ]).
276268 Member (PABEffect w ) effs =>
277269 BalanceConfig ->
278- [(TxOut , Integer )] ->
279270 Map TxOutRef TxOut ->
280271 Address ->
281272 Tx ->
282273 Eff effs (Either Text Tx )
283- balanceTxStep balanceCfg minUtxos utxos changeAddr tx =
274+ balanceTxStep balanceCfg utxos changeAddr tx =
284275 runEitherT $
285- (newEitherT . balanceTxIns @ w utxos) (addLovelaces minUtxos tx)
276+ (newEitherT . balanceTxIns @ w utxos) tx
286277 >>= hoistEither . handleNonAdaChange balanceCfg changeAddr utxos
287278
288279-- | Get change value of a transaction, taking inputs, outputs, mint and fees into account
@@ -305,23 +296,6 @@ getAdaChange utxos = lovelaceValue . getChange utxos
305296getNonAdaChange :: Map TxOutRef TxOut -> Tx -> Value
306297getNonAdaChange utxos = Ledger. noAdaValue . getChange utxos
307298
308- -- | Add min lovelaces to each tx output
309- addLovelaces :: [(TxOut , Integer )] -> Tx -> Tx
310- addLovelaces minLovelaces tx =
311- let lovelacesAdded =
312- map
313- ( \ txOut ->
314- let outValue = txOutValue txOut
315- lovelaces = Ada. getLovelace $ Ada. fromValue outValue
316- minUtxo = fromMaybe 0 $ lookup txOut minLovelaces
317- in txOut
318- { txOutValue =
319- outValue <> Ada. lovelaceValueOf (max 0 (minUtxo - lovelaces))
320- }
321- )
322- $ txOutputs tx
323- in tx {txOutputs = lovelacesAdded}
324-
325299balanceTxIns ::
326300 forall (w :: Type ) (effs :: [Type -> Type ]).
327301 Member (PABEffect w ) effs =>
0 commit comments