diff --git a/docs/band_price_source.md b/docs/band_price_source.md new file mode 100644 index 00000000..b9fb3081 --- /dev/null +++ b/docs/band_price_source.md @@ -0,0 +1,80 @@ +# Integrate mesh security using band oracle price source. + +## Prerequisites + +- Setup mesh-security consumer and provider chains as [integration_consumer](./integration_consumer.md), [integration_provider](./integration_provider.md) +- Choose a price source for 2 chains in [band laozi testnet](https://laozi-testnet6.cosmoscan.io/data-sources), [band mainnet](https://www.cosmoscan.io/data-sources) + +You can request 4 symbols on [oracle script id: 360](https://laozi-testnet6.cosmoscan.io/oracle-script/360) + +- BTC, ETH, USDT, BAND + +## Band Price Feeder + +Band oracle price feeder is design base on cw-band. More details could be found in: + +The contract needs some information to instantiate, which is: + +``` +trading_pair: { + base_asset: String, + quote_asset: String, +} -> Consumer chain denom is base_asset, provider chain denom is quote_asset +client_id: String -> Arbitary string for your request +oracle_script_id: Uint64, -> The data source's id you choose +ask_count: Uint64, -> The number of validator you want to ask (Recommend: 4 on testnet) +min_count: Uint64, -> The minimum number of validator need to answer to aggregate result (Recommend: 3 on testnet) +fee_limit: Vec, -> Data source fee that you willing to pay (Recommend: 250000uband, which is [{"denom": "uband", "amount":"250000"}]) +prepare_gas: Uint64, -> Gas for running prepare phrase (Recommend: 100000) +execute_gas: Uint64, -> Gas for running execute phrase (Recommend: 500000) +minimum_sources: u8, -> The minimum available sources to determine price is aggregated from at least minimum sources (for data integrity) 1 should be ok for testing +price_info_ttl_in_secs: u64, -> The price only can live in an amount of time, after that, they should be update (Recommend: 60) +``` + +## Configure relayer + +1. Create config for consumer chain and band chain as usual. +2. Create path, clients, connections +3. Deploy band price feeder on consumer chain +4. Setup channel using port wasm on consumer chain, port oracle on band chain and version bandchain-1 +5. Using contract address as price source in converter contract +Deploy contract: + +```bash +meshconsumerd tx wasm store ./tests/testdata/mesh_band_price_feed.wasm.gz --node $node --from $wallet --home=$home --chain-id $chainid --keyring-backend test --gas 300000 -y + +band_code_id=$(meshconsumerd q wasm list-code --node $node --output json | jq -r '.code_infos[-1].code_id') +client_id=$(yq e '.paths.{$PATH_NAME}.src.client-id' $relayer_home/config/config.yaml) +oracle_script_id=445 + +init_band_price_feed=$(cat < ./scripts/mesh/update_params.json -meshd tx gov submit-proposal ./scripts/mesh/update_params.json --from test1 --keyring-backend test --home=$home2node1 --node $node2 --chain-id chain-2 -y +meshproviderd tx gov submit-proposal ./scripts/mesh/update_params.json --from test1 --keyring-backend test --home=$home2node1 --node $node2 --chain-id chain-2 -y sleep 7 -meshd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home2node1 --chain-id chain-2 --node $node2 -y +meshproviderd tx gov vote 1 yes --from val1 --keyring-backend test --home=$home2node1 --chain-id chain-2 --node $node2 -y sleep 30 # stake from provider(chain2) '{"bond":{}}'=======bond============ -meshd tx wasm execute $vault '{"bond":{"amount":{"amount": "10000", "denom":"stake"}}}' --from test1 --home=$home2node1 --chain-id chain-2 --keyring-backend test --node $node2 --fees 1stake -y --gas 15406929 +meshproviderd tx wasm execute $vault '{"bond":{"amount":{"amount": "10000", "denom":"stake"}}}' --from test1 --home=$home2node1 --chain-id chain-2 --keyring-backend test --node $node2 --fees 1stake -y --gas 15406929 sleep 7 @@ -74,10 +79,10 @@ account_query=$(cat < $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json @@ -26,25 +26,25 @@ cat $home1/config/genesis.json | jq '.app_state["meshsecurity"]["params"]["epoch cat $home1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json # Allocate genesis accounts (cosmos formatted addresses) -val1=$(meshd keys show val1 --keyring-backend test --home=$home1 -a) -test1=$(meshd keys show test1 --keyring-backend test --home=$home1 -a) -val2=$(meshd keys show val2 --keyring-backend test --home=$home2 -a) -meshd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 -meshd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 -meshd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 +val1=$(meshconsumerd keys show val1 --keyring-backend test --home=$home1 -a) +test1=$(meshconsumerd keys show test1 --keyring-backend test --home=$home1 -a) +val2=$(meshconsumerd keys show val2 --keyring-backend test --home=$home2 -a) +meshconsumerd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 +meshconsumerd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 +meshconsumerd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 cp $home1/config/genesis.json $home2/config/genesis.json # Sign genesis transaction -meshd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home=$home1 -meshd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home=$home2 +meshconsumerd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home=$home1 +meshconsumerd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home=$home2 cp $home2/config/gentx/*.json $home1/config/gentx/ # Collect genesis tx -meshd collect-gentxs --home=$home1 +meshconsumerd collect-gentxs --home=$home1 cp $home1/config/genesis.json $home2/config/genesis.json # Run this to ensure everything worked and that the genesis file is setup correctly -meshd validate-genesis --home=$home1 +meshconsumerd validate-genesis --home=$home1 # change app.toml values VALIDATOR1_APP_TOML=$home1/config/app.toml @@ -67,11 +67,11 @@ sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2 sed -i -E 's|prometheus = false|prometheus = true|g' $VALIDATOR2_CONFIG sed -i -E 's|prometheus_listen_addr = ":26660"|prometheus_listen_addr = ":26630"|g' $VALIDATOR2_CONFIG -node1=$(meshd tendermint show-node-id --home=$home1) -node2=$(meshd tendermint show-node-id --home=$home2) +node1=$(meshconsumerd tendermint show-node-id --home=$home1) +node2=$(meshconsumerd tendermint show-node-id --home=$home2) sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656\"|g" $home1/config/config.toml sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$node1@localhost:26656,$node2@localhost:26656\"|g" $home2/config/config.toml # Start the node (remove the --pruning=nothing flag if historical queries are not needed) -screen -S mesh1-node1 -t mesh1-node1 -d -m meshd start --home=$home1 -screen -S mesh1-node2 -t mesh1-node2 -d -m meshd start --home=$home2 \ No newline at end of file +screen -S mesh1-node1 -t mesh1-node1 -d -m meshconsumerd start --home=$home1 +screen -S mesh1-node2 -t mesh1-node2 -d -m meshconsumerd start --home=$home2 \ No newline at end of file diff --git a/scripts/mesh/testibc/chain2.sh b/scripts/mesh/testibc/chain2.sh index 940e9d6b..59703063 100755 --- a/scripts/mesh/testibc/chain2.sh +++ b/scripts/mesh/testibc/chain2.sh @@ -7,13 +7,13 @@ home2=$HOME/.meshd/chain2/node2 chainid=chain-2 # init chain -meshd init mesh-2 --chain-id $chainid --home=$home1 -meshd init mesh-2 --chain-id $chainid --home=$home2 +meshproviderd init mesh-2 --chain-id $chainid --home=$home1 +meshproviderd init mesh-2 --chain-id $chainid --home=$home2 # keys add -meshd keys add val1 --keyring-backend test --home=$home1 -meshd keys add val2 --keyring-backend test --home=$home2 -meshd keys add test1 --keyring-backend test --home=$home1 +meshproviderd keys add val1 --keyring-backend test --home=$home1 +meshproviderd keys add val2 --keyring-backend test --home=$home2 +meshproviderd keys add test1 --keyring-backend test --home=$home1 # Change parameter token denominations to stake cat $home1/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json @@ -25,24 +25,24 @@ cat $home1/config/genesis.json | jq '.app_state["slashing"]["params"]["signed_bl cat $home1/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="stake"' > $home1/config/tmp_genesis.json && mv $home1/config/tmp_genesis.json $home1/config/genesis.json # Allocate genesis accounts (cosmos formatted addresses) -val1=$(meshd keys show val1 --keyring-backend test --home=$home1 -a) -test1=$(meshd keys show test1 --keyring-backend test --home=$home1 -a) -val2=$(meshd keys show val2 --keyring-backend test --home=$home2 -a) -meshd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 -meshd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 -meshd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 +val1=$(meshproviderd keys show val1 --keyring-backend test --home=$home1 -a) +test1=$(meshproviderd keys show test1 --keyring-backend test --home=$home1 -a) +val2=$(meshproviderd keys show val2 --keyring-backend test --home=$home2 -a) +meshproviderd add-genesis-account $val1 1000000000000stake --keyring-backend test --home=$home1 +meshproviderd add-genesis-account $val2 1000000000000stake --keyring-backend test --home=$home1 +meshproviderd add-genesis-account $test1 1000000000stake --keyring-backend test --home=$home1 cp $home1/config/genesis.json $home2/config/genesis.json # Sign genesis transactions -meshd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home $home1 -meshd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home $home2 +meshproviderd gentx val1 900000000000stake --keyring-backend test --chain-id $chainid --home $home1 +meshproviderd gentx val2 100000000000stake --keyring-backend test --chain-id $chainid --home $home2 cp $home2/config/gentx/*.json $home1/config/gentx/ # Collect genesis tx -meshd collect-gentxs --home $home1 +meshproviderd collect-gentxs --home $home1 # Run this to ensure everything worked and that the genesis file is setup correctly -meshd validate-genesis --home $home1 +meshproviderd validate-genesis --home $home1 cp $home1/config/genesis.json $home2/config/genesis.json # change app.toml values @@ -71,11 +71,11 @@ sed -i -E 's|tcp://0.0.0.0:26656|tcp://0.0.0.0:26663|g' $VALIDATOR2_CONFIG sed -i -E 's|allow_duplicate_ip = false|allow_duplicate_ip = true|g' $VALIDATOR2_CONFIG # peers -NODE1=$(meshd tendermint show-node-id --home=$home1) -NODE2=$(meshd tendermint show-node-id --home=$home2) +NODE1=$(meshproviderd tendermint show-node-id --home=$home1) +NODE2=$(meshproviderd tendermint show-node-id --home=$home2) sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$NODE1@localhost:26666,$NODE2@localhost:26666\"|g" $home1/config/config.toml sed -i -E "s|persistent_peers = \"\"|persistent_peers = \"$NODE1@localhost:26666,$NODE2@localhost:26666\"|g" $home2/config/config.toml # start -screen -S mesh2-node1 -t mesh2-node1 -d -m meshd start --home=$home1 -screen -S mesh2-node2 -t mesh2-node2 -d -m meshd start --home=$home2 \ No newline at end of file +screen -S mesh2-node1 -t mesh2-node1 -d -m meshproviderd start --home=$home1 +screen -S mesh2-node2 -t mesh2-node2 -d -m meshproviderd start --home=$home2 \ No newline at end of file diff --git a/scripts/mesh/testibc/config.yaml b/scripts/mesh/testibc/config.yaml index ab87fa2f..05ec1d9f 100644 --- a/scripts/mesh/testibc/config.yaml +++ b/scripts/mesh/testibc/config.yaml @@ -7,7 +7,7 @@ chains: consumer: type: cosmos value: - key-directory: /Users/phamminh/.relayer/keys/chain-1/ + key-directory: [Your directory/keys/chain-1] key: key1 chain-id: chain-1 rpc-addr: http://localhost:26657 @@ -32,7 +32,7 @@ chains: provider: type: cosmos value: - key-directory: /Users/phamminh/.relayer/keys/chain-2/ + key-directory: [Your directory/keys/chain-2] key: key2 chain-id: chain-2 rpc-addr: http://localhost:26667 diff --git a/scripts/mesh/testibc/config_band.yaml b/scripts/mesh/testibc/config_band.yaml new file mode 100644 index 00000000..3bfc3dc8 --- /dev/null +++ b/scripts/mesh/testibc/config_band.yaml @@ -0,0 +1,57 @@ +global: + api-listen-addr: :5183 + timeout: 10s + memo: "" + light-cache-size: 20 +chains: + consumer: + type: cosmos + value: + key-directory: scripts/relayer/keys/chain-1 + key: key1 + chain-id: chain-1 + rpc-addr: http://localhost:26657 + account-prefix: mesh + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01stake + min-gas-amount: 1000000 + max-gas-amount: 0 + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct + extra-codecs: [] + coin-type: 118 + signing-algorithm: "" + broadcast-mode: batch + min-loop-duration: 0s + extension-options: [] + feegrants: null + band: + type: cosmos + value: + key-directory: scripts/relayer/keys/band-laozi-testnet6 + key: testnet + chain-id: band-laozi-testnet6 + rpc-addr: https://rpc.laozi-testnet6.bandchain.org:443 + account-prefix: band + keyring-backend: test + gas-adjustment: 1.2 + gas-prices: 0.01uband + min-gas-amount: 1000000 + max-gas-amount: 0 + debug: false + timeout: 20s + block-timeout: "" + output-format: json + sign-mode: direct + extra-codecs: [] + coin-type: 494 + signing-algorithm: "" + broadcast-mode: batch + min-loop-duration: 0s + extension-options: [] + feegrants: null +paths: {} diff --git a/scripts/mesh/testibc/faucet.js b/scripts/mesh/testibc/faucet.js new file mode 100644 index 00000000..7f009893 --- /dev/null +++ b/scripts/mesh/testibc/faucet.js @@ -0,0 +1,22 @@ +async function getFaucet(address) { + const body = { + address: address, + amount: '100', + } + + let options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + }, + body: JSON.stringify(body), + } + + // See https://docs.bandchain.org/develop/api-endpoints#laozi-testnet-5 + let response = await fetch(`https://laozi-testnet6.bandchain.org/faucet`, options) + + console.log(response) + } + +const address = process.argv[2]; +getFaucet(address) diff --git a/scripts/mesh/testibc/instantiate.sh b/scripts/mesh/testibc/instantiate.sh index 599e4756..e2f06273 100755 --- a/scripts/mesh/testibc/instantiate.sh +++ b/scripts/mesh/testibc/instantiate.sh @@ -7,22 +7,18 @@ chainid2=chain-2 node1=tcp://127.0.0.1:26657 node2=tcp://127.0.0.1:26667 -test1=$(meshd keys show test1 --keyring-backend test -a --home=$home1) -val1=$(meshd keys show val1 --keyring-backend test -a --home=$home1) -test2=$(meshd keys show test1 --keyring-backend test -a --home=$home2) -val2=$(meshd keys show val1 --keyring-backend test -a --home=$home2) +test1=$(meshconsumerd keys show test1 --keyring-backend test -a --home=$home1) +val1=$(meshconsumerd keys show val1 --keyring-backend test -a --home=$home1) +test2=$(meshproviderd keys show test1 --keyring-backend test -a --home=$home2) +val2=$(meshproviderd keys show val1 --keyring-backend test -a --home=$home2) # # #=======bootstrap contract consumer -meshd tx wasm store ./tests/testdata/mesh_simple_price_feed.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 +meshconsumerd tx wasm store ./tests/testdata/mesh_virtual_staking.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 sleep 7 -meshd tx wasm store ./tests/testdata/mesh_virtual_staking.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 -sleep 7 -meshd tx wasm store ./tests/testdata/mesh_converter.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 -sleep 7 -meshd tx wasm instantiate 1 '{"native_per_foreign": "0.5"}' --node $node1 --label contract-pricefeed --admin $val1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 3059023 +meshconsumerd tx wasm store ./tests/testdata/mesh_converter.wasm.gz --node $node1 --from $val1 --home=$home1 --chain-id $chainid1 --keyring-backend test --fees 1stake -y --gas 10059023 sleep 7 -price_feed=$(meshd q wasm list-contract-by-code 1 --node $node1 --output json | jq -r '.contracts[0]' ) +price_feed=$(meshconsumerd q wasm list-contract-by-code 1 --node $node1 --output json | jq -r '.contracts[0]' ) echo "price feed contract: $price_feed" init_converter=$(cat < /dev/null && shellcheck "$0" echo "DEV-only: copy from local built instead of downloading" -for contract in mesh_external_staking mesh_converter mesh_native_staking mesh_native_staking_proxy mesh_osmosis_price_provider mesh_remote_price_feed mesh_simple_price_feed \ +for contract in mesh_external_staking mesh_converter mesh_native_staking mesh_native_staking_proxy mesh_osmosis_price_provider mesh_band_price_feed mesh_osmosis_price_feed mesh_simple_price_feed \ mesh_vault mesh_virtual_staking ; do cp -f ../../../mesh-security/artifacts/${contract}.wasm . gzip -fk ${contract}.wasm diff --git a/tests/testdata/mesh_band_price_feed.wasm.gz b/tests/testdata/mesh_band_price_feed.wasm.gz new file mode 100644 index 00000000..357ec578 Binary files /dev/null and b/tests/testdata/mesh_band_price_feed.wasm.gz differ diff --git a/tests/testdata/mesh_converter.wasm.gz b/tests/testdata/mesh_converter.wasm.gz index 65c15585..85925eaf 100644 Binary files a/tests/testdata/mesh_converter.wasm.gz and b/tests/testdata/mesh_converter.wasm.gz differ diff --git a/tests/testdata/mesh_external_staking.wasm.gz b/tests/testdata/mesh_external_staking.wasm.gz index 41b51f7c..292a1bc6 100644 Binary files a/tests/testdata/mesh_external_staking.wasm.gz and b/tests/testdata/mesh_external_staking.wasm.gz differ diff --git a/tests/testdata/mesh_native_staking.wasm.gz b/tests/testdata/mesh_native_staking.wasm.gz index 92665068..4ad4a956 100644 Binary files a/tests/testdata/mesh_native_staking.wasm.gz and b/tests/testdata/mesh_native_staking.wasm.gz differ diff --git a/tests/testdata/mesh_native_staking_proxy.wasm.gz b/tests/testdata/mesh_native_staking_proxy.wasm.gz index 448bc9e5..4a272fcd 100644 Binary files a/tests/testdata/mesh_native_staking_proxy.wasm.gz and b/tests/testdata/mesh_native_staking_proxy.wasm.gz differ diff --git a/tests/testdata/mesh_osmosis_price_feed.wasm.gz b/tests/testdata/mesh_osmosis_price_feed.wasm.gz new file mode 100644 index 00000000..2250359b Binary files /dev/null and b/tests/testdata/mesh_osmosis_price_feed.wasm.gz differ diff --git a/tests/testdata/mesh_osmosis_price_provider.wasm.gz b/tests/testdata/mesh_osmosis_price_provider.wasm.gz index 447dc050..cb369462 100644 Binary files a/tests/testdata/mesh_osmosis_price_provider.wasm.gz and b/tests/testdata/mesh_osmosis_price_provider.wasm.gz differ diff --git a/tests/testdata/mesh_simple_price_feed.wasm.gz b/tests/testdata/mesh_simple_price_feed.wasm.gz index 63761789..6f99efaa 100644 Binary files a/tests/testdata/mesh_simple_price_feed.wasm.gz and b/tests/testdata/mesh_simple_price_feed.wasm.gz differ diff --git a/tests/testdata/mesh_vault.wasm.gz b/tests/testdata/mesh_vault.wasm.gz index 583a23b3..2a6e5725 100644 Binary files a/tests/testdata/mesh_vault.wasm.gz and b/tests/testdata/mesh_vault.wasm.gz differ diff --git a/tests/testdata/mesh_virtual_staking.wasm.gz b/tests/testdata/mesh_virtual_staking.wasm.gz index 236b2108..0bc19308 100644 Binary files a/tests/testdata/mesh_virtual_staking.wasm.gz and b/tests/testdata/mesh_virtual_staking.wasm.gz differ diff --git a/tests/testdata/version.txt b/tests/testdata/version.txt index f536e9e0..66a6ad6a 100644 --- a/tests/testdata/version.txt +++ b/tests/testdata/version.txt @@ -1 +1 @@ -9c1a08272a3c580544ae4978bb40ca56f38d6d71 +da560f398b59d3a7430efbc1e71cbb0bcf62ad7a