账户
0xda...d9f8
0xda...d9F8

0xda...d9F8

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.17+commit.8df45f5f
语言
Solidity
合同源代码
文件 1 的 11:Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}
合同源代码
文件 2 的 11:Common.sol
/*
    SPDX-License-Identifier: Apache-2.0
*/

pragma solidity ^0.8.4;

library Common {
    function _validateAddress(address _addr) internal pure {
        require(_addr != address(0), "Address cannot be zero");
    }

    function _isContract(address account) internal view returns (bool) {
        return account.code.length > 0;
    }
}
合同源代码
文件 3 的 11:ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}
合同源代码
文件 4 的 11:IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
合同源代码
文件 5 的 11:IERC20.sol
// This is a file copied from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.4;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    function decimals() external view returns (uint8);

    function name() external view returns (string memory);

    function symbol() external view returns (string memory);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;
  
}
合同源代码
文件 6 的 11:IStarBaseDCA.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStarBaseDCA {
    // Order 结构体
    struct Order {
        uint160 cycleSecondsApart; // executed per second
        uint160 numberOfTrade; // executed 5 times
        address inputToken; // sell
        address outputToken; // buy
        address maker;
        uint160 inAmount; // One of the total (numberOfTrade)
        uint256 minOutAmountPerCycle; // min out amount
        uint256 maxOutAmountPerCycle; // max out amount
        uint256 expiration;
        uint256 salt;
    }
    // ============ DCA ===============
    function fillDCA(
        Order memory order,
        bytes memory signature,
        bytes memory takerInteraction
    ) external returns (uint256 curTakerFillAmount);

    function cancelOrder(Order memory order, bytes memory signature) external;
}
合同源代码
文件 7 的 11:IStarBaseDCABot.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IStarBaseDCABot {
    function fillStarBaseDCA(bytes memory callExternalData, address outputToken, uint256 minOutputTokenAmount) external;
}
合同源代码
文件 8 的 11:IStarBaseRouter.sol
/*

    Copyright 2020 StarBase.
    SPDX-License-Identifier: Apache-2.0

*/

pragma solidity ^0.8.4;

interface IStarBaseRouter {
    function defiSwap(
        uint amountIn,
        uint amountOutMin,
        address tokenIn,
        address tokenOut,
        address receiver,
        address callSwapAddr,
        bytes calldata datas
    ) external;
}
合同源代码
文件 9 的 11:InitializableOwnable.sol
/*

    Copyright 2020 StarBase  .
    SPDX-License-Identifier: Apache-2.0

*/

pragma solidity ^0.8.4;

/**
 * @title Ownable
 * @author StarBase  Simon
 *
 * @notice Ownership related functions
 */
contract InitializableOwnable {
    address public _OWNER_;
    address public _NEW_OWNER_;
    bool internal _INITIALIZED_;

    // ============ Events ============

    event OwnershipTransferPrepared(address indexed previousOwner, address indexed newOwner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    // ============ Modifiers ============

    modifier notInitialized() {
        require(!_INITIALIZED_, "StarBase_INITIALIZED");
        _;
    }

    modifier onlyOwner() {
        require(msg.sender == _OWNER_, "NOT_OWNER");
        _;
    }

    // ============ Functions ============

    function initOwner(address newOwner) public notInitialized {
        _INITIALIZED_ = true;
        _OWNER_ = newOwner;
    }

    function transferOwnership(address newOwner) public onlyOwner {
        emit OwnershipTransferPrepared(_OWNER_, newOwner);
        _NEW_OWNER_ = newOwner;
    }

    function claimOwnership() public {
        require(msg.sender == _NEW_OWNER_, "INVALID_CLAIM");
        emit OwnershipTransferred(_OWNER_, _NEW_OWNER_);
        _OWNER_ = _NEW_OWNER_;
        _NEW_OWNER_ = address(0);
    }
}
合同源代码
文件 10 的 11:SafeERC20.sol
/*

    Copyright 2020 StarBase  .
    SPDX-License-Identifier: Apache-2.0
    This is a simplified version of OpenZepplin's SafeERC20 library

*/

pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/Address.sol";
import { IERC20 } from "../intf/IERC20.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        require(Address.isContract(address(token)), "SafeERC20: call to non-contract");
        (bool success, bytes memory returndata) = address(token).call(data);
        require(success, "SafeERC20: low-level call failed");

        if (returndata.length > 0) {
            // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}
合同源代码
文件 11 的 11:StarBaseDCABot.sol
/*
    Copyright 2024 StarBase  .
    SPDX-License-Identifier: Apache-2.0
*/
pragma solidity ^0.8.4;

import { InitializableOwnable } from "./lib/InitializableOwnable.sol";
import { IERC20 } from "./intf/IERC20.sol";
import { SafeERC20 } from "./lib/SafeERC20.sol";
import { IStarBaseRouter } from "./intf/IStarBaseRouter.sol";
import { ERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { Common } from "./lib/Common.sol";
import { IStarBaseDCA } from "./intf/IStarBaseDCA.sol";
import { IStarBaseDCABot } from "./intf/IStarBaseDCABot.sol";

/**
 * @title StarBaseDCABot
 * @dev This contract is a DCA (Dollar Cost Averaging) bot for StarBase, enabling users to automate trades and interact with StarBase's DCA mechanism.
 * @notice The bot allows admin users to initiate DCA trades and perform token swaps through a connected router.
 * @author StarBase
 */
contract StarBaseDCABot is InitializableOwnable, ERC165 {
    using SafeERC20 for IERC20;

    // ================ Storage ================
    address public _StarBase_DCA_;
    address public _TOKEN_RECEIVER_;
    mapping(address => bool) public isAdminListed;
    address public _Setup_Tool_;

    // ================ Events ================
    event AddAdmin(address indexed admin);
    event RemoveAdmin(address indexed admin);
    event ChangeReceiver(address indexed newReceiver);
    event Fill(bytes, address, uint256);

    struct SwapData {
        address callSwapAddr;
        bytes datas;
    }

    /**
     * @dev Initializes the contract with the given parameters.
     * @param owner The address of the owner.
     * @param tokenReceiver The address of the token receiver for the filled DCA trades.
     * @param userAddr List of admin addresses that are allowed to execute certain functions.
     */
    constructor(address owner, address tokenReceiver, address[] memory userAddr) {
        Common._validateAddress(owner);
        Common._validateAddress(tokenReceiver);

        initOwner(owner);
        _TOKEN_RECEIVER_ = tokenReceiver;
        emit ChangeReceiver(_TOKEN_RECEIVER_);

        for (uint i = 0; i < userAddr.length; i++) {
            isAdminListed[userAddr[i]] = true;
            emit AddAdmin(userAddr[i]);
        }
    }

    /**
     * @dev Executes the DCA trade by interacting with the StarBase DCA contract and transferring the resulting tokens.
     * @param callExternalData Data to call the external DCA contract with.
     * @param outputToken The address of the token that is received after the DCA trade.
     * @param minOutputTokenAmount The minimum amount of the output token that should be received.
     */
    function fillStarBaseDCA(
        bytes memory callExternalData,
        address outputToken,
        uint256 minOutputTokenAmount
    ) external {
        require(isAdminListed[msg.sender], "SDCAB: ACCESS_DENIED");

        Common._validateAddress(outputToken);
        uint256 originTakerBalance = IERC20(outputToken).balanceOf(address(this));

        (bool success, bytes memory data) = _StarBase_DCA_.call(callExternalData);
        if (!success) {
            assembly {
                revert(add(data, 32), mload(data))
            }
        }

        uint256 leftTakerAmount = IERC20(outputToken).balanceOf(address(this)) - originTakerBalance;
        require(leftTakerAmount >= minOutputTokenAmount, "SDCAB: TAKER_AMOUNT_NOT_ENOUGH");
        IERC20(outputToken).safeTransfer(_TOKEN_RECEIVER_, leftTakerAmount);

        emit Fill(callExternalData, outputToken, minOutputTokenAmount);
    }

    /**
     * @dev Executes a swap on the DCA contract using the provided parameters.
     * @param inAmount The amount of the input token to swap.
     * @param minOutAmount The minimum amount of output token to receive.
     * @param maxOutAmount The maximum amount of output token to allow.
     * @param inputToken The address of the input token.
     * @param outputToken The address of the output token.
     * @param StarBaseRouteProxy The address of the StarBase route proxy for swapping.
     * @param datas Data for the swap call.
     * @return returnTakerAmount The amount of output token received from the swap.
     */
    function doDCASwap(
        uint256 inAmount,
        uint256 minOutAmount,
        uint256 maxOutAmount,
        address inputToken,
        address outputToken,
        address StarBaseRouteProxy,
        SwapData calldata datas
    ) external returns (uint256 returnTakerAmount) {
        Common._validateAddress(inputToken);
        Common._validateAddress(outputToken);
        Common._validateAddress(StarBaseRouteProxy);

        require(msg.sender == _StarBase_DCA_, "SDCAB: ACCESS_DENIED");
        uint256 originTakerBalance = IERC20(outputToken).balanceOf(address(this));
        _approve(IERC20(inputToken), StarBaseRouteProxy, inAmount);

        IStarBaseRouter(StarBaseRouteProxy).defiSwap(
            inAmount,
            minOutAmount,
            inputToken,
            outputToken,
            address(this),
            datas.callSwapAddr,
            datas.datas
        );

        returnTakerAmount = IERC20(outputToken).balanceOf(address(this)) - originTakerBalance;

        require(returnTakerAmount >= minOutAmount, "SDCAB: SWAP_TAKER_AMOUNT_NOT_ENOUGH");

        if (returnTakerAmount > maxOutAmount) {
            returnTakerAmount = maxOutAmount;
        }

        _approve(IERC20(outputToken), _StarBase_DCA_, returnTakerAmount);
    }

    function _checkIfContractSupportsInterface(address _contract, bytes4 interfaceId) internal view returns (bool) {
        (bool success, bytes memory result) = _contract.staticcall(
            abi.encodeWithSelector(ERC165.supportsInterface.selector, interfaceId)
        );

        if (success && result.length == 32) {
            return abi.decode(result, (bool));
        }
        return false;
    }

    function supportsInterface(bytes4 interfaceId) public pure override(ERC165) returns (bool) {
        return interfaceId == type(IStarBaseDCABot).interfaceId;
    }

    // ============= Ownable Functions =============
    function setDcaContract(address StarBaseDCA) external onlyOwner {
        require(
            _checkIfContractSupportsInterface(StarBaseDCA, type(IStarBaseDCA).interfaceId),
            "SLOP: ADDRESS_DOES_NOT_IMPLEMENT_REQUIRED_METHODS"
        );

        _StarBase_DCA_ = StarBaseDCA;
    }
    /**
     * @dev Adds an address to the list of admin addresses.
     * @param userAddr The address of the user to add as an admin.
     */
    function addAdminList(address userAddr) external onlyOwner {
        Common._validateAddress(userAddr);
        isAdminListed[userAddr] = true;
        emit AddAdmin(userAddr);
    }

    /**
     * @dev Removes an address from the list of admin addresses.
     * @param userAddr The address of the user to remove from the admin list.
     */
    function removeAdminList(address userAddr) external onlyOwner {
        Common._validateAddress(userAddr);
        isAdminListed[userAddr] = false;
        emit RemoveAdmin(userAddr);
    }

    /**
     * @dev Changes the address where the tokens are sent after a DCA fill.
     * @param newTokenReceiver The address of the new token receiver.
     */
    function changeTokenReceiver(address newTokenReceiver) external onlyOwner {
        Common._validateAddress(newTokenReceiver);
        _TOKEN_RECEIVER_ = newTokenReceiver;
        emit ChangeReceiver(newTokenReceiver);
    }

    // ============= Internal Functions =============

    /**
     * @dev Approves the specified amount of a token for a given spender.
     * @param token The token to approve.
     * @param to The address to approve.
     * @param amount The amount to approve.
     */
    function _approve(IERC20 token, address to, uint256 amount) internal {
        uint256 allowance = token.allowance(address(this), to);

        // Only approve if the current allowance is less than the required amount
        if (allowance < amount) {
            // Reset allowance to zero first to avoid race condition
            if (allowance > 0) {
                token.safeApprove(to, 0);
            }
            // Approve exactly the required amount
            token.safeApprove(to, amount);
        }
    }

    // ============= View Functions =============

    /**
     * @dev Returns the current version of the contract.
     * @return The current version number.
     */
    function version() external pure returns (uint256) {
        return 101;
    }
}
设置
{
  "compilationTarget": {
    "src/StarBaseDCABot.sol": "StarBaseDCABot"
  },
  "evmVersion": "london",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": false,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"tokenReceiver","type":"address"},{"internalType":"address[]","name":"userAddr","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"AddAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newReceiver","type":"address"}],"name":"ChangeReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"","type":"bytes"},{"indexed":false,"internalType":"address","name":"","type":"address"},{"indexed":false,"internalType":"uint256","name":"","type":"uint256"}],"name":"Fill","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferPrepared","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"admin","type":"address"}],"name":"RemoveAdmin","type":"event"},{"inputs":[],"name":"_NEW_OWNER_","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_OWNER_","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_Setup_Tool_","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_StarBase_DCA_","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_TOKEN_RECEIVER_","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddr","type":"address"}],"name":"addAdminList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newTokenReceiver","type":"address"}],"name":"changeTokenReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"inAmount","type":"uint256"},{"internalType":"uint256","name":"minOutAmount","type":"uint256"},{"internalType":"uint256","name":"maxOutAmount","type":"uint256"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"address","name":"StarBaseRouteProxy","type":"address"},{"components":[{"internalType":"address","name":"callSwapAddr","type":"address"},{"internalType":"bytes","name":"datas","type":"bytes"}],"internalType":"struct StarBaseDCABot.SwapData","name":"datas","type":"tuple"}],"name":"doDCASwap","outputs":[{"internalType":"uint256","name":"returnTakerAmount","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"callExternalData","type":"bytes"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"minOutputTokenAmount","type":"uint256"}],"name":"fillStarBaseDCA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"initOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAdminListed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddr","type":"address"}],"name":"removeAdminList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"StarBaseDCA","type":"address"}],"name":"setDcaContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]