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

feat: Allow depositing vesting tokens in the vault #2

Draft
wants to merge 16 commits into
base: feat/provider-module
Choose a base branch
from
Draft
26 changes: 23 additions & 3 deletions demo/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,13 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity"

"github.com/osmosis-labs/mesh-security-sdk/wasmbinding"
meshseckeeper "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/keeper"
meshsectypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurity/types"
meshsecprov "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider"
meshsecprovkeeper "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/keeper"
meshsecprovtypes "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types"
)

const appName = "MeshApp"
Expand Down Expand Up @@ -200,6 +205,7 @@ var (
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
meshsecurity.AppModuleBasic{},
meshsecprov.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -263,6 +269,7 @@ type MeshApp struct {
TransferKeeper ibctransferkeeper.Keeper
WasmKeeper wasmkeeper.Keeper
MeshSecKeeper *meshseckeeper.Keeper
MeshSecProvKeeper *meshsecprovkeeper.Keeper

ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -314,6 +321,7 @@ func NewMeshApp(
wasmtypes.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey,
meshsectypes.StoreKey,
meshsecprovtypes.StoreKey,
)

tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -417,6 +425,13 @@ func NewMeshApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

app.MeshSecProvKeeper = meshsecprovkeeper.NewKeeper(
appCodec,
keys[meshsecprovtypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.BankKeeper,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
legacyAmino,
Expand Down Expand Up @@ -585,15 +600,16 @@ func NewMeshApp(
meshMessageHandler := wasmkeeper.WithMessageHandlerDecorator(func(nested wasmkeeper.Messenger) wasmkeeper.Messenger {
return wasmkeeper.NewMessageHandlerChain(
// security layer for system integrity, should always be first in chain
meshseckeeper.NewIntegrityHandler(app.MeshSecKeeper),
wasmbinding.NewIntegrityHandler(app.MeshSecKeeper),
nested,
// append our custom message handler for mesh-security
meshseckeeper.NewDefaultCustomMsgHandler(app.MeshSecKeeper),
wasmbinding.CustomMessageDecorator(app.MeshSecKeeper, app.MeshSecProvKeeper),
)
})

wasmOpts = append(wasmOpts, meshMessageHandler,
// add support for the mesh-security queries
wasmkeeper.WithQueryHandlerDecorator(meshseckeeper.NewQueryDecorator(app.MeshSecKeeper, app.SlashingKeeper)),
wasmkeeper.WithQueryHandlerDecorator(wasmbinding.NewQueryDecorator(app.MeshSecKeeper, app.SlashingKeeper)),
)
// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
Expand Down Expand Up @@ -694,6 +710,7 @@ func NewMeshApp(
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
meshsecurity.NewAppModule(appCodec, app.MeshSecKeeper),
meshsecprov.NewAppModule(app.MeshSecProvKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
)

Expand All @@ -715,6 +732,7 @@ func NewMeshApp(
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName,
meshsecprovtypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand All @@ -731,6 +749,7 @@ func NewMeshApp(
ibcfeetypes.ModuleName,
wasmtypes.ModuleName,
meshsectypes.ModuleName, // last to capture all chain events
meshsecprovtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -755,6 +774,7 @@ func NewMeshApp(
// wasm after ibc transfer
wasmtypes.ModuleName,
meshsectypes.ModuleName,
meshsecprovtypes.ModuleName,
}
app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
app.ModuleManager.SetOrderExportGenesis(genesisModuleOrder...)
Expand Down
5 changes: 4 additions & 1 deletion demo/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ require (
cosmossdk.io/tools/rosetta v0.2.1
github.com/cometbft/cometbft v0.37.2
github.com/cometbft/cometbft-db v0.8.0
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/wasmbinding v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-20231230023625-3cdce6e349eb
github.com/spf13/viper v1.16.0
)

Expand Down Expand Up @@ -193,6 +194,8 @@ replace (
// See: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1

github.com/osmosis-labs/mesh-security-sdk/wasmbinding => ../wasmbinding

// local work dir
github.com/osmosis-labs/mesh-security-sdk/x => ../x

Expand Down
35 changes: 6 additions & 29 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
- [Query](#osmosis.meshsecurityprovider.Query)

- [osmosis/meshsecurityprovider/tx.proto](#osmosis/meshsecurityprovider/tx.proto)
- [MsgTest](#osmosis.meshsecurityprovider.MsgTest)
- [MsgTestResponse](#osmosis.meshsecurityprovider.MsgTestResponse)
- [MsgUpdateParams](#osmosis.meshsecurityprovider.MsgUpdateParams)
- [MsgUpdateParamsResponse](#osmosis.meshsecurityprovider.MsgUpdateParamsResponse)

Expand Down Expand Up @@ -54,6 +52,11 @@ GenesisState defines the meshsecurityprovider module's genesis state.



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `vault_address` | [string](#string) | | |





Expand Down Expand Up @@ -125,31 +128,6 @@ GenesisState defines the meshsecurityprovider module's genesis state.



<a name="osmosis.meshsecurityprovider.MsgTest"></a>

### MsgTest
===================== MsgTest


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender` | [string](#string) | | |






<a name="osmosis.meshsecurityprovider.MsgTestResponse"></a>

### MsgTestResponse







<a name="osmosis.meshsecurityprovider.MsgUpdateParams"></a>

### MsgUpdateParams
Expand Down Expand Up @@ -196,8 +174,7 @@ Since: cosmos-sdk 0.47

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `Test` | [MsgTest](#osmosis.meshsecurityprovider.MsgTest) | [MsgTestResponse](#osmosis.meshsecurityprovider.MsgTestResponse) | | |
| `UpdateParams` | [MsgUpdateParams](#osmosis.meshsecurityprovider.MsgUpdateParams) | [MsgUpdateParamsResponse](#osmosis.meshsecurityprovider.MsgUpdateParamsResponse) | UpdateParams defines an operation for updating the x/staking module parameters. Since: cosmos-sdk 0.47 | |
| `UpdateParams` | [MsgUpdateParams](#osmosis.meshsecurityprovider.MsgUpdateParams) | [MsgUpdateParamsResponse](#osmosis.meshsecurityprovider.MsgUpdateParamsResponse) | UpdateParams defines an operation for updating the module's parameters. Since: cosmos-sdk 0.47 | |

<!-- end services -->

Expand Down
7 changes: 5 additions & 2 deletions proto/osmosis/meshsecurityprovider/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ syntax = "proto3";
package osmosis.meshsecurityprovider;

import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types";

message Params {}
message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
string vault_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// GenesisState defines the meshsecurityprovider module's genesis state.
message GenesisState {
Expand Down
16 changes: 5 additions & 11 deletions proto/osmosis/meshsecurityprovider/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,19 @@ import "gogoproto/gogo.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "osmosis/meshsecurityprovider/genesis.proto";
import "cosmos_proto/cosmos.proto";
import "amino/amino.proto";

option go_package = "github.com/osmosis-labs/mesh-security-sdk/x/meshsecurityprovider/types";

service Msg {
option (cosmos.msg.v1.service) = true;

rpc Test(MsgTest) returns (MsgTestResponse);
// UpdateParams defines an operation for updating the x/staking module
// UpdateParams defines an operation for updating the module's
// parameters.
// Since: cosmos-sdk 0.47
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// ===================== MsgTest
message MsgTest {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
}

message MsgTestResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type.
//
// Since: cosmos-sdk 0.47
Expand All @@ -44,4 +37,5 @@ message MsgUpdateParams {
// MsgUpdateParams message.
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsResponse {};
message MsgUpdateParamsResponse {};

4 changes: 3 additions & 1 deletion tests/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type example struct {
ConsumerChain *ibctesting.TestChain
ProviderChain *ibctesting.TestChain
ConsumerApp *app.MeshApp
ProviderApp *app.MeshApp
IbcPath *ibctesting.Path
ProviderDenom string
ConsumerDenom string
Expand All @@ -114,6 +115,7 @@ func setupExampleChains(t *testing.T) example {
ConsumerChain: consChain,
ProviderChain: provChain,
ConsumerApp: consChain.App.(*app.MeshApp),
ProviderApp: provChain.App.(*app.MeshApp),
IbcPath: ibctesting.NewPath(consChain, provChain),
ProviderDenom: sdk.DefaultBondDenom,
ConsumerDenom: sdk.DefaultBondDenom,
Expand All @@ -132,7 +134,7 @@ func setupMeshSecurity(t *testing.T, x example) (*TestConsumerClient, ConsumerCo
x.ConsumerChain.DefaultMsgFees = sdk.NewCoins(sdk.NewCoin(x.ConsumerDenom, math.NewInt(1_000_000)))

providerCli := NewProviderClient(t, x.ProviderChain)
providerContracts := providerCli.BootstrapContracts(x.IbcPath.EndpointA.ConnectionID, converterPortID)
providerContracts := providerCli.BootstrapContracts(x.ProviderApp, x.IbcPath.EndpointA.ConnectionID, converterPortID)

// setup ibc control path: consumer -> provider (direction matters)
x.IbcPath.EndpointB.ChannelConfig = &ibctesting2.ChannelConfig{
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
cosmossdk.io/math v1.1.2
github.com/cometbft/cometbft v0.37.2
github.com/osmosis-labs/mesh-security-sdk/demo v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-20231230023625-3cdce6e349eb
github.com/tidwall/gjson v1.17.0
)

Expand Down Expand Up @@ -142,6 +142,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/osmosis-labs/mesh-security-sdk/wasmbinding v0.0.0-00010101000000-000000000000 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -197,6 +198,7 @@ replace (

// local work dirs
github.com/osmosis-labs/mesh-security-sdk/demo => ../../demo
github.com/osmosis-labs/mesh-security-sdk/wasmbinding => ../../wasmbinding
github.com/osmosis-labs/mesh-security-sdk/x => ../../x

// pin version! 126854af5e6d has issues with the store so that queries fail
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/mvp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestMVP(t *testing.T) {
// provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 100_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"100000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// then query contract state
assert.Equal(t, 100_000_000, providerCli.QueryVaultFreeBalance())
Expand Down
12 changes: 6 additions & 6 deletions tests/e2e/slashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func TestSlashingScenario1(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down Expand Up @@ -121,8 +121,8 @@ func TestSlashingScenario2(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down Expand Up @@ -208,8 +208,8 @@ func TestSlashingScenario3(t *testing.T) {
// Provider chain
// ==============
// Deposit - A user deposits the vault denom to provide some collateral to their account
execMsg := `{"bond":{}}`
providerCli.MustExecVault(execMsg, sdk.NewInt64Coin(x.ProviderDenom, 200_000_000))
execMsg := fmt.Sprintf(`{"bond":{"amount":{"denom":"%s", "amount":"200000000"}}}`, x.ProviderDenom)
providerCli.MustExecVault(execMsg)

// Stake Locally - A user triggers a local staking action to a chosen validator.
myLocalValidatorAddr := sdk.ValAddress(x.ProviderChain.Vals.Validators[0].Address).String()
Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type ProviderContracts struct {
externalStaking sdk.AccAddress
}

func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderContracts {
func (p *TestProviderClient) BootstrapContracts(provApp *app.MeshApp, connId, portID string) ProviderContracts {
var (
unbondingPeriod = 21 * 24 * 60 * 60 // 21 days - make configurable?
localSlashRatioDoubleSign = "0.20"
Expand All @@ -88,6 +88,7 @@ func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderC
rewardTokenDenom = sdk.DefaultBondDenom
localTokenDenom = sdk.DefaultBondDenom
)

vaultCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_vault.wasm")).CodeID
proxyCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_native_staking_proxy.wasm")).CodeID
nativeStakingCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_native_staking.wasm")).CodeID
Expand All @@ -96,6 +97,10 @@ func (p *TestProviderClient) BootstrapContracts(connId, portID string) ProviderC
initMsg := []byte(fmt.Sprintf(`{"denom": %q, "local_staking": {"code_id": %d, "msg": %q}}`, localTokenDenom, nativeStakingCodeID, base64.StdEncoding.EncodeToString(nativeInitMsg)))
vaultContract := InstantiateContract(p.t, p.chain, vaultCodeID, initMsg)

ctx := p.chain.GetContext()
params := provApp.MeshSecProvKeeper.GetParams(ctx)
params.VaultAddress = vaultContract.String()
provApp.MeshSecProvKeeper.SetParams(ctx, params)
// external staking
extStakingCodeID := p.chain.StoreCodeFile(buildPathToWasm("mesh_external_staking.wasm")).CodeID
initMsg = []byte(fmt.Sprintf(
Expand Down
4 changes: 3 additions & 1 deletion tests/starship/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require (
github.com/cosmology-tech/starship/registry v0.0.0-20231216113645-d0facbadb180
github.com/cosmos/go-bip39 v1.0.0
github.com/osmosis-labs/mesh-security-sdk/demo v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-00010101000000-000000000000
github.com/osmosis-labs/mesh-security-sdk/x v0.0.0-20231230023625-3cdce6e349eb
github.com/strangelove-ventures/lens v0.0.0-00010101000000-000000000000
go.uber.org/zap v1.26.0
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -147,6 +147,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/osmosis-labs/mesh-security-sdk/wasmbinding v0.0.0-00010101000000-000000000000 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/petermattis/goid v0.0.0-20230317030725-371a4b8eda08 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down Expand Up @@ -201,6 +202,7 @@ replace (

// local work dirs
github.com/osmosis-labs/mesh-security-sdk/demo => ../../demo
github.com/osmosis-labs/mesh-security-sdk/wasmbinding => ../../wasmbinding
github.com/osmosis-labs/mesh-security-sdk/x => ../../x

github.com/strangelove-ventures/lens => github.com/Anmol1696/lens v0.1.1-0.20230705212610-c00628a886a0
Expand Down
Loading