Files
proxmox/scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh
defiQUG dbd517b279 Sync workspace: config, docs, scripts, CI, operator rules, and submodule pointers.
- Update dbis_core, cross-chain-pmm-lps, explorer-monorepo, metamask-integration, pr-workspace/chains
- Omit embedded publish git dirs and empty placeholders from index

Made-with: Cursor
2026-04-12 06:12:20 -07:00

269 lines
9.3 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Create and seed a Mainnet DODO PMM pool: cWUSD* (base) / TRUU (quote).
#
# Seeding "1:1" means **equal USD on each leg**, not equal raw token amounts — see
# docs/03-deployment/MAINNET_PMM_TRUU_CWUSD_PEG_AND_BOT_RUNBOOK.md section 9 and:
# bash scripts/deployment/compute-mainnet-truu-pmm-seed-amounts.sh
# Large fixed USD per leg (prints base/quote + command lines):
# bash scripts/deployment/compute-mainnet-truu-liquidity-amounts.sh --usd-per-leg=125000
#
# Base tokens are 6 decimals (cWUSDT, cWUSDC). TRUU is 10 decimals on mainnet.
# You MUST set --initial-price to the correct DODO PMM "i" for your base/quote order
# (depends on DODO DVM math — verify on a fork before mainnet size).
#
# Defaults for volatile-style pools: fee 30 bps, k = 0.5e18, TWAP off.
# For peg-only cW↔stable pools use deploy-mainnet-public-dodo-wave1-pool.sh instead.
#
# Example (dry-run):
# bash scripts/deployment/deploy-mainnet-pmm-cw-truu-pool.sh \
# --pair=cwusdt-truu \
# --initial-price=<YOUR_I_VALUE> \
# --base-amount=10000000 \
# --quote-amount=25000000000 \
# --dry-run
#
# Top up an **existing** pool (createPool skipped when integration already has base/TRUU):
# Use the same --pair, --initial-price (ignored for create but kept for logs), and 1:1 USD legs.
# Quote raw from base raw: quote = base * Q_ref / B_ref using any prior deposit (e.g. cWUSDT/TRUU
# seed B_ref=1500000, Q_ref=372348929900893). Require wallet TRUU >= quote and cW base >= base.
#
# After live deploy, record the pool in cross-chain-pmm-lps/config/deployment-status.json
# and set PMM_TRUU_BASE_TOKEN / PMM_TRUU_QUOTE_TOKEN for scripts/verify/check-mainnet-pmm-peg-bot-readiness.sh
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
source "${PROJECT_ROOT}/smom-dbis-138/scripts/load-env.sh" >/dev/null 2>&1
require_cmd() {
command -v "$1" >/dev/null 2>&1 || {
echo "[fail] missing required command: $1" >&2
exit 1
}
}
require_cmd cast
PAIR=""
INITIAL_PRICE=""
BASE_AMOUNT=""
QUOTE_AMOUNT=""
MINT_BASE_AMOUNT="0"
FEE_BPS="${PMM_TRUU_FEE_BPS:-30}"
K_VALUE="${PMM_TRUU_K:-500000000000000000}"
OPEN_TWAP="false"
DRY_RUN=0
for arg in "$@"; do
case "$arg" in
--pair=*) PAIR="${arg#*=}" ;;
--initial-price=*) INITIAL_PRICE="${arg#*=}" ;;
--base-amount=*) BASE_AMOUNT="${arg#*=}" ;;
--quote-amount=*) QUOTE_AMOUNT="${arg#*=}" ;;
--mint-base-amount=*) MINT_BASE_AMOUNT="${arg#*=}" ;;
--fee-bps=*) FEE_BPS="${arg#*=}" ;;
--k=*) K_VALUE="${arg#*=}" ;;
--open-twap=*) OPEN_TWAP="${arg#*=}" ;;
--dry-run) DRY_RUN=1 ;;
*)
echo "[fail] unknown arg: $arg" >&2
exit 2
;;
esac
done
if [[ -z "$PAIR" || -z "$INITIAL_PRICE" || -z "$BASE_AMOUNT" || -z "$QUOTE_AMOUNT" ]]; then
echo "[fail] required args: --pair, --initial-price, --base-amount, --quote-amount" >&2
exit 1
fi
RPC_URL="${ETHEREUM_MAINNET_RPC:-}"
PRIVATE_KEY="${PRIVATE_KEY:-}"
INTEGRATION="${DODO_PMM_INTEGRATION_MAINNET:-}"
TRUU_MAINNET="${TRUU_MAINNET:-0xDAe0faFD65385E7775Cf75b1398735155EF6aCD2}"
if [[ -z "$RPC_URL" || -z "$PRIVATE_KEY" || -z "$INTEGRATION" ]]; then
echo "[fail] ETHEREUM_MAINNET_RPC, PRIVATE_KEY, and DODO_PMM_INTEGRATION_MAINNET are required" >&2
exit 1
fi
DEPLOYER="$(cast wallet address --private-key "$PRIVATE_KEY")"
BASE_SYMBOL=""
BASE_TOKEN=""
PAIR_LABEL=""
case "$PAIR" in
cwusdt-truu)
BASE_SYMBOL="cWUSDT"
BASE_TOKEN="${CWUSDT_MAINNET:-0xaF5017d0163ecb99D9B5D94e3b4D7b09Af44D8AE}"
PAIR_LABEL="cWUSDT/TRUU"
;;
cwusdc-truu)
BASE_SYMBOL="cWUSDC"
BASE_TOKEN="${CWUSDC_MAINNET:-0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a}"
PAIR_LABEL="cWUSDC/TRUU"
;;
*)
echo "[fail] unsupported pair: $PAIR (use cwusdt-truu or cwusdc-truu)" >&2
exit 2
;;
esac
parse_tx_hash() {
local output="$1"
local tx_hash
tx_hash="$(printf '%s\n' "$output" | grep -E '^0x[0-9a-fA-F]{64}$' | tail -n1 || true)"
if [[ -z "$tx_hash" ]]; then
tx_hash="$(printf '%s\n' "$output" | grep -E '^transactionHash[[:space:]]+0x[0-9a-fA-F]{64}$' | awk '{print $2}' | tail -n1 || true)"
fi
if [[ -z "$tx_hash" ]]; then
return 1
fi
printf '%s\n' "$tx_hash"
}
bool_to_cli() {
if [[ "$1" == "true" ]]; then
printf 'true'
else
printf 'false'
fi
}
QUOTE_TOKEN="$TRUU_MAINNET"
existing_pool="$(cast call "$INTEGRATION" 'pools(address,address)(address)' "$BASE_TOKEN" "$QUOTE_TOKEN" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_balance_before="$(cast call "$BASE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_balance_before="$(cast call "$QUOTE_TOKEN" 'balanceOf(address)(uint256)' "$DEPLOYER" --rpc-url "$RPC_URL" | awk '{print $1}')"
base_allowance_before="$(cast call "$BASE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
quote_allowance_before="$(cast call "$QUOTE_TOKEN" 'allowance(address,address)(uint256)' "$DEPLOYER" "$INTEGRATION" --rpc-url "$RPC_URL" | awk '{print $1}')"
create_gas="0"
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
create_gas="$(cast estimate "$INTEGRATION" \
'createPool(address,address,uint256,uint256,uint256,bool)(address)' \
"$BASE_TOKEN" "$QUOTE_TOKEN" "$FEE_BPS" "$INITIAL_PRICE" "$K_VALUE" "$(bool_to_cli "$OPEN_TWAP")" \
--from "$DEPLOYER" \
--rpc-url "$RPC_URL")"
fi
if (( base_balance_before < BASE_AMOUNT )); then
base_balance_after_mint=$(( base_balance_before + MINT_BASE_AMOUNT ))
if (( MINT_BASE_AMOUNT == 0 || base_balance_after_mint < BASE_AMOUNT )); then
echo "[fail] insufficient ${BASE_SYMBOL} balance: have=$base_balance_before need=$BASE_AMOUNT mint_base_amount=$MINT_BASE_AMOUNT" >&2
exit 1
fi
fi
if (( quote_balance_before < QUOTE_AMOUNT )); then
echo "[fail] insufficient TRUU balance: have=$quote_balance_before need=$QUOTE_AMOUNT" >&2
exit 1
fi
if (( DRY_RUN == 1 )); then
echo "pair=$PAIR_LABEL"
echo "baseToken=$BASE_TOKEN"
echo "quoteToken=$QUOTE_TOKEN"
echo "integration=$INTEGRATION"
echo "existingPool=$existing_pool"
echo "initialPrice=$INITIAL_PRICE"
echo "feeBps=$FEE_BPS"
echo "k=$K_VALUE"
echo "openTwap=$OPEN_TWAP"
echo "createGas=$create_gas"
echo "baseAmount=$BASE_AMOUNT (6-decimal cW units)"
echo "quoteAmount=$QUOTE_AMOUNT (10-decimal TRUU units)"
echo "mintBaseAmount=$MINT_BASE_AMOUNT"
echo "suggestedVerifierEnv=PMM_TRUU_BASE_TOKEN=$BASE_TOKEN PMM_TRUU_QUOTE_TOKEN=$QUOTE_TOKEN"
exit 0
fi
mint_tx=""
create_tx=""
approve_base_tx=""
approve_quote_tx=""
add_liquidity_tx=""
if (( MINT_BASE_AMOUNT > 0 )); then
mint_output="$(
cast send "$BASE_TOKEN" \
'mint(address,uint256)' \
"$DEPLOYER" "$MINT_BASE_AMOUNT" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY"
)"
mint_tx="$(parse_tx_hash "$mint_output")"
fi
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
create_output="$(
cast send "$INTEGRATION" \
'createPool(address,address,uint256,uint256,uint256,bool)(address)' \
"$BASE_TOKEN" "$QUOTE_TOKEN" "$FEE_BPS" "$INITIAL_PRICE" "$K_VALUE" "$(bool_to_cli "$OPEN_TWAP")" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY"
)"
create_tx="$(parse_tx_hash "$create_output")"
existing_pool="$(cast call "$INTEGRATION" 'pools(address,address)(address)' "$BASE_TOKEN" "$QUOTE_TOKEN" --rpc-url "$RPC_URL" | awk '{print $1}')"
fi
if [[ "$existing_pool" == "0x0000000000000000000000000000000000000000" ]]; then
echo "[fail] pool creation did not yield a pool address" >&2
exit 1
fi
if (( base_allowance_before < BASE_AMOUNT )); then
approve_base_output="$(
cast send "$BASE_TOKEN" \
'approve(address,uint256)(bool)' \
"$INTEGRATION" "$BASE_AMOUNT" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY"
)"
approve_base_tx="$(parse_tx_hash "$approve_base_output")"
fi
if (( quote_allowance_before < QUOTE_AMOUNT )); then
approve_quote_output="$(
cast send "$QUOTE_TOKEN" \
'approve(address,uint256)(bool)' \
"$INTEGRATION" "$QUOTE_AMOUNT" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY"
)"
approve_quote_tx="$(parse_tx_hash "$approve_quote_output")"
fi
add_liquidity_output="$(
cast send "$INTEGRATION" \
'addLiquidity(address,uint256,uint256)(uint256,uint256,uint256)' \
"$existing_pool" "$BASE_AMOUNT" "$QUOTE_AMOUNT" \
--rpc-url "$RPC_URL" \
--private-key "$PRIVATE_KEY"
)"
add_liquidity_tx="$(parse_tx_hash "$add_liquidity_output")"
reserves="$(cast call "$existing_pool" 'getVaultReserve()(uint256,uint256)' --rpc-url "$RPC_URL")"
base_reserve="$(printf '%s\n' "$reserves" | sed -n '1p' | awk '{print $1}')"
quote_reserve="$(printf '%s\n' "$reserves" | sed -n '2p' | awk '{print $1}')"
echo "pair=$PAIR_LABEL"
echo "pool=$existing_pool"
echo "baseToken=$BASE_TOKEN"
echo "quoteToken=$QUOTE_TOKEN"
echo "initialPrice=$INITIAL_PRICE"
echo "feeBps=$FEE_BPS"
echo "k=$K_VALUE"
echo "mintTx=${mint_tx:-none}"
echo "createTx=${create_tx:-none}"
echo "approveBaseTx=${approve_base_tx:-none}"
echo "approveQuoteTx=${approve_quote_tx:-none}"
echo "addLiquidityTx=$add_liquidity_tx"
echo "baseReserve=$base_reserve"
echo "quoteReserve=$quote_reserve"
echo "nextSteps=Add pool row to cross-chain-pmm-lps/config/deployment-status.json; set PMM_TRUU_BASE_TOKEN and PMM_TRUU_QUOTE_TOKEN; run scripts/verify/check-mainnet-pmm-peg-bot-readiness.sh"