Skip to content
Verified contractExactMIT

LeverageLongHelper

Address0xa8b4d0cf27639a514b8402679e3499c788846a0c
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
Yes, 200 runs
EVM version
cancun
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,074,003
Creation transaction
0x2839a24ee2…72979a6831

src/LeverageLongHelper.sol

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

/*//////////////////////////////////////////////////////////////
                              hooky
                    web · https://hookylend.xyz
                    x   · https://x.com/hookylend
                    tg  · https://t.me/hookylend
//////////////////////////////////////////////////////////////*/

interface IHookyLendingHook {
    function LTV_BPS() external view returns (uint256);
    function borrowFor(uint256 collateralHOOKY, address borrower, address ethRecipient)
        external
        returns (uint256 boundBand, uint256 debtETH);
    function quoteBorrow(uint256 collateralHOOKY)
        external
        view
        returns (uint256 boundBand, uint256 debtETH, uint256 netToUser, bool feasible);
}

interface IHookySwapHelper {
    function buy(uint256 minHookyOut, uint256 deadline) external payable returns (uint256 hookyOut);
}

interface IERC20Transfer {
    function transfer(address to, uint256 amount) external returns (bool);
}

/// @notice One-transaction HOOKY long helper. User approves the lending hook for
///         HOOKY collateral, then this helper opens the borrow under the user's
///         address and swaps the borrowed ETH into extra HOOKY for the user.
contract LeverageLongHelper {
    uint256 public constant BPS = 10_000;
    uint256 public constant MAX_LEVERAGE_BPS = 30_000; // x3 hard cap

    IHookyLendingHook public immutable lendingHook;
    IHookySwapHelper public immutable swapHelper;
    IERC20Transfer public immutable hooky;

    error ZeroAddress();
    error ZeroAmount();
    error DeadlineExpired();
    error BorrowUnavailable();
    error LeverageTooHigh();
    error HookyTransferFailed();
    error Reentrancy();

    event LongOpened(
        address indexed user,
        uint256 indexed boundBand,
        uint256 collateralHOOKY,
        uint256 debtETH,
        uint256 ethSwapped,
        uint256 hookyOut,
        uint256 projectedLeverageBps
    );

    uint256 private _locked = 1;
    modifier nonReentrant() {
        if (_locked != 1) revert Reentrancy();
        _locked = 2;
        _;
        _locked = 1;
    }

    constructor(address lendingHook_, address swapHelper_, address hooky_) {
        if (lendingHook_ == address(0) || swapHelper_ == address(0) || hooky_ == address(0)) {
            revert ZeroAddress();
        }
        lendingHook = IHookyLendingHook(lendingHook_);
        swapHelper = IHookySwapHelper(swapHelper_);
        hooky = IERC20Transfer(hooky_);
    }

    function openLong(uint256 collateralHOOKY, uint256 minHookyOut, uint256 deadline)
        external
        nonReentrant
        returns (uint256 boundBand, uint256 debtETH, uint256 hookyOut)
    {
        if (collateralHOOKY == 0) revert ZeroAmount();
        if (block.timestamp > deadline) revert DeadlineExpired();

        (, uint256 quotedDebt, uint256 quotedNet, bool feasible) = lendingHook.quoteBorrow(collateralHOOKY);
        if (!feasible || quotedDebt == 0 || quotedNet == 0) revert BorrowUnavailable();

        uint256 ltvBps = lendingHook.LTV_BPS();
        uint256 collateralValue = quotedDebt * BPS / ltvBps;
        uint256 projectedLeverageBps = ((collateralValue + quotedNet) * BPS) / collateralValue;
        if (projectedLeverageBps > MAX_LEVERAGE_BPS) revert LeverageTooHigh();

        uint256 ethBefore = address(this).balance;
        (boundBand, debtETH) = lendingHook.borrowFor(collateralHOOKY, msg.sender, address(this));
        uint256 ethToSwap = address(this).balance - ethBefore;
        if (ethToSwap == 0) revert BorrowUnavailable();

        hookyOut = swapHelper.buy{value: ethToSwap}(minHookyOut, deadline);
        if (!hooky.transfer(msg.sender, hookyOut)) revert HookyTransferFailed();

        emit LongOpened(msg.sender, boundBand, collateralHOOKY, debtETH, ethToSwap, hookyOut, projectedLeverageBps);
    }

    receive() external payable {}
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
    "@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/",
    "ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-gas-snapshot/",
    "forge-std/=node_modules/@uniswap/v4-core/lib/forge-std/",
    "openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "permit2/=node_modules/@uniswap/v4-periphery/lib/permit2/",
    "solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
    "v4-core/=node_modules/@uniswap/v4-periphery/lib/v4-core/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.