Commit 769c1c69 authored by Sunny Aggarwal's avatar Sunny Aggarwal
Browse files

in progress

parent 92ed4d96
Showing with 194 additions and 31 deletions
+194 -31
......@@ -13,6 +13,16 @@ message Params {
(gogoproto.moretags) = "yaml:\"pool_creation_fee\"",
(gogoproto.nullable) = false
];
string default_pool_swap_fee = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"default_pool_swap_fee\"",
(gogoproto.nullable) = false
];
string default_pool_exit_fee = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"default_pool_exit_fee\"",
(gogoproto.nullable) = false
];
}
option go_package = "github.com/osmosis-labs/osmosis/x/gamm/types";
......
......@@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/pkg/errors"
"github.com/osmosis-labs/osmosis/x/gamm/pool-models/balancer"
"github.com/osmosis-labs/osmosis/x/gamm/types"
......@@ -32,6 +33,15 @@ func (k Keeper) CreateBalancerPool(
// send pool creation fee to community pool
params := k.GetParams(ctx)
if !BalancerPoolParams.SwapFee.Equal(params.DefaultPoolSwapFee) {
return 0, errors.Wrapf(types.ErrInvalidSwapFee, "swap fee should be %s", params.DefaultPoolSwapFee)
}
if !BalancerPoolParams.ExitFee.Equal(params.DefaultPoolExitFee) {
return 0, errors.Wrapf(types.ErrInvalidExitFee, "exit fee should be %s", params.DefaultPoolExitFee)
}
err := k.distrKeeper.FundCommunityPool(ctx, params.PoolCreationFee, sender)
if err != nil {
return 0, err
......
......@@ -24,6 +24,8 @@ var (
ErrNotPositiveCriteria = sdkerrors.Register(ModuleName, 29, "min out amount or max in amount should be positive")
ErrNotPositiveRequireAmount = sdkerrors.Register(ModuleName, 30, "required amount should be positive")
ErrTooManyTokensOut = sdkerrors.Register(ModuleName, 31, "tx is trying to get more tokens out of the pool than exist")
ErrInvalidSwapFee = sdkerrors.Register(ModuleName, 32, "swap fee is invalid")
ErrInvalidExitFee = sdkerrors.Register(ModuleName, 33, "exit fee is invalid")
ErrPoolParamsInvalidDenom = sdkerrors.Register(ModuleName, 50, "pool params' LBP params has an invalid denomination")
ErrPoolParamsInvalidNumDenoms = sdkerrors.Register(ModuleName, 51, "pool params' LBP doesn't have same number of params as underlying pool")
......
......@@ -29,7 +29,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
// Params holds parameters for the incentives module
type Params struct {
PoolCreationFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=pool_creation_fee,json=poolCreationFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"pool_creation_fee" yaml:"pool_creation_fee"`
PoolCreationFee github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,1,rep,name=pool_creation_fee,json=poolCreationFee,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"pool_creation_fee" yaml:"pool_creation_fee"`
DefaultPoolSwapFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=default_pool_swap_fee,json=defaultPoolSwapFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"default_pool_swap_fee" yaml:"default_pool_swap_fee"`
DefaultPoolExitFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=default_pool_exit_fee,json=defaultPoolExitFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"default_pool_exit_fee" yaml:"default_pool_exit_fee"`
}
func (m *Params) Reset() { *m = Params{} }
......@@ -143,32 +145,37 @@ func init() {
}
var fileDescriptor_5a324eb7f1dd793e = []byte{
// 390 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x52, 0x3d, 0xeb, 0xd3, 0x40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39, 0x4d, 0x37, 0xbe, 0x7d, 0xed, 0xad, 0x1b, 0x9a, 0x97, 0x99, 0x43,
0x87, 0x5d, 0x72, 0x47, 0xc2, 0xc4, 0x8f, 0x94, 0xe3, 0x3a, 0x87, 0x91, 0xbd, 0xe4, 0x5a, 0x76,
0xcb, 0xe4, 0x0d, 0xf6, 0xc8, 0x66, 0xc3, 0x03, 0xd2, 0x69, 0xac, 0x33, 0xec, 0x96, 0x66, 0xc2,
0x55, 0x97, 0x52, 0xe7, 0x9a, 0x74, 0xcd, 0xec, 0x9e, 0x79, 0x64, 0xda, 0x3f, 0x9f, 0x47, 0xc1,
0xc5, 0x3c, 0x0a, 0x7e, 0xcd, 0xa3, 0xe0, 0xc3, 0x22, 0x6a, 0x5d, 0x2c, 0xa2, 0xd6, 0xf7, 0x45,
0xd4, 0x7a, 0xfd, 0xf0, 0xca, 0x6d, 0x3c, 0x4f, 0xaf, 0xe2, 0xb9, 0x5a, 0x06, 0x6c, 0xe2, 0x7e,
0x10, 0x7b, 0xa5, 0xbc, 0x63, 0xb7, 0x78, 0xf4, 0x3b, 0x00, 0x00, 0xff, 0xff, 0x7d, 0xd2, 0xc0,
0x0d, 0x3d, 0x03, 0x00, 0x00,
}
func (m *Params) Marshal() (dAtA []byte, err error) {
......@@ -191,6 +198,26 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
{
size := m.DefaultPoolExitFee.Size()
i -= size
if _, err := m.DefaultPoolExitFee.MarshalTo(dAtA[i:]); err != nil {
return 0, err
}
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x1a
{
size := m.DefaultPoolSwapFee.Size()
i -= size
if _, err := m.DefaultPoolSwapFee.MarshalTo(dAtA[i:]); err != nil {
return 0, err
}
i = encodeVarintGenesis(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
if len(m.PoolCreationFee) > 0 {
for iNdEx := len(m.PoolCreationFee) - 1; iNdEx >= 0; iNdEx-- {
{
......@@ -283,6 +310,10 @@ func (m *Params) Size() (n int) {
n += 1 + l + sovGenesis(uint64(l))
}
}
l = m.DefaultPoolSwapFee.Size()
n += 1 + l + sovGenesis(uint64(l))
l = m.DefaultPoolExitFee.Size()
n += 1 + l + sovGenesis(uint64(l))
return n
}
......@@ -375,6 +406,74 @@ func (m *Params) Unmarshal(dAtA []byte) error {
return err
}
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DefaultPoolSwapFee", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.DefaultPoolSwapFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field DefaultPoolExitFee", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenesis
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthGenesis
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthGenesis
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.DefaultPoolExitFee.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipGenesis(dAtA[iNdEx:])
......
......@@ -10,7 +10,9 @@ import (
// Parameter store keys
var (
KeyPoolCreationFee = []byte("PoolCreationFee")
KeyPoolCreationFee = []byte("PoolCreationFee")
KeyDefaultPoolSwapFee = []byte("DefaultPoolSwapFee")
KeyDefaultPoolExitFee = []byte("DefaultPoolExitFee")
)
// ParamTable for gamm module.
......@@ -18,16 +20,20 @@ func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
func NewParams(poolCreationFee sdk.Coins) Params {
func NewParams(poolCreationFee sdk.Coins, defaultPoolSwapFee, defaultPoolExitFee sdk.Dec) Params {
return Params{
PoolCreationFee: poolCreationFee,
PoolCreationFee: poolCreationFee,
DefaultPoolSwapFee: defaultPoolSwapFee,
DefaultPoolExitFee: defaultPoolExitFee,
}
}
// default gamm module parameters
func DefaultParams() Params {
return Params{
PoolCreationFee: sdk.Coins{sdk.NewInt64Coin(appparams.BaseCoinUnit, 1000_000_000)}, // 1000 OSMO
PoolCreationFee: sdk.Coins{sdk.NewInt64Coin(appparams.BaseCoinUnit, 1000_000_000)}, // 1000 OSMO
DefaultPoolSwapFee: sdk.MustNewDecFromStr("0.02"), // 1000 OSMO
DefaultPoolExitFee: sdk.MustNewDecFromStr("0"), // 1000 OSMO
}
}
......@@ -37,6 +43,14 @@ func (p Params) Validate() error {
return err
}
if err := validateDefaultPoolSwapFee(p.DefaultPoolSwapFee); err != nil {
return err
}
if err := validateDefaultPoolExitFee(p.DefaultPoolExitFee); err != nil {
return err
}
return nil
}
......@@ -45,6 +59,8 @@ func (p Params) Validate() error {
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(KeyPoolCreationFee, &p.PoolCreationFee, validatePoolCreationFee),
paramtypes.NewParamSetPair(KeyDefaultPoolSwapFee, &p.DefaultPoolSwapFee, validateDefaultPoolSwapFee),
paramtypes.NewParamSetPair(KeyDefaultPoolExitFee, &p.DefaultPoolExitFee, validateDefaultPoolExitFee),
}
}
......@@ -60,3 +76,29 @@ func validatePoolCreationFee(i interface{}) error {
return nil
}
func validateDefaultPoolSwapFee(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.LT(sdk.ZeroDec()) || v.GT(sdk.OneDec()) {
return fmt.Errorf("invalid default pool swap fee: %+v", i)
}
return nil
}
func validateDefaultPoolExitFee(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if v.LT(sdk.ZeroDec()) || v.GT(sdk.OneDec()) {
return fmt.Errorf("invalid default pool exit fee: %+v", i)
}
return nil
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment