2021-01-18 19:12:37 +00:00
|
|
|
package keeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
cdptypes "github.com/kava-labs/kava/x/cdp/types"
|
2021-01-21 13:52:09 +00:00
|
|
|
hardtypes "github.com/kava-labs/kava/x/hard/types"
|
2021-01-18 19:12:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Hooks wrapper struct for hooks
|
|
|
|
type Hooks struct {
|
|
|
|
k Keeper
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ cdptypes.CDPHooks = Hooks{}
|
2021-01-21 13:52:09 +00:00
|
|
|
var _ hardtypes.HARDHooks = Hooks{}
|
2021-01-18 19:12:37 +00:00
|
|
|
|
|
|
|
// Hooks create new incentive hooks
|
|
|
|
func (k Keeper) Hooks() Hooks { return Hooks{k} }
|
|
|
|
|
|
|
|
// AfterCDPCreated function that runs after a cdp is created
|
|
|
|
func (h Hooks) AfterCDPCreated(ctx sdk.Context, cdp cdptypes.CDP) {
|
2021-01-21 13:52:09 +00:00
|
|
|
h.k.InitializeUSDXMintingClaim(ctx, cdp)
|
2021-01-18 19:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// BeforeCDPModified function that runs before a cdp is modified
|
|
|
|
// note that this is called immediately after interest is synchronized, and so could potentially
|
|
|
|
// be called AfterCDPInterestUpdated or something like that, if we we're to expand the scope of cdp hooks
|
|
|
|
func (h Hooks) BeforeCDPModified(ctx sdk.Context, cdp cdptypes.CDP) {
|
2021-01-21 13:52:09 +00:00
|
|
|
h.k.SynchronizeUSDXMintingReward(ctx, cdp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AfterDepositCreated function that runs after a deposit is created
|
|
|
|
func (h Hooks) AfterDepositCreated(ctx sdk.Context, deposit hardtypes.Deposit) {
|
|
|
|
h.k.InitializeHardSupplyReward(ctx, deposit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BeforeDepositModified function that runs before a deposit is modified
|
|
|
|
func (h Hooks) BeforeDepositModified(ctx sdk.Context, deposit hardtypes.Deposit) {
|
|
|
|
h.k.SynchronizeHardSupplyReward(ctx, deposit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AfterDepositModified function that runs after a deposit is modified
|
|
|
|
func (h Hooks) AfterDepositModified(ctx sdk.Context, deposit hardtypes.Deposit) {
|
|
|
|
h.k.UpdateHardSupplyIndexDenoms(ctx, deposit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AfterBorrowCreated function that runs after a borrow is created
|
|
|
|
func (h Hooks) AfterBorrowCreated(ctx sdk.Context, borrow hardtypes.Borrow) {
|
|
|
|
h.k.InitializeHardBorrowReward(ctx, borrow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// BeforeBorrowModified function that runs before a borrow is modified
|
|
|
|
func (h Hooks) BeforeBorrowModified(ctx sdk.Context, borrow hardtypes.Borrow) {
|
|
|
|
h.k.SynchronizeHardBorrowReward(ctx, borrow)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AfterBorrowModified function that runs after a borrow is modified
|
|
|
|
func (h Hooks) AfterBorrowModified(ctx sdk.Context, borrow hardtypes.Borrow) {
|
|
|
|
h.k.UpdateHardBorrowIndexDenoms(ctx, borrow)
|
2021-01-18 19:12:37 +00:00
|
|
|
}
|