|
1 | 1 | package keeper |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + sdkmath "cosmossdk.io/math" |
4 | 5 | "cosmossdk.io/store/prefix" |
5 | 6 | storetypes "cosmossdk.io/store/types" |
6 | 7 | "github.com/cosmos/cosmos-sdk/runtime" |
@@ -56,3 +57,34 @@ func (k Keeper) GetPool(ctx sdk.Context, poolId uint64) (val types.Pool, found b |
56 | 57 | k.cdc.MustUnmarshal(b, &val) |
57 | 58 | return val, true |
58 | 59 | } |
| 60 | + |
| 61 | +func (k Keeper) SetLeveragedAmount(ctx sdk.Context) { |
| 62 | + pools := k.GetAllPools(ctx) |
| 63 | + for _, pool := range pools { |
| 64 | + ammPool, found := k.amm.GetPool(ctx, pool.AmmPoolId) |
| 65 | + if !found { |
| 66 | + continue |
| 67 | + } |
| 68 | + for _, asset := range ammPool.PoolAssets { |
| 69 | + pool.AssetLeverageAmounts = append(pool.AssetLeverageAmounts, &types.AssetLeverageAmount{ |
| 70 | + Denom: asset.Token.Denom, |
| 71 | + LeveragedAmount: sdkmath.ZeroInt(), |
| 72 | + }) |
| 73 | + } |
| 74 | + k.SetPool(ctx, pool) |
| 75 | + } |
| 76 | + |
| 77 | + iterator := k.GetPositionIterator(ctx) |
| 78 | + defer iterator.Close() |
| 79 | + |
| 80 | + for ; iterator.Valid(); iterator.Next() { |
| 81 | + var position types.Position |
| 82 | + k.cdc.MustUnmarshal(iterator.Value(), &position) |
| 83 | + pool, found := k.GetPool(ctx, position.AmmPoolId) |
| 84 | + if !found { |
| 85 | + continue |
| 86 | + } |
| 87 | + pool.UpdateAssetLeveragedAmount(ctx, position.Collateral.Denom, position.LeveragedLpAmount, true) |
| 88 | + k.SetPool(ctx, pool) |
| 89 | + } |
| 90 | +} |
0 commit comments