Skip to content

Commit 5b8721f

Browse files
authored
Fix issues found during bug bash (#143)
1 parent 3e8dbb0 commit 5b8721f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

x/dex/module.go

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"sort"
78

89
"github.com/CosmWasm/wasmd/x/wasm"
910
"github.com/gorilla/mux"
@@ -346,6 +347,12 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contract types.Contract
346347
assetDenomStr := pair.AssetDenom
347348
allExistingBuys := am.keeper.GetAllLongBookForPair(ctx, contractAddr, priceDenomStr, assetDenomStr)
348349
allExistingSells := am.keeper.GetAllShortBookForPair(ctx, contractAddr, priceDenomStr, assetDenomStr)
350+
sort.Slice(allExistingBuys, func(i, j int) bool {
351+
return allExistingBuys[i].GetPrice().LT(allExistingBuys[j].GetPrice())
352+
})
353+
sort.Slice(allExistingSells, func(i, j int) bool {
354+
return allExistingSells[i].GetPrice().LT(allExistingSells[j].GetPrice())
355+
})
349356

350357
longDirtyPrices, shortDirtyPrices := exchange.NewDirtyPrices(), exchange.NewDirtyPrices()
351358

@@ -473,6 +480,7 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contract types.Contract
473480
Id: marketOrder.Id,
474481
Initiator: types.CancellationInitiator_USER,
475482
})
483+
am.keeper.UpdateOrderStatus(ctx, contractAddr, marketOrder.Id, types.OrderStatus_CANCELLED)
476484
}
477485
}
478486
for _, marketOrder := range marketSells {
@@ -481,6 +489,7 @@ func (am AppModule) endBlockForContract(ctx sdk.Context, contract types.Contract
481489
Id: marketOrder.Id,
482490
Initiator: types.CancellationInitiator_USER,
483491
})
492+
am.keeper.UpdateOrderStatus(ctx, contractAddr, marketOrder.Id, types.OrderStatus_CANCELLED)
484493
}
485494
}
486495
}

x/dex/module_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ func TestEndBlockMarketOrder(t *testing.T) {
7373
Data: "{\"position_effect\":\"Open\",\"leverage\":\"1\"}",
7474
},
7575
)
76+
dexkeeper.MemState.GetBlockOrders(types.ContractAddress(contractAddr.String()), types.GetPairString(&pair)).AddOrder(
77+
types.Order{
78+
Id: 2,
79+
Account: testAccount.String(),
80+
ContractAddr: contractAddr.String(),
81+
Price: sdk.MustNewDecFromStr("2"),
82+
Quantity: sdk.MustNewDecFromStr("1"),
83+
PriceDenom: pair.PriceDenom,
84+
AssetDenom: pair.AssetDenom,
85+
OrderType: types.OrderType_LIMIT,
86+
PositionDirection: types.PositionDirection_LONG,
87+
Data: "{\"position_effect\":\"Open\",\"leverage\":\"1\"}",
88+
},
89+
)
7690
dexkeeper.MemState.GetDepositInfo(types.ContractAddress(contractAddr.String())).AddDeposit(
7791
dexcache.DepositInfoEntry{
7892
Creator: testAccount.String(),

0 commit comments

Comments
 (0)