Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00
Cross-Chain Transactions
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xAc87E0D7...c25D06069 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
CelerBridgeModule
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 1000000 runs
Other Settings:
cancun EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Modules
import { EIP712 } from "@modules/util/EIP712.sol";
import { BridgeModuleBase } from "@modules/bridge/base/BridgeModuleBase.sol";
// Interfaces
import { ICelerBridgeModule } from "@modules/bridge/interfaces/celer/ICelerBridgeModule.sol";
import { IModule } from "@modules/interfaces/IModule.sol";
import { ICelerOriginalTokenVaultV1 } from "@modules/bridge/interfaces/celer/ICelerOriginalTokenVaultV1.sol";
import { ICelerOriginalTokenVaultV2 } from "@modules/bridge/interfaces/celer/ICelerOriginalTokenVaultV2.sol";
import { ICelerPeggedTokenBridgeV1 } from "@modules/bridge/interfaces/celer/ICelerPeggedTokenBridgeV1.sol";
import { ICelerPeggedTokenBridgeV2 } from "@modules/bridge/interfaces/celer/ICelerPeggedTokenBridgeV2.sol";
import { IWETH } from "@interfaces/util/IWETH.sol";
// Libraries
import { SafeTransferLib } from "@solady/utils/SafeTransferLib.sol";
import { ERC20UtilsLib } from "@modules/libraries/ERC20UtilsLib.sol";
import { OrderHashLib } from "@modules/libraries/OrderHashLib.sol";
import { BridgeLib } from "@modules/libraries/BridgeLib.sol";
import { SignatureLib } from "@modules/libraries/SignatureLib.sol";
// Types
import { Order, OrderWithSig } from "@types/Order.sol";
// Celer Protobuf Libraries
import { PbPegged } from "@modules/bridge/libraries/celer/PbPegged.sol";
/// @title Celer Bridge Module
/// @notice Bridge module implementation for the Celer protocol supporting xAsset flows
/// @dev Supports pegged token bridging (xAsset) with deposit and burn operations
contract CelerBridgeModule is BridgeModuleBase, EIP712, ICelerBridgeModule {
using SafeTransferLib for address;
using ERC20UtilsLib for address;
using OrderHashLib for Order;
using SignatureLib for bytes;
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
// keccak256(abi.encode(uint256(keccak256("CelerBridgeModule.orderTransferIds")) - 1)) & ~bytes32(uint256(0xff));
bytes32 internal constant ORDER_TRANSFER_IDS_SLOT =
0x872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c60600;
/// @custom:storage-location erc7201:CelerBridgeModule.orderTransferIds
/// @notice Storage struct for Celer bridge order ID tracking
struct OrderTransferIdsStorage {
/// @notice Maps order hashes to their actual transferIds from Celer bridge operations
mapping(bytes32 orderHash => bytes32 transferId) orderTransferIds;
/// @notice Maps order hashes to their delayedTransferIds from delayed refund events
mapping(bytes32 orderHash => bytes32 delayedTransferId) orderDelayedTransferIds;
}
/// @notice Get the pointer to the order transfer IDs storage slot
/// @return otis The pointer to the order transfer IDs storage slot
function _orderTransferIdsStorage() internal pure returns (OrderTransferIdsStorage storage otis) {
bytes32 slot = ORDER_TRANSFER_IDS_SLOT;
assembly {
otis.slot := slot
}
}
/*//////////////////////////////////////////////////////////////
IMMUTABLE STATE
//////////////////////////////////////////////////////////////*/
/// @notice Celer original token vault V1 contract address (xAsset deposit flow)
address public immutable ORIGINAL_TOKEN_VAULT_V1;
/// @notice Celer original token vault V2 contract address (xAsset deposit flow)
address public immutable ORIGINAL_TOKEN_VAULT_V2;
/// @notice Celer pegged token bridge V1 contract address (xAsset burn flow)
address public immutable PEGGED_TOKEN_BRIDGE_V1;
/// @notice Celer pegged token bridge V2 contract address (xAsset burn flow)
address public immutable PEGGED_TOKEN_BRIDGE_V2;
/// @notice WETH contract address (used for transferId calculation)
address public immutable WETH;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Constructor for CelerBridgeModule
/// @param _portikusV2 The PortikusV2 contract address
/// @param _originalTokenVaultV1 Celer original token vault V1 contract address
/// @param _originalTokenVaultV2 Celer original token vault V2 contract address
/// @param _peggedTokenBridgeV1 Celer pegged token bridge V1 contract address
/// @param _peggedTokenBridgeV2 Celer pegged token bridge V2 contract address
/// @param _weth WETH contract address
constructor(
address _portikusV2,
address _weth,
address _originalTokenVaultV1,
address _originalTokenVaultV2,
address _peggedTokenBridgeV1,
address _peggedTokenBridgeV2
)
BridgeModuleBase("Celer Bridge Module", "1.0.0", _portikusV2)
{
if (_weth == address(0)) revert InvalidWethAddress();
WETH = _weth;
ORIGINAL_TOKEN_VAULT_V1 = _originalTokenVaultV1;
ORIGINAL_TOKEN_VAULT_V2 = _originalTokenVaultV2;
PEGGED_TOKEN_BRIDGE_V1 = _peggedTokenBridgeV1;
PEGGED_TOKEN_BRIDGE_V2 = _peggedTokenBridgeV2;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IModule
function selectors() external pure override returns (bytes4[] memory moduleSelectors) {
moduleSelectors = new bytes4[](3);
moduleSelectors[0] = this.bridgeWithCeler.selector;
moduleSelectors[1] = this.celerRefund.selector;
moduleSelectors[2] = this.celerDelayedRefund.selector;
}
/// @notice Bridges tokens using the Celer protocol
/// @dev Supports xAsset flows based on protocol data configuration
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param inputAmount The amount of input tokens to bridge
/// @param bridgeData Unused parameter (kept for interface compatibility)
function bridgeWithCeler(
Order memory order,
address beneficiary,
uint256 inputAmount,
bytes memory bridgeData
)
external
payable
{
// Require bridge access authorization from settlement module
BridgeLib.requireBridgeInitiated();
_bridgeInternal(order, beneficiary, inputAmount, bridgeData);
}
/// @notice Internal bridge implementation for Celer protocol
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param inputAmount The amount of input tokens to bridge
/// param bridgeData Unused parameter (kept for interface compatibility)
function _bridgeInternal(
Order memory order,
address beneficiary,
uint256 inputAmount,
bytes memory /* bridgeData */
)
internal
{
CelerBridgeData memory protocolData = _validateAndDecodeProtocolData(order);
// Execute appropriate bridge flow based on bridge type and capture transferId
bytes32 transferId;
if (protocolData.bridgeType == BridgeType.PegDepositV1) {
_bridgePegDepositV1(protocolData, order, beneficiary, inputAmount);
transferId = _calculatePegDepositV1TransferId(order, protocolData, inputAmount);
} else if (protocolData.bridgeType == BridgeType.PegDepositV2) {
transferId = _bridgePegDepositV2(protocolData, order, beneficiary, inputAmount);
} else if (protocolData.bridgeType == BridgeType.PegBurnV1) {
_bridgePegBurnV1(order, beneficiary, inputAmount, protocolData.nonce);
transferId = _calculatePegBurnV1TransferId(order, protocolData, inputAmount);
} else if (protocolData.bridgeType == BridgeType.PegBurnV2) {
transferId = _bridgePegBurnV2(order, beneficiary, inputAmount, protocolData.nonce);
} else {
revert InvalidBridgeType();
}
bytes32 orderHash = _hashTypedDataV4(order.hash());
// Store the transferId to prevent hash collision attacks
_orderTransferIdsStorage().orderTransferIds[orderHash] = transferId;
// Emit standard bridge event
emit TokensBridged(
order.hash(), // Use pure order hash for consistency with other bridge modules
beneficiary,
order.bridge.destinationChainId,
inputAmount,
_convertToDestDecimals(inputAmount, order.bridge.scalingFactor),
_getBridgeProtocolString(protocolData.bridgeType)
);
}
/// @notice Process a refund for a failed Celer bridge transfer
/// @param orderWithSig The signed order used to initiate the bridge transfer
/// @param _request The serialized request protobuf from SGN
/// @param _sigs The list of signatures sorted by signing addresses in ascending order
/// @param _signers The sorted list of signers
/// @param _powers The signing powers of the signers
function celerRefund(
OrderWithSig memory orderWithSig,
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external
{
bytes32 orderHash = _verifySignature(orderWithSig);
CelerBridgeData memory protocolData = _validateAndDecodeProtocolData(orderWithSig.order);
_validateRefundRequest(orderHash, _request);
// Execute refund
(uint256 refundAmount, bytes32 refundId) =
_executeRefund(orderWithSig.order, protocolData, _request, _sigs, _signers, _powers);
// Handle post-refund processing based on result
if (refundAmount == 0) {
// Delayed transfer - store refundId and emit delayed refund event
_orderTransferIdsStorage().orderDelayedTransferIds[orderHash] = refundId;
// Emit delayed refund event so user knows to call celerDelayedRefund later
emit CelerRefundDelayed(
orderHash,
orderWithSig.order.owner,
orderWithSig.order.destToken,
refundAmount,
protocolData.bridgeType,
refundId
);
return;
}
// Clean up storage - refund is complete, no longer need the transferId
delete _orderTransferIdsStorage().orderTransferIds[orderHash];
// Transfer refunded tokens to the original user
_transferRefundToUser(orderWithSig.order, refundAmount);
// Emit success event
emit CelerRefundProcessed(
orderHash, orderWithSig.order.owner, orderWithSig.order.destToken, refundAmount, protocolData.bridgeType
);
}
/// @inheritdoc ICelerBridgeModule
function celerDelayedRefund(bytes32 delayedTransferId, OrderWithSig memory orderWithSig) external {
bytes32 orderHash = _verifySignature(orderWithSig);
CelerBridgeData memory protocolData = _validateAndDecodeProtocolData(orderWithSig.order);
// Validate that the delayedTransferId belongs to this specific order
_validateDelayedRefundRequest(orderHash, delayedTransferId);
// Execute the delayed transfer on the appropriate Celer contract
uint256 refundAmount = _executeDelayedTransfer(orderWithSig.order, protocolData, delayedTransferId);
if (refundAmount == 0) revert RefundAmountNotReceived();
// Clean up storage - delayed refund is complete, no longer need the stored IDs
delete _orderTransferIdsStorage().orderTransferIds[orderHash];
delete _orderTransferIdsStorage().orderDelayedTransferIds[orderHash];
_transferRefundToUser(orderWithSig.order, refundAmount);
emit CelerRefundProcessed(
orderHash, orderWithSig.order.owner, orderWithSig.order.destToken, refundAmount, protocolData.bridgeType
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/
/// @notice Bridges tokens via Celer xAsset flow - PegDeposit V1
/// @param protocolData The validated Celer bridge configuration
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param bridgeAmount The amount of tokens to bridge
function _bridgePegDepositV1(
CelerBridgeData memory protocolData,
Order memory order,
address beneficiary,
uint256 bridgeAmount
)
internal
{
// Validate that the OriginalTokenVault V1 contract is supported on this chain
_requireBridgeSupported(ORIGINAL_TOKEN_VAULT_V1);
// If the destination token is ETH, deposit native token
if (order.destToken.isEth()) {
ICelerOriginalTokenVaultV1(ORIGINAL_TOKEN_VAULT_V1).depositNative{ value: bridgeAmount }(
bridgeAmount, uint64(order.bridge.destinationChainId), beneficiary, protocolData.nonce
);
return;
}
order.destToken.safeApprove(ORIGINAL_TOKEN_VAULT_V1, bridgeAmount);
ICelerOriginalTokenVaultV1(ORIGINAL_TOKEN_VAULT_V1).deposit(
order.destToken, bridgeAmount, uint64(order.bridge.destinationChainId), beneficiary, protocolData.nonce
);
}
/// @notice Bridges tokens via Celer xAsset flow - PegDeposit (V1 or V2)
/// @param protocolData The validated Celer bridge configuration
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param bridgeAmount The amount of tokens to bridge
/// @return transferId The actual transferId from V2 contracts, or bytes32(0) for V1 contracts
function _bridgePegDepositV2(
CelerBridgeData memory protocolData,
Order memory order,
address beneficiary,
uint256 bridgeAmount
)
internal
returns (bytes32 transferId)
{
// Validate that the OriginalTokenVault V2 contract is supported on this chain
_requireBridgeSupported(ORIGINAL_TOKEN_VAULT_V2);
// If the destination token is ETH, deposit native token
if (order.destToken.isEth()) {
transferId = ICelerOriginalTokenVaultV2(ORIGINAL_TOKEN_VAULT_V2).depositNative{ value: bridgeAmount }(
bridgeAmount, uint64(order.bridge.destinationChainId), beneficiary, protocolData.nonce
);
} else {
order.destToken.safeApprove(ORIGINAL_TOKEN_VAULT_V2, bridgeAmount);
transferId = ICelerOriginalTokenVaultV2(ORIGINAL_TOKEN_VAULT_V2).deposit(
order.destToken, bridgeAmount, uint64(order.bridge.destinationChainId), beneficiary, protocolData.nonce
);
}
}
/// @notice Bridges tokens via Celer xAsset flow - PegBurn V1
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param bridgeAmount The amount of tokens to bridge
/// @param nonce Unique nonce for the bridge transaction
function _bridgePegBurnV1(Order memory order, address beneficiary, uint256 bridgeAmount, uint64 nonce) internal {
// Validate that the PeggedTokenBridge V1 contract is supported on this chain
_requireBridgeSupported(PEGGED_TOKEN_BRIDGE_V1);
// Note: PegBurn doesn't support native ETH, only pegged tokens
if (order.destToken.isEth()) revert EthNotSupportedForPegBurn();
// Approve and burn pegged tokens (V1 - 4 parameters)
order.destToken.safeApprove(PEGGED_TOKEN_BRIDGE_V1, bridgeAmount);
ICelerPeggedTokenBridgeV1(PEGGED_TOKEN_BRIDGE_V1).burn(order.destToken, bridgeAmount, beneficiary, nonce);
}
/// @notice Bridges tokens via Celer xAsset flow - PegBurn V2
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param bridgeAmount The amount of tokens to bridge
/// @param nonce Unique nonce for the bridge transaction
/// @return transferId The actual burnId returned by the V2 contract
function _bridgePegBurnV2(
Order memory order,
address beneficiary,
uint256 bridgeAmount,
uint64 nonce
)
internal
returns (bytes32 transferId)
{
// Validate that the PeggedTokenBridge V2 contract is supported on this chain
_requireBridgeSupported(PEGGED_TOKEN_BRIDGE_V2);
// Note: PegBurn doesn't support native ETH, only pegged tokens
if (order.destToken.isEth()) revert EthNotSupportedForPegBurn();
// Approve and burn pegged tokens (V2 - 5 parameters)
order.destToken.safeApprove(PEGGED_TOKEN_BRIDGE_V2, bridgeAmount);
transferId = ICelerPeggedTokenBridgeV2(PEGGED_TOKEN_BRIDGE_V2).burn(
order.destToken, bridgeAmount, uint64(order.bridge.destinationChainId), beneficiary, nonce
);
}
/// @notice Execute a refund from Celer
/// @param order The order details
/// @param protocolData The already-decoded protocol data
/// @param _request The SGN refund request
/// @param _sigs The SGN signatures
/// @param _signers The SGN signers
/// @param _powers The SGN signing powers
/// @return refundAmount The amount refunded (0 if delayed)
/// @return refundId The refund ID for delayed transfers (only valid if refundAmount == 0)
function _executeRefund(
Order memory order,
CelerBridgeData memory protocolData,
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
internal
returns (uint256 refundAmount, bytes32 refundId)
{
// Store balance before withdrawal (ETH for WETH orders, token for others)
uint256 balanceBefore = _getTokenBalance(order.destToken);
// Execute refund and get the refund ID (from V2 return values or V1 calculation)
if (protocolData.bridgeType == BridgeType.PegDepositV1) {
ICelerOriginalTokenVaultV1(ORIGINAL_TOKEN_VAULT_V1).withdraw(_request, _sigs, _signers, _powers);
// V1: Calculate the refund ID ourselves
refundId = _calculatePegDepositV1DelayedTransferId(_request);
} else if (protocolData.bridgeType == BridgeType.PegDepositV2) {
refundId = ICelerOriginalTokenVaultV2(ORIGINAL_TOKEN_VAULT_V2).withdraw(_request, _sigs, _signers, _powers);
// V2: Returns wdId directly
} else if (protocolData.bridgeType == BridgeType.PegBurnV1) {
ICelerPeggedTokenBridgeV1(PEGGED_TOKEN_BRIDGE_V1).mint(_request, _sigs, _signers, _powers);
// V1: Calculate the refund ID ourselves
refundId = _calculatePegBurnV1DelayedTransferId(_request);
} else {
refundId = ICelerPeggedTokenBridgeV2(PEGGED_TOKEN_BRIDGE_V2).mint(_request, _sigs, _signers, _powers);
// V2: Returns mintId directly
}
// Calculate refund amount received (ETH for WETH orders, token for others)
refundAmount = _getTokenBalance(order.destToken) - balanceBefore;
}
/// @notice Execute a delayed transfer from Celer
/// @param order The original order
/// @param protocolData The protocol data
/// @param delayedTransferId The ID of the delayed transfer
/// @return refundAmount The amount refunded
function _executeDelayedTransfer(
Order memory order,
CelerBridgeData memory protocolData,
bytes32 delayedTransferId
)
internal
returns (uint256 refundAmount)
{
// Store balance before delayed transfer execution
uint256 balanceBefore = _getTokenBalance(order.destToken);
// Execute delayed transfer based on bridge type
// Note: All Celer contracts support delayed transfers for security
if (protocolData.bridgeType == BridgeType.PegDepositV1) {
ICelerOriginalTokenVaultV1(ORIGINAL_TOKEN_VAULT_V1).executeDelayedTransfer(delayedTransferId);
} else if (protocolData.bridgeType == BridgeType.PegDepositV2) {
ICelerOriginalTokenVaultV2(ORIGINAL_TOKEN_VAULT_V2).executeDelayedTransfer(delayedTransferId);
} else if (protocolData.bridgeType == BridgeType.PegBurnV1) {
ICelerPeggedTokenBridgeV1(PEGGED_TOKEN_BRIDGE_V1).executeDelayedTransfer(delayedTransferId);
} else {
ICelerPeggedTokenBridgeV2(PEGGED_TOKEN_BRIDGE_V2).executeDelayedTransfer(delayedTransferId);
}
// Calculate refund amount received
refundAmount = _getTokenBalance(order.destToken) - balanceBefore;
}
/*//////////////////////////////////////////////////////////////
INTERNAL HELPERS
//////////////////////////////////////////////////////////////*/
/// @notice Process refund validation including signature and transferId verification
/// @param orderHash The hash of the original order
/// @param _request The SGN refund request
function _validateRefundRequest(bytes32 orderHash, bytes calldata _request) internal view {
// Decode the refund request protobuf to get receiver and transferId
(,,, address receiver,, bytes32 actualTransferId) = _decodeWithdrawRequest(_request);
// Validate that the transferId is not zero (prevents matching uninitialized storage)
if (actualTransferId == 0) revert TransferIdMismatch();
// validate refund receiver is this contract
if (receiver != address(this)) revert InvalidRefundReceiver();
// Get the stored transferId from when the order was originally bridged
bytes32 storedTransferId = _orderTransferIdsStorage().orderTransferIds[orderHash];
// Validate that the refund request transferId matches the stored transferId from bridging
if (actualTransferId != storedTransferId) revert TransferIdMismatch();
}
/// @notice Validate that the delayedTransferId belongs to the specific order
/// @param orderHash The hash of the original order
/// @param delayedTransferId The delayed transfer ID to validate
function _validateDelayedRefundRequest(bytes32 orderHash, bytes32 delayedTransferId) internal view {
// Validate that the delayedTransferId is not zero (prevents matching uninitialized storage)
if (delayedTransferId == 0) revert TransferIdMismatch();
// Get the stored delayedTransferId from when the delayed refund event was emitted
bytes32 storedDelayedTransferId = _orderTransferIdsStorage().orderDelayedTransferIds[orderHash];
// Validate that the provided delayedTransferId matches the stored one
if (delayedTransferId != storedDelayedTransferId) revert TransferIdMismatch();
}
/// @notice Transfer refunded tokens to the user, handling WETH conversion if needed
/// @param order The original order
/// @param refundAmount The amount to transfer
function _transferRefundToUser(Order memory order, uint256 refundAmount) internal {
if (order.destToken == WETH) {
// For WETH orders, Celer sent us ETH, but user expects WETH
// Convert ETH back to WETH to match user's original destToken expectation
IWETH(WETH).deposit{ value: refundAmount }();
}
order.destToken.transferTo(order.owner, refundAmount);
}
/// @notice Get the current balance for a token, handling WETH/ETH distinction
/// @param token The token address to get balance for
/// @return balance The current balance
function _getTokenBalance(address token) internal view returns (uint256 balance) {
bool isWeth = token == WETH;
balance = isWeth ? ERC20UtilsLib.ETH_ADDRESS.getBalance() : token.getBalance();
}
/// @notice Verify the order signature and return the order hash
/// @param orderWithSig The order with signature to verify
/// @return orderHash The computed and verified order hash
function _verifySignature(OrderWithSig memory orderWithSig) internal view returns (bytes32 orderHash) {
orderHash = _hashTypedDataV4(orderWithSig.order.hash());
orderWithSig.signature.verify(orderHash, orderWithSig.order.owner);
}
/// @notice Calculate transferId for PegDepositV1 bridge type
/// @param order The bridge order
/// @param protocolData The Celer protocol data
/// @param actualBridgeAmount The actual amount that was bridged
/// @return transferId The calculated transfer ID
function _calculatePegDepositV1TransferId(
Order memory order,
CelerBridgeData memory protocolData,
uint256 actualBridgeAmount
)
internal
view
returns (bytes32 transferId)
{
address beneficiary = order.beneficiary == address(0) ? order.owner : order.beneficiary;
// For ETH orders, Celer uses WETH address in transferId calculation, not ETH_ADDRESS
address bridgeToken = order.destToken.isEth() ? WETH : order.destToken;
transferId = keccak256(
abi.encodePacked(
address(this), // msg.sender (CelerBridgeModule)
bridgeToken, // token (WETH for ETH, otherwise destToken)
actualBridgeAmount, // ACTUAL amount that was bridged
uint64(order.bridge.destinationChainId), // dstChainId
beneficiary, // receiver
protocolData.nonce, // nonce
uint64(block.chainid) // current chain ID
)
);
}
/// @notice Calculate transferId for PegBurnV1 bridge type
/// @param order The bridge order
/// @param protocolData The Celer protocol data
/// @param actualBridgeAmount The actual amount that was bridged
/// @return transferId The calculated transfer ID
function _calculatePegBurnV1TransferId(
Order memory order,
CelerBridgeData memory protocolData,
uint256 actualBridgeAmount
)
internal
view
returns (bytes32 transferId)
{
address beneficiary = order.beneficiary == address(0) ? order.owner : order.beneficiary;
// For ETH orders, Celer uses WETH address in transferId calculation, not ETH_ADDRESS
address bridgeToken = order.destToken.isEth() ? WETH : order.destToken;
transferId = keccak256(
abi.encodePacked(
address(this), // msg.sender (CelerBridgeModule)
bridgeToken, // token (WETH for ETH, otherwise destToken)
actualBridgeAmount, // ACTUAL amount that was bridged
beneficiary, // receiver
protocolData.nonce, // nonce
uint64(block.chainid) // current chain ID
)
);
}
/// @notice Calculate delayed transfer ID for PegDepositV1 bridge type
/// @param _request The SGN refund request protobuf
/// @return delayedTransferId The calculated delayed transfer ID
function _calculatePegDepositV1DelayedTransferId(bytes calldata _request)
internal
view
returns (bytes32 delayedTransferId)
{
// For PegDepositV1, decode the withdraw request
(address receiver, address token, uint256 amount, address burnAccount, uint64 refChainId, bytes32 refId) =
_decodeWithdrawRequest(_request);
delayedTransferId = keccak256(abi.encodePacked(receiver, token, amount, burnAccount, refChainId, refId));
}
/// @notice Calculate delayed transfer ID for PegBurnV1 bridge type
/// @param _request The SGN refund request protobuf
/// @return delayedTransferId The calculated delayed transfer ID
function _calculatePegBurnV1DelayedTransferId(bytes calldata _request)
internal
pure
returns (bytes32 delayedTransferId)
{
// For PegBurnV1, decode the mint request
(address receiver, address token, uint256 amount, address depositor, uint64 refChainId, bytes32 refId) =
_decodeMintRequest(_request);
delayedTransferId = keccak256(abi.encodePacked(receiver, token, amount, depositor, refChainId, refId));
}
/// @notice Validates and decodes the protocol data from the order
/// @param order The order containing the protocol data to validate
/// @return celerData The validated and decoded Celer bridge data
function _validateAndDecodeProtocolData(Order memory order)
internal
pure
returns (CelerBridgeData memory celerData)
{
if (order.bridge.protocolData.length == 0) revert MissingProtocolData();
celerData = abi.decode(order.bridge.protocolData, (CelerBridgeData));
}
/// @notice Validates that a bridge contract is supported on this chain (address is not zero)
/// @param contractAddress The contract address to validate
function _requireBridgeSupported(address contractAddress) internal pure {
if (contractAddress == address(0)) revert BridgeNotSupported();
}
/// @notice Gets the bridge protocol string for event emission
/// @param bridgeType The Celer bridge type
/// @return The protocol string
function _getBridgeProtocolString(BridgeType bridgeType) internal pure returns (string memory) {
if (bridgeType == BridgeType.PegDepositV1) return "celer-peg-deposit-v1";
if (bridgeType == BridgeType.PegDepositV2) return "celer-peg-deposit-v2";
if (bridgeType == BridgeType.PegBurnV1) return "celer-peg-burn-v1";
return "celer-peg-burn-v2";
}
/*//////////////////////////////////////////////////////////////
DECODE HELPERS
//////////////////////////////////////////////////////////////*/
/// @notice Decode a withdraw request from the SGN protobuf
/// @param _request The SGN withdraw request protobuf
/// @return receiver The receiver address
/// @return token The token address
/// @return amount The amount
/// @return burnAccount The burn account
/// @return refChainId The reference chain ID
/// @return refId The reference ID
function _decodeWithdrawRequest(bytes calldata _request)
internal
view
virtual
returns (address receiver, address token, uint256 amount, address burnAccount, uint64 refChainId, bytes32 refId)
{
// Decode using the PbPegged library (same as in OriginalTokenVault)
PbPegged.Withdraw memory request = PbPegged.decWithdraw(_request);
return (request.receiver, request.token, request.amount, request.burnAccount, request.refChainId, request.refId);
}
/// @notice Decode a mint request from the SGN protobuf
/// @param _request The SGN mint request protobuf
/// @return receiver The receiver address
/// @return token The token address
/// @return amount The amount
/// @return depositor The depositor address
/// @return refChainId The reference chain ID
/// @return refId The reference ID
function _decodeMintRequest(bytes calldata _request)
internal
pure
virtual
returns (address receiver, address token, uint256 amount, address depositor, uint64 refChainId, bytes32 refId)
{
// Decode using the PbPegged library (same as in PeggedTokenBridge)
PbPegged.Mint memory request = PbPegged.decMint(_request);
return (request.account, request.token, request.amount, request.depositor, request.refChainId, request.refId);
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Dependencies
import { MessageHashUtils } from "@openzeppelin/utils/cryptography/MessageHashUtils.sol";
// Interfaces
import { IEIP712 } from "@interfaces/util/IEIP712.sol";
/// @title EIP712
/// @notice Implements EIP712 domain separator and hashing functionality
/// @dev This contract is a modified version of the OpenZeppelin EIP712 contract
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol
contract EIP712 is IEIP712 {
/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
// The raw EIP712 domain separator type string
bytes private constant TYPE_HASH_RAW =
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)";
// Raw name
string private constant NAME_RAW = "Portikus";
// Raw version
string private constant VERSION_RAW = "2.0.0";
/*//////////////////////////////////////////////////////////////
IMMUTABLE
//////////////////////////////////////////////////////////////*/
// Hash of the EIP712 Domain Separator data
bytes32 private immutable HASHED_NAME;
bytes32 private immutable HASHED_VERSION;
bytes32 private immutable TYPE_HASH;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Initializes the EIP712 domain separator fields
constructor() {
HASHED_NAME = keccak256(bytes(NAME_RAW));
HASHED_VERSION = keccak256(bytes(VERSION_RAW));
TYPE_HASH = keccak256(abi.encodePacked(TYPE_HASH_RAW));
}
/*//////////////////////////////////////////////////////////////
INTERNAL
//////////////////////////////////////////////////////////////*/
/// @notice Returns the domain separator for the current chain
function _domainSeparatorV4() internal view returns (bytes32) {
// Uses address(this) as the verifyingContract is the adapter that installed a module
return keccak256(abi.encode(TYPE_HASH, HASHED_NAME, HASHED_VERSION, block.chainid, address(this)));
}
/// @notice Hashes the EIP712 Domain Separator and the struct hash
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/*//////////////////////////////////////////////////////////////
EXTERNAL
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IEIP712
function DOMAIN_SEPARATOR() external view override returns (bytes32) {
return _domainSeparatorV4();
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Contracts
import { BaseModule } from "@modules/base/BaseModule.sol";
// Libraries
import { SafeTransferLib } from "@solady/utils/SafeTransferLib.sol";
import { ERC20UtilsLib } from "@modules/libraries/ERC20UtilsLib.sol";
/// @title Bridge Module Base
/// @notice Abstract base contract for bridge modules containing shared functionality
/// @dev Provides common patterns, validations, and utilities for bridge implementations
abstract contract BridgeModuleBase is BaseModule {
using SafeTransferLib for address;
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when protocol data is missing or empty
error MissingProtocolData();
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when tokens are bridged across chains
/// @param orderHash The hash of the order being bridged
/// @param beneficiary The recipient on the destination chain
/// @param destChainId The destination chain ID
/// @param inputAmount The amount of tokens being bridged (expressed in source token decimals)
/// @param outputAmount The expected amount on the destination chain, expressed in destination token decimals
/// after applying `_convertToDestDecimals`
/// @param bridgeProtocol The bridge protocol used (e.g., "optimism", "polygon", "cctp")
event TokensBridged(
bytes32 indexed orderHash,
address indexed beneficiary,
uint256 indexed destChainId,
uint256 inputAmount,
uint256 outputAmount,
string bridgeProtocol
);
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @notice Constructor for BridgeModuleBase
/// @param _name The module name
/// @param _version The module version
/// @param _portikusV2 The PortikusV2 contract address
constructor(
string memory _name,
string memory _version,
address _portikusV2
)
BaseModule(_name, _version, _portikusV2)
{ }
/*//////////////////////////////////////////////////////////////
SHARED UTILITIES
//////////////////////////////////////////////////////////////*/
/// @notice Calculates agent fee with cap protection
/// @param requestedFee The requested agent fee
/// @param maxFee The maximum allowed fee
/// @return The capped agent fee
function _calculateCappedFee(uint256 requestedFee, uint256 maxFee) internal pure returns (uint256) {
return requestedFee > maxFee ? maxFee : requestedFee;
}
/*//////////////////////////////////////////////////////////////
DECIMAL CONVERSION
//////////////////////////////////////////////////////////////*/
/// @notice Converts an amount from source token decimals to destination token decimals
/// @dev scalingFactor = destDecimals - srcDecimals
///
/// Behavior:
/// - scalingFactor > 0 (dest has more decimals than src): multiply by 10^scalingFactor
/// - scalingFactor < 0 (dest has fewer decimals than src): divide by 10^(-scalingFactor)
///
/// Constraints:
/// - |scalingFactor| <= 18 to avoid 10^N overflow and keep gas predictable
///
/// Examples:
/// - USDC (6) -> WETH (18): scalingFactor = +12; 1e6 -> 1e6 * 10^12 = 1e18
/// - WETH (18) -> USDC (6): scalingFactor = -12; 1e18 -> 1e18 / 10^12 = 1e6
///
/// @param amount Amount expressed in source token decimals
/// @param scalingFactor Signed decimal difference (destDecimals - srcDecimals)
/// @return Amount expressed in destination token decimals
function _convertToDestDecimals(uint256 amount, int8 scalingFactor) internal pure returns (uint256) {
if (scalingFactor == 0) return amount;
// Validate scaling factor to prevent overflow
int8 absFactor = scalingFactor >= 0 ? scalingFactor : -scalingFactor;
require(uint8(absFactor) <= 18, "Bridge: scaling factor too large");
uint256 scale = 10 ** uint8(absFactor);
if (scalingFactor > 0) {
// destDecimals > srcDecimals: multiply to convert src -> dest
return amount * scale;
} else {
// srcDecimals > destDecimals: divide to convert src -> dest
return amount / scale;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Types
import { Order, OrderWithSig } from "@types/Order.sol";
/// @title Celer Bridge Module Interface
/// @notice Interface for Celer bridge protocol module supporting xAsset flows
interface ICelerBridgeModule {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when bridge type is invalid
error InvalidBridgeType();
/// @notice Thrown when peg burn is called with ETH token
error EthNotSupportedForPegBurn();
/// @notice Thrown when bridge type is not supported on the current chain
error BridgeNotSupported();
/// @notice Thrown when no tokens are received from a refund operation
error RefundAmountNotReceived();
/// @notice Thrown when the refund receiver is invalid
error InvalidRefundReceiver();
/// @notice Thrown when the transferId mismatch
error TransferIdMismatch();
/// @notice Thrown when the WETH address is invalid
error InvalidWethAddress();
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when a refund is successfully processed
/// @param orderHash The hash of the original order
/// @param user The user who received the refund
/// @param token The token that was refunded
/// @param amount The amount that was refunded
/// @param bridgeType The bridge type that processed the refund
event CelerRefundProcessed(
bytes32 indexed orderHash, address indexed user, address indexed token, uint256 amount, BridgeType bridgeType
);
/// @notice Emitted when a refund is queued for delayed execution
/// @param orderHash The hash of the original order
/// @param user The user who will receive the refund
/// @param token The token to be refunded
/// @param amount The amount to be refunded
/// @param bridgeType The bridge type that processed the refund
/// @param delayedTransferId The ID of the delayed transfer
event CelerRefundDelayed(
bytes32 indexed orderHash,
address indexed user,
address indexed token,
uint256 amount,
BridgeType bridgeType,
bytes32 delayedTransferId
);
/*//////////////////////////////////////////////////////////////
ENUMS
//////////////////////////////////////////////////////////////*/
/// @notice Supported Celer bridge types
enum BridgeType {
PegDepositV1, // xAsset flow - deposit to OriginalTokenVault V1
PegDepositV2, // xAsset flow - deposit to OriginalTokenVault V2
PegBurnV1, // xAsset flow - burn from PeggedTokenBridge V1 (4 params)
PegBurnV2 // xAsset flow - burn from PeggedTokenBridge V2 (5 params)
}
/*//////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/
/// @notice Protocol-controlled Celer bridge configuration
/// @dev This struct defines the data encoded in order.bridge.protocolData by the backend
struct CelerBridgeData {
/// @dev The type of Celer bridge to use
BridgeType bridgeType;
/// @dev Nonce for uniqueness guarantee
uint64 nonce;
}
/*//////////////////////////////////////////////////////////////
EXTERNAL
//////////////////////////////////////////////////////////////*/
/// @notice Bridges tokens using the Celer protocol
/// @param order The order containing bridge details
/// @param beneficiary The address of the beneficiary on destination chain
/// @param inputAmount The amount of input tokens to bridge
/// @param bridgeData Unused parameter (kept for interface compatibility)
function bridgeWithCeler(
Order memory order,
address beneficiary,
uint256 inputAmount,
bytes memory bridgeData
)
external
payable;
/// @notice Process a refund for a failed Celer bridge transfer
/// @param orderWithSig The signed order used to initiate the bridge transfer
/// @param _request The serialized request protobuf from SGN
/// @param _sigs The list of signatures sorted by signing addresses in ascending order
/// @param _signers The sorted list of signers
/// @param _powers The signing powers of the signers
function celerRefund(
OrderWithSig memory orderWithSig,
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external;
/// @notice Execute a delayed transfer that is now ready
/// @param delayedTransferId The ID of the delayed transfer to execute
/// @param orderWithSig The original order with signature
function celerDelayedRefund(bytes32 delayedTransferId, OrderWithSig memory orderWithSig) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title IModule
/// @notice Core interfaces that all modules must implement to be compatible with the Portikus protocol
interface IModule {
/*//////////////////////////////////////////////////////////////
METADATA
//////////////////////////////////////////////////////////////*/
/// @notice Returns the name of the module
function name() external view returns (string memory);
/// @notice Returns the version of the module
function version() external view returns (string memory);
/*//////////////////////////////////////////////////////////////
SELECTORS
//////////////////////////////////////////////////////////////*/
/// @notice Used by the executor to determine which functions should be installed
/// @dev The implementation should not include any of the function selectors defined in the IModule interface itself
/// @return moduleSelectors An array of function selectors that the module implements
function selectors() external pure returns (bytes4[] memory moduleSelectors);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title Celer Original Token Vault V1 Interface
/// @notice Interface for Celer's original token vault V1 (xAsset flow)
/// @dev V1 functions do not return transferId
interface ICelerOriginalTokenVaultV1 {
/// @notice Lock original tokens to trigger mint at a remote chain's PeggedTokenBridge
/// @param token The original token address
/// @param amount The amount to deposit
/// @param mintChainId The destination chain ID to mint tokens
/// @param mintAccount The destination account to receive the minted pegged tokens
/// @param nonce A number input to guarantee unique depositId
function deposit(address token, uint256 amount, uint64 mintChainId, address mintAccount, uint64 nonce) external;
/// @notice Lock native token as original token to trigger cross-chain mint
/// @param amount The amount to deposit
/// @param mintChainId The destination chain ID to mint tokens
/// @param mintAccount The destination account to receive the minted pegged tokens
/// @param nonce A number input to guarantee unique depositId
function depositNative(uint256 amount, uint64 mintChainId, address mintAccount, uint64 nonce) external payable;
/**
* @notice Withdraw locked original tokens triggered by a burn at a remote chain's PeggedTokenBridge.
* @param _request The serialized Withdraw protobuf.
* @param _sigs The list of signatures sorted by signing addresses in ascending order. A relay must be signed-off by
* +2/3 of the bridge's current signing power to be delivered.
* @param _signers The sorted list of signers.
* @param _powers The signing powers of the signers.
*/
function withdraw(
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external;
/// @notice Execute a delayed transfer that is now ready
/// @param id The delayed transfer ID to execute
function executeDelayedTransfer(bytes32 id) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title Celer Original Token Vault V2 Interface
/// @notice Interface for Celer's original token vault V2 (xAsset flow)
/// @dev V2 functions return transferId for better tracking
interface ICelerOriginalTokenVaultV2 {
/// @notice Lock original tokens to trigger mint at a remote chain's PeggedTokenBridge
/// @param token The original token address
/// @param amount The amount to deposit
/// @param mintChainId The destination chain ID to mint tokens
/// @param mintAccount The destination account to receive the minted pegged tokens
/// @param nonce A number input to guarantee unique depositId
/// @return depositId The unique deposit identifier (transferId)
function deposit(
address token,
uint256 amount,
uint64 mintChainId,
address mintAccount,
uint64 nonce
)
external
returns (bytes32 depositId);
/// @notice Lock native token as original token to trigger cross-chain mint
/// @param amount The amount to deposit
/// @param mintChainId The destination chain ID to mint tokens
/// @param mintAccount The destination account to receive the minted pegged tokens
/// @param nonce A number input to guarantee unique depositId
/// @return depositId The unique deposit identifier (transferId)
function depositNative(
uint256 amount,
uint64 mintChainId,
address mintAccount,
uint64 nonce
)
external
payable
returns (bytes32 depositId);
/**
* @notice Withdraw locked original tokens triggered by a burn at a remote chain's PeggedTokenBridge.
* @param _request The serialized Withdraw protobuf.
* @param _sigs The list of signatures sorted by signing addresses in ascending order. A relay must be signed-off by
* +2/3 of the bridge's current signing power to be delivered.
* @param _signers The sorted list of signers.
* @param _powers The signing powers of the signers.
*/
function withdraw(
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external
returns (bytes32 wdId);
/// @notice Execute a delayed transfer that is now ready
/// @param id The delayed transfer ID to execute
function executeDelayedTransfer(bytes32 id) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title Celer Pegged Token Bridge V1 Interface
/// @notice Interface for Celer's pegged token bridge V1 (xAsset flow - burn side)
/// @dev V1 functions do not return transferId
interface ICelerPeggedTokenBridgeV1 {
/// @notice Burn tokens to trigger withdrawal at a remote chain's OriginalTokenVault (V1)
/// @param _token The local token address
/// @param _amount The amount to burn
/// @param _withdrawAccount The account who will receive original tokens on the remote chain
/// @param _nonce A user input to guarantee unique depositId
function burn(address _token, uint256 _amount, address _withdrawAccount, uint64 _nonce) external;
/**
* @notice Mint tokens triggered by deposit at a remote chain's OriginalTokenVault.
* @param _request The serialized Mint protobuf.
* @param _sigs The list of signatures sorted by signing addresses in ascending order. A relay must be signed-off by
* +2/3 of the sigsVerifier's current signing power to be delivered.
* @param _signers The sorted list of signers.
* @param _powers The signing powers of the signers.
*/
function mint(
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external;
/// @notice Execute a delayed transfer that is now ready
/// @param id The delayed transfer ID to execute
function executeDelayedTransfer(bytes32 id) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title Celer Pegged Token Bridge V2 Interface
/// @notice Interface for Celer's pegged token bridge V2 (xAsset flow - burn side)
/// @dev V2 functions return transferId for better tracking
interface ICelerPeggedTokenBridgeV2 {
/// @notice Burn tokens to trigger withdrawal at a remote chain's OriginalTokenVault (V2)
/// @param _token The local token address
/// @param _amount The amount to burn
/// @param _toChainId The destination chain ID (0 for original vault withdrawal)
/// @param _toAccount The account who will receive tokens on the remote chain
/// @param _nonce A user input to guarantee unique depositId
/// @return burnId The unique burn identifier (transferId)
function burn(
address _token,
uint256 _amount,
uint64 _toChainId,
address _toAccount,
uint64 _nonce
)
external
returns (bytes32 burnId);
/**
* @notice Mint tokens triggered by deposit at a remote chain's OriginalTokenVault.
* @param _request The serialized Mint protobuf.
* @param _sigs The list of signatures sorted by signing addresses in ascending order. A relay must be signed-off by
* +2/3 of the sigsVerifier's current signing power to be delivered.
* @param _signers The sorted list of signers.
* @param _powers The signing powers of the signers.
*/
function mint(
bytes calldata _request,
bytes[] calldata _sigs,
address[] calldata _signers,
uint256[] calldata _powers
)
external
returns (bytes32 mintId);
/// @notice Execute a delayed transfer that is now ready
/// @param id The delayed transfer ID to execute
function executeDelayedTransfer(bytes32 id) external;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title WETH Interface
/// @notice Interface for Wrapped Ether (WETH) contract
/// @dev Standard WETH interface with deposit and withdraw functions
interface IWETH {
/// @notice Deposit ETH to receive WETH
function deposit() external payable;
/// @notice Withdraw WETH to receive ETH
/// @param amount The amount of WETH to withdraw
function withdraw(uint256 amount) external;
/// @notice Approve spender to transfer WETH tokens
/// @param spender The address to approve
/// @param amount The amount to approve
/// @return success True if approval was successful
function approve(address spender, uint256 amount) external returns (bool);
/// @notice Transfer WETH tokens
/// @param to The recipient address
/// @param amount The amount to transfer
/// @return success True if transfer was successful
function transfer(address to, uint256 amount) external returns (bool);
/// @notice Get WETH balance of an account
/// @param account The account to check
/// @return balance The WETH balance
function balanceOf(address account) external view returns (uint256 balance);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
///
/// @dev Note:
/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
library SafeTransferLib {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CUSTOM ERRORS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev The ETH transfer has failed.
error ETHTransferFailed();
/// @dev The ERC20 `transferFrom` has failed.
error TransferFromFailed();
/// @dev The ERC20 `transfer` has failed.
error TransferFailed();
/// @dev The ERC20 `approve` has failed.
error ApproveFailed();
/// @dev The Permit2 operation has failed.
error Permit2Failed();
/// @dev The Permit2 amount must be less than `2**160 - 1`.
error Permit2AmountOverflow();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTANTS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;
/// @dev Suggested gas stipend for contract receiving ETH to perform a few
/// storage reads and writes, but low enough to prevent griefing.
uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;
/// @dev The unique EIP-712 domain domain separator for the DAI token contract.
bytes32 internal constant DAI_DOMAIN_SEPARATOR =
0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;
/// @dev The address for the WETH9 contract on Ethereum mainnet.
address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
/// @dev The canonical Permit2 address.
/// [Github](https://github.com/Uniswap/permit2)
/// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ETH OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
//
// The regular variants:
// - Forwards all remaining gas to the target.
// - Reverts if the target reverts.
// - Reverts if the current contract has insufficient balance.
//
// The force variants:
// - Forwards with an optional gas stipend
// (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
// - If the target reverts, or if the gas stipend is exhausted,
// creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
// Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
// - Reverts if the current contract has insufficient balance.
//
// The try variants:
// - Forwards with a mandatory gas stipend.
// - Instead of reverting, returns whether the transfer succeeded.
/// @dev Sends `amount` (in wei) ETH to `to`.
function safeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Sends all the ETH in the current contract to `to`.
function safeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// Transfer all the ETH and check if it succeeded or not.
if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
/// @solidity memory-safe-assembly
assembly {
if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferETH(address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
if lt(selfbalance(), amount) {
mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
revert(0x1c, 0x04)
}
if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
function forceSafeTransferAllETH(address to) internal {
/// @solidity memory-safe-assembly
assembly {
// forgefmt: disable-next-item
if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
mstore(0x00, to) // Store the address in scratch space.
mstore8(0x0b, 0x73) // Opcode `PUSH20`.
mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
}
}
}
/// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
}
}
/// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
function trySafeTransferAllETH(address to, uint256 gasStipend)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
}
}
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* ERC20 OPERATIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for
/// the current contract to manage.
function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function trySafeTransferFrom(address token, address from, address to, uint256 amount)
internal
returns (bool success)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x60, amount) // Store the `amount` argument.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
success := lt(or(iszero(extcodesize(token)), returndatasize()), success)
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends all of ERC20 `token` from `from` to `to`.
/// Reverts upon failure.
///
/// The `from` account must have their entire balance approved for the current contract to manage.
function safeTransferAllFrom(address token, address from, address to)
internal
returns (uint256 amount)
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40) // Cache the free memory pointer.
mstore(0x40, to) // Store the `to` argument.
mstore(0x2c, shl(96, from)) // Store the `from` argument.
mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
)
) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x60, 0) // Restore the zero slot to zero.
mstore(0x40, m) // Restore the free memory pointer.
}
}
/// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransfer(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sends all of ERC20 `token` from the current contract to `to`.
/// Reverts upon failure.
function safeTransferAll(address token, address to) internal returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
mstore(0x20, address()) // Store the address of the current contract.
// Read the balance, reverting upon failure.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
)
) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
mstore(0x14, to) // Store the `to` argument.
amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
// Perform the transfer, reverting upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// Reverts upon failure.
function safeApprove(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
/// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
/// then retries the approval again (some tokens, e.g. USDT, requires this).
/// Reverts upon failure.
function safeApproveWithRetry(address token, address to, uint256 amount) internal {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, to) // Store the `to` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
// Perform the approval, retrying upon failure.
let success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x34, 0) // Store 0 for the `amount`.
mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
mstore(0x34, amount) // Store back the original `amount`.
// Retry the approval, reverting upon failure.
success := call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
if iszero(and(eq(mload(0x00), 1), success)) {
// Check the `extcodesize` again just in case the token selfdestructs lol.
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
revert(0x1c, 0x04)
}
}
}
}
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}
/// @dev Returns the amount of ERC20 `token` owned by `account`.
/// Returns zero if the `token` does not exist.
function balanceOf(address token, address account) internal view returns (uint256 amount) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x14, account) // Store the `account` argument.
mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
amount :=
mul( // The arguments of `mul` are evaluated from right to left.
mload(0x20),
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x1f), // At least 32 bytes returned.
staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
)
)
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
/// If the initial attempt fails, try to use Permit2 to transfer the token.
/// Reverts upon failure.
///
/// The `from` account must have at least `amount` approved for the current contract to manage.
function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
if (!trySafeTransferFrom(token, from, to, amount)) {
permit2TransferFrom(token, from, to, amount);
}
}
/// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
/// Reverts upon failure.
function permit2TransferFrom(address token, address from, address to, uint256 amount)
internal
{
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(add(m, 0x74), shr(96, shl(96, token)))
mstore(add(m, 0x54), amount)
mstore(add(m, 0x34), to)
mstore(add(m, 0x20), shl(96, from))
// `transferFrom(address,address,uint160,address)`.
mstore(m, 0x36c78516000000000000000000000000)
let p := PERMIT2
let exists := eq(chainid(), 1)
if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
if iszero(
and(
call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00),
lt(iszero(extcodesize(token)), exists) // Token has code and Permit2 exists.
)
) {
mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
}
}
}
/// @dev Permit a user to spend a given amount of
/// another user's tokens via native EIP-2612 permit if possible, falling
/// back to Permit2 if native permit fails or is not implemented on the token.
function permit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
for {} shl(96, xor(token, WETH9)) {} {
mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
if iszero(
and( // The arguments of `and` are evaluated from right to left.
lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
// Gas stipend to limit gas burn for tokens that don't refund gas when
// an non-existing function is called. 5K should be enough for a SLOAD.
staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
)
) { break }
// After here, we can be sure that token is a contract.
let m := mload(0x40)
mstore(add(m, 0x34), spender)
mstore(add(m, 0x20), shl(96, owner))
mstore(add(m, 0x74), deadline)
if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
mstore(0x14, owner)
mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
// `nonces` is already at `add(m, 0x54)`.
// `1` is already stored at `add(m, 0x94)`.
mstore(add(m, 0xb4), and(0xff, v))
mstore(add(m, 0xd4), r)
mstore(add(m, 0xf4), s)
success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
break
}
mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
mstore(add(m, 0x54), amount)
mstore(add(m, 0x94), and(0xff, v))
mstore(add(m, 0xb4), r)
mstore(add(m, 0xd4), s)
success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
break
}
}
if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
}
/// @dev Simple permit on the Permit2 contract.
function simplePermit2(
address token,
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
/// @solidity memory-safe-assembly
assembly {
let m := mload(0x40)
mstore(m, 0x927da105) // `allowance(address,address,address)`.
{
let addressMask := shr(96, not(0))
mstore(add(m, 0x20), and(addressMask, owner))
mstore(add(m, 0x40), and(addressMask, token))
mstore(add(m, 0x60), and(addressMask, spender))
mstore(add(m, 0xc0), and(addressMask, spender))
}
let p := mul(PERMIT2, iszero(shr(160, amount)))
if iszero(
and( // The arguments of `and` are evaluated from right to left.
gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
)
) {
mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
revert(add(0x18, shl(2, iszero(p))), 0x04)
}
mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
// `owner` is already `add(m, 0x20)`.
// `token` is already at `add(m, 0x40)`.
mstore(add(m, 0x60), amount)
mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
// `nonce` is already at `add(m, 0xa0)`.
// `spender` is already at `add(m, 0xc0)`.
mstore(add(m, 0xe0), deadline)
mstore(add(m, 0x100), 0x100) // `signature` offset.
mstore(add(m, 0x120), 0x41) // `signature` length.
mstore(add(m, 0x140), r)
mstore(add(m, 0x160), s)
mstore(add(m, 0x180), shl(248, v))
if iszero( // Revert if token does not have code, or if the call fails.
mul(extcodesize(token), call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00))) {
mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
revert(0x1c, 0x04)
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Libraries
import { SafeTransferLib } from "@solady/utils/SafeTransferLib.sol";
/// @title ERC20 Utility Library
/// @dev Library with common functions used by different modules within the Portikus V2 protocol
library ERC20UtilsLib {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when the permit execution fails
error PermitFailed();
/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
/// @dev An address used to represent the native token
address internal constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
/// @dev The address of the Permit2 contract
address internal constant PERMIT2_ADDRESS = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
/*//////////////////////////////////////////////////////////////
LIBRARIES
//////////////////////////////////////////////////////////////*/
using SafeTransferLib for address;
/*//////////////////////////////////////////////////////////////
TRANSFER
//////////////////////////////////////////////////////////////*/
/// @dev Transfer the dest token to the order beneficiary, reducing the amount by 1 wei for gas optimization
/// purposes. If the destToken is ETH, it will transfer native ETH to recipient
/// @param destToken The address of the dest token
/// @param recipient The address to transfer to
/// @param amount The amount to transfer
function transferTo(address destToken, address recipient, uint256 amount) internal {
// If the destToken is ETH, transfer native ETH
if (isEth(destToken)) {
recipient.safeTransferETH(amount);
} else {
// Otherwise, transfer the dest token to the recipient, reducing the amount by 1 wei
// for gas optimization purposes
destToken.safeTransfer(recipient, amount);
}
}
/// @dev Transfer the src token from the user to a recipient, using permit2 allowance or erc20 allowance based on
/// permit length, if the permit length is 192 or 1 it will call transferFrom using permit2
/// allowance, otherwise it will call transferFrom using erc20 allowance unless permit length is 96
/// @param srcToken The address of the src token
/// @param owner The owner of the token
/// @param recipient The recipient of the token
/// @param amount The amount to transfer
/// @param permitLength The length of the permit
function transferFrom(
address srcToken,
address owner,
address recipient,
uint256 amount,
uint256 permitLength
)
internal
{
// Skip transferring if the permit length is 96 (permit2TransferFrom)
if (permitLength == 96) {
return;
}
// If the permit length is 192 or 1 execute permit2TransferFrom to transfer the
// input assets from the owner to the agent, otherwise execute ERC20 transferFrom
if (permitLength == 192 || permitLength == 1) {
// Transfer the input assets from the owner to the recipient using permit2 allowance
srcToken.permit2TransferFrom(owner, recipient, amount);
} else {
// Transfer the input assets from the owner to the recipient using the ERC20 transferFrom function
srcToken.safeTransferFrom(owner, recipient, amount);
}
}
/*//////////////////////////////////////////////////////////////
PERMIT
//////////////////////////////////////////////////////////////*/
/// @dev Executes the permit function on the provided token, depending on the permit length,
/// it will call the EIP2612 permit (224), DAI-Style permit (256), Permit2 AllowanceTransfer (192)
/// or Permit2 Signature (96)
/// @param token The address of the token
/// @param data The permit data
/// @param owner The owner of the token (used for Permit2)
/// @param deadline The deadline for the permit (used for Permit2)
/// @param amount The amount to permit (used for Permit2)
function permit(
address token,
bytes calldata data,
address owner,
uint256 deadline,
uint256 amount,
address recipient
)
internal
{
// solhint-disable-next-line no-inline-assembly
assembly ("memory-safe") {
// check the permit length
switch data.length
// 0x00 = no permit
case 0x00 {
// do nothing
}
case 0x01 {
// 0x01 is used to signify already existing permit2 allowance
}
// 32(permit2nonce) + 64(signature) = 96 Permit2 Transfer format
case 0x60 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x30f28b7a00000000000000000000000000000000000000000000000000000000) // store the selector
mstore(add(x, 0x04), token) // store the srcToken
mstore(add(x, 0x24), amount) // store the amount
calldatacopy(add(x, 0x44), data.offset, 0x20) // copy the nonce
mstore(add(x, 0x64), deadline) // store the deadline
mstore(add(x, 0x84), recipient) // store the recipient address (executor)
mstore(add(x, 0xa4), amount) // store the amount
mstore(add(x, 0xc4), owner) // store the owner
mstore(add(x, 0xe4), 0x100) // store the offset
mstore(add(x, 0x104), 0x40) // store the length
calldatacopy(add(x, 0x124), add(data.offset, 0x20), 0x40) // copy the signature
// Call Permit2 contract and revert on failure
if iszero(call(gas(), PERMIT2_ADDRESS, 0x00, x, 0x164, 0x00, 0x00)) {
mstore(0x00, 0xb78cb0dd00000000000000000000000000000000000000000000000000000000) // store the
// selector
revert(0x00, 0x04) // Revert with PermitFailed error
}
}
// 32(amount) + 32(nonce) + 32(expiration) + 32(sigDeadline) + 64(signature) = 192 Permit2 allowance format
case 0xc0 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x2b67b57000000000000000000000000000000000000000000000000000000000) // store the selector
mstore(add(x, 0x04), owner) // store the owner address
mstore(add(x, 0x24), token) // store the token address
calldatacopy(add(x, 0x44), data.offset, 0x60) // copy amount, expiration, nonce
mstore(add(x, 0xa4), address()) // store this contract's address as the spender
calldatacopy(add(x, 0xc4), add(data.offset, 0x60), 0x20) // copy sigDeadline
mstore(add(x, 0xe4), 0x100) // store the offset for signature
mstore(add(x, 0x104), 0x40) // store the length of signature
calldatacopy(add(x, 0x124), add(data.offset, 0x80), 0x40) // copy the signature
// Call Permit2 contract and revert on failure
if iszero(call(gas(), PERMIT2_ADDRESS, 0x00, x, 0x164, 0x00, 0x00)) {
mstore(0x00, 0xb78cb0dd00000000000000000000000000000000000000000000000000000000) // store the
// selector
revert(0x00, 0x04) // Revert with PermitFailed error
}
}
// 32 * 7 = 224 EIP2612 Permit
case 0xe0 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0xd505accf00000000000000000000000000000000000000000000000000000000) // store the selector
calldatacopy(add(x, 0x04), data.offset, 0xe0) // store the args
pop(call(gas(), token, 0x00, x, 0xe4, 0x00, 0x20)) // call ERC20 permit, skip checking return data
}
// 32 * 8 = 256 DAI-Style Permit
case 0x100 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x8fcbaf0c00000000000000000000000000000000000000000000000000000000) // store the selector
calldatacopy(add(x, 0x04), data.offset, 0x100) // store the args
pop(call(gas(), token, 0x00, x, 0x104, 0x00, 0x20)) // call ERC20 permit, skip checking return data
}
// Otherwise revert
default {
mstore(0x00, 0xb78cb0dd00000000000000000000000000000000000000000000000000000000) // store the selector
revert(0x00, 0x04) // Revert with PermitFailed error
}
}
}
/// @dev A fillable version of the permit function from this lib, that doesn't support Permit2 SignatureTransfer
/// @param token The address of the token
/// @param data The permit data
/// @param owner The owner of the token (used for Permit2)
function permit(address token, bytes calldata data, address owner) internal {
// solhint-disable-next-line no-inline-assembly
assembly ("memory-safe") {
// check the permit length
switch data.length
// 0x00 = no permit
case 0x00 {
// do nothing
}
case 0x01 {
// 0x01 is used to signify already existing permit2 allowance
}
// 32(amount) + 32(nonce) + 32(expiration) + 32(sigDeadline) + 64(signature) = 192 Permit2 allowance format
case 0xc0 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x2b67b57000000000000000000000000000000000000000000000000000000000) // store the selector
mstore(add(x, 0x04), owner) // store the owner address
mstore(add(x, 0x24), token) // store the token address
calldatacopy(add(x, 0x44), data.offset, 0x60) // copy amount, expiration, nonce
mstore(add(x, 0xa4), address()) // store this contract's address as the spender
calldatacopy(add(x, 0xc4), add(data.offset, 0x60), 0x20) // copy sigDeadline
mstore(add(x, 0xe4), 0x100) // store the offset for signature
mstore(add(x, 0x104), 0x40) // store the length of signature
calldatacopy(add(x, 0x124), add(data.offset, 0x80), 0x40) // copy the signature
// Call Permit2 contract and revert on failure
if iszero(call(gas(), PERMIT2_ADDRESS, 0x00, x, 0x164, 0x00, 0x00)) {
mstore(0x00, 0xb78cb0dd00000000000000000000000000000000000000000000000000000000) // store the
// selector
revert(0x00, 0x04) // Revert with PermitFailed error
}
}
// 32 * 7 = 224 EIP2612 Permit
case 0xe0 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0xd505accf00000000000000000000000000000000000000000000000000000000) // store the selector
calldatacopy(add(x, 0x04), data.offset, 0xe0) // store the args
pop(call(gas(), token, 0x00, x, 0xe4, 0x00, 0x20)) // call ERC20 permit, skip checking return data
}
// 32 * 8 = 256 DAI-Style Permit
case 0x100 {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x8fcbaf0c00000000000000000000000000000000000000000000000000000000) // store the selector
calldatacopy(add(x, 0x04), data.offset, 0x100) // store the args
pop(call(gas(), token, 0x00, x, 0x104, 0x00, 0x20)) // call ERC20 permit, skip checking return data
}
// Otherwise revert
default {
mstore(0x00, 0xb78cb0dd00000000000000000000000000000000000000000000000000000000) // store the selector
revert(0x00, 0x04) // Revert with PermitFailed error
}
}
}
/*//////////////////////////////////////////////////////////////
UTILITIES
//////////////////////////////////////////////////////////////*/
/// @notice Checks if a token is ETH
/// @param token The token address to check
/// @return True if the token represents ETH
function isEth(address token) internal pure returns (bool) {
return token == ETH_ADDRESS;
}
/*//////////////////////////////////////////////////////////////
BALANCE
//////////////////////////////////////////////////////////////*/
/// @dev Returns the balance of address(this), works for both ETH and ERC20 tokens
function getBalance(address token) internal view returns (uint256 balanceOf) {
// solhint-disable-next-line no-inline-assembly
assembly {
switch eq(token, ETH_ADDRESS)
// ETH
case 0x01 { balanceOf := selfbalance() }
// ERC20
default {
let x := mload(0x40) // get the free memory pointer
mstore(x, 0x70a0823100000000000000000000000000000000000000000000000000000000) // store the selector
mstore(add(x, 0x04), address()) // store the account
let success := staticcall(gas(), token, x, 0x24, x, 0x20) // call balanceOf
if success { balanceOf := mload(x) } // load the balance
}
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Types
import { Order } from "@types/Order.sol";
import { Bridge } from "@types/Bridge.sol";
/// @title Order Hash Library
/// @dev Library with functions to handle hashing of Order structs
library OrderHashLib {
/*//////////////////////////////////////////////////////////////
TYPESTRINGS
//////////////////////////////////////////////////////////////*/
/// @dev The type of the order struct
bytes internal constant _ORDER_TYPESTRING = // solhint-disable-next-line max-line-length
"Order(address owner,address beneficiary,address srcToken,address destToken,uint256 srcAmount,uint256 destAmount,uint256 expectedAmount,uint256 deadline,uint8 kind,uint256 nonce,uint256 partnerAndFee,bytes permit,bytes metadata,Bridge bridge)Bridge(bytes4 protocolSelector,uint256 destinationChainId,address outputToken,int8 scalingFactor,bytes protocolData)";
bytes internal constant _BRIDGE_TYPESTRING = // solhint-disable-next-line max-line-length
"Bridge(bytes4 protocolSelector,uint256 destinationChainId,address outputToken,int8 scalingFactor,bytes protocolData)";
/*//////////////////////////////////////////////////////////////
TYPEHASH
//////////////////////////////////////////////////////////////*/
/// @dev The type hash of the order struct
bytes32 internal constant _ORDER_TYPEHASH = 0xc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7;
/// @dev The type hash of the Bridge struct
bytes32 internal constant _BRIDGE_TYPEHASH = 0x8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb;
/*//////////////////////////////////////////////////////////////
HASH
//////////////////////////////////////////////////////////////*/
/// @dev EIP-712 struct-hash of an `Order` (all done in assembly, no `abi.encode`)
/// @param order The order to hash
/// @return result The 32-byte hash
function hash(Order memory order) internal pure returns (bytes32 result) {
// Pre-compute hash of the dynamic bytes field
bytes32 permitHash = keccak256(order.permit);
bytes32 metadataHash = keccak256(order.metadata);
bytes32 protocolDataHash = keccak256(order.bridge.protocolData);
// bring struct into the stack
Bridge memory bridge = order.bridge;
assembly ("memory-safe") {
/* ───────────────────────────────── Bridge hash ─────────────────────── */
let ptr := mload(0x40) // free-mem pointer
mstore(ptr, _BRIDGE_TYPEHASH) // type-hash
mstore(add(ptr, 0x20), mload(bridge)) // protocolSelector (bytes4)
mstore(add(ptr, 0x40), mload(add(bridge, 0x20))) // destinationChainId
mstore(add(ptr, 0x60), mload(add(bridge, 0x40))) // outputToken
mstore(add(ptr, 0x80), signextend(0, mload(add(bridge, 0x60)))) // scalingFactor (int8)
mstore(add(ptr, 0xA0), protocolDataHash) // keccak256(protocolData)
let bridgeHash := keccak256(ptr, 0xC0) // 6 words → 192 bytes
/* ────────────────────────────── Order hash ────────────────────────── */
ptr := add(ptr, 0xC0) // reuse memory after bridge blob
mstore(ptr, _ORDER_TYPEHASH) // 0x00 type-hash
mstore(add(ptr, 0x20), mload(order)) // owner
mstore(add(ptr, 0x40), mload(add(order, 0x20))) // beneficiary
mstore(add(ptr, 0x60), mload(add(order, 0x40))) // srcToken
mstore(add(ptr, 0x80), mload(add(order, 0x60))) // destToken
mstore(add(ptr, 0xA0), mload(add(order, 0x80))) // srcAmount
mstore(add(ptr, 0xC0), mload(add(order, 0xA0))) // destAmount
mstore(add(ptr, 0xE0), mload(add(order, 0xC0))) // expectedAmount
mstore(add(ptr, 0x100), mload(add(order, 0xE0))) // deadline
mstore(add(ptr, 0x120), mload(add(order, 0x100))) // kind
mstore(add(ptr, 0x140), mload(add(order, 0x120))) // nonce
mstore(add(ptr, 0x160), mload(add(order, 0x140))) // partnerAndFee
mstore(add(ptr, 0x180), permitHash) // keccak256(order.permit)
mstore(add(ptr, 0x1A0), metadataHash) // keccak256(order.metadata)
mstore(add(ptr, 0x1C0), bridgeHash) // keccak256(Bridge blob)
result := keccak256(ptr, 0x1E0) // 15 words → 480 bytes
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { Address } from "@openzeppelin/utils/Address.sol";
// Types
import { Order } from "@types/Order.sol";
/// @title Bridge Library
/// @dev A library that provides functions for bridging tokens using various protocols
library BridgeLib {
using Address for address;
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice keccak256(abi.encode(uint256(keccak256("BridgeLib.initiated")) - 1)) & ~bytes32(uint256(0xff));
bytes32 internal constant BRIDGE_INITIATED_SLOT = 0x55784d688e8aecdf5908e67d2532e5fa1b0a3f379bbfebaef09e5fc7c0e69100;
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Thrown when bridge is not initiated
error BridgeNotInitiated();
/*//////////////////////////////////////////////////////////////
BRIDGE INITIATION
//////////////////////////////////////////////////////////////*/
/// @notice Initiates a bridge operation to allow bridge calls
/// @dev Should only be called by settlement modules after proper validation
function initiateBridge() internal {
bytes32 slot = BRIDGE_INITIATED_SLOT;
/// @solidity memory-safe-assembly
assembly {
sstore(slot, 1)
}
}
/// @notice Completes a bridge operation to prevent further bridge calls
/// @dev Should be called after bridge execution is complete
function completeBridge() internal {
bytes32 slot = BRIDGE_INITIATED_SLOT;
/// @solidity memory-safe-assembly
assembly {
sstore(slot, 0)
}
}
/// @notice Checks if bridge operation is currently initiated
/// @return initiated True if bridge is initiated, false otherwise
function isBridgeInitiated() internal view returns (bool initiated) {
bytes32 slot = BRIDGE_INITIATED_SLOT;
/// @solidity memory-safe-assembly
assembly {
initiated := sload(slot)
}
}
/// @notice Modifier function to require bridge initiation
/// @dev Should be called at the beginning of bridge functions
function requireBridgeInitiated() internal view {
if (!isBridgeInitiated()) {
revert BridgeNotInitiated();
}
}
/*//////////////////////////////////////////////////////////////
UNIVERSAL BRIDGE
//////////////////////////////////////////////////////////////*/
/// @notice Universal bridge function that handles dynamic routing to different bridge protocols
/// @dev Bridge protocol is determined by order.bridge.protocolSelector (set by protocol backend)
/// @param order The order containing bridge details with protocolSelector
/// @param beneficiary The address of the beneficiary
/// @param amount The amount of tokens to bridge
/// @param bridgeData The encoded protocol-specific bridge data containing agent-provided execution parameters
/// @return nativeFee The native fee paid to the bridge protocol, 0 if not applicable
function doBridge(
Order memory order,
address beneficiary,
uint256 amount,
bytes memory bridgeData
)
internal
returns (uint256 nativeFee)
{
// Initiate bridge operation before making the bridge call
initiateBridge();
// Call the bridge function using the protocol selector from the order (set by backend)
// bridgeData is passed directly as protocol-specific data
// Use OpenZeppelin's Address library for better error handling and revert reason bubbling
bytes memory result = address(this).functionDelegateCall(
abi.encodeWithSelector(order.bridge.protocolSelector, order, beneficiary, amount, bridgeData)
);
if (result.length != 0) nativeFee = abi.decode(result, (uint256));
// Complete bridge operation after the call
completeBridge();
}
/*//////////////////////////////////////////////////////////////
BRIDGE UTILITIES
//////////////////////////////////////////////////////////////*/
/// @notice Checks if the given order requires bridging
/// @param order The order to check
/// @return bool True if the order is a bridge order, false otherwise
function isBridge(Order memory order) internal view returns (bool) {
return order.bridge.destinationChainId != 0 && order.bridge.destinationChainId != block.chainid;
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Interfaces
import { IERC1271 } from "@interfaces/util/IERC1271.sol";
/// @title SignatureLib
/// @notice Library with functions to handle signature verification
/// @dev Supports EIP-2098 and ERC-1271 signatures
library SignatureLib {
/*//////////////////////////////////////////////////////////////
ERRORS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when the signature is invalid
error InvalidSignature();
/// @notice Emitted when the signer is invalid
error InvalidSigner();
/// @notice Emitted when the order is not pre signed
error NotPreSigned();
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
/// @notice Emitted when a pre signature is set
event PreSignatureSet(address indexed owner, bytes32 indexed orderHash, bool preSigned);
/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
/// @dev Used to mask the upper bit of a bytes32 value
bytes32 internal constant UPPER_BIT_MASK = (0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
/*//////////////////////////////////////////////////////////////
STORAGE
//////////////////////////////////////////////////////////////*/
/// @notice keccak256(abi.encode(uint256(keccak256("SignatureLib.preSignatures")) - 1)) & ~bytes32(uint256(0xff));
bytes32 internal constant PRE_SIGNATURES_SLOT = 0xc1c92bf4984cdb794b68c76840d7fa5d7356e7dac4a0bbc75375ce7b7b683800;
/// @custom:storage-location erc7201:SignatureLib.preSignatures
/// @notice The structure that defines the storage layout containing pre signatures, storage collisions are avoided
/// following the ERC-7201 standard
/// @param preSignatures A mapping of preSignatures for each user to an order hash,
/// where boolean indicates if the order was pre signed
struct PreSignatureStorage {
mapping(address owner => mapping(bytes32 orderHash => bool preSigned)) preSignatures;
}
/// @notice Get the pointer to the pre signatures storage slot
/// @return s The pointer to the pre signatures storage slot
function preSignaturesStorage() internal pure returns (PreSignatureStorage storage s) {
bytes32 slot = PRE_SIGNATURES_SLOT;
assembly {
s.slot := slot
}
}
/*//////////////////////////////////////////////////////////////
VERIFY
//////////////////////////////////////////////////////////////*/
/// @dev Verifies the signature of the provided data
/// @notice The signature must be in EIP-2098 format or empty in case the order is pre signed
/// @param signature The signature to verify
/// @param hash The hash of the data to verify
/// @param signer The expected signer of the data
function verify(bytes memory signature, bytes32 hash, address signer) internal view {
// - If signature is emitted, check if the order is pre signed
// - If signer is an EOA or a delegated EOA (EIP-7702), check EIP-2098 signature format
// - If signer is a contract, check ERC-1271 signature format
if (signature.length == 0) {
bool preSigned = isPreSigned(signer, hash);
if (!preSigned) revert NotPreSigned();
} else if (_isEOA(signer)) {
if (signature.length != 64) revert InvalidSignature();
// Verify using EIP-2098 signature format
// - signature is 64 bytes long
// - r is the first 32 bytes
// - vs is the last 32 bytes
// - v is the last byte of vs
// - s is the first 31 bytes of vs
(bytes32 r, bytes32 vs) = abi.decode(signature, (bytes32, bytes32));
bytes32 s = vs & UPPER_BIT_MASK;
uint8 v = uint8(uint256(vs >> 255)) + 27;
address actualSigner = ecrecover(hash, v, r, s);
if (actualSigner == address(0)) revert InvalidSignature();
if (actualSigner != signer) revert InvalidSigner();
} else {
bytes4 magicValue = IERC1271(signer).isValidSignature(hash, signature);
if (magicValue != IERC1271(signer).isValidSignature.selector) revert InvalidSignature();
}
}
/// @dev Detects if the address is an EOA or a delegated EOA (EIP-7702)
function _isEOA(address who) private view returns (bool) {
uint256 csize = address(who).code.length;
// EOA
if (csize == 0) return true;
// Delegated EOA (EIP-7702)
if (csize == 23) {
bytes32 word;
assembly {
let ptr := mload(0x40)
extcodecopy(who, ptr, 0, 3) // copy first 3 bytes
word := mload(ptr) // load the 32-byte word
}
return bytes3(word) == 0xef0100;
}
return false;
}
/*//////////////////////////////////////////////////////////////
PRE SIGNATURE
//////////////////////////////////////////////////////////////*/
/// @notice Sets pre signature for a specific order hash
/// @param owner The address of the order owner
/// @param orderHash The specific order hash to set
/// @param preSigned True if the order should be pre signed, false if the pre signature should be revoked
function setPreSigned(address owner, bytes32 orderHash, bool preSigned) internal {
preSignaturesStorage().preSignatures[owner][orderHash] = preSigned;
emit PreSignatureSet(owner, orderHash, preSigned);
}
/// @notice Checks if an order is pre signed
/// @param owner The address of the order owner
/// @param orderHash The specific order hash to check
/// @return True if the order is pre signed, false otherwise
function isPreSigned(address owner, bytes32 orderHash) internal view returns (bool) {
return preSignaturesStorage().preSignatures[owner][orderHash];
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
import { Bridge } from "./Bridge.sol";
/// @dev OrderKind enum to differentiate between sell and buy orders
enum OrderKind {
SELL,
BUY
}
/// @dev Order data structure containing the order details to be settled,
/// the order is signed by the owner to be executed by an agent
/// on behalf of the owner, executing the swap and transferring the
/// dest token to the beneficiary
struct Order {
/// @dev The address of the order owner
address owner;
/// @dev The address of the order beneficiary
address beneficiary;
/// @dev The address of the src token
address srcToken;
/// @dev The address of the dest token
address destToken;
/// @dev The amount of src token to swap
uint256 srcAmount;
/// @dev The minimum amount of dest token to receive
uint256 destAmount;
/// @dev The expected amount of tokens (for sell orders this is expected amount of dest token to receive, for buy
/// orders this is the expected amount of src token to spend)
uint256 expectedAmount;
/// @dev The deadline for the order (timestamp)
uint256 deadline;
/// @dev The type of order (SELL or BUY)
OrderKind kind;
/// @dev The nonce of the order
uint256 nonce;
/// @dev Encoded partner address, fee bps, and flags for the order
/// partnerAndFee = (partner << 96) | (partnerTakesSurplus << 8) | (capSurplus << 9) |
/// fee in bps (max fee is 2%)
uint256 partnerAndFee;
/// @dev Optional permit signature for the src token
bytes permit;
/// @dev Optional metadata for the order
bytes metadata;
/// @dev The bridge configuration, should contain all empty fields if cross-chain is not required
Bridge bridge;
}
/// @dev Order with signature
struct OrderWithSig {
/// @dev The order data
Order order;
/// @dev The signature of the order
bytes signature;
}// SPDX-License-Identifier: GPL-3.0-only
// COPIED FROM: celer-network/sgn-v2-contracts/contracts/libraries/PbPegged.sol
// REASON: Solidity version incompatibility (original uses 0.8.9, we need 0.8.25)
// CHANGES: Only updated pragma statement from "pragma solidity 0.8.9;" to "pragma solidity 0.8.25;"
// NOTE: All functionality remains identical to the original Celer implementation
// Code generated by protoc-gen-sol. DO NOT EDIT.
// source: contracts/libraries/proto/pegged.proto
pragma solidity 0.8.25;
import "./Pb.sol";
library PbPegged {
using Pb for Pb.Buffer; // so we can call Pb funcs on Buffer obj
struct Mint {
address token; // tag: 1
address account; // tag: 2
uint256 amount; // tag: 3
address depositor; // tag: 4
uint64 refChainId; // tag: 5
bytes32 refId; // tag: 6
} // end struct Mint
function decMint(bytes memory raw) internal pure returns (Mint memory m) {
Pb.Buffer memory buf = Pb.fromBytes(raw);
uint256 tag;
Pb.WireType wire;
while (buf.hasMore()) {
(tag, wire) = buf.decKey();
if (false) { }
// solidity has no switch/case
else if (tag == 1) {
m.token = Pb._address(buf.decBytes());
} else if (tag == 2) {
m.account = Pb._address(buf.decBytes());
} else if (tag == 3) {
m.amount = Pb._uint256(buf.decBytes());
} else if (tag == 4) {
m.depositor = Pb._address(buf.decBytes());
} else if (tag == 5) {
m.refChainId = uint64(buf.decVarint());
} else if (tag == 6) {
m.refId = Pb._bytes32(buf.decBytes());
} else {
buf.skipValue(wire);
} // skip value of unknown tag
}
} // end decoder Mint
struct Withdraw {
address token; // tag: 1
address receiver; // tag: 2
uint256 amount; // tag: 3
address burnAccount; // tag: 4
uint64 refChainId; // tag: 5
bytes32 refId; // tag: 6
} // end struct Withdraw
function decWithdraw(bytes memory raw) internal pure returns (Withdraw memory m) {
Pb.Buffer memory buf = Pb.fromBytes(raw);
uint256 tag;
Pb.WireType wire;
while (buf.hasMore()) {
(tag, wire) = buf.decKey();
if (false) { }
// solidity has no switch/case
else if (tag == 1) {
m.token = Pb._address(buf.decBytes());
} else if (tag == 2) {
m.receiver = Pb._address(buf.decBytes());
} else if (tag == 3) {
m.amount = Pb._uint256(buf.decBytes());
} else if (tag == 4) {
m.burnAccount = Pb._address(buf.decBytes());
} else if (tag == 5) {
m.refChainId = uint64(buf.decVarint());
} else if (tag == 6) {
m.refId = Pb._bytes32(buf.decBytes());
} else {
buf.skipValue(wire);
} // skip value of unknown tag
}
} // end decoder Withdraw
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[ERC-191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an ERC-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (ERC-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title IEIP712
/// @notice Interface for the fetching the EIP-712 domain separator
interface IEIP712 {
/*//////////////////////////////////////////////////////////////
EXTERNAL
//////////////////////////////////////////////////////////////*/
/// @notice Returns the domain separator for the EIP-712 signature
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
// Contracts
import { ReentrancyGuardTransient as ReentrancyGuard } from "@openzeppelin/utils/ReentrancyGuardTransient.sol";
// Interfaces
import { IModule } from "@modules/interfaces/IModule.sol";
// Libraries
import { ShortStrings, ShortString } from "@openzeppelin/utils/ShortStrings.sol";
/// @title Base Module
/// @notice An abstract base module to be inherited by all modules in the Portikus V2 protocol
abstract contract BaseModule is ReentrancyGuard, IModule {
/*//////////////////////////////////////////////////////////////
LIBRARIES
//////////////////////////////////////////////////////////////*/
using ShortStrings for string;
using ShortStrings for ShortString;
/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
/// @notice The name and version of the module
ShortString private immutable NAME;
ShortString private immutable VERSION;
/// @notice The address of the Portikus V2 contract
address public immutable PORTIKUS_V2;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
/// @param _name The name of the module
/// @param _version The version of the module
constructor(string memory _name, string memory _version, address _portikusV2) {
NAME = _name.toShortString();
VERSION = _version.toShortString();
PORTIKUS_V2 = _portikusV2;
}
/*//////////////////////////////////////////////////////////////
METADATA
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IModule
function name() external view virtual override returns (string memory) {
return NAME.toString();
}
/// @inheritdoc IModule
function version() external view virtual override returns (string memory) {
return VERSION.toString();
}
/*//////////////////////////////////////////////////////////////
SELECTORS
//////////////////////////////////////////////////////////////*/
/// @inheritdoc IModule
function selectors() external pure virtual override returns (bytes4[] memory moduleSelectors);
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @dev Represents bridge configuration for cross-chain operations
/// This struct is part of the Order and is signed by the user
/// Bridge selection is now the protocol's responsibility (set by backend)
struct Bridge {
/// @dev The bridge protocol selector
/// This determines which bridge module will be used for execution
bytes4 protocolSelector;
/// @dev The destination chain ID where tokens should be bridged
uint256 destinationChainId;
/// @dev The token address on the destination chain
address outputToken;
/// @dev Represents destDecimals - srcDecimals to convert between token decimal formats
/// Positive: dest has more decimals, divide amounts before bridge
/// Negative: src has more decimals, multiply amounts before bridge
/// Zero: same decimals, no conversion needed
int8 scalingFactor;
/// @dev Protocol-specific configuration data
/// Contains immutable parameters like destEid for Stargate or multiCallHandler for Across
bytes protocolData;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
/// @title IERC1271
/// @notice Interface for contracts implementing the ERC-1271 standard
interface IERC1271 {
/// @dev Should return whether the signature provided is valid for the provided data
/// @param hash Hash of the data to be signed
/// @param signature Signature byte array associated with _data
/// @return magicValue The bytes4 magic value 0x1626ba7e
function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}// SPDX-License-Identifier: GPL-3.0-only
// COPIED FROM: celer-network/sgn-v2-contracts/contracts/libraries/Pb.sol
// REASON: Solidity version incompatibility (original uses 0.8.9, we need 0.8.25)
// CHANGES: Only updated pragma statement from "pragma solidity 0.8.9;" to "pragma solidity 0.8.25;"
// NOTE: All functionality remains identical to the original Celer implementation
pragma solidity 0.8.25;
// runtime proto sol library
library Pb {
enum WireType {
Varint,
Fixed64,
LengthDelim,
StartGroup,
EndGroup,
Fixed32
}
struct Buffer {
uint256 idx; // the start index of next read. when idx=b.length, we're done
bytes b; // hold serialized proto msg, readonly
}
// create a new in-memory Buffer object from raw msg bytes
function fromBytes(bytes memory raw) internal pure returns (Buffer memory buf) {
buf.b = raw;
buf.idx = 0;
}
// whether there are unread bytes
function hasMore(Buffer memory buf) internal pure returns (bool) {
return buf.idx < buf.b.length;
}
// decode current field number and wiretype
function decKey(Buffer memory buf) internal pure returns (uint256 tag, WireType wiretype) {
uint256 v = decVarint(buf);
tag = v / 8;
wiretype = WireType(v & 7);
}
// count tag occurrences, return an array due to no memory map support
// have to create array for (maxtag+1) size. cnts[tag] = occurrences
// should keep buf.idx unchanged because this is only a count function
function cntTags(Buffer memory buf, uint256 maxtag) internal pure returns (uint256[] memory cnts) {
uint256 originalIdx = buf.idx;
cnts = new uint256[](maxtag + 1); // protobuf's tags are from 1 rather than 0
uint256 tag;
WireType wire;
while (hasMore(buf)) {
(tag, wire) = decKey(buf);
cnts[tag] += 1;
skipValue(buf, wire);
}
buf.idx = originalIdx;
}
// read varint from current buf idx, move buf.idx to next read, return the int value
function decVarint(Buffer memory buf) internal pure returns (uint256 v) {
bytes10 tmp; // proto int is at most 10 bytes (7 bits can be used per byte)
bytes memory bb = buf.b; // get buf.b mem addr to use in assembly
v = buf.idx; // use v to save one additional uint variable
assembly {
tmp := mload(add(add(bb, 32), v)) // load 10 bytes from buf.b[buf.idx] to tmp
}
uint256 b; // store current byte content
v = 0; // reset to 0 for return value
for (uint256 i = 0; i < 10; i++) {
assembly {
b := byte(i, tmp) // don't use tmp[i] because it does bound check and costs extra
}
v |= (b & 0x7F) << (i * 7);
if (b & 0x80 == 0) {
buf.idx += i + 1;
return v;
}
}
revert(); // i=10, invalid varint stream
}
// read length delimited field and return bytes
function decBytes(Buffer memory buf) internal pure returns (bytes memory b) {
uint256 len = decVarint(buf);
uint256 end = buf.idx + len;
require(end <= buf.b.length); // avoid overflow
b = new bytes(len);
bytes memory bufB = buf.b; // get buf.b mem addr to use in assembly
uint256 bStart;
uint256 bufBStart = buf.idx;
assembly {
bStart := add(b, 32)
bufBStart := add(add(bufB, 32), bufBStart)
}
for (uint256 i = 0; i < len; i += 32) {
assembly {
mstore(add(bStart, i), mload(add(bufBStart, i)))
}
}
buf.idx = end;
}
// return packed ints
function decPacked(Buffer memory buf) internal pure returns (uint256[] memory t) {
uint256 len = decVarint(buf);
uint256 end = buf.idx + len;
require(end <= buf.b.length); // avoid overflow
// array in memory must be init w/ known length
// so we have to create a tmp array w/ max possible len first
uint256[] memory tmp = new uint256[](len);
uint256 i = 0; // count how many ints are there
while (buf.idx < end) {
tmp[i] = decVarint(buf);
i++;
}
t = new uint256[](i); // init t with correct length
for (uint256 j = 0; j < i; j++) {
t[j] = tmp[j];
}
return t;
}
// move idx pass current value field, to beginning of next tag or msg end
function skipValue(Buffer memory buf, WireType wire) internal pure {
if (wire == WireType.Varint) {
decVarint(buf);
} else if (wire == WireType.LengthDelim) {
uint256 len = decVarint(buf);
buf.idx += len; // skip len bytes value data
require(buf.idx <= buf.b.length); // avoid overflow
} else {
revert();
} // unsupported wiretype
}
// type conversion help utils
function _bool(uint256 x) internal pure returns (bool v) {
return x != 0;
}
function _uint256(bytes memory b) internal pure returns (uint256 v) {
require(b.length <= 32); // b's length must be smaller than or equal to 32
assembly {
v := mload(add(b, 32))
} // load all 32bytes to v
v = v >> (8 * (32 - b.length)); // only first b.length is valid
}
function _address(bytes memory b) internal pure returns (address v) {
v = _addressPayable(b);
}
function _addressPayable(bytes memory b) internal pure returns (address payable v) {
require(b.length == 20);
//load 32bytes then shift right 12 bytes
assembly {
v := div(mload(add(b, 32)), 0x1000000000000000000000000)
}
}
function _bytes32(bytes memory b) internal pure returns (bytes32 v) {
require(b.length == 32);
assembly {
v := mload(add(b, 32))
}
}
// uint[] to uint8[]
function uint8s(uint256[] memory arr) internal pure returns (uint8[] memory t) {
t = new uint8[](arr.length);
for (uint256 i = 0; i < t.length; i++) {
t[i] = uint8(arr[i]);
}
}
function uint32s(uint256[] memory arr) internal pure returns (uint32[] memory t) {
t = new uint32[](arr.length);
for (uint256 i = 0; i < t.length; i++) {
t[i] = uint32(arr[i]);
}
}
function uint64s(uint256[] memory arr) internal pure returns (uint64[] memory t) {
t = new uint64[](arr.length);
for (uint256 i = 0; i < t.length; i++) {
t[i] = uint64(arr[i]);
}
}
function bools(uint256[] memory arr) internal pure returns (bool[] memory t) {
t = new bool[](arr.length);
for (uint256 i = 0; i < t.length; i++) {
t[i] = arr[i] != 0;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its checksummed ASCII `string` hexadecimal
* representation, according to EIP-55.
*/
function toChecksumHexString(address addr) internal pure returns (string memory) {
bytes memory buffer = bytes(toHexString(addr));
// hash the hex part of buffer (skip length + 2 bytes, length 40)
uint256 hashValue;
assembly ("memory-safe") {
hashValue := shr(96, keccak256(add(buffer, 0x22), 40))
}
for (uint256 i = 41; i > 1; --i) {
// possible values for buffer[i] are 48 (0) to 57 (9) and 97 (a) to 102 (f)
if (hashValue & 0xf > 7 && uint8(buffer[i]) > 96) {
// case shift by xoring with 0x20
buffer[i] ^= 0x20;
}
hashValue >>= 4;
}
return string(buffer);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
import {StorageSlot} from "./StorageSlot.sol";
/**
* @dev Variant of {ReentrancyGuard} that uses transient storage.
*
* NOTE: This variant only works on networks where EIP-1153 is available.
*/
abstract contract ReentrancyGuardTransient {
using StorageSlot for *;
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant REENTRANCY_GUARD_STORAGE =
0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_reentrancyGuardEntered()) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(true);
}
function _nonReentrantAfter() private {
REENTRANCY_GUARD_STORAGE.asBoolean().tstore(false);
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return REENTRANCY_GUARD_STORAGE.asBoolean().tload();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an success flag (no overflow).
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a success flag (no division by zero).
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a success flag (no division by zero).
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * SafeCast.toUint(condition));
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
Panic.panic(Panic.DIVISION_BY_ZERO);
}
// The following calculation ensures accurate ceiling division without overflow.
// Since a is non-zero, (a - 1) / b will not overflow.
// The largest possible result occurs when (a - 1) / b is type(uint256).max,
// but the largest value we can obtain is type(uint256).max - 1, which happens
// when a = type(uint256).max and b = 1.
unchecked {
return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
}
}
/**
* @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
*
* Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2²⁵⁶ + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
if (denominator <= prod1) {
Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
// that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv ≡ 1 mod 2⁴.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2⁸
inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
inverse *= 2 - denominator * inverse; // inverse mod 2³²
inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
// less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
}
/**
* @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
*
* If n is a prime, then Z/nZ is a field. In that case all elements are inversible, expect 0.
* If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
*
* If the input value is not inversible, 0 is returned.
*
* NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
* inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
*/
function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
unchecked {
if (n == 0) return 0;
// The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
// Used to compute integers x and y such that: ax + ny = gcd(a, n).
// When the gcd is 1, then the inverse of a modulo n exists and it's x.
// ax + ny = 1
// ax = 1 + (-y)n
// ax ≡ 1 (mod n) # x is the inverse of a modulo n
// If the remainder is 0 the gcd is n right away.
uint256 remainder = a % n;
uint256 gcd = n;
// Therefore the initial coefficients are:
// ax + ny = gcd(a, n) = n
// 0a + 1n = n
int256 x = 0;
int256 y = 1;
while (remainder != 0) {
uint256 quotient = gcd / remainder;
(gcd, remainder) = (
// The old remainder is the next gcd to try.
remainder,
// Compute the next remainder.
// Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
// where gcd is at most n (capped to type(uint256).max)
gcd - remainder * quotient
);
(x, y) = (
// Increment the coefficient of a.
y,
// Decrement the coefficient of n.
// Can overflow, but the result is casted to uint256 so that the
// next value of y is "wrapped around" to a value between 0 and n - 1.
x - y * int256(quotient)
);
}
if (gcd != 1) return 0; // No inverse exists.
return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
}
}
/**
* @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
*
* From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
* prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
* `a**(p-2)` is the modular multiplicative inverse of a in Fp.
*
* NOTE: this function does NOT check that `p` is a prime greater than `2`.
*/
function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
unchecked {
return Math.modExp(a, p - 2, p);
}
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
*
* Requirements:
* - modulus can't be zero
* - underlying staticcall to precompile must succeed
*
* IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
* sure the chain you're using it on supports the precompiled contract for modular exponentiation
* at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
* the underlying function will succeed given the lack of a revert, but the result may be incorrectly
* interpreted as 0.
*/
function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
(bool success, uint256 result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
* It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
* to operate modulo 0 or if the underlying precompile reverted.
*
* IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
* you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
* https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
* of a revert, but the result may be incorrectly interpreted as 0.
*/
function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
if (m == 0) return (false, 0);
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
// | Offset | Content | Content (Hex) |
// |-----------|------------|--------------------------------------------------------------------|
// | 0x00:0x1f | size of b | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x20:0x3f | size of e | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x40:0x5f | size of m | 0x0000000000000000000000000000000000000000000000000000000000000020 |
// | 0x60:0x7f | value of b | 0x<.............................................................b> |
// | 0x80:0x9f | value of e | 0x<.............................................................e> |
// | 0xa0:0xbf | value of m | 0x<.............................................................m> |
mstore(ptr, 0x20)
mstore(add(ptr, 0x20), 0x20)
mstore(add(ptr, 0x40), 0x20)
mstore(add(ptr, 0x60), b)
mstore(add(ptr, 0x80), e)
mstore(add(ptr, 0xa0), m)
// Given the result < m, it's guaranteed to fit in 32 bytes,
// so we can use the memory scratch space located at offset 0.
success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
result := mload(0x00)
}
}
/**
* @dev Variant of {modExp} that supports inputs of arbitrary length.
*/
function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
(bool success, bytes memory result) = tryModExp(b, e, m);
if (!success) {
Panic.panic(Panic.DIVISION_BY_ZERO);
}
return result;
}
/**
* @dev Variant of {tryModExp} that supports inputs of arbitrary length.
*/
function tryModExp(
bytes memory b,
bytes memory e,
bytes memory m
) internal view returns (bool success, bytes memory result) {
if (_zeroBytes(m)) return (false, new bytes(0));
uint256 mLen = m.length;
// Encode call args in result and move the free memory pointer
result = abi.encodePacked(b.length, e.length, mLen, b, e, m);
/// @solidity memory-safe-assembly
assembly {
let dataPtr := add(result, 0x20)
// Write result on top of args to avoid allocating extra memory.
success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
// Overwrite the length.
// result.length > returndatasize() is guaranteed because returndatasize() == m.length
mstore(result, mLen)
// Set the memory pointer after the returned data.
mstore(0x40, add(dataPtr, mLen))
}
}
/**
* @dev Returns whether the provided byte array is zero.
*/
function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
for (uint256 i = 0; i < byteArray.length; ++i) {
if (byteArray[i] != 0) {
return false;
}
}
return true;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* This method is based on Newton's method for computing square roots; the algorithm is restricted to only
* using integer operations.
*/
function sqrt(uint256 a) internal pure returns (uint256) {
unchecked {
// Take care of easy edge cases when a == 0 or a == 1
if (a <= 1) {
return a;
}
// In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
// sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
// the current value as `ε_n = | x_n - sqrt(a) |`.
//
// For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
// of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
// bigger than any uint256.
//
// By noticing that
// `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
// we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
// to the msb function.
uint256 aa = a;
uint256 xn = 1;
if (aa >= (1 << 128)) {
aa >>= 128;
xn <<= 64;
}
if (aa >= (1 << 64)) {
aa >>= 64;
xn <<= 32;
}
if (aa >= (1 << 32)) {
aa >>= 32;
xn <<= 16;
}
if (aa >= (1 << 16)) {
aa >>= 16;
xn <<= 8;
}
if (aa >= (1 << 8)) {
aa >>= 8;
xn <<= 4;
}
if (aa >= (1 << 4)) {
aa >>= 4;
xn <<= 2;
}
if (aa >= (1 << 2)) {
xn <<= 1;
}
// We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
//
// We can refine our estimation by noticing that the middle of that interval minimizes the error.
// If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
// This is going to be our x_0 (and ε_0)
xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)
// From here, Newton's method give us:
// x_{n+1} = (x_n + a / x_n) / 2
//
// One should note that:
// x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
// = ((x_n² + a) / (2 * x_n))² - a
// = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
// = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
// = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
// = (x_n² - a)² / (2 * x_n)²
// = ((x_n² - a) / (2 * x_n))²
// ≥ 0
// Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
//
// This gives us the proof of quadratic convergence of the sequence:
// ε_{n+1} = | x_{n+1} - sqrt(a) |
// = | (x_n + a / x_n) / 2 - sqrt(a) |
// = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
// = | (x_n - sqrt(a))² / (2 * x_n) |
// = | ε_n² / (2 * x_n) |
// = ε_n² / | (2 * x_n) |
//
// For the first iteration, we have a special case where x_0 is known:
// ε_1 = ε_0² / | (2 * x_0) |
// ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
// ≤ 2**(2*e-4) / (3 * 2**(e-1))
// ≤ 2**(e-3) / 3
// ≤ 2**(e-3-log2(3))
// ≤ 2**(e-4.5)
//
// For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
// ε_{n+1} = ε_n² / | (2 * x_n) |
// ≤ (2**(e-k))² / (2 * 2**(e-1))
// ≤ 2**(2*e-2*k) / 2**e
// ≤ 2**(e-2*k)
xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5) -- special case, see above
xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9) -- general case with k = 4.5
xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18) -- general case with k = 9
xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36) -- general case with k = 18
xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72) -- general case with k = 36
xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144) -- general case with k = 72
// Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
// ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
// sqrt(a) or sqrt(a) + 1.
return xn - SafeCast.toUint(xn > a / xn);
}
}
/**
* @dev Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 exp;
unchecked {
exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
value >>= exp;
result += exp;
exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
value >>= exp;
result += exp;
exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
value >>= exp;
result += exp;
exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
value >>= exp;
result += exp;
exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
value >>= exp;
result += exp;
exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
value >>= exp;
result += exp;
exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
value >>= exp;
result += exp;
result += SafeCast.toUint(value > 1);
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
uint256 isGt;
unchecked {
isGt = SafeCast.toUint(value > (1 << 128) - 1);
value >>= isGt * 128;
result += isGt * 16;
isGt = SafeCast.toUint(value > (1 << 64) - 1);
value >>= isGt * 64;
result += isGt * 8;
isGt = SafeCast.toUint(value > (1 << 32) - 1);
value >>= isGt * 32;
result += isGt * 4;
isGt = SafeCast.toUint(value > (1 << 16) - 1);
value >>= isGt * 16;
result += isGt * 2;
result += SafeCast.toUint(value > (1 << 8) - 1);
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
import {SafeCast} from "./SafeCast.sol";
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
*
* IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
* However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
* one branch when needed, making this function more expensive.
*/
function ternary(bool condition, int256 a, int256 b) internal pure returns (int256) {
unchecked {
// branchless ternary works because:
// b ^ (a ^ b) == a
// b ^ 0 == b
return b ^ ((a ^ b) * int256(SafeCast.toUint(condition)));
}
}
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return ternary(a > b, a, b);
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return ternary(a < b, a, b);
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// Formula from the "Bit Twiddling Hacks" by Sean Eron Anderson.
// Since `n` is a signed integer, the generated bytecode will use the SAR opcode to perform the right shift,
// taking advantage of the most significant (or "sign" bit) in two's complement representation.
// This opcode adds new most significant bits set to the value of the previous most significant bit. As a result,
// the mask will either be `bytes(0)` (if n is positive) or `~bytes32(0)` (if n is negative).
int256 mask = n >> 255;
// A `bytes(0)` mask leaves the input unchanged, while a `~bytes32(0)` mask complements it.
return uint256((n + mask) ^ mask);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.24;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* Since version 5.1, this library also support writing and reading value types to and from transient storage.
*
* * Example using transient storage:
* ```solidity
* contract Lock {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _LOCK_SLOT = 0xf4678858b2b588224636b8522b729e7722d32fc491da849ed75b3fdf3c84f542;
*
* modifier locked() {
* require(!_LOCK_SLOT.asBoolean().tload());
*
* _LOCK_SLOT.asBoolean().tstore(true);
* _;
* _LOCK_SLOT.asBoolean().tstore(false);
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev UDVT that represent a slot holding a address.
*/
type AddressSlotType is bytes32;
/**
* @dev Cast an arbitrary slot to a AddressSlotType.
*/
function asAddress(bytes32 slot) internal pure returns (AddressSlotType) {
return AddressSlotType.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bool.
*/
type BooleanSlotType is bytes32;
/**
* @dev Cast an arbitrary slot to a BooleanSlotType.
*/
function asBoolean(bytes32 slot) internal pure returns (BooleanSlotType) {
return BooleanSlotType.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a bytes32.
*/
type Bytes32SlotType is bytes32;
/**
* @dev Cast an arbitrary slot to a Bytes32SlotType.
*/
function asBytes32(bytes32 slot) internal pure returns (Bytes32SlotType) {
return Bytes32SlotType.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a uint256.
*/
type Uint256SlotType is bytes32;
/**
* @dev Cast an arbitrary slot to a Uint256SlotType.
*/
function asUint256(bytes32 slot) internal pure returns (Uint256SlotType) {
return Uint256SlotType.wrap(slot);
}
/**
* @dev UDVT that represent a slot holding a int256.
*/
type Int256SlotType is bytes32;
/**
* @dev Cast an arbitrary slot to a Int256SlotType.
*/
function asInt256(bytes32 slot) internal pure returns (Int256SlotType) {
return Int256SlotType.wrap(slot);
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(AddressSlotType slot) internal view returns (address value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(AddressSlotType slot, address value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(BooleanSlotType slot) internal view returns (bool value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(BooleanSlotType slot, bool value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Bytes32SlotType slot) internal view returns (bytes32 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Bytes32SlotType slot, bytes32 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Uint256SlotType slot) internal view returns (uint256 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Uint256SlotType slot, uint256 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
/**
* @dev Load the value held at location `slot` in transient storage.
*/
function tload(Int256SlotType slot) internal view returns (int256 value) {
/// @solidity memory-safe-assembly
assembly {
value := tload(slot)
}
}
/**
* @dev Store `value` at location `slot` in transient storage.
*/
function tstore(Int256SlotType slot, int256 value) internal {
/// @solidity memory-safe-assembly
assembly {
tstore(slot, value)
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @dev Helper library for emitting standardized panic codes.
*
* ```solidity
* contract Example {
* using Panic for uint256;
*
* // Use any of the declared internal constants
* function foo() { Panic.GENERIC.panic(); }
*
* // Alternatively
* function foo() { Panic.panic(Panic.GENERIC); }
* }
* ```
*
* Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
*/
// slither-disable-next-line unused-state
library Panic {
/// @dev generic / unspecified error
uint256 internal constant GENERIC = 0x00;
/// @dev used by the assert() builtin
uint256 internal constant ASSERT = 0x01;
/// @dev arithmetic underflow or overflow
uint256 internal constant UNDER_OVERFLOW = 0x11;
/// @dev division or modulo by zero
uint256 internal constant DIVISION_BY_ZERO = 0x12;
/// @dev enum conversion error
uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
/// @dev invalid encoding in storage
uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
/// @dev empty array pop
uint256 internal constant EMPTY_ARRAY_POP = 0x31;
/// @dev array out of bounds access
uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
/// @dev resource error (too large allocation or too large array)
uint256 internal constant RESOURCE_ERROR = 0x41;
/// @dev calling invalid internal function
uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;
/// @dev Reverts with a panic code. Recommended to use with
/// the internal constants with predefined codes.
function panic(uint256 code) internal pure {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, 0x4e487b71)
mstore(0x20, code)
revert(0x1c, 0x24)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
/// @solidity memory-safe-assembly
assembly {
u := iszero(iszero(b))
}
}
}{
"remappings": [
"@forge-std/=lib/forge-std/src/",
"@interfaces/=src/interfaces/",
"@types/=src/types/",
"@libraries/=src/libraries/",
"@solady/=lib/solady/src/",
"@prb-test/=lib/prb-test/src/",
"@openzeppelin/=lib/openzeppelin-contracts/contracts/",
"@admin/=src/admin/",
"@executors/=src/executors/",
"@mocks/=test/mocks/",
"@factory/=src/factory/",
"@registry/=src/registry/",
"@modules/=src/modules/",
"@adapter/=src/adapter/",
"@test/=test/",
"@aave-v3-core/=lib/aave-v3-core/contracts/",
"@create3/=lib/create3-factory/src/",
"aave-v3-core/=lib/aave-v3-core/",
"create3-factory/=lib/create3-factory/",
"ds-test/=lib/create3-factory/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"prb-test/=lib/prb-test/src/",
"solady/=lib/solady/src/",
"solmate/=lib/create3-factory/lib/solmate/src/"
],
"optimizer": {
"enabled": true,
"runs": 1000000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "cancun",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_portikusV2","type":"address"},{"internalType":"address","name":"_weth","type":"address"},{"internalType":"address","name":"_originalTokenVaultV1","type":"address"},{"internalType":"address","name":"_originalTokenVaultV2","type":"address"},{"internalType":"address","name":"_peggedTokenBridgeV1","type":"address"},{"internalType":"address","name":"_peggedTokenBridgeV2","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"BridgeNotInitiated","type":"error"},{"inputs":[],"name":"BridgeNotSupported","type":"error"},{"inputs":[],"name":"EthNotSupportedForPegBurn","type":"error"},{"inputs":[],"name":"InvalidBridgeType","type":"error"},{"inputs":[],"name":"InvalidRefundReceiver","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[],"name":"InvalidSigner","type":"error"},{"inputs":[],"name":"InvalidWethAddress","type":"error"},{"inputs":[],"name":"MissingProtocolData","type":"error"},{"inputs":[],"name":"NotPreSigned","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"RefundAmountNotReceived","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"TransferIdMismatch","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum ICelerBridgeModule.BridgeType","name":"bridgeType","type":"uint8"},{"indexed":false,"internalType":"bytes32","name":"delayedTransferId","type":"bytes32"}],"name":"CelerRefundDelayed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum ICelerBridgeModule.BridgeType","name":"bridgeType","type":"uint8"}],"name":"CelerRefundProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"beneficiary","type":"address"},{"indexed":true,"internalType":"uint256","name":"destChainId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"},{"indexed":false,"internalType":"string","name":"bridgeProtocol","type":"string"}],"name":"TokensBridged","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORIGINAL_TOKEN_VAULT_V1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ORIGINAL_TOKEN_VAULT_V2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PEGGED_TOKEN_BRIDGE_V1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PEGGED_TOKEN_BRIDGE_V2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PORTIKUS_V2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"address","name":"destToken","type":"address"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"uint256","name":"destAmount","type":"uint256"},{"internalType":"uint256","name":"expectedAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"enum OrderKind","name":"kind","type":"uint8"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"partnerAndFee","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"components":[{"internalType":"bytes4","name":"protocolSelector","type":"bytes4"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"int8","name":"scalingFactor","type":"int8"},{"internalType":"bytes","name":"protocolData","type":"bytes"}],"internalType":"struct Bridge","name":"bridge","type":"tuple"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"},{"internalType":"bytes","name":"bridgeData","type":"bytes"}],"name":"bridgeWithCeler","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"delayedTransferId","type":"bytes32"},{"components":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"address","name":"destToken","type":"address"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"uint256","name":"destAmount","type":"uint256"},{"internalType":"uint256","name":"expectedAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"enum OrderKind","name":"kind","type":"uint8"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"partnerAndFee","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"components":[{"internalType":"bytes4","name":"protocolSelector","type":"bytes4"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"int8","name":"scalingFactor","type":"int8"},{"internalType":"bytes","name":"protocolData","type":"bytes"}],"internalType":"struct Bridge","name":"bridge","type":"tuple"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct OrderWithSig","name":"orderWithSig","type":"tuple"}],"name":"celerDelayedRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"srcToken","type":"address"},{"internalType":"address","name":"destToken","type":"address"},{"internalType":"uint256","name":"srcAmount","type":"uint256"},{"internalType":"uint256","name":"destAmount","type":"uint256"},{"internalType":"uint256","name":"expectedAmount","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"enum OrderKind","name":"kind","type":"uint8"},{"internalType":"uint256","name":"nonce","type":"uint256"},{"internalType":"uint256","name":"partnerAndFee","type":"uint256"},{"internalType":"bytes","name":"permit","type":"bytes"},{"internalType":"bytes","name":"metadata","type":"bytes"},{"components":[{"internalType":"bytes4","name":"protocolSelector","type":"bytes4"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"int8","name":"scalingFactor","type":"int8"},{"internalType":"bytes","name":"protocolData","type":"bytes"}],"internalType":"struct Bridge","name":"bridge","type":"tuple"}],"internalType":"struct Order","name":"order","type":"tuple"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct OrderWithSig","name":"orderWithSig","type":"tuple"},{"internalType":"bytes","name":"_request","type":"bytes"},{"internalType":"bytes[]","name":"_sigs","type":"bytes[]"},{"internalType":"address[]","name":"_signers","type":"address[]"},{"internalType":"uint256[]","name":"_powers","type":"uint256[]"}],"name":"celerRefund","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"selectors","outputs":[{"internalType":"bytes4[]","name":"moduleSelectors","type":"bytes4[]"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]Contract Creation Code
0x6101e0604052348015610010575f80fd5b5060405161441b38038061441b83398101604081905261002f91610231565b6040518060400160405280601381526020017f43656c657220427269646765204d6f64756c6500000000000000000000000000815250604051806040016040528060058152602001640312e302e360dc1b81525087828282610096836101d060201b60201c565b6080526100a2826101d0565b60a0526001600160a01b031660c05250506040805180820182526008815267506f7274696b757360c01b6020918201527ff0ad1de82e0eb024a6da385106f0bbff7da8aaec15457f8c4d79413072d81d6b60e0528151808301835260058152640322e302e360dc1b908201527fb4bcb154e38601c389396fa918314da42d4626f13ef6d0ceb07e5f5d26b2fbc36101005281516080810190925260528083529194509092506143c9915083013960405160200161015f91906102a1565b60408051601f198184030181529190528051602090910120610120526001600160a01b0385166101a257604051633282248160e11b815260040160405180910390fd5b6001600160a01b039485166101c0529284166101405290831661016052821661018052166101a05250610312565b5f80829050601f81511115610203578260405163305a27a960e01b81526004016101fa91906102b7565b60405180910390fd5b805161020e826102ec565b179392505050565b80516001600160a01b038116811461022c575f80fd5b919050565b5f805f805f8060c08789031215610246575f80fd5b61024f87610216565b955061025d60208801610216565b945061026b60408801610216565b935061027960608801610216565b925061028760808801610216565b915061029560a08801610216565b90509295509295509295565b5f82518060208501845e5f920191825250919050565b602081525f82518060208401528060208501604085015e5f604082850101526040601f19601f83011684010191505092915050565b8051602080830151919081101561030c575f198160200360031b1b821691505b50919050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c051613f6c61045d5f395f818161026201528181610daa01528181610e0101528181611c9b015281816121cc015261273e01525f81816102db01528181610d1a01528181611288015281816127fc015281816128a8015261294901525f81816101fc01528181610ca7015281816111d101528181612542015281816125ee015261267c01525f81816101a401528181610c1a015281816110f7015281816122bb015281816123890152818161241f01526124c501525f818161029501528181610b5f0152818161101f01528181611ef001528181611fbe0152818161203f01526120e501525f8181610474015261184801525f81816104c2015261189601525f818161049a015261186e01525f61022f01525f6106aa01525f6103040152613f6c5ff3fe6080604052600436106100ce575f3560e01c806380baeb6e1161007c578063ad5c464811610057578063ad5c464814610251578063c1a6556514610284578063ecc11a68146102b7578063ef56043c146102ca575f80fd5b806380baeb6e1461019357806395e37a01146101eb5780639fb47cad1461021e575f80fd5b806350965a2b116100ac57806350965a2b1461013f57806354fd4d501461015e5780636e25b97814610172575f80fd5b806306fdde03146100d2578063325a6327146100fc5780633644e5151461011d575b5f80fd5b3480156100dd575f80fd5b506100e66102fd565b6040516100f39190613349565b60405180910390f35b348015610107575f80fd5b5061011b61011636600461371e565b61032d565b005b348015610128575f80fd5b5061013161046a565b6040519081526020016100f3565b34801561014a575f80fd5b5061011b6101593660046137e8565b610512565b348015610169575f80fd5b506100e66106a3565b34801561017d575f80fd5b506101866106ce565b6040516100f391906138c8565b34801561019e575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100f3565b3480156101f6575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b348015610229575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b34801561025c575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b34801561028f575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b61011b6102c536600461392d565b61080e565b3480156102d5575f80fd5b506101c67f000000000000000000000000000000000000000000000000000000000000000081565b60606103287f0000000000000000000000000000000000000000000000000000000000000000610828565b905090565b5f61033782610865565b90505f610346835f01516109e8565b90506103528285610a61565b5f610361845f01518387610b06565b9050805f0361039c576040517f77e45c5000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8381527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c60600602090815260408083208390557f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c6060190915281205583516104019082610da8565b835160608101519051835160405173ffffffffffffffffffffffffffffffffffffffff938416939092169186917ff8af68d41397b1aa370acfac3cedba0f7c9751c896ee05fec8df2b6a482acda19161045b918791613a0c565b60405180910390a45050505050565b5f610328604080517f000000000000000000000000000000000000000000000000000000000000000060208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f61051c8a610865565b90505f61052b8b5f01516109e8565b9050610538828b8b610eab565b5f8061054f8d5f0151848e8e8e8e8e8e8e8e610fb7565b91509150815f036105f8575f8481527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606016020526040908190208290558d51606081015190518551925173ffffffffffffffffffffffffffffffffffffffff92831693919092169187917f3ffb0bc9e8d1fa826949a90d3841a22652031046e94426b5d087ab54b7098b89916105e79188918890613a20565b60405180910390a450505050610698565b5f8481527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c6060060205260408120558c516106319083610da8565b8c5160608101519051845160405173ffffffffffffffffffffffffffffffffffffffff938416939092169187917ff8af68d41397b1aa370acfac3cedba0f7c9751c896ee05fec8df2b6a482acda19161068b918891613a0c565b60405180910390a4505050505b505050505050505050565b60606103287f0000000000000000000000000000000000000000000000000000000000000000610828565b6040805160038082526080820190925260609160208201838036833701905050905063ecc11a6860e01b815f8151811061070a5761070a613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015280517f50965a2b00000000000000000000000000000000000000000000000000000000908290600190811061077257610772613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015280517f325a63270000000000000000000000000000000000000000000000000000000090829060029081106107da576107da613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015290565b610816611338565b61082284848484611392565b50505050565b60605f610834836117fb565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f6109cc6109c7835f01515f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b61183b565b82515160208401519192506109e391908390611921565b919050565b604080518082019091525f8082526020820152816101a0015160800151515f03610a3e576040517f74a2f73200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816101a0015160800151806020019051810190610a5b9190613a6f565b92915050565b5f819003610a9b576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8281527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606016020526040902054818114610b01576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050565b5f80610b158560600151611c97565b90505f84516003811115610b2b57610b2b6139a6565b03610bd1576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c906024015b5f604051808303815f87803b158015610bb6575f80fd5b505af1158015610bc8573d5f803e3d5ffd5b50505050610d87565b600184516003811115610be657610be66139a6565b03610c5e576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c90602401610b9f565b600284516003811115610c7357610c736139a6565b03610ceb576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c90602401610b9f565b6040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c906024015f604051808303815f87803b158015610d70575f80fd5b505af1158015610d82573d5f803e3d5ffd5b505050505b80610d958660600151611c97565b610d9f9190613aea565b95945050505050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16826060015173ffffffffffffffffffffffffffffffffffffffff1603610e7d577f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b158015610e65575f80fd5b505af1158015610e77573d5f803e3d5ffd5b50505050505b81516060830151610ea79173ffffffffffffffffffffffffffffffffffffffff9091169083611d37565b5050565b5f80610eb78484611da9565b9550509450505050805f801b03610efa576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82163014610f49576040517ff1fd92a500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8581527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606006020526040902054818114610faf576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050565b5f805f610fc78d60600151611c97565b90505f8c516003811115610fdd57610fdd6139a6565b036110a0576040517fa21a928000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063a21a928090611062908e908e908e908e908e908e908e908e90600401613bdf565b5f604051808303815f87803b158015611079575f80fd5b505af115801561108b573d5f803e3d5ffd5b505050506110998b8b611e20565b915061130e565b60018c5160038111156110b5576110b56139a6565b0361117a576040517fa21a928000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063a21a92809061113a908e908e908e908e908e908e908e908e90600401613bdf565b6020604051808303815f875af1158015611156573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110999190613cf3565b60028c51600381111561118f5761118f6139a6565b0361124b576040517ff873430200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063f873430290611214908e908e908e908e908e908e908e908e90600401613bdf565b5f604051808303815f87803b15801561122b575f80fd5b505af115801561123d573d5f803e3d5ffd5b505050506110998b8b611eda565b6040517ff873430200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000169063f8734302906112cb908e908e908e908e908e908e908e908e90600401613bdf565b6020604051808303815f875af11580156112e7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061130b9190613cf3565b91505b8061131c8e60600151611c97565b6113269190613aea565b9250509a509a98505050505050505050565b7f55784d688e8aecdf5908e67d2532e5fa1b0a3f379bbfebaef09e5fc7c0e6910054611390576040517f70485a4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b5f61139c856109e8565b90505f80825160038111156113b3576113b36139a6565b036113d6576113c482878787611eeb565b6113cf86838661213b565b905061148d565b6001825160038111156113eb576113eb6139a6565b036113fc576113cf828787876122b5565b600282516003811115611411576114116139a6565b0361143157611426868686856020015161253d565b6113cf8683866126ad565b600382516003811115611446576114466139a6565b0361145b576113cf86868685602001516127f6565b6040517f511b184900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6115ec6109c7885f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b9050817f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606005f838152602091825260409020919091556101a0880151015173ffffffffffffffffffffffffffffffffffffffff871661179b895f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b7f886457ca6b553239d5c4940db912122367fab7a5ce932298d5cbb9e635e9b556886117d08a8d6101a001516060015161297a565b88516117db90612a4f565b6040516117ea93929190613d0a565b60405180910390a450505050505050565b5f60ff8216601f811115610a5b576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610a5b6118e6604080517f000000000000000000000000000000000000000000000000000000000000000060208201527f0000000000000000000000000000000000000000000000000000000000000000918101919091527f000000000000000000000000000000000000000000000000000000000000000060608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b82515f036119b25773ffffffffffffffffffffffffffffffffffffffff81165f9081527fc1c92bf4984cdb794b68c76840d7fa5d7356e7dac4a0bbc75375ce7b7b6838006020908152604080832085845290915290205460ff1680610822576040517f763020c100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6119bb81612b7f565b15611b855782516040146119fb576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8084806020019051810190611a119190613d28565b90925090507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81165f611a4960ff84901c601b613d4a565b604080515f808252602082018084528a905260ff84169282019290925260608101879052608081018590529192509060019060a0016020604051602081039080840390855afa158015611a9e573d5f803e3d5ffd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116611b16576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614611b7b576040517f815e1d6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b6040517f1626ba7e0000000000000000000000000000000000000000000000000000000081525f9073ffffffffffffffffffffffffffffffffffffffff831690631626ba7e90611bdb9086908890600401613d63565b602060405180830381865afa158015611bf6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c1a9190613d7b565b90507fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e0000000000000000000000000000000000000000000000000000000014610822576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f807f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614905080611d1357611d0e8373ffffffffffffffffffffffffffffffffffffffff16612c0f565b611d30565b611d3073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee612c0f565b9392505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff841603611d8857610b0173ffffffffffffffffffffffffffffffffffffffff831682612c80565b610b0173ffffffffffffffffffffffffffffffffffffffff84168383612c99565b5f805f805f805f611dee89898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250612cec92505050565b6020810151815160408301516060840151608085015160a090950151939e929d50909b50995091975095509350505050565b5f805f805f805f611e318989611da9565b60408051606097881b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000090811660208084019190915297891b8116603483015260488201969096529390961b909316606883015260c01b7fffffffffffffffff00000000000000000000000000000000000000000000000016607c8201526084808201929092528351808203909201825260a40190925281519101209998505050505050505050565b5f805f805f805f611e318989612e6e565b611f147f0000000000000000000000000000000000000000000000000000000000000000612eb3565b606083015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0361201e576101a0830151602090810151908501516040517ea95fd70000000000000000000000000000000000000000000000000000000081526004810184905267ffffffffffffffff928316602482015273ffffffffffffffffffffffffffffffffffffffff85811660448301529290911660648201527f00000000000000000000000000000000000000000000000000000000000000009091169062a95fd79083906084015f604051808303818588803b158015612002575f80fd5b505af1158015612014573d5f803e3d5ffd5b5050505050610822565b60608301516120649073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000000000000000000000000000000000000000000083612f03565b60608301516101a0840151602090810151908601516040517f2346362400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff93841660048201526024810185905267ffffffffffffffff92831660448201528584166064820152911660848201527f00000000000000000000000000000000000000000000000000000000000000009091169063234636249060a4015b5f604051808303815f87803b158015612129575f80fd5b505af1158015611b7b573d5f803e3d5ffd5b60208301515f90819073ffffffffffffffffffffffffffffffffffffffff161561216957846020015161216c565b84515b90505f6121bc866060015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b6121ca5785606001516121ec565b7f00000000000000000000000000000000000000000000000000000000000000005b6101a0870151602090810151878201516040517fffffffffffffffffffffffffffffffffffffffff00000000000000000000000030606090811b82169583019590955285851b81166034830152604882018a90527fffffffffffffffff00000000000000000000000000000000000000000000000060c094851b811660688401529488901b16607082015290821b831660848201524690911b909116608c8201529091506094015b60405160208183030381529060405280519060200120925050509392505050565b5f6122df7f0000000000000000000000000000000000000000000000000000000000000000612eb3565b606084015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036123fe576101a0840151602090810151908601516040517ea95fd70000000000000000000000000000000000000000000000000000000081526004810185905267ffffffffffffffff928316602482015273ffffffffffffffffffffffffffffffffffffffff86811660448301529290911660648201527f00000000000000000000000000000000000000000000000000000000000000009091169062a95fd790849060840160206040518083038185885af11580156123d2573d5f803e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906123f79190613cf3565b9050612535565b60608401516124449073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000000000000000000000000000000000000000000084612f03565b60608401516101a0850151602090810151908701516040517f2346362400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff93841660048201526024810186905267ffffffffffffffff92831660448201528684166064820152911660848201527f00000000000000000000000000000000000000000000000000000000000000009091169063234636249060a4015b6020604051808303815f875af115801561250e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125329190613cf3565b90505b949350505050565b6125667f0000000000000000000000000000000000000000000000000000000000000000612eb3565b606084015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036125cd576040517f039b4f5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608401516126139073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000000000000000000000000000000000000000000084612f03565b60608401516040517fde790c7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff918216600482015260248101849052848216604482015267ffffffffffffffff831660648201527f00000000000000000000000000000000000000000000000000000000000000009091169063de790c7e90608401612112565b60208301515f90819073ffffffffffffffffffffffffffffffffffffffff16156126db5784602001516126de565b84515b90505f61272e866060015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b61273c57856060015161275e565b7f00000000000000000000000000000000000000000000000000000000000000005b6020808701516040517fffffffffffffffffffffffffffffffffffffffff00000000000000000000000030606090811b82169483019490945284841b81166034830152604882018990529286901b90921660688301527fffffffffffffffff00000000000000000000000000000000000000000000000060c091821b8116607c8401524690911b166084820152909150608c01612294565b5f6128207f0000000000000000000000000000000000000000000000000000000000000000612eb3565b606085015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee03612887576040517f039b4f5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608501516128cd9073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000000000000000000000000000000000000000000085612f03565b60608501516101a0860151602001516040517fa002930100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201526024810186905267ffffffffffffffff9182166044820152868316606482015290841660848201527f00000000000000000000000000000000000000000000000000000000000000009091169063a00293019060a4016124f2565b5f815f0b5f0361298b575081610a5b565b5f80835f0b12156129a45761299f83613d96565b6129a6565b825b905060128160ff161115612a1a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4272696467653a207363616c696e6720666163746f7220746f6f206c61726765604482015260640160405180910390fd5b5f612a2682600a613eef565b90505f845f0b1315612a4557612a3c8186613efd565b92505050610a5b565b612a3c8186613f14565b60605f826003811115612a6457612a646139a6565b03612aa257505060408051808201909152601481527f63656c65722d7065672d6465706f7369742d7631000000000000000000000000602082015290565b6001826003811115612ab657612ab66139a6565b03612af457505060408051808201909152601481527f63656c65722d7065672d6465706f7369742d7632000000000000000000000000602082015290565b6002826003811115612b0857612b086139a6565b03612b4657505060408051808201909152601181527f63656c65722d7065672d6275726e2d7631000000000000000000000000000000602082015290565b505060408051808201909152601181527f63656c65722d7065672d6275726e2d7632000000000000000000000000000000602082015290565b5f73ffffffffffffffffffffffffffffffffffffffff82163b808203612ba85750600192915050565b80601703612c07575f60405160035f82873c517fffffff0000000000000000000000000000000000000000000000000000000000167fef0100000000000000000000000000000000000000000000000000000000000014949350505050565b505f92915050565b5f73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee821460018114612c76576040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152602081602483875afa8015612c6f57815193505b5050612c7a565b4791505b50919050565b5f385f3884865af1610ea75763b12d13eb5f526004601cfd5b81601452806034526fa9059cbb0000000000000000000000005f5260205f604460105f875af18060015f511416612ce257803d853b151710612ce2576390b8ec185f526004601cfd5b505f603452505050565b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a0830182905283518085019094528184528301849052909190805b60208301515183511015612e6657612d4983612f4c565b909250905081600103612d8457612d67612d6284612f84565b61303c565b73ffffffffffffffffffffffffffffffffffffffff168452612d32565b81600203612db857612d98612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff166020850152612d32565b81600303612ddb57612dd1612dcc84612f84565b613046565b6040850152612d32565b81600403612e0f57612def612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff166060850152612d32565b81600503612e3457612e208361307b565b67ffffffffffffffff166080850152612d32565b81600603612e5757612e4d612e4884612f84565b6130ea565b60a0850152612d32565b612e618382613100565b612d32565b505050919050565b5f805f805f805f611dee89898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061316c92505050565b73ffffffffffffffffffffffffffffffffffffffff8116612f00576040517f88b238d700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b81601452806034526f095ea7b30000000000000000000000005f5260205f604460105f875af18060015f511416612ce257803d853b151710612ce257633e3f8f735f526004601cfd5b5f805f612f588461307b565b9050612f65600882613f14565b9250806007166005811115612f7c57612f7c6139a6565b915050915091565b60605f612f908361307b565b90505f81845f0151612fa29190613f4c565b9050836020015151811115612fb5575f80fd5b8167ffffffffffffffff811115612fce57612fce61335b565b6040519080825280601f01601f191660200182016040528015612ff8576020820181803683370190505b5060208086015186519295509181860191908301015f5b8581101561303157818101518382015261302a602082613f4c565b905061300f565b505050935250919050565b5f610a5b826132d7565b5f602082511115613055575f80fd5b602082015190508151602061306a9190613aea565b613075906008613efd565b1c919050565b60208082015182518101909101515f9182805b600a8110156100ce5783811a91506130a7816007613efd565b82607f16901b85179450816080165f036130e2576130c6816001613f4c565b865187906130d5908390613f4c565b9052509395945050505050565b60010161308e565b5f81516020146130f8575f80fd5b506020015190565b5f816005811115613113576131136139a6565b0361312157610b018261307b565b6002816005811115613135576131356139a6565b036100ce575f6131448361307b565b905080835f018181516131579190613f4c565b90525060208301515183511115610b01575f80fd5b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a0830182905283518085019094528184528301849052909190805b60208301515183511015612e66576131c983612f4c565b9092509050816001036131ff576131e2612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1684526131b2565b8160020361323357613213612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1660208501526131b2565b8160030361325157613247612dcc84612f84565b60408501526131b2565b8160040361328557613265612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1660608501526131b2565b816005036132aa576132968361307b565b67ffffffffffffffff1660808501526131b2565b816006036132c8576132be612e4884612f84565b60a08501526131b2565b6132d28382613100565b6131b2565b5f81516014146132e5575f80fd5b50602001516c01000000000000000000000000900490565b5f81518084528060208401602086015e5f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b602081525f611d3060208301846132fd565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040516101c0810167ffffffffffffffff811182821017156133ac576133ac61335b565b60405290565b6040805190810167ffffffffffffffff811182821017156133ac576133ac61335b565b803573ffffffffffffffffffffffffffffffffffffffff811681146109e3575f80fd5b8035600281106109e3575f80fd5b5f82601f830112613415575f80fd5b813567ffffffffffffffff808211156134305761343061335b565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156134765761347661335b565b8160405283815286602085880101111561348e575f80fd5b836020870160208301375f602085830101528094505050505092915050565b7fffffffff0000000000000000000000000000000000000000000000000000000081168114612f00575f80fd5b5f60a082840312156134ea575f80fd5b60405160a0810167ffffffffffffffff828210818311171561350e5761350e61335b565b8160405282935084359150613522826134ad565b8183526020850135602084015261353b604086016133d5565b604084015260608501359150815f0b8214613554575f80fd5b816060840152608085013591508082111561356d575f80fd5b5061357a85828601613406565b6080830152505092915050565b5f6101c08284031215613598575f80fd5b6135a0613388565b90506135ab826133d5565b81526135b9602083016133d5565b60208201526135ca604083016133d5565b60408201526135db606083016133d5565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101006136168184016133f8565b90820152610120828101359082015261014080830135908201526101608083013567ffffffffffffffff8082111561364c575f80fd5b61365886838701613406565b83850152610180925082850135915080821115613673575f80fd5b61367f86838701613406565b838501526101a092508285013591508082111561369a575f80fd5b506136a7858286016134da565b82840152505092915050565b5f604082840312156136c3575f80fd5b6136cb6133b2565b9050813567ffffffffffffffff808211156136e4575f80fd5b6136f085838601613587565b83526020840135915080821115613705575f80fd5b5061371284828501613406565b60208301525092915050565b5f806040838503121561372f575f80fd5b82359150602083013567ffffffffffffffff81111561374c575f80fd5b613758858286016136b3565b9150509250929050565b5f8083601f840112613772575f80fd5b50813567ffffffffffffffff811115613789575f80fd5b6020830191508360208285010111156137a0575f80fd5b9250929050565b5f8083601f8401126137b7575f80fd5b50813567ffffffffffffffff8111156137ce575f80fd5b6020830191508360208260051b85010111156137a0575f80fd5b5f805f805f805f805f60a08a8c031215613800575f80fd5b893567ffffffffffffffff80821115613817575f80fd5b6138238d838e016136b3565b9a5060208c0135915080821115613838575f80fd5b6138448d838e01613762565b909a50985060408c013591508082111561385c575f80fd5b6138688d838e016137a7565b909850965060608c0135915080821115613880575f80fd5b61388c8d838e016137a7565b909650945060808c01359150808211156138a4575f80fd5b506138b18c828d016137a7565b915080935050809150509295985092959850929598565b602080825282518282018190525f9190848201906040850190845b818110156139215783517fffffffff0000000000000000000000000000000000000000000000000000000016835292840192918401916001016138e3565b50909695505050505050565b5f805f8060808587031215613940575f80fd5b843567ffffffffffffffff80821115613957575f80fd5b61396388838901613587565b9550613971602088016133d5565b945060408701359350606087013591508082111561398d575f80fd5b5061399a87828801613406565b91505092959194509250565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b60048110613a08577f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b9052565b82815260408101611d3060208301846139d3565b83815260608101613a3460208301856139d3565b826040830152949350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f60408284031215613a7f575f80fd5b613a876133b2565b825160048110613a95575f80fd5b8152602083015167ffffffffffffffff81168114613ab1575f80fd5b60208201529392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a5b57610a5b613abd565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b8183525f60208085019450825f5b85811015613b8b5773ffffffffffffffffffffffffffffffffffffffff613b78836133d5565b1687529582019590820190600101613b52565b509495945050505050565b8183525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115613bc6575f80fd5b8260051b80836020870137939093016020019392505050565b608081525f613bf2608083018a8c613afd565b602083820381850152818983528183019050818a60051b8401018b5f5b8c811015613cb7577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe086840301845281357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18f3603018112613c6f575f80fd5b8e01858101903567ffffffffffffffff811115613c8a575f80fd5b803603821315613c98575f80fd5b613ca3858284613afd565b958701959450505090840190600101613c0f565b50508581036040870152613ccc818a8c613b44565b93505050508281036060840152613ce4818587613b96565b9b9a5050505050505050505050565b5f60208284031215613d03575f80fd5b5051919050565b838152826020820152606060408201525f61253260608301846132fd565b5f8060408385031215613d39575f80fd5b505080516020909101519092909150565b60ff8181168382160190811115610a5b57610a5b613abd565b828152604060208201525f61253560408301846132fd565b5f60208284031215613d8b575f80fd5b8151611d30816134ad565b5f815f0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff808103613dc957613dc9613abd565b5f0392915050565b600181815b80851115613e2a57817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613e1057613e10613abd565b80851615613e1d57918102915b93841c9390800290613dd6565b509250929050565b5f82613e4057506001610a5b565b81613e4c57505f610a5b565b8160018114613e625760028114613e6c57613e88565b6001915050610a5b565b60ff841115613e7d57613e7d613abd565b50506001821b610a5b565b5060208310610133831016604e8410600b8410161715613eab575081810a610a5b565b613eb58383613dd1565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613ee757613ee7613abd565b029392505050565b5f611d3060ff841683613e32565b8082028115828204841417610a5b57610a5b613abd565b5f82613f47577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b80820180821115610a5b57610a5b613abd56fea164736f6c6343000819000a454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e7472616374290000000000000000000000000007005729e310000c6003402d8a0fb700da0c0000000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f76000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de778000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b
Deployed Bytecode
0x6080604052600436106100ce575f3560e01c806380baeb6e1161007c578063ad5c464811610057578063ad5c464814610251578063c1a6556514610284578063ecc11a68146102b7578063ef56043c146102ca575f80fd5b806380baeb6e1461019357806395e37a01146101eb5780639fb47cad1461021e575f80fd5b806350965a2b116100ac57806350965a2b1461013f57806354fd4d501461015e5780636e25b97814610172575f80fd5b806306fdde03146100d2578063325a6327146100fc5780633644e5151461011d575b5f80fd5b3480156100dd575f80fd5b506100e66102fd565b6040516100f39190613349565b60405180910390f35b348015610107575f80fd5b5061011b61011636600461371e565b61032d565b005b348015610128575f80fd5b5061013161046a565b6040519081526020016100f3565b34801561014a575f80fd5b5061011b6101593660046137e8565b610512565b348015610169575f80fd5b506100e66106a3565b34801561017d575f80fd5b506101866106ce565b6040516100f391906138c8565b34801561019e575f80fd5b506101c67f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b81565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100f3565b3480156101f6575f80fd5b506101c67f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de77881565b348015610229575f80fd5b506101c67f0000000000000000000000000007005729e310000c6003402d8a0fb700da0c0081565b34801561025c575f80fd5b506101c67f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab181565b34801561028f575f80fd5b506101c67f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f7681565b61011b6102c536600461392d565b61080e565b3480156102d5575f80fd5b506101c67f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b81565b60606103287f43656c657220427269646765204d6f64756c6500000000000000000000000013610828565b905090565b5f61033782610865565b90505f610346835f01516109e8565b90506103528285610a61565b5f610361845f01518387610b06565b9050805f0361039c576040517f77e45c5000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8381527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c60600602090815260408083208390557f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c6060190915281205583516104019082610da8565b835160608101519051835160405173ffffffffffffffffffffffffffffffffffffffff938416939092169186917ff8af68d41397b1aa370acfac3cedba0f7c9751c896ee05fec8df2b6a482acda19161045b918791613a0c565b60405180910390a45050505050565b5f610328604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527ff0ad1de82e0eb024a6da385106f0bbff7da8aaec15457f8c4d79413072d81d6b918101919091527fb4bcb154e38601c389396fa918314da42d4626f13ef6d0ceb07e5f5d26b2fbc360608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b5f61051c8a610865565b90505f61052b8b5f01516109e8565b9050610538828b8b610eab565b5f8061054f8d5f0151848e8e8e8e8e8e8e8e610fb7565b91509150815f036105f8575f8481527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606016020526040908190208290558d51606081015190518551925173ffffffffffffffffffffffffffffffffffffffff92831693919092169187917f3ffb0bc9e8d1fa826949a90d3841a22652031046e94426b5d087ab54b7098b89916105e79188918890613a20565b60405180910390a450505050610698565b5f8481527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c6060060205260408120558c516106319083610da8565b8c5160608101519051845160405173ffffffffffffffffffffffffffffffffffffffff938416939092169187917ff8af68d41397b1aa370acfac3cedba0f7c9751c896ee05fec8df2b6a482acda19161068b918891613a0c565b60405180910390a4505050505b505050505050505050565b60606103287f312e302e30000000000000000000000000000000000000000000000000000005610828565b6040805160038082526080820190925260609160208201838036833701905050905063ecc11a6860e01b815f8151811061070a5761070a613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015280517f50965a2b00000000000000000000000000000000000000000000000000000000908290600190811061077257610772613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015280517f325a63270000000000000000000000000000000000000000000000000000000090829060029081106107da576107da613a42565b7fffffffff000000000000000000000000000000000000000000000000000000009092166020928302919091019091015290565b610816611338565b61082284848484611392565b50505050565b60605f610834836117fb565b6040805160208082528183019092529192505f91906020820181803683375050509182525060208101929092525090565b5f6109cc6109c7835f01515f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b61183b565b82515160208401519192506109e391908390611921565b919050565b604080518082019091525f8082526020820152816101a0015160800151515f03610a3e576040517f74a2f73200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b816101a0015160800151806020019051810190610a5b9190613a6f565b92915050565b5f819003610a9b576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8281527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606016020526040902054818114610b01576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050565b5f80610b158560600151611c97565b90505f84516003811115610b2b57610b2b6139a6565b03610bd1576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f7673ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c906024015b5f604051808303815f87803b158015610bb6575f80fd5b505af1158015610bc8573d5f803e3d5ffd5b50505050610d87565b600184516003811115610be657610be66139a6565b03610c5e576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b73ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c90602401610b9f565b600284516003811115610c7357610c736139a6565b03610ceb576040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de77873ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c90602401610b9f565b6040517f9e25fc5c000000000000000000000000000000000000000000000000000000008152600481018490527f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b73ffffffffffffffffffffffffffffffffffffffff1690639e25fc5c906024015f604051808303815f87803b158015610d70575f80fd5b505af1158015610d82573d5f803e3d5ffd5b505050505b80610d958660600151611c97565b610d9f9190613aea565b95945050505050565b7f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab173ffffffffffffffffffffffffffffffffffffffff16826060015173ffffffffffffffffffffffffffffffffffffffff1603610e7d577f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab173ffffffffffffffffffffffffffffffffffffffff1663d0e30db0826040518263ffffffff1660e01b81526004015f604051808303818588803b158015610e65575f80fd5b505af1158015610e77573d5f803e3d5ffd5b50505050505b81516060830151610ea79173ffffffffffffffffffffffffffffffffffffffff9091169083611d37565b5050565b5f80610eb78484611da9565b9550509450505050805f801b03610efa576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82163014610f49576040517ff1fd92a500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8581527f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606006020526040902054818114610faf576040517f3530ea6600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050565b5f805f610fc78d60600151611c97565b90505f8c516003811115610fdd57610fdd6139a6565b036110a0576040517fa21a928000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f76169063a21a928090611062908e908e908e908e908e908e908e908e90600401613bdf565b5f604051808303815f87803b158015611079575f80fd5b505af115801561108b573d5f803e3d5ffd5b505050506110998b8b611e20565b915061130e565b60018c5160038111156110b5576110b56139a6565b0361117a576040517fa21a928000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b169063a21a92809061113a908e908e908e908e908e908e908e908e90600401613bdf565b6020604051808303815f875af1158015611156573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110999190613cf3565b60028c51600381111561118f5761118f6139a6565b0361124b576040517ff873430200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de778169063f873430290611214908e908e908e908e908e908e908e908e90600401613bdf565b5f604051808303815f87803b15801561122b575f80fd5b505af115801561123d573d5f803e3d5ffd5b505050506110998b8b611eda565b6040517ff873430200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b169063f8734302906112cb908e908e908e908e908e908e908e908e90600401613bdf565b6020604051808303815f875af11580156112e7573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061130b9190613cf3565b91505b8061131c8e60600151611c97565b6113269190613aea565b9250509a509a98505050505050505050565b7f55784d688e8aecdf5908e67d2532e5fa1b0a3f379bbfebaef09e5fc7c0e6910054611390576040517f70485a4b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b5f61139c856109e8565b90505f80825160038111156113b3576113b36139a6565b036113d6576113c482878787611eeb565b6113cf86838661213b565b905061148d565b6001825160038111156113eb576113eb6139a6565b036113fc576113cf828787876122b5565b600282516003811115611411576114116139a6565b0361143157611426868686856020015161253d565b6113cf8683866126ad565b600382516003811115611446576114466139a6565b0361145b576113cf86868685602001516127f6565b6040517f511b184900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f6115ec6109c7885f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b9050817f872b3af50308af25d4a8bbdce2b59ef27cd313880ba5e0ec7882ad68a4c606005f838152602091825260409020919091556101a0880151015173ffffffffffffffffffffffffffffffffffffffff871661179b895f808261016001518051906020012090505f8361018001518051906020012090505f846101a00151608001518051906020012090505f856101a0015190506040517f8d8bcbf96f8246b1dcca3f4e1750aecf6cd6971d370b908f10af1d459a2df6eb815281516020820152602082015160408201526040820151606082015260608201515f0b60808201528260a082015260c0812060c0820191507fc75d848e51cd0f81113e24c5a62c9b8566b0ff0d476245a7882709315eefbbf7825287516020830152602088015160408301526040880151606083015260608801516080830152608088015160a083015260a088015160c083015260c088015160e083015260e088015161010083015261010088015161012083015261012088015161014083015261014088015161016083015285610180830152846101a0830152806101c0830152506101e0812095505050505050919050565b7f886457ca6b553239d5c4940db912122367fab7a5ce932298d5cbb9e635e9b556886117d08a8d6101a001516060015161297a565b88516117db90612a4f565b6040516117ea93929190613d0a565b60405180910390a450505050505050565b5f60ff8216601f811115610a5b576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f610a5b6118e6604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60208201527ff0ad1de82e0eb024a6da385106f0bbff7da8aaec15457f8c4d79413072d81d6b918101919091527fb4bcb154e38601c389396fa918314da42d4626f13ef6d0ceb07e5f5d26b2fbc360608201524660808201523060a08201525f9060c00160405160208183030381529060405280519060200120905090565b836040517f19010000000000000000000000000000000000000000000000000000000000008152600281019290925260228201526042902090565b82515f036119b25773ffffffffffffffffffffffffffffffffffffffff81165f9081527fc1c92bf4984cdb794b68c76840d7fa5d7356e7dac4a0bbc75375ce7b7b6838006020908152604080832085845290915290205460ff1680610822576040517f763020c100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6119bb81612b7f565b15611b855782516040146119fb576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f8084806020019051810190611a119190613d28565b90925090507f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81165f611a4960ff84901c601b613d4a565b604080515f808252602082018084528a905260ff84169282019290925260608101879052608081018590529192509060019060a0016020604051602081039080840390855afa158015611a9e573d5f803e3d5ffd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff8116611b16576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8573ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614611b7b576040517f815e1d6400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5050505050505050565b6040517f1626ba7e0000000000000000000000000000000000000000000000000000000081525f9073ffffffffffffffffffffffffffffffffffffffff831690631626ba7e90611bdb9086908890600401613d63565b602060405180830381865afa158015611bf6573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c1a9190613d7b565b90507fffffffff0000000000000000000000000000000000000000000000000000000081167f1626ba7e0000000000000000000000000000000000000000000000000000000014610822576040517f8baa579f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b5f807f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1614905080611d1357611d0e8373ffffffffffffffffffffffffffffffffffffffff16612c0f565b611d30565b611d3073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee612c0f565b9392505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee73ffffffffffffffffffffffffffffffffffffffff841603611d8857610b0173ffffffffffffffffffffffffffffffffffffffff831682612c80565b610b0173ffffffffffffffffffffffffffffffffffffffff84168383612c99565b5f805f805f805f611dee89898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f92019190915250612cec92505050565b6020810151815160408301516060840151608085015160a090950151939e929d50909b50995091975095509350505050565b5f805f805f805f611e318989611da9565b60408051606097881b7fffffffffffffffffffffffffffffffffffffffff00000000000000000000000090811660208084019190915297891b8116603483015260488201969096529390961b909316606883015260c01b7fffffffffffffffff00000000000000000000000000000000000000000000000016607c8201526084808201929092528351808203909201825260a40190925281519101209998505050505050505050565b5f805f805f805f611e318989612e6e565b611f147f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f76612eb3565b606083015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee0361201e576101a0830151602090810151908501516040517ea95fd70000000000000000000000000000000000000000000000000000000081526004810184905267ffffffffffffffff928316602482015273ffffffffffffffffffffffffffffffffffffffff85811660448301529290911660648201527f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f769091169062a95fd79083906084015f604051808303818588803b158015612002575f80fd5b505af1158015612014573d5f803e3d5ffd5b5050505050610822565b60608301516120649073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f7683612f03565b60608301516101a0840151602090810151908601516040517f2346362400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff93841660048201526024810185905267ffffffffffffffff92831660448201528584166064820152911660848201527f000000000000000000000000fe31bfc4f7c9b69246a6dc0087d91a91cb040f769091169063234636249060a4015b5f604051808303815f87803b158015612129575f80fd5b505af1158015611b7b573d5f803e3d5ffd5b60208301515f90819073ffffffffffffffffffffffffffffffffffffffff161561216957846020015161216c565b84515b90505f6121bc866060015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b6121ca5785606001516121ec565b7f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab15b6101a0870151602090810151878201516040517fffffffffffffffffffffffffffffffffffffffff00000000000000000000000030606090811b82169583019590955285851b81166034830152604882018a90527fffffffffffffffff00000000000000000000000000000000000000000000000060c094851b811660688401529488901b16607082015290821b831660848201524690911b909116608c8201529091506094015b60405160208183030381529060405280519060200120925050509392505050565b5f6122df7f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b612eb3565b606084015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036123fe576101a0840151602090810151908601516040517ea95fd70000000000000000000000000000000000000000000000000000000081526004810185905267ffffffffffffffff928316602482015273ffffffffffffffffffffffffffffffffffffffff86811660448301529290911660648201527f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b9091169062a95fd790849060840160206040518083038185885af11580156123d2573d5f803e3d5ffd5b50505050506040513d601f19601f820116820180604052508101906123f79190613cf3565b9050612535565b60608401516124449073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b84612f03565b60608401516101a0850151602090810151908701516040517f2346362400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff93841660048201526024810186905267ffffffffffffffff92831660448201528684166064820152911660848201527f000000000000000000000000ea4b1b0aa3c110c55f650d28159ce4ad43a4a58b9091169063234636249060a4015b6020604051808303815f875af115801561250e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906125329190613cf3565b90505b949350505050565b6125667f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de778612eb3565b606084015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee036125cd576040517f039b4f5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608401516126139073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de77884612f03565b60608401516040517fde790c7e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff918216600482015260248101849052848216604482015267ffffffffffffffff831660648201527f000000000000000000000000bdd2739ae69a054895be33a22b2d2ed71a1de7789091169063de790c7e90608401612112565b60208301515f90819073ffffffffffffffffffffffffffffffffffffffff16156126db5784602001516126de565b84515b90505f61272e866060015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1490565b61273c57856060015161275e565b7f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab15b6020808701516040517fffffffffffffffffffffffffffffffffffffffff00000000000000000000000030606090811b82169483019490945284841b81166034830152604882018990529286901b90921660688301527fffffffffffffffff00000000000000000000000000000000000000000000000060c091821b8116607c8401524690911b166084820152909150608c01612294565b5f6128207f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b612eb3565b606085015173ffffffffffffffffffffffffffffffffffffffff1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee03612887576040517f039b4f5600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60608501516128cd9073ffffffffffffffffffffffffffffffffffffffff167f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b85612f03565b60608501516101a0860151602001516040517fa002930100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff92831660048201526024810186905267ffffffffffffffff9182166044820152868316606482015290841660848201527f000000000000000000000000c72e7fc220e650e93495622422f3c14fb03aaf6b9091169063a00293019060a4016124f2565b5f815f0b5f0361298b575081610a5b565b5f80835f0b12156129a45761299f83613d96565b6129a6565b825b905060128160ff161115612a1a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f4272696467653a207363616c696e6720666163746f7220746f6f206c61726765604482015260640160405180910390fd5b5f612a2682600a613eef565b90505f845f0b1315612a4557612a3c8186613efd565b92505050610a5b565b612a3c8186613f14565b60605f826003811115612a6457612a646139a6565b03612aa257505060408051808201909152601481527f63656c65722d7065672d6465706f7369742d7631000000000000000000000000602082015290565b6001826003811115612ab657612ab66139a6565b03612af457505060408051808201909152601481527f63656c65722d7065672d6465706f7369742d7632000000000000000000000000602082015290565b6002826003811115612b0857612b086139a6565b03612b4657505060408051808201909152601181527f63656c65722d7065672d6275726e2d7631000000000000000000000000000000602082015290565b505060408051808201909152601181527f63656c65722d7065672d6275726e2d7632000000000000000000000000000000602082015290565b5f73ffffffffffffffffffffffffffffffffffffffff82163b808203612ba85750600192915050565b80601703612c07575f60405160035f82873c517fffffff0000000000000000000000000000000000000000000000000000000000167fef0100000000000000000000000000000000000000000000000000000000000014949350505050565b505f92915050565b5f73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee821460018114612c76576040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152602081602483875afa8015612c6f57815193505b5050612c7a565b4791505b50919050565b5f385f3884865af1610ea75763b12d13eb5f526004601cfd5b81601452806034526fa9059cbb0000000000000000000000005f5260205f604460105f875af18060015f511416612ce257803d853b151710612ce2576390b8ec185f526004601cfd5b505f603452505050565b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a0830182905283518085019094528184528301849052909190805b60208301515183511015612e6657612d4983612f4c565b909250905081600103612d8457612d67612d6284612f84565b61303c565b73ffffffffffffffffffffffffffffffffffffffff168452612d32565b81600203612db857612d98612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff166020850152612d32565b81600303612ddb57612dd1612dcc84612f84565b613046565b6040850152612d32565b81600403612e0f57612def612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff166060850152612d32565b81600503612e3457612e208361307b565b67ffffffffffffffff166080850152612d32565b81600603612e5757612e4d612e4884612f84565b6130ea565b60a0850152612d32565b612e618382613100565b612d32565b505050919050565b5f805f805f805f611dee89898080601f0160208091040260200160405190810160405280939291908181526020018383808284375f9201919091525061316c92505050565b73ffffffffffffffffffffffffffffffffffffffff8116612f00576040517f88b238d700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b81601452806034526f095ea7b30000000000000000000000005f5260205f604460105f875af18060015f511416612ce257803d853b151710612ce257633e3f8f735f526004601cfd5b5f805f612f588461307b565b9050612f65600882613f14565b9250806007166005811115612f7c57612f7c6139a6565b915050915091565b60605f612f908361307b565b90505f81845f0151612fa29190613f4c565b9050836020015151811115612fb5575f80fd5b8167ffffffffffffffff811115612fce57612fce61335b565b6040519080825280601f01601f191660200182016040528015612ff8576020820181803683370190505b5060208086015186519295509181860191908301015f5b8581101561303157818101518382015261302a602082613f4c565b905061300f565b505050935250919050565b5f610a5b826132d7565b5f602082511115613055575f80fd5b602082015190508151602061306a9190613aea565b613075906008613efd565b1c919050565b60208082015182518101909101515f9182805b600a8110156100ce5783811a91506130a7816007613efd565b82607f16901b85179450816080165f036130e2576130c6816001613f4c565b865187906130d5908390613f4c565b9052509395945050505050565b60010161308e565b5f81516020146130f8575f80fd5b506020015190565b5f816005811115613113576131136139a6565b0361312157610b018261307b565b6002816005811115613135576131356139a6565b036100ce575f6131448361307b565b905080835f018181516131579190613f4c565b90525060208301515183511115610b01575f80fd5b6040805160c0810182525f8082526020808301829052828401829052606083018290526080830182905260a0830182905283518085019094528184528301849052909190805b60208301515183511015612e66576131c983612f4c565b9092509050816001036131ff576131e2612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1684526131b2565b8160020361323357613213612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1660208501526131b2565b8160030361325157613247612dcc84612f84565b60408501526131b2565b8160040361328557613265612d6284612f84565b73ffffffffffffffffffffffffffffffffffffffff1660608501526131b2565b816005036132aa576132968361307b565b67ffffffffffffffff1660808501526131b2565b816006036132c8576132be612e4884612f84565b60a08501526131b2565b6132d28382613100565b6131b2565b5f81516014146132e5575f80fd5b50602001516c01000000000000000000000000900490565b5f81518084528060208401602086015e5f6020828601015260207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f83011685010191505092915050565b602081525f611d3060208301846132fd565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6040516101c0810167ffffffffffffffff811182821017156133ac576133ac61335b565b60405290565b6040805190810167ffffffffffffffff811182821017156133ac576133ac61335b565b803573ffffffffffffffffffffffffffffffffffffffff811681146109e3575f80fd5b8035600281106109e3575f80fd5b5f82601f830112613415575f80fd5b813567ffffffffffffffff808211156134305761343061335b565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156134765761347661335b565b8160405283815286602085880101111561348e575f80fd5b836020870160208301375f602085830101528094505050505092915050565b7fffffffff0000000000000000000000000000000000000000000000000000000081168114612f00575f80fd5b5f60a082840312156134ea575f80fd5b60405160a0810167ffffffffffffffff828210818311171561350e5761350e61335b565b8160405282935084359150613522826134ad565b8183526020850135602084015261353b604086016133d5565b604084015260608501359150815f0b8214613554575f80fd5b816060840152608085013591508082111561356d575f80fd5b5061357a85828601613406565b6080830152505092915050565b5f6101c08284031215613598575f80fd5b6135a0613388565b90506135ab826133d5565b81526135b9602083016133d5565b60208201526135ca604083016133d5565b60408201526135db606083016133d5565b60608201526080820135608082015260a082013560a082015260c082013560c082015260e082013560e08201526101006136168184016133f8565b90820152610120828101359082015261014080830135908201526101608083013567ffffffffffffffff8082111561364c575f80fd5b61365886838701613406565b83850152610180925082850135915080821115613673575f80fd5b61367f86838701613406565b838501526101a092508285013591508082111561369a575f80fd5b506136a7858286016134da565b82840152505092915050565b5f604082840312156136c3575f80fd5b6136cb6133b2565b9050813567ffffffffffffffff808211156136e4575f80fd5b6136f085838601613587565b83526020840135915080821115613705575f80fd5b5061371284828501613406565b60208301525092915050565b5f806040838503121561372f575f80fd5b82359150602083013567ffffffffffffffff81111561374c575f80fd5b613758858286016136b3565b9150509250929050565b5f8083601f840112613772575f80fd5b50813567ffffffffffffffff811115613789575f80fd5b6020830191508360208285010111156137a0575f80fd5b9250929050565b5f8083601f8401126137b7575f80fd5b50813567ffffffffffffffff8111156137ce575f80fd5b6020830191508360208260051b85010111156137a0575f80fd5b5f805f805f805f805f60a08a8c031215613800575f80fd5b893567ffffffffffffffff80821115613817575f80fd5b6138238d838e016136b3565b9a5060208c0135915080821115613838575f80fd5b6138448d838e01613762565b909a50985060408c013591508082111561385c575f80fd5b6138688d838e016137a7565b909850965060608c0135915080821115613880575f80fd5b61388c8d838e016137a7565b909650945060808c01359150808211156138a4575f80fd5b506138b18c828d016137a7565b915080935050809150509295985092959850929598565b602080825282518282018190525f9190848201906040850190845b818110156139215783517fffffffff0000000000000000000000000000000000000000000000000000000016835292840192918401916001016138e3565b50909695505050505050565b5f805f8060808587031215613940575f80fd5b843567ffffffffffffffff80821115613957575f80fd5b61396388838901613587565b9550613971602088016133d5565b945060408701359350606087013591508082111561398d575f80fd5b5061399a87828801613406565b91505092959194509250565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b60048110613a08577f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b9052565b82815260408101611d3060208301846139d3565b83815260608101613a3460208301856139d3565b826040830152949350505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b5f60408284031215613a7f575f80fd5b613a876133b2565b825160048110613a95575f80fd5b8152602083015167ffffffffffffffff81168114613ab1575f80fd5b60208201529392505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b81810381811115610a5b57610a5b613abd565b81835281816020850137505f602082840101525f60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b8183525f60208085019450825f5b85811015613b8b5773ffffffffffffffffffffffffffffffffffffffff613b78836133d5565b1687529582019590820190600101613b52565b509495945050505050565b8183525f7f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831115613bc6575f80fd5b8260051b80836020870137939093016020019392505050565b608081525f613bf2608083018a8c613afd565b602083820381850152818983528183019050818a60051b8401018b5f5b8c811015613cb7577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe086840301845281357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18f3603018112613c6f575f80fd5b8e01858101903567ffffffffffffffff811115613c8a575f80fd5b803603821315613c98575f80fd5b613ca3858284613afd565b958701959450505090840190600101613c0f565b50508581036040870152613ccc818a8c613b44565b93505050508281036060840152613ce4818587613b96565b9b9a5050505050505050505050565b5f60208284031215613d03575f80fd5b5051919050565b838152826020820152606060408201525f61253260608301846132fd565b5f8060408385031215613d39575f80fd5b505080516020909101519092909150565b60ff8181168382160190811115610a5b57610a5b613abd565b828152604060208201525f61253560408301846132fd565b5f60208284031215613d8b575f80fd5b8151611d30816134ad565b5f815f0b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff808103613dc957613dc9613abd565b5f0392915050565b600181815b80851115613e2a57817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613e1057613e10613abd565b80851615613e1d57918102915b93841c9390800290613dd6565b509250929050565b5f82613e4057506001610a5b565b81613e4c57505f610a5b565b8160018114613e625760028114613e6c57613e88565b6001915050610a5b565b60ff841115613e7d57613e7d613abd565b50506001821b610a5b565b5060208310610133831016604e8410600b8410161715613eab575081810a610a5b565b613eb58383613dd1565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115613ee757613ee7613abd565b029392505050565b5f611d3060ff841683613e32565b8082028115828204841417610a5b57610a5b613abd565b5f82613f47577f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b500490565b80820180821115610a5b57610a5b613abd56fea164736f6c6343000819000a
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.