@evvm/testnet-contracts 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +195 -17
  2. package/contracts/evvm/Evvm.sol +13 -10
  3. package/contracts/evvm/lib/EvvmStorage.sol +2 -0
  4. package/contracts/evvm/lib/SignatureUtils.sol +12 -13
  5. package/contracts/nameService/NameService.sol +11 -8
  6. package/contracts/nameService/lib/ErrorsLib.sol +1 -1
  7. package/contracts/nameService/lib/SignatureUtils.sol +38 -39
  8. package/contracts/p2pSwap/P2PSwap.sol +14 -382
  9. package/contracts/p2pSwap/lib/SignatureUtils.sol +15 -16
  10. package/contracts/staking/Estimator.sol +4 -4
  11. package/contracts/staking/Staking.sol +28 -17
  12. package/contracts/staking/lib/ErrorsLib.sol +0 -1
  13. package/contracts/staking/lib/SignatureUtils.sol +6 -34
  14. package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +3 -3
  15. package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +3 -3
  16. package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +7 -7
  17. package/interfaces/IStaking.sol +1 -1
  18. package/library/Erc191TestBuilder.sol +57 -57
  19. package/library/EvvmService.sol +104 -0
  20. package/library/primitives/Math.sol +415 -0
  21. package/library/primitives/SignatureRecover.sol +42 -0
  22. package/library/utils/AdvancedStrings.sol +89 -0
  23. package/library/utils/SignatureUtil.sol +29 -0
  24. package/library/utils/service/AsyncNonceService.sol +34 -0
  25. package/library/utils/service/MakeServicePaymentOnEvvm.sol +49 -0
  26. package/library/utils/service/StakingServiceUtils.sol +37 -0
  27. package/library/utils/service/SyncNonceService.sol +18 -0
  28. package/package.json +16 -4
  29. package/contracts/evvm/EvvmLegacy.sol +0 -1553
  30. package/library/AdvancedStrings.sol +0 -77
  31. package/library/SignatureRecover.sol +0 -140
  32. package/library/StakingServiceHooks.sol +0 -116
@@ -38,69 +38,36 @@ pragma solidity ^0.8.0;
38
38
 
