Skip to content

Commit

Permalink
Patch/missing parsers concentratedliq other errors (#521)
Browse files Browse the repository at this point in the history
* Add CSV parsers for concentrated liquidity reward collection messages

* Add ignorer for CancelUnbondingDelegation
  • Loading branch information
pharr117 authored Jan 23, 2024
1 parent 9665106 commit d62374f
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 7 deletions.
5 changes: 3 additions & 2 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ var messageTypeIgnorer = map[string]interface{}{
slashing.MsgUnjail: nil,
slashing.MsgUpdateParams: nil,
// Creating and editing validator is not taxable
staking.MsgCreateValidator: nil,
staking.MsgEditValidator: nil,
staking.MsgCreateValidator: nil,
staking.MsgEditValidator: nil,
staking.MsgCancelUnbondingDelegation: nil, // No rewards are withdrawn when cancelling an unbonding delegation
// Delegating and Locking are not taxable
superfluid.MsgSuperfluidDelegate: nil,
superfluid.MsgSuperfluidUndelegate: nil,
Expand Down
11 changes: 6 additions & 5 deletions cosmos/modules/staking/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (
)

const (
MsgDelegate = "/cosmos.staking.v1beta1.MsgDelegate"
MsgUndelegate = "/cosmos.staking.v1beta1.MsgUndelegate"
MsgBeginRedelegate = "/cosmos.staking.v1beta1.MsgBeginRedelegate"
MsgCreateValidator = "/cosmos.staking.v1beta1.MsgCreateValidator" // An explicitly ignored msg for tx parsing purposes
MsgEditValidator = "/cosmos.staking.v1beta1.MsgEditValidator" // An explicitly ignored msg for tx parsing purposes
MsgDelegate = "/cosmos.staking.v1beta1.MsgDelegate"
MsgUndelegate = "/cosmos.staking.v1beta1.MsgUndelegate"
MsgBeginRedelegate = "/cosmos.staking.v1beta1.MsgBeginRedelegate"
MsgCreateValidator = "/cosmos.staking.v1beta1.MsgCreateValidator" // An explicitly ignored msg for tx parsing purposes
MsgEditValidator = "/cosmos.staking.v1beta1.MsgEditValidator" // An explicitly ignored msg for tx parsing purposes
MsgCancelUnbondingDelegation = "/cosmos.staking.v1beta1.MsgCancelUnbondingDelegation"
)

type WrapperMsgDelegate struct {
Expand Down
24 changes: 24 additions & 0 deletions csv/parsers/accointing/accointing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/staking"
"github.com/DefiantLabs/cosmos-tax-cli/csv/parsers"
"github.com/DefiantLabs/cosmos-tax-cli/db"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/concentratedliquidity"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/poolmanager"
"github.com/DefiantLabs/cosmos-tax-cli/util"
Expand Down Expand Up @@ -250,6 +251,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgRecvPacket(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
case concentratedliquidity.MsgCollectIncentives, concentratedliquidity.MsgCollectSpreadRewards:
newRow, err = ParseConcentratedLiquidityCollection(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -436,3 +439,24 @@ func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
}
return *row, err
}

func ParseConcentratedLiquidityCollection(event db.TaxableTransaction) (Row, error) {
row := &Row{}
row.OperationID = event.Message.Tx.Hash
row.Classification = LiquidityPool
row.Date = event.Message.Tx.Block.TimeStamp.Format(TimeLayout)

denomToUse := event.DenominationReceived
amountToUse := event.AmountReceived

conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(amountToUse), denomToUse)
if err != nil {
config.Log.Error("Error with ParseConcentratedLiquidityCollection.", err)
return *row, fmt.Errorf("cannot parse denom units for TX %s (classification: deposit)", row.OperationID)
}

row.InBuyAmount = conversionAmount.Text('f', -1)
row.InBuyAsset = conversionSymbol

return *row, err
}
21 changes: 21 additions & 0 deletions csv/parsers/cointracker/cointracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/staking"
"github.com/DefiantLabs/cosmos-tax-cli/csv/parsers"
"github.com/DefiantLabs/cosmos-tax-cli/db"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/concentratedliquidity"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/poolmanager"
"github.com/DefiantLabs/cosmos-tax-cli/util"
Expand Down Expand Up @@ -212,6 +213,8 @@ func ParseTx(address string, events []db.TaxableTransaction, fees []db.Fee) (row
newRow, err = ParseMsgRecvPacket(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
case concentratedliquidity.MsgCollectIncentives, concentratedliquidity.MsgCollectSpreadRewards:
newRow, err = ParseConcentratedLiquidityCollection(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -422,3 +425,21 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) {
}
return *row, err
}

func ParseConcentratedLiquidityCollection(event db.TaxableTransaction) (Row, error) {
row := &Row{}
denomToUse := event.DenominationReceived
amountToUse := event.AmountReceived

conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(amountToUse), denomToUse)
if err != nil {
config.Log.Error("Error with ParseConcentratedLiquidityCollection.", err)
return *row, fmt.Errorf("cannot parse denom units for TX %s (classification: deposit)", event.Message.Tx.Hash)
}

row.ReceivedAmount = conversionAmount.Text('f', -1)
row.ReceivedCurrency = conversionSymbol
row.Date = event.Message.Tx.Block.TimeStamp.Format(TimeLayout)

return *row, err
}
22 changes: 22 additions & 0 deletions csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/staking"
"github.com/DefiantLabs/cosmos-tax-cli/csv/parsers"
"github.com/DefiantLabs/cosmos-tax-cli/db"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/concentratedliquidity"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/poolmanager"
"github.com/DefiantLabs/cosmos-tax-cli/util"
Expand Down Expand Up @@ -213,6 +214,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgRecvPacket(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(address, event)
case concentratedliquidity.MsgCollectIncentives, concentratedliquidity.MsgCollectSpreadRewards:
newRow, err = ParseConcentratedLiquidityCollection(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -404,3 +407,22 @@ func ParsePoolManagerSwap(address string, event db.TaxableTransaction) (Row, err
}
return *row, err
}

func ParseConcentratedLiquidityCollection(event db.TaxableTransaction) (Row, error) {
row := &Row{}
denomToUse := event.DenominationReceived
amountToUse := event.AmountReceived

conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(amountToUse), denomToUse)
if err != nil {
config.Log.Error("Error with ParseConcentratedLiquidityCollection.", err)
return *row, fmt.Errorf("cannot parse denom units for TX %s (classification: deposit)", event.Message.Tx.Hash)
}

row.BaseAmount = conversionAmount.Text('f', -1)
row.BaseCurrency = conversionSymbol
row.Type = Receive
row.Date = event.Message.Tx.Block.TimeStamp.Format(TimeLayout)

return *row, err
}
23 changes: 23 additions & 0 deletions csv/parsers/koinly/koinly.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/staking"
"github.com/DefiantLabs/cosmos-tax-cli/csv/parsers"
"github.com/DefiantLabs/cosmos-tax-cli/db"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/concentratedliquidity"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/poolmanager"
"github.com/DefiantLabs/cosmos-tax-cli/util"
Expand Down Expand Up @@ -316,6 +317,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv
newRow, err = ParseMsgRecvPacket(address, event)
case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut:
newRow, err = ParsePoolManagerSwap(event)
case concentratedliquidity.MsgCollectIncentives, concentratedliquidity.MsgCollectSpreadRewards:
newRow, err = ParseConcentratedLiquidityCollection(event)
default:
config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType)
continue
Expand Down Expand Up @@ -503,3 +506,23 @@ func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) {
}
return *row, err
}

func ParseConcentratedLiquidityCollection(event db.TaxableTransaction) (Row, error) {
row := &Row{}
denomToUse := event.DenominationReceived
amountToUse := event.AmountReceived

conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(amountToUse), denomToUse)
if err != nil {
config.Log.Error("Error with ParseConcentratedLiquidityCollection.", err)
return *row, fmt.Errorf("cannot parse denom units for TX %s (classification: deposit)", event.Message.Tx.Hash)
}

row.ReceivedAmount = conversionAmount.Text('f', -1)
row.ReceivedCurrency = conversionSymbol
row.Label = Income
row.Date = event.Message.Tx.Block.TimeStamp.Format(TimeLayout)
row.TxHash = event.Message.Tx.Hash

return *row, err
}

0 comments on commit d62374f

Please sign in to comment.