WIP: Chain138 deployment scripts, flash receivers, HYBX OMNL recovery

This commit is contained in:
defiQUG
2026-06-02 06:09:44 -07:00
parent e1560a880b
commit f04a7cb7c8
35 changed files with 2279 additions and 83 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ cd ..
# Deploy Admin Dashboard
echo ""
echo "--- Building Admin Dashboard ---"
cd ../dbis_core/frontend
cd /home/intlc/projects/dbis_core/frontend
if [ -f "package.json" ]; then
npm install
+180
View File
@@ -0,0 +1,180 @@
#!/usr/bin/env bash
# Export BSC cW* verification artifacts: pinned profile build + Standard JSON for BscScan manual upload.
#
# Usage (from smom-dbis-138/):
# ./scripts/deployment/export-bsc-cw-verification-artifacts.sh
# ./scripts/deployment/export-bsc-cw-verification-artifacts.sh --verify # also submit forge verify (cWBNB may fail)
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
REPO_ROOT="$(cd "$PROJECT_ROOT/.." && pwd)"
OUT_DIR="$REPO_ROOT/reports/status/bsc-cw-verification"
VERIFY=0
[[ "${1:-}" == "--verify" ]] && VERIFY=1
cd "$PROJECT_ROOT"
if [[ -f "$SCRIPT_DIR/../lib/deployment/dotenv.sh" ]]; then
# shellcheck disable=SC1090
source "$SCRIPT_DIR/../lib/deployment/dotenv.sh"
load_deployment_env --repo-root "$PROJECT_ROOT"
fi
[[ -n "${ETHERSCAN_API_KEY:-}" ]] || { echo "ETHERSCAN_API_KEY required" >&2; exit 1; }
ADMIN="${CW_VERIFY_ADMIN:-}"
if [[ -z "$ADMIN" && -n "${PRIVATE_KEY:-}" ]]; then
ADMIN="$(cast wallet address --private-key "$PRIVATE_KEY")"
fi
[[ -n "$ADMIN" ]] || { echo "CW_VERIFY_ADMIN or PRIVATE_KEY required" >&2; exit 1; }
CWBNB="${CWBNB_BSC:-0x179034a08ac2c9c35d2e41239f68c79dca6f18fa}"
CONTRACT_PATH="contracts/tokens/CompliantWrappedToken.sol:CompliantWrappedToken"
CTOR="$(cast abi-encode 'constructor(string,string,uint8,address)' \
'Wrapped BNB Gas (Compliant)' 'cWBNB' 18 "$ADMIN")"
mkdir -p "$OUT_DIR"
echo "==> Pinned profile: bsc_tokens_verify (see foundry.toml + config/bsc-cw-verify-profile.v1.json)"
echo "==> Scoped build: scripts/forge/scope.sh build tokens"
export FOUNDRY_PROFILE=bsc_tokens_verify
export FOUNDRY_SRC="contracts/tokens,contracts/interfaces"
export FOUNDRY_OUT="out/scopes/tokens"
export FOUNDRY_CACHE_PATH="cache/scopes/tokens"
bash "$PROJECT_ROOT/scripts/forge/scope.sh" build tokens
echo "==> Export Standard JSON Input (upload at https://bscscan.com/verifyContract solidity-standard-json-input)"
JSON_OUT="$OUT_DIR/CompliantWrappedToken_cWBNB_standard_input.json"
# forge may print ERROR log lines before the JSON object on stdout — keep only the JSON line
forge verify-contract \
--chain bsc \
--num-of-optimizations 200 \
--via-ir \
--evm-version london \
--compiler-version "0.8.20+commit.a1b79de6" \
--constructor-args "$CTOR" \
--show-standard-json-input \
"$CWBNB" \
"$CONTRACT_PATH" 2>/dev/null | awk '/^\{/{buf=$0} END{if(buf) print buf}' | jq -c . > "$JSON_OUT"
[[ -s "$JSON_OUT" ]] || { echo "Failed to write Standard JSON (forge output empty?)" >&2; exit 5; }
echo " wrote $JSON_OUT"
echo "==> Export flattened source (reference only; prefer Standard-JSON for via-ir)"
forge flatten contracts/tokens/CompliantWrappedToken.sol > "$OUT_DIR/CompliantWrappedToken_cWBNB_flattened.sol" 2>/dev/null
echo " wrote $OUT_DIR/CompliantWrappedToken_cWBNB_flattened.sol"
RPC="${BSC_RPC_URL:-${BSC_MAINNET_RPC:-}}"
if [[ -n "$RPC" ]]; then
ONCHAIN="$(cast code "$CWBNB" --rpc-url "$RPC" | sed 's/^0x//' | tr '[:upper:]' '[:lower:]')"
BUILT="$(jq -r .deployedBytecode.object "$FOUNDRY_OUT/CompliantWrappedToken.sol/CompliantWrappedToken.json" | sed 's/^0x//' | tr '[:upper:]' '[:lower:]')"
MATCH=false
[[ "$ONCHAIN" == "$BUILT" ]] && MATCH=true
FIRST_DIFF_OFFSET=""
if [[ "$MATCH" == false ]]; then
FIRST_DIFF_OFFSET="$(python3 -c "
on, b = '''$ONCHAIN''', '''$BUILT'''
n = min(len(on), len(b)) // 2
for i in range(n):
if on[2*i:2*i+2] != b[2*i:2*i+2]:
print(i)
break
else:
print(n if len(on)//2 != len(b)//2 else '')
" 2>/dev/null || true)"
fi
jq -n \
--arg generatedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--arg address "$CWBNB" \
--argjson onChainRuntimeBytes $(( ${#ONCHAIN} / 2 )) \
--argjson pinnedBuildRuntimeBytes $(( ${#BUILT} / 2 )) \
--argjson runtimeBytecodeMatch "$([[ "$MATCH" == true ]] && echo true || echo false)" \
--arg firstRuntimeDiffOffset "${FIRST_DIFF_OFFSET:-null}" \
--arg constructorArgs "$CTOR" \
--arg foundryProfile "bsc_tokens_verify" \
--arg standardJson "$JSON_OUT" \
'{
generatedAt: $generatedAt,
address: $address,
onChainRuntimeBytes: $onChainRuntimeBytes,
pinnedBuildRuntimeBytes: $pinnedBuildRuntimeBytes,
runtimeBytecodeMatch: $runtimeBytecodeMatch,
firstRuntimeDiffOffset: (if $firstRuntimeDiffOffset == "" or $firstRuntimeDiffOffset == "null" then null else ($firstRuntimeDiffOffset|tonumber) end),
constructorArgs: $constructorArgs,
foundryProfile: $foundryProfile,
standardJson: $standardJson
}' > "$OUT_DIR/cWBNB_bytecode_compare.json"
echo " wrote $OUT_DIR/cWBNB_bytecode_compare.json"
fi
cat > "$OUT_DIR/README.md" <<EOF
# BSC cWBNB verification artifacts
Generated by \`smom-dbis-138/scripts/deployment/export-bsc-cw-verification-artifacts.sh\`.
## Pinned compiler (matches verified BSC cWUSDT)
| Setting | Value |
|---------|--------|
| Profile | \`bsc_tokens_verify\` in \`foundry.toml\` |
| solc | \`0.8.20+commit.a1b79de6\` |
| Optimizer | enabled, **200** runs |
| via-ir | **true** (required — stack too deep without) |
| EVM | **london** (not cancun) |
| Scope | \`FOUNDRY_SRC=contracts/tokens,contracts/interfaces\`, \`FOUNDRY_OUT=out/scopes/tokens\` |
## Manual BscScan steps
1. Open https://bscscan.com/verifyContract
2. Contract address: \`$CWBNB\`
3. Compiler type: **Solidity (Standard-Json-Input)**
4. Upload \`CompliantWrappedToken_cWBNB_standard_input.json\`
5. Constructor arguments ABI-encoded (hex): see \`cWBNB_bytecode_compare.json\` or run:
\`\`\`bash
cast abi-encode 'constructor(string,string,uint8,address)' 'Wrapped BNB Gas (Compliant)' 'cWBNB' 18 <ADMIN>
\`\`\`
## If verification still fails
On-chain runtime bytecode is **~45 bytes longer** than the current pinned scoped build (see \`cWBNB_bytecode_compare.json\`). That indicates deploy used a slightly different artifact (solc patch, source revision, or metadata), not just constructor naming. Options:
- Locate the deploy transaction and pin the exact \`solc\` commit from that date.
- Compare \`git log contracts/tokens/CompliantWrappedToken.sol\` at deploy block.
- Redeploy cWBNB only if a new address is acceptable.
## Automated verify (may fail until bytecode pin found)
\`\`\`bash
cd smom-dbis-138
FOUNDRY_PROFILE=bsc_tokens_verify \\
FOUNDRY_SRC=contracts/tokens FOUNDRY_OUT=out/scopes/tokens \\
forge verify-contract --chain bsc --num-of-optimizations 200 --via-ir --evm-version london \\
--compiler-version 0.8.20+commit.a1b79de6 \\
--etherscan-api-key "\$ETHERSCAN_API_KEY" \\
--constructor-args "\$CTOR" \\
$CWBNB $CONTRACT_PATH
\`\`\`
EOF
echo " wrote $OUT_DIR/README.md"
if [[ "$VERIFY" -eq 1 ]]; then
echo "==> forge verify-contract (automated)"
set +e
forge verify-contract \
--chain bsc \
--num-of-optimizations 200 \
--via-ir \
--evm-version london \
--compiler-version "0.8.20+commit.a1b79de6" \
--etherscan-api-key "${ETHERSCAN_API_KEY}" \
--constructor-args "$CTOR" \
--watch --rpc-timeout 120 \
"$CWBNB" \
"$CONTRACT_PATH"
set -e
fi
echo ""
echo "Done. Artifacts: $OUT_DIR/"
+2 -2
View File
@@ -33,8 +33,8 @@ fi
echo ""
echo "--- Building Admin Dashboard ---"
if [ -d "../dbis_core/frontend" ] && [ -f "../dbis_core/frontend/package.json" ]; then
cd ../dbis_core/frontend
if [ -d "/home/intlc/projects/dbis_core/frontend" ] && [ -f "/home/intlc/projects/dbis_core/frontend/package.json" ]; then
cd /home/intlc/projects/dbis_core/frontend
echo "Installing dependencies..."
npm install
echo "Building..."
+11
View File
@@ -22,6 +22,7 @@ declare -A ROOT_SCRIPT_SCOPE_ALIASES=(
["DeployCompliantUSDT.s.sol"]="tokens"
["DeployCWAssetReserveVerifier.s.sol"]="bridge/integration"
["DeployCWReserveVerifier.s.sol"]="bridge/integration"
["DeployCWReserveSettlementStack.s.sol"]="cw-settlement"
["DeployFeeCollector.s.sol"]="utils"
["DeployGenericStateChannelManager.s.sol"]="channels"
["DeployMainnetTether.s.sol"]="tether"
@@ -40,6 +41,10 @@ declare -A ROOT_SCRIPT_SCOPE_ALIASES=(
["DeployRWATokenFactory138.s.sol"]="rwa"
["DeployM00DiamondHub138.s.sol"]="m00-diamond"
["UpgradeM00DiamondAcl138.s.sol"]="m00-diamond"
["UpgradeM00DiamondHubComplete138.s.sol"]="m00-diamond"
["SeedM00LiIndexWeights138.s.sol"]="m00-diamond"
["WireChain138OraclePegs138.s.sol"]="oracle"
["GrantUarRegistrarRWA138.s.sol"]="rwa"
["FundBridgeLinkViaCcip138.s.sol"]="ccip"
["FundBridgeLinkViaCcipMainnet.s.sol"]="ccip"
["DeployCCIPRelayBridgeLINK.s.sol"]="relay"
@@ -240,9 +245,13 @@ prepare_scope_env() {
if [[ "$scope" == "rwa" ]]; then
export FOUNDRY_SRC="contracts/rwa,contracts/compliance"
export FOUNDRY_PROFILE="${FOUNDRY_PROFILE:-chain138}"
elif [[ "$scope" == "m00-diamond" ]]; then
export FOUNDRY_SRC="contracts/m00-diamond,contracts/rwa"
export FOUNDRY_PROFILE="${FOUNDRY_PROFILE:-m00-diamond}"
elif [[ "$scope" == "oracle" ]]; then
export FOUNDRY_SRC="$src_dir"
export FOUNDRY_PROFILE="${FOUNDRY_PROFILE:-chain138}"
else
export FOUNDRY_SRC="$src_dir"
fi
@@ -261,6 +270,8 @@ prepare_scope_env() {
local script_dir="script/$scope"
if [[ -d "$REPO_ROOT/$script_dir" ]]; then
export FOUNDRY_SCRIPT="$script_dir"
elif [[ "$scope" == "oracle" && -d "$REPO_ROOT/script/reserve" ]]; then
export FOUNDRY_SCRIPT="script/reserve"
fi
fi
}
+101 -16
View File
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash
# Complete Keeper Deployment Script
# Deploys all keeper components and sets up monitoring
@@ -8,10 +8,23 @@ set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m'
DRY_RUN="${DRY_RUN:-0}"
EXPECTED_KEEPER="0xD3AD6831aacB5386B8A25BB8D8176a6C8a026f04"
for arg in "$@"; do
case "$arg" in
--dry-run)
DRY_RUN=1
;;
esac
done
# Load environment variables
if [ -f .env ]; then
# shellcheck disable=SC1091
source .env
fi
@@ -20,15 +33,94 @@ RPC_URL="${RPC_URL_138:-https://rpc.d-bis.org}"
PRIVATE_KEY="${PRIVATE_KEY}"
KEEPER_ADDRESS="${PRICE_FEED_KEEPER_ADDRESS}"
echo -e "${GREEN}=== Complete Keeper Deployment ===${NC}\n"
normalize_addr() {
echo "$1" | tr '[:upper:]' '[:lower:]'
}
# Step 1: Deploy PriceFeedKeeper
echo -e "${YELLOW}Step 1: Deploying PriceFeedKeeper...${NC}"
if [ -z "$KEEPER_ADDRESS" ]; then
forge script script/reserve/DeployKeeper.s.sol:DeployKeeper \
validate_keeper_env() {
if [ -z "$KEEPER_ADDRESS" ]; then
echo -e "${RED}ERROR: PRICE_FEED_KEEPER_ADDRESS is not set in .env${NC}"
echo -e "${YELLOW}Expected: PRICE_FEED_KEEPER_ADDRESS=${EXPECTED_KEEPER}${NC}"
exit 1
fi
if [ "$(normalize_addr "$KEEPER_ADDRESS")" != "$(normalize_addr "$EXPECTED_KEEPER")" ]; then
echo -e "${RED}ERROR: PRICE_FEED_KEEPER_ADDRESS mismatch${NC}"
echo -e " .env: ${KEEPER_ADDRESS}"
echo -e " expected: ${EXPECTED_KEEPER}"
exit 1
fi
}
dry_run_msg() {
echo -e "${CYAN}[DRY RUN]${NC} $*"
}
run_forge_broadcast() {
local script_path="$1"
forge script "$script_path" \
--rpc-url "$RPC_URL" \
--broadcast \
--verify
}
print_forge_would_run() {
local label="$1"
local script_path="$2"
dry_run_msg "$label"
echo " forge script $script_path --rpc-url \"$RPC_URL\" --broadcast --verify"
}
if [ "$DRY_RUN" = "1" ]; then
echo -e "${CYAN}=== Complete Keeper Deployment (DRY RUN) ===${NC}\n"
validate_keeper_env
echo -e "${GREEN}PRICE_FEED_KEEPER_ADDRESS (.env):${NC} $KEEPER_ADDRESS"
echo -e "${GREEN}RPC_URL:${NC} $RPC_URL"
echo ""
echo -e "${YELLOW}Step 1: PriceFeedKeeper${NC}"
dry_run_msg "Skip deploy; keeper already configured at $KEEPER_ADDRESS"
echo ""
if [ "$DEPLOY_CHAINLINK" = "true" ]; then
echo -e "${YELLOW}Step 2: ChainlinkKeeperCompatible (DEPLOY_CHAINLINK=true)${NC}"
print_forge_would_run "Would deploy ChainlinkKeeperCompatible" \
"script/reserve/DeployChainlinkKeeper.s.sol:DeployChainlinkKeeper"
dry_run_msg "Would append CHAINLINK_KEEPER_COMPATIBLE_ADDRESS to .env (skipped)"
dry_run_msg "Follow-up: node scripts/reserve/chainlink-keeper-setup.js"
echo ""
else
echo -e "${YELLOW}Step 2: ChainlinkKeeperCompatible${NC}"
dry_run_msg "Skipped (set DEPLOY_CHAINLINK=true to include)"
echo ""
fi
if [ "$DEPLOY_GELATO" = "true" ]; then
echo -e "${YELLOW}Step 3: GelatoKeeperCompatible (DEPLOY_GELATO=true)${NC}"
print_forge_would_run "Would deploy GelatoKeeperCompatible" \
"script/reserve/DeployGelatoKeeper.s.sol:DeployGelatoKeeper"
dry_run_msg "Would append GELATO_KEEPER_COMPATIBLE_ADDRESS to .env (skipped)"
dry_run_msg "Follow-up: node scripts/reserve/gelato-keeper-setup.js"
echo ""
else
echo -e "${YELLOW}Step 3: GelatoKeeperCompatible${NC}"
dry_run_msg "Skipped (set DEPLOY_GELATO=true to include)"
echo ""
fi
echo -e "${YELLOW}Step 4: Verify deployment${NC}"
dry_run_msg "Would run read-only upkeep check (no --broadcast):"
echo " forge script script/reserve/CheckUpkeep.s.sol:CheckUpkeep --rpc-url \"$RPC_URL\""
echo ""
echo -e "${GREEN}=== Dry Run Complete (no transactions broadcast, .env unchanged) ===${NC}"
exit 0
fi
echo -e "${GREEN}=== Complete Keeper Deployment ===${NC}\n"
# Step 1: Deploy PriceFeedKeepe
echo -e "${YELLOW}Step 1: Deploying PriceFeedKeeper...${NC}"
if [ -z "$KEEPER_ADDRESS" ]; then
run_forge_broadcast "script/reserve/DeployKeeper.s.sol:DeployKeeper"
# Extract keeper address from output
KEEPER_ADDRESS=$(forge script script/reserve/DeployKeeper.s.sol:DeployKeeper \
@@ -43,10 +135,7 @@ fi
# Step 2: Deploy Chainlink Keeper Compatible (optional)
if [ "$DEPLOY_CHAINLINK" = "true" ]; then
echo -e "${YELLOW}Step 2: Deploying ChainlinkKeeperCompatible...${NC}"
forge script script/reserve/DeployChainlinkKeeper.s.sol:DeployChainlinkKeeper \
--rpc-url "$RPC_URL" \
--broadcast \
--verify
run_forge_broadcast "script/reserve/DeployChainlinkKeeper.s.sol:DeployChainlinkKeeper"
CHAINLINK_KEEPER=$(forge script script/reserve/DeployChainlinkKeeper.s.sol:DeployChainlinkKeeper \
--rpc-url "$RPC_URL" 2>&1 | grep "ChainlinkKeeperCompatible deployed at:" | awk '{print $NF}')
@@ -62,10 +151,7 @@ fi
# Step 3: Deploy Gelato Keeper Compatible (optional)
if [ "$DEPLOY_GELATO" = "true" ]; then
echo -e "${YELLOW}Step 3: Deploying GelatoKeeperCompatible...${NC}"
forge script script/reserve/DeployGelatoKeeper.s.sol:DeployGelatoKeeper \
--rpc-url "$RPC_URL" \
--broadcast \
--verify
run_forge_broadcast "script/reserve/DeployGelatoKeeper.s.sol:DeployGelatoKeeper"
GELATO_KEEPER=$(forge script script/reserve/DeployGelatoKeeper.s.sol:DeployGelatoKeeper \
--rpc-url "$RPC_URL" 2>&1 | grep "GelatoKeeperCompatible deployed at:" | awk '{print $NF}')
@@ -99,5 +185,4 @@ echo " docker-compose -f docker/docker-compose.keeper.yml up -d"
echo ""
echo "4. Or use systemd:"
echo " sudo systemctl enable price-feed-keeper"
echo " sudo systemctl start price-feed-keeper"
echo " sudo systemctl start price-feed-keeper"