Skip to content

Commit

Permalink
Resolve existing unit tests to release a new version
Browse files Browse the repository at this point in the history
  • Loading branch information
kiragpg committed Nov 15, 2023
1 parent 54ce5e6 commit d2dce20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion x/basket/keeper/basket.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ func (k Keeper) EditBasket(ctx sdk.Context, basket types.Basket) error {
}

usedDenom := make(map[string]bool)
rates, _ := basket.RatesAndIndexes()
basketDenomSupplyEst := sdk.ZeroDec()
for index, token := range basket.Tokens {
// ensure tokens amount is derivated from previous by denom
basket.Tokens[index].Amount = prevAmounts[token.Denom]
if !prevAmounts[token.Denom].IsNil() {
basket.Tokens[index].Amount = prevAmounts[token.Denom]
} else {
basket.Tokens[index].Amount = sdk.ZeroInt()
}

// validate denom for the token
if err := sdk.ValidateDenom(token.Denom); err != nil {
Expand All @@ -140,6 +146,13 @@ func (k Keeper) EditBasket(ctx sdk.Context, basket types.Basket) error {
return types.ErrDuplicateDenomExistsOnTokens
}
usedDenom[token.Denom] = true
basketDenomSupplyEst = basketDenomSupplyEst.
Add(basket.Tokens[index].Amount.ToLegacyDec().Mul(rates[token.Denom]))
}

supply := k.bk.GetSupply(ctx, basket.GetBasketDenom())
if supply.Amount.GT(basketDenomSupplyEst.TruncateInt()) {
return types.ErrBasketDenomSupplyTooBig
}

k.SetBasket(ctx, basket)
Expand Down
1 change: 1 addition & 0 deletions x/basket/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ var (
ErrDuplicateDenomExistsOnTokens = errors.Register(ModuleName, 20, "duplicated denom exists on tokens list")
ErrTokenExceedingCap = errors.Register(ModuleName, 21, "token exceeding cap")
ErrEmptyUnderlyingTokens = errors.Register(ModuleName, 22, "empty underlying tokens")
ErrBasketDenomSupplyTooBig = errors.Register(ModuleName, 23, "basket denom supply too big compared to underlying tokens")
)

0 comments on commit d2dce20

Please sign in to comment.