@@ -24,7 +24,10 @@ use types/pool.{
2424 MintLP , PoolMintRedeemer , PoolRedeemer , PoolScoop , StablePoolDatum ,
2525 UpdatePoolFees , WithdrawFees ,
2626} as types_pool
27- use types/ settings.{SettingsDatum , find_settings_datum}
27+ use types/ settings.{
28+ ProtocolFeeBasisPointsExtension , SettingsDatum , find_protocol_fee_extension,
29+ find_settings_datum,
30+ }
2831
2932/// An implementation of a curve-like "Stableswap" invariant that enables more efficient trades for stablecoin pairs.
3033///
@@ -461,9 +464,9 @@ validator pool(
461464 reserve_a
462465 }
463466
464- // We follow Curve's model for initial liquidity, by setting it to the initial sum invariant
467+ // We follow Curve's model for initial liquidity, by setting it to the initial sum invariant, but divide by precision to avoid very large numbers potentially causing overflow
465468 expect
466- pool_output_datum.sum_invariant == pool_output_datum.circulating_lp
469+ pool_output_datum.sum_invariant / calc_precision == pool_output_datum.circulating_lp
467470
468471 // And check that we mint the correct tokens, and nothing else.
469472 let expected_mint =
@@ -518,6 +521,9 @@ validator pool(
518521 // and potentially even on access UIs for the Sundae protocol
519522 expect metadata_output.datum == InlineDatum (Void )
520523
524+ expect Some (protocol_fee_extension) =
525+ find_protocol_fee_extension (settings_datum)
526+
521527 // And check that the datum is initialized correctly; This is part of why we have a minting policy handling this,
522528 // as it allows us to authenticate the providence of the datum.
523529 // A datum is valid so long as
@@ -541,6 +547,7 @@ validator pool(
541547 shared.fees_in_legal_range (
542548 pool_output_datum.protocol_fee_basis_points.2nd,
543549 ),
550+ protocol_fee_extension.protocol_fee_basis_points == pool_output_datum.protocol_fee_basis_points,
544551 pool_output_datum.linear_amplification > 0 ,
545552 liquidity_invariant (
546553 reserve_a * calc_precision,
@@ -901,7 +908,8 @@ validator manage(settings_policy_id: PolicyId) {
901908 pool_output_address.payment_credential == Script (pool_script_hash)
902909
903910 // As part of withdrawing, we should decrease the protocol fees by the amount we're withdrawing
904- // but, importantly, *nothing else*; so we construct a datum with everything from the initial datum, plus the protofol fees updated
911+ // but, the treasury admin is also allowed to update the protocol fees basis points, but nothing else in the datum
912+ // is allowed to be changed.
905913 let expected_datum =
906914 StablePoolDatum {
907915 .. datum,
@@ -910,6 +918,7 @@ validator manage(settings_policy_id: PolicyId) {
910918 initial_fee_a - amount.2nd,
911919 initial_fee_b - amount.3rd,
912920 ),
921+ protocol_fee_basis_points: output_datum.protocol_fee_basis_points,
913922 }
914923 expect output_datum == expected_datum
915924
@@ -957,17 +966,13 @@ validator manage(settings_policy_id: PolicyId) {
957966
958967 let StablePoolDatum {
959968 lp_fee_basis_points,
960- protocol_fee_basis_points,
961- protocol_fees,
962969 fee_manager: output_fee_manager,
963970 ..
964971 } = pool_output_datum
965972
966973 // Make sure we don't update the fees to negative or above 100%
967974 expect shared.fees_in_legal_range (lp_fee_basis_points.1st)
968975 expect shared.fees_in_legal_range (lp_fee_basis_points.2nd)
969- expect shared.fees_in_legal_range (protocol_fee_basis_points.1st)
970- expect shared.fees_in_legal_range (protocol_fee_basis_points.2nd)
971976
972977 // Check that the *current* fee manager approves the update
973978 expect Some (fee_manager) = datum.fee_manager
@@ -983,12 +988,11 @@ validator manage(settings_policy_id: PolicyId) {
983988 StablePoolDatum {
984989 .. datum,
985990 protocol_fees: (
986- protocol_fees.1st + lovelace_diff,
987- protocol_fees.2nd,
988- protocol_fees.3rd,
991+ datum. protocol_fees.1st + lovelace_diff,
992+ datum. protocol_fees.2nd,
993+ datum. protocol_fees.3rd,
989994 ),
990995 lp_fee_basis_points: lp_fee_basis_points,
991- protocol_fee_basis_points: protocol_fee_basis_points,
992996 fee_manager: output_fee_manager,
993997 }
994998 pool_output_datum == expected_datum
@@ -1010,7 +1014,6 @@ validator manage(settings_policy_id: PolicyId) {
10101014 // We need the pool output to check that only the fees or fee manager are updated
10111015 let StablePoolDatum {
10121016 assets,
1013- protocol_fees,
10141017 linear_amplification,
10151018 sum_invariant,
10161019 linear_amplification_manager: output_linear_amplification_manager,
@@ -1020,7 +1023,7 @@ validator manage(settings_policy_id: PolicyId) {
10201023 let
10211024 pool_quantity_a,
10221025 pool_quantity_b,
1023- <- pool_input_to_asset_reserves (assets, protocol_fees, pool_input)
1026+ <- pool_input_to_asset_reserves (assets, datum. protocol_fees, pool_input)
10241027
10251028 expect
10261029 liquidity_invariant (
@@ -1048,9 +1051,9 @@ validator manage(settings_policy_id: PolicyId) {
10481051 StablePoolDatum {
10491052 .. datum,
10501053 protocol_fees: (
1051- protocol_fees.1st + lovelace_diff,
1052- protocol_fees.2nd,
1053- protocol_fees.3rd,
1054+ datum. protocol_fees.1st + lovelace_diff,
1055+ datum. protocol_fees.2nd,
1056+ datum. protocol_fees.3rd,
10541057 ),
10551058 linear_amplification: linear_amplification,
10561059 sum_invariant: sum_invariant,
0 commit comments