Skip to content

Commit

Permalink
feat: complete unbond on delete
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Dec 22, 2023
1 parent fc330c5 commit 7a7de12
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions x/alliance/keeper/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,38 @@ import (
"github.com/terra-money/alliance/x/alliance/types"
)

// BeginUnbondingsForDissolvingAlliances got thought all alliances, check if there is any alliance winding down
// and if so, start the unbonding process for all delegations
// BeginUnbondingsForDissolvingAlliances iterates thought all alliances,
// if there is any alliance being dissolved
// - when that specific alliance is being disslved it will first check if the
// AllianceDissolutionTime has been set and if it is in the past compared to
// the current block time the alliance will be deleted.
// - if the alliance is not initalized and is being dissolved it means that

Check failure on line 16 in x/alliance/keeper/unbonding.go

View workflow job for this annotation

GitHub Actions / lint

`initalized` is a misspelling of `initialized` (misspell)
// all alliance unbondings have been executed and no further comput needs to be done.
// - else iterate the delegations and begin the unbonding for all assets,
// setting always the last unbonding period for the latest unbonding executed
// as the AllianceDissolutionTime, so that we can keep track of when to delete the alliance.
func (k Keeper) BeginUnbondingsForDissolvingAlliances(ctx sdk.Context) (err error) {
assets := k.GetAllAssets(ctx)

amountOfUndelegationsExecuted := 0

for _, asset := range assets {
if !asset.IsDissolving {
continue
}
assetDereference := *asset
if asset.AllianceDissolutionTime.Before(ctx.BlockTime()) {
err := k.DeleteAsset(ctx, assetDereference)
if err != nil {
return err
amountOfUndelegationsExecuted := 0

if assetDereference.AllianceDissolutionTime != nil {
if ctx.BlockTime().After(*assetDereference.AllianceDissolutionTime) {
err := k.DeleteAsset(ctx, assetDereference)
if err != nil {
return err
}
continue
}
break
}

if !assetDereference.IsInitialized && assetDereference.IsDissolving {
continue
}

k.IterateDelegations(ctx, func(delegation types.Delegation) (stop bool) {
Expand All @@ -35,7 +49,7 @@ func (k Keeper) BeginUnbondingsForDissolvingAlliances(ctx sdk.Context) (err erro
return true
}

if delegation.Denom == asset.Denom {
if delegation.Denom == assetDereference.Denom {
validator, fail := k.GetAllianceValidator(ctx, sdk.ValAddress(delegation.DelegatorAddress))
if err != nil {
err = fail
Expand All @@ -60,6 +74,11 @@ func (k Keeper) BeginUnbondingsForDissolvingAlliances(ctx sdk.Context) (err erro
if err != nil {
return err
}

if amountOfUndelegationsExecuted == 0 {
assetDereference.IsInitialized = false
k.SetAsset(ctx, assetDereference)
}
}

return err
Expand Down

0 comments on commit 7a7de12

Please sign in to comment.