Skip to content

Commit

Permalink
feat: Allow undelegation from bankrupt delegatee
Browse files Browse the repository at this point in the history
  • Loading branch information
OnedgeLee committed Jan 15, 2025
1 parent fa466c8 commit 3bc8409
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Lib9c/Action/ClaimStakeReward.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public static IWorld Claim(
var stakeRegularRewardSheet = sheets.GetSheet<StakeRegularRewardSheet>();
// NOTE:
var ncg = states.GetGoldCurrency();
var stakedNcg = states.GetStaked(stakeStateAddress);
var stakedNcg = states.GetStaked(context.Signer);
var stakingLevel = Math.Min(
stakeRegularRewardSheet.FindLevelByStakedAmount(
context.Signer,
Expand Down
2 changes: 1 addition & 1 deletion Lib9c/Delegation/Delegatee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public virtual BigInteger Bond(TDelegator delegator, FungibleAssetValue fav, lon
public FungibleAssetValue Unbond(TDelegator delegator, BigInteger share, long height)
{
DistributeReward(delegator, height);
if (TotalShares.IsZero || TotalDelegated.RawValue.IsZero)
if (TotalShares.IsZero)
{
throw new InvalidOperationException(
"Cannot unbond without bonding.");
Expand Down
13 changes: 8 additions & 5 deletions Lib9c/Delegation/Delegator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,20 @@ public virtual void Undelegate(
}

FungibleAssetValue fav = delegatee.Unbond((TDelegator)this, share, height);
unbondLockIn = unbondLockIn.LockIn(
fav, height, height + delegatee.UnbondingPeriod);

if (fav.Sign > 0)
{
unbondLockIn = unbondLockIn.LockIn(
fav, height, height + delegatee.UnbondingPeriod);
AddUnbondingRef(delegatee, UnbondingFactory.ToReference(unbondLockIn));
Repository.SetUnbondLockIn(unbondLockIn);
}

if (Repository.GetBond(delegatee, Address).Share.IsZero)
{
Metadata.RemoveDelegatee(delegatee.Address);
}

AddUnbondingRef(delegatee, UnbondingFactory.ToReference(unbondLockIn));

Repository.SetUnbondLockIn(unbondLockIn);
Repository.SetDelegator((TDelegator)this);
}

Expand Down

0 comments on commit 3bc8409

Please sign in to comment.