Skip to content

Commit

Permalink
#525: Osmosis tokenfactory module support
Browse files Browse the repository at this point in the history
  • Loading branch information
pharr117 committed Jan 27, 2024
1 parent a281fff commit bdd6ae9
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
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
3 changes: 3 additions & 0 deletions osmosis/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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{} }},
}
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
}

0 comments on commit bdd6ae9

Please sign in to comment.