@openzeppelin/wizard 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (235) hide show
  1. package/README.md +82 -0
  2. package/dist/add-pausable.d.ts +4 -0
  3. package/dist/add-pausable.d.ts.map +1 -0
  4. package/dist/add-pausable.js +30 -0
  5. package/dist/add-pausable.js.map +1 -0
  6. package/dist/api.d.ts +24 -0
  7. package/dist/api.d.ts.map +1 -0
  8. package/dist/api.js +24 -0
  9. package/dist/api.js.map +1 -0
  10. package/dist/build-generic.d.ts +21 -0
  11. package/dist/build-generic.d.ts.map +1 -0
  12. package/dist/build-generic.js +24 -0
  13. package/dist/build-generic.js.map +1 -0
  14. package/dist/common-functions.d.ts +3 -0
  15. package/dist/common-functions.d.ts.map +1 -0
  16. package/dist/common-functions.js +13 -0
  17. package/dist/common-functions.js.map +1 -0
  18. package/dist/common-options.d.ts +11 -0
  19. package/dist/common-options.d.ts.map +1 -0
  20. package/dist/common-options.js +19 -0
  21. package/dist/common-options.js.map +1 -0
  22. package/dist/contract.d.ts +86 -0
  23. package/dist/contract.d.ts.map +1 -0
  24. package/dist/contract.js +125 -0
  25. package/dist/contract.js.map +1 -0
  26. package/dist/contract.test.d.ts +2 -0
  27. package/dist/contract.test.d.ts.map +1 -0
  28. package/dist/contract.test.js +147 -0
  29. package/dist/contract.test.js.map +1 -0
  30. package/dist/erc1155.d.ts +14 -0
  31. package/dist/erc1155.d.ts.map +1 -0
  32. package/dist/erc1155.js +130 -0
  33. package/dist/erc1155.js.map +1 -0
  34. package/dist/erc1155.test.d.ts +2 -0
  35. package/dist/erc1155.test.d.ts.map +1 -0
  36. package/dist/erc1155.test.js +80 -0
  37. package/dist/erc1155.test.js.map +1 -0
  38. package/dist/erc20.d.ts +19 -0
  39. package/dist/erc20.d.ts.map +1 -0
  40. package/dist/erc20.js +202 -0
  41. package/dist/erc20.js.map +1 -0
  42. package/dist/erc20.test.d.ts +2 -0
  43. package/dist/erc20.test.d.ts.map +1 -0
  44. package/dist/erc20.test.js +126 -0
  45. package/dist/erc20.test.js.map +1 -0
  46. package/dist/erc721.d.ts +18 -0
  47. package/dist/erc721.d.ts.map +1 -0
  48. package/dist/erc721.js +200 -0
  49. package/dist/erc721.js.map +1 -0
  50. package/dist/erc721.test.d.ts +2 -0
  51. package/dist/erc721.test.d.ts.map +1 -0
  52. package/dist/erc721.test.js +106 -0
  53. package/dist/erc721.test.js.map +1 -0
  54. package/dist/error.d.ts +8 -0
  55. package/dist/error.d.ts.map +1 -0
  56. package/dist/error.js +11 -0
  57. package/dist/error.js.map +1 -0
  58. package/dist/general.d.ts +8 -0
  59. package/dist/general.d.ts.map +1 -0
  60. package/dist/general.js +22 -0
  61. package/dist/general.js.map +1 -0
  62. package/dist/general.test.d.ts +2 -0
  63. package/dist/general.test.d.ts.map +1 -0
  64. package/dist/general.test.js +42 -0
  65. package/dist/general.test.js.map +1 -0
  66. package/dist/generate/alternatives.d.ts +7 -0
  67. package/dist/generate/alternatives.d.ts.map +1 -0
  68. package/dist/generate/alternatives.js +29 -0
  69. package/dist/generate/alternatives.js.map +1 -0
  70. package/dist/generate/erc1155.d.ts +3 -0
  71. package/dist/generate/erc1155.d.ts.map +1 -0
  72. package/dist/generate/erc1155.js +24 -0
  73. package/dist/generate/erc1155.js.map +1 -0
  74. package/dist/generate/erc20.d.ts +3 -0
  75. package/dist/generate/erc20.d.ts.map +1 -0
  76. package/dist/generate/erc20.js +28 -0
  77. package/dist/generate/erc20.js.map +1 -0
  78. package/dist/generate/erc721.d.ts +3 -0
  79. package/dist/generate/erc721.d.ts.map +1 -0
  80. package/dist/generate/erc721.js +28 -0
  81. package/dist/generate/erc721.js.map +1 -0
  82. package/dist/generate/governor.d.ts +3 -0
  83. package/dist/generate/governor.d.ts.map +1 -0
  84. package/dist/generate/governor.js +32 -0
  85. package/dist/generate/governor.js.map +1 -0
  86. package/dist/generate/sources.d.ts +16 -0
  87. package/dist/generate/sources.d.ts.map +1 -0
  88. package/dist/generate/sources.js +79 -0
  89. package/dist/generate/sources.js.map +1 -0
  90. package/dist/governor.d.ts +26 -0
  91. package/dist/governor.d.ts.map +1 -0
  92. package/dist/governor.js +386 -0
  93. package/dist/governor.js.map +1 -0
  94. package/dist/governor.test.d.ts +2 -0
  95. package/dist/governor.test.d.ts.map +1 -0
  96. package/dist/governor.test.js +104 -0
  97. package/dist/governor.test.js.map +1 -0
  98. package/dist/index.d.ts +17 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +25 -0
  101. package/dist/index.js.map +1 -0
  102. package/dist/kind.d.ts +4 -0
  103. package/dist/kind.d.ts.map +1 -0
  104. package/dist/kind.js +28 -0
  105. package/dist/kind.js.map +1 -0
  106. package/dist/options.d.ts +11 -0
  107. package/dist/options.d.ts.map +1 -0
  108. package/dist/options.js +40 -0
  109. package/dist/options.js.map +1 -0
  110. package/dist/print-versioned.d.ts +3 -0
  111. package/dist/print-versioned.d.ts.map +1 -0
  112. package/dist/print-versioned.js +12 -0
  113. package/dist/print-versioned.js.map +1 -0
  114. package/dist/print.d.ts +6 -0
  115. package/dist/print.d.ts.map +1 -0
  116. package/dist/print.js +182 -0
  117. package/dist/print.js.map +1 -0
  118. package/dist/scripts/prepare.d.ts +2 -0
  119. package/dist/scripts/prepare.d.ts.map +1 -0
  120. package/dist/scripts/prepare.js +52 -0
  121. package/dist/scripts/prepare.js.map +1 -0
  122. package/dist/set-access-control.d.ts +5 -0
  123. package/dist/set-access-control.d.ts.map +1 -0
  124. package/dist/set-access-control.js +38 -0
  125. package/dist/set-access-control.js.map +1 -0
  126. package/dist/set-info.d.ts +13 -0
  127. package/dist/set-info.d.ts.map +1 -0
  128. package/dist/set-info.js +17 -0
  129. package/dist/set-info.js.map +1 -0
  130. package/dist/set-upgradeable.d.ts +6 -0
  131. package/dist/set-upgradeable.d.ts.map +1 -0
  132. package/dist/set-upgradeable.js +43 -0
  133. package/dist/set-upgradeable.js.map +1 -0
  134. package/dist/test.d.ts +2 -0
  135. package/dist/test.d.ts.map +1 -0
  136. package/dist/test.js +23 -0
  137. package/dist/test.js.map +1 -0
  138. package/dist/utils/define-functions.d.ts +5 -0
  139. package/dist/utils/define-functions.d.ts.map +1 -0
  140. package/dist/utils/define-functions.js +11 -0
  141. package/dist/utils/define-functions.js.map +1 -0
  142. package/dist/utils/duration.d.ts +3 -0
  143. package/dist/utils/duration.d.ts.map +1 -0
  144. package/dist/utils/duration.js +31 -0
  145. package/dist/utils/duration.js.map +1 -0
  146. package/dist/utils/find-cover.d.ts +2 -0
  147. package/dist/utils/find-cover.d.ts.map +1 -0
  148. package/dist/utils/find-cover.js +23 -0
  149. package/dist/utils/find-cover.js.map +1 -0
  150. package/dist/utils/format-lines.d.ts +7 -0
  151. package/dist/utils/format-lines.d.ts.map +1 -0
  152. package/dist/utils/format-lines.js +30 -0
  153. package/dist/utils/format-lines.js.map +1 -0
  154. package/dist/utils/map-values.d.ts +2 -0
  155. package/dist/utils/map-values.d.ts.map +1 -0
  156. package/dist/utils/map-values.js +12 -0
  157. package/dist/utils/map-values.js.map +1 -0
  158. package/dist/utils/sorted-by.d.ts +2 -0
  159. package/dist/utils/sorted-by.d.ts.map +1 -0
  160. package/dist/utils/sorted-by.js +8 -0
  161. package/dist/utils/sorted-by.js.map +1 -0
  162. package/dist/utils/to-identifier.d.ts +2 -0
  163. package/dist/utils/to-identifier.d.ts.map +1 -0
  164. package/dist/utils/to-identifier.js +12 -0
  165. package/dist/utils/to-identifier.js.map +1 -0
  166. package/dist/utils/to-identifier.test.d.ts +2 -0
  167. package/dist/utils/to-identifier.test.d.ts.map +1 -0
  168. package/dist/utils/to-identifier.test.js +21 -0
  169. package/dist/utils/to-identifier.test.js.map +1 -0
  170. package/dist/utils/transitive-closure.d.ts +5 -0
  171. package/dist/utils/transitive-closure.d.ts.map +1 -0
  172. package/dist/utils/transitive-closure.js +27 -0
  173. package/dist/utils/transitive-closure.js.map +1 -0
  174. package/dist/zip.d.ts +4 -0
  175. package/dist/zip.d.ts.map +1 -0
  176. package/dist/zip.js +48 -0
  177. package/dist/zip.js.map +1 -0
  178. package/dist/zip.test.d.ts +2 -0
  179. package/dist/zip.test.d.ts.map +1 -0
  180. package/dist/zip.test.js +37 -0
  181. package/dist/zip.test.js.map +1 -0
  182. package/package.json +37 -0
  183. package/src/add-pausable.ts +32 -0
  184. package/src/api.ts +39 -0
  185. package/src/build-generic.ts +33 -0
  186. package/src/common-functions.ts +11 -0
  187. package/src/common-options.ts +24 -0
  188. package/src/contract.test.ts +164 -0
  189. package/src/contract.test.ts.md +272 -0
  190. package/src/contract.test.ts.snap +0 -0
  191. package/src/contract.ts +201 -0
  192. package/src/erc1155.test.ts +90 -0
  193. package/src/erc1155.test.ts.md +416 -0
  194. package/src/erc1155.test.ts.snap +0 -0
  195. package/src/erc1155.ts +160 -0
  196. package/src/erc20.test.ts +144 -0
  197. package/src/erc20.test.ts.md +571 -0
  198. package/src/erc20.test.ts.snap +0 -0
  199. package/src/erc20.ts +250 -0
  200. package/src/erc721.test.ts +122 -0
  201. package/src/erc721.test.ts.md +517 -0
  202. package/src/erc721.test.ts.snap +0 -0
  203. package/src/erc721.ts +250 -0
  204. package/src/error.ts +7 -0
  205. package/src/generate/alternatives.ts +38 -0
  206. package/src/generate/erc1155.ts +23 -0
  207. package/src/generate/erc20.ts +27 -0
  208. package/src/generate/erc721.ts +27 -0
  209. package/src/generate/governor.ts +30 -0
  210. package/src/generate/sources.ts +91 -0
  211. package/src/governor.test.ts +120 -0
  212. package/src/governor.test.ts.md +1419 -0
  213. package/src/governor.test.ts.snap +0 -0
  214. package/src/governor.ts +445 -0
  215. package/src/index.ts +23 -0
  216. package/src/kind.ts +30 -0
  217. package/src/options.ts +45 -0
  218. package/src/print-versioned.ts +12 -0
  219. package/src/print.ts +236 -0
  220. package/src/scripts/prepare.ts +60 -0
  221. package/src/set-access-control.ts +39 -0
  222. package/src/set-info.ts +24 -0
  223. package/src/set-upgradeable.ts +49 -0
  224. package/src/test.ts +21 -0
  225. package/src/utils/define-functions.ts +18 -0
  226. package/src/utils/duration.ts +34 -0
  227. package/src/utils/find-cover.ts +26 -0
  228. package/src/utils/format-lines.ts +31 -0
  229. package/src/utils/map-values.ts +10 -0
  230. package/src/utils/sorted-by.ts +3 -0
  231. package/src/utils/to-identifier.test.ts +20 -0
  232. package/src/utils/to-identifier.ts +7 -0
  233. package/src/utils/transitive-closure.ts +27 -0
  234. package/src/zip.test.ts +35 -0
  235. package/src/zip.ts +53 -0
