- 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
45 lines
1.6 KiB
Solidity
45 lines
1.6 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity ^0.8.20;
|
|
|
|
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
|
|
|
interface IDODOIntegrationSwapExactIn {
|
|
function swapExactIn(address pool, address tokenIn, uint256 amountIn, uint256 minAmountOut)
|
|
external
|
|
returns (uint256 amountOut);
|
|
}
|
|
|
|
/**
|
|
* @title DODOIntegrationExternalUnwinder
|
|
* @notice Unwinds base -> quote through a DODO PMM integration.
|
|
* @dev `data` must be `abi.encode(address pool)` selecting the registered pool to use.
|
|
*/
|
|
contract DODOIntegrationExternalUnwinder {
|
|
using SafeERC20 for IERC20;
|
|
|
|
address public immutable integration;
|
|
|
|
error BadParams();
|
|
|
|
constructor(address integration_) {
|
|
integration = integration_;
|
|
}
|
|
|
|
function unwind(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, bytes calldata data)
|
|
external
|
|
returns (uint256 amountOut)
|
|
{
|
|
if (tokenIn == address(0) || tokenOut == address(0) || tokenIn == tokenOut || amountIn == 0) revert BadParams();
|
|
if (data.length != 32) revert BadParams();
|
|
|
|
address pool = abi.decode(data, (address));
|
|
if (pool == address(0)) revert BadParams();
|
|
|
|
IERC20(tokenIn).safeTransferFrom(msg.sender, address(this), amountIn);
|
|
IERC20(tokenIn).forceApprove(integration, amountIn);
|
|
amountOut = IDODOIntegrationSwapExactIn(integration).swapExactIn(pool, tokenIn, amountIn, minAmountOut);
|
|
IERC20(tokenOut).safeTransfer(msg.sender, amountOut);
|
|
}
|
|
}
|