Skip to content

Commit

Permalink
Patch/failed blocks patches (#489)
Browse files Browse the repository at this point in the history
* Add new tool for dumping failed heights from db to json file

* Add parser and handler for MsgCreateCosmwasmPool that gets the amount spent for the address that created the pool

* Add missing ignore list entry for MsgVoteWeighted

* Improve pool manager swap exact amount in to prefer token_swapped event but fallback to transfer event if it fails

* Reorganize Osmosis gamm parser package for easier development

* Split poolmodels creation messages out of reorganized creates gamm file for more reorg

* Add stableswap pool creation message parser and handlers

* Add more ignore list entries for other message types

* Add new parser for msgswapexactamountin that fixes errors produced by event emissions containing empty strings for amount values
  • Loading branch information
pharr117 authored Sep 25, 2023
1 parent b949512 commit c963a2d
Show file tree
Hide file tree
Showing 19 changed files with 2,396 additions and 1,988 deletions.
6 changes: 5 additions & 1 deletion core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ var messageTypeIgnorer = map[string]interface{}{
authz.MsgRevoke: nil,
// Making a config change is not taxable
distribution.MsgSetWithdrawAddress: nil,
// Making a stableswap config change is not taxable
gamm.MsgStableSwapAdjustScalingFactors: nil,
// Voting is not taxable
gov.MsgVote: nil,
gov.MsgVote: nil,
gov.MsgVoteWeighted: nil,
// The IBC msgs below do not create taxable events
ibc.MsgTransfer: nil,
ibc.MsgUpdateClient: nil,
Expand Down Expand Up @@ -131,6 +134,7 @@ var messageTypeIgnorer = map[string]interface{}{
// CosmWasm
wasm.MsgExecuteContract: nil,
wasm.MsgInstantiateContract: nil,
wasm.MsgInstantiateContract2: nil,
wasm.MsgStoreCode: nil,
wasm.MsgMigrateContract: nil,
wasm.MsgUpdateAdmin: nil,
Expand Down
1 change: 1 addition & 0 deletions cosmwasm/modules/wasm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package wasm
const (
MsgExecuteContract = "/cosmwasm.wasm.v1.MsgExecuteContract"
MsgInstantiateContract = "/cosmwasm.wasm.v1.MsgInstantiateContract"
MsgInstantiateContract2 = "/cosmwasm.wasm.v1.MsgInstantiateContract2"
MsgStoreCode = "/cosmwasm.wasm.v1.MsgStoreCode"
MsgMigrateContract = "/cosmwasm.wasm.v1.MsgMigrateContract"
MsgUpdateAdmin = "/cosmwasm.wasm.v1.MsgUpdateAdmin"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/BurntSushi/toml v1.3.2
// FYI, you can do go get github.com/DefiantLabs/lens@1f6f34841280df179c6e098f040bd584ced43a4c
// (using the commit hash from github) to pin to a specific commit.
github.com/DefiantLabs/lens v0.3.1-0.20230912024053-e1f0edb846cb
github.com/DefiantLabs/lens v0.3.1-0.20230924162135-0717939c271c
github.com/cosmos/cosmos-sdk v0.47.4
github.com/gin-gonic/gin v1.9.1
github.com/go-co-op/gocron v1.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/CosmWasm/wasmvm v1.2.3/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.5.0/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/DefiantLabs/lens v0.3.1-0.20230912024053-e1f0edb846cb h1:Hb5n3S7pgrB0M2K6oEc8JVkd32dCh2KLGxbakGMmBXw=
github.com/DefiantLabs/lens v0.3.1-0.20230912024053-e1f0edb846cb/go.mod h1:fABWE6u4nNrcttpJpn7XeTGMtKVB8yfaVRBENwY+45s=
github.com/DefiantLabs/lens v0.3.1-0.20230924162135-0717939c271c h1:0xoXyeZKBIVunGijUIhxon5D3X3/V2/WzoYkef0AGRI=
github.com/DefiantLabs/lens v0.3.1-0.20230924162135-0717939c271c/go.mod h1:fABWE6u4nNrcttpJpn7XeTGMtKVB8yfaVRBENwY+45s=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
Expand Down
7 changes: 5 additions & 2 deletions osmosis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package osmosis
import (
txTypes "github.com/DefiantLabs/cosmos-indexer/cosmos/modules/tx"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/concentratedliquidity"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/cosmwasmpool"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/gamm"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/poolmanager"
"github.com/DefiantLabs/cosmos-indexer/osmosis/modules/valsetpref"
)

// MessageTypeHandler is used to unmarshal JSON to a particular type.
var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{
gamm.MsgSwapExactAmountIn: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn2{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn3{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn4{} }},
gamm.MsgSwapExactAmountIn: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn2{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn3{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn4{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountIn5{} }},
gamm.MsgSwapExactAmountOut: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgSwapExactAmountOut{} }},
gamm.MsgJoinSwapExternAmountIn: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinSwapExternAmountIn{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinSwapExternAmountIn2{} }},
gamm.MsgJoinSwapShareAmountOut: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinSwapShareAmountOut{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinSwapShareAmountOut2{} }},
Expand All @@ -20,7 +21,8 @@ var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{
gamm.MsgExitPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool2{} }},
gamm.MsgCreatePool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool2{} }},
gamm.MsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreateBalancerPool{} }},
gamm.OldMsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperOldMsgCreateBalancerPool{} }},
gamm.PoolModelsMsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperPoolModelsMsgCreateBalancerPool{} }},
gamm.PoolModelsMsgCreateStableswapPool: {func() txTypes.CosmosMessage { return &gamm.WrapperPoolModelsMsgCreateStableswapPool{} }},
poolmanager.MsgSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountIn{} }},
poolmanager.MsgSwapExactAmountOut: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSwapExactAmountOut{} }},
poolmanager.MsgSplitRouteSwapExactAmountIn: {func() txTypes.CosmosMessage { return &poolmanager.WrapperMsgSplitRouteSwapExactAmountIn{} }},
Expand All @@ -30,6 +32,7 @@ var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{
concentratedliquidity.MsgCreateConcentratedPool: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrappeMsgCreateConcentratedPool{} }},
concentratedliquidity.MsgCollectIncentives: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCollectIncentives{} }},
concentratedliquidity.MsgAddToPosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgAddToPosition{} }},
cosmwasmpool.MsgCreateCosmWasmPool: {func() txTypes.CosmosMessage { return &cosmwasmpool.WrapperMsgCreateCosmWasmPool{} }},
valsetpref.MsgDelegateToValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgDelegateToValidatorSet{} }},
valsetpref.MsgUndelegateFromValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgUndelegateFromValidatorSet{} }},
valsetpref.MsgWithdrawDelegationRewards: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgWithdrawDelegationRewards{} }},
Expand Down
79 changes: 79 additions & 0 deletions osmosis/modules/cosmwasmpool/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package cosmwasmpool

