|
{
|
|
"language": "Solidity",
|
|
"sources": {
|
|
"contracts/upgradeability/RealTokenYamUpgradeableV3.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nimport { IERC20 } from \"../interfaces/IERC20.sol\";\nimport \"../interfaces/IRealTokenYamUpgradeableV3.sol\";\nimport \"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol\";\nimport \"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol\";\n\ncontract RealTokenYamUpgradeableV3 is\n PausableUpgradeable,\n AccessControlUpgradeable,\n UUPSUpgradeable,\n ReentrancyGuardUpgradeable,\n IRealTokenYamUpgradeableV3\n{\n bytes32 public constant UPGRADER_ROLE = keccak256(\"UPGRADER_ROLE\");\n bytes32 public constant MODERATOR_ROLE = keccak256(\"MODERATOR_ROLE\");\n\n mapping(uint256 => uint256) private prices;\n mapping(uint256 => uint256) private amounts;\n mapping(uint256 => address) private offerTokens;\n mapping(uint256 => address) private buyerTokens;\n mapping(uint256 => address) private sellers;\n mapping(uint256 => address) private buyers;\n mapping(address => TokenType) private tokenTypes;\n uint256 private offerCount;\n uint256 public fee; // fee in basis points\n\n /// @custom:oz-upgrades-unsafe-allow constructor\n constructor() {\n _disableInitializers();\n }\n\n /// @notice the initialize function to execute only once during the contract deployment\n /// @param admin_ address of the default admin account: whitelist tokens, delete frozen offers, upgrade the contract\n /// @param moderator_ address of the admin with unique responsibles\n function initialize(address admin_, address moderator_) external initializer {\n __AccessControl_init();\n __UUPSUpgradeable_init();\n\n _grantRole(DEFAULT_ADMIN_ROLE, admin_);\n _grantRole(UPGRADER_ROLE, admin_);\n _grantRole(MODERATOR_ROLE, moderator_);\n __ReentrancyGuard_init();\n }\n\n /// @notice The admin (with upgrader role) uses this function to update the contract\n /// @dev This function is always needed in future implementation contract versions, otherwise, the contract will not be upgradeable\n /// @param newImplementation is the address of the new implementation contract\n function _authorizeUpgrade(address newImplementation)\n internal\n override\n onlyRole(UPGRADER_ROLE)\n {}\n\n /**\n * @dev Only moderator or admin can call functions marked by this modifier.\n **/\n modifier onlyModeratorOrAdmin() {\n require(\n hasRole(MODERATOR_ROLE, _msgSender()) ||\n hasRole(DEFAULT_ADMIN_ROLE, _msgSender()),\n \"caller is not moderator or admin\"\n );\n _;\n }\n\n /**\n * @dev Only whitelisted token can be used by functions marked by this modifier.\n **/\n modifier onlyWhitelistTokenWithType(address token_) {\n require(\n tokenTypes[token_] != TokenType.NOTWHITELISTEDTOKEN,\n \"Token is not whitelisted\"\n );\n _;\n }\n\n function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {\n _pause();\n }\n\n function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {\n _unpause();\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function toggleWhitelistWithType(\n address[] calldata tokens_,\n TokenType[] calldata types_\n ) external override onlyRole(DEFAULT_ADMIN_ROLE) {\n uint256 length = tokens_.length;\n require(types_.length == length, \"Lengths are not equal\");\n for (uint256 i = 0; i < length; ) {\n tokenTypes[tokens_[i]] = types_[i];\n ++i;\n }\n emit TokenWhitelistWithTypeToggled(tokens_, types_);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function createOffer(\n address offerToken,\n address buyerToken,\n address buyer,\n uint256 price,\n uint256 amount\n ) public override whenNotPaused {\n // If the offerToken is a RealToken, isTransferValid need to be checked\n if (tokenTypes[offerToken] == TokenType.REALTOKEN) {\n require(\n _isTransferValid(offerToken, msg.sender, msg.sender, amount),\n \"Seller can not transfer tokens\"\n );\n }\n _createOffer(offerToken, buyerToken, buyer, price, amount);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function createOfferWithPermit(\n address offerToken,\n address buyerToken,\n address buyer,\n uint256 price,\n uint256 amount,\n uint256 newAllowance,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external override whenNotPaused {\n // If the offerToken is a RealToken, isTransferValid need to be checked\n if (tokenTypes[offerToken] == TokenType.REALTOKEN) {\n require(\n _isTransferValid(offerToken, msg.sender, msg.sender, amount),\n \"Seller can not transfer tokens\"\n );\n }\n\n // Create the offer\n _createOffer(offerToken, buyerToken, buyer, price, amount);\n\n IBridgeToken(offerToken).permit(\n msg.sender,\n address(this),\n newAllowance,\n deadline,\n v,\n r,\n s\n );\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function buy(\n uint256 offerId,\n uint256 price,\n uint256 amount\n ) external override whenNotPaused {\n _buy(offerId, price, amount);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function buyWithPermit(\n uint256 offerId,\n uint256 price,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external override whenNotPaused {\n // If the offerToken is a RealToken, isTransferValid need to be checked\n if (tokenTypes[offerTokens[offerId]] == TokenType.REALTOKEN) {\n require(\n _isTransferValid(\n offerTokens[offerId],\n sellers[offerId],\n msg.sender,\n amount\n ),\n \"transfer is not valid\"\n );\n }\n\n uint256 buyerTokenAmount = (price * amount) /\n (uint256(10)**IERC20(offerTokens[offerId]).decimals());\n IBridgeToken(buyerTokens[offerId]).permit(\n msg.sender,\n address(this),\n buyerTokenAmount,\n deadline,\n v,\n r,\n s\n );\n _buy(offerId, price, amount);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function updateOffer(\n uint256 offerId,\n uint256 price,\n uint256 amount\n ) external override whenNotPaused {\n _updateOffer(offerId, price, amount);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function updateOfferWithPermit(\n uint256 offerId,\n uint256 price,\n uint256 amount,\n uint256 newAllowance,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external override whenNotPaused {\n IBridgeToken(offerTokens[offerId]).permit(\n msg.sender,\n address(this),\n newAllowance,\n deadline,\n v,\n r,\n s\n );\n // Then update the offer\n _updateOffer(offerId, price, amount);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function deleteOffer(uint256 offerId) public override whenNotPaused {\n require(sellers[offerId] == msg.sender, \"only the seller can delete offer\");\n _deleteOffer(offerId);\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function deleteOfferBatch(uint256[] calldata offerIds)\n external\n override\n whenNotPaused\n {\n uint256 length = offerIds.length;\n for (uint256 i = 0; i < length; ) {\n deleteOffer(offerIds[i]);\n ++i;\n }\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function deleteOfferByAdmin(uint256[] calldata offerIds)\n external\n override\n onlyRole(DEFAULT_ADMIN_ROLE)\n {\n uint256 length = offerIds.length;\n for (uint256 i = 0; i < length; ) {\n _deleteOffer(offerIds[i]);\n ++i;\n }\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function getOfferCount() external view override returns (uint256) {\n return offerCount;\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function getTokenType(address token)\n external\n view\n override\n returns (TokenType)\n {\n return tokenTypes[token];\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function tokenInfo(address tokenAddr)\n external\n view\n override\n returns (\n uint256,\n string memory,\n string memory\n )\n {\n IERC20 tokenInterface = IERC20(tokenAddr);\n return (\n tokenInterface.decimals(),\n tokenInterface.symbol(),\n tokenInterface.name()\n );\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function getInitialOffer(uint256 offerId)\n external\n view\n override\n returns (\n address,\n address,\n address,\n address,\n uint256,\n uint256\n )\n {\n return (\n offerTokens[offerId],\n buyerTokens[offerId],\n sellers[offerId],\n buyers[offerId],\n prices[offerId],\n amounts[offerId]\n );\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function showOffer(uint256 offerId)\n external\n view\n override\n returns (\n address,\n address,\n address,\n address,\n uint256,\n uint256\n )\n {\n // get offerTokens balance and allowance, whichever is lower is the available amount\n uint256 availableBalance = IERC20(offerTokens[offerId]).balanceOf(\n sellers[offerId]\n );\n uint256 availableAllow = IERC20(offerTokens[offerId]).allowance(\n sellers[offerId],\n address(this)\n );\n uint256 availableAmount = amounts[offerId];\n\n if (availableBalance < availableAmount) {\n availableAmount = availableBalance;\n }\n\n if (availableAllow < availableAmount) {\n availableAmount = availableAllow;\n }\n\n return (\n offerTokens[offerId],\n buyerTokens[offerId],\n sellers[offerId],\n buyers[offerId],\n prices[offerId],\n availableAmount\n );\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function pricePreview(uint256 offerId, uint256 amount)\n external\n view\n override\n returns (uint256)\n {\n IERC20 offerTokenInterface = IERC20(offerTokens[offerId]);\n return\n (amount * prices[offerId]) /\n (uint256(10)**offerTokenInterface.decimals());\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function saveLostTokens(address token)\n external\n override\n onlyModeratorOrAdmin\n {\n IERC20 tokenInterface = IERC20(token);\n tokenInterface.transfer(\n msg.sender,\n tokenInterface.balanceOf(address(this))\n );\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function setFee(uint256 fee_) external override onlyRole(DEFAULT_ADMIN_ROLE) {\n emit FeeChanged(fee, fee_);\n fee = fee_;\n }\n\n /**\n * @notice Creates a new offer or updates an existing offer (call this again with the changed price + offerId)\n * @param _offerToken The address of the token to be sold\n * @param _buyerToken The address of the token to be bought\n * @param _price The price in base units of the token to be sold\n * @param _amount The amount of tokens to be sold\n **/\n function _createOffer(\n address _offerToken,\n address _buyerToken,\n address _buyer,\n uint256 _price,\n uint256 _amount\n )\n private\n onlyWhitelistTokenWithType(_offerToken)\n onlyWhitelistTokenWithType(_buyerToken)\n {\n // if no offerId is given a new offer is made, if offerId is given only the offers price is changed if owner matches\n uint256 _offerId = offerCount;\n offerCount++;\n if (_buyer != address(0)) {\n buyers[_offerId] = _buyer;\n }\n sellers[_offerId] = msg.sender;\n offerTokens[_offerId] = _offerToken;\n buyerTokens[_offerId] = _buyerToken;\n prices[_offerId] = _price;\n amounts[_offerId] = _amount;\n\n emit OfferCreated(\n _offerToken,\n _buyerToken,\n msg.sender,\n _buyer,\n _offerId,\n _price,\n _amount\n );\n }\n\n /**\n * @notice Creates a new offer or updates an existing offer (call this again with the changed price + offerId)\n * @param _offerId The address of the token to be sold\n * @param _price The address of the token to be bought\n * @param _amount The price in base units of the token to be sold\n **/\n function _updateOffer(\n uint256 _offerId,\n uint256 _price,\n uint256 _amount\n ) private {\n require(\n sellers[_offerId] == msg.sender,\n \"only the seller can change offer\"\n );\n emit OfferUpdated(\n _offerId,\n prices[_offerId],\n _price,\n amounts[_offerId],\n _amount\n );\n prices[_offerId] = _price;\n amounts[_offerId] = _amount;\n }\n\n /**\n * @notice Deletes an existing offer\n * @param _offerId The Id of the offer to be deleted\n **/\n function _deleteOffer(uint256 _offerId) private {\n delete sellers[_offerId];\n delete buyers[_offerId];\n delete offerTokens[_offerId];\n delete buyerTokens[_offerId];\n delete prices[_offerId];\n delete amounts[_offerId];\n emit OfferDeleted(_offerId);\n }\n\n /**\n * @notice Accepts an existing offer\n * @notice The buyer must bring the price correctly to ensure no frontrunning / changed offer\n * @notice If the offer is changed in meantime, it will not execute\n * @param _offerId The Id of the offer\n * @param _price The price in base units of the offer tokens\n * @param _amount The amount of offer tokens\n **/\n function _buy(\n uint256 _offerId,\n uint256 _price,\n uint256 _amount\n ) private {\n if (buyers[_offerId] != address(0)) {\n require(buyers[_offerId] == msg.sender, \"private offer\");\n }\n\n address seller = sellers[_offerId];\n address offerToken = offerTokens[_offerId];\n address buyerToken = buyerTokens[_offerId];\n\n IERC20 offerTokenInterface = IERC20(offerToken);\n IERC20 buyerTokenInterface = IERC20(buyerToken);\n\n // given price is being checked with recorded data from mappings\n require(prices[_offerId] == _price, \"offer price wrong\");\n\n // calculate the price of the order\n require(_amount <= amounts[_offerId], \"amount too high\");\n require(\n _amount * _price > (uint256(10)**offerTokenInterface.decimals()),\n \"amount too low\"\n );\n uint256 buyerTokenAmount = (_amount * _price) /\n (uint256(10)**offerTokenInterface.decimals());\n\n // some old erc20 tokens give no return value so we must work around by getting their balance before and after the exchange\n uint256 oldBuyerBalance = buyerTokenInterface.balanceOf(msg.sender);\n uint256 oldSellerBalance = offerTokenInterface.balanceOf(seller);\n\n // Update amount in mapping\n amounts[_offerId] = amounts[_offerId] - _amount;\n\n // finally do the exchange\n buyerTokenInterface.transferFrom(msg.sender, seller, buyerTokenAmount);\n offerTokenInterface.transferFrom(seller, msg.sender, _amount);\n\n // now check if the balances changed on both accounts.\n // we do not check for exact amounts since some tokens behave differently with fees, burnings, etc\n // we assume if both balances are higher than before all is good\n require(\n oldBuyerBalance > buyerTokenInterface.balanceOf(msg.sender),\n \"buyer error\"\n );\n require(\n oldSellerBalance > offerTokenInterface.balanceOf(seller),\n \"seller error\"\n );\n\n emit OfferAccepted(\n _offerId,\n seller,\n msg.sender,\n offerToken,\n buyerToken,\n _price,\n _amount\n );\n }\n\n /**\n * @notice Returns true if the transfer is valid, false otherwise\n * @param _token The token address\n * @param _from The sender address\n * @param _to The receiver address\n * @param _amount The amount of tokens to be transferred\n * @return Whether the transfer is valid\n **/\n function _isTransferValid(\n address _token,\n address _from,\n address _to,\n uint256 _amount\n ) private view returns (bool) {\n // Generalize verifying rules (for example: 11, 1, 12)\n (bool isTransferValid, , ) = IBridgeToken(_token).canTransfer(\n _from,\n _to,\n _amount\n );\n\n // If everything is fine, return true\n return isTransferValid;\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function createOfferBatch(\n address[] calldata _offerTokens,\n address[] calldata _buyerTokens,\n address[] calldata _buyers,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external override whenNotPaused {\n uint256 length = _offerTokens.length;\n require(\n _buyerTokens.length == length &&\n _buyers.length == length &&\n _prices.length == length &&\n _amounts.length == length,\n \"length mismatch\"\n );\n for (uint256 i = 0; i < length; ) {\n createOffer(\n _offerTokens[i],\n _buyerTokens[i],\n _buyers[i],\n _prices[i],\n _amounts[i]\n );\n ++i;\n }\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function updateOfferBatch(\n uint256[] calldata _offerIds,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external override whenNotPaused {\n uint256 length = _offerIds.length;\n require(\n _prices.length == length && _amounts.length == length,\n \"length mismatch\"\n );\n for (uint256 i = 0; i < length; ) {\n _updateOffer(_offerIds[i], _prices[i], _amounts[i]);\n ++i;\n }\n }\n\n /// @inheritdoc\tIRealTokenYamUpgradeableV3\n function buyOfferBatch(\n uint256[] calldata _offerIds,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external override whenNotPaused {\n uint256 length = _offerIds.length;\n require(\n _prices.length == length && _amounts.length == length,\n \"length mismatch\"\n );\n for (uint256 i = 0; i < length; ) {\n _buy(_offerIds[i], _prices[i], _amounts[i]);\n ++i;\n }\n }\n}\n"
|
|
},
|
|
"contracts/interfaces/IRealTokenYamUpgradeableV3.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\nimport \"./IBridgeToken.sol\";\nimport \"./IComplianceRegistry.sol\";\n\ninterface IRealTokenYamUpgradeableV3 {\n enum TokenType {\n NOTWHITELISTEDTOKEN,\n REALTOKEN,\n ERC20WITHPERMIT,\n ERC20WITHOUTPERMIT\n }\n\n /**\n * @dev Emitted after an offer is updated\n * @param tokens the token addresses\n **/\n event TokenWhitelistWithTypeToggled(\n address[] indexed tokens,\n TokenType[] indexed types\n );\n\n /**\n * @dev Emitted after an offer is created\n * @param offerToken the token you want to sell\n * @param buyerToken the token you want to buy\n * @param offerId the Id of the offer\n * @param price the price in baseunits of the token you want to sell\n * @param amount the amount of tokens you want to sell\n **/\n event OfferCreated(\n address indexed offerToken,\n address indexed buyerToken,\n address seller,\n address buyer,\n uint256 indexed offerId,\n uint256 price,\n uint256 amount\n );\n\n /**\n * @dev Emitted after an offer is updated\n * @param offerId the Id of the offer\n * @param oldPrice the old price of the token\n * @param newPrice the new price of the token\n * @param oldAmount the old amount of tokens\n * @param newAmount the new amount of tokens\n **/\n event OfferUpdated(\n uint256 indexed offerId,\n uint256 oldPrice,\n uint256 indexed newPrice,\n uint256 oldAmount,\n uint256 indexed newAmount\n );\n\n /**\n * @dev Emitted after an offer is deleted\n * @param offerId the Id of the offer to be deleted\n **/\n event OfferDeleted(uint256 indexed offerId);\n\n /**\n * @dev Emitted after an offer is accepted\n * @param offerId The Id of the offer that was accepted\n * @param seller the address of the seller\n * @param buyer the address of the buyer\n * @param price the price in baseunits of the token\n * @param amount the amount of tokens that the buyer bought\n **/\n event OfferAccepted(\n uint256 indexed offerId,\n address indexed seller,\n address indexed buyer,\n address offerToken,\n address buyerToken,\n uint256 price,\n uint256 amount\n );\n\n /**\n * @dev Emitted after an offer is deleted\n * @param oldFee the old fee basic points\n * @param newFee the new fee basic points\n **/\n event FeeChanged(uint256 indexed oldFee, uint256 indexed newFee);\n\n /**\n * @notice Creates a new offer or updates an existing offer\n * @param offerToken The address of the token to be sold\n * @param buyerToken The address of the token to be bought\n * @param buyer The address of the allowed buyer (zero address means anyone can buy)\n * @param price The price in base units of the token to be sold\n * @param amount The amount of the offer token\n **/\n function createOffer(\n address offerToken,\n address buyerToken,\n address buyer,\n uint256 price,\n uint256 amount\n ) external;\n\n /**\n * @notice Creates a new offer or updates an existing offer with permit\n * @param offerToken The address of the token to be sold\n * @param buyerToken The address of the token to be bought\n * @param buyer The address of the allowed buyer (zero address means anyone can buy)\n * @param price The price in base units of the token to be sold\n * @param amount The amount to be sold\n * @param newAllowance The amount to be permitted\n * @param deadline The deadline of the permit\n * @param v v of the signature\n * @param r r of the signature\n * @param s s of the signature\n **/\n function createOfferWithPermit(\n address offerToken,\n address buyerToken,\n address buyer,\n uint256 price,\n uint256 amount,\n uint256 newAllowance,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @notice Updates an existing offer\n * @param offerId The Id of the offer\n * @param price The price in base units of the token to be sold\n * @param amount The amount of the offer token\n **/\n function updateOffer(\n uint256 offerId,\n uint256 price,\n uint256 amount\n ) external;\n\n /**\n * @notice Updates an existing offer\n * @param offerId The Id of the offer\n * @param price The price in base units of the token to be sold\n * @param amount The amount of the offer token\n * @param newAllowance The amount to be permitted\n * @param deadline The deadline of the permit\n * @param v v of the signature\n * @param r r of the signature\n * @param s s of the signature\n **/\n function updateOfferWithPermit(\n uint256 offerId,\n uint256 price,\n uint256 amount,\n uint256 newAllowance,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @notice Deletes an existing offer, only the seller of the offer can do this\n * @param offerId The Id of the offer to be deleted\n **/\n function deleteOffer(uint256 offerId) external;\n\n /**\n * @notice Deletes an array of existing offers (for example in case tokens are frozen), only the admin can do this\n * @param offerIds The Ids array of the offers to be deleted\n **/\n function deleteOfferBatch(uint256[] calldata offerIds) external;\n\n /**\n * @notice Deletes an existing offer (for example in case tokens are frozen), only the admin can do this\n * @param offerIds The Id of the offer to be deleted\n **/\n function deleteOfferByAdmin(uint256[] calldata offerIds) external;\n\n /**\n * @notice Accepts an existing offer\n * @notice The buyer must bring the price correctly to ensure no frontrunning / changed offer\n * @notice If the offer is changed in meantime, it will not execute\n * @param offerId The Id of the offer\n * @param price The price in base units of the offer tokens\n * @param amount The amount of offer tokens\n **/\n function buy(\n uint256 offerId,\n uint256 price,\n uint256 amount\n ) external;\n\n /**\n * @notice Accepts an existing offer with permit\n * @notice The buyer must bring the price correctly to ensure no frontrunning / changed offer\n * @notice If the offer is changed in meantime, it will not execute\n * @param offerId The Id of the offer\n * @param price The price in base units of the offer tokens\n * @param amount The amount of offer tokens\n * @param deadline The deadline of the permit\n * @param v v of the signature\n * @param r r of the signature\n * @param s s of the signature\n **/\n function buyWithPermit(\n uint256 offerId,\n uint256 price,\n uint256 amount,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n\n /**\n * @notice Returns the offer count\n * @return offerCount The offer count\n **/\n // return the total number of offers to loop through all offers\n // its the web frontends job to keep track of offers\n function getOfferCount() external view returns (uint256);\n\n /**\n * @notice Returns the offer count\n * @return offerCount The offer count\n **/\n function getTokenType(address token) external view returns (TokenType);\n\n /**\n * @notice Returns the token information: decimals, symbole, name\n * @param tokenAddress The address of the reference asset of the distribution\n * @return The decimals of the token\n * @return The symbol of the token\n * @return The name of the token\n **/\n function tokenInfo(address tokenAddress)\n external\n view\n returns (\n uint256,\n string memory,\n string memory\n );\n\n /**\n * @notice Returns the offer information\n * @param offerId The offer Id\n * @return The offer token address\n * @return The buyer token address\n * @return The seller address\n * @return The buyer address\n * @return The price\n * @return The amount of the offer token\n **/\n function getInitialOffer(uint256 offerId)\n external\n view\n returns (\n address,\n address,\n address,\n address,\n uint256,\n uint256\n );\n\n /**\n * @notice Returns the offer information\n * @param offerId The offer Id\n * @return The offer token address\n * @return The buyer token address\n * @return The seller address\n * @return The buyer address\n * @return The price\n * @return The available balance\n **/\n function showOffer(uint256 offerId)\n external\n view\n returns (\n address,\n address,\n address,\n address,\n uint256,\n uint256\n );\n\n /**\n * @notice Returns price in buyertokens for the specified amount of offertokens\n * @param offerId The offer Id\n * @param amount The amount of offer tokens\n * @return The total amount to pay\n **/\n function pricePreview(uint256 offerId, uint256 amount)\n external\n view\n returns (uint256);\n\n /**\n * @notice Whitelist or unwhitelist a token\n * @param tokens The token addresses\n * @param types The token whitelist status, true for whitelisted and false for unwhitelisted\n **/\n function toggleWhitelistWithType(\n address[] calldata tokens,\n TokenType[] calldata types\n ) external;\n\n /**\n * @notice In case someone wrongfully directly sends erc20 to this contract address, the moderator can move them out\n * @param token The token address\n **/\n function saveLostTokens(address token) external;\n\n /**\n * @notice Admin sets the fee\n * @param fee The new fee basic points\n **/\n function setFee(uint256 fee) external;\n\n /**\n * @notice Creates a new offer or updates an existing offer (call this again with the changed price + offerId)\n * @param _offerTokens The array addresses of the tokens to be sold\n * @param _buyerTokens The array addresses of the tokens to be bought\n * @param _buyers The array addresses of the allowed buyers (zero address means anyone can buy)\n * @param _prices The array prices in base units of the tokens to be sold\n * @param _amounts The array amounts of the offer tokens\n **/\n function createOfferBatch(\n address[] calldata _offerTokens,\n address[] calldata _buyerTokens,\n address[] calldata _buyers,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external;\n\n /**\n * @notice Updates an array of existing offers\n * @param _offerIds The array Ids of the offers\n * @param _prices The array prices in base units of the tokens to be sold\n * @param _amounts The array amounts of the offer tokens\n **/\n function updateOfferBatch(\n uint256[] calldata _offerIds,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external;\n\n /**\n * @notice Accepts an existing offer\n * @notice The buyer must bring the price correctly to ensure no frontrunning / changed offer\n * @notice If the offer is changed in meantime, it will not execute\n * @param _offerIds The array Ids of the offers\n * @param _prices The array prices in base units of the offer tokens\n * @param _amounts The array amounts of offer tokens\n **/\n function buyOfferBatch(\n uint256[] calldata _offerIds,\n uint256[] calldata _prices,\n uint256[] calldata _amounts\n ) external;\n}\n"
|
|
},
|
|
"contracts/interfaces/IERC20.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IERC20 {\n function balanceOf(address account) external view returns (uint256);\n\n function allowance(address owner, address spender)\n external\n view\n returns (uint256);\n\n function approve(address spender, uint256 amount) external returns (bool);\n\n // no return value on transfer and transferFrom to tolerate old erc20 tokens\n // we work around that in the buy function by checking balance twice\n function transferFrom(\n address sender,\n address recipient,\n uint256 amount\n ) external;\n\n function transfer(address to, uint256 amount) external;\n\n function decimals() external view returns (uint256);\n\n function symbol() external view returns (string calldata);\n\n function name() external view returns (string calldata);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlUpgradeable.sol\";\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../utils/StringsUpgradeable.sol\";\nimport \"../utils/introspection/ERC165Upgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {\n function __AccessControl_init() internal onlyInitializing {\n }\n\n function __AccessControl_init_unchained() internal onlyInitializing {\n }\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n StringsUpgradeable.toHexString(uint160(account), 20),\n \" is missing role \",\n StringsUpgradeable.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleGranted} event.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n *\n * May emit a {RoleRevoked} event.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n *\n * May emit a {RoleRevoked} event.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * May emit a {RoleGranted} event.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleGranted} event.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n *\n * May emit a {RoleRevoked} event.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/utils/UUPSUpgradeable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../ERC1967/ERC1967UpgradeUpgradeable.sol\";\nimport \"./Initializable.sol\";\n\n/**\n * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an\n * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.\n *\n * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is\n * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing\n * `UUPSUpgradeable` with a custom implementation of upgrades.\n *\n * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.\n *\n * _Available since v4.1._\n */\nabstract contract UUPSUpgradeable is Initializable, IERC1822ProxiableUpgradeable, ERC1967UpgradeUpgradeable {\n function __UUPSUpgradeable_init() internal onlyInitializing {\n }\n\n function __UUPSUpgradeable_init_unchained() internal onlyInitializing {\n }\n /// @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment\n address private immutable __self = address(this);\n\n /**\n * @dev Check that the execution is being performed through a delegatecall call and that the execution context is\n * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case\n * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a\n * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to\n * fail.\n */\n modifier onlyProxy() {\n require(address(this) != __self, \"Function must be called through delegatecall\");\n require(_getImplementation() == __self, \"Function must be called through active proxy\");\n _;\n }\n\n /**\n * @dev Check that the execution is not being performed through a delegate call. This allows a function to be\n * callable on the implementing contract but not through proxies.\n */\n modifier notDelegated() {\n require(address(this) == __self, \"UUPSUpgradeable: must not be called through delegatecall\");\n _;\n }\n\n /**\n * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the\n * implementation. It is used to validate that the this implementation remains valid after an upgrade.\n *\n * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.\n */\n function proxiableUUID() external view virtual override notDelegated returns (bytes32) {\n return _IMPLEMENTATION_SLOT;\n }\n\n /**\n * @dev Upgrade the implementation of the proxy to `newImplementation`.\n *\n * Calls {_authorizeUpgrade}.\n *\n * Emits an {Upgraded} event.\n */\n function upgradeTo(address newImplementation) external virtual onlyProxy {\n _authorizeUpgrade(newImplementation);\n _upgradeToAndCallUUPS(newImplementation, new bytes(0), false);\n }\n\n /**\n * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call\n * encoded in `data`.\n *\n * Calls {_authorizeUpgrade}.\n *\n * Emits an {Upgraded} event.\n */\n function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual onlyProxy {\n _authorizeUpgrade(newImplementation);\n _upgradeToAndCallUUPS(newImplementation, data, true);\n }\n\n /**\n * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by\n * {upgradeTo} and {upgradeToAndCall}.\n *\n * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.\n *\n * ```solidity\n * function _authorizeUpgrade(address) internal override onlyOwner {}\n * ```\n */\n function _authorizeUpgrade(address newImplementation) internal virtual;\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/ContextUpgradeable.sol\";\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module which allows children to implement an emergency stop\n * mechanism that can be triggered by an authorized account.\n *\n * This module is used through inheritance. It will make available the\n * modifiers `whenNotPaused` and `whenPaused`, which can be applied to\n * the functions of your contract. Note that they will not be pausable by\n * simply including this module, only once the modifiers are put in place.\n */\nabstract contract PausableUpgradeable is Initializable, ContextUpgradeable {\n /**\n * @dev Emitted when the pause is triggered by `account`.\n */\n event Paused(address account);\n\n /**\n * @dev Emitted when the pause is lifted by `account`.\n */\n event Unpaused(address account);\n\n bool private _paused;\n\n /**\n * @dev Initializes the contract in unpaused state.\n */\n function __Pausable_init() internal onlyInitializing {\n __Pausable_init_unchained();\n }\n\n function __Pausable_init_unchained() internal onlyInitializing {\n _paused = false;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is not paused.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n modifier whenNotPaused() {\n _requireNotPaused();\n _;\n }\n\n /**\n * @dev Modifier to make a function callable only when the contract is paused.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n modifier whenPaused() {\n _requirePaused();\n _;\n }\n\n /**\n * @dev Returns true if the contract is paused, and false otherwise.\n */\n function paused() public view virtual returns (bool) {\n return _paused;\n }\n\n /**\n * @dev Throws if the contract is paused.\n */\n function _requireNotPaused() internal view virtual {\n require(!paused(), \"Pausable: paused\");\n }\n\n /**\n * @dev Throws if the contract is not paused.\n */\n function _requirePaused() internal view virtual {\n require(paused(), \"Pausable: not paused\");\n }\n\n /**\n * @dev Triggers stopped state.\n *\n * Requirements:\n *\n * - The contract must not be paused.\n */\n function _pause() internal virtual whenNotPaused {\n _paused = true;\n emit Paused(_msgSender());\n }\n\n /**\n * @dev Returns to normal state.\n *\n * Requirements:\n *\n * - The contract must be paused.\n */\n function _unpause() internal virtual whenPaused {\n _paused = false;\n emit Unpaused(_msgSender());\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Contract module that helps prevent reentrant calls to a function.\n *\n * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier\n * available, which can be applied to functions to make sure there are no nested\n * (reentrant) calls to them.\n *\n * Note that because there is a single `nonReentrant` guard, functions marked as\n * `nonReentrant` may not call one another. This can be worked around by making\n * those functions `private`, and then adding `external` `nonReentrant` entry\n * points to them.\n *\n * TIP: If you would like to learn more about reentrancy and alternative ways\n * to protect against it, check out our blog post\n * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].\n */\nabstract contract ReentrancyGuardUpgradeable is Initializable {\n // Booleans are more expensive than uint256 or any type that takes up a full\n // word because each write operation emits an extra SLOAD to first read the\n // slot's contents, replace the bits taken up by the boolean, and then write\n // back. This is the compiler's defense against contract upgrades and\n // pointer aliasing, and it cannot be disabled.\n\n // The values being non-zero value makes deployment a bit more expensive,\n // but in exchange the refund on every call to nonReentrant will be lower in\n // amount. Since refunds are capped to a percentage of the total\n // transaction's gas, it is best to keep them low in cases like this one, to\n // increase the likelihood of the full refund coming into effect.\n uint256 private constant _NOT_ENTERED = 1;\n uint256 private constant _ENTERED = 2;\n\n uint256 private _status;\n\n function __ReentrancyGuard_init() internal onlyInitializing {\n __ReentrancyGuard_init_unchained();\n }\n\n function __ReentrancyGuard_init_unchained() internal onlyInitializing {\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev Prevents a contract from calling itself, directly or indirectly.\n * Calling a `nonReentrant` function from another `nonReentrant`\n * function is not supported. It is possible to prevent this from happening\n * by making the `nonReentrant` function external, and making it call a\n * `private` function that does the actual work.\n */\n modifier nonReentrant() {\n // On the first call to nonReentrant, _notEntered will be true\n require(_status != _ENTERED, \"ReentrancyGuard: reentrant call\");\n\n // Any calls to nonReentrant after this point will fail\n _status = _ENTERED;\n\n _;\n\n // By storing the original value once again, a refund is triggered (see\n // https://eips.ethereum.org/EIPS/eip-2200)\n _status = _NOT_ENTERED;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[49] private __gap;\n}\n"
|
|
},
|
|
"contracts/interfaces/IComplianceRegistry.sol": {
|
|
"content": "// SPDX-License-Identifier: CNU\n\n/*\n Copyright (c) 2019 Mt Pelerin Group Ltd\n\n This program is free software; you can redistribute it and/or modify\n it under the terms of the GNU Affero General Public License version 3\n as published by the Free Software Foundation with the addition of the\n following permission added to Section 15 as permitted in Section 7(a):\n FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY\n MT PELERIN GROUP LTD. MT PELERIN GROUP LTD DISCLAIMS THE WARRANTY OF NON INFRINGEMENT\n OF THIRD PARTY RIGHTS\n\n This program is distributed in the hope that it will be useful, but\n WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n or FITNESS FOR A PARTICULAR PURPOSE.\n See the GNU Affero General Public License for more details.\n You should have received a copy of the GNU Affero General Public License\n along with this program; if not, see http://www.gnu.org/licenses or write to\n the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,\n Boston, MA, 02110-1301 USA, or download the license from the following URL:\n https://www.gnu.org/licenses/agpl-3.0.fr.html\n\n The interactive user interfaces in modified source and object code versions\n of this program must display Appropriate Legal Notices, as required under\n Section 5 of the GNU Affero General Public License.\n\n You can be released from the requirements of the license by purchasing\n a commercial license. Buying such a license is mandatory as soon as you\n develop commercial activities involving Mt Pelerin Group Ltd software without\n disclosing the source code of your own applications.\n These activities include: offering paid services based/using this product to customers,\n using this product in any application, distributing this product with a closed\n source product.\n\n For more information, please contact Mt Pelerin Group Ltd at this\n address: hello@mtpelerin.com\n*/\n\npragma solidity ^0.8.0;\n\n/**\n * @title IComplianceRegistry\n * @dev IComplianceRegistry interface\n **/\ninterface IComplianceRegistry {\n event AddressAttached(\n address indexed trustedIntermediary,\n uint256 indexed userId,\n address indexed address_\n );\n event AddressDetached(\n address indexed trustedIntermediary,\n uint256 indexed userId,\n address indexed address_\n );\n\n function userId(address[] calldata _trustedIntermediaries, address _address)\n external\n view\n returns (uint256, address);\n\n function validUntil(address _trustedIntermediary, uint256 _userId)\n external\n view\n returns (uint256);\n\n function attribute(\n address _trustedIntermediary,\n uint256 _userId,\n uint256 _key\n ) external view returns (uint256);\n\n function attributes(\n address _trustedIntermediary,\n uint256 _userId,\n uint256[] calldata _keys\n ) external view returns (uint256[] memory);\n\n function isAddressValid(\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (bool);\n\n function isValid(address _trustedIntermediary, uint256 _userId)\n external\n view\n returns (bool);\n\n function registerUser(\n address _address,\n uint256[] calldata _attributeKeys,\n uint256[] calldata _attributeValues\n ) external;\n\n function registerUsers(\n address[] calldata _addresses,\n uint256[] calldata _attributeKeys,\n uint256[] calldata _attributeValues\n ) external;\n\n function attachAddress(uint256 _userId, address _address) external;\n\n function attachAddresses(\n uint256[] calldata _userIds,\n address[] calldata _addresses\n ) external;\n\n function detachAddress(address _address) external;\n\n function detachAddresses(address[] calldata _addresses) external;\n\n function updateUserAttributes(\n uint256 _userId,\n uint256[] calldata _attributeKeys,\n uint256[] calldata _attributeValues\n ) external;\n\n function updateUsersAttributes(\n uint256[] calldata _userIds,\n uint256[] calldata _attributeKeys,\n uint256[] calldata _attributeValues\n ) external;\n\n function updateTransfers(\n address _realm,\n address _from,\n address _to,\n uint256 _value\n ) external;\n\n function monthlyTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function yearlyTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function monthlyInTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function yearlyInTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function monthlyOutTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function yearlyOutTransfers(\n address _realm,\n address[] calldata _trustedIntermediaries,\n address _address\n ) external view returns (uint256);\n\n function addOnHoldTransfer(\n address trustedIntermediary,\n address token,\n address from,\n address to,\n uint256 amount\n ) external;\n\n function getOnHoldTransfers(address trustedIntermediary)\n external\n view\n returns (\n uint256 length,\n uint256[] memory id,\n address[] memory token,\n address[] memory from,\n address[] memory to,\n uint256[] memory amount\n );\n\n function processOnHoldTransfers(\n uint256[] calldata transfers,\n uint8[] calldata transferDecisions,\n bool skipMinBoundaryUpdate\n ) external;\n\n function updateOnHoldMinBoundary(uint256 maxIterations) external;\n\n event TransferOnHold(\n address indexed trustedIntermediary,\n address indexed token,\n address indexed from,\n address to,\n uint256 amount\n );\n event TransferApproved(\n address indexed trustedIntermediary,\n address indexed token,\n address indexed from,\n address to,\n uint256 amount\n );\n event TransferRejected(\n address indexed trustedIntermediary,\n address indexed token,\n address indexed from,\n address to,\n uint256 amount\n );\n event TransferCancelled(\n address indexed trustedIntermediary,\n address indexed token,\n address indexed from,\n address to,\n uint256 amount\n );\n}\n"
|
|
},
|
|
"contracts/interfaces/IBridgeToken.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\ninterface IBridgeToken {\n function rules() external view returns (uint256[] memory, uint256[] memory);\n\n function rule(uint256 ruleId) external view returns (uint256, uint256);\n\n function owner() external view returns (address);\n\n function allowance(address _owner, address _spender)\n external\n view\n returns (uint256);\n\n function transferFrom(\n address _from,\n address _to,\n uint256 _value\n ) external returns (bool);\n\n function canTransfer(\n address _from,\n address _to,\n uint256 _amount\n )\n external\n view\n returns (\n bool,\n uint256,\n uint256\n );\n\n function permit(\n address owner,\n address spender,\n uint256 value,\n uint256 deadline,\n uint8 v,\n bytes32 r,\n bytes32 s\n ) external;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\nimport \"../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract ContextUpgradeable is Initializable {\n function __Context_init() internal onlyInitializing {\n }\n\n function __Context_init_unchained() internal onlyInitializing {\n }\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/StringsUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary StringsUpgradeable {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n uint8 private constant _ADDRESS_LENGTH = 20;\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n\n /**\n * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.\n */\n function toHexString(address addr) internal pure returns (string memory) {\n return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../../utils/AddressUpgradeable.sol\";\n\n/**\n * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed\n * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an\n * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer\n * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.\n *\n * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be\n * reused. This mechanism prevents re-execution of each \"step\" but allows the creation of new initialization steps in\n * case an upgrade adds a module that needs to be initialized.\n *\n * For example:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * contract MyToken is ERC20Upgradeable {\n * function initialize() initializer public {\n * __ERC20_init(\"MyToken\", \"MTK\");\n * }\n * }\n * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {\n * function initializeV2() reinitializer(2) public {\n * __ERC20Permit_init(\"MyToken\");\n * }\n * }\n * ```\n *\n * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as\n * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.\n *\n * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure\n * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.\n *\n * [CAUTION]\n * ====\n * Avoid leaving a contract uninitialized.\n *\n * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation\n * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke\n * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:\n *\n * [.hljs-theme-light.nopadding]\n * ```\n * /// @custom:oz-upgrades-unsafe-allow constructor\n * constructor() {\n * _disableInitializers();\n * }\n * ```\n * ====\n */\nabstract contract Initializable {\n /**\n * @dev Indicates that the contract has been initialized.\n * @custom:oz-retyped-from bool\n */\n uint8 private _initialized;\n\n /**\n * @dev Indicates that the contract is in the process of being initialized.\n */\n bool private _initializing;\n\n /**\n * @dev Triggered when the contract has been initialized or reinitialized.\n */\n event Initialized(uint8 version);\n\n /**\n * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,\n * `onlyInitializing` functions can be used to initialize parent contracts. Equivalent to `reinitializer(1)`.\n */\n modifier initializer() {\n bool isTopLevelCall = !_initializing;\n require(\n (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),\n \"Initializable: contract is already initialized\"\n );\n _initialized = 1;\n if (isTopLevelCall) {\n _initializing = true;\n }\n _;\n if (isTopLevelCall) {\n _initializing = false;\n emit Initialized(1);\n }\n }\n\n /**\n * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the\n * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be\n * used to initialize parent contracts.\n *\n * `initializer` is equivalent to `reinitializer(1)`, so a reinitializer may be used after the original\n * initialization step. This is essential to configure modules that are added through upgrades and that require\n * initialization.\n *\n * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in\n * a contract, executing them in the right order is up to the developer or operator.\n */\n modifier reinitializer(uint8 version) {\n require(!_initializing && _initialized < version, \"Initializable: contract is already initialized\");\n _initialized = version;\n _initializing = true;\n _;\n _initializing = false;\n emit Initialized(version);\n }\n\n /**\n * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the\n * {initializer} and {reinitializer} modifiers, directly or indirectly.\n */\n modifier onlyInitializing() {\n require(_initializing, \"Initializable: contract is not initializing\");\n _;\n }\n\n /**\n * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.\n * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized\n * to any version. It is recommended to use this to lock implementation contracts that are designed to be called\n * through proxies.\n */\n function _disableInitializers() internal virtual {\n require(!_initializing, \"Initializable: contract is initializing\");\n if (_initialized < type(uint8).max) {\n _initialized = type(uint8).max;\n emit Initialized(type(uint8).max);\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/access/IAccessControlUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControlUpgradeable {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/introspection/ERC165Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165Upgradeable.sol\";\nimport \"../../proxy/utils/Initializable.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {\n function __ERC165_init() internal onlyInitializing {\n }\n\n function __ERC165_init_unchained() internal onlyInitializing {\n }\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165Upgradeable).interfaceId;\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary AddressUpgradeable {\n /**\n * @dev Returns true if `account` is a contract.\n *\n * [IMPORTANT]\n * ====\n * It is unsafe to assume that an address for which this function returns\n * false is an externally-owned account (EOA) and not a contract.\n *\n * Among others, `isContract` will return false for the following\n * types of addresses:\n *\n * - an externally-owned account\n * - a contract in construction\n * - an address where a contract will be created\n * - an address where a contract lived, but was destroyed\n * ====\n *\n * [IMPORTANT]\n * ====\n * You shouldn't rely on `isContract` to protect against flash loan attacks!\n *\n * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n * constructor.\n * ====\n */\n function isContract(address account) internal view returns (bool) {\n // This method relies on extcodesize/address.code.length, which returns 0\n // for contracts in construction, since the code is only stored at the end\n // of the constructor execution.\n\n return account.code.length > 0;\n }\n\n /**\n * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n * `recipient`, forwarding all available gas and reverting on errors.\n *\n * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n * of certain opcodes, possibly making contracts go over the 2300 gas limit\n * imposed by `transfer`, making them unable to receive funds via\n * `transfer`. {sendValue} removes this limitation.\n *\n * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n *\n * IMPORTANT: because control is transferred to `recipient`, care must be\n * taken to not create reentrancy vulnerabilities. Consider using\n * {ReentrancyGuard} or the\n * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n */\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n (bool success, ) = recipient.call{value: amount}(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n /**\n * @dev Performs a Solidity function call using a low level `call`. A\n * plain `call` is an unsafe replacement for a function call: use this\n * function instead.\n *\n * If `target` reverts with a revert reason, it is bubbled up by this\n * function (like regular Solidity function calls).\n *\n * Returns the raw returned data. To convert to the expected return value,\n * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n *\n * Requirements:\n *\n * - `target` must be a contract.\n * - calling `target` with `data` must not revert.\n *\n * _Available since v3.1._\n */\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n * `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, 0, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but also transferring `value` wei to `target`.\n *\n * Requirements:\n *\n * - the calling contract must have an ETH balance of at least `value`.\n * - the called Solidity function must be `payable`.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n * with `errorMessage` as a fallback revert reason when `target` reverts.\n *\n * _Available since v3.1._\n */\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{value: value}(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n return functionStaticCall(target, data, \"Address: low-level static call failed\");\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a static call.\n *\n * _Available since v3.3._\n */\n function functionStaticCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal view returns (bytes memory) {\n require(isContract(target), \"Address: static call to non-contract\");\n\n (bool success, bytes memory returndata) = target.staticcall(data);\n return verifyCallResult(success, returndata, errorMessage);\n }\n\n /**\n * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the\n * revert reason using the provided one.\n *\n * _Available since v4.3._\n */\n function verifyCallResult(\n bool success,\n bytes memory returndata,\n string memory errorMessage\n ) internal pure returns (bytes memory) {\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n /// @solidity memory-safe-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/introspection/IERC165Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165Upgradeable {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/interfaces/draft-IERC1822Upgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (interfaces/draft-IERC1822.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified\n * proxy whose upgrades are fully controlled by the current implementation.\n */\ninterface IERC1822ProxiableUpgradeable {\n /**\n * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation\n * address.\n *\n * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks\n * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this\n * function revert if invoked through a proxy.\n */\n function proxiableUUID() external view returns (bytes32);\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/ERC1967/ERC1967UpgradeUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (proxy/ERC1967/ERC1967Upgrade.sol)\n\npragma solidity ^0.8.2;\n\nimport \"../beacon/IBeaconUpgradeable.sol\";\nimport \"../../interfaces/draft-IERC1822Upgradeable.sol\";\nimport \"../../utils/AddressUpgradeable.sol\";\nimport \"../../utils/StorageSlotUpgradeable.sol\";\nimport \"../utils/Initializable.sol\";\n\n/**\n * @dev This abstract contract provides getters and event emitting update functions for\n * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.\n *\n * _Available since v4.1._\n *\n * @custom:oz-upgrades-unsafe-allow delegatecall\n */\nabstract contract ERC1967UpgradeUpgradeable is Initializable {\n function __ERC1967Upgrade_init() internal onlyInitializing {\n }\n\n function __ERC1967Upgrade_init_unchained() internal onlyInitializing {\n }\n // This is the keccak-256 hash of \"eip1967.proxy.rollback\" subtracted by 1\n bytes32 private constant _ROLLBACK_SLOT = 0x4910fdfa16fed3260ed0e7147f7cc6da11a60208b5b9406d12a635614ffd9143;\n\n /**\n * @dev Storage slot with the address of the current implementation.\n * This is the keccak-256 hash of \"eip1967.proxy.implementation\" subtracted by 1, and is\n * validated in the constructor.\n */\n bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n\n /**\n * @dev Emitted when the implementation is upgraded.\n */\n event Upgraded(address indexed implementation);\n\n /**\n * @dev Returns the current implementation address.\n */\n function _getImplementation() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n }\n\n /**\n * @dev Stores a new address in the EIP1967 implementation slot.\n */\n function _setImplementation(address newImplementation) private {\n require(AddressUpgradeable.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n StorageSlotUpgradeable.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n }\n\n /**\n * @dev Perform implementation upgrade\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeTo(address newImplementation) internal {\n _setImplementation(newImplementation);\n emit Upgraded(newImplementation);\n }\n\n /**\n * @dev Perform implementation upgrade with additional setup call.\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeToAndCall(\n address newImplementation,\n bytes memory data,\n bool forceCall\n ) internal {\n _upgradeTo(newImplementation);\n if (data.length > 0 || forceCall) {\n _functionDelegateCall(newImplementation, data);\n }\n }\n\n /**\n * @dev Perform implementation upgrade with security checks for UUPS proxies, and additional setup call.\n *\n * Emits an {Upgraded} event.\n */\n function _upgradeToAndCallUUPS(\n address newImplementation,\n bytes memory data,\n bool forceCall\n ) internal {\n // Upgrades from old implementations will perform a rollback test. This test requires the new\n // implementation to upgrade back to the old, non-ERC1822 compliant, implementation. Removing\n // this special case will break upgrade paths from old UUPS implementation to new ones.\n if (StorageSlotUpgradeable.getBooleanSlot(_ROLLBACK_SLOT).value) {\n _setImplementation(newImplementation);\n } else {\n try IERC1822ProxiableUpgradeable(newImplementation).proxiableUUID() returns (bytes32 slot) {\n require(slot == _IMPLEMENTATION_SLOT, \"ERC1967Upgrade: unsupported proxiableUUID\");\n } catch {\n revert(\"ERC1967Upgrade: new implementation is not UUPS\");\n }\n _upgradeToAndCall(newImplementation, data, forceCall);\n }\n }\n\n /**\n * @dev Storage slot with the admin of the contract.\n * This is the keccak-256 hash of \"eip1967.proxy.admin\" subtracted by 1, and is\n * validated in the constructor.\n */\n bytes32 internal constant _ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;\n\n /**\n * @dev Emitted when the admin account has changed.\n */\n event AdminChanged(address previousAdmin, address newAdmin);\n\n /**\n * @dev Returns the current admin.\n */\n function _getAdmin() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value;\n }\n\n /**\n * @dev Stores a new address in the EIP1967 admin slot.\n */\n function _setAdmin(address newAdmin) private {\n require(newAdmin != address(0), \"ERC1967: new admin is the zero address\");\n StorageSlotUpgradeable.getAddressSlot(_ADMIN_SLOT).value = newAdmin;\n }\n\n /**\n * @dev Changes the admin of the proxy.\n *\n * Emits an {AdminChanged} event.\n */\n function _changeAdmin(address newAdmin) internal {\n emit AdminChanged(_getAdmin(), newAdmin);\n _setAdmin(newAdmin);\n }\n\n /**\n * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.\n * This is bytes32(uint256(keccak256('eip1967.proxy.beacon')) - 1)) and is validated in the constructor.\n */\n bytes32 internal constant _BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;\n\n /**\n * @dev Emitted when the beacon is upgraded.\n */\n event BeaconUpgraded(address indexed beacon);\n\n /**\n * @dev Returns the current beacon.\n */\n function _getBeacon() internal view returns (address) {\n return StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value;\n }\n\n /**\n * @dev Stores a new beacon in the EIP1967 beacon slot.\n */\n function _setBeacon(address newBeacon) private {\n require(AddressUpgradeable.isContract(newBeacon), \"ERC1967: new beacon is not a contract\");\n require(\n AddressUpgradeable.isContract(IBeaconUpgradeable(newBeacon).implementation()),\n \"ERC1967: beacon implementation is not a contract\"\n );\n StorageSlotUpgradeable.getAddressSlot(_BEACON_SLOT).value = newBeacon;\n }\n\n /**\n * @dev Perform beacon upgrade with additional setup call. Note: This upgrades the address of the beacon, it does\n * not upgrade the implementation contained in the beacon (see {UpgradeableBeacon-_setImplementation} for that).\n *\n * Emits a {BeaconUpgraded} event.\n */\n function _upgradeBeaconToAndCall(\n address newBeacon,\n bytes memory data,\n bool forceCall\n ) internal {\n _setBeacon(newBeacon);\n emit BeaconUpgraded(newBeacon);\n if (data.length > 0 || forceCall) {\n _functionDelegateCall(IBeaconUpgradeable(newBeacon).implementation(), data);\n }\n }\n\n /**\n * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n * but performing a delegate call.\n *\n * _Available since v3.4._\n */\n function _functionDelegateCall(address target, bytes memory data) private returns (bytes memory) {\n require(AddressUpgradeable.isContract(target), \"Address: delegate call to non-contract\");\n\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory returndata) = target.delegatecall(data);\n return AddressUpgradeable.verifyCallResult(success, returndata, \"Address: low-level delegate call failed\");\n }\n\n /**\n * @dev This empty reserved space is put in place to allow future versions to add new\n * variables without shifting down storage in the inheritance chain.\n * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps\n */\n uint256[50] private __gap;\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/utils/StorageSlotUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.7.0) (utils/StorageSlot.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for reading and writing primitive types to specific storage slots.\n *\n * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.\n * This library helps with reading and writing to such slots without the need for inline assembly.\n *\n * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.\n *\n * Example usage to set ERC1967 implementation slot:\n * ```\n * contract ERC1967 {\n * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;\n *\n * function _getImplementation() internal view returns (address) {\n * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;\n * }\n *\n * function _setImplementation(address newImplementation) internal {\n * require(Address.isContract(newImplementation), \"ERC1967: new implementation is not a contract\");\n * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;\n * }\n * }\n * ```\n *\n * _Available since v4.1 for `address`, `bool`, `bytes32`, and `uint256`._\n */\nlibrary StorageSlotUpgradeable {\n struct AddressSlot {\n address value;\n }\n\n struct BooleanSlot {\n bool value;\n }\n\n struct Bytes32Slot {\n bytes32 value;\n }\n\n struct Uint256Slot {\n uint256 value;\n }\n\n /**\n * @dev Returns an `AddressSlot` with member `value` located at `slot`.\n */\n function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `BooleanSlot` with member `value` located at `slot`.\n */\n function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.\n */\n function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n\n /**\n * @dev Returns an `Uint256Slot` with member `value` located at `slot`.\n */\n function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {\n /// @solidity memory-safe-assembly\n assembly {\n r.slot := slot\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin/contracts-upgradeable/proxy/beacon/IBeaconUpgradeable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (proxy/beacon/IBeacon.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev This is the interface that {BeaconProxy} expects of its beacon.\n */\ninterface IBeaconUpgradeable {\n /**\n * @dev Must return an address that can be used as a delegate call target.\n *\n * {BeaconProxy} will check that this address is a contract.\n */\n function implementation() external view returns (address);\n}\n"
|
|
}
|
|
},
|
|
"settings": {
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 200
|
|
},
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
},
|
|
"libraries": {}
|
|
}
|
|
} |