# Deployment script library

Reusable helpers for deployment scripts: **tag-based CLI** (no .env placeholders for one-off values), **interactive prompts** when run without args, and **callable modular linking** so scripts can invoke each other with arguments.

## Conventions

- **Secrets and chain config** stay in `.env` (e.g. `PRIVATE_KEY`, RPC URLs, contract addresses).
- **One-off or per-run values** are passed via **script tags** (e.g. `--eth 1.5`, `--chain bsc polygon`, `--lockbox`), not .env.
- Scripts that accept amounts **prompt interactively** when run with no args and stdin is a TTY.
- Scripts are **callable** from other scripts by passing the same tags (e.g. `run-all-four-gaps.sh g4 --eth 1`).

## Modules

| File | Purpose |
|------|--------|
| `prompts.sh` | Tag parsers: `parse_fund_tags` (--eth, --weth, --dry-run), `prompt_fund_amounts`, `eth_to_wei`, `parse_phase_tags` (g1, g2g3, g4), `parse_chain_filter` (--chain bsc polygon ...), `parse_lockbox_tag` (--lockbox / --no-lockbox), `parse_link_tags` (--link, --dry-run), `parse_dry_run_tag`, `parse_deploy_tag` (--deploy), `parse_delay_tag` (--delay). `L2_CHAIN_NAMES`, `normalize_chain_name`. |
| `dotenv.sh` | `load_deployment_env`, `require_fund_lp_env`. |
| `costs.sh` | Gas and cost helpers (existing). |

## Validate syntax (one command)

- **From this repo** (`smom-dbis-138`):  
  `./scripts/deployment/check-syntax.sh`
- **From workspace root** (e.g. `proxmox`):  
  `./smom-dbis-138/scripts/deployment/check-syntax.sh`

Checks all tag-based deployment scripts and the lib with `bash -n`.

## Usage

```bash
# From any script in scripts/deployment:
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/deployment/dotenv.sh"
source "$SCRIPT_DIR/../lib/deployment/prompts.sh"
load_deployment_env

# Parse G4 amounts from args, then prompt if still empty (TTY)
parse_fund_tags "$@"
prompt_fund_amounts
# Use FUND_ETH_AMOUNT_WEI, FUND_WETH_AMOUNT_WEI
```

## Example: G4 fund mainnet LP

- **Standalone:** `./scripts/deployment/fund-mainnet-lp.sh --eth 1.5 --weth 0.5`
- **Interactive:** `./scripts/deployment/fund-mainnet-lp.sh`
- **From run-all:** `./scripts/deployment/run-all-four-gaps.sh g4 --eth 1`

No `FUND_ETH_AMOUNT_WEI` / `FUND_WETH_AMOUNT_WEI` in .env.

## Other scripts (tags)

| Script | Tags |
|--------|------|
| deploy-pmm-all-l2s.sh | --chain bsc polygon ... (or DEPLOY_PMM_L2S_FILTER in .env) |
| live-test-trustless-bridge.sh | --check (optional: print LP stats and BondManager totalEthHeld); prints cast commands for lock → claim → finalize → release |
| deploy-trustless-l2s.sh | --chain, --lockbox / --no-lockbox |
| fund-ccip-bridges-with-link.sh | --link amount, --dry-run |
| run-final-unblock-checklist.sh | --dry-run, --status-only, --json, --only / --skip, --mainnet-link, --bsc-link, --mainnet-eth, --mainnet-weth, --mainnet-relay-weth, --bsc-relay-weth |
| fix-nonce-and-retry.sh | --chain, --script (positional still supported) |
| run-remaining-g2g3-with-nonce-fix.sh | --delay, --lockbox / --no-lockbox |
| check-balances-gas-and-deploy.sh | --deploy |
