1
1
// SPDX-License-Identifier: MPL-2.0
2
2
pragma solidity = 0.8.9 ;
3
3
4
- import {Counters} from "@openzeppelin/contracts/utils/Counters.sol " ;
4
+ import {Strings} from "@openzeppelin/contracts/utils/Strings.sol " ;
5
+ import {Base64} from "@devprotocol/util-contracts/contracts/utils/Base64.sol " ;
5
6
import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol " ;
6
- import {EnumerableSet } from "@openzeppelin/ contracts/utils/structs/EnumerableSet .sol " ;
7
+ import {AddressLib } from "@devprotocol/util- contracts/contracts/ utils/AddressLib .sol " ;
7
8
import {ERC721EnumerableUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol " ;
8
9
9
10
import {ISBTToken} from "./interfaces/ISBTToken.sol " ;
11
+ import {DecimalString} from "./libs/DecimalString.sol " ;
10
12
11
13
contract SBTToken is ISBTToken , ERC721EnumerableUpgradeable {
14
+ using Base64 for bytes ;
15
+ using Strings for uint256 ;
16
+ using AddressLib for address ;
17
+ using DecimalString for uint256 ;
18
+
12
19
/// @dev EOA with minting rights.
13
- address private minter ;
20
+ address private _minter ;
14
21
/// @dev Account with proxy adming rights.
15
- address private proxyAdmin;
22
+ address private _proxyAdmin;
23
+
16
24
/// @dev Holds the URI information of a SBT token.
17
- mapping (uint256 => string ) private tokenUriImage;
25
+ mapping (uint256 => string ) private _tokenUriImage;
26
+ /// @dev Holds the generic metadata and attribute information of a SBT token.
27
+ mapping (uint256 => Metadata) private _tokenMetadata;
18
28
19
29
modifier onlyMinter () {
20
- require (minter == _msgSender (), "Illegal access " );
30
+ require (_minter == _msgSender (), "Illegal access " );
21
31
_;
22
32
}
23
33
24
- event SetProxyAdmin (address _proxyAdmin );
25
-
26
- function initialize (address _minter ) external initializer {
27
- __ERC721_init ("Dev Protocol SBT V1 " , "DEV-SBT-V1 " );
28
- minter = _minter;
29
- }
30
-
31
- function setProxyAdmin (address _proxyAdmin ) external {
32
- require (proxyAdmin == address (0 ), "Already set " );
33
- proxyAdmin = _proxyAdmin;
34
- emit SetProxyAdmin (_proxyAdmin);
35
- }
36
-
37
- function setTokenURIImage (
38
- uint256 _tokenId ,
39
- string memory _data
40
- ) external override onlyMinter {
41
- tokenUriImage[_tokenId] = _data;
42
- }
43
-
44
- function mint (
45
- address _owner
46
- ) external override onlyMinter returns (uint256 tokenId_ ) {
47
- uint256 currentId = this .currentIndex ();
48
- _mint (_owner, currentId);
49
- emit Minted (currentId, _owner);
50
- return currentId;
34
+ function _setTokenURI (
35
+ uint256 tokenId ,
36
+ Metadata memory tokenMetadata ,
37
+ string memory tokenUriImage
38
+ ) private {
39
+ _tokenMetadata[tokenId] = tokenMetadata;
40
+ _tokenUriImage[tokenId] = tokenUriImage;
41
+ emit SetSBTTokenURI (tokenId, abi.encode (tokenMetadata, tokenUriImage));
51
42
}
52
43
53
44
function _beforeTokenTransfer (
@@ -71,24 +62,56 @@ contract SBTToken is ISBTToken, ERC721EnumerableUpgradeable {
71
62
}
72
63
}
73
64
74
- function _tokenURI (uint256 _tokenId ) private view returns (string memory ) {
75
- return tokenUriImage[_tokenId];
65
+ function initialize (address minter ) external initializer {
66
+ __ERC721_init ("Dev Protocol SBT V1 " , "DEV-SBT-V1 " );
67
+ _minter = minter;
76
68
}
77
69
78
- function owner () external view returns (address ) {
79
- return ProxyAdmin (proxyAdmin).owner ();
70
+ function setProxyAdmin (address proxyAdmin ) external {
71
+ require (_proxyAdmin == address (0 ), "Already set " );
72
+ _proxyAdmin = proxyAdmin;
73
+ emit SetProxyAdmin (proxyAdmin);
74
+ }
75
+
76
+ function setTokenURI (
77
+ uint256 tokenId ,
78
+ Metadata memory tokenMetadata ,
79
+ string memory tokenUriImage
80
+ ) external override onlyMinter {
81
+ require (tokenId < currentIndex (), "Token not found " );
82
+ _setTokenURI (tokenId, tokenMetadata, tokenUriImage);
83
+ }
84
+
85
+ function mint (
86
+ address to ,
87
+ Metadata memory tokenMetadata ,
88
+ string memory tokenUriImage
89
+ ) external override onlyMinter returns (uint256 tokenId_ ) {
90
+ uint256 currentId = currentIndex ();
91
+ _mint (to, currentId);
92
+ emit Minted (currentId, to);
93
+ _setTokenURI (currentId, tokenMetadata, tokenUriImage);
94
+ return currentId;
95
+ }
96
+
97
+ function _tokenURI (uint256 tokenId ) private view returns (string memory ) {
98
+ return _tokenUriImage[tokenId];
80
99
}
81
100
82
101
function tokenURI (
83
- uint256 _tokenId
102
+ uint256 tokenId
84
103
) public view override returns (string memory ) {
85
- return _tokenURI (_tokenId );
104
+ return _tokenURI (tokenId );
86
105
}
87
106
88
- function currentIndex () external view override returns (uint256 ) {
107
+ function currentIndex () public view override returns (uint256 ) {
89
108
return super .totalSupply ();
90
109
}
91
110
111
+ function owner () external view returns (address ) {
112
+ return ProxyAdmin (_proxyAdmin).owner ();
113
+ }
114
+
92
115
function tokensOfOwner (
93
116
address _owner
94
117
) external view override returns (uint256 [] memory ) {
0 commit comments