diff --git a/app/upgrades/v1.2.0/upgrade.go b/app/upgrades/v1.2.0/upgrade.go index 0bbef62..8061f87 100644 --- a/app/upgrades/v1.2.0/upgrade.go +++ b/app/upgrades/v1.2.0/upgrade.go @@ -18,6 +18,8 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { ctx.Logger().Info("Starting module migrations...") + marketAccount := keepers.AccountKeeper.GetModuleAccount(ctx, markettypes.ModuleName) + // Deactivate all drops and remove owners drops := keepers.MarketKeeper.GetAllDrop(ctx) for _, drop := range drops { @@ -47,17 +49,30 @@ func CreateUpgradeHandler( keepers.MarketKeeper.SetMember(ctx, member) } - // Set order status to balances to zero + // Set order status to canceled orders := keepers.MarketKeeper.GetAllOrder(ctx) for _, order := range orders { if order.Status == "active" { order.Status = "canceled" + order.Prev = 0 + order.Next = 0 + order.UpdTime = ctx.BlockHeader().Time.Unix() + coinRefund := sdk.NewCoin(order.DenomBid, order.Amount) + marketBal := keepers.BankKeeper.GetBalance(ctx, marketAccount.GetAddress(), order.DenomBid) + if marketBal.Amount.GTE(order.Amount) { + refundAddr, _ := sdk.AccAddressFromBech32(order.Owner) + keepers.BankKeeper.SendCoinsFromModuleToAccount( + ctx, + markettypes.ModuleName, + refundAddr, + sdk.NewCoins(coinRefund), + ) + } + + keepers.MarketKeeper.SetOrder(ctx, order) } - keepers.MarketKeeper.SetOrder(ctx, order) } - marketAccount := keepers.AccountKeeper.GetModuleAccount(ctx, markettypes.ModuleName) - marketCoins := keepers.BankKeeper.GetAllBalances(ctx, marketAccount.GetAddress()) reclaimer, _ := sdk.AccAddressFromBech32("onomy1yc0lg97cy5e80jyajtkz0zke2rr4734anugf9g")