Skip to content
Verified contractPartialGPL-3.0

EWBCreditBridge

Address0x4e66693a6331788036e25b39d71e2ae82be64d58
Balance

0.03 ETH

 

Transactions

4

 

Compiler

solc 0.8.19

 

Same code

1 more contract

 

Details

Compiler
solc 0.8.19+commit.7dd6d404
Language
solidity
Optimization
Yes, 200 runs
Via IR
yes
License
GPL-3.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,185,094
Creation transaction
0xf3d338e417…1c39d9bc2b

contracts/EWBCreditBridge.sol

// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.19;

/**
 * @title EWBCreditBridge
 * @author Wayne Fyffe — Exposed Walls (EWB)
 *
 * ================================================================
 * WHAT THIS CONTRACT DOES
 * ================================================================
 *
 * The automated link between WhaleVault and DeltaNeutralVault.
 *
 * When Wayne locks minting rights in WhaleVault, this contract
 * automatically deploys ETH into DeltaNeutralVault to start
 * generating yield. No second signature needed.
 *
 * ================================================================
 * FULL AUTOMATED LOOP
 * ================================================================
 *
 *   STEP 1 — Wayne funds the bridge (one time)
 *   Ballet wallet calls fund() and sends ETH
 *   ETH sits in bridge ready to deploy
 *
 *   STEP 2 — Wayne locks minting rights (Ballet signs once)
 *   WhaleVault.lockMintingRights(tokenIds[], purpose, expiry)
 *       ↓ auto — WhaleVault calls this contract
 *   onLock(lockId, faceValueETH)
 *       ↓ auto
 *   ETH deployed to DeltaNeutralVault
 *       ↓ auto
 *   ETH → Lido → wstETH → Aave → yield accumulates
 *
 *   STEP 3 — Wayne borrows USDC (Ballet signs once)
 *   EWBMintingRightsVault.borrowUSDC(lockId, tokenIds[], amount)
 *       ↓ auto
 *   Aave releases Circle USDC
 *       ↓ auto
 *   USDC → Ballet wallet 0xc82A...D46cf instantly
 *
 *   STEP 4 — Yield auto-repays debt (no signature needed)
 *   DeltaNeutralVault.harvestToUSDC()
 *       ↓ auto
 *   stETH yield → Uniswap → USDC
 *       ↓ auto
 *   EWBMintingRightsVault.autoRepay() called
 *       ↓ auto
 *   Aave debt paid down
 *       ↓ auto
 *   Borrowing capacity restored
 *
 *   STEP 5 — Cycle resets
 *   Wayne calls borrowUSDC() again when ready
 *   Or unlockMintingRights() to close the cycle
 *
 * ================================================================
 * WHAT WAYNE SIGNS
 * ================================================================
 *
 *   fund()                   — one time — seeds the bridge with ETH
 *   lockMintingRights()      — once per cycle — triggers auto-deploy
 *   borrowUSDC()             — when he wants USDC
 *   unlockMintingRights()    — to close cycle
 *
 * ================================================================
 * WHAT IS FULLY AUTOMATIC (no signature)
 * ================================================================
 *
 *   onLock()                 — ETH deployed when lock triggers
 *   deployLongLeg()          — ETH → wstETH → Aave
 *   harvestToUSDC()          — yield → USDC
 *   autoRepay()              — yield pays Aave debt
 *   borrowing capacity restored automatically
 *
 * ================================================================
 * CONFIRMED ADDRESSES
 * ================================================================
 *
 *   Ballet wallet (owner):  0xc82A59594560A3010F336ebe2e9CC4794DCD46cf
 *   All USDC goes to:       0xc82A59594560A3010F336ebe2e9CC4794DCD46cf
 *
 * ================================================================
 */

import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";

// ── Interfaces ──────────────────────────────────────────────────

interface IEWBWhaleVault {
    function getLockFaceValueETH(uint256 lockId) external view returns (uint256);
    function getLockFaceValueUSD(uint256 lockId) external view returns (uint256);
    function isMintingRightLocked(uint256 tokenId) external view returns (bool);
    function owner() external view returns (address);
}

interface IEWBDeltaNeutralVault {
    function deployLongLeg() external payable;
    function totalDeployed() external view returns (uint256);
    function maxDeployment() external view returns (uint256);
    function emergencyExit() external;
}

// ── Contract ────────────────────────────────────────────────────

