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

add scaling factors to stableswap pool creation #2222

Merged
merged 12 commits into from
Aug 7, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking Changes

* [#2222](https://github.com/osmosis-labs/osmosis/pull/2222) Add scaling factors to MsgCreateStableswapPool
* [#1889](https://github.com/osmosis-labs/osmosis/pull/1825) Add proto responses to gamm LP messages:
* MsgJoinPoolResponse: share_out_amount and token_in fields
* MsgExitPoolResponse: token_out field
Expand Down
7 changes: 6 additions & 1 deletion proto/osmosis/gamm/pool-models/stableswap/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ message MsgCreateStableswapPool {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

string future_pool_governor = 4
repeated uint64 scaling_factors = 4 [
(gogoproto.moretags) = "yaml:\"stableswap_scaling_factor\"",
(gogoproto.nullable) = false
];

string future_pool_governor = 5
[ (gogoproto.moretags) = "yaml:\"future_pool_governor\"" ];
}

Expand Down
2 changes: 2 additions & 0 deletions x/gamm/pool-models/internal/cfmm_common/lp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestCalcExitPool(t *testing.T) {
1,
stableswap.PoolParams{ExitFee: sdk.ZeroDec()},
twoStablePoolAssets,
[]uint64{1, 1},
"",
)
require.NoError(t, err)
Expand All @@ -62,6 +63,7 @@ func TestCalcExitPool(t *testing.T) {
1,
stableswap.PoolParams{ExitFee: sdk.MustNewDecFromStr("0.0001")},
twoStablePoolAssets,
[]uint64{1, 1},
"",
)
require.NoError(t, err)
Expand Down
9 changes: 8 additions & 1 deletion x/gamm/pool-models/stableswap/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ func NewMsgCreateStableswapPool(
sender sdk.AccAddress,
poolParams PoolParams,
initialLiquidity sdk.Coins,
scalingFactors []uint64,
futurePoolGovernor string,
) MsgCreateStableswapPool {
return MsgCreateStableswapPool{
Sender: sender.String(),
PoolParams: &poolParams,
InitialPoolLiquidity: initialLiquidity,
ScalingFactors: scalingFactors,
FuturePoolGovernor: futurePoolGovernor,
}
}
Expand All @@ -51,6 +53,11 @@ func (msg MsgCreateStableswapPool) ValidateBasic() error {
} else if len(msg.InitialPoolLiquidity) > 2 {
return types.ErrTooManyPoolAssets
}
if len(msg.ScalingFactors) != 2 {
return types.ErrInvalidScalingFactors
} else if msg.ScalingFactors[0] == 0 || msg.ScalingFactors[1] == 0 {
return types.ErrInvalidScalingFactors
}
catShaark marked this conversation as resolved.
Show resolved Hide resolved

// validation for future owner
if err = types.ValidateFutureGovernor(msg.FuturePoolGovernor); err != nil {
Expand Down Expand Up @@ -91,7 +98,7 @@ func (msg MsgCreateStableswapPool) InitialLiquidity() sdk.Coins {
}

func (msg MsgCreateStableswapPool) CreatePool(ctx sdk.Context, poolId uint64) (types.PoolI, error) {
stableswapPool, err := NewStableswapPool(poolId, *msg.PoolParams, msg.InitialPoolLiquidity, msg.FuturePoolGovernor)
stableswapPool, err := NewStableswapPool(poolId, *msg.PoolParams, msg.InitialPoolLiquidity, msg.ScalingFactors, msg.FuturePoolGovernor)
if err != nil {
return nil, err
}
Expand Down
25 changes: 25 additions & 0 deletions x/gamm/pool-models/stableswap/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestMsgCreateStableswapPool(t *testing.T) {
Sender: addr1,
PoolParams: poolParams,
InitialPoolLiquidity: testPoolAsset,
ScalingFactors: []uint64{1, 1},
FuturePoolGovernor: "",
}

Expand Down Expand Up @@ -112,6 +113,30 @@ func TestMsgCreateStableswapPool(t *testing.T) {
}),
expectPass: false,
},
{
name: "nil scaling factors",
msg: createMsg(func(msg MsgCreateStableswapPool) MsgCreateStableswapPool {
msg.ScalingFactors = nil
return msg
}),
expectPass: false,
},
{
name: "scaling factors with invalid lenght",
msg: createMsg(func(msg MsgCreateStableswapPool) MsgCreateStableswapPool {
msg.ScalingFactors = []uint64{1, 2, 3}
return msg
}),
expectPass: false,
},
{
name: "scaling factors has zero value",
msg: createMsg(func(msg MsgCreateStableswapPool) MsgCreateStableswapPool {
msg.ScalingFactors = []uint64{0, 1}
return msg
}),
expectPass: false,
},
{
name: "invalid governor",
msg: createMsg(func(msg MsgCreateStableswapPool) MsgCreateStableswapPool {
Expand Down
3 changes: 2 additions & 1 deletion x/gamm/pool-models/stableswap/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ var _ types.PoolI = &Pool{}
// * len(initialLiquidity) = 2
// * FutureGovernor is valid
// * poolID doesn't already exist
func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLiquidity sdk.Coins, futureGovernor string) (Pool, error) {
func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLiquidity sdk.Coins, scalingFactors []uint64, futureGovernor string) (Pool, error) {
pool := Pool{
Address: types.NewPoolAddress(poolId).String(),
Id: poolId,
PoolParams: stableswapPoolParams,
TotalShares: sdk.NewCoin(types.GetPoolShareDenom(poolId), types.InitPoolSharesSupply),
PoolLiquidity: initialLiquidity,
ScalingFactor: scalingFactors,
FuturePoolGovernor: futureGovernor,
}

Expand Down
205 changes: 157 additions & 48 deletions x/gamm/pool-models/stableswap/tx.pb.go

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

2 changes: 1 addition & 1 deletion x/gamm/pool-models/stableswap/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func createTestPool(t *testing.T, poolLiquidity sdk.Coins, swapFee, exitFee sdk.
pool, err := NewStableswapPool(1, PoolParams{
SwapFee: swapFee,
ExitFee: exitFee,
}, poolLiquidity, "")
}, poolLiquidity, []uint64{1, 1}, "")

require.NoError(t, err)

Expand Down
Loading