S Price: $0.066347 (-2.08%)
Gas: 55 Gwei

Contract

0x69D72992Bfff03f0eBe66108eC281f96D8777777

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Token Holdings

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Approve571617902025-12-04 16:13:3853 days ago1764864818IN
0x69D72992...6D8777777
0 S0.001385550.0001
Approve571617802025-12-04 16:13:3053 days ago1764864810IN
0x69D72992...6D8777777
0 S0.0015260550.0001
Approve517562222025-10-24 13:59:4394 days ago1761314383IN
0x69D72992...6D8777777
0 S0.0026661855
Approve517556772025-10-24 13:53:0394 days ago1761313983IN
0x69D72992...6D8777777
0 S0.0026661855
Approve517553652025-10-24 13:49:4194 days ago1761313781IN
0x69D72992...6D8777777
0 S0.0016786555
Approve517552922025-10-24 13:48:5494 days ago1761313734IN
0x69D72992...6D8777777
0 S0.0029327960.5
Approve517551612025-10-24 13:47:3694 days ago1761313656IN
0x69D72992...6D8777777
0 S0.0026661855
Approve507555662025-10-15 17:08:37103 days ago1760548117IN
0x69D72992...6D8777777
0 S0.002321650.0001
Send506917922025-10-15 5:46:16104 days ago1760507176IN
0x69D72992...6D8777777
10 S0.00683250
Send502854942025-10-12 5:49:18107 days ago1760248158IN
0x69D72992...6D8777777
10 S0.006937950
Send502854732025-10-12 5:48:56107 days ago1760248136IN
0x69D72992...6D8777777
10 S0.007198750
Send502852172025-10-12 5:44:36107 days ago1760247876IN
0x69D72992...6D8777777
10 S0.007198750
Send502846192025-10-12 5:35:30107 days ago1760247330IN
0x69D72992...6D8777777
5 S0.007198750
Send502844232025-10-12 5:32:33107 days ago1760247153IN
0x69D72992...6D8777777
5 S0.007143650
Send502840482025-10-12 5:28:04107 days ago1760246884IN
0x69D72992...6D8777777
5 S0.007198750
Send502840162025-10-12 5:27:37107 days ago1760246857IN
0x69D72992...6D8777777
5 S0.007198750
Send502837792025-10-12 5:23:57107 days ago1760246637IN
0x69D72992...6D8777777
5 S0.007198750
Send502834492025-10-12 5:19:55107 days ago1760246395IN
0x69D72992...6D8777777
10 S0.007143650
Send502828272025-10-12 5:10:48107 days ago1760245848IN
0x69D72992...6D8777777
5 S0.007143650
Send502828062025-10-12 5:10:21107 days ago1760245821IN
0x69D72992...6D8777777
5 S0.006937950
Send502827412025-10-12 5:09:23107 days ago1760245763IN
0x69D72992...6D8777777
20 S0.007099650
Send502813032025-10-12 4:49:48107 days ago1760244588IN
0x69D72992...6D8777777
20 S0.007099650
Send502812282025-10-12 4:48:58107 days ago1760244538IN
0x69D72992...6D8777777
20 S0.0072415951.00001
Send502810672025-10-12 4:47:04107 days ago1760244424IN
0x69D72992...6D8777777
20 S0.006938450
Send502810362025-10-12 4:46:40107 days ago1760244400IN
0x69D72992...6D8777777
20 S0.007099650
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
506917922025-10-15 5:46:16104 days ago1760507176
0x69D72992...6D8777777
10 S
502854942025-10-12 5:49:18107 days ago1760248158
0x69D72992...6D8777777
10 S
502854732025-10-12 5:48:56107 days ago1760248136
0x69D72992...6D8777777
10 S
502852172025-10-12 5:44:36107 days ago1760247876
0x69D72992...6D8777777
10 S
502846192025-10-12 5:35:30107 days ago1760247330
0x69D72992...6D8777777
5 S
502844232025-10-12 5:32:33107 days ago1760247153
0x69D72992...6D8777777
5 S
502840482025-10-12 5:28:04107 days ago1760246884
0x69D72992...6D8777777
5 S
502840162025-10-12 5:27:37107 days ago1760246857
0x69D72992...6D8777777
5 S
502837792025-10-12 5:23:57107 days ago1760246637
0x69D72992...6D8777777
5 S
502834492025-10-12 5:19:55107 days ago1760246395
0x69D72992...6D8777777
10 S
502828272025-10-12 5:10:48107 days ago1760245848
0x69D72992...6D8777777
5 S
502828062025-10-12 5:10:21107 days ago1760245821
0x69D72992...6D8777777
5 S
502827412025-10-12 5:09:23107 days ago1760245763
0x69D72992...6D8777777
20 S
502813032025-10-12 4:49:48107 days ago1760244588
0x69D72992...6D8777777
20 S
502812282025-10-12 4:48:58107 days ago1760244538
0x69D72992...6D8777777
20 S
502810672025-10-12 4:47:04107 days ago1760244424
0x69D72992...6D8777777
20 S
502810362025-10-12 4:46:40107 days ago1760244400
0x69D72992...6D8777777
20 S
502809572025-10-12 4:45:49107 days ago1760244349
0x69D72992...6D8777777
20 S
502808492025-10-12 4:44:37107 days ago1760244277
0x69D72992...6D8777777
20 S
502030682025-10-11 15:24:32107 days ago1760196272
0x69D72992...6D8777777
1 S
502021542025-10-11 15:15:55107 days ago1760195755
0x69D72992...6D8777777
1 S
502013182025-10-11 15:09:17107 days ago1760195357
0x69D72992...6D8777777
1 S
502011972025-10-11 15:08:11107 days ago1760195291
0x69D72992...6D8777777
0.01 S
501854612025-10-11 12:54:01108 days ago1760187241
0x69D72992...6D8777777
0.01 S
501796322025-10-11 12:13:48108 days ago1760184828
0x69D72992...6D8777777
0.01 S
View All Internal Transactions
Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
omniDRAGON

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 47 : omniDRAGON.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {OFT} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFT.sol";
import {MessagingFee, SendParam} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

// Uniswap V3 for TWAP
import {TickMath} from "../../libraries/uniswap/TickMath.sol";

// Dragon ecosystem interfaces
import {IOmniDragonLotteryManager} from "../../interfaces/lottery/IOmniDragonLotteryManager.sol";
import {IOmniDragonRegistry} from "../../interfaces/config/IOmniDragonRegistry.sol";
import {IOmniDragonChainlinkOracle} from "../../interfaces/oracles/IOmniDragonChainlinkOracle.sol";
import {IUniswapV3Pool} from "../../interfaces/protocols/IUniswapV3Pool.sol";
import {DragonErrors} from "../../libraries/errors/DragonErrors.sol";

// Event Categories for gas optimization
enum EventCategory {
  BUY_JACKPOT,
  BUY_REVENUE,
  BUY_BURN,
  SELL_JACKPOT,
  SELL_REVENUE,
  SELL_BURN
}

// Fee detection reasons (replaces string for gas efficiency)
enum FeeReason {
  BUY_TAXED,       // 0
  BUY_NO_TAX,      // 1
  SELL_TAXED,      // 2
  SELL_NO_TAX      // 3
}

// Lottery failure reasons (replaces string for gas efficiency)
enum LotteryFailReason {
  MANAGER_NOT_SET,     // 0
  BUYER_IS_CONTRACT,   // 1
  BELOW_MINIMUM_USD,   // 2
  UNKNOWN_ERROR        // 3
}

/**
 * @title omniDRAGON V3
 * @author 0xakita.eth
 * @notice Cross-chain token with LayerZero V2 OFT, intelligent fee system, and oracle-based pricing
 * @dev V3 Optimized Features:
 * - Uniswap V3-only support
 * - Optional fees (0% at launch, configurable up to 25% max)
 * - Oracle-based DRAGON/USD pricing (eliminates pool lock issues)
 * - Self-sustaining oracle updates (during sells, no keeper needed)
 * - EOA-only lottery (tx.origin validation prevents contract wins)
 * - Lottery Manager validates minimums and calculates USD
 * 
 * Dragon Fee Detection:
 * - Simplified: Fees applied when router or V3 pool involved
 * - No fees on cross-chain bridging or non-trading transfers
 * - Configurable routers and pools
 *
 * Architecture:
 * - Token updates oracle during sells (when pool unlocked)
 * - Token reads oracle during buys (no pool lock issue)
 * - Lottery Manager calculates USD and manages lottery logic
 * - Modular design allows lottery upgrades without touching token
 *
 * Security:
 * - tx.origin + extcodesize check prevents contract lottery wins
 * - Reentrancy protection on lottery calls
 * - Maximum 25% fee cap enforced
 * - Comprehensive event emission for transparency
 * - No pause mechanism - trades cannot be stopped
 * - All pool interactions wrapped in try/catch (graceful degradation)
 */
contract omniDRAGON is OFT, ReentrancyGuard {
  using SafeERC20 for IERC20;

  // ================================
  // CONSTANTS & STORAGE
  // ================================
  
  uint256 public constant MAX_SUPPLY = 69_420_000 * 10 ** 18;
  uint256 public constant INITIAL_SUPPLY = 69_420_000 * 10 ** 18;
  uint256 public constant BASIS_POINTS = 10000;
  uint256 public constant SONIC_CHAIN_ID = 146;
  uint256 public constant MAX_FEE_BPS = 2500; // 25% maximum fee cap
  address public constant DEAD_ADDRESS = 0x000000000000000000000000000000000000dEaD;
  
  // V3 TWAP constants
  uint256 private constant Q96 = 2**96; // Uniswap V3 price scaling factor

  // ================================
  // STRUCTS
  // ================================
  
  struct Fees {
    uint16 jackpot; // Basis points for jackpot
    uint16 veDRAGON; // Basis points for veDRAGON holders
    uint16 burn; // Basis points to burn
    uint16 total; // Total basis points
  }
  
  // VRF funding configuration
  struct VRFFundingConfig {
    bool enabled;           // Whether VRF auto-funding is enabled
    uint16 feeBps;          // Basis points of collected fees to reserve for VRF (default 500 = 5%)
    uint256 minBalance;     // Minimum lottery balance before triggering refill (in native token)
    uint256 maxSwapAmount;  // Maximum DRAGON to swap per transaction (safety limit)
  }

  // Separate buy/sell fee controls
  struct ControlFlags {
    bool buyFeesEnabled;        // Separate control for buy fees
    bool sellFeesEnabled;       // Separate control for sell fees
    bool initialMintCompleted;
  }

  // ================================
  // STATE VARIABLES
  // ================================

  // Registry integration
  IOmniDragonRegistry public immutable REGISTRY;
  address public immutable DELEGATE;

  // Core addresses
  address public jackpotVault;
  address public revenueDistributor;
  address public lotteryManager;

  // Fee configuration (mutable)
  Fees public buyFees = Fees(0, 0, 0, 0);           // 0% at launch (configurable up to 25% max)
  Fees public sellFees = Fees(0, 0, 0, 0);          // 0% at launch (configurable up to 25% max)

  // Separate buy/sell fee controls (fees disabled at launch)
  ControlFlags public controlFlags = ControlFlags(false, false, false);
  
  // VRF auto-funding configuration
  VRFFundingConfig public vrfFunding = VRFFundingConfig({
    enabled: false,              // Disabled by default
    feeBps: 500,                 // 5% of fees reserved for VRF
    minBalance: 0.05 ether,      // Refill when lottery has < 0.05 ETH
    maxSwapAmount: 1000 * 10**18 // Max 1000 DRAGON per swap
  });

  // ================================
  // V3 TWAP PRICING CONFIG
  // ================================
  
  // V3 pool for TWAP-based USD pricing
  address public mainV3Pool;                // DRAGON/wrappedNative V3 pool
  address public wrappedNative;             // wS (Sonic) or WETH
  uint32  public priceTwapWindow = 300;     // 5 min default (300s) - configurable
  uint256 public priceStaleAfter = 7200;    // 2 hours - aligned with oracle MAX_STALENESS
  uint128 public minPoolLiquidity = 0;      // Optional: min liquidity to trust TWAP

  // Cached decimals (gas optimization)
  uint8   public dragonDecimalsCache;       // Usually 18
  uint8   public nativeDecimalsCache;       // Usually 18

  // Oracle for native/USD (Chainlink adapter)
  address public priceOracle;

  // ================================
  // LOTTERY DETECTION MAPPINGS (V3 Only)
  // ================================
  
  // V3 pool detection
  mapping(address => bool) public isUniswapV3Pool;
  mapping(address => bool) public isSwapRouter;
  
  // Uniswap V3 SwapRouter address for VRF funding swaps
  address public swapRouter;

  // ================================
  // EVENTS
  // ================================
  
  event FeesDistributed(
    address indexed vault,
    uint256 amount,
    EventCategory indexed category
  );
  
  // lottery events
  event LotteryTriggered(
    address indexed buyer,
    uint256 dragonAmount,
    uint256 indexed requestId  // Lottery entry ID = request ID (consistent with VRF events)
  );

  event LotteryTriggerFailed(
    address indexed buyer,
    uint256 amount,
    LotteryFailReason reason
  );
  
  event InitialMintCompleted(
    address indexed recipient,
    uint256 amount,
    uint256 chainId
  );
  
  event LotteryFeeApplied(
    address indexed from,
    address indexed to,
    uint256 amount,
    uint256 feeAmount,
    FeeReason reason
  );

  // Configuration events (simplified)
  event FeesUpdated(uint16 jackpot, uint16 veDRAGON, uint16 burn, uint16 total, bool isBuy);
  event FeeToggled(bool buyEnabled, bool sellEnabled);
  event PoolConfigUpdated(address indexed pool, address indexed token);
  event TwapConfigUpdated(uint32 window, uint256 staleAfter, uint128 minLiquidity);
  event OracleUpdated(address indexed oracle);
  
  // Ecosystem events
  event EcosystemUpdated(address indexed lottery, address indexed jackpot, address indexed revenue);
  
  // VRF funding events
  event VRFFundingConfigured(bool enabled, uint16 feeBps, uint256 minBalance, uint256 maxSwapAmount);
  event VRFAutoFunded(uint256 dragonAmount, uint256 nativeReceived, address indexed lottery);
  event VRFAutoFundingFailed(uint256 dragonAmount, string reason);
  event SwapRouterUpdated(address indexed router);

  // ================================
  // MODIFIERS
  // ================================
  
  modifier validAddress(address _addr) {
    if (_addr == address(0)) revert DragonErrors.ZeroAddress();
    _;
  }

  // ================================
  // CONSTRUCTOR
  // ================================
  
  constructor(
    string memory _name,
    string memory _symbol,
    address _delegate,
    address _registry,
    address _owner
  ) OFT(_name, _symbol, _getLayerZeroEndpoint(_registry), _delegate) Ownable(_owner) {
    if (_registry == address(0)) revert DragonErrors.ZeroAddress();
    if (_delegate == address(0)) revert DragonErrors.ZeroAddress();
    if (_owner == address(0)) revert DragonErrors.ZeroAddress();

    // Validate LayerZero endpoint
    address lzEndpoint = _getLayerZeroEndpoint(_registry);
    if (lzEndpoint == address(0)) revert("Invalid LZ endpoint");

    REGISTRY = IOmniDragonRegistry(_registry);
    DELEGATE = _delegate;

    // Cache decimals
    dragonDecimalsCache = 18;  // DRAGON decimals

    // Mint initial supply only on Sonic chain
    if (block.chainid == SONIC_CHAIN_ID) {
      _mint(_owner, INITIAL_SUPPLY);
      controlFlags.initialMintCompleted = true;
      emit InitialMintCompleted(_owner, INITIAL_SUPPLY, block.chainid);
    }
  }

  // ================================
  // CORE TRANSFER LOGIC
  // ================================
  /**
   * @dev Enhanced transfer from with lottery fee detection
   */
  function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
    _spendAllowance(from, _msgSender(), amount);
    return _transferWithLotteryDetection(from, to, amount);
  }

  /**
   * @dev Enhanced transfer with lottery fee detection
   */
  function transfer(address to, uint256 amount) public virtual override returns (bool) {
    return _transferWithLotteryDetection(_msgSender(), to, amount);
  }

  /**
   * @dev Lottery transfer logic with enhanced DEX detection
   */
  function _transferWithLotteryDetection(address from, address to, uint256 amount) internal returns (bool) {
    if (from == address(0) || to == address(0)) revert DragonErrors.ZeroAddress();

    // Determine if fees should be applied using lottery detection
    if (_shouldApplyTradingFees(from, to, amount)) {
      return _processTradeWithFees(from, to, amount);
    } else {
      // No fees - direct transfer
      _transfer(from, to, amount);
      return true;
    }
  }

  // ================================
  // LOTTERY FEE DETECTION LOGIC
  // ================================
  /**
   * @dev Simplified logic: Apply fees if router or V3 pool involved
   */
  function _shouldApplyTradingFees(address from, address to, uint256 /* amount */) 
    internal 
    view
    returns (bool) 
  {
    // V3 pool or router = trading operation
    return isSwapRouter[from] || isSwapRouter[to] || 
           isUniswapV3Pool[from] || isUniswapV3Pool[to];
  }

  // ================================
  // FEE PROCESSING
  // ================================
  /**
   * @dev Process trade with fees applied
   */
  function _processTradeWithFees(address from, address to, uint256 amount) internal returns (bool) {

    // Determine transaction type
    bool fromIsPair = _isKnownTradingVenue(from);
    bool toIsPair = _isKnownTradingVenue(to);

    if (fromIsPair && !toIsPair) {
      // Buy transaction: from a trading venue to a user
      return _processBuy(from, to, amount);
    } else if (!fromIsPair && toIsPair) {
      // Sell transaction: from a user to a trading venue
      return _processSell(from, to, amount);
    } else {
      // Edge case: treat as sell if both are trading venues or neither
      return _processSell(from, to, amount);
    }
  }

  /**
   * @dev Check if address is a known trading venue (V3 only)
   */
  function _isKnownTradingVenue(address addr) internal view returns (bool) {
    return isSwapRouter[addr] || isUniswapV3Pool[addr];
  }

  /**
   * @dev Process buy transaction with fees
   * @notice Always applies buy fees (including V3 buys)
   * @notice Triggers lottery on all buys
   * @notice Updates oracle price on buys (in addition to sells) for more frequent updates
   */
  function _processBuy(address from, address to, uint256 amount) internal returns (bool) {
    if (controlFlags.buyFeesEnabled) {
      uint256 feeAmount = (amount * buyFees.total) / BASIS_POINTS;
      uint256 transferAmount = amount - feeAmount;

      // Transfer fees to contract first, then distribute
      _transfer(from, address(this), feeAmount);
      _transfer(from, to, transferAmount);
      _distributeBuyFeesFromContract(feeAmount);

      emit LotteryFeeApplied(from, to, amount, feeAmount, FeeReason.BUY_TAXED);

      // Update oracle price on buys too (not just sells)
      // This provides more frequent price updates for the ecosystem
      // Pool is unlocked during buy, so TWAP is accessible
      _tryUpdateOraclePrice();

      // Trigger lottery with V3 TWAP-derived USD value
      // Use tx.origin to get actual user (not router contract)
      if (lotteryManager != address(0)) {
        _safeTriggerLottery(tx.origin, amount);
      }
    } else {
      _transfer(from, to, amount);
      emit LotteryFeeApplied(from, to, amount, 0, FeeReason.BUY_NO_TAX);
    }

    return true;
  }

  /**
   * @dev Process sell transaction (fees disabled by default)
   * @notice Oracle updates on buys only (not sells) for gas efficiency
   */
  function _processSell(address from, address to, uint256 amount) internal returns (bool) {
    // Sell fees disabled by default - straight transfer
    if (!controlFlags.sellFeesEnabled || sellFees.total == 0) {
      _transfer(from, to, amount);
      emit LotteryFeeApplied(from, to, amount, 0, FeeReason.SELL_NO_TAX);
      return true;
    }

    // Apply sell fees if enabled (future use)
    uint256 feeAmount = (amount * sellFees.total) / BASIS_POINTS;
    uint256 transferAmount = amount - feeAmount;
    _transfer(from, address(this), feeAmount);
    _transfer(from, to, transferAmount);
    _distributeSellFeesFromContract(feeAmount);
    emit LotteryFeeApplied(from, to, amount, feeAmount, FeeReason.SELL_TAXED);
    return true;
  }

  // ================================
  // FEE DISTRIBUTION
  // ================================
  /**
   * @dev Distribute buy fees from contract balance with optional VRF funding
   */
  function _distributeBuyFeesFromContract(uint256 feeAmount) internal {
    if (feeAmount == 0) return;
    
    // Safety: prevent division by zero if buyFees.total is 0
    if (buyFees.total == 0) return;

    // Reserve VRF funding portion if enabled
    uint256 vrfReserve = 0;
    uint256 distributeFees = feeAmount;
    
    if (vrfFunding.enabled && vrfFunding.feeBps > 0) {
      vrfReserve = (feeAmount * vrfFunding.feeBps) / BASIS_POINTS;
      distributeFees = feeAmount - vrfReserve;
    }

    // Distribute remaining fees to ecosystem
    uint256 jackpotAmount = (distributeFees * buyFees.jackpot) / buyFees.total;
    uint256 revenueAmount = (distributeFees * buyFees.veDRAGON) / buyFees.total;
    uint256 burnAmount = (distributeFees * buyFees.burn) / buyFees.total;

    if (jackpotVault != address(0) && jackpotAmount > 0) {
      _transfer(address(this), jackpotVault, jackpotAmount);
      emit FeesDistributed(jackpotVault, jackpotAmount, EventCategory.BUY_JACKPOT);
    }

    if (revenueDistributor != address(0) && revenueAmount > 0) {
      _transfer(address(this), revenueDistributor, revenueAmount);
      emit FeesDistributed(revenueDistributor, revenueAmount, EventCategory.BUY_REVENUE);
    }

    if (burnAmount > 0) {
      _transfer(address(this), DEAD_ADDRESS, burnAmount);
      emit FeesDistributed(DEAD_ADDRESS, burnAmount, EventCategory.BUY_BURN);
    }
    
    // Process VRF funding if enabled and lottery needs funding
    if (vrfReserve > 0) {
      _processVRFFunding(vrfReserve);
    }
  }

  /**
   * @dev Distribute sell fees (uses same logic as buy fees)
   * @notice Sell fees disabled by default - kept for potential future use
   */
  function _distributeSellFeesFromContract(uint256 feeAmount) internal {
    if (feeAmount == 0) return;
    // If sell fees ever enabled, distribute using buy fee ratios
    _distributeBuyFeesFromContract(feeAmount);
  }
  
  // ================================
  // VRF AUTO-FUNDING
  // ================================
  
  /**
   * @dev Process VRF funding from collected fees
   * @param dragonAmount Amount of DRAGON reserved for VRF funding
   */
  function _processVRFFunding(uint256 dragonAmount) internal {
    // Skip if lottery not configured
    if (lotteryManager == address(0)) return;
    
    // Check if lottery needs funding
    uint256 lotteryBalance = lotteryManager.balance;
    if (lotteryBalance >= vrfFunding.minBalance) {
      // Lottery has enough balance, hold DRAGON for later
      return;
    }
    
    // Cap swap amount for safety
    if (dragonAmount > vrfFunding.maxSwapAmount) {
      dragonAmount = vrfFunding.maxSwapAmount;
    }
    
    // Attempt to swap DRAGON → native and send to lottery
    _swapDragonForVRF(dragonAmount);
  }
  
  /**
   * @dev Swap DRAGON to native token and send to lottery manager
   * @param dragonAmount Amount of DRAGON to swap
   */
  function _swapDragonForVRF(uint256 dragonAmount) internal {
    // Validate configuration
    if (swapRouter == address(0) || wrappedNative == address(0) || mainV3Pool == address(0)) {
      emit VRFAutoFundingFailed(dragonAmount, "Config incomplete");
      return;
    }
    
    // Approve router to spend DRAGON
    _approve(address(this), swapRouter, dragonAmount);
    
    // Prepare swap parameters for Uniswap V3 SwapRouter
    // Using proper struct encoding for exactInputSingle
    bytes memory swapData = abi.encodeWithSelector(
      bytes4(keccak256("exactInputSingle((address,address,uint24,address,uint256,uint256,uint160))")),
      abi.encode(
        address(this),         // tokenIn (DRAGON)
        wrappedNative,         // tokenOut (wS/WETH)
        uint24(3000),          // fee (0.3% pool)
        address(this),         // recipient (this contract)
        dragonAmount,          // amountIn
        uint256(0),            // amountOutMinimum (accept any - consider adding slippage protection)
        uint160(0)             // sqrtPriceLimitX96 (no limit)
      )
    );
    
    // Execute swap (non-reverting)
    (bool swapSuccess, bytes memory swapResult) = swapRouter.call(swapData);
    
    if (!swapSuccess) {
      emit VRFAutoFundingFailed(dragonAmount, "Swap failed");
      return;
    }
    
    // Decode amount of wrapped native received
    uint256 wrappedNativeReceived;
    if (swapResult.length >= 32) {
      wrappedNativeReceived = abi.decode(swapResult, (uint256));
    } else {
      emit VRFAutoFundingFailed(dragonAmount, "Invalid swap result");
      return;
    }
    
    if (wrappedNativeReceived == 0) {
      emit VRFAutoFundingFailed(dragonAmount, "Zero output");
      return;
    }
    
    // Unwrap to native token
    (bool unwrapSuccess, ) = wrappedNative.call(
      abi.encodeWithSignature("withdraw(uint256)", wrappedNativeReceived)
    );
    
    if (!unwrapSuccess) {
      emit VRFAutoFundingFailed(dragonAmount, "Unwrap failed");
      return;
    }
    
    // Send native to lottery manager
    (bool sendSuccess, ) = lotteryManager.call{value: wrappedNativeReceived}("");
    
    if (sendSuccess) {
      emit VRFAutoFunded(dragonAmount, wrappedNativeReceived, lotteryManager);
    } else {
      emit VRFAutoFundingFailed(dragonAmount, "Send failed");
    }
  }
  
  /**
   * @notice Manually trigger VRF funding with specific amount
   * @param dragonAmount Amount of DRAGON to swap for VRF funding
   * @dev Only owner can call. Useful for manual refills or testing.
   */
  function manualVRFFunding(uint256 dragonAmount) external onlyOwner nonReentrant {
    require(dragonAmount > 0, "Zero amount");
    require(dragonAmount <= balanceOf(address(this)), "Insufficient balance");
    require(lotteryManager != address(0), "Lottery not set");
    
    _swapDragonForVRF(dragonAmount);
  }

  // ================================
  // V3 TWAP PRICING HELPERS
  // ================================
  /**
   * @dev Get average tick over priceTwapWindow
   * @return avgTick Time-weighted average tick
   */
  function _twapTick() internal view returns (int24 avgTick) {
    require(mainV3Pool != address(0), "pool not set");
    
    uint32[] memory secondsAgos = new uint32[](2);
    secondsAgos[0] = priceTwapWindow;
    secondsAgos[1] = 0;
    
    (int56[] memory tickCumulatives,) = IUniswapV3Pool(mainV3Pool).observe(secondsAgos);
    int56 delta = tickCumulatives[1] - tickCumulatives[0];
    
    // Average tick over window (truncation is acceptable per Uniswap docs)
    avgTick = int24(delta / int56(uint56(priceTwapWindow)));
  }

  /**
   * @dev Convert tick to price in Q64.96 format
   * @param tick Tick value
   * @return priceQ96 token1/token0 price in Q64.96
   */
  function _priceQ96FromTick(int24 tick) internal pure returns (uint256 priceQ96) {
    uint160 sqrtP = TickMath.getSqrtRatioAtTick(tick);  // Q64.96
    // priceQ96 = (sqrtP^2) / 2^96  (token1 per token0)
    priceQ96 = Math.mulDiv(uint256(sqrtP), uint256(sqrtP), Q96);
  }

  /**
   * @dev Get native per DRAGON as 1e18 scalar from V3 TWAP
   * @return nativePerDragon1e18 Amount of native per 1 DRAGON (scaled to 1e18)
   * @dev Returns 0 if pool is locked or TWAP unavailable
   */
  function _dragonToNative_1e18() internal view returns (uint256 nativePerDragon1e18) {
    if (mainV3Pool == address(0) || wrappedNative == address(0)) {
      return 0;  // Not configured
    }
    
    // Try to get live TWAP
    return _tryGetLiveTWAP();
  }
  
  /**
   * @dev Attempt to get live TWAP price (returns 0 if pool locked or unavailable)
   * @return price Live TWAP price or 0 if unavailable
   */
  function _tryGetLiveTWAP() internal view returns (uint256 price) {
    // Optional: check pool has minimum liquidity (skip if pool locked)
    if (minPoolLiquidity > 0) {
      try IUniswapV3Pool(mainV3Pool).liquidity() returns (uint128 liquidity) {
        if (liquidity < minPoolLiquidity) {
          return 0;  // Insufficient liquidity
        }
      } catch {
        return 0;  // Pool locked or call failed
      }
    }
    
    // Get TWAP tick and convert to price (may fail if pool locked)
    int24 tick;
    try this._twapTickExternal() returns (int24 t) {
      tick = t;
    } catch {
      return 0;  // TWAP failed (pool locked, insufficient observations, etc.)
    }
    
    uint256 priceQ96 = _priceQ96FromTick(tick);  // token1 per token0 (Q64.96)
    
    // Safety: check for zero price (invalid tick or extreme price)
    if (priceQ96 == 0) {
      return 0;  // Invalid price
    }
    
    // Determine token orientation (skip if pool locked)
    address t0;
    try IUniswapV3Pool(mainV3Pool).token0() returns (address token) {
      t0 = token;
    } catch {
      return 0;  // Pool locked or call failed
    }
    
    bool dragonIsToken0 = (t0 == address(this));
    
    // Get decimals (use cached values, should be set in setPoolConfig)
    uint8 dragonDec = dragonDecimalsCache;
    uint8 nativeDec = nativeDecimalsCache;
    
    // Safety: ensure decimals are set
    if (dragonDec == 0 || nativeDec == 0) {
      return 0;  // Decimals not initialized
    }
    
    // Calculate scale factor: 10^(18 + nativeDec - dragonDec)
    // For 18/18 decimals: 10^18
    // Defensive: bound decimal exponent to prevent revert
    int256 exp = int256(uint256(18)) + int256(uint256(nativeDec)) - int256(uint256(dragonDec));
    if (exp < 0 || exp > 36) {
      return 0;  // Bad decimals configuration
    }
    uint256 scale = 10 ** uint256(exp);
    
    if (dragonIsToken0) {
      // priceQ96 = native/dragon, so we're done
      // nativePerDragon = priceQ96 * scale / Q96
      price = Math.mulDiv(priceQ96, scale, Q96);
    } else {
      // priceQ96 = dragon/native, need to invert
      // nativePerDragon = scale * Q96 / priceQ96
      // Note: priceQ96 != 0 already checked above, safe from division by zero
      price = Math.mulDiv(scale, Q96, priceQ96);
    }
  }

  /**
   * @dev External wrapper for _twapTick to enable try/catch
   */
  function _twapTickExternal() external view returns (int24) {
    return _twapTick();
  }

  // ================================
  // LOTTERY INTEGRATION
  // ================================
  /**
   * @dev Trigger lottery entry
   * @param buyer Address of the buyer (must be EOA, not contract)
   * @param amount Amount of DRAGON bought
   * @dev Lottery Manager calculates USD value and validates minimum
   * @dev Uses OpenZeppelin's ReentrancyGuard inherited from parent
   */
  function _safeTriggerLottery(address buyer, uint256 amount) internal nonReentrant {
    // Early exit if lottery not configured
    if (lotteryManager == address(0)) {
      emit LotteryTriggerFailed(buyer, amount, LotteryFailReason.MANAGER_NOT_SET);
      return;
    }
    
    // CRITICAL: Only EOAs (users) can win lottery, not contracts
    // Check if buyer is a contract
    uint256 codeSize;
    assembly {
      codeSize := extcodesize(buyer)
    }
    if (codeSize > 0) {
      emit LotteryTriggerFailed(buyer, amount, LotteryFailReason.BUYER_IS_CONTRACT);
      return;
    }
    
    // Trigger lottery - Lottery Manager will calculate USD and validate minimum
    // Note: Lottery manager returns sequential requestId (used as entry ID and VRF request ID)
    // Returns 0 if below minimum or lottery inactive
    try IOmniDragonLotteryManager(lotteryManager).processSwapLottery(
      buyer,
      address(this),
      amount
    ) returns (uint256 requestId) {
      if (requestId > 0) {
        // Lottery entry created successfully (USD calculated by lottery manager)
        emit LotteryTriggered(buyer, amount, requestId);
      } else {
        // Lottery entry rejected (below minimum or inactive)
        emit LotteryTriggerFailed(buyer, amount, LotteryFailReason.BELOW_MINIMUM_USD);
      }
    } catch {
      emit LotteryTriggerFailed(buyer, amount, LotteryFailReason.UNKNOWN_ERROR);
    }
  }

  // ================================
  // FEE SETTER FUNCTIONS
  // ================================
  /**
   * @notice Set fees (buy or sell)
   * @dev Total must be <= MAX_FEE_BPS (2500 = 25%)
   */
  function setFees(
    uint16 _jackpot,
    uint16 _veDRAGON,
    uint16 _burn,
    bool _isBuy
  ) external onlyOwner {
    uint16 total = _jackpot + _veDRAGON + _burn;
    require(total <= MAX_FEE_BPS, "Fee exceeds maximum");
    
    Fees memory newFees = Fees({
      jackpot: _jackpot,
      veDRAGON: _veDRAGON,
      burn: _burn,
      total: total
    });
    
    if (_isBuy) {
      buyFees = newFees;
    } else {
      sellFees = newFees;
    }
    
    emit FeesUpdated(_jackpot, _veDRAGON, _burn, total, _isBuy);
  }

  /**
   * @notice Toggle fee enablement
   */
  function setFeesEnabled(bool _buyEnabled, bool _sellEnabled) external onlyOwner {
    controlFlags.buyFeesEnabled = _buyEnabled;
    controlFlags.sellFeesEnabled = _sellEnabled;
    emit FeeToggled(_buyEnabled, _sellEnabled);
  }

  // ================================Q
  // V3 TWAP ADMIN FUNCTIONS
  // ================================
  /**
   * @notice Configure pool and TWAP settings
   */
  function setPoolConfig(address pool, address token) external onlyOwner {
    require(pool != address(0) && token != address(0), "Zero address");
    
    if (pool != mainV3Pool) {
      // Validate pool contains DRAGON and wrappedNative
      address t0 = IUniswapV3Pool(pool).token0();
      address t1 = IUniswapV3Pool(pool).token1();
      require(
        (t0 == address(this) || t1 == address(this)) &&
        (t0 == token || t1 == token),
        "Invalid pool"
      );
      mainV3Pool = pool;
    }
    
    if (token != wrappedNative) {
      wrappedNative = token;
      nativeDecimalsCache = IERC20Metadata(token).decimals();
      dragonDecimalsCache = IERC20Metadata(address(this)).decimals();
    }
    
    emit PoolConfigUpdated(pool, token);
  }

  /**
   * @notice Configure TWAP parameters
   */
  function setTwapConfig(uint32 window, uint256 staleAfter, uint128 minLiq) external onlyOwner {
    require(window >= 10 && window <= 3600, "Invalid window");
    require(staleAfter >= 60 && staleAfter <= 24 hours, "Invalid stale threshold");
    priceTwapWindow = window;
    priceStaleAfter = staleAfter;
    minPoolLiquidity = minLiq;
    emit TwapConfigUpdated(window, staleAfter, minLiq);
  }

  /**
   * @notice Set price oracle
   */
  function setPriceOracle(address _oracle) external onlyOwner {
    priceOracle = _oracle;
    emit OracleUpdated(_oracle);
  }
  
  /**
   * @dev Internal helper to update oracle price (non-reverting)
   * @dev Called automatically during sells to keep oracle price fresh
   */
  function _tryUpdateOraclePrice() internal {
    // Cache oracle address for gas optimization (avoid multiple SLOADs)
    address cachedOracle = priceOracle;
    if (cachedOracle == address(0)) return;
    
    // Check if oracle was recently updated - skip if still fresh (gas optimization)
    try IOmniDragonChainlinkOracle(cachedOracle).getDragonPrice() returns (int256 price, uint256 timestamp) {
      if (price > 0 && timestamp > 0) {
        // If oracle was updated in last 2 minutes, skip update to save gas
        if (block.timestamp - timestamp < 120) {
          return;  // Oracle still fresh, no need to update
        }
      }
    } catch {
      // Oracle call failed, continue with update attempt
    }
    
    // Calculate DRAGON/USD using TWAP (when pool unlocked)
    // Step 1: Get DRAGON → wrappedNative from V3 TWAP
    uint256 nativePerDragon1e18 = _tryGetLiveTWAP();
    if (nativePerDragon1e18 == 0) return;  // TWAP not available (pool locked or no observations)
    
    // Step 2: Get wrappedNative → USD from Chainlink (use cached oracle address)
    (int256 nativeUsd1e18, uint256 ts) = IOmniDragonChainlinkOracle(cachedOracle).getNativePrice();
    if (nativeUsd1e18 <= 0 || ts == 0) return;  // Oracle not available
    if (block.timestamp - ts > priceStaleAfter) return;  // Stale price
    
    // Step 3: Calculate DRAGON/USD (1e18 format)
    // dragonUsd = nativePerDragon * nativeUsd (both in 1e18)
    int256 dragonUsd1e18 = int256(Math.mulDiv(nativePerDragon1e18, uint256(nativeUsd1e18), 1e18));
    
    if (dragonUsd1e18 <= 0) return;  // Invalid calculated price
    
    // Step 4: Update oracle contract (use cached oracle address)
    // Using low-level call to avoid interface dependency and never revert
    (bool success, ) = cachedOracle.call(
      abi.encodeWithSignature("updateDragonPrice(int256)", dragonUsd1e18)
    );
    // Note: success is intentionally ignored - update is best-effort
    success;  // Suppress unused variable warning
  }
  
  /**
   * @notice Manually update DRAGON price in oracle using current TWAP
   * @dev Anyone can call this to refresh oracle when pool is unlocked
   * @dev Useful for priming the oracle or manual updates
   */
  function updateDragonPriceToOracle() external {
    _tryUpdateOraclePrice();
  }
  

  // ================================
  // ADMIN CONFIGURATION FUNCTIONS
  // ================================
  /**
   * @dev Set Uniswap V3 pool addresses
   * @notice Mark address as V3 pool for swap detection
   */
  function setUniswapV3Pool(address pool, bool isPool) external onlyOwner {
    isUniswapV3Pool[pool] = isPool;
  }

  /**
   * @dev Set swap router for fee detection
   * @notice Mark address as swap router for lottery detection
   */
  function setSwapRouter(address router, bool isRouter) external onlyOwner {
    isSwapRouter[router] = isRouter;
  }
  
  /**
   * @notice Set the Uniswap V3 SwapRouter address for VRF funding swaps
   * @param router Address of Uniswap V3 SwapRouter02 contract
   */
  function setVRFSwapRouter(address router) external onlyOwner {
    require(router != address(0), "Zero address");
    swapRouter = router;
    emit SwapRouterUpdated(router);
  }
  
  /**
   * @notice Configure VRF auto-funding parameters
   * @param enabled Whether VRF auto-funding is enabled
   * @param feeBps Basis points of fees to reserve (max 1000 = 10%)
   * @param minBalance Minimum lottery balance before refill (in wei)
   * @param maxSwapAmount Maximum DRAGON to swap per transaction
   */
  function setVRFFundingConfig(
    bool enabled,
    uint16 feeBps,
    uint256 minBalance,
    uint256 maxSwapAmount
  ) external onlyOwner {
    require(feeBps <= 1000, "Max 10% of fees");
    require(maxSwapAmount > 0, "Max swap must be > 0");
    
    vrfFunding.enabled = enabled;
    vrfFunding.feeBps = feeBps;
    vrfFunding.minBalance = minBalance;
    vrfFunding.maxSwapAmount = maxSwapAmount;
    
    emit VRFFundingConfigured(enabled, feeBps, minBalance, maxSwapAmount);
  }

  /**
   * @notice Configure ecosystem contracts
   */
  function setEcosystem(
    address _lottery,
    address _jackpot,
    address _revenue
  ) external onlyOwner {
    require(_lottery != address(0) && _jackpot != address(0) && _revenue != address(0), "Zero address");
    lotteryManager = _lottery;
    jackpotVault = _jackpot;
    revenueDistributor = _revenue;
    emit EcosystemUpdated(_lottery, _jackpot, _revenue);
  }

  // ================================
  // LAYERZERO OFT FUNCTIONS
  // ================================
  
  /**
   * @notice Sets the peer address (OApp instance) for a corresponding endpoint
   * @param _eid The endpoint ID of the target chain
   * @param _peer The address of the peer OFT contract on the target chain (as bytes32)
   * @dev Inherited from OAppCore. Required for cross-chain bridging.
   * @dev Only owner can call. Use bytes32(uint256(uint160(address))) to convert address to bytes32.
   * @dev Example: For Arbitrum (eid 30110), set peer to enable bridging to/from Arbitrum
   */
  // function setPeer(uint32 _eid, bytes32 _peer) external onlyOwner
  // Inherited from OAppCore - available to call
  
  /**
   * @notice Sets the delegate address for LayerZero operations
   * @param _delegate The address that can configure LayerZero settings
   * @dev Inherited from OAppCore. Delegate can configure message settings in the endpoint.
   */
  // function setDelegate(address _delegate) external onlyOwner
  // Inherited from OAppCore - available to call
  
  /**
   * @notice Retrieves the peer OFT address for a specific chain
   * @param _eid The endpoint ID of the target chain
   * @return peer The peer address (as bytes32)
   * @dev Inherited from OAppCore. Returns bytes32(0) if not set.
   */
  // function peers(uint32 _eid) external view returns (bytes32 peer)
  // Inherited from OAppCore - available to call
  
  // NOTE: LayerZero V2 OFT handles cross-chain transfers internally.
  // Our lottery fee detection in _transferWithLotteryDetection ensures
  // that cross-chain operations don't trigger trading fees.

  // ================================
  // UTILITY FUNCTIONS
  // ================================
  /**
   * @dev Get LayerZero endpoint from registry
   */
  function _getLayerZeroEndpoint(address _registry) internal view returns (address) {
    try IOmniDragonRegistry(_registry).getLayerZeroEndpoint(uint16(block.chainid)) returns (address endpoint) {
      return endpoint;
    } catch {
      return address(0);
    }
  }

  // ================================
  // VIEW FUNCTIONS
  // ================================
  
  /**
   * @notice Verify all critical integrations are properly configured
   * @return isConfigured True if all critical components are set
   * @return missingComponents Bitmap of missing components (bit flags)
   * @return configDetails Human-readable configuration status
   * @dev Bit flags: 1=oracle, 2=lottery, 4=jackpot, 8=revenue, 16=pool, 32=router
   */
  function verifyIntegrationConfig() external view returns (
    bool isConfigured,
    uint8 missingComponents,
    string memory configDetails
  ) {
    missingComponents = 0;
    
    // Check critical components
    if (priceOracle == address(0)) missingComponents |= 1;
    if (lotteryManager == address(0)) missingComponents |= 2;
    if (jackpotVault == address(0)) missingComponents |= 4;
    if (revenueDistributor == address(0)) missingComponents |= 8;
    if (mainV3Pool == address(0)) missingComponents |= 16;
    if (wrappedNative == address(0)) missingComponents |= 16; // Same bit as pool
    
    // Check if at least one router/pool is configured
    bool hasRouter = false;
    // Note: Can't easily iterate mappings, but this gives a basic check
    
    isConfigured = (missingComponents == 0);
    
    // Build human-readable status
    if (isConfigured) {
      configDetails = "All critical components configured";
    } else {
      configDetails = "Missing components - check bit flags";
    }
    
    return (isConfigured, missingComponents, configDetails);
  }
  
  /**
   * @notice Get current configuration addresses
   * @return oracle The oracle address
   * @return lottery The lottery manager address
   * @return jackpot The jackpot vault address
   * @return revenue The revenue distributor address
   * @return pool The main V3 pool address
   * @return native The wrapped native token address
   */
  function getConfigAddresses() external view returns (
    address oracle,
    address lottery,
    address jackpot,
    address revenue,
    address pool,
    address native
  ) {
    return (
      priceOracle,
      lotteryManager,
      jackpotVault,
      revenueDistributor,
      mainV3Pool,
      wrappedNative
    );
  }
  
  /**
   * @notice Preview lottery probability for a potential buy
   * @param trader Address of trader
   * @param dragonAmount Amount of DRAGON to buy
   * @return usdValue Calculated USD value using V3 TWAP
   * @return baseProbability Base probability in BPS
   * @return veDragonBoost veDRAGON boost multiplier in BPS
   * @return finalProbability Final probability in BPS
   * @return readableProb Human-readable probability (e.g., "0.342%")
   */

  // ========== SONIC FEEM INTEGRATION ==========
  /**
   * @dev Register my contract on Sonic FeeM
   * @notice This registers the contract with Sonic's Fee Manager for network benefits
   */
  function registerMe() external onlyOwner {
    (bool _success,) = address(0xDC2B0D2Dd2b7759D97D50db4eabDC36973110830).call(
      abi.encodeWithSignature("selfRegister(uint256)", 143)
    );
    require(_success, "FeeM registration failed");
  }
  
  /**
   * @dev Receive function to accept native tokens from unwrap operations
   */
  receive() external payable {
    // Accept native tokens from wrapped native unwrap or manual funding
    // No action needed - balance automatically credited
  }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { IOFT, OFTCore } from "./OFTCore.sol";

