From ab6d6bde6159ca62b886ab317f3966c7543ed069 Mon Sep 17 00:00:00 2001 From: Jason Ridgway-Taylor Date: Thu, 31 Aug 2023 14:41:08 +0300 Subject: [PATCH] Added enforcement of correct side wehn depositing tokens --- batcher/batcher.mligo | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/batcher/batcher.mligo b/batcher/batcher.mligo index 9fff23bf..fd2dd6f1 100644 --- a/batcher/batcher.mligo +++ b/batcher/batcher.mligo @@ -40,6 +40,7 @@ [@inline] let cannot_update_scale_factor_to_more_than_the_maximum : nat = 136n [@inline] let cannot_remove_swap_pair_that_is_not_disabled : nat = 137n [@inline] let token_name_not_in_list_of_valid_tokens : nat = 138n +[@inline] let incorrect_side_specified: nat = 139n (* Constants *) @@ -1699,6 +1700,16 @@ let confirm_swap_pair_is_disabled_prior_to_removal (valid_swap:valid_swap) : unit = if valid_swap.is_disabled_for_deposits then () else failwith cannot_remove_swap_pair_that_is_not_disabled + +let enforce_correct_side + (order:external_swap_order) + (valid_swap:valid_swap) : unit = + let swap = order.swap in + match order.side with + | 0n -> if swap.from.token.name = vaild_swap.from.token.name then () else failwith incorrect_side_specified + | 1n -> if swap.from.token.name = vaild_swap.to.token.name then () else failwith incorrect_side_specified + | _ -> failwith incorrect_side_specified + (* Register a deposit during a valid (Open) deposit time; fails otherwise. Updates the current_batch if the time is valid but the new batch was not initialized. *) [@inline] @@ -1708,6 +1719,7 @@ let deposit (external_order: external_swap_order) (storage : storage) : result = let pair_name = Utils.get_rate_name_from_pair pair in let valid_swap = get_valid_swap_reduced pair_name storage in if valid_swap.is_disabled_for_deposits then failwith swap_is_disabled_for_deposits else + let () = enforce_correct_side external_order.side vaild_swap in let fee_amount_in_mutez = storage.fee_in_mutez in let fee_provided = Tezos.get_amount () in if fee_provided < fee_amount_in_mutez then failwith insufficient_swap_fee else