Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00Latest 13 from a total of 13 transactions
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Deposit | 24189880 | 44 days ago | IN | 0 ETH | 0.00049038 | ||||
| Update Manual Wh... | 24189714 | 44 days ago | IN | 0 ETH | 0.00012153 | ||||
| Owner | 24189126 | 45 days ago | IN | 0 ETH | 0.00000106 | ||||
| Transfer Ownersh... | 24189126 | 45 days ago | IN | 0 ETH | 0.00000174 | ||||
| Set Authority | 24189126 | 45 days ago | IN | 0 ETH | 0.00000216 | ||||
| Update Contract ... | 24189126 | 45 days ago | IN | 0 ETH | 0.00000232 | ||||
| Set Deposit Cap | 24189125 | 45 days ago | IN | 0 ETH | 0.000002 | ||||
| Add Asset | 24189125 | 45 days ago | IN | 0 ETH | 0.00000201 | ||||
| Update Manual Wh... | 24189125 | 45 days ago | IN | 0 ETH | 0.00000205 | ||||
| Set Access Contr... | 24189125 | 45 days ago | IN | 0 ETH | 0.00000201 | ||||
| Set Delegate | 24189125 | 45 days ago | IN | 0 ETH | 0.00000134 | ||||
| Add Chain | 24189125 | 45 days ago | IN | 0 ETH | 0.00000222 | ||||
| Set Peer | 24189125 | 45 days ago | IN | 0 ETH | 0.00000202 |
Latest 1 internal transaction
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| 0x61010060 | 24189125 | 45 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
MultiChainLayerZeroTellerWithMultiAssetSupport
Compiler Version
v0.8.22+commit.4fc1097e
Optimization Enabled:
Yes with 200 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { MultiChainTellerBase, MultiChainTellerBase_MessagesNotAllowedFrom } from "./MultiChainTellerBase.sol";
import { BridgeData, ERC20 } from "./CrossChainTellerBase.sol";
import { OAppAuth, MessagingFee, Origin, MessagingReceipt } from "./OAppAuth/OAppAuth.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";
/**
* @title MultiChainLayerZeroTellerWithMultiAssetSupport
* @notice LayerZero implementation of MultiChainTeller
*/
contract MultiChainLayerZeroTellerWithMultiAssetSupport is MultiChainTellerBase, OAppAuth {
using OptionsBuilder for bytes;
error MultiChainLayerZeroTellerWithMultiAssetSupport_InvalidToken();
constructor(
address _owner,
address _vault,
address _accountant,
address _endpoint
)
MultiChainTellerBase(_owner, _vault, _accountant)
OAppAuth(_endpoint, _owner)
{ }
/**
* @notice function override to return the fee quote
* @param shareAmount to be sent as a message
* @param data Bridge data
*/
function _quote(uint256 shareAmount, BridgeData calldata data) internal view override returns (uint256) {
bytes memory _message = abi.encode(shareAmount, data.destinationChainReceiver);
bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(data.messageGas, 0);
if (address(data.bridgeFeeToken) != NATIVE) {
revert MultiChainLayerZeroTellerWithMultiAssetSupport_InvalidToken();
}
MessagingFee memory fee = _quote(data.chainSelector, _message, _options, false);
return fee.nativeFee;
}
/**
* @notice Called when data is received from the protocol. It overrides the equivalent function in the parent
* contract.
* Protocol messages are defined as packets, comprised of the following parameters.
* @param _origin A struct containing information about where the packet came from.
* @param _guid A global unique identifier for tracking the packet.
* @param payload Encoded message.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata payload,
address, // Executor address as specified by the OApp.
bytes calldata // Any extra data or options to trigger on receipt.
)
internal
override
{
_beforeReceive();
if (!selectorToChains[_origin.srcEid].allowMessagesFrom) {
revert MultiChainTellerBase_MessagesNotAllowedFrom(_origin.srcEid);
}
accountant.checkpoint();
// Decode the payload to get the message
(uint256 shareAmount, address receiver) = abi.decode(payload, (uint256, address));
vault.enter(address(0), ERC20(address(0)), 0, receiver, shareAmount);
_afterReceive(shareAmount, receiver, _guid);
}
/**
* @notice bridge override to allow bridge logic to be done for bridge() and depositAndBridge()
* @param shareAmount to be moved across chain
* @param data BridgeData
*/
function _bridge(uint256 shareAmount, BridgeData calldata data) internal override returns (bytes32) {
if (address(data.bridgeFeeToken) != NATIVE) {
revert MultiChainLayerZeroTellerWithMultiAssetSupport_InvalidToken();
}
bytes memory _payload = abi.encode(shareAmount, data.destinationChainReceiver);
bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(data.messageGas, 0);
MessagingReceipt memory receipt = _lzSend(
data.chainSelector,
_payload,
_options,
// Fee in native gas and ZRO token.
MessagingFee(msg.value, 0),
// Refund address in case of failed source message.
payable(msg.sender)
);
return receipt.guid;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { CrossChainTellerBase, BridgeData } from "./CrossChainTellerBase.sol";
struct Chain {
bool allowMessagesFrom;
bool allowMessagesTo;
address targetTeller;
uint64 messageGasLimit;
uint64 minimumMessageGas;
}
error MultiChainTellerBase_MessagesNotAllowedFrom(uint32 chainSelector);
error MultiChainTellerBase_MessagesNotAllowedFromSender(uint256 chainSelector, address sender);
error MultiChainTellerBase_MessagesNotAllowedTo(uint256 chainSelector);
error MultiChainTellerBase_TargetTellerIsZeroAddress();
error MultiChainTellerBase_DestinationChainReceiverIsZeroAddress();
error MultiChainTellerBase_ZeroMessageGasLimit();
error MultiChainTellerBase_GasLimitExceeded();
error MultiChainTellerBase_GasTooLow();
/**
* @title MultiChainTellerBase
* @notice Base contract for the MultiChainTellers,
* We've noticed that many bridge options are L1 -> L2 only, which are quite simple IE Optimism Messenger
* While others like LZ that can contact many bridges, contain lots of additional complexity to manage the configuration
* for these chains
* To keep this separated we are using this MultiChain syntax for the > 2 chain messaging while only CrossChain for 2
* chain messengers like OP
*/
abstract contract MultiChainTellerBase is CrossChainTellerBase {
event ChainAdded(
uint256 chainSelector,
bool allowMessagesFrom,
bool allowMessagesTo,
address targetTeller,
uint64 messageGasLimit,
uint64 messageGasMin
);
event ChainRemoved(uint256 chainSelector);
event ChainAllowMessagesFrom(uint256 chainSelector, address targetTeller);
event ChainAllowMessagesTo(uint256 chainSelector, address targetTeller);
event ChainStopMessagesFrom(uint256 chainSelector);
event ChainStopMessagesTo(uint256 chainSelector);
event ChainSetGasLimit(uint256 chainSelector, uint64 messageGasLimit);
mapping(uint32 => Chain) public selectorToChains;
constructor(address _owner, address _vault, address _accountant)
CrossChainTellerBase(_owner, _vault, _accountant)
{ }
/**
* @dev Callable by OWNER_ROLE.
* @notice adds an acceptable chain to bridge to
* @param chainSelector chainSelector of chain
* @param allowMessagesFrom allow messages from this chain
* @param allowMessagesTo allow messages to the chain
* @param targetTeller address of the target teller on this chain
* @param messageGasLimit to pass to bridge
* @param messageGasMin to require a minimum provided gas for this chain
*/
function addChain(
uint32 chainSelector,
bool allowMessagesFrom,
bool allowMessagesTo,
address targetTeller,
uint64 messageGasLimit,
uint64 messageGasMin
)
external
requiresAuth
{
if (allowMessagesTo && messageGasLimit == 0) {
revert MultiChainTellerBase_ZeroMessageGasLimit();
}
selectorToChains[chainSelector] =
Chain(allowMessagesFrom, allowMessagesTo, targetTeller, messageGasLimit, messageGasMin);
emit ChainAdded(chainSelector, allowMessagesFrom, allowMessagesTo, targetTeller, messageGasLimit, messageGasMin);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice block messages from a particular chain
* @param chainSelector of chain
*/
function stopMessagesFromChain(uint32 chainSelector) external requiresAuth {
Chain storage chain = selectorToChains[chainSelector];
chain.allowMessagesFrom = false;
emit ChainStopMessagesFrom(chainSelector);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice allow messages from a particular chain
* @param chainSelector of chain
*/
function allowMessagesFromChain(uint32 chainSelector, address targetTeller) external requiresAuth {
Chain storage chain = selectorToChains[chainSelector];
chain.allowMessagesFrom = true;
chain.targetTeller = targetTeller;
emit ChainAllowMessagesFrom(chainSelector, targetTeller);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice Remove a chain from the teller.
* @dev Callable by OWNER_ROLE.
*/
function removeChain(uint32 chainSelector) external requiresAuth {
delete selectorToChains[chainSelector];
emit ChainRemoved(chainSelector);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice Allow messages to a chain.
*/
function allowMessagesToChain(
uint32 chainSelector,
address targetTeller,
uint64 messageGasLimit
)
external
requiresAuth
{
if (messageGasLimit == 0) {
revert MultiChainTellerBase_ZeroMessageGasLimit();
}
Chain storage chain = selectorToChains[chainSelector];
chain.allowMessagesTo = true;
chain.targetTeller = targetTeller;
chain.messageGasLimit = messageGasLimit;
emit ChainAllowMessagesTo(chainSelector, targetTeller);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice Stop messages to a chain.
*/
function stopMessagesToChain(uint32 chainSelector) external requiresAuth {
Chain storage chain = selectorToChains[chainSelector];
chain.allowMessagesTo = false;
emit ChainStopMessagesTo(chainSelector);
}
/**
* @dev Callable by OWNER_ROLE.
* @notice Set the gas limit for messages to a chain.
*/
function setChainGasLimit(uint32 chainSelector, uint64 messageGasLimit) external requiresAuth {
if (messageGasLimit == 0) {
revert MultiChainTellerBase_ZeroMessageGasLimit();
}
Chain storage chain = selectorToChains[chainSelector];
chain.messageGasLimit = messageGasLimit;
emit ChainSetGasLimit(chainSelector, messageGasLimit);
}
/**
* @notice override beforeBridge to check Chain struct
* @param data bridge data
*/
function _beforeBridge(BridgeData calldata data) internal override {
Chain memory chain = selectorToChains[data.chainSelector];
if (!chain.allowMessagesTo) {
revert MultiChainTellerBase_MessagesNotAllowedTo(data.chainSelector);
}
if (chain.targetTeller == address(0)) {
revert MultiChainTellerBase_TargetTellerIsZeroAddress();
}
if (data.destinationChainReceiver == address(0)) {
revert MultiChainTellerBase_DestinationChainReceiverIsZeroAddress();
}
if (data.messageGas > chain.messageGasLimit) {
revert MultiChainTellerBase_GasLimitExceeded();
}
if (data.messageGas < chain.minimumMessageGas) {
revert MultiChainTellerBase_GasTooLow();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { TellerWithMultiAssetSupport } from "../TellerWithMultiAssetSupport.sol";
import { ERC20 } from "@solmate/tokens/ERC20.sol";
struct BridgeData {
uint32 chainSelector;
address destinationChainReceiver;
ERC20 bridgeFeeToken;
uint64 messageGas;
bytes data;
}
/**
* @title CrossChainTellerBase
* @notice Base contract for the CrossChainTeller, includes functions to overload with specific bridge method
*/
abstract contract CrossChainTellerBase is TellerWithMultiAssetSupport {
event MessageSent(bytes32 messageId, uint256 shareAmount, address to);
event MessageReceived(bytes32 messageId, uint256 shareAmount, address to);
constructor(
address _owner,
address _vault,
address _accountant
)
TellerWithMultiAssetSupport(_owner, _vault, _accountant)
{ }
/**
* @notice function to deposit into the vault AND bridge crosschain in 1 call
* @param depositAsset ERC20 to deposit
* @param depositAmount amount of deposit asset to deposit
* @param minimumMint minimum required shares to receive
* @param data Bridge Data
*/
function depositAndBridge(
ERC20 depositAsset,
uint256 depositAmount,
uint256 minimumMint,
BridgeData calldata data
)
external
payable
requiresAuth
nonReentrant
{
if (!isSupported[depositAsset]) {
revert TellerWithMultiAssetSupport__AssetNotSupported();
}
uint256 shareAmount = _erc20Deposit(depositAsset, depositAmount, minimumMint, msg.sender);
_afterPublicDeposit(msg.sender, depositAsset, depositAmount, shareAmount, shareLockPeriod);
bridge(shareAmount, data);
}
/**
* @notice Preview fee required to bridge shares in a given feeToken.
*/
function previewFee(uint256 shareAmount, BridgeData calldata data) external view returns (uint256 fee) {
return _quote(shareAmount, data);
}
/**
* @notice bridging code to be done without deposit, for users who already have vault tokens
* @param shareAmount to bridge
* @param data bridge data
*/
function bridge(
uint256 shareAmount,
BridgeData calldata data
)
public
payable
requiresAuth
returns (bytes32 messageId)
{
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
_beforeBridge(data);
// Since shares are directly burned, call `beforeTransfer` to enforce before transfer hooks.
beforeTransfer(msg.sender);
// Burn shares from sender
vault.exit(address(0), ERC20(address(0)), 0, msg.sender, shareAmount);
messageId = _bridge(shareAmount, data);
_afterBridge(shareAmount, data, messageId);
}
/**
* @notice the virtual bridge function to be overridden
* @param data bridge data
* @return messageId
*/
function _bridge(uint256 shareAmount, BridgeData calldata data) internal virtual returns (bytes32);
/**
* @notice the virtual function to override to get bridge fees
* @param shareAmount to send
* @param data bridge data
*/
function _quote(uint256 shareAmount, BridgeData calldata data) internal view virtual returns (uint256);
/**
* @notice after bridge code, just an emit but can be overridden
* @notice the before bridge hook to perform additional checks
* @param data bridge data
*/
function _beforeBridge(BridgeData calldata data) internal virtual;
/**
* @notice after bridge code, just an emit but can be overridden
* @param shareAmount share amount burned
* @param data bridge data
* @param messageId message id returned when bridged
*/
function _afterBridge(uint256 shareAmount, BridgeData calldata data, bytes32 messageId) internal virtual {
emit MessageSent(messageId, shareAmount, data.destinationChainReceiver);
}
/**
* @notice a before receive hook to call some logic before a receive is processed
*/
function _beforeReceive() internal virtual {
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
}
/**
* @notice a hook to execute after receiving
* @param shareAmount the shareAmount that was minted
* @param destinationChainReceiver the receiver of the shares
* @param messageId the message ID
*/
function _afterReceive(uint256 shareAmount, address destinationChainReceiver, bytes32 messageId) internal virtual {
emit MessageReceived(messageId, shareAmount, destinationChainReceiver);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppSender.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { Origin } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppReceiver.sol";
import { OAppAuthCore } from "./OAppAuthCore.sol";
import { OAppAuthReceiver } from "./OAppAuthReceiver.sol";
import { OAppAuthSender } from "./OAppAuthSender.sol";
/**
* @title OAppAuth
* @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver
* functionality.
*
* @dev This Auth version of OAppCore uses solmate's Auth instead of OZ's Ownable for compatibility purposes
*/
abstract contract OAppAuth is OAppAuthSender, OAppAuthReceiver {
/**
* @dev Constructor to initialize the OApp with the provided endpoint and owner.
* @param _endpoint The address of the LOCAL LayerZero endpoint.
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
*/
constructor(address _endpoint, address _delegate) OAppAuthCore(_endpoint, _delegate) { }
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol implementation.
* @return receiverVersion The version of the OAppReceiver.sol implementation.
*/
function oAppVersion()
public
pure
virtual
override(OAppAuthSender, OAppAuthReceiver)
returns (uint64 senderVersion, uint64 receiverVersion)
{
return (SENDER_VERSION, RECEIVER_VERSION);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ExecutorOptions } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/ExecutorOptions.sol";
import { DVNOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/DVNOptions.sol";
/**
* @title OptionsBuilder
* @dev Library for building and encoding various message options.
*/
library OptionsBuilder {
using SafeCast for uint256;
using BytesLib for bytes;
// Constants for options types
uint16 internal constant TYPE_1 = 1; // legacy options type 1
uint16 internal constant TYPE_2 = 2; // legacy options type 2
uint16 internal constant TYPE_3 = 3;
// Custom error message
error InvalidSize(uint256 max, uint256 actual);
error InvalidOptionType(uint16 optionType);
// Modifier to ensure only options of type 3 are used
modifier onlyType3(bytes memory _options) {
if (_options.toUint16(0) != TYPE_3) revert InvalidOptionType(_options.toUint16(0));
_;
}
/**
* @dev Creates a new options container with type 3.
* @return options The newly created options container.
*/
function newOptions() internal pure returns (bytes memory) {
return abi.encodePacked(TYPE_3);
}
/**
* @dev Adds an executor LZ receive option to the existing options.
* @param _options The existing options container.
* @param _gas The gasLimit used on the lzReceive() function in the OApp.
* @param _value The msg.value passed to the lzReceive() function in the OApp.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed by the executor
* eg. if (_gas: 200k, and _value: 1 ether) AND (_gas: 100k, _value: 0.5 ether) are sent in an option to the LayerZeroEndpoint,
* that becomes (300k, 1.5 ether) when the message is executed on the remote lzReceive() function.
*/
function addExecutorLzReceiveOption(
bytes memory _options,
uint128 _gas,
uint128 _value
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeLzReceiveOption(_gas, _value);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZRECEIVE, option);
}
/**
* @dev Adds an executor native drop option to the existing options.
* @param _options The existing options container.
* @param _amount The amount for the native value that is airdropped to the 'receiver'.
* @param _receiver The receiver address for the native drop option.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed by the executor on the remote chain.
*/
function addExecutorNativeDropOption(
bytes memory _options,
uint128 _amount,
bytes32 _receiver
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeNativeDropOption(_amount, _receiver);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_NATIVE_DROP, option);
}
/**
* @dev Adds an executor LZ compose option to the existing options.
* @param _options The existing options container.
* @param _index The index for the lzCompose() function call.
* @param _gas The gasLimit for the lzCompose() function call.
* @param _value The msg.value for the lzCompose() function call.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed PER index by the executor on the remote chain.
* @dev If the OApp sends N lzCompose calls on the remote, you must provide N incremented indexes starting with 0.
* ie. When your remote OApp composes (N = 3) messages, you must set this option for index 0,1,2
*/
function addExecutorLzComposeOption(
bytes memory _options,
uint16 _index,
uint128 _gas,
uint128 _value
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeLzComposeOption(_index, _gas, _value);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZCOMPOSE, option);
}
/**
* @dev Adds an executor ordered execution option to the existing options.
* @param _options The existing options container.
* @return options The updated options container.
*/
function addExecutorOrderedExecutionOption(
bytes memory _options
) internal pure onlyType3(_options) returns (bytes memory) {
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_ORDERED_EXECUTION, bytes(""));
}
/**
* @dev Adds a DVN pre-crime option to the existing options.
* @param _options The existing options container.
* @param _dvnIdx The DVN index for the pre-crime option.
* @return options The updated options container.
*/
function addDVNPreCrimeOption(
bytes memory _options,
uint8 _dvnIdx
) internal pure onlyType3(_options) returns (bytes memory) {
return addDVNOption(_options, _dvnIdx, DVNOptions.OPTION_TYPE_PRECRIME, bytes(""));
}
/**
* @dev Adds an executor option to the existing options.
* @param _options The existing options container.
* @param _optionType The type of the executor option.
* @param _option The encoded data for the executor option.
* @return options The updated options container.
*/
function addExecutorOption(
bytes memory _options,
uint8 _optionType,
bytes memory _option
) internal pure onlyType3(_options) returns (bytes memory) {
return
abi.encodePacked(
_options,
ExecutorOptions.WORKER_ID,
_option.length.toUint16() + 1, // +1 for optionType
_optionType,
_option
);
}
/**
* @dev Adds a DVN option to the existing options.
* @param _options The existing options container.
* @param _dvnIdx The DVN index for the DVN option.
* @param _optionType The type of the DVN option.
* @param _option The encoded data for the DVN option.
* @return options The updated options container.
*/
function addDVNOption(
bytes memory _options,
uint8 _dvnIdx,
uint8 _optionType,
bytes memory _option
) internal pure onlyType3(_options) returns (bytes memory) {
return
abi.encodePacked(
_options,
DVNOptions.WORKER_ID,
_option.length.toUint16() + 2, // +2 for optionType and dvnIdx
_dvnIdx,
_optionType,
_option
);
}
/**
* @dev Encodes legacy options of type 1.
* @param _executionGas The gasLimit value passed to lzReceive().
* @return legacyOptions The encoded legacy options.
*/
function encodeLegacyOptionsType1(uint256 _executionGas) internal pure returns (bytes memory) {
if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
return abi.encodePacked(TYPE_1, _executionGas);
}
/**
* @dev Encodes legacy options of type 2.
* @param _executionGas The gasLimit value passed to lzReceive().
* @param _nativeForDst The amount of native air dropped to the receiver.
* @param _receiver The _nativeForDst receiver address.
* @return legacyOptions The encoded legacy options of type 2.
*/
function encodeLegacyOptionsType2(
uint256 _executionGas,
uint256 _nativeForDst,
bytes memory _receiver // @dev Use bytes instead of bytes32 in legacy type 2 for _receiver.
) internal pure returns (bytes memory) {
if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
if (_nativeForDst > type(uint128).max) revert InvalidSize(type(uint128).max, _nativeForDst);
if (_receiver.length > 32) revert InvalidSize(32, _receiver.length);
return abi.encodePacked(TYPE_2, _executionGas, _nativeForDst, _receiver);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { ERC20 } from "@solmate/tokens/ERC20.sol";
import { WETH } from "@solmate/tokens/WETH.sol";
import { BoringVault } from "src/base/BoringVault.sol";
import { AccountantWithRateProviders } from "src/base/Roles/AccountantWithRateProviders.sol";
import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol";
import { SafeTransferLib } from "@solmate/utils/SafeTransferLib.sol";
import { BeforeTransferHook } from "src/interfaces/BeforeTransferHook.sol";
import { Auth, Authority } from "@solmate/auth/Auth.sol";
import { ReentrancyGuard } from "@solmate/utils/ReentrancyGuard.sol";
import { IKeyring } from "src/interfaces/IKeyring.sol";
import { IRateProvider } from "src/interfaces/IRateProvider.sol";
/**
* @title TellerWithMultiAssetSupport
*/
contract TellerWithMultiAssetSupport is Auth, BeforeTransferHook, ReentrancyGuard {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
using SafeTransferLib for WETH;
// ========================================= CONSTANTS =========================================
/**
* @notice Native address used to tell the contract to handle native asset deposits.
*/
address internal constant NATIVE = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/**
* @notice The maximum possible share lock period.
*/
uint256 internal constant MAX_SHARE_LOCK_PERIOD = 3 days;
// ========================================= STATE =========================================
uint256 public depositCap;
/**
* @notice Mapping ERC20s to an isSupported bool.
*/
mapping(ERC20 => bool) public isSupported;
/**
* @notice The deposit nonce used to map to a deposit hash.
*/
uint96 public depositNonce = 1;
/**
* @notice After deposits, shares are locked to the msg.sender's address
* for `shareLockPeriod`.
* @dev During this time all transfers from msg.sender will revert, and
* deposits are refundable.
*/
uint64 public shareLockPeriod;
/**
* @notice Used to pause calls to `deposit` and `depositWithPermit`.
*/
bool public isPaused;
/**
* @dev Maps deposit nonce to keccak256(address receiver, address _depositAsset, uint256 _depositAmount, uint256
* _shareAmount, uint256 _timestamp, uint256 _shareLockPeriod).
*/
mapping(uint256 => bytes32) public publicDepositHistory;
/**
* @notice Maps user address to the time their shares will be unlocked.
*/
mapping(address => uint256) public shareUnlockTime;
/**
* @notice Access control mode for the vault
*/
enum AccessControlMode {
DISABLED,
KEYRING_KYC,
MANUAL_WHITELIST
}
/**
* @notice Current access control mode
*/
AccessControlMode public accessControlMode;
/**
* @notice Keyring contract interface
*/
IKeyring public keyringContract;
/**
* @notice Keyring policy ID to check against
*/
uint256 public keyringPolicyId;
/**
* @notice Manual whitelist for addresses when in MANUAL_WHITELIST mode
*/
mapping(address => bool) public manualWhitelist;
/**
* @notice Whitelist for smart contracts (AMMs, protocols) that work in both modes
*/
mapping(address => bool) public contractWhitelist;
//============================== ERRORS ===============================
error TellerWithMultiAssetSupport__ShareLockPeriodTooLong();
error TellerWithMultiAssetSupport__SharesAreLocked();
error TellerWithMultiAssetSupport__SharesAreUnLocked();
error TellerWithMultiAssetSupport__BadDepositHash();
error TellerWithMultiAssetSupport__AssetNotSupported();
error TellerWithMultiAssetSupport__ZeroAssets();
error TellerWithMultiAssetSupport__MinimumMintNotMet();
error TellerWithMultiAssetSupport__MinimumAssetsNotMet();
error TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow();
error TellerWithMultiAssetSupport__ZeroShares();
error TellerWithMultiAssetSupport__Paused();
error TellerWithMultiAssetSupport__KeyringCredentialInvalid();
error TellerWithMultiAssetSupport__NotWhitelisted();
//============================== EVENTS ===============================
event Paused();
event Unpaused();
event AssetAdded(address indexed asset);
event AssetRemoved(address indexed asset);
event Deposit(
uint256 indexed nonce,
address indexed receiver,
address indexed _depositAsset,
uint256 _depositAmount,
uint256 _shareAmount,
uint256 depositTimestamp,
uint256 shareLockPeriodAtTimeOfDeposit
);
event BulkDeposit(address indexed asset, uint256 _depositAmount);
event BulkWithdraw(address indexed asset, uint256 _shareAmount);
event DepositRefunded(uint256 indexed nonce, bytes32 depositHash, address indexed user);
event DepositCapUpdated(uint256 oldCap, uint256 newCap);
event AccessControlModeUpdated(AccessControlMode oldMode, AccessControlMode newMode);
event KeyringConfigUpdated(address keyringContract, uint256 policyId);
event ManualWhitelistUpdated(address indexed account, bool status);
event ContractWhitelistUpdated(address indexed account, bool status);
event ShareLockPeriodUpdated(uint64 oldPeriod, uint64 newPeriod);
//============================== IMMUTABLES ===============================
/**
* @notice The BoringVault this contract is working with.
*/
BoringVault public immutable vault;
/**
* @notice The AccountantWithRateProviders this contract is working with.
*/
AccountantWithRateProviders public immutable accountant;
/**
* @notice One share of the BoringVault.
*/
uint256 internal immutable ONE_SHARE;
/**
* @notice Check if an address has access to mint/redeem
* @param _entity The address to check
*/
modifier checkAccess(address _entity) {
if (accessControlMode == AccessControlMode.KEYRING_KYC) {
if (!contractWhitelist[_entity] && address(keyringContract) != address(0)) {
if (!keyringContract.checkCredential(keyringPolicyId, _entity)) {
revert TellerWithMultiAssetSupport__KeyringCredentialInvalid();
}
}
} else if (accessControlMode == AccessControlMode.MANUAL_WHITELIST) {
if (!manualWhitelist[_entity] && !contractWhitelist[_entity]) {
revert TellerWithMultiAssetSupport__NotWhitelisted();
}
}
// If DISABLED, no checks performed
_;
}
constructor(address _owner, address _vault, address _accountant) Auth(_owner, Authority(address(0))) {
vault = BoringVault(payable(_vault));
ONE_SHARE = 10 ** vault.decimals();
accountant = AccountantWithRateProviders(_accountant);
}
// ========================================= ADMIN FUNCTIONS =========================================
function setDepositCap(uint256 _depositCap) external requiresAuth {
uint256 oldCap = depositCap;
depositCap = _depositCap;
emit DepositCapUpdated(oldCap, _depositCap);
}
/**
* @notice Pause this contract, which prevents future calls to `deposit` and `depositWithPermit`.
* @dev Callable by MULTISIG_ROLE.
*/
function pause() external requiresAuth {
isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to `deposit` and `depositWithPermit`.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
isPaused = false;
emit Unpaused();
}
/**
* @notice Adds this asset as a deposit asset.
* @dev The accountant must also support pricing this asset, else the `deposit` call will revert.
* @dev Callable by OWNER_ROLE.
*/
function addAsset(ERC20 _asset) external requiresAuth {
isSupported[_asset] = true;
emit AssetAdded(address(_asset));
}
/**
* @notice Removes this asset as a deposit asset.
* @dev Callable by OWNER_ROLE.
*/
function removeAsset(ERC20 _asset) external requiresAuth {
isSupported[_asset] = false;
emit AssetRemoved(address(_asset));
}
/**
* @notice Sets the share lock period.
* @dev This not only locks shares to the user address, but also serves as the pending deposit period, where
* deposits can be reverted.
* @dev If a new shorter share lock period is set, users with pending share locks could make a new deposit to
* receive 1 wei shares,
* and have their shares unlock sooner than their original deposit allows. This state would allow for the user
* deposit to be refunded,
* but only if they have not transferred their shares out of there wallet. This is an accepted limitation, and
* should be known when decreasing
* the share lock period.
* @dev Callable by OWNER_ROLE.
*/
function setShareLockPeriod(uint64 _shareLockPeriod) external requiresAuth {
if (_shareLockPeriod > MAX_SHARE_LOCK_PERIOD) revert TellerWithMultiAssetSupport__ShareLockPeriodTooLong();
uint64 oldPeriod = shareLockPeriod;
shareLockPeriod = _shareLockPeriod;
emit ShareLockPeriodUpdated(oldPeriod, _shareLockPeriod);
}
/**
* @notice Sets the access control mode
* @dev Callable by OWNER_ROLE
*/
function setAccessControlMode(AccessControlMode _mode) external requiresAuth {
emit AccessControlModeUpdated(accessControlMode, _mode);
accessControlMode = _mode;
}
/**
* @notice Configure Keyring integration
* @dev Callable by OWNER_ROLE
*/
function setKeyringConfig(address _keyringContract, uint256 _policyId) external requiresAuth {
keyringContract = IKeyring(_keyringContract);
keyringPolicyId = _policyId;
emit KeyringConfigUpdated(_keyringContract, _policyId);
}
/**
* @notice Update manual whitelist
* @dev Callable by OWNER_ROLE
*/
function updateManualWhitelist(address[] calldata _addresses, bool _status) external requiresAuth {
for (uint256 i = 0; i < _addresses.length; i++) {
manualWhitelist[_addresses[i]] = _status;
emit ManualWhitelistUpdated(_addresses[i], _status);
}
}
/**
* @notice Update contract whitelist (for AMMs, protocols)
* @dev Callable by OWNER_ROLE
*/
function updateContractWhitelist(address[] calldata _addresses, bool _status) external requiresAuth {
for (uint256 i = 0; i < _addresses.length; i++) {
contractWhitelist[_addresses[i]] = _status;
emit ContractWhitelistUpdated(_addresses[i], _status);
}
}
// ========================================= BeforeTransferHook FUNCTIONS =========================================
/**
* @notice Implement beforeTransfer hook to check if shares are locked.
*/
function beforeTransfer(address _from) public view {
if (shareUnlockTime[_from] > block.timestamp) revert TellerWithMultiAssetSupport__SharesAreLocked();
}
// ========================================= REVERT DEPOSIT FUNCTIONS =========================================
/**
* @notice Allows DEPOSIT_REFUNDER_ROLE to revert a pending deposit.
* @dev Once a deposit share lock period has passed, it can no longer be reverted.
* @dev It is possible the admin does not setup the BoringVault to call the transfer hook,
* but this contract can still be saving share lock state. In the event this happens
* deposits are still refundable if the user has not transferred their shares.
* But there is no guarantee that the user has not transferred their shares.
* @dev Callable by STRATEGIST_MULTISIG_ROLE.
*/
function refundDeposit(
uint256 _nonce,
address _receiver,
address _depositAsset,
uint256 _depositAmount,
uint256 _shareAmount,
uint256 _depositTimestamp,
uint256 _shareLockUpPeriodAtTimeOfDeposit
)
external
requiresAuth
{
if ((block.timestamp - _depositTimestamp) > _shareLockUpPeriodAtTimeOfDeposit) {
// Shares are already unlocked, so we can not revert deposit.
revert TellerWithMultiAssetSupport__SharesAreUnLocked();
}
bytes32 depositHash = keccak256(
abi.encode(
_receiver,
_depositAsset,
_depositAmount,
_shareAmount,
_depositTimestamp,
_shareLockUpPeriodAtTimeOfDeposit
)
);
if (publicDepositHistory[_nonce] != depositHash) revert TellerWithMultiAssetSupport__BadDepositHash();
// Delete hash to prevent refund gas.
delete publicDepositHistory[_nonce];
accountant.checkpoint();
// Burn shares and refund assets to receiver.
vault.exit(_receiver, ERC20(_depositAsset), _depositAmount, _receiver, _shareAmount);
emit DepositRefunded(_nonce, depositHash, _receiver);
}
// ========================================= USER FUNCTIONS =========================================
/**
* @notice Allows users to deposit into the BoringVault, if this contract is not paused.
* @dev Publicly callable.
*/
function deposit(
ERC20 _depositAsset,
uint256 _depositAmount,
uint256 _minimumMint
)
external
requiresAuth
nonReentrant
checkAccess(msg.sender)
returns (uint256 shares)
{
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
if (!isSupported[_depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
shares = _erc20Deposit(_depositAsset, _depositAmount, _minimumMint, msg.sender);
_afterPublicDeposit(msg.sender, _depositAsset, _depositAmount, shares, shareLockPeriod);
}
/**
* @notice Allows users to deposit into BoringVault using permit.
* @dev Publicly callable.
*/
function depositWithPermit(
ERC20 _depositAsset,
uint256 _depositAmount,
uint256 _minimumMint,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
)
external
requiresAuth
nonReentrant
checkAccess(msg.sender)
returns (uint256 shares)
{
if (isPaused) revert TellerWithMultiAssetSupport__Paused();
if (!isSupported[_depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
// solhint-disable-next-line no-empty-blocks
try _depositAsset.permit(msg.sender, address(vault), _depositAmount, _deadline, _v, _r, _s) { }
catch {
if (_depositAsset.allowance(msg.sender, address(vault)) < _depositAmount) {
revert TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow();
}
}
shares = _erc20Deposit(_depositAsset, _depositAmount, _minimumMint, msg.sender);
_afterPublicDeposit(msg.sender, _depositAsset, _depositAmount, shares, shareLockPeriod);
}
/**
* @notice Allows on ramp role to deposit into this contract.
* @dev Does NOT support native deposits.
* @dev Callable by SOLVER_ROLE.
*/
function bulkDeposit(
ERC20 _depositAsset,
uint256 _depositAmount,
uint256 _minimumMint,
address _to
)
external
requiresAuth
nonReentrant
checkAccess(_to)
returns (uint256 shares)
{
if (!isSupported[_depositAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
shares = _erc20Deposit(_depositAsset, _depositAmount, _minimumMint, _to);
emit BulkDeposit(address(_depositAsset), _depositAmount);
}
/**
* @notice Allows off ramp role to withdraw from this contract.
* @dev Callable by SOLVER_ROLE.
*/
function bulkWithdraw(
ERC20 _withdrawAsset,
uint256 _shareAmount,
uint256 _minimumAssets,
address _to
)
external
requiresAuth
checkAccess(msg.sender)
returns (uint256 assetsOut)
{
if (!isSupported[_withdrawAsset]) revert TellerWithMultiAssetSupport__AssetNotSupported();
if (_shareAmount == 0) revert TellerWithMultiAssetSupport__ZeroShares();
accountant.checkpoint();
// Get exchange rate in 18 decimals
uint256 rate = accountant.getRate();
// Calculate value in 18 decimals
uint256 withdrawValueIn18 = _shareAmount.mulDivDown(rate, ONE_SHARE);
// Convert to asset amount based on asset type
if (address(_withdrawAsset) == address(accountant.base())) {
// Base asset - convert from 18 to base decimals
assetsOut = _changeDecimals(withdrawValueIn18, 18, accountant.decimals());
} else {
(bool isPegged,) = accountant.rateProviderData(_withdrawAsset);
if (isPegged) {
// Pegged asset - convert from 18 to asset decimals
assetsOut = _changeDecimals(withdrawValueIn18, 18, _withdrawAsset.decimals());
} else {
// Non-pegged asset - use rate provider
(, IRateProvider rateProvider) = accountant.rateProviderData(_withdrawAsset);
uint256 assetRate = rateProvider.getRate();
assetsOut = withdrawValueIn18.mulDivDown(10 ** _withdrawAsset.decimals(), assetRate);
}
}
if (assetsOut < _minimumAssets) revert TellerWithMultiAssetSupport__MinimumAssetsNotMet();
vault.exit(_to, _withdrawAsset, assetsOut, msg.sender, _shareAmount);
emit BulkWithdraw(address(_withdrawAsset), _shareAmount);
}
// ========================================= INTERNAL HELPER FUNCTIONS =========================================
/**
* @notice Implements a common ERC20 deposit into BoringVault.
*/
function _erc20Deposit(
ERC20 _depositAsset,
uint256 _depositAmount,
uint256 _minimumMint,
address _to
)
internal
returns (uint256 shares)
{
if (_depositAmount == 0) revert TellerWithMultiAssetSupport__ZeroAssets();
accountant.checkpoint();
// Get exchange rate in 18 decimals
uint256 rate = accountant.getRate();
// Convert deposit amount to 18 decimal value based on asset type
uint256 depositValueIn18;
if (address(_depositAsset) == address(accountant.base())) {
// Base asset - convert to 18 decimals
depositValueIn18 = _changeDecimals(_depositAmount, accountant.decimals(), 18);
} else {
(bool isPegged,) = accountant.rateProviderData(_depositAsset);
if (isPegged) {
// Pegged asset - convert to 18 decimals (1:1 with base)
depositValueIn18 = _changeDecimals(_depositAmount, _depositAsset.decimals(), 18);
} else {
// Non-pegged asset - use rate provider
(, IRateProvider rateProvider) = accountant.rateProviderData(_depositAsset);
uint256 assetRate = rateProvider.getRate();
depositValueIn18 = _depositAmount.mulDivDown(assetRate, 10 ** _depositAsset.decimals());
}
}
// Calculate shares using 18 decimal values
shares = depositValueIn18.mulDivDown(ONE_SHARE, rate);
if (shares < _minimumMint) revert TellerWithMultiAssetSupport__MinimumMintNotMet();
uint256 shareValueInBase = shares.mulDivDown(rate, ONE_SHARE);
// Convert to base decimals for cap check
shareValueInBase = _changeDecimals(shareValueInBase, 18, accountant.decimals());
uint256 currentTotalValue = vault.totalSupply().mulDivDown(rate, ONE_SHARE);
currentTotalValue = _changeDecimals(currentTotalValue, 18, accountant.decimals());
require(currentTotalValue + shareValueInBase <= depositCap, "Deposit cap exceeded");
vault.enter(msg.sender, _depositAsset, _depositAmount, _to, shares);
}
/**
* @notice Handle share lock logic, and event.
*/
function _afterPublicDeposit(
address _user,
ERC20 _depositAsset,
uint256 _depositAmount,
uint256 _shares,
uint256 _currentShareLockPeriod
)
internal
{
shareUnlockTime[_user] = block.timestamp + _currentShareLockPeriod;
uint256 nonce = depositNonce;
publicDepositHistory[nonce] = keccak256(
abi.encode(_user, _depositAsset, _depositAmount, _shares, block.timestamp, _currentShareLockPeriod)
);
depositNonce++;
emit Deposit(
nonce, _user, address(_depositAsset), _depositAmount, _shares, block.timestamp, _currentShareLockPeriod
);
}
/**
* @notice Internal helper to change decimals
*/
function _changeDecimals(uint256 amount, uint8 fromDecimals, uint8 toDecimals) internal pure returns (uint256) {
if (fromDecimals == toDecimals) return amount;
if (fromDecimals < toDecimals) {
return amount * 10 ** (toDecimals - fromDecimals);
} else {
return amount / 10 ** (fromDecimals - toDecimals);
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "./OAppCore.sol";
/**
* @title OAppSender
* @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
*/
abstract contract OAppSender is OAppCore {
using SafeERC20 for IERC20;
// Custom error messages
error NotEnoughNative(uint256 msgValue);
error LzTokenUnavailable();
// @dev The version of the OAppSender implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant SENDER_VERSION = 1;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
* ie. this is a SEND only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (SENDER_VERSION, 0);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
* @return fee The calculated MessagingFee for the message.
* - nativeFee: The native fee for the message.
* - lzTokenFee: The LZ token fee for the message.
*/
function _quote(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
bool _payInLzToken
) internal view virtual returns (MessagingFee memory fee) {
return
endpoint.quote(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
address(this)
);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _fee The calculated LayerZero fee for the message.
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
* @param _refundAddress The address to receive any excess fee values sent to the endpoint.
* @return receipt The receipt for the sent message.
* - guid: The unique identifier for the sent message.
* - nonce: The nonce of the sent message.
* - fee: The LayerZero fee incurred for the message.
*/
function _lzSend(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
MessagingFee memory _fee,
address _refundAddress
) internal virtual returns (MessagingReceipt memory receipt) {
// @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
uint256 messageValue = _payNative(_fee.nativeFee);
if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);
return
// solhint-disable-next-line check-send-result
endpoint.send{ value: messageValue }(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
_refundAddress
);
}
/**
* @dev Internal function to pay the native fee associated with the message.
* @param _nativeFee The native fee to be paid.
* @return nativeFee The amount of native currency paid.
*
* @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
* this will need to be overridden because msg.value would contain multiple lzFees.
* @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
* @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
* @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
*/
function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
return _nativeFee;
}
/**
* @dev Internal function to pay the LZ token fee associated with the message.
* @param _lzTokenFee The LZ token fee to be paid.
*
* @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
* @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
*/
function _payLzToken(uint256 _lzTokenFee) internal virtual {
// @dev Cannot cache the token because it is not immutable in the endpoint.
address lzToken = endpoint.lzToken();
if (lzToken == address(0)) revert LzTokenUnavailable();
// Pay LZ token fee by sending tokens to the endpoint.
IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IOAppReceiver, Origin } from "./interfaces/IOAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";
/**
* @title OAppReceiver
* @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
*/
abstract contract OAppReceiver is IOAppReceiver, OAppCore {
// Custom error message for when the caller is not the registered endpoint/
error OnlyEndpoint(address addr);
// @dev The version of the OAppReceiver implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant RECEIVER_VERSION = 2;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppSender version. Indicates that the OAppSender is not implemented.
* ie. this is a RECEIVE only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions.
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (0, RECEIVER_VERSION);
}
/**
* @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
* @dev _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @dev _message The lzReceive payload.
* @param _sender The sender address.
* @return isSender Is a valid sender.
*
* @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
* @dev The default sender IS the OAppReceiver implementer.
*/
function isComposeMsgSender(
Origin calldata /*_origin*/,
bytes calldata /*_message*/,
address _sender
) public view virtual returns (bool) {
return _sender == address(this);
}
/**
* @notice Checks if the path initialization is allowed based on the provided origin.
* @param origin The origin information containing the source endpoint and sender address.
* @return Whether the path has been initialized.
*
* @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
* @dev This defaults to assuming if a peer has been set, its initialized.
* Can be overridden by the OApp if there is other logic to determine this.
*/
function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
return peers[origin.srcEid] == origin.sender;
}
/**
* @notice Retrieves the next nonce for a given source endpoint and sender address.
* @dev _srcEid The source endpoint ID.
* @dev _sender The sender address.
* @return nonce The next nonce.
*
* @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
* @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
* @dev This is also enforced by the OApp.
* @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
*/
function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public view virtual returns (uint64 nonce) {
return 0;
}
/**
* @dev Entry point for receiving messages or packets from the endpoint.
* @param _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @param _guid The unique identifier for the received LayerZero message.
* @param _message The payload of the received message.
* @param _executor The address of the executor for the received message.
* @param _extraData Additional arbitrary data provided by the corresponding executor.
*
* @dev Entry point for receiving msg/packet from the LayerZero endpoint.
*/
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) public payable virtual {
// Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);
// Ensure that the sender matches the expected peer for the source endpoint.
if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);
// Call the internal OApp implementation of lzReceive.
_lzReceive(_origin, _guid, _message, _executor, _extraData);
}
/**
* @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) internal virtual;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { Auth } from "@solmate/auth/Auth.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppCore.sol";
/**
* @title OAppAuthCore
* @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
*
* @dev This Auth version of OAppCore uses solmate's Auth instead of OZ's Ownable for compatibility purposes
*/
abstract contract OAppAuthCore is IOAppCore, Auth {
// The LayerZero endpoint associated with the given OApp
ILayerZeroEndpointV2 public immutable endpoint;
// Mapping to store peers associated with corresponding endpoints
mapping(uint32 eid => bytes32 peer) public peers;
/**
* @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
* @param _endpoint The address of the LOCAL Layer Zero endpoint.
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
*
* @dev The delegate typically should be set as the owner of the contract.
*/
constructor(address _endpoint, address _delegate) {
endpoint = ILayerZeroEndpointV2(_endpoint);
if (_delegate == address(0)) revert InvalidDelegate();
endpoint.setDelegate(_delegate);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*
* @notice this contract replaces the OZ Ownable onlyOwner with Solmate requiresAuth
*/
function setPeer(uint32 _eid, bytes32 _peer) public virtual requiresAuth {
_setPeer(_eid, _peer);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*/
function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
peers[_eid] = _peer;
emit PeerSet(_eid, _peer);
}
/**
* @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
* ie. the peer is set to bytes32(0).
* @param _eid The endpoint ID.
* @return peer The address of the peer associated with the specified endpoint.
*/
function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
bytes32 peer = peers[_eid];
if (peer == bytes32(0)) revert NoPeer(_eid);
return peer;
}
/**
* @notice Sets the delegate address for the OApp.
* @param _delegate The address of the delegate to be set.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint
* contract.
*
* @notice this contract replaces the OZ Ownable onlyOwner with Solmate requiresAuth
*/
function setDelegate(address _delegate) public requiresAuth {
endpoint.setDelegate(_delegate);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IOAppReceiver, Origin } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppReceiver.sol";
import { OAppAuthCore } from "./OAppAuthCore.sol";
/**
* @title OAppAuthReceiver
* @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
*
* @dev This Auth version of OAppCore uses solmate's Auth instead of OZ's Ownable for compatibility purposes
*/
abstract contract OAppAuthReceiver is IOAppReceiver, OAppAuthCore {
// Custom error message for when the caller is not the registered endpoint/
error OnlyEndpoint(address addr);
// @dev The version of the OAppReceiver implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant RECEIVER_VERSION = 2;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppSender version. Indicates that the OAppSender is not implemented.
* ie. this is a RECEIVE only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct
* versions.
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (0, RECEIVER_VERSION);
}
/**
* @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
* @dev _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @dev _message The lzReceive payload.
* @param _sender The sender address.
* @return isSender Is a valid sender.
*
* @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
* @dev The default sender IS the OAppReceiver implementer.
*/
function isComposeMsgSender(
Origin calldata, /*_origin*/
bytes calldata, /*_message*/
address _sender
)
public
view
virtual
returns (bool)
{
return _sender == address(this);
}
/**
* @notice Checks if the path initialization is allowed based on the provided origin.
* @param origin The origin information containing the source endpoint and sender address.
* @return Whether the path has been initialized.
*
* @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
* @dev This defaults to assuming if a peer has been set, its initialized.
* Can be overridden by the OApp if there is other logic to determine this.
*/
function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
return peers[origin.srcEid] == origin.sender;
}
/**
* @notice Retrieves the next nonce for a given source endpoint and sender address.
* @dev _srcEid The source endpoint ID.
* @dev _sender The sender address.
* @return nonce The next nonce.
*
* @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
* @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
* @dev This is also enforced by the OApp.
* @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
*/
function nextNonce(
uint32,
/*_srcEid*/
bytes32 /*_sender*/
)
public
view
virtual
returns (uint64 nonce)
{
return 0;
}
/**
* @dev Entry point for receiving messages or packets from the endpoint.
* @param _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @param _guid The unique identifier for the received LayerZero message.
* @param _message The payload of the received message.
* @param _executor The address of the executor for the received message.
* @param _extraData Additional arbitrary data provided by the corresponding executor.
*
* @dev Entry point for receiving msg/packet from the LayerZero endpoint.
*/
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
)
public
payable
virtual
{
// Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);
// Ensure that the sender matches the expected peer for the source endpoint.
if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);
// Call the internal OApp implementation of lzReceive.
_lzReceive(_origin, _guid, _message, _executor, _extraData);
}
/**
* @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
)
internal
virtual;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {
MessagingParams,
MessagingFee,
MessagingReceipt
} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppAuthCore } from "./OAppAuthCore.sol";
/**
* @title OAppAuthSender
* @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
*
* @dev This Auth version of OAppCore uses solmate's Auth instead of OZ's Ownable for compatibility purposes
*/
abstract contract OAppAuthSender is OAppAuthCore {
using SafeERC20 for IERC20;
// Custom error messages
error NotEnoughNative(uint256 msgValue);
error LzTokenUnavailable();
// @dev The version of the OAppSender implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant SENDER_VERSION = 1;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
* ie. this is a SEND only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct
* versions
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (SENDER_VERSION, 0);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
* @return fee The calculated MessagingFee for the message.
* - nativeFee: The native fee for the message.
* - lzTokenFee: The LZ token fee for the message.
*/
function _quote(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
bool _payInLzToken
)
internal
view
virtual
returns (MessagingFee memory fee)
{
return endpoint.quote(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken), address(this)
);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _fee The calculated LayerZero fee for the message.
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
* @param _refundAddress The address to receive any excess fee values sent to the endpoint.
* @return receipt The receipt for the sent message.
* - guid: The unique identifier for the sent message.
* - nonce: The nonce of the sent message.
* - fee: The LayerZero fee incurred for the message.
*/
function _lzSend(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
MessagingFee memory _fee,
address _refundAddress
)
internal
virtual
returns (MessagingReceipt memory receipt)
{
// @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the
// endpoint.
uint256 messageValue = _payNative(_fee.nativeFee);
if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);
// solhint-disable-next-line check-send-result
return endpoint.send{ value: messageValue }(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0), _refundAddress
);
}
/**
* @dev Internal function to pay the native fee associated with the message.
* @param _nativeFee The native fee to be paid.
* @return nativeFee The amount of native currency paid.
*
* @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
* this will need to be overridden because msg.value would contain multiple lzFees.
* @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
* @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
* @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
*/
function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
return _nativeFee;
}
/**
* @dev Internal function to pay the LZ token fee associated with the message.
* @param _lzTokenFee The LZ token fee to be paid.
*
* @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
* @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
*/
function _payLzToken(uint256 _lzTokenFee) internal virtual {
// @dev Cannot cache the token because it is not immutable in the endpoint.
address lzToken = endpoint.lzToken();
if (lzToken == address(0)) revert LzTokenUnavailable();
// Pay LZ token fee by sending tokens to the endpoint.
IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
}
}// SPDX-License-Identifier: Unlicense
/*
* @title Solidity Bytes Arrays Utils
* @author Gonçalo Sá <goncalo.sa@consensys.net>
*
* @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
* The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
*/
pragma solidity >=0.8.0 <0.9.0;
library BytesLib {
function concat(
bytes memory _preBytes,
bytes memory _postBytes
)
internal
pure
returns (bytes memory)
{
bytes memory tempBytes;
assembly {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)
// Store the length of the first bytes array at the beginning of
// the memory for tempBytes.
let length := mload(_preBytes)
mstore(tempBytes, length)
// 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))
}
// 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))
}
// 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),
not(31) // Round down to the nearest 32 bytes.
))
}
return tempBytes;
}
function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
assembly {
// 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)
// 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)
// 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 {
// 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))
),
// and 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 {
// 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))
// 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)
// 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)
// 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 {
// 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 equal_nonAligned(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 {
// 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 endMinusWord := add(_preBytes, length)
let mc := add(_preBytes, 0x20)
let cc := add(_postBytes, 0x20)
for {
// the next line is the loop condition:
// while(uint256(mc < endWord) + cb == 2)
} eq(add(lt(mc, endMinusWord), 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
}
}
// Only if still successful
// For <1 word tail bytes
if gt(success, 0) {
// Get the remainder of length/32
// length % 32 = AND(length, 32 - 1)
let numTailBytes := and(length, 0x1f)
let mcRem := mload(mc)
let ccRem := mload(cc)
for {
let i := 0
// the next line is the loop condition:
// while(uint256(i < numTailBytes) + cb == 2)
} eq(add(lt(i, numTailBytes), cb), 2) {
i := add(i, 1)
} {
if iszero(eq(byte(i, mcRem), byte(i, ccRem))) {
// 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 {
// 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 {
// 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 v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
/// @solidity memory-safe-assembly
assembly {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { CalldataBytesLib } from "../../libs/CalldataBytesLib.sol";
library ExecutorOptions {
using CalldataBytesLib for bytes;
uint8 internal constant WORKER_ID = 1;
uint8 internal constant OPTION_TYPE_LZRECEIVE = 1;
uint8 internal constant OPTION_TYPE_NATIVE_DROP = 2;
uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;
error Executor_InvalidLzReceiveOption();
error Executor_InvalidNativeDropOption();
error Executor_InvalidLzComposeOption();
/// @dev decode the next executor option from the options starting from the specified cursor
/// @param _options [executor_id][executor_option][executor_id][executor_option]...
/// executor_option = [option_size][option_type][option]
/// option_size = len(option_type) + len(option)
/// executor_id: uint8, option_size: uint16, option_type: uint8, option: bytes
/// @param _cursor the cursor to start decoding from
/// @return optionType the type of the option
/// @return option the option of the executor
/// @return cursor the cursor to start decoding the next executor option
function nextExecutorOption(
bytes calldata _options,
uint256 _cursor
) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
unchecked {
// skip worker id
cursor = _cursor + 1;
// read option size
uint16 size = _options.toU16(cursor);
cursor += 2;
// read option type
optionType = _options.toU8(cursor);
// startCursor and endCursor are used to slice the option from _options
uint256 startCursor = cursor + 1; // skip option type
uint256 endCursor = cursor + size;
option = _options[startCursor:endCursor];
cursor += size;
}
}
function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
gas = _option.toU128(0);
value = _option.length == 32 ? _option.toU128(16) : 0;
}
function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
if (_option.length != 48) revert Executor_InvalidNativeDropOption();
amount = _option.toU128(0);
receiver = _option.toB32(16);
}
function decodeLzComposeOption(
bytes calldata _option
) internal pure returns (uint16 index, uint128 gas, uint128 value) {
if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
index = _option.toU16(0);
gas = _option.toU128(2);
value = _option.length == 34 ? _option.toU128(18) : 0;
}
function encodeLzReceiveOption(uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
return _value == 0 ? abi.encodePacked(_gas) : abi.encodePacked(_gas, _value);
}
function encodeNativeDropOption(uint128 _amount, bytes32 _receiver) internal pure returns (bytes memory) {
return abi.encodePacked(_amount, _receiver);
}
function encodeLzComposeOption(uint16 _index, uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
return _value == 0 ? abi.encodePacked(_index, _gas) : abi.encodePacked(_index, _gas, _value);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { CalldataBytesLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";
library DVNOptions {
using CalldataBytesLib for bytes;
using BytesLib for bytes;
uint8 internal constant WORKER_ID = 2;
uint8 internal constant OPTION_TYPE_PRECRIME = 1;
error DVN_InvalidDVNIdx();
error DVN_InvalidDVNOptions(uint256 cursor);
/// @dev group dvn options by its idx
/// @param _options [dvn_id][dvn_option][dvn_id][dvn_option]...
/// dvn_option = [option_size][dvn_idx][option_type][option]
/// option_size = len(dvn_idx) + len(option_type) + len(option)
/// dvn_id: uint8, dvn_idx: uint8, option_size: uint16, option_type: uint8, option: bytes
/// @return dvnOptions the grouped options, still share the same format of _options
/// @return dvnIndices the dvn indices
function groupDVNOptionsByIdx(
bytes memory _options
) internal pure returns (bytes[] memory dvnOptions, uint8[] memory dvnIndices) {
if (_options.length == 0) return (dvnOptions, dvnIndices);
uint8 numDVNs = getNumDVNs(_options);
// if there is only 1 dvn, we can just return the whole options
if (numDVNs == 1) {
dvnOptions = new bytes[](1);
dvnOptions[0] = _options;
dvnIndices = new uint8[](1);
dvnIndices[0] = _options.toUint8(3); // dvn idx
return (dvnOptions, dvnIndices);
}
// otherwise, we need to group the options by dvn_idx
dvnIndices = new uint8[](numDVNs);
dvnOptions = new bytes[](numDVNs);
unchecked {
uint256 cursor = 0;
uint256 start = 0;
uint8 lastDVNIdx = 255; // 255 is an invalid dvn_idx
while (cursor < _options.length) {
++cursor; // skip worker_id
// optionLength asserted in getNumDVNs (skip check)
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
// dvnIdx asserted in getNumDVNs (skip check)
uint8 dvnIdx = _options.toUint8(cursor);
// dvnIdx must equal to the lastDVNIdx for the first option
// so it is always skipped in the first option
// this operation slices out options whenever the scan finds a different lastDVNIdx
if (lastDVNIdx == 255) {
lastDVNIdx = dvnIdx;
} else if (dvnIdx != lastDVNIdx) {
uint256 len = cursor - start - 3; // 3 is for worker_id and option_length
bytes memory opt = _options.slice(start, len);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, opt);
// reset the start and lastDVNIdx
start += len;
lastDVNIdx = dvnIdx;
}
cursor += optionLength;
}
// skip check the cursor here because the cursor is asserted in getNumDVNs
// if we have reached the end of the options, we need to process the last dvn
uint256 size = cursor - start;
bytes memory op = _options.slice(start, size);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, op);
// revert dvnIndices to start from 0
for (uint8 i = 0; i < numDVNs; ++i) {
--dvnIndices[i];
}
}
}
function _insertDVNOptions(
bytes[] memory _dvnOptions,
uint8[] memory _dvnIndices,
uint8 _dvnIdx,
bytes memory _newOptions
) internal pure {
// dvnIdx starts from 0 but default value of dvnIndices is 0,
// so we tell if the slot is empty by adding 1 to dvnIdx
if (_dvnIdx == 255) revert DVN_InvalidDVNIdx();
uint8 dvnIdxAdj = _dvnIdx + 1;
for (uint256 j = 0; j < _dvnIndices.length; ++j) {
uint8 index = _dvnIndices[j];
if (dvnIdxAdj == index) {
_dvnOptions[j] = abi.encodePacked(_dvnOptions[j], _newOptions);
break;
} else if (index == 0) {
// empty slot, that means it is the first time we see this dvn
_dvnIndices[j] = dvnIdxAdj;
_dvnOptions[j] = _newOptions;
break;
}
}
}
/// @dev get the number of unique dvns
/// @param _options the format is the same as groupDVNOptionsByIdx
function getNumDVNs(bytes memory _options) internal pure returns (uint8 numDVNs) {
uint256 cursor = 0;
BitMap256 bitmap;
// find number of unique dvn_idx
unchecked {
while (cursor < _options.length) {
++cursor; // skip worker_id
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
if (optionLength < 2) revert DVN_InvalidDVNOptions(cursor); // at least 1 byte for dvn_idx and 1 byte for option_type
uint8 dvnIdx = _options.toUint8(cursor);
// if dvnIdx is not set, increment numDVNs
// max num of dvns is 255, 255 is an invalid dvn_idx
// The order of the dvnIdx is not required to be sequential, as enforcing the order may weaken
// the composability of the options. e.g. if we refrain from enforcing the order, an OApp that has
// already enforced certain options can append additional options to the end of the enforced
// ones without restrictions.
if (dvnIdx == 255) revert DVN_InvalidDVNIdx();
if (!bitmap.get(dvnIdx)) {
++numDVNs;
bitmap = bitmap.set(dvnIdx);
}
cursor += optionLength;
}
}
if (cursor != _options.length) revert DVN_InvalidDVNOptions(cursor);
}
/// @dev decode the next dvn option from _options starting from the specified cursor
/// @param _options the format is the same as groupDVNOptionsByIdx
/// @param _cursor the cursor to start decoding
/// @return optionType the type of the option
/// @return option the option
/// @return cursor the cursor to start decoding the next option
function nextDVNOption(
bytes calldata _options,
uint256 _cursor
) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
unchecked {
// skip worker id
cursor = _cursor + 1;
// read option size
uint16 size = _options.toU16(cursor);
cursor += 2;
// read option type
optionType = _options.toU8(cursor + 1); // skip dvn_idx
// startCursor and endCursor are used to slice the option from _options
uint256 startCursor = cursor + 2; // skip option type and dvn_idx
uint256 endCursor = cursor + size;
option = _options[startCursor:endCursor];
cursor += size;
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "./ERC20.sol";
import {SafeTransferLib} from "../utils/SafeTransferLib.sol";
/// @notice Minimalist and modern Wrapped Ether implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/WETH.sol)
/// @author Inspired by WETH9 (https://github.com/dapphub/ds-weth/blob/master/src/weth9.sol)
contract WETH is ERC20("Wrapped Ether", "WETH", 18) {
using SafeTransferLib for address;
event Deposit(address indexed from, uint256 amount);
event Withdrawal(address indexed to, uint256 amount);
function deposit() public payable virtual {
_mint(msg.sender, msg.value);
emit Deposit(msg.sender, msg.value);
}
function withdraw(uint256 amount) public virtual {
_burn(msg.sender, amount);
emit Withdrawal(msg.sender, amount);
msg.sender.safeTransferETH(amount);
}
receive() external payable virtual {
deposit();
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { ERC721Holder } from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import { ERC1155Holder } from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol";
import { SafeTransferLib } from "@solmate/utils/SafeTransferLib.sol";
import { ERC20 } from "@solmate/tokens/ERC20.sol";
import { BeforeTransferHook } from "src/interfaces/BeforeTransferHook.sol";
import { Auth, Authority } from "@solmate/auth/Auth.sol";
/**
* @title BoringVault
* @custom:security-contact security@molecularlabs.io
*/
contract BoringVault is ERC20, Auth, ERC721Holder, ERC1155Holder {
using Address for address;
using SafeTransferLib for ERC20;
using FixedPointMathLib for uint256;
// ========================================= STATE =========================================
/**
* @notice Contract responsible for implementing `beforeTransfer`.
*/
BeforeTransferHook public hook;
//============================== EVENTS ===============================
event Enter(address indexed from, address indexed asset, uint256 amount, address indexed to, uint256 shares);
event Exit(address indexed to, address indexed asset, uint256 amount, address indexed from, uint256 shares);
//============================== CONSTRUCTOR ===============================
constructor(
address _owner,
string memory _name,
string memory _symbol,
uint8 _decimals
)
ERC20(_name, _symbol, _decimals)
Auth(_owner, Authority(address(0)))
{ }
//============================== MANAGE ===============================
/**
* @notice Allows manager to make an arbitrary function call from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(
address target,
bytes calldata data,
uint256 value
)
external
requiresAuth
returns (bytes memory result)
{
result = target.functionCallWithValue(data, value);
}
/**
* @notice Allows manager to make arbitrary function calls from this contract.
* @dev Callable by MANAGER_ROLE.
*/
function manage(
address[] calldata targets,
bytes[] calldata data,
uint256[] calldata values
)
external
requiresAuth
returns (bytes[] memory results)
{
uint256 targetsLength = targets.length;
results = new bytes[](targetsLength);
for (uint256 i; i < targetsLength; ++i) {
results[i] = targets[i].functionCallWithValue(data[i], values[i]);
}
}
//============================== ENTER ===============================
/**
* @notice Allows minter to mint shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred in.
* @dev Callable by MINTER_ROLE.
*/
function enter(
address from,
ERC20 asset,
uint256 assetAmount,
address to,
uint256 shareAmount
)
external
requiresAuth
{
// Transfer assets in
if (assetAmount > 0) asset.safeTransferFrom(from, address(this), assetAmount);
// Mint shares.
_mint(to, shareAmount);
emit Enter(from, address(asset), assetAmount, to, shareAmount);
}
//============================== EXIT ===============================
/**
* @notice Allows burner to burn shares, in exchange for assets.
* @dev If assetAmount is zero, no assets are transferred out.
* @dev Callable by BURNER_ROLE.
*/
function exit(
address to,
ERC20 asset,
uint256 assetAmount,
address from,
uint256 shareAmount
)
external
requiresAuth
{
// Burn shares.
_burn(from, shareAmount);
// Transfer assets out.
if (assetAmount > 0) asset.safeTransfer(to, assetAmount);
emit Exit(to, address(asset), assetAmount, from, shareAmount);
}
//============================== BEFORE TRANSFER HOOK ===============================
/**
* @notice Sets the share locker.
* @notice If set to zero address, the share locker logic is disabled.
* @dev Callable by OWNER_ROLE.
*/
function setBeforeTransferHook(address _hook) external requiresAuth {
hook = BeforeTransferHook(_hook);
}
/**
* @notice Check if from addresses shares are locked, reverting if so.
*/
function _callBeforeTransfer(address from) internal view {
if (address(hook) != address(0)) hook.beforeTransfer(from);
}
function transfer(address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(msg.sender);
return super.transfer(to, amount);
}
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
_callBeforeTransfer(from);
return super.transferFrom(from, to, amount);
}
//============================== RECEIVE ===============================
receive() external payable { }
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol";
import { IRateProvider } from "src/interfaces/IRateProvider.sol";
import { ERC20 } from "@solmate/tokens/ERC20.sol";
import { SafeTransferLib } from "@solmate/utils/SafeTransferLib.sol";
import { BoringVault } from "src/base/BoringVault.sol";
import { Auth, Authority } from "@solmate/auth/Auth.sol";
/**
* @title AccountantWithRateProviders
*/
contract AccountantWithRateProviders is Auth, IRateProvider {
using FixedPointMathLib for uint256;
using SafeTransferLib for ERC20;
// ========================================= STRUCTS =========================================
/**
* @param payoutAddress the address `claimFees` sends fees to
* @param feesOwedInBase total pending fees owed in terms of base
* @param totalSharesLastUpdate total amount of shares the last exchange rate update
* @param exchangeRate the current exchange rate in terms of base
* @param _allowedExchangeRateChangeUpper the max allowed change to exchange rate from an update
* @param _allowedExchangeRateChangeLower the min allowed change to exchange rate from an update
* @param _lastUpdateTimestamp the block timestamp of the last exchange rate update
* @param _isPaused whether or not this contract is paused
* @param _minimumUpdateDelayInSeconds the minimum amount of time that must pass between
* exchange rate updates, such that the update won't trigger the contract to be paused
* @param _managementFee the management fee
*/
struct AccountantState {
address _payoutAddress;
uint128 _feesOwedInBase;
uint128 _totalSharesLastUpdate;
uint96 _exchangeRate;
uint16 _allowedExchangeRateChangeUpper;
uint16 _allowedExchangeRateChangeLower;
uint64 _lastUpdateTimestamp;
bool _isPaused;
uint32 _minimumUpdateDelayInSeconds;
uint16 _managementFee;
}
/**
* @notice Lending specific state
* @param _lendingRate Annual lending interest rate in basis points (1000 = 10%)
* @param _lastAccrualTime Timestamp of last interest accrual
*/
struct LendingInfo {
uint256 _lendingRate; // Rate for vault growth
uint256 _lastAccrualTime; // Last checkpoint
}
/**
* @param isPeggedToBase whether or not the asset is 1:1 with the base asset
* @param rateProvider the rate provider for this asset if `isPeggedToBase` is false
*/
struct RateProviderData {
bool isPeggedToBase;
IRateProvider rateProvider;
}
// ========================================= CONSTANTS =========================================
// Constants for calculations
uint256 constant SECONDS_PER_YEAR = 365 days;
uint256 constant BASIS_POINTS = 10_000;
// ========================================= STATE =========================================
/**
* @notice Store the accountant state in 3 packed slots.
*/
AccountantState public accountantState;
LendingInfo public lendingInfo;
uint256 public maxLendingRate;
/**
* @notice Maps ERC20s to their RateProviderData.
*/
mapping(ERC20 => RateProviderData) public rateProviderData;
//============================== ERRORS ===============================
error AccountantWithRateProviders__UpperBoundTooSmall();
error AccountantWithRateProviders__LowerBoundTooLarge();
error AccountantWithRateProviders__ManagementFeeTooLarge();
error AccountantWithRateProviders__Paused();
error AccountantWithRateProviders__ZeroFeesOwed();
error AccountantWithRateProviders__OnlyCallableByBoringVault();
error AccountantWithRateProviders__UpdateDelayTooLarge();
error AccountantWithRateProviders__UpperMustExceedLower();
//============================== EVENTS ===============================
event Paused();
event Unpaused();
event DelayInSecondsUpdated(uint32 oldDelay, uint32 newDelay);
event UpperBoundUpdated(uint16 oldBound, uint16 newBound);
event LowerBoundUpdated(uint16 oldBound, uint16 newBound);
event PayoutAddressUpdated(address oldPayout, address newPayout);
event RateProviderUpdated(address asset, bool isPegged, address rateProvider);
event ExchangeRateUpdated(uint96 oldRate, uint96 newRate, uint64 currentTime);
event FeesClaimed(address indexed feeAsset, uint256 amount);
event LendingRateUpdated(uint256 newRate, uint256 timestamp);
event ManagementFeeRateUpdated(uint16 newRate, uint256 timestamp);
event MaxLendingRateUpdated(uint256 newMaxRate);
event Checkpoint(uint256 indexed timestamp);
//============================== IMMUTABLES ===============================
/**
* @notice The base asset rates are provided in.
*/
ERC20 public immutable base;
/**
* @notice The decimals rates are provided in.
*/
uint8 public immutable decimals;
/**
* @notice The BoringVault this accountant is working with.
* Used to determine share supply for fee calculation.
*/
BoringVault public immutable vault;
/**
* @notice One share of the BoringVault.
*/
uint256 internal immutable ONE_SHARE;
constructor(
address _owner,
address _vault,
address _payoutAddress,
uint96 _startingExchangeRate,
address _base,
uint16 _allowedExchangeRateChangeUpper,
uint16 _allowedExchangeRateChangeLower,
uint32 _minimumUpdateDelayInSeconds,
uint16 _managementFee
)
Auth(_owner, Authority(address(0)))
{
base = ERC20(_base);
decimals = ERC20(_base).decimals();
vault = BoringVault(payable(_vault));
ONE_SHARE = 10 ** vault.decimals();
accountantState = AccountantState({
_payoutAddress: _payoutAddress,
_feesOwedInBase: 0,
_totalSharesLastUpdate: uint128(vault.totalSupply()),
_exchangeRate: _startingExchangeRate,
_allowedExchangeRateChangeUpper: _allowedExchangeRateChangeUpper,
_allowedExchangeRateChangeLower: _allowedExchangeRateChangeLower,
_lastUpdateTimestamp: uint64(block.timestamp),
_isPaused: false,
_minimumUpdateDelayInSeconds: _minimumUpdateDelayInSeconds,
_managementFee: _managementFee
});
lendingInfo._lastAccrualTime = block.timestamp;
maxLendingRate = 5000;
}
// ========================================= ADMIN FUNCTIONS =========================================
/**
* @notice Pause this contract, which prevents future calls to `updateExchangeRate`, and any safe rate
* calls will revert.
* @dev Pausing only prevents state changes, not time-based calculations
* @dev Callable by MULTISIG_ROLE.
*/
function pause() public requiresAuth {
accountantState._isPaused = true;
emit Paused();
}
/**
* @notice Unpause this contract, which allows future calls to `updateExchangeRate`, and any safe rate
* calls will stop reverting.
* @dev Callable by MULTISIG_ROLE.
*/
function unpause() external requiresAuth {
accountantState._isPaused = false;
emit Unpaused();
}
/**
* @notice Update the minimum time delay between `updateExchangeRate` calls.
* @dev There are no input requirements, as it is possible the admin would want
* the exchange rate updated as frequently as needed.
* @dev Callable by OWNER_ROLE.
*/
function updateDelay(uint32 _minimumUpdateDelayInSeconds) external requiresAuth {
if (_minimumUpdateDelayInSeconds > 14 days) revert AccountantWithRateProviders__UpdateDelayTooLarge();
uint32 oldDelay = accountantState._minimumUpdateDelayInSeconds;
accountantState._minimumUpdateDelayInSeconds = _minimumUpdateDelayInSeconds;
emit DelayInSecondsUpdated(oldDelay, _minimumUpdateDelayInSeconds);
}
/**
* @notice Update the allowed upper bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateUpper(uint16 _allowedExchangeRateChangeUpper) external requiresAuth {
if (_allowedExchangeRateChangeUpper <= accountantState._allowedExchangeRateChangeLower) {
revert AccountantWithRateProviders__UpperMustExceedLower();
}
if (_allowedExchangeRateChangeUpper < BASIS_POINTS) revert AccountantWithRateProviders__UpperBoundTooSmall();
uint16 oldBound = accountantState._allowedExchangeRateChangeUpper;
accountantState._allowedExchangeRateChangeUpper = _allowedExchangeRateChangeUpper;
emit UpperBoundUpdated(oldBound, _allowedExchangeRateChangeUpper);
}
/**
* @notice Update the allowed lower bound change of exchange rate between `updateExchangeRateCalls`.
* @dev Callable by OWNER_ROLE.
*/
function updateLower(uint16 _allowedExchangeRateChangeLower) external requiresAuth {
if (_allowedExchangeRateChangeLower >= accountantState._allowedExchangeRateChangeUpper) {
revert AccountantWithRateProviders__UpperMustExceedLower();
}
if (_allowedExchangeRateChangeLower > BASIS_POINTS) revert AccountantWithRateProviders__LowerBoundTooLarge();
uint16 oldBound = accountantState._allowedExchangeRateChangeLower;
accountantState._allowedExchangeRateChangeLower = _allowedExchangeRateChangeLower;
emit LowerBoundUpdated(oldBound, _allowedExchangeRateChangeLower);
}
/**
* @notice Update the payout address fees are sent to.
* @dev Callable by OWNER_ROLE.
*/
function updatePayoutAddress(address _payoutAddress) external requiresAuth {
address oldPayout = accountantState._payoutAddress;
accountantState._payoutAddress = _payoutAddress;
emit PayoutAddressUpdated(oldPayout, _payoutAddress);
}
/**
* @notice Update the rate provider data for a specific `asset`.
* @dev Rate providers must return rates in terms of `base`
* @dev Rate providers MUST ALWAYS return rates in 18 decimals regardless of asset decimals
* @dev The rate should represent how much base value 1 unit of asset is worth
* @dev Callable by OWNER_ROLE.
*/
function setRateProviderData(ERC20 _asset, bool _isPeggedToBase, address _rateProvider) external requiresAuth {
rateProviderData[_asset] =
RateProviderData({ isPeggedToBase: _isPeggedToBase, rateProvider: IRateProvider(_rateProvider) });
emit RateProviderUpdated(address(_asset), _isPeggedToBase, _rateProvider);
}
// ========================================= UPDATE EXCHANGE RATE/FEES FUNCTIONS
// =========================================
/**
* @notice Updates this contract exchangeRate.
* @dev If new exchange rate is outside of accepted bounds, or if not enough time has passed, this
* will pause the contract, and this function will NOT calculate fees owed.
* @dev Callable by UPDATE_EXCHANGE_RATE_ROLE.
*/
function updateExchangeRate(uint96 _newExchangeRate) external requiresAuth {
AccountantState storage state = accountantState;
uint64 currentTime = uint64(block.timestamp);
(uint96 currentRateWithInterest,) = calculateExchangeRateWithInterest();
uint96 oldExchangeRate = state._exchangeRate;
_checkpointInterestAndFees();
uint256 currentTotalShares = vault.totalSupply();
if (
currentTime < state._lastUpdateTimestamp + state._minimumUpdateDelayInSeconds
|| _newExchangeRate
> uint256(currentRateWithInterest).mulDivDown(state._allowedExchangeRateChangeUpper, BASIS_POINTS)
|| _newExchangeRate
< uint256(currentRateWithInterest).mulDivDown(state._allowedExchangeRateChangeLower, BASIS_POINTS)
) {
pause();
}
// Always update the rate and timestamp
state._exchangeRate = _newExchangeRate;
state._totalSharesLastUpdate = uint128(currentTotalShares);
state._lastUpdateTimestamp = currentTime;
emit ExchangeRateUpdated(oldExchangeRate, _newExchangeRate, currentTime);
}
/**
* @notice Set lending rate
* @dev Checkpoints current interest and management fees before changing rate
* @dev This prevents loss of accrued value when rate changes
* @param _lendingRate New lending rate in basis points (1000 = 10% APY)
*/
function setLendingRate(uint256 _lendingRate) external requiresAuth {
require(_lendingRate <= maxLendingRate, "Lending rate exceeds maximum");
// Checkpoint both interest and fees before rate change
_checkpointInterestAndFees();
lendingInfo._lendingRate = _lendingRate;
emit LendingRateUpdated(_lendingRate, block.timestamp);
}
/**
* @notice Set management fee rate (requires checkpoint)
* @dev Checkpoints current management fees at old rate before changing
* @dev This ensures fees are correctly attributed to each rate period
* @param _managementFeeRate New management fee rate in basis points
*/
function setManagementFeeRate(uint16 _managementFeeRate) external requiresAuth {
if (_managementFeeRate > 0.2e4) revert AccountantWithRateProviders__ManagementFeeTooLarge();
_checkpointInterestAndFees();
accountantState._managementFee = _managementFeeRate;
emit ManagementFeeRateUpdated(_managementFeeRate, block.timestamp);
}
/**
* @notice Set maximum lending rate
* @dev Callable by OWNER_ROLE
*/
function setMaxLendingRate(uint256 _maxLendingRate) external requiresAuth {
_checkpointInterestAndFees();
maxLendingRate = _maxLendingRate;
// Adjust current rate if needed
if (lendingInfo._lendingRate > _maxLendingRate) {
lendingInfo._lendingRate = _maxLendingRate;
emit LendingRateUpdated(_maxLendingRate, block.timestamp);
}
emit MaxLendingRateUpdated(_maxLendingRate);
}
/**
* @notice Claim pending fees.
* @dev This function must be called by the BoringVault.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the _feeAsset's decimals.
*/
function claimFees(ERC20 _feeAsset) external {
if (msg.sender != address(vault)) revert AccountantWithRateProviders__OnlyCallableByBoringVault();
AccountantState storage state = accountantState;
if (state._isPaused) revert AccountantWithRateProviders__Paused();
_checkpointInterestAndFees();
if (state._feesOwedInBase == 0) revert AccountantWithRateProviders__ZeroFeesOwed();
// Determine amount of fees owed in _feeAsset
uint256 feesOwedInFeeAsset;
RateProviderData memory data = rateProviderData[_feeAsset];
if (address(_feeAsset) == address(base)) {
feesOwedInFeeAsset = state._feesOwedInBase;
} else {
uint8 feeAssetDecimals = ERC20(_feeAsset).decimals();
uint256 feesOwedInBaseUsingFeeAssetDecimals =
_changeDecimals(state._feesOwedInBase, decimals, feeAssetDecimals);
if (data.isPeggedToBase) {
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals;
} else {
uint256 rate = data.rateProvider.getRate();
feesOwedInFeeAsset = feesOwedInBaseUsingFeeAssetDecimals.mulDivDown(10 ** 18, rate);
}
}
// Zero out fees owed
state._feesOwedInBase = 0;
// Transfer fee asset to payout address
_feeAsset.safeTransferFrom(msg.sender, state._payoutAddress, feesOwedInFeeAsset);
emit FeesClaimed(address(_feeAsset), feesOwedInFeeAsset);
}
// ========================================= RATE FUNCTIONS =========================================
/**
* @notice Get this BoringVault's current rate in the base (real-time with interest).
*/
function getRate() public view returns (uint256 rate) {
(uint96 currentRate,) = calculateExchangeRateWithInterest();
return currentRate;
}
/**
* @notice Calculate current exchange rate including accrued interest
* @dev This is a view function - interest continues accruing even when paused
* @return newRate The exchange rate including accrued interest
* @return interestAccrued The amount of interest accrued since last checkpoint
*/
function calculateExchangeRateWithInterest() public view returns (uint96 newRate, uint256 interestAccrued) {
newRate = accountantState._exchangeRate;
if (lendingInfo._lendingRate > 0) {
uint256 timeElapsed = block.timestamp - lendingInfo._lastAccrualTime;
// Calculate rate increase in 18 decimals
uint256 rateIncrease = uint256(accountantState._exchangeRate)
.mulDivDown(lendingInfo._lendingRate * timeElapsed, SECONDS_PER_YEAR * BASIS_POINTS);
newRate = accountantState._exchangeRate + uint96(rateIncrease);
// Interest accrued is only for actual deposits
if (vault.totalSupply() > 0) {
// Calculate in 18 decimals, then convert to base decimals
uint256 totalDepositsIn18 = vault.totalSupply().mulDivDown(newRate, ONE_SHARE);
uint256 totalDeposits = _changeDecimals(totalDepositsIn18, 18, decimals);
interestAccrued =
totalDeposits.mulDivDown(lendingInfo._lendingRate * timeElapsed, SECONDS_PER_YEAR * BASIS_POINTS);
}
}
}
/**
* @notice Get this BoringVault's current rate in the base.
* @dev Revert if paused.
*/
function getRateSafe() external view returns (uint256 rate) {
if (accountantState._isPaused) revert AccountantWithRateProviders__Paused();
(uint96 currentRate,) = calculateExchangeRateWithInterest();
rate = currentRate;
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev This function will lose precision if the exchange rate
* decimals is greater than the _quote's decimals.
*/
function getRateInQuote(ERC20 _quote) public view returns (uint256 rateInQuote) {
// Get real-time rate in 18 decimals
(uint96 currentRate,) = calculateExchangeRateWithInterest();
if (address(_quote) == address(base)) {
// Convert from 18 decimals to base decimals for display
rateInQuote = _changeDecimals(currentRate, 18, decimals);
} else {
RateProviderData memory data = rateProviderData[_quote];
uint8 quoteDecimals = ERC20(_quote).decimals();
if (data.isPeggedToBase) {
// Convert from 18 decimals to quote decimals
rateInQuote = _changeDecimals(currentRate, 18, quoteDecimals);
} else {
// Rate provider should return 18 decimals
uint256 quoteRate = data.rateProvider.getRate();
// Calculate: currentRate * 1e18 / quoteRate, then scale to quote decimals
uint256 rateInQuote18 = uint256(currentRate).mulDivDown(1e18, quoteRate);
rateInQuote = _changeDecimals(rateInQuote18, 18, quoteDecimals);
}
}
}
/**
* @notice Get this BoringVault's current rate in the provided quote.
* @dev `quote` must have its RateProviderData set, else this will revert.
* @dev Revert if paused.
*/
function getRateInQuoteSafe(ERC20 _quote) external view returns (uint256 rateInQuote) {
if (accountantState._isPaused) revert AccountantWithRateProviders__Paused();
rateInQuote = getRateInQuote(_quote);
}
/**
* @notice Get total rate paid by borrower
* @dev This is the sum of lending rate (for depositors) and management fee rate
* @return Total borrower rate in basis points
*/
function getBorrowerRate() public view returns (uint256) {
return lendingInfo._lendingRate + accountantState._managementFee;
}
/**
* @notice Preview total management fees owed including unclaimed
* @dev Calculates real-time fees without modifying state
* @dev Includes both stored fees and fees accrued since last checkpoint
* @return totalFees Total management fees owed in base asset
*/
function previewFeesOwed() external view returns (uint256 totalFees) {
totalFees = accountantState._feesOwedInBase;
if (vault.totalSupply() > 0 && accountantState._managementFee > 0) {
uint256 timeElapsed = block.timestamp - lendingInfo._lastAccrualTime;
(uint96 currentRate,) = calculateExchangeRateWithInterest();
uint256 totalDepositsIn18 = vault.totalSupply().mulDivDown(currentRate, ONE_SHARE);
// Convert to base decimals for fee calculation
uint256 totalDeposits = _changeDecimals(totalDepositsIn18, 18, decimals);
uint256 managementFees =
totalDeposits.mulDivDown(accountantState._managementFee * timeElapsed, SECONDS_PER_YEAR * BASIS_POINTS);
totalFees += managementFees;
}
}
// ========================================= INTERNAL HELPER FUNCTIONS =========================================
/**
* @notice Checkpoint both interest and management fees
* @dev Updates exchange rate with interest and feesOwedInBase with management fees
*/
function _checkpointInterestAndFees() internal {
uint256 timeElapsed = block.timestamp - lendingInfo._lastAccrualTime;
if (timeElapsed > 0) {
(uint96 newRate,) = calculateExchangeRateWithInterest();
accountantState._exchangeRate = newRate;
// Only calculate management fees when there are actual deposits
if (vault.totalSupply() > 0 && accountantState._managementFee > 0) {
// Calculate value in 18 decimals, then convert to base decimals for fee storage
uint256 totalValueIn18 = vault.totalSupply().mulDivDown(newRate, ONE_SHARE);
uint256 totalValue = _changeDecimals(totalValueIn18, 18, decimals);
uint256 managementFees = totalValue.mulDivDown(
accountantState._managementFee * timeElapsed, SECONDS_PER_YEAR * BASIS_POINTS
);
accountantState._feesOwedInBase += uint128(managementFees);
}
lendingInfo._lastAccrualTime = block.timestamp;
emit Checkpoint(block.timestamp);
}
}
/**
* @notice Updates the stored exchange rate and accrues management fees
* @dev Should be called before any operation that depends on the current exchange rate
* @dev This includes deposits, withdrawals, and fee calculations
* @dev Callable by authorized contracts (Teller) to ensure rate consistency
*/
function checkpoint() external requiresAuth {
require(!accountantState._isPaused, "Cannot checkpoint when paused");
_checkpointInterestAndFees();
}
/**
* @notice Used to change the decimals of precision used for an amount.
*/
function _changeDecimals(uint256 _amount, uint8 _fromDecimals, uint8 _toDecimals) internal pure returns (uint256) {
if (_fromDecimals == _toDecimals) {
return _amount;
} else if (_fromDecimals < _toDecimals) {
return _amount * 10 ** (_toDecimals - _fromDecimals);
} else {
return _amount / 10 ** (_fromDecimals - _toDecimals);
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol)
/// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol)
library FixedPointMathLib {
/*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
uint256 internal constant MAX_UINT256 = 2**256 - 1;
uint256 internal constant WAD = 1e18; // The scalar of ETH and most ERC20s.
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down.
}
function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up.
}
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down.
}
function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) {
return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up.
}
/*//////////////////////////////////////////////////////////////
LOW LEVEL FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/
function mulDivDown(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// Divide x * y by the denominator.
z := div(mul(x, y), denominator)
}
}
function mulDivUp(
uint256 x,
uint256 y,
uint256 denominator
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Equivalent to require(denominator != 0 && (y == 0 || x <= type(uint256).max / y))
if iszero(mul(denominator, iszero(mul(y, gt(x, div(MAX_UINT256, y)))))) {
revert(0, 0)
}
// If x * y modulo the denominator is strictly greater than 0,
// 1 is added to round up the division of x * y by the denominator.
z := add(gt(mod(mul(x, y), denominator), 0), div(mul(x, y), denominator))
}
}
function rpow(
uint256 x,
uint256 n,
uint256 scalar
) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
switch x
case 0 {
switch n
case 0 {
// 0 ** 0 = 1
z := scalar
}
default {
// 0 ** n = 0
z := 0
}
}
default {
switch mod(n, 2)
case 0 {
// If n is even, store scalar in z for now.
z := scalar
}
default {
// If n is odd, store x in z for now.
z := x
}
// Shifting right by 1 is like dividing by 2.
let half := shr(1, scalar)
for {
// Shift n right by 1 before looping to halve it.
n := shr(1, n)
} n {
// Shift n right by 1 each iteration to halve it.
n := shr(1, n)
} {
// Revert immediately if x ** 2 would overflow.
// Equivalent to iszero(eq(div(xx, x), x)) here.
if shr(128, x) {
revert(0, 0)
}
// Store x squared.
let xx := mul(x, x)
// Round to the nearest number.
let xxRound := add(xx, half)
// Revert if xx + half overflowed.
if lt(xxRound, xx) {
revert(0, 0)
}
// Set x to scaled xxRound.
x := div(xxRound, scalar)
// If n is even:
if mod(n, 2) {
// Compute z * x.
let zx := mul(z, x)
// If z * x overflowed:
if iszero(eq(div(zx, x), z)) {
// Revert if x is non-zero.
if iszero(iszero(x)) {
revert(0, 0)
}
}
// Round to the nearest number.
let zxRound := add(zx, half)
// Revert if zx + half overflowed.
if lt(zxRound, zx) {
revert(0, 0)
}
// Return properly scaled zxRound.
z := div(zxRound, scalar)
}
}
}
}
}
/*//////////////////////////////////////////////////////////////
GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
let y := x // We start y at x, which will help us make our initial estimate.
z := 181 // The "correct" value is 1, but this saves a multiplication later.
// This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
// start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.
// We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) {
y := shr(128, y)
z := shl(64, z)
}
if iszero(lt(y, 0x1000000000000000000)) {
y := shr(64, y)
z := shl(32, z)
}
if iszero(lt(y, 0x10000000000)) {
y := shr(32, y)
z := shl(16, z)
}
if iszero(lt(y, 0x1000000)) {
y := shr(16, y)
z := shl(8, z)
}
// Goal was to get z*z*y within a small factor of x. More iterations could
// get y in a tighter range. Currently, we will have y in [256, 256*2^16).
// We ensured y >= 256 so that the relative difference between y and y+1 is small.
// That's not possible if x < 256 but we can just verify those cases exhaustively.
// Now, z*z*y <= x < z*z*(y+1), and y <= 2^(16+8), and either y >= 256, or x < 256.
// Correctness can be checked exhaustively for x < 256, so we assume y >= 256.
// Then z*sqrt(y) is within sqrt(257)/sqrt(256) of sqrt(x), or about 20bps.
// For s in the range [1/256, 256], the estimate f(s) = (181/1024) * (s+1) is in the range
// (1/2.84 * sqrt(s), 2.84 * sqrt(s)), with largest error when s = 1 and when s = 256 or 1/256.
// Since y is in [256, 256*2^16), let a = y/65536, so that a is in [1/256, 256). Then we can estimate
// sqrt(y) using sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2^18.
// There is no overflow risk here since y < 2^136 after the first branch above.
z := shr(18, mul(z, add(y, 65536))) // A mul() is saved from starting z at 181.
// Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough.
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
z := shr(1, add(z, div(x, z)))
// If x+1 is a perfect square, the Babylonian method cycles between
// floor(sqrt(x)) and ceil(sqrt(x)). This statement ensures we return floor.
// See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division
// Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
// If you don't care whether the floor or ceil square root is returned, you can remove this statement.
z := sub(z, lt(div(x, z), z))
}
}
function unsafeMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Mod x by y. Note this will return
// 0 instead of reverting if y is zero.
z := mod(x, y)
}
}
function unsafeDiv(uint256 x, uint256 y) internal pure returns (uint256 r) {
/// @solidity memory-safe-assembly
assembly {
// Divide x by y. Note this will return
// 0 instead of reverting if y is zero.
r := div(x, y)
}
}
function unsafeDivUp(uint256 x, uint256 y) internal pure returns (uint256 z) {
/// @solidity memory-safe-assembly
assembly {
// Add 1 to x * y if x % y > 0. Note this will
// return 0 instead of reverting if y is zero.
z := add(gt(mod(x, y), 0), div(x, y))
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(
ERC20 token,
address from,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(
ERC20 token,
address to,
uint256 amount
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
interface BeforeTransferHook {
function beforeTransfer(address from) external view;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
abstract contract Auth {
event OwnershipTransferred(address indexed user, address indexed newOwner);
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
address public owner;
Authority public authority;
constructor(address _owner, Authority _authority) {
owner = _owner;
authority = _authority;
emit OwnershipTransferred(msg.sender, _owner);
emit AuthorityUpdated(msg.sender, _authority);
}
modifier requiresAuth() virtual {
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
_;
}
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
}
function setAuthority(Authority newAuthority) public virtual {
// We check if the caller is the owner first because we want to ensure they can
// always swap out the authority even if it's reverting or using up a lot of gas.
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
authority = newAuthority;
emit AuthorityUpdated(msg.sender, newAuthority);
}
function transferOwnership(address newOwner) public virtual requiresAuth {
owner = newOwner;
emit OwnershipTransferred(msg.sender, newOwner);
}
}
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Auth.sol)
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
interface Authority {
function canCall(
address user,
address target,
bytes4 functionSig
) external view returns (bool);
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Gas optimized reentrancy protection for smart contracts.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ReentrancyGuard.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/security/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
uint256 private locked = 1;
modifier nonReentrant() virtual {
require(locked == 1, "REENTRANCY");
locked = 2;
_;
locked = 1;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.22;
interface IKeyring {
function checkCredential(uint256 policyId, address entity) external view returns (bool);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity ^0.8.0;
interface IRateProvider {
function getRate() external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);
event PacketDelivered(Origin origin, address receiver);
event LzReceiveAlert(
address indexed receiver,
address indexed executor,
Origin origin,
bytes32 guid,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
event LzTokenSet(address token);
event DelegateSet(address sender, address delegate);
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);
function send(
MessagingParams calldata _params,
address _refundAddress
) external payable returns (MessagingReceipt memory);
function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);
function initializable(Origin calldata _origin, address _receiver) external view returns (bool);
function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable;
// oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
function setLzToken(address _lzToken) external;
function lzToken() external view returns (address);
function nativeToken() external view returns (address);
function setDelegate(address _delegate) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "./interfaces/IOAppCore.sol";
/**
* @title OAppCore
* @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
*/
abstract contract OAppCore is IOAppCore, Ownable {
// The LayerZero endpoint associated with the given OApp
ILayerZeroEndpointV2 public immutable endpoint;
// Mapping to store peers associated with corresponding endpoints
mapping(uint32 eid => bytes32 peer) public peers;
/**
* @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
* @param _endpoint The address of the LOCAL Layer Zero endpoint.
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
*
* @dev The delegate typically should be set as the owner of the contract.
*/
constructor(address _endpoint, address _delegate) {
endpoint = ILayerZeroEndpointV2(_endpoint);
if (_delegate == address(0)) revert InvalidDelegate();
endpoint.setDelegate(_delegate);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*/
function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
_setPeer(_eid, _peer);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*/
function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
peers[_eid] = _peer;
emit PeerSet(_eid, _peer);
}
/**
* @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
* ie. the peer is set to bytes32(0).
* @param _eid The endpoint ID.
* @return peer The address of the peer associated with the specified endpoint.
*/
function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
bytes32 peer = peers[_eid];
if (peer == bytes32(0)) revert NoPeer(_eid);
return peer;
}
/**
* @notice Sets the delegate address for the OApp.
* @param _delegate The address of the delegate to be set.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
*/
function setDelegate(address _delegate) public onlyOwner {
endpoint.setDelegate(_delegate);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroReceiver, Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol";
interface IOAppReceiver is ILayerZeroReceiver {
/**
* @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
* @param _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @param _message The lzReceive payload.
* @param _sender The sender address.
* @return isSender Is a valid sender.
*
* @dev Applications can optionally choose to implement a separate composeMsg sender that is NOT the bridging layer.
* @dev The default sender IS the OAppReceiver implementer.
*/
function isComposeMsgSender(
Origin calldata _origin,
bytes calldata _message,
address _sender
) external view returns (bool isSender);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
/**
* @title IOAppCore
*/
interface IOAppCore {
// Custom error messages
error OnlyPeer(uint32 eid, bytes32 sender);
error NoPeer(uint32 eid);
error InvalidEndpointCall();
error InvalidDelegate();
// Event emitted when a peer (OApp) is set for a corresponding endpoint
event PeerSet(uint32 eid, bytes32 peer);
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*/
function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);
/**
* @notice Retrieves the LayerZero endpoint associated with the OApp.
* @return iEndpoint The LayerZero endpoint as an interface.
*/
function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);
/**
* @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
* @param _eid The endpoint ID.
* @return peer The peer address (OApp instance) associated with the corresponding endpoint.
*/
function peers(uint32 _eid) external view returns (bytes32 peer);
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*/
function setPeer(uint32 _eid, bytes32 _peer) external;
/**
* @notice Sets the delegate address for the OApp Core.
* @param _delegate The address of the delegate to be set.
*/
function setDelegate(address _delegate) external;
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
library CalldataBytesLib {
function toU8(bytes calldata _bytes, uint256 _start) internal pure returns (uint8) {
return uint8(_bytes[_start]);
}
function toU16(bytes calldata _bytes, uint256 _start) internal pure returns (uint16) {
unchecked {
uint256 end = _start + 2;
return uint16(bytes2(_bytes[_start:end]));
}
}
function toU32(bytes calldata _bytes, uint256 _start) internal pure returns (uint32) {
unchecked {
uint256 end = _start + 4;
return uint32(bytes4(_bytes[_start:end]));
}
}
function toU64(bytes calldata _bytes, uint256 _start) internal pure returns (uint64) {
unchecked {
uint256 end = _start + 8;
return uint64(bytes8(_bytes[_start:end]));
}
}
function toU128(bytes calldata _bytes, uint256 _start) internal pure returns (uint128) {
unchecked {
uint256 end = _start + 16;
return uint128(bytes16(_bytes[_start:end]));
}
}
function toU256(bytes calldata _bytes, uint256 _start) internal pure returns (uint256) {
unchecked {
uint256 end = _start + 32;
return uint256(bytes32(_bytes[_start:end]));
}
}
function toAddr(bytes calldata _bytes, uint256 _start) internal pure returns (address) {
unchecked {
uint256 end = _start + 20;
return address(bytes20(_bytes[_start:end]));
}
}
function toB32(bytes calldata _bytes, uint256 _start) internal pure returns (bytes32) {
unchecked {
uint256 end = _start + 32;
return bytes32(_bytes[_start:end]);
}
}
}// SPDX-License-Identifier: MIT
// modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
pragma solidity ^0.8.20;
type BitMap256 is uint256;
using BitMaps for BitMap256 global;
library BitMaps {
/**
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap256 bitmap, uint8 index) internal pure returns (bool) {
uint256 mask = 1 << index;
return BitMap256.unwrap(bitmap) & mask != 0;
}
/**
* @dev Sets the bit at `index`.
*/
function set(BitMap256 bitmap, uint8 index) internal pure returns (BitMap256) {
uint256 mask = 1 << index;
return BitMap256.wrap(BitMap256.unwrap(bitmap) | mask);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) 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 Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/utils/ERC1155Holder.sol)
pragma solidity ^0.8.20;
import {IERC165, ERC165} from "../../../utils/introspection/ERC165.sol";
import {IERC1155Receiver} from "../IERC1155Receiver.sol";
/**
* @dev Simple implementation of `IERC1155Receiver` that will allow a contract to hold ERC-1155 tokens.
*
* IMPORTANT: When inheriting this contract, you must include a way to use the received tokens, otherwise they will be
* stuck.
*/
abstract contract ERC1155Holder is ERC165, IERC1155Receiver {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
}
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
struct SetConfigParam {
uint32 eid;
uint32 configType;
bytes config;
}
interface IMessageLibManager {
struct Timeout {
address lib;
uint256 expiry;
}
event LibraryRegistered(address newLib);
event DefaultSendLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
event SendLibrarySet(address sender, uint32 eid, address newLib);
event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);
function registerLibrary(address _lib) external;
function isRegisteredLibrary(address _lib) external view returns (bool);
function getRegisteredLibraries() external view returns (address[] memory);
function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
function defaultSendLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function defaultReceiveLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;
function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);
function isSupportedEid(uint32 _eid) external view returns (bool);
function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);
/// ------------------- OApp interfaces -------------------
function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;
function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);
function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;
function getConfig(
address _oapp,
address _lib,
uint32 _eid,
uint32 _configType
) external view returns (bytes memory config);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingComposer {
event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
event LzComposeAlert(
address indexed from,
address indexed to,
address indexed executor,
bytes32 guid,
uint16 index,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
function composeQueue(
address _from,
address _to,
bytes32 _guid,
uint16 _index
) external view returns (bytes32 messageHash);
function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;
function lzCompose(
address _from,
address _to,
bytes32 _guid,
uint16 _index,
bytes calldata _message,
bytes calldata _extraData
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingChannel {
event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
function eid() external view returns (uint32);
// this is an emergency function if a message cannot be verified for some reasons
// required to provide _nextNonce to avoid race condition
function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
function inboundPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bytes32);
function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32 dstEid, address sender);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { Origin } from "./ILayerZeroEndpointV2.sol";
interface ILayerZeroReceiver {
function allowInitializePath(Origin calldata _origin) external view returns (bool);
function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC-721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC-721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC1155/IERC1155Receiver.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Interface that must be implemented by smart contracts in order to receive
* ERC-1155 token transfers.
*/
interface IERC1155Receiver is IERC165 {
/**
* @dev Handles the receipt of a single ERC-1155 token type. This function is
* called at the end of a `safeTransferFrom` after the balance has been updated.
*
* NOTE: To accept the transfer, this must return
* `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))`
* (i.e. 0xf23a6e61, or its own function selector).
*
* @param operator The address which initiated the transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param id The ID of the token being transferred
* @param value The amount of tokens being transferred
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
*/
function onERC1155Received(
address operator,
address from,
uint256 id,
uint256 value,
bytes calldata data
) external returns (bytes4);
/**
* @dev Handles the receipt of a multiple ERC-1155 token types. This function
* is called at the end of a `safeBatchTransferFrom` after the balances have
* been updated.
*
* NOTE: To accept the transfer(s), this must return
* `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))`
* (i.e. 0xbc197c81, or its own function selector).
*
* @param operator The address which initiated the batch transfer (i.e. msg.sender)
* @param from The address which previously owned the token
* @param ids An array containing ids of each token being transferred (order and length must match values array)
* @param values An array containing amounts of each token being transferred (order and length must match ids array)
* @param data Additional data with no specified format
* @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
*/
function onERC1155BatchReceived(
address operator,
address from,
uint256[] calldata ids,
uint256[] calldata values,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}{
"remappings": [
"@solmate/=lib/solmate/src/",
"@forge-std/=lib/forge-std/src/",
"forge-std/=lib/forge-std/src/",
"@ds-test/=lib/forge-std/lib/ds-test/src/",
"ds-test/=lib/forge-std/lib/ds-test/src/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"@ion-protocol/=lib/ion-protocol/src/",
"@layerzerolabs/=node_modules/@layerzerolabs/",
"@axelar-network/=node_modules/@axelar-network/",
"@balancer-labs/v2-interfaces/=lib/ion-protocol/lib/balancer-v2-monorepo/pkg/interfaces/",
"@balancer-labs/v2-pool-stable/=lib/ion-protocol/lib/balancer-v2-monorepo/pkg/pool-stable/",
"@chainlink/=node_modules/@chainlink/",
"@eth-optimism/=node_modules/@eth-optimism/",
"@uniswap/v3-core/=lib/ion-protocol/lib/v3-core/",
"@uniswap/v3-periphery/=lib/ion-protocol/lib/v3-periphery/",
"balancer-v2-monorepo/=lib/ion-protocol/lib/",
"chainlink/=lib/ion-protocol/lib/chainlink/",
"createx/=lib/createx/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-safe/=lib/ion-protocol/lib/forge-safe/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat-deploy/=node_modules/hardhat-deploy/",
"ion-protocol/=lib/ion-protocol/",
"openzeppelin-contracts-upgradeable/=lib/ion-protocol/lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin/=lib/createx/lib/openzeppelin-contracts/contracts/",
"pendle-core-v2-public/=lib/ion-protocol/lib/pendle-core-v2-public/contracts/",
"solady/=lib/ion-protocol/lib/solady/",
"solarray/=lib/ion-protocol/lib/solarray/src/",
"solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
"solidity-stringutils/=lib/ion-protocol/lib/forge-safe/lib/surl/lib/solidity-stringutils/",
"solmate/=lib/solmate/src/",
"surl/=lib/ion-protocol/lib/forge-safe/lib/surl/",
"v3-core/=lib/ion-protocol/lib/v3-core/",
"v3-periphery/=lib/v3-periphery/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "shanghai",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_vault","type":"address"},{"internalType":"address","name":"_accountant","type":"address"},{"internalType":"address","name":"_endpoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidEndpointCall","type":"error"},{"inputs":[{"internalType":"uint16","name":"optionType","type":"uint16"}],"name":"InvalidOptionType","type":"error"},{"inputs":[],"name":"LzTokenUnavailable","type":"error"},{"inputs":[],"name":"MultiChainLayerZeroTellerWithMultiAssetSupport_InvalidToken","type":"error"},{"inputs":[],"name":"MultiChainTellerBase_DestinationChainReceiverIsZeroAddress","type":"error"},{"inputs":[],"name":"MultiChainTellerBase_GasLimitExceeded","type":"error"},{"inputs":[],"name":"MultiChainTellerBase_GasTooLow","type":"error"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"}],"name":"MultiChainTellerBase_MessagesNotAllowedFrom","type":"error"},{"inputs":[{"internalType":"uint256","name":"chainSelector","type":"uint256"}],"name":"MultiChainTellerBase_MessagesNotAllowedTo","type":"error"},{"inputs":[],"name":"MultiChainTellerBase_TargetTellerIsZeroAddress","type":"error"},{"inputs":[],"name":"MultiChainTellerBase_ZeroMessageGasLimit","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"NoPeer","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"}],"name":"NotEnoughNative","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"OnlyEndpoint","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"OnlyPeer","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__AssetNotSupported","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__BadDepositHash","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__KeyringCredentialInvalid","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__MinimumAssetsNotMet","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__MinimumMintNotMet","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__NotWhitelisted","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__Paused","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__PermitFailedAndAllowanceTooLow","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__ShareLockPeriodTooLong","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__SharesAreLocked","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__SharesAreUnLocked","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__ZeroAssets","type":"error"},{"inputs":[],"name":"TellerWithMultiAssetSupport__ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"enum TellerWithMultiAssetSupport.AccessControlMode","name":"oldMode","type":"uint8"},{"indexed":false,"internalType":"enum TellerWithMultiAssetSupport.AccessControlMode","name":"newMode","type":"uint8"}],"name":"AccessControlModeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"}],"name":"AssetAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"}],"name":"AssetRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"AuthorityUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_depositAmount","type":"uint256"}],"name":"BulkDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_shareAmount","type":"uint256"}],"name":"BulkWithdraw","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"},{"indexed":false,"internalType":"bool","name":"allowMessagesFrom","type":"bool"},{"indexed":false,"internalType":"bool","name":"allowMessagesTo","type":"bool"},{"indexed":false,"internalType":"address","name":"targetTeller","type":"address"},{"indexed":false,"internalType":"uint64","name":"messageGasLimit","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"messageGasMin","type":"uint64"}],"name":"ChainAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"},{"indexed":false,"internalType":"address","name":"targetTeller","type":"address"}],"name":"ChainAllowMessagesFrom","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"},{"indexed":false,"internalType":"address","name":"targetTeller","type":"address"}],"name":"ChainAllowMessagesTo","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"}],"name":"ChainRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"messageGasLimit","type":"uint64"}],"name":"ChainSetGasLimit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"}],"name":"ChainStopMessagesFrom","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"chainSelector","type":"uint256"}],"name":"ChainStopMessagesTo","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"ContractWhitelistUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"_depositAsset","type":"address"},{"indexed":false,"internalType":"uint256","name":"_depositAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_shareAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"depositTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shareLockPeriodAtTimeOfDeposit","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldCap","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newCap","type":"uint256"}],"name":"DepositCapUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"nonce","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"depositHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"DepositRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"keyringContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"policyId","type":"uint256"}],"name":"KeyringConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"ManualWhitelistUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"messageId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"shareAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"MessageReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"messageId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"shareAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"}],"name":"MessageSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"eid","type":"uint32"},{"indexed":false,"internalType":"bytes32","name":"peer","type":"bytes32"}],"name":"PeerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPeriod","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPeriod","type":"uint64"}],"name":"ShareLockPeriodUpdated","type":"event"},{"anonymous":false,"inputs":[],"name":"Unpaused","type":"event"},{"inputs":[],"name":"accessControlMode","outputs":[{"internalType":"enum TellerWithMultiAssetSupport.AccessControlMode","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accountant","outputs":[{"internalType":"contract AccountantWithRateProviders","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_asset","type":"address"}],"name":"addAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"bool","name":"allowMessagesFrom","type":"bool"},{"internalType":"bool","name":"allowMessagesTo","type":"bool"},{"internalType":"address","name":"targetTeller","type":"address"},{"internalType":"uint64","name":"messageGasLimit","type":"uint64"},{"internalType":"uint64","name":"messageGasMin","type":"uint64"}],"name":"addChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"address","name":"targetTeller","type":"address"}],"name":"allowMessagesFromChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"address","name":"targetTeller","type":"address"},{"internalType":"uint64","name":"messageGasLimit","type":"uint64"}],"name":"allowMessagesToChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"authority","outputs":[{"internalType":"contract Authority","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"}],"name":"beforeTransfer","outputs":[],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareAmount","type":"uint256"},{"components":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"address","name":"destinationChainReceiver","type":"address"},{"internalType":"contract ERC20","name":"bridgeFeeToken","type":"address"},{"internalType":"uint64","name":"messageGas","type":"uint64"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct BridgeData","name":"data","type":"tuple"}],"name":"bridge","outputs":[{"internalType":"bytes32","name":"messageId","type":"bytes32"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_depositAsset","type":"address"},{"internalType":"uint256","name":"_depositAmount","type":"uint256"},{"internalType":"uint256","name":"_minimumMint","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"bulkDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_withdrawAsset","type":"address"},{"internalType":"uint256","name":"_shareAmount","type":"uint256"},{"internalType":"uint256","name":"_minimumAssets","type":"uint256"},{"internalType":"address","name":"_to","type":"address"}],"name":"bulkWithdraw","outputs":[{"internalType":"uint256","name":"assetsOut","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"contractWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_depositAsset","type":"address"},{"internalType":"uint256","name":"_depositAmount","type":"uint256"},{"internalType":"uint256","name":"_minimumMint","type":"uint256"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"depositAsset","type":"address"},{"internalType":"uint256","name":"depositAmount","type":"uint256"},{"internalType":"uint256","name":"minimumMint","type":"uint256"},{"components":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"address","name":"destinationChainReceiver","type":"address"},{"internalType":"contract ERC20","name":"bridgeFeeToken","type":"address"},{"internalType":"uint64","name":"messageGas","type":"uint64"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct BridgeData","name":"data","type":"tuple"}],"name":"depositAndBridge","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"depositCap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"depositNonce","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_depositAsset","type":"address"},{"internalType":"uint256","name":"_depositAmount","type":"uint256"},{"internalType":"uint256","name":"_minimumMint","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"uint8","name":"_v","type":"uint8"},{"internalType":"bytes32","name":"_r","type":"bytes32"},{"internalType":"bytes32","name":"_s","type":"bytes32"}],"name":"depositWithPermit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"internalType":"contract ILayerZeroEndpointV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"","type":"tuple"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"address","name":"_sender","type":"address"}],"name":"isComposeMsgSender","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"name":"isSupported","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keyringContract","outputs":[{"internalType":"contract IKeyring","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keyringPolicyId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"_origin","type":"tuple"},{"internalType":"bytes32","name":"_guid","type":"bytes32"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"address","name":"_executor","type":"address"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"manualWhitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"nextNonce","outputs":[{"internalType":"uint64","name":"nonce","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oAppVersion","outputs":[{"internalType":"uint64","name":"senderVersion","type":"uint64"},{"internalType":"uint64","name":"receiverVersion","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"peers","outputs":[{"internalType":"bytes32","name":"peer","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shareAmount","type":"uint256"},{"components":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"address","name":"destinationChainReceiver","type":"address"},{"internalType":"contract ERC20","name":"bridgeFeeToken","type":"address"},{"internalType":"uint64","name":"messageGas","type":"uint64"},{"internalType":"bytes","name":"data","type":"bytes"}],"internalType":"struct BridgeData","name":"data","type":"tuple"}],"name":"previewFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"publicDepositHistory","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"address","name":"_depositAsset","type":"address"},{"internalType":"uint256","name":"_depositAmount","type":"uint256"},{"internalType":"uint256","name":"_shareAmount","type":"uint256"},{"internalType":"uint256","name":"_depositTimestamp","type":"uint256"},{"internalType":"uint256","name":"_shareLockUpPeriodAtTimeOfDeposit","type":"uint256"}],"name":"refundDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"_asset","type":"address"}],"name":"removeAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"}],"name":"removeChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"selectorToChains","outputs":[{"internalType":"bool","name":"allowMessagesFrom","type":"bool"},{"internalType":"bool","name":"allowMessagesTo","type":"bool"},{"internalType":"address","name":"targetTeller","type":"address"},{"internalType":"uint64","name":"messageGasLimit","type":"uint64"},{"internalType":"uint64","name":"minimumMessageGas","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"enum TellerWithMultiAssetSupport.AccessControlMode","name":"_mode","type":"uint8"}],"name":"setAccessControlMode","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract Authority","name":"newAuthority","type":"address"}],"name":"setAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"},{"internalType":"uint64","name":"messageGasLimit","type":"uint64"}],"name":"setChainGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_depositCap","type":"uint256"}],"name":"setDepositCap","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_keyringContract","type":"address"},{"internalType":"uint256","name":"_policyId","type":"uint256"}],"name":"setKeyringConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"bytes32","name":"_peer","type":"bytes32"}],"name":"setPeer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_shareLockPeriod","type":"uint64"}],"name":"setShareLockPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shareLockPeriod","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"shareUnlockTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"}],"name":"stopMessagesFromChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"chainSelector","type":"uint32"}],"name":"stopMessagesToChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_addresses","type":"address[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"updateContractWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_addresses","type":"address[]"},{"internalType":"bool","name":"_status","type":"bool"}],"name":"updateManualWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vault","outputs":[{"internalType":"contract BoringVault","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
61010060405260016002819055600580546001600160601b03191690911790553480156200002b575f80fd5b50604051620055bb380380620055bb8339810160408190526200004e9162000237565b5f80546001600160a01b0386166001600160a01b03199182168117835560018054909216909155604051839287928492849283928a928a928592859285928592859285928592909133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908490a36040516001600160a01b0382169033907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350506001600160a01b03821660808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa1580156200013d573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019062000163919062000291565b6200017090600a620003c9565b60c0526001600160a01b0390811660a0528a811660e05289169750620001b1965050505050505057604051632d618d8160e21b815260040160405180910390fd5b60e05160405163ca5eb5e160e01b81526001600160a01b0383811660048301529091169063ca5eb5e1906024015f604051808303815f87803b158015620001f6575f80fd5b505af115801562000209573d5f803e3d5ffd5b505050505050505050505050620003d9565b80516001600160a01b038116811462000232575f80fd5b919050565b5f805f80608085870312156200024b575f80fd5b62000256856200021b565b935062000266602086016200021b565b925062000276604086016200021b565b915062000286606086016200021b565b905092959194509250565b5f60208284031215620002a2575f80fd5b815160ff81168114620002b3575f80fd5b9392505050565b634e487b7160e01b5f52601160045260245ffd5b600181815b808511156200030e57815f1904821115620002f257620002f2620002ba565b808516156200030057918102915b93841c9390800290620002d3565b509250929050565b5f826200032657506001620003c3565b816200033457505f620003c3565b81600181146200034d5760028114620003585762000378565b6001915050620003c3565b60ff8411156200036c576200036c620002ba565b50506001821b620003c3565b5060208310610133831016604e8410600b84101617156200039d575081810a620003c3565b620003a98383620002ce565b805f1904821115620003bf57620003bf620002ba565b0290505b92915050565b5f620002b360ff84168362000316565b60805160a05160c05160e0516150c7620004f45f395f81816106d301528181610e5d01528181612b3a01528181613fb7015281816140a1015281816142db015261439201525f81816119c60152818161343b0152818161348b015261351c01525f8181610669015281816118cf0152818161193e015281816119ee01528181611a8c01528181611b3701528181611c140152818161204201528181612fd101528181613040015281816130c30152818161315f0152818161320c015281816132e7015281816134b9015281816135cc01526138e201525f8181610aac01528181611550015281816115f001528181611d99015281816120af015281816128f70152818161353d01528181613692015261397b01526150c75ff3fe608060405260043610610327575f3560e01c80638456cb59116101a3578063d555f368116100f2578063e329820811610092578063f2fde38b1161006d578063f2fde38b14610a7c578063fbfa77cf14610a9b578063ff7bd03d14610ace578063ffc19a0114610aed575f80fd5b8063e329820814610a1a578063e83931af14610a39578063f11a8ca514610a58575f80fd5b8063dbab77b6116100cd578063dbab77b614610989578063dbd5edc7146109a8578063de35f5cb146109bd578063e11484c0146109f4575f80fd5b8063d555f36814610927578063d636b05f14610946578063d9e9c9781461095b575f80fd5b8063a69559d11161015d578063bd0d9cbd11610138578063bd0d9cbd146108b7578063bf7e214f146108d6578063bfe1a0f2146108f5578063ca5eb5e114610908575f80fd5b8063a69559d114610859578063b187bd261461086c578063bb0b6a531461088c575f80fd5b80638456cb591461079857806386651203146107ac5780638da5cb5b146107cb5780639a94d3d0146107e95780639d574420146108145780639fdb11b614610833575f80fd5b80633e64ce99116102795780634fb3ccc5116102195780637a9e5e4b116101f45780637a9e5e4b146106f55780637bb4122e146107145780637d25a05e1461073357806382413eac1461076a575f80fd5b80634fb3ccc51461065857806355a2d64d146106a35780635e280f11146106c2575f80fd5b806346b563f41161025457806346b563f4146105ae5780634a5e42b1146105cd5780634c999f5e146105ec5780634f129c531461062a575f80fd5b80633e64ce991461055c5780633f4ba83a1461057b57806345ad60631461058f575f80fd5b80632264e930116102e45780633400288b116102bf5780633400288b146104595780633c5722c9146104785780633d4bd6fe146104975780633d935d9e1461053d575f80fd5b80632264e930146103fc578063287fc8251461041b578063298410e51461043a575f80fd5b80630efe6a8b1461032b57806312056e2d1461035d57806313137d651461037e57806317442b70146103915780631899ea81146103b2578063202eac57146103dd575b5f80fd5b348015610336575f80fd5b5061034a6103453660046144ff565b610b0c565b6040519081526020015b60405180910390f35b348015610368575f80fd5b5061037c610377366004614545565b610d8c565b005b61037c61038c3660046145ba565b610e5b565b34801561039c575f80fd5b5060408051600181526002602082015201610354565b3480156103bd575f80fd5b5061034a6103cc366004614652565b60076020525f908152604090205481565b3480156103e8575f80fd5b5061037c6103f7366004614685565b610f16565b348015610407575f80fd5b5061037c6104163660046146ba565b610fd9565b348015610426575f80fd5b5061037c6104353660046146e4565b6110a8565b348015610445575f80fd5b5061037c610454366004614652565b611141565b348015610464575f80fd5b5061037c610473366004614702565b6111bd565b348015610483575f80fd5b5061037c610492366004614737565b6111fc565b3480156104a2575f80fd5b506104fc6104b13660046147b5565b600c6020525f90815260409020805460019091015460ff808316926101008104909116916001600160a01b0362010000830416916001600160401b03600160b01b9091048116911685565b60408051951515865293151560208601526001600160a01b03909216928401929092526001600160401b03918216606084015216608082015260a001610354565b348015610548575f80fd5b5061034a6105573660046147dc565b611302565b348015610567575f80fd5b5061034a61057636600461483f565b6116cd565b348015610586575f80fd5b5061037c611e51565b34801561059a575f80fd5b5061037c6105a93660046147b5565b611eb9565b3480156105b9575f80fd5b5061037c6105c8366004614886565b611f3a565b3480156105d8575f80fd5b5061037c6105e7366004614652565b612169565b3480156105f7575f80fd5b5061061a610606366004614652565b600b6020525f908152604090205460ff1681565b6040519015158152602001610354565b348015610635575f80fd5b5061061a610644366004614652565b60046020525f908152604090205460ff1681565b348015610663575f80fd5b5061068b7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b039091168152602001610354565b3480156106ae575f80fd5b5061037c6106bd3660046147b5565b6121e2565b3480156106cd575f80fd5b5061068b7f000000000000000000000000000000000000000000000000000000000000000081565b348015610700575f80fd5b5061037c61070f366004614652565b61227e565b34801561071f575f80fd5b5061037c61072e3660046148e6565b612362565b34801561073e575f80fd5b5061075261074d366004614702565b612527565b6040516001600160401b039091168152602001610354565b348015610775575f80fd5b5061061a610784366004614962565b6001600160a01b0381163014949350505050565b3480156107a3575f80fd5b5061037c61252f565b3480156107b7575f80fd5b5061037c6107c63660046149b9565b61259d565b3480156107d6575f80fd5b505f5461068b906001600160a01b031681565b3480156107f4575f80fd5b5061034a6108033660046149b9565b60066020525f908152604090205481565b34801561081f575f80fd5b5061034a61082e36600461483f565b61260c565b34801561083e575f80fd5b5060055461075290600160601b90046001600160401b031681565b61034a6108673660046149e0565b612871565b348015610877575f80fd5b5060055461061a90600160a01b900460ff1681565b348015610897575f80fd5b5061034a6108a63660046147b5565b600d6020525f908152604090205481565b3480156108c2575f80fd5b5061037c6108d1366004614a23565b612978565b3480156108e1575f80fd5b5060015461068b906001600160a01b031681565b61037c610903366004614a3f565b612a0a565b348015610913575f80fd5b5061037c610922366004614652565b612aea565b348015610932575f80fd5b5061037c6109413660046147b5565b612b94565b348015610951575f80fd5b5061034a60095481565b348015610966575f80fd5b5061061a610975366004614652565b600a6020525f908152604090205460ff1681565b348015610994575f80fd5b5061037c6109a3366004614737565b612c14565b3480156109b3575f80fd5b5061034a60035481565b3480156109c8575f80fd5b506005546109dc906001600160601b031681565b6040516001600160601b039091168152602001610354565b3480156109ff575f80fd5b50600854610a0d9060ff1681565b6040516103549190614ad1565b348015610a25575f80fd5b5061037c610a34366004614adf565b612d14565b348015610a44575f80fd5b5061037c610a53366004614652565b612e0c565b348015610a63575f80fd5b5060085461068b9061010090046001600160a01b031681565b348015610a87575f80fd5b5061037c610a96366004614652565b612e47565b348015610aa6575f80fd5b5061068b7f000000000000000000000000000000000000000000000000000000000000000081565b348015610ad9575f80fd5b5061061a610ae8366004614b1a565b612ec2565b348015610af8575f80fd5b5061034a610b073660046149e0565b612ef6565b5f610b22335f356001600160e01b031916612f08565b610b475760405162461bcd60e51b8152600401610b3e90614b34565b60405180910390fd5b600254600114610b695760405162461bcd60e51b8152600401610b3e90614b5a565b6002805533600160085460ff166002811115610b8757610b87614a9d565b03610c67576001600160a01b0381165f908152600b602052604090205460ff16158015610bc3575060085461010090046001600160a01b031615155b15610c625760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa158015610c21573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c459190614b7e565b610c6257604051630d3e301d60e11b815260040160405180910390fd5b610ce3565b600260085460ff166002811115610c8057610c80614a9d565b03610ce3576001600160a01b0381165f908152600a602052604090205460ff16158015610cc557506001600160a01b0381165f908152600b602052604090205460ff16155b15610ce35760405163b75d22ed60e01b815260040160405180910390fd5b600554600160a01b900460ff1615610d0e5760405163e0f9e71d60e01b815260040160405180910390fd5b6001600160a01b0385165f9081526004602052604090205460ff16610d465760405163645fd19f60e11b815260040160405180910390fd5b610d5285858533612fae565b9150610d7f338686856005600c9054906101000a90046001600160401b03166001600160401b0316613708565b5060016002559392505050565b610da1335f356001600160e01b031916612f08565b610dbd5760405162461bcd60e51b8152600401610b3e90614b34565b6203f480816001600160401b03161115610dea57604051631fac010160e21b815260040160405180910390fd5b600580546001600160401b03838116600160601b81810267ffffffffffffffff60601b1985161790945560408051949093049091168084526020840191909152917f29fb89878328cdeff99ebae571aca5dd957a58ba179596359c1b0d4440673b6791015b60405180910390a15050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03163314610ea6576040516391ac5e4f60e01b8152336004820152602401610b3e565b60208701803590610ec090610ebb908a6147b5565b613841565b14610efe57610ed260208801886147b5565b60405163309afaf360e21b815263ffffffff909116600482015260208801356024820152604401610b3e565b610f0d8787878787878761387c565b50505050505050565b610f2b335f356001600160e01b031916612f08565b610f475760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff82165f908152600c60205260409081902080546001600160a01b038416620100000261ff01600160b01b031990911617600117815590517fe925de263dcdbdc20307c9ab92758ed8cc0edf3d173dad4a3aa54c070f27a54390610fcc908590859063ffffffff9290921682526001600160a01b0316602082015260400190565b60405180910390a1505050565b610fee335f356001600160e01b031916612f08565b61100a5760405162461bcd60e51b8152600401610b3e90614b34565b806001600160401b03165f03611033576040516323f0e08b60e11b815260040160405180910390fd5b63ffffffff82165f818152600c6020908152604091829020805467ffffffffffffffff60b01b1916600160b01b6001600160401b038716908102919091178255835194855291840191909152917f53d0cf6aa4c6d5098568da88caa5cbffc1601722f79a7a01d6611d19d6046d2b9101610fcc565b6110bd335f356001600160e01b031916612f08565b6110d95760405162461bcd60e51b8152600401610b3e90614b34565b6008546040517fb8de0a8cda9c21ae9d2261ded3b241270440fa52dabf5b8c1e513e6b40ca8a67916111129160ff909116908490614b99565b60405180910390a16008805482919060ff1916600183600281111561113957611139614a9d565b021790555050565b611156335f356001600160e01b031916612f08565b6111725760405162461bcd60e51b8152600401610b3e90614b34565b6001600160a01b0381165f81815260046020526040808220805460ff19166001179055517f0e3c58ebfb2e7465fbb1c32e6b4f40c3c4f5ca77e8218a386aff8617831260d79190a250565b6111d2335f356001600160e01b031916612f08565b6111ee5760405162461bcd60e51b8152600401610b3e90614b34565b6111f882826139fb565b5050565b611211335f356001600160e01b031916612f08565b61122d5760405162461bcd60e51b8152600401610b3e90614b34565b5f5b828110156112fc5781600b5f86868581811061124d5761124d614bb4565b90506020020160208101906112629190614652565b6001600160a01b0316815260208101919091526040015f20805460ff191691151591909117905583838281811061129b5761129b614bb4565b90506020020160208101906112b09190614652565b6001600160a01b03167f75c4a453892342445f30810ef4163253a127a81c39d7ddfd519e996ff085c491836040516112ec911515815260200190565b60405180910390a260010161122f565b50505050565b5f611318335f356001600160e01b031916612f08565b6113345760405162461bcd60e51b8152600401610b3e90614b34565b6002546001146113565760405162461bcd60e51b8152600401610b3e90614b5a565b6002805533600160085460ff16600281111561137457611374614a9d565b03611454576001600160a01b0381165f908152600b602052604090205460ff161580156113b0575060085461010090046001600160a01b031615155b1561144f5760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa15801561140e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114329190614b7e565b61144f57604051630d3e301d60e11b815260040160405180910390fd5b6114d0565b600260085460ff16600281111561146d5761146d614a9d565b036114d0576001600160a01b0381165f908152600a602052604090205460ff161580156114b257506001600160a01b0381165f908152600b602052604090205460ff16155b156114d05760405163b75d22ed60e01b815260040160405180910390fd5b600554600160a01b900460ff16156114fb5760405163e0f9e71d60e01b815260040160405180910390fd5b6001600160a01b0389165f9081526004602052604090205460ff166115335760405163645fd19f60e11b815260040160405180910390fd5b60405163d505accf60e01b81523360048201526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081166024830152604482018a90526064820188905260ff8716608483015260a4820186905260c482018590528a169063d505accf9060e4015f604051808303815f87803b1580156115be575f80fd5b505af19250505080156115cf575060015b61168357604051636eb1769f60e11b81523360048201526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811660248301528991908b169063dd62ed3e90604401602060405180830381865afa158015611640573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116649190614bc8565b1015611683576040516301b8851f60e41b815260040160405180910390fd5b61168f89898933612fae565b91506116bc338a8a856005600c9054906101000a90046001600160401b03166001600160401b0316613708565b506001600255979650505050505050565b5f6116e3335f356001600160e01b031916612f08565b6116ff5760405162461bcd60e51b8152600401610b3e90614b34565b33600160085460ff16600281111561171957611719614a9d565b036117f9576001600160a01b0381165f908152600b602052604090205460ff16158015611755575060085461010090046001600160a01b031615155b156117f45760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa1580156117b3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117d79190614b7e565b6117f457604051630d3e301d60e11b815260040160405180910390fd5b611875565b600260085460ff16600281111561181257611812614a9d565b03611875576001600160a01b0381165f908152600a602052604090205460ff1615801561185757506001600160a01b0381165f908152600b602052604090205460ff16155b156118755760405163b75d22ed60e01b815260040160405180910390fd5b6001600160a01b0386165f9081526004602052604090205460ff166118ad5760405163645fd19f60e11b815260040160405180910390fd5b845f036118cd57604051630ea3153160e21b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611925575f80fd5b505af1158015611937573d5f803e3d5ffd5b505050505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611998573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119bc9190614bc8565b90505f6119ea87837f0000000000000000000000000000000000000000000000000000000000000000613a48565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a48573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a6c9190614bdf565b6001600160a01b0316886001600160a01b031603611b1657611b0f8160127f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0a9190614bfa565b613a63565b9350611d61565b6040516312e2d8f360e01b81526001600160a01b0389811660048301525f917f0000000000000000000000000000000000000000000000000000000000000000909116906312e2d8f3906024016040805180830381865afa158015611b7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ba19190614c15565b5090508015611bf357611bec8260128b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b9450611d5f565b6040516312e2d8f360e01b81526001600160a01b038a811660048301525f917f0000000000000000000000000000000000000000000000000000000000000000909116906312e2d8f3906024016040805180830381865afa158015611c5a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c7e9190614c15565b9150505f816001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cbe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ce29190614bc8565b9050611d5a8b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d23573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d479190614bfa565b611d5290600a614d36565b859083613a48565b965050505b505b85841015611d82576040516302620f6160e61b815260040160405180910390fd5b6040516318457e6160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906318457e6190611dd69088908c90899033908e90600401614d44565b5f604051808303815f87803b158015611ded575f80fd5b505af1158015611dff573d5f803e3d5ffd5b50505050876001600160a01b03167fdcc60b41ff1c604459e6aa4a7299817416b19fc586a392f111646e26597c4af988604051611e3e91815260200190565b60405180910390a2505050949350505050565b611e66335f356001600160e01b031916612f08565b611e825760405162461bcd60e51b8152600401610b3e90614b34565b6005805460ff60a01b191690556040517fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d16933905f90a1565b611ece335f356001600160e01b031916612f08565b611eea5760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c6020908152604091829020805461ff0019168155915192835290917fc45af64a13a09ef916a1114c59589294ec9c3095f2bfbbb093a7a96656858ded9101610e4f565b611f4f335f356001600160e01b031916612f08565b611f6b5760405162461bcd60e51b8152600401610b3e90614b34565b80611f768342614d77565b1115611f9557604051634c1eef1760e11b815260040160405180910390fd5b604080516001600160a01b038089166020830152871691810191909152606081018590526080810184905260a0810183905260c081018290525f9060e00160408051601f1981840301815291815281516020928301205f8b8152600690935291205490915081146120195760405163fa174ecb60e01b815260040160405180910390fd5b5f88815260066020526040808220829055805163c2c4c5c160e01b815290516001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169263c2c4c5c1926004808201939182900301818387803b158015612084575f80fd5b505af1158015612096573d5f803e3d5ffd5b50506040516318457e6160e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001692506318457e6191506120ee908a908a908a9083908b90600401614d44565b5f604051808303815f87803b158015612105575f80fd5b505af1158015612117573d5f803e3d5ffd5b50505050866001600160a01b0316887faf98ea774275cadfa3e477a7b52cba03e01197445a76bd5d0d561608708c36248360405161215791815260200190565b60405180910390a35050505050505050565b61217e335f356001600160e01b031916612f08565b61219a5760405162461bcd60e51b8152600401610b3e90614b34565b6001600160a01b0381165f81815260046020526040808220805460ff19169055517f37803e2125c48ee96c38ddf04e826daf335b0e1603579040fd275aba6d06b6fc9190a250565b6121f7335f356001600160e01b031916612f08565b6122135760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c602090815260409182902080546001600160f01b0319168155600101805467ffffffffffffffff1916905590519182527f11a9d1a77f76361ed131c19b1dc5758504c51dbde2e49fc973a0ef9577ad13d5910160405180910390a150565b5f546001600160a01b031633148061230f575060015460405163b700961360e01b81526001600160a01b039091169063b7009613906122d090339030906001600160e01b03195f351690600401614d8a565b602060405180830381865afa1580156122eb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061230f9190614b7e565b612317575f80fd5b600180546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b612377335f356001600160e01b031916612f08565b6123935760405162461bcd60e51b8152600401610b3e90614b34565b8380156123a757506001600160401b038216155b156123c5576040516323f0e08b60e11b815260040160405180910390fd5b6040805160a081018252861515815285151560208083019182526001600160a01b038088168486019081526001600160401b03808916606087019081528882166080880190815263ffffffff8f165f908152600c90965294889020965187549651935191518316600160b01b0267ffffffffffffffff60b01b199290951662010000029190911662010000600160f01b03199315156101000261ff00199215159290921661ffff199097169690961717919091169390931717835551600190920180549290911667ffffffffffffffff19909216919091179055517f92ca48f4323e5539c637c7a03bd3e43941aa078e4f165e1d02c7e309317c429c906125179088908890889088908890889063ffffffff969096168652931515602086015291151560408501526001600160a01b031660608401526001600160401b0390811660808401521660a082015260c00190565b60405180910390a1505050505050565b5f5b92915050565b612544335f356001600160e01b031916612f08565b6125605760405162461bcd60e51b8152600401610b3e90614b34565b6005805460ff60a01b1916600160a01b1790556040517f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e752905f90a1565b6125b2335f356001600160e01b031916612f08565b6125ce5760405162461bcd60e51b8152600401610b3e90614b34565b600380549082905560408051828152602081018490527ffbe912fdd0185617e8cafd12d97b59175b90e15f5c629faf6413469af54ee0809101610e4f565b5f612622335f356001600160e01b031916612f08565b61263e5760405162461bcd60e51b8152600401610b3e90614b34565b6002546001146126605760405162461bcd60e51b8152600401610b3e90614b5a565b6002805581600160085460ff16600281111561267e5761267e614a9d565b0361275e576001600160a01b0381165f908152600b602052604090205460ff161580156126ba575060085461010090046001600160a01b031615155b156127595760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa158015612718573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061273c9190614b7e565b61275957604051630d3e301d60e11b815260040160405180910390fd5b6127da565b600260085460ff16600281111561277757612777614a9d565b036127da576001600160a01b0381165f908152600a602052604090205460ff161580156127bc57506001600160a01b0381165f908152600b602052604090205460ff16155b156127da5760405163b75d22ed60e01b815260040160405180910390fd5b6001600160a01b0386165f9081526004602052604090205460ff166128125760405163645fd19f60e11b815260040160405180910390fd5b61281e86868686612fae565b9150856001600160a01b03167f6f9b974223f85a1ae805c33b8b519039e2435481d949db1110de151a94d587af8660405161285b91815260200190565b60405180910390a2506001600255949350505050565b5f612887335f356001600160e01b031916612f08565b6128a35760405162461bcd60e51b8152600401610b3e90614b34565b600554600160a01b900460ff16156128ce5760405163e0f9e71d60e01b815260040160405180910390fd5b6128d782613acb565b6128e033612e0c565b6040516318457e6160e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906318457e6190612934905f908190819033908a90600401614d44565b5f604051808303815f87803b15801561294b575f80fd5b505af115801561295d573d5f803e3d5ffd5b5050505061296b8383613c77565b9050612529838383613d91565b61298d335f356001600160e01b031916612f08565b6129a95760405162461bcd60e51b8152600401610b3e90614b34565b60088054610100600160a81b0319166101006001600160a01b03851690810291909117909155600982905560408051918252602082018390527fdd311e842d0dd0d276250faf64c7c9bed12bf94d1e4c1e33b304102684994fc89101610e4f565b612a1f335f356001600160e01b031916612f08565b612a3b5760405162461bcd60e51b8152600401610b3e90614b34565b600254600114612a5d5760405162461bcd60e51b8152600401610b3e90614b5a565b600280556001600160a01b0384165f9081526004602052604090205460ff16612a995760405163645fd19f60e11b815260040160405180910390fd5b5f612aa685858533612fae565b9050612ad3338686846005600c9054906101000a90046001600160401b03166001600160401b0316613708565b612add8183612871565b5050600160025550505050565b612aff335f356001600160e01b031916612f08565b612b1b5760405162461bcd60e51b8152600401610b3e90614b34565b60405163ca5eb5e160e01b81526001600160a01b0382811660048301527f0000000000000000000000000000000000000000000000000000000000000000169063ca5eb5e1906024015f604051808303815f87803b158015612b7b575f80fd5b505af1158015612b8d573d5f803e3d5ffd5b5050505050565b612ba9335f356001600160e01b031916612f08565b612bc55760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c6020908152604091829020805460ff19168155915192835290917f1cb867ed6a020e020ea220d4f48bb8e36552abf9095e093e377d33933f2b31e49101610e4f565b612c29335f356001600160e01b031916612f08565b612c455760405162461bcd60e51b8152600401610b3e90614b34565b5f5b828110156112fc5781600a5f868685818110612c6557612c65614bb4565b9050602002016020810190612c7a9190614652565b6001600160a01b0316815260208101919091526040015f20805460ff1916911515919091179055838382818110612cb357612cb3614bb4565b9050602002016020810190612cc89190614652565b6001600160a01b03167fbe87d514b3e161103a7c1ddd4c9f1f4a93559090d347b432e657a09fc47f8e0b83604051612d04911515815260200190565b60405180910390a2600101612c47565b612d29335f356001600160e01b031916612f08565b612d455760405162461bcd60e51b8152600401610b3e90614b34565b806001600160401b03165f03612d6e576040516323f0e08b60e11b815260040160405180910390fd5b63ffffffff83165f818152600c602090815260409182902080546001600160401b038616600160b01b0267ffffffffffffffff60b01b196001600160a01b038916620100008102610100600160b01b0319909416939093176101001716178255835194855291840191909152917f34fe916485e02ec88e487b0e611e5c9bacabba9e3eaae7a900aa08be8197d419910160405180910390a150505050565b6001600160a01b0381165f90815260076020526040902054421015612e445760405163f64059db60e01b815260040160405180910390fd5b50565b612e5c335f356001600160e01b031916612f08565b612e785760405162461bcd60e51b8152600401610b3e90614b34565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b5f60208201803590600d908390612ed990866147b5565b63ffffffff16815260208101919091526040015f20541492915050565b5f612f018383613de8565b9392505050565b6001545f906001600160a01b03168015801590612f8f575060405163b700961360e01b81526001600160a01b0382169063b700961390612f5090879030908890600401614d8a565b602060405180830381865afa158015612f6b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f8f9190614b7e565b80612fa657505f546001600160a01b038581169116145b949350505050565b5f835f03612fcf5760405163259be69560e11b815260040160405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015613027575f80fd5b505af1158015613039573d5f803e3d5ffd5b505050505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561309a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130be9190614bc8565b90505f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561311d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131419190614bdf565b6001600160a01b0316876001600160a01b0316036131eb576131e4867f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131b9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131dd9190614bfa565b6012613a63565b9050613435565b6040516312e2d8f360e01b81526001600160a01b0388811660048301525f917f0000000000000000000000000000000000000000000000000000000000000000909116906312e2d8f3906024016040805180830381865afa158015613252573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906132769190614c15565b50905080156132c6576132bf87896001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131b9573d5f803e3d5ffd5b9150613433565b6040516312e2d8f360e01b81526001600160a01b0389811660048301525f917f0000000000000000000000000000000000000000000000000000000000000000909116906312e2d8f3906024016040805180830381865afa15801561332d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133519190614c15565b9150505f816001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613391573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133b59190614bc8565b905061342e818b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133f7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061341b9190614bfa565b61342690600a614d36565b8b9190613a48565b935050505b505b613460817f000000000000000000000000000000000000000000000000000000000000000084613a48565b9250848310156134835760405163097b2ad560e31b815260040160405180910390fd5b5f6134af84847f0000000000000000000000000000000000000000000000000000000000000000613a48565b90506135138160127f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b90505f6135c2847f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613597573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906135bb9190614bc8565b9190613a48565b90506136268160127f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b6003549091506136368383614db7565b111561367b5760405162461bcd60e51b815260206004820152601460248201527311195c1bdcda5d0818d85c08195e18d95959195960621b6044820152606401610b3e565b604051631ceb5d1960e11b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906339d6ba32906136cf9033908d908d908c908c90600401614d44565b5f604051808303815f87803b1580156136e6575f80fd5b505af11580156136f8573d5f803e3d5ffd5b5050505050505050949350505050565b6137128142614db7565b6001600160a01b038681165f81815260076020908152604091829020949094556005548151948501929092529187169183019190915260608201859052608082018490524260a083015260c082018390526001600160601b03169060e00160408051601f1981840301815291815281516020928301205f848152600690935290822055600580546001600160601b0316916137ac83614dca565b91906101000a8154816001600160601b0302191690836001600160601b0316021790555050846001600160a01b0316866001600160a01b0316827fe96d7872363f475d18b2f5390caaa5eaa96b2d38e42c62afe4ac08ebd2b13c3a87874288604051613831949392919093845260208401929092526040830152606082015260800190565b60405180910390a4505050505050565b63ffffffff81165f908152600d6020526040812054806125295760405163f6ff4fb760e01b815263ffffffff84166004820152602401610b3e565b613884613eab565b600c5f61389460208a018a6147b5565b63ffffffff16815260208101919091526040015f205460ff166138e0576138be60208801886147b5565b604051635408978f60e11b815263ffffffff9091166004820152602401610b3e565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015613938575f80fd5b505af115801561394a573d5f803e3d5ffd5b505050505f80868681019061395f9190614def565b604051631ceb5d1960e11b815291935091506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906339d6ba32906139b8905f908190819087908990600401614d44565b5f604051808303815f87803b1580156139cf575f80fd5b505af11580156139e1573d5f803e3d5ffd5b505050506139f082828a613ed8565b505050505050505050565b63ffffffff82165f818152600d6020908152604091829020849055815192835282018390527f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b9101610e4f565b5f825f190484118302158202613a5c575f80fd5b5091020490565b5f8160ff168360ff1603613a78575082612f01565b8160ff168360ff161015613aac57613a908383614e12565b613a9b90600a614d36565b613aa59085614e2b565b9050612f01565b613ab68284614e12565b613ac190600a614d36565b613aa59085614e42565b5f600c81613adc60208501856147b5565b63ffffffff16815260208082019290925260409081015f20815160a081018352815460ff8082161515835261010082041615159482018590526201000081046001600160a01b031693820193909352600160b01b9092046001600160401b0390811660608401526001909101541660808201529150613b8457613b6260208301836147b5565b604051630a8acb5760e21b815263ffffffff9091166004820152602401610b3e565b60408101516001600160a01b0316613baf5760405163098a923160e41b815260040160405180910390fd5b5f613bc06040840160208501614652565b6001600160a01b031603613be75760405163f4a986cb60e01b815260040160405180910390fd5b80606001516001600160401b0316826060016020810190613c089190614545565b6001600160401b03161115613c3057604051636e33764360e11b815260040160405180910390fd5b6080808201516001600160401b031690613c4f90840160608501614545565b6001600160401b031610156111f857604051637abded0b60e11b815260040160405180910390fd5b5f73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee613c9d6060840160408501614652565b6001600160a01b031614613cc457604051634e4f206760e01b815260040160405180910390fd5b5f83613cd66040850160208601614652565b604051602001613cf99291909182526001600160a01b0316602082015260400190565b60408051601f1981840301815291905290505f613d56613d1f6080860160608701614545565b6001600160401b03165f613d4f60408051600360f01b602082015281516002818303018152602290910190915290565b9190613f21565b90505f613d86613d6960208701876147b5565b848460405180604001604052803481526020015f81525033613f86565b519695505050505050565b7fe0ec62d39b054dc2fd626dbc271483735df6e6fa1ef8389754bf8ab27a75eab28184613dc46040860160208701614652565b6040805193845260208401929092526001600160a01b031690820152606001610fcc565b5f8083613dfb6040850160208601614652565b604051602001613e1e9291909182526001600160a01b0316602082015260400190565b60408051601f1981840301815291905290505f613e44613d1f6080860160608701614545565b905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee613e6b6060860160408701614652565b6001600160a01b031614613e9257604051634e4f206760e01b815260040160405180910390fd5b5f613d86613ea360208701876147b5565b84845f61408c565b600554600160a01b900460ff1615613ed65760405163e0f9e71d60e01b815260040160405180910390fd5b565b60408051828152602081018590526001600160a01b038416918101919091527fb944fddc61d7fedb8b736790454ba972000703b0d21c7481d6dbf95b7c2cc2f190606001610fcc565b6060836003613f30825f61416a565b61ffff1614613f6357613f43815f61416a565b604051633a51740d60e01b815261ffff9091166004820152602401610b3e565b5f613f6e85856141c6565b9050613f7c86600183614248565b9695505050505050565b613f8e6144a8565b5f613f9b845f01516142b1565b602085015190915015613fb557613fb584602001516142d8565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632637a450826040518060a001604052808b63ffffffff1681526020016140058c613841565b81526020018a81526020018981526020015f8960200151111515815250866040518463ffffffff1660e01b8152600401614040929190614eae565b60806040518083038185885af115801561405c573d5f803e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906140819190614f7e565b979650505050505050565b604080518082019091525f80825260208201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ddc28c586040518060a001604052808863ffffffff1681526020016140ee89613841565b8152602001878152602001868152602001851515815250306040518363ffffffff1660e01b8152600401614123929190614eae565b6040805180830381865afa15801561413d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906141619190614fef565b95945050505050565b5f614176826002614db7565b835110156141bd5760405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606401610b3e565b50016002015190565b60606fffffffffffffffffffffffffffffffff82161561421757604080516001600160801b0319608086811b8216602084015285901b16603082015201604051602081830303815290604052612f01565b6040516001600160801b0319608085901b166020820152603001604051602081830303815290604052905092915050565b6060836003614257825f61416a565b61ffff161461426a57613f43815f61416a565b84600161427785516143b7565b614282906001615009565b868660405160200161429895949392919061502b565b6040516020818303038152906040529150509392505050565b5f8134146142d4576040516304fb820960e51b8152346004820152602401610b3e565b5090565b5f7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e4fe1d946040518163ffffffff1660e01b8152600401602060405180830381865afa158015614335573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143599190614bdf565b90506001600160a01b038116614382576040516329b99a9560e11b815260040160405180910390fd5b6111f86001600160a01b038216337f0000000000000000000000000000000000000000000000000000000000000000856143e5565b5f61ffff8211156142d4576040516306dfcc6560e41b81526010600482015260248101839052604401610b3e565b604080516001600160a01b038581166024830152841660448201526064808201849052825180830390910181526084909101909152602080820180516001600160e01b03166323b872dd60e01b17815282516112fc93889390925f9283929183919082885af18061445b576040513d5f823e3d81fd5b50505f513d9150811561447257806001141561447f565b6001600160a01b0384163b155b156112fc57604051635274afe760e01b81526001600160a01b0385166004820152602401610b3e565b60405180606001604052805f80191681526020015f6001600160401b031681526020016144e660405180604001604052805f81526020015f81525090565b905290565b6001600160a01b0381168114612e44575f80fd5b5f805f60608486031215614511575f80fd5b833561451c816144eb565b95602085013595506040909401359392505050565b6001600160401b0381168114612e44575f80fd5b5f60208284031215614555575f80fd5b8135612f0181614531565b5f60608284031215614570575f80fd5b50919050565b5f8083601f840112614586575f80fd5b5081356001600160401b0381111561459c575f80fd5b6020830191508360208285010111156145b3575f80fd5b9250929050565b5f805f805f805f60e0888a0312156145d0575f80fd5b6145da8989614560565b96506060880135955060808801356001600160401b03808211156145fc575f80fd5b6146088b838c01614576565b909750955060a08a0135915061461d826144eb565b90935060c08901359080821115614632575f80fd5b5061463f8a828b01614576565b989b979a50959850939692959293505050565b5f60208284031215614662575f80fd5b8135612f01816144eb565b803563ffffffff81168114614680575f80fd5b919050565b5f8060408385031215614696575f80fd5b61469f8361466d565b915060208301356146af816144eb565b809150509250929050565b5f80604083850312156146cb575f80fd5b6146d48361466d565b915060208301356146af81614531565b5f602082840312156146f4575f80fd5b813560038110612f01575f80fd5b5f8060408385031215614713575f80fd5b61471c8361466d565b946020939093013593505050565b8015158114612e44575f80fd5b5f805f60408486031215614749575f80fd5b83356001600160401b038082111561475f575f80fd5b818601915086601f830112614772575f80fd5b813581811115614780575f80fd5b8760208260051b8501011115614794575f80fd5b602092830195509350508401356147aa8161472a565b809150509250925092565b5f602082840312156147c5575f80fd5b612f018261466d565b60ff81168114612e44575f80fd5b5f805f805f805f60e0888a0312156147f2575f80fd5b87356147fd816144eb565b96506020880135955060408801359450606088013593506080880135614822816147ce565b9699959850939692959460a0840135945060c09093013592915050565b5f805f8060808587031215614852575f80fd5b843561485d816144eb565b93506020850135925060408501359150606085013561487b816144eb565b939692955090935050565b5f805f805f805f60e0888a03121561489c575f80fd5b8735965060208801356148ae816144eb565b955060408801356148be816144eb565b969995985095966060810135965060808101359560a0820135955060c0909101359350915050565b5f805f805f8060c087890312156148fb575f80fd5b6149048761466d565b955060208701356149148161472a565b945060408701356149248161472a565b93506060870135614934816144eb565b9250608087013561494481614531565b915060a087013561495481614531565b809150509295509295509295565b5f805f8060a08587031215614975575f80fd5b61497f8686614560565b935060608501356001600160401b03811115614999575f80fd5b6149a587828801614576565b909450925050608085013561487b816144eb565b5f602082840312156149c9575f80fd5b5035919050565b5f60a08284031215614570575f80fd5b5f80604083850312156149f1575f80fd5b8235915060208301356001600160401b03811115614a0d575f80fd5b614a19858286016149d0565b9150509250929050565b5f8060408385031215614a34575f80fd5b823561471c816144eb565b5f805f8060808587031215614a52575f80fd5b8435614a5d816144eb565b9350602085013592506040850135915060608501356001600160401b03811115614a85575f80fd5b614a91878288016149d0565b91505092959194509250565b634e487b7160e01b5f52602160045260245ffd5b60038110614acd57634e487b7160e01b5f52602160045260245ffd5b9052565b602081016125298284614ab1565b5f805f60608486031215614af1575f80fd5b614afa8461466d565b92506020840135614b0a816144eb565b915060408401356147aa81614531565b5f60608284031215614b2a575f80fd5b612f018383614560565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b5f60208284031215614b8e575f80fd5b8151612f018161472a565b60408101614ba78285614ab1565b612f016020830184614ab1565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614bd8575f80fd5b5051919050565b5f60208284031215614bef575f80fd5b8151612f01816144eb565b5f60208284031215614c0a575f80fd5b8151612f01816147ce565b5f8060408385031215614c26575f80fd5b8251614c318161472a565b60208401519092506146af816144eb565b634e487b7160e01b5f52601160045260245ffd5b600181815b80851115614c9057815f1904821115614c7657614c76614c42565b80851615614c8357918102915b93841c9390800290614c5b565b509250929050565b5f82614ca657506001612529565b81614cb257505f612529565b8160018114614cc85760028114614cd257614cee565b6001915050612529565b60ff841115614ce357614ce3614c42565b50506001821b612529565b5060208310610133831016604e8410600b8410161715614d11575081810a612529565b614d1b8383614c56565b805f1904821115614d2e57614d2e614c42565b029392505050565b5f612f0160ff841683614c98565b6001600160a01b039586168152938516602085015260408401929092529092166060820152608081019190915260a00190565b8181038181111561252957612529614c42565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b8082018082111561252957612529614c42565b5f6001600160601b03808316818103614de557614de5614c42565b6001019392505050565b5f8060408385031215614e00575f80fd5b8235915060208301356146af816144eb565b60ff828116828216039081111561252957612529614c42565b808202811582820484141761252957612529614c42565b5f82614e5c57634e487b7160e01b5f52601260045260245ffd5b500490565b5f5b83811015614e7b578181015183820152602001614e63565b50505f910152565b5f8151808452614e9a816020860160208601614e61565b601f01601f19169290920160200192915050565b6040815263ffffffff8351166040820152602083015160608201525f604084015160a06080840152614ee360e0840182614e83565b90506060850151603f198483030160a0850152614f008282614e83565b60809690960151151560c08501525050506001600160a01b039190911660209091015290565b5f60408284031215614f36575f80fd5b604051604081018181106001600160401b0382111715614f6457634e487b7160e01b5f52604160045260245ffd5b604052825181526020928301519281019290925250919050565b5f60808284031215614f8e575f80fd5b604051606081018181106001600160401b0382111715614fbc57634e487b7160e01b5f52604160045260245ffd5b604052825181526020830151614fd181614531565b6020820152614fe38460408501614f26565b60408201529392505050565b5f60408284031215614fff575f80fd5b612f018383614f26565b61ffff81811683821601908082111561502457615024614c42565b5092915050565b5f865161503c818460208b01614e61565b6001600160f81b031960f888811b82169285019283526001600160f01b031960f089901b16600184015286901b1660038201528351615082816004840160208801614e61565b0160040197965050505050505056fea26469706673582212209144f070eb2e9c2c72abc494aba3b15824651689389cb1fb377cd4cf0f26e00764736f6c6343000816003300000000000000000000000003014c3cdadd8a5a1d8eba50e35212a53ba3a504000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a650000000000000000000000001a44076050125825900e736c501f859c50fe728c
Deployed Bytecode
0x608060405260043610610327575f3560e01c80638456cb59116101a3578063d555f368116100f2578063e329820811610092578063f2fde38b1161006d578063f2fde38b14610a7c578063fbfa77cf14610a9b578063ff7bd03d14610ace578063ffc19a0114610aed575f80fd5b8063e329820814610a1a578063e83931af14610a39578063f11a8ca514610a58575f80fd5b8063dbab77b6116100cd578063dbab77b614610989578063dbd5edc7146109a8578063de35f5cb146109bd578063e11484c0146109f4575f80fd5b8063d555f36814610927578063d636b05f14610946578063d9e9c9781461095b575f80fd5b8063a69559d11161015d578063bd0d9cbd11610138578063bd0d9cbd146108b7578063bf7e214f146108d6578063bfe1a0f2146108f5578063ca5eb5e114610908575f80fd5b8063a69559d114610859578063b187bd261461086c578063bb0b6a531461088c575f80fd5b80638456cb591461079857806386651203146107ac5780638da5cb5b146107cb5780639a94d3d0146107e95780639d574420146108145780639fdb11b614610833575f80fd5b80633e64ce99116102795780634fb3ccc5116102195780637a9e5e4b116101f45780637a9e5e4b146106f55780637bb4122e146107145780637d25a05e1461073357806382413eac1461076a575f80fd5b80634fb3ccc51461065857806355a2d64d146106a35780635e280f11146106c2575f80fd5b806346b563f41161025457806346b563f4146105ae5780634a5e42b1146105cd5780634c999f5e146105ec5780634f129c531461062a575f80fd5b80633e64ce991461055c5780633f4ba83a1461057b57806345ad60631461058f575f80fd5b80632264e930116102e45780633400288b116102bf5780633400288b146104595780633c5722c9146104785780633d4bd6fe146104975780633d935d9e1461053d575f80fd5b80632264e930146103fc578063287fc8251461041b578063298410e51461043a575f80fd5b80630efe6a8b1461032b57806312056e2d1461035d57806313137d651461037e57806317442b70146103915780631899ea81146103b2578063202eac57146103dd575b5f80fd5b348015610336575f80fd5b5061034a6103453660046144ff565b610b0c565b6040519081526020015b60405180910390f35b348015610368575f80fd5b5061037c610377366004614545565b610d8c565b005b61037c61038c3660046145ba565b610e5b565b34801561039c575f80fd5b5060408051600181526002602082015201610354565b3480156103bd575f80fd5b5061034a6103cc366004614652565b60076020525f908152604090205481565b3480156103e8575f80fd5b5061037c6103f7366004614685565b610f16565b348015610407575f80fd5b5061037c6104163660046146ba565b610fd9565b348015610426575f80fd5b5061037c6104353660046146e4565b6110a8565b348015610445575f80fd5b5061037c610454366004614652565b611141565b348015610464575f80fd5b5061037c610473366004614702565b6111bd565b348015610483575f80fd5b5061037c610492366004614737565b6111fc565b3480156104a2575f80fd5b506104fc6104b13660046147b5565b600c6020525f90815260409020805460019091015460ff808316926101008104909116916001600160a01b0362010000830416916001600160401b03600160b01b9091048116911685565b60408051951515865293151560208601526001600160a01b03909216928401929092526001600160401b03918216606084015216608082015260a001610354565b348015610548575f80fd5b5061034a6105573660046147dc565b611302565b348015610567575f80fd5b5061034a61057636600461483f565b6116cd565b348015610586575f80fd5b5061037c611e51565b34801561059a575f80fd5b5061037c6105a93660046147b5565b611eb9565b3480156105b9575f80fd5b5061037c6105c8366004614886565b611f3a565b3480156105d8575f80fd5b5061037c6105e7366004614652565b612169565b3480156105f7575f80fd5b5061061a610606366004614652565b600b6020525f908152604090205460ff1681565b6040519015158152602001610354565b348015610635575f80fd5b5061061a610644366004614652565b60046020525f908152604090205460ff1681565b348015610663575f80fd5b5061068b7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a6581565b6040516001600160a01b039091168152602001610354565b3480156106ae575f80fd5b5061037c6106bd3660046147b5565b6121e2565b3480156106cd575f80fd5b5061068b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c81565b348015610700575f80fd5b5061037c61070f366004614652565b61227e565b34801561071f575f80fd5b5061037c61072e3660046148e6565b612362565b34801561073e575f80fd5b5061075261074d366004614702565b612527565b6040516001600160401b039091168152602001610354565b348015610775575f80fd5b5061061a610784366004614962565b6001600160a01b0381163014949350505050565b3480156107a3575f80fd5b5061037c61252f565b3480156107b7575f80fd5b5061037c6107c63660046149b9565b61259d565b3480156107d6575f80fd5b505f5461068b906001600160a01b031681565b3480156107f4575f80fd5b5061034a6108033660046149b9565b60066020525f908152604090205481565b34801561081f575f80fd5b5061034a61082e36600461483f565b61260c565b34801561083e575f80fd5b5060055461075290600160601b90046001600160401b031681565b61034a6108673660046149e0565b612871565b348015610877575f80fd5b5060055461061a90600160a01b900460ff1681565b348015610897575f80fd5b5061034a6108a63660046147b5565b600d6020525f908152604090205481565b3480156108c2575f80fd5b5061037c6108d1366004614a23565b612978565b3480156108e1575f80fd5b5060015461068b906001600160a01b031681565b61037c610903366004614a3f565b612a0a565b348015610913575f80fd5b5061037c610922366004614652565b612aea565b348015610932575f80fd5b5061037c6109413660046147b5565b612b94565b348015610951575f80fd5b5061034a60095481565b348015610966575f80fd5b5061061a610975366004614652565b600a6020525f908152604090205460ff1681565b348015610994575f80fd5b5061037c6109a3366004614737565b612c14565b3480156109b3575f80fd5b5061034a60035481565b3480156109c8575f80fd5b506005546109dc906001600160601b031681565b6040516001600160601b039091168152602001610354565b3480156109ff575f80fd5b50600854610a0d9060ff1681565b6040516103549190614ad1565b348015610a25575f80fd5b5061037c610a34366004614adf565b612d14565b348015610a44575f80fd5b5061037c610a53366004614652565b612e0c565b348015610a63575f80fd5b5060085461068b9061010090046001600160a01b031681565b348015610a87575f80fd5b5061037c610a96366004614652565b612e47565b348015610aa6575f80fd5b5061068b7f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df81565b348015610ad9575f80fd5b5061061a610ae8366004614b1a565b612ec2565b348015610af8575f80fd5b5061034a610b073660046149e0565b612ef6565b5f610b22335f356001600160e01b031916612f08565b610b475760405162461bcd60e51b8152600401610b3e90614b34565b60405180910390fd5b600254600114610b695760405162461bcd60e51b8152600401610b3e90614b5a565b6002805533600160085460ff166002811115610b8757610b87614a9d565b03610c67576001600160a01b0381165f908152600b602052604090205460ff16158015610bc3575060085461010090046001600160a01b031615155b15610c625760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa158015610c21573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c459190614b7e565b610c6257604051630d3e301d60e11b815260040160405180910390fd5b610ce3565b600260085460ff166002811115610c8057610c80614a9d565b03610ce3576001600160a01b0381165f908152600a602052604090205460ff16158015610cc557506001600160a01b0381165f908152600b602052604090205460ff16155b15610ce35760405163b75d22ed60e01b815260040160405180910390fd5b600554600160a01b900460ff1615610d0e5760405163e0f9e71d60e01b815260040160405180910390fd5b6001600160a01b0385165f9081526004602052604090205460ff16610d465760405163645fd19f60e11b815260040160405180910390fd5b610d5285858533612fae565b9150610d7f338686856005600c9054906101000a90046001600160401b03166001600160401b0316613708565b5060016002559392505050565b610da1335f356001600160e01b031916612f08565b610dbd5760405162461bcd60e51b8152600401610b3e90614b34565b6203f480816001600160401b03161115610dea57604051631fac010160e21b815260040160405180910390fd5b600580546001600160401b03838116600160601b81810267ffffffffffffffff60601b1985161790945560408051949093049091168084526020840191909152917f29fb89878328cdeff99ebae571aca5dd957a58ba179596359c1b0d4440673b6791015b60405180910390a15050565b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b03163314610ea6576040516391ac5e4f60e01b8152336004820152602401610b3e565b60208701803590610ec090610ebb908a6147b5565b613841565b14610efe57610ed260208801886147b5565b60405163309afaf360e21b815263ffffffff909116600482015260208801356024820152604401610b3e565b610f0d8787878787878761387c565b50505050505050565b610f2b335f356001600160e01b031916612f08565b610f475760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff82165f908152600c60205260409081902080546001600160a01b038416620100000261ff01600160b01b031990911617600117815590517fe925de263dcdbdc20307c9ab92758ed8cc0edf3d173dad4a3aa54c070f27a54390610fcc908590859063ffffffff9290921682526001600160a01b0316602082015260400190565b60405180910390a1505050565b610fee335f356001600160e01b031916612f08565b61100a5760405162461bcd60e51b8152600401610b3e90614b34565b806001600160401b03165f03611033576040516323f0e08b60e11b815260040160405180910390fd5b63ffffffff82165f818152600c6020908152604091829020805467ffffffffffffffff60b01b1916600160b01b6001600160401b038716908102919091178255835194855291840191909152917f53d0cf6aa4c6d5098568da88caa5cbffc1601722f79a7a01d6611d19d6046d2b9101610fcc565b6110bd335f356001600160e01b031916612f08565b6110d95760405162461bcd60e51b8152600401610b3e90614b34565b6008546040517fb8de0a8cda9c21ae9d2261ded3b241270440fa52dabf5b8c1e513e6b40ca8a67916111129160ff909116908490614b99565b60405180910390a16008805482919060ff1916600183600281111561113957611139614a9d565b021790555050565b611156335f356001600160e01b031916612f08565b6111725760405162461bcd60e51b8152600401610b3e90614b34565b6001600160a01b0381165f81815260046020526040808220805460ff19166001179055517f0e3c58ebfb2e7465fbb1c32e6b4f40c3c4f5ca77e8218a386aff8617831260d79190a250565b6111d2335f356001600160e01b031916612f08565b6111ee5760405162461bcd60e51b8152600401610b3e90614b34565b6111f882826139fb565b5050565b611211335f356001600160e01b031916612f08565b61122d5760405162461bcd60e51b8152600401610b3e90614b34565b5f5b828110156112fc5781600b5f86868581811061124d5761124d614bb4565b90506020020160208101906112629190614652565b6001600160a01b0316815260208101919091526040015f20805460ff191691151591909117905583838281811061129b5761129b614bb4565b90506020020160208101906112b09190614652565b6001600160a01b03167f75c4a453892342445f30810ef4163253a127a81c39d7ddfd519e996ff085c491836040516112ec911515815260200190565b60405180910390a260010161122f565b50505050565b5f611318335f356001600160e01b031916612f08565b6113345760405162461bcd60e51b8152600401610b3e90614b34565b6002546001146113565760405162461bcd60e51b8152600401610b3e90614b5a565b6002805533600160085460ff16600281111561137457611374614a9d565b03611454576001600160a01b0381165f908152600b602052604090205460ff161580156113b0575060085461010090046001600160a01b031615155b1561144f5760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa15801561140e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906114329190614b7e565b61144f57604051630d3e301d60e11b815260040160405180910390fd5b6114d0565b600260085460ff16600281111561146d5761146d614a9d565b036114d0576001600160a01b0381165f908152600a602052604090205460ff161580156114b257506001600160a01b0381165f908152600b602052604090205460ff16155b156114d05760405163b75d22ed60e01b815260040160405180910390fd5b600554600160a01b900460ff16156114fb5760405163e0f9e71d60e01b815260040160405180910390fd5b6001600160a01b0389165f9081526004602052604090205460ff166115335760405163645fd19f60e11b815260040160405180910390fd5b60405163d505accf60e01b81523360048201526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df81166024830152604482018a90526064820188905260ff8716608483015260a4820186905260c482018590528a169063d505accf9060e4015f604051808303815f87803b1580156115be575f80fd5b505af19250505080156115cf575060015b61168357604051636eb1769f60e11b81523360048201526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df811660248301528991908b169063dd62ed3e90604401602060405180830381865afa158015611640573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906116649190614bc8565b1015611683576040516301b8851f60e41b815260040160405180910390fd5b61168f89898933612fae565b91506116bc338a8a856005600c9054906101000a90046001600160401b03166001600160401b0316613708565b506001600255979650505050505050565b5f6116e3335f356001600160e01b031916612f08565b6116ff5760405162461bcd60e51b8152600401610b3e90614b34565b33600160085460ff16600281111561171957611719614a9d565b036117f9576001600160a01b0381165f908152600b602052604090205460ff16158015611755575060085461010090046001600160a01b031615155b156117f45760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa1580156117b3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117d79190614b7e565b6117f457604051630d3e301d60e11b815260040160405180910390fd5b611875565b600260085460ff16600281111561181257611812614a9d565b03611875576001600160a01b0381165f908152600a602052604090205460ff1615801561185757506001600160a01b0381165f908152600b602052604090205460ff16155b156118755760405163b75d22ed60e01b815260040160405180910390fd5b6001600160a01b0386165f9081526004602052604090205460ff166118ad5760405163645fd19f60e11b815260040160405180910390fd5b845f036118cd57604051630ea3153160e21b815260040160405180910390fd5b7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015611925575f80fd5b505af1158015611937573d5f803e3d5ffd5b505050505f7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611998573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906119bc9190614bc8565b90505f6119ea87837f00000000000000000000000000000000000000000000000000000000000f4240613a48565b90507f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa158015611a48573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611a6c9190614bdf565b6001600160a01b0316886001600160a01b031603611b1657611b0f8160127f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b0a9190614bfa565b613a63565b9350611d61565b6040516312e2d8f360e01b81526001600160a01b0389811660048301525f917f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65909116906312e2d8f3906024016040805180830381865afa158015611b7d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ba19190614c15565b5090508015611bf357611bec8260128b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b9450611d5f565b6040516312e2d8f360e01b81526001600160a01b038a811660048301525f917f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65909116906312e2d8f3906024016040805180830381865afa158015611c5a573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c7e9190614c15565b9150505f816001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cbe573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611ce29190614bc8565b9050611d5a8b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611d23573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d479190614bfa565b611d5290600a614d36565b859083613a48565b965050505b505b85841015611d82576040516302620f6160e61b815260040160405180910390fd5b6040516318457e6160e01b81526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df16906318457e6190611dd69088908c90899033908e90600401614d44565b5f604051808303815f87803b158015611ded575f80fd5b505af1158015611dff573d5f803e3d5ffd5b50505050876001600160a01b03167fdcc60b41ff1c604459e6aa4a7299817416b19fc586a392f111646e26597c4af988604051611e3e91815260200190565b60405180910390a2505050949350505050565b611e66335f356001600160e01b031916612f08565b611e825760405162461bcd60e51b8152600401610b3e90614b34565b6005805460ff60a01b191690556040517fa45f47fdea8a1efdd9029a5691c7f759c32b7c698632b563573e155625d16933905f90a1565b611ece335f356001600160e01b031916612f08565b611eea5760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c6020908152604091829020805461ff0019168155915192835290917fc45af64a13a09ef916a1114c59589294ec9c3095f2bfbbb093a7a96656858ded9101610e4f565b611f4f335f356001600160e01b031916612f08565b611f6b5760405162461bcd60e51b8152600401610b3e90614b34565b80611f768342614d77565b1115611f9557604051634c1eef1760e11b815260040160405180910390fd5b604080516001600160a01b038089166020830152871691810191909152606081018590526080810184905260a0810183905260c081018290525f9060e00160408051601f1981840301815291815281516020928301205f8b8152600690935291205490915081146120195760405163fa174ecb60e01b815260040160405180910390fd5b5f88815260066020526040808220829055805163c2c4c5c160e01b815290516001600160a01b037f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65169263c2c4c5c1926004808201939182900301818387803b158015612084575f80fd5b505af1158015612096573d5f803e3d5ffd5b50506040516318457e6160e01b81526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df1692506318457e6191506120ee908a908a908a9083908b90600401614d44565b5f604051808303815f87803b158015612105575f80fd5b505af1158015612117573d5f803e3d5ffd5b50505050866001600160a01b0316887faf98ea774275cadfa3e477a7b52cba03e01197445a76bd5d0d561608708c36248360405161215791815260200190565b60405180910390a35050505050505050565b61217e335f356001600160e01b031916612f08565b61219a5760405162461bcd60e51b8152600401610b3e90614b34565b6001600160a01b0381165f81815260046020526040808220805460ff19169055517f37803e2125c48ee96c38ddf04e826daf335b0e1603579040fd275aba6d06b6fc9190a250565b6121f7335f356001600160e01b031916612f08565b6122135760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c602090815260409182902080546001600160f01b0319168155600101805467ffffffffffffffff1916905590519182527f11a9d1a77f76361ed131c19b1dc5758504c51dbde2e49fc973a0ef9577ad13d5910160405180910390a150565b5f546001600160a01b031633148061230f575060015460405163b700961360e01b81526001600160a01b039091169063b7009613906122d090339030906001600160e01b03195f351690600401614d8a565b602060405180830381865afa1580156122eb573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061230f9190614b7e565b612317575f80fd5b600180546001600160a01b0319166001600160a01b03831690811790915560405133907fa3396fd7f6e0a21b50e5089d2da70d5ac0a3bbbd1f617a93f134b76389980198905f90a350565b612377335f356001600160e01b031916612f08565b6123935760405162461bcd60e51b8152600401610b3e90614b34565b8380156123a757506001600160401b038216155b156123c5576040516323f0e08b60e11b815260040160405180910390fd5b6040805160a081018252861515815285151560208083019182526001600160a01b038088168486019081526001600160401b03808916606087019081528882166080880190815263ffffffff8f165f908152600c90965294889020965187549651935191518316600160b01b0267ffffffffffffffff60b01b199290951662010000029190911662010000600160f01b03199315156101000261ff00199215159290921661ffff199097169690961717919091169390931717835551600190920180549290911667ffffffffffffffff19909216919091179055517f92ca48f4323e5539c637c7a03bd3e43941aa078e4f165e1d02c7e309317c429c906125179088908890889088908890889063ffffffff969096168652931515602086015291151560408501526001600160a01b031660608401526001600160401b0390811660808401521660a082015260c00190565b60405180910390a1505050505050565b5f5b92915050565b612544335f356001600160e01b031916612f08565b6125605760405162461bcd60e51b8152600401610b3e90614b34565b6005805460ff60a01b1916600160a01b1790556040517f9e87fac88ff661f02d44f95383c817fece4bce600a3dab7a54406878b965e752905f90a1565b6125b2335f356001600160e01b031916612f08565b6125ce5760405162461bcd60e51b8152600401610b3e90614b34565b600380549082905560408051828152602081018490527ffbe912fdd0185617e8cafd12d97b59175b90e15f5c629faf6413469af54ee0809101610e4f565b5f612622335f356001600160e01b031916612f08565b61263e5760405162461bcd60e51b8152600401610b3e90614b34565b6002546001146126605760405162461bcd60e51b8152600401610b3e90614b5a565b6002805581600160085460ff16600281111561267e5761267e614a9d565b0361275e576001600160a01b0381165f908152600b602052604090205460ff161580156126ba575060085461010090046001600160a01b031615155b156127595760085460095460405163043bb58960e51b815260048101919091526001600160a01b03838116602483015261010090920490911690638776b12090604401602060405180830381865afa158015612718573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061273c9190614b7e565b61275957604051630d3e301d60e11b815260040160405180910390fd5b6127da565b600260085460ff16600281111561277757612777614a9d565b036127da576001600160a01b0381165f908152600a602052604090205460ff161580156127bc57506001600160a01b0381165f908152600b602052604090205460ff16155b156127da5760405163b75d22ed60e01b815260040160405180910390fd5b6001600160a01b0386165f9081526004602052604090205460ff166128125760405163645fd19f60e11b815260040160405180910390fd5b61281e86868686612fae565b9150856001600160a01b03167f6f9b974223f85a1ae805c33b8b519039e2435481d949db1110de151a94d587af8660405161285b91815260200190565b60405180910390a2506001600255949350505050565b5f612887335f356001600160e01b031916612f08565b6128a35760405162461bcd60e51b8152600401610b3e90614b34565b600554600160a01b900460ff16156128ce5760405163e0f9e71d60e01b815260040160405180910390fd5b6128d782613acb565b6128e033612e0c565b6040516318457e6160e01b81526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df16906318457e6190612934905f908190819033908a90600401614d44565b5f604051808303815f87803b15801561294b575f80fd5b505af115801561295d573d5f803e3d5ffd5b5050505061296b8383613c77565b9050612529838383613d91565b61298d335f356001600160e01b031916612f08565b6129a95760405162461bcd60e51b8152600401610b3e90614b34565b60088054610100600160a81b0319166101006001600160a01b03851690810291909117909155600982905560408051918252602082018390527fdd311e842d0dd0d276250faf64c7c9bed12bf94d1e4c1e33b304102684994fc89101610e4f565b612a1f335f356001600160e01b031916612f08565b612a3b5760405162461bcd60e51b8152600401610b3e90614b34565b600254600114612a5d5760405162461bcd60e51b8152600401610b3e90614b5a565b600280556001600160a01b0384165f9081526004602052604090205460ff16612a995760405163645fd19f60e11b815260040160405180910390fd5b5f612aa685858533612fae565b9050612ad3338686846005600c9054906101000a90046001600160401b03166001600160401b0316613708565b612add8183612871565b5050600160025550505050565b612aff335f356001600160e01b031916612f08565b612b1b5760405162461bcd60e51b8152600401610b3e90614b34565b60405163ca5eb5e160e01b81526001600160a01b0382811660048301527f0000000000000000000000001a44076050125825900e736c501f859c50fe728c169063ca5eb5e1906024015f604051808303815f87803b158015612b7b575f80fd5b505af1158015612b8d573d5f803e3d5ffd5b5050505050565b612ba9335f356001600160e01b031916612f08565b612bc55760405162461bcd60e51b8152600401610b3e90614b34565b63ffffffff81165f818152600c6020908152604091829020805460ff19168155915192835290917f1cb867ed6a020e020ea220d4f48bb8e36552abf9095e093e377d33933f2b31e49101610e4f565b612c29335f356001600160e01b031916612f08565b612c455760405162461bcd60e51b8152600401610b3e90614b34565b5f5b828110156112fc5781600a5f868685818110612c6557612c65614bb4565b9050602002016020810190612c7a9190614652565b6001600160a01b0316815260208101919091526040015f20805460ff1916911515919091179055838382818110612cb357612cb3614bb4565b9050602002016020810190612cc89190614652565b6001600160a01b03167fbe87d514b3e161103a7c1ddd4c9f1f4a93559090d347b432e657a09fc47f8e0b83604051612d04911515815260200190565b60405180910390a2600101612c47565b612d29335f356001600160e01b031916612f08565b612d455760405162461bcd60e51b8152600401610b3e90614b34565b806001600160401b03165f03612d6e576040516323f0e08b60e11b815260040160405180910390fd5b63ffffffff83165f818152600c602090815260409182902080546001600160401b038616600160b01b0267ffffffffffffffff60b01b196001600160a01b038916620100008102610100600160b01b0319909416939093176101001716178255835194855291840191909152917f34fe916485e02ec88e487b0e611e5c9bacabba9e3eaae7a900aa08be8197d419910160405180910390a150505050565b6001600160a01b0381165f90815260076020526040902054421015612e445760405163f64059db60e01b815260040160405180910390fd5b50565b612e5c335f356001600160e01b031916612f08565b612e785760405162461bcd60e51b8152600401610b3e90614b34565b5f80546001600160a01b0319166001600160a01b0383169081178255604051909133917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a350565b5f60208201803590600d908390612ed990866147b5565b63ffffffff16815260208101919091526040015f20541492915050565b5f612f018383613de8565b9392505050565b6001545f906001600160a01b03168015801590612f8f575060405163b700961360e01b81526001600160a01b0382169063b700961390612f5090879030908890600401614d8a565b602060405180830381865afa158015612f6b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f8f9190614b7e565b80612fa657505f546001600160a01b038581169116145b949350505050565b5f835f03612fcf5760405163259be69560e11b815260040160405180910390fd5b7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015613027575f80fd5b505af1158015613039573d5f803e3d5ffd5b505050505f7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa15801561309a573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906130be9190614bc8565b90505f7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b0316635001f3b56040518163ffffffff1660e01b8152600401602060405180830381865afa15801561311d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131419190614bdf565b6001600160a01b0316876001600160a01b0316036131eb576131e4867f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131b9573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906131dd9190614bfa565b6012613a63565b9050613435565b6040516312e2d8f360e01b81526001600160a01b0388811660048301525f917f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65909116906312e2d8f3906024016040805180830381865afa158015613252573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906132769190614c15565b50905080156132c6576132bf87896001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156131b9573d5f803e3d5ffd5b9150613433565b6040516312e2d8f360e01b81526001600160a01b0389811660048301525f917f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65909116906312e2d8f3906024016040805180830381865afa15801561332d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133519190614c15565b9150505f816001600160a01b031663679aefce6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613391573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906133b59190614bc8565b905061342e818b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156133f7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061341b9190614bfa565b61342690600a614d36565b8b9190613a48565b935050505b505b613460817f00000000000000000000000000000000000000000000000000000000000f424084613a48565b9250848310156134835760405163097b2ad560e31b815260040160405180910390fd5b5f6134af84847f00000000000000000000000000000000000000000000000000000000000f4240613a48565b90506135138160127f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b90505f6135c2847f00000000000000000000000000000000000000000000000000000000000f42407f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df6001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613597573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906135bb9190614bc8565b9190613a48565b90506136268160127f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611ae6573d5f803e3d5ffd5b6003549091506136368383614db7565b111561367b5760405162461bcd60e51b815260206004820152601460248201527311195c1bdcda5d0818d85c08195e18d95959195960621b6044820152606401610b3e565b604051631ceb5d1960e11b81526001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df16906339d6ba32906136cf9033908d908d908c908c90600401614d44565b5f604051808303815f87803b1580156136e6575f80fd5b505af11580156136f8573d5f803e3d5ffd5b5050505050505050949350505050565b6137128142614db7565b6001600160a01b038681165f81815260076020908152604091829020949094556005548151948501929092529187169183019190915260608201859052608082018490524260a083015260c082018390526001600160601b03169060e00160408051601f1981840301815291815281516020928301205f848152600690935290822055600580546001600160601b0316916137ac83614dca565b91906101000a8154816001600160601b0302191690836001600160601b0316021790555050846001600160a01b0316866001600160a01b0316827fe96d7872363f475d18b2f5390caaa5eaa96b2d38e42c62afe4ac08ebd2b13c3a87874288604051613831949392919093845260208401929092526040830152606082015260800190565b60405180910390a4505050505050565b63ffffffff81165f908152600d6020526040812054806125295760405163f6ff4fb760e01b815263ffffffff84166004820152602401610b3e565b613884613eab565b600c5f61389460208a018a6147b5565b63ffffffff16815260208101919091526040015f205460ff166138e0576138be60208801886147b5565b604051635408978f60e11b815263ffffffff9091166004820152602401610b3e565b7f0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a656001600160a01b031663c2c4c5c16040518163ffffffff1660e01b81526004015f604051808303815f87803b158015613938575f80fd5b505af115801561394a573d5f803e3d5ffd5b505050505f80868681019061395f9190614def565b604051631ceb5d1960e11b815291935091506001600160a01b037f000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df16906339d6ba32906139b8905f908190819087908990600401614d44565b5f604051808303815f87803b1580156139cf575f80fd5b505af11580156139e1573d5f803e3d5ffd5b505050506139f082828a613ed8565b505050505050505050565b63ffffffff82165f818152600d6020908152604091829020849055815192835282018390527f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b9101610e4f565b5f825f190484118302158202613a5c575f80fd5b5091020490565b5f8160ff168360ff1603613a78575082612f01565b8160ff168360ff161015613aac57613a908383614e12565b613a9b90600a614d36565b613aa59085614e2b565b9050612f01565b613ab68284614e12565b613ac190600a614d36565b613aa59085614e42565b5f600c81613adc60208501856147b5565b63ffffffff16815260208082019290925260409081015f20815160a081018352815460ff8082161515835261010082041615159482018590526201000081046001600160a01b031693820193909352600160b01b9092046001600160401b0390811660608401526001909101541660808201529150613b8457613b6260208301836147b5565b604051630a8acb5760e21b815263ffffffff9091166004820152602401610b3e565b60408101516001600160a01b0316613baf5760405163098a923160e41b815260040160405180910390fd5b5f613bc06040840160208501614652565b6001600160a01b031603613be75760405163f4a986cb60e01b815260040160405180910390fd5b80606001516001600160401b0316826060016020810190613c089190614545565b6001600160401b03161115613c3057604051636e33764360e11b815260040160405180910390fd5b6080808201516001600160401b031690613c4f90840160608501614545565b6001600160401b031610156111f857604051637abded0b60e11b815260040160405180910390fd5b5f73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee613c9d6060840160408501614652565b6001600160a01b031614613cc457604051634e4f206760e01b815260040160405180910390fd5b5f83613cd66040850160208601614652565b604051602001613cf99291909182526001600160a01b0316602082015260400190565b60408051601f1981840301815291905290505f613d56613d1f6080860160608701614545565b6001600160401b03165f613d4f60408051600360f01b602082015281516002818303018152602290910190915290565b9190613f21565b90505f613d86613d6960208701876147b5565b848460405180604001604052803481526020015f81525033613f86565b519695505050505050565b7fe0ec62d39b054dc2fd626dbc271483735df6e6fa1ef8389754bf8ab27a75eab28184613dc46040860160208701614652565b6040805193845260208401929092526001600160a01b031690820152606001610fcc565b5f8083613dfb6040850160208601614652565b604051602001613e1e9291909182526001600160a01b0316602082015260400190565b60408051601f1981840301815291905290505f613e44613d1f6080860160608701614545565b905073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee613e6b6060860160408701614652565b6001600160a01b031614613e9257604051634e4f206760e01b815260040160405180910390fd5b5f613d86613ea360208701876147b5565b84845f61408c565b600554600160a01b900460ff1615613ed65760405163e0f9e71d60e01b815260040160405180910390fd5b565b60408051828152602081018590526001600160a01b038416918101919091527fb944fddc61d7fedb8b736790454ba972000703b0d21c7481d6dbf95b7c2cc2f190606001610fcc565b6060836003613f30825f61416a565b61ffff1614613f6357613f43815f61416a565b604051633a51740d60e01b815261ffff9091166004820152602401610b3e565b5f613f6e85856141c6565b9050613f7c86600183614248565b9695505050505050565b613f8e6144a8565b5f613f9b845f01516142b1565b602085015190915015613fb557613fb584602001516142d8565b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b0316632637a450826040518060a001604052808b63ffffffff1681526020016140058c613841565b81526020018a81526020018981526020015f8960200151111515815250866040518463ffffffff1660e01b8152600401614040929190614eae565b60806040518083038185885af115801561405c573d5f803e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906140819190614f7e565b979650505050505050565b604080518082019091525f80825260208201527f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b031663ddc28c586040518060a001604052808863ffffffff1681526020016140ee89613841565b8152602001878152602001868152602001851515815250306040518363ffffffff1660e01b8152600401614123929190614eae565b6040805180830381865afa15801561413d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906141619190614fef565b95945050505050565b5f614176826002614db7565b835110156141bd5760405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606401610b3e565b50016002015190565b60606fffffffffffffffffffffffffffffffff82161561421757604080516001600160801b0319608086811b8216602084015285901b16603082015201604051602081830303815290604052612f01565b6040516001600160801b0319608085901b166020820152603001604051602081830303815290604052905092915050565b6060836003614257825f61416a565b61ffff161461426a57613f43815f61416a565b84600161427785516143b7565b614282906001615009565b868660405160200161429895949392919061502b565b6040516020818303038152906040529150509392505050565b5f8134146142d4576040516304fb820960e51b8152346004820152602401610b3e565b5090565b5f7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b031663e4fe1d946040518163ffffffff1660e01b8152600401602060405180830381865afa158015614335573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906143599190614bdf565b90506001600160a01b038116614382576040516329b99a9560e11b815260040160405180910390fd5b6111f86001600160a01b038216337f0000000000000000000000001a44076050125825900e736c501f859c50fe728c856143e5565b5f61ffff8211156142d4576040516306dfcc6560e41b81526010600482015260248101839052604401610b3e565b604080516001600160a01b038581166024830152841660448201526064808201849052825180830390910181526084909101909152602080820180516001600160e01b03166323b872dd60e01b17815282516112fc93889390925f9283929183919082885af18061445b576040513d5f823e3d81fd5b50505f513d9150811561447257806001141561447f565b6001600160a01b0384163b155b156112fc57604051635274afe760e01b81526001600160a01b0385166004820152602401610b3e565b60405180606001604052805f80191681526020015f6001600160401b031681526020016144e660405180604001604052805f81526020015f81525090565b905290565b6001600160a01b0381168114612e44575f80fd5b5f805f60608486031215614511575f80fd5b833561451c816144eb565b95602085013595506040909401359392505050565b6001600160401b0381168114612e44575f80fd5b5f60208284031215614555575f80fd5b8135612f0181614531565b5f60608284031215614570575f80fd5b50919050565b5f8083601f840112614586575f80fd5b5081356001600160401b0381111561459c575f80fd5b6020830191508360208285010111156145b3575f80fd5b9250929050565b5f805f805f805f60e0888a0312156145d0575f80fd5b6145da8989614560565b96506060880135955060808801356001600160401b03808211156145fc575f80fd5b6146088b838c01614576565b909750955060a08a0135915061461d826144eb565b90935060c08901359080821115614632575f80fd5b5061463f8a828b01614576565b989b979a50959850939692959293505050565b5f60208284031215614662575f80fd5b8135612f01816144eb565b803563ffffffff81168114614680575f80fd5b919050565b5f8060408385031215614696575f80fd5b61469f8361466d565b915060208301356146af816144eb565b809150509250929050565b5f80604083850312156146cb575f80fd5b6146d48361466d565b915060208301356146af81614531565b5f602082840312156146f4575f80fd5b813560038110612f01575f80fd5b5f8060408385031215614713575f80fd5b61471c8361466d565b946020939093013593505050565b8015158114612e44575f80fd5b5f805f60408486031215614749575f80fd5b83356001600160401b038082111561475f575f80fd5b818601915086601f830112614772575f80fd5b813581811115614780575f80fd5b8760208260051b8501011115614794575f80fd5b602092830195509350508401356147aa8161472a565b809150509250925092565b5f602082840312156147c5575f80fd5b612f018261466d565b60ff81168114612e44575f80fd5b5f805f805f805f60e0888a0312156147f2575f80fd5b87356147fd816144eb565b96506020880135955060408801359450606088013593506080880135614822816147ce565b9699959850939692959460a0840135945060c09093013592915050565b5f805f8060808587031215614852575f80fd5b843561485d816144eb565b93506020850135925060408501359150606085013561487b816144eb565b939692955090935050565b5f805f805f805f60e0888a03121561489c575f80fd5b8735965060208801356148ae816144eb565b955060408801356148be816144eb565b969995985095966060810135965060808101359560a0820135955060c0909101359350915050565b5f805f805f8060c087890312156148fb575f80fd5b6149048761466d565b955060208701356149148161472a565b945060408701356149248161472a565b93506060870135614934816144eb565b9250608087013561494481614531565b915060a087013561495481614531565b809150509295509295509295565b5f805f8060a08587031215614975575f80fd5b61497f8686614560565b935060608501356001600160401b03811115614999575f80fd5b6149a587828801614576565b909450925050608085013561487b816144eb565b5f602082840312156149c9575f80fd5b5035919050565b5f60a08284031215614570575f80fd5b5f80604083850312156149f1575f80fd5b8235915060208301356001600160401b03811115614a0d575f80fd5b614a19858286016149d0565b9150509250929050565b5f8060408385031215614a34575f80fd5b823561471c816144eb565b5f805f8060808587031215614a52575f80fd5b8435614a5d816144eb565b9350602085013592506040850135915060608501356001600160401b03811115614a85575f80fd5b614a91878288016149d0565b91505092959194509250565b634e487b7160e01b5f52602160045260245ffd5b60038110614acd57634e487b7160e01b5f52602160045260245ffd5b9052565b602081016125298284614ab1565b5f805f60608486031215614af1575f80fd5b614afa8461466d565b92506020840135614b0a816144eb565b915060408401356147aa81614531565b5f60608284031215614b2a575f80fd5b612f018383614560565b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b5f60208284031215614b8e575f80fd5b8151612f018161472a565b60408101614ba78285614ab1565b612f016020830184614ab1565b634e487b7160e01b5f52603260045260245ffd5b5f60208284031215614bd8575f80fd5b5051919050565b5f60208284031215614bef575f80fd5b8151612f01816144eb565b5f60208284031215614c0a575f80fd5b8151612f01816147ce565b5f8060408385031215614c26575f80fd5b8251614c318161472a565b60208401519092506146af816144eb565b634e487b7160e01b5f52601160045260245ffd5b600181815b80851115614c9057815f1904821115614c7657614c76614c42565b80851615614c8357918102915b93841c9390800290614c5b565b509250929050565b5f82614ca657506001612529565b81614cb257505f612529565b8160018114614cc85760028114614cd257614cee565b6001915050612529565b60ff841115614ce357614ce3614c42565b50506001821b612529565b5060208310610133831016604e8410600b8410161715614d11575081810a612529565b614d1b8383614c56565b805f1904821115614d2e57614d2e614c42565b029392505050565b5f612f0160ff841683614c98565b6001600160a01b039586168152938516602085015260408401929092529092166060820152608081019190915260a00190565b8181038181111561252957612529614c42565b6001600160a01b0393841681529190921660208201526001600160e01b0319909116604082015260600190565b8082018082111561252957612529614c42565b5f6001600160601b03808316818103614de557614de5614c42565b6001019392505050565b5f8060408385031215614e00575f80fd5b8235915060208301356146af816144eb565b60ff828116828216039081111561252957612529614c42565b808202811582820484141761252957612529614c42565b5f82614e5c57634e487b7160e01b5f52601260045260245ffd5b500490565b5f5b83811015614e7b578181015183820152602001614e63565b50505f910152565b5f8151808452614e9a816020860160208601614e61565b601f01601f19169290920160200192915050565b6040815263ffffffff8351166040820152602083015160608201525f604084015160a06080840152614ee360e0840182614e83565b90506060850151603f198483030160a0850152614f008282614e83565b60809690960151151560c08501525050506001600160a01b039190911660209091015290565b5f60408284031215614f36575f80fd5b604051604081018181106001600160401b0382111715614f6457634e487b7160e01b5f52604160045260245ffd5b604052825181526020928301519281019290925250919050565b5f60808284031215614f8e575f80fd5b604051606081018181106001600160401b0382111715614fbc57634e487b7160e01b5f52604160045260245ffd5b604052825181526020830151614fd181614531565b6020820152614fe38460408501614f26565b60408201529392505050565b5f60408284031215614fff575f80fd5b612f018383614f26565b61ffff81811683821601908082111561502457615024614c42565b5092915050565b5f865161503c818460208b01614e61565b6001600160f81b031960f888811b82169285019283526001600160f01b031960f089901b16600184015286901b1660038201528351615082816004840160208801614e61565b0160040197965050505050505056fea26469706673582212209144f070eb2e9c2c72abc494aba3b15824651689389cb1fb377cd4cf0f26e00764736f6c63430008160033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000003014c3cdadd8a5a1d8eba50e35212a53ba3a504000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a650000000000000000000000001a44076050125825900e736c501f859c50fe728c
-----Decoded View---------------
Arg [0] : _owner (address): 0x03014C3cDaDD8a5A1D8EBa50e35212a53Ba3A504
Arg [1] : _vault (address): 0xCcdda614f1aa349c267de68D27C5664D928D63dF
Arg [2] : _accountant (address): 0x8B3BDA484Dae27e0138E1b80e9dc1D698B2B8a65
Arg [3] : _endpoint (address): 0x1a44076050125825900e736c501f859c50fE728c
-----Encoded View---------------
4 Constructor Arguments found :
Arg [0] : 00000000000000000000000003014c3cdadd8a5a1d8eba50e35212a53ba3a504
Arg [1] : 000000000000000000000000ccdda614f1aa349c267de68d27c5664d928d63df
Arg [2] : 0000000000000000000000008b3bda484dae27e0138e1b80e9dc1d698b2b8a65
Arg [3] : 0000000000000000000000001a44076050125825900e736c501f859c50fe728c
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 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.