Skip to content

Commit

Permalink
Merge branch 'main' into terpay/two-pool-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
davidterpay authored Aug 7, 2023
2 parents 5e12273 + 03d558b commit 3508497
Show file tree
Hide file tree
Showing 102 changed files with 5,782 additions and 1,316 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/protocol-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Render and Deploy Docs

on:
workflow_dispatch:
push:
branches:
- main

jobs:

build:
name: Render and deploy protocol and API docs
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout the source code
uses: actions/checkout@v3
with:
lfs: true
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Load Rust caching
uses: astriaorg/[email protected]
- name: Load get-version action to grab version component of deployment path
uses: battila7/get-version-action@v2
id: get_version
- name: Print version component of deployment path
run: echo ${{ steps.get_version.outputs.version }}
- name: Install mdbook
run: cargo install mdbook mdbook-katex mdbook-mermaid
- name: Build protocol spec
run: cd docs/protocol && mdbook build
- name: Move protocol spec to subdirectory & Deploy
env:
DO_DOCS_PK: ${{ secrets.DO_DOCS_PK }}
DO_DOCS_IP: ${{ secrets.DO_DOCS_IP }}
run: |
cd docs/protocol
if [ -d "do-tmp" ]; then rm -rf do-tmp; fi
mkdir do-tmp
mv book do-tmp/${{ steps.get_version.outputs.version }}
tree do-tmp
which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
which rsync || ( apt-get update -y && apt-get install rsync -y )
eval $(ssh-agent -s)
ssh-add <(echo "$DO_DOCS_PK" )
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keyscan $DO_DOCS_IP >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
cd do-tmp/main
scp -r * root@$DO_DOCS_IP:/var/www/html
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,8 @@ blocks.db
tests/cl-genesis-positions/script
tests/cl-genesis-positions/*.json

# Docs
docs/protocol/book

# Release folder
dist/
dist/
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Features

* [#5072](https://github.com/osmosis-labs/osmosis/pull/5072) IBC-hooks: Add support for async acks when processing onRecvPacket

### State Breaking

* [#5532](https://github.com/osmosis-labs/osmosis/pull/5532) fix: Fix x/tokenfactory genesis import denoms reset x/bank existing denom metadata
Expand Down Expand Up @@ -74,6 +78,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#5927] (https://github.com/osmosis-labs/osmosis/pull/5927) Add gas metering to x/tokenfactory trackBeforeSend hook
* [#5890](https://github.com/osmosis-labs/osmosis/pull/5890) feat: CreateCLPool & LinkCFMMtoCL pool into one gov-prop
* [#5964](https://github.com/osmosis-labs/osmosis/pull/5964) fix e2e test concurrency bugs
* [#5948] (https://github.com/osmosis-labs/osmosis/pull/5948) Parameterizing Pool Type Information in Protorev
* [#5953] (https://github.com/osmosis-labs/osmosis/pull/5953) Supporting two pool routes in ProtoRev

### Minor improvements & Bug Fixes
Expand Down
9 changes: 7 additions & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
appKeepers.keys[ibchookstypes.StoreKey],
appKeepers.GetSubspace(ibchookstypes.ModuleName),
appKeepers.IBCKeeper.ChannelKeeper,
nil,
)
appKeepers.IBCHooksKeeper = &hooksKeeper
appKeepers.IBCHooksKeeper = hooksKeeper

appKeepers.WireICS20PreWasmKeeper(appCodec, bApp, appKeepers.IBCHooksKeeper)

Expand Down Expand Up @@ -428,7 +431,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.keys[tokenfactorytypes.StoreKey],
appKeepers.GetSubspace(tokenfactorytypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper.WithMintCoinsRestriction(tokenfactorytypes.NewTokenFactoryDenomMintCoinsRestriction()),
appKeepers.BankKeeper,
appKeepers.DistrKeeper,
)
appKeepers.TokenFactoryKeeper = &tokenFactoryKeeper
Expand Down Expand Up @@ -477,6 +480,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.RateLimitingICS4Wrapper.ContractKeeper = appKeepers.ContractKeeper
appKeepers.Ics20WasmHooks.ContractKeeper = appKeepers.ContractKeeper
appKeepers.CosmwasmPoolKeeper.SetContractKeeper(appKeepers.ContractKeeper)
appKeepers.IBCHooksKeeper.ContractKeeper = appKeepers.ContractKeeper

// set token factory contract keeper
appKeepers.TokenFactoryKeeper.SetContractKeeper(appKeepers.ContractKeeper)
Expand Down Expand Up @@ -671,6 +675,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(icqtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(cosmwasmpooltypes.ModuleName)
paramsKeeper.Subspace(ibchookstypes.ModuleName)

return paramsKeeper
}
Expand Down
2 changes: 1 addition & 1 deletion app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func appModules(
tokenfactory.NewAppModule(*app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
valsetprefmodule.NewAppModule(appCodec, *app.ValidatorSetPreferenceKeeper),
ibcratelimitmodule.NewAppModule(*app.RateLimitingICS4Wrapper),
ibc_hooks.NewAppModule(app.AccountKeeper),
ibc_hooks.NewAppModule(app.AccountKeeper, *app.IBCHooksKeeper),
icq.NewAppModule(*app.AppKeepers.ICQKeeper),
packetforward.NewAppModule(app.PacketForwardKeeper),
cwpoolmodule.NewAppModule(appCodec, *app.CosmwasmPoolKeeper),
Expand Down
7 changes: 1 addition & 6 deletions app/upgrades/v17/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,7 @@ func CreateUpgradeHandler(
keepers.DistrKeeper.SetFeePool(ctx, feePool)

// Reset the pool weights upon upgrade. This will add support for CW pools on ProtoRev.
keepers.ProtoRevKeeper.SetPoolWeights(ctx, types.PoolWeights{
BalancerWeight: 1,
StableWeight: 4,
ConcentratedWeight: 300,
CosmwasmWeight: 300,
})
keepers.ProtoRevKeeper.SetInfoByPoolType(ctx, types.DefaultPoolTypeInfo)

return migrations, nil
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/osmosisd/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,31 @@ const defaultConfigTemplate = `# This is a TOML config file.
# The network chain ID
chain-id = "{{ .ChainID }}"
# The keyring's backend, where the keys are stored (os|file|kwallet|pass|test|memory)
keyring-backend = "{{ .KeyringBackend }}"
# CLI output format (text|json)
output = "{{ .Output }}"
# <host>:<port> to Tendermint RPC interface for this chain
node = "{{ .Node }}"
# Transaction broadcasting mode (sync|async)
broadcast-mode = "{{ .BroadcastMode }}"
# Human-readable denoms
# If enabled, when using CLI, user can input base denoms (baseatom, basescrt, baseweth, basewbtc, basewbtc.grv etc.) instead of their ibc equivalents.
# Human-readable denoms: Input
# If enabled, when using CLI, user can input 0 exponent denoms (atom, scrt, avax, wbtc, etc.) instead of their ibc equivalents.
# Note, this will also change the coin's value to it's base value if the input or flag is a coin.
# Example:
# * 10.45atom input will automatically change to 10450000ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2
# * uakt will change to ibc/1480B8FD20AD5FCAE81EA87584D269547DD4D436843C1D20F15E00EB64743EF4
# * 12000000uscrt will change to 12000000ibc/0954E1C28EB7AF5B72D24F3BC2B47BBB2FDF91BDDFD57B74B99E133AED40972A
# This feature isn't stable yet, and outputs will change in subsequent releases
human-readable-denoms-input = {{ .HumanReadableDenomsInput }}
# If enabled, CLI response return base denoms (baseatom, basescrt, baseweth, basewbtc, basewbtc.grv etc.) instead of their ibc equivalents.
# Human-readable denoms: Output
# If enabled, CLI response return base denoms (uatom, uscrt, wavax-wei, wbtc-satoshi, etc.) instead of their ibc equivalents.
# This feature isn't stable yet, and outputs will change in subsequent releases
human-readable-denoms-output = {{ .HumanReadableDenomsOutput }}
Expand Down
89 changes: 71 additions & 18 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ type Asset struct {
}

type DenomUnit struct {
Denom string `json:"denom"`
Exponent uint64 `json:"exponent"`
Denom string `json:"denom"`
Exponent uint64 `json:"exponent"`
Aliases []string `json:"aliases"`
}

type Trace struct {
Expand All @@ -79,8 +80,8 @@ type Trace struct {
}

type DenomUnitMap struct {
Base string
DenomUnits []DenomUnit `json:"denom_units"`
Base string
Exponent uint64 `json:"exponent"`
}

var (
Expand Down Expand Up @@ -143,16 +144,38 @@ func loadAssetList(initClientCtx client.Context, cmd *cobra.Command, basedenomTo

if basedenomToIBC {
for _, asset := range assetList.Assets {
DenomUnitMap := DenomUnitMap{
Base: asset.Base,
DenomUnits: asset.DenomUnits,
// Each asset has a list of denom units. A majority of them have 2 entries, one being the base 0 exponent denom and the other being a larger exponent denom.
// An example for tether:
// * Exponent 0: uusdt
// * Exponent 6: usdt
// This implies that if a usdt value is given, in order to convert it to it's base denom (uusdt), we need to multiply the provided value by 10^6.
for i, denomUnit := range asset.DenomUnits {
DenomUnitMap := DenomUnitMap{
Base: asset.Base,
Exponent: asset.DenomUnits[i].Exponent,
}
// The 0 exponent denom is the base denom.
if asset.DenomUnits[i].Exponent == 0 {
// To make everyone's life harder, some assets have multiple base denom aliases. For example, the asset list has the following base aliases for the asset "luna":
// * uluna
// * microluna
for _, alias := range denomUnit.Aliases {
baseMap[strings.ToLower(alias)] = DenomUnitMap
}
} else {
// Otherwise we just store the denom alias for that exponent.
baseMap[strings.ToLower(denomUnit.Denom)] = DenomUnitMap
}
}
baseMap["base"+strings.ToLower(asset.Symbol)] = DenomUnitMap
}
}
if IBCtoBasedenom {
// We just store a link from the first base denom alias to the IBC denom. This is just used for display purposes on the terminal's output.
for _, asset := range assetList.Assets {
baseMapRev[asset.Base] = "base" + strings.ToLower(asset.Symbol)
if len(asset.DenomUnits) > 0 && asset.DenomUnits[0].Exponent == 0 && len(asset.DenomUnits[0].Aliases) > 0 {
baseDenom := asset.DenomUnits[0].Aliases[0]
baseMapRev[asset.Base] = strings.ToLower(baseDenom)
}
}
}
return baseMap, baseMapRev
Expand Down Expand Up @@ -295,17 +318,20 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
for i, arg := range args {
lowerCaseArg := strings.ToLower(arg)
lowerCaseArgArray := strings.Split(lowerCaseArg, ",")
re := regexp.MustCompile(`^(\d+)(.+)`)

re := regexp.MustCompile(`^([\d.]+)(\D+)$`)

for i, lowerCaseArg := range lowerCaseArgArray {
match := re.FindStringSubmatch(lowerCaseArg)
if len(match) == 3 {
value, denom := match[1], match[2]
// If the index has a length of 3 then it has a number and a denom (this is a coin object)
// Note, index 0 is the entire string, index 1 is the number, and index 2 is the denom
if _, ok := assetMap[match[2]]; ok {
// In this case, we just need to replace the denom with the base denom and retain the number
lowerCaseArgArray[i] = match[1] + assetMap[match[2]].Base
transformedCoin, err := transformCoinValueToBaseInt(value, denom, assetMap)
if err != nil {
continue
}
lowerCaseArgArray[i] = transformedCoin
} else {
if _, ok := assetMap[lowerCaseArg]; ok {
// In this case, we just need to replace the denom with the base denom
Expand All @@ -321,17 +347,19 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
lowerCaseFlagValue := strings.ToLower(flag.Value.String())
lowerCaseFlagValueArray := strings.Split(lowerCaseFlagValue, ",")

re := regexp.MustCompile(`^(\d+)(.+)`)
re := regexp.MustCompile(`^([\d.]+)(\D+)$`)

for i, lowerCaseFlagValue := range lowerCaseFlagValueArray {
match := re.FindStringSubmatch(lowerCaseFlagValue)
if len(match) == 3 {
value, denom := match[1], match[2]
// If the index has a length of 3 then it has a number and a denom (this is a coin object)
// Note, index 0 is the entire string, index 1 is the number, and index 2 is the denom
if _, ok := assetMap[match[2]]; ok {
// In this case, we just need to replace the denom with the base denom and retain the number
lowerCaseFlagValueArray[i] = strings.Replace(lowerCaseFlagValue, match[2], assetMap[match[2]].Base, -1)
transformedCoin, err := transformCoinValueToBaseInt(value, denom, assetMap)
if err != nil {
continue
}
lowerCaseFlagValueArray[i] = transformedCoin
} else {
if _, ok := assetMap[lowerCaseFlagValue]; ok {
// Otherwise, we just need to replace the denom with the base denom
Expand Down Expand Up @@ -407,7 +435,7 @@ func initAppConfig() (string, interface{}) {
###############################################################################
[osmosis-mempool]
# This is the max allowed gas any tx.
# This is the max allowed gas any tx.
# This is only for local mempool purposes, and thus is only ran on check tx.
max-gas-wanted-per-tx = "25000000"
Expand Down Expand Up @@ -676,3 +704,28 @@ source ~/.zshrc
},
})
}

// transformCoinValueToBaseInt transforms a cli input that has been split into a number and a denom into it's base int value and base denom.
// i.e. 10.7osmo -> 10700000uosmo
// 12atom -> 12000000uatom
// 15000000uakt -> 15000000uakt (does nothing since it's already in base denom format)
func transformCoinValueToBaseInt(coinValue, coinDenom string, assetMap map[string]DenomUnitMap) (string, error) {
// If the index has a length of 3 then it has a number and a denom (this is a coin object)
// Note, index 0 is the entire string, index 1 is the number, and index 2 is the denom
if denomUnitMap, ok := assetMap[coinDenom]; ok {
// In this case, we just need to replace the denom with the base denom and retain the number
if denomUnitMap.Exponent != 0 {
coinDec, err := sdk.NewDecFromStr(coinValue)
if err != nil {
return "", err
}
transformedCoinValue := coinDec.Mul(sdk.MustNewDecFromStr("10").Power(denomUnitMap.Exponent))
transformedCoinValueInt := transformedCoinValue.TruncateInt()
transformedCoinValueStr := transformedCoinValueInt.String()
return transformedCoinValueStr + assetMap[coinDenom].Base, nil
} else {
return coinValue + assetMap[coinDenom].Base, nil
}
}
return "", fmt.Errorf("denom %s not found in asset map", coinDenom)
}
2 changes: 1 addition & 1 deletion cosmwasm/contracts/crosschain-registry/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ mod tests {
let unauthorized_remove_msg = ExecuteMsg::ModifyContractAlias {
operations: vec![ContractAliasInput {
operation: Operation::Remove,
alias: alias,
alias,
address: Some(address),
new_alias: None,
}],
Expand Down
16 changes: 16 additions & 0 deletions docs/protocol/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[book]
authors = ["Osmosis Labs"]
language = "en"
multilingual = false
src = "src"
title = "The Osmosis Protocol"

[preprocessor.katex]

[preprocessor.mermaid]
command = "mdbook-mermaid"

[output.html]
curly-quotes = true
fold = { enable = true, level = 1 }
git-repository-url = "https://github.com/osmosis-labs/osmosis"
12 changes: 12 additions & 0 deletions docs/protocol/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Summary

[Osmosis](./osmosis.md)
- [Decentralized Exchange](./core_dex.md)
- [Weighted Pool](./dex/weighted.md)
- [Stableswap Pool](./dex/stableswap.md)
- [Concentrated Pool](./dex/concentrated.md)
- [Cosmwasm Pool](./dex/cosmwasm.md)
- [Governance](./governance.md)
- [Staking](./staking.md)
- [Smart Contracts](./smartcontracts.md)
- [Ecosystem](./ecosystem.md)
12 changes: 12 additions & 0 deletions docs/protocol/src/core_dex.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Decentralized Exchange

Osmosis is a decentralized automated market maker (AMM) protocol built using Cosmos SDK that represents a flexible building block for programmable liquidity.

By separating the AMM curve logic and math from the core swapping functionality, Osmosis becomes an extensible AMM that can incorporate any number of swap curves and pool types. This includes:

- Traditional 50/50 weighted pools
- Custom weights like 80/20 for controlled exposure
- Solidly-style Stableswap curve
- Concentrated Liquidity pools
- CosmWasm pools

1 change: 1 addition & 0 deletions docs/protocol/src/dex/concentrated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Concentrated Pool
1 change: 1 addition & 0 deletions docs/protocol/src/dex/cosmwams.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CosmWasm Pool
1 change: 1 addition & 0 deletions docs/protocol/src/dex/cosmwasm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Cosmwasm Pool
1 change: 1 addition & 0 deletions docs/protocol/src/dex/stableswap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Stableswap Pool
Loading

0 comments on commit 3508497

Please sign in to comment.