Skip to content

Commit

Permalink
Merge pull request #372 from sge-network/fix/missing-locked-balances
Browse files Browse the repository at this point in the history
Fix / Missing locked balances
  • Loading branch information
3eyedraga authored Mar 20, 2024
2 parents 8fbca35 + e7d167e commit 977c6da
Show file tree
Hide file tree
Showing 47 changed files with 660 additions and 377 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
v4 "github.com/sge-network/sge/app/upgrades/v4"
v5 "github.com/sge-network/sge/app/upgrades/v5"
v6 "github.com/sge-network/sge/app/upgrades/v6"
v7 "github.com/sge-network/sge/app/upgrades/v7"

abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
Expand Down Expand Up @@ -80,6 +81,7 @@ var (
v4.Upgrade,
v5.Upgrade,
v6.Upgrade,
v7.Upgrade,
}
)

Expand Down
19 changes: 19 additions & 0 deletions app/upgrades/v7/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v7

import (
store "github.com/cosmos/cosmos-sdk/store/types"

"github.com/sge-network/sge/app/upgrades"
)

// UpgradeName defines the on-chain upgrade name for the v1.5.3 upgrade.
const UpgradeName = "v1.5.3"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
44 changes: 44 additions & 0 deletions app/upgrades/v7/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package v7

import (
"fmt"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/sge-network/sge/app/keepers"
subaccounttypes "github.com/sge-network/sge/x/subaccount/types"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
k *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
allSubaccounts := k.SubaccountKeeper.GetAllSubaccounts(ctx)

for _, sa := range allSubaccounts {
subAccAddr := sdk.MustAccAddressFromBech32(sa.Address)
accSummary, found := k.SubaccountKeeper.GetAccountSummary(ctx, subAccAddr)
if !found {
panic(fmt.Errorf("account summary for the subaccount not found %s", subAccAddr))
}

_, totalBalances := k.SubaccountKeeper.GetBalances(ctx, subAccAddr, subaccounttypes.LockedBalanceStatus_LOCKED_BALANCE_STATUS_UNSPECIFIED)

missingBalance := accSummary.DepositedAmount.Sub(totalBalances)
if missingBalance.GT(sdkmath.ZeroInt()) {
k.SubaccountKeeper.SetLockedBalances(ctx, subAccAddr, []subaccounttypes.LockedBalance{
{
Amount: missingBalance,
UnlockTS: 1710830000,
},
})
}
}

return mm.RunMigrations(ctx, configurator, fromVM)
}
}
8 changes: 4 additions & 4 deletions proto/sge/orderbook/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ service Query {
}

// Queries list of settled Orderbook Participation items of a certain height.
rpc SettledOrderbookParticipationsOfHeight(
rpc SettledOrderBookParticipationsOfHeight(
QuerySettledOrderBookParticipationsOfHeightRequest)
returns (QuerySettledOrderbookParticipationsOfHeightResponse) {
returns (QuerySettledOrderBookParticipationsOfHeightResponse) {
option (google.api.http).get =
"/sge/orderbook/participations/settled/{block_height}";
}
Expand Down Expand Up @@ -320,9 +320,9 @@ message QuerySettledOrderBookParticipationsOfHeightRequest {
int64 block_height = 2;
}

// QuerySettledOrderbookParticipationsOfHeightResponse is the response type for
// QuerySettledOrderBookParticipationsOfHeightResponse is the response type for
// the settled orderbook participations of a certain height list query.
message QuerySettledOrderbookParticipationsOfHeightResponse {
message QuerySettledOrderBookParticipationsOfHeightResponse {
repeated OrderBookParticipation participations = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand Down
10 changes: 10 additions & 0 deletions proto/sge/subaccount/balance.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,13 @@ message LockedBalance {
(gogoproto.nullable) = false
];
}

// LockedBalanceStatus type.
enum LockedBalanceStatus {
// the invalid or unknown
LOCKED_BALANCE_STATUS_UNSPECIFIED = 0;
// locked
LOCKED_BALANCE_STATUS_LOCKED = 1;
// unlocked
LOCKED_BALANCE_STATUS_UNLOCKED = 2;
}
6 changes: 6 additions & 0 deletions proto/sge/subaccount/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ message QuerySubaccountResponse {
sge.subaccount.AccountSummary balance = 2 [ (gogoproto.nullable) = false ];
repeated sge.subaccount.LockedBalance locked_balance = 3
[ (gogoproto.nullable) = false ];
repeated sge.subaccount.LockedBalance unlocked_balance = 4
[ (gogoproto.nullable) = false ];
string withdrawable_unlocked_balance = 5 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}
4 changes: 2 additions & 2 deletions x/orderbook/keeper/grpc_query_participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ func (k Keeper) OrderBookParticipations(
}, nil
}

// SettledOrderbookParticipationsOfHeight returns settled orderbook participations of a certain height
func (k Keeper) SettledOrderbookParticipationsOfHeight(
// SettledOrderBookParticipationsOfHeight returns settled orderbook participations of a certain height
func (k Keeper) SettledOrderBookParticipationsOfHeight(
c context.Context,
req *types.QuerySettledOrderBookParticipationsOfHeightRequest,
) (*types.QuerySettledOrderBookParticipationsOfHeightResponse, error) {
Expand Down
111 changes: 59 additions & 52 deletions x/orderbook/types/participation.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 977c6da

Please sign in to comment.