@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.
- package/README.md +82 -0
- package/dist/add-pausable.d.ts +4 -0
- package/dist/add-pausable.d.ts.map +1 -0
- package/dist/add-pausable.js +30 -0
- package/dist/add-pausable.js.map +1 -0
- package/dist/api.d.ts +24 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +24 -0
- package/dist/api.js.map +1 -0
- package/dist/build-generic.d.ts +21 -0
- package/dist/build-generic.d.ts.map +1 -0
- package/dist/build-generic.js +24 -0
- package/dist/build-generic.js.map +1 -0
- package/dist/common-functions.d.ts +3 -0
- package/dist/common-functions.d.ts.map +1 -0
- package/dist/common-functions.js +13 -0
- package/dist/common-functions.js.map +1 -0
- package/dist/common-options.d.ts +11 -0
- package/dist/common-options.d.ts.map +1 -0
- package/dist/common-options.js +19 -0
- package/dist/common-options.js.map +1 -0
- package/dist/contract.d.ts +86 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +125 -0
- package/dist/contract.js.map +1 -0
- package/dist/contract.test.d.ts +2 -0
- package/dist/contract.test.d.ts.map +1 -0
- package/dist/contract.test.js +147 -0
- package/dist/contract.test.js.map +1 -0
- package/dist/erc1155.d.ts +14 -0
- package/dist/erc1155.d.ts.map +1 -0
- package/dist/erc1155.js +130 -0
- package/dist/erc1155.js.map +1 -0
- package/dist/erc1155.test.d.ts +2 -0
- package/dist/erc1155.test.d.ts.map +1 -0
- package/dist/erc1155.test.js +80 -0
- package/dist/erc1155.test.js.map +1 -0
- package/dist/erc20.d.ts +19 -0
- package/dist/erc20.d.ts.map +1 -0
- package/dist/erc20.js +202 -0
- package/dist/erc20.js.map +1 -0
- package/dist/erc20.test.d.ts +2 -0
- package/dist/erc20.test.d.ts.map +1 -0
- package/dist/erc20.test.js +126 -0
- package/dist/erc20.test.js.map +1 -0
- package/dist/erc721.d.ts +18 -0
- package/dist/erc721.d.ts.map +1 -0
- package/dist/erc721.js +200 -0
- package/dist/erc721.js.map +1 -0
- package/dist/erc721.test.d.ts +2 -0
- package/dist/erc721.test.d.ts.map +1 -0
- package/dist/erc721.test.js +106 -0
- package/dist/erc721.test.js.map +1 -0
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +11 -0
- package/dist/error.js.map +1 -0
- package/dist/general.d.ts +8 -0
- package/dist/general.d.ts.map +1 -0
- package/dist/general.js +22 -0
- package/dist/general.js.map +1 -0
- package/dist/general.test.d.ts +2 -0
- package/dist/general.test.d.ts.map +1 -0
- package/dist/general.test.js +42 -0
- package/dist/general.test.js.map +1 -0
- package/dist/generate/alternatives.d.ts +7 -0
- package/dist/generate/alternatives.d.ts.map +1 -0
- package/dist/generate/alternatives.js +29 -0
- package/dist/generate/alternatives.js.map +1 -0
- package/dist/generate/erc1155.d.ts +3 -0
- package/dist/generate/erc1155.d.ts.map +1 -0
- package/dist/generate/erc1155.js +24 -0
- package/dist/generate/erc1155.js.map +1 -0
- package/dist/generate/erc20.d.ts +3 -0
- package/dist/generate/erc20.d.ts.map +1 -0
- package/dist/generate/erc20.js +28 -0
- package/dist/generate/erc20.js.map +1 -0
- package/dist/generate/erc721.d.ts +3 -0
- package/dist/generate/erc721.d.ts.map +1 -0
- package/dist/generate/erc721.js +28 -0
- package/dist/generate/erc721.js.map +1 -0
- package/dist/generate/governor.d.ts +3 -0
- package/dist/generate/governor.d.ts.map +1 -0
- package/dist/generate/governor.js +32 -0
- package/dist/generate/governor.js.map +1 -0
- package/dist/generate/sources.d.ts +16 -0
- package/dist/generate/sources.d.ts.map +1 -0
- package/dist/generate/sources.js +79 -0
- package/dist/generate/sources.js.map +1 -0
- package/dist/governor.d.ts +26 -0
- package/dist/governor.d.ts.map +1 -0
- package/dist/governor.js +386 -0
- package/dist/governor.js.map +1 -0
- package/dist/governor.test.d.ts +2 -0
- package/dist/governor.test.d.ts.map +1 -0
- package/dist/governor.test.js +104 -0
- package/dist/governor.test.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/kind.d.ts +4 -0
- package/dist/kind.d.ts.map +1 -0
- package/dist/kind.js +28 -0
- package/dist/kind.js.map +1 -0
- package/dist/options.d.ts +11 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +40 -0
- package/dist/options.js.map +1 -0
- package/dist/print-versioned.d.ts +3 -0
- package/dist/print-versioned.d.ts.map +1 -0
- package/dist/print-versioned.js +12 -0
- package/dist/print-versioned.js.map +1 -0
- package/dist/print.d.ts +6 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +182 -0
- package/dist/print.js.map +1 -0
- package/dist/scripts/prepare.d.ts +2 -0
- package/dist/scripts/prepare.d.ts.map +1 -0
- package/dist/scripts/prepare.js +52 -0
- package/dist/scripts/prepare.js.map +1 -0
- package/dist/set-access-control.d.ts +5 -0
- package/dist/set-access-control.d.ts.map +1 -0
- package/dist/set-access-control.js +38 -0
- package/dist/set-access-control.js.map +1 -0
- package/dist/set-info.d.ts +13 -0
- package/dist/set-info.d.ts.map +1 -0
- package/dist/set-info.js +17 -0
- package/dist/set-info.js.map +1 -0
- package/dist/set-upgradeable.d.ts +6 -0
- package/dist/set-upgradeable.d.ts.map +1 -0
- package/dist/set-upgradeable.js +43 -0
- package/dist/set-upgradeable.js.map +1 -0
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/dist/test.js +23 -0
- package/dist/test.js.map +1 -0
- package/dist/utils/define-functions.d.ts +5 -0
- package/dist/utils/define-functions.d.ts.map +1 -0
- package/dist/utils/define-functions.js +11 -0
- package/dist/utils/define-functions.js.map +1 -0
- package/dist/utils/duration.d.ts +3 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +31 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/find-cover.d.ts +2 -0
- package/dist/utils/find-cover.d.ts.map +1 -0
- package/dist/utils/find-cover.js +23 -0
- package/dist/utils/find-cover.js.map +1 -0
- package/dist/utils/format-lines.d.ts +7 -0
- package/dist/utils/format-lines.d.ts.map +1 -0
- package/dist/utils/format-lines.js +30 -0
- package/dist/utils/format-lines.js.map +1 -0
- package/dist/utils/map-values.d.ts +2 -0
- package/dist/utils/map-values.d.ts.map +1 -0
- package/dist/utils/map-values.js +12 -0
- package/dist/utils/map-values.js.map +1 -0
- package/dist/utils/sorted-by.d.ts +2 -0
- package/dist/utils/sorted-by.d.ts.map +1 -0
- package/dist/utils/sorted-by.js +8 -0
- package/dist/utils/sorted-by.js.map +1 -0
- package/dist/utils/to-identifier.d.ts +2 -0
- package/dist/utils/to-identifier.d.ts.map +1 -0
- package/dist/utils/to-identifier.js +12 -0
- package/dist/utils/to-identifier.js.map +1 -0
- package/dist/utils/to-identifier.test.d.ts +2 -0
- package/dist/utils/to-identifier.test.d.ts.map +1 -0
- package/dist/utils/to-identifier.test.js +21 -0
- package/dist/utils/to-identifier.test.js.map +1 -0
- package/dist/utils/transitive-closure.d.ts +5 -0
- package/dist/utils/transitive-closure.d.ts.map +1 -0
- package/dist/utils/transitive-closure.js +27 -0
- package/dist/utils/transitive-closure.js.map +1 -0
- package/dist/zip.d.ts +4 -0
- package/dist/zip.d.ts.map +1 -0
- package/dist/zip.js +48 -0
- package/dist/zip.js.map +1 -0
- package/dist/zip.test.d.ts +2 -0
- package/dist/zip.test.d.ts.map +1 -0
- package/dist/zip.test.js +37 -0
- package/dist/zip.test.js.map +1 -0
- package/package.json +37 -0
- package/src/add-pausable.ts +32 -0
- package/src/api.ts +39 -0
- package/src/build-generic.ts +33 -0
- package/src/common-functions.ts +11 -0
- package/src/common-options.ts +24 -0
- package/src/contract.test.ts +164 -0
- package/src/contract.test.ts.md +272 -0
- package/src/contract.test.ts.snap +0 -0
- package/src/contract.ts +201 -0
- package/src/erc1155.test.ts +90 -0
- package/src/erc1155.test.ts.md +416 -0
- package/src/erc1155.test.ts.snap +0 -0
- package/src/erc1155.ts +160 -0
- package/src/erc20.test.ts +144 -0
- package/src/erc20.test.ts.md +571 -0
- package/src/erc20.test.ts.snap +0 -0
- package/src/erc20.ts +250 -0
- package/src/erc721.test.ts +122 -0
- package/src/erc721.test.ts.md +517 -0
- package/src/erc721.test.ts.snap +0 -0
- package/src/erc721.ts +250 -0
- package/src/error.ts +7 -0
- package/src/generate/alternatives.ts +38 -0
- package/src/generate/erc1155.ts +23 -0
- package/src/generate/erc20.ts +27 -0
- package/src/generate/erc721.ts +27 -0
- package/src/generate/governor.ts +30 -0
- package/src/generate/sources.ts +91 -0
- package/src/governor.test.ts +120 -0
- package/src/governor.test.ts.md +1419 -0
- package/src/governor.test.ts.snap +0 -0
- package/src/governor.ts +445 -0
- package/src/index.ts +23 -0
- package/src/kind.ts +30 -0
- package/src/options.ts +45 -0
- package/src/print-versioned.ts +12 -0
- package/src/print.ts +236 -0
- package/src/scripts/prepare.ts +60 -0
- package/src/set-access-control.ts +39 -0
- package/src/set-info.ts +24 -0
- package/src/set-upgradeable.ts +49 -0
- package/src/test.ts +21 -0
- package/src/utils/define-functions.ts +18 -0
- package/src/utils/duration.ts +34 -0
- package/src/utils/find-cover.ts +26 -0
- package/src/utils/format-lines.ts +31 -0
- package/src/utils/map-values.ts +10 -0
- package/src/utils/sorted-by.ts +3 -0
- package/src/utils/to-identifier.test.ts +20 -0
- package/src/utils/to-identifier.ts +7 -0
- package/src/utils/transitive-closure.ts +27 -0
- package/src/zip.test.ts +35 -0
- 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
|
+
});
|