/**
 * @title OFT Contract
 * @dev OFT is an ERC-20 token that extends the functionality of the OFTCore contract.
 */
abstract contract OFT is OFTCore, ERC20 {
    /**
     * @dev Constructor for the OFT contract.
     * @param _name The name of the OFT.
     * @param _symbol The symbol of the OFT.
     * @param _lzEndpoint The LayerZero endpoint address.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     */
    constructor(
        string memory _name,
        string memory _symbol,
        address _lzEndpoint,
        address _delegate
    ) ERC20(_name, _symbol) OFTCore(decimals(), _lzEndpoint, _delegate) {}

    /**
     * @dev Retrieves the address of the underlying ERC20 implementation.
     * @return The address of the OFT token.
     *
     * @dev In the case of OFT, address(this) and erc20 are the same contract.
     */
    function token() public view returns (address) {
        return address(this);
    }

    /**
     * @notice Indicates whether the OFT contract requires approval of the 'token()' to send.
     * @return requiresApproval Needs approval of the underlying token implementation.
     *
     * @dev In the case of OFT where the contract IS the token, approval is NOT required.
     */
    function approvalRequired() external pure virtual returns (bool) {
        return false;
    }

    /**
     * @dev Burns tokens from the sender's specified balance.
     * @param _from The address to debit the tokens from.
     * @param _amountLD The amount of tokens to send in local decimals.
     * @param _minAmountLD The minimum amount to send in local decimals.
     * @param _dstEid The destination chain ID.
     * @return amountSentLD The amount sent in local decimals.
     * @return amountReceivedLD The amount received in local decimals on the remote.
     */
    function _debit(
        address _from,
        uint256 _amountLD,
        uint256 _minAmountLD,
        uint32 _dstEid
    ) internal virtual override returns (uint256 amountSentLD, uint256 amountReceivedLD) {
        (amountSentLD, amountReceivedLD) = _debitView(_amountLD, _minAmountLD, _dstEid);

        // @dev In NON-default OFT, amountSentLD could be 100, with a 10% fee, the amountReceivedLD amount is 90,
        // therefore amountSentLD CAN differ from amountReceivedLD.

        // @dev Default OFT burns on src.
        _burn(_from, amountSentLD);
    }

    /**
     * @dev Credits tokens to the specified address.
     * @param _to The address to credit the tokens to.
     * @param _amountLD The amount of tokens to credit in local decimals.
     * @dev _srcEid The source chain ID.
     * @return amountReceivedLD The amount of tokens ACTUALLY received in local decimals.
     */
    function _credit(
        address _to,
        uint256 _amountLD,
        uint32 /*_srcEid*/
    ) internal virtual override returns (uint256 amountReceivedLD) {
        if (_to == address(0x0)) _to = address(0xdead); // _mint(...) does not support address(0x0)
        // @dev Default OFT mints on dst.
        _mint(_to, _amountLD);
        // @dev In the case of NON-default OFT, the _amountLD MIGHT not be == amountReceivedLD.
        return _amountLD;
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { MessagingReceipt, MessagingFee } from "../../oapp/OAppSender.sol";

/**
 * @dev Struct representing token parameters for the OFT send() operation.
 */
struct SendParam {
    uint32 dstEid; // Destination endpoint ID.
    bytes32 to; // Recipient address.
    uint256 amountLD; // Amount to send in local decimals.
    uint256 minAmountLD; // Minimum amount to send in local decimals.
    bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
    bytes composeMsg; // The composed message for the send() operation.
    bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}

/**
 * @dev Struct representing OFT limit information.
 * @dev These amounts can change dynamically and are up the the specific oft implementation.
 */
struct OFTLimit {
    uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient.
    uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient.
}

/**
 * @dev Struct representing OFT receipt information.
 */
struct OFTReceipt {
    uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals.
    // @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
    uint256 amountReceivedLD; // Amount of tokens to be received on the remote side.
}

/**
 * @dev Struct representing OFT fee details.
 * @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI.
 */
struct OFTFeeDetail {
    int256 feeAmountLD; // Amount of the fee in local decimals.
    string description; // Description of the fee.
}

/**
 * @title IOFT
 * @dev Interface for the OftChain (OFT) token.
 * @dev Does not inherit ERC20 to accommodate usage by OFTAdapter as well.
 * @dev This specific interface ID is '0x02e49c2c'.
 */
interface IOFT {
    // Custom error messages
    error InvalidLocalDecimals();
    error SlippageExceeded(uint256 amountLD, uint256 minAmountLD);

    // Events
    event OFTSent(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 dstEid, // Destination Endpoint ID.
        address indexed fromAddress, // Address of the sender on the src chain.
        uint256 amountSentLD, // Amount of tokens sent in local decimals.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );
    event OFTReceived(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 srcEid, // Source Endpoint ID.
        address indexed toAddress, // Address of the recipient on the dst chain.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );

    /**
     * @notice Retrieves interfaceID and the version of the OFT.
     * @return interfaceId The interface ID.
     * @return version The version.
     *
     * @dev interfaceId: This specific interface ID is '0x02e49c2c'.
     * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs.
     * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented.
     * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1)
     */
    function oftVersion() external view returns (bytes4 interfaceId, uint64 version);

    /**
     * @notice Retrieves the address of the token associated with the OFT.
     * @return token The address of the ERC20 token implementation.
     */
    function token() external view returns (address);

    /**
     * @notice Indicates whether the OFT contract requires approval of the 'token()' to send.
     * @return requiresApproval Needs approval of the underlying token implementation.
     *
     * @dev Allows things like wallet implementers to determine integration requirements,
     * without understanding the underlying token implementation.
     */
    function approvalRequired() external view returns (bool);

    /**
     * @notice Retrieves the shared decimals of the OFT.
     * @return sharedDecimals The shared decimals of the OFT.
     */
    function sharedDecimals() external view returns (uint8);

    /**
     * @notice Provides a quote for OFT-related operations.
     * @param _sendParam The parameters for the send operation.
     * @return limit The OFT limit information.
     * @return oftFeeDetails The details of OFT fees.
     * @return receipt The OFT receipt information.
     */
    function quoteOFT(
        SendParam calldata _sendParam
    ) external view returns (OFTLimit memory, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory);

    /**
     * @notice Provides a quote for the send() operation.
     * @param _sendParam The parameters for the send() operation.
     * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token.
     * @return fee The calculated LayerZero messaging fee from the send() operation.
     *
     * @dev MessagingFee: LayerZero msg fee
     *  - nativeFee: The native fee.
     *  - lzTokenFee: The lzToken fee.
     */
    function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory);

    /**
     * @notice Executes the send() operation.
     * @param _sendParam The parameters for the send operation.
     * @param _fee The fee information supplied by the caller.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess funds from fees etc. on the src.
     * @return receipt The LayerZero messaging receipt from the send() operation.
     * @return oftReceipt The OFT receipt information.
     *
     * @dev MessagingReceipt: LayerZero msg receipt
     *  - guid: The unique identifier for the sent message.
     *  - nonce: The nonce of the sent message.
     *  - fee: The LayerZero fee incurred for the message.
     */
    function send(
        SendParam calldata _sendParam,
        MessagingFee calldata _fee,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory, OFTReceipt memory);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    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 overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        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 division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return 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.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev 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^256 and mod 2^256 - 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^256 + 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^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

            ///////////////////////////////////////////////
            // 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^256 / 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^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            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^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // 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^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, 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;
        }
    }

    /**
     * @notice 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) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice 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 + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @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;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 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 + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @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 + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @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;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 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 + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @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: GPL-2.0-or-later
pragma solidity ^0.8.20;

/// @title Math library for computing sqrt prices from ticks and vice versa
/// @notice Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports
/// prices between 2**-128 and 2**128
/// @dev Adapted from Uniswap V3 Core for Solidity 0.8.20 compatibility
library TickMath {
    /// @dev The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128
    int24 internal constant MIN_TICK = -887272;
    /// @dev The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128
    int24 internal constant MAX_TICK = -MIN_TICK;

    /// @dev The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)
    uint160 internal constant MIN_SQRT_RATIO = 4295128739;
    /// @dev The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)
    uint160 internal constant MAX_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;

    /// @notice Calculates sqrt(1.0001^tick) * 2^96
    /// @dev Throws if |tick| > max tick
    /// @param tick The input tick for the above formula
    /// @return sqrtPriceX96 A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
    /// at the given tick
    function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96) {
        unchecked {
            uint256 absTick = tick < 0 ? uint256(-int256(tick)) : uint256(int256(tick));
            require(absTick <= uint256(int256(MAX_TICK)), 'T');

            uint256 ratio = absTick & 0x1 != 0
                ? 0xfffcb933bd6fad37aa2d162d1a594001
                : 0x100000000000000000000000000000000;
            if (absTick & 0x2 != 0) ratio = (ratio * 0xfff97272373d413259a46990580e213a) >> 128;
            if (absTick & 0x4 != 0) ratio = (ratio * 0xfff2e50f5f656932ef12357cf3c7fdcc) >> 128;
            if (absTick & 0x8 != 0) ratio = (ratio * 0xffe5caca7e10e4e61c3624eaa0941cd0) >> 128;
            if (absTick & 0x10 != 0) ratio = (ratio * 0xffcb9843d60f6159c9db58835c926644) >> 128;
            if (absTick & 0x20 != 0) ratio = (ratio * 0xff973b41fa98c081472e6896dfb254c0) >> 128;
            if (absTick & 0x40 != 0) ratio = (ratio * 0xff2ea16466c96a3843ec78b326b52861) >> 128;
            if (absTick & 0x80 != 0) ratio = (ratio * 0xfe5dee046a99a2a811c461f1969c3053) >> 128;
            if (absTick & 0x100 != 0) ratio = (ratio * 0xfcbe86c7900a88aedcffc83b479aa3a4) >> 128;
            if (absTick & 0x200 != 0) ratio = (ratio * 0xf987a7253ac413176f2b074cf7815e54) >> 128;
            if (absTick & 0x400 != 0) ratio = (ratio * 0xf3392b0822b70005940c7a398e4b70f3) >> 128;
            if (absTick & 0x800 != 0) ratio = (ratio * 0xe7159475a2c29b7443b29c7fa6e889d9) >> 128;
            if (absTick & 0x1000 != 0) ratio = (ratio * 0xd097f3bdfd2022b8845ad8f792aa5825) >> 128;
            if (absTick & 0x2000 != 0) ratio = (ratio * 0xa9f746462d870fdf8a65dc1f90e061e5) >> 128;
            if (absTick & 0x4000 != 0) ratio = (ratio * 0x70d869a156d2a1b890bb3df62baf32f7) >> 128;
            if (absTick & 0x8000 != 0) ratio = (ratio * 0x31be135f97d08fd981231505542fcfa6) >> 128;
            if (absTick & 0x10000 != 0) ratio = (ratio * 0x9aa508b5b7a84e1c677de54f3e99bc9) >> 128;
            if (absTick & 0x20000 != 0) ratio = (ratio * 0x5d6af8dedb81196699c329225ee604) >> 128;
            if (absTick & 0x40000 != 0) ratio = (ratio * 0x2216e584f5fa1ea926041bedfe98) >> 128;
            if (absTick & 0x80000 != 0) ratio = (ratio * 0x48a170391f7dc42444e8fa2) >> 128;

            if (tick > 0) ratio = type(uint256).max / ratio;

            // this divides by 1<<32 rounding up to go from a Q128.128 to a Q128.96.
            // we then downcast because we know the result always fits within 160 bits due to our tick input constraint
            // we round up in the division so getTickAtSqrtRatio of the output price is always consistent
            sqrtPriceX96 = uint160((ratio >> 32) + (ratio % (1 << 32) == 0 ? 0 : 1));
        }
    }

    /// @notice Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio
    /// @dev Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may
    /// ever return.
    /// @param sqrtPriceX96 The sqrt ratio for which to compute the tick as a Q64.96
    /// @return tick The greatest tick for which the ratio is less than or equal to the input ratio
    function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick) {
        unchecked {
            // second inequality must be < because the price can never reach the price at the max tick
            require(sqrtPriceX96 >= MIN_SQRT_RATIO && sqrtPriceX96 < MAX_SQRT_RATIO, 'R');
            uint256 ratio = uint256(sqrtPriceX96) << 32;

            uint256 r = ratio;
            uint256 msb = 0;

            assembly {
                let f := shl(7, gt(r, 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(6, gt(r, 0xFFFFFFFFFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(5, gt(r, 0xFFFFFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(4, gt(r, 0xFFFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(3, gt(r, 0xFF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(2, gt(r, 0xF))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := shl(1, gt(r, 0x3))
                msb := or(msb, f)
                r := shr(f, r)
            }
            assembly {
                let f := gt(r, 0x1)
                msb := or(msb, f)
            }

            if (msb >= 128) r = ratio >> (msb - 127);
            else r = ratio << (127 - msb);

            int256 log_2 = (int256(msb) - 128) << 64;

            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(63, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(62, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(61, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(60, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(59, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(58, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(57, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(56, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(55, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(54, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(53, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(52, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(51, f))
                r := shr(f, r)
            }
            assembly {
                r := shr(127, mul(r, r))
                let f := shr(128, r)
                log_2 := or(log_2, shl(50, f))
            }

            int256 log_sqrt10001 = log_2 * 255738958999603826347141; // 128.128 number

            int24 tickLow = int24((log_sqrt10001 - 3402992956809132418596140100660247210) >> 128);
            int24 tickHi = int24((log_sqrt10001 + 291339464771989622907027621153398088495) >> 128);

            tick = tickLow == tickHi ? tickLow : getSqrtRatioAtTick(tickHi) <= sqrtPriceX96 ? tickHi : tickLow;
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title IOmniDragonLotteryManager
 * @author 0xakita.eth
 * @dev Interface for lottery manager with smart fee detection integration
 */
interface IOmniDragonLotteryManager {
    
    // ================================
    // STRUCTS
    // ================================
    
    struct SwapLotteryEntry {
        address trader;
        address tokenIn;
        uint256 amountIn;
        uint256 swapValueUSD;
        uint256 baseProb;              // Base probability from USD amount
        uint256 veDragonMultiplier;    // veDRAGON multiplier (1x to 2.5x)
        uint256 finalProb;             // Final probability
        uint256 requestId;             // Chainlink VRF request ID
        uint256 randomWord;
        bool fulfilled;
        bool won;
        uint256 prizeAmount;
        uint256 timestamp;
    }
    
    struct UserMilestone {
        uint256 totalVolumeUSD;        // Lifetime trading volume
        uint256 lastUpdated;
        mapping(address => uint256) tokenVolumes;
        mapping(uint256 => uint256) chainVolumes;
    }

    // ================================
    // EVENTS
    // ================================
    
    event SwapLotteryCreated(
        uint256 indexed entryId,
        address indexed trader,
        uint256 swapValueUSD,
        uint256 finalProbability,
        uint256 veDragonMultiplier
    );
    
    event VolumeUpdated(
        address indexed trader,
        uint256 volumeAdded,
        uint256 totalVolume
    );
    
    event LotteryFulfilled(
        uint256 indexed entryId,
        address indexed trader,
        bool won,
        uint256 prizeAmount,
        uint256 randomWord
    );

    // ================================
    // MAIN FUNCTIONS
    // ================================
    
    /**
     * @dev Process swap lottery - calculates USD internally using oracle
     * @param trader Address of the trader
     * @param tokenIn Address of input token (should be DRAGON token)
     * @param amountIn Amount of input tokens
     * @return entryId Generated lottery entry ID (0 if rejected)
     * @notice Function is payable to support VRF fee payment
     */
    function processSwapLottery(
        address trader,
        address tokenIn,
        uint256 amountIn
    ) external payable returns (uint256 entryId);

    // ================================
    // VIEW FUNCTIONS
    // ================================
    
    /**
     * @dev Preview lottery probability for a potential swap
     */
    function previewSwapLottery(address trader, uint256 swapValueUSD)
        external
        view
        returns (
            uint256 baseProb,
            uint256 veDragonMultiplier,
            uint256 finalProb,
            uint256 probabilityPercent,
            bool isCapped
        );
    
    /**
     * @dev Get user volume statistics
     */
    function getUserVolume(address trader) 
        external 
        view 
        returns (
            uint256 totalVolume,
            uint256 lastUpdated
        );
    
    /**
     * @dev Get detailed probability breakdown for UI
     */
    function getDetailedProbability(address trader, uint256 swapValueUSD)
        external
        view
        returns (
            uint256 baseProbabilityBPS,      // Base prob in basis points
            uint256 veDragonMultiplierBPS,   // veDRAGON multiplier in basis points (10000 = 1x)
            uint256 finalProbabilityBPS,     // Final prob in basis points
            string memory probabilityDisplay, // Human readable "X.XXX%"
            string memory veDragonBoost,     // Human readable "2.3x boost"
            bool isCapped
        );
    
    /**
     * @dev Get lottery entry details
     */
    function getLotteryEntry(uint256 entryId)
        external
        view
        returns (SwapLotteryEntry memory);
    
    /**
     * @dev Get user's current veDRAGON boost level
     */
    function getUserVeDragonBoost(address trader)
        external
        view
        returns (
            uint256 veDragonBalance,
            uint256 multiplier,
            string memory boostDisplay,
            uint256 percentile
        );

    // ================================
    // ADMIN FUNCTIONS
    // ================================
    
    /**
     * @dev Set authorized swap integrator
     */
    function setSwapIntegrator(address integrator, bool authorized) external;
    
    /**
     * @dev Update VRF configuration
     */
    function updateVRFConfig(
        address vrfCoordinator,
        bytes32 keyHash,
        uint64 subscriptionId
    ) external;
    
    /**
     * @dev Emergency functions
     */
    function emergencyPause() external;
    function emergencyUnpause() external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title IOmniDragonRegistry
 * @dev Interface for OmniDragon registry with oracle management
 */
interface IOmniDragonRegistry {
  /**
   * @dev Simplified struct to hold essential chain configuration
   */
  struct ChainConfig {
    uint16 chainId;
    string chainName;
    address wrappedNativeToken; // WETH, WAVAX, WS, etc.
    string wrappedNativeSymbol; // "WETH", "WAVAX", "WS", etc.
    address uniswapV2Router; // DEX router for this chain
    address uniswapV2Factory; // DEX factory for this chain
    bool isActive; // Whether this chain is active
  }

  /**
   * @dev Oracle configuration struct
   */
  struct OracleConfig {
    address primaryOracle;      // Primary oracle address (Sonic chain)
    uint32 primaryChainEid;    // Primary chain EID
    uint32 lzReadChannelId;    // lzRead channel ID
    bool isConfigured;         // Whether oracle is configured
  }

  // Events
  event ChainRegistered(uint16 indexed chainId, string chainName);
  event ChainUpdated(uint16 indexed chainId);
  event ChainStatusChanged(uint16 indexed chainId, bool isActive);
  
  // Oracle events
  event PriceOracleSet(uint16 indexed chainId, address indexed oracle);
  event PrimaryOracleConfigured(address indexed primaryOracle, uint32 chainEid);
  event LzReadChannelConfigured(uint16 indexed chainId, uint32 channelId);

  /**
   * @notice Register a new chain configuration
   * @param _chainId The chain ID
   * @param _chainName The human-readable chain name
   * @param _wrappedNativeToken The wrapped native token address
   * @param _uniswapV2Router The Uniswap V2 router address
   * @param _uniswapV2Factory The Uniswap V2 factory address
   * @param _isActive Whether this chain is active
   */
  function registerChain(
    uint16 _chainId,
    string calldata _chainName,
    address _wrappedNativeToken,
    address _uniswapV2Router,
    address _uniswapV2Factory,
    bool _isActive
  ) external;

  /**
   * @notice Update existing chain configuration
   * @param _chainId The chain ID to update
   * @param _chainName The human-readable chain name
   * @param _wrappedNativeToken The wrapped native token address
   * @param _uniswapV2Router The Uniswap V2 router address
   * @param _uniswapV2Factory The Uniswap V2 factory address
   */
  function updateChain(
    uint16 _chainId,
    string calldata _chainName,
    address _wrappedNativeToken,
    address _uniswapV2Router,
    address _uniswapV2Factory
  ) external;

  /**
   * @notice Set chain active status
   * @param _chainId The chain ID
   * @param _isActive Whether the chain should be active
   */
  function setChainStatus(uint16 _chainId, bool _isActive) external;

  /**
   * @notice Get chain configuration
   * @param _chainId The chain ID
   * @return config The chain configuration
   */
  function getChainConfig(uint16 _chainId) external view returns (ChainConfig memory config);

  /**
   * @notice Get all supported chains
   * @return Array of supported chain IDs
   */
  function getSupportedChains() external view returns (uint16[] memory);

  /**
   * @notice Get current chain ID
   * @return The current chain ID
   */
  function getCurrentChainId() external view returns (uint16);

  /**
   * @notice Check if chain is supported and active
   * @param _chainId The chain ID to check
   * @return True if chain is supported and active
   */
  function isChainSupported(uint16 _chainId) external view returns (bool);

  /**
   * @notice Get wrapped native token address for a chain
   * @param _chainId The chain ID
   * @return The wrapped native token address
   */
  function getWrappedNativeToken(uint16 _chainId) external view returns (address);

  /**
   * @notice Get wrapped native token symbol for a chain
   * @param _chainId The chain ID
   * @return The wrapped native token symbol
   */
  function getWrappedNativeSymbol(uint16 _chainId) external view returns (string memory);

  /**
   * @notice Get Uniswap V2 router for a chain
   * @param _chainId The chain ID
   * @return The Uniswap V2 router address
   */
  function getUniswapV2Router(uint16 _chainId) external view returns (address);

  /**
   * @notice Get Uniswap V2 factory for a chain
   * @param _chainId The chain ID
   * @return The Uniswap V2 factory address
   */
  function getUniswapV2Factory(uint16 _chainId) external view returns (address);

  /**
   * @notice Get LayerZero endpoint for a chain
   * @param _chainId The chain ID
   * @return The LayerZero endpoint address
   */
  function getLayerZeroEndpoint(uint16 _chainId) external view returns (address);

  // ============ ORACLE MANAGEMENT ============

  /**
   * @notice Set price oracle for a specific chain
   * @param _chainId Chain ID
   * @param _oracle Oracle address
   */
  function setPriceOracle(uint16 _chainId, address _oracle) external;

  /**
   * @notice Get price oracle for a specific chain
   * @param _chainId Chain ID
   * @return Oracle address
   */
  function getPriceOracle(uint16 _chainId) external view returns (address);

  /**
   * @notice Configure primary oracle (on Sonic chain)
   * @param _primaryOracle Primary oracle address
   * @param _chainEid Primary chain EID
   */
  function configurePrimaryOracle(address _primaryOracle, uint32 _chainEid) external;

  /**
   * @notice Set lzRead channel for a chain
   * @param _chainId Chain ID
   * @param _channelId lzRead channel ID
   */
  function setLzReadChannel(uint16 _chainId, uint32 _channelId) external;

  /**
   * @notice Get oracle configuration for a chain
   * @param _chainId Chain ID
   * @return Oracle configuration
   */
  function getOracleConfig(uint16 _chainId) external view returns (OracleConfig memory);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title IOmniDragonChainlinkOracle
 * @notice Interface for OmniDragonChainlinkOracle contract
 * @dev Only includes functions actually used by omniDRAGON token and lottery manager
 */
interface IOmniDragonChainlinkOracle {
    
    // ================================
    // PRICE FUNCTIONS (Core)
    // ================================
    
    /**
     * @notice Get native token USD price from Chainlink
     * @return price Price in 1e18 format
     * @return timestamp Last update timestamp
     */
    function getNativePrice() external view returns (int256 price, uint256 timestamp);
    
    /**
     * @notice Get DRAGON/USD price
     * @return price Price in 1e18 format
     * @return timestamp Last update timestamp
     */
    function getDragonPrice() external view returns (int256 price, uint256 timestamp);
    
    /**
     * @notice Update DRAGON/USD price
     * @param _price DRAGON/USD price in 1e18 format
     * @dev Only callable by authorized dragonToken or owner
     */
    function updateDragonPrice(int256 _price) external;
    
    // ================================
    // STATE VARIABLES (For verification)
    // ================================
    
    function dragonToken() external view returns (address);
    function chainlinkFeed() external view returns (address);
    
    // ================================
    // EVENTS
    // ================================
    
    event DragonPriceUpdated(int256 price, uint256 timestamp, address indexed updater);
    event ChainlinkFeedSet(address indexed feed);
    event DragonTokenSet(address indexed token);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title IUniswapV3Pool
 * @notice Minimal Uniswap V3 pool interface for TWAP price calculation
 * @dev Only includes functions needed for time-weighted average price oracle
 */
interface IUniswapV3Pool {
    /**
     * @notice The current price and tick information
     * @return sqrtPriceX96 The current sqrt(price) in Q64.96 format
     * @return tick The current tick
     * @return observationIndex The index of the last oracle observation
     * @return observationCardinality The current maximum number of observations
     * @return observationCardinalityNext The next maximum number of observations
     * @return feeProtocol The protocol fee
     * @return unlocked Whether the pool is currently locked
     */
    function slot0() external view returns (
        uint160 sqrtPriceX96,
        int24  tick,
        uint16 observationIndex,
        uint16 observationCardinality,
        uint16 observationCardinalityNext,
        uint8  feeProtocol,
        bool   unlocked
    );
    
    /**
     * @notice The first of the two tokens in the pool
     * @return The token0 address
     */
    function token0() external view returns (address);
    
    /**
     * @notice The second of the two tokens in the pool
     * @return The token1 address
     */
    function token1() external view returns (address);
    
    /**
     * @notice Returns cumulative tick and liquidity data for TWAP calculations
     * @param secondsAgos Array of seconds ago to query (e.g., [600, 0] for 10-minute TWAP)
     * @return tickCumulatives Cumulative tick values at each timestamp
     * @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity (unused for simple TWAP)
     */
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (
            int56[] memory tickCumulatives,
            uint160[] memory secondsPerLiquidityCumulativeX128s
        );
    
    /**
     * @notice The currently in-range liquidity
     * @return The liquidity at the current tick
     */
    function liquidity() external view returns (uint128);
}

File 15 of 47 : DragonErrors.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * @title DragonErrors
 * @author 0xakita.eth
 * @notice Shared custom errors for the Dragon ecosystem
 * @dev Centralizes common error definitions to avoid duplication
 * 
 * Social Links:
 * - Twitter: https://x.com/sonicreddragon
 * - Telegram: https://t.me/sonicreddragon
 */
library DragonErrors {
    // ========== GENERAL ERRORS ==========
    
    /// @dev Thrown when a zero address is passed where it's not allowed
    error ZeroAddress();
    
    /// @dev Thrown when an amount is zero where it's not allowed  
    error ZeroAmount();
    
    /// @dev Thrown when a transfer operation fails
    error TransferFailed();
    
    /// @dev Thrown when there's insufficient balance for an operation
    error InsufficientBalance();
    
    /// @dev Thrown when an unauthorized address attempts an action
    error UnauthorizedCaller();
    
    /// @dev Thrown when a contract is paused
    error ContractPaused();
    
    // ========== VALIDATION ERRORS ==========
    
    /// @dev Thrown when invalid fee structure is provided
    error InvalidFeeStructure();
    
    /// @dev Thrown when invalid fee configuration is set
    error InvalidFeeConfiguration();
    
    /// @dev Thrown when transfer amount exceeds maximum allowed
    error MaxTransferExceeded();
    
    /// @dev Thrown when amount is below minimum threshold
    error AmountBelowMinimum();
    
    // ========== STATE ERRORS ==========
    
    /// @dev Thrown when trading is disabled
    error TradingDisabled();
    
    /// @dev Thrown when emergency mode is disabled but emergency action is attempted
    error EmergencyModeDisabled();
    
    /// @dev Thrown when operation is attempted with no available jackpot
    error NoJackpotToPay();
    
    /// @dev Thrown when wrapped token is not set but required
    error WrappedTokenNotSet();
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { OApp, Origin } from "../oapp/OApp.sol";
import { OAppOptionsType3 } from "../oapp/libs/OAppOptionsType3.sol";
import { IOAppMsgInspector } from "../oapp/interfaces/IOAppMsgInspector.sol";

import { OAppPreCrimeSimulator } from "../precrime/OAppPreCrimeSimulator.sol";

import { IOFT, SendParam, OFTLimit, OFTReceipt, OFTFeeDetail, MessagingReceipt, MessagingFee } from "./interfaces/IOFT.sol";
import { OFTMsgCodec } from "./libs/OFTMsgCodec.sol";
import { OFTComposeMsgCodec } from "./libs/OFTComposeMsgCodec.sol";

/**
 * @title OFTCore
 * @dev Abstract contract for the OftChain (OFT) token.
 */
abstract contract OFTCore is IOFT, OApp, OAppPreCrimeSimulator, OAppOptionsType3 {
    using OFTMsgCodec for bytes;
    using OFTMsgCodec for bytes32;

    // @notice Provides a conversion rate when swapping between denominations of SD and LD
    //      - shareDecimals == SD == shared Decimals
    //      - localDecimals == LD == local decimals
    // @dev Considers that tokens have different decimal amounts on various chains.
    // @dev eg.
    //  For a token
    //      - locally with 4 decimals --> 1.2345 => uint(12345)
    //      - remotely with 2 decimals --> 1.23 => uint(123)
    //      - The conversion rate would be 10 ** (4 - 2) = 100
    //  @dev If you want to send 1.2345 -> (uint 12345), you CANNOT represent that value on the remote,
    //  you can only display 1.23 -> uint(123).
    //  @dev To preserve the dust that would otherwise be lost on that conversion,
    //  we need to unify a denomination that can be represented on ALL chains inside of the OFT mesh
    uint256 public immutable decimalConversionRate;

    // @notice Msg types that are used to identify the various OFT operations.
    // @dev This can be extended in child contracts for non-default oft operations
    // @dev These values are used in things like combineOptions() in OAppOptionsType3.sol.
    uint16 public constant SEND = 1;
    uint16 public constant SEND_AND_CALL = 2;

    // Address of an optional contract to inspect both 'message' and 'options'
    address public msgInspector;
    event MsgInspectorSet(address inspector);

    /**
     * @dev Constructor.
     * @param _localDecimals The decimals of the token on the local chain (this chain).
     * @param _endpoint The address of the LayerZero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     */
    constructor(uint8 _localDecimals, address _endpoint, address _delegate) OApp(_endpoint, _delegate) {
        if (_localDecimals < sharedDecimals()) revert InvalidLocalDecimals();
        decimalConversionRate = 10 ** (_localDecimals - sharedDecimals());
    }

    /**
     * @notice Retrieves interfaceID and the version of the OFT.
     * @return interfaceId The interface ID.
     * @return version The version.
     *
     * @dev interfaceId: This specific interface ID is '0x02e49c2c'.
     * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs.
     * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented.
     * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1)
     */
    function oftVersion() external pure virtual returns (bytes4 interfaceId, uint64 version) {
        return (type(IOFT).interfaceId, 1);
    }

    /**
     * @dev Retrieves the shared decimals of the OFT.
     * @return The shared decimals of the OFT.
     *
     * @dev Sets an implicit cap on the amount of tokens, over uint64.max() will need some sort of outbound cap / totalSupply cap
     * Lowest common decimal denominator between chains.
     * Defaults to 6 decimal places to provide up to 18,446,744,073,709.551615 units (max uint64).
     * For tokens exceeding this totalSupply(), they will need to override the sharedDecimals function with something smaller.
     * ie. 4 sharedDecimals would be 1,844,674,407,370,955.1615
     */
    function sharedDecimals() public view virtual returns (uint8) {
        return 6;
    }

    /**
     * @dev Sets the message inspector address for the OFT.
     * @param _msgInspector The address of the message inspector.
     *
     * @dev This is an optional contract that can be used to inspect both 'message' and 'options'.
     * @dev Set it to address(0) to disable it, or set it to a contract address to enable it.
     */
    function setMsgInspector(address _msgInspector) public virtual onlyOwner {
        msgInspector = _msgInspector;
        emit MsgInspectorSet(_msgInspector);
    }

    /**
     * @notice Provides a quote for OFT-related operations.
     * @param _sendParam The parameters for the send operation.
     * @return oftLimit The OFT limit information.
     * @return oftFeeDetails The details of OFT fees.
     * @return oftReceipt The OFT receipt information.
     */
    function quoteOFT(
        SendParam calldata _sendParam
    )
        external
        view
        virtual
        returns (OFTLimit memory oftLimit, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory oftReceipt)
    {
        uint256 minAmountLD = 0; // Unused in the default implementation.
        uint256 maxAmountLD = type(uint64).max; // Unused in the default implementation.
        oftLimit = OFTLimit(minAmountLD, maxAmountLD);

        // Unused in the default implementation; reserved for future complex fee details.
        oftFeeDetails = new OFTFeeDetail[](0);

        // @dev This is the same as the send() operation, but without the actual send.
        // - amountSentLD is the amount in local decimals that would be sent from the sender.
        // - amountReceivedLD is the amount in local decimals that will be credited to the recipient on the remote OFT instance.
        // @dev The amountSentLD MIGHT not equal the amount the user actually receives. HOWEVER, the default does.
        (uint256 amountSentLD, uint256 amountReceivedLD) = _debitView(
            _sendParam.amountLD,
            _sendParam.minAmountLD,
            _sendParam.dstEid
        );
        oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);
    }

    /**
     * @notice Provides a quote for the send() operation.
     * @param _sendParam The parameters for the send() operation.
     * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token.
     * @return msgFee The calculated LayerZero messaging fee from the send() operation.
     *
     * @dev MessagingFee: LayerZero msg fee
     *  - nativeFee: The native fee.
     *  - lzTokenFee: The lzToken fee.
     */
    function quoteSend(
        SendParam calldata _sendParam,
        bool _payInLzToken
    ) external view virtual returns (MessagingFee memory msgFee) {
        // @dev mock the amount to receive, this is the same operation used in the send().
        // The quote is as similar as possible to the actual send() operation.
        (, uint256 amountReceivedLD) = _debitView(_sendParam.amountLD, _sendParam.minAmountLD, _sendParam.dstEid);

        // @dev Builds the options and OFT message to quote in the endpoint.
        (bytes memory message, bytes memory options) = _buildMsgAndOptions(_sendParam, amountReceivedLD);

        // @dev Calculates the LayerZero fee for the send() operation.
        return _quote(_sendParam.dstEid, message, options, _payInLzToken);
    }

    /**
     * @dev Executes the send operation.
     * @param _sendParam The parameters for the send operation.
     * @param _fee The calculated fee for the send() operation.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess funds.
     * @return msgReceipt The receipt for the send operation.
     * @return oftReceipt The OFT receipt information.
     *
     * @dev MessagingReceipt: LayerZero msg receipt
     *  - guid: The unique identifier for the sent message.
     *  - nonce: The nonce of the sent message.
     *  - fee: The LayerZero fee incurred for the message.
     */
    function send(
        SendParam calldata _sendParam,
        MessagingFee calldata _fee,
        address _refundAddress
    ) external payable virtual returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
        // @dev Applies the token transfers regarding this send() operation.
        // - amountSentLD is the amount in local decimals that was ACTUALLY sent/debited from the sender.
        // - amountReceivedLD is the amount in local decimals that will be received/credited to the recipient on the remote OFT instance.
        (uint256 amountSentLD, uint256 amountReceivedLD) = _debit(
            msg.sender,
            _sendParam.amountLD,
            _sendParam.minAmountLD,
            _sendParam.dstEid
        );

        // @dev Builds the options and OFT message to quote in the endpoint.
        (bytes memory message, bytes memory options) = _buildMsgAndOptions(_sendParam, amountReceivedLD);

        // @dev Sends the message to the LayerZero endpoint and returns the LayerZero msg receipt.
        msgReceipt = _lzSend(_sendParam.dstEid, message, options, _fee, _refundAddress);
        // @dev Formulate the OFT receipt.
        oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);

        emit OFTSent(msgReceipt.guid, _sendParam.dstEid, msg.sender, amountSentLD, amountReceivedLD);
    }

    /**
     * @dev Internal function to build the message and options.
     * @param _sendParam The parameters for the send() operation.
     * @param _amountLD The amount in local decimals.
     * @return message The encoded message.
     * @return options The encoded options.
     */
    function _buildMsgAndOptions(
        SendParam calldata _sendParam,
        uint256 _amountLD
    ) internal view virtual returns (bytes memory message, bytes memory options) {
        bool hasCompose;
        // @dev This generated message has the msg.sender encoded into the payload so the remote knows who the caller is.
        (message, hasCompose) = OFTMsgCodec.encode(
            _sendParam.to,
            _toSD(_amountLD),
            // @dev Must be include a non empty bytes if you want to compose, EVEN if you dont need it on the remote.
            // EVEN if you dont require an arbitrary payload to be sent... eg. '0x01'
            _sendParam.composeMsg
        );
        // @dev Change the msg type depending if its composed or not.
        uint16 msgType = hasCompose ? SEND_AND_CALL : SEND;
        // @dev Combine the callers _extraOptions with the enforced options via the OAppOptionsType3.
        options = combineOptions(_sendParam.dstEid, msgType, _sendParam.extraOptions);

        // @dev Optionally inspect the message and options depending if the OApp owner has set a msg inspector.
        // @dev If it fails inspection, needs to revert in the implementation. ie. does not rely on return boolean
        if (msgInspector != address(0)) IOAppMsgInspector(msgInspector).inspect(message, options);
    }

    /**
     * @dev Internal function to handle the receive on the LayerZero endpoint.
     * @param _origin The origin information.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address from the src chain.
     *  - nonce: The nonce of the LayerZero message.
     * @param _guid The unique identifier for the received LayerZero message.
     * @param _message The encoded message.
     * @dev _executor The address of the executor.
     * @dev _extraData Additional data.
     */
    function _lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address /*_executor*/, // @dev unused in the default implementation.
        bytes calldata /*_extraData*/ // @dev unused in the default implementation.
    ) internal virtual override {
        // @dev The src sending chain doesnt know the address length on this chain (potentially non-evm)
        // Thus everything is bytes32() encoded in flight.
        address toAddress = _message.sendTo().bytes32ToAddress();
        // @dev Credit the amountLD to the recipient and return the ACTUAL amount the recipient received in local decimals
        uint256 amountReceivedLD = _credit(toAddress, _toLD(_message.amountSD()), _origin.srcEid);

        if (_message.isComposed()) {
            // @dev Proprietary composeMsg format for the OFT.
            bytes memory composeMsg = OFTComposeMsgCodec.encode(
                _origin.nonce,
                _origin.srcEid,
                amountReceivedLD,
                _message.composeMsg()
            );

            // @dev Stores the lzCompose payload that will be executed in a separate tx.
            // Standardizes functionality for executing arbitrary contract invocation on some non-evm chains.
            // @dev The off-chain executor will listen and process the msg based on the src-chain-callers compose options passed.
            // @dev The index is used when a OApp needs to compose multiple msgs on lzReceive.
            // For default OFT implementation there is only 1 compose msg per lzReceive, thus its always 0.
            endpoint.sendCompose(toAddress, _guid, 0 /* the index of the composed message*/, composeMsg);
        }

        emit OFTReceived(_guid, _origin.srcEid, toAddress, amountReceivedLD);
    }

    /**
     * @dev Internal function to handle the OAppPreCrimeSimulator simulated receive.
     * @param _origin The origin information.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address from the src chain.
     *  - nonce: The nonce of the LayerZero message.
     * @param _guid The unique identifier for the received LayerZero message.
     * @param _message The LayerZero message.
     * @param _executor The address of the off-chain executor.
     * @param _extraData Arbitrary data passed by the msg executor.
     *
     * @dev Enables the preCrime simulator to mock sending lzReceive() messages,
     * routes the msg down from the OAppPreCrimeSimulator, and back up to the OAppReceiver.
     */
    function _lzReceiveSimulate(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) internal virtual override {
        _lzReceive(_origin, _guid, _message, _executor, _extraData);
    }

    /**
     * @dev Check if the peer is considered 'trusted' by the OApp.
     * @param _eid The endpoint ID to check.
     * @param _peer The peer to check.
     * @return Whether the peer passed is considered 'trusted' by the OApp.
     *
     * @dev Enables OAppPreCrimeSimulator to check whether a potential Inbound Packet is from a trusted source.
     */
    function isPeer(uint32 _eid, bytes32 _peer) public view virtual override returns (bool) {
        return peers[_eid] == _peer;
    }

    /**
     * @dev Internal function to remove dust from the given local decimal amount.
     * @param _amountLD The amount in local decimals.
     * @return amountLD The amount after removing dust.
     *
     * @dev Prevents the loss of dust when moving amounts between chains with different decimals.
     * @dev eg. uint(123) with a conversion rate of 100 becomes uint(100).
     */
    function _removeDust(uint256 _amountLD) internal view virtual returns (uint256 amountLD) {
        return (_amountLD / decimalConversionRate) * decimalConversionRate;
    }

    /**
     * @dev Internal function to convert an amount from shared decimals into local decimals.
     * @param _amountSD The amount in shared decimals.
     * @return amountLD The amount in local decimals.
     */
    function _toLD(uint64 _amountSD) internal view virtual returns (uint256 amountLD) {
        return _amountSD * decimalConversionRate;
    }

    /**
     * @dev Internal function to convert an amount from local decimals into shared decimals.
     * @param _amountLD The amount in local decimals.
     * @return amountSD The amount in shared decimals.
     */
    function _toSD(uint256 _amountLD) internal view virtual returns (uint64 amountSD) {
        return uint64(_amountLD / decimalConversionRate);
    }

    /**
     * @dev Internal function to mock the amount mutation from a OFT debit() operation.
     * @param _amountLD The amount to send in local decimals.
     * @param _minAmountLD The minimum amount to send in local decimals.
     * @dev _dstEid The destination endpoint ID.
     * @return amountSentLD The amount sent, in local decimals.
     * @return amountReceivedLD The amount to be received on the remote chain, in local decimals.
     *
     * @dev This is where things like fees would be calculated and deducted from the amount to be received on the remote.
     */
    function _debitView(
        uint256 _amountLD,
        uint256 _minAmountLD,
        uint32 /*_dstEid*/
    ) internal view virtual returns (uint256 amountSentLD, uint256 amountReceivedLD) {
        // @dev Remove the dust so nothing is lost on the conversion between chains with different decimals for the token.
        amountSentLD = _removeDust(_amountLD);
        // @dev The amount to send is the same as amount received in the default implementation.
        amountReceivedLD = amountSentLD;

        // @dev Check for slippage.
        if (amountReceivedLD < _minAmountLD) {
            revert SlippageExceeded(amountReceivedLD, _minAmountLD);
        }
    }

    /**
     * @dev Internal function to perform a debit operation.
     * @param _from The address to debit.
     * @param _amountLD The amount to send in local decimals.
     * @param _minAmountLD The minimum amount to send in local decimals.
     * @param _dstEid The destination endpoint ID.
     * @return amountSentLD The amount sent in local decimals.
     * @return amountReceivedLD The amount received in local decimals on the remote.
     *
     * @dev Defined here but are intended to be overriden depending on the OFT implementation.
     * @dev Depending on OFT implementation the _amountLD could differ from the amountReceivedLD.
     */
    function _debit(
        address _from,
        uint256 _amountLD,
        uint256 _minAmountLD,
        uint32 _dstEid
    ) internal virtual returns (uint256 amountSentLD, uint256 amountReceivedLD);

    /**
     * @dev Internal function to perform a credit operation.
     * @param _to The address to credit.
     * @param _amountLD The amount to credit in local decimals.
     * @param _srcEid The source endpoint ID.
     * @return amountReceivedLD The amount ACTUALLY received in local decimals.
     *
     * @dev Defined here but are intended to be overriden depending on the OFT implementation.
     * @dev Depending on OFT implementation the _amountLD could differ from the amountReceivedLD.
     */
    function _credit(
        address _to,
        uint256 _amountLD,
        uint32 _srcEid
    ) internal virtual returns (uint256 amountReceivedLD);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppSender
 * @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
 */
abstract contract OAppSender is OAppCore {
    using SafeERC20 for IERC20;

    // Custom error messages
    error NotEnoughNative(uint256 msgValue);
    error LzTokenUnavailable();

    // @dev The version of the OAppSender implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant SENDER_VERSION = 1;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
     * ie. this is a SEND only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (SENDER_VERSION, 0);
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
     * @return fee The calculated MessagingFee for the message.
     *      - nativeFee: The native fee for the message.
     *      - lzTokenFee: The LZ token fee for the message.
     */
    function _quote(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        bool _payInLzToken
    ) internal view virtual returns (MessagingFee memory fee) {
        return
            endpoint.quote(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
                address(this)
            );
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _fee The calculated LayerZero fee for the message.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess fee values sent to the endpoint.
     * @return receipt The receipt for the sent message.
     *      - guid: The unique identifier for the sent message.
     *      - nonce: The nonce of the sent message.
     *      - fee: The LayerZero fee incurred for the message.
     */
    function _lzSend(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        MessagingFee memory _fee,
        address _refundAddress
    ) internal virtual returns (MessagingReceipt memory receipt) {
        // @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
        uint256 messageValue = _payNative(_fee.nativeFee);
        if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);

        return
            // solhint-disable-next-line check-send-result
            endpoint.send{ value: messageValue }(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
                _refundAddress
            );
    }

    /**
     * @dev Internal function to pay the native fee associated with the message.
     * @param _nativeFee The native fee to be paid.
     * @return nativeFee The amount of native currency paid.
     *
     * @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
     * this will need to be overridden because msg.value would contain multiple lzFees.
     * @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
     * @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
     * @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
     */
    function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
        if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
        return _nativeFee;
    }

    /**
     * @dev Internal function to pay the LZ token fee associated with the message.
     * @param _lzTokenFee The LZ token fee to be paid.
     *
     * @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
     * @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
     */
    function _payLzToken(uint256 _lzTokenFee) internal virtual {
        // @dev Cannot cache the token because it is not immutable in the endpoint.
        address lzToken = endpoint.lzToken();
        if (lzToken == address(0)) revert LzTokenUnavailable();

        // Pay LZ token fee by sending tokens to the endpoint.
        IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

File 23 of 47 : OApp.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppSender, MessagingFee, MessagingReceipt } from "./OAppSender.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppReceiver, Origin } from "./OAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OApp
 * @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality.
 */
abstract contract OApp is OAppSender, OAppReceiver {
    /**
     * @dev Constructor to initialize the OApp with the provided endpoint and owner.
     * @param _endpoint The address of the LOCAL LayerZero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     */
    constructor(address _endpoint, address _delegate) OAppCore(_endpoint, _delegate) {}

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol implementation.
     * @return receiverVersion The version of the OAppReceiver.sol implementation.
     */
    function oAppVersion()
        public
        pure
        virtual
        override(OAppSender, OAppReceiver)
        returns (uint64 senderVersion, uint64 receiverVersion)
    {
        return (SENDER_VERSION, RECEIVER_VERSION);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppOptionsType3, EnforcedOptionParam } from "../interfaces/IOAppOptionsType3.sol";

/**
 * @title OAppOptionsType3
 * @dev Abstract contract implementing the IOAppOptionsType3 interface with type 3 options.
 */
abstract contract OAppOptionsType3 is IOAppOptionsType3, Ownable {
    uint16 internal constant OPTION_TYPE_3 = 3;

    // @dev The "msgType" should be defined in the child contract.
    mapping(uint32 eid => mapping(uint16 msgType => bytes enforcedOption)) public enforcedOptions;

    /**
     * @dev Sets the enforced options for specific endpoint and message type combinations.
     * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc.
     * @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType.
     * eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay
     * if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose().
     */
    function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) public virtual onlyOwner {
        _setEnforcedOptions(_enforcedOptions);
    }

    /**
     * @dev Sets the enforced options for specific endpoint and message type combinations.
     * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options.
     *
     * @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc.
     * @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType.
     * eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay
     * if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose().
     */
    function _setEnforcedOptions(EnforcedOptionParam[] memory _enforcedOptions) internal virtual {
        for (uint256 i = 0; i < _enforcedOptions.length; i++) {
            // @dev Enforced options are only available for optionType 3, as type 1 and 2 dont support combining.
            _assertOptionsType3(_enforcedOptions[i].options);
            enforcedOptions[_enforcedOptions[i].eid][_enforcedOptions[i].msgType] = _enforcedOptions[i].options;
        }

        emit EnforcedOptionSet(_enforcedOptions);
    }

    /**
     * @notice Combines options for a given endpoint and message type.
     * @param _eid The endpoint ID.
     * @param _msgType The OAPP message type.
     * @param _extraOptions Additional options passed by the caller.
     * @return options The combination of caller specified options AND enforced options.
     *
     * @dev If there is an enforced lzReceive option:
     * - {gasLimit: 200k, msg.value: 1 ether} AND a caller supplies a lzReceive option: {gasLimit: 100k, msg.value: 0.5 ether}
     * - The resulting options will be {gasLimit: 300k, msg.value: 1.5 ether} when the message is executed on the remote lzReceive() function.
     * @dev This presence of duplicated options is handled off-chain in the verifier/executor.
     */
    function combineOptions(
        uint32 _eid,
        uint16 _msgType,
        bytes calldata _extraOptions
    ) public view virtual returns (bytes memory) {
        bytes memory enforced = enforcedOptions[_eid][_msgType];

        // No enforced options, pass whatever the caller supplied, even if it's empty or legacy type 1/2 options.
        if (enforced.length == 0) return _extraOptions;

        // No caller options, return enforced
        if (_extraOptions.length == 0) return enforced;

        // @dev If caller provided _extraOptions, must be type 3 as its the ONLY type that can be combined.
        if (_extraOptions.length >= 2) {
            _assertOptionsType3(_extraOptions);
            // @dev Remove the first 2 bytes containing the type from the _extraOptions and combine with enforced.
            return bytes.concat(enforced, _extraOptions[2:]);
        }

        // No valid set of options was found.
        revert InvalidOptions(_extraOptions);
    }

    /**
     * @dev Internal function to assert that options are of type 3.
     * @param _options The options to be checked.
     */
    function _assertOptionsType3(bytes memory _options) internal pure virtual {
        uint16 optionsType;
        assembly {
            optionsType := mload(add(_options, 2))
        }
        if (optionsType != OPTION_TYPE_3) revert InvalidOptions(_options);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

/**
 * @title IOAppMsgInspector
 * @dev Interface for the OApp Message Inspector, allowing examination of message and options contents.
 */
interface IOAppMsgInspector {
    // Custom error message for inspection failure
    error InspectionFailed(bytes message, bytes options);

    /**
     * @notice Allows the inspector to examine LayerZero message contents and optionally throw a revert if invalid.
     * @param _message The message payload to be inspected.
     * @param _options Additional options or parameters for inspection.
     * @return valid A boolean indicating whether the inspection passed (true) or failed (false).
     *
     * @dev Optionally done as a revert, OR use the boolean provided to handle the failure.
     */
    function inspect(bytes calldata _message, bytes calldata _options) external view returns (bool valid);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IPreCrime } from "./interfaces/IPreCrime.sol";
import { IOAppPreCrimeSimulator, InboundPacket, Origin } from "./interfaces/IOAppPreCrimeSimulator.sol";

/**
 * @title OAppPreCrimeSimulator
 * @dev Abstract contract serving as the base for preCrime simulation functionality in an OApp.
 */
abstract contract OAppPreCrimeSimulator is IOAppPreCrimeSimulator, Ownable {
    // The address of the preCrime implementation.
    address public preCrime;

    /**
     * @dev Retrieves the address of the OApp contract.
     * @return The address of the OApp contract.
     *
     * @dev The simulator contract is the base contract for the OApp by default.
     * @dev If the simulator is a separate contract, override this function.
     */
    function oApp() external view virtual returns (address) {
        return address(this);
    }

    /**
     * @dev Sets the preCrime contract address.
     * @param _preCrime The address of the preCrime contract.
     */
    function setPreCrime(address _preCrime) public virtual onlyOwner {
        preCrime = _preCrime;
        emit PreCrimeSet(_preCrime);
    }

    /**
     * @dev Interface for pre-crime simulations. Always reverts at the end with the simulation results.
     * @param _packets An array of InboundPacket objects representing received packets to be delivered.
     *
     * @dev WARNING: MUST revert at the end with the simulation results.
     * @dev Gives the preCrime implementation the ability to mock sending packets to the lzReceive function,
     * WITHOUT actually executing them.
     */
    function lzReceiveAndRevert(InboundPacket[] calldata _packets) public payable virtual {
        for (uint256 i = 0; i < _packets.length; i++) {
            InboundPacket calldata packet = _packets[i];

            // Ignore packets that are not from trusted peers.
            if (!isPeer(packet.origin.srcEid, packet.origin.sender)) continue;

            // @dev Because a verifier is calling this function, it doesnt have access to executor params:
            //  - address _executor
            //  - bytes calldata _extraData
            // preCrime will NOT work for OApps that rely on these two parameters inside of their _lzReceive().
            // They are instead stubbed to default values, address(0) and bytes("")
            // @dev Calling this.lzReceiveSimulate removes ability for assembly return 0 callstack exit,
            // which would cause the revert to be ignored.
            this.lzReceiveSimulate{ value: packet.value }(
                packet.origin,
                packet.guid,
                packet.message,
                packet.executor,
                packet.extraData
            );
        }

        // @dev Revert with the simulation results. msg.sender must implement IPreCrime.buildSimulationResult().
        revert SimulationResult(IPreCrime(msg.sender).buildSimulationResult());
    }

    /**
     * @dev Is effectively an internal function because msg.sender must be address(this).
     * Allows resetting the call stack for 'internal' calls.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _guid The unique identifier of the packet.
     * @param _message The message payload of the packet.
     * @param _executor The executor address for the packet.
     * @param _extraData Additional data for the packet.
     */
    function lzReceiveSimulate(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) external payable virtual {
        // @dev Ensure ONLY can be called 'internally'.
        if (msg.sender != address(this)) revert OnlySelf();
        _lzReceiveSimulate(_origin, _guid, _message, _executor, _extraData);
    }

    /**
     * @dev Internal function to handle the OAppPreCrimeSimulator simulated receive.
     * @param _origin The origin information.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address from the src chain.
     *  - nonce: The nonce of the LayerZero message.
     * @param _guid The GUID of the LayerZero message.
     * @param _message The LayerZero message.
     * @param _executor The address of the off-chain executor.
     * @param _extraData Arbitrary data passed by the msg executor.
     *
     * @dev Enables the preCrime simulator to mock sending lzReceive() messages,
     * routes the msg down from the OAppPreCrimeSimulator, and back up to the OAppReceiver.
     */
    function _lzReceiveSimulate(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) internal virtual;

    /**
     * @dev checks if the specified peer is considered 'trusted' by the OApp.
     * @param _eid The endpoint Id to check.
     * @param _peer The peer to check.
     * @return Whether the peer passed is considered 'trusted' by the OApp.
     */
    function isPeer(uint32 _eid, bytes32 _peer) public view virtual returns (bool);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library OFTMsgCodec {
    // Offset constants for encoding and decoding OFT messages
    uint8 private constant SEND_TO_OFFSET = 32;
    uint8 private constant SEND_AMOUNT_SD_OFFSET = 40;

    /**
     * @dev Encodes an OFT LayerZero message.
     * @param _sendTo The recipient address.
     * @param _amountShared The amount in shared decimals.
     * @param _composeMsg The composed message.
     * @return _msg The encoded message.
     * @return hasCompose A boolean indicating whether the message has a composed payload.
     */
    function encode(
        bytes32 _sendTo,
        uint64 _amountShared,
        bytes memory _composeMsg
    ) internal view returns (bytes memory _msg, bool hasCompose) {
        hasCompose = _composeMsg.length > 0;
        // @dev Remote chains will want to know the composed function caller ie. msg.sender on the src.
        _msg = hasCompose
            ? abi.encodePacked(_sendTo, _amountShared, addressToBytes32(msg.sender), _composeMsg)
            : abi.encodePacked(_sendTo, _amountShared);
    }

    /**
     * @dev Checks if the OFT message is composed.
     * @param _msg The OFT message.
     * @return A boolean indicating whether the message is composed.
     */
    function isComposed(bytes calldata _msg) internal pure returns (bool) {
        return _msg.length > SEND_AMOUNT_SD_OFFSET;
    }

    /**
     * @dev Retrieves the recipient address from the OFT message.
     * @param _msg The OFT message.
     * @return The recipient address.
     */
    function sendTo(bytes calldata _msg) internal pure returns (bytes32) {
        return bytes32(_msg[:SEND_TO_OFFSET]);
    }

    /**
     * @dev Retrieves the amount in shared decimals from the OFT message.
     * @param _msg The OFT message.
     * @return The amount in shared decimals.
     */
    function amountSD(bytes calldata _msg) internal pure returns (uint64) {
        return uint64(bytes8(_msg[SEND_TO_OFFSET:SEND_AMOUNT_SD_OFFSET]));
    }

    /**
     * @dev Retrieves the composed message from the OFT message.
     * @param _msg The OFT message.
     * @return The composed message.
     */
    function composeMsg(bytes calldata _msg) internal pure returns (bytes memory) {
        return _msg[SEND_AMOUNT_SD_OFFSET:];
    }

    /**
     * @dev Converts an address to bytes32.
     * @param _addr The address to convert.
     * @return The bytes32 representation of the address.
     */
    function addressToBytes32(address _addr) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(_addr)));
    }

    /**
     * @dev Converts bytes32 to an address.
     * @param _b The bytes32 value to convert.
     * @return The address representation of bytes32.
     */
    function bytes32ToAddress(bytes32 _b) internal pure returns (address) {
        return address(uint160(uint256(_b)));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

library OFTComposeMsgCodec {
    // Offset constants for decoding composed messages
    uint8 private constant NONCE_OFFSET = 8;
    uint8 private constant SRC_EID_OFFSET = 12;
    uint8 private constant AMOUNT_LD_OFFSET = 44;
    uint8 private constant COMPOSE_FROM_OFFSET = 76;

    /**
     * @dev Encodes a OFT composed message.
     * @param _nonce The nonce value.
     * @param _srcEid The source endpoint ID.
     * @param _amountLD The amount in local decimals.
     * @param _composeMsg The composed message.
     * @return _msg The encoded Composed message.
     */
    function encode(
        uint64 _nonce,
        uint32 _srcEid,
        uint256 _amountLD,
        bytes memory _composeMsg // 0x[composeFrom][composeMsg]
    ) internal pure returns (bytes memory _msg) {
        _msg = abi.encodePacked(_nonce, _srcEid, _amountLD, _composeMsg);
    }

    /**
     * @dev Retrieves the nonce from the composed message.
     * @param _msg The message.
     * @return The nonce value.
     */
    function nonce(bytes calldata _msg) internal pure returns (uint64) {
        return uint64(bytes8(_msg[:NONCE_OFFSET]));
    }

    /**
     * @dev Retrieves the source endpoint ID from the composed message.
     * @param _msg The message.
     * @return The source endpoint ID.
     */
    function srcEid(bytes calldata _msg) internal pure returns (uint32) {
        return uint32(bytes4(_msg[NONCE_OFFSET:SRC_EID_OFFSET]));
    }

    /**
     * @dev Retrieves the amount in local decimals from the composed message.
     * @param _msg The message.
     * @return The amount in local decimals.
     */
    function amountLD(bytes calldata _msg) internal pure returns (uint256) {
        return uint256(bytes32(_msg[SRC_EID_OFFSET:AMOUNT_LD_OFFSET]));
    }

    /**
     * @dev Retrieves the composeFrom value from the composed message.
     * @param _msg The message.
     * @return The composeFrom value.
     */
    function composeFrom(bytes calldata _msg) internal pure returns (bytes32) {
        return bytes32(_msg[AMOUNT_LD_OFFSET:COMPOSE_FROM_OFFSET]);
    }

    /**
     * @dev Retrieves the composed message.
     * @param _msg The message.
     * @return The composed message.
     */
    function composeMsg(bytes calldata _msg) internal pure returns (bytes memory) {
        return _msg[COMPOSE_FROM_OFFSET:];
    }

    /**
     * @dev Converts an address to bytes32.
     * @param _addr The address to convert.
     * @return The bytes32 representation of the address.
     */
    function addressToBytes32(address _addr) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(_addr)));
    }

    /**
     * @dev Converts bytes32 to an address.
     * @param _b The bytes32 value to convert.
     * @return The address representation of bytes32.
     */
    function bytes32ToAddress(bytes32 _b) internal pure returns (address) {
        return address(uint160(uint256(_b)));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";

struct MessagingParams {
    uint32 dstEid;
    bytes32 receiver;
    bytes message;
    bytes options;
    bool payInLzToken;
}

struct MessagingReceipt {
    bytes32 guid;
    uint64 nonce;
    MessagingFee fee;
}

struct MessagingFee {
    uint256 nativeFee;
    uint256 lzTokenFee;
}

struct Origin {
    uint32 srcEid;
    bytes32 sender;
    uint64 nonce;
}

interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
    event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);

    event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);

    event PacketDelivered(Origin origin, address receiver);

    event LzReceiveAlert(
        address indexed receiver,
        address indexed executor,
        Origin origin,
        bytes32 guid,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    event LzTokenSet(address token);

    event DelegateSet(address sender, address delegate);

    function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

    function send(
        MessagingParams calldata _params,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory);

    function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;

    function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);

    function initializable(Origin calldata _origin, address _receiver) external view returns (bool);

    function lzReceive(
        Origin calldata _origin,
        address _receiver,
        bytes32 _guid,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;

    // oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
    function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;

    function setLzToken(address _lzToken) external;

    function lzToken() external view returns (address);

    function nativeToken() external view returns (address);

    function setDelegate(address _delegate) external;
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "./interfaces/IOAppCore.sol";

/**
 * @title OAppCore
 * @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
 */
abstract contract OAppCore is IOAppCore, Ownable {
    // The LayerZero endpoint associated with the given OApp
    ILayerZeroEndpointV2 public immutable endpoint;

    // Mapping to store peers associated with corresponding endpoints
    mapping(uint32 eid => bytes32 peer) public peers;

    /**
     * @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
     * @param _endpoint The address of the LOCAL Layer Zero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     *
     * @dev The delegate typically should be set as the owner of the contract.
     */
    constructor(address _endpoint, address _delegate) {
        endpoint = ILayerZeroEndpointV2(_endpoint);

        if (_delegate == address(0)) revert InvalidDelegate();
        endpoint.setDelegate(_delegate);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
        _setPeer(_eid, _peer);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
        peers[_eid] = _peer;
        emit PeerSet(_eid, _peer);
    }

    /**
     * @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
     * ie. the peer is set to bytes32(0).
     * @param _eid The endpoint ID.
     * @return peer The address of the peer associated with the specified endpoint.
     */
    function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
        bytes32 peer = peers[_eid];
        if (peer == bytes32(0)) revert NoPeer(_eid);
        return peer;
    }

    /**
     * @notice Sets the delegate address for the OApp.
     * @param _delegate The address of the delegate to be set.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
     */
    function setDelegate(address _delegate) public onlyOwner {
        endpoint.setDelegate(_delegate);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { IOAppReceiver, Origin } from "./interfaces/IOAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppReceiver
 * @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
 */
abstract contract OAppReceiver is IOAppReceiver, OAppCore {
    // Custom error message for when the caller is not the registered endpoint/
    error OnlyEndpoint(address addr);

    // @dev The version of the OAppReceiver implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant RECEIVER_VERSION = 2;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppSender version. Indicates that the OAppSender is not implemented.
     * ie. this is a RECEIVE only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions.
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (0, RECEIVER_VERSION);
    }

    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @dev _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @dev _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata /*_origin*/,
        bytes calldata /*_message*/,
        address _sender
    ) public view virtual returns (bool) {
        return _sender == address(this);
    }

    /**
     * @notice Checks if the path initialization is allowed based on the provided origin.
     * @param origin The origin information containing the source endpoint and sender address.
     * @return Whether the path has been initialized.
     *
     * @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
     * @dev This defaults to assuming if a peer has been set, its initialized.
     * Can be overridden by the OApp if there is other logic to determine this.
     */
    function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
        return peers[origin.srcEid] == origin.sender;
    }

    /**
     * @notice Retrieves the next nonce for a given source endpoint and sender address.
     * @dev _srcEid The source endpoint ID.
     * @dev _sender The sender address.
     * @return nonce The next nonce.
     *
     * @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
     * @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
     * @dev This is also enforced by the OApp.
     * @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
     */
    function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public view virtual returns (uint64 nonce) {
        return 0;
    }

    /**
     * @dev Entry point for receiving messages or packets from the endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _guid The unique identifier for the received LayerZero message.
     * @param _message The payload of the received message.
     * @param _executor The address of the executor for the received message.
     * @param _extraData Additional arbitrary data provided by the corresponding executor.
     *
     * @dev Entry point for receiving msg/packet from the LayerZero endpoint.
     */
    function lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) public payable virtual {
        // Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
        if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);

        // Ensure that the sender matches the expected peer for the source endpoint.
        if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);

        // Call the internal OApp implementation of lzReceive.
        _lzReceive(_origin, _guid, _message, _executor, _extraData);
    }

    /**
     * @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
     */
    function _lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) internal virtual;
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

