├── .gitignore ├── README.md ├── contracts ├── BaseGET.sol ├── EIP1155 │ ├── README.md │ └── contracts │ │ ├── BaseGET1155.sol │ │ ├── ERC1155Upgradeable.sol │ │ ├── EconomicsGET.sol │ │ ├── FoundationContract.sol │ │ ├── GETERC1155.sol │ │ ├── GETProtocolConfigurationV2.sol │ │ └── ProxyAdmin.sol ├── EconomicsGET.sol ├── EventMetadataStorage.sol ├── FoundationContract.sol ├── GETProtocolConfigurationV2.sol ├── GetEventFinancing.sol ├── README.md ├── interfaces │ ├── IBaseGET.sol │ ├── IBasketVault.sol │ ├── IERC165.sol │ ├── IERC20.sol │ ├── IERC721.sol │ ├── IERC721TokenVault.sol │ ├── IERC721VaultFactory.sol │ ├── IEconomicsGET.sol │ ├── IEventFinancing.sol │ ├── IEventMetadataStorage.sol │ ├── IGETAccessControl.sol │ ├── IGETProtocolConfiguration.sol │ ├── IIndexERC721.sol │ ├── IIndexERC721Factory.sol │ ├── INFT_ERC721.sol │ ├── INFT_ERC721V3.sol │ ├── IOracleGET.sol │ ├── ISettingsCollateral.sol │ ├── IUniswapV2Pair.sol │ ├── IfoundationContract.sol │ └── IsyncConfiguration.sol ├── oracles │ ├── OracleHelper.sol │ └── data │ │ └── oracledata.js ├── previous_deployments │ ├── AccessControlGET.sol │ ├── AccessControlGETV2.sol │ ├── GETProtocolConfiguration.sol │ ├── MockGET.sol │ ├── MockUSDC.sol │ ├── README.MD │ ├── getNFT_ERC721.sol │ ├── getNFT_ERC721V2.sol │ └── getNFT_ERC721V3.sol └── utils │ ├── AddressUpgradeable.sol │ ├── ContextUpgradeable.sol │ ├── CountersUpgradeable.sol │ ├── ERC165Upgradeable.sol │ ├── EnumerableMapUpgradeable.sol │ ├── EnumerableSetUpgradeable.sol │ ├── IERC165Upgradeable.sol │ ├── Initializable.sol │ ├── Migrations.sol │ ├── OwnableUpgradeable.sol │ ├── ReentrancyGuardUpgradeable.sol │ ├── SafeMathUpgradeable.sol │ └── StringsUpgradeable.sol └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | truffle.js 2 | contracts/research/ 3 | .openzeppelin/ 4 | artifacts/ 5 | cache/ 6 | contracts_copy/ 7 | migrations_copy/ 8 | node_modules/ 9 | test/ 10 | hardhat.config.js -------------------------------------------------------------------------------- /contracts/EIP1155/README.md: -------------------------------------------------------------------------------- 1 | 2 | # PROCESS - Upgrade to EIP1155 3 | Readme describing the process and progress of adding the ability to mint ERC1155 NFTs as tickets. Implementing EIP1155 will enable batch minting as well as delivering huge gas savings on a per ticket basis. The projected gas savings achieved by implementing 1155 as implemented in testing right now are around 85-95% (depending on the size of the batch).As described in the original EIP1155 standard/proposal, the standard relies on event emission as a means to store data and publically document changes. 4 | 5 | 6 | ## Scaling ticket minting 7 | A big chokepoint for GET in minting large amounts of tickets can be summarized by the following technical blockchain realities: 8 | - To enable on-chain economics, tickets needs to be registered by funded and whitelisted EOA accounts. This means that while scaling by registering and funding more relayers is possible (and will happen naturally as more ticket issuers are onboarding) going for this method of scaling off the bat is 'too easy'. TLDR: Relayers transmitting tx's are horizontally scaleable, but this has drawbacks operationally. 9 | - A charataristic of the GETH nodes is that they can only hold in the mempool 16 tx per emitting account (so per relayer) 10 | - As we use ERC721 and store considerable amount of metadata we can only mint 1 NFT per tx (350k gas, 1 tx = 1 mint) 11 | - At any point in time a relayer can only offer 16tx's to the mempool 12 | 13 | As we can only emit 16 tx at a time and every tx is 'only' 1 mint, hammering through transactions by raising gwei doesn't considerably speed up the amount we can process. Essentially with ERC721 we hit a processing limit that can only be relieved by using more relayers. Implementing EIP1155 will enable batch minting of 100+ getNFTs per tx. In addition using EIP1155 will reduce the need for more relayer for the same ticket issuer. 14 | 15 | #### Benefits of implementing EIP1155 16 | - Huge cost savings (85-95% less Polygon needed per getNFT) 17 | - Ability to batch mint 100 NFTs in a single transaction 18 | - Ability to mint 1600 NFTs in 16 transactions 19 | 20 | #### Downsides of implementing EIP1155 21 | - Far less metadata permanently stored on chain of individual tickets 22 | - Potential loss in (time) definition as NFTs are minted in batches (could disturb sequencing) 23 | - Batch mints use a large abount of gas (2-3M) possibly Polygon nodes will be reluctant to take them when mempool is volatile (speculation, could not be the case) 24 | - Increases complexity of ticket engine, as we will need to build a 'bucket' system 25 | - Event logs could be pruned from the blockchain state 26 | 27 | --- 28 | 29 | ### BaseGET.sol 30 | 31 | ```jsx 32 | primaryBatchSale(address eventAddress, uint256 startId, uint256 endId, uint256[] memory basePrices, uint256 orderTime) 33 | ``` 34 | 35 | The protocol now batch-mints tickets with the `primaryBatchSale` function, this function in turn emits `primaryBatchSaleMint` upon successful mints. This function takes in the `eventAddress` into which all the tickets in the this batch would be minted, A `startId` and `endId` which signifies the range of the token `ids` to be minted, an array of `basePrices` whose length must be in accordance to the amount of tickets being minted and the `orderTime`. 36 | 37 | ```jsx 38 | event primaryBatchSaleMint(uint256 indexed startIndex, uint256 indexed endIndex, uint64 indexed getUsed, uint64 orderTime, uint256[] basePrices) 39 | ``` 40 | 41 | This event is emitted upon successfully batch minting tickets. 42 | 43 | ## Conclusion: 44 | 45 | This is by far not conclusive neither is it sufficient enough a documentation to in detail state all the changes made. For clarity sake, I'd rewrite this once I have the contracts re-written and ready to be deployed on Mumbai. 46 | 47 | 48 | ## State Change Functions 49 | 50 | ### 1. `primarySale` Function - Responsible for single mints of NFTs 51 | 52 | `eventAddress` - Address of GET custody that would be unique per event. All tickets of a particular event would be minted into this address. 53 | 54 | `id` - Unique id per token. 55 | 56 | `primaryPrice` - Price paid by primary ticket buyer in the local/event currency 57 | 58 | `basePrice` - price as charged by GET to the ticketeer in USD 59 | 60 | `orderTime` - timestamp the state change was triggered in the system of the integrator 61 | 62 | `data` - any arbitrary data to be stored on-chain 63 | 64 | `ticketMetadata` - additional meta data about a sale or ticket (like seating, notes, or resale rules) stored in a `struct`. 65 | 66 | ```jsx 67 | function primarySale(address eventAddress, uint256 id, uint256 primaryPrice, uint256 basePrice, uint256 orderTime, bytes memory data, bytes32[] memory ticketMetadata) public onlyRelayer 68 | ``` 69 | 70 | emits `PrimarySaleMint` upon success 71 | 72 | 73 | ```jsx 74 | PrimarySaleMint(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime, uint256 basePrice) 75 | ``` 76 | 77 | ### 2. `primaryBatchSale` Function - Responsible for batch mints of NFTs 78 | 79 | `eventAddress` - Address of GET custody that would be unique per event. All tickets of a particular event would be minted into this address. 80 | 81 | `ids` - Array of `ids` 82 | 83 | `primaryPrices` - Array of `primaryPrices`. 84 | 85 | `amounts` - Array of the number of a specific token to be minted. This number of elements in this array must correspond with the number of tokens to be minted. I.e `ids.length == amounts.length == basePrices.length` 86 | 87 | `basePrices` - array of `basePrice` 88 | 89 | `orderTime` - timestamp the state change was triggered in the system of the integrator 90 | 91 | `meta` - any arbitrary data to be stored on-chain 92 | 93 | 94 | 95 | ```jsx 96 | function primaryBatchSale(address eventAddress,uint256[] memory ids,uint256[] memory amounts,uint256[] memory basePrices,uint256 orderTime,bytes memory meta) public onlyRelayer 97 | ``` 98 | 99 | This emits `PrimaryBatchMint` upon success 100 | 101 | ```jsx 102 | PrimaryBatchMint(uint256[] indexed ids,uint64 indexed getUsed,uint64 orderTime,uint256[] indexed basePrices) 103 | ``` 104 | 105 | ### 3. `secondaryTransfer` Function - Responsible for handling single ticket resales 106 | 107 | `id` - NFT index 108 | 109 | `eventAddress` - EOA address of GETCustody that is the event the getNFT was issued for 110 | 111 | `orderTime` - timestamp the state change was triggered in the system of the integrator 112 | 113 | `primaryPrice` - price paid for the getNFT during the primary sale 114 | 115 | `secondaryPrice` - price paid for the getNFT on the secondary market 116 | 117 | ```jsx 118 | function secondaryTransfer(uint256 id,address eventAddress,uint256 orderTime,uint256 primaryPrice,uint256 secondaryPrice) 119 | ``` 120 | 121 | This emits `SecondarySale` upon success. 122 | 123 | ```jsx 124 | SecondarySale(uint256 indexed nftIndex,uint64 indexed getUsed,uint256 resalePrice,uint64 indexed orderTime) 125 | ``` 126 | 127 | ### 4. `scanNFT` Function 128 | 129 | 130 | 131 | `id` - NFT index 132 | 133 | `orderTime` - timestamp of engine of request 134 | 135 | `eventAddress` - EOA address of GETCustody that is the event the getNFT was issued for. 136 | 137 | ```jsx 138 | function scanNFT(uint256 id,uint256 orderTime,address eventAddress) public onlyRelayer 139 | ``` 140 | 141 | This emits TicketScanned upon success. 142 | 143 | ```jsx 144 | TicketScanned(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime); 145 | ``` 146 | 147 | ### 5. `invalidateNFT` Function 148 | 149 | `id` - NFT index 150 | 151 | `orderTime` - timestamp of engine of request 152 | 153 | `eventAddress` - EOA address of GETCustody that is the event the getNFT was issued for. 154 | 155 | ```jsx 156 | function invalidateNFT(uint256 id,uint256 orderTime,address eventAddress) public onlyRelayer 157 | ``` 158 | 159 | This emits TicketInvalidated upon success. 160 | 161 | ```jsx 162 | TicketInvalidated(uint256 indexed nftIndex,uint64 indexed getUsed,uint64 indexed orderTime) 163 | ``` 164 | 165 | ### 6. `claimGetNFT` Function 166 | 167 | `id` - unique ticket ID 168 | 169 | `eventAddress` - EOA address of GETCustody that is the known owner of the getNFT 170 | 171 | `externalAddress` - EOA address of user that is claiming the getNFT 172 | 173 | `orderTime` - timestamp the statechange was triggered in the system of the integrator 174 | 175 | `data` - an arbitrary data to be stored on-chain 176 | 177 | ```jsx 178 | function claimGetNFT(uint256 id,address eventAddress,address externalAddress,uint256 orderTime,bytes memory data) 179 | ``` 180 | 181 | This emits NftClaimed upon success 182 | 183 | ```jsx 184 | NftClaimed(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime) 185 | ``` 186 | 187 | ## View Functions 188 | 189 | ### 1. `isNFTClaimable` Function 190 | 191 | `nftIndex` - unique identifier of getNFT assigned by contract at mint 192 | 193 | `eventAddress` - EOA address of GETCustody that is the known owner of the getNFT 194 | 195 | ```jsx 196 | isNFTClaimable(uint256 nftIndex, address eventAddress) public view returns (bool) 197 | ``` 198 | 199 | Returns a boolean. 200 | 201 | ### 2. `isNFTSellable` Function 202 | 203 | `id` - unique identifier of getNFT assigned by contract at mint 204 | 205 | ```jsx 206 | isNFTSellable(uint256 id) public view returns (bool) 207 | ``` 208 | 209 | Returns a boolean. 210 | 211 | ### 3. isNFTSellable Function 212 | 213 | `nftIndex/id` - unique identifier of getNFT assigned by contract at mint 214 | 215 | ```jsx 216 | returnStructTicket(uint256 nftIndex) public view returns (TicketData memory) 217 | ``` 218 | 219 | Returns a TicketData struct 220 | 221 | ```jsx 222 | TicketData { 223 | address eventAddress; 224 | bytes32[] ticketMetadata; 225 | uint32[2] salePrices; 226 | TicketStates state; 227 | } 228 | ``` 229 | 230 | ### 4. `viewPrimaryPrice` Function 231 | 232 | `nftIndex/id` - unique identifier of getNFT assigned by contract at mint 233 | 234 | ```jsx 235 | viewPrimaryPrice(uint256 nftIndex) public view returns (uint32) 236 | ``` 237 | 238 | Returns an integer 239 | 240 | ### 5. `viewLatestResalePrice` Function 241 | 242 | `nftIndex/id` - unique identifier of getNFT assigned by contract at mint 243 | 244 | ```jsx 245 | viewLatestResalePrice(uint256 nftIndex) public view returns (uint32) 246 | ``` 247 | 248 | Returns an integer 249 | 250 | ### 6. `viewEventOfIndex` Function 251 | 252 | `nftIndex/id` - unique identifier of getNFT assigned by contract at mint 253 | 254 | ```jsx 255 | viewEventOfIndex(uint256 nftIndex) public view returns (address) 256 | ``` 257 | 258 | Returns an integer 259 | 260 | ### 7. `viewTicketMetadata` is an alias for `returnStructTicket` 261 | 262 | ### 8. `viewTicketState` Function 263 | 264 | ```jsx 265 | viewTicketState(uint256 nftIndex) public view returns (uint256) 266 | ``` 267 | 268 | Returns an integer that represented a state within the state structure below 269 | 270 | ```jsx 271 | TicketStates{ 272 | UNSCANNED, 273 | SCANNED, 274 | CLAIMABLE, 275 | INVALIDATED, 276 | PREMINTED, 277 | COLLATERALIZED, 278 | CLAIMED 279 | } 280 | ``` 281 | 282 | -------------------------------------------------------------------------------- /contracts/EIP1155/contracts/BaseGET1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./FoundationContract.sol"; 5 | 6 | contract BaseGET1155 is FoundationContract { 7 | function __BaseGETNFT_init_unchained() internal initializer {} 8 | 9 | function __BaseGETNFT_init(address configuration_address) public initializer { 10 | __Context_init(); 11 | __FoundationContract_init(configuration_address); 12 | __BaseGETNFT_init_unchained(); 13 | } 14 | 15 | // UNSCANNED is the state the ticket assumes upon creation before it is ever scanned. Only UNSCANNED mytickets can be resold. 16 | // SCANNED is the state the ticket assumes when scanned; this can happen infinite number of times. 17 | // CLAIMABLE is the state the ticket can assume that allows it to be claimed, this happens after the finalScan 18 | // INVALIDATED is the state the ticket can assume when the ticket is flagged as invalid by the ticket issuer. 19 | // PREMINTED is the state a ticket is currently in an index contract, but it has not been sold/used as colleteral (this is essentially the 'issued for colleterization' state) 20 | // COLLATERALIZED ticket is at the moment colleterized / locked in the ticket event financing contract 21 | enum TicketStates { 22 | UNSCANNED, 23 | SCANNED, 24 | CLAIMABLE, 25 | INVALIDATED, 26 | PREMINTED, 27 | COLLATERALIZED, 28 | CLAIMED 29 | } 30 | 31 | struct TicketData { 32 | address eventAddress; 33 | bytes32[] ticketMetadata; 34 | uint32[2] salePrices; 35 | TicketStates state; 36 | } 37 | 38 | mapping(uint256 => TicketData) private _ticket_data; 39 | 40 | event PrimarySaleMint( 41 | uint256 indexed nftIndex, 42 | uint64 indexed getUsed, 43 | uint64 indexed orderTime, 44 | uint256 basePrice 45 | ); 46 | 47 | event PrimaryBatchMint( 48 | uint256[] indexed ids, 49 | uint64 indexed getUsed, 50 | uint64 orderTime, 51 | uint256[] indexed basePrices 52 | ); 53 | 54 | event SecondarySale( 55 | uint256 indexed nftIndex, 56 | uint64 indexed getUsed, 57 | uint256 resalePrice, 58 | uint64 indexed orderTime 59 | ); 60 | 61 | event TicketInvalidated( 62 | uint256 indexed nftIndex, 63 | uint64 indexed getUsed, 64 | uint64 indexed orderTime 65 | ); 66 | 67 | event NftClaimed(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime); 68 | 69 | event NftTokenURIEdited(uint256 indexed nftIndex, uint64 indexed getUsed, string netTokenURI); 70 | 71 | event IllegalScan(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime); 72 | 73 | event TicketScanned(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime); 74 | 75 | event NFTCheckedIn(uint256 indexed nftIndex, uint64 indexed getUsed, uint64 indexed orderTime); 76 | 77 | // OPERATIONAL TICKETING FUNCTIONS // 78 | 79 | /** 80 | * @dev primary sale function, transfers or mints NFT to EOA of a primary market ticket buyer 81 | * @param eventAddress EOA address of the event and the address the ticket is minted to - primary key assinged by GETcustody 82 | * @param id uinque NFT identifier 83 | * @param primaryPrice price paid by primary ticket buyer in the local/event currenct 84 | * @param basePrice price as charged to the ticketeer in USD 85 | * @param orderTime timestamp the statechange was triggered in the system of the integrator 86 | * @param data an arbitrary data to be stored on-chain 87 | * @param ticketMetadata additional meta data about a sale or ticket (like seating, notes, or reslae rukes) stored in unstructed list 88 | */ 89 | function primarySale( 90 | address eventAddress, 91 | uint256 id, 92 | uint256 primaryPrice, 93 | uint256 basePrice, 94 | uint256 orderTime, 95 | bytes memory data, 96 | bytes32[] memory ticketMetadata 97 | ) public onlyRelayer { 98 | // Event NFT is minted for an un-colleterized/financed eventAddress -> getNFT minted to EOA account 99 | _mintGETNFT(eventAddress, id, primaryPrice, data, ticketMetadata); 100 | 101 | uint256 _fueled = ECONOMICS.fuelBackpackTicket(msg.sender, basePrice); 102 | 103 | emit PrimarySaleMint(id, uint64(_fueled), uint64(orderTime), basePrice); 104 | } 105 | 106 | function primaryBatchSale( 107 | address eventAddress, 108 | uint256[] memory ids, 109 | uint256[] memory amounts, 110 | uint256[] memory basePrices, 111 | uint256 orderTime, 112 | bytes memory meta 113 | ) public onlyRelayer { 114 | require( 115 | (ids.length == basePrices.length) && (ids.length == amounts.length), 116 | "BaseGET: Invalid call to primaryBatchSale" 117 | ); 118 | 119 | GET_ERC1155.mintBatch(eventAddress, ids, amounts, meta); 120 | 121 | uint256 _fueled = ECONOMICS.fuelBatchBackpackTickets(ids, msg.sender, basePrices); 122 | 123 | emit PrimaryBatchMint(ids, uint64(_fueled), uint64(orderTime), basePrices); 124 | } 125 | 126 | // TODO: Make this 1155 compatible 127 | function collateralMint( 128 | address destinationAddress, // index contract address 129 | address eventAddress, 130 | uint256 primaryPrice, 131 | string memory ticketURI, 132 | bytes32[] memory ticketMetadata 133 | ) external onlyFactory returns (uint256) { 134 | // Event NFT is created for is not colleterized, getNFT minted to index contract 135 | // uint256 nftIndexC = _mintGETNFT( 136 | // destinationAddress, 137 | // eventAddress, 138 | // primaryPrice, 139 | // ticketURI, 140 | // ticketMetadata 141 | // ); 142 | // return nftIndexC; 143 | } 144 | 145 | /** transfers a getNFT from EOA to EOA 146 | @param id NFT index 147 | @param eventAddress EOA address of GETCustody that is the event the getNFT was issued for 148 | @param orderTime timestamp the statechange was triggered in the system of the integrator 149 | @param primaryPrice price paid for the getNFT during the primary sale 150 | @param secondaryPrice price paid for the getNFT on the secondary market 151 | */ 152 | function secondaryTransfer( 153 | uint256 id, 154 | address eventAddress, 155 | uint256 orderTime, 156 | uint256 primaryPrice, 157 | uint256 secondaryPrice 158 | ) public onlyRelayer { 159 | if (_ticket_data[id].eventAddress == address(0)) { 160 | TicketData storage tdata = _ticket_data[id]; 161 | tdata.eventAddress = eventAddress; 162 | tdata.salePrices[0] = uint32(primaryPrice); 163 | tdata.salePrices[1] = uint32(secondaryPrice); 164 | tdata.state = TicketStates.UNSCANNED; 165 | } else { 166 | require(_ticket_data[id].state == TicketStates.UNSCANNED, "RE/SALE_ERROR"); 167 | } 168 | 169 | emit SecondarySale(id, 0, secondaryPrice, uint64(orderTime)); 170 | } 171 | 172 | /** finalScan / permanent scan function 173 | @param id NFT index 174 | @param orderTime timestamp of engine of request 175 | */ 176 | function scanNFT( 177 | uint256 id, 178 | uint256 orderTime, 179 | address eventAddress 180 | ) public onlyRelayer { 181 | if (_ticket_data[id].eventAddress == address(0)) { 182 | TicketData storage tdata = _ticket_data[id]; 183 | tdata.eventAddress = eventAddress; 184 | tdata.state = TicketStates.CLAIMABLE; 185 | 186 | // transfer all the GET in the backpack to the feeCollector 187 | uint256 _fueled = ECONOMICS.emptyBackpackBasic(msg.sender); 188 | 189 | _ticket_data[id].state = TicketStates.CLAIMABLE; 190 | 191 | emit TicketScanned(id, uint64(_fueled), uint64(orderTime)); 192 | } else { 193 | require(_ticket_data[id].state != TicketStates.INVALIDATED, "SCAN_INVALIDATED"); 194 | 195 | if (_ticket_data[id].state == TicketStates.CLAIMABLE) { 196 | // nft has been scanned before 197 | emit IllegalScan(id, 0, uint64(orderTime)); 198 | } else { 199 | // nft has never been scanned 200 | // transfer all the GET in the backpack to the feeCollector 201 | uint256 _fueled = ECONOMICS.emptyBackpackBasic(msg.sender); 202 | 203 | _ticket_data[id].state = TicketStates.CLAIMABLE; 204 | 205 | emit TicketScanned(id, uint64(_fueled), uint64(orderTime)); 206 | } 207 | } 208 | } 209 | 210 | /** invalidates a getNFT, making it unusable and untransferrable 211 | @param id unique ticket ID 212 | @param orderTime timestamp the statechange was triggered in the system of the integrator 213 | */ 214 | function invalidateNFT( 215 | uint256 id, 216 | uint256 orderTime, 217 | address eventAddress 218 | ) public onlyRelayer { 219 | if (_ticket_data[id].eventAddress == address(0)) { 220 | TicketData storage tdata = _ticket_data[id]; 221 | tdata.eventAddress = eventAddress; 222 | tdata.state = TicketStates.INVALIDATED; 223 | } else { 224 | require(_ticket_data[id].state != TicketStates.INVALIDATED, "DOUBLE_INVALIDATION"); 225 | 226 | _ticket_data[id].state = TicketStates.INVALIDATED; 227 | } 228 | 229 | emit TicketInvalidated(id, 0, uint64(orderTime)); 230 | } 231 | 232 | /** Claims a scanned and valid NFT to an external EOA address 233 | @param id unique ticket ID 234 | @param eventAddress EOA address of GETCustody that is the known owner of the getNFT 235 | @param externalAddress EOA address of user that is claiming the gtNFT 236 | @param orderTime timestamp the statechange was triggered in the system of the integrator 237 | */ 238 | function claimGetNFT( 239 | uint256 id, 240 | address eventAddress, 241 | address externalAddress, 242 | uint256 orderTime, 243 | bytes memory data 244 | ) public onlyRelayer { 245 | TicketData storage tdata = _ticket_data[id]; 246 | 247 | if (tdata.eventAddress == address(0)) { 248 | tdata.eventAddress = eventAddress; 249 | tdata.state = TicketStates.CLAIMED; 250 | } else { 251 | require(tdata.state == TicketStates.CLAIMABLE, "CLAIM_ERROR"); 252 | tdata.state = TicketStates.CLAIMED; 253 | } 254 | /// Transfer the NFT to destinationAddress 255 | GET_ERC1155.relayerTransferFrom(id, eventAddress, externalAddress, data); 256 | emit NftClaimed(id, 0, uint64(orderTime)); 257 | } 258 | 259 | /** 260 | @dev internal getNFT minting function 261 | @notice this function can be called internally, as well as externally (in case of event financing) 262 | @notice should only mint to EOA addresses managed by GETCustody 263 | @param eventAddress EOA address of the event - primary key assinged by GETcustody 264 | * @param id uinque NFT identifier 265 | @param issuePrice the price the getNFT will be offered or collaterized at 266 | @param data arbitrary data to be stored on-chain 267 | @param ticketMetadata additional meta data about a sale or ticket (like seating, notes, or reslae rukes) stored in unstructed list 268 | */ 269 | function _mintGETNFT( 270 | address eventAddress, 271 | uint256 id, 272 | uint256 issuePrice, 273 | bytes memory data, 274 | bytes32[] memory ticketMetadata 275 | ) internal returns (uint256) { 276 | GET_ERC1155.mint(eventAddress, id, data); 277 | 278 | TicketData storage tdata = _ticket_data[id]; 279 | tdata.ticketMetadata = ticketMetadata; 280 | tdata.eventAddress = eventAddress; 281 | tdata.salePrices[0] = uint32(issuePrice); 282 | tdata.state = TicketStates.UNSCANNED; 283 | return id; 284 | } 285 | 286 | /** edits metadataURI stored in the getNFT 287 | @dev unused function can be commented 288 | @param id uint256 unique identifier of getNFT assigned by contract at mint 289 | @param newTokenURI new string stored in metadata of the getNFT 290 | */ 291 | function editTokenURIbyIndex(uint256 id, string memory newTokenURI) public onlyRelayer { 292 | emit NftTokenURIEdited(id, 0, newTokenURI); 293 | } 294 | 295 | // VIEW FUNCTIONS 296 | 297 | /** Returns if an getNFT can be claimed by an external EOA 298 | @param nftIndex uint256 unique identifier of getNFT assigned by contract at mint 299 | @param eventAddress EOA address of GETCustody that is the known owner of the getNFT 300 | */ 301 | function isNFTClaimable(uint256 nftIndex, address eventAddress) public view returns (bool) { 302 | if (_ticket_data[nftIndex].state == TicketStates.CLAIMABLE) { 303 | return true; 304 | } else { 305 | return false; 306 | } 307 | } 308 | 309 | /** Returns if an getNFT can be resold 310 | @param id uint256 unique identifier of getNFT assigned by contract at mint 311 | */ 312 | function isNFTSellable(uint256 id) public view returns (bool) { 313 | if (_ticket_data[id].state == TicketStates.UNSCANNED) { 314 | return true; 315 | } 316 | return false; 317 | } 318 | 319 | /** 320 | @param nftIndex index of the nft 321 | TODO change this function as to work with the new TicketData struct 322 | */ 323 | function ticketMetadataIndex(uint256 nftIndex) 324 | public 325 | view 326 | returns ( 327 | address _eventAddress, 328 | bytes32[] memory _ticketMetadata, 329 | uint32[2] memory _salePrices, 330 | TicketStates _state 331 | ) 332 | { 333 | TicketData storage tdata = _ticket_data[nftIndex]; 334 | _eventAddress = tdata.eventAddress; 335 | _ticketMetadata = tdata.ticketMetadata; 336 | _salePrices = tdata.salePrices; 337 | _state = tdata.state; 338 | } 339 | 340 | /** 341 | @param ownerAddress address of the owner of the getNFT 342 | @notice the ownerAddress of an active ticket is generally held by GETCustody 343 | */ 344 | 345 | /** returns the metadata struct of the ticket (base data) 346 | @param nftIndex unique indentifier of getNFT 347 | */ 348 | function returnStructTicket(uint256 nftIndex) public view returns (TicketData memory) { 349 | return _ticket_data[nftIndex]; 350 | } 351 | 352 | function viewPrimaryPrice(uint256 nftIndex) public view returns (uint32) { 353 | return _ticket_data[nftIndex].salePrices[0]; 354 | } 355 | 356 | function viewLatestResalePrice(uint256 nftIndex) public view returns (uint32) { 357 | return _ticket_data[nftIndex].salePrices[1]; 358 | } 359 | 360 | function viewEventOfIndex(uint256 nftIndex) public view returns (address) { 361 | return _ticket_data[nftIndex].eventAddress; 362 | } 363 | 364 | function viewTicketMetadata(uint256 nftIndex) public view returns (bytes32[] memory) { 365 | return _ticket_data[nftIndex].ticketMetadata; 366 | } 367 | 368 | function viewTicketState(uint256 nftIndex) public view returns (uint256) { 369 | return uint256(_ticket_data[nftIndex].state); 370 | } 371 | } 372 | -------------------------------------------------------------------------------- /contracts/EIP1155/contracts/FoundationContract.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./utils/Initializable.sol"; 5 | import "./utils/ContextUpgradeable.sol"; 6 | 7 | import "./utils/SafeMathUpgradeable.sol"; 8 | 9 | import "./interfaces/IGETAccessControl.sol"; 10 | import "./interfaces/IBaseGET.sol"; 11 | import "./interfaces/IEventMetadataStorage.sol"; 12 | import "./interfaces/IEventFinancing.sol"; 13 | import "./interfaces/INFT_ERC1155V1.sol"; 14 | import "./interfaces/IEconomicsGET.sol"; 15 | import "./interfaces/IERC20.sol"; 16 | 17 | import "./interfaces/IfoundationContract.sol"; 18 | 19 | import "./interfaces/IGETProtocolConfiguration.sol"; 20 | 21 | contract FoundationContract is Initializable, ContextUpgradeable { 22 | using SafeMathUpgradeable for uint256; 23 | using SafeMathUpgradeable for uint128; 24 | using SafeMathUpgradeable for uint64; 25 | using SafeMathUpgradeable for uint32; 26 | 27 | bytes32 private GET_GOVERNANCE; 28 | bytes32 private GET_ADMIN; 29 | bytes32 private RELAYER_ROLE; 30 | bytes32 private FACTORY_ROLE; 31 | 32 | IGETProtocolConfiguration public CONFIGURATION; 33 | 34 | IGETAccessControl internal GET_BOUNCER; 35 | IBaseGET internal BASE; 36 | IGET_ERC1155V1 internal GET_ERC1155; 37 | IEventMetadataStorage internal METADATA; 38 | IEventFinancing internal FINANCE; // reserved slot 39 | IEconomicsGET internal ECONOMICS; 40 | IERC20 internal FUELTOKEN; 41 | 42 | function __FoundationContract_init_unchained(address _configurationAddress) 43 | internal 44 | initializer 45 | { 46 | CONFIGURATION = IGETProtocolConfiguration(_configurationAddress); 47 | GET_GOVERNANCE = 0x8f56080c0d86264195811790c4a1d310776ff2c3a02bf8a3c20af9f01a045218; 48 | GET_ADMIN = 0xc78a2ac81d1427bc228e4daa9ddf3163091b3dfd17f74bdd75ef0b9166a23a7e; 49 | RELAYER_ROLE = 0xe2b7fb3b832174769106daebcfd6d1970523240dda11281102db9363b83b0dc4; 50 | FACTORY_ROLE = 0xdfbefbf47cfe66b701d8cfdbce1de81c821590819cb07e71cb01b6602fb0ee27; 51 | } 52 | 53 | function __FoundationContract_init(address _configurationAddress) public initializer { 54 | __Context_init(); 55 | __FoundationContract_init_unchained(_configurationAddress); 56 | } 57 | 58 | /** 59 | * @dev Throws if called by any account other than the GET Protocol admin account. 60 | */ 61 | modifier onlyAdmin() { 62 | require(GET_BOUNCER.hasRole(GET_ADMIN, msg.sender), "NOT_ADMIN"); 63 | _; 64 | } 65 | 66 | /** 67 | * @dev Throws if called by any account other than the GET Protocol admin account. 68 | */ 69 | modifier onlyRelayer() { 70 | require(GET_BOUNCER.hasRole(RELAYER_ROLE, msg.sender), "NOT_RELAYER"); 71 | _; 72 | } 73 | 74 | /** 75 | * @dev Throws if called by any account other than a GET Protocol governance address. 76 | */ 77 | modifier onlyGovernance() { 78 | require(GET_BOUNCER.hasRole(GET_GOVERNANCE, msg.sender), "NOT_GOVERNANCE"); 79 | _; 80 | } 81 | 82 | /** 83 | * @dev Throws if called by any account other than a GET Protocol governance address. 84 | */ 85 | modifier onlyFactory() { 86 | require(GET_BOUNCER.hasRole(FACTORY_ROLE, msg.sender), "NOT_FACTORY"); 87 | _; 88 | } 89 | 90 | /** 91 | @dev calling this function will sync the global contract variables and instantiations with the DAO controlled configuration contract 92 | @notice can only be called by configurationGET contract 93 | TODO we could make this virtual, and then override the function in the contracts that inherit the foundation to instantiate the contracts that are relevant that particular contract 94 | */ 95 | function syncConfiguration() external returns (bool) { 96 | // check if caller is configurationGETProxyAddress 97 | require(msg.sender == address(CONFIGURATION), "CALLER_NOT_CONFIG"); 98 | 99 | GET_BOUNCER = IGETAccessControl(CONFIGURATION.AccessControlGET_proxy_address()); 100 | 101 | BASE = IBaseGET(CONFIGURATION.baseGETNFT_proxy_address()); 102 | 103 | GET_ERC1155 = IGET_ERC1155V1(CONFIGURATION.getNFT_ERC1155_proxy_address()); 104 | 105 | METADATA = IEventMetadataStorage(CONFIGURATION.eventMetadataStorage_proxy_address()); 106 | 107 | FINANCE = IEventFinancing(CONFIGURATION.getEventFinancing_proxy_address()); 108 | 109 | ECONOMICS = IEconomicsGET(CONFIGURATION.economicsGET_proxy_address()); 110 | 111 | FUELTOKEN = IERC20(CONFIGURATION.fueltoken_get_address()); 112 | 113 | return true; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /contracts/EIP1155/contracts/GETERC1155.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; 6 | // import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol"; 7 | import "./ERC1155Upgradeable.sol"; 8 | import "./interfaces/IGETAccessControl.sol"; 9 | 10 | contract GETERC1155 is Initializable, ERC1155Upgradeable { 11 | IGETAccessControl public GET_BOUNCER; 12 | bytes32 private constant FACTORY_ROLE = 13 | 0xdfbefbf47cfe66b701d8cfdbce1de81c821590819cb07e71cb01b6602fb0ee27; 14 | bytes32 private constant GET_ADMIN = keccak256("GET_ADMIN"); 15 | 16 | function __GETERC1155_init_unchainded(address address_bouncer) internal initializer { 17 | GET_BOUNCER = IGETAccessControl(address_bouncer); 18 | } 19 | 20 | function __GETERC1155_init( 21 | string memory uri, 22 | uint256 individualTokenIdAmount, 23 | address bouncer 24 | ) external initializer { 25 | __ERC1155_init(uri, individualTokenIdAmount); 26 | __GETERC1155_init_unchainded(bouncer); 27 | } 28 | 29 | mapping(uint256 => address) ticketToEvent; 30 | mapping(address => address) eventToRelayer; 31 | 32 | event EventCreated( 33 | address indexed eventAddress, 34 | address indexed relayerAddress, 35 | uint256 indexed timeCreated 36 | ); 37 | 38 | /** 39 | * @dev this function should be called from the EventMetadata contract when an event is created 40 | */ 41 | 42 | /** 43 | * @dev Throws if called by any account other than a GET Protocol governance address. 44 | */ 45 | modifier onlyFactory() { 46 | require(GET_BOUNCER.hasRole(FACTORY_ROLE, msg.sender), "CALLER_NOT_FACTORY"); 47 | _; 48 | } 49 | 50 | /** 51 | * @dev Throws if called by any account other than the GET Protocol admin account. 52 | */ 53 | modifier onlyAdmin() { 54 | require(GET_BOUNCER.hasRole(GET_ADMIN, msg.sender), "CALLER_NOT_ADMIN"); 55 | _; 56 | } 57 | 58 | function createEvent(address eventAddress) external { 59 | eventToRelayer[eventAddress] = _msgSender(); 60 | emit EventCreated(eventAddress, _msgSender(), block.timestamp); 61 | } 62 | 63 | /** 64 | * @notice all tickets are minted into their respective eventAddresses 65 | * @param _eventAddress - address the token would be minted to. 66 | * @param id - token id. 67 | * @param data - any arbitrary data. 68 | * @notice the tokens minted by this contract are all non-fungible hence there would only exist one token per type (per id) 69 | */ 70 | 71 | function mint( 72 | address _eventAddress, 73 | uint256 id, 74 | bytes memory data 75 | ) external onlyFactory { 76 | // ticketToEvent[id] = _eventAddress; 77 | super._mint(_eventAddress, id, 1, data); 78 | } 79 | 80 | function mintBatch( 81 | address _eventAddress, 82 | uint256[] memory ids, 83 | uint256[] memory amounts, 84 | bytes memory data 85 | ) external onlyFactory { 86 | // for (uint256 i = 0; i < ids.length; i++) { 87 | // ticketToEvent[ids[i]] = _eventAddress; 88 | // } 89 | super._mintBatch(_eventAddress, ids, amounts, data); 90 | } 91 | 92 | function relayerTransferFrom( 93 | uint256 id, 94 | address eventAddress, 95 | address destinationAddress, 96 | bytes memory data 97 | ) external onlyFactory { 98 | super._safeTransferFrom(eventAddress, destinationAddress, id, 1, data); 99 | } 100 | 101 | function mintBatch2( 102 | address _eventAddress, 103 | uint256[] memory ids, 104 | uint256[] memory amounts, 105 | bytes memory data 106 | ) external onlyFactory { 107 | // for (uint256 i = 0; i < ids.length; i++) { 108 | // ticketToEvent[ids[i]] = _eventAddress; 109 | // } 110 | super._mintBatch2(_eventAddress, ids, amounts, data); 111 | } 112 | 113 | function getMintBatch( 114 | address _eventAddress, 115 | uint256 start, 116 | uint256 end 117 | ) external onlyFactory { 118 | // for (uint256 i = 0; i < ids.length; i++) { 119 | // ticketToEvent[ids[i]] = _eventAddress; 120 | // } 121 | super._getMintBatch(_eventAddress, start, end); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /contracts/EIP1155/contracts/GETProtocolConfigurationV2.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./utils/Initializable.sol"; 5 | import "./utils/ContextUpgradeable.sol"; 6 | import "./utils/OwnableUpgradeable.sol"; 7 | 8 | import "./interfaces/IsyncConfiguration.sol"; 9 | import "./interfaces/IGETProtocolConfiguration.sol"; 10 | import "./interfaces/IUniswapV2Pair.sol"; 11 | 12 | contract GETProtocolConfigurationV2 is Initializable, ContextUpgradeable, OwnableUpgradeable { 13 | address public GETgovernanceAddress; 14 | address payable public feeCollectorAddress; 15 | address payable public treasuryDAOAddress; 16 | address payable public stakingContractAddress; 17 | address payable public emergencyAddress; 18 | address payable public bufferAddressGlobal; 19 | 20 | // address private proxyAdminAddress; old 21 | address private priceOracleAddress; 22 | 23 | address public AccessControlGET_proxy_address; 24 | address public baseGETNFT_proxy_address; 25 | address public getNFT_ERC1155_proxy_address; 26 | address public eventMetadataStorage_proxy_address; 27 | address public getEventFinancing_proxy_address; 28 | address public economicsGET_proxy_address; 29 | address public fueltoken_get_address; 30 | 31 | /// global economics configurations (Work in progress) 32 | uint256 public basicTaxRate; 33 | 34 | /// GET and USD price oracle/price feed configurations (work in progress) 35 | uint256 public priceGETUSD; // x1000 36 | 37 | IUniswapV2Pair public liquidityPoolGETETH; 38 | IUniswapV2Pair public liquidityPoolETHUSDC; 39 | 40 | function __GETProtocolConfiguration_init_unchained() public initializer {} 41 | 42 | function __GETProtocolConfiguration_init() public initializer { 43 | __Context_init(); 44 | __Ownable_init(); 45 | __GETProtocolConfiguration_init_unchained(); 46 | } 47 | 48 | /// EVENTS 49 | 50 | event UpdateAccessControl(address _old, address _new); 51 | event UpdatebaseGETNFT(address _old, address _new); 52 | event UpdateERC1155(address _old, address _new); 53 | event UpdateMetdata(address _old, address _new); 54 | event UpdateFinancing(address _old, address _new); 55 | event UpdateEconomics(address _old, address _new); 56 | event UpdateFueltoken(address _old, address _new); 57 | event UpdatePriceOracle(address _old, address _new); 58 | 59 | event UpdateGoverance(address _old, address _new); 60 | event UpdateFeeCollector(address _old, address _new); 61 | event UpdateTreasuryDAO(address _old, address _new); 62 | event UpdateStakingContract(address _old, address _new); 63 | event UpdateBasicTaxRate(uint256 _old, uint256 _new); 64 | event UpdateBufferGlobal(address _old, address _new); 65 | event UpdateGETUSD(uint256 _old, uint256 _new); 66 | 67 | event UpdateLiquidityPoolAddress( 68 | address _oldPoolGETETH, 69 | address _oldPoolUSDCETH, 70 | address _newPoolGETETH, 71 | address _newPoolUSDCETH 72 | ); 73 | 74 | /// INITIALIZATION 75 | 76 | // this function only needs to be used once, after the initial deploy 77 | function setAllContractsStorageProxies( 78 | address _access_control_proxy, 79 | address _base_proxy, 80 | address _erc1155_proxy, 81 | address _metadata_proxy, 82 | address _financing_proxy, 83 | address _economics_proxy 84 | ) external onlyOwner { 85 | // require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 86 | AccessControlGET_proxy_address = _access_control_proxy; 87 | 88 | // require(isContract(_base_proxy), "_base_proxy not a contract"); 89 | baseGETNFT_proxy_address = _base_proxy; 90 | 91 | // require(isContract(_erc721_proxy), "_erc721_proxy not a contract"); 92 | getNFT_ERC1155_proxy_address = _erc1155_proxy; 93 | 94 | // require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 95 | eventMetadataStorage_proxy_address = _metadata_proxy; 96 | 97 | // require(isContract(_financing_proxy), "_financing_proxy not a contract"); 98 | getEventFinancing_proxy_address = _financing_proxy; 99 | 100 | // require(isContract(_economics_proxy), "_economics_proxy not a contract"); 101 | economicsGET_proxy_address = _economics_proxy; 102 | 103 | // sync the change across all proxies 104 | _callSync(); 105 | } 106 | 107 | // setting a new AccessControlGET_proxy_address Proxy address 108 | function setAccessControlGETProxy(address _access_control_proxy) external onlyOwner { 109 | require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 110 | 111 | emit UpdateAccessControl(AccessControlGET_proxy_address, _access_control_proxy); 112 | 113 | AccessControlGET_proxy_address = _access_control_proxy; 114 | 115 | // sync the change across all proxies 116 | _callSync(); 117 | } 118 | 119 | function setBASEProxy(address _base_proxy) external onlyOwner { 120 | require(isContract(_base_proxy), "_base_proxy not a contract"); 121 | 122 | emit UpdatebaseGETNFT(baseGETNFT_proxy_address, _base_proxy); 123 | 124 | baseGETNFT_proxy_address = _base_proxy; 125 | 126 | // sync the change across all proxies 127 | _callSync(); 128 | } 129 | 130 | function setERC1155Proxy(address _erc1155_proxy) external onlyOwner { 131 | require(isContract(_erc1155_proxy), "_erc1155_proxy not a contract"); 132 | 133 | emit UpdateERC1155(getNFT_ERC1155_proxy_address, _erc1155_proxy); 134 | 135 | getNFT_ERC1155_proxy_address = _erc1155_proxy; 136 | 137 | // sync the change across all proxies 138 | _callSync(); 139 | } 140 | 141 | function setMetaProxy(address _metadata_proxy) external onlyOwner { 142 | require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 143 | 144 | emit UpdateMetdata(eventMetadataStorage_proxy_address, _metadata_proxy); 145 | 146 | eventMetadataStorage_proxy_address = _metadata_proxy; 147 | 148 | // sync the change across all proxies 149 | _callSync(); 150 | } 151 | 152 | function setFinancingProxy(address _financing_proxy) external onlyOwner { 153 | require(isContract(_financing_proxy), "_financing_proxy not a contract"); 154 | 155 | emit UpdateFinancing(getEventFinancing_proxy_address, _financing_proxy); 156 | 157 | getEventFinancing_proxy_address = _financing_proxy; 158 | 159 | // sync the change across all proxies 160 | _callSync(); 161 | } 162 | 163 | function setPriceOracle(address _price_oracle_new) external onlyOwner { 164 | require(isContract(_price_oracle_new), "new _price_oracle is not a contract"); 165 | 166 | emit UpdatePriceOracle(priceOracleAddress, _price_oracle_new); 167 | 168 | priceOracleAddress = _price_oracle_new; 169 | 170 | // sync the change across all proxies 171 | _callSync(); 172 | } 173 | 174 | function setEconomicsProxy(address _economics_proxy) external onlyOwner { 175 | require(isContract(_economics_proxy), "_economics_proxy not a contract"); 176 | 177 | emit UpdateEconomics(economicsGET_proxy_address, _economics_proxy); 178 | 179 | economicsGET_proxy_address = _economics_proxy; 180 | 181 | // sync the change across all proxies 182 | _callSync(); 183 | } 184 | 185 | function setgetNFT_ERC1155(address _getNFT_ERC1155) external onlyOwner { 186 | require(isContract(_getNFT_ERC1155), "_getNFT_ERC1155 not a contract"); 187 | 188 | emit UpdateERC1155(getNFT_ERC1155_proxy_address, _getNFT_ERC1155); 189 | 190 | getNFT_ERC1155_proxy_address = _getNFT_ERC1155; 191 | 192 | // sync the change across all proxies 193 | _callSync(); 194 | } 195 | 196 | function setFueltoken(address _fueltoken_get_address) external onlyOwner { 197 | require(isContract(_fueltoken_get_address), "_fueltoken_get_address not a contract"); 198 | 199 | emit UpdateFueltoken(fueltoken_get_address, _fueltoken_get_address); 200 | 201 | fueltoken_get_address = _fueltoken_get_address; 202 | 203 | // sync the change across all proxies 204 | _callSync(); 205 | } 206 | 207 | /** 208 | @notice internal function calling all proxy contracts of the protocol and updating all the global values 209 | */ 210 | function _callSync() internal { 211 | // UPDATE BASE 212 | require( 213 | IsyncConfiguration(baseGETNFT_proxy_address).syncConfiguration(), 214 | "FAILED_UPDATE_BASE" 215 | ); 216 | 217 | // UPDATE ECONOMICS 218 | require( 219 | IsyncConfiguration(economicsGET_proxy_address).syncConfiguration(), 220 | "FAILED_UPDATE_ECONOMICS" 221 | ); 222 | 223 | // UPDATE METADATA 224 | require( 225 | IsyncConfiguration(eventMetadataStorage_proxy_address).syncConfiguration(), 226 | "FAILED_UPDATE_METADATA" 227 | ); 228 | 229 | // UPDATE FINANCING 230 | require( 231 | IsyncConfiguration(getEventFinancing_proxy_address).syncConfiguration(), 232 | "FAILED_UPDATE_FINANCE" 233 | ); 234 | } 235 | 236 | // MANAGING GLOBAL VALUES 237 | 238 | function setGovernance(address _newGovernance) external onlyOwner { 239 | // require(isContract(_newGovernance), "_newGovernance not a contract"); 240 | 241 | emit UpdateGoverance(GETgovernanceAddress, _newGovernance); 242 | 243 | GETgovernanceAddress = _newGovernance; 244 | } 245 | 246 | function setGETUSDPrice(uint256 _newGETUSDPrice) external { 247 | require(msg.sender == priceOracleAddress, "ONLY_ORACLE_CAN_UPDATE"); 248 | 249 | emit UpdateGETUSD(priceGETUSD, _newGETUSDPrice); 250 | 251 | priceGETUSD = _newGETUSDPrice; 252 | } 253 | 254 | function setFeeCollector(address payable _newFeeCollector) external onlyOwner { 255 | require(_newFeeCollector != address(0), "_newFeeCollector cannot be burn address"); 256 | 257 | emit UpdateFeeCollector(feeCollectorAddress, _newFeeCollector); 258 | 259 | feeCollectorAddress = _newFeeCollector; 260 | } 261 | 262 | function setBufferAddressGlobal(address payable _newBufferGlobal) external onlyOwner { 263 | require(_newBufferGlobal != address(0), "_newBuffer cannot be burn address"); 264 | 265 | emit UpdateBufferGlobal(bufferAddressGlobal, _newBufferGlobal); 266 | 267 | bufferAddressGlobal = _newBufferGlobal; 268 | } 269 | 270 | function setTreasuryDAO(address payable _newTreasury) external onlyOwner { 271 | require(_newTreasury != address(0), "_newTreasury cannot be 0x0"); 272 | 273 | emit UpdateTreasuryDAO(treasuryDAOAddress, _newTreasury); 274 | 275 | treasuryDAOAddress = _newTreasury; 276 | } 277 | 278 | function setStakingContract(address payable _newStaking) external onlyOwner { 279 | // require(isContract(_newStaking), "_newStaking not a contract"); 280 | 281 | emit UpdateStakingContract(stakingContractAddress, _newStaking); 282 | 283 | stakingContractAddress = _newStaking; 284 | } 285 | 286 | function setBasicTaxRate(uint256 _basicTaxRate) external onlyOwner { 287 | require(_basicTaxRate >= 0, "TAXRATE_INVALID"); 288 | 289 | emit UpdateBasicTaxRate(basicTaxRate, _basicTaxRate); 290 | 291 | basicTaxRate = _basicTaxRate; 292 | } 293 | 294 | /** function that manually sets the price of GET in USD 295 | @notice this is a temporary approach, in the future it would make most sense to use LP pool TWAP oracles 296 | @dev as for every other contract the USD value is multiplied by 1000 297 | */ 298 | function setGETUSD(uint256 _newGETUSD) external onlyOwner { 299 | emit UpdateGETUSD(priceGETUSD, _newGETUSD); 300 | priceGETUSD = _newGETUSD; 301 | } 302 | 303 | function viewOracleContract() public view returns (address) { 304 | return priceOracleAddress; 305 | } 306 | 307 | function isContract(address account) internal view returns (bool) { 308 | // This method relies on extcodesize, which returns 0 for contracts in 309 | // construction, since the code is only stored at the end of the 310 | // constructor execution. 311 | 312 | uint256 size; 313 | // solhint-disable-next-line no-inline-assembly 314 | assembly { 315 | size := extcodesize(account) 316 | } 317 | return size > 0; 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /contracts/EventMetadataStorage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./FoundationContract.sol"; 5 | 6 | contract EventMetadataStorage is FoundationContract { 7 | 8 | function __initialize_metadata_unchained() internal initializer { 9 | } 10 | 11 | function __initialize_metadata( 12 | address configuration_address 13 | ) public initializer { 14 | __Context_init(); 15 | __FoundationContract_init( 16 | configuration_address); 17 | __initialize_metadata_unchained(); 18 | } 19 | 20 | struct EventStruct { 21 | address eventAddress; 22 | address relayerAddress; 23 | address underWriterAddress; 24 | string eventName; 25 | string shopUrl; 26 | string imageUrl; 27 | bytes32[4] eventMetadata; // -> [bytes32 latitude, bytes32 longitude, bytes32 currency, bytes32 ticketeerName] 28 | uint256[2] eventTimes; // -> [uin256 startingTime, uint256 endingTime] 29 | bool setAside; // -> false = default 30 | bytes32[] extraData; 31 | bool privateEvent; 32 | bool created; 33 | } 34 | 35 | mapping(address => EventStruct) private allEventStructs; 36 | address[] private eventAddresses; 37 | 38 | event NewEventRegistered( 39 | address indexed eventAddress, 40 | uint256 indexed getUsed, 41 | string eventName, 42 | uint256 indexed orderTime 43 | ); 44 | 45 | event AccessControlSet( 46 | address indexed newAccesscontrol 47 | ); 48 | 49 | event UnderWriterSet( 50 | address indexed eventAddress, 51 | address indexed underWriterAddress 52 | ); 53 | 54 | event BaseConfigured( 55 | address baseAddress 56 | ); 57 | 58 | // OPERATIONAL FUNCTIONS 59 | 60 | function registerEvent( 61 | address _eventAddress, 62 | address _integratorAccountPublicKeyHash, 63 | string memory _eventName, 64 | string memory _shopUrl, 65 | string memory _imageUrl, 66 | bytes32[4] memory _eventMeta, // -> [bytes32 latitude, bytes32 longitude, bytes32 currency, bytes32 ticketeerName] 67 | uint256[2] memory _eventTimes, // -> [uin256 startingTime, uint256 endingTime] 68 | bool _setAside, // -> false = default 69 | bytes32[] memory _extraData, 70 | bool _isPrivate 71 | ) public onlyRelayer { 72 | 73 | address _underwriterAddress = 0x0000000000000000000000000000000000000000; 74 | 75 | EventStruct storage _event = allEventStructs[_eventAddress]; 76 | _event.eventAddress = _eventAddress; 77 | _event.relayerAddress = _integratorAccountPublicKeyHash; 78 | _event.underWriterAddress = _underwriterAddress; 79 | _event.eventName = _eventName; 80 | _event.shopUrl = _shopUrl; 81 | _event.imageUrl = _imageUrl; 82 | _event.eventMetadata = _eventMeta; 83 | _event.eventTimes = _eventTimes; 84 | _event.setAside = _setAside; 85 | _event.extraData = _extraData; 86 | _event.privateEvent = _isPrivate; 87 | _event.created = true; 88 | 89 | eventAddresses.push(_eventAddress); 90 | 91 | emit NewEventRegistered( 92 | _eventAddress, 93 | 0, 94 | _eventName, 95 | block.timestamp 96 | ); 97 | } 98 | 99 | // VIEW FUNCTIONS 100 | 101 | /** returns if an event address exists 102 | @param eventAddress EOA address of the event - primary key assinged by GETcustody 103 | */ 104 | function doesEventExist( 105 | address eventAddress 106 | ) public view virtual returns(bool) 107 | { 108 | return allEventStructs[eventAddress].created; 109 | } 110 | 111 | /** returns all metadata of an event 112 | @param eventAddress EOA address of the event - primary key assinged by GETcustody 113 | */ 114 | function getEventData( 115 | address eventAddress) 116 | public virtual view 117 | returns ( 118 | address _relayerAddress, 119 | address _underWriterAddress, 120 | string memory _eventName, 121 | string memory _shopUrl, 122 | string memory _imageUrl, 123 | bytes32[4] memory _eventMeta, 124 | uint256[2] memory _eventTimes, 125 | bool _setAside, 126 | bytes32[] memory _extraData, 127 | bool _privateEvent 128 | ) 129 | { 130 | EventStruct storage mdata = allEventStructs[eventAddress]; 131 | _relayerAddress = mdata.relayerAddress; 132 | _underWriterAddress = mdata.underWriterAddress; 133 | _eventName = mdata.eventName; 134 | _shopUrl = mdata.shopUrl; 135 | _imageUrl = mdata.imageUrl; 136 | _eventMeta = mdata.eventMetadata; 137 | _eventTimes = mdata.eventTimes; 138 | _setAside = mdata.setAside; 139 | _extraData = mdata.extraData; 140 | _privateEvent = mdata.privateEvent; 141 | } 142 | 143 | function getEventCount() public view returns(uint256) 144 | { 145 | return eventAddresses.length; 146 | } 147 | 148 | function returnStructEvent( 149 | address eventAddress 150 | ) public view returns (EventStruct memory) 151 | { 152 | return allEventStructs[eventAddress]; 153 | } 154 | 155 | } -------------------------------------------------------------------------------- /contracts/FoundationContract.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./utils/Initializable.sol"; 5 | import "./utils/ContextUpgradeable.sol"; 6 | 7 | import "./utils/SafeMathUpgradeable.sol"; 8 | 9 | import "./interfaces/IGETAccessControl.sol"; 10 | import "./interfaces/IBaseGET.sol"; 11 | import "./interfaces/IEventMetadataStorage.sol"; 12 | import "./interfaces/IEventFinancing.sol"; 13 | import "./interfaces/INFT_ERC721V3.sol"; 14 | import "./interfaces/IEconomicsGET.sol"; 15 | import "./interfaces/IERC20.sol"; 16 | 17 | import "./interfaces/IfoundationContract.sol"; 18 | 19 | import "./interfaces/IGETProtocolConfiguration.sol"; 20 | 21 | contract FoundationContract is Initializable, ContextUpgradeable { 22 | 23 | using SafeMathUpgradeable for uint256; 24 | using SafeMathUpgradeable for uint128; 25 | using SafeMathUpgradeable for uint64; 26 | using SafeMathUpgradeable for uint32; 27 | 28 | bytes32 private GET_GOVERNANCE; 29 | bytes32 private GET_ADMIN; 30 | bytes32 private RELAYER_ROLE; 31 | bytes32 private FACTORY_ROLE; 32 | 33 | IGETProtocolConfiguration public CONFIGURATION; 34 | 35 | IGETAccessControl internal GET_BOUNCER; 36 | IBaseGET internal BASE; 37 | IGET_ERC721V3 internal GET_ERC721; 38 | IEventMetadataStorage internal METADATA; 39 | IEventFinancing internal FINANCE; // reserved slot 40 | IEconomicsGET internal ECONOMICS; 41 | IERC20 internal FUELTOKEN; 42 | 43 | function __FoundationContract_init_unchained( 44 | address _configurationAddress 45 | ) internal initializer { 46 | CONFIGURATION = IGETProtocolConfiguration(_configurationAddress); 47 | GET_GOVERNANCE = 0x8f56080c0d86264195811790c4a1d310776ff2c3a02bf8a3c20af9f01a045218; 48 | GET_ADMIN = 0xc78a2ac81d1427bc228e4daa9ddf3163091b3dfd17f74bdd75ef0b9166a23a7e; 49 | RELAYER_ROLE = 0xe2b7fb3b832174769106daebcfd6d1970523240dda11281102db9363b83b0dc4; 50 | FACTORY_ROLE = 0xdfbefbf47cfe66b701d8cfdbce1de81c821590819cb07e71cb01b6602fb0ee27; 51 | } 52 | 53 | function __FoundationContract_init( 54 | address _configurationAddress 55 | ) public initializer { 56 | __Context_init(); 57 | __FoundationContract_init_unchained( 58 | _configurationAddress 59 | ); 60 | } 61 | 62 | /** 63 | * @dev Throws if called by any account other than the GET Protocol admin account. 64 | */ 65 | modifier onlyAdmin() { 66 | require(GET_BOUNCER.hasRole(GET_ADMIN, msg.sender), 67 | "NOT_ADMIN"); 68 | _; 69 | } 70 | 71 | /** 72 | * @dev Throws if called by any account other than the GET Protocol admin account. 73 | */ 74 | modifier onlyRelayer() { 75 | require(GET_BOUNCER.hasRole(RELAYER_ROLE, msg.sender), 76 | "NOT_RELAYER"); 77 | _; 78 | } 79 | 80 | /** 81 | * @dev Throws if called by any account other than a GET Protocol governance address. 82 | */ 83 | modifier onlyGovernance() { 84 | require( 85 | GET_BOUNCER.hasRole(GET_GOVERNANCE, msg.sender), 86 | "NOT_GOVERNANCE" 87 | ); 88 | _; 89 | } 90 | 91 | /** 92 | * @dev Throws if called by any account other than a GET Protocol governance address. 93 | */ 94 | modifier onlyFactory() { 95 | require(GET_BOUNCER.hasRole(FACTORY_ROLE, msg.sender), 96 | "NOT_FACTORY"); 97 | _; 98 | } 99 | 100 | /** 101 | @dev calling this function will sync the global contract variables and instantiations with the DAO controlled configuration contract 102 | @notice can only be called by configurationGET contract 103 | TODO we could make this virtual, and then override the function in the contracts that inherit the foundation to instantiate the contracts that are relevant that particular contract 104 | */ 105 | function syncConfiguration() external returns(bool) { 106 | 107 | // check if caller is configurationGETProxyAddress 108 | require(msg.sender == address(CONFIGURATION), "CALLER_NOT_CONFIG"); 109 | 110 | GET_BOUNCER = IGETAccessControl( 111 | CONFIGURATION.AccessControlGET_proxy_address() 112 | ); 113 | 114 | BASE = IBaseGET( 115 | CONFIGURATION.baseGETNFT_proxy_address() 116 | ); 117 | 118 | GET_ERC721 = IGET_ERC721V3( 119 | CONFIGURATION.getNFT_ERC721_proxy_address() 120 | ); 121 | 122 | METADATA = IEventMetadataStorage( 123 | CONFIGURATION.eventMetadataStorage_proxy_address() 124 | ); 125 | 126 | FINANCE = IEventFinancing( 127 | CONFIGURATION.getEventFinancing_proxy_address() 128 | ); 129 | 130 | ECONOMICS = IEconomicsGET( 131 | CONFIGURATION.economicsGET_proxy_address() 132 | ); 133 | 134 | FUELTOKEN = IERC20( 135 | CONFIGURATION.fueltoken_get_address() 136 | ); 137 | 138 | return true; 139 | } 140 | 141 | } 142 | -------------------------------------------------------------------------------- /contracts/GETProtocolConfigurationV2.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./utils/Initializable.sol"; 5 | import "./utils/ContextUpgradeable.sol"; 6 | import "./utils/OwnableUpgradeable.sol"; 7 | 8 | import "./interfaces/IsyncConfiguration.sol"; 9 | import "./interfaces/IGETProtocolConfiguration.sol"; 10 | import "./interfaces/IUniswapV2Pair.sol"; 11 | 12 | contract GETProtocolConfigurationV2 is Initializable, ContextUpgradeable, OwnableUpgradeable { 13 | 14 | address public GETgovernanceAddress; 15 | address payable public feeCollectorAddress; 16 | address payable public treasuryDAOAddress; 17 | address payable public stakingContractAddress; 18 | address payable public emergencyAddress; 19 | address payable public bufferAddressGlobal; 20 | 21 | // address private proxyAdminAddress; old 22 | address private priceOracleAddress; 23 | 24 | address public AccessControlGET_proxy_address; 25 | address public baseGETNFT_proxy_address; 26 | address public getNFT_ERC721_proxy_address; 27 | address public eventMetadataStorage_proxy_address; 28 | address public getEventFinancing_proxy_address; 29 | address public economicsGET_proxy_address; 30 | address public fueltoken_get_address; 31 | 32 | /// global economics configurations (Work in progress) 33 | uint256 public basicTaxRate; 34 | 35 | /// GET and USD price oracle/price feed configurations (work in progress) 36 | uint256 public priceGETUSD; // x1000 37 | 38 | IUniswapV2Pair public liquidityPoolGETETH; 39 | IUniswapV2Pair public liquidityPoolETHUSDC; 40 | 41 | function __GETProtocolConfiguration_init_unchained() public initializer {} 42 | 43 | function __GETProtocolConfiguration_init() public initializer { 44 | __Context_init(); 45 | __Ownable_init(); 46 | __GETProtocolConfiguration_init_unchained(); 47 | } 48 | 49 | /// EVENTS 50 | 51 | event UpdateAccessControl(address _old, address _new); 52 | event UpdatebaseGETNFT(address _old, address _new); 53 | event UpdateERC721(address _old, address _new); 54 | event UpdateMetdata(address _old, address _new); 55 | event UpdateFinancing(address _old, address _new); 56 | event UpdateEconomics(address _old, address _new); 57 | event UpdateFueltoken(address _old, address _new); 58 | event UpdatePriceOracle(address _old, address _new); 59 | 60 | event UpdateGoverance(address _old, address _new); 61 | event UpdateFeeCollector(address _old, address _new); 62 | event UpdateTreasuryDAO(address _old, address _new); 63 | event UpdateStakingContract(address _old, address _new); 64 | event UpdateBasicTaxRate(uint256 _old, uint256 _new); 65 | event UpdateBufferGlobal(address _old, address _new); 66 | event UpdateGETUSD(uint256 _old, uint256 _new); 67 | 68 | event UpdateLiquidityPoolAddress( 69 | address _oldPoolGETETH, 70 | address _oldPoolUSDCETH, 71 | address _newPoolGETETH, 72 | address _newPoolUSDCETH 73 | ); 74 | 75 | /// INITIALIZATION 76 | 77 | // this function only needs to be used once, after the initial deploy 78 | function setAllContractsStorageProxies( 79 | address _access_control_proxy, 80 | address _base_proxy, 81 | address _erc721_proxy, 82 | address _metadata_proxy, 83 | address _financing_proxy, 84 | address _economics_proxy 85 | ) external onlyOwner { 86 | // require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 87 | AccessControlGET_proxy_address = _access_control_proxy; 88 | 89 | // require(isContract(_base_proxy), "_base_proxy not a contract"); 90 | baseGETNFT_proxy_address = _base_proxy; 91 | 92 | // require(isContract(_erc721_proxy), "_erc721_proxy not a contract"); 93 | getNFT_ERC721_proxy_address = _erc721_proxy; 94 | 95 | // require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 96 | eventMetadataStorage_proxy_address = _metadata_proxy; 97 | 98 | // require(isContract(_financing_proxy), "_financing_proxy not a contract"); 99 | getEventFinancing_proxy_address = _financing_proxy; 100 | 101 | // require(isContract(_economics_proxy), "_economics_proxy not a contract"); 102 | economicsGET_proxy_address = _economics_proxy; 103 | 104 | // sync the change across all proxies 105 | _callSync(); 106 | 107 | } 108 | 109 | // setting a new AccessControlGET_proxy_address Proxy address 110 | function setAccessControlGETProxy( 111 | address _access_control_proxy 112 | ) external onlyOwner { 113 | 114 | require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 115 | 116 | emit UpdateAccessControl( 117 | AccessControlGET_proxy_address, 118 | _access_control_proxy 119 | ); 120 | 121 | AccessControlGET_proxy_address = _access_control_proxy; 122 | 123 | // sync the change across all proxies 124 | _callSync(); 125 | 126 | } 127 | 128 | 129 | 130 | 131 | function setBASEProxy( 132 | address _base_proxy) external onlyOwner { 133 | 134 | require(isContract(_base_proxy), "_base_proxy not a contract"); 135 | 136 | emit UpdatebaseGETNFT( 137 | baseGETNFT_proxy_address, 138 | _base_proxy 139 | ); 140 | 141 | baseGETNFT_proxy_address = _base_proxy; 142 | 143 | // sync the change across all proxies 144 | _callSync(); 145 | 146 | } 147 | 148 | function setERC721Proxy( 149 | address _erc721_proxy) external onlyOwner { 150 | 151 | require(isContract(_erc721_proxy), "_erc721_proxy not a contract"); 152 | 153 | emit UpdateERC721( 154 | getNFT_ERC721_proxy_address, 155 | _erc721_proxy 156 | ); 157 | 158 | getNFT_ERC721_proxy_address = _erc721_proxy; 159 | 160 | // sync the change across all proxies 161 | _callSync(); 162 | 163 | } 164 | 165 | function setMetaProxy( 166 | address _metadata_proxy) external onlyOwner { 167 | 168 | require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 169 | 170 | emit UpdateMetdata( 171 | eventMetadataStorage_proxy_address, 172 | _metadata_proxy 173 | ); 174 | 175 | eventMetadataStorage_proxy_address = _metadata_proxy; 176 | 177 | // sync the change across all proxies 178 | _callSync(); 179 | 180 | } 181 | 182 | function setFinancingProxy( 183 | address _financing_proxy) external onlyOwner { 184 | 185 | require(isContract(_financing_proxy), "_financing_proxy not a contract"); 186 | 187 | emit UpdateFinancing( 188 | getEventFinancing_proxy_address, 189 | _financing_proxy 190 | ); 191 | 192 | getEventFinancing_proxy_address = _financing_proxy; 193 | 194 | // sync the change across all proxies 195 | _callSync(); 196 | 197 | } 198 | 199 | 200 | function setPriceOracle( 201 | address _price_oracle_new) external onlyOwner { 202 | 203 | require(isContract(_price_oracle_new), "new _price_oracle is not a contract"); 204 | 205 | emit UpdatePriceOracle( 206 | priceOracleAddress, 207 | _price_oracle_new 208 | ); 209 | 210 | priceOracleAddress = _price_oracle_new; 211 | 212 | // sync the change across all proxies 213 | _callSync(); 214 | 215 | } 216 | 217 | function setEconomicsProxy( 218 | address _economics_proxy) external onlyOwner { 219 | 220 | require(isContract(_economics_proxy), "_economics_proxy not a contract"); 221 | 222 | emit UpdateEconomics( 223 | economicsGET_proxy_address, 224 | _economics_proxy 225 | ); 226 | 227 | economicsGET_proxy_address = _economics_proxy; 228 | 229 | // sync the change across all proxies 230 | _callSync(); 231 | 232 | } 233 | 234 | function setgetNFT_ERC721(address _getNFT_ERC721) external onlyOwner { 235 | 236 | require(isContract(_getNFT_ERC721), "_getNFT_ERC721 not a contract"); 237 | 238 | emit UpdateERC721(getNFT_ERC721_proxy_address, _getNFT_ERC721); 239 | 240 | getNFT_ERC721_proxy_address = _getNFT_ERC721; 241 | 242 | // sync the change across all proxies 243 | _callSync(); 244 | 245 | } 246 | 247 | function setFueltoken(address _fueltoken_get_address) external onlyOwner { 248 | 249 | require(isContract(_fueltoken_get_address), "_fueltoken_get_address not a contract"); 250 | 251 | emit UpdateFueltoken(fueltoken_get_address, _fueltoken_get_address); 252 | 253 | fueltoken_get_address = _fueltoken_get_address; 254 | 255 | // sync the change across all proxies 256 | _callSync(); 257 | 258 | } 259 | 260 | /** 261 | @notice internal function calling all proxy contracts of the protocol and updating all the global values 262 | */ 263 | function _callSync() internal { 264 | 265 | // UPDATE BASE 266 | require(IsyncConfiguration(baseGETNFT_proxy_address).syncConfiguration(), "FAILED_UPDATE_BASE"); 267 | 268 | // UPDATE ECONOMICS 269 | require(IsyncConfiguration(economicsGET_proxy_address).syncConfiguration(), "FAILED_UPDATE_ECONOMICS"); 270 | 271 | // UPDATE METADATA 272 | require(IsyncConfiguration(eventMetadataStorage_proxy_address).syncConfiguration(), "FAILED_UPDATE_METADATA"); 273 | 274 | // UPDATE FINANCING 275 | require(IsyncConfiguration(getEventFinancing_proxy_address).syncConfiguration(), "FAILED_UPDATE_FINANCE"); 276 | 277 | } 278 | 279 | // MANAGING GLOBAL VALUES 280 | 281 | 282 | function setGovernance( 283 | address _newGovernance 284 | ) external onlyOwner { 285 | 286 | // require(isContract(_newGovernance), "_newGovernance not a contract"); 287 | 288 | emit UpdateGoverance(GETgovernanceAddress, _newGovernance); 289 | 290 | GETgovernanceAddress = _newGovernance; 291 | 292 | } 293 | 294 | 295 | function setGETUSDPrice( 296 | uint256 _newGETUSDPrice 297 | ) external { 298 | 299 | require(msg.sender == priceOracleAddress, "ONLY_ORACLE_CAN_UPDATE"); 300 | 301 | emit UpdateGETUSD(priceGETUSD, _newGETUSDPrice); 302 | 303 | priceGETUSD = _newGETUSDPrice; 304 | 305 | } 306 | 307 | function setFeeCollector( 308 | address payable _newFeeCollector 309 | ) external onlyOwner { 310 | 311 | require(_newFeeCollector != address(0), "_newFeeCollector cannot be burn address"); 312 | 313 | emit UpdateFeeCollector(feeCollectorAddress, _newFeeCollector); 314 | 315 | feeCollectorAddress = _newFeeCollector; 316 | 317 | } 318 | 319 | function setBufferAddressGlobal( 320 | address payable _newBufferGlobal 321 | ) external onlyOwner { 322 | 323 | require(_newBufferGlobal != address(0), "_newBuffer cannot be burn address"); 324 | 325 | emit UpdateBufferGlobal(bufferAddressGlobal, _newBufferGlobal); 326 | 327 | bufferAddressGlobal = _newBufferGlobal; 328 | 329 | } 330 | 331 | function setTreasuryDAO( 332 | address payable _newTreasury 333 | ) external onlyOwner { 334 | 335 | require(_newTreasury != address(0), "_newTreasury cannot be 0x0"); 336 | 337 | emit UpdateTreasuryDAO(treasuryDAOAddress, _newTreasury); 338 | 339 | treasuryDAOAddress = _newTreasury; 340 | 341 | } 342 | 343 | function setStakingContract( 344 | address payable _newStaking 345 | ) external onlyOwner { 346 | 347 | // require(isContract(_newStaking), "_newStaking not a contract"); 348 | 349 | emit UpdateStakingContract(stakingContractAddress, _newStaking); 350 | 351 | stakingContractAddress = _newStaking; 352 | 353 | } 354 | 355 | function setBasicTaxRate( 356 | uint256 _basicTaxRate 357 | ) external onlyOwner { 358 | 359 | require(_basicTaxRate >= 0, "TAXRATE_INVALID"); 360 | 361 | emit UpdateBasicTaxRate(basicTaxRate, _basicTaxRate); 362 | 363 | basicTaxRate = _basicTaxRate; 364 | 365 | } 366 | 367 | 368 | /** function that manually sets the price of GET in USD 369 | @notice this is a temporary approach, in the future it would make most sense to use LP pool TWAP oracles 370 | @dev as for every other contract the USD value is multiplied by 1000 371 | */ 372 | function setGETUSD( 373 | uint256 _newGETUSD 374 | ) external onlyOwner { 375 | emit UpdateGETUSD(priceGETUSD, _newGETUSD); 376 | priceGETUSD = _newGETUSD; 377 | } 378 | 379 | function viewOracleContract() public view returns(address) { 380 | return priceOracleAddress; 381 | } 382 | 383 | function isContract(address account) internal view returns (bool) { 384 | // This method relies on extcodesize, which returns 0 for contracts in 385 | // construction, since the code is only stored at the end of the 386 | // constructor execution. 387 | 388 | uint256 size; 389 | // solhint-disable-next-line no-inline-assembly 390 | assembly { size := extcodesize(account) } 391 | return size > 0; 392 | } 393 | 394 | 395 | } 396 | -------------------------------------------------------------------------------- /contracts/GetEventFinancing.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./FoundationContract.sol"; 5 | 6 | contract GetEventFinancing is FoundationContract { 7 | 8 | function __initialize_event_financing_unchained() internal initializer {} 9 | 10 | function __initialize_event_financing( 11 | address configuration_address 12 | ) public initializer { 13 | __Context_init(); 14 | __FoundationContract_init( 15 | configuration_address); 16 | __initialize_event_financing_unchained(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/interfaces/IBaseGET.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IBaseGET { 5 | 6 | enum TicketStates { UNSCANNED, SCANNED, CLAIMABLE, INVALIDATED } 7 | 8 | struct TicketData { 9 | address eventAddress; 10 | bytes32[] ticketMetadata; 11 | uint256[2] salePrices; 12 | TicketStates state; 13 | } 14 | 15 | function primarySale( 16 | address destinationAddress, 17 | address eventAddress, 18 | uint256 primaryPrice, 19 | uint256 basePrice, 20 | uint256 orderTime, 21 | bytes32[] calldata ticketMetadata 22 | ) external; 23 | 24 | function secondaryTransfer( 25 | address originAddress, 26 | address destinationAddress, 27 | uint256 orderTime, 28 | uint256 secondaryPrice 29 | ) external; 30 | 31 | function collateralMint( 32 | address basketAddress, 33 | address eventAddress, 34 | uint256 primaryPrice, 35 | bytes32[] calldata ticketMetadata 36 | ) external returns(uint256); 37 | 38 | function scanNFT( 39 | address originAddress, 40 | uint256 orderTime 41 | ) external returns(bool); 42 | 43 | function invalidateAddressNFT( 44 | address originAddress, 45 | uint256 orderTime 46 | ) external; 47 | 48 | function claimgetNFT( 49 | address originAddress, 50 | address externalAddress 51 | ) external; 52 | 53 | function setOnChainSwitch( 54 | bool _switchState, 55 | uint256 _refactorSwapIndex 56 | ) external; 57 | 58 | /// VIEW FUNCTIONS 59 | 60 | function isNFTClaimable( 61 | uint256 nftIndex, 62 | address ownerAddress 63 | ) external view returns(bool); 64 | 65 | function returnStruct( 66 | uint256 nftIndex 67 | ) external view returns (TicketData memory); 68 | 69 | function addressToIndex( 70 | address ownerAddress 71 | ) external view returns (uint256); 72 | 73 | function viewPrimaryPrice( 74 | uint256 nftIndex 75 | ) external view returns (uint32); 76 | 77 | function viewLatestResalePrice( 78 | uint256 nftIndex 79 | ) external view returns (uint32); 80 | 81 | function viewEventOfIndex( 82 | uint256 nftIndex 83 | ) external view returns (address); 84 | 85 | function viewTicketMetadata( 86 | uint256 nftIndex 87 | ) external view returns (bytes32[] memory); 88 | 89 | function viewTicketState( 90 | uint256 nftIndex 91 | ) external view returns(uint); 92 | 93 | } -------------------------------------------------------------------------------- /contracts/interfaces/IBasketVault.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IBasketVault { 5 | 6 | function depositERC721(address _token, uint256 _tokenId) external; 7 | function withdrawERC721(address _token, uint256 _tokenId) external; 8 | function withdrawETH() external; 9 | function withdrawERC20(address _token) external; 10 | 11 | } -------------------------------------------------------------------------------- /contracts/interfaces/IERC165.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Interface of the ERC165 standard, as defined in the 7 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 8 | * 9 | * Implementers can declare support of contract interfaces, which can then be 10 | * queried by others ({ERC165Checker}). 11 | * 12 | * For an implementation, see {ERC165}. 13 | */ 14 | interface IERC165 { 15 | /** 16 | * @dev Returns true if this contract implements the interface defined by 17 | * `interfaceId`. See the corresponding 18 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 19 | * to learn more about how these ids are created. 20 | * 21 | * This function call must use less than 30 000 gas. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/interfaces/IERC20.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | /** 5 | * @dev Interface of the ERC20 standard as defined in the EIP. 6 | */ 7 | interface IERC20 { 8 | /** 9 | * @dev Returns the amount of tokens in existence. 10 | */ 11 | function totalSupply() external view returns (uint256); 12 | 13 | /** 14 | * @dev Returns the amount of tokens owned by `account`. 15 | */ 16 | function balanceOf(address account) external view returns (uint256); 17 | 18 | /** 19 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 20 | * 21 | * Returns a boolean value indicating whether the operation succeeded. 22 | * 23 | * Emits a {Transfer} event. 24 | */ 25 | function transfer(address recipient, uint256 amount) external returns (bool); 26 | 27 | /** 28 | * @dev Returns the remaining number of tokens that `spender` will be 29 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 30 | * zero by default. 31 | * 32 | * This value changes when {approve} or {transferFrom} are called. 33 | */ 34 | function allowance(address owner, address spender) external view returns (uint256); 35 | 36 | /** 37 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 38 | * 39 | * Returns a boolean value indicating whether the operation succeeded. 40 | * 41 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 42 | * that someone may use both the old and the new allowance by unfortunate 43 | * transaction ordering. One possible solution to mitigate this race 44 | * condition is to first reduce the spender's allowance to 0 and set the 45 | * desired value afterwards: 46 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 47 | * 48 | * Emits an {Approval} event. 49 | */ 50 | function approve(address spender, uint256 amount) external returns (bool); 51 | 52 | /** 53 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 54 | * allowance mechanism. `amount` is then deducted from the caller's 55 | * allowance. 56 | * 57 | * Returns a boolean value indicating whether the operation succeeded. 58 | * 59 | * Emits a {Transfer} event. 60 | */ 61 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 62 | 63 | /** 64 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 65 | * another (`to`). 66 | * 67 | * Note that `value` may be zero. 68 | */ 69 | event Transfer(address indexed from, address indexed to, uint256 value); 70 | 71 | /** 72 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 73 | * a call to {approve}. `value` is the new allowance. 74 | */ 75 | event Approval(address indexed owner, address indexed spender, uint256 value); 76 | } 77 | -------------------------------------------------------------------------------- /contracts/interfaces/IERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC165.sol"; 6 | 7 | /** 8 | * @dev Required interface of an ERC721 compliant contract. 9 | */ 10 | interface IERC721 is IERC165 { 11 | /** 12 | * @dev Emitted when `tokenId` token is transferred from `from` to `to`. 13 | */ 14 | event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); 15 | 16 | /** 17 | * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. 18 | */ 19 | event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); 20 | 21 | /** 22 | * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. 23 | */ 24 | event ApprovalForAll(address indexed owner, address indexed operator, bool approved); 25 | 26 | /** 27 | * @dev Returns the number of tokens in ``owner``'s account. 28 | */ 29 | function balanceOf(address owner) external view returns (uint256 balance); 30 | 31 | /** 32 | * @dev Returns the owner of the `tokenId` token. 33 | * 34 | * Requirements: 35 | * 36 | * - `tokenId` must exist. 37 | */ 38 | function ownerOf(uint256 tokenId) external view returns (address owner); 39 | 40 | /** 41 | * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients 42 | * are aware of the ERC721 protocol to prevent tokens from being forever locked. 43 | * 44 | * Requirements: 45 | * 46 | * - `from` cannot be the zero address. 47 | * - `to` cannot be the zero address. 48 | * - `tokenId` token must exist and be owned by `from`. 49 | * - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. 50 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 51 | * 52 | * Emits a {Transfer} event. 53 | */ 54 | function safeTransferFrom(address from, address to, uint256 tokenId) external; 55 | 56 | /** 57 | * @dev Transfers `tokenId` token from `from` to `to`. 58 | * 59 | * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. 60 | * 61 | * Requirements: 62 | * 63 | * - `from` cannot be the zero address. 64 | * - `to` cannot be the zero address. 65 | * - `tokenId` token must be owned by `from`. 66 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 67 | * 68 | * Emits a {Transfer} event. 69 | */ 70 | function transferFrom(address from, address to, uint256 tokenId) external; 71 | 72 | /** 73 | * @dev Gives permission to `to` to transfer `tokenId` token to another account. 74 | * The approval is cleared when the token is transferred. 75 | * 76 | * Only a single account can be approved at a time, so approving the zero address clears previous approvals. 77 | * 78 | * Requirements: 79 | * 80 | * - The caller must own the token or be an approved operator. 81 | * - `tokenId` must exist. 82 | * 83 | * Emits an {Approval} event. 84 | */ 85 | function approve(address to, uint256 tokenId) external; 86 | 87 | /** 88 | * @dev Returns the account approved for `tokenId` token. 89 | * 90 | * Requirements: 91 | * 92 | * - `tokenId` must exist. 93 | */ 94 | function getApproved(uint256 tokenId) external view returns (address operator); 95 | 96 | /** 97 | * @dev Approve or remove `operator` as an operator for the caller. 98 | * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. 99 | * 100 | * Requirements: 101 | * 102 | * - The `operator` cannot be the caller. 103 | * 104 | * Emits an {ApprovalForAll} event. 105 | */ 106 | function setApprovalForAll(address operator, bool _approved) external; 107 | 108 | /** 109 | * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. 110 | * 111 | * See {setApprovalForAll} 112 | */ 113 | function isApprovedForAll(address owner, address operator) external view returns (bool); 114 | 115 | /** 116 | * @dev Safely transfers `tokenId` token from `from` to `to`. 117 | * 118 | * Requirements: 119 | * 120 | * - `from` cannot be the zero address. 121 | * - `to` cannot be the zero address. 122 | * - `tokenId` token must exist and be owned by `from`. 123 | * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. 124 | * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. 125 | * 126 | * Emits a {Transfer} event. 127 | */ 128 | function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; 129 | } 130 | -------------------------------------------------------------------------------- /contracts/interfaces/IERC721TokenVault.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IERC721TokenVault { 5 | 6 | // Vault variables 7 | function token() external view returns(address); 8 | function id() external view returns(uint256); 9 | function auctionEnd() external view returns(uint256); 10 | function auctionLength() external view returns(address); 11 | function reserveTotal() external view returns(address); 12 | function livePrice() external view returns(address); 13 | function winning() external view returns(address); 14 | 15 | // VIEW & CONFIGURATION FUNCTIONS 16 | function reservePrice() external view returns(uint256); 17 | function claimFees() external; 18 | function updateUserPrice(uint256 _new) external; 19 | function start() external; 20 | function end() external; 21 | function bid() external; 22 | function redeem() external; 23 | function cash() external; 24 | 25 | } -------------------------------------------------------------------------------- /contracts/interfaces/IERC721VaultFactory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IERC721VaultFactory { 5 | 6 | function mint( 7 | string memory _name, 8 | string memory _symbol, 9 | address _token, 10 | uint256 _id, 11 | uint256 _supply, 12 | uint256 _listPrice, 13 | uint256 _fee 14 | ) external returns(uint256); 15 | 16 | function pause() external; 17 | function unpause() external; 18 | 19 | function vaultCount() external returns(uint256); 20 | // function vaults() external returns(address); 21 | 22 | 23 | function returnVaultAddress( 24 | uint256 _vaultIndex 25 | ) external view returns(address); 26 | 27 | } -------------------------------------------------------------------------------- /contracts/interfaces/IEconomicsGET.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IEconomicsGET { 5 | 6 | struct DynamicRateStruct { 7 | bool configured; // 0 8 | uint16 mint_rate; // 1 9 | uint16 resell_rate; // 2 10 | uint16 claim_rate; // 3 11 | uint16 crowd_rate; // 4 12 | uint16 scalper_fee; // 5 13 | uint16 extra_rate; // 6 14 | uint16 share_rate; // 7 15 | uint16 edit_rate; // 8 16 | uint16 max_base_price; // 9 17 | uint16 min_base_price; // 10 18 | uint16 reserve_slot_1; // 11 19 | uint16 reserve_slot_2; // 12 20 | } 21 | 22 | function fuelBackpackTicket( 23 | uint256 nftIndex, 24 | address relayerAddress, 25 | uint256 basePrice 26 | ) external returns (uint256); 27 | 28 | function emptyBackpackBasic( 29 | uint256 nftIndex 30 | ) external returns (uint256); 31 | 32 | function chargeTaxRateBasic( 33 | uint256 nftIndex 34 | ) external; 35 | 36 | function swipeDepotBalance() external returns(uint256); 37 | 38 | function topUpBuffer( 39 | uint256 topUpAmount, 40 | uint256 priceGETTopUp, 41 | address relayerAddress, 42 | address bufferAddress 43 | ) external returns(uint256); 44 | 45 | function setRelayerBuffer( 46 | address _relayerAddress, 47 | address _bufferAddressRelayer 48 | ) external; 49 | 50 | /// VIEW FUNCTIONS 51 | 52 | function checkRelayerConfiguration( 53 | address _relayerAddress 54 | ) external view returns (bool); 55 | 56 | function balanceRelayerSilo( 57 | address relayerAddress 58 | ) external view returns (uint256); 59 | 60 | function valueRelayerSilo( 61 | address _relayerAddress 62 | ) external view returns(uint256); 63 | 64 | function estimateNFTMints( 65 | address _relayerAddress 66 | ) external view returns(uint256); 67 | 68 | function viewRelayerFactor( 69 | address _relayerAddress 70 | ) external view returns(uint256); 71 | 72 | function viewRelayerGETPrice( 73 | address _relayerAddress 74 | ) external view returns (uint256); 75 | 76 | function viewBackPackValue( 77 | uint256 _nftIndex, 78 | address _relayerAddress 79 | ) external view returns (uint256); 80 | 81 | function viewBackPackBalance( 82 | uint256 _nftIndex 83 | ) external view returns (uint256); 84 | 85 | function viewDepotBalance() external view returns(uint256); 86 | function viewDepotValue() external view returns(uint256); 87 | } -------------------------------------------------------------------------------- /contracts/interfaces/IEventFinancing.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IEventFinancing { 5 | 6 | } -------------------------------------------------------------------------------- /contracts/interfaces/IEventMetadataStorage.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IEventMetadataStorage { 5 | 6 | function registerEvent( 7 | address eventAddress, 8 | address integratorAccountPublicKeyHash, 9 | string calldata eventName, 10 | string calldata shopUrl, 11 | string calldata imageUrl, 12 | bytes32[4] calldata eventMeta, // -> [bytes32 latitude, bytes32 longitude, bytes32 currency, bytes32 ticketeerName] 13 | uint256[2] calldata eventTimes, // -> [uin256 startingTime, uint256 endingTime] 14 | bool setAside, // -> false = default 15 | bytes32[] calldata extraData, 16 | bool isPrivate 17 | ) external; 18 | 19 | function getUnderwriterAddress( 20 | address eventAddress 21 | ) external view returns(address); 22 | 23 | function doesEventExist( 24 | address eventAddress 25 | ) external view returns(bool); 26 | 27 | event newEventRegistered( 28 | address indexed eventAddress, 29 | string indexed eventName, 30 | uint256 indexed timestamp 31 | ); 32 | 33 | event UnderWriterSet( 34 | address eventAddress, 35 | address underWriterAddress, 36 | address requester 37 | ); 38 | 39 | } 40 | 41 | -------------------------------------------------------------------------------- /contracts/interfaces/IGETAccessControl.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IGETAccessControl { 5 | function hasRole(bytes32, address) external view returns (bool); 6 | } -------------------------------------------------------------------------------- /contracts/interfaces/IGETProtocolConfiguration.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IGETProtocolConfiguration { 5 | 6 | function GETgovernanceAddress() external view returns(address); 7 | function feeCollectorAddress() external view returns(address); 8 | function treasuryDAOAddress() external view returns(address); 9 | function stakingContractAddress() external view returns(address); 10 | function emergencyAddress() external view returns(address); 11 | function bufferAddress() external view returns(address); 12 | 13 | function AccessControlGET_proxy_address() external view returns(address); 14 | function baseGETNFT_proxy_address() external view returns(address); 15 | function getNFT_ERC721_proxy_address() external view returns(address); 16 | function eventMetadataStorage_proxy_address() external view returns(address); 17 | function getEventFinancing_proxy_address() external view returns(address); 18 | function economicsGET_proxy_address() external view returns(address); 19 | function fueltoken_get_address() external view returns(address); 20 | 21 | function basicTaxRate() external view returns(uint256); 22 | function priceGETUSD() external view returns(uint256); 23 | 24 | function setAllContractsStorageProxies( 25 | address _access_control_proxy, 26 | address _base_proxy, 27 | address _erc721_proxy, 28 | address _metadata_proxy, 29 | address _financing_proxy, 30 | address _economics_proxy 31 | ) external; 32 | 33 | } -------------------------------------------------------------------------------- /contracts/interfaces/IIndexERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IIndexERC721 { 5 | 6 | function depositERC721(address _token, uint256 _tokenId) external; 7 | function withdrawERC721(address _token, uint256 _tokenId) external; 8 | function withdrawETH() external; 9 | function withdrawERC20(address _token) external; 10 | 11 | } -------------------------------------------------------------------------------- /contracts/interfaces/IIndexERC721Factory.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IIndexERC721Factory { 5 | 6 | function baskets() external returns(address); 7 | 8 | function createBasket() external returns(address); 9 | 10 | } -------------------------------------------------------------------------------- /contracts/interfaces/INFT_ERC721.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IGET_ERC721 { 5 | 6 | function mintERC721( 7 | address destinationAddress, 8 | string calldata ticketURI 9 | ) external returns(uint256); 10 | 11 | function tokenOfOwnerByIndex( 12 | address owner, 13 | uint256 index 14 | ) external view returns(uint256); 15 | 16 | function balanceOf( 17 | address owner 18 | ) external view returns(uint256); 19 | 20 | function relayerTransferFrom( 21 | address originAddress, 22 | address destinationAddress, 23 | uint256 nftIndex 24 | ) external; 25 | 26 | function editTokenURI( 27 | uint256 nftIndex, 28 | string calldata _newTokenURI 29 | ) external; 30 | 31 | function isNftIndex( 32 | uint256 nftIndex 33 | ) external view returns(bool); 34 | 35 | function ownerOf( 36 | uint256 tokenId 37 | ) external view returns (address); 38 | 39 | function setApprovalForAll( 40 | address operator, 41 | bool _approved) external; 42 | 43 | } -------------------------------------------------------------------------------- /contracts/interfaces/INFT_ERC721V3.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IGET_ERC721V3 { 5 | 6 | function mintERC721( 7 | address destinationAddress, 8 | string calldata ticketURI 9 | ) external returns(uint256); 10 | 11 | function mintERC721_V3( 12 | address destinationAddress 13 | ) external returns(uint256); 14 | 15 | function tokenOfOwnerByIndex( 16 | address owner, 17 | uint256 index 18 | ) external view returns(uint256); 19 | 20 | function balanceOf( 21 | address owner 22 | ) external view returns(uint256); 23 | 24 | function relayerTransferFrom( 25 | address originAddress, 26 | address destinationAddress, 27 | uint256 nftIndex 28 | ) external; 29 | 30 | function changeBouncer( 31 | address _newBouncerAddress 32 | ) external; 33 | 34 | function isNftIndex( 35 | uint256 nftIndex 36 | ) external view returns(bool); 37 | 38 | function ownerOf( 39 | uint256 nftIndex 40 | ) external view returns (address); 41 | 42 | function setApprovalForAll( 43 | address operator, 44 | bool _approved) external; 45 | 46 | } -------------------------------------------------------------------------------- /contracts/interfaces/IOracleGET.sol: -------------------------------------------------------------------------------- 1 | 2 | // SPDX-License-Identifier: MIT 3 | pragma solidity ^0.8.0; 4 | 5 | interface IOracleGET { 6 | function update() external; 7 | function consult(address token, uint amountIn) external view returns (uint amountOut); 8 | 9 | function blockTimestampLast() external view returns (uint32); 10 | function PERIOD() external view returns (uint); 11 | 12 | } -------------------------------------------------------------------------------- /contracts/interfaces/ISettingsCollateral.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface ISettingsCollateral { 5 | 6 | function maxAuctionLength() external returns(uint256); 7 | 8 | function minAuctionLength() external returns(uint256); 9 | 10 | function maxCuratorFee() external returns(uint256); 11 | 12 | function governanceFee() external returns(uint256); 13 | 14 | function minBidIncrease() external returns(uint256); 15 | 16 | function minVotePercentage() external returns(uint256); 17 | 18 | function maxReserveFactor() external returns(uint256); 19 | 20 | function minReserveFactor() external returns(uint256); 21 | 22 | function feeReceiver() external returns(address payable); 23 | 24 | } -------------------------------------------------------------------------------- /contracts/interfaces/IUniswapV2Pair.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.5.0; 2 | 3 | interface IUniswapV2Pair { 4 | event Approval(address indexed owner, address indexed spender, uint value); 5 | event Transfer(address indexed from, address indexed to, uint value); 6 | 7 | function name() external pure returns (string memory); 8 | function symbol() external pure returns (string memory); 9 | function decimals() external pure returns (uint8); 10 | function totalSupply() external view returns (uint); 11 | function balanceOf(address owner) external view returns (uint); 12 | function allowance(address owner, address spender) external view returns (uint); 13 | 14 | function approve(address spender, uint value) external returns (bool); 15 | function transfer(address to, uint value) external returns (bool); 16 | function transferFrom(address from, address to, uint value) external returns (bool); 17 | 18 | function DOMAIN_SEPARATOR() external view returns (bytes32); 19 | function PERMIT_TYPEHASH() external pure returns (bytes32); 20 | function nonces(address owner) external view returns (uint); 21 | 22 | function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external; 23 | 24 | event Mint(address indexed sender, uint amount0, uint amount1); 25 | event Burn(address indexed sender, uint amount0, uint amount1, address indexed to); 26 | event Swap( 27 | address indexed sender, 28 | uint amount0In, 29 | uint amount1In, 30 | uint amount0Out, 31 | uint amount1Out, 32 | address indexed to 33 | ); 34 | event Sync(uint112 reserve0, uint112 reserve1); 35 | 36 | function MINIMUM_LIQUIDITY() external pure returns (uint); 37 | function factory() external view returns (address); 38 | function token0() external view returns (address); 39 | function token1() external view returns (address); 40 | function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); 41 | function price0CumulativeLast() external view returns (uint); 42 | function price1CumulativeLast() external view returns (uint); 43 | function kLast() external view returns (uint); 44 | 45 | function mint(address to) external returns (uint liquidity); 46 | function burn(address to) external returns (uint amount0, uint amount1); 47 | function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external; 48 | function skim(address to) external; 49 | function sync() external; 50 | 51 | function initialize(address, address) external; 52 | } 53 | -------------------------------------------------------------------------------- /contracts/interfaces/IfoundationContract.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IfoundationContract { 5 | 6 | // TODO add interface for the foundation base contract 7 | 8 | 9 | } -------------------------------------------------------------------------------- /contracts/interfaces/IsyncConfiguration.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | interface IsyncConfiguration { 5 | function syncConfiguration() external returns(bool); 6 | } 7 | 8 | -------------------------------------------------------------------------------- /contracts/oracles/OracleHelper.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "../interfaces/IOracleGET.sol"; 5 | import "../FoundationContract.sol"; 6 | 7 | contract OracleHelper is FoundationContract { 8 | 9 | // addresses of the oracles 10 | IOracleGET public oracleGETETH; 11 | IOracleGET public oracleUSDCETH; 12 | 13 | address public addressGET; // address of the GET token on POLYGON! 14 | address public addressUSDC; // address of the USDC token on POLYGON! 15 | address public addressETH; // address of wrapped ETH on POLYGON 16 | 17 | // uint32 public stampPreviousUpdate; 18 | uint32 public lastEconomicsUpdate; 19 | 20 | // this is the dollar value of 1 GET in USDC(6 decimals) as it was last stored in the economics contract 21 | // note USDC only has 6 decimals, so if you want to calculate how much dollars it is you need to divide by 1_000_000 22 | uint256 public priceGETUSDLastEconomics; 23 | 24 | uint256 public priceOracleGETETH; 25 | uint256 public priceOracleUSDCETH; 26 | 27 | mapping(address => bool) public isOracleUpdater; 28 | 29 | event PriceGETUSDUpdated( 30 | uint256 priceGETUpdated 31 | ); 32 | 33 | event ThereWasAnAttempt( 34 | address _tryhardAddress 35 | ); 36 | 37 | function __OracleHelper_init_unchained( 38 | address _addressGETETHPool, 39 | address _addressUSDCETHPool, 40 | address _addressGET, 41 | address _addressUSDC, 42 | address _addressETH 43 | ) internal initializer { 44 | oracleGETETH = IOracleGET(_addressGETETHPool); 45 | oracleUSDCETH = IOracleGET(_addressUSDCETHPool); 46 | addressGET = _addressGET; 47 | addressUSDC = _addressUSDC; 48 | addressETH = _addressETH; 49 | } 50 | 51 | function __OracleHelper_init( 52 | address _configurationAddress, 53 | address _addressGETETHPool, 54 | address _addressUSDCETHPool, 55 | address _addressGET, 56 | address _addressUSDC, 57 | address _addressETH 58 | ) public initializer { 59 | __Context_init(); 60 | __FoundationContract_init( 61 | _configurationAddress); 62 | __OracleHelper_init_unchained( 63 | _addressGETETHPool, 64 | _addressUSDCETHPool, 65 | _addressGET, 66 | _addressUSDC, 67 | _addressETH 68 | ); 69 | } 70 | 71 | // constructor( 72 | // address _addressGETETHPool, 73 | // address _addressUSDCETHPool, 74 | // address _addressGET, 75 | // address _addressUSDC, 76 | // address _addressETH 77 | // ) public { 78 | // oracleGETETH = IOracleGET(_addressGETETHPool); 79 | // oracleUSDCETH = IOracleGET(_addressUSDCETHPool); 80 | // addressGET = _addressGET; 81 | // addressUSDC = _addressUSDC; 82 | // addressETH = _addressETH; 83 | // } 84 | 85 | function updateEconomicsPrice() external { 86 | 87 | uint32 _currentBlock = currentBlockTimestamp(); 88 | 89 | uint256 _priceGET = _updateOracles(_currentBlock); 90 | 91 | if (_priceGET != priceGETUSDLastEconomics) { 92 | // update the economics contract 93 | // ECONOMICS.setGETUSDPrice(_priceGET); 94 | 95 | // mint a reward NFT to the updater 96 | // _mintRewardNFT(); 97 | 98 | isOracleUpdater[msg.sender] = true; 99 | 100 | emit PriceGETUSDUpdated( 101 | _priceGET 102 | ); 103 | 104 | } else { 105 | 106 | emit ThereWasAnAttempt( 107 | msg.sender 108 | ); 109 | } 110 | 111 | } 112 | 113 | 114 | function _updateOracles( 115 | uint32 _currentBlock 116 | ) internal returns (uint256) { 117 | 118 | uint256 _priceUSDCETH; 119 | uint256 _priceGETETH; 120 | 121 | if (isGETETHOracleFresh(_currentBlock) == false) { 122 | oracleGETETH.update(); // update the GETETH oracle 123 | 124 | _priceGETETH = oracleGETETH.consult( 125 | addressGET, 126 | 1_00000_00000_00000_000 /** 1e18 = 1 unit of GET */ 127 | ); 128 | } else { 129 | _priceGETETH = priceOracleGETETH; 130 | } 131 | 132 | 133 | if (isUSDCETHOracleFresh(_currentBlock) == false) { 134 | oracleUSDCETH.update(); // update the USDCETH oracle 135 | 136 | // calculate how much units of USDC you receive when selling 1 full ETH in 137 | _priceUSDCETH = oracleUSDCETH.consult( 138 | addressETH, 139 | 1_00000_00000_00000_000 /** 1e18 = 1 unit of ETH */ 140 | ); 141 | } else { 142 | _priceUSDCETH = priceOracleUSDCETH; 143 | } 144 | 145 | // note USDC has 6 decimals, so divide by 1e6 for USD amount 146 | priceGETUSDLastEconomics = (_priceGETETH * _priceUSDCETH) / 1_000_000; 147 | 148 | return priceGETUSDLastEconomics; 149 | 150 | } 151 | 152 | 153 | // checks how long ago the GETETH oracle was updated 154 | function isGETETHOracleFresh( 155 | uint32 _currentBlock 156 | ) public view returns (bool) { 157 | uint32 _updatedLast = oracleGETETH.blockTimestampLast(); 158 | uint32 _diff = _currentBlock - _updatedLast; 159 | uint _period = oracleGETETH.PERIOD(); 160 | 161 | if (_diff >= _period) { // it has been more than 24 hours since the last update of the oracle 162 | return false; 163 | } 164 | else { 165 | return true; 166 | } 167 | } 168 | 169 | // checks how long ago the GETETH oracle was updated 170 | function isUSDCETHOracleFresh( 171 | uint32 _currentBlock 172 | ) public view returns (bool) { 173 | uint32 _updatedLast = oracleUSDCETH.blockTimestampLast(); 174 | uint32 _diff = _currentBlock - _updatedLast; 175 | uint _period = oracleUSDCETH.PERIOD(); 176 | 177 | if (_diff >= _period) { // it has been more than 24 hours since the last update of the oracle 178 | return false; 179 | } 180 | else { 181 | return true; 182 | } 183 | } 184 | 185 | 186 | function currentBlockTimestamp() internal view returns (uint32) { 187 | return uint32(block.timestamp % 2 ** 32); 188 | } 189 | 190 | } -------------------------------------------------------------------------------- /contracts/oracles/data/oracledata.js: -------------------------------------------------------------------------------- 1 | 2 | const oracleData = { 3 | 4 | liquityPoolAddressGET_ETH: "0x3f79187726f13d894ec63e3a70f10ac8ce596318", 5 | liquityPoolAddressUSDC_ETH: "0x853ee4b2a13f8a742d64c8f088be7ba2131f670d", 6 | 7 | tokenAddressGETPolygon: "0xdb725f82818de83e99f1dac22a9b5b51d3d04dd4", 8 | tokenAddressUSDCPolygon: "0x2791bca1f2de4661ed88a30c99a7a9449aa84174", 9 | tokenAddressETHPolygon: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619", 10 | 11 | daysSimulation: 1, 12 | 13 | quickSwapFactory: "0x5757371414417b8C6CAad45bAeF941aBc7d3Ab32", 14 | windowSize: 86400, 15 | granularity: 24, 16 | oracleSwapAmount1: "1", 17 | oracleSwapAmount2: "1000000000000", 18 | 19 | achtienstring: "1000000000000000000", 20 | achtiennummmers: 1000000000000000000, 21 | 22 | deployed_USDCETH_Oracle: "0x33Ab6870275a32FEce80ec7B2d4f8F9364bdE5f9", 23 | deployed_GETETH_Oracle: "0x2D170b04b9188Db150f6c58AFa830Bf16B08a0e8" 24 | 25 | } 26 | 27 | module.exports = oracleData; 28 | -------------------------------------------------------------------------------- /contracts/previous_deployments/AccessControlGET.sol: -------------------------------------------------------------------------------- 1 | // Sources flattened with hardhat v2.6.2 https://hardhat.org 2 | 3 | // File contracts/utils/Initializable.sol 4 | 5 | // SPDX-License-Identifier: MIT 6 | 7 | // solhint-disable-next-line compiler-version 8 | pragma solidity ^0.8.0; 9 | 10 | /** 11 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 12 | * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an 13 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 14 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 15 | * 16 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 17 | * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. 18 | * 19 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 20 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 21 | */ 22 | abstract contract Initializable { 23 | 24 | /** 25 | * @dev Indicates that the contract has been initialized. 26 | */ 27 | bool private _initialized; 28 | 29 | /** 30 | * @dev Indicates that the contract is in the process of being initialized. 31 | */ 32 | bool private _initializing; 33 | 34 | /** 35 | * @dev Modifier to protect an initializer function from being invoked twice. 36 | */ 37 | modifier initializer() { 38 | require(_initializing || !_initialized, "Initializable: contract is already initialized"); 39 | 40 | bool isTopLevelCall = !_initializing; 41 | if (isTopLevelCall) { 42 | _initializing = true; 43 | _initialized = true; 44 | } 45 | 46 | _; 47 | 48 | if (isTopLevelCall) { 49 | _initializing = false; 50 | } 51 | } 52 | } 53 | 54 | /* 55 | * @dev Provides information about the current execution context, including the 56 | * sender of the transaction and its data. While these are generally available 57 | * via msg.sender and msg.data, they should not be accessed in such a direct 58 | * manner, since when dealing with meta-transactions the account sending and 59 | * paying for execution may not be the actual sender (as far as an application 60 | * is concerned). 61 | * 62 | * This contract is only required for intermediate, library-like contracts. 63 | */ 64 | abstract contract ContextUpgradeable is Initializable { 65 | function __Context_init() internal initializer { 66 | __Context_init_unchained(); 67 | } 68 | 69 | function __Context_init_unchained() internal initializer { 70 | } 71 | function _msgSender() internal view virtual returns (address) { 72 | return msg.sender; 73 | } 74 | 75 | function _msgData() internal view virtual returns (bytes calldata) { 76 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 77 | return msg.data; 78 | } 79 | uint256[50] private __gap; 80 | } 81 | 82 | /** 83 | * @dev String operations. 84 | */ 85 | library StringsUpgradeable { 86 | bytes16 private constant alphabet = "0123456789abcdef"; 87 | 88 | /** 89 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 90 | */ 91 | function toString(uint256 value) internal pure returns (string memory) { 92 | // Inspired by OraclizeAPI's implementation - MIT licence 93 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 94 | 95 | if (value == 0) { 96 | return "0"; 97 | } 98 | uint256 temp = value; 99 | uint256 digits; 100 | while (temp != 0) { 101 | digits++; 102 | temp /= 10; 103 | } 104 | bytes memory buffer = new bytes(digits); 105 | while (value != 0) { 106 | digits -= 1; 107 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 108 | value /= 10; 109 | } 110 | return string(buffer); 111 | } 112 | 113 | /** 114 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 115 | */ 116 | function toHexString(uint256 value) internal pure returns (string memory) { 117 | if (value == 0) { 118 | return "0x00"; 119 | } 120 | uint256 temp = value; 121 | uint256 length = 0; 122 | while (temp != 0) { 123 | length++; 124 | temp >>= 8; 125 | } 126 | return toHexString(value, length); 127 | } 128 | 129 | /** 130 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 131 | */ 132 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 133 | bytes memory buffer = new bytes(2 * length + 2); 134 | buffer[0] = "0"; 135 | buffer[1] = "x"; 136 | for (uint256 i = 2 * length + 1; i > 1; --i) { 137 | buffer[i] = alphabet[value & 0xf]; 138 | value >>= 4; 139 | } 140 | require(value == 0, "Strings: hex length insufficient"); 141 | return string(buffer); 142 | } 143 | 144 | } 145 | 146 | 147 | /** 148 | * @dev Interface of the ERC165 standard, as defined in the 149 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 150 | * 151 | * Implementers can declare support of contract interfaces, which can then be 152 | * queried by others ({ERC165Checker}). 153 | * 154 | * For an implementation, see {ERC165}. 155 | */ 156 | interface IERC165Upgradeable { 157 | /** 158 | * @dev Returns true if this contract implements the interface defined by 159 | * `interfaceId`. See the corresponding 160 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 161 | * to learn more about how these ids are created. 162 | * 163 | * This function call must use less than 30 000 gas. 164 | */ 165 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 166 | } 167 | 168 | 169 | 170 | /** 171 | * @dev Implementation of the {IERC165} interface. 172 | * 173 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 174 | * for the additional interface id that will be supported. For example: 175 | * 176 | * ```solidity 177 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 178 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 179 | * } 180 | * ``` 181 | * 182 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 183 | */ 184 | abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { 185 | function __ERC165_init() internal initializer { 186 | __ERC165_init_unchained(); 187 | } 188 | 189 | function __ERC165_init_unchained() internal initializer { 190 | } 191 | /** 192 | * @dev See {IERC165-supportsInterface}. 193 | */ 194 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 195 | return interfaceId == type(IERC165Upgradeable).interfaceId; 196 | } 197 | uint256[50] private __gap; 198 | } 199 | 200 | 201 | 202 | 203 | /** 204 | * @dev External interface of AccessControl declared to support ERC165 detection. 205 | */ 206 | interface IAccessControlUpgradeable { 207 | function hasRole(bytes32 role, address account) external view returns (bool); 208 | function getRoleAdmin(bytes32 role) external view returns (bytes32); 209 | function grantRole(bytes32 role, address account) external; 210 | function revokeRole(bytes32 role, address account) external; 211 | function renounceRole(bytes32 role, address account) external; 212 | } 213 | 214 | /** 215 | * @dev Contract module that allows children to implement role-based access 216 | * control mechanisms. This is a lightweight version that doesn't allow enumerating role 217 | * members except through off-chain means by accessing the contract event logs. Some 218 | * applications may benefit from on-chain enumerability, for those cases see 219 | * {AccessControlEnumerable}. 220 | * 221 | * Roles are referred to by their `bytes32` identifier. These should be exposed 222 | * in the external API and be unique. The best way to achieve this is by 223 | * using `public constant` hash digests: 224 | * 225 | * ``` 226 | * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); 227 | * ``` 228 | * 229 | * Roles can be used to represent a set of permissions. To restrict access to a 230 | * function call, use {hasRole}: 231 | * 232 | * ``` 233 | * function foo() public { 234 | * require(hasRole(MY_ROLE, msg.sender)); 235 | * ... 236 | * } 237 | * ``` 238 | * 239 | * Roles can be granted and revoked dynamically via the {grantRole} and 240 | * {revokeRole} functions. Each role has an associated admin role, and only 241 | * accounts that have a role's admin role can call {grantRole} and {revokeRole}. 242 | * 243 | * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means 244 | * that only accounts with this role will be able to grant or revoke other 245 | * roles. More complex role relationships can be created by using 246 | * {_setRoleAdmin}. 247 | * 248 | * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to 249 | * grant and revoke this role. Extra precautions should be taken to secure 250 | * accounts that have been granted it. 251 | */ 252 | abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { 253 | 254 | 255 | 256 | function __AccessControl_init() internal initializer { 257 | __Context_init_unchained(); 258 | __ERC165_init_unchained(); 259 | __AccessControl_init_unchained(); 260 | } 261 | 262 | function __AccessControl_init_unchained() internal initializer { 263 | } 264 | struct RoleData { 265 | mapping (address => bool) members; 266 | bytes32 adminRole; 267 | } 268 | 269 | mapping (bytes32 => RoleData) private _roles; 270 | 271 | bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; 272 | 273 | /** 274 | * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` 275 | * 276 | * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite 277 | * {RoleAdminChanged} not being emitted signaling this. 278 | * 279 | * _Available since v3.1._ 280 | */ 281 | event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); 282 | 283 | /** 284 | * @dev Emitted when `account` is granted `role`. 285 | * 286 | * `sender` is the account that originated the contract call, an admin role 287 | * bearer except when using {_setupRole}. 288 | */ 289 | event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); 290 | 291 | /** 292 | * @dev Emitted when `account` is revoked `role`. 293 | * 294 | * `sender` is the account that originated the contract call: 295 | * - if using `revokeRole`, it is the admin role bearer 296 | * - if using `renounceRole`, it is the role bearer (i.e. `account`) 297 | */ 298 | event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); 299 | 300 | /** 301 | * @dev Modifier that checks that an account has a specific role. Reverts 302 | * with a standardized message including the required role. 303 | * 304 | * The format of the revert reason is given by the following regular expression: 305 | * 306 | * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ 307 | * 308 | * _Available since v4.1._ 309 | */ 310 | modifier onlyRole(bytes32 role) { 311 | _checkRole(role, _msgSender()); 312 | _; 313 | } 314 | 315 | /** 316 | * @dev See {IERC165-supportsInterface}. 317 | */ 318 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 319 | return interfaceId == type(IAccessControlUpgradeable).interfaceId 320 | || super.supportsInterface(interfaceId); 321 | } 322 | 323 | /** 324 | * @dev Returns `true` if `account` has been granted `role`. 325 | */ 326 | function hasRole(bytes32 role, address account) public view override returns (bool) { 327 | return _roles[role].members[account]; 328 | } 329 | 330 | /** 331 | * @dev Revert with a standard message if `account` is missing `role`. 332 | * 333 | * The format of the revert reason is given by the following regular expression: 334 | * 335 | * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ 336 | */ 337 | function _checkRole(bytes32 role, address account) internal view { 338 | if(!hasRole(role, account)) { 339 | revert(string(abi.encodePacked( 340 | "AccessControl: account ", 341 | StringsUpgradeable.toHexString(uint160(account), 20), 342 | " is missing role ", 343 | StringsUpgradeable.toHexString(uint256(role), 32) 344 | ))); 345 | } 346 | } 347 | 348 | /** 349 | * @dev Returns the admin role that controls `role`. See {grantRole} and 350 | * {revokeRole}. 351 | * 352 | * To change a role's admin, use {_setRoleAdmin}. 353 | */ 354 | function getRoleAdmin(bytes32 role) public view override returns (bytes32) { 355 | return _roles[role].adminRole; 356 | } 357 | 358 | /** 359 | * @dev Grants `role` to `account`. 360 | * 361 | * If `account` had not been already granted `role`, emits a {RoleGranted} 362 | * event. 363 | * 364 | * Requirements: 365 | * 366 | * - the caller must have ``role``'s admin role. 367 | */ 368 | function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { 369 | _grantRole(role, account); 370 | } 371 | 372 | /** 373 | * @dev Revokes `role` from `account`. 374 | * 375 | * If `account` had been granted `role`, emits a {RoleRevoked} event. 376 | * 377 | * Requirements: 378 | * 379 | * - the caller must have ``role``'s admin role. 380 | */ 381 | function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { 382 | _revokeRole(role, account); 383 | } 384 | 385 | /** 386 | * @dev Revokes `role` from the calling account. 387 | * 388 | * Roles are often managed via {grantRole} and {revokeRole}: this function's 389 | * purpose is to provide a mechanism for accounts to lose their privileges 390 | * if they are compromised (such as when a trusted device is misplaced). 391 | * 392 | * If the calling account had been granted `role`, emits a {RoleRevoked} 393 | * event. 394 | * 395 | * Requirements: 396 | * 397 | * - the caller must be `account`. 398 | */ 399 | function renounceRole(bytes32 role, address account) public virtual override { 400 | require(account == _msgSender(), "AccessControl: can only renounce roles for self"); 401 | 402 | _revokeRole(role, account); 403 | } 404 | 405 | /** 406 | * @dev Grants `role` to `account`. 407 | * 408 | * If `account` had not been already granted `role`, emits a {RoleGranted} 409 | * event. Note that unlike {grantRole}, this function doesn't perform any 410 | * checks on the calling account. 411 | * 412 | * [WARNING] 413 | * ==== 414 | * This function should only be called from the constructor when setting 415 | * up the initial roles for the system. 416 | * 417 | * Using this function in any other way is effectively circumventing the admin 418 | * system imposed by {AccessControl}. 419 | * ==== 420 | */ 421 | function _setupRole(bytes32 role, address account) internal virtual { 422 | _grantRole(role, account); 423 | } 424 | 425 | /** 426 | * @dev Sets `adminRole` as ``role``'s admin role. 427 | * 428 | * Emits a {RoleAdminChanged} event. 429 | */ 430 | function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { 431 | emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); 432 | _roles[role].adminRole = adminRole; 433 | } 434 | 435 | function _grantRole(bytes32 role, address account) private { 436 | if (!hasRole(role, account)) { 437 | _roles[role].members[account] = true; 438 | emit RoleGranted(role, account, _msgSender()); 439 | } 440 | } 441 | 442 | function _revokeRole(bytes32 role, address account) private { 443 | if (hasRole(role, account)) { 444 | _roles[role].members[account] = false; 445 | emit RoleRevoked(role, account, _msgSender()); 446 | } 447 | } 448 | uint256[49] private __gap; 449 | } 450 | 451 | 452 | contract AccessControlGET is Initializable, AccessControlUpgradeable { 453 | bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE"); 454 | bytes32 public constant FACTORY_ROLE = keccak256("FACTORY_ROLE"); 455 | bytes32 public constant GET_ADMIN = keccak256("GET_ADMIN"); 456 | bytes32 public constant GET_GOVERNANCE = keccak256("GET_GOVERNANCE"); 457 | 458 | string public constant contractName = "AccessControlGET"; 459 | string public constant contractVersion = "1"; 460 | 461 | function __AccessControlMock_init() public initializer { 462 | __Context_init_unchained(); 463 | __ERC165_init_unchained(); 464 | __AccessControl_init_unchained(); 465 | __AccessControlMock_init_unchained(); 466 | } 467 | 468 | function __AccessControlMock_init_unchained() internal initializer { 469 | _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); 470 | _setupRole(GET_ADMIN, _msgSender()); 471 | _setupRole(FACTORY_ROLE, _msgSender()); 472 | _setupRole(GET_GOVERNANCE, _msgSender()); 473 | _setupRole(RELAYER_ROLE, _msgSender()); 474 | } 475 | 476 | function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public { 477 | _setRoleAdmin(roleId, adminRoleId); 478 | } 479 | 480 | function senderProtected(bytes32 roleId) public onlyRole(roleId) {} 481 | uint256[50] private __gap; 482 | } 483 | -------------------------------------------------------------------------------- /contracts/previous_deployments/AccessControlGETV2.sol: -------------------------------------------------------------------------------- 1 | // Sources flattened with hardhat v2.6.2 https://hardhat.org 2 | 3 | // File contracts/utils/Initializable.sol 4 | 5 | // SPDX-License-Identifier: MIT 6 | 7 | // solhint-disable-next-line compiler-version 8 | pragma solidity ^0.8.0; 9 | 10 | /** 11 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 12 | * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an 13 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 14 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 15 | * 16 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 17 | * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. 18 | * 19 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 20 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 21 | */ 22 | abstract contract Initializable { 23 | 24 | /** 25 | * @dev Indicates that the contract has been initialized. 26 | */ 27 | bool private _initialized; 28 | 29 | /** 30 | * @dev Indicates that the contract is in the process of being initialized. 31 | */ 32 | bool private _initializing; 33 | 34 | /** 35 | * @dev Modifier to protect an initializer function from being invoked twice. 36 | */ 37 | modifier initializer() { 38 | require(_initializing || !_initialized, "Initializable: contract is already initialized"); 39 | 40 | bool isTopLevelCall = !_initializing; 41 | if (isTopLevelCall) { 42 | _initializing = true; 43 | _initialized = true; 44 | } 45 | 46 | _; 47 | 48 | if (isTopLevelCall) { 49 | _initializing = false; 50 | } 51 | } 52 | } 53 | 54 | /* 55 | * @dev Provides information about the current execution context, including the 56 | * sender of the transaction and its data. While these are generally available 57 | * via msg.sender and msg.data, they should not be accessed in such a direct 58 | * manner, since when dealing with meta-transactions the account sending and 59 | * paying for execution may not be the actual sender (as far as an application 60 | * is concerned). 61 | * 62 | * This contract is only required for intermediate, library-like contracts. 63 | */ 64 | abstract contract ContextUpgradeable is Initializable { 65 | function __Context_init() internal initializer { 66 | __Context_init_unchained(); 67 | } 68 | 69 | function __Context_init_unchained() internal initializer { 70 | } 71 | function _msgSender() internal view virtual returns (address) { 72 | return msg.sender; 73 | } 74 | 75 | function _msgData() internal view virtual returns (bytes calldata) { 76 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 77 | return msg.data; 78 | } 79 | uint256[50] private __gap; 80 | } 81 | 82 | /** 83 | * @dev String operations. 84 | */ 85 | library StringsUpgradeable { 86 | bytes16 private constant alphabet = "0123456789abcdef"; 87 | 88 | /** 89 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 90 | */ 91 | function toString(uint256 value) internal pure returns (string memory) { 92 | // Inspired by OraclizeAPI's implementation - MIT licence 93 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 94 | 95 | if (value == 0) { 96 | return "0"; 97 | } 98 | uint256 temp = value; 99 | uint256 digits; 100 | while (temp != 0) { 101 | digits++; 102 | temp /= 10; 103 | } 104 | bytes memory buffer = new bytes(digits); 105 | while (value != 0) { 106 | digits -= 1; 107 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 108 | value /= 10; 109 | } 110 | return string(buffer); 111 | } 112 | 113 | /** 114 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 115 | */ 116 | function toHexString(uint256 value) internal pure returns (string memory) { 117 | if (value == 0) { 118 | return "0x00"; 119 | } 120 | uint256 temp = value; 121 | uint256 length = 0; 122 | while (temp != 0) { 123 | length++; 124 | temp >>= 8; 125 | } 126 | return toHexString(value, length); 127 | } 128 | 129 | /** 130 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 131 | */ 132 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 133 | bytes memory buffer = new bytes(2 * length + 2); 134 | buffer[0] = "0"; 135 | buffer[1] = "x"; 136 | for (uint256 i = 2 * length + 1; i > 1; --i) { 137 | buffer[i] = alphabet[value & 0xf]; 138 | value >>= 4; 139 | } 140 | require(value == 0, "Strings: hex length insufficient"); 141 | return string(buffer); 142 | } 143 | 144 | } 145 | 146 | 147 | /** 148 | * @dev Interface of the ERC165 standard, as defined in the 149 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 150 | * 151 | * Implementers can declare support of contract interfaces, which can then be 152 | * queried by others ({ERC165Checker}). 153 | * 154 | * For an implementation, see {ERC165}. 155 | */ 156 | interface IERC165Upgradeable { 157 | /** 158 | * @dev Returns true if this contract implements the interface defined by 159 | * `interfaceId`. See the corresponding 160 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 161 | * to learn more about how these ids are created. 162 | * 163 | * This function call must use less than 30 000 gas. 164 | */ 165 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 166 | } 167 | 168 | 169 | 170 | /** 171 | * @dev Implementation of the {IERC165} interface. 172 | * 173 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 174 | * for the additional interface id that will be supported. For example: 175 | * 176 | * ```solidity 177 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 178 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 179 | * } 180 | * ``` 181 | * 182 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 183 | */ 184 | abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { 185 | function __ERC165_init() internal initializer { 186 | __ERC165_init_unchained(); 187 | } 188 | 189 | function __ERC165_init_unchained() internal initializer { 190 | } 191 | /** 192 | * @dev See {IERC165-supportsInterface}. 193 | */ 194 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 195 | return interfaceId == type(IERC165Upgradeable).interfaceId; 196 | } 197 | uint256[50] private __gap; 198 | } 199 | 200 | 201 | 202 | 203 | /** 204 | * @dev External interface of AccessControl declared to support ERC165 detection. 205 | */ 206 | interface IAccessControlUpgradeable { 207 | function hasRole(bytes32 role, address account) external view returns (bool); 208 | function getRoleAdmin(bytes32 role) external view returns (bytes32); 209 | function grantRole(bytes32 role, address account) external; 210 | function revokeRole(bytes32 role, address account) external; 211 | function renounceRole(bytes32 role, address account) external; 212 | } 213 | 214 | /** 215 | * @dev Contract module that allows children to implement role-based access 216 | * control mechanisms. This is a lightweight version that doesn't allow enumerating role 217 | * members except through off-chain means by accessing the contract event logs. Some 218 | * applications may benefit from on-chain enumerability, for those cases see 219 | * {AccessControlEnumerable}. 220 | * 221 | * Roles are referred to by their `bytes32` identifier. These should be exposed 222 | * in the external API and be unique. The best way to achieve this is by 223 | * using `public constant` hash digests: 224 | * 225 | * ``` 226 | * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); 227 | * ``` 228 | * 229 | * Roles can be used to represent a set of permissions. To restrict access to a 230 | * function call, use {hasRole}: 231 | * 232 | * ``` 233 | * function foo() public { 234 | * require(hasRole(MY_ROLE, msg.sender)); 235 | * ... 236 | * } 237 | * ``` 238 | * 239 | * Roles can be granted and revoked dynamically via the {grantRole} and 240 | * {revokeRole} functions. Each role has an associated admin role, and only 241 | * accounts that have a role's admin role can call {grantRole} and {revokeRole}. 242 | * 243 | * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means 244 | * that only accounts with this role will be able to grant or revoke other 245 | * roles. More complex role relationships can be created by using 246 | * {_setRoleAdmin}. 247 | * 248 | * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to 249 | * grant and revoke this role. Extra precautions should be taken to secure 250 | * accounts that have been granted it. 251 | */ 252 | abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { 253 | 254 | 255 | 256 | function __AccessControl_init() internal initializer { 257 | __Context_init_unchained(); 258 | __ERC165_init_unchained(); 259 | __AccessControl_init_unchained(); 260 | } 261 | 262 | function __AccessControl_init_unchained() internal initializer { 263 | } 264 | struct RoleData { 265 | mapping (address => bool) members; 266 | bytes32 adminRole; 267 | } 268 | 269 | mapping (bytes32 => RoleData) private _roles; 270 | 271 | bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; 272 | 273 | /** 274 | * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` 275 | * 276 | * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite 277 | * {RoleAdminChanged} not being emitted signaling this. 278 | * 279 | * _Available since v3.1._ 280 | */ 281 | event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); 282 | 283 | /** 284 | * @dev Emitted when `account` is granted `role`. 285 | * 286 | * `sender` is the account that originated the contract call, an admin role 287 | * bearer except when using {_setupRole}. 288 | */ 289 | event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); 290 | 291 | /** 292 | * @dev Emitted when `account` is revoked `role`. 293 | * 294 | * `sender` is the account that originated the contract call: 295 | * - if using `revokeRole`, it is the admin role bearer 296 | * - if using `renounceRole`, it is the role bearer (i.e. `account`) 297 | */ 298 | event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); 299 | 300 | /** 301 | * @dev Modifier that checks that an account has a specific role. Reverts 302 | * with a standardized message including the required role. 303 | * 304 | * The format of the revert reason is given by the following regular expression: 305 | * 306 | * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ 307 | * 308 | * _Available since v4.1._ 309 | */ 310 | modifier onlyRole(bytes32 role) { 311 | _checkRole(role, _msgSender()); 312 | _; 313 | } 314 | 315 | /** 316 | * @dev See {IERC165-supportsInterface}. 317 | */ 318 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 319 | return interfaceId == type(IAccessControlUpgradeable).interfaceId 320 | || super.supportsInterface(interfaceId); 321 | } 322 | 323 | /** 324 | * @dev Returns `true` if `account` has been granted `role`. 325 | */ 326 | function hasRole(bytes32 role, address account) public view override returns (bool) { 327 | return _roles[role].members[account]; 328 | } 329 | 330 | /** 331 | * @dev Revert with a standard message if `account` is missing `role`. 332 | * 333 | * The format of the revert reason is given by the following regular expression: 334 | * 335 | * /^AccessControl: account (0x[0-9a-f]{20}) is missing role (0x[0-9a-f]{32})$/ 336 | */ 337 | function _checkRole(bytes32 role, address account) internal view { 338 | if(!hasRole(role, account)) { 339 | revert(string(abi.encodePacked( 340 | "AccessControl: account ", 341 | StringsUpgradeable.toHexString(uint160(account), 20), 342 | " is missing role ", 343 | StringsUpgradeable.toHexString(uint256(role), 32) 344 | ))); 345 | } 346 | } 347 | 348 | /** 349 | * @dev Returns the admin role that controls `role`. See {grantRole} and 350 | * {revokeRole}. 351 | * 352 | * To change a role's admin, use {_setRoleAdmin}. 353 | */ 354 | function getRoleAdmin(bytes32 role) public view override returns (bytes32) { 355 | return _roles[role].adminRole; 356 | } 357 | 358 | /** 359 | * @dev Grants `role` to `account`. 360 | * 361 | * If `account` had not been already granted `role`, emits a {RoleGranted} 362 | * event. 363 | * 364 | * Requirements: 365 | * 366 | * - the caller must have ``role``'s admin role. 367 | */ 368 | function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { 369 | _grantRole(role, account); 370 | } 371 | 372 | /** 373 | * @dev Revokes `role` from `account`. 374 | * 375 | * If `account` had been granted `role`, emits a {RoleRevoked} event. 376 | * 377 | * Requirements: 378 | * 379 | * - the caller must have ``role``'s admin role. 380 | */ 381 | function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { 382 | _revokeRole(role, account); 383 | } 384 | 385 | /** 386 | * @dev Revokes `role` from the calling account. 387 | * 388 | * Roles are often managed via {grantRole} and {revokeRole}: this function's 389 | * purpose is to provide a mechanism for accounts to lose their privileges 390 | * if they are compromised (such as when a trusted device is misplaced). 391 | * 392 | * If the calling account had been granted `role`, emits a {RoleRevoked} 393 | * event. 394 | * 395 | * Requirements: 396 | * 397 | * - the caller must be `account`. 398 | */ 399 | function renounceRole(bytes32 role, address account) public virtual override { 400 | require(account == _msgSender(), "AccessControl: can only renounce roles for self"); 401 | 402 | _revokeRole(role, account); 403 | } 404 | 405 | /** 406 | * @dev Grants `role` to `account`. 407 | * 408 | * If `account` had not been already granted `role`, emits a {RoleGranted} 409 | * event. Note that unlike {grantRole}, this function doesn't perform any 410 | * checks on the calling account. 411 | * 412 | * [WARNING] 413 | * ==== 414 | * This function should only be called from the constructor when setting 415 | * up the initial roles for the system. 416 | * 417 | * Using this function in any other way is effectively circumventing the admin 418 | * system imposed by {AccessControl}. 419 | * ==== 420 | */ 421 | function _setupRole(bytes32 role, address account) internal virtual { 422 | _grantRole(role, account); 423 | } 424 | 425 | /** 426 | * @dev Sets `adminRole` as ``role``'s admin role. 427 | * 428 | * Emits a {RoleAdminChanged} event. 429 | */ 430 | function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { 431 | emit RoleAdminChanged(role, getRoleAdmin(role), adminRole); 432 | _roles[role].adminRole = adminRole; 433 | } 434 | 435 | function _grantRole(bytes32 role, address account) private { 436 | if (!hasRole(role, account)) { 437 | _roles[role].members[account] = true; 438 | emit RoleGranted(role, account, _msgSender()); 439 | } 440 | } 441 | 442 | function _revokeRole(bytes32 role, address account) private { 443 | if (hasRole(role, account)) { 444 | _roles[role].members[account] = false; 445 | emit RoleRevoked(role, account, _msgSender()); 446 | } 447 | } 448 | uint256[49] private __gap; 449 | } 450 | 451 | 452 | contract AccessControlGETV2 is Initializable, AccessControlUpgradeable { 453 | bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE"); 454 | bytes32 public constant FACTORY_ROLE = keccak256("FACTORY_ROLE"); 455 | bytes32 public constant GET_ADMIN = keccak256("GET_ADMIN"); 456 | bytes32 public constant GET_GOVERNANCE = keccak256("GET_GOVERNANCE"); 457 | 458 | string public constant contractName = "AccessControlGET"; 459 | string public constant contractVersion = "2"; 460 | 461 | function __AccessControlMock_init() public initializer { 462 | __Context_init_unchained(); 463 | __ERC165_init_unchained(); 464 | __AccessControl_init_unchained(); 465 | __AccessControlMock_init_unchained(); 466 | } 467 | 468 | function __AccessControlMock_init_unchained() internal initializer { 469 | _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); 470 | _setupRole(GET_ADMIN, _msgSender()); 471 | _setupRole(FACTORY_ROLE, _msgSender()); 472 | _setupRole(GET_GOVERNANCE, _msgSender()); 473 | _setupRole(RELAYER_ROLE, _msgSender()); 474 | } 475 | 476 | function setRoleAdmin(bytes32 roleId, bytes32 adminRoleId) public onlyRole(DEFAULT_ADMIN_ROLE) { 477 | _setRoleAdmin(roleId, adminRoleId); 478 | } 479 | 480 | function senderProtected(bytes32 roleId) public onlyRole(roleId) {} 481 | uint256[50] private __gap; 482 | } 483 | -------------------------------------------------------------------------------- /contracts/previous_deployments/GETProtocolConfiguration.sol: -------------------------------------------------------------------------------- 1 | //SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | import "./utils/Initializable.sol"; 5 | import "./utils/ContextUpgradeable.sol"; 6 | import "./utils/OwnableUpgradeable.sol"; 7 | 8 | import "./interfaces/IsyncConfiguration.sol"; 9 | import "./interfaces/IGETProtocolConfiguration.sol"; 10 | import "./interfaces/IUniswapV2Pair.sol"; 11 | 12 | contract GETProtocolConfiguration is Initializable, ContextUpgradeable, OwnableUpgradeable { 13 | 14 | address public GETgovernanceAddress; 15 | address payable public feeCollectorAddress; 16 | address payable public treasuryDAOAddress; 17 | address payable public stakingContractAddress; 18 | address payable public emergencyAddress; 19 | address payable public bufferAddressGlobal; 20 | 21 | address private proxyAdminAddress; 22 | address public AccessControlGET_proxy_address; 23 | address public baseGETNFT_proxy_address; 24 | address public getNFT_ERC721_proxy_address; 25 | address public eventMetadataStorage_proxy_address; 26 | address public getEventFinancing_proxy_address; 27 | address public economicsGET_proxy_address; 28 | address public fueltoken_get_address; 29 | 30 | /// global economics configurations (Work in progress) 31 | uint256 public basicTaxRate; 32 | 33 | /// GET and USD price oracle/price feed configurations (work in progress) 34 | uint256 public priceGETUSD; // x1000 35 | IUniswapV2Pair public liquidityPoolGETETH; 36 | IUniswapV2Pair public liquidityPoolETHUSDC; 37 | 38 | function __GETProtocolConfiguration_init_unchained() public initializer {} 39 | 40 | function __GETProtocolConfiguration_init() public initializer { 41 | __Context_init(); 42 | __Ownable_init(); 43 | __GETProtocolConfiguration_init_unchained(); 44 | } 45 | 46 | /// EVENTS 47 | 48 | event UpdateAccessControl(address _old, address _new); 49 | event UpdatebaseGETNFT(address _old, address _new); 50 | event UpdateERC721(address _old, address _new); 51 | event UpdateMetdata(address _old, address _new); 52 | event UpdateFinancing(address _old, address _new); 53 | event UpdateEconomics(address _old, address _new); 54 | event UpdateFueltoken(address _old, address _new); 55 | 56 | event UpdateGoverance(address _old, address _new); 57 | event UpdateFeeCollector(address _old, address _new); 58 | event UpdateTreasuryDAO(address _old, address _new); 59 | event UpdateStakingContract(address _old, address _new); 60 | event UpdateBasicTaxRate(uint256 _old, uint256 _new); 61 | event UpdateGETUSD(uint256 _old, uint256 _new); 62 | event UpdateBufferGlobal(address _old, address _new); 63 | 64 | event UpdateLiquidityPoolAddress( 65 | address _oldPoolGETETH, 66 | address _oldPoolUSDCETH, 67 | address _newPoolGETETH, 68 | address _newPoolUSDCETH 69 | ); 70 | 71 | /// INITIALIZATION 72 | 73 | // this function only needs to be used once, after the initial deploy 74 | function setAllContractsStorageProxies( 75 | address _access_control_proxy, 76 | address _base_proxy, 77 | address _erc721_proxy, 78 | address _metadata_proxy, 79 | address _financing_proxy, 80 | address _economics_proxy 81 | ) external onlyOwner { 82 | // require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 83 | AccessControlGET_proxy_address = _access_control_proxy; 84 | 85 | // require(isContract(_base_proxy), "_base_proxy not a contract"); 86 | baseGETNFT_proxy_address = _base_proxy; 87 | 88 | // require(isContract(_erc721_proxy), "_erc721_proxy not a contract"); 89 | getNFT_ERC721_proxy_address = _erc721_proxy; 90 | 91 | // require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 92 | eventMetadataStorage_proxy_address = _metadata_proxy; 93 | 94 | // require(isContract(_financing_proxy), "_financing_proxy not a contract"); 95 | getEventFinancing_proxy_address = _financing_proxy; 96 | 97 | // require(isContract(_economics_proxy), "_economics_proxy not a contract"); 98 | economicsGET_proxy_address = _economics_proxy; 99 | 100 | // sync the change across all proxies 101 | _callSync(); 102 | 103 | } 104 | 105 | // setting a new AccessControlGET_proxy_address Proxy address 106 | function setAccessControlGETProxy( 107 | address _access_control_proxy 108 | ) external onlyOwner { 109 | 110 | require(isContract(_access_control_proxy), "_access_control_proxy not a contract"); 111 | 112 | emit UpdateAccessControl( 113 | AccessControlGET_proxy_address, 114 | _access_control_proxy 115 | ); 116 | 117 | AccessControlGET_proxy_address = _access_control_proxy; 118 | 119 | // sync the change across all proxies 120 | _callSync(); 121 | 122 | } 123 | 124 | function setBASEProxy( 125 | address _base_proxy) external onlyOwner { 126 | 127 | require(isContract(_base_proxy), "_base_proxy not a contract"); 128 | 129 | emit UpdatebaseGETNFT( 130 | baseGETNFT_proxy_address, 131 | _base_proxy 132 | ); 133 | 134 | baseGETNFT_proxy_address = _base_proxy; 135 | 136 | // sync the change across all proxies 137 | _callSync(); 138 | 139 | } 140 | 141 | function setERC721Proxy( 142 | address _erc721_proxy) external onlyOwner { 143 | 144 | require(isContract(_erc721_proxy), "_erc721_proxy not a contract"); 145 | 146 | emit UpdateERC721( 147 | getNFT_ERC721_proxy_address, 148 | _erc721_proxy 149 | ); 150 | 151 | getNFT_ERC721_proxy_address = _erc721_proxy; 152 | 153 | // sync the change across all proxies 154 | _callSync(); 155 | 156 | } 157 | 158 | function setMetaProxy( 159 | address _metadata_proxy) external onlyOwner { 160 | 161 | require(isContract(_metadata_proxy), "_metadata_proxy not a contract"); 162 | 163 | emit UpdateMetdata( 164 | eventMetadataStorage_proxy_address, 165 | _metadata_proxy 166 | ); 167 | 168 | eventMetadataStorage_proxy_address = _metadata_proxy; 169 | 170 | // sync the change across all proxies 171 | _callSync(); 172 | 173 | } 174 | 175 | function setFinancingProxy( 176 | address _financing_proxy) external onlyOwner { 177 | 178 | require(isContract(_financing_proxy), "_financing_proxy not a contract"); 179 | 180 | emit UpdateFinancing( 181 | getEventFinancing_proxy_address, 182 | _financing_proxy 183 | ); 184 | 185 | getEventFinancing_proxy_address = _financing_proxy; 186 | 187 | // sync the change across all proxies 188 | _callSync(); 189 | 190 | } 191 | 192 | function setEconomicsProxy( 193 | address _economics_proxy) external onlyOwner { 194 | 195 | require(isContract(_economics_proxy), "_economics_proxy not a contract"); 196 | 197 | emit UpdateEconomics( 198 | economicsGET_proxy_address, 199 | _economics_proxy 200 | ); 201 | 202 | economicsGET_proxy_address = _economics_proxy; 203 | 204 | // sync the change across all proxies 205 | _callSync(); 206 | 207 | } 208 | 209 | function setgetNFT_ERC721(address _getNFT_ERC721) external onlyOwner { 210 | 211 | require(isContract(_getNFT_ERC721), "_getNFT_ERC721 not a contract"); 212 | 213 | emit UpdateERC721(getNFT_ERC721_proxy_address, _getNFT_ERC721); 214 | 215 | getNFT_ERC721_proxy_address = _getNFT_ERC721; 216 | 217 | // sync the change across all proxies 218 | _callSync(); 219 | 220 | } 221 | 222 | function setFueltoken(address _fueltoken_get_address) external onlyOwner { 223 | 224 | require(isContract(_fueltoken_get_address), "_fueltoken_get_address not a contract"); 225 | 226 | emit UpdateFueltoken(fueltoken_get_address, _fueltoken_get_address); 227 | 228 | fueltoken_get_address = _fueltoken_get_address; 229 | 230 | // sync the change across all proxies 231 | _callSync(); 232 | 233 | } 234 | 235 | /** 236 | @notice internal function calling all proxy contracts of the protocol and updating all the global values 237 | */ 238 | function _callSync() internal { 239 | 240 | // UPDATE BASE 241 | require(IsyncConfiguration(baseGETNFT_proxy_address).syncConfiguration(), "FAILED_UPDATE_BASE"); 242 | 243 | // UPDATE ECONOMICS 244 | require(IsyncConfiguration(economicsGET_proxy_address).syncConfiguration(), "FAILED_UPDATE_ECONOMICS"); 245 | 246 | // UPDATE METADATA 247 | require(IsyncConfiguration(eventMetadataStorage_proxy_address).syncConfiguration(), "FAILED_UPDATE_METADATA"); 248 | 249 | // UPDATE FINANCING 250 | require(IsyncConfiguration(getEventFinancing_proxy_address).syncConfiguration(), "FAILED_UPDATE_FINANCE"); 251 | 252 | } 253 | 254 | // MANAGING GLOBAL VALUES 255 | 256 | 257 | function setGovernance( 258 | address _newGovernance 259 | ) external onlyOwner { 260 | 261 | // require(isContract(_newGovernance), "_newGovernance not a contract"); 262 | 263 | emit UpdateGoverance(GETgovernanceAddress, _newGovernance); 264 | 265 | GETgovernanceAddress = _newGovernance; 266 | 267 | } 268 | 269 | function setFeeCollector( 270 | address payable _newFeeCollector 271 | ) external onlyOwner { 272 | 273 | require(_newFeeCollector != address(0), "_newFeeCollector cannot be burn address"); 274 | 275 | emit UpdateFeeCollector(feeCollectorAddress, _newFeeCollector); 276 | 277 | feeCollectorAddress = _newFeeCollector; 278 | 279 | } 280 | 281 | function setBufferAddressGlobal( 282 | address payable _newBufferGlobal 283 | ) external onlyOwner { 284 | 285 | require(_newBufferGlobal != address(0), "_newBuffer cannot be burn address"); 286 | 287 | emit UpdateBufferGlobal(bufferAddressGlobal, _newBufferGlobal); 288 | 289 | bufferAddressGlobal = _newBufferGlobal; 290 | 291 | } 292 | 293 | function setTreasuryDAO( 294 | address payable _newTreasury 295 | ) external onlyOwner { 296 | 297 | require(_newTreasury != address(0), "_newTreasury cannot be 0x0"); 298 | 299 | emit UpdateTreasuryDAO(treasuryDAOAddress, _newTreasury); 300 | 301 | treasuryDAOAddress = _newTreasury; 302 | 303 | } 304 | 305 | function setStakingContract( 306 | address payable _newStaking 307 | ) external onlyOwner { 308 | 309 | // require(isContract(_newStaking), "_newStaking not a contract"); 310 | 311 | emit UpdateStakingContract(stakingContractAddress, _newStaking); 312 | 313 | stakingContractAddress = _newStaking; 314 | 315 | } 316 | 317 | function setBasicTaxRate( 318 | uint256 _basicTaxRate 319 | ) external onlyOwner { 320 | 321 | require(_basicTaxRate >= 0, "TAXRATE_INVALID"); 322 | 323 | emit UpdateBasicTaxRate(basicTaxRate, _basicTaxRate); 324 | 325 | basicTaxRate = _basicTaxRate; 326 | 327 | } 328 | 329 | /** function that manually sets the price of GET in USD 330 | @notice this is a temporary approach, in the future it would make most sense to use LP pool TWAP oracles 331 | @dev as for every other contract the USD value is multiplied by 1000 332 | */ 333 | function setGETUSD( 334 | uint256 _newGETUSD 335 | ) external onlyOwner { 336 | emit UpdateGETUSD(priceGETUSD, _newGETUSD); 337 | priceGETUSD = _newGETUSD; 338 | } 339 | 340 | function isContract(address account) internal view returns (bool) { 341 | // This method relies on extcodesize, which returns 0 for contracts in 342 | // construction, since the code is only stored at the end of the 343 | // constructor execution. 344 | 345 | uint256 size; 346 | // solhint-disable-next-line no-inline-assembly 347 | assembly { size := extcodesize(account) } 348 | return size > 0; 349 | } 350 | 351 | 352 | } 353 | -------------------------------------------------------------------------------- /contracts/previous_deployments/MockGET.sol: -------------------------------------------------------------------------------- 1 | // Sources flattened with hardhat v2.6.4 https://hardhat.org 2 | 3 | // File contracts/token/ERC20/IERC20.sol 4 | 5 | // SPDX-License-Identifier: MIT 6 | 7 | pragma solidity ^0.8.0; 8 | 9 | /** 10 | * @dev Interface of the ERC20 standard as defined in the EIP. 11 | */ 12 | interface IERC20 { 13 | /** 14 | * @dev Returns the amount of tokens in existence. 15 | */ 16 | function totalSupply() external view returns (uint256); 17 | 18 | /** 19 | * @dev Returns the amount of tokens owned by `account`. 20 | */ 21 | function balanceOf(address account) external view returns (uint256); 22 | 23 | /** 24 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 25 | * 26 | * Returns a boolean value indicating whether the operation succeeded. 27 | * 28 | * Emits a {Transfer} event. 29 | */ 30 | function transfer(address recipient, uint256 amount) external returns (bool); 31 | 32 | /** 33 | * @dev Returns the remaining number of tokens that `spender` will be 34 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 35 | * zero by default. 36 | * 37 | * This value changes when {approve} or {transferFrom} are called. 38 | */ 39 | function allowance(address owner, address spender) external view returns (uint256); 40 | 41 | /** 42 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 43 | * 44 | * Returns a boolean value indicating whether the operation succeeded. 45 | * 46 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 47 | * that someone may use both the old and the new allowance by unfortunate 48 | * transaction ordering. One possible solution to mitigate this race 49 | * condition is to first reduce the spender's allowance to 0 and set the 50 | * desired value afterwards: 51 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 52 | * 53 | * Emits an {Approval} event. 54 | */ 55 | function approve(address spender, uint256 amount) external returns (bool); 56 | 57 | /** 58 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 59 | * allowance mechanism. `amount` is then deducted from the caller's 60 | * allowance. 61 | * 62 | * Returns a boolean value indicating whether the operation succeeded. 63 | * 64 | * Emits a {Transfer} event. 65 | */ 66 | function transferFrom( 67 | address sender, 68 | address recipient, 69 | uint256 amount 70 | ) external returns (bool); 71 | 72 | /** 73 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 74 | * another (`to`). 75 | * 76 | * Note that `value` may be zero. 77 | */ 78 | event Transfer(address indexed from, address indexed to, uint256 value); 79 | 80 | /** 81 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 82 | * a call to {approve}. `value` is the new allowance. 83 | */ 84 | event Approval(address indexed owner, address indexed spender, uint256 value); 85 | } 86 | 87 | 88 | /** 89 | * @dev Interface for the optional metadata functions from the ERC20 standard. 90 | * 91 | * _Available since v4.1._ 92 | */ 93 | interface IERC20Metadata is IERC20 { 94 | /** 95 | * @dev Returns the name of the token. 96 | */ 97 | function name() external view returns (string memory); 98 | 99 | /** 100 | * @dev Returns the symbol of the token. 101 | */ 102 | function symbol() external view returns (string memory); 103 | 104 | /** 105 | * @dev Returns the decimals places of the token. 106 | */ 107 | function decimals() external view returns (uint8); 108 | } 109 | 110 | 111 | /** 112 | * @dev Provides information about the current execution context, including the 113 | * sender of the transaction and its data. While these are generally available 114 | * via msg.sender and msg.data, they should not be accessed in such a direct 115 | * manner, since when dealing with meta-transactions the account sending and 116 | * paying for execution may not be the actual sender (as far as an application 117 | * is concerned). 118 | * 119 | * This contract is only required for intermediate, library-like contracts. 120 | */ 121 | abstract contract Context { 122 | function _msgSender() internal view virtual returns (address) { 123 | return msg.sender; 124 | } 125 | 126 | function _msgData() internal view virtual returns (bytes calldata) { 127 | return msg.data; 128 | } 129 | } 130 | 131 | 132 | 133 | 134 | /** 135 | * @dev Implementation of the {IERC20} interface. 136 | * 137 | * This implementation is agnostic to the way tokens are created. This means 138 | * that a supply mechanism has to be added in a derived contract using {_mint}. 139 | * For a generic mechanism see {ERC20PresetMinterPauser}. 140 | * 141 | * TIP: For a detailed writeup see our guide 142 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 143 | * to implement supply mechanisms]. 144 | * 145 | * We have followed general OpenZeppelin Contracts guidelines: functions revert 146 | * instead returning `false` on failure. This behavior is nonetheless 147 | * conventional and does not conflict with the expectations of ERC20 148 | * applications. 149 | * 150 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 151 | * This allows applications to reconstruct the allowance for all accounts just 152 | * by listening to said events. Other implementations of the EIP may not emit 153 | * these events, as it isn't required by the specification. 154 | * 155 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 156 | * functions have been added to mitigate the well-known issues around setting 157 | * allowances. See {IERC20-approve}. 158 | */ 159 | contract ERC20 is Context, IERC20, IERC20Metadata { 160 | mapping(address => uint256) private _balances; 161 | 162 | mapping(address => mapping(address => uint256)) private _allowances; 163 | 164 | uint256 private _totalSupply; 165 | 166 | string private _name; 167 | string private _symbol; 168 | 169 | /** 170 | * @dev Sets the values for {name} and {symbol}. 171 | * 172 | * The default value of {decimals} is 18. To select a different value for 173 | * {decimals} you should overload it. 174 | * 175 | * All two of these values are immutable: they can only be set once during 176 | * construction. 177 | */ 178 | constructor(string memory name_, string memory symbol_) { 179 | _name = name_; 180 | _symbol = symbol_; 181 | } 182 | 183 | /** 184 | * @dev Returns the name of the token. 185 | */ 186 | function name() public view virtual override returns (string memory) { 187 | return _name; 188 | } 189 | 190 | /** 191 | * @dev Returns the symbol of the token, usually a shorter version of the 192 | * name. 193 | */ 194 | function symbol() public view virtual override returns (string memory) { 195 | return _symbol; 196 | } 197 | 198 | /** 199 | * @dev Returns the number of decimals used to get its user representation. 200 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 201 | * be displayed to a user as `5.05` (`505 / 10 ** 2`). 202 | * 203 | * Tokens usually opt for a value of 18, imitating the relationship between 204 | * Ether and Wei. This is the value {ERC20} uses, unless this function is 205 | * overridden; 206 | * 207 | * NOTE: This information is only used for _display_ purposes: it in 208 | * no way affects any of the arithmetic of the contract, including 209 | * {IERC20-balanceOf} and {IERC20-transfer}. 210 | */ 211 | function decimals() public view virtual override returns (uint8) { 212 | return 18; 213 | } 214 | 215 | /** 216 | * @dev See {IERC20-totalSupply}. 217 | */ 218 | function totalSupply() public view virtual override returns (uint256) { 219 | return _totalSupply; 220 | } 221 | 222 | /** 223 | * @dev See {IERC20-balanceOf}. 224 | */ 225 | function balanceOf(address account) public view virtual override returns (uint256) { 226 | return _balances[account]; 227 | } 228 | 229 | /** 230 | * @dev See {IERC20-transfer}. 231 | * 232 | * Requirements: 233 | * 234 | * - `recipient` cannot be the zero address. 235 | * - the caller must have a balance of at least `amount`. 236 | */ 237 | function transfer(address recipient, uint256 amount) public virtual override returns (bool) { 238 | _transfer(_msgSender(), recipient, amount); 239 | return true; 240 | } 241 | 242 | /** 243 | * @dev See {IERC20-allowance}. 244 | */ 245 | function allowance(address owner, address spender) public view virtual override returns (uint256) { 246 | return _allowances[owner][spender]; 247 | } 248 | 249 | /** 250 | * @dev See {IERC20-approve}. 251 | * 252 | * Requirements: 253 | * 254 | * - `spender` cannot be the zero address. 255 | */ 256 | function approve(address spender, uint256 amount) public virtual override returns (bool) { 257 | _approve(_msgSender(), spender, amount); 258 | return true; 259 | } 260 | 261 | /** 262 | * @dev See {IERC20-transferFrom}. 263 | * 264 | * Emits an {Approval} event indicating the updated allowance. This is not 265 | * required by the EIP. See the note at the beginning of {ERC20}. 266 | * 267 | * Requirements: 268 | * 269 | * - `sender` and `recipient` cannot be the zero address. 270 | * - `sender` must have a balance of at least `amount`. 271 | * - the caller must have allowance for ``sender``'s tokens of at least 272 | * `amount`. 273 | */ 274 | function transferFrom( 275 | address sender, 276 | address recipient, 277 | uint256 amount 278 | ) public virtual override returns (bool) { 279 | _transfer(sender, recipient, amount); 280 | 281 | uint256 currentAllowance = _allowances[sender][_msgSender()]; 282 | require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); 283 | unchecked { 284 | _approve(sender, _msgSender(), currentAllowance - amount); 285 | } 286 | 287 | return true; 288 | } 289 | 290 | /** 291 | * @dev Atomically increases the allowance granted to `spender` by the caller. 292 | * 293 | * This is an alternative to {approve} that can be used as a mitigation for 294 | * problems described in {IERC20-approve}. 295 | * 296 | * Emits an {Approval} event indicating the updated allowance. 297 | * 298 | * Requirements: 299 | * 300 | * - `spender` cannot be the zero address. 301 | */ 302 | function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { 303 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); 304 | return true; 305 | } 306 | 307 | /** 308 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 309 | * 310 | * This is an alternative to {approve} that can be used as a mitigation for 311 | * problems described in {IERC20-approve}. 312 | * 313 | * Emits an {Approval} event indicating the updated allowance. 314 | * 315 | * Requirements: 316 | * 317 | * - `spender` cannot be the zero address. 318 | * - `spender` must have allowance for the caller of at least 319 | * `subtractedValue`. 320 | */ 321 | function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { 322 | uint256 currentAllowance = _allowances[_msgSender()][spender]; 323 | require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); 324 | unchecked { 325 | _approve(_msgSender(), spender, currentAllowance - subtractedValue); 326 | } 327 | 328 | return true; 329 | } 330 | 331 | /** 332 | * @dev Moves `amount` of tokens from `sender` to `recipient`. 333 | * 334 | * This internal function is equivalent to {transfer}, and can be used to 335 | * e.g. implement automatic token fees, slashing mechanisms, etc. 336 | * 337 | * Emits a {Transfer} event. 338 | * 339 | * Requirements: 340 | * 341 | * - `sender` cannot be the zero address. 342 | * - `recipient` cannot be the zero address. 343 | * - `sender` must have a balance of at least `amount`. 344 | */ 345 | function _transfer( 346 | address sender, 347 | address recipient, 348 | uint256 amount 349 | ) internal virtual { 350 | require(sender != address(0), "ERC20: transfer from the zero address"); 351 | require(recipient != address(0), "ERC20: transfer to the zero address"); 352 | 353 | _beforeTokenTransfer(sender, recipient, amount); 354 | 355 | uint256 senderBalance = _balances[sender]; 356 | require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); 357 | unchecked { 358 | _balances[sender] = senderBalance - amount; 359 | } 360 | _balances[recipient] += amount; 361 | 362 | emit Transfer(sender, recipient, amount); 363 | 364 | _afterTokenTransfer(sender, recipient, amount); 365 | } 366 | 367 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 368 | * the total supply. 369 | * 370 | * Emits a {Transfer} event with `from` set to the zero address. 371 | * 372 | * Requirements: 373 | * 374 | * - `account` cannot be the zero address. 375 | */ 376 | function _mint(address account, uint256 amount) internal virtual { 377 | require(account != address(0), "ERC20: mint to the zero address"); 378 | 379 | _beforeTokenTransfer(address(0), account, amount); 380 | 381 | _totalSupply += amount; 382 | _balances[account] += amount; 383 | emit Transfer(address(0), account, amount); 384 | 385 | _afterTokenTransfer(address(0), account, amount); 386 | } 387 | 388 | /** 389 | * @dev Destroys `amount` tokens from `account`, reducing the 390 | * total supply. 391 | * 392 | * Emits a {Transfer} event with `to` set to the zero address. 393 | * 394 | * Requirements: 395 | * 396 | * - `account` cannot be the zero address. 397 | * - `account` must have at least `amount` tokens. 398 | */ 399 | function _burn(address account, uint256 amount) internal virtual { 400 | require(account != address(0), "ERC20: burn from the zero address"); 401 | 402 | _beforeTokenTransfer(account, address(0), amount); 403 | 404 | uint256 accountBalance = _balances[account]; 405 | require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); 406 | unchecked { 407 | _balances[account] = accountBalance - amount; 408 | } 409 | _totalSupply -= amount; 410 | 411 | emit Transfer(account, address(0), amount); 412 | 413 | _afterTokenTransfer(account, address(0), amount); 414 | } 415 | 416 | /** 417 | * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. 418 | * 419 | * This internal function is equivalent to `approve`, and can be used to 420 | * e.g. set automatic allowances for certain subsystems, etc. 421 | * 422 | * Emits an {Approval} event. 423 | * 424 | * Requirements: 425 | * 426 | * - `owner` cannot be the zero address. 427 | * - `spender` cannot be the zero address. 428 | */ 429 | function _approve( 430 | address owner, 431 | address spender, 432 | uint256 amount 433 | ) internal virtual { 434 | require(owner != address(0), "ERC20: approve from the zero address"); 435 | require(spender != address(0), "ERC20: approve to the zero address"); 436 | 437 | _allowances[owner][spender] = amount; 438 | emit Approval(owner, spender, amount); 439 | } 440 | 441 | /** 442 | * @dev Hook that is called before any transfer of tokens. This includes 443 | * minting and burning. 444 | * 445 | * Calling conditions: 446 | * 447 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 448 | * will be transferred to `to`. 449 | * - when `from` is zero, `amount` tokens will be minted for `to`. 450 | * - when `to` is zero, `amount` of ``from``'s tokens will be burned. 451 | * - `from` and `to` are never both zero. 452 | * 453 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 454 | */ 455 | function _beforeTokenTransfer( 456 | address from, 457 | address to, 458 | uint256 amount 459 | ) internal virtual {} 460 | 461 | /** 462 | * @dev Hook that is called after any transfer of tokens. This includes 463 | * minting and burning. 464 | * 465 | * Calling conditions: 466 | * 467 | * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens 468 | * has been transferred to `to`. 469 | * - when `from` is zero, `amount` tokens have been minted for `to`. 470 | * - when `to` is zero, `amount` of ``from``'s tokens have been burned. 471 | * - `from` and `to` are never both zero. 472 | * 473 | * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. 474 | */ 475 | function _afterTokenTransfer( 476 | address from, 477 | address to, 478 | uint256 amount 479 | ) internal virtual {} 480 | } 481 | 482 | 483 | // mock class using ERC20 484 | contract MockGET is ERC20 { 485 | bytes32 public constant RELAYER_ROLE = keccak256("RELAYER_ROLE"); 486 | bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); 487 | constructor(string memory _name, string memory _symbol) payable ERC20(_name, _symbol) { 488 | } 489 | 490 | function mint(address account, uint256 amount) public { 491 | _mint(account, amount); 492 | } 493 | 494 | function burn(address account, uint256 amount) public { 495 | _burn(account, amount); 496 | } 497 | 498 | function transferInternal( 499 | address from, 500 | address to, 501 | uint256 value 502 | ) public { 503 | _transfer(from, to, value); 504 | } 505 | 506 | function approveInternal( 507 | address owner, 508 | address spender, 509 | uint256 value 510 | ) public { 511 | _approve(owner, spender, value); 512 | } 513 | } 514 | -------------------------------------------------------------------------------- /contracts/previous_deployments/README.MD: -------------------------------------------------------------------------------- 1 | # Deployed contracts 2 | Contains flattened contracts of deployements of previous upgrades. U stands fo "Upgrade" and the integer for the round. If only 1 contract is upgraded this is still an upgrade round. Take note that for the storage proxy structure only the latest contract is of relevance to access if memory is overwritten. This directory is mainly kept to keep track of what was changed over time and in what sequence. 3 | 4 | Whenever a deployment or upgrade is done make carefull 'backups' of the .openzeppelin artifact before and after the upgrade. Make sure not to overwrite old artifacts. It is a huge pain to upgrade contracts without having artifacs and it can even be impossible. To prevent overwriting zip the artifacts (before of before YOUR upgrade as well the artifacts EXACTlY after your upgrade) and add them to the appropriate folder. Make a note in the README.MD file of the upgrade with what was done, any 5 | 6 | ## Folder and contract naming structure 7 | The upgrade round is incremented per cycle. The contract name (both Solidity namespace as file) only increment if the contract code is changed and an upgrade is pushed. This means that it is possible that version of contracts between each other do not match. So a baseNFTV3 and an AccessControlV2, this is because the versioning is per contract not all contracts as a whole. I realize this might be slighly confusing but I don't really see alternatives. Not doing this causes even more problems as we will need to completely seperate the contracts and deployments (we have done that before). I can explain in meat space why this is but has to do with compiling of contracts in Truffle/Hardhat. 8 | 9 | ### U0_DeployedContracts 10 | Original contracts deployed. No artifacts. 11 | 12 | ### U1_DeployedContracts 13 | Upgrade of the baseNFT contract (checkNFT addition). 14 | 15 | ### U2_DeployedContracts 16 | Upgrade of the AccessControl and ERC721 contract. 17 | 18 | ### U3_DeployedContracts 19 | Complete refactor of the protocol. Replacing all contracts except getNFT_ERC721V2.sol (of the U2 upgrade). -------------------------------------------------------------------------------- /contracts/utils/AddressUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Collection of functions related to the address type 7 | */ 8 | library AddressUpgradeable { 9 | /** 10 | * @dev Returns true if `account` is a contract. 11 | * 12 | * [IMPORTANT] 13 | * ==== 14 | * It is unsafe to assume that an address for which this function returns 15 | * false is an externally-owned account (EOA) and not a contract. 16 | * 17 | * Among others, `isContract` will return false for the following 18 | * types of addresses: 19 | * 20 | * - an externally-owned account 21 | * - a contract in construction 22 | * - an address where a contract will be created 23 | * - an address where a contract lived, but was destroyed 24 | * ==== 25 | */ 26 | function isContract(address account) internal view returns (bool) { 27 | // This method relies on extcodesize, which returns 0 for contracts in 28 | // construction, since the code is only stored at the end of the 29 | // constructor execution. 30 | 31 | uint256 size; 32 | // solhint-disable-next-line no-inline-assembly 33 | assembly { size := extcodesize(account) } 34 | return size > 0; 35 | } 36 | 37 | /** 38 | * @dev Replacement for Solidity's `transfer`: sends `amount` wei to 39 | * `recipient`, forwarding all available gas and reverting on errors. 40 | * 41 | * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost 42 | * of certain opcodes, possibly making contracts go over the 2300 gas limit 43 | * imposed by `transfer`, making them unable to receive funds via 44 | * `transfer`. {sendValue} removes this limitation. 45 | * 46 | * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. 47 | * 48 | * IMPORTANT: because control is transferred to `recipient`, care must be 49 | * taken to not create reentrancy vulnerabilities. Consider using 50 | * {ReentrancyGuard} or the 51 | * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. 52 | */ 53 | function sendValue(address payable recipient, uint256 amount) internal { 54 | require(address(this).balance >= amount, "Address: insufficient balance"); 55 | 56 | // solhint-disable-next-line avoid-low-level-calls, avoid-call-value 57 | (bool success, ) = recipient.call{ value: amount }(""); 58 | require(success, "Address: unable to send value, recipient may have reverted"); 59 | } 60 | 61 | /** 62 | * @dev Performs a Solidity function call using a low level `call`. A 63 | * plain`call` is an unsafe replacement for a function call: use this 64 | * function instead. 65 | * 66 | * If `target` reverts with a revert reason, it is bubbled up by this 67 | * function (like regular Solidity function calls). 68 | * 69 | * Returns the raw returned data. To convert to the expected return value, 70 | * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. 71 | * 72 | * Requirements: 73 | * 74 | * - `target` must be a contract. 75 | * - calling `target` with `data` must not revert. 76 | * 77 | * _Available since v3.1._ 78 | */ 79 | function functionCall(address target, bytes memory data) internal returns (bytes memory) { 80 | return functionCall(target, data, "Address: low-level call failed"); 81 | } 82 | 83 | /** 84 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with 85 | * `errorMessage` as a fallback revert reason when `target` reverts. 86 | * 87 | * _Available since v3.1._ 88 | */ 89 | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) { 90 | return functionCallWithValue(target, data, 0, errorMessage); 91 | } 92 | 93 | /** 94 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 95 | * but also transferring `value` wei to `target`. 96 | * 97 | * Requirements: 98 | * 99 | * - the calling contract must have an ETH balance of at least `value`. 100 | * - the called Solidity function must be `payable`. 101 | * 102 | * _Available since v3.1._ 103 | */ 104 | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { 105 | return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); 106 | } 107 | 108 | /** 109 | * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but 110 | * with `errorMessage` as a fallback revert reason when `target` reverts. 111 | * 112 | * _Available since v3.1._ 113 | */ 114 | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) { 115 | require(address(this).balance >= value, "Address: insufficient balance for call"); 116 | require(isContract(target), "Address: call to non-contract"); 117 | 118 | // solhint-disable-next-line avoid-low-level-calls 119 | (bool success, bytes memory returndata) = target.call{ value: value }(data); 120 | return _verifyCallResult(success, returndata, errorMessage); 121 | } 122 | 123 | /** 124 | * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], 125 | * but performing a static call. 126 | * 127 | * _Available since v3.3._ 128 | */ 129 | function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { 130 | return functionStaticCall(target, data, "Address: low-level static call failed"); 131 | } 132 | 133 | /** 134 | * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], 135 | * but performing a static call. 136 | * 137 | * _Available since v3.3._ 138 | */ 139 | function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) { 140 | require(isContract(target), "Address: static call to non-contract"); 141 | 142 | // solhint-disable-next-line avoid-low-level-calls 143 | (bool success, bytes memory returndata) = target.staticcall(data); 144 | return _verifyCallResult(success, returndata, errorMessage); 145 | } 146 | 147 | function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) { 148 | if (success) { 149 | return returndata; 150 | } else { 151 | // Look for revert reason and bubble it up if present 152 | if (returndata.length > 0) { 153 | // The easiest way to bubble the revert reason is using memory via assembly 154 | 155 | // solhint-disable-next-line no-inline-assembly 156 | assembly { 157 | let returndata_size := mload(returndata) 158 | revert(add(32, returndata), returndata_size) 159 | } 160 | } else { 161 | revert(errorMessage); 162 | } 163 | } 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /contracts/utils/ContextUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | import "./Initializable.sol"; 5 | 6 | /* 7 | * @dev Provides information about the current execution context, including the 8 | * sender of the transaction and its data. While these are generally available 9 | * via msg.sender and msg.data, they should not be accessed in such a direct 10 | * manner, since when dealing with meta-transactions the account sending and 11 | * paying for execution may not be the actual sender (as far as an application 12 | * is concerned). 13 | * 14 | * This contract is only required for intermediate, library-like contracts. 15 | */ 16 | abstract contract ContextUpgradeable is Initializable { 17 | function __Context_init() internal initializer { 18 | __Context_init_unchained(); 19 | } 20 | 21 | function __Context_init_unchained() internal initializer { 22 | } 23 | function _msgSender() internal view virtual returns (address) { 24 | return msg.sender; 25 | } 26 | 27 | function _msgData() internal view virtual returns (bytes calldata) { 28 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 29 | return msg.data; 30 | } 31 | uint256[50] private __gap; 32 | } 33 | -------------------------------------------------------------------------------- /contracts/utils/CountersUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @title Counters 7 | * @author Matt Condon (@shrugs) 8 | * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number 9 | * of elements in a mapping, issuing ERC721 ids, or counting request ids. 10 | * 11 | * Include with `using Counters for Counters.Counter;` 12 | */ 13 | library CountersUpgradeable { 14 | struct Counter { 15 | // This variable should never be directly accessed by users of the library: interactions must be restricted to 16 | // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add 17 | // this feature: see https://github.com/ethereum/solidity/issues/4637 18 | uint256 _value; // default: 0 19 | } 20 | 21 | function current(Counter storage counter) internal view returns (uint256) { 22 | return counter._value; 23 | } 24 | 25 | function increment(Counter storage counter) internal { 26 | unchecked { 27 | counter._value += 1; 28 | } 29 | } 30 | 31 | function decrement(Counter storage counter) internal { 32 | uint256 value = counter._value; 33 | require(value > 0, "Counter: decrement overflow"); 34 | unchecked { 35 | counter._value = value - 1; 36 | } 37 | } 38 | 39 | function reset(Counter storage counter) internal { 40 | counter._value = 0; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /contracts/utils/ERC165Upgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./IERC165Upgradeable.sol"; 6 | import "./Initializable.sol"; 7 | 8 | /** 9 | * @dev Implementation of the {IERC165} interface. 10 | * 11 | * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check 12 | * for the additional interface id that will be supported. For example: 13 | * 14 | * ```solidity 15 | * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 16 | * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); 17 | * } 18 | * ``` 19 | * 20 | * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. 21 | */ 22 | abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { 23 | function __ERC165_init() internal initializer { 24 | __ERC165_init_unchained(); 25 | } 26 | 27 | function __ERC165_init_unchained() internal initializer { 28 | } 29 | /** 30 | * @dev See {IERC165-supportsInterface}. 31 | */ 32 | function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { 33 | return interfaceId == type(IERC165Upgradeable).interfaceId; 34 | } 35 | uint256[50] private __gap; 36 | } 37 | -------------------------------------------------------------------------------- /contracts/utils/EnumerableMapUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "./EnumerableSetUpgradeable.sol"; 6 | 7 | /** 8 | * @dev Library for managing an enumerable variant of Solidity's 9 | * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`] 10 | * type. 11 | * 12 | * Maps have the following properties: 13 | * 14 | * - Entries are added, removed, and checked for existence in constant time 15 | * (O(1)). 16 | * - Entries are enumerated in O(n). No guarantees are made on the ordering. 17 | * 18 | * ``` 19 | * contract Example { 20 | * // Add the library methods 21 | * using EnumerableMap for EnumerableMap.UintToAddressMap; 22 | * 23 | * // Declare a set state variable 24 | * EnumerableMap.UintToAddressMap private myMap; 25 | * } 26 | * ``` 27 | * 28 | * As of v3.0.0, only maps of type `uint256 -> address` (`UintToAddressMap`) are 29 | * supported. 30 | */ 31 | library EnumerableMapUpgradeable { 32 | using EnumerableSetUpgradeable for EnumerableSetUpgradeable.Bytes32Set; 33 | 34 | // To implement this library for multiple types with as little code 35 | // repetition as possible, we write it in terms of a generic Map type with 36 | // bytes32 keys and values. 37 | // The Map implementation uses private functions, and user-facing 38 | // implementations (such as Uint256ToAddressMap) are just wrappers around 39 | // the underlying Map. 40 | // This means that we can only create new EnumerableMaps for types that fit 41 | // in bytes32. 42 | 43 | struct Map { 44 | // Storage of keys 45 | EnumerableSetUpgradeable.Bytes32Set _keys; 46 | 47 | mapping (bytes32 => bytes32) _values; 48 | } 49 | 50 | /** 51 | * @dev Adds a key-value pair to a map, or updates the value for an existing 52 | * key. O(1). 53 | * 54 | * Returns true if the key was added to the map, that is if it was not 55 | * already present. 56 | */ 57 | function _set(Map storage map, bytes32 key, bytes32 value) private returns (bool) { 58 | map._values[key] = value; 59 | return map._keys.add(key); 60 | } 61 | 62 | /** 63 | * @dev Removes a key-value pair from a map. O(1). 64 | * 65 | * Returns true if the key was removed from the map, that is if it was present. 66 | */ 67 | function _remove(Map storage map, bytes32 key) private returns (bool) { 68 | delete map._values[key]; 69 | return map._keys.remove(key); 70 | } 71 | 72 | /** 73 | * @dev Returns true if the key is in the map. O(1). 74 | */ 75 | function _contains(Map storage map, bytes32 key) private view returns (bool) { 76 | return map._keys.contains(key); 77 | } 78 | 79 | /** 80 | * @dev Returns the number of key-value pairs in the map. O(1). 81 | */ 82 | function _length(Map storage map) private view returns (uint256) { 83 | return map._keys.length(); 84 | } 85 | 86 | /** 87 | * @dev Returns the key-value pair stored at position `index` in the map. O(1). 88 | * 89 | * Note that there are no guarantees on the ordering of entries inside the 90 | * array, and it may change when more entries are added or removed. 91 | * 92 | * Requirements: 93 | * 94 | * - `index` must be strictly less than {length}. 95 | */ 96 | function _at(Map storage map, uint256 index) private view returns (bytes32, bytes32) { 97 | bytes32 key = map._keys.at(index); 98 | return (key, map._values[key]); 99 | } 100 | 101 | /** 102 | * @dev Tries to returns the value associated with `key`. O(1). 103 | * Does not revert if `key` is not in the map. 104 | */ 105 | function _tryGet(Map storage map, bytes32 key) private view returns (bool, bytes32) { 106 | bytes32 value = map._values[key]; 107 | if (value == bytes32(0)) { 108 | return (_contains(map, key), bytes32(0)); 109 | } else { 110 | return (true, value); 111 | } 112 | } 113 | 114 | /** 115 | * @dev Returns the value associated with `key`. O(1). 116 | * 117 | * Requirements: 118 | * 119 | * - `key` must be in the map. 120 | */ 121 | function _get(Map storage map, bytes32 key) private view returns (bytes32) { 122 | bytes32 value = map._values[key]; 123 | require(value != 0 || _contains(map, key), "EnumerableMap: nonexistent key"); 124 | return value; 125 | } 126 | 127 | /** 128 | * @dev Same as {_get}, with a custom error message when `key` is not in the map. 129 | * 130 | * CAUTION: This function is deprecated because it requires allocating memory for the error 131 | * message unnecessarily. For custom revert reasons use {_tryGet}. 132 | */ 133 | function _get(Map storage map, bytes32 key, string memory errorMessage) private view returns (bytes32) { 134 | bytes32 value = map._values[key]; 135 | require(value != 0 || _contains(map, key), errorMessage); 136 | return value; 137 | } 138 | 139 | // UintToAddressMap 140 | 141 | struct UintToAddressMap { 142 | Map _inner; 143 | } 144 | 145 | /** 146 | * @dev Adds a key-value pair to a map, or updates the value for an existing 147 | * key. O(1). 148 | * 149 | * Returns true if the key was added to the map, that is if it was not 150 | * already present. 151 | */ 152 | function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) { 153 | return _set(map._inner, bytes32(key), bytes32(uint256(uint160(value)))); 154 | } 155 | 156 | /** 157 | * @dev Removes a value from a set. O(1). 158 | * 159 | * Returns true if the key was removed from the map, that is if it was present. 160 | */ 161 | function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) { 162 | return _remove(map._inner, bytes32(key)); 163 | } 164 | 165 | /** 166 | * @dev Returns true if the key is in the map. O(1). 167 | */ 168 | function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) { 169 | return _contains(map._inner, bytes32(key)); 170 | } 171 | 172 | /** 173 | * @dev Returns the number of elements in the map. O(1). 174 | */ 175 | function length(UintToAddressMap storage map) internal view returns (uint256) { 176 | return _length(map._inner); 177 | } 178 | 179 | /** 180 | * @dev Returns the element stored at position `index` in the set. O(1). 181 | * Note that there are no guarantees on the ordering of values inside the 182 | * array, and it may change when more values are added or removed. 183 | * 184 | * Requirements: 185 | * 186 | * - `index` must be strictly less than {length}. 187 | */ 188 | function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256, address) { 189 | (bytes32 key, bytes32 value) = _at(map._inner, index); 190 | return (uint256(key), address(uint160(uint256(value)))); 191 | } 192 | 193 | /** 194 | * @dev Tries to returns the value associated with `key`. O(1). 195 | * Does not revert if `key` is not in the map. 196 | * 197 | * _Available since v3.4._ 198 | */ 199 | function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool, address) { 200 | (bool success, bytes32 value) = _tryGet(map._inner, bytes32(key)); 201 | return (success, address(uint160(uint256(value)))); 202 | } 203 | 204 | /** 205 | * @dev Returns the value associated with `key`. O(1). 206 | * 207 | * Requirements: 208 | * 209 | * - `key` must be in the map. 210 | */ 211 | function get(UintToAddressMap storage map, uint256 key) internal view returns (address) { 212 | return address(uint160(uint256(_get(map._inner, bytes32(key))))); 213 | } 214 | 215 | /** 216 | * @dev Same as {get}, with a custom error message when `key` is not in the map. 217 | * 218 | * CAUTION: This function is deprecated because it requires allocating memory for the error 219 | * message unnecessarily. For custom revert reasons use {tryGet}. 220 | */ 221 | function get(UintToAddressMap storage map, uint256 key, string memory errorMessage) internal view returns (address) { 222 | return address(uint160(uint256(_get(map._inner, bytes32(key), errorMessage)))); 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /contracts/utils/EnumerableSetUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Library for managing 7 | * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive 8 | * types. 9 | * 10 | * Sets have the following properties: 11 | * 12 | * - Elements are added, removed, and checked for existence in constant time 13 | * (O(1)). 14 | * - Elements are enumerated in O(n). No guarantees are made on the ordering. 15 | * 16 | * ``` 17 | * contract Example { 18 | * // Add the library methods 19 | * using EnumerableSet for EnumerableSet.AddressSet; 20 | * 21 | * // Declare a set state variable 22 | * EnumerableSet.AddressSet private mySet; 23 | * } 24 | * ``` 25 | * 26 | * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) 27 | * and `uint256` (`UintSet`) are supported. 28 | */ 29 | library EnumerableSetUpgradeable { 30 | // To implement this library for multiple types with as little code 31 | // repetition as possible, we write it in terms of a generic Set type with 32 | // bytes32 values. 33 | // The Set implementation uses private functions, and user-facing 34 | // implementations (such as AddressSet) are just wrappers around the 35 | // underlying Set. 36 | // This means that we can only create new EnumerableSets for types that fit 37 | // in bytes32. 38 | 39 | struct Set { 40 | // Storage of set values 41 | bytes32[] _values; 42 | 43 | // Position of the value in the `values` array, plus 1 because index 0 44 | // means a value is not in the set. 45 | mapping (bytes32 => uint256) _indexes; 46 | } 47 | 48 | /** 49 | * @dev Add a value to a set. O(1). 50 | * 51 | * Returns true if the value was added to the set, that is if it was not 52 | * already present. 53 | */ 54 | function _add(Set storage set, bytes32 value) private returns (bool) { 55 | if (!_contains(set, value)) { 56 | set._values.push(value); 57 | // The value is stored at length-1, but we add 1 to all indexes 58 | // and use 0 as a sentinel value 59 | set._indexes[value] = set._values.length; 60 | return true; 61 | } else { 62 | return false; 63 | } 64 | } 65 | 66 | /** 67 | * @dev Removes a value from a set. O(1). 68 | * 69 | * Returns true if the value was removed from the set, that is if it was 70 | * present. 71 | */ 72 | function _remove(Set storage set, bytes32 value) private returns (bool) { 73 | // We read and store the value's index to prevent multiple reads from the same storage slot 74 | uint256 valueIndex = set._indexes[value]; 75 | 76 | if (valueIndex != 0) { // Equivalent to contains(set, value) 77 | // To delete an element from the _values array in O(1), we swap the element to delete with the last one in 78 | // the array, and then remove the last element (sometimes called as 'swap and pop'). 79 | // This modifies the order of the array, as noted in {at}. 80 | 81 | uint256 toDeleteIndex = valueIndex - 1; 82 | uint256 lastIndex = set._values.length - 1; 83 | 84 | if (lastIndex != toDeleteIndex) { 85 | bytes32 lastvalue = set._values[lastIndex]; 86 | 87 | // Move the last value to the index where the value to delete is 88 | set._values[toDeleteIndex] = lastvalue; 89 | // Update the index for the moved value 90 | set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex 91 | } 92 | 93 | // Delete the slot where the moved value was stored 94 | set._values.pop(); 95 | 96 | // Delete the index for the deleted slot 97 | delete set._indexes[value]; 98 | 99 | return true; 100 | } else { 101 | return false; 102 | } 103 | } 104 | 105 | /** 106 | * @dev Returns true if the value is in the set. O(1). 107 | */ 108 | function _contains(Set storage set, bytes32 value) private view returns (bool) { 109 | return set._indexes[value] != 0; 110 | } 111 | 112 | /** 113 | * @dev Returns the number of values on the set. O(1). 114 | */ 115 | function _length(Set storage set) private view returns (uint256) { 116 | return set._values.length; 117 | } 118 | 119 | /** 120 | * @dev Returns the value stored at position `index` in the set. O(1). 121 | * 122 | * Note that there are no guarantees on the ordering of values inside the 123 | * array, and it may change when more values are added or removed. 124 | * 125 | * Requirements: 126 | * 127 | * - `index` must be strictly less than {length}. 128 | */ 129 | function _at(Set storage set, uint256 index) private view returns (bytes32) { 130 | return set._values[index]; 131 | } 132 | 133 | // Bytes32Set 134 | 135 | struct Bytes32Set { 136 | Set _inner; 137 | } 138 | 139 | /** 140 | * @dev Add a value to a set. O(1). 141 | * 142 | * Returns true if the value was added to the set, that is if it was not 143 | * already present. 144 | */ 145 | function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { 146 | return _add(set._inner, value); 147 | } 148 | 149 | /** 150 | * @dev Removes a value from a set. O(1). 151 | * 152 | * Returns true if the value was removed from the set, that is if it was 153 | * present. 154 | */ 155 | function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { 156 | return _remove(set._inner, value); 157 | } 158 | 159 | /** 160 | * @dev Returns true if the value is in the set. O(1). 161 | */ 162 | function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { 163 | return _contains(set._inner, value); 164 | } 165 | 166 | /** 167 | * @dev Returns the number of values in the set. O(1). 168 | */ 169 | function length(Bytes32Set storage set) internal view returns (uint256) { 170 | return _length(set._inner); 171 | } 172 | 173 | /** 174 | * @dev Returns the value stored at position `index` in the set. O(1). 175 | * 176 | * Note that there are no guarantees on the ordering of values inside the 177 | * array, and it may change when more values are added or removed. 178 | * 179 | * Requirements: 180 | * 181 | * - `index` must be strictly less than {length}. 182 | */ 183 | function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { 184 | return _at(set._inner, index); 185 | } 186 | 187 | // AddressSet 188 | 189 | struct AddressSet { 190 | Set _inner; 191 | } 192 | 193 | /** 194 | * @dev Add a value to a set. O(1). 195 | * 196 | * Returns true if the value was added to the set, that is if it was not 197 | * already present. 198 | */ 199 | function add(AddressSet storage set, address value) internal returns (bool) { 200 | return _add(set._inner, bytes32(uint256(uint160(value)))); 201 | } 202 | 203 | /** 204 | * @dev Removes a value from a set. O(1). 205 | * 206 | * Returns true if the value was removed from the set, that is if it was 207 | * present. 208 | */ 209 | function remove(AddressSet storage set, address value) internal returns (bool) { 210 | return _remove(set._inner, bytes32(uint256(uint160(value)))); 211 | } 212 | 213 | /** 214 | * @dev Returns true if the value is in the set. O(1). 215 | */ 216 | function contains(AddressSet storage set, address value) internal view returns (bool) { 217 | return _contains(set._inner, bytes32(uint256(uint160(value)))); 218 | } 219 | 220 | /** 221 | * @dev Returns the number of values in the set. O(1). 222 | */ 223 | function length(AddressSet storage set) internal view returns (uint256) { 224 | return _length(set._inner); 225 | } 226 | 227 | /** 228 | * @dev Returns the value stored at position `index` in the set. O(1). 229 | * 230 | * Note that there are no guarantees on the ordering of values inside the 231 | * array, and it may change when more values are added or removed. 232 | * 233 | * Requirements: 234 | * 235 | * - `index` must be strictly less than {length}. 236 | */ 237 | function at(AddressSet storage set, uint256 index) internal view returns (address) { 238 | return address(uint160(uint256(_at(set._inner, index)))); 239 | } 240 | 241 | 242 | // UintSet 243 | 244 | struct UintSet { 245 | Set _inner; 246 | } 247 | 248 | /** 249 | * @dev Add a value to a set. O(1). 250 | * 251 | * Returns true if the value was added to the set, that is if it was not 252 | * already present. 253 | */ 254 | function add(UintSet storage set, uint256 value) internal returns (bool) { 255 | return _add(set._inner, bytes32(value)); 256 | } 257 | 258 | /** 259 | * @dev Removes a value from a set. O(1). 260 | * 261 | * Returns true if the value was removed from the set, that is if it was 262 | * present. 263 | */ 264 | function remove(UintSet storage set, uint256 value) internal returns (bool) { 265 | return _remove(set._inner, bytes32(value)); 266 | } 267 | 268 | /** 269 | * @dev Returns true if the value is in the set. O(1). 270 | */ 271 | function contains(UintSet storage set, uint256 value) internal view returns (bool) { 272 | return _contains(set._inner, bytes32(value)); 273 | } 274 | 275 | /** 276 | * @dev Returns the number of values on the set. O(1). 277 | */ 278 | function length(UintSet storage set) internal view returns (uint256) { 279 | return _length(set._inner); 280 | } 281 | 282 | /** 283 | * @dev Returns the value stored at position `index` in the set. O(1). 284 | * 285 | * Note that there are no guarantees on the ordering of values inside the 286 | * array, and it may change when more values are added or removed. 287 | * 288 | * Requirements: 289 | * 290 | * - `index` must be strictly less than {length}. 291 | */ 292 | function at(UintSet storage set, uint256 index) internal view returns (uint256) { 293 | return uint256(_at(set._inner, index)); 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /contracts/utils/IERC165Upgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev Interface of the ERC165 standard, as defined in the 7 | * https://eips.ethereum.org/EIPS/eip-165[EIP]. 8 | * 9 | * Implementers can declare support of contract interfaces, which can then be 10 | * queried by others ({ERC165Checker}). 11 | * 12 | * For an implementation, see {ERC165}. 13 | */ 14 | interface IERC165Upgradeable { 15 | /** 16 | * @dev Returns true if this contract implements the interface defined by 17 | * `interfaceId`. See the corresponding 18 | * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] 19 | * to learn more about how these ids are created. 20 | * 21 | * This function call must use less than 30 000 gas. 22 | */ 23 | function supportsInterface(bytes4 interfaceId) external view returns (bool); 24 | } 25 | -------------------------------------------------------------------------------- /contracts/utils/Initializable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | // solhint-disable-next-line compiler-version 4 | pragma solidity ^0.8.0; 5 | 6 | /** 7 | * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed 8 | * behind a proxy. Since a proxied contract can't have a constructor, it's common to move constructor logic to an 9 | * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer 10 | * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. 11 | * 12 | * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as 13 | * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. 14 | * 15 | * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure 16 | * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. 17 | */ 18 | abstract contract Initializable { 19 | 20 | /** 21 | * @dev Indicates that the contract has been initialized. 22 | */ 23 | bool private _initialized; 24 | 25 | /** 26 | * @dev Indicates that the contract is in the process of being initialized. 27 | */ 28 | bool private _initializing; 29 | 30 | /** 31 | * @dev Modifier to protect an initializer function from being invoked twice. 32 | */ 33 | modifier initializer() { 34 | require(_initializing || !_initialized, "Initializable: contract is already initialized"); 35 | 36 | bool isTopLevelCall = !_initializing; 37 | if (isTopLevelCall) { 38 | _initializing = true; 39 | _initialized = true; 40 | } 41 | 42 | _; 43 | 44 | if (isTopLevelCall) { 45 | _initializing = false; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /contracts/utils/Migrations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.0; 3 | 4 | contract Migrations { 5 | address public owner = msg.sender; 6 | uint public last_completed_migration; 7 | 8 | modifier restricted() { 9 | require( 10 | msg.sender == owner, 11 | "This function is restricted to the contract's owner" 12 | ); 13 | _; 14 | } 15 | 16 | function setCompleted(uint completed) public restricted { 17 | last_completed_migration = completed; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /contracts/utils/OwnableUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | import "../utils/ContextUpgradeable.sol"; 6 | import "./Initializable.sol"; 7 | /** 8 | * @dev Contract module which provides a basic access control mechanism, where 9 | * there is an account (an owner) that can be granted exclusive access to 10 | * specific functions. 11 | * 12 | * By default, the owner account will be the one that deploys the contract. This 13 | * can later be changed with {transferOwnership}. 14 | * 15 | * This module is used through inheritance. It will make available the modifier 16 | * `onlyOwner`, which can be applied to your functions to restrict their use to 17 | * the owner. 18 | */ 19 | abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable { 20 | address private _owner; 21 | 22 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 23 | 24 | /** 25 | * @dev Initializes the contract setting the deployer as the initial owner. 26 | */ 27 | function __Ownable_init() internal initializer { 28 | __Context_init_unchained(); 29 | __Ownable_init_unchained(); 30 | } 31 | 32 | function __Ownable_init_unchained() internal initializer { 33 | address msgSender = _msgSender(); 34 | _owner = msgSender; 35 | emit OwnershipTransferred(address(0), msgSender); 36 | } 37 | 38 | /** 39 | * @dev Returns the address of the current owner. 40 | */ 41 | function owner() public view virtual returns (address) { 42 | return _owner; 43 | } 44 | 45 | /** 46 | * @dev Throws if called by any account other than the owner. 47 | */ 48 | modifier onlyOwner() { 49 | require(owner() == _msgSender(), "Ownable: caller is not the owner"); 50 | _; 51 | } 52 | 53 | /** 54 | * @dev Leaves the contract without owner. It will not be possible to call 55 | * `onlyOwner` functions anymore. Can only be called by the current owner. 56 | * 57 | * NOTE: Renouncing ownership will leave the contract without an owner, 58 | * thereby removing any functionality that is only available to the owner. 59 | */ 60 | function renounceOwnership() public virtual onlyOwner { 61 | emit OwnershipTransferred(_owner, address(0)); 62 | _owner = address(0); 63 | } 64 | 65 | /** 66 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 67 | * Can only be called by the current owner. 68 | */ 69 | function transferOwnership(address newOwner) public virtual onlyOwner { 70 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 71 | emit OwnershipTransferred(_owner, newOwner); 72 | _owner = newOwner; 73 | } 74 | uint256[49] private __gap; 75 | } 76 | -------------------------------------------------------------------------------- /contracts/utils/ReentrancyGuardUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | import "./Initializable.sol"; 5 | 6 | /** 7 | * @dev Contract module that helps prevent reentrant calls to a function. 8 | * 9 | * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier 10 | * available, which can be applied to functions to make sure there are no nested 11 | * (reentrant) calls to them. 12 | * 13 | * Note that because there is a single `nonReentrant` guard, functions marked as 14 | * `nonReentrant` may not call one another. This can be worked around by making 15 | * those functions `private`, and then adding `external` `nonReentrant` entry 16 | * points to them. 17 | * 18 | * TIP: If you would like to learn more about reentrancy and alternative ways 19 | * to protect against it, check out our blog post 20 | * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. 21 | */ 22 | abstract contract ReentrancyGuardUpgradeable is Initializable { 23 | // Booleans are more expensive than uint256 or any type that takes up a full 24 | // word because each write operation emits an extra SLOAD to first read the 25 | // slot's contents, replace the bits taken up by the boolean, and then write 26 | // back. This is the compiler's defense against contract upgrades and 27 | // pointer aliasing, and it cannot be disabled. 28 | 29 | // The values being non-zero value makes deployment a bit more expensive, 30 | // but in exchange the refund on every call to nonReentrant will be lower in 31 | // amount. Since refunds are capped to a percentage of the total 32 | // transaction's gas, it is best to keep them low in cases like this one, to 33 | // increase the likelihood of the full refund coming into effect. 34 | uint256 private constant _NOT_ENTERED = 1; 35 | uint256 private constant _ENTERED = 2; 36 | 37 | uint256 private _status; 38 | 39 | function __ReentrancyGuard_init() internal initializer { 40 | __ReentrancyGuard_init_unchained(); 41 | } 42 | 43 | function __ReentrancyGuard_init_unchained() internal initializer { 44 | _status = _NOT_ENTERED; 45 | } 46 | 47 | /** 48 | * @dev Prevents a contract from calling itself, directly or indirectly. 49 | * Calling a `nonReentrant` function from another `nonReentrant` 50 | * function is not supported. It is possible to prevent this from happening 51 | * by making the `nonReentrant` function external, and making it call a 52 | * `private` function that does the actual work. 53 | */ 54 | modifier nonReentrant() { 55 | // On the first call to nonReentrant, _notEntered will be true 56 | require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); 57 | 58 | // Any calls to nonReentrant after this point will fail 59 | _status = _ENTERED; 60 | 61 | _; 62 | 63 | // By storing the original value once again, a refund is triggered (see 64 | // https://eips.ethereum.org/EIPS/eip-2200) 65 | _status = _NOT_ENTERED; 66 | } 67 | uint256[49] private __gap; 68 | } -------------------------------------------------------------------------------- /contracts/utils/SafeMathUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | // CAUTION 6 | // This version of SafeMath should only be used with Solidity 0.8 or later, 7 | // because it relies on the compiler's built in overflow checks. 8 | 9 | /** 10 | * @dev Wrappers over Solidity's arithmetic operations. 11 | * 12 | * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler 13 | * now has built in overflow checking. 14 | */ 15 | library SafeMathUpgradeable { 16 | /** 17 | * @dev Returns the addition of two unsigned integers, with an overflow flag. 18 | * 19 | * _Available since v3.4._ 20 | */ 21 | function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { 22 | unchecked { 23 | uint256 c = a + b; 24 | if (c < a) return (false, 0); 25 | return (true, c); 26 | } 27 | } 28 | 29 | /** 30 | * @dev Returns the substraction of two unsigned integers, with an overflow flag. 31 | * 32 | * _Available since v3.4._ 33 | */ 34 | function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { 35 | unchecked { 36 | if (b > a) return (false, 0); 37 | return (true, a - b); 38 | } 39 | } 40 | 41 | /** 42 | * @dev Returns the multiplication of two unsigned integers, with an overflow flag. 43 | * 44 | * _Available since v3.4._ 45 | */ 46 | function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { 47 | unchecked { 48 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 49 | // benefit is lost if 'b' is also tested. 50 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 51 | if (a == 0) return (true, 0); 52 | uint256 c = a * b; 53 | if (c / a != b) return (false, 0); 54 | return (true, c); 55 | } 56 | } 57 | 58 | /** 59 | * @dev Returns the division of two unsigned integers, with a division by zero flag. 60 | * 61 | * _Available since v3.4._ 62 | */ 63 | function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { 64 | unchecked { 65 | if (b == 0) return (false, 0); 66 | return (true, a / b); 67 | } 68 | } 69 | 70 | /** 71 | * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. 72 | * 73 | * _Available since v3.4._ 74 | */ 75 | function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { 76 | unchecked { 77 | if (b == 0) return (false, 0); 78 | return (true, a % b); 79 | } 80 | } 81 | 82 | /** 83 | * @dev Returns the addition of two unsigned integers, reverting on 84 | * overflow. 85 | * 86 | * Counterpart to Solidity's `+` operator. 87 | * 88 | * Requirements: 89 | * 90 | * - Addition cannot overflow. 91 | */ 92 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 93 | return a + b; 94 | } 95 | 96 | /** 97 | * @dev Returns the subtraction of two unsigned integers, reverting on 98 | * overflow (when the result is negative). 99 | * 100 | * Counterpart to Solidity's `-` operator. 101 | * 102 | * Requirements: 103 | * 104 | * - Subtraction cannot overflow. 105 | */ 106 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 107 | return a - b; 108 | } 109 | 110 | /** 111 | * @dev Returns the multiplication of two unsigned integers, reverting on 112 | * overflow. 113 | * 114 | * Counterpart to Solidity's `*` operator. 115 | * 116 | * Requirements: 117 | * 118 | * - Multiplication cannot overflow. 119 | */ 120 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 121 | return a * b; 122 | } 123 | 124 | /** 125 | * @dev Returns the integer division of two unsigned integers, reverting on 126 | * division by zero. The result is rounded towards zero. 127 | * 128 | * Counterpart to Solidity's `/` operator. 129 | * 130 | * Requirements: 131 | * 132 | * - The divisor cannot be zero. 133 | */ 134 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 135 | return a / b; 136 | } 137 | 138 | /** 139 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 140 | * reverting when dividing by zero. 141 | * 142 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 143 | * opcode (which leaves remaining gas untouched) while Solidity uses an 144 | * invalid opcode to revert (consuming all remaining gas). 145 | * 146 | * Requirements: 147 | * 148 | * - The divisor cannot be zero. 149 | */ 150 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 151 | return a % b; 152 | } 153 | 154 | /** 155 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 156 | * overflow (when the result is negative). 157 | * 158 | * CAUTION: This function is deprecated because it requires allocating memory for the error 159 | * message unnecessarily. For custom revert reasons use {trySub}. 160 | * 161 | * Counterpart to Solidity's `-` operator. 162 | * 163 | * Requirements: 164 | * 165 | * - Subtraction cannot overflow. 166 | */ 167 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 168 | unchecked { 169 | require(b <= a, errorMessage); 170 | return a - b; 171 | } 172 | } 173 | 174 | /** 175 | * @dev Returns the integer division of two unsigned integers, reverting with custom message on 176 | * division by zero. The result is rounded towards zero. 177 | * 178 | * Counterpart to Solidity's `/` operator. Note: this function uses a 179 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 180 | * uses an invalid opcode to revert (consuming all remaining gas). 181 | * 182 | * Requirements: 183 | * 184 | * - The divisor cannot be zero. 185 | */ 186 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 187 | unchecked { 188 | require(b > 0, errorMessage); 189 | return a / b; 190 | } 191 | } 192 | 193 | /** 194 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 195 | * reverting with custom message when dividing by zero. 196 | * 197 | * CAUTION: This function is deprecated because it requires allocating memory for the error 198 | * message unnecessarily. For custom revert reasons use {tryMod}. 199 | * 200 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 201 | * opcode (which leaves remaining gas untouched) while Solidity uses an 202 | * invalid opcode to revert (consuming all remaining gas). 203 | * 204 | * Requirements: 205 | * 206 | * - The divisor cannot be zero. 207 | */ 208 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 209 | unchecked { 210 | require(b > 0, errorMessage); 211 | return a % b; 212 | } 213 | } 214 | } 215 | -------------------------------------------------------------------------------- /contracts/utils/StringsUpgradeable.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | pragma solidity ^0.8.0; 4 | 5 | /** 6 | * @dev String operations. 7 | */ 8 | library StringsUpgradeable { 9 | bytes16 private constant alphabet = "0123456789abcdef"; 10 | 11 | /** 12 | * @dev Converts a `uint256` to its ASCII `string` decimal representation. 13 | */ 14 | function toString(uint256 value) internal pure returns (string memory) { 15 | // Inspired by OraclizeAPI's implementation - MIT licence 16 | // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol 17 | 18 | if (value == 0) { 19 | return "0"; 20 | } 21 | uint256 temp = value; 22 | uint256 digits; 23 | while (temp != 0) { 24 | digits++; 25 | temp /= 10; 26 | } 27 | bytes memory buffer = new bytes(digits); 28 | while (value != 0) { 29 | digits -= 1; 30 | buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); 31 | value /= 10; 32 | } 33 | return string(buffer); 34 | } 35 | 36 | /** 37 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. 38 | */ 39 | function toHexString(uint256 value) internal pure returns (string memory) { 40 | if (value == 0) { 41 | return "0x00"; 42 | } 43 | uint256 temp = value; 44 | uint256 length = 0; 45 | while (temp != 0) { 46 | length++; 47 | temp >>= 8; 48 | } 49 | return toHexString(value, length); 50 | } 51 | 52 | /** 53 | * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. 54 | */ 55 | function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { 56 | bytes memory buffer = new bytes(2 * length + 2); 57 | buffer[0] = "0"; 58 | buffer[1] = "x"; 59 | for (uint256 i = 2 * length + 1; i > 1; --i) { 60 | buffer[i] = alphabet[value & 0xf]; 61 | value >>= 4; 62 | } 63 | require(value == 0, "Strings: hex length insufficient"); 64 | return string(buffer); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "upgrade_fresh", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@nomiclabs/hardhat-ethers": "^2.0.1", 14 | "@nomiclabs/hardhat-etherscan": "^2.1.1", 15 | "@nomiclabs/hardhat-truffle5": "^2.0.0", 16 | "@nomiclabs/hardhat-waffle": "^2.0.1", 17 | "@nomiclabs/hardhat-web3": "^2.0.0", 18 | "@openzeppelin/hardhat-upgrades": "^1.6.0", 19 | "@openzeppelin/truffle-upgrades": "^1.5.0", 20 | "chai": "^4.3.0", 21 | "ethereum-waffle": "^3.2.2", 22 | "ethers": "^5.0.31", 23 | "hardhat": "^2.0.10", 24 | "web3": "^1.2.9" 25 | } 26 | } 27 | --------------------------------------------------------------------------------