import (
"errors"
"fmt"
"strings"

parsingTypes "github.com/DefiantLabs/cosmos-indexer/cosmos/modules"
txModule "github.com/DefiantLabs/cosmos-indexer/cosmos/modules/tx"
"github.com/DefiantLabs/cosmos-indexer/util"
sdk "github.com/cosmos/cosmos-sdk/types"
cosmwasmPoolModelTypes "github.com/osmosis-labs/osmosis/v19/x/cosmwasmpool/model"
)

const (
MsgCreateCosmWasmPool = "/osmosis.cosmwasmpool.v1beta1.MsgCreateCosmWasmPool"
)

type WrapperMsgCreateCosmWasmPool struct {
txModule.Message
OsmosisMsgCreateCosmWasmPool *cosmwasmPoolModelTypes.MsgCreateCosmWasmPool
Address string
TokensSpent sdk.Coins
}

func (sf *WrapperMsgCreateCosmWasmPool) String() string {
var tokensSpent []string
if !(len(sf.TokensSpent) == 0) {
for _, v := range sf.TokensSpent {
tokensSpent = append(tokensSpent, v.String())
}
}
return fmt.Sprintf("MsgCreateCosmWasmPool: %s created pool and spent %s",
sf.Address, strings.Join(tokensSpent, ", "))
}

func (sf *WrapperMsgCreateCosmWasmPool) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error {
sf.Type = msgType
sf.OsmosisMsgCreateCosmWasmPool = msg.(*cosmwasmPoolModelTypes.MsgCreateCosmWasmPool)

validLog := txModule.IsMessageActionEquals(sf.GetType(), log)
if !validLog {
return util.ReturnInvalidLog(msgType, log)
}

coinSpentEvents := txModule.GetEventsWithType("coin_spent", log)
if len(coinSpentEvents) == 0 {
return &txModule.MessageLogFormatError{MessageType: msgType, Log: fmt.Sprintf("%+v", log)}
}

senderCoinsSpentStrings := txModule.GetCoinsSpent(sf.OsmosisMsgCreateCosmWasmPool.Sender, coinSpentEvents)

for _, coinSpentString := range senderCoinsSpentStrings {
coinsSpent, err := sdk.ParseCoinsNormalized(coinSpentString)
if err != nil {
return errors.New("error parsing coins spent from event")
}

sf.TokensSpent = append(sf.TokensSpent, coinsSpent...)
}

sf.Address = sf.OsmosisMsgCreateCosmWasmPool.Sender

return nil
}

func (sf *WrapperMsgCreateCosmWasmPool) ParseRelevantData() []parsingTypes.MessageRelevantInformation {
relevantData := make([]parsingTypes.MessageRelevantInformation, 0)
for _, token := range sf.TokensSpent {
if token.Amount.IsPositive() {
relevantData = append(relevantData, parsingTypes.MessageRelevantInformation{
AmountSent: token.Amount.BigInt(),
DenominationSent: token.Denom,
SenderAddress: sf.Address,
})
}
}
return relevantData
}
Loading

0 comments on commit c963a2d

Please sign in to comment.