S Price: $0.504688 (+2.63%)

Contract

0x75c7f62b450a6BCd489ef8e9Ee1169f5989fd6bD

Overview

S Balance

Sonic LogoSonic LogoSonic Logo0 S

S Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0x705a4730...A43fA384e
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
PlayersLibrary

Compiler Version
v0.8.28+commit.7893614a

Optimization Enabled:
Yes with 9999999 runs

Other Settings:
cancun EvmVersion
File 1 of 14 : PlayersLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";

import {IItemNFT} from "../interfaces/IItemNFT.sol";
import {IWorldActions} from "../interfaces/IWorldActions.sol";

import {CombatStyleLibrary} from "../libraries/CombatStyleLibrary.sol";
import {SkillLibrary} from "../libraries/SkillLibrary.sol";

import {Skill, CombatStats, CombatStyle, BoostType, Attire} from "../globals/misc.sol";
import {PendingQueuedActionEquipmentState, QueuedAction, ActionChoice, PlayerBoostInfo, PackedXP, PendingQueuedActionProcessed, Item, Player, Player, XP_BYTES, IS_FULL_MODE_BIT, CheckpointEquipments} from "../globals/players.sol";
import {ActionRewards} from "../globals/rewards.sol";
import {NONE} from "../globals/items.sol";
import {RATE_MUL, SPAWN_MUL, GUAR_MUL} from "../globals/actions.sol";

