mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
44a90a8ef9
* Add earn adapter * Add earn adapter to list * Update test var
49 lines
1.0 KiB
Go
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
|
|
}
|