@buenos_andres/contracts 0.0.1-test.2 → 0.0.1-test.24

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 (36) hide show
  1. package/README.md +1 -0
  2. package/package.json +3 -14
  3. package/{dist/utils → utils}/Utils.compact +1 -0
  4. package/utils/witnesses/UtilsWitnesses.js +4 -0
  5. package/utils/witnesses/UtilsWitnesses.js.map +1 -0
  6. package/dist/access/AccessControl.compact +0 -321
  7. package/dist/access/Ownable.compact +0 -212
  8. package/dist/access/witnesses/AccessControlWitnesses.d.ts +0 -2
  9. package/dist/access/witnesses/AccessControlWitnesses.js +0 -1
  10. package/dist/access/witnesses/AccessControlWitnesses.ts +0 -3
  11. package/dist/access/witnesses/OwnableWitnesses.d.ts +0 -2
  12. package/dist/access/witnesses/OwnableWitnesses.js +0 -1
  13. package/dist/access/witnesses/OwnableWitnesses.ts +0 -3
  14. package/dist/security/Initializable.compact +0 -59
  15. package/dist/security/Pausable.compact +0 -88
  16. package/dist/security/witnesses/InitializableWitnesses.d.ts +0 -2
  17. package/dist/security/witnesses/InitializableWitnesses.js +0 -1
  18. package/dist/security/witnesses/InitializableWitnesses.ts +0 -3
  19. package/dist/security/witnesses/PausableWitnesses.d.ts +0 -2
  20. package/dist/security/witnesses/PausableWitnesses.js +0 -1
  21. package/dist/security/witnesses/PausableWitnesses.ts +0 -3
  22. package/dist/token/FungibleToken.compact +0 -606
  23. package/dist/token/MultiToken.compact +0 -545
  24. package/dist/token/NonFungibleToken.compact +0 -805
  25. package/dist/token/witnesses/FungibleTokenWitnesses.d.ts +0 -2
  26. package/dist/token/witnesses/FungibleTokenWitnesses.js +0 -1
  27. package/dist/token/witnesses/FungibleTokenWitnesses.ts +0 -3
  28. package/dist/token/witnesses/MultiTokenWitnesses.d.ts +0 -2
  29. package/dist/token/witnesses/MultiTokenWitnesses.js +0 -1
  30. package/dist/token/witnesses/MultiTokenWitnesses.ts +0 -3
  31. package/dist/token/witnesses/NonFungibleTokenWitnesses.d.ts +0 -2
  32. package/dist/token/witnesses/NonFungibleTokenWitnesses.js +0 -1
  33. package/dist/token/witnesses/NonFungibleTokenWitnesses.ts +0 -3
  34. package/dist/utils/witnesses/UtilsWitnesses.js +0 -1
  35. package/dist/utils/witnesses/UtilsWitnesses.ts +0 -3
  36. /package/{dist/utils → utils}/witnesses/UtilsWitnesses.d.ts +0 -0
