Skip to content

Commit

Permalink
Merge pull request #210 from quasar-finance/main-strategy
Browse files Browse the repository at this point in the history
Main strategy Rebased branch
  • Loading branch information
akure authored Feb 15, 2023
2 parents 2444ef1 + 7ad6686 commit cc7d85a
Show file tree
Hide file tree
Showing 182 changed files with 4,738 additions and 9,218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
- name: Display go version
run: go version
- name: Go lint
Expand All @@ -38,6 +38,6 @@ jobs:
- name: Show versions
run: rustc -V && cargo -V
- name: Rust lint
run: cd smart-contracts && RUSTFLAGS="-Dwarnings" cargo clippy --workspace -- -D warnings
run: cd smart-contracts && RUSTFLAGS="-Dwarnings" cargo clippy --workspace -- -D warnings
- name: Rust format check
run: cd smart-contracts && cargo fmt --all -- --check
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
- name: Display go version
run: go version
- name: Run all tests
Expand All @@ -43,8 +43,8 @@ jobs:
# uses: docker://cosmwasm/rust-optimizer:0.12.6
# with:
# args: >-
# --rm -v "$(pwd)":/code
# --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target
# --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
- name: Compile wasm code
run: 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/rust-optimizer:0.12.6
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: 1.19
- name: Display go version
run: go version
- name: Build Docker Image
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ node_modules/
vue/

smart-contracts/**/artifacts
smart-contracts/**/target
**/target
local_testnet_run-*nodes/
21 changes: 4 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.19"
ARG RUNNER_IMAGE="gcr.io/distroless/static"
ARG RUNNER_IMAGE="ubuntu"

# --------------------------------------------------------
# Builder
# --------------------------------------------------------

FROM golang:${GO_VERSION}-alpine as builder
FROM golang:${GO_VERSION}-buster as builder

RUN apk add --no-cache \
git \
ca-certificates \
build-base \
linux-headers

# Download go dependencies
WORKDIR /quasar
Expand All @@ -22,13 +17,7 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
go mod download

# Cosmwasm - Download correct libwasmvm version
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a && \
# verify checksum
wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt && \
sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1)


# Copy the remaining files
COPY . .
Expand All @@ -37,9 +26,7 @@ COPY . .
# force it to use static lib (from above) not standard libgo_cosmwasm.so file
# then log output of file /quasar/build/quasarnoded
# then ensure static linking
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/root/go/pkg/mod \
LEDGER_ENABLED=false BUILD_TAGS=muslc LINK_STATICALLY=true make build
RUN go build -o build/quasarnoded ./cmd/quasarnoded

# --------------------------------------------------------
# Runner
Expand Down
41 changes: 2 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,6 @@ MOCKSDIR = $(CURDIR)/testutil/mock

export GO111MODULE = on

# process build tags

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(QUASAR_BUILD_OPTIONS)))
build_tags += gcc
else ifeq (rocksdb,$(findstring rocksdb,$(QUASAR_BUILD_OPTIONS)))
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
whitespace += $(whitespace)
Expand All @@ -59,11 +26,7 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=quasar \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)"

