Unverified Commit 33ec9921 authored by antstalepresh's avatar antstalepresh Committed by GitHub
Browse files

Refactor synthetic lockup (#836)

* add basic changes for simulation

* add superfluid message types

* register msg server, handler, fix build issues, configure basic actions for superfluid operations

* resolve message validatebasic, fix automatic delegation from intermediary account, increase simulation coverage

* Put superfluid unbonding duration as param, simulation test genesis manipulation

* add simulation for proposals

* add basic checker for superfluid operations

* update reward management logic

* add tx commands for superfluid delegate

* add cli commands for proposals

* single node configuration as epoch - min and relevant times

* resolve twap price issue, synthetic lockup distribution, connect epochs hook to superfluid, fix gauge creation issue

* fix simulation weights

* superfluid lockup ownership check & error handling & queries & addTokensToLock/removeTokensFromLock connection with synthetic lockup

* add more test plans

* further test steps

* Add S...
parent c1015b6c
Showing with 303 additions and 95 deletions
+303 -95
......@@ -65,4 +65,16 @@ message SyntheticLock {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"end_time\""
];
google.protobuf.Duration duration = 4 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true,
(gogoproto.jsontag) = "duration,omitempty",
(gogoproto.moretags) = "yaml:\"duration\""
];
// The coins from the underlying lock ID that are synthetically locked
repeated cosmos.base.v1beta1.Coin coins = 5 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
string owner = 6 [ (gogoproto.moretags) = "yaml:\"owner\"" ];
}
......@@ -15,3 +15,7 @@ func (k Keeper) DeleteLockRefByKey(ctx sdk.Context, key []byte, lockID uint64) e
func (k Keeper) GetLockRefs(ctx sdk.Context, key []byte) []uint64 {
return k.getLockRefs(ctx, key)
}
func (k Keeper) SyntheticCoins(coins sdk.Coins, suffix string) sdk.Coins {
return syntheticCoins(coins, suffix)
}
......@@ -77,26 +77,27 @@ func (k Keeper) deleteLockRefs(ctx sdk.Context, lockRefPrefix []byte, lock types
return nil
}
func (k Keeper) addSyntheticLockRefs(ctx sdk.Context, lockRefPrefix []byte, lock types.PeriodLock) error {
refKeys, err := syntheticLockRefKeys(lock)
// XXX
func (k Keeper) addSyntheticLockRefs(ctx sdk.Context, lockRefPrefix []byte, synthLock types.SyntheticLock) error {
refKeys, err := syntheticLockRefKeys(synthLock)
if err != nil {
return err
}
for _, refKey := range refKeys {
if err := k.addLockRefByKey(ctx, combineKeys(lockRefPrefix, refKey), lock.ID); err != nil {
if err := k.addLockRefByKey(ctx, combineKeys(lockRefPrefix, refKey), synthLock.UnderlyingLockId); err != nil {
return err
}
}
return nil
}
func (k Keeper) deleteSyntheticLockRefs(ctx sdk.Context, lockRefPrefix []byte, lock types.PeriodLock) error {
refKeys, err := syntheticLockRefKeys(lock)
func (k Keeper) deleteSyntheticLockRefs(ctx sdk.Context, lockRefPrefix []byte, synthLock types.SyntheticLock) error {
refKeys, err := syntheticLockRefKeys(synthLock)
if err != nil {
return err
}
for _, refKey := range refKeys {
if err := k.deleteLockRefByKey(ctx, combineKeys(lockRefPrefix, refKey), lock.ID); err != nil {
if err := k.deleteLockRefByKey(ctx, combineKeys(lockRefPrefix, refKey), synthLock.UnderlyingLockId); err != nil {
return err
}
}
......@@ -564,33 +565,26 @@ func (k Keeper) ResetAllSyntheticLocks(ctx sdk.Context, syntheticLocks []types.S
ctx.Logger().Info(msg)
}
lock, err := k.GetLockByID(ctx, synthLock.UnderlyingLockId)
if err != nil {
return err
}
lock.Coins = syntheticCoins(lock.Coins, synthLock.Suffix)
lock.EndTime = synthLock.EndTime
err = k.setSyntheticLockAndResetRefs(ctx, *lock, synthLock)
err := k.setSyntheticLockAndResetRefs(ctx, synthLock)
if err != nil {
return err
}
// Add to the accumlation store cache
for _, coin := range lock.Coins {
for _, coin := range synthLock.Coins {
// update or create the new map from duration -> Int for this denom.
var curDurationMap map[time.Duration]sdk.Int
if durationMap, ok := accumulationStoreEntries[coin.Denom]; ok {
curDurationMap = durationMap
// update or create new amount in the duration map
newAmt := coin.Amount
if curAmt, ok := durationMap[lock.Duration]; ok {
if curAmt, ok := durationMap[synthLock.Duration]; ok {
newAmt = newAmt.Add(curAmt)
}
curDurationMap[lock.Duration] = newAmt
curDurationMap[synthLock.Duration] = newAmt
} else {
denoms = append(denoms, coin.Denom)
curDurationMap = map[time.Duration]sdk.Int{lock.Duration: coin.Amount}
curDurationMap = map[time.Duration]sdk.Int{synthLock.Duration: coin.Amount}
}
accumulationStoreEntries[coin.Denom] = curDurationMap
}
......@@ -619,18 +613,18 @@ func (k Keeper) ResetAllSyntheticLocks(ctx sdk.Context, syntheticLocks []types.S
return nil
}
func (k Keeper) setSyntheticLockAndResetRefs(ctx sdk.Context, lock types.PeriodLock, synthLock types.SyntheticLock) error {
err := k.setSyntheticLockupObject(ctx, synthLock.UnderlyingLockId, synthLock.Suffix, synthLock.EndTime)
func (k Keeper) setSyntheticLockAndResetRefs(ctx sdk.Context, synthLock types.SyntheticLock) error {
err := k.setSyntheticLockupObject(ctx, &synthLock)
if err != nil {
return err
}
// store refs by the status of unlock
if lock.IsUnlocking() {
return k.addSyntheticLockRefs(ctx, types.KeyPrefixUnlocking, lock)
if synthLock.IsUnlocking() {
return k.addSyntheticLockRefs(ctx, types.KeyPrefixUnlocking, synthLock)
}
return k.addSyntheticLockRefs(ctx, types.KeyPrefixNotUnlocking, lock)
return k.addSyntheticLockRefs(ctx, types.KeyPrefixNotUnlocking, synthLock)
}
// setLockAndResetLockRefs sets the lock, and resets all of its lock references
......
......@@ -9,20 +9,15 @@ import (
"github.com/osmosis-labs/osmosis/x/lockup/types"
)
func (k Keeper) setSyntheticLockupObject(ctx sdk.Context, underlyingLockID uint64, suffix string, endTime time.Time) error {
synthLock := &types.SyntheticLock{
UnderlyingLockId: underlyingLockID,
Suffix: suffix,
EndTime: endTime,
}
func (k Keeper) setSyntheticLockupObject(ctx sdk.Context, synthLock *types.SyntheticLock) error {
store := ctx.KVStore(k.storeKey)
bz, err := proto.Marshal(synthLock)
if err != nil {
return err
}
store.Set(syntheticLockStoreKey(underlyingLockID, suffix), bz)
if !endTime.Equal(time.Time{}) {
store.Set(syntheticLockTimeStoreKey(underlyingLockID, suffix, endTime), bz)
store.Set(syntheticLockStoreKey(synthLock.UnderlyingLockId, synthLock.Suffix), bz)
if !synthLock.EndTime.Equal(time.Time{}) {
store.Set(syntheticLockTimeStoreKey(synthLock.UnderlyingLockId, synthLock.Suffix, synthLock.EndTime), bz)
}
return nil
}
......@@ -81,7 +76,7 @@ func (k Keeper) GetAllSyntheticLockups(ctx sdk.Context) []types.SyntheticLock {
}
// CreateSyntheticLockup create synthetic lockup with lock id and suffix
func (k Keeper) CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string, unlockDuration time.Duration) error {
func (k Keeper) CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string, unlockDuration time.Duration, isUnlocking bool) error {
// Note: synthetic lockup is doing everything same as lockup except coin movement
// There is no relationship between unbonding and bonding synthetic lockup, it's managed separately
// Accumulation store works without caring about unlocking synthetic or not
......@@ -91,7 +86,6 @@ func (k Keeper) CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix str
return types.ErrSyntheticLockupAlreadyExists
}
isUnlocking := (unlockDuration != 0)
lock, err := k.GetLockByID(ctx, lockID)
if err != nil {
return err
......@@ -108,7 +102,15 @@ func (k Keeper) CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix str
}
// set synthetic lockup object
err = k.setSyntheticLockupObject(ctx, lockID, suffix, lock.EndTime)
synthLock := types.SyntheticLock{
UnderlyingLockId: lockID,
Suffix: suffix,
EndTime: lock.EndTime,
Duration: unlockDuration,
Coins: lock.Coins,
Owner: lock.Owner,
}
err = k.setSyntheticLockupObject(ctx, &synthLock)
if err != nil {
return err
}
......@@ -116,7 +118,7 @@ func (k Keeper) CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix str
unlockingPrefix := unlockingPrefix(isUnlocking)
// add lock refs into not unlocking queue
err = k.addSyntheticLockRefs(ctx, unlockingPrefix, *lock)
err = k.addSyntheticLockRefs(ctx, unlockingPrefix, synthLock)
if err != nil {
return err
}
......@@ -148,7 +150,7 @@ func (k Keeper) DeleteSyntheticLockup(ctx sdk.Context, lockID uint64, suffix str
k.deleteSyntheticLockupObject(ctx, lockID, suffix)
// delete lock refs from the unlocking queue
err = k.deleteSyntheticLockRefs(ctx, unlockingPrefix(lock.IsUnlocking()), *lock)
err = k.deleteSyntheticLockRefs(ctx, unlockingPrefix(lock.IsUnlocking()), *synthLock)
if err != nil {
return err
}
......
......@@ -22,19 +22,19 @@ func (suite *KeeperTestSuite) TestSyntheticLockupCreation() {
suite.Require().Equal(locks[0].Coins, coins)
// create not unbonding synthetic lockup
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix1", 0)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix1", time.Second, false)
suite.Require().NoError(err)
// try creating same suffix synthetic lockup for a single lockup
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix1", time.Second)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix1", time.Second, true)
suite.Require().Error(err)
// create unbonding synthetic lockup
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix2", time.Second)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix2", time.Second, true)
suite.Require().NoError(err)
// try creating unbonding synthetic lockup that is long than native lockup unbonding duration
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix3", time.Second*2)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "suffix3", time.Second*2, true)
suite.Require().Error(err)
}
......@@ -114,7 +114,7 @@ func (suite *KeeperTestSuite) TestSyntheticLockupCreateGetDeleteAccumulation() {
locks = suite.app.LockupKeeper.GetAccountUnlockedBeforeTime(suite.ctx, addr1, suite.ctx.BlockTime())
suite.Require().Len(locks, 0)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", 0)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", time.Second, false)
suite.Require().NoError(err)
synthLock, err := suite.app.LockupKeeper.GetSyntheticLockup(suite.ctx, 1, "stakedtovalidator1")
......@@ -123,6 +123,9 @@ func (suite *KeeperTestSuite) TestSyntheticLockupCreateGetDeleteAccumulation() {
UnderlyingLockId: 1,
Suffix: "stakedtovalidator1",
EndTime: time.Time{},
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator1"),
Owner: addr1.String(),
})
expectedSynthLocks := []types.SyntheticLock{*synthLock}
......@@ -187,7 +190,7 @@ func (suite *KeeperTestSuite) TestSyntheticLockupCreateGetDeleteAccumulation() {
suite.Require().Len(locks, 0)
// try creating synthetic lockup with same lock and suffix
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", time.Second)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", time.Second, false)
suite.Require().Error(err)
// delete synthetic lockup
......@@ -221,7 +224,7 @@ func (suite *KeeperTestSuite) TestSyntheticLockupDeleteAllSyntheticLocksByLockup
suite.Require().Len(locks, 1)
suite.Require().Equal(locks[0].Coins, coins)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", 0)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", time.Second, false)
suite.Require().NoError(err)
synthLock, err := suite.app.LockupKeeper.GetSyntheticLockup(suite.ctx, 1, "stakedtovalidator1")
......@@ -230,6 +233,9 @@ func (suite *KeeperTestSuite) TestSyntheticLockupDeleteAllSyntheticLocksByLockup
UnderlyingLockId: 1,
Suffix: "stakedtovalidator1",
EndTime: time.Time{},
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator1"),
Owner: addr1.String(),
})
err = suite.app.LockupKeeper.DeleteAllSyntheticLocksByLockup(suite.ctx, 1)
......@@ -254,10 +260,10 @@ func (suite *KeeperTestSuite) TestSyntheticLockupDeleteAllMaturedSyntheticLocks(
suite.Require().Len(locks, 1)
suite.Require().Equal(locks[0].Coins, coins)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", 0)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator1", time.Second, false)
suite.Require().NoError(err)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator2", time.Second)
err = suite.app.LockupKeeper.CreateSyntheticLockup(suite.ctx, 1, "stakedtovalidator2", time.Second, true)
suite.Require().NoError(err)
synthLock, err := suite.app.LockupKeeper.GetSyntheticLockup(suite.ctx, 1, "stakedtovalidator1")
......@@ -266,6 +272,9 @@ func (suite *KeeperTestSuite) TestSyntheticLockupDeleteAllMaturedSyntheticLocks(
UnderlyingLockId: 1,
Suffix: "stakedtovalidator1",
EndTime: time.Time{},
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator1"),
Owner: addr1.String(),
})
synthLock, err = suite.app.LockupKeeper.GetSyntheticLockup(suite.ctx, 1, "stakedtovalidator2")
suite.Require().NoError(err)
......@@ -273,6 +282,9 @@ func (suite *KeeperTestSuite) TestSyntheticLockupDeleteAllMaturedSyntheticLocks(
UnderlyingLockId: 1,
Suffix: "stakedtovalidator2",
EndTime: suite.ctx.BlockTime().Add(time.Second),
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator2"),
Owner: addr1.String(),
})
suite.app.LockupKeeper.DeleteAllMaturedSyntheticLocks(suite.ctx)
......@@ -310,11 +322,17 @@ func (suite *KeeperTestSuite) TestResetAllSyntheticLocks() {
UnderlyingLockId: 1,
Suffix: "stakedtovalidator1",
EndTime: time.Time{},
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator1"),
Owner: addr1.String(),
},
{
UnderlyingLockId: 1,
Suffix: "stakedtovalidator2",
EndTime: suite.ctx.BlockTime().Add(time.Second),
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator2"),
Owner: addr1.String(),
},
})
......@@ -324,6 +342,9 @@ func (suite *KeeperTestSuite) TestResetAllSyntheticLocks() {
UnderlyingLockId: 1,
Suffix: "stakedtovalidator1",
EndTime: time.Time{},
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator1"),
Owner: addr1.String(),
})
synthLock, err = suite.app.LockupKeeper.GetSyntheticLockup(suite.ctx, 1, "stakedtovalidator2")
suite.Require().NoError(err)
......@@ -331,6 +352,9 @@ func (suite *KeeperTestSuite) TestResetAllSyntheticLocks() {
UnderlyingLockId: 1,
Suffix: "stakedtovalidator2",
EndTime: suite.ctx.BlockTime().Add(time.Second),
Duration: time.Second,
Coins: suite.app.LockupKeeper.SyntheticCoins(coins, "stakedtovalidator2"),
Owner: addr1.String(),
})
accum := suite.app.LockupKeeper.GetPeriodLocksAccumulation(suite.ctx, types.QueryCondition{
......
......@@ -69,19 +69,19 @@ func lockRefKeys(lock types.PeriodLock) ([][]byte, error) {
}
// syntheticLockRefKeys are different from native lockRefKeys to avoid conflicts
func syntheticLockRefKeys(lock types.PeriodLock) ([][]byte, error) {
func syntheticLockRefKeys(synthLock types.SyntheticLock) ([][]byte, error) {
// Note: syntheticLockRefKeys should be only used for querying and should not be combined with native lockup operations
// synthetic suffix denom should not conflict with native denom
refKeys := [][]byte{}
timeKey := getTimeKey(lock.EndTime)
durationKey := getDurationKey(lock.Duration)
timeKey := getTimeKey(synthLock.EndTime)
durationKey := getDurationKey(synthLock.Duration)
owner, err := sdk.AccAddressFromBech32(lock.Owner)
owner, err := sdk.AccAddressFromBech32(synthLock.Owner)
if err != nil {
return nil, err
}
for _, coin := range lock.Coins {
for _, coin := range synthLock.Coins {
denomBz := []byte(coin.Denom)
refKeys = append(refKeys, combineKeys(types.KeyPrefixDenomLockTimestamp, denomBz, timeKey))
refKeys = append(refKeys, combineKeys(types.KeyPrefixDenomLockDuration, denomBz, durationKey))
......
......@@ -24,6 +24,11 @@ func (p PeriodLock) IsUnlocking() bool {
return !p.EndTime.Equal(time.Time{})
}
// IsUnlocking returns lock started unlocking already
func (p SyntheticLock) IsUnlocking() bool {
return !p.EndTime.Equal(time.Time{})
}
func SumLocksByDenom(locks []PeriodLock, denom string) sdk.Int {
sum := sdk.NewInt(0)
err := sdk.ValidateDenom(denom)
......
......@@ -209,7 +209,10 @@ type SyntheticLock struct {
UnderlyingLockId uint64 `protobuf:"varint,1,opt,name=underlying_lock_id,json=underlyingLockId,proto3" json:"underlying_lock_id,omitempty"`
Suffix string `protobuf:"bytes,2,opt,name=suffix,proto3" json:"suffix,omitempty"`
// used for unbonding synthetic lockups, for active synthetic lockups, this value is set to uninitialized value
EndTime time.Time `protobuf:"bytes,3,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"`
EndTime time.Time `protobuf:"bytes,3,opt,name=end_time,json=endTime,proto3,stdtime" json:"end_time" yaml:"end_time"`
Duration time.Duration `protobuf:"bytes,4,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"`
Coins github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,5,rep,name=coins,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"coins"`
Owner string `protobuf:"bytes,6,opt,name=owner,proto3" json:"owner,omitempty" yaml:"owner"`
}
func (m *SyntheticLock) Reset() { *m = SyntheticLock{} }
......@@ -266,6 +269,27 @@ func (m *SyntheticLock) GetEndTime() time.Time {
return time.Time{}
}
func (m *SyntheticLock) GetDuration() time.Duration {
if m != nil {
return m.Duration
}
return 0
}
func (m *SyntheticLock) GetCoins() github_com_cosmos_cosmos_sdk_types.Coins {
if m != nil {
return m.Coins
}
return nil
}
func (m *SyntheticLock) GetOwner() string {
if m != nil {
return m.Owner
}
return ""
}
func init() {
proto.RegisterEnum("osmosis.lockup.LockQueryType", LockQueryType_name, LockQueryType_value)
proto.RegisterType((*PeriodLock)(nil), "osmosis.lockup.PeriodLock")
......@@ -276,44 +300,45 @@ func init() {
func init() { proto.RegisterFile("osmosis/lockup/lock.proto", fileDescriptor_7e9d7527a237b489) }
var fileDescriptor_7e9d7527a237b489 = []byte{
// 582 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xbf, 0x6f, 0xd3, 0x40,
0x14, 0xb6, 0xf3, 0x8b, 0xf6, 0x20, 0x69, 0x74, 0xaa, 0x50, 0x1a, 0xc0, 0x8e, 0x3c, 0xa0, 0x08,
0xb5, 0x67, 0x52, 0x36, 0x46, 0x37, 0x48, 0x44, 0x62, 0x00, 0x53, 0x31, 0xb0, 0x44, 0xfe, 0x71,
0x71, 0x4e, 0xb1, 0x7d, 0xc6, 0x3f, 0xa0, 0xfe, 0x0f, 0x18, 0x3b, 0xc2, 0xcc, 0x04, 0x7f, 0x49,
0xc7, 0x8e, 0x4c, 0x29, 0x4a, 0xc4, 0xc2, 0xd8, 0xbf, 0x00, 0xdd, 0x9d, 0x9d, 0x34, 0x45, 0x48,
0x1d, 0x3a, 0x9d, 0xdf, 0x7d, 0xef, 0x7d, 0xef, 0xdd, 0xf7, 0x3e, 0x19, 0xec, 0xd1, 0x24, 0xa0,
0x09, 0x49, 0x74, 0x9f, 0x3a, 0xb3, 0x2c, 0xe2, 0x07, 0x8a, 0x62, 0x9a, 0x52, 0xd8, 0x2a, 0x20,
0x24, 0xa0, 0xee, 0xae, 0x47, 0x3d, 0xca, 0x21, 0x9d, 0x7d, 0x89, 0xac, 0xae, 0xe2, 0x51, 0xea,
0xf9, 0x58, 0xe7, 0x91, 0x9d, 0x4d, 0x74, 0x37, 0x8b, 0xad, 0x94, 0xd0, 0xb0, 0xc0, 0xd5, 0xeb,
0x78, 0x4a, 0x02, 0x9c, 0xa4, 0x56, 0x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b, 0x9f, 0xbf, 0x29, 0x92, 0xf1, 0xf2, 0x6c, 0xa1, 0xc8,
0xe7, 0x0b, 0x45, 0xfe, 0xb5, 0x50, 0xe4, 0xd3, 0xa5, 0x22, 0x9d, 0x2f, 0x15, 0xe9, 0xe7, 0x52,
0x91, 0xde, 0xa3, 0x2b, 0x2e, 0x2a, 0x56, 0x7e, 0xe0, 0x5b, 0x76, 0x52, 0x06, 0xfa, 0x49, 0xf9,
0xe3, 0xe0, 0x8e, 0xb2, 0x1b, 0x7c, 0xec, 0x67, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0x10, 0xff,
0x71, 0xc5, 0x57, 0x04, 0x00, 0x00,
// 600 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x3d, 0x6f, 0xd3, 0x40,
0x18, 0xc7, 0xed, 0xbc, 0xd1, 0x1e, 0x34, 0x8d, 0x4e, 0x15, 0x4a, 0x03, 0xd8, 0x91, 0x07, 0x14,
0xa1, 0xf6, 0x4c, 0xca, 0xc6, 0xe8, 0x16, 0x89, 0x48, 0x0c, 0x60, 0x2a, 0x06, 0x96, 0xc8, 0x2f,
0x17, 0xe7, 0x14, 0xdb, 0x67, 0xfc, 0x02, 0xf5, 0x37, 0x60, 0xec, 0x08, 0x0b, 0x0b, 0x1b, 0x9f,
0xa4, 0x63, 0x47, 0xa6, 0x14, 0x25, 0x62, 0x61, 0xec, 0x27, 0x40, 0x77, 0x67, 0xe7, 0xa5, 0x08,
0xd4, 0x81, 0x4e, 0xce, 0xe3, 0xff, 0x3d, 0xff, 0x7b, 0xee, 0x77, 0x7f, 0x07, 0xec, 0xd2, 0x24,
0xa0, 0x09, 0x49, 0x74, 0x9f, 0x3a, 0x93, 0x2c, 0xe2, 0x0f, 0x14, 0xc5, 0x34, 0xa5, 0xb0, 0x59,
0x48, 0x48, 0x48, 0x9d, 0x1d, 0x8f, 0x7a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 0x52, 0x20, 0x28, 0xaa, 0xb5, 0xa8, 0x54, 0xff,
0x53, 0x54, 0x56, 0x83, 0x5e, 0xbb, 0xd1, 0xa0, 0xdf, 0x7c, 0x28, 0x97, 0x5f, 0x77, 0xe3, 0x9f,
0x5f, 0xf7, 0xa3, 0x3e, 0xd8, 0x5a, 0x8b, 0x20, 0x6c, 0x02, 0x60, 0xe4, 0xe5, 0x31, 0x5b, 0x12,
0x04, 0xa0, 0x61, 0xe4, 0x8c, 0x4f, 0x4b, 0xee, 0xd4, 0x3e, 0x7e, 0x55, 0x24, 0xe3, 0xf9, 0xd9,
0x4c, 0x91, 0xcf, 0x67, 0x8a, 0xfc, 0x63, 0xa6, 0xc8, 0xa7, 0x73, 0x45, 0x3a, 0x9f, 0x2b, 0xd2,
0xf7, 0xb9, 0x22, 0xbd, 0x45, 0x2b, 0x53, 0x16, 0x39, 0xdf, 0xf7, 0x2d, 0x3b, 0x29, 0x0b, 0xfd,
0xa4, 0xfc, 0xb7, 0xe4, 0x13, 0xdb, 0x0d, 0xce, 0xf5, 0xc9, 0xef, 0x00, 0x00, 0x00, 0xff, 0xff,
0xf4, 0x94, 0xd1, 0x40, 0x4c, 0x05, 0x00, 0x00,
}
func (m *PeriodLock) Marshal() (dAtA []byte, err error) {
......@@ -452,13 +477,42 @@ func (m *SyntheticLock) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
n5, err5 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):])
if len(m.Owner) > 0 {
i -= len(m.Owner)
copy(dAtA[i:], m.Owner)
i = encodeVarintLock(dAtA, i, uint64(len(m.Owner)))
i--
dAtA[i] = 0x32
}
if len(m.Coins) > 0 {
for iNdEx := len(m.Coins) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Coins[iNdEx].MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintLock(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x2a
}
}
n5, err5 := github_com_gogo_protobuf_types.StdDurationMarshalTo(m.Duration, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdDuration(m.Duration):])
if err5 != nil {
return 0, err5
}
i -= n5
i = encodeVarintLock(dAtA, i, uint64(n5))
i--
dAtA[i] = 0x22
n6, err6 := github_com_gogo_protobuf_types.StdTimeMarshalTo(m.EndTime, dAtA[i-github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime):])
if err6 != nil {
return 0, err6
}
i -= n6
i = encodeVarintLock(dAtA, i, uint64(n6))
i--
dAtA[i] = 0x1a
if len(m.Suffix) > 0 {
i -= len(m.Suffix)
......@@ -547,6 +601,18 @@ func (m *SyntheticLock) Size() (n int) {
}
l = github_com_gogo_protobuf_types.SizeOfStdTime(m.EndTime)
n += 1 + l + sovLock(uint64(l))
l = github_com_gogo_protobuf_types.SizeOfStdDuration(m.Duration)
n += 1 + l + sovLock(uint64(l))
if len(m.Coins) > 0 {
for _, e := range m.Coins {
l = e.Size()
n += 1 + l + sovLock(uint64(l))
}
}
l = len(m.Owner)
if l > 0 {
n += 1 + l + sovLock(uint64(l))
}
return n
}
......@@ -1037,6 +1103,105 @@ func (m *SyntheticLock) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowLock
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthLock
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthLock
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := github_com_gogo_protobuf_types.StdDurationUnmarshal(&m.Duration, dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Coins", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowLock
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthLock
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthLock
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Coins = append(m.Coins, types.Coin{})
if err := m.Coins[len(m.Coins)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowLock
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthLock
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthLock
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Owner = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipLock(dAtA[iNdEx:])
......
......@@ -208,7 +208,8 @@ func (k Keeper) SuperfluidDelegate(ctx sdk.Context, sender string, lockID uint64
// Register a synthetic lockup for superfluid staking
suffix = stakingSuffix(valAddr)
err = k.lk.CreateSyntheticLockup(ctx, lockID, suffix, 0)
notUnlocking := false
err = k.lk.CreateSyntheticLockup(ctx, lockID, suffix, params.UnbondingDuration, notUnlocking)
if err != nil {
return err
}
......@@ -299,7 +300,8 @@ func (k Keeper) SuperfluidUndelegate(ctx sdk.Context, sender string, lockID uint
params := k.GetParams(ctx)
suffix = unstakingSuffix(intermediaryAcc.ValAddr)
err = k.lk.CreateSyntheticLockup(ctx, lockID, suffix, params.UnbondingDuration)
unlocking := true
err = k.lk.CreateSyntheticLockup(ctx, lockID, suffix, params.UnbondingDuration, unlocking)
if err != nil {
return nil, err
}
......
......@@ -20,7 +20,7 @@ type LockupKeeper interface {
GetPeriodLocks(ctx sdk.Context) ([]lockuptypes.PeriodLock, error)
GetLockByID(ctx sdk.Context, lockID uint64) (*lockuptypes.PeriodLock, error)
GetSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string) (*lockuptypes.SyntheticLock, error)
CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string, unlockDuration time.Duration) error
CreateSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string, unlockDuration time.Duration, isUnlocking bool) error
DeleteSyntheticLockup(ctx sdk.Context, lockID uint64, suffix string) error
SlashTokensFromLockByID(ctx sdk.Context, lockID uint64, coins sdk.Coins) (*lockuptypes.PeriodLock, error)
}
......
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