Skip to content

Commit

Permalink
Merge branch 'main' into feat/add-arm-support
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored May 19, 2022
2 parents 70ef044 + 82e58f8 commit 06c5cd3
Show file tree
Hide file tree
Showing 10 changed files with 741 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ message Pool {
(gogoproto.moretags) = "yaml:\"stableswap_scaling_factor\"",
(gogoproto.nullable) = false
];
// scaling_factor_governor is the address can adjust pool scaling factors
string scaling_factor_governor = 8
[ (gogoproto.moretags) = "yaml:\"scaling_factor_governor\"" ];
}
16 changes: 16 additions & 0 deletions proto/osmosis/gamm/pool-models/stableswap/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ option go_package = "github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/stabl
service Msg {
rpc CreateStableswapPool(MsgCreateStableswapPool)
returns (MsgCreateStableswapPoolResponse);
rpc StableSwapAdjustScalingFactors(MsgStableSwapAdjustScalingFactors)
returns (MsgStableSwapAdjustScalingFactorsResponse);
}

message MsgCreateStableswapPool {
Expand All @@ -29,3 +31,17 @@ message MsgCreateStableswapPool {
message MsgCreateStableswapPoolResponse {
uint64 pool_id = 1 [ (gogoproto.customname) = "PoolID" ];
}

message MsgStableSwapAdjustScalingFactors {
// Sender must be the pool's scaling_factor_governor in order for the tx to succeed
string sender = 1
[ (gogoproto.moretags) = "yaml:\"sender\"" ];
uint64 pool_id = 2 [ (gogoproto.customname) = "PoolID" ];

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

message MsgStableSwapAdjustScalingFactorsResponse {}
10 changes: 10 additions & 0 deletions x/gamm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ func (server msgServer) CreateBalancerPool(goCtx context.Context, msg *balancer.
// return &stableswap.MsgCreateStableswapPoolResponse{PoolID: poolId}, nil
// }

// func (server msgServer) StableSwapAdjustScalingFactors(goCtx context.Context, msg *stableswap.MsgStableSwapAdjustScalingFactors) (*stableswap.MsgStableSwapAdjustScalingFactorsResponse, error) {
// ctx := sdk.UnwrapSDKContext(goCtx)

// if err := server.keeper.SetStableSwapScalingFactors(ctx, msg.ScalingFactors, msg.PoolID, msg.ScalingFactorGovernor); err != nil {
// return nil, err
// }

// return &stableswap.MsgStableSwapAdjustScalingFactorsResponse{}, nil
// }

func (server msgServer) CreatePool(goCtx context.Context, msg types.CreatePoolMsg) (poolId uint64, err error) {
ctx := sdk.UnwrapSDKContext(goCtx)

Expand Down
29 changes: 29 additions & 0 deletions x/gamm/keeper/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/v7/x/gamm/pool-models/stableswap"
"github.com/osmosis-labs/osmosis/v7/x/gamm/types"
)

Expand Down Expand Up @@ -224,3 +225,31 @@ func (k Keeper) GetNextPoolNumberAndIncrement(ctx sdk.Context) uint64 {
k.SetNextPoolNumber(ctx, poolNumber+1)
return poolNumber
}

// set ScalingFactors in stable stableswap pools
func (k *Keeper) SetStableSwapScalingFactors(ctx sdk.Context, scalingFactors []uint64, poolId uint64, scalingFactorGovernor string) error {
poolI, err := k.GetPoolAndPoke(ctx, poolId)
if err != nil {
return err
}

stableswapPool, ok := poolI.(*stableswap.Pool)
if !ok {
return types.ErrNotStableSwapPool
}

if scalingFactorGovernor != stableswapPool.ScalingFactorGovernor {
return types.ErrNotScalingFactorGovernor
}

if len(scalingFactors) != stableswapPool.PoolLiquidity.Len() {
return types.ErrInvalidStableswapScalingFactors
}

stableswapPool.ScalingFactor = scalingFactors

if err = k.SetPool(ctx, stableswapPool); err != nil {
return err
}
return nil
}
34 changes: 34 additions & 0 deletions x/gamm/keeper/pool_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,37 @@ func (suite *KeeperTestSuite) TestJoinSwapExactAmountInConsistency() {
})
}
}

// func (suite *KeeperTestSuite) TestSetStableSwapScalingFactors() {
// stableSwapPoolParams := stableswap.PoolParams{
// SwapFee: defaultSwapFee,
// ExitFee: defaultExitFee,
// }

// testPoolAsset := sdk.Coins{
// sdk.NewCoin("foo", sdk.NewInt(10000)),
// sdk.NewCoin("bar", sdk.NewInt(10000)),
// }

// suite.FundAcc(suite.TestAccs[0], defaultAcctFunds)

// testScalingFactors := []uint64{1, 1}

// msg := stableswap.NewMsgCreateStableswapPool(
// suite.TestAccs[0], stableSwapPoolParams, testPoolAsset, defaultFutureGovernor)
// poolID, err := suite.App.GAMMKeeper.CreatePool(suite.Ctx, msg)
// suite.Require().NoError(err)

// err = suite.App.GAMMKeeper.SetStableSwapScalingFactors(suite.Ctx, testScalingFactors, poolID, "")
// suite.Require().NoError(err)

// poolI, err := suite.App.GAMMKeeper.GetPoolAndPoke(suite.Ctx, poolID)
// suite.Require().NoError(err)

// poolScalingFactors := poolI.(*stableswap.Pool).GetScalingFactors()

// suite.Require().Equal(
// poolScalingFactors,
// testScalingFactors,
// )
// }
2 changes: 2 additions & 0 deletions x/gamm/pool-models/stableswap/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&Pool{}, "osmosis/gamm/StableswapPool", nil)
cdc.RegisterConcrete(&MsgCreateStableswapPool{}, "osmosis/gamm/create-stableswap-pool", nil)
cdc.RegisterConcrete(&MsgStableSwapAdjustScalingFactors{}, "osmosis/gamm/stableswap-adjust-scaling-factors", nil)
cdc.RegisterConcrete(&PoolParams{}, "osmosis/gamm/StableswapPoolParams", nil)
}