// This file contains methods for interacting with the player that is used to decrease implementation deployment bytecode code.
library PlayersLibrary {
  using CombatStyleLibrary for uint8;
  using SkillLibrary for uint8;
  using SkillLibrary for Skill;

  error InvalidXPSkill();
  error InvalidAction();
  error SkillForPetNotHandledYet();

  // This is to prevent some precision loss in the healing calculations
  uint256 constant HEALING_SCALE = 1_000_000;

  function _getLevel(uint256 xp) internal pure returns (uint16) {
    uint256 low;
    uint256 high = XP_BYTES.length / 4;

    while (low < high) {
      uint256 mid = (low + high) / 2;

      // Note that mid will always be strictly less than high (i.e. it will be a valid array index)
      if (_getXP(mid) > xp) {
        high = mid;
      } else {
        low = mid + 1;
      }
    }

    if (low != 0) {
      return uint16(low);
    } else {
      return 1;
    }
  }

  function getLevel(uint256 xp) external pure returns (uint16) {
    return _getLevel(xp);
  }

  function _getXP(uint256 index) private pure returns (uint32) {
    uint256 key = index * 4;
    return
      uint32(
        XP_BYTES[key] |
          (bytes4(XP_BYTES[key + 1]) >> 8) |
          (bytes4(XP_BYTES[key + 2]) >> 16) |
          (bytes4(XP_BYTES[key + 3]) >> 24)
      );
  }

  function _getRealBalance(
    uint256 originalBalance,
    uint256 itemId,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  ) private pure returns (uint256 balance) {
    balance = originalBalance;
    for (uint256 i; i < pendingQueuedActionEquipmentStates.length; ++i) {
      PendingQueuedActionEquipmentState memory pendingQueuedActionEquipmentState = pendingQueuedActionEquipmentStates[
        i
      ];
      for (uint256 j; j < pendingQueuedActionEquipmentState.producedItemTokenIds.length; ++j) {
        if (pendingQueuedActionEquipmentState.producedItemTokenIds[j] == itemId) {
          balance += pendingQueuedActionEquipmentState.producedAmounts[j];
        }
      }
      for (uint256 j; j < pendingQueuedActionEquipmentState.consumedItemTokenIds.length; ++j) {
        if (pendingQueuedActionEquipmentState.consumedItemTokenIds[j] == itemId) {
          if (balance >= pendingQueuedActionEquipmentState.consumedAmounts[j]) {
            balance -= pendingQueuedActionEquipmentState.consumedAmounts[j];
          } else {
            balance = 0;
          }
        }
      }
    }
  }

  function getBalanceUsingCheckpoint(
    uint256 itemId,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) private pure returns (uint256 balance) {
    for (uint256 i; i < checkpointEquipments.itemTokenIds.length; ++i) {
      if (checkpointEquipments.itemTokenIds[i] == itemId) {
        return _getRealBalance(checkpointEquipments.balances[i], itemId, pendingQueuedActionEquipmentStates);
      }
    }
  }

  function getBalancesUsingCheckpoint(
    uint16[] memory itemIds,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) private pure returns (uint256[] memory balances) {
    balances = new uint256[](itemIds.length);

    for (uint256 i; i < checkpointEquipments.itemTokenIds.length; ++i) {
      uint256 itemTokenId = checkpointEquipments.itemTokenIds[i];
      uint256 checkpointBalance = checkpointEquipments.balances[i];
      for (uint256 j; j < itemIds.length; ++j) {
        if (itemIds[j] == itemTokenId) {
          balances[j] = _getRealBalance(checkpointBalance, itemIds[j], pendingQueuedActionEquipmentStates);
          break;
        }
      }
    }
  }

  // This takes into account any intermediate changes from previous actions from view functions
  // as those cannot affect the blockchain state with balanceOf
  function getBalanceUsingCurrentBalance(
    address from,
    uint256 itemId,
    address itemNFT,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  ) public view returns (uint256 balance) {
    balance = _getRealBalance(IItemNFT(itemNFT).balanceOf(from, itemId), itemId, pendingQueuedActionEquipmentStates);
  }

  function getBalanceUsingCurrentBalances(
    address from,
    uint16[] memory itemIds,
    address itemNFT,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates
  ) public view returns (uint256[] memory balances) {
    balances = IItemNFT(itemNFT).balanceOfs(from, itemIds);
    uint256 bounds = balances.length;
    for (uint256 i; i < bounds; ++i) {
      balances[i] = _getRealBalance(balances[i], itemIds[i], pendingQueuedActionEquipmentStates);
    }
  }

  function _getMaxRequiredRatio(
    address from,
    ActionChoice memory actionChoice,
    uint16 baseInputItemsConsumedNum,
    IItemNFT itemNFT,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  ) private view returns (uint256 maxRequiredRatio) {
    maxRequiredRatio = baseInputItemsConsumedNum;

    if (baseInputItemsConsumedNum != 0) {
      if (actionChoice.inputTokenId1 != 0) {
        maxRequiredRatio = _getMaxRequiredRatioPartial(
          from,
          actionChoice.inputTokenId1,
          actionChoice.inputAmount1,
          maxRequiredRatio,
          itemNFT,
          pendingQueuedActionEquipmentStates
        );
      }
      if (actionChoice.inputTokenId2 != 0) {
        maxRequiredRatio = _getMaxRequiredRatioPartial(
          from,
          actionChoice.inputTokenId2,
          actionChoice.inputAmount2,
          maxRequiredRatio,
          itemNFT,
          pendingQueuedActionEquipmentStates
        );
      }
      if (actionChoice.inputTokenId3 != 0) {
        maxRequiredRatio = _getMaxRequiredRatioPartial(
          from,
          actionChoice.inputTokenId3,
          actionChoice.inputAmount3,
          maxRequiredRatio,
          itemNFT,
          pendingQueuedActionEquipmentStates
        );
      }
    }
  }

  function _getMaxRequiredRatioPartial(
    address from,
    uint16 inputTokenId,
    uint256 inputAmount,
    uint256 prevConsumeMaxRatio,
    IItemNFT itemNFT,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  ) private view returns (uint256 maxRequiredRatio) {
    uint256 balance = getBalanceUsingCurrentBalance(
      from,
      inputTokenId,
      address(itemNFT),
      pendingQueuedActionEquipmentStates
    );
    uint256 tempMaxRequiredRatio = balance / inputAmount;
    if (tempMaxRequiredRatio < prevConsumeMaxRatio) {
      maxRequiredRatio = tempMaxRequiredRatio;
    } else {
      maxRequiredRatio = prevConsumeMaxRatio;
    }
  }

  function _max(int a, int b) private pure returns (int) {
    return a > b ? a : b;
  }

  function _dmgPerMinute(int attack, int defence, uint8 alphaCombat, uint8 betaCombat) private pure returns (uint256) {
    if (attack == 0) {
      return 0;
    }
    // Negative defence is capped at the negative of the attack value.
    // So an attack of 10 and defence of -15 is the same as attack -10.
    defence = _max(-attack, defence);
    return uint256(_max(1, int128(attack) * int8(alphaCombat) + (attack * 2 - defence) * int8(betaCombat)));
  }

  function dmg(
    int attack,
    int defence,
    uint8 alphaCombat,
    uint8 betaCombat,
    uint256 elapsedTime
  ) public pure returns (uint32) {
    return uint32((_dmgPerMinute(attack, defence, alphaCombat, betaCombat) * elapsedTime) / 60);
  }

  function _fullDmg(
    CombatStats memory combatStats,
    CombatStats memory enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    uint256 elapsedTime
  ) private pure returns (uint32 fullDmg) {
    fullDmg = dmg(combatStats.meleeAttack, enemyCombatStats.meleeDefence, alphaCombat, betaCombat, elapsedTime);
    fullDmg += dmg(combatStats.rangedAttack, enemyCombatStats.rangedDefence, alphaCombat, betaCombat, elapsedTime);
    fullDmg += dmg(combatStats.magicAttack, enemyCombatStats.magicDefence, alphaCombat, betaCombat, elapsedTime);
  }

  function _timeToKill(
    int attack,
    int defence,
    uint8 alphaCombat,
    uint8 betaCombat,
    int16 enemyHealth
  ) private pure returns (uint256) {
    // Formula is max(1, a(atk) + b(2 * atk - def))
    // Always do at least 1 damage per minute
    uint256 dmgPerMinute = _dmgPerMinute(attack, defence, alphaCombat, betaCombat);
    return Math.ceilDiv(uint256(uint16(enemyHealth)) * 60, dmgPerMinute);
  }

  function _timeToKillPlayer(
    CombatStats memory combatStats,
    CombatStats memory enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    int health
  ) private pure returns (uint256) {
    uint256 dmgPerMinute = _dmgPerMinute(
      enemyCombatStats.meleeAttack,
      combatStats.meleeDefence,
      alphaCombat,
      betaCombat
    );
    dmgPerMinute += _dmgPerMinute(enemyCombatStats.rangedAttack, combatStats.rangedDefence, alphaCombat, betaCombat);
    dmgPerMinute += _dmgPerMinute(enemyCombatStats.magicAttack, combatStats.magicDefence, alphaCombat, betaCombat);
    return Math.ceilDiv(uint256(health) * 60, dmgPerMinute);
  }

  function _getTimeToKill(
    Skill skill,
    CombatStats memory combatStats,
    CombatStats memory enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    int16 enemyHealth
  ) private pure returns (uint256 timeToKill) {
    int16 attack;
    int16 defence;
    if (skill == Skill.MELEE) {
      attack = combatStats.meleeAttack;
      defence = enemyCombatStats.meleeDefence;
    } else if (skill == Skill.RANGED) {
      attack = combatStats.rangedAttack;
      defence = enemyCombatStats.rangedDefence;
    } else if (skill == Skill.MAGIC) {
      attack = combatStats.magicAttack;
      defence = enemyCombatStats.magicDefence;
    } else {
      assert(false);
    }

    timeToKill = _timeToKill(attack, defence, alphaCombat, betaCombat, enemyHealth);
  }

  function _getDmgDealtByPlayer(
    ActionChoice memory actionChoice,
    CombatStats memory combatStats,
    CombatStats memory enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    uint256 elapsedTime
  ) private pure returns (uint32 dmgDealt) {
    Skill skill = actionChoice.skill._asSkill();
    if (skill == Skill.MELEE) {
      dmgDealt = dmg(combatStats.meleeAttack, enemyCombatStats.meleeDefence, alphaCombat, betaCombat, elapsedTime);
    } else if (skill == Skill.RANGED) {
      dmgDealt = dmg(combatStats.rangedAttack, enemyCombatStats.rangedDefence, alphaCombat, betaCombat, elapsedTime);
    } else if (skill == Skill.MAGIC) {
      // Assumes this is a magic action
      dmgDealt = dmg(combatStats.magicAttack, enemyCombatStats.magicDefence, alphaCombat, betaCombat, elapsedTime);
    } else {
      assert(false);
    }
  }

  function determineBattleOutcome(
    address from,
    address itemNFT,
    uint256 elapsedTime,
    ActionChoice calldata actionChoice,
    uint16 regenerateId,
    uint256 numSpawnedPerHour,
    CombatStats memory combatStats,
    CombatStats calldata enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    uint8 alphaCombatHealing,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates
  )
    external
    view
    returns (
      uint256 xpElapsedTime,
      uint256 combatElapsedTime,
      uint16 baseInputItemsConsumedNum,
      uint16 foodConsumed,
      bool died
    )
  {
    return
      _determineBattleOutcome(
        from,
        itemNFT,
        elapsedTime,
        actionChoice,
        regenerateId,
        numSpawnedPerHour,
        combatStats,
        enemyCombatStats,
        alphaCombat,
        betaCombat,
        alphaCombatHealing,
        pendingQueuedActionEquipmentStates
      );
  }

  function _determineBattleOutcome(
    address from,
    address itemNFT,
    uint256 elapsedTime,
    ActionChoice memory actionChoice,
    uint16 regenerateId,
    uint256 numSpawnedPerHour,
    CombatStats memory combatStats,
    CombatStats memory enemyCombatStats,
    uint8 alphaCombat,
    uint8 betaCombat,
    uint8 alphaCombatHealing,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  )
    internal
    view
    returns (
      uint256 xpElapsedTime,
      uint256 combatElapsedTime,
      uint16 baseInputItemsConsumedNum,
      uint16 foodConsumed,
      bool died
    )
  {
    uint256 respawnTime = (3600 * SPAWN_MUL) / numSpawnedPerHour;
    uint32 dmgDealt = _getDmgDealtByPlayer(
      actionChoice,
      combatStats,
      enemyCombatStats,
      alphaCombat,
      betaCombat,
      respawnTime
    );

    uint256 combatTimePerKill = _getTimeToKill(
      actionChoice.skill._asSkill(),
      combatStats,
      enemyCombatStats,
      alphaCombat,
      betaCombat,
      enemyCombatStats.health
    );

    // Steps for this:
    // 1 - Work out best case scenario for how many we can kill in the elapsed time assuming we have enough food and consumables
    // 2 - Now work out how many we can kill in the combat time based on how many consumables we actually have
    // 3 - Now work out how many we can kill in the elapsed time based on how much food we actually have and adjust combat time
    // 3.5 - If not enough food (i.e died) then backtrack the scrolls.

    // Time spent in comabt with the enemies that were killed, needed in case foodConsumed gets maxed out
    uint256 combatElapsedTimeKilling;
    uint256 numKilled;
    bool canKillAll = dmgDealt > uint16(enemyCombatStats.health);
    if (canKillAll) {
      // But how many can we kill in the time that has elapsed?
      numKilled = (elapsedTime * numSpawnedPerHour) / (3600 * SPAWN_MUL);
      uint256 combatTimePerEnemy = Math.ceilDiv(uint16(enemyCombatStats.health) * respawnTime, dmgDealt);
      combatElapsedTime = combatTimePerEnemy * numKilled;
      combatElapsedTimeKilling = combatElapsedTime;
      // Add remainder combat time to current monster you are fighting
      combatElapsedTime += Math.min(combatTimePerEnemy, elapsedTime - respawnTime * numKilled);
    } else {
      numKilled = elapsedTime / combatTimePerKill;
      combatElapsedTimeKilling = combatTimePerKill * numKilled;
      combatElapsedTime = elapsedTime;
    }

    xpElapsedTime = respawnTime * numKilled;

    // Step 2 - Work out how many consumables are used
    // Check how many to consume, and also adjust xpElapsedTime if they don't have enough consumables
    uint256 maxRequiredBaseInputItemsConsumedRatio = baseInputItemsConsumedNum;
    if (actionChoice.rate != 0) {
      baseInputItemsConsumedNum = uint16(
        Math.max(numKilled, Math.ceilDiv(combatElapsedTime * actionChoice.rate, 3600 * RATE_MUL))
      );

      // This checks the balances
      maxRequiredBaseInputItemsConsumedRatio = _getMaxRequiredRatio(
        from,
        actionChoice,
        baseInputItemsConsumedNum,
        IItemNFT(itemNFT),
        pendingQueuedActionEquipmentStates
      );

      if (baseInputItemsConsumedNum == 0) {
        // Requires input items but we don't have any. In combat the entire time getting rekt
        xpElapsedTime = 0;
        combatElapsedTime = elapsedTime;
      } else if (baseInputItemsConsumedNum > maxRequiredBaseInputItemsConsumedRatio) {
        numKilled = (numKilled * maxRequiredBaseInputItemsConsumedRatio) / baseInputItemsConsumedNum;
        xpElapsedTime = respawnTime * numKilled;
        baseInputItemsConsumedNum = uint16(maxRequiredBaseInputItemsConsumedRatio);

        if (canKillAll) {
          uint256 combatTimePerEnemy = Math.ceilDiv(uint16(enemyCombatStats.health) * respawnTime, dmgDealt);
          combatElapsedTime = combatTimePerEnemy * numKilled;
          combatElapsedTimeKilling = combatElapsedTime;
          combatElapsedTime += elapsedTime - (respawnTime * numKilled);
        } else {
          // In combat the entire time
          combatElapsedTime = elapsedTime;
          combatElapsedTimeKilling = combatTimePerKill * numKilled;
        }
      }
    }

    // Calculate combat damage
    // Step 3 - Calculate raw damage taken
    int32 totalHealthLost = int32(_fullDmg(enemyCombatStats, combatStats, alphaCombat, betaCombat, combatElapsedTime));

    // Take away our health points from the total dealt to us
    totalHealthLost -= combatStats.health;

    int32 totalHealthLostOnlyKilled = int32(
      _fullDmg(enemyCombatStats, combatStats, alphaCombat, betaCombat, combatElapsedTimeKilling)
    );

    totalHealthLostOnlyKilled -= combatStats.health;

    int32 playerHealth = combatStats.health;
    uint256 totalFoodRequiredKilling;
    (foodConsumed, totalFoodRequiredKilling, died) = _getFoodConsumed(
      from,
      regenerateId,
      totalHealthLost > 0 ? uint32(totalHealthLost) : 0,
      totalHealthLostOnlyKilled > 0 ? uint32(totalHealthLostOnlyKilled) : 0,
      playerHealth,
      alphaCombatHealing,
      itemNFT,
      pendingQueuedActionEquipmentStates
    );

    // Didn't have enough food to survive the best case combat scenario
    if (died) {
      uint256 healthRestored;
      if (regenerateId != NONE) {
        Item memory item = IItemNFT(itemNFT).getItem(regenerateId);
        healthRestored = item.healthRestored;
      }

      // Calculate total health using raw values
      int256 totalHealth = playerHealth + int256(uint256(foodConsumed * healthRestored));
      // How much combat time is required to kill the player
      uint256 killPlayerTime = _timeToKillPlayer(combatStats, enemyCombatStats, alphaCombat, betaCombat, totalHealth);

      combatElapsedTime = Math.min(combatElapsedTime, killPlayerTime); // Needed?
      if (healthRestored == 0 || totalHealthLost <= 0) {
        // No food attached or didn't lose any health

        if (canKillAll) {
          uint256 combatTimePerEnemy = Math.ceilDiv(uint16(enemyCombatStats.health) * respawnTime, dmgDealt);
          numKilled = combatElapsedTime / combatTimePerEnemy;
        } else {
          // In combat the entire time
          numKilled = combatElapsedTime / combatTimePerKill;
        }
      } else {
        // How many can we kill with the food we did consume
        if (totalFoodRequiredKilling != 0) {
          if (foodConsumed < totalFoodRequiredKilling) {
            numKilled = (numKilled * foodConsumed) / totalFoodRequiredKilling;
          }
        } else {
          numKilled = 0;
        }
      }
      xpElapsedTime = respawnTime * numKilled;

      // Step 3.5 - Wasn't enough food, so work out how many consumables we actually used.
      if (actionChoice.rate != 0) {
        // Make sure we use at least 1 per kill
        baseInputItemsConsumedNum = uint16(
          Math.max(numKilled, Math.ceilDiv(combatElapsedTime * actionChoice.rate, 3600 * RATE_MUL))
        );

        // Make sure we don't go above the maximum amount of consumables (scrolls/arrows) that we actually have
        if (baseInputItemsConsumedNum > maxRequiredBaseInputItemsConsumedRatio) {
          uint256 newMaxRequiredBaseInputItemsConsumedRatio = _getMaxRequiredRatio(
            from,
            actionChoice,
            baseInputItemsConsumedNum,
            IItemNFT(itemNFT),
            pendingQueuedActionEquipmentStates
          );

          baseInputItemsConsumedNum = uint16(
            Math.min(baseInputItemsConsumedNum, newMaxRequiredBaseInputItemsConsumedRatio)
          );
        }
      }
    }
  }

  function _calculateHealingDoneFromHealth(
    uint256 health,
    uint256 alphaCombatHealing
  ) private pure returns (uint256 healingDoneFromHealth) {
    // healing fraction = 1 + (alphaCombatHealing * health / 100)
    uint256 scaledHealth = ((HEALING_SCALE * alphaCombatHealing) / 100) * health;
    uint256 divisor = 100;
    healingDoneFromHealth = HEALING_SCALE + scaledHealth / divisor;
  }

  function _calculateTotalFoodRequired(
    uint256 totalHealthLost,
    uint256 healthRestoredFromItem,
    uint256 healingDoneFromHealth
  ) private pure returns (uint256 totalFoodRequired) {
    uint256 numerator = totalHealthLost * HEALING_SCALE;
    uint256 denominator = healthRestoredFromItem * healingDoneFromHealth;
    totalFoodRequired = Math.ceilDiv(numerator, denominator);
  }

  function _getFoodConsumed(
    address from,
    uint16 regenerateId,
    uint32 totalHealthLost,
    uint32 totalHealthLostKilling,
    int32 totalHealthPlayer,
    uint256 alphaCombatHealing,
    address itemNFT,
    PendingQueuedActionEquipmentState[] memory pendingQueuedActionEquipmentStates
  ) private view returns (uint16 foodConsumed, uint256 totalFoodRequiredKilling, bool died) {
    uint256 healthRestoredFromItem;
    if (regenerateId != NONE) {
      Item memory item = IItemNFT(itemNFT).getItem(regenerateId);
      healthRestoredFromItem = item.healthRestored;
    }

    if (healthRestoredFromItem == 0 || totalHealthLost <= 0) {
      // No food attached or didn't lose any health
      died = totalHealthLost != 0;
    } else {
      // Only use positive values for healing bonus
      uint256 effectiveHealth = totalHealthPlayer > 0 ? uint32(totalHealthPlayer) : 0;
      uint256 healingDoneFromHealth = _calculateHealingDoneFromHealth(effectiveHealth, alphaCombatHealing);
      uint256 totalFoodRequired = _calculateTotalFoodRequired(
        totalHealthLost,
        healthRestoredFromItem,
        healingDoneFromHealth
      );
      totalFoodRequiredKilling = _calculateTotalFoodRequired(
        totalHealthLostKilling,
        healthRestoredFromItem,
        healingDoneFromHealth
      );

      uint256 balance = getBalanceUsingCurrentBalance(from, regenerateId, itemNFT, pendingQueuedActionEquipmentStates);

      // Can only consume a maximum of 65535 food
      if (totalFoodRequired > type(uint16).max) {
        died = true;
      } else {
        died = totalFoodRequired > balance;
      }

      if (died) {
        foodConsumed = uint16(balance > type(uint16).max ? type(uint16).max : balance);
      } else {
        foodConsumed = uint16(totalFoodRequired);
      }
    }
  }

  function getNonCombatAdjustedElapsedTime(
    address from,
    address itemNFT,
    uint256 elapsedTime,
    ActionChoice calldata actionChoice,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates
  ) external view returns (uint256 xpElapsedTime, uint16 baseInputItemsConsumedNum) {
    // Check the max that can be used
    baseInputItemsConsumedNum = uint16((elapsedTime * actionChoice.rate) / (3600 * RATE_MUL));

    if (baseInputItemsConsumedNum != 0) {
      // This checks the balances
      uint256 maxRequiredRatio = _getMaxRequiredRatio(
        from,
        actionChoice,
        baseInputItemsConsumedNum,
        IItemNFT(itemNFT),
        pendingQueuedActionEquipmentStates
      );
      bool hadEnoughConsumables = baseInputItemsConsumedNum <= maxRequiredRatio;
      if (!hadEnoughConsumables) {
        baseInputItemsConsumedNum = uint16(maxRequiredRatio);
      }
    }

    // Work out what the actual elapsedTime should be had all those been made
    xpElapsedTime = (uint256(baseInputItemsConsumedNum) * 3600 * RATE_MUL) / actionChoice.rate;
  }

  function _getBoostedTime(
    uint256 actionStartTime,
    uint256 elapsedTime,
    uint40 boostStartTime,
    uint24 boostDuration
  ) internal pure returns (uint24 boostedTime) {
    // Calculate time overlap between action and boost periods
    uint256 actionEndTime = actionStartTime + elapsedTime;
    uint256 boostEndTime = boostStartTime + boostDuration;

    // If there's no overlap or no elapsed time, boosted time is 0
    if (actionStartTime >= boostEndTime || actionEndTime <= boostStartTime || elapsedTime == 0) {
      boostedTime = 0;
    } else {
      // Calculate overlap using max of start times and min of end times
      uint256 overlapStart = actionStartTime > boostStartTime ? actionStartTime : boostStartTime;
      uint256 overlapEnd = actionEndTime < boostEndTime ? actionEndTime : boostEndTime;
      boostedTime = uint24(overlapEnd - overlapStart);
    }
  }

  function getBoostedTime(
    uint256 actionStartTime,
    uint256 elapsedTime,
    uint40 boostStartTime,
    uint24 boostDuration
  ) external pure returns (uint24) {
    return _getBoostedTime(actionStartTime, elapsedTime, boostStartTime, boostDuration);
  }

  function _getXPFromBoostImpl(
    bool isCombatSkill,
    uint256 actionStartTime,
    uint256 xpElapsedTime,
    uint24 xpPerHour,
    BoostType boostType,
    uint40 boostStartTime,
    uint24 boostDuration,
    uint16 boostValue
  ) private pure returns (uint32 boostPointsAccrued) {
    if (
      boostType == BoostType.ANY_XP ||
      (isCombatSkill && boostType == BoostType.COMBAT_XP) ||
      (!isCombatSkill && boostType == BoostType.NON_COMBAT_XP)
    ) {
      uint256 boostedTime = _getBoostedTime(actionStartTime, xpElapsedTime, boostStartTime, boostDuration);
      boostPointsAccrued = uint32((boostedTime * xpPerHour * boostValue) / (3600 * 100));
    }
  }

  function _getXPFromBoost(
    bool isCombatSkill,
    uint256 actionStartTime,
    uint256 xpElapsedTime,
    uint24 xpPerHour,
    PlayerBoostInfo storage boostInfo
  ) private view returns (uint32 boostPointsAccrued) {
    if (boostInfo.itemTokenId != NONE && boostInfo.startTime < block.timestamp && xpElapsedTime != 0) {
      // A boost is active
      return
        _getXPFromBoostImpl(
          isCombatSkill,
          actionStartTime,
          xpElapsedTime,
          xpPerHour,
          boostInfo.boostType,
          boostInfo.startTime,
          boostInfo.duration,
          boostInfo.value
        );
    }
  }

  function _getXPFromExtraOrLastBoost(
    bool isCombatSkill,
    uint256 actionStartTime,
    uint256 xpElapsedTime,
    uint24 xpPerHour,
    PlayerBoostInfo storage boostInfo
  ) private view returns (uint32 boostPointsAccrued) {
    if (
      boostInfo.extraOrLastItemTokenId != NONE && boostInfo.extraOrLastStartTime < block.timestamp && xpElapsedTime != 0
    ) {
      // An extra boost is active or an overriden one was active at this time
      return
        _getXPFromBoostImpl(
          isCombatSkill,
          actionStartTime,
          xpElapsedTime,
          xpPerHour,
          boostInfo.extraOrLastBoostType,
          boostInfo.extraOrLastStartTime,
          boostInfo.extraOrLastDuration,
          boostInfo.extraOrLastValue
        );
    }
  }

  function _extraBoostFromFullAttire(
    uint16[] memory itemTokenIds,
    uint256[] memory balances,
    uint16[5] calldata expectedItemTokenIds
  ) private pure returns (bool matches) {
    // Check if they have the full equipment required
    if (itemTokenIds.length == 5) {
      for (uint256 i; i < 5; ++i) {
        if (itemTokenIds[i] != expectedItemTokenIds[i] || balances[i] == 0) {
          return false;
        }
      }
      return true;
    }
  }

  function subtractMatchingRewards(
    uint256[] calldata newIds,
    uint256[] calldata newAmounts,
    uint256[] calldata prevNewIds,
    uint256[] calldata prevNewAmounts
  ) external pure returns (uint256[] memory ids, uint256[] memory amounts) {
    // Subtract previous rewards. If amount is zero after, replace with end and reduce the array size
    ids = newIds;
    amounts = newAmounts;
    uint256 prevNewIdsLength = prevNewIds.length;
    for (uint256 i; i < prevNewIdsLength; ++i) {
      uint16 prevNewId = uint16(prevNewIds[i]);
      uint24 prevNewAmount = uint24(prevNewAmounts[i]);
      uint256 length = ids.length;
      for (uint256 j = 0; j < length; ++j) {
        if (ids[j] == prevNewId) {
          amounts[j] -= prevNewAmount;
          if (amounts[j] == 0) {
            ids[j] = ids[ids.length - 1];
            amounts[j] = amounts[amounts.length - 1];

            assembly ("memory-safe") {
              mstore(ids, length)
              mstore(amounts, length)
            }
            --length;
          }
          break;
        }
      }
    }
  }

  function _readXP(Skill skill, PackedXP storage packedXP) internal view returns (uint256) {
    require(!skill._isSkillCombat() && !skill._isSkill(Skill.TRAVELING), InvalidXPSkill());
    if (skill._isSkillNone()) {
      return 0;
    }
    uint256 offset = 2; // Accounts for NONE & COMBAT meta-skills
    uint256 val = uint8(skill) - offset;
    uint256 slotNum = val / 6;
    uint256 relativePos = val % 6;

    uint256 slotVal;
    assembly ("memory-safe") {
      slotVal := sload(add(packedXP.slot, slotNum))
    }

    return uint40(slotVal >> (relativePos * 40));
  }

  function readXP(Skill skill, PackedXP storage packedXP) external view returns (uint256) {
    return _readXP(skill, packedXP);
  }

  function getCombatStatsFromHero(
    PendingQueuedActionProcessed calldata pendingQueuedActionProcessed,
    PackedXP storage packedXP
  ) external view returns (CombatStats memory combatStats) {
    combatStats.meleeAttack = int16(
      _getLevel(_getAbsoluteActionStartXP(Skill.MELEE, pendingQueuedActionProcessed, packedXP))
    );
    combatStats.rangedAttack = int16(
      _getLevel(_getAbsoluteActionStartXP(Skill.RANGED, pendingQueuedActionProcessed, packedXP))
    );
    combatStats.magicAttack = int16(
      _getLevel(_getAbsoluteActionStartXP(Skill.MAGIC, pendingQueuedActionProcessed, packedXP))
    );
    combatStats.health = int16(
      _getLevel(_getAbsoluteActionStartXP(Skill.HEALTH, pendingQueuedActionProcessed, packedXP))
    );
    uint16 defenceLevel = _getLevel(_getAbsoluteActionStartXP(Skill.DEFENCE, pendingQueuedActionProcessed, packedXP));
    combatStats.meleeDefence = int16(defenceLevel);
    combatStats.rangedDefence = int16(defenceLevel);
    combatStats.magicDefence = int16(defenceLevel);
  }

  function updateCombatStatsFromAttire(
    CombatStats memory combatStats,
    address itemNFT,
    Attire storage attire,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) external view returns (CombatStats memory statsOut) {
    statsOut = combatStats;
    bool skipNonFullAttire;
    (uint16[] memory itemTokenIds, uint256[] memory balances) = getAttireWithBalance(
      attire,
      skipNonFullAttire,
      pendingQueuedActionEquipmentStates,
      checkpointEquipments
    );
    if (itemTokenIds.length != 0) {
      Item[] memory items = IItemNFT(itemNFT).getItems(itemTokenIds);
      for (uint256 i = 0; i < items.length; ++i) {
        if (balances[i] != 0) {
          _updateCombatStatsFromItem(statsOut, items[i]);
        }
      }
    }
  }

  // none of the combat stats are allowed to be negative at this point
  function updateCombatStatsFromPet(
    CombatStats memory combatStats,
    uint8 skillEnhancement1,
    uint8 skillFixedEnhancement1,
    uint8 skillPercentageEnhancement1,
    uint8 skillEnhancement2,
    uint8 skillFixedEnhancement2,
    uint8 skillPercentageEnhancement2
  ) external pure returns (CombatStats memory statsOut) {
    statsOut = combatStats;
    Skill skill1 = skillEnhancement1._asSkill();
    if (skill1 == Skill.HEALTH) {
      statsOut.health += int16(skillFixedEnhancement1 + (uint16(statsOut.health) * skillPercentageEnhancement1) / 100);
    } else if (skill1 == Skill.MELEE) {
      statsOut.meleeAttack += int16(
        skillFixedEnhancement1 + (uint16(statsOut.meleeAttack) * skillPercentageEnhancement1) / 100
      );
    } else if (skill1 == Skill.RANGED) {
      statsOut.rangedAttack += int16(
        skillFixedEnhancement1 + (uint16(statsOut.rangedAttack) * skillPercentageEnhancement1) / 100
      );
    } else if (skill1 == Skill.MAGIC) {
      statsOut.magicAttack += int16(
        skillFixedEnhancement1 + (uint16(statsOut.magicAttack) * skillPercentageEnhancement1) / 100
      );
    } else if (skill1 == Skill.DEFENCE) {
      statsOut.meleeDefence += int16(
        skillFixedEnhancement1 + (uint16(statsOut.meleeDefence) * skillPercentageEnhancement1) / 100
      );
      statsOut.rangedDefence += int16(
        skillFixedEnhancement1 + (uint16(statsOut.rangedDefence) * skillPercentageEnhancement1) / 100
      );
      statsOut.magicDefence += int16(
        skillFixedEnhancement1 + (uint16(statsOut.magicDefence) * skillPercentageEnhancement1) / 100
      );
    } else {
      revert SkillForPetNotHandledYet();
    }

    Skill skill2 = skillEnhancement2._asSkill();
    if (skill2 != Skill.NONE) {
      if (skill2 == Skill.DEFENCE) {
        statsOut.meleeDefence += int16(
          skillFixedEnhancement2 + (uint16(statsOut.meleeDefence) * skillPercentageEnhancement2) / 100
        );
        statsOut.rangedDefence += int16(
          skillFixedEnhancement2 + (uint16(statsOut.rangedDefence) * skillPercentageEnhancement2) / 100
        );
        statsOut.magicDefence += int16(
          skillFixedEnhancement2 + (uint16(statsOut.magicDefence) * skillPercentageEnhancement2) / 100
        );
      } else {
        revert SkillForPetNotHandledYet();
      }
    }
  }

  // 2 versions of getAttireWithBalance exist, 1 has storage attire and the other has calldata attire. This is to
  // allow more versions of versions to accept storage attire.
  function getAttireWithBalance(
    Attire calldata attire,
    bool skipNonFullAttire,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) public pure returns (uint16[] memory itemTokenIds, uint256[] memory balances) {
    uint256 attireLength;
    itemTokenIds = new uint16[](7);
    if (attire.head != NONE) {
      itemTokenIds[attireLength++] = attire.head;
    }
    if (attire.neck != NONE && !skipNonFullAttire) {
      itemTokenIds[attireLength++] = attire.neck;
    }
    if (attire.body != NONE) {
      itemTokenIds[attireLength++] = attire.body;
    }
    if (attire.arms != NONE) {
      itemTokenIds[attireLength++] = attire.arms;
    }
    if (attire.legs != NONE) {
      itemTokenIds[attireLength++] = attire.legs;
    }
    if (attire.feet != NONE) {
      itemTokenIds[attireLength++] = attire.feet;
    }
    if (attire.ring != NONE && !skipNonFullAttire) {
      itemTokenIds[attireLength++] = attire.ring;
    }

    assembly ("memory-safe") {
      mstore(itemTokenIds, attireLength)
    }

    if (attireLength != 0) {
      balances = getBalancesUsingCheckpoint(itemTokenIds, pendingQueuedActionEquipmentStates, checkpointEquipments);
    }
  }

  function getAttireTokenIds(
    Attire memory attire,
    bool skipNonFullAttire
  ) public pure returns (uint16[] memory itemTokenIds) {
    uint256 attireLength;
    itemTokenIds = new uint16[](7);
    if (attire.head != NONE) {
      itemTokenIds[attireLength++] = attire.head;
    }
    if (attire.neck != NONE && !skipNonFullAttire) {
      itemTokenIds[attireLength++] = attire.neck;
    }
    if (attire.body != NONE) {
      itemTokenIds[attireLength++] = attire.body;
    }
    if (attire.arms != NONE) {
      itemTokenIds[attireLength++] = attire.arms;
    }
    if (attire.legs != NONE) {
      itemTokenIds[attireLength++] = attire.legs;
    }
    if (attire.feet != NONE) {
      itemTokenIds[attireLength++] = attire.feet;
    }
    if (attire.ring != NONE && !skipNonFullAttire) {
      itemTokenIds[attireLength++] = attire.ring;
    }
    assembly ("memory-safe") {
      mstore(itemTokenIds, attireLength)
    }
  }

  function getAttireWithCurrentBalance(
    address from,
    Attire memory attire,
    address itemNFT,
    bool skipNonFullAttire
  ) external view returns (uint16[] memory itemTokenIds, uint256[] memory balances) {
    itemTokenIds = getAttireTokenIds(attire, skipNonFullAttire);
    if (itemTokenIds.length != 0) {
      balances = IItemNFT(itemNFT).balanceOfs(from, itemTokenIds);
    }
  }

  function getAttireWithBalance(
    Attire storage attire,
    bool skipNonFullAttire,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) public pure returns (uint16[] memory itemTokenIds, uint256[] memory balances) {
    itemTokenIds = getAttireTokenIds(attire, skipNonFullAttire);
    if (itemTokenIds.length != 0) {
      balances = getBalancesUsingCheckpoint(itemTokenIds, pendingQueuedActionEquipmentStates, checkpointEquipments);
    }
  }

  // Subtract any existing xp gained from the first in-progress actions and add the new xp gained
  function getAbsoluteActionStartXP(
    uint8 skillId,
    PendingQueuedActionProcessed calldata pendingQueuedActionProcessed,
    PackedXP storage packedXP
  ) public view returns (uint256) {
    return _getAbsoluteActionStartXP(skillId._asSkill(), pendingQueuedActionProcessed, packedXP);
  }

  // Subtract any existing xp gained from the first in-progress actions and add the new xp gained
  function _getAbsoluteActionStartXP(
    Skill skill,
    PendingQueuedActionProcessed calldata pendingQueuedActionProcessed,
    PackedXP storage packedXP
  ) internal view returns (uint256) {
    uint256 xp = _readXP(skill, packedXP);
    if (pendingQueuedActionProcessed.currentAction.skill1 == skill) {
      xp -= pendingQueuedActionProcessed.currentAction.xpGained1;
    } else if (pendingQueuedActionProcessed.currentAction.skill2 == skill) {
      xp -= pendingQueuedActionProcessed.currentAction.xpGained2;
    } else if (pendingQueuedActionProcessed.currentAction.skill3 == skill) {
      xp -= pendingQueuedActionProcessed.currentAction.xpGained3;
    }

    // Add any new xp gained from previous actions now completed that haven't been pushed to the blockchain yet. For instance
    // battling monsters may increase your level so you are stronger for a later queued action.
    for (uint256 i; i < pendingQueuedActionProcessed.skills.length; ++i) {
      if (pendingQueuedActionProcessed.skills[i] == skill) {
        xp += pendingQueuedActionProcessed.xpGainedSkills[i];
      }
    }

    return xp;
  }

  function updateStatsFromHandEquipment(
    address itemNFT,
    uint16[2] calldata handEquipmentTokenIds,
    CombatStats calldata combatStats,
    bool isCombat,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    uint16 handItemTokenIdRangeMin,
    CheckpointEquipments calldata checkpointEquipments
  ) external view returns (bool missingRequiredHandEquipment, CombatStats memory statsOut) {
    statsOut = combatStats;
    for (uint256 i = 0; i < handEquipmentTokenIds.length; ++i) {
      uint16 handEquipmentTokenId = handEquipmentTokenIds[i];
      if (handEquipmentTokenId != NONE) {
        uint256 balance = getBalanceUsingCheckpoint(
          handEquipmentTokenId,
          pendingQueuedActionEquipmentStates,
          checkpointEquipments
        );
        if (balance == 0) {
          // Assume that if the player doesn't have the non-combat item that this action cannot be done or if the action choice required it (e.g range bows)
          if (!isCombat || handItemTokenIdRangeMin != NONE) {
            missingRequiredHandEquipment = true;
          }
        } else if (isCombat) {
          // Update the combat stats
          Item memory item = IItemNFT(itemNFT).getItem(handEquipmentTokenId);
          _updateCombatStatsFromItem(statsOut, item);
        }
      }
    }
  }

  function _updateCombatStatsFromItem(CombatStats memory combatStats, Item memory item) internal pure {
    combatStats.meleeAttack += item.meleeAttack;
    combatStats.rangedAttack += item.rangedAttack;
    combatStats.magicAttack += item.magicAttack;
    combatStats.meleeDefence += item.meleeDefence;
    combatStats.rangedDefence += item.rangedDefence;
    combatStats.magicDefence += item.magicDefence;
    combatStats.health += item.health;
  }

  function getBonusAvatarXPPercent(Player storage player, uint8 skillId) public view returns (uint8 bonusPercent) {
    return _getBonusAvatarXPPercent(player, skillId._asSkill());
  }

  function _getBonusAvatarXPPercent(Player storage player, Skill skill) internal view returns (uint8 bonusPercent) {
    bool hasBonusSkill = player.skillBoosted1 == skill || player.skillBoosted2 == skill;
    if (!hasBonusSkill) {
      return 0;
    }
    bool bothSet = player.skillBoosted1 != Skill.NONE && player.skillBoosted2 != Skill.NONE;
    bonusPercent = bothSet ? 5 : 10;
    // Upgraded characters get double base bonus stats
    bool isUpgraded = uint8(player.packedData >> IS_FULL_MODE_BIT) & 1 == 1;
    bonusPercent = isUpgraded ? bonusPercent * 2 : bonusPercent;
  }

  function _extraFromAvatar(
    Player storage player,
    Skill skill,
    uint256 elapsedTime,
    uint24 xpPerHour
  ) internal view returns (uint32 extraPointsAccrued) {
    uint8 bonusPercent = _getBonusAvatarXPPercent(player, skill);
    extraPointsAccrued = uint32((elapsedTime * xpPerHour * bonusPercent) / (3600 * 100));
  }

  function getPointsAccrued(
    Player storage player,
    QueuedAction storage queuedAction,
    uint256 startTime,
    uint8 skillId,
    uint256 xpElapsedTime,
    Attire storage attire,
    PlayerBoostInfo storage activeBoost,
    PlayerBoostInfo storage globalBoost,
    PlayerBoostInfo storage clanBoost,
    address worldActions,
    uint8 bonusAttirePercent,
    uint16[5] calldata expectedItemTokenIds,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) external view returns (uint32 pointsAccrued, uint32 pointsAccruedExclBaseBoost) {
    Skill skill = skillId._asSkill();
    bool isCombatSkill = queuedAction.combatStyle._isCombatStyle();
    uint24 xpPerHour = IWorldActions(worldActions).getXPPerHour(
      queuedAction.actionId,
      isCombatSkill ? NONE : queuedAction.choiceId
    );
    pointsAccrued = uint32((xpElapsedTime * xpPerHour) / 3600);
    // Normal Player specific boosts
    pointsAccrued += _getXPFromBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, activeBoost);
    pointsAccrued += _getXPFromExtraOrLastBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, activeBoost);
    // Global boost
    pointsAccrued += _getXPFromBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, globalBoost);
    pointsAccrued += _getXPFromExtraOrLastBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, globalBoost);
    // Clan boost
    pointsAccrued += _getXPFromBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, clanBoost);
    pointsAccrued += _getXPFromExtraOrLastBoost(isCombatSkill, startTime, xpElapsedTime, xpPerHour, clanBoost);
    pointsAccrued += _extraXPFromFullAttire(
      attire,
      xpElapsedTime,
      xpPerHour,
      bonusAttirePercent,
      expectedItemTokenIds,
      pendingQueuedActionEquipmentStates,
      checkpointEquipments
    );
    pointsAccruedExclBaseBoost = pointsAccrued;
    pointsAccrued += _extraFromAvatar(player, skill, xpElapsedTime, xpPerHour);
  }

  function _extraXPFromFullAttire(
    Attire storage attire,
    uint256 elapsedTime,
    uint24 xpPerHour,
    uint8 bonusPercent,
    uint16[5] calldata expectedItemTokenIds,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    CheckpointEquipments calldata checkpointEquipments
  ) internal pure returns (uint32 extraPointsAccrued) {
    if (bonusPercent == 0) {
      return 0;
    }
    // Check if they have the full equipment set, if so they can get some bonus
    bool skipNonFullAttire = true;
    (uint16[] memory itemTokenIds, uint256[] memory balances) = getAttireWithBalance(
      attire,
      skipNonFullAttire,
      pendingQueuedActionEquipmentStates,
      checkpointEquipments
    );
    bool hasFullAttire = _extraBoostFromFullAttire(itemTokenIds, balances, expectedItemTokenIds);
    if (hasFullAttire) {
      extraPointsAccrued = uint32((elapsedTime * xpPerHour * bonusPercent) / (3600 * 100));
    }
  }

  function getSuccessPercent(
    uint16 actionId,
    uint8 actionSkillId,
    bool isCombat,
    PendingQueuedActionProcessed calldata pendingQueuedActionProcessed,
    address worldActions,
    uint256 maxSuccessPercentChange,
    PackedXP storage packedXP
  ) external view returns (uint8 successPercent) {
    successPercent = 100;
    (uint8 actionSuccessPercent, uint32 minXP) = IWorldActions(worldActions).getActionSuccessPercentAndMinXP(actionId);
    if (actionSuccessPercent != 100) {
      require(!isCombat, InvalidAction());

      uint256 minLevel = _getLevel(minXP);
      uint256 skillLevel = _getLevel(
        _getAbsoluteActionStartXP(actionSkillId._asSkill(), pendingQueuedActionProcessed, packedXP)
      );
      uint256 extraBoost = skillLevel - minLevel;

      successPercent = uint8(Math.min(maxSuccessPercentChange, actionSuccessPercent + extraBoost));
    }
  }

  function getFullAttireBonusRewardsPercent(
    Attire storage attire,
    PendingQueuedActionEquipmentState[] calldata pendingQueuedActionEquipmentStates,
    uint8 bonusRewardsPercent,
    uint16[5] calldata fullAttireBonusItemTokenIds,
    CheckpointEquipments calldata checkpointEquipments
  ) external pure returns (uint8 fullAttireBonusRewardsPercent) {
    if (bonusRewardsPercent == 0) {
      return 0;
    }

    // Check if they have the full equipment set, if so they can get some bonus
    bool skipNonFullAttire = true;
    (uint16[] memory itemTokenIds, uint256[] memory balances) = getAttireWithBalance(
      attire,
      skipNonFullAttire,
      pendingQueuedActionEquipmentStates,
      checkpointEquipments
    );
    bool hasFullAttire = _extraBoostFromFullAttire(itemTokenIds, balances, fullAttireBonusItemTokenIds);

    if (hasFullAttire) {
      fullAttireBonusRewardsPercent = bonusRewardsPercent;
    }
  }

  function _appendGuaranteedRewards(
    uint256[] memory ids,
    uint256[] memory amounts,
    uint256 elapsedTime,
    ActionRewards memory actionRewards,
    uint16 monstersKilled,
    bool isCombat,
    uint8 successPercent
  ) internal pure returns (uint256 length) {
    length = _appendGuaranteedReward(
      ids,
      amounts,
      elapsedTime,
      actionRewards.guaranteedRewardTokenId1,
      actionRewards.guaranteedRewardRate1,
      length,
      monstersKilled,
      isCombat,
      successPercent
    );
    length = _appendGuaranteedReward(
      ids,
      amounts,
      elapsedTime,
      actionRewards.guaranteedRewardTokenId2,
      actionRewards.guaranteedRewardRate2,
      length,
      monstersKilled,
      isCombat,
      successPercent
    );
    length = _appendGuaranteedReward(
      ids,
      amounts,
      elapsedTime,
      actionRewards.guaranteedRewardTokenId3,
      actionRewards.guaranteedRewardRate3,
      length,
      monstersKilled,
      isCombat,
      successPercent
    );
  }

  function _appendGuaranteedReward(
    uint256[] memory ids,
    uint256[] memory amounts,
    uint256 elapsedTime,
    uint16 rewardTokenId,
    uint24 rewardRate,
    uint256 oldLength,
    uint16 monstersKilled,
    bool isCombat,
    uint8 successPercent
  ) internal pure returns (uint256 length) {
    length = oldLength;
    if (rewardTokenId != NONE) {
      uint256 numRewards;
      if (isCombat) {
        numRewards = (monstersKilled * rewardRate) / GUAR_MUL; // rate is per kill
      } else {
        numRewards = (elapsedTime * rewardRate * successPercent) / (3600 * GUAR_MUL * 100);
      }

      if (numRewards != 0) {
        ids[length] = rewardTokenId;
        amounts[length] = numRewards;
        length++;
      }
    }
  }
}

