Skip to content

Commit

Permalink
Remove LOOKBACK from get_value_of_pool_expired_position
Browse files Browse the repository at this point in the history
  • Loading branch information
Chepelau committed Dec 11, 2023
1 parent 5cf4f34 commit 74821ef
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/amm_core/liquidity_pool.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,9 @@ mod LiquidityPool {
// @notice Retrieves the value of the expired position within the pool
// @dev Returns a total value of pools non expired position.
// @dev Walks backwards (iteration starts from last index) all options in storage var "available_options"
// @dev that expired in last 8 weeks
// @dev (how much to go back is defined by LOOKBACK variable inside the function)
// @param lptoken_address: Address of the liquidity pool token
// @return res: Value of the expired position within specified liquidity pool
fn get_value_of_pool_expired_position(lptoken_address: LPTAddress) -> Fixed {
let LOOKBACK = 24 * 3600 * 7 * 8;
// ^ Only look back 8 weeks, all options should be long expired by then
let now = get_block_timestamp();
let last_ix = get_available_options_usable_index(lptoken_address);

Expand Down Expand Up @@ -187,14 +183,23 @@ mod LiquidityPool {
continue;
};

if (now - option.maturity) > LOOKBACK {
// We're over lookback window so break the loop
break;
};

// Get pool's position in given option
let option_position = option.pools_position();

// There is nothing to calculate if there is no position
if option_position == 0 {
// ix = 0 means there are no more options to consider
// so break the loop
if ix == 0 {
break;
}

// We're not at the end (beginning) of array
// so decrease index and continue
ix -= 1;
continue;
};

// Add value of the given position
pool_pos += option.value_of_position(option_position);

Expand Down

0 comments on commit 74821ef

Please sign in to comment.