Overview
S Balance
0 S
S Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 8 from a total of 8 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Verify Intent_ep... | 4762560 | 28 hrs ago | IN | 0 S | 0.0107553 | ||||
Store Source Cha... | 4029642 | 6 days ago | IN | 0 S | 0.0016561 | ||||
Verify Intent_ep... | 3911180 | 7 days ago | IN | 0 S | 0.00711108 | ||||
Store Source Cha... | 3910714 | 7 days ago | IN | 0 S | 0.00256687 | ||||
Store Source Cha... | 3910710 | 7 days ago | IN | 0 S | 0.0016561 | ||||
Store Source Cha... | 3910706 | 7 days ago | IN | 0 S | 0.0016561 | ||||
Store Source Cha... | 3910704 | 7 days ago | IN | 0 S | 0.0016561 | ||||
Store Source Cha... | 3910699 | 7 days ago | IN | 0 S | 0.00256647 |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
LiquidityIntentsVerifierV1
Compiler Version
v0.8.24+commit.e11b9ed9
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../interfaces/IRegistryV1.sol"; import "../interfaces/ILexPoolV1.sol"; import "./NonceMechanisms/AccountAndActionSerialNonceBase.sol"; import "./MultiSourceChainIntentsVerifierBase.sol"; /** * @title LiquidityIntentsVerifierV1 * @notice This contract is responsible for verifying liquidity related intents * @dev All verification functions in this contract work in the same manner * - Verify that the payload was signed by the trader * - Verify that the nonce is valid (and mark it as used) * - Perform the action * - Emit an event */ contract LiquidityIntentsVerifierV1 is MultiSourceChainIntentsVerifierBase, AccountAndActionSerialNonceBase { // ***** Enums ***** enum LiquidityIntentsVerifierActions { NONE, REQUEST_EPOCH_DEPOSIT, REQUEST_EPOCH_REDEEM } // ***** Action Verifications (Immutable) ***** string public constant REQUEST_PAYLOAD_EPOCH_DEPOSIT_TYPE_DESCRIPTOR = "LiquidityProviderRequestPayload_EpochDeposit(uint256 nonce,address pool,address liquidityProvider,uint256 epoch,uint256 amount,uint256 minAmountOut)"; string public constant REQUEST_PAYLOAD_EPOCH_REDEEM_TYPE_DESCRIPTOR = "LiquidityProviderRequestPayload_EpochRedeem(uint256 nonce,address pool,address liquidityProvider,uint256 epoch,uint256 amount,uint256 minAmountOut)"; struct LiquidityProviderRequestPayload_EpochDeposit { uint256 nonce; address pool; address liquidityProvider; uint256 epoch; uint256 amount; uint256 minAmountOut; } struct LiquidityProviderRequestPayload_EpochRedeem { uint256 nonce; address pool; address liquidityProvider; uint256 epoch; uint256 amount; uint256 minAmountOut; } // ***** Contracts (Immutable) ***** IRegistryV1 public immutable registry; // ***** Events ***** event LiquidityIntentVerified( address indexed sender, address indexed pool, address indexed liquidityProvider, LiquidityIntentsVerifierActions action, uint256 nonce ); event InteractedOnBehalf( address indexed pool, address indexed liquidityProvider, address indexed permissionedAccount, LiquidityIntentsVerifierActions action ); // ***** Modifiers ***** modifier notContract() { require(tx.origin == _msgSender()); _; } // ***** Views ***** function recoverEpochDepositPayloadSigner( LiquidityProviderRequestPayload_EpochDeposit calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashEpochDepositPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverEpochRedeemPayloadSigner( LiquidityProviderRequestPayload_EpochRedeem calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashEpochRedeemPayload(payload) ) ); return ecrecover(digest, v, r, s); } // ***** Constructor ***** constructor( IRegistryV1 _registry ) MultiSourceChainIntentsVerifierBase("Liquidity Intents Verifier", "1") { require(address(_registry) != address(0), "WRONG_PARAMS"); registry = _registry; } // ***** Context Utils ***** function _msgSender() public view returns (address) { return msg.sender; } // ***** Liquidity Provider Interactions -- Epoch Requests ***** function verifyIntent_epochDeposit( LiquidityProviderRequestPayload_EpochDeposit calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domain, bytes32 referralCode ) external payable { bytes32 domainSeparator = domainSeparatorForAsset(payload.pool); address recoveredSigner = recoverEpochDepositPayloadSigner( payload, v, r, s, domainSeparator ); require( recoveredSigner == payload.liquidityProvider || isIntentPermitted( address(ILexPoolV1(payload.pool).underlying()), payload.liquidityProvider, recoveredSigner ), "NOT_SIGNED_BY_LIQUIDITY_PROVIDER" ); require(payload.amount > 0, "AMOUNT_ZERO"); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.liquidityProvider, uint8(LiquidityIntentsVerifierActions.REQUEST_EPOCH_DEPOSIT), payload.nonce ); ILexPoolV1(payload.pool).requestDepositViaIntent( payload.liquidityProvider, payload.amount, payload.minAmountOut, domain, referralCode ); // Events emit LiquidityIntentVerified( msg.sender, payload.pool, payload.liquidityProvider, LiquidityIntentsVerifierActions.REQUEST_EPOCH_DEPOSIT, payload.nonce ); } function verifyIntent_epochRedeem( LiquidityProviderRequestPayload_EpochRedeem calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable { bytes32 domainSeparator = domainSeparatorForAsset(payload.pool); address recoveredSigner = recoverEpochRedeemPayloadSigner( payload, v, r, s, domainSeparator ); require( recoveredSigner == payload.liquidityProvider || isIntentPermitted( address(ILexPoolV1(payload.pool).underlying()), payload.liquidityProvider, recoveredSigner ), "NOT_SIGNED_BY_LIQUIDITY_PROVIDER" ); require(payload.amount > 0, "AMOUNT_ZERO"); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.liquidityProvider, uint8(LiquidityIntentsVerifierActions.REQUEST_EPOCH_REDEEM), payload.nonce ); ILexPoolV1(payload.pool).requestRedeemViaIntent( payload.liquidityProvider, payload.amount, payload.minAmountOut ); // Events emit LiquidityIntentVerified( msg.sender, payload.pool, payload.liquidityProvider, LiquidityIntentsVerifierActions.REQUEST_EPOCH_REDEEM, payload.nonce ); } function interactOnBehalf_epochDeposit( address pool, address liquidityProvider, uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external payable { address permissionedAccount = msg.sender; require( isIntentPermitted( address(ILexPoolV1(pool).underlying()), liquidityProvider, permissionedAccount ), "NO_PERMISSION" ); require(amount > 0, "AMOUNT_ZERO"); ILexPoolV1(pool).requestDepositViaIntent( liquidityProvider, amount, minAmountOut, domain, referralCode ); // Events emit InteractedOnBehalf( pool, liquidityProvider, permissionedAccount, LiquidityIntentsVerifierActions.REQUEST_EPOCH_DEPOSIT ); } function interactOnBehalf_epochRedeem( address pool, address liquidityProvider, uint256 amount, uint256 minAmountOut ) external payable { address permissionedAccount = msg.sender; require( isIntentPermitted( address(ILexPoolV1(pool).underlying()), liquidityProvider, permissionedAccount ), "NO_PERMISSION" ); require(amount > 0, "AMOUNT_ZERO"); ILexPoolV1(pool).requestRedeemViaIntent( liquidityProvider, amount, minAmountOut ); // Events emit InteractedOnBehalf( pool, liquidityProvider, permissionedAccount, LiquidityIntentsVerifierActions.REQUEST_EPOCH_REDEEM ); } // ***** Intents Permissions ***** function isIntentPermitted( address settlementAsset, address owner, address spender ) internal view returns (bool) { string memory dynRoleIntentsPermissionsSuffix = intentsPermissions[ OFTChip(settlementAsset) ]; if (bytes(dynRoleIntentsPermissionsSuffix).length == 0) { return false; } IntentsPermissions intentsPermissionsContract = IntentsPermissions( registry.getDynamicRoleAddress( string( abi.encodePacked( DYN_ROLE_INTENTS_PERMISSIONS_PREFIX, dynRoleIntentsPermissionsSuffix ) ) ) ); if (address(intentsPermissionsContract) == address(0)) { return false; } return intentsPermissionsContract.permission( PermissionsType.LIQUIDITY, owner, spender ); } // ***** Signed Payloads Utils ***** function hashEpochDepositPayload( LiquidityProviderRequestPayload_EpochDeposit memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(REQUEST_PAYLOAD_EPOCH_DEPOSIT_TYPE_DESCRIPTOR)), payload.nonce, payload.pool, payload.liquidityProvider, payload.epoch, payload.amount, payload.minAmountOut ) ); } function hashEpochRedeemPayload( LiquidityProviderRequestPayload_EpochRedeem memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(REQUEST_PAYLOAD_EPOCH_REDEEM_TYPE_DESCRIPTOR)), payload.nonce, payload.pool, payload.liquidityProvider, payload.epoch, payload.amount, payload.minAmountOut ) ); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import { ILayerZeroComposer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroComposer.sol"; /** * @title IOAppComposer * @dev This interface defines the OApp Composer, allowing developers to inherit only the OApp package without the protocol. */ // solhint-disable-next-line no-empty-blocks interface IOAppComposer is ILayerZeroComposer {}
// 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: MIT pragma solidity ^0.8.20; /** * @title IOAppMsgInspector * @dev Interface for the OApp Message Inspector, allowing examination of message and options contents. */ interface IOAppMsgInspector { // Custom error message for inspection failure error InspectionFailed(bytes message, bytes options); /** * @notice Allows the inspector to examine LayerZero message contents and optionally throw a revert if invalid. * @param _message The message payload to be inspected. * @param _options Additional options or parameters for inspection. * @return valid A boolean indicating whether the inspection passed (true) or failed (false). * * @dev Optionally done as a revert, OR use the boolean provided to handle the failure. */ function inspect(bytes calldata _message, bytes calldata _options) external view returns (bool valid); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; /** * @dev Struct representing enforced option parameters. */ struct EnforcedOptionParam { uint32 eid; // Endpoint ID uint16 msgType; // Message Type bytes options; // Additional options } /** * @title IOAppOptionsType3 * @dev Interface for the OApp with Type 3 Options, allowing the setting and combining of enforced options. */ interface IOAppOptionsType3 { // Custom error message for invalid options error InvalidOptions(bytes options); // Event emitted when enforced options are set event EnforcedOptionSet(EnforcedOptionParam[] _enforcedOptions); /** * @notice Sets enforced options for specific endpoint and message type combinations. * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options. */ function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) external; /** * @notice Combines options for a given endpoint and message type. * @param _eid The endpoint ID. * @param _msgType The OApp message type. * @param _extraOptions Additional options passed by the caller. * @return options The combination of caller specified options AND enforced options. */ function combineOptions( uint32 _eid, uint16 _msgType, bytes calldata _extraOptions ) external view returns (bytes memory options); }
// 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 { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IOAppOptionsType3, EnforcedOptionParam } from "../interfaces/IOAppOptionsType3.sol"; /** * @title OAppOptionsType3 * @dev Abstract contract implementing the IOAppOptionsType3 interface with type 3 options. */ abstract contract OAppOptionsType3 is IOAppOptionsType3, Ownable { uint16 internal constant OPTION_TYPE_3 = 3; // @dev The "msgType" should be defined in the child contract. mapping(uint32 eid => mapping(uint16 msgType => bytes enforcedOption)) public enforcedOptions; /** * @dev Sets the enforced options for specific endpoint and message type combinations. * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options. * * @dev Only the owner/admin of the OApp can call this function. * @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc. * @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType. * eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay * if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose(). */ function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) public virtual onlyOwner { _setEnforcedOptions(_enforcedOptions); } /** * @dev Sets the enforced options for specific endpoint and message type combinations. * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options. * * @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc. * @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType. * eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay * if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose(). */ function _setEnforcedOptions(EnforcedOptionParam[] memory _enforcedOptions) internal virtual { for (uint256 i = 0; i < _enforcedOptions.length; i++) { // @dev Enforced options are only available for optionType 3, as type 1 and 2 dont support combining. _assertOptionsType3(_enforcedOptions[i].options); enforcedOptions[_enforcedOptions[i].eid][_enforcedOptions[i].msgType] = _enforcedOptions[i].options; } emit EnforcedOptionSet(_enforcedOptions); } /** * @notice Combines options for a given endpoint and message type. * @param _eid The endpoint ID. * @param _msgType The OAPP message type. * @param _extraOptions Additional options passed by the caller. * @return options The combination of caller specified options AND enforced options. * * @dev If there is an enforced lzReceive option: * - {gasLimit: 200k, msg.value: 1 ether} AND a caller supplies a lzReceive option: {gasLimit: 100k, msg.value: 0.5 ether} * - The resulting options will be {gasLimit: 300k, msg.value: 1.5 ether} when the message is executed on the remote lzReceive() function. * @dev This presence of duplicated options is handled off-chain in the verifier/executor. */ function combineOptions( uint32 _eid, uint16 _msgType, bytes calldata _extraOptions ) public view virtual returns (bytes memory) { bytes memory enforced = enforcedOptions[_eid][_msgType]; // No enforced options, pass whatever the caller supplied, even if it's empty or legacy type 1/2 options. if (enforced.length == 0) return _extraOptions; // No caller options, return enforced if (_extraOptions.length == 0) return enforced; // @dev If caller provided _extraOptions, must be type 3 as its the ONLY type that can be combined. if (_extraOptions.length >= 2) { _assertOptionsType3(_extraOptions); // @dev Remove the first 2 bytes containing the type from the _extraOptions and combine with enforced. return bytes.concat(enforced, _extraOptions[2:]); } // No valid set of options was found. revert InvalidOptions(_extraOptions); } /** * @dev Internal function to assert that options are of type 3. * @param _options The options to be checked. */ function _assertOptionsType3(bytes memory _options) internal pure virtual { uint16 optionsType; assembly { optionsType := mload(add(_options, 2)) } if (optionsType != OPTION_TYPE_3) revert InvalidOptions(_options); } }
// 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 { OAppSender, MessagingFee, MessagingReceipt } from "./OAppSender.sol"; // @dev Import the 'Origin' so it's exposed to OApp implementers // solhint-disable-next-line no-unused-import import { OAppReceiver, Origin } from "./OAppReceiver.sol"; import { OAppCore } from "./OAppCore.sol"; /** * @title OApp * @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality. */ abstract contract OApp is OAppSender, OAppReceiver { /** * @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) OAppCore(_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(OAppSender, OAppReceiver) returns (uint64 senderVersion, uint64 receiverVersion) { return (SENDER_VERSION, RECEIVER_VERSION); } }
// 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 { 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 { 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 { MessagingReceipt, MessagingFee } from "../../oapp/OAppSender.sol"; /** * @dev Struct representing token parameters for the OFT send() operation. */ struct SendParam { uint32 dstEid; // Destination endpoint ID. bytes32 to; // Recipient address. uint256 amountLD; // Amount to send in local decimals. uint256 minAmountLD; // Minimum amount to send in local decimals. bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message. bytes composeMsg; // The composed message for the send() operation. bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations. } /** * @dev Struct representing OFT limit information. * @dev These amounts can change dynamically and are up the the specific oft implementation. */ struct OFTLimit { uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient. uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient. } /** * @dev Struct representing OFT receipt information. */ struct OFTReceipt { uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals. // @dev In non-default implementations, the amountReceivedLD COULD differ from this value. uint256 amountReceivedLD; // Amount of tokens to be received on the remote side. } /** * @dev Struct representing OFT fee details. * @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI. */ struct OFTFeeDetail { int256 feeAmountLD; // Amount of the fee in local decimals. string description; // Description of the fee. } /** * @title IOFT * @dev Interface for the OftChain (OFT) token. * @dev Does not inherit ERC20 to accommodate usage by OFTAdapter as well. * @dev This specific interface ID is '0x02e49c2c'. */ interface IOFT { // Custom error messages error InvalidLocalDecimals(); error SlippageExceeded(uint256 amountLD, uint256 minAmountLD); // Events event OFTSent( bytes32 indexed guid, // GUID of the OFT message. uint32 dstEid, // Destination Endpoint ID. address indexed fromAddress, // Address of the sender on the src chain. uint256 amountSentLD, // Amount of tokens sent in local decimals. uint256 amountReceivedLD // Amount of tokens received in local decimals. ); event OFTReceived( bytes32 indexed guid, // GUID of the OFT message. uint32 srcEid, // Source Endpoint ID. address indexed toAddress, // Address of the recipient on the dst chain. uint256 amountReceivedLD // Amount of tokens received in local decimals. ); /** * @notice Retrieves interfaceID and the version of the OFT. * @return interfaceId The interface ID. * @return version The version. * * @dev interfaceId: This specific interface ID is '0x02e49c2c'. * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs. * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented. * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1) */ function oftVersion() external view returns (bytes4 interfaceId, uint64 version); /** * @notice Retrieves the address of the token associated with the OFT. * @return token The address of the ERC20 token implementation. */ function token() external view returns (address); /** * @notice Indicates whether the OFT contract requires approval of the 'token()' to send. * @return requiresApproval Needs approval of the underlying token implementation. * * @dev Allows things like wallet implementers to determine integration requirements, * without understanding the underlying token implementation. */ function approvalRequired() external view returns (bool); /** * @notice Retrieves the shared decimals of the OFT. * @return sharedDecimals The shared decimals of the OFT. */ function sharedDecimals() external view returns (uint8); /** * @notice Provides a quote for OFT-related operations. * @param _sendParam The parameters for the send operation. * @return limit The OFT limit information. * @return oftFeeDetails The details of OFT fees. * @return receipt The OFT receipt information. */ function quoteOFT( SendParam calldata _sendParam ) external view returns (OFTLimit memory, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory); /** * @notice Provides a quote for the send() operation. * @param _sendParam The parameters for the send() operation. * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token. * @return fee The calculated LayerZero messaging fee from the send() operation. * * @dev MessagingFee: LayerZero msg fee * - nativeFee: The native fee. * - lzTokenFee: The lzToken fee. */ function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory); /** * @notice Executes the send() operation. * @param _sendParam The parameters for the send operation. * @param _fee The fee information supplied by the caller. * - nativeFee: The native fee. * - lzTokenFee: The lzToken fee. * @param _refundAddress The address to receive any excess funds from fees etc. on the src. * @return receipt The LayerZero messaging receipt from the send() operation. * @return oftReceipt The OFT receipt information. * * @dev MessagingReceipt: LayerZero msg receipt * - guid: The unique identifier for the sent message. * - nonce: The nonce of the sent message. * - fee: The LayerZero fee incurred for the message. */ function send( SendParam calldata _sendParam, MessagingFee calldata _fee, address _refundAddress ) external payable returns (MessagingReceipt memory, OFTReceipt memory); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; library OFTComposeMsgCodec { // Offset constants for decoding composed messages uint8 private constant NONCE_OFFSET = 8; uint8 private constant SRC_EID_OFFSET = 12; uint8 private constant AMOUNT_LD_OFFSET = 44; uint8 private constant COMPOSE_FROM_OFFSET = 76; /** * @dev Encodes a OFT composed message. * @param _nonce The nonce value. * @param _srcEid The source endpoint ID. * @param _amountLD The amount in local decimals. * @param _composeMsg The composed message. * @return _msg The encoded Composed message. */ function encode( uint64 _nonce, uint32 _srcEid, uint256 _amountLD, bytes memory _composeMsg // 0x[composeFrom][composeMsg] ) internal pure returns (bytes memory _msg) { _msg = abi.encodePacked(_nonce, _srcEid, _amountLD, _composeMsg); } /** * @dev Retrieves the nonce from the composed message. * @param _msg The message. * @return The nonce value. */ function nonce(bytes calldata _msg) internal pure returns (uint64) { return uint64(bytes8(_msg[:NONCE_OFFSET])); } /** * @dev Retrieves the source endpoint ID from the composed message. * @param _msg The message. * @return The source endpoint ID. */ function srcEid(bytes calldata _msg) internal pure returns (uint32) { return uint32(bytes4(_msg[NONCE_OFFSET:SRC_EID_OFFSET])); } /** * @dev Retrieves the amount in local decimals from the composed message. * @param _msg The message. * @return The amount in local decimals. */ function amountLD(bytes calldata _msg) internal pure returns (uint256) { return uint256(bytes32(_msg[SRC_EID_OFFSET:AMOUNT_LD_OFFSET])); } /** * @dev Retrieves the composeFrom value from the composed message. * @param _msg The message. * @return The composeFrom value. */ function composeFrom(bytes calldata _msg) internal pure returns (bytes32) { return bytes32(_msg[AMOUNT_LD_OFFSET:COMPOSE_FROM_OFFSET]); } /** * @dev Retrieves the composed message. * @param _msg The message. * @return The composed message. */ function composeMsg(bytes calldata _msg) internal pure returns (bytes memory) { return _msg[COMPOSE_FROM_OFFSET:]; } /** * @dev Converts an address to bytes32. * @param _addr The address to convert. * @return The bytes32 representation of the address. */ function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } /** * @dev Converts bytes32 to an address. * @param _b The bytes32 value to convert. * @return The address representation of bytes32. */ function bytes32ToAddress(bytes32 _b) internal pure returns (address) { return address(uint160(uint256(_b))); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; library OFTMsgCodec { // Offset constants for encoding and decoding OFT messages uint8 private constant SEND_TO_OFFSET = 32; uint8 private constant SEND_AMOUNT_SD_OFFSET = 40; /** * @dev Encodes an OFT LayerZero message. * @param _sendTo The recipient address. * @param _amountShared The amount in shared decimals. * @param _composeMsg The composed message. * @return _msg The encoded message. * @return hasCompose A boolean indicating whether the message has a composed payload. */ function encode( bytes32 _sendTo, uint64 _amountShared, bytes memory _composeMsg ) internal view returns (bytes memory _msg, bool hasCompose) { hasCompose = _composeMsg.length > 0; // @dev Remote chains will want to know the composed function caller ie. msg.sender on the src. _msg = hasCompose ? abi.encodePacked(_sendTo, _amountShared, addressToBytes32(msg.sender), _composeMsg) : abi.encodePacked(_sendTo, _amountShared); } /** * @dev Checks if the OFT message is composed. * @param _msg The OFT message. * @return A boolean indicating whether the message is composed. */ function isComposed(bytes calldata _msg) internal pure returns (bool) { return _msg.length > SEND_AMOUNT_SD_OFFSET; } /** * @dev Retrieves the recipient address from the OFT message. * @param _msg The OFT message. * @return The recipient address. */ function sendTo(bytes calldata _msg) internal pure returns (bytes32) { return bytes32(_msg[:SEND_TO_OFFSET]); } /** * @dev Retrieves the amount in shared decimals from the OFT message. * @param _msg The OFT message. * @return The amount in shared decimals. */ function amountSD(bytes calldata _msg) internal pure returns (uint64) { return uint64(bytes8(_msg[SEND_TO_OFFSET:SEND_AMOUNT_SD_OFFSET])); } /** * @dev Retrieves the composed message from the OFT message. * @param _msg The OFT message. * @return The composed message. */ function composeMsg(bytes calldata _msg) internal pure returns (bytes memory) { return _msg[SEND_AMOUNT_SD_OFFSET:]; } /** * @dev Converts an address to bytes32. * @param _addr The address to convert. * @return The bytes32 representation of the address. */ function addressToBytes32(address _addr) internal pure returns (bytes32) { return bytes32(uint256(uint160(_addr))); } /** * @dev Converts bytes32 to an address. * @param _b The bytes32 value to convert. * @return The address representation of bytes32. */ function bytes32ToAddress(bytes32 _b) internal pure returns (address) { return address(uint160(uint256(_b))); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { IOFT, OFTCore } from "./OFTCore.sol"; /** * @title OFT Contract * @dev OFT is an ERC-20 token that extends the functionality of the OFTCore contract. */ abstract contract OFT is OFTCore, ERC20 { /** * @dev Constructor for the OFT contract. * @param _name The name of the OFT. * @param _symbol The symbol of the OFT. * @param _lzEndpoint The LayerZero endpoint address. * @param _delegate The delegate capable of making OApp configurations inside of the endpoint. */ constructor( string memory _name, string memory _symbol, address _lzEndpoint, address _delegate ) ERC20(_name, _symbol) OFTCore(decimals(), _lzEndpoint, _delegate) {} /** * @dev Retrieves the address of the underlying ERC20 implementation. * @return The address of the OFT token. * * @dev In the case of OFT, address(this) and erc20 are the same contract. */ function token() public view returns (address) { return address(this); } /** * @notice Indicates whether the OFT contract requires approval of the 'token()' to send. * @return requiresApproval Needs approval of the underlying token implementation. * * @dev In the case of OFT where the contract IS the token, approval is NOT required. */ function approvalRequired() external pure virtual returns (bool) { return false; } /** * @dev Burns tokens from the sender's specified balance. * @param _from The address to debit the tokens from. * @param _amountLD The amount of tokens to send in local decimals. * @param _minAmountLD The minimum amount to send in local decimals. * @param _dstEid The destination chain ID. * @return amountSentLD The amount sent in local decimals. * @return amountReceivedLD The amount received in local decimals on the remote. */ function _debit( address _from, uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid ) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) { (amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid); // @dev In NON-default OFT, amountSentLD could be 100, with a 10% fee, the amountReceivedLD amount is 90, // therefore amountSentLD CAN differ from amountReceivedLD. // @dev Default OFT burns on src. _burn(_from, amountSentLD); } /** * @dev Credits tokens to the specified address. * @param _to The address to credit the tokens to. * @param _amountLD The amount of tokens to credit in local decimals. * @dev _srcEid The source chain ID. * @return amountReceivedLD The amount of tokens ACTUALLY received in local decimals. */ function _credit( address _to, uint256 _amountLD, uint32 /*_srcEid*/ ) internal virtual override returns (uint256 amountReceivedLD) { // @dev Default OFT mints on dst. _mint(_to, _amountLD); // @dev In the case of NON-default OFT, the _amountLD MIGHT not be == amountReceivedLD. return _amountLD; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import { OApp, Origin } from "../oapp/OApp.sol"; import { OAppOptionsType3 } from "../oapp/libs/OAppOptionsType3.sol"; import { IOAppMsgInspector } from "../oapp/interfaces/IOAppMsgInspector.sol"; import { OAppPreCrimeSimulator } from "../precrime/OAppPreCrimeSimulator.sol"; import { IOFT, SendParam, OFTLimit, OFTReceipt, OFTFeeDetail, MessagingReceipt, MessagingFee } from "./interfaces/IOFT.sol"; import { OFTMsgCodec } from "./libs/OFTMsgCodec.sol"; import { OFTComposeMsgCodec } from "./libs/OFTComposeMsgCodec.sol"; /** * @title OFTCore * @dev Abstract contract for the OftChain (OFT) token. */ abstract contract OFTCore is IOFT, OApp, OAppPreCrimeSimulator, OAppOptionsType3 { using OFTMsgCodec for bytes; using OFTMsgCodec for bytes32; // @notice Provides a conversion rate when swapping between denominations of SD and LD // - shareDecimals == SD == shared Decimals // - localDecimals == LD == local decimals // @dev Considers that tokens have different decimal amounts on various chains. // @dev eg. // For a token // - locally with 4 decimals --> 1.2345 => uint(12345) // - remotely with 2 decimals --> 1.23 => uint(123) // - The conversion rate would be 10 ** (4 - 2) = 100 // @dev If you want to send 1.2345 -> (uint 12345), you CANNOT represent that value on the remote, // you can only display 1.23 -> uint(123). // @dev To preserve the dust that would otherwise be lost on that conversion, // we need to unify a denomination that can be represented on ALL chains inside of the OFT mesh uint256 public immutable decimalConversionRate; // @notice Msg types that are used to identify the various OFT operations. // @dev This can be extended in child contracts for non-default oft operations // @dev These values are used in things like combineOptions() in OAppOptionsType3.sol. uint16 public constant SEND = 1; uint16 public constant SEND_AND_CALL = 2; // Address of an optional contract to inspect both 'message' and 'options' address public msgInspector; event MsgInspectorSet(address inspector); /** * @dev Constructor. * @param _localDecimals The decimals of the token on the local chain (this chain). * @param _endpoint The address of the LayerZero endpoint. * @param _delegate The delegate capable of making OApp configurations inside of the endpoint. */ constructor(uint8 _localDecimals, address _endpoint, address _delegate) OApp(_endpoint, _delegate) { if (_localDecimals < sharedDecimals()) revert InvalidLocalDecimals(); decimalConversionRate = 10 ** (_localDecimals - sharedDecimals()); } /** * @notice Retrieves interfaceID and the version of the OFT. * @return interfaceId The interface ID. * @return version The version. * * @dev interfaceId: This specific interface ID is '0x02e49c2c'. * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs. * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented. * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1) */ function oftVersion() external pure virtual returns (bytes4 interfaceId, uint64 version) { return (type(IOFT).interfaceId, 1); } /** * @dev Retrieves the shared decimals of the OFT. * @return The shared decimals of the OFT. * * @dev Sets an implicit cap on the amount of tokens, over uint64.max() will need some sort of outbound cap / totalSupply cap * Lowest common decimal denominator between chains. * Defaults to 6 decimal places to provide up to 18,446,744,073,709.551615 units (max uint64). * For tokens exceeding this totalSupply(), they will need to override the sharedDecimals function with something smaller. * ie. 4 sharedDecimals would be 1,844,674,407,370,955.1615 */ function sharedDecimals() public view virtual returns (uint8) { return 6; } /** * @dev Sets the message inspector address for the OFT. * @param _msgInspector The address of the message inspector. * * @dev This is an optional contract that can be used to inspect both 'message' and 'options'. * @dev Set it to address(0) to disable it, or set it to a contract address to enable it. */ function setMsgInspector(address _msgInspector) public virtual onlyOwner { msgInspector = _msgInspector; emit MsgInspectorSet(_msgInspector); } /** * @notice Provides a quote for OFT-related operations. * @param _sendParam The parameters for the send operation. * @return oftLimit The OFT limit information. * @return oftFeeDetails The details of OFT fees. * @return oftReceipt The OFT receipt information. */ function quoteOFT( SendParam calldata _sendParam ) external view virtual returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt) { uint256 minAmountLD = 0; // Unused in the default implementation. uint256 maxAmountLD = type(uint64).max; // Unused in the default implementation. oftLimit = OFTLimit(minAmountLD, maxAmountLD); // Unused in the default implementation; reserved for future complex fee details. oftFeeDetails = new OFTFeeDetail[](0); // @dev This is the same as the send() operation, but without the actual send. // - amountSentLD is the amount in local decimals that would be sent from the sender. // - amountReceivedLD is the amount in local decimals that will be credited to the recipient on the remote OFT instance. // @dev The amountSentLD MIGHT not equal the amount the user actually receives. HOWEVER, the default does. (uint256 amountSentLD, uint256 amountReceivedLD) = _debitView( _sendParam.amountLD, _sendParam.minAmountLD, _sendParam.dstEid ); oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD); } /** * @notice Provides a quote for the send() operation. * @param _sendParam The parameters for the send() operation. * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token. * @return msgFee The calculated LayerZero messaging fee from the send() operation. * * @dev MessagingFee: LayerZero msg fee * - nativeFee: The native fee. * - lzTokenFee: The lzToken fee. */ function quoteSend( SendParam calldata _sendParam, bool _payInLzToken ) external view virtual returns (MessagingFee memory msgFee) { // @dev mock the amount to receive, this is the same operation used in the send(). // The quote is as similar as possible to the actual send() operation. (, uint256 amountReceivedLD) = _debitView(_sendParam.amountLD, _sendParam.minAmountLD, _sendParam.dstEid); // @dev Builds the options and OFT message to quote in the endpoint. (bytes memory message, bytes memory options) = _buildMsgAndOptions(_sendParam, amountReceivedLD); // @dev Calculates the LayerZero fee for the send() operation. return _quote(_sendParam.dstEid, message, options, _payInLzToken); } /** * @dev Executes the send operation. * @param _sendParam The parameters for the send operation. * @param _fee The calculated fee for the send() operation. * - nativeFee: The native fee. * - lzTokenFee: The lzToken fee. * @param _refundAddress The address to receive any excess funds. * @return msgReceipt The receipt for the send operation. * @return oftReceipt The OFT receipt information. * * @dev MessagingReceipt: LayerZero msg receipt * - guid: The unique identifier for the sent message. * - nonce: The nonce of the sent message. * - fee: The LayerZero fee incurred for the message. */ function send( SendParam calldata _sendParam, MessagingFee calldata _fee, address _refundAddress ) external payable virtual returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) { // @dev Applies the token transfers regarding this send() operation. // - amountSentLD is the amount in local decimals that was ACTUALLY sent/debited from the sender. // - amountReceivedLD is the amount in local decimals that will be received/credited to the recipient on the remote OFT instance. (uint256 amountSentLD, uint256 amountReceivedLD) = _debit( msg.sender, _sendParam.amountLD, _sendParam.minAmountLD, _sendParam.dstEid ); // @dev Builds the options and OFT message to quote in the endpoint. (bytes memory message, bytes memory options) = _buildMsgAndOptions(_sendParam, amountReceivedLD); // @dev Sends the message to the LayerZero endpoint and returns the LayerZero msg receipt. msgReceipt = _lzSend(_sendParam.dstEid, message, options, _fee, _refundAddress); // @dev Formulate the OFT receipt. oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD); emit OFTSent(msgReceipt.guid, _sendParam.dstEid, msg.sender, amountSentLD, amountReceivedLD); } /** * @dev Internal function to build the message and options. * @param _sendParam The parameters for the send() operation. * @param _amountLD The amount in local decimals. * @return message The encoded message. * @return options The encoded options. */ function _buildMsgAndOptions( SendParam calldata _sendParam, uint256 _amountLD ) internal view virtual returns (bytes memory message, bytes memory options) { bool hasCompose; // @dev This generated message has the msg.sender encoded into the payload so the remote knows who the caller is. (message, hasCompose) = OFTMsgCodec.encode( _sendParam.to, _toSD(_amountLD), // @dev Must be include a non empty bytes if you want to compose, EVEN if you dont need it on the remote. // EVEN if you dont require an arbitrary payload to be sent... eg. '0x01' _sendParam.composeMsg ); // @dev Change the msg type depending if its composed or not. uint16 msgType = hasCompose ? SEND_AND_CALL : SEND; // @dev Combine the callers _extraOptions with the enforced options via the OAppOptionsType3. options = combineOptions(_sendParam.dstEid, msgType, _sendParam.extraOptions); // @dev Optionally inspect the message and options depending if the OApp owner has set a msg inspector. // @dev If it fails inspection, needs to revert in the implementation. ie. does not rely on return boolean if (msgInspector != address(0)) IOAppMsgInspector(msgInspector).inspect(message, options); } /** * @dev Internal function to handle the receive on the LayerZero endpoint. * @param _origin The origin information. * - srcEid: The source chain endpoint ID. * - sender: The sender address from the src chain. * - nonce: The nonce of the LayerZero message. * @param _guid The unique identifier for the received LayerZero message. * @param _message The encoded message. * @dev _executor The address of the executor. * @dev _extraData Additional data. */ function _lzReceive( Origin calldata _origin, bytes32 _guid, bytes calldata _message, address /*_executor*/, // @dev unused in the default implementation. bytes calldata /*_extraData*/ // @dev unused in the default implementation. ) internal virtual override { // @dev The src sending chain doesnt know the address length on this chain (potentially non-evm) // Thus everything is bytes32() encoded in flight. address toAddress = _message.sendTo().bytes32ToAddress(); // @dev Credit the amountLD to the recipient and return the ACTUAL amount the recipient received in local decimals uint256 amountReceivedLD = _credit(toAddress, _toLD(_message.amountSD()), _origin.srcEid); if (_message.isComposed()) { // @dev Proprietary composeMsg format for the OFT. bytes memory composeMsg = OFTComposeMsgCodec.encode( _origin.nonce, _origin.srcEid, amountReceivedLD, _message.composeMsg() ); // @dev Stores the lzCompose payload that will be executed in a separate tx. // Standardizes functionality for executing arbitrary contract invocation on some non-evm chains. // @dev The off-chain executor will listen and process the msg based on the src-chain-callers compose options passed. // @dev The index is used when a OApp needs to compose multiple msgs on lzReceive. // For default OFT implementation there is only 1 compose msg per lzReceive, thus its always 0. endpoint.sendCompose(toAddress, _guid, 0 /* the index of the composed message*/, composeMsg); } emit OFTReceived(_guid, _origin.srcEid, toAddress, amountReceivedLD); } /** * @dev Internal function to handle the OAppPreCrimeSimulator simulated receive. * @param _origin The origin information. * - srcEid: The source chain endpoint ID. * - sender: The sender address from the src chain. * - nonce: The nonce of the LayerZero message. * @param _guid The unique identifier for the received LayerZero message. * @param _message The LayerZero message. * @param _executor The address of the off-chain executor. * @param _extraData Arbitrary data passed by the msg executor. * * @dev Enables the preCrime simulator to mock sending lzReceive() messages, * routes the msg down from the OAppPreCrimeSimulator, and back up to the OAppReceiver. */ function _lzReceiveSimulate( Origin calldata _origin, bytes32 _guid, bytes calldata _message, address _executor, bytes calldata _extraData ) internal virtual override { _lzReceive(_origin, _guid, _message, _executor, _extraData); } /** * @dev Check if the peer is considered 'trusted' by the OApp. * @param _eid The endpoint ID to check. * @param _peer The peer to check. * @return Whether the peer passed is considered 'trusted' by the OApp. * * @dev Enables OAppPreCrimeSimulator to check whether a potential Inbound Packet is from a trusted source. */ function isPeer(uint32 _eid, bytes32 _peer) public view virtual override returns (bool) { return peers[_eid] == _peer; } /** * @dev Internal function to remove dust from the given local decimal amount. * @param _amountLD The amount in local decimals. * @return amountLD The amount after removing dust. * * @dev Prevents the loss of dust when moving amounts between chains with different decimals. * @dev eg. uint(123) with a conversion rate of 100 becomes uint(100). */ function _removeDust(uint256 _amountLD) internal view virtual returns (uint256 amountLD) { return (_amountLD / decimalConversionRate) * decimalConversionRate; } /** * @dev Internal function to convert an amount from shared decimals into local decimals. * @param _amountSD The amount in shared decimals. * @return amountLD The amount in local decimals. */ function _toLD(uint64 _amountSD) internal view virtual returns (uint256 amountLD) { return _amountSD * decimalConversionRate; } /** * @dev Internal function to convert an amount from local decimals into shared decimals. * @param _amountLD The amount in local decimals. * @return amountSD The amount in shared decimals. */ function _toSD(uint256 _amountLD) internal view virtual returns (uint64 amountSD) { return uint64(_amountLD / decimalConversionRate); } /** * @dev Internal function to mock the amount mutation from a OFT debit() operation. * @param _amountLD The amount to send in local decimals. * @param _minAmountLD The minimum amount to send in local decimals. * @dev _dstEid The destination endpoint ID. * @return amountSentLD The amount sent, in local decimals. * @return amountReceivedLD The amount to be received on the remote chain, in local decimals. * * @dev This is where things like fees would be calculated and deducted from the amount to be received on the remote. */ function _debitView( uint256 _amountLD, uint256 _minAmountLD, uint32 /*_dstEid*/ ) internal view virtual returns (uint256 amountSentLD, uint256 amountReceivedLD) { // @dev Remove the dust so nothing is lost on the conversion between chains with different decimals for the token. amountSentLD = _removeDust(_amountLD); // @dev The amount to send is the same as amount received in the default implementation. amountReceivedLD = amountSentLD; // @dev Check for slippage. if (amountReceivedLD < _minAmountLD) { revert SlippageExceeded(amountReceivedLD, _minAmountLD); } } /** * @dev Internal function to perform a debit operation. * @param _from The address to debit. * @param _amountLD The amount to send in local decimals. * @param _minAmountLD The minimum amount to send in local decimals. * @param _dstEid The destination endpoint ID. * @return amountSentLD The amount sent in local decimals. * @return amountReceivedLD The amount received in local decimals on the remote. * * @dev Defined here but are intended to be overriden depending on the OFT implementation. * @dev Depending on OFT implementation the _amountLD could differ from the amountReceivedLD. */ function _debit( address _from, uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid ) internal virtual returns (uint256 amountSentLD, uint256 amountReceivedLD); /** * @dev Internal function to perform a credit operation. * @param _to The address to credit. * @param _amountLD The amount to credit in local decimals. * @param _srcEid The source endpoint ID. * @return amountReceivedLD The amount ACTUALLY received in local decimals. * * @dev Defined here but are intended to be overriden depending on the OFT implementation. * @dev Depending on OFT implementation the _amountLD could differ from the amountReceivedLD. */ function _credit( address _to, uint256 _amountLD, uint32 _srcEid ) internal virtual returns (uint256 amountReceivedLD); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; // @dev Import the Origin so it's exposed to OAppPreCrimeSimulator implementers. // solhint-disable-next-line no-unused-import import { InboundPacket, Origin } from "../libs/Packet.sol"; /** * @title IOAppPreCrimeSimulator Interface * @dev Interface for the preCrime simulation functionality in an OApp. */ interface IOAppPreCrimeSimulator { // @dev simulation result used in PreCrime implementation error SimulationResult(bytes result); error OnlySelf(); /** * @dev Emitted when the preCrime contract address is set. * @param preCrimeAddress The address of the preCrime contract. */ event PreCrimeSet(address preCrimeAddress); /** * @dev Retrieves the address of the preCrime contract implementation. * @return The address of the preCrime contract. */ function preCrime() external view returns (address); /** * @dev Retrieves the address of the OApp contract. * @return The address of the OApp contract. */ function oApp() external view returns (address); /** * @dev Sets the preCrime contract address. * @param _preCrime The address of the preCrime contract. */ function setPreCrime(address _preCrime) external; /** * @dev Mocks receiving a packet, then reverts with a series of data to infer the state/result. * @param _packets An array of LayerZero InboundPacket objects representing received packets. */ function lzReceiveAndRevert(InboundPacket[] calldata _packets) external payable; /** * @dev checks if the specified peer is considered 'trusted' by the OApp. * @param _eid The endpoint Id to check. * @param _peer The peer to check. * @return Whether the peer passed is considered 'trusted' by the OApp. */ function isPeer(uint32 _eid, bytes32 _peer) external view returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; struct PreCrimePeer { uint32 eid; bytes32 preCrime; bytes32 oApp; } // TODO not done yet interface IPreCrime { error OnlyOffChain(); // for simulate() error PacketOversize(uint256 max, uint256 actual); error PacketUnsorted(); error SimulationFailed(bytes reason); // for preCrime() error SimulationResultNotFound(uint32 eid); error InvalidSimulationResult(uint32 eid, bytes reason); error CrimeFound(bytes crime); function getConfig(bytes[] calldata _packets, uint256[] calldata _packetMsgValues) external returns (bytes memory); function simulate( bytes[] calldata _packets, uint256[] calldata _packetMsgValues ) external payable returns (bytes memory); function buildSimulationResult() external view returns (bytes memory); function preCrime( bytes[] calldata _packets, uint256[] calldata _packetMsgValues, bytes[] calldata _simulations ) external; function version() external view returns (uint64 major, uint8 minor); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import { PacketV1Codec } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/PacketV1Codec.sol"; /** * @title InboundPacket * @dev Structure representing an inbound packet received by the contract. */ struct InboundPacket { Origin origin; // Origin information of the packet. uint32 dstEid; // Destination endpointId of the packet. address receiver; // Receiver address for the packet. bytes32 guid; // Unique identifier of the packet. uint256 value; // msg.value of the packet. address executor; // Executor address for the packet. bytes message; // Message payload of the packet. bytes extraData; // Additional arbitrary data for the packet. } /** * @title PacketDecoder * @dev Library for decoding LayerZero packets. */ library PacketDecoder { using PacketV1Codec for bytes; /** * @dev Decode an inbound packet from the given packet data. * @param _packet The packet data to decode. * @return packet An InboundPacket struct representing the decoded packet. */ function decode(bytes calldata _packet) internal pure returns (InboundPacket memory packet) { packet.origin = Origin(_packet.srcEid(), _packet.sender(), _packet.nonce()); packet.dstEid = _packet.dstEid(); packet.receiver = _packet.receiverB20(); packet.guid = _packet.guid(); packet.message = _packet.message(); } /** * @dev Decode multiple inbound packets from the given packet data and associated message values. * @param _packets An array of packet data to decode. * @param _packetMsgValues An array of associated message values for each packet. * @return packets An array of InboundPacket structs representing the decoded packets. */ function decode( bytes[] calldata _packets, uint256[] memory _packetMsgValues ) internal pure returns (InboundPacket[] memory packets) { packets = new InboundPacket[](_packets.length); for (uint256 i = 0; i < _packets.length; i++) { bytes calldata packet = _packets[i]; packets[i] = PacketDecoder.decode(packet); // @dev Allows the verifier to specify the msg.value that gets passed in lzReceive. packets[i].value = _packetMsgValues[i]; } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { IPreCrime } from "./interfaces/IPreCrime.sol"; import { IOAppPreCrimeSimulator, InboundPacket, Origin } from "./interfaces/IOAppPreCrimeSimulator.sol"; /** * @title OAppPreCrimeSimulator * @dev Abstract contract serving as the base for preCrime simulation functionality in an OApp. */ abstract contract OAppPreCrimeSimulator is IOAppPreCrimeSimulator, Ownable { // The address of the preCrime implementation. address public preCrime; /** * @dev Retrieves the address of the OApp contract. * @return The address of the OApp contract. * * @dev The simulator contract is the base contract for the OApp by default. * @dev If the simulator is a separate contract, override this function. */ function oApp() external view virtual returns (address) { return address(this); } /** * @dev Sets the preCrime contract address. * @param _preCrime The address of the preCrime contract. */ function setPreCrime(address _preCrime) public virtual onlyOwner { preCrime = _preCrime; emit PreCrimeSet(_preCrime); } /** * @dev Interface for pre-crime simulations. Always reverts at the end with the simulation results. * @param _packets An array of InboundPacket objects representing received packets to be delivered. * * @dev WARNING: MUST revert at the end with the simulation results. * @dev Gives the preCrime implementation the ability to mock sending packets to the lzReceive function, * WITHOUT actually executing them. */ function lzReceiveAndRevert(InboundPacket[] calldata _packets) public payable virtual { for (uint256 i = 0; i < _packets.length; i++) { InboundPacket calldata packet = _packets[i]; // Ignore packets that are not from trusted peers. if (!isPeer(packet.origin.srcEid, packet.origin.sender)) continue; // @dev Because a verifier is calling this function, it doesnt have access to executor params: // - address _executor // - bytes calldata _extraData // preCrime will NOT work for OApps that rely on these two parameters inside of their _lzReceive(). // They are instead stubbed to default values, address(0) and bytes("") // @dev Calling this.lzReceiveSimulate removes ability for assembly return 0 callstack exit, // which would cause the revert to be ignored. this.lzReceiveSimulate{ value: packet.value }( packet.origin, packet.guid, packet.message, packet.executor, packet.extraData ); } // @dev Revert with the simulation results. msg.sender must implement IPreCrime.buildSimulationResult(). revert SimulationResult(IPreCrime(msg.sender).buildSimulationResult()); } /** * @dev Is effectively an internal function because msg.sender must be address(this). * Allows resetting the call stack for 'internal' calls. * @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 of the packet. * @param _message The message payload of the packet. * @param _executor The executor address for the packet. * @param _extraData Additional data for the packet. */ function lzReceiveSimulate( Origin calldata _origin, bytes32 _guid, bytes calldata _message, address _executor, bytes calldata _extraData ) external payable virtual { // @dev Ensure ONLY can be called 'internally'. if (msg.sender != address(this)) revert OnlySelf(); _lzReceiveSimulate(_origin, _guid, _message, _executor, _extraData); } /** * @dev Internal function to handle the OAppPreCrimeSimulator simulated receive. * @param _origin The origin information. * - srcEid: The source chain endpoint ID. * - sender: The sender address from the src chain. * - nonce: The nonce of the LayerZero message. * @param _guid The GUID of the LayerZero message. * @param _message The LayerZero message. * @param _executor The address of the off-chain executor. * @param _extraData Arbitrary data passed by the msg executor. * * @dev Enables the preCrime simulator to mock sending lzReceive() messages, * routes the msg down from the OAppPreCrimeSimulator, and back up to the OAppReceiver. */ function _lzReceiveSimulate( Origin calldata _origin, bytes32 _guid, bytes calldata _message, address _executor, bytes calldata _extraData ) internal virtual; /** * @dev checks if the specified peer is considered 'trusted' by the OApp. * @param _eid The endpoint Id to check. * @param _peer The peer to check. * @return Whether the peer passed is considered 'trusted' by the OApp. */ function isPeer(uint32 _eid, bytes32 _peer) public view virtual returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; /** * @title ILayerZeroComposer */ interface ILayerZeroComposer { /** * @notice Composes a LayerZero message from an OApp. * @param _from The address initiating the composition, typically the OApp where the lzReceive was called. * @param _guid The unique identifier for the corresponding LayerZero src/dst tx. * @param _message The composed message payload in bytes. NOT necessarily the same payload passed via lzReceive. * @param _executor The address of the executor for the composed message. * @param _extraData Additional arbitrary data in bytes passed by the entity who executes the lzCompose. */ function lzCompose( address _from, bytes32 _guid, bytes calldata _message, address _executor, bytes calldata _extraData ) external payable; }
// 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.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.0; import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import { SetConfigParam } from "./IMessageLibManager.sol"; enum MessageLibType { Send, Receive, SendAndReceive } interface IMessageLib is IERC165 { function setConfig(address _oapp, SetConfigParam[] calldata _config) external; function getConfig(uint32 _eid, address _oapp, uint32 _configType) external view returns (bytes memory config); function isSupportedEid(uint32 _eid) external view returns (bool); // message libs of same major version are compatible function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion); function messageLibType() external view returns (MessageLibType); }
// 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 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 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 IMessagingContext { function isSendingMessage() external view returns (bool); function getSendContext() external view returns (uint32 dstEid, address sender); }
// SPDX-License-Identifier: MIT pragma solidity >=0.8.0; import { MessagingFee } from "./ILayerZeroEndpointV2.sol"; import { IMessageLib } from "./IMessageLib.sol"; struct Packet { uint64 nonce; uint32 srcEid; address sender; uint32 dstEid; bytes32 receiver; bytes32 guid; bytes message; } interface ISendLib is IMessageLib { function send( Packet calldata _packet, bytes calldata _options, bool _payInLzToken ) external returns (MessagingFee memory, bytes memory encodedPacket); function quote( Packet calldata _packet, bytes calldata _options, bool _payInLzToken ) external view returns (MessagingFee memory); function setTreasury(address _treasury) external; function withdrawFee(address _to, uint256 _amount) external; function withdrawLzTokenFee(address _lzToken, address _to, uint256 _amount) external; }
// SPDX-License-Identifier: LZBL-1.2 pragma solidity ^0.8.20; library AddressCast { error AddressCast_InvalidSizeForAddress(); error AddressCast_InvalidAddress(); function toBytes32(bytes calldata _addressBytes) internal pure returns (bytes32 result) { if (_addressBytes.length > 32) revert AddressCast_InvalidAddress(); result = bytes32(_addressBytes); unchecked { uint256 offset = 32 - _addressBytes.length; result = result >> (offset * 8); } } function toBytes32(address _address) internal pure returns (bytes32 result) { result = bytes32(uint256(uint160(_address))); } function toBytes(bytes32 _addressBytes32, uint256 _size) internal pure returns (bytes memory result) { if (_size == 0 || _size > 32) revert AddressCast_InvalidSizeForAddress(); result = new bytes(_size); unchecked { uint256 offset = 256 - _size * 8; assembly { mstore(add(result, 32), shl(offset, _addressBytes32)) } } } function toAddress(bytes32 _addressBytes32) internal pure returns (address result) { result = address(uint160(uint256(_addressBytes32))); } function toAddress(bytes calldata _addressBytes) internal pure returns (address result) { if (_addressBytes.length != 20) revert AddressCast_InvalidAddress(); result = address(bytes20(_addressBytes)); } }
// SPDX-License-Identifier: LZBL-1.2 pragma solidity ^0.8.20; import { Packet } from "../../interfaces/ISendLib.sol"; import { AddressCast } from "../../libs/AddressCast.sol"; library PacketV1Codec { using AddressCast for address; using AddressCast for bytes32; uint8 internal constant PACKET_VERSION = 1; // header (version + nonce + path) // version uint256 private constant PACKET_VERSION_OFFSET = 0; // nonce uint256 private constant NONCE_OFFSET = 1; // path uint256 private constant SRC_EID_OFFSET = 9; uint256 private constant SENDER_OFFSET = 13; uint256 private constant DST_EID_OFFSET = 45; uint256 private constant RECEIVER_OFFSET = 49; // payload (guid + message) uint256 private constant GUID_OFFSET = 81; // keccak256(nonce + path) uint256 private constant MESSAGE_OFFSET = 113; function encode(Packet memory _packet) internal pure returns (bytes memory encodedPacket) { encodedPacket = abi.encodePacked( PACKET_VERSION, _packet.nonce, _packet.srcEid, _packet.sender.toBytes32(), _packet.dstEid, _packet.receiver, _packet.guid, _packet.message ); } function encodePacketHeader(Packet memory _packet) internal pure returns (bytes memory) { return abi.encodePacked( PACKET_VERSION, _packet.nonce, _packet.srcEid, _packet.sender.toBytes32(), _packet.dstEid, _packet.receiver ); } function encodePayload(Packet memory _packet) internal pure returns (bytes memory) { return abi.encodePacked(_packet.guid, _packet.message); } function header(bytes calldata _packet) internal pure returns (bytes calldata) { return _packet[0:GUID_OFFSET]; } function version(bytes calldata _packet) internal pure returns (uint8) { return uint8(bytes1(_packet[PACKET_VERSION_OFFSET:NONCE_OFFSET])); } function nonce(bytes calldata _packet) internal pure returns (uint64) { return uint64(bytes8(_packet[NONCE_OFFSET:SRC_EID_OFFSET])); } function srcEid(bytes calldata _packet) internal pure returns (uint32) { return uint32(bytes4(_packet[SRC_EID_OFFSET:SENDER_OFFSET])); } function sender(bytes calldata _packet) internal pure returns (bytes32) { return bytes32(_packet[SENDER_OFFSET:DST_EID_OFFSET]); } function senderAddressB20(bytes calldata _packet) internal pure returns (address) { return sender(_packet).toAddress(); } function dstEid(bytes calldata _packet) internal pure returns (uint32) { return uint32(bytes4(_packet[DST_EID_OFFSET:RECEIVER_OFFSET])); } function receiver(bytes calldata _packet) internal pure returns (bytes32) { return bytes32(_packet[RECEIVER_OFFSET:GUID_OFFSET]); } function receiverB20(bytes calldata _packet) internal pure returns (address) { return receiver(_packet).toAddress(); } function guid(bytes calldata _packet) internal pure returns (bytes32) { return bytes32(_packet[GUID_OFFSET:MESSAGE_OFFSET]); } function message(bytes calldata _packet) internal pure returns (bytes calldata) { return bytes(_packet[MESSAGE_OFFSET:]); } function payload(bytes calldata _packet) internal pure returns (bytes calldata) { return bytes(_packet[GUID_OFFSET:]); } function payloadHash(bytes calldata _packet) internal pure returns (bytes32) { return keccak256(payload(_packet)); } }
// 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 // OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol) pragma solidity ^0.8.20; /** * @dev Standard ERC20 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens. */ interface IERC20Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC20InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC20InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers. * @param spender Address that may be allowed to operate on tokens without being their owner. * @param allowance Amount of tokens a `spender` is allowed to operate with. * @param needed Minimum amount required to perform a transfer. */ error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC20InvalidApprover(address approver); /** * @dev Indicates a failure with the `spender` to be approved. Used in approvals. * @param spender Address that may be allowed to operate on tokens without being their owner. */ error ERC20InvalidSpender(address spender); } /** * @dev Standard ERC721 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens. */ interface IERC721Errors { /** * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20. * Used in balance queries. * @param owner Address of the current owner of a token. */ error ERC721InvalidOwner(address owner); /** * @dev Indicates a `tokenId` whose `owner` is the zero address. * @param tokenId Identifier number of a token. */ error ERC721NonexistentToken(uint256 tokenId); /** * @dev Indicates an error related to the ownership over a particular token. Used in transfers. * @param sender Address whose tokens are being transferred. * @param tokenId Identifier number of a token. * @param owner Address of the current owner of a token. */ error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC721InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC721InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param tokenId Identifier number of a token. */ error ERC721InsufficientApproval(address operator, uint256 tokenId); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC721InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC721InvalidOperator(address operator); } /** * @dev Standard ERC1155 Errors * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens. */ interface IERC1155Errors { /** * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. * @param balance Current balance for the interacting account. * @param needed Minimum amount required to perform a transfer. * @param tokenId Identifier number of a token. */ error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId); /** * @dev Indicates a failure with the token `sender`. Used in transfers. * @param sender Address whose tokens are being transferred. */ error ERC1155InvalidSender(address sender); /** * @dev Indicates a failure with the token `receiver`. Used in transfers. * @param receiver Address to which tokens are being transferred. */ error ERC1155InvalidReceiver(address receiver); /** * @dev Indicates a failure with the `operator`’s approval. Used in transfers. * @param operator Address that may be allowed to operate on tokens without being their owner. * @param owner Address of the current owner of a token. */ error ERC1155MissingApprovalForAll(address operator, address owner); /** * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals. * @param approver Address initiating an approval operation. */ error ERC1155InvalidApprover(address approver); /** * @dev Indicates a failure with the `operator` to be approved. Used in approvals. * @param operator Address that may be allowed to operate on tokens without being their owner. */ error ERC1155InvalidOperator(address operator); /** * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation. * Used in batch transfers. * @param idsLength Length of the array of token identifiers * @param valuesLength Length of the array of token amounts */ error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "./IERC20.sol"; import {IERC20Metadata} from "./extensions/IERC20Metadata.sol"; import {Context} from "../../utils/Context.sol"; import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * * TIP: For a detailed writeup see our guide * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * The default value of {decimals} is 18. To change this, you should override * this function so it returns a different value. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. */ abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors { mapping(address account => uint256) private _balances; mapping(address account => mapping(address spender => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the default value returned by this function, unless * it's overridden. * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `value`. */ function transfer(address to, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _transfer(owner, to, value); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 value) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, value); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `value`. * - the caller must have allowance for ``from``'s tokens of at least * `value`. */ function transferFrom(address from, address to, uint256 value) public virtual returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, value); _transfer(from, to, value); return true; } /** * @dev Moves a `value` amount of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _transfer(address from, address to, uint256 value) internal { if (from == address(0)) { revert ERC20InvalidSender(address(0)); } if (to == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(from, to, value); } /** * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from` * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding * this function. * * Emits a {Transfer} event. */ function _update(address from, address to, uint256 value) internal virtual { if (from == address(0)) { // Overflow check required: The rest of the code assumes that totalSupply never overflows _totalSupply += value; } else { uint256 fromBalance = _balances[from]; if (fromBalance < value) { revert ERC20InsufficientBalance(from, fromBalance, value); } unchecked { // Overflow not possible: value <= fromBalance <= totalSupply. _balances[from] = fromBalance - value; } } if (to == address(0)) { unchecked { // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply. _totalSupply -= value; } } else { unchecked { // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256. _balances[to] += value; } } emit Transfer(from, to, value); } /** * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0). * Relies on the `_update` mechanism * * Emits a {Transfer} event with `from` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead. */ function _mint(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidReceiver(address(0)); } _update(address(0), account, value); } /** * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply. * Relies on the `_update` mechanism. * * Emits a {Transfer} event with `to` set to the zero address. * * NOTE: This function is not virtual, {_update} should be overridden instead */ function _burn(address account, uint256 value) internal { if (account == address(0)) { revert ERC20InvalidSender(address(0)); } _update(account, address(0), value); } /** * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. * * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument. */ function _approve(address owner, address spender, uint256 value) internal { _approve(owner, spender, value, true); } /** * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event. * * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any * `Approval` event during `transferFrom` operations. * * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to * true using the following override: * ``` * function _approve(address owner, address spender, uint256 value, bool) internal virtual override { * super._approve(owner, spender, value, true); * } * ``` * * Requirements are the same as {_approve}. */ function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual { if (owner == address(0)) { revert ERC20InvalidApprover(address(0)); } if (spender == address(0)) { revert ERC20InvalidSpender(address(0)); } _allowances[owner][spender] = value; if (emitEvent) { emit Approval(owner, spender, value); } } /** * @dev Updates `owner` s allowance for `spender` based on spent `value`. * * Does not update the allowance value in case of infinite allowance. * Revert if not enough allowance is available. * * Does not emit an {Approval} event. */ function _spendAllowance(address owner, address spender, uint256 value) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { if (currentAllowance < value) { revert ERC20InsufficientAllowance(spender, currentAllowance, value); } unchecked { _approve(owner, spender, currentAllowance - value, false); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. * * ==== Security Considerations * * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be * considered as an intention to spend the allowance in any specific way. The second is that because permits have * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be * generally recommended is: * * ```solidity * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public { * try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {} * doThing(..., value); * } * * function doThing(..., uint256 value) public { * token.safeTransferFrom(msg.sender, address(this), value); * ... * } * ``` * * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also * {SafeERC20-safeTransferFrom}). * * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so * contracts should have entry points that don't rely on permit. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. * * CAUTION: See Security Considerations above. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.20; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the value of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the value of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves a `value` amount of tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 value) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets a `value` amount of tokens as the allowance of `spender` over the * caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 value) external returns (bool); /** * @dev Moves a `value` amount of tokens from `from` to `to` using the * allowance mechanism. `value` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 value) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.20; import {IERC20} from "../IERC20.sol"; import {IERC20Permit} from "../extensions/IERC20Permit.sol"; import {Address} from "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev An operation with an ERC20 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 Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data); if (returndata.length != 0 && !abi.decode(returndata, (bool))) { 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 silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol) pragma solidity ^0.8.20; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev The ETH balance of the account is not enough to perform the operation. */ error AddressInsufficientBalance(address account); /** * @dev There's no code at `target` (it is not a contract). */ error AddressEmptyCode(address target); /** * @dev A call to an address target failed. The target may have reverted. */ error FailedInnerCall(); /** * @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 AddressInsufficientBalance(address(this)); } (bool success, ) = recipient.call{value: amount}(""); if (!success) { revert FailedInnerCall(); } } /** * @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 * {FailedInnerCall} 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 AddressInsufficientBalance(address(this)); } (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 {FailedInnerCall}) 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 {FailedInnerCall} 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 {FailedInnerCall}. */ 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 FailedInnerCall(); } } }
// 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 ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * 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[EIP 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); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; contract ClaimableAdminStorage { /** * @notice Administrator for this contract */ address public admin; /** * @notice Pending administrator for this contract */ address public pendingAdmin; /*** Modifiers ***/ modifier onlyAdmin() { require(msg.sender == admin, "ONLY_ADMIN"); _; } /*** Constructor ***/ constructor() { // Set admin to caller admin = msg.sender; } } contract AcceptableImplementationClaimableAdminStorage is ClaimableAdminStorage { /** * @notice Active logic */ address public implementation; /** * @notice Pending logic */ address public pendingImplementation; } contract AcceptableRegistryImplementationClaimableAdminStorage is AcceptableImplementationClaimableAdminStorage { /** * @notice System Registry */ address public registry; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./AcceptableImplementationClaimableAdminStorage.sol"; /** * @title Claimable Admin */ contract ClaimableAdmin is ClaimableAdminStorage { /** * @notice Emitted when pendingAdmin is changed */ event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin); /** * @notice Emitted when pendingAdmin is accepted, which means admin is updated */ event NewAdmin(address oldAdmin, address newAdmin); /*** Admin Functions ***/ /** * @notice Begins transfer of admin rights. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @dev Admin function to begin change of admin. The newPendingAdmin must call `_acceptAdmin` to finalize the transfer. * @param newPendingAdmin New pending admin. */ function _setPendingAdmin(address newPendingAdmin) public { // Check caller = admin require(msg.sender == admin, "Not Admin"); // Save current value, if any, for inclusion in log address oldPendingAdmin = pendingAdmin; // Store pendingAdmin with value newPendingAdmin pendingAdmin = newPendingAdmin; // Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin) emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin); } /** * @notice Accepts transfer of admin rights. msg.sender must be pendingAdmin * @dev Admin function for pending admin to accept role and update admin */ function _acceptAdmin() public { // Check caller is pendingAdmin and pendingAdmin ≠ address(0) require( msg.sender == pendingAdmin && pendingAdmin != address(0), "Not the EXISTING pending admin" ); // Save current values for inclusion in log address oldAdmin = admin; address oldPendingAdmin = pendingAdmin; // Store admin with value pendingAdmin admin = pendingAdmin; // Clear the pending value pendingAdmin = address(0); emit NewAdmin(oldAdmin, admin); emit NewPendingAdmin(oldPendingAdmin, pendingAdmin); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IContractRegistryBase { function isImplementationValidForProxy( bytes32 proxyNameHash, address _implementation ) external view returns (bool); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; /** * @title EIP712Utils * @notice Utility functions for EIP-712 logic. * @dev Based on https://github.com/ethereum/EIPs/blob/master/assets/eip-712/Example.sol */ contract EIP712Utils { struct EIP712Domain { string name; string version; uint256 chainId; address verifyingContract; } bytes32 public constant EIP712DOMAIN_TYPEHASH = keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ); function hashDomain( EIP712Domain memory eip712Domain ) internal pure returns (bytes32) { return keccak256( abi.encode( EIP712DOMAIN_TYPEHASH, keccak256(bytes(eip712Domain.name)), keccak256(bytes(eip712Domain.version)), eip712Domain.chainId, eip712Domain.verifyingContract ) ); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./EIP712Utils.sol"; /** * @title MultiChainEIP712Base * @notice Base contract for EIP712 signature verification using multiple chain ids */ contract MultiChainEIP712Base is EIP712Utils { // ***** Events ***** event DomainSeparatorForChainStored( uint256 indexed chainId, bytes32 domainSeparator ); // ***** Storage ***** string public CONTRACT_DOMAIN_NAME; string public CONTRACT_DOMAIN_VERSION; // asset => domain separator for intents mapping(uint256 => bytes32) public domainSeparatorForChain; // ***** Constructor ***** constructor( string memory _contractDomainName, string memory _contractDomainVersion ) { CONTRACT_DOMAIN_NAME = _contractDomainName; CONTRACT_DOMAIN_VERSION = _contractDomainVersion; } // ***** Domain Generation ***** function generateAndStoreDomainSeparatorIfMissingInternal( uint256 chainId ) internal returns (bytes32) { bytes32 storedDomainSeparator = domainSeparatorForChain[chainId]; if (storedDomainSeparator == bytes32(0)) { bytes32 domainSeparator = hashDomain( EIP712Domain({ name: CONTRACT_DOMAIN_NAME, version: CONTRACT_DOMAIN_VERSION, chainId: chainId, verifyingContract: address(this) }) ); domainSeparatorForChain[chainId] = domainSeparator; emit DomainSeparatorForChainStored(chainId, domainSeparator); return domainSeparator; } else { return storedDomainSeparator; } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import {ChipEnumsV1} from "../interfaces/ChipEnumsV1.sol"; import "../interfaces/IRegistryV1.sol"; /** * @title BaseChip * @notice Base for Chip contracts to inherit from, handles the auto approval mechanism. */ contract BaseChip is ChipEnumsV1 { // ***** Events ***** event AutoApprovedSpenderSet( string indexed role, address indexed oldSpender, address indexed newSpender ); // ***** Immutable Storage ***** IRegistryV1 public immutable registry; ChipMode public immutable chipMode; // ***** Storage ***** // address => is auto approved mapping(address => bool) public autoApproved; // role hash => role address mapping(bytes32 => address) public autoApprovedSpendersByRoles; // ***** Views ***** function getAutoApprovedSpenderAddressByRole( string calldata role ) public view returns (address) { bytes32 roleHash = keccak256(abi.encodePacked(role)); return autoApprovedSpendersByRoles[roleHash]; } // ***** Constructor ***** constructor(IRegistryV1 _registry, ChipMode _chipMode) { require(address(_registry) != address(0), "!_registry"); registry = _registry; chipMode = _chipMode; } // ***** Admin Functions ***** function setAutoApprovedSpenderForRoleInternal( string calldata role, address spender ) internal { require( spender == address(0) || registry.getValidSpenderTargetForChipByRole(address(this), role) == spender, "NOT_REGISTRY_APPROVED" ); address oldSpender = getAutoApprovedSpenderAddressByRole(role); autoApproved[oldSpender] = false; autoApproved[spender] = true; bytes32 roleHash = keccak256(abi.encodePacked(role)); autoApprovedSpendersByRoles[roleHash] = spender; emit AutoApprovedSpenderSet(role, oldSpender, spender); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFT.sol"; import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; import "../../interfaces/IRegistryV1.sol"; import "../../interfaces/ILzCreditControllerV1.sol"; import "../../interfaces/ILzDebitControllerV1.sol"; import "../BaseChip.sol"; /** * @title OFTChip * @notice The OFTChip is a remote chip that extends the LayerZero OFT token. */ contract OFTChip is OFT, BaseChip { // ***** Events ***** event IsSendPausedSet(bool isPaused); event CreditControllerSet( address indexed previousController, address indexed newController ); event DebitControllerSet( address indexed previousController, address indexed newController ); event TokensSwept( address indexed token, address indexed receiver, uint256 amount ); // ***** Storage ***** bool public isSendPaused; ILzCreditControllerV1 public creditController; ILzDebitControllerV1 public debitController; // ***** Constructor ***** constructor( IRegistryV1 _registry, string memory _name, string memory _symbol, address _lzEndpoint, address _delegate, address _initialOwner ) OFT(_name, _symbol, _lzEndpoint, _delegate) BaseChip(_registry, ChipMode.REMOTE) Ownable(_initialOwner) { require(address(_lzEndpoint) != address(0), "!_lzEndpoint"); } // ***** Admin Functions ***** /** * @notice Set the auto approved spender for a role * @param role The role to set the spender for * @param spender The spender to set */ function setAutoApprovedSpenderForRole( string calldata role, address spender ) external onlyOwner { setAutoApprovedSpenderForRoleInternal(role, spender); } /** * @notice Set the send pause state * @param _isPaused The new send pause state */ function setIsSendPaused(bool _isPaused) external onlyOwner { bool currentState = isSendPaused; require(_isPaused != currentState, "ALREADY_SET"); isSendPaused = _isPaused; emit IsSendPausedSet(_isPaused); } /** * @notice Set the credit controller * @param _creditController The new credit controller */ function setCreditController( ILzCreditControllerV1 _creditController ) external onlyOwner { // Sanity require( address(_creditController) == address(0) || _creditController.isCreditController(), "NOT_CREDIT_CONTROLLER" ); address previousController = address(creditController); require(previousController != address(_creditController), "ALREADY_SET"); creditController = _creditController; emit CreditControllerSet(previousController, address(_creditController)); } /** * @notice Set the debit controller * @param _debitController The new debit controller */ function setDebitController( ILzDebitControllerV1 _debitController ) external onlyOwner { // Sanity require( address(_debitController) == address(0) || _debitController.isDebitController(), "NOT_DEBIT_CONTROLLER" ); address previousController = address(debitController); require(previousController != address(_debitController), "ALREADY_SET"); debitController = _debitController; emit DebitControllerSet(previousController, address(_debitController)); } /** * @notice Sweep any non-underlying tokens from the contract * @dev Owner can sweep any tokens other than the underlying token * @param _token The token to sweep * @param _amount The amount to sweep */ function sweepTokens(ERC20 _token, uint256 _amount) external onlyOwner { require(address(_token) != address(this), "CANNOT_SWEEP_SELF"); _token.transfer(owner(), _amount); emit TokensSwept(address(_token), owner(), _amount); } // ***** Lz Functions ***** /** * @dev Credits tokens to the specified address. * @param _to The address to credit the tokens to. * @param _amountLD The amount of tokens to credit in local decimals. * @dev _srcEid The source chain ID. * @return amountReceivedLD The amount of tokens ACTUALLY received in local decimals. */ function _credit( address _to, uint256 _amountLD, uint32 _srcEid ) internal virtual override returns (uint256 amountReceivedLD) { ILzCreditControllerV1 creditController_ = creditController; if (address(creditController_) != address(0)) { try creditController_.informLzCreditRequest(_to, _amountLD, _srcEid) {} catch {} } return super._credit(_to, _amountLD, _srcEid); } /** * @dev Burns tokens from the sender's specified balance. * @param _from The address to debit the tokens from. * @param _amountLD The amount of tokens to send in local decimals. * @param _minAmountLD The minimum amount to send in local decimals. * @param _dstEid The destination chain ID. * @return amountSentLD The amount sent in local decimals. * @return amountReceivedLD The amount received in local decimals on the remote. */ function _debit( address _from, uint256 _amountLD, uint256 _minAmountLD, uint32 _dstEid ) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) { require(!isSendPaused, "SEND_PAUSED"); ILzDebitControllerV1 debitController_ = debitController; if (address(debitController_) != address(0)) { require( debitController_.informLzDebitRequestWithSource( _from, _amountLD, _minAmountLD, _dstEid ), "DEBIT_NOT_APPROVED" ); } return super._debit(_from, _amountLD, _minAmountLD, _dstEid); } // ***** ERC20 internal override Functions ***** /** * @notice Uses the base ERC20 logic unless 'spender' is marked as 'autoApproved' */ function allowance( address owner, address spender ) public view virtual override returns (uint256) { if (autoApproved[spender]) { return type(uint).max; } else { return ERC20.allowance(owner, spender); } } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../../AdministrationContracts/ClaimableAdmin.sol"; import "../../CryptographyContracts/MultiChainEIP712Base.sol"; import {IntentsPermissions, PermissionsType} from "../../Peripheral/Chips/IntentsPermissions.sol"; import {OFTChip} from "../Chips/OFTChip/OFTChip.sol"; /** * @title MultiSourceChainIntentsVerifierBase * @dev Base contract for verifying intents that can be signed with different 'chainId' values. */ contract MultiSourceChainIntentsVerifierBase is ClaimableAdmin, MultiChainEIP712Base { // ***** Storage ***** string public constant DYN_ROLE_INTENTS_PERMISSIONS_PREFIX = "INTENTS_PERMISSIONS_"; // OFTChip => open flag to check for intents permissions mapping(OFTChip => string) public intentsPermissions; // ***** Events ***** event SourceChainIdForAssetStored( address indexed asset, uint256 indexed chainId ); // asset => source chain ID mapping(address => uint256) public sourceChainIdForAsset; constructor( string memory _contractDomainName, string memory _contractDomainVersion ) MultiChainEIP712Base(_contractDomainName, _contractDomainVersion) {} // ***** Views ***** /** * @notice Returns the domain separator for the given asset. * @param asset The asset for which to return the domain separator. * @return The domain separator for the given asset. */ function domainSeparatorForAsset( address asset ) public view returns (bytes32) { return domainSeparatorForChain[sourceChainIdForAsset[asset]]; } // ***** Admin Functions ***** /** * @notice Stores the source chain ID for the given asset. * @param asset The asset for which to store the source chain ID. * @param chainId The source chain ID to store. */ function storeSourceChainForAsset( address asset, uint256 chainId ) external virtual onlyAdmin { storeSourceChainForAssetInternal(asset, chainId); } /** * @notice Opens/Closes the intents permissions check for the chip. * @param oftChip The chip for the intents permissions check. * @param dynAddressSuffix is a suffix for dynamicly set address in the Registry */ function setIntentsPermissions( OFTChip oftChip, string calldata dynAddressSuffix ) external onlyAdmin { intentsPermissions[oftChip] = dynAddressSuffix; } // ***** Internals ***** /** * @notice Stores the source chain ID for the given asset. * @dev chain Ids for assets cannot be changed. * @param asset The asset for which to store the source chain ID. * @param chainId The source chain ID to store. */ function storeSourceChainForAssetInternal( address asset, uint256 chainId ) internal { // Can only configure once require( sourceChainIdForAsset[asset] == 0, "CHAIN_ID_FOR_ASSET_ALREADY_CONFIGURED" ); // Cannot set to zero require(chainId != 0, "CHAIN_ID_ZERO"); // Ensure domain separator is configured for this chain generateAndStoreDomainSeparatorIfMissingInternal(chainId); // Store mapping sourceChainIdForAsset[asset] = chainId; // event emit SourceChainIdForAssetStored(asset, chainId); } /** * @notice Returns the domain separator for the given asset. * @dev Allows inheriting contracts to get the relevant domain separator for intents verifications. * @param _asset The asset for which to return the domain separator. * @return The domain separator for the given asset. */ function getDomainSeparatorForAssetInternal( address _asset ) internal view returns (bytes32) { (bytes32 domainSeparator, ) = getDomainSeparatorAndChainForAssetInternal( _asset ); return domainSeparator; } /** * @notice Returns the domain separator and chain ID for the given asset. * @dev Allows inheriting contracts to get the relevant domain separator and chain ID for intents verifications. * @param _asset The asset for which to return the domain separator and chain ID. * @return The domain separator and chain ID for the given asset. */ function getDomainSeparatorAndChainForAssetInternal( address _asset ) internal view returns (bytes32, uint256) { uint256 chainId = sourceChainIdForAsset[_asset]; require(chainId != 0, "NO_CHAIN_ID_FOR_ASSET"); bytes32 domainSeparator = domainSeparatorForChain[chainId]; require(domainSeparator != bytes32(0), "NO_DOMAIN_SEPARATOR_FOR_CHAIN"); return (domainSeparator, chainId); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; /** * @title AccountAndActionSerialNonceBase * @notice Base contract for managing serial nonces for actions per account */ contract AccountAndActionSerialNonceBase { // ***** Storage ***** // account => action type => nonce mapping(address => mapping(uint8 => uint256)) public nonceMap; // ***** Views ***** /** * @notice Get the next valid nonce for an account and action type. * @param account The account to get the nonce for. * @param actionType The action type to get the nonce for. * @return The next valid nonce. */ function getNextValidNonceFor( address account, uint8 actionType ) external view returns (uint256) { return nonceMap[account][actionType]; } // ***** Internal ***** /** * @notice Validate a nonce for an account and action type, and increase the stored counter by 1. * @param account The account to validate the nonce for. * @param actionType The action type to validate the nonce for. * @param nonce The nonce to validate. */ function validateNonceForActionAndIncrease( address account, uint8 actionType, uint256 nonce ) internal { uint256 currentNonceMapValue = nonceMap[account][actionType]; require(nonce == currentNonceMapValue, "INCORRECT_NONCE"); nonceMap[account][actionType] = currentNonceMapValue + 1; } }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; contract ChipEnumsV1 { enum ChipMode { NONE, LOCAL, REMOTE, HYBRID } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IFundingRateModel { // return value is the "funding paid by heavier side" in PRECISION per OI (heavier side) per second // e.g : (0.01 * PRECISION) = Paying (heavier) side (as a whole) pays 1% of funding per second for each OI unit function getFundingRate( uint256 pairId, uint256 openInterestLong, uint256 openInterestShort, uint256 pairMaxOpenInterest ) external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IGlobalLock { function lock() external; function freeLock() external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface IInterestRateModel { // Returns asset/second of interest per borrowed unit // e.g : (0.01 * PRECISION) = 1% of interest per second function getBorrowRate(uint256 utilization) external view returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./LexErrors.sol"; import "./LexPoolAdminEnums.sol"; import "./IPoolAccountantV1.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface LexPoolStructs { struct PendingDeposit { uint256 amount; uint256 minAmountOut; } struct PendingRedeem { uint256 amount; uint256 minAmountOut; uint256 maxAmountOut; } } interface LexPoolEvents is LexPoolAdminEnums { event NewEpoch( uint256 epochId, int256 reportedUnrealizedPricePnL, uint256 exchangeRate, uint256 virtualUnderlyingBalance, uint256 totalSupply ); event AddressUpdated(LexPoolAddressesEnum indexed enumCode, address a); event NumberUpdated(LexPoolNumbersEnum indexed enumCode, uint value); event DepositRequest( address indexed user, uint256 amount, uint256 minAmountOut, uint256 processingEpoch ); event RedeemRequest( address indexed user, uint256 amount, uint256 minAmountOut, uint256 processingEpoch ); event ProcessedDeposit( address indexed user, bool deposited, uint256 depositedAmount ); event ProcessedRedeem( address indexed user, bool redeemed, uint256 withdrawnAmount // Underlying amount ); event CanceledDeposit( address indexed user, uint256 epoch, uint256 cancelledAmount ); event CanceledRedeem( address indexed user, uint256 epoch, uint256 cancelledAmount ); event ImmediateDepositAllowedToggled(bool indexed value); event ImmediateDeposit( address indexed depositor, uint256 depositAmount, uint256 mintAmount ); event ReservesWithdrawn( address _to, uint256 interestShare, uint256 totalFundingShare ); } interface ILexPoolFunctionality is IERC20, LexPoolStructs, LexPoolEvents, LexErrors { function setPoolAccountant( IPoolAccountantFunctionality _poolAccountant ) external; function setPnlRole(address pnl) external; function setMaxExtraWithdrawalAmountF(uint256 maxExtra) external; function setEpochsDelayDeposit(uint256 delay) external; function setEpochsDelayRedeem(uint256 delay) external; function setEpochDuration(uint256 duration) external; function setMinDepositAmount(uint256 amount) external; function toggleImmediateDepositAllowed() external; function reduceReserves( address _to ) external returns (uint256 interestShare, uint256 totalFundingShare); function requestDeposit( uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external; function requestDepositViaIntent( address user, uint256 amount, uint256 minAmountOut, bytes32 domain, bytes32 referralCode ) external; function requestRedeem(uint256 amount, uint256 minAmountOut) external; function requestRedeemViaIntent( address user, uint256 amount, uint256 minAmountOut ) external; function processDeposit( address[] memory users ) external returns ( uint256 amountDeposited, uint256 amountCancelled, uint256 counterDeposited, uint256 counterCancelled ); function cancelDeposits( address[] memory users, uint256[] memory epochs ) external; function processRedeems( address[] memory users ) external returns ( uint256 amountRedeemed, uint256 amountCancelled, uint256 counterDeposited, uint256 counterCancelled ); function cancelRedeems( address[] memory users, uint256[] memory epochs ) external; function nextEpoch( int256 totalUnrealizedPricePnL ) external returns (uint256 newExchangeRate); function currentVirtualUtilization() external view returns (uint256); function currentVirtualUtilization( uint256 totalBorrows, uint256 totalReserves, int256 unrealizedFunding ) external view returns (uint256); function virtualBalanceForUtilization() external view returns (uint256); function virtualBalanceForUtilization( uint256 extraAmount, int256 unrealizedFunding ) external view returns (uint256); function underlyingBalanceForExchangeRate() external view returns (uint256); function sendAssetToTrader(address to, uint256 amount) external; function isUtilizationForLPsValid() external view returns (bool); } interface ILexPoolV1 is ILexPoolFunctionality { function name() external view returns (string memory); function symbol() external view returns (string memory); function SELF_UNIT_SCALE() external view returns (uint); function underlyingDecimals() external view returns (uint256); function poolAccountant() external view returns (address); function underlying() external view returns (IERC20); function tradingFloor() external view returns (address); function currentEpoch() external view returns (uint256); function currentExchangeRate() external view returns (uint256); function nextEpochStartMin() external view returns (uint256); function epochDuration() external view returns (uint256); function minDepositAmount() external view returns (uint256); function epochsDelayDeposit() external view returns (uint256); function epochsDelayRedeem() external view returns (uint256); function immediateDepositAllowed() external view returns (bool); function pendingDeposits( uint epoch, address account ) external view returns (PendingDeposit memory); function pendingRedeems( uint epoch, address account ) external view returns (PendingRedeem memory); function pendingDepositAmount() external view returns (uint256); function pendingWithdrawalAmount() external view returns (uint256); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; interface ILzCreditControllerV1 { function isCreditController() external view returns (bool); function informLzCreditRequest( address _to, uint256 _amountToCreditLD, uint32 /*_srcEid*/ ) external returns (bool isPermitted); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; interface ILzDebitControllerV1 { function isDebitController() external view returns (bool); function informLzDebitRequest( uint256 _amountToSendLD, // amount to send in local decimals() uint256 _minAmountToCreditLD, // minimum ammount to credit on the destination uint32 _dstEid // destination endpoint id ) external returns (bool isPermitted); function informLzDebitRequestWithSource( address _debitFrom, // address to debit from uint256 _amountToSendLD, // amount to send in local decimals() uint256 _minAmountToCreditLD, // minimum ammount to credit on the destination uint32 _dstEid // destination endpoint id ) external returns (bool isPermitted); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./LexErrors.sol"; import "./ILexPoolV1.sol"; import "./IInterestRateModel.sol"; import "./IFundingRateModel.sol"; import "./TradingEnumsV1.sol"; interface PoolAccountantStructs { // @note To be used for passing information in function calls struct PositionRegistrationParams { uint256 collateral; uint32 leverage; bool long; uint64 openPrice; uint64 tp; } struct PairFunding { // Slot 0 int256 accPerOiLong; // 32 bytes -- Underlying Decimals // Slot 1 int256 accPerOiShort; // 32 bytes -- Underlying Decimals // Slot 2 uint256 lastUpdateTimestamp; // 32 bytes } struct TradeInitialAccFees { // Slot 0 uint256 borrowIndex; // 32 bytes // Slot 1 int256 funding; // 32 bytes -- underlying units -- Underlying Decimals } struct PairOpenInterest { // Slot 0 uint256 long; // 32 bytes -- underlying units -- Dynamic open interest for long positions // Slot 1 uint256 short; // 32 bytes -- underlying units -- Dynamic open interest for short positions } // This struct is not kept in storage struct PairFromTo { string from; string to; } struct Pair { // Slot 0 uint16 id; // 02 bytes uint16 groupId; // 02 bytes uint16 feeId; // 02 bytes uint32 minLeverage; // 04 bytes uint32 maxLeverage; // 04 bytes uint32 maxBorrowF; // 04 bytes -- FRACTION_SCALE (5) // Slot 1 uint256 maxPositionSize; // 32 bytes -- underlying units // Slot 2 uint256 maxGain; // 32 bytes -- underlying units // Slot 3 uint256 maxOpenInterest; // 32 bytes -- Underlying units // Slot 4 uint256 maxSkew; // 32 bytes -- underlying units // Slot 5 uint256 minOpenFee; // 32 bytes -- underlying units. MAX_UINT means use the default group level value // Slot 6 uint256 minPerformanceFee; // 32 bytes -- underlying units } struct Group { // Slot 0 uint16 id; // 02 bytes uint32 minLeverage; // 04 bytes uint32 maxLeverage; // 04 bytes uint32 maxBorrowF; // 04 bytes -- FRACTION_SCALE (5) // Slot 1 uint256 maxPositionSize; // 32 bytes (Underlying units) // Slot 2 uint256 minOpenFee; // 32 bytes (Underlying uints). MAX_UINT means use the default global level value } struct Fee { // Slot 0 uint16 id; // 02 bytes uint32 openFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of leveraged pos) uint32 closeFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of leveraged pos) uint32 performanceFeeF; // 04 bytes -- FRACTION_SCALE (5) (Fraction of performance) } } interface PoolAccountantEvents is PoolAccountantStructs { event PairAdded( uint256 indexed id, string indexed from, string indexed to, Pair pair ); event PairUpdated(uint256 indexed id, Pair pair); event GroupAdded(uint256 indexed id, string indexed groupName, Group group); event GroupUpdated(uint256 indexed id, Group group); event FeeAdded(uint256 indexed id, string indexed name, Fee fee); event FeeUpdated(uint256 indexed id, Fee fee); event TradeInitialAccFeesStored( bytes32 indexed positionId, uint256 borrowIndex, // uint256 rollover, int256 funding ); event AccrueFunding( uint256 indexed pairId, int256 valueLong, int256 valueShort ); event ProtocolFundingShareAccrued( uint16 indexed pairId, uint256 protocolFundingShare ); // event AccRolloverFeesStored(uint256 pairIndex, uint256 value); event FeesCharged( bytes32 indexed positionId, address indexed trader, uint16 indexed pairId, PositionRegistrationParams positionRegistrationParams, // bool long, // uint256 collateral, // Underlying Decimals // uint256 leverage, int256 profitPrecision, // PRECISION uint256 interest, int256 funding, // Underlying Decimals uint256 closingFee, uint256 tradeValue ); event PerformanceFeeCharging( bytes32 indexed positionId, uint256 performanceFee ); event MaxOpenInterestUpdated(uint256 pairIndex, uint256 maxOpenInterest); event AccrueInterest( uint256 cash, uint256 totalInterestNew, uint256 borrowIndexNew, uint256 interestShareNew ); event Borrow( uint256 indexed pairId, uint256 borrowAmount, uint256 newTotalBorrows ); event Repay( uint256 indexed pairId, uint256 repayAmount, uint256 newTotalBorrows ); } interface IPoolAccountantFunctionality is PoolAccountantStructs, PoolAccountantEvents, LexErrors, TradingEnumsV1 { function setTradeIncentivizer(address _tradeIncentivizer) external; function setMaxGainF(uint256 _maxGainF) external; function setFrm(IFundingRateModel _frm) external; function setMinOpenFee(uint256 min) external; function setLexPartF(uint256 partF) external; function setFundingRateMax(uint256 maxValue) external; function setLiquidationThresholdF(uint256 threshold) external; function setLiquidationFeeF(uint256 fee) external; function setIrm(IInterestRateModel _irm) external; function setIrmHard(IInterestRateModel _irm) external; function setInterestShareFactor(uint256 factor) external; function setFundingShareFactor(uint256 factor) external; function setBorrowRateMax(uint256 rate) external; function setMaxTotalBorrows(uint256 maxBorrows) external; function setMaxVirtualUtilization(uint256 _maxVirtualUtilization) external; function resetTradersPairGains(uint256 pairId) external; function addGroup(Group calldata _group) external; function updateGroup(Group calldata _group) external; function addFee(Fee calldata _fee) external; function updateFee(Fee calldata _fee) external; function addPair(Pair calldata _pair) external; function addPairs(Pair[] calldata _pairs) external; function updatePair(Pair calldata _pair) external; function readAndZeroReserves() external returns (uint256 accumulatedInterestShare, uint256 accFundingShare); function registerOpenTrade( bytes32 positionId, address trader, uint16 pairId, uint256 collateral, uint32 leverage, bool long, uint256 tp, uint256 openPrice ) external returns (uint256 fee, uint256 lexPartFee); function registerCloseTrade( bytes32 positionId, address trader, uint16 pairId, PositionRegistrationParams calldata positionRegistrationParams, uint256 closePrice, PositionCloseType positionCloseType ) external returns ( uint256 closingFee, uint256 tradeValue, int256 profitPrecision, uint finalClosePrice ); function registerUpdateTp( bytes32 positionId, address trader, uint16 pairId, uint256 collateral, uint32 leverage, bool long, uint256 openPrice, uint256 oldTriggerPrice, uint256 triggerPrice ) external; // function registerUpdateSl( // address trader, // uint256 pairIndex, // uint256 index, // uint256 collateral, // uint256 leverage, // bool long, // uint256 openPrice, // uint256 triggerPrice // ) external returns (uint256 fee); function accrueInterest() external returns ( uint256 totalInterestNew, uint256 interestShareNew, uint256 borrowIndexNew ); // Limited only for the LexPool function accrueInterest( uint256 availableCash ) external returns ( uint256 totalInterestNew, uint256 interestShareNew, uint256 borrowIndexNew ); function getTradeClosingValues( bytes32 positionId, uint16 pairId, PositionRegistrationParams calldata positionRegistrationParams, uint256 closePrice, bool isLiquidation ) external returns ( uint256 tradeValue, // Underlying Decimals uint256 safeClosingFee, int256 profitPrecision, uint256 interest, int256 funding ); function getTradeLiquidationPrice( bytes32 positionId, uint16 pairId, uint256 openPrice, // PRICE_SCALE (8) uint256 tp, bool long, uint256 collateral, // Underlying Decimals uint32 leverage ) external returns ( uint256 // PRICE_SCALE (8) ); function calcTradeDynamicFees( bytes32 positionId, uint16 pairId, bool long, uint256 collateral, uint32 leverage, uint256 openPrice, uint256 tp ) external returns (uint256 interest, int256 funding); function unrealizedFunding() external view returns (int256); function totalBorrows() external view returns (uint256); function interestShare() external view returns (uint256); function fundingShare() external view returns (uint256); function totalReservesView() external view returns (uint256); function borrowsAndInterestShare() external view returns (uint256 totalBorrows, uint256 totalInterestShare); function pairTotalOpenInterest( uint256 pairIndex ) external view returns (int256); function pricePnL( uint256 pairId, uint256 price ) external view returns (int256); function getAllSupportedPairIds() external view returns (uint16[] memory); function getAllSupportedGroupsIds() external view returns (uint16[] memory); function getAllSupportedFeeIds() external view returns (uint16[] memory); } interface IPoolAccountantV1 is IPoolAccountantFunctionality { function totalBorrows() external view returns (uint256); function maxTotalBorrows() external view returns (uint256); function pairBorrows(uint256 pairId) external view returns (uint256); function groupBorrows(uint256 groupId) external view returns (uint256); function pairMaxBorrow(uint16 pairId) external view returns (uint256); function groupMaxBorrow(uint16 groupId) external view returns (uint256); function lexPool() external view returns (ILexPoolV1); function maxGainF() external view returns (uint256); function interestShareFactor() external view returns (uint256); function fundingShareFactor() external view returns (uint256); function frm() external view returns (IFundingRateModel); function irm() external view returns (IInterestRateModel); function pairs(uint16 pairId) external view returns (Pair memory); function groups(uint16 groupId) external view returns (Group memory); function fees(uint16 feeId) external view returns (Fee memory); function openInterestInPair( uint pairId ) external view returns (PairOpenInterest memory); function minOpenFee() external view returns (uint256); function liquidationThresholdF() external view returns (uint256); function liquidationFeeF() external view returns (uint256); function lexPartF() external view returns (uint256); function tradersPairGains(uint256 pairId) external view returns (int256); function calcBorrowAmount( uint256 collateral, uint256 leverage, bool long, uint256 openPrice, uint256 tp ) external pure returns (uint256); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "../../AdministrationContracts/IContractRegistryBase.sol"; import "./IGlobalLock.sol"; interface IRegistryV1Functionality is IContractRegistryBase, IGlobalLock { // **** Locking mechanism **** function isTradersPortalAndLocker( address _address ) external view returns (bool); function isTriggersAndLocker(address _address) external view returns (bool); function isTradersPortalOrTriggersAndLocker( address _address ) external view returns (bool); } interface IRegistryV1 is IRegistryV1Functionality { // **** Public Storage params **** function feesManagers(address asset) external view returns (address); function orderBook() external view returns (address); function tradersPortal() external view returns (address); function triggers() external view returns (address); function tradeIntentsVerifier() external view returns (address); function liquidityIntentsVerifier() external view returns (address); function chipsIntentsVerifier() external view returns (address); function lexProxiesFactory() external view returns (address); function chipsFactory() external view returns (address); /** * @return An array of all supported trading floors */ function getAllSupportedTradingFloors() external view returns (address[] memory); /** * @return An array of all supported settlement assets */ function getSettlementAssetsForTradingFloor( address _tradingFloor ) external view returns (address[] memory); /** * @return The spender role address that is set for this chip */ function getValidSpenderTargetForChipByRole( address chip, string calldata role ) external view returns (address); /** * @return the address of the valid 'burnHandler' for the chip */ function validBurnHandlerForChip( address chip ) external view returns (address); /** * @return The address matching for the given role */ function getDynamicRoleAddress( string calldata _role ) external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface LexErrors { enum CapType { NONE, // 0 MIN_OPEN_FEE, // 1 MAX_POS_SIZE_PAIR, // 2 MAX_POS_SIZE_GROUP, // 3 MAX_LEVERAGE, // 4 MIN_LEVERAGE, // 5 MAX_VIRTUAL_UTILIZATION, // 6 MAX_OPEN_INTEREST, // 7 MAX_ABS_SKEW, // 8 MAX_BORROW_PAIR, // 9 MAX_BORROW_GROUP, // 10 MIN_DEPOSIT_AMOUNT, // 11 MAX_ACCUMULATED_GAINS, // 12 BORROW_RATE_MAX, // 13 FUNDING_RATE_MAX, // 14 MAX_POTENTIAL_GAIN, // 15 MAX_TOTAL_BORROW, // 16 MIN_PERFORMANCE_FEE // 17 //... } error CapError(CapType, uint256 value); }
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.24; interface LexPoolAdminEnums { enum LexPoolAddressesEnum { none, poolAccountant, pnlRole } enum LexPoolNumbersEnum { none, maxExtraWithdrawalAmountF, epochsDelayDeposit, epochsDelayRedeem, epochDuration, minDepositAmount } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; interface TradingEnumsV1 { enum PositionPhase { NONE, OPEN_MARKET, OPEN_LIMIT, OPENED, CLOSE_MARKET, CLOSED } enum OpenOrderType { NONE, MARKET, LIMIT } enum CloseOrderType { NONE, MARKET } enum FeeType { NONE, OPEN_FEE, CLOSE_FEE, TRIGGER_FEE } enum LimitTrigger { NONE, TP, SL, LIQ } enum PositionField { NONE, TP, SL } enum PositionCloseType { NONE, TP, SL, LIQ, MARKET } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import {IOAppComposer} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppComposer.sol"; import {OFTComposeMsgCodec} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/libs/OFTComposeMsgCodec.sol"; import "../../AdministrationContracts/ClaimableAdmin.sol"; import "../../Lynx/Chips/OFTChip/OFTChip.sol"; uint8 constant PERMISSIONS_SIZE = 4; // @dev Change PERMISSIONS_SIZE when changing the enum enum PermissionsType { // @dev NEVER CHANGE THE ORDER OF THIS ENUM! NONE, TRADING, LIQUIDITY, CHIP_OUT } struct IntentsPermissionsMsg { bool allow; PermissionsType permissionsType; address spender; } /** * @title IntentsPermissions * @notice Holds permissions for signing intents on behalf of another account */ contract IntentsPermissions is IOAppComposer, ClaimableAdmin { using SafeERC20 for IERC20; // ***** Events ***** event IntentsPermissionsSet( PermissionsType indexed permissionsType, address indexed owner, address indexed spender, bool allow ); event AllowedCreatePermissionsSet(address indexed owner, bool allowed); event TokensSwept( address indexed token, address indexed receiver, uint256 amount ); event NativeSwept(address indexed receiver, uint256 amount); // ***** Immutable Storage ***** OFTChip public immutable oftChip; IERC20 public immutable oftChipToken; // ***** Storage ***** // Owner address => isAllowed mapping(address => bool) public allowedCreatePermissions; // PermissionsType => owner address => spender address => is approved mapping(address => mapping(address => bool))[PERMISSIONS_SIZE] public permissions; // ***** Views ***** function isAllowedCreatePermissions( address owner ) public view returns (bool) { return allowedCreatePermissions[owner]; } function permission( PermissionsType permissionsType, address owner, address spender ) public view returns (bool) { return permissions[uint256(permissionsType)][owner][spender]; } // ***** Constructor ***** constructor(address _oftChip) { require(_oftChip != address(0), "INVALID_OFT_CHIP"); oftChip = OFTChip(_oftChip); oftChipToken = IERC20(oftChip.token()); } // ***** Admin Functions ***** /// @notice Sets the allowedCreatePermissions flag. /// @param _allowedCreatePermissions The new allowedCreatePermissions flag. function setAllowedCreatePermissions( address _allowedCreatePermissions, bool _allowed ) external onlyAdmin { allowedCreatePermissions[_allowedCreatePermissions] = _allowed; emit AllowedCreatePermissionsSet(_allowedCreatePermissions, _allowed); } /** * @notice Sweep any non-underlying tokens from the contract * @dev Owner can sweep any tokens, this contract should not hold any tokens * @param _token The token to sweep * @param _amount The amount to sweep */ function sweepTokens(IERC20 _token, uint256 _amount) external onlyAdmin { _token.safeTransfer(admin, _amount); emit TokensSwept(address(_token), admin, _amount); } /** * @notice Sweep native coin from the contract * @dev Owner can sweep any native coin accidentally sent to the contract * @param _amount The amount to sweep */ function sweepNative(uint256 _amount) external onlyAdmin { payable(admin).transfer(_amount); emit NativeSwept(admin, _amount); } // ***** External Functions ***** /// @notice Handles incoming composed messages from LayerZero. /// @dev Decodes the message payload to perform intents permission setting and pass tokens to the owner. /// This method expects the encoded compose message to contain the permissions type, spender and a flag to turn on/off permissions. /// @param oApp The address of the originating OApp. /// @param /*guid*/ The globally unique identifier of the message (unused). /// @param message The encoded message content in the format of the OFTComposeMsgCodec. /// @param /*Executor*/ Executor address (unused). /// @param /*Executor Data*/ Additional data for checking for a specific executor (unused). function lzCompose( address oApp, bytes32 /*guid*/, bytes calldata message, address /*Executor*/, bytes calldata /*Executor Data*/ ) external payable override { require(oApp == address(oftChip), "INVALID_OAPP_RECEIVED"); require( msg.sender == address(oftChip.endpoint()), "INVALID_ENDPOINT_RECEIVED" ); // Transfer chips to the sender uint256 amountLD = OFTComposeMsgCodec.amountLD(message); address owner = OFTComposeMsgCodec.bytes32ToAddress( OFTComposeMsgCodec.composeFrom(message) ); oftChipToken.safeTransfer(owner, amountLD); // Check if the owner is allowed to create permissions if (!allowedCreatePermissions[owner]) { return; } // Extract the composed message from the delivered message using the MsgCodec IntentsPermissionsMsg memory intentsPermissionsMsg = abi.decode( OFTComposeMsgCodec.composeMsg(message), (IntentsPermissionsMsg) ); permissions[uint256(intentsPermissionsMsg.permissionsType)][owner][ intentsPermissionsMsg.spender ] = intentsPermissionsMsg.allow; // Emit an event to log the given permission emit IntentsPermissionsSet( intentsPermissionsMsg.permissionsType, owner, intentsPermissionsMsg.spender, intentsPermissionsMsg.allow ); } function setPermissionForSpender( PermissionsType _permissionsType, address _spender, bool _allow ) external { address owner = msg.sender; // Check if the owner is allowed to create permissions if (!allowedCreatePermissions[owner]) { return; } // State require( permissions[uint256(_permissionsType)][owner][_spender] != _allow, "ALREADY_SET" ); permissions[uint256(_permissionsType)][owner][_spender] = _allow; // Event emit IntentsPermissionsSet(_permissionsType, owner, _spender, _allow); } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"contract IRegistryV1","name":"_registry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"chainId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"domainSeparator","type":"bytes32"}],"name":"DomainSeparatorForChainStored","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"liquidityProvider","type":"address"},{"indexed":true,"internalType":"address","name":"permissionedAccount","type":"address"},{"indexed":false,"internalType":"enum LiquidityIntentsVerifierV1.LiquidityIntentsVerifierActions","name":"action","type":"uint8"}],"name":"InteractedOnBehalf","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"liquidityProvider","type":"address"},{"indexed":false,"internalType":"enum LiquidityIntentsVerifierV1.LiquidityIntentsVerifierActions","name":"action","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"LiquidityIntentVerified","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"NewAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldPendingAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newPendingAdmin","type":"address"}],"name":"NewPendingAdmin","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"},{"indexed":true,"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"SourceChainIdForAssetStored","type":"event"},{"inputs":[],"name":"CONTRACT_DOMAIN_NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CONTRACT_DOMAIN_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DYN_ROLE_INTENTS_PERMISSIONS_PREFIX","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EIP712DOMAIN_TYPEHASH","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_EPOCH_DEPOSIT_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_EPOCH_REDEEM_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_acceptAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"_msgSender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newPendingAdmin","type":"address"}],"name":"_setPendingAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"domainSeparatorForAsset","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"domainSeparatorForChain","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint8","name":"actionType","type":"uint8"}],"name":"getNextValidNonceFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract OFTChip","name":"","type":"address"}],"name":"intentsPermissions","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"interactOnBehalf_epochDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"name":"interactOnBehalf_epochRedeem","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint8","name":"","type":"uint8"}],"name":"nonceMap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingAdmin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"internalType":"struct LiquidityIntentsVerifierV1.LiquidityProviderRequestPayload_EpochDeposit","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes32","name":"domainSeparator","type":"bytes32"}],"name":"recoverEpochDepositPayloadSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"internalType":"struct LiquidityIntentsVerifierV1.LiquidityProviderRequestPayload_EpochRedeem","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes32","name":"domainSeparator","type":"bytes32"}],"name":"recoverEpochRedeemPayloadSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract IRegistryV1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract OFTChip","name":"oftChip","type":"address"},{"internalType":"string","name":"dynAddressSuffix","type":"string"}],"name":"setIntentsPermissions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"sourceChainIdForAsset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"storeSourceChainForAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"internalType":"struct LiquidityIntentsVerifierV1.LiquidityProviderRequestPayload_EpochDeposit","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes32","name":"domain","type":"bytes32"},{"internalType":"bytes32","name":"referralCode","type":"bytes32"}],"name":"verifyIntent_epochDeposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"liquidityProvider","type":"address"},{"internalType":"uint256","name":"epoch","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minAmountOut","type":"uint256"}],"internalType":"struct LiquidityIntentsVerifierV1.LiquidityProviderRequestPayload_EpochRedeem","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_epochRedeem","outputs":[],"stateMutability":"payable","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b50604051620023b2380380620023b2833981016040819052620000349162000115565b604080518082018252601a81527f4c697175696469747920496e74656e7473205665726966696572000000000000602080830191909152825180840190935260018352603160f81b90830152600080546001600160a01b031916331790559081816002620000a38382620001ee565b506003620000b28282620001ee565b5050506001600160a01b03831691506200010390505760405162461bcd60e51b815260206004820152600c60248201526b57524f4e475f504152414d5360a01b604482015260640160405180910390fd5b6001600160a01b0316608052620002ba565b6000602082840312156200012857600080fd5b81516001600160a01b03811681146200014057600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200017257607f821691505b6020821081036200019357634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001e9576000816000526020600020601f850160051c81016020861015620001c45750805b601f850160051c820191505b81811015620001e557828155600101620001d0565b5050505b505050565b81516001600160401b038111156200020a576200020a62000147565b62000222816200021b84546200015d565b8462000199565b602080601f8311600181146200025a5760008415620002415750858301515b600019600386901b1c1916600185901b178555620001e5565b600085815260208120601f198616915b828110156200028b578886015182559484019460019091019084016200026a565b5085821015620002aa5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6080516120d5620002dd600039600081816103aa01526112aa01526120d56000f3fe6080604052600436106101815760003560e01c80637b103999116100d1578063c49f91d31161008a578063e2a1181a11610064578063e2a1181a146104b0578063e7c3822f146104d0578063e9c714f2146104f0578063f851a4401461050557600080fd5b8063c49f91d314610449578063cf63e34e1461047d578063d81587101461049057600080fd5b80637b103999146103985780638714f383146103cc5780639652a4bd146103e15780639d443327146103f6578063b71d1a0c14610416578063c3a8f1201461043657600080fd5b806312d99fd11161013e5780632678224711610118578063267822471461031857806358659d6e146103385780635dc1783e146103585780636fccbffc1461036b57600080fd5b806312d99fd11461027d57806316e27a7c1461029d5780631f470ad3146102e057600080fd5b80630518007f1461018657806306b042b3146101b15780630da7fba9146101c65780630f2a3d47146101db578063108c66e314610216578063119df25f14610256575b600080fd5b34801561019257600080fd5b5061019b610525565b6040516101a891906118e1565b60405180910390f35b6101c46101bf36600461192c565b610541565b005b3480156101d257600080fd5b5061019b6106d9565b3480156101e757600080fd5b506102086101f6366004611972565b60066020526000908152604090205481565b6040519081526020016101a8565b34801561022257600080fd5b5061019b60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525081565b34801561026257600080fd5b50335b6040516001600160a01b0390911681526020016101a8565b34801561028957600080fd5b506101c461029836600461198f565b610767565b3480156102a957600080fd5b506102086102b8366004611972565b6001600160a01b03166000908152600660209081526040808320548352600490915290205490565b3480156102ec57600080fd5b506102086102fb3660046119d1565b600760209081526000928352604080842090915290825290205481565b34801561032457600080fd5b50600154610265906001600160a01b031681565b34801561034457600080fd5b506101c4610353366004611a06565b6107bc565b6101c4610366366004611a9d565b61082c565b34801561037757600080fd5b50610208610386366004611af7565b60046020526000908152604090205481565b3480156103a457600080fd5b506102657f000000000000000000000000000000000000000000000000000000000000000081565b3480156103d857600080fd5b5061019b610ac2565b3480156103ed57600080fd5b5061019b610ade565b34801561040257600080fd5b5061019b610411366004611972565b610aeb565b34801561042257600080fd5b506101c4610431366004611972565b610b04565b6101c4610444366004611b10565b610bac565b34801561045557600080fd5b506102087f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81565b6101c461048b366004611b69565b610d4f565b34801561049c57600080fd5b506102086104ab3660046119d1565b610fcf565b3480156104bc57600080fd5b506102656104cb366004611bae565b610ffd565b3480156104dc57600080fd5b506102656104eb366004611bae565b6110b4565b3480156104fc57600080fd5b506101c46110cf565b34801561051157600080fd5b50600054610265906001600160a01b031681565b6040518060c0016040528060948152602001611f796094913981565b60003390506105b2856001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610587573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ab9190611bff565b85836111ed565b6105f35760405162461bcd60e51b815260206004820152600d60248201526c2727afa822a926a4a9a9a4a7a760991b60448201526064015b60405180910390fd5b600083116106135760405162461bcd60e51b81526004016105ea90611c1c565b604051639980a5f360e01b81526001600160a01b0385811660048301526024820185905260448201849052861690639980a5f390606401600060405180830381600087803b15801561066457600080fd5b505af1158015610678573d6000803e3d6000fd5b50505050806001600160a01b0316846001600160a01b0316866001600160a01b03167f240672ee6e1a111e985d4a1efb7f4bd13043ce9249564d6dcc96710162bd6e4d60026040516106ca9190611c6b565b60405180910390a45050505050565b600280546106e690611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461071290611c79565b801561075f5780601f106107345761010080835404028352916020019161075f565b820191906000526020600020905b81548152906001019060200180831161074257829003601f168201915b505050505081565b6000546001600160a01b031633146107ae5760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b60448201526064016105ea565b6107b8828261141b565b5050565b6000546001600160a01b031633146108035760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b60448201526064016105ea565b6001600160a01b0383166000908152600560205260409020610826828483611d14565b50505050565b60006108416102b86040890160208a01611972565b905060006108528888888886610ffd565b90506108646060890160408a01611972565b6001600160a01b0316816001600160a01b03161480610908575061090861089160408a0160208b01611972565b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f29190611bff565b61090260608b0160408c01611972565b836111ed565b6109545760405162461bcd60e51b815260206004820181905260248201527f4e4f545f5349474e45445f42595f4c49515549444954595f50524f564944455260448201526064016105ea565b60008860800135116109785760405162461bcd60e51b81526004016105ea90611c1c565b61099461098b60608a0160408b01611972565b60018a35611520565b6109a46040890160208a01611972565b6001600160a01b031663f2fc6e666109c260608b0160408c01611972565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260808b0135602482015260a08b01356044820152606481018790526084810186905260a401600060405180830381600087803b158015610a2557600080fd5b505af1158015610a39573d6000803e3d6000fd5b50610a4e925050506060890160408a01611972565b6001600160a01b0316610a6760408a0160208b01611972565b6001600160a01b0316336001600160a01b03167f3ddac1a4cdd199fa329b4066e2326f873d47bff9f7b5dc8eb800703b4c295ed960018c60000135604051610ab0929190611dd5565b60405180910390a45050505050505050565b6040518060c001604052806093815260200161200d6093913981565b600380546106e690611c79565b600560205260009081526040902080546106e690611c79565b6000546001600160a01b03163314610b4a5760405162461bcd60e51b81526020600482015260096024820152682737ba1020b236b4b760b91b60448201526064016105ea565b600180546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991015b60405180910390a15050565b6000339050610c1d876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190611bff565b87836111ed565b610c595760405162461bcd60e51b815260206004820152600d60248201526c2727afa822a926a4a9a9a4a7a760991b60448201526064016105ea565b60008511610c795760405162461bcd60e51b81526004016105ea90611c1c565b60405163797e373360e11b81526001600160a01b0387811660048301526024820187905260448201869052606482018590526084820184905288169063f2fc6e669060a401600060405180830381600087803b158015610cd857600080fd5b505af1158015610cec573d6000803e3d6000fd5b50505050806001600160a01b0316866001600160a01b0316886001600160a01b03167f240672ee6e1a111e985d4a1efb7f4bd13043ce9249564d6dcc96710162bd6e4d6001604051610d3e9190611c6b565b60405180910390a450505050505050565b6000610d646102b86040870160208801611972565b90506000610d7586868686866110b4565b9050610d876060870160408801611972565b6001600160a01b0316816001600160a01b03161480610e255750610e25610db46040880160208901611972565b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610df1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e159190611bff565b6109026060890160408a01611972565b610e715760405162461bcd60e51b815260206004820181905260248201527f4e4f545f5349474e45445f42595f4c49515549444954595f50524f564944455260448201526064016105ea565b6000866080013511610e955760405162461bcd60e51b81526004016105ea90611c1c565b610eb1610ea86060880160408901611972565b60028835611520565b610ec16040870160208801611972565b6001600160a01b0316639980a5f3610edf6060890160408a01611972565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526080890135602482015260a08901356044820152606401600060405180830381600087803b158015610f3457600080fd5b505af1158015610f48573d6000803e3d6000fd5b50610f5d925050506060870160408801611972565b6001600160a01b0316610f766040880160208901611972565b6001600160a01b0316336001600160a01b03167f3ddac1a4cdd199fa329b4066e2326f873d47bff9f7b5dc8eb800703b4c295ed960028a60000135604051610fbf929190611dd5565b60405180910390a4505050505050565b6001600160a01b038216600090815260076020908152604080832060ff851684529091529020545b92915050565b60008082611018611013368a90038a018a611e7c565b6115c5565b60405161190160f01b60208201526022810192909252604282015260620160408051601f1981840301815282825280516020918201206000845290830180835281905260ff8916918301919091526060820187905260808201869052915060019060a0016020604051602081039080840390855afa15801561109e573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b600080826110186110ca368a90038a018a611e7c565b611633565b6001546001600160a01b0316331480156110f357506001546001600160a01b031615155b61113f5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420746865204558495354494e472070656e64696e672061646d696e000060448201526064016105ea565b60008054600180546001600160a01b038082166001600160a01b031980861682179096559490911690915560408051919092168082526020820184905292917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc910160405180910390a1600154604080516001600160a01b03808516825290921660208301527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a99101610ba0565b6001600160a01b0383166000908152600560205260408120805482919061121390611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461123f90611c79565b801561128c5780601f106112615761010080835404028352916020019161128c565b820191906000526020600020905b81548152906001019060200180831161126f57829003601f168201915b5050505050905080516000036112a6576000915050611414565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166358ca59ce60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525084604051602001611316929190611e98565b6040516020818303038152906040526040518263ffffffff1660e01b815260040161134191906118e1565b602060405180830381865afa15801561135e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113829190611bff565b90506001600160a01b03811661139d57600092505050611414565b60405163b0cbc2e160e01b81526001600160a01b0382169063b0cbc2e1906113ce9060029089908990600401611ec7565b602060405180830381865afa1580156113eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140f9190611ef9565b925050505b9392505050565b6001600160a01b0382166000908152600660205260409020541561148f5760405162461bcd60e51b815260206004820152602560248201527f434841494e5f49445f464f525f41535345545f414c52454144595f434f4e464960448201526411d554915160da1b60648201526084016105ea565b806000036114cf5760405162461bcd60e51b815260206004820152600d60248201526c434841494e5f49445f5a45524f60981b60448201526064016105ea565b6114d881611684565b506001600160a01b038216600081815260066020526040808220849055518392917f8983e01eaf5771a114f1aa7f72a023a35642e048180682aa2fb04db0cbd220c291a35050565b6001600160a01b038316600090815260076020908152604080832060ff861684529091529020548181146115885760405162461bcd60e51b815260206004820152600f60248201526e494e434f52524543545f4e4f4e434560881b60448201526064016105ea565b611593816001611f1b565b6001600160a01b03909416600090815260076020908152604080832060ff909616835294905292909220929092555050565b60006040518060c0016040528060948152602001611f796094913980516020918201208351848301516040808701516060880151608089015160a08a01519351611616989394929391929101611f3c565b604051602081830303815290604052805190602001209050919050565b60006040518060c001604052806093815260200161200d6093913980516020918201208351848301516040808701516060880151608089015160a08a01519351611616989394929391929101611f3c565b60008181526004602052604081205480610ff75760006117e06040518060800160405280600280546116b590611c79565b80601f01602080910402602001604051908101604052809291908181526020018280546116e190611c79565b801561172e5780601f106117035761010080835404028352916020019161172e565b820191906000526020600020905b81548152906001019060200180831161171157829003601f168201915b505050505081526020016003805461174590611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461177190611c79565b80156117be5780601f10611793576101008083540402835291602001916117be565b820191906000526020600020905b8154815290600101906020018083116117a157829003601f168201915b50505050508152602001868152602001306001600160a01b031681525061183d565b600085815260046020526040908190208290555190915084907f04df087044a5490c34ea0092af5dbdd1a3a35fefd63f0864c1d05dba3075f165906118289084815260200190565b60405180910390a29392505050565b50919050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f826000015180519060200120836020015180519060200120846040015185606001516040516020016116169594939291909485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b60005b838110156118d85781810151838201526020016118c0565b50506000910152565b60208152600082518060208401526119008160408501602087016118bd565b601f01601f19169190910160400192915050565b6001600160a01b038116811461192957600080fd5b50565b6000806000806080858703121561194257600080fd5b843561194d81611914565b9350602085013561195d81611914565b93969395505050506040820135916060013590565b60006020828403121561198457600080fd5b813561141481611914565b600080604083850312156119a257600080fd5b82356119ad81611914565b946020939093013593505050565b803560ff811681146119cc57600080fd5b919050565b600080604083850312156119e457600080fd5b82356119ef81611914565b91506119fd602084016119bb565b90509250929050565b600080600060408486031215611a1b57600080fd5b8335611a2681611914565b9250602084013567ffffffffffffffff80821115611a4357600080fd5b818601915086601f830112611a5757600080fd5b813581811115611a6657600080fd5b876020828501011115611a7857600080fd5b6020830194508093505050509250925092565b600060c0828403121561183757600080fd5b6000806000806000806101608789031215611ab757600080fd5b611ac18888611a8b565b9550611acf60c088016119bb565b959895975050505060e084013593610100810135936101208201359350610140909101359150565b600060208284031215611b0957600080fd5b5035919050565b60008060008060008060c08789031215611b2957600080fd5b8635611b3481611914565b95506020870135611b4481611914565b95989597505050506040840135936060810135936080820135935060a0909101359150565b6000806000806101208587031215611b8057600080fd5b611b8a8686611a8b565b9350611b9860c086016119bb565b939693955050505060e082013591610100013590565b60008060008060006101408688031215611bc757600080fd5b611bd18787611a8b565b9450611bdf60c087016119bb565b949794965050505060e08301359261010081013592610120909101359150565b600060208284031215611c1157600080fd5b815161141481611914565b6020808252600b908201526a414d4f554e545f5a45524f60a81b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b60038110611c6757611c67611c41565b9052565b60208101610ff78284611c57565b600181811c90821680611c8d57607f821691505b60208210810361183757634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b601f821115611d0f576000816000526020600020601f850160051c81016020861015611cec5750805b601f850160051c820191505b81811015611d0b57828155600101611cf8565b5050505b505050565b67ffffffffffffffff831115611d2c57611d2c611cad565b611d4083611d3a8354611c79565b83611cc3565b6000601f841160018114611d745760008515611d5c5750838201355b600019600387901b1c1916600186901b178355611dce565b600083815260209020601f19861690835b82811015611da55786850135825560209485019460019092019101611d85565b5086821015611dc25760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b60408101611de38285611c57565b8260208301529392505050565b600060c08284031215611e0257600080fd5b60405160c0810181811067ffffffffffffffff82111715611e2557611e25611cad565b604052823581529050806020830135611e3d81611914565b60208201526040830135611e5081611914565b80604083015250606083013560608201526080830135608082015260a083013560a08201525092915050565b600060c08284031215611e8e57600080fd5b6114148383611df0565b60008351611eaa8184602088016118bd565b835190830190611ebe8183602088016118bd565b01949350505050565b6060810160048510611edb57611edb611c41565b9381526001600160a01b039283166020820152911660409091015290565b600060208284031215611f0b57600080fd5b8151801515811461141457600080fd5b80820180821115610ff757634e487b7160e01b600052601160045260246000fd5b96875260208701959095526001600160a01b039384166040870152919092166060850152608084019190915260a083015260c082015260e0019056fe4c697175696469747950726f7669646572526571756573745061796c6f61645f45706f63684465706f7369742875696e74323536206e6f6e63652c6164647265737320706f6f6c2c61646472657373206c697175696469747950726f76696465722c75696e743235362065706f63682c75696e7432353620616d6f756e742c75696e74323536206d696e416d6f756e744f7574294c697175696469747950726f7669646572526571756573745061796c6f61645f45706f636852656465656d2875696e74323536206e6f6e63652c6164647265737320706f6f6c2c61646472657373206c697175696469747950726f76696465722c75696e743235362065706f63682c75696e7432353620616d6f756e742c75696e74323536206d696e416d6f756e744f757429a2646970667358221220107b6ae03e54d993d5f11ba2b8f9fa464646d2956593f32622a82873102384db64736f6c634300081800330000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c207
Deployed Bytecode
0x6080604052600436106101815760003560e01c80637b103999116100d1578063c49f91d31161008a578063e2a1181a11610064578063e2a1181a146104b0578063e7c3822f146104d0578063e9c714f2146104f0578063f851a4401461050557600080fd5b8063c49f91d314610449578063cf63e34e1461047d578063d81587101461049057600080fd5b80637b103999146103985780638714f383146103cc5780639652a4bd146103e15780639d443327146103f6578063b71d1a0c14610416578063c3a8f1201461043657600080fd5b806312d99fd11161013e5780632678224711610118578063267822471461031857806358659d6e146103385780635dc1783e146103585780636fccbffc1461036b57600080fd5b806312d99fd11461027d57806316e27a7c1461029d5780631f470ad3146102e057600080fd5b80630518007f1461018657806306b042b3146101b15780630da7fba9146101c65780630f2a3d47146101db578063108c66e314610216578063119df25f14610256575b600080fd5b34801561019257600080fd5b5061019b610525565b6040516101a891906118e1565b60405180910390f35b6101c46101bf36600461192c565b610541565b005b3480156101d257600080fd5b5061019b6106d9565b3480156101e757600080fd5b506102086101f6366004611972565b60066020526000908152604090205481565b6040519081526020016101a8565b34801561022257600080fd5b5061019b60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525081565b34801561026257600080fd5b50335b6040516001600160a01b0390911681526020016101a8565b34801561028957600080fd5b506101c461029836600461198f565b610767565b3480156102a957600080fd5b506102086102b8366004611972565b6001600160a01b03166000908152600660209081526040808320548352600490915290205490565b3480156102ec57600080fd5b506102086102fb3660046119d1565b600760209081526000928352604080842090915290825290205481565b34801561032457600080fd5b50600154610265906001600160a01b031681565b34801561034457600080fd5b506101c4610353366004611a06565b6107bc565b6101c4610366366004611a9d565b61082c565b34801561037757600080fd5b50610208610386366004611af7565b60046020526000908152604090205481565b3480156103a457600080fd5b506102657f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c20781565b3480156103d857600080fd5b5061019b610ac2565b3480156103ed57600080fd5b5061019b610ade565b34801561040257600080fd5b5061019b610411366004611972565b610aeb565b34801561042257600080fd5b506101c4610431366004611972565b610b04565b6101c4610444366004611b10565b610bac565b34801561045557600080fd5b506102087f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81565b6101c461048b366004611b69565b610d4f565b34801561049c57600080fd5b506102086104ab3660046119d1565b610fcf565b3480156104bc57600080fd5b506102656104cb366004611bae565b610ffd565b3480156104dc57600080fd5b506102656104eb366004611bae565b6110b4565b3480156104fc57600080fd5b506101c46110cf565b34801561051157600080fd5b50600054610265906001600160a01b031681565b6040518060c0016040528060948152602001611f796094913981565b60003390506105b2856001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610587573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ab9190611bff565b85836111ed565b6105f35760405162461bcd60e51b815260206004820152600d60248201526c2727afa822a926a4a9a9a4a7a760991b60448201526064015b60405180910390fd5b600083116106135760405162461bcd60e51b81526004016105ea90611c1c565b604051639980a5f360e01b81526001600160a01b0385811660048301526024820185905260448201849052861690639980a5f390606401600060405180830381600087803b15801561066457600080fd5b505af1158015610678573d6000803e3d6000fd5b50505050806001600160a01b0316846001600160a01b0316866001600160a01b03167f240672ee6e1a111e985d4a1efb7f4bd13043ce9249564d6dcc96710162bd6e4d60026040516106ca9190611c6b565b60405180910390a45050505050565b600280546106e690611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461071290611c79565b801561075f5780601f106107345761010080835404028352916020019161075f565b820191906000526020600020905b81548152906001019060200180831161074257829003601f168201915b505050505081565b6000546001600160a01b031633146107ae5760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b60448201526064016105ea565b6107b8828261141b565b5050565b6000546001600160a01b031633146108035760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b60448201526064016105ea565b6001600160a01b0383166000908152600560205260409020610826828483611d14565b50505050565b60006108416102b86040890160208a01611972565b905060006108528888888886610ffd565b90506108646060890160408a01611972565b6001600160a01b0316816001600160a01b03161480610908575061090861089160408a0160208b01611972565b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108f29190611bff565b61090260608b0160408c01611972565b836111ed565b6109545760405162461bcd60e51b815260206004820181905260248201527f4e4f545f5349474e45445f42595f4c49515549444954595f50524f564944455260448201526064016105ea565b60008860800135116109785760405162461bcd60e51b81526004016105ea90611c1c565b61099461098b60608a0160408b01611972565b60018a35611520565b6109a46040890160208a01611972565b6001600160a01b031663f2fc6e666109c260608b0160408c01611972565b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260808b0135602482015260a08b01356044820152606481018790526084810186905260a401600060405180830381600087803b158015610a2557600080fd5b505af1158015610a39573d6000803e3d6000fd5b50610a4e925050506060890160408a01611972565b6001600160a01b0316610a6760408a0160208b01611972565b6001600160a01b0316336001600160a01b03167f3ddac1a4cdd199fa329b4066e2326f873d47bff9f7b5dc8eb800703b4c295ed960018c60000135604051610ab0929190611dd5565b60405180910390a45050505050505050565b6040518060c001604052806093815260200161200d6093913981565b600380546106e690611c79565b600560205260009081526040902080546106e690611c79565b6000546001600160a01b03163314610b4a5760405162461bcd60e51b81526020600482015260096024820152682737ba1020b236b4b760b91b60448201526064016105ea565b600180546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991015b60405180910390a15050565b6000339050610c1d876001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610bf2573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c169190611bff565b87836111ed565b610c595760405162461bcd60e51b815260206004820152600d60248201526c2727afa822a926a4a9a9a4a7a760991b60448201526064016105ea565b60008511610c795760405162461bcd60e51b81526004016105ea90611c1c565b60405163797e373360e11b81526001600160a01b0387811660048301526024820187905260448201869052606482018590526084820184905288169063f2fc6e669060a401600060405180830381600087803b158015610cd857600080fd5b505af1158015610cec573d6000803e3d6000fd5b50505050806001600160a01b0316866001600160a01b0316886001600160a01b03167f240672ee6e1a111e985d4a1efb7f4bd13043ce9249564d6dcc96710162bd6e4d6001604051610d3e9190611c6b565b60405180910390a450505050505050565b6000610d646102b86040870160208801611972565b90506000610d7586868686866110b4565b9050610d876060870160408801611972565b6001600160a01b0316816001600160a01b03161480610e255750610e25610db46040880160208901611972565b6001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610df1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e159190611bff565b6109026060890160408a01611972565b610e715760405162461bcd60e51b815260206004820181905260248201527f4e4f545f5349474e45445f42595f4c49515549444954595f50524f564944455260448201526064016105ea565b6000866080013511610e955760405162461bcd60e51b81526004016105ea90611c1c565b610eb1610ea86060880160408901611972565b60028835611520565b610ec16040870160208801611972565b6001600160a01b0316639980a5f3610edf6060890160408a01611972565b6040516001600160e01b031960e084901b1681526001600160a01b0390911660048201526080890135602482015260a08901356044820152606401600060405180830381600087803b158015610f3457600080fd5b505af1158015610f48573d6000803e3d6000fd5b50610f5d925050506060870160408801611972565b6001600160a01b0316610f766040880160208901611972565b6001600160a01b0316336001600160a01b03167f3ddac1a4cdd199fa329b4066e2326f873d47bff9f7b5dc8eb800703b4c295ed960028a60000135604051610fbf929190611dd5565b60405180910390a4505050505050565b6001600160a01b038216600090815260076020908152604080832060ff851684529091529020545b92915050565b60008082611018611013368a90038a018a611e7c565b6115c5565b60405161190160f01b60208201526022810192909252604282015260620160408051601f1981840301815282825280516020918201206000845290830180835281905260ff8916918301919091526060820187905260808201869052915060019060a0016020604051602081039080840390855afa15801561109e573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b600080826110186110ca368a90038a018a611e7c565b611633565b6001546001600160a01b0316331480156110f357506001546001600160a01b031615155b61113f5760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420746865204558495354494e472070656e64696e672061646d696e000060448201526064016105ea565b60008054600180546001600160a01b038082166001600160a01b031980861682179096559490911690915560408051919092168082526020820184905292917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc910160405180910390a1600154604080516001600160a01b03808516825290921660208301527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a99101610ba0565b6001600160a01b0383166000908152600560205260408120805482919061121390611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461123f90611c79565b801561128c5780601f106112615761010080835404028352916020019161128c565b820191906000526020600020905b81548152906001019060200180831161126f57829003601f168201915b5050505050905080516000036112a6576000915050611414565b60007f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c2076001600160a01b03166358ca59ce60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525084604051602001611316929190611e98565b6040516020818303038152906040526040518263ffffffff1660e01b815260040161134191906118e1565b602060405180830381865afa15801561135e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113829190611bff565b90506001600160a01b03811661139d57600092505050611414565b60405163b0cbc2e160e01b81526001600160a01b0382169063b0cbc2e1906113ce9060029089908990600401611ec7565b602060405180830381865afa1580156113eb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140f9190611ef9565b925050505b9392505050565b6001600160a01b0382166000908152600660205260409020541561148f5760405162461bcd60e51b815260206004820152602560248201527f434841494e5f49445f464f525f41535345545f414c52454144595f434f4e464960448201526411d554915160da1b60648201526084016105ea565b806000036114cf5760405162461bcd60e51b815260206004820152600d60248201526c434841494e5f49445f5a45524f60981b60448201526064016105ea565b6114d881611684565b506001600160a01b038216600081815260066020526040808220849055518392917f8983e01eaf5771a114f1aa7f72a023a35642e048180682aa2fb04db0cbd220c291a35050565b6001600160a01b038316600090815260076020908152604080832060ff861684529091529020548181146115885760405162461bcd60e51b815260206004820152600f60248201526e494e434f52524543545f4e4f4e434560881b60448201526064016105ea565b611593816001611f1b565b6001600160a01b03909416600090815260076020908152604080832060ff909616835294905292909220929092555050565b60006040518060c0016040528060948152602001611f796094913980516020918201208351848301516040808701516060880151608089015160a08a01519351611616989394929391929101611f3c565b604051602081830303815290604052805190602001209050919050565b60006040518060c001604052806093815260200161200d6093913980516020918201208351848301516040808701516060880151608089015160a08a01519351611616989394929391929101611f3c565b60008181526004602052604081205480610ff75760006117e06040518060800160405280600280546116b590611c79565b80601f01602080910402602001604051908101604052809291908181526020018280546116e190611c79565b801561172e5780601f106117035761010080835404028352916020019161172e565b820191906000526020600020905b81548152906001019060200180831161171157829003601f168201915b505050505081526020016003805461174590611c79565b80601f016020809104026020016040519081016040528092919081815260200182805461177190611c79565b80156117be5780601f10611793576101008083540402835291602001916117be565b820191906000526020600020905b8154815290600101906020018083116117a157829003601f168201915b50505050508152602001868152602001306001600160a01b031681525061183d565b600085815260046020526040908190208290555190915084907f04df087044a5490c34ea0092af5dbdd1a3a35fefd63f0864c1d05dba3075f165906118289084815260200190565b60405180910390a29392505050565b50919050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f826000015180519060200120836020015180519060200120846040015185606001516040516020016116169594939291909485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b60005b838110156118d85781810151838201526020016118c0565b50506000910152565b60208152600082518060208401526119008160408501602087016118bd565b601f01601f19169190910160400192915050565b6001600160a01b038116811461192957600080fd5b50565b6000806000806080858703121561194257600080fd5b843561194d81611914565b9350602085013561195d81611914565b93969395505050506040820135916060013590565b60006020828403121561198457600080fd5b813561141481611914565b600080604083850312156119a257600080fd5b82356119ad81611914565b946020939093013593505050565b803560ff811681146119cc57600080fd5b919050565b600080604083850312156119e457600080fd5b82356119ef81611914565b91506119fd602084016119bb565b90509250929050565b600080600060408486031215611a1b57600080fd5b8335611a2681611914565b9250602084013567ffffffffffffffff80821115611a4357600080fd5b818601915086601f830112611a5757600080fd5b813581811115611a6657600080fd5b876020828501011115611a7857600080fd5b6020830194508093505050509250925092565b600060c0828403121561183757600080fd5b6000806000806000806101608789031215611ab757600080fd5b611ac18888611a8b565b9550611acf60c088016119bb565b959895975050505060e084013593610100810135936101208201359350610140909101359150565b600060208284031215611b0957600080fd5b5035919050565b60008060008060008060c08789031215611b2957600080fd5b8635611b3481611914565b95506020870135611b4481611914565b95989597505050506040840135936060810135936080820135935060a0909101359150565b6000806000806101208587031215611b8057600080fd5b611b8a8686611a8b565b9350611b9860c086016119bb565b939693955050505060e082013591610100013590565b60008060008060006101408688031215611bc757600080fd5b611bd18787611a8b565b9450611bdf60c087016119bb565b949794965050505060e08301359261010081013592610120909101359150565b600060208284031215611c1157600080fd5b815161141481611914565b6020808252600b908201526a414d4f554e545f5a45524f60a81b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b60038110611c6757611c67611c41565b9052565b60208101610ff78284611c57565b600181811c90821680611c8d57607f821691505b60208210810361183757634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052604160045260246000fd5b601f821115611d0f576000816000526020600020601f850160051c81016020861015611cec5750805b601f850160051c820191505b81811015611d0b57828155600101611cf8565b5050505b505050565b67ffffffffffffffff831115611d2c57611d2c611cad565b611d4083611d3a8354611c79565b83611cc3565b6000601f841160018114611d745760008515611d5c5750838201355b600019600387901b1c1916600186901b178355611dce565b600083815260209020601f19861690835b82811015611da55786850135825560209485019460019092019101611d85565b5086821015611dc25760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b60408101611de38285611c57565b8260208301529392505050565b600060c08284031215611e0257600080fd5b60405160c0810181811067ffffffffffffffff82111715611e2557611e25611cad565b604052823581529050806020830135611e3d81611914565b60208201526040830135611e5081611914565b80604083015250606083013560608201526080830135608082015260a083013560a08201525092915050565b600060c08284031215611e8e57600080fd5b6114148383611df0565b60008351611eaa8184602088016118bd565b835190830190611ebe8183602088016118bd565b01949350505050565b6060810160048510611edb57611edb611c41565b9381526001600160a01b039283166020820152911660409091015290565b600060208284031215611f0b57600080fd5b8151801515811461141457600080fd5b80820180821115610ff757634e487b7160e01b600052601160045260246000fd5b96875260208701959095526001600160a01b039384166040870152919092166060850152608084019190915260a083015260c082015260e0019056fe4c697175696469747950726f7669646572526571756573745061796c6f61645f45706f63684465706f7369742875696e74323536206e6f6e63652c6164647265737320706f6f6c2c61646472657373206c697175696469747950726f76696465722c75696e743235362065706f63682c75696e7432353620616d6f756e742c75696e74323536206d696e416d6f756e744f7574294c697175696469747950726f7669646572526571756573745061796c6f61645f45706f636852656465656d2875696e74323536206e6f6e63652c6164647265737320706f6f6c2c61646472657373206c697175696469747950726f76696465722c75696e743235362065706f63682c75696e7432353620616d6f756e742c75696e74323536206d696e416d6f756e744f757429a2646970667358221220107b6ae03e54d993d5f11ba2b8f9fa464646d2956593f32622a82873102384db64736f6c63430008180033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c207
-----Decoded View---------------
Arg [0] : _registry (address): 0x4CF3d61165a6Be8FF741320ad27Cab57faE5c207
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c207
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
[ 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.