Skip to content

Commit

Permalink
Remove pool startTime from GAMM (osmosis-labs#294)
Browse files Browse the repository at this point in the history
* remove starttime from pool

* resolve tests
  • Loading branch information
antstalepresh authored Jun 13, 2021
1 parent 2d315fe commit 9d95b11
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 174 deletions.
5 changes: 0 additions & 5 deletions proto/osmosis/gamm/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ message PoolParams {
(gogoproto.moretags) = "yaml:\"smooth_weight_change_params\"",
(gogoproto.nullable) = true
];
google.protobuf.Timestamp start_time = 4 [
(gogoproto.stdtime) = true,
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"start_time\""
];
}

message Pool {
Expand Down
1 change: 0 additions & 1 deletion x/gamm/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ type createPoolInputs struct {
InitialDeposit string `json:"initial-deposit"`
SwapFee string `json:"swap-fee"`
ExitFee string `json:"exit-fee"`
StartTime string `json:"start-time"`
FutureGovernor string `json:"future-governor"`
SmoothWeightChangeParams smoothWeightChangeParamsInputs `json:"lbp-params"`
}
Expand Down
9 changes: 0 additions & 9 deletions x/gamm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,6 @@ func NewBuildCreatePoolMsg(clientCtx client.Context, txf tx.Factory, fs *flag.Fl
return txf, nil, err
}

var startTime time.Time
if pool.StartTime != "" {
startTime, err = time.Parse(time.RFC3339, pool.StartTime)
if err != nil {
return txf, nil, err
}
}

var poolAssets []types.PoolAsset
for i := 0; i < len(poolAssetCoins); i++ {

Expand All @@ -388,7 +380,6 @@ func NewBuildCreatePoolMsg(clientCtx client.Context, txf tx.Factory, fs *flag.Fl
PoolParams: types.PoolParams{
SwapFee: swapFee,
ExitFee: exitFee,
StartTime: startTime,
},
PoolAssets: poolAssets,
FuturePoolGovernor: pool.FutureGovernor,
Expand Down
13 changes: 4 additions & 9 deletions x/gamm/keeper/pool_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ func (suite *KeeperTestSuite) TestCreatePool() {

liquidity := suite.app.GAMMKeeper.GetTotalLiquidity(suite.ctx)
suite.Require().Equal("10000bar,10000foo", liquidity.String())

suite.Require().Equal(suite.ctx.BlockTime(), pool.GetPoolParams().StartTime)
},
}, {
fn: func() {
Expand Down Expand Up @@ -421,14 +419,12 @@ func (suite *KeeperTestSuite) TestExitPool() {
func (suite *KeeperTestSuite) TestActivePool() {
type testCase struct {
blockTime time.Time
startTime time.Time
expectPass bool
}

testCases := []testCase{
{time.Unix(1000, 0), time.Unix(1000, 0), true},
{time.Unix(2000, 0), time.Unix(1000, 0), true},
{time.Unix(1000, 0), time.Unix(2000, 0), false},
{time.Unix(1000, 0), true},
{time.Unix(2000, 0), true},
}

for _, tc := range testCases {
Expand All @@ -451,9 +447,8 @@ func (suite *KeeperTestSuite) TestActivePool() {

// Create the pool at first
poolId := suite.preparePoolWithPoolParams(types.PoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
StartTime: tc.startTime,
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
})
suite.ctx = suite.ctx.WithBlockTime(tc.blockTime)

Expand Down
12 changes: 4 additions & 8 deletions x/gamm/keeper/swap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"

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

Expand Down Expand Up @@ -202,15 +202,13 @@ func (suite *KeeperTestSuite) TestSimpleSwapExactAmountOut() {

func (suite *KeeperTestSuite) TestActivePoolSwap() {
type testCase struct {
blockTime time.Time
startTime time.Time
blockTime time.Time
expectPass bool
}

testCases := []testCase{
{time.Unix(1000, 0), time.Unix(1000, 0), true},
{time.Unix(2000, 0), time.Unix(1000, 0), true},
{time.Unix(1000, 0), time.Unix(2000, 0), false},
{time.Unix(1000, 0), true},
{time.Unix(2000, 0), true},
}

for _, tc := range testCases {
Expand All @@ -234,7 +232,6 @@ func (suite *KeeperTestSuite) TestActivePoolSwap() {
poolId := suite.preparePoolWithPoolParams(types.PoolParams{
SwapFee: sdk.NewDec(0),
ExitFee: sdk.NewDec(0),
StartTime: tc.startTime,
})

suite.ctx = suite.ctx.WithBlockTime(tc.blockTime)
Expand All @@ -255,4 +252,3 @@ func (suite *KeeperTestSuite) TestActivePoolSwap() {
}
}
}

26 changes: 11 additions & 15 deletions x/gamm/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func WeightedOperations(
bk stakingTypes.BankKeeper, k keeper.Keeper,
) simulation.WeightedOperations {
var (
weightMsgCreatePool int
weightMsgCreatePool int
weightMsgSwapExactAmountIn int
)

Expand Down Expand Up @@ -85,7 +85,7 @@ func genFuturePoolGovernor(r *rand.Rand, addr sdk.Address, tokenList []string) s

func genPoolAssets(r *rand.Rand, acct simtypes.Account, coins sdk.Coins) []types.PoolAsset {
// selecting random number between [2, Min(coins.Len, 6)]
numCoins := 2 + r.Intn(Min(coins.Len(), 6) - 1)
numCoins := 2 + r.Intn(Min(coins.Len(), 6)-1)
denomIndices := r.Perm(numCoins)
assets := []types.PoolAsset{}
for i := 0; i < numCoins; i++ {
Expand All @@ -106,15 +106,11 @@ func genPoolParams(r *rand.Rand, blockTime time.Time, assets []types.PoolAsset)
exitFeeInt := int64(r.Intn(1e5))
exitFee := sdk.NewDecWithPrec(exitFeeInt, 5)

timeSecs := r.Intn(1*60*60*24*7) // range of 1 week from the block time
startTime := blockTime.Add(time.Duration(timeSecs) * time.Second)

// TODO: Randomly generate LBP params
return types.PoolParams{
SwapFee: swapFee,
ExitFee: exitFee,
SmoothWeightChangeParams: nil,
StartTime: startTime,
}
}

Expand Down Expand Up @@ -180,7 +176,7 @@ func SimulateMsgSwapExactAmountIn(ak stakingTypes.AccountKeeper, bk stakingTypes
amt, _ := simtypes.RandPositiveInt(r, coin.Amount)

tokenIn := sdk.Coin{
Denom: coin.Denom,
Denom: coin.Denom,
Amount: amt,
}

Expand All @@ -193,9 +189,9 @@ func SimulateMsgSwapExactAmountIn(ak stakingTypes.AccountKeeper, bk stakingTypes
tokenOutMin, _ := simtypes.RandPositiveInt(r, tokenOut.Amount)

msg := types.MsgSwapExactAmountIn{
Sender: simAccount.Address.String(),
Routes: routes,
TokenIn: tokenIn,
Sender: simAccount.Address.String(),
Routes: routes,
TokenIn: tokenIn,
TokenOutMinAmount: tokenOutMin,
}

Expand All @@ -206,13 +202,13 @@ func SimulateMsgSwapExactAmountIn(ak stakingTypes.AccountKeeper, bk stakingTypes
}

func RandomExactAmountInRoute(ctx sdk.Context, r *rand.Rand, k keeper.Keeper, tokenIn sdk.Coin) (res []types.SwapAmountInRoute, tokenOut sdk.Coin) {
routeLen := r.Intn(1)+1
routeLen := r.Intn(1) + 1

pools, err := k.GetPools(ctx)
if err != nil {
panic(err)
}
if len(pools) == 0 {
if len(pools) == 0 {
return
}

Expand All @@ -230,7 +226,7 @@ func RandomExactAmountInRoute(ctx sdk.Context, r *rand.Rand, k keeper.Keeper, to
for _, asset := range pool.GetAllPoolAssets() {
if asset.Token.Denom != tokenIn.Denom {
res[i] = types.SwapAmountInRoute{
PoolId: pool.GetId(),
PoolId: pool.GetId(),
TokenOutDenom: asset.Token.Denom,
}
sp, err := k.CalculateSpotPriceWithSwapFee(ctx, pool.GetId(), tokenIn.Denom, asset.Token.Denom)
Expand All @@ -239,8 +235,8 @@ func RandomExactAmountInRoute(ctx sdk.Context, r *rand.Rand, k keeper.Keeper, to
}
amt := tokenIn.Amount.ToDec().Quo(sp).RoundInt()
tokenIn = sdk.Coin{
Denom: asset.Token.Denom,
Amount: amt,
Denom: asset.Token.Denom,
Amount: amt,
}
break
}
Expand Down
7 changes: 2 additions & 5 deletions x/gamm/spec/02_pool_params.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ At launch, Pools have the following parameters:
SwapFee
ExitFee
FutureGovernor
StartTime
Weights
SmoothWeightChangeParams
```
Expand All @@ -28,10 +27,8 @@ We go through these in sequence.
- Noone will govern it, this is done by leaving the future governor string as blank.
- Allow a given address to govern it, this is done by setting the future governor as a bech32 address.
- Lockups to a token. This is the full DAO scenario. The future governor specifies a token denomination `Denom`, and a lockup duration `Duration`. This says that "all tokens of denomination `Denom` that are locked up for `Duration` or longer, have equal say in governance of this pool".
4. StartTime
This defines a time at which trading will be allowed on the pool. Prior to this time having passed, users can only add liquidity to the pool at its existing spot price and weights via the `JoinPool` message, or exit liquidity via `ExitPool` message. This allows a pool to build some liquidity prior to trading being enabled.
5. Weights
4. Weights
This defines the weights of the pool. https://balancer.fi/whitepaper.pdf
TODO Add better description of how the weights affect things here.
6. SmoothWeightChangeParams
5. SmoothWeightChangeParams
SmoothWeightChangeParams allows pool governance to smoothly change the weights of the assets it holds in the pool. So it can slowly move from a 2:1 ratio, to a 1:1 ratio. Currently, smooth weight changes are implemented as a linear change in weight ratios over a given duration of time. So weights changed from 4:1 to 2:2 over 2 days, then at day 1 of the change, the weights would be 3:1.5, and at day 2 its 2:2, and will remain at these weight ratios.
2 changes: 0 additions & 2 deletions x/gamm/types/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestPoolMarshalYAML(t *testing.T) {
swap_fee: "0.025000000000000000"
exit_fee: "0.025000000000000000"
smooth_weight_change_params: null
start_time: 0001-01-01T00:00:00Z
future_pool_governor: ""
total_weight: "300.000000000000000000"
total_shares:
Expand Down Expand Up @@ -124,7 +123,6 @@ func TestLBPPoolMarshalYAML(t *testing.T) {
denom: test2
amount: "0"
weight: "300.000000000000000000"
start_time: 0001-01-01T00:00:00Z
future_pool_governor: ""
total_weight: "300.000000000000000000"
total_shares:
Expand Down
8 changes: 0 additions & 8 deletions x/gamm/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,6 @@ func (pa *Pool) setInitialPoolParams(params PoolParams, sortedAssets []PoolAsset
}
}

// Set pool start time if not present.
if params.StartTime.Unix() <= 0 {
params.StartTime = time.Unix(curBlockTime.Unix(), 0)
}

return nil
}

Expand Down Expand Up @@ -475,9 +470,6 @@ func (pa Pool) NumAssets() int {
}

func (pa Pool) IsActive(curBlockTime time.Time) bool {
if pa.PoolParams.StartTime.After(curBlockTime) {
return false
}

// Add frozen pool checking, etc...

Expand Down
Loading

0 comments on commit 9d95b11

Please sign in to comment.