mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
35 lines
790 B
Go
35 lines
790 B
Go
|
package keeper
|
||
|
|
||
|
import (
|
||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||
|
|
||
|
"github.com/kava-labs/kava/x/harvest/types"
|
||
|
)
|
||
|
|
||
|
// Borrow funds
|
||
|
func (k Keeper) Borrow(ctx sdk.Context, borrower sdk.AccAddress, coins sdk.Coins) error {
|
||
|
err := k.supplyKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleAccountName, borrower, coins)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
borrow, found := k.GetBorrow(ctx, borrower)
|
||
|
if !found {
|
||
|
borrow = types.NewBorrow(borrower, coins)
|
||
|
} else {
|
||
|
borrow.Amount = borrow.Amount.Add(coins...)
|
||
|
}
|
||
|
|
||
|
k.SetBorrow(ctx, borrow)
|
||
|
|
||
|
ctx.EventManager().EmitEvent(
|
||
|
sdk.NewEvent(
|
||
|
types.EventTypeHarvestBorrow,
|
||
|
sdk.NewAttribute(types.AttributeKeyBorrower, borrow.Borrower.String()),
|
||
|
sdk.NewAttribute(types.AttributeKeyBorrowCoins, coins.String()),
|
||
|
),
|
||
|
)
|
||
|
|
||
|
return nil
|
||
|
}
|