Skip to content

Commit

Permalink
[Perpetual]: Remove toPay storage and code (#966)
Browse files Browse the repository at this point in the history
remove topay
  • Loading branch information
amityadav0 authored Nov 20, 2024
1 parent 1dc7e6e commit 0b231d2
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 1,077 deletions.
10 changes: 0 additions & 10 deletions proto/elys/perpetual/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,6 @@ service Query {
"/elys-network/elys/perpetual/open-estimation";
}

// Queries a list of GetAllToPay items.
rpc GetAllToPay(QueryGetAllToPayRequest) returns (QueryGetAllToPayResponse) {
option (google.api.http).get =
"/elys-network/elys/perpetual/get_all_to_pay";
}

// Queries a list of CloseEstimation items.
rpc CloseEstimation(QueryCloseEstimationRequest)
returns (QueryCloseEstimationResponse) {
Expand Down Expand Up @@ -320,10 +314,6 @@ message QueryOpenEstimationResponse {
];
}

message QueryGetAllToPayRequest {}

message QueryGetAllToPayResponse { repeated ToPay to_pay = 1; }

message PoolResponse {
uint64 amm_pool_id = 1;
string health = 2 [
Expand Down
11 changes: 0 additions & 11 deletions proto/elys/perpetual/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,6 @@ message FundingRateBlock {
int64 block_time = 6;
}

message ToPay {
string asset_balance = 1 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string asset_denom = 2;
string address = 3;
uint64 id = 4;
}

message WhiteList { repeated string validator_list = 1; }

message PositionRequest {
Expand Down
2 changes: 0 additions & 2 deletions x/perpetual/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdMtp())
cmd.AddCommand(CmdOpenEstimation())

cmd.AddCommand(CmdGetAllToPay())

cmd.AddCommand(CmdCloseEstimation())

// this line is used by starport scaffolding # 1
Expand Down
42 changes: 0 additions & 42 deletions x/perpetual/client/cli/query_get_all_to_pay.go

This file was deleted.

33 changes: 6 additions & 27 deletions x/perpetual/keeper/mtp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package keeper

import (
"fmt"

"cosmossdk.io/math"
"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
"fmt"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/query"
Expand Down Expand Up @@ -279,37 +280,15 @@ func (k Keeper) GetOpenMTPCount(ctx sdk.Context) uint64 {
return count
}

func (k Keeper) SetToPay(ctx sdk.Context, toPay *types.ToPay) error {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
address := sdk.MustAccAddressFromBech32(toPay.Address)

key := types.GetToPayKey(address, toPay.Id)
store.Set(key, k.cdc.MustMarshal(toPay))
return nil
}

func (k Keeper) GetAllToPayStore(ctx sdk.Context) []types.ToPay {
var toPays []types.ToPay
// Delete all to pay if any
func (k Keeper) DeleteAllToPay(ctx sdk.Context) error {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
iterator := storetypes.KVStorePrefixIterator(store, types.ToPayPrefix)
iterator := storetypes.KVStorePrefixIterator(store, []byte{0x09})
defer iterator.Close()

for ; iterator.Valid(); iterator.Next() {
var toPay types.ToPay
bytesValue := iterator.Value()
k.cdc.MustUnmarshal(bytesValue, &toPay)
toPays = append(toPays, toPay)
store.Delete(iterator.Key())
}
return toPays
}

func (k Keeper) DeleteToPay(ctx sdk.Context, address sdk.AccAddress, id uint64) error {
store := runtime.KVStoreAdapter(k.storeService.OpenKVStore(ctx))
key := types.GetToPayKey(address, id)
if !store.Has(key) {
return types.ErrToPayDoesNotExist
}
store.Delete(key)
return nil
}

Expand Down
29 changes: 0 additions & 29 deletions x/perpetual/keeper/query_get_all_to_pay.go

This file was deleted.

21 changes: 0 additions & 21 deletions x/perpetual/keeper/query_get_all_to_pay_test.go

This file was deleted.

10 changes: 10 additions & 0 deletions x/perpetual/migrations/v13_migration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package migrations

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

func (m Migrator) V13Migration(ctx sdk.Context) error {
m.keeper.DeleteAllToPay(ctx)
return nil
}
7 changes: 4 additions & 3 deletions x/perpetual/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package perpetual

import (
"context"
"cosmossdk.io/core/appmodule"
"encoding/json"
"fmt"

"cosmossdk.io/core/appmodule"

// this line is used by starport scaffolding # 1

"github.com/grpc-ecosystem/grpc-gateway/runtime"
Expand Down Expand Up @@ -124,7 +125,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 11, m.V12Migration)
err := cfg.RegisterMigration(types.ModuleName, 12, m.V13Migration)
if err != nil {
panic(err)
}
Expand All @@ -151,7 +152,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
}

// ConsensusVersion is a sequence number for state-breaking change of the module. It should be incremented on each consensus-breaking change introduced by the module. To avoid wrong/empty versions, the initial version should be set to 1
func (AppModule) ConsensusVersion() uint64 { return 12 }
func (AppModule) ConsensusVersion() uint64 { return 13 }

// BeginBlock contains the logic that is automatically triggered at the beginning of each block
func (am AppModule) BeginBlock(gotCtx context.Context) error {
Expand Down
3 changes: 1 addition & 2 deletions x/perpetual/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ var (
ErrInvalidAmount = errorsmod.Register(ModuleName, 40, "invalid amount")
ErrInvalidPrice = errorsmod.Register(ModuleName, 41, "error invalid price ")
ErrPoolHasToBeOracle = errorsmod.Register(ModuleName, 42, "pool has to be oracle enabled")
ErrToPayDoesNotExist = errorsmod.Register(ModuleName, 43, "to pay does not exist")
ErrZeroCustodyAmount = errorsmod.Register(ModuleName, 44, "Custody amount is zero")
ErrZeroCustodyAmount = errorsmod.Register(ModuleName, 43, "Custody amount is zero")
)
8 changes: 2 additions & 6 deletions x/perpetual/types/keys.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package types

import (
"cosmossdk.io/math"
"encoding/binary"

"cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/address"
)
Expand Down Expand Up @@ -42,7 +43,6 @@ var (

InterestRatePrefix = []byte{0x07}
FundingRatePrefix = []byte{0x08}
ToPayPrefix = []byte{0x09}
)

func KeyPrefix(p string) []byte {
Expand Down Expand Up @@ -89,7 +89,3 @@ func GetInterestRateKey(block uint64, pool uint64) []byte {
func GetFundingRateKey(block uint64, pool uint64) []byte {
return append(GetUint64Bytes(block), GetUint64Bytes(pool)...)
}

func GetToPayKey(addr sdk.AccAddress, id uint64) []byte {
return append(ToPayPrefix, append(address.MustLengthPrefix(addr), sdk.Uint64ToBigEndian(id)...)...)
}
Loading

0 comments on commit 0b231d2

Please sign in to comment.