Skip to content

Commit

Permalink
[Defiplaza v2 Adapter v1]: Add a maximum allowed target ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Mar 12, 2024
1 parent 786c114 commit 8a3047b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/defiplaza-v2-adapter-v1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define_error! {
UNEXPECTED_ERROR => "Unexpected Error.";
INVALID_NUMBER_OF_BUCKETS => "Invalid number of buckets.";
NO_PAIR_CONFIG => "The pair config of the provided pool is not known.";
TARGET_RATIO_EXCEEDS_MAXIMUM => "The target ratio exceeds the allowed maximum";
}

macro_rules! pool {
Expand Down Expand Up @@ -208,6 +209,14 @@ pub mod adapter {
// Step 1: Get the pair's state
let pair_state = pool.get_state();

// Ensure that the pool's target ratio does not exceed the maximum
// allowed.
assert!(
pair_state.target_ratio <= self.max_allowed_target_ratio,
"{}",
TARGET_RATIO_EXCEEDS_MAXIMUM
);

// Step 2: Determine which of the resources is in shortage. The one
// in shortage is the one that we will be contributing first to the
// pool. If the pool is in equilibrium then we can pick any of the
Expand Down

0 comments on commit 8a3047b

Please sign in to comment.