neo-devpack-solidity 0.22.0

Production-focused Solidity-to-NeoVM compilation system
Documentation
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

/**
 * @title NEP-17 Fungible Token Standard
 * @dev Complete implementation of Neo N3 NEP-17 standard for Solidity
 * @author Jimmy <jimmy@r3e.network>
 * 
 * NEP-17 is Neo's enhanced fungible token standard, providing:
 * - Standard ERC-20 compatibility
 * - Neo-specific features (onNEP17Payment callback)
 * - Advanced transfer capabilities
 * - Integration with Neo native tokens
 * - Event system compatible with Neo Runtime.Notify
 */

import "../contracts/FrameworkBase.sol";
import "../libraries/Neo.sol";
import "../libraries/Runtime.sol";
import "../libraries/Storage.sol";

/// @dev Neo N3 Any type - represents any stack item type in NeoVM
type Any is bytes;

/**
 * @title INEP17
 * @dev Interface for NEP-17 fungible token standard
 */
interface INEP17 {
    // Standard NEP-17 functions
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint8);
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    // NEP-17 `data` is an unconstrained StackItem (Neo ABI type: Any).
    // This devpack uses the Neo DevPack for Solidity `Any` type to accurately reflect the standard.
    function transfer(address from, address to, uint256 amount, Any calldata data) external returns (bool);
    
    // Events
    event Transfer(address indexed from, address indexed to, uint256 amount);
}

/**
 * @title INEP17Receiver
 * @dev Interface for contracts that can receive NEP-17 tokens
 */
interface INEP17Receiver {
    function onNEP17Payment(address from, uint256 amount, Any calldata data) external;
}

/**
 * @title NEP17
 * @dev Complete NEP-17 token implementation with Neo N3 integration
 */
