Skip to content

Commit

Permalink
re-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
albertchon committed Oct 29, 2021
1 parent aafc8fe commit f8be4ba
Show file tree
Hide file tree
Showing 5 changed files with 494 additions and 182 deletions.
2 changes: 2 additions & 0 deletions chain/exchange/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&TradingRewardCampaignLaunchProposal{}, "exchange/TradingRewardCampaignLaunchProposal", nil)
cdc.RegisterConcrete(&TradingRewardCampaignUpdateProposal{}, "exchange/TradingRewardCampaignUpdateProposal", nil)
cdc.RegisterConcrete(&FeeDiscountProposal{}, "exchange/FeeDiscountProposal", nil)
cdc.RegisterConcrete(&BatchCommunityPoolSpendProposal{}, "exchange/BatchCommunityPoolSpendProposal", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
Expand Down Expand Up @@ -79,6 +80,7 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&TradingRewardCampaignLaunchProposal{},
&TradingRewardCampaignUpdateProposal{},
&FeeDiscountProposal{},
&BatchCommunityPoolSpendProposal{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
8 changes: 4 additions & 4 deletions chain/exchange/types/common_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (s *Subaccount) GetSubaccountID() (*common.Hash, error) {
return SdkAddressWithNonceToSubaccountID(trader, s.SubaccountNonce)
}

func SdkAddressWithNonceToSubaccountID(addr sdk.Address, nonce uint32) (*common.Hash, error) {
func SdkAddressWithNonceToSubaccountID(addr sdk.AccAddress, nonce uint32) (*common.Hash, error) {
if len(addr.Bytes()) > common.AddressLength {
return &AuctionSubaccountID, ErrBadSubaccountID
}
Expand All @@ -145,15 +145,15 @@ func SdkAddressWithNonceToSubaccountID(addr sdk.Address, nonce uint32) (*common.
return &subaccountID, nil
}

func SdkAddressToSubaccountID(addr sdk.Address) common.Hash {
func SdkAddressToSubaccountID(addr sdk.AccAddress) common.Hash {
return common.BytesToHash(common.RightPadBytes(addr.Bytes(), 32))
}

func SdkAddressToEthAddress(addr sdk.Address) common.Address {
func SdkAddressToEthAddress(addr sdk.AccAddress) common.Address {
return common.BytesToAddress(addr.Bytes())
}

func SubaccountIDToSdkAddress(subaccountID common.Hash) sdk.Address {
func SubaccountIDToSdkAddress(subaccountID common.Hash) sdk.AccAddress {
return sdk.AccAddress(subaccountID[:common.AddressLength])
}

Expand Down
2 changes: 1 addition & 1 deletion chain/exchange/types/derivative_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/ethereum/go-ethereum/common"
)

func NewMarketOrderForLiquidation(position *Position, positionSubaccountID common.Hash, liquidator sdk.Address) *DerivativeMarketOrder {
func NewMarketOrderForLiquidation(position *Position, positionSubaccountID common.Hash, liquidator sdk.AccAddress) *DerivativeMarketOrder {

// if long position, market sell order at price 0
// if short position, market buy order at price infinity
Expand Down
64 changes: 54 additions & 10 deletions chain/exchange/types/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import (
oracletypes "github.com/InjectiveLabs/sdk-go/chain/oracle/types"

sdk "github.com/cosmos/cosmos-sdk/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
gov "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/ethereum/go-ethereum/common"
)

// constants
const (
ProposalTypeExchangeEnable string = "ProposalTypeExchangeEnable"
ProposalTypeBatchExchangeModification string = "ProposalTypeBatchExchangeModification"
ProposalTypeSpotMarketParamUpdate string = "ProposalTypeSpotMarketParamUpdate"
ProposalTypeSpotMarketLaunch string = "ProposalTypeSpotMarketLaunch"
ProposalTypePerpetualMarketLaunch string = "ProposalTypePerpetualMarketLaunch"
ProposalTypeExpiryFuturesMarketLaunch string = "ProposalTypeExpiryFuturesMarketLaunch"
ProposalTypeDerivativeMarketParamUpdate string = "ProposalTypeDerivativeMarketParamUpdate"
ProposalTypeTradingRewardCampaign string = "ProposalTypeTradingRewardCampaign"
ProposalTypeTradingRewardCampaignUpdate string = "ProposalTypeTradingRewardCampaignUpdateProposal"
ProposalTypeFeeDiscountProposal string = "ProposalTypeFeeDiscountProposal"
ProposalTypeExchangeEnable string = "ProposalTypeExchangeEnable"
ProposalTypeBatchExchangeModification string = "ProposalTypeBatchExchangeModification"
ProposalTypeSpotMarketParamUpdate string = "ProposalTypeSpotMarketParamUpdate"
ProposalTypeSpotMarketLaunch string = "ProposalTypeSpotMarketLaunch"
ProposalTypePerpetualMarketLaunch string = "ProposalTypePerpetualMarketLaunch"
ProposalTypeExpiryFuturesMarketLaunch string = "ProposalTypeExpiryFuturesMarketLaunch"
ProposalTypeDerivativeMarketParamUpdate string = "ProposalTypeDerivativeMarketParamUpdate"
ProposalTypeTradingRewardCampaign string = "ProposalTypeTradingRewardCampaign"
ProposalTypeTradingRewardCampaignUpdate string = "ProposalTypeTradingRewardCampaignUpdateProposal"
ProposalTypeFeeDiscountProposal string = "ProposalTypeFeeDiscountProposal"
ProposalTypeBatchCommunityPoolSpendProposal string = "ProposalTypeBatchCommunityPoolSpendProposal"
)

func init() {
Expand All @@ -45,6 +47,8 @@ func init() {
gov.RegisterProposalTypeCodec(&TradingRewardCampaignUpdateProposal{}, "injective/TradingRewardCampaignUpdateProposal")
gov.RegisterProposalType(ProposalTypeFeeDiscountProposal)
gov.RegisterProposalTypeCodec(&FeeDiscountProposal{}, "injective/FeeDiscountProposal")
gov.RegisterProposalType(ProposalTypeBatchCommunityPoolSpendProposal)
gov.RegisterProposalTypeCodec(&BatchCommunityPoolSpendProposal{}, "injective/BatchCommunityPoolSpendProposal")
}

func SafeIsPositiveInt(v sdk.Int) bool {
Expand Down Expand Up @@ -1050,3 +1054,43 @@ func (t *FeeDiscountTierInfo) ValidateBasic() error {
}
return nil
}

// NewBatchCommunityPoolSpendProposal returns new instance of BatchCommunityPoolSpendProposal
func NewBatchCommunityPoolSpendProposal(title, description string, proposals []*distributiontypes.CommunityPoolSpendProposal) *BatchCommunityPoolSpendProposal {
return &BatchCommunityPoolSpendProposal{
Title: title,
Description: description,
Proposals: proposals,
}
}

// Implements Proposal Interface
var _ gov.Content = &BatchCommunityPoolSpendProposal{}

// GetTitle returns the title of this proposal.
func (p *BatchCommunityPoolSpendProposal) GetTitle() string {
return p.Title
}

// GetDescription returns the description of this proposal.
func (p *BatchCommunityPoolSpendProposal) GetDescription() string {
return p.Description
}

// ProposalRoute returns router key of this proposal.
func (p *BatchCommunityPoolSpendProposal) ProposalRoute() string { return RouterKey }

// ProposalType returns proposal type of this proposal.
func (p *BatchCommunityPoolSpendProposal) ProposalType() string {
return ProposalTypeBatchCommunityPoolSpendProposal
}

// ValidateBasic returns ValidateBasic result of this proposal.
func (p *BatchCommunityPoolSpendProposal) ValidateBasic() error {
for _, proposal := range p.Proposals {
if err := proposal.ValidateBasic(); err != nil {
return err
}
}
return gov.ValidateAbstract(p)
}
Loading

0 comments on commit f8be4ba

Please sign in to comment.