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

Remove unsupported gamm token from Osmosis LP parser output for coint… #529

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
93 changes: 45 additions & 48 deletions csv/parsers/cointracker/osmosis.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cointracker

import (
"strings"

"github.com/DefiantLabs/cosmos-tax-cli/csv/parsers"
"github.com/DefiantLabs/cosmos-tax-cli/db"
"github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/concentratedliquidity"
Expand Down Expand Up @@ -37,71 +39,66 @@ func (sf *OsmosisLpTxGroup) AddTxToGroup(tx db.TaxableTransaction) {
}

func (sf *OsmosisLpTxGroup) ParseGroup() error {
// cbClient := coinbasepro.NewClient()
txsToFees := parsers.GetTxToFeesMap(sf.GroupedTxes)
for _, txMessages := range sf.GroupedTxes {
for _, message := range txMessages {
row := Row{}
row.Date = message.Message.Tx.Block.TimeStamp.Format(TimeLayout)

denomRecieved := message.DenominationReceived
valueRecieved := message.AmountReceived
conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(valueRecieved), denomRecieved)
if err != nil {
row.ReceivedAmount = util.NumericToString(valueRecieved)
row.ReceivedCurrency = denomRecieved.Base
} else {
row.ReceivedAmount = conversionAmount.Text('f', -1)
row.ReceivedCurrency = conversionSymbol

if !strings.Contains(denomRecieved.Base, "gamm") {
conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(valueRecieved), denomRecieved)
if err != nil {
row.ReceivedAmount = util.NumericToString(valueRecieved)
row.ReceivedCurrency = denomRecieved.Base
} else {
row.ReceivedAmount = conversionAmount.Text('f', -1)
row.ReceivedCurrency = conversionSymbol
}
}

denomSent := message.DenominationSent
valueSent := message.AmountSent
conversionAmount, conversionSymbol, err = db.ConvertUnits(util.FromNumeric(valueSent), denomSent)
if err != nil {
row.SentAmount = util.NumericToString(valueSent)
row.SentCurrency = denomSent.Base
} else {
row.SentAmount = conversionAmount.Text('f', -1)
row.SentCurrency = conversionSymbol
}

/*
// We deliberately exclude the GAMM tokens from OutSell/InBuy for Exits/Joins respectively
// Accointing has no way of using the GAMM token to determine LP cost basis etc...
if _, ok := parsers.IsOsmosisExit[message.Message.MessageType.MessageType]; ok {
row.Label = LiquidityOut
// add the value of gam tokens
price, err := parsers.GetRate(cbClient, message.DenominationReceived.Symbol, message.Message.Tx.Block.TimeStamp)
if err != nil {
row.Description = fmt.Sprintf("could not lookup value of %v %v. It will be equivalent to %v %v at %v.", row.SentAmount, row.SentCurrency, row.ReceivedAmount, row.ReceivedCurrency, row.Date)
} else {
receivedAmount, err := strconv.ParseFloat(row.ReceivedAmount, 64)
if err != nil {
config.Log.Fatal(fmt.Sprintf("Could not parse amount %v", row.ReceivedAmount), err)
}
gamValue := receivedAmount * price
row.Description = fmt.Sprintf("%v %v on %v was $%v USD", row.SentAmount, row.SentCurrency, row.Date, gamValue)
}
} else if _, ok := parsers.IsOsmosisJoin[message.Message.MessageType.MessageType]; ok {
row.Label = LiquidityIn
// add the value of gam tokens
price, err := parsers.GetRate(cbClient, message.DenominationSent.Symbol, message.Message.Tx.Block.TimeStamp)
if err != nil {
row.Description = fmt.Sprintf("could not lookup value of %v %v. It will be equivalent to %v %v at %v.", row.ReceivedAmount, row.ReceivedCurrency, row.SentAmount, row.SentCurrency, row.Date)
} else {
sentAmount, err := strconv.ParseFloat(row.SentAmount, 64)
if err != nil {
config.Log.Fatal(fmt.Sprintf("Could not parse amount %v", row.SentAmount), err)
}
gamValue := sentAmount * price
row.Description = fmt.Sprintf("%v %v on %v was $%v USD", row.ReceivedAmount, row.ReceivedCurrency, row.Date, gamValue)
}
if !strings.Contains(denomSent.Base, "gamm") {
conversionAmount, conversionSymbol, err := db.ConvertUnits(util.FromNumeric(valueSent), denomSent)
if err != nil {
row.SentAmount = util.NumericToString(valueSent)
row.SentCurrency = denomSent.Base
} else {
row.SentAmount = conversionAmount.Text('f', -1)
row.SentCurrency = conversionSymbol
}
}

messageFee := txsToFees[message.Message.Tx.ID]
if len(messageFee) > 0 {
fee := messageFee[0]
parseAndAddFeeWithDefault(&row, fee)

*/
// This fee has been processed, pop it off the stack
txsToFees[message.Message.Tx.ID] = txsToFees[message.Message.Tx.ID][1:]

}

sf.Rows = append(sf.Rows, row)
}
}

// If there are any fees left over, add them to the CSV
for _, fees := range txsToFees {
for _, fee := range fees {
row := Row{}
err := row.ParseFee(fee.Tx, fee)
if err != nil {
return err
}
sf.Rows = append(sf.Rows, row)
}
}

return nil
}

Expand Down
Loading