github.com/status-im/status-go@v1.1.0/contracts/stickers/contracts.sol (about) 1 // This solidity file was added to the project to generate the ABI to consume 2 // these smart contracts: 3 // 0x0577215622f43a39f4bc9640806dfea9b10d2a36: StickerType 4 // 0x12824271339304d3a9f7e096e62a2a7e73b4a7e7: StickerMarket 5 // 0x110101156e8F0743948B2A61aFcf3994A8Fb172e: StickerPack 6 7 pragma solidity ^0.5.0; 8 9 contract Controlled { 10 event NewController(address controller); 11 12 address payable public controller; 13 14 /// @notice Changes the controller of the contract 15 /// @param _newController The new controller of the contract 16 function changeController(address payable _newController) public; 17 } 18 19 /** 20 * @dev Interface of the ERC165 standard, as defined in the 21 * [EIP](https://eips.ethereum.org/EIPS/eip-165). 22 * 23 * Implementers can declare support of contract interfaces, which can then be 24 * queried by others (`ERC165Checker`). 25 * 26 * For an implementation, see `ERC165`. 27 */ 28 interface IERC165 { 29 /** 30 * @dev Returns true if this contract implements the interface defined by 31 * `interfaceId`. See the corresponding 32 * [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified) 33 * to learn more about how these ids are created. 34 * 35 * This function call must use less than 30 000 gas. 36 */ 37 function supportsInterface(bytes4 interfaceId) external view returns (bool); 38 } 39 40 /** 41 * @title ERC721 token receiver interface 42 * @dev Interface for any contract that wants to support safeTransfers 43 * from ERC721 asset contracts. 44 */ 45 contract IERC721Receiver { 46 /** 47 * @notice Handle the receipt of an NFT 48 * @dev The ERC721 smart contract calls this function on the recipient 49 * after a `safeTransfer`. This function MUST return the function selector, 50 * otherwise the caller will revert the transaction. The selector to be 51 * returned can be obtained as `this.onERC721Received.selector`. This 52 * function MAY throw to revert and reject the transfer. 53 * Note: the ERC721 contract address is always the message sender. 54 * @param operator The address which called `safeTransferFrom` function 55 * @param from The address which previously owned the token 56 * @param tokenId The NFT identifier which is being transferred 57 * @param data Additional data with no specified format 58 * @return bytes4 `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))` 59 */ 60 function onERC721Received( 61 address operator, 62 address from, 63 uint256 tokenId, 64 bytes memory data 65 ) public returns (bytes4); 66 } 67 68 /** 69 * @dev Implementation of the `IERC165` interface. 70 * 71 * Contracts may inherit from this and call `_registerInterface` to declare 72 * their support of an interface. 73 */ 74 contract ERC165 is IERC165 { 75 /** 76 * @dev See `IERC165.supportsInterface`. 77 * 78 * Time complexity O(1), guaranteed to always use less than 30 000 gas. 79 */ 80 function supportsInterface(bytes4 interfaceId) external view returns (bool); 81 } 82 83 84 /** 85 * @dev Required interface of an ERC721 compliant contract. 86 */ 87 contract IERC721 is IERC165 { 88 event Transfer( 89 address indexed from, 90 address indexed to, 91 uint256 indexed tokenId 92 ); 93 event Approval( 94 address indexed owner, 95 address indexed approved, 96 uint256 indexed tokenId 97 ); 98 event ApprovalForAll( 99 address indexed owner, 100 address indexed operator, 101 bool approved 102 ); 103 104 /** 105 * @dev Returns the number of NFTs in `owner`'s account. 106 */ 107 function balanceOf(address owner) public view returns (uint256 balance); 108 109 /** 110 * @dev Returns the owner of the NFT specified by `tokenId`. 111 */ 112 function ownerOf(uint256 tokenId) public view returns (address owner); 113 114 /** 115 * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to 116 * another (`to`). 117 * 118 * 119 * 120 * Requirements: 121 * - `from`, `to` cannot be zero. 122 * - `tokenId` must be owned by `from`. 123 * - If the caller is not `from`, it must be have been allowed to move this 124 * NFT by either `approve` or `setApproveForAll`. 125 */ 126 function safeTransferFrom( 127 address from, 128 address to, 129 uint256 tokenId 130 ) public; 131 132 /** 133 * @dev Transfers a specific NFT (`tokenId`) from one account (`from`) to 134 * another (`to`). 135 * 136 * Requirements: 137 * - If the caller is not `from`, it must be approved to move this NFT by 138 * either `approve` or `setApproveForAll`. 139 */ 140 function transferFrom( 141 address from, 142 address to, 143 uint256 tokenId 144 ) public; 145 146 function approve(address to, uint256 tokenId) public; 147 148 function getApproved(uint256 tokenId) 149 public 150 view 151 returns (address operator); 152 153 function setApprovalForAll(address operator, bool _approved) public; 154 155 function isApprovedForAll(address owner, address operator) 156 public 157 view 158 returns (bool); 159 160 function safeTransferFrom( 161 address from, 162 address to, 163 uint256 tokenId, 164 bytes memory data 165 ) public; 166 } 167 168 /** 169 * @title ERC-721 Non-Fungible Token Standard, optional enumeration extension 170 * @dev See https://eips.ethereum.org/EIPS/eip-721 171 */ 172 contract IERC721Enumerable is IERC721 { 173 function totalSupply() public view returns (uint256); 174 175 function tokenOfOwnerByIndex(address owner, uint256 index) 176 public 177 view 178 returns (uint256 tokenId); 179 180 function tokenByIndex(uint256 index) public view returns (uint256); 181 } 182 183 /** 184 * @title ERC-721 Non-Fungible Token Standard, optional metadata extension 185 * @dev See https://eips.ethereum.org/EIPS/eip-721 186 */ 187 contract IERC721Metadata is IERC721 { 188 function name() external view returns (string memory); 189 190 function symbol() external view returns (string memory); 191 192 function tokenURI(uint256 tokenId) external view returns (string memory); 193 } 194 195 contract TokenClaimer { 196 event ClaimedTokens( 197 address indexed _token, 198 address indexed _controller, 199 uint256 _amount 200 ); 201 202 function claimTokens(address _token) external; 203 } 204 205 /** 206 * @title ERC721 Non-Fungible Token Standard basic implementation 207 * @dev see https://eips.ethereum.org/EIPS/eip-721 208 */ 209 contract ERC721 is ERC165, IERC721 { 210 /** 211 * @dev Gets the balance of the specified address. 212 * @param owner address to query the balance of 213 * @return uint256 representing the amount owned by the passed address 214 */ 215 function balanceOf(address owner) public view returns (uint256); 216 217 /** 218 * @dev Gets the owner of the specified token ID. 219 * @param tokenId uint256 ID of the token to query the owner of 220 * @return address currently marked as the owner of the given token ID 221 */ 222 function ownerOf(uint256 tokenId) public view returns (address); 223 224 /** 225 * @dev Approves another address to transfer the given token ID 226 * The zero address indicates there is no approved address. 227 * There can only be one approved address per token at a given time. 228 * Can only be called by the token owner or an approved operator. 229 * @param to address to be approved for the given token ID 230 * @param tokenId uint256 ID of the token to be approved 231 */ 232 function approve(address to, uint256 tokenId) public; 233 234 /** 235 * @dev Gets the approved address for a token ID, or zero if no address set 236 * Reverts if the token ID does not exist. 237 * @param tokenId uint256 ID of the token to query the approval of 238 * @return address currently approved for the given token ID 239 */ 240 function getApproved(uint256 tokenId) public view returns (address); 241 242 /** 243 * @dev Sets or unsets the approval of a given operator 244 * An operator is allowed to transfer all tokens of the sender on their behalf. 245 * @param to operator address to set the approval 246 * @param approved representing the status of the approval to be set 247 */ 248 function setApprovalForAll(address to, bool approved) public; 249 250 /** 251 * @dev Tells whether an operator is approved by a given owner. 252 * @param owner owner address which you want to query the approval of 253 * @param operator operator address which you want to query the approval of 254 * @return bool whether the given operator is approved by the given owner 255 */ 256 function isApprovedForAll(address owner, address operator) 257 public 258 view 259 returns (bool); 260 261 /** 262 * @dev Transfers the ownership of a given token ID to another address. 263 * Usage of this method is discouraged, use `safeTransferFrom` whenever possible. 264 * Requires the msg.sender to be the owner, approved, or operator. 265 * @param from current owner of the token 266 * @param to address to receive the ownership of the given token ID 267 * @param tokenId uint256 ID of the token to be transferred 268 */ 269 function transferFrom( 270 address from, 271 address to, 272 uint256 tokenId 273 ) public; 274 275 /** 276 * @dev Safely transfers the ownership of a given token ID to another address 277 * If the target address is a contract, it must implement `onERC721Received`, 278 * which is called upon a safe transfer, and return the magic value 279 * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, 280 * the transfer is reverted. 281 * Requires the msg.sender to be the owner, approved, or operator 282 * @param from current owner of the token 283 * @param to address to receive the ownership of the given token ID 284 * @param tokenId uint256 ID of the token to be transferred 285 */ 286 function safeTransferFrom( 287 address from, 288 address to, 289 uint256 tokenId 290 ) public; 291 292 /** 293 * @dev Safely transfers the ownership of a given token ID to another address 294 * If the target address is a contract, it must implement `onERC721Received`, 295 * which is called upon a safe transfer, and return the magic value 296 * `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))`; otherwise, 297 * the transfer is reverted. 298 * Requires the msg.sender to be the owner, approved, or operator 299 * @param from current owner of the token 300 * @param to address to receive the ownership of the given token ID 301 * @param tokenId uint256 ID of the token to be transferred 302 * @param _data bytes data to send along with a safe transfer check 303 */ 304 function safeTransferFrom( 305 address from, 306 address to, 307 uint256 tokenId, 308 bytes memory _data 309 ) public; 310 } 311 312 /** 313 * @title ERC-721 Non-Fungible Token Standard, full implementation interface 314 * @dev See https://eips.ethereum.org/EIPS/eip-721 315 */ 316 contract IERC721Full is IERC721, IERC721Enumerable, IERC721Metadata { 317 // solhint-disable-previous-line no-empty-blocks 318 } 319 320 /** 321 * @title ERC-721 Non-Fungible Token with optional enumeration extension logic 322 * @dev See https://eips.ethereum.org/EIPS/eip-721 323 */ 324 contract ERC721Enumerable is ERC165, ERC721, IERC721Enumerable { 325 /** 326 * @dev Gets the token ID at a given index of the tokens list of the requested owner. 327 * @param owner address owning the tokens list to be accessed 328 * @param index uint256 representing the index to be accessed of the requested tokens list 329 * @return uint256 token ID at the given index of the tokens list owned by the requested address 330 */ 331 function tokenOfOwnerByIndex(address owner, uint256 index) 332 public 333 view 334 returns (uint256); 335 336 /** 337 * @dev Gets the total amount of tokens stored by the contract. 338 * @return uint256 representing the total amount of tokens 339 */ 340 function totalSupply() public view returns (uint256); 341 342 /** 343 * @dev Gets the token ID at a given index of all the tokens in this contract 344 * Reverts if the index is greater or equal to the total number of tokens. 345 * @param index uint256 representing the index to be accessed of the tokens list 346 * @return uint256 token ID at the given index of the tokens list 347 */ 348 function tokenByIndex(uint256 index) public view returns (uint256); 349 } 350 351 contract ERC721Metadata is ERC165, ERC721, IERC721Metadata { 352 /** 353 * @dev Gets the token name. 354 * @return string representing the token name 355 */ 356 function name() external view returns (string memory); 357 358 /** 359 * @dev Gets the token symbol. 360 * @return string representing the token symbol 361 */ 362 function symbol() external view returns (string memory); 363 364 /** 365 * @dev Returns an URI for a given token ID. 366 * Throws if the token ID does not exist. May return an empty string. 367 * @param tokenId uint256 ID of the token to query 368 */ 369 function tokenURI(uint256 tokenId) external view returns (string memory); 370 } 371 372 /** 373 * @title Full ERC721 Token 374 * This implementation includes all the required and some optional functionality of the ERC721 standard 375 * Moreover, it includes approve all functionality using operator terminology 376 * @dev see https://eips.ethereum.org/EIPS/eip-721 377 */ 378 contract ERC721Full is ERC721, ERC721Enumerable, ERC721Metadata { 379 380 } 381 382 /** 383 * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) 384 */ 385 contract StickerPack is Controlled, TokenClaimer, ERC721Full { 386 mapping(uint256 => uint256) public tokenPackId; //packId 387 uint256 public tokenCount; //tokens buys 388 389 /** 390 * @notice controller can generate tokens at will 391 * @param _owner account being included new token 392 * @param _packId pack being minted 393 * @return tokenId created 394 */ 395 function generateToken(address _owner, uint256 _packId) 396 external 397 returns (uint256 tokenId); 398 399 /** 400 * @notice This method can be used by the controller to extract mistakenly 401 * sent tokens to this contract. 402 * @param _token The address of the token contract that you want to recover 403 * set to 0 in case you want to extract ether. 404 */ 405 function claimTokens(address _token) external; 406 } 407 408 interface ApproveAndCallFallBack { 409 function receiveApproval( 410 address from, 411 uint256 _amount, 412 address _token, 413 bytes calldata _data 414 ) external; 415 } 416 417 /** 418 * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) 419 * StickerMarket allows any address register "StickerPack" which can be sold to any address in form of "StickerPack", an ERC721 token. 420 */ 421 contract StickerMarket is Controlled, TokenClaimer, ApproveAndCallFallBack { 422 event ClaimedTokens( 423 address indexed _token, 424 address indexed _controller, 425 uint256 _amount 426 ); 427 event MarketState(State state); 428 event RegisterFee(uint256 value); 429 event BurnRate(uint256 value); 430 431 enum State { 432 Invalid, 433 Open, 434 BuyOnly, 435 Controlled, 436 Closed 437 } 438 439 State public state = State.Open; 440 uint256 registerFee; 441 uint256 burnRate; 442 443 //include global var to set burn rate/percentage 444 address public snt; //payment token 445 StickerPack public stickerPack; 446 StickerType public stickerType; 447 448 /** 449 * @dev Mints NFT StickerPack in `msg.sender` account, and Transfers SNT using user allowance 450 * emit NonfungibleToken.Transfer(`address(0)`, `msg.sender`, `tokenId`) 451 * @notice buy a pack from market pack owner, including a StickerPack's token in msg.sender account with same metadata of `_packId` 452 * @param _packId id of market pack 453 * @param _destination owner of token being brought 454 * @param _price agreed price 455 * @return tokenId generated StickerPack token 456 */ 457 function buyToken( 458 uint256 _packId, 459 address _destination, 460 uint256 _price 461 ) external returns (uint256 tokenId); 462 463 /** 464 * @dev emits StickerMarket.Register(`packId`, `_urlHash`, `_price`, `_contenthash`) 465 * @notice Registers to sell a sticker pack 466 * @param _price cost in wei to users minting this pack 467 * @param _donate value between 0-10000 representing percentage of `_price` that is donated to StickerMarket at every buy 468 * @param _category listing category 469 * @param _owner address of the beneficiary of buys 470 * @param _contenthash EIP1577 pack contenthash for listings 471 * @param _fee Fee msg.sender agrees to pay for this registration 472 * @return packId Market position of Sticker Pack data. 473 */ 474 function registerPack( 475 uint256 _price, 476 uint256 _donate, 477 bytes4[] calldata _category, 478 address _owner, 479 bytes calldata _contenthash, 480 uint256 _fee 481 ) external returns (uint256 packId); 482 483 /** 484 * @notice MiniMeToken ApproveAndCallFallBack forwarder for registerPack and buyToken 485 * @param _from account calling "approve and buy" 486 * @param _value must be exactly whats being consumed 487 * @param _token must be exactly SNT contract 488 * @param _data abi encoded call 489 */ 490 function receiveApproval( 491 address _from, 492 uint256 _value, 493 address _token, 494 bytes calldata _data 495 ) external; 496 497 /** 498 * @notice changes market state, only controller can call. 499 * @param _state new state 500 */ 501 function setMarketState(State _state) external; 502 503 /** 504 * @notice changes register fee, only controller can call. 505 * @param _value total SNT cost of registration 506 */ 507 function setRegisterFee(uint256 _value) external; 508 509 /** 510 * @notice changes burn rate percentage, only controller can call. 511 * @param _value new value between 0 and 10000 512 */ 513 function setBurnRate(uint256 _value) external; 514 515 /** 516 * @notice controller can generate packs at will 517 * @param _price cost in wei to users minting with _urlHash metadata 518 * @param _donate optional amount of `_price` that is donated to StickerMarket at every buy 519 * @param _category listing category 520 * @param _owner address of the beneficiary of buys 521 * @param _contenthash EIP1577 pack contenthash for listings 522 * @return packId Market position of Sticker Pack data. 523 */ 524 function generatePack( 525 uint256 _price, 526 uint256 _donate, 527 bytes4[] calldata _category, 528 address _owner, 529 bytes calldata _contenthash 530 ) external returns (uint256 packId); 531 532 /** 533 * @notice removes all market data about a marketed pack, can only be called by market controller 534 * @param _packId pack being purged 535 * @param _limit limits categories being purged 536 */ 537 function purgePack(uint256 _packId, uint256 _limit) external; 538 539 /** 540 * @notice controller can generate tokens at will 541 * @param _owner account being included new token 542 * @param _packId pack being minted 543 * @return tokenId created 544 */ 545 function generateToken(address _owner, uint256 _packId) 546 external 547 returns (uint256 tokenId); 548 549 /** 550 * @notice Change controller of stickerType 551 * @param _newController new controller of stickerType. 552 */ 553 function migrate(address payable _newController) external; 554 555 /** 556 * @notice This method can be used by the controller to extract mistakenly 557 * sent tokens to this contract. 558 * @param _token The address of the token contract that you want to recover 559 * set to 0 in case you want to extract ether. 560 */ 561 function claimTokens(address _token) external; 562 563 /** 564 * @notice returns pack data of token 565 * @param _tokenId user token being queried 566 * @return categories, registration time and contenthash 567 */ 568 function getTokenData(uint256 _tokenId) 569 external 570 view 571 returns ( 572 bytes4[] memory category, 573 uint256 timestamp, 574 bytes memory contenthash 575 ); 576 577 // For ABI/web3.js purposes 578 // fired by StickerType 579 event Register( 580 uint256 indexed packId, 581 uint256 dataPrice, 582 bytes contenthash 583 ); 584 // fired by StickerPack and MiniMeToken 585 event Transfer( 586 address indexed from, 587 address indexed to, 588 uint256 indexed value 589 ); 590 } 591 592 /** 593 * @author Ricardo Guilherme Schmidt (Status Research & Development GmbH) 594 * StickerMarket allows any address register "StickerPack" which can be sold to any address in form of "StickerPack", an ERC721 token. 595 */ 596 contract StickerType is Controlled, TokenClaimer, ERC721Full { 597 event Register( 598 uint256 indexed packId, 599 uint256 dataPrice, 600 bytes contenthash, 601 bool mintable 602 ); 603 event PriceChanged(uint256 indexed packId, uint256 dataPrice); 604 event MintabilityChanged(uint256 indexed packId, bool mintable); 605 event ContenthashChanged(uint256 indexed packid, bytes contenthash); 606 event Categorized(bytes4 indexed category, uint256 indexed packId); 607 event Uncategorized(bytes4 indexed category, uint256 indexed packId); 608 event Unregister(uint256 indexed packId); 609 610 struct Pack { 611 bytes4[] category; 612 bool mintable; 613 uint256 timestamp; 614 uint256 price; //in "wei" 615 uint256 donate; //in "percent" 616 bytes contenthash; 617 } 618 619 mapping(uint256 => Pack) public packs; 620 uint256 public packCount; //pack registers 621 622 /** 623 * @notice controller can generate packs at will 624 * @param _price cost in wei to users minting with _urlHash metadata 625 * @param _donate optional amount of `_price` that is donated to StickerMarket at every buy 626 * @param _category listing category 627 * @param _owner address of the beneficiary of buys 628 * @param _contenthash EIP1577 pack contenthash for listings 629 * @return packId Market position of Sticker Pack data. 630 */ 631 function generatePack( 632 uint256 _price, 633 uint256 _donate, 634 bytes4[] calldata _category, 635 address _owner, 636 bytes calldata _contenthash 637 ) external returns (uint256 packId); 638 639 /** 640 * @notice removes all market data about a marketed pack, can only be called by market controller 641 * @param _packId position to be deleted 642 * @param _limit limit of categories to cleanup 643 */ 644 function purgePack(uint256 _packId, uint256 _limit) external; 645 646 /** 647 * @notice changes contenthash of `_packId`, can only be called by controller 648 * @param _packId which market position is being altered 649 * @param _contenthash new contenthash 650 */ 651 function setPackContenthash(uint256 _packId, bytes calldata _contenthash) 652 external; 653 654 /** 655 * @notice This method can be used by the controller to extract mistakenly 656 * sent tokens to this contract. 657 * @param _token The address of the token contract that you want to recover 658 * set to 0 in case you want to extract ether. 659 */ 660 function claimTokens(address _token) external; 661 662 /** 663 * @notice changes price of `_packId`, can only be called when market is open 664 * @param _packId pack id changing price settings 665 * @param _price cost in wei to users minting this pack 666 * @param _donate value between 0-10000 representing percentage of `_price` that is donated to StickerMarket at every buy 667 */ 668 function setPackPrice( 669 uint256 _packId, 670 uint256 _price, 671 uint256 _donate 672 ) external; 673 674 /** 675 * @notice add caregory in `_packId`, can only be called when market is open 676 * @param _packId pack adding category 677 * @param _category category to list 678 */ 679 function addPackCategory(uint256 _packId, bytes4 _category) external; 680 681 /** 682 * @notice remove caregory in `_packId`, can only be called when market is open 683 * @param _packId pack removing category 684 * @param _category category to unlist 685 */ 686 function removePackCategory(uint256 _packId, bytes4 _category) external; 687 688 /** 689 * @notice Changes if pack is enabled for sell 690 * @param _packId position edit 691 * @param _mintable true to enable sell 692 */ 693 function setPackState(uint256 _packId, bool _mintable) external; 694 695 /** 696 * @notice read available market ids in a category (might be slow) 697 * @param _category listing category 698 * @return array of market id registered 699 */ 700 function getAvailablePacks(bytes4 _category) 701 external 702 view 703 returns (uint256[] memory availableIds); 704 705 /** 706 * @notice count total packs in a category 707 * @param _category listing category 708 * @return total number of packs in category 709 */ 710 function getCategoryLength(bytes4 _category) 711 external 712 view 713 returns (uint256 size); 714 715 /** 716 * @notice read a packId in the category list at a specific index 717 * @param _category listing category 718 * @param _index index 719 * @return packId on index 720 */ 721 function getCategoryPack(bytes4 _category, uint256 _index) 722 external 723 view 724 returns (uint256 packId); 725 726 /** 727 * @notice returns all data from pack in market 728 * @param _packId pack id being queried 729 * @return categories, owner, mintable, price, donate and contenthash 730 */ 731 function getPackData(uint256 _packId) 732 external 733 view 734 returns ( 735 bytes4[] memory category, 736 address owner, 737 bool mintable, 738 uint256 timestamp, 739 uint256 price, 740 bytes memory contenthash 741 ); 742 743 /** 744 * @notice returns all data from pack in market 745 * @param _packId pack id being queried 746 * @return categories, owner, mintable, price, donate and contenthash 747 */ 748 function getPackSummary(uint256 _packId) 749 external 750 view 751 returns ( 752 bytes4[] memory category, 753 uint256 timestamp, 754 bytes memory contenthash 755 ); 756 757 /** 758 * @notice returns payment data for migrated contract 759 * @param _packId pack id being queried 760 * @return owner, mintable, price and donate 761 */ 762 function getPaymentData(uint256 _packId) 763 external 764 view 765 returns ( 766 address owner, 767 bool mintable, 768 uint256 price, 769 uint256 donate 770 ); 771 }