File 2 of 14 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

import {Panic} from "../Panic.sol";
import {SafeCast} from "./SafeCast.sol";

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an success flag (no overflow).
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

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

    /**
     * @dev Returns the multiplication of two unsigned integers, with an success flag (no overflow).
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool success, uint256 result) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

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

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

    /**
     * @dev Branchless ternary evaluation for `a ? b : c`. Gas costs are constant.
     *
     * IMPORTANT: This function may reduce bytecode size and consume less gas when used standalone.
     * However, the compiler may optimize Solidity ternary operations (i.e. `a ? b : c`) to only compute
     * one branch when needed, making this function more expensive.
     */
    function ternary(bool condition, uint256 a, uint256 b) internal pure returns (uint256) {
        unchecked {
            // branchless ternary works because:
            // b ^ (a ^ b) == a
            // b ^ 0 == b
            return b ^ ((a ^ b) * SafeCast.toUint(condition));
        }
    }

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

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return ternary(a < b, a, b);
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }

        // The following calculation ensures accurate ceiling division without overflow.
        // Since a is non-zero, (a - 1) / b will not overflow.
        // The largest possible result occurs when (a - 1) / b is type(uint256).max,
        // but the largest value we can obtain is type(uint256).max - 1, which happens
        // when a = type(uint256).max and b = 1.
        unchecked {
            return SafeCast.toUint(a > 0) * ((a - 1) / b + 1);
        }
    }

    /**
     * @dev Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     *
     * Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2²⁵⁶ and mod 2²⁵⁶ - 1, then use
            // the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2²⁵⁶ + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly ("memory-safe") {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2²⁵⁶. Also prevents denominator == 0.
            if (denominator <= prod1) {
                Panic.panic(ternary(denominator == 0, Panic.DIVISION_BY_ZERO, Panic.UNDER_OVERFLOW));
            }

            ///////////////////////////////////////////////
            // 512 by 256 division.
            ///////////////////////////////////////////////

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly ("memory-safe") {
                // 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 ("memory-safe") {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2²⁵⁶ / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2²⁵⁶. Now that denominator is an odd number, it has an inverse modulo 2²⁵⁶ such
            // that denominator * inv ≡ 1 mod 2²⁵⁶. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv ≡ 1 mod 2⁴.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2¹⁶
            inverse *= 2 - denominator * inverse; // inverse mod 2³²
            inverse *= 2 - denominator * inverse; // inverse mod 2⁶⁴
            inverse *= 2 - denominator * inverse; // inverse mod 2¹²⁸
            inverse *= 2 - denominator * inverse; // inverse mod 2²⁵⁶

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2²⁵⁶. Since the preconditions guarantee that the outcome is
            // less than 2²⁵⁶, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @dev Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        return mulDiv(x, y, denominator) + SafeCast.toUint(unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0);
    }

    /**
     * @dev Calculate the modular multiplicative inverse of a number in Z/nZ.
     *
     * If n is a prime, then Z/nZ is a field. In that case all elements are inversible, except 0.
     * If n is not a prime, then Z/nZ is not a field, and some elements might not be inversible.
     *
     * If the input value is not inversible, 0 is returned.
     *
     * NOTE: If you know for sure that n is (big) a prime, it may be cheaper to use Fermat's little theorem and get the
     * inverse using `Math.modExp(a, n - 2, n)`. See {invModPrime}.
     */
    function invMod(uint256 a, uint256 n) internal pure returns (uint256) {
        unchecked {
            if (n == 0) return 0;

            // The inverse modulo is calculated using the Extended Euclidean Algorithm (iterative version)
            // Used to compute integers x and y such that: ax + ny = gcd(a, n).
            // When the gcd is 1, then the inverse of a modulo n exists and it's x.
            // ax + ny = 1
            // ax = 1 + (-y)n
            // ax ≡ 1 (mod n) # x is the inverse of a modulo n

            // If the remainder is 0 the gcd is n right away.
            uint256 remainder = a % n;
            uint256 gcd = n;

            // Therefore the initial coefficients are:
            // ax + ny = gcd(a, n) = n
            // 0a + 1n = n
            int256 x = 0;
            int256 y = 1;

            while (remainder != 0) {
                uint256 quotient = gcd / remainder;

                (gcd, remainder) = (
                    // The old remainder is the next gcd to try.
                    remainder,
                    // Compute the next remainder.
                    // Can't overflow given that (a % gcd) * (gcd // (a % gcd)) <= gcd
                    // where gcd is at most n (capped to type(uint256).max)
                    gcd - remainder * quotient
                );

                (x, y) = (
                    // Increment the coefficient of a.
                    y,
                    // Decrement the coefficient of n.
                    // Can overflow, but the result is casted to uint256 so that the
                    // next value of y is "wrapped around" to a value between 0 and n - 1.
                    x - y * int256(quotient)
                );
            }

            if (gcd != 1) return 0; // No inverse exists.
            return ternary(x < 0, n - uint256(-x), uint256(x)); // Wrap the result if it's negative.
        }
    }

    /**
     * @dev Variant of {invMod}. More efficient, but only works if `p` is known to be a prime greater than `2`.
     *
     * From https://en.wikipedia.org/wiki/Fermat%27s_little_theorem[Fermat's little theorem], we know that if p is
     * prime, then `a**(p-1) ≡ 1 mod p`. As a consequence, we have `a * a**(p-2) ≡ 1 mod p`, which means that
     * `a**(p-2)` is the modular multiplicative inverse of a in Fp.
     *
     * NOTE: this function does NOT check that `p` is a prime greater than `2`.
     */
    function invModPrime(uint256 a, uint256 p) internal view returns (uint256) {
        unchecked {
            return Math.modExp(a, p - 2, p);
        }
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m)
     *
     * Requirements:
     * - modulus can't be zero
     * - underlying staticcall to precompile must succeed
     *
     * IMPORTANT: The result is only valid if the underlying call succeeds. When using this function, make
     * sure the chain you're using it on supports the precompiled contract for modular exponentiation
     * at address 0x05 as specified in https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise,
     * the underlying function will succeed given the lack of a revert, but the result may be incorrectly
     * interpreted as 0.
     */
    function modExp(uint256 b, uint256 e, uint256 m) internal view returns (uint256) {
        (bool success, uint256 result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Returns the modular exponentiation of the specified base, exponent and modulus (b ** e % m).
     * It includes a success flag indicating if the operation succeeded. Operation will be marked as failed if trying
     * to operate modulo 0 or if the underlying precompile reverted.
     *
     * IMPORTANT: The result is only valid if the success flag is true. When using this function, make sure the chain
     * you're using it on supports the precompiled contract for modular exponentiation at address 0x05 as specified in
     * https://eips.ethereum.org/EIPS/eip-198[EIP-198]. Otherwise, the underlying function will succeed given the lack
     * of a revert, but the result may be incorrectly interpreted as 0.
     */
    function tryModExp(uint256 b, uint256 e, uint256 m) internal view returns (bool success, uint256 result) {
        if (m == 0) return (false, 0);
        assembly ("memory-safe") {
            let ptr := mload(0x40)
            // | Offset    | Content    | Content (Hex)                                                      |
            // |-----------|------------|--------------------------------------------------------------------|
            // | 0x00:0x1f | size of b  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x20:0x3f | size of e  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x40:0x5f | size of m  | 0x0000000000000000000000000000000000000000000000000000000000000020 |
            // | 0x60:0x7f | value of b | 0x<.............................................................b> |
            // | 0x80:0x9f | value of e | 0x<.............................................................e> |
            // | 0xa0:0xbf | value of m | 0x<.............................................................m> |
            mstore(ptr, 0x20)
            mstore(add(ptr, 0x20), 0x20)
            mstore(add(ptr, 0x40), 0x20)
            mstore(add(ptr, 0x60), b)
            mstore(add(ptr, 0x80), e)
            mstore(add(ptr, 0xa0), m)

            // Given the result < m, it's guaranteed to fit in 32 bytes,
            // so we can use the memory scratch space located at offset 0.
            success := staticcall(gas(), 0x05, ptr, 0xc0, 0x00, 0x20)
            result := mload(0x00)
        }
    }

    /**
     * @dev Variant of {modExp} that supports inputs of arbitrary length.
     */
    function modExp(bytes memory b, bytes memory e, bytes memory m) internal view returns (bytes memory) {
        (bool success, bytes memory result) = tryModExp(b, e, m);
        if (!success) {
            Panic.panic(Panic.DIVISION_BY_ZERO);
        }
        return result;
    }

    /**
     * @dev Variant of {tryModExp} that supports inputs of arbitrary length.
     */
    function tryModExp(
        bytes memory b,
        bytes memory e,
        bytes memory m
    ) internal view returns (bool success, bytes memory result) {
        if (_zeroBytes(m)) return (false, new bytes(0));

        uint256 mLen = m.length;

        // Encode call args in result and move the free memory pointer
        result = abi.encodePacked(b.length, e.length, mLen, b, e, m);

        assembly ("memory-safe") {
            let dataPtr := add(result, 0x20)
            // Write result on top of args to avoid allocating extra memory.
            success := staticcall(gas(), 0x05, dataPtr, mload(result), dataPtr, mLen)
            // Overwrite the length.
            // result.length > returndatasize() is guaranteed because returndatasize() == m.length
            mstore(result, mLen)
            // Set the memory pointer after the returned data.
            mstore(0x40, add(dataPtr, mLen))
        }
    }

    /**
     * @dev Returns whether the provided byte array is zero.
     */
    function _zeroBytes(bytes memory byteArray) private pure returns (bool) {
        for (uint256 i = 0; i < byteArray.length; ++i) {
            if (byteArray[i] != 0) {
                return false;
            }
        }
        return true;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * This method is based on Newton's method for computing square roots; the algorithm is restricted to only
     * using integer operations.
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        unchecked {
            // Take care of easy edge cases when a == 0 or a == 1
            if (a <= 1) {
                return a;
            }

            // In this function, we use Newton's method to get a root of `f(x) := x² - a`. It involves building a
            // sequence x_n that converges toward sqrt(a). For each iteration x_n, we also define the error between
            // the current value as `ε_n = | x_n - sqrt(a) |`.
            //
            // For our first estimation, we consider `e` the smallest power of 2 which is bigger than the square root
            // of the target. (i.e. `2**(e-1) ≤ sqrt(a) < 2**e`). We know that `e ≤ 128` because `(2¹²⁸)² = 2²⁵⁶` is
            // bigger than any uint256.
            //
            // By noticing that
            // `2**(e-1) ≤ sqrt(a) < 2**e → (2**(e-1))² ≤ a < (2**e)² → 2**(2*e-2) ≤ a < 2**(2*e)`
            // we can deduce that `e - 1` is `log2(a) / 2`. We can thus compute `x_n = 2**(e-1)` using a method similar
            // to the msb function.
            uint256 aa = a;
            uint256 xn = 1;

            if (aa >= (1 << 128)) {
                aa >>= 128;
                xn <<= 64;
            }
            if (aa >= (1 << 64)) {
                aa >>= 64;
                xn <<= 32;
            }
            if (aa >= (1 << 32)) {
                aa >>= 32;
                xn <<= 16;
            }
            if (aa >= (1 << 16)) {
                aa >>= 16;
                xn <<= 8;
            }
            if (aa >= (1 << 8)) {
                aa >>= 8;
                xn <<= 4;
            }
            if (aa >= (1 << 4)) {
                aa >>= 4;
                xn <<= 2;
            }
            if (aa >= (1 << 2)) {
                xn <<= 1;
            }

            // We now have x_n such that `x_n = 2**(e-1) ≤ sqrt(a) < 2**e = 2 * x_n`. This implies ε_n ≤ 2**(e-1).
            //
            // We can refine our estimation by noticing that the middle of that interval minimizes the error.
            // If we move x_n to equal 2**(e-1) + 2**(e-2), then we reduce the error to ε_n ≤ 2**(e-2).
            // This is going to be our x_0 (and ε_0)
            xn = (3 * xn) >> 1; // ε_0 := | x_0 - sqrt(a) | ≤ 2**(e-2)

            // From here, Newton's method give us:
            // x_{n+1} = (x_n + a / x_n) / 2
            //
            // One should note that:
            // x_{n+1}² - a = ((x_n + a / x_n) / 2)² - a
            //              = ((x_n² + a) / (2 * x_n))² - a
            //              = (x_n⁴ + 2 * a * x_n² + a²) / (4 * x_n²) - a
            //              = (x_n⁴ + 2 * a * x_n² + a² - 4 * a * x_n²) / (4 * x_n²)
            //              = (x_n⁴ - 2 * a * x_n² + a²) / (4 * x_n²)
            //              = (x_n² - a)² / (2 * x_n)²
            //              = ((x_n² - a) / (2 * x_n))²
            //              ≥ 0
            // Which proves that for all n ≥ 1, sqrt(a) ≤ x_n
            //
            // This gives us the proof of quadratic convergence of the sequence:
            // ε_{n+1} = | x_{n+1} - sqrt(a) |
            //         = | (x_n + a / x_n) / 2 - sqrt(a) |
            //         = | (x_n² + a - 2*x_n*sqrt(a)) / (2 * x_n) |
            //         = | (x_n - sqrt(a))² / (2 * x_n) |
            //         = | ε_n² / (2 * x_n) |
            //         = ε_n² / | (2 * x_n) |
            //
            // For the first iteration, we have a special case where x_0 is known:
            // ε_1 = ε_0² / | (2 * x_0) |
            //     ≤ (2**(e-2))² / (2 * (2**(e-1) + 2**(e-2)))
            //     ≤ 2**(2*e-4) / (3 * 2**(e-1))
            //     ≤ 2**(e-3) / 3
            //     ≤ 2**(e-3-log2(3))
            //     ≤ 2**(e-4.5)
            //
            // For the following iterations, we use the fact that, 2**(e-1) ≤ sqrt(a) ≤ x_n:
            // ε_{n+1} = ε_n² / | (2 * x_n) |
            //         ≤ (2**(e-k))² / (2 * 2**(e-1))
            //         ≤ 2**(2*e-2*k) / 2**e
            //         ≤ 2**(e-2*k)
            xn = (xn + a / xn) >> 1; // ε_1 := | x_1 - sqrt(a) | ≤ 2**(e-4.5)  -- special case, see above
            xn = (xn + a / xn) >> 1; // ε_2 := | x_2 - sqrt(a) | ≤ 2**(e-9)    -- general case with k = 4.5
            xn = (xn + a / xn) >> 1; // ε_3 := | x_3 - sqrt(a) | ≤ 2**(e-18)   -- general case with k = 9
            xn = (xn + a / xn) >> 1; // ε_4 := | x_4 - sqrt(a) | ≤ 2**(e-36)   -- general case with k = 18
            xn = (xn + a / xn) >> 1; // ε_5 := | x_5 - sqrt(a) | ≤ 2**(e-72)   -- general case with k = 36
            xn = (xn + a / xn) >> 1; // ε_6 := | x_6 - sqrt(a) | ≤ 2**(e-144)  -- general case with k = 72

            // Because e ≤ 128 (as discussed during the first estimation phase), we know have reached a precision
            // ε_6 ≤ 2**(e-144) < 1. Given we're operating on integers, then we can ensure that xn is now either
            // sqrt(a) or sqrt(a) + 1.
            return xn - SafeCast.toUint(xn > a / xn);
        }
    }

    /**
     * @dev Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && result * result < a);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 exp;
        unchecked {
            exp = 128 * SafeCast.toUint(value > (1 << 128) - 1);
            value >>= exp;
            result += exp;

            exp = 64 * SafeCast.toUint(value > (1 << 64) - 1);
            value >>= exp;
            result += exp;

            exp = 32 * SafeCast.toUint(value > (1 << 32) - 1);
            value >>= exp;
            result += exp;

            exp = 16 * SafeCast.toUint(value > (1 << 16) - 1);
            value >>= exp;
            result += exp;

            exp = 8 * SafeCast.toUint(value > (1 << 8) - 1);
            value >>= exp;
            result += exp;

            exp = 4 * SafeCast.toUint(value > (1 << 4) - 1);
            value >>= exp;
            result += exp;

            exp = 2 * SafeCast.toUint(value > (1 << 2) - 1);
            value >>= exp;
            result += exp;

            result += SafeCast.toUint(value > 1);
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << result < value);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 10 ** result < value);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        uint256 isGt;
        unchecked {
            isGt = SafeCast.toUint(value > (1 << 128) - 1);
            value >>= isGt * 128;
            result += isGt * 16;

            isGt = SafeCast.toUint(value > (1 << 64) - 1);
            value >>= isGt * 64;
            result += isGt * 8;

            isGt = SafeCast.toUint(value > (1 << 32) - 1);
            value >>= isGt * 32;
            result += isGt * 4;

            isGt = SafeCast.toUint(value > (1 << 16) - 1);
            value >>= isGt * 16;
            result += isGt * 2;

            result += SafeCast.toUint(value > (1 << 8) - 1);
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + SafeCast.toUint(unsignedRoundsUp(rounding) && 1 << (result << 3) < value);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 3 of 14 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }

    /**
     * @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
     */
    function toUint(bool b) internal pure returns (uint256 u) {
        assembly ("memory-safe") {
            u := iszero(iszero(b))
        }
    }
}

File 4 of 14 : Panic.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Panic.sol)

