From d6947679c42a1cb3a915ae8f8a7fcb53e6fb5924 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Sat, 27 Jan 2024 11:09:26 -0500 Subject: [PATCH 1/4] #522: Fix validation to respect start block, end block and block input file as a group --- config/index_config.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/config/index_config.go b/config/index_config.go index c611676..44db2b3 100644 --- a/config/index_config.go +++ b/config/index_config.go @@ -3,6 +3,7 @@ package config import ( "errors" "fmt" + "os" "strings" "github.com/spf13/cobra" @@ -96,7 +97,7 @@ func (conf *IndexConfig) Validate() error { } // Check for required configs when base indexer is enabled - if conf.Base.ChainIndexingEnabled { + if conf.Base.ChainIndexingEnabled && conf.Base.BlockInputFile == "" { if conf.Base.StartBlock == 0 { return errors.New("base.start-block must be set when index-chain is enabled") } @@ -105,6 +106,13 @@ func (conf *IndexConfig) Validate() error { } } + if conf.Base.ChainIndexingEnabled && conf.Base.BlockInputFile != "" { + // Check if block input file exists + if _, err := os.Stat(conf.Base.BlockInputFile); os.IsNotExist(err) { + return errors.New("base.block-input-file does not exist") + } + } + // Check for required configs when block event indexer is enabled if conf.Base.BlockEventIndexingEnabled { // If block event indexes are not valid, error From 451e3b7030b7474f5df981cf240216de08d8780c Mon Sep 17 00:00:00 2001 From: pharr117 Date: Sat, 27 Jan 2024 11:43:10 -0500 Subject: [PATCH 2/4] #523: Fix missing parser for rewards withdrawal for MsgUndelegateFromRebalancedValidatorSet --- osmosis/handlers.go | 51 +++++++++++++++-------------- osmosis/modules/valsetpref/types.go | 47 +++++++++++++++++++++++--- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/osmosis/handlers.go b/osmosis/handlers.go index ebe875a..bb4151e 100644 --- a/osmosis/handlers.go +++ b/osmosis/handlers.go @@ -11,29 +11,30 @@ import ( // 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{} }, 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{} }}, - gamm.MsgJoinPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinPool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinPool2{} }}, - gamm.MsgExitSwapShareAmountIn: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapShareAmountIn{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapShareAmountIn2{} }}, - gamm.MsgExitSwapExternAmountOut: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapExternAmountOut{} }}, - gamm.MsgExitPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool2{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool3{} }}, - gamm.MsgCreatePool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool2{} }}, - gamm.MsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreateBalancerPool{} }}, - 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{} }}, - concentratedliquidity.MsgCreatePosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCreatePosition{} }}, - concentratedliquidity.MsgWithdrawPosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgWithdrawPosition{} }}, - concentratedliquidity.MsgCollectSpreadRewards: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCollectSpreadRewards{} }}, - 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{} }}, + 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{} }}, + gamm.MsgJoinPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinPool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgJoinPool2{} }}, + gamm.MsgExitSwapShareAmountIn: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapShareAmountIn{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapShareAmountIn2{} }}, + gamm.MsgExitSwapExternAmountOut: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitSwapExternAmountOut{} }}, + gamm.MsgExitPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool2{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgExitPool3{} }}, + gamm.MsgCreatePool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool{} }, func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreatePool2{} }}, + gamm.MsgCreateBalancerPool: {func() txTypes.CosmosMessage { return &gamm.WrapperMsgCreateBalancerPool{} }}, + 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{} }}, + concentratedliquidity.MsgCreatePosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCreatePosition{} }}, + concentratedliquidity.MsgWithdrawPosition: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgWithdrawPosition{} }}, + concentratedliquidity.MsgCollectSpreadRewards: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgCollectSpreadRewards{} }}, + 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{} }}, + valsetpref.MsgUndelegateFromRebalancedValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgUndelegateFromRebalancedValidatorSet{} }}, } diff --git a/osmosis/modules/valsetpref/types.go b/osmosis/modules/valsetpref/types.go index e78d607..384854b 100644 --- a/osmosis/modules/valsetpref/types.go +++ b/osmosis/modules/valsetpref/types.go @@ -13,11 +13,12 @@ import ( ) const ( - MsgSetValidatorSetPreference = "/osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference" - MsgDelegateToValidatorSet = "/osmosis.valsetpref.v1beta1.MsgDelegateToValidatorSet" - MsgUndelegateFromValidatorSet = "/osmosis.valsetpref.v1beta1.MsgUndelegateFromValidatorSet" - MsgRedelegateValidatorSet = "/osmosis.valsetpref.v1beta1.MsgRedelegateValidatorSet" - MsgWithdrawDelegationRewards = "/osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewards" + MsgSetValidatorSetPreference = "/osmosis.valsetpref.v1beta1.MsgSetValidatorSetPreference" + MsgDelegateToValidatorSet = "/osmosis.valsetpref.v1beta1.MsgDelegateToValidatorSet" + MsgUndelegateFromValidatorSet = "/osmosis.valsetpref.v1beta1.MsgUndelegateFromValidatorSet" + MsgRedelegateValidatorSet = "/osmosis.valsetpref.v1beta1.MsgRedelegateValidatorSet" + MsgWithdrawDelegationRewards = "/osmosis.valsetpref.v1beta1.MsgWithdrawDelegationRewards" + MsgUndelegateFromRebalancedValidatorSet = "/osmosis.valsetpref.v1beta1.MsgUndelegateFromRebalancedValidatorSet" // linter thinks this is a password //nolint:gosec MsgDelegateBondedTokens = "/osmosis.valsetpref.v1beta1.MsgDelegateBondedTokens" @@ -253,3 +254,39 @@ func (sf *WrapperMsgDelegateBondedTokens) HandleMsg(msgType string, msg sdk.Msg, func (sf *WrapperMsgDelegateBondedTokens) ParseRelevantData() []parsingTypes.MessageRelevantInformation { return getRelevantData(sf.RewardsOut, sf.DelegatorAddress) } + +type WrapperMsgUndelegateFromRebalancedValidatorSet struct { + txModule.Message + OsmosisMsgUndelegateFromRebalancedValidatorSet *valsetPrefTypes.MsgUndelegateFromRebalancedValidatorSet + DelegatorAddress string + RewardsOut sdk.Coins +} + +func (sf *WrapperMsgUndelegateFromRebalancedValidatorSet) String() string { + return getString("MsgUndelegateFromRebalancedValidatorSet", sf.RewardsOut, sf.DelegatorAddress) +} + +func (sf *WrapperMsgUndelegateFromRebalancedValidatorSet) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { + sf.Type = msgType + sf.OsmosisMsgUndelegateFromRebalancedValidatorSet = msg.(*valsetPrefTypes.MsgUndelegateFromRebalancedValidatorSet) + sf.DelegatorAddress = sf.OsmosisMsgUndelegateFromRebalancedValidatorSet.Delegator + + // Confirm that the action listed in the message log matches the Message type + validLog := txModule.IsMessageActionEquals(sf.GetType(), log) + if !validLog { + return util.ReturnInvalidLog(msgType, log) + } + + coins, err := getRewardsReceived(log, sf.DelegatorAddress) + if err != nil { + return err + } + + sf.RewardsOut = coins + + return nil +} + +func (sf *WrapperMsgUndelegateFromRebalancedValidatorSet) ParseRelevantData() []parsingTypes.MessageRelevantInformation { + return getRelevantData(sf.RewardsOut, sf.DelegatorAddress) +} From a281fff876e3f8504e09ecb7a4e38fd958dd151f Mon Sep 17 00:00:00 2001 From: pharr117 Date: Sat, 27 Jan 2024 14:34:16 -0500 Subject: [PATCH 3/4] #524: Fix missing parser for rewards withdrawal for MsgTransferPositions --- osmosis/handlers.go | 1 + .../modules/concentratedliquidity/types.go | 81 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/osmosis/handlers.go b/osmosis/handlers.go index bb4151e..9576a03 100644 --- a/osmosis/handlers.go +++ b/osmosis/handlers.go @@ -32,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{} }}, + concentratedliquidity.MsgTransferPositions: {func() txTypes.CosmosMessage { return &concentratedliquidity.WrapperMsgTransferPositions{} }}, cosmwasmpool.MsgCreateCosmWasmPool: {func() txTypes.CosmosMessage { return &cosmwasmpool.WrapperMsgCreateCosmWasmPool{} }}, valsetpref.MsgDelegateToValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgDelegateToValidatorSet{} }}, valsetpref.MsgUndelegateFromValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgUndelegateFromValidatorSet{} }}, diff --git a/osmosis/modules/concentratedliquidity/types.go b/osmosis/modules/concentratedliquidity/types.go index 402f9a8..1cbe068 100644 --- a/osmosis/modules/concentratedliquidity/types.go +++ b/osmosis/modules/concentratedliquidity/types.go @@ -20,6 +20,7 @@ const ( MsgCreateConcentratedPool = "/osmosis.concentratedliquidity.poolmodel.concentrated.v1beta1.MsgCreateConcentratedPool" MsgCollectIncentives = "/osmosis.concentratedliquidity.v1beta1.MsgCollectIncentives" MsgAddToPosition = "/osmosis.concentratedliquidity.v1beta1.MsgAddToPosition" + MsgTransferPositions = "/osmosis.concentratedliquidity.v1beta1.MsgTransferPositions" tokensOutEvent = "tokens_out" ) @@ -456,3 +457,83 @@ func (sf *WrapperMsgAddToPosition) ParseRelevantData() []parsingTypes.MessageRel return relevantData } + +type WrapperMsgTransferPositions struct { + txModule.Message + OsmosisMsgTransferPositions *clTypes.MsgTransferPositions + TokensRecv sdk.Coins + Address string +} + +func (sf *WrapperMsgTransferPositions) String() string { + var tokensRecv []string + var tokensRecvString string + + if !(len(sf.TokensRecv) == 0) { + for _, v := range sf.TokensRecv { + tokensRecv = append(tokensRecv, v.String()) + } + + tokensRecvString = strings.Join(tokensRecv, ", ") + " in rewards" + } else { + tokensRecvString = "no rewards" + } + + return fmt.Sprintf("MsgTransferPositions: %s collected %s", + sf.Address, tokensRecvString) +} + +func (sf *WrapperMsgTransferPositions) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { + sf.Type = msgType + sf.OsmosisMsgTransferPositions = msg.(*clTypes.MsgTransferPositions) + + // Collect spread rewards + spreadRewardsEvents := txModule.GetEventsWithType("collect_spread_rewards", log) + + for _, spreadRewardsEvent := range spreadRewardsEvents { + for _, attribute := range spreadRewardsEvent.Attributes { + if attribute.Key == tokensOutEvent { + coinsReceived, err := sdk.ParseCoinsNormalized(attribute.Value) + if err != nil { + return errors.New("error parsing coins received from spread rewards event") + } + sf.TokensRecv = append(sf.TokensRecv, coinsReceived...) + } + } + } + + // Collect incentives + incentivesEvents := txModule.GetEventsWithType("collect_incentives", log) + + for _, incentivesEvent := range incentivesEvents { + for _, attribute := range incentivesEvent.Attributes { + if attribute.Key == tokensOutEvent { + coinsReceived, err := sdk.ParseCoinsNormalized(attribute.Value) + if err != nil { + return errors.New("error parsing coins received from incentives event") + } + sf.TokensRecv = append(sf.TokensRecv, coinsReceived...) + } + } + } + + sf.Address = sf.OsmosisMsgTransferPositions.Sender + + return nil +} + +func (sf *WrapperMsgTransferPositions) ParseRelevantData() []parsingTypes.MessageRelevantInformation { + relevantData := make([]parsingTypes.MessageRelevantInformation, 0) + + for _, token := range sf.TokensRecv { + if token.Amount.IsPositive() { + relevantData = append(relevantData, parsingTypes.MessageRelevantInformation{ + AmountReceived: token.Amount.BigInt(), + DenominationReceived: token.Denom, + SenderAddress: sf.Address, + }) + } + } + + return relevantData +} From bdd6ae9b3b10e5a0d078641dc1853364895398b7 Mon Sep 17 00:00:00 2001 From: pharr117 Date: Sat, 27 Jan 2024 15:09:10 -0500 Subject: [PATCH 4/4] #525: Osmosis tokenfactory module support --- core/tx.go | 6 ++ osmosis/handlers.go | 3 + osmosis/modules/tokenfactory/types.go | 109 ++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 osmosis/modules/tokenfactory/types.go diff --git a/core/tx.go b/core/tx.go index 5eb1041..b1d1481 100644 --- a/core/tx.go +++ b/core/tx.go @@ -27,6 +27,7 @@ import ( "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/incentives" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/lockup" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/superfluid" + "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/tokenfactory" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/valsetpref" "github.com/DefiantLabs/cosmos-tax-cli/tendermint/modules/liquidity" "github.com/DefiantLabs/cosmos-tax-cli/util" @@ -133,6 +134,11 @@ var messageTypeIgnorer = map[string]interface{}{ liquidity.MsgWithdrawWithinBatch: nil, liquidity.MsgSwapWithinBatch: nil, + // These tokenfactory module messages dont create taxable events + tokenfactory.MsgCreateDenom: nil, + tokenfactory.MsgSetBeforeSendHook: nil, + tokenfactory.MsgSetDenomMetadata: nil, + //////////////////////////////////////////////////// /////// Possible Taxable Events, future work /////// //////////////////////////////////////////////////// diff --git a/osmosis/handlers.go b/osmosis/handlers.go index 9576a03..239611d 100644 --- a/osmosis/handlers.go +++ b/osmosis/handlers.go @@ -6,6 +6,7 @@ import ( "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/cosmwasmpool" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/gamm" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/poolmanager" + "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/tokenfactory" "github.com/DefiantLabs/cosmos-tax-cli/osmosis/modules/valsetpref" ) @@ -38,4 +39,6 @@ var MessageTypeHandler = map[string][]func() txTypes.CosmosMessage{ valsetpref.MsgUndelegateFromValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgUndelegateFromValidatorSet{} }}, valsetpref.MsgWithdrawDelegationRewards: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgWithdrawDelegationRewards{} }}, valsetpref.MsgUndelegateFromRebalancedValidatorSet: {func() txTypes.CosmosMessage { return &valsetpref.WrapperMsgUndelegateFromRebalancedValidatorSet{} }}, + tokenfactory.MsgMint: {func() txTypes.CosmosMessage { return &tokenfactory.WrapperMsgMint{} }}, + tokenfactory.MsgBurn: {func() txTypes.CosmosMessage { return &tokenfactory.WrapperMsgBurn{} }}, } diff --git a/osmosis/modules/tokenfactory/types.go b/osmosis/modules/tokenfactory/types.go new file mode 100644 index 0000000..e4af181 --- /dev/null +++ b/osmosis/modules/tokenfactory/types.go @@ -0,0 +1,109 @@ +package tokenfactory + +import ( + "fmt" + + parsingTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules" + txModule "github.com/DefiantLabs/cosmos-tax-cli/cosmos/modules/tx" + "github.com/DefiantLabs/cosmos-tax-cli/util" + sdk "github.com/cosmos/cosmos-sdk/types" + tfTypes "github.com/osmosis-labs/osmosis/v21/x/tokenfactory/types" +) + +const ( + MsgCreateDenom = "/osmosis.tokenfactory.v1beta1.MsgCreateDenom" + MsgMint = "/osmosis.tokenfactory.v1beta1.MsgMint" + MsgBurn = "/osmosis.tokenfactory.v1beta1.MsgBurn" + MsgSetDenomMetadata = "/osmosis.tokenfactory.v1beta1.MsgSetDenomMetadata" + MsgSetBeforeSendHook = "/osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook" +) + +// Create interface definition for MsgMint +type WrapperMsgMint struct { + txModule.Message + OsmosisMsgMint *tfTypes.MsgMint + Address string + CoinReceived sdk.Coin +} + +func (sf *WrapperMsgMint) String() string { + return fmt.Sprintf("MsgMint: %s received %s", + sf.Address, sf.CoinReceived.String()) +} + +func (sf *WrapperMsgMint) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { + sf.Type = msgType + sf.OsmosisMsgMint = msg.(*tfTypes.MsgMint) + + validLog := txModule.IsMessageActionEquals(sf.GetType(), log) + if !validLog { + return util.ReturnInvalidLog(msgType, log) + } + + // This logic is pulled from the Osmosis codebase of who gets minted to. + // See here: https://github.com/osmosis-labs/osmosis/blob/7c81b90825ab2efe92444ac167191b8d041e0c21/x/tokenfactory/keeper/msg_server.go#L63-L65 + + sf.Address = sf.OsmosisMsgMint.MintToAddress + + if sf.Address == "" { + sf.Address = sf.OsmosisMsgMint.Sender + } + + sf.CoinReceived = sf.OsmosisMsgMint.Amount + + return nil +} + +func (sf *WrapperMsgMint) ParseRelevantData() []parsingTypes.MessageRelevantInformation { + relevantData := make([]parsingTypes.MessageRelevantInformation, 1) + + relevantData[0] = parsingTypes.MessageRelevantInformation{ + AmountReceived: sf.CoinReceived.Amount.BigInt(), + DenominationReceived: sf.CoinReceived.Denom, + ReceiverAddress: sf.Address, + } + return relevantData +} + +type WrapperMsgBurn struct { + txModule.Message + OsmosisMsgBurn *tfTypes.MsgBurn + Address string + CoinSent sdk.Coin +} + +func (sf *WrapperMsgBurn) String() string { + return fmt.Sprintf("MsgBurn: %s sent %s", + sf.Address, sf.CoinSent.String()) +} + +func (sf *WrapperMsgBurn) HandleMsg(msgType string, msg sdk.Msg, log *txModule.LogMessage) error { + sf.Type = msgType + sf.OsmosisMsgBurn = msg.(*tfTypes.MsgBurn) + + validLog := txModule.IsMessageActionEquals(sf.GetType(), log) + if !validLog { + return util.ReturnInvalidLog(msgType, log) + } + + sf.Address = sf.OsmosisMsgBurn.BurnFromAddress + + if sf.Address == "" { + sf.Address = sf.OsmosisMsgBurn.Sender + } + + sf.CoinSent = sf.OsmosisMsgBurn.Amount + + return nil +} + +func (sf *WrapperMsgBurn) ParseRelevantData() []parsingTypes.MessageRelevantInformation { + relevantData := make([]parsingTypes.MessageRelevantInformation, 1) + + relevantData[0] = parsingTypes.MessageRelevantInformation{ + AmountSent: sf.CoinSent.Amount.BigInt(), + DenominationSent: sf.CoinSent.Denom, + SenderAddress: sf.Address, + } + return relevantData +}