Expand All @@ -26,6 +27,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgCreateStableswapPool{},
&MsgStableSwapAdjustScalingFactors{},
)
msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}
Expand Down
47 changes: 46 additions & 1 deletion x/gamm/pool-models/stableswap/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

const (
TypeMsgCreateStableswapPool = "create_stableswap_pool"
TypeMsgCreateStableswapPool = "create_stableswap_pool"
TypeMsgStableSwapAdjustScalingFactors = "stable_swap_adjust_scaling_factors"
)

var (
Expand Down Expand Up @@ -97,3 +98,47 @@ func (msg MsgCreateStableswapPool) CreatePool(ctx sdk.Context, poolId uint64) (t

return &stableswapPool, nil
}

var _ sdk.Msg = &MsgStableSwapAdjustScalingFactors{}

// Implement sdk.Msg
func NewMsgStableSwapAdjustScalingFactors(
sender string,
poolID uint64,
) MsgStableSwapAdjustScalingFactors {
return MsgStableSwapAdjustScalingFactors{
ScalingFactorGovernor: sender,
PoolID: poolID,
}
}

func (msg MsgStableSwapAdjustScalingFactors) Route() string {
return types.RouterKey
}

func (msg MsgStableSwapAdjustScalingFactors) Type() string { return TypeMsgCreateStableswapPool }
func (msg MsgStableSwapAdjustScalingFactors) ValidateBasic() error {
if msg.ScalingFactorGovernor == "" {
return nil
}

_, err := sdk.AccAddressFromBech32(msg.ScalingFactorGovernor)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "Invalid sender address (%s)", err)
}

return nil
}

func (msg MsgStableSwapAdjustScalingFactors) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgStableSwapAdjustScalingFactors) GetSigners() []sdk.AccAddress {
scalingFactorGovernor, err := sdk.AccAddressFromBech32(msg.ScalingFactorGovernor)
if err != nil {
panic(err)
}

return []sdk.AccAddress{scalingFactorGovernor}
}
124 changes: 85 additions & 39 deletions x/gamm/pool-models/stableswap/stableswap_pool.pb.go

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

Loading

0 comments on commit 06c5cd3

Please sign in to comment.