pragma solidity ^0.8.20;

/**
 * @dev Helper library for emitting standardized panic codes.
 *
 * ```solidity
 * contract Example {
 *      using Panic for uint256;
 *
 *      // Use any of the declared internal constants
 *      function foo() { Panic.GENERIC.panic(); }
 *
 *      // Alternatively
 *      function foo() { Panic.panic(Panic.GENERIC); }
 * }
 * ```
 *
 * Follows the list from https://github.com/ethereum/solidity/blob/v0.8.24/libsolutil/ErrorCodes.h[libsolutil].
 *
 * _Available since v5.1._
 */
// slither-disable-next-line unused-state
library Panic {
    /// @dev generic / unspecified error
    uint256 internal constant GENERIC = 0x00;
    /// @dev used by the assert() builtin
    uint256 internal constant ASSERT = 0x01;
    /// @dev arithmetic underflow or overflow
    uint256 internal constant UNDER_OVERFLOW = 0x11;
    /// @dev division or modulo by zero
    uint256 internal constant DIVISION_BY_ZERO = 0x12;
    /// @dev enum conversion error
    uint256 internal constant ENUM_CONVERSION_ERROR = 0x21;
    /// @dev invalid encoding in storage
    uint256 internal constant STORAGE_ENCODING_ERROR = 0x22;
    /// @dev empty array pop
    uint256 internal constant EMPTY_ARRAY_POP = 0x31;
    /// @dev array out of bounds access
    uint256 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
    /// @dev resource error (too large allocation or too large array)
    uint256 internal constant RESOURCE_ERROR = 0x41;
    /// @dev calling invalid internal function
    uint256 internal constant INVALID_INTERNAL_FUNCTION = 0x51;

    /// @dev Reverts with a panic code. Recommended to use with
    /// the internal constants with predefined codes.
    function panic(uint256 code) internal pure {
        assembly ("memory-safe") {
            mstore(0x00, 0x4e487b71)
            mstore(0x20, code)
            revert(0x1c, 0x24)
        }
    }
}

File 5 of 14 : actions.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Skill, Attire, CombatStyle, CombatStats} from "./misc.sol";
import {GuaranteedReward, RandomReward} from "./rewards.sol";

enum ActionQueueStrategy {
  OVERWRITE,
  APPEND,
  KEEP_LAST_IN_PROGRESS
}

struct QueuedActionInput {
  Attire attire;
  uint16 actionId;
  uint16 regenerateId; // Food (combat), maybe something for non-combat later
  uint16 choiceId; // Melee/Ranged/Magic (combat), logs, ore (non-combat)
  uint16 rightHandEquipmentTokenId; // Axe/Sword/bow, can be empty
  uint16 leftHandEquipmentTokenId; // Shield, can be empty
  uint24 timespan; // How long to queue the action for
  uint8 combatStyle; // CombatStyle specific style of combat
  uint40 petId; // id of the pet (can be empty)
}

struct QueuedAction {
  uint16 actionId;
  uint16 regenerateId; // Food (combat), maybe something for non-combat later
  uint16 choiceId; // Melee/Ranged/Magic (combat), logs, ore (non-combat)
  uint16 rightHandEquipmentTokenId; // Axe/Sword/bow, can be empty
  uint16 leftHandEquipmentTokenId; // Shield, can be empty
  uint24 timespan; // How long to queue the action for
  uint24 prevProcessedTime; // How long the action has been processed for previously
  uint24 prevProcessedXPTime; // How much XP has been gained for this action so far
  uint64 queueId; // id of this queued action
  bytes1 packed; // 1st bit is isValid (not used yet), 2nd bit is for hasPet (decides if the 2nd storage slot is read)
  uint8 combatStyle;
  uint24 reserved;
  // Next storage slot
  uint40 petId; // id of the pet (can be empty)
}

// This is only used as an input arg (and events)
struct ActionInput {
  uint16 actionId;
  ActionInfo info;
  GuaranteedReward[] guaranteedRewards;
  RandomReward[] randomRewards;
  CombatStats combatStats;
}

struct ActionInfo {
  uint8 skill;
  bool actionChoiceRequired; // If true, then the user must choose an action choice
  uint24 xpPerHour;
  uint32 minXP;
  uint24 numSpawned; // Mostly for combat, capped respawn rate for xp/drops. Per hour, base 10000
  uint16 handItemTokenIdRangeMin; // Inclusive
  uint16 handItemTokenIdRangeMax; // Inclusive
  uint8 successPercent; // 0-100
  uint8 worldLocation; // 0 is the main starting world
  bool isFullModeOnly;
  bool isAvailable;
  uint16 questPrerequisiteId;
}

uint16 constant ACTIONCHOICE_MELEE_BASIC_SWORD = 1500;
uint16 constant ACTIONCHOICE_MAGIC_SHADOW_BLAST = 2000;
uint16 constant ACTIONCHOICE_RANGED_BASIC_BOW = 3000;

// Allows for 2, 4 or 8 hour respawn time
uint256 constant SPAWN_MUL = 1000;
uint256 constant RATE_MUL = 1000;
uint256 constant GUAR_MUL = 10; // Guaranteeded reward multiplier (1 decimal, allows for 2 hour action times)

uint256 constant MAX_QUEUEABLE_ACTIONS = 3; // Available slots to queue actions

File 6 of 14 : items.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

uint16 constant NONE = 0;

uint16 constant COMBAT_BASE = 2048;
// Melee
uint16 constant SWORD_BASE = COMBAT_BASE;
uint16 constant BRONZE_SWORD = SWORD_BASE;

// Woodcutting (2816 - 3071)
uint16 constant WOODCUTTING_BASE = 2816;
uint16 constant BRONZE_AXE = WOODCUTTING_BASE;

// Firemaking (3328 - 3583)
uint16 constant FIRE_BASE = 3328;
uint16 constant MAGIC_FIRE_STARTER = FIRE_BASE;
uint16 constant FIRE_MAX = FIRE_BASE + 255;

// Fishing (3072 - 3327)
uint16 constant FISHING_BASE = 3072;
uint16 constant NET_STICK = FISHING_BASE;

// Mining (2560 - 2815)
uint16 constant MINING_BASE = 2560;
uint16 constant BRONZE_PICKAXE = MINING_BASE;

// Magic
uint16 constant STAFF_BASE = COMBAT_BASE + 50;
uint16 constant TOTEM_STAFF = STAFF_BASE;

// Ranged
uint16 constant BOW_BASE = COMBAT_BASE + 100;
uint16 constant BASIC_BOW = BOW_BASE;

// Cooked fish
uint16 constant COOKED_FISH_BASE = 11008;
uint16 constant COOKED_FEOLA = COOKED_FISH_BASE + 3;

// Scrolls
uint16 constant SCROLL_BASE = 12032;
uint16 constant SHADOW_SCROLL = SCROLL_BASE;

// Boosts
uint16 constant BOOST_BASE = 12800;
uint16 constant COMBAT_BOOST = BOOST_BASE;
uint16 constant XP_BOOST = BOOST_BASE + 1;
uint16 constant GATHERING_BOOST = BOOST_BASE + 2;
uint16 constant SKILL_BOOST = BOOST_BASE + 3;
uint16 constant ABSENCE_BOOST = BOOST_BASE + 4;
uint16 constant LUCKY_POTION = BOOST_BASE + 5;
uint16 constant LUCK_OF_THE_DRAW = BOOST_BASE + 6;
uint16 constant PRAY_TO_THE_BEARDIE = BOOST_BASE + 7;
uint16 constant PRAY_TO_THE_BEARDIE_2 = BOOST_BASE + 8;
uint16 constant PRAY_TO_THE_BEARDIE_3 = BOOST_BASE + 9;
uint16 constant BOOST_RESERVED_1 = BOOST_BASE + 10;
uint16 constant BOOST_RESERVED_2 = BOOST_BASE + 11;
uint16 constant BOOST_RESERVED_3 = BOOST_BASE + 12;
uint16 constant GO_OUTSIDE = BOOST_BASE + 13;
uint16 constant RAINING_RARES = BOOST_BASE + 14;
uint16 constant CLAN_BOOSTER = BOOST_BASE + 15;
uint16 constant CLAN_BOOSTER_2 = BOOST_BASE + 16;
uint16 constant CLAN_BOOSTER_3 = BOOST_BASE + 17;
uint16 constant BOOST_RESERVED_4 = BOOST_BASE + 18;
uint16 constant BOOST_RESERVED_5 = BOOST_BASE + 19;
uint16 constant BOOST_RESERVED_6 = BOOST_BASE + 20;
uint16 constant BOOST_MAX = 13055;

// Eggs
uint16 constant EGG_BASE = 12544;
uint16 constant SECRET_EGG_1_TIER1 = EGG_BASE;
uint16 constant SECRET_EGG_2_TIER1 = EGG_BASE + 1;
uint16 constant EGG_MAX = 12799;

// Miscs
uint16 constant MISC_BASE = 65535;
uint16 constant RAID_PASS = MISC_BASE - 1;

struct BulkTransferInfo {
  uint256[] tokenIds;
  uint256[] amounts;
  address to;
}

File 7 of 14 : misc.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

enum BoostType {
  NONE,
  ANY_XP,
  COMBAT_XP,
  NON_COMBAT_XP,
  GATHERING,
  ABSENCE,
  PASSIVE_SKIP_CHANCE,
  // Clan wars
  PVP_BLOCK,
  PVP_REATTACK,
  PVP_SUPER_ATTACK,
  // Combat stats
  COMBAT_FIXED
}

struct Equipment {
  uint16 itemTokenId;
  uint24 amount;
}

enum Skill {
  NONE,
  COMBAT, // This is a helper which incorporates all combat skills, attack <-> magic, defence, health etc
  MELEE,
  RANGED,
  MAGIC,
  DEFENCE,
  HEALTH,
  RESERVED_COMBAT,
  MINING,
  WOODCUTTING,
  FISHING,
  SMITHING,
  THIEVING,
  CRAFTING,
  COOKING,
  FIREMAKING,
  FARMING,
  ALCHEMY,
  FLETCHING,
  FORGING,
  RESERVED2,
  RESERVED3,
  RESERVED4,
  RESERVED5,
  RESERVED6,
  RESERVED7,
  RESERVED8,
  RESERVED9,
  RESERVED10,
  RESERVED11,
  RESERVED12,
  RESERVED13,
  RESERVED14,
  RESERVED15,
  RESERVED16,
  RESERVED17,
  RESERVED18,
  RESERVED19,
  RESERVED20,
  TRAVELING // Helper Skill for travelling
}

struct Attire {
  uint16 head;
  uint16 neck;
  uint16 body;
  uint16 arms;
  uint16 legs;
  uint16 feet;
  uint16 ring;
  uint16 reserved1;
}

