ETH Price: $3,403.96 (-7.90%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

2 Token Transfers found.

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
OrigamiBorrowLendMigrator

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 10000 runs

Other Settings:
default evmVersion
File 1 of 12 : OrigamiBorrowLendMigrator.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (periphery/OrigamiBorrowLendMigrator.sol)

import { IOrigamiFlashLoanReceiver } from "contracts/interfaces/common/flashLoan/IOrigamiFlashLoanReceiver.sol";
import { IOrigamiFlashLoanProvider } from "contracts/interfaces/common/flashLoan/IOrigamiFlashLoanProvider.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IOrigamiBorrowAndLend } from "contracts/interfaces/common/borrowAndLend/IOrigamiBorrowAndLend.sol";
import { OrigamiElevatedAccess } from "contracts/common/access/OrigamiElevatedAccess.sol";
import { CommonEventsAndErrors } from "contracts/libraries/CommonEventsAndErrors.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/**
 * @notice Migrate a borrow and lend position from and old contract to a new
 * contract, using a flashloan
 * 1/ Flashloan debt token - enough to repay the entire debt
 * 2/ repayAndWithdraw(entire_debt, entire_collateral)
 * 3/ supplyAndBorrow(entire_collateral, entire_debt)
 * 4/ repay flashloan
 * 
 * It's the MULTISIG's responsibility to do this within a single multisig transaction:
 *   a/ Deploy the newBorrowLend
 *   b/ newBorrowLend.setPositionOwner(oldBorrowLend.positionOwner())
 *   c/ GRANT access for this migrator to call oldBorrowLend.repayAndWithdraw()
 *   d/ GRANT access for this migrator to call newBorrowLend.supplyAndBorrow()
 *   e/ Call newBorrowLend.execute()
 *   f/ lovTokenManager.setBorrowLend(newBorrowLend);
 *   g/ REVOKE access for this migrator to call oldBorrowLend.repayAndWithdraw()
 *   h/ REVOKE access for this migrator to call newBorrowLend.supplyAndBorrow()
 */
contract OrigamiBorrowLendMigrator is IOrigamiFlashLoanReceiver, OrigamiElevatedAccess {
    using SafeERC20 for IERC20;

    /// @notice The Origami flashLoan provider contract, which may be via Aave/Spark/Balancer/etc
    IOrigamiFlashLoanProvider public immutable flashLoanProvider;

    /// @notice The old Origami borrow lend contract
    IOrigamiBorrowAndLend public immutable oldBorrowLend;

    /// @notice The new Origami borrow lend contract
    IOrigamiBorrowAndLend public immutable newBorrowLend;

    /// @notice The collateral token to migrate
    IERC20 public immutable collateralToken;

    /// @notice The debt token to migrate
    IERC20 public immutable debtToken;

    constructor(
        address _initialOwner,
        address _oldBorrowLend,
        address _newBorrowLend,
        address _flashLoanProvider
    ) OrigamiElevatedAccess(_initialOwner) {
        oldBorrowLend = IOrigamiBorrowAndLend(_oldBorrowLend);
        collateralToken = IERC20(oldBorrowLend.supplyToken());
        debtToken = IERC20(oldBorrowLend.borrowToken());

        newBorrowLend = IOrigamiBorrowAndLend(_newBorrowLend);
        flashLoanProvider = IOrigamiFlashLoanProvider(_flashLoanProvider);
    }

    /**
     * @notice only Elevated Access can execute the migration
     */
    function execute() external onlyElevatedAccess {
        // 1. Get the current debt
        uint256 debtAmount = oldBorrowLend.debtBalance();

        // 2. Flashloan that amount
        // When the payment is received, flashLoanCallback() will be called
        flashLoanProvider.flashLoan(
            debtToken,
            debtAmount,
            bytes("")
        );
    }

    /**
     * @notice Handle receiving the flashloan and do the migration
     * The exact amount of flashloan must be repaid to `flashLoanProvider` 
     * at the end of this function
     */
    function flashLoanCallback(
        IERC20 token,
        uint256 amount,
        uint256 fee,
        bytes calldata /*params*/
    ) external override returns (bool success) {
        if (msg.sender != address(flashLoanProvider)) revert CommonEventsAndErrors.InvalidAccess();
        if (address(token) != address(debtToken)) revert CommonEventsAndErrors.InvalidToken(address(token));
        if (fee > 0) revert CommonEventsAndErrors.InvalidParam();

        // 3. Repay entire debt, withdraw entire collateral and send to the new borrow lend
        debtToken.safeTransfer(address(oldBorrowLend), amount);
        uint256 suppliedCollateral = oldBorrowLend.suppliedBalance();
        (uint256 debtRepaidAmount, uint256 withdrawnAmount) = oldBorrowLend.repayAndWithdraw(
            type(uint256).max, // Use type(uint256).max to ensure it withdraws max shares including any rounding.
            suppliedCollateral, 
            address(newBorrowLend)
        );

        if (debtRepaidAmount != amount) revert CommonEventsAndErrors.InvalidAmount(address(debtToken), debtRepaidAmount);
        if (withdrawnAmount != suppliedCollateral) revert CommonEventsAndErrors.InvalidAmount(address(collateralToken), suppliedCollateral);

        // 4. Supply the collateral to the new borrow lend, and borrow the entire debt amount
        // The debt is sent to the flashLoanProvider for flashloan repayment.
        newBorrowLend.supplyAndBorrow(suppliedCollateral, amount, msg.sender);
        return true;
    }
}

File 2 of 12 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @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.
 */
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].
     */
    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);
}

