Overview
S Balance
0 S
S Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 9 from a total of 9 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Store Source Cha... | 5921312 | 2 days ago | IN | 0 S | 0.00276193 | ||||
Store Source Cha... | 5921308 | 2 days ago | IN | 0 S | 0.00276259 | ||||
Verify Intent_tr... | 4856128 | 11 days ago | IN | 1 wei | 0.0148129 | ||||
Store Source Cha... | 4029634 | 17 days ago | IN | 0 S | 0.00165755 | ||||
Store Source Cha... | 3910696 | 18 days ago | IN | 0 S | 0.00256832 | ||||
Store Source Cha... | 3910694 | 18 days ago | IN | 0 S | 0.00165755 | ||||
Store Source Cha... | 3910692 | 18 days ago | IN | 0 S | 0.00165755 | ||||
Store Source Cha... | 3910691 | 18 days ago | IN | 0 S | 0.00165755 | ||||
Store Source Cha... | 3910685 | 18 days ago | IN | 0 S | 0.00256792 |
Latest 1 internal transaction
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
4856128 | 11 days ago | 1 wei |
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
TradeIntentsVerifierV1
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/ITradingFloorV1.sol"; import "../interfaces/IOrderBookV1.sol"; import "../interfaces/ITradersPortalV1.sol"; import "./NonceMechanisms/HashAndActionSerialNonceBase.sol"; import "./MultiSourceChainIntentsVerifierBase.sol"; /** * @title TradeIntentsVerifierV1 * @notice This contract is responsible for verifying trade 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 * * Only exception is the openNewPosition function, which also stores the domain separator and trader for the position * so that it can be used in further verifications related to the position. */ contract TradeIntentsVerifierV1 is MultiSourceChainIntentsVerifierBase, HashAndActionSerialNonceBase { // ***** Enums ***** enum TradeIntentsVerifierActions { NONE, REQUEST_POSITION_OPEN, REQUEST_POSITION_MARKET_CLOSE, REQUEST_POSITION_SINGLE_FIELD_UPDATE, REQUEST_POSITION_DOUBLE_FIELD_UPDATE, DIRECT_UPDATE_PENDING_LIMIT_POSITION, DIRECT_CANCEL_PENDING_LIMIT_POSITION } // ***** Action Verifications (Immutable) ***** string public constant REQUEST_PAYLOAD_OPEN_POSITION_TYPE_DESCRIPTOR = "UserRequestPayload_OpenPosition(uint256 nonce,PositionRequestIdentifiers positionRequestIdentifiers,PositionRequestParams positionRequestParams,uint8 orderType)PositionRequestIdentifiers(address trader,uint16 pairId,address settlementAsset,uint32 positionIndex)PositionRequestParams(bool long,uint256 collateral,uint32 leverage,uint64 minPrice,uint64 maxPrice,uint64 tp,uint64 sl,uint64 tpByFraction,uint64 slByFraction)"; string public constant POSITION_REQUEST_IDENTIFIERS_TYPE_DESCRIPTOR = "PositionRequestIdentifiers(address trader,uint16 pairId,address settlementAsset,uint32 positionIndex)"; string public constant POSITION_REQUEST_PARAMS_TYPE_DESCRIPTOR = "PositionRequestParams(bool long,uint256 collateral,uint32 leverage,uint64 minPrice,uint64 maxPrice,uint64 tp,uint64 sl,uint64 tpByFraction,uint64 slByFraction)"; string public constant REQUEST_PAYLOAD_CLOSE_MARKET_TYPE_DESCRIPTOR = "UserRequestPayload_CloseMarket(uint256 nonce,bytes32 positionId,uint64 minPrice,uint64 maxPrice)"; string public constant REQUEST_PAYLOAD_UPDATE_POSITION_SINGLE_FIELD_TYPE_DESCRIPTOR = "UserRequestPayload_UpdatePositionSingleField(uint256 nonce,bytes32 positionId,uint8 orderType,uint64 fieldValue)"; string public constant REQUEST_PAYLOAD_UPDATE_POSITION_DOUBLE_FIELD_TYPE_DESCRIPTOR = "UserRequestPayload_UpdatePositionDoubleField(uint256 nonce,bytes32 positionId,uint8 orderType,uint64 fieldValueA,uint64 fieldValueB)"; string public constant DIRECT_PAYLOAD_UPDATE_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR = "UserDirectPayload_UpdatePendingLimitPosition(uint256 nonce,bytes32 positionId,uint64 minPrice,uint64 maxPrice,uint64 tp,uint64 sl)"; string public constant DIRECT_PAYLOAD_CANCEL_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR = "UserDirectPayload_CancelPendingLimitPosition(uint256 nonce,bytes32 positionId)"; struct UserRequestPayload_OpenPosition { uint256 nonce; ITradingFloorV1.PositionRequestIdentifiers positionRequestIdentifiers; ITradingFloorV1.PositionRequestParams positionRequestParams; ITradingFloorV1.OpenOrderType orderType; } struct UserRequestPayload_CloseMarket { uint256 nonce; bytes32 positionId; uint64 minPrice; uint64 maxPrice; } struct UserRequestPayload_UpdatePositionSingleField { uint256 nonce; bytes32 positionId; OrderBookStructsV1.UpdatePositionFieldOrderType orderType; uint64 fieldValue; } struct UserRequestPayload_UpdatePositionDoubleField { uint256 nonce; bytes32 positionId; OrderBookStructsV1.UpdatePositionFieldOrderType orderType; uint64 fieldValueA; uint64 fieldValueB; } struct UserDirectPayload_UpdatePendingLimitPosition { uint256 nonce; bytes32 positionId; uint64 minPrice; uint64 maxPrice; uint64 tp; uint64 sl; } struct UserDirectPayload_CancelPendingLimitPosition { uint256 nonce; bytes32 positionId; } // ***** Contracts (Immutable) ***** IRegistryV1 public immutable registry; // ***** Params ***** // position id => domain separator mapping(bytes32 => bytes32) public domainSeparatorsForPosition; // position id => trader mapping(bytes32 => address) public tradersForPosition; // position id => settlement asset mapping(bytes32 => address) public settlementAssetsForPosition; // ***** Events ***** event TradeIntentVerified( address indexed sender, TradeIntentsVerifierActions indexed action, bytes32 positionId, uint256 nonce ); // ***** Modifiers ***** modifier notContract() { require(tx.origin == _msgSender()); _; } // ***** Views ***** function getTradersPortal() public view returns (ITradersPortalV1) { return ITradersPortalV1(registry.tradersPortal()); } function getTradingFloor() public view returns (ITradingFloorV1) { return ITradingFloorV1( ITradersPortalV1(registry.tradersPortal()).tradingFloor() ); } function recoverOpenPositionPayloadSigner( UserRequestPayload_OpenPosition calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashOpenPositionPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverCloseMarketPayloadSigner( UserRequestPayload_CloseMarket calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashCloseMarketPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverUpdatePositionSingleFieldPayloadSigner( UserRequestPayload_UpdatePositionSingleField calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashUpdatePositionSingleFieldPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverUpdatePositionDoubleFieldPayloadSigner( UserRequestPayload_UpdatePositionDoubleField calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashUpdatePositionDoubleFieldPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverUpdatePendingLimitPositionSigner( UserDirectPayload_UpdatePendingLimitPosition calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashUpdatePendingLimitPositionPayload(payload) ) ); return ecrecover(digest, v, r, s); } function recoverCancelPendingLimitPositionSigner( UserDirectPayload_CancelPendingLimitPosition calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domainSeparator ) public pure returns (address) { bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", domainSeparator, hashCancelPendingLimitPositionPayload(payload) ) ); return ecrecover(digest, v, r, s); } // ***** Constructor ***** constructor( IRegistryV1 _registry ) MultiSourceChainIntentsVerifierBase("Trade Intents Verifier", "1") { require(address(_registry) != address(0), "WRONG_PARAMS"); registry = _registry; } // ***** Admin functions ***** // ***** Traders Interactions -- Requests ***** function verifyIntent_traderRequest_openNewPosition( UserRequestPayload_OpenPosition calldata payload, uint8 v, bytes32 r, bytes32 s, bytes32 domain, bytes32 referralCode, bool runCapTests ) external payable notContract { bytes32 domainSeparator = getDomainSeparatorForAssetInternal( payload.positionRequestIdentifiers.settlementAsset ); // Recover trader address recoveredSigner = recoverOpenPositionPayloadSigner( payload, v, r, s, domainSeparator ); // Sanity require( payload.positionRequestIdentifiers.trader == recoveredSigner || isIntentPermitted( payload.positionRequestIdentifiers.settlementAsset, payload.positionRequestIdentifiers.trader, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Generate expected position id bytes32 expectedPositionId = getTradingFloor().generatePositionHashId( payload.positionRequestIdentifiers.settlementAsset, payload.positionRequestIdentifiers.trader, payload.positionRequestIdentifiers.pairId, payload.positionRequestIdentifiers.positionIndex ); // Validate & Register Nonce validateNonceForActionAndIncrease( expectedPositionId, uint8(TradeIntentsVerifierActions.REQUEST_POSITION_OPEN), payload.nonce ); // Perform action bytes32 positionId = getTradersPortal().traderRequest_openNewPosition{ value: msg.value }( payload.positionRequestIdentifiers, payload.positionRequestParams, payload.orderType, domain, referralCode, runCapTests ); // SANITY : Ensure that the positionId is the expected one // NOTE : This should never fail and if it is the case, it is a critical error. require(positionId == expectedPositionId, "UNEXPECTED_POSITION_ID"); // Store position domain and trader for further verifications domainSeparatorsForPosition[positionId] = domainSeparator; tradersForPosition[positionId] = payload.positionRequestIdentifiers.trader; // Save settlement asset for positionId settlementAssetsForPosition[positionId] = payload .positionRequestIdentifiers .settlementAsset; // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.REQUEST_POSITION_OPEN, positionId, payload.nonce ); } function verifyIntent_traderRequest_marketClosePosition( UserRequestPayload_CloseMarket calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable notContract { // Get verification values ( bytes32 domainSeparatorForPosition, address traderForPosition ) = getDomainSeparatorAndTraderForPositionInternal(payload.positionId); // Recover trader address recoveredSigner = recoverCloseMarketPayloadSigner( payload, v, r, s, domainSeparatorForPosition ); // Sanity require( traderForPosition == recoveredSigner || isIntentPermittedByPositionId( payload.positionId, traderForPosition, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.positionId, uint8(TradeIntentsVerifierActions.REQUEST_POSITION_MARKET_CLOSE), payload.nonce ); // Perform action getTradersPortal().traderRequest_marketClosePosition{value: msg.value}( payload.positionId, payload.minPrice, payload.maxPrice ); // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.REQUEST_POSITION_MARKET_CLOSE, payload.positionId, payload.nonce ); } function verifyIntent_traderRequest_updatePositionSingleField( UserRequestPayload_UpdatePositionSingleField calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable notContract { // Get verification values ( bytes32 domainSeparatorForPosition, address traderForPosition ) = getDomainSeparatorAndTraderForPositionInternal(payload.positionId); // Recover trader address recoveredSigner = recoverUpdatePositionSingleFieldPayloadSigner( payload, v, r, s, domainSeparatorForPosition ); // Sanity require( traderForPosition == recoveredSigner || isIntentPermittedByPositionId( payload.positionId, traderForPosition, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.positionId, uint8(TradeIntentsVerifierActions.REQUEST_POSITION_SINGLE_FIELD_UPDATE), payload.nonce ); // Perform action getTradersPortal().traderRequest_updatePositionSingleField{ value: msg.value }(payload.positionId, payload.orderType, payload.fieldValue); // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.REQUEST_POSITION_SINGLE_FIELD_UPDATE, payload.positionId, payload.nonce ); } function verifyIntent_traderRequest_updatePositionDoubleField( UserRequestPayload_UpdatePositionDoubleField calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable notContract { // Get verification values ( bytes32 domainSeparatorForPosition, address traderForPosition ) = getDomainSeparatorAndTraderForPositionInternal(payload.positionId); // Recover trader address recoveredSigner = recoverUpdatePositionDoubleFieldPayloadSigner( payload, v, r, s, domainSeparatorForPosition ); // Sanity require( traderForPosition == recoveredSigner || isIntentPermittedByPositionId( payload.positionId, traderForPosition, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.positionId, uint8(TradeIntentsVerifierActions.REQUEST_POSITION_DOUBLE_FIELD_UPDATE), payload.nonce ); // Perform action getTradersPortal().traderRequest_updatePositionDoubleField{ value: msg.value }( payload.positionId, payload.orderType, payload.fieldValueA, payload.fieldValueB ); // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.REQUEST_POSITION_DOUBLE_FIELD_UPDATE, payload.positionId, payload.nonce ); } // ***** Traders Interactions -- Direct Actions ***** function verifyIntent_traderAction_updatePendingLimitPosition( UserDirectPayload_UpdatePendingLimitPosition calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable notContract { // Get verification values ( bytes32 domainSeparatorForPosition, address traderForPosition ) = getDomainSeparatorAndTraderForPositionInternal(payload.positionId); // Recover trader address recoveredSigner = recoverUpdatePendingLimitPositionSigner( payload, v, r, s, domainSeparatorForPosition ); // Sanity require( traderForPosition == recoveredSigner || isIntentPermittedByPositionId( payload.positionId, traderForPosition, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.positionId, uint8(TradeIntentsVerifierActions.DIRECT_UPDATE_PENDING_LIMIT_POSITION), payload.nonce ); // Perform action getTradersPortal().directAction_updatePendingPosition_limit( payload.positionId, payload.minPrice, payload.maxPrice, payload.tp, payload.sl ); // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.DIRECT_UPDATE_PENDING_LIMIT_POSITION, payload.positionId, payload.nonce ); } function verifyIntent_traderAction_cancelPendingLimitPosition( UserDirectPayload_CancelPendingLimitPosition calldata payload, uint8 v, bytes32 r, bytes32 s ) external payable notContract { // Get verification values ( bytes32 domainSeparatorForPosition, address traderForPosition ) = getDomainSeparatorAndTraderForPositionInternal(payload.positionId); // Recover trader address recoveredSigner = recoverCancelPendingLimitPositionSigner( payload, v, r, s, domainSeparatorForPosition ); // Sanity require( traderForPosition == recoveredSigner || isIntentPermittedByPositionId( payload.positionId, traderForPosition, recoveredSigner ), "NOT_SIGNED_BY_TRADER" ); // Validate & Register Nonce validateNonceForActionAndIncrease( payload.positionId, uint8(TradeIntentsVerifierActions.DIRECT_CANCEL_PENDING_LIMIT_POSITION), payload.nonce ); // Perform action getTradersPortal().directAction_cancelPendingPosition_limit( payload.positionId ); // Event emit TradeIntentVerified( msg.sender, TradeIntentsVerifierActions.DIRECT_CANCEL_PENDING_LIMIT_POSITION, payload.positionId, payload.nonce ); } // ***** Domain Separator Distinction ***** function getDomainSeparatorAndTraderForPositionInternal( bytes32 _positionId ) internal returns (bytes32 domainSeparator, address trader) { domainSeparator = domainSeparatorsForPosition[_positionId]; trader = tradersForPosition[_positionId]; if (domainSeparator == bytes32(0) || trader == address(0)) { ITradingFloorV1 tradingFloor = getTradingFloor(); TradingFloorStructsV1.PositionIdentifiers memory positionIdentifiers = tradingFloor.positionIdentifiersById( _positionId ); domainSeparator = getDomainSeparatorForAssetInternal( positionIdentifiers.settlementAsset ); trader = positionIdentifiers.trader; require(domainSeparator != bytes32(0), "NO_DOMAIN_SEPARATOR_FOR_CHAIN"); require(trader != address(0), "NO_TRADER_FOR_POSITION"); domainSeparatorsForPosition[_positionId] = domainSeparator; tradersForPosition[_positionId] = trader; } } // ***** Domain Separator Distinction ***** function getSettlementAssetForPositionInternal( bytes32 _positionId ) internal returns (address settlementAsset) { settlementAsset = settlementAssetsForPosition[_positionId]; if (settlementAsset == address(0)) { settlementAsset = getTradingFloor() .positionIdentifiersById(_positionId) .settlementAsset; require(settlementAsset != address(0), "NO_SA_FOR_POSITION"); settlementAssetsForPosition[_positionId] = settlementAsset; } } // ***** Intents Permissions ***** function isIntentPermittedByPositionId( bytes32 positionId, address owner, address spender ) internal returns (bool) { address settlementAsset = getSettlementAssetForPositionInternal(positionId); return isIntentPermitted(settlementAsset, owner, spender); } 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.TRADING, owner, spender ); } // ***** Context Utils ***** function _msgSender() public view returns (address) { return msg.sender; } // ***** Signed Payloads Utils ***** function hashOpenPositionPayload( UserRequestPayload_OpenPosition memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(REQUEST_PAYLOAD_OPEN_POSITION_TYPE_DESCRIPTOR)), payload.nonce, hashPositionRequestIdentifiers(payload.positionRequestIdentifiers), hashPositionRequestParams(payload.positionRequestParams), payload.orderType ) ); } function hashPositionRequestIdentifiers( ITradingFloorV1.PositionRequestIdentifiers memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(POSITION_REQUEST_IDENTIFIERS_TYPE_DESCRIPTOR)), payload.trader, payload.pairId, payload.settlementAsset, payload.positionIndex ) ); } function hashPositionRequestParams( ITradingFloorV1.PositionRequestParams memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(POSITION_REQUEST_PARAMS_TYPE_DESCRIPTOR)), payload.long, payload.collateral, payload.leverage, payload.minPrice, payload.maxPrice, payload.tp, payload.sl, payload.tpByFraction, payload.slByFraction ) ); } function hashCloseMarketPayload( UserRequestPayload_CloseMarket memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256(bytes(REQUEST_PAYLOAD_CLOSE_MARKET_TYPE_DESCRIPTOR)), payload.nonce, payload.positionId, payload.minPrice, payload.maxPrice ) ); } function hashUpdatePositionSingleFieldPayload( UserRequestPayload_UpdatePositionSingleField memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256( bytes(REQUEST_PAYLOAD_UPDATE_POSITION_SINGLE_FIELD_TYPE_DESCRIPTOR) ), payload.nonce, payload.positionId, payload.orderType, payload.fieldValue ) ); } function hashUpdatePositionDoubleFieldPayload( UserRequestPayload_UpdatePositionDoubleField memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256( bytes(REQUEST_PAYLOAD_UPDATE_POSITION_DOUBLE_FIELD_TYPE_DESCRIPTOR) ), payload.nonce, payload.positionId, payload.orderType, payload.fieldValueA, payload.fieldValueB ) ); } function hashUpdatePendingLimitPositionPayload( UserDirectPayload_UpdatePendingLimitPosition memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256( bytes(DIRECT_PAYLOAD_UPDATE_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR) ), payload.nonce, payload.positionId, payload.minPrice, payload.maxPrice, payload.tp, payload.sl ) ); } function hashCancelPendingLimitPositionPayload( UserDirectPayload_CancelPendingLimitPosition memory payload ) internal pure returns (bytes32) { return keccak256( abi.encode( keccak256( bytes(DIRECT_PAYLOAD_CANCEL_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR) ), payload.nonce, payload.positionId ) ); } }
// 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 HashAndActionSerialNonceBase * @notice Base contract for managing serial nonces for actions per id */ contract HashAndActionSerialNonceBase { // ***** Storage ***** // id => action type => nonce mapping(bytes32 => mapping(uint8 => uint256)) public nonceMap; // ***** Views ***** /** * @notice Get the next valid nonce for an action type * @param id The id * @param actionType The action type * @return The next valid nonce */ function getNextValidNonceFor( bytes32 id, uint8 actionType ) external view returns (uint256) { return nonceMap[id][actionType]; } // ***** Internal ***** /** * @notice Validate the nonce for an action type and increase the nonce * @param id The id * @param actionType The action type * @param nonce The nonce */ function validateNonceForActionAndIncrease( bytes32 id, uint8 actionType, uint256 nonce ) internal { uint256 currentNonceMapValue = nonceMap[id][actionType]; require(nonce == currentNonceMapValue, "INCORRECT_NONCE"); nonceMap[id][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 "./ITokenV1.sol"; import "./OrderBookStructsV1.sol"; import "./TradingFloorStructsV1.sol"; interface IOrderBookFunctionalityV1 is OrderBookStructsV1 { // Update Position Orders function storeUpdatePositionSingleFieldOrder( bytes32 _positionId, UpdatePositionFieldOrderType orderType, uint64 fieldValue ) external returns (UpdatePositionFieldOrder memory); function storeUpdatePositionDoubleFieldOrder( bytes32 _positionId, UpdatePositionFieldOrderType orderType, uint64 fieldValueA, uint64 fieldValueB ) external returns (UpdatePositionFieldOrder memory); function readAndDeleteUpdatePositionOrder( bytes32 _positionId ) external returns (UpdatePositionFieldOrder memory order); } interface IOrderBookV1 is IOrderBookFunctionalityV1 { function PRECISION() external pure returns (uint); // *** Public Storage addresses *** function tradingFloor() external view returns (address); // *** Public Storage params *** function pendingUpdateTradeFieldOrdersById( bytes32 positionId ) external view returns (UpdatePositionFieldOrder memory); }
// 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; import "./ITradingFloorV1.sol"; import "./IOrderBookV1.sol"; interface ITradersPortalV1Functionality { function traderRequest_openNewPosition( ITradingFloorV1.PositionRequestIdentifiers calldata positionRequestIdentifiers, ITradingFloorV1.PositionRequestParams calldata positionRequestParams, ITradingFloorV1.OpenOrderType orderType, bytes32 domain, bytes32 referralCode, bool runCapTests ) external payable returns (bytes32); function traderRequest_marketClosePosition( bytes32 _positionId, uint64 _minPrice, uint64 _maxPrice ) external payable; function traderRequest_updatePositionSingleField( bytes32 _positionId, OrderBookStructsV1.UpdatePositionFieldOrderType orderType, uint64 fieldValue ) external payable; function traderRequest_updatePositionDoubleField( bytes32 _positionId, OrderBookStructsV1.UpdatePositionFieldOrderType orderType, uint64 fieldValueA, uint64 fieldValueB ) external payable; function directAction_updatePendingPosition_limit( bytes32 positionId, uint64 minPrice, uint64 maxPrice, uint64 tp, uint64 sl ) external; function directAction_cancelPendingPosition_limit( bytes32 _positionId ) external; } interface ITradersPortalV1 is ITradersPortalV1Functionality { // **** Public Storage params **** function tradingFloor() external view returns (address); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.8.24; import "./TradingFloorStructsV1.sol"; import "./IPoolAccountantV1.sol"; import "./ILexPoolV1.sol"; interface ITradingFloorV1Functionality is TradingFloorStructsV1 { function supportNewSettlementAsset( address _asset, address _lexPool, address _poolAccountant ) external; function getPositionTriggerInfo( bytes32 _positionId ) external view returns ( PositionPhase positionPhase, uint64 timestamp, uint16 pairId, bool long, uint32 spreadReductionF ); function getPositionPortalInfo( bytes32 _positionId ) external view returns ( PositionPhase positionPhase, uint64 inPhaseSince, address positionTrader ); function storePendingPosition( OpenOrderType _orderType, PositionRequestIdentifiers memory _requestIdentifiers, PositionRequestParams memory _requestParams, uint32 _spreadReductionF ) external returns (bytes32 positionId); function setOpenedPositionToMarketClose( bytes32 _positionId, uint64 _minPrice, uint64 _maxPrice ) external; function cancelPendingPosition( bytes32 _positionId, OpenOrderType _orderType, uint feeFraction ) external; function cancelMarketCloseForPosition( bytes32 _positionId, CloseOrderType _orderType, uint feeFraction ) external; function updatePendingPosition_openLimit( bytes32 _positionId, uint64 _minPrice, uint64 _maxPrice, uint64 _tp, uint64 _sl ) external; function openNewPosition_market( bytes32 _positionId, uint64 assetEffectivePrice, uint256 feeForCancellation ) external; function openNewPosition_limit( bytes32 _positionId, uint64 assetEffectivePrice, uint256 feeForCancellation ) external; function closeExistingPosition_Market( bytes32 _positionId, uint64 assetPrice, uint64 effectivePrice ) external; function closeExistingPosition_Limit( bytes32 _positionId, LimitTrigger limitTrigger, uint64 assetPrice, uint64 effectivePrice ) external; // Manage open trade function updateOpenedPosition( bytes32 _positionId, PositionField updateField, uint64 fieldValue, uint64 effectivePrice ) external; // Fees function collectFee(address _asset, FeeType _feeType, address _to) external; } interface ITradingFloorV1 is ITradingFloorV1Functionality { function PRECISION() external pure returns (uint); // *** Views *** function pairTradersArray( address _asset, uint _pairIndex ) external view returns (address[] memory); function generatePositionHashId( address settlementAsset, address trader, uint16 pairId, uint32 index ) external pure returns (bytes32 hashId); // *** Public Storage addresses *** function lexPoolForAsset(address asset) external view returns (ILexPoolV1); function poolAccountantForAsset( address asset ) external view returns (IPoolAccountantV1); function registry() external view returns (address); // *** Public Storage params *** function positionsById(bytes32 id) external view returns (Position memory); function positionIdentifiersById( bytes32 id ) external view returns (PositionIdentifiers memory); function positionLimitsInfoById( bytes32 id ) external view returns (PositionLimitsInfo memory); function triggerPricesById( bytes32 id ) external view returns (PositionTriggerPrices memory); function pairTradersInfo( address settlementAsset, address trader, uint pairId ) external view returns (PairTraderInfo memory); function spreadReductionsP(uint) external view returns (uint); function maxSlF() external view returns (uint); function maxTradesPerPair() external view returns (uint); function maxSanityProfitF() external view returns (uint); function feesMap( address settlementAsset, FeeType feeType ) external view returns (uint256); }
// 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; // import "./ITokenV1.sol"; import "./TradingFloorStructsV1.sol"; interface OrderBookStructsV1 { enum UpdatePositionFieldOrderType { NONE, UPDATE_TP, UPDATE_SL, UPDATE_TP_AND_SL } struct UpdatePositionFieldOrder { // Slot 0 bytes32 positionId; // 32 bytes // Slot 1 UpdatePositionFieldOrderType orderType; // 01 bytes uint64 timestamp; // 08 bytes uint64 fieldValueA; // 08 bytes uint64 fieldValueB; // 08 bytes } }
// 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 "./TradingEnumsV1.sol"; interface TradingFloorStructsV1 is TradingEnumsV1 { enum AdminNumericParam { NONE, MAX_TRADES_PER_PAIR, MAX_SL_F, MAX_SANITY_PROFIT_F } /** * @dev Memory struct for identifiers */ struct PositionRequestIdentifiers { address trader; uint16 pairId; address settlementAsset; uint32 positionIndex; } struct PositionRequestParams { bool long; uint256 collateral; // Settlement Asset Decimals uint32 leverage; uint64 minPrice; // PRICE_SCALE uint64 maxPrice; // PRICE_SCALE uint64 tp; // PRICE_SCALE uint64 sl; // PRICE_SCALE uint64 tpByFraction; // FRACTION_SCALE uint64 slByFraction; // FRACTION_SCALE } /** * @dev Storage struct for identifiers */ struct PositionIdentifiers { // Slot 0 address settlementAsset; // 20 bytes uint16 pairId; // 02 bytes uint32 index; // 04 bytes // Slot 1 address trader; // 20 bytes } struct Position { // Slot 0 uint collateral; // 32 bytes -- Settlement Asset Decimals // Slot 1 PositionPhase phase; // 01 bytes uint64 inPhaseSince; // 08 bytes uint32 leverage; // 04 bytes bool long; // 01 bytes uint64 openPrice; // 08 bytes -- PRICE_SCALE (8) uint32 spreadReductionF; // 04 bytes -- FRACTION_SCALE (5) } /** * Holds the non liquidation limits for the position */ struct PositionLimitsInfo { uint64 tpLastUpdated; // 08 bytes -- timestamp uint64 slLastUpdated; // 08 bytes -- timestamp uint64 tp; // 08 bytes -- PRICE_SCALE (8) uint64 sl; // 08 bytes -- PRICE_SCALE (8) } /** * Holds the prices for opening (and market closing) of a position */ struct PositionTriggerPrices { uint64 minPrice; // 08 bytes -- PRICE_SCALE uint64 maxPrice; // 08 bytes -- PRICE_SCALE uint64 tpByFraction; // 04 bytes -- FRACTION_SCALE uint64 slByFraction; // 04 bytes -- FRACTION_SCALE } /** * @dev administration struct, used to keep tracks on the 'PairTraders' list and * to limit the amount of positions a trader can have */ struct PairTraderInfo { uint32 positionsCounter; // 04 bytes uint32 positionInArray; // 04 bytes (the index + 1) // Note : Can add more fields here } }
// 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":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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"enum TradeIntentsVerifierV1.TradeIntentsVerifierActions","name":"action","type":"uint8"},{"indexed":false,"internalType":"bytes32","name":"positionId","type":"bytes32"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"TradeIntentVerified","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":"DIRECT_PAYLOAD_CANCEL_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DIRECT_PAYLOAD_UPDATE_PENDING_LIMIT_POSITION_TYPE_DESCRIPTOR","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":"POSITION_REQUEST_IDENTIFIERS_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"POSITION_REQUEST_PARAMS_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_CLOSE_MARKET_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_OPEN_POSITION_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_UPDATE_POSITION_DOUBLE_FIELD_TYPE_DESCRIPTOR","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REQUEST_PAYLOAD_UPDATE_POSITION_SINGLE_FIELD_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":"bytes32","name":"","type":"bytes32"}],"name":"domainSeparatorsForPosition","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"id","type":"bytes32"},{"internalType":"uint8","name":"actionType","type":"uint8"}],"name":"getNextValidNonceFor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTradersPortal","outputs":[{"internalType":"contract ITradersPortalV1","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTradingFloor","outputs":[{"internalType":"contract ITradingFloorV1","name":"","type":"address"}],"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":"bytes32","name":"","type":"bytes32"},{"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":"bytes32","name":"positionId","type":"bytes32"}],"internalType":"struct TradeIntentsVerifierV1.UserDirectPayload_CancelPendingLimitPosition","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":"recoverCancelPendingLimitPositionSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_CloseMarket","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":"recoverCloseMarketPayloadSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"components":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"uint16","name":"pairId","type":"uint16"},{"internalType":"address","name":"settlementAsset","type":"address"},{"internalType":"uint32","name":"positionIndex","type":"uint32"}],"internalType":"struct TradingFloorStructsV1.PositionRequestIdentifiers","name":"positionRequestIdentifiers","type":"tuple"},{"components":[{"internalType":"bool","name":"long","type":"bool"},{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint32","name":"leverage","type":"uint32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"},{"internalType":"uint64","name":"tp","type":"uint64"},{"internalType":"uint64","name":"sl","type":"uint64"},{"internalType":"uint64","name":"tpByFraction","type":"uint64"},{"internalType":"uint64","name":"slByFraction","type":"uint64"}],"internalType":"struct TradingFloorStructsV1.PositionRequestParams","name":"positionRequestParams","type":"tuple"},{"internalType":"enum TradingEnumsV1.OpenOrderType","name":"orderType","type":"uint8"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_OpenPosition","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":"recoverOpenPositionPayloadSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"},{"internalType":"uint64","name":"tp","type":"uint64"},{"internalType":"uint64","name":"sl","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserDirectPayload_UpdatePendingLimitPosition","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":"recoverUpdatePendingLimitPositionSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"enum OrderBookStructsV1.UpdatePositionFieldOrderType","name":"orderType","type":"uint8"},{"internalType":"uint64","name":"fieldValueA","type":"uint64"},{"internalType":"uint64","name":"fieldValueB","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_UpdatePositionDoubleField","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":"recoverUpdatePositionDoubleFieldPayloadSigner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"enum OrderBookStructsV1.UpdatePositionFieldOrderType","name":"orderType","type":"uint8"},{"internalType":"uint64","name":"fieldValue","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_UpdatePositionSingleField","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":"recoverUpdatePositionSingleFieldPayloadSigner","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":"bytes32","name":"","type":"bytes32"}],"name":"settlementAssetsForPosition","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","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":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"tradersForPosition","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"}],"internalType":"struct TradeIntentsVerifierV1.UserDirectPayload_CancelPendingLimitPosition","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_traderAction_cancelPendingLimitPosition","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"},{"internalType":"uint64","name":"tp","type":"uint64"},{"internalType":"uint64","name":"sl","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserDirectPayload_UpdatePendingLimitPosition","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_traderAction_updatePendingLimitPosition","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_CloseMarket","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_traderRequest_marketClosePosition","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"components":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"uint16","name":"pairId","type":"uint16"},{"internalType":"address","name":"settlementAsset","type":"address"},{"internalType":"uint32","name":"positionIndex","type":"uint32"}],"internalType":"struct TradingFloorStructsV1.PositionRequestIdentifiers","name":"positionRequestIdentifiers","type":"tuple"},{"components":[{"internalType":"bool","name":"long","type":"bool"},{"internalType":"uint256","name":"collateral","type":"uint256"},{"internalType":"uint32","name":"leverage","type":"uint32"},{"internalType":"uint64","name":"minPrice","type":"uint64"},{"internalType":"uint64","name":"maxPrice","type":"uint64"},{"internalType":"uint64","name":"tp","type":"uint64"},{"internalType":"uint64","name":"sl","type":"uint64"},{"internalType":"uint64","name":"tpByFraction","type":"uint64"},{"internalType":"uint64","name":"slByFraction","type":"uint64"}],"internalType":"struct TradingFloorStructsV1.PositionRequestParams","name":"positionRequestParams","type":"tuple"},{"internalType":"enum TradingEnumsV1.OpenOrderType","name":"orderType","type":"uint8"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_OpenPosition","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"},{"internalType":"bool","name":"runCapTests","type":"bool"}],"name":"verifyIntent_traderRequest_openNewPosition","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"enum OrderBookStructsV1.UpdatePositionFieldOrderType","name":"orderType","type":"uint8"},{"internalType":"uint64","name":"fieldValueA","type":"uint64"},{"internalType":"uint64","name":"fieldValueB","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_UpdatePositionDoubleField","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_traderRequest_updatePositionDoubleField","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"bytes32","name":"positionId","type":"bytes32"},{"internalType":"enum OrderBookStructsV1.UpdatePositionFieldOrderType","name":"orderType","type":"uint8"},{"internalType":"uint64","name":"fieldValue","type":"uint64"}],"internalType":"struct TradeIntentsVerifierV1.UserRequestPayload_UpdatePositionSingleField","name":"payload","type":"tuple"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"verifyIntent_traderRequest_updatePositionSingleField","outputs":[],"stateMutability":"payable","type":"function"}]
Contract Creation Code
60a06040523480156200001157600080fd5b5060405162003c5e38038062003c5e833981016040819052620000349162000115565b604080518082018252601681527f547261646520496e74656e747320566572696669657200000000000000000000602080830191909152825180840190935260018352603160f81b90830152600080546001600160a01b031916331790559081816002620000a38382620001ee565b506003620000b28282620001ee565b5050506001600160a01b03831691506200010390505760405162461bcd60e51b815260206004820152600c60248201526b57524f4e475f504152414d5360a01b604482015260640160405180910390fd5b6001600160a01b0316608052620002ba565b6000602082840312156200012857600080fd5b81516001600160a01b03811681146200014057600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c908216806200017257607f821691505b6020821081036200019357634e487b7160e01b600052602260045260246000fd5b50919050565b601f821115620001e9576000816000526020600020601f850160051c81016020861015620001c45750805b601f850160051c820191505b81811015620001e557828155600101620001d0565b5050505b505050565b81516001600160401b038111156200020a576200020a62000147565b62000222816200021b84546200015d565b8462000199565b602080601f8311600181146200025a5760008415620002415750858301515b600019600386901b1c1916600185901b178555620001e5565b600085815260208120601f198616915b828110156200028b578886015182559484019460019091019084016200026a565b5085821015620002aa5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b608051613973620002eb6000396000818161056b01528181610dc9015281816117760152611df001526139736000f3fe60806040526004361061025c5760003560e01c80637b10399911610144578063b71d1a0c116100b6578063e9c714f21161007a578063e9c714f214610755578063eb56eef81461076a578063f07482b41461078a578063f2d515bd1461079f578063f851a440146107b2578063fbc8349e146107d257600080fd5b8063b71d1a0c146106a1578063ba83462d146106c1578063c49f91d3146106ee578063c8b82f7314610722578063e519b7671461073557600080fd5b80639652a4bd116101085780639652a4bd146105ec5780639d44332714610601578063a3ace82614610621578063a55cdb7914610657578063a5f0788214610677578063a90c599b1461068c57600080fd5b80637b103999146105595780637c28fe641461058d57806385813c6e146105a25780638e98bcdd146105c257806390b28139146105d757600080fd5b806323c059c4116101dd5780634b43c4f8116101a15780634b43c4f8146104765780634d7f3d2d146104ae57806355afba4a146104e457806358659d6e146104f95780636fccbffc146105195780637407cad51461054657600080fd5b806323c059c4146103e157806326782247146104015780633f8025d2146104215780633febb98914610441578063475d6ef31461046157600080fd5b8063108c66e311610224578063108c66e314610304578063119df25f1461034457806312d99fd11461036b57806316e27a7c1461038b5780631fab1801146103ce57600080fd5b80630193166c14610261578063064ab2d0146102765780630d981894146102895780630da7fba9146102b45780630f2a3d47146102c9575b600080fd5b61027461026f36600461256c565b6107e7565b005b61027461028436600461256c565b61096d565b34801561029557600080fd5b5061029e610a88565b6040516102ab91906125d3565b60405180910390f35b3480156102c057600080fd5b5061029e610aa4565b3480156102d557600080fd5b506102f66102e436600461261e565b60066020526000908152604090205481565b6040519081526020016102ab565b34801561031057600080fd5b5061029e60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525081565b34801561035057600080fd5b50335b6040516001600160a01b0390911681526020016102ab565b34801561037757600080fd5b5061027461038636600461263b565b610b32565b34801561039757600080fd5b506102f66103a636600461261e565b6001600160a01b03166000908152600660209081526040808320548352600490915290205490565b6102746103dc366004612679565b610b87565b3480156103ed57600080fd5b506103536103fc3660046126cf565b610cb3565b34801561040d57600080fd5b50600154610353906001600160a01b031681565b34801561042d57600080fd5b5061035361043c36600461272f565b610d6a565b34801561044d57600080fd5b506102f661045c366004612780565b610d85565b34801561046d57600080fd5b5061029e610da9565b34801561048257600080fd5b506102f6610491366004612780565b600760209081526000928352604080842090915290825290205481565b3480156104ba57600080fd5b506103536104c93660046127ac565b6009602052600090815260409020546001600160a01b031681565b3480156104f057600080fd5b50610353610dc5565b34801561050557600080fd5b506102746105143660046127c5565b610e4e565b34801561052557600080fd5b506102f66105343660046127ac565b60046020526000908152604090205481565b610274610554366004612849565b610ebe565b34801561056557600080fd5b506103537f000000000000000000000000000000000000000000000000000000000000000081565b34801561059957600080fd5b5061029e61101e565b3480156105ae57600080fd5b506103536105bd36600461288e565b61103a565b3480156105ce57600080fd5b5061029e611055565b3480156105e357600080fd5b5061029e611074565b3480156105f857600080fd5b5061029e611090565b34801561060d57600080fd5b5061029e61061c36600461261e565b61109d565b34801561062d57600080fd5b5061035361063c3660046127ac565b600a602052600090815260409020546001600160a01b031681565b34801561066357600080fd5b5061035361067236600461288e565b6110b6565b34801561068357600080fd5b5061029e6110d1565b34801561069857600080fd5b5061029e6110ed565b3480156106ad57600080fd5b506102746106bc36600461261e565b611109565b3480156106cd57600080fd5b506102f66106dc3660046127ac565b60086020526000908152604090205481565b3480156106fa57600080fd5b506102f67f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81565b610274610730366004612909565b6111b1565b34801561074157600080fd5b5061035361075036600461297f565b61150c565b34801561076157600080fd5b50610274611527565b34801561077657600080fd5b506103536107853660046129cf565b611645565b34801561079657600080fd5b5061029e611660565b6102746107ad366004612a22565b61167c565b3480156107be57600080fd5b50600054610353906001600160a01b031681565b3480156107de57600080fd5b50610353611772565b3233146107f357600080fd5b6000806108038660200135611833565b915091506000610816878787878761103a565b9050806001600160a01b0316826001600160a01b031614806108425750610842876020013583836119da565b6108675760405162461bcd60e51b815260040161085e90612a65565b60405180910390fd5b610879602088013560025b89356119fe565b610881610dc5565b6001600160a01b031663719683ea3460208a01356108a560608c0160408d01612ac0565b6108b560808d0160608e01612ac0565b6040516001600160e01b031960e087901b16815260048101939093526001600160401b0391821660248401521660448201526064016000604051808303818588803b15801561090357600080fd5b505af1158015610917573d6000803e3d6000fd5b506002935061092592505050565b6040805160208a81013582528a359082015233917fd7793dfee69185c798d1c6d1d457aba44c8fb6c6465e8f0cce60d56ce07fc212910160405180910390a350505050505050565b32331461097957600080fd5b6000806109898660200135611833565b91509150600061099c87878787876110b6565b9050806001600160a01b0316826001600160a01b031614806109c857506109c8876020013583836119da565b6109e45760405162461bcd60e51b815260040161085e90612a65565b6109f360208801356003610872565b6109fb610dc5565b6001600160a01b0316631d3e4d463460208a0135610a1f60608c0160408d01612aea565b610a2f60808d0160608e01612ac0565b6040518563ffffffff1660e01b8152600401610a4d93929190612b15565b6000604051808303818588803b158015610a6657600080fd5b505af1158015610a7a573d6000803e3d6000fd5b506003935061092592505050565b6040518060800160405280606081526020016138de6060913981565b60028054610ab190612b42565b80601f0160208091040260200160405190810160405280929190818152602001828054610add90612b42565b8015610b2a5780601f10610aff57610100808354040283529160200191610b2a565b820191906000526020600020905b815481529060010190602001808311610b0d57829003601f168201915b505050505081565b6000546001600160a01b03163314610b795760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b604482015260640161085e565b610b838282611a8e565b5050565b323314610b9357600080fd5b600080610ba38660200135611833565b915091506000610bb6878787878761150c565b9050806001600160a01b0316826001600160a01b03161480610be25750610be2876020013583836119da565b610bfe5760405162461bcd60e51b815260040161085e90612a65565b610c0d60208801356004610872565b610c15610dc5565b6001600160a01b0316636b8b5e223460208a0135610c3960608c0160408d01612aea565b610c4960808d0160608e01612ac0565b610c5960a08e0160808f01612ac0565b6040518663ffffffff1660e01b8152600401610c789493929190612b76565b6000604051808303818588803b158015610c9157600080fd5b505af1158015610ca5573d6000803e3d6000fd5b506004935061092592505050565b60008082610cce610cc9368a90038a018a612c0c565b611b93565b60405161190160f01b60208201526022810192909252604282015260620160408051601f1981840301815282825280516020918201206000845290830180835281905260ff8916918301919091526060820187905260808201869052915060019060a0016020604051602081039080840390855afa158015610d54573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b60008082610cce610d80368a90038a018a612c5a565b611bf1565b600082815260076020908152604080832060ff851684529091529020545b92915050565b6040518060c001604052806082815260200161385c6082913981565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fab337046040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e499190612cec565b905090565b6000546001600160a01b03163314610e955760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b604482015260640161085e565b6001600160a01b0383166000908152600560205260409020610eb8828483612d5a565b50505050565b323314610eca57600080fd5b600080610eda8660200135611833565b915091506000610eed8787878787610d6a565b9050806001600160a01b0316826001600160a01b03161480610f195750610f19876020013583836119da565b610f355760405162461bcd60e51b815260040161085e90612a65565b610f4460208801356005610872565b610f4c610dc5565b6001600160a01b031663f86d29486020890135610f6f60608b0160408c01612ac0565b610f7f60808c0160608d01612ac0565b610f8f60a08d0160808e01612ac0565b610f9f60c08e0160a08f01612ac0565b6040516001600160e01b031960e088901b16815260048101959095526001600160401b03938416602486015291831660448501528216606484015216608482015260a401600060405180830381600087803b158015610ffd57600080fd5b505af1158015611011573d6000803e3d6000fd5b5060059250610925915050565b6040518060800160405280604e815260200161380e604e913981565b60008082610cce611050368a90038a018a612e1a565b611c76565b604051806101e001604052806101a4815260200161366a6101a4913981565b6040518060a00160405280606581526020016136056065913981565b60038054610ab190612b42565b60056020526000908152604090208054610ab190612b42565b60008082610cce6110cc368a90038a018a612e6b565b611cdc565b6040518060c00160405280609f8152602001613566609f913981565b6040518060a00160405280607081526020016134f66070913981565b6000546001600160a01b0316331461114f5760405162461bcd60e51b81526020600482015260096024820152682737ba1020b236b4b760b91b604482015260640161085e565b600180546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991015b60405180910390a15050565b3233146111bd57600080fd5b60006111d76111d260808a0160608b0161261e565b611d1f565b905060006111e88989898986611645565b90506001600160a01b03811661120460408b0160208c0161261e565b6001600160a01b0316148061123d575061123d61122760808b0160608c0161261e565b61123760408c0160208d0161261e565b83611d33565b6112595760405162461bcd60e51b815260040161085e90612a65565b6000611263611772565b6001600160a01b031663a40d726861128160808d0160608e0161261e565b61129160408e0160208f0161261e565b8d60200160200160208101906112a79190612eaf565b8e60200160600160208101906112bd9190612ee9565b6040516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909216602484015261ffff16604483015263ffffffff166064820152608401602060405180830381865afa15801561131e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113429190612f06565b90506113518160018c356119fe565b600061135b610dc5565b6001600160a01b03166344176266348d6020018e60a0018f6101c00160208101906113869190612f2e565b8c8c8c6040518863ffffffff1660e01b81526004016113aa96959493929190612f5d565b60206040518083038185885af11580156113c8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906113ed9190612f06565b90508181146114375760405162461bcd60e51b815260206004820152601660248201527515539156141150d5115117d413d4d2551253d397d25160521b604482015260640161085e565b60008181526008602090815260409182902086905561145a918d01908d0161261e565b600082815260096020526040902080546001600160a01b0319166001600160a01b039290921691909117905561149660808c0160608d0161261e565b6000828152600a6020526040902080546001600160a01b0319166001600160a01b03929092169190911790556001604080518381528d35602082015233917fd7793dfee69185c798d1c6d1d457aba44c8fb6c6465e8f0cce60d56ce07fc212910160405180910390a35050505050505050505050565b60008082610cce611522368a90038a018a6130e9565b611f5f565b6001546001600160a01b03163314801561154b57506001546001600160a01b031615155b6115975760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420746865204558495354494e472070656e64696e672061646d696e0000604482015260640161085e565b60008054600180546001600160a01b038082166001600160a01b031980861682179096559490911690915560408051919092168082526020820184905292917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc910160405180910390a1600154604080516001600160a01b03808516825290921660208301527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991016111a5565b60008082610cce61165b368a90038a018a61321a565b611fa8565b6040518060c00160405280608481526020016134726084913981565b32331461168857600080fd5b6000806116988660200135611833565b9150915060006116ab8787878787610cb3565b9050806001600160a01b0316826001600160a01b031614806116d757506116d7876020013583836119da565b6116f35760405162461bcd60e51b815260040161085e90612a65565b61170260208801356006610872565b61170a610dc5565b60405163568b6add60e01b8152602089013560048201526001600160a01b03919091169063568b6add90602401600060405180830381600087803b15801561175157600080fd5b505af1158015611765573d6000803e3d6000fd5b5060069250610925915050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663fab337046040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f69190612cec565b6001600160a01b0316630d3b0b766040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b6000818152600860209081526040808320546009909252909120546001600160a01b031681158061186b57506001600160a01b038116155b156119d557600061187a611772565b60405163042e37c560e01b8152600481018690529091506000906001600160a01b0383169063042e37c590602401608060405180830381865afa1580156118c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e991906132d2565b90506118f88160000151611d1f565b606082015190945092508361194f5760405162461bcd60e51b815260206004820152601d60248201527f4e4f5f444f4d41494e5f534550415241544f525f464f525f434841494e000000604482015260640161085e565b6001600160a01b03831661199e5760405162461bcd60e51b81526020600482015260166024820152752727afaa2920a222a92fa327a92fa827a9a4aa24a7a760511b604482015260640161085e565b505060008381526008602090815260408083208590556009909152902080546001600160a01b0319166001600160a01b0383161790555b915091565b6000806119e685612005565b90506119f3818585611d33565b9150505b9392505050565b600083815260076020908152604080832060ff86168452909152902054818114611a5c5760405162461bcd60e51b815260206004820152600f60248201526e494e434f52524543545f4e4f4e434560881b604482015260640161085e565b611a6781600161332d565b600094855260076020908152604080872060ff909616875294905292909320919091555050565b6001600160a01b03821660009081526006602052604090205415611b025760405162461bcd60e51b815260206004820152602560248201527f434841494e5f49445f464f525f41535345545f414c52454144595f434f4e464960448201526411d554915160da1b606482015260840161085e565b80600003611b425760405162461bcd60e51b815260206004820152600d60248201526c434841494e5f49445f5a45524f60981b604482015260640161085e565b611b4b81612113565b506001600160a01b038216600081815260066020526040808220849055518392917f8983e01eaf5771a114f1aa7f72a023a35642e048180682aa2fb04db0cbd220c291a35050565b60006040518060800160405280604e815260200161380e604e9139805160209182012083518483015160408051948501939093529183015260608201526080015b604051602081830303815290604052805190602001209050919050565b60006040518060c001604052806082815260200161385c6082913980516020918201208351848301516040808701516060808901516080808b015160a0808d015187519b8c019a909a52958a0197909752918801949094526001600160401b03918216908701529182169085015290811660c08401521660e082015261010001611bd4565b60006040518060800160405280606081526020016138de606091398051602091820120835184830151604080870151606080890151835197880196909652918601939093528401526001600160401b0390811660808401521660a082015260c001611bd4565b60006040518060a00160405280607081526020016134f660709139805160209182012083518483015160408087015160608801519151611bd4969192910161334e565b600080611d2b836122cc565b509392505050565b6001600160a01b03831660009081526005602052604081208054829190611d5990612b42565b80601f0160208091040260200160405190810160405280929190818152602001828054611d8590612b42565b8015611dd25780601f10611da757610100808354040283529160200191611dd2565b820191906000526020600020905b815481529060010190602001808311611db557829003601f168201915b505050505090508051600003611dec5760009150506119f7565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166358ca59ce60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525084604051602001611e5c92919061338b565b6040516020818303038152906040526040518263ffffffff1660e01b8152600401611e8791906125d3565b602060405180830381865afa158015611ea4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec89190612cec565b90506001600160a01b038116611ee3576000925050506119f7565b60405163b0cbc2e160e01b81526001600160a01b0382169063b0cbc2e190611f1490600190899089906004016133ba565b602060405180830381865afa158015611f31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5591906133e5565b9695505050505050565b60006040518060c0016040528060848152602001613472608491398051602091820120835184830151604080870151606088015160808901519251611bd4979293919201613402565b6000604051806101e001604052806101a4815260200161366a6101a49139805190602001208260000151611fdf8460200151612393565b611fec8560400151612406565b8560600151604051602001611bd4959493929190613447565b6000818152600a60205260409020546001600160a01b03168061210e5761202a611772565b6001600160a01b031663042e37c5836040518263ffffffff1660e01b815260040161205791815260200190565b608060405180830381865afa158015612074573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209891906132d2565b5190506001600160a01b0381166120e65760405162461bcd60e51b81526020600482015260126024820152712727afa9a0afa327a92fa827a9a4aa24a7a760711b604482015260640161085e565b6000828152600a6020526040902080546001600160a01b0319166001600160a01b0383161790555b919050565b60008181526004602052604081205480610da357600061226f60405180608001604052806002805461214490612b42565b80601f016020809104026020016040519081016040528092919081815260200182805461217090612b42565b80156121bd5780601f10612192576101008083540402835291602001916121bd565b820191906000526020600020905b8154815290600101906020018083116121a057829003601f168201915b50505050508152602001600380546121d490612b42565b80601f016020809104026020016040519081016040528092919081815260200182805461220090612b42565b801561224d5780601f106122225761010080835404028352916020019161224d565b820191906000526020600020905b81548152906001019060200180831161223057829003601f168201915b50505050508152602001868152602001306001600160a01b03168152506124c9565b600085815260046020526040908190208290555190915084907f04df087044a5490c34ea0092af5dbdd1a3a35fefd63f0864c1d05dba3075f165906122b79084815260200190565b60405180910390a29392505050565b50919050565b6001600160a01b038116600090815260066020526040812054819080820361232e5760405162461bcd60e51b81526020600482015260156024820152741393d7d0d210525397d25117d193d497d054d4d155605a1b604482015260640161085e565b6000818152600460205260409020548061238a5760405162461bcd60e51b815260206004820152601d60248201527f4e4f5f444f4d41494e5f534550415241544f525f464f525f434841494e000000604482015260640161085e565b94909350915050565b60006040518060a00160405280606581526020016136056065913980516020918201208351848301516040808701516060808901518351978801969096526001600160a01b039485169287019290925261ffff9092169085015216608083015263ffffffff1660a082015260c001611bd4565b60006040518060c00160405280609f8152602001613566609f913980519060200120826000015183602001518460400151856060015186608001518760a001518860c001518960e001518a6101000151604051602001611bd49a99989796959493929190998a5297151560208a0152604089019690965263ffffffff9490941660608801526001600160401b03928316608088015290821660a0870152811660c086015290811660e0850152908116610100840152166101208201526101400190565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82600001518051906020012083602001518051906020012084604001518560600151604051602001611bd49594939291909485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b6000608082840312156122c657600080fd5b803560ff8116811461210e57600080fd5b60008060008060e0858703121561258257600080fd5b61258c8686612549565b935061259a6080860161255b565b939693955050505060a08201359160c0013590565b60005b838110156125ca5781810151838201526020016125b2565b50506000910152565b60208152600082518060208401526125f28160408501602087016125af565b601f01601f19169190910160400192915050565b6001600160a01b038116811461261b57600080fd5b50565b60006020828403121561263057600080fd5b81356119f781612606565b6000806040838503121561264e57600080fd5b823561265981612606565b946020939093013593505050565b600060a082840312156122c657600080fd5b600080600080610100858703121561269057600080fd5b61269a8686612667565b93506126a860a0860161255b565b939693955050505060c08201359160e0013590565b6000604082840312156122c657600080fd5b600080600080600060c086880312156126e757600080fd5b6126f187876126bd565b94506126ff6040870161255b565b949794965050505060608301359260808101359260a0909101359150565b600060c082840312156122c657600080fd5b6000806000806000610140868803121561274857600080fd5b612752878761271d565b945061276060c0870161255b565b949794965050505060e08301359261010081013592610120909101359150565b6000806040838503121561279357600080fd5b823591506127a36020840161255b565b90509250929050565b6000602082840312156127be57600080fd5b5035919050565b6000806000604084860312156127da57600080fd5b83356127e581612606565b925060208401356001600160401b038082111561280157600080fd5b818601915086601f83011261281557600080fd5b81358181111561282457600080fd5b87602082850101111561283657600080fd5b6020830194508093505050509250925092565b600080600080610120858703121561286057600080fd5b61286a868661271d565b935061287860c0860161255b565b939693955050505060e082013591610100013590565b600080600080600061010086880312156128a757600080fd5b6128b18787612549565b94506128bf6080870161255b565b949794965050505060a08301359260c08101359260e0909101359150565b60006101e082840312156122c657600080fd5b801515811461261b57600080fd5b803561210e816128f0565b60008060008060008060006102a0888a03121561292557600080fd5b61292f89896128dd565b965061293e6101e0890161255b565b9550610200880135945061022088013593506102408801359250610260880135915061028088013561296f816128f0565b8091505092959891949750929550565b6000806000806000610120868803121561299857600080fd5b6129a28787612667565b94506129b060a0870161255b565b949794965050505060c08301359260e081013592610100909101359150565b600080600080600061026086880312156129e857600080fd5b6129f287876128dd565b9450612a016101e0870161255b565b94979496505050506102008301359261022081013592610240909101359150565b60008060008060a08587031215612a3857600080fd5b612a4286866126bd565b9350612a506040860161255b565b93969395505050506060820135916080013590565b6020808252601490820152732727aa2fa9a4a3a722a22fa12cafaa2920a222a960611b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b80356001600160401b038116811461210e57600080fd5b600060208284031215612ad257600080fd5b6119f782612aa9565b80356004811061210e57600080fd5b600060208284031215612afc57600080fd5b6119f782612adb565b6004811061261b5761261b612a93565b83815260608101612b2584612b05565b8360208301526001600160401b0383166040830152949350505050565b600181811c90821680612b5657607f821691505b6020821081036122c657634e487b7160e01b600052602260045260246000fd5b84815260808101612b8685612b05565b60208201949094526001600160401b0392831660408201529116606090910152919050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715612be357612be3612bab565b60405290565b60405161012081016001600160401b0381118282101715612be357612be3612bab565b600060408284031215612c1e57600080fd5b604051604081018181106001600160401b0382111715612c4057612c40612bab565b604052823581526020928301359281019290925250919050565b600060c08284031215612c6c57600080fd5b60405160c081018181106001600160401b0382111715612c8e57612c8e612bab565b80604052508235815260208301356020820152612cad60408401612aa9565b6040820152612cbe60608401612aa9565b6060820152612ccf60808401612aa9565b6080820152612ce060a08401612aa9565b60a08201529392505050565b600060208284031215612cfe57600080fd5b81516119f781612606565b601f821115612d55576000816000526020600020601f850160051c81016020861015612d325750805b601f850160051c820191505b81811015612d5157828155600101612d3e565b5050505b505050565b6001600160401b03831115612d7157612d71612bab565b612d8583612d7f8354612b42565b83612d09565b6000601f841160018114612db95760008515612da15750838201355b600019600387901b1c1916600186901b178355612e13565b600083815260209020601f19861690835b82811015612dea5786850135825560209485019460019092019101612dca565b5086821015612e075760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b600060808284031215612e2c57600080fd5b612e34612bc1565b8235815260208301356020820152612e4e60408401612aa9565b6040820152612e5f60608401612aa9565b60608201529392505050565b600060808284031215612e7d57600080fd5b612e85612bc1565b8235815260208301356020820152612e4e60408401612adb565b61ffff8116811461261b57600080fd5b600060208284031215612ec157600080fd5b81356119f781612e9f565b63ffffffff8116811461261b57600080fd5b803561210e81612ecc565b600060208284031215612efb57600080fd5b81356119f781612ecc565b600060208284031215612f1857600080fd5b5051919050565b80356003811061210e57600080fd5b600060208284031215612f4057600080fd5b6119f782612f1f565b60038110612f5957612f59612a93565b9052565b61022081018735612f6d81612606565b6001600160a01b039081168352602089013590612f8982612e9f565b61ffff8216602085015260408a01359150612fa382612606565b1660408301526060880135612fb781612ecc565b63ffffffff1660608301528635612fcd816128f0565b15156080830152602087013560a08301526040870135612fec81612ecc565b63ffffffff1660c083015261300360608801612aa9565b6001600160401b031660e083015261301d60808801612aa9565b610100613034818501836001600160401b03169052565b61304060a08a01612aa9565b6001600160401b038116610120860152915061305e60c08a01612aa9565b6001600160401b038116610140860152915061307c60e08a01612aa9565b6001600160401b0381166101608601529150613099818a01612aa9565b9150506130b26101808401826001600160401b03169052565b506130c16101a0830187612f49565b846101c0830152836101e08301526130de61020083018415159052565b979650505050505050565b600060a082840312156130fb57600080fd5b60405160a081018181106001600160401b038211171561311d5761311d612bab565b8060405250823581526020830135602082015261313c60408401612adb565b604082015261314d60608401612aa9565b606082015261315e60808401612aa9565b60808201529392505050565b6000610120828403121561317d57600080fd5b613185612be9565b9050613190826128fe565b8152602082013560208201526131a860408301612ede565b60408201526131b960608301612aa9565b60608201526131ca60808301612aa9565b60808201526131db60a08301612aa9565b60a08201526131ec60c08301612aa9565b60c08201526131fd60e08301612aa9565b60e0820152610100613210818401612aa9565b9082015292915050565b60008183036101e081121561322e57600080fd5b613236612bc1565b833581526080601f198301121561324c57600080fd5b613254612bc1565b9150602084013561326481612606565b8252604084013561327481612e9f565b6020830152606084013561328781612606565b6040830152608084013561329a81612ecc565b6060830152602081018290526132b38560a0860161316a565b60408201526132c56101c08501612f1f565b6060820152949350505050565b6000608082840312156132e457600080fd5b6132ec612bc1565b82516132f781612606565b8152602083015161330781612e9f565b6020820152604083015161331a81612ecc565b60408201526060830151612e5f81612606565b80820180821115610da357634e487b7160e01b600052601160045260246000fd5b858152602081018590526040810184905260a0810161336c84612b05565b8360608301526001600160401b03831660808301529695505050505050565b6000835161339d8184602088016125af565b8351908301906133b18183602088016125af565b01949350505050565b606081016133c785612b05565b9381526001600160a01b039283166020820152911660409091015290565b6000602082840312156133f757600080fd5b81516119f7816128f0565b868152602081018690526040810185905260c0810161342085612b05565b60608201949094526001600160401b039283166080820152911660a0909101529392505050565b600060a082019050868252856020830152846040830152836060830152611f556080830184612f4956fe55736572526571756573745061796c6f61645f557064617465506f736974696f6e446f75626c654669656c642875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e7438206f72646572547970652c75696e743634206669656c6456616c7565412c75696e743634206669656c6456616c7565422955736572526571756573745061796c6f61645f557064617465506f736974696f6e53696e676c654669656c642875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e7438206f72646572547970652c75696e743634206669656c6456616c756529506f736974696f6e52657175657374506172616d7328626f6f6c206c6f6e672c75696e7432353620636f6c6c61746572616c2c75696e743332206c657665726167652c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2c75696e74363420747042794672616374696f6e2c75696e74363420736c42794672616374696f6e29506f736974696f6e526571756573744964656e746966696572732861646472657373207472616465722c75696e743136207061697249642c6164647265737320736574746c656d656e7441737365742c75696e74333220706f736974696f6e496e6465782955736572526571756573745061796c6f61645f4f70656e506f736974696f6e2875696e74323536206e6f6e63652c506f736974696f6e526571756573744964656e7469666965727320706f736974696f6e526571756573744964656e746966696572732c506f736974696f6e52657175657374506172616d7320706f736974696f6e52657175657374506172616d732c75696e7438206f726465725479706529506f736974696f6e526571756573744964656e746966696572732861646472657373207472616465722c75696e743136207061697249642c6164647265737320736574746c656d656e7441737365742c75696e74333220706f736974696f6e496e64657829506f736974696f6e52657175657374506172616d7328626f6f6c206c6f6e672c75696e7432353620636f6c6c61746572616c2c75696e743332206c657665726167652c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2c75696e74363420747042794672616374696f6e2c75696e74363420736c42794672616374696f6e29557365724469726563745061796c6f61645f43616e63656c50656e64696e674c696d6974506f736974696f6e2875696e74323536206e6f6e63652c6279746573333220706f736974696f6e496429557365724469726563745061796c6f61645f55706461746550656e64696e674c696d6974506f736974696f6e2875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2955736572526571756573745061796c6f61645f436c6f73654d61726b65742875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e743634206d696e50726963652c75696e743634206d6178507269636529a2646970667358221220d30dc2db59f6e82655196707b5df99c02eccfd9fcdc8c8207e8c7ddc2469a38564736f6c634300081800330000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c207
Deployed Bytecode
0x60806040526004361061025c5760003560e01c80637b10399911610144578063b71d1a0c116100b6578063e9c714f21161007a578063e9c714f214610755578063eb56eef81461076a578063f07482b41461078a578063f2d515bd1461079f578063f851a440146107b2578063fbc8349e146107d257600080fd5b8063b71d1a0c146106a1578063ba83462d146106c1578063c49f91d3146106ee578063c8b82f7314610722578063e519b7671461073557600080fd5b80639652a4bd116101085780639652a4bd146105ec5780639d44332714610601578063a3ace82614610621578063a55cdb7914610657578063a5f0788214610677578063a90c599b1461068c57600080fd5b80637b103999146105595780637c28fe641461058d57806385813c6e146105a25780638e98bcdd146105c257806390b28139146105d757600080fd5b806323c059c4116101dd5780634b43c4f8116101a15780634b43c4f8146104765780634d7f3d2d146104ae57806355afba4a146104e457806358659d6e146104f95780636fccbffc146105195780637407cad51461054657600080fd5b806323c059c4146103e157806326782247146104015780633f8025d2146104215780633febb98914610441578063475d6ef31461046157600080fd5b8063108c66e311610224578063108c66e314610304578063119df25f1461034457806312d99fd11461036b57806316e27a7c1461038b5780631fab1801146103ce57600080fd5b80630193166c14610261578063064ab2d0146102765780630d981894146102895780630da7fba9146102b45780630f2a3d47146102c9575b600080fd5b61027461026f36600461256c565b6107e7565b005b61027461028436600461256c565b61096d565b34801561029557600080fd5b5061029e610a88565b6040516102ab91906125d3565b60405180910390f35b3480156102c057600080fd5b5061029e610aa4565b3480156102d557600080fd5b506102f66102e436600461261e565b60066020526000908152604090205481565b6040519081526020016102ab565b34801561031057600080fd5b5061029e60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525081565b34801561035057600080fd5b50335b6040516001600160a01b0390911681526020016102ab565b34801561037757600080fd5b5061027461038636600461263b565b610b32565b34801561039757600080fd5b506102f66103a636600461261e565b6001600160a01b03166000908152600660209081526040808320548352600490915290205490565b6102746103dc366004612679565b610b87565b3480156103ed57600080fd5b506103536103fc3660046126cf565b610cb3565b34801561040d57600080fd5b50600154610353906001600160a01b031681565b34801561042d57600080fd5b5061035361043c36600461272f565b610d6a565b34801561044d57600080fd5b506102f661045c366004612780565b610d85565b34801561046d57600080fd5b5061029e610da9565b34801561048257600080fd5b506102f6610491366004612780565b600760209081526000928352604080842090915290825290205481565b3480156104ba57600080fd5b506103536104c93660046127ac565b6009602052600090815260409020546001600160a01b031681565b3480156104f057600080fd5b50610353610dc5565b34801561050557600080fd5b506102746105143660046127c5565b610e4e565b34801561052557600080fd5b506102f66105343660046127ac565b60046020526000908152604090205481565b610274610554366004612849565b610ebe565b34801561056557600080fd5b506103537f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c20781565b34801561059957600080fd5b5061029e61101e565b3480156105ae57600080fd5b506103536105bd36600461288e565b61103a565b3480156105ce57600080fd5b5061029e611055565b3480156105e357600080fd5b5061029e611074565b3480156105f857600080fd5b5061029e611090565b34801561060d57600080fd5b5061029e61061c36600461261e565b61109d565b34801561062d57600080fd5b5061035361063c3660046127ac565b600a602052600090815260409020546001600160a01b031681565b34801561066357600080fd5b5061035361067236600461288e565b6110b6565b34801561068357600080fd5b5061029e6110d1565b34801561069857600080fd5b5061029e6110ed565b3480156106ad57600080fd5b506102746106bc36600461261e565b611109565b3480156106cd57600080fd5b506102f66106dc3660046127ac565b60086020526000908152604090205481565b3480156106fa57600080fd5b506102f67f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81565b610274610730366004612909565b6111b1565b34801561074157600080fd5b5061035361075036600461297f565b61150c565b34801561076157600080fd5b50610274611527565b34801561077657600080fd5b506103536107853660046129cf565b611645565b34801561079657600080fd5b5061029e611660565b6102746107ad366004612a22565b61167c565b3480156107be57600080fd5b50600054610353906001600160a01b031681565b3480156107de57600080fd5b50610353611772565b3233146107f357600080fd5b6000806108038660200135611833565b915091506000610816878787878761103a565b9050806001600160a01b0316826001600160a01b031614806108425750610842876020013583836119da565b6108675760405162461bcd60e51b815260040161085e90612a65565b60405180910390fd5b610879602088013560025b89356119fe565b610881610dc5565b6001600160a01b031663719683ea3460208a01356108a560608c0160408d01612ac0565b6108b560808d0160608e01612ac0565b6040516001600160e01b031960e087901b16815260048101939093526001600160401b0391821660248401521660448201526064016000604051808303818588803b15801561090357600080fd5b505af1158015610917573d6000803e3d6000fd5b506002935061092592505050565b6040805160208a81013582528a359082015233917fd7793dfee69185c798d1c6d1d457aba44c8fb6c6465e8f0cce60d56ce07fc212910160405180910390a350505050505050565b32331461097957600080fd5b6000806109898660200135611833565b91509150600061099c87878787876110b6565b9050806001600160a01b0316826001600160a01b031614806109c857506109c8876020013583836119da565b6109e45760405162461bcd60e51b815260040161085e90612a65565b6109f360208801356003610872565b6109fb610dc5565b6001600160a01b0316631d3e4d463460208a0135610a1f60608c0160408d01612aea565b610a2f60808d0160608e01612ac0565b6040518563ffffffff1660e01b8152600401610a4d93929190612b15565b6000604051808303818588803b158015610a6657600080fd5b505af1158015610a7a573d6000803e3d6000fd5b506003935061092592505050565b6040518060800160405280606081526020016138de6060913981565b60028054610ab190612b42565b80601f0160208091040260200160405190810160405280929190818152602001828054610add90612b42565b8015610b2a5780601f10610aff57610100808354040283529160200191610b2a565b820191906000526020600020905b815481529060010190602001808311610b0d57829003601f168201915b505050505081565b6000546001600160a01b03163314610b795760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b604482015260640161085e565b610b838282611a8e565b5050565b323314610b9357600080fd5b600080610ba38660200135611833565b915091506000610bb6878787878761150c565b9050806001600160a01b0316826001600160a01b03161480610be25750610be2876020013583836119da565b610bfe5760405162461bcd60e51b815260040161085e90612a65565b610c0d60208801356004610872565b610c15610dc5565b6001600160a01b0316636b8b5e223460208a0135610c3960608c0160408d01612aea565b610c4960808d0160608e01612ac0565b610c5960a08e0160808f01612ac0565b6040518663ffffffff1660e01b8152600401610c789493929190612b76565b6000604051808303818588803b158015610c9157600080fd5b505af1158015610ca5573d6000803e3d6000fd5b506004935061092592505050565b60008082610cce610cc9368a90038a018a612c0c565b611b93565b60405161190160f01b60208201526022810192909252604282015260620160408051601f1981840301815282825280516020918201206000845290830180835281905260ff8916918301919091526060820187905260808201869052915060019060a0016020604051602081039080840390855afa158015610d54573d6000803e3d6000fd5b5050604051601f19015198975050505050505050565b60008082610cce610d80368a90038a018a612c5a565b611bf1565b600082815260076020908152604080832060ff851684529091529020545b92915050565b6040518060c001604052806082815260200161385c6082913981565b60007f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c2076001600160a01b031663fab337046040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e499190612cec565b905090565b6000546001600160a01b03163314610e955760405162461bcd60e51b815260206004820152600a60248201526927a7262cafa0a226a4a760b11b604482015260640161085e565b6001600160a01b0383166000908152600560205260409020610eb8828483612d5a565b50505050565b323314610eca57600080fd5b600080610eda8660200135611833565b915091506000610eed8787878787610d6a565b9050806001600160a01b0316826001600160a01b03161480610f195750610f19876020013583836119da565b610f355760405162461bcd60e51b815260040161085e90612a65565b610f4460208801356005610872565b610f4c610dc5565b6001600160a01b031663f86d29486020890135610f6f60608b0160408c01612ac0565b610f7f60808c0160608d01612ac0565b610f8f60a08d0160808e01612ac0565b610f9f60c08e0160a08f01612ac0565b6040516001600160e01b031960e088901b16815260048101959095526001600160401b03938416602486015291831660448501528216606484015216608482015260a401600060405180830381600087803b158015610ffd57600080fd5b505af1158015611011573d6000803e3d6000fd5b5060059250610925915050565b6040518060800160405280604e815260200161380e604e913981565b60008082610cce611050368a90038a018a612e1a565b611c76565b604051806101e001604052806101a4815260200161366a6101a4913981565b6040518060a00160405280606581526020016136056065913981565b60038054610ab190612b42565b60056020526000908152604090208054610ab190612b42565b60008082610cce6110cc368a90038a018a612e6b565b611cdc565b6040518060c00160405280609f8152602001613566609f913981565b6040518060a00160405280607081526020016134f66070913981565b6000546001600160a01b0316331461114f5760405162461bcd60e51b81526020600482015260096024820152682737ba1020b236b4b760b91b604482015260640161085e565b600180546001600160a01b038381166001600160a01b031983168117909355604080519190921680825260208201939093527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991015b60405180910390a15050565b3233146111bd57600080fd5b60006111d76111d260808a0160608b0161261e565b611d1f565b905060006111e88989898986611645565b90506001600160a01b03811661120460408b0160208c0161261e565b6001600160a01b0316148061123d575061123d61122760808b0160608c0161261e565b61123760408c0160208d0161261e565b83611d33565b6112595760405162461bcd60e51b815260040161085e90612a65565b6000611263611772565b6001600160a01b031663a40d726861128160808d0160608e0161261e565b61129160408e0160208f0161261e565b8d60200160200160208101906112a79190612eaf565b8e60200160600160208101906112bd9190612ee9565b6040516001600160e01b031960e087901b1681526001600160a01b03948516600482015293909216602484015261ffff16604483015263ffffffff166064820152608401602060405180830381865afa15801561131e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113429190612f06565b90506113518160018c356119fe565b600061135b610dc5565b6001600160a01b03166344176266348d6020018e60a0018f6101c00160208101906113869190612f2e565b8c8c8c6040518863ffffffff1660e01b81526004016113aa96959493929190612f5d565b60206040518083038185885af11580156113c8573d6000803e3d6000fd5b50505050506040513d601f19601f820116820180604052508101906113ed9190612f06565b90508181146114375760405162461bcd60e51b815260206004820152601660248201527515539156141150d5115117d413d4d2551253d397d25160521b604482015260640161085e565b60008181526008602090815260409182902086905561145a918d01908d0161261e565b600082815260096020526040902080546001600160a01b0319166001600160a01b039290921691909117905561149660808c0160608d0161261e565b6000828152600a6020526040902080546001600160a01b0319166001600160a01b03929092169190911790556001604080518381528d35602082015233917fd7793dfee69185c798d1c6d1d457aba44c8fb6c6465e8f0cce60d56ce07fc212910160405180910390a35050505050505050505050565b60008082610cce611522368a90038a018a6130e9565b611f5f565b6001546001600160a01b03163314801561154b57506001546001600160a01b031615155b6115975760405162461bcd60e51b815260206004820152601e60248201527f4e6f7420746865204558495354494e472070656e64696e672061646d696e0000604482015260640161085e565b60008054600180546001600160a01b038082166001600160a01b031980861682179096559490911690915560408051919092168082526020820184905292917ff9ffabca9c8276e99321725bcb43fb076a6c66a54b7f21c4e8146d8519b417dc910160405180910390a1600154604080516001600160a01b03808516825290921660208301527fca4f2f25d0898edd99413412fb94012f9e54ec8142f9b093e7720646a95b16a991016111a5565b60008082610cce61165b368a90038a018a61321a565b611fa8565b6040518060c00160405280608481526020016134726084913981565b32331461168857600080fd5b6000806116988660200135611833565b9150915060006116ab8787878787610cb3565b9050806001600160a01b0316826001600160a01b031614806116d757506116d7876020013583836119da565b6116f35760405162461bcd60e51b815260040161085e90612a65565b61170260208801356006610872565b61170a610dc5565b60405163568b6add60e01b8152602089013560048201526001600160a01b03919091169063568b6add90602401600060405180830381600087803b15801561175157600080fd5b505af1158015611765573d6000803e3d6000fd5b5060069250610925915050565b60007f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c2076001600160a01b031663fab337046040518163ffffffff1660e01b8152600401602060405180830381865afa1580156117d2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117f69190612cec565b6001600160a01b0316630d3b0b766040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e25573d6000803e3d6000fd5b6000818152600860209081526040808320546009909252909120546001600160a01b031681158061186b57506001600160a01b038116155b156119d557600061187a611772565b60405163042e37c560e01b8152600481018690529091506000906001600160a01b0383169063042e37c590602401608060405180830381865afa1580156118c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118e991906132d2565b90506118f88160000151611d1f565b606082015190945092508361194f5760405162461bcd60e51b815260206004820152601d60248201527f4e4f5f444f4d41494e5f534550415241544f525f464f525f434841494e000000604482015260640161085e565b6001600160a01b03831661199e5760405162461bcd60e51b81526020600482015260166024820152752727afaa2920a222a92fa327a92fa827a9a4aa24a7a760511b604482015260640161085e565b505060008381526008602090815260408083208590556009909152902080546001600160a01b0319166001600160a01b0383161790555b915091565b6000806119e685612005565b90506119f3818585611d33565b9150505b9392505050565b600083815260076020908152604080832060ff86168452909152902054818114611a5c5760405162461bcd60e51b815260206004820152600f60248201526e494e434f52524543545f4e4f4e434560881b604482015260640161085e565b611a6781600161332d565b600094855260076020908152604080872060ff909616875294905292909320919091555050565b6001600160a01b03821660009081526006602052604090205415611b025760405162461bcd60e51b815260206004820152602560248201527f434841494e5f49445f464f525f41535345545f414c52454144595f434f4e464960448201526411d554915160da1b606482015260840161085e565b80600003611b425760405162461bcd60e51b815260206004820152600d60248201526c434841494e5f49445f5a45524f60981b604482015260640161085e565b611b4b81612113565b506001600160a01b038216600081815260066020526040808220849055518392917f8983e01eaf5771a114f1aa7f72a023a35642e048180682aa2fb04db0cbd220c291a35050565b60006040518060800160405280604e815260200161380e604e9139805160209182012083518483015160408051948501939093529183015260608201526080015b604051602081830303815290604052805190602001209050919050565b60006040518060c001604052806082815260200161385c6082913980516020918201208351848301516040808701516060808901516080808b015160a0808d015187519b8c019a909a52958a0197909752918801949094526001600160401b03918216908701529182169085015290811660c08401521660e082015261010001611bd4565b60006040518060800160405280606081526020016138de606091398051602091820120835184830151604080870151606080890151835197880196909652918601939093528401526001600160401b0390811660808401521660a082015260c001611bd4565b60006040518060a00160405280607081526020016134f660709139805160209182012083518483015160408087015160608801519151611bd4969192910161334e565b600080611d2b836122cc565b509392505050565b6001600160a01b03831660009081526005602052604081208054829190611d5990612b42565b80601f0160208091040260200160405190810160405280929190818152602001828054611d8590612b42565b8015611dd25780601f10611da757610100808354040283529160200191611dd2565b820191906000526020600020905b815481529060010190602001808311611db557829003601f168201915b505050505090508051600003611dec5760009150506119f7565b60007f0000000000000000000000004cf3d61165a6be8ff741320ad27cab57fae5c2076001600160a01b03166358ca59ce60405180604001604052806014815260200173494e54454e54535f5045524d495353494f4e535f60601b81525084604051602001611e5c92919061338b565b6040516020818303038152906040526040518263ffffffff1660e01b8152600401611e8791906125d3565b602060405180830381865afa158015611ea4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ec89190612cec565b90506001600160a01b038116611ee3576000925050506119f7565b60405163b0cbc2e160e01b81526001600160a01b0382169063b0cbc2e190611f1490600190899089906004016133ba565b602060405180830381865afa158015611f31573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5591906133e5565b9695505050505050565b60006040518060c0016040528060848152602001613472608491398051602091820120835184830151604080870151606088015160808901519251611bd4979293919201613402565b6000604051806101e001604052806101a4815260200161366a6101a49139805190602001208260000151611fdf8460200151612393565b611fec8560400151612406565b8560600151604051602001611bd4959493929190613447565b6000818152600a60205260409020546001600160a01b03168061210e5761202a611772565b6001600160a01b031663042e37c5836040518263ffffffff1660e01b815260040161205791815260200190565b608060405180830381865afa158015612074573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061209891906132d2565b5190506001600160a01b0381166120e65760405162461bcd60e51b81526020600482015260126024820152712727afa9a0afa327a92fa827a9a4aa24a7a760711b604482015260640161085e565b6000828152600a6020526040902080546001600160a01b0319166001600160a01b0383161790555b919050565b60008181526004602052604081205480610da357600061226f60405180608001604052806002805461214490612b42565b80601f016020809104026020016040519081016040528092919081815260200182805461217090612b42565b80156121bd5780601f10612192576101008083540402835291602001916121bd565b820191906000526020600020905b8154815290600101906020018083116121a057829003601f168201915b50505050508152602001600380546121d490612b42565b80601f016020809104026020016040519081016040528092919081815260200182805461220090612b42565b801561224d5780601f106122225761010080835404028352916020019161224d565b820191906000526020600020905b81548152906001019060200180831161223057829003601f168201915b50505050508152602001868152602001306001600160a01b03168152506124c9565b600085815260046020526040908190208290555190915084907f04df087044a5490c34ea0092af5dbdd1a3a35fefd63f0864c1d05dba3075f165906122b79084815260200190565b60405180910390a29392505050565b50919050565b6001600160a01b038116600090815260066020526040812054819080820361232e5760405162461bcd60e51b81526020600482015260156024820152741393d7d0d210525397d25117d193d497d054d4d155605a1b604482015260640161085e565b6000818152600460205260409020548061238a5760405162461bcd60e51b815260206004820152601d60248201527f4e4f5f444f4d41494e5f534550415241544f525f464f525f434841494e000000604482015260640161085e565b94909350915050565b60006040518060a00160405280606581526020016136056065913980516020918201208351848301516040808701516060808901518351978801969096526001600160a01b039485169287019290925261ffff9092169085015216608083015263ffffffff1660a082015260c001611bd4565b60006040518060c00160405280609f8152602001613566609f913980519060200120826000015183602001518460400151856060015186608001518760a001518860c001518960e001518a6101000151604051602001611bd49a99989796959493929190998a5297151560208a0152604089019690965263ffffffff9490941660608801526001600160401b03928316608088015290821660a0870152811660c086015290811660e0850152908116610100840152166101208201526101400190565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82600001518051906020012083602001518051906020012084604001518560600151604051602001611bd49594939291909485526020850193909352604084019190915260608301526001600160a01b0316608082015260a00190565b6000608082840312156122c657600080fd5b803560ff8116811461210e57600080fd5b60008060008060e0858703121561258257600080fd5b61258c8686612549565b935061259a6080860161255b565b939693955050505060a08201359160c0013590565b60005b838110156125ca5781810151838201526020016125b2565b50506000910152565b60208152600082518060208401526125f28160408501602087016125af565b601f01601f19169190910160400192915050565b6001600160a01b038116811461261b57600080fd5b50565b60006020828403121561263057600080fd5b81356119f781612606565b6000806040838503121561264e57600080fd5b823561265981612606565b946020939093013593505050565b600060a082840312156122c657600080fd5b600080600080610100858703121561269057600080fd5b61269a8686612667565b93506126a860a0860161255b565b939693955050505060c08201359160e0013590565b6000604082840312156122c657600080fd5b600080600080600060c086880312156126e757600080fd5b6126f187876126bd565b94506126ff6040870161255b565b949794965050505060608301359260808101359260a0909101359150565b600060c082840312156122c657600080fd5b6000806000806000610140868803121561274857600080fd5b612752878761271d565b945061276060c0870161255b565b949794965050505060e08301359261010081013592610120909101359150565b6000806040838503121561279357600080fd5b823591506127a36020840161255b565b90509250929050565b6000602082840312156127be57600080fd5b5035919050565b6000806000604084860312156127da57600080fd5b83356127e581612606565b925060208401356001600160401b038082111561280157600080fd5b818601915086601f83011261281557600080fd5b81358181111561282457600080fd5b87602082850101111561283657600080fd5b6020830194508093505050509250925092565b600080600080610120858703121561286057600080fd5b61286a868661271d565b935061287860c0860161255b565b939693955050505060e082013591610100013590565b600080600080600061010086880312156128a757600080fd5b6128b18787612549565b94506128bf6080870161255b565b949794965050505060a08301359260c08101359260e0909101359150565b60006101e082840312156122c657600080fd5b801515811461261b57600080fd5b803561210e816128f0565b60008060008060008060006102a0888a03121561292557600080fd5b61292f89896128dd565b965061293e6101e0890161255b565b9550610200880135945061022088013593506102408801359250610260880135915061028088013561296f816128f0565b8091505092959891949750929550565b6000806000806000610120868803121561299857600080fd5b6129a28787612667565b94506129b060a0870161255b565b949794965050505060c08301359260e081013592610100909101359150565b600080600080600061026086880312156129e857600080fd5b6129f287876128dd565b9450612a016101e0870161255b565b94979496505050506102008301359261022081013592610240909101359150565b60008060008060a08587031215612a3857600080fd5b612a4286866126bd565b9350612a506040860161255b565b93969395505050506060820135916080013590565b6020808252601490820152732727aa2fa9a4a3a722a22fa12cafaa2920a222a960611b604082015260600190565b634e487b7160e01b600052602160045260246000fd5b80356001600160401b038116811461210e57600080fd5b600060208284031215612ad257600080fd5b6119f782612aa9565b80356004811061210e57600080fd5b600060208284031215612afc57600080fd5b6119f782612adb565b6004811061261b5761261b612a93565b83815260608101612b2584612b05565b8360208301526001600160401b0383166040830152949350505050565b600181811c90821680612b5657607f821691505b6020821081036122c657634e487b7160e01b600052602260045260246000fd5b84815260808101612b8685612b05565b60208201949094526001600160401b0392831660408201529116606090910152919050565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b0381118282101715612be357612be3612bab565b60405290565b60405161012081016001600160401b0381118282101715612be357612be3612bab565b600060408284031215612c1e57600080fd5b604051604081018181106001600160401b0382111715612c4057612c40612bab565b604052823581526020928301359281019290925250919050565b600060c08284031215612c6c57600080fd5b60405160c081018181106001600160401b0382111715612c8e57612c8e612bab565b80604052508235815260208301356020820152612cad60408401612aa9565b6040820152612cbe60608401612aa9565b6060820152612ccf60808401612aa9565b6080820152612ce060a08401612aa9565b60a08201529392505050565b600060208284031215612cfe57600080fd5b81516119f781612606565b601f821115612d55576000816000526020600020601f850160051c81016020861015612d325750805b601f850160051c820191505b81811015612d5157828155600101612d3e565b5050505b505050565b6001600160401b03831115612d7157612d71612bab565b612d8583612d7f8354612b42565b83612d09565b6000601f841160018114612db95760008515612da15750838201355b600019600387901b1c1916600186901b178355612e13565b600083815260209020601f19861690835b82811015612dea5786850135825560209485019460019092019101612dca565b5086821015612e075760001960f88860031b161c19848701351681555b505060018560011b0183555b5050505050565b600060808284031215612e2c57600080fd5b612e34612bc1565b8235815260208301356020820152612e4e60408401612aa9565b6040820152612e5f60608401612aa9565b60608201529392505050565b600060808284031215612e7d57600080fd5b612e85612bc1565b8235815260208301356020820152612e4e60408401612adb565b61ffff8116811461261b57600080fd5b600060208284031215612ec157600080fd5b81356119f781612e9f565b63ffffffff8116811461261b57600080fd5b803561210e81612ecc565b600060208284031215612efb57600080fd5b81356119f781612ecc565b600060208284031215612f1857600080fd5b5051919050565b80356003811061210e57600080fd5b600060208284031215612f4057600080fd5b6119f782612f1f565b60038110612f5957612f59612a93565b9052565b61022081018735612f6d81612606565b6001600160a01b039081168352602089013590612f8982612e9f565b61ffff8216602085015260408a01359150612fa382612606565b1660408301526060880135612fb781612ecc565b63ffffffff1660608301528635612fcd816128f0565b15156080830152602087013560a08301526040870135612fec81612ecc565b63ffffffff1660c083015261300360608801612aa9565b6001600160401b031660e083015261301d60808801612aa9565b610100613034818501836001600160401b03169052565b61304060a08a01612aa9565b6001600160401b038116610120860152915061305e60c08a01612aa9565b6001600160401b038116610140860152915061307c60e08a01612aa9565b6001600160401b0381166101608601529150613099818a01612aa9565b9150506130b26101808401826001600160401b03169052565b506130c16101a0830187612f49565b846101c0830152836101e08301526130de61020083018415159052565b979650505050505050565b600060a082840312156130fb57600080fd5b60405160a081018181106001600160401b038211171561311d5761311d612bab565b8060405250823581526020830135602082015261313c60408401612adb565b604082015261314d60608401612aa9565b606082015261315e60808401612aa9565b60808201529392505050565b6000610120828403121561317d57600080fd5b613185612be9565b9050613190826128fe565b8152602082013560208201526131a860408301612ede565b60408201526131b960608301612aa9565b60608201526131ca60808301612aa9565b60808201526131db60a08301612aa9565b60a08201526131ec60c08301612aa9565b60c08201526131fd60e08301612aa9565b60e0820152610100613210818401612aa9565b9082015292915050565b60008183036101e081121561322e57600080fd5b613236612bc1565b833581526080601f198301121561324c57600080fd5b613254612bc1565b9150602084013561326481612606565b8252604084013561327481612e9f565b6020830152606084013561328781612606565b6040830152608084013561329a81612ecc565b6060830152602081018290526132b38560a0860161316a565b60408201526132c56101c08501612f1f565b6060820152949350505050565b6000608082840312156132e457600080fd5b6132ec612bc1565b82516132f781612606565b8152602083015161330781612e9f565b6020820152604083015161331a81612ecc565b60408201526060830151612e5f81612606565b80820180821115610da357634e487b7160e01b600052601160045260246000fd5b858152602081018590526040810184905260a0810161336c84612b05565b8360608301526001600160401b03831660808301529695505050505050565b6000835161339d8184602088016125af565b8351908301906133b18183602088016125af565b01949350505050565b606081016133c785612b05565b9381526001600160a01b039283166020820152911660409091015290565b6000602082840312156133f757600080fd5b81516119f7816128f0565b868152602081018690526040810185905260c0810161342085612b05565b60608201949094526001600160401b039283166080820152911660a0909101529392505050565b600060a082019050868252856020830152846040830152836060830152611f556080830184612f4956fe55736572526571756573745061796c6f61645f557064617465506f736974696f6e446f75626c654669656c642875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e7438206f72646572547970652c75696e743634206669656c6456616c7565412c75696e743634206669656c6456616c7565422955736572526571756573745061796c6f61645f557064617465506f736974696f6e53696e676c654669656c642875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e7438206f72646572547970652c75696e743634206669656c6456616c756529506f736974696f6e52657175657374506172616d7328626f6f6c206c6f6e672c75696e7432353620636f6c6c61746572616c2c75696e743332206c657665726167652c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2c75696e74363420747042794672616374696f6e2c75696e74363420736c42794672616374696f6e29506f736974696f6e526571756573744964656e746966696572732861646472657373207472616465722c75696e743136207061697249642c6164647265737320736574746c656d656e7441737365742c75696e74333220706f736974696f6e496e6465782955736572526571756573745061796c6f61645f4f70656e506f736974696f6e2875696e74323536206e6f6e63652c506f736974696f6e526571756573744964656e7469666965727320706f736974696f6e526571756573744964656e746966696572732c506f736974696f6e52657175657374506172616d7320706f736974696f6e52657175657374506172616d732c75696e7438206f726465725479706529506f736974696f6e526571756573744964656e746966696572732861646472657373207472616465722c75696e743136207061697249642c6164647265737320736574746c656d656e7441737365742c75696e74333220706f736974696f6e496e64657829506f736974696f6e52657175657374506172616d7328626f6f6c206c6f6e672c75696e7432353620636f6c6c61746572616c2c75696e743332206c657665726167652c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2c75696e74363420747042794672616374696f6e2c75696e74363420736c42794672616374696f6e29557365724469726563745061796c6f61645f43616e63656c50656e64696e674c696d6974506f736974696f6e2875696e74323536206e6f6e63652c6279746573333220706f736974696f6e496429557365724469726563745061796c6f61645f55706461746550656e64696e674c696d6974506f736974696f6e2875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e743634206d696e50726963652c75696e743634206d617850726963652c75696e7436342074702c75696e74363420736c2955736572526571756573745061796c6f61645f436c6f73654d61726b65742875696e74323536206e6f6e63652c6279746573333220706f736974696f6e49642c75696e743634206d696e50726963652c75696e743634206d6178507269636529a2646970667358221220d30dc2db59f6e82655196707b5df99c02eccfd9fcdc8c8207e8c7ddc2469a38564736f6c63430008180033
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 ]
[ 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.