Skip to content

Commit

Permalink
Merge branch 'feat/mint-devfund' of github.com:tendermint/spn into fe…
Browse files Browse the repository at this point in the history
…at/mint-devfund
  • Loading branch information
giunatale committed Jun 16, 2022
2 parents c33780f + 959698b commit 06fddec
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 22 deletions.
31 changes: 21 additions & 10 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,17 +394,11 @@ func New(
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AuthKeeper)
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks()),
)

// ... other modules keepers

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), stakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

// register the proposal types
Expand All @@ -426,7 +420,7 @@ func New(

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
appCodec, keys[evidencetypes.StoreKey], &stakingKeeper, app.SlashingKeeper,
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down Expand Up @@ -511,7 +505,7 @@ func New(
keys[monitoringpmoduletypes.StoreKey],
keys[monitoringpmoduletypes.MemStoreKey],
app.GetSubspace(monitoringpmoduletypes.ModuleName),
app.StakingKeeper,
stakingKeeper,
app.IBCKeeper.ClientKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ChannelKeeper,
Expand All @@ -526,7 +520,7 @@ func New(
keys[participationmoduletypes.MemStoreKey],
app.GetSubspace(participationmoduletypes.ModuleName),
app.FundraisingKeeper,
app.StakingKeeper,
stakingKeeper,
)

app.ClaimKeeper = *claimmodulekeeper.NewKeeper(
Expand All @@ -540,6 +534,23 @@ func New(

// this line is used by starport scaffolding # stargate/app/keeperDefinition

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
app.StakingKeeper = *stakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
app.DistrKeeper.Hooks(),
app.SlashingKeeper.Hooks(),
app.ClaimKeeper.NewMissionDelegationHooks(1),
),
)

// register the gov hooks
app.GovKeeper = *app.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
app.ClaimKeeper.NewMissionVoteHooks(2),
),
)

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := ibcporttypes.NewRouter()
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
Expand Down
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ genesis:
gov:
deposit_params:
min_deposit:
- "amount": "10000000"
- "amount": "1"
"denom": "uspn"
mint:
params:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/tendermint/spn
go 1.18

