Skip to content

Commit ca0a41a

Browse files
committed
fix: querying old tax params proposals
1 parent 006a25a commit ca0a41a

File tree

6 files changed

+143
-3
lines changed

6 files changed

+143
-3
lines changed

app/app.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import (
5353
"github.com/Nolus-Protocol/nolus-core/app/keepers"
5454
appparams "github.com/Nolus-Protocol/nolus-core/app/params"
5555
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
56-
v069 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v069"
56+
v070 "github.com/Nolus-Protocol/nolus-core/app/upgrades/v070"
5757
"github.com/Nolus-Protocol/nolus-core/docs"
5858

5959
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
@@ -68,7 +68,7 @@ const (
6868
var (
6969
DefaultNodeHome string
7070

71-
Upgrades = []upgrades.Upgrade{v069.Upgrade}
71+
Upgrades = []upgrades.Upgrade{v070.Upgrade}
7272
)
7373

7474
var (

app/upgrades/v070/constants.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package v070
2+
3+
import (
4+
store "cosmossdk.io/store/types"
5+
"github.com/Nolus-Protocol/nolus-core/app/upgrades"
6+
)
7+
8+
const (
9+
// UpgradeName defines the on-chain upgrades name.
10+
UpgradeName = "v0.7.0"
11+
)
12+
13+
var Upgrade = upgrades.Upgrade{
14+
UpgradeName: UpgradeName,
15+
CreateUpgradeHandler: CreateUpgradeHandler,
16+
StoreUpgrades: store.StoreUpgrades{
17+
Added: []string{},
18+
},
19+
}

app/upgrades/v070/upgrades.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package v070
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/Nolus-Protocol/nolus-core/app/keepers"
8+
9+
upgradetypes "cosmossdk.io/x/upgrade/types"
10+
"github.com/cosmos/cosmos-sdk/codec"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
12+
"github.com/cosmos/cosmos-sdk/types/module"
13+
)
14+
15+
func CreateUpgradeHandler(
16+
mm *module.Manager,
17+
configurator module.Configurator,
18+
keepers *keepers.AppKeepers,
19+
codec codec.Codec,
20+
) upgradetypes.UpgradeHandler {
21+
return func(c context.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
22+
ctx := sdk.UnwrapSDKContext(c)
23+
24+
ctx.Logger().Info("Starting module migrations...")
25+
vm, err := mm.RunMigrations(ctx, configurator, vm) //nolint:contextcheck
26+
if err != nil {
27+
return vm, err
28+
}
29+
30+
ctx.Logger().Info(fmt.Sprintf("Migration {%s} applied", UpgradeName))
31+
return vm, nil
32+
}
33+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Upgrade to accept fees in foreign denoms
2+
3+
- Status: Accepted
4+
- Deciders: Product Owner, Development Team
5+
- Date: (2023-12-15)
6+
- Updated : 2025-01-15
7+
- Tags: foreign fees, cosmos-sdk, refactoring
8+
9+
Technical Story
10+
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.
11+
12+
## Context and Problem Statement
13+
14+
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.
15+
16+
## Decision Drivers
17+
18+
19+
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.
20+
21+
## Decision Outcome
22+
23+
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.
24+
25+
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:*
26+
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.
27+
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.
28+
29+
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.
30+
31+
### Positive Consequences
32+
33+
- 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.
34+
35+
- 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.
36+
37+
## Potential evolution
38+
39+
- 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.
40+
41+
- 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.
42+
43+
- 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.
44+
45+
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.

x/tax/module.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/Nolus-Protocol/nolus-core/x/tax/exported"
2424
"github.com/Nolus-Protocol/nolus-core/x/tax/keeper"
2525
"github.com/Nolus-Protocol/nolus-core/x/tax/simulation"
26+
typesv1beta1 "github.com/Nolus-Protocol/nolus-core/x/tax/types"
2627
types "github.com/Nolus-Protocol/nolus-core/x/tax/typesv2"
2728
)
2829

@@ -66,6 +67,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
6667
// RegisterInterfaces registers the module's interface types.
6768
func (a AppModuleBasic) RegisterInterfaces(reg cdctypes.InterfaceRegistry) {
6869
types.RegisterInterfaces(reg)
70+
typesv1beta1.RegisterInterfaces(reg)
6971
}
7072

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

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

x/tax/types/codec.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package types
2+
3+
import (
4+
"github.com/cosmos/cosmos-sdk/codec"
5+
"github.com/cosmos/cosmos-sdk/codec/legacy"
6+
sdkcodectypes "github.com/cosmos/cosmos-sdk/codec/types"
7+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
8+
sdk "github.com/cosmos/cosmos-sdk/types"
9+
"github.com/cosmos/cosmos-sdk/types/msgservice"
10+
)
11+
12+
// We need this file for backwards compatibility. For example, there are proposals for updating the tax params ran with the old parameters structure,
13+
// and they fail the decoding upon querying all/concrete proposals.
14+
15+
var Amino = codec.NewLegacyAmino()
16+
17+
func init() {
18+
RegisterLegacyAminoCodec(Amino)
19+
cryptocodec.RegisterCrypto(Amino)
20+
21+
// Register all Amino interfaces and concrete types on the authz Amino codec
22+
// so that this can later be used to properly serialize MsgGrant and MsgExec
23+
// instances.
24+
sdk.RegisterLegacyAminoCodec(Amino)
25+
}
26+
27+
// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec.
28+
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
29+
cdc.RegisterConcrete(Params{}, "nolus-core/x/tax/Params", nil)
30+
legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "nolus-core/x/tax/MsgUpdateParams")
31+
}
32+
33+
func RegisterInterfaces(registry sdkcodectypes.InterfaceRegistry) {
34+
registry.RegisterImplementations(
35+
(*sdk.Msg)(nil),
36+
&MsgUpdateParams{},
37+
&QueryParamsRequest{},
38+
)
39+
40+
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
41+
}

0 commit comments

Comments
 (0)