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

Patch/various bug fixes #526

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion config/index_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"errors"
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ///////
////////////////////////////////////////////////////
Expand Down
55 changes: 30 additions & 25 deletions osmosis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,39 @@ 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"
)

// 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{} }},
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{} }},
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{} }},
}
81 changes: 81 additions & 0 deletions osmosis/modules/concentratedliquidity/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
109 changes: 109 additions & 0 deletions osmosis/modules/tokenfactory/types.go
Original file line number Diff line number Diff line change
@@ -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
}
Loading
Loading