-
Notifications
You must be signed in to change notification settings - Fork 10
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:register vesting type, add support for delegation/undelegation of native token #127
Changes from all commits
4e5c5f2
350ecbb
eb50f8b
6b1c497
ce54f9a
9929962
d7824eb
5ed62a4
aee4011
45e9206
5669fa4
bd5cc35
651715a
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package keeper | ||
MaxMustermann2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import ( | ||
delegationtype "github.com/ExocoreNetwork/exocore/x/delegation/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// this keeper interface is defined here to avoid a circular dependency | ||
type delegationKeeper interface { | ||
GetDelegationInfo(ctx sdk.Context, stakerID, assetID string) (*delegationtype.QueryDelegationInfoResponse, error) | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ | |||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
assetstype "github.com/ExocoreNetwork/exocore/x/assets/types" | ||||||||||||||||||||||||||
delegationkeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" | ||||||||||||||||||||||||||
"github.com/ethereum/go-ethereum/common/hexutil" | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
errorsmod "cosmossdk.io/errors" | ||||||||||||||||||||||||||
"cosmossdk.io/math" | ||||||||||||||||||||||||||
|
@@ -63,10 +65,54 @@ | |||||||||||||||||||||||||
Info: stateInfo, | ||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
// add exo-native-token info | ||||||||||||||||||||||||||
info, err := k.GetStakerSpecifiedAssetInfo(ctx, stakerID, assetstype.NativeAssetID) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||
Comment on lines
+70
to
+71
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. Wrap error with additional context When returning the error from Apply this diff to enhance the error handling: if err != nil {
- return nil, err
+ return nil, errorsmod.Wrap(err, "failed to get staker specified asset info for native asset")
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
ret = append(ret, assetstype.DepositByAsset{ | ||||||||||||||||||||||||||
AssetID: assetstype.NativeAssetID, | ||||||||||||||||||||||||||
Info: *info, | ||||||||||||||||||||||||||
}) | ||||||||||||||||||||||||||
return ret, nil | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func (k Keeper) GetStakerSpecifiedAssetInfo(ctx sdk.Context, stakerID string, assetID string) (info *assetstype.StakerAssetInfo, err error) { | ||||||||||||||||||||||||||
if assetID == assetstype.NativeAssetID { | ||||||||||||||||||||||||||
stakerAddrStr, _, err := assetstype.ParseID(stakerID) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorsmod.Wrap(err, "failed to parse stakerID") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
stakerAccDecode, err := hexutil.Decode(stakerAddrStr) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorsmod.Wrap(err, "failed to decode staker address") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
stakerAcc := sdk.AccAddress(stakerAccDecode) | ||||||||||||||||||||||||||
balance := k.bk.GetBalance(ctx, stakerAcc, assetstype.NativeAssetDenom) | ||||||||||||||||||||||||||
info := &assetstype.StakerAssetInfo{ | ||||||||||||||||||||||||||
TotalDepositAmount: balance.Amount, | ||||||||||||||||||||||||||
WithdrawableAmount: balance.Amount, | ||||||||||||||||||||||||||
PendingUndelegationAmount: math.NewInt(0), | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
delegationInfoRecords, err := k.dk.GetDelegationInfo(ctx, stakerID, assetID) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorsmod.Wrap(err, "failed to GetDelegationInfo") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
for operator, record := range delegationInfoRecords.DelegationInfos { | ||||||||||||||||||||||||||
operatorAssetInfo, err := k.GetOperatorSpecifiedAssetInfo(ctx, sdk.MustAccAddressFromBech32(operator), assetID) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorsmod.Wrap(err, "failed to GetOperatorSpecifiedAssetInfo") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+103
to
+106
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. Avoid potential panics by not using Using Apply this diff to handle potential errors: -operatorAssetInfo, err := k.GetOperatorSpecifiedAssetInfo(ctx, sdk.MustAccAddressFromBech32(operator), assetID)
+operatorAccAddr, err := sdk.AccAddressFromBech32(operator)
+if err != nil {
+ return nil, errorsmod.Wrapf(err, "invalid operator address: %s", operator)
+}
+operatorAssetInfo, err := k.GetOperatorSpecifiedAssetInfo(ctx, operatorAccAddr, assetID)
if err != nil {
return nil, errorsmod.Wrap(err, "failed to GetOperatorSpecifiedAssetInfo")
} Committable suggestion
Suggested change
|
||||||||||||||||||||||||||
undelegatableTokens, err := delegationkeeper.TokensFromShares(record.UndelegatableShare, operatorAssetInfo.TotalShare, operatorAssetInfo.TotalAmount) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, errorsmod.Wrap(err, "failed to get shares from token") | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
info.TotalDepositAmount = info.TotalDepositAmount.Add(undelegatableTokens).Add(record.WaitUndelegationAmount) | ||||||||||||||||||||||||||
info.PendingUndelegationAmount = info.PendingUndelegationAmount.Add(record.WaitUndelegationAmount) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
return info, nil | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
store := prefix.NewStore(ctx.KVStore(k.storeKey), assetstype.KeyPrefixReStakerAssetInfos) | ||||||||||||||||||||||||||
key := assetstype.GetJoinedStoreKey(stakerID, assetID) | ||||||||||||||||||||||||||
value := store.Get(key) | ||||||||||||||||||||||||||
|
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.
Update comments to reflect current transfer stack
The comments mention
Recovery Middleware
, but it appears the recovery middleware is no longer part of the transfer stack. Please update the comments to accurately represent the current middleware configuration.Apply this diff to correct the comments:
Committable suggestion