// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Script, console} from "forge-std/Script.sol";
import {AaveUniV2CwStableRebalanceFlashReceiver} from "../../contracts/flash/AaveUniV2CwStableRebalanceFlashReceiver.sol";

/**
 * @title DeployAaveUniV2CwStableRebalanceFlashReceiver
 * @notice Deploy the UniV2 rebalance + remove Aave flash receiver.
 *
 * Env:
 *   PRIVATE_KEY
 *   AAVE_POOL_ADDRESS              optional; default Aave V3 mainnet Pool
 *   UNIV2_FLASH_REBALANCE_OWNER    optional; default deployer
 */
contract DeployAaveUniV2CwStableRebalanceFlashReceiver is Script {
    address internal constant DEFAULT_AAVE_POOL_MAINNET = 0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2;

    function run() external {
        uint256 pk = vm.envUint("PRIVATE_KEY");
        address pool = vm.envOr("AAVE_POOL_ADDRESS", DEFAULT_AAVE_POOL_MAINNET);
        address deployer = vm.addr(pk);
        address owner = vm.envOr("UNIV2_FLASH_REBALANCE_OWNER", deployer);

        vm.startBroadcast(pk);
        AaveUniV2CwStableRebalanceFlashReceiver receiver =
            new AaveUniV2CwStableRebalanceFlashReceiver(pool, owner);
        vm.stopBroadcast();

        console.log("AaveUniV2CwStableRebalanceFlashReceiver", address(receiver));
        console.log("owner", owner);
        console.log("aavePool", pool);
    }
}