struct CombatStats {
  // From skill points
  int16 meleeAttack;
  int16 magicAttack;
  int16 rangedAttack;
  int16 health;
  // These include equipment
  int16 meleeDefence;
  int16 magicDefence;
  int16 rangedDefence;
}

enum CombatStyle {
  NONE,
  ATTACK,
  DEFENCE
}

File 8 of 14 : players.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {QueuedAction} from "./actions.sol";
import {Skill, BoostType, CombatStats, Equipment} from "./misc.sol";
import {PlayerQuest} from "./quests.sol";

// 4 bytes for each level. 0x00000000 is the first level, 0x00000054 is the second, etc.
bytes constant XP_BYTES = hex"0000000000000054000000AE0000010E00000176000001E60000025E000002DE00000368000003FD0000049B00000546000005FC000006C000000792000008730000096400000A6600000B7B00000CA400000DE100000F36000010A200001229000013CB0000158B0000176B0000196E00001B9400001DE20000205A000022FF000025D5000028DD00002C1E00002F99000033540000375200003B9A000040300000451900004A5C00004FFF0000560900005C810000637000006ADD000072D100007B570000847900008E42000098BE0000A3F90000B0020000BCE70000CAB80000D9860000E9630000FA6200010C990001201D0001350600014B6F0001637300017D2E000198C10001B64E0001D5F80001F7E600021C430002433B00026CFD000299BE0002C9B30002FD180003342B00036F320003AE730003F23D00043AE3000488BE0004DC2F0005359B000595700005FC2400066A360006E02D00075E990007E6160008774C000912EB0009B9B4000A6C74000B2C06000BF956000CD561000DC134000EBDF3000FCCD40010EF2400122648001373BF0014D9230016582C0017F2B00019AAA9001B8234001D7B95001F99390021DDBC00244BE60026E6B60029B15F002CAF51002FE43A0033540D00370303003AF5A4003F30CC0043B9B0004895E3004DCB600053609100595C53005FC6030066A585006E034D0075E86C007E5E980087703B0091287D009B935300A6BD8F00B2B4EE00BF882800CD470500DC026F00EBCC8500FCB8B7010EDBD5";
uint256 constant MAX_LEVEL = 140; // Original max level
uint256 constant MAX_LEVEL_1 = 160; // TODO: Update later
uint256 constant MAX_LEVEL_2 = 190; // TODO: Update later

enum EquipPosition {
  NONE,
  HEAD,
  NECK,
  BODY,
  ARMS,
  LEGS,
  FEET,
  RING,
  SPARE2,
  LEFT_HAND,
  RIGHT_HAND,
  BOTH_HANDS,
  QUIVER,
  MAGIC_BAG,
  FOOD,
  AUX, // wood, seeds  etc..
  BOOST_VIAL,
  EXTRA_BOOST_VIAL,
  GLOBAL_BOOST_VIAL,
  CLAN_BOOST_VIAL,
  PASSIVE_BOOST_VIAL,
  LOCKED_VAULT,
  TERRITORY
}

struct Player {
  uint40 currentActionStartTimestamp; // The in-progress start time of the first queued action
  Skill currentActionProcessedSkill1; // The skill that the queued action has already gained XP in
  uint24 currentActionProcessedXPGained1; // The amount of XP that the queued action has already gained
  Skill currentActionProcessedSkill2;
  uint24 currentActionProcessedXPGained2;
  Skill currentActionProcessedSkill3;
  uint24 currentActionProcessedXPGained3;
  uint16 currentActionProcessedFoodConsumed;
  uint16 currentActionProcessedBaseInputItemsConsumedNum; // e.g scrolls, crafting materials etc
  Skill skillBoosted1; // The first skill that is boosted
  Skill skillBoosted2; // The second skill that is boosted (if applicable)
  uint48 totalXP;
  uint16 totalLevel; // Doesn't not automatically add new skills to it
  bytes1 packedData; // Contains worldLocation in first 6 bits (0 is the main starting randomnessBeacon), and full mode unlocked in the upper most bit
  // TODO: Can be up to 7
  QueuedAction[] actionQueue;
  string name; // Raw name
}

struct Item {
  EquipPosition equipPosition;
  bytes1 packedData; // 0x1 exists, upper most bit is full mode
  uint16 questPrerequisiteId;
  // Can it be transferred?
  bool isTransferable; // TODO: Move into packedData
  // Food
  uint16 healthRestored;
  // Boost vial
  BoostType boostType;
  uint16 boostValue; // Varies, could be the % increase
  uint24 boostDuration; // How long the effect of the boost last
  // Combat stats
  int16 meleeAttack;
  int16 magicAttack;
  int16 rangedAttack;
  int16 meleeDefence;
  int16 magicDefence;
  int16 rangedDefence;
  int16 health;
  // Minimum requirements in this skill to use this item (can be NONE)
  Skill skill;
  uint32 minXP;
}

// Used for events
struct BoostInfo {
  uint40 startTime;
  uint24 duration;
  uint16 value;
  uint16 itemTokenId; // Get the effect of it
  BoostType boostType;
}

struct PlayerBoostInfo {
  uint40 startTime;
  uint24 duration;
  uint16 value;
  uint16 itemTokenId; // Get the effect of it
  BoostType boostType;
  // Another boost slot (for global/clan boosts this is the "last", for users it is the "extra")
  uint40 extraOrLastStartTime;
  uint24 extraOrLastDuration;
  uint16 extraOrLastValue;
  uint16 extraOrLastItemTokenId;
  BoostType extraOrLastBoostType;
  uint40 cooldown; // Just put here for packing
}

// This is effectively a ratio to produce 1 of outputTokenId.
// Available choices that can be undertaken for an action
struct ActionChoiceInput {
  uint8 skill; // Skill that this action choice is related to
  uint24 rate; // Rate of output produced per hour (base 1000) 3 decimals
  uint24 xpPerHour;
  uint16[] inputTokenIds;
  uint24[] inputAmounts;
  uint16 outputTokenId;
  uint8 outputAmount;
  uint8 successPercent; // 0-100
  uint16 handItemTokenIdRangeMin; // Inclusive
  uint16 handItemTokenIdRangeMax; // Inclusive
  bool isFullModeOnly;
  bool isAvailable;
  uint16 questPrerequisiteId;
  uint8[] skills; // Skills required to do this action choice
  uint32[] skillMinXPs; // Min XP in the corresponding skills to be able to do this action choice
  int16[] skillDiffs; // How much the skill is increased/decreased by this action choice
}

struct ActionChoice {
  uint8 skill; // Skill that this action choice is related to
  uint24 rate; // Rate of output produced per hour (base 1000) 3 decimals
  uint24 xpPerHour;
  uint16 inputTokenId1;
  uint24 inputAmount1;
  uint16 inputTokenId2;
  uint24 inputAmount2;
  uint16 inputTokenId3;
  uint24 inputAmount3;
  uint16 outputTokenId;
  uint8 outputAmount;
  uint8 successPercent; // 0-100
  uint8 skill1; // Skills required to do this action choice, commonly the same as skill
  uint32 skillMinXP1; // Min XP in the skill to be able to do this action choice
  int16 skillDiff1; // How much the skill is increased/decreased by this action choice
  uint8 skill2;
  uint32 skillMinXP2;
  int16 skillDiff2;
  uint8 skill3;
  uint32 skillMinXP3;
  int16 skillDiff3;
  uint16 handItemTokenIdRangeMin; // Inclusive
  uint16 handItemTokenIdRangeMax; // Inclusive
  uint16 questPrerequisiteId;
  // FullMode is last bit, first 6 bits is worldLocation,
  // 2nd last bit is if there are other skills in next storage slot to check,
  // 3rd last bit if the input amounts should be used
  bytes1 packedData;
}

// Must be in the same order as Skill enum
struct PackedXP {
  uint40 melee;
  uint40 ranged;
  uint40 magic;
  uint40 defence;
  uint40 health;
  uint40 reservedCombat;
  bytes2 packedDataIsMaxed; // 2 bits per skill to indicate whether the maxed skill is reached. I think this was added in case we added a new max level which a user had already passed so old & new levels are the same and it would not trigger a level up event.
  // Next slot
  uint40 mining;
  uint40 woodcutting;
  uint40 fishing;
  uint40 smithing;
  uint40 thieving;
  uint40 crafting;
  bytes2 packedDataIsMaxed1; // 2 bits per skill to indicate whether the maxed skill is reached
  // Next slot
  uint40 cooking;
  uint40 firemaking;
  uint40 farming;
  uint40 alchemy;
  uint40 fletching;
  uint40 forging;
  bytes2 packedDataIsMaxed2; // 2 bits per skill to indicate whether the maxed skill is reached
}

struct AvatarInfo {
  string name;
  string description;
  string imageURI;
  Skill[2] startSkills; // Can be NONE
}

struct PastRandomRewardInfo {
  uint16 itemTokenId;
  uint24 amount;
  uint64 queueId;
}

struct PendingQueuedActionEquipmentState {
  uint256[] consumedItemTokenIds;
  uint256[] consumedAmounts;
  uint256[] producedItemTokenIds;
  uint256[] producedAmounts;
}

struct PendingQueuedActionMetadata {
  uint32 xpGained; // total xp gained
  uint32 rolls;
  bool died;
  uint16 actionId;
  uint64 queueId;
  uint24 elapsedTime;
  uint24 xpElapsedTime;
  uint8 checkpoint;
}

struct PendingQueuedActionData {
  // The amount of XP that the queued action has already gained
  Skill skill1;
  uint24 xpGained1;
  Skill skill2; // Most likely health
  uint24 xpGained2;
  Skill skill3; // Could come
  uint24 xpGained3;
  // How much food is consumed in the current action so far
  uint16 foodConsumed;
  // How many base consumables are consumed in the current action so far
  uint16 baseInputItemsConsumedNum;
}

struct PendingQueuedActionProcessed {
  // XP gained during this session
  Skill[] skills;
  uint32[] xpGainedSkills;
  // Data for the current action which has been previously processed, this is used to store on the Player
  PendingQueuedActionData currentAction;
}

struct QuestState {
  uint256[] consumedItemTokenIds;
  uint256[] consumedAmounts;
  uint256[] rewardItemTokenIds;
  uint256[] rewardAmounts;
  PlayerQuest[] activeQuestInfo;
  uint256[] questsCompleted;
  Skill[] skills; // Skills gained XP in
  uint32[] xpGainedSkills; // XP gained in these skills
}

struct LotteryWinnerInfo {
  uint16 lotteryId;
  uint24 raffleId;
  uint16 itemTokenId;
  uint16 amount;
  bool instantConsume;
  uint64 playerId;
}

struct PendingQueuedActionState {
  // These 2 are in sync. Separated to reduce gas/deployment costs as these are passed down many layers.
  PendingQueuedActionEquipmentState[] equipmentStates;
  PendingQueuedActionMetadata[] actionMetadatas;
  QueuedAction[] remainingQueuedActions;
  PastRandomRewardInfo[] producedPastRandomRewards;
  uint256[] xpRewardItemTokenIds;
  uint256[] xpRewardAmounts;
  uint256[] dailyRewardItemTokenIds;
  uint256[] dailyRewardAmounts;
  PendingQueuedActionProcessed processedData;
  bytes32 dailyRewardMask;
  QuestState quests;
  uint256 numPastRandomRewardInstancesToRemove;
  uint8 worldLocation;
  LotteryWinnerInfo lotteryWinner;
}

struct FullAttireBonusInput {
  Skill skill;
  uint8 bonusXPPercent;
  uint8 bonusRewardsPercent; // 3 = 3%
  uint16[5] itemTokenIds; // 0 = head, 1 = body, 2 arms, 3 body, 4 = feet
}

// Contains everything you need to create an item
struct ItemInput {
  CombatStats combatStats;
  uint16 tokenId;
  EquipPosition equipPosition;
  bool isTransferable;
  bool isFullModeOnly;
  bool isAvailable;
  uint16 questPrerequisiteId;
  // Minimum requirements in this skill
  Skill skill;
  uint32 minXP;
  // Food
  uint16 healthRestored;
  // Boost
  BoostType boostType;
  uint16 boostValue; // Varies, could be the % increase
  uint24 boostDuration; // How long the effect of the boost vial last
  // uri
  string metadataURI;
  string name;
}

/* Order head, neck, body, arms, legs, feet, ring, reserved1,
   leftHandEquipment, rightHandEquipment,
   Not used yet: input1, input2,input3, regenerate, reserved2, reserved3 */
struct CheckpointEquipments {
  uint16[16] itemTokenIds;
  uint16[16] balances;
}

struct ActivePlayerInfo {
  uint64 playerId;
  uint40 checkpoint;
  uint24 timespan;
  uint24 timespan1;
  uint24 timespan2;
}

uint8 constant START_LEVEL = 17; // Needs updating when there is a new skill. Only useful for new heroes.

uint256 constant MAX_UNIQUE_TICKETS = 64;
// Used in a bunch of places
uint256 constant IS_FULL_MODE_BIT = 7;

// Passive/Instant/InstantVRF/Actions/ActionChoices/Item action
uint256 constant IS_AVAILABLE_BIT = 6;

// Passive actions
uint256 constant HAS_RANDOM_REWARDS_BIT = 5;

// The rest use world location for first 4 bits

// Queued action
uint256 constant HAS_PET_BIT = 2;
uint256 constant IS_VALID_BIT = 1;

File 9 of 14 : quests.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Skill} from "./misc.sol";

struct QuestInput {
  uint16 dependentQuestId; // The quest that must be completed before this one can be started
  uint16 actionId1; // action to do
  uint16 actionNum1; // how many (up to 65535)
  uint16 actionId2; // another action to do
  uint16 actionNum2; // how many (up to 65535)
  uint16 actionChoiceId; // actionChoice to perform
  uint16 actionChoiceNum; // how many to do (base number), (up to 65535)
  Skill skillReward; // The skill to reward XP to
  uint24 skillXPGained; // The amount of XP to give (up to 65535)
  uint16 rewardItemTokenId1; // Reward an item
  uint16 rewardAmount1; // amount of the reward (up to 65535)
  uint16 rewardItemTokenId2; // Reward another item
  uint16 rewardAmount2; // amount of the reward (up to 65535)
  uint16 burnItemTokenId; // Burn an item
  uint16 burnAmount; // amount of the burn (up to 65535)
  uint16 questId; // Unique id for this quest
  bool isFullModeOnly; // If true this quest requires the user be evolved
  uint8 worldLocation; // 0 is the main starting world
}

struct Quest {
  uint16 dependentQuestId; // The quest that must be completed before this one can be started
  uint16 actionId1; // action to do
  uint16 actionNum1; // how many (up to 65535)
  uint16 actionId2; // another action to do
  uint16 actionNum2; // how many (up to 65535)
  uint16 actionChoiceId; // actionChoice to perform
  uint16 actionChoiceNum; // how many to do (base number), (up to 65535)
  Skill skillReward; // The skill to reward XP to
  uint24 skillXPGained; // The amount of XP to give (up to 65535)
  uint16 rewardItemTokenId1; // Reward an item
  uint16 rewardAmount1; // amount of the reward (up to 65535)
  uint16 rewardItemTokenId2; // Reward another item
  uint16 rewardAmount2; // amount of the reward (up to 65535)
  uint16 burnItemTokenId; // Burn an item
  uint16 burnAmount; // amount of the burn (up to 65535)
  uint16 reserved; // Reserved for future use (previously was questId and cleared)
  bytes1 packedData; // FullMode is last bit, first 6 bits is worldLocation
}

struct PlayerQuest {
  uint32 questId;
  uint16 actionCompletedNum1;
  uint16 actionCompletedNum2;
  uint16 actionChoiceCompletedNum;
  uint16 burnCompletedAmount;
}

uint256 constant QUEST_PURSE_STRINGS = 5; // MAKE SURE THIS MATCHES definitions

File 10 of 14 : rewards.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {BoostType, Equipment} from "./misc.sol";

struct GuaranteedReward {
  uint16 itemTokenId;
  uint16 rate; // num per hour (base 10, 1 decimal) for actions and num per duration for passive actions
}

struct RandomReward {
  uint16 itemTokenId;
  uint16 chance; // out of 65535
  uint8 amount; // out of 255
}

struct PendingRandomReward {
  uint16 actionId;
  uint40 startTime;
  uint24 xpElapsedTime;
  uint16 boostItemTokenId;
  uint24 elapsedTime;
  uint40 boostStartTime; // When the boost was started
  uint24 sentinelElapsedTime;
  // Full equipment at the time this was generated
  uint8 fullAttireBonusRewardsPercent;
  uint64 queueId; // TODO: Could reduce this if more stuff is needed
}

struct ActionRewards {
  uint16 guaranteedRewardTokenId1;
  uint16 guaranteedRewardRate1; // Num per hour base 10 (1 decimal) for actions (Max 6553.5 per hour), num per duration for passive actions
  uint16 guaranteedRewardTokenId2;
  uint16 guaranteedRewardRate2;
  uint16 guaranteedRewardTokenId3;
  uint16 guaranteedRewardRate3;
  // Random chance rewards
  uint16 randomRewardTokenId1;
  uint16 randomRewardChance1; // out of 65535
  uint8 randomRewardAmount1; // out of 255
  uint16 randomRewardTokenId2;
  uint16 randomRewardChance2;
  uint8 randomRewardAmount2;
  uint16 randomRewardTokenId3;
  uint16 randomRewardChance3;
  uint8 randomRewardAmount3;
  uint16 randomRewardTokenId4;
  uint16 randomRewardChance4;
  uint8 randomRewardAmount4;
  // No more room in this storage slot!
}

struct XPThresholdReward {
  uint32 xpThreshold;
  Equipment[] rewards;
}

enum InstantVRFActionType {
  NONE,
  GENERIC,
  FORGING,
  EGG
}

struct InstantVRFActionInput {
  uint16 actionId;
  uint16[] inputTokenIds;
  uint24[] inputAmounts;
  bytes data;
  InstantVRFActionType actionType;
  bool isFullModeOnly;
  bool isAvailable;
  uint16 questPrerequisiteId;
}

struct InstantVRFRandomReward {
  uint16 itemTokenId;
  uint16 chance; // out of 65535
  uint16 amount; // out of 65535
}

uint256 constant MAX_GUARANTEED_REWARDS_PER_ACTION = 3;
uint256 constant MAX_RANDOM_REWARDS_PER_ACTION = 4;
uint256 constant MAX_REWARDS_PER_ACTION = MAX_GUARANTEED_REWARDS_PER_ACTION + MAX_RANDOM_REWARDS_PER_ACTION;
uint256 constant MAX_CONSUMED_PER_ACTION = 3;
uint256 constant MAX_QUEST_REWARDS = 2;

uint256 constant TIER_1_DAILY_REWARD_START_XP = 0;
uint256 constant TIER_2_DAILY_REWARD_START_XP = 7_650;
uint256 constant TIER_3_DAILY_REWARD_START_XP = 33_913;
uint256 constant TIER_4_DAILY_REWARD_START_XP = 195_864;
uint256 constant TIER_5_DAILY_REWARD_START_XP = 784_726;
uint256 constant TIER_6_DAILY_REWARD_START_XP = 2_219_451;

// 4 bytes for each threshold, starts at 500 xp in decimal
bytes constant XP_THRESHOLD_REWARDS = hex"00000000000001F4000003E8000009C40000138800002710000075300000C350000186A00001D4C0000493E0000557300007A120000927C0000B71B0000DBBA0000F424000124F800016E360001B7740001E8480002625A0002932E0002DC6C0003567E0003D0900004C4B40005B8D80006ACFC0007A1200008954400098968000A7D8C000B71B0000C65D4000D59F8000E4E1C0";