ifeq (cleveldb,$(findstring cleveldb,$(QUASAR_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
else ifeq (rocksdb,$(findstring rocksdb,$(QUASAR_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb
endif

ifeq (,$(findstring nostrip,$(QUASAR_BUILD_OPTIONS)))
ldflags += -w -s
endif
Expand All @@ -90,7 +53,7 @@ BUILD_TARGETS := build install
build: BUILD_ARGS=-o $(BUILDDIR)/

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
GOWORK=off go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/quasarnoded
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/quasarnoded

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/
Expand Down
15 changes: 15 additions & 0 deletions demos/orion-manual-demo/LP-strategy-demo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# LP-strategy demo

## Introduction
The LP strategy demo shows how to test the current version of the LP-strategy. This current version only executes the actual strategy part of the LP-strategy, meaning sending tokens to osmosis, joining a pool through join-swap extern-amount-in and locking the tokens.

## setup
To get this demo working, at the minimum a local [osmosis](https://github.com/osmosis-labs/osmosis) release >= v13 such as the [13.1.2](https://github.com/osmosis-labs/osmosis/releases/tag/v13.1.2) release, the local quasarnoded contained in this repo and the [go relayer](https://github.com/cosmos/relayer/releases/tag/v2.1.2). Optionally, if packet forwarding needs to be tested aswell, a local chain of that token is also needed. Most logical is to try this with [gaiad](https://github.com/cosmos/gaia/releases/tag/v7.1.0) for uatom.

## execution
the `run_all.sh` script sets up the local chains, and starts to run the go relayer. The current setup of the go relayer assumes that a local gaiad instance is running. Through `create_and_execute_contract.sh`, a contract is setup and a channel between the contract and the ica host on osmosis is made. The contract is now ready to be interacted with.

## what's where
The contract currently provides 2 entry points: `TransferJoinLock` and `DepositAndLockTokens`; `TransferJoinLock` is the entrypoint as expected to be used and called by the bookkeeping vault. `DepositAndLockTokens` allows for more parameters to be set by the caller. This message does not trigger a transfer. Eventually this will be removed and replaced with better testing setups.

Internally, after one of the two initial execute messages is called, an ibc packet is dispatched, the sequence number is saved and an enum is saved. On the ibc ack, the original message's enum is looked up in the contracts state and a new ibc message is dispatched. The message are done in the following order. ibc_transfer -> join_pool_extern_swap_amount_in -> lock_tokens. ibc acks to transfer messages are provided by our local transfer decorator, found in `decorators/ibc_transfer_wasm_decorator.go`
2 changes: 1 addition & 1 deletion demos/orion-manual-demo/cosmos_localnet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/sh

# Configure variables
BINARY=gaiad
Expand Down
35 changes: 29 additions & 6 deletions demos/orion-manual-demo/create_and_execute_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ RPC="http://127.0.0.1:26659"
NODE="--node $RPC"
TXFLAG="$NODE --chain-id $CHAIN_ID --gas-prices 10$FEE_DENOM --gas auto --gas-adjustment 1.3"
echo $NODE
# the callback_address is the address of the orion module
INIT='{"callback_address":"quasar14yjkz7yxapuee3d7qkhwzlumwrarayfh0pycxc"}'
MSG='{"register_ica_on_zone":{"zone_id":"osmosis"}}'
# lock_period is 60 for 60 sec, in prod should be at least: 60 sec/min * 60 min/hr * 24hr * 14days "1209600"
# pool_id is hardcoded to 1 for this testing setup, expected to be done by the instantiater on local/testnet
# pool_denom should be looked up and hardcoded aswell
# base_denom: base_denom should be the denom of the token on osmosos, for now uosmo
# local_denom: the denom of the token used locally, in this testing case: the denom of the path transfer/channel-1/uosmo
# quote_denom is the denom other denom in the pool, stake for now
INIT='{"lock_period":60,"pool_id":1,"pool_denom":"gamm/pool/1","base_denom":"uosmo","local_denom":"ibc/0471F1C4E7AFD3F07702BEF6DC365268D64570F7C1FDC98EA6098DD6DE59817B","quote_denom":"stake","return_source_channel":"channel-0","transfer_channel":"channel-1"}'

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/rust-optimizer:0.12.6

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

Expand All @@ -26,7 +30,26 @@ OUT=$(quasarnoded tx wasm instantiate $CODE_ID "$INIT" --from alice --keyring-ba
ADDR=$(quasarnoded query wasm list-contract-by-code $CODE_ID --output json $NODE | jq -r '.contracts[0]')
echo "Got address of deployed contract = $ADDR"

echo "Executing register ica message... ('$MSG')"
quasarnoded tx wasm execute $ADDR "$MSG" -y --from alice --keyring-backend test --gas-prices 10$FEE_DENOM --gas auto --gas-adjustment 1.3 $NODE --chain-id $CHAIN_ID
rly transact channel quasar_osmosis --src-port "wasm.$ADDR" --dst-port icqhost --order unordered --version icq-1 --override
rly transact channel quasar_osmosis --src-port "wasm.$ADDR" --dst-port icahost --order ordered --version '{"version":"ics27-1","encoding":"proto3","tx_type":"sdk_multi_msg","controller_connection_id":"connection-1","host_connection_id":"connection-0"}' --override

QMSG='{"channels": {}}'
CADDR=$(quasarnoded query wasm contract-state smart $ADDR "$QMSG" --output json | jq '.data.channels[] | select(.counterparty_endpoint.port_id=="icahost").channel_type.ica.counter_party_address')
CCHAN=$(quasarnoded query wasm contract-state smart $ADDR "$QMSG" --output json | jq '.data.channels[] | select(.counterparty_endpoint.port_id=="icahost").id')


AMOUNT="100000uosmo"
HOME_OSMOSIS=$HOME/.osmosis
# echo $CADDR
# echo "preloading the ICA address with $AMOUNT to play around with"
BANKTX=$(printf 'osmosisd tx bank send bob %s %s -y --keyring-backend test --node tcp://localhost:26679 --chain-id osmosis --gas 583610 --home %s' $CADDR $AMOUNT $HOME_OSMOSIS)
echo $BANKTX
# $BANKTX

# BONDMSG='{"bond": {"id": "my-id"}}'
# BOND=$(printf 'quasarnoded tx wasm execute %s '%s' -y --from alice --keyring-backend test --gas-prices 10uqsr --gas auto --gas-adjustment 1.3 --node http://127.0.0.1:26659 --chain-id quasar --amount 1000ibc/0471F1C4E7AFD3F07702BEF6DC365268D64570F7C1FDC98EA6098DD6DE59817\n' $ADDR $BONDMSG)

# echo "bonding tokens, to replay: "
# echo $BOND
# $BOND
cd -
2 changes: 1 addition & 1 deletion demos/orion-manual-demo/hermes_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Specify the verbosity for the relayer logging output. Default: 'info'
# Valid options are 'error', 'warn', 'info', 'debug', 'trace'.
log_level = 'debug'
log_level = 'info'


# Specify the mode to be used by the relayer. [Required]
Expand Down
37 changes: 35 additions & 2 deletions demos/orion-manual-demo/osmo_localnet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/sh

# Configure variables
BINARY=osmosisd
Expand Down Expand Up @@ -81,7 +81,6 @@ 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 = {
halven_started_epoch: "0",
minter: {
epoch_provisions: "0.000000000000000000"
},
Expand Down Expand Up @@ -144,6 +143,38 @@ cat $HOME_OSMOSIS/config/genesis_original.json |
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.MsgLockTokens",
"/osmosis.superfluid.MsgSuperfluidUnbondLock"
]
}
}
}' |
jq '.app_state.interchainquery = {
host_port: "icqhost",
params: {
Expand All @@ -153,6 +184,8 @@ cat $HOME_OSMOSIS/config/genesis_original.json |
"/cosmos.bank.v1beta1.Query/Balance",
"/osmosis.epochs.v1beta1.Query/EpochInfos",
"/osmosis.gamm.v1beta1.Query/Pool",
"/osmosis.gamm.v1beta1.Query/CalcExitPoolCoinsFromShares",
"/osmosis.gamm.v2.Query/SpotPrice",
"/osmosis.poolincentives.v1beta1.Query/LockableDurations",
"/osmosis.mint.v1beta1.Query/Params",
"/osmosis.mint.v1beta1.Query/EpochProvisions",
Expand Down
2 changes: 1 addition & 1 deletion demos/orion-manual-demo/quasar_localnet.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/sh

## This script helps to create a basic version of the quasar chain genesis file for development purposes.
## However it will need some manual modifications before you start the chain to incorporate the custom fields.
Expand Down
Loading

0 comments on commit cc7d85a

Please sign in to comment.