From 41c9231c15725e9985fd773d68d08c764904c58f Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 2 Nov 2023 08:06:41 +0100 Subject: [PATCH] feat: added update collateral to genesis export and loads for test and network migration --- proto/nibiru/perp/v2/genesis.proto | 9 +- x/common/testutil/genesis/perp_genesis.go | 1 + x/perp/v2/client/cli/cli_test.go | 24 ++-- x/perp/v2/module/genesis.go | 9 ++ x/perp/v2/module/genesis_test.go | 2 + x/perp/v2/types/genesis.pb.go | 150 +++++++++++++++------- x/perp/v2/types/genesis_test.go | 1 + 7 files changed, 137 insertions(+), 59 deletions(-) diff --git a/proto/nibiru/perp/v2/genesis.proto b/proto/nibiru/perp/v2/genesis.proto index 66ca0a8a8..71ccab80e 100644 --- a/proto/nibiru/perp/v2/genesis.proto +++ b/proto/nibiru/perp/v2/genesis.proto @@ -2,9 +2,9 @@ syntax = "proto3"; package nibiru.perp.v2; -import "gogoproto/gogo.proto"; -import "google/api/annotations.proto"; import "cosmos/base/v1beta1/coin.proto"; +import "google/api/annotations.proto"; +import "gogoproto/gogo.proto"; import "nibiru/perp/v2/state.proto"; option go_package = "github.com/NibiruChain/nibiru/x/perp/v2/types"; @@ -23,7 +23,7 @@ message GenesisState { [ (gogoproto.nullable) = false ]; uint64 dnr_epoch = 6; - + message TraderVolume { string trader = 1; uint64 epoch = 2; @@ -31,7 +31,10 @@ message GenesisState { (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false ]; + + // For testing purpose, we allow the collateral to be set at genesis } + Collateral collateral = 11; repeated TraderVolume trader_volumes = 7 [ (gogoproto.nullable) = false ]; diff --git a/x/common/testutil/genesis/perp_genesis.go b/x/common/testutil/genesis/perp_genesis.go index a15bb4f76..0c84e9dc4 100644 --- a/x/common/testutil/genesis/perp_genesis.go +++ b/x/common/testutil/genesis/perp_genesis.go @@ -122,6 +122,7 @@ func AddPerpV2Genesis(gen app.GenesisState) app.GenesisState { Amms: ammsv2, Positions: []perpv2types.GenesisPosition{}, ReserveSnapshots: []perpv2types.ReserveSnapshot{}, + Collateral: &perpv2types.DefaultTestingCollateralNotForProd, } gen[perpv2types.ModuleName] = app.MakeEncodingConfig().Marshaler. diff --git a/x/perp/v2/client/cli/cli_test.go b/x/perp/v2/client/cli/cli_test.go index 55fca13da..2d4d53c88 100644 --- a/x/perp/v2/client/cli/cli_test.go +++ b/x/perp/v2/client/cli/cli_test.go @@ -90,7 +90,7 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.NewCoins( sdk.NewInt64Coin(denoms.NIBI, 10e6), sdk.NewInt64Coin(denoms.USDC, 1e3*common.TO_MICRO), - sdk.NewInt64Coin(denoms.NUSD, 5e3*common.TO_MICRO), + sdk.NewInt64Coin(types.DefaultTestingCollateralNotForProd.GetTFDenom(), 5e3*common.TO_MICRO), ), val, denoms.NIBI, @@ -486,14 +486,14 @@ func (s *IntegrationTestSuite) TestRemoveMargin() { s.T().Log("removing margin on user 0....") _, err = s.network.ExecTxCmd(cli.RemoveMarginCmd(), s.users[0], []string{ asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - fmt.Sprintf("%s%s", "10000000", denoms.NUSD), + fmt.Sprintf("%s%s", "10000000", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }) s.Contains(err.Error(), types.ErrBadDebt.Error()) s.T().Log("removing margin on user 0....") _, err = s.network.ExecTxCmd(cli.RemoveMarginCmd(), s.users[0], []string{ asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - fmt.Sprintf("%s%s", "1", denoms.NUSD), + fmt.Sprintf("%s%s", "1", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }) s.NoError(err) s.NoError(s.network.WaitForNextBlock()) @@ -524,7 +524,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { name: "PASS: add margin to correct position", args: []string{ asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectedCode: 0, expectedMargin: sdk.NewDec(1_010_000), @@ -534,7 +534,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { name: "fail: position not found", args: []string{ asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectedCode: types.ErrPositionNotFound.ABCICode(), expectFail: false, @@ -559,7 +559,7 @@ func (s *IntegrationTestSuite) TestX_AddMargin() { name: "fail: invalid pair", args: []string{ "alisdhjal;dhao;sdh", - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectFail: true, }, @@ -626,7 +626,7 @@ func (s *IntegrationTestSuite) TestX_RemoveMargin() { name: "PASS: remove margin to correct position", args: []string{ asset.Registry.Pair(denoms.ETH, denoms.NUSD).String(), - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectedCode: 0, expectedMargin: sdk.NewDec(990_000), @@ -636,7 +636,7 @@ func (s *IntegrationTestSuite) TestX_RemoveMargin() { name: "fail: position not found", args: []string{ asset.Registry.Pair(denoms.BTC, denoms.NUSD).String(), - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectedCode: types.ErrPositionNotFound.ABCICode(), expectFail: false, @@ -661,7 +661,7 @@ func (s *IntegrationTestSuite) TestX_RemoveMargin() { name: "fail: invalid pair", args: []string{ "alisdhjal;dhao;sdh", - fmt.Sprintf("10000%s", denoms.NUSD), + fmt.Sprintf("10000%s", types.DefaultTestingCollateralNotForProd.GetTFDenom()), }, expectFail: true, }, @@ -704,7 +704,7 @@ func (s *IntegrationTestSuite) TestDonateToEcosystemFund() { out, err := s.network.ExecTxCmd( cli.DonateToEcosystemFundCmd(), sdk.MustAccAddressFromBech32("nibi1w89pf5yq8ntjg89048qmtaz929fdxup0a57d8m"), - []string{"100unusd"}, + []string{"100" + types.DefaultTestingCollateralNotForProd.GetTFDenom()}, ) s.NoError(err) s.Require().EqualValues(abcitypes.CodeTypeOK, out.Code) @@ -724,11 +724,11 @@ func (s *IntegrationTestSuite) TestDonateToEcosystemFund() { testutilcli.ExecQuery( s.network.Validators[0].ClientCtx, bankcli.GetBalancesCmd(), - []string{moduleAccountAddrPerpEF, "--denom", "unusd"}, + []string{moduleAccountAddrPerpEF, "--denom", types.DefaultTestingCollateralNotForProd.GetTFDenom()}, resp, ), ) - s.Require().EqualValues(sdk.NewInt64Coin("unusd", 100), *resp) + s.Require().EqualValues(sdk.NewInt64Coin(types.DefaultTestingCollateralNotForProd.GetTFDenom(), 100), *resp) } func (s *IntegrationTestSuite) TestQueryModuleAccount() { diff --git a/x/perp/v2/module/genesis.go b/x/perp/v2/module/genesis.go index a884058a0..732e67bbd 100644 --- a/x/perp/v2/module/genesis.go +++ b/x/perp/v2/module/genesis.go @@ -70,6 +70,10 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) customDiscount.Discount.Fee, ) } + + if genState.Collateral != nil { + k.Admin.UpdateCollateral(ctx, *&genState.Collateral.Denom, *&genState.Collateral.ContractAddress) + } } // ExportGenesis returns the capability module's exported genesis. @@ -134,5 +138,10 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { }, }) } + + collateral, err := k.Collateral.Get(ctx) + if err != nil { + genesis.Collateral = &collateral + } return genesis } diff --git a/x/perp/v2/module/genesis_test.go b/x/perp/v2/module/genesis_test.go index d2092f218..742e217ae 100644 --- a/x/perp/v2/module/genesis_test.go +++ b/x/perp/v2/module/genesis_test.go @@ -68,6 +68,7 @@ func RunTestGenesis(t *testing.T, tc TestCase) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) // create some params + app.PerpKeeperV2.Admin.UpdateCollateral(ctx, "unusd", types.DefaultTestingCollateralNotForProd.ContractAddress) app.PerpKeeperV2.SaveMarket(ctx, *mock.TestMarket()) app.PerpKeeperV2.MarketLastVersion.Insert(ctx, pair, types.MarketLastVersion{Version: 1}) app.PerpKeeperV2.SaveAMM(ctx, *mock.TestAMMDefault()) @@ -118,6 +119,7 @@ func RunTestGenesis(t *testing.T, tc TestCase) { require.Equal(t, genState.CustomDiscounts, genStateAfterInit.CustomDiscounts) require.Equal(t, genState.GlobalDiscount, genStateAfterInit.GlobalDiscount) require.Equal(t, genState.TraderVolumes, genStateAfterInit.TraderVolumes) + require.Equal(t, genState.Collateral, genStateAfterInit.Collateral) } func TestNewAppModuleBasic(t *testing.T) { diff --git a/x/perp/v2/types/genesis.pb.go b/x/perp/v2/types/genesis.pb.go index aacf854cc..e6ad875bc 100644 --- a/x/perp/v2/types/genesis.pb.go +++ b/x/perp/v2/types/genesis.pb.go @@ -36,6 +36,7 @@ type GenesisState struct { Positions []GenesisPosition `protobuf:"bytes,4,rep,name=positions,proto3" json:"positions"` ReserveSnapshots []ReserveSnapshot `protobuf:"bytes,5,rep,name=reserve_snapshots,json=reserveSnapshots,proto3" json:"reserve_snapshots"` DnrEpoch uint64 `protobuf:"varint,6,opt,name=dnr_epoch,json=dnrEpoch,proto3" json:"dnr_epoch,omitempty"` + Collateral *Collateral `protobuf:"bytes,11,opt,name=collateral,proto3" json:"collateral,omitempty"` TraderVolumes []GenesisState_TraderVolume `protobuf:"bytes,7,rep,name=trader_volumes,json=traderVolumes,proto3" json:"trader_volumes"` GlobalDiscount []GenesisState_Discount `protobuf:"bytes,8,rep,name=global_discount,json=globalDiscount,proto3" json:"global_discount"` CustomDiscounts []GenesisState_CustomDiscount `protobuf:"bytes,9,rep,name=custom_discounts,json=customDiscounts,proto3" json:"custom_discounts"` @@ -110,6 +111,13 @@ func (m *GenesisState) GetDnrEpoch() uint64 { return 0 } +func (m *GenesisState) GetCollateral() *Collateral { + if m != nil { + return m.Collateral + } + return nil +} + func (m *GenesisState) GetTraderVolumes() []GenesisState_TraderVolume { if m != nil { return m.TraderVolumes @@ -393,50 +401,52 @@ func init() { func init() { proto.RegisterFile("nibiru/perp/v2/genesis.proto", fileDescriptor_c2c7acfef3993fde) } var fileDescriptor_c2c7acfef3993fde = []byte{ - // 678 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xdf, 0x6a, 0x13, 0x4d, - 0x14, 0xcf, 0x36, 0x69, 0x9a, 0x4c, 0xfb, 0xa5, 0xfd, 0xc6, 0x52, 0x96, 0x58, 0xd2, 0x52, 0x50, - 0x22, 0xd2, 0x1d, 0x1a, 0x41, 0xd0, 0x2b, 0x9b, 0x56, 0x8b, 0x60, 0xa4, 0x6c, 0x4b, 0x2f, 0x44, - 0x88, 0x93, 0xcd, 0xb8, 0x59, 0x9a, 0x9d, 0x59, 0xe6, 0x4c, 0x82, 0x5e, 0xeb, 0x03, 0x78, 0xe1, - 0x23, 0xf8, 0x0c, 0x3e, 0x43, 0x2f, 0x7b, 0x29, 0x5e, 0x14, 0x69, 0x5f, 0x44, 0x76, 0x66, 0x12, - 0x93, 0xc5, 0x54, 0x45, 0xf0, 0x2a, 0x99, 0x39, 0xbf, 0x3f, 0x67, 0xce, 0x39, 0x7b, 0xd0, 0x3a, - 0x8f, 0x3a, 0x91, 0x1c, 0x90, 0x84, 0xc9, 0x84, 0x0c, 0x1b, 0x24, 0x64, 0x9c, 0x41, 0x04, 0x5e, - 0x22, 0x85, 0x12, 0xb8, 0x62, 0xa2, 0x5e, 0x1a, 0xf5, 0x86, 0x8d, 0xea, 0x6a, 0x28, 0x42, 0xa1, - 0x43, 0x24, 0xfd, 0x67, 0x50, 0xd5, 0xf5, 0x50, 0x88, 0xb0, 0xcf, 0x08, 0x4d, 0x22, 0x42, 0x39, - 0x17, 0x8a, 0xaa, 0x48, 0x70, 0xab, 0x51, 0xad, 0x05, 0x02, 0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xad, 0xb9, 0xbf, 0x4a, 0xeb, 0x14, 0x55, 0xa6, - 0x1b, 0x35, 0xb3, 0x3c, 0xbb, 0xa8, 0x34, 0x1e, 0xab, 0xd4, 0xf3, 0x77, 0xc7, 0xca, 0x1f, 0xd3, - 0xb6, 0xde, 0x39, 0xc8, 0x9d, 0xd5, 0x41, 0xdc, 0x42, 0x85, 0x84, 0x46, 0xd6, 0xb5, 0xf9, 0xc0, - 0xbe, 0x67, 0x67, 0xe2, 0x3d, 0xcf, 0xb5, 0xdb, 0x5e, 0x8f, 0x46, 0x9c, 0xd8, 0x65, 0xf4, 0x86, - 0x04, 0x22, 0x8e, 0x05, 0x27, 0x14, 0x80, 0x29, 0xef, 0x90, 0x46, 0xd2, 0xd7, 0x32, 0xd8, 0x45, - 0x0b, 0x76, 0x98, 0x6c, 0x3f, 0x47, 0xc7, 0xad, 0xcf, 0x0e, 0x5a, 0xce, 0x2c, 0x85, 0x7f, 0x66, - 0x8e, 0x1f, 0xa2, 0xd2, 0x68, 0xf3, 0xe8, 0x81, 0x5a, 0x6c, 0xb8, 0xd9, 0x2a, 0x66, 0x36, 0xd5, - 0x18, 0xdf, 0x3c, 0x38, 0xbb, 0xac, 0x39, 0xe7, 0x97, 0x35, 0xe7, 0xdb, 0x65, 0xcd, 0xf9, 0x70, - 0x55, 0xcb, 0x9d, 0x5f, 0xd5, 0x72, 0x5f, 0xae, 0x6a, 0xb9, 0x17, 0xdb, 0xbf, 0x4a, 0x74, 0xb4, - 0xb4, 0xf5, 0x00, 0x74, 0x8a, 0x7a, 0x6b, 0xdf, 0xfb, 0x1e, 0x00, 0x00, 0xff, 0xff, 0x86, 0x40, - 0x11, 0x89, 0x55, 0x06, 0x00, 0x00, + // 705 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x54, 0xd1, 0x6a, 0x13, 0x4d, + 0x14, 0xce, 0x26, 0x69, 0x9a, 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0x4a, 0xdb, 0x7e, 0x6f, 0x21, 0x7b, 0x51, + 0x07, 0x71, 0x07, 0xe5, 0x63, 0xea, 0x9b, 0xac, 0xad, 0x47, 0xe6, 0x3d, 0xbb, 0x33, 0xef, 0x79, + 0xa1, 0xb2, 0xb5, 0x87, 0xd4, 0x8f, 0x88, 0x59, 0x64, 0x6f, 0x89, 0xc7, 0xc3, 0x90, 0x47, 0x84, + 0x02, 0x30, 0xe9, 0x1c, 0x51, 0x5f, 0xb8, 0x4a, 0x06, 0xdb, 0x68, 0xd9, 0x0c, 0x93, 0xe9, 0xe7, + 0xe4, 0xb8, 0xfd, 0xd9, 0x42, 0xab, 0xa9, 0x85, 0xf2, 0xd7, 0x92, 0xe3, 0x3d, 0x54, 0x9c, 0x6c, + 0x2d, 0x35, 0x50, 0xe5, 0xa6, 0x9d, 0xae, 0x62, 0x6a, 0xcb, 0x4d, 0xf1, 0xad, 0xc3, 0xf3, 0xeb, + 0x9a, 0x75, 0x71, 0x5d, 0xb3, 0xae, 0xae, 0x6b, 0xd6, 0xc7, 0x9b, 0x5a, 0xe6, 0xe2, 0xa6, 0x96, + 0xf9, 0x72, 0x53, 0xcb, 0xbc, 0xdc, 0xf9, 0x99, 0xd1, 0xc9, 0xc2, 0x57, 0x03, 0xd0, 0x2b, 0xa8, + 0x8d, 0xff, 0xe0, 0x5b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x58, 0xc1, 0x9e, 0x75, 0x91, 0x06, 0x00, + 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -459,6 +469,18 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Collateral != nil { + { + size, err := m.Collateral.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x5a + } if len(m.MarketLastVersions) > 0 { for iNdEx := len(m.MarketLastVersions) - 1; iNdEx >= 0; iNdEx-- { { @@ -863,6 +885,10 @@ func (m *GenesisState) Size() (n int) { n += 1 + l + sovGenesis(uint64(l)) } } + if m.Collateral != nil { + l = m.Collateral.Size() + n += 1 + l + sovGenesis(uint64(l)) + } return n } @@ -1270,6 +1296,42 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 11: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Collateral", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Collateral == nil { + m.Collateral = &Collateral{} + } + if err := m.Collateral.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/perp/v2/types/genesis_test.go b/x/perp/v2/types/genesis_test.go index eac7b2810..53c77a50b 100644 --- a/x/perp/v2/types/genesis_test.go +++ b/x/perp/v2/types/genesis_test.go @@ -25,6 +25,7 @@ func TestDefaultGenesis(t *testing.T) { require.Empty(t, genesis.Amms) require.Empty(t, genesis.Positions) require.Empty(t, genesis.ReserveSnapshots) + require.Empty(t, genesis.Collateral) } func TestGenesisValidate(t *testing.T) {