@@ -0,0 +1,90 @@
1
+ import test from 'ava';
2
+ import { erc1155 } from '.';
3
+
4
+ import { buildERC1155, ERC1155Options } from './erc1155';
5
+ import { printContract } from './print';
6
+
7
+ function testERC1155(title: string, opts: Partial<ERC1155Options>) {
8
+ test(title, t => {
9
+ const c = buildERC1155({
10
+ name: 'MyToken',
11
+ uri: 'https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/',
12
+ ...opts,
13
+ });
14
+ t.snapshot(printContract(c));
15
+ });
16
+ }
17
+
18
+ /**
19
+ * Tests external API for equivalence with internal API
20
+ */
21
+ function testAPIEquivalence(title: string, opts?: ERC1155Options) {
22
+ test(title, t => {
23
+ t.is(erc1155.print(opts), printContract(buildERC1155({
24
+ name: 'MyToken',
25
+ uri: '',
26
+ ...opts,
27
+ })));
28
+ });
29
+ }
30
+
31
+ testERC1155('basic', {});
32
+
33
+ testERC1155('basic + roles', {
34
+ access: 'roles',
35
+ });
36
+
37
+ testERC1155('burnable', {
38
+ burnable: true,
39
+ });
40
+
41
+ testERC1155('pausable', {
42
+ pausable: true,
43
+ });
44
+
45
+ testERC1155('mintable', {
46
+ mintable: true,
47
+ });
48
+
49
+ testERC1155('mintable + roles', {
50
+ mintable: true,
51
+ access: 'roles',
52
+ });
53
+
54
+ testERC1155('supply tracking', {
55
+ supply: true,
56
+ });
57
+
58
+ testERC1155('full upgradeable transparent', {
59
+ mintable: true,
60
+ access: 'roles',
61
+ burnable: true,
62
+ pausable: true,
63
+ upgradeable: 'transparent',
64
+ });
65
+
66
+ testERC1155('full upgradeable uups', {
67
+ mintable: true,
68
+ access: 'roles',
69
+ burnable: true,
70
+ pausable: true,
71
+ upgradeable: 'uups',
72
+ });
73
+
74
+ testAPIEquivalence('API default');
75
+
76
+ testAPIEquivalence('API basic', { name: 'CustomToken', uri: 'https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/' });
77
+
78
+ testAPIEquivalence('API full upgradeable', {
79
+ name: 'CustomToken',
80
+ uri: 'https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/',
81
+ mintable: true,
82
+ access: 'roles',
83
+ burnable: true,
84
+ pausable: true,
85
+ upgradeable: 'uups',
86
+ });
87
+
88
+ test('API assert defaults', async t => {
89
+ t.is(erc1155.print(erc1155.defaults), erc1155.print());
90
+ });
@@ -0,0 +1,416 @@
1
+ # Snapshot report for `src/erc1155.test.ts`
2
+
3
+ The actual snapshot is saved in `erc1155.test.ts.snap`.
4
+
5
+ Generated by [AVA](https://avajs.dev).
6
+
7
+ ## basic
8
+
9
+ > Snapshot 1
10
+
11
+ `// SPDX-License-Identifier: MIT␊
12
+ pragma solidity ^0.8.4;␊
13
+
14
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
15
+ import "@openzeppelin/contracts/access/Ownable.sol";␊
16
+
17
+ contract MyToken is ERC1155, Ownable {␊
18
+ constructor()␊
19
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
20
+ {}␊
21
+
22
+ function setURI(string memory newuri) public onlyOwner {␊
23
+ _setURI(newuri);␊
24
+ }␊
25
+ }␊
26
+ `
27
+
28
+ ## basic + roles
29
+
30
+ > Snapshot 1
31
+
32
+ `// SPDX-License-Identifier: MIT␊
33
+ pragma solidity ^0.8.4;␊
34
+
35
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
36
+ import "@openzeppelin/contracts/access/AccessControl.sol";␊
37
+
38
+ contract MyToken is ERC1155, AccessControl {␊
39
+ bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
40
+
41
+ constructor()␊
42
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
43
+ {␊
44
+ _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);␊
45
+ _grantRole(URI_SETTER_ROLE, msg.sender);␊
46
+ }␊
47
+
48
+ function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {␊
49
+ _setURI(newuri);␊
50
+ }␊
51
+
52
+ // The following functions are overrides required by Solidity.␊
53
+
54
+ function supportsInterface(bytes4 interfaceId)␊
55
+ public␊
56
+ view␊
57
+ override(ERC1155, AccessControl)␊
58
+ returns (bool)␊
59
+ {␊
60
+ return super.supportsInterface(interfaceId);␊
61
+ }␊
62
+ }␊
63
+ `
64
+
65
+ ## burnable
66
+
67
+ > Snapshot 1
68
+
69
+ `// SPDX-License-Identifier: MIT␊
70
+ pragma solidity ^0.8.4;␊
71
+
72
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
73
+ import "@openzeppelin/contracts/access/Ownable.sol";␊
74
+ import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol";␊
75
+
76
+ contract MyToken is ERC1155, Ownable, ERC1155Burnable {␊
77
+ constructor()␊
78
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
79
+ {}␊
80
+
81
+ function setURI(string memory newuri) public onlyOwner {␊
82
+ _setURI(newuri);␊
83
+ }␊
84
+ }␊
85
+ `
86
+
87
+ ## pausable
88
+
89
+ > Snapshot 1
90
+
91
+ `// SPDX-License-Identifier: MIT␊
92
+ pragma solidity ^0.8.4;␊
93
+
94
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
95
+ import "@openzeppelin/contracts/access/Ownable.sol";␊
96
+ import "@openzeppelin/contracts/security/Pausable.sol";␊
97
+
98
+ contract MyToken is ERC1155, Ownable, Pausable {␊
99
+ constructor()␊
100
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
101
+ {}␊
102
+
103
+ function setURI(string memory newuri) public onlyOwner {␊
104
+ _setURI(newuri);␊
105
+ }␊
106
+
107
+ function pause() public onlyOwner {␊
108
+ _pause();␊
109
+ }␊
110
+
111
+ function unpause() public onlyOwner {␊
112
+ _unpause();␊
113
+ }␊
114
+
115
+ function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
116
+ internal␊
117
+ whenNotPaused␊
118
+ override␊
119
+ {␊
120
+ super._beforeTokenTransfer(operator, from, to, ids, amounts, data);␊
121
+ }␊
122
+ }␊
123
+ `
124
+
125
+ ## mintable
126
+
127
+ > Snapshot 1
128
+
129
+ `// SPDX-License-Identifier: MIT␊
130
+ pragma solidity ^0.8.4;␊
131
+
132
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
133
+ import "@openzeppelin/contracts/access/Ownable.sol";␊
134
+
135
+ contract MyToken is ERC1155, Ownable {␊
136
+ constructor()␊
137
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
138
+ {}␊
139
+
140
+ function setURI(string memory newuri) public onlyOwner {␊
141
+ _setURI(newuri);␊
142
+ }␊
143
+
144
+ function mint(address account, uint256 id, uint256 amount, bytes memory data)␊
145
+ public␊
146
+ onlyOwner␊
147
+ {␊
148
+ _mint(account, id, amount, data);␊
149
+ }␊
150
+
151
+ function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
152
+ public␊
153
+ onlyOwner␊
154
+ {␊
155
+ _mintBatch(to, ids, amounts, data);␊
156
+ }␊
157
+ }␊
158
+ `
159
+
160
+ ## mintable + roles
161
+
162
+ > Snapshot 1
163
+
164
+ `// SPDX-License-Identifier: MIT␊
165
+ pragma solidity ^0.8.4;␊
166
+
167
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
168
+ import "@openzeppelin/contracts/access/AccessControl.sol";␊
169
+
170
+ contract MyToken is ERC1155, AccessControl {␊
171
+ bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
172
+ bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");␊
173
+
174
+ constructor()␊
175
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
176
+ {␊
177
+ _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);␊
178
+ _grantRole(URI_SETTER_ROLE, msg.sender);␊
179
+ _grantRole(MINTER_ROLE, msg.sender);␊
180
+ }␊
181
+
182
+ function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {␊
183
+ _setURI(newuri);␊
184
+ }␊
185
+
186
+ function mint(address account, uint256 id, uint256 amount, bytes memory data)␊
187
+ public␊
188
+ onlyRole(MINTER_ROLE)␊
189
+ {␊
190
+ _mint(account, id, amount, data);␊
191
+ }␊
192
+
193
+ function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
194
+ public␊
195
+ onlyRole(MINTER_ROLE)␊
196
+ {␊
197
+ _mintBatch(to, ids, amounts, data);␊
198
+ }␊
199
+
200
+ // The following functions are overrides required by Solidity.␊
201
+
202
+ function supportsInterface(bytes4 interfaceId)␊
203
+ public␊
204
+ view␊
205
+ override(ERC1155, AccessControl)␊
206
+ returns (bool)␊
207
+ {␊
208
+ return super.supportsInterface(interfaceId);␊
209
+ }␊
210
+ }␊
211
+ `
212
+
213
+ ## supply tracking
214
+
215
+ > Snapshot 1
216
+
217
+ `// SPDX-License-Identifier: MIT␊
218
+ pragma solidity ^0.8.4;␊
219
+
220
+ import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";␊
221
+ import "@openzeppelin/contracts/access/Ownable.sol";␊
222
+ import "@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol";␊
223
+
224
+ contract MyToken is ERC1155, Ownable, ERC1155Supply {␊
225
+ constructor()␊
226
+ ERC1155("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/")␊
227
+ {}␊
228
+
229
+ function setURI(string memory newuri) public onlyOwner {␊
230
+ _setURI(newuri);␊
231
+ }␊
232
+
233
+ // The following functions are overrides required by Solidity.␊
234
+
235
+ function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
236
+ internal␊
237
+ override(ERC1155, ERC1155Supply)␊
238
+ {␊
239
+ super._beforeTokenTransfer(operator, from, to, ids, amounts, data);␊
240
+ }␊
241
+ }␊
242
+ `
243
+
244
+ ## full upgradeable transparent
245
+
246
+ > Snapshot 1
247
+
248
+ `// SPDX-License-Identifier: MIT␊
249
+ pragma solidity ^0.8.4;␊
250
+
251
+ import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
252
+ import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
253
+ import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";␊
254
+ import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
255
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
256
+
257
+ contract MyToken is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable {␊
258
+ bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
259
+ bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");␊
260
+ bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");␊
261
+
262
+ /// @custom:oz-upgrades-unsafe-allow constructor␊
263
+ constructor() {␊
264
+ _disableInitializers();␊
265
+ }␊
266
+
267
+ function initialize() initializer public {␊
268
+ __ERC1155_init("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊
269
+ __AccessControl_init();␊
270
+ __Pausable_init();␊
271
+ __ERC1155Burnable_init();␊
272
+
273
+ _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);␊
274
+ _grantRole(URI_SETTER_ROLE, msg.sender);␊
275
+ _grantRole(PAUSER_ROLE, msg.sender);␊
276
+ _grantRole(MINTER_ROLE, msg.sender);␊
277
+ }␊
278
+
279
+ function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {␊
280
+ _setURI(newuri);␊
281
+ }␊
282
+
283
+ function pause() public onlyRole(PAUSER_ROLE) {␊
284
+ _pause();␊
285
+ }␊
286
+
287
+ function unpause() public onlyRole(PAUSER_ROLE) {␊
288
+ _unpause();␊
289
+ }␊
290
+
291
+ function mint(address account, uint256 id, uint256 amount, bytes memory data)␊
292
+ public␊
293
+ onlyRole(MINTER_ROLE)␊
294
+ {␊
295
+ _mint(account, id, amount, data);␊
296
+ }␊
297
+
298
+ function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
299
+ public␊
300
+ onlyRole(MINTER_ROLE)␊
301
+ {␊
302
+ _mintBatch(to, ids, amounts, data);␊
303
+ }␊
304
+
305
+ function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
306
+ internal␊
307
+ whenNotPaused␊
308
+ override␊
309
+ {␊
310
+ super._beforeTokenTransfer(operator, from, to, ids, amounts, data);␊
311
+ }␊
312
+
313
+ // The following functions are overrides required by Solidity.␊
314
+
315
+ function supportsInterface(bytes4 interfaceId)␊
316
+ public␊
317
+ view␊
318
+ override(ERC1155Upgradeable, AccessControlUpgradeable)␊
319
+ returns (bool)␊
320
+ {␊
321
+ return super.supportsInterface(interfaceId);␊
322
+ }␊
323
+ }␊
324
+ `
325
+
326
+ ## full upgradeable uups
327
+
328
+ > Snapshot 1
329
+
330
+ `// SPDX-License-Identifier: MIT␊
331
+ pragma solidity ^0.8.4;␊
332
+
333
+ import "@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol";␊
334
+ import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";␊
335
+ import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";␊
336
+ import "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155BurnableUpgradeable.sol";␊
337
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";␊
338
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";␊
339
+
340
+ contract MyToken is Initializable, ERC1155Upgradeable, AccessControlUpgradeable, PausableUpgradeable, ERC1155BurnableUpgradeable, UUPSUpgradeable {␊
341
+ bytes32 public constant URI_SETTER_ROLE = keccak256("URI_SETTER_ROLE");␊
342
+ bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");␊
343
+ bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");␊
344
+ bytes32 public constant UPGRADER_ROLE = keccak256("UPGRADER_ROLE");␊
345
+
346
+ /// @custom:oz-upgrades-unsafe-allow constructor␊
347
+ constructor() {␊
348
+ _disableInitializers();␊
349
+ }␊
350
+
351
+ function initialize() initializer public {␊
352
+ __ERC1155_init("https://gateway.pinata.cloud/ipfs/QmcP9hxrnC1T5ATPmq2saFeAM1ypFX9BnAswCdHB9JCjLA/");␊
353
+ __AccessControl_init();␊
354
+ __Pausable_init();␊
355
+ __ERC1155Burnable_init();␊
356
+ __UUPSUpgradeable_init();␊
357
+
358
+ _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);␊
359
+ _grantRole(URI_SETTER_ROLE, msg.sender);␊
360
+ _grantRole(PAUSER_ROLE, msg.sender);␊
361
+ _grantRole(MINTER_ROLE, msg.sender);␊
362
+ _grantRole(UPGRADER_ROLE, msg.sender);␊
363
+ }␊
364
+
365
+ function setURI(string memory newuri) public onlyRole(URI_SETTER_ROLE) {␊
366
+ _setURI(newuri);␊
367
+ }␊
368
+
369
+ function pause() public onlyRole(PAUSER_ROLE) {␊
370
+ _pause();␊
371
+ }␊
372
+
373
+ function unpause() public onlyRole(PAUSER_ROLE) {␊
374
+ _unpause();␊
375
+ }␊
376
+
377
+ function mint(address account, uint256 id, uint256 amount, bytes memory data)␊
378
+ public␊
379
+ onlyRole(MINTER_ROLE)␊
380
+ {␊
381
+ _mint(account, id, amount, data);␊
382
+ }␊
383
+
384
+ function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
385
+ public␊
386
+ onlyRole(MINTER_ROLE)␊
387
+ {␊
388
+ _mintBatch(to, ids, amounts, data);␊
389
+ }␊
390
+
391
+ function _beforeTokenTransfer(address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)␊
392
+ internal␊
393
+ whenNotPaused␊
394
+ override␊
395
+ {␊
396
+ super._beforeTokenTransfer(operator, from, to, ids, amounts, data);␊
397
+ }␊
398
+
399
+ function _authorizeUpgrade(address newImplementation)␊
400
+ internal␊
401
+ onlyRole(UPGRADER_ROLE)␊
402
+ override␊
403
+ {}␊
404
+
405
+ // The following functions are overrides required by Solidity.␊
406
+
407
+ function supportsInterface(bytes4 interfaceId)␊
408
+ public␊
409
+ view␊
410
+ override(ERC1155Upgradeable, AccessControlUpgradeable)␊
411
+ returns (bool)␊
412
+ {␊
413
+ return super.supportsInterface(interfaceId);␊
414
+ }␊
415
+ }␊
416
+ `
Binary file
package/src/erc1155.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { Contract, ContractBuilder } from './contract';
2
+ import { Access, setAccessControl } from './set-access-control';
3
+ import { addPausable } from './add-pausable';
4
+ import { supportsInterface } from './common-functions';
5
+ import { defineFunctions } from './utils/define-functions';
6
+ import { CommonOptions, withCommonDefaults, defaults as commonDefaults } from './common-options';
7
+ import { setUpgradeable } from './set-upgradeable';
8
+ import { setInfo } from './set-info';
9
+ import { printContract } from './print';
10
+
11
+ export interface ERC1155Options extends CommonOptions {
12
+ name: string;
13
+ uri: string;
14
+ burnable?: boolean;
15
+ pausable?: boolean;
16
+ mintable?: boolean;
17
+ supply?: boolean;
18
+ }
19
+
20
+ export const defaults: Required<ERC1155Options> = {
21
+ name: 'MyToken',
22
+ uri: '',
23
+ burnable: false,
24
+ pausable: false,
25
+ mintable: false,
26
+ supply: false,
27
+ access: commonDefaults.access,
28
+ upgradeable: commonDefaults.upgradeable,
29
+ info: commonDefaults.info
30
+ } as const;
31
+
32
+ function withDefaults(opts: ERC1155Options): Required<ERC1155Options> {
33
+ return {
34
+ ...opts,
35
+ ...withCommonDefaults(opts),
36
+ burnable: opts.burnable ?? defaults.burnable,
37
+ pausable: opts.pausable ?? defaults.pausable,
38
+ mintable: opts.mintable ?? defaults.mintable,
39
+ supply: opts.supply ?? defaults.supply,
40
+ };
41
+ }
42
+
43
+ export function printERC1155(opts: ERC1155Options = defaults): string {
44
+ return printContract(buildERC1155(opts));
45
+ }
46
+
47
+ export function buildERC1155(opts: ERC1155Options): Contract {
48
+ const allOpts = withDefaults(opts);
49
+
50
+ const c = new ContractBuilder(allOpts.name);
51
+
52
+ const { access, upgradeable, info } = allOpts;
53
+
54
+ addBase(c, allOpts.uri);
55
+ addSetUri(c, access);
56
+
57
+ if (allOpts.pausable) {
58
+ addPausable(c, access, [functions._beforeTokenTransfer]);
59
+ }
60
+
61
+ if (allOpts.burnable) {
62
+ addBurnable(c);
63
+ }
64
+
65
+ if (allOpts.mintable) {
66
+ addMintable(c, access);
67
+ }
68
+
69
+ if (allOpts.supply) {
70
+ addSupply(c);
71
+ }
72
+
73
+ setUpgradeable(c, upgradeable, access);
74
+
75
+ setInfo(c, info);
76
+
77
+ return c;
78
+ }
79
+
80
+ function addBase(c: ContractBuilder, uri: string) {
81
+ c.addParent(
82
+ {
83
+ name: 'ERC1155',
84
+ path: '@openzeppelin/contracts/token/ERC1155/ERC1155.sol',
85
+ },
86
+ [uri],
87
+ );
88
+
89
+ c.addOverride('ERC1155', functions._beforeTokenTransfer);
90
+ c.addOverride('ERC1155', supportsInterface);
91
+ }
92
+
93
+ function addBurnable(c: ContractBuilder) {
94
+ c.addParent({
95
+ name: 'ERC1155Burnable',
96
+ path: '@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol',
97
+ });
98
+ }
99
+
100
+ function addMintable(c: ContractBuilder, access: Access) {
101
+ setAccessControl(c, functions.mint, access, 'MINTER');
102
+ setAccessControl(c, functions.mintBatch, access, 'MINTER');
103
+ c.addFunctionCode('_mint(account, id, amount, data);', functions.mint);
104
+ c.addFunctionCode('_mintBatch(to, ids, amounts, data);', functions.mintBatch);
105
+ }
106
+
107
+ function addSetUri(c: ContractBuilder, access: Access) {
108
+ setAccessControl(c, functions.setURI, access, 'URI_SETTER');
109
+ c.addFunctionCode('_setURI(newuri);', functions.setURI);
110
+ }
111
+
112
+ function addSupply(c: ContractBuilder) {
113
+ c.addParent({
114
+ name: 'ERC1155Supply',
115
+ path: '@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol',
116
+ });
117
+ c.addOverride('ERC1155Supply', functions._beforeTokenTransfer);
118
+ }
119
+
120
+ const functions = defineFunctions({
121
+ _beforeTokenTransfer: {
122
+ kind: 'internal' as const,
123
+ args: [
124
+ { name: 'operator', type: 'address' },
125
+ { name: 'from', type: 'address' },
126
+ { name: 'to', type: 'address' },
127
+ { name: 'ids', type: 'uint256[] memory' },
128
+ { name: 'amounts', type: 'uint256[] memory' },
129
+ { name: 'data', type: 'bytes memory' },
130
+ ],
131
+ },
132
+
133
+ setURI: {
134
+ kind: 'public' as const,
135
+ args: [
136
+ { name: 'newuri', type: 'string memory' },
137
+ ],
138
+ },
139
+
140
+ mint: {
141
+ kind: 'public' as const,
142
+ args: [
143
+ { name: 'account', type: 'address' },
144
+ { name: 'id', type: 'uint256' },
145
+ { name: 'amount', type: 'uint256' },
146
+ { name: 'data', type: 'bytes memory' },
147
+ ],
148
+ },
149
+
150
+ mintBatch: {
151
+ kind: 'public' as const,
152
+ args: [
153
+ { name: 'to', type: 'address' },
154
+ { name: 'ids', type: 'uint256[] memory' },
155
+ { name: 'amounts', type: 'uint256[] memory' },
156
+ { name: 'data', type: 'bytes memory' },
157
+ ],
158
+ },
159
+
160
+ });