Skip to content

Commit

Permalink
feat: add cl vault (#445)
Browse files Browse the repository at this point in the history
Co-authored-by: LaurensKubat <[email protected]>
Co-authored-by: nahem <[email protected]>
Co-authored-by: magiodev <[email protected]>
  • Loading branch information
4 people authored Sep 13, 2023
1 parent 0c93807 commit 79a87f8
Show file tree
Hide file tree
Showing 96 changed files with 9,896 additions and 2,873 deletions.
32 changes: 31 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.rs
**/**.go
go.mod
go.sum
Expand Down Expand Up @@ -81,3 +80,34 @@ jobs:
path: |
smart-contracts/artifacts/basic_vault.wasm
smart-contracts/artifacts/lp_strategy.wasm
smart-contracts/artifacts/cl_vault.wasm
test-test-tube:
runs-on: ubuntu-latest
needs: build-rust
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Get git diff
uses: technote-space/[email protected]
with:
PATTERNS: |
**/**.rs
Makefile
.github/workflows/build.yml
- name: Download contracts
if: env.GIT_DIFF
uses: actions/download-artifact@v3
with:
name:
smart-contracts
- name: Install Rust
if: env.GIT_DIFF
uses: dtolnay/rust-toolchain@stable
- name: the classic ls
run: ls -R
- name: Move the cl-vault
if: env.GIT_DIFF
run: mkdir -p smart-contracts/contracts/cl-vault/test-tube-build/wasm32-unknown-unknown/release && mv ./cl_vault.wasm smart-contracts/contracts/cl-vault/test-tube-build/wasm32-unknown-unknown/release/cl_vault.wasm
- name: Run test-tube tests
if: env.GIT_DIFF
run: cd smart-contracts && cargo test --package cl-vault --lib -- test_tube::* --nocapture --ignored
1 change: 1 addition & 0 deletions demos/cl-vault-demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logs
18 changes: 18 additions & 0 deletions demos/cl-vault-demo/demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# CL-vault demo

In this demo we instantiate and deposit into a CL-pool using the cl-vault contract.

<!-- We then modify the range of that CL-vault contract -->

## Setup

```zsh
./osmo_localnet.sh
./local_execute_contract.sh
```

## For testnet

```zsh
./testnet_execute_contract.sh
```
1 change: 1 addition & 0 deletions demos/cl-vault-demo/keys/osmo.key
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rabbit garlic monitor wish pony magic budget someone room torch celery empower word assume digital rack electric weapon urban foot sketch jelly wet myself
44 changes: 44 additions & 0 deletions demos/cl-vault-demo/local_execute_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/sh

set -e

on_error() {
echo "Some error occurred"

afplay /System/Library/Sounds/Sosumi.aiff
say -r 60 you suck
}

trap 'on_error' ERR

CHAIN_ID="osmosis"
TESTNET_NAME="osmosis"
FEE_DENOM="uosmo"
RPC="http://127.0.0.1:26679"
NODE="--node $RPC"
TXFLAG="$NODE --chain-id $CHAIN_ID --gas-prices 10$FEE_DENOM --gas auto --gas-adjustment 1.3"
echo $NODE

# Alice: osmo1sqlsc5024sszglyh7pswk5hfpc5xtl77wcmrz0
# Bob: osmo1ez43ye5qn3q2zwh8uvswppvducwnkq6wjqc87d
INIT='{"thesis":"hello world","name":"Distilled","admin":"osmo1sqlsc5024sszglyh7pswk5hfpc5xtl77wcmrz0","range_admin":"osmo1sqlsc5024sszglyh7pswk5hfpc5xtl77wcmrz0","pool_id":1,"config":{"performance_fee":"0.1","treasury":"osmo1sqlsc5024sszglyh7pswk5hfpc5xtl77wcmrz0","swap_max_slippage":"0.01"},"vault_token_subdenom":"test-cl-vault-1","initial_lower_tick":0,"initial_upper_tick":100000}'

cd ../../smart-contracts

# docker run --rm -v "$(pwd)":/code --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry cosmwasm/workspace-optimizer-arm64:0.12.11

echo "Running store code"
RES=$(osmosisd tx wasm store artifacts/cl_vault-aarch64.wasm --from bob --keyring-backend test -y --output json -b block $TXFLAG)
CODE_ID=$(echo $RES | jq -r '.logs[0].events[-1].attributes[1].value')
echo "Got CODE_ID = $CODE_ID"

echo "Deploying contract"
# swallow output
OUT1=$(osmosisd tx wasm instantiate $CODE_ID "$INIT" --from bob --keyring-backend test --label "my first contract" --gas-prices 10$FEE_DENOM --gas auto --gas-adjustment 1.3 -b block -y --admin osmo1sqlsc5024sszglyh7pswk5hfpc5xtl77wcmrz0 $NODE --chain-id $CHAIN_ID)
ADDR1=$(osmosisd query wasm list-contract-by-code $CODE_ID --output json $NODE | jq -r '.contracts[0]')
echo "Got address of deployed contract = $ADDR1"

afplay /System/Library/Sounds/Funk.aiff
say "I want to die"

cd -
257 changes: 257 additions & 0 deletions demos/cl-vault-demo/osmo_localnet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,257 @@
#!/bin/sh

# Configure variables
BINARY=osmosisd
HOME_OSMOSIS=$HOME/.osmosis
CHAIN_ID=osmosis
ALICE="cruise scene law sea push expose scorpion wire trick repair wave quote task dose inner denial alpha favorite certain blouse motion flash split lunch"
BOB="lizard garlic canyon winner cheese tent drip task because ecology clay bridge junk critic track artefact gather harsh deliver unit vacant earth diesel stool"
USER_1="guard cream sadness conduct invite crumble clock pudding hole grit liar hotel maid produce squeeze return argue turtle know drive eight casino maze host"
USER_2="fuel obscure melt april direct second usual hair leave hobby beef bacon solid drum used law mercy worry fat super must ritual bring faculty"
RELAYER_ACC="$(cat ./keys/osmo.key)"

mkdir logs

ALICE_GENESIS_COINS=20000000uosmo,2000000000stake,1000000000000fakestake
BOB_GENESIS_COINS=10000000000000uosmo,1000000000stake,1000000000000fakestake,100000000000000usdc
USER_1_GENESIS_COINS=10000000000stake,10000000000uosmo
USER_2_GENESIS_COINS=10000000000stake,10000000000uosmo
RELAYER_ACC_GENESIS_COINS=10000000uosmo,10000000000stake

echo $HOME_OSMOSIS

rm -rf $HOME_OSMOSIS
# Bootstrap
$BINARY init $CHAIN_ID --chain-id $CHAIN_ID --home $HOME_OSMOSIS

echo $ALICE | $BINARY keys add alice --keyring-backend test --recover --home $HOME_OSMOSIS
echo $BOB | $BINARY keys add bob --keyring-backend test --recover --home $HOME_OSMOSIS
echo $USER_1 | $BINARY keys add user1 --keyring-backend test --recover --home $HOME_OSMOSIS
echo $USER_2 | $BINARY keys add user2 --keyring-backend test --recover --home $HOME_OSMOSIS
echo $RELAYER_ACC | $BINARY keys add relayer_acc --keyring-backend test --recover --home $HOME_OSMOSIS
$BINARY add-genesis-account $($BINARY keys show alice --keyring-backend test -a --home $HOME_OSMOSIS) $ALICE_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY add-genesis-account $($BINARY keys show bob --keyring-backend test -a --home $HOME_OSMOSIS) $BOB_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY add-genesis-account $($BINARY keys show user1 --keyring-backend test -a --home $HOME_OSMOSIS) $USER_1_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY add-genesis-account $($BINARY keys show user2 --keyring-backend test -a --home $HOME_OSMOSIS) $USER_2_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY add-genesis-account $($BINARY keys show relayer_acc --keyring-backend test -a --home $HOME_OSMOSIS) $RELAYER_ACC_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY add-genesis-account osmo15td5pfjkmfn8d6l4t8dc67l3apgt9epw4ct298 $RELAYER_ACC_GENESIS_COINS --home $HOME_OSMOSIS
$BINARY gentx alice 10000000uosmo --chain-id $CHAIN_ID --keyring-backend test --home $HOME_OSMOSIS
$BINARY collect-gentxs --home $HOME_OSMOSIS

# Check platform
platform='unknown'
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
elif [ "$unamestr" = 'Darwin' ]; then
platform='macos'
fi

if [ $platform = 'linux' ]; then
sed -i 's/enable = false/enable = true/g' $HOME_OSMOSIS/config/app.toml
sed -i 's/swagger = false/swagger = true/g' $HOME_OSMOSIS/config/app.toml
sed -i 's/minimum-gas-prices = ""/minimum-gas-prices = "0uosmo"/g' $HOME_OSMOSIS/config/app.toml
sed -i 's+laddr = "tcp://127.0.0.1:26657"+laddr = "tcp://127.0.0.1:26679"+g' $HOME_OSMOSIS/config/config.toml
sed -i 's+node = "tcp://localhost:26657"+node = "tcp://localhost:26679"+g' $HOME_OSMOSIS/config/client.toml
sed -i 's+laddr = "tcp://0.0.0.0:26656"+laddr = "tcp://0.0.0.0:26662"+g' $HOME_OSMOSIS/config/config.toml
sed -i 's+pprof_laddr = "localhost:6060"+pprof_laddr = "localhost:6062"+g' $HOME_OSMOSIS/config/config.toml
sed -i 's+address = "0.0.0.0:9090"+address = "0.0.0.0:9096"+g' $HOME_OSMOSIS/config/app.toml
sed -i 's+address = "0.0.0.0:9091"+address = "0.0.0.0:8092"+g' $HOME_OSMOSIS/config/app.toml
sed -i 's+address = "tcp://0.0.0.0:1317"+address = "tcp://0.0.0.0:1312"+g' $HOME_OSMOSIS/config/app.toml
sed -i 's+address = ":8080"+address = ":8082"+g' $HOME_OSMOSIS/config/app.toml
elif [ $platform = 'macos' ]; then
sed -i'.original' -e 's/enable = false/enable = true/g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's/swagger = false/swagger = true/g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's/minimum-gas-prices = ""/minimum-gas-prices = "0uosmo"/g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's+laddr = "tcp://127.0.0.1:26657"+laddr = "tcp://127.0.0.1:26679"+g' $HOME_OSMOSIS/config/config.toml
sed -i'.original' -e 's+node = "tcp://localhost:26657"+node = "tcp://localhost:26679"+g' $HOME_OSMOSIS/config/client.toml
sed -i'.original' -e 's+laddr = "tcp://0.0.0.0:26656"+laddr = "tcp://0.0.0.0:26662"+g' $HOME_OSMOSIS/config/config.toml
sed -i'.original' -e 's+pprof_laddr = "localhost:6060"+pprof_laddr = "localhost:6062"+g' $HOME_OSMOSIS/config/config.toml
sed -i'.original' -e 's+address = "0.0.0.0:9090"+address = "0.0.0.0:9096"+g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's+address = "0.0.0.0:9091"+address = "0.0.0.0:8092"+g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's+address = "tcp://0.0.0.0:1317"+address = "tcp://0.0.0.0:1312"+g' $HOME_OSMOSIS/config/app.toml
sed -i'.original' -e 's+address = ":8080"+address = ":8082"+g' $HOME_OSMOSIS/config/app.toml
else
echo "only linux and macos platforms are supported, if you are using other platforms you should probably improve this script."

exit 1
sed -i '' 's/enable = false/enable = true/g' $HOME_OSMOSIS/config/app.toml
sed -i '' 's/swagger = false/swagger = true/g' $HOME_OSMOSIS/config/app.toml
fi

cp $HOME_OSMOSIS/config/genesis.json $HOME_OSMOSIS/config/genesis_original.json
cat $HOME_OSMOSIS/config/genesis_original.json |
jq '.app_state.crisis.constant_fee.denom="uosmo"' |
jq '.app_state.staking.params.bond_denom="uosmo"' |
jq '.app_state.mint = {
minter: {
epoch_provisions: "0.000000000000000000"
},
params: {
distribution_proportions: {
community_pool: "0.100000000000000000",
developer_rewards: "0.200000000000000000",
pool_incentives: "0.300000000000000000",
staking: "0.400000000000000000"
},
epoch_identifier: "day",
genesis_epoch_provisions: "5000000.000000000000000000",
mint_denom: "uosmo",
minting_rewards_distribution_start_epoch: "0",
reduction_factor: "0.500000000000000000",
reduction_period_in_epochs: "156",
weighted_developer_rewards_receivers: []
}
}' |
jq '.app_state.incentives = {
last_gauge_id: "0",
lockable_durations: [
"1s",
"120s",
"180s",
"240s"
],
params: {
distr_epoch_identifier: "day"
}
}' |
jq '.app_state.poolincentives = {
distr_info: {
records: [
{
gauge_id: "0",
weight: "10000"
},
{
gauge_id: "1",
weight: "1000"
},
{
gauge_id: "2",
weight: "100"
}
],
total_weight: "11100"
},
lockable_durations: [
"120s",
"180s",
"240s"
],
params: {
minted_denom: "uosmo"
}
}' |
jq '.app_state.txfees.basedenom="uosmo"' |
jq '.app_state.gov.deposit_params.min_deposit=[{denom:"uosmo",amount:"1"}]' |
jq '.app_state.gov.voting_params.voting_period="30s"' |
jq '.app_state.gov.tally_params={quorum:"0.000000000000000001",threshold:"0.5",veto_threshold:"0.334"}' |
jq '.app_state.interchainaccounts = {
host_genesis_state: {
port: "icahost",
params: {
host_enabled: true,
allow_messages: [
"/ibc.applications.transfer.v1.MsgTransfer",
"/cosmos.bank.v1beta1.MsgSend",
"/cosmos.staking.v1beta1.MsgDelegate",
"/cosmos.staking.v1beta1.MsgBeginRedelegate",
"/cosmos.staking.v1beta1.MsgCreateValidator",
"/cosmos.staking.v1beta1.MsgEditValidator",
"/cosmos.staking.v1beta1.MsgUndelegate",
"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
"/cosmos.distribution.v1beta1.MsgSetWithdrawAddress",
"/cosmos.distribution.v1beta1.MsgWithdrawValidatorCommission",
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/cosmos.gov.v1beta1.MsgVote",
"/osmosis.gamm.v1beta1.MsgJoinPool",
"/osmosis.gamm.v1beta1.MsgExitPool",
"/osmosis.gamm.v1beta1.MsgSwapExactAmountIn",
"/osmosis.gamm.v1beta1.MsgSwapExactAmountOut",
"/osmosis.gamm.v1beta1.MsgJoinSwapExternAmountIn",
"/osmosis.gamm.v1beta1.MsgJoinSwapShareAmountOut",
"/osmosis.gamm.v1beta1.MsgExitSwapExternAmountOut",
"/osmosis.gamm.v1beta1.MsgExitSwapShareAmountIn",
"/osmosis.lockup.MsgBeginUnlocking",
"/osmosis.lockup.MsgLockTokens",
"/osmosis.superfluid.MsgSuperfluidUnbondLock"
]
}
}
}' |
jq '.app_state.interchainquery = {
host_port: "icqhost",
params: {
host_enabled: true,
allow_queries: [
"/ibc.applications.transfer.v1.Query/DenomTrace",
"/cosmos.auth.v1beta1.Query/Account",
"/cosmos.auth.v1beta1.Query/Params",
"/cosmos.bank.v1beta1.Query/Balance",
"/cosmos.bank.v1beta1.Query/DenomMetadata",
"/cosmos.bank.v1beta1.Query/Params",
"/cosmos.bank.v1beta1.Query/SupplyOf",
"/cosmos.distribution.v1beta1.Query/Params",
"/cosmos.distribution.v1beta1.Query/DelegatorWithdrawAddress",
"/cosmos.distribution.v1beta1.Query/ValidatorCommission",
"/cosmos.gov.v1beta1.Query/Deposit",
"/cosmos.gov.v1beta1.Query/Params",
"/cosmos.gov.v1beta1.Query/Vote",
"/cosmos.slashing.v1beta1.Query/Params",
"/cosmos.slashing.v1beta1.Query/SigningInfo",
"/cosmos.staking.v1beta1.Query/Delegation",
"/cosmos.staking.v1beta1.Query/Params",
"/cosmos.staking.v1beta1.Query/Validator",
"/osmosis.epochs.v1beta1.Query/EpochInfos",
"/osmosis.epochs.v1beta1.Query/CurrentEpoch",
"/osmosis.gamm.v1beta1.Query/NumPools",
"/osmosis.gamm.v1beta1.Query/TotalLiquidity",
"/osmosis.gamm.v1beta1.Query/Pool",
"/osmosis.gamm.v1beta1.Query/PoolParams",
"/osmosis.gamm.v1beta1.Query/TotalPoolLiquidity",
"/osmosis.gamm.v1beta1.Query/TotalShares",
"/osmosis.gamm.v1beta1.Query/CalcJoinPoolShares",
"/osmosis.gamm.v1beta1.Query/CalcExitPoolCoinsFromShares",
"/osmosis.gamm.v1beta1.Query/CalcJoinPoolNoSwapShares",
"/osmosis.gamm.v1beta1.Query/PoolType",
"/osmosis.gamm.v2.Query/SpotPrice",
"/osmosis.gamm.v1beta1.Query/EstimateSwapExactAmountIn",
"/osmosis.gamm.v1beta1.Query/EstimateSwapExactAmountOut",
"/osmosis.incentives.Query/ModuleToDistributeCoins",
"/osmosis.incentives.Query/LockableDurations",
"/osmosis.lockup.Query/ModuleBalance",
"/osmosis.lockup.Query/ModuleLockedAmount",
"/osmosis.lockup.Query/AccountUnlockableCoins",
"/osmosis.lockup.Query/AccountUnlockingCoins",
"/osmosis.lockup.Query/LockedDenom",
"/osmosis.lockup.Query/LockedByID",
"/osmosis.lockup.Query/NextLockID",
"/osmosis.mint.v1beta1.Query/EpochProvisions",
"/osmosis.mint.v1beta1.Query/Params",
"/osmosis.poolincentives.v1beta1.Query/GaugeIds",
"/osmosis.superfluid.Query/Params",
"/osmosis.superfluid.Query/AssetType",
"/osmosis.superfluid.Query/AllAssets",
"/osmosis.superfluid.Query/AssetMultiplier",
"/osmosis.poolmanager.v1beta1.Query/NumPools",
"/osmosis.poolmanager.v1beta1.Query/EstimateSwapExactAmountIn",
"/osmosis.poolmanager.v1beta1.Query/EstimateSwapExactAmountOut",
"/osmosis.txfees.v1beta1.Query/FeeTokens",
"/osmosis.txfees.v1beta1.Query/DenomSpotPrice",
"/osmosis.txfees.v1beta1.Query/DenomPoolId",
"/osmosis.txfees.v1beta1.Query/BaseDenom",
"/osmosis.tokenfactory.v1beta1.Query/Params",
"/osmosis.tokenfactory.v1beta1.Query/DenomAuthorityMetadata",
"/osmosis.twap.v1beta1.Query/ArithmeticTwap",
"/osmosis.twap.v1beta1.Query/ArithmeticTwapToNow",
"/osmosis.twap.v1beta1.Query/GeometricTwap",
"/osmosis.twap.v1beta1.Query/GeometricTwapToNow",
"/osmosis.twap.v1beta1.Query/Params",
"/osmosis.downtimedetector.v1beta1.Query/RecoveredSinceDowntimeOfLength"
]
}
}' \
>$HOME_OSMOSIS/config/genesis.json

# Start
$BINARY start --home $HOME_OSMOSIS >>./logs/osmo_localnet.log 2>&1
Loading

0 comments on commit 79a87f8

Please sign in to comment.