@@ -1,606 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
-
3
- pragma language_version >= 0.16.0;
4
-
5
- /**
6
- * @module FungibleToken
7
- * @description An unshielded FungibleToken library.
8
- *
9
- * @notice One notable difference regarding this implementation and the EIP20 spec
10
- * consists of the token size. Uint<128> is used as the token size because Uint<256>
11
- * cannot be supported.
12
- * This is due to encoding limits on the midnight circuit backend:
13
- * https://github.com/midnightntwrk/compactc/issues/929
14
- *
15
- * @notice At the moment Midnight does not support contract-to-contract communication, but
16
- * there are ongoing efforts to enable this in the future. Thus, the main circuits of this module
17
- * restrict developers from sending tokens to contracts; however, we provide developers
18
- * the ability to experiment with sending tokens to contracts using the `_unsafe`
19
- * transfer methods. Once contract-to-contract communication is available we will follow the
20
- * deprecation plan outlined below:
21
- *
22
- * Initial Minor Version Change:
23
- *
24
- * - Mark _unsafeFN as deprecated and emit a warning if possible.
25
- * - Keep its implementation intact so existing callers continue to work.
26
- *
27
- * Later Major Version Change:
28
- *
29
- * - Drop _unsafeFN and remove `isContract` guard from `FN`.
30
- * - By this point, anyone using _unsafeFN should have migrated to the now C2C-capable `FN`.
31
- *
32
- * Due to the vast incompatibilities with the EIP20 spec, it is our
33
- * opinion that this implementation should not be called ERC20 at this time
34
- * as this would be both very confusing and misleading. This may change as more
35
- * features become available. The list of missing features is as follows:
36
- *
37
- * - Full uint256 support.
38
- * - Events.
39
- * - Contract-to-contract calls.
40
- */
41
- module FungibleToken {
42
- import CompactStandardLibrary;
43
- import "../security/Initializable" prefix Initializable_;
44
- import "../utils/Utils" prefix Utils_;
45
-
46
- /**
47
- * @description Mapping from account addresses to their token balances.
48
- * @type {Either<ZswapCoinPublicKey, ContractAddress>} account - The account address.
49
- * @type {Uint<128>} balance - The balance of the account.
50
- * @type {Map<account, balance>}
51
- * @type {Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>} _balances
52
- */
53
- export ledger _balances: Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>;
54
- /**
55
- * @description Mapping from owner accounts to spender accounts and their allowances.
56
- * @type {Either<ZswapCoinPublicKey, ContractAddress>} account - The owner account address.
57
- * @type {Either<ZswapCoinPublicKey, ContractAddress>} spender - The spender account address.
58
- * @type {Uint<128>} allowance - The amount allowed to be spent by the spender.
59
- * @type {Map<account, Map<spender, allowance>>}
60
- * @type {Map<Either<ZswapCoinPublicKey, ContractAddress>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>} _allowances
61
- */
62
- export ledger _allowances: Map<Either<ZswapCoinPublicKey, ContractAddress>, Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>;
63
-
64
- export ledger _totalSupply: Uint<128>;
65
-
66
- export sealed ledger _name: Opaque<"string">;
67
- export sealed ledger _symbol: Opaque<"string">;
68
- export sealed ledger _decimals: Uint<8>;
69
-
70
- /**
71
- * @description Initializes the contract by setting the name, symbol, and decimals.
72
- * @dev This MUST be called in the implementing contract's constructor. Failure to do so
73
- * can lead to an irreparable contract.
74
- *
75
- * @circuitInfo k=10, rows=71
76
- *
77
- * @param {Opaque<"string">} name_ - The name of the token.
78
- * @param {Opaque<"string">} symbol_ - The symbol of the token.
79
- * @param {Uint<8>} decimals_ - The number of decimals used to get the user representation.
80
- * @return {[]} - Empty tuple.
81
- */
82
- export circuit initialize(
83
- name_: Opaque<"string">,
84
- symbol_: Opaque<"string">,
85
- decimals_:Uint<8>
86
- ): [] {
87
- Initializable_initialize();
88
- _name = disclose(name_);
89
- _symbol = disclose(symbol_);
90
- _decimals = disclose(decimals_);
91
- }
92
-
93
- /**
94
- * @description Returns the token name.
95
- *
96
- * @circuitInfo k=10, rows=37
97
- *
98
- * Requirements:
99
- *
100
- * - Contract is initialized.
101
- *
102
- * @return {Opaque<"string">} - The token name.
103
- */
104
- export circuit name(): Opaque<"string"> {
105
- Initializable_assertInitialized();
106
- return _name;
107
- }
108
-
109
- /**
110
- * @description Returns the symbol of the token.
111
- *
112
- * @circuitInfo k=10, rows=37
113
- *
114
- * Requirements:
115
- *
116
- * - Contract is initialized.
117
- *
118
- * @return {Opaque<"string">} - The token name.
119
- */
120
- export circuit symbol(): Opaque<"string"> {
121
- Initializable_assertInitialized();
122
- return _symbol;
123
- }
124
-
125
- /**
126
- * @description Returns the number of decimals used to get its user representation.
127
- *
128
- * @circuitInfo k=10, rows=36
129
- *
130
- * Requirements:
131
- *
132
- * - Contract is initialized.
133
- *
134
- * @return {Uint<8>} - The account's token balance.
135
- */
136
- export circuit decimals(): Uint<8> {
137
- Initializable_assertInitialized();
138
- return _decimals;
139
- }
140
-
141
- /**
142
- * @description Returns the value of tokens in existence.
143
- *
144
- * @circuitInfo k=10, rows=36
145
- *
146
- * Requirements:
147
- *
148
- * - Contract is initialized.
149
- *
150
- * @return {Uint<128>} - The total supply of tokens.
151
- */
152
- export circuit totalSupply(): Uint<128> {
153
- Initializable_assertInitialized();
154
- return _totalSupply;
155
- }
156
-
157
- /**
158
- * @description Returns the value of tokens owned by `account`.
159
- *
160
- * @circuitInfo k=10, rows=310
161
- *
162
- * @dev Manually checks if `account` is a key in the map and returns 0 if it is not.
163
- *
164
- * Requirements:
165
- *
166
- * - Contract is initialized.
167
- *
168
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The public key or contract address to query.
169
- * @return {Uint<128>} - The account's token balance.
170
- */
171
- export circuit balanceOf(account: Either<ZswapCoinPublicKey, ContractAddress>): Uint<128> {
172
- Initializable_assertInitialized();
173
- if (!_balances.member(disclose(account))) {
174
- return 0;
175
- }
176
-
177
- return _balances.lookup(disclose(account));
178
- }
179
-
180
- /**
181
- * @description Moves a `value` amount of tokens from the caller's account to `to`.
182
- *
183
- * @circuitInfo k=11, rows=1173
184
- *
185
- * @notice Transfers to contract addresses are currently disallowed until contract-to-contract
186
- * interactions are supported in Compact. This restriction prevents assets from
187
- * being inadvertently locked in contracts that cannot currently handle token receipt.
188
- *
189
- * Requirements:
190
- *
191
- * - Contract is initialized.
192
- * - `to` is not a ContractAddress.
193
- * - `to` is not the zero address.
194
- * - The caller has a balance of at least `value`.
195
- *
196
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transfer, either a user or a contract.
197
- * @param {Uint<128>} value - The amount to transfer.
198
- * @return {Boolean} - As per the IERC20 spec, this MUST return true.
199
- */
200
- export circuit transfer(to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>): Boolean {
201
- Initializable_assertInitialized();
202
- assert(!Utils_isContractAddress(to), "FungibleToken: Unsafe Transfer");
203
- return _unsafeTransfer(to, value);
204
- }
205
-
206
- /**
207
- * @description Unsafe variant of `transfer` which allows transfers to contract addresses.
208
- *
209
- * @circuitInfo k=11, rows=1170
210
- *
211
- * @warning Transfers to contract addresses are considered unsafe because contract-to-contract
212
- * calls are not currently supported. Tokens sent to a contract address may become irretrievable.
213
- * Once contract-to-contract calls are supported, this circuit may be deprecated.
214
- *
215
- * Requirements:
216
- *
217
- * - Contract is initialized.
218
- * - `to` is not the zero address.
219
- * - The caller has a balance of at least `value`.
220
- *
221
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transfer, either a user or a contract.
222
- * @param {Uint<128>} value - The amount to transfer.
223
- * @return {Boolean} - As per the IERC20 spec, this MUST return true.
224
- */
225
- export circuit _unsafeTransfer(to: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>): Boolean {
226
- Initializable_assertInitialized();
227
- const owner = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
228
- _unsafeUncheckedTransfer(owner, to, value);
229
- return true;
230
- }
231
-
232
- /**
233
- * @description Returns the remaining number of tokens that `spender` will be allowed to spend on behalf of `owner`
234
- * through `transferFrom`. This value changes when `approve` or `transferFrom` are called.
235
- *
236
- * @circuitInfo k=10, rows=624
237
- *
238
- * @dev Manually checks if `owner` and `spender` are keys in the map and returns 0 if they are not.
239
- *
240
- * Requirements:
241
- *
242
- * - Contract is initialized.
243
- *
244
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} owner - The public key or contract address of approver.
245
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} spender - The public key or contract address of spender.
246
- * @return {Uint<128>} - The `spender`'s allowance over `owner`'s tokens.
247
- */
248
- export circuit allowance(
249
- owner: Either<ZswapCoinPublicKey, ContractAddress>,
250
- spender: Either<ZswapCoinPublicKey, ContractAddress>
251
- ): Uint<128> {
252
- Initializable_assertInitialized();
253
- if (!_allowances.member(disclose(owner)) || !_allowances.lookup(owner).member(disclose(spender))) {
254
- return 0;
255
- }
256
-
257
- return _allowances.lookup(owner).lookup(disclose(spender));
258
- }
259
-
260
- /**
261
- * @description Sets a `value` amount of tokens as allowance of `spender` over the caller's tokens.
262
- *
263
- * @circuitInfo k=10, rows=452
264
- *
265
- * Requirements:
266
- *
267
- * - Contract is initialized.
268
- * - `spender` is not the zero address.
269
- *
270
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} spender - The Zswap key or ContractAddress that may spend on behalf of the caller.
271
- * @param {Uint<128>} value - The amount of tokens the `spender` may spend.
272
- * @return {Boolean} - Returns a boolean value indicating whether the operation succeeded.
273
- */
274
- export circuit approve(spender: Either<ZswapCoinPublicKey, ContractAddress>, value: Uint<128>): Boolean {
275
- Initializable_assertInitialized();
276
-
277
- const owner = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
278
- _approve(owner, spender, value);
279
- return true;
280
- }
281
-
282
- /**
283
- * @description Moves `value` tokens from `from` to `to` using the allowance mechanism.
284
- * `value` is the deducted from the caller's allowance.
285
- *
286
- * @circuitInfo k=11, rows=1821
287
- *
288
- * @notice Transfers to contract addresses are currently disallowed until contract-to-contract
289
- * interactions are supported in Compact. This restriction prevents assets from
290
- * being inadvertently locked in contracts that cannot currently handle token receipt.
291
- *
292
- * Requirements:
293
- *
294
- * - Contract is initialized.
295
- * - `from` is not the zero address.
296
- * - `from` must have a balance of at least `value`.
297
- * - `to` is not the zero address.
298
- * - `to` is not a ContractAddress.
299
- * - The caller has an allowance of `from`'s tokens of at least `value`.
300
- *
301
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The current owner of the tokens for the transfer, either a user or a contract.
302
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transfer, either a user or a contract.
303
- * @param {Uint<128>} value - The amount to transfer.
304
- * @return {Boolean} - As per the IERC20 spec, this MUST return true.
305
- */
306
- export circuit transferFrom(
307
- from: Either<ZswapCoinPublicKey, ContractAddress>,
308
- to: Either<ZswapCoinPublicKey, ContractAddress>,
309
- value: Uint<128>
310
- ): Boolean {
311
- Initializable_assertInitialized();
312
- assert(!Utils_isContractAddress(to), "FungibleToken: Unsafe Transfer");
313
- return _unsafeTransferFrom(from, to, value);
314
- }
315
-
316
- /**
317
- * @description Unsafe variant of `transferFrom` which allows transfers to contract addresses.
318
- *
319
- * @circuitInfo k=11, rows=1818
320
- *
321
- * @warning Transfers to contract addresses are considered unsafe because contract-to-contract
322
- * calls are not currently supported. Tokens sent to a contract address may become irretrievable.
323
- * Once contract-to-contract calls are supported, this circuit may be deprecated.
324
- *
325
- * Requirements:
326
- *
327
- * - Contract is initialized.
328
- * - `from` is not the zero address.
329
- * - `from` must have a balance of at least `value`.
330
- * - `to` is not the zero address.
331
- * - The caller has an allowance of `from`'s tokens of at least `value`.
332
- *
333
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The current owner of the tokens for the transfer, either a user or a contract.
334
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the transfer, either a user or a contract.
335
- * @param {Uint<128>} value - The amount to transfer.
336
- * @return {Boolean} - As per the IERC20 spec, this MUST return true.
337
- */
338
- export circuit _unsafeTransferFrom(
339
- from: Either<ZswapCoinPublicKey, ContractAddress>,
340
- to: Either<ZswapCoinPublicKey, ContractAddress>,
341
- value: Uint<128>
342
- ): Boolean {
343
- Initializable_assertInitialized();
344
-
345
- const spender = left<ZswapCoinPublicKey, ContractAddress>(ownPublicKey());
346
- _spendAllowance(from, spender, value);
347
- _unsafeUncheckedTransfer(from, to, value);
348
- return true;
349
- }
350
-
351
- /**
352
- * @description Moves a `value` amount of tokens from `from` to `to`.
353
- * This circuit is equivalent to {transfer}, and can be used to
354
- * e.g. implement automatic token fees, slashing mechanisms, etc.
355
- *
356
- * @circuitInfo k=11, rows=1312
357
- *
358
- * @notice Transfers to contract addresses are currently disallowed until contract-to-contract
359
- * interactions are supported in Compact. This restriction prevents assets from
360
- * being inadvertently locked in contracts that cannot currently handle token receipt.
361
- *
362
- * Requirements:
363
- *
364
- * - Contract is initialized.
365
- * - `from` is not be the zero address.
366
- * - `from` must have at least a balance of `value`.
367
- * - `to` must not be the zero address.
368
- * - `to` must not be a ContractAddress.
369
- *
370
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner of the tokens to transfer.
371
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The receipient of the transferred tokens.
372
- * @param {Uint<128>} value - The amount of tokens to transfer.
373
- * @return {[]} - Empty tuple.
374
- */
375
- export circuit _transfer(
376
- from: Either<ZswapCoinPublicKey, ContractAddress>,
377
- to: Either<ZswapCoinPublicKey, ContractAddress>,
378
- value: Uint<128>
379
- ): [] {
380
- Initializable_assertInitialized();
381
- assert(!Utils_isContractAddress(to), "FungibleToken: Unsafe Transfer");
382
- _unsafeUncheckedTransfer(from, to, value);
383
- }
384
-
385
- /**
386
- * @description Unsafe variant of `transferFrom` which allows transfers to contract addresses.
387
- *
388
- * @circuitInfo k=11, rows=1309
389
- *
390
- * @warning Transfers to contract addresses are considered unsafe because contract-to-contract
391
- * calls are not currently supported. Tokens sent to a contract address may become irretrievable.
392
- * Once contract-to-contract calls are supported, this circuit may be deprecated.
393
- *
394
- * Requirements:
395
- *
396
- * - Contract is initialized.
397
- * - `from` is not the zero address.
398
- * - `to` is not the zero address.
399
- *
400
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The owner of the tokens to transfer.
401
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The receipient of the transferred tokens.
402
- * @param {Uint<128>} value - The amount of tokens to transfer.
403
- * @return {[]} - Empty tuple.
404
- */
405
- export circuit _unsafeUncheckedTransfer(
406
- from: Either<ZswapCoinPublicKey, ContractAddress>,
407
- to: Either<ZswapCoinPublicKey, ContractAddress>,
408
- value: Uint<128>
409
- ): [] {
410
- Initializable_assertInitialized();
411
- assert(!Utils_isKeyOrAddressZero(from), "FungibleToken: invalid sender");
412
- assert(!Utils_isKeyOrAddressZero(to), "FungibleToken: invalid receiver");
413
-
414
- _update(from, to, value);
415
- }
416
-
417
- /**
418
- * @description Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
419
- * (or `to`) is the zero address.
420
- * @dev Checks for a mint overflow in order to output a more readable error message.
421
- *
422
- * @circuitInfo k=11, rows=1305
423
- *
424
- * Requirements:
425
- *
426
- * - Contract is initialized.
427
- *
428
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} from - The original owner of the tokens moved (which is 0 if tokens are minted).
429
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} to - The recipient of the tokens moved (which is 0 if tokens are burned).
430
- * @param {Uint<128>} value - The amount of tokens moved from `from` to `to`.
431
- * @return {[]} - Empty tuple.
432
- */
433
- circuit _update(
434
- from: Either<ZswapCoinPublicKey, ContractAddress>,
435
- to: Either<ZswapCoinPublicKey, ContractAddress>,
436
- value: Uint<128>
437
- ): [] {
438
- Initializable_assertInitialized();
439
- if (Utils_isKeyOrAddressZero(disclose(from))) {
440
- // Mint
441
- const MAX_UINT128 = 340282366920938463463374607431768211455;
442
- assert(MAX_UINT128 - _totalSupply >= value, "FungibleToken: arithmetic overflow");
443
-
444
- _totalSupply = disclose(_totalSupply + value as Uint<128>);
445
- } else {
446
- const fromBal = balanceOf(from);
447
- assert(fromBal >= value, "FungibleToken: insufficient balance");
448
- _balances.insert(disclose(from), disclose(fromBal - value as Uint<128>));
449
- }
450
-
451
- if (Utils_isKeyOrAddressZero(disclose(to))) {
452
- // Burn
453
- _totalSupply = disclose(_totalSupply - value as Uint<128>);
454
- } else {
455
- const toBal = balanceOf(to);
456
- _balances.insert(disclose(to), disclose(toBal + value as Uint<128>));
457
- }
458
- }
459
-
460
- /**
461
- * @description Creates a `value` amount of tokens and assigns them to `account`,
462
- * by transferring it from the zero address. Relies on the `update` mechanism.
463
- *
464
- * @circuitInfo k=10, rows=752
465
- *
466
- * @notice Transfers to contract addresses are currently disallowed until contract-to-contract
467
- * interactions are supported in Compact. This restriction prevents assets from
468
- * being inadvertently locked in contracts that cannot currently handle token receipt.
469
- *
470
- * Requirements:
471
- *
472
- * - Contract is initialized.
473
- * - `to` is not a ContractAddress.
474
- * - `account` is not the zero address.
475
- *
476
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The recipient of tokens minted.
477
- * @param {Uint<128>} value - The amount of tokens minted.
478
- * @return {[]} - Empty tuple.
479
- */
480
- export circuit _mint(
481
- account: Either<ZswapCoinPublicKey, ContractAddress>,
482
- value: Uint<128>
483
- ): [] {
484
- Initializable_assertInitialized();
485
- assert(!Utils_isContractAddress(account), "FungibleToken: Unsafe Transfer");
486
- _unsafeMint(account, value);
487
- }
488
-
489
- /**
490
- * @description Unsafe variant of `_mint` which allows transfers to contract addresses.
491
- *
492
- * @circuitInfo k=10, rows=749
493
- *
494
- * @warning Transfers to contract addresses are considered unsafe because contract-to-contract
495
- * calls are not currently supported. Tokens sent to a contract address may become irretrievable.
496
- * Once contract-to-contract calls are supported, this circuit may be deprecated.
497
- *
498
- * Requirements:
499
- *
500
- * - Contract is initialized.
501
- * - `account` is not the zero address.
502
- *
503
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The recipient of tokens minted.
504
- * @param {Uint<128>} value - The amount of tokens minted.
505
- * @return {[]} - Empty tuple.
506
- */
507
- export circuit _unsafeMint(
508
- account: Either<ZswapCoinPublicKey, ContractAddress>,
509
- value: Uint<128>
510
- ): [] {
511
- Initializable_assertInitialized();
512
- assert(!Utils_isKeyOrAddressZero(account), "FungibleToken: invalid receiver");
513
- _update(burnAddress(), account, value);
514
- }
515
-
516
- /**
517
- * @description Destroys a `value` amount of tokens from `account`, lowering the total supply.
518
- * Relies on the `_update` mechanism.
519
- *
520
- * @circuitInfo k=10, rows=773
521
- *
522
- * Requirements:
523
- *
524
- * - Contract is initialized.
525
- * - `account` is not the zero address.
526
- * - `account` must have at least a balance of `value`.
527
- *
528
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} account - The target owner of tokens to burn.
529
- * @param {Uint<128>} value - The amount of tokens to burn.
530
- * @return {[]} - Empty tuple.
531
- */
532
- export circuit _burn(
533
- account: Either<ZswapCoinPublicKey, ContractAddress>,
534
- value: Uint<128>
535
- ): [] {
536
- Initializable_assertInitialized();
537
- assert(!Utils_isKeyOrAddressZero(account), "FungibleToken: invalid sender");
538
- _update(account, burnAddress(), value);
539
- }
540
-
541
- /**
542
- * @description Sets `value` as the allowance of `spender` over the `owner`'s tokens.
543
- * This circuit is equivalent to `approve`, and can be used to
544
- *
545
- * @circuitInfo k=10, rows=583
546
- *
547
- * e.g. set automatic allowances for certain subsystems, etc.
548
- *
549
- * Requirements:
550
- *
551
- * - Contract is initialized.
552
- * - `owner` is not the zero address.
553
- * - `spender` is not the zero address.
554
- *
555
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} owner - The owner of the tokens.
556
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} spender - The spender of the tokens.
557
- * @param {Uint<128>} value - The amount of tokens `spender` may spend on behalf of `owner`.
558
- * @return {[]} - Empty tuple.
559
- */
560
- export circuit _approve(
561
- owner: Either<ZswapCoinPublicKey, ContractAddress>,
562
- spender: Either<ZswapCoinPublicKey, ContractAddress>,
563
- value: Uint<128>
564
- ): [] {
565
- Initializable_assertInitialized();
566
- assert(!Utils_isKeyOrAddressZero(owner), "FungibleToken: invalid owner");
567
- assert(!Utils_isKeyOrAddressZero(spender), "FungibleToken: invalid spender");
568
- if (!_allowances.member(disclose(owner))) {
569
- // If owner doesn't exist, create and insert a new sub-map directly
570
- _allowances.insert(disclose(owner), default<Map<Either<ZswapCoinPublicKey, ContractAddress>, Uint<128>>>);
571
- }
572
- _allowances.lookup(owner).insert(disclose(spender), disclose(value));
573
- }
574
-
575
- /**
576
- * @description Updates `owner`'s allowance for `spender` based on spent `value`.
577
- * Does not update the allowance value in case of infinite allowance.
578
- *
579
- * @circuitInfo k=10, rows=931
580
- *
581
- * Requirements:
582
- *
583
- * - Contract is initialized.
584
- * - `spender` must have at least an allowance of `value` from `owner`.
585
- *
586
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} owner - The owner of the tokens.
587
- * @param {Either<ZswapCoinPublicKey, ContractAddress>} spender - The spender of the tokens.
588
- * @param {Uint<128>} value - The amount of token allowance to spend.
589
- * @return {[]} - Empty tuple.
590
- */
591
- export circuit _spendAllowance(
592
- owner: Either<ZswapCoinPublicKey, ContractAddress>,
593
- spender: Either<ZswapCoinPublicKey, ContractAddress>,
594
- value: Uint<128>
595
- ): [] {
596
- Initializable_assertInitialized();
597
- assert((_allowances.member(disclose(owner)) && _allowances.lookup(owner).member(disclose(spender))), "FungibleToken: insufficient allowance");
598
-
599
- const currentAllowance = _allowances.lookup(owner).lookup(disclose(spender));
600
- const MAX_UINT128 = 340282366920938463463374607431768211455;
601
- if (currentAllowance < MAX_UINT128) {
602
- assert(currentAllowance >= value, "FungibleToken: insufficient allowance");
603
- _approve(owner, spender, currentAllowance - value as Uint<128>);
604
- }
605
- }
606
- }