From 02d7e0bc0d5b744fb9fe96352a665b0bd77d11b6 Mon Sep 17 00:00:00 2001 From: Matthias <97468149+matthiasmatt@users.noreply.github.com> Date: Fri, 29 Dec 2023 19:52:48 +0100 Subject: [PATCH 1/7] feat(oracle): Add more events on validator's performance (#1755) * feat: add more events to the oracle * chore: changelog --- CHANGELOG.md | 1 + proto/nibiru/oracle/v1/event.proto | 22 ++ x/oracle/keeper/update_exchange_rates.go | 12 + x/oracle/types/event.pb.go | 412 +++++++++++++++++++++-- 4 files changed, 420 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0132dcdcd..b0b9d6f23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price * [#1705](https://github.com/NibiruChain/nibiru/pull/1705) - feat(perp): Add oracle pair to market object * [#1718](https://github.com/NibiruChain/nibiru/pull/1718) - fix: fees does not require additional funds +* [#1755](https://github.com/NibiruChain/nibiru/pull/1755) - feat(oracle): Add more events on validator's performance ### Non-breaking/Compatible Improvements diff --git a/proto/nibiru/oracle/v1/event.proto b/proto/nibiru/oracle/v1/event.proto index f9dda8853..82284e9b1 100644 --- a/proto/nibiru/oracle/v1/event.proto +++ b/proto/nibiru/oracle/v1/event.proto @@ -53,3 +53,25 @@ message EventAggregatePrevote { // transaction messages on behalf of the voting validator. string feeder = 2; } + + +message EventValidatorPerformance{ + // Validator is the Bech32 address to which the vote will be credited. + string validator = 1; + + // Tendermint consensus voting power + int64 voting_power = 2; + + // RewardWeight: Weight of rewards the validator should receive in units of + // consensus power. + int64 reward_weight = 3; + + // Number of valid votes for which the validator will be rewarded + int64 win_count = 4; + + // Number of abstained votes for which there will be no reward or punishment + int64 abstain_count = 5; + + // Number of invalid/punishable votes + int64 miss_count = 6; +} \ No newline at end of file diff --git a/x/oracle/keeper/update_exchange_rates.go b/x/oracle/keeper/update_exchange_rates.go index 99a1251b1..dff65f9dc 100644 --- a/x/oracle/keeper/update_exchange_rates.go +++ b/x/oracle/keeper/update_exchange_rates.go @@ -30,6 +30,18 @@ func (k Keeper) UpdateExchangeRates(ctx sdk.Context) types.ValidatorPerformances params, _ := k.Params.Get(ctx) k.clearVotesAndPrevotes(ctx, params.VotePeriod) k.refreshWhitelist(ctx, params.Whitelist, whitelistedPairs) + + for _, validatorPerformance := range validatorPerformances { + _ = ctx.EventManager().EmitTypedEvent(&types.EventValidatorPerformance{ + Validator: validatorPerformance.ValAddress.String(), + VotingPower: validatorPerformance.Power, + RewardWeight: validatorPerformance.RewardWeight, + WinCount: validatorPerformance.WinCount, + AbstainCount: validatorPerformance.AbstainCount, + MissCount: validatorPerformance.MissCount, + }) + } + return validatorPerformances } diff --git a/x/oracle/types/event.pb.go b/x/oracle/types/event.pb.go index 085a6c8ef..fb48c177f 100644 --- a/x/oracle/types/event.pb.go +++ b/x/oracle/types/event.pb.go @@ -256,43 +256,141 @@ func (m *EventAggregatePrevote) GetFeeder() string { return "" } +type EventValidatorPerformance struct { + // Validator is the Bech32 address to which the vote will be credited. + Validator string `protobuf:"bytes,1,opt,name=validator,proto3" json:"validator,omitempty"` + // Tendermint consensus voting power + VotingPower int64 `protobuf:"varint,2,opt,name=voting_power,json=votingPower,proto3" json:"voting_power,omitempty"` + // RewardWeight: Weight of rewards the validator should receive in units of + // consensus power. + RewardWeight int64 `protobuf:"varint,3,opt,name=reward_weight,json=rewardWeight,proto3" json:"reward_weight,omitempty"` + // Number of valid votes for which the validator will be rewarded + WinCount int64 `protobuf:"varint,4,opt,name=win_count,json=winCount,proto3" json:"win_count,omitempty"` + // Number of abstained votes for which there will be no reward or punishment + AbstainCount int64 `protobuf:"varint,5,opt,name=abstain_count,json=abstainCount,proto3" json:"abstain_count,omitempty"` + // Number of invalid/punishable votes + MissCount int64 `protobuf:"varint,6,opt,name=miss_count,json=missCount,proto3" json:"miss_count,omitempty"` +} + +func (m *EventValidatorPerformance) Reset() { *m = EventValidatorPerformance{} } +func (m *EventValidatorPerformance) String() string { return proto.CompactTextString(m) } +func (*EventValidatorPerformance) ProtoMessage() {} +func (*EventValidatorPerformance) Descriptor() ([]byte, []int) { + return fileDescriptor_94ec441b793fc0ea, []int{4} +} +func (m *EventValidatorPerformance) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventValidatorPerformance) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventValidatorPerformance.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventValidatorPerformance) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventValidatorPerformance.Merge(m, src) +} +func (m *EventValidatorPerformance) XXX_Size() int { + return m.Size() +} +func (m *EventValidatorPerformance) XXX_DiscardUnknown() { + xxx_messageInfo_EventValidatorPerformance.DiscardUnknown(m) +} + +var xxx_messageInfo_EventValidatorPerformance proto.InternalMessageInfo + +func (m *EventValidatorPerformance) GetValidator() string { + if m != nil { + return m.Validator + } + return "" +} + +func (m *EventValidatorPerformance) GetVotingPower() int64 { + if m != nil { + return m.VotingPower + } + return 0 +} + +func (m *EventValidatorPerformance) GetRewardWeight() int64 { + if m != nil { + return m.RewardWeight + } + return 0 +} + +func (m *EventValidatorPerformance) GetWinCount() int64 { + if m != nil { + return m.WinCount + } + return 0 +} + +func (m *EventValidatorPerformance) GetAbstainCount() int64 { + if m != nil { + return m.AbstainCount + } + return 0 +} + +func (m *EventValidatorPerformance) GetMissCount() int64 { + if m != nil { + return m.MissCount + } + return 0 +} + func init() { proto.RegisterType((*EventPriceUpdate)(nil), "nibiru.oracle.v1.EventPriceUpdate") proto.RegisterType((*EventDelegateFeederConsent)(nil), "nibiru.oracle.v1.EventDelegateFeederConsent") proto.RegisterType((*EventAggregateVote)(nil), "nibiru.oracle.v1.EventAggregateVote") proto.RegisterType((*EventAggregatePrevote)(nil), "nibiru.oracle.v1.EventAggregatePrevote") + proto.RegisterType((*EventValidatorPerformance)(nil), "nibiru.oracle.v1.EventValidatorPerformance") } func init() { proto.RegisterFile("nibiru/oracle/v1/event.proto", fileDescriptor_94ec441b793fc0ea) } var fileDescriptor_94ec441b793fc0ea = []byte{ - // 407 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0xcd, 0x8e, 0xd3, 0x30, - 0x14, 0x85, 0x63, 0x0a, 0x95, 0xc6, 0xc3, 0x62, 0x64, 0x01, 0xaa, 0xa2, 0x92, 0x0e, 0x41, 0x42, - 0x5d, 0x80, 0xad, 0x81, 0x27, 0xa0, 0xd3, 0x99, 0xdd, 0xa0, 0x51, 0xc4, 0x8f, 0xc4, 0x06, 0xb9, - 0xc9, 0xc5, 0xb5, 0x48, 0x6c, 0xcb, 0x76, 0xa3, 0xe1, 0x29, 0xe0, 0x1d, 0xd8, 0xf1, 0x24, 0xb3, - 0xec, 0x12, 0xb1, 0x28, 0xa8, 0x7d, 0x11, 0x14, 0x27, 0xe5, 0xaf, 0xbb, 0xae, 0x72, 0x73, 0xce, - 0xf5, 0xc9, 0x17, 0xdf, 0x8b, 0x87, 0x4a, 0xce, 0xa4, 0x5d, 0x30, 0x6d, 0x79, 0x5e, 0x02, 0xab, - 0x4f, 0x18, 0xd4, 0xa0, 0x3c, 0x35, 0x56, 0x7b, 0x4d, 0x8e, 0x5a, 0x97, 0xb6, 0x2e, 0xad, 0x4f, - 0xe2, 0xfb, 0x3b, 0xfd, 0x9d, 0x17, 0x0e, 0xc4, 0x77, 0x84, 0x16, 0x3a, 0x94, 0xac, 0xa9, 0x3a, - 0x75, 0x28, 0xb4, 0x16, 0x25, 0x30, 0x6e, 0x24, 0xe3, 0x4a, 0x69, 0xcf, 0xbd, 0xd4, 0xca, 0xb5, - 0x6e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e, 0xbe, 0xfe, 0x18, 0x91, 0x1d, 0xcb, 0x65, 0x5d, 0x5c, - 0x7a, 0x81, 0xef, 0xfe, 0x0b, 0x79, 0x69, 0xa1, 0xde, 0x9b, 0x73, 0x72, 0x7e, 0xbd, 0x4e, 0xd0, - 0x72, 0x9d, 0xa0, 0x9f, 0xeb, 0x04, 0x7d, 0xde, 0x24, 0xd1, 0x72, 0x93, 0x44, 0xdf, 0x36, 0x49, - 0xf4, 0xf6, 0xf1, 0x5f, 0x43, 0x7b, 0x11, 0xd8, 0x4f, 0xe7, 0x5c, 0x2a, 0xd6, 0xad, 0xd7, 0xd5, - 0x76, 0xc1, 0xc2, 0xf8, 0x66, 0xfd, 0xb0, 0x29, 0xcf, 0x7e, 0x05, 0x00, 0x00, 0xff, 0xff, 0x3b, - 0xea, 0x2b, 0x3c, 0xae, 0x02, 0x00, 0x00, + // 510 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0x6e, 0xe8, 0x56, 0x51, 0xb7, 0x48, 0x93, 0x05, 0xa8, 0x94, 0x2e, 0xdd, 0x3a, 0x09, 0xf5, + 0x02, 0x12, 0x0d, 0x9e, 0x80, 0xb6, 0xdb, 0xdd, 0x50, 0x15, 0xc1, 0x26, 0x71, 0x53, 0xb9, 0xc9, + 0x99, 0x6b, 0x91, 0xd8, 0x91, 0xed, 0x26, 0xe3, 0x29, 0xe0, 0x1d, 0xb8, 0xe3, 0x49, 0x76, 0xb9, + 0x4b, 0xc4, 0xc5, 0x40, 0xed, 0x8b, 0x20, 0x3b, 0xee, 0xf8, 0xd9, 0x05, 0xd2, 0xae, 0x72, 0xfc, + 0x7d, 0x9f, 0xbf, 0x7c, 0xc9, 0x39, 0x07, 0xf5, 0x38, 0x9b, 0x33, 0xb9, 0x0c, 0x85, 0x24, 0x71, + 0x0a, 0x61, 0x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 0xc8, 0x9d, 0x06, 0x5f, 0x3c, 0x84, 0xad, + 0xe9, 0x6b, 0x4a, 0xa5, 0x75, 0x3d, 0x15, 0x1a, 0xee, 0x66, 0x86, 0xcf, 0x50, 0xc3, 0x7e, 0x8c, + 0x49, 0x5f, 0x1f, 0xb6, 0x5e, 0x1e, 0x04, 0xff, 0x36, 0x2a, 0x38, 0xba, 0x88, 0x17, 0x84, 0x53, + 0x88, 0x88, 0x86, 0xb7, 0xcb, 0x3c, 0x85, 0x51, 0xd7, 0xfc, 0xaf, 0xaf, 0x3f, 0xfa, 0xf8, 0x16, + 0xa5, 0x22, 0x67, 0x37, 0x38, 0x41, 0x8f, 0xfe, 0x0e, 0x39, 0x95, 0x50, 0xdc, 0x39, 0xe7, 0x60, + 0xe5, 0xa1, 0x27, 0xd6, 0xef, 0x74, 0x23, 0x9d, 0x82, 0x3c, 0x17, 0x32, 0x23, 0x3c, 0xfe, 0x9f, + 0xe7, 0x3e, 0x6a, 0x17, 0x42, 0x33, 0x4e, 0x67, 0xb9, 0x28, 0x9d, 0x73, 0x3d, 0x6a, 0x55, 0xd8, + 0xd4, 0x40, 0xf8, 0x00, 0x3d, 0x90, 0x50, 0x12, 0x99, 0xcc, 0x4a, 0x60, 0x74, 0xa1, 0x5d, 0x2f, + 0xdb, 0x15, 0x78, 0x66, 0x31, 0xfc, 0x14, 0x35, 0x4b, 0xc6, 0x67, 0xb1, 0x58, 0x72, 0xdd, 0xd9, + 0xb2, 0x82, 0xfb, 0x25, 0xe3, 0x63, 0x73, 0x36, 0x0e, 0x64, 0xae, 0x34, 0xb9, 0x11, 0x6c, 0x57, + 0x0e, 0x0e, 0xac, 0x44, 0xbb, 0x08, 0x65, 0x4c, 0x29, 0xa7, 0x68, 0x58, 0x45, 0xd3, 0x20, 0x96, + 0x1e, 0x1d, 0x5f, 0xae, 0x7c, 0xef, 0x6a, 0xe5, 0x7b, 0x3f, 0x57, 0xbe, 0xf7, 0x79, 0xed, 0xd7, + 0xae, 0xd6, 0x7e, 0xed, 0xdb, 0xda, 0xaf, 0xbd, 0x7f, 0xfe, 0xc7, 0x64, 0xbe, 0xb1, 0x0d, 0x1a, + 0x2f, 0x08, 0xe3, 0xa1, 0xdb, 0xa1, 0x8b, 0xcd, 0x16, 0xd9, 0x19, 0x9d, 0x37, 0xec, 0x3a, 0xbc, + 0xfa, 0x15, 0x00, 0x00, 0xff, 0xff, 0x5f, 0xd7, 0x9a, 0x89, 0x93, 0x03, 0x00, 0x00, } func (m *EventPriceUpdate) Marshal() (dAtA []byte, err error) { @@ -465,6 +563,61 @@ func (m *EventAggregatePrevote) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *EventValidatorPerformance) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventValidatorPerformance) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventValidatorPerformance) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.MissCount != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.MissCount)) + i-- + dAtA[i] = 0x30 + } + if m.AbstainCount != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.AbstainCount)) + i-- + dAtA[i] = 0x28 + } + if m.WinCount != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.WinCount)) + i-- + dAtA[i] = 0x20 + } + if m.RewardWeight != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.RewardWeight)) + i-- + dAtA[i] = 0x18 + } + if m.VotingPower != 0 { + i = encodeVarintEvent(dAtA, i, uint64(m.VotingPower)) + i-- + dAtA[i] = 0x10 + } + if len(m.Validator) > 0 { + i -= len(m.Validator) + copy(dAtA[i:], m.Validator) + i = encodeVarintEvent(dAtA, i, uint64(len(m.Validator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintEvent(dAtA []byte, offset int, v uint64) int { offset -= sovEvent(v) base := offset @@ -551,6 +704,34 @@ func (m *EventAggregatePrevote) Size() (n int) { return n } +func (m *EventValidatorPerformance) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Validator) + if l > 0 { + n += 1 + l + sovEvent(uint64(l)) + } + if m.VotingPower != 0 { + n += 1 + sovEvent(uint64(m.VotingPower)) + } + if m.RewardWeight != 0 { + n += 1 + sovEvent(uint64(m.RewardWeight)) + } + if m.WinCount != 0 { + n += 1 + sovEvent(uint64(m.WinCount)) + } + if m.AbstainCount != 0 { + n += 1 + sovEvent(uint64(m.AbstainCount)) + } + if m.MissCount != 0 { + n += 1 + sovEvent(uint64(m.MissCount)) + } + return n +} + func sovEvent(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1068,6 +1249,183 @@ func (m *EventAggregatePrevote) Unmarshal(dAtA []byte) error { } return nil } +func (m *EventValidatorPerformance) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventValidatorPerformance: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventValidatorPerformance: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Validator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvent + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvent + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Validator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field VotingPower", wireType) + } + m.VotingPower = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.VotingPower |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardWeight", wireType) + } + m.RewardWeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RewardWeight |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field WinCount", wireType) + } + m.WinCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.WinCount |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AbstainCount", wireType) + } + m.AbstainCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AbstainCount |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 6: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MissCount", wireType) + } + m.MissCount = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvent + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MissCount |= int64(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipEvent(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvent + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipEvent(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From d8641fbbebcd50745d90637081c4d47b45a66e26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:37:39 +0000 Subject: [PATCH 2/7] chore(deps): Bump google.golang.org/protobuf from 1.31.0 to 1.32.0 (#1756) Bumps google.golang.org/protobuf from 1.31.0 to 1.32.0. --- updated-dependencies: - dependency-name: google.golang.org/protobuf dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> --- CHANGELOG.md | 1 + go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0b9d6f23..91129e1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Dependencies - Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) +- Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) * Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720)) * Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724)) diff --git a/go.mod b/go.mod index dc7dc715d..da87be4ec 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/stretchr/testify v1.8.4 google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 google.golang.org/grpc v1.60.0 - google.golang.org/protobuf v1.31.0 + google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/go.sum b/go.sum index d5737d783..a0e04d09c 100644 --- a/go.sum +++ b/go.sum @@ -1878,8 +1878,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From f235fe29fa5de194de6fd76a25f963061619fb2e Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:51:33 -0600 Subject: [PATCH 3/7] refactor(decode-base64): clean code improvements and fn docs (#1754) --- CHANGELOG.md | 1 + cmd/nibid/cmd/decode_base64.go | 84 ++++++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91129e1fe..13fec3c34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1723](https://github.com/NibiruChain/nibiru/pull/1723) - ci(e2e-wasm.yml): rm unused workflow * [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs * [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests +* [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs ### Dependencies - Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) diff --git a/cmd/nibid/cmd/decode_base64.go b/cmd/nibid/cmd/decode_base64.go index 968f07679..3de3706f2 100644 --- a/cmd/nibid/cmd/decode_base64.go +++ b/cmd/nibid/cmd/decode_base64.go @@ -15,18 +15,39 @@ import ( wasmvm "github.com/CosmWasm/wasmvm/types" ) -// YieldStargateMsgs parses the JSON and sends wasmvm.StargateMsg objects to a channel -func YieldStargateMsgs(jsonBz []byte) ([]wasmvm.StargateMsg, error) { +// YieldStargateMsgs takes a byte slice of JSON data and converts it into a slice +// of wasmvm.StargateMsg objects. This function is essential for processing +// JSON-formatted messages that contain base64-encoded protobuf messages. +// +// Args: +// - jsonBz []byte: A byte slice containing the JSON data to be parsed. +// +// Returns: +// - sgMsgs []wasmvm.StargateMsg: A slice of wasmvm.StargateMsg objects parsed +// from the provided JSON data. +// - err error: An error object, which is nil if the operation is successful. +func YieldStargateMsgs(jsonBz []byte) (sgMsgs []wasmvm.StargateMsg, err error) { var data interface{} if err := json.Unmarshal(jsonBz, &data); err != nil { - return nil, err + return sgMsgs, err } - var msgs []wasmvm.StargateMsg - parseStargateMsgs(data, &msgs) - return msgs, nil + parseStargateMsgs(data, &sgMsgs) + return sgMsgs, nil } +// parseStargateMsgs is a recursive function used by YieldStargateMsgs to +// traverse the JSON data, filter for any protobuf.Any messages in the +// "WasmVM.StargateMsg" format and decode them from base64 back to human-readable +// form as JSON objects. +// +// Args: +// - jsonData any: JSON data to parse. According to the JSON specification, +// possible value types are: +// Null, Bool, Number(f64), String, Array, or Object(Map) +// - msgs *[]wasmvm.StargateMsg: Mutable reference to a slice of protobuf +// messages. These are potentially altered in place if the value is an +// encoded base 64 string. func parseStargateMsgs(jsonData any, msgs *[]wasmvm.StargateMsg) { switch v := jsonData.(type) { case map[string]interface{}: @@ -48,33 +69,51 @@ func parseStargateMsgs(jsonData any, msgs *[]wasmvm.StargateMsg) { } } +// StargateMsgDecoded is a struct designed to hold a decoded version of a +// "wasmvm.StargateMsg". type StargateMsgDecoded struct { TypeURL string `json:"type_url"` Value string `json:"value"` } +// DecodeBase64StargateMsgs decodes a series of base64-encoded +// wasmvm.StargateMsg objects from the provided JSON byte slice (jsonBz). +// This function is vital for extracting and interpreting the contents of these +// protobuf messages. +// +// Args: +// - jsonBz []byte: JSON data containing potential base64-encoded messages. +// - clientCtx client.Context: Context for the `nibid` CLI. +// +// Returns: +// - newSgMsgs []StargateMsgDecoded: The decoded stargate messages. +// - err error: An error object, which is nil if the operation is successful. func DecodeBase64StargateMsgs( - jsonBz []byte, context client.Context, + jsonBz []byte, clientCtx client.Context, ) (newSgMsgs []StargateMsgDecoded, err error) { - codec := context.Codec + codec := clientCtx.Codec var data interface{} if err := json.Unmarshal(jsonBz, &data); err != nil { - return []StargateMsgDecoded{}, err + return newSgMsgs, fmt.Errorf( + "failed to decode stargate msgs due to invalid JSON: %w", err) } sgMsgs, err := YieldStargateMsgs(jsonBz) if err != nil { - return + return newSgMsgs, err } for _, sgMsg := range sgMsgs { valueStr := string(sgMsg.Value) - value := strings.Replace(string(sgMsg.Value), `\"`, `"`, -1) - value = strings.Replace(value, `"{`, `{`, -1) - value = strings.Replace(value, `}"`, `}`, -1) + replacer := strings.NewReplacer( + `\"`, `"`, // old, new + `"{`, `{`, + `}"`, `}`, + ) + value := replacer.Replace(string(sgMsg.Value)) if _, err := base64.StdEncoding.DecodeString(valueStr); err == nil { - protoMsg, err := context.InterfaceRegistry.Resolve(sgMsg.TypeURL) + protoMsg, err := clientCtx.InterfaceRegistry.Resolve(sgMsg.TypeURL) if err != nil { return newSgMsgs, err } @@ -92,9 +131,13 @@ func DecodeBase64StargateMsgs( return newSgMsgs, err } - newSgMsgs = append(newSgMsgs, StargateMsgDecoded{sgMsg.TypeURL, string(outBytes)}) + newSgMsgs = append(newSgMsgs, + StargateMsgDecoded{sgMsg.TypeURL, string(outBytes)}, + ) } else if _, err := json.Marshal(value); err == nil { - newSgMsgs = append(newSgMsgs, StargateMsgDecoded{sgMsg.TypeURL, string(sgMsg.Value)}) + newSgMsgs = append(newSgMsgs, + StargateMsgDecoded{sgMsg.TypeURL, string(sgMsg.Value)}, + ) } else { return newSgMsgs, fmt.Errorf( "parse error: encountered wasmvm.StargateMsg with unexpected format: %s", sgMsg) @@ -103,7 +146,9 @@ func DecodeBase64StargateMsgs( return newSgMsgs, nil } -// DecodeBase64Cmd creates a cobra command for base64 decoding. +// DecodeBase64Cmd creates a Cobra command used to decode base64-encoded protobuf +// messages from a JSON input. This function enables users to input arbitrary +// JSON strings and parse the contents of base-64 encoded protobuf.Any messages. func DecodeBase64Cmd(defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ Use: "base64-decode", @@ -114,8 +159,9 @@ The input should be a JSON object with 'type_url' and 'value' fields.`, clientCtx := client.GetClientContextFromCmd(cmd) outMessage, err := DecodeBase64StargateMsgs([]byte(args[0]), clientCtx) - fmt.Println(outMessage) - + if err == nil { + fmt.Println(outMessage) + } return err }, } From d2aa5610d2b70fd9f0cd9a5c049cdae124e70a00 Mon Sep 17 00:00:00 2001 From: Kevin Yang <5478483+k-yang@users.noreply.github.com> Date: Mon, 1 Jan 2024 09:30:57 -0800 Subject: [PATCH 4/7] test(sim): add sim genesis state for custom modules (#1759) * test(sim): add randomized inflation genesis state * test(sim): add tokenfactory random genesis state * test(sim): add tokenfactory random genesis state * test(sim): update sudo random genesis * test(sim): add devgas random genesis * test(sim): add perp random genesis * test(sim): wire spot sim genesis * chore: update changelog --- CHANGELOG.md | 4 +- x/devgas/v1/module.go | 77 +++++++++++++++++----------- x/devgas/v1/simulation/genesis.go | 46 +++++++++++++++++ x/inflation/module.go | 4 +- x/inflation/simulation/genesis.go | 47 +++++++++++++++++ x/perp/v2/module/module.go | 23 +++++++-- x/perp/v2/simulation/genesis.go | 24 +++++++++ x/spot/module.go | 31 ++++++++--- x/spot/module_simulation.go | 33 ------------ x/spot/simulation/genesis.go | 34 ++++++++++++ x/sudo/simulation/genesis.go | 24 ++------- x/tokenfactory/module.go | 61 +++++++++++++--------- x/tokenfactory/simulation/genesis.go | 44 ++++++++++++++++ 13 files changed, 335 insertions(+), 117 deletions(-) create mode 100644 x/devgas/v1/simulation/genesis.go create mode 100644 x/inflation/simulation/genesis.go create mode 100644 x/perp/v2/simulation/genesis.go delete mode 100644 x/spot/module_simulation.go create mode 100644 x/spot/simulation/genesis.go create mode 100644 x/tokenfactory/simulation/genesis.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 13fec3c34..7bbfad80c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,10 +81,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1728](https://github.com/NibiruChain/nibiru/pull/1728) - test(devgas-cli): CLI tests for devgas txs * [#1735](https://github.com/NibiruChain/nibiru/pull/1735) - test(sim): fix simulation tests * [#1754](https://github.com/NibiruChain/nibiru/pull/1754) - refactor(decode-base64): clean code improvements and fn docs +* [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules ### Dependencies + - Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) -- Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) +* Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) * Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720)) * Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724)) diff --git a/x/devgas/v1/module.go b/x/devgas/v1/module.go index a99c44316..b76044225 100644 --- a/x/devgas/v1/module.go +++ b/x/devgas/v1/module.go @@ -5,28 +5,29 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" sdkcodec "github.com/cosmos/cosmos-sdk/codec" sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" - devgascli "github.com/NibiruChain/nibiru/x/devgas/v1/client/cli" - devgasexported "github.com/NibiruChain/nibiru/x/devgas/v1/exported" - devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" - devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types" + "github.com/NibiruChain/nibiru/x/devgas/v1/client/cli" + "github.com/NibiruChain/nibiru/x/devgas/v1/exported" + "github.com/NibiruChain/nibiru/x/devgas/v1/keeper" + "github.com/NibiruChain/nibiru/x/devgas/v1/simulation" + "github.com/NibiruChain/nibiru/x/devgas/v1/types" ) // type check to ensure the interface is properly implemented var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ConsensusVersion defines the current module consensus version. @@ -37,13 +38,13 @@ type AppModuleBasic struct{} // Name returns the fees module's name. func (AppModuleBasic) Name() string { - return devgastypes.ModuleName + return types.ModuleName } // RegisterLegacyAminoCodec performs a no-op as the fees do not support Amino // encoding. func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *sdkcodec.LegacyAmino) { - devgastypes.RegisterLegacyAminoCodec(cdc) + types.RegisterLegacyAminoCodec(cdc) } // ConsensusVersion returns the consensus state-breaking version for the module. @@ -56,22 +57,22 @@ func (AppModuleBasic) ConsensusVersion() uint64 { func (AppModuleBasic) RegisterInterfaces( interfaceRegistry sdkcodectypes.InterfaceRegistry, ) { - devgastypes.RegisterInterfaces(interfaceRegistry) + types.RegisterInterfaces(interfaceRegistry) } // DefaultGenesis returns default genesis state as raw bytes for the fees // module. func (AppModuleBasic) DefaultGenesis(cdc sdkcodec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(devgastypes.DefaultGenesisState()) + return cdc.MustMarshalJSON(types.DefaultGenesisState()) } // ValidateGenesis performs genesis state validation for the fees module. func (b AppModuleBasic) ValidateGenesis( cdc sdkcodec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage, ) error { - var genesisState devgastypes.GenesisState + var genesisState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", devgastypes.ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } return genesisState.Validate() @@ -82,19 +83,19 @@ func (b AppModuleBasic) ValidateGenesis( func (b AppModuleBasic) RegisterGRPCGatewayRoutes( c sdkclient.Context, serveMux *runtime.ServeMux, ) { - if err := devgastypes.RegisterQueryHandlerClient(context.Background(), serveMux, devgastypes.NewQueryClient(c)); err != nil { + if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil { panic(err) } } // GetTxCmd returns the root tx command for the fees module. func (AppModuleBasic) GetTxCmd() *cobra.Command { - return devgascli.NewTxCmd() + return cli.NewTxCmd() } // GetQueryCmd returns the fees module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return devgascli.GetQueryCmd() + return cli.GetQueryCmd() } // ___________________________________________________________________________ @@ -102,18 +103,18 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface for the fees module. type AppModule struct { AppModuleBasic - keeper devgaskeeper.Keeper + keeper keeper.Keeper ak authkeeper.AccountKeeper // legacySubspace is used solely for migration of x/params managed parameters - legacySubspace devgasexported.Subspace + legacySubspace exported.Subspace } // NewAppModule creates a new AppModule Object func NewAppModule( - k devgaskeeper.Keeper, + k keeper.Keeper, ak authkeeper.AccountKeeper, - ss devgasexported.Subspace, + ss exported.Subspace, ) AppModule { return AppModule{ AppModuleBasic: AppModuleBasic{}, @@ -125,7 +126,7 @@ func NewAppModule( // Name returns the fees module's name. func (AppModule) Name() string { - return devgastypes.ModuleName + return types.ModuleName } // RegisterInvariants registers the fees module's invariants. @@ -133,15 +134,15 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // QuerierRoute returns the module's query routing key. func (am AppModule) QuerierRoute() string { - return devgastypes.RouterKey + return types.RouterKey } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - devgastypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - devgastypes.RegisterQueryServer( - cfg.QueryServer(), devgaskeeper.NewQuerier(am.keeper), + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer( + cfg.QueryServer(), keeper.NewQuerier(am.keeper), ) } @@ -158,7 +159,7 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid // InitGenesis performs the fees module's genesis initialization. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState devgastypes.GenesisState + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) InitGenesis(ctx, am.keeper, genesisState) @@ -170,3 +171,21 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec) json. gs := ExportGenesis(ctx, am.keeper) return cdc.MustMarshalJSON(gs) } + +//---------------------------------------------------------------------------- +// AppModuleSimulation functions +//---------------------------------------------------------------------------- + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return nil +} diff --git a/x/devgas/v1/simulation/genesis.go b/x/devgas/v1/simulation/genesis.go new file mode 100644 index 000000000..8fd31e5c9 --- /dev/null +++ b/x/devgas/v1/simulation/genesis.go @@ -0,0 +1,46 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/devgas/v1/types" +) + +const ( + DeveloperFeeShare = "developer_fee_share" +) + +func GenDeveloperFeeShare(r *rand.Rand) sdk.Dec { + return sdk.NewDecWithPrec(int64(r.Intn(100)), 2) +} + +func RandomizedGenState(simState *module.SimulationState) { + var developerFeeShare sdk.Dec + simState.AppParams.GetOrGenerate( + simState.Cdc, DeveloperFeeShare, &developerFeeShare, simState.Rand, + func(r *rand.Rand) { developerFeeShare = GenDeveloperFeeShare(r) }, + ) + + devgasGenesis := types.GenesisState{ + Params: types.ModuleParams{ + EnableFeeShare: true, + DeveloperShares: developerFeeShare, + AllowedDenoms: []string{}, + }, + FeeShare: []types.FeeShare{}, + } + + bz, err := json.MarshalIndent(&devgasGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/devgas parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&devgasGenesis) +} diff --git a/x/inflation/module.go b/x/inflation/module.go index 5265af192..5ccfaa65e 100644 --- a/x/inflation/module.go +++ b/x/inflation/module.go @@ -19,6 +19,7 @@ import ( "github.com/NibiruChain/nibiru/x/inflation/client/cli" "github.com/NibiruChain/nibiru/x/inflation/keeper" + "github.com/NibiruChain/nibiru/x/inflation/simulation" "github.com/NibiruChain/nibiru/x/inflation/types" ) @@ -153,7 +154,8 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw // AppModuleSimulation functions // GenerateGenesisState creates a randomized GenState of the inflation module. -func (am AppModule) GenerateGenesisState(_ *module.SimulationState) { +func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) } // ProposalContents doesn't return any content functions for governance proposals. diff --git a/x/inflation/simulation/genesis.go b/x/inflation/simulation/genesis.go new file mode 100644 index 000000000..11f1dc874 --- /dev/null +++ b/x/inflation/simulation/genesis.go @@ -0,0 +1,47 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/inflation/types" +) + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + inflationGenesis := types.GenesisState{ + Params: types.Params{ + InflationEnabled: true, + PolynomialFactors: []sdk.Dec{ + sdk.MustNewDecFromStr("-0.00014903"), + sdk.MustNewDecFromStr("0.07527647"), + sdk.MustNewDecFromStr("-19.11742154"), + sdk.MustNewDecFromStr("3170.0969905"), + sdk.MustNewDecFromStr("-339271.31060432"), + sdk.MustNewDecFromStr("18063678.8582418"), + }, + InflationDistribution: types.InflationDistribution{ + CommunityPool: sdk.NewDecWithPrec(35_159141, 8), // 35.159141% + StakingRewards: sdk.NewDecWithPrec(27_757217, 8), // 27.757217% + StrategicReserves: sdk.NewDecWithPrec(37_083642, 8), // 37.083642% + }, + EpochsPerPeriod: 30, + PeriodsPerYear: 12, + MaxPeriod: 8 * 12, + }, + Period: 0, + SkippedEpochs: 0, + } + + bz, err := json.MarshalIndent(&inflationGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/inflation parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&inflationGenesis) +} diff --git a/x/perp/v2/module/module.go b/x/perp/v2/module/module.go index 94027376a..c58d70c7a 100644 --- a/x/perp/v2/module/module.go +++ b/x/perp/v2/module/module.go @@ -11,18 +11,21 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "github.com/NibiruChain/nibiru/x/perp/v2/client/cli" "github.com/NibiruChain/nibiru/x/perp/v2/keeper" - types "github.com/NibiruChain/nibiru/x/perp/v2/types" + "github.com/NibiruChain/nibiru/x/perp/v2/simulation" + "github.com/NibiruChain/nibiru/x/perp/v2/types" ) // type check to ensure the interface is properly implemented var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ---------------------------------------------------------------------------- @@ -167,3 +170,17 @@ func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.Val EndBlocker(ctx, am.keeper) return []abci.ValidatorUpdate{} } + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} diff --git a/x/perp/v2/simulation/genesis.go b/x/perp/v2/simulation/genesis.go new file mode 100644 index 000000000..6f010bdef --- /dev/null +++ b/x/perp/v2/simulation/genesis.go @@ -0,0 +1,24 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/perp/v2/types" +) + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + perpGenesis := *types.DefaultGenesis() + + bz, err := json.MarshalIndent(&perpGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/tokenfactory parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&perpGenesis) +} diff --git a/x/spot/module.go b/x/spot/module.go index c0fc8a40f..9bd9cca72 100644 --- a/x/spot/module.go +++ b/x/spot/module.go @@ -5,25 +5,26 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" "github.com/NibiruChain/nibiru/x/spot/client/cli" "github.com/NibiruChain/nibiru/x/spot/keeper" + "github.com/NibiruChain/nibiru/x/spot/simulation" "github.com/NibiruChain/nibiru/x/spot/types" ) var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModule = AppModule{} + _ module.AppModuleBasic = AppModuleBasic{} + _ module.AppModuleSimulation = AppModule{} ) // ---------------------------------------------------------------------------- @@ -155,3 +156,21 @@ func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { return []abci.ValidatorUpdate{} } + +// GenerateGenesisState creates a default GenState of the module +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// ProposalContents doesn't return any content functions for governance proposals +func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { + return nil +} + +// RegisterStoreDecoder registers a decoder +func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} + +// WeightedOperations returns the all the spot module operations with their respective weights. +func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { + return simulation.WeightedOperations(am.accountKeeper, am.bankKeeper, am.keeper) +} diff --git a/x/spot/module_simulation.go b/x/spot/module_simulation.go deleted file mode 100644 index 0b3e6dfd2..000000000 --- a/x/spot/module_simulation.go +++ /dev/null @@ -1,33 +0,0 @@ -package spot - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - - "github.com/NibiruChain/nibiru/x/spot/simulation" - "github.com/NibiruChain/nibiru/x/spot/types" -) - -// GenerateGenesisState creates a default GenState of the module -func (AppModule) GenerateGenesisState(simState *module.SimulationState) { - accs := make([]string, len(simState.Accounts)) - for i, acc := range simState.Accounts { - accs[i] = acc.Address.String() - } - dexGenesis := types.DefaultGenesis() - simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(dexGenesis) -} - -// ProposalContents doesn't return any content functions for governance proposals -func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - -// RegisterStoreDecoder registers a decoder -func (am AppModule) RegisterStoreDecoder(_ sdk.StoreDecoderRegistry) {} - -// WeightedOperations returns the all the spot module operations with their respective weights. -func (am AppModule) WeightedOperations(_ module.SimulationState) []simtypes.WeightedOperation { - return simulation.WeightedOperations(am.accountKeeper, am.bankKeeper, am.keeper) -} diff --git a/x/spot/simulation/genesis.go b/x/spot/simulation/genesis.go new file mode 100644 index 000000000..46904391f --- /dev/null +++ b/x/spot/simulation/genesis.go @@ -0,0 +1,34 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/tokenfactory/types" +) + +const ( + DenomCreationGasConsume = "denom_creation_gas_consume" +) + +func GenDenomCreationGasConsume(r *rand.Rand) uint64 { + return uint64(r.Intn(4e6)) +} + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + spotGenesis := types.DefaultGenesis() + + bz, err := json.MarshalIndent(&spotGenesis, "", " ") + if err != nil { + panic(err) + } + + fmt.Printf("Selected randomly generated x/spot parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(spotGenesis) +} diff --git a/x/sudo/simulation/genesis.go b/x/sudo/simulation/genesis.go index 89a863582..6558770e4 100644 --- a/x/sudo/simulation/genesis.go +++ b/x/sudo/simulation/genesis.go @@ -5,36 +5,18 @@ package simulation import ( "encoding/json" "fmt" - "math/rand" - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/NibiruChain/nibiru/x/sudo/types" ) -// Simulation parameter constants -const ( - CommunityTax = "community_tax" - WithdrawEnabled = "withdraw_enabled" -) - -// GenCommunityTax randomized CommunityTax -func GenCommunityTax(r *rand.Rand) math.LegacyDec { - return sdk.NewDecWithPrec(1, 2).Add(sdk.NewDecWithPrec(int64(r.Intn(30)), 2)) -} - -// GenWithdrawEnabled returns a randomized WithdrawEnabled parameter. -func GenWithdrawEnabled(r *rand.Rand) bool { - return r.Int63n(101) <= 95 // 95% chance of withdraws being enabled -} - -// RandomizedGenState generates a random GenesisState for distribution func RandomizedGenState(simState *module.SimulationState) { + rootAddress := simState.Accounts[simState.Rand.Intn(len(simState.Accounts))].Address + genState := types.GenesisState{ Sudoers: types.Sudoers{ - Root: simState.Accounts[0].Address.String(), + Root: rootAddress.String(), Contracts: []string{}, }, } diff --git a/x/tokenfactory/module.go b/x/tokenfactory/module.go index 80b41b36c..9cc05ec99 100644 --- a/x/tokenfactory/module.go +++ b/x/tokenfactory/module.go @@ -14,27 +14,28 @@ import ( "encoding/json" "fmt" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/cometbft/cometbft/abci/types" - sdkclient "github.com/cosmos/cosmos-sdk/client" sdkcodec "github.com/cosmos/cosmos-sdk/codec" sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/spf13/cobra" - modulecli "github.com/NibiruChain/nibiru/x/tokenfactory/cli" - modulekeeper "github.com/NibiruChain/nibiru/x/tokenfactory/keeper" - moduletypes "github.com/NibiruChain/nibiru/x/tokenfactory/types" + "github.com/NibiruChain/nibiru/x/tokenfactory/cli" + "github.com/NibiruChain/nibiru/x/tokenfactory/keeper" + "github.com/NibiruChain/nibiru/x/tokenfactory/simulation" + "github.com/NibiruChain/nibiru/x/tokenfactory/types" ) // type check to ensure the interface is properly implemented var ( _ module.AppModuleBasic = AppModuleBasic{} _ module.AppModule = AppModule{} + _ module.AppModuleSimulation = AppModule{} _ module.BeginBlockAppModule = AppModule{} _ module.EndBlockAppModule = AppModule{} ) @@ -47,13 +48,13 @@ type AppModuleBasic struct{} // Name returns the fees module's name. func (AppModuleBasic) Name() string { - return moduletypes.ModuleName + return types.ModuleName } // RegisterLegacyAminoCodec performs a no-op as the fees do not support Amino // encoding. func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *sdkcodec.LegacyAmino) { - moduletypes.RegisterLegacyAminoCodec(cdc) + types.RegisterLegacyAminoCodec(cdc) } // ConsensusVersion returns the consensus state-breaking version for the module. @@ -66,22 +67,22 @@ func (AppModuleBasic) ConsensusVersion() uint64 { func (AppModuleBasic) RegisterInterfaces( interfaceRegistry sdkcodectypes.InterfaceRegistry, ) { - moduletypes.RegisterInterfaces(interfaceRegistry) + types.RegisterInterfaces(interfaceRegistry) } // DefaultGenesis returns default genesis state as raw bytes for the fees // module. func (AppModuleBasic) DefaultGenesis(cdc sdkcodec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(moduletypes.DefaultGenesis()) + return cdc.MustMarshalJSON(types.DefaultGenesis()) } // ValidateGenesis performs genesis state validation for the fees module. func (b AppModuleBasic) ValidateGenesis( cdc sdkcodec.JSONCodec, _ sdkclient.TxEncodingConfig, bz json.RawMessage, ) error { - var genesisState moduletypes.GenesisState + var genesisState types.GenesisState if err := cdc.UnmarshalJSON(bz, &genesisState); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", moduletypes.ModuleName, err) + return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) } return genesisState.Validate() @@ -92,19 +93,19 @@ func (b AppModuleBasic) ValidateGenesis( func (b AppModuleBasic) RegisterGRPCGatewayRoutes( c sdkclient.Context, serveMux *runtime.ServeMux, ) { - if err := moduletypes.RegisterQueryHandlerClient(context.Background(), serveMux, moduletypes.NewQueryClient(c)); err != nil { + if err := types.RegisterQueryHandlerClient(context.Background(), serveMux, types.NewQueryClient(c)); err != nil { panic(err) } } // GetTxCmd returns the root tx command for the fees module. func (AppModuleBasic) GetTxCmd() *cobra.Command { - return modulecli.NewTxCmd() + return cli.NewTxCmd() } // GetQueryCmd returns the fees module's root query command. func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return modulecli.NewQueryCmd() + return cli.NewQueryCmd() } // ___________________________________________________________________________ @@ -112,13 +113,13 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { // AppModule implements the AppModule interface for the fees module. type AppModule struct { AppModuleBasic - keeper modulekeeper.Keeper + keeper keeper.Keeper ak authkeeper.AccountKeeper } // NewAppModule creates a new AppModule Object func NewAppModule( - k modulekeeper.Keeper, + k keeper.Keeper, ak authkeeper.AccountKeeper, ) AppModule { return AppModule{ @@ -130,7 +131,7 @@ func NewAppModule( // Name returns the fees module's name. func (AppModule) Name() string { - return moduletypes.ModuleName + return types.ModuleName } // RegisterInvariants registers the fees module's invariants. @@ -138,14 +139,14 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} // QuerierRoute returns the module's query routing key. func (am AppModule) QuerierRoute() string { - return moduletypes.RouterKey + return types.RouterKey } // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - moduletypes.RegisterMsgServer(cfg.MsgServer(), am.keeper) - moduletypes.RegisterQueryServer( + types.RegisterMsgServer(cfg.MsgServer(), am.keeper) + types.RegisterQueryServer( cfg.QueryServer(), am.keeper.Querier(), ) } @@ -163,7 +164,7 @@ func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.Valid // InitGenesis performs the fees module's genesis initialization. It returns // no validator updates. func (am AppModule) InitGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState moduletypes.GenesisState + var genesisState types.GenesisState cdc.MustUnmarshalJSON(data, &genesisState) am.keeper.InitGenesis(ctx, genesisState) @@ -175,3 +176,17 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc sdkcodec.JSONCodec) json. gs := am.keeper.ExportGenesis(ctx) return cdc.MustMarshalJSON(gs) } + +// GenerateGenesisState implements module.AppModuleSimulation. +func (AppModule) GenerateGenesisState(simState *module.SimulationState) { + simulation.RandomizedGenState(simState) +} + +// RegisterStoreDecoder implements module.AppModuleSimulation. +func (AppModule) RegisterStoreDecoder(sdk.StoreDecoderRegistry) { +} + +// WeightedOperations implements module.AppModuleSimulation. +func (AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { + return []simtypes.WeightedOperation{} +} diff --git a/x/tokenfactory/simulation/genesis.go b/x/tokenfactory/simulation/genesis.go new file mode 100644 index 000000000..40856bd06 --- /dev/null +++ b/x/tokenfactory/simulation/genesis.go @@ -0,0 +1,44 @@ +package simulation + +// DONTCOVER + +import ( + "encoding/json" + "fmt" + "math/rand" + + "github.com/cosmos/cosmos-sdk/types/module" + + "github.com/NibiruChain/nibiru/x/tokenfactory/types" +) + +const ( + DenomCreationGasConsume = "denom_creation_gas_consume" +) + +func GenDenomCreationGasConsume(r *rand.Rand) uint64 { + return uint64(r.Intn(4e6)) +} + +// RandomizedGenState generates a random GenesisState for distribution +func RandomizedGenState(simState *module.SimulationState) { + var denomCreationGasConsume uint64 + simState.AppParams.GetOrGenerate( + simState.Cdc, DenomCreationGasConsume, &denomCreationGasConsume, simState.Rand, + func(r *rand.Rand) { denomCreationGasConsume = GenDenomCreationGasConsume(r) }, + ) + + tokenfactoryGenesis := types.GenesisState{ + Params: types.ModuleParams{ + DenomCreationGasConsume: denomCreationGasConsume, + }, + FactoryDenoms: []types.GenesisDenom{}, + } + + bz, err := json.MarshalIndent(&tokenfactoryGenesis, "", " ") + if err != nil { + panic(err) + } + fmt.Printf("Selected randomly generated x/tokenfactory parameters:\n%s\n", bz) + simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&tokenfactoryGenesis) +} From 310fcf1da8b35deb38c8c4e12882e8c6778a9eb2 Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Mon, 1 Jan 2024 12:30:05 -0600 Subject: [PATCH 5/7] feat(perp): MsgWithdrawFromPerpFund sudo call as part of #1642 (#1734) * feat(perp): MsgDonateToPerpFund * changelog * linter * test assertiong * test(perp-cli_test): Grab module acc addr programatically * consistent naming with #1752 --- CHANGELOG.md | 4 +- app/keepers.go | 2 +- proto/nibiru/perp/v2/tx.proto | 38 +- wasmbinding/bindings/msg.go | 16 +- wasmbinding/exec_perp.go | 23 +- wasmbinding/exec_perp_test.go | 32 - wasmbinding/exec_test.go | 49 -- wasmbinding/message_plugin.go | 7 - x/oracle/keeper/hooks.go | 2 +- x/oracle/keeper/hooks_test.go | 2 +- x/perp/v2/client/cli/cli_test.go | 12 +- x/perp/v2/integration/action/market.go | 8 +- x/perp/v2/integration/action/settlement.go | 4 +- x/perp/v2/keeper/amm.go | 6 +- x/perp/v2/keeper/amm_test.go | 82 +- x/perp/v2/keeper/clearing_house.go | 2 +- x/perp/v2/keeper/clearing_house_test.go | 32 +- x/perp/v2/keeper/dnr_test.go | 16 +- x/perp/v2/keeper/grpc_query_test.go | 4 +- x/perp/v2/keeper/keeper.go | 7 +- x/perp/v2/keeper/liquidate.go | 2 +- x/perp/v2/keeper/liquidate_test.go | 20 +- x/perp/v2/keeper/margin_test.go | 12 +- x/perp/v2/keeper/msg_server.go | 28 +- x/perp/v2/keeper/msg_server_test.go | 6 +- x/perp/v2/keeper/{admin.go => sudo.go} | 74 +- .../v2/keeper/{admin_test.go => sudo_test.go} | 97 ++- x/perp/v2/keeper/withdraw.go | 4 +- x/perp/v2/keeper/withdraw_test.go | 12 +- x/perp/v2/module/abci_test.go | 4 +- x/perp/v2/module/genesis.go | 2 +- x/perp/v2/module/genesis_test.go | 2 +- x/perp/v2/module/module.go | 2 +- x/perp/v2/types/errors.go | 1 + x/perp/v2/types/keys.go | 4 +- x/perp/v2/types/msgs.go | 33 + x/perp/v2/types/msgs_test.go | 45 +- x/perp/v2/types/tx.pb.go | 707 +++++++++++++++--- 38 files changed, 955 insertions(+), 448 deletions(-) rename x/perp/v2/keeper/{admin.go => sudo.go} (76%) rename x/perp/v2/keeper/{admin_test.go => sudo_test.go} (85%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bbfad80c..e5edd07f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1573](https://github.com/NibiruChain/nibiru/pull/1573) - feat(perp): Close markets and compute settlement price * [#1705](https://github.com/NibiruChain/nibiru/pull/1705) - feat(perp): Add oracle pair to market object * [#1718](https://github.com/NibiruChain/nibiru/pull/1718) - fix: fees does not require additional funds +* [#1734](https://github.com/NibiruChain/nibiru/pull/1734) - feat(perp): MsgDonateToPerpFund sudo call as part of #1642 * [#1755](https://github.com/NibiruChain/nibiru/pull/1755) - feat(oracle): Add more events on validator's performance ### Non-breaking/Compatible Improvements @@ -85,9 +86,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Dependencies -- Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) +* Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) * Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) - * Bump `google.golang.org/grpc` from 1.59.0 to 1.60.0 ([#1720](https://github.com/NibiruChain/nibiru/pull/1720)) * Bump `golang.org/x/crypto` from 0.15.0 to 0.17.0 ([#1724](https://github.com/NibiruChain/nibiru/pull/1724)) * Bump `github.com/holiman/uint256` from 1.2.3 to 1.2.4 ([#1730](https://github.com/NibiruChain/nibiru/pull/1730)) diff --git a/app/keepers.go b/app/keepers.go index e252bc554..b623ebbbb 100644 --- a/app/keepers.go +++ b/app/keepers.go @@ -805,7 +805,7 @@ func ModuleAccPerms() map[string][]string { perptypes.ModuleName: {}, perptypes.VaultModuleAccount: {}, - perptypes.PerpEFModuleAccount: {}, + perptypes.PerpFundModuleAccount: {}, perptypes.FeePoolModuleAccount: {}, perptypes.DNRAllocationModuleAccount: {}, perptypes.DNREscrowModuleAccount: {}, diff --git a/proto/nibiru/perp/v2/tx.proto b/proto/nibiru/perp/v2/tx.proto index 7dba213c7..faae01c34 100644 --- a/proto/nibiru/perp/v2/tx.proto +++ b/proto/nibiru/perp/v2/tx.proto @@ -30,7 +30,7 @@ service Msg { returns (MsgDonateToEcosystemFundResponse) {} // ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it - // is possible to make an sdk.Coin using it. [Admin] Only callable by sudoers. + // is possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers. rpc ChangeCollateralDenom(MsgChangeCollateralDenom) returns (MsgChangeCollateralDenomResponse) {} @@ -41,14 +41,19 @@ service Msg { returns (MsgWithdrawEpochRebatesResponse) {} // ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. rpc ShiftPegMultiplier(MsgShiftPegMultiplier) returns (MsgShiftPegMultiplierResponse) {} // ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. rpc ShiftSwapInvariant(MsgShiftSwapInvariant) returns (MsgShiftSwapInvariantResponse) {} + + // WithdrawFromPerpFund: gRPC tx msg to withdraw from the perp fund module + // account. [SUDO] Only callable by sudoers. + rpc WithdrawFromPerpFund(MsgWithdrawFromPerpFund) + returns (MsgWithdrawFromPerpFundResponse) {} } // -------------------------- Settle Position -------------------------- @@ -353,7 +358,7 @@ message MsgDonateToEcosystemFundResponse {} // ----------------------- MsgChangeCollateralDenom ----------------------- // MsgChangeCollateralDenom: Changes the collateral denom for the module. -// [Admin] Only callable by sudoers. +// [SUDO] Only callable by sudoers. message MsgChangeCollateralDenom { string sender = 1; string new_denom = 2; @@ -394,8 +399,8 @@ message MsgWithdrawEpochRebatesResponse { // -------------------------- ShiftPegMultiplier -------------------------- -// ShiftPegMultiplier: gRPC tx msg for changing the peg multiplier. -// Admin-only. +// MsgShiftPegMultiplier: gRPC tx msg for changing the peg multiplier. +// [SUDO] Only callable sudoers. message MsgShiftPegMultiplier { string sender = 1; string pair = 2 [ @@ -413,8 +418,8 @@ message MsgShiftPegMultiplierResponse {} // -------------------------- ShiftSwapInvariant -------------------------- -// ShiftSwapInvariant: gRPC tx msg for changing the swap invariant. -// Admin-only. +// MsgShiftSwapInvariant: gRPC tx msg for changing the swap invariant. +// [SUDO] Only callable sudoers. message MsgShiftSwapInvariant { string sender = 1; string pair = 2 [ @@ -429,3 +434,20 @@ message MsgShiftSwapInvariant { } message MsgShiftSwapInvariantResponse {} + +// -------------------------- WithdrawFromPerpFund -------------------------- + +// MsgWithdrawFromPerpFund: gRPC tx msg for changing the swap invariant. +// [SUDO] Only callable sudoers. +message MsgWithdrawFromPerpFund { + string sender = 1; + string amount = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", + (gogoproto.nullable) = false + ]; + // Optional denom in case withdrawing assets aside from NUSD. + string denom = 3; + string to_addr = 4; +} + +message MsgWithdrawFromPerpFundResponse {} diff --git a/wasmbinding/bindings/msg.go b/wasmbinding/bindings/msg.go index 836406af1..42532c059 100644 --- a/wasmbinding/bindings/msg.go +++ b/wasmbinding/bindings/msg.go @@ -14,10 +14,8 @@ import ( type NibiruMsg struct { // bindings-perp ExecuteMsg enum types // MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO - DonateToInsuranceFund *DonateToInsuranceFund `json:"donate_to_insurance_fund,omitempty"` // TODO - InsuranceFundWithdraw *InsuranceFundWithdraw `json:"insurance_fund_withdraw,omitempty"` - SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"` - CreateMarket *CreateMarket `json:"create_market,omitempty"` + SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"` + CreateMarket *CreateMarket `json:"create_market,omitempty"` EditOracleParams *EditOracleParams `json:"edit_oracle_params,omitempty"` @@ -25,11 +23,6 @@ type NibiruMsg struct { NoOp *NoOp `json:"no_op,omitempty"` } -type DonateToInsuranceFund struct { - Sender string `json:"sender"` - Donation sdk.Coin `json:"donation"` -} - type EditOracleParams struct { VotePeriod *sdkmath.Int `json:"vote_period,omitempty"` VoteThreshold *sdk.Dec `json:"vote_threshold,omitempty"` @@ -43,11 +36,6 @@ type EditOracleParams struct { ValidatorFeeRatio *sdk.Dec `json:"validator_fee_ratio,omitempty"` } -type InsuranceFundWithdraw struct { - Amount sdkmath.Int `json:"amount"` - To string `json:"to"` -} - type SetMarketEnabled struct { Pair string `json:"pair"` Enabled bool `json:"enabled"` diff --git a/wasmbinding/exec_perp.go b/wasmbinding/exec_perp.go index d3c4badd6..f3defcf01 100644 --- a/wasmbinding/exec_perp.go +++ b/wasmbinding/exec_perp.go @@ -20,25 +20,6 @@ func (exec *ExecutorPerp) MsgServer() perpv2types.MsgServer { return perpv2keeper.NewMsgServerImpl(exec.PerpV2) } -func (exec *ExecutorPerp) InsuranceFundWithdraw( - cwMsg *bindings.InsuranceFundWithdraw, ctx sdk.Context, -) (err error) { - if cwMsg == nil { - return wasmvmtypes.InvalidRequest{Err: "null msg"} - } - - to, err := sdk.AccAddressFromBech32(cwMsg.To) - if err != nil { - return err - } - - return exec.PerpV2.Admin.WithdrawFromInsuranceFund( - ctx, - cwMsg.Amount, - to, - ) -} - // TODO: rename to CloseMarket func (exec *ExecutorPerp) SetMarketEnabled( cwMsg *bindings.SetMarketEnabled, ctx sdk.Context, @@ -52,7 +33,7 @@ func (exec *ExecutorPerp) SetMarketEnabled( return err } - return exec.PerpV2.Admin.CloseMarket(ctx, pair) + return exec.PerpV2.Sudo().CloseMarket(ctx, pair) } func (exec *ExecutorPerp) CreateMarket( @@ -90,7 +71,7 @@ func (exec *ExecutorPerp) CreateMarket( } } - return exec.PerpV2.Admin.CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{ + return exec.PerpV2.Sudo().CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{ Pair: pair, PriceMultiplier: cwMsg.PegMult, SqrtDepth: cwMsg.SqrtDepth, diff --git a/wasmbinding/exec_perp_test.go b/wasmbinding/exec_perp_test.go index 0aa232cbc..e25571d42 100644 --- a/wasmbinding/exec_perp_test.go +++ b/wasmbinding/exec_perp_test.go @@ -134,7 +134,6 @@ func (s *TestSuitePerpExecutor) OnSetupEnd() { // Happy path coverage func (s *TestSuitePerpExecutor) TestPerpExecutorHappy() { for _, err := range []error{ - s.DoInsuranceFundWithdrawTest(sdk.NewInt(69), s.contractDeployer), s.DoCreateMarketTest(asset.MustNewPair("ufoo:ubar")), s.DoCreateMarketTestWithParams(asset.MustNewPair("ufoo2:ubar")), } { @@ -142,25 +141,6 @@ func (s *TestSuitePerpExecutor) TestPerpExecutorHappy() { } } -func (s *TestSuitePerpExecutor) DoInsuranceFundWithdrawTest( - amt sdkmath.Int, to sdk.AccAddress, -) error { - cwMsg := &bindings.InsuranceFundWithdraw{ - Amount: amt, - To: to.String(), - } - - err := testapp.FundModuleAccount( - s.nibiru.BankKeeper, - s.ctx, - perpv2types.PerpEFModuleAccount, - sdk.NewCoins(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420))), - ) - s.NoError(err) - - return s.exec.InsuranceFundWithdraw(cwMsg, s.ctx) -} - func (s *TestSuitePerpExecutor) DoCreateMarketTest(pair asset.Pair) error { cwMsg := &bindings.CreateMarket{ Pair: pair.String(), @@ -197,11 +177,6 @@ func (s *TestSuitePerpExecutor) DoCreateMarketTestWithParams(pair asset.Pair) er return s.exec.CreateMarket(cwMsg, s.ctx) } -func (s *TestSuitePerpExecutor) TestSadPaths_Nil() { - err := s.exec.InsuranceFundWithdraw(nil, s.ctx) - s.Error(err) -} - func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest( pair asset.Pair, enabled bool, ) error { @@ -220,13 +195,6 @@ func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest( return err } -func (s *TestSuitePerpExecutor) TestSadPath_InsuranceFundWithdraw() { - fundsToWithdraw := sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(69_000)) - - err := s.DoInsuranceFundWithdrawTest(fundsToWithdraw.Amount, s.contractDeployer) - s.Error(err) -} - func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() { sadPair := asset.Pair("ftt:ust:doge") pair := sadPair diff --git a/wasmbinding/exec_test.go b/wasmbinding/exec_test.go index 0ad880db0..cdbc5776c 100644 --- a/wasmbinding/exec_test.go +++ b/wasmbinding/exec_test.go @@ -313,55 +313,6 @@ func (s *TestSuiteExecutor) TestNoOp() { s.NoErrorf(err, "contractRespBz: %s", contractRespBz) } -func (s *TestSuiteExecutor) TestInsuranceFundWithdraw() { - admin := s.contractDeployer.String() - amtToWithdraw := sdk.NewInt(69) - execMsg := bindings.NibiruMsg{ - InsuranceFundWithdraw: &bindings.InsuranceFundWithdraw{ - Amount: amtToWithdraw, - To: admin, - }, - } - - s.T().Log("Executing should fail since the IF doesn't have funds") - contract := s.contractController - s.keeper.SetSudoContracts( - []string{contract.String()}, s.ctx, - ) - contractRespBz, err := s.ExecuteAgainstContract(contract, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - - s.T().Log("Executing without permission should fail") - s.keeper.SetSudoContracts( - []string{}, s.ctx, - ) - contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - - s.T().Log("Executing should work when the IF has funds") - err = testapp.FundModuleAccount( - s.nibiru.BankKeeper, - s.ctx, - perpv2types.PerpEFModuleAccount, - sdk.NewCoins(sdk.NewCoin(perpv2types.TestingCollateralDenomNUSD, sdk.NewInt(420))), - ) - s.NoError(err) - s.keeper.SetSudoContracts( - []string{contract.String()}, s.ctx, - ) - contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - s.T().Log("Executing the wrong contract should fail") - contract = s.contractPerp - s.keeper.SetSudoContracts( - []string{contract.String()}, s.ctx, - ) - contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - s.Contains(err.Error(), "Error parsing into type") -} - func (s *TestSuiteExecutor) TestSetMarketEnabled() { // admin := s.contractDeployer.String() perpv2Genesis := genesis.PerpV2Genesis() diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 51ef552ba..6642c90dd 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -71,13 +71,6 @@ func (messenger *CustomMessenger) DispatchMsg( err = messenger.Perp.CreateMarket(cwMsg, ctx) return events, data, err - case contractExecuteMsg.ExecuteMsg.InsuranceFundWithdraw != nil: - if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil { - return events, data, err - } - cwMsg := contractExecuteMsg.ExecuteMsg.InsuranceFundWithdraw - err = messenger.Perp.InsuranceFundWithdraw(cwMsg, ctx) - return events, data, err case contractExecuteMsg.ExecuteMsg.SetMarketEnabled != nil: if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil { return events, data, err diff --git a/x/oracle/keeper/hooks.go b/x/oracle/keeper/hooks.go index 5d5ae2888..69e26117d 100644 --- a/x/oracle/keeper/hooks.go +++ b/x/oracle/keeper/hooks.go @@ -57,7 +57,7 @@ func (h Hooks) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, _ uint64) } if !totalRemainder.IsZero() { - err = h.bankKeeper.SendCoinsFromModuleToModule(ctx, perptypes.FeePoolModuleAccount, perptypes.PerpEFModuleAccount, totalRemainder) + err = h.bankKeeper.SendCoinsFromModuleToModule(ctx, perptypes.FeePoolModuleAccount, perptypes.PerpFundModuleAccount, totalRemainder) if err != nil { h.k.Logger(ctx).Error("Failed to send coins to perp ef module", "err", err) } diff --git a/x/oracle/keeper/hooks_test.go b/x/oracle/keeper/hooks_test.go index 516c0dc38..5f655dfc9 100644 --- a/x/oracle/keeper/hooks_test.go +++ b/x/oracle/keeper/hooks_test.go @@ -73,7 +73,7 @@ func TestHooks_AfterEpochEnd(t *testing.T) { balances := app.BankKeeper.GetAllBalances(ctx, account.GetAddress()) assert.Equal(t, tt.expectedOracleBalances, balances) - account = app.AccountKeeper.GetModuleAccount(ctx, perptypes.PerpEFModuleAccount) + account = app.AccountKeeper.GetModuleAccount(ctx, perptypes.PerpFundModuleAccount) balances = app.BankKeeper.GetAllBalances(ctx, account.GetAddress()) assert.Equal(t, tt.expectedEFBalances, balances) }) diff --git a/x/perp/v2/client/cli/cli_test.go b/x/perp/v2/client/cli/cli_test.go index 9113d95c7..47a6a8b4f 100644 --- a/x/perp/v2/client/cli/cli_test.go +++ b/x/perp/v2/client/cli/cli_test.go @@ -8,6 +8,7 @@ import ( abcitypes "github.com/cometbft/cometbft/abci/types" sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankcli "github.com/cosmos/cosmos-sdk/x/bank/client/cli" "github.com/stretchr/testify/suite" @@ -714,16 +715,21 @@ func (s *IntegrationTestSuite) TestDonateToEcosystemFund() { s.NoError(s.network.WaitForNextBlock()) resp := new(sdk.Coin) - moduleAccountAddrPerpEF := "nibi1trh2mamq64u4g042zfeevvjk4cukrthvppfnc7" + + moduleAccPerpFund := authtypes.NewModuleAddress( + types.PerpFundModuleAccount).String() s.NoError( testutilcli.ExecQuery( s.network.Validators[0].ClientCtx, bankcli.GetBalancesCmd(), - []string{moduleAccountAddrPerpEF, "--denom", types.TestingCollateralDenomNUSD}, + []string{moduleAccPerpFund, "--denom", types.TestingCollateralDenomNUSD}, resp, ), ) - s.Require().EqualValues(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 100), *resp) + s.Require().EqualValues( + sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 100).String(), + resp.String(), + ) } func (s *IntegrationTestSuite) TestQueryModuleAccount() { diff --git a/x/perp/v2/integration/action/market.go b/x/perp/v2/integration/action/market.go index 896479ef3..73b966a17 100644 --- a/x/perp/v2/integration/action/market.go +++ b/x/perp/v2/integration/action/market.go @@ -127,7 +127,7 @@ type shiftPegMultiplier struct { } func (e shiftPegMultiplier) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { - err := app.PerpKeeperV2.Admin.ShiftPegMultiplier( + err := app.PerpKeeperV2.Sudo().ShiftPegMultiplier( ctx, e.pair, e.newValue, testapp.DefaultSudoRoot(), ) return ctx, err @@ -146,7 +146,7 @@ type shiftSwapInvariant struct { } func (e shiftSwapInvariant) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { - err := app.PerpKeeperV2.Admin.ShiftSwapInvariant( + err := app.PerpKeeperV2.Sudo().ShiftSwapInvariant( ctx, e.pair, e.newValue, testapp.DefaultSudoRoot(), ) return ctx, err @@ -166,7 +166,7 @@ type createPool struct { } func (c createPool) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { - err := app.PerpKeeperV2.Admin.CreateMarket(ctx, keeper.ArgsCreateMarket{ + err := app.PerpKeeperV2.Sudo().CreateMarket(ctx, keeper.ArgsCreateMarket{ Pair: c.pair, PriceMultiplier: c.amm.PriceMultiplier, SqrtDepth: c.amm.SqrtDepth, @@ -200,7 +200,7 @@ func (c setCollateral) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, err if err != nil { return ctx, err } - err = app.PerpKeeperV2.Admin.ChangeCollateralDenom(ctx, c.Denom, senderAddr) + err = app.PerpKeeperV2.Sudo().ChangeCollateralDenom(ctx, c.Denom, senderAddr) return ctx, err } diff --git a/x/perp/v2/integration/action/settlement.go b/x/perp/v2/integration/action/settlement.go index 62cafc869..1719d581a 100644 --- a/x/perp/v2/integration/action/settlement.go +++ b/x/perp/v2/integration/action/settlement.go @@ -17,7 +17,7 @@ type closeMarket struct { } func (c closeMarket) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { - err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) + err := app.PerpKeeperV2.Sudo().CloseMarket(ctx, c.pair) if err != nil { return ctx, err } @@ -35,7 +35,7 @@ type closeMarketShouldFail struct { } func (c closeMarketShouldFail) Do(app *app.NibiruApp, ctx sdk.Context) (sdk.Context, error) { - err := app.PerpKeeperV2.Admin.CloseMarket(ctx, c.pair) + err := app.PerpKeeperV2.Sudo().CloseMarket(ctx, c.pair) if err == nil { return ctx, err } diff --git a/x/perp/v2/keeper/amm.go b/x/perp/v2/keeper/amm.go index ae317d7f0..fe94ad4be 100644 --- a/x/perp/v2/keeper/amm.go +++ b/x/perp/v2/keeper/amm.go @@ -28,7 +28,7 @@ func (k Keeper) handleMarketUpdateCost( ) err = k.BankKeeper.SendCoinsFromModuleToModule( ctx, - types.PerpEFModuleAccount, + types.PerpFundModuleAccount, types.VaultModuleAccount, cost, ) @@ -36,7 +36,7 @@ func (k Keeper) handleMarketUpdateCost( return costPaid, types.ErrNotEnoughFundToPayAction.Wrapf( "need %s, got %s", cost.String(), - k.BankKeeper.GetBalance(ctx, k.AccountKeeper.GetModuleAddress(types.PerpEFModuleAccount), collateral).String(), + k.BankKeeper.GetBalance(ctx, k.AccountKeeper.GetModuleAddress(types.PerpFundModuleAccount), collateral).String(), ) } else { costPaid = cost[0] @@ -46,7 +46,7 @@ func (k Keeper) handleMarketUpdateCost( err = k.BankKeeper.SendCoinsFromModuleToModule( ctx, types.VaultModuleAccount, - types.PerpEFModuleAccount, + types.PerpFundModuleAccount, sdk.NewCoins( sdk.NewCoin(collateral, costAmt.Neg()), ), diff --git a/x/perp/v2/keeper/amm_test.go b/x/perp/v2/keeper/amm_test.go index 3dee582a0..0136778f9 100644 --- a/x/perp/v2/keeper/amm_test.go +++ b/x/perp/v2/keeper/amm_test.go @@ -29,14 +29,14 @@ func TestShiftPegMultiplier(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1000)), WithTotalShort(sdk.NewDec(500))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.OneDec()), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -52,14 +52,14 @@ func TestShiftPegMultiplier(t *testing.T) { WithEnabled(true), ), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.NewDec(10)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -72,14 +72,14 @@ func TestShiftPegMultiplier(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1000)), WithTotalShort(sdk.NewDec(500))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.NewDec(10)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1004500)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(995500)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(995500)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -92,14 +92,14 @@ func TestShiftPegMultiplier(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1000)), WithTotalShort(sdk.NewDec(500))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.MustNewDecFromStr("0.25")), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(999626)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000374)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000374)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -112,14 +112,14 @@ func TestShiftPegMultiplier(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(500)), WithTotalShort(sdk.NewDec(1000))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.NewDec(10)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(995500)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1004500)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1004500)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -132,14 +132,14 @@ func TestShiftPegMultiplier(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(500)), WithTotalShort(sdk.NewDec(1000))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftPegMultiplier(pair, sdk.MustNewDecFromStr("0.25")), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000376)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(999624)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(999624)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e12)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e12)), @@ -160,7 +160,7 @@ func TestShiftPegMultiplier_Fail(t *testing.T) { account := testutil.AccAddress() - err := app.PerpKeeperV2.Admin.CreateMarket( + err := app.PerpKeeperV2.Sudo().CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, @@ -188,12 +188,12 @@ func TestShiftPegMultiplier_Fail(t *testing.T) { adminAddr := testapp.DefaultSudoRoot() // Error because of invalid pair - err = app.PerpKeeperV2.Admin.ShiftPegMultiplier( + err = app.PerpKeeperV2.Sudo().ShiftPegMultiplier( ctx, asset.MustNewPair("luna:usdt"), sdk.NewDec(-1), adminAddr) require.ErrorContains(t, err, "market luna:usdt not found") // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin.ShiftPegMultiplier(ctx, pair, sdk.NewDec(-1), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftPegMultiplier(ctx, pair, sdk.NewDec(-1), adminAddr) require.ErrorIs(t, err, types.ErrAmmNonPositivePegMult) // Add market activity @@ -215,11 +215,11 @@ func TestShiftPegMultiplier_Fail(t *testing.T) { require.NoError(t, err) // Error because no money in perp ef fund - err = app.PerpKeeperV2.Admin.ShiftPegMultiplier(ctx, pair, sdk.NewDec(3), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftPegMultiplier(ctx, pair, sdk.NewDec(3), adminAddr) require.ErrorContains(t, err, types.ErrNotEnoughFundToPayAction.Error()) // Works because it goes in the other way - err = app.PerpKeeperV2.Admin.ShiftPegMultiplier(ctx, pair, sdk.NewDec(1), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftPegMultiplier(ctx, pair, sdk.NewDec(1), adminAddr) require.NoError(t, err) } @@ -230,7 +230,7 @@ func TestShiftSwapInvariant_Fail(t *testing.T) { app, ctx := testapp.NewNibiruTestAppAndContext() account := testutil.AccAddress() - err := app.PerpKeeperV2.Admin.CreateMarket( + err := app.PerpKeeperV2.Sudo().CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, @@ -258,11 +258,11 @@ func TestShiftSwapInvariant_Fail(t *testing.T) { adminAddr := testapp.DefaultSudoRoot() // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin.ShiftSwapInvariant(ctx, asset.MustNewPair("luna:usdt"), sdk.NewInt(-1), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftSwapInvariant(ctx, asset.MustNewPair("luna:usdt"), sdk.NewInt(-1), adminAddr) require.ErrorContains(t, err, "market luna:usdt not found") // Error because of invalid price multiplier - err = app.PerpKeeperV2.Admin.ShiftSwapInvariant(ctx, pair, sdk.NewInt(-1), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftSwapInvariant(ctx, pair, sdk.NewInt(-1), adminAddr) require.ErrorIs(t, err, types.ErrAmmNonPositiveSwapInvariant) // Add market activity @@ -284,15 +284,15 @@ func TestShiftSwapInvariant_Fail(t *testing.T) { require.NoError(t, err) // Error because no money in perp ef fund - err = app.PerpKeeperV2.Admin.ShiftSwapInvariant(ctx, pair, sdk.NewInt(2_000_000), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftSwapInvariant(ctx, pair, sdk.NewInt(2_000_000), adminAddr) require.ErrorContains(t, err, types.ErrNotEnoughFundToPayAction.Error()) // Fail at validate - err = app.PerpKeeperV2.Admin.ShiftSwapInvariant(ctx, pair, sdk.NewInt(0), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftSwapInvariant(ctx, pair, sdk.NewInt(0), adminAddr) require.ErrorContains(t, err, types.ErrAmmNonPositiveSwapInvariant.Error()) // Works because it goes in the other way - err = app.PerpKeeperV2.Admin.ShiftSwapInvariant(ctx, pair, sdk.NewInt(500_000), adminAddr) + err = app.PerpKeeperV2.Sudo().ShiftSwapInvariant(ctx, pair, sdk.NewInt(500_000), adminAddr) require.NoError(t, err) } @@ -308,14 +308,14 @@ func TestShiftSwapInvariant(t *testing.T) { WithSqrtDepth(sdk.NewDec(1e6)), ), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e12)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e6)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e6)), @@ -332,14 +332,14 @@ func TestShiftSwapInvariant(t *testing.T) { WithSqrtDepth(sdk.NewDec(1e6)), ), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e18)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e9)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e9)), @@ -352,14 +352,14 @@ func TestShiftSwapInvariant(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1e5)), WithSqrtDepth(sdk.NewDec(1e6))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e14)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1008101)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(991899)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(991899)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e7)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e7)), @@ -372,14 +372,14 @@ func TestShiftSwapInvariant(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalLong(sdk.NewDec(1e2)), WithSqrtDepth(sdk.NewDec(1e6))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e6)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(999991)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000009)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000009)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e3)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e3)), @@ -392,14 +392,14 @@ func TestShiftSwapInvariant(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalShort(sdk.NewDec(1e5)), WithSqrtDepth(sdk.NewDec(1e6))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e14)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1010102)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(989898)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(989898)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e7)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e7)), @@ -412,14 +412,14 @@ func TestShiftSwapInvariant(t *testing.T) { Given( CreateCustomMarket(pair, WithTotalShort(sdk.NewDec(1e2)), WithSqrtDepth(sdk.NewDec(1e6))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1e6)))), ). When( ShiftSwapInvariant(pair, sdk.NewInt(1e6)), ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(999989)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000011)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1000011)), AMMShouldBeEqual(pair, AMM_SqrtDepthShouldBeEqual(sdk.NewDec(1e3)), AMM_BaseReserveShouldBeEqual(sdk.NewDec(1e3)), @@ -437,7 +437,7 @@ func TestKeeper_GetMarketByPairAndVersion(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) - err := app.PerpKeeperV2.Admin.CreateMarket( + err := app.PerpKeeperV2.Sudo().CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, @@ -448,12 +448,12 @@ func TestKeeper_GetMarketByPairAndVersion(t *testing.T) { ) require.NoError(t, err) - market, err := app.PerpKeeperV2.Admin.GetMarketByPairAndVersion(ctx, pair, 1) + market, err := app.PerpKeeperV2.Sudo().GetMarketByPairAndVersion(ctx, pair, 1) require.NoError(t, err) require.Equal(t, market.Version, uint64(1)) require.Equal(t, market.Pair, pair) - market, err = app.PerpKeeperV2.Admin.GetMarketByPairAndVersion(ctx, pair, 2) + market, err = app.PerpKeeperV2.Sudo().GetMarketByPairAndVersion(ctx, pair, 2) require.ErrorContains(t, err, fmt.Sprintf("market with pair %s and version 2 not found", pair.String())) } @@ -462,7 +462,7 @@ func TestKeeper_GetAMMByPairAndVersion(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) - err := app.PerpKeeperV2.Admin.CreateMarket( + err := app.PerpKeeperV2.Sudo().CreateMarket( ctx, keeper.ArgsCreateMarket{ Pair: pair, @@ -473,11 +473,11 @@ func TestKeeper_GetAMMByPairAndVersion(t *testing.T) { ) require.NoError(t, err) - amm, err := app.PerpKeeperV2.Admin.GetAMMByPairAndVersion(ctx, pair, 1) + amm, err := app.PerpKeeperV2.Sudo().GetAMMByPairAndVersion(ctx, pair, 1) require.NoError(t, err) require.Equal(t, amm.Version, uint64(1)) require.Equal(t, amm.Pair, pair) - amm, err = app.PerpKeeperV2.Admin.GetAMMByPairAndVersion(ctx, pair, 2) + amm, err = app.PerpKeeperV2.Sudo().GetAMMByPairAndVersion(ctx, pair, 2) require.ErrorContains(t, err, fmt.Sprintf("amm with pair %s and version 2 not found", pair.String())) } diff --git a/x/perp/v2/keeper/clearing_house.go b/x/perp/v2/keeper/clearing_house.go index 65fe2e61d..1dedae8b0 100644 --- a/x/perp/v2/keeper/clearing_house.go +++ b/x/perp/v2/keeper/clearing_house.go @@ -685,7 +685,7 @@ func (k Keeper) transferFee( if err = k.BankKeeper.SendCoinsFromAccountToModule( ctx, /* from */ trader, - /* to */ types.PerpEFModuleAccount, + /* to */ types.PerpFundModuleAccount, /* coins */ sdk.NewCoins( sdk.NewCoin( collateral, diff --git a/x/perp/v2/keeper/clearing_house_test.go b/x/perp/v2/keeper/clearing_house_test.go index 3fcbb8305..a8f4c8021 100644 --- a/x/perp/v2/keeper/clearing_house_test.go +++ b/x/perp/v2/keeper/clearing_house_test.go @@ -43,7 +43,7 @@ func TestMarketOrder(t *testing.T) { FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200)))), FundAccount(bob, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), MarketOrder(alice, pairBtcNusd, types.Direction_SHORT, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()), MarketOrder(bob, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()), @@ -263,7 +263,7 @@ func TestMarketOrder(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_000)))), MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(9_000), sdk.NewDec(10), sdk.ZeroDec()), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ShiftSwapInvariant(pairBtcNusd, sdk.NewInt(1)), ). When( @@ -1273,7 +1273,7 @@ func TestPartialClose(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 2))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 27))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 27))), InsertPosition( WithPair(pairBtcNusd), WithTrader(alice), @@ -1493,7 +1493,7 @@ func TestPartialClose(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(18)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 48))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 48))), InsertPosition( WithPair(pairBtcNusd), WithTrader(alice), @@ -1679,7 +1679,7 @@ func TestClosePosition(t *testing.T) { ), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 18))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 1000))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 102))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 102))), ). When( MoveToNextBlock(), @@ -1709,7 +1709,7 @@ func TestClosePosition(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("-10000.000000000000000000"), }), ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1102)), // 1000 + 102 from perp ef - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(0)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(0)), ), TC("close short position with positive PnL"). @@ -1824,7 +1824,7 @@ func TestClosePosition(t *testing.T) { ), FundAccount(alice, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 22))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 1000))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 98))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 98))), ). When( MoveToNextBlock(), @@ -1854,7 +1854,7 @@ func TestClosePosition(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("10000.000000000000000000"), }), ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(1098)), // 1000 + 98 from perp ef - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(0)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(0)), ), } @@ -1876,7 +1876,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.ZeroDec()), @@ -1891,7 +1891,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_SHORT, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.NewDec(10_000_000_000_000)), @@ -1906,7 +1906,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.ZeroDec()), @@ -1926,7 +1926,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_SHORT, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.ZeroDec()), @@ -1947,7 +1947,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.ZeroDec()), @@ -1969,7 +1969,7 @@ func TestUpdateSwapInvariant(t *testing.T) { SetBlockTime(startBlockTime), SetBlockNumber(1), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(10_200_000_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_SHORT, sdk.NewInt(10_000_000_000), sdk.OneDec(), sdk.ZeroDec()), @@ -2015,7 +2015,7 @@ func TestUpdateSwapInvariant(t *testing.T) { PositionShouldNotExist(bob, pairBtcNusd, 1), ModuleBalanceShouldBeEqualTo(types.VaultModuleAccount, sdk.NewCoins()), - ModuleBalanceShouldBeEqualTo(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(39_960_000)))), + ModuleBalanceShouldBeEqualTo(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(39_960_000)))), ), TC("long and short position - reducing k"). Given( @@ -2047,7 +2047,7 @@ func TestUpdateSwapInvariant(t *testing.T) { PositionShouldNotExist(bob, pairBtcNusd, 1), ModuleBalanceShouldBeEqualTo(types.VaultModuleAccount, sdk.NewCoins()), - ModuleBalanceShouldBeEqualTo(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(39_960_000)))), + ModuleBalanceShouldBeEqualTo(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(39_960_000)))), ), } diff --git a/x/perp/v2/keeper/dnr_test.go b/x/perp/v2/keeper/dnr_test.go index 1dcab9e46..ced828f7c 100644 --- a/x/perp/v2/keeper/dnr_test.go +++ b/x/perp/v2/keeper/dnr_test.go @@ -38,7 +38,7 @@ func TestUserVolumes(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()), @@ -59,7 +59,7 @@ func TestUserVolumes(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( DnREpochIs(1), @@ -83,7 +83,7 @@ func TestUserVolumes(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ).When( DnREpochIs(1), MarketOrder(alice, pairBtcNusd, types.Direction_LONG, sdk.NewInt(10_000), sdk.OneDec(), sdk.ZeroDec()), // open epoch 1 @@ -126,7 +126,7 @@ func TestDiscount(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( DnREpochIs(1), @@ -147,7 +147,7 @@ func TestDiscount(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( SetGlobalDiscount(fauxGlobalFeeDiscount, sdk.NewInt(50_000)), @@ -172,7 +172,7 @@ func TestDiscount(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( SetGlobalDiscount(globalFeeDiscount, sdk.NewInt(50_000)), @@ -197,7 +197,7 @@ func TestDiscount(t *testing.T) { SetBlockTime(startBlockTime), FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(1000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(100_000_000)))), ). When( SetGlobalDiscount(sdk.MustNewDecFromStr("0.0004"), sdk.NewInt(50_000)), @@ -235,7 +235,7 @@ func TestRebates(t *testing.T) { FundAccount(alice, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(100_000)))), FundAccount(bob, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, positionSize.AddRaw(100_000)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(100_000_000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(100_000_000)))), ). When( DnREpochIs(1), diff --git a/x/perp/v2/keeper/grpc_query_test.go b/x/perp/v2/keeper/grpc_query_test.go index de30f16b9..80f119641 100644 --- a/x/perp/v2/keeper/grpc_query_test.go +++ b/x/perp/v2/keeper/grpc_query_test.go @@ -347,7 +347,7 @@ func TestQueryMarkets(t *testing.T) { WithEnabled(true), WithPricePeg(sdk.NewDec(2)), ), - FundModule("perp_ef", sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(denoms.NUSD, sdk.NewInt(10)))), ). When( InsertPosition( @@ -364,7 +364,7 @@ func TestQueryMarkets(t *testing.T) { ), QueryModuleAccounts(QueryModuleAccounts_ModulesBalanceShouldBe( map[string]sdk.Coins{ - "perp_ef": sdk.NewCoins( + types.PerpFundModuleAccount: sdk.NewCoins( sdk.NewCoin(denoms.BTC, sdk.ZeroInt()), sdk.NewCoin(denoms.NUSD, sdk.NewInt(10)), ), diff --git a/x/perp/v2/keeper/keeper.go b/x/perp/v2/keeper/keeper.go index 998e36b7f..309e6e124 100644 --- a/x/perp/v2/keeper/keeper.go +++ b/x/perp/v2/keeper/keeper.go @@ -28,9 +28,6 @@ type Keeper struct { EpochKeeper types.EpochKeeper SudoKeeper types.SudoKeeper - // Extends the Keeper with admin functions. See admin.go. - Admin admin - MarketLastVersion collections.Map[asset.Pair, types.MarketLastVersion] Markets collections.Map[collections.Pair[asset.Pair, uint64], types.Market] AMMs collections.Map[collections.Pair[asset.Pair, uint64], types.AMM] @@ -63,7 +60,7 @@ func NewKeeper( panic("The x/perp module account has not been set") } - k := Keeper{ + return Keeper{ cdc: cdc, storeKey: storeKey, BankKeeper: bankKeeper, @@ -134,8 +131,6 @@ func NewKeeper( common.StringValueEncoder, ), } - k.Admin = admin{&k} - return k } const ( diff --git a/x/perp/v2/keeper/liquidate.go b/x/perp/v2/keeper/liquidate.go index 25290ec09..3be649238 100644 --- a/x/perp/v2/keeper/liquidate.go +++ b/x/perp/v2/keeper/liquidate.go @@ -418,7 +418,7 @@ func (k Keeper) distributeLiquidateRewards( if err = k.BankKeeper.SendCoinsFromModuleToModule( ctx, /* from */ types.VaultModuleAccount, - /* to */ types.PerpEFModuleAccount, + /* to */ types.PerpFundModuleAccount, sdk.NewCoins(ecosystemFundFee), ); err != nil { return err diff --git a/x/perp/v2/keeper/liquidate_test.go b/x/perp/v2/keeper/liquidate_test.go index dc3ec4b6a..736dcd672 100644 --- a/x/perp/v2/keeper/liquidate_test.go +++ b/x/perp/v2/keeper/liquidate_test.go @@ -47,7 +47,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(750)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), PositionShouldBeEqual(alice, pairBtcUsdc, Position_PositionShouldBeEqualTo( @@ -81,7 +81,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(600)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), @@ -102,7 +102,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(600)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), @@ -124,7 +124,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(600)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), @@ -146,7 +146,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(600)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), @@ -158,7 +158,7 @@ func TestMultiLiquidate(t *testing.T) { CreateCustomMarket(pairBtcUsdc), InsertPosition(WithTrader(alice), WithPair(pairBtcUsdc), WithSize(sdk.NewDec(10000)), WithMargin(sdk.NewDec(1000)), WithOpenNotional(sdk.NewDec(10800))), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 1000))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 50))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewInt64Coin(types.TestingCollateralDenomNUSD, 50))), ). When( MoveToNextBlock(), @@ -168,7 +168,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(800)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), @@ -189,7 +189,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(750)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), MarketShouldBeEqual(pairBtcUsdc, Market_PrepaidBadDebtShouldBeEqualTo(sdk.ZeroInt(), types.TestingCollateralDenomNUSD)), @@ -211,7 +211,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), PositionShouldBeEqual(alice, pairBtcUsdc, Position_PositionShouldBeEqualTo( @@ -258,7 +258,7 @@ func TestMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(2350)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(275)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(275)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(375)), PositionShouldBeEqual(alice, pairBtcUsdc, Position_PositionShouldBeEqualTo( diff --git a/x/perp/v2/keeper/margin_test.go b/x/perp/v2/keeper/margin_test.go index f1cb16a80..45dbc7e02 100644 --- a/x/perp/v2/keeper/margin_test.go +++ b/x/perp/v2/keeper/margin_test.go @@ -71,7 +71,7 @@ func TestAddMargin(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("0"), }), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), ), @@ -121,7 +121,7 @@ func TestAddMargin(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("0"), }), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(10)), ), @@ -201,7 +201,7 @@ func TestRemoveMargin(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("0"), }), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(500)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ), @@ -228,7 +228,7 @@ func TestRemoveMargin(t *testing.T) { LastUpdatedBlockNumber: 1, })), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ), @@ -276,7 +276,7 @@ func TestRemoveMargin(t *testing.T) { ExchangedSize: sdk.MustNewDecFromStr("0"), }), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(500)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ), @@ -303,7 +303,7 @@ func TestRemoveMargin(t *testing.T) { LastUpdatedBlockNumber: 1, })), BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ModuleBalanceEqual(types.FeePoolModuleAccount, types.TestingCollateralDenomNUSD, sdk.OneInt()), ), } diff --git a/x/perp/v2/keeper/msg_server.go b/x/perp/v2/keeper/msg_server.go index 650526b41..6db05ede6 100644 --- a/x/perp/v2/keeper/msg_server.go +++ b/x/perp/v2/keeper/msg_server.go @@ -131,7 +131,7 @@ func (m msgServer) DonateToEcosystemFund(ctx context.Context, msg *types.MsgDona if err := m.k.BankKeeper.SendCoinsFromAccountToModule( sdk.UnwrapSDKContext(ctx), sdk.MustAccAddressFromBech32(msg.Sender), - types.PerpEFModuleAccount, + types.PerpFundModuleAccount, sdk.NewCoins(msg.Donation), ); err != nil { return nil, err @@ -141,7 +141,7 @@ func (m msgServer) DonateToEcosystemFund(ctx context.Context, msg *types.MsgDona } // ChangeCollateralDenom Updates the collateral denom. A denom is valid if it is -// possible to make an sdk.Coin using it. [Admin] Only callable by sudoers. +// possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers. func (m msgServer) ChangeCollateralDenom( goCtx context.Context, txMsg *types.MsgChangeCollateralDenom, ) (resp *types.MsgChangeCollateralDenomResponse, err error) { @@ -153,7 +153,7 @@ func (m msgServer) ChangeCollateralDenom( } ctx := sdk.UnwrapSDKContext(goCtx) - err = m.k.Admin.ChangeCollateralDenom(ctx, txMsg.NewDenom, txMsg.GetSigners()[0]) + err = m.k.Sudo().ChangeCollateralDenom(ctx, txMsg.NewDenom, txMsg.GetSigners()[0]) return &types.MsgChangeCollateralDenomResponse{}, err } @@ -196,25 +196,39 @@ func (m msgServer) WithdrawEpochRebates(ctx context.Context, msg *types.MsgWithd } // ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier. -// [Admin] Only callable by sudoers. +// [SUDO] Only callable by sudoers. func (m msgServer) ShiftPegMultiplier( goCtx context.Context, msg *types.MsgShiftPegMultiplier, ) (*types.MsgShiftPegMultiplierResponse, error) { // Sender is checked in `msg.ValidateBasic` before reaching this fn call. sender, _ := sdk.AccAddressFromBech32(msg.Sender) ctx := sdk.UnwrapSDKContext(goCtx) - err := m.k.Admin.ShiftPegMultiplier(ctx, msg.Pair, msg.NewPegMult, sender) + err := m.k.Sudo().ShiftPegMultiplier(ctx, msg.Pair, msg.NewPegMult, sender) return &types.MsgShiftPegMultiplierResponse{}, err } // ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant. -// [Admin] Only callable by sudoers. +// [SUDO] Only callable by sudoers. func (m msgServer) ShiftSwapInvariant( goCtx context.Context, msg *types.MsgShiftSwapInvariant, ) (*types.MsgShiftSwapInvariantResponse, error) { // Sender is checked in `msg.ValidateBasic` before reaching this fn call. sender, _ := sdk.AccAddressFromBech32(msg.Sender) ctx := sdk.UnwrapSDKContext(goCtx) - err := m.k.Admin.ShiftSwapInvariant(ctx, msg.Pair, msg.NewSwapInvariant, sender) + err := m.k.Sudo().ShiftSwapInvariant(ctx, msg.Pair, msg.NewSwapInvariant, sender) return &types.MsgShiftSwapInvariantResponse{}, err } + +// WithdrawFromPerpFund: gRPC tx msg for changing a market's swap invariant. +// [SUDO] Only callable by sudoers. +func (m msgServer) WithdrawFromPerpFund( + goCtx context.Context, msg *types.MsgWithdrawFromPerpFund, +) (resp *types.MsgWithdrawFromPerpFundResponse, err error) { + // Sender is checked in `msg.ValidateBasic` before reaching this fn call. + sender, _ := sdk.AccAddressFromBech32(msg.Sender) + toAddr, _ := sdk.AccAddressFromBech32(msg.ToAddr) + ctx := sdk.UnwrapSDKContext(goCtx) + return resp, m.k.Sudo().WithdrawFromPerpFund( + ctx, msg.Amount, sender, toAddr, msg.Denom, + ) +} diff --git a/x/perp/v2/keeper/msg_server_test.go b/x/perp/v2/keeper/msg_server_test.go index 0d357178a..736206169 100644 --- a/x/perp/v2/keeper/msg_server_test.go +++ b/x/perp/v2/keeper/msg_server_test.go @@ -246,7 +246,7 @@ func TestMsgServerDonateToPerpEf(t *testing.T) { ). Then( BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(50)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(50)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(50)), ), } @@ -276,7 +276,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(750)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(125)), PositionShouldBeEqual(alice, pairBtcUsdc, Position_PositionShouldBeEqualTo( @@ -309,7 +309,7 @@ func TestMsgServerMultiLiquidate(t *testing.T) { ). Then( ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(600)), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.NewInt(150)), BalanceEqual(liquidator, types.TestingCollateralDenomNUSD, sdk.NewInt(250)), PositionShouldNotExist(alice, pairBtcUsdc, 1), ), diff --git a/x/perp/v2/keeper/admin.go b/x/perp/v2/keeper/sudo.go similarity index 76% rename from x/perp/v2/keeper/admin.go rename to x/perp/v2/keeper/sudo.go index 78270101a..0da898072 100644 --- a/x/perp/v2/keeper/admin.go +++ b/x/perp/v2/keeper/sudo.go @@ -11,46 +11,54 @@ import ( types "github.com/NibiruChain/nibiru/x/perp/v2/types" ) -// Extends the Keeper with admin functions. Admin is syntactic sugar to separate -// admin calls off from the other Keeper methods. +// Sudo extends the Keeper with sudo functions. Sudo is syntactic sugar to separate +// sudoExtension calls off from the other Keeper methods. // -// These Admin functions should: -// 1. Not be wired into the MsgServer. -// 2. Not be called in other methods in the x/perp module. -// 3. Only be callable from nibiru/wasmbinding via sudo contracts. +// These Sudo functions should: +// 1. Not be called in other methods in the x/perp module. +// 2. Only be callable from the x/sudo root or sudo contracts. // -// The intention here is to make it more obvious to the developer that an unsafe -// function is being used when it's called from the PerpKeeper.Admin struct. -type admin struct{ *Keeper } - -/* -WithdrawFromInsuranceFund sends funds from the Insurance Fund to the given "to" -address. - -Args: -- ctx: Blockchain context holding the current state -- amount: Amount of micro-NUSD to withdraw. -- to: Recipient address -*/ -func (k admin) WithdrawFromInsuranceFund( - ctx sdk.Context, amount sdkmath.Int, to sdk.AccAddress, +// The intention behind "sudoExtension" is to make it more obvious to the +// developer that an unsafe function is being used when it's called from +// "PerpKeeper.Sudo()" +func (k Keeper) Sudo() sudoExtension { return sudoExtension{k} } + +type sudoExtension struct{ Keeper } + +// WithdrawFromPerpFund sends funds from the Perp Fund to the "to" address. +// +// Args: +// - ctx: Blockchain context holding the current state +// - amount: Amount of micro-NUSD to withdraw. +// - sender: Admin address registered in x/sudo +// - to: Recipient address +func (k sudoExtension) WithdrawFromPerpFund( + ctx sdk.Context, amount sdkmath.Int, sender, to sdk.AccAddress, denom string, ) (err error) { - collateral, err := k.Collateral.Get(ctx) - if err != nil { + if err := k.SudoKeeper.CheckPermissions(sender, ctx); err != nil { return err } - coinToSend := sdk.NewCoin(collateral, amount) + var collateralDenom string = denom + if denom == "" { + denomFromState, err := k.Collateral.Get(ctx) + if err != nil { + return err + } + collateralDenom = denomFromState + } + + coinToSend := sdk.NewCoin(collateralDenom, amount) if err = k.BankKeeper.SendCoinsFromModuleToAccount( ctx, - /* from */ types.PerpEFModuleAccount, + /* from */ types.PerpFundModuleAccount, /* to */ to, /* amount */ sdk.NewCoins(coinToSend), ); err != nil { return err } ctx.EventManager().EmitEvent(sdk.NewEvent( - "withdraw_from_if", + "withdraw_from_perp_fund", sdk.NewAttribute("to", to.String()), sdk.NewAttribute("funds", coinToSend.String()), )) @@ -68,7 +76,7 @@ type ArgsCreateMarket struct { } // CreateMarket creates a pool for a specific pair. -func (k admin) CreateMarket( +func (k sudoExtension) CreateMarket( ctx sdk.Context, args ArgsCreateMarket, ) error { @@ -121,7 +129,7 @@ func (k admin) CreateMarket( // CloseMarket closes the market. From now on, no new position can be opened on // this market or closed. Only the open positions can be settled by calling // SettlePosition. -func (k admin) CloseMarket(ctx sdk.Context, pair asset.Pair) (err error) { +func (k sudoExtension) CloseMarket(ctx sdk.Context, pair asset.Pair) (err error) { market, err := k.GetMarket(ctx, pair) if err != nil { return err @@ -150,8 +158,8 @@ func (k admin) CloseMarket(ctx sdk.Context, pair asset.Pair) (err error) { } // ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it is -// possible to make an sdk.Coin using it. [Admin] Only callable by sudoers. -func (k admin) ChangeCollateralDenom( +// possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers. +func (k sudoExtension) ChangeCollateralDenom( ctx sdk.Context, denom string, sender sdk.AccAddress, @@ -164,7 +172,7 @@ func (k admin) ChangeCollateralDenom( // UnsafeChangeCollateralDenom: Used in the genesis to set the collateral // without requiring an explicit call from sudoers. -func (k admin) UnsafeChangeCollateralDenom( +func (k sudoExtension) UnsafeChangeCollateralDenom( ctx sdk.Context, denom string, ) error { @@ -178,7 +186,7 @@ func (k admin) UnsafeChangeCollateralDenom( // ShiftPegMultiplier: Edit the peg multiplier of an amm pool after making sure // there's enough money in the perp fund to pay for the repeg. These funds get // send to the vault to pay for trader's new net margin. -func (k admin) ShiftPegMultiplier( +func (k sudoExtension) ShiftPegMultiplier( ctx sdk.Context, pair asset.Pair, newPriceMultiplier sdk.Dec, @@ -224,7 +232,7 @@ func (k admin) ShiftPegMultiplier( // ShiftSwapInvariant: Edit the swap invariant (liquidity depth) of an amm pool, // ensuring that there's enough money in the perp fund to pay for the operation. // These funds get send to the vault to pay for trader's new net margin. -func (k admin) ShiftSwapInvariant( +func (k sudoExtension) ShiftSwapInvariant( ctx sdk.Context, pair asset.Pair, newSwapInvariant sdkmath.Int, diff --git a/x/perp/v2/keeper/admin_test.go b/x/perp/v2/keeper/sudo_test.go similarity index 85% rename from x/perp/v2/keeper/admin_test.go rename to x/perp/v2/keeper/sudo_test.go index 365140995..9fdd4db63 100644 --- a/x/perp/v2/keeper/admin_test.go +++ b/x/perp/v2/keeper/sudo_test.go @@ -28,78 +28,70 @@ import ( . "github.com/NibiruChain/nibiru/x/perp/v2/integration/assertion" ) -func TestAdmin_WithdrawFromInsuranceFund(t *testing.T) { - expectBalance := func( - want sdkmath.Int, t *testing.T, nibiru *app.NibiruApp, ctx sdk.Context, - ) { - insuranceFund := nibiru.AccountKeeper.GetModuleAddress(perptypes.PerpEFModuleAccount) - balances := nibiru.BankKeeper.GetAllBalances(ctx, insuranceFund) - got := balances.AmountOf(perptypes.TestingCollateralDenomNUSD) - require.EqualValues(t, want.String(), got.String()) - } - - setup := func() (nibiru *app.NibiruApp, ctx sdk.Context) { - testapp.EnsureNibiruPrefix() - nibiru, ctx = testapp.NewNibiruTestAppAndContext() - expectBalance(sdk.ZeroInt(), t, nibiru, ctx) - nibiru.PerpKeeperV2.Collateral.Set(ctx, perptypes.TestingCollateralDenomNUSD) - return nibiru, ctx - } - - fundModule := func(t *testing.T, amount sdkmath.Int, ctx sdk.Context, nibiru *app.NibiruApp) { +func (s *TestSuiteAdmin) TestAdmin_WithdrawFromPerpFund() { + fundModule := func(amount sdkmath.Int, ctx sdk.Context, nibiru *app.NibiruApp) { coins := sdk.NewCoins(sdk.NewCoin(perptypes.TestingCollateralDenomNUSD, amount)) err := testapp.FundModuleAccount( - nibiru.BankKeeper, ctx, perptypes.PerpEFModuleAccount, + nibiru.BankKeeper, ctx, perptypes.PerpFundModuleAccount, coins, ) - require.NoError(t, err) + s.NoError(err) } testCases := []testutil.FunctionTestCase{ { Name: "withdraw all", Test: func() { - nibiru, ctx := setup() - admin := testutil.AccAddress() + s.SetupTest() + nibiru, ctx := s.nibiru, s.ctx + admin := s.addrAdmin amountToFund := sdk.NewInt(420) - fundModule(t, amountToFund, ctx, nibiru) + fundModule(amountToFund, ctx, nibiru) + balBefore := nibiru.BankKeeper.GetBalance(ctx, admin, perptypes.TestingCollateralDenomNUSD).Amount amountToWithdraw := amountToFund - err := nibiru.PerpKeeperV2.Admin.WithdrawFromInsuranceFund( - ctx, amountToWithdraw, admin) - require.NoError(t, err) + err := nibiru.PerpKeeperV2.Sudo().WithdrawFromPerpFund( + ctx, amountToWithdraw, admin, admin, "") + s.Require().NoError(err) - require.EqualValues(t, + balAfter := nibiru.BankKeeper.GetBalance(ctx, admin, perptypes.TestingCollateralDenomNUSD).Amount + s.EqualValues( amountToFund.String(), - nibiru.BankKeeper.GetBalance(ctx, admin, perptypes.TestingCollateralDenomNUSD).Amount.String(), + balAfter.Sub(balBefore).String(), ) - expectBalance(sdk.ZeroInt(), t, nibiru, ctx) + + perpFundAddr := nibiru.AccountKeeper.GetModuleAddress(perptypes.PerpFundModuleAccount) + got := nibiru.BankKeeper.GetAllBalances(ctx, perpFundAddr).AmountOf(perptypes.TestingCollateralDenomNUSD) + s.EqualValues(sdkmath.ZeroInt().String(), got.String()) }, }, { Name: "withdraw too much - err", Test: func() { - nibiru, ctx := setup() - admin := testutil.AccAddress() + s.SetupTest() + nibiru, ctx := s.nibiru, s.ctx + admin := s.addrAdmin amountToFund := sdk.NewInt(420) - fundModule(t, amountToFund, ctx, nibiru) + fundModule(amountToFund, ctx, nibiru) amountToWithdraw := amountToFund.MulRaw(5) - err := nibiru.PerpKeeperV2.Admin.WithdrawFromInsuranceFund( - ctx, amountToWithdraw, admin) - require.Error(t, err) + err := nibiru.PerpKeeperV2.Sudo().WithdrawFromPerpFund( + ctx, amountToWithdraw, admin, admin, "") + s.Require().Error(err) }, }, } - testutil.RunFunctionTests(t, testCases) + for _, tc := range testCases { + s.Run(tc.Name, tc.Test) + } } func TestCreateMarket(t *testing.T) { pair := asset.Registry.Pair(denoms.BTC, denoms.NUSD) amm := *mock.TestAMMDefault() app, ctx := testapp.NewNibiruTestAppAndContext() - admin := app.PerpKeeperV2.Admin + admin := app.PerpKeeperV2.Sudo() // Error because of invalid market market := perptypes.DefaultMarket(pair).WithMaintenanceMarginRatio(sdk.NewDec(2)) @@ -343,7 +335,7 @@ func TestAdmin_ChangeCollateralDenom(t *testing.T) { } { t.Run(tc.name, func(t *testing.T) { bapp, ctx := setup() - err := bapp.PerpKeeperV2.Admin.ChangeCollateralDenom( + err := bapp.PerpKeeperV2.Sudo().ChangeCollateralDenom( ctx, tc.newDenom, tc.sender, ) @@ -412,6 +404,8 @@ func (s *TestSuiteAdmin) HandleMsg(txMsg sdk.Msg) (err error) { _, err = s.perpMsgServer.ShiftSwapInvariant(ctx, msg) case *perptypes.MsgChangeCollateralDenom: _, err = s.perpMsgServer.ChangeCollateralDenom(ctx, msg) + case *perptypes.MsgWithdrawFromPerpFund: + _, err = s.perpMsgServer.WithdrawFromPerpFund(ctx, msg) default: return fmt.Errorf("unexpected message of type %T encountered", msg) } @@ -438,6 +432,12 @@ func (s *TestSuiteAdmin) TestCheckPermissions() { &perptypes.MsgChangeCollateralDenom{ Sender: sender, NewDenom: "newdenom", }, + &perptypes.MsgWithdrawFromPerpFund{ + Sender: sender, + Amount: sdk.NewInt(420), + Denom: "", + ToAddr: sender, + }, } { s.Run(fmt.Sprintf("%T", testCaseMsg), func() { err := s.HandleMsg(testCaseMsg) @@ -468,6 +468,24 @@ func (s *TestSuiteAdmin) DoShiftSwapInvariantTest(pair asset.Pair) error { return err } +func (s *TestSuiteAdmin) DoWithdrawFromPerpFundTest(toAddr string) error { + wantCoin := sdk.NewInt64Coin("perpfundtest", 25) + s.NoError( + testapp.FundModuleAccount( + s.nibiru.BankKeeper, s.ctx, types.PerpFundModuleAccount, + sdk.NewCoins(wantCoin)), + ) + _, err := s.perpMsgServer.WithdrawFromPerpFund( + sdk.WrapSDKContext(s.ctx), &perptypes.MsgWithdrawFromPerpFund{ + Sender: s.addrAdmin.String(), + Amount: wantCoin.Amount, + Denom: wantCoin.Denom, + ToAddr: toAddr, + }, + ) + return err +} + // TestAdmin_DoHappy: Happy path test cases func (s *TestSuiteAdmin) TestAdmin_DoHappy() { pair := asset.Registry.Pair(denoms.ATOM, denoms.NUSD) @@ -475,6 +493,7 @@ func (s *TestSuiteAdmin) TestAdmin_DoHappy() { for _, err := range []error{ s.DoShiftPegTest(pair), s.DoShiftSwapInvariantTest(pair), + s.DoWithdrawFromPerpFundTest(s.addrAdmin.String()), } { s.NoError(err) } diff --git a/x/perp/v2/keeper/withdraw.go b/x/perp/v2/keeper/withdraw.go index f39f4ab71..29c89ff23 100644 --- a/x/perp/v2/keeper/withdraw.go +++ b/x/perp/v2/keeper/withdraw.go @@ -62,7 +62,7 @@ func (k Keeper) WithdrawFromVault( if err := k.BankKeeper.SendCoinsFromModuleToModule( ctx, - types.PerpEFModuleAccount, + types.PerpFundModuleAccount, types.VaultModuleAccount, sdk.NewCoins( sdk.NewCoin(collateral, shortage), @@ -125,7 +125,7 @@ func (k Keeper) realizeBadDebt(ctx sdk.Context, market types.Market, badDebtToRe } return k.BankKeeper.SendCoinsFromModuleToModule(ctx, - /*from=*/ types.PerpEFModuleAccount, + /*from=*/ types.PerpFundModuleAccount, /*to=*/ types.VaultModuleAccount, sdk.NewCoins( sdk.NewCoin( diff --git a/x/perp/v2/keeper/withdraw_test.go b/x/perp/v2/keeper/withdraw_test.go index 5415c6b5c..040ff7e15 100644 --- a/x/perp/v2/keeper/withdraw_test.go +++ b/x/perp/v2/keeper/withdraw_test.go @@ -44,7 +44,7 @@ func TestWithdrawFromVault(t *testing.T) { SetBlockTime(startBlockTime), CreateCustomMarket(pairBtcUsdc), FundModule(types.VaultModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(500)))), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(500)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(500)))), ). When( WithdrawFromVault(pairBtcUsdc, alice, sdk.NewInt(1000)), @@ -52,7 +52,7 @@ func TestWithdrawFromVault(t *testing.T) { Then( BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(1000)), ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), MarketShouldBeEqual(pairBtcUsdc, Market_PrepaidBadDebtShouldBeEqualTo(sdk.NewInt(500), types.TestingCollateralDenomNUSD)), ), @@ -61,7 +61,7 @@ func TestWithdrawFromVault(t *testing.T) { SetBlockNumber(1), SetBlockTime(startBlockTime), CreateCustomMarket(pairBtcUsdc), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1000)))), ). When( WithdrawFromVault(pairBtcUsdc, alice, sdk.NewInt(1000)), @@ -69,7 +69,7 @@ func TestWithdrawFromVault(t *testing.T) { Then( BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(1000)), ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), MarketShouldBeEqual(pairBtcUsdc, Market_PrepaidBadDebtShouldBeEqualTo(sdk.NewInt(1000), types.TestingCollateralDenomNUSD)), ), @@ -78,7 +78,7 @@ func TestWithdrawFromVault(t *testing.T) { SetBlockNumber(1), SetBlockTime(startBlockTime), CreateCustomMarket(pairBtcUsdc, WithPrepaidBadDebt(sdk.NewInt(1000), types.TestingCollateralDenomNUSD)), - FundModule(types.PerpEFModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1000)))), + FundModule(types.PerpFundModuleAccount, sdk.NewCoins(sdk.NewCoin(types.TestingCollateralDenomNUSD, sdk.NewInt(1000)))), ). When( WithdrawFromVault(pairBtcUsdc, alice, sdk.NewInt(1000)), @@ -86,7 +86,7 @@ func TestWithdrawFromVault(t *testing.T) { Then( BalanceEqual(alice, types.TestingCollateralDenomNUSD, sdk.NewInt(1000)), ModuleBalanceEqual(types.VaultModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), - ModuleBalanceEqual(types.PerpEFModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), + ModuleBalanceEqual(types.PerpFundModuleAccount, types.TestingCollateralDenomNUSD, sdk.ZeroInt()), MarketShouldBeEqual(pairBtcUsdc, Market_PrepaidBadDebtShouldBeEqualTo(sdk.NewInt(2000), types.TestingCollateralDenomNUSD)), ), } diff --git a/x/perp/v2/module/abci_test.go b/x/perp/v2/module/abci_test.go index 4da2dbc78..164262f80 100644 --- a/x/perp/v2/module/abci_test.go +++ b/x/perp/v2/module/abci_test.go @@ -34,7 +34,7 @@ func TestSnapshotUpdates(t *testing.T) { ctx = ctx.WithBlockTime(time.Date(2015, 10, 21, 0, 0, 0, 0, time.UTC)).WithBlockHeight(1) - require.NoError(t, app.PerpKeeperV2.Admin.CreateMarket( + require.NoError(t, app.PerpKeeperV2.Sudo().CreateMarket( /* ctx */ ctx, keeper.ArgsCreateMarket{ Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), PriceMultiplier: initialAmm.PriceMultiplier, @@ -119,7 +119,7 @@ func TestEndBlocker(t *testing.T) { runBlock(5 * time.Second) - require.NoError(t, app.PerpKeeperV2.Admin.CreateMarket( + require.NoError(t, app.PerpKeeperV2.Sudo().CreateMarket( /* ctx */ ctx, keeper.ArgsCreateMarket{ Pair: asset.Registry.Pair(denoms.BTC, denoms.NUSD), PriceMultiplier: initialAmm.PriceMultiplier, diff --git a/x/perp/v2/module/genesis.go b/x/perp/v2/module/genesis.go index 623ae04c5..080bc5443 100644 --- a/x/perp/v2/module/genesis.go +++ b/x/perp/v2/module/genesis.go @@ -74,7 +74,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) } if genState.CollateralDenom != "" { - err := k.Admin.UnsafeChangeCollateralDenom(ctx, genState.CollateralDenom) + err := k.Sudo().UnsafeChangeCollateralDenom(ctx, genState.CollateralDenom) if err != nil { panic(err) } diff --git a/x/perp/v2/module/genesis_test.go b/x/perp/v2/module/genesis_test.go index 7844f8885..f92dcbf45 100644 --- a/x/perp/v2/module/genesis_test.go +++ b/x/perp/v2/module/genesis_test.go @@ -91,7 +91,7 @@ func RunTestGenesis(t *testing.T, tc TestCase) { app.SudoKeeper.Sudoers.Set(ctx, sudoers) // create some params - require.NoError(t, app.PerpKeeperV2.Admin.ChangeCollateralDenom( + require.NoError(t, app.PerpKeeperV2.Sudo().ChangeCollateralDenom( ctx, "unusd", sudoersRoot)) app.PerpKeeperV2.SaveMarket(ctx, *mock.TestMarket()) app.PerpKeeperV2.MarketLastVersion.Insert(ctx, pair, types.MarketLastVersion{Version: 1}) diff --git a/x/perp/v2/module/module.go b/x/perp/v2/module/module.go index c58d70c7a..8770bb84a 100644 --- a/x/perp/v2/module/module.go +++ b/x/perp/v2/module/module.go @@ -145,7 +145,7 @@ func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.Ra InitGenesis(ctx, am.keeper, genState) // See https://github.com/cosmos/cosmos-sdk/issues/5569 on why we do this. - am.ak.GetModuleAccount(ctx, types.PerpEFModuleAccount) + am.ak.GetModuleAccount(ctx, types.PerpFundModuleAccount) am.ak.GetModuleAccount(ctx, types.VaultModuleAccount) am.ak.GetModuleAccount(ctx, types.FeePoolModuleAccount) diff --git a/x/perp/v2/types/errors.go b/x/perp/v2/types/errors.go index abd3a008b..dd16027e9 100644 --- a/x/perp/v2/types/errors.go +++ b/x/perp/v2/types/errors.go @@ -50,6 +50,7 @@ var ( ErrSettlementPositionMarketEnabled = registerError("market is enabled, you can only settle position on disabled market") ErrCollateralDenomNotSet = registerError("ErrorCollateral: no collateral denom set for the perp keeper") ErrInvalidCollateral = registerError("ErrorCollateral: invalid collateral denom") + ErrGeneric = registerError("perp GenericError") ) // Register error instance for "ErrorMarketOrder" diff --git a/x/perp/v2/types/keys.go b/x/perp/v2/types/keys.go index 3ce91b28a..00e36f632 100644 --- a/x/perp/v2/types/keys.go +++ b/x/perp/v2/types/keys.go @@ -5,7 +5,7 @@ import "github.com/NibiruChain/nibiru/x/common" const ( ModuleName = "perp" VaultModuleAccount = "vault" - PerpEFModuleAccount = "perp_ef" + PerpFundModuleAccount = "perp_fund" FeePoolModuleAccount = "fee_pool" DNRAllocationModuleAccount = "dnr_allocation" DNREscrowModuleAccount = "dnr_escrow" @@ -26,7 +26,7 @@ var ( var ModuleAccounts = []string{ ModuleName, - PerpEFModuleAccount, + PerpFundModuleAccount, VaultModuleAccount, FeePoolModuleAccount, common.TreasuryPoolModuleAccount, diff --git a/x/perp/v2/types/msgs.go b/x/perp/v2/types/msgs.go index 2dbf0a380..d8173d516 100644 --- a/x/perp/v2/types/msgs.go +++ b/x/perp/v2/types/msgs.go @@ -21,6 +21,7 @@ var ( _ sdk.Msg = &MsgWithdrawEpochRebates{} _ sdk.Msg = &MsgShiftPegMultiplier{} _ sdk.Msg = &MsgShiftSwapInvariant{} + _ sdk.Msg = &MsgWithdrawFromPerpFund{} ) // ------------------------ MsgRemoveMargin ------------------------ @@ -407,3 +408,35 @@ func (m MsgShiftSwapInvariant) GetSigners() []sdk.AccAddress { func (m MsgShiftSwapInvariant) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) } + +// ------------------------ MsgWithdrawFromPerpFund ------------------------ + +func (m MsgWithdrawFromPerpFund) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(m.Sender); err != nil { + return fmt.Errorf("%w: invalid sender address (%s): %s", + errors.ErrInvalidAddress, m.Sender, err, + ) + } + if !m.Amount.IsPositive() { + return fmt.Errorf( + "%w: msg \"amount\" must be positive, got %s", ErrGeneric, m.Amount) + } + if _, err := sdk.AccAddressFromBech32(m.ToAddr); err != nil { + return fmt.Errorf("%w: invalid \"to_addr\" (%s): %s", + errors.ErrInvalidAddress, m.ToAddr, err, + ) + } + return nil +} + +func (m MsgWithdrawFromPerpFund) GetSigners() []sdk.AccAddress { + signer, err := sdk.AccAddressFromBech32(m.Sender) + if err != nil { + panic(err) + } + return []sdk.AccAddress{signer} +} + +func (m MsgWithdrawFromPerpFund) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) +} diff --git a/x/perp/v2/types/msgs_test.go b/x/perp/v2/types/msgs_test.go index 3b894bab1..fcc13e75c 100644 --- a/x/perp/v2/types/msgs_test.go +++ b/x/perp/v2/types/msgs_test.go @@ -4,6 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/common/asset" @@ -392,7 +393,8 @@ func TestMsgValidateBasic(t *testing.T) { expectErr: true, expectedError: ErrAmmNonPositivePegMult.Error(), }, - // MsgDonateToEcosystemFund test cases + + // MsgShiftSwapInvariant test cases { name: "MsgShiftSwapInvariant: Invalid pair", msg: &MsgShiftSwapInvariant{ @@ -423,6 +425,41 @@ func TestMsgValidateBasic(t *testing.T) { expectErr: true, expectedError: ErrAmmNonPositiveSwapInvariant.Error(), }, + + // MsgWithdrawFromPerpFund test cases + { + name: "MsgWithdrawFromPerpFund: invalid to addr", + msg: &MsgWithdrawFromPerpFund{ + Sender: validSender, + Amount: sdk.NewInt(420), // valid positive + Denom: "", + ToAddr: "invalidaddr", + }, + expectErr: true, + expectedError: sdkerrors.ErrInvalidAddress.Error(), + }, + { + name: "MsgWithdrawFromPerpFund: invalid sender", + msg: &MsgWithdrawFromPerpFund{ + Sender: "invalidaddr", + Amount: sdk.NewInt(420), // valid positive + Denom: "", + ToAddr: validSender, + }, + expectErr: true, + expectedError: sdkerrors.ErrInvalidAddress.Error(), + }, + { + name: "MsgWithdrawFromPerpFund: invalid amount", + msg: &MsgWithdrawFromPerpFund{ + Sender: validSender, + Amount: sdk.NewInt(-420), + Denom: "", + ToAddr: validSender, + }, + expectErr: true, + expectedError: ErrGeneric.Error(), + }, } for _, tc := range testCases { @@ -453,6 +490,7 @@ func TestMsg_GetSigners(t *testing.T) { &MsgMultiLiquidate{Sender: validSender}, &MsgShiftPegMultiplier{Sender: validSender}, &MsgShiftSwapInvariant{Sender: validSender}, + &MsgWithdrawFromPerpFund{Sender: validSender}, } msgInvalidSenderList := []sdk.Msg{ &MsgAddMargin{Sender: invalidSender}, @@ -465,6 +503,7 @@ func TestMsg_GetSigners(t *testing.T) { &MsgMultiLiquidate{Sender: invalidSender}, &MsgShiftPegMultiplier{Sender: invalidSender}, &MsgShiftSwapInvariant{Sender: invalidSender}, + &MsgWithdrawFromPerpFund{Sender: invalidSender}, } for _, msg := range msgValidSenderList { @@ -609,6 +648,10 @@ func TestMsg_GetSignBytes(t *testing.T) { name: "MsgShiftSwapInvariant", msg: &MsgShiftSwapInvariant{}, }, + { + name: "MsgWithdrawFromPerpFund", + msg: &MsgWithdrawFromPerpFund{}, + }, } for _, tc := range testCases { diff --git a/x/perp/v2/types/tx.pb.go b/x/perp/v2/types/tx.pb.go index a20200646..9b488a81b 100644 --- a/x/perp/v2/types/tx.pb.go +++ b/x/perp/v2/types/tx.pb.go @@ -915,7 +915,7 @@ func (m *MsgDonateToEcosystemFundResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgDonateToEcosystemFundResponse proto.InternalMessageInfo // MsgChangeCollateralDenom: Changes the collateral denom for the module. -// [Admin] Only callable by sudoers. +// [SUDO] Only callable by sudoers. type MsgChangeCollateralDenom struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` NewDenom string `protobuf:"bytes,2,opt,name=new_denom,json=newDenom,proto3" json:"new_denom,omitempty"` @@ -1199,8 +1199,8 @@ func (m *MsgWithdrawEpochRebatesResponse) GetWithdrawnRebates() github_com_cosmo return nil } -// ShiftPegMultiplier: gRPC tx msg for changing the peg multiplier. -// Admin-only. +// MsgShiftPegMultiplier: gRPC tx msg for changing the peg multiplier. +// [SUDO] Only callable sudoers. type MsgShiftPegMultiplier struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` Pair github_com_NibiruChain_nibiru_x_common_asset.Pair `protobuf:"bytes,2,opt,name=pair,proto3,customtype=github.com/NibiruChain/nibiru/x/common/asset.Pair" json:"pair"` @@ -1283,8 +1283,8 @@ func (m *MsgShiftPegMultiplierResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgShiftPegMultiplierResponse proto.InternalMessageInfo -// ShiftSwapInvariant: gRPC tx msg for changing the swap invariant. -// Admin-only. +// MsgShiftSwapInvariant: gRPC tx msg for changing the swap invariant. +// [SUDO] Only callable sudoers. type MsgShiftSwapInvariant struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` Pair github_com_NibiruChain_nibiru_x_common_asset.Pair `protobuf:"bytes,2,opt,name=pair,proto3,customtype=github.com/NibiruChain/nibiru/x/common/asset.Pair" json:"pair"` @@ -1367,6 +1367,106 @@ func (m *MsgShiftSwapInvariantResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgShiftSwapInvariantResponse proto.InternalMessageInfo +// MsgWithdrawFromPerpFund: gRPC tx msg for changing the swap invariant. +// [SUDO] Only callable sudoers. +type MsgWithdrawFromPerpFund struct { + Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=amount,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"amount"` + // Optional denom in case withdrawing assets aside from NUSD. + Denom string `protobuf:"bytes,3,opt,name=denom,proto3" json:"denom,omitempty"` + ToAddr string `protobuf:"bytes,4,opt,name=to_addr,json=toAddr,proto3" json:"to_addr,omitempty"` +} + +func (m *MsgWithdrawFromPerpFund) Reset() { *m = MsgWithdrawFromPerpFund{} } +func (m *MsgWithdrawFromPerpFund) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawFromPerpFund) ProtoMessage() {} +func (*MsgWithdrawFromPerpFund) Descriptor() ([]byte, []int) { + return fileDescriptor_b95cda40bf0a0f91, []int{25} +} +func (m *MsgWithdrawFromPerpFund) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawFromPerpFund) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawFromPerpFund.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawFromPerpFund) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawFromPerpFund.Merge(m, src) +} +func (m *MsgWithdrawFromPerpFund) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawFromPerpFund) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawFromPerpFund.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawFromPerpFund proto.InternalMessageInfo + +func (m *MsgWithdrawFromPerpFund) GetSender() string { + if m != nil { + return m.Sender + } + return "" +} + +func (m *MsgWithdrawFromPerpFund) GetDenom() string { + if m != nil { + return m.Denom + } + return "" +} + +func (m *MsgWithdrawFromPerpFund) GetToAddr() string { + if m != nil { + return m.ToAddr + } + return "" +} + +type MsgWithdrawFromPerpFundResponse struct { +} + +func (m *MsgWithdrawFromPerpFundResponse) Reset() { *m = MsgWithdrawFromPerpFundResponse{} } +func (m *MsgWithdrawFromPerpFundResponse) String() string { return proto.CompactTextString(m) } +func (*MsgWithdrawFromPerpFundResponse) ProtoMessage() {} +func (*MsgWithdrawFromPerpFundResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_b95cda40bf0a0f91, []int{26} +} +func (m *MsgWithdrawFromPerpFundResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgWithdrawFromPerpFundResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgWithdrawFromPerpFundResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgWithdrawFromPerpFundResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgWithdrawFromPerpFundResponse.Merge(m, src) +} +func (m *MsgWithdrawFromPerpFundResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgWithdrawFromPerpFundResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgWithdrawFromPerpFundResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgWithdrawFromPerpFundResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSettlePosition)(nil), "nibiru.perp.v2.MsgSettlePosition") proto.RegisterType((*MsgRemoveMargin)(nil), "nibiru.perp.v2.MsgRemoveMargin") @@ -1395,111 +1495,117 @@ func init() { proto.RegisterType((*MsgShiftPegMultiplierResponse)(nil), "nibiru.perp.v2.MsgShiftPegMultiplierResponse") proto.RegisterType((*MsgShiftSwapInvariant)(nil), "nibiru.perp.v2.MsgShiftSwapInvariant") proto.RegisterType((*MsgShiftSwapInvariantResponse)(nil), "nibiru.perp.v2.MsgShiftSwapInvariantResponse") + proto.RegisterType((*MsgWithdrawFromPerpFund)(nil), "nibiru.perp.v2.MsgWithdrawFromPerpFund") + proto.RegisterType((*MsgWithdrawFromPerpFundResponse)(nil), "nibiru.perp.v2.MsgWithdrawFromPerpFundResponse") } func init() { proto.RegisterFile("nibiru/perp/v2/tx.proto", fileDescriptor_b95cda40bf0a0f91) } var fileDescriptor_b95cda40bf0a0f91 = []byte{ - // 1570 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x59, 0xcd, 0x6f, 0x5b, 0xc5, - 0x16, 0xf7, 0x8d, 0xdd, 0x34, 0x39, 0x49, 0xf3, 0x71, 0x9b, 0x26, 0xae, 0x5f, 0x9f, 0x93, 0x77, - 0xf5, 0x5e, 0x5f, 0x58, 0xc4, 0x6e, 0x03, 0x12, 0x02, 0x09, 0x50, 0x3e, 0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 0x7b, - 0x6a, 0x4b, 0x89, 0xf5, 0xd6, 0xa6, 0xac, 0x9e, 0x46, 0x66, 0xf5, 0xed, 0x47, 0x4f, 0x8b, 0xda, - 0xe3, 0xa7, 0x45, 0xed, 0x97, 0xa7, 0x45, 0xed, 0xa3, 0xbd, 0x62, 0xe6, 0xf1, 0x5e, 0x31, 0xf3, - 0xc3, 0x5e, 0x31, 0x73, 0x67, 0xe9, 0xa0, 0x8e, 0x10, 0xff, 0x88, 0x26, 0xeb, 0xf7, 0xe6, 0xb0, - 0xff, 0x43, 0xd6, 0xcb, 0x7f, 0x04, 0x00, 0x00, 0xff, 0xff, 0x4e, 0xc7, 0xc2, 0xd7, 0x63, 0x1b, - 0x00, 0x00, + // 1648 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xec, 0x59, 0x5f, 0x6f, 0x1b, 0xc5, + 0x16, 0xf7, 0xc6, 0x8e, 0x93, 0x9c, 0xa4, 0xf9, 0xb3, 0x4d, 0x13, 0xd7, 0xb7, 0xd7, 0x49, 0x57, + 0xf7, 0xf6, 0xe6, 0x3e, 0xc4, 0x6e, 0x03, 0x12, 0x02, 0x09, 0x50, 0xfe, 0x34, 0xa8, 0xa8, 0x6e, + 0xdd, 0x4d, 0xd5, 0xa2, 0x52, 0xb4, 0x9d, 0x78, 0x27, 0x9b, 0x55, 0xd7, 0x33, 0xee, 0xce, 0xd8, + 0x4e, 0xca, 0x1b, 0x9f, 0x80, 0x07, 0x1e, 0x90, 0x90, 0x78, 0x43, 0x42, 0x3c, 0x20, 0xf5, 0x01, + 0x78, 0xe1, 0x03, 0xf4, 0xb1, 0x8f, 0x08, 0xa1, 0x82, 0x9a, 0x17, 0x5e, 0xa9, 0xf8, 0x00, 0x68, + 0xf6, 0x9f, 0x77, 0xdd, 0xb1, 0xe3, 0x98, 0x34, 0x12, 0x88, 0xa7, 0x64, 0x76, 0xce, 0xf9, 0x9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, 0x30, 0x6a, 0x0e, 0x46, 0x9a, 0xd8, 0x65, 0x36, 0x25, 0xb9, 0xf4, 0xa2, + 0xb2, 0x94, 0xd1, 0xc3, 0xa1, 0xf6, 0x48, 0x81, 0xa9, 0x32, 0xb3, 0x74, 0x5c, 0xa3, 0x4d, 0x5c, + 0x46, 0xae, 0x65, 0x9f, 0x98, 0x53, 0xaf, 0x41, 0xb6, 0xe6, 0x19, 0xf4, 0x7c, 0x1a, 0x5f, 0x39, + 0x5b, 0xf4, 0x83, 0x5e, 0x14, 0x41, 0x2f, 0x06, 0x41, 0x2f, 0xae, 0x53, 0x9b, 0xac, 0x65, 0x84, + 0x2d, 0x3d, 0x10, 0xd7, 0x7e, 0x55, 0x60, 0xbe, 0xc3, 0x67, 0x1d, 0xb3, 0x3a, 0x25, 0x0c, 0xab, + 0x6f, 0x01, 0xf8, 0x52, 0x06, 0x6d, 0x70, 0xcf, 0xff, 0x3e, 0x80, 0xc7, 0x7c, 0x95, 0xeb, 0x0d, + 0xae, 0xde, 0x86, 0xa9, 0x9d, 0x06, 0x31, 0x6d, 0x62, 0x19, 0x75, 0xb4, 0x5f, 0xc3, 0x84, 0x07, + 0x74, 0x8b, 0x01, 0xdd, 0x0b, 0x31, 0xba, 0x41, 0x91, 0xf8, 0x7f, 0x96, 0x99, 0x79, 0xbf, 0xc4, + 0xf7, 0xeb, 0x98, 0x15, 0x37, 0x70, 0x55, 0x9f, 0x0c, 0x60, 0x2a, 0x3e, 0x8a, 0xfa, 0x2a, 0x8c, + 0xd6, 0x83, 0xac, 0x07, 0x7c, 0x73, 0xc5, 0x64, 0x49, 0x16, 0xc3, 0xaa, 0xd0, 0x23, 0x49, 0xed, + 0x6b, 0x05, 0x26, 0xca, 0xcc, 0x5a, 0x35, 0xcd, 0xbf, 0x48, 0x6e, 0xbe, 0x50, 0x60, 0x36, 0xee, + 0x70, 0x94, 0x18, 0x49, 0x60, 0x95, 0x63, 0x0f, 0xec, 0x50, 0xdf, 0x81, 0xfd, 0xdd, 0x5f, 0x8e, + 0xe5, 0x86, 0xc3, 0xed, 0xab, 0xf6, 0x83, 0x86, 0x6d, 0x22, 0x8e, 0xbb, 0x46, 0xf7, 0x06, 0x4c, + 0x38, 0x81, 0x90, 0xd8, 0x24, 0x72, 0x43, 0x8b, 0xe9, 0xa5, 0xf1, 0x95, 0xe5, 0x4e, 0x3b, 0x2f, + 0x00, 0x16, 0xaf, 0xb6, 0xb5, 0xf4, 0x04, 0x44, 0x9e, 0xc3, 0x78, 0x6c, 0x32, 0xca, 0x9f, 0x72, + 0x3c, 0xf9, 0x9b, 0x83, 0x2c, 0x77, 0x91, 0x20, 0x32, 0xe4, 0x13, 0xf1, 0x47, 0xda, 0xb7, 0x69, + 0x38, 0xfb, 0x82, 0x97, 0x51, 0x8e, 0x50, 0x07, 0x4d, 0xc5, 0xa3, 0xf9, 0xe6, 0xa1, 0x34, 0x43, + 0x80, 0x04, 0xdd, 0xe0, 0x5b, 0x07, 0xed, 0x6f, 0x86, 0xe0, 0xb4, 0x44, 0x4a, 0xec, 0x50, 0xac, + 0x51, 0xad, 0x62, 0xc6, 0xbc, 0x10, 0x8c, 0xea, 0xe1, 0x50, 0x9d, 0x85, 0x61, 0xec, 0xba, 0x34, + 0x64, 0xe2, 0x0f, 0xd4, 0x4d, 0x98, 0x0c, 0x71, 0xa9, 0x6b, 0xec, 0x60, 0xdc, 0x5f, 0xa1, 0x2a, + 0xfa, 0xa9, 0xb6, 0xda, 0x26, 0xc6, 0xea, 0xdb, 0x30, 0x2e, 0x68, 0x19, 0x78, 0xc7, 0x03, 0xc9, + 0xf4, 0x07, 0x32, 0x26, 0x74, 0x2e, 0xef, 0x08, 0x80, 0x76, 0xa4, 0x87, 0xe3, 0x91, 0x8e, 0x12, + 0x9a, 0x3d, 0x96, 0x84, 0x6a, 0xdf, 0xa5, 0x61, 0x52, 0xc4, 0x1d, 0xb9, 0xf7, 0x31, 0xbf, 0xee, + 0x0a, 0x0b, 0x27, 0xb4, 0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dd, 0xad, 0xc9, 0x7b, 0x41, 0x22, 0x9e, 0x89, 0x4e, 0xd0, 0x2b, 0x9e, 0x71, + 0xc1, 0x9e, 0xf1, 0x94, 0xed, 0xd8, 0x5a, 0x6a, 0xed, 0x9d, 0xc7, 0xcf, 0x0a, 0xca, 0x93, 0x67, + 0x05, 0xe5, 0x97, 0x67, 0x05, 0xe5, 0xe3, 0x83, 0x42, 0xea, 0xc9, 0x41, 0x21, 0xf5, 0xc3, 0x41, + 0x21, 0x75, 0x67, 0xf9, 0xb0, 0x9e, 0x1a, 0xfd, 0x0c, 0x29, 0x5a, 0xcb, 0x76, 0xd6, 0xfb, 0x29, + 0xf0, 0x95, 0x3f, 0x02, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x7a, 0xd3, 0x25, 0xa5, 0x1c, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1523,16 +1629,19 @@ type MsgClient interface { SettlePosition(ctx context.Context, in *MsgSettlePosition, opts ...grpc.CallOption) (*MsgClosePositionResponse, error) DonateToEcosystemFund(ctx context.Context, in *MsgDonateToEcosystemFund, opts ...grpc.CallOption) (*MsgDonateToEcosystemFundResponse, error) // ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it - // is possible to make an sdk.Coin using it. [Admin] Only callable by sudoers. + // is possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers. ChangeCollateralDenom(ctx context.Context, in *MsgChangeCollateralDenom, opts ...grpc.CallOption) (*MsgChangeCollateralDenomResponse, error) AllocateEpochRebates(ctx context.Context, in *MsgAllocateEpochRebates, opts ...grpc.CallOption) (*MsgAllocateEpochRebatesResponse, error) WithdrawEpochRebates(ctx context.Context, in *MsgWithdrawEpochRebates, opts ...grpc.CallOption) (*MsgWithdrawEpochRebatesResponse, error) // ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. ShiftPegMultiplier(ctx context.Context, in *MsgShiftPegMultiplier, opts ...grpc.CallOption) (*MsgShiftPegMultiplierResponse, error) // ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. ShiftSwapInvariant(ctx context.Context, in *MsgShiftSwapInvariant, opts ...grpc.CallOption) (*MsgShiftSwapInvariantResponse, error) + // WithdrawFromPerpFund: gRPC tx msg to withdraw from the perp fund module + // account. [SUDO] Only callable by sudoers. + WithdrawFromPerpFund(ctx context.Context, in *MsgWithdrawFromPerpFund, opts ...grpc.CallOption) (*MsgWithdrawFromPerpFundResponse, error) } type msgClient struct { @@ -1660,6 +1769,15 @@ func (c *msgClient) ShiftSwapInvariant(ctx context.Context, in *MsgShiftSwapInva return out, nil } +func (c *msgClient) WithdrawFromPerpFund(ctx context.Context, in *MsgWithdrawFromPerpFund, opts ...grpc.CallOption) (*MsgWithdrawFromPerpFundResponse, error) { + out := new(MsgWithdrawFromPerpFundResponse) + err := c.cc.Invoke(ctx, "/nibiru.perp.v2.Msg/WithdrawFromPerpFund", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { RemoveMargin(context.Context, *MsgRemoveMargin) (*MsgRemoveMarginResponse, error) @@ -1671,16 +1789,19 @@ type MsgServer interface { SettlePosition(context.Context, *MsgSettlePosition) (*MsgClosePositionResponse, error) DonateToEcosystemFund(context.Context, *MsgDonateToEcosystemFund) (*MsgDonateToEcosystemFundResponse, error) // ChangeCollateralDenom: Updates the collateral denom. A denom is valid if it - // is possible to make an sdk.Coin using it. [Admin] Only callable by sudoers. + // is possible to make an sdk.Coin using it. [SUDO] Only callable by sudoers. ChangeCollateralDenom(context.Context, *MsgChangeCollateralDenom) (*MsgChangeCollateralDenomResponse, error) AllocateEpochRebates(context.Context, *MsgAllocateEpochRebates) (*MsgAllocateEpochRebatesResponse, error) WithdrawEpochRebates(context.Context, *MsgWithdrawEpochRebates) (*MsgWithdrawEpochRebatesResponse, error) // ShiftPegMultiplier: gRPC tx msg for changing a market's peg multiplier. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. ShiftPegMultiplier(context.Context, *MsgShiftPegMultiplier) (*MsgShiftPegMultiplierResponse, error) // ShiftSwapInvariant: gRPC tx msg for changing a market's swap invariant. - // [Admin] Only callable by sudoers. + // [SUDO] Only callable by sudoers. ShiftSwapInvariant(context.Context, *MsgShiftSwapInvariant) (*MsgShiftSwapInvariantResponse, error) + // WithdrawFromPerpFund: gRPC tx msg to withdraw from the perp fund module + // account. [SUDO] Only callable by sudoers. + WithdrawFromPerpFund(context.Context, *MsgWithdrawFromPerpFund) (*MsgWithdrawFromPerpFundResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1726,6 +1847,9 @@ func (*UnimplementedMsgServer) ShiftPegMultiplier(ctx context.Context, req *MsgS func (*UnimplementedMsgServer) ShiftSwapInvariant(ctx context.Context, req *MsgShiftSwapInvariant) (*MsgShiftSwapInvariantResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ShiftSwapInvariant not implemented") } +func (*UnimplementedMsgServer) WithdrawFromPerpFund(ctx context.Context, req *MsgWithdrawFromPerpFund) (*MsgWithdrawFromPerpFundResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WithdrawFromPerpFund not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -1965,6 +2089,24 @@ func _Msg_ShiftSwapInvariant_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +func _Msg_WithdrawFromPerpFund_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgWithdrawFromPerpFund) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).WithdrawFromPerpFund(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/nibiru.perp.v2.Msg/WithdrawFromPerpFund", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).WithdrawFromPerpFund(ctx, req.(*MsgWithdrawFromPerpFund)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "nibiru.perp.v2.Msg", HandlerType: (*MsgServer)(nil), @@ -2021,6 +2163,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ShiftSwapInvariant", Handler: _Msg_ShiftSwapInvariant_Handler, }, + { + MethodName: "WithdrawFromPerpFund", + Handler: _Msg_WithdrawFromPerpFund_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "nibiru/perp/v2/tx.proto", @@ -3324,6 +3470,83 @@ func (m *MsgShiftSwapInvariantResponse) MarshalToSizedBuffer(dAtA []byte) (int, return len(dAtA) - i, nil } +func (m *MsgWithdrawFromPerpFund) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawFromPerpFund) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawFromPerpFund) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.ToAddr) > 0 { + i -= len(m.ToAddr) + copy(dAtA[i:], m.ToAddr) + i = encodeVarintTx(dAtA, i, uint64(len(m.ToAddr))) + i-- + dAtA[i] = 0x22 + } + if len(m.Denom) > 0 { + i -= len(m.Denom) + copy(dAtA[i:], m.Denom) + i = encodeVarintTx(dAtA, i, uint64(len(m.Denom))) + i-- + dAtA[i] = 0x1a + } + { + size := m.Amount.Size() + i -= size + if _, err := m.Amount.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Sender) > 0 { + i -= len(m.Sender) + copy(dAtA[i:], m.Sender) + i = encodeVarintTx(dAtA, i, uint64(len(m.Sender))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgWithdrawFromPerpFundResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgWithdrawFromPerpFundResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgWithdrawFromPerpFundResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -3790,6 +4013,38 @@ func (m *MsgShiftSwapInvariantResponse) Size() (n int) { return n } +func (m *MsgWithdrawFromPerpFund) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Sender) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Amount.Size() + n += 1 + l + sovTx(uint64(l)) + l = len(m.Denom) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.ToAddr) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgWithdrawFromPerpFundResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -7496,6 +7751,236 @@ func (m *MsgShiftSwapInvariantResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgWithdrawFromPerpFund) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawFromPerpFund: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawFromPerpFund: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Sender", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Sender = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Amount.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Denom", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Denom = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ToAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ToAddr = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgWithdrawFromPerpFundResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgWithdrawFromPerpFundResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgWithdrawFromPerpFundResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 From 67b889ae08613919810d7152ff76bb37e98a0486 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 18:52:54 +0000 Subject: [PATCH 6/7] chore(deps): Bump github.com/cometbft/cometbft-db from 0.9.0 to 0.9.1 (#1760) * chore(deps): Bump github.com/cometbft/cometbft-db from 0.9.0 to 0.9.1 Bumps [github.com/cometbft/cometbft-db](https://github.com/cometbft/cometbft-db) from 0.9.0 to 0.9.1. - [Release notes](https://github.com/cometbft/cometbft-db/releases) - [Changelog](https://github.com/cometbft/cometbft-db/blob/main/CHANGELOG.md) - [Commits](https://github.com/cometbft/cometbft-db/compare/v0.9.0...v0.9.1) --------- Signed-off-by: dependabot[bot] Co-authored-by: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Co-authored-by: Unique-Divine --- CHANGELOG.md | 1 + go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5edd07f9..6d526c8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,6 +85,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1736](https://github.com/NibiruChain/nibiru/pull/1736) - test(sim): add sim genesis state for all cusom modules ### Dependencies +- Bump `github.com/cometbft/cometbft-db` from 0.9.0 to 0.9.1 ([#1760](https://github.com/NibiruChain/nibiru/pull/1760)) * Bump `github.com/prometheus/client_golang` from 1.17.0 to 1.18.0 ([#1750](https://github.com/NibiruChain/nibiru/pull/1750)) * Bump `google.golang.org/protobuf` from 1.31.0 to 1.32.0 ([#1756](https://github.com/NibiruChain/nibiru/pull/1756)) diff --git a/go.mod b/go.mod index da87be4ec..7a106ef7e 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/NibiruChain/collections v0.4.0 github.com/armon/go-metrics v0.4.1 github.com/cometbft/cometbft v0.37.2 - github.com/cometbft/cometbft-db v0.9.0 + github.com/cometbft/cometbft-db v0.9.1 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/go-bip39 v1.0.0 diff --git a/go.sum b/go.sum index a0e04d09c..e98f18df8 100644 --- a/go.sum +++ b/go.sum @@ -383,8 +383,8 @@ github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZ github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= github.com/cometbft/cometbft v0.37.2 h1:XB0yyHGT0lwmJlFmM4+rsRnczPlHoAKFX6K8Zgc2/Jc= github.com/cometbft/cometbft v0.37.2/go.mod h1:Y2MMMN//O5K4YKd8ze4r9jmk4Y7h0ajqILXbH5JQFVs= -github.com/cometbft/cometbft-db v0.9.0 h1:J+7haCZCddpM8DBESe6R7/ScnqigdQKph8V2yucApx8= -github.com/cometbft/cometbft-db v0.9.0/go.mod h1:iliyWaoV0mRwBJoizElCwwRA9Tf7jZJOURcRZF9m60U= +github.com/cometbft/cometbft-db v0.9.1 h1:MIhVX5ja5bXNHF8EYrThkG9F7r9kSfv8BX4LWaxWJ4M= +github.com/cometbft/cometbft-db v0.9.1/go.mod h1:iliyWaoV0mRwBJoizElCwwRA9Tf7jZJOURcRZF9m60U= github.com/confio/ics23/go v0.9.0 h1:cWs+wdbS2KRPZezoaaj+qBleXgUk5WOQFMP3CQFGTr4= github.com/confio/ics23/go v0.9.0/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= From c2a96d5c5ae1e305b35120a67ad2acdebac14e86 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Tue, 2 Jan 2024 01:39:55 +0100 Subject: [PATCH 7/7] remove mentions of bindings for creating the market. (#1757) Co-authored-by: Unique-Divine --- wasmbinding/bindings/msg.go | 8 ------ wasmbinding/exec_perp.go | 45 -------------------------------- wasmbinding/exec_perp_test.go | 48 ----------------------------------- wasmbinding/exec_test.go | 42 ------------------------------ wasmbinding/message_plugin.go | 8 ------ 5 files changed, 151 deletions(-) diff --git a/wasmbinding/bindings/msg.go b/wasmbinding/bindings/msg.go index 42532c059..40f20cfc8 100644 --- a/wasmbinding/bindings/msg.go +++ b/wasmbinding/bindings/msg.go @@ -15,7 +15,6 @@ type NibiruMsg struct { // bindings-perp ExecuteMsg enum types // MultiLiquidate *MultiLiquidate `json:"multi_liquidate,omitempty"` // TODO SetMarketEnabled *SetMarketEnabled `json:"set_market_enabled,omitempty"` - CreateMarket *CreateMarket `json:"create_market,omitempty"` EditOracleParams *EditOracleParams `json:"edit_oracle_params,omitempty"` @@ -41,13 +40,6 @@ type SetMarketEnabled struct { Enabled bool `json:"enabled"` } -type CreateMarket struct { - Pair string `json:"pair"` - PegMult sdk.Dec `json:"peg_mult,omitempty"` - SqrtDepth sdk.Dec `json:"sqrt_depth,omitempty"` - MarketParams *MarketParams `json:"market_params,omitempty"` -} - type MarketParams struct { Pair string Enabled bool `json:"enabled,omitempty"` diff --git a/wasmbinding/exec_perp.go b/wasmbinding/exec_perp.go index f3defcf01..5f5aca1b0 100644 --- a/wasmbinding/exec_perp.go +++ b/wasmbinding/exec_perp.go @@ -1,8 +1,6 @@ package wasmbinding import ( - "time" - wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,46 +33,3 @@ func (exec *ExecutorPerp) SetMarketEnabled( return exec.PerpV2.Sudo().CloseMarket(ctx, pair) } - -func (exec *ExecutorPerp) CreateMarket( - cwMsg *bindings.CreateMarket, ctx sdk.Context, -) (err error) { - if cwMsg == nil { - return wasmvmtypes.InvalidRequest{Err: "null msg"} - } - - pair, err := asset.TryNewPair(cwMsg.Pair) - if err != nil { - return err - } - - var market perpv2types.Market - if cwMsg.MarketParams == nil { - market = perpv2types.DefaultMarket(pair) - } else { - mp := cwMsg.MarketParams - market = perpv2types.Market{ - Pair: pair, - Enabled: true, - MaintenanceMarginRatio: mp.MaintenanceMarginRatio, - MaxLeverage: mp.MaxLeverage, - LatestCumulativePremiumFraction: mp.LatestCumulativePremiumFraction, - ExchangeFeeRatio: mp.ExchangeFeeRatio, - EcosystemFundFeeRatio: mp.EcosystemFundFeeRatio, - LiquidationFeeRatio: mp.LiquidationFeeRatio, - PartialLiquidationRatio: mp.PartialLiquidationRatio, - FundingRateEpochId: mp.FundingRateEpochId, - MaxFundingRate: mp.MaxFundingRate, - TwapLookbackWindow: time.Duration(mp.TwapLookbackWindow.Int64()), - PrepaidBadDebt: sdk.NewCoin(pair.QuoteDenom(), sdk.ZeroInt()), - OraclePair: asset.MustNewPair(mp.OraclePair), - } - } - - return exec.PerpV2.Sudo().CreateMarket(ctx, perpv2keeper.ArgsCreateMarket{ - Pair: pair, - PriceMultiplier: cwMsg.PegMult, - SqrtDepth: cwMsg.SqrtDepth, - Market: &market, - }) -} diff --git a/wasmbinding/exec_perp_test.go b/wasmbinding/exec_perp_test.go index e25571d42..d1f373225 100644 --- a/wasmbinding/exec_perp_test.go +++ b/wasmbinding/exec_perp_test.go @@ -131,52 +131,6 @@ func (s *TestSuitePerpExecutor) OnSetupEnd() { s.ratesMap = SetExchangeRates(&s.Suite, s.nibiru, s.ctx) } -// Happy path coverage -func (s *TestSuitePerpExecutor) TestPerpExecutorHappy() { - for _, err := range []error{ - s.DoCreateMarketTest(asset.MustNewPair("ufoo:ubar")), - s.DoCreateMarketTestWithParams(asset.MustNewPair("ufoo2:ubar")), - } { - s.NoError(err) - } -} - -func (s *TestSuitePerpExecutor) DoCreateMarketTest(pair asset.Pair) error { - cwMsg := &bindings.CreateMarket{ - Pair: pair.String(), - PegMult: sdk.NewDec(2_500), - SqrtDepth: sdk.NewDec(1_000), - MarketParams: nil, - } - - return s.exec.CreateMarket(cwMsg, s.ctx) -} - -func (s *TestSuitePerpExecutor) DoCreateMarketTestWithParams(pair asset.Pair) error { - cwMsg := &bindings.CreateMarket{ - Pair: pair.String(), - PegMult: sdk.NewDec(2_500), - SqrtDepth: sdk.NewDec(1_000), - MarketParams: &bindings.MarketParams{ - Pair: pair.String(), - Enabled: true, - MaintenanceMarginRatio: sdk.OneDec(), - MaxLeverage: sdk.OneDec(), - LatestCumulativePremiumFraction: sdk.OneDec(), - ExchangeFeeRatio: sdk.OneDec(), - EcosystemFundFeeRatio: sdk.OneDec(), - LiquidationFeeRatio: sdk.OneDec(), - PartialLiquidationRatio: sdk.OneDec(), - FundingRateEpochId: "hi", - MaxFundingRate: sdk.OneDec(), - TwapLookbackWindow: sdk.OneInt(), - OraclePair: pair.String(), - }, - } - - return s.exec.CreateMarket(cwMsg, s.ctx) -} - func (s *TestSuitePerpExecutor) DoSetMarketEnabledTest( pair asset.Pair, enabled bool, ) error { @@ -202,8 +156,6 @@ func (s *TestSuitePerpExecutor) TestSadPaths_InvalidPair() { for _, err := range []error{ s.DoSetMarketEnabledTest(pair, true), s.DoSetMarketEnabledTest(pair, false), - s.DoCreateMarketTest(pair), - s.DoCreateMarketTestWithParams(pair), } { s.Error(err) } diff --git a/wasmbinding/exec_test.go b/wasmbinding/exec_test.go index cdbc5776c..019a7aa21 100644 --- a/wasmbinding/exec_test.go +++ b/wasmbinding/exec_test.go @@ -355,45 +355,3 @@ func (s *TestSuiteExecutor) TestSetMarketEnabled() { s.Errorf(err, "contractRespBz: %s", contractRespBz) s.Contains(err.Error(), "Error parsing into type") } - -func (s *TestSuiteExecutor) TestCreateMarket() { - contract := s.contractController - pair := asset.MustNewPair("bloop:blam") - execMsg := bindings.NibiruMsg{ - CreateMarket: &bindings.CreateMarket{ - Pair: pair.String(), - PegMult: sdk.NewDec(420), - SqrtDepth: sdk.NewDec(1_000), - MarketParams: nil, - }, - } - - s.T().Logf("Execute - happy: market: %s", pair) - s.keeper.SetSudoContracts( - []string{contract.String()}, s.ctx, - ) - contractRespBz, err := s.ExecuteAgainstContract(contract, execMsg) - s.NoErrorf(err, "contractRespBz: %s", contractRespBz) - - market, err := s.nibiru.PerpKeeperV2.GetMarket(s.ctx, pair) - s.NoError(err) - s.NoError(market.Validate()) - s.False(market.Enabled, "by default, we create a market in a disabled state") - s.EqualValues(pair, market.Pair) - - s.T().Log("Executing without permission should fail") - s.keeper.SetSudoContracts( - []string{}, s.ctx, - ) - contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - - s.T().Log("Executing the wrong contract should fail") - contract = s.contractPerp - s.keeper.SetSudoContracts( - []string{contract.String()}, s.ctx, - ) - contractRespBz, err = s.ExecuteAgainstContract(contract, execMsg) - s.Errorf(err, "contractRespBz: %s", contractRespBz) - s.Contains(err.Error(), "Error parsing into type") -} diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 6642c90dd..2bf63e8f0 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -63,14 +63,6 @@ func (messenger *CustomMessenger) DispatchMsg( switch { // Perp module | controller - case contractExecuteMsg.ExecuteMsg.CreateMarket != nil: - if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil { - return events, data, err - } - cwMsg := contractExecuteMsg.ExecuteMsg.CreateMarket - err = messenger.Perp.CreateMarket(cwMsg, ctx) - return events, data, err - case contractExecuteMsg.ExecuteMsg.SetMarketEnabled != nil: if err := messenger.Sudo.CheckPermissions(contractAddr, ctx); err != nil { return events, data, err