File size: 8,661 Bytes
f998fcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// This contract is part of Zellic’s smart contract dataset, which is a collection of publicly available contract code gathered as of March 2023.

// SPDX-License-Identifier: MIT

pragma solidity 0.8.13;

import "./IERC20.sol";

/// @title IERC1400 Security Token Standard
/// @dev See https://github.com/SecurityTokenStandard/EIP-Spec

interface IERC1400 is IERC20 {
    /*------------------ Documentation Management --------------------*/

    /**
     * @dev Returns the documents url and hash
     */
    function getDocument(bytes32 _docName)
        external
        view
        returns (string memory, bytes32);

    /**
     * @dev Creates a new document when the document doesn't already exist
     * and updates otherwise
     *
     * Emits {Document} event
     */
    function setDocument(
        bytes32 _docName,
        string calldata _uri,
        bytes32 _documentHash
    ) external;

    /*--------------------- Token Information -----------------------*/

    /**
     * @dev Returns the `_tokenHolder` balance in the `_partition` partition
     */
    function balanceOfByPartition(bytes32 _partition, address _tokenHolder)
        external
        view
        returns (uint256);

    /**
     * @dev Returns the partitions where the `_tokenHolder` has tokens
     */
    function partitionsOf(address _tokenHolder)
        external
        view
        returns (bytes32[] memory);

    /*------------------------- Transfers ---------------------------*/

    /**
     * @dev Moves `_value` amount of tokens from the caller`s
     * account to `_to`, the caller is known to the contract by
     * its `_data` in document
     *
     * Emits {Transfer}
     */
    function transferWithData(
        address _to,
        uint256 _value,
        bytes calldata _data
    ) external;

    /**
     * @dev Moves `_value` amount of tokens from `_from` account to `_to`
     * using the allowance mechanism. `_value` is then deducted from the
     * caller's allowance.
     *
     * Emits {Transfer}
     */
    function transferFromWithData(
        address _from,
        address _to,
        uint256 _value,
        bytes calldata _data
    ) external;

    /*------------------- Partition Token Transfers ---------------------*/
    /**
     * @dev Moves `_value` amount of tokens in the `_partition` from the
     * caller's account to `_to`
     *
     * Emits {TransferByPartition}
     */
    function transferByPartition(
        bytes32 _partition,
        address _to,
        uint256 _value,
        bytes calldata _data
    ) external returns (bytes32);

    /*------------------------ Token Issuance --------------------------*/
    /**
     * @dev Returns true if the token can be issued, false otherwise
     */
    function isIssuable() external view returns (bool);

    /**
     * @dev Mints token to `_tokenHolder` which is known to the contract by
     * its `_data` in document
     *
     * Emits {Issued}
     */
    function issue(
        address _tokenHolder,
        uint256 _value,
        bytes calldata _data
    ) external;

    /**
     * @dev Creates token in the `_partition` and moves it to `_tokenHolder`
     * which is known to the contract by its `_data` in document
     *
     * note Creates a new partition if the `_partition` doesn't already exist
     *
     * Emits {IssuedByPartition}
     */
    function issueByPartition(
        bytes32 _partition,
        address _tokenHolder,
        uint256 _value,
        bytes calldata _data
    ) external;

    /*------------------------ Token Redemption --------------------------*/
    /**
     * @dev Burns and deducts the `_value` amount of tokens from the caller's
     * account which is known to the contract by its `_data` in document
     *
     * Emits {Redeemed}
     */
    function redeem(uint256 _value, bytes calldata _data) external;

    /**
     * @dev Burns and deducts the `_value` amount of tokens from the `_tokenHolder`
     * account which is known to the contract by its `_data` in document using the
     * allowance mechanism. `_value` is then deducted from the caller's allowance
     *
     * Emits {Redeemed}
     */
    function redeemFrom(
        address _tokenHolder,
        uint256 _value,
        bytes calldata _data
    ) external;