/**
 * @dev Struct representing enforced option parameters.
 */
struct EnforcedOptionParam {
    uint32 eid; // Endpoint ID
    uint16 msgType; // Message Type
    bytes options; // Additional options
}

/**
 * @title IOAppOptionsType3
 * @dev Interface for the OApp with Type 3 Options, allowing the setting and combining of enforced options.
 */
interface IOAppOptionsType3 {
    // Custom error message for invalid options
    error InvalidOptions(bytes options);

    // Event emitted when enforced options are set
    event EnforcedOptionSet(EnforcedOptionParam[] _enforcedOptions);

    /**
     * @notice Sets enforced options for specific endpoint and message type combinations.
     * @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options.
     */
    function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) external;

    /**
     * @notice Combines options for a given endpoint and message type.
     * @param _eid The endpoint ID.
     * @param _msgType The OApp message type.
     * @param _extraOptions Additional options passed by the caller.
     * @return options The combination of caller specified options AND enforced options.
     */
    function combineOptions(
        uint32 _eid,
        uint16 _msgType,
        bytes calldata _extraOptions
    ) external view returns (bytes memory options);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;
struct PreCrimePeer {
    uint32 eid;
    bytes32 preCrime;
    bytes32 oApp;
}

// TODO not done yet
interface IPreCrime {
    error OnlyOffChain();

