feat: restore operator WIP — PMM JSON sync entrypoint, dotenv RPC trim + secrets, pool env alignment

- Resolve stash: merge load_deployment_env path with secure-secrets and CR/LF RPC strip
- create-pmm-full-mesh-chain138.sh delegates to sync-chain138-pmm-pools-from-json.sh
- env.additions.example: canonical PMM pool defaults (cUSDT/USDT per crosscheck)
- Include Chain138 scripts, official mirror deploy scaffolding, and prior staged changes

Made-with: Cursor
This commit is contained in:
defiQUG
2026-03-27 19:02:30 -07:00
parent c6e7bad15e
commit 2a4753eb2d
200 changed files with 5987 additions and 913 deletions

View File

@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Script, console} from "forge-std/Script.sol";
import {OfficialStableMirrorToken} from "../contracts/tokens/OfficialStableMirrorToken.sol";
/**
* @title DeployOfficialUSDC138
* @notice Deploy the local Chain 138 quote-side USDC mirror used by DODO PMM pools.
*/
contract DeployOfficialUSDC138 is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
address owner = vm.envOr("OFFICIAL_USDC_138_OWNER", deployer);
uint256 initialSupply = vm.envOr("OFFICIAL_USDC_138_INITIAL_SUPPLY", uint256(0));
console.log("Deploying Official USDC (Chain 138) with deployer:", vm.toString(deployer));
console.log("Owner:", vm.toString(owner));
console.log("Initial supply:", initialSupply);
vm.startBroadcast(deployerPrivateKey);
OfficialStableMirrorToken token = new OfficialStableMirrorToken(
"USD Coin (Chain 138)",
"USDC",
6,
owner,
initialSupply
);
console.log("Official USDC (Chain 138) deployed at:", vm.toString(address(token)));
vm.stopBroadcast();
}
}

View File

@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Script, console} from "forge-std/Script.sol";
import {OfficialStableMirrorToken} from "../contracts/tokens/OfficialStableMirrorToken.sol";
/**
* @title DeployOfficialUSDT138
* @notice Deploy the local Chain 138 quote-side USDT mirror used by DODO PMM pools.
*/
contract DeployOfficialUSDT138 is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
address owner = vm.envOr("OFFICIAL_USDT_138_OWNER", deployer);
uint256 initialSupply = vm.envOr("OFFICIAL_USDT_138_INITIAL_SUPPLY", uint256(0));
console.log("Deploying Official USDT (Chain 138) with deployer:", vm.toString(deployer));
console.log("Owner:", vm.toString(owner));
console.log("Initial supply:", initialSupply);
vm.startBroadcast(deployerPrivateKey);
OfficialStableMirrorToken token = new OfficialStableMirrorToken(
"Tether USD (Chain 138)",
"USDT",
6,
owner,
initialSupply
);
console.log("Official USDT (Chain 138) deployed at:", vm.toString(address(token)));
vm.stopBroadcast();
}
}

View File

