From a04f8dab2cbf799c67dcf4df2669bafa1dde3bc8 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 18:13:10 -0400 Subject: [PATCH 01/11] Move to different event in withdraw validator commission as the withdraw_commission event does not contain address --- cosmos/modules/distribution/types.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cosmos/modules/distribution/types.go b/cosmos/modules/distribution/types.go index 897fd77..9b2c9e0 100644 --- a/cosmos/modules/distribution/types.go +++ b/cosmos/modules/distribution/types.go @@ -73,7 +73,7 @@ func (sf *WrapperMsgWithdrawValidatorCommission) HandleMsg(msgType string, msg s } // The attribute in the log message that shows you the delegator withdrawal address and amount received - delegatorReceivedCoinsEvt := txModule.GetEventWithType(distTypes.EventTypeWithdrawCommission, log) + delegatorReceivedCoinsEvt := txModule.GetEventWithType("coin_received", log) if delegatorReceivedCoinsEvt == nil { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } From bf4994ceb1ee9949102f0fccc875171e493cca41 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 19:03:26 -0400 Subject: [PATCH 02/11] Fix db IndexNewBlock function to force updates when a transaction is found in the database --- db/db.go | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/db/db.go b/db/db.go index bffa767..7825fad 100644 --- a/db/db.go +++ b/db/db.go @@ -282,15 +282,30 @@ func IndexNewBlock(db *gorm.DB, blockHeight int64, blockTime time.Time, txs []Tx // It is possible to have more than 1 taxable TX for a single msg. In most cases it should only be 1 or 2, but // more is possible. Keying off of msg ID and amount may be sufficient.... - if err := dbTransaction. + + var foundRecord TaxableTransaction + dbTransaction. Where(TaxableTransaction{ MessageID: taxableTxOnly.MessageID, AmountSent: taxableTxOnly.AmountSent, AmountReceived: taxableTxOnly.AmountReceived, - }). - FirstOrCreate(&taxableTxOnly).Error; err != nil { - config.Log.Error("Error creating taxable transaction.", err) - return err + }).Limit(1).Find(&foundRecord) + + // If not found, do a create + if foundRecord.ID == 0 { + res := dbTransaction.Create(&taxableTxOnly) + + if res.Error != nil { + config.Log.Error("Error creating taxable transaction.", res.Error) + return res.Error + } + } else { + // Force update with new data + res := dbTransaction.Model(&foundRecord).Updates(&taxableTxOnly) + if res.Error != nil { + config.Log.Error("Error updating taxable transaction.", res.Error) + return res.Error + } } } } From 58452d7de28f1b4a1f34f3b7192c196116b08d30 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 20:28:35 -0400 Subject: [PATCH 03/11] Add error return when attribute does not exist in event, update all locations this is used --- cosmos/modules/bank/types.go | 6 +- cosmos/modules/distribution/types.go | 27 +++- cosmos/modules/gov/types.go | 31 ++++- cosmos/modules/staking/types.go | 14 ++- cosmos/modules/tx/logic.go | 8 +- osmosis/modules/gamm/types.go | 180 ++++++++++++++++++++++----- osmosis/modules/poolmanager/types.go | 6 +- 7 files changed, 226 insertions(+), 46 deletions(-) diff --git a/cosmos/modules/bank/types.go b/cosmos/modules/bank/types.go index 58e13d0..fef64a8 100644 --- a/cosmos/modules/bank/types.go +++ b/cosmos/modules/bank/types.go @@ -38,7 +38,11 @@ func (sf *WrapperMsgSend) HandleMsg(msgType string, msg sdk.Msg, log *txModule.L return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } - receiverAddress := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, receivedCoinsEvt) + receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, receivedCoinsEvt) + + if err != nil { + return err + } // coins_received := txModule.GetValueForAttribute("amount", receivedCoinsEvt) if !strings.EqualFold(sf.CosmosMsgSend.ToAddress, receiverAddress) { diff --git a/cosmos/modules/distribution/types.go b/cosmos/modules/distribution/types.go index 9b2c9e0..aa7934f 100644 --- a/cosmos/modules/distribution/types.go +++ b/cosmos/modules/distribution/types.go @@ -78,8 +78,18 @@ func (sf *WrapperMsgWithdrawValidatorCommission) HandleMsg(msgType string, msg s return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } - sf.DelegatorReceiverAddress = txModule.GetValueForAttribute(bankTypes.AttributeKeyReceiver, delegatorReceivedCoinsEvt) - coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyReceiver, delegatorReceivedCoinsEvt) + + if err != nil { + return err + } + + sf.DelegatorReceiverAddress = receiverAddress + coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + + if err != nil { + return err + } coin, err := stdTypes.ParseCoinNormalized(coinsReceived) if err != nil { @@ -114,8 +124,17 @@ func (sf *WrapperMsgWithdrawDelegatorReward) HandleMsg(msgType string, msg stdTy return nil } - sf.RecipientAddress = txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, delegatorReceivedCoinsEvt) - coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + recipientAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, delegatorReceivedCoinsEvt) + if err != nil { + return err + } + + sf.RecipientAddress = recipientAddress + coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + + if err != nil { + return err + } // This may be able to be optimized by doing one or the other coin, err := stdTypes.ParseCoinNormalized(coinsReceived) diff --git a/cosmos/modules/gov/types.go b/cosmos/modules/gov/types.go index cad4d63..4f98644 100644 --- a/cosmos/modules/gov/types.go +++ b/cosmos/modules/gov/types.go @@ -96,8 +96,18 @@ func (sf *WrapperMsgSubmitProposal) HandleMsg(msgType string, msg stdTypes.Msg, return nil } - coinsReceived := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt) - recipientAccount := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt) + 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 @@ -132,11 +142,24 @@ func (sf *WrapperMsgDeposit) HandleMsg(msgType string, msg stdTypes.Msg, log *tx return nil } - coinsReceived := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt) + 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) - recipientAccount := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt) + if err != nil { + return err + } + + recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt) + + if err != nil { + return err + } + sf.DepositReceiverAddress = recipientAccount if err != nil { diff --git a/cosmos/modules/staking/types.go b/cosmos/modules/staking/types.go index 5341269..c8e30ed 100644 --- a/cosmos/modules/staking/types.go +++ b/cosmos/modules/staking/types.go @@ -61,8 +61,18 @@ func (sf *WrapperMsgDelegate) HandleMsg(msgType string, msg stdTypes.Msg, log *t sf.AutoWithdrawalReward = nil sf.DelegatorAddress = sf.CosmosMsgDelegate.DelegatorAddress } else { - sf.DelegatorAddress = txModule.GetValueForAttribute("recipient", delegatorReceivedCoinsEvt) - coinsReceived := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + delegatorAddress, err := txModule.GetValueForAttribute("recipient", delegatorReceivedCoinsEvt) + if err != nil { + return err + } + + sf.DelegatorAddress = delegatorAddress + + coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) + if err != nil { + return err + } + coin, err := stdTypes.ParseCoinNormalized(coinsReceived) if err != nil { sf.AutoWithdrawalRewards, err = stdTypes.ParseCoinsNormalized(coinsReceived) diff --git a/cosmos/modules/tx/logic.go b/cosmos/modules/tx/logic.go index d6be95c..58d9fee 100644 --- a/cosmos/modules/tx/logic.go +++ b/cosmos/modules/tx/logic.go @@ -108,18 +108,18 @@ func ParseTransferEvent(evt LogMessageEvent) ([]TransferEvent, error) { // If order is reversed, the last attribute containing the given key will be returned // otherwise the first attribute will be returned -func GetValueForAttribute(key string, evt *LogMessageEvent) string { +func GetValueForAttribute(key string, evt *LogMessageEvent) (string, error) { if evt == nil || evt.Attributes == nil { - return "" + return "", nil } for _, attr := range evt.Attributes { if attr.Key == key { - return attr.Value + return attr.Value, nil } } - return "" + return "", fmt.Errorf("Attribute %s missing from event", key) } func GetCoinsSpent(spender string, evts []LogMessageEvent) []string { diff --git a/osmosis/modules/gamm/types.go b/osmosis/modules/gamm/types.go index 6052944..c1b1610 100644 --- a/osmosis/modules/gamm/types.go +++ b/osmosis/modules/gamm/types.go @@ -372,7 +372,11 @@ func (sf *WrapperMsgSwapExactAmountIn) HandleMsg(msgType string, msg sdk.Msg, lo } // Address of whoever initiated the swap. Will be both sender/receiver. - senderReceiver := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + if err != nil { + return err + } + if senderReceiver == "" { fmt.Println("Error getting sender.") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -380,7 +384,11 @@ func (sf *WrapperMsgSwapExactAmountIn) HandleMsg(msgType string, msg sdk.Msg, lo sf.Address = senderReceiver // This gets the first token swapped in (if there are multiple pools we do not care about intermediates) - tokenInStr := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, tokensSwappedEvt) + tokenInStr, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, tokensSwappedEvt) + if err != nil { + return err + } + tokenIn, err := sdk.ParseCoinNormalized(tokenInStr) if err != nil { fmt.Println("Error parsing coins in. Err: ", err) @@ -419,7 +427,11 @@ func (sf *WrapperMsgSwapExactAmountIn2) HandleMsg(msgType string, msg sdk.Msg, l } // Address of whoever initiated the swap. Will be both sender/receiver. - senderReceiver := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + if err != nil { + return err + } + if senderReceiver == "" { fmt.Println("Error getting sender.") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -492,7 +504,11 @@ func (sf *WrapperMsgSwapExactAmountIn3) HandleMsg(msgType string, msg sdk.Msg, l } // Address of whoever initiated the swap. Will be both sender/receiver. - senderReceiver := txModule.GetValueForAttribute("sender", tokensTransferredEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", tokensTransferredEvt) + if err != nil { + return err + } + if senderReceiver == "" { fmt.Println("Error getting sender.") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -556,7 +572,11 @@ func (sf *WrapperMsgSwapExactAmountIn4) HandleMsg(msgType string, msg sdk.Msg, l } // Address of whoever initiated the swap. Will be both sender/receiver. - senderReceiver := txModule.GetValueForAttribute("sender", tokensTransferredEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", tokensTransferredEvt) + if err != nil { + return err + } + if senderReceiver == "" { fmt.Println("Error getting sender.") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -603,7 +623,11 @@ func (sf *WrapperMsgSwapExactAmountOut) HandleMsg(msgType string, msg sdk.Msg, l } } - senderReceiver := txModule.GetValueForAttribute("sender", transferEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", transferEvt) + if err != nil { + return err + } + if senderReceiver == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -622,7 +646,11 @@ func (sf *WrapperMsgSwapExactAmountOut) HandleMsg(msgType string, msg sdk.Msg, l } } else { // This gets the first token swapped in (if there are multiple pools we do not care about intermediates) - tokenInStr := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, tokensSwappedEvt) + tokenInStr, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, tokensSwappedEvt) + if err != nil { + return err + } + tokenIn, err := sdk.ParseCoinNormalized(tokenInStr) if err != nil { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -630,7 +658,11 @@ func (sf *WrapperMsgSwapExactAmountOut) HandleMsg(msgType string, msg sdk.Msg, l sf.TokenIn = tokenIn // Address of whoever initiated the swap. Will be both sender/receiver. - senderReceiver := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + senderReceiver, err := txModule.GetValueForAttribute("sender", tokensSwappedEvt) + if err != nil { + return err + } + if senderReceiver == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -666,7 +698,11 @@ func (sf *WrapperMsgJoinSwapExternAmountIn) HandleMsg(msgType string, msg sdk.Ms } // This gets the amount of GAMM tokens received - gammTokenInStr := txModule.GetValueForAttribute(EventAttributeAmount, coinbaseEvt) + gammTokenInStr, err := txModule.GetValueForAttribute(EventAttributeAmount, coinbaseEvt) + if err != nil { + return err + } + if !strings.Contains(gammTokenInStr, "gamm") { fmt.Println("Gamm token in string must contain gamm") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -687,7 +723,11 @@ func (sf *WrapperMsgJoinSwapExternAmountIn) HandleMsg(msgType string, msg sdk.Ms } // Address of whoever initiated the join. - senderAddress := txModule.GetValueForAttribute("sender", poolJoinedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolJoinedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -753,7 +793,11 @@ func (sf *WrapperMsgJoinSwapShareAmountOut) HandleMsg(msgType string, msg sdk.Ms } // This gets the amount of GAMM tokens received - gammTokenInStr := txModule.GetValueForAttribute(EventAttributeAmount, coinbaseEvt) + gammTokenInStr, err := txModule.GetValueForAttribute(EventAttributeAmount, coinbaseEvt) + if err != nil { + return err + } + if !strings.Contains(gammTokenInStr, "gamm") { fmt.Println("Gamm token in string must contain gamm") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -771,13 +815,21 @@ func (sf *WrapperMsgJoinSwapShareAmountOut) HandleMsg(msgType string, msg sdk.Ms } // Address of whoever initiated the join. - senderAddress := txModule.GetValueForAttribute("sender", poolJoinedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolJoinedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress - tokenIn := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + tokenIn, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + if err != nil { + return err + } + if tokenIn == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -834,13 +886,21 @@ func (sf *WrapperMsgJoinSwapShareAmountOut2) HandleMsg(msgType string, msg sdk.M } // Address of whoever initiated the join. - senderAddress := txModule.GetValueForAttribute("sender", poolJoinedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolJoinedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress - tokenIn := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + tokenIn, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + if err != nil { + return err + } + if tokenIn == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -930,14 +990,22 @@ func (sf *WrapperMsgJoinPool) HandleMsg(msgType string, msg sdk.Msg, log *txModu } // Address of whoever initiated the join. - senderAddress := txModule.GetValueForAttribute("sender", poolJoinedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolJoinedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress // String value for the tokens in, which can be multiple - tokensInString := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + tokensInString, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, poolJoinedEvent) + if err != nil { + return err + } + if tokensInString == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -1166,7 +1234,11 @@ func (sf *WrapperMsgExitSwapShareAmountIn) HandleMsg(msgType string, msg sdk.Msg } // This gets the amount of GAMM exited with - gammTokenInStr := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + gammTokenInStr, err := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + if err != nil { + return err + } + if !strings.Contains(gammTokenInStr, "gamm") { fmt.Println("Gamm token in string must contain gamm") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -1184,13 +1256,21 @@ func (sf *WrapperMsgExitSwapShareAmountIn) HandleMsg(msgType string, msg sdk.Msg } // Address of whoever initiated the exit. - senderAddress := txModule.GetValueForAttribute("sender", poolExitedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolExitedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress - tokenOut := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + tokenOut, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + if err != nil { + return err + } + if tokenOut == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -1220,7 +1300,11 @@ func (sf *WrapperMsgExitSwapShareAmountIn2) HandleMsg(msgType string, msg sdk.Ms } // This gets the amount of GAMM exited with - gammTokenInStr := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + gammTokenInStr, err := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + if err != nil { + return err + } + if !strings.Contains(gammTokenInStr, "gamm") { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -1237,13 +1321,21 @@ func (sf *WrapperMsgExitSwapShareAmountIn2) HandleMsg(msgType string, msg sdk.Ms } // Address of whoever initiated the exit. - senderAddress := txModule.GetValueForAttribute("sender", poolExitedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolExitedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress - tokensOut := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + tokensOut, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + if err != nil { + return err + } + if tokensOut == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -1259,8 +1351,16 @@ func (sf *WrapperMsgExitSwapShareAmountIn2) HandleMsg(msgType string, msg sdk.Ms // This is to handle multi-token pool exit swaps for i := range tokenSwappedEvents { - tokenSwappedIn := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, &tokenSwappedEvents[i]) - tokenSwappedOut := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, &tokenSwappedEvents[i]) + tokenSwappedIn, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensIn, &tokenSwappedEvents[i]) + if err != nil { + return err + } + + tokenSwappedOut, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, &tokenSwappedEvents[i]) + if err != nil { + return err + } + parsedTokensSwappedIn, err := sdk.ParseCoinNormalized(tokenSwappedIn) if err != nil { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -1296,7 +1396,11 @@ func (sf *WrapperMsgExitSwapExternAmountOut) HandleMsg(msgType string, msg sdk.M } // This gets the amount of GAMM exited with - gammTokenInStr := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + gammTokenInStr, err := txModule.GetValueForAttribute(EventAttributeAmount, burnEvt) + if err != nil { + return err + } + if !strings.Contains(gammTokenInStr, "gamm") { fmt.Println("Gamm token in string must contain gamm") return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} @@ -1314,13 +1418,21 @@ func (sf *WrapperMsgExitSwapExternAmountOut) HandleMsg(msgType string, msg sdk.M } // Address of whoever initiated the exit. - senderAddress := txModule.GetValueForAttribute("sender", poolExitedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolExitedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress - tokenOut := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + tokenOut, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + if err != nil { + return err + } + if tokenOut == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } @@ -1421,14 +1533,22 @@ func (sf *WrapperMsgExitPool) HandleMsg(msgType string, msg sdk.Msg, log *txModu } // Address of whoever initiated the exit. - senderAddress := txModule.GetValueForAttribute("sender", poolExitedEvent) + senderAddress, err := txModule.GetValueForAttribute("sender", poolExitedEvent) + if err != nil { + return err + } + if senderAddress == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } sf.Address = senderAddress // String value for the tokens in, which can be multiple - tokensOutString := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + tokensOutString, err := txModule.GetValueForAttribute(gammTypes.AttributeKeyTokensOut, poolExitedEvent) + if err != nil { + return err + } + if tokensOutString == "" { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} } diff --git a/osmosis/modules/poolmanager/types.go b/osmosis/modules/poolmanager/types.go index 2733f02..ff60270 100644 --- a/osmosis/modules/poolmanager/types.go +++ b/osmosis/modules/poolmanager/types.go @@ -113,7 +113,11 @@ func (sf *WrapperMsgSwapExactAmountOut) HandleMsg(msgType string, msg sdk.Msg, l } // This gets the first token swapped in (if there are multiple pools we do not care about intermediates) - tokenInStr := txModule.GetValueForAttribute("tokens_in", tokensSwappedEvt) + tokenInStr, err := txModule.GetValueForAttribute("tokens_in", tokensSwappedEvt) + if err != nil { + return err + } + tokenIn, err := sdk.ParseCoinNormalized(tokenInStr) if err != nil { return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} From d44e6ef3987d048a103fa207446cd34d1e46617f Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 21:08:53 -0400 Subject: [PATCH 04/11] Add error passing back up the call stack on message found missing from ignore list and with no parsers which will fail entire block --- core/tx.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/tx.go b/core/tx.go index a8fe22d..ca01816 100644 --- a/core/tx.go +++ b/core/tx.go @@ -424,12 +424,11 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper config.Log.Fatal("Issue parsing a cosmos msg that we DO have a parser for! PLEASE INVESTIGATE") } // if this msg isn't include in our list of those we are explicitly ignoring, do something about it. + // we have decided to throw the error back up the call stack, which will prevent any indexing from happening on this block and add this to the failed block table if _, ok := messageTypeIgnorer[msgType]; !ok { - config.Log.Warn(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. We do not currently have a message handler for this message type", tx.TxResponse.Height, msgType)) + config.Log.Error(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. We do not currently have a message handler for this message type", tx.TxResponse.Height, msgType)) + return txDBWapper, txTime, fmt.Errorf("missing parser or ignore list entry for msg type '%v'", msgType) } - // println("------------------Cosmos message parsing failed. MESSAGE FORMAT FOLLOWS:---------------- \n\n") - // spew.Dump(message) - // println("\n------------------END MESSAGE----------------------\n") } else { config.Log.Debug(fmt.Sprintf("[Block: %v] Cosmos message of known type: %s", tx.TxResponse.Height, cosmosMessage)) currMessageType.MessageType = cosmosMessage.GetType() From e17f07f02db74395559f21f4f14b16292fd39f3d Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 21:23:59 -0400 Subject: [PATCH 05/11] Update language for clarity in log and error message --- core/tx.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tx.go b/core/tx.go index ca01816..7f765fc 100644 --- a/core/tx.go +++ b/core/tx.go @@ -426,8 +426,8 @@ func ProcessTx(db *gorm.DB, tx txtypes.MergedTx) (txDBWapper dbTypes.TxDBWrapper // if this msg isn't include in our list of those we are explicitly ignoring, do something about it. // we have decided to throw the error back up the call stack, which will prevent any indexing from happening on this block and add this to the failed block table if _, ok := messageTypeIgnorer[msgType]; !ok { - config.Log.Error(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. We do not currently have a message handler for this message type", tx.TxResponse.Height, msgType)) - return txDBWapper, txTime, fmt.Errorf("missing parser or ignore list entry for msg type '%v'", msgType) + config.Log.Error(fmt.Sprintf("[Block: %v] ParseCosmosMessage failed for msg of type '%v'. Missing parser and ignore list entry.", tx.TxResponse.Height, msgType)) + return txDBWapper, txTime, fmt.Errorf("missing parser and ignore list entry for msg type '%v'", msgType) } } else { config.Log.Debug(fmt.Sprintf("[Block: %v] Cosmos message of known type: %s", tx.TxResponse.Height, cosmosMessage)) From 4cdfbd0d877ab53b5c78bb33c0da6526ec10728f Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 21:29:11 -0400 Subject: [PATCH 06/11] gofumpt --- cosmos/modules/bank/types.go | 1 - cosmos/modules/distribution/types.go | 3 --- cosmos/modules/gov/types.go | 4 ---- 3 files changed, 8 deletions(-) diff --git a/cosmos/modules/bank/types.go b/cosmos/modules/bank/types.go index fef64a8..9626b15 100644 --- a/cosmos/modules/bank/types.go +++ b/cosmos/modules/bank/types.go @@ -39,7 +39,6 @@ func (sf *WrapperMsgSend) HandleMsg(msgType string, msg sdk.Msg, log *txModule.L } receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyRecipient, receivedCoinsEvt) - if err != nil { return err } diff --git a/cosmos/modules/distribution/types.go b/cosmos/modules/distribution/types.go index aa7934f..114dffe 100644 --- a/cosmos/modules/distribution/types.go +++ b/cosmos/modules/distribution/types.go @@ -79,14 +79,12 @@ func (sf *WrapperMsgWithdrawValidatorCommission) HandleMsg(msgType string, msg s } receiverAddress, err := txModule.GetValueForAttribute(bankTypes.AttributeKeyReceiver, delegatorReceivedCoinsEvt) - if err != nil { return err } sf.DelegatorReceiverAddress = receiverAddress coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) - if err != nil { return err } @@ -131,7 +129,6 @@ func (sf *WrapperMsgWithdrawDelegatorReward) HandleMsg(msgType string, msg stdTy sf.RecipientAddress = recipientAddress coinsReceived, err := txModule.GetValueForAttribute("amount", delegatorReceivedCoinsEvt) - if err != nil { return err } diff --git a/cosmos/modules/gov/types.go b/cosmos/modules/gov/types.go index 4f98644..89c2bce 100644 --- a/cosmos/modules/gov/types.go +++ b/cosmos/modules/gov/types.go @@ -97,13 +97,11 @@ func (sf *WrapperMsgSubmitProposal) HandleMsg(msgType string, msg stdTypes.Msg, } coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt) - if err != nil { return err } recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt) - if err != nil { return err } @@ -143,7 +141,6 @@ func (sf *WrapperMsgDeposit) HandleMsg(msgType string, msg stdTypes.Msg, log *tx } coinsReceived, err := txModule.GetValueForAttribute("amount", proposerDepositedCoinsEvt) - if err != nil { return err } @@ -155,7 +152,6 @@ func (sf *WrapperMsgDeposit) HandleMsg(msgType string, msg stdTypes.Msg, log *tx } recipientAccount, err := txModule.GetValueForAttribute("recipient", proposerDepositedCoinsEvt) - if err != nil { return err } From ac661d8152a5162d1e384338fc81594c34821f4a Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 22:51:43 -0400 Subject: [PATCH 07/11] Add parser and handler that determines amounts in and out for MsgSplitRouteSwapExactAmountIn --- osmosis/handlers.go | 1 + osmosis/modules/poolmanager/types.go | 103 ++++++++++++++++++++++++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/osmosis/handlers.go b/osmosis/handlers.go index e8ed47e..2dcda82 100644 --- a/osmosis/handlers.go +++ b/osmosis/handlers.go @@ -22,6 +22,7 @@ var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{ gamm.MsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreateBalancerPool{} }}, poolmanager.MsgSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountIn{} }}, poolmanager.MsgSwapExactAmountOut: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountOut{} }}, + poolmanager.MsgSplitRouteSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSplitRouteSwapExactAmountIn{} }}, concentratedliquidity.MsgCreatePosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCreatePosition{} }}, concentratedliquidity.MsgWithdrawPosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgWithdrawPosition{} }}, concentratedliquidity.MsgCollectSpreadRewards: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCollectSpreadRewards{} }}, diff --git a/osmosis/modules/poolmanager/types.go b/osmosis/modules/poolmanager/types.go index ff60270..fa541b4 100644 --- a/osmosis/modules/poolmanager/types.go +++ b/osmosis/modules/poolmanager/types.go @@ -12,8 +12,9 @@ import ( ) const ( - MsgSwapExactAmountIn = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn" - MsgSwapExactAmountOut = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountOut" + MsgSwapExactAmountIn = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountIn" + MsgSwapExactAmountOut = "/osmosis.poolmanager.v1beta1.MsgSwapExactAmountOut" + MsgSplitRouteSwapExactAmountIn = "/osmosis.poolmanager.v1beta1.MsgSplitRouteSwapExactAmountIn" ) type WrapperMsgSwapExactAmountIn struct { @@ -32,6 +33,14 @@ type WrapperMsgSwapExactAmountOut struct { TokenIn sdk.Coin } +type WrapperMsgSplitRouteSwapExactAmountIn struct { + txModule.Message + OsmosisMsgSplitRouteSwapExactAmountIn *poolManagerTypes.MsgSplitRouteSwapExactAmountIn + Address string + TokenOut sdk.Coin + TokenIn sdk.Coin +} + func (sf *WrapperMsgSwapExactAmountIn) String() string { var tokenSwappedOut string var tokenSwappedIn string @@ -59,6 +68,19 @@ func (sf *WrapperMsgSwapExactAmountOut) String() string { sf.Address, tokenSwappedIn, tokenSwappedOut) } +func (sf *WrapperMsgSplitRouteSwapExactAmountIn) String() string { + var tokenSwappedOut string + var tokenSwappedIn string + if !sf.TokenOut.IsNil() { + tokenSwappedOut = sf.TokenOut.String() + } + if !sf.TokenIn.IsNil() { + tokenSwappedIn = sf.TokenIn.String() + } + return fmt.Sprintf("MsgSplitRouteSwapExactAmountIn (pool-manager): %s swapped in %s and received %s", + sf.Address, tokenSwappedIn, tokenSwappedOut) +} + func (sf *WrapperMsgSwapExactAmountIn) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { sf.Type = msgType sf.OsmosisMsgSwapExactAmountIn = msg.(*poolManagerTypes.MsgSwapExactAmountIn) @@ -129,6 +151,70 @@ func (sf *WrapperMsgSwapExactAmountOut) HandleMsg(msgType string, msg sdk.Msg, l return err } +// This message behaves like the following: +// 1. Given a token in denom and a set of routes that end in the same denom +// 2. Swap the token in denom for the amount specified for each route +// 3. Get the single denom out that is at the end of each route +// The message errors out if the ending route denoms do not match for every route +// https://github.com/osmosis-labs/osmosis/blob/feaa5ef7d01dc3d082b9d4e7d1dd846d2b54cf6d/x/poolmanager/router.go#L130 +func (sf *WrapperMsgSplitRouteSwapExactAmountIn) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { + sf.Type = msgType + sf.OsmosisMsgSplitRouteSwapExactAmountIn = msg.(*poolManagerTypes.MsgSplitRouteSwapExactAmountIn) + + denomIn := sf.OsmosisMsgSplitRouteSwapExactAmountIn.TokenInDenom + + if len(sf.OsmosisMsgSplitRouteSwapExactAmountIn.Routes) == 0 { + return nil + } + + found := false + denomOut := "" + + totalIn := sdk.NewCoin(denomIn, sdk.ZeroInt()) + + // Determine the token out denom from the first route that has pools and its final entry - gauranteed to be the same for every route based on the spec + // Also determine the amount of token in based on the routes provided in the message + for _, route := range sf.OsmosisMsgSplitRouteSwapExactAmountIn.Routes { + if len(route.Pools) > 0 && !found { + found = true + denomOut = route.Pools[len(route.Pools)-1].TokenOutDenom + } + + tokenInCoins := sdk.NewCoin(denomIn, route.TokenInAmount) + totalIn = totalIn.Add(tokenInCoins) + } + + if !found || denomOut == "" { + return nil + } + + // Get the final out amount from the split_route_swap_exact_amount_in event + splitRouteFinalEvent := txModule.GetEventWithType("split_route_swap_exact_amount_in", log) + + if splitRouteFinalEvent == nil { + return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} + } + + tokensOutString, err := txModule.GetValueForAttribute("tokens_out", splitRouteFinalEvent) + + if err != nil { + return err + } + + tokenOutAmount, ok := sdk.NewIntFromString(tokensOutString) + if !ok { + return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)} + } + + finalTokensOut := sdk.NewCoin(denomOut, tokenOutAmount) + + sf.TokenOut = finalTokensOut + sf.TokenIn = totalIn + sf.Address = sf.OsmosisMsgSplitRouteSwapExactAmountIn.Sender + + return nil +} + func (sf *WrapperMsgSwapExactAmountIn) ParseRelevantData() []parsingTypes.MessageRelevantInformation { relevantData := make([]parsingTypes.MessageRelevantInformation, 1) relevantData[0] = parsingTypes.MessageRelevantInformation{ @@ -154,3 +240,16 @@ func (sf *WrapperMsgSwapExactAmountOut) ParseRelevantData() []parsingTypes.Messa } return relevantData } + +func (sf *WrapperMsgSplitRouteSwapExactAmountIn) ParseRelevantData() []parsingTypes.MessageRelevantInformation { + relevantData := make([]parsingTypes.MessageRelevantInformation, 1) + relevantData[0] = parsingTypes.MessageRelevantInformation{ + AmountSent: sf.TokenIn.Amount.BigInt(), + DenominationSent: sf.TokenIn.Denom, + AmountReceived: sf.TokenOut.Amount.BigInt(), + DenominationReceived: sf.TokenOut.Denom, + SenderAddress: sf.Address, + ReceiverAddress: sf.Address, + } + return relevantData +} From b03e6fc206b4eb8a5ee2d2e214055db617002216 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 22:55:56 -0400 Subject: [PATCH 08/11] gofumpt --- osmosis/modules/poolmanager/types.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osmosis/modules/poolmanager/types.go b/osmosis/modules/poolmanager/types.go index fa541b4..9d1f71f 100644 --- a/osmosis/modules/poolmanager/types.go +++ b/osmosis/modules/poolmanager/types.go @@ -172,7 +172,7 @@ func (sf *WrapperMsgSplitRouteSwapExactAmountIn) HandleMsg(msgType string, msg s totalIn := sdk.NewCoin(denomIn, sdk.ZeroInt()) - // Determine the token out denom from the first route that has pools and its final entry - gauranteed to be the same for every route based on the spec + // Determine the token out denom from the first route that has pools and its final entry - guaranteed to be the same for every route based on the spec // Also determine the amount of token in based on the routes provided in the message for _, route := range sf.OsmosisMsgSplitRouteSwapExactAmountIn.Routes { if len(route.Pools) > 0 && !found { @@ -196,7 +196,6 @@ func (sf *WrapperMsgSplitRouteSwapExactAmountIn) HandleMsg(msgType string, msg s } tokensOutString, err := txModule.GetValueForAttribute("tokens_out", splitRouteFinalEvent) - if err != nil { return err } From c9616cefd283f3ac431abbd37492847d1c7a884a Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 28 Aug 2023 23:13:23 -0400 Subject: [PATCH 09/11] Add csv parsers for new pool manager types --- csv/parsers/accointing/accointing.go | 12 ++++++++++++ csv/parsers/cointracker/cointracker.go | 12 ++++++++++++ .../cryptotaxcalculator/cryptotaxcalculator.go | 12 ++++++++++++ csv/parsers/koinly/koinly.go | 12 ++++++++++++ csv/parsers/taxbit/taxbit.go | 12 ++++++++++++ 5 files changed, 60 insertions(+) diff --git a/csv/parsers/accointing/accointing.go b/csv/parsers/accointing/accointing.go index eb8e1bd..34bb4d1 100644 --- a/csv/parsers/accointing/accointing.go +++ b/csv/parsers/accointing/accointing.go @@ -15,6 +15,7 @@ import ( "github.com/DefiantLabs/cosmos-indexer/csv/parsers" "github.com/DefiantLabs/cosmos-indexer/db" "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm" + "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager" ) func (p *Parser) TimeLayout() string { @@ -259,6 +260,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv newRow, err = ParseMsgTransfer(address, event) case ibc.MsgRecvPacket: newRow, err = ParseMsgTransfer(address, event) + case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut: + newRow, err = ParsePoolManagerSwap(event) default: config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType) continue @@ -394,3 +397,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) { } return *row, err } + +func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) { + row := &Row{} + err := row.ParseSwap(event) + if err != nil { + config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err) + } + return *row, err +} diff --git a/csv/parsers/cointracker/cointracker.go b/csv/parsers/cointracker/cointracker.go index a17af30..4425b24 100644 --- a/csv/parsers/cointracker/cointracker.go +++ b/csv/parsers/cointracker/cointracker.go @@ -13,6 +13,7 @@ import ( "github.com/DefiantLabs/cosmos-indexer/csv/parsers" "github.com/DefiantLabs/cosmos-indexer/db" "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm" + "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager" ) func (p *Parser) TimeLayout() string { @@ -251,6 +252,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv newRow, err = ParseMsgTransfer(address, event) case ibc.MsgRecvPacket: newRow, err = ParseMsgTransfer(address, event) + case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut: + newRow, err = ParsePoolManagerSwap(event) default: config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType) continue @@ -365,6 +368,15 @@ func ParseMsgDeposit(address string, event db.TaxableTransaction) (Row, error) { return *row, err } +func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) { + row := &Row{} + err := row.ParseSwap(event) + if err != nil { + config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err) + } + return *row, err +} + func ParseOsmosisReward(event db.TaxableEvent) (Row, error) { row := &Row{} err := row.EventParseBasic(event) diff --git a/csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go b/csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go index ba822d5..4c45a9f 100644 --- a/csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go +++ b/csv/parsers/cryptotaxcalculator/cryptotaxcalculator.go @@ -13,6 +13,7 @@ import ( "github.com/DefiantLabs/cosmos-indexer/csv/parsers" "github.com/DefiantLabs/cosmos-indexer/db" "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm" + "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager" ) func (p *Parser) TimeLayout() string { @@ -193,6 +194,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv newRow, err = ParseMsgTransfer(address, event) case ibc.MsgRecvPacket: newRow, err = ParseMsgTransfer(address, event) + case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut: + newRow, err = ParsePoolManagerSwap(address, event) default: config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType) continue @@ -317,3 +320,12 @@ func ParseMsgSwapExactAmountOut(address string, event db.TaxableTransaction) (Ro } return *row, err } + +func ParsePoolManagerSwap(address string, event db.TaxableTransaction) (Row, error) { + row := &Row{} + err := row.ParseSwap(event, address, Buy) + if err != nil { + config.Log.Error("Error with ParsePoolManagerSwap.", err) + } + return *row, err +} diff --git a/csv/parsers/koinly/koinly.go b/csv/parsers/koinly/koinly.go index 5e740c1..3edcaf2 100644 --- a/csv/parsers/koinly/koinly.go +++ b/csv/parsers/koinly/koinly.go @@ -16,6 +16,7 @@ import ( "github.com/DefiantLabs/cosmos-indexer/csv/parsers" "github.com/DefiantLabs/cosmos-indexer/db" "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm" + "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager" ) var unsupportedCoins = []string{ @@ -325,6 +326,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv newRow, err = ParseMsgTransfer(address, event) case ibc.MsgRecvPacket: newRow, err = ParseMsgTransfer(address, event) + case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut: + newRow, err = ParsePoolManagerSwap(event) default: config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType) continue @@ -447,3 +450,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) { } return *row, err } + +func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) { + row := &Row{} + err := row.ParseSwap(event) + if err != nil { + config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err) + } + return *row, err +} diff --git a/csv/parsers/taxbit/taxbit.go b/csv/parsers/taxbit/taxbit.go index 5233309..7b8f98c 100644 --- a/csv/parsers/taxbit/taxbit.go +++ b/csv/parsers/taxbit/taxbit.go @@ -13,6 +13,7 @@ import ( "github.com/DefiantLabs/cosmos-indexer/csv/parsers" "github.com/DefiantLabs/cosmos-indexer/db" "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm" + "github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager" ) func (p *Parser) TimeLayout() string { @@ -255,6 +256,8 @@ func ParseTx(address string, events []db.TaxableTransaction) (rows []parsers.Csv newRow, err = ParseMsgTransfer(address, event) case ibc.MsgRecvPacket: newRow, err = ParseMsgTransfer(address, event) + case poolmanager.MsgSplitRouteSwapExactAmountIn, poolmanager.MsgSwapExactAmountIn, poolmanager.MsgSwapExactAmountOut: + newRow, err = ParsePoolManagerSwap(event) default: config.Log.Errorf("no parser for message type '%v'", event.Message.MessageType.MessageType) continue @@ -377,3 +380,12 @@ func ParseOsmosisReward(event db.TaxableEvent) (Row, error) { } return *row, err } + +func ParsePoolManagerSwap(event db.TaxableTransaction) (Row, error) { + row := &Row{} + err := row.ParseSwap(event) + if err != nil { + config.Log.Error("Error with ParseMsgSwapExactAmountOut.", err) + } + return *row, err +} From f9c14619416ad3c9f9722ba8688f24910e3ccc6d Mon Sep 17 00:00:00 2001 From: pharr117 Date: Mon, 4 Sep 2023 11:03:18 -0400 Subject: [PATCH 10/11] Add new superfluid delegation message to type ignorer --- core/tx.go | 11 ++++++----- osmosis/modules/superfluid/types.go | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/tx.go b/core/tx.go index 7f765fc..e80f90c 100644 --- a/core/tx.go +++ b/core/tx.go @@ -99,11 +99,12 @@ var messageTypeIgnorer = map[string]interface{}{ staking.MsgCreateValidator: nil, staking.MsgEditValidator: nil, // Delegating and Locking are not taxable - superfluid.MsgSuperfluidDelegate: nil, - superfluid.MsgSuperfluidUndelegate: nil, - superfluid.MsgSuperfluidUnbondLock: nil, - superfluid.MsgLockAndSuperfluidDelegate: nil, - superfluid.MsgUnPoolWhitelistedPool: nil, + superfluid.MsgSuperfluidDelegate: nil, + superfluid.MsgSuperfluidUndelegate: nil, + superfluid.MsgSuperfluidUnbondLock: nil, + superfluid.MsgLockAndSuperfluidDelegate: nil, + superfluid.MsgUnPoolWhitelistedPool: nil, + superfluid.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition: nil, // Setting validator pref is not taxable valsetpref.MsgSetValidatorSetPreference: nil, diff --git a/osmosis/modules/superfluid/types.go b/osmosis/modules/superfluid/types.go index 379abb0..67f97cb 100644 --- a/osmosis/modules/superfluid/types.go +++ b/osmosis/modules/superfluid/types.go @@ -1,9 +1,10 @@ package superfluid const ( - MsgSuperfluidDelegate = "/osmosis.superfluid.MsgSuperfluidDelegate" - MsgSuperfluidUndelegate = "/osmosis.superfluid.MsgSuperfluidUndelegate" - MsgSuperfluidUnbondLock = "/osmosis.superfluid.MsgSuperfluidUnbondLock" - MsgLockAndSuperfluidDelegate = "/osmosis.superfluid.MsgLockAndSuperfluidDelegate" - MsgUnPoolWhitelistedPool = "/osmosis.superfluid.MsgUnPoolWhitelistedPool" + MsgSuperfluidDelegate = "/osmosis.superfluid.MsgSuperfluidDelegate" + MsgSuperfluidUndelegate = "/osmosis.superfluid.MsgSuperfluidUndelegate" + MsgSuperfluidUnbondLock = "/osmosis.superfluid.MsgSuperfluidUnbondLock" + MsgLockAndSuperfluidDelegate = "/osmosis.superfluid.MsgLockAndSuperfluidDelegate" + MsgUnPoolWhitelistedPool = "/osmosis.superfluid.MsgUnPoolWhitelistedPool" + MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition = "/osmosis.superfluid.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition" ) From 3ab136f001e38b4b4eddd8c9aaed6e3e299d06e2 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Thu, 7 Sep 2023 18:25:41 -0400 Subject: [PATCH 11/11] Add more superfluid message types to type ignore list --- core/tx.go | 4 ++++ osmosis/modules/superfluid/types.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/core/tx.go b/core/tx.go index e80f90c..82ea2c1 100644 --- a/core/tx.go +++ b/core/tx.go @@ -105,6 +105,10 @@ var messageTypeIgnorer = map[string]interface{}{ superfluid.MsgLockAndSuperfluidDelegate: nil, superfluid.MsgUnPoolWhitelistedPool: nil, superfluid.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition: nil, + superfluid.MsgSuperfluidUndelegateAndUnbondLock: nil, + superfluid.MsgCreateFullRangePositionAndSuperfluidDelegate: nil, + superfluid.MsgAddToConcentratedLiquiditySuperfluidPosition: nil, + superfluid.MsgUnbondConvertAndStake: nil, // Setting validator pref is not taxable valsetpref.MsgSetValidatorSetPreference: nil, diff --git a/osmosis/modules/superfluid/types.go b/osmosis/modules/superfluid/types.go index 67f97cb..eb864f8 100644 --- a/osmosis/modules/superfluid/types.go +++ b/osmosis/modules/superfluid/types.go @@ -7,4 +7,8 @@ const ( MsgLockAndSuperfluidDelegate = "/osmosis.superfluid.MsgLockAndSuperfluidDelegate" MsgUnPoolWhitelistedPool = "/osmosis.superfluid.MsgUnPoolWhitelistedPool" MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition = "/osmosis.superfluid.MsgUnlockAndMigrateSharesToFullRangeConcentratedPosition" + MsgSuperfluidUndelegateAndUnbondLock = "/osmosis.superfluid.MsgSuperfluidUndelegateAndUnbondLock" + MsgCreateFullRangePositionAndSuperfluidDelegate = "/osmosis.superfluid.MsgCreateFullRangePositionAndSuperfluidDelegate" + MsgAddToConcentratedLiquiditySuperfluidPosition = "/osmosis.superfluid.MsgAddToConcentratedLiquiditySuperfluidPosition" + MsgUnbondConvertAndStake = "/osmosis.superfluid.MsgUnbondConvertAndStake" )