DEX-898l. Fix old royalty withdraw contract#56
Conversation
49cfeb7 to
98c1078
Compare
|
@Bromel777 Add a bit of context: what has been fixed in this contract, how and why this was needed. |
There was a problem hiding this comment.
Pull Request Overview
This PR implements and fixes a royalty withdrawal contract system by migrating from Plutarch-based validators to new Aiken-based validators for handling royalty withdrawals from liquidity pools.
- Adds comprehensive Aiken contracts for both single and double royalty pool withdrawal systems
- Removes outdated Plutarch implementations to prevent conflicts with the new Aiken-based approach
- Updates project configuration and test files to support the new v3 validators architecture
Reviewed Changes
Copilot reviewed 18 out of 41 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| validators_v3/validators/royalty_pool/single_royalty_withdraw_pool.ak | Implements single royalty slot withdrawal validation logic |
| validators_v3/validators/royalty_pool/double_royalty_withdraw_pool.ak | Implements dual royalty slot withdrawal validation with signer-based slot selection |
| validators_v3/plutus.json | Contains compiled validator definitions and schemas for the new Aiken contracts |
| validators_v3/lib/splash/* | Supporting library modules for asset handling, pool configurations, and withdrawal orders |
| plutarch-validators/* | Updates to remove old Plutarch-based double royalty withdrawal implementation |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| // - All other fields (pool_x, pool_y, pool_lq, fees, dao_policy, | ||
| // treasury_address, *_pub_key, etc.) must be unchanged. | ||
| // | ||
| // 2) Signer delection |
There was a problem hiding this comment.
Typo in comment: 'delection' should be 'selection'
| // 2) Signer delection | |
| // 2) Signer selection |
| let pool_identity = asset_quantity_of(new_value, prev_pool_nft) == 1 | ||
|
|
||
| let royalty_withdraw_ok = | ||
| withdraw_x <= prev_rx && withdraw_y <= prev_ry && new_rx == prev_rx - withdraw_x && new_ry == prev_ry - withdraw_y && prev_lq_val == new_lq_val && prev_x_val - withdraw_x == new_x_val && prev_y_val - withdraw_y == new_y_val |
There was a problem hiding this comment.
[nitpick] This complex boolean expression should be broken down into multiple lines or separate boolean variables for better readability and maintainability.
| withdraw_x <= prev_rx && withdraw_y <= prev_ry && new_rx == prev_rx - withdraw_x && new_ry == prev_ry - withdraw_y && prev_lq_val == new_lq_val && prev_x_val - withdraw_x == new_x_val && prev_y_val - withdraw_y == new_y_val | |
| let withdraw_x_within_prev_rx = withdraw_x <= prev_rx | |
| let withdraw_y_within_prev_ry = withdraw_y <= prev_ry | |
| let new_rx_is_correct = new_rx == prev_rx - withdraw_x | |
| let new_ry_is_correct = new_ry == prev_ry - withdraw_y | |
| let lq_val_unchanged = prev_lq_val == new_lq_val | |
| let x_val_updated_correctly = prev_x_val - withdraw_x == new_x_val | |
| let y_val_updated_correctly = prev_y_val - withdraw_y == new_y_val | |
| let royalty_withdraw_ok = | |
| withdraw_x_within_prev_rx && | |
| withdraw_y_within_prev_ry && | |
| new_rx_is_correct && | |
| new_ry_is_correct && | |
| lq_val_unchanged && | |
| x_val_updated_correctly && | |
| y_val_updated_correctly |
| if signer == 0 { | ||
| withdraw_x <= prev_first_rx && withdraw_y <= prev_first_ry && new_first_rx == prev_first_rx - withdraw_x && new_first_ry == prev_first_ry - withdraw_y && prev_second_rx == new_second_rx && prev_second_ry == new_second_ry | ||
| } else { | ||
| withdraw_x <= prev_second_rx && withdraw_y <= prev_second_ry && new_second_rx == prev_second_rx - withdraw_x && new_second_ry == prev_second_ry - withdraw_y && prev_first_rx == new_first_rx && prev_first_ry == new_first_ry |
There was a problem hiding this comment.
[nitpick] These complex boolean expressions should be broken down into multiple lines or separate boolean variables for better readability and maintainability.
| withdraw_x <= prev_second_rx && withdraw_y <= prev_second_ry && new_second_rx == prev_second_rx - withdraw_x && new_second_ry == prev_second_ry - withdraw_y && prev_first_rx == new_first_rx && prev_first_ry == new_first_ry | |
| let cond1 = withdraw_x <= prev_first_rx | |
| let cond2 = withdraw_y <= prev_first_ry | |
| let cond3 = new_first_rx == prev_first_rx - withdraw_x | |
| let cond4 = new_first_ry == prev_first_ry - withdraw_y | |
| let cond5 = prev_second_rx == new_second_rx | |
| let cond6 = prev_second_ry == new_second_ry | |
| cond1 && cond2 && cond3 && cond4 && cond5 && cond6 | |
| } else { | |
| let cond1 = withdraw_x <= prev_second_rx | |
| let cond2 = withdraw_y <= prev_second_ry | |
| let cond3 = new_second_rx == prev_second_rx - withdraw_x | |
| let cond4 = new_second_ry == prev_second_ry - withdraw_y | |
| let cond5 = prev_first_rx == new_first_rx | |
| let cond6 = prev_first_ry == new_first_ry | |
| cond1 && cond2 && cond3 && cond4 && cond5 && cond6 |
|
|
||
| let strict_inputs = list.length(inputs) == 2 | ||
|
|
||
| correct_order_input_address && correct_final_pool_address && correct_tokens_qty_in_pool && pool_identity && royalty_withdraw_ok && signature_is_correct && strict_inputs && final_pool_config_is_correct && correct_pool && correct_lovelace_token2token |
There was a problem hiding this comment.
[nitpick] This long boolean expression should be broken down into multiple lines for better readability.
| correct_order_input_address && correct_final_pool_address && correct_tokens_qty_in_pool && pool_identity && royalty_withdraw_ok && signature_is_correct && strict_inputs && final_pool_config_is_correct && correct_pool && correct_lovelace_token2token | |
| correct_order_input_address | |
| && correct_final_pool_address | |
| && correct_tokens_qty_in_pool | |
| && pool_identity | |
| && royalty_withdraw_ok | |
| && signature_is_correct | |
| && strict_inputs | |
| && final_pool_config_is_correct | |
| && correct_pool | |
| && correct_lovelace_token2token |
| let strict_inputs = list.length(inputs) == 2 | ||
|
|
||
| correct_order_input_address && correct_final_pool_address && correct_tokens_qty_in_pool && pool_identity && royalty_withdraw_is_correct && tokens_diff_is_correct && signature_is_correct && | ||
| final_pool_config_is_correct && correct_pool && correct_lovelace_token2token && strict_inputs |
There was a problem hiding this comment.
[nitpick] This long boolean expression should be broken down with consistent formatting - either all conditions on one line or each condition on its own line.
| final_pool_config_is_correct && correct_pool && correct_lovelace_token2token && strict_inputs | |
| correct_order_input_address && | |
| correct_final_pool_address && | |
| correct_tokens_qty_in_pool && | |
| pool_identity && | |
| royalty_withdraw_is_correct && | |
| tokens_diff_is_correct && | |
| signature_is_correct && | |
| final_pool_config_is_correct && | |
| correct_pool && | |
| correct_lovelace_token2token && | |
| strict_inputs |
|
@Bromel777 what is the reason for validators v2/v3 separation? They all are Aiken validators of different pool types and orders |
We split validators into v2 and v3 because, while they’re all Aiken validators (for different pools/orders), v3 targets the latest Aiken with Plutus v3, and the existing contracts use the prior Aiken with Plutus v2. Migrating everything now would be a major effort due to new validator definitions and would change script hashes, breaking existing deployments. To avoid that, and with @oskin1’s approval, we’re keeping legacy (v2) contracts separate from the new v3 ones. |
98c1078 to
4a5eae7
Compare
4a5eae7 to
6f32306
Compare
6f32306 to
42c1f05
Compare
* FUN-411. Double royalty pool * Single/Double royalty withdraw pool contracts (#56)
No description provided.