Skip to content

Instantly share code, notes, and snippets.

@karzak
Created March 5, 2021 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karzak/aeee0e02831d912398e0470aeb15d233 to your computer and use it in GitHub Desktop.
Save karzak/aeee0e02831d912398e0470aeb15d233 to your computer and use it in GitHub Desktop.
Hard Audit PR 843
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