Skip to content

Commit

Permalink
docs(CL): concentrated-liquidity module spec pt1 (#3142)
Browse files Browse the repository at this point in the history
* concentrated liquidity: further swap/lp work (#3101)

* further swap generalization

* add step and swap state

* Update test.yml

* Update test.yml

* Further generalize swaps and lp (#3111)

* Change sqrt to caller

* Remove margin of error from mint

* Change Pool to have dec curr price

* Remove swap structs

* Adams comments

* address code review comments

* final additions

* address code review comments

* code review

Co-authored-by: Matt, Park <[email protected]>

* updates (#3119)

Co-authored-by: Roman <[email protected]>

* refactor(CL): move multihop to swap router, wire to concentrated liquidity module (#3128)

* feat/refactor(CL): move multihop to swaprouter, connect to concentrated liquidity

* comments

* godoc for RouteExactAmountOut

* link issues

* delete multihop_test.go

* Update x/swaprouter/router_test.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/swaprouter/router_test.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/concentrated-liquidity/pool.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/gamm/keeper/swap.go

Co-authored-by: Adam Tucker <[email protected]>

Co-authored-by: Adam Tucker <[email protected]>

* Add state for Mint: tick and Position (#3136)

* WIP: tick

* Finish implementing

* Update x/concentrated-liquidity/lp.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/concentrated-liquidity/lp.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/concentrated-liquidity/lp.go

Co-authored-by: Adam Tucker <[email protected]>

* Change to negative calculations

* Add comment

* Add getter in osmoutils

* Update osmoutils/store_helper.go

Co-authored-by: Adam Tucker <[email protected]>

* Update x/concentrated-liquidity/position.go

Co-authored-by: Adam Tucker <[email protected]>

Co-authored-by: Adam Tucker <[email protected]>

* feat(CL): CreatePosition and WithdrawPosition messages (#3139)

* feat(CL): CreatePosition and WithdrawPosition messages

* lint

* docs(CL): `concentrated-liquidity` module spec pt1

* add tests for GetIfFound (#3145)

* add tests for GetIfFound

* refactor

* Update docs/architecture/concentrated-liquidity-adr.md

Co-authored-by: Adam Tucker <[email protected]>

* Update docs/architecture/concentrated-liquidity-adr.md

Co-authored-by: Adam Tucker <[email protected]>

* Update docs/architecture/concentrated-liquidity-adr.md

Co-authored-by: Adam Tucker <[email protected]>

* Update docs/architecture/concentrated-liquidity-adr.md

Co-authored-by: Adam Tucker <[email protected]>

* Update test.yml (#3148)

* Merge main into concentrated-liquidity-main (#3149)

* Add servers to openapi spec file (#2980)

* Chain.schema.json: Added ibc data, fix genesis name, formatting (#3077)

Closes: #XXX

## What is the purpose of the change

> Add a description of the overall background and high level changes that this PR introduces

*(E.g.: This pull request improves documation of area A by adding ....*

To update the chain schema codebase data. This file Auto-updates the chain registry.


## Brief Changelog

*(for example:)*
 
  - *The metadata is stored in the blob store on job creation time as a persistent artifact*
  - *Deployments RPC transmits only the blob storage reference*
  - *Daemons retrieve the RPC data from the blob cache*

Added ibc data (ibc go version and enabled features(ics-20),
fix genesis name, (was version number before, now goes by name)
minor formatting chg.


## Testing and Verifying

*(Please pick one of the following options)*

--> This change is a trivial rework / code cleanup without any test coverage.

*(or)*

This change is already covered by existing tests, such as *(please describe tests)*.

*(or)*

This change added tests and can be verified as follows:

*(example:)*
  - *Added unit test that validates ...*
  - *Added integration tests for end-to-end deployment with ...*
  - *Extended integration test for ...*
  - *Manually verified the change by ...*

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? (yes / no) No
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? (yes / no) No
  - How is the feature or change documented? (not applicable   /   specification (`x/<module>/spec/`)  /  [Osmosis docs repo](https://github.com/osmosis-labs/docs)   /   not documented) not documented

* labels (#3082)

* [x/gamm][stableswap]: Expand inverse relation tests to multi assets and add scaling factors (#3006)

* expand inverse relation tests to multi assets and add scaling factors

* tighten binary search bounds to fit spec

* remove todo

* Fix sped

* move output negation to caller

Co-authored-by: Dev Ojha <[email protected]>

* remove all uses of two-asset binary search solver (#3084)

* [stableswap]: Implement simplified direct multi-asset CFMM solver (#3068)

Closes: #2730

## What is the purpose of the change

This PR implements a direct solver for our multi-asset CFMM. Similar to our two-asset direct solver, it is intended to be kept in our codebase as a reference implementation and proof for our CFMM but is outclassed by our binary search solver for practical use.

## Brief Changelog

- Implement direct multi-asset solver and test it against our full suite of CFMM cases

## Testing and Verifying

- The solver implementation is tested against our full multi-asset CFMM test suite in `amm_test.go`

## Documentation and Release Note

  - Does this pull request introduce a new feature or user-facing behavior changes? (no)
  - Is a relevant changelog entry added to the `Unreleased` section in `CHANGELOG.md`? (no)
  - How is the feature or change documented? (not documented)

* refactor: remove PokePool from the PoolI interface, define on extension instead (#3035)

* refactor: remove PokePool from the PoolI interface, use extension instead

* changelog

* fix weights bug

* Update x/gamm/keeper/pool_test.go

Co-authored-by: Matt, Park <[email protected]>

* Update x/gamm/keeper/pool_test.go

* address comments

Co-authored-by: Matt, Park <[email protected]>

* ci(CL): run tests on CL branch and add backport config (#3095)

* ci(CL): run tests on CL branch and add backport config

* Update .github/mergify.yml

* After create pool test (#2783)

* add test for afterCreatePool

* format

* add test to check trackChangePool

Co-authored-by: Matt, Park <[email protected]>

* fix GetModuleToDistributeCoins (#2957)

* update comment in gamm module (#3103)

* chore(deps): Bump github.com/tendermint/tendermint (#3106)

Bumps [github.com/tendermint/tendermint](https://github.com/tendermint/tendermint) from 0.34.21 to 0.34.22.
- [Release notes](https://github.com/tendermint/tendermint/releases)
- [Changelog](https://github.com/tendermint/tendermint/blob/main/CHANGELOG.md)
- [Commits](tendermint/tendermint@v0.34.21...v0.34.22)

---
updated-dependencies:
- dependency-name: github.com/tendermint/tendermint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): Bump github.com/golangci/golangci-lint (#3104)

Bumps [github.com/golangci/golangci-lint](https://github.com/golangci/golangci-lint) from 1.50.0 to 1.50.1.
- [Release notes](https://github.com/golangci/golangci-lint/releases)
- [Changelog](https://github.com/golangci/golangci-lint/blob/master/CHANGELOG.md)
- [Commits](golangci/golangci-lint@v1.50.0...v1.50.1)

---
updated-dependencies:
- dependency-name: github.com/golangci/golangci-lint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps): Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 (#3105)

Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](stretchr/testify@v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: update concentrated liquidity backport label (#3115)

* feat(osmomath): log2 approximation (#2788)

* feat: osmomath log2 approximation

* lint

* fix comment

* comment

* Update osmomath/decimal.go

* improve accuracy with narrower range

* comment

* implement and test precise log for x >= 1

* tests for negative values

* make non-mutative and test

* bench

* changelog

* remove redundant assignments

* improve comments

* [stableswap]: Cap number of assets and post-scaled asset amounts to ensure pools never overflow (#3055)

* add tests for 10-asset pools with 10B per asset

* add max post-scaled asset check and create pool tests

* add sanity tests for new swap guardrails

* move max scaled asset amt to constant

* add join-pool-internal tests for new functionality

* Remove unused versions in mergify (#3121)

* Query lockup params (#3098)

* change proto

* add grpc & cli query

* test

* set params in genesis

* add test case: setParams & query

* CI: Delete failing step (#3124)

* Delete failing step

* Fix int overflow in test logic

* [x/gamm][stableswap]: Add inverse join/exit tests, fix single asset join bug, and remove uneven ratio joins (#3102)

* add tests for 10-asset pools with 10B per asset

* add max post-scaled asset check and create pool tests

* add sanity tests for new swap guardrails

* move max scaled asset amt to constant

* add join-pool-internal tests for new functionality

* fix single join bug, remove uneven ratio joins, and add inverse join tests

* add error checks to single asset joins

* fix mistake in test case

* remove commented line

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>

* Stableswap implement JoinPoolNoSwap (#2942)

* ...

* add tests and denom validation check

* make format

Co-authored-by: alpo <[email protected]>
Co-authored-by: alpo <[email protected]>

* Make testing suite to ensure queries never alter state (#3001)

* create func to check alter state

* add tests

* format

* Update app/apptesting/test_suite.go

Co-authored-by: Roman <[email protected]>

* remove fmt

* epochs: try to use Invoke

* gamm: use Invoke

* incentives: use Invoke

* lockup: use Invoke

* mint: use Invoke

* pool-incentives: use Invoke

* superfluid: use Invoke

* tokenfactory

* txfees

* format

* fix

Co-authored-by: Roman <[email protected]>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Daniel Farina <[email protected]>
Co-authored-by: JeremyParish69 <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: alpo <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: Roman <[email protected]>
Co-authored-by: Hieu Vu <[email protected]>
Co-authored-by: khanh-notional <[email protected]>
Co-authored-by: Nguyen Thanh Nhan <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Niccolo Raspa <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: alpo <[email protected]>

* Update contracts.yml (#3150)

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: Matt, Park <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: Hieu Vu <[email protected]>
Co-authored-by: Daniel Farina <[email protected]>
Co-authored-by: JeremyParish69 <[email protected]>
Co-authored-by: alpo <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: khanh-notional <[email protected]>
Co-authored-by: Nguyen Thanh Nhan <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Niccolo Raspa <[email protected]>
Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: alpo <[email protected]>
  • Loading branch information
15 people authored Oct 25, 2022
1 parent e38be99 commit 2a9bc7a
Show file tree
Hide file tree
Showing 80 changed files with 5,616 additions and 1,229 deletions.
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

0 comments on commit 2a9bc7a

Please sign in to comment.