Skip to content

Commit

Permalink
Merge pull request #565 from DefiantLabs/pharr117/lens-updates-osmosi…
Browse files Browse the repository at this point in the history
…s-v26

pharr117/lens updates osmosis v26
  • Loading branch information
pharr117 authored Sep 29, 2024
2 parents 6191481 + a1e6a86 commit 7af9805
Show file tree
Hide file tree
Showing 25 changed files with 591 additions and 1,213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: '1.22'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.10-alpine3.18 AS build-env
FROM golang:1.22.4-alpine3.19 AS build-env

# Customize to your build env

Expand All @@ -14,12 +14,12 @@ RUN apk add --update --no-cache curl make git libc-dev bash gcc linux-headers eu

# Install build dependencies.
RUN if [ "${TARGETPLATFORM}" = "linux/amd64" ] ; then \
wget -P /lib https://github.com/CosmWasm/wasmvm/releases/download/v1.2.3/libwasmvm_muslc.x86_64.a ; \
wget -P /lib https://github.com/CosmWasm/wasmvm/releases/download/v2.1.2/libwasmvm_muslc.x86_64.a ; \
cp /lib/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a ; \
fi

RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ] ; then \
wget -P /lib https://github.com/CosmWasm/wasmvm/releases/download/v1.2.3/libwasmvm_muslc.aarch64.a ; \
wget -P /lib https://github.com/CosmWasm/wasmvm/releases/download/v2.1.2/libwasmvm_muslc.aarch64.a ; \
cp /lib/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.a ; \
fi

Expand Down
1 change: 1 addition & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rpc-retry-max-wait=30 #RPC query failure backoff max wait time in seconds
[lens]
rpc = "https://rpc.kujira.ccvalidators.com:443" #On Kujira use one of the endpoints from the list https://github.com/Team-Kujira/networks/tree/master/mainnet
account-prefix = "kujira"
validator-account-prefix="kujiravaloper"
chain-id = "kaiyo-1"
chain-name = "Kujira"

Expand Down
15 changes: 10 additions & 5 deletions config/common_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ type Database struct {
}

type lens struct {
RPC string
AccountPrefix string `mapstructure:"account-prefix"`
ChainID string `mapstructure:"chain-id"`
ChainName string `mapstructure:"chain-name"`
RPC string
AccountPrefix string `mapstructure:"account-prefix"`
ValidatorAccountPrefix string `mapstructure:"validator-account-prefix"`
ChainID string `mapstructure:"chain-id"`
ChainName string `mapstructure:"chain-name"`
}

