0g-chain/x/incentive/keeper/adapters/swap/adapter.go
Derrick Lee f52a581ea9
Add GetSynchronizedClaim and swap adapter (#1386)
* Add source adapters to keeper, implement GetSynchronizedClaim

* Iterate acc shares sorted

* Add swap adapter, update tests to use swap claimtype

* Add swap adapter test

* Add tests for non-empty pools

* Iterate over source ids instead of sorted keys
2022-11-14 17:55:10 -08:00

47 lines
885 B
Go

package swap
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/kava-labs/kava/x/incentive/types"
)
var _ types.SourceAdapter = SourceAdapter{}
type SourceAdapter struct {
keeper types.SwapKeeper
}
func NewSourceAdapter(keeper types.SwapKeeper) SourceAdapter {
return SourceAdapter{
keeper: keeper,
}
}
func (f SourceAdapter) TotalSharesBySource(ctx sdk.Context, sourceID string) sdk.Dec {
shares, found := f.keeper.GetPoolShares(ctx, sourceID)
if !found {
shares = sdk.ZeroInt()
}
return shares.ToDec()
}
func (f SourceAdapter) OwnerSharesBySource(
ctx sdk.Context,
owner sdk.AccAddress,
sourceIDs []string,
) map[string]sdk.Dec {
shares := make(map[string]sdk.Dec)
for _, id := range sourceIDs {
s, found := f.keeper.GetDepositorSharesAmount(ctx, owner, id)
if !found {
s = sdk.ZeroInt()
}
shares[id] = s.ToDec()
}
return shares
}