creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/ArexaPlatform/ArexaPlatformFacet.sol": {
        "content": "// SPDX-License-Identifier: UNLICENCED\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { LibBlackWhiteList } from \"../base/BlackWhiteList/LibBlackWhiteList.sol\";\r\n\r\nimport { LibArexaPlatformShared } from \"./Platform/LibArexaPlatformShared.sol\";\r\nimport { LibArexaPlatformSubscriptions } from \"./Platform/LibArexaPlatformSubscriptions.sol\";\r\nimport { LibArexaPlatformT3 } from \"./Platform/LibArexaPlatformT3.sol\";\r\nimport { LibArexaPlatformT4 } from \"./Platform/LibArexaPlatformT4.sol\";\r\nimport { LibArexaPlatformT5 } from \"./Platform/LibArexaPlatformT5.sol\";\r\n\r\nimport { LibERC1155 } from \"../base/ERC1155/base/LibERC1155.sol\";\r\n\r\nimport { CallProtection } from \"../base/Shared/ProtectedCall.sol\";\r\nimport { ReentryProtection } from \"../base/Shared/ReentryProtection.sol\";\r\nimport { ModifierRole } from \"../base/AccessControl/ModifierRole.sol\";\r\nimport { ModifierPausable } from \"../base/TargetedPausable/ModifierPausable.sol\";\r\nimport { LibArexaConst } from \"./LibArexaConst.sol\";\r\n\r\ncontract ArexaPlatformFacet is CallProtection, ReentryProtection, ModifierRole, ModifierPausable {\r\n\tuint256 public constant SUBSCR1_TOKEN_TYPE = LibArexaConst.SUBSCR1_TOKEN_TYPE; //Tier 1, every month\r\n\tuint256 public constant SUBSCR2_TOKEN_TYPE = LibArexaConst.SUBSCR2_TOKEN_TYPE; //Tier 2, every month\r\n\tuint256 public constant TRADER_TOKEN_ID = LibArexaConst.TRADER_TOKEN_ID; //Tier 3, unlimited, always mint\r\n\tuint256 public constant AREXA_TOKEN_ID = LibArexaConst.AREXA_TOKEN_ID; //Tier 4, 100000000 piece\r\n\tuint256 public constant MAGIC_TOKEN_ID = LibArexaConst.MAGIC_TOKEN_ID; //Tier 5, 100 piece\r\n\r\n\tuint8 public constant AREXA_TOKEN_POOL_INVESTOR = LibArexaConst.AREXA_TOKEN_POOL_INVESTOR;\r\n\tuint8 public constant AREXA_TOKEN_POOL_AREXAINC = LibArexaConst.AREXA_TOKEN_POOL_AREXAINC;\r\n\tuint8 public constant AREXA_TOKEN_POOL_MARKETING = LibArexaConst.AREXA_TOKEN_POOL_MARKETING;\r\n\tuint8 public constant AREXA_TOKEN_POOL_DEVELOPMENT = LibArexaConst.AREXA_TOKEN_POOL_DEVELOPMENT;\r\n\tuint8 public constant AREXA_TOKEN_POOL_RESERVED = LibArexaConst.AREXA_TOKEN_POOL_RESERVED;\r\n\r\n\tuint8 public constant AMOUNT_VALUE_TYPE = LibArexaPlatformShared.AMOUNT_VALUE_TYPE;\r\n\tuint8 public constant QUANTITY_VALUE_TYPE = LibArexaPlatformShared.QUANTITY_VALUE_TYPE;\r\n\r\n\tfunction getCurrentSubscriptionTokenId(uint256 tokenType) external view protectedCall returns (uint256) {\r\n\t\treturn LibArexaPlatformSubscriptions.getCurrentSubscriptionTokenId(tokenType);\r\n\t}\r\n\r\n\tfunction calcSubscriptionPrice(uint256 tokenId, uint32 quantity) external view protectedCall returns (uint256) {\r\n\t\treturn LibArexaPlatformSubscriptions.calcSubscriptionPrice(tokenId, quantity);\r\n\t}\r\n\r\n\tfunction buySubscription(uint256 tokenId, uint32 quantity) external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier1 Oracle or Tier2 Edge\r\n\t\t//Price: variable USDT/piece, based on algorithm\r\n\t\t//Quantity: 1 per account\r\n\t\t// uint256 balance = LibERC1155.balanceOf(msg.sender, tokenId);\r\n\t\t// require(balance == 0, \"Only 1 token can be bought per account!\");\r\n\t\tLibArexaPlatformSubscriptions.buySubscription(tokenId, msg.sender, quantity, 0);\r\n\t}\r\n\r\n\tfunction buyOracleSubscription(uint32 quantity) external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier1 Oracle\r\n\t\t//SUBSCR1_TOKEN_TYPE\r\n\t\t//Price: variable USDT/piece, based on algorithm\r\n\t\t//Quantity: 1 per account\r\n\t\tuint256 tokenId = LibArexaPlatformSubscriptions.getCurrentSubscriptionTokenId(SUBSCR1_TOKEN_TYPE);\r\n\t\t// uint256 balance = LibERC1155.balanceOf(msg.sender, tokenId);\r\n\t\t// require(balance == 0, \"Only 1 token can be bought per account!\");\r\n\t\tLibArexaPlatformSubscriptions.buySubscription(tokenId, msg.sender, quantity, 0);\r\n\t}\r\n\r\n\tfunction buyEdgeSubscription(uint32 quantity) external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier2 Edge\r\n\t\t//SUBSCR2_TOKEN_TYPE\r\n\t\t//Price: variable USDT/piece, based on algorithm\r\n\t\t//Quantity: 1 per account\r\n\t\tuint256 tokenId = LibArexaPlatformSubscriptions.getCurrentSubscriptionTokenId(SUBSCR2_TOKEN_TYPE);\r\n\t\t// uint256 balance = LibERC1155.balanceOf(msg.sender, tokenId);\r\n\t\t// require(balance == 1, \"Only 1 token can be bought per account!\");\r\n\t\tLibArexaPlatformSubscriptions.buySubscription(tokenId, msg.sender, quantity, 0);\r\n\t}\r\n\r\n\tfunction buyTraderToken(uint128 value, uint8 valueType) external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier3 Singularity\r\n\t\t//TRADER_TOKEN\r\n\t\t//Price: 1.0 USDT/piece\r\n\t\t//Quantity: No limit to buy\r\n\t\t//valueType: 0 is amount, 1 is quantity\r\n\t\tLibArexaPlatformT3.buyTraderToken(msg.sender, msg.sender, value, valueType, 0);\r\n\t}\r\n\r\n\tfunction buyArexaToken(uint128 value, uint8 valueType) external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier4\r\n\t\t//AREXA_TOKEN\r\n\t\t//Price: 0.1 USDT/piece\r\n\t\t//Quantity: No limit to buy\r\n\t\t//valueType: 0 is amount, 1 is quantity\r\n\t\tLibArexaPlatformT4.buyArexaToken(msg.sender, value, valueType, 0);\r\n\t}\r\n\r\n\tfunction buyMagic100Token() external protectedCall noReentry whenNotPaused(LibArexaConst.FULL) {\r\n\t\t//Tier5\r\n\t\t//MAGIC_TOKEN_ID\r\n\t\t//Price: 100.0 USDT/piece\r\n\t\t//Quantity: 1\r\n\r\n\t\trequire(\r\n\t\t\tLibBlackWhiteList.getAccountBlackWhiteList(LibArexaConst.MAGIC100_FIRST_BUYER, msg.sender),\r\n\t\t\t\"Only an approved account can buy the Magic token\"\r\n\t\t);\r\n\r\n\t\tLibBlackWhiteList.setAccountBlackWhiteList(LibArexaConst.MAGIC100_FIRST_BUYER, msg.sender, false);\r\n\r\n\t\tuint256 balance = LibERC1155.balanceOf(msg.sender, LibArexaConst.MAGIC_TOKEN_ID);\r\n\t\trequire(balance == 0, \"Only 1 Magic token can be bought now!\");\r\n\r\n\t\tLibArexaPlatformT5.buyMagic100Token(msg.sender, 0);\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/LibArexaConst.sol": {
        "content": "// SPDX-License-Identifier: UNLICENCED\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nlibrary LibArexaConst {\r\n\t//\r\n\t//Pausable\r\n\tbytes32 public constant FULL = 0x00;\r\n\tbytes32 public constant SUBSCR1_TOKEN = keccak256(abi.encode(\"TOKEN\", LibArexaConst.SUBSCR1_TOKEN_TYPE));\r\n\tbytes32 public constant SUBSCR2_TOKEN = keccak256(abi.encode(\"TOKEN\", LibArexaConst.SUBSCR2_TOKEN_TYPE));\r\n\tbytes32 public constant TRADER_TOKEN = keccak256(abi.encode(\"TOKEN\", LibArexaConst.TRADER_TOKEN_ID));\r\n\tbytes32 public constant AREXA_TOKEN = keccak256(abi.encode(\"TOKEN\", LibArexaConst.AREXA_TOKEN_ID));\r\n\tbytes32 public constant MAGIC_TOKEN = keccak256(abi.encode(\"TOKEN\", LibArexaConst.MAGIC_TOKEN_ID));\r\n\r\n\t//Roles\r\n\tbytes32 public constant AREXA_ADMIN_ROLE = keccak256(\"AREXA_ADMIN_ROLE\");\r\n\t//bytes32 public constant TOKEN_ADMIN_ROLE = keccak256(\"AREXA_TOKEN_ADMIN_ROLE\");\r\n\t//bytes32 public constant TREASURY_ROLE = keccak256(\"AREXA_TREASURY_ROLE\");\r\n\r\n\t//BlackWhite lists\r\n\tbytes32 public constant MAGIC100_FIRST_BUYER = keccak256(\"MAGIC100_FIRST_BUYER\"); //WhiteList\r\n\r\n\t//TokenIDs:\r\n\tuint256 public constant SUBSCR1_TOKEN_TYPE = 100000000; //Tier 1, every month\r\n\tuint256 public constant SUBSCR2_TOKEN_TYPE = 200000000; //Tier 2, every month\r\n\tuint256 public constant TRADER_TOKEN_ID = 300000000; //Tier 3, unlimited, always mint\r\n\tuint256 public constant AREXA_TOKEN_ID = 400000000; //Tier 4, 100000000 piece\r\n\tuint256 public constant MAGIC_TOKEN_ID = 500000000; //Tier 5, 100 piece\r\n\r\n\t//AREXA TOKEN POOL TYPES:\r\n\tuint8 public constant AREXA_TOKEN_POOL_INVESTOR = 1; //35M\r\n\tuint8 public constant AREXA_TOKEN_POOL_AREXAINC = 2; //5M\r\n\tuint8 public constant AREXA_TOKEN_POOL_MARKETING = 3; //5M\r\n\tuint8 public constant AREXA_TOKEN_POOL_DEVELOPMENT = 4; //5M\r\n\tuint8 public constant AREXA_TOKEN_POOL_RESERVED = 5; //50M\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformShared.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibArexaPlatformStorage.sol\";\r\nimport \"../../base/TokenPNL/LibTokenPNL.sol\";\r\n\r\nimport \"../LibArexaConst.sol\";\r\n\r\nlibrary LibArexaPlatformShared {\r\n\tuint8 public constant AMOUNT_VALUE_TYPE = 0;\r\n\tuint8 public constant QUANTITY_VALUE_TYPE = 1;\r\n\r\n\tfunction getPayingToken() internal view returns (IERC20) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\treturn arexa.payingERC20Token;\r\n\t}\r\n\r\n\tfunction getArexaERC20Token() internal view returns (IERC20) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\treturn arexa.arexaERC20Token;\r\n\t}\r\n\r\n\tfunction getArexaTokenPool(uint8 _tokenPool) internal view returns (uint256 total_, uint256 sold_) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\ttotal_ = arexa.arexaTokenPool[_tokenPool].total;\r\n\t\tsold_ = arexa.arexaTokenPool[_tokenPool].sold;\r\n\t}\r\n\r\n\tfunction getArexaIncomeParameter(uint256 _tokenId) internal view returns (uint32 pool_, uint32 arexa_) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\tpool_ = arexa.arexaIncomeParameter[_tokenId].pool;\r\n\t\tarexa_ = arexa.arexaIncomeParameter[_tokenId].arexa;\r\n\t}\r\n\r\n\tfunction _divideAmountPoolAndArexa(uint256 _tokenId, uint256 _value) internal {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tuint256 poolAmount = (_value * arexa.arexaIncomeParameter[_tokenId].pool) /\r\n\t\t\t(arexa.arexaIncomeParameter[_tokenId].pool + arexa.arexaIncomeParameter[_tokenId].arexa);\r\n\t\tuint256 arexaAmount = _value - poolAmount;\r\n\r\n\t\tLibTokenPNL.changeTotalValue(address(arexa.payingERC20Token), LibArexaConst.AREXA_TOKEN_ID, int256(poolAmount));\r\n\t\tarexa.poolBalance += poolAmount;\r\n\t\tarexa.arexaBalance += arexaAmount;\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\nimport { IERC20 } from \"../../base/ERC20/IERC20.sol\";\r\n\r\nstruct ArexaTokenPool {\r\n\tuint256 total;\r\n\tuint256 sold;\r\n}\r\n\r\nstruct ArexaIncomeParameter {\r\n\tuint32 pool;\r\n\tuint32 arexa;\r\n}\r\n\r\nstruct ArexaPlatformStorage {\r\n\tmapping(uint8 => ArexaTokenPool) arexaTokenPool;\r\n\tmapping(uint256 => ArexaIncomeParameter) arexaIncomeParameter;\r\n\tIERC20 payingERC20Token; //USDT\r\n\tuint256 poolBalance; //The \"pool\" part of the sum income\r\n\tuint256 arexaBalance; //The \"owner\" part of the sum income\r\n\t//tokenType => lastSubscriptionTokenId\r\n\tmapping(uint256 => uint256) lastSubscriptionTokenIds;\r\n\tIERC20 arexaERC20Token; //AREXA\r\n\tuint256 stakedArexaERC20TokenQuantity;\r\n\tuint256 poolPaidOutBalance; //The \"pool\" part of the sum outgoing\r\n\tuint256 arexaPaidOutBalance; //The \"owner\" part of the sum outgoing\r\n}\r\n\r\nlibrary LibArexaPlatformStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.contracts.arexa-platform.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (ArexaPlatformStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformSubscriptions.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibArexaPlatformStorage.sol\";\r\nimport \"../../utils/SafeERC20.sol\";\r\nimport \"../../base/Diamond/LibDiamond.sol\";\r\nimport \"../../base/ERC1155/base/LibERC1155.sol\";\r\nimport \"../../base/TokenDynamicPricing/LibTokenDynamicPricing.sol\";\r\n\r\nimport \"../LibArexaConst.sol\";\r\n\r\nimport \"./LibArexaPlatformShared.sol\";\r\n\r\nlibrary LibArexaPlatformSubscriptions {\r\n\t//\r\n\tfunction createSubscriptions(\r\n\t\taddress _operator,\r\n\t\tuint256 _tokenType,\r\n\t\tuint16 _year,\r\n\t\tuint8 _month,\r\n\t\tuint256 _quantity,\r\n\t\tuint256 _min,\r\n\t\tuint256 _max\r\n\t) internal returns (uint256 tokenId) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\t//100 000 000 10**8\r\n\t\t// 20 240 000\r\n\t\tuint256 monthlyTokenType = _tokenType + uint256(_year) * 10 ** 4 + uint256(_month) * 10 ** 2;\r\n\r\n\t\trequire(int256(arexa.lastSubscriptionTokenIds[_tokenType]) - int256(monthlyTokenType) < 99, \"Can't create for old months\");\r\n\r\n\t\tif (arexa.lastSubscriptionTokenIds[_tokenType] < monthlyTokenType) {\r\n\t\t\tarexa.lastSubscriptionTokenIds[_tokenType] = monthlyTokenType;\r\n\t\t}\r\n\t\tarexa.lastSubscriptionTokenIds[_tokenType]++;\r\n\t\ttokenId = arexa.lastSubscriptionTokenIds[_tokenType];\r\n\t\tLibTokenDynamicPricing.initialize(tokenId, _quantity, _min, _max);\r\n\t\tLibERC1155.mint(_operator, LibDiamond.getDiamondAddress(), tokenId, _quantity, \"\");\r\n\t}\r\n\r\n\tfunction getCurrentSubscriptionTokenId(uint256 _tokenType) internal view returns (uint256) {\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\t\treturn arexa.lastSubscriptionTokenIds[_tokenType];\r\n\t}\r\n\r\n\tfunction calcSubscriptionPrice(uint256 _tokenId, uint32 _quantity) internal view returns (uint256) {\r\n\t\treturn LibTokenDynamicPricing.calcTotalValue(_tokenId, _quantity);\r\n\t}\r\n\r\n\tfunction buySubscription(uint256 _tokenId, address _account, uint32 _quantity, uint16 _discountPercent) internal {\r\n\t\t//Tier1 or Tier2\r\n\t\t//AREXA_TOKEN\r\n\t\t//Price: X USDT/piece\r\n\t\t//Quantity: No limit to buy\r\n\r\n\t\trequire(_discountPercent <= 10000, \"Discount percent cannot be more then 100,00%\");\r\n\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tuint256 amount = LibTokenDynamicPricing.buyQuantity(_tokenId, _quantity);\r\n\r\n\t\tamount = (((amount * (10000 - _discountPercent) * 10) / 10000) + 5) / 10;\r\n\r\n\t\taddress contractAddress = LibDiamond.getDiamondAddress();\r\n\r\n\t\t//Transfer \"payingERC20Token\" from \"_account\" account to \"contractAddress\" account\r\n\t\tif (amount > 0) {\r\n\t\t\tSafeERC20.safeTransferFrom(arexa.payingERC20Token, _account, contractAddress, amount);\r\n\t\t}\r\n\r\n\t\t//divide the amount to pool and arexa\r\n\t\t//SUBSCR1_TOKEN_TYPE OR SUBSCR2_TOKEN_TYPE lesz a vége\r\n\t\tuint256 tokenType = (_tokenId / 100000000) * 100000000;\r\n\t\tLibArexaPlatformShared._divideAmountPoolAndArexa(tokenType, amount);\r\n\r\n\t\tLibERC1155.safeTransfer(contractAddress, contractAddress, _account, _tokenId, _quantity, \"\");\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformT3.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibArexaPlatformStorage.sol\";\r\nimport \"../../utils/SafeERC20.sol\";\r\nimport \"../../base/Diamond/LibDiamond.sol\";\r\nimport \"../../base/ERC1155/base/LibERC1155.sol\";\r\n\r\nimport \"../LibArexaConst.sol\";\r\n\r\nimport { IERC20Metadata } from \"../../base/ERC20/metadata/IERC20Metadata.sol\";\r\n\r\nimport \"./LibArexaPlatformShared.sol\";\r\n\r\nlibrary LibArexaPlatformT3 {\r\n\tfunction buyTraderToken(address _operator, address _account, uint128 _value, uint8 _valueType, uint16 _discountPercent) internal {\r\n\t\t//Tier3\r\n\t\t//AREXA_TOKEN\r\n\t\t//Price: 1.0 USDT/piece\r\n\t\t//Quantity: No limit to buy\r\n\t\t//_valueType: 0 is amount, 1 is quantity\r\n\t\trequire(_valueType == 0 || _valueType == 1, \"valueType can be 0 or 1 only!\");\r\n\r\n\t\trequire(_discountPercent <= 10000, \"Discount percent cannot be more then 100,00%\");\r\n\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tuint256 decimal = 10 ** IERC20Metadata(address(arexa.payingERC20Token)).decimals();\r\n\t\tuint256 priceFactor = 10;\r\n\t\tuint256 price = decimal * priceFactor * 1;\r\n\r\n\t\tuint256 amount = 0;\r\n\t\tuint256 quantity = 0;\r\n\t\tif (_valueType == 1) {\r\n\t\t\tamount = ((_value * 10 * price) / priceFactor + 5) / 10; //add 5 and div 10: rounding to the nearest\r\n\t\t\tquantity = (amount * priceFactor) / price;\r\n\t\t\trequire(amount > 0 && quantity > 0, \"The input quantity is too small for paying token!\");\r\n\t\t} else {\r\n\t\t\tquantity = (_value * priceFactor) / price;\r\n\t\t\tamount = (quantity * price) / priceFactor;\r\n\t\t\trequire(amount > 0 && quantity > 0, \"The input amount is too small for buying a token!\");\r\n\t\t}\r\n\r\n\t\tamount = (((amount * (10000 - _discountPercent) * 10) / 10000) + 5) / 10;\r\n\r\n\t\taddress contractAddress = LibDiamond.getDiamondAddress();\r\n\r\n\t\tif (amount > 0) {\r\n\t\t\tSafeERC20.safeTransferFrom(arexa.payingERC20Token, _account, contractAddress, amount);\r\n\t\t}\r\n\r\n\t\t//divide the amount to pool and arexa, fontos a sorrend, mielőtt megkapta a tokent és adminisztráltuk a PNL változást, előtte növeljük a pool értéket\r\n\t\t//azért mert így a deltaPNLben nem napja meg maga után járó részt.\r\n\t\tLibArexaPlatformShared._divideAmountPoolAndArexa(LibArexaConst.TRADER_TOKEN_ID, amount);\r\n\r\n\t\tLibERC1155.mint(_operator, _account, LibArexaConst.TRADER_TOKEN_ID, quantity, \"\");\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformT4.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibArexaPlatformStorage.sol\";\r\nimport \"./LibArexaPlatformShared.sol\";\r\n\r\nimport \"../LibArexaConst.sol\";\r\n\r\nimport \"../../utils/SafeERC20.sol\";\r\nimport \"../../base/Diamond/LibDiamond.sol\";\r\nimport \"../../base/ERC1155/base/LibERC1155.sol\";\r\n\r\nimport { IERC20Metadata } from \"../../base/ERC20/metadata/IERC20Metadata.sol\";\r\n\r\nlibrary LibArexaPlatformT4 {\r\n\tfunction buyArexaToken(address _account, uint128 _value, uint8 _valueType, uint16 _discountPercent) internal {\r\n\t\t//Tier4\r\n\t\t//AREXA_TOKEN\r\n\t\t//Price: 0.1 USDT/piece\r\n\t\t//Quantity: No limit to buy\r\n\t\t//_valueType: 0 is amount, 1 is quantity\r\n\r\n\t\trequire(_valueType == 0 || _valueType == 1, \"valueType can be 0 or 1 only!\");\r\n\r\n\t\trequire(_discountPercent <= 10000, \"Discount percent cannot be more then 100,00%\");\r\n\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tuint256 decimal = 10 ** IERC20Metadata(address(arexa.payingERC20Token)).decimals();\r\n\t\tuint256 priceFactor = 10;\r\n\t\tuint256 price = ((decimal * priceFactor) * 1) / 10;\r\n\r\n\t\tuint256 amount = 0;\r\n\t\tuint256 quantity = 0;\r\n\t\tif (_valueType == 1) {\r\n\t\t\tamount = ((_value * 10 * price) / priceFactor + 5) / 10; //add 5 and div 10: rounding to the nearest\r\n\t\t\tquantity = (amount * priceFactor) / price;\r\n\t\t\trequire(amount > 0 && quantity > 0, \"The input quantity is too small for paying token\");\r\n\t\t} else {\r\n\t\t\tquantity = (_value * priceFactor) / price;\r\n\t\t\tamount = (quantity * price) / priceFactor;\r\n\t\t\trequire(amount > 0 && quantity > 0, \"The input amount is too small for buying a token\");\r\n\t\t}\r\n\r\n\t\tamount = (((amount * (10000 - _discountPercent) * 10) / 10000) + 5) / 10;\r\n\r\n\t\tArexaTokenPool storage tokenPool = arexa.arexaTokenPool[LibArexaConst.AREXA_TOKEN_POOL_INVESTOR];\r\n\t\trequire(tokenPool.sold + quantity <= tokenPool.total, \"Not enough token to sell\");\r\n\t\ttokenPool.sold = tokenPool.sold + quantity;\r\n\r\n\t\taddress contractAddress = LibDiamond.getDiamondAddress();\r\n\r\n\t\tif (amount > 0) {\r\n\t\t\tSafeERC20.safeTransferFrom(arexa.payingERC20Token, _account, contractAddress, amount);\r\n\t\t}\r\n\r\n\t\t//divide the amount to pool and arexa, fontos a sorrend, mielőtt megkapta a tokent és adminisztráltuk a PNL változást, előtte növeljük a pool értéket\r\n\t\t//azért mert így a deltaPNLben nem napja meg maga után járó részt.\r\n\t\tLibArexaPlatformShared._divideAmountPoolAndArexa(LibArexaConst.AREXA_TOKEN_ID, amount);\r\n\r\n\t\tLibERC1155.safeTransfer(contractAddress, contractAddress, _account, LibArexaConst.AREXA_TOKEN_ID, quantity, \"\");\r\n\t\tarexa.stakedArexaERC20TokenQuantity = arexa.stakedArexaERC20TokenQuantity + quantity;\r\n\t}\r\n\r\n\tfunction payByArexaToken(uint8 _poolType, address _account, uint32 _quantity) internal {\r\n\t\t//Tier4\r\n\t\t//AREXA_TOKEN GIFT\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tArexaTokenPool storage tokenPool = arexa.arexaTokenPool[_poolType];\r\n\t\trequire(tokenPool.sold + _quantity <= tokenPool.total, \"Not enoguh token to gift\");\r\n\t\ttokenPool.sold = tokenPool.sold + _quantity;\r\n\r\n\t\taddress contractAddress = LibDiamond.getDiamondAddress();\r\n\r\n\t\tLibERC1155.safeTransfer(contractAddress, contractAddress, _account, LibArexaConst.AREXA_TOKEN_ID, _quantity, \"\");\r\n\t\tarexa.stakedArexaERC20TokenQuantity = arexa.stakedArexaERC20TokenQuantity + _quantity;\r\n\t}\r\n}\r\n"
      },
      "contracts/ArexaPlatform/Platform/LibArexaPlatformT5.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 AREXA\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibArexaPlatformStorage.sol\";\r\nimport \"../../utils/SafeERC20.sol\";\r\nimport \"../../base/Diamond/LibDiamond.sol\";\r\nimport \"../../base/ERC1155/base/LibERC1155.sol\";\r\n\r\nimport \"../LibArexaConst.sol\";\r\n\r\nimport { IERC20Metadata } from \"../../base/ERC20/metadata/IERC20Metadata.sol\";\r\nimport \"../../base/BridgeCentralized/IBridgeableToken.sol\";\r\n\r\nimport \"./LibArexaPlatformShared.sol\";\r\n\r\nlibrary LibArexaPlatformT5 {\r\n\tfunction buyMagic100Token(address _account, uint16 _discountPercent) internal {\r\n\t\t//Tier5\r\n\t\t//MAGIC_TOKEN_ID\r\n\t\t//Price: 100.0 USDT/piece\r\n\t\t//Quantity: 1\r\n\r\n\t\trequire(_discountPercent <= 10000, \"Discount percent cannot be more then 100,00%\");\r\n\r\n\t\tArexaPlatformStorage storage arexa = LibArexaPlatformStorage.layout();\r\n\r\n\t\tuint256 decimal = 10 ** IERC20Metadata(address(arexa.payingERC20Token)).decimals();\r\n\t\tuint256 amount = (((100 * decimal * (10000 - _discountPercent) * 10) / 10000) + 5) / 10;\r\n\r\n\t\taddress contractAddress = LibDiamond.getDiamondAddress();\r\n\r\n\t\tif (amount > 0) {\r\n\t\t\tSafeERC20.safeTransferFrom(arexa.payingERC20Token, _account, contractAddress, amount);\r\n\t\t}\r\n\r\n\t\tLibERC1155.safeTransfer(contractAddress, contractAddress, _account, LibArexaConst.MAGIC_TOKEN_ID, 1, \"\");\r\n\r\n\t\t//divide the amount to pool and arexa, fontos a sorrend, miután megkapta a tokent és adminisztráltuk a PNL változást, utána növeljük a pool értéket csak!\r\n\t\tLibArexaPlatformShared._divideAmountPoolAndArexa(LibArexaConst.MAGIC_TOKEN_ID, amount);\r\n\t}\r\n}\r\n"
      },
      "contracts/base/AccessControl/LibAccessControl.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibAccessControlStorage.sol\";\r\n\r\nimport { IERC173 } from \"../../interfaces/IERC173.sol\";\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\nimport { UintUtils } from \"../../utils/UintUtils.sol\";\r\nimport { AddressUtils } from \"../../utils/AddressUtils.sol\";\r\n\r\nlibrary LibAccessControl {\r\n\tusing EnumerableSet for EnumerableSet.AddressSet;\r\n\tusing UintUtils for uint256;\r\n\tusing AddressUtils for address;\r\n\r\n\terror Ownable__NotOwner();\r\n\terror Ownable__NotTransitiveOwner();\r\n\r\n\terror AccessDenied(bytes32 role, address account);\r\n\r\n\tevent OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n\tevent RoleAdminChanged(address indexed owner, bytes32 role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\r\n\tevent RoleGranted(address indexed owner, bytes32 role, address indexed account, address indexed sender);\r\n\tevent RoleRevoked(address indexed owner, bytes32 role, address indexed account, address indexed sender);\r\n\r\n\tbytes32 internal constant DEFAULT_ADMIN_ROLE = 0x00;\r\n\r\n\tfunction _setOwner(address _newOwner) internal {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\taddress previousOwner = acls.owner;\r\n\t\tacls.owner = _newOwner;\r\n\r\n\t\t//Init DEFAULT_ADMIN_ROLE to _newOwner\r\n\t\tLibAccessControl._grantRole(LibAccessControl.DEFAULT_ADMIN_ROLE, _newOwner);\r\n\r\n\t\temit OwnershipTransferred(previousOwner, _newOwner);\r\n\t}\r\n\r\n\tfunction _owner() internal view returns (address owner_) {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\towner_ = acls.owner;\r\n\t}\r\n\r\n\tfunction _transitiveOwner() internal view returns (address owner_) {\r\n\t\towner_ = LibAccessControl._owner();\r\n\r\n\t\twhile (owner_.isContract()) {\r\n\t\t\ttry IERC173(owner_).owner() returns (address transitiveOwner) {\r\n\t\t\t\towner_ = transitiveOwner;\r\n\t\t\t} catch {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction _enforceIsOwner() internal view {\r\n\t\t//require(msg.sender == _owner(), \"Not owner!\");\r\n\t\tif (msg.sender != _owner()) {\r\n\t\t\trevert Ownable__NotOwner();\r\n\t\t}\r\n\t}\r\n\r\n\tfunction _enforceIsTransitiveOwner() internal view {\r\n\t\t//require(msg.sender == _transitiveOwner(), \"Not transitive owner!\");\r\n\t\tif (msg.sender != _transitiveOwner()) {\r\n\t\t\trevert Ownable__NotTransitiveOwner();\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * @notice assign role to given account\r\n\t * @param _role role to assign\r\n\t * @param _account recipient of role assignment\r\n\t */\r\n\tfunction _grantRole(bytes32 _role, address _account) internal {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\tif (!_hasRole(_role, _account)) {\r\n\t\t\tacls.roles[acls.owner][_role].members.add(_account);\r\n\t\t\temit RoleGranted(acls.owner, _role, _account, msg.sender);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * @notice unassign role from given account\r\n\t * @param _role role to unassign\r\n\t * @param _account account to revokeAccessControlStorage\r\n\t */\r\n\tfunction _revokeRole(bytes32 _role, address _account) internal {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\t// require(_role != LibAccessControl.DEFAULT_ADMIN_ROLE && _account != acls.owner);\r\n\t\tacls.roles[acls.owner][_role].members.remove(_account);\r\n\t\temit RoleRevoked(acls.owner, _role, _account, msg.sender);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice relinquish role\r\n\t * @param _role role to relinquish\r\n\t */\r\n\tfunction _renounceRole(bytes32 _role) internal {\r\n\t\t_revokeRole(_role, msg.sender);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Query one of the accounts that have role of the project\r\n\t * @dev WARNING: When using _getProjectRoleMember and _getProjectRoleMemberCount, make sure you perform all queries on the same block.\r\n\t * @param _role role to query\r\n\t * @param _index index of role member\r\n\t */\r\n\tfunction _getRoleMember(bytes32 _role, uint256 _index) internal view returns (address) {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\treturn acls.roles[acls.owner][_role].members.at(_index);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Query the number of accounts that have role.\r\n\t * @dev WARNING: When using _getRoleMember and _getRoleMemberCount, make sure you perform all queries on the same block.\r\n\t * @param _role role to query\r\n\t */\r\n\tfunction _getRoleMemberCount(address, bytes32 _role) internal view returns (uint256) {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\treturn acls.roles[acls.owner][_role].members.length();\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query whether role is assigned to account\r\n\t * @param _role role to query\r\n\t * @param _account account to query\r\n\t * @return bool whether role is assigned to account\r\n\t */\r\n\tfunction _hasRole(bytes32 _role, address _account) internal view returns (bool) {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\treturn acls.roles[acls.owner][_role].members.contains(_account);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice revert if sender does not have given role\r\n\t * @param _role role to query\r\n\t */\r\n\tfunction _checkRole(bytes32 _role) internal view {\r\n\t\t_checkRole(_role, msg.sender);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice revert if given account does not have given role\r\n\t * @param _role role to query\r\n\t * @param _account to query\r\n\t */\r\n\tfunction _checkRole(bytes32 _role, address _account) internal view {\r\n\t\tif (!_hasRole(_role, _account)) {\r\n\t\t\trevert AccessDenied({ role: _role, account: _account });\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query admin role for given role\r\n\t * @param _role role to query\r\n\t * @return admin role\r\n\t */\r\n\tfunction _getRoleAdmin(bytes32 _role) internal view returns (bytes32) {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\treturn acls.roles[acls.owner][_role].adminRole;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice set role as admin role\r\n\t * @param _role role to set\r\n\t * @param _adminRole admin role to set\r\n\t */\r\n\tfunction _setRoleAdmin(bytes32 _role, bytes32 _adminRole) internal {\r\n\t\tAccessControllStorage storage acls = LibAccessControlStorage.layout();\r\n\t\tbytes32 previousAdminRole = _getRoleAdmin(_role);\r\n\t\tacls.roles[acls.owner][_role].adminRole = _adminRole;\r\n\t\temit RoleAdminChanged(acls.owner, _role, previousAdminRole, _adminRole);\r\n\t}\r\n}\r\n"
      },
      "contracts/base/AccessControl/LibAccessControlStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\nimport \"./RoleData.sol\";\r\n\r\nstruct AccessControllStorage {\r\n\t//owner => role => adminRole, members mapping\r\n\taddress owner;\r\n\tmapping(address => mapping(bytes32 => RoleData)) roles;\r\n}\r\n\r\nlibrary LibAccessControlStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.access-control.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (AccessControllStorage storage acls_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tacls_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/AccessControl/ModifierRole.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { LibAccessControl } from \"./LibAccessControl.sol\";\r\n\r\nabstract contract ModifierRole {\r\n\tmodifier onlyOwner() {\r\n\t\tLibAccessControl._enforceIsOwner();\r\n\t\t_;\r\n\t}\r\n\r\n\tmodifier onlyTransitiveOwner() {\r\n\t\tLibAccessControl._enforceIsTransitiveOwner();\r\n\t\t_;\r\n\t}\r\n\r\n\tmodifier onlyRole(bytes32 role) {\r\n\t\tLibAccessControl._checkRole(role);\r\n\t\t_;\r\n\t}\r\n\r\n\tmodifier onlyRoleAdmin(bytes32 role) {\r\n\t\tLibAccessControl._checkRole(LibAccessControl._getRoleAdmin(role));\r\n\t\t_;\r\n\t}\r\n}\r\n"
      },
      "contracts/base/AccessControl/RoleData.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct RoleData {\r\n\tbytes32 adminRole;\r\n\tEnumerableSet.AddressSet members;\r\n}\r\n"
      },
      "contracts/base/BlackWhiteList/LibBlackWhiteList.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibBlackWhiteListStorage.sol\";\r\n\r\nlibrary LibBlackWhiteList {\r\n\t//_target: which list is belongs to...\r\n\t//_account: an account on a _target\r\n\t//_lockValue:\r\n\t//  - if _target is a blackList than true _lockValue means that the account is prohibited\r\n\t//  - if _target is a blackList than false _lockValue means that the account is acceptable\r\n\t//  - if _target is a whiteList than true _lockValue means that the account is acceptable\r\n\t//  - if _target is a whiteList than false _lockValue means that the account is prohibited\r\n\tevent AccountBlackWhiteList(bytes32 indexed _target, address indexed _account, bool _lockValue);\r\n\r\n\tfunction getAccountBlackWhiteList(bytes32 _target, address _account) internal view returns (bool lockValue_) {\r\n\t\tBlackWhiteListStorage storage wls = LibBlackWhiteListStorage.layout();\r\n\t\tlockValue_ = wls.whiteList[_target][_account];\r\n\t}\r\n\r\n\tfunction setAccountBlackWhiteList(bytes32 _target, address _account, bool _lockValue) internal {\r\n\t\tBlackWhiteListStorage storage wls = LibBlackWhiteListStorage.layout();\r\n\t\twls.whiteList[_target][_account] = _lockValue;\r\n\t\temit AccountBlackWhiteList(_target, _account, _lockValue);\r\n\t}\r\n\r\n\tfunction setBatchAccountBlackWhiteList(bytes32 _target, address[] calldata _accounts, bool _lockValue) internal {\r\n\t\trequire(_accounts.length <= 255, \"Batch: too many addresses\");\r\n\t\tBlackWhiteListStorage storage wls = LibBlackWhiteListStorage.layout();\r\n\t\tfor (uint8 i = 0; i < _accounts.length; i++) {\r\n\t\t\twls.whiteList[_target][_accounts[i]] = _lockValue;\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/BlackWhiteList/LibBlackWhiteListStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct BlackWhiteListStorage {\r\n\tmapping(bytes32 => mapping(address => bool)) whiteList;\r\n}\r\n\r\nlibrary LibBlackWhiteListStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.white-list.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (BlackWhiteListStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/BridgeCentralized/IBridgeableToken.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\ninterface IBridgeableToken {\r\n\tfunction mint(address to, uint256 amount) external;\r\n\r\n\tfunction burnFrom(address from, uint256 amount) external;\r\n}\r\n"
      },
      "contracts/base/Diamond/LibDiamond.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\n/******************************************************************************\\\n* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)\n* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535\n/******************************************************************************/\nimport \"./LibDiamondStorage.sol\";\nimport { IDiamondCut } from \"../../interfaces/IDiamondCut.sol\";\n\nimport { LibAccessControl } from \"../AccessControl/LibAccessControl.sol\";\n\n// Remember to add the loupe functions from DiamondLoupeFacet to the diamond.\n// The loupe functions are required by the EIP2535 Diamonds standard\n\nerror InitializationFunctionReverted(address _initializationContractAddress, bytes _calldata);\n\nlibrary LibDiamond {\n\tevent DiamondCut(IDiamondCut.FacetCut[] _diamondCut, address _init, bytes _calldata);\n\n\tfunction setDiamondAddress(address _diamondAddress) internal {\n\t\tDiamondStorage storage ds = LibDiamondStorage.layout();\n\t\trequire(ds.diamondAddress == address(0), \"Already initialized!\");\n\t\tds.diamondAddress = _diamondAddress;\n\t}\n\n\tfunction getDiamondAddress() internal view returns (address) {\n\t\tDiamondStorage storage ds = LibDiamondStorage.layout();\n\t\treturn ds.diamondAddress;\n\t}\n\n\tfunction setContractOwner(address _newOwner) internal {\n\t\tLibAccessControl._setOwner(_newOwner);\n\t}\n\n\tfunction enforceIsContractOwner() internal view {\n\t\tLibAccessControl._enforceIsOwner();\n\t}\n\n\t// Internal function version of diamondCut\n\tfunction diamondCut(IDiamondCut.FacetCut[] memory _diamondCut, address _init, bytes memory _calldata) internal {\n\t\tfor (uint256 facetIndex; facetIndex < _diamondCut.length; facetIndex++) {\n\t\t\tIDiamondCut.FacetCutAction action = _diamondCut[facetIndex].action;\n\t\t\tif (action == IDiamondCut.FacetCutAction.Add) {\n\t\t\t\taddFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);\n\t\t\t} else if (action == IDiamondCut.FacetCutAction.Replace) {\n\t\t\t\treplaceFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);\n\t\t\t} else if (action == IDiamondCut.FacetCutAction.Remove) {\n\t\t\t\tremoveFunctions(_diamondCut[facetIndex].facetAddress, _diamondCut[facetIndex].functionSelectors);\n\t\t\t} else {\n\t\t\t\trevert(\"LibDiamondCut: Incorrect FacetCutAction\");\n\t\t\t}\n\t\t}\n\t\temit DiamondCut(_diamondCut, _init, _calldata);\n\t\tinitializeDiamondCut(_init, _calldata);\n\t}\n\n\tfunction addFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {\n\t\trequire(_functionSelectors.length > 0, \"LibDiamondCut: No selectors in facet to cut\");\n\t\tDiamondStorage storage ds = LibDiamondStorage.layout();\n\t\trequire(_facetAddress != address(0), \"LibDiamondCut: Add facet can't be address(0)\");\n\t\tuint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length);\n\t\t// add new facet address if it does not exist\n\t\tif (selectorPosition == 0) {\n\t\t\taddFacet(ds, _facetAddress);\n\t\t}\n\t\tfor (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\n\t\t\tbytes4 selector = _functionSelectors[selectorIndex];\n\t\t\taddress oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;\n\t\t\trequire(oldFacetAddress == address(0), \"LibDiamondCut: Can't add function that already exists\");\n\t\t\taddFunction(ds, selector, selectorPosition, _facetAddress);\n\t\t\tselectorPosition++;\n\t\t}\n\t}\n\n\tfunction replaceFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {\n\t\trequire(_functionSelectors.length > 0, \"LibDiamondCut: No selectors in facet to cut\");\n\t\tDiamondStorage storage ds = LibDiamondStorage.layout();\n\t\trequire(_facetAddress != address(0), \"LibDiamondCut: Add facet can't be address(0)\");\n\t\tuint96 selectorPosition = uint96(ds.facetFunctionSelectors[_facetAddress].functionSelectors.length);\n\t\t// add new facet address if it does not exist\n\t\tif (selectorPosition == 0) {\n\t\t\taddFacet(ds, _facetAddress);\n\t\t}\n\t\tfor (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\n\t\t\tbytes4 selector = _functionSelectors[selectorIndex];\n\t\t\taddress oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;\n\t\t\trequire(oldFacetAddress != _facetAddress, \"LibDiamondCut: Can't replace function with same function\");\n\t\t\tremoveFunction(ds, oldFacetAddress, selector);\n\t\t\taddFunction(ds, selector, selectorPosition, _facetAddress);\n\t\t\tselectorPosition++;\n\t\t}\n\t}\n\n\tfunction removeFunctions(address _facetAddress, bytes4[] memory _functionSelectors) internal {\n\t\trequire(_functionSelectors.length > 0, \"LibDiamondCut: No selectors in facet to cut\");\n\t\tDiamondStorage storage ds = LibDiamondStorage.layout();\n\t\t// if function does not exist then do nothing and return\n\t\trequire(_facetAddress == address(0), \"LibDiamondCut: Remove facet address must be address(0)\");\n\t\tfor (uint256 selectorIndex; selectorIndex < _functionSelectors.length; selectorIndex++) {\n\t\t\tbytes4 selector = _functionSelectors[selectorIndex];\n\t\t\taddress oldFacetAddress = ds.selectorToFacetAndPosition[selector].facetAddress;\n\t\t\tremoveFunction(ds, oldFacetAddress, selector);\n\t\t}\n\t}\n\n\tfunction addFacet(DiamondStorage storage ds, address _facetAddress) internal {\n\t\tenforceHasContractCode(_facetAddress, \"LibDiamondCut: New facet has no code\");\n\t\tds.facetFunctionSelectors[_facetAddress].facetAddressPosition = ds.facetAddresses.length;\n\t\tds.facetAddresses.push(_facetAddress);\n\t}\n\n\tfunction addFunction(DiamondStorage storage ds, bytes4 _selector, uint96 _selectorPosition, address _facetAddress) internal {\n\t\tds.selectorToFacetAndPosition[_selector].functionSelectorPosition = _selectorPosition;\n\t\tds.facetFunctionSelectors[_facetAddress].functionSelectors.push(_selector);\n\t\tds.selectorToFacetAndPosition[_selector].facetAddress = _facetAddress;\n\t}\n\n\tfunction removeFunction(DiamondStorage storage ds, address _facetAddress, bytes4 _selector) internal {\n\t\trequire(_facetAddress != address(0), \"LibDiamondCut: Can't remove function that doesn't exist\");\n\t\t// an immutable function is a function defined directly in a diamond\n\t\trequire(_facetAddress != address(this), \"LibDiamondCut: Can't remove immutable function\");\n\t\t// replace selector with last selector, then delete last selector\n\t\tuint256 selectorPosition = ds.selectorToFacetAndPosition[_selector].functionSelectorPosition;\n\t\tuint256 lastSelectorPosition = ds.facetFunctionSelectors[_facetAddress].functionSelectors.length - 1;\n\t\t// if not the same then replace _selector with lastSelector\n\t\tif (selectorPosition != lastSelectorPosition) {\n\t\t\tbytes4 lastSelector = ds.facetFunctionSelectors[_facetAddress].functionSelectors[lastSelectorPosition];\n\t\t\tds.facetFunctionSelectors[_facetAddress].functionSelectors[selectorPosition] = lastSelector;\n\t\t\tds.selectorToFacetAndPosition[lastSelector].functionSelectorPosition = uint96(selectorPosition);\n\t\t}\n\t\t// delete the last selector\n\t\tds.facetFunctionSelectors[_facetAddress].functionSelectors.pop();\n\t\tdelete ds.selectorToFacetAndPosition[_selector];\n\n\t\t// if no more selectors for facet address then delete the facet address\n\t\tif (lastSelectorPosition == 0) {\n\t\t\t// replace facet address with last facet address and delete last facet address\n\t\t\tuint256 lastFacetAddressPosition = ds.facetAddresses.length - 1;\n\t\t\tuint256 facetAddressPosition = ds.facetFunctionSelectors[_facetAddress].facetAddressPosition;\n\t\t\tif (facetAddressPosition != lastFacetAddressPosition) {\n\t\t\t\taddress lastFacetAddress = ds.facetAddresses[lastFacetAddressPosition];\n\t\t\t\tds.facetAddresses[facetAddressPosition] = lastFacetAddress;\n\t\t\t\tds.facetFunctionSelectors[lastFacetAddress].facetAddressPosition = facetAddressPosition;\n\t\t\t}\n\t\t\tds.facetAddresses.pop();\n\t\t\tdelete ds.facetFunctionSelectors[_facetAddress].facetAddressPosition;\n\t\t}\n\t}\n\n\tfunction initializeDiamondCut(address _init, bytes memory _calldata) internal {\n\t\tif (_init == address(0)) {\n\t\t\treturn;\n\t\t}\n\t\tenforceHasContractCode(_init, \"LibDiamondCut: _init address has no code\");\n\t\t(bool success, bytes memory error) = _init.delegatecall(_calldata);\n\t\tif (!success) {\n\t\t\tif (error.length > 0) {\n\t\t\t\t// bubble up error\n\t\t\t\t/// @solidity memory-safe-assembly\n\t\t\t\tassembly {\n\t\t\t\t\tlet returndata_size := mload(error)\n\t\t\t\t\trevert(add(32, error), returndata_size)\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\trevert InitializationFunctionReverted(_init, _calldata);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction enforceHasContractCode(address _contract, string memory _errorMessage) internal view {\n\t\tuint256 contractSize;\n\t\tassembly {\n\t\t\tcontractSize := extcodesize(_contract)\n\t\t}\n\t\trequire(contractSize > 0, _errorMessage);\n\t}\n}\n"
      },
      "contracts/base/Diamond/LibDiamondStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct FacetAddressAndPosition {\r\n\taddress facetAddress;\r\n\tuint96 functionSelectorPosition; // position in facetFunctionSelectors.functionSelectors array\r\n}\r\n\r\nstruct FacetFunctionSelectors {\r\n\tbytes4[] functionSelectors;\r\n\tuint256 facetAddressPosition; // position of facetAddress in facetAddresses array\r\n}\r\n\r\nstruct DiamondStorage {\r\n\taddress diamondAddress;\r\n\t// maps function selector to the facet address and\r\n\t// the position of the selector in the facetFunctionSelectors.selectors array\r\n\tmapping(bytes4 => FacetAddressAndPosition) selectorToFacetAndPosition;\r\n\t// maps facet addresses to function selectors\r\n\tmapping(address => FacetFunctionSelectors) facetFunctionSelectors;\r\n\t// facet addresses\r\n\taddress[] facetAddresses;\r\n\t// Used to query if a contract implements an interface.\r\n\t// Used to implement ERC-165.\r\n\tmapping(bytes4 => bool) supportedInterfaces;\r\n\t//the whole diamond is paused or not\r\n\tbool paused;\r\n}\r\n\r\nlibrary LibDiamondStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.contracts.diamond.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (DiamondStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/ERC1155/base/LibERC1155.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibERC1155Storage.sol\";\r\n\r\nimport \"../customization/LibERC1155Customization.sol\";\r\n\r\nimport { AddressUtils } from \"../../../utils/AddressUtils.sol\";\r\nimport { EnumerableSet } from \"../../../utils/EnumerableSet.sol\";\r\nimport { IERC1155Receiver } from \"../IERC1155Receiver.sol\";\r\n\r\nerror LibERC1155__BalanceQueryZeroAddress(); //Ok\r\nerror LibERC1155__ArrayLengthMismatch(); //Ok\r\nerror LibERC1155__MintToZeroAddress(); //ok\r\nerror LibERC1155__BurnExceedsBalance(); ///Ok\r\nerror LibERC1155__BurnFromZeroAddress(); //Ok\r\nerror LibERC1155__ERC1155ReceiverRejected(); // OK\r\nerror LibERC1155__ERC1155ReceiverNotImplemented(); //ok\r\nerror LibERC1155__TransferExceedsBalance(); //Ok\r\nerror LibERC1155__TransferToZeroAddress(); //Ok\r\nerror LibERC1155__NotOwnerOrApproved(); //Ok\r\nerror LibERC1155__NotOwnerOrApprovedLimit(); //Ok\r\nerror LibERC1155__SelfApproval(); //OK\r\n\r\nlibrary LibERC1155 {\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * EVENTS from IERC1155\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tevent TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);\r\n\r\n\tevent TransferBatch(address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values);\r\n\r\n\tevent ApprovalForAll(address indexed account, address indexed operator, bool approved);\r\n\r\n\tevent URI(string value, uint256 indexed tokenId);\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * EVENTS from IERC1155Allowance\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tevent Approval(address indexed owner, address indexed operator, uint256 indexed id, uint256 currenctValue, uint256 newValue);\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * EVENTS from IERC1155Paused\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tevent AllTokenPaused(address indexed account);\r\n\r\n\tevent AllTokenUnpaused(address indexed account);\r\n\r\n\tevent TokenPaused(address indexed account, uint256 indexed tokenId);\r\n\r\n\tevent TokenUnpaused(address indexed account, uint256 indexed tokenId);\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * Usings\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tusing AddressUtils for address;\r\n\tusing EnumerableSet for EnumerableSet.AddressSet;\r\n\tusing EnumerableSet for EnumerableSet.UintSet;\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155\r\n\t *\r\n\t ************************************************************************************************************/\r\n\r\n\t/**\r\n\t * @notice query the balance of given token held by given address\r\n\t * @param _account address to query\r\n\t * @param _tokenId token to query\r\n\t * @return token balance\r\n\t */\r\n\tfunction balanceOf(address _account, uint256 _tokenId) internal view returns (uint256) {\r\n\t\tif (_account == address(0)) revert LibERC1155__BalanceQueryZeroAddress();\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.balances[_tokenId][_account];\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query the balance of given token held by the given addresses\r\n\t * @param _accounts addresses to query\r\n\t * @param _tokenIds list of token IDs to query\r\n\t * @return tokens' balance\r\n\t */\r\n\tfunction balanceOfBatch(address[] memory _accounts, uint256[] memory _tokenIds) internal view returns (uint256[] memory) {\r\n\t\trequire(_accounts.length == _tokenIds.length, \"ERC1155: accounts and ids length mismatch\");\r\n\t\tif (_tokenIds.length != _accounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\tuint256[] memory batchBalances = new uint256[](_accounts.length);\r\n\r\n\t\tfor (uint256 i = 0; i < _accounts.length; ++i) {\r\n\t\t\tbatchBalances[i] = balanceOf(_accounts[i], _tokenIds[i]);\r\n\t\t}\r\n\r\n\t\treturn batchBalances;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice mint given quantity of tokens for given address\r\n\t * @param _operator caller, msg.sender or msgSender()\r\n\t * @param _toAccount beneficiary of minting\r\n\t * @param _tokenId token ID\r\n\t * @param _amount quantity of tokens to mint\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction mint(address _operator, address _toAccount, uint256 _tokenId, uint256 _amount, bytes memory _data) internal {\r\n\t\tif (_toAccount == address(0)) revert LibERC1155__MintToZeroAddress();\r\n\r\n\t\tuint256[] memory tokenIds = _asSingletonArray(_tokenId);\r\n\t\tuint256[] memory amounts = _asSingletonArray(_amount);\r\n\r\n\t\t_beforeTokenTransfer(_operator, address(0), _toAccount, tokenIds, amounts, _data);\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\t_whenTokenNotPaused(e1155s, _tokenId);\r\n\r\n\t\te1155s.balances[_tokenId][_toAccount] += _amount;\r\n\t\temit TransferSingle(_operator, address(0), _toAccount, _tokenId, _amount);\r\n\r\n\t\t_afterTokenTransfer(_operator, address(0), _toAccount, tokenIds, amounts, _data);\r\n\r\n\t\t_doSafeTransferAcceptanceCheck(_operator, address(0), _toAccount, _tokenId, _amount, _data);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice mint batch of tokens for given address\r\n\t * @param _operator caller, msg.sender or msgSender()\r\n\t * @param _toAccount beneficiary of minting\r\n\t * @param _tokenIds list of token IDs\r\n\t * @param _amounts list of quantities of tokens to mint\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction mintBatch(\r\n\t\taddress _operator,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tif (_toAccount == address(0)) revert LibERC1155__MintToZeroAddress();\r\n\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\t_beforeTokenTransfer(_operator, address(0), _toAccount, _tokenIds, _amounts, _data);\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\r\n\t\tfor (uint256 i = 0; i < _tokenIds.length; ) {\r\n\t\t\tuint256 tokenId = _tokenIds[i];\r\n\t\t\t_whenTokenNotPaused(e1155s, tokenId);\r\n\t\t\te1155s.balances[tokenId][_toAccount] += _amounts[i];\r\n\t\t\tunchecked {\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\temit TransferBatch(_operator, address(0), _toAccount, _tokenIds, _amounts);\r\n\r\n\t\t_afterTokenTransfer(_operator, address(0), _toAccount, _tokenIds, _amounts, _data);\r\n\r\n\t\t_doSafeBatchTransferAcceptanceCheck(_operator, address(0), _toAccount, _tokenIds, _amounts, _data);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice burn given quantity of tokens held by given address\r\n\t * @param _operator caller, msg.sender or msgSender()\r\n\t * @param _fromAccount holder of tokens to burn\r\n\t * @param _tokenId token ID\r\n\t * @param _amount quantity of tokens to burn\r\n\t */\r\n\tfunction burn(address _operator, address _fromAccount, uint256 _tokenId, uint256 _amount) internal {\r\n\t\tif (_fromAccount == address(0)) revert LibERC1155__BurnFromZeroAddress();\r\n\r\n\t\t_beforeTokenTransfer(_operator, _fromAccount, address(0), _asSingletonArray(_tokenId), _asSingletonArray(_amount), \"\");\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\t_whenTokenNotPaused(e1155s, _tokenId);\r\n\r\n\t\tif (_amount > e1155s.balances[_tokenId][_fromAccount]) revert LibERC1155__BurnExceedsBalance();\r\n\r\n\t\tunchecked {\r\n\t\t\te1155s.balances[_tokenId][_fromAccount] -= _amount;\r\n\t\t}\r\n\r\n\t\temit TransferSingle(_operator, _fromAccount, address(0), _tokenId, _amount);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice burn given batch of tokens held by given address\r\n\t * @param _operator caller, msg.sender or msgSender()\r\n\t * @param _fromAccount holder of tokens to burn\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to burn\r\n\t */\r\n\tfunction burnBatch(address _operator, address _fromAccount, uint256[] memory _tokenIds, uint256[] memory _amounts) internal {\r\n\t\tif (_fromAccount == address(0)) revert LibERC1155__BurnFromZeroAddress();\r\n\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\t_beforeTokenTransfer(_operator, _fromAccount, address(0), _tokenIds, _amounts, \"\");\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\r\n\t\tunchecked {\r\n\t\t\tfor (uint256 i; i < _tokenIds.length; i++) {\r\n\t\t\t\tuint256 tokenId = _tokenIds[i];\r\n\t\t\t\t_whenTokenNotPaused(e1155s, tokenId);\r\n\t\t\t\tif (_amounts[i] > e1155s.balances[tokenId][_fromAccount]) revert LibERC1155__BurnExceedsBalance();\r\n\t\t\t\te1155s.balances[tokenId][_fromAccount] -= _amounts[i];\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\temit TransferBatch(_operator, _fromAccount, address(0), _tokenIds, _amounts);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice transfer tokens between given addresses\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenId token ID\r\n\t * @param _amount quantity of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction safeTransfer(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256 _tokenId,\r\n\t\tuint256 _amount,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tif (_toAccount == address(0)) revert LibERC1155__TransferToZeroAddress();\r\n\r\n\t\tuint256[] memory tokenIds = _asSingletonArray(_tokenId);\r\n\t\tuint256[] memory amounts = _asSingletonArray(_amount);\r\n\r\n\t\t_beforeTokenTransfer(_operator, _fromAccount, _toAccount, tokenIds, amounts, _data);\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\t_whenTokenNotPaused(e1155s, _tokenId);\r\n\r\n\t\tuint256 senderBalance = e1155s.balances[_tokenId][_fromAccount];\r\n\r\n\t\tif (_amount > senderBalance) revert LibERC1155__TransferExceedsBalance();\r\n\t\tcheckAllowance(_operator, _fromAccount, _tokenId, _amount);\r\n\r\n\t\tunchecked {\r\n\t\t\te1155s.balances[_tokenId][_fromAccount] = senderBalance - _amount;\r\n\t\t\tif (_operator != _fromAccount) {\r\n\t\t\t\tif (e1155s.operatorSpendingLimitEnabled[_tokenId]) {\r\n\t\t\t\t\te1155s.allowances[_fromAccount][_operator][_tokenId] = e1155s.allowances[_fromAccount][_operator][_tokenId] - _amount;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\te1155s.balances[_tokenId][_toAccount] += _amount;\r\n\r\n\t\temit TransferSingle(_operator, _fromAccount, _toAccount, _tokenId, _amount);\r\n\r\n\t\t_afterTokenTransfer(_operator, _fromAccount, _toAccount, tokenIds, amounts, _data);\r\n\r\n\t\t_doSafeTransferAcceptanceCheck(_operator, _fromAccount, _toAccount, _tokenId, _amount, _data);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice transfer batch of tokens between given addresses\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction safeTransferBatch(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tif (_toAccount == address(0)) revert LibERC1155__TransferToZeroAddress();\r\n\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\t_beforeTokenTransfer(_operator, _fromAccount, _toAccount, _tokenIds, _amounts, _data);\r\n\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\r\n\t\tcheckAllowanceBach(_operator, _fromAccount, _tokenIds, _amounts);\r\n\r\n\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\tuint256 tokenId = _tokenIds[i];\r\n\t\t\tuint256 amount = _amounts[i];\r\n\r\n\t\t\tunchecked {\r\n\t\t\t\t_whenTokenNotPaused(e1155s, tokenId);\r\n\r\n\t\t\t\tuint256 senderBalance = e1155s.balances[tokenId][_fromAccount];\r\n\r\n\t\t\t\tif (amount > senderBalance) revert LibERC1155__TransferExceedsBalance();\r\n\r\n\t\t\t\te1155s.balances[tokenId][_fromAccount] = senderBalance - amount;\r\n\r\n\t\t\t\tif (_operator != _fromAccount) {\r\n\t\t\t\t\tif (e1155s.operatorSpendingLimitEnabled[tokenId]) {\r\n\t\t\t\t\t\te1155s.allowances[_fromAccount][_operator][tokenId] = e1155s.allowances[_fromAccount][_operator][tokenId] - amount;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\r\n\t\t\t// balance increase cannot be unchecked because ERC1155Base neither tracks nor validates a totalSupply\r\n\t\t\te1155s.balances[tokenId][_toAccount] += amount;\r\n\t\t}\r\n\r\n\t\temit TransferBatch(_operator, _fromAccount, _toAccount, _tokenIds, _amounts);\r\n\r\n\t\t_afterTokenTransfer(_operator, _fromAccount, _toAccount, _tokenIds, _amounts, _data);\r\n\r\n\t\t_doSafeBatchTransferAcceptanceCheck(_operator, _fromAccount, _toAccount, _tokenIds, _amounts, _data);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Enable or disable approval for a third party (\"operator\") to manage all of the caller's tokens.\r\n\t * @dev MUST emit the ApprovalForAll event on success.\r\n\t * @param _account The owner of the tokens\r\n\t * @param _operator Address to add to the set of authorized operators\r\n\t * @param _approved True if the operator is approved, false to revoke approval\r\n\t */\r\n\tfunction setApprovalForAll(address _account, address _operator, bool _approved) internal {\r\n\t\tif (_account == _operator) revert LibERC1155__SelfApproval();\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\te1155s.operatorApprovals[_account][_operator] = _approved;\r\n\t\temit ApprovalForAll(_account, _operator, _approved);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Queries the approval status of an operator for a given owner.\r\n\t * @param _account The owner of the tokens\r\n\t * @param _operator Address of authorized operator\r\n\t * @return True if the operator is approved, false if not\r\n\t */\r\n\tfunction isApprovedForAll(address _account, address _operator) internal view returns (bool) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.operatorApprovals[_account][_operator];\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155Receiver\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tbytes4 internal constant ERC1155_ACCEPTED = 0xf23a6e61; // bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))\r\n\tbytes4 internal constant ERC1155_BATCH_ACCEPTED = 0xbc197c81; // bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))\r\n\r\n\tfunction onERC1155Received(\r\n\t\taddress _operator,\r\n\t\taddress _from,\r\n\t\tuint256 _id,\r\n\t\tuint256 _value,\r\n\t\tbytes calldata _data\r\n\t) internal returns (bytes4) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tERC1155ReceiverStorage storage receivedData = e1155s.receivedTokens[e1155s.receivedTokensLength];\r\n\t\treceivedData.operator = _operator;\r\n\t\treceivedData.from = _from;\r\n\t\treceivedData.ids = _asSingletonArray(_id);\r\n\t\treceivedData.values = _asSingletonArray(_value);\r\n\t\treceivedData.data = _data;\r\n\t\te1155s.receivedTokensLength++;\r\n\r\n\t\t// if (shouldReject == true) {\r\n\t\t// \trevert(\"onERC1155Received: transfer not accepted\");\r\n\t\t// } else {\r\n\t\t// \treturn ERC1155_ACCEPTED;\r\n\t\t// }\r\n\t\treturn ERC1155_ACCEPTED;\r\n\t}\r\n\r\n\tfunction onERC1155BatchReceived(\r\n\t\taddress _operator,\r\n\t\taddress _from,\r\n\t\tuint256[] calldata _ids,\r\n\t\tuint256[] calldata _values,\r\n\t\tbytes calldata _data\r\n\t) internal returns (bytes4) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tERC1155ReceiverStorage storage receivedData = e1155s.receivedTokens[e1155s.receivedTokensLength];\r\n\t\treceivedData.operator = _operator;\r\n\t\treceivedData.from = _from;\r\n\t\treceivedData.ids = _ids;\r\n\t\treceivedData.values = _values;\r\n\t\treceivedData.data = _data;\r\n\t\te1155s.receivedTokensLength++;\r\n\t\treturn ERC1155_BATCH_ACCEPTED;\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155Allowance\r\n\t *\r\n\t ************************************************************************************************************/\r\n\r\n\tfunction isOperatorSpendingLimitEnabled(uint256 _tokenId) internal view returns (bool) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.operatorSpendingLimitEnabled[_tokenId];\r\n\t}\r\n\r\n\tfunction setOperatorSpendingLimitEnabled(uint256 _tokenId, bool _enabled) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\te1155s.operatorSpendingLimitEnabled[_tokenId] = _enabled;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Allow other accounts/contracts to spend tokens on behalf of msg.sender\r\n\t * @dev MUST emit Approval event on success.\r\n\t * To minimize the risk of the approve/transferFrom attack vector (see https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/), this function will throw if the current approved allowance does not equal the expected _currentValue, unless _value is 0.\r\n\t * @param _owner Address of token owner\r\n\t * @param _operator Address to approve, _operator will ba able to send token\r\n\t * @param _tokenId ID of the Token\r\n\t * @param _currentValue Expected current value of approved allowance.\r\n\t * @param _newValue Allowance amount\r\n\t */\r\n\tfunction approve(address _owner, address _operator, uint256 _tokenId, uint256 _currentValue, uint256 _newValue) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\trequire(e1155s.allowances[_owner][_operator][_tokenId] == _currentValue, \"Current value mismatch\");\r\n\t\te1155s.allowances[_owner][_operator][_tokenId] = _newValue;\r\n\r\n\t\temit Approval(_owner, _operator, _tokenId, _currentValue, _newValue);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice Queries the spending limit approved for an account\r\n\t * @param _owner The owner allowing the spending\r\n\t * @param _operator The address allowed to spend.\r\n\t * @param _tokenId ID of the Token\r\n\t * @return The _operator's allowed spending balance of the Token requested\r\n\t */\r\n\tfunction allowance(address _owner, address _operator, uint256 _tokenId) internal view returns (uint256) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.allowances[_owner][_operator][_tokenId];\r\n\t}\r\n\r\n\tfunction checkAllowance(address _operator, address _fromAccount, uint256 _tokenId, uint256 _value) internal view {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tif (_fromAccount != _operator) {\r\n\t\t\tif (!e1155s.operatorApprovals[_fromAccount][_operator]) {\r\n\t\t\t\trevert LibERC1155__NotOwnerOrApproved();\r\n\t\t\t}\r\n\t\t\tif (e1155s.operatorSpendingLimitEnabled[_tokenId] && e1155s.allowances[_fromAccount][_operator][_tokenId] < _value) {\r\n\t\t\t\trevert LibERC1155__NotOwnerOrApprovedLimit();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction checkAllowanceBach(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts\r\n\t) internal view {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tif (_fromAccount != _operator) {\r\n\t\t\tif (!e1155s.operatorApprovals[_fromAccount][_operator]) {\r\n\t\t\t\trevert LibERC1155__NotOwnerOrApproved();\r\n\t\t\t}\r\n\r\n\t\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\t\tunchecked {\r\n\t\t\t\t\tuint256 tokenId = _tokenIds[i];\r\n\t\t\t\t\tuint256 amount = _amounts[i];\r\n\t\t\t\t\tif (e1155s.operatorSpendingLimitEnabled[tokenId] && e1155s.allowances[_fromAccount][_operator][tokenId] < amount) {\r\n\t\t\t\t\t\trevert LibERC1155__NotOwnerOrApprovedLimit();\r\n\t\t\t\t\t}\r\n\t\t\t\t\ti++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155Metadata\r\n\t *\r\n\t ************************************************************************************************************/\r\n\r\n\t/**\r\n\t * @notice Query global metadata URI, can contain {id}, client will replace with a valid token id\r\n\t */\r\n\tfunction getUri() internal view returns (string memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.uri;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice set global metadata URI, can contain {id}, client will\r\n\t * @param _URI global URI\r\n\t */\r\n\tfunction setURI(string memory _URI) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\te1155s.uri = _URI;\r\n\t}\r\n\r\n\tfunction getTokenBaseUri() internal view returns (string memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.baseURI;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice set base metadata URI\r\n\t * @dev base URI is a non-standard feature adapted from the ERC721 specification\r\n\t * @param _baseURI base URI\r\n\t */\r\n\tfunction setTokenBaseURI(string memory _baseURI) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\te1155s.baseURI = _baseURI;\r\n\t}\r\n\r\n\tfunction getTokenUri(uint256 _tokenId) internal view returns (string memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.tokenURIs[_tokenId];\r\n\t}\r\n\r\n\t/**\r\n\t * @notice set pre-token metadata URI\r\n\t * @param _tokenId token whose metadata URI to set\r\n\t * @param _tokenURI per-token URI\r\n\t */\r\n\tfunction setTokenURI(uint256 _tokenId, string memory _tokenURI) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\te1155s.tokenURIs[_tokenId] = _tokenURI;\r\n\t\temit URI(_tokenURI, _tokenId);\r\n\t}\r\n\r\n\t/**\r\n\t * This implementation returns the concatenation of the `_baseURI`\r\n\t * and the token-specific uri if the latter is set\r\n\t *\r\n\t * This enables the following behaviors:\r\n\t *\r\n\t * - if `_tokenURIs[tokenId]` is set, then the result is the concatenation\r\n\t *   of `_baseURI` and `_tokenURIs[tokenId]`\r\n\t *\r\n\t * - if `_tokenURIs[tokenId]` is NOT set then we fallback to the defaut URI\r\n\t *   which contains `ERC1155.uri`;\r\n\t */\r\n\tfunction getUri(uint256 tokenId) internal view returns (string memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tstring memory tokenURI = e1155s.tokenURIs[tokenId];\r\n\r\n\t\t// If token URI is set, concatenate base URI and tokenURI (via abi.encodePacked).\r\n\t\treturn bytes(tokenURI).length > 0 ? string(abi.encodePacked(e1155s.baseURI, tokenURI)) : e1155s.uri;\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155Enumerable\r\n\t *\r\n\t ************************************************************************************************************/\r\n\r\n\t/**\r\n\t * @notice query total minted supply of given token\r\n\t * @param _tokenId token id to query\r\n\t * @return token supply\r\n\t */\r\n\tfunction totalSupply(uint256 _tokenId) internal view returns (uint256) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.totalSupply[_tokenId];\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query total number of holders for given token\r\n\t * @param id token id to query\r\n\t * @return quantity of holders\r\n\t */\r\n\tfunction totalHolders(uint256 id) internal view returns (uint256) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\treturn e1155s.accountsByToken[id].length();\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query holders of given token\r\n\t * @param _tokenId token id to query\r\n\t * @return list of holder addresses\r\n\t */\r\n\tfunction accountsByToken(uint256 _tokenId) internal view returns (address[] memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tEnumerableSet.AddressSet storage accounts = e1155s.accountsByToken[_tokenId];\r\n\r\n\t\taddress[] memory addresses = new address[](accounts.length());\r\n\r\n\t\tunchecked {\r\n\t\t\tfor (uint256 i; i < accounts.length(); i++) {\r\n\t\t\t\taddresses[i] = accounts.at(i);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn addresses;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice query tokens held by given address\r\n\t * @param _account address to query\r\n\t * @return list of token ids\r\n\t */\r\n\tfunction tokensByAccount(address _account) internal view returns (uint256[] memory) {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\tEnumerableSet.UintSet storage tokens = e1155s.tokensByAccount[_account];\r\n\r\n\t\tuint256[] memory ids = new uint256[](tokens.length());\r\n\r\n\t\tunchecked {\r\n\t\t\tfor (uint256 i; i < tokens.length(); i++) {\r\n\t\t\t\tids[i] = tokens.at(i);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn ids;\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * IERC1155Pausable\r\n\t *\r\n\t ************************************************************************************************************/\r\n\tfunction whenNotPaused(ERC1155Storage storage e1155s) internal view {\r\n\t\trequire(!e1155s.paused, \"All token is paused!\");\r\n\t}\r\n\r\n\tfunction _whenTokenNotPaused(ERC1155Storage storage e1155s, uint256 _tokenId) internal view {\r\n\t\twhenNotPaused(e1155s);\r\n\t\trequire(!e1155s.pausedToken[_tokenId], \"Token is paused!\");\r\n\t}\r\n\r\n\tfunction whenNotPaused() internal view {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\twhenNotPaused(e1155s);\r\n\t}\r\n\r\n\tfunction whenTokenNotPaused(uint256 _tokenId) internal view {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\t_whenTokenNotPaused(e1155s, _tokenId);\r\n\t}\r\n\r\n\tfunction pauseAllToken(address _operator) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\trequire(!e1155s.paused, \"All tokens are already paused\");\r\n\t\te1155s.paused = true;\r\n\t\temit AllTokenPaused(_operator);\r\n\t}\r\n\r\n\tfunction unpauseAllToken(address _operator) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\trequire(e1155s.paused, \"All tokens are not paused yet\");\r\n\t\te1155s.paused = false;\r\n\t\temit AllTokenUnpaused(_operator);\r\n\t}\r\n\r\n\tfunction pauseToken(address _operator, uint256 _tokenId) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\trequire(!e1155s.pausedToken[_tokenId], \"Token is already paused\");\r\n\t\te1155s.pausedToken[_tokenId] = true;\r\n\t\temit TokenPaused(_operator, _tokenId);\r\n\t}\r\n\r\n\tfunction unpauseToken(address _operator, uint256 _tokenId) internal {\r\n\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\t\trequire(e1155s.pausedToken[_tokenId], \"Token is not paused yet\");\r\n\t\te1155s.pausedToken[_tokenId] = false;\r\n\t\temit TokenUnpaused(_operator, _tokenId);\r\n\t}\r\n\r\n\t/************************************************************************************************************\r\n\t *\r\n\t * Library internal helper functions\r\n\t *\r\n\t ************************************************************************************************************/\r\n\r\n\t/**\r\n\t * @notice revert if applicable transfer recipient is not valid ERC1155Receiver\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenId token ID\r\n\t * @param _amount quantity of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction _doSafeTransferAcceptanceCheck(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256 _tokenId,\r\n\t\tuint256 _amount,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tif (_toAccount.isContract()) {\r\n\t\t\ttry IERC1155Receiver(_toAccount).onERC1155Received(_operator, _fromAccount, _tokenId, _amount, _data) returns (\r\n\t\t\t\tbytes4 response\r\n\t\t\t) {\r\n\t\t\t\tif (response != IERC1155Receiver.onERC1155Received.selector) revert LibERC1155__ERC1155ReceiverRejected();\r\n\t\t\t} catch Error(string memory reason) {\r\n\t\t\t\trevert(reason);\r\n\t\t\t} catch {\r\n\t\t\t\trevert LibERC1155__ERC1155ReceiverNotImplemented();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * @notice revert if applicable transfer recipient is not valid ERC1155Receiver\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction _doSafeBatchTransferAcceptanceCheck(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory _data\r\n\t) private {\r\n\t\tif (_toAccount.isContract()) {\r\n\t\t\ttry IERC1155Receiver(_toAccount).onERC1155BatchReceived(_operator, _fromAccount, _tokenIds, _amounts, _data) returns (\r\n\t\t\t\tbytes4 response\r\n\t\t\t) {\r\n\t\t\t\tif (response != IERC1155Receiver.onERC1155BatchReceived.selector) revert LibERC1155__ERC1155ReceiverRejected();\r\n\t\t\t} catch Error(string memory reason) {\r\n\t\t\t\trevert(reason);\r\n\t\t\t} catch {\r\n\t\t\t\trevert LibERC1155__ERC1155ReceiverNotImplemented();\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\tfunction _asSingletonArray(uint256 element) internal pure returns (uint256[] memory) {\r\n\t\tuint256[] memory array = new uint256[](1);\r\n\t\tarray[0] = element;\r\n\t\treturn array;\r\n\t}\r\n\r\n\t/**\r\n\t * @notice ERC1155 hook, called before all transfers including mint and burn\r\n\t * The same hook is called on both single and batched variants. For single\r\n\t * transfers, the length of the `ids` and `amounts` arrays will be 1.\r\n\t * Calling conditions (for each `id` and `amount` pair):\r\n\t * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens of token type `id` will be  transferred to `to`.\r\n\t * - When `from` is zero, `amount` tokens of token type `id` will be minted for `to`.\r\n\t * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` will be burned.\r\n\t * - `from` and `to` are never both zero.\r\n\t * - `ids` and `amounts` have the same, non-zero length.\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction _beforeTokenTransfer(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tif (_fromAccount != _toAccount) {\r\n\t\t\tERC1155Storage storage e1155s = LibERC1155Storage.layout();\r\n\r\n\t\t\tmapping(uint256 => EnumerableSet.AddressSet) storage tokenAccounts = e1155s.accountsByToken;\r\n\r\n\t\t\tEnumerableSet.UintSet storage fromAccountTokens = e1155s.tokensByAccount[_fromAccount];\r\n\t\t\tEnumerableSet.UintSet storage toAccountTokens = e1155s.tokensByAccount[_toAccount];\r\n\r\n\t\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\t\tuint256 amount = _amounts[i];\r\n\r\n\t\t\t\tif (amount > 0) {\r\n\t\t\t\t\tuint256 id = _tokenIds[i];\r\n\r\n\t\t\t\t\tif (_fromAccount == address(0)) {\r\n\t\t\t\t\t\te1155s.totalSupply[id] += amount;\r\n\t\t\t\t\t} else if (balanceOf(_fromAccount, id) == amount) {\r\n\t\t\t\t\t\ttokenAccounts[id].remove(_fromAccount);\r\n\t\t\t\t\t\tfromAccountTokens.remove(id);\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (_toAccount == address(0)) {\r\n\t\t\t\t\t\te1155s.totalSupply[id] -= amount;\r\n\t\t\t\t\t} else if (balanceOf(_toAccount, id) == 0) {\r\n\t\t\t\t\t\ttokenAccounts[id].add(_toAccount);\r\n\t\t\t\t\t\ttoAccountTokens.add(id);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tunchecked {\r\n\t\t\t\t\ti++;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\tLibERC1155Customization.beforeTokenTransfer(_operator, _fromAccount, _toAccount, _tokenIds, _amounts, _data);\r\n\t}\r\n\r\n\t/**\r\n\t * @notice ERC1155 hook, called after all transfers including mint and burn\r\n\t * The same hook is called on both single and batched variants. For single\r\n\t * transfers, the length of the `id` and `amount` arrays will be 1.\r\n\t * Calling conditions (for each `id` and `amount` pair):\r\n\t * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens of token type `id` will be  transferred to `to`.\r\n\t * - When `from` is zero, `amount` tokens of token type `id` will be minted for `to`.\r\n\t * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` will be burned.\r\n\t * - `from` and `to` are never both zero.\r\n\t * - `ids` and `amounts` have the same, non-zero length.\r\n\t * @param _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t * @param _data data payload\r\n\t */\r\n\tfunction _afterTokenTransfer(\r\n\t\taddress _operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory _data\r\n\t) internal {\r\n\t\tLibERC1155Customization.afterTokenTransfer(_operator, _fromAccount, _toAccount, _tokenIds, _amounts, _data);\r\n\t}\r\n}\r\n"
      },
      "contracts/base/ERC1155/base/LibERC1155Storage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../../utils/EnumerableSet.sol\";\r\n\r\nstruct ERC1155ReceiverStorage {\r\n\tbytes data;\r\n\taddress operator;\r\n\taddress from;\r\n\tuint256[] ids;\r\n\tuint256[] values;\r\n}\r\n\r\nstruct ERC1155Storage {\r\n\tmapping(uint256 => mapping(address => uint256)) balances; // Mapping from token ID to account balances\r\n\tmapping(address => mapping(address => bool)) operatorApprovals; // Mapping from account to operator approvals\r\n\tmapping(uint256 => bool) operatorSpendingLimitEnabled;\r\n\tmapping(address => mapping(address => mapping(uint256 => uint256))) allowances;\r\n\tmapping(uint256 => uint256) totalSupply;\r\n\tmapping(uint256 => EnumerableSet.AddressSet) accountsByToken;\r\n\tmapping(address => EnumerableSet.UintSet) tokensByAccount;\r\n\tstring uri; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json\r\n\tstring baseURI; // Optional base URI, e.g. ipfs://53453534\r\n\tmapping(uint256 => string) tokenURIs; // Optional mapping for token URIs, e.g. 4236464216781, so tokenURI will be: ipfs://53453534/4236464216781\r\n\tbool paused;\r\n\tmapping(uint256 => bool) pausedToken;\r\n\tuint256 receivedTokensLength;\r\n\tmapping(uint256 => ERC1155ReceiverStorage) receivedTokens;\r\n}\r\n\r\nlibrary LibERC1155Storage {\r\n\tbytes32 internal constant ERC1155_STORAGE_SLOT = keccak256(\"usmart.contracts.erc1155-base.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (ERC1155Storage storage e1155s_) {\r\n\t\tbytes32 position = ERC1155_STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\te1155s_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/ERC1155/customization/LibERC1155Customization.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"../../TokenRestriction/LibTokenRestriction.sol\";\r\nimport \"../../TokenPNL/LibTokenPNL.sol\";\r\n\r\nimport \"../../../ArexaPlatform/Platform/LibArexaPlatformShared.sol\";\r\n\r\nlibrary LibERC1155Customization {\r\n\t/**\r\n\t * @notice ERC1155 hook, called before all transfers including mint and burn\r\n\t * The same hook is called on both single and batched variants. For single\r\n\t * transfers, the length of the `ids` and `amounts` arrays will be 1.\r\n\t * Calling conditions (for each `id` and `amount` pair):\r\n\t * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens of token type `id` will be  transferred to `to`.\r\n\t * - When `from` is zero, `amount` tokens of token type `id` will be minted for `to`.\r\n\t * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` will be burned.\r\n\t * - `from` and `to` are never both zero.\r\n\t * - `ids` and `amounts` have the same, non-zero length.\r\n\t *  param_operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t *  param_toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t *  param _data data payload\r\n\t */\r\n\tfunction beforeTokenTransfer(\r\n\t\taddress, //_operator,\r\n\t\taddress _fromAccount,\r\n\t\taddress, //_toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory //_data\r\n\t) internal view {\r\n\t\tif (_fromAccount != address(0)) {\r\n\t\t\tLibTokenRestriction.checkRestrictions(_fromAccount, _tokenIds, _amounts);\r\n\t\t}\r\n\t}\r\n\r\n\t/**\r\n\t * @notice ERC1155 hook, called after all transfers including mint and burn\r\n\t * The same hook is called on both single and batched variants. For single\r\n\t * transfers, the length of the `id` and `amount` arrays will be 1.\r\n\t * Calling conditions (for each `id` and `amount` pair):\r\n\t * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens of token type `id` will be  transferred to `to`.\r\n\t * - When `from` is zero, `amount` tokens of token type `id` will be minted for `to`.\r\n\t * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` will be burned.\r\n\t * - `from` and `to` are never both zero.\r\n\t * - `ids` and `amounts` have the same, non-zero length.\r\n\t * _operator executor of transfer\r\n\t * @param _fromAccount sender of tokens\r\n\t * @param _toAccount receiver of tokens\r\n\t * @param _tokenIds token IDs\r\n\t * @param _amounts quantities of tokens to transfer\r\n\t * _data data payload\r\n\t */\r\n\tfunction afterTokenTransfer(\r\n\t\taddress, //_operator\r\n\t\taddress _fromAccount,\r\n\t\taddress _toAccount,\r\n\t\tuint256[] memory _tokenIds,\r\n\t\tuint256[] memory _amounts,\r\n\t\tbytes memory //_data\r\n\t) internal {\r\n\t\tif (_fromAccount != address(0)) {\r\n\t\t\tLibTokenRestriction.recalcRestrictions(_fromAccount, _tokenIds, _amounts, 0);\r\n\t\t}\r\n\r\n\t\tif (_toAccount != address(0)) {\r\n\t\t\tLibTokenRestriction.recalcRestrictions(_toAccount, _tokenIds, _amounts, 1);\r\n\t\t}\r\n\r\n\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\tLibTokenPNL.refreshDivident(\r\n\t\t\t\taddress(LibArexaPlatformShared.getPayingToken()),\r\n\t\t\t\t_tokenIds[i],\r\n\t\t\t\t_fromAccount,\r\n\t\t\t\t_toAccount,\r\n\t\t\t\t_amounts[i]\r\n\t\t\t);\r\n\r\n\t\t\tunchecked {\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/ERC1155/IERC1155Receiver.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\n/**\n * https://eips.ethereum.org/EIPS/eip-1155.\n */\ninterface IERC1155Receiver {\n\t/**\n\t * @notice Handle the receipt of a single ERC1155 token type.\n\t * @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeTransferFrom` after the balance has been updated.\n\t * This function MUST return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))` (i.e. 0xf23a6e61) if it accepts the transfer.\n\t * This function MUST revert if it rejects the transfer.\n\t * Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller.\n\t * @param _operator The address which initiated the transfer (i.e. msg.sender)\n\t * @param _from The address which previously owned the token\n\t * @param _id The ID of the token being transferred\n\t * @param _value The amount of tokens being transferred\n\t * @param _data Additional data with no specified format\n\t * @return `bytes4(keccak256(\"onERC1155Received(address,address,uint256,uint256,bytes)\"))`\n\t */\n\tfunction onERC1155Received(\n\t\taddress _operator,\n\t\taddress _from,\n\t\tuint256 _id,\n\t\tuint256 _value,\n\t\tbytes calldata _data\n\t) external returns (bytes4);\n\n\t/**\n\t * @notice Handle the receipt of multiple ERC1155 token types.\n\t * @dev An ERC1155-compliant smart contract MUST call this function on the token recipient contract, at the end of a `safeBatchTransferFrom` after the balances have been updated.\n\t * This function MUST return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))` (i.e. 0xbc197c81) if it accepts the transfer(s).\n\t * This function MUST revert if it rejects the transfer(s).\n\t * Return of any other value than the prescribed keccak256 generated value MUST result in the transaction being reverted by the caller.\n\t * @param _operator The address which initiated the batch transfer (i.e. msg.sender)\n\t * @param _from The address which previously owned the token\n\t * @param _ids An array containing ids of each token being transferred (order and length must match _values array)\n\t * @param _values An array containing amounts of each token being transferred (order and length must match _ids array)\n\t * @param _data Additional data with no specified format\n\t * @return `bytes4(keccak256(\"onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)\"))`\n\t */\n\tfunction onERC1155BatchReceived(\n\t\taddress _operator,\n\t\taddress _from,\n\t\tuint256[] calldata _ids,\n\t\tuint256[] calldata _values,\n\t\tbytes calldata _data\n\t) external returns (bytes4);\n}\n"
      },
      "contracts/base/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\n/**\n * @title ERC20 interface\n * @dev see https://eips.ethereum.org/EIPS/eip-20\n */\ninterface IERC20 {\n\tevent Transfer(address indexed from, address indexed to, uint256 value);\n\n\tevent Approval(address indexed owner, address indexed spender, uint256 value);\n\n\t/**\n\t * @notice query the total minted token supply\n\t * @return token supply\n\t */\n\tfunction totalSupply() external view returns (uint256);\n\n\t/**\n\t * @notice query the token balance of given account\n\t * @param account address to query\n\t * @return token balance\n\t */\n\tfunction balanceOf(address account) external view returns (uint256);\n\n\t/**\n\t * @notice query the allowance granted from given holder to given spender\n\t * @param holder approver of allowance\n\t * @param spender recipient of allowance\n\t * @return token allowance\n\t */\n\tfunction allowance(address holder, address spender) external view returns (uint256);\n\n\t/**\n\t * @notice grant approval to spender to spend tokens\n\t * @dev prefer ERC20Extended functions to avoid transaction-ordering vulnerability (see https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729)\n\t * @param spender recipient of allowance\n\t * @param amount quantity of tokens approved for spending\n\t * @return success status (always true; otherwise function should revert)\n\t */\n\tfunction approve(address spender, uint256 amount) external returns (bool);\n\n\t/**\n\t * @notice transfer tokens to given recipient\n\t * @param recipient beneficiary of token transfer\n\t * @param amount quantity of tokens to transfer\n\t * @return success status (always true; otherwise function should revert)\n\t */\n\tfunction transfer(address recipient, uint256 amount) external returns (bool);\n\n\t/**\n\t * @notice transfer tokens to given recipient on behalf of given holder\n\t * @param holder holder of tokens prior to transfer\n\t * @param recipient beneficiary of token transfer\n\t * @param amount quantity of tokens to transfer\n\t * @return success status (always true; otherwise function should revert)\n\t */\n\tfunction transferFrom(address holder, address recipient, uint256 amount) external returns (bool);\n}\n"
      },
      "contracts/base/ERC20/metadata/IERC20Metadata.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\n/**\n * @title ERC20 metadata interface\n */\ninterface IERC20Metadata {\n\t/**\n\t * @notice return token name\n\t * @return token name\n\t */\n\tfunction name() external view returns (string memory);\n\n\t/**\n\t * @notice return token symbol\n\t * @return token symbol\n\t */\n\tfunction symbol() external view returns (string memory);\n\n\t/**\n\t * @notice return token decimals, generally used only for display purposes\n\t * @return token decimals\n\t */\n\tfunction decimals() external view returns (uint8);\n}\n"
      },
      "contracts/base/Shared/LibReentryProtectionStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nstruct ReentryProtectionStorage {\r\n\tuint256 lockCounter;\r\n}\r\n\r\nlibrary LibReentryProtectionStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.reentry-protection.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (ReentryProtectionStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/Shared/ProtectedCall.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { LibDiamond } from \"../Diamond/LibDiamond.sol\";\r\n\r\ncontract CallProtection {\r\n\tmodifier protectedCall() {\r\n\t\trequire(address(this) == LibDiamond.getDiamondAddress(), \"NOT_ALLOWED\");\r\n\t\t_;\r\n\t}\r\n}\r\n"
      },
      "contracts/base/Shared/ReentryProtection.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibReentryProtectionStorage.sol\";\r\n\r\ncontract ReentryProtection {\r\n\tmodifier noReentry() {\r\n\t\t// Use counter to only write to storage once\r\n\t\tReentryProtectionStorage storage rps = LibReentryProtectionStorage.layout();\r\n\t\trps.lockCounter++;\r\n\t\tuint256 lockValue = rps.lockCounter;\r\n\t\t_;\r\n\t\trequire(lockValue == rps.lockCounter, \"ReentryProtection: reentry detected!\");\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TargetedPausable/LibTargetedPausable.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibTargetedPausableStorage.sol\";\r\n\r\nlibrary LibTargetedPausable {\r\n\terror TargetedPausable__TargetedPaused();\r\n\terror TargetedPausable__NotTargetedPaused();\r\n\r\n\t//target: what was paused\r\n\t//account: the operator who is paused the target\r\n\tevent TargetedPaused(bytes32 indexed target, address indexed account);\r\n\r\n\t//target: what was unpaused\r\n\t//account: the operator who is unpaused the target\r\n\tevent TargetedUnpaused(bytes32 target, address indexed account);\r\n\r\n\tfunction whenNotPaused(bytes32 _target) internal view {\r\n\t\tif (LibTargetedPausable.paused(_target)) revert TargetedPausable__TargetedPaused();\r\n\t}\r\n\r\n\tfunction whenPaused(bytes32 _target) internal view {\r\n\t\tif (!LibTargetedPausable.paused(_target)) revert TargetedPausable__NotTargetedPaused();\r\n\t}\r\n\r\n\tfunction paused(bytes32 _target) internal view returns (bool paused_) {\r\n\t\tpaused_ = LibTargetedPausableStorage.layout().paused[_target];\r\n\t}\r\n\r\n\tfunction pause(bytes32 _target, address _operator) internal {\r\n\t\tTargetedPausableStorage storage ps = LibTargetedPausableStorage.layout();\r\n\t\tif (ps.paused[_target]) revert TargetedPausable__TargetedPaused();\r\n\t\tps.paused[_target] = true;\r\n\t\temit TargetedPaused(_target, _operator);\r\n\t}\r\n\r\n\tfunction unpause(bytes32 _target, address _operator) internal {\r\n\t\tTargetedPausableStorage storage ps = LibTargetedPausableStorage.layout();\r\n\t\tif (!ps.paused[_target]) revert TargetedPausable__NotTargetedPaused();\r\n\t\tps.paused[_target] = false;\r\n\t\tdelete ps.paused[_target];\r\n\t\temit TargetedUnpaused(_target, _operator);\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TargetedPausable/LibTargetedPausableStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct TargetedPausableStorage {\r\n\tmapping(bytes32 => bool) paused;\r\n}\r\n\r\nlibrary LibTargetedPausableStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.targeted-pausable.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (TargetedPausableStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TargetedPausable/ModifierPausable.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { LibTargetedPausable } from \"./LibTargetedPausable.sol\";\r\n\r\nabstract contract ModifierPausable {\r\n\t//\r\n\tmodifier whenNotPaused(bytes32 target) {\r\n\t\tLibTargetedPausable.whenNotPaused(target);\r\n\t\t_;\r\n\t}\r\n\r\n\tmodifier whenPaused(bytes32 target) {\r\n\t\tLibTargetedPausable.whenPaused(target);\r\n\t\t_;\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenDynamicPricing/LibTokenDynamicPricing.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibTokenDynamicPricingStorage.sol\";\r\n\r\nimport \"../../utils/Math.sol\";\r\n\r\nlibrary LibTokenDynamicPricing {\r\n\tfunction initialize(uint256 _tokenId, uint256 _initialQuantity, uint256 _min, uint256 _max) internal {\r\n\t\tTokenDynamicPricingStorage storage dynamicPricing = LibTokenDynamicPricingStorage.layout();\r\n\t\tDynamicPricing storage pricing = dynamicPricing.tokenDynamicPricing[_tokenId];\r\n\r\n\t\tpricing.isEnabled = true;\r\n\t\tpricing.quantity = _initialQuantity;\r\n\t\tpricing.k = (_min == 0) ? _initialQuantity * _initialQuantity : _initialQuantity * _initialQuantity * _min;\r\n\t\tpricing.min = _min; //must contain the decimals of the paying token!!!\r\n\t\tpricing.max = (_max == 0 || _max < _min) ? pricing.k : _max; //must contain the decimals of the paying token!!!\r\n\t}\r\n\r\n\tfunction _calcTotalValue(DynamicPricing storage pricing, uint256 _quantity) internal view returns (uint256) {\r\n\t\trequire(pricing.isEnabled, \"Calculation is not enabled for the token!\");\r\n\t\trequire(_quantity <= pricing.quantity, \"Not enought quantity left!\");\r\n\t\tuint256 totalValue = (((10 * _quantity * pricing.k) / (pricing.quantity * (pricing.quantity - _quantity + 1))) + 5) / 10;\r\n\t\treturn Math.min(_quantity * pricing.max, Math.max(_quantity * pricing.min, totalValue));\r\n\t}\r\n\r\n\tfunction calcTotalValue(uint256 _tokenId, uint256 _quantity) internal view returns (uint256) {\r\n\t\tTokenDynamicPricingStorage storage dynamicPricing = LibTokenDynamicPricingStorage.layout();\r\n\t\tDynamicPricing storage pricing = dynamicPricing.tokenDynamicPricing[_tokenId];\r\n\t\treturn _calcTotalValue(pricing, _quantity);\r\n\t}\r\n\r\n\tfunction buyQuantity(uint256 _tokenId, uint256 _quantity) internal returns (uint256) {\r\n\t\tTokenDynamicPricingStorage storage dynamicPricing = LibTokenDynamicPricingStorage.layout();\r\n\t\tDynamicPricing storage pricing = dynamicPricing.tokenDynamicPricing[_tokenId];\r\n\t\tuint256 totalValue = _calcTotalValue(pricing, _quantity);\r\n\r\n\t\tpricing.quantity = pricing.quantity - _quantity;\r\n\t\tpricing.totalValue = pricing.totalValue + totalValue;\r\n\r\n\t\tif (pricing.quantity == 0) {\r\n\t\t\tpricing.isEnabled = false;\r\n\t\t}\r\n\r\n\t\treturn totalValue;\r\n\t}\r\n\r\n\tfunction getEnabled(uint256 _tokenId) internal view returns (bool) {\r\n\t\t//\r\n\t\tTokenDynamicPricingStorage storage dynamicPricing = LibTokenDynamicPricingStorage.layout();\r\n\t\tDynamicPricing storage pricing = dynamicPricing.tokenDynamicPricing[_tokenId];\r\n\t\treturn pricing.isEnabled;\r\n\t}\r\n\r\n\tfunction setPricingEnabled(uint256 _tokenId, bool _enabledValue) internal {\r\n\t\tTokenDynamicPricingStorage storage dynamicPricing = LibTokenDynamicPricingStorage.layout();\r\n\t\tDynamicPricing storage pricing = dynamicPricing.tokenDynamicPricing[_tokenId];\r\n\t\trequire(\r\n\t\t\t!_enabledValue || (_enabledValue && pricing.quantity > 0),\r\n\t\t\t\"Reenable of token pricing is only availabe is there is som token left to sell!\"\r\n\t\t);\r\n\t\tpricing.isEnabled = _enabledValue;\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenDynamicPricing/LibTokenDynamicPricingStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct DynamicPricing {\r\n\tbool isEnabled;\r\n\tuint256 quantity;\r\n\tuint256 totalValue;\r\n\tuint256 k;\r\n\tuint256 min;\r\n\tuint256 max;\r\n}\r\n\r\nstruct TokenDynamicPricingStorage {\r\n\t//tokenId => restriction, every token have\r\n\tmapping(uint256 => DynamicPricing) tokenDynamicPricing;\r\n}\r\n\r\nlibrary LibTokenDynamicPricingStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.token-dynamic-pricing.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (TokenDynamicPricingStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenPNL/LibTokenPNL.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibTokenPNLStorage.sol\";\r\n\r\nlibrary LibTokenPNL {\r\n\tfunction initTokenPNL(address _contract, uint256 _tokenId) internal {\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\tinventory.isEnabled = true;\r\n\t\tinventory.sumQuantity = 0;\r\n\t\tinventory.sumAmount = 0;\r\n\t\tinventory.sumPnl = 0;\r\n\t}\r\n\r\n\tfunction changeTotalValue(address _contract, uint256 _tokenId, int256 _amount) internal {\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\tif (!inventory.isEnabled) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t//because every transfer, mint and burn do like ralizing the pnl\r\n\t\t//and after this realizing the user can payout the collected a PNL\r\n\t\t//so decreasing the value can cause money loss in the contract!!!\r\n\t\t//if wanted full inventory feature in a distributed way: ask uSmart ;)\r\n\t\trequire(_amount >= 0, \"Pool can only increase!\");\r\n\r\n\t\tinventory.sumAmount += _amount;\r\n\t\tinventory.sumPnl += _amount; //Here is the MAGIC!\r\n\t}\r\n\r\n\tfunction getInventory(\r\n\t\taddress _contract,\r\n\t\tuint256 _tokenId\r\n\t) internal view returns (bool isEnabled, int256 sumQuantity, int256 sumAmount, int256 sumPnl) {\r\n\t\t//\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\treturn (inventory.isEnabled, inventory.sumQuantity, inventory.sumAmount, inventory.sumPnl);\r\n\t}\r\n\r\n\tfunction getInventoryItem(\r\n\t\taddress _contract,\r\n\t\tuint256 _tokenId,\r\n\t\taddress _account\r\n\t) internal view returns (int256 quantity, int256 deltaPnl, int256 payedPnl) {\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\treturn (inventory.divident[_account].quantity, inventory.divident[_account].deltaPnl, inventory.divident[_account].payedPnl);\r\n\t}\r\n\r\n\tfunction _refreshDividentInternal(Inventory storage inventory, address _account, int256 _quantity) internal {\r\n\t\tInventoryItem storage inventoryItem = inventory.divident[_account];\r\n\r\n\t\trequire(inventory.sumQuantity + _quantity >= 0, \"Pool token quanity can't be less then zero!\");\r\n\t\trequire(inventoryItem.quantity + _quantity >= 0, \"User token quanity can't be less then zero!\");\r\n\r\n\t\tint256 addressPnlDelta = 0;\r\n\t\tif (inventory.sumQuantity != 0) {\r\n\t\t\taddressPnlDelta = (inventory.sumPnl * _quantity) / inventory.sumQuantity;\r\n\t\t}\r\n\r\n\t\tinventory.sumQuantity = inventory.sumQuantity + _quantity;\r\n\t\tinventory.sumPnl = inventory.sumPnl + addressPnlDelta;\r\n\t\tinventoryItem.quantity = inventoryItem.quantity + _quantity;\r\n\t\tinventoryItem.deltaPnl = inventoryItem.deltaPnl - addressPnlDelta;\r\n\t}\r\n\r\n\tfunction refreshDivident(address _contract, uint256 _tokenId, address _fromAccount, address _toAccount, uint256 _quantity) internal {\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\tif (!inventory.isEnabled) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tif (_fromAccount != address(0)) {\r\n\t\t\t_refreshDividentInternal(inventory, _fromAccount, -1 * int256(_quantity));\r\n\t\t}\r\n\r\n\t\tif (_toAccount != address(0)) {\r\n\t\t\t_refreshDividentInternal(inventory, _toAccount, int256(_quantity));\r\n\t\t}\r\n\t}\r\n\r\n\tfunction calcDivident(address _contract, uint256 _tokenId, address _account) internal view returns (int256) {\r\n\t\tif (_account == address(0)) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\tif (!inventory.isEnabled) {\r\n\t\t\treturn 0;\r\n\t\t}\r\n\r\n\t\tInventoryItem storage inventoryItem = inventory.divident[_account];\r\n\t\t//calculate actual value of the token\r\n\t\tint256 actValue = 0;\r\n\t\tif (inventory.sumQuantity != 0) {\r\n\t\t\tactValue = (inventory.sumPnl * inventoryItem.quantity) / inventory.sumQuantity;\r\n\t\t}\r\n\t\t//the divident is equal with the actual value minus the summa pnlDelta\r\n\t\t//note: the pnlDelta already have the negative sign!!!\r\n\t\tint256 actDivident = actValue + inventoryItem.deltaPnl - inventoryItem.payedPnl;\r\n\r\n\t\treturn actDivident;\r\n\t}\r\n\r\n\tfunction refreshPayoutDivident(address _contract, uint256 _tokenId, address _account, int256 _amount) internal {\r\n\t\tTokenPNLStorage storage tokenPNL = LibTokenPNLStorage.layout();\r\n\t\tInventory storage inventory = tokenPNL.inventory[_contract][_tokenId];\r\n\t\tif (!inventory.isEnabled) {\r\n\t\t\treturn;\r\n\t\t}\r\n\t\trequire(_amount >= 0, \"Only positive amount can be payed out!\");\r\n\r\n\t\tint256 payableDivident = calcDivident(_contract, _tokenId, _account);\r\n\r\n\t\trequire(_amount <= payableDivident, \"The amount is bigger then tha payable divident!\");\r\n\r\n\t\tInventoryItem storage inventoryItem = inventory.divident[_account];\r\n\t\tinventoryItem.payedPnl = inventoryItem.payedPnl + _amount;\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenPNL/LibTokenPNLStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\nimport { IERC20 } from \"../../base/ERC20/IERC20.sol\";\r\n\r\nstruct InventoryItem {\r\n\tint256 quantity;\r\n\tint256 deltaPnl; //After calculating the act Pnl based on the quantity this is a Pnl modification factor!\r\n\tint256 payedPnl;\r\n}\r\n\r\nstruct Inventory {\r\n\tbool isEnabled;\r\n\tint256 sumQuantity;\r\n\tint256 sumAmount;\r\n\tint256 sumPnl;\r\n\t//Account - pool divident calculation\r\n\tmapping(address => InventoryItem) divident;\r\n}\r\n\r\nstruct TokenPNLStorage {\r\n\t//contract => tokenId => inventory map\r\n\t//Eg: IERC20 => 0 => inventory\r\n\t//Eg: IERC1155 => tokenId => Inventory\r\n\tmapping(address => mapping(uint256 => Inventory)) inventory;\r\n}\r\n\r\nlibrary LibTokenPNLStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.token-pnl.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (TokenPNLStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenRestriction/LibTokenRestriction.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"./LibTokenRestrictionStorage.sol\";\r\nimport \"../../base/ERC1155/base/LibERC1155.sol\";\r\nimport \"../../utils/Math.sol\";\r\n\r\nimport { IERC20 } from \"../../base/ERC20/IERC20.sol\";\r\n\r\nlibrary LibTokenRestriction {\r\n\tfunction initTokenRestriction(uint256 _tokenId, uint256 _endOfRestriction, uint256 _endOfRestrictionCalc, uint256 _timeDelta) internal {\r\n\t\t// require(block.number + 12 * _timeDelta < _endOfRestriction);\r\n\t\t// require(_endOfRestriction + 12 * _timeDelta < _endOfRestrictionCalc);\r\n\r\n\t\tTokenRestrictionStorage storage arexa = LibTokenRestrictionStorage.layout();\r\n\t\tRestriction storage restriction = arexa.tokenRestriction[_tokenId];\r\n\t\tif ((restriction.endOfRestrictionCalc == 0) || (restriction.endOfRestriction + 1 == restriction.endOfRestrictionCalc)) {\r\n\t\t\trestriction.endOfRestriction = _endOfRestriction;\r\n\t\t\trestriction.endOfRestrictionCalc = _endOfRestrictionCalc;\r\n\t\t\trestriction.timeDelta = _timeDelta;\r\n\t\t}\r\n\t}\r\n\r\n\tfunction calcUnrestrictedAmount(address _account, uint256 _tokenId, uint256 _amount) internal view returns (uint256) {\r\n\t\tTokenRestrictionStorage storage arexa = LibTokenRestrictionStorage.layout();\r\n\t\tRestriction storage restriction = arexa.tokenRestriction[_tokenId];\r\n\r\n\t\tif (restriction.endOfRestrictionCalc < block.number) {\r\n\t\t\treturn _amount;\r\n\t\t}\r\n\r\n\t\tRestrictionCalc storage accRestr = restriction.restriction[_account];\r\n\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((K8-I8)/L8)*(E8-M8)/12)\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((actTime-time)/timeDelta)*(bought-accumulated)/12)\r\n\t\tuint256 helper = ((block.number - accRestr.time) / restriction.timeDelta) * ((accRestr.bought - accRestr.accumulated) / 12);\r\n\r\n\t\t//=MIN(M10+Q10;E10)-G10\r\n\t\t//=MIN(accumulated+helper;bought)-sold\r\n\t\tuint256 canSell = Math.min(accRestr.accumulated + helper, accRestr.bought) - accRestr.sold;\r\n\r\n\t\treturn canSell;\r\n\t}\r\n\r\n\tfunction checkRestriction(address _account, uint256 _tokenId, uint256 _amount) internal view returns (bool) {\r\n\t\tTokenRestrictionStorage storage arexa = LibTokenRestrictionStorage.layout();\r\n\t\tRestriction storage restriction = arexa.tokenRestriction[_tokenId];\r\n\r\n\t\tif (restriction.endOfRestrictionCalc <= block.number) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\r\n\t\t// if (restriction.endOfRestriction < block.number) {\r\n\t\t// \treturn;\r\n\t\t// }\r\n\r\n\t\tRestrictionCalc storage accRestr = restriction.restriction[_account];\r\n\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((K8-I8)/L8)*(E8-M8)/12)\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((actTime-time)/timeDelta)*(bought-accumulated)/12)\r\n\t\tuint256 helper = ((block.number - accRestr.time) / restriction.timeDelta) * ((accRestr.bought - accRestr.accumulated) / 12);\r\n\r\n\t\t//=MIN(M10+Q10;E10)-G10\r\n\t\t//=MIN(accumulated+helper;bought)-sold\r\n\t\tuint256 canSell = Math.min(accRestr.accumulated + helper, accRestr.bought) - accRestr.sold;\r\n\r\n\t\trequire(_amount <= canSell, \"The amount is grater then the accumlated ('sellable') amount!\");\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\tfunction checkRestrictions(address _account, uint256[] memory _tokenIds, uint256[] memory _amounts) internal view returns (bool) {\r\n\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\tcheckRestriction(_account, _tokenIds[i], _amounts[i]);\r\n\t\t\tunchecked {\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn true;\r\n\t}\r\n\r\n\tfunction recalcRestriction(address _account, uint256 _tokenId, uint256 _amount, uint8 _direction) internal {\r\n\t\t//eladható mennyiség kalkulációhoz\r\n\t\tTokenRestrictionStorage storage arexa = LibTokenRestrictionStorage.layout();\r\n\t\tRestriction storage restriction = arexa.tokenRestriction[_tokenId];\r\n\r\n\t\tif (restriction.endOfRestrictionCalc <= block.number) {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\tRestrictionCalc storage accRestr = restriction.restriction[_account];\r\n\r\n\t\tif (restriction.endOfRestriction <= block.number) {\r\n\t\t\t//valami mást kell csinálni\r\n\t\t\tif (_direction == 1) {\r\n\t\t\t\taccRestr.bought += _amount;\r\n\t\t\t\taccRestr.accumulated += _amount;\r\n\t\t\t}\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t\t//frissíteni üzemszerűen.\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((J12-I12)/L12)*(E12-M12)/12)\r\n\t\t//=FLOOR.MATH(FLOOR.MATH((actTime-time)/timeDelta)*(bought-accumlated)/12)\r\n\t\tuint256 helper = ((block.number - accRestr.time) / restriction.timeDelta) * ((accRestr.bought - accRestr.accumulated) / 12);\r\n\r\n\t\t//=MIN(M12+N12; E12)\r\n\t\t//=MIN(accumulated+helper; bought)\r\n\t\taccRestr.accumulated = Math.min(accRestr.accumulated + helper, accRestr.bought);\r\n\r\n\t\t//vesz, elad\r\n\t\tif (_direction == 1) {\r\n\t\t\taccRestr.bought += _amount;\r\n\t\t} else {\r\n\t\t\taccRestr.sold += _amount;\r\n\t\t}\r\n\r\n\t\taccRestr.time = block.number;\r\n\t}\r\n\r\n\tfunction recalcRestrictions(address _account, uint256[] memory _tokenIds, uint256[] memory _amounts, uint8 _direction) internal {\r\n\t\tif (_tokenIds.length != _amounts.length) revert LibERC1155__ArrayLengthMismatch();\r\n\r\n\t\tfor (uint256 i; i < _tokenIds.length; ) {\r\n\t\t\trecalcRestriction(_account, _tokenIds[i], _amounts[i], _direction);\r\n\t\t\tunchecked {\r\n\t\t\t\ti++;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/base/TokenRestriction/LibTokenRestrictionStorage.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport { EnumerableSet } from \"../../utils/EnumerableSet.sol\";\r\n\r\nstruct RestrictionCalc {\r\n\tuint256 bought;\r\n\tuint256 sold;\r\n\tuint256 time; //blockheight * 1 000 000 000\r\n\tuint256 accumulated;\r\n}\r\n\r\nstruct Restriction {\r\n\tuint256 endOfRestriction; //if act-time is lower then endOfRestriction then only calculating the a previous data, new tokens do not restircted\r\n\tuint256 endOfRestrictionCalc; //if act-time is lower then endOfRestrictionCalc then now calculation at all\r\n\tuint256 timeDelta; //if time is blockHeight based then delta should be calculated like that. If second based then...\r\n\t//Account - restriction calculation params\r\n\tmapping(address => RestrictionCalc) restriction;\r\n}\r\n\r\nstruct TokenRestrictionStorage {\r\n\t//tokenId => restriction, every token have\r\n\tmapping(uint256 => Restriction) tokenRestriction;\r\n}\r\n\r\nlibrary LibTokenRestrictionStorage {\r\n\tbytes32 internal constant STORAGE_SLOT = keccak256(\"usmart.common.token-restriction.storage.v1\");\r\n\r\n\tfunction layout() internal pure returns (TokenRestrictionStorage storage layout_) {\r\n\t\tbytes32 position = STORAGE_SLOT;\r\n\t\tassembly {\r\n\t\t\tlayout_.slot := position\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/interfaces/IDiamondCut.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.9;\n\n/******************************************************************************\\\n* Author: Nick Mudge <nick@perfectabstractions.com> (https://twitter.com/mudgen)\n* EIP-2535 Diamonds: https://eips.ethereum.org/EIPS/eip-2535\n/******************************************************************************/\n\ninterface IDiamondCut {\n\tenum FacetCutAction {\n\t\tAdd,\n\t\tReplace,\n\t\tRemove\n\t}\n\t// Add=0, Replace=1, Remove=2\n\n\tstruct FacetCut {\n\t\taddress facetAddress;\n\t\tFacetCutAction action;\n\t\tbytes4[] functionSelectors;\n\t}\n\n\t/// @notice Add/replace/remove any number of functions and optionally execute\n\t///         a function with delegatecall\n\t/// @param _diamondCut Contains the facet addresses and function selectors\n\t/// @param _init The address of the contract or facet to execute _calldata\n\t/// @param _calldata A function call, including function selector and arguments\n\t///                  _calldata is executed with delegatecall on _init\n\tfunction diamondCut(FacetCut[] calldata _diamondCut, address _init, bytes calldata _calldata) external;\n\n\tevent DiamondCut(FacetCut[] _diamondCut, address _init, bytes _calldata);\n}\n"
      },
      "contracts/interfaces/IERC173.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\n/// @title ERC-173 Contract Ownership Standard\r\n///  Note: the ERC-165 identifier for this interface is 0x7f5828d0\r\ninterface IERC173 {\r\n\t/// @dev This emits when ownership of a contract changes.\r\n\tevent OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\r\n\r\n\t/// @notice Get the address of the owner\r\n\t/// @return owner_ The address of the owner.\r\n\tfunction owner() external view returns (address owner_);\r\n\r\n\t/// @notice Set the address of the new owner of the contract\r\n\t/// @dev Set _newOwner to address(0) to renounce any ownership.\r\n\t/// @param _newOwner The address of the new owner of the contract\r\n\tfunction transferOwnership(address _newOwner) external;\r\n}\r\n"
      },
      "contracts/utils/AddressUtils.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\nimport { UintUtils } from \"./UintUtils.sol\";\n\nlibrary AddressUtils {\n\tusing UintUtils for uint256;\n\n\terror AddressUtils__InsufficientBalance();\n\terror AddressUtils__NotContract();\n\terror AddressUtils__SendValueFailed();\n\n\tfunction toString(address account) internal pure returns (string memory) {\n\t\treturn uint256(uint160(account)).toHexString(20);\n\t}\n\n\tfunction isContract(address account) internal view returns (bool) {\n\t\tuint256 size;\n\t\tassembly {\n\t\t\tsize := extcodesize(account)\n\t\t}\n\t\treturn size > 0;\n\t}\n\n\tfunction sendValue(address payable account, uint256 amount) internal {\n\t\t(bool success, ) = account.call{ value: amount }(\"\");\n\t\tif (!success) revert AddressUtils__SendValueFailed();\n\t}\n\n\tfunction functionCall(address target, bytes memory data) internal returns (bytes memory) {\n\t\treturn functionCall(target, data, \"AddressUtils: failed low-level call\");\n\t}\n\n\tfunction functionCall(address target, bytes memory data, string memory error) internal returns (bytes memory) {\n\t\treturn _functionCallWithValue(target, data, 0, error);\n\t}\n\n\tfunction functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n\t\treturn functionCallWithValue(target, data, value, \"AddressUtils: failed low-level call with value\");\n\t}\n\n\tfunction functionCallWithValue(address target, bytes memory data, uint256 value, string memory error) internal returns (bytes memory) {\n\t\tif (value > address(this).balance) revert AddressUtils__InsufficientBalance();\n\t\treturn _functionCallWithValue(target, data, value, error);\n\t}\n\n\t/**\n\t * @notice execute arbitrary external call with limited gas usage and amount of copied return data\n\t * @dev derived from https://github.com/nomad-xyz/ExcessivelySafeCall (MIT License)\n\t * @param target recipient of call\n\t * @param gasAmount gas allowance for call\n\t * @param value native token value to include in call\n\t * @param maxCopy maximum number of bytes to copy from return data\n\t * @param data encoded call data\n\t * @return success whether call is successful\n\t * @return returnData copied return data\n\t */\n\tfunction excessivelySafeCall(\n\t\taddress target,\n\t\tuint256 gasAmount,\n\t\tuint256 value,\n\t\tuint16 maxCopy,\n\t\tbytes memory data\n\t) internal returns (bool success, bytes memory returnData) {\n\t\treturnData = new bytes(maxCopy);\n\n\t\tassembly {\n\t\t\t// execute external call via assembly to avoid automatic copying of return data\n\t\t\tsuccess := call(gasAmount, target, value, add(data, 0x20), mload(data), 0, 0)\n\n\t\t\t// determine whether to limit amount of data to copy\n\t\t\tlet toCopy := returndatasize()\n\n\t\t\tif gt(toCopy, maxCopy) {\n\t\t\t\ttoCopy := maxCopy\n\t\t\t}\n\n\t\t\t// store the length of the copied bytes\n\t\t\tmstore(returnData, toCopy)\n\n\t\t\t// copy the bytes from returndata[0:toCopy]\n\t\t\treturndatacopy(add(returnData, 0x20), 0, toCopy)\n\t\t}\n\t}\n\n\tfunction _functionCallWithValue(address target, bytes memory data, uint256 value, string memory error) private returns (bytes memory) {\n\t\tif (!isContract(target)) revert AddressUtils__NotContract();\n\n\t\t(bool success, bytes memory returnData) = target.call{ value: value }(data);\n\n\t\tif (success) {\n\t\t\treturn returnData;\n\t\t} else if (returnData.length > 0) {\n\t\t\tassembly {\n\t\t\t\tlet returnData_size := mload(returnData)\n\t\t\t\trevert(add(32, returnData), returnData_size)\n\t\t\t}\n\t\t} else {\n\t\t\trevert(error);\n\t\t}\n\t}\n}\n"
      },
      "contracts/utils/EnumerableSet.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\n/**\n * @title Set implementation with enumeration functions\n * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT license)\n */\nlibrary EnumerableSet {\n\terror EnumerableSet__IndexOutOfBounds();\n\n\tstruct Set {\n\t\tbytes32[] _values;\n\t\t// 1-indexed to allow 0 to signify nonexistence\n\t\tmapping(bytes32 => uint256) _indexes;\n\t}\n\n\tstruct Bytes32Set {\n\t\tSet _inner;\n\t}\n\n\tstruct AddressSet {\n\t\tSet _inner;\n\t}\n\n\tstruct UintSet {\n\t\tSet _inner;\n\t}\n\n\tfunction at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n\t\treturn _at(set._inner, index);\n\t}\n\n\tfunction at(AddressSet storage set, uint256 index) internal view returns (address) {\n\t\treturn address(uint160(uint256(_at(set._inner, index))));\n\t}\n\n\tfunction at(UintSet storage set, uint256 index) internal view returns (uint256) {\n\t\treturn uint256(_at(set._inner, index));\n\t}\n\n\tfunction contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n\t\treturn _contains(set._inner, value);\n\t}\n\n\tfunction contains(AddressSet storage set, address value) internal view returns (bool) {\n\t\treturn _contains(set._inner, bytes32(uint256(uint160(value))));\n\t}\n\n\tfunction contains(UintSet storage set, uint256 value) internal view returns (bool) {\n\t\treturn _contains(set._inner, bytes32(value));\n\t}\n\n\tfunction indexOf(Bytes32Set storage set, bytes32 value) internal view returns (uint256) {\n\t\treturn _indexOf(set._inner, value);\n\t}\n\n\tfunction indexOf(AddressSet storage set, address value) internal view returns (uint256) {\n\t\treturn _indexOf(set._inner, bytes32(uint256(uint160(value))));\n\t}\n\n\tfunction indexOf(UintSet storage set, uint256 value) internal view returns (uint256) {\n\t\treturn _indexOf(set._inner, bytes32(value));\n\t}\n\n\tfunction length(Bytes32Set storage set) internal view returns (uint256) {\n\t\treturn _length(set._inner);\n\t}\n\n\tfunction length(AddressSet storage set) internal view returns (uint256) {\n\t\treturn _length(set._inner);\n\t}\n\n\tfunction length(UintSet storage set) internal view returns (uint256) {\n\t\treturn _length(set._inner);\n\t}\n\n\tfunction add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n\t\treturn _add(set._inner, value);\n\t}\n\n\tfunction add(AddressSet storage set, address value) internal returns (bool) {\n\t\treturn _add(set._inner, bytes32(uint256(uint160(value))));\n\t}\n\n\tfunction add(UintSet storage set, uint256 value) internal returns (bool) {\n\t\treturn _add(set._inner, bytes32(value));\n\t}\n\n\tfunction remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n\t\treturn _remove(set._inner, value);\n\t}\n\n\tfunction remove(AddressSet storage set, address value) internal returns (bool) {\n\t\treturn _remove(set._inner, bytes32(uint256(uint160(value))));\n\t}\n\n\tfunction remove(UintSet storage set, uint256 value) internal returns (bool) {\n\t\treturn _remove(set._inner, bytes32(value));\n\t}\n\n\tfunction toArray(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n\t\treturn set._inner._values;\n\t}\n\n\tfunction toArray(AddressSet storage set) internal view returns (address[] memory) {\n\t\tbytes32[] storage values = set._inner._values;\n\t\taddress[] storage array;\n\n\t\tassembly {\n\t\t\tarray.slot := values.slot\n\t\t}\n\n\t\treturn array;\n\t}\n\n\tfunction toArray(UintSet storage set) internal view returns (uint256[] memory) {\n\t\tbytes32[] storage values = set._inner._values;\n\t\tuint256[] storage array;\n\n\t\tassembly {\n\t\t\tarray.slot := values.slot\n\t\t}\n\n\t\treturn array;\n\t}\n\n\tfunction _at(Set storage set, uint256 index) private view returns (bytes32) {\n\t\tif (index >= set._values.length) revert EnumerableSet__IndexOutOfBounds();\n\t\treturn set._values[index];\n\t}\n\n\tfunction _contains(Set storage set, bytes32 value) private view returns (bool) {\n\t\treturn set._indexes[value] != 0;\n\t}\n\n\tfunction _indexOf(Set storage set, bytes32 value) private view returns (uint256) {\n\t\tunchecked {\n\t\t\treturn set._indexes[value] - 1;\n\t\t}\n\t}\n\n\tfunction _length(Set storage set) private view returns (uint256) {\n\t\treturn set._values.length;\n\t}\n\n\tfunction _add(Set storage set, bytes32 value) private returns (bool status) {\n\t\tif (!_contains(set, value)) {\n\t\t\tset._values.push(value);\n\t\t\tset._indexes[value] = set._values.length;\n\t\t\tstatus = true;\n\t\t}\n\t}\n\n\tfunction _remove(Set storage set, bytes32 value) private returns (bool status) {\n\t\tuint256 valueIndex = set._indexes[value];\n\n\t\tif (valueIndex != 0) {\n\t\t\tunchecked {\n\t\t\t\tbytes32 last = set._values[set._values.length - 1];\n\n\t\t\t\t// move last value to now-vacant index\n\n\t\t\t\tset._values[valueIndex - 1] = last;\n\t\t\t\tset._indexes[last] = valueIndex;\n\t\t\t}\n\t\t\t// clear last index\n\n\t\t\tset._values.pop();\n\t\t\tdelete set._indexes[value];\n\n\t\t\tstatus = true;\n\t\t}\n\t}\n}\n"
      },
      "contracts/utils/Math.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\nlibrary Math {\n\t/**\n\t * @notice calculate the absolute value of a number\n\t * @param a number whose absoluve value to calculate\n\t * @return absolute value\n\t */\n\tfunction abs(int256 a) internal pure returns (uint256) {\n\t\treturn uint256(a < 0 ? -a : a);\n\t}\n\n\t/**\n\t * @notice select the greater of two numbers\n\t * @param a first number\n\t * @param b second number\n\t * @return greater number\n\t */\n\tfunction max(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\treturn a > b ? a : b;\n\t}\n\n\t/**\n\t * @notice select the lesser of two numbers\n\t * @param a first number\n\t * @param b second number\n\t * @return lesser number\n\t */\n\tfunction min(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\treturn a > b ? b : a;\n\t}\n\n\t/**\n\t * @notice calculate the average of two numbers, rounded down\n\t * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT license)\n\t * @param a first number\n\t * @param b second number\n\t * @return mean value\n\t */\n\tfunction average(uint256 a, uint256 b) internal pure returns (uint256) {\n\t\tunchecked {\n\t\t\treturn (a & b) + ((a ^ b) >> 1);\n\t\t}\n\t}\n\n\t/**\n\t * @notice estimate square root of number\n\t * @dev uses Babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)\n\t * @param x input number\n\t * @return y square root\n\t */\n\tfunction sqrt(uint256 x) internal pure returns (uint256 y) {\n\t\tuint256 z = (x + 1) >> 1;\n\t\ty = x;\n\t\twhile (z < y) {\n\t\t\ty = z;\n\t\t\tz = (x / z + z) >> 1;\n\t\t}\n\t}\n}\n"
      },
      "contracts/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\r\n/**\r\n * Copyright (C) 2024 uSmart\r\n */\r\npragma solidity ^0.8.9;\r\n\r\nimport \"../base/ERC20/IERC20.sol\";\r\nimport { AddressUtils } from \"./AddressUtils.sol\";\r\n\r\nlibrary SafeERC20 {\r\n\terror SafeERC20FailedOperation(address token);\r\n\tusing AddressUtils for address;\r\n\r\n\tfunction safeTransfer(IERC20 token, address to, uint256 value) internal {\r\n\t\tbytes memory returndata = address(token).functionCall(abi.encodeCall(token.transfer, (to, value)));\r\n\t\tif (returndata.length != 0 && !abi.decode(returndata, (bool))) {\r\n\t\t\trevert SafeERC20FailedOperation(address(token));\r\n\t\t}\r\n\t}\r\n\r\n\tfunction safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\r\n\t\tbytes memory returndata = address(token).functionCall(abi.encodeCall(token.transferFrom, (from, to, value)));\r\n\t\tif (returndata.length != 0 && !abi.decode(returndata, (bool))) {\r\n\t\t\trevert SafeERC20FailedOperation(address(token));\r\n\t\t}\r\n\t}\r\n}\r\n"
      },
      "contracts/utils/UintUtils.sol": {
        "content": "// SPDX-License-Identifier: MIT\n/**\n * Copyright (C) 2024 uSmart\n */\npragma solidity ^0.8.9;\n\n/**\n * @title utility functions for uint256 operations\n * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts/ (MIT license)\n */\nlibrary UintUtils {\n\terror UintUtils__InsufficientHexLength();\n\n\tbytes16 private constant HEX_SYMBOLS = \"0123456789abcdef\";\n\n\tfunction add(uint256 a, int256 b) internal pure returns (uint256) {\n\t\treturn b < 0 ? sub(a, -b) : a + uint256(b);\n\t}\n\n\tfunction sub(uint256 a, int256 b) internal pure returns (uint256) {\n\t\treturn b < 0 ? add(a, -b) : a - uint256(b);\n\t}\n\n\tfunction toString(uint256 value) internal pure returns (string memory) {\n\t\tif (value == 0) {\n\t\t\treturn \"0\";\n\t\t}\n\n\t\tuint256 temp = value;\n\t\tuint256 digits;\n\n\t\twhile (temp != 0) {\n\t\t\tdigits++;\n\t\t\ttemp /= 10;\n\t\t}\n\n\t\tbytes memory buffer = new bytes(digits);\n\n\t\twhile (value != 0) {\n\t\t\tdigits -= 1;\n\t\t\tbuffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n\t\t\tvalue /= 10;\n\t\t}\n\n\t\treturn string(buffer);\n\t}\n\n\tfunction toHexString(uint256 value) internal pure returns (string memory) {\n\t\tif (value == 0) {\n\t\t\treturn \"0x00\";\n\t\t}\n\n\t\tuint256 length = 0;\n\n\t\tfor (uint256 temp = value; temp != 0; temp >>= 8) {\n\t\t\tunchecked {\n\t\t\t\tlength++;\n\t\t\t}\n\t\t}\n\n\t\treturn toHexString(value, length);\n\t}\n\n\tfunction toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n\t\tbytes memory buffer = new bytes(2 * length + 2);\n\t\tbuffer[0] = \"0\";\n\t\tbuffer[1] = \"x\";\n\n\t\tunchecked {\n\t\t\tfor (uint256 i = 2 * length + 1; i > 1; --i) {\n\t\t\t\tbuffer[i] = HEX_SYMBOLS[value & 0xf];\n\t\t\t\tvalue >>= 4;\n\t\t\t}\n\t\t}\n\n\t\tif (value != 0) revert UintUtils__InsufficientHexLength();\n\n\t\treturn string(buffer);\n\t}\n}\n"
      }
    },
    "settings": {
      "viaIR": false,
      "optimizer": {
        "enabled": false,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "metadata": {
        "useLiteralContent": true
      },
      "libraries": {}
    }
  }}