type throttlingBase struct {
Expand Down Expand Up @@ -59,7 +60,8 @@ func SetupDatabaseFlags(databaseConf *Database, cmd *cobra.Command) {

func SetupLensFlags(lensConf *lens, cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&lensConf.RPC, "lens.rpc", "", "node rpc endpoint")
cmd.PersistentFlags().StringVar(&lensConf.AccountPrefix, "lens.account-prefix", "", "lens account prefix")
cmd.PersistentFlags().StringVar(&lensConf.AccountPrefix, "lens.account-prefix", "osmo", "lens account prefix")
cmd.PersistentFlags().StringVar(&lensConf.ValidatorAccountPrefix, "lens.validator-account-prefix", "osmovaloper", "lens validator account prefix")
cmd.PersistentFlags().StringVar(&lensConf.ChainID, "lens.chain-id", "", "lens chain ID")
cmd.PersistentFlags().StringVar(&lensConf.ChainName, "lens.chain-name", "", "lens chain name")
}
Expand Down Expand Up @@ -104,6 +106,9 @@ func validateLensConf(lensConf lens) (lens, error) {
if util.StrNotSet(lensConf.AccountPrefix) {
return lensConf, errors.New("lens account-prefix must be set")
}
if util.StrNotSet(lensConf.ValidatorAccountPrefix) {
return lensConf, errors.New("lens validator-account-prefix must be set")
}
if util.StrNotSet(lensConf.ChainID) {
return lensConf, errors.New("lens chain-id must be set")
}
Expand Down
11 changes: 9 additions & 2 deletions config/lens_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package config

import (
lensClient "github.com/DefiantLabs/lens/client"
ibcTypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/cosmos/cosmos-sdk/types/module"
ibcTypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
)

func GetLensClient(conf lens) *lensClient.ChainClient {
Expand All @@ -25,6 +26,12 @@ func RegisterAdditionalTypes(cc *lensClient.ChainClient) {
}

func GetLensConfig(conf lens, debug bool) *lensClient.ChainClientConfig {
mods := []module.AppModuleBasic{}

for _, mod := range lensClient.OsmosisModuleBasics {
mods = append(mods, mod)
}

return &lensClient.ChainClientConfig{
Key: "default",
ChainID: conf.ChainID,
Expand All @@ -38,6 +45,6 @@ func GetLensConfig(conf lens, debug bool) *lensClient.ChainClientConfig {
Timeout: "30s",
OutputFormat: "json",
SignModeStr: "direct",
Modules: lensClient.OsmosisModuleBasics,
Modules: mods,
}
}
2 changes: 1 addition & 1 deletion core/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func ExtractTransactionAddresses(tx tx.MergedTx) []string {
func ParseSignerAddress(pubkeyString string, keytype string) (retstring string, reterror error) {
defer func() {
if r := recover(); r != nil {
reterror = fmt.Errorf(fmt.Sprintf("Error parsing signer address into Bech32: %v", r))
reterror = fmt.Errorf("error parsing signer address into Bech32: %v", r)
retstring = ""
}
}()
Expand Down
4 changes: 2 additions & 2 deletions core/block_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/DefiantLabs/cosmos-tax-cli/config"
eventTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/events"
"github.com/DefiantLabs/cosmos-tax-cli/cosmoshub"
ctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/DefiantLabs/cosmos-tax-cli/rpc"
)

var (
Expand All @@ -32,7 +32,7 @@ func ChainSpecificBeginBlockerEventTypeHandlerBootstrap(chainID string) {
// Stub, for use when we have begin blocker events
}

func ProcessRPCBlockEvents(blockResults *ctypes.ResultBlockResults) ([]eventTypes.EventRelevantInformation, error) {
func ProcessRPCBlockEvents(blockResults *rpc.CustomBlockResults) ([]eventTypes.EventRelevantInformation, error) {
var taxableEvents []eventTypes.EventRelevantInformation
if len(endBlockerEventTypeHandlers) != 0 {
for _, event := range blockResults.EndBlockEvents {
Expand Down
4 changes: 2 additions & 2 deletions core/epoch_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
eventTypes "github.com/DefiantLabs/cosmos-tax-cli/cosmos/events"
osmosisTypes "github.com/DefiantLabs/cosmos-tax-cli/osmosis"
osmosisEpochTypes "github.com/DefiantLabs/cosmos-tax-cli/osmosis/epochs"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/DefiantLabs/cosmos-tax-cli/rpc"
)

var epochIdentifierEventTypeHandlers = map[string]map[string]map[string][]func() eventTypes.CosmosEvent{}
Expand All @@ -19,7 +19,7 @@ func ChainSpecificEpochIdentifierEventTypeHandlersBootstrap(chainID string) {
}
}

func ProcessRPCEpochEvents(blockResults *coretypes.ResultBlockResults, epochIdentifier string) ([]eventTypes.EventRelevantInformation, error) {
func ProcessRPCEpochEvents(blockResults *rpc.CustomBlockResults, epochIdentifier string) ([]eventTypes.EventRelevantInformation, error) {
var taxableEvents []eventTypes.EventRelevantInformation

if handlers, ok := epochIdentifierEventTypeHandlers[epochIdentifier]; ok {
Expand Down
39 changes: 33 additions & 6 deletions core/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
cosmosTx "github.com/cosmos/cosmos-sdk/types/tx"
"gorm.io/gorm"

sdkMath "cosmossdk.io/math"
indexerEvents "github.com/DefiantLabs/cosmos-tax-cli/cosmos/events"
)

Expand Down Expand Up @@ -351,7 +352,15 @@ func ProcessRPCBlockByHeightTXs(db *gorm.DB, cl *client.ChainClient, blockResult
}

indexerTx.AuthInfo = *txFull.AuthInfo
indexerTx.Signers = txFull.GetSigners()
txSigners, _, err := txFull.GetSigners(cl.Codec.Marshaler)
if err != nil {
return nil, blockTime, fmt.Errorf("error getting signers: %v", err)
}

for _, signer := range txSigners {
indexerTx.Signers = append(indexerTx.Signers, signer)
}

indexerMergedTx.TxResponse = indexerTxResp
indexerMergedTx.Tx = indexerTx
indexerMergedTx.Tx.AuthInfo = *txFull.AuthInfo
Expand All @@ -361,7 +370,12 @@ func ProcessRPCBlockByHeightTXs(db *gorm.DB, cl *client.ChainClient, blockResult
return currTxDbWrappers, blockTime, err
}

processedTx.SignerAddress = dbTypes.Address{Address: txFull.FeePayer().String()}
if len(indexerTx.Signers) > 0 {
processedTx.SignerAddress = dbTypes.Address{Address: indexerTx.Signers[0].String()}
} else {
return currTxDbWrappers, blockTime, fmt.Errorf("tx signers could not be processed, no signers found")
}

currTxDbWrappers[txIdx] = processedTx
}

Expand Down Expand Up @@ -430,7 +444,15 @@ func ProcessRPCTXs(db *gorm.DB, cl *client.ChainClient, txEventResp *cosmosTx.Ge
}

indexerTx.AuthInfo = *currTx.AuthInfo
indexerTx.Signers = currTx.GetSigners()
txSigners, _, err := currTx.GetSigners(cl.Codec.Marshaler)
if err != nil {
return nil, blockTime, fmt.Errorf("error getting signers: %v", err)
}

for _, signer := range txSigners {
indexerTx.Signers = append(indexerTx.Signers, signer)
}

indexerMergedTx.TxResponse = indexerTxResp
indexerMergedTx.Tx = indexerTx
indexerMergedTx.Tx.AuthInfo = *currTx.AuthInfo
Expand All @@ -444,7 +466,12 @@ func ProcessRPCTXs(db *gorm.DB, cl *client.ChainClient, txEventResp *cosmosTx.Ge
blockTime = &txTime
}

processedTx.SignerAddress = dbTypes.Address{Address: currTx.FeePayer().String()}
if len(indexerTx.Signers) > 0 {
processedTx.SignerAddress = dbTypes.Address{Address: indexerTx.Signers[0].String()}
} else {
return currTxDbWrappers, blockTime, fmt.Errorf("tx signers could not be processed, no signers found")
}

currTxDbWrappers[txIdx] = processedTx
}

Expand All @@ -462,8 +489,8 @@ func AnalyzeSwaps() {
for _, swap := range allSwaps {
if swap.TokenOut.Denom == "uosmo" && swap.TokenIn.Denom == "uosmo" {
amount := swap.TokenOut.Amount.Sub(swap.TokenIn.Amount)
if amount.GT(types.ZeroInt()) {
txProfit := amount.ToLegacyDec().Quo(types.NewDec(1000000)).MustFloat64()
if amount.GT(sdkMath.ZeroInt()) {
txProfit := amount.ToLegacyDec().Quo(sdkMath.LegacyNewDec(1000000)).MustFloat64()
profit += txProfit
}

Expand Down
2 changes: 1 addition & 1 deletion cosmos/modules/denoms/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package denoms

import transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
import transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"

type Pagination struct {
NextKey string `json:"next_key"`
Expand Down
18 changes: 9 additions & 9 deletions cosmos/modules/ibc/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"fmt"
"strings"

"cosmossdk.io/math"
sdkMath "cosmossdk.io/math"
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"
stdTypes "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
)

const (
Expand Down Expand Up @@ -59,7 +59,7 @@ type WrapperMsgRecvPacket struct {
Sequence uint64
SenderAddress string
ReceiverAddress string
Amount math.Int
Amount sdkMath.Int
Denom string
}

Expand Down Expand Up @@ -94,7 +94,7 @@ func (w *WrapperMsgRecvPacket) HandleMsg(msgType string, msg stdTypes.Msg, log *
w.ReceiverAddress = data.Receiver
w.Sequence = w.MsgRecvPacket.Packet.Sequence

amount, ok := stdTypes.NewIntFromString(data.Amount)
amount, ok := sdkMath.NewIntFromString(data.Amount)
if !ok {
return fmt.Errorf("failed to convert denom amount to sdk.Int, got(%s)", data.Amount)
}
Expand All @@ -112,7 +112,7 @@ func (w *WrapperMsgRecvPacket) ParseRelevantData() []parsingTypes.MessageRelevan
}

// MsgRecvPacket indicates a user has received assets on this chain so amount sent will always be 0
amountSent := stdTypes.NewInt(0)
amountSent := sdkMath.NewInt(0)

return []parsingTypes.MessageRelevantInformation{{
SenderAddress: w.SenderAddress,
Expand All @@ -137,7 +137,7 @@ type WrapperMsgAcknowledgement struct {
Sequence uint64
SenderAddress string
ReceiverAddress string
Amount math.Int
Amount sdkMath.Int
Denom string
AckType int
AckResult int
Expand Down Expand Up @@ -170,7 +170,7 @@ func (w *WrapperMsgAcknowledgement) HandleMsg(msgType string, msg stdTypes.Msg,
w.ReceiverAddress = data.Receiver
w.Sequence = w.MsgAcknowledgement.Packet.Sequence

amount, ok := stdTypes.NewIntFromString(data.Amount)
amount, ok := sdkMath.NewIntFromString(data.Amount)
if !ok {
return fmt.Errorf("failed to convert denom amount to sdk.Int, got(%s)", data.Amount)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (w *WrapperMsgAcknowledgement) ParseRelevantData() []parsingTypes.MessageRe

// MsgAcknowledgement indicates a user has successfully sent a packet
// so the received amount will always be zero
amountReceived := stdTypes.NewInt(0)
amountReceived := sdkMath.NewInt(0)

return []parsingTypes.MessageRelevantInformation{{
SenderAddress: w.SenderAddress,
Expand Down
Loading

0 comments on commit 7af9805

Please sign in to comment.