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

check batcher fee on donation order and use ADA constant variable instead of hardcoded string #52

Merged
merged 1 commit into from
Apr 26, 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
37 changes: 33 additions & 4 deletions lib/amm_dex_v2/order_validation.ak
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn get_optimized_swap_output_value(
a_to_b: Bool,
) -> Option<SortedValueList> {
// Ensure that asset A is ADA
if asset_a_policy_id == #"" && asset_a_asset_name == #"" {
if utils.is_ada_asset(asset_a_policy_id, asset_a_asset_name) {
let order_in_value_list = order_in_value |> utils.value_to_list
let ada_entry = builtin.head_list(order_in_value_list)
let rest_0 = builtin.tail_list(order_in_value_list)
Expand All @@ -57,7 +57,15 @@ fn get_optimized_swap_output_value(
if a_to_b {
Some(
[
(#"", [(#"", asset_a_amount - ( used_batcher_fee + amount_in ))]),
(
ada_policy_id,
[
(
ada_asset_name,
asset_a_amount - ( used_batcher_fee + amount_in ),
),
],
),
(asset_b_policy_id, [(asset_b_asset_name, amount_out)]),
],
)
Expand All @@ -74,14 +82,32 @@ fn get_optimized_swap_output_value(
if asset_amount > amount_in {
Some(
[
(#"", [(#"", asset_a_amount - used_batcher_fee + amount_out)]),
(
ada_policy_id,
[
(
ada_asset_name,
asset_a_amount - used_batcher_fee + amount_out,
),
],
),
(asset_pid, [(asset_tn, asset_amount - amount_in)]),
],
)
} else if asset_amount == amount_in {
// Asset B have no change
Some(
[(#"", [(#"", asset_a_amount - used_batcher_fee + amount_out)])],
[
(
ada_policy_id,
[
(
ada_asset_name,
asset_a_amount - used_batcher_fee + amount_out,
),
],
),
],
)
} else {
fail
Expand Down Expand Up @@ -968,6 +994,9 @@ fn validate_donation(
if utils.is_ada_asset(asset_a_policy_id, asset_a_asset_name) {
temp_amount_a - used_batcher_fee
} else {
let ada_amount =
order_in_value |> value.quantity_of(ada_policy_id, ada_asset_name)
expect ada_amount >= used_batcher_fee
temp_amount_a
}
let amount_b =
Expand Down
Loading
Loading