@buenos_andres/contracts 0.1.4 → 0.2.9
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/package.json +31 -11
- package/security/Initializable.compact +2 -2
- package/security/Pausable.compact +2 -2
- package/security/witnesses/InitializableWitnesses.js +1 -1
- package/security/witnesses/PausableWitnesses.js +1 -1
- package/utils/Utils.compact +2 -2
- package/utils/witnesses/UtilsWitnesses.js +1 -1
- package/access/AccessControl.compact +0 -322
- package/access/Ownable.compact +0 -213
- package/access/witnesses/AccessControlWitnesses.d.ts +0 -2
- package/access/witnesses/AccessControlWitnesses.js +0 -3
- package/access/witnesses/OwnableWitnesses.d.ts +0 -2
- package/access/witnesses/OwnableWitnesses.js +0 -3
- package/token/FungibleToken.compact +0 -607
- package/token/MultiToken.compact +0 -546
- package/token/NonFungibleToken.compact +0 -806
- package/token/witnesses/FungibleTokenWitnesses.d.ts +0 -2
- package/token/witnesses/FungibleTokenWitnesses.js +0 -3
- package/token/witnesses/MultiTokenWitnesses.d.ts +0 -2
- package/token/witnesses/MultiTokenWitnesses.js +0 -3
- package/token/witnesses/NonFungibleTokenWitnesses.d.ts +0 -2
- package/token/witnesses/NonFungibleTokenWitnesses.js +0 -3
package/token/MultiToken.compact
DELETED
|
@@ -1,546 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MIT
|
|
2
|
-
// MyFun Contracts v0.1.4 (token/MultiToken.compact)
|
|
3
|
-
|
|
4
|
-
pragma language_version >= 0.16.0;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @module MultiToken
|
|
8
|
-
* @description An unshielded MultiToken library. This library is inspired by
|
|
9
|
-
* ERC1155. Many aspects of the EIP-1155 spec cannot be implemented in Compact;
|
|
10
|
-
* therefore, the MultiToken module should be treated as an approximation of
|
|
11
|
-
* the ERC1155 standard and not necessarily a compliant implementation.
|
|
12
|
-
*
|
|
13
|
-
* @notice One notable difference regarding this implementation and the EIP1155 spec
|
|
14
|
-
* consists of the token size. Uint<128> is used as the token size because Uint<256>
|
|
15
|
-
* cannot be supported. This is true for both token IDs and for amounts.
|
|
16
|
-
* This is due to encoding limits on the midnight circuit backend:
|
|
17
|
-
* https://github.com/midnightntwrk/compactc/issues/929
|
|
18
|
-
*
|
|
19
|
-
* @notice Some features defined in th EIP1155 spec are NOT included.
|
|
20
|
-
* Such features include:
|
|
21
|
-
*
|
|
22
|
-
* 1. Batch mint, burn, transfer - Without support for dynamic arrays,
|
|
23
|
-
* batching transfers is difficult to do without a hacky solution.
|
|
24
|
-
* For instance, we could change the `to` and `from` parameters to be
|
|
25
|
-
* vectors. This would change the signature and would be both difficult
|
|
26
|
-
* to use and easy to misuse.
|
|
27
|
-
*
|
|
28
|
-
* 2. Querying batched balances - This can be somewhat supported.
|
|
29
|
-
* The issue, without dynamic arrays, is that the module circuit must use
|
|
30
|
-
* Vector<n> for accounts and ids; therefore, the implementing contract must
|
|
31
|
-
* explicitly define the number of balances to query in the circuit i.e.
|
|
32
|
-
*
|
|
33
|
-
* balanceOfBatch_10(
|
|
34
|
-
* accounts: Vector<10, Either<ZswapCoinPublicKey, ContractAddress>>,
|
|
35
|
-
* ids: Vector<10, Uint<128>>
|
|
36
|
-
* ): Vector<10, Uint<128>>
|
|
37
|
-
*
|
|
38
|
-
* Since this module does not offer mint or transfer batching,
|
|
39
|
-
* balance batching is also not included at this time.
|
|
40
|
-
*
|
|
41
|
-
* 3. Introspection - Compact currently cannot support contract-to-contract
|
|
42
|
-
* queries for introspection. ERC165 (or an equivalent thereof) is NOT
|
|
43
|
-
* included in the contract.
|
|
44
|
-
*
|
|
45
|
-
* 4. Safe transfers - The lack of an introspection mechanism means
|
|
46
|
-
* safe transfers of any kind can not be supported.
|
|
47
|
-
* BE AWARE: Tokens sent to a contract address MAY be lost forever.
|
|
48
|
-
*
|
|
49
|
-
* Due to the vast incompatibilities with the EIP1155 spec, it is our
|
|
50
|
-
* opinion that this implementation should not be called ERC1155 at this time
|
|
51
|
-
* as this would be both very confusing and misleading. This may change as more
|
|
52
|
-
* features become available. The list of missing features is as follows:
|
|
53
|
-
*
|
|
54
|
-
* - Full uint256 support.
|
|
55
|
-
* - Events.
|
|
56
|
-
* - Dynamic arrays.
|
|
57
|
-
* - Introspection.
|
|
58
|
-
* - Contract-to-contract calls for acceptance callback.
|
|
59
|
-
*
|
|
60
|
-
* @notice Further discussion and consideration required:
|
|
61
|
-
*
|
|
62
|
-
* - Consider changing the underscore in the internal methods to `unsafe` or
|
|
63
|
-
* adopting dot notation for prefixing imports.
|
|
64
|
-
* - Revise logic once contract-to-contract interactions are available on midnight.
|
|
65
|
-
*/
|
|
66
|
-
module MultiToken {
|
|
67
|
-
import CompactStandardLibrary;
|
|
68
|
-
import "../security/Initializable" prefix Initializable_;
|
|
69
|
-
import "../utils/Utils" prefix Utils_;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @description Mapping from token ID to account balances.
|
|
73
|
-
* @type {Uint<128>} id - The token identifier.
|
|
74
|
-
* @type {Either<ZswapCoinPublicKey, ContractAddress>} account - The account address.
|
|
75
|
-
* @type {Uint<128>} balance - The balance of the account for the token.
|
|
76
|
-
* @type {Map<id, Map<account, balance>>}
|
|
77
|
-
* @type {Map<Uint<128>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>} _balances
|
|
78
|
-
*/
|
|
79
|
-
export ledger _balances: Map<Uint<128>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @description Mapping from account to operator approvals.
|
|
83
|
-
* @type {Either<ZswapCoinPublicKey, ContractAddress>} account - The account address.
|
|
84
|
-
* @type {Either<ZswapCoinPublicKey, ContractAddress>} operator - The operator address.
|
|
85
|
-
* @type {Boolean} approved - The approval status of the operator for the account.
|
|
86
|
-
* @type {Map<account, Map<operator, approved>>}
|
|
87
|
-
* @type {Map<Either<ZswapCoinPublicKey, ContractAddress>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Boolean>>}
|
|
88
|
-
*/
|
|
89
|
-
export ledger _operatorApprovals: Map<Either<ZswapCoinPublicKey, ContractAddress>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Boolean>>;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @description Base URI for computing token URIs.
|
|
93
|
-
* Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json
|
|
94
|
-
* @type {Opaque<"string">} _uri - The base URI for all token URIs.
|
|
95
|
-
*/
|
|
96
|
-
export ledger _uri: Opaque<"string">;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @description Initializes the contract by setting the base URI for all tokens.
|
|
100
|
-
*
|
|
101
|
-
* @circuitInfo k=10, rows=45
|
|
102
|
-
*
|
|
103
|
-
* Requirements:
|
|
104
|
-
*
|
|
105
|
-
* - Must be called in the contract's constructor.
|
|
106
|
-
*
|
|
107
|
-
* @param {Opaque<"string">} uri_ - The base URI for all token URIs.
|
|
108
|
-
* @return {[]} - Empty tuple.
|
|
109
|
-
*/
|
|
110
|
-
export circuit initialize(uri_: Opaque<"string">): [] {
|
|
111
|
-
Initializable_initialize();
|
|
112
|
-
_setURI(uri_);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @description This implementation returns the same URI for *all* token types. It relies
|
|
117
|
-
* on the token type ID substitution mechanism defined in the EIP:
|
|
118
|
-
* https://eips.ethereum.org/EIPS/eip-1155#metadata.
|
|
119
|
-
* Clients calling this function must replace the `\{id\}` substring with the
|
|
120
|
-
* actual token type ID.
|
|
121
|
-
*
|
|
122
|
-
* @circuitInfo k=10, rows=90
|
|
123
|
-
*
|
|
124
|
-
* Requirements:
|
|
125
|
-
*
|
|
126
|
-
* - Contract is initialized.
|
|
127
|
-
*
|
|
128
|
-
* @param {Uint<128>} id - The token identifier to query.
|
|
129
|
-
* return {Opaque<"string">} - The base URI for all tokens.
|
|
130
|
-
*/
|
|
131
|
-
export circuit uri(id: Uint<128>): Opaque<"string"> {
|
|
132
|
-
Initializable_assertInitialized();
|
|
133
|
-
|
|
134
|
-
return _uri;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* @description Returns the amount of `id` tokens owned by `account`.
|
|
139
|
-
*
|
|
140
|
-
* @circuitInfo k=10, rows=439
|
|
141
|
-
*
|
|
142
|
-
* Requirements:
|
|
143
|
-
*
|
|
144
|
-
* - Contract is initialized.
|
|
145
|
-
*
|
|
146
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The account balance to query.
|
|
147
|
-
* @param {Uint<128>} id - The token identifier to query.
|
|
148
|
-
* return {Uint<128>} - The quantity of `id` tokens that `account` owns.
|
|
149
|
-
*/
|
|
150
|
-
export circuit balanceOf(account: Either<ZswapCoinPublicKey, ContractAddress>, id: Uint<128>): Uint<128> {
|
|
151
|
-
Initializable_assertInitialized();
|
|
152
|
-
|
|
153
|
-
if (!_balances.member(disclose(id)) || !_balances.lookup(id).member(disclose(account))) {
|
|
154
|
-
return 0;
|
|
155
|
-
}
|
|
156
|
-
return _balances.lookup(id).lookup(disclose(account));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @description Enables or disables approval for `operator` to manage all of the caller's assets.
|
|
161
|
-
*
|
|
162
|
-
* @circuitInfo k=10, rows=404
|
|
163
|
-
*
|
|
164
|
-
* Requirements:
|
|
165
|
-
*
|
|
166
|
-
* - Contract is initialized.
|
|
167
|
-
* - `operator` is not the zero address.
|
|
168
|
-
*
|
|
169
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} operator - The ZswapCoinPublicKey or ContractAddress
|
|
170
|
-
* whose approval is set for the caller's assets.
|
|
171
|
-
* @param {Boolean} approved - The boolean value determining if the operator may or may not handle the
|
|
172
|
-
* caller's assets.
|
|
173
|
-
* @return {[]} - Empty tuple.
|
|
174
|
-
*/
|
|
175
|
-
export circuit setApprovalForAll(operator: Either<ZswapCoinPublicKey, ContractAddress>, approved: Boolean): [] {
|
|
176
|
-
Initializable_assertInitialized();
|
|
177
|
-
|
|
178
|
-
// TODO: Contract-to-contract calls not yet supported.
|
|
179
|
-
const caller = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
|
|
180
|
-
_setApprovalForAll(caller, operator, approved);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* @description Queries if `operator` is an authorized operator for `owner`.
|
|
185
|
-
*
|
|
186
|
-
* @circuitInfo k=10, rows=619
|
|
187
|
-
*
|
|
188
|
-
* Requirements:
|
|
189
|
-
*
|
|
190
|
-
* - Contract is initialized.
|
|
191
|
-
*
|
|
192
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The queried possessor of assets.
|
|
193
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} operator - The queried handler of `account`'s assets.
|
|
194
|
-
* @return {Boolean} - Whether or not `operator` has permission to handle `account`'s assets.
|
|
195
|
-
*/
|
|
196
|
-
export circuit isApprovedForAll(
|
|
197
|
-
account: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
198
|
-
operator: Either<ZswapCoinPublicKey, ContractAddress>
|
|
199
|
-
): Boolean {
|
|
200
|
-
Initializable_assertInitialized();
|
|
201
|
-
|
|
202
|
-
if (!_operatorApprovals.member(disclose(account)) || !_operatorApprovals.lookup(account).member(disclose(operator))) {
|
|
203
|
-
return false;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
return _operatorApprovals.lookup(account).lookup(disclose(operator));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @description Transfers ownership of `value` amount of `id` tokens from `from` to `to`.
|
|
211
|
-
* The caller must be `from` or approved to transfer on their behalf.
|
|
212
|
-
*
|
|
213
|
-
* @circuitInfo k=11, rows=1882
|
|
214
|
-
*
|
|
215
|
-
* @notice Transfers to contract addresses are currently disallowed until contract-to-contract
|
|
216
|
-
* interactions are supported in Compact. This restriction prevents assets from
|
|
217
|
-
* being inadvertently locked in contracts that cannot currently handle token receipt.
|
|
218
|
-
*
|
|
219
|
-
* @extensibility External circuit. Can be used directly by consumers of this module.
|
|
220
|
-
* See **Extensibility** documentation for usage patterns.
|
|
221
|
-
*
|
|
222
|
-
* Requirements:
|
|
223
|
-
*
|
|
224
|
-
* - Contract is initialized.
|
|
225
|
-
* - `to` is not a ContractAddress.
|
|
226
|
-
* - `to` is not the zero address.
|
|
227
|
-
* - `from` is not the zero address.
|
|
228
|
-
* - Caller must be `from` or approved via `setApprovalForAll`.
|
|
229
|
-
* - `from` must have an `id` balance of at least `value`.
|
|
230
|
-
*
|
|
231
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner from which the transfer originates.
|
|
232
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transferred assets.
|
|
233
|
-
* @param {Uint<128>} id - The unique identifier of the asset type.
|
|
234
|
-
* @param {Uint<128>} value - The quantity of `id` tokens to transfer.
|
|
235
|
-
* @return {[]} - Empty tuple.
|
|
236
|
-
*/
|
|
237
|
-
export circuit transferFrom(
|
|
238
|
-
from: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
239
|
-
to: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
240
|
-
id: Uint<128>,
|
|
241
|
-
value: Uint<128>
|
|
242
|
-
): [] {
|
|
243
|
-
assert(!Utils_isContractAddress(to), "MultiToken: unsafe transfer");
|
|
244
|
-
_unsafeTransferFrom(from, to, id, value);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* @description Transfers ownership of `value` amount of `id` tokens from `from` to `to`.
|
|
249
|
-
* Does not impose restrictions on the caller, making it suitable for composition
|
|
250
|
-
* in higher-level contract logic.
|
|
251
|
-
*
|
|
252
|
-
* @circuitInfo k=11, rows=1487
|
|
253
|
-
*
|
|
254
|
-
* @notice Transfers to contract addresses are currently disallowed until contract-to-contract
|
|
255
|
-
* interactions are supported in Compact. This restriction prevents assets from
|
|
256
|
-
* being inadvertently locked in contracts that cannot currently handle token receipt.
|
|
257
|
-
*
|
|
258
|
-
* Requirements:
|
|
259
|
-
*
|
|
260
|
-
* - Contract is initialized.
|
|
261
|
-
* - `to` is not a ContractAddress.
|
|
262
|
-
* - `to` is not the zero address.
|
|
263
|
-
* - `from` is not the zero address.
|
|
264
|
-
* - `from` must have an `id` balance of at least `value`.
|
|
265
|
-
*
|
|
266
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner from which the transfer originates.
|
|
267
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transferred assets.
|
|
268
|
-
* @param {Uint<128>} id - The unique identifier of the asset type.
|
|
269
|
-
* @param {Uint<128>} value - The quantity of `id` tokens to transfer.
|
|
270
|
-
* @return {[]} - Empty tuple.
|
|
271
|
-
*/
|
|
272
|
-
export circuit _transfer(
|
|
273
|
-
from: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
274
|
-
to: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
275
|
-
id: Uint<128>,
|
|
276
|
-
value: Uint<128>
|
|
277
|
-
): [] {
|
|
278
|
-
assert(!Utils_isContractAddress(to), "MultiToken: unsafe transfer");
|
|
279
|
-
_unsafeTransfer(from, to, id, value);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* @description Transfers a value amount of tokens of type id from from to to.
|
|
284
|
-
* This circuit will mint (or burn) if `from` (or `to`) is the zero address.
|
|
285
|
-
*
|
|
286
|
-
* @circuitInfo k=11, rows=1482
|
|
287
|
-
*
|
|
288
|
-
* Requirements:
|
|
289
|
-
*
|
|
290
|
-
* - Contract is initialized.
|
|
291
|
-
* - If `from` is not zero, the balance of `id` of `from` must be >= `value`.
|
|
292
|
-
*
|
|
293
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The origin of the transfer.
|
|
294
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The destination of the transfer.
|
|
295
|
-
* @param {Uint<128>} id - The unique identifier of the asset type.
|
|
296
|
-
* @param {Uint<128>} value - The quantity of `id` tokens to transfer.
|
|
297
|
-
* @return {[]} - Empty tuple.
|
|
298
|
-
*/
|
|
299
|
-
circuit _update(
|
|
300
|
-
from: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
301
|
-
to: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
302
|
-
id: Uint<128>,
|
|
303
|
-
value: Uint<128>
|
|
304
|
-
): [] {
|
|
305
|
-
Initializable_assertInitialized();
|
|
306
|
-
|
|
307
|
-
if (!Utils_isKeyOrAddressZero(disclose(from))) {
|
|
308
|
-
const fromBalance = balanceOf(from, id);
|
|
309
|
-
assert(fromBalance >= value, "MultiToken: insufficient balance");
|
|
310
|
-
// overflow not possible
|
|
311
|
-
const newBalance = fromBalance - value;
|
|
312
|
-
_balances.lookup(id).insert(disclose(from), disclose(newBalance));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (!Utils_isKeyOrAddressZero(disclose(to))) {
|
|
316
|
-
// id not initialized
|
|
317
|
-
if (!_balances.member(disclose(id))) {
|
|
318
|
-
_balances.insert(disclose(id), default<Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>);
|
|
319
|
-
_balances.lookup(id).insert(disclose(to), disclose(value as Uint<128>));
|
|
320
|
-
} else {
|
|
321
|
-
const toBalance = balanceOf(to, id);
|
|
322
|
-
// TODO: Replace with Max_Uint128()
|
|
323
|
-
const MAX_UINT128 = 340282366920938463463374607431768211455;
|
|
324
|
-
assert(MAX_UINT128 - toBalance >= value, "MultiToken: arithmetic overflow");
|
|
325
|
-
_balances.lookup(id).insert(disclose(to), disclose(toBalance + value as Uint<128>));
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* @description Unsafe variant of `transferFrom` which allows transfers to contract addresses.
|
|
332
|
-
* The caller must be `from` or approved to transfer on their behalf.
|
|
333
|
-
*
|
|
334
|
-
* @circuitInfo k=11, rows=1881
|
|
335
|
-
*
|
|
336
|
-
* @warning Transfers to contract addresses are considered unsafe because contract-to-contract
|
|
337
|
-
* calls are not currently supported. Tokens sent to a contract address may become irretrievable.
|
|
338
|
-
* Once contract-to-contract calls are supported, this circuit may be deprecated.
|
|
339
|
-
*
|
|
340
|
-
* Requirements:
|
|
341
|
-
*
|
|
342
|
-
* - Contract is initialized.
|
|
343
|
-
* - `to` is not the zero address.
|
|
344
|
-
* - `from` is not the zero address.
|
|
345
|
-
* - Caller must be `from` or approved via `setApprovalForAll`.
|
|
346
|
-
* - `from` must have an `id` balance of at least `value`.
|
|
347
|
-
*
|
|
348
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner from which the transfer originates.
|
|
349
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transferred assets.
|
|
350
|
-
* @param {Uint<128>} id - The unique identifier of the asset type.
|
|
351
|
-
* @param {Uint<128>} value - The quantity of `id` tokens to transfer.
|
|
352
|
-
* @return {[]} - Empty tuple.
|
|
353
|
-
*/
|
|
354
|
-
export circuit _unsafeTransferFrom(
|
|
355
|
-
from: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
356
|
-
to: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
357
|
-
id: Uint<128>,
|
|
358
|
-
value: Uint<128>
|
|
359
|
-
): [] {
|
|
360
|
-
Initializable_assertInitialized();
|
|
361
|
-
|
|
362
|
-
// TODO: Contract-to-contract calls not yet supported.
|
|
363
|
-
// Once available, handle ContractAddress recipients here.
|
|
364
|
-
const caller = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
|
|
365
|
-
if (disclose(from) != caller) {
|
|
366
|
-
assert(isApprovedForAll(from, caller), "MultiToken: unauthorized operator");
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
_unsafeTransfer(from, to, id, value);
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* @description Unsafe variant of `_transfer` which allows transfers to contract addresses.
|
|
374
|
-
* Does not impose restrictions on the caller, making it suitable as a low-level
|
|
375
|
-
* building block for advanced contract logic.
|
|
376
|
-
*
|
|
377
|
-
* @circuitInfo k=11, rows=1486
|
|
378
|
-
*
|
|
379
|
-
* @warning Transfers to contract addresses are considered unsafe because contract-to-contract
|
|
380
|
-
* calls are not currently supported. Tokens sent to a contract address may become irretrievable.
|
|
381
|
-
* Once contract-to-contract calls are supported, this circuit may be deprecated.
|
|
382
|
-
*
|
|
383
|
-
* Requirements:
|
|
384
|
-
*
|
|
385
|
-
* - Contract is initialized.
|
|
386
|
-
* - `from` is not the zero address.
|
|
387
|
-
* - `to` is not the zero address.
|
|
388
|
-
* - `from` must have an `id` balance of at least `value`.
|
|
389
|
-
*
|
|
390
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner from which the transfer originates.
|
|
391
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transferred assets.
|
|
392
|
-
* @param {Uint<128>} id - The unique identifier of the asset type.
|
|
393
|
-
* @param {Uint<128>} value - The quantity of `id` tokens to transfer.
|
|
394
|
-
* @return {[]} - Empty tuple.
|
|
395
|
-
*/
|
|
396
|
-
export circuit _unsafeTransfer(
|
|
397
|
-
from: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
398
|
-
to: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
399
|
-
id: Uint<128>,
|
|
400
|
-
value: Uint<128>
|
|
401
|
-
): [] {
|
|
402
|
-
Initializable_assertInitialized();
|
|
403
|
-
|
|
404
|
-
assert(!Utils_isKeyOrAddressZero(from), "MultiToken: invalid sender");
|
|
405
|
-
assert(!Utils_isKeyOrAddressZero(to), "MultiToken: invalid receiver");
|
|
406
|
-
_update(from, to, id, value);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* @description Sets a new URI for all token types, by relying on the token type ID
|
|
411
|
-
* substitution mechanism defined in the MultiToken standard.
|
|
412
|
-
* See https://eips.ethereum.org/EIPS/eip-1155#metadata.
|
|
413
|
-
*
|
|
414
|
-
* @circuitInfo k=10, rows=39
|
|
415
|
-
*
|
|
416
|
-
* @notice By this mechanism, any occurrence of the `\{id\}` substring in either the
|
|
417
|
-
* URI or any of the values in the JSON file at said URI will be replaced by
|
|
418
|
-
* clients with the token type ID.
|
|
419
|
-
*
|
|
420
|
-
* For example, the `https://token-cdn-domain/\{id\}.json` URI would be
|
|
421
|
-
* interpreted by clients as
|
|
422
|
-
* `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json`
|
|
423
|
-
* for token type ID 0x4cce0.
|
|
424
|
-
*
|
|
425
|
-
* Requirements:
|
|
426
|
-
*
|
|
427
|
-
* - Contract is initialized.
|
|
428
|
-
*
|
|
429
|
-
* @param {Opaque<"string">} newURI - The new base URI for all tokens.
|
|
430
|
-
* @return {[]} - Empty tuple.
|
|
431
|
-
*/
|
|
432
|
-
export circuit _setURI(newURI: Opaque<"string">): [] {
|
|
433
|
-
Initializable_assertInitialized();
|
|
434
|
-
|
|
435
|
-
_uri = disclose(newURI);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* @description Creates a `value` amount of tokens of type `token_id`, and assigns them to `to`.
|
|
440
|
-
*
|
|
441
|
-
* @circuitInfo k=10, rows=912
|
|
442
|
-
*
|
|
443
|
-
* @notice Transfers to contract addresses are currently disallowed until contract-to-contract
|
|
444
|
-
* interactions are supported in Compact. This restriction prevents assets from
|
|
445
|
-
* being inadvertently locked in contracts that cannot currently handle token receipt.
|
|
446
|
-
*
|
|
447
|
-
* Requirements:
|
|
448
|
-
*
|
|
449
|
-
* - Contract is initialized.
|
|
450
|
-
* - `to` is not the zero address.
|
|
451
|
-
* - `to` is not a ContractAddress.
|
|
452
|
-
*
|
|
453
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the minted tokens.
|
|
454
|
-
* @param {Uint<128>} id - The unique identifier for the token type.
|
|
455
|
-
* @param {Uint<128>} value - The quantity of `id` tokens that are minted to `to`.
|
|
456
|
-
* @return {[]} - Empty tuple.
|
|
457
|
-
*/
|
|
458
|
-
export circuit _mint(to: Either<ZswapCoinPublicKey, ContractAddress>, id: Uint<128>, value: Uint<128>): [] {
|
|
459
|
-
assert(!Utils_isContractAddress(to), "MultiToken: unsafe transfer");
|
|
460
|
-
_unsafeMint(to, id, value);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/**
|
|
464
|
-
* @description Unsafe variant of `_mint` which allows transfers to contract addresses.
|
|
465
|
-
*
|
|
466
|
-
* @circuitInfo k=10, rows=911
|
|
467
|
-
*
|
|
468
|
-
* @warning Transfers to contract addresses are considered unsafe because contract-to-contract
|
|
469
|
-
* calls are not currently supported. Tokens sent to a contract address may become irretrievable.
|
|
470
|
-
* Once contract-to-contract calls are supported, this circuit may be deprecated.
|
|
471
|
-
*
|
|
472
|
-
* Requirements:
|
|
473
|
-
*
|
|
474
|
-
* - Contract is initialized.
|
|
475
|
-
* - `to` is not the zero address.
|
|
476
|
-
*
|
|
477
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the minted tokens.
|
|
478
|
-
* @param {Uint<128>} id - The unique identifier for the token type.
|
|
479
|
-
* @param {Uint<128>} value - The quantity of `id` tokens that are minted to `to`.
|
|
480
|
-
* @return {[]} - Empty tuple.
|
|
481
|
-
*/
|
|
482
|
-
export circuit _unsafeMint(to: Either<ZswapCoinPublicKey, ContractAddress>, id: Uint<128>, value: Uint<128>): [] {
|
|
483
|
-
Initializable_assertInitialized();
|
|
484
|
-
|
|
485
|
-
assert(!Utils_isKeyOrAddressZero(to), "MultiToken: invalid receiver");
|
|
486
|
-
_update(burnAddress(), to, id, value);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
* @description Destroys a `value` amount of tokens of type `token_id` from `from`.
|
|
491
|
-
*
|
|
492
|
-
* @circuitInfo k=10, rows=688
|
|
493
|
-
*
|
|
494
|
-
* Requirements:
|
|
495
|
-
*
|
|
496
|
-
* - Contract is initialized.
|
|
497
|
-
* - `from` is not the zero address.
|
|
498
|
-
* - `from` must have an `id` balance of at least `value`.
|
|
499
|
-
*
|
|
500
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner whose tokens will be destroyed.
|
|
501
|
-
* @param {Uint<128>} id - The unique identifier of the token type.
|
|
502
|
-
* @param {Uint<128>} value - The quantity of `id` tokens that will be destroyed from `from`.
|
|
503
|
-
* @return {[]} - Empty tuple.
|
|
504
|
-
*/
|
|
505
|
-
export circuit _burn(from: Either<ZswapCoinPublicKey, ContractAddress>, id: Uint<128>, value: Uint<128>): [] {
|
|
506
|
-
Initializable_assertInitialized();
|
|
507
|
-
|
|
508
|
-
assert(!Utils_isKeyOrAddressZero(from), "MultiToken: invalid sender");
|
|
509
|
-
_update(from, burnAddress(), id, value);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* @description Enables or disables approval for `operator` to manage all of the caller's assets.
|
|
514
|
-
*
|
|
515
|
-
* @circuitInfo k=10, rows=518
|
|
516
|
-
*
|
|
517
|
-
* @notice This circuit does not check for access permissions but can be useful as a building block
|
|
518
|
-
* for more complex contract logic.
|
|
519
|
-
*
|
|
520
|
-
* Requirements:
|
|
521
|
-
*
|
|
522
|
-
* - Contract is initialized.
|
|
523
|
-
* - `operator` is not the zero address.
|
|
524
|
-
*
|
|
525
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} owner - The ZswapCoinPublicKey or ContractAddress of the target owner.
|
|
526
|
-
* @param {Either<ZswapCoinPublicKey, ContractAddress>} operator - The ZswapCoinPublicKey or ContractAddress whose approval is set for the
|
|
527
|
-
* `owner`'s assets.
|
|
528
|
-
* @param {Boolean} approved - The boolean value determining if the operator may or may not handle the
|
|
529
|
-
* `owner`'s assets.
|
|
530
|
-
* @return {[]} - Empty tuple.
|
|
531
|
-
*/
|
|
532
|
-
export circuit _setApprovalForAll(
|
|
533
|
-
owner: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
534
|
-
operator: Either<ZswapCoinPublicKey, ContractAddress>,
|
|
535
|
-
approved: Boolean
|
|
536
|
-
): [] {
|
|
537
|
-
Initializable_assertInitialized();
|
|
538
|
-
|
|
539
|
-
assert(!Utils_isKeyOrAddressZero(operator), "MultiToken: invalid operator");
|
|
540
|
-
if (!_operatorApprovals.member(disclose(owner))) {
|
|
541
|
-
_operatorApprovals.insert(disclose(owner), default<Map<Either<ZswapCoinPublicKey, ContractAddress>, Boolean>>);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
_operatorApprovals.lookup(owner).insert(disclose(operator), disclose(approved));
|
|
545
|
-
}
|
|
546
|
-
}
|