-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yaroms
committed
Apr 17, 2024
1 parent
9970a8a
commit 68e6915
Showing
3 changed files
with
50 additions
and
64 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/lavanet/lava/utils" | ||
"github.com/lavanet/lava/x/dualstaking/types" | ||
) | ||
|
||
func (k Keeper) BalanceDelegator(ctx sdk.Context, delegator sdk.AccAddress) (int, error) { | ||
diff, providers, err := k.VerifyDelegatorBalance(ctx, delegator) | ||
if err != nil { | ||
return providers, err | ||
} | ||
|
||
// if diff is zero, do nothing, this is a redelegate | ||
if diff.IsZero() { | ||
return providers, nil | ||
} else if diff.IsPositive() { | ||
// less provider delegations,a delegation operation was done, delegate to empty provider | ||
err = k.delegate(ctx, delegator.String(), types.EMPTY_PROVIDER, types.EMPTY_PROVIDER_CHAINID, | ||
sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), diff)) | ||
if err != nil { | ||
return providers, err | ||
} | ||
} else if diff.IsNegative() { | ||
// more provider delegation, unbond operation was done, unbond from providers | ||
err = k.UnbondUniformProviders(ctx, delegator.String(), sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), diff.Neg())) | ||
if err != nil { | ||
return providers, err | ||
} | ||
} | ||
|
||
diff, _, err = k.VerifyDelegatorBalance(ctx, delegator) | ||
if err != nil { | ||
return providers, err | ||
} | ||
// now it needs to be zero | ||
if !diff.IsZero() { | ||
return providers, utils.LavaFormatError("validator and provider balances are not balanced", nil, | ||
utils.Attribute{Key: "delegator", Value: delegator.String()}, | ||
utils.Attribute{Key: "diff", Value: diff.String()}, | ||
) | ||
} | ||
|
||
return providers, nil | ||
} |
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