Skip to content

Commit

Permalink
Merge branch 'main' into ci/prepare-white-whale-crate
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x authored Jan 25, 2024
2 parents 5482e76 + dc80b06 commit 5bfa4a9
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scripts/deployment/deploy_env/base.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if [ -n "$ZSH_VERSION" ]; then
# Using an array for TXFLAG
TXFLAG=(--node $RPC --chain-id $CHAIN_ID --gas-prices 0.55$DENOM --gas auto --gas-adjustment 1.5 -y -b sync --output json)
TXFLAG=(--node $RPC --chain-id $CHAIN_ID --gas-prices 0.15$DENOM --gas auto --gas-adjustment 1.2 -y -b sync --output json)
else
# Using a string for TXFLAG
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices 0.55$DENOM --gas auto --gas-adjustment 1.5 -y -b block --output json"
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices 0.15$DENOM --gas auto --gas-adjustment 1.2 -y -b sync --output json"
fi

export TXFLAG
2 changes: 1 addition & 1 deletion scripts/deployment/deploy_env/base_injective.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if [ -n "$ZSH_VERSION" ]; then
TXFLAG=(--node $RPC --chain-id $CHAIN_ID --gas-prices=500000000inj --gas 10000000 -y -b sync --output json)
else
# Using a string for TXFLAG
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices=500000000inj --gas 10000000 -y -b block --output json"
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices=500000000inj --gas 10000000 -y -b sync --output json"
fi

export TXFLAG
4 changes: 2 additions & 2 deletions scripts/deployment/deploy_env/base_migaloo.env
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if [ -n "$ZSH_VERSION" ]; then
# Using an array for TXFLAG
TXFLAG=(--node $RPC --chain-id $CHAIN_ID --gas-prices 0.25$DENOM --gas auto --gas-adjustment 1.3 -y -b block --output json)
TXFLAG=(--node $RPC --chain-id $CHAIN_ID --gas-prices 1$DENOM --gas auto --gas-adjustment 1.3 -y -b sync --output json)
else
# Using a string for TXFLAG
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices 0.25$DENOM --gas auto --gas-adjustment 1.3 -y -b block --output json"
TXFLAG="--node $RPC --chain-id $CHAIN_ID --gas-prices 1$DENOM --gas auto --gas-adjustment 1.3 -y -b sync --output json"
fi

export TXFLAG
8 changes: 8 additions & 0 deletions scripts/deployment/deploy_env/chain_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ function init_chain_env() {
source <(cat "$project_root_path"/scripts/deployment/deploy_env/base_migaloo.env)
;;

osmosis)
source <(cat "$project_root_path"/scripts/deployment/deploy_env/mainnets/osmosis.env)
;;

osmosis-testnet)
source <(cat "$project_root_path"/scripts/deployment/deploy_env/testnets/osmosis.env)
;;

