Skip to content

Commit

Permalink
add back removed settle round logic
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenPtr committed Jan 20, 2025
1 parent 1b74a07 commit a093239
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ fn test_callback_works_as_expected() {
#[available_gas(90000000)]
fn test_0_rounds() {
let (mut vault, _) = setup_facade();

// need to customize each to do 0s
accelerate_to_auctioning_custom(ref vault, array![].span(), array![].span());
accelerate_to_running_custom(ref vault, array![].span(), array![].span(), array![].span());
Expand Down
37 changes: 37 additions & 0 deletions src/vault/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,40 @@ mod Vault {
let current_round = self.get_round_dispatcher(current_round_id);
let (total_payout, payout_per_option) = current_round.settle_round(twap);

// @dev Calculate the remaining liquidity after the round settles
let starting_liq = current_round.get_starting_liquidity();
let unsold_liq = current_round.get_unsold_liquidity();
let remaining_liq = starting_liq - unsold_liq - total_payout;

// @dev Calculate the amount of liquidity that was stashed/not stashed by liquidity
// providers, avoiding division by 0
let vault = get_contract_address();
let starting_liq_queued = self
.queued_liquidity
.entry(vault)
.entry(current_round_id)
.read();
let remaining_liq_stashed = match starting_liq.is_zero() {
true => 0,
false => (remaining_liq * starting_liq_queued) / starting_liq
};
let remaining_liq_not_stashed = remaining_liq - remaining_liq_stashed;

// @dev All of the remaining liquidity becomes unlocked, any stashed liquidity is
// set aside and no longer participates in the protocol
self.vault_locked_balance.write(0);
self
.vault_stashed_balance
.write(self.vault_stashed_balance.read() + remaining_liq_stashed);
self
.vault_unlocked_balance
.write(self.vault_unlocked_balance.read() + remaining_liq_not_stashed);

// @dev Transfer payout from the vault to the just settled round,
if (total_payout > 0) {
self.get_eth_dispatcher().transfer(current_round.contract_address, total_payout);
}

// @dev Emit event
self.emit(Event::OptionRoundSettled(OptionRoundSettled {
round_id: current_round_id,
Expand All @@ -835,6 +869,9 @@ mod Vault {
payout_per_option
}));

// @dev Deploy the next option round contract & update the current round id
self.deploy_next_round(L1Data { twap, volatility, reserve_price });

// @dev Return just the total payout
total_payout
}
Expand Down

0 comments on commit a093239

Please sign in to comment.