Skip to content
Verified contractPartialMIT

LeverageDraws

Address0xebdb209fe2124c4a304d24022e8c78bdb1e77861
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
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,478,350
Creation transaction
0xed614d930b…75ee0ef5a4

src/LeverageDraws.sol

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

interface IVRFCoordinatorV2Plus {
    struct RandomWordsRequest {
        bytes32 keyHash;
        uint256 subId;
        uint16 requestConfirmations;
        uint32 callbackGasLimit;
        uint32 numWords;
        bytes extraArgs;
    }

    function requestRandomWords(RandomWordsRequest calldata req) external returns (uint256 requestId);
}

interface IFactoryVaults {
    function isVault(address) external view returns (bool);
}

interface IVaultSeed {
    function onSeed(uint256 index, uint256 word) external;
}

/// @title LeverageDraws
/// @notice Single Chainlink VRF v2.5 consumer shared by every vault, so the subscription only
///         needs one consumer. Vaults request a word per purchase; the word is forwarded back.
contract LeverageDraws {
    bytes4 internal constant EXTRA_ARGS_V1_TAG = 0x92fd1338; // bytes4(keccak256("VRF ExtraArgsV1"))

    address public immutable coordinator;
    IFactoryVaults public immutable factory;
    address public owner;

    bytes32 public keyHash;
    uint256 public subId;
    uint32 public callbackGasLimit = 150_000;
    uint16 public confirmations = 3;
    bool public nativePayment;

    struct Req {
        address vault;
        uint256 index;
    }

    mapping(uint256 => Req) public requests;

    event Config(bytes32 keyHash, uint256 subId, uint32 gas, uint16 confs, bool native);
    event Requested(uint256 indexed requestId, address indexed vault, uint256 index);
    event Fulfilled(uint256 indexed requestId, address indexed vault, uint256 index, uint256 word);
    event OwnerSet(address owner);

    error NotOwner();
    error NotVault();
    error NotCoordinator();
    error NotConfigured();

    constructor(address _coordinator, address _factory, address _owner) {
        coordinator = _coordinator;
        factory = IFactoryVaults(_factory);
        owner = _owner;
    }

    function setConfig(bytes32 _keyHash, uint256 _subId, uint32 _gas, uint16 _confs, bool _native) external {
        if (msg.sender != owner) revert NotOwner();
        keyHash = _keyHash;
        subId = _subId;
        callbackGasLimit = _gas;
        confirmations = _confs;
        nativePayment = _native;
        emit Config(_keyHash, _subId, _gas, _confs, _native);
    }

    function setOwner(address o) external {
        if (msg.sender != owner) revert NotOwner();
        owner = o;
        emit OwnerSet(o);
    }

    function request(uint256 index) external returns (uint256 requestId) {
        if (!factory.isVault(msg.sender)) revert NotVault();
        if (subId == 0) revert NotConfigured();
        requestId = IVRFCoordinatorV2Plus(coordinator).requestRandomWords(
            IVRFCoordinatorV2Plus.RandomWordsRequest({
                keyHash: keyHash,
                subId: subId,
                requestConfirmations: confirmations,
                callbackGasLimit: callbackGasLimit,
                numWords: 1,
                extraArgs: abi.encodeWithSelector(EXTRA_ARGS_V1_TAG, nativePayment)
            })
        );
        requests[requestId] = Req(msg.sender, index);
        emit Requested(requestId, msg.sender, index);
    }

    /// @notice Chainlink VRF v2.5 callback entrypoint.
    function rawFulfillRandomWords(uint256 requestId, uint256[] calldata words) external {
        if (msg.sender != coordinator) revert NotCoordinator();
        Req memory r = requests[requestId];
        if (r.vault == address(0)) return;
        delete requests[requestId];
        IVaultSeed(r.vault).onSeed(r.index, words[0]);
        emit Fulfilled(requestId, r.vault, r.index, words[0]);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "cancun",
  "remappings": [
    "@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
    "@uniswap/v4-periphery/=lib/v4-periphery/",
    "v4-core/=lib/v4-periphery/lib/v4-core/src/",
    "v4-periphery/=lib/v4-periphery/src/",
    "solady/=lib/solady/src/",
    "permit2/=lib/permit2/",
    "forge-std/=lib/forge-std/src/",
    "@ensdomains/=lib/v4-periphery/lib/v4-core/node_modules/@ensdomains/",
    "@openzeppelin/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "ds-test/=lib/permit2/lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/permit2/lib/forge-gas-snapshot/src/",
    "hardhat/=lib/v4-periphery/lib/v4-core/node_modules/hardhat/",
    "openzeppelin-contracts/=lib/permit2/lib/openzeppelin-contracts/",
    "solmate/=lib/permit2/lib/solmate/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.