    /*------------------------ Transfer Validity --------------------------*/
    /**
     * @dev Returns true if the caller's data the `_data` is valid, false otherwise
     */
    function canTransfer(
        address _to,
        uint256 _value,
        bytes calldata _data
    ) external view returns (bytes1, bytes32);

    /**
     * @dev Returns true if the caller's data the `_data` is valid and enough
     *  allowance, false otherwise
     */
    function canTransferFrom(
        address _from,
        address _to,
        uint256 _value,
        bytes calldata _data
    ) external view returns (bytes1, bytes32);

    /**
     * @dev Returns a type {bytes1} reason code, type {bytes32} message, and data
     * if necessary
     */
    function canTransferByPartition(
        address _from,
        address _to,
        bytes32 _partition,
        uint256 _value,
        bytes calldata _data
    )
        external
        view
        returns (
            bytes1,
            bytes32,
            bytes32
        );

    /*------------------------ Document Events --------------------------*/
    /**
     * @dev Emittied when a document is created/updated
     */
    event Document(bytes32 indexed _name, string _uri, bytes32 _documentHash);

    /*------------------------ Transfer Events --------------------------*/
    /**
     * @dev Emittied when `_value` amount of token in the partition `_fromPartition`
     * from the `_from` to `_to`
     */
    event TransferByPartition(
        bytes32 indexed _fromPartition,
        address _operator,
        address indexed _from,
        address indexed _to,
        uint256 _value,
        bytes _data,
        bytes _operatorData
    );

    /*------------------ Issuance / Redemption Events -------------------*/
    /**
     * @dev Emittied when `_value` amount of token is issued to `_to`
     * which is known to the contract by its `_data` in document
     *
     * note `_operator` is the caller
     */
    event Issued(
        address indexed _operator,
        address indexed _to,
        uint256 _value,
        bytes _data
    );

    /**
     * @dev Emittied when `_value` amount of token is redeemed
     * from the `_from` which is known to the contract by
     *  its `_data` in document
     *
     * note `_operator` is the caller
     */
    event Redeemed(
        address indexed _operator,
        address indexed _from,
        uint256 _value,
        bytes _data
    );

    /**
     * @dev Emittied when `_value` amount of token is issued to `_to`
     * in the partition `_fromPartition` which is known to the contract
     * by its `_data` in document
     *
     * note `_operator` is the caller and `_operatorData` depends on
     * the logic applied and can be nothing
     */
    event IssuedByPartition(
        bytes32 indexed _partition,
        address indexed _operator,
        address indexed _to,
        uint256 _value,
        bytes _data,
        bytes _operatorData
    );

    /**
     * @dev Emittied when `_value` amount of token is redeemed
     * from the `_from` in the partition `_fromPartition` which
     * is known to the contract by its `_data` in document
     *
     * note `_operator` is the caller and `_operatorData` depends on
     * the logic applied and can be nothing
     */
    event RedeemedByPartition(
        bytes32 indexed _partition,
        address indexed _operator,
        address indexed _from,
        uint256 _value,
        bytes _operatorData
    );
}

/**
 * Reason codes - ERC-1066
 *
 * To improve the token holder experience, canTransfer MUST return a reason byte code
 * on success or failure based on the ERC-1066 application-specific status codes specified below.
 * An implementation can also return arbitrary data as a bytes32 to provide additional
 * information not captured by the reason code.
 *
 * Code	Reason
 * 0x50	transfer failure
 * 0x51	transfer success
 * 0x52	insufficient balance
 * 0x53	insufficient allowance
 * 0x54	transfers halted (contract paused)
 * 0x55	funds locked (lockup period)
 * 0x56	invalid sender
 * 0x57	invalid receiver
 * 0x58	invalid operator (transfer agent)
 * 0x59
 * 0x5a
 * 0x5b
 * 0x5a
 * 0x5b
 * 0x5c
 * 0x5d
 * 0x5e
 * 0x5f	token meta or info
 *
 * These codes are being discussed at: https://ethereum-magicians.org/t/erc-1066-ethereum-status-codes-esc/283/24
 */