File 11 of 14 : IItemNFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Item} from "../globals/players.sol";

interface IItemNFT {
  function balanceOfs(address account, uint16[] memory ids) external view returns (uint256[] memory);

  function balanceOfs10(address account, uint16[10] memory ids) external view returns (uint256[] memory);

  function balanceOf(address account, uint256 id) external view returns (uint256);

  function getItem(uint16 tokenId) external view returns (Item memory);

  function getItems(uint16[] calldata tokenIds) external view returns (Item[] memory);

  function totalSupply(uint256 id) external view returns (uint256); // ERC1155Supply

  function totalSupply() external view returns (uint256); // ERC1155Supply

  function mint(address to, uint256 id, uint256 quantity) external;

  function mintBatch(address to, uint256[] calldata ids, uint256[] calldata quantities) external;

  function burn(address account, uint256 id, uint256 value) external;

  function burnBatch(address account, uint256[] calldata ids, uint256[] calldata values) external;

  function getTimestampFirstMint(uint256 id) external view returns (uint256);

  function exists(uint256 id) external view returns (bool);
}

File 12 of 14 : IWorldActions.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {CombatStats, Skill} from "../globals/misc.sol";
import {ActionChoice} from "../globals/players.sol";
import {ActionRewards} from "../globals/rewards.sol";
import {ActionInfo} from "../globals/actions.sol";

interface IWorldActions {
  function getXPPerHour(uint16 actionId, uint16 actionChoiceId) external view returns (uint24 xpPerHour);

  function getNumSpawn(uint16 actionId) external view returns (uint256 numSpawned);

  function getActionSuccessPercentAndMinXP(uint16 actionId) external view returns (uint8 successPercent, uint32 minXP);

  function getCombatStats(uint16 actionId) external view returns (CombatStats memory stats);

  function getActionChoice(uint16 actionId, uint16 choiceId) external view returns (ActionChoice memory choice);

  function getRewardsHelper(
    uint16 actionId
  ) external view returns (ActionRewards memory, Skill skill, uint256 numSpawned); // , uint8 worldLocation);

  function getSkill(uint256 actionId) external view returns (Skill skill);

  function getActionRewards(uint256 actionId) external view returns (ActionRewards memory);

  function getActionInfo(uint256 actionId) external view returns (ActionInfo memory info);
}

File 13 of 14 : CombatStyleLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {CombatStyle} from "../globals/misc.sol";

library CombatStyleLibrary {
  error InvalidCombatStyleId(uint8 combatStyle);

  function _asCombatStyle(uint8 combatStyle) internal pure returns (CombatStyle) {
    require(
      combatStyle >= uint8(type(CombatStyle).min) && combatStyle <= uint8(type(CombatStyle).max),
      InvalidCombatStyleId(combatStyle)
    );
    return CombatStyle(combatStyle);
  }

  function _isCombatStyle(CombatStyle combatStyle) internal pure returns (bool) {
    return combatStyle != CombatStyle.NONE;
  }

  function _isCombatStyle(uint8 combatStyle) internal pure returns (bool) {
    return _isCombatStyle(_asCombatStyle(combatStyle));
  }
}

File 14 of 14 : SkillLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Skill} from "../globals/misc.sol";

library SkillLibrary {
  error InvalidSkillId(uint8 skill);

  function _asSkill(uint8 skill) internal pure returns (Skill) {
    require(skill >= uint8(type(Skill).min) && skill <= uint8(type(Skill).max), InvalidSkillId(skill));
    return Skill(skill);
  }

  function _isSkill(uint8 skill) internal pure returns (bool) {
    return _isSkill(_asSkill(skill));
  }

  function _isSkill(uint8 skill, Skill check) internal pure returns (bool) {
    return _isSkill(_asSkill(skill), check);
  }

  function _isSkillCombat(uint8 skill) internal pure returns (bool) {
    return _isSkillCombat(_asSkill(skill));
  }

  function _isSkillNone(uint8 skill) internal pure returns (bool) {
    return _isSkillNone(_asSkill(skill));
  }

  function _asUint8(Skill skill) internal pure returns (uint8) {
    return uint8(skill);
  }

  function _isSkill(Skill skill) internal pure returns (bool) {
    return !_isSkill(skill, Skill.NONE);
  }

  function _isSkill(Skill skill, Skill check) internal pure returns (bool) {
    return skill == check;
  }

  function _isSkillCombat(Skill skill) internal pure returns (bool) {
    return _isSkill(skill, Skill.COMBAT);
  }

  function _isSkillNone(Skill skill) internal pure returns (bool) {
    return _isSkill(skill, Skill.NONE);
  }
}

