@theqrl/qrl-contracts 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.
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (interfaces/ISQRCTN1.hyp)
3
+
4
+ pragma hyperion >=0.0;
5
+
6
+ import {ISQRCTN1} from "../token/SQRCTN1/ISQRCTN1.hyp";
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (interfaces/IZRC165.hyp)
3
+
4
+ pragma hyperion >=0.0;
5
+
6
+ import {IZRC165} from "../utils/introspection/IZRC165.hyp";
@@ -0,0 +1,20 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (interfaces/IZRC4906.hyp)
3
+
4
+ pragma hyperion >=0.0;
5
+
6
+ import {IZRC165} from "./IZRC165.hyp";
7
+ import {ISQRCTN1} from "./ISQRCTN1.hyp";
8
+
9
+ /// @title SQRC-TN1 Metadata Update Extension
10
+ interface IZRC4906 is IZRC165, ISQRCTN1 {
11
+ /// @dev This event emits when the metadata of a token is changed.
12
+ /// So that the third-party platforms such as NFT market could
13
+ /// timely update the images and related attributes of the NFT.
14
+ event MetadataUpdate(uint256 _tokenId);
15
+
16
+ /// @dev This event emits when the metadata of a range of tokens is changed.
17
+ /// So that the third-party platforms such as NFT market could
18
+ /// timely update the images and related attributes of the NFTs.
19
+ event BatchMetadataUpdate(uint256 _fromTokenId, uint256 _toTokenId);
20
+ }
@@ -0,0 +1,161 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (interfaces/draft-IZRC6093.hyp)
3
+ pragma hyperion >=0.0;
4
+
5
+ /**
6
+ * @dev Standard SQRC-TF1 Errors
7
+ * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ZRC-6093] custom errors for SQRC-TF1 tokens.
8
+ */
9
+ interface ISQRCTF1Errors {
10
+ /**
11
+ * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
12
+ * @param sender Address whose tokens are being transferred.
13
+ * @param balance Current balance for the interacting account.
14
+ * @param needed Minimum amount required to perform a transfer.
15
+ */
16
+ error SQRCTF1InsufficientBalance(address sender, uint256 balance, uint256 needed);
17
+
18
+ /**
19
+ * @dev Indicates a failure with the token `sender`. Used in transfers.
20
+ * @param sender Address whose tokens are being transferred.
21
+ */
22
+ error SQRCTF1InvalidSender(address sender);
23
+
24
+ /**
25
+ * @dev Indicates a failure with the token `receiver`. Used in transfers.
26
+ * @param receiver Address to which tokens are being transferred.
27
+ */
28
+ error SQRCTF1InvalidReceiver(address receiver);
29
+
30
+ /**
31
+ * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
32
+ * @param spender Address that may be allowed to operate on tokens without being their owner.
33
+ * @param allowance Amount of tokens a `spender` is allowed to operate with.
34
+ * @param needed Minimum amount required to perform a transfer.
35
+ */
36
+ error SQRCTF1InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
37
+
38
+ /**
39
+ * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
40
+ * @param approver Address initiating an approval operation.
41
+ */
42
+ error SQRCTF1InvalidApprover(address approver);
43
+
44
+ /**
45
+ * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
46
+ * @param spender Address that may be allowed to operate on tokens without being their owner.
47
+ */
48
+ error SQRCTF1InvalidSpender(address spender);
49
+ }
50
+
51
+ /**
52
+ * @dev Standard SQRC-TN1 Errors
53
+ * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ZRC-6093] custom errors for SQRC-TN1 tokens.
54
+ */
55
+ interface ISQRCTN1Errors {
56
+ /**
57
+ * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in SQRC-TF1.
58
+ * Used in balance queries.
59
+ * @param owner Address of the current owner of a token.
60
+ */
61
+ error SQRCTN1InvalidOwner(address owner);
62
+
63
+ /**
64
+ * @dev Indicates a `tokenId` whose `owner` is the zero address.
65
+ * @param tokenId Identifier number of a token.
66
+ */
67
+ error SQRCTN1NonexistentToken(uint256 tokenId);
68
+
69
+ /**
70
+ * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
71
+ * @param sender Address whose tokens are being transferred.
72
+ * @param tokenId Identifier number of a token.
73
+ * @param owner Address of the current owner of a token.
74
+ */
75
+ error SQRCTN1IncorrectOwner(address sender, uint256 tokenId, address owner);
76
+
77
+ /**
78
+ * @dev Indicates a failure with the token `sender`. Used in transfers.
79
+ * @param sender Address whose tokens are being transferred.
80
+ */
81
+ error SQRCTN1InvalidSender(address sender);
82
+
83
+ /**
84
+ * @dev Indicates a failure with the token `receiver`. Used in transfers.
85
+ * @param receiver Address to which tokens are being transferred.
86
+ */
87
+ error SQRCTN1InvalidReceiver(address receiver);
88
+
89
+ /**
90
+ * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
91
+ * @param operator Address that may be allowed to operate on tokens without being their owner.
92
+ * @param tokenId Identifier number of a token.
93
+ */
94
+ error SQRCTN1InsufficientApproval(address operator, uint256 tokenId);
95
+
96
+ /**
97
+ * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
98
+ * @param approver Address initiating an approval operation.
99
+ */
100
+ error SQRCTN1InvalidApprover(address approver);
101
+
102
+ /**
103
+ * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
104
+ * @param operator Address that may be allowed to operate on tokens without being their owner.
105
+ */
106
+ error SQRCTN1InvalidOperator(address operator);
107
+ }
108
+
109
+ /**
110
+ * @dev Standard SQRC-TB1 Errors
111
+ * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ZRC-6093] custom errors for SQRC-TB1 tokens.
112
+ */
113
+ interface ISQRCTB1Errors {
114
+ /**
115
+ * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
116
+ * @param sender Address whose tokens are being transferred.
117
+ * @param balance Current balance for the interacting account.
118
+ * @param needed Minimum amount required to perform a transfer.
119
+ * @param tokenId Identifier number of a token.
120
+ */
121
+ error SQRCTB1InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
122
+
123
+ /**
124
+ * @dev Indicates a failure with the token `sender`. Used in transfers.
125
+ * @param sender Address whose tokens are being transferred.
126
+ */
127
+ error SQRCTB1InvalidSender(address sender);
128
+
129
+ /**
130
+ * @dev Indicates a failure with the token `receiver`. Used in transfers.
131
+ * @param receiver Address to which tokens are being transferred.
132
+ */
133
+ error SQRCTB1InvalidReceiver(address receiver);
134
+
135
+ /**
136
+ * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
137
+ * @param operator Address that may be allowed to operate on tokens without being their owner.
138
+ * @param owner Address of the current owner of a token.
139
+ */
140
+ error SQRCTB1MissingApprovalForAll(address operator, address owner);
141
+
142
+ /**
143
+ * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
144
+ * @param approver Address initiating an approval operation.
145
+ */
146
+ error SQRCTB1InvalidApprover(address approver);
147
+
148
+ /**
149
+ * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
150
+ * @param operator Address that may be allowed to operate on tokens without being their owner.
151
+ */
152
+ error SQRCTB1InvalidOperator(address operator);
153
+
154
+ /**
155
+ * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
156
+ * Used in batch transfers.
157
+ * @param idsLength Length of the array of token identifiers
158
+ * @param valuesLength Length of the array of token amounts
159
+ */
160
+ error SQRCTB1InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
161
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@theqrl/qrl-contracts",
3
+ "description": "Secure Hyperion Smart Contract library for QRL",
4
+ "version": "0.1.0",
5
+ "files": [
6
+ "**/*.hyp",
7
+ "/build/contracts/*.json",
8
+ "!/mocks/**/*"
9
+ ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/theQRL/qrl-contracts.git"
13
+ },
14
+ "keywords": [
15
+ "hyperion",
16
+ "smart",
17
+ "contracts",
18
+ "security",
19
+ "qrl"
20
+ ],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/theQRL/qrl-contracts/issues"
25
+ }
26
+ }
@@ -0,0 +1,123 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (token/SQRCTB1/ISQRCTB1.hyp)
3
+
4
+ pragma hyperion >=0.0;
5
+
6
+ import {IZRC165} from "../../utils/introspection/IZRC165.hyp";
7
+
8
+ /**
9
+ * @dev Required interface of an SQRC-TB1 compliant contract, as defined in the
10
+ * https://eips.ethereum.org/EIPS/eip-1155[ZRC].
11
+ */
12
+ interface ISQRCTB1 is IZRC165 {
13
+ /**
14
+ * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
15
+ */
16
+ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
17
+
18
+ /**
19
+ * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
20
+ * transfers.
21
+ */
22
+ event TransferBatch(
23
+ address indexed operator,
24
+ address indexed from,
25
+ address indexed to,
26
+ uint256[] ids,
27
+ uint256[] values
28
+ );
29
+
30
+ /**
31
+ * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
32
+ * `approved`.
33
+ */
34
+ event ApprovalForAll(address indexed account, address indexed operator, bool approved);
35
+
36
+ /**
37
+ * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
38
+ *
39
+ * If an {URI} event was emitted for `id`, the standard
40
+ * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
41
+ * returned by {ISQRCTB1MetadataURI-uri}.
42
+ */
43
+ event URI(string value, uint256 indexed id);
44
+
45
+ /**
46
+ * @dev Returns the value of tokens of token type `id` owned by `account`.
47
+ */
48
+ function balanceOf(address account, uint256 id) external view returns (uint256);
49
+
50
+ /**
51
+ * @dev xref:ROOT:zrc1155.adoc#batch-operations[Batched] version of {balanceOf}.
52
+ *
53
+ * Requirements:
54
+ *
55
+ * - `accounts` and `ids` must have the same length.
56
+ */
57
+ function balanceOfBatch(
58
+ address[] calldata accounts,
59
+ uint256[] calldata ids
60
+ ) external view returns (uint256[] memory);
61
+
62
+ /**
63
+ * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
64
+ *
65
+ * Emits an {ApprovalForAll} event.
66
+ *
67
+ * Requirements:
68
+ *
69
+ * - `operator` cannot be the zero address.
70
+ */
71
+ function setApprovalForAll(address operator, bool approved) external;
72
+
73
+ /**
74
+ * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
75
+ *
76
+ * See {setApprovalForAll}.
77
+ */
78
+ function isApprovedForAll(address account, address operator) external view returns (bool);
79
+
80
+ /**
81
+ * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
82
+ *
83
+ * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
84
+ * to an untrusted contract, when invoking {ISQRCTB1Receiver-onSQRCTB1Received} on the receiver.
85
+ * Ensure to follow the checks-effects-interactions pattern and consider employing
86
+ * reentrancy guards when interacting with untrusted contracts.
87
+ *
88
+ * Emits a {TransferSingle} event.
89
+ *
90
+ * Requirements:
91
+ *
92
+ * - `to` cannot be the zero address.
93
+ * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
94
+ * - `from` must have a balance of tokens of type `id` of at least `value` amount.
95
+ * - If `to` refers to a smart contract, it must implement {ISQRCTB1Receiver-onSQRCTB1Received} and return the
96
+ * acceptance magic value.
97
+ */
98
+ function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
99
+
100
+ /**
101
+ * @dev xref:ROOT:zrc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
102
+ *
103
+ * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
104
+ * to an untrusted contract, when invoking {ISQRCTB1Receiver-onSQRCTB1BatchReceived} on the receiver.
105
+ * Ensure to follow the checks-effects-interactions pattern and consider employing
106
+ * reentrancy guards when interacting with untrusted contracts.
107
+ *
108
+ * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
109
+ *
110
+ * Requirements:
111
+ *
112
+ * - `ids` and `values` must have the same length.
113
+ * - If `to` refers to a smart contract, it must implement {ISQRCTB1Receiver-onSQRCTB1BatchReceived} and return the
114
+ * acceptance magic value.
115
+ */
116
+ function safeBatchTransferFrom(
117
+ address from,
118
+ address to,
119
+ uint256[] calldata ids,
120
+ uint256[] calldata values,
121
+ bytes calldata data
122
+ ) external;
123
+ }
@@ -0,0 +1,59 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // QRL Contracts (last updated v0.1.0) (token/SQRCTB1/ISQRCTB1Receiver.hyp)
3
+
4
+ pragma hyperion >=0.0;
5
+
6
+ import {IZRC165} from "../../utils/introspection/IZRC165.hyp";
7
+
8
+ /**
9
+ * @dev Interface that must be implemented by smart contracts in order to receive
10
+ * SQRC-TB1 token transfers.
11
+ */
12
+ interface ISQRCTB1Receiver is IZRC165 {
13
+ /**
14
+ * @dev Handles the receipt of a single SQRC-TB1 token type. This function is
15
+ * called at the end of a `safeTransferFrom` after the balance has been updated.
16
+ *
17
+ * NOTE: To accept the transfer, this must return
18
+ * `bytes4(keccak256("onSQRCTB1Received(address,address,uint256,uint256,bytes)"))`
19
+ * (i.e. 0xf23a6e61, or its own function selector).
20
+ *
21
+ * @param operator The address which initiated the transfer (i.e. msg.sender)
22
+ * @param from The address which previously owned the token
23
+ * @param id The ID of the token being transferred
24
+ * @param value The amount of tokens being transferred
25
+ * @param data Additional data with no specified format
26
+ * @return `bytes4(keccak256("onSQRCTB1Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed
27
+ */
28
+ function onSQRCTB1Received(
29
+ address operator,
30
+ address from,
31
+ uint256 id,
32
+ uint256 value,
33
+ bytes calldata data
34
+ ) external returns (bytes4);
35
+
36
+ /**
37
+ * @dev Handles the receipt of a multiple SQRC-TB1 token types. This function
38
+ * is called at the end of a `safeBatchTransferFrom` after the balances have
39
+ * been updated.
40
+ *
41
+ * NOTE: To accept the transfer(s), this must return
42
+ * `bytes4(keccak256("onSQRCTB1BatchReceived(address,address,uint256[],uint256[],bytes)"))`
43
+ * (i.e. 0xbc197c81, or its own function selector).
44
+ *
45
+ * @param operator The address which initiated the batch transfer (i.e. msg.sender)
46
+ * @param from The address which previously owned the token
47
+ * @param ids An array containing ids of each token being transferred (order and length must match values array)
48
+ * @param values An array containing amounts of each token being transferred (order and length must match ids array)
49
+ * @param data Additional data with no specified format
50
+ * @return `bytes4(keccak256("onSQRCTB1BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed
51
+ */
52
+ function onSQRCTB1BatchReceived(
53
+ address operator,
54
+ address from,
55
+ uint256[] calldata ids,
56
+ uint256[] calldata values,
57
+ bytes calldata data
58
+ ) external returns (bytes4);
59
+ }