Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Latest 5 internal transactions
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| Deposit | 17822944 | 943 days ago | 0.1 ETH | ||||
| Deposit | 17822108 | 943 days ago | 0.45 ETH | ||||
| Deposit | 17820034 | 943 days ago | 0.01 ETH | ||||
| 0x60a06040 | 17811970 | 944 days ago | Contract Creation | 0 ETH | |||
| 0x60a06040 | 17811970 | 944 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
ConnextRouter
Compiler Version
v0.8.15+commit.e14f2714
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title ConnextRouter
*
* @author Fujidao Labs
*
* @notice A Router implementing Connext specific bridging logic.
*/
import {IERC20, SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IConnext, IXReceiver} from "../interfaces/connext/IConnext.sol";
import {ConnextReceiver} from "./ConnextReceiver.sol";
import {ConnextHandler} from "./ConnextHandler.sol";
import {BaseRouter} from "../abstracts/BaseRouter.sol";
import {IWETH9} from "../abstracts/WETH9.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IVaultPermissions} from "../interfaces/IVaultPermissions.sol";
import {IChief} from "../interfaces/IChief.sol";
import {IRouter} from "../interfaces/IRouter.sol";
import {IFlasher} from "../interfaces/IFlasher.sol";
import {LibBytes} from "../libraries/LibBytes.sol";
contract ConnextRouter is BaseRouter, IXReceiver {
using SafeERC20 for IERC20;
/**
* @dev Emitted when a new destination ConnextReceiver gets added.
*
* @param router ConnextReceiver on another chain
* @param domain the destination domain identifier according Connext nomenclature
*/
event NewConnextReceiver(address indexed router, uint256 indexed domain);
/**
* @dev Emitted when Connext `xCall` is invoked.
*
* @param transferId the unique identifier of the crosschain transfer
* @param caller the account that called the function
* @param receiver the router on destDomain
* @param destDomain the destination domain identifier according Connext nomenclature
* @param asset the asset being transferred
* @param amount the amount of transferring asset the recipient address receives
* @param callData the calldata sent to destination router that will get decoded and executed
*/
event XCalled(
bytes32 indexed transferId,
address indexed caller,
address indexed receiver,
uint256 destDomain,
address asset,
uint256 amount,
bytes callData
);
/**
* @dev Emitted when the router receives a cross-chain call.
*
* @param transferId the unique identifier of the crosschain transfer
* @param originDomain the origin domain identifier according Connext nomenclature
* @param success whether or not the xBundle call succeeds
* @param asset the asset being transferred
* @param amount the amount of transferring asset the recipient address receives
* @param callData the calldata that will get decoded and executed
*/
event XReceived(
bytes32 indexed transferId,
uint256 indexed originDomain,
bool success,
address asset,
uint256 amount,
bytes callData
);
/// @dev Custom Errors
error ConnextRouter__setRouter_invalidInput();
error ConnextRouter__xReceive_notAllowedCaller();
error ConnextRouter__xReceiver_noValueTransferUseXbundle();
error ConnnextRouter__xBundleConnext_notSelfCalled();
error ConnextRouter__crossTransfer_checkReceiver();
/// @dev The connext contract on the origin domain.
IConnext public immutable connext;
ConnextHandler public immutable handler;
address public immutable connextReceiver;
/**
* @notice A mapping of a domain of another chain and a deployed ConnextReceiver there.
*
* @dev For the list of domains supported by Connext,
* plz check: https://docs.connext.network/resources/deployments
*/
mapping(uint256 => address) public receiverByDomain;
modifier onlySelf() {
if (msg.sender != address(this)) {
revert ConnnextRouter__xBundleConnext_notSelfCalled();
}
_;
}
modifier onlyConnextReceiver() {
if (msg.sender != connextReceiver) {
revert ConnextRouter__xReceive_notAllowedCaller();
}
_;
}
constructor(IWETH9 weth, IConnext connext_, IChief chief) BaseRouter(weth, chief) {
connext = connext_;
connextReceiver = address(new ConnextReceiver(address(this)));
handler = new ConnextHandler(address(this));
_allowCaller(msg.sender, true);
}
/*////////////////////////////////////
Connext specific functions
////////////////////////////////////*/
/**
* @notice Called by Connext on the destination chain.
*
* @param transferId the unique identifier of the crosschain transfer
* @param amount the amount of transferring asset, after slippage, the recipient address receives
* @param asset the asset being transferred
* @param originSender the address of the contract or EOA that called xcall on the origin chain
* @param originDomain the origin domain identifier according Connext nomenclature
* @param callData the calldata that will get decoded and executed, see "Requirements"
*
* @dev It does not perform authentication of the calling address. As a result of that,
* all txns go through Connext's fast path.
* If `xBundle` fails internally, this contract will send the received funds to {ConnextHandler}.
*
* Requirements:
* - `calldata` parameter must be encoded with the following structure:
* > abi.encode(Action[] actions, bytes[] args)
* - actions: array of serialized actions to execute from available enum {IRouter.Action}.
* - args: array of encoded arguments according to each action. See {BaseRouter-internalBundle}.
*/
function xReceive(
bytes32 transferId,
uint256 amount,
address asset,
address originSender,
uint32 originDomain,
bytes memory callData
)
external
onlyConnextReceiver
returns (bytes memory)
{
(Action[] memory actions, bytes[] memory args) = abi.decode(callData, (Action[], bytes[]));
Snapshot memory tokenToCheck_ = Snapshot(asset, IERC20(asset).balanceOf(address(this)));
IERC20(asset).safeTransferFrom(connextReceiver, address(this), amount);
/**
* @dev Due to the AMM nature of Connext, there could be some slippage
* incurred on the amount that this contract receives after bridging.
* There is also a routing fee of 0.05% of the bridged amount.
* The slippage can't be calculated upfront so that's why we need to
* replace `amount` in the encoded args for the first action if
* the action is Deposit, or Payback.
*/
uint256 beforeSlipped;
(args[0], beforeSlipped) = _accountForSlippage(amount, actions[0], args[0]);
/**
* @dev Connext will keep the custody of the bridged amount if the call
* to `xReceive` fails. That's why we need to ensure the funds are not stuck at Connext.
* Therefore we try/catch instead of directly calling _bundleInternal(...).
*/
try this.xBundleConnext(actions, args, beforeSlipped, tokenToCheck_) {
emit XReceived(transferId, originDomain, true, asset, amount, callData);
} catch {
IERC20(asset).safeTransfer(address(handler), amount);
handler.recordFailed(transferId, amount, asset, originSender, originDomain, actions, args);
emit XReceived(transferId, originDomain, false, asset, amount, callData);
}
return "";
}
/**
* @notice Function selector created to allow try-catch procedure in Connext message data
* passing.Including argument for `beforeSlipepd` not available in {BaseRouter-xBundle}.
*
* @param actions an array of actions that will be executed in a row
* @param args an array of encoded inputs needed to execute each action
* @param beforeSlipped amount passed by the origin cross-chain router operation
* @param tokenToCheck_ snapshot after xReceive from Connext
*
* @dev Requirements:
* - Must only be called within the context of this same contract.
*/
function xBundleConnext(
Action[] calldata actions,
bytes[] calldata args,
uint256 beforeSlipped,
Snapshot memory tokenToCheck_
)
external
payable
onlySelf
{
_bundleInternal(actions, args, beforeSlipped, tokenToCheck_);
}
/**
* @dev Decodes and replaces "amount" argument in args with `receivedAmount`
* in Deposit, or Payback.
*
* Refer to:
* https://github.com/Fujicracy/fuji-v2/issues/253#issuecomment-1385995095
*/
function _accountForSlippage(
uint256 receivedAmount,
Action action,
bytes memory args
)
private
pure
returns (bytes memory newArgs, uint256 beforeSlipped)
{
uint256 prevAmount;
(newArgs, prevAmount) = _replaceAmountArgInAction(action, args, receivedAmount);
if (prevAmount != receivedAmount) {
beforeSlipped = prevAmount;
}
}
/**
* @dev NOTE to integrators
* The `beneficiary_`, of a `_crossTransfer(...)` must meet these requirement:
* - Must be an externally owned account (EOA) or
* - Must be a contract that implements or is capable of calling:
* - connext.forceUpdateSlippage(TransferInfo, _slippage) add the destination chain.
* Refer to 'delegate' argument:
* https://docs.connext.network/developers/guides/handling-failures#increasing-slippage-tolerance
*/
/// @inheritdoc BaseRouter
function _crossTransfer(
bytes memory params,
address beneficiary
)
internal
override
returns (address)
{
(
uint256 destDomain,
uint256 slippage,
address asset,
uint256 amount,
address receiver,
address sender
) = abi.decode(params, (uint256, uint256, address, uint256, address, address));
_checkIfAddressZero(receiver);
/// @dev In a simple _crossTransfer funds should not be left in destination `ConnextRouter.sol`
if (receiver == receiverByDomain[destDomain]) {
revert ConnextRouter__crossTransfer_checkReceiver();
}
address beneficiary_ = _checkBeneficiary(beneficiary, receiver);
_safePullTokenFrom(asset, sender, amount);
_safeApprove(asset, address(connext), amount);
bytes32 transferId = connext.xcall(
// _destination: Domain ID of the destination chain
uint32(destDomain),
// _to: address of the target contract
receiver,
// _asset: address of the token contract
asset,
// _delegate: address that has rights to update the original slippage tolerance
// by calling Connext's forceUpdateSlippage function
beneficiary_,
// _amount: amount of tokens to transfer
amount,
// _slippage: can be anything between 0-10000 becaus
// the maximum amount of slippage the user will accept in BPS, 30 == 0.3%
slippage,
// _callData: empty because we're only sending funds
""
);
emit XCalled(transferId, msg.sender, receiver, destDomain, asset, amount, "");
return beneficiary_;
}
/**
* @dev NOTE to integrators
* The `beneficiary_`, of a `_crossTransferWithCalldata(...)` must meet these requirement:
* - Must be an externally owned account (EOA) or
* - Must be a contract that implements or is capable of calling:
* - connext.forceUpdateSlippage(TransferInfo, _slippage) add the destination chain.
* Refer to 'delegate' argument:
* https://docs.connext.network/developers/guides/handling-failures#increasing-slippage-tolerance
*/
/// @inheritdoc BaseRouter
function _crossTransferWithCalldata(
bytes memory params,
address beneficiary
)
internal
override
returns (address beneficiary_)
{
(
uint256 destDomain,
uint256 slippage,
address asset,
uint256 amount,
address sender,
bytes memory callData
) = abi.decode(params, (uint256, uint256, address, uint256, address, bytes));
(Action[] memory actions, bytes[] memory args) = abi.decode(callData, (Action[], bytes[]));
beneficiary_ = _checkBeneficiary(beneficiary, _getBeneficiaryFromCalldata(actions, args));
address to_ = receiverByDomain[destDomain];
_checkIfAddressZero(to_);
_safePullTokenFrom(asset, sender, amount);
_safeApprove(asset, address(connext), amount);
bytes32 transferId = connext.xcall(
// _destination: Domain ID of the destination chain
uint32(destDomain),
// _to: address of the target contract
to_,
// _asset: address of the token contract
asset,
// _delegate: address that can revert or forceLocal on destination
beneficiary_,
// _amount: amount of tokens to transfer
amount,
// _slippage: can be anything between 0-10000 becaus
// the maximum amount of slippage the user will accept in BPS, 30 == 0.3%
slippage,
// _callData: the encoded calldata to send
callData
);
emit XCalled(
transferId, msg.sender, receiverByDomain[destDomain], destDomain, asset, amount, callData
);
return beneficiary_;
}
/// @inheritdoc BaseRouter
function _replaceAmountInCrossAction(
Action action,
bytes memory args,
uint256 updateAmount
)
internal
pure
override
returns (bytes memory newArgs, uint256 previousAmount)
{
if (action == Action.XTransfer) {
(
uint256 destDomain,
uint256 slippage,
address asset,
uint256 amount,
address receiver,
address sender
) = abi.decode(args, (uint256, uint256, address, uint256, address, address));
previousAmount = amount;
newArgs = abi.encode(destDomain, slippage, asset, updateAmount, receiver, sender);
} else if (action == Action.XTransferWithCall) {
(
uint256 destDomain,
uint256 slippage,
address asset,
uint256 amount,
address sender,
bytes memory callData
) = abi.decode(args, (uint256, uint256, address, uint256, address, bytes));
previousAmount = amount;
newArgs = abi.encode(destDomain, slippage, asset, updateAmount, sender, callData);
}
}
/// @inheritdoc BaseRouter
function _getBeneficiaryFromCalldata(
Action[] memory actions,
bytes[] memory args
)
internal
view
override
returns (address beneficiary_)
{
if (actions[0] == Action.Deposit || actions[0] == Action.Payback) {
// For Deposit or Payback.
(,, address receiver,) = abi.decode(args[0], (IVault, uint256, address, address));
beneficiary_ = receiver;
} else if (actions[0] == Action.Withdraw || actions[0] == Action.Borrow) {
// For Withdraw or Borrow
(,,, address owner) = abi.decode(args[0], (IVault, uint256, address, address));
beneficiary_ = owner;
} else if (actions[0] == Action.WithdrawETH) {
// For WithdrawEth
(, address receiver) = abi.decode(args[0], (uint256, address));
beneficiary_ = receiver;
} else if (actions[0] == Action.PermitBorrow || actions[0] == Action.PermitWithdraw) {
(, address owner,,,,,,) = abi.decode(
args[0], (IVaultPermissions, address, address, uint256, uint256, uint8, bytes32, bytes32)
);
beneficiary_ = owner;
} else if (actions[0] == Action.Flashloan) {
(,,,, Action[] memory newActions, bytes[] memory newArgs) =
abi.decode(args[0], (IFlasher, address, uint256, address, Action[], bytes[]));
beneficiary_ = _getBeneficiaryFromCalldata(newActions, newArgs);
} else if (actions[0] == Action.XTransfer) {
(,,,, address receiver,) =
abi.decode(args[0], (uint256, uint256, address, uint256, address, address));
beneficiary_ = receiver;
} else if (actions[0] == Action.XTransferWithCall) {
(,,,, bytes memory callData) =
abi.decode(args[0], (uint256, uint256, address, uint256, bytes));
(Action[] memory actions_, bytes[] memory args_) = abi.decode(callData, (Action[], bytes[]));
beneficiary_ = _getBeneficiaryFromCalldata(actions_, args_);
} else if (actions[0] == Action.DepositETH) {
/// @dev depositETH cannot be actions[0] in ConnextRouter or inner-flashloan
revert BaseRouter__bundleInternal_notFirstAction();
} else if (actions[0] == Action.Swap) {
/// @dev swap cannot be actions[0].
revert BaseRouter__bundleInternal_notFirstAction();
}
}
/**
* @notice Anyone can call this function on the origin domain to increase the relayer fee for a transfer.
*
* @param transferId the unique identifier of the crosschain transaction
*/
function bumpTransfer(bytes32 transferId) external payable {
connext.bumpTransfer{value: msg.value}(transferId);
}
/**
* @notice Registers an address of the ConnextReceiver deployed on another chain.
*
* @param domain unique identifier of a chain as defined in
* https://docs.connext.network/resources/deployments
* @param receiver address of ConnextReceiver deployed on the chain defined by its domain
*
* @dev The mapping domain -> receiver is used in `xReceive` to verify the origin sender.
* Requirements:
* - Must be restricted to timelock.
* - `receiver` must be a non-zero address.
*/
function setReceiver(uint256 domain, address receiver) external onlyTimelock {
_checkIfAddressZero(receiver);
receiverByDomain[domain] = receiver;
emit NewConnextReceiver(receiver, domain);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (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. Compatible with tokens that require the approval to be set to
* 0 before setting it to a non-zero value.
*/
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));
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IConnext
*
* @author Fujidao Labs
*
* @notice Defines the common interfaces and data types used
* to interact with Connext Amarok.
*/
/**
* @notice These are the parameters that will remain constant between the
* two chains. They are supplied on `xcall` and should be asserted on `execute`
* @property to - The account that receives funds, in the event of a crosschain call,
* will receive funds if the call fails.
*
* @param originDomain - The originating domain (i.e. where `xcall` is called). Must match nomad domain schema
* @param destinationDomain - The final domain (i.e. where `execute` / `reconcile` are called). Must match nomad domain schema
* @param canonicalDomain - The canonical domain of the asset you are bridging
* @param to - The address you are sending funds (and potentially data) to
* @param delegate - An address who can execute txs on behalf of `to`, in addition to allowing relayers
* @param receiveLocal - If true, will use the local nomad asset on the destination instead of adopted.
* @param callData - The data to execute on the receiving chain. If no crosschain call is needed, then leave empty.
* @param slippage - Slippage user is willing to accept from original amount in expressed in BPS (i.e. if
* a user takes 1% slippage, this is expressed as 1_000)
* @param originSender - The msg.sender of the xcall
* @param bridgedAmt - The amount sent over the bridge (after potential AMM on xcall)
* @param normalizedIn - The amount sent to `xcall`, normalized to 18 decimals
* @param nonce - The nonce on the origin domain used to ensure the transferIds are unique
* @param canonicalId - The unique identifier of the canonical token corresponding to bridge assets
*/
struct TransferInfo {
uint32 originDomain;
uint32 destinationDomain;
uint32 canonicalDomain;
address to;
address delegate;
bool receiveLocal;
bytes callData;
uint256 slippage;
address originSender;
uint256 bridgedAmt;
uint256 normalizedIn;
uint256 nonce;
bytes32 canonicalId;
}
/**
* @notice
* @param params - The TransferInfo. These are consistent across sending and receiving chains.
* @param routers - The routers who you are sending the funds on behalf of.
* @param routerSignatures - Signatures belonging to the routers indicating permission to use funds
* for the signed transfer ID.
* @param sequencer - The sequencer who assigned the router path to this transfer.
* @param sequencerSignature - Signature produced by the sequencer for path assignment accountability
* for the path that was signed.
*/
struct ExecuteArgs {
TransferInfo params;
address[] routers;
bytes[] routerSignatures;
address sequencer;
bytes sequencerSignature;
}
interface IConnext {
function xcall(
uint32 _destination,
address _to,
address _asset,
address _delegate,
uint256 _amount,
uint256 _slippage,
bytes calldata _callData
)
external
payable
returns (bytes32);
function execute(ExecuteArgs calldata _args)
external
returns (bool success, bytes memory returnData);
function bumpTransfer(bytes32 transferId) external payable;
function forceUpdateSlippage(TransferInfo calldata _params, uint256 _slippage) external;
}
interface IXReceiver {
function xReceive(
bytes32 _transferId,
uint256 _amount,
address _asset,
address _originSender,
uint32 _origin,
bytes memory _callData
)
external
returns (bytes memory);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title ConnextReceiver
*
* @author Fujidao Labs
*
* @notice A proxy contract that receive the XReceive call from connext to
* allow assets to be safely pulled in {ConnextRouter.sol}
*/
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {IXReceiver} from "../interfaces/connext/IConnext.sol";
import {ConnextRouter} from "./ConnextRouter.sol";
contract ConnextReceiver is IXReceiver {
using SafeERC20 for IERC20;
error ConnextReceiver__xReceive_notReceivedAssetBalance();
ConnextRouter public immutable connextRouter;
/**
* @notice Constructor that initializes ConnextReceiver
*/
constructor(address connextRouter_) {
// No need to check address(0) since this contract is deployed within {ConnextRouter.sol}
connextRouter = ConnextRouter(payable(connextRouter_));
}
function xReceive(
bytes32 transferId,
uint256 amount,
address asset,
address originSender,
uint32 originDomain,
bytes memory callData
)
external
returns (bytes memory)
{
if (amount > 0) {
uint256 balance = IERC20(asset).balanceOf(address(this));
if (balance < amount) {
revert ConnextReceiver__xReceive_notReceivedAssetBalance();
}
IERC20(asset).safeIncreaseAllowance(address(connextRouter), amount);
}
return connextRouter.xReceive(transferId, amount, asset, originSender, originDomain, callData);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title ConnextHandler
*
* @author Fujidao Labs
*
* @notice Handles failed transactions from Connext and keeps custody of
* the transferred funds.
*/
import {ConnextRouter} from "./ConnextRouter.sol";
import {IRouter} from "../interfaces/IRouter.sol";
import {IVault} from "../interfaces/IVault.sol";
import {ISwapper} from "../interfaces/ISwapper.sol";
import {IERC20, SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
contract ConnextHandler {
using SafeERC20 for IERC20;
/**
* @dev Contains the information of a failed transaction.
*/
struct FailedTxn {
bytes32 transferId;
uint256 amount;
address asset;
address originSender;
uint32 originDomain;
IRouter.Action[] actions;
bytes[] args;
uint256 nonce;
bool executed;
}
/**
* @dev Emitted when a failed transaction is recorded.
*
* @param transferId unique id of the cross-chain txn
* @param amount transferred
* @param asset being transferred
* @param originSender of the cross-chain txn
* @param originDomain of the cross-chain txn
* @param actions to be called in xBundle
* @param args to be called for each action in xBundle
* @param nonce of failed txn
*/
event FailedTxnRecorded(
bytes32 indexed transferId,
uint256 amount,
address asset,
address originSender,
uint32 originDomain,
IRouter.Action[] actions,
bytes[] args,
uint256 nonce
);
/**
* @dev Emitted when a failed transaction gets retried.
*
* @param transferId the unique identifier of the cross-chain txn
* @param success boolean
* @param oldArgs of the failed transaction
* @param newArgs attemped in execution
*/
event FailedTxnExecuted(
bytes32 indexed transferId,
IRouter.Action[] oldActions,
IRouter.Action[] newActions,
bytes[] oldArgs,
bytes[] newArgs,
uint256 nonce,
bool indexed success
);
/// @dev Custom errors
error ConnextHandler__callerNotConnextRouter();
error ConnextHandler__executeFailed_emptyTxn();
error ConnextHandler__executeFailed_tranferAlreadyExecuted(bytes32 transferId, uint256 nonce);
bytes32 private constant ZERO_BYTES32 =
0x0000000000000000000000000000000000000000000000000000000000000000;
ConnextRouter public immutable connextRouter;
/**
* @dev Maps a failed transferId -> calldata[]
* Multiple failed attempts are registered with nonce
*/
mapping(bytes32 => FailedTxn[]) private _failedTxns;
modifier onlyConnextRouter() {
if (msg.sender != address(connextRouter)) {
revert ConnextHandler__callerNotConnextRouter();
}
_;
}
/// @dev Modifier that checks `msg.sender` is an allowed called in {ConnextRouter}.
modifier onlyAllowedCaller() {
if (!connextRouter.isAllowedCaller(msg.sender)) {
revert ConnextHandler__callerNotConnextRouter();
}
_;
}
/**
* @notice Constructor that initialized
*/
constructor(address connextRouter_) {
connextRouter = ConnextRouter(payable(connextRouter_));
}
/**
* @notice Returns the struct of failed transaction by `transferId`.
*
* @param transferId the unique identifier of the cross-chain txn
* @param nonce or position in the array of the failed attempts to execute
*/
function getFailedTxn(bytes32 transferId, uint256 nonce) public view returns (FailedTxn memory) {
return _failedTxns[transferId][nonce];
}
function getFailedTxnNextNonce(bytes32 transferId) public view returns (uint256 next) {
return _failedTxns[transferId].length;
}
/**
* @notice Records a failed {ConnextRouter-xReceive} call.
*
* @param transferId the unique identifier of the cross-chain txn
* @param amount the amount of transferring asset, after slippage, the recipient address receives
* @param asset the asset being transferred
* @param originSender the address of the contract or EOA that called xcall on the origin chain
* @param originDomain the origin domain identifier according Connext nomenclature
* @param actions that should be executed in {BaseRouter-internalBundle}
* @param args for the actions
*
* @dev At this point of execution {ConnextRouter} sent all balance of `asset` to this contract.
* It has already been verified that `amount` of `asset` is >= to balance sent.
* This function does not need to emit an event since {ConnextRouter} already emit
* a failed `XReceived` event.
*/
function recordFailed(
bytes32 transferId,
uint256 amount,
address asset,
address originSender,
uint32 originDomain,
IRouter.Action[] memory actions,
bytes[] memory args
)
external
onlyConnextRouter
{
uint256 nextNonce = getFailedTxnNextNonce(transferId);
_failedTxns[transferId].push(
FailedTxn(
transferId, amount, asset, originSender, originDomain, actions, args, nextNonce, false
)
);
emit FailedTxnRecorded(
transferId, amount, asset, originSender, originDomain, actions, args, nextNonce
);
}
/**
* @notice Executes a failed transaction with update `args`
*
* @param transferId the unique identifier of the cross-chain txn
* @param nonce or position in the array of the failed attempts to execute
* @param actions that will replace actions of failed txn
* @param args taht will replace args of failed txn
*
* @dev Requirements:
* - Must only be called by an allowed caller in {ConnextRouter}.
* - Must clear the txn from `_failedTxns` mapping if execution succeeds.
* - Must replace `sender` in `args` for value tranfer type actions (Deposit-Payback-Swap}.
*/
function executeFailedWithUpdatedArgs(
bytes32 transferId,
uint256 nonce,
IRouter.Action[] memory actions,
bytes[] memory args
)
external
onlyAllowedCaller
{
FailedTxn memory txn = _failedTxns[transferId][nonce];
if (txn.transferId == ZERO_BYTES32 || txn.originDomain == 0) {
revert ConnextHandler__executeFailed_emptyTxn();
} else if (txn.executed) {
revert ConnextHandler__executeFailed_tranferAlreadyExecuted(transferId, nonce);
}
IERC20(txn.asset).safeIncreaseAllowance(address(connextRouter), txn.amount);
_failedTxns[transferId][nonce].executed = true;
try connextRouter.xBundle(actions, args) {
emit FailedTxnExecuted(transferId, txn.actions, actions, txn.args, args, nonce, true);
} catch {
_failedTxns[transferId][nonce].executed = false;
IERC20(txn.asset).safeDecreaseAllowance(address(connextRouter), txn.amount);
emit FailedTxnExecuted(transferId, txn.actions, actions, txn.args, args, nonce, false);
}
}
/**
* @notice Rescue stuck funds due to failed cross-chain calls (cf. ConnextRouter).
*
* @param token the address of the ERC-20 token to sweep
* @param receiver the address that will receive the swept funds
* @param amount amount to sweep
*/
function sweepToken(IERC20 token, address receiver, uint256 amount) external onlyAllowedCaller {
token.safeTransfer(receiver, amount);
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.15;
/**
* @title BaseRouter
*
* @author Fujidao Labs
*
* @notice Abstract contract to be inherited by all routers.
*/
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {ERC20, IERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {IRouter} from "../interfaces/IRouter.sol";
import {ISwapper} from "../interfaces/ISwapper.sol";
import {IVault} from "../interfaces/IVault.sol";
import {IChief} from "../interfaces/IChief.sol";
import {IFlasher} from "../interfaces/IFlasher.sol";
import {IVaultPermissions} from "../interfaces/IVaultPermissions.sol";
import {SystemAccessControl} from "../access/SystemAccessControl.sol";
import {ReentrancyGuard} from "../helpers/ReentrancyGuard.sol";
import {IWETH9} from "../abstracts/WETH9.sol";
import {LibBytes} from "../libraries/LibBytes.sol";
abstract contract BaseRouter is ReentrancyGuard, SystemAccessControl, IRouter {
using SafeERC20 for ERC20;
/**
* @dev Contains an address of an ERC-20 and the balance the router holds
* at a given moment of the transaction (ref. `_tokensToCheck`).
*/
struct Snapshot {
address token;
uint256 balance;
}
/**
* @dev Struct used internally containing the arguments of a IRouter.Action.Permit* to store
* and pass in memory and avoid "stack too deep" errors.
*/
struct PermitArgs {
IVaultPermissions vault;
address owner;
address receiver;
uint256 amount;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}
struct BundleStore {
uint256 len;
/**
* @dev Operations in the bundle should "benefit" or be executed
* on behalf of this account. These are receivers on DEPOSIT and PAYBACK
* or owners on WITHDRAW and BORROW.
*/
address beneficiary;
/**
* @dev Hash generated during execution of "_bundleInternal()" that should
* match the signed permit.
* This argument is used in {VaultPermissions-PermitWithdraw} and
* {VaultPermissions-PermitBorrow}
*/
bytes32 actionArgsHash;
uint256 nativeBalance;
Snapshot[] tokensToCheck;
}
/**
* @dev Emitted when `caller` is updated according to `allowed` boolean
* to perform cross-chain calls.
*
* @param caller permitted for cross-chain calls
* @param allowed boolean state
*/
event AllowCaller(address caller, bool allowed);
/// @dev Custom Errors
error BaseRouter__bundleInternal_notFirstAction();
error BaseRouter__bundleInternal_paramsMismatch();
error BaseRouter__bundleInternal_flashloanInvalidRequestor();
error BaseRouter__bundleInternal_noBalanceChange();
error BaseRouter__bundleInternal_notBeneficiary();
error BaseRouter__checkVaultInput_notActiveVault();
error BaseRouter__bundleInternal_notAllowedSwapper();
error BaseRouter__checkValidFlasher_notAllowedFlasher();
error BaseRouter__handlePermit_notPermitAction();
error BaseRouter__safeTransferETH_transferFailed();
error BaseRouter__receive_senderNotWETH();
error BaseRouter__fallback_notAllowed();
error BaseRouter__allowCaller_noAllowChange();
error BaseRouter__isInTokenList_snapshotLimitReached();
error BaseRouter__xBundleFlashloan_insufficientFlashloanBalance();
error BaseRouter__checkIfAddressZero_invalidZeroAddress();
IWETH9 public immutable WETH9;
bytes32 private constant ZERO_BYTES32 =
0x0000000000000000000000000000000000000000000000000000000000000000;
uint256 private _flashloanEnterStatus;
/// @dev Apply it on entry cross-chain calls functions as required.
mapping(address => bool) public isAllowedCaller;
modifier onlyValidFlasherNonReentrant() {
_checkValidFlasher(msg.sender);
if (_flashloanEnterStatus == _ENTERED) {
revert ReentrancyGuard_reentrantCall();
}
_flashloanEnterStatus = _ENTERED;
_;
_flashloanEnterStatus = _NOT_ENTERED;
}
/**
* @notice Constructor of a new {BaseRouter}.
*
* @param weth wrapped native token of this chain
* @param chief_ contract
*/
constructor(IWETH9 weth, IChief chief_) payable {
__SystemAccessControl_init(address(chief_));
WETH9 = weth;
_flashloanEnterStatus = _NOT_ENTERED;
}
/// @inheritdoc IRouter
function xBundle(
Action[] calldata actions,
bytes[] calldata args
)
external
payable
override
nonReentrant
{
_bundleInternal(actions, args, 0, Snapshot(address(0), 0));
}
/// @inheritdoc IRouter
function xBundleFlashloan(
Action[] calldata actions,
bytes[] calldata args,
address flashloanAsset,
uint256 flashAmount
)
external
payable
override
onlyValidFlasherNonReentrant
{
uint256 currentBalance = IERC20(flashloanAsset).balanceOf(address(this));
if (currentBalance < flashAmount) {
revert BaseRouter__xBundleFlashloan_insufficientFlashloanBalance();
}
_bundleInternal(actions, args, 0, Snapshot(flashloanAsset, currentBalance - flashAmount));
}
/**
* @notice Marks a specific caller as allowed/disallowed to call certain functions.
*
* @param caller address to allow/disallow
* @param allowed 'true' to allow, 'false' to disallow
*
* @dev The authorization is to be implemented on the bridge-specific contract.
*/
function allowCaller(address caller, bool allowed) external onlyTimelock {
_allowCaller(caller, allowed);
}
/// @inheritdoc IRouter
function sweepToken(ERC20 token, address receiver) external onlyHouseKeeper {
uint256 amount = token.balanceOf(address(this));
if (amount == 0) return;
token.safeTransfer(receiver, amount);
}
/// @inheritdoc IRouter
function sweepETH(address receiver) external onlyHouseKeeper {
_safeTransferETH(receiver, address(this).balance);
}
/**
* @dev Executes a bundle of actions.
* Requirements:
* - Must not leave any balance in this contract after all actions.
* - Must call `_checkNoBalanceChange()` after all `actions` are executed.
* - Must call `_addTokenToList()` in `actions` that involve tokens.
* - Must clear `_beneficiary` from storage after all `actions` are executed.
*
* @param actions an array of actions that will be executed in a row
* @param args an array of encoded inputs needed to execute each action
* @param beforeSlipped amount passed by the origin cross-chain router operation
* @param tokenToCheck_ snapshot token balance awareness required from parent calls
*/
function _bundleInternal(
Action[] memory actions,
bytes[] memory args,
uint256 beforeSlipped,
Snapshot memory tokenToCheck_
)
internal
{
BundleStore memory store;
store.len = actions.length;
if (store.len != args.length) {
revert BaseRouter__bundleInternal_paramsMismatch();
}
/**
* @dev Stores token balances of this contract at a given moment.
* It's used to ensure there're no changes in balances at the
* end of a transaction.
*/
store.tokensToCheck = new Snapshot[](10);
/// @dev Add token to check from parent calls.
if (tokenToCheck_.token != address(0)) {
store.tokensToCheck[0] = tokenToCheck_;
}
store.nativeBalance = address(this).balance - msg.value;
for (uint256 i; i < store.len;) {
Action action = actions[i];
if (action == Action.Deposit) {
// DEPOSIT
(IVault vault, uint256 amount, address receiver, address sender) =
abi.decode(args[i], (IVault, uint256, address, address));
_checkVaultInput(address(vault));
address token = vault.asset();
store.beneficiary = _checkBeneficiary(store.beneficiary, receiver);
_addTokenToList(token, store.tokensToCheck);
_addTokenToList(address(vault), store.tokensToCheck);
_safePullTokenFrom(token, sender, amount);
_safeApprove(token, address(vault), amount);
vault.deposit(amount, receiver);
} else if (action == Action.Withdraw) {
// WITHDRAW
(bool replace, bytes memory nextArgs) = _handleWithdrawAction(actions, args, store, i);
if (replace) args[i + 1] = nextArgs;
} else if (action == Action.Borrow) {
// BORROW
(IVault vault, uint256 amount, address receiver, address owner) =
abi.decode(args[i], (IVault, uint256, address, address));
_checkVaultInput(address(vault));
store.beneficiary = _checkBeneficiary(store.beneficiary, owner);
_addTokenToList(vault.debtAsset(), store.tokensToCheck);
vault.borrow(amount, receiver, owner);
} else if (action == Action.Payback) {
// PAYBACK
(IVault vault, uint256 amount, address receiver, address sender) =
abi.decode(args[i], (IVault, uint256, address, address));
_checkVaultInput(address(vault));
address token = vault.debtAsset();
store.beneficiary = _checkBeneficiary(store.beneficiary, receiver);
_addTokenToList(token, store.tokensToCheck);
_safePullTokenFrom(token, sender, amount);
_safeApprove(token, address(vault), amount);
vault.payback(amount, receiver);
} else if (action == Action.PermitWithdraw) {
// PERMIT WITHDRAW
// TODO Need to handle case in where withdraw action replaced argument.
if (store.actionArgsHash == ZERO_BYTES32) {
store.actionArgsHash = _getActionArgsHash(actions, args, beforeSlipped);
}
// Scoped code in new private function to avoid "Stack too deep"
address owner_ = _handlePermitAction(action, args[i], store.actionArgsHash);
store.beneficiary = _checkBeneficiary(store.beneficiary, owner_);
} else if (action == Action.PermitBorrow) {
// PERMIT BORROW
// TODO Need to handle case in where withdraw action replaced argument.
if (store.actionArgsHash == ZERO_BYTES32) {
store.actionArgsHash = _getActionArgsHash(actions, args, beforeSlipped);
}
// Scoped code in new private function to avoid "Stack too deep"
address owner_ = _handlePermitAction(action, args[i], store.actionArgsHash);
store.beneficiary = _checkBeneficiary(store.beneficiary, owner_);
} else if (action == Action.XTransfer) {
// SIMPLE BRIDGE TRANSFER
store.beneficiary = _crossTransfer(args[i], store.beneficiary);
} else if (action == Action.XTransferWithCall) {
// BRIDGE WITH CALLDATA
store.beneficiary = _crossTransferWithCalldata(args[i], store.beneficiary);
} else if (action == Action.Swap) {
// SWAP
if (i == 0) {
/// @dev swap cannot be actions[0].
revert BaseRouter__bundleInternal_notFirstAction();
}
store.beneficiary = _handleSwapAction(args[i], store.beneficiary, store.tokensToCheck);
} else if (action == Action.Flashloan) {
// FLASHLOAN
// Decode params.
(
IFlasher flasher,
address asset,
uint256 flashAmount,
address requestor,
Action[] memory innerActions,
bytes[] memory innerArgs
) = abi.decode(args[i], (IFlasher, address, uint256, address, Action[], bytes[]));
_checkValidFlasher(address(flasher));
if (requestor != address(this)) {
revert BaseRouter__bundleInternal_flashloanInvalidRequestor();
}
_addTokenToList(asset, store.tokensToCheck);
store.beneficiary =
_checkBeneficiary(store.beneficiary, _getBeneficiaryFromCalldata(innerActions, innerArgs));
bytes memory requestorCalldata = abi.encodeWithSelector(
this.xBundleFlashloan.selector, innerActions, innerArgs, asset, flashAmount
);
// Call Flasher.
flasher.initiateFlashloan(asset, flashAmount, requestor, requestorCalldata);
} else if (action == Action.DepositETH) {
uint256 amount = abi.decode(args[i], (uint256));
///@dev There is no check for msg.value as that is already done via `nativeBalance`
_addTokenToList(address(WETH9), store.tokensToCheck);
WETH9.deposit{value: amount}();
} else if (action == Action.WithdrawETH) {
(uint256 amount, address receiver) = abi.decode(args[i], (uint256, address));
store.beneficiary = _checkBeneficiary(store.beneficiary, receiver);
_addTokenToList(address(WETH9), store.tokensToCheck);
WETH9.withdraw(amount);
_safeTransferETH(receiver, amount);
}
unchecked {
++i;
}
}
_checkNoBalanceChange(store.tokensToCheck, store.nativeBalance);
}
/**
* @dev Decodes and replaces "amount" argument in args with `updateAmount`
* in actions in where it is required to replace it.
*/
function _replaceAmountArgInAction(
Action action,
bytes memory args,
uint256 updateAmount
)
internal
pure
returns (bytes memory newArgs, uint256 previousAmount)
{
if (
action == Action.Deposit || action == Action.Withdraw || action == Action.Borrow
|| action == Action.Payback
) {
(IVault vault, uint256 amount, address addr1, address addr2) =
abi.decode(args, (IVault, uint256, address, address));
previousAmount = amount;
newArgs = abi.encode(vault, updateAmount, addr1, addr2);
} else if (action == Action.XTransfer || action == Action.XTransferWithCall) {
(newArgs, previousAmount) = _replaceAmountInCrossAction(action, args, updateAmount);
} else if (action == Action.Swap) {
(
ISwapper swapper,
address assetIn,
address assetOut,
uint256 amountIn,
uint256 amountOut,
address receiver,
address sweeper,
uint256 minSweepOut
) =
abi.decode(args, (ISwapper, address, address, uint256, uint256, address, address, uint256));
previousAmount = amountIn;
newArgs = abi.encode(
swapper, assetIn, assetOut, updateAmount, amountOut, receiver, sweeper, minSweepOut
);
} else if (action == Action.WithdrawETH) {
(uint256 amount, address receiver) = abi.decode(args, (uint256, address));
previousAmount = amount;
newArgs = abi.encode(updateAmount, receiver);
}
}
/**
* @dev Similar to `_replaceAmountArgInAction(...)` but asbtracted to implement
* specific bridge logic.
*/
function _replaceAmountInCrossAction(
Action action,
bytes memory args,
uint256 updateAmount
)
internal
pure
virtual
returns (bytes memory newArgs, uint256 previousAmount);
/**
* @dev Handles both permit actions logic flow.
* This function was required to avoid "stack too deep" error in `_bundleInternal()`.
*
* @param action either IRouter.Action.PermitWithdraw (6), or IRouter.Action.PermitBorrow (7)
* @param arg of the ongoing action
* @param actionArgsHash_ created previously withing `_bundleInternal()` to be used in permit check
*/
function _handlePermitAction(
IRouter.Action action,
bytes memory arg,
bytes32 actionArgsHash_
)
private
returns (address)
{
PermitArgs memory permitArgs;
{
(
permitArgs.vault,
permitArgs.owner,
permitArgs.receiver,
permitArgs.amount,
permitArgs.deadline,
permitArgs.v,
permitArgs.r,
permitArgs.s
) = abi.decode(
arg, (IVaultPermissions, address, address, uint256, uint256, uint8, bytes32, bytes32)
);
}
_checkVaultInput(address(permitArgs.vault));
if (action == IRouter.Action.PermitWithdraw) {
permitArgs.vault.permitWithdraw(
permitArgs.owner,
permitArgs.receiver,
permitArgs.amount,
permitArgs.deadline,
actionArgsHash_,
permitArgs.v,
permitArgs.r,
permitArgs.s
);
} else if (action == IRouter.Action.PermitBorrow) {
permitArgs.vault.permitBorrow(
permitArgs.owner,
permitArgs.receiver,
permitArgs.amount,
permitArgs.deadline,
actionArgsHash_,
permitArgs.v,
permitArgs.r,
permitArgs.s
);
} else {
revert BaseRouter__handlePermit_notPermitAction();
}
return permitArgs.owner;
}
/**
* @dev Returns the `zeroPermitEncodedArgs` which is required to create
* the `actionArgsHash` used during permit signature
*
* @param vault that will execute action
* @param owner owner of the assets
* @param receiver of the assets after action
* @param amount of assets being permitted in action
*/
function _getZeroPermitEncodedArgs(
IVaultPermissions vault,
address owner,
address receiver,
uint256 amount
)
private
pure
returns (bytes memory)
{
return abi.encode(vault, owner, receiver, amount, 0, 0, ZERO_BYTES32, ZERO_BYTES32);
}
/**
* @dev Returns the `actionsArgsHash` required in
* {VaultPermissions-permitWithdraw} or {VaultPermissions-permitBorrow}.
* Requirements:
* - Must replace arguments in IRouter.Action.PermitWithdraw for "zeroPermit".
* - Must replace arguments in IRouter.Action.PermitBorrow for "zeroPermit".
* - Must replace `beforeSlipped` amount in cross-chain txs that had slippage.
*
*
* @param actions being executed in this `_bundleInternal`
* @param args provided in `_bundleInternal`
* @param beforeSlipped amount passed by the origin cross-chain router operation
*/
function _getActionArgsHash(
IRouter.Action[] memory actions,
bytes[] memory args,
uint256 beforeSlipped
)
private
pure
returns (bytes32)
{
uint256 len = actions.length;
/**
* @dev We intend to ONLY modify the new bytes array.
* "memory" in solidity persists within internal calls.
*/
bytes[] memory modArgs = new bytes[](len);
for (uint256 i; i < len; i++) {
modArgs[i] = args[i];
if (
i == 0 && beforeSlipped != 0
&& (actions[i] == IRouter.Action.Deposit || actions[i] == IRouter.Action.Payback)
) {
/**
* @dev Replace slippage values in the first ( i==0 ) "value" transfer
* action in the destination chain (deposit or to payback).
* If `beforeSlipped` == 0, it means there was no slippage in the attempted cross-chain tx
* or the tx is single chain; thereore, not requiring any replacement.
* Then, if beforeSlipped != 0 and beforeSlipped != slippedAmount, function should replace
* to obtain the "original" intended transfer value signed in `actionArgsHash`.
*/
(IVault vault, uint256 slippedAmount, address receiver, address sender) =
abi.decode(modArgs[i], (IVault, uint256, address, address));
if (beforeSlipped != slippedAmount) {
modArgs[i] = abi.encode(vault, beforeSlipped, receiver, sender);
}
}
if (actions[i] == IRouter.Action.PermitWithdraw || actions[i] == IRouter.Action.PermitBorrow)
{
// Need to replace permit `args` at `index` with the `zeroPermitArg`.
(IVaultPermissions vault, address owner, address receiver, uint256 amount,,,,) = abi.decode(
modArgs[i],
(IVaultPermissions, address, address, uint256, uint256, uint8, bytes32, bytes32)
);
modArgs[i] = _getZeroPermitEncodedArgs(vault, owner, receiver, amount);
}
}
return keccak256(abi.encode(actions, modArgs));
}
/**
* @dev Handles withdraw actions logic flow. When there may be futher actions
* requiring to replace the `amount` argument, it handles the replacement.
*
* Requirements:
* - Check if next action is type that requires `amount` arg update otherwise
* proceed as normal.
*/
function _handleWithdrawAction(
Action[] memory actions,
bytes[] memory args,
BundleStore memory store,
uint256 i
)
private
returns (bool replace, bytes memory updatedArgs)
{
(IVault vault, uint256 amount, address receiver, address owner) =
abi.decode(args[i], (IVault, uint256, address, address));
_checkVaultInput(address(vault));
store.beneficiary = _checkBeneficiary(store.beneficiary, owner);
_addTokenToList(vault.asset(), store.tokensToCheck);
_addTokenToList(address(vault), store.tokensToCheck);
if (i + 1 == store.len) {
// If Withdraw is last action just withdraw
vault.withdraw(amount, receiver, owner);
return (false, "");
}
Action nextAction = actions[i + 1];
bytes memory nextArgs = args[i + 1];
// Default to return same args
updatedArgs = nextArgs;
if (
(
nextAction == Action.Deposit || nextAction == Action.Swap || nextAction == Action.XTransfer
|| nextAction == Action.XTransferWithCall || nextAction == Action.WithdrawETH
) && receiver == address(this)
) {
// Sandwhich the withrawal with bal requests to know if max-soft-withdrawal took place.
IERC20 asset = IERC20(vault.asset());
uint256 prevBal = asset.balanceOf(address(this));
vault.withdraw(amount, receiver, owner);
uint256 afterBal = asset.balanceOf(address(this));
uint256 updateAmount = (afterBal - prevBal);
if (amount > updateAmount) {
replace = true;
// If the withdraw `amount` encoded was > than the `owner`'s "maxWithdraw", the
// difference in "(afterBal - prevBal)" must be less than amount.
(updatedArgs,) = _replaceAmountArgInAction(nextAction, nextArgs, updateAmount);
}
}
vault.withdraw(amount, receiver, owner);
}
/**
* @dev Handles swap actions logic flow.
* This function was required to avoid "stack too deep" error in `_bundleInternal()`.
* Requirements:
* - Must return updated "beneficiary".
* - Must check swapper is a valid swapper at {Chief}.
* - Must check `receiver` and `sweeper` args are the expected
* beneficiary when the receiver and sweeper are not address(this).
*
* @param arg of the ongoing action
* @param beneficiary_ passed through `_bundleInternal()`
* @param tokensToCheck_ passed through `_bundleInternal()`
*/
function _handleSwapAction(
bytes memory arg,
address beneficiary_,
Snapshot[] memory tokensToCheck_
)
private
returns (address)
{
(
ISwapper swapper,
address assetIn,
address assetOut,
uint256 amountIn,
uint256 amountOut,
address receiver,
address sweeper,
uint256 minSweepOut
) = abi.decode(arg, (ISwapper, address, address, uint256, uint256, address, address, uint256));
if (!chief.allowedSwapper(address(swapper))) {
revert BaseRouter__bundleInternal_notAllowedSwapper();
}
_addTokenToList(assetIn, tokensToCheck_);
_addTokenToList(assetOut, tokensToCheck_);
_safeApprove(assetIn, address(swapper), amountIn);
if (receiver != address(this) && !chief.allowedFlasher(receiver)) {
beneficiary_ = _checkBeneficiary(beneficiary_, receiver);
}
if (sweeper != address(this)) {
beneficiary_ = _checkBeneficiary(beneficiary_, sweeper);
}
swapper.swap(assetIn, assetOut, amountIn, amountOut, receiver, sweeper, minSweepOut);
return (beneficiary_);
}
/**
* @dev Helper function to transfer ETH.
*
* @param receiver address to receive the ETH
* @param amount amount to be transferred
*/
function _safeTransferETH(address receiver, uint256 amount) internal {
if (amount == 0) return;
_checkIfAddressZero(receiver);
(bool success,) = receiver.call{value: amount}(new bytes(0));
if (!success) {
revert BaseRouter__safeTransferETH_transferFailed();
}
}
/**
* @dev Helper function to pull ERC-20 token from a sender address after some checks.
* The checks are needed because when we bundle multiple actions
* it can happen the router already holds the assets in question;
* for. example when we withdraw from a vault and deposit to another one.
*
* @param token ERC-20 token address
* @param sender address to pull tokens from
* @param amount amount of tokens to be pulled
*/
function _safePullTokenFrom(address token, address sender, uint256 amount) internal {
if (amount == 0) return;
if (sender != address(this) && sender == msg.sender) {
ERC20(token).safeTransferFrom(sender, address(this), amount);
}
}
/**
* @dev Helper function to approve ERC-20 transfers.
*
* @param token ERC-20 address to approve
* @param to address to approve as a spender
* @param amount amount to be approved
*/
function _safeApprove(address token, address to, uint256 amount) internal {
if (amount == 0) return;
ERC20(token).safeIncreaseAllowance(to, amount);
}
/**
* @dev Check `allowCaller()` above.
*
* @param caller address to allow/disallow
* @param allowed 'true' to allow, 'false' to disallow
*/
function _allowCaller(address caller, bool allowed) internal {
_checkIfAddressZero(caller);
if (isAllowedCaller[caller] == allowed) {
revert BaseRouter__allowCaller_noAllowChange();
}
isAllowedCaller[caller] = allowed;
emit AllowCaller(caller, allowed);
}
/**
* @dev Function to be implemented on the bridge-specific contract
* used to transfer funds WITHOUT calldata to a destination chain.
*
* Note Check requirements at children contract.
*/
function _crossTransfer(bytes memory, address beneficiary) internal virtual returns (address);
/**
* @dev Function to be implemented on the bridge-specific contract
* used to transfer funds WITH calldata to a destination chain.
*
* Note Check requirements at children contract.
*/
function _crossTransferWithCalldata(
bytes memory,
address beneficiary
)
internal
virtual
returns (address);
/**
* @dev Returns "true" and the `latestIndex` where a zero-address exists
*
* @param token address of ERC-20 to check
* @param tokenList to check
*/
function _isInTokenList(
address token,
Snapshot[] memory tokenList
)
private
pure
returns (bool value, uint256 latestIndex)
{
uint256 len = tokenList.length;
for (uint256 i; i < len;) {
if (token == tokenList[i].token) {
return (true, 0); // leave when the element is found
}
if (tokenList[i].token == address(0)) {
return (false, i); // leave if the first empty spot is found
}
unchecked {
++i;
}
}
// revert if looped through whole array and found no match or empty value
revert BaseRouter__isInTokenList_snapshotLimitReached();
}
/**
* @dev Adds a token and balance to a Snapshot and returns it.
* Requirements:
* - Must check if token has already been added.
*
* @param token address of ERC-20 to be pushed
* @param tokenList to add token
*/
function _addTokenToList(address token, Snapshot[] memory tokenList) private view {
(bool isInList, uint256 latestIndex) = _isInTokenList(token, tokenList);
if (!isInList) {
tokenList[latestIndex] = Snapshot(token, IERC20(token).balanceOf(address(this)));
}
}
/**
* @dev Checks that `erc20-balanceOf` of `_tokensToCheck` haven't change for this address.
* Requirements:
* - Must be called in `_bundleInternal()` at the end of all executed `actions`.
* - Must clear `_tokensToCheck` from storage at the end of checks.
*
* @param tokensToCheck array of 'Snapshot' elements
* @param nativeBalance the stored balance of ETH
*/
function _checkNoBalanceChange(
Snapshot[] memory tokensToCheck,
uint256 nativeBalance
)
private
view
{
uint256 len = tokensToCheck.length;
for (uint256 i; i < len;) {
if (tokensToCheck[i].token != address(0)) {
uint256 previousBalance = tokensToCheck[i].balance;
uint256 currentBalance = IERC20(tokensToCheck[i].token).balanceOf(address(this));
if (currentBalance != previousBalance) {
revert BaseRouter__bundleInternal_noBalanceChange();
}
} else {
break;
}
unchecked {
++i;
}
}
// Check at the end the native balance.
if (nativeBalance != address(this).balance) {
revert BaseRouter__bundleInternal_noBalanceChange();
}
}
/**
* @dev When bundling multiple actions assure that we act for a single beneficiary;
* receivers on DEPOSIT and PAYBACK and owners on WITHDRAW and BORROW
* must be the same user
*
* @param user address to verify is the beneficiary
*/
function _checkBeneficiary(address beneficiary, address user) internal pure returns (address) {
if (beneficiary == address(0)) {
return user;
} else if (beneficiary != user) {
revert BaseRouter__bundleInternal_notBeneficiary();
} else {
return user;
}
}
/**
* @dev Extracts the beneficiary from a set of actions and args.
* Requirements:
* - Must be implemented in child contracts, and added to `_crossTransfer` and
* `crossTansferWithCalldata` as applicable.
* - Must revert if `actions[0]` == IRouter.Action.Swap
* - Must revert if `actions[0]` == IRouter.Action.DepositETH
*
* NOTE: This function is also implemented in Action.Flashloan of
* `_internalBundle(...)`, meaning that within a flashloan
* the Action.DepositETH cannot be the first action either.
*
* @param actions an array of actions that will be executed in a row
* @param args an array of encoded inputs needed to execute each action
*/
function _getBeneficiaryFromCalldata(
Action[] memory actions,
bytes[] memory args
)
internal
view
virtual
returns (address beneficiary_);
function _checkVaultInput(address vault_) internal view {
if (!chief.isVaultActive(vault_)) {
revert BaseRouter__checkVaultInput_notActiveVault();
}
}
/**
* @dev Revert if flasher is not a valid flasher at {Chief}.
*
* @param flasher address to check
*/
function _checkValidFlasher(address flasher) internal view {
if (!chief.allowedFlasher(flasher)) {
revert BaseRouter__checkValidFlasher_notAllowedFlasher();
}
}
/**
* @dev Reverts if passed `addr` is address(0).
*/
function _checkIfAddressZero(address addr) internal pure {
if (addr == address(0)) {
revert BaseRouter__checkIfAddressZero_invalidZeroAddress();
}
}
/**
* @dev Only WETH contract is allowed to transfer ETH to this address.
* Prevent other addresses to send Ether to this contract.
*/
receive() external payable {
if (msg.sender != address(WETH9)) {
revert BaseRouter__receive_senderNotWETH();
}
}
/**
* @dev Revert fallback calls.
*/
fallback() external payable {
revert BaseRouter__fallback_notAllowed();
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IWETH9
*
* @author Unknown
*
* @notice Abstract contract of add-on functions of a
* typical ERC20 wrapped native token.
*/
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
abstract contract IWETH9 is ERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable virtual;
/// @notice Withdraw wrapped ether to get ether
function withdraw(uint256) external virtual;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IVault
*
* @author Fujidao Labs
*
* @notice Defines the interface for vaults extending from IERC4326.
*/
import {IERC4626} from "openzeppelin-contracts/contracts/interfaces/IERC4626.sol";
import {ILendingProvider} from "./ILendingProvider.sol";
import {IFujiOracle} from "./IFujiOracle.sol";
interface IVault is IERC4626 {
/**
* @dev Emit when borrow action occurs.
*
* @param sender who calls {IVault-borrow}
* @param receiver of the borrowed 'debt' amount
* @param owner who will incur the debt
* @param debt amount
* @param shares amount of 'debtShares' received
*/
event Borrow(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 debt,
uint256 shares
);
/**
* @dev Emit when payback action occurs.
*
* @param sender address who calls {IVault-payback}
* @param owner address whose debt will be reduced
* @param debt amount
* @param shares amound of 'debtShares' burned
*/
event Payback(address indexed sender, address indexed owner, uint256 debt, uint256 shares);
/**
* @dev Emit when the vault is initialized
*
* @param initializer of this vault
*
*/
event VaultInitialized(address initializer);
/**
* @dev Emit when the oracle address is changed.
*
* @param newOracle the new oracle address
*/
event OracleChanged(IFujiOracle newOracle);
/**
* @dev Emit when the available providers for the vault change.
*
* @param newProviders the new providers available
*/
event ProvidersChanged(ILendingProvider[] newProviders);
/**
* @dev Emit when the active provider is changed.
*
* @param newActiveProvider the new active provider
*/
event ActiveProviderChanged(ILendingProvider newActiveProvider);
/**
* @dev Emit when the vault is rebalanced.
*
* @param assets amount to be rebalanced
* @param debt amount to be rebalanced
* @param from provider
* @param to provider
*/
event VaultRebalance(uint256 assets, uint256 debt, address indexed from, address indexed to);
/**
* @dev Emit when the max LTV is changed.
* See factors: https://github.com/Fujicracy/CrossFuji/tree/main/packages/protocol#readme.
*
* @param newMaxLtv the new max LTV
*/
event MaxLtvChanged(uint256 newMaxLtv);
/**
* @dev Emit when the liquidation ratio is changed.
* See factors: https://github.com/Fujicracy/CrossFuji/tree/main/packages/protocol#readme.
*
* @param newLiqRatio the new liquidation ratio
*/
event LiqRatioChanged(uint256 newLiqRatio);
/**
* @dev Emit when the minumum amount is changed.
*
* @param newMinAmount the new minimum amount
*/
event MinAmountChanged(uint256 newMinAmount);
/**
* @dev Emit when the deposit cap is changed.
*
* @param newDepositCap the new deposit cap of this vault
*/
event DepositCapChanged(uint256 newDepositCap);
/*///////////////////////////
Asset management functions
//////////////////////////*/
/**
* @notice Returns the amount of assets owned by `owner`.
*
* @param owner to check balance
*
* @dev This method avoids having to do external conversions from shares to
* assets, since {IERC4626-balanceOf} returns shares.
*/
function balanceOfAsset(address owner) external view returns (uint256 assets);
/*///////////////////////////
Debt management functions
//////////////////////////*/
/**
* @notice Returns the decimals for 'debtAsset' of this vault.
*
* @dev Requirements:
* - Must match the 'debtAsset' decimals in ERC20 token.
* - Must return zero in a {YieldVault}.
*/
function debtDecimals() external view returns (uint8);
/**
* @notice Returns the address of the underlying token used as debt in functions
* `borrow()`, and `payback()`. Based on {IERC4626-asset}.
*
* @dev Requirements:
* - Must be an ERC-20 token contract.
* - Must not revert.
* - Must return zero in a {YieldVault}.
*/
function debtAsset() external view returns (address);
/**
* @notice Returns the amount of debt owned by `owner`.
*
* @param owner to check balance
*/
function balanceOfDebt(address owner) external view returns (uint256 debt);
/**
* @notice Returns the amount of `debtShares` owned by `owner`.
*
* @param owner to check balance
*/
function balanceOfDebtShares(address owner) external view returns (uint256 debtShares);
/**
* @notice Returns the total amount of the underlying debt asset
* that is “managed” by this vault. Based on {IERC4626-totalAssets}.
*
* @dev Requirements:
* - Must account for any compounding occuring from yield or interest accrual.
* - Must be inclusive of any fees that are charged against assets in the Vault.
* - Must not revert.
* - Must return zero in a {YieldVault}.
*/
function totalDebt() external view returns (uint256);
/**
* @notice Returns the amount of shares this vault would exchange for the amount
* of debt assets provided. Based on {IERC4626-convertToShares}.
*
* @param debt to convert into `debtShares`
*
* @dev Requirements:
* - Must not be inclusive of any fees that are charged against assets in the Vault.
* - Must not show any variations depending on the caller.
* - Must not reflect slippage or other on-chain conditions, when performing the actual exchange.
* - Must not revert.
*
* NOTE: This calculation MAY not reflect the “per-user” price-per-share, and instead Must reflect the
* “average-user’s” price-per-share, meaning what the average user Must expect to see when exchanging to and
* from.
*/
function convertDebtToShares(uint256 debt) external view returns (uint256 shares);
/**
* @notice Returns the amount of debt assets that this vault would exchange for the amount
* of shares provided. Based on {IERC4626-convertToAssets}.
*
* @param shares amount to convert into `debt`
*
* @dev Requirements:
* - Must not be inclusive of any fees that are charged against assets in the Vault.
* - Must not show any variations depending on the caller.
* - Must not reflect slippage or other on-chain conditions, when performing the actual exchange.
* - Must not revert.
*
* NOTE: This calculation MAY not reflect the “per-user” price-per-share, and instead must reflect the
* “average-user’s” price-per-share, meaning what the average user Must expect to see when exchanging to and
* from.
*/
function convertToDebt(uint256 shares) external view returns (uint256 debt);
/**
* @notice Returns the maximum amount of the debt asset that can be borrowed for the `owner`,
* through a borrow call.
*
* @param owner to check
*
* @dev Requirements:
* - Must return a limited value if receiver is subject to some borrow limit.
* - Must return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be borrowed.
* - Must not revert.
*/
function maxBorrow(address owner) external view returns (uint256 debt);
/**
* @notice Returns the maximum amount of debt that can be payback by the `borrower`.
*
* @param owner to check
*
* @dev Requirements:
* - Must not revert.
*/
function maxPayback(address owner) external view returns (uint256 debt);
/**
* @notice Returns the maximum amount of debt shares that can be "minted-for-borrowing" by the `borrower`.
*
* @param owner to check
*
* @dev Requirements:
* - Must not revert.
*/
function maxMintDebt(address owner) external view returns (uint256 shares);
/**
* @notice Returns the maximum amount of debt shares that can be "burned-for-payback" by the `borrower`.
*
* @param owner to check
*
* @dev Requirements:
* - Must not revert.
*/
function maxBurnDebt(address owner) external view returns (uint256 shares);
/**
* @notice Returns the amount of `debtShares` that borrowing `debt` amount will generate.
*
* @param debt amount to check
*
* @dev Requirements:
* - Must not revert.
*/
function previewBorrow(uint256 debt) external view returns (uint256 shares);
/**
* @notice Returns the amount of debt that borrowing `debtShares` amount will generate.
*
* @param shares of debt to check
*
* @dev Requirements:
* - Must not revert.
*/
function previewMintDebt(uint256 shares) external view returns (uint256 debt);
/**
* @notice Returns the amount of `debtShares` that will be burned by paying back
* `debt` amount.
*
* @param debt to check
*
* @dev Requirements:
* - Must not revert.
*/
function previewPayback(uint256 debt) external view returns (uint256 shares);
/**
* @notice Returns the amount of debt asset that will be pulled from user, if `debtShares` are
* burned to payback.
*
* @param debt to check
*
* @dev Requirements:
* - Must not revert.
*/
function previewBurnDebt(uint256 shares) external view returns (uint256 debt);
/**
* @notice Perform a borrow action. Function inspired on {IERC4626-deposit}.
*
* @param debt amount
* @param receiver of the `debt` amount
* @param owner who will incur the `debt` amount
*
* * @dev Mints debtShares to owner by taking a loan of exact amount of underlying tokens.
* Requirements:
* - Must emit the Borrow event.
* - Must revert if owner does not own sufficient collateral to back debt.
* - Must revert if caller is not owner or permissioned operator to act on owner behalf.
*/
function borrow(uint256 debt, address receiver, address owner) external returns (uint256 shares);
/**
* @notice Perform a borrow action by minting `debtShares`.
*
* @param shares of debt to mint
* @param receiver of the borrowed amount
* @param owner who will incur the `debt` and whom `debtShares` will be accounted
*
* * @dev Mints `debtShares` to `owner`.
* Requirements:
* - Must emit the Borrow event.
* - Must revert if owner does not own sufficient collateral to back debt.
* - Must revert if caller is not owner or permissioned operator to act on owner behalf.
*/
function mintDebt(
uint256 shares,
address receiver,
address owner
)
external
returns (uint256 debt);
/**
* @notice Burns `debtShares` to `receiver` by paying back loan with exact amount of underlying tokens.
*
* @param debt amount to payback
* @param receiver to whom debt amount is being paid back
*
* @dev Implementations will require pre-erc20-approval of the underlying debt token.
* Requirements:
* - Must emit a Payback event.
*/
function payback(uint256 debt, address receiver) external returns (uint256 shares);
/**
* @notice Burns `debtShares` to `owner` by paying back loan by specifying debt shares.
*
* @param shares of debt to payback
* @param owner to whom debt amount is being paid back
*
* @dev Implementations will require pre-erc20-approval of the underlying debt token.
* Requirements:
* - Must emit a Payback event.
*/
function burnDebt(uint256 shares, address owner) external returns (uint256 debt);
/*///////////////////
General functions
///////////////////*/
/**
* @notice Returns the active provider of this vault.
*/
function getProviders() external view returns (ILendingProvider[] memory);
/**
* @notice Returns the active provider of this vault.
*/
function activeProvider() external view returns (ILendingProvider);
/*/////////////////////////
Rebalancing Function
////////////////////////*/
/**
* @notice Performs rebalancing of vault by moving funds across providers.
*
* @param assets amount of this vault to be rebalanced
* @param debt amount of this vault to be rebalanced (Note: pass zero if this is a {YieldVault})
* @param from provider
* @param to provider
* @param fee expected from rebalancing operation
* @param setToAsActiveProvider boolean
*
* @dev Requirements:
* - Must check providers `from` and `to` are valid.
* - Must be called from a {RebalancerManager} contract that makes all proper checks.
* - Must revert if caller is not an approved rebalancer.
* - Must emit the VaultRebalance event.
* - Must check `fee` is a reasonable amount.
*/
function rebalance(
uint256 assets,
uint256 debt,
ILendingProvider from,
ILendingProvider to,
uint256 fee,
bool setToAsActiveProvider
)
external
returns (bool);
/*/////////////////////////
Liquidation Functions
/////////////////////////*/
/**
* @notice Returns the current health factor of 'owner'.
*
* @param owner to get health factor
*
* @dev Requirements:
* - Must return type(uint254).max when 'owner' has no debt.
* - Must revert in {YieldVault}.
*
* 'healthFactor' is scaled up by 1e18. A value below 1e18 means 'owner' is eligable for liquidation.
* See factors: https://github.com/Fujicracy/CrossFuji/tree/main/packages/protocol#readme.
*/
function getHealthFactor(address owner) external returns (uint256 healthFactor);
/**
* @notice Returns the liquidation close factor based on 'owner's' health factor.
*
* @param owner of debt position
*
* @dev Requirements:
* - Must return zero if `owner` is not liquidatable.
* - Must revert in {YieldVault}.
*/
function getLiquidationFactor(address owner) external returns (uint256 liquidationFactor);
/**
* @notice Performs liquidation of an unhealthy position, meaning a 'healthFactor' below 1e18.
*
* @param owner to be liquidated
* @param receiver of the collateral shares of liquidation
* @param liqCloseFactor percentage of `owner`'s debt to attempt liquidation
*
* @dev Requirements:
* - Must revert if caller is not an approved liquidator.
* - Must revert if 'owner' is not liquidatable.
* - Must emit the Liquidation event.
* - Must liquidate accoring to `liqCloseFactor` but restricted to the following:
* - Liquidate up to 50% of 'owner' debt when: 100 >= 'healthFactor' > 95.
* - Liquidate up to 100% of 'owner' debt when: 95 > 'healthFactor'.
* - Must revert in {YieldVault}.
*
* WARNING! It is liquidator's responsability to check if liquidation is profitable.
*/
function liquidate(
address owner,
address receiver,
uint256 liqCloseFactor
)
external
returns (uint256 gainedShares);
/*/////////////////////
Setter functions
////////////////////*/
/**
* @notice Sets the lists of providers of this vault.
*
* @param providers address array
*
* @dev Requirements:
* - Must not contain zero addresses.
*/
function setProviders(ILendingProvider[] memory providers) external;
/**
* @notice Sets the active provider for this vault.
*
* @param activeProvider address
*
* @dev Requirements:
* - Must be a provider previously set by `setProviders()`.
* - Must be called from a timelock contract.
*
* WARNING! Changing active provider without a `rebalance()` call
* can result in denial of service for vault users.
*/
function setActiveProvider(ILendingProvider activeProvider) external;
/**
* @notice Sets the minimum amount for: `deposit()`, `mint()` and borrow()`.
*
* @param amount to be as minimum.
*/
function setMinAmount(uint256 amount) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IVaultPermissions
*
* @author Fujidao Labs
*
* @notice Defines the interface for a vault extended with
* signed permit operations for `withdraw()` and `borrow()` allowance.
*/
interface IVaultPermissions {
/**
* @dev Emitted when `asset` withdraw allowance is set.
*
* @param owner who provides allowance
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
* @param amount of allowance given
*/
event WithdrawApproval(address indexed owner, address operator, address receiver, uint256 amount);
/**
* @dev Emitted when `debtAsset` borrow allowance is set.
*
* @param owner who provides allowance
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
* @param amount of allowance given
*/
event BorrowApproval(address indexed owner, address operator, address receiver, uint256 amount);
/// @dev Based on {IERC20Permit-DOMAIN_SEPARATOR}.
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external returns (bytes32);
/**
* @notice Returns the current amount of withdraw allowance from `owner` to `receiver` that
* can be executed by `operator`. This is similar to {IERC20-allowance} for BaseVault assets,
* instead of token-shares.
*
* @param owner who provides allowance
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
*
* @dev Requirements:
* - Must replace {IERC4626-allowance} in a vault implementation.
*/
function withdrawAllowance(
address owner,
address operator,
address receiver
)
external
view
returns (uint256);
/**
* @notice Returns the current amount of borrow allowance from `owner` to `receiver` that
* can be executed by `operator`. This is similar to {IERC20-allowance} for
* BaseVault-debtAsset.
*
* @param owner who provides allowance
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
*/
function borrowAllowance(
address owner,
address operator,
address receiver
)
external
view
returns (uint256);
/**
* @dev Atomically increases the `withdrawAllowance` granted to `receiver` and
* executable by `operator` by the caller. Based on OZ {ERC20-increaseAllowance} for assets.
*
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
* @param byAmount to increase withdraw allowance
*
* @dev Requirements:
* - Must emit a {WithdrawApproval} event indicating the updated withdraw allowance.
* - Must check `operator` and `receiver are not zero address.
*/
function increaseWithdrawAllowance(
address operator,
address receiver,
uint256 byAmount
)
external
returns (bool);
/**
* @dev Atomically decreases the `withdrawAllowance` granted to `receiver` and
* executable by `operator` by the caller. Based on OZ {ERC20-decreaseAllowance} for assets.
*
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
* @param byAmount to decrease withdraw allowance
*
* @dev Requirements:
* - Must emit a {WithdrawApproval} event indicating the updated withdraw allowance.
* - Must check `operator` and `receiver` are not zero address.
* - Must check `operator` and `receiver` have `borrowAllowance` of at least `byAmount`.
*
*/
function decreaseWithdrawAllowance(
address operator,
address receiver,
uint256 byAmount
)
external
returns (bool);
/**
* @dev Atomically increases the `borrowAllowance` granted to `receiver` and
* executable by `operator` by the caller. Based on OZ {ERC20-increaseAllowance}
* for `debtAsset`.
*
* @param operator address who can execute the use of the allowance
* @param receiver address who can spend the allowance
* @param byAmount to increase borrow allowance
*
* @dev Requirements:
* - Must emit a {BorrowApproval} event indicating the updated borrow allowance.
* - Must check `operator` and `receiver` are not zero address.
*/
function increaseBorrowAllowance(
address operator,
address receiver,
uint256 byAmount
)
external
returns (bool);
/**
* @dev Atomically decrease the `borrowAllowance` granted to `receiver` and
* executable by `operator` by the caller. Based on OZ {ERC20-decreaseAllowance}
* for `debtAsset`.
*
* @param operator who can execute the use of the allowance
* @param receiver who can spend the allowance
* @param byAmount to decrease borrow allowance
*
* Requirements:
* - Must emit a {BorrowApproval} event indicating the updated borrow allowance.
* - Must check `operator` and `receiver` are not the zero address.
* - Must check `operator` and `receiver` have `borrowAllowance` of at least `byAmount`.
*/
function decreaseBorrowAllowance(
address operator,
address receiver,
uint256 byAmount
)
external
returns (bool);
/**
* @notice Returns the curent used nonces for permits of `owner`.
* Based on OZ {IERC20Permit-nonces}.
*
* @param owner address to check nonces
*/
function nonces(address owner) external view returns (uint256);
/**
* @notice Sets `amount` as the `withdrawAllowance` of `receiver` executable by
* caller over `owner`'s tokens, given the `owner`'s signed approval.
* Inspired by {IERC20Permit-permit} for assets.
*
* @param owner providing allowance
* @param receiver who can spend the allowance
* @param amount of allowance
* @param deadline timestamp limit for the execution of signed permit
* @param actionArgsHash keccak256 of the abi.encoded(args,actions) to be performed in {BaseRouter._internalBundle}
* @param v signature value
* @param r signature value
* @param s signature value
*
* @dev Requirements:
* - Must check `deadline` is a timestamp in the future.
* - Must check `receiver` is a non-zero address.
* - Must check that `v`, `r` and `s` are valid `secp256k1` signature for `owner`
* over EIP712-formatted function arguments.
* - Must check the signature used `owner`'s current nonce (see {nonces}).
* - Must emits an {AssetsApproval} event.
*/
function permitWithdraw(
address owner,
address receiver,
uint256 amount,
uint256 deadline,
bytes32 actionArgsHash,
uint8 v,
bytes32 r,
bytes32 s
)
external;
/**
* @notice Sets `amount` as the `borrowAllowance` of `receiver` executable by caller over
* `owner`'s borrowing powwer, given the `owner`'s signed approval.
* Inspired by {IERC20Permit-permit} for debt.
*
* @param owner address providing allowance
* @param receiver address who can spend the allowance
* @param amount of allowance
* @param deadline timestamp limit for the execution of signed permit
* @param actionArgsHash keccak256 of the abi.encoded(args,actions) to be performed in {BaseRouter._internalBundle}
* @param v signature value
* @param r signature value
* @param s signature value
*
* @dev Requirements:
* - Must emit a {BorrowApproval} event.
* - Must be implemented in a {BorrowingVault}.
* - Must check `deadline` is a timestamp in the future.
* - Must check `receiver` is a non-zero address.
* - Must check that `v`, `r` and `s` are valid `secp256k1` signature for `owner`.
* over EIP712-formatted function arguments.
* - Must check the signature used `owner`'s current nonce (see {nonces}).
*/
function permitBorrow(
address owner,
address receiver,
uint256 amount,
uint256 deadline,
bytes32 actionArgsHash,
uint8 v,
bytes32 r,
bytes32 s
)
external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IChief
*
* @author Fujidao Labs
*
* @notice Defines interface for {Chief} access control operations.
*/
import {IAccessControl} from "openzeppelin-contracts/contracts/access/IAccessControl.sol";
interface IChief is IAccessControl {
/// @notice Returns the timelock address of the FujiV2 system.
function timelock() external view returns (address);
/// @notice Returns the address mapper contract address of the FujiV2 system.
function addrMapper() external view returns (address);
/**
* @notice Returns true if `vault` is active.
*
* @param vault to check status
*/
function isVaultActive(address vault) external view returns (bool);
/**
* @notice Returns true if `flasher` is an allowed {IFlasher}.
*
* @param flasher address to check
*/
function allowedFlasher(address flasher) external view returns (bool);
/**
* @notice Returns true if `swapper` is an allowed {ISwapper}.
*
* @param swapper address to check
*/
function allowedSwapper(address swapper) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title Router Interface
*
* @author Fujidao Labs
*
* @notice Define the interface for router operations.
*/
import {ERC20} from "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
interface IRouter {
/// @dev List of actions allowed to be executed by the router.
enum Action {
Deposit,
Withdraw,
Borrow,
Payback,
Flashloan,
Swap,
PermitWithdraw,
PermitBorrow,
XTransfer,
XTransferWithCall,
DepositETH,
WithdrawETH
}
/**
* @notice An entry-point function that executes encoded commands along with provided inputs.
*
* @param actions an array of actions that will be executed in a row
* @param args an array of encoded inputs needed to execute each action
*/
function xBundle(Action[] memory actions, bytes[] memory args) external payable;
/**
* @notice Similar to `xBundle(..)` but with additional arguments for flashloan.
*
* @param actions an array of actions that will be executed in a row
* @param args an array of encoded inputs needed to execute each action
* @param flashloanAsset being sent by the IFlasher
* @param amount of flashloan
*
* @dev Note this method cannot be re-entered further by another IFlasher call.
*/
function xBundleFlashloan(
Action[] memory actions,
bytes[] memory args,
address flashloanAsset,
uint256 amount
)
external
payable;
/**
* @notice Sweeps accidental ERC-20 transfers to this contract or stuck funds due to failed
* cross-chain calls (cf. ConnextRouter).
*
* @param token the address of the ERC-20 token to sweep
* @param receiver the address that will receive the swept funds
*/
function sweepToken(ERC20 token, address receiver) external;
/**
* @notice Sweeps accidental ETH transfers to this contract.
*
* @param receiver the address that will receive the swept funds
*/
function sweepETH(address receiver) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IFlasher
* @author Fujidao Labs
* @notice Defines the interface for all flashloan providers.
*/
interface IFlasher {
/**
* @notice Initiates a flashloan a this provider.
* @param asset address to be flashloaned.
* @param amount of `asset` to be flashloaned.
* @param requestor address to which flashloan will be facilitated.
* @param requestorCalldata encoded args with selector that will be OPCODE-CALL'ed to `requestor`.
* @dev To encode `params` see examples:
* • solidity:
* > abi.encodeWithSelector(contract.transferFrom.selector, from, to, amount);
* • ethersJS:
* > contract.interface.encodeFunctionData("transferFrom", [from, to, amount]);
* • foundry cast:
* > cast calldata "transferFrom(address,address,uint256)" from, to, amount
*
* Requirements:
* - MUST implement `_checkAndSetEntryPoint()`
*/
function initiateFlashloan(
address asset,
uint256 amount,
address requestor,
bytes memory requestorCalldata
)
external;
/**
* @notice Returns the address from which flashloan for `asset` is sourced.
* @param asset intended to be flashloaned.
* @dev Override at flashloan provider implementation as required.
* Some protocol implementations source flashloans from different contracts
* depending on `asset`.
*/
function getFlashloanSourceAddr(address asset) external view returns (address callAddr);
/**
* @notice Returns the expected flashloan fee for `amount`
* of this flashloan provider.
* @param asset to be flashloaned
* @param amount of flashloan
*/
function computeFlashloanFee(address asset, uint256 amount) external view returns (uint256 fee);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/*
* @title LibBytes
* @author Gonçalo Sá <goncalo.sa@consensys.net>
*
* @notice Utility library for ethereum contracts written in Solidity.
* The library lets you concatenate, slice and type cast bytes arrays
* both in memory and storage. Taken from:
* https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol.
*/
library LibBytes {
function concat(
bytes memory _preBytes,
bytes memory _postBytes
)
internal
pure
returns (bytes memory)
{
bytes memory tempBytes;
assembly {
/**
* @dev Get a location of some free memory and store it in tempBytes as
* Solidity does for memory variables.
*/
tempBytes := mload(0x40)
/**
* @dev Store the length of the first bytes array at the beginning of
* the memory for tempBytes.
*/
let length := mload(_preBytes)
mstore(tempBytes, length)
/**
* @dev Maintain a memory counter for the current write location in the
* temp bytes array by adding the 32 bytes for the array length to
* the starting location.
*/
let mc := add(tempBytes, 0x20)
// Stop copying when the memory counter reaches the length of the first bytes array.
let end := add(mc, length)
for {
// Initialize a copy counter to the start of the _preBytes data, 32 bytes into its memory.
let cc := add(_preBytes, 0x20)
} lt(mc, end) {
// Increase both counters by 32 bytes each iteration.
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
// Write the _preBytes data into the tempBytes memory 32 bytes at a time.
mstore(mc, mload(cc))
}
/**
* @dev Add the length of _postBytes to the current length of tempBytes
* and store it as the new length in the first 32 bytes of the
* tempBytes memory.
*/
length := mload(_postBytes)
mstore(tempBytes, add(length, mload(tempBytes)))
// Move the memory counter back from a multiple of 0x20 to the actual end of the _preBytes data.
mc := end
// Stop copying when the memory counter reaches the new combined length of the arrays.
end := add(mc, length)
for { let cc := add(_postBytes, 0x20) } lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} { mstore(mc, mload(cc)) }
/**
* @dev Update the free-memory pointer by padding our last write location
* to 32 bytes: add 31 bytes to the end of tempBytes to move to the
* next 32 byte block, then round down to the nearest multiple of
* 32. If the sum of the length of the two arrays is zero then add
* one before rounding down to leave a blank 32 bytes (the length block with 0).
*/
mstore(
0x40,
and(
add(add(end, iszero(add(length, mload(_preBytes)))), 31),
// Round down to the nearest 32 bytes.
not(31)
)
)
}
return tempBytes;
}
function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
assembly {
/**
* @dev Read the first 32 bytes of _preBytes storage, which is the length
* of the array. (We don't need to use the offset into the slot
* because arrays use the entire slot.)
*/
let fslot := sload(_preBytes.slot)
/**
* @dev Arrays of 31 bytes or less have an even value in their slot,
* while longer arrays have an odd value. The actual length is
* the slot divided by two for odd values, and the lowest order
* byte divided by two for even values.
* If the slot is even, bitwise and the slot with 255 and divide by
* two to get the length. If the slot is odd, bitwise and the slot
* with -1 and divide by two.
*/
let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
let mlength := mload(_postBytes)
let newlength := add(slength, mlength)
/**
* @dev // slength can contain both the length and contents of the array
* if length < 32 bytes so let's prepare for that
* v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
*/
switch add(lt(slength, 32), lt(newlength, 32))
case 2 {
/**
* @dev Since the new array still fits in the slot, we just need to
* update the contents of the slot.
* uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
*/
sstore(
_preBytes.slot,
// All the modifications to the slot are inside this next block
add(
// we can just add to the slot contents because the bytes we want to change are the LSBs
fslot,
add(
mul(
div(
// load the bytes from memory.
mload(add(_postBytes, 0x20)),
// Zero all bytes to the right.
exp(0x100, sub(32, mlength))
),
// Now shift left the number of bytes to leave space for the length in the slot.
exp(0x100, sub(32, newlength))
),
// Increase length by the double of the memory bytes length.
mul(mlength, 2)
)
)
)
}
case 1 {
/**
* @dev The stored value fits in the slot, but the combined value
* will exceed it. Get the keccak hash to get the contents of the array.
*/
mstore(0x0, _preBytes.slot)
let sc := add(keccak256(0x0, 0x20), div(slength, 32))
// Save new length.
sstore(_preBytes.slot, add(mul(newlength, 2), 1))
/**
* @dev The contents of the _postBytes array start 32 bytes into
* the structure. Our first read should obtain the `submod`
* bytes that can fit into the unused space in the last word
* of the stored array. To get this, we read 32 bytes starting
* from `submod`, so the data we read overlaps with the array
* contents by `submod` bytes. Masking the lowest-order
* `submod` bytes allows us to add that value directly to the
* stored value.
*/
let submod := sub(32, slength)
let mc := add(_postBytes, submod)
let end := add(_postBytes, mlength)
let mask := sub(exp(0x100, submod), 1)
sstore(
sc,
add(
and(fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00),
and(mload(mc), mask)
)
)
for {
mc := add(mc, 0x20)
sc := add(sc, 1)
} lt(mc, end) {
sc := add(sc, 1)
mc := add(mc, 0x20)
} { sstore(sc, mload(mc)) }
mask := exp(0x100, sub(mc, end))
sstore(sc, mul(div(mload(mc), mask), mask))
}
default {
// Get the keccak hash to get the contents of the array.
mstore(0x0, _preBytes.slot)
// Start copying to the last used word of the stored array.
let sc := add(keccak256(0x0, 0x20), div(slength, 32))
// Save new length.
sstore(_preBytes.slot, add(mul(newlength, 2), 1))
// Copy over the first `submod` bytes of the new data as in case 1 above.
let slengthmod := mod(slength, 32)
let mlengthmod := mod(mlength, 32)
let submod := sub(32, slengthmod)
let mc := add(_postBytes, submod)
let end := add(_postBytes, mlength)
let mask := sub(exp(0x100, submod), 1)
sstore(sc, add(sload(sc), and(mload(mc), mask)))
for {
sc := add(sc, 1)
mc := add(mc, 0x20)
} lt(mc, end) {
sc := add(sc, 1)
mc := add(mc, 0x20)
} { sstore(sc, mload(mc)) }
mask := exp(0x100, sub(mc, end))
sstore(sc, mul(div(mload(mc), mask), mask))
}
}
}
function slice(
bytes memory _bytes,
uint256 _start,
uint256 _length
)
internal
pure
returns (bytes memory)
{
require(_length + 31 >= _length, "slice_overflow");
require(_bytes.length >= _start + _length, "slice_outOfBounds");
bytes memory tempBytes;
assembly {
switch iszero(_length)
case 0 {
// Get a location of some free memory and store it in tempBytes as Solidity does for memory variables.
tempBytes := mload(0x40)
/**
* @dev The first word of the slice result is potentially a partial
* word read from the original array. To read it, we calculate
* the length of that partial word and start copying that many
* bytes into the array. The first word we copy will start with
* data we don't care about, but the last `lengthmod` bytes will
* land at the beginning of the contents of the new array. When
* we're done copying, we overwrite the full first word with
* the actual length of the slice.
*/
let lengthmod := and(_length, 31)
/**
* @dev The multiplication in the next line is necessary
* because when slicing multiples of 32 bytes (lengthmod == 0)
* the following copy loop was copying the origin's length
* and then ending prematurely not copying everything it should.
*/
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
let end := add(mc, _length)
for {
// The multiplication in the next line has the same exact purpose as the one above.
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} { mstore(mc, mload(cc)) }
mstore(tempBytes, _length)
// Update free-memory pointer allocating the array padded to 32 bytes like the compiler does now.
mstore(0x40, and(add(mc, 31), not(31)))
}
// If we want a zero-length slice let's just return a zero-length array.
default {
tempBytes := mload(0x40)
// Zero out the 32 bytes slice we are about to return we need to do it because Solidity does not garbage collect
mstore(tempBytes, 0)
mstore(0x40, add(tempBytes, 0x20))
}
}
return tempBytes;
}
function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
address tempAddress;
assembly {
tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
}
return tempAddress;
}
function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
require(_bytes.length >= _start + 1, "toUint8_outOfBounds");
uint8 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x1), _start))
}
return tempUint;
}
function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
uint16 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x2), _start))
}
return tempUint;
}
function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
uint32 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x4), _start))
}
return tempUint;
}
function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
uint64 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x8), _start))
}
return tempUint;
}
function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
uint96 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0xc), _start))
}
return tempUint;
}
function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
uint128 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x10), _start))
}
return tempUint;
}
function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
uint256 tempUint;
assembly {
tempUint := mload(add(add(_bytes, 0x20), _start))
}
return tempUint;
}
function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
bytes32 tempBytes32;
assembly {
tempBytes32 := mload(add(add(_bytes, 0x20), _start))
}
return tempBytes32;
}
function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
bool success = true;
assembly {
let length := mload(_preBytes)
// If lengths don't match the arrays are not equal
switch eq(length, mload(_postBytes))
case 1 {
/**
* @dev cb is a circuit breaker in the for loop since there's
* no said feature for inline assembly loops
* cb = 1 - don't breaker
* cb = 0 - break
*/
let cb := 1
let mc := add(_preBytes, 0x20)
let end := add(mc, length)
for { let cc := add(_postBytes, 0x20) }
// The next line is the loop condition: while(uint256(mc < end) + cb == 2).
eq(add(lt(mc, end), cb), 2) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
// If any of these checks fails then arrays are not equal.
if iszero(eq(mload(mc), mload(cc))) {
// Unsuccess:
success := 0
cb := 0
}
}
}
default {
// Unsuccess:
success := 0
}
}
return success;
}
function equalStorage(
bytes storage _preBytes,
bytes memory _postBytes
)
internal
view
returns (bool)
{
bool success = true;
assembly {
// We know _preBytes_offset is 0.
let fslot := sload(_preBytes.slot)
// Decode the length of the stored array like in concatStorage().
let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
let mlength := mload(_postBytes)
// If lengths don't match the arrays are not equal.
switch eq(slength, mlength)
case 1 {
/**
* @dev Slength can contain both the length and contents of the array
* if length < 32 bytes so let's prepare for that
* v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
*/
if iszero(iszero(slength)) {
switch lt(slength, 32)
case 1 {
// Blank the last byte which is the length.
fslot := mul(div(fslot, 0x100), 0x100)
if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
// Unsuccess:
success := 0
}
}
default {
/**
* @dev cb is a circuit breaker in the for loop since there's
* no said feature for inline assembly loops
* cb = 1 - don't breaker
* cb = 0 - break
*/
let cb := 1
// Get the keccak hash to get the contents of the array.
mstore(0x0, _preBytes.slot)
let sc := keccak256(0x0, 0x20)
let mc := add(_postBytes, 0x20)
let end := add(mc, mlength)
// The next line is the loop condition: while(uint256(mc < end) + cb == 2)
for {} eq(add(lt(mc, end), cb), 2) {
sc := add(sc, 1)
mc := add(mc, 0x20)
} {
if iszero(eq(sload(sc), mload(mc))) {
// Unsuccess:
success := 0
cb := 0
}
}
}
}
}
default {
// Unsuccess:
success := 0
}
}
return success;
}
}// 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);
}// 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);
}// 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);
}
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title ISwapper
*
* @author Fujidao Labs
*
* @notice Defines the interface for routers to perform token swaps with DEX protocols.
*
* @dev Implementation inheriting this interface should be permisionless.
*/
interface ISwapper {
/**
* @notice Swap tokens at exchange.
*
* @param assetIn address of the ERC-20 token to swap from
* @param assetOut address of the ERC-20 token to swap to
* @param amountIn that will be pulled from msg.sender
* @param amountOut of `assetOut` expected after the swap
* @param receiver of the `amountOut` tokens
* @param sweeper who receives the leftovers `assetIn` tokens after swap
* @param minSweepOut amount of `assetIn` leftover expected after swap
*
* @dev Slippage is controlled through `minSweepOut`. If `minSweepOut` is 0,
* the slippage check gets skipped.
*/
function swap(
address assetIn,
address assetOut,
uint256 amountIn,
uint256 amountOut,
address receiver,
address sweeper,
uint256 minSweepOut
)
external;
/**
* @notice Estimate the amount of `assetIn` required for `swap()`.
*
* @param assetIn address of the ERC-20 token to swap from
* @param assetOut address of the ERC-20 token to swap to
* @param amountOut expected amount of `assetOut` after the swap
*/
function getAmountIn(
address assetIn,
address assetOut,
uint256 amountOut
)
external
view
returns (uint256 amountIn);
/**
* @notice Estimate the amount of `assetOut` received after swap
*
* @param assetIn address of the ERC-20 token to swap from
* @param assetOut address of the ERC-20 token to swap to
* @param amountIn of `assetIn` to perform swap
*/
function getAmountOut(
address assetIn,
address assetOut,
uint256 amountIn
)
external
view
returns (uint256 amountOut);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.0;
import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/
contract ERC20 is Context, IERC20, IERC20Metadata {
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual override returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual override returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address to, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual override returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 amount) public virtual override returns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/
function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
return true;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/
function _transfer(address from, address to, uint256 amount) internal virtual {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 amount) internal virtual {
require(account != address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 amount) internal virtual {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title SystemAccessControl
*
* @author Fujidao Labs
*
* @notice Abstract contract that should be inherited by contract implementations that
* call the {Chief} contract for access control checks.
*/
import {IChief} from "../interfaces/IChief.sol";
import {CoreRoles} from "./CoreRoles.sol";
contract SystemAccessControl is CoreRoles {
/// @dev Custom Errors
error SystemAccessControl__hasRole_missingRole(address caller, bytes32 role);
error SystemAccessControl__onlyTimelock_callerIsNotTimelock();
error SystemAccessControl__onlyHouseKeeper_notHouseKeeper();
IChief public chief;
/**
* @dev Modifier that checks `caller` has `role`.
*/
modifier hasRole(address caller, bytes32 role) {
if (!chief.hasRole(role, caller)) {
revert SystemAccessControl__hasRole_missingRole(caller, role);
}
_;
}
/**
* @dev Modifier that checks `msg.sender` has HOUSE_KEEPER_ROLE.
*/
modifier onlyHouseKeeper() {
if (!chief.hasRole(HOUSE_KEEPER_ROLE, msg.sender)) {
revert SystemAccessControl__onlyHouseKeeper_notHouseKeeper();
}
_;
}
/**
* @dev Modifier that checks `msg.sender` is the defined `timelock` in {Chief}
* contract.
*/
modifier onlyTimelock() {
if (msg.sender != chief.timelock()) {
revert SystemAccessControl__onlyTimelock_callerIsNotTimelock();
}
_;
}
/**
* @notice Init of a new {SystemAccessControl}.
*
* @param chief_ address
*
* @dev Requirements:
* - Must pass non-zero {Chief} address, that could be checked at child contract.
*/
function __SystemAccessControl_init(address chief_) internal {
chief = IChief(chief_);
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title ReentrancyGuard
*
* @author Fujidao Labs
*
* @notice This contract implementats a slight modified version of ReentrancyGuard in
* OpenZeppelin Contracts (v4.9.0) (security/ReentrancyGuard.sol).
*
* @dev Changes include:
* - Definition of error `ReentrancyGuard_reentrantCall()`.
* - Constants `_NOT_ENTERED` and `_ENTERED` are declared as 'internal'.
* - Usage of revert error statement in `_nonReentrantBefore()`. *
*/
abstract contract ReentrancyGuard {
/// Custom Errors
error ReentrancyGuard_reentrantCall();
// 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 internal constant _NOT_ENTERED = 1;
uint256 internal constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
if (_status == _ENTERED) {
revert ReentrancyGuard_reentrantCall();
}
// 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: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC4626.sol)
pragma solidity ^0.8.0;
import "../token/ERC20/IERC20.sol";
import "../token/ERC20/extensions/IERC20Metadata.sol";
/**
* @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in
* https://eips.ethereum.org/EIPS/eip-4626[ERC-4626].
*
* _Available since v4.7._
*/
interface IERC4626 is IERC20, IERC20Metadata {
event Deposit(address indexed sender, address indexed owner, uint256 assets, uint256 shares);
event Withdraw(
address indexed sender,
address indexed receiver,
address indexed owner,
uint256 assets,
uint256 shares
);
/**
* @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing.
*
* - MUST be an ERC-20 token contract.
* - MUST NOT revert.
*/
function asset() external view returns (address assetTokenAddress);
/**
* @dev Returns the total amount of the underlying asset that is “managed” by Vault.
*
* - SHOULD include any compounding that occurs from yield.
* - MUST be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT revert.
*/
function totalAssets() external view returns (uint256 totalManagedAssets);
/**
* @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToShares(uint256 assets) external view returns (uint256 shares);
/**
* @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal
* scenario where all the conditions are met.
*
* - MUST NOT be inclusive of any fees that are charged against assets in the Vault.
* - MUST NOT show any variations depending on the caller.
* - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange.
* - MUST NOT revert.
*
* NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the
* “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and
* from.
*/
function convertToAssets(uint256 shares) external view returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver,
* through a deposit call.
*
* - MUST return a limited value if receiver is subject to some deposit limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited.
* - MUST NOT revert.
*/
function maxDeposit(address receiver) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit
* call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called
* in the same transaction.
* - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the
* deposit would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewDeposit(uint256 assets) external view returns (uint256 shares);
/**
* @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* deposit execution, and are accounted for during deposit.
* - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function deposit(uint256 assets, address receiver) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call.
* - MUST return a limited value if receiver is subject to some mint limit.
* - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted.
* - MUST NOT revert.
*/
function maxMint(address receiver) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given
* current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call
* in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the
* same transaction.
* - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint
* would be accepted, regardless if the user has enough tokens approved, etc.
* - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by minting.
*/
function previewMint(uint256 shares) external view returns (uint256 assets);
/**
* @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens.
*
* - MUST emit the Deposit event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint
* execution, and are accounted for during mint.
* - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not
* approving enough underlying tokens to the Vault contract, etc).
*
* NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token.
*/
function mint(uint256 shares, address receiver) external returns (uint256 assets);
/**
* @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the
* Vault, through a withdraw call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxWithdraw(address owner) external view returns (uint256 maxAssets);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw
* call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if
* called
* in the same transaction.
* - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though
* the withdrawal would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by depositing.
*/
function previewWithdraw(uint256 assets) external view returns (uint256 shares);
/**
* @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* withdraw execution, and are accounted for during withdraw.
* - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares);
/**
* @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault,
* through a redeem call.
*
* - MUST return a limited value if owner is subject to some withdrawal limit or timelock.
* - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock.
* - MUST NOT revert.
*/
function maxRedeem(address owner) external view returns (uint256 maxShares);
/**
* @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block,
* given current on-chain conditions.
*
* - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call
* in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the
* same transaction.
* - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the
* redemption would be accepted, regardless if the user has enough shares, etc.
* - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees.
* - MUST NOT revert.
*
* NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in
* share price or some other type of condition, meaning the depositor will lose assets by redeeming.
*/
function previewRedeem(uint256 shares) external view returns (uint256 assets);
/**
* @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver.
*
* - MUST emit the Withdraw event.
* - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the
* redeem execution, and are accounted for during redeem.
* - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner
* not having enough shares, etc).
*
* NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed.
* Those methods should be performed separately.
*/
function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
import {IVault} from "./IVault.sol";
/**
* @title ILendingProvider
*
* @author Fujidao Labs
*
* @notice Defines the interface for core engine to perform operations at lending providers.
*
* @dev Functions are intended to be called in the context of a Vault via delegateCall,
* except indicated.
*/
interface ILendingProvider {
function providerName() external view returns (string memory);
/**
* @notice Returns the operator address that requires ERC20-approval for vault operations.
*
* @param keyAsset address to inquiry operator
* @param asset address of the calling vault
* @param debtAsset address of the calling vault. Note: if {YieldVault} this will be address(0).
*
* @dev Provider implementations may or not require all 3 inputs.
*/
function approvedOperator(
address keyAsset,
address asset,
address debtAsset
)
external
view
returns (address operator);
/**
* @notice Performs deposit operation at lending provider on behalf vault.
*
* @param amount amount to deposit
* @param vault IVault calling this function
*
* @dev Requirements:
* - This function should be delegate called in the context of a `vault`.
*/
function deposit(uint256 amount, IVault vault) external returns (bool success);
/**
* @notice Performs borrow operation at lending provider on behalf vault.
*
* @param amount amount to borrow
* @param vault IVault calling this function
*
* @dev Requirements:
* - This function should be delegate called in the context of a `vault`.
*/
function borrow(uint256 amount, IVault vault) external returns (bool success);
/**
* @notice Performs withdraw operation at lending provider on behalf vault.
* @param amount amount to withdraw
* @param vault IVault calling this function.
*
* @dev Requirements:
* - This function should be delegate called in the context of a `vault`.
*/
function withdraw(uint256 amount, IVault vault) external returns (bool success);
/**
*
* @notice Performs payback operation at lending provider on behalf vault.
*
* @param amount amount to payback
* @param vault IVault calling this function.
*
* @dev Requirements:
* - This function should be delegate called in the context of a `vault`.
* - Check there is erc20-approval to `approvedOperator` by the `vault` prior to call.
*/
function payback(uint256 amount, IVault vault) external returns (bool success);
/**
* @notice Returns DEPOSIT balance of 'user' at lending provider.
*
* @param user address whom balance is needed
* @param vault IVault required by some specific providers with multi-markets, otherwise pass address(0).
*
* @dev Requirements:
* - Must not require Vault context.
*/
function getDepositBalance(address user, IVault vault) external view returns (uint256 balance);
/**
* @notice Returns BORROW balance of 'user' at lending provider.
*
* @param user address whom balance is needed
* @param vault IVault required by some specific providers with multi-markets, otherwise pass address(0).
*
* @dev Requirements:
* - Must not require Vault context.
*/
function getBorrowBalance(address user, IVault vault) external view returns (uint256 balance);
/**
* @notice Returns the latest SUPPLY annual percent rate (APR) at lending provider.
*
* @param vault IVault required by some specific providers with multi-markets, otherwise pass address(0)
*
* @dev Requirements:
* - Must return the rate in ray units (1e27)
* Example 8.5% APR = 0.085 x 1e27 = 85000000000000000000000000
* - Must not require Vault context.
*/
function getDepositRateFor(IVault vault) external view returns (uint256 rate);
/**
* @notice Returns the latest BORROW annual percent rate (APR) at lending provider.
*
* @param vault IVault required by some specific providers with multi-markets, otherwise pass address(0)
*
* @dev Requirements:
* - Must return the rate in ray units (1e27)
* Example 8.5% APR = 0.085 x 1e27 = 85000000000000000000000000
* - Must not require Vault context.
*/
function getBorrowRateFor(IVault vault) external view returns (uint256 rate);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title IFujiOracle
*
* @author Fujidao Labs
*
* @notice Defines the interface of the {FujiOracle}.
*/
interface IFujiOracle {
/**
* @dev Emit when a change in price feed address is done for an `asset`.
*
* @param asset address
* @param newPriceFeedAddress that returns USD price from Chainlink
*/
event AssetPriceFeedChanged(address asset, address newPriceFeedAddress);
/**
* @notice Returns the exchange rate between two assets, with price oracle given in
* specified `decimals`.
*
* @param currencyAsset to be used, zero-address for USD
* @param commodityAsset to be used, zero-address for USD
* @param decimals of the desired price output
*
* @dev Price format is defined as: (amount of currencyAsset per unit of commodityAsset Exchange Rate).
* Requirements:
* - Must check that both `currencyAsset` and `commodityAsset` are set in
* usdPriceFeeds, otherwise return zero.
*/
function getPriceOf(
address currencyAsset,
address commodityAsset,
uint8 decimals
)
external
view
returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/
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 v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.15;
/**
* @title CoreRoles
*
* @author Fujidao Labs
*
* @notice System definition of roles used across FujiV2 contracts.
*/
contract CoreRoles {
bytes32 public constant HOUSE_KEEPER_ROLE = keccak256("HOUSE_KEEPER_ROLE");
bytes32 public constant REBALANCER_ROLE = keccak256("REBALANCER_ROLE");
bytes32 public constant HARVESTER_ROLE = keccak256("HARVESTER_ROLE");
bytes32 public constant LIQUIDATOR_ROLE = keccak256("LIQUIDATOR_ROLE");
bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
bytes32 public constant UNPAUSER_ROLE = keccak256("UNPAUSER_ROLE");
}{
"remappings": [
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@std/=lib/forge-std/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"nxtp/=lib/nxtp/packages/deployments/contracts/contracts/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/openzeppelin-contracts/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs"
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "london",
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IWETH9","name":"weth","type":"address"},{"internalType":"contract IConnext","name":"connext_","type":"address"},{"internalType":"contract IChief","name":"chief","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BaseRouter__allowCaller_noAllowChange","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_flashloanInvalidRequestor","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_noBalanceChange","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_notAllowedSwapper","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_notBeneficiary","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_notFirstAction","type":"error"},{"inputs":[],"name":"BaseRouter__bundleInternal_paramsMismatch","type":"error"},{"inputs":[],"name":"BaseRouter__checkIfAddressZero_invalidZeroAddress","type":"error"},{"inputs":[],"name":"BaseRouter__checkValidFlasher_notAllowedFlasher","type":"error"},{"inputs":[],"name":"BaseRouter__checkVaultInput_notActiveVault","type":"error"},{"inputs":[],"name":"BaseRouter__fallback_notAllowed","type":"error"},{"inputs":[],"name":"BaseRouter__handlePermit_notPermitAction","type":"error"},{"inputs":[],"name":"BaseRouter__isInTokenList_snapshotLimitReached","type":"error"},{"inputs":[],"name":"BaseRouter__receive_senderNotWETH","type":"error"},{"inputs":[],"name":"BaseRouter__safeTransferETH_transferFailed","type":"error"},{"inputs":[],"name":"BaseRouter__xBundleFlashloan_insufficientFlashloanBalance","type":"error"},{"inputs":[],"name":"ConnextRouter__crossTransfer_checkReceiver","type":"error"},{"inputs":[],"name":"ConnextRouter__setRouter_invalidInput","type":"error"},{"inputs":[],"name":"ConnextRouter__xReceive_notAllowedCaller","type":"error"},{"inputs":[],"name":"ConnextRouter__xReceiver_noValueTransferUseXbundle","type":"error"},{"inputs":[],"name":"ConnnextRouter__xBundleConnext_notSelfCalled","type":"error"},{"inputs":[],"name":"ReentrancyGuard_reentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"SystemAccessControl__hasRole_missingRole","type":"error"},{"inputs":[],"name":"SystemAccessControl__onlyHouseKeeper_notHouseKeeper","type":"error"},{"inputs":[],"name":"SystemAccessControl__onlyTimelock_callerIsNotTimelock","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"caller","type":"address"},{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"AllowCaller","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"},{"indexed":true,"internalType":"uint256","name":"domain","type":"uint256"}],"name":"NewConnextReceiver","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transferId","type":"bytes32"},{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"destDomain","type":"uint256"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"callData","type":"bytes"}],"name":"XCalled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transferId","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"originDomain","type":"uint256"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"callData","type":"bytes"}],"name":"XReceived","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"HARVESTER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HOUSE_KEEPER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LIQUIDATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REBALANCER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNPAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"bool","name":"allowed","type":"bool"}],"name":"allowCaller","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"transferId","type":"bytes32"}],"name":"bumpTransfer","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"chief","outputs":[{"internalType":"contract IChief","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"connext","outputs":[{"internalType":"contract IConnext","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"connextReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"handler","outputs":[{"internalType":"contract ConnextHandler","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAllowedCaller","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"receiverByDomain","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"domain","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"setReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"sweepETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"token","type":"address"},{"internalType":"address","name":"receiver","type":"address"}],"name":"sweepToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IRouter.Action[]","name":"actions","type":"uint8[]"},{"internalType":"bytes[]","name":"args","type":"bytes[]"}],"name":"xBundle","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"enum IRouter.Action[]","name":"actions","type":"uint8[]"},{"internalType":"bytes[]","name":"args","type":"bytes[]"},{"internalType":"uint256","name":"beforeSlipped","type":"uint256"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"}],"internalType":"struct BaseRouter.Snapshot","name":"tokenToCheck_","type":"tuple"}],"name":"xBundleConnext","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"enum IRouter.Action[]","name":"actions","type":"uint8[]"},{"internalType":"bytes[]","name":"args","type":"bytes[]"},{"internalType":"address","name":"flashloanAsset","type":"address"},{"internalType":"uint256","name":"flashAmount","type":"uint256"}],"name":"xBundleFlashloan","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"transferId","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"originSender","type":"address"},{"internalType":"uint32","name":"originDomain","type":"uint32"},{"internalType":"bytes","name":"callData","type":"bytes"}],"name":"xReceive","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
6101006040523480156200001257600080fd5b506040516200729a3803806200729a833981016040819052620000359162000225565b6001600081905580546001600160a01b0319166001600160a01b038316179055826001600160a01b039081166080526001600255821660a05260405130906200007e90620001f3565b6001600160a01b039091168152602001604051809103906000f080158015620000ab573d6000803e3d6000fd5b506001600160a01b031660e0526040513090620000c89062000201565b6001600160a01b039091168152602001604051809103906000f080158015620000f5573d6000803e3d6000fd5b506001600160a01b031660c0526200010f33600162000118565b50505062000279565b6200012382620001c8565b6001600160a01b03821660009081526003602052604090205481151560ff90911615150362000165576040516332fe3f1960e21b815260040160405180910390fd5b6001600160a01b038216600081815260036020908152604091829020805460ff19168515159081179091558251938452908301527f6bf208b256dacdc89831fd5124ada2aa0f56252c178dd5aff85ee68daf0a7f1c910160405180910390a15050565b6001600160a01b038116620001f05760405163bb26626360e01b815260040160405180910390fd5b50565b6109368062004e6483390190565b611b00806200579a83390190565b6001600160a01b0381168114620001f057600080fd5b6000806000606084860312156200023b57600080fd5b835162000248816200020f565b60208501519093506200025b816200020f565b60408501519092506200026e816200020f565b809150509250925092565b60805160a05160c05160e051614b4f620003156000396000818161037e01528181610bd10152610cba01526000818161042501528181610dac0152610de80152600081816104590152818161063601528181612a9f01528181612b1e01528181612c880152612cb1015260008181610149015281816102820152818161195b0152818161198601528181611a670152611aa20152614b4f6000f3fe6080604052600436106101395760003560e01c8063a495566d116100ab578063de4b05481161006f578063de4b054814610447578063e63ab1e91461047b578063f4200a14146104af578063fb1bb9de146104e3578063fd614f4114610517578063ffd864d31461054457610189565b8063a495566d1461036c578063a6801258146103a0578063b80d0586146103e0578063b8342a3414610400578063c80916d41461041357610189565b80634aa4a4fc116100fd5780634aa4a4fc14610270578063580ff61d146102bc5780636127d048146102cf57806363a560ec146103055780637270bdb014610339578063a3fb20f41461035957610189565b80631163b2b0146101a257806316d8887a146101c25780632424401f14610209578063258836fe1461021c578063490b48f81461023c57610189565b3661018957336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610187576040516372643aad60e01b815260040160405180910390fd5b005b60405163c6a579c760e01b815260040160405180910390fd5b3480156101ae57600080fd5b506101876101bd366004613c7e565b610564565b3480156101ce57600080fd5b506101f67f5e17fc5225d4a099df75359ce1f405503ca79498a8dc46a7d583235a0ee45c1681565b6040519081526020015b60405180910390f35b610187610217366004613ca2565b610620565b34801561022857600080fd5b50610187610237366004613cbb565b61069f565b34801561024857600080fd5b506101f67fccc64574297998b6c3edf6078cc5e01268465ff116954e3af02ff3a70a730f4681565b34801561027c57600080fd5b506102a47f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610200565b6101876102ca366004613d7e565b6107e2565b3480156102db57600080fd5b506102a46102ea366004613ca2565b6004602052600090815260409020546001600160a01b031681565b34801561031157600080fd5b506101f67f3fc733b4d20d27a28452ddf0e9351aced28242fe03389a653cdb783955316b9b81565b34801561034557600080fd5b50610187610354366004613e5a565b61084c565b610187610367366004613e88565b6108fe565b34801561037857600080fd5b506102a47f000000000000000000000000000000000000000000000000000000000000000081565b3480156103ac57600080fd5b506103d06103bb366004613c7e565b60036020526000908152604090205460ff1681565b6040519015158152602001610200565b3480156103ec57600080fd5b506101876103fb366004613ef3565b610980565b61018761040e366004613f18565b610a87565b34801561041f57600080fd5b506102a47f000000000000000000000000000000000000000000000000000000000000000081565b34801561045357600080fd5b506102a47f000000000000000000000000000000000000000000000000000000000000000081565b34801561048757600080fd5b506101f67f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b3480156104bb57600080fd5b506101f67fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab81565b3480156104ef57600080fd5b506101f67f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a81565b34801561052357600080fd5b50610537610532366004614020565b610bc4565b6040516102009190614107565b34801561055057600080fd5b506001546102a4906001600160a01b031681565b600154604051632474521560e21b81527fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab60048201523360248201526001600160a01b03909116906391d1485490604401602060405180830381865afa1580156105d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f6919061411a565b61061357604051639c73fc7f60e01b815260040160405180910390fd5b61061d8147610f0b565b50565b604051632424401f60e01b8152600481018290527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632424401f9034906024016000604051808303818588803b15801561068357600080fd5b505af1158015610697573d6000803e3d6000fd5b505050505050565b600154604051632474521560e21b81527fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab60048201523360248201526001600160a01b03909116906391d1485490604401602060405180830381865afa15801561070d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610731919061411a565b61074e57604051639c73fc7f60e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610795573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b99190614137565b9050806000036107c857505050565b6107dc6001600160a01b0384168383610fae565b505b5050565b33301461080257604051633228cc7160e21b815260040160405180910390fd5b6106978686808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506108459250879150889050614173565b8484611011565b600160009054906101000a90046001600160a01b03166001600160a01b031663d33219b46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c391906141e6565b6001600160a01b0316336001600160a01b0316146108f45760405163b909292960e01b815260040160405180910390fd5b6107de8282611b36565b610906611be3565b6109708484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506109499250859150869050614173565b6000604051806040016040528060006001600160a01b031681526020016000815250611011565b61097a6001600055565b50505050565b600160009054906101000a90046001600160a01b03166001600160a01b031663d33219b46040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f791906141e6565b6001600160a01b0316336001600160a01b031614610a285760405163b909292960e01b815260040160405180910390fd5b610a3181611c0d565b60008281526004602052604080822080546001600160a01b0319166001600160a01b038516908117909155905184927f9bd7d4d7594aad109cd154387aa65eb873afbb3189646cff5cc066e8160ea90291a35050565b610a9033611c34565b6002805403610ab25760405163590dc0d160e11b815260040160405180910390fd5b600280556040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610afd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b219190614137565b905081811015610b4457604051632028a34d60e01b815260040160405180910390fd5b610bb6878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250610b879250889150899050614173565b60006040518060400160405280886001600160a01b031681526020018787610baf9190614219565b9052611011565b505060016002555050505050565b6060336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610c0f576040516305d1b38f60e01b815260040160405180910390fd5b60008083806020019051810190610c269190614368565b6040805180820182526001600160a01b038b1680825291516370a0823160e01b81523060048201529395509193506000926020830191906370a0823190602401602060405180830381865afa158015610c83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca79190614137565b90529050610ce06001600160a01b0389167f0000000000000000000000000000000000000000000000000000000000000000308c611cbf565b6000610d218a85600081518110610cf957610cf96143cb565b602002602001015185600081518110610d1457610d146143cb565b6020026020010151611cf7565b84600081518110610d3457610d346143cb565b602090810291909101019190915260405163580ff61d60e01b8152909150309063580ff61d90610d6e9087908790869088906004016144a5565b600060405180830381600087803b158015610d8857600080fd5b505af1925050508015610d99575060015b610ea657610dd16001600160a01b038a167f00000000000000000000000000000000000000000000000000000000000000008c610fae565b60405163e667df2f60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063e667df2f90610e29908e908e908e908e908e908c908c906004016144f6565b600060405180830381600087803b158015610e4357600080fd5b505af1158015610e57573d6000803e3d6000fd5b505050508663ffffffff168b7f62277c9bd483b2bd832cf3849e52ec0a2b1e4297f133ccb28e963239a8007f5a60008c8e8b604051610e99949392919061455b565b60405180910390a3610eed565b8663ffffffff168b7f62277c9bd483b2bd832cf3849e52ec0a2b1e4297f133ccb28e963239a8007f5a60018c8e8b604051610ee4949392919061455b565b60405180910390a35b50506040805160208101909152600081529998505050505050505050565b80600003610f17575050565b610f2082611c0d565b604080516000808252602082019092526001600160a01b038416908390604051610f4a9190614594565b60006040518083038185875af1925050503d8060008114610f87576040519150601f19603f3d011682016040523d82523d6000602084013e610f8c565b606091505b50509050806107dc576040516322462d1f60e01b815260040160405180910390fd5b6040516001600160a01b0383166024820152604481018290526107dc90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611d20565b61104f6040518060a001604052806000815260200160006001600160a01b031681526020016000801916815260200160008152602001606081525090565b8451808252845114611074576040516305b9af8f60e51b815260040160405180910390fd5b60408051600a808252610160820190925290816020015b604080518082019091526000808252602082015281526020019060019003908161108b575050608082015281516001600160a01b0316156110ea578181608001516000815181106110de576110de6143cb565b60200260200101819052505b6110f43447614219565b606082015260005b8151811015611b1c576000868281518110611119576111196143cb565b602002602001015190506000600b811115611136576111366143e1565b81600b811115611148576111486143e1565b036112c657600080600080898681518110611165576111656143cb565b602002602001015180602001905181019061118091906145b0565b935093509350935061119184611dfa565b6000846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111f591906141e6565b9050611205886020015184611e85565b6001600160a01b031660208901526080880151611223908290611ed7565b611231858960800151611ed7565b61123c818386611f8c565b611247818686611fd4565b604051636e553f6560e01b8152600481018590526001600160a01b038481166024830152861690636e553f65906044015b6020604051808303816000875af1158015611297573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bb9190614137565b505050505050611b13565b600181600b8111156112da576112da6143e1565b03611328576000806112ee89898787611ff5565b915091508115611321578088611305866001614605565b81518110611315576113156143cb565b60200260200101819052505b5050611b13565b600281600b81111561133c5761133c6143e1565b036114a457600080600080898681518110611359576113596143cb565b602002602001015180602001905181019061137491906145b0565b935093509350935061138584611dfa565b611393876020015182611e85565b87602001906001600160a01b031690816001600160a01b03168152505061141f846001600160a01b031663a919802d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061141591906141e6565b8860800151611ed7565b604051633545906160e21b8152600481018490526001600160a01b038381166024830152828116604483015285169063d5164184906064016020604051808303816000875af1158015611476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061149a9190614137565b5050505050611b13565b600381600b8111156114b8576114b86143e1565b036115de576000806000808986815181106114d5576114d56143cb565b60200260200101518060200190518101906114f091906145b0565b935093509350935061150184611dfa565b6000846001600160a01b031663a919802d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611541573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061156591906141e6565b9050611575886020015184611e85565b6001600160a01b031660208901526080880151611593908290611ed7565b61159e818386611f8c565b6115a9818686611fd4565b60405163d084b9af60e01b8152600481018590526001600160a01b03848116602483015286169063d084b9af90604401611278565b600681600b8111156115f2576115f26143e1565b0361165f5760408301516116115761160b87878761250f565b60408401525b600061163b82888581518110611629576116296143cb565b6020026020010151866040015161283a565b905061164b846020015182611e85565b6001600160a01b0316602085015250611b13565b600781600b811115611673576116736143e1565b0361168c5760408301516116115761160b87878761250f565b600881600b8111156116a0576116a06143e1565b036116df576116cc8683815181106116ba576116ba6143cb565b60200260200101518460200151612a11565b6001600160a01b03166020840152611b13565b600981600b8111156116f3576116f36143e1565b0361171f576116cc86838151811061170d5761170d6143cb565b60200260200101518460200151612bff565b600581600b811115611733576117336143e1565b03611785578160000361175957604051631d137c1560e11b815260040160405180910390fd5b6116cc86838151811061176e5761176e6143cb565b602002602001015184602001518560800151612db9565b600481600b811115611799576117996143e1565b0361190c576000806000806000808b88815181106117b9576117b96143cb565b60200260200101518060200190518101906117d4919061461d565b9550955095509550955095506117e986611c34565b6001600160a01b03831630146118125760405163ef34858960e01b815260040160405180910390fd5b611820858a60800151611ed7565b61183789602001516118328484613003565b611e85565b6001600160a01b031660208a0152604051600090632e0d0a8d60e21b9061186890859085908a908a906024016146b6565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051631f8aa39560e21b81529091506001600160a01b03881690637e2a8e54906118ce9089908990899087906004016146f8565b600060405180830381600087803b1580156118e857600080fd5b505af11580156118fc573d6000803e3d6000fd5b5050505050505050505050611b13565b600a81600b811115611920576119206143e1565b036119f3576000868381518110611939576119396143cb565b60200260200101518060200190518101906119549190614137565b90506119847f00000000000000000000000000000000000000000000000000000000000000008560800151611ed7565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156119df57600080fd5b505af11580156112bb573d6000803e3d6000fd5b600b81600b811115611a0757611a076143e1565b03611b1357600080878481518110611a2157611a216143cb565b6020026020010151806020019051810190611a3c919061472b565b91509150611a4e856020015182611e85565b6001600160a01b031660208601526080850151611a8c907f000000000000000000000000000000000000000000000000000000000000000090611ed7565b604051632e1a7d4d60e01b8152600481018390527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611aee57600080fd5b505af1158015611b02573d6000803e3d6000fd5b50505050611b108183610f0b565b50505b506001016110fc565b50611b2f81608001518260600151613488565b5050505050565b611b3f82611c0d565b6001600160a01b03821660009081526003602052604090205481151560ff909116151503611b80576040516332fe3f1960e21b815260040160405180910390fd5b6001600160a01b038216600081815260036020908152604091829020805460ff19168515159081179091558251938452908301527f6bf208b256dacdc89831fd5124ada2aa0f56252c178dd5aff85ee68daf0a7f1c910160405180910390a15050565b600260005403611c065760405163590dc0d160e11b815260040160405180910390fd5b6002600055565b6001600160a01b03811661061d5760405163bb26626360e01b815260040160405180910390fd5b6001546040516306a33c7960e51b81526001600160a01b0383811660048301529091169063d4678f2090602401602060405180830381865afa158015611c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ca2919061411a565b61061d5760405163b448a01d60e01b815260040160405180910390fd5b6040516001600160a01b038085166024830152831660448201526064810182905261097a9085906323b872dd60e01b90608401610fda565b6060600080611d078585886135ce565b9093509050858114611d17578091505b50935093915050565b6000611d75826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138399092919063ffffffff16565b9050805160001480611d96575080806020019051810190611d96919061411a565b6107dc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b600154604051630c5aed5760e01b81526001600160a01b03838116600483015290911690630c5aed5790602401602060405180830381865afa158015611e44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e68919061411a565b61061d5760405163106f25d560e31b815260040160405180910390fd5b60006001600160a01b038316611e9c575080611ed1565b816001600160a01b0316836001600160a01b031614611ece57604051630727952560e41b815260040160405180910390fd5b50805b92915050565b600080611ee48484613850565b915091508161097a576040805180820182526001600160a01b03861680825291516370a0823160e01b8152306004820152909160208301916370a0823190602401602060405180830381865afa158015611f42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f669190614137565b815250838281518110611f7b57611f7b6143cb565b602002602001018190525050505050565b80600003611f9957505050565b6001600160a01b0382163014801590611fba57506001600160a01b03821633145b156107dc576107dc6001600160a01b038416833084611cbf565b80600003611fe157505050565b6107dc6001600160a01b0384168383613913565b60006060600080600080888781518110612011576120116143cb565b602002602001015180602001905181019061202c91906145b0565b935093509350935061203d84611dfa565b61204b886020015182611e85565b88602001906001600160a01b031690816001600160a01b0316815250506120d7846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cd91906141e6565b8960800151611ed7565b6120e5848960800151611ed7565b87516120f2886001614605565b0361219257604051632d182be560e21b8152600481018490526001600160a01b038381166024830152828116604483015285169063b460af94906064016020604051808303816000875af115801561214e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121729190614137565b506000604051806020016040528060008152509550955050505050612506565b60008a6121a0896001614605565b815181106121b0576121b06143cb565b6020026020010151905060008a8960016121ca9190614605565b815181106121da576121da6143cb565b602002602001015190508096506000600b8111156121fa576121fa6143e1565b82600b81111561220c5761220c6143e1565b14806122295750600582600b811115612227576122276143e1565b145b806122455750600882600b811115612243576122436143e1565b145b806122615750600982600b81111561225f5761225f6143e1565b145b8061227d5750600b82600b81111561227b5761227b6143e1565b145b801561229157506001600160a01b03841630145b15612483576000866001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122fa91906141e6565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa158015612344573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123689190614137565b604051632d182be560e21b8152600481018990526001600160a01b03888116602483015287811660448301529192509089169063b460af94906064016020604051808303816000875af11580156123c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123e79190614137565b506040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa15801561242f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124539190614137565b905060006124618383614219565b90508089111561247e5760019b5061247a8686836135ce565b509a505b505050505b604051632d182be560e21b8152600481018690526001600160a01b038581166024830152848116604483015287169063b460af94906064016020604051808303816000875af11580156124da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124fe9190614137565b505050505050505b94509492505050565b825160009081816001600160401b0381111561252d5761252d613d38565b60405190808252806020026020018201604052801561256057816020015b606081526020019060019003908161254b5790505b50905060005b8281101561280557858181518110612580576125806143cb565b602002602001015182828151811061259a5761259a6143cb565b60200260200101819052508060001480156125b457508415155b801561261e575060008782815181106125cf576125cf6143cb565b6020026020010151600b8111156125e8576125e86143e1565b148061261e57506003878281518110612603576126036143cb565b6020026020010151600b81111561261c5761261c6143e1565b145b156126c45760008060008085858151811061263b5761263b6143cb565b602002602001015180602001905181019061265691906145b0565b93509350935093508289146126bf57604080516001600160a01b0380871660208301529181018b90528184166060820152908216608082015260a0016040516020818303038152906040528686815181106126b3576126b36143cb565b60200260200101819052505b505050505b60068782815181106126d8576126d86143cb565b6020026020010151600b8111156126f1576126f16143e1565b14806127275750600787828151811061270c5761270c6143cb565b6020026020010151600b811115612725576127256143e1565b145b156127f357600080600080858581518110612744576127446143cb565b602002602001015180602001905181019061275f9190614750565b5050604080516001600160a01b038089166020830152808816828401528616606082015260808101859052600060a0820181905260c0820181905260e08201819052610100808301919091528251808303909101815261012090910190915295995093975091955093506127d1915050565b8686815181106127e3576127e36143cb565b6020026020010181905250505050505b806127fd816147dc565b915050612566565b5085816040516020016128199291906147f5565b60405160208183030381529060405280519060200120925050509392505050565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290528380602001905181019061288e9190614750565b60e089015260c088015260ff1660a0870152608086015260608501526001600160a01b0390811660408501529081166020840152168082526128cf90611dfa565b600685600b8111156128e3576128e36143e1565b036129795780600001516001600160a01b0316630fad31318260200151836040015184606001518560800151888760a001518860c001518960e001516040518963ffffffff1660e01b8152600401612942989796959493929190614823565b600060405180830381600087803b15801561295c57600080fd5b505af1158015612970573d6000803e3d6000fd5b50505050612a05565b600785600b81111561298d5761298d6143e1565b036129ec5780600001516001600160a01b03166396ebbc458260200151836040015184606001518560800151888760a001518860c001518960e001516040518963ffffffff1660e01b8152600401612942989796959493929190614823565b604051632f67478960e21b815260040160405180910390fd5b60200151949350505050565b600080600080600080600088806020019051810190612a30919061486a565b955095509550955095509550612a4582611c0d565b6000868152600460205260409020546001600160a01b0390811690831603612a80576040516313f7d4e360e21b815260040160405180910390fd5b6000612a8c8984611e85565b9050612a99858386611f8c565b612ac4857f000000000000000000000000000000000000000000000000000000000000000086611fd4565b6040516345560b5d60e11b815263ffffffff881660048201526001600160a01b038481166024830152868116604483015282811660648301526084820186905260a4820188905260e060c4830152600060e48301819052917f000000000000000000000000000000000000000000000000000000000000000090911690638aac16ba90610104016020604051808303816000875af1158015612b6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8e9190614137565b604080518a81526001600160a01b038981166020830152918101889052608060608201819052600090820152919250851690339083907fb7c6eb876c99dadc81a4df296037aa08e5c6be07a3765524cf8812aec701f7e49060a00160405180910390a4509998505050505050505050565b600080600080600080600088806020019051810190612c1e91906148d3565b95509550955095509550955060008082806020019051810190612c419190614368565b91509150612c538a6118328484613003565b6000898152600460205260409020549099506001600160a01b0316612c7781611c0d565b612c82878688611f8c565b612cad877f000000000000000000000000000000000000000000000000000000000000000088611fd4565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638aac16ba8b848b8f8c8f8c6040518863ffffffff1660e01b8152600401612d079796959493929190614945565b6020604051808303816000875af1158015612d26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d4a9190614137565b60008b815260046020526040908190205490519192506001600160a01b031690339083907fb7c6eb876c99dadc81a4df296037aa08e5c6be07a3765524cf8812aec701f7e490612da1908f908e908e908d906149a0565b60405180910390a45050505050505050505092915050565b60008060008060008060008060008b806020019051810190612ddb91906149cd565b97509750975097509750975097509750600160009054906101000a90046001600160a01b03166001600160a01b031663877945f0896040518263ffffffff1660e01b8152600401612e3b91906001600160a01b0391909116815260200190565b602060405180830381865afa158015612e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7c919061411a565b612e995760405163418f824160e01b815260040160405180910390fd5b612ea3878b611ed7565b612ead868b611ed7565b612eb8878987611fd4565b6001600160a01b0383163014801590612f3c57506001546040516306a33c7960e51b81526001600160a01b0385811660048301529091169063d4678f2090602401602060405180830381865afa158015612f16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f3a919061411a565b155b15612f4e57612f4b8b84611e85565b9a505b6001600160a01b0382163014612f6b57612f688b83611e85565b9a505b60405163e2c4f23b60e01b81526001600160a01b03888116600483015287811660248301526044820187905260648201869052848116608483015283811660a483015260c4820183905289169063e2c4f23b9060e401600060405180830381600087803b158015612fdb57600080fd5b505af1158015612fef573d6000803e3d6000fd5b509c9e9d5050505050505050505050505050565b60008083600081518110613019576130196143cb565b6020026020010151600b811115613032576130326143e1565b1480613069575060038360008151811061304e5761304e6143cb565b6020026020010151600b811115613067576130676143e1565b145b156130aa57600082600081518110613083576130836143cb565b602002602001015180602001905181019061309e91906145b0565b509350611ed192505050565b6001836000815181106130bf576130bf6143cb565b6020026020010151600b8111156130d8576130d86143e1565b148061310f57506002836000815181106130f4576130f46143cb565b6020026020010151600b81111561310d5761310d6143e1565b145b1561315057600082600081518110613129576131296143cb565b602002602001015180602001905181019061314491906145b0565b9450611ed19350505050565b600b83600081518110613165576131656143cb565b6020026020010151600b81111561317e5761317e6143e1565b036131bd57600082600081518110613198576131986143cb565b60200260200101518060200190518101906131b3919061472b565b9250611ed1915050565b6007836000815181106131d2576131d26143cb565b6020026020010151600b8111156131eb576131eb6143e1565b14806132225750600683600081518110613207576132076143cb565b6020026020010151600b811115613220576132206143e1565b145b156132685760008260008151811061323c5761323c6143cb565b60200260200101518060200190518101906132579190614750565b50949750611ed19650505050505050565b60048360008151811061327d5761327d6143cb565b6020026020010151600b811115613296576132966143e1565b036132e757600080836000815181106132b1576132b16143cb565b60200260200101518060200190518101906132cc919061461d565b95509550505050506132de8282613003565b92505050611ed1565b6008836000815181106132fc576132fc6143cb565b6020026020010151600b811115613315576133156143e1565b036133585760008260008151811061332f5761332f6143cb565b602002602001015180602001905181019061334a919061486a565b509550611ed1945050505050565b60098360008151811061336d5761336d6143cb565b6020026020010151600b811115613386576133866143e1565b036133f0576000826000815181106133a0576133a06143cb565b60200260200101518060200190518101906133bb9190614a60565b945050505050600080828060200190518101906133d89190614368565b915091506133e68282613003565b9350505050611ed1565b600a83600081518110613405576134056143cb565b6020026020010151600b81111561341e5761341e6143e1565b0361343c57604051631d137c1560e11b815260040160405180910390fd5b600583600081518110613451576134516143cb565b6020026020010151600b81111561346a5761346a6143e1565b03611ed157604051631d137c1560e11b815260040160405180910390fd5b815160005b818110156135ad5760006001600160a01b03168482815181106134b2576134b26143cb565b6020026020010151600001516001600160a01b0316146135a05760008482815181106134e0576134e06143cb565b60200260200101516020015190506000858381518110613502576135026143cb565b6020908102919091010151516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135779190614137565b905081811461359957604051632c1b2f5f60e21b815260040160405180910390fd5b50506135a5565b6135ad565b60010161348d565b504782146107dc57604051632c1b2f5f60e21b815260040160405180910390fd5b606060008085600b8111156135e5576135e56143e1565b14806136025750600185600b811115613600576136006143e1565b145b8061361e5750600285600b81111561361c5761361c6143e1565b145b8061363a5750600385600b811115613638576136386143e1565b145b156136a7576000806000808780602001905181019061365991906145b0565b604080516001600160a01b0395861660208201528082018d9052928516606084015293166080808301919091528351808303909101815260a090910190925290965094506138319350505050565b600885600b8111156136bb576136bb6143e1565b14806136d85750600985600b8111156136d6576136d66143e1565b145b156136f2576136e88585856139c0565b9092509050613831565b600585600b811115613706576137066143e1565b036137c1576000806000806000806000808b80602001905181019061372b91906149cd565b975097509750975097509750975097508498508787878d878787876040516020016137a39897969594939291906001600160a01b0398891681529688166020880152948716604087015260608601939093526080850191909152841660a084015290921660c082015260e08101919091526101000190565b60405160208183030381529060405299505050505050505050613831565b600b85600b8111156137d5576137d56143e1565b0361383157600080858060200190518101906137f1919061472b565b91509150819250848160405160200161381d9291909182526001600160a01b0316602082015260400190565b604051602081830303815290604052935050505b935093915050565b60606138488484600085613af0565b949350505050565b80516000908190815b818110156138f257848181518110613873576138736143cb565b6020026020010151600001516001600160a01b0316866001600160a01b0316036138a6576001600093509350505061390c565b60006001600160a01b03168582815181106138c3576138c36143cb565b6020026020010151600001516001600160a01b0316036138ea5760009350915061390c9050565b600101613859565b50604051633e6e02d360e21b815260040160405180910390fd5b9250929050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015613963573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139879190614137565b905061097a8463095ea7b360e01b856139a08686614605565b6040516001600160a01b0390921660248301526044820152606401610fda565b60606000600885600b8111156139d8576139d86143e1565b03613a7157600080600080600080898060200190518101906139fa919061486a565b9550955095509550955095508296508585858b8585604051602001613a559695949392919095865260208601949094526001600160a01b0392831660408601526060850191909152811660808401521660a082015260c00190565b6040516020818303038152906040529750505050505050613831565b600985600b811115613a8557613a856143e1565b036138315760008060008060008089806020019051810190613aa791906148d3565b9550955095509550955095508296508585858b8585604051602001613ad196959493929190614acd565b6040516020818303038152906040529750505050505050935093915050565b606082471015613b515760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611df1565b600080866001600160a01b03168587604051613b6d9190614594565b60006040518083038185875af1925050503d8060008114613baa576040519150601f19603f3d011682016040523d82523d6000602084013e613baf565b606091505b5091509150613bc087838387613bcb565b979650505050505050565b60608315613c3a578251600003613c33576001600160a01b0385163b613c335760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611df1565b5081613848565b6138488383815115613c4f5781518083602001fd5b8060405162461bcd60e51b8152600401611df19190614107565b6001600160a01b038116811461061d57600080fd5b600060208284031215613c9057600080fd5b8135613c9b81613c69565b9392505050565b600060208284031215613cb457600080fd5b5035919050565b60008060408385031215613cce57600080fd5b8235613cd981613c69565b91506020830135613ce981613c69565b809150509250929050565b60008083601f840112613d0657600080fd5b5081356001600160401b03811115613d1d57600080fd5b6020830191508360208260051b850101111561390c57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613d7657613d76613d38565b604052919050565b60008060008060008086880360a0811215613d9857600080fd5b87356001600160401b0380821115613daf57600080fd5b613dbb8b838c01613cf4565b909950975060208a0135915080821115613dd457600080fd5b613de08b838c01613cf4565b909750955060408a8101359550869250605f1984011215613e0057600080fd5b60405192506040830191508282108183111715613e1f57613e1f613d38565b506040526060880135613e3181613c69565b81526080979097013560208801525093969295509093909291565b801515811461061d57600080fd5b60008060408385031215613e6d57600080fd5b8235613e7881613c69565b91506020830135613ce981613e4c565b60008060008060408587031215613e9e57600080fd5b84356001600160401b0380821115613eb557600080fd5b613ec188838901613cf4565b90965094506020870135915080821115613eda57600080fd5b50613ee787828801613cf4565b95989497509550505050565b60008060408385031215613f0657600080fd5b823591506020830135613ce981613c69565b60008060008060008060808789031215613f3157600080fd5b86356001600160401b0380821115613f4857600080fd5b613f548a838b01613cf4565b90985096506020890135915080821115613f6d57600080fd5b50613f7a89828a01613cf4565b9095509350506040870135613f8e81613c69565b80925050606087013590509295509295509295565b60006001600160401b03821115613fbc57613fbc613d38565b50601f01601f191660200190565b600082601f830112613fdb57600080fd5b8135613fee613fe982613fa3565b613d4e565b81815284602083860101111561400357600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060008060c0878903121561403957600080fd5b8635955060208701359450604087013561405281613c69565b9350606087013561406281613c69565b9250608087013563ffffffff8116811461407b57600080fd5b915060a08701356001600160401b0381111561409657600080fd5b6140a289828a01613fca565b9150509295509295509295565b60005b838110156140ca5781810151838201526020016140b2565b8381111561097a5750506000910152565b600081518084526140f38160208601602086016140af565b601f01601f19169290920160200192915050565b602081526000613c9b60208301846140db565b60006020828403121561412c57600080fd5b8151613c9b81613e4c565b60006020828403121561414957600080fd5b5051919050565b60006001600160401b0382111561416957614169613d38565b5060051b60200190565b6000614181613fe984614150565b80848252602080830192508560051b85013681111561419f57600080fd5b855b818110156141da5780356001600160401b038111156141c05760008081fd5b6141cc36828a01613fca565b8652509382019382016141a1565b50919695505050505050565b6000602082840312156141f857600080fd5b8151613c9b81613c69565b634e487b7160e01b600052601160045260246000fd5b60008282101561422b5761422b614203565b500390565b600082601f83011261424157600080fd5b81516020614251613fe983614150565b82815260059290921b8401810191818101908684111561427057600080fd5b8286015b84811015614299578051600c811061428c5760008081fd5b8352918301918301614274565b509695505050505050565b600082601f8301126142b557600080fd5b81516142c3613fe982613fa3565b8181528460208386010111156142d857600080fd5b6138488260208301602087016140af565b600082601f8301126142fa57600080fd5b8151602061430a613fe983614150565b82815260059290921b8401810191818101908684111561432957600080fd5b8286015b848110156142995780516001600160401b0381111561434c5760008081fd5b61435a8986838b01016142a4565b84525091830191830161432d565b6000806040838503121561437b57600080fd5b82516001600160401b038082111561439257600080fd5b61439e86838701614230565b935060208501519150808211156143b457600080fd5b506143c1858286016142e9565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b60008151808452602080850194508084016000805b84811015614444578251600c811061443257634e487b7160e01b83526021600452602483fd5b8852968301969183019160010161440c565b50959695505050505050565b600081518084526020808501808196508360051b8101915082860160005b858110156144985782840389526144868483516140db565b9885019893509084019060010161446e565b5091979650505050505050565b60a0815260006144b860a08301876143f7565b82810360208401526144ca8187614450565b6040840195909552505081516001600160a01b0316606082015260209091015160809091015292915050565b878152602081018790526001600160a01b0386811660408301528516606082015263ffffffff8416608082015260e060a0820181905260009061453b908301856143f7565b82810360c084015261454d8185614450565b9a9950505050505050505050565b841515815260018060a01b038416602082015282604082015260806060820152600061458a60808301846140db565b9695505050505050565b600082516145a68184602087016140af565b9190910192915050565b600080600080608085870312156145c657600080fd5b84516145d181613c69565b6020860151604087015191955093506145e981613c69565b60608601519092506145fa81613c69565b939692955090935050565b6000821982111561461857614618614203565b500190565b60008060008060008060c0878903121561463657600080fd5b865161464181613c69565b602088015190965061465281613c69565b60408801516060890151919650945061466a81613c69565b60808801519093506001600160401b038082111561468757600080fd5b6146938a838b01614230565b935060a08901519150808211156146a957600080fd5b506140a289828a016142e9565b6080815260006146c960808301876143f7565b82810360208401526146db8187614450565b6001600160a01b0395909516604084015250506060015292915050565b6001600160a01b038581168252602082018590528316604082015260806060820181905260009061458a908301846140db565b6000806040838503121561473e57600080fd5b825191506020830151613ce981613c69565b600080600080600080600080610100898b03121561476d57600080fd5b885161477881613c69565b60208a015190985061478981613c69565b60408a015190975061479a81613c69565b80965050606089015194506080890151935060a089015160ff811681146147c057600080fd5b60c08a015160e0909a0151989b979a5095989497939692505050565b6000600182016147ee576147ee614203565b5060010190565b60408152600061480860408301856143f7565b828103602084015261481a8185614450565b95945050505050565b6001600160a01b03988916815296909716602087015260408601949094526060850192909252608084015260ff1660a083015260c082015260e08101919091526101000190565b60008060008060008060c0878903121561488357600080fd5b8651955060208701519450604087015161489c81613c69565b6060880151608089015191955093506148b481613c69565b60a08801519092506148c581613c69565b809150509295509295509295565b60008060008060008060c087890312156148ec57600080fd5b8651955060208701519450604087015161490581613c69565b60608801516080890151919550935061491d81613c69565b60a08801519092506001600160401b0381111561493957600080fd5b6140a289828a016142a4565b63ffffffff881681526001600160a01b0387811660208301528681166040830152851660608201526080810184905260a0810183905260e060c08201819052600090614993908301846140db565b9998505050505050505050565b84815260018060a01b038416602082015282604082015260806060820152600061458a60808301846140db565b600080600080600080600080610100898b0312156149ea57600080fd5b88516149f581613c69565b60208a0151909850614a0681613c69565b60408a0151909750614a1781613c69565b80965050606089015194506080890151935060a0890151614a3781613c69565b60c08a0151909350614a4881613c69565b8092505060e089015190509295985092959890939650565b600080600080600060a08688031215614a7857600080fd5b85519450602086015193506040860151614a9181613c69565b6060870151608088015191945092506001600160401b03811115614ab457600080fd5b614ac0888289016142a4565b9150509295509295909350565b868152602081018690526001600160a01b038581166040830152606082018590528316608082015260c060a08201819052600090614b0d908301846140db565b9897505050505050505056fea2646970667358221220d7fab334805691a470ba4480079161f7c76017f7cc04d8518dbf82ac6edb476d64736f6c634300080f003360a060405234801561001057600080fd5b5060405161093638038061093683398101604081905261002f91610040565b6001600160a01b0316608052610070565b60006020828403121561005257600080fd5b81516001600160a01b038116811461006957600080fd5b9392505050565b60805161089e610098600039600081816040015281816101440152610182015261089e6000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063f36e55891461003b578063fd614f411461007f575b600080fd5b6100627f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b61009261008d3660046105e2565b61009f565b6040516100769190610709565b6060851561016b576040516370a0823160e01b81523060048201526000906001600160a01b038716906370a0823190602401602060405180830381865afa1580156100ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101129190610723565b905086811015610135576040516323c3077960e11b815260040160405180910390fd5b6101696001600160a01b0387167f000000000000000000000000000000000000000000000000000000000000000089610213565b505b60405163fd614f4160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063fd614f41906101c1908a908a908a908a908a908a9060040161073c565b6000604051808303816000875af11580156101e0573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610208919081019061078d565b979650505050505050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015610263573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102879190610723565b90506102f28463095ea7b360e01b856102a08686610804565b6040516001600160a01b039092166024830152604482015260640160408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526102f8565b50505050565b600061034d826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166103d79092919063ffffffff16565b905080516000148061036e57508080602001905181019061036e919061082a565b6103d25760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b505050565b60606103e684846000856103ee565b949350505050565b60608247101561044f5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103c9565b600080866001600160a01b0316858760405161046b919061084c565b60006040518083038185875af1925050503d80600081146104a8576040519150601f19603f3d011682016040523d82523d6000602084013e6104ad565b606091505b50915091506102088783838760608315610528578251600003610521576001600160a01b0385163b6105215760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103c9565b50816103e6565b6103e6838381511561053d5781518083602001fd5b8060405162461bcd60e51b81526004016103c99190610709565b80356001600160a01b038116811461056e57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156105b2576105b2610573565b604052919050565b600067ffffffffffffffff8211156105d4576105d4610573565b50601f01601f191660200190565b60008060008060008060c087890312156105fb57600080fd5b863595506020870135945061061260408801610557565b935061062060608801610557565b9250608087013563ffffffff8116811461063957600080fd5b915060a087013567ffffffffffffffff81111561065557600080fd5b8701601f8101891361066657600080fd5b8035610679610674826105ba565b610589565b8181528a602083850101111561068e57600080fd5b816020840160208301376000602083830101528093505050509295509295509295565b60005b838110156106cc5781810151838201526020016106b4565b838111156102f25750506000910152565b600081518084526106f58160208601602086016106b1565b601f01601f19169290920160200192915050565b60208152600061071c60208301846106dd565b9392505050565b60006020828403121561073557600080fd5b5051919050565b868152602081018690526001600160a01b0385811660408301528416606082015263ffffffff8316608082015260c060a08201819052600090610781908301846106dd565b98975050505050505050565b60006020828403121561079f57600080fd5b815167ffffffffffffffff8111156107b657600080fd5b8201601f810184136107c757600080fd5b80516107d5610674826105ba565b8181528560208385010111156107ea57600080fd5b6107fb8260208301602086016106b1565b95945050505050565b6000821982111561082557634e487b7160e01b600052601160045260246000fd5b500190565b60006020828403121561083c57600080fd5b8151801515811461071c57600080fd5b6000825161085e8184602087016106b1565b919091019291505056fea264697066735822122075b4315383d074f34fd2916769f427f3baa169a0892cd673c5f8ef5f0111999d64736f6c634300080f003360a060405234801561001057600080fd5b50604051611b00380380611b0083398101604081905261002f91610040565b6001600160a01b0316608052610070565b60006020828403121561005257600080fd5b81516001600160a01b038116811461006957600080fd5b9392505050565b608051611a4c6100b46000396000818160fa015281816101490152818161044b01528181610743015281816107da0152818161089501526109860152611a4c6000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c80631e8ce9b71461006757806364aff9ec1461009a5780638e9a7ed6146100af578063ae53791f146100cf578063e667df2f146100e2578063f36e5589146100f5575b600080fd5b610087610075366004611139565b60009081526020819052604090205490565b6040519081526020015b60405180910390f35b6100ad6100a8366004611167565b610134565b005b6100c26100bd3660046111a8565b6101f2565b60405161009191906112f9565b6100ad6100dd366004611575565b610436565b6100ad6100f03660046115ec565b61097b565b61011c7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610091565b6040516314d0024b60e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a680125890602401602060405180830381865afa158015610198573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101bc91906116a4565b6101d957604051631bd4dfdf60e01b815260040160405180910390fd5b6101ed6001600160a01b0384168383610b40565b505050565b60408051610120810182526000808252602080830182905282840182905260608084018390526080840183905260a0840181905260c084015260e08301829052610100830182905285825281905291909120805483908110610256576102566116cd565b6000918252602091829020604080516101208101825260089093029091018054835260018101548385015260028101546001600160a01b03908116848401526003820154908116606085015263ffffffff600160a01b9091041660808401526004810180548351818702810187019094528084529394919360a08601939283018282801561033357602002820191906000526020600020906000905b82829054906101000a900460ff16600b811115610311576103116111ca565b8152602060019283018181049485019490930390920291018084116102f25790505b5050505050815260200160058201805480602002602001604051908101604052809291908181526020016000905b8282101561040d578382906000526020600020018054610380906116e3565b80601f01602080910402602001604051908101604052809291908181526020018280546103ac906116e3565b80156103f95780601f106103ce576101008083540402835291602001916103f9565b820191906000526020600020905b8154815290600101906020018083116103dc57829003601f168201915b505050505081526020019060010190610361565b505050908252506006820154602082015260079091015460ff1615156040909101529392505050565b6040516314d0024b60e31b81523360048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a680125890602401602060405180830381865afa15801561049a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104be91906116a4565b6104db57604051631bd4dfdf60e01b815260040160405180910390fd5b60008481526020819052604081208054859081106104fb576104fb6116cd565b6000918252602091829020604080516101208101825260089093029091018054835260018101548385015260028101546001600160a01b03908116848401526003820154908116606085015263ffffffff600160a01b9091041660808401526004810180548351818702810187019094528084529394919360a0860193928301828280156105d857602002820191906000526020600020906000905b82829054906101000a900460ff16600b8111156105b6576105b66111ca565b8152602060019283018181049485019490930390920291018084116105975790505b5050505050815260200160058201805480602002602001604051908101604052809291908181526020016000905b828210156106b2578382906000526020600020018054610625906116e3565b80601f0160208091040260200160405190810160405280929190818152602001828054610651906116e3565b801561069e5780601f106106735761010080835404028352916020019161069e565b820191906000526020600020905b81548152906001019060200180831161068157829003601f168201915b505050505081526020019060010190610606565b505050908252506006820154602082015260079091015460ff161515604090910152805190915015806106ed5750608081015163ffffffff16155b1561070b5760405163f359c15960e01b815260040160405180910390fd5b8061010001511561073e576040516316d9dd2b60e31b815260048101869052602481018590526044015b60405180910390fd5b6107847f0000000000000000000000000000000000000000000000000000000000000000826020015183604001516001600160a01b0316610ba39092919063ffffffff16565b600160008087815260200190815260200160002085815481106107a9576107a96116cd565b60009182526020909120600890910201600701805460ff19169115159190911790556040516328fec83d60e21b81527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03169063a3fb20f49061081990869086906004016117a7565b600060405180830381600087803b15801561083357600080fd5b505af1925050508015610844575060015b610927576000858152602081905260408120805486908110610868576108686116cd565b906000526020600020906008020160070160006101000a81548160ff0219169083151502179055506108d67f0000000000000000000000000000000000000000000000000000000000000000826020015183604001516001600160a01b0316610c569092919063ffffffff16565b60001515857f75f79b2296bef29375e5770c80017c3c99e13d6ab7a848dd7dbfa2dfd73efe858360a00151868560c00151878a60405161091a9594939291906117d5565b60405180910390a3610974565b60011515857f75f79b2296bef29375e5770c80017c3c99e13d6ab7a848dd7dbfa2dfd73efe858360a00151868560c00151878a60405161096b9594939291906117d5565b60405180910390a35b5050505050565b336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146109c457604051631bd4dfdf60e01b815260040160405180910390fd5b60008781526020818152604080832080548251610120810184528c81528085018c81526001600160a01b038c81169583019586528b81166060840190815263ffffffff8c81166080860190815260a086018d815260c087018d905260e0870188905261010087018c905260018089018a55988c529a8a902086516008890290910190815594519785019790975596516002840180549184166001600160a01b0319909216919091179055516003830180549651909716600160a01b026001600160c01b0319909616911617939093179093559351805192939192610aae9260048501920190610fc4565b5060c08201518051610aca916005840191602090910190611078565b5060e08201516006820155610100909101516007909101805460ff191691151591909117905560405188907f0cd93b1bd7644619341d89c0d5340b28f9b6bc50f5a3aaae6f65b48a0df0cb9a90610b2e908a908a908a908a908a908a908a90611835565b60405180910390a25050505050505050565b6040516001600160a01b0383166024820152604481018290526101ed90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152610d5f565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015610bf3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c17919061189a565b9050610c508463095ea7b360e01b85610c3086866118b3565b6040516001600160a01b0390921660248301526044820152606401610b6c565b50505050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015610ca6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cca919061189a565b905081811015610d2e5760405162461bcd60e51b815260206004820152602960248201527f5361666545524332303a2064656372656173656420616c6c6f77616e63652062604482015268656c6f77207a65726f60b81b6064820152608401610735565b6040516001600160a01b03841660248201528282036044820152610c5090859063095ea7b360e01b90606401610b6c565b6000610db4826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316610e349092919063ffffffff16565b9050805160001480610dd5575080806020019051810190610dd591906116a4565b6101ed5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610735565b6060610e438484600085610e4b565b949350505050565b606082471015610eac5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610735565b600080866001600160a01b03168587604051610ec891906118d9565b60006040518083038185875af1925050503d8060008114610f05576040519150601f19603f3d011682016040523d82523d6000602084013e610f0a565b606091505b5091509150610f1b87838387610f26565b979650505050505050565b60608315610f95578251600003610f8e576001600160a01b0385163b610f8e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610735565b5081610e43565b610e438383815115610faa5781518083602001fd5b8060405162461bcd60e51b815260040161073591906118f5565b82805482825590600052602060002090601f016020900481019282156110685791602002820160005b8382111561103957835183826101000a81548160ff0219169083600b811115611018576110186111ca565b02179055509260200192600101602081600001049283019260010302610fed565b80156110665782816101000a81549060ff0219169055600101602081600001049283019260010302611039565b505b506110749291506110ca565b5090565b8280548282559060005260206000209081019282156110be579160200282015b828111156110be57825182906110ae9082611956565b5091602001919060010190611098565b506110749291506110df565b5b8082111561107457600081556001016110cb565b808211156110745760006110f382826110fc565b506001016110df565b508054611108906116e3565b6000825580601f10611118575050565b601f01602090049060005260206000209081019061113691906110ca565b50565b60006020828403121561114b57600080fd5b5035919050565b6001600160a01b038116811461113657600080fd5b60008060006060848603121561117c57600080fd5b833561118781611152565b9250602084013561119781611152565b929592945050506040919091013590565b600080604083850312156111bb57600080fd5b50508035926020909101359150565b634e487b7160e01b600052602160045260246000fd5b6000600c821061120057634e487b7160e01b600052602160045260246000fd5b50815260200190565b600081518084526020808501945080840160005b8381101561123e576112308783516111e0565b96509082019060010161121d565b509495945050505050565b60005b8381101561126457818101518382015260200161124c565b83811115610c505750506000910152565b6000815180845261128d816020860160208601611249565b601f01601f19169290920160200192915050565b600082825180855260208086019550808260051b84010181860160005b848110156112ec57601f198684030189526112da838351611275565b988401989250908301906001016112be565b5090979650505050505050565b6020815281516020820152602082015160408201526000604083015161132a60608401826001600160a01b03169052565b5060608301516001600160a01b038116608084015250608083015163ffffffff811660a08401525060a08301516101208060c085015261136e610140850183611209565b915060c0850151601f198584030160e086015261138b83826112a1565b60e0870151610100878101919091529096015115159190940152509192915050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156113ec576113ec6113ad565b604052919050565b600067ffffffffffffffff82111561140e5761140e6113ad565b5060051b60200190565b600082601f83011261142957600080fd5b8135602061143e611439836113f4565b6113c3565b82815260059290921b8401810191818101908684111561145d57600080fd5b8286015b84811015611486578035600c81106114795760008081fd5b8352918301918301611461565b509695505050505050565b6000601f83818401126114a357600080fd5b823560206114b3611439836113f4565b82815260059290921b850181019181810190878411156114d257600080fd5b8287015b8481101561156957803567ffffffffffffffff808211156114f75760008081fd5b818a0191508a603f83011261150c5760008081fd5b85820135604082821115611522576115226113ad565b611533828b01601f191689016113c3565b92508183528c8183860101111561154a5760008081fd5b81818501898501375060009082018701528452509183019183016114d6565b50979650505050505050565b6000806000806080858703121561158b57600080fd5b8435935060208501359250604085013567ffffffffffffffff808211156115b157600080fd5b6115bd88838901611418565b935060608701359150808211156115d357600080fd5b506115e087828801611491565b91505092959194509250565b600080600080600080600060e0888a03121561160757600080fd5b8735965060208801359550604088013561162081611152565b9450606088013561163081611152565b9350608088013563ffffffff8116811461164957600080fd5b925060a088013567ffffffffffffffff8082111561166657600080fd5b6116728b838c01611418565b935060c08a013591508082111561168857600080fd5b506116958a828b01611491565b91505092959891949750929550565b6000602082840312156116b657600080fd5b815180151581146116c657600080fd5b9392505050565b634e487b7160e01b600052603260045260246000fd5b600181811c908216806116f757607f821691505b60208210810361171757634e487b7160e01b600052602260045260246000fd5b50919050565b600081518084526020808501945080840160005b8381101561123e576117448783516111e0565b965090820190600101611731565b600081518084526020808501808196508360051b8101915082860160005b8581101561179a578284038952611788848351611275565b98850198935090840190600101611770565b5091979650505050505050565b6040815260006117ba604083018561171d565b82810360208401526117cc8185611752565b95945050505050565b60a0815260006117e860a083018861171d565b82810360208401526117fa818861171d565b9050828103604084015261180e8187611752565b905082810360608401526118228186611752565b9150508260808301529695505050505050565b8781526001600160a01b0387811660208301528616604082015263ffffffff8516606082015260e0608082018190526000906118739083018661171d565b82810360a08401526118858186611752565b9150508260c083015298975050505050505050565b6000602082840312156118ac57600080fd5b5051919050565b600082198211156118d457634e487b7160e01b600052601160045260246000fd5b500190565b600082516118eb818460208701611249565b9190910192915050565b6020815260006116c66020830184611275565b601f8211156101ed57600081815260208120601f850160051c8101602086101561192f5750805b601f850160051c820191505b8181101561194e5782815560010161193b565b505050505050565b815167ffffffffffffffff811115611970576119706113ad565b6119848161197e84546116e3565b84611908565b602080601f8311600181146119b957600084156119a15750858301515b600019600386901b1c1916600185901b17855561194e565b600085815260208120601f198616915b828110156119e8578886015182559484019460019091019084016119c9565b5085821015611a065787850151600019600388901b60f8161c191681555b5050505050600190811b0190555056fea2646970667358221220a02c27221b6d38925d60e87b97cccd4761d5cee8989366043a6d31264dfac8fe64736f6c634300080f0033000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c600000000000000000000000088ed3b8d03e5a70bf23286872b24cffd76e91922
Deployed Bytecode
0x6080604052600436106101395760003560e01c8063a495566d116100ab578063de4b05481161006f578063de4b054814610447578063e63ab1e91461047b578063f4200a14146104af578063fb1bb9de146104e3578063fd614f4114610517578063ffd864d31461054457610189565b8063a495566d1461036c578063a6801258146103a0578063b80d0586146103e0578063b8342a3414610400578063c80916d41461041357610189565b80634aa4a4fc116100fd5780634aa4a4fc14610270578063580ff61d146102bc5780636127d048146102cf57806363a560ec146103055780637270bdb014610339578063a3fb20f41461035957610189565b80631163b2b0146101a257806316d8887a146101c25780632424401f14610209578063258836fe1461021c578063490b48f81461023c57610189565b3661018957336001600160a01b037f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc21614610187576040516372643aad60e01b815260040160405180910390fd5b005b60405163c6a579c760e01b815260040160405180910390fd5b3480156101ae57600080fd5b506101876101bd366004613c7e565b610564565b3480156101ce57600080fd5b506101f67f5e17fc5225d4a099df75359ce1f405503ca79498a8dc46a7d583235a0ee45c1681565b6040519081526020015b60405180910390f35b610187610217366004613ca2565b610620565b34801561022857600080fd5b50610187610237366004613cbb565b61069f565b34801561024857600080fd5b506101f67fccc64574297998b6c3edf6078cc5e01268465ff116954e3af02ff3a70a730f4681565b34801561027c57600080fd5b506102a47f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281565b6040516001600160a01b039091168152602001610200565b6101876102ca366004613d7e565b6107e2565b3480156102db57600080fd5b506102a46102ea366004613ca2565b6004602052600090815260409020546001600160a01b031681565b34801561031157600080fd5b506101f67f3fc733b4d20d27a28452ddf0e9351aced28242fe03389a653cdb783955316b9b81565b34801561034557600080fd5b50610187610354366004613e5a565b61084c565b610187610367366004613e88565b6108fe565b34801561037857600080fd5b506102a47f000000000000000000000000d66623152d092aa7a753d2b01b30bdf2b1a96f1981565b3480156103ac57600080fd5b506103d06103bb366004613c7e565b60036020526000908152604090205460ff1681565b6040519015158152602001610200565b3480156103ec57600080fd5b506101876103fb366004613ef3565b610980565b61018761040e366004613f18565b610a87565b34801561041f57600080fd5b506102a47f000000000000000000000000efc9d651e79b7799e9868d54f73f230911af722181565b34801561045357600080fd5b506102a47f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c681565b34801561048757600080fd5b506101f67f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a81565b3480156104bb57600080fd5b506101f67fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab81565b3480156104ef57600080fd5b506101f67f427da25fe773164f88948d3e215c94b6554e2ed5e5f203a821c9f2f6131cf75a81565b34801561052357600080fd5b50610537610532366004614020565b610bc4565b6040516102009190614107565b34801561055057600080fd5b506001546102a4906001600160a01b031681565b600154604051632474521560e21b81527fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab60048201523360248201526001600160a01b03909116906391d1485490604401602060405180830381865afa1580156105d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105f6919061411a565b61061357604051639c73fc7f60e01b815260040160405180910390fd5b61061d8147610f0b565b50565b604051632424401f60e01b8152600481018290527f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c66001600160a01b031690632424401f9034906024016000604051808303818588803b15801561068357600080fd5b505af1158015610697573d6000803e3d6000fd5b505050505050565b600154604051632474521560e21b81527fe9e995cadb4a71c3f5032f9fbf95a1e1369b940625a86946b14b2d845bf747ab60048201523360248201526001600160a01b03909116906391d1485490604401602060405180830381865afa15801561070d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610731919061411a565b61074e57604051639c73fc7f60e01b815260040160405180910390fd5b6040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610795573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b99190614137565b9050806000036107c857505050565b6107dc6001600160a01b0384168383610fae565b505b5050565b33301461080257604051633228cc7160e21b815260040160405180910390fd5b6106978686808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506108459250879150889050614173565b8484611011565b600160009054906101000a90046001600160a01b03166001600160a01b031663d33219b46040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108c391906141e6565b6001600160a01b0316336001600160a01b0316146108f45760405163b909292960e01b815260040160405180910390fd5b6107de8282611b36565b610906611be3565b6109708484808060200260200160405190810160405280939291908181526020018383602002808284376000920191909152506109499250859150869050614173565b6000604051806040016040528060006001600160a01b031681526020016000815250611011565b61097a6001600055565b50505050565b600160009054906101000a90046001600160a01b03166001600160a01b031663d33219b46040518163ffffffff1660e01b8152600401602060405180830381865afa1580156109d3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f791906141e6565b6001600160a01b0316336001600160a01b031614610a285760405163b909292960e01b815260040160405180910390fd5b610a3181611c0d565b60008281526004602052604080822080546001600160a01b0319166001600160a01b038516908117909155905184927f9bd7d4d7594aad109cd154387aa65eb873afbb3189646cff5cc066e8160ea90291a35050565b610a9033611c34565b6002805403610ab25760405163590dc0d160e11b815260040160405180910390fd5b600280556040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa158015610afd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b219190614137565b905081811015610b4457604051632028a34d60e01b815260040160405180910390fd5b610bb6878780806020026020016040519081016040528093929190818152602001838360200280828437600092019190915250610b879250889150899050614173565b60006040518060400160405280886001600160a01b031681526020018787610baf9190614219565b9052611011565b505060016002555050505050565b6060336001600160a01b037f000000000000000000000000d66623152d092aa7a753d2b01b30bdf2b1a96f191614610c0f576040516305d1b38f60e01b815260040160405180910390fd5b60008083806020019051810190610c269190614368565b6040805180820182526001600160a01b038b1680825291516370a0823160e01b81523060048201529395509193506000926020830191906370a0823190602401602060405180830381865afa158015610c83573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca79190614137565b90529050610ce06001600160a01b0389167f000000000000000000000000d66623152d092aa7a753d2b01b30bdf2b1a96f19308c611cbf565b6000610d218a85600081518110610cf957610cf96143cb565b602002602001015185600081518110610d1457610d146143cb565b6020026020010151611cf7565b84600081518110610d3457610d346143cb565b602090810291909101019190915260405163580ff61d60e01b8152909150309063580ff61d90610d6e9087908790869088906004016144a5565b600060405180830381600087803b158015610d8857600080fd5b505af1925050508015610d99575060015b610ea657610dd16001600160a01b038a167f000000000000000000000000efc9d651e79b7799e9868d54f73f230911af72218c610fae565b60405163e667df2f60e01b81526001600160a01b037f000000000000000000000000efc9d651e79b7799e9868d54f73f230911af7221169063e667df2f90610e29908e908e908e908e908e908c908c906004016144f6565b600060405180830381600087803b158015610e4357600080fd5b505af1158015610e57573d6000803e3d6000fd5b505050508663ffffffff168b7f62277c9bd483b2bd832cf3849e52ec0a2b1e4297f133ccb28e963239a8007f5a60008c8e8b604051610e99949392919061455b565b60405180910390a3610eed565b8663ffffffff168b7f62277c9bd483b2bd832cf3849e52ec0a2b1e4297f133ccb28e963239a8007f5a60018c8e8b604051610ee4949392919061455b565b60405180910390a35b50506040805160208101909152600081529998505050505050505050565b80600003610f17575050565b610f2082611c0d565b604080516000808252602082019092526001600160a01b038416908390604051610f4a9190614594565b60006040518083038185875af1925050503d8060008114610f87576040519150601f19603f3d011682016040523d82523d6000602084013e610f8c565b606091505b50509050806107dc576040516322462d1f60e01b815260040160405180910390fd5b6040516001600160a01b0383166024820152604481018290526107dc90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611d20565b61104f6040518060a001604052806000815260200160006001600160a01b031681526020016000801916815260200160008152602001606081525090565b8451808252845114611074576040516305b9af8f60e51b815260040160405180910390fd5b60408051600a808252610160820190925290816020015b604080518082019091526000808252602082015281526020019060019003908161108b575050608082015281516001600160a01b0316156110ea578181608001516000815181106110de576110de6143cb565b60200260200101819052505b6110f43447614219565b606082015260005b8151811015611b1c576000868281518110611119576111196143cb565b602002602001015190506000600b811115611136576111366143e1565b81600b811115611148576111486143e1565b036112c657600080600080898681518110611165576111656143cb565b602002602001015180602001905181019061118091906145b0565b935093509350935061119184611dfa565b6000846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156111d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111f591906141e6565b9050611205886020015184611e85565b6001600160a01b031660208901526080880151611223908290611ed7565b611231858960800151611ed7565b61123c818386611f8c565b611247818686611fd4565b604051636e553f6560e01b8152600481018590526001600160a01b038481166024830152861690636e553f65906044015b6020604051808303816000875af1158015611297573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112bb9190614137565b505050505050611b13565b600181600b8111156112da576112da6143e1565b03611328576000806112ee89898787611ff5565b915091508115611321578088611305866001614605565b81518110611315576113156143cb565b60200260200101819052505b5050611b13565b600281600b81111561133c5761133c6143e1565b036114a457600080600080898681518110611359576113596143cb565b602002602001015180602001905181019061137491906145b0565b935093509350935061138584611dfa565b611393876020015182611e85565b87602001906001600160a01b031690816001600160a01b03168152505061141f846001600160a01b031663a919802d6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156113f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061141591906141e6565b8860800151611ed7565b604051633545906160e21b8152600481018490526001600160a01b038381166024830152828116604483015285169063d5164184906064016020604051808303816000875af1158015611476573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061149a9190614137565b5050505050611b13565b600381600b8111156114b8576114b86143e1565b036115de576000806000808986815181106114d5576114d56143cb565b60200260200101518060200190518101906114f091906145b0565b935093509350935061150184611dfa565b6000846001600160a01b031663a919802d6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611541573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061156591906141e6565b9050611575886020015184611e85565b6001600160a01b031660208901526080880151611593908290611ed7565b61159e818386611f8c565b6115a9818686611fd4565b60405163d084b9af60e01b8152600481018590526001600160a01b03848116602483015286169063d084b9af90604401611278565b600681600b8111156115f2576115f26143e1565b0361165f5760408301516116115761160b87878761250f565b60408401525b600061163b82888581518110611629576116296143cb565b6020026020010151866040015161283a565b905061164b846020015182611e85565b6001600160a01b0316602085015250611b13565b600781600b811115611673576116736143e1565b0361168c5760408301516116115761160b87878761250f565b600881600b8111156116a0576116a06143e1565b036116df576116cc8683815181106116ba576116ba6143cb565b60200260200101518460200151612a11565b6001600160a01b03166020840152611b13565b600981600b8111156116f3576116f36143e1565b0361171f576116cc86838151811061170d5761170d6143cb565b60200260200101518460200151612bff565b600581600b811115611733576117336143e1565b03611785578160000361175957604051631d137c1560e11b815260040160405180910390fd5b6116cc86838151811061176e5761176e6143cb565b602002602001015184602001518560800151612db9565b600481600b811115611799576117996143e1565b0361190c576000806000806000808b88815181106117b9576117b96143cb565b60200260200101518060200190518101906117d4919061461d565b9550955095509550955095506117e986611c34565b6001600160a01b03831630146118125760405163ef34858960e01b815260040160405180910390fd5b611820858a60800151611ed7565b61183789602001516118328484613003565b611e85565b6001600160a01b031660208a0152604051600090632e0d0a8d60e21b9061186890859085908a908a906024016146b6565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051631f8aa39560e21b81529091506001600160a01b03881690637e2a8e54906118ce9089908990899087906004016146f8565b600060405180830381600087803b1580156118e857600080fd5b505af11580156118fc573d6000803e3d6000fd5b5050505050505050505050611b13565b600a81600b811115611920576119206143e1565b036119f3576000868381518110611939576119396143cb565b60200260200101518060200190518101906119549190614137565b90506119847f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc28560800151611ed7565b7f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031663d0e30db0826040518263ffffffff1660e01b81526004016000604051808303818588803b1580156119df57600080fd5b505af11580156112bb573d6000803e3d6000fd5b600b81600b811115611a0757611a076143e1565b03611b1357600080878481518110611a2157611a216143cb565b6020026020010151806020019051810190611a3c919061472b565b91509150611a4e856020015182611e85565b6001600160a01b031660208601526080850151611a8c907f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290611ed7565b604051632e1a7d4d60e01b8152600481018390527f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b031690632e1a7d4d90602401600060405180830381600087803b158015611aee57600080fd5b505af1158015611b02573d6000803e3d6000fd5b50505050611b108183610f0b565b50505b506001016110fc565b50611b2f81608001518260600151613488565b5050505050565b611b3f82611c0d565b6001600160a01b03821660009081526003602052604090205481151560ff909116151503611b80576040516332fe3f1960e21b815260040160405180910390fd5b6001600160a01b038216600081815260036020908152604091829020805460ff19168515159081179091558251938452908301527f6bf208b256dacdc89831fd5124ada2aa0f56252c178dd5aff85ee68daf0a7f1c910160405180910390a15050565b600260005403611c065760405163590dc0d160e11b815260040160405180910390fd5b6002600055565b6001600160a01b03811661061d5760405163bb26626360e01b815260040160405180910390fd5b6001546040516306a33c7960e51b81526001600160a01b0383811660048301529091169063d4678f2090602401602060405180830381865afa158015611c7e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ca2919061411a565b61061d5760405163b448a01d60e01b815260040160405180910390fd5b6040516001600160a01b038085166024830152831660448201526064810182905261097a9085906323b872dd60e01b90608401610fda565b6060600080611d078585886135ce565b9093509050858114611d17578091505b50935093915050565b6000611d75826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166138399092919063ffffffff16565b9050805160001480611d96575080806020019051810190611d96919061411a565b6107dc5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084015b60405180910390fd5b600154604051630c5aed5760e01b81526001600160a01b03838116600483015290911690630c5aed5790602401602060405180830381865afa158015611e44573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e68919061411a565b61061d5760405163106f25d560e31b815260040160405180910390fd5b60006001600160a01b038316611e9c575080611ed1565b816001600160a01b0316836001600160a01b031614611ece57604051630727952560e41b815260040160405180910390fd5b50805b92915050565b600080611ee48484613850565b915091508161097a576040805180820182526001600160a01b03861680825291516370a0823160e01b8152306004820152909160208301916370a0823190602401602060405180830381865afa158015611f42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f669190614137565b815250838281518110611f7b57611f7b6143cb565b602002602001018190525050505050565b80600003611f9957505050565b6001600160a01b0382163014801590611fba57506001600160a01b03821633145b156107dc576107dc6001600160a01b038416833084611cbf565b80600003611fe157505050565b6107dc6001600160a01b0384168383613913565b60006060600080600080888781518110612011576120116143cb565b602002602001015180602001905181019061202c91906145b0565b935093509350935061203d84611dfa565b61204b886020015182611e85565b88602001906001600160a01b031690816001600160a01b0316815250506120d7846001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cd91906141e6565b8960800151611ed7565b6120e5848960800151611ed7565b87516120f2886001614605565b0361219257604051632d182be560e21b8152600481018490526001600160a01b038381166024830152828116604483015285169063b460af94906064016020604051808303816000875af115801561214e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121729190614137565b506000604051806020016040528060008152509550955050505050612506565b60008a6121a0896001614605565b815181106121b0576121b06143cb565b6020026020010151905060008a8960016121ca9190614605565b815181106121da576121da6143cb565b602002602001015190508096506000600b8111156121fa576121fa6143e1565b82600b81111561220c5761220c6143e1565b14806122295750600582600b811115612227576122276143e1565b145b806122455750600882600b811115612243576122436143e1565b145b806122615750600982600b81111561225f5761225f6143e1565b145b8061227d5750600b82600b81111561227b5761227b6143e1565b145b801561229157506001600160a01b03841630145b15612483576000866001600160a01b03166338d52e0f6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156122d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122fa91906141e6565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038316906370a0823190602401602060405180830381865afa158015612344573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123689190614137565b604051632d182be560e21b8152600481018990526001600160a01b03888116602483015287811660448301529192509089169063b460af94906064016020604051808303816000875af11580156123c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123e79190614137565b506040516370a0823160e01b81523060048201526000906001600160a01b038416906370a0823190602401602060405180830381865afa15801561242f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124539190614137565b905060006124618383614219565b90508089111561247e5760019b5061247a8686836135ce565b509a505b505050505b604051632d182be560e21b8152600481018690526001600160a01b038581166024830152848116604483015287169063b460af94906064016020604051808303816000875af11580156124da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124fe9190614137565b505050505050505b94509492505050565b825160009081816001600160401b0381111561252d5761252d613d38565b60405190808252806020026020018201604052801561256057816020015b606081526020019060019003908161254b5790505b50905060005b8281101561280557858181518110612580576125806143cb565b602002602001015182828151811061259a5761259a6143cb565b60200260200101819052508060001480156125b457508415155b801561261e575060008782815181106125cf576125cf6143cb565b6020026020010151600b8111156125e8576125e86143e1565b148061261e57506003878281518110612603576126036143cb565b6020026020010151600b81111561261c5761261c6143e1565b145b156126c45760008060008085858151811061263b5761263b6143cb565b602002602001015180602001905181019061265691906145b0565b93509350935093508289146126bf57604080516001600160a01b0380871660208301529181018b90528184166060820152908216608082015260a0016040516020818303038152906040528686815181106126b3576126b36143cb565b60200260200101819052505b505050505b60068782815181106126d8576126d86143cb565b6020026020010151600b8111156126f1576126f16143e1565b14806127275750600787828151811061270c5761270c6143cb565b6020026020010151600b811115612725576127256143e1565b145b156127f357600080600080858581518110612744576127446143cb565b602002602001015180602001905181019061275f9190614750565b5050604080516001600160a01b038089166020830152808816828401528616606082015260808101859052600060a0820181905260c0820181905260e08201819052610100808301919091528251808303909101815261012090910190915295995093975091955093506127d1915050565b8686815181106127e3576127e36143cb565b6020026020010181905250505050505b806127fd816147dc565b915050612566565b5085816040516020016128199291906147f5565b60405160208183030381529060405280519060200120925050509392505050565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290528380602001905181019061288e9190614750565b60e089015260c088015260ff1660a0870152608086015260608501526001600160a01b0390811660408501529081166020840152168082526128cf90611dfa565b600685600b8111156128e3576128e36143e1565b036129795780600001516001600160a01b0316630fad31318260200151836040015184606001518560800151888760a001518860c001518960e001516040518963ffffffff1660e01b8152600401612942989796959493929190614823565b600060405180830381600087803b15801561295c57600080fd5b505af1158015612970573d6000803e3d6000fd5b50505050612a05565b600785600b81111561298d5761298d6143e1565b036129ec5780600001516001600160a01b03166396ebbc458260200151836040015184606001518560800151888760a001518860c001518960e001516040518963ffffffff1660e01b8152600401612942989796959493929190614823565b604051632f67478960e21b815260040160405180910390fd5b60200151949350505050565b600080600080600080600088806020019051810190612a30919061486a565b955095509550955095509550612a4582611c0d565b6000868152600460205260409020546001600160a01b0390811690831603612a80576040516313f7d4e360e21b815260040160405180910390fd5b6000612a8c8984611e85565b9050612a99858386611f8c565b612ac4857f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c686611fd4565b6040516345560b5d60e11b815263ffffffff881660048201526001600160a01b038481166024830152868116604483015282811660648301526084820186905260a4820188905260e060c4830152600060e48301819052917f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c690911690638aac16ba90610104016020604051808303816000875af1158015612b6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8e9190614137565b604080518a81526001600160a01b038981166020830152918101889052608060608201819052600090820152919250851690339083907fb7c6eb876c99dadc81a4df296037aa08e5c6be07a3765524cf8812aec701f7e49060a00160405180910390a4509998505050505050505050565b600080600080600080600088806020019051810190612c1e91906148d3565b95509550955095509550955060008082806020019051810190612c419190614368565b91509150612c538a6118328484613003565b6000898152600460205260409020549099506001600160a01b0316612c7781611c0d565b612c82878688611f8c565b612cad877f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c688611fd4565b60007f0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c66001600160a01b0316638aac16ba8b848b8f8c8f8c6040518863ffffffff1660e01b8152600401612d079796959493929190614945565b6020604051808303816000875af1158015612d26573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d4a9190614137565b60008b815260046020526040908190205490519192506001600160a01b031690339083907fb7c6eb876c99dadc81a4df296037aa08e5c6be07a3765524cf8812aec701f7e490612da1908f908e908e908d906149a0565b60405180910390a45050505050505050505092915050565b60008060008060008060008060008b806020019051810190612ddb91906149cd565b97509750975097509750975097509750600160009054906101000a90046001600160a01b03166001600160a01b031663877945f0896040518263ffffffff1660e01b8152600401612e3b91906001600160a01b0391909116815260200190565b602060405180830381865afa158015612e58573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612e7c919061411a565b612e995760405163418f824160e01b815260040160405180910390fd5b612ea3878b611ed7565b612ead868b611ed7565b612eb8878987611fd4565b6001600160a01b0383163014801590612f3c57506001546040516306a33c7960e51b81526001600160a01b0385811660048301529091169063d4678f2090602401602060405180830381865afa158015612f16573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f3a919061411a565b155b15612f4e57612f4b8b84611e85565b9a505b6001600160a01b0382163014612f6b57612f688b83611e85565b9a505b60405163e2c4f23b60e01b81526001600160a01b03888116600483015287811660248301526044820187905260648201869052848116608483015283811660a483015260c4820183905289169063e2c4f23b9060e401600060405180830381600087803b158015612fdb57600080fd5b505af1158015612fef573d6000803e3d6000fd5b509c9e9d5050505050505050505050505050565b60008083600081518110613019576130196143cb565b6020026020010151600b811115613032576130326143e1565b1480613069575060038360008151811061304e5761304e6143cb565b6020026020010151600b811115613067576130676143e1565b145b156130aa57600082600081518110613083576130836143cb565b602002602001015180602001905181019061309e91906145b0565b509350611ed192505050565b6001836000815181106130bf576130bf6143cb565b6020026020010151600b8111156130d8576130d86143e1565b148061310f57506002836000815181106130f4576130f46143cb565b6020026020010151600b81111561310d5761310d6143e1565b145b1561315057600082600081518110613129576131296143cb565b602002602001015180602001905181019061314491906145b0565b9450611ed19350505050565b600b83600081518110613165576131656143cb565b6020026020010151600b81111561317e5761317e6143e1565b036131bd57600082600081518110613198576131986143cb565b60200260200101518060200190518101906131b3919061472b565b9250611ed1915050565b6007836000815181106131d2576131d26143cb565b6020026020010151600b8111156131eb576131eb6143e1565b14806132225750600683600081518110613207576132076143cb565b6020026020010151600b811115613220576132206143e1565b145b156132685760008260008151811061323c5761323c6143cb565b60200260200101518060200190518101906132579190614750565b50949750611ed19650505050505050565b60048360008151811061327d5761327d6143cb565b6020026020010151600b811115613296576132966143e1565b036132e757600080836000815181106132b1576132b16143cb565b60200260200101518060200190518101906132cc919061461d565b95509550505050506132de8282613003565b92505050611ed1565b6008836000815181106132fc576132fc6143cb565b6020026020010151600b811115613315576133156143e1565b036133585760008260008151811061332f5761332f6143cb565b602002602001015180602001905181019061334a919061486a565b509550611ed1945050505050565b60098360008151811061336d5761336d6143cb565b6020026020010151600b811115613386576133866143e1565b036133f0576000826000815181106133a0576133a06143cb565b60200260200101518060200190518101906133bb9190614a60565b945050505050600080828060200190518101906133d89190614368565b915091506133e68282613003565b9350505050611ed1565b600a83600081518110613405576134056143cb565b6020026020010151600b81111561341e5761341e6143e1565b0361343c57604051631d137c1560e11b815260040160405180910390fd5b600583600081518110613451576134516143cb565b6020026020010151600b81111561346a5761346a6143e1565b03611ed157604051631d137c1560e11b815260040160405180910390fd5b815160005b818110156135ad5760006001600160a01b03168482815181106134b2576134b26143cb565b6020026020010151600001516001600160a01b0316146135a05760008482815181106134e0576134e06143cb565b60200260200101516020015190506000858381518110613502576135026143cb565b6020908102919091010151516040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613553573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906135779190614137565b905081811461359957604051632c1b2f5f60e21b815260040160405180910390fd5b50506135a5565b6135ad565b60010161348d565b504782146107dc57604051632c1b2f5f60e21b815260040160405180910390fd5b606060008085600b8111156135e5576135e56143e1565b14806136025750600185600b811115613600576136006143e1565b145b8061361e5750600285600b81111561361c5761361c6143e1565b145b8061363a5750600385600b811115613638576136386143e1565b145b156136a7576000806000808780602001905181019061365991906145b0565b604080516001600160a01b0395861660208201528082018d9052928516606084015293166080808301919091528351808303909101815260a090910190925290965094506138319350505050565b600885600b8111156136bb576136bb6143e1565b14806136d85750600985600b8111156136d6576136d66143e1565b145b156136f2576136e88585856139c0565b9092509050613831565b600585600b811115613706576137066143e1565b036137c1576000806000806000806000808b80602001905181019061372b91906149cd565b975097509750975097509750975097508498508787878d878787876040516020016137a39897969594939291906001600160a01b0398891681529688166020880152948716604087015260608601939093526080850191909152841660a084015290921660c082015260e08101919091526101000190565b60405160208183030381529060405299505050505050505050613831565b600b85600b8111156137d5576137d56143e1565b0361383157600080858060200190518101906137f1919061472b565b91509150819250848160405160200161381d9291909182526001600160a01b0316602082015260400190565b604051602081830303815290604052935050505b935093915050565b60606138488484600085613af0565b949350505050565b80516000908190815b818110156138f257848181518110613873576138736143cb565b6020026020010151600001516001600160a01b0316866001600160a01b0316036138a6576001600093509350505061390c565b60006001600160a01b03168582815181106138c3576138c36143cb565b6020026020010151600001516001600160a01b0316036138ea5760009350915061390c9050565b600101613859565b50604051633e6e02d360e21b815260040160405180910390fd5b9250929050565b604051636eb1769f60e11b81523060048201526001600160a01b0383811660248301526000919085169063dd62ed3e90604401602060405180830381865afa158015613963573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139879190614137565b905061097a8463095ea7b360e01b856139a08686614605565b6040516001600160a01b0390921660248301526044820152606401610fda565b60606000600885600b8111156139d8576139d86143e1565b03613a7157600080600080600080898060200190518101906139fa919061486a565b9550955095509550955095508296508585858b8585604051602001613a559695949392919095865260208601949094526001600160a01b0392831660408601526060850191909152811660808401521660a082015260c00190565b6040516020818303038152906040529750505050505050613831565b600985600b811115613a8557613a856143e1565b036138315760008060008060008089806020019051810190613aa791906148d3565b9550955095509550955095508296508585858b8585604051602001613ad196959493929190614acd565b6040516020818303038152906040529750505050505050935093915050565b606082471015613b515760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401611df1565b600080866001600160a01b03168587604051613b6d9190614594565b60006040518083038185875af1925050503d8060008114613baa576040519150601f19603f3d011682016040523d82523d6000602084013e613baf565b606091505b5091509150613bc087838387613bcb565b979650505050505050565b60608315613c3a578251600003613c33576001600160a01b0385163b613c335760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401611df1565b5081613848565b6138488383815115613c4f5781518083602001fd5b8060405162461bcd60e51b8152600401611df19190614107565b6001600160a01b038116811461061d57600080fd5b600060208284031215613c9057600080fd5b8135613c9b81613c69565b9392505050565b600060208284031215613cb457600080fd5b5035919050565b60008060408385031215613cce57600080fd5b8235613cd981613c69565b91506020830135613ce981613c69565b809150509250929050565b60008083601f840112613d0657600080fd5b5081356001600160401b03811115613d1d57600080fd5b6020830191508360208260051b850101111561390c57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b0381118282101715613d7657613d76613d38565b604052919050565b60008060008060008086880360a0811215613d9857600080fd5b87356001600160401b0380821115613daf57600080fd5b613dbb8b838c01613cf4565b909950975060208a0135915080821115613dd457600080fd5b613de08b838c01613cf4565b909750955060408a8101359550869250605f1984011215613e0057600080fd5b60405192506040830191508282108183111715613e1f57613e1f613d38565b506040526060880135613e3181613c69565b81526080979097013560208801525093969295509093909291565b801515811461061d57600080fd5b60008060408385031215613e6d57600080fd5b8235613e7881613c69565b91506020830135613ce981613e4c565b60008060008060408587031215613e9e57600080fd5b84356001600160401b0380821115613eb557600080fd5b613ec188838901613cf4565b90965094506020870135915080821115613eda57600080fd5b50613ee787828801613cf4565b95989497509550505050565b60008060408385031215613f0657600080fd5b823591506020830135613ce981613c69565b60008060008060008060808789031215613f3157600080fd5b86356001600160401b0380821115613f4857600080fd5b613f548a838b01613cf4565b90985096506020890135915080821115613f6d57600080fd5b50613f7a89828a01613cf4565b9095509350506040870135613f8e81613c69565b80925050606087013590509295509295509295565b60006001600160401b03821115613fbc57613fbc613d38565b50601f01601f191660200190565b600082601f830112613fdb57600080fd5b8135613fee613fe982613fa3565b613d4e565b81815284602083860101111561400357600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060008060c0878903121561403957600080fd5b8635955060208701359450604087013561405281613c69565b9350606087013561406281613c69565b9250608087013563ffffffff8116811461407b57600080fd5b915060a08701356001600160401b0381111561409657600080fd5b6140a289828a01613fca565b9150509295509295509295565b60005b838110156140ca5781810151838201526020016140b2565b8381111561097a5750506000910152565b600081518084526140f38160208601602086016140af565b601f01601f19169290920160200192915050565b602081526000613c9b60208301846140db565b60006020828403121561412c57600080fd5b8151613c9b81613e4c565b60006020828403121561414957600080fd5b5051919050565b60006001600160401b0382111561416957614169613d38565b5060051b60200190565b6000614181613fe984614150565b80848252602080830192508560051b85013681111561419f57600080fd5b855b818110156141da5780356001600160401b038111156141c05760008081fd5b6141cc36828a01613fca565b8652509382019382016141a1565b50919695505050505050565b6000602082840312156141f857600080fd5b8151613c9b81613c69565b634e487b7160e01b600052601160045260246000fd5b60008282101561422b5761422b614203565b500390565b600082601f83011261424157600080fd5b81516020614251613fe983614150565b82815260059290921b8401810191818101908684111561427057600080fd5b8286015b84811015614299578051600c811061428c5760008081fd5b8352918301918301614274565b509695505050505050565b600082601f8301126142b557600080fd5b81516142c3613fe982613fa3565b8181528460208386010111156142d857600080fd5b6138488260208301602087016140af565b600082601f8301126142fa57600080fd5b8151602061430a613fe983614150565b82815260059290921b8401810191818101908684111561432957600080fd5b8286015b848110156142995780516001600160401b0381111561434c5760008081fd5b61435a8986838b01016142a4565b84525091830191830161432d565b6000806040838503121561437b57600080fd5b82516001600160401b038082111561439257600080fd5b61439e86838701614230565b935060208501519150808211156143b457600080fd5b506143c1858286016142e9565b9150509250929050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052602160045260246000fd5b60008151808452602080850194508084016000805b84811015614444578251600c811061443257634e487b7160e01b83526021600452602483fd5b8852968301969183019160010161440c565b50959695505050505050565b600081518084526020808501808196508360051b8101915082860160005b858110156144985782840389526144868483516140db565b9885019893509084019060010161446e565b5091979650505050505050565b60a0815260006144b860a08301876143f7565b82810360208401526144ca8187614450565b6040840195909552505081516001600160a01b0316606082015260209091015160809091015292915050565b878152602081018790526001600160a01b0386811660408301528516606082015263ffffffff8416608082015260e060a0820181905260009061453b908301856143f7565b82810360c084015261454d8185614450565b9a9950505050505050505050565b841515815260018060a01b038416602082015282604082015260806060820152600061458a60808301846140db565b9695505050505050565b600082516145a68184602087016140af565b9190910192915050565b600080600080608085870312156145c657600080fd5b84516145d181613c69565b6020860151604087015191955093506145e981613c69565b60608601519092506145fa81613c69565b939692955090935050565b6000821982111561461857614618614203565b500190565b60008060008060008060c0878903121561463657600080fd5b865161464181613c69565b602088015190965061465281613c69565b60408801516060890151919650945061466a81613c69565b60808801519093506001600160401b038082111561468757600080fd5b6146938a838b01614230565b935060a08901519150808211156146a957600080fd5b506140a289828a016142e9565b6080815260006146c960808301876143f7565b82810360208401526146db8187614450565b6001600160a01b0395909516604084015250506060015292915050565b6001600160a01b038581168252602082018590528316604082015260806060820181905260009061458a908301846140db565b6000806040838503121561473e57600080fd5b825191506020830151613ce981613c69565b600080600080600080600080610100898b03121561476d57600080fd5b885161477881613c69565b60208a015190985061478981613c69565b60408a015190975061479a81613c69565b80965050606089015194506080890151935060a089015160ff811681146147c057600080fd5b60c08a015160e0909a0151989b979a5095989497939692505050565b6000600182016147ee576147ee614203565b5060010190565b60408152600061480860408301856143f7565b828103602084015261481a8185614450565b95945050505050565b6001600160a01b03988916815296909716602087015260408601949094526060850192909252608084015260ff1660a083015260c082015260e08101919091526101000190565b60008060008060008060c0878903121561488357600080fd5b8651955060208701519450604087015161489c81613c69565b6060880151608089015191955093506148b481613c69565b60a08801519092506148c581613c69565b809150509295509295509295565b60008060008060008060c087890312156148ec57600080fd5b8651955060208701519450604087015161490581613c69565b60608801516080890151919550935061491d81613c69565b60a08801519092506001600160401b0381111561493957600080fd5b6140a289828a016142a4565b63ffffffff881681526001600160a01b0387811660208301528681166040830152851660608201526080810184905260a0810183905260e060c08201819052600090614993908301846140db565b9998505050505050505050565b84815260018060a01b038416602082015282604082015260806060820152600061458a60808301846140db565b600080600080600080600080610100898b0312156149ea57600080fd5b88516149f581613c69565b60208a0151909850614a0681613c69565b60408a0151909750614a1781613c69565b80965050606089015194506080890151935060a0890151614a3781613c69565b60c08a0151909350614a4881613c69565b8092505060e089015190509295985092959890939650565b600080600080600060a08688031215614a7857600080fd5b85519450602086015193506040860151614a9181613c69565b6060870151608088015191945092506001600160401b03811115614ab457600080fd5b614ac0888289016142a4565b9150509295509295909350565b868152602081018690526001600160a01b038581166040830152606082018590528316608082015260c060a08201819052600090614b0d908301846140db565b9897505050505050505056fea2646970667358221220d7fab334805691a470ba4480079161f7c76017f7cc04d8518dbf82ac6edb476d64736f6c634300080f0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c600000000000000000000000088ed3b8d03e5a70bf23286872b24cffd76e91922
-----Decoded View---------------
Arg [0] : weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [1] : connext_ (address): 0x8898B472C54c31894e3B9bb83cEA802a5d0e63C6
Arg [2] : chief (address): 0x88ed3B8D03e5a70Bf23286872b24cFFd76e91922
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [1] : 0000000000000000000000008898b472c54c31894e3b9bb83cea802a5d0e63c6
Arg [2] : 00000000000000000000000088ed3b8d03e5a70bf23286872b24cffd76e91922
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
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.