Skip to content

Commit

Permalink
Add CSV parsers for concentrated liquidity reward collection messages
Browse files Browse the repository at this point in the history
  • Loading branch information
pharr117 committed Jan 21, 2024
1 parent 9665106 commit 786a87a
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
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 786a87a

Please sign in to comment.