39
39
  import {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
40
40
  import {Staking} from "@evvm/testnet-contracts/contracts/staking/Staking.sol";
41
- import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
42
- import {SignatureRecover} from "@evvm/testnet-contracts/library/SignatureRecover.sol";
43
- import {SignatureUtils} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/SignatureUtils.sol";
44
- import {AdvancedStrings} from "@evvm/testnet-contracts/library/AdvancedStrings.sol";
41
+ import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
45
42
  import {EvvmStructs} from "@evvm/testnet-contracts/contracts/evvm/lib/EvvmStructs.sol";
46
- import {StakingServiceHooks} from "@evvm/testnet-contracts/library/StakingServiceHooks.sol";
47
-
48
- contract P2PSwap is StakingServiceHooks {
49
- using SignatureRecover for *;
50
- using AdvancedStrings for *;
43
+ import {StakingServiceUtils} from "@evvm/testnet-contracts/library/utils/service/StakingServiceUtils.sol";
44
+ import {SignatureUtils} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/SignatureUtils.sol";
51
45
 
52
- /// @notice Current contract owner with administrative privileges
46
+ contract P2PSwap is StakingServiceUtils {
53
47
  address owner;
54
- /// @notice Proposed new owner address pending acceptance
55
48
  address owner_proposal;
56
- /// @notice Timestamp when the proposed owner change can be accepted
57
49
  uint256 owner_timeToAccept;
58
50
 
59
- /// @notice Address of the EVVM core contract for payment processing
60
51
  address evvmAddress;
61
- /// @notice Address of the Staking contract for service staking functionality
62
52
  address stakingAddress;
63
53
 
64
- /// @notice Constant address representing the MATE token (Principal Token)
65
54
  address constant MATE_TOKEN_ADDRESS =
66
55
  0x0000000000000000000000000000000000000001;
67
- /// @notice Constant address representing native ETH
68
56
  address constant ETH_ADDRESS = 0x0000000000000000000000000000000000000000;
69
57
 
70
- /**
71
- * @notice Market metadata containing token pair and order tracking information
72
- * @param tokenA Address of the first token in the trading pair
73
- * @param tokenB Address of the second token in the trading pair
74
- * @param maxSlot Maximum order ID ever created in this market
75
- * @param ordersAvailable Current number of active orders in the market
76
- */
77
58
  struct MarketInformation {
78
59
  address tokenA;
79
60
  address tokenB;
80
61
  uint256 maxSlot;
81
62
  uint256 ordersAvailable;
82
63
  }
83
-
84
- /**
85
- * @notice Individual order details within a market
86
- * @param seller Address of the user who created the order
87
- * @param amountA Amount of tokenA the seller is offering
88
- * @param amountB Amount of tokenB the seller wants in return
89
- */
64
+
90
65
  struct Order {
91
66
  address seller;
92
67
  uint256 amountA;
93
68
  uint256 amountB;
94
69
  }
95
70
 
96
- /**
97
- * @notice Extended order information for external queries
98
- * @param marketId ID of the market containing this order
99
- * @param orderId Unique order ID within the market
100
- * @param seller Address of the user who created the order
101
- * @param amountA Amount of tokenA being offered
102
- * @param amountB Amount of tokenB being requested
103
- */
104
71
  struct OrderForGetter {
105
72
  uint256 marketId;
106
73
  uint256 orderId;
@@ -109,26 +76,12 @@ contract P2PSwap is StakingServiceHooks {
109
76
  uint256 amountB;
110
77
  }
111
78
 
112
- /**
113
- * @notice Fee distribution percentages (in basis points, total must equal 10,000)
114
- * @param seller Percentage of fees distributed to the order seller
115
- * @param service Percentage of fees retained by the P2PSwap service
116
- * @param mateStaker Percentage of fees distributed to MATE token stakers
117
- */
118
79
  struct Percentage {
119
80
  uint256 seller;
120
81
  uint256 service;
121
82
  uint256 mateStaker;
122
83
  }
123
84
 
124
- /**
125
- * @notice Metadata required for creating a new order
126
- * @param nonce Unique nonce to prevent replay attacks
127
- * @param tokenA Address of the token being offered
128
- * @param tokenB Address of the token being requested
129
- * @param amountA Amount of tokenA to offer
130
- * @param amountB Amount of tokenB requested in return
131
- */
132
85
  struct MetadataMakeOrder {
133
86
  uint256 nonce;
134
87
  address tokenA;
@@ -137,14 +90,6 @@ contract P2PSwap is StakingServiceHooks {
137
90
  uint256 amountB;
138
91
  }
139
92
 
140
- /**
141
- * @notice Metadata required for canceling an existing order
142
- * @param nonce Unique nonce to prevent replay attacks
143
- * @param tokenA Address of the first token in the market
144
- * @param tokenB Address of the second token in the market
145
- * @param orderId ID of the order to cancel
146
- * @param signature User's signature authorizing the cancellation
147
- */
148
93
  struct MetadataCancelOrder {
149
94
  uint256 nonce;
150
95
  address tokenA;
@@ -153,15 +98,6 @@ contract P2PSwap is StakingServiceHooks {
153
98
  bytes signature;
154
99
  }
155
100
 
156
- /**
157
- * @notice Metadata required for executing/filling an order
158
- * @param nonce Unique nonce to prevent replay attacks
159
- * @param tokenA Address of the first token in the market
160
- * @param tokenB Address of the second token in the market
161
- * @param orderId ID of the order to execute
162
- * @param amountOfTokenBToFill Amount of tokenB to pay (including fees)
163
- * @param signature User's signature authorizing the execution
164
- */
165
101
  struct MetadataDispatchOrder {
166
102
  uint256 nonce;
167
103
  address tokenA;
@@ -171,65 +107,40 @@ contract P2PSwap is StakingServiceHooks {
171
107
  bytes signature;
172
108
  }
173
109
 
174
- /// @notice Current fee distribution percentages
175
110
  Percentage rewardPercentage;
176
- /// @notice Proposed new fee distribution percentages
177
111
  Percentage rewardPercentage_proposal;
178
- /// @notice Timestamp when reward percentage change can be accepted
179
112
  uint256 rewardPercentage_timeToAcceptNewChange;
180
113
 
181
- /// @notice Current trading fee percentage (in basis points)
182
114
  uint256 percentageFee;
183
- /// @notice Proposed new trading fee percentage
184
115
  uint256 percentageFee_proposal;
185
- /// @notice Timestamp when fee percentage change can be accepted
186
116
  uint256 percentageFee_timeToAccept;
187
117
 
188
- /// @notice Maximum fixed fee limit for order execution
189
118
  uint256 maxLimitFillFixedFee;
190
- /// @notice Proposed new maximum fixed fee limit
191
119
  uint256 maxLimitFillFixedFee_proposal;
192
- /// @notice Timestamp when max fee limit change can be accepted
193
120
  uint256 maxLimitFillFixedFee_timeToAccept;
194
121
 
195
- /// @notice Token address for pending withdrawal
196
122
  address tokenToWithdraw;
197
- /// @notice Amount for pending withdrawal
198
123
  uint256 amountToWithdraw;
199
- /// @notice Recipient address for pending withdrawal
200
124
  address recipientToWithdraw;
201
- /// @notice Timestamp when withdrawal can be executed
202
125
  uint256 timeToWithdrawal;
203
126
 
204
- /// @notice Total number of markets created
205
127
  uint256 marketCount;
206
128
 
207
- /// @notice Tracks used nonces per user to prevent replay attacks
208
129
  mapping(address user => mapping(uint256 nonce => bool isUsed)) nonceP2PSwap;
209
130
 
210
- /// @notice Maps token pairs to their market ID
211
131
  mapping(address tokenA => mapping(address tokenB => uint256 id)) marketId;
212
132
 
213
- /// @notice Stores market information by market ID
214
133
  mapping(uint256 id => MarketInformation info) marketMetadata;
215
134
 
216
- /// @notice Stores orders within each market
217
135
  mapping(uint256 idMarket => mapping(uint256 idOrder => Order)) ordersInsideMarket;
218
136
 
219
- /// @notice Tracks service fee balances accumulated per token
220
137
  mapping(address => uint256) balancesOfContract;
221
138
 
222
- /**
223
- * @notice Initializes the P2PSwap contract with required addresses and default parameters
224
- * @param _evvmAddress Address of the EVVM core contract for payment processing
225
- * @param _stakingAddress Address of the Staking contract for service functionality
226
- * @param _owner Address that will have administrative privileges
227
- */
228
139
  constructor(
229
140
  address _evvmAddress,
230
141
  address _stakingAddress,
231
142
  address _owner
232
- ) StakingServiceHooks(_stakingAddress) {
143
+ ) StakingServiceUtils(_stakingAddress) {
233
144
  evvmAddress = _evvmAddress;
234
145
  owner = _owner;
235
146
  maxLimitFillFixedFee = 0.001 ether;
@@ -242,19 +153,6 @@ contract P2PSwap is StakingServiceHooks {
242
153
  stakingAddress = _stakingAddress;
243
154
  }
244
155
 
245
- /**
246
- * @notice Creates a new trading order in the specified market
247
- * @dev Verifies signature, processes payment, creates/finds market, and assigns order slot
248
- * @param user Address of the user creating the order
249
- * @param metadata Order details including tokens, amounts, and nonce
250
- * @param signature User's signature authorizing the order creation
251
- * @param _priorityFee_Evvm Priority fee for EVVM transaction processing
252
- * @param _nonce_Evvm Nonce for EVVM payment transaction
253
- * @param _priority_Evvm Whether to use priority (async) processing
254
- * @param _signature_Evvm Signature for EVVM payment authorization
255
- * @return market ID of the market where order was created
256
- * @return orderId Unique ID of the created order within the market
257
- */
258
156
  function makeOrder(
259
157
  address user,
260
158
  MetadataMakeOrder memory metadata,
@@ -340,16 +238,6 @@ contract P2PSwap is StakingServiceHooks {
340
238
  nonceP2PSwap[user][metadata.nonce] = true;
341
239
  }
342
240
 
343
- /**
344
- * @notice Cancels an existing order and refunds tokens to the seller
345
- * @dev Verifies signature, validates ownership, refunds tokenA, and removes order
346
- * @param user Address of the user canceling the order
347
- * @param metadata Cancel details including market info and order ID
348
- * @param _priorityFee_Evvm Priority fee for EVVM transaction (optional)
349
- * @param _nonce_Evvm Nonce for EVVM payment transaction (if priority fee > 0)
350
- * @param _priority_Evvm Whether to use priority processing
351
- * @param _signature_Evvm Signature for EVVM payment (if priority fee > 0)
352
- */
353
241
  function cancelOrder(
354
242
  address user,
355
243
  MetadataCancelOrder memory metadata,
@@ -419,16 +307,6 @@ contract P2PSwap is StakingServiceHooks {
419
307
  nonceP2PSwap[user][metadata.nonce] = true;
420
308
  }
421
309
 
422
- /**
423
- * @notice Executes an order using proportional fee calculation
424
- * @dev Calculates fee as percentage of order amount, distributes payments to all parties
425
- * @param user Address of the user filling the order
426
- * @param metadata Execution details including order ID and payment amount
427
- * @param _priorityFee_Evvm Priority fee for EVVM transaction processing
428
- * @param _nonce_Evvm Nonce for EVVM payment transaction
429
- * @param _priority_Evvm Whether to use priority (async) processing
430
- * @param _signature_Evvm Signature for EVVM payment authorization
431
- */
432
310
  function dispatchOrder_fillPropotionalFee(
433
311
  address user,
434
312
  MetadataDispatchOrder memory metadata,
@@ -461,7 +339,7 @@ contract P2PSwap is StakingServiceHooks {
461
339
  market == 0 ||
462
340
  ordersInsideMarket[market][metadata.orderId].seller == address(0)
463
341
  ) {
464
- revert();
342
+ revert("Invalid order");
465
343
  }
466
344
 
467
345
  uint256 fee = calculateFillPropotionalFee(
@@ -550,17 +428,6 @@ contract P2PSwap is StakingServiceHooks {
550
428
  nonceP2PSwap[user][metadata.nonce] = true;
551
429
  }
552
430
 
553
- /**
554
- * @notice Executes an order using fixed fee calculation with maximum limits
555
- * @dev Calculates fee with upper bound, distributes payments, handles overpayment refunds
556
- * @param user Address of the user filling the order
557
- * @param metadata Execution details including order ID and payment amount
558
- * @param _priorityFee_Evvm Priority fee for EVVM transaction processing
559
- * @param _nonce_Evvm Nonce for EVVM payment transaction
560
- * @param _priority_Evvm Whether to use priority (async) processing
561
- * @param _signature_Evvm Signature for EVVM payment authorization
562
- * @param maxFillFixedFee Maximum output amount for fee calculation (testing parameter)
563
- */
564
431
  function dispatchOrder_fillFixedFee(
565
432
  address user,
566
433
  MetadataDispatchOrder memory metadata,
@@ -568,7 +435,7 @@ contract P2PSwap is StakingServiceHooks {
568
435
  uint256 _nonce_Evvm,
569
436
  bool _priority_Evvm,
570
437
  bytes memory _signature_Evvm,
571
- uint256 maxFillFixedFee
438
+ uint256 maxFillFixedFee ///@dev for testing purposes
572
439
  ) external {
573
440
  if (
574
441
  !SignatureUtils.verifyMessageSignedForDispatchOrder(
@@ -581,20 +448,20 @@ contract P2PSwap is StakingServiceHooks {
581
448
  metadata.signature
582
449
  )
583
450
  ) {
584
- revert();
451
+ revert("Invalid signature");
585
452
  }
586
453
 
587
454
  uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
588
455
 
589
456
  if (nonceP2PSwap[user][metadata.nonce]) {
590
- revert();
457
+ revert("Invalid nonce");
591
458
  }
592
459
 
593
460
  if (
594
461
  market == 0 ||
595
462
  ordersInsideMarket[market][metadata.orderId].seller == address(0)
596
463
  ) {
597
- revert();
464
+ revert("Invalid order");
598
465
  }
599
466
 
600
467
  (uint256 fee, uint256 fee10) = calculateFillFixedFee(
@@ -606,7 +473,7 @@ contract P2PSwap is StakingServiceHooks {
606
473
  metadata.amountOfTokenBToFill <
607
474
  ordersInsideMarket[market][metadata.orderId].amountB + fee - fee10
608
475
  ) {
609
- revert();
476
+ revert("Insuficient amountOfTokenBToFill");
610
477
  }
611
478
 
612
479
  makePay(
@@ -688,26 +555,14 @@ contract P2PSwap is StakingServiceHooks {
688
555
  nonceP2PSwap[user][metadata.nonce] = true;
689
556
  }
690
557
 
691
- /**
692
- * @notice Calculates proportional trading fee as percentage of order amount
693
- * @dev Fee is calculated as (amount * percentageFee) / 10,000 basis points
694
- * @param amount The order amount to calculate fee for
695
- * @return fee The calculated proportional fee amount
696
- */
558
+ //devolver el 0.05% del monto de la orden
697
559
  function calculateFillPropotionalFee(
698
560
  uint256 amount
699
561
  ) internal view returns (uint256 fee) {
562
+ ///@dev get the % of the amount
700
563
  fee = (amount * percentageFee) / 10_000;
701
564
  }
702
565
 
703
- /**
704
- * @notice Calculates fixed trading fee with maximum limit constraints
705
- * @dev Compares proportional fee with maximum output, applies 10% reduction if needed
706
- * @param amount Order amount for proportional fee calculation
707
- * @param maxFillFixedFee Maximum output amount for fee limiting
708
- * @return fee The final calculated fee amount
709
- * @return fee10 10% of the fee amount for specific calculations
710
- */
711
566
  function calculateFillFixedFee(
712
567
  uint256 amount,
713
568
  uint256 maxFillFixedFee
@@ -720,13 +575,6 @@ contract P2PSwap is StakingServiceHooks {
720
575
  }
721
576
  }
722
577
 
723
- /**
724
- * @notice Creates a new trading market for a token pair
725
- * @dev Increments market count, assigns market ID, initializes market metadata
726
- * @param tokenA Address of the first token in the trading pair
727
- * @param tokenB Address of the second token in the trading pair
728
- * @return The newly created market ID
729
- */
730
578
  function createMarket(
731
579
  address tokenA,
732
580
  address tokenB
@@ -741,17 +589,6 @@ contract P2PSwap is StakingServiceHooks {
741
589
  // Tools for Evvm
742
590
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
743
591
 
744
- /**
745
- * @notice Internal function to process payments through EVVM contract
746
- * @dev Calls EVVM.pay() with all necessary parameters for token transfer
747
- * @param _user_Evvm Address of the user making the payment
748
- * @param _token_Evvm Address of the token being transferred
749
- * @param _nonce_Evvm Nonce for the EVVM transaction
750
- * @param _ammount_Evvm Amount of tokens to transfer
751
- * @param _priorityFee_Evvm Additional priority fee for the transaction
752
- * @param _priority_Evvm Whether to use priority (async) processing
753
- * @param _signature_Evvm User's signature authorizing the payment
754
- */
755
592
  function makePay(
756
593
  address _user_Evvm,
757
594
  address _token_Evvm,
@@ -775,13 +612,6 @@ contract P2PSwap is StakingServiceHooks {
775
612
  );
776
613
  }
777
614
 
778
- /**
779
- * @notice Internal function to distribute tokens from contract balance via EVVM
780
- * @dev Calls EVVM.caPay() to transfer tokens from P2PSwap to specified user
781
- * @param _user_Evvm Address of the recipient
782
- * @param _token_Evvm Address of the token to transfer
783
- * @param _ammount_Evvm Amount of tokens to transfer
784
- */
785
615
  function makeCaPay(
786
616
  address _user_Evvm,
787
617
  address _token_Evvm,
@@ -790,13 +620,6 @@ contract P2PSwap is StakingServiceHooks {
790
620
  Evvm(evvmAddress).caPay(_user_Evvm, _token_Evvm, _ammount_Evvm);
791
621
  }
792
622
 
793
- /**
794
- * @notice Internal function to distribute tokens to multiple recipients via EVVM
795
- * @dev Calls EVVM.disperseCaPay() for efficient batch token distribution
796
- * @param toData Array of recipient addresses and amounts
797
- * @param token Address of the token to distribute
798
- * @param amount Total amount being distributed (must match sum of individual amounts)
799
- */
800
623
  function makeDisperseCaPay(
801
624
  EvvmStructs.DisperseCaPayMetadata[] memory toData,
802
625
  address token,
@@ -809,11 +632,6 @@ contract P2PSwap is StakingServiceHooks {
809
632
  // Admin tools
810
633
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
811
634
 
812
- /**
813
- * @notice Proposes a new contract owner with 1-day delay
814
- * @dev Only current owner can propose, starts time-delayed governance process
815
- * @param _owner Address of the proposed new owner
816
- */
817
635
  function proposeOwner(address _owner) external {
818
636
  if (msg.sender != owner) {
819
637
  revert();
@@ -822,10 +640,6 @@ contract P2PSwap is StakingServiceHooks {
822
640
  owner_timeToAccept = block.timestamp + 1 days;
823
641
  }
824
642
 
825
- /**
826
- * @notice Rejects the current owner change proposal
827
- * @dev Only proposed owner can reject before deadline expires
828
- */
829
643
  function rejectProposeOwner() external {
830
644
  if (
831
645
  msg.sender != owner_proposal || block.timestamp > owner_timeToAccept
@@ -835,10 +649,6 @@ contract P2PSwap is StakingServiceHooks {
835
649
  owner_proposal = address(0);
836
650
  }
837
651
 
838
- /**
839
- * @notice Accepts ownership transfer after time delay
840
- * @dev Only proposed owner can accept after 1-day waiting period
841
- */
842
652
  function acceptOwner() external {
843
653
  if (
844
654
  msg.sender != owner_proposal || block.timestamp > owner_timeToAccept
@@ -849,13 +659,6 @@ contract P2PSwap is StakingServiceHooks {
849
659
  owner_proposal = address(0);
850
660
  }
851
661
 
852
- /**
853
- * @notice Proposes new fee distribution percentages for fixed fee model
854
- * @dev Percentages must sum to 10,000 basis points (100%)
855
- * @param _seller Percentage for order sellers (basis points)
856
- * @param _service Percentage for P2PSwap service (basis points)
857
- * @param _mateStaker Percentage for MATE token stakers (basis points)
858
- */
859
662
  function proposeFillFixedPercentage(
860
663
  uint256 _seller,
861
664
  uint256 _service,
@@ -871,10 +674,6 @@ contract P2PSwap is StakingServiceHooks {
871
674
  rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
872
675
  }
873
676
 
874
- /**
875
- * @notice Rejects the current fee percentage proposal for fixed fee model
876
- * @dev Only owner can reject before deadline expires, resets proposal to zero
877
- */
878
677
  function rejectProposeFillFixedPercentage() external {
879
678
  if (
880
679
  msg.sender != owner ||
@@ -885,10 +684,6 @@ contract P2PSwap is StakingServiceHooks {
885
684
  rewardPercentage_proposal = Percentage(0, 0, 0);
886
685
  }
887
686
 
888
- /**
889
- * @notice Accepts the fee percentage proposal for fixed fee model after time delay
890
- * @dev Only owner can accept after 1-day waiting period, applies new percentages
891
- */
892
687
  function acceptFillFixedPercentage() external {
893
688
  if (
894
689
  msg.sender != owner ||
@@ -899,13 +694,6 @@ contract P2PSwap is StakingServiceHooks {
899
694
  rewardPercentage = rewardPercentage_proposal;
900
695
  }
901
696
 
902
- /**
903
- * @notice Proposes new fee distribution percentages for proportional fee model
904
- * @dev Percentages must sum to 10,000 basis points (100%)
905
- * @param _seller Percentage for order sellers (basis points)
906
- * @param _service Percentage for P2PSwap service (basis points)
907
- * @param _mateStaker Percentage for MATE token stakers (basis points)
908
- */
909
697
  function proposeFillPropotionalPercentage(
910
698
  uint256 _seller,
911
699
  uint256 _service,
@@ -918,10 +706,6 @@ contract P2PSwap is StakingServiceHooks {
918
706
  rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
919
707
  }
920
708
 
921
- /**
922
- * @notice Rejects the current fee percentage proposal for proportional fee model
923
- * @dev Only owner can reject before deadline expires, resets proposal to zero
924
- */
925
709
  function rejectProposeFillPropotionalPercentage() external {
926
710
  if (
927
711
  msg.sender != owner ||
@@ -932,10 +716,6 @@ contract P2PSwap is StakingServiceHooks {
932
716
  rewardPercentage_proposal = Percentage(0, 0, 0);
933
717
  }
934
718
 
935
- /**
936
- * @notice Accepts the fee percentage proposal for proportional fee model after time delay
937
- * @dev Only owner can accept after 1-day waiting period, applies new percentages
938
- */
939
719
  function acceptFillPropotionalPercentage() external {
940
720
  if (
941
721
  msg.sender != owner ||
@@ -946,11 +726,6 @@ contract P2PSwap is StakingServiceHooks {
946
726
  rewardPercentage = rewardPercentage_proposal;
947
727
  }
948
728
 
949
- /**
950
- * @notice Proposes a new percentage fee for proportional fee calculation
951
- * @dev Only owner can propose, starts time-delayed governance process
952
- * @param _percentageFee New percentage fee value in basis points
953
- */
954
729
  function proposePercentageFee(uint256 _percentageFee) external {
955
730
  if (msg.sender != owner) {
956
731
  revert();
@@ -959,10 +734,6 @@ contract P2PSwap is StakingServiceHooks {
959
734
  percentageFee_timeToAccept = block.timestamp + 1 days;
960
735
  }
961
736
 
962
- /**
963
- * @notice Rejects the current percentage fee proposal
964
- * @dev Only owner can reject before deadline expires, resets proposal to zero
965
- */
966
737
  function rejectProposePercentageFee() external {
967
738
  if (
968
739
  msg.sender != owner || block.timestamp > percentageFee_timeToAccept
@@ -972,10 +743,6 @@ contract P2PSwap is StakingServiceHooks {
972
743
  percentageFee_proposal = 0;
973
744
  }
974
745
 
975
- /**
976
- * @notice Accepts the percentage fee proposal after time delay
977
- * @dev Only owner can accept after 1-day waiting period, applies new fee
978
- */
979
746
  function acceptPercentageFee() external {
980
747
  if (
981
748
  msg.sender != owner || block.timestamp > percentageFee_timeToAccept
@@ -985,11 +752,6 @@ contract P2PSwap is StakingServiceHooks {
985
752
  percentageFee = percentageFee_proposal;
986
753
  }
987
754
 
988
- /**
989
- * @notice Proposes a new maximum limit for fixed fee calculations
990
- * @dev Only owner can propose, starts time-delayed governance process
991
- * @param _maxLimitFillFixedFee New maximum limit value for fixed fee calculations
992
- */
993
755
  function proposeMaxLimitFillFixedFee(
994
756
  uint256 _maxLimitFillFixedFee
995
757
  ) external {
@@ -1000,10 +762,6 @@ contract P2PSwap is StakingServiceHooks {
1000
762
  maxLimitFillFixedFee_timeToAccept = block.timestamp + 1 days;
1001
763
  }
1002
764
 
1003
- /**
1004
- * @notice Rejects the current maximum limit proposal for fixed fees
1005
- * @dev Only owner can reject before deadline expires, resets proposal to zero
1006
- */
1007
765
  function rejectProposeMaxLimitFillFixedFee() external {
1008
766
  if (
1009
767
  msg.sender != owner ||
@@ -1014,10 +772,6 @@ contract P2PSwap is StakingServiceHooks {
1014
772
  maxLimitFillFixedFee_proposal = 0;
1015
773
  }
1016
774
 
1017
- /**
1018
- * @notice Accepts the maximum limit proposal for fixed fees after time delay
1019
- * @dev Only owner can accept after 1-day waiting period, applies new limit
1020
- */
1021
775
  function acceptMaxLimitFillFixedFee() external {
1022
776
  if (
1023
777
  msg.sender != owner ||
@@ -1028,13 +782,6 @@ contract P2PSwap is StakingServiceHooks {
1028
782
  maxLimitFillFixedFee = maxLimitFillFixedFee_proposal;
1029
783
  }
1030
784
 
1031
- /**
1032
- * @notice Proposes withdrawal of accumulated service fees
1033
- * @dev Only owner can propose, amount must not exceed available balance
1034
- * @param _tokenToWithdraw Address of token to withdraw
1035
- * @param _amountToWithdraw Amount of tokens to withdraw
1036
- * @param _to Recipient address for the withdrawal
1037
- */
1038
785
  function proposeWithdrawal(
1039
786
  address _tokenToWithdraw,
1040
787
  uint256 _amountToWithdraw,
@@ -1052,10 +799,6 @@ contract P2PSwap is StakingServiceHooks {
1052
799
  timeToWithdrawal = block.timestamp + 1 days;
1053
800
  }
1054
801
 
1055
- /**
1056
- * @notice Rejects the current withdrawal proposal
1057
- * @dev Only owner can reject before deadline expires, clears all withdrawal data
1058
- */
1059
802
  function rejectProposeWithdrawal() external {
1060
803
  if (msg.sender != owner || block.timestamp > timeToWithdrawal) {
1061
804
  revert();
@@ -1066,10 +809,6 @@ contract P2PSwap is StakingServiceHooks {
1066
809
  timeToWithdrawal = 0;
1067
810
  }
1068
811
 
1069
- /**
1070
- * @notice Executes the withdrawal proposal after time delay
1071
- * @dev Transfers tokens via EVVM, updates balance, and clears withdrawal data
1072
- */
1073
812
  function acceptWithdrawal() external {
1074
813
  if (msg.sender != owner || block.timestamp > timeToWithdrawal) {
1075
814
  revert();
@@ -1083,11 +822,6 @@ contract P2PSwap is StakingServiceHooks {
1083
822
  timeToWithdrawal = 0;
1084
823
  }
1085
824
 
1086
- /**
1087
- * @notice Stakes accumulated MATE tokens using service staking functionality
1088
- * @dev Only owner can stake, requires sufficient MATE token balance
1089
- * @param amount Number of staking tokens to stake (not MATE token amount)
1090
- */
1091
825
  function stake(uint256 amount) external {
1092
826
  if (
1093
827
  msg.sender != owner ||
@@ -1098,23 +832,12 @@ contract P2PSwap is StakingServiceHooks {
1098
832
  _makeStakeService(amount);
1099
833
  }
1100
834
 
1101
- /**
1102
- * @notice Unstakes service staking tokens and receives MATE tokens
1103
- * @dev Only owner can unstake, subject to staking contract time locks
1104
- * @param amount Number of staking tokens to unstake
1105
- */
1106
835
  function unstake(uint256 amount) external {
1107
836
  if (msg.sender != owner) revert();
1108
837
 
1109
838
  _makeUnstakeService(amount);
1110
839
  }
1111
840
 
1112
- /**
1113
- * @notice Manually adds balance to the contract for a specific token
1114
- * @dev Only owner can add balance, useful for reconciling accounting discrepancies
1115
- * @param _token Address of the token to add balance for
1116
- * @param _amount Amount to add to the contract's balance tracking
1117
- */
1118
841
  function addBalance(address _token, uint256 _amount) external {
1119
842
  if (msg.sender != owner) {
1120
843
  revert();
@@ -1125,12 +848,6 @@ contract P2PSwap is StakingServiceHooks {
1125
848
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
1126
849
  //getters
1127
850
  //◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
1128
- /**
1129
- * @notice Retrieves all active orders in a specific market
1130
- * @dev Returns array with extended order information including market and order IDs
1131
- * @param market The market ID to query orders from
1132
- * @return orders Array of OrderForGetter structs containing all active orders
1133
- */
1134
851
  function getAllMarketOrders(
1135
852
  uint256 market
1136
853
  ) public view returns (OrderForGetter[] memory orders) {
@@ -1150,12 +867,6 @@ contract P2PSwap is StakingServiceHooks {
1150
867
  return orders;
1151
868
  }
1152
869
 
1153
- /**
1154
- * @notice Retrieves a specific order by market and order ID
1155
- * @param market The market ID containing the order
1156
- * @param orderId The specific order ID to retrieve
1157
- * @return order The Order struct containing seller address and amounts
1158
- */
1159
870
  function getOrder(
1160
871
  uint256 market,
1161
872
  uint256 orderId
@@ -1164,13 +875,6 @@ contract P2PSwap is StakingServiceHooks {
1164
875
  return order;
1165
876
  }
1166
877
 
1167
- /**
1168
- * @notice Retrieves all orders from a specific user in a specific market
1169
- * @dev Returns array with extended order information for user's orders only
1170
- * @param user Address of the user whose orders to retrieve
1171
- * @param market The market ID to query orders from
1172
- * @return orders Array of OrderForGetter structs containing user's orders in the market
1173
- */
1174
878
  function getMyOrdersInSpecificMarket(
1175
879
  address user,
1176
880
  uint256 market
@@ -1191,12 +895,6 @@ contract P2PSwap is StakingServiceHooks {
1191
895
  return orders;
1192
896
  }
1193
897
 
1194
- /**
1195
- * @notice Finds the market ID for a specific token pair
1196
- * @param tokenA Address of the first token
1197
- * @param tokenB Address of the second token
1198
- * @return The market ID for the token pair, or 0 if market doesn't exist
1199
- */
1200
898
  function findMarket(
1201
899
  address tokenA,
1202
900
  address tokenB
@@ -1204,22 +902,12 @@ contract P2PSwap is StakingServiceHooks {
1204
902
  return marketId[tokenA][tokenB];
1205
903
  }
1206
904
 
1207
- /**
1208
- * @notice Retrieves metadata information for a specific market
1209
- * @param market The market ID to get metadata for
1210
- * @return MarketInformation struct containing token addresses, max slot, and other metadata
1211
- */
1212
905
  function getMarketMetadata(
1213
906
  uint256 market
1214
907
  ) public view returns (MarketInformation memory) {
1215
908
  return marketMetadata[market];
1216
909
  }
1217
910
 
1218
- /**
1219
- * @notice Retrieves metadata information for all existing markets
1220
- * @dev Returns array of all market metadata from market ID 1 to marketCount
1221
- * @return Array of MarketInformation structs containing all markets data
1222
- */
1223
911
  function getAllMarketsMetadata()
1224
912
  public
1225
913
  view
@@ -1234,13 +922,6 @@ contract P2PSwap is StakingServiceHooks {
1234
922
  return markets;
1235
923
  }
1236
924
 
1237
- /**
1238
- * @notice Checks if a nonce has been used by a specific user
1239
- * @dev Used to prevent replay attacks in P2P swap operations
1240
- * @param user Address of the user to check
1241
- * @param nonce The nonce value to verify
1242
- * @return True if nonce has been used, false otherwise
1243
- */
1244
925
  function checkIfANonceP2PSwapIsUsed(
1245
926
  address user,
1246
927
  uint256 nonce
@@ -1248,45 +929,24 @@ contract P2PSwap is StakingServiceHooks {
1248
929
  return nonceP2PSwap[user][nonce];
1249
930
  }
1250
931
 
1251
- /**
1252
- * @notice Returns the accumulated service fee balance for a specific token
1253
- * @param token Address of the token to check balance for
1254
- * @return The accumulated balance of the specified token
1255
- */
1256
932
  function getBalanceOfContract(
1257
933
  address token
1258
934
  ) external view returns (uint256) {
1259
935
  return balancesOfContract[token];
1260
936
  }
1261
937
 
1262
- /**
1263
- * @notice Returns the currently proposed new owner address
1264
- * @return Address of the proposed owner, or address(0) if no proposal exists
1265
- */
1266
938
  function getOwnerProposal() external view returns (address) {
1267
939
  return owner_proposal;
1268
940
  }
1269
941
 
1270
- /**
1271
- * @notice Returns the current contract owner address
1272
- * @return Address of the current contract owner
1273
- */
1274
942
  function getOwner() external view returns (address) {
1275
943
  return owner;
1276
944
  }
1277
945
 
1278
- /**
1279
- * @notice Returns the deadline timestamp for accepting ownership transfer
1280
- * @return Timestamp until which the ownership proposal can be accepted
1281
- */
1282
946
  function getOwnerTimeToAccept() external view returns (uint256) {
1283
947
  return owner_timeToAccept;
1284
948
  }
1285
949
 
1286
- /**
1287
- * @notice Returns the currently proposed reward percentage distribution
1288
- * @return Percentage struct with proposed seller, service, and staker percentages
1289
- */
1290
950
  function getRewardPercentageProposal()
1291
951
  external
1292
952
  view
@@ -1295,54 +955,26 @@ contract P2PSwap is StakingServiceHooks {
1295
955
  return rewardPercentage_proposal;
1296
956
  }
1297
957
 
1298
- /**
1299
- * @notice Returns the current active reward percentage distribution
1300
- * @return Percentage struct with active seller, service, and staker percentages
1301
- */
1302
958
  function getRewardPercentage() external view returns (Percentage memory) {
1303
959
  return rewardPercentage;
1304
960
  }
1305
961
 
1306
- /**
1307
- * @notice Returns the currently proposed percentage fee value
1308
- * @return Proposed percentage fee in basis points for proportional fee calculation
1309
- */
1310
962
  function getProposalPercentageFee() external view returns (uint256) {
1311
963
  return percentageFee_proposal;
1312
964
  }
1313
965
 
1314
- /**
1315
- * @notice Returns the current active percentage fee value
1316
- * @return Active percentage fee in basis points for proportional fee calculation
1317
- */
1318
966
  function getPercentageFee() external view returns (uint256) {
1319
967
  return percentageFee;
1320
968
  }
1321
969
 
1322
- /**
1323
- * @notice Returns the currently proposed maximum limit for fixed fee calculations
1324
- * @return Proposed maximum limit value for fixed fee model
1325
- */
1326
970
  function getMaxLimitFillFixedFeeProposal() external view returns (uint256) {
1327
971
  return maxLimitFillFixedFee_proposal;
1328
972
  }
1329
973
 
1330
- /**
1331
- * @notice Returns the current active maximum limit for fixed fee calculations
1332
- * @return Active maximum limit value for fixed fee model
1333
- */
1334
974
  function getMaxLimitFillFixedFee() external view returns (uint256) {
1335
975
  return maxLimitFillFixedFee;
1336
976
  }
1337
977
 
1338
- /**
1339
- * @notice Returns complete information about the current withdrawal proposal
1340
- * @dev Returns all withdrawal parameters including token, amount, recipient, and deadline
1341
- * @return tokenToWithdraw Address of token to be withdrawn
1342
- * @return amountToWithdraw Amount of tokens to be withdrawn
1343
- * @return recipientToWithdraw Address that will receive the tokens
1344
- * @return timeToWithdrawal Deadline timestamp for accepting the withdrawal
1345
- */
1346
978
  function getProposedWithdrawal()
1347
979
  external
1348
980
  view