Created
March 5, 2021 20:26
-
-
Save karzak/aeee0e02831d912398e0470aeb15d233 to your computer and use it in GitHub Desktop.
Hard Audit PR 843
This file contains hidden or 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
func (k Keeper) DecrementBorrowedCoins(ctx sdk.Context, coins sdk.Coins) error { | |
borrowedCoins, found := k.GetBorrowedCoins(ctx) | |
if !found { | |
return sdkerrors.Wrapf(types.ErrBorrowedCoinsNotFound, "cannot repay coins if no coins are currently borrowed") | |
} | |
updatedBorrowedCoins := sdk.NewCoins() | |
for _, coin := range coins { | |
// If amount is greater than total borrowed amount due to rounding, set total borrowed amount to 0 | |
// by skipping the coin such that it's not included in the updatedBorrowedCoins object | |
if coin.Amount.GTE(borrowedCoins.AmountOf(coin.Denom)) { | |
continue | |
} | |
updatedBorrowCoin := sdk.NewCoin(coin.Denom, borrowedCoins.AmountOf(coin.Denom).Sub(coin.Amount)) | |
updatedBorrowedCoins = updatedBorrowedCoins.Add(updatedBorrowCoin) | |
} | |
k.SetBorrowedCoins(ctx, updatedBorrowedCoins) | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment