Skip to content
Verified contractExactMIT

WBTCCicadaConverter

Address0xece8864f7243da7f0a5a7efd1dd46eb4762d9773
Balance

0 ETH

 

Transactions

10

 

Compiler

solc 0.8.27

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.27+commit.40a35a09
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
23,218,572
Creation transaction
0x263bfe41d5…ff3849bfb3

src/wBTCConverter.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {IStrBTC} from "./IStrBTC.sol";

/**
 * @title WBTCCicadaConverter
 * @notice Converter for strBTC minting against WBTC collateral with 1:1 rate
 */
contract WBTCCicadaConverter {
    error AmountMustBeGreaterThanZero();
    error InsufficientWBTCBalance();
    error NotMinter();
    error NotTimelock();
    error RedeemNotAllowed();
    error WhitelistAlreadyDisabled();
    error TransferFailed();

    IStrBTC public immutable STRBTC;
    IERC20 public immutable WBTC;

    address public immutable CICADA_MINTER;
    address public immutable CICADA_REDEEMER;
    address public immutable TIMELOCK;

    bool public whitelistDisabled;

    event WBTCDepositedAndMinted(address indexed caller, address indexed recipient, uint256 wbtcAmount);
    event StrBTCRedeemedForWBTC(address indexed caller, address indexed recipient, uint256 strbtcAmount);
    event RedeemWhitelistDisabled(address indexed caller);

    modifier onlyTimelock() {
        if (msg.sender != TIMELOCK) revert NotTimelock();
        _;
    }

    /**
     * @notice Constructor
     * @param _wbtc address of the WBTC token
     * @param _strbtc address of the strBTC token
     * @param _cicadaMinter address of the minter (defined by Cicada)
     * @param _cicadaRedeemer address of Cicada, which has the right to redeem until whitelist is disabled
     * @param _timelock address of TimelockController, which can disable the whitelist
     */
    constructor(address _wbtc, address _strbtc, address _cicadaMinter, address _cicadaRedeemer, address _timelock) {
        WBTC = IERC20(_wbtc);
        STRBTC = IStrBTC(_strbtc);

        CICADA_MINTER = _cicadaMinter;
        CICADA_REDEEMER = _cicadaRedeemer;
        TIMELOCK = _timelock;

        whitelistDisabled = false;
    }

    /**
     * @notice Deposit WBTC and mint strBTC 1:1 to `recipient`
     * @param amount amount of WBTC to deposit
     * @param recipient address of the recipient of strBTC
     * @return amount of minted strBTC
     */
    function convertWBTCToStrBTC(uint256 amount, address recipient) external returns (uint256) {
        if (msg.sender != CICADA_MINTER) revert NotMinter();
        if (amount == 0) revert AmountMustBeGreaterThanZero();

        bool success = WBTC.transferFrom(msg.sender, address(this), amount);
        if (!success) revert TransferFailed();

        STRBTC.converterMint(recipient, amount);

        emit WBTCDepositedAndMinted(msg.sender, recipient, amount);

        return amount;
    }

    /**
     * @notice Redeem strBTC for WBTC 1:1. While whitelist is enabled, only `cicadaRedeemer` can call
     * @param amount amount of strBTC to redeem
     * @param recipient address of the recipient of WBTC
     * @return amount of redeemed WBTC
     */
    function convertStrBTCToWBTC(uint256 amount, address recipient) external returns (uint256) {
        if (amount == 0) revert AmountMustBeGreaterThanZero();
        if (!whitelistDisabled && msg.sender != CICADA_REDEEMER) revert RedeemNotAllowed();

        if (WBTC.balanceOf(address(this)) < amount) revert InsufficientWBTCBalance();

        bool success = STRBTC.transferFrom(msg.sender, address(this), amount);
        if (!success) revert TransferFailed();

        STRBTC.converterBurn(address(this), amount);

        success = WBTC.transfer(recipient, amount);
        if (!success) revert TransferFailed();

        emit StrBTCRedeemedForWBTC(msg.sender, recipient, amount);

        return amount;
    }

    /**
     * @notice Disable the redeem whitelist. Can only be called by TimelockController
     */
    function disableRedeemWhitelist() external onlyTimelock {
        if (whitelistDisabled) revert WhitelistAlreadyDisabled();
        whitelistDisabled = true;
        emit RedeemWhitelistDisabled(msg.sender);
    }
}

lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

src/IStrBTC.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

interface IStrBTC {
    function totalSupply() external view returns (uint256);
    function totalShares() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function getSharesByPooledBTC(uint256 btcAmount) external view returns (uint256);
    function getPooledBTCByShares(uint256 sharesAmount) external view returns (uint256);
    function converterMint(address to, uint256 amount) external;
    function converterBurn(address from, uint256 amount) external;
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.