Skip to content

Commit

Permalink
fix: querying old tax params proposals
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockwarr committed Jan 20, 2025
1 parent 006a25a commit ca0a41a
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import (
"github.com/Nolus-Protocol/nolus-core/app/keepers"
appparams "github.com/Nolus-Protocol/nolus-core/app/params"
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
v069 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v069"
v070 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v070"
"github.com/Nolus-Protocol/nolus-core/docs"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand All @@ -68,7 +68,7 @@ const (
var (
DefaultNodeHome string

Upgrades = []upgrades.Upgrade{v069.Upgrade}
Upgrades = []upgrades.Upgrade{v070.Upgrade}
)

var (
Expand Down
19 changes: 19 additions & 0 deletions app/upgrades/v070/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v070

import (
store "cosmossdk.io/store/types"
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrades name.
UpgradeName = "v0.7.0"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
},
}
33 changes: 33 additions & 0 deletions app/upgrades/v070/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package v070

import (
"context"
"fmt"

"github.com/Nolus-Protocol/nolus-core/app/keepers"

upgradetypes "cosmossdk.io/x/upgrade/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
codec codec.Codec,
) upgradetypes.UpgradeHandler {
return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx := sdk.UnwrapSDKContext(c)

ctx.Logger().Info("Starting module migrations...")
vm, err := mm.RunMigrations(ctx, configurator, vm) //nolint:contextcheck
if err != nil {
return vm, err
}

ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName))
return vm, nil
}
}
45 changes: 45 additions & 0 deletions doc/adr/20250115-accept-fees-in-foreign-denoms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Upgrade to accept fees in foreign denoms

- Status: Accepted
- Deciders: Product Owner, Development Team
- Date: (2023-12-15)
- Updated : 2025-01-15
- Tags: foreign fees, cosmos-sdk, refactoring

Technical Story
We aim to allow the nolus protocol to accept fees paid in foreign denoms and not only in NLS. This will involve a custom fee checker functionality which was introduced in cosmos-sdk@v47+, executed with the help of ante handlers. The custom fee checker will be implemented as a part of the x/tax module.

## Context and Problem Statement

The decision to enable paying in foreign denoms (to the nolus network) is driven by the desire to scale our protocol and make it easier to use for new users. The protocol won't support all kinds of foreign denoms out of the box but will be controlled with parameters for the custom nolus' x/gov module.

## Decision Drivers


Having the ability to pay fees in denoms other than NLS will allow us to not require every user to own NLS to use the network. This will make it easier for newcomers to try out the protocol with their existing funds.

## Decision Outcome

The decision we took is to implement a custom TxFeeChecker functionality executed by the ante handler - cosmos-sdk/x/auth/ante deductFee decorator.The custom txFeeChecker is an optional parameter to the deductFee decorator. We forked the default implementation of the txFeecheker and built additional logic on it to support our use case.

OLD *We used our custom wasm contracts to query for prices and then calculate the fees needed to be paid. Our tax module has new parameters with the following proto format:*
UPDATED: We use custom parameters from the tax module where we select each denom that we want to accept and set a fraction of what is the minimum accepted fee per gas.
The calculation is similar to the default implementation for the fee in base asset. Check the proto files of the tax module to see the new parameters.

For each DEX that we work with, there will be a separate profit address. The denoms that we want to accept as fees will be defined for each DEX. For example, ATOM transferred from dex1 to nolus will have one denom, and ATOM transferred from dex2 to nolus will have another denom. The custom txFeeChecker will compare the denom that the user paid with the accepted denoms. When there is a match, we will know what fraction to use for the minimum required fees calculation. The deducted tax, not paid in the base asset, will be sent to the corresponding profit address from the parameters configuration.

### Positive Consequences

- Easier Onboarding for New Users: New users can participate in the nolus network without the necessity to acquire NLS initially. This reduces the barrier to entry and encourages experimentation with the protocol using existing funds.

- Scalability Enhancement: The flexibility to accept fees in various denoms promotes scalability. As the network evolves, additional foreign denoms can be incorporated through parameter adjustments in the custom nolus' x/gov module.

## Potential evolution

- Monitoring and Analytics: Implement monitoring and analytics tools to track the usage of different denoms and fee structures. This data can inform future adjustments to parameters and provide insights into user behavior within the nolus network.

- Security Audits and Compliance: Conduct regular security audits to ensure the robustness of the implemented fee calculation logic. Stay abreast of regulatory developments and ensure compliance with evolving standards related to decentralized finance (DeFi) and blockchain protocols.

- Cross-Chain Compatibility: Explore possibilities for cross-chain compatibility, allowing the nolus protocol to interact seamlessly with assets and protocols on other blockchains. This could open up new avenues for liquidity and user adoption.

This decision is documented to provide clarity on the rationale behind the upgrade and serves as a reference for future discussions and evaluations related to our blockchain development efforts.
4 changes: 3 additions & 1 deletion x/tax/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/Nolus-Protocol/nolus-core/x/tax/exported"
"github.com/Nolus-Protocol/nolus-core/x/tax/keeper"
"github.com/Nolus-Protocol/nolus-core/x/tax/simulation"
typesv1beta1 "github.com/Nolus-Protocol/nolus-core/x/tax/types"
types "github.com/Nolus-Protocol/nolus-core/x/tax/typesv2"
)

Expand Down Expand Up @@ -66,6 +67,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
// RegisterInterfaces registers the module's interface types.
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
types.RegisterInterfaces(reg)
typesv1beta1.RegisterInterfaces(reg)
}

// DefaultGenesis returns the capability module's default genesis state.
Expand Down Expand Up @@ -156,7 +158,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
m := keeper.NewMigrator(am.keeper, am.legacySubspace)

if err := cfg.RegisterMigration(types.ModuleName, 3, m.Migrate3to4); err != nil {
panic(fmt.Sprintf("failed to migrate x/%s from version 2 to 3: %v", types.ModuleName, err))
panic(fmt.Sprintf("failed to migrate x/%s from version 3 to 4: %v", types.ModuleName, err))
}
}

Expand Down
41 changes: 41 additions & 0 deletions x/tax/types/codec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
)

// We need this file for backwards compatibility. For example, there are proposals for updating the tax params ran with the old parameters structure,
// and they fail the decoding upon querying all/concrete proposals.

var Amino = codec.NewLegacyAmino()

func init() {
RegisterLegacyAminoCodec(Amino)
cryptocodec.RegisterCrypto(Amino)

// Register all Amino interfaces and concrete types on the authz Amino codec
// so that this can later be used to properly serialize MsgGrant and MsgExec
// instances.
sdk.RegisterLegacyAminoCodec(Amino)
}

// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec.
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(Params{}, "nolus-core/x/tax/Params", nil)
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "nolus-core/x/tax/MsgUpdateParams")
}

func RegisterInterfaces(registry sdkcodectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgUpdateParams{},
&QueryParamsRequest{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

0 comments on commit ca0a41a

Please sign in to comment.