mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-14 03:55:19 +00:00
f52a581ea9
* 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
47 lines
885 B
Go
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
|
|
}
|