File 3 of 12 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` 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 amount) external returns (bool);
}

File 4 of 12 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

File 5 of 12 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 6 of 12 : OrigamiElevatedAccess.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (common/access/OrigamiElevatedAccessBase.sol)

import { OrigamiElevatedAccessBase } from "contracts/common/access/OrigamiElevatedAccessBase.sol";

/**
 * @notice Inherit to add Owner roles for DAO elevated access.
 */ 
abstract contract OrigamiElevatedAccess is OrigamiElevatedAccessBase {
    constructor(address initialOwner) {
        _init(initialOwner);
    }
}

File 7 of 12 : OrigamiElevatedAccessBase.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (common/access/OrigamiElevatedAccessBase.sol)

import { IOrigamiElevatedAccess } from "contracts/interfaces/common/access/IOrigamiElevatedAccess.sol";
import { CommonEventsAndErrors } from "contracts/libraries/CommonEventsAndErrors.sol";

/**
 * @notice Inherit to add Owner roles for DAO elevated access.
 */ 
abstract contract OrigamiElevatedAccessBase is IOrigamiElevatedAccess {
    /**
     * @notice The address of the current owner.
     */ 
    address public override owner;

    /**
     * @notice Explicit approval for an address to execute a function.
     * allowedCaller => function selector => true/false
     */
    mapping(address => mapping(bytes4 => bool)) public override explicitFunctionAccess;

    /// @dev Track proposed owner
    address private _proposedNewOwner;

    function _init(address initialOwner) internal {
        if (owner != address(0)) revert CommonEventsAndErrors.InvalidAccess();
        if (initialOwner == address(0)) revert CommonEventsAndErrors.InvalidAddress(address(0));
        owner = initialOwner;
    }

    /**
     * @notice Proposes a new Owner.
     * Can only be called by the current owner
     */
    function proposeNewOwner(address account) external override onlyElevatedAccess {
        if (account == address(0)) revert CommonEventsAndErrors.InvalidAddress(account);
        emit NewOwnerProposed(owner, _proposedNewOwner, account);
        _proposedNewOwner = account;
    }

    /**
     * @notice Caller accepts the role as new Owner.
     * Can only be called by the proposed owner
     */
    function acceptOwner() external override {
        if (msg.sender != _proposedNewOwner) revert CommonEventsAndErrors.InvalidAccess();

        emit NewOwnerAccepted(owner, msg.sender);
        owner = msg.sender;
        delete _proposedNewOwner;
    }

    /**
     * @notice Grant `allowedCaller` the rights to call the function selectors in the access list.
     * @dev fnSelector == bytes4(keccak256("fn(argType1,argType2,...)"))
     */
    function setExplicitAccess(address allowedCaller, ExplicitAccess[] calldata access) external override onlyElevatedAccess {
        if (allowedCaller == address(0)) revert CommonEventsAndErrors.InvalidAddress(allowedCaller);
        ExplicitAccess memory _access;
        for (uint256 i; i < access.length; ++i) {
            _access = access[i];
            emit ExplicitAccessSet(allowedCaller, _access.fnSelector, _access.allowed);
            explicitFunctionAccess[allowedCaller][_access.fnSelector] = _access.allowed;
        }
    }

    function isElevatedAccess(address caller, bytes4 fnSelector) internal view returns (bool) {
        return (
            caller == owner || 
            explicitFunctionAccess[caller][fnSelector]
        );
    }

    /**
     * @notice The owner is allowed to call, or if explicit access has been given to the caller.
     * @dev Important: Only for use when called from an *external* contract. 
     * If a function with this modifier is called internally then the `msg.sig` 
     * will still refer to the top level externally called function.
     */
    modifier onlyElevatedAccess() {
        if (!isElevatedAccess(msg.sender, msg.sig)) revert CommonEventsAndErrors.InvalidAccess();
        _;
    }
}

File 8 of 12 : IOrigamiElevatedAccess.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (interfaces/common/access/IOrigamiElevatedAccess.sol)

/**
 * @notice Inherit to add Owner roles for DAO elevated access.
 */ 
interface IOrigamiElevatedAccess {
    event ExplicitAccessSet(address indexed account, bytes4 indexed fnSelector, bool indexed value);

    event NewOwnerProposed(address indexed oldOwner, address indexed oldProposedOwner, address indexed newProposedOwner);
    event NewOwnerAccepted(address indexed oldOwner, address indexed newOwner);

    struct ExplicitAccess {
        bytes4 fnSelector;
        bool allowed;
    }

    /**
     * @notice The address of the current owner.
     */ 
    function owner() external view returns (address);

    /**
     * @notice Explicit approval for an address to execute a function.
     * allowedCaller => function selector => true/false
     */
    function explicitFunctionAccess(address contractAddr, bytes4 functionSelector) external view returns (bool);

    /**
     * @notice Proposes a new Owner.
     * Can only be called by the current owner
     */
    function proposeNewOwner(address account) external;

    /**
     * @notice Caller accepts the role as new Owner.
     * Can only be called by the proposed owner
     */
    function acceptOwner() external;

    /**
     * @notice Grant `allowedCaller` the rights to call the function selectors in the access list.
     * @dev fnSelector == bytes4(keccak256("fn(argType1,argType2,...)"))
     */
    function setExplicitAccess(address allowedCaller, ExplicitAccess[] calldata access) external;
}

File 9 of 12 : IOrigamiBorrowAndLend.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (interfaces/common/borrowAndLend/IOrigamiBorrowAndLend.sol)

/**
 * @notice An Origami abstraction over a borrow/lend money market for
 * a single `supplyToken` and a single `borrowToken`, for a given `positionOwner`
 */
interface IOrigamiBorrowAndLend {
    event PositionOwnerSet(address indexed account);
    event SurplusDebtReclaimed(uint256 amount, address indexed recipient);

    /**
     * @notice Set the position owner who can borrow/lend via this contract
     */
    function setPositionOwner(address account) external;

    /**
     * @notice Supply tokens as collateral
     */
    function supply(
        uint256 supplyAmount
    ) external;

    /**
     * @notice Withdraw collateral tokens to recipient
     * @dev Set `withdrawAmount` to type(uint256).max in order to withdraw the whole balance
     */
    function withdraw(
        uint256 withdrawAmount, 
        address recipient
    ) external returns (uint256 amountWithdrawn);

    /**
     * @notice Borrow tokens and send to recipient
     */
    function borrow(
        uint256 borrowAmount,
        address recipient
    ) external;

    /**
     * @notice Repay debt. 
     * @dev If `repayAmount` is set higher than the actual outstanding debt balance, it will be capped
     * to that outstanding debt balance
     * `debtRepaidAmount` return parameter will be capped to the outstanding debt balance.
     * Any surplus debtTokens (if debt fully repaid) will remain in this contract
     */
    function repay(
        uint256 repayAmount
    ) external returns (uint256 debtRepaidAmount);

    /**
     * @notice Repay debt and withdraw collateral in one step
     * @dev If `repayAmount` is set higher than the actual outstanding debt balance, it will be capped
     * to that outstanding debt balance
     * Set `withdrawAmount` to type(uint256).max in order to withdraw the whole balance
     * `debtRepaidAmount` return parameter will be capped to the outstanding debt amount.
     * Any surplus debtTokens (if debt fully repaid) will remain in this contract
     */
    function repayAndWithdraw(
        uint256 repayAmount, 
        uint256 withdrawAmount, 
        address recipient
    ) external returns (
        uint256 debtRepaidAmount,
        uint256 withdrawnAmount
    );

    /**
     * @notice Supply collateral and borrow in one step
     */
    function supplyAndBorrow(
        uint256 supplyAmount, 
        uint256 borrowAmount, 
        address recipient
    ) external;

    /**
     * @notice The approved owner of the borrow/lend position
     */
    function positionOwner() external view returns (address);

    /**
     * @notice The token supplied as collateral
     */
    function supplyToken() external view returns (address);

    /**
     * @notice The token which is borrowed
     */
    function borrowToken() external view returns (address);

    /**
     * @notice The current (manually tracked) balance of tokens supplied
     */
    function suppliedBalance() external view returns (uint256);

    /**
     * @notice The current debt balance of tokens borrowed
     */
    function debtBalance() external view returns (uint256);

    /**
     * @notice Whether a given Assets/Liabilities Ratio is safe, given the upstream
     * money market parameters
     */
    function isSafeAlRatio(uint256 alRatio) external view returns (bool);

    /**
     * @notice How many `supplyToken` are available to withdraw from collateral
     * from the entire protocol, assuming this contract has fully paid down its debt
     */
    function availableToWithdraw() external view returns (uint256);

    /**
     * @notice How much more capacity is available to supply
     */
    function availableToSupply() external view returns (
        uint256 supplyCap,
        uint256 available
    );

    /**
     * @notice How many `borrowToken` are available to borrow
     * from the entire protocol
     */
    function availableToBorrow() external view returns (uint256);
}

File 10 of 12 : IOrigamiFlashLoanProvider.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (interfaces/common/flashLoan/IOrigamiFlashLoanProvider.sol)

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

/**
 * @notice An Origami abstraction over FlashLoan providers
 */
interface IOrigamiFlashLoanProvider {
    /**
     * @notice Initiate a flashloan for a single token
     * The caller must implement the `IOrigamiFlashLoanReceiver()` interface.
     * @param token The ERC20 token to borrow
     * @param amount The amount to borrow
     * @param params Client specific abi encoded params which are passed through from the msg.sender 
     *               and into the `flashLoanCallback()` call
     */
    function flashLoan(
        IERC20 token, 
        uint256 amount, 
        bytes memory params
    ) external;
}

File 11 of 12 : IOrigamiFlashLoanReceiver.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (interfaces/common/flashLoan/IOrigamiFlashLoanReceiver.sol)

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

/**
 * @notice Handle Flash Loan callback's originated from a `IOrigamiFlashLoanProvider`
 */
interface IOrigamiFlashLoanReceiver {
    /**
     * @notice Invoked from IOrigamiFlashLoanProvider once a flash loan is successfully
     * received, to the msg.sender of `flashLoan()`
     * @dev Must return false (or revert) if handling within the callback failed.
     * @param token The ERC20 token which has been borrowed
     * @param amount The amount which has been borrowed
     * @param fee The flashloan fee amount (in the same token)
     * @param params Client specific abi encoded params which are passed through from the original `flashLoan()` call
     */
    function flashLoanCallback(
        IERC20 token,
        uint256 amount,
        uint256 fee,
        bytes calldata params
    ) external returns (bool success);
}

File 12 of 12 : CommonEventsAndErrors.sol
pragma solidity 0.8.19;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Origami (libraries/CommonEventsAndErrors.sol)

/// @notice A collection of common events and errors thrown within the Origami contracts
library CommonEventsAndErrors {
    error InsufficientBalance(address token, uint256 required, uint256 balance);
    error InvalidToken(address token);
    error InvalidParam();
    error InvalidAddress(address addr);
    error InvalidAmount(address token, uint256 amount);
    error ExpectedNonZero();
    error Slippage(uint256 minAmountExpected, uint256 actualAmount);
    error IsPaused();
    error UnknownExecuteError(bytes returndata);
    error InvalidAccess();
    error BreachedMaxTotalSupply(uint256 totalSupply, uint256 maxTotalSupply);

    event TokenRecovered(address indexed to, address indexed token, uint256 amount);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 10000
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_initialOwner","type":"address"},{"internalType":"address","name":"_oldBorrowLend","type":"address"},{"internalType":"address","name":"_newBorrowLend","type":"address"},{"internalType":"address","name":"_flashLoanProvider","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidAccess","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"InvalidAddress","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"InvalidAmount","type":"error"},{"inputs":[],"name":"InvalidParam","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"InvalidToken","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"bytes4","name":"fnSelector","type":"bytes4"},{"indexed":true,"internalType":"bool","name":"value","type":"bool"}],"name":"ExplicitAccessSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"NewOwnerAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"oldProposedOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newProposedOwner","type":"address"}],"name":"NewOwnerProposed","type":"event"},{"inputs":[],"name":"acceptOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collateralToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"debtToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes4","name":"","type":"bytes4"}],"name":"explicitFunctionAccess","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"flashLoanCallback","outputs":[{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"flashLoanProvider","outputs":[{"internalType":"contract IOrigamiFlashLoanProvider","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"newBorrowLend","outputs":[{"internalType":"contract IOrigamiBorrowAndLend","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oldBorrowLend","outputs":[{"internalType":"contract IOrigamiBorrowAndLend","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"proposeNewOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"allowedCaller","type":"address"},{"components":[{"internalType":"bytes4","name":"fnSelector","type":"bytes4"},{"internalType":"bool","name":"allowed","type":"bool"}],"internalType":"struct IOrigamiElevatedAccess.ExplicitAccess[]","name":"access","type":"tuple[]"}],"name":"setExplicitAccess","outputs":[],"stateMutability":"nonpayable","type":"function"}]

6101206040523480156200001257600080fd5b5060405162001908380380620019088339810160408190526200003591620001ee565b83620000418162000155565b506001600160a01b03831660a081905260408051632902cbab60e11b815290516352059756916004808201926020929091908290030181865afa1580156200008d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000b391906200024b565b6001600160a01b031660e0816001600160a01b03168152505060a0516001600160a01b031663456dc17a6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200010d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200013391906200024b565b6001600160a01b039081166101005291821660c0521660805250620002709050565b6000546001600160a01b0316156200018057604051633006171960e21b815260040160405180910390fd5b6001600160a01b038116620001af57604051634726455360e11b81526000600482015260240160405180910390fd5b600080546001600160a01b0319166001600160a01b0392909216919091179055565b80516001600160a01b0381168114620001e957600080fd5b919050565b600080600080608085870312156200020557600080fd5b6200021085620001d1565b93506200022060208601620001d1565b92506200023060408601620001d1565b91506200024060608601620001d1565b905092959194509250565b6000602082840312156200025e57600080fd5b6200026982620001d1565b9392505050565b60805160a05160c05160e051610100516115f96200030f6000396000818161024d015281816102e2015281816103d4015281816105fc01526108d30152600081816101dd015261067401526000818160de0152818161051601526106e40152600081816101a3015281816103f60152818161041f0152818161054601526107cc01526000818161015c0152818161028901526108a601526115f96000f3fe608060405234801561001057600080fd5b50600436106100d45760003560e01c8063b1f8100d11610081578063daeccc791161005b578063daeccc7914610212578063ebbc496514610240578063f8d898981461024857600080fd5b8063b1f8100d146101c5578063b2016bd4146101d8578063bfccf0ec146101ff57600080fd5b8063639af6d0116100b2578063639af6d0146101575780638da5cb5b1461017e5780639d16bf4e1461019e57600080fd5b806324c6f1fc146100d957806335cb62af1461012a578063614619541461014d575b600080fd5b6101007f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b61013d6101383660046111c9565b61026f565b6040519015158152602001610121565b610155610764565b005b6101007f000000000000000000000000000000000000000000000000000000000000000081565b6000546101009073ffffffffffffffffffffffffffffffffffffffff1681565b6101007f000000000000000000000000000000000000000000000000000000000000000081565b6101556101d336600461125f565b610932565b6101007f000000000000000000000000000000000000000000000000000000000000000081565b61015561020d36600461127c565b610a8e565b61013d610220366004611339565b600160209081526000928352604080842090915290825290205460ff1681565b610155610ca3565b6101007f000000000000000000000000000000000000000000000000000000000000000081565b60003373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146102e0576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614610382576040517f961c9a4f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff871660048201526024015b60405180910390fd5b83156103ba576040517fd252903400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61041b73ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000087610d71565b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663e4e889546040518163ffffffff1660e01b8152600401602060405180830381865afa158015610488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ac919061136e565b6040517fe5331e910000000000000000000000000000000000000000000000000000000081527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60048201526024810182905273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000008116604483015291925060009182917f00000000000000000000000000000000000000000000000000000000000000009091169063e5331e919060640160408051808303816000875af1158015610590573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b49190611387565b91509150878214610630576040517fb2b3b53b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016600482015260248101839052604401610379565b8281146106a8576040517fb2b3b53b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016600482015260248101849052604401610379565b6040517f62625c3f00000000000000000000000000000000000000000000000000000000815260048101849052602481018990523360448201527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16906362625c3f90606401600060405180830381600087803b15801561073d57600080fd5b505af1158015610751573d6000803e3d6000fd5b5060019c9b505050505050505050505050565b610792336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b6107c8576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663bf1eb64a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610835573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610859919061136e565b604080516020810182526000815290517fe0232b4200000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169163e0232b42916108fd917f0000000000000000000000000000000000000000000000000000000000000000918691600401611419565b600060405180830381600087803b15801561091757600080fd5b505af115801561092b573d6000803e3d6000fd5b5050505050565b610960336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b610996576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff81166109fb576040517f8e4c8aa600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82166004820152602401610379565b6002546000805460405173ffffffffffffffffffffffffffffffffffffffff808616948116939216917f64420d4a41c6ed4de2bccbf33192eea18e576c5b23c79c3a722d4e9534c2e8d891a4600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610abc336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b610af2576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8316610b57576040517f8e4c8aa600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84166004820152602401610379565b604080518082019091526000808252602082015260005b8281101561092b57838382818110610b8857610b88611457565b905060400201803603810190610b9e9190611494565b91508160200151151582600001517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168673ffffffffffffffffffffffffffffffffffffffff167ff5736e75de2c751f775d4c5ed517289f77074f8c337f451ba4c0c3ed1dd7f9ad60405160405180910390a460208281015173ffffffffffffffffffffffffffffffffffffffff8716600090815260018352604080822086517fffffffff000000000000000000000000000000000000000000000000000000001683529093529190912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055610c9c81611518565b9050610b6e565b60025473ffffffffffffffffffffffffffffffffffffffff163314610cf4576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008054604051339273ffffffffffffffffffffffffffffffffffffffff909216917f5cd6b24c0149d980c82592262b3a81294b39f8f6e3c004126aaf0828c787d55491a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000009081163317909155600280549091169055565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610dfe908490610e86565b505050565b6000805473ffffffffffffffffffffffffffffffffffffffff84811691161480610e7f575073ffffffffffffffffffffffffffffffffffffffff831660009081526001602090815260408083207fffffffff000000000000000000000000000000000000000000000000000000008616845290915290205460ff165b9392505050565b6000610ee8826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610f959092919063ffffffff16565b9050805160001480610f09575080806020019051810190610f099190611577565b610dfe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610379565b6060610fa48484600085610fac565b949350505050565b60608247101561103e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610379565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516110679190611594565b60006040518083038185875af1925050503d80600081146110a4576040519150601f19603f3d011682016040523d82523d6000602084013e6110a9565b606091505b50915091506110ba878383876110c5565b979650505050505050565b6060831561115b5782516000036111545773ffffffffffffffffffffffffffffffffffffffff85163b611154576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610379565b5081610fa4565b610fa483838151156111705781518083602001fd5b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037991906115b0565b73ffffffffffffffffffffffffffffffffffffffff811681146111c657600080fd5b50565b6000806000806000608086880312156111e157600080fd5b85356111ec816111a4565b94506020860135935060408601359250606086013567ffffffffffffffff8082111561121757600080fd5b818801915088601f83011261122b57600080fd5b81358181111561123a57600080fd5b89602082850101111561124c57600080fd5b9699959850939650602001949392505050565b60006020828403121561127157600080fd5b8135610e7f816111a4565b60008060006040848603121561129157600080fd5b833561129c816111a4565b9250602084013567ffffffffffffffff808211156112b957600080fd5b818601915086601f8301126112cd57600080fd5b8135818111156112dc57600080fd5b8760208260061b85010111156112f157600080fd5b6020830194508093505050509250925092565b80357fffffffff000000000000000000000000000000000000000000000000000000008116811461133457600080fd5b919050565b6000806040838503121561134c57600080fd5b8235611357816111a4565b915061136560208401611304565b90509250929050565b60006020828403121561138057600080fd5b5051919050565b6000806040838503121561139a57600080fd5b505080516020909101519092909150565b60005b838110156113c65781810151838201526020016113ae565b50506000910152565b600081518084526113e78160208601602086016113ab565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b73ffffffffffffffffffffffffffffffffffffffff8416815282602082015260606040820152600061144e60608301846113cf565b95945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80151581146111c657600080fd5b6000604082840312156114a657600080fd5b6040516040810181811067ffffffffffffffff821117156114f0577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040526114fc83611304565b8152602083013561150c81611486565b60208201529392505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611570577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b60006020828403121561158957600080fd5b8151610e7f81611486565b600082516115a68184602087016113ab565b9190910192915050565b602081526000610e7f60208301846113cf56fea2646970667358221220097c3d6295ec575e370febb228033370ebb3b9f99396df3a6851aef92b468e7b64736f6c63430008130033000000000000000000000000781b4c57100738095222bd92d37b07ed034ab696000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c34000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb1000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106100d45760003560e01c8063b1f8100d11610081578063daeccc791161005b578063daeccc7914610212578063ebbc496514610240578063f8d898981461024857600080fd5b8063b1f8100d146101c5578063b2016bd4146101d8578063bfccf0ec146101ff57600080fd5b8063639af6d0116100b2578063639af6d0146101575780638da5cb5b1461017e5780639d16bf4e1461019e57600080fd5b806324c6f1fc146100d957806335cb62af1461012a578063614619541461014d575b600080fd5b6101007f000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb181565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b61013d6101383660046111c9565b61026f565b6040519015158152602001610121565b610155610764565b005b6101007f000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a81565b6000546101009073ffffffffffffffffffffffffffffffffffffffff1681565b6101007f000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c3481565b6101556101d336600461125f565b610932565b6101007f00000000000000000000000083f20f44975d03b1b09e64809b757c47f942beea81565b61015561020d36600461127c565b610a8e565b61013d610220366004611339565b600160209081526000928352604080842090915290825290205460ff1681565b610155610ca3565b6101007f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4881565b60003373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a16146102e0576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4873ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff1614610382576040517f961c9a4f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff871660048201526024015b60405180910390fd5b83156103ba576040517fd252903400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61041b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48167f000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c3487610d71565b60007f000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c3473ffffffffffffffffffffffffffffffffffffffff1663e4e889546040518163ffffffff1660e01b8152600401602060405180830381865afa158015610488573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104ac919061136e565b6040517fe5331e910000000000000000000000000000000000000000000000000000000081527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60048201526024810182905273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb18116604483015291925060009182917f000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c349091169063e5331e919060640160408051808303816000875af1158015610590573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105b49190611387565b91509150878214610630576040517fb2b3b53b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4816600482015260248101839052604401610379565b8281146106a8576040517fb2b3b53b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000083f20f44975d03b1b09e64809b757c47f942beea16600482015260248101849052604401610379565b6040517f62625c3f00000000000000000000000000000000000000000000000000000000815260048101849052602481018990523360448201527f000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb173ffffffffffffffffffffffffffffffffffffffff16906362625c3f90606401600060405180830381600087803b15801561073d57600080fd5b505af1158015610751573d6000803e3d6000fd5b5060019c9b505050505050505050505050565b610792336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b6107c8576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c3473ffffffffffffffffffffffffffffffffffffffff1663bf1eb64a6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610835573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610859919061136e565b604080516020810182526000815290517fe0232b4200000000000000000000000000000000000000000000000000000000815291925073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a169163e0232b42916108fd917f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48918691600401611419565b600060405180830381600087803b15801561091757600080fd5b505af115801561092b573d6000803e3d6000fd5b5050505050565b610960336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b610996576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff81166109fb576040517f8e4c8aa600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82166004820152602401610379565b6002546000805460405173ffffffffffffffffffffffffffffffffffffffff808616948116939216917f64420d4a41c6ed4de2bccbf33192eea18e576c5b23c79c3a722d4e9534c2e8d891a4600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b610abc336000357fffffffff0000000000000000000000000000000000000000000000000000000016610e03565b610af2576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8316610b57576040517f8e4c8aa600000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84166004820152602401610379565b604080518082019091526000808252602082015260005b8281101561092b57838382818110610b8857610b88611457565b905060400201803603810190610b9e9190611494565b91508160200151151582600001517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19168673ffffffffffffffffffffffffffffffffffffffff167ff5736e75de2c751f775d4c5ed517289f77074f8c337f451ba4c0c3ed1dd7f9ad60405160405180910390a460208281015173ffffffffffffffffffffffffffffffffffffffff8716600090815260018352604080822086517fffffffff000000000000000000000000000000000000000000000000000000001683529093529190912080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016911515919091179055610c9c81611518565b9050610b6e565b60025473ffffffffffffffffffffffffffffffffffffffff163314610cf4576040517fc0185c6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008054604051339273ffffffffffffffffffffffffffffffffffffffff909216917f5cd6b24c0149d980c82592262b3a81294b39f8f6e3c004126aaf0828c787d55491a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000009081163317909155600280549091169055565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610dfe908490610e86565b505050565b6000805473ffffffffffffffffffffffffffffffffffffffff84811691161480610e7f575073ffffffffffffffffffffffffffffffffffffffff831660009081526001602090815260408083207fffffffff000000000000000000000000000000000000000000000000000000008616845290915290205460ff165b9392505050565b6000610ee8826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16610f959092919063ffffffff16565b9050805160001480610f09575080806020019051810190610f099190611577565b610dfe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610379565b6060610fa48484600085610fac565b949350505050565b60608247101561103e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610379565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516110679190611594565b60006040518083038185875af1925050503d80600081146110a4576040519150601f19603f3d011682016040523d82523d6000602084013e6110a9565b606091505b50915091506110ba878383876110c5565b979650505050505050565b6060831561115b5782516000036111545773ffffffffffffffffffffffffffffffffffffffff85163b611154576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610379565b5081610fa4565b610fa483838151156111705781518083602001fd5b806040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161037991906115b0565b73ffffffffffffffffffffffffffffffffffffffff811681146111c657600080fd5b50565b6000806000806000608086880312156111e157600080fd5b85356111ec816111a4565b94506020860135935060408601359250606086013567ffffffffffffffff8082111561121757600080fd5b818801915088601f83011261122b57600080fd5b81358181111561123a57600080fd5b89602082850101111561124c57600080fd5b9699959850939650602001949392505050565b60006020828403121561127157600080fd5b8135610e7f816111a4565b60008060006040848603121561129157600080fd5b833561129c816111a4565b9250602084013567ffffffffffffffff808211156112b957600080fd5b818601915086601f8301126112cd57600080fd5b8135818111156112dc57600080fd5b8760208260061b85010111156112f157600080fd5b6020830194508093505050509250925092565b80357fffffffff000000000000000000000000000000000000000000000000000000008116811461133457600080fd5b919050565b6000806040838503121561134c57600080fd5b8235611357816111a4565b915061136560208401611304565b90509250929050565b60006020828403121561138057600080fd5b5051919050565b6000806040838503121561139a57600080fd5b505080516020909101519092909150565b60005b838110156113c65781810151838201526020016113ae565b50506000910152565b600081518084526113e78160208601602086016113ab565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b73ffffffffffffffffffffffffffffffffffffffff8416815282602082015260606040820152600061144e60608301846113cf565b95945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80151581146111c657600080fd5b6000604082840312156114a657600080fd5b6040516040810181811067ffffffffffffffff821117156114f0577f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040526114fc83611304565b8152602083013561150c81611486565b60208201529392505050565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203611570577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b60006020828403121561158957600080fd5b8151610e7f81611486565b600082516115a68184602087016113ab565b9190910192915050565b602081526000610e7f60208301846113cf56fea2646970667358221220097c3d6295ec575e370febb228033370ebb3b9f99396df3a6851aef92b468e7b64736f6c63430008130033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000781b4c57100738095222bd92d37b07ed034ab696000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c34000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb1000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a

-----Decoded View---------------
Arg [0] : _initialOwner (address): 0x781B4c57100738095222bd92D37B07ed034AB696
Arg [1] : _oldBorrowLend (address): 0xDF3D394669Fe433713D170c6DE85f02E260c1c34
Arg [2] : _newBorrowLend (address): 0x415A37462350C7B428D3310629f8B5520e18dDB1
Arg [3] : _flashLoanProvider (address): 0xC8eE801b35a82743BA7F314623962a2bBfdbC90A

-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 000000000000000000000000781b4c57100738095222bd92d37b07ed034ab696
Arg [1] : 000000000000000000000000df3d394669fe433713d170c6de85f02e260c1c34
Arg [2] : 000000000000000000000000415a37462350c7b428d3310629f8b5520e18ddb1
Arg [3] : 000000000000000000000000c8ee801b35a82743ba7f314623962a2bbfdbc90a


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
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.