@@ -756,10 +756,8 @@ validator manage(settings_policy_id: PolicyId) {
756756 expect InlineDatum (datum) = pool_input.datum
757757 expect datum: PoolDatum = datum
758758 // We need the pool output to check that only the fees or fee manager are updated
759- let (
760- Output { address: pool_output_address, value: pool_output_value, .. },
761- pool_output_datum,
762- ) = find_pool_output (outputs)
759+ let (lovelace_diff, pool_output_datum) =
760+ pool_output_datum (pool_input, outputs)
763761
764762 let PoolDatum {
765763 bid_fees_per_10_thousand,
@@ -775,6 +773,7 @@ validator manage(settings_policy_id: PolicyId) {
775773 let expected_datum =
776774 PoolDatum {
777775 .. datum,
776+ protocol_fees: datum.protocol_fees + lovelace_diff,
778777 bid_fees_per_10_thousand: bid_fees_per_10_thousand,
779778 ask_fees_per_10_thousand: ask_fees_per_10_thousand,
780779 fee_manager: output_fee_manager,
@@ -791,12 +790,32 @@ validator manage(settings_policy_id: PolicyId) {
791790 withdrawals,
792791 )
793792
794- // And make sure we don't touch the assets on the pool input; they must be spent back into the same script
795- and {
796- pool_output_address == pool_input.address,
797- pool_output_value == pool_input.value,
798- }
793+ // The value and address are verified in pool_output_datum
794+ pool_output_datum == expected_datum
799795 }
800796 }
801797 }
802798}
799+
800+ fn pool_output_datum (
801+ pool_input: Output ,
802+ outputs: List < Output > ,
803+ ) -> (Int , PoolDatum ) {
804+ let (
805+ Output { address: pool_output_address, value: pool_output_value, .. },
806+ pool_output_datum,
807+ ) = find_pool_output (outputs)
808+ expect pool_output_address == pool_input.address
809+ expect
810+ assets.without_lovelace (pool_output_value) == assets.without_lovelace (
811+ pool_input.value,
812+ )
813+
814+ // Allow for increased lovelace amount in case the minutxo cost of the output is larger than the input
815+ // it is important to verify this is also added to the protocol fees so that the pool values are not changed
816+ let lovelace_diff =
817+ assets.lovelace_of (pool_output_value) - assets.lovelace_of (pool_input.value)
818+ expect lovelace_diff >= 0
819+
820+ (lovelace_diff, pool_output_datum)
821+ }
0 commit comments