Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve SSW-205 (validate pool fees range) #75

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/shared.ak
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,12 @@ test count_orders_test() {
pub fn oracle_sft_name() {
"oracle"
}

pub fn fees_in_legal_range(fees: (Int, Int)) {
and {
fees.1st >= 0,
fees.2nd >= 0,
fees.1st <= 10000,
fees.2nd <= 10000,
}
}
8 changes: 4 additions & 4 deletions plutus.json

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions validators/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,9 @@ validator(settings_policy_id: PolicyId) {
..
} = pool_output_datum

expect shared.fees_in_legal_range(bid_fees_per_10_thousand)
expect shared.fees_in_legal_range(ask_fees_per_10_thousand)

let expected_datum = PoolDatum {
..datum,
bid_fees_per_10_thousand,
Expand Down Expand Up @@ -496,14 +499,8 @@ validator(settings_policy_id: PolicyId) {
pool_output_datum.assets == (asset_a, asset_b),
pool_output_datum.circulating_lp == initial_lq,
pool_output_datum.market_open <= pool_output_datum.fee_finalized,
pool_output_datum.bid_fees_per_10_thousand.1st >= 0,
pool_output_datum.bid_fees_per_10_thousand.2nd >= 0,
pool_output_datum.bid_fees_per_10_thousand.1st <= 10000,
pool_output_datum.bid_fees_per_10_thousand.2nd <= 10000,
pool_output_datum.ask_fees_per_10_thousand.1st >= 0,
pool_output_datum.ask_fees_per_10_thousand.2nd >= 0,
pool_output_datum.ask_fees_per_10_thousand.1st <= 10000,
pool_output_datum.ask_fees_per_10_thousand.2nd <= 10000,
shared.fees_in_legal_range(pool_output_datum.bid_fees_per_10_thousand),
shared.fees_in_legal_range(pool_output_datum.ask_fees_per_10_thousand),
}

// Make sure that the pool output is paid into own_policy_id (the pool script, remember this is a multivalidator)
Expand Down
17 changes: 14 additions & 3 deletions validators/tests/pool.ak
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ScoopTestOptions {
edit_order_actual_destination: Option<Destination>,
edit_fee: Option<Value>,
edit_swap_fees: Option<((Int,Int), (Int, Int))>,
edit_new_swap_fees: Option<((Int,Int), (Int, Int))>,
edit_fee_admin: Option<Option<multisig.MultisigScript>>,
edit_withdrawals: Option<Dict<StakeCredential, Int>>,
edit_pool_input_address: Option<Address>,
Expand All @@ -56,6 +57,7 @@ fn default_scoop_test_options() -> ScoopTestOptions {
edit_order_actual_destination: None,
edit_fee: None,
edit_swap_fees: None,
edit_new_swap_fees: None,
edit_fee_admin: None,
edit_withdrawals: None,
edit_pool_input_address: None,
Expand Down Expand Up @@ -719,10 +721,11 @@ fn update_pool_fees_transaction (options: ScoopTestOptions) {
|> with_asset_of_tx_input(value.from_asset(constants.rberry_policy, constants.rberry_asset_name, 1_000_000_000))
|> with_asset_of_tx_input(value.from_asset(constants.pool_script_hash, pool_nft_name, 1))

let new_pool_fees = option.or_else(options.edit_new_swap_fees, ((10,10),(310,150)))
let pool_out_datum = PoolDatum {
..pool_datum,
bid_fees_per_10_thousand: (10,10),
ask_fees_per_10_thousand: (310,150),
bid_fees_per_10_thousand: new_pool_fees.1st,
ask_fees_per_10_thousand: new_pool_fees.2nd,
}

let pool_output = new_tx_output(pool_output_address, 0, InlineDatum(pool_out_datum))
Expand Down Expand Up @@ -760,6 +763,14 @@ test update_pool_fees_transaction_test() {
update_pool_fees_transaction(default_scoop_test_options())
}

test illegal_new_pool_fees_test() fail {
let settings = ScoopTestOptions {
..default_scoop_test_options(),
edit_new_swap_fees: Some(((10001,10001),(10001,10001))),
}
update_pool_fees_transaction(settings)
}

test cannot_update_pool_fees_transaction_test() fail {
let settings = ScoopTestOptions {
..default_scoop_test_options(),
Expand Down Expand Up @@ -1191,4 +1202,4 @@ test burn_pool() {
let pool_mint_redeemer = BurnPool(constants.pool_ident)
let result = pool_validator.mint(constants.settings_policy_id, pool_mint_redeemer, ctx)
result
}
}
Loading