mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
Hard Audit: refresh borrow/deposit after syncing (#824)
* refresh borrow/deposit after syncing * revisions
This commit is contained in:
parent
a5b72363d0
commit
15da55b451
@ -20,6 +20,9 @@ func (k Keeper) Repay(ctx sdk.Context, sender, owner sdk.AccAddress, coins sdk.C
|
||||
// Sync borrow interest so loan is up-to-date
|
||||
k.SyncBorrowInterest(ctx, owner)
|
||||
|
||||
// Refresh borrow after syncing interest
|
||||
borrow, _ = k.GetBorrow(ctx, owner)
|
||||
|
||||
// Validate that sender holds coins for repayment
|
||||
err := k.ValidateRepay(ctx, sender, owner, coins)
|
||||
if err != nil {
|
||||
|
@ -9,20 +9,25 @@ import (
|
||||
|
||||
// Withdraw returns some or all of a deposit back to original depositor
|
||||
func (k Keeper) Withdraw(ctx sdk.Context, depositor sdk.AccAddress, coins sdk.Coins) error {
|
||||
deposit, found := k.GetDeposit(ctx, depositor)
|
||||
// Call incentive hooks
|
||||
existingDeposit, found := k.GetDeposit(ctx, depositor)
|
||||
if !found {
|
||||
return sdkerrors.Wrapf(types.ErrDepositNotFound, "no deposit found for %s", depositor)
|
||||
}
|
||||
// Call incentive hooks
|
||||
k.BeforeDepositModified(ctx, deposit)
|
||||
k.BeforeDepositModified(ctx, existingDeposit)
|
||||
|
||||
existingBorrow, hasExistingBorrow := k.GetBorrow(ctx, depositor)
|
||||
if hasExistingBorrow {
|
||||
k.BeforeBorrowModified(ctx, existingBorrow)
|
||||
}
|
||||
|
||||
// Sync interest
|
||||
k.SyncBorrowInterest(ctx, depositor)
|
||||
k.SyncSupplyInterest(ctx, depositor)
|
||||
|
||||
// Refresh Deposit after syncing interest
|
||||
deposit, _ := k.GetDeposit(ctx, depositor)
|
||||
|
||||
amount, err := k.CalculateWithdrawAmount(deposit.Amount, coins)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Loading…
Reference in New Issue
Block a user