mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25: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
|
// Sync borrow interest so loan is up-to-date
|
||||||
k.SyncBorrowInterest(ctx, owner)
|
k.SyncBorrowInterest(ctx, owner)
|
||||||
|
|
||||||
|
// Refresh borrow after syncing interest
|
||||||
|
borrow, _ = k.GetBorrow(ctx, owner)
|
||||||
|
|
||||||
// Validate that sender holds coins for repayment
|
// Validate that sender holds coins for repayment
|
||||||
err := k.ValidateRepay(ctx, sender, owner, coins)
|
err := k.ValidateRepay(ctx, sender, owner, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -9,20 +9,25 @@ import (
|
|||||||
|
|
||||||
// Withdraw returns some or all of a deposit back to original depositor
|
// 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 {
|
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 {
|
if !found {
|
||||||
return sdkerrors.Wrapf(types.ErrDepositNotFound, "no deposit found for %s", depositor)
|
return sdkerrors.Wrapf(types.ErrDepositNotFound, "no deposit found for %s", depositor)
|
||||||
}
|
}
|
||||||
// Call incentive hooks
|
k.BeforeDepositModified(ctx, existingDeposit)
|
||||||
k.BeforeDepositModified(ctx, deposit)
|
|
||||||
existingBorrow, hasExistingBorrow := k.GetBorrow(ctx, depositor)
|
existingBorrow, hasExistingBorrow := k.GetBorrow(ctx, depositor)
|
||||||
if hasExistingBorrow {
|
if hasExistingBorrow {
|
||||||
k.BeforeBorrowModified(ctx, existingBorrow)
|
k.BeforeBorrowModified(ctx, existingBorrow)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sync interest
|
||||||
k.SyncBorrowInterest(ctx, depositor)
|
k.SyncBorrowInterest(ctx, depositor)
|
||||||
k.SyncSupplyInterest(ctx, depositor)
|
k.SyncSupplyInterest(ctx, depositor)
|
||||||
|
|
||||||
|
// Refresh Deposit after syncing interest
|
||||||
|
deposit, _ := k.GetDeposit(ctx, depositor)
|
||||||
|
|
||||||
amount, err := k.CalculateWithdrawAmount(deposit.Amount, coins)
|
amount, err := k.CalculateWithdrawAmount(deposit.Amount, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user