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

docs(CL): concentrated-liquidity module spec pt1 #3142

Merged
merged 15 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
- app/wasm/**/*
"C:x/claim":
- x/claim/**/*
"C:x/concentrated-liquidity":
- x/concentrated-liquidity/**/*
"C:x/epochs":
- x/epochs/**/*
"C:x/gamm":
Expand All @@ -34,6 +36,8 @@
- x/pool-incentives/**/*
"C:x/superfluid":
- x/superfluid/**/*
"C:x/swaprouter":
- x/swaprouter/**/*
"C:x/txfees":
- x/txfees/**/*
"C:x/tokenfactory":
Expand All @@ -52,7 +56,7 @@
"C:CLI":
- client/**/*
- x/*/client/**/*
# Add "C:docs" label to documented related files and directories.
# Add "C:docs" label to documented related files and directories.
"C:docs":
- bug.md
- issue.md
Expand All @@ -61,4 +65,3 @@
- x/**/*.md
- x/**/*/*.md
- tests/**/*.md

32 changes: 8 additions & 24 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ pull_request_rules:
backport:
branches:
- v4.x
- name: backport patches to v5.x branch
conditions:
- base=main
- label=A:backport/v5.x
actions:
backport:
branches:
- v5.x
- name: backport patches to v6.x branch
conditions:
- base=main
Expand All @@ -54,14 +46,6 @@ pull_request_rules:
backport:
branches:
- v6.x
- name: backport patches to v7.x branch
conditions:
- base=main
- label=A:backport/v7.x
actions:
backport:
branches:
- v7.x
- name: backport patches to v8.x branch
conditions:
- base=main
Expand All @@ -70,14 +54,6 @@ pull_request_rules:
backport:
branches:
- v8.x
- name: backport patches to v9.x branch
conditions:
- base=main
- label=A:backport/v9.x
actions:
backport:
branches:
- v9.x
- name: backport patches to v10.x branch
conditions:
- base=main
Expand Down Expand Up @@ -110,3 +86,11 @@ pull_request_rules:
backport:
branches:
- v13.x
- name: backport patches to concentrated-liquidity-main
conditions:
- base=main
- label=A:backport/cl
actions:
backport:
branches:
- concentrated-liquidity-main
34 changes: 0 additions & 34 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,37 +87,3 @@ jobs:
# if: ${{ matrix.contract.output != null }}
# run: >
# diff ${{ matrix.contract.output }} ${{ matrix.contract.build }}


lints:
name: Cosmwasm Lints
runs-on: ubuntu-latest
strategy:
matrix:
workdir: [./x/ibc-rate-limit]

steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.rs
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy

- name: Format
working-directory: ${{ matrix.workdir }}
run: >
cargo fmt --all -- --check

- name: run cargo clippy
working-directory: ${{ matrix.workdir }}
run: >
cargo clippy -- -D warnings

1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- concentrated-liquidity-main

jobs:
golangci:
Expand Down
22 changes: 2 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@ on:
push:
branches:
- "main"
- "concentrated-liquidity-main"
- "v[0-9]**"
workflow_dispatch:

jobs:
should_run_go_test:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
-
id: skip_check
uses: fkirc/skip-duplicate-actions@master
with:
cancel_others: "true" # workflow-runs from outdated commits will be cancelled.
concurrent_skipping: "same_content"
skip_after_successful_duplicate: "true"
paths: '["**/*.go", "**/*.mod", "**/*.sum"]'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'
-
name: Skipping test
run: echo Should I skip tests? ${{ steps.skip_check.outputs.should_skip }}

