Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gov module support to work with both v1beta1 and v1 message types #519

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ var messageTypeHandler = map[string][]func() txtypes.CosmosMessage{
distribution.MsgFundCommunityPool: {func() txtypes.CosmosMessage { return &distribution.WrapperMsgFundCommunityPool{} }},
gov.MsgDeposit: {func() txtypes.CosmosMessage { return &gov.WrapperMsgDeposit{} }},
gov.MsgSubmitProposal: {func() txtypes.CosmosMessage { return &gov.WrapperMsgSubmitProposal{} }},
gov.MsgDepositV1: {func() txtypes.CosmosMessage { return &gov.WrapperMsgDepositV1{} }},
gov.MsgSubmitProposalV1: {func() txtypes.CosmosMessage { return &gov.WrapperMsgSubmitProposalV1{} }},
staking.MsgDelegate: {func() txtypes.CosmosMessage { return &staking.WrapperMsgDelegate{} }},
staking.MsgUndelegate: {func() txtypes.CosmosMessage { return &staking.WrapperMsgUndelegate{} }},
staking.MsgBeginRedelegate: {func() txtypes.CosmosMessage { return &staking.WrapperMsgBeginRedelegate{} }},
Expand All @@ -70,8 +72,10 @@ var messageTypeIgnorer = map[string]interface{}{
// Making a stableswap config change is not taxable
gamm.MsgStableSwapAdjustScalingFactors: nil,
// Voting is not taxable
gov.MsgVote: nil,
gov.MsgVoteWeighted: nil,
gov.MsgVote: nil,
gov.MsgVoteWeighted: nil,
gov.MsgVoteV1: nil,
gov.MsgVoteWeightedV1: nil,
// The IBC msgs below do not create taxable events
ibc.MsgTransfer: nil,
ibc.MsgUpdateClient: nil,
Expand Down
179 changes: 173 additions & 6 deletions cosmos/modules/gov/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/util"
stdTypes "github.com/cosmos/cosmos-sdk/types"
bankTypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govTypesV1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govTypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
)

const (
MsgVote = "/cosmos.gov.v1beta1.MsgVote"
MsgDeposit = "/cosmos.gov.v1beta1.MsgDeposit" // handle additional deposits to the given proposal
MsgSubmitProposal = "/cosmos.gov.v1beta1.MsgSubmitProposal" // handle the initial deposit for the proposer
MsgVoteWeighted = "/cosmos.gov.v1beta1.MsgVoteWeighted"
MsgVote = "/cosmos.gov.v1beta1.MsgVote"
MsgDeposit = "/cosmos.gov.v1beta1.MsgDeposit" // handle additional deposits to the given proposal
MsgSubmitProposal = "/cosmos.gov.v1beta1.MsgSubmitProposal" // handle the initial deposit for the proposer
MsgVoteWeighted = "/cosmos.gov.v1beta1.MsgVoteWeighted"
MsgVoteV1 = "/cosmos.gov.v1.MsgVote"
MsgDepositV1 = "/cosmos.gov.v1.MsgDeposit" // handle additional deposits to the given proposal
MsgSubmitProposalV1 = "/cosmos.gov.v1.MsgSubmitProposal" // handle the initial deposit for the proposer
MsgVoteWeightedV1 = "/cosmos.gov.v1.MsgVoteWeighted"
)

type WrapperMsgSubmitProposal struct {
Expand All @@ -35,6 +40,22 @@ type WrapperMsgDeposit struct {
DepositReceiverAddress string
}

type WrapperMsgSubmitProposalV1 struct {
txModule.Message
CosmosMsgSubmitProposal *govTypesV1.MsgSubmitProposal
CoinReceived stdTypes.Coin
MultiCoinsReceived stdTypes.Coins
DepositReceiverAddress string
}

type WrapperMsgDepositV1 struct {
txModule.Message
CosmosMsgDeposit *govTypesV1.MsgDeposit
CoinReceived stdTypes.Coin
MultiCoinsReceived stdTypes.Coins
DepositReceiverAddress string
}

func (sf *WrapperMsgSubmitProposal) ParseRelevantData() []parsingTypes.MessageRelevantInformation {
relevantData := make([]parsingTypes.MessageRelevantInformation, len(sf.CosmosMsgSubmitProposal.InitialDeposit))

Expand Down Expand Up @@ -79,6 +100,50 @@ func (sf *WrapperMsgDeposit) ParseRelevantData() []parsingTypes.MessageRelevantI
return relevantData
}

func (sf *WrapperMsgSubmitProposalV1) ParseRelevantData() []parsingTypes.MessageRelevantInformation {
relevantData := make([]parsingTypes.MessageRelevantInformation, len(sf.CosmosMsgSubmitProposal.InitialDeposit))

for i, v := range sf.CosmosMsgSubmitProposal.InitialDeposit {
var currRelevantData parsingTypes.MessageRelevantInformation
currRelevantData.SenderAddress = sf.CosmosMsgSubmitProposal.Proposer
currRelevantData.ReceiverAddress = sf.DepositReceiverAddress

// Amount always seems to be an integer, float may be an extra unneeded step
currRelevantData.AmountSent = v.Amount.BigInt()
currRelevantData.DenominationSent = v.Denom

// This is required since we do CSV parsing on the receiver here too
currRelevantData.AmountReceived = v.Amount.BigInt()
currRelevantData.DenominationReceived = v.Denom

relevantData[i] = currRelevantData
}

return relevantData
}

func (sf *WrapperMsgDepositV1) ParseRelevantData() []parsingTypes.MessageRelevantInformation {
relevantData := make([]parsingTypes.MessageRelevantInformation, len(sf.CosmosMsgDeposit.Amount))

for i, v := range sf.CosmosMsgDeposit.Amount {
var currRelevantData parsingTypes.MessageRelevantInformation
currRelevantData.SenderAddress = sf.CosmosMsgDeposit.Depositor
currRelevantData.ReceiverAddress = sf.DepositReceiverAddress

// Amount always seems to be an integer, float may be an extra unneeded step
currRelevantData.AmountSent = v.Amount.BigInt()
currRelevantData.DenominationSent = v.Denom

// This is required since we do CSV parsing on the receiver here too
currRelevantData.AmountReceived = v.Amount.BigInt()
currRelevantData.DenominationReceived = v.Denom

relevantData[i] = currRelevantData
}

return relevantData
}

// Proposal with an initial deposit
func (sf *WrapperMsgSubmitProposal) HandleMsg(msgType string, msg stdTypes.Msg, log *txModule.LogMessage) error {
sf.Type = msgType
Expand Down Expand Up @@ -171,12 +236,114 @@ func (sf *WrapperMsgDeposit) HandleMsg(msgType string, msg stdTypes.Msg, log *tx
return err
}

// Proposal with an initial deposit
func (sf *WrapperMsgSubmitProposalV1) HandleMsg(msgType string, msg stdTypes.Msg, log *txModule.LogMessage) error {
sf.Type = msgType
sf.CosmosMsgSubmitProposal = msg.(*govTypesV1.MsgSubmitProposal)

// Confirm that the action listed in the message log matches the Message type
validLog := txModule.IsMessageActionEquals(sf.GetType(), log)
if !validLog {
return util.ReturnInvalidLog(msgType, log)
}

// If there was an initial deposit, there will be a transfer log with sender and amount
proposerDepositedCoinsEvt := txModule.GetEventWithType(bankTypes.EventTypeTransfer, log)
if proposerDepositedCoinsEvt == nil {
return nil
}

coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
if err != nil {
return err
}

recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
if err != nil {
return err
}

sf.DepositReceiverAddress = recipientAccount

// This may be able to be optimized by doing one or the other
coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
if err != nil {
sf.MultiCoinsReceived, err = stdTypes.ParseCoinsNormalized(coinsReceived)
if err != nil {
config.Log.Error("Error parsing coins normalized", err)
return err
}
} else {
sf.CoinReceived = coin
}

return err
}

// Additional deposit
func (sf *WrapperMsgDepositV1) HandleMsg(msgType string, msg stdTypes.Msg, log *txModule.LogMessage) error {
sf.Type = msgType
sf.CosmosMsgDeposit = msg.(*govTypesV1.MsgDeposit)

// Confirm that the action listed in the message log matches the Message type
validLog := txModule.IsMessageActionEquals(sf.GetType(), log)
if !validLog {
return util.ReturnInvalidLog(msgType, log)
}

// If there was an initial deposit, there will be a transfer log with sender and amount
proposerDepositedCoinsEvt := txModule.GetEventWithType(bankTypes.EventTypeTransfer, log)
if proposerDepositedCoinsEvt == nil {
return nil
}

coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt)
if err != nil {
return err
}

// This may be able to be optimized by doing one or the other
coin, err := stdTypes.ParseCoinNormalized(coinsReceived)
if err != nil {
return err
}

recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt)
if err != nil {
return err
}

sf.DepositReceiverAddress = recipientAccount

if err != nil {
sf.MultiCoinsReceived, err = stdTypes.ParseCoinsNormalized(coinsReceived)
if err != nil {
config.Log.Error("Error parsing coins normalized", err)
return err
}
} else {
sf.CoinReceived = coin
}

return err
}

func (sf *WrapperMsgDeposit) String() string {
return fmt.Sprintf("WrapperMsgDeposit: Address %s deposited %s",
return fmt.Sprintf("MsgDeposit: Address %s deposited %s",
sf.CosmosMsgDeposit.Depositor, sf.CosmosMsgDeposit.Amount)
}

func (sf *WrapperMsgSubmitProposal) String() string {
return fmt.Sprintf("WrapperMsgDeposit: Address %s deposited %s",
return fmt.Sprintf("MsgSubmit: Address %s deposited %s",
sf.CosmosMsgSubmitProposal.Proposer, sf.CosmosMsgSubmitProposal.InitialDeposit)
}

func (sf *WrapperMsgDepositV1) String() string {
return fmt.Sprintf("MsgDeposit: Address %s deposited %s",
sf.CosmosMsgDeposit.Depositor, sf.CosmosMsgDeposit.Amount)
}

func (sf *WrapperMsgSubmitProposalV1) String() string {
return fmt.Sprintf("MsgSubmit: Address %s deposited %s",
sf.CosmosMsgSubmitProposal.Proposer, sf.CosmosMsgSubmitProposal.InitialDeposit)
}
4 changes: 2 additions & 2 deletions csv/parsers/accointing/accointing.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgSwapExactAmountIn(event)
case gamm.MsgSwapExactAmountOut:
newRow, err = ParseMsgSwapExactAmountOut(event)
case gov.MsgSubmitProposal:
case gov.MsgSubmitProposal, gov.MsgSubmitProposalV1:
newRow, err = ParseMsgSubmitProposal(address, event)
case gov.MsgDeposit:
case gov.MsgDeposit, gov.MsgDepositV1:
newRow, err = ParseMsgDeposit(address, event)
case ibc.MsgTransfer:
newRow, err = ParseMsgTransfer(address, event)
Expand Down
4 changes: 2 additions & 2 deletions csv/parsers/cointracker/cointracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgWithdrawDelegatorReward(address, event)
case staking.MsgBeginRedelegate:
newRow, err = ParseMsgWithdrawDelegatorReward(address, event)
case gov.MsgSubmitProposal:
case gov.MsgSubmitProposal, gov.MsgSubmitProposalV1:
newRow, err = ParseMsgSubmitProposal(address, event)
case gov.MsgDeposit:
case gov.MsgDeposit, gov.MsgDepositV1:
newRow, err = ParseMsgDeposit(address, event)
case gamm.MsgSwapExactAmountIn:
newRow, err = ParseMsgSwapExactAmountIn(event)
Expand Down
4 changes: 2 additions & 2 deletions csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgSwapExactAmountIn(address, event)
case gamm.MsgSwapExactAmountOut:
newRow, err = ParseMsgSwapExactAmountOut(address, event)
case gov.MsgSubmitProposal:
case gov.MsgSubmitProposal, gov.MsgSubmitProposalV1:
newRow, err = ParseMsgSubmitProposal(address, event)
case gov.MsgDeposit:
case gov.MsgDeposit, gov.MsgDepositV1:
newRow, err = ParseMsgDeposit(address, event)
case ibc.MsgTransfer:
newRow, err = ParseMsgTransfer(address, event)
Expand Down
4 changes: 2 additions & 2 deletions csv/parsers/koinly/koinly.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgSwapExactAmountOut(event)
case ibc.MsgTransfer:
newRow, err = ParseMsgTransfer(address, event)
case gov.MsgSubmitProposal:
case gov.MsgSubmitProposal, gov.MsgSubmitProposalV1:
newRow, err = ParseMsgSubmitProposal(address, event)
case gov.MsgDeposit:
case gov.MsgDeposit, gov.MsgDepositV1:
newRow, err = ParseMsgDeposit(address, event)
case ibc.MsgAcknowledgement:
newRow, err = ParseMsgTransfer(address, event)
Expand Down
4 changes: 2 additions & 2 deletions csv/parsers/taxbit/taxbit.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgWithdrawDelegatorReward(address, event)
case staking.MsgBeginRedelegate:
newRow, err = ParseMsgWithdrawDelegatorReward(address, event)
case gov.MsgSubmitProposal:
case gov.MsgSubmitProposal, gov.MsgSubmitProposalV1:
newRow, err = ParseMsgSubmitProposal(address, event)
case gamm.MsgSwapExactAmountIn:
newRow, err = ParseMsgSwapExactAmountIn(event)
case gamm.MsgSwapExactAmountOut:
newRow, err = ParseMsgSwapExactAmountOut(event)
case gov.MsgDeposit:
case gov.MsgDeposit, gov.MsgDepositV1:
newRow, err = ParseMsgDeposit(address, event)
case ibc.MsgTransfer:
newRow, err = ParseMsgTransfer(address, event)
Expand Down
Loading