    // for simulate()
    error PacketOversize(uint256 max, uint256 actual);
    error PacketUnsorted();
    error SimulationFailed(bytes reason);

    // for preCrime()
    error SimulationResultNotFound(uint32 eid);
    error InvalidSimulationResult(uint32 eid, bytes reason);
    error CrimeFound(bytes crime);

    function getConfig(bytes[] calldata _packets, uint256[] calldata _packetMsgValues) external returns (bytes memory);

    function simulate(
        bytes[] calldata _packets,
        uint256[] calldata _packetMsgValues
    ) external payable returns (bytes memory);

    function buildSimulationResult() external view returns (bytes memory);

    function preCrime(
        bytes[] calldata _packets,
        uint256[] calldata _packetMsgValues,
        bytes[] calldata _simulations
    ) external;

    function version() external view returns (uint64 major, uint8 minor);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

// @dev Import the Origin so it's exposed to OAppPreCrimeSimulator implementers.
// solhint-disable-next-line no-unused-import
import { InboundPacket, Origin } from "../libs/Packet.sol";

/**
 * @title IOAppPreCrimeSimulator Interface
 * @dev Interface for the preCrime simulation functionality in an OApp.
 */
interface IOAppPreCrimeSimulator {
    // @dev simulation result used in PreCrime implementation
    error SimulationResult(bytes result);
    error OnlySelf();

    /**
     * @dev Emitted when the preCrime contract address is set.
     * @param preCrimeAddress The address of the preCrime contract.
     */
    event PreCrimeSet(address preCrimeAddress);

    /**
     * @dev Retrieves the address of the preCrime contract implementation.
     * @return The address of the preCrime contract.
     */
    function preCrime() external view returns (address);

    /**
     * @dev Retrieves the address of the OApp contract.
     * @return The address of the OApp contract.
     */
    function oApp() external view returns (address);

    /**
     * @dev Sets the preCrime contract address.
     * @param _preCrime The address of the preCrime contract.
     */
    function setPreCrime(address _preCrime) external;

    /**
     * @dev Mocks receiving a packet, then reverts with a series of data to infer the state/result.
     * @param _packets An array of LayerZero InboundPacket objects representing received packets.
     */
    function lzReceiveAndRevert(InboundPacket[] calldata _packets) external payable;

    /**
     * @dev checks if the specified peer is considered 'trusted' by the OApp.
     * @param _eid The endpoint Id to check.
     * @param _peer The peer to check.
     * @return Whether the peer passed is considered 'trusted' by the OApp.
     */
    function isPeer(uint32 _eid, bytes32 _peer) external view returns (bool);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

struct SetConfigParam {
    uint32 eid;
    uint32 configType;
    bytes config;
}

interface IMessageLibManager {
    struct Timeout {
        address lib;
        uint256 expiry;
    }

    event LibraryRegistered(address newLib);
    event DefaultSendLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
    event SendLibrarySet(address sender, uint32 eid, address newLib);
    event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
    event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);

    function registerLibrary(address _lib) external;

    function isRegisteredLibrary(address _lib) external view returns (bool);

    function getRegisteredLibraries() external view returns (address[] memory);

    function setDefaultSendLibrary(uint32 _eid, address _newLib) external;

    function defaultSendLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function defaultReceiveLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;

    function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);

    function isSupportedEid(uint32 _eid) external view returns (bool);

