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/rewards abci #3430

Merged
merged 15 commits into from
Dec 2, 2023
67 changes: 51 additions & 16 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/Sifchain/sifnode/x/dispensation"
dispkeeper "github.com/Sifchain/sifnode/x/dispensation/keeper"
disptypes "github.com/Sifchain/sifnode/x/dispensation/types"
epochs "github.com/Sifchain/sifnode/x/epochs"
epochskeeper "github.com/Sifchain/sifnode/x/epochs/keeper"
epochstypes "github.com/Sifchain/sifnode/x/epochs/types"
"github.com/Sifchain/sifnode/x/ethbridge"
ethbridgekeeper "github.com/Sifchain/sifnode/x/ethbridge/keeper"
ethbridgetypes "github.com/Sifchain/sifnode/x/ethbridge/types"
Expand Down Expand Up @@ -162,6 +165,7 @@ var (
tokenregistry.AppModuleBasic{},
admin.AppModuleBasic{},
vesting.AppModuleBasic{},
epochs.AppModuleBasic{},
)

maccPerms = map[string][]string{
Expand Down Expand Up @@ -237,6 +241,7 @@ type SifchainApp struct {
DispensationKeeper dispkeeper.Keeper
TokenRegistryKeeper tokenregistrytypes.Keeper
AdminKeeper adminkeeper.Keeper
EpochsKeeper epochskeeper.Keeper

mm *module.Manager
sm *module.SimulationManager
Expand Down Expand Up @@ -286,6 +291,7 @@ func NewSifAppWithBlacklist(
tokenregistrytypes.StoreKey,
admintypes.StoreKey,
authzkeeper.StoreKey,
epochstypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -344,22 +350,22 @@ func NewSifAppWithBlacklist(
appCodec, keys[feegrant.StoreKey], app.AccountKeeper,
)

stakingKeeper := stakingkeeper.NewKeeper(
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)

app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &app.StakingKeeper,
app.AccountKeeper, app.BankKeeper, authtypes.FeeCollectorName,
)

app.DistrKeeper = distrkeeper.NewKeeper(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
&app.StakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(),
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
appCodec, keys[slashingtypes.StoreKey], &app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)
/*
Invariants are certain conditions which are checked , which should hold true to certify the network is not byzantine .
Expand Down Expand Up @@ -404,12 +410,6 @@ func NewSifAppWithBlacklist(
app.GetSubspace(margintypes.ModuleName),
)

// 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.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)
Expand All @@ -420,7 +420,7 @@ func NewSifAppWithBlacklist(
AddRoute(distrtypes.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.DistrKeeper)).
AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(app.UpgradeKeeper)).
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper))
govKeeper := govkeeper.NewKeeper(
app.GovKeeper = govkeeper.NewKeeper(
appCodec,
keys[govtypes.StoreKey],
app.GetSubspace(govtypes.ModuleName),
Expand All @@ -429,11 +429,6 @@ func NewSifAppWithBlacklist(
app.StakingKeeper,
govRouter,
)
app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register governance hooks
),
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
Expand Down Expand Up @@ -471,6 +466,12 @@ func NewSifAppWithBlacklist(
app.AccountKeeper,
app.GetSubspace(disptypes.ModuleName),
)

app.EpochsKeeper = *epochskeeper.NewKeeper(
appCodec,
keys[epochstypes.StoreKey],
)

mockModule := ibcmock.NewAppModule(&app.IBCKeeper.PortKeeper)
mockIBCModule := ibcmock.NewIBCModule(&mockModule, ibcmock.NewMockIBCApp(ibcmock.ModuleName, scopedIBCMockKeeper))

Expand All @@ -493,6 +494,33 @@ func NewSifAppWithBlacklist(
cfg := module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.configurator = cfg

/**** Module Hooks ****/

// register hooks after all modules have been initialized

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

app.GovKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register governance hooks
),
)

