Files
smom-dbis-138/test/flash/UniswapV3ExternalUnwinderFork.t.sol
defiQUG 76aa419320 feat: bridges, PMM, flash workflow, token-aggregation, and deployment docs
- CCIP/trustless bridge contracts, GRU tokens, DEX/PMM tests, reserve vault.
- Token-aggregation service routes, planner, chain config, relay env templates.
- Config snapshots and multi-chain deployment markdown updates.
- gitignore services/btc-intake/dist/ (tsc output); do not track dist.

Run forge build && forge test before deploy (large solc graph).

Made-with: Cursor
2026-04-07 23:40:52 -07:00

58 lines
1.9 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Test} from "forge-std/Test.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {UniswapV3ExternalUnwinder} from "../../contracts/flash/UniswapV3ExternalUnwinder.sol";
contract UniswapV3ExternalUnwinderForkTest is Test {
address constant UNISWAP_V3_ROUTER = 0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45;
address constant WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
address constant USDC = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48;
address constant CWUSDC = 0x2de5F116bFcE3d0f922d9C8351e0c5Fc24b9284a;
bool public forkAvailable;
UniswapV3ExternalUnwinder internal unwinder;
function setUp() public {
string memory rpcUrl = vm.envOr("ETHEREUM_MAINNET_RPC", string(""));
if (bytes(rpcUrl).length == 0) {
forkAvailable = false;
return;
}
try vm.createSelectFork(rpcUrl) {
forkAvailable = true;
} catch {
forkAvailable = false;
return;
}
unwinder = new UniswapV3ExternalUnwinder(UNISWAP_V3_ROUTER);
}
modifier skipIfNoFork() {
if (!forkAvailable) {
return;
}
_;
}
function testFork_knownRoute_WETHToUSDC_singleHopWorks() public skipIfNoFork {
deal(WETH, address(unwinder), 1 ether);
uint256 before = IERC20(USDC).balanceOf(address(this));
uint256 amountOut = unwinder.unwind(WETH, USDC, 1 ether, 1, abi.encode(uint24(3000)));
uint256 afterBal = IERC20(USDC).balanceOf(address(this));
assertGt(amountOut, 0, "amountOut > 0");
assertEq(afterBal - before, amountOut, "USDC received");
}
function testFork_cWUSDCToUSDC_routeUnavailableOnUniswapV3() public skipIfNoFork {
deal(CWUSDC, address(unwinder), 1_000_000);
vm.expectRevert();
unwinder.unwind(CWUSDC, USDC, 1_000_000, 1, abi.encode(uint24(3000)));
}
}