Skip to content

Commit

Permalink
Merge pull request #263 from P-U-D-G-E/reorder_mino
Browse files Browse the repository at this point in the history
Fix for reorder in case of no liquidity left when reorder is possible
  • Loading branch information
3eyedraga authored Oct 6, 2023
2 parents 1b4b5bb + bc5a1b7 commit eac83d6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
19 changes: 12 additions & 7 deletions x/orderbook/keeper/bet_wager.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,22 @@ func (k Keeper) fulfillBetByParticipationQueue(

if setFulfilled {
fInfo.setItemFulfilledAndRemove()
eUpdate, err := fInfo.checkFullfillmentForOtherOdds(requeThreshold)
if err != nil {
return err
}
for _, exposure := range eUpdate {
k.SetParticipationExposure(ctx, exposure)
if fInfo.inProcessItem.participation.IsEligibleForNextRoundPreLiquidityReduction() {
eUpdate, err := fInfo.checkFullfillmentForOtherOdds(requeThreshold)
if err != nil {
return err
}
for _, exposure := range eUpdate {
k.SetParticipationExposure(ctx, exposure)
}
}
}

k.SetParticipationExposure(ctx, fInfo.inProcessItem.participationExposure)
k.SetOrderBookParticipation(ctx, fInfo.inProcessItem.participation)

// if there are no more exposures to be filled
if fInfo.inProcessItem.allExposureFulfilled() {
if fInfo.inProcessItem.allExposureFulfilled() && fInfo.inProcessItem.participation.IsEligibleForNextRoundPreLiquidityReduction() {
err := k.refreshQueueAndState(ctx, fInfo, book)
if err != nil {
return err
Expand Down Expand Up @@ -465,6 +467,9 @@ func (fInfo *fulfillmentInfo) checkFullfillmentForOtherOdds(requeThreshold sdkma

// check if other exposures are fulfilled according to new max loss multipliers
for _, oddUID := range fInfo.oddUIDS {
if oddUID == fInfo.oddsUID {
continue
}
exposure, ok := fInfo.inProcessItem.allExposures[oddUID]
if !ok {
err = sdkerrors.Wrapf(types.ErrParticipationExposuresNotFound, "%s %d", oddUID, fInfo.inProcessItem.participation.Index)
Expand Down
2 changes: 1 addition & 1 deletion x/orderbook/keeper/bet_wager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) {
betOdds := make(map[string]*bettypes.BetOddsCompact)
var oddUIDS []string
for _, odd := range ts.market.Odds {
betOdds[odd.UID] = &bettypes.BetOddsCompact{UID: odd.UID, MaxLossMultiplier: sdk.MustNewDecFromStr("0.1")}
betOdds[odd.UID] = &bettypes.BetOddsCompact{UID: odd.UID, MaxLossMultiplier: sdk.MustNewDecFromStr("0.3")}
oddUIDS = append(oddUIDS, odd.UID)
}

Expand Down
7 changes: 7 additions & 0 deletions x/orderbook/types/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ func (p *OrderBookParticipation) IsEligibleForNextRound() bool {
return p.CurrentRoundLiquidity.GT(sdk.ZeroInt())
}

// IsEligibleForNextRound determines if the participation has enough
// liquidity to be used in the next round or not
func (p *OrderBookParticipation) IsEligibleForNextRoundPreLiquidityReduction() bool {
maxLoss := sdk.MaxInt(sdk.ZeroInt(), p.CurrentRoundMaxLoss)
return p.CurrentRoundLiquidity.Sub(maxLoss).GT(sdk.ZeroInt())
}

// TrimCurrentRoundLiquidity subtracts the max loss from the current round liquidity.
func (p *OrderBookParticipation) TrimCurrentRoundLiquidity() {
maxLoss := sdk.MaxInt(sdk.ZeroInt(), p.CurrentRoundMaxLoss)
Expand Down

0 comments on commit eac83d6

Please sign in to comment.