orai)
source <(cat "$project_root_path"/scripts/deployment/deploy_env/mainnets/orai.env)
;;
Expand Down
4 changes: 4 additions & 0 deletions scripts/deployment/deploy_env/mainnets/osmosis.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export CHAIN_ID="osmosis-1"
export DENOM="uosmo"
export BINARY="osmosisd"
export RPC="https://rpc.osmosis.zone:443"
10 changes: 6 additions & 4 deletions scripts/deployment/deploy_liquidity_hub.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function init_fee_distributor() {
grace_period=21 #default value is 21 epochs
distribution_asset='{"native_token":{"denom":"'$whale_denom'"}}'
epoch_duration=86400000000000 #default value is 1 day, in nanoseconds
genesis_epoch=1689260400000000000 #fill with desired unix time, in nanoseconds
genesis_epoch=1706540400000000000 #fill with desired unix time, in nanoseconds
epoch_config='{"duration":"'$epoch_duration'", "genesis_epoch": "'$genesis_epoch'"}'

init='{"bonding_contract_addr": '"$bonding_contract_addr"', "fee_collector_addr": '"$fee_collector_addr"', "grace_period": "'$grace_period'", "epoch_config": '"$epoch_config"', "distribution_asset": '"$distribution_asset"'}'
Expand All @@ -125,23 +125,25 @@ function init_whale_lair() {
echo -e "\nInitializing the Whale Lair..."

# Prepare the instantiation message
unbonding_period=1209600000000000 # default value is 14 days, in nanoseconds
unbonding_period=86400000000000 # default value is 14 days, in nanoseconds
growth_rate="0.000000064300411522" # this is the value when you interpolate the growth rate to 2X with 365 days of bonding

bonding_assets=$(jq '.contracts[] | select (.wasm == "fee_collector.wasm") | .contract_address' $output_file)
grace_period="21" #default value is 21 epochs
distribution_asset='{"native_token":{"denom":"'$whale_denom'"}}'
epoch_duration="86400000000000" #default value is 1 day, in nanoseconds
genesis_epoch="1689865200000000000" #fill with desired unix time, in nanoseconds
genesis_epoch="1706540400000000000" #fill with desired unix time, in nanoseconds
epoch_config='{"duration":"'$epoch_duration'", "genesis_epoch": "'$genesis_epoch'"}'

init='{"bonding_contract_addr": '"$bonding_contract_addr"', "fee_collector_addr": '"$fee_collector_addr"', "grace_period":
"'$grace_period'", "epoch_config": '"$epoch_config"', "distribution_asset": '"$distribution_asset"'}'

echo "init_whale_lair fn is broken. Fix."
exit 0
#todo fix this message here, it's broken
# Instantiate the contract
code_id=$(jq -r '.contracts[] | select (.wasm == "fee_distributor.wasm") | .code_id' $output_file)
$BINARY tx wasm instantiate $code_id "$init" --from $deployer --label "White Whale Fee Distributor" $TXFLAG --admin $deployer_address
$BINARY tx wasm instantiate $code_id "$init" --from $deployer --label "White Whale Lair" $TXFLAG --admin $deployer_address

# Get contract address
contract_address=$($BINARY query wasm list-contract-by-code $code_id --node $RPC --output json | jq -r '.contracts[-1]')
Expand Down
38 changes: 27 additions & 11 deletions scripts/deployment/extract_pools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ project_root_path=$(realpath "$0" | sed 's|\(.*\)/.*|\1|' | cd ../ | pwd)

# Displays tool usage
function display_usage() {
echo "WW Pool Deployer"
echo -e "\nUsage:./deploy_pool.sh [flags].\n"
echo "WW Pool Extractor"
echo -e "\nUsage:./extract_pools.sh [flags].\n"
echo -e "Available flags:\n"
echo -e " -h \thelp"
echo -e " -c \tThe chain where you want to deploy (juno|juno-testnet|terra|terra-testnet|... check chain_env.sh for the complete list of supported chains)"
echo -e " -p \tPool configuration file to get deployment info from."
echo -e " -c \tThe chain where you want to extract pools on (juno|juno-testnet|terra|terra-testnet|... check chain_env.sh for the complete list of supported chains)"
}

# Generates the label for the given asset pair
Expand All @@ -21,6 +20,8 @@ function generate_label() {
local processed_assets=()

for asset in "${assets[@]}"; do
# reload the original chain env in case it gets overriden by the cw20:* asset case
init_chain_env $chain
local processed_asset="$asset"

# first of, check if the asset is an ibc token. An IBC token can be a native token on the chain it came from, or a token factory token
Expand All @@ -35,6 +36,22 @@ function generate_label() {
# if the denom trace has the pattern factory:*... this is the factory token model adopted by the kujira token factory
elif [[ "$denom_trace_result" == factory:* ]]; then
processed_asset="${denom_trace_result##*:}"

# if the denom trace has the pattern cw20:*...
elif [[ "$denom_trace_result" == cw20:* ]]; then
denom_trace_result=${denom_trace_result#*:}

# remove the cw20: prefix and load the chain env for the chain the token is on
if [[ $denom_trace_result =~ ([a-zA-Z]+)1 ]]; then
x=${BASH_REMATCH[1]}
init_chain_env $x
else
continue
fi

local query='{"token_info":{}}'
local symbol=$($BINARY query wasm contract-state smart $denom_trace_result "$query" --node $RPC --output json | jq -r '.data.symbol')
processed_asset=$symbol
else # else, just use the denom trace result. This can be the case of native tokens being transferred to another chain, i.e. uwhale on terra
processed_asset="$denom_trace_result"
fi
Expand Down Expand Up @@ -115,7 +132,12 @@ function extract_pools() {
done < <(echo "$pairs" | jq -c '.[]')

# Combine all pool entries into a single JSON array and write to the output file
jq -n --argjson pools "$(echo "${pools[@]}" | jq -s '.')" '{pools: $pools}' >"$output_file"
jq -n \
--argjson pools "$(echo "${pools[@]}" | jq -s '.')" \
--arg pool_factory_addr "$pool_factory_addr" \
--arg chain "$CHAIN_ID" \
'{chain: $chain, pool_factory_addr: $pool_factory_addr, pools: $pools }' \
>"$output_file"

echo -e "\n**** Extracted pool data on $CHAIN_ID successfully ****\n"
jq '.' $output_file
Expand All @@ -134,12 +156,6 @@ while getopts $optstring arg; do
chain=$OPTARG
source $deployment_script_dir/deploy_env/chain_env.sh
init_chain_env $OPTARG
if [[ "$chain" = "local" ]]; then
tx_delay=0.5
else
tx_delay=8
fi

extract_pools
;;
h)
Expand Down
106 changes: 106 additions & 0 deletions scripts/deployment/extract_vaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env bash
set -e

# Import the deploy_liquidity_hub script
deployment_script_dir=$(cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)
project_root_path=$(realpath "$0" | sed 's|\(.*\)/.*|\1|' | cd ../ | pwd)

# Displays tool usage
function display_usage() {
echo "WW Vault Extractor"
echo -e "\nUsage:./extract_vaults.sh [flags].\n"
echo -e "Available flags:\n"
echo -e " -h \thelp"
echo -e " -c \tThe chain where you want to extract vaults on (juno|juno-testnet|terra|terra-testnet|... check chain_env.sh for the complete list of supported chains)"
}

function extract_vaults() {
mkdir -p $project_root_path/scripts/deployment/output
output_file=$project_root_path/scripts/deployment/output/"$CHAIN_ID"_vaults.json
deployment_file=$project_root_path/scripts/deployment/output/"$CHAIN_ID"_liquidity_hub_contracts.json
if [[ ! -f "$output_file" ]]; then
# create file to dump results into
echo '{"vaults": []}' | jq '.' >$output_file
fi

vault_factory_addr=$(jq -r '.contracts[] | select (.wasm == "vault_factory.wasm") | .contract_address' $deployment_file)
local limit=30
query='{"vaults":{"limit": '$limit'}}'
local vaults=$($BINARY query wasm contract-state smart $vault_factory_addr "$query" --node $RPC --output json | jq '.data.vaults')
vault_code_id=$(jq -r '.contracts[] | select (.wasm == "vault.wasm") | .code_id' $deployment_file)
lp_code_id=$(jq -r '.contracts[] | select (.wasm == "terraswap_token.wasm") | .code_id' $deployment_file)

echo -e "\nExtracting vaults info...\n"

echo ${vaults[@]}

modified_vaults=()
while IFS= read -r line; do
vault=$(echo $line | jq -r '.vault')
asset_info=$(echo $line | jq -c '.asset_info')

# Generate label for the pair
query='{"config":{}}'
local lp_asset=$($BINARY query wasm contract-state smart $vault "$query" --node $RPC --output json | jq -c '.data.lp_asset')

# Create the vault entry
vault_entry=$(jq --argjson asset_info "$asset_info" --arg vault "$vault" --arg vault_code_id "$vault_code_id" --arg lp_code_id "$lp_code_id" --argjson lp_asset "$lp_asset" -n '{
vault: $vault,
asset: $asset_info,
lp_asset: $lp_asset,
vault_code_id: $vault_code_id,
lp_code_id: $lp_code_id
}')

# Append the vault entry to the modified_vaults array
modified_vaults+=("$vault_entry")
done < <(echo "$vaults" | jq -c '.[]')

# Combine all modified vault entries into a single JSON array and write to the output file
jq -n \
--argjson vaults "$(echo "${modified_vaults[@]}" | jq -s '.')" \
--arg vault_factory_addr "$vault_factory_addr" \
--arg chain "$CHAIN_ID" \
'{chain: $chain, vault_factory_addr: $vault_factory_addr, vaults: $vaults}' \
>"$output_file"

#
# jq '[.[] | {vault: .vault, asset_info: .asset_info}]' <<<"$vaults" >$output_file
# jq --arg vault_factory_addr "$vault_factory_addr" \
# --arg chain "$CHAIN_ID" \
# '{chain: $chain, vault_factory_addr: $vault_factory_addr, vaults: [.[] | {vault: .vault, asset_info: .asset_info}]}' <<<$vaults >$output_file

echo -e "\n**** Extracted vault data on $CHAIN_ID successfully ****\n"
jq '.' $output_file
}

if [ -z $1 ]; then
display_usage
exit 0
fi

# get args
optstring=':c:h'
while getopts $optstring arg; do
case "$arg" in
c)
chain=$OPTARG
source $deployment_script_dir/deploy_env/chain_env.sh
init_chain_env $OPTARG
extract_vaults
;;
h)
display_usage
exit 0
;;
:)
echo "Must supply an argument to -$OPTARG" >&2
exit 1
;;
?)
echo "Invalid option: -${OPTARG}"
display_usage
exit 2
;;
esac
done

0 comments on commit 5bfa4a9

Please sign in to comment.