app.EpochsKeeper = *app.EpochsKeeper.SetHooks(
epochskeeper.NewMultiEpochHooks(
// insert epoch hooks receivers here
app.ClpKeeper.Hooks(),
),
)
epochsModule := epochs.NewAppModule(appCodec, app.EpochsKeeper)

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.mm = module.NewManager(
Expand Down Expand Up @@ -526,15 +554,19 @@ func NewSifAppWithBlacklist(
dispensation.NewAppModule(app.DispensationKeeper, app.BankKeeper, app.AccountKeeper),
tokenregistry.NewAppModule(app.TokenRegistryKeeper, &appCodec),
admin.NewAppModule(app.AdminKeeper, &appCodec),
epochsModule,
)
// During begin block slashing happens after distr.BeginBlocker so that
// there is nothing left over in the validator fee pool, so as to keep the
// CanWithdrawInvariant invariant.
// NOTE: staking module is required if HistoricalEntries param > 0
// NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC)
app.mm.SetOrderBeginBlockers(
// upgrades should be run first
upgradetypes.ModuleName,
capabilitytypes.ModuleName,
// Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning
epochstypes.ModuleName,
minttypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
Expand Down Expand Up @@ -564,6 +596,8 @@ func NewSifAppWithBlacklist(
crisistypes.ModuleName,
govtypes.ModuleName,
stakingtypes.ModuleName,
// Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end
epochstypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
Expand Down Expand Up @@ -620,6 +654,7 @@ func NewSifAppWithBlacklist(
oracletypes.ModuleName,
ethbridge.ModuleName,
dispensation.ModuleName,
epochstypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down
7 changes: 5 additions & 2 deletions app/setup_handlers.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package app

import (
epochstypes "github.com/Sifchain/sifnode/x/epochs/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
m "github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

const releaseVersion = "1.2.0-beta"
const releaseVersion = "1.3.0-beta"

func SetupHandlers(app *SifchainApp) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, _ types.Plan, vm m.VersionMap) (m.VersionMap, error) {
Expand All @@ -22,7 +23,9 @@ func SetupHandlers(app *SifchainApp) {
}
if upgradeInfo.Name == releaseVersion && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
// Added: []string{},
Added: []string{
epochstypes.StoreKey,
},
}
// Use upgrade store loader for the initial loading of all stores when app starts,
// it checks if version == upgradeHeight and applies store upgrades before loading the stores,
Expand Down
41 changes: 40 additions & 1 deletion integrationtest/output/results.json
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
{"accounts":{"sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd":[{"denom":"cusdc","amount":"999998975129996"},{"denom":"rowan","amount":"999999002243793715591658472"}]},"Pools":{"cusdc":{"external_asset":{"symbol":"cusdc"},"native_asset_balance":"997756206284408341528","external_asset_balance":"1024870004","pool_units":"1000000000000000000000","swap_price_native":"3.851417996402505993","swap_price_external":"0.259644629830901241","reward_period_native_distributed":"0","external_liabilities":"0","external_custody":"0","native_liabilities":"0","native_custody":"0","health":"0.995049498561352358","interest_rate":"0.400000000000000000","last_height_interest_rate_computed":5,"unsettled_external_liabilities":"0","unsettled_native_liabilities":"0","block_interest_native":"0","block_interest_external":"13699020"}},"LPs":{"\u0001cusdc_sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd":{"asset":{"symbol":"cusdc"},"liquidity_provider_units":"1000000000000000000000","liquidity_provider_address":"sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd"}}}
{
"accounts": {
"sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": [
{ "denom": "cusdc", "amount": "999998975129996" },
{ "denom": "rowan", "amount": "999999002243793715591658472" }
]
},
"Pools": {
"cusdc": {
"external_asset": { "symbol": "cusdc" },
"native_asset_balance": "997756206284408341528",
"external_asset_balance": "1024870004",
"pool_units": "1000000000000000000000",
"swap_price_native": "3.851417996402505993",
"swap_price_external": "0.259644629830901241",
"reward_period_native_distributed": "0",
"external_liabilities": "0",
"external_custody": "0",
"native_liabilities": "0",
"native_custody": "0",
"health": "0.995049498561352358",
"interest_rate": "0.400000000000000000",
"last_height_interest_rate_computed": 5,
"unsettled_external_liabilities": "0",
"unsettled_native_liabilities": "0",
"block_interest_native": "0",
"block_interest_external": "13699020",
"reward_amount_external": "0"
}
},
"LPs": {
"\u0001cusdc_sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": {
"asset": { "symbol": "cusdc" },
"liquidity_provider_units": "1000000000000000000000",
"liquidity_provider_address": "sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd",
"last_updated_block": 0,
"reward_amount": null
}
}
}
95 changes: 49 additions & 46 deletions integrationtest/output/tc1.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
{
"accounts": {
"sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": [
{
"denom": "cusdc",
"amount": "999998994370679"
},
{
"denom": "rowan",
"amount": "999999000005078262924594065"
}
]
},
"Pools": {
"cusdc": {
"external_asset": {
"symbol": "cusdc"
},
"native_asset_balance": "999994921737075405935",
"external_asset_balance": "1005629321",
"pool_units": "1000000000000000000000",
"swap_price_native": "0.987727340533795089",
"swap_price_external": "1.012425149089800862",
"reward_period_native_distributed": "0",
"external_liabilities": "0",
"external_custody": "0",
"native_liabilities": "0",
"native_custody": "0",
"health": "0.990098960118728966",
"interest_rate": "0.500000000000000000",
"last_height_interest_rate_computed": 5,
"unsettled_external_liabilities": "0",
"unsettled_native_liabilities": "2023304519940209643",
"block_interest_native": "0",
"block_interest_external": "4390203"
}
},
"LPs": {
"\u0001cusdc_sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": {
"asset": {
"symbol": "cusdc"
},
"liquidity_provider_units": "1000000000000000000000",
"liquidity_provider_address": "sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd"
}
}
}
"accounts": {
"sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": [
{
"denom": "cusdc",
"amount": "999998994370679"
},
{
"denom": "rowan",
"amount": "999999000005078262924594065"
}
]
},
"Pools": {
"cusdc": {
"external_asset": {
"symbol": "cusdc"
},
"native_asset_balance": "999994921737075405935",
"external_asset_balance": "1005629321",
"pool_units": "1000000000000000000000",
"swap_price_native": "0.987727340533795089",
"swap_price_external": "1.012425149089800862",
"reward_period_native_distributed": "0",
"external_liabilities": "0",
"external_custody": "0",
"native_liabilities": "0",
"native_custody": "0",
"health": "0.990098960118728966",
"interest_rate": "0.500000000000000000",
"last_height_interest_rate_computed": 5,
"unsettled_external_liabilities": "0",
"unsettled_native_liabilities": "2023304519940209643",
"block_interest_native": "0",
"block_interest_external": "4390203",
"reward_amount_external": "0"
}
},
"LPs": {
"\u0001cusdc_sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd": {
"asset": {
"symbol": "cusdc"
},
"liquidity_provider_units": "1000000000000000000000",
"liquidity_provider_address": "sif1syavy2npfyt9tcncdtsdzf7kny9lh777yqc2nd",
"last_updated_block": 1,
"reward_amount": null
}
}
}
Loading
Loading