Skip to content

Commit

Permalink
RC v1.6.4 (#68)
Browse files Browse the repository at this point in the history
* [LUM-837] Fee manager revamp (#66)

* WIP move fees to pool level

* WIP

* Fee manager structure fix

* Cleaning

* Fixed pointers issues

* Reset the collected amount after distribution

* Update fee distribution

* Fixed tests and added validation methods

* Code format

* Validate pool should also validate the fee takers

* Use correct constant for default fee amount

* Update keeper_fees.go

* Patch the logic to the old way. Fix prize to ensure it's checked over multiple fee takers

* Introduce store migration for default fee takers init

* Code format

* Missing migrator

* Fix prize collection to make transfer uniques per fee taker

* Validate total amount of fee included in pool operations

* Introduce test for fee takers validation

* Centralize the fee taker validation

---------

Co-authored-by: Fabrice Bascoulergue <lebascou@users.noreply.github.com>

* [LUM-863] Entities fix (#67)

* Make sure to back save entities

* Added migration to fix entities

* code format

* Format

* missing upgrade handler

* Handle stucked ibc transfer restoration

---------

Co-authored-by: Fabrice Bascoulergue <lebascou@users.noreply.github.com>
  • Loading branch information
Segfaultd and lebascou authored Jan 25, 2024
1 parent 4f4349b commit 808aad2
Show file tree
Hide file tree
Showing 41 changed files with 1,223 additions and 436 deletions.
14 changes: 12 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ func (app *App) registerUpgradeHandlers() {
{PoolPercent: 8, Quantity: 60, IsUnique: false, DrawProbability: sdk.NewDecWithPrec(90, 2)},
},
}
err = app.MillionsKeeper.UpdatePool(ctx, pool.GetPoolId(), []string{}, nil, nil, nil, nil, &prizeStrategy, millionstypes.PoolState_Unspecified)
err = app.MillionsKeeper.UpdatePool(ctx, pool.GetPoolId(), []string{}, nil, nil, nil, nil, &prizeStrategy, millionstypes.PoolState_Unspecified, nil)
if err != nil {
return nil, err
}
Expand All @@ -874,7 +874,7 @@ func (app *App) registerUpgradeHandlers() {
{PoolPercent: 8, Quantity: 60, IsUnique: true, DrawProbability: sdk.NewDecWithPrec(90, 2)},
},
}
err = app.MillionsKeeper.UpdatePool(ctx, pool.GetPoolId(), []string{}, nil, nil, nil, nil, &prizeStrategy, millionstypes.PoolState_Unspecified)
err = app.MillionsKeeper.UpdatePool(ctx, pool.GetPoolId(), []string{}, nil, nil, nil, nil, &prizeStrategy, millionstypes.PoolState_Unspecified, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -914,6 +914,11 @@ func (app *App) registerUpgradeHandlers() {
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

app.UpgradeKeeper.SetUpgradeHandler("v1.6.4", func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("Starting v1.6.4 upgrade")
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

upgradeInfo, err := app.UpgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
Expand Down Expand Up @@ -1010,4 +1015,9 @@ func (app *App) registerUpgradeHandlers() {
storeUpgrades := storetypes.StoreUpgrades{}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}

if upgradeInfo.Name == "v1.6.4" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
1 change: 0 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ genesis:
min_draw_schedule_delta: "1h"
max_draw_schedule_delta: "8784h" # 366days
prize_expiration_delta: "720h" # 30days
fees_stakers: "0.10"
min_deposit_draw_delta: "60s"
faucet:
name: user1
Expand Down
8 changes: 4 additions & 4 deletions proto/lum/network/millions/gov.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ message ProposalRegisterPool {
(gogoproto.nullable) = false
];
PoolType pool_type = 16;
repeated FeeTaker fee_takers = 17 [ (gogoproto.nullable) = false ];
}

message ProposalUpdatePool {
Expand All @@ -60,6 +61,7 @@ message ProposalUpdatePool {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = true
];
repeated FeeTaker fee_takers = 11 [ (gogoproto.nullable) = false ];
}

message ProposalUpdateParams {
Expand All @@ -86,10 +88,8 @@ message ProposalUpdateParams {
[ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ];
google.protobuf.Duration prize_expiration_delta = 8
[ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ];
string fees_stakers = 9 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];
// DO NOT USE - EX FEES STAKERS
reserved 9;
google.protobuf.Duration min_deposit_draw_delta = 10
[ (gogoproto.stdduration) = true, (gogoproto.nullable) = true ];
}
8 changes: 2 additions & 6 deletions proto/lum/network/millions/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ message Params {
// pools)
google.protobuf.Duration prize_expiration_delta = 6
[ (gogoproto.stdduration) = true, (gogoproto.nullable) = false ];
// fees_stakers the fees distributed by stakers over prize won (common to all
// pools)
string fees_stakers = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// DEPRECATED - DO NOT USE IN THE FUTURE - EX FEES STAKERS
reserved 7;
// min_deposit_draw_delta the minimum delta before a draw for a deposit to be
// accepted during the time weighted balance computation for a draw
google.protobuf.Duration min_deposit_draw_delta = 8
Expand Down
24 changes: 23 additions & 1 deletion proto/lum/network/millions/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ enum PoolType {
POOL_TYPE_STAKING = 1 [ (gogoproto.enumvalue_customname) = "Staking" ];
}

enum FeeTakerType {
option (gogoproto.goproto_enum_prefix) = true;

FEE_TAKER_TYPE_UNSPECIFIED = 0
[ (gogoproto.enumvalue_customname) = "Unspecified" ];
FEE_TAKER_TYPE_LOCAL_ADDR = 1
[ (gogoproto.enumvalue_customname) = "LocalAddr" ];
FEE_TAKER_TYPE_LOCAL_MODULE_ACCOUNT = 2
[ (gogoproto.enumvalue_customname) = "LocalModuleAccount" ];
FEE_TAKER_TYPE_REMOTE_ADDR = 3
[ (gogoproto.enumvalue_customname) = "RemoteAddr" ];
}

message FeeTaker {
string destination = 1;
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
FeeTakerType type = 3;
}

message Pool {
uint64 pool_id = 1;
string denom = 2;
Expand Down Expand Up @@ -96,7 +118,7 @@ message Pool {
DrawState last_draw_state = 28;
cosmos.base.v1beta1.Coin available_prize_pool = 29
[ (gogoproto.nullable) = false ];
reserved 30;
repeated FeeTaker fee_takers = 30 [ (gogoproto.nullable) = false ];
reserved 31;

PoolState state = 32;
Expand Down
20 changes: 17 additions & 3 deletions x/millions/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"testing"
"time"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/stretchr/testify/require"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
Expand Down Expand Up @@ -43,7 +45,6 @@ var testGenesis = millionstypes.GenesisState{
MinDrawScheduleDelta: 1 * time.Hour,
MaxDrawScheduleDelta: 366 * 24 * time.Hour, // 366 days
PrizeExpirationDelta: 30 * 24 * time.Hour, // 30 days
FeesStakers: sdk.NewDec(0),
MinDepositDrawDelta: 5 * time.Minute,
},
NextPoolId: 6,
Expand All @@ -55,26 +56,41 @@ var testGenesis = millionstypes.GenesisState{
ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), UnbondingDuration: time.Duration(millionstypes.DefaultUnbondingDuration), MaxUnbondingEntries: sdk.NewInt(millionstypes.DefaultMaxUnbondingEntries), AvailablePrizePool: sdk.NewCoin("denom-1", sdk.ZeroInt()),
DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat,
State: millionstypes.PoolState_Created, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper",
FeeTakers: []millionstypes.FeeTaker{
{Destination: authtypes.FeeCollectorName, Amount: sdk.NewDecWithPrec(millionstypes.DefaultFeeTakerAmount, 2), Type: millionstypes.FeeTakerType_LocalModuleAccount},
},
},
{PoolId: 2, PoolType: millionstypes.PoolType_Staking, TvlAmount: sdk.NewInt(603), DepositorsCount: 2, SponsorshipAmount: sdk.NewInt(401), Denom: "denom-2", NativeDenom: "denom-2", NextDrawId: 2,
ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), UnbondingDuration: time.Duration(millionstypes.DefaultUnbondingDuration), MaxUnbondingEntries: sdk.NewInt(millionstypes.DefaultMaxUnbondingEntries), AvailablePrizePool: sdk.NewCoin("denom-2", sdk.ZeroInt()),
DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat,
State: millionstypes.PoolState_Ready, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper",
FeeTakers: []millionstypes.FeeTaker{
{Destination: authtypes.FeeCollectorName, Amount: sdk.NewDecWithPrec(millionstypes.DefaultFeeTakerAmount, 2), Type: millionstypes.FeeTakerType_LocalModuleAccount},
},
},
{PoolId: 3, PoolType: millionstypes.PoolType_Staking, TvlAmount: sdk.NewInt(601), DepositorsCount: 1, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-3", NativeDenom: "denom-3", NextDrawId: 1,
ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), UnbondingDuration: time.Duration(millionstypes.DefaultUnbondingDuration), MaxUnbondingEntries: sdk.NewInt(millionstypes.DefaultMaxUnbondingEntries), AvailablePrizePool: sdk.NewCoin("denom-3", sdk.ZeroInt()),
DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat,
State: millionstypes.PoolState_Killed, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper",
FeeTakers: []millionstypes.FeeTaker{
{Destination: authtypes.FeeCollectorName, Amount: sdk.NewDecWithPrec(millionstypes.DefaultFeeTakerAmount, 2), Type: millionstypes.FeeTakerType_LocalModuleAccount},
},
},
{PoolId: 4, PoolType: millionstypes.PoolType_Staking, TvlAmount: sdk.NewInt(400), DepositorsCount: 1, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-4", NativeDenom: "denom-4", NextDrawId: 1,
ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), UnbondingDuration: time.Duration(millionstypes.DefaultUnbondingDuration), MaxUnbondingEntries: sdk.NewInt(millionstypes.DefaultMaxUnbondingEntries), AvailablePrizePool: sdk.NewCoin("denom-4", sdk.ZeroInt()),
DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat,
State: millionstypes.PoolState_Created, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper",
FeeTakers: []millionstypes.FeeTaker{
{Destination: authtypes.FeeCollectorName, Amount: sdk.NewDecWithPrec(millionstypes.DefaultFeeTakerAmount, 2), Type: millionstypes.FeeTakerType_LocalModuleAccount},
},
},
{PoolId: 5, PoolType: millionstypes.PoolType_Staking, TvlAmount: sdk.NewInt(0), DepositorsCount: 0, SponsorshipAmount: sdk.ZeroInt(), Denom: "denom-5", NativeDenom: "denom-5", NextDrawId: 1,
ChainId: "c1", Validators: defaultValidators, MinDepositAmount: sdk.NewInt(1_000_000), UnbondingDuration: time.Duration(millionstypes.DefaultUnbondingDuration), MaxUnbondingEntries: sdk.NewInt(millionstypes.DefaultMaxUnbondingEntries), AvailablePrizePool: sdk.NewCoin("denom-5", sdk.ZeroInt()),
DrawSchedule: defaultSchedule, PrizeStrategy: defaultPrizeStrat,
State: millionstypes.PoolState_Killed, Bech32PrefixAccAddr: "lum", Bech32PrefixValAddr: "lumvaloper",
FeeTakers: []millionstypes.FeeTaker{
{Destination: authtypes.FeeCollectorName, Amount: sdk.NewDecWithPrec(millionstypes.DefaultFeeTakerAmount, 2), Type: millionstypes.FeeTakerType_LocalModuleAccount},
},
},
},
Deposits: []millionstypes.Deposit{
Expand Down Expand Up @@ -131,7 +147,6 @@ func TestInitGenesis(t *testing.T) {
require.Equal(t, testGenesis.Params.MinDrawScheduleDelta, params.MinDrawScheduleDelta)
require.Equal(t, testGenesis.Params.MaxDrawScheduleDelta, params.MaxDrawScheduleDelta)
require.Equal(t, testGenesis.Params.PrizeExpirationDelta, params.PrizeExpirationDelta)
require.Equal(t, testGenesis.Params.FeesStakers, params.FeesStakers)
require.Equal(t, testGenesis.Params.MinDepositDrawDelta, params.MinDepositDrawDelta)

// Make sure genesis next poolID matches
Expand Down Expand Up @@ -329,7 +344,6 @@ func TestExportGenesis(t *testing.T) {
require.Equal(t, exportGenesis.Params.MinDrawScheduleDelta, testGenesis.Params.MinDrawScheduleDelta)
require.Equal(t, exportGenesis.Params.MaxDrawScheduleDelta, testGenesis.Params.MaxDrawScheduleDelta)
require.Equal(t, exportGenesis.Params.PrizeExpirationDelta, testGenesis.Params.PrizeExpirationDelta)
require.Equal(t, exportGenesis.Params.FeesStakers, testGenesis.Params.FeesStakers)
require.Equal(t, exportGenesis.Params.MinDepositDrawDelta, testGenesis.Params.MinDepositDrawDelta)

// Test IDs export
Expand Down
6 changes: 2 additions & 4 deletions x/millions/handler_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func NewMillionsProposalHandler(k keeper.Keeper) govtypes.Handler {
switch c := content.(type) {
case *types.ProposalUpdatePool:
{
return k.UpdatePool(ctx, c.PoolId, c.Validators, c.MinDepositAmount, c.UnbondingDuration, c.MaxUnbondingEntries, c.DrawSchedule, c.PrizeStrategy, c.State)
return k.UpdatePool(ctx, c.PoolId, c.Validators, c.MinDepositAmount, c.UnbondingDuration, c.MaxUnbondingEntries, c.DrawSchedule, c.PrizeStrategy, c.State, c.FeeTakers)
}
case *types.ProposalRegisterPool:
{
Expand All @@ -35,6 +35,7 @@ func NewMillionsProposalHandler(k keeper.Keeper) govtypes.Handler {
c.MaxUnbondingEntries,
c.GetDrawSchedule(),
c.GetPrizeStrategy(),
c.FeeTakers,
)
return err
}
Expand All @@ -59,9 +60,6 @@ func NewMillionsProposalHandler(k keeper.Keeper) govtypes.Handler {
if c.PrizeExpirationDelta != nil {
params.PrizeExpirationDelta = *c.PrizeExpirationDelta
}
if c.FeesStakers != nil {
params.FeesStakers = *c.FeesStakers
}
if c.MinDepositDrawDelta != nil {
params.MinDepositDrawDelta = *c.MinDepositDrawDelta
}
Expand Down
Loading

0 comments on commit 808aad2

Please sign in to comment.