go:
needs: should_run_go_test
if: ${{ needs.should_run_test.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest
steps:
-
Expand Down Expand Up @@ -124,3 +105,4 @@ jobs:
-
name: Test e2e and Upgrade
run: make test-e2e-ci

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

### Features

* [#2788](https://github.com/osmosis-labs/osmosis/pull/2788) Add logarithm base 2 implementation.
* [#2739](https://github.com/osmosis-labs/osmosis/pull/2739) Add pool type query

### Bug fixes
Expand Down
10 changes: 9 additions & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (s *KeeperTestHelper) SwapAndSetSpotPrice(poolId uint64, fromAsset sdk.Coin
coins := sdk.Coins{sdk.NewInt64Coin(fromAsset.Denom, 100000000000000)}
s.FundAcc(acc1, coins)

_, err := s.App.GAMMKeeper.SwapExactAmountOut(
_, err := s.App.GAMMKeeper.SwapExactAmountOutDefaultSwapFee(
s.Ctx,
acc1,
poolId,
Expand Down Expand Up @@ -350,6 +350,14 @@ func (s *KeeperTestHelper) BuildTx(
return txBuilder.GetTx()
}

// StateNotAltered validates that app state is not altered. Fails if it is.
func (s *KeeperTestHelper) StateNotAltered() {
oldState := s.App.ExportState(s.Ctx)
s.Commit()
newState := s.App.ExportState(s.Ctx)
s.Require().Equal(oldState, newState)
}

// CreateRandomAccounts is a function return a list of randomly generated AccAddresses
func CreateRandomAccounts(numAccts int) []sdk.AccAddress {
testAddrs := make([]sdk.AccAddress, numAccts)
Expand Down
4 changes: 4 additions & 0 deletions app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,7 @@ func (app *OsmosisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr
},
)
}

func (app *OsmosisApp) ExportState(ctx sdk.Context) map[string]json.RawMessage {
return app.mm.ExportGenesis(ctx, app.AppCodec())
}
2 changes: 1 addition & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.keys[txfeestypes.StoreKey],
appKeepers.GAMMKeeper,
appKeepers.SwapRouterKeeper,
appKeepers.GAMMKeeper,
txfeestypes.FeeCollectorName,
txfeestypes.NonNativeFeeCollectorName,
Expand Down
12 changes: 9 additions & 3 deletions chain.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"codebase":{
"git_repo": "https://github.com/osmosis-labs/osmosis",
"recommended_version": "12.1.0",
"compatible_versions": ["12.1.0"],
"recommended_version": "12.2.0",
"compatible_versions": [
"12.2.0"
],
"binaries": {
"linux/amd64": "https://github.com/osmosis-labs/osmosis/releases/download/v12.1.0/osmosisd-12.1.0-linux-amd64?checksum=sha256:44433f93946338b8cb167d9030ebbcfe924294d95d745026ada5dbe8f50d5010",
"linux/arm64": "https://github.com/osmosis-labs/osmosis/releases/download/v12.1.0/osmosisd-12.1.0-linux-arm64?checksum=sha256:ef2c3d60156be5481534ecb33f9d94d73afa38a1b016e7e1c6d3fe10e3e69b3a"
Expand All @@ -12,8 +14,12 @@
"tendermint_version": "0.34",
"cosmwasm_version": "0.28",
"cosmwasm_enabled": true,
"ibc_go_version": "3.3.0",
"ics_enabled": [
"ics20-1"
],
"genesis": {
"name": "v3.1.0",
"name": "v3",
"genesis_url": "https://github.com/osmosis-labs/networks/raw/main/osmosis-1/genesis.json"
},
"versions": [
Expand Down
121 changes: 118 additions & 3 deletions docs/architecture/concentrated-liquidity-adr.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,122 @@ logic that is specific to minting, burning liquidity, and swapping within concen
Under the "Liquidity Provision" user story, we will track tasks specific to defining
foundations, boilerplate, module wiring and their respective tests.

Providing, burning liquidity, and swapping functions are to be tracked in their own stories.
While low-level details for providing, burning liquidity, and swapping functions are to be tracked in their own user stories, we define
all messages here.

##### `MsgCreatePosition`

- **Request**

This message allows LPs to provide liquidity between `LowerTick` and `UpperTick` in a given `PoolId.
The user provides the amount of each token desired. Since LPs are only allowed to provide
liquidity proportional to the existing reserves, the actual amount of tokens used might differ from requested.
As a result, LPs may also provide the minimum amount of each token to be used so that the system fails
to create position if the desired amounts cannot be satisfied.

```go
type MsgCreatePosition struct {
PoolId uint64
Sender string
LowerTick int64
UpperTick int64
TokenDesired0 types.Coin
TokenDesired1 types.Coin
TokenMinAmount0 github_com_cosmos_cosmos_sdk_types.Int
TokenMinAmount1 github_com_cosmos_cosmos_sdk_types.Int
}
```

- **Response**

On succesful response, we receive the actual amounts of each token used to create the
liquidityCreated number of shares in the given range.

```go
type MsgCreatePositionResponse struct {
Amount0 github_com_cosmos_cosmos_sdk_types.Int
Amount1 github_com_cosmos_cosmos_sdk_types.Int
LiquidityCreated github_com_cosmos_cosmos_sdk_types.Int
}
```

This message should call the `createPosition` keeper method that is introduced in the `"Liquidity Provision"` section of this document.

##### `MsgWithdrawPosition`

- **Request**

This message allows LPs to withdraw their position in a given pool and range (given by ticks), potentially in partial
amount of liquidity. It should fail if there is no position in the given tick ranges, if tick ranges are invalid,
or if attempting to withdraw an amount higher than originally provided.

```go
type MsgWithdrawPosition struct {
PoolId uint64
Sender string
LowerTick int64
UpperTick int64
LiquidityAmount github_com_cosmos_cosmos_sdk_types.Int
}
```

- **Response**

On succesful response, we receive the amounts of each token withdrawn
for the provided share liquidity amount.

```go
type MsgWithdrawPositionResponse struct {
Amount0 github_com_cosmos_cosmos_sdk_types.Int
Amount1 github_com_cosmos_cosmos_sdk_types.Int
}
```

This message should call the `withdrawPosition` keeper method that is introduced in the `"Liquidity Provision"` section of this document.

##### `SwapExactAmountIn` Keeper Method

This method has the same interface as the pre-existing `SwapExactAmountIn` in the `x/gamm` module.
It takes an exact amount of coins of one denom in to return a minimum amount of tokenOutDenom.

```go
func (k Keeper) SwapExactAmountIn(
ctx sdk.Context,
sender sdk.AccAddress,
pool gammtypes.PoolI,
tokenIn sdk.Coin,
tokenOutDenom string,
tokenOutMinAmount sdk.Int,
swapFee sdk.Dec,
) (tokenOutAmount sdk.Int, err error) {
...
}
```

This method should be called from the new `swap-router` module's `RouteExactAmountIn` initiated by the `MsgSwapExactAmountIn`.
See the next `"Swap Router Module"` section of this document for more details.

##### `SwapExactAmountOut` Keeper Method

This method is comparable to `SwapExactAmountIn`. It has the same interface as the pre-existing `SwapExactAmountOut` in the `x/gamm` module.
It takes an exact amount of coins of one denom out to return a maximum amount of tokenInDenom.

```go
func (k Keeper) SwapExactAmountOut(
ctx sdk.Context,
sender sdk.AccAddress,
poolI gammtypes.PoolI,
tokenInDenom string,
tokenInMaxAmount sdk.Int,
tokenOut sdk.Coin,
swapFee sdk.Dec,
) (tokenInAmount sdk.Int, err error) {
...
}
```

This method should be called from the new `swap-router` module's `RouteExactAmountOut` initiated by the `MsgSwapExactAmountOut`.
See the next `"Swap Router Module"` section of this document for more details.

#### Swap Router Module

Expand All @@ -127,7 +242,7 @@ To avoid fragmenting swap entrypoints and duplicating boilerplate logic, we woul
a new `swap-router` module. For now, its only purpose is to receive swap messages and propagate them
either to the `gamm` or `concentrated-liquidity` modules.

Therefore, we should move the existing `gamm` swap messages and tests to the new `swap-router` module, connecting to the `swap-router` keeper that simply propagates swaps to `gamm` or `concentrated-liquidity` modules.
Therefore, we move the existing `gamm` swap messages and tests to the new `swap-router` module, connecting to the `swap-router` keeper that simply propagates swaps to `gamm` or `concentrated-liquidity` modules.

The messages to move are:
- `MsgSwapExactAmountIn`
Expand Down Expand Up @@ -170,7 +285,7 @@ The deltaX and the deltaY would be the actual amount of tokens joined for the re
Given the parameters needed for calculating the tokens needed for creating a position for a given tick, the API in the msg server layer would look like the following:

```go
func CreatePosition(
func createPosition(
ctx sdk.Context,
poolId uint64,
owner sdk.AccAddress,
Expand Down
Loading