#!/usr/bin/env bash set -euo pipefail # Create and seed Mainnet DODO PMM pool cWUSDT (base) / cWUSDC (quote) at 1:1 initial price. # # One integration pool supports swaps in both directions; there is no second pool for the reverse. # lpFeeRate defaults to 3 bps to match other public cW*/USD rails; k=0; TWAP off (same as wave-1 public stables). # # initialPrice uses DODO convention (1e18 = unity peg for same-decimal USD-linked stables). # # Examples: # bash scripts/deployment/compute-mainnet-cwusdt-cwusdc-seed-amounts.sh --multiplier=50 --cap-raw=... # bash scripts/deployment/deploy-mainnet-cwusdt-cwusdc-pool.sh \ # --initial-price=1000000000000000000 \ # --base-amount= --quote-amount= \ # --dry-run # # Registry: cross-chain-pmm-lps/config/deployment-status.json lists the live vault # 0xe944b7Cb012A0820c07f54D51e92f0e1C74168DB when already created; this script skips # createPool when integration mapping exists and only tops up liquidity if you pass amounts. 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 INITIAL_PRICE="1000000000000000000" BASE_AMOUNT="" QUOTE_AMOUNT="" MINT_BASE_AMOUNT="0" MINT_QUOTE_AMOUNT="0" FEE_BPS="3" K_VALUE="0" OPEN_TWAP="false" DRY_RUN=0 for arg in "$@"; do case "$arg" in --initial-price=*) INITIAL_PRICE="${arg#*=}" ;; --base-amount=*) BASE_AMOUNT="${arg#*=}" ;; --quote-amount=*) QUOTE_AMOUNT="${arg#*=}" ;; --mint-base-amount=*) MINT_BASE_AMOUNT="${arg#*=}" ;; --mint-quote-amount=*) MINT_QUOTE_AMOUNT="${arg#*=}" ;; --fee-bps=*) FEE_BPS="${arg#*=}" ;; --k=*) K_VALUE="${arg#*=}" ;; --open-twap=*) OPEN_TWAP="${arg#*=}" ;; --dry-run) DRY_RUN=1 ;; -h | --help) sed -n '1,28p' "$0" exit 0 ;; *) echo "[fail] unknown arg: $arg" >&2 exit 2 ;; esac done if [[ -z "$BASE_AMOUNT" || -z "$QUOTE_AMOUNT" ]]; then echo "[fail] required: --base-amount and --quote-amount (use matched 1:1 raw for peg seed)" >&2 exit 1 fi RPC_URL="${ETHEREUM_MAINNET_RPC:-}" PRIVATE_KEY="${PRIVATE_KEY:-}" INTEGRATION="${DODO_PMM_INTEGRATION_MAINNET:-}" CWUSDT="${CWUSDT_MAINNET:-0xaF5017d0163ecb99D9B5D94e3b4D7b09Af44D8AE}" CWUSDC="${CWUSDC_MAINNET:-0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a}" 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_TOKEN="$CWUSDT" QUOTE_TOKEN="$CWUSDC" PAIR_LABEL="cWUSDT/cWUSDC" 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 } 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_after_mint=$(( base_balance_before + MINT_BASE_AMOUNT )) if (( MINT_BASE_AMOUNT == 0 || base_after_mint < BASE_AMOUNT )); then echo "[fail] insufficient cWUSDT: have=$base_balance_before need=$BASE_AMOUNT mint_base=$MINT_BASE_AMOUNT" >&2 exit 1 fi fi if (( quote_balance_before < QUOTE_AMOUNT )); then quote_after_mint=$(( quote_balance_before + MINT_QUOTE_AMOUNT )) if (( MINT_QUOTE_AMOUNT == 0 || quote_after_mint < QUOTE_AMOUNT )); then echo "[fail] insufficient cWUSDC: have=$quote_balance_before need=$QUOTE_AMOUNT mint_quote=$MINT_QUOTE_AMOUNT" >&2 exit 1 fi 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" echo "quoteAmount=$QUOTE_AMOUNT" echo "mintBaseAmount=$MINT_BASE_AMOUNT" echo "mintQuoteAmount=$MINT_QUOTE_AMOUNT" echo "baseBalanceBefore=$base_balance_before" echo "quoteBalanceBefore=$quote_balance_before" exit 0 fi mint_base_tx="" mint_quote_tx="" create_tx="" approve_base_tx="" approve_quote_tx="" add_liquidity_tx="" if (( MINT_BASE_AMOUNT > 0 )); then mint_base_output="$( cast send "$BASE_TOKEN" \ 'mint(address,uint256)' \ "$DEPLOYER" "$MINT_BASE_AMOUNT" \ --rpc-url "$RPC_URL" \ --private-key "$PRIVATE_KEY" )" mint_base_tx="$(parse_tx_hash "$mint_base_output")" fi if (( MINT_QUOTE_AMOUNT > 0 )); then mint_quote_output="$( cast send "$QUOTE_TOKEN" \ 'mint(address,uint256)' \ "$DEPLOYER" "$MINT_QUOTE_AMOUNT" \ --rpc-url "$RPC_URL" \ --private-key "$PRIVATE_KEY" )" mint_quote_tx="$(parse_tx_hash "$mint_quote_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 "export POOL_CWUSDT_CWUSDC_MAINNET=$existing_pool" echo "initialPrice=$INITIAL_PRICE" echo "feeBps=$FEE_BPS" echo "mintBaseTx=${mint_base_tx:-none}" echo "mintQuoteTx=${mint_quote_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"