0g-chain/x/incentive/keeper/adapters/earn/adapter.go
Derrick Lee 44a90a8ef9
Add base earn incentive accumulator (#1393)
* Add earn adapter

* Add earn adapter to list

* Update test var
2022-11-29 14:12:08 -08:00

49 lines
1.0 KiB
Go

package earn
import (
sdk "github.com/cosmos/cosmos-sdk/types"
earntypes "github.com/kava-labs/kava/x/earn/types"
"github.com/kava-labs/kava/x/incentive/types"
)
var _ types.SourceAdapter = SourceAdapter{}
type SourceAdapter struct {
keeper types.EarnKeeper
}
func NewSourceAdapter(keeper types.EarnKeeper) SourceAdapter {
return SourceAdapter{
keeper: keeper,
}
}
func (f SourceAdapter) TotalSharesBySource(ctx sdk.Context, sourceID string) sdk.Dec {
vaultShares, found := f.keeper.GetVaultTotalShares(ctx, sourceID)
if !found {
return sdk.ZeroDec()
}
return vaultShares.Amount
}
func (f SourceAdapter) OwnerSharesBySource(
ctx sdk.Context,
owner sdk.AccAddress,
sourceIDs []string,
) map[string]sdk.Dec {
accountShares, found := f.keeper.GetVaultAccountShares(ctx, owner)
if !found {
accountShares = earntypes.VaultShares{}
}
shares := make(map[string]sdk.Dec)
for _, id := range sourceIDs {
// Sets shares to zero if not found
shares[id] = accountShares.AmountOf(id)
}
return shares
}