Unverified Commit e5dc1caa authored by Dev Ojha's avatar Dev Ojha Committed by GitHub
Browse files

Update the risk factor from 5% to 50% (#958)

* Reduce the amount of work in migration

* Update risk factor

* Update tests

* Update migration test
parent e41d15ba
Showing with 30 additions and 14 deletions
+30 -14
......@@ -48,6 +48,7 @@ func MergeLockupsForSimilarDurations(
// We make at most one lock per (addr, denom, base duration) triplet, which we keep adding coins to.
// We call this the new "normalized lock", and the value in the map is the new lock ID.
normals := make(map[string]uint64)
locksToNormalize := []types.PeriodLock{}
for _, lock := range k.GetAccountPeriodLocks(ctx, addr) {
// ignore multilocks
if len(lock.Coins) > 1 {
......@@ -57,6 +58,22 @@ func MergeLockupsForSimilarDurations(
if lock.IsUnlocking() {
continue
}
normalizedDuration, ok := normalizeDuration(baselineDurations, durationDiff, lock.Duration)
if !ok {
continue
}
coin := lock.Coins[0]
// In this pass, add lock to normals if exact match
key := addr.String() + "/" + coin.Denom + "/" + strconv.FormatInt(int64(normalizedDuration), 10)
_, normalExists := normals[key]
if normalizedDuration == lock.Duration && !normalExists {
normals[key] = lock.ID
continue
}
locksToNormalize = append(locksToNormalize, lock)
}
for _, lock := range locksToNormalize {
coin := lock.Coins[0]
normalizedDuration, ok := normalizeDuration(baselineDurations, durationDiff, lock.Duration)
if !ok {
......
......@@ -38,6 +38,9 @@ func (suite *KeeperTestSuite) TestLockupMergeMigration() {
for i := 0; i < 100; i++ {
addr, denom := addr(rand.Intn(5)), denom(rand.Intn(5))
duration := baseDuration + time.Duration(rand.Int63n(int64(keeper.HourDuration)))
if rand.Intn(3) == 0 {
duration = baseDuration
}
amount := rand.Int63n(100000)
add(addr, denom, baseDuration, amount)
suite.LockTokens(addr, sdk.Coins{sdk.NewInt64Coin(denom, amount)}, duration)
......
......@@ -56,7 +56,7 @@ func (suite *KeeperTestSuite) TestSuperfluidAfterEpochEnd() {
suite.Require().NoError(err)
delegation, found := suite.app.StakingKeeper.GetDelegation(suite.ctx, acc.GetAccAddress(), valAddr)
suite.Require().True(found)
suite.Require().Equal(delegation.Shares, sdk.NewDec(9500))
suite.Require().Equal(sdk.NewDec(5000), delegation.Shares)
// TODO: Check reward distribution
}
})
......
......@@ -4,7 +4,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
lockuptypes "github.com/osmosis-labs/osmosis/v7/x/lockup/types"
"github.com/osmosis-labs/osmosis/v7/x/superfluid/types"
)
func (suite *KeeperTestSuite) TestBeforeValidatorSlashed() {
......@@ -62,7 +61,6 @@ func (suite *KeeperTestSuite) TestBeforeValidatorSlashed() {
// setup validators
valAddrs := suite.SetupValidators(tc.validatorStats)
intermediaryAccs := []types.SuperfluidIntermediaryAccount{}
locks := []lockuptypes.PeriodLock{}
slashFactor := sdk.NewDecWithPrec(5, 2)
......@@ -71,10 +69,8 @@ func (suite *KeeperTestSuite) TestBeforeValidatorSlashed() {
valAddr := valAddrs[del.valIndex]
delAddr := delAddrs[del.delIndex]
lock := suite.SetupSuperfluidDelegate(delAddr, valAddr, del.lpDenom, del.lpAmount)
expAcc := types.NewSuperfluidIntermediaryAccount(lock.Coins[0].Denom, valAddr.String(), 0)
// save accounts and locks for future use
intermediaryAccs = append(intermediaryAccs, expAcc)
locks = append(locks, lock)
}
......
......@@ -69,13 +69,13 @@ func (suite *KeeperTestSuite) checkIntermediaryAccountDelegations(intermediaryAc
// check delegation from intermediary account to validator
delegation, found := suite.app.StakingKeeper.GetDelegation(suite.ctx, acc.GetAccAddress(), valAddr)
suite.Require().True(found)
suite.Require().True(delegation.Shares.GTE(sdk.NewDec(19000000)))
suite.Require().True(delegation.Shares.GTE(sdk.NewDec(10000000)))
// check delegated tokens
validator, found := suite.app.StakingKeeper.GetValidator(suite.ctx, valAddr)
suite.Require().True(found)
delegatedTokens := validator.TokensFromShares(delegation.Shares).TruncateInt()
suite.Require().True(delegatedTokens.GTE(sdk.NewInt(19000000)))
suite.Require().True(delegatedTokens.GTE(sdk.NewInt(10000000)))
}
}
......@@ -142,21 +142,21 @@ func (suite *KeeperTestSuite) TestSuperfluidDelegate() {
[]stakingtypes.BondStatus{stakingtypes.Bonded},
1,
[]superfluidDelegation{{0, 0, "gamm/pool/1", 1000000}},
[]sdk.Dec{sdk.NewDec(19000000)}, // 95% x 2 x 1000000
[]sdk.Dec{sdk.NewDec(10000000)}, // 50% x 20 x 1000000
},
{
"with single validator and additional superfluid delegations",
[]stakingtypes.BondStatus{stakingtypes.Bonded},
1,
[]superfluidDelegation{{0, 0, "gamm/pool/1", 1000000}, {0, 0, "gamm/pool/1", 1000000}},
[]sdk.Dec{sdk.NewDec(38000000)}, // 95% x 2 x 1000000 x 2
[]sdk.Dec{sdk.NewDec(20000000)}, // 50% x 20 x 1000000 x 2
},
{
"with multiples validator and multiple superfluid delegations",
[]stakingtypes.BondStatus{stakingtypes.Bonded, stakingtypes.Bonded},
2,
[]superfluidDelegation{{0, 0, "gamm/pool/1", 1000000}, {1, 1, "gamm/pool/1", 1000000}},
[]sdk.Dec{sdk.NewDec(19000000), sdk.NewDec(19000000)}, // 95% x 2 x 1000000
[]sdk.Dec{sdk.NewDec(10000000), sdk.NewDec(10000000)}, // 50% x 20 x 1000000
},
}
......@@ -234,7 +234,7 @@ func (suite *KeeperTestSuite) TestSuperfluidDelegate() {
// check delegation from intermediary account to validator
delegation, found := suite.app.StakingKeeper.GetDelegation(suite.ctx, expAcc.GetAccAddress(), valAddr)
suite.Require().True(found)
suite.Require().Equal(delegation.Shares, tc.expInterDelegation[index])
suite.Require().Equal(tc.expInterDelegation[index], delegation.Shares)
}
// try delegating twice with same lockup
......@@ -305,7 +305,7 @@ func (suite *KeeperTestSuite) TestSuperfluidUndelegate() {
[]uint64{},
[]uint64{2},
[]bool{true},
[]sdk.Dec{sdk.NewDec(19000000)},
[]sdk.Dec{sdk.NewDec(10000000)},
},
{
"try undelegating twice for same lock id",
......
......@@ -48,5 +48,5 @@ func (suite *KeeperTestSuite) TestGetRiskAdjustedOsmoValue() {
types.SuperfluidAsset{Denom: "gamm/pool/1", AssetType: types.SuperfluidAssetTypeLPShare},
sdk.NewInt(100),
)
suite.Require().Equal(adjustedValue, sdk.NewInt(95))
suite.Require().Equal(sdk.NewInt(50), adjustedValue)
}
......@@ -11,7 +11,7 @@ import (
// Parameter store keys
var (
KeyMinimumRiskFactor = []byte("MinimumRiskFactor")
defaultMinimumRiskFactor = sdk.NewDecWithPrec(5, 2) // 5%
defaultMinimumRiskFactor = sdk.NewDecWithPrec(5, 1) // 50%
)
// ParamTable for minting module.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment