Skip to content

Commit a890bde

Browse files
Merge pull request #75 from SundaeSwap-finance/rrruko/ssw-205-validate-pool-fees-range
Resolve SSW-205 (validate pool fees range)
2 parents e84cfdf + cd22571 commit a890bde

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

lib/shared.ak

+9
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,12 @@ test count_orders_test() {
271271
pub fn oracle_sft_name() {
272272
"oracle"
273273
}
274+
275+
pub fn fees_in_legal_range(fees: (Int, Int)) {
276+
and {
277+
fees.1st >= 0,
278+
fees.2nd >= 0,
279+
fees.1st <= 10000,
280+
fees.2nd <= 10000,
281+
}
282+
}

plutus.json

+4-4
Large diffs are not rendered by default.

validators/pool.ak

+5-8
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ validator(settings_policy_id: PolicyId) {
331331
..
332332
} = pool_output_datum
333333

334+
expect shared.fees_in_legal_range(bid_fees_per_10_thousand)
335+
expect shared.fees_in_legal_range(ask_fees_per_10_thousand)
336+
334337
let expected_datum = PoolDatum {
335338
..datum,
336339
bid_fees_per_10_thousand,
@@ -496,14 +499,8 @@ validator(settings_policy_id: PolicyId) {
496499
pool_output_datum.assets == (asset_a, asset_b),
497500
pool_output_datum.circulating_lp == initial_lq,
498501
pool_output_datum.market_open <= pool_output_datum.fee_finalized,
499-
pool_output_datum.bid_fees_per_10_thousand.1st >= 0,
500-
pool_output_datum.bid_fees_per_10_thousand.2nd >= 0,
501-
pool_output_datum.bid_fees_per_10_thousand.1st <= 10000,
502-
pool_output_datum.bid_fees_per_10_thousand.2nd <= 10000,
503-
pool_output_datum.ask_fees_per_10_thousand.1st >= 0,
504-
pool_output_datum.ask_fees_per_10_thousand.2nd >= 0,
505-
pool_output_datum.ask_fees_per_10_thousand.1st <= 10000,
506-
pool_output_datum.ask_fees_per_10_thousand.2nd <= 10000,
502+
shared.fees_in_legal_range(pool_output_datum.bid_fees_per_10_thousand),
503+
shared.fees_in_legal_range(pool_output_datum.ask_fees_per_10_thousand),
507504
}
508505

509506
// Make sure that the pool output is paid into own_policy_id (the pool script, remember this is a multivalidator)

validators/tests/pool.ak

+14-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ScoopTestOptions {
3939
edit_order_actual_destination: Option<Destination>,
4040
edit_fee: Option<Value>,
4141
edit_swap_fees: Option<((Int,Int), (Int, Int))>,
42+
edit_new_swap_fees: Option<((Int,Int), (Int, Int))>,
4243
edit_fee_admin: Option<Option<multisig.MultisigScript>>,
4344
edit_withdrawals: Option<Dict<StakeCredential, Int>>,
4445
edit_pool_input_address: Option<Address>,
@@ -56,6 +57,7 @@ fn default_scoop_test_options() -> ScoopTestOptions {
5657
edit_order_actual_destination: None,
5758
edit_fee: None,
5859
edit_swap_fees: None,
60+
edit_new_swap_fees: None,
5961
edit_fee_admin: None,
6062
edit_withdrawals: None,
6163
edit_pool_input_address: None,
@@ -719,10 +721,11 @@ fn update_pool_fees_transaction (options: ScoopTestOptions) {
719721
|> with_asset_of_tx_input(value.from_asset(constants.rberry_policy, constants.rberry_asset_name, 1_000_000_000))
720722
|> with_asset_of_tx_input(value.from_asset(constants.pool_script_hash, pool_nft_name, 1))
721723

724+
let new_pool_fees = option.or_else(options.edit_new_swap_fees, ((10,10),(310,150)))
722725
let pool_out_datum = PoolDatum {
723726
..pool_datum,
724-
bid_fees_per_10_thousand: (10,10),
725-
ask_fees_per_10_thousand: (310,150),
727+
bid_fees_per_10_thousand: new_pool_fees.1st,
728+
ask_fees_per_10_thousand: new_pool_fees.2nd,
726729
}
727730

728731
let pool_output = new_tx_output(pool_output_address, 0, InlineDatum(pool_out_datum))
@@ -760,6 +763,14 @@ test update_pool_fees_transaction_test() {
760763
update_pool_fees_transaction(default_scoop_test_options())
761764
}
762765

766+
test illegal_new_pool_fees_test() fail {
767+
let settings = ScoopTestOptions {
768+
..default_scoop_test_options(),
769+
edit_new_swap_fees: Some(((10001,10001),(10001,10001))),
770+
}
771+
update_pool_fees_transaction(settings)
772+
}
773+
763774
test cannot_update_pool_fees_transaction_test() fail {
764775
let settings = ScoopTestOptions {
765776
..default_scoop_test_options(),
@@ -1191,4 +1202,4 @@ test burn_pool() {
11911202
let pool_mint_redeemer = BurnPool(constants.pool_ident)
11921203
let result = pool_validator.mint(constants.settings_policy_id, pool_mint_redeemer, ctx)
11931204
result
1194-
}
1205+
}

0 commit comments

Comments
 (0)