    function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);

    /// ------------------- OApp interfaces -------------------
    function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;

    function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);

    function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);

    function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);

    function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;

    function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);

    function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;

    function getConfig(
        address _oapp,
        address _lib,
        uint32 _eid,
        uint32 _configType
    ) external view returns (bytes memory config);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingComposer {
    event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
    event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
    event LzComposeAlert(
        address indexed from,
        address indexed to,
        address indexed executor,
        bytes32 guid,
        uint16 index,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    function composeQueue(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index
    ) external view returns (bytes32 messageHash);

    function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;

    function lzCompose(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingChannel {
    event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
    event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
    event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);

    function eid() external view returns (uint32);

    // this is an emergency function if a message cannot be verified for some reasons
    // required to provide _nextNonce to avoid race condition
    function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;

    function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);

    function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);

    function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);

    function inboundPayloadHash(
        address _receiver,
        uint32 _srcEid,
        bytes32 _sender,
        uint64 _nonce
    ) external view returns (bytes32);

    function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingContext {
    function isSendingMessage() external view returns (bool);

    function getSendContext() external view returns (uint32 dstEid, address sender);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";

/**
 * @title IOAppCore
 */
interface IOAppCore {
    // Custom error messages
    error OnlyPeer(uint32 eid, bytes32 sender);
    error NoPeer(uint32 eid);
    error InvalidEndpointCall();
    error InvalidDelegate();

    // Event emitted when a peer (OApp) is set for a corresponding endpoint
    event PeerSet(uint32 eid, bytes32 peer);

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     */
    function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);

    /**
     * @notice Retrieves the LayerZero endpoint associated with the OApp.
     * @return iEndpoint The LayerZero endpoint as an interface.
     */
    function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);

    /**
     * @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @return peer The peer address (OApp instance) associated with the corresponding endpoint.
     */
    function peers(uint32 _eid) external view returns (bytes32 peer);

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     */
    function setPeer(uint32 _eid, bytes32 _peer) external;

    /**
     * @notice Sets the delegate address for the OApp Core.
     * @param _delegate The address of the delegate to be set.
     */
    function setDelegate(address _delegate) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import { ILayerZeroReceiver, Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol";

interface IOAppReceiver is ILayerZeroReceiver {
    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement a separate composeMsg sender that is NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata _origin,
        bytes calldata _message,
        address _sender
    ) external view returns (bool isSender);
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { PacketV1Codec } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/PacketV1Codec.sol";

/**
 * @title InboundPacket
 * @dev Structure representing an inbound packet received by the contract.
 */
struct InboundPacket {
    Origin origin; // Origin information of the packet.
    uint32 dstEid; // Destination endpointId of the packet.
    address receiver; // Receiver address for the packet.
    bytes32 guid; // Unique identifier of the packet.
    uint256 value; // msg.value of the packet.
    address executor; // Executor address for the packet.
    bytes message; // Message payload of the packet.
    bytes extraData; // Additional arbitrary data for the packet.
}

/**
 * @title PacketDecoder
 * @dev Library for decoding LayerZero packets.
 */
library PacketDecoder {
    using PacketV1Codec for bytes;

    /**
     * @dev Decode an inbound packet from the given packet data.
     * @param _packet The packet data to decode.
     * @return packet An InboundPacket struct representing the decoded packet.
     */
    function decode(bytes calldata _packet) internal pure returns (InboundPacket memory packet) {
        packet.origin = Origin(_packet.srcEid(), _packet.sender(), _packet.nonce());
        packet.dstEid = _packet.dstEid();
        packet.receiver = _packet.receiverB20();
        packet.guid = _packet.guid();
        packet.message = _packet.message();
    }

    /**
     * @dev Decode multiple inbound packets from the given packet data and associated message values.
     * @param _packets An array of packet data to decode.
     * @param _packetMsgValues An array of associated message values for each packet.
     * @return packets An array of InboundPacket structs representing the decoded packets.
     */
    function decode(
        bytes[] calldata _packets,
        uint256[] memory _packetMsgValues
    ) internal pure returns (InboundPacket[] memory packets) {
        packets = new InboundPacket[](_packets.length);
        for (uint256 i = 0; i < _packets.length; i++) {
            bytes calldata packet = _packets[i];
            packets[i] = PacketDecoder.decode(packet);
            // @dev Allows the verifier to specify the msg.value that gets passed in lzReceive.
            packets[i].value = _packetMsgValues[i];
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { Origin } from "./ILayerZeroEndpointV2.sol";

interface ILayerZeroReceiver {
    function allowInitializePath(Origin calldata _origin) external view returns (bool);

    function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);

    function lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) external payable;
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { Packet } from "../../interfaces/ISendLib.sol";
import { AddressCast } from "../../libs/AddressCast.sol";

library PacketV1Codec {
    using AddressCast for address;
    using AddressCast for bytes32;

    uint8 internal constant PACKET_VERSION = 1;

    // header (version + nonce + path)
    // version
    uint256 private constant PACKET_VERSION_OFFSET = 0;
    //    nonce
    uint256 private constant NONCE_OFFSET = 1;
    //    path
    uint256 private constant SRC_EID_OFFSET = 9;
    uint256 private constant SENDER_OFFSET = 13;
    uint256 private constant DST_EID_OFFSET = 45;
    uint256 private constant RECEIVER_OFFSET = 49;
    // payload (guid + message)
    uint256 private constant GUID_OFFSET = 81; // keccak256(nonce + path)
    uint256 private constant MESSAGE_OFFSET = 113;

    function encode(Packet memory _packet) internal pure returns (bytes memory encodedPacket) {
        encodedPacket = abi.encodePacked(
            PACKET_VERSION,
            _packet.nonce,
            _packet.srcEid,
            _packet.sender.toBytes32(),
            _packet.dstEid,
            _packet.receiver,
            _packet.guid,
            _packet.message
        );
    }

    function encodePacketHeader(Packet memory _packet) internal pure returns (bytes memory) {
        return
            abi.encodePacked(
                PACKET_VERSION,
                _packet.nonce,
                _packet.srcEid,
                _packet.sender.toBytes32(),
                _packet.dstEid,
                _packet.receiver
            );
    }

    function encodePayload(Packet memory _packet) internal pure returns (bytes memory) {
        return abi.encodePacked(_packet.guid, _packet.message);
    }

    function header(bytes calldata _packet) internal pure returns (bytes calldata) {
        return _packet[0:GUID_OFFSET];
    }

    function version(bytes calldata _packet) internal pure returns (uint8) {
        return uint8(bytes1(_packet[PACKET_VERSION_OFFSET:NONCE_OFFSET]));
    }

    function nonce(bytes calldata _packet) internal pure returns (uint64) {
        return uint64(bytes8(_packet[NONCE_OFFSET:SRC_EID_OFFSET]));
    }

    function srcEid(bytes calldata _packet) internal pure returns (uint32) {
        return uint32(bytes4(_packet[SRC_EID_OFFSET:SENDER_OFFSET]));
    }

    function sender(bytes calldata _packet) internal pure returns (bytes32) {
        return bytes32(_packet[SENDER_OFFSET:DST_EID_OFFSET]);
    }

    function senderAddressB20(bytes calldata _packet) internal pure returns (address) {
        return sender(_packet).toAddress();
    }

    function dstEid(bytes calldata _packet) internal pure returns (uint32) {
        return uint32(bytes4(_packet[DST_EID_OFFSET:RECEIVER_OFFSET]));
    }

    function receiver(bytes calldata _packet) internal pure returns (bytes32) {
        return bytes32(_packet[RECEIVER_OFFSET:GUID_OFFSET]);
    }

    function receiverB20(bytes calldata _packet) internal pure returns (address) {
        return receiver(_packet).toAddress();
    }

    function guid(bytes calldata _packet) internal pure returns (bytes32) {
        return bytes32(_packet[GUID_OFFSET:MESSAGE_OFFSET]);
    }

    function message(bytes calldata _packet) internal pure returns (bytes calldata) {
        return bytes(_packet[MESSAGE_OFFSET:]);
    }

    function payload(bytes calldata _packet) internal pure returns (bytes calldata) {
        return bytes(_packet[GUID_OFFSET:]);
    }

    function payloadHash(bytes calldata _packet) internal pure returns (bytes32) {
        return keccak256(payload(_packet));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { MessagingFee } from "./ILayerZeroEndpointV2.sol";
import { IMessageLib } from "./IMessageLib.sol";

struct Packet {
    uint64 nonce;
    uint32 srcEid;
    address sender;
    uint32 dstEid;
    bytes32 receiver;
    bytes32 guid;
    bytes message;
}

interface ISendLib is IMessageLib {
    function send(
        Packet calldata _packet,
        bytes calldata _options,
        bool _payInLzToken
    ) external returns (MessagingFee memory, bytes memory encodedPacket);

    function quote(
        Packet calldata _packet,
        bytes calldata _options,
        bool _payInLzToken
    ) external view returns (MessagingFee memory);

    function setTreasury(address _treasury) external;

    function withdrawFee(address _to, uint256 _amount) external;

    function withdrawLzTokenFee(address _lzToken, address _to, uint256 _amount) external;
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

library AddressCast {
    error AddressCast_InvalidSizeForAddress();
    error AddressCast_InvalidAddress();

    function toBytes32(bytes calldata _addressBytes) internal pure returns (bytes32 result) {
        if (_addressBytes.length > 32) revert AddressCast_InvalidAddress();
        result = bytes32(_addressBytes);
        unchecked {
            uint256 offset = 32 - _addressBytes.length;
            result = result >> (offset * 8);
        }
    }

    function toBytes32(address _address) internal pure returns (bytes32 result) {
        result = bytes32(uint256(uint160(_address)));
    }

    function toBytes(bytes32 _addressBytes32, uint256 _size) internal pure returns (bytes memory result) {
        if (_size == 0 || _size > 32) revert AddressCast_InvalidSizeForAddress();
        result = new bytes(_size);
        unchecked {
            uint256 offset = 256 - _size * 8;
            assembly {
                mstore(add(result, 32), shl(offset, _addressBytes32))
            }
        }
    }

    function toAddress(bytes32 _addressBytes32) internal pure returns (address result) {
        result = address(uint160(uint256(_addressBytes32)));
    }

    function toAddress(bytes calldata _addressBytes) internal pure returns (address result) {
        if (_addressBytes.length != 20) revert AddressCast_InvalidAddress();
        result = address(bytes20(_addressBytes));
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

import { SetConfigParam } from "./IMessageLibManager.sol";

enum MessageLibType {
    Send,
    Receive,
    SendAndReceive
}

interface IMessageLib is IERC165 {
    function setConfig(address _oapp, SetConfigParam[] calldata _config) external;

    function getConfig(uint32 _eid, address _oapp, uint32 _configType) external view returns (bytes memory config);

    function isSupportedEid(uint32 _eid) external view returns (bool);

    // message libs of same major version are compatible
    function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion);

    function messageLibType() external view returns (MessageLibType);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

Settings
{
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "@layerzerolabs/=node_modules/@layerzerolabs/",
    "@layerzerolabs/oapp-evm/=node_modules/@layerzerolabs/lz-evm-oapp-v2/",
    "@layerzerolabs/oft-evm/=node_modules/@layerzerolabs/lz-evm-oapp-v2/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@uniswap/v3-core/=node_modules/@uniswap/v3-core/",
    "@arbitrum/=node_modules/@chainlink/contracts/node_modules/@arbitrum/",
    "@chainlink/=node_modules/@chainlink/",
    "@eth-optimism/=node_modules/@eth-optimism/",
    "@offchainlabs/=node_modules/@offchainlabs/",
    "@scroll-tech/=node_modules/@scroll-tech/",
    "chainlink-vrf-v2.5/=lib/chainlink-vrf-v2.5/",
    "hardhat-deploy/=node_modules/hardhat-deploy/",
    "hardhat/=node_modules/hardhat/",
    "solady/=node_modules/solady/",
    "solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
    "solmate/=node_modules/solmate/",
    "v3-core/=lib/v3-core/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"address","name":"_delegate","type":"address"},{"internalType":"address","name":"_registry","type":"address"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"ERC20InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"approver","type":"address"}],"name":"ERC20InvalidApprover","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"}],"name":"ERC20InvalidReceiver","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"ERC20InvalidSender","type":"error"},{"inputs":[{"internalType":"address","name":"spender","type":"address"}],"name":"ERC20InvalidSpender","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidEndpointCall","type":"error"},{"inputs":[],"name":"InvalidLocalDecimals","type":"error"},{"inputs":[{"internalType":"bytes","name":"options","type":"bytes"}],"name":"InvalidOptions","type":"error"},{"inputs":[],"name":"LzTokenUnavailable","type":"error"},{"inputs":[],"name":"MathOverflowedMulDiv","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"NoPeer","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"}],"name":"NotEnoughNative","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"OnlyEndpoint","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"OnlyPeer","type":"error"},{"inputs":[],"name":"OnlySelf","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"bytes","name":"result","type":"bytes"}],"name":"SimulationResult","type":"error"},{"inputs":[{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"uint256","name":"minAmountLD","type":"uint256"}],"name":"SlippageExceeded","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lottery","type":"address"},{"indexed":true,"internalType":"address","name":"jackpot","type":"address"},{"indexed":true,"internalType":"address","name":"revenue","type":"address"}],"name":"EcosystemUpdated","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"uint16","name":"msgType","type":"uint16"},{"internalType":"bytes","name":"options","type":"bytes"}],"indexed":false,"internalType":"struct EnforcedOptionParam[]","name":"_enforcedOptions","type":"tuple[]"}],"name":"EnforcedOptionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"buyEnabled","type":"bool"},{"indexed":false,"internalType":"bool","name":"sellEnabled","type":"bool"}],"name":"FeeToggled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vault","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":true,"internalType":"enum EventCategory","name":"category","type":"uint8"}],"name":"FeesDistributed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"jackpot","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"veDRAGON","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"burn","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"total","type":"uint16"},{"indexed":false,"internalType":"bool","name":"isBuy","type":"bool"}],"name":"FeesUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"chainId","type":"uint256"}],"name":"InitialMintCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"},{"indexed":false,"internalType":"enum FeeReason","name":"reason","type":"uint8"}],"name":"LotteryFeeApplied","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"enum LotteryFailReason","name":"reason","type":"uint8"}],"name":"LotteryTriggerFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"buyer","type":"address"},{"indexed":false,"internalType":"uint256","name":"dragonAmount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"}],"name":"LotteryTriggered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"inspector","type":"address"}],"name":"MsgInspectorSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"guid","type":"bytes32"},{"indexed":false,"internalType":"uint32","name":"srcEid","type":"uint32"},{"indexed":true,"internalType":"address","name":"toAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountReceivedLD","type":"uint256"}],"name":"OFTReceived","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"guid","type":"bytes32"},{"indexed":false,"internalType":"uint32","name":"dstEid","type":"uint32"},{"indexed":true,"internalType":"address","name":"fromAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountSentLD","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountReceivedLD","type":"uint256"}],"name":"OFTSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oracle","type":"address"}],"name":"OracleUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"eid","type":"uint32"},{"indexed":false,"internalType":"bytes32","name":"peer","type":"bytes32"}],"name":"PeerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"PoolConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"preCrimeAddress","type":"address"}],"name":"PreCrimeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"}],"name":"SwapRouterUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"window","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"staleAfter","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"minLiquidity","type":"uint128"}],"name":"TwapConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"dragonAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"nativeReceived","type":"uint256"},{"indexed":true,"internalType":"address","name":"lottery","type":"address"}],"name":"VRFAutoFunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"dragonAmount","type":"uint256"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"VRFAutoFundingFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"enabled","type":"bool"},{"indexed":false,"internalType":"uint16","name":"feeBps","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"minBalance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"maxSwapAmount","type":"uint256"}],"name":"VRFFundingConfigured","type":"event"},{"inputs":[],"name":"BASIS_POINTS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEAD_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELEGATE","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"INITIAL_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE_BPS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_SUPPLY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"REGISTRY","outputs":[{"internalType":"contract IOmniDragonRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEND","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SEND_AND_CALL","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SONIC_CHAIN_ID","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_twapTickExternal","outputs":[{"internalType":"int24","name":"","type":"int24"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"approvalRequired","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"buyFees","outputs":[{"internalType":"uint16","name":"jackpot","type":"uint16"},{"internalType":"uint16","name":"veDRAGON","type":"uint16"},{"internalType":"uint16","name":"burn","type":"uint16"},{"internalType":"uint16","name":"total","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"uint16","name":"_msgType","type":"uint16"},{"internalType":"bytes","name":"_extraOptions","type":"bytes"}],"name":"combineOptions","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"controlFlags","outputs":[{"internalType":"bool","name":"buyFeesEnabled","type":"bool"},{"internalType":"bool","name":"sellFeesEnabled","type":"bool"},{"internalType":"bool","name":"initialMintCompleted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimalConversionRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"dragonDecimalsCache","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"internalType":"contract ILayerZeroEndpointV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"uint16","name":"msgType","type":"uint16"}],"name":"enforcedOptions","outputs":[{"internalType":"bytes","name":"enforcedOption","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getConfigAddresses","outputs":[{"internalType":"address","name":"oracle","type":"address"},{"internalType":"address","name":"lottery","type":"address"},{"internalType":"address","name":"jackpot","type":"address"},{"internalType":"address","name":"revenue","type":"address"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"native","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"","type":"tuple"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"address","name":"_sender","type":"address"}],"name":"isComposeMsgSender","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"bytes32","name":"_peer","type":"bytes32"}],"name":"isPeer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isSwapRouter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isUniswapV3Pool","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"jackpotVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lotteryManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"_origin","type":"tuple"},{"internalType":"bytes32","name":"_guid","type":"bytes32"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"address","name":"_executor","type":"address"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"origin","type":"tuple"},{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"bytes32","name":"guid","type":"bytes32"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"address","name":"executor","type":"address"},{"internalType":"bytes","name":"message","type":"bytes"},{"internalType":"bytes","name":"extraData","type":"bytes"}],"internalType":"struct InboundPacket[]","name":"_packets","type":"tuple[]"}],"name":"lzReceiveAndRevert","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"_origin","type":"tuple"},{"internalType":"bytes32","name":"_guid","type":"bytes32"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"address","name":"_executor","type":"address"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"lzReceiveSimulate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mainV3Pool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"dragonAmount","type":"uint256"}],"name":"manualVRFFunding","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minPoolLiquidity","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"msgInspector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nativeDecimalsCache","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"nextNonce","outputs":[{"internalType":"uint64","name":"nonce","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oApp","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oAppVersion","outputs":[{"internalType":"uint64","name":"senderVersion","type":"uint64"},{"internalType":"uint64","name":"receiverVersion","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"oftVersion","outputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"},{"internalType":"uint64","name":"version","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"peers","outputs":[{"internalType":"bytes32","name":"peer","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"preCrime","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceOracle","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceStaleAfter","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceTwapWindow","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"bytes32","name":"to","type":"bytes32"},{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"uint256","name":"minAmountLD","type":"uint256"},{"internalType":"bytes","name":"extraOptions","type":"bytes"},{"internalType":"bytes","name":"composeMsg","type":"bytes"},{"internalType":"bytes","name":"oftCmd","type":"bytes"}],"internalType":"struct SendParam","name":"_sendParam","type":"tuple"}],"name":"quoteOFT","outputs":[{"components":[{"internalType":"uint256","name":"minAmountLD","type":"uint256"},{"internalType":"uint256","name":"maxAmountLD","type":"uint256"}],"internalType":"struct OFTLimit","name":"oftLimit","type":"tuple"},{"components":[{"internalType":"int256","name":"feeAmountLD","type":"int256"},{"internalType":"string","name":"description","type":"string"}],"internalType":"struct OFTFeeDetail[]","name":"oftFeeDetails","type":"tuple[]"},{"components":[{"internalType":"uint256","name":"amountSentLD","type":"uint256"},{"internalType":"uint256","name":"amountReceivedLD","type":"uint256"}],"internalType":"struct OFTReceipt","name":"oftReceipt","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"bytes32","name":"to","type":"bytes32"},{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"uint256","name":"minAmountLD","type":"uint256"},{"internalType":"bytes","name":"extraOptions","type":"bytes"},{"internalType":"bytes","name":"composeMsg","type":"bytes"},{"internalType":"bytes","name":"oftCmd","type":"bytes"}],"internalType":"struct SendParam","name":"_sendParam","type":"tuple"},{"internalType":"bool","name":"_payInLzToken","type":"bool"}],"name":"quoteSend","outputs":[{"components":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"lzTokenFee","type":"uint256"}],"internalType":"struct MessagingFee","name":"msgFee","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"registerMe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"revenueDistributor","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sellFees","outputs":[{"internalType":"uint16","name":"jackpot","type":"uint16"},{"internalType":"uint16","name":"veDRAGON","type":"uint16"},{"internalType":"uint16","name":"burn","type":"uint16"},{"internalType":"uint16","name":"total","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"bytes32","name":"to","type":"bytes32"},{"internalType":"uint256","name":"amountLD","type":"uint256"},{"internalType":"uint256","name":"minAmountLD","type":"uint256"},{"internalType":"bytes","name":"extraOptions","type":"bytes"},{"internalType":"bytes","name":"composeMsg","type":"bytes"},{"internalType":"bytes","name":"oftCmd","type":"bytes"}],"internalType":"struct SendParam","name":"_sendParam","type":"tuple"},{"components":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"lzTokenFee","type":"uint256"}],"internalType":"struct MessagingFee","name":"_fee","type":"tuple"},{"internalType":"address","name":"_refundAddress","type":"address"}],"name":"send","outputs":[{"components":[{"internalType":"bytes32","name":"guid","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"},{"components":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"lzTokenFee","type":"uint256"}],"internalType":"struct MessagingFee","name":"fee","type":"tuple"}],"internalType":"struct MessagingReceipt","name":"msgReceipt","type":"tuple"},{"components":[{"internalType":"uint256","name":"amountSentLD","type":"uint256"},{"internalType":"uint256","name":"amountReceivedLD","type":"uint256"}],"internalType":"struct OFTReceipt","name":"oftReceipt","type":"tuple"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lottery","type":"address"},{"internalType":"address","name":"_jackpot","type":"address"},{"internalType":"address","name":"_revenue","type":"address"}],"name":"setEcosystem","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"uint16","name":"msgType","type":"uint16"},{"internalType":"bytes","name":"options","type":"bytes"}],"internalType":"struct EnforcedOptionParam[]","name":"_enforcedOptions","type":"tuple[]"}],"name":"setEnforcedOptions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_jackpot","type":"uint16"},{"internalType":"uint16","name":"_veDRAGON","type":"uint16"},{"internalType":"uint16","name":"_burn","type":"uint16"},{"internalType":"bool","name":"_isBuy","type":"bool"}],"name":"setFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_buyEnabled","type":"bool"},{"internalType":"bool","name":"_sellEnabled","type":"bool"}],"name":"setFeesEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_msgInspector","type":"address"}],"name":"setMsgInspector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"bytes32","name":"_peer","type":"bytes32"}],"name":"setPeer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"setPoolConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_preCrime","type":"address"}],"name":"setPreCrime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oracle","type":"address"}],"name":"setPriceOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"},{"internalType":"bool","name":"isRouter","type":"bool"}],"name":"setSwapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"window","type":"uint32"},{"internalType":"uint256","name":"staleAfter","type":"uint256"},{"internalType":"uint128","name":"minLiq","type":"uint128"}],"name":"setTwapConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"},{"internalType":"bool","name":"isPool","type":"bool"}],"name":"setUniswapV3Pool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"feeBps","type":"uint16"},{"internalType":"uint256","name":"minBalance","type":"uint256"},{"internalType":"uint256","name":"maxSwapAmount","type":"uint256"}],"name":"setVRFFundingConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"}],"name":"setVRFSwapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sharedDecimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateDragonPriceToOracle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"verifyIntegrationConfig","outputs":[{"internalType":"bool","name":"isConfigured","type":"bool"},{"internalType":"uint8","name":"missingComponents","type":"uint8"},{"internalType":"string","name":"configDetails","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vrfFunding","outputs":[{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"uint16","name":"feeBps","type":"uint16"},{"internalType":"uint256","name":"minBalance","type":"uint256"},{"internalType":"uint256","name":"maxSwapAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wrappedNative","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101006040818152346200076c576000620064928038038091620000248287620007a3565b8539830160a084820312620007685783516001600160401b03919082811162000764578162000055918701620007c7565b926020918287015184811162000760579062000073918801620007c7565b95620000818682016200083e565b6200009d608062000095606085016200083e565b93016200083e565b91620000a98162000853565b6001600160a01b03938416979096908815620007485785546001600160a01b031981168a1787558a519886918b9083167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08a80a31660805284841697881562000739575084608051169a8b3b1562000735578a9b8780999a9b9c51809263ca5eb5e160e01b825260049d8e8301528160249b8c925af180156200072b5762000704575b5064e8d4a5100060a0528151838111620006f257600854926001938481811c91168015620006e7575b8c821014620005de579180918c8c94601f80968183116200068d575b92505050508c9084831160011462000619578c926200060d575b5050600019600383901b1c191690841b176008555b815191848311620005fb576009548481811c91168015620005f0575b8c821014620005de57908b82848695941162000585575b50508b9183116001146200051e578a9262000512575b5050600019600383901b1c191690821b176009555b600a558560608b51620002318162000771565b828152828a820152828d820152015260018060401b031980600e5416600e558660608c82815191620002638362000771565b818352818d8401528201520152600f5416600f55895190606082019082821090821117620004fe5786918b918252828152828982015201526060896201f40087151562ff000060105460ff8316809362ffffff1993849160101b16921617176010558351620002d28162000771565b8a81526101f48c82015266b1a2bc2ec500008095820152683635c9adc5dea000009586910152601154161717601155601255601355604b60a21b63ffffffff60a01b196015541617601555611c206016556017549260018060801b03198416601755808216918215620004ee576200034a9062000853565b1615620004ac5760c05260e0526001600160881b031916600960811b1760175546609214620003f4575b8551615bb29081620008e0823960805181818161099c0152818161145c01528181611d7c01528181612a1401528181612b6e01528181614ee10152614f8d015260a0518181816113a30152818161218a015281816128a001528181615123015281816152eb0152615313015260c051816105a3015260e051816118780152f35b600754906a396c41bd9e54ada3800000948583018093116200049b57505091847f053fc7f64e7b809338c1b9fd4303ac5f0bcdd083c4aac2a23078545bebfc1f4694928794600755818152600583528481208481540190557fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef838651868152a36201000062ff000019601054161760105582519182524690820152a2388080808062000374565b634e487b7160e01b84526011905282fd5b885162461bcd60e51b81528088018790526013818601527f496e76616c6964204c5a20656e64706f696e74000000000000000000000000006044820152606490fd5b8a5163d92e233d60e01b81528990fd5b8560418a634e487b7160e01b600052526000fd5b01519050388062000209565b60098b528b8b208594509190601f1984168c8e5b8282106200056d575050841162000553575b505050811b016009556200021e565b015160001960f88460031b161c1916905538808062000544565b83850151865588979095019493840193018e62000532565b909192935060098c5283828d209181870160051c8301938710620005d4575b91869588929594930160051c01915b828110620005c557508d9150620001f3565b8d8155869550879101620005b3565b92508192620005a4565b634e487b7160e01b8b5260228d52898bfd5b90607f1690620001dc565b634e487b7160e01b8a5260418c52888afd5b015190503880620001ab565b869350908c918e601f198516906008855280852094905b8282106200066b575050841162000651575b505050811b01600855620001c0565b015160001960f88460031b161c1916905538808062000642565b91929395968291958786015181550195019301908f9189969594939262000630565b839495506008819492939452209181860160051c8301938610620006dd575b918891869594930160051c01915b828110620006ce57508e9150858e62000191565b8e8155859450889101620006ba565b92508192620006ac565b90607f169062000175565b634e487b7160e01b895260418b528789fd5b83819992991162000719578c5296386200014c565b634e487b7160e01b825260418b528782fd5b8d513d8b823e3d90fd5b8680fd5b632d618d8160e21b8152600490fd5b8951631e4fbdf760e01b815260048101879052602490fd5b8280fd5b8380fd5b5080fd5b600080fd5b608081019081106001600160401b038211176200078d57604052565b634e487b7160e01b600052604160045260246000fd5b601f909101601f19168101906001600160401b038211908210176200078d57604052565b919080601f840112156200076c578251906001600160401b0382116200078d576040519160209162000803601f8301601f1916840185620007a3565b8184528282870101116200076c5760005b8181106200082a57508260009394955001015290565b858101830151848201840152820162000814565b51906001600160a01b03821682036200076c57565b60405163b87f29e160e01b81524661ffff16600482015290602090829060249082906001600160a01b03165afa6000918162000899575b50620008965750600090565b90565b90916020823d8211620008d6575b81620008b660209383620007a3565b81010312620008d35750620008cb906200083e565b90386200088a565b80fd5b3d9150620008a756fe6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806306244f581461055157806306433b1b1461054c57806306fdde0314610547578063095ea7b3146105425780630d35b4151461053d578063111ecdad1461053857806313137d6514610533578063134d4f251461052e578063156a0d0f1461052957806317442b701461052457806318160ddd1461051f5780631936b2781461051a5780631f5e1334146105155780632048db44146105105780632171dcc91461050b57806323b872dd146105065780632630c12f146105015780632a4f12ca146104fc5780632ede5651146104f75780632ff2e9dc146104e8578063302a20d6146104f2578063313ce567146104ed57806332cb6b0c146104e85780633400288b146104e35780633b6f743b146104de5780633be701f1146104d95780633d6add81146104d45780634404c3d6146104cf5780634454a9b1146104ca5780634a2d5c9d146104c55780634d48a48c146104c05780634d536549146104bb5780634e6fd6c4146104b65780634f989520146104b157806352ae2879146103c6578063530e784f146104ac5780635535d461146104a75780635976e045146104a25780635a0dfe4d1461049d5780635e280f11146104985780636fc1b31e146104935780637033568f1461048e57806370a0823114610489578063715018a614610484578063740e0d221461047f5780637d25a05e1461047a57806382413eac14610475578063857749b0146104705780638a59b9a21461046b5780638da5cb5b1461046657806393f234b11461046157806395d89b411461045c578063963efcaa146104575780639a198d61146104525780639f68b9641461044d578063a1bc910f14610448578063a9059cbb14610443578063b3fac98d1461043e578063b731ea0a14610439578063b98bd07014610434578063b9c89a641461042f578063bb0b6a531461042a578063bc70b35414610425578063bd815db014610420578063c31c9c071461041b578063c5c80bf414610416578063c7c7f5b314610411578063c8312ce51461040c578063ca5eb5e114610407578063cf2f568f14610402578063d045a0dc146103fd578063d4243885146103f8578063d55be8c6146103f3578063dd62ed3e146103ee578063e0f3ccf5146103e9578063e1f1c4a7146103e4578063e4748b9e146103df578063eae0a488146103da578063eb6d3a11146103d5578063ee509ff9146103d0578063f2fde38b146103cb578063fc0c546a146103c6578063fdf2b32b146103c15763ff7bd03d0361000e57612fb1565b612ea0565b611a37565b612e14565b612df0565b612dc7565b612d9e565b612d51565b612d34565b612ce7565b612ca2565b612c85565b612c15565b612ab9565b612a7c565b6129e3565b6129c5565b612837565b6127a4565b61277b565b612625565b6125d1565b612596565b612551565b612477565b612402565b6122e9565b6122bd565b61227b565b61225f565b6121ad565b612172565b6120cb565b6120a7565b61207e565b612021565b612005565b611fa7565b611f80565b611edc565b611e81565b611e44565b611e1b565b611dab565b611d66565b611d1e565b611cac565b611c2d565b611a52565b611a0e565b6119f1565b6118e4565b6118a7565b611862565b611839565b611664565b61154a565b61150a565b611349565b6112c7565b61126c565b6112ab565b611292565b611245565b6111c1565b611198565b6110d0565b611090565b610f0f565b610ed4565b610c15565b610bd2565b610bb0565b610b89565b610b6d565b610981565b6108b6565b610810565b610724565b61062e565b61058d565b610566565b600091031261056157565b600080fd5b346105615760003660031901126105615760206001600160801b0360175416604051908152f35b34610561576000366003190112610561576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b60005b8381106105e55750506000910152565b81810151838201526020016105d5565b9060209161060e815180928185528580860191016105d2565b601f01601f1916010190565b90602061062b9281815201906105f5565b90565b346105615760008060031936011261071057604051908060085461065181611abd565b808552916001918083169081156106e6575060011461068b575b6106878561067b81870382611c0c565b6040519182918261061a565b0390f35b9250600883527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee35b8284106106ce57505050810160200161067b8261068761066b565b805460208587018101919091529093019281016106b3565b8695506106879693506020925061067b94915060ff191682840152151560051b820101929361066b565b80fd5b6001600160a01b0381160361056157565b346105615760403660031901126105615761074e60043561074481610713565b6024359033615832565b602060405160018152f35b908160e09103126105615790565b9392916107828560a081019360208091805184520151910152565b60409160a083870152815180915260c086019160c08260051b880101936020809201936000915b8483106107d1575050505050509060606107cf9294019060208091805184520151910152565b565b90919293949584806108006001938d60bf1990820301875285838c5180518452015191818582015201906105f5565b98019301930191949392906107a9565b34610561576020366003190112610561576001600160401b0360043581811161056157610841903690600401610759565b9061084a614cfe565b50610853614cfe565b506040519061086182611ba3565b60008252602082015261068761089a6040519361087d85611bf1565b6000855261088a8161489d565b5060406060820135910135615311565b6108a261366b565b918252602082015260405193849384610767565b34610561576000366003190112610561576004546040516001600160a01b039091168152602090f35b606090600319011261056157600490565b9181601f84011215610561578235916001600160401b038311610561576020838186019501011161056157565b600319810160e081126105615760601361056157600491606435916001600160401b039060843582811161056157816109579187016108f0565b9390939260a43561096781610713565b9260c4359182116105615761097d9188016108f0565b9091565b61098a3661091d565b50929492506001600160a01b039190507f00000000000000000000000000000000000000000000000000000000000000008216338103610b555783356109cf81610ef0565b6109d8816148a7565b906020860135809203610b20575050610a006109f48388615459565b6001600160a01b031690565b91610a26610a16610a11838a615465565b6152dd565b610a1f8761489d565b5084615252565b809760288311610a77575b50505050610a72610a50600080516020615afd8339815191529461489d565b956040519384931696836020909392919363ffffffff60408201951681520152565b0390a3005b90610aa29291610a9c610a8c60408a0161521d565b93610a968a61489d565b92615477565b92615371565b90803b1561056157604051633e5ac80960e11b8152916000918391829084908290610ad2908c8a60048501615227565b03925af18015610b1b57600080516020615afd83398151915294610a7292610a5092610b02575b88919650610a31565b80610b0f610b1592611bde565b80610556565b38610af9565b613d45565b610b2981610ef0565b60405163309afaf360e21b815263ffffffff9190911660048201526024810191909152604490fd5b0390fd5b6040516391ac5e4f60e01b8152336004820152602490fd5b3461056157600036600319011261056157602060405160028152f35b34610561576000366003190112610561576040805162b9270b60e21b815260016020820152f35b3461056157600036600319011261056157604080516001815260026020820152f35b34610561576000366003190112610561576020600754604051908152f35b604090600319011261056157600435610c0881610713565b9060243561062b81610713565b3461056157610c2336610bf0565b90610c2c615598565b6001600160a01b03918183169182151580610ec9575b610c4b90613f43565b601454610c60906001600160a01b03166109f4565b8303610dac575b50601554610c7d906001600160a01b03166109f4565b928116928303610cb0575b507fed7692d7eac8e25ca74b0bcb7b52fe51d01a8910e8e320c6f3223365708d76de600080a3005b601580546001600160a01b0319166001600160a01b0390921691909117905560405163313ce56760e01b8082526020918281600481885afa8015610b1b57610d1a91600091610d8f575b506017805460ff60881b191660889290921b60ff60881b16919091179055565b6040519081528181600481305afa908115610b1b57610d5c92600092610d62575b50506017805460ff60801b191660809290921b60ff60801b16919091179055565b38610c88565b610d819250803d10610d88575b610d798183611c0c565b810190613fce565b3880610d3b565b503d610d6f565b610da69150843d8611610d8857610d798183611c0c565b38610cfa565b604051630dfe168160e01b81529060208083600481885afa928315610b1b57600093610eaa575b5060405163d21220a760e01b8152908082600481895afa908115610b1b57610e4194610e1f938992600094610e7b575b50501690308214918215610e6f575b82610e47575b5050613f93565b60018060a01b03166bffffffffffffffffffffffff60a01b6014541617601455565b38610c67565b90915087808716809214928315610e63575b5050503880610e18565b16149050388781610e59565b81891630149250610e12565b610e9b929450803d10610ea3575b610e938183611c0c565b810190613f7e565b913880610e03565b503d610e89565b81610ec29294503d8511610ea357610e938183611c0c565b9138610dd3565b508184161515610c42565b3461056157600036600319011261056157602060405160018152f35b63ffffffff81160361056157565b6001600160801b0381160361056157565b3461056157606036600319011261056157600435610f2c81610ef0565b60243560443591610f3c83610efe565b610f44615598565b63ffffffff8116600a8110159081611054575b501561101e5761100c7f5ed39a8177ebe03619cb94f5c49cedbee5a9ea0c55ddc44f0aeaff8948924eae93603c84101580611011575b610f9690613fe7565b6015805463ffffffff60a01b191660a085901b63ffffffff60a01b16179055610fbe84601655565b610fde816001600160801b03166001600160801b03196017541617601755565b604051938493849160409194936001600160801b039163ffffffff6060860197168552602085015216910152565b0390a1005b5062015180841115610f8d565b60405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642077696e646f7760901b6044820152606490fd5b610e109150111538610f57565b8015150361056157565b60409060031901126105615760043561108381610713565b9060243561062b81611061565b34610561576100196110a13661106b565b906110aa615598565b60018060a01b0316600052601a60205260406000209060ff801983541691151516179055565b34610561576060366003190112610561576004356110ed81610713565b6024356110f981610713565b6001600160a01b038216600090815260066020908152604080832033845290915290206044359290546001810161114b575b610687611139858585612ff7565b60405190151581529081906020820190565b8381106111715791839161116861068795611139950333836158e6565b9193509161112b565b604051637dc7a0d960e11b8152336004820152602481019190915260448101849052606490fd5b34610561576000366003190112610561576018546040516001600160a01b039091168152602090f35b34610561576040366003190112610561577f81b107915bdf0513375bf3f4b55e32203154ec9b68049c9522e9d3b666c991a2604060043561120181611061565b6024359061120e82611061565b611216615598565b1515906010549015159061ff008260081b169060ff84169061ffff1916171760105582519182526020820152a1005b3461056157600036600319011261056157602063ffffffff60155460a01c16604051908152f35b346105615760003660031901126105615760206040516a396c41bd9e54ada38000008152f35b3461056157600036600319011261056157610019614049565b3461056157600036600319011261056157602060405160128152f35b34610561576040366003190112610561577f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b60043561130581610ef0565b60243590611311615598565b63ffffffff811660005260016020528160406000205561100c604051928392836020909392919363ffffffff60408201951681520152565b3461056157604080600319360112610561576004356001600160401b0381116105615761137a903690600401610759565b9060243561138781611061565b61138f614cfe565b5060608301358335936113a185610ef0565b7f0000000000000000000000000000000000000000000000000000000000000000801561150557806113d79186840135046132ac565b918083106114e5575083926113f3611458969361143d93615112565b906113fd85610ef0565b611405614cfe565b5061140f856148a7565b61142661141a613678565b63ffffffff9097168752565b602086015285850152606084015215156080830152565b815180948192631bb8518b60e31b8352309060048401614d53565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610b1b57610687926000926114b6575b505191829182815181526020918201519181019190915260400190565b816114d79293503d84116114de575b6114cf8183611c0c565b810190614d3f565b9038611499565b503d6114c5565b84516371c4efed60e01b8152600481018490526024810191909152604490fd5b6132c4565b346105615761001961151b3661106b565b90611524615598565b60018060a01b0316600052601960205260406000209060ff801983541691151516179055565b346105615760603660031901126105615760043561156781610713565b60243561157381610713565b6044359161158083610713565b611588615598565b6001600160a01b039081169283151580611617575b8061160c575b6115ac90613f43565b600d80546001600160a01b03199081168617909155600b805482169484169485179055600c80549091166001600160a01b03831617905516917ff5bf353491658caa63438c79ce5f38eff2976c2c075d83bbba7e8b2a2a4bf418600080a4005b5080821615156115a3565b50818316151561159d565b6004359061ffff8216820361056157565b6024359061ffff8216820361056157565b6044359061ffff8216820361056157565b359061ffff8216820361056157565b346105615760803660031901126105615761167d611622565b611685611633565b61168d611644565b916064359261169b84611061565b6116a3615598565b6116b6816116b18585613f2d565b613f2d565b936109c461ffff8616116117fe577f99eecaee2197aae33e41a7fab052496c51b61e908fcdeb223fc543aec60fd4fb9461100c926116f2613697565b61ffff8616815261ffff8716602082015261ffff8216604082015261ffff8316606082015283156117a5576117719061ffff81511690600e549163ffff0000602083015160101b169067ffff000000000000606065ffff00000000604086015160201b1694015160301b16936001600160401b03191617171717600e55565b6040805161ffff968716815296861660208801529085169086015290921660608401529015156080830152819060a0820190565b6117f99061ffff81511690600f549163ffff0000602083015160101b169067ffff000000000000606065ffff00000000604086015160201b1694015160301b16936001600160401b03191617171717600f55565b611771565b60405162461bcd60e51b81526020600482015260136024820152724665652065786365656473206d6178696d756d60681b6044820152606490fd5b3461056157600036600319011261056157600b546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b3461056157600036600319011261056157602060405160928152f35b60ff61062b94936060931515835216602082015281604082015201906105f5565b3461056157600080600319360112610710576018546001600160a01b0316156119e9575b600d5461191d906001600160a01b03166109f4565b156119e1575b600b54611938906001600160a01b03166109f4565b156119d9575b600c54611953906001600160a01b03166109f4565b156119d1575b60145461196e906001600160a01b03166109f4565b156119c9575b601554611989906001600160a01b03166109f4565b156119c1575b60ff81161580156119b1576106876119a5614829565b604051938493846118c3565b6106876119bc6147e3565b6119a5565b60101761198f565b601017611974565b600817611959565b60041761193e565b600217611923565b506001611908565b3461056157600036600319011261056157602060405161dead8152f35b3461056157600036600319011261056157600d546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576020604051308152f35b3461056157602036600319011261056157600435611a6f81610713565b611a77615598565b601880546001600160a01b0319166001600160a01b039290921691821790557f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b8180940394600080a2005b90600182811c92168015611aed575b6020831014611ad757565b634e487b7160e01b600052602260045260246000fd5b91607f1691611acc565b9060009291805491611b0883611abd565b918282526001938481169081600014611b6a5750600114611b2a575b50505050565b90919394506000526020928360002092846000945b838610611b56575050505001019038808080611b24565b805485870183015294019385908201611b3f565b9294505050602093945060ff191683830152151560051b01019038808080611b24565b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117611bbe57604052565b611b8d565b606081019081106001600160401b03821117611bbe57604052565b6001600160401b038111611bbe57604052565b602081019081106001600160401b03821117611bbe57604052565b90601f801991011681019081106001600160401b03821117611bbe57604052565b3461056157604036600319011261056157610687611c91611c98611c85600435611c5681610ef0565b63ffffffff611c63611633565b9116600052600360205260406000209061ffff16600052602052604060002090565b60405192838092611af7565b0382611c0c565b6040519182916020835260208301906105f5565b3461056157602036600319011261056157600435611cc981610713565b611cd1615598565b6001600160a01b0316611ce5811515613f43565b601b80546001600160a01b031916821790557f36db479a3b4d3672bd6f5fca4484283f60b5ac70647b1ceec13ecbb1d030a2df600080a2005b34610561576040366003190112610561576020611d5c600435611d4081610ef0565b6024359063ffffffff1660005260016020526040600020541490565b6040519015158152f35b34610561576000366003190112610561576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b34610561576020366003190112610561577ff0be4f1e87349231d80c36b33f9e8639658eeaf474014dee15a3e6a4d44141976020600435611deb81610713565b611df3615598565b600480546001600160a01b0319166001600160a01b03929092169182179055604051908152a1005b34610561576000366003190112610561576014546040516001600160a01b039091168152602090f35b3461056157602036600319011261056157600435611e6181610713565b60018060a01b031660005260056020526020604060002054604051908152f35b346105615760008060031936011261071057611e9b615598565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461056157602036600319011261056157600435611ef8615598565b611f00615983565b8015611f4d57306000908152600560205260409020611f439190611f279054821115613ac5565b600d54611f3e906001600160a01b03161515613b08565b613710565b6100196001600a55565b60405162461bcd60e51b815260206004820152600b60248201526a16995c9bc8185b5bdd5b9d60aa1b6044820152606490fd5b3461056157604036600319011261056157611f9c600435610ef0565b602060405160008152f35b346105615760a036600319011261056157611fc1366108df565b506064356001600160401b03811161056157611fe19036906004016108f0565b50506020608435611ff181610713565b6040516001600160a01b0390911630148152f35b3461056157600036600319011261056157602060405160068152f35b346105615760003660031901126105615760c060018060a01b0380601854169080600d54169080600b541681600c5416908260145416926015541693604051958652602086015260408501526060840152608083015260a0820152f35b34610561576000366003190112610561576000546040516001600160a01b039091168152602090f35b3461056157600036600319011261056157602060ff60175460801c16604051908152f35b34610561576000806003193601126107105760405190806009546120ee81611abd565b808552916001918083169081156106e65750600114612117576106878561067b81870382611c0c565b9250600983527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af5b82841061215a57505050810160200161067b8261068761066b565b8054602085870181019190915290930192810161213f565b346105615760003660031901126105615760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b3461056157600080600319360112610710576121c7615598565b808060405160208101906307983f4560e21b8252608f6024820152602481526121ef81611bc3565b51908273dc2b0d2dd2b7759d97d50db4eabdc369731108305af16122116136d1565b501561221a5780f35b60405162461bcd60e51b815260206004820152601860248201527f4665654d20726567697374726174696f6e206661696c656400000000000000006044820152606490fd5b3461056157600036600319011261056157602060405160008152f35b346105615760203660031901126105615760043561229881610713565b60018060a01b0316600052601a602052602060ff604060002054166040519015158152f35b34610561576040366003190112610561576020611d5c6004356122df81610713565b6024359033612ff7565b34610561576000806003193601126107105760145461236b91906001600160a01b0316612317811515613b46565b81612320613b98565b60155460a01c63ffffffff16926123458461233a84613bc9565b9063ffffffff169052565b8261234f83613bdb565b52604051808097819463883bdbfd60e01b835260048301613d04565b03915afa908115610b1b5763ffffffff6123b86123c39361068796866123c997926123de575b50506123b26123a56123ac6123a584613bdb565b5160060b90565b92613bc9565b90613d51565b911660060b90613d76565b60020b90565b60405160029190910b81529081906020820190565b6123fa92503d8091833e6123f28183611c0c565b810190613c67565b503880612391565b34610561576000366003190112610561576002546040516001600160a01b039091168152602090f35b906020600319830112610561576004356001600160401b039283821161056157806023830112156105615781600401359384116105615760248460051b83010111610561576024019190565b34610561576124853661242b565b9061248e615598565b61249782613b81565b9060406124a681519384611c0c565b8383526020938484019060051b8301923684116105615780915b8483106124d05761001986614ad0565b6001600160401b0390833582811161056157830191606083360312610561578551926124fb84611bc3565b803561250681610ef0565b84526125138a8201611655565b8a8501528681013591821161056157019036601f830112156105615788926125428493369085813591016148df565b878201528152019201916124c0565b34610561576000366003190112610561576011546012546013546040805160ff85161515815260089490941c61ffff1660208501528301919091526060820152608090f35b346105615760203660031901126105615763ffffffff6004356125b881610ef0565b1660005260016020526020604060002054604051908152f35b34610561576060366003190112610561576004356125ee81610ef0565b6125f6611633565b604435906001600160401b038211610561576106879261261d611c989336906004016108f0565b929091614c20565b61262e3661242b565b60005b81811061269b57604051638e9e709960e01b8152600081600481335afa8015610b1b57610b519160009161267a575b50604051638351eea760e01b81529182916004830161061a565b612695913d8091833e61268d8183611c0c565b81019061553a565b82612660565b6126a6818385615493565b906126d86126d46126b68461489d565b60208501359063ffffffff1660005260016020526040600020541490565b1590565b612771576126ea6101008301836150a6565b926126f760e082016154b6565b906127066101208201826150a6565b959095303b156105615760009461273c60c092604051998a9788968795633411683760e21b875260a08a01358a600489016154c0565b03920135305af1918215610b1b576127599261275e575b50614916565b612631565b80610b0f61276b92611bde565b38612753565b6127599150614916565b3461056157600036600319011261056157601b546040516001600160a01b039091168152602090f35b34610561576020366003190112610561576004356127c181610713565b60018060a01b03166000526019602052602060ff604060002054166040519015158152f35b9160806107cf929493612826604060c0830197805184526001600160401b0360208201511660208501520151604083019060208091805184520151910152565b019060208091805184520151910152565b6080366003190112610561576004356001600160401b03811161056157612862903690600401610759565b604080602319360112610561576064359061287c82610713565b612884614dc1565b5061288d614cfe565b5060608301359161289e8435610ef0565b7f0000000000000000000000000000000000000000000000000000000000000000801561150557806128d49184870135046132ac565b928084106129a55750331561298d5790612918610687926128f58533615759565b6128ff8587615112565b6129088861489d565b9161291236614de9565b92614e64565b9261292161366b565b948186528160208701527f85496b760a4b7f8d66384b9df21b381f5d1b1e79f229a47aaf4c232edc2fe59a61298061295a87519361489d565b9385519181839233978460409194939263ffffffff606083019616825260208201520152565b0390a351928392836127e6565b8151634b637e8f60e11b815260006004820152602490fd5b82516371c4efed60e01b8152600481018590526024810191909152604490fd5b34610561576000366003190112610561576020601654604051908152f35b34610561576000602036600319011261071057600435612a0281610713565b612a0a615598565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000811691839190833b15612a785760249083604051958694859363ca5eb5e160e01b85521660048401525af18015610b1b57612a6c575080f35b612a7590611bde565b80f35b8280fd5b3461056157600036600319011261056157606060105460ff6040519181811615158352818160081c161515602084015260101c1615156040820152f35b612ac23661091d565b5050509290303303612c0357612adb6109f48583615459565b93612afc612aec610a118385615465565b612af58561489d565b5086615252565b9160288211612b4c575b5050612b20600080516020615afd8339815191529261489d565b6040805163ffffffff909216825260208201929092526001600160a01b03909416939081908101610a72565b9082612b6b92610a9c612b616040880161521d565b93610a968861489d565b917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316803b1561056157604051633e5ac80960e11b8152936000918591829084908290612bc5908b8d60048501615227565b03925af1908115610b1b57600080516020615afd83398151915293612b2092612bf0575b5092612b06565b80610b0f612bfd92611bde565b38612be9565b60405163029a949d60e31b8152600490fd5b34610561576020366003190112610561577fd48d879cef83a1c0bdda516f27b13ddb1b3f8bbac1c9e1511bb2a659c24277606020600435612c5581610713565b612c5d615598565b600280546001600160a01b0319166001600160a01b03929092169182179055604051908152a1005b346105615760003660031901126105615760206040516109c48152f35b34610561576020612cde612cb536610bf0565b6001600160a01b0391821660009081526006855260408082209290931681526020919091522090565b54604051908152f35b3461056157600036600319011261056157600f546040805161ffff8084168252601084901c811660208084019190915284901c81169282019290925260309290921c166060820152608090f35b346105615760003660031901126105615760206040516127108152f35b3461056157600036600319011261056157600e546040805161ffff8084168252601084901c811660208084019190915284901c81169282019290925260309290921c166060820152608090f35b3461056157600036600319011261056157600c546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576015546040516001600160a01b039091168152602090f35b3461056157600036600319011261056157602060ff60175460881c16604051908152f35b3461056157602036600319011261056157600435612e3181610713565b612e39615598565b6001600160a01b039081168015612e8757600080546001600160a01b03198116831782559092167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b604051631e4fbdf760e01b815260006004820152602490fd5b3461056157608036600319011261056157600435612ebd81611061565b612ec5611633565b60643591604435612ed4615598565b6103e861ffff841611612f7a578361100c91612f127f3c5eaaf6ca1b740f7357efefb3dba70726e1efbf1d834dbcade52108a88c4e919615156147a0565b612f288460ff8019601154169115151617601155565b6011805462ffff001916600887901b62ffff0016179055612f4881601255565b612f5182601355565b604051948594859094939261ffff60609360808401971515845216602083015260408201520152565b60405162461bcd60e51b815260206004820152600f60248201526e4d617820313025206f66206665657360881b6044820152606490fd5b34610561576060366003190112610561576020612fcd366108df565b63ffffffff8135612fdd81610ef0565b166000526001825260406000205482604051920135148152f35b91906001600160a01b03808416801580156130b9575b6130a757600090808252601a60205260ff604083205416928315613093575b50821561307b575b50508015613059575b1561304b5761062b926130c3565b613054926156b4565b600190565b506001600160a01b03811660009081526019602052604090205460ff1661303d565b81526019602052604090205460ff1690503880613034565b84168252604082205460ff1692503861302c565b60405163d92e233d60e01b8152600490fd5b508183161561300d565b91906130ce83613260565b6130d782613260565b908080613258575b1561323057505090916130f460105460ff1690565b156131ca5761312861312061311a613113600e5461ffff9060301c1690565b61ffff1690565b856132ac565b612710900490565b61314761313582866132f1565b6131408330866156b4565b84846156b4565b613150816133ff565b6040805185815260208101929092526000908201526001600160a01b03928316918316907ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d18390606090a36131a2614049565b600d546001600160a01b0316166131ba575b50600190565b6131c49032613d9d565b386131b4565b9190613228816131fc847ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d18394876156b4565b60408051948552600060208601526001908501526001600160a01b039081169416929081906060820190565b0390a3600190565b159081613250575b50156132475761062b926132fe565b61062b926132fe565b905038613238565b5081156130df565b6001600160a01b03166000908152601a602052604090205460ff1680156132845790565b50601960205260ff6040600020541690565b634e487b7160e01b600052601160045260246000fd5b818102929181159184041417156132bf57565b613296565b634e487b7160e01b600052601260045260246000fd5b8015611505576000190490565b8115611505570490565b919082039182116132bf57565b91907ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d183906133356126d460105460ff9060081c1690565b80156133ee575b6133b35761335a61312061311a613113600f5461ffff9060301c1690565b9061337a61336883866132f1565b6133738430896156b4565b82876156b4565b6133838261361f565b6040805194855260208501929092526002918401919091526001600160a01b039081169316918060608101613228565b806133c28461322893876156b4565b60408051948552600060208601526003908501526001600160a01b039081169416929081906060820190565b50600f5460301c61ffff161561333c565b801561361c57600e5461ffff808260301c168015611b24576000938060115460ff81168061360e575b6135df575b50509061344761346b9261344c83613447878916846132ac565b6132e7565b9461346084613447838a60101c16856132ac565b9660201c16906132ac565b600b549092906001600160a01b03166001600160a01b03928184161515806135d6575b613584575b5050600c546001600160a01b031691821615158061357b575b613518575b5050806134cb575b50806134c25750565b6107cf9061362e565b61dead7f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed61350f836134ff600295306155c4565b6040519081529081906020820190565b0390a3386134b9565b61352581600193306156b4565b600c547f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed9061357190613560906001600160a01b03166109f4565b604051938452929081906020820190565b0390a338806134b1565b508015156134ac565b61359181600093306156b4565b600b547f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed906135cc90613560906001600160a01b03166109f4565b0390a33880613493565b5080151561348e565b61344791965061346b939250613600613120866136079360081c16896132ac565b80976132f1565b919261342d565b50848160081c161515613428565b50565b801561361c576107cf906133ff565b600d546001600160a01b031680156136675731601254111561361c576107cf9060135480821161365f575b50613710565b905038613659565b5050565b604051906107cf82611ba3565b6040519060a082018281106001600160401b03821117611bbe57604052565b60405190608082018281106001600160401b03821117611bbe57604052565b6001600160401b038111611bbe57601f01601f191660200190565b3d156136fc573d906136e2826136b6565b916136f06040519384611c0c565b82523d6000602084013e565b606090565b90816020910312610561575190565b601b546001600160a01b031680158015613aa9575b8015613a8d575b613a44578161373b9130615832565b601554604080513060208083018290526001600160a01b0390941682840152610bb86060830152608082015260a08101849052600060c0820181905260e08083019190915281529092601f199290919061379761010083611c0c565b8451916137c4836137b8848201936304e45aaf60e01b85526024830161061a565b03868101855284611c0c565b601b546001600160a01b031692600093849283809351925af16137e56136d1565b90156139fc57805182116139ac5780828061380593518301019101613701565b938415613964576015548651632e1a7d4d60e01b9381019384526024810187905260449283018152849384936001600160a01b03909316929091849161384b9082611c0c565b51925af16138576136d1565b501561391e57600d5481908190819086906001600160a01b03165af161387b6136d1565b50156138da57600d547ff3ff75e0b1c978244be90689011b17bbb5e59d063b132091240a301cf1f1f7709291906138d5906138be906001600160a01b03166109f4565b945191825260208201929092529081906040820190565b0390a2565b915191825250604060208201819052600b908201526a14d95b990819985a5b195960aa1b6060820152600080516020615b3d8339815191529080608081015b0390a1565b50915191825250604060208201819052600d908201526c155b9ddc985c0819985a5b1959609a1b6060820152600080516020615b3d833981519152908060808101613919565b5050506139199150600080516020615b3d833981519152925191829182608091815260406020820152600b60408201526a16995c9bc81bdd5d1c1d5d60aa1b60608201520190565b5050506139199150600080516020615b3d8339815191529251918291826080918152604060208201526013604082015272125b9d985b1a59081cddd85c081c995cdd5b1d606a1b60608201520190565b5050506139199150600080516020615b3d833981519152925191829182608091815260406020820152600b60408201526a14ddd85c0819985a5b195960aa1b60608201520190565b50604080519182526020820181905260119082015270436f6e66696720696e636f6d706c65746560781b6060820152600080516020615b3d833981519152908060808101613919565b50601454613aa3906001600160a01b03166109f4565b1561372c565b50601554613abf906001600160a01b03166109f4565b15613725565b15613acc57565b60405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606490fd5b15613b0f57565b60405162461bcd60e51b815260206004820152600f60248201526e131bdd1d195c9e481b9bdd081cd95d608a1b6044820152606490fd5b15613b4d57565b60405162461bcd60e51b815260206004820152600c60248201526b1c1bdbdb081b9bdd081cd95d60a21b6044820152606490fd5b6001600160401b038111611bbe5760051b60200190565b60405190613ba582611bc3565b600282526040366020840137565b634e487b7160e01b600052603260045260246000fd5b805115613bd65760200190565b613bb3565b805160011015613bd65760400190565b8051821015613bd65760209160051b010190565b81601f8201121561056157805191613c1683613b81565b92613c246040519485611c0c565b808452602092838086019260051b820101928311610561578301905b828210613c4e575050505090565b8380918351613c5c81610713565b815201910190613c40565b919091604081840312610561578051926001600160401b03938481116105615782019381601f8601121561056157845194613ca186613b81565b90613caf6040519283611c0c565b868252602096878084019160051b83010191858311610561578801905b828210613ceb57505050948301519081116105615761062b9201613bff565b81518060060b8103610561578152908801908801613ccc565b6020908160408183019282815285518094520193019160005b828110613d2b575050505090565b835163ffffffff1685529381019392810192600101613d1d565b6040513d6000823e3d90fd5b600691820b910b0390667fffffffffffff198212667fffffffffffff8313176132bf57565b60060b9060060b90811561150557667fffffffffffff1981146000198314166132bf570590565b90613daf91613daa615983565b613db6565b6001600a55565b600d546001600160a01b0390811692918315613f0157803b613ed557604051635be4331d60e11b81526001600160a01b03821660048201523060248201526044810184905293602090859060649082906000905af160009481613ea5575b50613e4557604080519384526003602085015291169250600080516020615b5d8339815191529190819081016138d5565b8315613e805760405192835216907f451067e4777bd02c1f731ed3c067654bab9c423835639447bd13b158729334bd9080602081015b0390a3565b604080519384526002602085015291169250600080516020615b5d83398151915291a2565b613ec791955060203d8111613ece575b613ebf8183611c0c565b810190613701565b9338613e14565b503d613eb5565b604080519384526001602085015291169250600080516020615b5d8339815191529190819081016138d5565b604080519384526000602085015291169250600080516020615b5d8339815191529190819081016138d5565b91909161ffff808094169116019182116132bf57565b15613f4a57565b60405162461bcd60e51b815260206004820152600c60248201526b5a65726f206164647265737360a01b6044820152606490fd5b90816020910312610561575161062b81610713565b15613f9a57565b60405162461bcd60e51b815260206004820152600c60248201526b125b9d985b1a59081c1bdbdb60a21b6044820152606490fd5b90816020910312610561575160ff811681036105615790565b15613fee57565b60405162461bcd60e51b815260206004820152601760248201527f496e76616c6964207374616c65207468726573686f6c640000000000000000006044820152606490fd5b9190826040910312610561576020825192015190565b6018546001600160a01b0316808015613667576040908151637aa3994960e01b81528281600481855afa908160009182936141af575b5061417b575b505061408f614236565b908115611b245782600491815192838092630ba1864f60e11b82525afa8015610b1b57600091829161414c575b5060008213801590614144575b61413d576140d790426132f1565b60165410611b24576140e8916159a6565b916000831315614138576000928380935161412b8161411d60208201956308085ad960e41b8752602483019190602083019252565b03601f198101835282611c0c565b51925af15061361c6136d1565b505050565b5050505050565b5080156140c9565b905061416e9150833d8511614174575b6141668183611c0c565b810190614033565b386140bc565b503d61415c565b600012806141a6575b61418f575b80614085565b61419b607891426132f1565b106141385738614189565b50801515614184565b9092506141c99150843d8611614174576141668183611c0c565b913861407f565b90816020910312610561575161062b81610efe565b9081602091031261056157518060020b81036105615790565b90816012019182126001166132bf57565b818103929160001380158285131691841216176132bf57565b604d81116132bf57600a0a90565b6017546001600160801b0380821690816143ab575b505060405163b3fac98d60e01b815260209060008282600481305afa90918161437c575b5061427c57505050600090565b61428590614436565b90811561433a5760006004826142a86109f46109f460145460018060a01b031690565b604051630dfe168160e01b815292839182905afa91928261435d575b50506142d257505050600090565b9160ff808260801c169160881c169080158015614355575b61434c576142fa6142ff926141fe565b61420f565b600081128015614342575b61433a5761431790614228565b916001600160a01b03163003614331579061062b91615ab6565b61062b91615a2d565b505050600090565b506024811361430a565b50505050600090565b5081156142ea565b614374929350803d10610ea357610e938183611c0c565b9038806142c4565b61439d919250833d85116143a4575b6143958183611c0c565b8101906141e5565b903861426f565b503d61438b565b6014546004906020906143c8906109f4906001600160a01b031681565b604051630d34328160e11b815292839182905afa60009181614406575b506143f35750505050600090565b161061440057388061424b565b50600090565b61442891925060203d811161442f575b6144208183611c0c565b8101906141d0565b90386143e5565b503d614416565b61062b9060020b600081121561479a5780600003905b61445b620d89e883111561486d565b6001821615614788576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b16916002811661476c575b60048116614750575b60088116614734575b60108116614718575b602081166146fc575b604081166146e0575b6080908181166146c5575b61010081166146aa575b610200811661468f575b6104008116614674575b6108008116614659575b611000811661463e575b6120008116614623575b6140008116614608575b61800081166145ed575b6201000081166145d2575b6202000081166145b8575b62040000811661459e575b6208000016614583575b50600012614575575b63ffffffff811661456d576000905b60201c60ff91909116016001600160a01b031680615ab6565b600190614554565b61457e906132da565b614545565b6b048a170391f7dc42444e8fa26000929302901c919061453c565b6d2216e584f5fa1ea926041bedfe98909302811c92614532565b926e5d6af8dedb81196699c329225ee60402811c92614527565b926f09aa508b5b7a84e1c677de54f3e99bc902811c9261451c565b926f31be135f97d08fd981231505542fcfa602811c92614511565b926f70d869a156d2a1b890bb3df62baf32f702811c92614507565b926fa9f746462d870fdf8a65dc1f90e061e502811c926144fd565b926fd097f3bdfd2022b8845ad8f792aa582502811c926144f3565b926fe7159475a2c29b7443b29c7fa6e889d902811c926144e9565b926ff3392b0822b70005940c7a398e4b70f302811c926144df565b926ff987a7253ac413176f2b074cf7815e5402811c926144d5565b926ffcbe86c7900a88aedcffc83b479aa3a402811c926144cb565b926ffe5dee046a99a2a811c461f1969c305302811c926144c1565b916fff2ea16466c96a3843ec78b326b528610260801c916144b6565b916fff973b41fa98c081472e6896dfb254c00260801c916144ad565b916fffcb9843d60f6159c9db58835c9266440260801c916144a4565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c9161449b565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91614492565b916ffff97272373d413259a46990580e213a0260801c91614489565b6001600160881b03600160801b61447e565b8061444c565b156147a757565b60405162461bcd60e51b815260206004820152601460248201527304d61782073776170206d757374206265203e20360641b6044820152606490fd5b604051906147f082611bc3565b60248252636c61677360e01b6040837f4d697373696e6720636f6d706f6e656e7473202d20636865636b20626974206660208201520152565b6040519061483682611bc3565b6022825261195960f21b6040837f416c6c20637269746963616c20636f6d706f6e656e747320636f6e666967757260208201520152565b1561487457565b60405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606490fd5b3561062b81610ef0565b63ffffffff168060005260016020526040600020549081156148c7575090565b6024906040519063f6ff4fb760e01b82526004820152fd5b9291926148eb826136b6565b916148f96040519384611c0c565b829481845281830111610561578281602093846000960137010152565b60001981146132bf5760010190565b90601f811161493357505050565b600091825260208220906020601f850160051c8301941061496f575b601f0160051c01915b82811061496457505050565b818155600101614958565b909250829061494f565b91909182516001600160401b038111611bbe576149a08161499a8454611abd565b84614925565b602080601f83116001146149dc5750819293946000926149d1575b50508160011b916000199060031b1c1916179055565b0151905038806149bb565b90601f198316956149f285600052602060002090565b926000905b888210614a2f57505083600195969710614a16575b505050811b019055565b015160001960f88460031b161c19169055388080614a0c565b806001859682949686015181550195019301906149f7565b602080820190808352835180925260409283810182858560051b8401019601946000925b858410614a7c575050505050505090565b909192939495968580614abf600193603f19868203018852868c5163ffffffff815116835261ffff858201511685840152015190606090818982015201906105f5565b990194019401929594939190614a6b565b90600091825b8151811015614b6057614b5b90614b566040614afe81614af68588613beb565b510151614cc6565b614b5181614b0c8588613beb565b5101519163ffffffff614b1f8689613beb565b515116895261ffff602091600383528a2091614b3b878a613beb565b5101511661ffff16600052602052604060002090565b614979565b614916565b614ad6565b507fbe4864a8e820971c0247f5992e2da559595f7bf076a21cb5928d443d2a13b6749192506139199060405191829182614a47565b909291928360021161056157831161056157600201916001190190565b602090836107cf939594956040519683614bd589955180928880890191016105d2565b8401918583013701600083820152038085520183611c0c565b908060209392818452848401376000828201840152601f01601f1916010190565b91602061062b938181520191614bee565b611c85611c919263ffffffff614c55939795969716600052600360205260406000209061ffff16600052602052604060002090565b805115614cb8578315614cb2576002841015614c89575050610b51604051928392639a6d49cd60e01b845260048401614c0f565b909280614cac9161062b94614ca7614ca23684846148df565b614cc6565b614b95565b91614bb2565b92509050565b50919061062b9136916148df565b600361ffff60028301511603614cd95750565b604051639a6d49cd60e01b815260206004820152908190610b519060248301906105f5565b60405190614d0b82611ba3565b60006020838281520152565b919082604091031261056157604051614d2f81611ba3565b6020808294805184520151910152565b906040828203126105615761062b91614d17565b906020909392936040835263ffffffff81511660408401528181015160608401526080614da7614d91604084015160a08488015260e08701906105f5565b6060840151868203603f190160a08801526105f5565b910151151560c08401526001600160a01b03909416910152565b60405190614dce82611bc3565b8160008152600060208201526040614de4614cfe565b910152565b60409060231901126105615760405190614e0282611ba3565b60243582526044356020830152565b6001600160401b0381160361056157565b9060808282031261056157614e5c906040805193614e3f85611bc3565b805185526020810151614e5181614e11565b602086015201614d17565b604082015290565b614ec160809492614edd9694614e78614dc1565b506020614e858651614f54565b950191825180614f45575b50614e9a856148a7565b9251151592614eaa61141a613678565b602086015260408501526060840152151585830152565b6040518095819482936302637a4560e41b845260048401614d53565b03917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165af1908115610b1b57600091614f1d575090565b61062b915060803d8111614f3e575b614f368183611c0c565b810190614e22565b503d614f2c565b614f4e90614f76565b38614e90565b803403614f5e5790565b6040516304fb820960e51b8152346004820152602490fd5b60405163393f876560e21b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000008116926020929091908381600481885afa908115610b1b57600091615089575b5016928315615077576040516323b872dd60e01b8482019081523360248301526001600160a01b039092166044820152606481019290925261502f91600091829161501a816084810161411d565b519082875af16150286136d1565b9084615920565b805191821515928361505e575b5050506150465750565b60249060405190635274afe760e01b82526004820152fd5b61506e93508201810191016150d8565b1538808061503c565b6040516329b99a9560e11b8152600490fd5b6150a09150843d8611610ea357610e938183611c0c565b38614fcc565b903590601e198136030182121561056157018035906001600160401b0382116105615760200191813603831361056157565b90816020910312610561575161062b81611061565b909161510461062b936040845260408401906105f5565b9160208184039101526105f5565b909161517661515461514861519d957f0000000000000000000000000000000000000000000000000000000000000000906132e7565b6001600160401b031690565b61516b61516460a08601866150a6565b36916148df565b9060208501356153ce565b9390928394600014615215576002905b61261d6151928261489d565b9160808101906150a6565b60045490926001600160a01b039091169083826151b957505050565b60405163043a78eb60e01b8152926020928492839182916151dd91600484016150ed565b03915afa8015610b1b576151ee5750565b61361c9060203d811161520e575b6152068183611c0c565b8101906150d8565b503d6151fc565b600190615186565b3561062b81614e11565b61062b939260809260018060a01b0316825260208201526000604082015281606082015201906105f5565b6001600160a01b03818116156152d3575b81169081156152ba57600754908382018092116132bf576007919091556001600160a01b031660009081526005602052604090208281540190556000600080516020615b1d8339815191526020604051858152a390565b60405163ec442f0560e01b815260006004820152602490fd5b61dead9150615263565b61062b906001600160401b037f000000000000000000000000000000000000000000000000000000000000000091166132ac565b7f00000000000000000000000000000000000000000000000000000000000000008015611505578061534392046132ac565b9182918084106153505750565b6040516371c4efed60e01b8152600481018590526024810191909152604490fd5b604c919361062b936040519586936001600160401b0360c01b9060c01b16602085015263ffffffff60e01b9060e01b166028840152602c8301526153be81518092602086860191016105d2565b810103602c810184520182611c0c565b8251158015939061542c576154299160689160405194859260208401526001600160401b0360c01b9060c01b16604083015233604883015261541981518092602086860191016105d2565b8101036048810184520182611c0c565b91565b50906040519160208301526001600160401b0360c01b9060c01b1660408201526028815261542981611bc3565b90602011610561573590565b90602811610561576020013560c01c90565b90806028116105615761062b91369160271901906028016148df565b9190811015613bd65760051b8101359061013e1981360301821215610561570190565b3561062b81610713565b92909361551c926001600160401b03604061062b9a98999763ffffffff81356154e881610ef0565b16885260208101356020890152013561550081614e11565b166040860152606085015260e0608085015260e0840191614bee565b6001600160a01b0390941660a082015280840360c090910152614bee565b602081830312610561578051906001600160401b038211610561570181601f8201121561056157805161556c816136b6565b9261557a6040519485611c0c565b818452602082840101116105615761062b91602080850191016105d2565b6000546001600160a01b031633036155ac57565b60405163118cdaa760e01b8152336004820152602490fd5b6001600160a01b03811690811561569b576001600160a01b03811660009081526005602052604090205483811061566c578361561491039160018060a01b03166000526005602052604060002090565b5561dead6000819052600560209081527f7d509c07f0d4edcc2dd1b53aae68677132eb562dcba78e36381b63ccaf66e6ba8054850190556040519384529092600080516020615b1d8339815191529181908101613e7b565b60405163391434e360e21b81526001600160a01b03929092166004830152602482015260448101839052606490fd5b604051634b637e8f60e11b815260006004820152602490fd5b916001600160a01b038084169290831561569b5781169384156152ba576001600160a01b03811660009081526005602052604090205483811061566c57613e7b928492615728600080516020615b1d8339815191529661574394039160018060a01b03166000526005602052604060002090565b556001600160a01b0316600090815260056020526040902090565b8054820190556040519081529081906020820190565b6001600160a01b03811690816157a25750600754918083018093116132bf576020600080516020615b1d833981519152916000946007555b8060075403600755604051908152a3565b6001600160a01b03811660009081526005602052604090205493929081851061580057816020916157fa600080516020615b1d8339815191529460009798039160018060a01b03166000526005602052604060002090565b55615791565b60405163391434e360e21b81526001600160a01b03919091166004820152602481018590526044810191909152606490fd5b6001600160a01b0380821692919083156158cd5782169384156158b457806158aa7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259461589360209560018060a01b03166000526006602052604060002090565b9060018060a01b0316600052602052604060002090565b55604051908152a3565b604051634a1406b160e11b815260006004820152602490fd5b60405163e602df0560e01b815260006004820152602490fd5b906001600160a01b03808316156158cd578116156158b45761589361591d9260018060a01b03166000526006602052604060002090565b55565b90615947575080511561593557805190602001fd5b604051630a12f52160e11b8152600490fd5b8151158061597a575b615958575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15615950565b6002600a5414615994576002600a55565b604051633ee5aeb560e01b8152600490fd5b908082029060001981840990828083109203918083039214615a1c57670de0b6b3a76400009082821115615a0a577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60405163227bc15360e01b8152600490fd5b5050670de0b6b3a764000091500490565b600160601b91606082901b9160001984820993838086109503948086039514615aa95784831115615a0a5782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b50509061062b92506132e7565b818102919060001982820991838084109303928084039314615af357600160601b9183831115615a0a570990828211900360a01b910360601c1790565b50505060601c9056feefed6d3500546b29533b128a29e3a94d70788727f0507505ac12eaf2e578fd9cddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef780f4e88314062bd6e7b2daeb47a4dc34d23b318c7311ca6c0f02ace99271cfd22f6f9edacc2bcfc7e3749caab22297d7f3e7a44706adc0cd94e17fb7ecd5798a2646970667358221220ff25e1029f3ebaddecc767c64c8e8206ac10cfdacc93d2b0f2af3af7eeaee6aa64736f6c6343000814003300000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f0000000000000000000000006940adc0a505108bc11ca28eefb7e3bac7af0777000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f0000000000000000000000000000000000000000000000000000000000000006447261676f6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006445241474f4e0000000000000000000000000000000000000000000000000000

Deployed Bytecode

0x6080604052600436101561001b575b361561001957600080fd5b005b60003560e01c806306244f581461055157806306433b1b1461054c57806306fdde0314610547578063095ea7b3146105425780630d35b4151461053d578063111ecdad1461053857806313137d6514610533578063134d4f251461052e578063156a0d0f1461052957806317442b701461052457806318160ddd1461051f5780631936b2781461051a5780631f5e1334146105155780632048db44146105105780632171dcc91461050b57806323b872dd146105065780632630c12f146105015780632a4f12ca146104fc5780632ede5651146104f75780632ff2e9dc146104e8578063302a20d6146104f2578063313ce567146104ed57806332cb6b0c146104e85780633400288b146104e35780633b6f743b146104de5780633be701f1146104d95780633d6add81146104d45780634404c3d6146104cf5780634454a9b1146104ca5780634a2d5c9d146104c55780634d48a48c146104c05780634d536549146104bb5780634e6fd6c4146104b65780634f989520146104b157806352ae2879146103c6578063530e784f146104ac5780635535d461146104a75780635976e045146104a25780635a0dfe4d1461049d5780635e280f11146104985780636fc1b31e146104935780637033568f1461048e57806370a0823114610489578063715018a614610484578063740e0d221461047f5780637d25a05e1461047a57806382413eac14610475578063857749b0146104705780638a59b9a21461046b5780638da5cb5b1461046657806393f234b11461046157806395d89b411461045c578063963efcaa146104575780639a198d61146104525780639f68b9641461044d578063a1bc910f14610448578063a9059cbb14610443578063b3fac98d1461043e578063b731ea0a14610439578063b98bd07014610434578063b9c89a641461042f578063bb0b6a531461042a578063bc70b35414610425578063bd815db014610420578063c31c9c071461041b578063c5c80bf414610416578063c7c7f5b314610411578063c8312ce51461040c578063ca5eb5e114610407578063cf2f568f14610402578063d045a0dc146103fd578063d4243885146103f8578063d55be8c6146103f3578063dd62ed3e146103ee578063e0f3ccf5146103e9578063e1f1c4a7146103e4578063e4748b9e146103df578063eae0a488146103da578063eb6d3a11146103d5578063ee509ff9146103d0578063f2fde38b146103cb578063fc0c546a146103c6578063fdf2b32b146103c15763ff7bd03d0361000e57612fb1565b612ea0565b611a37565b612e14565b612df0565b612dc7565b612d9e565b612d51565b612d34565b612ce7565b612ca2565b612c85565b612c15565b612ab9565b612a7c565b6129e3565b6129c5565b612837565b6127a4565b61277b565b612625565b6125d1565b612596565b612551565b612477565b612402565b6122e9565b6122bd565b61227b565b61225f565b6121ad565b612172565b6120cb565b6120a7565b61207e565b612021565b612005565b611fa7565b611f80565b611edc565b611e81565b611e44565b611e1b565b611dab565b611d66565b611d1e565b611cac565b611c2d565b611a52565b611a0e565b6119f1565b6118e4565b6118a7565b611862565b611839565b611664565b61154a565b61150a565b611349565b6112c7565b61126c565b6112ab565b611292565b611245565b6111c1565b611198565b6110d0565b611090565b610f0f565b610ed4565b610c15565b610bd2565b610bb0565b610b89565b610b6d565b610981565b6108b6565b610810565b610724565b61062e565b61058d565b610566565b600091031261056157565b600080fd5b346105615760003660031901126105615760206001600160801b0360175416604051908152f35b34610561576000366003190112610561576040517f0000000000000000000000006940adc0a505108bc11ca28eefb7e3bac7af07776001600160a01b03168152602090f35b60005b8381106105e55750506000910152565b81810151838201526020016105d5565b9060209161060e815180928185528580860191016105d2565b601f01601f1916010190565b90602061062b9281815201906105f5565b90565b346105615760008060031936011261071057604051908060085461065181611abd565b808552916001918083169081156106e6575060011461068b575b6106878561067b81870382611c0c565b6040519182918261061a565b0390f35b9250600883527ff3f7a9fe364faab93b216da50a3214154f22a0a2b415b23a84c8169e8b636ee35b8284106106ce57505050810160200161067b8261068761066b565b805460208587018101919091529093019281016106b3565b8695506106879693506020925061067b94915060ff191682840152151560051b820101929361066b565b80fd5b6001600160a01b0381160361056157565b346105615760403660031901126105615761074e60043561074481610713565b6024359033615832565b602060405160018152f35b908160e09103126105615790565b9392916107828560a081019360208091805184520151910152565b60409160a083870152815180915260c086019160c08260051b880101936020809201936000915b8483106107d1575050505050509060606107cf9294019060208091805184520151910152565b565b90919293949584806108006001938d60bf1990820301875285838c5180518452015191818582015201906105f5565b98019301930191949392906107a9565b34610561576020366003190112610561576001600160401b0360043581811161056157610841903690600401610759565b9061084a614cfe565b50610853614cfe565b506040519061086182611ba3565b60008252602082015261068761089a6040519361087d85611bf1565b6000855261088a8161489d565b5060406060820135910135615311565b6108a261366b565b918252602082015260405193849384610767565b34610561576000366003190112610561576004546040516001600160a01b039091168152602090f35b606090600319011261056157600490565b9181601f84011215610561578235916001600160401b038311610561576020838186019501011161056157565b600319810160e081126105615760601361056157600491606435916001600160401b039060843582811161056157816109579187016108f0565b9390939260a43561096781610713565b9260c4359182116105615761097d9188016108f0565b9091565b61098a3661091d565b50929492506001600160a01b039190507f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b8216338103610b555783356109cf81610ef0565b6109d8816148a7565b906020860135809203610b20575050610a006109f48388615459565b6001600160a01b031690565b91610a26610a16610a11838a615465565b6152dd565b610a1f8761489d565b5084615252565b809760288311610a77575b50505050610a72610a50600080516020615afd8339815191529461489d565b956040519384931696836020909392919363ffffffff60408201951681520152565b0390a3005b90610aa29291610a9c610a8c60408a0161521d565b93610a968a61489d565b92615477565b92615371565b90803b1561056157604051633e5ac80960e11b8152916000918391829084908290610ad2908c8a60048501615227565b03925af18015610b1b57600080516020615afd83398151915294610a7292610a5092610b02575b88919650610a31565b80610b0f610b1592611bde565b80610556565b38610af9565b613d45565b610b2981610ef0565b60405163309afaf360e21b815263ffffffff9190911660048201526024810191909152604490fd5b0390fd5b6040516391ac5e4f60e01b8152336004820152602490fd5b3461056157600036600319011261056157602060405160028152f35b34610561576000366003190112610561576040805162b9270b60e21b815260016020820152f35b3461056157600036600319011261056157604080516001815260026020820152f35b34610561576000366003190112610561576020600754604051908152f35b604090600319011261056157600435610c0881610713565b9060243561062b81610713565b3461056157610c2336610bf0565b90610c2c615598565b6001600160a01b03918183169182151580610ec9575b610c4b90613f43565b601454610c60906001600160a01b03166109f4565b8303610dac575b50601554610c7d906001600160a01b03166109f4565b928116928303610cb0575b507fed7692d7eac8e25ca74b0bcb7b52fe51d01a8910e8e320c6f3223365708d76de600080a3005b601580546001600160a01b0319166001600160a01b0390921691909117905560405163313ce56760e01b8082526020918281600481885afa8015610b1b57610d1a91600091610d8f575b506017805460ff60881b191660889290921b60ff60881b16919091179055565b6040519081528181600481305afa908115610b1b57610d5c92600092610d62575b50506017805460ff60801b191660809290921b60ff60801b16919091179055565b38610c88565b610d819250803d10610d88575b610d798183611c0c565b810190613fce565b3880610d3b565b503d610d6f565b610da69150843d8611610d8857610d798183611c0c565b38610cfa565b604051630dfe168160e01b81529060208083600481885afa928315610b1b57600093610eaa575b5060405163d21220a760e01b8152908082600481895afa908115610b1b57610e4194610e1f938992600094610e7b575b50501690308214918215610e6f575b82610e47575b5050613f93565b60018060a01b03166bffffffffffffffffffffffff60a01b6014541617601455565b38610c67565b90915087808716809214928315610e63575b5050503880610e18565b16149050388781610e59565b81891630149250610e12565b610e9b929450803d10610ea3575b610e938183611c0c565b810190613f7e565b913880610e03565b503d610e89565b81610ec29294503d8511610ea357610e938183611c0c565b9138610dd3565b508184161515610c42565b3461056157600036600319011261056157602060405160018152f35b63ffffffff81160361056157565b6001600160801b0381160361056157565b3461056157606036600319011261056157600435610f2c81610ef0565b60243560443591610f3c83610efe565b610f44615598565b63ffffffff8116600a8110159081611054575b501561101e5761100c7f5ed39a8177ebe03619cb94f5c49cedbee5a9ea0c55ddc44f0aeaff8948924eae93603c84101580611011575b610f9690613fe7565b6015805463ffffffff60a01b191660a085901b63ffffffff60a01b16179055610fbe84601655565b610fde816001600160801b03166001600160801b03196017541617601755565b604051938493849160409194936001600160801b039163ffffffff6060860197168552602085015216910152565b0390a1005b5062015180841115610f8d565b60405162461bcd60e51b815260206004820152600e60248201526d496e76616c69642077696e646f7760901b6044820152606490fd5b610e109150111538610f57565b8015150361056157565b60409060031901126105615760043561108381610713565b9060243561062b81611061565b34610561576100196110a13661106b565b906110aa615598565b60018060a01b0316600052601a60205260406000209060ff801983541691151516179055565b34610561576060366003190112610561576004356110ed81610713565b6024356110f981610713565b6001600160a01b038216600090815260066020908152604080832033845290915290206044359290546001810161114b575b610687611139858585612ff7565b60405190151581529081906020820190565b8381106111715791839161116861068795611139950333836158e6565b9193509161112b565b604051637dc7a0d960e11b8152336004820152602481019190915260448101849052606490fd5b34610561576000366003190112610561576018546040516001600160a01b039091168152602090f35b34610561576040366003190112610561577f81b107915bdf0513375bf3f4b55e32203154ec9b68049c9522e9d3b666c991a2604060043561120181611061565b6024359061120e82611061565b611216615598565b1515906010549015159061ff008260081b169060ff84169061ffff1916171760105582519182526020820152a1005b3461056157600036600319011261056157602063ffffffff60155460a01c16604051908152f35b346105615760003660031901126105615760206040516a396c41bd9e54ada38000008152f35b3461056157600036600319011261056157610019614049565b3461056157600036600319011261056157602060405160128152f35b34610561576040366003190112610561577f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b60043561130581610ef0565b60243590611311615598565b63ffffffff811660005260016020528160406000205561100c604051928392836020909392919363ffffffff60408201951681520152565b3461056157604080600319360112610561576004356001600160401b0381116105615761137a903690600401610759565b9060243561138781611061565b61138f614cfe565b5060608301358335936113a185610ef0565b7f000000000000000000000000000000000000000000000000000000e8d4a51000801561150557806113d79186840135046132ac565b918083106114e5575083926113f3611458969361143d93615112565b906113fd85610ef0565b611405614cfe565b5061140f856148a7565b61142661141a613678565b63ffffffff9097168752565b602086015285850152606084015215156080830152565b815180948192631bb8518b60e31b8352309060048401614d53565b03817f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b6001600160a01b03165afa908115610b1b57610687926000926114b6575b505191829182815181526020918201519181019190915260400190565b816114d79293503d84116114de575b6114cf8183611c0c565b810190614d3f565b9038611499565b503d6114c5565b84516371c4efed60e01b8152600481018490526024810191909152604490fd5b6132c4565b346105615761001961151b3661106b565b90611524615598565b60018060a01b0316600052601960205260406000209060ff801983541691151516179055565b346105615760603660031901126105615760043561156781610713565b60243561157381610713565b6044359161158083610713565b611588615598565b6001600160a01b039081169283151580611617575b8061160c575b6115ac90613f43565b600d80546001600160a01b03199081168617909155600b805482169484169485179055600c80549091166001600160a01b03831617905516917ff5bf353491658caa63438c79ce5f38eff2976c2c075d83bbba7e8b2a2a4bf418600080a4005b5080821615156115a3565b50818316151561159d565b6004359061ffff8216820361056157565b6024359061ffff8216820361056157565b6044359061ffff8216820361056157565b359061ffff8216820361056157565b346105615760803660031901126105615761167d611622565b611685611633565b61168d611644565b916064359261169b84611061565b6116a3615598565b6116b6816116b18585613f2d565b613f2d565b936109c461ffff8616116117fe577f99eecaee2197aae33e41a7fab052496c51b61e908fcdeb223fc543aec60fd4fb9461100c926116f2613697565b61ffff8616815261ffff8716602082015261ffff8216604082015261ffff8316606082015283156117a5576117719061ffff81511690600e549163ffff0000602083015160101b169067ffff000000000000606065ffff00000000604086015160201b1694015160301b16936001600160401b03191617171717600e55565b6040805161ffff968716815296861660208801529085169086015290921660608401529015156080830152819060a0820190565b6117f99061ffff81511690600f549163ffff0000602083015160101b169067ffff000000000000606065ffff00000000604086015160201b1694015160301b16936001600160401b03191617171717600f55565b611771565b60405162461bcd60e51b81526020600482015260136024820152724665652065786365656473206d6178696d756d60681b6044820152606490fd5b3461056157600036600319011261056157600b546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576040517f000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f6001600160a01b03168152602090f35b3461056157600036600319011261056157602060405160928152f35b60ff61062b94936060931515835216602082015281604082015201906105f5565b3461056157600080600319360112610710576018546001600160a01b0316156119e9575b600d5461191d906001600160a01b03166109f4565b156119e1575b600b54611938906001600160a01b03166109f4565b156119d9575b600c54611953906001600160a01b03166109f4565b156119d1575b60145461196e906001600160a01b03166109f4565b156119c9575b601554611989906001600160a01b03166109f4565b156119c1575b60ff81161580156119b1576106876119a5614829565b604051938493846118c3565b6106876119bc6147e3565b6119a5565b60101761198f565b601017611974565b600817611959565b60041761193e565b600217611923565b506001611908565b3461056157600036600319011261056157602060405161dead8152f35b3461056157600036600319011261056157600d546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576020604051308152f35b3461056157602036600319011261056157600435611a6f81610713565b611a77615598565b601880546001600160a01b0319166001600160a01b039290921691821790557f3df77beb5db05fcdd70a30fc8adf3f83f9501b68579455adbd100b8180940394600080a2005b90600182811c92168015611aed575b6020831014611ad757565b634e487b7160e01b600052602260045260246000fd5b91607f1691611acc565b9060009291805491611b0883611abd565b918282526001938481169081600014611b6a5750600114611b2a575b50505050565b90919394506000526020928360002092846000945b838610611b56575050505001019038808080611b24565b805485870183015294019385908201611b3f565b9294505050602093945060ff191683830152151560051b01019038808080611b24565b634e487b7160e01b600052604160045260246000fd5b604081019081106001600160401b03821117611bbe57604052565b611b8d565b606081019081106001600160401b03821117611bbe57604052565b6001600160401b038111611bbe57604052565b602081019081106001600160401b03821117611bbe57604052565b90601f801991011681019081106001600160401b03821117611bbe57604052565b3461056157604036600319011261056157610687611c91611c98611c85600435611c5681610ef0565b63ffffffff611c63611633565b9116600052600360205260406000209061ffff16600052602052604060002090565b60405192838092611af7565b0382611c0c565b6040519182916020835260208301906105f5565b3461056157602036600319011261056157600435611cc981610713565b611cd1615598565b6001600160a01b0316611ce5811515613f43565b601b80546001600160a01b031916821790557f36db479a3b4d3672bd6f5fca4484283f60b5ac70647b1ceec13ecbb1d030a2df600080a2005b34610561576040366003190112610561576020611d5c600435611d4081610ef0565b6024359063ffffffff1660005260016020526040600020541490565b6040519015158152f35b34610561576000366003190112610561576040517f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b6001600160a01b03168152602090f35b34610561576020366003190112610561577ff0be4f1e87349231d80c36b33f9e8639658eeaf474014dee15a3e6a4d44141976020600435611deb81610713565b611df3615598565b600480546001600160a01b0319166001600160a01b03929092169182179055604051908152a1005b34610561576000366003190112610561576014546040516001600160a01b039091168152602090f35b3461056157602036600319011261056157600435611e6181610713565b60018060a01b031660005260056020526020604060002054604051908152f35b346105615760008060031936011261071057611e9b615598565b80546001600160a01b03198116825581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461056157602036600319011261056157600435611ef8615598565b611f00615983565b8015611f4d57306000908152600560205260409020611f439190611f279054821115613ac5565b600d54611f3e906001600160a01b03161515613b08565b613710565b6100196001600a55565b60405162461bcd60e51b815260206004820152600b60248201526a16995c9bc8185b5bdd5b9d60aa1b6044820152606490fd5b3461056157604036600319011261056157611f9c600435610ef0565b602060405160008152f35b346105615760a036600319011261056157611fc1366108df565b506064356001600160401b03811161056157611fe19036906004016108f0565b50506020608435611ff181610713565b6040516001600160a01b0390911630148152f35b3461056157600036600319011261056157602060405160068152f35b346105615760003660031901126105615760c060018060a01b0380601854169080600d54169080600b541681600c5416908260145416926015541693604051958652602086015260408501526060840152608083015260a0820152f35b34610561576000366003190112610561576000546040516001600160a01b039091168152602090f35b3461056157600036600319011261056157602060ff60175460801c16604051908152f35b34610561576000806003193601126107105760405190806009546120ee81611abd565b808552916001918083169081156106e65750600114612117576106878561067b81870382611c0c565b9250600983527f6e1540171b6c0c960b71a7020d9f60077f6af931a8bbf590da0223dacf75c7af5b82841061215a57505050810160200161067b8261068761066b565b8054602085870181019190915290930192810161213f565b346105615760003660031901126105615760206040517f000000000000000000000000000000000000000000000000000000e8d4a510008152f35b3461056157600080600319360112610710576121c7615598565b808060405160208101906307983f4560e21b8252608f6024820152602481526121ef81611bc3565b51908273dc2b0d2dd2b7759d97d50db4eabdc369731108305af16122116136d1565b501561221a5780f35b60405162461bcd60e51b815260206004820152601860248201527f4665654d20726567697374726174696f6e206661696c656400000000000000006044820152606490fd5b3461056157600036600319011261056157602060405160008152f35b346105615760203660031901126105615760043561229881610713565b60018060a01b0316600052601a602052602060ff604060002054166040519015158152f35b34610561576040366003190112610561576020611d5c6004356122df81610713565b6024359033612ff7565b34610561576000806003193601126107105760145461236b91906001600160a01b0316612317811515613b46565b81612320613b98565b60155460a01c63ffffffff16926123458461233a84613bc9565b9063ffffffff169052565b8261234f83613bdb565b52604051808097819463883bdbfd60e01b835260048301613d04565b03915afa908115610b1b5763ffffffff6123b86123c39361068796866123c997926123de575b50506123b26123a56123ac6123a584613bdb565b5160060b90565b92613bc9565b90613d51565b911660060b90613d76565b60020b90565b60405160029190910b81529081906020820190565b6123fa92503d8091833e6123f28183611c0c565b810190613c67565b503880612391565b34610561576000366003190112610561576002546040516001600160a01b039091168152602090f35b906020600319830112610561576004356001600160401b039283821161056157806023830112156105615781600401359384116105615760248460051b83010111610561576024019190565b34610561576124853661242b565b9061248e615598565b61249782613b81565b9060406124a681519384611c0c565b8383526020938484019060051b8301923684116105615780915b8483106124d05761001986614ad0565b6001600160401b0390833582811161056157830191606083360312610561578551926124fb84611bc3565b803561250681610ef0565b84526125138a8201611655565b8a8501528681013591821161056157019036601f830112156105615788926125428493369085813591016148df565b878201528152019201916124c0565b34610561576000366003190112610561576011546012546013546040805160ff85161515815260089490941c61ffff1660208501528301919091526060820152608090f35b346105615760203660031901126105615763ffffffff6004356125b881610ef0565b1660005260016020526020604060002054604051908152f35b34610561576060366003190112610561576004356125ee81610ef0565b6125f6611633565b604435906001600160401b038211610561576106879261261d611c989336906004016108f0565b929091614c20565b61262e3661242b565b60005b81811061269b57604051638e9e709960e01b8152600081600481335afa8015610b1b57610b519160009161267a575b50604051638351eea760e01b81529182916004830161061a565b612695913d8091833e61268d8183611c0c565b81019061553a565b82612660565b6126a6818385615493565b906126d86126d46126b68461489d565b60208501359063ffffffff1660005260016020526040600020541490565b1590565b612771576126ea6101008301836150a6565b926126f760e082016154b6565b906127066101208201826150a6565b959095303b156105615760009461273c60c092604051998a9788968795633411683760e21b875260a08a01358a600489016154c0565b03920135305af1918215610b1b576127599261275e575b50614916565b612631565b80610b0f61276b92611bde565b38612753565b6127599150614916565b3461056157600036600319011261056157601b546040516001600160a01b039091168152602090f35b34610561576020366003190112610561576004356127c181610713565b60018060a01b03166000526019602052602060ff604060002054166040519015158152f35b9160806107cf929493612826604060c0830197805184526001600160401b0360208201511660208501520151604083019060208091805184520151910152565b019060208091805184520151910152565b6080366003190112610561576004356001600160401b03811161056157612862903690600401610759565b604080602319360112610561576064359061287c82610713565b612884614dc1565b5061288d614cfe565b5060608301359161289e8435610ef0565b7f000000000000000000000000000000000000000000000000000000e8d4a51000801561150557806128d49184870135046132ac565b928084106129a55750331561298d5790612918610687926128f58533615759565b6128ff8587615112565b6129088861489d565b9161291236614de9565b92614e64565b9261292161366b565b948186528160208701527f85496b760a4b7f8d66384b9df21b381f5d1b1e79f229a47aaf4c232edc2fe59a61298061295a87519361489d565b9385519181839233978460409194939263ffffffff606083019616825260208201520152565b0390a351928392836127e6565b8151634b637e8f60e11b815260006004820152602490fd5b82516371c4efed60e01b8152600481018590526024810191909152604490fd5b34610561576000366003190112610561576020601654604051908152f35b34610561576000602036600319011261071057600435612a0281610713565b612a0a615598565b6001600160a01b037f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b811691839190833b15612a785760249083604051958694859363ca5eb5e160e01b85521660048401525af18015610b1b57612a6c575080f35b612a7590611bde565b80f35b8280fd5b3461056157600036600319011261056157606060105460ff6040519181811615158352818160081c161515602084015260101c1615156040820152f35b612ac23661091d565b5050509290303303612c0357612adb6109f48583615459565b93612afc612aec610a118385615465565b612af58561489d565b5086615252565b9160288211612b4c575b5050612b20600080516020615afd8339815191529261489d565b6040805163ffffffff909216825260208201929092526001600160a01b03909416939081908101610a72565b9082612b6b92610a9c612b616040880161521d565b93610a968861489d565b917f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b6001600160a01b0316803b1561056157604051633e5ac80960e11b8152936000918591829084908290612bc5908b8d60048501615227565b03925af1908115610b1b57600080516020615afd83398151915293612b2092612bf0575b5092612b06565b80610b0f612bfd92611bde565b38612be9565b60405163029a949d60e31b8152600490fd5b34610561576020366003190112610561577fd48d879cef83a1c0bdda516f27b13ddb1b3f8bbac1c9e1511bb2a659c24277606020600435612c5581610713565b612c5d615598565b600280546001600160a01b0319166001600160a01b03929092169182179055604051908152a1005b346105615760003660031901126105615760206040516109c48152f35b34610561576020612cde612cb536610bf0565b6001600160a01b0391821660009081526006855260408082209290931681526020919091522090565b54604051908152f35b3461056157600036600319011261056157600f546040805161ffff8084168252601084901c811660208084019190915284901c81169282019290925260309290921c166060820152608090f35b346105615760003660031901126105615760206040516127108152f35b3461056157600036600319011261056157600e546040805161ffff8084168252601084901c811660208084019190915284901c81169282019290925260309290921c166060820152608090f35b3461056157600036600319011261056157600c546040516001600160a01b039091168152602090f35b34610561576000366003190112610561576015546040516001600160a01b039091168152602090f35b3461056157600036600319011261056157602060ff60175460881c16604051908152f35b3461056157602036600319011261056157600435612e3181610713565b612e39615598565b6001600160a01b039081168015612e8757600080546001600160a01b03198116831782559092167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b604051631e4fbdf760e01b815260006004820152602490fd5b3461056157608036600319011261056157600435612ebd81611061565b612ec5611633565b60643591604435612ed4615598565b6103e861ffff841611612f7a578361100c91612f127f3c5eaaf6ca1b740f7357efefb3dba70726e1efbf1d834dbcade52108a88c4e919615156147a0565b612f288460ff8019601154169115151617601155565b6011805462ffff001916600887901b62ffff0016179055612f4881601255565b612f5182601355565b604051948594859094939261ffff60609360808401971515845216602083015260408201520152565b60405162461bcd60e51b815260206004820152600f60248201526e4d617820313025206f66206665657360881b6044820152606490fd5b34610561576060366003190112610561576020612fcd366108df565b63ffffffff8135612fdd81610ef0565b166000526001825260406000205482604051920135148152f35b91906001600160a01b03808416801580156130b9575b6130a757600090808252601a60205260ff604083205416928315613093575b50821561307b575b50508015613059575b1561304b5761062b926130c3565b613054926156b4565b600190565b506001600160a01b03811660009081526019602052604090205460ff1661303d565b81526019602052604090205460ff1690503880613034565b84168252604082205460ff1692503861302c565b60405163d92e233d60e01b8152600490fd5b508183161561300d565b91906130ce83613260565b6130d782613260565b908080613258575b1561323057505090916130f460105460ff1690565b156131ca5761312861312061311a613113600e5461ffff9060301c1690565b61ffff1690565b856132ac565b612710900490565b61314761313582866132f1565b6131408330866156b4565b84846156b4565b613150816133ff565b6040805185815260208101929092526000908201526001600160a01b03928316918316907ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d18390606090a36131a2614049565b600d546001600160a01b0316166131ba575b50600190565b6131c49032613d9d565b386131b4565b9190613228816131fc847ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d18394876156b4565b60408051948552600060208601526001908501526001600160a01b039081169416929081906060820190565b0390a3600190565b159081613250575b50156132475761062b926132fe565b61062b926132fe565b905038613238565b5081156130df565b6001600160a01b03166000908152601a602052604090205460ff1680156132845790565b50601960205260ff6040600020541690565b634e487b7160e01b600052601160045260246000fd5b818102929181159184041417156132bf57565b613296565b634e487b7160e01b600052601260045260246000fd5b8015611505576000190490565b8115611505570490565b919082039182116132bf57565b91907ffceff8f013fba7b51634a14dc1db8470204c3f895fb983d10ea83f88c2f7d183906133356126d460105460ff9060081c1690565b80156133ee575b6133b35761335a61312061311a613113600f5461ffff9060301c1690565b9061337a61336883866132f1565b6133738430896156b4565b82876156b4565b6133838261361f565b6040805194855260208501929092526002918401919091526001600160a01b039081169316918060608101613228565b806133c28461322893876156b4565b60408051948552600060208601526003908501526001600160a01b039081169416929081906060820190565b50600f5460301c61ffff161561333c565b801561361c57600e5461ffff808260301c168015611b24576000938060115460ff81168061360e575b6135df575b50509061344761346b9261344c83613447878916846132ac565b6132e7565b9461346084613447838a60101c16856132ac565b9660201c16906132ac565b600b549092906001600160a01b03166001600160a01b03928184161515806135d6575b613584575b5050600c546001600160a01b031691821615158061357b575b613518575b5050806134cb575b50806134c25750565b6107cf9061362e565b61dead7f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed61350f836134ff600295306155c4565b6040519081529081906020820190565b0390a3386134b9565b61352581600193306156b4565b600c547f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed9061357190613560906001600160a01b03166109f4565b604051938452929081906020820190565b0390a338806134b1565b508015156134ac565b61359181600093306156b4565b600b547f52930d55c25b0f73c386a80b850b4c9283ce269586f2daaeb160b71dd3fcdaed906135cc90613560906001600160a01b03166109f4565b0390a33880613493565b5080151561348e565b61344791965061346b939250613600613120866136079360081c16896132ac565b80976132f1565b919261342d565b50848160081c161515613428565b50565b801561361c576107cf906133ff565b600d546001600160a01b031680156136675731601254111561361c576107cf9060135480821161365f575b50613710565b905038613659565b5050565b604051906107cf82611ba3565b6040519060a082018281106001600160401b03821117611bbe57604052565b60405190608082018281106001600160401b03821117611bbe57604052565b6001600160401b038111611bbe57601f01601f191660200190565b3d156136fc573d906136e2826136b6565b916136f06040519384611c0c565b82523d6000602084013e565b606090565b90816020910312610561575190565b601b546001600160a01b031680158015613aa9575b8015613a8d575b613a44578161373b9130615832565b601554604080513060208083018290526001600160a01b0390941682840152610bb86060830152608082015260a08101849052600060c0820181905260e08083019190915281529092601f199290919061379761010083611c0c565b8451916137c4836137b8848201936304e45aaf60e01b85526024830161061a565b03868101855284611c0c565b601b546001600160a01b031692600093849283809351925af16137e56136d1565b90156139fc57805182116139ac5780828061380593518301019101613701565b938415613964576015548651632e1a7d4d60e01b9381019384526024810187905260449283018152849384936001600160a01b03909316929091849161384b9082611c0c565b51925af16138576136d1565b501561391e57600d5481908190819086906001600160a01b03165af161387b6136d1565b50156138da57600d547ff3ff75e0b1c978244be90689011b17bbb5e59d063b132091240a301cf1f1f7709291906138d5906138be906001600160a01b03166109f4565b945191825260208201929092529081906040820190565b0390a2565b915191825250604060208201819052600b908201526a14d95b990819985a5b195960aa1b6060820152600080516020615b3d8339815191529080608081015b0390a1565b50915191825250604060208201819052600d908201526c155b9ddc985c0819985a5b1959609a1b6060820152600080516020615b3d833981519152908060808101613919565b5050506139199150600080516020615b3d833981519152925191829182608091815260406020820152600b60408201526a16995c9bc81bdd5d1c1d5d60aa1b60608201520190565b5050506139199150600080516020615b3d8339815191529251918291826080918152604060208201526013604082015272125b9d985b1a59081cddd85c081c995cdd5b1d606a1b60608201520190565b5050506139199150600080516020615b3d833981519152925191829182608091815260406020820152600b60408201526a14ddd85c0819985a5b195960aa1b60608201520190565b50604080519182526020820181905260119082015270436f6e66696720696e636f6d706c65746560781b6060820152600080516020615b3d833981519152908060808101613919565b50601454613aa3906001600160a01b03166109f4565b1561372c565b50601554613abf906001600160a01b03166109f4565b15613725565b15613acc57565b60405162461bcd60e51b8152602060048201526014602482015273496e73756666696369656e742062616c616e636560601b6044820152606490fd5b15613b0f57565b60405162461bcd60e51b815260206004820152600f60248201526e131bdd1d195c9e481b9bdd081cd95d608a1b6044820152606490fd5b15613b4d57565b60405162461bcd60e51b815260206004820152600c60248201526b1c1bdbdb081b9bdd081cd95d60a21b6044820152606490fd5b6001600160401b038111611bbe5760051b60200190565b60405190613ba582611bc3565b600282526040366020840137565b634e487b7160e01b600052603260045260246000fd5b805115613bd65760200190565b613bb3565b805160011015613bd65760400190565b8051821015613bd65760209160051b010190565b81601f8201121561056157805191613c1683613b81565b92613c246040519485611c0c565b808452602092838086019260051b820101928311610561578301905b828210613c4e575050505090565b8380918351613c5c81610713565b815201910190613c40565b919091604081840312610561578051926001600160401b03938481116105615782019381601f8601121561056157845194613ca186613b81565b90613caf6040519283611c0c565b868252602096878084019160051b83010191858311610561578801905b828210613ceb57505050948301519081116105615761062b9201613bff565b81518060060b8103610561578152908801908801613ccc565b6020908160408183019282815285518094520193019160005b828110613d2b575050505090565b835163ffffffff1685529381019392810192600101613d1d565b6040513d6000823e3d90fd5b600691820b910b0390667fffffffffffff198212667fffffffffffff8313176132bf57565b60060b9060060b90811561150557667fffffffffffff1981146000198314166132bf570590565b90613daf91613daa615983565b613db6565b6001600a55565b600d546001600160a01b0390811692918315613f0157803b613ed557604051635be4331d60e11b81526001600160a01b03821660048201523060248201526044810184905293602090859060649082906000905af160009481613ea5575b50613e4557604080519384526003602085015291169250600080516020615b5d8339815191529190819081016138d5565b8315613e805760405192835216907f451067e4777bd02c1f731ed3c067654bab9c423835639447bd13b158729334bd9080602081015b0390a3565b604080519384526002602085015291169250600080516020615b5d83398151915291a2565b613ec791955060203d8111613ece575b613ebf8183611c0c565b810190613701565b9338613e14565b503d613eb5565b604080519384526001602085015291169250600080516020615b5d8339815191529190819081016138d5565b604080519384526000602085015291169250600080516020615b5d8339815191529190819081016138d5565b91909161ffff808094169116019182116132bf57565b15613f4a57565b60405162461bcd60e51b815260206004820152600c60248201526b5a65726f206164647265737360a01b6044820152606490fd5b90816020910312610561575161062b81610713565b15613f9a57565b60405162461bcd60e51b815260206004820152600c60248201526b125b9d985b1a59081c1bdbdb60a21b6044820152606490fd5b90816020910312610561575160ff811681036105615790565b15613fee57565b60405162461bcd60e51b815260206004820152601760248201527f496e76616c6964207374616c65207468726573686f6c640000000000000000006044820152606490fd5b9190826040910312610561576020825192015190565b6018546001600160a01b0316808015613667576040908151637aa3994960e01b81528281600481855afa908160009182936141af575b5061417b575b505061408f614236565b908115611b245782600491815192838092630ba1864f60e11b82525afa8015610b1b57600091829161414c575b5060008213801590614144575b61413d576140d790426132f1565b60165410611b24576140e8916159a6565b916000831315614138576000928380935161412b8161411d60208201956308085ad960e41b8752602483019190602083019252565b03601f198101835282611c0c565b51925af15061361c6136d1565b505050565b5050505050565b5080156140c9565b905061416e9150833d8511614174575b6141668183611c0c565b810190614033565b386140bc565b503d61415c565b600012806141a6575b61418f575b80614085565b61419b607891426132f1565b106141385738614189565b50801515614184565b9092506141c99150843d8611614174576141668183611c0c565b913861407f565b90816020910312610561575161062b81610efe565b9081602091031261056157518060020b81036105615790565b90816012019182126001166132bf57565b818103929160001380158285131691841216176132bf57565b604d81116132bf57600a0a90565b6017546001600160801b0380821690816143ab575b505060405163b3fac98d60e01b815260209060008282600481305afa90918161437c575b5061427c57505050600090565b61428590614436565b90811561433a5760006004826142a86109f46109f460145460018060a01b031690565b604051630dfe168160e01b815292839182905afa91928261435d575b50506142d257505050600090565b9160ff808260801c169160881c169080158015614355575b61434c576142fa6142ff926141fe565b61420f565b600081128015614342575b61433a5761431790614228565b916001600160a01b03163003614331579061062b91615ab6565b61062b91615a2d565b505050600090565b506024811361430a565b50505050600090565b5081156142ea565b614374929350803d10610ea357610e938183611c0c565b9038806142c4565b61439d919250833d85116143a4575b6143958183611c0c565b8101906141e5565b903861426f565b503d61438b565b6014546004906020906143c8906109f4906001600160a01b031681565b604051630d34328160e11b815292839182905afa60009181614406575b506143f35750505050600090565b161061440057388061424b565b50600090565b61442891925060203d811161442f575b6144208183611c0c565b8101906141d0565b90386143e5565b503d614416565b61062b9060020b600081121561479a5780600003905b61445b620d89e883111561486d565b6001821615614788576001600160881b036ffffcb933bd6fad37aa2d162d1a5940015b16916002811661476c575b60048116614750575b60088116614734575b60108116614718575b602081166146fc575b604081166146e0575b6080908181166146c5575b61010081166146aa575b610200811661468f575b6104008116614674575b6108008116614659575b611000811661463e575b6120008116614623575b6140008116614608575b61800081166145ed575b6201000081166145d2575b6202000081166145b8575b62040000811661459e575b6208000016614583575b50600012614575575b63ffffffff811661456d576000905b60201c60ff91909116016001600160a01b031680615ab6565b600190614554565b61457e906132da565b614545565b6b048a170391f7dc42444e8fa26000929302901c919061453c565b6d2216e584f5fa1ea926041bedfe98909302811c92614532565b926e5d6af8dedb81196699c329225ee60402811c92614527565b926f09aa508b5b7a84e1c677de54f3e99bc902811c9261451c565b926f31be135f97d08fd981231505542fcfa602811c92614511565b926f70d869a156d2a1b890bb3df62baf32f702811c92614507565b926fa9f746462d870fdf8a65dc1f90e061e502811c926144fd565b926fd097f3bdfd2022b8845ad8f792aa582502811c926144f3565b926fe7159475a2c29b7443b29c7fa6e889d902811c926144e9565b926ff3392b0822b70005940c7a398e4b70f302811c926144df565b926ff987a7253ac413176f2b074cf7815e5402811c926144d5565b926ffcbe86c7900a88aedcffc83b479aa3a402811c926144cb565b926ffe5dee046a99a2a811c461f1969c305302811c926144c1565b916fff2ea16466c96a3843ec78b326b528610260801c916144b6565b916fff973b41fa98c081472e6896dfb254c00260801c916144ad565b916fffcb9843d60f6159c9db58835c9266440260801c916144a4565b916fffe5caca7e10e4e61c3624eaa0941cd00260801c9161449b565b916ffff2e50f5f656932ef12357cf3c7fdcc0260801c91614492565b916ffff97272373d413259a46990580e213a0260801c91614489565b6001600160881b03600160801b61447e565b8061444c565b156147a757565b60405162461bcd60e51b815260206004820152601460248201527304d61782073776170206d757374206265203e20360641b6044820152606490fd5b604051906147f082611bc3565b60248252636c61677360e01b6040837f4d697373696e6720636f6d706f6e656e7473202d20636865636b20626974206660208201520152565b6040519061483682611bc3565b6022825261195960f21b6040837f416c6c20637269746963616c20636f6d706f6e656e747320636f6e666967757260208201520152565b1561487457565b60405162461bcd60e51b81526020600482015260016024820152601560fa1b6044820152606490fd5b3561062b81610ef0565b63ffffffff168060005260016020526040600020549081156148c7575090565b6024906040519063f6ff4fb760e01b82526004820152fd5b9291926148eb826136b6565b916148f96040519384611c0c565b829481845281830111610561578281602093846000960137010152565b60001981146132bf5760010190565b90601f811161493357505050565b600091825260208220906020601f850160051c8301941061496f575b601f0160051c01915b82811061496457505050565b818155600101614958565b909250829061494f565b91909182516001600160401b038111611bbe576149a08161499a8454611abd565b84614925565b602080601f83116001146149dc5750819293946000926149d1575b50508160011b916000199060031b1c1916179055565b0151905038806149bb565b90601f198316956149f285600052602060002090565b926000905b888210614a2f57505083600195969710614a16575b505050811b019055565b015160001960f88460031b161c19169055388080614a0c565b806001859682949686015181550195019301906149f7565b602080820190808352835180925260409283810182858560051b8401019601946000925b858410614a7c575050505050505090565b909192939495968580614abf600193603f19868203018852868c5163ffffffff815116835261ffff858201511685840152015190606090818982015201906105f5565b990194019401929594939190614a6b565b90600091825b8151811015614b6057614b5b90614b566040614afe81614af68588613beb565b510151614cc6565b614b5181614b0c8588613beb565b5101519163ffffffff614b1f8689613beb565b515116895261ffff602091600383528a2091614b3b878a613beb565b5101511661ffff16600052602052604060002090565b614979565b614916565b614ad6565b507fbe4864a8e820971c0247f5992e2da559595f7bf076a21cb5928d443d2a13b6749192506139199060405191829182614a47565b909291928360021161056157831161056157600201916001190190565b602090836107cf939594956040519683614bd589955180928880890191016105d2565b8401918583013701600083820152038085520183611c0c565b908060209392818452848401376000828201840152601f01601f1916010190565b91602061062b938181520191614bee565b611c85611c919263ffffffff614c55939795969716600052600360205260406000209061ffff16600052602052604060002090565b805115614cb8578315614cb2576002841015614c89575050610b51604051928392639a6d49cd60e01b845260048401614c0f565b909280614cac9161062b94614ca7614ca23684846148df565b614cc6565b614b95565b91614bb2565b92509050565b50919061062b9136916148df565b600361ffff60028301511603614cd95750565b604051639a6d49cd60e01b815260206004820152908190610b519060248301906105f5565b60405190614d0b82611ba3565b60006020838281520152565b919082604091031261056157604051614d2f81611ba3565b6020808294805184520151910152565b906040828203126105615761062b91614d17565b906020909392936040835263ffffffff81511660408401528181015160608401526080614da7614d91604084015160a08488015260e08701906105f5565b6060840151868203603f190160a08801526105f5565b910151151560c08401526001600160a01b03909416910152565b60405190614dce82611bc3565b8160008152600060208201526040614de4614cfe565b910152565b60409060231901126105615760405190614e0282611ba3565b60243582526044356020830152565b6001600160401b0381160361056157565b9060808282031261056157614e5c906040805193614e3f85611bc3565b805185526020810151614e5181614e11565b602086015201614d17565b604082015290565b614ec160809492614edd9694614e78614dc1565b506020614e858651614f54565b950191825180614f45575b50614e9a856148a7565b9251151592614eaa61141a613678565b602086015260408501526060840152151585830152565b6040518095819482936302637a4560e41b845260048401614d53565b03917f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b6001600160a01b03165af1908115610b1b57600091614f1d575090565b61062b915060803d8111614f3e575b614f368183611c0c565b810190614e22565b503d614f2c565b614f4e90614f76565b38614e90565b803403614f5e5790565b6040516304fb820960e51b8152346004820152602490fd5b60405163393f876560e21b81526001600160a01b037f0000000000000000000000006f475642a6e85809b1c36fa62763669b1b48dd5b8116926020929091908381600481885afa908115610b1b57600091615089575b5016928315615077576040516323b872dd60e01b8482019081523360248301526001600160a01b039092166044820152606481019290925261502f91600091829161501a816084810161411d565b519082875af16150286136d1565b9084615920565b805191821515928361505e575b5050506150465750565b60249060405190635274afe760e01b82526004820152fd5b61506e93508201810191016150d8565b1538808061503c565b6040516329b99a9560e11b8152600490fd5b6150a09150843d8611610ea357610e938183611c0c565b38614fcc565b903590601e198136030182121561056157018035906001600160401b0382116105615760200191813603831361056157565b90816020910312610561575161062b81611061565b909161510461062b936040845260408401906105f5565b9160208184039101526105f5565b909161517661515461514861519d957f000000000000000000000000000000000000000000000000000000e8d4a51000906132e7565b6001600160401b031690565b61516b61516460a08601866150a6565b36916148df565b9060208501356153ce565b9390928394600014615215576002905b61261d6151928261489d565b9160808101906150a6565b60045490926001600160a01b039091169083826151b957505050565b60405163043a78eb60e01b8152926020928492839182916151dd91600484016150ed565b03915afa8015610b1b576151ee5750565b61361c9060203d811161520e575b6152068183611c0c565b8101906150d8565b503d6151fc565b600190615186565b3561062b81614e11565b61062b939260809260018060a01b0316825260208201526000604082015281606082015201906105f5565b6001600160a01b03818116156152d3575b81169081156152ba57600754908382018092116132bf576007919091556001600160a01b031660009081526005602052604090208281540190556000600080516020615b1d8339815191526020604051858152a390565b60405163ec442f0560e01b815260006004820152602490fd5b61dead9150615263565b61062b906001600160401b037f000000000000000000000000000000000000000000000000000000e8d4a5100091166132ac565b7f000000000000000000000000000000000000000000000000000000e8d4a510008015611505578061534392046132ac565b9182918084106153505750565b6040516371c4efed60e01b8152600481018590526024810191909152604490fd5b604c919361062b936040519586936001600160401b0360c01b9060c01b16602085015263ffffffff60e01b9060e01b166028840152602c8301526153be81518092602086860191016105d2565b810103602c810184520182611c0c565b8251158015939061542c576154299160689160405194859260208401526001600160401b0360c01b9060c01b16604083015233604883015261541981518092602086860191016105d2565b8101036048810184520182611c0c565b91565b50906040519160208301526001600160401b0360c01b9060c01b1660408201526028815261542981611bc3565b90602011610561573590565b90602811610561576020013560c01c90565b90806028116105615761062b91369160271901906028016148df565b9190811015613bd65760051b8101359061013e1981360301821215610561570190565b3561062b81610713565b92909361551c926001600160401b03604061062b9a98999763ffffffff81356154e881610ef0565b16885260208101356020890152013561550081614e11565b166040860152606085015260e0608085015260e0840191614bee565b6001600160a01b0390941660a082015280840360c090910152614bee565b602081830312610561578051906001600160401b038211610561570181601f8201121561056157805161556c816136b6565b9261557a6040519485611c0c565b818452602082840101116105615761062b91602080850191016105d2565b6000546001600160a01b031633036155ac57565b60405163118cdaa760e01b8152336004820152602490fd5b6001600160a01b03811690811561569b576001600160a01b03811660009081526005602052604090205483811061566c578361561491039160018060a01b03166000526005602052604060002090565b5561dead6000819052600560209081527f7d509c07f0d4edcc2dd1b53aae68677132eb562dcba78e36381b63ccaf66e6ba8054850190556040519384529092600080516020615b1d8339815191529181908101613e7b565b60405163391434e360e21b81526001600160a01b03929092166004830152602482015260448101839052606490fd5b604051634b637e8f60e11b815260006004820152602490fd5b916001600160a01b038084169290831561569b5781169384156152ba576001600160a01b03811660009081526005602052604090205483811061566c57613e7b928492615728600080516020615b1d8339815191529661574394039160018060a01b03166000526005602052604060002090565b556001600160a01b0316600090815260056020526040902090565b8054820190556040519081529081906020820190565b6001600160a01b03811690816157a25750600754918083018093116132bf576020600080516020615b1d833981519152916000946007555b8060075403600755604051908152a3565b6001600160a01b03811660009081526005602052604090205493929081851061580057816020916157fa600080516020615b1d8339815191529460009798039160018060a01b03166000526005602052604060002090565b55615791565b60405163391434e360e21b81526001600160a01b03919091166004820152602481018590526044810191909152606490fd5b6001600160a01b0380821692919083156158cd5782169384156158b457806158aa7f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259461589360209560018060a01b03166000526006602052604060002090565b9060018060a01b0316600052602052604060002090565b55604051908152a3565b604051634a1406b160e11b815260006004820152602490fd5b60405163e602df0560e01b815260006004820152602490fd5b906001600160a01b03808316156158cd578116156158b45761589361591d9260018060a01b03166000526006602052604060002090565b55565b90615947575080511561593557805190602001fd5b604051630a12f52160e11b8152600490fd5b8151158061597a575b615958575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15615950565b6002600a5414615994576002600a55565b604051633ee5aeb560e01b8152600490fd5b908082029060001981840990828083109203918083039214615a1c57670de0b6b3a76400009082821115615a0a577faccb18165bd6fe31ae1cf318dc5b51eee0e1ba569b88cd74c1773b91fac10669940990828211900360ee1b910360121c170290565b60405163227bc15360e01b8152600490fd5b5050670de0b6b3a764000091500490565b600160601b91606082901b9160001984820993838086109503948086039514615aa95784831115615a0a5782910981600003821680920460028082600302188083028203028083028203028083028203028083028203028083028203028092029003029360018380600003040190848311900302920304170290565b50509061062b92506132e7565b818102919060001982820991838084109303928084039314615af357600160601b9183831115615a0a570990828211900360a01b910360601c1790565b50505060601c9056feefed6d3500546b29533b128a29e3a94d70788727f0507505ac12eaf2e578fd9cddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef780f4e88314062bd6e7b2daeb47a4dc34d23b318c7311ca6c0f02ace99271cfd22f6f9edacc2bcfc7e3749caab22297d7f3e7a44706adc0cd94e17fb7ecd5798a2646970667358221220ff25e1029f3ebaddecc767c64c8e8206ac10cfdacc93d2b0f2af3af7eeaee6aa64736f6c63430008140033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f0000000000000000000000006940adc0a505108bc11ca28eefb7e3bac7af0777000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f0000000000000000000000000000000000000000000000000000000000000006447261676f6e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006445241474f4e0000000000000000000000000000000000000000000000000000

-----Decoded View---------------
Arg [0] : _name (string): Dragon
Arg [1] : _symbol (string): DRAGON
Arg [2] : _delegate (address): 0xDDd0050d1E084dFc72d5d06447Cc10bcD3fEF60F
Arg [3] : _registry (address): 0x6940aDc0A505108bC11CA28EefB7E3BAc7AF0777
Arg [4] : _owner (address): 0xDDd0050d1E084dFc72d5d06447Cc10bcD3fEF60F

-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [2] : 000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f
Arg [3] : 0000000000000000000000006940adc0a505108bc11ca28eefb7e3bac7af0777
Arg [4] : 000000000000000000000000ddd0050d1e084dfc72d5d06447cc10bcd3fef60f
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000006
Arg [6] : 447261676f6e0000000000000000000000000000000000000000000000000000
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000006
Arg [8] : 445241474f4e0000000000000000000000000000000000000000000000000000


Block Transaction Gas Used Reward
view all blocks ##produced##

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.