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

Add Hook for Extend Lockup Duration #1405

Merged
merged 4 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions x/lockup/keeper/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,11 @@ func (k Keeper) ExtendLockup(ctx sdk.Context, lock types.PeriodLock, newDuration
return err
}

k.hooks.OnTokenUnlocked(ctx, lock.OwnerAddress(), lock.ID, lock.Coins, oldLock.Duration, lock.EndTime)
k.hooks.OnTokenLocked(ctx, lock.OwnerAddress(), lock.ID, lock.Coins, lock.Duration, lock.EndTime)
k.hooks.OnLockupExtend(ctx,
lock.GetID(),
oldLock.GetDuration(),
lock.GetDuration(),
)

return nil
}
7 changes: 7 additions & 0 deletions x/lockup/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type LockupHooks interface {
OnStartUnlock(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time)
OnTokenUnlocked(ctx sdk.Context, address sdk.AccAddress, lockID uint64, amount sdk.Coins, lockDuration time.Duration, unlockTime time.Time)
OnTokenSlashed(ctx sdk.Context, lockID uint64, amount sdk.Coins)
OnLockupExtend(ctx sdk.Context, lockID uint64, prevDuration time.Duration, newDuration time.Duration)
}

var _ LockupHooks = MultiLockupHooks{}
Expand Down Expand Up @@ -52,3 +53,9 @@ func (h MultiLockupHooks) OnTokenSlashed(ctx sdk.Context, lockID uint64, amount
h[i].OnTokenSlashed(ctx, lockID, amount)
}
}

func (h MultiLockupHooks) OnLockupExtend(ctx sdk.Context, lockID uint64, prevDuration, newDuration time.Duration) {
for i := range h {
h[i].OnLockupExtend(ctx, lockID, prevDuration, newDuration)
}
}
3 changes: 3 additions & 0 deletions x/superfluid/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func (h Hooks) OnTokenUnlocked(ctx sdk.Context, address sdk.AccAddress, lockID u
func (h Hooks) OnTokenSlashed(ctx sdk.Context, lockID uint64, amount sdk.Coins) {
}

func (h Hooks) OnLockupExtend(ctx sdk.Context, lockID uint64, oldDuration, newDuration time.Duration) {
}

// staking hooks.
func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) {}
func (h Hooks) BeforeValidatorModified(ctx sdk.Context, valAddr sdk.ValAddress) {}
Expand Down