-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DAO module + Upgrade logic (#320)
* feat: add dao module + upgrade
- Loading branch information
Showing
52 changed files
with
7,449 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,4 @@ ignore: | |
- "types/*.pb.go" | ||
- "x/**/*.pb.gw.go" | ||
- "scripts/" | ||
- "x/dao/**" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package v176 | ||
|
||
const ( | ||
// UpgradeName is the shared upgrade plan name for network | ||
UpgradeName = "v1.7.6" | ||
|
||
// LockupLengthThreshold is the threshold for lockup periods length | ||
LockupLengthThreshold = 1717043774 | ||
|
||
// EndTimeForCheck is the threshold for end time of lockup periods | ||
EndTimeForCheck = 1767213372 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package v176 | ||
|
||
import ( | ||
"time" | ||
|
||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
sdkvestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" | ||
|
||
vestingtypes "github.com/haqq-network/haqq/x/vesting/types" | ||
) | ||
|
||
func FixLockupPeriods(ctx sdk.Context, ak authkeeper.AccountKeeper) error { | ||
logger := ctx.Logger() | ||
logger.Info("Start turning on DAO module") | ||
|
||
ak.IterateAccounts(ctx, func(acc authtypes.AccountI) (stop bool) { | ||
// Check if acc is vesting account | ||
vacc, ok := acc.(*vestingtypes.ClawbackVestingAccount) | ||
if !ok { | ||
return false | ||
} | ||
|
||
firstPeriod := vacc.LockupPeriods[0] | ||
firstPeriodTime := time.Unix(vacc.StartTime.Unix()+firstPeriod.Length, 0) | ||
|
||
if firstPeriodTime.After(time.Unix(LockupLengthThreshold, 0)) && vacc.GetEndTime() > EndTimeForCheck { | ||
unixBlockTime := ctx.BlockTime().Unix() | ||
|
||
sumOfLockupPeriods := math.NewInt(0) | ||
elapsedTime := vacc.GetStartTime() | ||
countPeriods := 0 | ||
|
||
newLookupPeriods := make(sdkvestingtypes.Periods, 0, len(vacc.LockupPeriods)) | ||
|
||
for _, period := range vacc.LockupPeriods { | ||
elapsedTime += period.Length | ||
|
||
if elapsedTime >= unixBlockTime { | ||
countPeriods += 1 | ||
sumOfLockupPeriods = sumOfLockupPeriods.Add(period.Amount[0].Amount) | ||
} | ||
} | ||
|
||
sumPerPeriod := sumOfLockupPeriods.QuoRaw(int64(countPeriods)) | ||
diff := sumOfLockupPeriods.Sub(sumPerPeriod.Mul(math.NewIntFromUint64(uint64(countPeriods)))) | ||
|
||
for index, period := range vacc.LockupPeriods { | ||
period.Amount[0].Amount = sumPerPeriod | ||
|
||
if index == len(vacc.LockupPeriods)-1 { | ||
period.Amount[0].Amount = period.Amount[0].Amount.Add(diff) | ||
} | ||
|
||
newLookupPeriods = append(newLookupPeriods, period) | ||
} | ||
|
||
vacc.LockupPeriods = newLookupPeriods | ||
ak.SetAccount(ctx, vacc) | ||
} | ||
|
||
return false | ||
}) | ||
|
||
return nil | ||
} |
Oops, something went wrong.