Skip to content

DEX-898l. Fix old royalty withdraw contract#56

Merged
Bromel777 merged 1 commit intofun-411-double-royalty-poolfrom
dex-898-fix-old-royalty-withdraw-contract
Oct 20, 2025
Merged

DEX-898l. Fix old royalty withdraw contract#56
Bromel777 merged 1 commit intofun-411-double-royalty-poolfrom
dex-898-fix-old-royalty-withdraw-contract

Conversation

@Bromel777
Copy link
Collaborator

No description provided.

@Bromel777 Bromel777 force-pushed the dex-898-fix-old-royalty-withdraw-contract branch from 49cfeb7 to 98c1078 Compare August 18, 2025 08:08
@Bromel777 Bromel777 requested review from AOranov and oskin1 August 18, 2025 18:49
@oskin1 oskin1 requested a review from Copilot August 19, 2025 08:56
@oskin1
Copy link
Contributor

oskin1 commented Aug 19, 2025

@Bromel777 Add a bit of context: what has been fixed in this contract, how and why this was needed.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in comment: 'delection' should be 'selection'

Suggested change
// 2) Signer delection
// 2) Signer selection

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This complex boolean expression should be broken down into multiple lines or separate boolean variables for better readability and maintainability.

Suggested change
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

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] These complex boolean expressions should be broken down into multiple lines or separate boolean variables for better readability and maintainability.

Suggested change
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

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This long boolean expression should be broken down into multiple lines for better readability.

Suggested change
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

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@AOranov
Copy link
Collaborator

AOranov commented Aug 19, 2025

@Bromel777 what is the reason for validators v2/v3 separation? They all are Aiken validators of different pool types and orders

@Bromel777
Copy link
Collaborator Author

@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.

@Bromel777 Bromel777 force-pushed the dex-898-fix-old-royalty-withdraw-contract branch from 98c1078 to 4a5eae7 Compare August 20, 2025 12:34
@Bromel777 Bromel777 force-pushed the dex-898-fix-old-royalty-withdraw-contract branch from 4a5eae7 to 6f32306 Compare October 20, 2025 19:51
@Bromel777 Bromel777 force-pushed the dex-898-fix-old-royalty-withdraw-contract branch from 6f32306 to 42c1f05 Compare October 20, 2025 19:52
@Bromel777 Bromel777 merged commit df2cc5b into fun-411-double-royalty-pool Oct 20, 2025
1 check failed
Bromel777 added a commit that referenced this pull request Oct 21, 2025
* FUN-411. Double royalty pool

* Single/Double royalty withdraw pool contracts (#56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants