Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
avkr003 authored Dec 26, 2024
2 parents 03ce2c0 + e776107 commit c4558d2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
5 changes: 5 additions & 0 deletions x/estaking/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
commitmenttypes "github.com/elys-network/elys/x/commitment/types"
"github.com/elys-network/elys/x/estaking/types"
ptypes "github.com/elys-network/elys/x/parameter/types"
)

Expand All @@ -15,6 +16,10 @@ func (k Keeper) CommitmentChanged(ctx sdk.Context, creator sdk.AccAddress, amoun
if err != nil {
return err
}
_, err = k.WithdrawAllRewards(ctx, &types.MsgWithdrawAllRewards{DelegatorAddress: creator.String()})
if err != nil {
return err
}

del, _ := k.Delegation(ctx, creator, edenValAddr)
if del == nil {
Expand Down
12 changes: 10 additions & 2 deletions x/leveragelp/keeper/msg_server_close_positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func (k msgServer) ClosePositions(goCtx context.Context, msg *types.MsgClosePosi
continue
}

_, _, _, err = k.CheckAndLiquidateUnhealthyPosition(ctx, &position, pool, ammPool)
cachedCtx, write := ctx.CacheContext()
_, _, _, err = k.CheckAndLiquidateUnhealthyPosition(cachedCtx, &position, pool, ammPool)
if err == nil {
write()
}
if err != nil {
// Add log about error or not liquidated
liqLog = append(liqLog, fmt.Sprintf("Position: Address:%s Id:%d cannot be liquidated due to err: %s", position.Address, position.Id, err.Error()))
Expand Down Expand Up @@ -67,7 +71,11 @@ func (k msgServer) ClosePositions(goCtx context.Context, msg *types.MsgClosePosi
if poolErr != nil {
continue
}
_, _, err = k.CheckAndCloseAtStopLoss(ctx, &position, pool, ammPool)
cachedCtx, write := ctx.CacheContext()
_, _, err = k.CheckAndCloseAtStopLoss(cachedCtx, &position, pool, ammPool)
if err == nil {
write()
}
if err != nil {
// Add log about error or not closed
closeLog = append(closeLog, fmt.Sprintf("Position: Address:%s Id:%d cannot be liquidated due to err: %s", position.Address, position.Id, err.Error()))
Expand Down
18 changes: 15 additions & 3 deletions x/perpetual/keeper/msg_server_close_positions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ func (k msgServer) ClosePositions(goCtx context.Context, msg *types.MsgClosePosi
continue
}

err = k.CheckAndLiquidateUnhealthyPosition(ctx, &position, pool, ammPool, baseCurrency.Denom)
cachedCtx, write := ctx.CacheContext()
err = k.CheckAndLiquidateUnhealthyPosition(cachedCtx, &position, pool, ammPool, baseCurrency.Denom)
if err == nil {
write()
}
if err != nil {
// Add log about error or not liquidated
liqLog = append(liqLog, fmt.Sprintf("Position: Address:%s Id:%d cannot be liquidated due to err: %s", position.Address, position.Id, err.Error()))
Expand All @@ -57,7 +61,11 @@ func (k msgServer) ClosePositions(goCtx context.Context, msg *types.MsgClosePosi
continue
}

err = k.CheckAndCloseAtStopLoss(ctx, &position, pool, baseCurrency.Denom)
cachedCtx, write := ctx.CacheContext()
err = k.CheckAndCloseAtStopLoss(cachedCtx, &position, pool, baseCurrency.Denom)
if err == nil {
write()
}
if err != nil {
// Add log about error or not closed
closeLog = append(closeLog, fmt.Sprintf("Position: Address:%s Id:%d cannot be liquidated due to err: %s", position.Address, position.Id, err.Error()))
Expand All @@ -78,7 +86,11 @@ func (k msgServer) ClosePositions(goCtx context.Context, msg *types.MsgClosePosi
continue
}

err = k.CheckAndCloseAtTakeProfit(ctx, &position, pool, baseCurrency.Denom)
cachedCtx, write := ctx.CacheContext()
err = k.CheckAndCloseAtTakeProfit(cachedCtx, &position, pool, baseCurrency.Denom)
if err == nil {
write()
}
if err != nil {
// Add log about error or not closed
takeProfitLog = append(takeProfitLog, fmt.Sprintf("Position: Address:%s Id:%d cannot be liquidated due to err: %s", position.Address, position.Id, err.Error()))
Expand Down
30 changes: 25 additions & 5 deletions x/tradeshield/keeper/msg_server_execute_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,32 @@ func (k msgServer) ExecuteOrders(goCtx context.Context, msg *types.MsgExecuteOrd
switch spotOrder.OrderType {
case types.SpotOrderType_STOPLOSS:
// execute the stop loss order
_, err = k.ExecuteStopLossOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteStopLossOrder(cachedCtx, spotOrder)
if err == nil {
write()
}
case types.SpotOrderType_LIMITSELL:
// execute the limit sell order
_, err = k.ExecuteLimitSellOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteLimitSellOrder(cachedCtx, spotOrder)
if err == nil {
write()
}
case types.SpotOrderType_LIMITBUY:
// execute the limit buy order
_, err = k.ExecuteLimitBuyOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteLimitBuyOrder(cachedCtx, spotOrder)
if err == nil {
write()
}
case types.SpotOrderType_MARKETBUY:
// execute the market buy order
_, err = k.ExecuteMarketBuyOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteMarketBuyOrder(cachedCtx, spotOrder)
if err == nil {
write()
}
}

// log the error if any
Expand All @@ -61,7 +77,11 @@ func (k msgServer) ExecuteOrders(goCtx context.Context, msg *types.MsgExecuteOrd
switch perpetualOrder.PerpetualOrderType {
case types.PerpetualOrderType_LIMITOPEN:
// execute the limit open order
err = k.ExecuteLimitOpenOrder(ctx, perpetualOrder)
cachedCtx, write := ctx.CacheContext()
err = k.ExecuteLimitOpenOrder(cachedCtx, perpetualOrder)
if err == nil {
write()
}
// Disable for v1
// case types.PerpetualOrderType_LIMITCLOSE:
// // execute the limit close order
Expand Down

0 comments on commit c4558d2

Please sign in to comment.