require (
github.com/cosmos/cosmos-sdk v0.45.4
github.com/cosmos/ibc-go/v3 v3.0.0
github.com/cosmos/cosmos-sdk v0.45.5
github.com/cosmos/ibc-go/v3 v3.0.1
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-sdk v0.44.2/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4=
github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0=
github.com/cosmos/cosmos-sdk v0.45.4 h1:eStDAhJdMY8n5arbBRe+OwpNeBSunxSBHp1g55ulfdA=
github.com/cosmos/cosmos-sdk v0.45.4/go.mod h1:WOqtDxN3eCCmnYLVla10xG7lEXkFjpTaqm2a2WasgCc=
github.com/cosmos/cosmos-sdk v0.45.5 h1:GVrZM+lss6y626Pq6loxh/3KLRgK/J6/alTkcKkYmGU=
github.com/cosmos/cosmos-sdk v0.45.5/go.mod h1:WOqtDxN3eCCmnYLVla10xG7lEXkFjpTaqm2a2WasgCc=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand All @@ -432,8 +432,8 @@ github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwRO
github.com/cosmos/iavl v0.17.3 h1:s2N819a2olOmiauVa0WAhoIJq9EhSXE9HDBAoR9k+8Y=
github.com/cosmos/iavl v0.17.3/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w=
github.com/cosmos/ibc-go v1.2.2/go.mod h1:XmYjsRFOs6Q9Cz+CSsX21icNoH27vQKb3squgnCOCbs=
github.com/cosmos/ibc-go/v3 v3.0.0 h1:XUNplHVS51Q2gMnTFsFsH9QJ7flsovMamnltKbEgPQ4=
github.com/cosmos/ibc-go/v3 v3.0.0/go.mod h1:Mb+1NXiPOLd+CPFlOC6BKeAUaxXlhuWenMmRiUiSmwY=
github.com/cosmos/ibc-go/v3 v3.0.1 h1:JMQhAHYt/chIm240kIXeFIJfQr8m6FR3sE/eDqbpxWA=
github.com/cosmos/ibc-go/v3 v3.0.1/go.mod h1:DbOlOa4yKumaHGKApKkJN90L88PCjSD9ZBdAfL9tT40=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
github.com/cosmos/ledger-cosmos-go v0.11.1/go.mod h1:J8//BsAGTo3OC/vDLjMRFLW6q0WAaXvHnVc7ZmE8iUY=
github.com/cosmos/ledger-go v0.9.2 h1:Nnao/dLwaVTk1Q5U9THldpUMMXU94BOTWPddSmVB6pI=
Expand Down
9 changes: 9 additions & 0 deletions proto/claim/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";
package tendermint.spn.claim;

option go_package = "github.com/tendermint/spn/x/claim/types";

message EventMissionCompleted {
uint64 missionID = 1;
string claimer = 2;
}
23 changes: 22 additions & 1 deletion testutil/keeper/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
Expand Down Expand Up @@ -129,6 +131,24 @@ func (i initializer) Capability() *capabilitykeeper.Keeper {
return capabilitykeeper.NewKeeper(i.Codec, storeKey, memStoreKey)
}

// create mock ProtocolVersionSetter for UpgradeKeeper

type ProtocolVersionSetter struct{}

func (vs ProtocolVersionSetter) SetProtocolVersion(uint64) {
return
}

func (i initializer) Upgrade() upgradekeeper.Keeper {
storeKey := sdk.NewKVStoreKey(upgradetypes.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, sdk.StoreTypeIAVL, i.DB)

skipUpgradeHeights := make(map[int64]bool)
vs := ProtocolVersionSetter{}

return upgradekeeper.NewKeeper(skipUpgradeHeights, storeKey, i.Codec, "", vs)
}

func (i initializer) Staking(
authKeeper authkeeper.AccountKeeper,
bankKeeper bankkeeper.Keeper,
Expand All @@ -147,6 +167,7 @@ func (i initializer) IBC(
paramKeeper paramskeeper.Keeper,
stakingKeeper stakingkeeper.Keeper,
capabilityKeeper capabilitykeeper.Keeper,
upgradeKeeper upgradekeeper.Keeper,
) *ibckeeper.Keeper {
storeKey := sdk.NewKVStoreKey(ibchost.StoreKey)

Expand All @@ -157,7 +178,7 @@ func (i initializer) IBC(
storeKey,
paramKeeper.Subspace(ibchost.ModuleName),
stakingKeeper,
nil,
upgradeKeeper,
capabilityKeeper.ScopeToModule(ibchost.ModuleName),
)
}
Expand Down
6 changes: 4 additions & 2 deletions testutil/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func NewTestSetup(t testing.TB) (sdk.Context, TestKeepers, TestMsgServers) {
bankKeeper := initializer.Bank(paramKeeper, authKeeper)
stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper)
distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper, paramKeeper)
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper)
upgradeKeeper := initializer.Upgrade()
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper, upgradeKeeper)
fundraisingKeeper := initializer.Fundraising(paramKeeper, authKeeper, bankKeeper, distrKeeper)
profileKeeper := initializer.Profile()
launchKeeper := initializer.Launch(profileKeeper, distrKeeper, paramKeeper)
Expand Down Expand Up @@ -178,7 +179,8 @@ func NewTestSetupWithIBCMocks(
bankKeeper := initializer.Bank(paramKeeper, authKeeper)
stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper)
distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper, paramKeeper)
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper)
upgradeKeeper := initializer.Upgrade()
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper, upgradeKeeper)
fundraisingKeeper := initializer.Fundraising(paramKeeper, authKeeper, bankKeeper, distrKeeper)
profileKeeper := initializer.Profile()
launchKeeper := initializer.Launch(profileKeeper, distrKeeper, paramKeeper)
Expand Down
3 changes: 2 additions & 1 deletion testutil/keeper/monitoring_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func NewTestSetupWithIBCMocksMonitoringp(
bankKeeper := initializer.Bank(paramKeeper, authKeeper)
stakingKeeper := initializer.Staking(authKeeper, bankKeeper, paramKeeper)
distrKeeper := initializer.Distribution(authKeeper, bankKeeper, stakingKeeper, paramKeeper)
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper)
upgradeKeeper := initializer.Upgrade()
ibcKeeper := initializer.IBC(paramKeeper, stakingKeeper, *capabilityKeeper, upgradeKeeper)
monitoringProviderKeeper := initializer.Monitoringp(
stakingKeeper,
*ibcKeeper,
Expand Down
7 changes: 6 additions & 1 deletion x/claim/keeper/mission.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,10 @@ func (k Keeper) CompleteMission(ctx sdk.Context, missionID uint64, address strin
k.SetAirdropSupply(ctx, airdropSupply)
k.SetClaimRecord(ctx, claimRecord)

return nil
err = ctx.EventManager().EmitTypedEvent(&types.EventMissionCompleted{
MissionID: missionID,
Claimer: address,
})

return err
}
60 changes: 60 additions & 0 deletions x/claim/keeper/mission_delegation_hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

type MissionDelegationHooks struct {
k Keeper
missionID uint64
}

// NewMissionDelegationHooks returns a StakingHooks that triggers mission completion on delegation for an account
func (k Keeper) NewMissionDelegationHooks(missionID uint64) MissionDelegationHooks {
return MissionDelegationHooks{k, missionID}
}

var _ stakingtypes.StakingHooks = MissionDelegationHooks{}

// BeforeDelegationCreated completes mission when a delegation is performed
func (h MissionDelegationHooks) BeforeDelegationCreated(ctx sdk.Context, delAddr sdk.AccAddress, _ sdk.ValAddress) {
// TODO: error handling
_ = h.k.CompleteMission(ctx, h.missionID, delAddr.String())
}

// AfterValidatorCreated implements StakingHooks
func (h MissionDelegationHooks) AfterValidatorCreated(_ sdk.Context, _ sdk.ValAddress) {
}

// AfterValidatorRemoved implements StakingHooks
func (h MissionDelegationHooks) AfterValidatorRemoved(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {
}

// BeforeDelegationSharesModified implements StakingHooks
func (h MissionDelegationHooks) BeforeDelegationSharesModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {
}

// AfterDelegationModified implements StakingHooks
func (h MissionDelegationHooks) AfterDelegationModified(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {
}

// BeforeValidatorSlashed implements StakingHooks
func (h MissionDelegationHooks) BeforeValidatorSlashed(_ sdk.Context, _ sdk.ValAddress, _ sdk.Dec) {
}

// BeforeValidatorModified implements StakingHooks
func (h MissionDelegationHooks) BeforeValidatorModified(_ sdk.Context, _ sdk.ValAddress) {
}

// AfterValidatorBonded implements StakingHooks
func (h MissionDelegationHooks) AfterValidatorBonded(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {
}

// AfterValidatorBeginUnbonding implements StakingHooks
func (h MissionDelegationHooks) AfterValidatorBeginUnbonding(_ sdk.Context, _ sdk.ConsAddress, _ sdk.ValAddress) {
}

// BeforeDelegationRemoved implements StakingHooks
func (h MissionDelegationHooks) BeforeDelegationRemoved(_ sdk.Context, _ sdk.AccAddress, _ sdk.ValAddress) {
}
40 changes: 40 additions & 0 deletions x/claim/keeper/mission_vote_hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

type MissionVoteHooks struct {
k Keeper
missionID uint64
}

// NewMissionVoteHooks returns a GovHooks that triggers mission completion on voting for a proposal
func (k Keeper) NewMissionVoteHooks(missionID uint64) MissionVoteHooks {
return MissionVoteHooks{k, missionID}
}

var _ govtypes.GovHooks = MissionVoteHooks{}

// AfterProposalVote completes mission when a vote is cast
func (h MissionVoteHooks) AfterProposalVote(ctx sdk.Context, _ uint64, voterAddr sdk.AccAddress) {
// TODO: error handling
_ = h.k.CompleteMission(ctx, h.missionID, voterAddr.String())
}

// AfterProposalSubmission implements GovHooks
func (h MissionVoteHooks) AfterProposalSubmission(_ sdk.Context, _ uint64) {
}

// AfterProposalDeposit implements GovHooks
func (h MissionVoteHooks) AfterProposalDeposit(_ sdk.Context, _ uint64, _ sdk.AccAddress) {
}

// AfterProposalFailedMinDeposit implements GovHooks
func (h MissionVoteHooks) AfterProposalFailedMinDeposit(_ sdk.Context, _ uint64) {
}

// AfterProposalVotingPeriodEnded implements GovHooks
func (h MissionVoteHooks) AfterProposalVotingPeriodEnded(_ sdk.Context, _ uint64) {
}
Loading

0 comments on commit 06fddec

Please sign in to comment.