diff --git a/csv/parsers/cointracker/osmosis.go b/csv/parsers/cointracker/osmosis.go index da520a3..ea0f5d8 100644 --- a/csv/parsers/cointracker/osmosis.go +++ b/csv/parsers/cointracker/osmosis.go @@ -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" @@ -37,7 +39,7 @@ 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{} @@ -45,63 +47,58 @@ func (sf *OsmosisLpTxGroup) ParseGroup() error { 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 }