@@ -10,6 +10,8 @@ import "../../../contracts/bridge/trustless/EnhancedSwapRouter.sol";
* @dev Deploys EnhancedSwapRouter with Uniswap V3, Curve, Dodoex, Balancer, and 1inch
*/
contract DeployEnhancedSwapRouter is Script {
address constant PLACEHOLDER = 0x000000000000000000000000000000000000dEaD;
// Ethereum Mainnet addresses
address constant UNISWAP_V3_ROUTER = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
address constant CURVE_3POOL = 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7;
@@ -21,39 +23,77 @@ contract DeployEnhancedSwapRouter is Script {
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant DAI = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
// Chain 138 canonical token addresses
address constant CHAIN138_WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant CHAIN138_USDT = 0x004b63A7B5b0E06f6bB6adb4a5F9f590BF3182D1;
address constant CHAIN138_USDC = 0x71D6687F38b93CCad569Fa6352c876eea967201b;
address constant CHAIN138_DAI_PLACEHOLDER = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
// Chain 138 live DODO pool map (2026-03-26)
address constant CHAIN138_cUSDT = 0x93E66202A11B1772E55407B32B44e5Cd8eda7f22;
address constant CHAIN138_cUSDC = 0xf22258f57794CC8E06237084b353Ab30fFfa640b;
address constant CHAIN138_cEURT = 0xdf4b71c61E5912712C1Bdd451416B9aC26949d72;
address constant CHAIN138_cXAUC = 0x290E52a8819A4fbD0714E517225429aA2B70EC6b;
address constant CHAIN138_POOL_CUSDTCUSDC = 0xff8d3b8fDF7B112759F076B69f4271D4209C0849;
address constant CHAIN138_POOL_CUSDTUSDT = 0x6fc60DEDc92a2047062294488539992710b99D71;
address constant CHAIN138_POOL_CUSDCUSDC = 0x0309178Ae30302D83C76d6DD402a684ef3160eeC;
address constant CHAIN138_POOL_CUSDT_XAU_PUBLIC = 0x1AA55E2001E5651349aFf5a63FD7a7ae44f0f1b0;
address constant CHAIN138_POOL_CUSDC_XAU_PUBLIC = 0xEa9AC6357CaCB42a83b9082B870610363b177CbA;
address constant CHAIN138_POOL_CEURT_XAU_PUBLIC = 0xba99bc1eAac164569d5aca96c806934dDaf970CF;
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address deployer = vm.addr(deployerPrivateKey);
uint256 chainId = block.chainid;
bool isMainnet = chainId == 1;
bool isChain138 = chainId == 138;
require(isMainnet || isChain138, "DeployEnhancedSwapRouter: supported chains are Ethereum Mainnet and Chain 138");
(
address uniswapV3Router,
address curve3Pool,
address dodoexRouter,
address balancerVault,
address oneInchRouter,
address weth,
address usdt,
address usdc,
address dai
) = _resolveAddresses(chainId);
console.log("=== EnhancedSwapRouter Deployment ===");
console.log("Deployer:", deployer);
console.log("Chain ID:", block.chainid);
require(block.chainid == 1, "DeployEnhancedSwapRouter: Ethereum Mainnet only");
console.log("Chain ID:", chainId);
if (isChain138) {
console.log("Mode: Chain 138 env-driven deployment");
console.log("Note: live DODO pools are stable/stable and stable/XAU.");
console.log("Note: WETH->stable routing remains optional until real WETH routes are configured.");
}
vm.startBroadcast(deployerPrivateKey);
console.log("\n--- Deploying EnhancedSwapRouter ---");
console.log("Uniswap V3 Router:", UNISWAP_V3_ROUTER);
console.log("Curve 3Pool:", CURVE_3POOL);
console.log("Dodoex Router:", DODOEX_ROUTER);
console.log("Balancer Vault:", BALANCER_VAULT);
console.log("1inch Router:", ONEINCH_ROUTER);
console.log("WETH:", WETH);
console.log("USDT:", USDT);
console.log("USDC:", USDC);
console.log("DAI:", DAI);
console.log("Uniswap V3 Router:", uniswapV3Router);
console.log("Curve 3Pool:", curve3Pool);
console.log("Dodoex Router:", dodoexRouter);
console.log("Balancer Vault:", balancerVault);
console.log("1inch Router:", oneInchRouter);
console.log("WETH:", weth);
console.log("USDT:", usdt);
console.log("USDC:", usdc);
console.log("DAI:", dai);
EnhancedSwapRouter router = new EnhancedSwapRouter(
UNISWAP_V3_ROUTER,
CURVE_3POOL,
DODOEX_ROUTER,
BALANCER_VAULT,
ONEINCH_ROUTER,
WETH,
USDT,
USDC,
DAI
uniswapV3Router,
curve3Pool,
dodoexRouter,
balancerVault,
oneInchRouter,
weth,
usdt,
usdc,
dai
);
console.log("\nEnhancedSwapRouter deployed at:", address(router));
@@ -62,7 +102,11 @@ contract DeployEnhancedSwapRouter is Script {
router.grantRole(router.ROUTING_MANAGER_ROLE(), deployer);
// Configure default routing
_configureDefaultRouting(router, deployer);
_configureDefaultRouting(router);
if (isChain138) {
_configureChain138InitialState(router, uniswapV3Router, curve3Pool, dodoexRouter, balancerVault, oneInchRouter);
}
vm.stopBroadcast();
@@ -70,9 +114,13 @@ contract DeployEnhancedSwapRouter is Script {
console.log("EnhancedSwapRouter:", address(router));
console.log("\n=== Export to .env ===");
console.log("export ENHANCED_SWAP_ROUTER=", vm.toString(address(router)));
if (isChain138) {
console.log("export ENHANCED_SWAP_ROUTER_CHAIN138=", vm.toString(address(router)));
console.log("export ENHANCED_SWAP_ROUTER_ADDRESS=", vm.toString(address(router)));
}
}
function _configureDefaultRouting(EnhancedSwapRouter router, address deployer) internal {
function _configureDefaultRouting(EnhancedSwapRouter router) internal {
console.log("\n--- Configuring Default Routing ---");
// Small swaps (< $10k): Uniswap V3, Dodoex
@@ -102,5 +150,110 @@ contract DeployEnhancedSwapRouter is Script {
// after identifying the actual pool addresses
console.log("\nWARNING: Remember to configure Balancer pool IDs after deployment");
}
}
function _configureChain138InitialState(
EnhancedSwapRouter router,
address uniswapV3Router,
address curve3Pool,
address dodoexRouter,
address balancerVault,
address oneInchRouter
) internal {
console.log("\n--- Chain 138 Initial Configuration ---");
address dodoPmmProvider = vm.envOr("DODO_PMM_PROVIDER_ADDRESS", address(0));
if (dodoPmmProvider == address(0)) {
dodoPmmProvider = vm.envOr("DODO_PMM_PROVIDER", address(0));
}
_registerPair(router, CHAIN138_cUSDT, CHAIN138_cUSDC, CHAIN138_POOL_CUSDTCUSDC);
_registerPair(router, CHAIN138_cUSDT, CHAIN138_USDT, CHAIN138_POOL_CUSDTUSDT);
_registerPair(router, CHAIN138_cUSDC, CHAIN138_USDC, CHAIN138_POOL_CUSDCUSDC);
_registerPair(router, CHAIN138_cUSDT, CHAIN138_cXAUC, CHAIN138_POOL_CUSDT_XAU_PUBLIC);
_registerPair(router, CHAIN138_cUSDC, CHAIN138_cXAUC, CHAIN138_POOL_CUSDC_XAU_PUBLIC);
_registerPair(router, CHAIN138_cEURT, CHAIN138_cXAUC, CHAIN138_POOL_CEURT_XAU_PUBLIC);
if (dodoPmmProvider != address(0)) {
router.setDodoLiquidityProvider(dodoPmmProvider);
console.log("Configured DODO PMM provider:", dodoPmmProvider);
}
// Disable providers that are definitely not usable until explicitly configured on Chain 138.
if (curve3Pool == PLACEHOLDER) {
router.setProviderEnabled(EnhancedSwapRouter.SwapProvider.Curve, false);
console.log("Disabled Curve provider (placeholder address)");
}
if (balancerVault == PLACEHOLDER) {
router.setProviderEnabled(EnhancedSwapRouter.SwapProvider.Balancer, false);
console.log("Disabled Balancer provider (placeholder address)");
}
if (oneInchRouter == PLACEHOLDER) {
router.setProviderEnabled(EnhancedSwapRouter.SwapProvider.OneInch, false);
console.log("Disabled 1inch provider (placeholder address)");
}
if (uniswapV3Router == PLACEHOLDER) {
router.setProviderEnabled(EnhancedSwapRouter.SwapProvider.UniswapV3, false);
console.log("Disabled Uniswap V3 provider (placeholder address)");
}
if (dodoexRouter == PLACEHOLDER && dodoPmmProvider == address(0)) {
router.setProviderEnabled(EnhancedSwapRouter.SwapProvider.Dodoex, false);
console.log("Disabled Dodoex provider (no router and no PMM provider configured)");
} else {
console.log("Dodo pool mappings registered for current live Chain 138 pairs.");
}
console.log("WARNING: swapToStablecoin() still needs real WETH->stable routes to be useful on Chain 138.");
console.log("WARNING: current Chain 138 DODO initialization is primarily for token-to-token pair mappings via swapTokenToToken().");
}
function _registerPair(
EnhancedSwapRouter router,
address tokenA,
address tokenB,
address pool
) internal {
router.setDodoPoolAddress(tokenA, tokenB, pool);
router.setDodoPoolAddress(tokenB, tokenA, pool);
console.log("Registered DODO pool:", pool);
}
function _resolveAddresses(
uint256 chainId
)
internal
returns (
address uniswapV3Router,
address curve3Pool,
address dodoexRouter,
address balancerVault,
address oneInchRouter,
address weth,
address usdt,
address usdc,
address dai
)
{
if (chainId == 1) {
uniswapV3Router = vm.envOr("UNISWAP_V3_ROUTER", UNISWAP_V3_ROUTER);
curve3Pool = vm.envOr("CURVE_3POOL", CURVE_3POOL);
dodoexRouter = vm.envOr("DODOEX_ROUTER", DODOEX_ROUTER);
balancerVault = vm.envOr("BALANCER_VAULT", BALANCER_VAULT);
oneInchRouter = vm.envOr("ONEINCH_ROUTER", ONEINCH_ROUTER);
weth = vm.envOr("WETH", WETH);
usdt = vm.envOr("USDT", USDT);
usdc = vm.envOr("USDC", USDC);
dai = vm.envOr("DAI", DAI);
return (uniswapV3Router, curve3Pool, dodoexRouter, balancerVault, oneInchRouter, weth, usdt, usdc, dai);
}
// Chain 138: use canonical token defaults and env-driven protocol addresses.
uniswapV3Router = vm.envOr("UNISWAP_V3_ROUTER", PLACEHOLDER);
curve3Pool = vm.envOr("CURVE_3POOL", PLACEHOLDER);
dodoexRouter = vm.envOr("DODOEX_ROUTER", PLACEHOLDER);
balancerVault = vm.envOr("BALANCER_VAULT", PLACEHOLDER);
oneInchRouter = vm.envOr("ONEINCH_ROUTER", PLACEHOLDER);
weth = vm.envOr("WETH", CHAIN138_WETH);
usdt = vm.envOr("OFFICIAL_USDT_ADDRESS", CHAIN138_USDT);
usdc = vm.envOr("OFFICIAL_USDC_ADDRESS", CHAIN138_USDC);
dai = vm.envOr("DAI", CHAIN138_DAI_PLACEHOLDER);
}
}

View File

@@ -9,10 +9,11 @@ import {CompliantFiatToken} from "../../contracts/tokens/CompliantFiatToken.sol"
* @title DeployCompliantFiatTokens
* @notice Deterministic deployment of CompliantFiatToken (cEURC, cEURT, cGBPC, cGBPT, cAUDC, cJPYC, cCHFC, cCADC, cXAUC, cXAUT; optional cCADT) via CREATE2.
* @dev Use same ADMIN/OWNER and salts per chain for identical addresses. See docs/runbooks and TOKEN_SCOPE_GRU.md.
* cXAUC/cXAUT use currency code XAU: **1 full token = 1 troy oz Au** (see CompliantFiatToken NatSpec).
*/
contract DeployCompliantFiatTokens is Script {
uint256 constant DECIMALS = 6;
uint256 constant INITIAL_SUPPLY = 1_000_000 * 10**6; // 1M tokens
uint256 constant INITIAL_SUPPLY = 1_000_000 * 10**6; // 1M units: fiat = currency units; XAU = troy ounces
function run() external {
uint256 pk = vm.envUint("PRIVATE_KEY");

View File

@@ -17,10 +17,12 @@ import {CompliantFiatToken} from "../../contracts/tokens/CompliantFiatToken.sol"
* OWNER, ADMIN (optional; default deployer)
* DEPLOY_CUSDT=1, DEPLOY_CUSDC=1 (default both 1)
* DEPLOY_CEURC=1, DEPLOY_CEURT=1, ... (optional; deploy extra CompliantFiatToken)
*
* XAU: cXAUC/cXAUT — 1 full token = 1 troy ounce Au (see CompliantFiatToken).
*/
contract DeployCompliantFiatTokensForChain is Script {
uint256 constant DECIMALS = 6;
uint256 constant INITIAL_SUPPLY = 1_000_000 * 10**6; // 1M
uint256 constant INITIAL_SUPPLY = 1_000_000 * 10**6; // 1M units (fiat: currency; XAU: troy oz)
function run() external {
uint256 pk = vm.envUint("PRIVATE_KEY");

View File

@@ -41,9 +41,8 @@ contract AddLiquidityPMMPoolsChain138 is Script {
address usdt = integration.officialUSDT();
address usdc = integration.officialUSDC();
// On Chain 138, DODOPMMIntegration may have been deployed with mainnet official USDT/USDC
// (0xdAC17F958D2ee523a2206206994597C13D831ec7, 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48).
// Those addresses have no code on 138, so skip cUSDT/USDT and cUSDC/USDC to avoid "call to non-contract".
// On Chain 138, cUSDT/USDT and cUSDC/USDC should point at live local mirror quote tokens.
// If the configured quote-side addresses have no code on 138, skip those pools to avoid "call to non-contract".
bool skipOfficialPools = block.chainid == 138 && (
!_isContract(usdt) || !_isContract(usdc)
);

View File

@@ -0,0 +1,89 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Script, console} from "forge-std/Script.sol";
import {DODOPMMIntegration} from "../../contracts/dex/DODOPMMIntegration.sol";
/**
* @title CreatePublicXAUPoolsChain138
* @notice Create the public XAU-anchored pools on Chain 138 using the configured cXAU anchor token.
* @dev Env:
* - PRIVATE_KEY
* - DODOPMM_INTEGRATION or DODOPMM_INTEGRATION_ADDRESS
* - XAU_ADDRESS_138 or CXAUC_ADDRESS_138 or CXAUT_ADDRESS_138
* Optional:
* - COMPLIANT_USDT_ADDRESS, COMPLIANT_USDC_ADDRESS, cEURT_ADDRESS_138
* - CREATE_CUSDT_XAU=1, CREATE_CUSDC_XAU=1, CREATE_CEURT_XAU=1
*/
contract CreatePublicXAUPoolsChain138 is Script {
address internal constant CHAIN138_CUSDT = 0x93E66202A11B1772E55407B32B44e5Cd8eda7f22;
address internal constant CHAIN138_CUSDC = 0xf22258f57794CC8E06237084b353Ab30fFfa640b;
address internal constant CHAIN138_CEURT = 0xdf4b71c61E5912712C1Bdd451416B9aC26949d72;
address internal constant CHAIN138_CXAUC = 0x290E52a8819A4fbD0714E517225429aA2B70EC6b;
address internal constant CHAIN138_CXAUT = 0x94e408E26c6FD8F4ee00b54dF19082FDA07dC96E;
uint256 internal constant LP_FEE_BPS = 3;
uint256 internal constant INITIAL_PRICE_1E18 = 1e18;
uint256 internal constant K_50PCT = 0.5e18;
bool internal constant USE_TWAP = true;
function run() external {
uint256 pk = vm.envUint("PRIVATE_KEY");
address integrationAddr = vm.envOr("DODOPMM_INTEGRATION", address(0));
if (integrationAddr == address(0)) integrationAddr = vm.envOr("DODOPMM_INTEGRATION_ADDRESS", address(0));
require(integrationAddr != address(0), "DODOPMM_INTEGRATION not set");
address xau = vm.envOr("XAU_ADDRESS_138", address(0));
if (xau == address(0)) xau = vm.envOr("CXAUC_ADDRESS_138", address(0));
if (xau == address(0)) xau = vm.envOr("CXAUT_ADDRESS_138", address(0));
if (xau == address(0) && block.chainid == 138) xau = CHAIN138_CXAUC;
require(xau != address(0), "XAU anchor not set");
address cUSDT = vm.envOr("COMPLIANT_USDT_ADDRESS", address(0));
address cUSDC = vm.envOr("COMPLIANT_USDC_ADDRESS", address(0));
address cEURT = vm.envOr("cEURT_ADDRESS_138", address(0));
if (cUSDT == address(0) && block.chainid == 138) cUSDT = CHAIN138_CUSDT;
if (cUSDC == address(0) && block.chainid == 138) cUSDC = CHAIN138_CUSDC;
if (cEURT == address(0) && block.chainid == 138) cEURT = CHAIN138_CEURT;
bool createCUSDT = vm.envOr("CREATE_CUSDT_XAU", true);
bool createCUSDC = vm.envOr("CREATE_CUSDC_XAU", true);
bool createCEURT = vm.envOr("CREATE_CEURT_XAU", true);
DODOPMMIntegration integration = DODOPMMIntegration(integrationAddr);
vm.startBroadcast(pk);
if (createCUSDT && cUSDT != address(0)) {
_createIfMissing(integration, cUSDT, xau, "cUSDT/XAU");
}
if (createCUSDC && cUSDC != address(0)) {
_createIfMissing(integration, cUSDC, xau, "cUSDC/XAU");
}
if (createCEURT && cEURT != address(0)) {
_createIfMissing(integration, cEURT, xau, "cEURT/XAU");
}
vm.stopBroadcast();
console.log("Public XAU pools checked against anchor:", xau == CHAIN138_CXAUC ? "cXAUC" : (xau == CHAIN138_CXAUT ? "cXAUT" : "custom"));
console.log("Default Chain 138 XAU anchors:", vm.toString(CHAIN138_CXAUC), vm.toString(CHAIN138_CXAUT));
}
function _createIfMissing(
DODOPMMIntegration integration,
address base,
address quote,
string memory label
) internal {
address existing = integration.pools(base, quote);
if (existing != address(0)) {
console.log(label, "already exists at", existing);
return;
}
address pool = integration.createPool(base, quote, LP_FEE_BPS, INITIAL_PRICE_1E18, K_50PCT, USE_TWAP);
console.log(label, "created at", pool);
}
}

View File

@@ -24,8 +24,16 @@ contract DeployDODOPMMIntegration is Script {
address compliantUSDT = vm.envOr("COMPLIANT_USDT_ADDRESS", address(0));
address compliantUSDC = vm.envOr("COMPLIANT_USDC_ADDRESS", address(0));
if (dodoVendingMachine == address(0) || compliantUSDT == address(0) || compliantUSDC == address(0)) {
console.log("Skipping DODO PMM deploy: set DODO_VENDING_MACHINE_ADDRESS, COMPLIANT_USDT_ADDRESS, COMPLIANT_USDC_ADDRESS in .env");
if (
dodoVendingMachine == address(0) ||
officialUSDT == address(0) ||
officialUSDC == address(0) ||
compliantUSDT == address(0) ||
compliantUSDC == address(0)
) {
console.log(
"Skipping DODO PMM deploy: set DODO_VENDING_MACHINE_ADDRESS, OFFICIAL_USDT_ADDRESS, OFFICIAL_USDC_ADDRESS, COMPLIANT_USDT_ADDRESS, COMPLIANT_USDC_ADDRESS in .env"
);
return;
}
@@ -64,4 +72,3 @@ contract DeployDODOPMMIntegration is Script {
console.log("3. Configure pool parameters (lpFeeRate, k, initialPrice)");
}
}

View File

@@ -13,6 +13,8 @@ import {DODOPMMIntegration} from "../../contracts/dex/DODOPMMIntegration.sol";
* Deployer must have POOL_MANAGER_ROLE on DODOPMMIntegration to create pools.
*/
contract DeployPrivatePoolRegistryAndPools is Script {
address internal constant CHAIN138_CXAUC = 0x290E52a8819A4fbD0714E517225429aA2B70EC6b;
address internal constant CHAIN138_CXAUT = 0x94e408E26c6FD8F4ee00b54dF19082FDA07dC96E;
uint256 constant LP_FEE_BPS = 3;
uint256 constant INITIAL_PRICE_1E18 = 1e18;
uint256 constant K_50PCT = 0.5e18;
@@ -29,35 +31,37 @@ contract DeployPrivatePoolRegistryAndPools is Script {
console.log("PrivatePoolRegistry deployed at:", vm.toString(address(registry)));
address integrationAddr = vm.envOr("DODOPMM_INTEGRATION_ADDRESS", address(0));
if (integrationAddr == address(0)) integrationAddr = vm.envOr("DODO_PMM_INTEGRATION_ADDRESS", address(0));
if (integrationAddr == address(0)) integrationAddr = vm.envOr("DODOPMM_INTEGRATION", address(0));
if (integrationAddr == address(0)) integrationAddr = vm.envOr("DODO_PMM_INTEGRATION", address(0));
address xau = vm.envOr("XAU_ADDRESS_138", address(0));
if (xau == address(0)) xau = vm.envOr("CXAUC_ADDRESS_138", address(0));
if (xau == address(0)) xau = vm.envOr("CXAUT_ADDRESS_138", address(0));
if (xau == address(0) && block.chainid == 138) xau = CHAIN138_CXAUC;
if (integrationAddr != address(0) && xau != address(0)) {
address cUSDT = vm.envOr("COMPLIANT_USDT_ADDRESS", address(0));
address cUSDC = vm.envOr("COMPLIANT_USDC_ADDRESS", address(0));
address cEURT = vm.envOr("cEURT_ADDRESS_138", address(0));
if (cUSDT == address(0) && block.chainid == 138) cUSDT = 0x93E66202A11B1772E55407B32B44e5Cd8eda7f22;
if (cUSDC == address(0) && block.chainid == 138) cUSDC = 0xf22258f57794CC8E06237084b353Ab30fFfa640b;
if (cEURT == address(0) && block.chainid == 138) cEURT = 0xdf4b71c61E5912712C1Bdd451416B9aC26949d72;
DODOPMMIntegration integration = DODOPMMIntegration(integrationAddr);
if (cUSDT != address(0)) {
try integration.createPool(cUSDT, xau, LP_FEE_BPS, INITIAL_PRICE_1E18, K_50PCT, USE_TWAP) returns (address pool) {
registry.register(cUSDT, xau, pool);
console.log("Created and registered cUSDT/XAU pool:", vm.toString(pool));
} catch {}
_ensureRegistered(registry, integration, cUSDT, xau, "cUSDT/XAU");
}
if (cUSDC != address(0)) {
try integration.createPool(cUSDC, xau, LP_FEE_BPS, INITIAL_PRICE_1E18, K_50PCT, USE_TWAP) returns (address pool) {
registry.register(cUSDC, xau, pool);
console.log("Created and registered cUSDC/XAU pool:", vm.toString(pool));
} catch {}
_ensureRegistered(registry, integration, cUSDC, xau, "cUSDC/XAU");
}
if (cEURT != address(0)) {
try integration.createPool(cEURT, xau, LP_FEE_BPS, INITIAL_PRICE_1E18, K_50PCT, USE_TWAP) returns (address pool) {
registry.register(cEURT, xau, pool);
console.log("Created and registered cEURT/XAU pool:", vm.toString(pool));
} catch {}
_ensureRegistered(registry, integration, cEURT, xau, "cEURT/XAU");
}
} else {
console.log("Skipping pool creation (set DODOPMM_INTEGRATION_ADDRESS and XAU_ADDRESS_138 to create XAU-anchored pools)");
console.log(
"Skipping pool creation (set DODOPMM_INTEGRATION_ADDRESS and XAU_ADDRESS_138/CXAUC_ADDRESS_138/CXAUT_ADDRESS_138 to create XAU-anchored pools)"
);
}
vm.stopBroadcast();
@@ -65,5 +69,30 @@ contract DeployPrivatePoolRegistryAndPools is Script {
console.log("\n=== Deployment Summary ===");
console.log("PrivatePoolRegistry:", vm.toString(address(registry)));
console.log("Admin:", vm.toString(admin));
console.log("Default XAU anchor on Chain 138:", vm.toString(CHAIN138_CXAUC));
console.log("Alternate XAU anchor on Chain 138:", vm.toString(CHAIN138_CXAUT));
}
function _ensureRegistered(
PrivatePoolRegistry registry,
DODOPMMIntegration integration,
address base,
address quote,
string memory label
) internal {
address pool = integration.pools(base, quote);
if (pool == address(0)) {
pool = integration.createPool(base, quote, LP_FEE_BPS, INITIAL_PRICE_1E18, K_50PCT, USE_TWAP);
console.log("Created", label, "pool:", vm.toString(pool));
} else {
console.log(label, "pool already exists:", vm.toString(pool));
}
if (registry.getPrivatePool(base, quote) == address(0)) {
registry.register(base, quote, pool);
console.log("Registered", label, "pool:", vm.toString(pool));
} else {
console.log(label, "already registered:", vm.toString(registry.getPrivatePool(base, quote)));
}
}
}

View File

@@ -0,0 +1,135 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {Script, stdJson, console} from "forge-std/Script.sol";
import {DODOPMMIntegration} from "../../contracts/dex/DODOPMMIntegration.sol";
import {DODOPMMProvider} from "../../contracts/liquidity/providers/DODOPMMProvider.sol";
/**
* @title ImportProviderPoolsToIntegration
* @notice Import provider-known pools into DODOPMMIntegration using the desired-state JSON.
* @dev This is the migration path for stale provider-only pools that already exist as DODO pool
* contracts but are missing from integration.pools / allPools / poolConfigs.
*
* Required env:
* - PRIVATE_KEY
* - DODO_PMM_INTEGRATION_ADDRESS (or DODO_PMM_INTEGRATION)
* - DODO_PMM_PROVIDER_ADDRESS (or DODO_PMM_PROVIDER) for target provider compatibility
*
* Optional env:
* - DODO_PMM_PROVIDER_SOURCE_ADDRESS (or DODO_PMM_PROVIDER_SOURCE) to read from an existing provider
* - POOL_CONFIG_JSON (defaults to smom-dbis-138/config/chain138-pmm-pools.json)
* - LP_FEE_RATE / INITIAL_PRICE / K_FACTOR / ENABLE_TWAP to override JSON defaults
*/
contract ImportProviderPoolsToIntegration is Script {
using stdJson for string;
string internal constant DEFAULT_CONFIG_PATH = "config/chain138-pmm-pools.json";
function run() external {
uint256 pk = vm.envUint("PRIVATE_KEY");
address integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION_ADDRESS");
if (integrationAddr == address(0)) integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION");
address providerAddr = vm.envAddress("DODO_PMM_PROVIDER_ADDRESS");
if (providerAddr == address(0)) providerAddr = vm.envAddress("DODO_PMM_PROVIDER");
address providerSourceAddr = vm.envOr("DODO_PMM_PROVIDER_SOURCE_ADDRESS", address(0));
if (providerSourceAddr == address(0)) providerSourceAddr = vm.envOr("DODO_PMM_PROVIDER_SOURCE", address(0));
if (providerSourceAddr == address(0)) providerSourceAddr = providerAddr;
require(integrationAddr != address(0), "DODO_PMM_INTEGRATION_ADDRESS not set");
require(providerAddr != address(0), "DODO_PMM_PROVIDER_ADDRESS not set");
string memory path = vm.envOr("POOL_CONFIG_JSON", string(DEFAULT_CONFIG_PATH));
string memory json = vm.readFile(path);
DODOPMMIntegration integration = DODOPMMIntegration(integrationAddr);
DODOPMMProvider providerSource = DODOPMMProvider(providerSourceAddr);
uint256 lpFeeRate = vm.envOr("LP_FEE_RATE", json.readUint(".defaults.lpFeeRate"));
uint256 initialPrice = vm.envOr("INITIAL_PRICE", json.readUint(".defaults.initialPrice"));
uint256 kFactor = vm.envOr("K_FACTOR", json.readUint(".defaults.kFactor"));
bool enableTwap = vm.envOr("ENABLE_TWAP", json.readBool(".defaults.enableTwap"));
string[] memory cStars = json.readStringArray(".groups.cStarSymbols");
string[] memory officials = json.readStringArray(".groups.officialStableSymbols");
string memory wethSymbol = json.readString(".groups.wethSymbol");
bool deployCStarVsCStar = json.readBool(".groups.deploy.cStarVsCStar");
bool deployCStarVsOfficial = json.readBool(".groups.deploy.cStarVsOfficial");
bool deployCStarVsWeth = json.readBool(".groups.deploy.cStarVsWeth");
bool deployOfficialVsWeth = json.readBool(".groups.deploy.officialVsWeth");
vm.startBroadcast(pk);
if (deployCStarVsCStar) {
for (uint256 i = 0; i < cStars.length; i++) {
for (uint256 j = i + 1; j < cStars.length; j++) {
_importIfNeeded(json, providerSource, integration, cStars[i], cStars[j], lpFeeRate, initialPrice, kFactor, enableTwap);
}
}
}
if (deployCStarVsOfficial) {
for (uint256 i = 0; i < cStars.length; i++) {
for (uint256 j = 0; j < officials.length; j++) {
_importIfNeeded(json, providerSource, integration, cStars[i], officials[j], lpFeeRate, initialPrice, kFactor, enableTwap);
}
}
}
if (deployCStarVsWeth) {
for (uint256 i = 0; i < cStars.length; i++) {
_importIfNeeded(json, providerSource, integration, cStars[i], wethSymbol, lpFeeRate, initialPrice, kFactor, enableTwap);
}
}
if (deployOfficialVsWeth) {
for (uint256 i = 0; i < officials.length; i++) {
_importIfNeeded(json, providerSource, integration, officials[i], wethSymbol, lpFeeRate, initialPrice, kFactor, enableTwap);
}
}
for (uint256 i = 0; json.keyExists(string.concat(".explicitPairs[", vm.toString(i), "]")); i++) {
string memory baseKey = string.concat(".explicitPairs[", vm.toString(i), "].baseSymbol");
string memory quoteKey = string.concat(".explicitPairs[", vm.toString(i), "].quoteSymbol");
string memory explicitBase = json.readString(baseKey);
string memory explicitQuote = json.readString(quoteKey);
_importIfNeeded(json, providerSource, integration, explicitBase, explicitQuote, lpFeeRate, initialPrice, kFactor, enableTwap);
}
vm.stopBroadcast();
}
function _importIfNeeded(
string memory json,
DODOPMMProvider provider,
DODOPMMIntegration integration,
string memory baseSymbol,
string memory quoteSymbol,
uint256 lpFeeRate,
uint256 initialPrice,
uint256 kFactor,
bool enableTwap
) internal {
address base = json.readAddress(string.concat(".tokens.", baseSymbol));
address quote = json.readAddress(string.concat(".tokens.", quoteSymbol));
if (base == address(0) || quote == address(0) || base == quote) return;
address integrationPool = integration.pools(base, quote);
if (integrationPool != address(0)) return;
address providerPool = provider.pools(base, quote);
if (providerPool == address(0)) return;
integration.importExistingPool(
providerPool,
base,
quote,
lpFeeRate,
initialPrice,
kFactor,
enableTwap
);
console.log("Imported:", baseSymbol, "/", quoteSymbol);
console.log("Pool:", providerPool);
}
}

View File

@@ -7,10 +7,11 @@ import {DODOPMMIntegration} from "../../contracts/dex/DODOPMMIntegration.sol";
/**
* @title RegisterDODOPools
* @notice Register existing DODO PMM pools with DODOPMMProvider.
* @notice Register all existing DODO PMM pools from DODOPMMIntegration with DODOPMMProvider.
* @dev Set DODO_PMM_PROVIDER_ADDRESS, DODO_PMM_INTEGRATION (or DODO_PMM_INTEGRATION_ADDRESS).
* Pool addresses: POOL_CUSDTCUSDC, POOL_CUSDTUSDT, POOL_CUSDCUSDC (optional).
* Token addresses read from integration if not in env.
* Reads integration.getAllPools() and poolConfigs(pool), then registers both directions
* for every discovered pool so provider.supportsTokenPair() and executeSwap() work
* symmetrically across the current live set and any future c* full-mesh expansion.
*/
contract RegisterDODOPools is Script {
function run() external {
@@ -18,34 +19,35 @@ contract RegisterDODOPools is Script {
address providerAddr = vm.envAddress("DODO_PMM_PROVIDER_ADDRESS");
address integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION");
if (integrationAddr == address(0)) integrationAddr = vm.envAddress("DODO_PMM_INTEGRATION_ADDRESS");
require(providerAddr != address(0), "DODO_PMM_PROVIDER_ADDRESS not set");
require(integrationAddr != address(0), "DODO_PMM_INTEGRATION not set");
DODOPMMIntegration integration = DODOPMMIntegration(integrationAddr);
address cusdt = integration.compliantUSDT();
address cusdc = integration.compliantUSDC();
address usdt = integration.officialUSDT();
address usdc = integration.officialUSDC();
address poolCusdtCusdc = vm.envOr("POOL_CUSDTCUSDC", address(0));
address poolCusdtUsdt = vm.envOr("POOL_CUSDTUSDT", address(0));
address poolCusdcUsdc = vm.envOr("POOL_CUSDCUSDC", address(0));
DODOPMMProvider provider = DODOPMMProvider(providerAddr);
address[] memory pools = integration.getAllPools();
require(pools.length > 0, "No pools found in DODOPMMIntegration");
vm.startBroadcast(pk);
if (poolCusdtCusdc != address(0)) {
provider.registerPool(cusdt, cusdc, poolCusdtCusdc);
console.log("Registered cUSDT/cUSDC pool:", poolCusdtCusdc);
for (uint256 i = 0; i < pools.length; i++) {
try integration.getPoolConfig(pools[i]) returns (DODOPMMIntegration.PoolConfig memory config) {
_registerPair(provider, config.baseToken, config.quoteToken, pools[i]);
} catch {
console.log("Skipping removed or unreadable pool:", pools[i]);
}
}
if (poolCusdtUsdt != address(0)) {
provider.registerPool(cusdt, usdt, poolCusdtUsdt);
console.log("Registered cUSDT/USDT pool:", poolCusdtUsdt);
}
if (poolCusdcUsdc != address(0)) {
provider.registerPool(cusdc, usdc, poolCusdcUsdc);
console.log("Registered cUSDC/USDC pool:", poolCusdcUsdc);
}
vm.stopBroadcast();
}
function _registerPair(
DODOPMMProvider provider,
address tokenA,
address tokenB,
address pool
) internal {
provider.registerPool(tokenA, tokenB, pool);
provider.registerPool(tokenB, tokenA, pool);
console.log("Registered base:", tokenA);
console.log("Registered quote:", tokenB);
console.log("Pool:", pool);
}
}