contract NEP17 is INEP17, FrameworkBase {
    using Neo for *;
    using Runtime for *;

    // Neo N3 Oracle native contract hash.
    address private constant ORACLE_NATIVE_CONTRACT = 0xfe924b7cfe89ddd271abaf7210a80a7e11178758;
    
    // Token metadata
    string private _name;
    string private _symbol;
    uint8 private _decimals;
    uint256 private _totalSupply;
    
    // Balances and allowances
    mapping(address => uint256) private _balances;
    mapping(address => mapping(address => uint256)) private _allowances;
    
    // NEP-17 specific features
    bool private _transfersEnabled = true;
    address private _minter;
    uint256 private _maxSupply;
    uint256 private _conditionalTransferNonce;

    // Multi-signature authorization: only owner-approved signers may move the
    // contract's own (escrowed) token pool via multiSigTransfer, and at least
    // `_multisigThreshold` of them must witness the transaction.
    mapping(address => bool) private _multisigSigners;
    uint256 private _multisigThreshold;

    // Events (NEP-17 compatible)
    event Transfer(address indexed from, address indexed to, uint256 amount);
    event Approval(address indexed owner, address indexed spender, uint256 amount);
    event Mint(address indexed to, uint256 amount);
    event Burn(address indexed from, uint256 amount);
    
    // NEP-17 specific events
    event TransfersEnabled();
    event TransfersDisabled();
    event MinterChanged(address indexed oldMinter, address indexed newMinter);
    event MaxSupplySet(uint256 maxSupply);

    // Extended events
    event EmergencyPause(address indexed caller, uint256 timestamp);
    event EmergencyUnpause(address indexed caller, uint256 timestamp);
    event TimelockCreated(
        bytes32 indexed timelockId,
        address indexed from,
        address indexed to,
        uint256 amount,
        uint256 releaseTime
    );
    event TimelockClaimed(bytes32 indexed timelockId, address indexed to, uint256 amount);
    event ConditionalTransferCreated(
        bytes32 indexed requestId,
        address indexed from,
        address indexed to,
        uint256 amount
    );
    event ConditionalTransferExecuted(address indexed from, address indexed to, uint256 amount);
    event ConditionalTransferFailed(address indexed from, uint256 amount);
    
    // Custom errors
    error NEP17InsufficientBalance(address account, uint256 balance, uint256 needed);
    error NEP17InvalidReceiver(address receiver);
    error NEP17TransfersDisabled();
    error NEP17ExceedsMaxSupply(uint256 amount, uint256 maxSupply);
    error NEP17InvalidAmount(uint256 amount);
    error NEP17NotMinter(address caller);
    
    // Modifiers
    modifier whenTransfersEnabled() {
        if (!_transfersEnabled) revert NEP17TransfersDisabled();
        _;
    }
    
    modifier onlyMinter() {
        if (msg.sender != _minter) revert NEP17NotMinter(msg.sender);
        _;
    }
    
    modifier validAmount(uint256 amount) {
        if (amount == 0) revert NEP17InvalidAmount(amount);
        _;
    }
    
    modifier validReceiver(address to) {
        if (to == address(0)) revert NEP17InvalidReceiver(to);
        _;
    }
    
    /**
     * @dev Constructor
     */
    constructor(
        string memory name_,
        string memory symbol_,
        uint8 decimals_,
        uint256 initialSupply,
        uint256 maxSupply_
    ) FrameworkBase() {
        require(bytes(name_).length > 0, "NEP17: name cannot be empty");
        require(bytes(symbol_).length > 0, "NEP17: symbol cannot be empty");
        require(decimals_ <= 18, "NEP17: decimals cannot exceed 18");
        
        // A non-zero max supply must accommodate the initial mint. `_mint`
        // (used below) does not enforce the cap — unlike the public `mint()` —
        // so guard the initial supply here to keep the cap invariant.
        require(
            maxSupply_ == 0 || initialSupply <= maxSupply_,
            "NEP17: initial supply exceeds max supply"
        );

        _name = name_;
        _symbol = symbol_;
        _decimals = decimals_;
        _minter = msg.sender;
        _maxSupply = maxSupply_;

        if (initialSupply > 0) {
            _mint(msg.sender, initialSupply);
        }
    }
    
    // ========== View Functions ==========
    
    /**
     * @dev Returns the name of the token
     */
    function name() public view returns (string memory) {
        return _name;
    }
    
    /**
     * @dev Returns the symbol of the token
     */
    function symbol() public view override returns (string memory) {
        return _symbol;
    }
    
    /**
     * @dev Returns the number of decimals
     */
    function decimals() public view override returns (uint8) {
        return _decimals;
    }
    
    /**
     * @dev Returns the total supply
     */
    function totalSupply() public view override returns (uint256) {
        return _totalSupply;
    }
    
    /**
     * @dev Returns the balance of an account
     */
    function balanceOf(address account) public view override returns (uint256) {
        return _balances[account];
    }
    
    /**
     * @dev Returns the allowance
     */
    function allowance(address owner, address spender) public view returns (uint256) {
        return _allowances[owner][spender];
    }
    
    /**
     * @dev Returns if transfers are enabled
     */
    function transfersEnabled() public view returns (bool) {
        return _transfersEnabled;
    }
    
    /**
     * @dev Returns the minter address
     */
    function minter() public view returns (address) {
        return _minter;
    }
    
    /**
     * @dev Returns the maximum supply
     */
    function maxSupply() public view returns (uint256) {
        return _maxSupply;
    }
    
    // ========== Transfer Functions ==========
    
    /**
     * @dev NEP-17 transfer function
     */
    function transfer(
        address from,
        address to,
        uint256 amount,
        Any calldata data
    ) public override whenTransfersEnabled validReceiver(to) returns (bool) {
        // NEP-17 requires a zero-amount transfer to be processed normally
        // (emit Transfer, run the receiver callback, return true) — so
        // `validAmount` is intentionally NOT applied here; it stays on
        // mint/burn where a non-zero amount is a legitimate business rule.
        // Authorization: the owner (acting as the direct sender or via witness)
        // or a spender holding sufficient allowance. Cache the witness result so
        // it is consulted once for both the check and the allowance accounting.
        //
        // M-DEV3 note — this is a HYBRID authorization model that mixes
        // NEP-17 witness semantics with ERC-20 allowance semantics:
        //   1. The owner authorizes either by being the direct caller OR by
        //      passing `Runtime.checkWitness(from)` (Neo N3 witness check).
        //   2. OR any address holding `_allowances[from][spender] >= amount`
        //      may move the tokens WITHOUT a witness check (pure ERC-20 path).
        // This is stricter than ERC-20 (adds the witness option) but allows a
        // non-witnessed, allowance-only path that strict NEP-17 does not. The
        // hybrid is intentional for Solidity-source compatibility (existing
        // approve/transferFrom contracts keep working), but callers relying on
        // a strict NEP-17 "only the owner or a witness holder can move tokens"
        // invariant should be aware of this allowance path.
        bool ownerAuthorized = from == msg.sender || Runtime.checkWitness(from);
        require(
            ownerAuthorized || _allowances[from][msg.sender] >= amount,
            "NEP17: unauthorized transfer"
        );

        _transfer(from, to, amount, data);

        // Consume allowance ONLY when the transfer was authorized via an
        // approval (i.e. the spender is acting on the owner's behalf), never when
        // the owner authorized directly. Decrementing on the owner-authorized
        // path would compute `_allowances[from][msg.sender] - amount`, which
        // underflows (Panic 0x11) and reverts when the allowance is below
        // `amount` — e.g. a witness-authorized transfer with zero allowance.
        if (!ownerAuthorized && _allowances[from][msg.sender] != type(uint256).max) {
            require(
                _allowances[from][msg.sender] >= amount,
                "NEP17: insufficient allowance"
            );
            _approve(from, msg.sender, _allowances[from][msg.sender] - amount);
        }

        return true;
    }
    
    /**
     * @dev Standard ERC-20 transfer
     */
    function transfer(address to, uint256 amount) public returns (bool) {
        return transfer(msg.sender, to, amount, "");
    }
    
    /**
     * @dev Transfer from (ERC-20 compatibility)
     */
    function transferFrom(address from, address to, uint256 amount) public returns (bool) {
        return transfer(from, to, amount, "");
    }
    
    /**
     * @dev Approve spender
     */
    function approve(address spender, uint256 amount) public returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }
    
    /**
     * @dev Increase allowance
     */
    function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
        _approve(msg.sender, spender, _allowances[msg.sender][spender] + addedValue);
        return true;
    }
    
    /**
     * @dev Decrease allowance
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
        uint256 currentAllowance = _allowances[msg.sender][spender];
        require(currentAllowance >= subtractedValue, "NEP17: decreased allowance below zero");
        _approve(msg.sender, spender, currentAllowance - subtractedValue);
        return true;
    }
    
    // ========== Minting and Burning ==========
    
    /**
     * @dev Mint tokens
     */
    function mint(address to, uint256 amount) public onlyMinter validReceiver(to) validAmount(amount) {
        if (_maxSupply > 0 && _totalSupply + amount > _maxSupply) {
            revert NEP17ExceedsMaxSupply(amount, _maxSupply);
        }
        
        _mint(to, amount);
    }
    
    /**
     * @dev Burn tokens
     */
    function burn(uint256 amount) public validAmount(amount) {
        _burn(msg.sender, amount);
    }
    
    /**
     * @dev Burn tokens from account (with allowance)
     */
    function burnFrom(address from, uint256 amount) public validAmount(amount) {
        uint256 currentAllowance = _allowances[from][msg.sender];
        require(currentAllowance >= amount, "NEP17: burn amount exceeds allowance");
        
        _burn(from, amount);
        _approve(from, msg.sender, currentAllowance - amount);
    }
    
    // ========== Admin Functions ==========
    
    /**
     * @dev Owner: authorize/deauthorize a multi-signature signer for the pool.
     */
    function setMultisigSigner(address signer, bool allowed) public onlyOwner {
        require(signer != address(0), "NEP17: invalid signer");
        _multisigSigners[signer] = allowed;
    }

    /**
     * @dev Owner: set the minimum number of authorized witnesses required for
     * a multiSigTransfer (must be at least 2).
     */
    function setMultisigThreshold(uint256 threshold) public onlyOwner {
        require(threshold >= 2, "NEP17: threshold must be >= 2");
        _multisigThreshold = threshold;
    }

    /**
     * @dev Enable transfers
     */
    function enableTransfers() public onlyOwner {
        require(!_transfersEnabled, "NEP17: transfers already enabled");
        _transfersEnabled = true;
        emit TransfersEnabled();
    }

    /**
     * @dev Disable transfers
     */
    function disableTransfers() public onlyOwner {
        require(_transfersEnabled, "NEP17: transfers already disabled");
        _transfersEnabled = false;
        emit TransfersDisabled();
    }
    
    /**
     * @dev Change minter
     */
    function changeMinter(address newMinter) public onlyOwner {
        require(newMinter != address(0), "NEP17: new minter is zero address");
        address oldMinter = _minter;
        _minter = newMinter;
        emit MinterChanged(oldMinter, newMinter);
    }
    
    /**
     * @dev Set maximum supply
     */
    function setMaxSupply(uint256 newMaxSupply) public onlyOwner {
        require(newMaxSupply >= _totalSupply, "NEP17: max supply below current supply");
        _maxSupply = newMaxSupply;
        emit MaxSupplySet(newMaxSupply);
    }
    
    // ========== Batch Operations ==========
    
    /**
     * @dev Batch transfer to multiple recipients
     */
    function batchTransfer(
        address[] memory recipients,
        uint256[] memory amounts,
        bytes[] memory data
    ) public whenTransfersEnabled returns (bool) {
        require(recipients.length == amounts.length, "NEP17: array length mismatch");
        require(recipients.length == data.length, "NEP17: array length mismatch");
        require(recipients.length > 0, "NEP17: empty arrays");
        require(recipients.length <= 100, "NEP17: too many recipients");
        
        for (uint256 i = 0; i < recipients.length; i++) {
            transfer(msg.sender, recipients[i], amounts[i], data[i]);
        }
        
        return true;
    }
    
    /**
     * @dev Batch mint to multiple recipients
     */
    function batchMint(address[] memory recipients, uint256[] memory amounts) 
        public 
        onlyMinter 
        returns (bool) 
    {
        require(recipients.length == amounts.length, "NEP17: array length mismatch");
        require(recipients.length > 0, "NEP17: empty arrays");
        require(recipients.length <= 100, "NEP17: too many recipients");
        
        for (uint256 i = 0; i < recipients.length; i++) {
            mint(recipients[i], amounts[i]);
        }
        
        return true;
    }
    
    // ========== Internal Functions ==========
    
    /**
     * @dev Internal transfer function
     */
    function _transfer(address from, address to, uint256 amount, Any memory data) internal {
        uint256 fromBalance = _balances[from];
        if (fromBalance < amount) {
            revert NEP17InsufficientBalance(from, fromBalance, amount);
        }
        
        unchecked {
            _balances[from] = fromBalance - amount;
        }
        _balances[to] += amount;
        
        emit Transfer(from, to, amount);

        // Call onNEP17Payment if the recipient is a *different* contract.
        // Escrowing to `address(this)` (timelock / conditional / staking /
        // scheduled transfers all move tokens to self) is an internal
        // bookkeeping move: this contract does not implement onNEP17Payment,
        // so invoking the callback on itself would fault and revert the whole
        // escrow-in leg. Skipping self also avoids spurious self-reentrancy.
        if (to != address(this) && to.code.length > 0) {
            try INEP17Receiver(to).onNEP17Payment(from, amount, data) {
                // Success
            } catch {
                // Revert if recipient doesn't implement interface correctly
                revert NEP17InvalidReceiver(to);
            }
        }
    }
    
    /**
     * @dev Internal mint function
     */
    function _mint(address to, uint256 amount) internal {
        _totalSupply += amount;
        _balances[to] += amount;
        
        emit Transfer(address(0), to, amount);
        emit Mint(to, amount);
        
        // Call onNEP17Payment if recipient is a contract
        if (to.code.length > 0) {
            try INEP17Receiver(to).onNEP17Payment(address(0), amount, "") {
                // Success
            } catch {
                // Mint can proceed even if recipient doesn't implement interface
            }
        }
    }
    
    /**
     * @dev Internal burn function
     */
    function _burn(address from, uint256 amount) internal {
        uint256 accountBalance = _balances[from];
        if (accountBalance < amount) {
            revert NEP17InsufficientBalance(from, accountBalance, amount);
        }
        
        unchecked {
            _balances[from] = accountBalance - amount;
        }
        // Keep totalSupply decrement checked for defense-in-depth
        _totalSupply -= amount;

        emit Transfer(from, address(0), amount);
        emit Burn(from, amount);
    }
    
    /**
     * @dev Internal approve function
     */
    function _approve(address owner, address spender, uint256 amount) internal {
        require(owner != address(0), "NEP17: approve from zero address");
        require(spender != address(0), "NEP17: approve to zero address");
        
        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }
    
    // ========== Neo Integration Functions ==========
    
    // NOTE: getHoldersCount() was removed because Solidity mappings use
    // keccak256-derived storage slots, not prefix-based keys. Storage.find()
    // with a "balance" prefix cannot iterate over mapping entries. If your
    // contract needs holder enumeration, maintain an explicit address[] array
    // or use the Neo-specific Storage.put()/find() API directly instead of
    // the native `mapping` type.
    
    /**
     * @dev Get token info for Neo blockchain
     */
    function getTokenInfo() public view virtual returns (
        string memory tokenName,
        string memory tokenSymbol,
        uint8 tokenDecimals,
        uint256 tokenTotalSupply,
        uint256 tokenMaxSupply,
        address tokenMinter,
        bool tokenTransfersEnabled
    ) {
        return (_name, _symbol, _decimals, _totalSupply, _maxSupply, _minter, _transfersEnabled);
    }
    
    /**
     * @dev Get contract metadata for Neo
     */
    function getContractMetadata() public view virtual returns (
        string memory standard,
        string memory name,
        string memory version,
        string memory author
    ) {
        return (
            "NEP-17",
            "Neo N3 Fungible Token",
            "1.0.0",
            "Jimmy <jimmy@r3e.network>"
        );
    }
    
    // ========== Emergency Functions ==========
    
    /**
     * @dev Emergency pause (disable transfers)
     */
    function emergencyPause() public virtual onlyOwner {
        disableTransfers();
        emit EmergencyPause(msg.sender, block.timestamp);
    }
    
    /**
     * @dev Emergency unpause (enable transfers)
     */
    function emergencyUnpause() public onlyOwner {
        enableTransfers();
        emit EmergencyUnpause(msg.sender, block.timestamp);
    }
    
    // ========== Advanced Features ==========
    
    /**
     * @dev Time-locked transfer
     */
    function transferWithTimelock(
        address to,
        uint256 amount,
        uint256 releaseTime
    ) public whenTransfersEnabled validReceiver(to) validAmount(amount) {
        require(releaseTime > block.timestamp, "NEP17: release time must be in future");
        
        // Store the time-locked transfer
        bytes32 timelockId = keccak256(abi.encode(msg.sender, to, amount, releaseTime, block.timestamp));
        
        // Transfer to this contract temporarily
        _transfer(msg.sender, address(this), amount, "");
        
        // Store timelock info
        Storage.put(
            abi.encode("timelock", timelockId),
            abi.encode(msg.sender, to, amount, releaseTime)
        );
        
        // Emit event
        emit TimelockCreated(timelockId, msg.sender, to, amount, releaseTime);
    }
    
    /**
     * @dev Claim time-locked tokens
     */
    function claimTimelock(bytes32 timelockId) public {
        bytes memory timelockData = Storage.get(abi.encode("timelock", timelockId));
        require(timelockData.length > 0, "NEP17: timelock not found");
        
        (address from, address to, uint256 amount, uint256 releaseTime) = 
            abi.decode(timelockData, (address, address, uint256, uint256));
        
        require(block.timestamp >= releaseTime, "NEP17: timelock not yet expired");
        require(msg.sender == to, "NEP17: only recipient can claim");
        
        // Delete timelock
        Storage.remove(abi.encode("timelock", timelockId));
        
        // Transfer tokens
        _transfer(address(this), to, amount, "");
        
        // Emit event
        emit TimelockClaimed(timelockId, to, amount);
    }
    
    /**
     * @dev Multi-signature transfer
     */
    function multiSigTransfer(
        address to,
        uint256 amount,
        address[] memory signers,
        bytes[] memory signatures
    ) public whenTransfersEnabled validReceiver(to) validAmount(amount) {
        require(signers.length == signatures.length, "NEP17: array length mismatch");
        require(signers.length >= 2, "NEP17: minimum 2 signers required");
        require(signers.length <= 10, "NEP17: maximum 10 signers allowed");
        // The threshold must be configured by the owner; an unconfigured (zero)
        // threshold disables the pool transfer entirely (fail closed).
        require(_multisigThreshold >= 2, "NEP17: multisig not configured");
        require(signers.length >= _multisigThreshold, "NEP17: below threshold");

        // Off-chain signatures are collected by clients, but on-chain authorization
        // is enforced via Neo witness checks for each declared signer.
        signatures;

        for (uint256 i = 0; i < signers.length; i++) {
            address signer = signers[i];
            require(signer != address(0), "NEP17: invalid signer");

            // CRITICAL: the signer must be an OWNER-AUTHORIZED pool signer.
            // Without this, any caller could supply two arbitrary accounts they
            // control, witness the tx, and drain the contract's escrowed pool.
            require(_multisigSigners[signer], "NEP17: signer not authorized");

            // Prevent duplicate signers from satisfying quorum multiple times.
            for (uint256 j = 0; j < i; j++) {
                require(signers[j] != signer, "NEP17: duplicate signer");
            }

            require(Runtime.checkWitness(signer), "NEP17: signer witness missing");
        }
        
        // Execute transfer from multisig pool
        _transfer(address(this), to, amount, abi.encode("multisig", signers));
    }
    
    /**
     * @dev Conditional transfer based on oracle data
     */
    function conditionalTransfer(
        address to,
        uint256 amount,
        string memory oracleUrl,
        string memory condition
    ) public whenTransfersEnabled validReceiver(to) validAmount(amount) {
        // Escrow tokens in contract until condition is met
        _transfer(msg.sender, address(this), amount, "");
        
        // Create request id and escrow record.
        // Include a monotonic nonce to avoid collisions for repeated same-params requests.
        uint256 nonce = _conditionalTransferNonce++;
        bytes32 requestId = keccak256(abi.encode(msg.sender, to, amount, condition, block.timestamp, nonce));

        // Store pending transfer by local request id so callbacks can be validated and replay-protected.
        Storage.put(
            abi.encode("conditional_transfer", requestId),
            abi.encode(msg.sender, to, amount)
        );

        // Pass only the local request id through oracle userData; callback must load escrowed state.
        Syscalls.oracleRequest(
            oracleUrl,
            condition,
            "conditionalTransferCallback",
            abi.encode(requestId),
            10000000
        );

        emit ConditionalTransferCreated(requestId, msg.sender, to, amount);
    }
    
    /**
     * @dev Oracle callback for conditional transfers
     */
    // The Neo N3 Oracle native contract invokes the registered callback with the
    // fixed argument order `(string url, bytes userData, int code, bytes result)`.
    // The previous declaration had these in the wrong order, so `userData` (which
    // carries our local request id) was read from the wrong slot and the escrowed
    // tokens could never be released — permanently locking them.
    function conditionalTransferCallback(
        string calldata url,
        bytes calldata userData,
        uint256 code,
        bytes calldata result
    ) external {
        url; // oracle request URL (reserved for diagnostics)
        require(msg.sender == ORACLE_NATIVE_CONTRACT, "NEP17: unauthorized callback");

        bytes32 localRequestId = abi.decode(userData, (bytes32));
        bytes memory pending = Storage.get(abi.encode("conditional_transfer", localRequestId));
        require(pending.length > 0, "NEP17: conditional transfer not found");

        (address from, address to, uint256 amount) = abi.decode(pending, (address, address, uint256));

        // Consume request before state transitions to prevent callback replay.
        Storage.remove(abi.encode("conditional_transfer", localRequestId));

        // The oracle `result` is the filtered response body, NOT necessarily a
        // 32-byte ABI word. `abi.decode(result, (bool))` on a shorter body
        // Panics (0x41) and would revert this callback AFTER the request record
        // was consumed above — permanently stranding the escrow. Short-circuit
        // on `result.length >= 32` so an unparsable/short result falls through
        // to the refund branch instead of reverting.
        if (code == 0 && result.length >= 32 && abi.decode(result, (bool))) {
            _transfer(address(this), to, amount, "");
            emit ConditionalTransferExecuted(from, to, amount);
        } else {
            // Refund escrowed tokens on oracle errors or unmet conditions.
            _transfer(address(this), from, amount, "");
            emit ConditionalTransferFailed(from, amount);
        }
    }
    
    // NOTE: getAllBalances() was removed for the same reason as getHoldersCount().
    // Solidity mappings use keccak256-derived storage slots and cannot be iterated
    // via Storage.find() with a prefix. See the comment above getHoldersCount's
    // former location for alternatives.
    
    /**
     * @dev NEP-17 specific metadata
     */
    function nep17Metadata() public view returns (
        string memory standard,
        bytes memory logo,
        string memory website,
        string memory description
    ) {
        return (
            "NEP-17",
            "", // Logo data (optional)
            "https://r3e.network",
            string(abi.encodePacked("NEP-17 token: ", _name))
        );
    }
}