-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix * migrate script * update script * update
- Loading branch information
1 parent
e0da1dc
commit 04d1d41
Showing
3 changed files
with
31 additions
and
5 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
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,29 @@ | ||
package migrations | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/leveragelp/types" | ||
) | ||
|
||
func (m Migrator) V6Migration(ctx sdk.Context) error { | ||
pools := m.keeper.GetAllPools(ctx) | ||
// Reset pools | ||
for _, pool := range pools { | ||
pool.LeveragedLpAmount = sdk.NewInt(0) | ||
m.keeper.SetPool(ctx, pool) | ||
} | ||
// Traverse positions and update lp amount and health, as there are few positions, haven't optimized it much | ||
positions := m.keeper.GetAllPositions(ctx) | ||
for _, position := range positions { | ||
// Retrieve Pool | ||
pool, found := m.keeper.GetPool(ctx, position.AmmPoolId) | ||
if !found { | ||
return errorsmod.Wrap(types.ErrInvalidBorrowingAsset, "invalid pool id") | ||
} | ||
pool.LeveragedLpAmount = pool.LeveragedLpAmount.Add(position.LeveragedLpAmount) | ||
pool.Health = m.keeper.CalculatePoolHealth(ctx, &pool) | ||
m.keeper.SetPool(ctx, pool) | ||
} | ||
return 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