-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
feat!: facilitate the tokenization of vested delegation in the LSM module #19614
Changes from 9 commits
4d79e01
ac71ede
d21d8f9
9eeb34f
9321e31
f72d359
cd5b806
987a86d
7cfaabc
5b42259
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
|
||
"cosmossdk.io/math" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
|
@@ -441,3 +442,30 @@ func (k Keeper) RefreshTotalLiquidStaked(ctx sdk.Context) error { | |
|
||
return nil | ||
} | ||
|
||
// CheckVestedDelegationInVestingAccount verifies whether the provided vesting account | ||
// holds a vested delegation for an equal or greater amount of the specified coin | ||
// at the given block time. | ||
// | ||
// Note that this function facilitates a specific use-case in the LSM module for tokenizing vested delegations. | ||
// For more details, see https://github.com/cosmos/gaia/issues/2877. | ||
func CheckVestedDelegationInVestingAccount(account vesting.VestingAccount, blockTime time.Time, coin sdk.Coin) bool { | ||
// Get the vesting coins at the current block time | ||
vestingAmount := account.GetVestingCoins(blockTime).AmountOf(coin.Denom) | ||
|
||
// Note that the "DelegatedVesting" and "DelegatedFree" values | ||
// were computed during the last delegation or undelegation operation | ||
delVestingAmount := account.GetDelegatedVesting().AmountOf(coin.Denom) | ||
delVested := account.GetDelegatedFree() | ||
|
||
// Calculate the new vested delegated coins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need to perform any calc here? Shouldn't the vesting type give us the amount of total vested? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The LSM module needs the total delegations vested at the current block time to know how many can be tokenized. Since the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, right we don't have an API for that. Would be nice to have this on the vesting types, but since it's legacy now maybe not worth it. |
||
x := sdk.MinInt(vestingAmount.Sub(delVestingAmount), math.ZeroInt()) | ||
|
||
// Add the newly vested delegated coins to the existing delegated vested amount | ||
if !x.IsZero() { | ||
delVested = delVested.Add(sdk.NewCoin(coin.Denom, x.Abs())) | ||
} | ||
|
||
// Check if the total delegated vested amount is greater than or equal to the specified coin amount | ||
return delVested.AmountOf(coin.Denom).GTE(coin.Amount) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there 2 imports for
gopkg.in/yaml.v2 v2.4.0
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. Was probably duplicated while resolving conflicts with
feature/v0.47.x-ics-lsm
.Removed by 987a86d.