mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 18:15:19 +00:00
1442deb3dc
* basic borrow types * borrow keeper scaffolding * borrow limits param * integrate pricefeed keeper * msg handling and querier * borrow user validation * update migration scripts for compile * borrows querier, fixes * add money market param * add spot market ID to params, refactor pricefeed * working bnb -> ukava borrows * refactor to getAssetPrice * conversion_factor param, refactor validateBorrow() * address misc revisions * remove validation code * add borrow test * update test params * single borrow with sdk.Coins per user * fix harvest test * removed legacy commented out code * address minor revisions
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
|
|
}
|