Settings
{
  "evmVersion": "cancun",
  "optimizer": {
    "enabled": true,
    "runs": 9999999,
    "details": {
      "yul": true
    }
  },
  "viaIR": true,
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[],"name":"InvalidAction","type":"error"},{"inputs":[{"internalType":"uint8","name":"combatStyle","type":"uint8"}],"name":"InvalidCombatStyleId","type":"error"},{"inputs":[{"internalType":"uint8","name":"skill","type":"uint8"}],"name":"InvalidSkillId","type":"error"},{"inputs":[],"name":"InvalidXPSkill","type":"error"},{"inputs":[],"name":"SkillForPetNotHandledYet","type":"error"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"itemNFT","type":"address"},{"internalType":"uint256","name":"elapsedTime","type":"uint256"},{"components":[{"internalType":"uint8","name":"skill","type":"uint8"},{"internalType":"uint24","name":"rate","type":"uint24"},{"internalType":"uint24","name":"xpPerHour","type":"uint24"},{"internalType":"uint16","name":"inputTokenId1","type":"uint16"},{"internalType":"uint24","name":"inputAmount1","type":"uint24"},{"internalType":"uint16","name":"inputTokenId2","type":"uint16"},{"internalType":"uint24","name":"inputAmount2","type":"uint24"},{"internalType":"uint16","name":"inputTokenId3","type":"uint16"},{"internalType":"uint24","name":"inputAmount3","type":"uint24"},{"internalType":"uint16","name":"outputTokenId","type":"uint16"},{"internalType":"uint8","name":"outputAmount","type":"uint8"},{"internalType":"uint8","name":"successPercent","type":"uint8"},{"internalType":"uint8","name":"skill1","type":"uint8"},{"internalType":"uint32","name":"skillMinXP1","type":"uint32"},{"internalType":"int16","name":"skillDiff1","type":"int16"},{"internalType":"uint8","name":"skill2","type":"uint8"},{"internalType":"uint32","name":"skillMinXP2","type":"uint32"},{"internalType":"int16","name":"skillDiff2","type":"int16"},{"internalType":"uint8","name":"skill3","type":"uint8"},{"internalType":"uint32","name":"skillMinXP3","type":"uint32"},{"internalType":"int16","name":"skillDiff3","type":"int16"},{"internalType":"uint16","name":"handItemTokenIdRangeMin","type":"uint16"},{"internalType":"uint16","name":"handItemTokenIdRangeMax","type":"uint16"},{"internalType":"uint16","name":"questPrerequisiteId","type":"uint16"},{"internalType":"bytes1","name":"packedData","type":"bytes1"}],"internalType":"struct ActionChoice","name":"actionChoice","type":"tuple"},{"internalType":"uint16","name":"regenerateId","type":"uint16"},{"internalType":"uint256","name":"numSpawnedPerHour","type":"uint256"},{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"combatStats","type":"tuple"},{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"enemyCombatStats","type":"tuple"},{"internalType":"uint8","name":"alphaCombat","type":"uint8"},{"internalType":"uint8","name":"betaCombat","type":"uint8"},{"internalType":"uint8","name":"alphaCombatHealing","type":"uint8"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"}],"name":"determineBattleOutcome","outputs":[{"internalType":"uint256","name":"xpElapsedTime","type":"uint256"},{"internalType":"uint256","name":"combatElapsedTime","type":"uint256"},{"internalType":"uint16","name":"baseInputItemsConsumedNum","type":"uint16"},{"internalType":"uint16","name":"foodConsumed","type":"uint16"},{"internalType":"bool","name":"died","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"int256","name":"attack","type":"int256"},{"internalType":"int256","name":"defence","type":"int256"},{"internalType":"uint8","name":"alphaCombat","type":"uint8"},{"internalType":"uint8","name":"betaCombat","type":"uint8"},{"internalType":"uint256","name":"elapsedTime","type":"uint256"}],"name":"dmg","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"head","type":"uint16"},{"internalType":"uint16","name":"neck","type":"uint16"},{"internalType":"uint16","name":"body","type":"uint16"},{"internalType":"uint16","name":"arms","type":"uint16"},{"internalType":"uint16","name":"legs","type":"uint16"},{"internalType":"uint16","name":"feet","type":"uint16"},{"internalType":"uint16","name":"ring","type":"uint16"},{"internalType":"uint16","name":"reserved1","type":"uint16"}],"internalType":"struct Attire","name":"attire","type":"tuple"},{"internalType":"bool","name":"skipNonFullAttire","type":"bool"}],"name":"getAttireTokenIds","outputs":[{"internalType":"uint16[]","name":"itemTokenIds","type":"uint16[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint16","name":"head","type":"uint16"},{"internalType":"uint16","name":"neck","type":"uint16"},{"internalType":"uint16","name":"body","type":"uint16"},{"internalType":"uint16","name":"arms","type":"uint16"},{"internalType":"uint16","name":"legs","type":"uint16"},{"internalType":"uint16","name":"feet","type":"uint16"},{"internalType":"uint16","name":"ring","type":"uint16"},{"internalType":"uint16","name":"reserved1","type":"uint16"}],"internalType":"struct Attire","name":"attire","type":"tuple"},{"internalType":"bool","name":"skipNonFullAttire","type":"bool"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"},{"components":[{"internalType":"uint16[16]","name":"itemTokenIds","type":"uint16[16]"},{"internalType":"uint16[16]","name":"balances","type":"uint16[16]"}],"internalType":"struct CheckpointEquipments","name":"checkpointEquipments","type":"tuple"}],"name":"getAttireWithBalance","outputs":[{"internalType":"uint16[]","name":"itemTokenIds","type":"uint16[]"},{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"components":[{"internalType":"uint16","name":"head","type":"uint16"},{"internalType":"uint16","name":"neck","type":"uint16"},{"internalType":"uint16","name":"body","type":"uint16"},{"internalType":"uint16","name":"arms","type":"uint16"},{"internalType":"uint16","name":"legs","type":"uint16"},{"internalType":"uint16","name":"feet","type":"uint16"},{"internalType":"uint16","name":"ring","type":"uint16"},{"internalType":"uint16","name":"reserved1","type":"uint16"}],"internalType":"struct Attire","name":"attire","type":"tuple"},{"internalType":"address","name":"itemNFT","type":"address"},{"internalType":"bool","name":"skipNonFullAttire","type":"bool"}],"name":"getAttireWithCurrentBalance","outputs":[{"internalType":"uint16[]","name":"itemTokenIds","type":"uint16[]"},{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"itemId","type":"uint256"},{"internalType":"address","name":"itemNFT","type":"address"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"}],"name":"getBalanceUsingCurrentBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint16[]","name":"itemIds","type":"uint16[]"},{"internalType":"address","name":"itemNFT","type":"address"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"}],"name":"getBalanceUsingCurrentBalances","outputs":[{"internalType":"uint256[]","name":"balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"actionStartTime","type":"uint256"},{"internalType":"uint256","name":"elapsedTime","type":"uint256"},{"internalType":"uint40","name":"boostStartTime","type":"uint40"},{"internalType":"uint24","name":"boostDuration","type":"uint24"}],"name":"getBoostedTime","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"xp","type":"uint256"}],"name":"getLevel","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"itemNFT","type":"address"},{"internalType":"uint256","name":"elapsedTime","type":"uint256"},{"components":[{"internalType":"uint8","name":"skill","type":"uint8"},{"internalType":"uint24","name":"rate","type":"uint24"},{"internalType":"uint24","name":"xpPerHour","type":"uint24"},{"internalType":"uint16","name":"inputTokenId1","type":"uint16"},{"internalType":"uint24","name":"inputAmount1","type":"uint24"},{"internalType":"uint16","name":"inputTokenId2","type":"uint16"},{"internalType":"uint24","name":"inputAmount2","type":"uint24"},{"internalType":"uint16","name":"inputTokenId3","type":"uint16"},{"internalType":"uint24","name":"inputAmount3","type":"uint24"},{"internalType":"uint16","name":"outputTokenId","type":"uint16"},{"internalType":"uint8","name":"outputAmount","type":"uint8"},{"internalType":"uint8","name":"successPercent","type":"uint8"},{"internalType":"uint8","name":"skill1","type":"uint8"},{"internalType":"uint32","name":"skillMinXP1","type":"uint32"},{"internalType":"int16","name":"skillDiff1","type":"int16"},{"internalType":"uint8","name":"skill2","type":"uint8"},{"internalType":"uint32","name":"skillMinXP2","type":"uint32"},{"internalType":"int16","name":"skillDiff2","type":"int16"},{"internalType":"uint8","name":"skill3","type":"uint8"},{"internalType":"uint32","name":"skillMinXP3","type":"uint32"},{"internalType":"int16","name":"skillDiff3","type":"int16"},{"internalType":"uint16","name":"handItemTokenIdRangeMin","type":"uint16"},{"internalType":"uint16","name":"handItemTokenIdRangeMax","type":"uint16"},{"internalType":"uint16","name":"questPrerequisiteId","type":"uint16"},{"internalType":"bytes1","name":"packedData","type":"bytes1"}],"internalType":"struct ActionChoice","name":"actionChoice","type":"tuple"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"}],"name":"getNonCombatAdjustedElapsedTime","outputs":[{"internalType":"uint256","name":"xpElapsedTime","type":"uint256"},{"internalType":"uint16","name":"baseInputItemsConsumedNum","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"newIds","type":"uint256[]"},{"internalType":"uint256[]","name":"newAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"prevNewIds","type":"uint256[]"},{"internalType":"uint256[]","name":"prevNewAmounts","type":"uint256[]"}],"name":"subtractMatchingRewards","outputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"combatStats","type":"tuple"},{"internalType":"uint8","name":"skillEnhancement1","type":"uint8"},{"internalType":"uint8","name":"skillFixedEnhancement1","type":"uint8"},{"internalType":"uint8","name":"skillPercentageEnhancement1","type":"uint8"},{"internalType":"uint8","name":"skillEnhancement2","type":"uint8"},{"internalType":"uint8","name":"skillFixedEnhancement2","type":"uint8"},{"internalType":"uint8","name":"skillPercentageEnhancement2","type":"uint8"}],"name":"updateCombatStatsFromPet","outputs":[{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"statsOut","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"itemNFT","type":"address"},{"internalType":"uint16[2]","name":"handEquipmentTokenIds","type":"uint16[2]"},{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"combatStats","type":"tuple"},{"internalType":"bool","name":"isCombat","type":"bool"},{"components":[{"internalType":"uint256[]","name":"consumedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"consumedAmounts","type":"uint256[]"},{"internalType":"uint256[]","name":"producedItemTokenIds","type":"uint256[]"},{"internalType":"uint256[]","name":"producedAmounts","type":"uint256[]"}],"internalType":"struct PendingQueuedActionEquipmentState[]","name":"pendingQueuedActionEquipmentStates","type":"tuple[]"},{"internalType":"uint16","name":"handItemTokenIdRangeMin","type":"uint16"},{"components":[{"internalType":"uint16[16]","name":"itemTokenIds","type":"uint16[16]"},{"internalType":"uint16[16]","name":"balances","type":"uint16[16]"}],"internalType":"struct CheckpointEquipments","name":"checkpointEquipments","type":"tuple"}],"name":"updateStatsFromHandEquipment","outputs":[{"internalType":"bool","name":"missingRequiredHandEquipment","type":"bool"},{"components":[{"internalType":"int16","name":"meleeAttack","type":"int16"},{"internalType":"int16","name":"magicAttack","type":"int16"},{"internalType":"int16","name":"rangedAttack","type":"int16"},{"internalType":"int16","name":"health","type":"int16"},{"internalType":"int16","name":"meleeDefence","type":"int16"},{"internalType":"int16","name":"magicDefence","type":"int16"},{"internalType":"int16","name":"rangedDefence","type":"int16"}],"internalType":"struct CombatStats","name":"statsOut","type":"tuple"}],"stateMutability":"view","type":"function"}]

Deployed Bytecode

0x6103c06040526004361015610012575f80fd5b5f3560e01c80630148a102146130ef578063022c5b2314613072578063036fec3f1461302d57806303bd944214612fc557806304cd71ef146122885780630e1f49d61461212c57806321982a4914611a1a57806332f20ab0146116f15780633d5905d1146116aa5780635b5cb6d01461143657806364d0d939146111545780637864946d14611055578063845960d514610c9457806386481d4014610c5157806396384bf014610b315780639b61bf921461083f578063ad2ef51114610680578063bfce97f214610616578063c1fce48414610580578063d0f14e44146103b6578063d8fcc08a146103145763decc02fe1461010c575f80fd5b60e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760043561ffff81168091036102fd5761014d613405565b90604435918215158093036102fd576064359267ffffffffffffffff84116102fd576101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc85360301126102fd5760843573ffffffffffffffffffffffffffffffffffffffff81168091036102fd5760a43591604060649560248251809581937f36f15ed700000000000000000000000000000000000000000000000000000000835260048301525afa918215610309575f905f936102b7575b5060ff169060648203610224575b60208660ff60405191168152f35b90919293945061028f5761027560ff9461ffff61026f61026a6020998361025363ffffffff61027b9a16614b5f565b169461026560c4359260040191614211565b614788565b614b5f565b16613cbd565b90614204565b908180821091180218165f80808080610216565b7f4a7f394f000000000000000000000000000000000000000000000000000000005f5260045ffd5b9250506040823d604011610301575b816102d360409383613539565b810103126102fd5781519160ff831683036102fd576102f6602060ff9201613ce7565b9290610208565b5f80fd5b3d91506102c6565b6040513d5f823e3d90fd5b6105007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760243567ffffffffffffffff81116102fd5761035f9036906004016134a2565b906103686133f5565b36610104116102fd576104007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffefc3601126102fd576020926103ab926004356141c8565b60ff60405191168152f35b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576103e8613439565b6024359067ffffffffffffffff82116102fd57366023830112156102fd5781600401356104148161357a565b926104226040519485613539565b8184526024602085019260051b820101903682116102fd57602401915b8183106105655750505061045161345c565b916064359267ffffffffffffffff84116102fd575f826104786104c59636906004016134a2565b93909573ffffffffffffffffffffffffffffffffffffffff6040518099819582947fae5c3a470000000000000000000000000000000000000000000000000000000084526004840161419b565b0392165afa938415610309575f94610541575b508351925f5b8481106104ff57604051602080825281906104fb908201896137ca565b0390f35b8061053061050f60019389613ca9565b5161ffff61051d8489613ca9565b511661052a3688886135fc565b9161439e565b61053a8289613ca9565b52016104de565b61055e9194503d805f833e6105568183613539565b810190614121565b92846104d8565b823561ffff811681036102fd5781526020928301920161043f565b60607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760043560ff811681036102fd576024359067ffffffffffffffff82116102fd576101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc83360301126102fd5760209161060e916102656044359260040191614211565b604051908152f35b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760443564ffffffffff811681036102fd576064359062ffffff821682036102fd5760209161067391602435600435615001565b62ffffff60405191168152f35b6101607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576106b3613439565b6101007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdc3601126102fd57604051906106eb8261351c565b60243561ffff811681036102fd57825260443561ffff811681036102fd57602083015260643561ffff811681036102fd57604083015260843561ffff811681036102fd57606083015260a43561ffff811681036102fd57608083015260c43561ffff811681036102fd5760a083015260e43561ffff811681036102fd5760c08301526101043561ffff811681036102fd5760e0830152610789613415565b61079c61079461380d565b606094613eab565b9182516107b5575b50506104fb60405192839283613854565b829350915f916108099373ffffffffffffffffffffffffffffffffffffffff6040518096819582947fae5c3a470000000000000000000000000000000000000000000000000000000084526004840161419b565b0392165afa908115610309575f91610825575b509082806107a4565b61083991503d805f833e6105568183613539565b8261081c565b6105a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd57610872613439565b366064116102fd5760e07fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126102fd576108ac61380d565b6101643567ffffffffffffffff81116102fd576108cd9036906004016134a2565b9091610184359161ffff83168093036102fd576104007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe5c3601126102fd575f93610915613bee565b5060405191610923836134d3565b6064358060010b81036102fd5783526084358060010b81036102fd57602084015260a4358060010b81036102fd57604084015260c4358060010b81036102fd57606084015260e4358060010b81036102fd576080840152610104358060010b81036102fd5760a0840152610124358060010b81036102fd5760c08401525f5b6002811015610ac45761ffff6109bd8260051b602401614088565b1690816109cf575b60019150016109a2565b856109db848685614f8c565b610a0957909150158015610a00575b6109f7575b6001906109c5565b600196506109ef565b508515156109ea565b610a17575b600191506109c5565b604051917f810de9de00000000000000000000000000000000000000000000000000000000835260048301526102208260248173ffffffffffffffffffffffffffffffffffffffff8d165afa918215610309575f92610a83575b50610a7e60019286614d8b565b610a0e565b91506102203d8111610abd575b610a9a8184613539565b8201610220838203126102fd57610ab6610a7e91600194613cf8565b9250610a71565b503d610a90565b61010087610b2f866040519215158352602083019060c08091805160010b8452602081015160010b6020850152604081015160010b6040850152606081015160010b6060850152608081015160010b608085015260a081015160010b60a0850152015160010b910152565bf35b6104607ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760243580151581036102fd5760443567ffffffffffffffff81116102fd57610b889036906004016134a2565b6104007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126102fd57610c21606093604051610bc58161351c565b61ffff600435548181168352818160101c166020840152818160201c166040840152818160301c166060840152818160401c166080840152818160501c1660a0840152818160601c1660c084015260701c1660e0820152613eab565b918251610c395750506104fb60405192839283613854565b82935090606491610c4993614e7a565b9082806107a4565b60207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576020610c88600435614b5f565b61ffff60405191168152f35b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360161054081126102fd57610100136102fd57610cd06137fd565b6101243567ffffffffffffffff81116102fd57610cf19036906004016134a2565b91906104007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffebc3601126102fd576060925f610100937fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe060405195610d558188613539565b600787520136602087013761ffff610d6b614011565b16611032575b61ffff610d7c614022565b1615158061102a575b61100a575b61ffff610d95614033565b16610fea575b61ffff610da6614044565b16610fca575b61ffff610db7614055565b16610faa575b61ffff610dc8614066565b16610f83575b61ffff610dd9614077565b1615159081610f7a575b50610f53575b808452610e015750506104fb60405192839283613854565b8251929350907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610e4a610e348561357a565b94610e426040519687613539565b80865261357a565b013660208501375f9061014492610344915b60108410610e715750505050509082806107a4565b93959492936010851015610f265761ffff610e908660051b8901614088565b16956010861015610f265761ffff610eac8760051b8601614088565b16935f5b8251811015610f15578861ffff610ec78386613ca9565b511614610ed657600101610eb0565b9096919894600193969850610f02610f099161ffff610ef5858e613ca9565b511661052a36898c6135fc565b9189613ca9565b525b0192939193610e5c565b509590979350600191949650610f0b565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffd5b610f5b614077565b61ffff610f71610f6a84613e7e565b9387613ca9565b91169052610de9565b90501586610de3565b610f8b614066565b61ffff610fa1610f9a85613e7e565b9488613ca9565b91169052610dce565b610fb2614055565b61ffff610fc1610f9a85613e7e565b91169052610dbd565b610fd2614044565b61ffff610fe1610f9a85613e7e565b91169052610dac565b610ff2614033565b61ffff611001610f9a85613e7e565b91169052610d9b565b611012614022565b61ffff611021610f9a85613e7e565b91169052610d8a565b508015610d85565b905061103c614011565b9060019161ffff61104c87613c9c565b91169052610d71565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc360161012081126102fd57610100136102fd576040516110958161351c565b60043561ffff811681036102fd57815260243561ffff811681036102fd57602082015260443561ffff811681036102fd57604082015260643561ffff811681036102fd57606082015260843561ffff811681036102fd57608082015260a43561ffff811681036102fd5760a082015260c43561ffff811681036102fd5760c082015260e43561ffff811681036102fd57816111409160e06104fb94015261113a6137fd565b90613eab565b60405191829160208352602083019061381d565b6105407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5761118836613715565b60e43573ffffffffffffffffffffffffffffffffffffffff81168091036102fd576101243567ffffffffffffffff81116102fd576111ca9036906004016134a2565b916104007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffebc3601126102fd576111fe613bee565b5060609261126f5f6040516112128161351c565b61ffff61010435548181168352818160101c166020840152818160201c166040840152818160301c166060840152818160401c166080840152818160501c1660a0840152818160601c1660c084015260701c1660e0820152613eab565b92835161141d575b505081516112e1575b60e084610b2f604051809260c08091805160010b8452602081015160010b6020850152604081015160010b6040850152606081015160010b6060850152608081015160010b608085015260a081015160010b60a0850152015160010b910152565b611323915f9160405180809581947fdf90046300000000000000000000000000000000000000000000000000000000835260206004840152602483019061381d565b03915afa908115610309575f9161137f575b505f5b8151811015611373578061134e60019285613ca9565b5161135a575b01611338565b61136e6113678285613ca9565b5186614d8b565b611354565b50505060e08280611280565b90503d805f833e6113908183613539565b8101906020818303126102fd5780519067ffffffffffffffff82116102fd570181601f820112156102fd5780516113c68161357a565b926113d46040519485613539565b81845260206102208186019302840101928184116102fd57602001915b838310611402575050505083611335565b6020610220916114128486613cf8565b8152019201916113f1565b61142e929450906101449184614e7a565b918480611277565b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760043567ffffffffffffffff81116102fd576114809036906004016134a2565b9060243567ffffffffffffffff81116102fd576114a19036906004016134a2565b9260443567ffffffffffffffff81116102fd576114c29036906004016134a2565b9390926064359067ffffffffffffffff82116102fd576114f66114ec6114fe9336906004016134a2565b9490953691613592565b963691613592565b935f5b81811061153257611524876104fb886040519384936040855260408501906137ca565b9083820360208501526137ca565b61ffff611540828488613c8c565b351662ffffff611551838688613c8c565b3516908851915f5b83811061156d575b50505050600101611501565b82611578828d613ca9565b511461158657600101611559565b915061159f90611599838b969596613ca9565b51613cbd565b6115a9828a613ca9565b526115b48189613ca9565b51156115c3575b808293611561565b88517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161167d576115f9908a613ca9565b51611604828b613ca9565b5287517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff810190811161167d5761163e611646918a613ca9565b519189613ca9565b52818852818752811561167d577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600192016115bb565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760206103ab6116e96116e4613405565b614211565b600435614ced565b6101a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5761172536613715565b60e4359060ff821682036102fd57610104359160ff83168093036102fd57610124359260ff84168094036102fd5761175b6133e4565b610164359460ff86168096036102fd57610184359360ff85168095036102fd5761178d90611787613bee565b50614211565b60288110156118f3576006810361192057506117d661ffff6117c86117e0956064836117c060608c019788518316613c24565b160490613c3d565b1660010b825160010b613c53565b60010b9052614211565b60288110156118f35780611850575b60e083610b2f604051809260c08091805160010b8452602081015160010b6020850152604081015160010b6040850152606081015160010b6060850152608081015160010b608085015260a081015160010b60a0850152015160010b910152565b6005036118cb576118bf61ffff6117c860e09560808601611886846117c860648261187e8b87518316613c24565b160485613c3d565b60010b905260c086016118a6846117c860648261187e8b87518316613c24565b60010b90526064836117c060a089019788518316613c24565b60010b905282806117ef565b7f4d688627000000000000000000000000000000000000000000000000000000005f5260045ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b6002810361195e575061ffff6119466117e0946064836117c0611954968b518316613c24565b1660010b855160010b613c53565b60010b8452614211565b6003810361198857506117d661ffff6117c86117e0956064836117c060408c019788518316613c24565b600481036119b257506117d661ffff6117c86117e0956064836117c060208c019788518316613c24565b6005036118cb576117d661ffff6117c86117e095608089016119e1846117c860648261187e8b87518316613c24565b60010b905260c08901611a01846117c860648261187e8b87518316613c24565b60010b90526064836117c060a08c019788518316613c24565b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760043567ffffffffffffffff81116102fd5780600401906101407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc82360301126102fd5760243591611a94613bee565b91611aa0846002614494565b6044820135946028861080156102fd575f92600288036120ca57611ad59062ffffff611ace60648801613bde565b1690613cbd565b965b835b611ae38780614734565b9050811015611b8657611b0081611afa8980614734565b90613c8c565b356028811015611b825785611b5557600214611b1f575b600101611ad9565b97611b3189611afa602489018a614734565b359063ffffffff82168092036102fd57600191611b4d91614204565b989050611b17565b6024867f4e487b710000000000000000000000000000000000000000000000000000000081526021600452fd5b8580fd5b508486918861ffff611b978c614b5f565b1660010b8152611ba8866003614494565b9185156102fd575f926003820361206857611bcd9062ffffff611ace60648801613bde565b965b835b611bdb8780614734565b9050811015611c4757611bf281611afa8980614734565b356028811015611b825785611b5557600314611c11575b600101611bd1565b97611c2389611afa602489018a614734565b359063ffffffff82168092036102fd57600191611c3f91614204565b989050611c09565b508486918861ffff611c588c614b5f565b1660010b6040870152611c6c826004614494565b9181156102fd575f926004870361200657611c919062ffffff611ace60648801613bde565b965b835b611c9f8780614734565b9050811015611d0b57611cb681611afa8980614734565b356028811015611b825785611b5557600414611cd5575b600101611c95565b97611ce789611afa602489018a614734565b359063ffffffff82168092036102fd57600191611d0391614204565b989050611ccd565b508486918861ffff611d1c8c614b5f565b1660010b6020830152611d30856006614494565b9186156102fd575f9260068303611fa457611d559062ffffff611ace60648801613bde565b965b835b611d638780614734565b9050811015611dcf57611d7a81611afa8980614734565b356028811015611b825785611b5557600614611d99575b600101611d59565b97611dab89611afa602489018a614734565b359063ffffffff82168092036102fd57600191611dc791614204565b989050611d91565b5092509461ffff611de3611df39398614b5f565b1660010b60608701526005614494565b90156102fd575f94600503611f4357611e169062ffffff611ace60648501613bde565b935b805b611e248480614734565b9050811015611ec157611e3b81611afa8680614734565b356028811015611ebd5782611e9057600514611e5a575b600101611e1a565b94611e6c86611afa6024860187614734565b359063ffffffff82168092036102fd57600191611e8891614204565b959050611e52565b6024837f4e487b710000000000000000000000000000000000000000000000000000000081526021600452fd5b8280fd5b60e08561ffff611ed089614b5f565b1660010b8060808301528060c083015260a0820152610b2f604051809260c08091805160010b8452602081015160010b6020850152604081015160010b6040850152606081015160010b6060850152608081015160010b608085015260a081015160010b60a0850152015160010b910152565b6084820135945060288510156102fd575f94600503611f7657611f709062ffffff611ace60a48501613bde565b93611e18565b935060c481013560288110156102fd5760055f9103611e185793611f709062ffffff611ace60e48501613bde565b6084850135935060288410156102fd575f93600603611fd757611fd19062ffffff611ace60a48801613bde565b96611d57565b9660c4850135935060288410156102fd5760065f9403611d575796611fd19062ffffff611ace60e48801613bde565b6084850135935060288410156102fd575f93600403612039576120339062ffffff611ace60a48801613bde565b96611c93565b9660c4850135935060288410156102fd5760045f9403611c9357966120339062ffffff611ace60e48801613bde565b6084850135935060288410156102fd575f9360030361209b576120959062ffffff611ace60a48801613bde565b96611bcf565b9660c4850135935060288410156102fd5760035f9403611bcf57966120959062ffffff611ace60e48801613bde565b6084850135935060288410156102fd575f936002036120fd576120f79062ffffff611ace60a48801613bde565b96611ad7565b9660c4850135935060288410156102fd5760025f9403611ad757966120f79062ffffff611ace60e48801613bde565b6103a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5761215f613439565b61216761347f565b6103207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126102fd57610384359167ffffffffffffffff83116102fd576121b761ffff9336906004016134a2565b929091846236ee806121d762ffffff6121ce613bcc565b16604435613889565b0416809481612238575b505050505016610e10810290808204610e10148115171561167d576236ee808102918083046103e8149015171561167d5761222b60409262ffffff612224613bcc565b169061389c565b9082519182526020820152f35b73ffffffffffffffffffffffffffffffffffffffff61226561226d9661225d36613962565b9336916135fc565b941692614685565b80821161227e575b808083816121e1565b8291501682612275565b6106007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576122bb613439565b610200526122c761347f565b6102a0526103207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c3601126102fd576103843561036081905261ffff811690036102fd5760e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3c3601126102fd5760405161038052612348610380516134d3565b6103c435600181900b81036102fd5761038051526103e4358060010b81036102fd576020610380510152610404358060010b81036102fd576040610380510152610424358060010b81036102fd576060610380510152610444358060010b81036102fd576080610380510152610464358060010b81036102fd5760a0610380510152610484358060010b81036102fd5760c061038051015260e07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb5c3601126102fd57610584356103a081905260ff811690036102fd576105a43561024081905260ff811690036102fd576105c43560ff811681036102fd576105e43567ffffffffffffffff81116102fd576124619036906004016134a2565b9061246b36613962565b610280526040516101e0526124826101e0516134d3565b6104a435600181900b81036102fd576101e051526104c4358060010b81036102fd5760206101e05101526104e4358060010b81036102fd5760406101e0510152610504358060010b81036102fd5760606101e0510152610524358060010b81036102fd5760806101e0510152610544358060010b81036102fd5760a06101e051015261056435918260010b83036102fd576125269260c06101e051015236916135fc565b610260525f6102c0525f610320525f610340525f610340525f610300526103a43515612f98576103a4356236ee80046103005261256960ff610280515116614211565b60288110156118f35760028103612f12575063ffffffff603c6125b4610380515160010b6125af60806101e051015160010b610300519261024051916103a05191614564565b613889565b0416905b6125c860ff610280515116614211565b60606101e05101519060288110156118f35760028103612e93575061ffff612613610380515160010b60806101e051015160010b5b61024051916103a0519160010b9060010b614564565b911690603c820291808304603c149015171561167d57612632916151cd565b9061ffff60606101e051015116908163ffffffff8516115f14612e70576236ee806126626103a435604435613889565b0490816126c061268f63ffffffff881661268a6103005161ffff60606101e051015116613889565b6151cd565b6126b16126a961269f8584613889565b9461030051613889565b604435613cbd565b90818082109118021882614204565b610320525b6126d28361030051613889565b6102c0525f6102205262ffffff60206102805101511680612d4e575b5061274563ffffffff61271a61272f8261271a61032051610240516103a051610380516101e05161521c565b1660030b606061038051015160010b9061464a565b93610240516103a051610380516101e05161521c565b6102e052606061038051015160010b6101a0525f8160030b135f14612d48578063ffffffff165b5f6101c0525f6102e05160030b135f14612d3e576102e05163ffffffff166101c0525b5f6101808190526101608190526101008190526103605190939061ffff16612c87575b61010051158015612c79575b15612b5f575063ffffffff161515610160525b61016051612815575b60a06040516102c051815261032051602082015261ffff6103405116604082015261ffff610180511660608201526101605115156080820152f35b5f610140526103605161ffff16612aa8575b61284761283e6101405161ffff6101805116613889565b6101a051614549565b610120526128c96128a06128776101e0515160010b61024051906103a05190608061038051015160010b90614564565b61027560406101e051015160010b61024051906103a0519060c061038051015160010b90614564565b61027560206101e051015160010b61024051906103a0519060a061038051015160010b90614564565b60c05261012051603c610120510204603c146101205115171561167d576128f860c051603c61012051026151cd565b8061032051108161032051180218610320526101405115908115612a9a575b5015612a5157505063ffffffff83161115612a3e575061295263ffffffff61295b921661268a6103005161ffff60606101e051015116613889565b6103205161389c565b6129688161030051613889565b6102c05262ffffff6020610280510151169081612989575b808080806127da565b6129ce61299c61ffff9361032051613889565b60016236ee807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff830104019015150290565b90818082119118021816610340526102205161034051116129f1575b8080612980565b61ffff612a266102605173ffffffffffffffffffffffffffffffffffffffff6102a05116610340516102805161020051614685565b806103405110816103405118021816610340526129ea565b612a4c91506103205161389c565b61295b565b9093509150508015612a92578061ffff610180511610612a72575b5061295b565b612a87612a8c9261ffff610180511690613889565b61389c565b81612a6c565b50505f61295b565b5f915060030b131586612917565b6040517f810de9de00000000000000000000000000000000000000000000000000000000815261ffff610360511660048201526102208160248173ffffffffffffffffffffffffffffffffffffffff6102a051165afa908115610309575f91612b1e575b506080015161ffff1661014052612827565b90506102203d8111612b58575b612b358183613539565b8101610220828203126102fd57612b5160809161ffff93613cf8565b9150612b0c565b503d612b2b565b909192505f6101a051135f14612c735763ffffffff6101a051165b60ff8216620f4240029160ff620f4240840491160361167d576064918263ffffffff612ba893169104613889565b04620f42400160e05260e051620f42401161167d5760e05161010051612bd39263ffffffff166152ea565b60a052612bef60e0516101005163ffffffff6101c051166152ea565b90612c0c610260516102a05161ffff6103605116610200516138c0565b60805261ffff60a051115f14612c63576001610160525b6101605115612c535761ffff608051115f14612c485761ffff805b16610180526127d1565b61ffff608051612c3e565b61ffff60a05116610180526127d1565b60805160a0511161016052612c23565b5f612b7a565b5063ffffffff8216156127be565b6040517f810de9de00000000000000000000000000000000000000000000000000000000815261ffff610360511660048201526102208160248173ffffffffffffffffffffffffffffffffffffffff6102a051165afa908115610309575f91612cfd575b506080015161ffff16610100526127b2565b90506102203d8111612d37575b612d148183613539565b8101610220828203126102fd57612d3060809161ffff93613cf8565b9150612ceb565b503d612d0a565b5f6101c05261278f565b5f61276c565b612d6161299c61ffff9261032051613889565b80851181861802181661034052612da06102605173ffffffffffffffffffffffffffffffffffffffff6102a05116610340516102805161020051614685565b6102205261034051612dbf575f6102c052604435610320525b866126ee565b61022051610340511115612db9575090612de590612a8761034051916102205190613889565b90612df38261030051613889565b6102c05261ffff6102205116610340528263ffffffff8616115f14612e5a57612e38826125af63ffffffff881661268a6103005161ffff60606101e051015116613889565b612e51612e4b6126a98561030051613889565b82614204565b61032052612db9565b60443561032052612e6b8285613889565b612db9565b612e7c8360443561389c565b90612e878285613889565b604435610320526126c5565b60038103612ebd575061ffff612613604061038051015160010b60c06101e051015160010b6125fd565b600403612ee55761ffff612613602061038051015160010b60a06101e051015160010b6125fd565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52600160045260245ffd5b60038103612f5a575063ffffffff603c612f52604061038051015160010b6125af60c06101e051015160010b610300519261024051916103a05191614564565b0416906125b8565b600403612ee55763ffffffff603c612f52602061038051015160010b6125af60a06101e051015160010b610300519261024051916103a05191614564565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601260045260245ffd5b60a07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd57602063ffffffff603c61301d6130036133f5565b6125af61300e6133d4565b60843592602435600435614564565b041663ffffffff60405191168152f35b60407ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd5760043560288110156102fd5761060e60209160243590614494565b60807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576130a4613439565b6130ac61345c565b906064359067ffffffffffffffff82116102fd57366023830112156102fd576020926130e561060e9336906024816004013591016135fc565b91602435906138c0565b6106207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126102fd576044356131256133d4565b60843560c4359160e43590610104359461313d613415565b916131466133e4565b36610204116102fd576102043567ffffffffffffffff81116102fd576131709036906004016134a2565b9390926104007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffddc3601126102fd576131a790614211565b98602435549060ff8260e01c16600281116133a95760038110156118f35761ffff6044602092151594855f146133895773ffffffffffffffffffffffffffffffffffffffff5f9b5b846040519d8e9687957f74db3052000000000000000000000000000000000000000000000000000000008752166004860152166024840152165afa9788156103095789975f9961334a575b5087899162ffffff83169c61324f8e84613889565b610e10900463ffffffff166132678286868b8b614253565b613270916138a6565b9061327e9085858a8a6142c6565b613287916138a6565b6132948285858a8a614253565b61329d916138a6565b906132ab90848489896142c6565b6132b4916138a6565b6132c18484848989614253565b6132ca916138a6565b946132d4946142c6565b6132dd916138a6565b946132ea9460a43561433f565b6132f3916138a6565b9261330090600435614ced565b9161330a91613889565b9060ff1661331791613889565b62057e40900463ffffffff1661332d90826138a6565b906040519163ffffffff16825263ffffffff166020820152604090f35b975097506020873d602011613381575b8161336760209383613539565b810103126102fd57889761337b8998613879565b9861323a565b3d915061335a565b73ffffffffffffffffffffffffffffffffffffffff8382861c169b6131ef565b7f95d7346c000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b6064359060ff821682036102fd57565b610144359060ff821682036102fd57565b6044359060ff821682036102fd57565b6024359060ff821682036102fd57565b610124359073ffffffffffffffffffffffffffffffffffffffff821682036102fd57565b6004359073ffffffffffffffffffffffffffffffffffffffff821682036102fd57565b6044359073ffffffffffffffffffffffffffffffffffffffff821682036102fd57565b6024359073ffffffffffffffffffffffffffffffffffffffff821682036102fd57565b9181601f840112156102fd5782359167ffffffffffffffff83116102fd576020808501948460051b0101116102fd57565b60e0810190811067ffffffffffffffff8211176134ef57604052565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b610100810190811067ffffffffffffffff8211176134ef57604052565b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff8211176134ef57604052565b67ffffffffffffffff81116134ef5760051b60200190565b92919061359e8161357a565b936135ac6040519586613539565b602085838152019160051b81019283116102fd57905b8282106135ce57505050565b81358152602091820191016135c2565b9080601f830112156102fd578160206135f993359101613592565b90565b929190926136098461357a565b936136176040519586613539565b602085828152019060051b8201918383116102fd5780915b83831061363d575050505050565b823567ffffffffffffffff81116102fd5782016080818703126102fd57604051916080830183811067ffffffffffffffff8211176134ef57604052813567ffffffffffffffff81116102fd57876136959184016135de565b8352602082013567ffffffffffffffff81116102fd57876136b79184016135de565b6020840152604082013567ffffffffffffffff81116102fd57876136dc9184016135de565b604084015260608201359267ffffffffffffffff84116102fd57613705886020958695016135de565b606082015281520192019161362f565b7ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc60e09101126102fd576040519061374c826134d3565b816004358060010b81036102fd5781526024358060010b81036102fd5760208201526044358060010b81036102fd5760408201526064358060010b81036102fd5760608201526084358060010b81036102fd57608082015260a4358060010b81036102fd5760a082015260c435908160010b82036102fd5760c00152565b90602080835192838152019201905f5b8181106137e75750505090565b82518452602093840193909201916001016137da565b610104359081151582036102fd57565b610144359081151582036102fd57565b90602080835192838152019201905f5b81811061383a5750505090565b825161ffff1684526020938401939092019160010161382d565b909161386b6135f99360408452604084019061381d565b9160208184039101526137ca565b519062ffffff821682036102fd57565b8181029291811591840414171561167d57565b8115612f98570490565b9063ffffffff8091169116019063ffffffff821161167d57565b73ffffffffffffffffffffffffffffffffffffffff60446020929594958260405197889485937efdd58e000000000000000000000000000000000000000000000000000000008552166004840152866024840152165afa8015610309575f9061392e575b6135f9935061439e565b506020833d60201161395a575b8161394860209383613539565b810103126102fd576135f99251613924565b3d915061393b565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9c6103209101126102fd5760405190610320820182811067ffffffffffffffff8211176134ef576040528160643560ff811681036102fd57815260843562ffffff811681036102fd57602082015260a43562ffffff811681036102fd57604082015260c43561ffff811681036102fd57606082015260e43562ffffff811681036102fd5760808201526101043561ffff811681036102fd5760a08201526101243562ffffff811681036102fd5760c08201526101443561ffff811681036102fd5760e08201526101643562ffffff811681036102fd576101008201526101843561ffff811681036102fd576101208201526101a43560ff811681036102fd576101408201526101c43560ff811681036102fd576101608201526101e43560ff811681036102fd576101808201526102043563ffffffff811681036102fd576101a0820152610224358060010b81036102fd576101c08201526102443560ff811681036102fd576101e08201526102643563ffffffff811681036102fd57610200820152610284358060010b81036102fd576102208201526102a43560ff811681036102fd576102408201526102c43563ffffffff811681036102fd576102608201526102e4358060010b81036102fd576102808201526103043561ffff811681036102fd576102a08201526103243561ffff811681036102fd576102c08201526103443561ffff811681036102fd576102e082015261036435907fff00000000000000000000000000000000000000000000000000000000000000821682036102fd576103000152565b60843562ffffff811681036102fd5790565b3562ffffff811681036102fd5790565b60405190613bfb826134d3565b5f60c0838281528260208201528260408201528260608201528260808201528260a08201520152565b9061ffff8091169116029061ffff821691820361167d57565b9061ffff8091169116019061ffff821161167d57565b9060010b9060010b01907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80008212617fff83131761167d57565b9190811015610f265760051b0190565b805115610f265760200190565b8051821015610f265760209160051b010190565b9190820391821161167d57565b519061ffff821682036102fd57565b51908160010b82036102fd57565b519063ffffffff821682036102fd57565b9190826102209103126102fd57604051610220810181811067ffffffffffffffff8211176134ef576040528092805160178110156102fd57825260208101517fff00000000000000000000000000000000000000000000000000000000000000811681036102fd576020830152613d7160408201613cca565b6040830152606081015180151581036102fd576060830152613d9560808201613cca565b608083015260a0810151600b8110156102fd5760a0830152613db960c08201613cca565b60c0830152613dca60e08201613879565b60e0830152613ddc6101008201613cd9565b610100830152613def6101208201613cd9565b610120830152613e026101408201613cd9565b610140830152613e156101608201613cd9565b610160830152613e286101808201613cd9565b610180830152613e3b6101a08201613cd9565b6101a0830152613e4e6101c08201613cd9565b6101c08301526101e08101519060288210156102fd57610200613e799181936101e086015201613ce7565b910152565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff811461167d5760010190565b91905f90610100907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe060405192613ee28185613539565b6007845201366020840137819461ffff81511680613ff5575b5060c08161ffff6020819401511680151580613fed575b613fda575b508260408201511680613fc7575b508260608201511680613fb4575b508260808201511680613fa1575b508260a08201511680613f87575b50015116908115159081613f7e575b50613f67575052565b613f7a613f7384613e7e565b9383613ca9565b5252565b9050155f613f5e565b613f9a613f9388613e7e565b9787613ca9565b525f613f4f565b613fad613f9388613e7e565b525f613f41565b613fc0613f9388613e7e565b525f613f33565b613fd3613f9388613e7e565b525f613f25565b613fe6613f9388613e7e565b525f613f17565b508415613f12565b935060c061ffff9160019561400986613c9c565b529150613efb565b60043561ffff811681036102fd5790565b60243561ffff811681036102fd5790565b60443561ffff811681036102fd5790565b60643561ffff811681036102fd5790565b60843561ffff811681036102fd5790565b60a43561ffff811681036102fd5790565b60c43561ffff811681036102fd5790565b3561ffff811681036102fd5790565b92909391614109600160609561ffff604051916140b38361351c565b548181168352818160101c166020840152818160201c166040840152818160301c166060840152818160401c166080840152818160501c1660a0840152818160601c1660c084015260701c1660e0820152613eab565b94855161411557505050565b6135f993945085614e7a565b6020818303126102fd5780519067ffffffffffffffff82116102fd57019080601f830112156102fd5781516141558161357a565b926141636040519485613539565b81845260208085019260051b8201019283116102fd57602001905b82821061418b5750505090565b815181526020918201910161417e565b60409073ffffffffffffffffffffffffffffffffffffffff6135f99493168152816020820152019061381d565b939291905f9460ff8416156141fb576101046141f0936064936141ea93614097565b9061509b565b6141f75750565b9150565b505f9450505050565b9190820180921161167d57565b60ff16602781116142285760288110156118f35790565b7fe8657d09000000000000000000000000000000000000000000000000000000005f5260045260245ffd5b949394929091925f95549161ffff8360501c161515806142b6575b806142ad575b61427f575050505050565b6135f995965061ffff8360401c169462ffffff8460281c169460ff64ffffffffff86169560601c169361510f565b50841515614274565b504264ffffffffff84161061426e565b949394929091925f95549161ffff8360b81c1615158061432c575b80614323575b6142f2575050505050565b6135f995965061ffff8360a81c169462ffffff8460901c169460ff64ffffffffff8660681c169560c81c169361510f565b508415156142e7565b504264ffffffffff8460681c16106142e1565b93959490929560ff5f97169485156143935761022461436593610164936141ea93614097565b61436e57505050565b63ffffffff939450916125af61438e9262ffffff62057e40951690613889565b041690565b505f96505050505050565b5f92915b825184101561448d576143b58484613ca9565b51905f9360408301945b85518051821015614408576143d5828592613ca9565b51146143e4575b6001016143bf565b936144006001916143f9876060880151613ca9565b5190614204565b9490506143dc565b5050959093505f5b8251805182101561447a57614426828792613ca9565b5114614435575b600101614410565b92836020840191614447828451613ca9565b51811061446e5761445e6144659260019451613ca9565b5190613cbd565b935b905061442d565b50505060015f93614467565b5090956001909501949391506143a29050565b5092915050565b6028811015806118f35760018214158061453c575b15614514576118f357801561450e5760ff16907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe820191821161167d5760068083069204015460288202918083046028149015171561167d5764ffffffffff911c1690565b50505f90565b7f0fe48d07000000000000000000000000000000000000000000000000000000005f5260045ffd5b50505f60278214156144a9565b9190915f838201938412911290801582169115161761167d57565b909291928115614642577f8000000000000000000000000000000000000000000000000000000000000000821461167d5760ff90825f03908082135f1461463a5750935b165f0b81600f0b029283600f0b93840361167d578160011b91820560020361167d57808203925f82128385128116908486139015161761167d5760ff165f0b808402937f800000000000000000000000000000000000000000000000000000000000000082145f82121661167d578405149114171561167d5761462a91614549565b806001135f146135f95750600190565b9050936145a8565b505050505f90565b9060030b9060030b0390637fffffff82137fffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000083121761167d57565b909493929161ffff16948561469b575b50505050565b61ffff60608201511680614714575b5061ffff60a082015116806146f4575b5061ffff60e08201511690816146d1575b50614695565b9062ffffff6101006146e9979894930151169161529a565b905f808080806146cb565b838297869262ffffff60c061470d96015116908661529a565b945f6146ba565b838297869262ffffff608061472d96015116908661529a565b945f6146aa565b9035907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1813603018212156102fd570180359067ffffffffffffffff82116102fd57602001918160051b360383136102fd57565b92916147949084614494565b9260408201359360288510156102fd57602882101594856118f3578203614842576147c99062ffffff611ace60608601613bde565b935b5f5b6147d78480614734565b9050811015614695576147ee81611afa8680614734565b3560288110156102fd57826118f357831461480c575b6001016147cd565b9461481e86611afa6020870187614734565b359063ffffffff82168092036102fd5760019161483a91614204565b959050614804565b6080830135945060288510156102fd575f9482036148745761486e9062ffffff611ace60a08601613bde565b936147cb565b935060c082013560288110156102fd57815f91036147cb579361486e9062ffffff611ace60e08601613bde565b60405190610260820182811067ffffffffffffffff8211176134ef5760405261023082527edc026f00ebcc8500fcb8b7010edbd500000000000000000000000000000000610240837854000000ae0000010e00000176000001e60000025e000002de60208201527d0368000003fd0000049b00000546000005fc000006c0000007920000087360408201527d096400000a6600000b7b00000ca400000de100000f36000010a20000122960608201527d13cb0000158b0000176b0000196e00001b9400001de20000205a000022ff60808201527d25d5000028dd00002c1e00002f99000033540000375200003b9a0000403060a08201527d451900004a5c00004fff0000560900005c810000637000006add000072d160c08201527d7b570000847900008e42000098be0000a3f90000b0020000bce70000cab860e08201527dd9860000e9630000fa6200010c990001201d0001350600014b6f000163736101008201527e017d2e000198c10001b64e0001d5f80001f7e600021c430002433b00026cfd6101208201527e0299be0002c9b30002fd180003342b00036f320003ae730003f23d00043ae36101408201527e0488be0004dc2f0005359b000595700005fc2400066a360006e02d00075e996101608201527e07e6160008774c000912eb0009b9b4000a6c74000b2c06000bf956000cd5616101808201527e0dc134000ebdf3000fccd40010ef2400122648001373bf0014d9230016582c6101a08201527e17f2b00019aaa9001b8234001d7b95001f99390021ddbc00244be60026e6b66101c08201527e29b15f002caf51002fe43a0033540d00370303003af5a4003f30cc0043b9b06101e08201527e4895e3004dcb600053609100595c53005fc6030066a585006e034d0075e86c6102008201527e7e5e980087703b0091287d009b935300a6bd8f00b2b4ee00bf882800cd47056102208201520152565b5f90614b696148a1565b5160021c5b808310614b8a5750508015614b845761ffff1690565b50600190565b614b948184614204565b907ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc8260011c9260011b168281046004148315171561167d577fff00000000000000000000000000000000000000000000000000000000000000614bff82614bfa6148a1565b6152d9565b5116614c096148a1565b600183019081841161167d577eff00000000000000000000000000000000000000000000000000000000000091614c3f916152d9565b5160081c1617614c4d6148a1565b600283019081841161167d577dff000000000000000000000000000000000000000000000000000000000091614c82916152d9565b5160101c1617614c906148a1565b916003810180911161167d57614cc57cff000000000000000000000000000000000000000000000000000000009187946152d9565b5160181c161760e01c1115614cda5750614b6e565b92506001810180911161167d5791614b6e565b549060ff8260a81c169060288110156118f35760288210156118f357808214908115614d72575b501561450e57151580614d5a575b15614d4e57600180806005935b60ff1c1616036135f95760011b6101fe60fe82169116810361167d5790565b60018080600a93614d2f565b5060ff8160b01c1660288110156118f3571515614d22565b905060ff8360b01c1660288110156118f357145f614d14565b9060606101c0614e6292614dab61010082015160010b865160010b613c53565b60010b855261014081015160010b614dcb6040870191825160010b613c53565b60010b905261012081015160010b614deb6020870191825160010b613c53565b60010b905261016081015160010b614e0b6080870191825160010b613c53565b60010b90526101a081015160010b614e2b60c0870191825160010b613c53565b60010b905261018081015160010b614e4b60a0870191825160010b613c53565b60010b9052015160010b920191825160010b613c53565b60010b9052565b906010811015610f265760051b0190565b909392918151907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0614ec4614eae8461357a565b93614ebc6040519586613539565b80855261357a565b0136602084013781955f935b60108510614ee057505050505050565b61ffff614efa614ef587899b9a979899614e69565b614088565b169661ffff614f10614ef5896102008d01614e69565b16945f5b8351811015614f7a578961ffff614f2b8387613ca9565b511614614f3a57600101614f14565b909850614f6f614f68849695989761ffff614f5b85969e9c96600198613ca9565b511661052a36898d6135fc565b9187613ca9565b525b01939091614ed0565b50975097956001919392959450614f71565b5f93926101a49291855b60108110614fa5575050505050565b6010811015610f26578161ffff614fc08360051b8801614088565b1614614fce57600101614f96565b919350919394506010811015610f26576135f99361ffff614ff861052a9360051b6103a401614088565b169336916135fc565b929162ffffff64ffffffffff6150178487614204565b92169316830164ffffffffff811161167d5764ffffffffff169182851090811591615090575b8115615087575b501561505257505050505f90565b62ffffff93615074938082111561507f5750915b808210156150785750613cbd565b1690565b9050613cbd565b905091615066565b9050155f615044565b84831115915061503d565b9291905f9360058151146150ae57505050565b90919293505f5b60058110156151065761ffff6150cb8284613ca9565b511661ffff6150de8360051b8701614088565b16148015906150f4575b614642576001016150b5565b506150ff8184613ca9565b51156150e8565b50505050600190565b5f98979693959394600b81101590816118f357600181149283156151b1575b831561518c575b505050615145575b505050505050565b63ffffffff9697509362ffffff8061516d62057e40989661ffff966151769661517e9a615001565b16911690613889565b911690613889565b0416905f808080808061513d565b15925090826151a0575b50505f8080615135565b9091506118f3576003145f80615196565b925082806151c0575b9261512e565b505f9150600281146151ba565b90801561520a576152026001917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff840161389c565b019015150290565b634e487b715f5260126020526024601cfd5b92846125af82858560a060206152888b63ffffffff603c6135f99f80839f839f9e6152809f916040878761526a615280986125af87878f9a60806125af9c5160010b91015160010b90614564565b041698015160010b60c08d015160010b90614564565b0416906138a6565b9a015160010b91015160010b90614564565b90612a879293959161ffff73ffffffffffffffffffffffffffffffffffffffff6152c797169216906138c0565b90808210156152d4575090565b905090565b908151811015610f26570160200190565b90620f4240820291808304620f4240149015171561167d576135f99261530f91613889565b906151cd56fea264697066735822122037d268954d94f16950e2f2ed9cc03d563e485bfd738b0b84ceaa3ef14bd739a464736f6c634300081c0033

Block Transaction Gas Used Reward
view all blocks produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits

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.