Skip to content

Commit

Permalink
rename to ToTokens
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-zaremba committed Aug 2, 2023
1 parent d6472ff commit dc0d4db
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion x/leverage/keeper/collateral.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (k Keeper) ModuleMaxWithdraw(ctx sdk.Context, spendableUTokens sdk.Coin) (s

// Get module collateral for the uDenom
totalCollateral := k.GetTotalCollateral(ctx, spendableUTokens.Denom)
totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral))
totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral))
if err != nil {
return sdk.ZeroInt(), err
}
Expand Down
13 changes: 5 additions & 8 deletions x/leverage/keeper/exchange_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"github.com/umee-network/umee/v5/x/leverage/types"
)

// ToUToken converts a token to uTokens at the current uToken exchange rate.
// This is the uToken amount a user would receive when supplying the token.
// ToUToken returns uToken in the amount a user would receive when supplying the token.
// Returns error if the input is not a Token.
func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) {
if err := token.Validate(); err != nil {
Expand All @@ -24,8 +23,7 @@ func (k Keeper) ToUToken(ctx sdk.Context, token sdk.Coin) (sdk.Coin, error) {
return sdk.NewCoin(uTokenDenom, uTokenAmount), nil
}

// ToToken converts a uToken to tokens at the current uToken exchange rate.
// This is the token amount a user would receive when withdrawing the uToken.
// ToToken returns Token in the amount a user would receive when withdrawing the uToken.
// Returns error if the input is not a uToken.
func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) {
if err := uToken.Validate(); err != nil {
Expand All @@ -43,11 +41,10 @@ func (k Keeper) ToToken(ctx sdk.Context, uToken sdk.Coin) (sdk.Coin, error) {
return sdk.NewCoin(tokenDenom, tokenAmount), nil
}

// ToToken converts an sdk.Coins containing uTokens to tokens using uToken exchange rates.
// These are the token amounts a user would receive when withdrawing the uTokens.
// ToToken returns list of Tokens in the amount a user would receive when withdrawing the
// list of uTokens.
// Returns error if any of the inputs are uTokens.
// tokens.
func (k Keeper) Tokens2uTokensRate(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) {
func (k Keeper) ToTokens(ctx sdk.Context, uTokens sdk.Coins) (sdk.Coins, error) {
if err := uTokens.Validate(); err != nil {
return sdk.Coins{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/limits.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (k Keeper) ModuleAvailableLiquidity(ctx sdk.Context, denom string) (sdkmath

// Get module collateral for the associated uToken
totalCollateral := k.GetTotalCollateral(ctx, types.ToUTokenDenom(denom))
totalTokenCollateral, err := k.Tokens2uTokensRate(ctx, sdk.NewCoins(totalCollateral))
totalTokenCollateral, err := k.ToTokens(ctx, sdk.NewCoins(totalCollateral))
if err != nil {
return sdkmath.Int{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion x/leverage/keeper/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (k Keeper) GetAllSupplied(ctx sdk.Context, supplierAddr sdk.AccAddress) (sd
}

// convert the sum of found uTokens to base tokens
return k.Tokens2uTokensRate(ctx, collateral.Add(uTokens...))
return k.ToTokens(ctx, collateral.Add(uTokens...))
}

// GetTotalSupply returns the total supplied by all suppliers in a given denom,
Expand Down

0 comments on commit dc0d4db

Please sign in to comment.