Source Code
Overview
ETH Balance
0 ETH
More Info
ContractCreator
Multichain Info
N/A
Loading...
Loading
Contract Name:
OsTokenFlashLoans
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 200 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.22; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {ReentrancyGuard} from '@openzeppelin/contracts/utils/ReentrancyGuard.sol'; import {IOsTokenFlashLoans} from '../interfaces/IOsTokenFlashLoans.sol'; import {IOsTokenFlashLoanRecipient} from '../interfaces/IOsTokenFlashLoanRecipient.sol'; import {IOsToken} from '../interfaces/IOsToken.sol'; import {Errors} from '../libraries/Errors.sol'; /** * @title OsTokenFlashLoans * @author StakeWise * @notice Mint and burn up to 100 000 osToken shares in single transaction. */ contract OsTokenFlashLoans is ReentrancyGuard, IOsTokenFlashLoans { uint256 private constant _maxFlashLoanAmount = 100_000 ether; address private immutable _osToken; /** * @dev Constructor * @param osToken The address of the OsToken contract */ constructor(address osToken) ReentrancyGuard() { _osToken = osToken; } /// @inheritdoc IOsTokenFlashLoans function flashLoan(uint256 osTokenShares, bytes memory userData) external override nonReentrant { // check if not more than max flash loan amount requested if (osTokenShares == 0 || osTokenShares > _maxFlashLoanAmount) { revert Errors.InvalidShares(); } // get current balance uint256 preLoanBalance = IERC20(_osToken).balanceOf(address(this)); // mint OsToken shares for the caller IOsToken(_osToken).mint(msg.sender, osTokenShares); // execute callback IOsTokenFlashLoanRecipient(msg.sender).receiveFlashLoan(osTokenShares, userData); // get post loan balance uint256 postLoanBalance = IERC20(_osToken).balanceOf(address(this)); // check if the amount was repaid if (postLoanBalance < preLoanBalance + osTokenShares) { revert Errors.FlashLoanFailed(); } // burn OsToken shares IOsToken(address(_osToken)).burn(address(this), osTokenShares); // emit event emit OsTokenFlashLoan(msg.sender, osTokenShares); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.20; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ 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); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol) pragma solidity ^0.8.20; /** * @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; /** * @dev Unauthorized reentrant call. */ error ReentrancyGuardReentrantCall(); 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 if (_status == ENTERED) { revert ReentrancyGuardReentrantCall(); } // 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; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.22; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import {IERC20Permit} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol'; import {IERC20Metadata} from '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol'; import {IERC5267} from '@openzeppelin/contracts/interfaces/IERC5267.sol'; /** * @title IOsToken * @author StakeWise * @notice Defines the interface for the OsToken contract */ interface IOsToken is IERC20, IERC20Metadata, IERC20Permit, IERC5267 { /** * @notice Emitted when a controller is updated * @param controller The address of the controller * @param registered Whether the controller is registered or not */ event ControllerUpdated(address indexed controller, bool registered); /** * @notice Returns whether controller is registered or not * @param controller The address of the controller * @return Whether the controller is registered or not */ function controllers(address controller) external view returns (bool); /** * @notice Mint OsToken. Can only be called by the controller. * @param account The address of the account to mint OsToken for * @param value The amount of OsToken to mint */ function mint(address account, uint256 value) external; /** * @notice Burn OsToken. Can only be called by the controller. * @param account The address of the account to burn OsToken for * @param value The amount of OsToken to burn */ function burn(address account, uint256 value) external; /** * @notice Enable or disable the controller. Can only be called by the contract owner. * @param controller The address of the controller * @param registered Whether the controller is registered or not */ function setController(address controller, bool registered) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.22; /** * @title IOsTokenFlashLoanRecipient * @author StakeWise * @notice Interface for OsTokenFlashLoanRecipient contract */ interface IOsTokenFlashLoanRecipient { /** * @notice Receive flash loan hook * @param osTokenShares The osToken flash loan amount * @param userData Arbitrary data passed to the hook */ function receiveFlashLoan(uint256 osTokenShares, bytes memory userData) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.22; /** * @title IOsTokenFlashLoans * @author StakeWise * @notice Interface for OsTokenFlashLoans contract */ interface IOsTokenFlashLoans { /** * @notice Event emitted on flash loan * @param caller The address of the caller * @param amount The flashLoan osToken shares amount */ event OsTokenFlashLoan(address indexed caller, uint256 amount); /** * @notice Flash loan OsToken shares * @param osTokenShares The flashLoan osToken shares amount * @param userData Arbitrary data passed to the `IOsTokenFlashLoanRecipient.receiveFlashLoan` function */ function flashLoan(uint256 osTokenShares, bytes memory userData) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.22; /** * @title Errors * @author StakeWise * @notice Contains all the custom errors */ library Errors { error AccessDenied(); error InvalidShares(); error InvalidAssets(); error ZeroAddress(); error InsufficientAssets(); error CapacityExceeded(); error InvalidCapacity(); error InvalidSecurityDeposit(); error InvalidFeeRecipient(); error InvalidFeePercent(); error NotHarvested(); error NotCollateralized(); error InvalidProof(); error LowLtv(); error InvalidPosition(); error InvalidHealthFactor(); error InvalidReceivedAssets(); error InvalidTokenMeta(); error UpgradeFailed(); error InvalidValidators(); error DeadlineExpired(); error PermitInvalidSigner(); error InvalidValidatorsRegistryRoot(); error InvalidVault(); error AlreadyAdded(); error AlreadyRemoved(); error InvalidOracles(); error NotEnoughSignatures(); error InvalidOracle(); error TooEarlyUpdate(); error InvalidAvgRewardPerSecond(); error InvalidRewardsRoot(); error HarvestFailed(); error LiquidationDisabled(); error InvalidLiqThresholdPercent(); error InvalidLiqBonusPercent(); error InvalidLtvPercent(); error InvalidCheckpointIndex(); error InvalidCheckpointValue(); error MaxOraclesExceeded(); error ExitRequestNotProcessed(); error ValueNotChanged(); error InvalidWithdrawalCredentials(); error EigenPodNotFound(); error InvalidQueuedShares(); error FlashLoanFailed(); }
{ "viaIR": true, "optimizer": { "enabled": true, "runs": 200, "details": { "yul": true } }, "evmVersion": "shanghai", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
[{"inputs":[{"internalType":"address","name":"osToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FlashLoanFailed","type":"error"},{"inputs":[],"name":"InvalidShares","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"OsTokenFlashLoan","type":"event"},{"inputs":[{"internalType":"uint256","name":"osTokenShares","type":"uint256"},{"internalType":"bytes","name":"userData","type":"bytes"}],"name":"flashLoan","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a03461006d57601f6104af38819003918201601f19168301916001600160401b038311848410176100715780849260209460405283398101031261006d57516001600160a01b038116810361006d5760015f55608052604051610429908161008682396080518160cc0152f35b5f80fd5b634e487b7160e01b5f52604160045260245ffdfe6080604081815260049081361015610015575f80fd5b5f925f3560e01c635296a4311461002a575f80fd5b346102bb57816003193601126102bb57823592602480359267ffffffffffffffff938481116102bb57366023820112156102bb578084013594851161039757602094601f1991610081601f830184168801856103d1565b818452368583830101116102bb57815f9286899301838701378401015260025f54146103875760025f5586158015610374575b6103645785516370a0823160e01b80825230868301527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316949193909287858481895afa94851561035a575f9561032b575b50853b156102bb5788516340c10f1960e01b815233888201908152602081018c90525f90829081906040010381838b5af180156103215761030e575b50333b1561030a57908a91895191639ab02a0f60e01b83528b898401528a858401528051908160448501528a855b8381106102f2575050506064838593601f8486858597860101520116810103018183335af180156102e8576102d0575b50508651918252308583015285828281875afa9182156102c6578992610293575b5087830180931161028257501061027357908186923b1561026f578451632770a7eb60e21b81523092810192835260208301879052918391839182908490829060400103925af180156102655761024d575b50507f608dcb82e0689bc8041b8d5bf74059e6326293e4f890c730002ec03448b93ccf91519283523392a26001815580f35b610256906103a9565b61026157835f61021b565b8380fd5b84513d84823e3d90fd5b8280fd5b5082516349088f5960e11b8152fd5b634e487b7160e01b89526011855288fd5b9091508581813d83116102bf575b6102ab81836103d1565b810103126102bb5751905f6101c9565b5f80fd5b503d6102a1565b87513d8b823e3d90fd5b6102d9906103a9565b6102e457885f6101a8565b8880fd5b89513d84823e3d90fd5b828101820151868201606401528f96508c9101610178565b8a80fd5b610319919b506103a9565b5f995f61014a565b8a513d5f823e3d90fd5b9094508781813d8311610353575b61034381836103d1565b810103126102bb5751935f61010e565b503d610339565b89513d5f823e3d90fd5b8551636edcc52360e01b81528490fd5b5069152d02c7e14af680000087116100b4565b8551633ee5aeb560e01b81528490fd5b82604185634e487b7160e01b5f52525ffd5b67ffffffffffffffff81116103bd57604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff8211176103bd5760405256fea2646970667358221220969f8d79c0665c13ef9734d7141917134abff3c8347b03f69454e5f0178eefce64736f6c63430008160033000000000000000000000000f603c5a3f774f05d4d848a9bb139809790890864
Deployed Bytecode
0x6080604081815260049081361015610015575f80fd5b5f925f3560e01c635296a4311461002a575f80fd5b346102bb57816003193601126102bb57823592602480359267ffffffffffffffff938481116102bb57366023820112156102bb578084013594851161039757602094601f1991610081601f830184168801856103d1565b818452368583830101116102bb57815f9286899301838701378401015260025f54146103875760025f5586158015610374575b6103645785516370a0823160e01b80825230868301527f000000000000000000000000f603c5a3f774f05d4d848a9bb1398097908908646001600160a01b0316949193909287858481895afa94851561035a575f9561032b575b50853b156102bb5788516340c10f1960e01b815233888201908152602081018c90525f90829081906040010381838b5af180156103215761030e575b50333b1561030a57908a91895191639ab02a0f60e01b83528b898401528a858401528051908160448501528a855b8381106102f2575050506064838593601f8486858597860101520116810103018183335af180156102e8576102d0575b50508651918252308583015285828281875afa9182156102c6578992610293575b5087830180931161028257501061027357908186923b1561026f578451632770a7eb60e21b81523092810192835260208301879052918391839182908490829060400103925af180156102655761024d575b50507f608dcb82e0689bc8041b8d5bf74059e6326293e4f890c730002ec03448b93ccf91519283523392a26001815580f35b610256906103a9565b61026157835f61021b565b8380fd5b84513d84823e3d90fd5b8280fd5b5082516349088f5960e11b8152fd5b634e487b7160e01b89526011855288fd5b9091508581813d83116102bf575b6102ab81836103d1565b810103126102bb5751905f6101c9565b5f80fd5b503d6102a1565b87513d8b823e3d90fd5b6102d9906103a9565b6102e457885f6101a8565b8880fd5b89513d84823e3d90fd5b828101820151868201606401528f96508c9101610178565b8a80fd5b610319919b506103a9565b5f995f61014a565b8a513d5f823e3d90fd5b9094508781813d8311610353575b61034381836103d1565b810103126102bb5751935f61010e565b503d610339565b89513d5f823e3d90fd5b8551636edcc52360e01b81528490fd5b5069152d02c7e14af680000087116100b4565b8551633ee5aeb560e01b81528490fd5b82604185634e487b7160e01b5f52525ffd5b67ffffffffffffffff81116103bd57604052565b634e487b7160e01b5f52604160045260245ffd5b90601f8019910116810190811067ffffffffffffffff8211176103bd5760405256fea2646970667358221220969f8d79c0665c13ef9734d7141917134abff3c8347b03f69454e5f0178eefce64736f6c63430008160033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000f603c5a3f774f05d4d848a9bb139809790890864
-----Decoded View---------------
Arg [0] : osToken (address): 0xF603c5A3F774F05d4D848A9bB139809790890864
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000f603c5a3f774f05d4d848a9bb139809790890864
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.