Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(CL/gamm): create CFMMPoolI interface, refactor PoolI (merge 4 - state breaking) #3560

Merged
merged 12 commits into from
Dec 5, 2022
2 changes: 1 addition & 1 deletion app/apptesting/gamm.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (s *KeeperTestHelper) RunBasicJoin(poolId uint64) {
s.Require().NoError(err)
}

func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, pool gammtypes.PoolI, targetSpotPrice sdk.Dec, baseDenom, quoteDenom string) (amountTrade sdk.Dec) {
func (s *KeeperTestHelper) CalcAmoutOfTokenToGetTargetPrice(ctx sdk.Context, pool gammtypes.CFMMPoolI, targetSpotPrice sdk.Dec, baseDenom, quoteDenom string) (amountTrade sdk.Dec) {
blPool, ok := pool.(*balancer.Pool)
s.Require().True(ok)
quoteAsset, _ := blPool.GetPoolAsset(quoteDenom)
Expand Down
4 changes: 2 additions & 2 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, re
}

// SetupGammPoolsWithBondDenomMultiplier uses given multipliers to set initial pool supply of bond denom.
func (s *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []sdk.Dec) []gammtypes.PoolI {
func (s *KeeperTestHelper) SetupGammPoolsWithBondDenomMultiplier(multipliers []sdk.Dec) []gammtypes.CFMMPoolI {
bondDenom := s.App.StakingKeeper.BondDenom(s.Ctx)
// TODO: use sdk crypto instead of tendermint to generate address
acc1 := sdk.AccAddress(ed25519.GenPrivKey().PubKey().Address().Bytes())

params := s.App.GAMMKeeper.GetParams(s.Ctx)

pools := []gammtypes.PoolI{}
pools := []gammtypes.CFMMPoolI{}
for index, multiplier := range multipliers {
token := fmt.Sprintf("token%d", index)
uosmoAmount := gammtypes.InitPoolSharesSupply.ToDec().Mul(multiplier).RoundInt()
Expand Down
8 changes: 4 additions & 4 deletions cmd/osmosisd/cmd/balances_from_state_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func newDerivedAccount(address string) DerivedAccount {
}

// underlyingCoins returns liquidity pool's underlying coin balances.
func underlyingCoins(originCoins sdk.Coins, pools map[string]gammtypes.PoolI) sdk.Coins {
func underlyingCoins(originCoins sdk.Coins, pools map[string]gammtypes.CFMMPoolI) sdk.Coins {
balances := sdk.Coins{}
convertAgain := false
for _, coin := range originCoins {
Expand Down Expand Up @@ -85,7 +85,7 @@ func underlyingCoins(originCoins sdk.Coins, pools map[string]gammtypes.PoolI) sd
// TODO: Make a separate type for this.
func underlyingCoinsForSelectPools(
originCoins sdk.Coins,
pools map[string]gammtypes.PoolI,
pools map[string]gammtypes.CFMMPoolI,
selectPoolIDs []uint64,
) map[uint64]sdk.Coins {
balancesByPool := make(map[uint64]sdk.Coins)
Expand Down Expand Up @@ -263,9 +263,9 @@ Example:
}

// collect gamm pools
pools := make(map[string]gammtypes.PoolI)
pools := make(map[string]gammtypes.CFMMPoolI)
for _, any := range gammGenesis.Pools {
var pool gammtypes.PoolI
var pool gammtypes.CFMMPoolI
err := clientCtx.InterfaceRegistry.UnpackAny(any, &pool)
if err != nil {
panic(err)
Expand Down
319 changes: 167 additions & 152 deletions tests/mocks/mock_pool.go → tests/mocks/cfmm_pool.go

Large diffs are not rendered by default.

311 changes: 311 additions & 0 deletions tests/mocks/cl_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion x/gamm/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v13/x/gamm/types"
swaproutertypes "github.com/osmosis-labs/osmosis/v13/x/swaprouter/types"
)

// SetParams sets the total set of params.
Expand All @@ -12,7 +13,7 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
}

// SetPool adds an existing pool to the keeper store.
func (k Keeper) SetPool(ctx sdk.Context, pool types.PoolI) error {
func (k Keeper) SetPool(ctx sdk.Context, pool swaproutertypes.PoolI) error {
return k.setPool(ctx, pool)
}

Expand All @@ -28,3 +29,12 @@ func (k Keeper) GetOsmoRoutedMultihopTotalSwapFee(ctx sdk.Context, route types.M
totalPathSwapFee sdk.Dec, sumOfSwapFees sdk.Dec, err error) {
return k.getOsmoRoutedMultihopTotalSwapFee(ctx, route)
}

func ConvertToCFMMPool(pool swaproutertypes.PoolI) (types.CFMMPoolI, error) {
return convertToCFMMPool(pool)
}

func (k Keeper) UnmarshalPoolLegacy(bz []byte) (swaproutertypes.PoolI, error) {
var acc swaproutertypes.PoolI
return acc, k.cdc.UnmarshalInterface(bz, &acc)
}
Loading