fix: address AI review findings on VWAP bootstrap PR

SPDX license:
- Restore GPL-3.0-or-later SPDX header to DeployBase.sol (removed by
  the em-dash sed fix in an earlier commit).

SeedSwapper deduplication:
- Extract SeedSwapper into onchain/script/DeployCommon.sol — a single
  canonical definition shared by both deploy scripts.  This eliminates
  duplicate Foundry artifacts (previously both DeployLocal.sol and
  DeployBase.sol produced a SeedSwapper artifact, causing ambiguity for
  verification and coverage tools).
- Remove inline SeedSwapper and redundant IWETH9 import from
  DeployLocal.sol and DeployBase.sol; add `import "./DeployCommon.sol"`.

SeedSwapper hardening (in DeployCommon.sol):
- Replace magic-literal price sentinels with named constants
  SQRT_PRICE_LIMIT_MIN / SQRT_PRICE_LIMIT_MAX.
- Wrap both weth.transfer() calls with require() so a non-standard
  WETH9 false-return is caught rather than silently ignored.
- Add post-swap WETH sweep in executeSeedBuy(): if the price limit is
  reached before the full input is spent, the residual WETH balance is
  returned to `recipient` instead of being stranded in the contract.

bootstrap-common.sh:
- Normalise cumulativeVolume output through `cast to-dec` before the
  string comparison, guarding against a future change in cast output
  format (decimal vs hex).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
openhands 2026-03-13 00:12:39 +00:00
parent 3e9c3e6533
commit 38bc0f7057
4 changed files with 74 additions and 97 deletions

View file

@ -7,59 +7,11 @@ import { LiquidityManager } from "../src/LiquidityManager.sol";
import "../src/Optimizer.sol";
import "../src/Stake.sol";
import "../src/helpers/UniswapHelpers.sol";
import { IWETH9 } from "../src/interfaces/IWETH9.sol";
import { ERC1967Proxy } from "@openzeppelin/proxy/ERC1967/ERC1967Proxy.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import "forge-std/Script.sol";
/**
* @title SeedSwapper
* @notice One-shot helper deployed during DeployLocal.run() to perform the initial seed buy.
* Executing a small buy before the protocol opens eliminates the cumulativeVolume==0
* front-run window: after the seed recenter, VWAP has a real anchor and the bootstrap
* path in LiquidityManager.recenter() is never reachable by external users.
*/
contract SeedSwapper {
IWETH9 private immutable weth;
IUniswapV3Pool private immutable pool;
bool private immutable token0isWeth;
constructor(address _weth, address _pool, bool _token0isWeth) {
weth = IWETH9(_weth);
pool = IUniswapV3Pool(_pool);
token0isWeth = _token0isWeth;
}
/// @notice Wraps msg.value ETH to WETH and swaps it for KRK (buying KRK).
/// The KRK output is sent to `recipient`. The fee generated by the swap
/// is captured in the LM's positions, so the subsequent recenter() call
/// will collect a non-zero ethFee and record VWAP.
function executeSeedBuy(address recipient) external payable {
weth.deposit{ value: msg.value }();
// zeroForOne=true when WETH is token0: sell token0(WETH) token1(KRK)
// zeroForOne=false when WETH is token1: sell token1(WETH) token0(KRK)
bool zeroForOne = token0isWeth;
// Price limits: allow the swap to reach the extreme of the range.
// TickMath.MIN_SQRT_RATIO + 1 and MAX_SQRT_RATIO - 1 are the standard sentinels.
uint160 priceLimit = zeroForOne
? 4295128740 // TickMath.MIN_SQRT_RATIO + 1
: 1461446703485210103287273052203988822378723970341; // TickMath.MAX_SQRT_RATIO - 1
pool.swap(recipient, zeroForOne, int256(msg.value), priceLimit, "");
}
/// @notice Uniswap V3 callback: pay the WETH owed for the seed buy.
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata) external {
require(msg.sender == address(pool), "only pool");
int256 wethDelta = token0isWeth ? amount0Delta : amount1Delta;
if (wethDelta > 0) {
weth.transfer(msg.sender, uint256(wethDelta));
}
}
}
import "./DeployCommon.sol";
/**
* @title DeployLocal