Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix / Requeue validation removal #254

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 17 additions & 31 deletions x/orderbook/keeper/bet_wager.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,14 @@ func (k Keeper) initFulfillmentInfo(
) {
fInfo = fulfillmentInfo{
// bet specs
betAmount: betAmount,
payoutProfit: payoutProfit,
betUID: betUID,
betID: betID,
oddsUID: oddsUID,
oddsType: oddsType,
oddsVal: oddsVal,
maxLossMultiplier: maxLossMultiplier,
totalAvailableLiquidity: sdk.NewInt(0),
betAmount: betAmount,
payoutProfit: payoutProfit,
betUID: betUID,
betID: betID,
oddsUID: oddsUID,
oddsType: oddsType,
oddsVal: oddsVal,
maxLossMultiplier: maxLossMultiplier,

// in process maps
fulfillmentMap: make(map[uint64]fulfillmentItem),
Expand Down Expand Up @@ -237,9 +236,6 @@ func (k Keeper) initFulfillmentInfo(
if found {
item.participationExposure = pe
fInfo.fulfillmentMap[pe.ParticipationIndex] = item

fInfo.totalAvailableLiquidity = fInfo.totalAvailableLiquidity.
Add(item.calcAvailableLiquidity(maxLossMultiplier))
}
}

Expand Down Expand Up @@ -271,15 +267,6 @@ func (fInfo *fulfillmentInfo) validate() error {
}
}

if fInfo.totalAvailableLiquidity.LT(fInfo.payoutProfit.TruncateInt()) {
return sdkerrors.Wrapf(
types.ErrInsufficientFundToCoverPayout,
"total liquidity %s, payout %s",
fInfo.totalAvailableLiquidity,
fInfo.payoutProfit,
)
}

return nil
}

Expand Down Expand Up @@ -417,16 +404,15 @@ func (k Keeper) refreshQueueAndState(
}

type fulfillmentInfo struct {
betUID string
betID uint64
oddsUID string
oddsType bettypes.OddsType
oddsVal string
maxLossMultiplier sdk.Dec
betAmount sdkmath.Int
payoutProfit sdk.Dec
fulfilledBetAmount sdkmath.Int
totalAvailableLiquidity sdkmath.Int
betUID string
betID uint64
oddsUID string
oddsType bettypes.OddsType
oddsVal string
maxLossMultiplier sdk.Dec
betAmount sdkmath.Int
payoutProfit sdk.Dec
fulfilledBetAmount sdkmath.Int

fulfillmentQueue []uint64
fulfillmentMap fulfillmentMap
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 @@ -248,7 +248,7 @@ func (ts *testBetSuite) placeBetsAndTest() ([]bettypes.Bet, sdk.Dec, sdk.Dec) {
failedWinnerBetID,
sdk.NewInt(100000000000),
ts.betFee,
types.ErrInsufficientFundToCoverPayout,
types.ErrInternalProcessingBet,
)

///// loser bet placement
Expand Down
10 changes: 8 additions & 2 deletions x/orderbook/keeper/orderbook_settle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ func TestOrderBookSettlement(t *testing.T) {
Sub(ts.participations[1].Fee),
participant2BalanceAfterSettlement)

// In this case, in the orderbook we have a long loop of requeue
// and the payout is a large value.
// in the real scenario when the bet placement transaction fails duo to
// orderbook failure, the hole transaction would fail and no state change will happen.
participant3BalanceAfterSettlement := ts.tApp.BankKeeper.GetBalance(
ts.ctx, sdk.MustAccAddressFromBech32(ts.deposits[2].DepositorAddress),
params.DefaultBondDenom).Amount
require.Equal(t,
participant3BalanceBeforeDeposit.Int64(),
participant3BalanceAfterSettlement.Int64())
participant3BalanceBeforeDeposit.
// subtract participation fee
Sub(ts.participations[2].Fee),
participant3BalanceAfterSettlement)
}
1 change: 0 additions & 1 deletion x/orderbook/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ var (
ErrMaxWithdrawableAmountIsZero = sdkerrors.Register(ModuleName, 6021, "maximum withdrawal amount is zero")
ErrParticipationOnInactiveMarket = sdkerrors.Register(ModuleName, 6022, "participation is allowed on an active market only")
ErrMarketNotFound = sdkerrors.Register(ModuleName, 6023, "market not found to initialize participation")
ErrInsufficientFundToCoverPayout = sdkerrors.Register(ModuleName, 6024, "insufficient fund in the participations to cover the payout")
ErrUnknownMarketStatus = sdkerrors.Register(ModuleName, 6025, "unknown market status of orderbook settlement")
ErrWithdrawalTooLarge = sdkerrors.Register(ModuleName, 6026, "withdrawal is more than unused amount")
)
Expand Down
Loading