contract EWBCreditBridge is ReentrancyGuard, Pausable {

    // ── Constants ───────────────────────────────────────────────

    uint256 public constant PRECISION       = 10_000;
    uint256 public constant MAX_DEPLOYMENT_ETH = 6_391 ether;

    /// @notice Ballet wallet — Wayne Fyffe — sole owner
    address public constant BALLET_WALLET =
        0xc82A59594560A3010F336ebe2e9CC4794DCD46cf;

    // ── State ────────────────────────────────────────────────────

    address public immutable owner;
    address public immutable whaleVault;
    address public immutable deltaVault;

    /// @notice LTV basis points applied to face value ETH for deployment
    /// Default: 3000 = 30%
    uint256 public ltvBps = 3_000;

    /// @notice ETH deployed per lockId
    mapping(uint256 => uint256) public deployedPerLock;

    /// @notice Total ETH currently deployed via this bridge
    uint256 public totalBridgeDeployed;

    // ── Events ───────────────────────────────────────────────────

    event BridgeFunded(uint256 amount);
    event LockDeployed(
        uint256 indexed lockId,
        uint256 faceValueETH,
        uint256 ltvETH,
        uint256 deployedETH
    );
    event LockWithdrawn(uint256 indexed lockId, uint256 withdrawnETH);
    event PartialDeploy(uint256 indexed lockId, uint256 ltvETH, uint256 actualDeployed);
    event EmergencyExit(uint256 amount);

    // ── Modifiers ────────────────────────────────────────────────

    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }

    modifier onlyWhaleVault() {
        require(msg.sender == whaleVault, "Not WhaleVault");
        _;
    }

    // ── Constructor ──────────────────────────────────────────────

    constructor(
        address _whaleVault,
        address _deltaVault
    ) {
        require(_whaleVault != address(0), "Zero whaleVault");
        require(_deltaVault != address(0), "Zero deltaVault");

        owner      = BALLET_WALLET;
        whaleVault = _whaleVault;
        deltaVault = _deltaVault;
    }

    // ── Funding ──────────────────────────────────────────────────

    /**
     * @notice Fund the bridge with ETH ready to deploy
     * @dev Wayne sends ETH here once. Bridge holds it until lock triggers.
     *      When lockMintingRights() is called, this ETH automatically
     *      deploys to DeltaNeutralVault → Lido → wstETH → Aave → yield.
     */
    function fund() external payable onlyOwner {
        require(msg.value > 0, "Zero ETH");
        emit BridgeFunded(msg.value);
    }

    receive() external payable {
        emit BridgeFunded(msg.value);
    }

    // ── Core: Lock triggers automatic deployment ─────────────────

    /**
     * @notice Called automatically by WhaleVault when minting rights locked
     * @dev Wayne never calls this directly. It is triggered by lockMintingRights().
     *      Deploys LTV-equivalent ETH into DeltaNeutralVault automatically.
     *      ETH → Lido → wstETH → Aave → yield → auto-repays USDC debt
     *
     * @param lockId       The lock ID from WhaleVault
     * @param faceValueETH Face value in ETH (18 dec)
     */
    function onLock(uint256 lockId, uint256 faceValueETH)
        external
        onlyWhaleVault
        nonReentrant
        whenNotPaused
    {
        require(faceValueETH > 0, "Zero face value");
        require(deployedPerLock[lockId] == 0, "Lock already deployed");

        // Calculate ETH to deploy = face value × LTV
        uint256 ltvETH = faceValueETH * ltvBps / PRECISION;
        require(ltvETH > 0, "LTV too small");

        // Cap to available bridge balance and vault capacity
        IEWBDeltaNeutralVault dv = IEWBDeltaNeutralVault(deltaVault);
        uint256 remainingCap  = dv.maxDeployment() - dv.totalDeployed();
        uint256 currentBridgeBalance = address(this).balance;

        uint256 toDeploy = ltvETH;
        if (toDeploy > currentBridgeBalance)  toDeploy = currentBridgeBalance;
        if (toDeploy > remainingCap)   toDeploy = remainingCap;

        require(toDeploy > 0, unicode"Nothing to deploy — fund the bridge first");

        if (toDeploy < ltvETH) {
            emit PartialDeploy(lockId, ltvETH, toDeploy);
        }

        // CEI: record state before external call
        deployedPerLock[lockId]  = toDeploy;
        totalBridgeDeployed     += toDeploy;

        // Deploy ETH → DeltaNeutralVault → Lido → wstETH → Aave
        dv.deployLongLeg{value: toDeploy}();

        emit LockDeployed(lockId, faceValueETH, ltvETH, toDeploy);
    }

    /**
     * @notice Called automatically by WhaleVault when minting rights unlocked
     * @dev Records that ETH deployment for this lock is complete.
     *      ETH remains in Aave earning yield until harvestToUSDC() is called.
     *
     * @param lockId The lock ID being released
     */
    function onUnlock(uint256 lockId)
        external
        onlyWhaleVault
        nonReentrant
    {
        uint256 deployed = deployedPerLock[lockId];
        if (deployed == 0) return;

        deployedPerLock[lockId]  = 0;
        totalBridgeDeployed     -= deployed;

        emit LockWithdrawn(lockId, deployed);
    }

    // ── Admin ────────────────────────────────────────────────────

    function setLtvBps(uint256 _ltvBps) external onlyOwner {
        require(_ltvBps <= 5_000, "Max 50% LTV");
        ltvBps = _ltvBps;
    }

    function emergencyWithdraw() external onlyOwner {
        uint256 balance = address(this).balance;
        require(balance > 0, "Nothing to withdraw");
        (bool ok,) = payable(BALLET_WALLET).call{value: balance}("");
        require(ok, "Transfer failed");
        emit EmergencyExit(balance);
    }

    function pause()   external onlyOwner { _pause(); }
    function unpause() external onlyOwner { _unpause(); }

    // ── Views ─────────────────────────────────────────────────────

    function bridgeBalance() external view returns (uint256) {
        return address(this).balance;
    }

    function deployedForLock(uint256 lockId) external view returns (uint256) {
        return deployedPerLock[lockId];
    }

    function vaultStats() external view returns (
        uint256 _balance,
        uint256 _totalDeployed,
        uint256 _ltvBps
    ) {
        _balance       = address(this).balance;
        _totalDeployed = totalBridgeDeployed;
        _ltvBps        = ltvBps;
    }
}

@openzeppelin/contracts/security/Pausable.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract Pausable is Context {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}

@openzeppelin/contracts/security/ReentrancyGuard.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

@openzeppelin/contracts/utils/Context.sol

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "optimizer": {
    "runs": 200,
    "enabled": true
  }
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.