@evvm/testnet-contracts 2.1.3 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +2 -2
- package/README.md +355 -55
- package/contracts/evvm/Evvm.sol +39 -38
- package/contracts/evvm/lib/ErrorsLib.sol +2 -1
- package/contracts/evvm/lib/EvvmStorage.sol +2 -0
- package/contracts/evvm/lib/EvvmStructs.sol +27 -1
- package/contracts/evvm/lib/SignatureUtils.sol +14 -17
- package/contracts/nameService/NameService.sol +124 -366
- package/contracts/nameService/lib/ErrorsLib.sol +2 -8
- package/contracts/nameService/lib/IdentityValidation.sol +182 -0
- package/contracts/nameService/lib/NameServiceStructs.sol +69 -0
- package/contracts/nameService/lib/SignatureUtils.sol +47 -41
- package/contracts/p2pSwap/P2PSwap.sol +54 -535
- package/contracts/p2pSwap/lib/P2PSwapStructs.sol +59 -0
- package/contracts/p2pSwap/lib/SignatureUtils.sol +16 -18
- package/contracts/staking/Estimator.sol +7 -6
- package/contracts/staking/Staking.sol +70 -159
- package/contracts/staking/lib/ErrorsLib.sol +0 -1
- package/contracts/staking/lib/SignatureUtils.sol +7 -36
- package/contracts/staking/lib/StakingStructs.sol +94 -0
- package/contracts/treasury/Treasury.sol +18 -20
- package/contracts/treasuryTwoChains/TreasuryExternalChainStation.sol +88 -35
- package/contracts/treasuryTwoChains/TreasuryHostChainStation.sol +81 -47
- package/contracts/treasuryTwoChains/lib/ErrorsLib.sol +2 -0
- package/contracts/treasuryTwoChains/lib/ExternalChainStationStructs.sol +3 -14
- package/contracts/treasuryTwoChains/lib/HostChainStationStructs.sol +3 -7
- package/contracts/treasuryTwoChains/lib/SignatureUtils.sol +12 -14
- package/interfaces/IEstimator.sol +7 -50
- package/interfaces/IEvvm.sol +17 -91
- package/interfaces/INameService.sol +37 -88
- package/interfaces/IP2PSwap.sol +19 -15
- package/interfaces/IStaking.sol +20 -50
- package/interfaces/ITreasury.sol +1 -4
- package/interfaces/ITreasuryExternalChainStation.sol +11 -15
- package/interfaces/ITreasuryHostChainStation.sol +7 -10
- package/library/Erc191TestBuilder.sol +56 -57
- package/library/EvvmService.sol +40 -0
- package/library/primitives/IERC20.sol +79 -0
- package/library/primitives/Math.sol +415 -0
- package/library/primitives/SignatureRecover.sol +42 -0
- package/library/utils/AdvancedStrings.sol +89 -0
- package/library/utils/GovernanceUtils.sol +81 -0
- package/library/utils/SignatureUtil.sol +29 -0
- package/library/utils/nonces/AsyncNonce.sol +32 -0
- package/library/utils/nonces/SyncNonce.sol +27 -0
- package/library/utils/service/EvvmPayments.sol +77 -0
- package/library/utils/service/StakingServiceUtils.sol +32 -0
- package/package.json +11 -13
- package/contracts/evvm/EvvmLegacy.sol +0 -1553
- package/library/AdvancedStrings.sol +0 -77
- package/library/SignatureRecover.sol +0 -140
- package/library/StakingServiceHooks.sol +0 -116
|
@@ -36,201 +36,59 @@ pragma solidity ^0.8.0;
|
|
|
36
36
|
* - Staker Rewards: 10% (configurable)
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
|
-
import {Evvm} from "@evvm/testnet-contracts/contracts/evvm/Evvm.sol";
|
|
40
39
|
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
40
|
import {SignatureUtils} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/SignatureUtils.sol";
|
|
44
|
-
import {AdvancedStrings} from "@evvm/testnet-contracts/library/AdvancedStrings.sol";
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
import {AdvancedStrings} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
42
|
+
import {P2PSwapStructs} from "@evvm/testnet-contracts/contracts/p2pSwap/lib/P2PSwapStructs.sol";
|
|
43
|
+
import {EvvmStructs} from "@evvm/testnet-contracts/interfaces/IEvvm.sol";
|
|
44
|
+
import {EvvmService} from "@evvm/testnet-contracts/library/EvvmService.sol";
|
|
45
|
+
|
|
46
|
+
contract P2PSwap is
|
|
47
|
+
EvvmService,
|
|
48
|
+
P2PSwapStructs
|
|
49
|
+
{
|
|
53
50
|
address owner;
|
|
54
|
-
/// @notice Proposed new owner address pending acceptance
|
|
55
51
|
address owner_proposal;
|
|
56
|
-
/// @notice Timestamp when the proposed owner change can be accepted
|
|
57
52
|
uint256 owner_timeToAccept;
|
|
58
53
|
|
|
59
|
-
/// @notice Address of the EVVM core contract for payment processing
|
|
60
|
-
address evvmAddress;
|
|
61
|
-
/// @notice Address of the Staking contract for service staking functionality
|
|
62
|
-
address stakingAddress;
|
|
63
|
-
|
|
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
|
-
struct MarketInformation {
|
|
78
|
-
address tokenA;
|
|
79
|
-
address tokenB;
|
|
80
|
-
uint256 maxSlot;
|
|
81
|
-
uint256 ordersAvailable;
|
|
82
|
-
}
|
|
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
|
-
*/
|
|
90
|
-
struct Order {
|
|
91
|
-
address seller;
|
|
92
|
-
uint256 amountA;
|
|
93
|
-
uint256 amountB;
|
|
94
|
-
}
|
|
95
|
-
|
|
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
|
-
struct OrderForGetter {
|
|
105
|
-
uint256 marketId;
|
|
106
|
-
uint256 orderId;
|
|
107
|
-
address seller;
|
|
108
|
-
uint256 amountA;
|
|
109
|
-
uint256 amountB;
|
|
110
|
-
}
|
|
111
|
-
|
|
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
|
-
struct Percentage {
|
|
119
|
-
uint256 seller;
|
|
120
|
-
uint256 service;
|
|
121
|
-
uint256 mateStaker;
|
|
122
|
-
}
|
|
123
|
-
|
|
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
|
-
struct MetadataMakeOrder {
|
|
133
|
-
uint256 nonce;
|
|
134
|
-
address tokenA;
|
|
135
|
-
address tokenB;
|
|
136
|
-
uint256 amountA;
|
|
137
|
-
uint256 amountB;
|
|
138
|
-
}
|
|
139
|
-
|
|
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
|
-
struct MetadataCancelOrder {
|
|
149
|
-
uint256 nonce;
|
|
150
|
-
address tokenA;
|
|
151
|
-
address tokenB;
|
|
152
|
-
uint256 orderId;
|
|
153
|
-
bytes signature;
|
|
154
|
-
}
|
|
155
|
-
|
|
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
|
-
struct MetadataDispatchOrder {
|
|
166
|
-
uint256 nonce;
|
|
167
|
-
address tokenA;
|
|
168
|
-
address tokenB;
|
|
169
|
-
uint256 orderId;
|
|
170
|
-
uint256 amountOfTokenBToFill;
|
|
171
|
-
bytes signature;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/// @notice Current fee distribution percentages
|
|
175
58
|
Percentage rewardPercentage;
|
|
176
|
-
/// @notice Proposed new fee distribution percentages
|
|
177
59
|
Percentage rewardPercentage_proposal;
|
|
178
|
-
/// @notice Timestamp when reward percentage change can be accepted
|
|
179
60
|
uint256 rewardPercentage_timeToAcceptNewChange;
|
|
180
61
|
|
|
181
|
-
/// @notice Current trading fee percentage (in basis points)
|
|
182
62
|
uint256 percentageFee;
|
|
183
|
-
/// @notice Proposed new trading fee percentage
|
|
184
63
|
uint256 percentageFee_proposal;
|
|
185
|
-
/// @notice Timestamp when fee percentage change can be accepted
|
|
186
64
|
uint256 percentageFee_timeToAccept;
|
|
187
65
|
|
|
188
|
-
/// @notice Maximum fixed fee limit for order execution
|
|
189
66
|
uint256 maxLimitFillFixedFee;
|
|
190
|
-
/// @notice Proposed new maximum fixed fee limit
|
|
191
67
|
uint256 maxLimitFillFixedFee_proposal;
|
|
192
|
-
/// @notice Timestamp when max fee limit change can be accepted
|
|
193
68
|
uint256 maxLimitFillFixedFee_timeToAccept;
|
|
194
69
|
|
|
195
|
-
/// @notice Token address for pending withdrawal
|
|
196
70
|
address tokenToWithdraw;
|
|
197
|
-
/// @notice Amount for pending withdrawal
|
|
198
71
|
uint256 amountToWithdraw;
|
|
199
|
-
/// @notice Recipient address for pending withdrawal
|
|
200
72
|
address recipientToWithdraw;
|
|
201
|
-
/// @notice Timestamp when withdrawal can be executed
|
|
202
73
|
uint256 timeToWithdrawal;
|
|
203
74
|
|
|
204
|
-
/// @notice Total number of markets created
|
|
205
75
|
uint256 marketCount;
|
|
206
76
|
|
|
207
|
-
/// @notice Tracks used nonces per user to prevent replay attacks
|
|
208
|
-
mapping(address user => mapping(uint256 nonce => bool isUsed)) nonceP2PSwap;
|
|
209
|
-
|
|
210
|
-
/// @notice Maps token pairs to their market ID
|
|
211
77
|
mapping(address tokenA => mapping(address tokenB => uint256 id)) marketId;
|
|
212
78
|
|
|
213
|
-
/// @notice Stores market information by market ID
|
|
214
79
|
mapping(uint256 id => MarketInformation info) marketMetadata;
|
|
215
80
|
|
|
216
|
-
/// @notice Stores orders within each market
|
|
217
81
|
mapping(uint256 idMarket => mapping(uint256 idOrder => Order)) ordersInsideMarket;
|
|
218
82
|
|
|
219
|
-
/// @notice Tracks service fee balances accumulated per token
|
|
220
83
|
mapping(address => uint256) balancesOfContract;
|
|
221
84
|
|
|
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
85
|
constructor(
|
|
229
86
|
address _evvmAddress,
|
|
230
87
|
address _stakingAddress,
|
|
231
88
|
address _owner
|
|
232
|
-
)
|
|
233
|
-
|
|
89
|
+
)
|
|
90
|
+
EvvmService(_evvmAddress, _stakingAddress)
|
|
91
|
+
{
|
|
234
92
|
owner = _owner;
|
|
235
93
|
maxLimitFillFixedFee = 0.001 ether;
|
|
236
94
|
percentageFee = 500;
|
|
@@ -239,22 +97,8 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
239
97
|
service: 4000,
|
|
240
98
|
mateStaker: 1000
|
|
241
99
|
});
|
|
242
|
-
stakingAddress = _stakingAddress;
|
|
243
100
|
}
|
|
244
101
|
|
|
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
102
|
function makeOrder(
|
|
259
103
|
address user,
|
|
260
104
|
MetadataMakeOrder memory metadata,
|
|
@@ -266,7 +110,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
266
110
|
) external returns (uint256 market, uint256 orderId) {
|
|
267
111
|
if (
|
|
268
112
|
!SignatureUtils.verifyMessageSignedForMakeOrder(
|
|
269
|
-
|
|
113
|
+
evvm.getEvvmID(),
|
|
270
114
|
user,
|
|
271
115
|
metadata.nonce,
|
|
272
116
|
metadata.tokenA,
|
|
@@ -279,11 +123,9 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
279
123
|
revert("Invalid signature");
|
|
280
124
|
}
|
|
281
125
|
|
|
282
|
-
|
|
283
|
-
revert("Nonce already used");
|
|
284
|
-
}
|
|
126
|
+
verifyAsyncNonce(user, metadata.nonce);
|
|
285
127
|
|
|
286
|
-
|
|
128
|
+
requestPay(
|
|
287
129
|
user,
|
|
288
130
|
metadata.tokenA,
|
|
289
131
|
_nonce_Evvm,
|
|
@@ -321,7 +163,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
321
163
|
metadata.amountB
|
|
322
164
|
);
|
|
323
165
|
|
|
324
|
-
if (
|
|
166
|
+
if (evvm.isAddressStaker(msg.sender)) {
|
|
325
167
|
if (_priorityFee_Evvm > 0) {
|
|
326
168
|
// send the executor the priorityFee
|
|
327
169
|
makeCaPay(msg.sender, metadata.tokenA, _priorityFee_Evvm);
|
|
@@ -332,24 +174,14 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
332
174
|
msg.sender,
|
|
333
175
|
MATE_TOKEN_ADDRESS,
|
|
334
176
|
_priorityFee_Evvm > 0
|
|
335
|
-
? (
|
|
336
|
-
: (
|
|
177
|
+
? (evvm.getRewardAmount() * 3)
|
|
178
|
+
: (evvm.getRewardAmount() * 2)
|
|
337
179
|
);
|
|
338
180
|
}
|
|
339
181
|
|
|
340
|
-
|
|
182
|
+
markAsyncNonceAsUsed(user, metadata.nonce);
|
|
341
183
|
}
|
|
342
184
|
|
|
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
185
|
function cancelOrder(
|
|
354
186
|
address user,
|
|
355
187
|
MetadataCancelOrder memory metadata,
|
|
@@ -360,7 +192,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
360
192
|
) external {
|
|
361
193
|
if (
|
|
362
194
|
!SignatureUtils.verifyMessageSignedForCancelOrder(
|
|
363
|
-
|
|
195
|
+
evvm.getEvvmID(),
|
|
364
196
|
user,
|
|
365
197
|
metadata.nonce,
|
|
366
198
|
metadata.tokenA,
|
|
@@ -374,9 +206,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
374
206
|
|
|
375
207
|
uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
|
|
376
208
|
|
|
377
|
-
|
|
378
|
-
revert("Invalid nonce");
|
|
379
|
-
}
|
|
209
|
+
verifyAsyncNonce(user, metadata.nonce);
|
|
380
210
|
|
|
381
211
|
if (
|
|
382
212
|
market == 0 ||
|
|
@@ -386,7 +216,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
386
216
|
}
|
|
387
217
|
|
|
388
218
|
if (_priorityFee_Evvm > 0) {
|
|
389
|
-
|
|
219
|
+
requestPay(
|
|
390
220
|
user,
|
|
391
221
|
MATE_TOKEN_ADDRESS,
|
|
392
222
|
_nonce_Evvm,
|
|
@@ -405,30 +235,19 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
405
235
|
|
|
406
236
|
ordersInsideMarket[market][metadata.orderId].seller = address(0);
|
|
407
237
|
|
|
408
|
-
if (
|
|
238
|
+
if (evvm.isAddressStaker(msg.sender)) {
|
|
409
239
|
makeCaPay(
|
|
410
240
|
msg.sender,
|
|
411
241
|
MATE_TOKEN_ADDRESS,
|
|
412
242
|
_priorityFee_Evvm > 0
|
|
413
|
-
? ((
|
|
414
|
-
|
|
415
|
-
: (Evvm(evvmAddress).getRewardAmount() * 2)
|
|
243
|
+
? ((evvm.getRewardAmount() * 3) + _priorityFee_Evvm)
|
|
244
|
+
: (evvm.getRewardAmount() * 2)
|
|
416
245
|
);
|
|
417
246
|
}
|
|
418
247
|
marketMetadata[market].ordersAvailable--;
|
|
419
|
-
|
|
248
|
+
markAsyncNonceAsUsed(user, metadata.nonce);
|
|
420
249
|
}
|
|
421
250
|
|
|
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
251
|
function dispatchOrder_fillPropotionalFee(
|
|
433
252
|
address user,
|
|
434
253
|
MetadataDispatchOrder memory metadata,
|
|
@@ -439,7 +258,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
439
258
|
) external {
|
|
440
259
|
if (
|
|
441
260
|
!SignatureUtils.verifyMessageSignedForDispatchOrder(
|
|
442
|
-
|
|
261
|
+
evvm.getEvvmID(),
|
|
443
262
|
user,
|
|
444
263
|
metadata.nonce,
|
|
445
264
|
metadata.tokenA,
|
|
@@ -453,15 +272,13 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
453
272
|
|
|
454
273
|
uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
|
|
455
274
|
|
|
456
|
-
|
|
457
|
-
revert("Invalid nonce");
|
|
458
|
-
}
|
|
275
|
+
verifyAsyncNonce(user, metadata.nonce);
|
|
459
276
|
|
|
460
277
|
if (
|
|
461
278
|
market == 0 ||
|
|
462
279
|
ordersInsideMarket[market][metadata.orderId].seller == address(0)
|
|
463
280
|
) {
|
|
464
|
-
revert();
|
|
281
|
+
revert("Invalid order");
|
|
465
282
|
}
|
|
466
283
|
|
|
467
284
|
uint256 fee = calculateFillPropotionalFee(
|
|
@@ -475,7 +292,7 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
475
292
|
revert("Insuficient amountOfTokenToFill");
|
|
476
293
|
}
|
|
477
294
|
|
|
478
|
-
|
|
295
|
+
requestPay(
|
|
479
296
|
user,
|
|
480
297
|
metadata.tokenB,
|
|
481
298
|
_nonce_Evvm,
|
|
@@ -534,33 +351,22 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
534
351
|
ordersInsideMarket[market][metadata.orderId].amountA
|
|
535
352
|
);
|
|
536
353
|
|
|
537
|
-
if (
|
|
354
|
+
if (evvm.isAddressStaker(msg.sender)) {
|
|
538
355
|
makeCaPay(
|
|
539
356
|
msg.sender,
|
|
540
357
|
MATE_TOKEN_ADDRESS,
|
|
541
358
|
metadata.amountOfTokenBToFill >
|
|
542
359
|
ordersInsideMarket[market][metadata.orderId].amountB + fee
|
|
543
|
-
?
|
|
544
|
-
:
|
|
360
|
+
? evvm.getRewardAmount() * 5
|
|
361
|
+
: evvm.getRewardAmount() * 4
|
|
545
362
|
);
|
|
546
363
|
}
|
|
547
364
|
|
|
548
365
|
ordersInsideMarket[market][metadata.orderId].seller = address(0);
|
|
549
366
|
marketMetadata[market].ordersAvailable--;
|
|
550
|
-
|
|
367
|
+
markAsyncNonceAsUsed(user, metadata.nonce);
|
|
551
368
|
}
|
|
552
369
|
|
|
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
370
|
function dispatchOrder_fillFixedFee(
|
|
565
371
|
address user,
|
|
566
372
|
MetadataDispatchOrder memory metadata,
|
|
@@ -568,11 +374,11 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
568
374
|
uint256 _nonce_Evvm,
|
|
569
375
|
bool _priority_Evvm,
|
|
570
376
|
bytes memory _signature_Evvm,
|
|
571
|
-
uint256 maxFillFixedFee
|
|
377
|
+
uint256 maxFillFixedFee ///@dev for testing purposes
|
|
572
378
|
) external {
|
|
573
379
|
if (
|
|
574
380
|
!SignatureUtils.verifyMessageSignedForDispatchOrder(
|
|
575
|
-
|
|
381
|
+
evvm.getEvvmID(),
|
|
576
382
|
user,
|
|
577
383
|
metadata.nonce,
|
|
578
384
|
metadata.tokenA,
|
|
@@ -581,20 +387,18 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
581
387
|
metadata.signature
|
|
582
388
|
)
|
|
583
389
|
) {
|
|
584
|
-
revert();
|
|
390
|
+
revert("Invalid signature");
|
|
585
391
|
}
|
|
586
392
|
|
|
587
393
|
uint256 market = findMarket(metadata.tokenA, metadata.tokenB);
|
|
588
394
|
|
|
589
|
-
|
|
590
|
-
revert();
|
|
591
|
-
}
|
|
395
|
+
verifyAsyncNonce(user, metadata.nonce);
|
|
592
396
|
|
|
593
397
|
if (
|
|
594
398
|
market == 0 ||
|
|
595
399
|
ordersInsideMarket[market][metadata.orderId].seller == address(0)
|
|
596
400
|
) {
|
|
597
|
-
revert();
|
|
401
|
+
revert("Invalid order");
|
|
598
402
|
}
|
|
599
403
|
|
|
600
404
|
(uint256 fee, uint256 fee10) = calculateFillFixedFee(
|
|
@@ -606,10 +410,10 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
606
410
|
metadata.amountOfTokenBToFill <
|
|
607
411
|
ordersInsideMarket[market][metadata.orderId].amountB + fee - fee10
|
|
608
412
|
) {
|
|
609
|
-
revert();
|
|
413
|
+
revert("Insuficient amountOfTokenBToFill");
|
|
610
414
|
}
|
|
611
415
|
|
|
612
|
-
|
|
416
|
+
requestPay(
|
|
613
417
|
user,
|
|
614
418
|
metadata.tokenB,
|
|
615
419
|
_nonce_Evvm,
|
|
@@ -672,42 +476,30 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
672
476
|
ordersInsideMarket[market][metadata.orderId].amountA
|
|
673
477
|
);
|
|
674
478
|
|
|
675
|
-
if (
|
|
479
|
+
if (evvm.isAddressStaker(msg.sender)) {
|
|
676
480
|
makeCaPay(
|
|
677
481
|
msg.sender,
|
|
678
482
|
MATE_TOKEN_ADDRESS,
|
|
679
483
|
metadata.amountOfTokenBToFill >
|
|
680
484
|
ordersInsideMarket[market][metadata.orderId].amountB + fee
|
|
681
|
-
?
|
|
682
|
-
:
|
|
485
|
+
? evvm.getRewardAmount() * 5
|
|
486
|
+
: evvm.getRewardAmount() * 4
|
|
683
487
|
);
|
|
684
488
|
}
|
|
685
489
|
|
|
686
490
|
ordersInsideMarket[market][metadata.orderId].seller = address(0);
|
|
687
491
|
marketMetadata[market].ordersAvailable--;
|
|
688
|
-
|
|
492
|
+
markAsyncNonceAsUsed(user, metadata.nonce);
|
|
689
493
|
}
|
|
690
494
|
|
|
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
|
-
*/
|
|
495
|
+
//devolver el 0.05% del monto de la orden
|
|
697
496
|
function calculateFillPropotionalFee(
|
|
698
497
|
uint256 amount
|
|
699
498
|
) internal view returns (uint256 fee) {
|
|
499
|
+
///@dev get the % of the amount
|
|
700
500
|
fee = (amount * percentageFee) / 10_000;
|
|
701
501
|
}
|
|
702
502
|
|
|
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
503
|
function calculateFillFixedFee(
|
|
712
504
|
uint256 amount,
|
|
713
505
|
uint256 maxFillFixedFee
|
|
@@ -720,13 +512,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
720
512
|
}
|
|
721
513
|
}
|
|
722
514
|
|
|
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
515
|
function createMarket(
|
|
731
516
|
address tokenA,
|
|
732
517
|
address tokenB
|
|
@@ -737,95 +522,18 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
737
522
|
return marketCount;
|
|
738
523
|
}
|
|
739
524
|
|
|
740
|
-
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
741
|
-
// Tools for Evvm
|
|
742
|
-
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
743
|
-
|
|
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
|
-
function makePay(
|
|
756
|
-
address _user_Evvm,
|
|
757
|
-
address _token_Evvm,
|
|
758
|
-
uint256 _nonce_Evvm,
|
|
759
|
-
uint256 _ammount_Evvm,
|
|
760
|
-
uint256 _priorityFee_Evvm,
|
|
761
|
-
bool _priority_Evvm,
|
|
762
|
-
bytes memory _signature_Evvm
|
|
763
|
-
) internal {
|
|
764
|
-
Evvm(evvmAddress).pay(
|
|
765
|
-
_user_Evvm,
|
|
766
|
-
address(this),
|
|
767
|
-
"",
|
|
768
|
-
_token_Evvm,
|
|
769
|
-
_ammount_Evvm,
|
|
770
|
-
_priorityFee_Evvm,
|
|
771
|
-
_nonce_Evvm,
|
|
772
|
-
_priority_Evvm,
|
|
773
|
-
address(this),
|
|
774
|
-
_signature_Evvm
|
|
775
|
-
);
|
|
776
|
-
}
|
|
777
|
-
|
|
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
|
-
function makeCaPay(
|
|
786
|
-
address _user_Evvm,
|
|
787
|
-
address _token_Evvm,
|
|
788
|
-
uint256 _ammount_Evvm
|
|
789
|
-
) internal {
|
|
790
|
-
Evvm(evvmAddress).caPay(_user_Evvm, _token_Evvm, _ammount_Evvm);
|
|
791
|
-
}
|
|
792
|
-
|
|
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
|
-
function makeDisperseCaPay(
|
|
801
|
-
EvvmStructs.DisperseCaPayMetadata[] memory toData,
|
|
802
|
-
address token,
|
|
803
|
-
uint256 amount
|
|
804
|
-
) internal {
|
|
805
|
-
Evvm(evvmAddress).disperseCaPay(toData, token, amount);
|
|
806
|
-
}
|
|
807
|
-
|
|
808
525
|
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
809
526
|
// Admin tools
|
|
810
527
|
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
811
528
|
|
|
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
529
|
function proposeOwner(address _owner) external {
|
|
818
530
|
if (msg.sender != owner) {
|
|
819
531
|
revert();
|
|
820
532
|
}
|
|
821
533
|
owner_proposal = _owner;
|
|
822
|
-
owner_timeToAccept = block.timestamp + 1
|
|
534
|
+
owner_timeToAccept = block.timestamp + 1 days;
|
|
823
535
|
}
|
|
824
536
|
|
|
825
|
-
/**
|
|
826
|
-
* @notice Rejects the current owner change proposal
|
|
827
|
-
* @dev Only proposed owner can reject before deadline expires
|
|
828
|
-
*/
|
|
829
537
|
function rejectProposeOwner() external {
|
|
830
538
|
if (
|
|
831
539
|
msg.sender != owner_proposal || block.timestamp > owner_timeToAccept
|
|
@@ -835,10 +543,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
835
543
|
owner_proposal = address(0);
|
|
836
544
|
}
|
|
837
545
|
|
|
838
|
-
/**
|
|
839
|
-
* @notice Accepts ownership transfer after time delay
|
|
840
|
-
* @dev Only proposed owner can accept after 1-day waiting period
|
|
841
|
-
*/
|
|
842
546
|
function acceptOwner() external {
|
|
843
547
|
if (
|
|
844
548
|
msg.sender != owner_proposal || block.timestamp > owner_timeToAccept
|
|
@@ -849,13 +553,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
849
553
|
owner_proposal = address(0);
|
|
850
554
|
}
|
|
851
555
|
|
|
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
556
|
function proposeFillFixedPercentage(
|
|
860
557
|
uint256 _seller,
|
|
861
558
|
uint256 _service,
|
|
@@ -868,13 +565,9 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
868
565
|
revert();
|
|
869
566
|
}
|
|
870
567
|
rewardPercentage_proposal = Percentage(_seller, _service, _mateStaker);
|
|
871
|
-
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1
|
|
568
|
+
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
|
|
872
569
|
}
|
|
873
570
|
|
|
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
571
|
function rejectProposeFillFixedPercentage() external {
|
|
879
572
|
if (
|
|
880
573
|
msg.sender != owner ||
|
|
@@ -885,10 +578,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
885
578
|
rewardPercentage_proposal = Percentage(0, 0, 0);
|
|
886
579
|
}
|
|
887
580
|
|
|
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
581
|
function acceptFillFixedPercentage() external {
|
|
893
582
|
if (
|
|
894
583
|
msg.sender != owner ||
|
|
@@ -899,13 +588,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
899
588
|
rewardPercentage = rewardPercentage_proposal;
|
|
900
589
|
}
|
|
901
590
|
|
|
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
591
|
function proposeFillPropotionalPercentage(
|
|
910
592
|
uint256 _seller,
|
|
911
593
|
uint256 _service,
|
|
@@ -915,13 +597,9 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
915
597
|
revert();
|
|
916
598
|
}
|
|
917
599
|
rewardPercentage_proposal = Percentage(_seller, _service, _mateStaker);
|
|
918
|
-
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1
|
|
600
|
+
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
|
|
919
601
|
}
|
|
920
602
|
|
|
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
603
|
function rejectProposeFillPropotionalPercentage() external {
|
|
926
604
|
if (
|
|
927
605
|
msg.sender != owner ||
|
|
@@ -932,10 +610,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
932
610
|
rewardPercentage_proposal = Percentage(0, 0, 0);
|
|
933
611
|
}
|
|
934
612
|
|
|
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
613
|
function acceptFillPropotionalPercentage() external {
|
|
940
614
|
if (
|
|
941
615
|
msg.sender != owner ||
|
|
@@ -946,23 +620,14 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
946
620
|
rewardPercentage = rewardPercentage_proposal;
|
|
947
621
|
}
|
|
948
622
|
|
|
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
623
|
function proposePercentageFee(uint256 _percentageFee) external {
|
|
955
624
|
if (msg.sender != owner) {
|
|
956
625
|
revert();
|
|
957
626
|
}
|
|
958
627
|
percentageFee_proposal = _percentageFee;
|
|
959
|
-
percentageFee_timeToAccept = block.timestamp + 1
|
|
628
|
+
percentageFee_timeToAccept = block.timestamp + 1 days;
|
|
960
629
|
}
|
|
961
630
|
|
|
962
|
-
/**
|
|
963
|
-
* @notice Rejects the current percentage fee proposal
|
|
964
|
-
* @dev Only owner can reject before deadline expires, resets proposal to zero
|
|
965
|
-
*/
|
|
966
631
|
function rejectProposePercentageFee() external {
|
|
967
632
|
if (
|
|
968
633
|
msg.sender != owner || block.timestamp > percentageFee_timeToAccept
|
|
@@ -972,10 +637,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
972
637
|
percentageFee_proposal = 0;
|
|
973
638
|
}
|
|
974
639
|
|
|
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
640
|
function acceptPercentageFee() external {
|
|
980
641
|
if (
|
|
981
642
|
msg.sender != owner || block.timestamp > percentageFee_timeToAccept
|
|
@@ -985,11 +646,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
985
646
|
percentageFee = percentageFee_proposal;
|
|
986
647
|
}
|
|
987
648
|
|
|
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
649
|
function proposeMaxLimitFillFixedFee(
|
|
994
650
|
uint256 _maxLimitFillFixedFee
|
|
995
651
|
) external {
|
|
@@ -997,13 +653,9 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
997
653
|
revert();
|
|
998
654
|
}
|
|
999
655
|
maxLimitFillFixedFee_proposal = _maxLimitFillFixedFee;
|
|
1000
|
-
maxLimitFillFixedFee_timeToAccept = block.timestamp + 1
|
|
656
|
+
maxLimitFillFixedFee_timeToAccept = block.timestamp + 1 days;
|
|
1001
657
|
}
|
|
1002
658
|
|
|
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
659
|
function rejectProposeMaxLimitFillFixedFee() external {
|
|
1008
660
|
if (
|
|
1009
661
|
msg.sender != owner ||
|
|
@@ -1014,10 +666,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1014
666
|
maxLimitFillFixedFee_proposal = 0;
|
|
1015
667
|
}
|
|
1016
668
|
|
|
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
669
|
function acceptMaxLimitFillFixedFee() external {
|
|
1022
670
|
if (
|
|
1023
671
|
msg.sender != owner ||
|
|
@@ -1028,13 +676,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1028
676
|
maxLimitFillFixedFee = maxLimitFillFixedFee_proposal;
|
|
1029
677
|
}
|
|
1030
678
|
|
|
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
679
|
function proposeWithdrawal(
|
|
1039
680
|
address _tokenToWithdraw,
|
|
1040
681
|
uint256 _amountToWithdraw,
|
|
@@ -1049,13 +690,9 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1049
690
|
tokenToWithdraw = _tokenToWithdraw;
|
|
1050
691
|
amountToWithdraw = _amountToWithdraw;
|
|
1051
692
|
recipientToWithdraw = _to;
|
|
1052
|
-
timeToWithdrawal = block.timestamp + 1
|
|
693
|
+
timeToWithdrawal = block.timestamp + 1 days;
|
|
1053
694
|
}
|
|
1054
695
|
|
|
1055
|
-
/**
|
|
1056
|
-
* @notice Rejects the current withdrawal proposal
|
|
1057
|
-
* @dev Only owner can reject before deadline expires, clears all withdrawal data
|
|
1058
|
-
*/
|
|
1059
696
|
function rejectProposeWithdrawal() external {
|
|
1060
697
|
if (msg.sender != owner || block.timestamp > timeToWithdrawal) {
|
|
1061
698
|
revert();
|
|
@@ -1066,10 +703,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1066
703
|
timeToWithdrawal = 0;
|
|
1067
704
|
}
|
|
1068
705
|
|
|
1069
|
-
/**
|
|
1070
|
-
* @notice Executes the withdrawal proposal after time delay
|
|
1071
|
-
* @dev Transfers tokens via EVVM, updates balance, and clears withdrawal data
|
|
1072
|
-
*/
|
|
1073
706
|
function acceptWithdrawal() external {
|
|
1074
707
|
if (msg.sender != owner || block.timestamp > timeToWithdrawal) {
|
|
1075
708
|
revert();
|
|
@@ -1083,38 +716,22 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1083
716
|
timeToWithdrawal = 0;
|
|
1084
717
|
}
|
|
1085
718
|
|
|
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
719
|
function stake(uint256 amount) external {
|
|
1092
720
|
if (
|
|
1093
721
|
msg.sender != owner ||
|
|
1094
|
-
amount *
|
|
722
|
+
amount * staking.priceOfStaking() >
|
|
1095
723
|
balancesOfContract[0x0000000000000000000000000000000000000001]
|
|
1096
724
|
) revert();
|
|
1097
725
|
|
|
1098
726
|
_makeStakeService(amount);
|
|
1099
727
|
}
|
|
1100
728
|
|
|
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
729
|
function unstake(uint256 amount) external {
|
|
1107
730
|
if (msg.sender != owner) revert();
|
|
1108
731
|
|
|
1109
732
|
_makeUnstakeService(amount);
|
|
1110
733
|
}
|
|
1111
734
|
|
|
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
735
|
function addBalance(address _token, uint256 _amount) external {
|
|
1119
736
|
if (msg.sender != owner) {
|
|
1120
737
|
revert();
|
|
@@ -1125,12 +742,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1125
742
|
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
1126
743
|
//getters
|
|
1127
744
|
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
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
745
|
function getAllMarketOrders(
|
|
1135
746
|
uint256 market
|
|
1136
747
|
) public view returns (OrderForGetter[] memory orders) {
|
|
@@ -1150,12 +761,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1150
761
|
return orders;
|
|
1151
762
|
}
|
|
1152
763
|
|
|
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
764
|
function getOrder(
|
|
1160
765
|
uint256 market,
|
|
1161
766
|
uint256 orderId
|
|
@@ -1164,13 +769,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1164
769
|
return order;
|
|
1165
770
|
}
|
|
1166
771
|
|
|
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
772
|
function getMyOrdersInSpecificMarket(
|
|
1175
773
|
address user,
|
|
1176
774
|
uint256 market
|
|
@@ -1191,12 +789,6 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1191
789
|
return orders;
|
|
1192
790
|
}
|
|
1193
791
|
|
|
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
792
|
function findMarket(
|
|
1201
793
|
address tokenA,
|
|
1202
794
|
address tokenB
|
|
@@ -1204,22 +796,12 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1204
796
|
return marketId[tokenA][tokenB];
|
|
1205
797
|
}
|
|
1206
798
|
|
|
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
799
|
function getMarketMetadata(
|
|
1213
800
|
uint256 market
|
|
1214
801
|
) public view returns (MarketInformation memory) {
|
|
1215
802
|
return marketMetadata[market];
|
|
1216
803
|
}
|
|
1217
804
|
|
|
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
805
|
function getAllMarketsMetadata()
|
|
1224
806
|
public
|
|
1225
807
|
view
|
|
@@ -1234,59 +816,24 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1234
816
|
return markets;
|
|
1235
817
|
}
|
|
1236
818
|
|
|
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
|
-
function checkIfANonceP2PSwapIsUsed(
|
|
1245
|
-
address user,
|
|
1246
|
-
uint256 nonce
|
|
1247
|
-
) public view returns (bool) {
|
|
1248
|
-
return nonceP2PSwap[user][nonce];
|
|
1249
|
-
}
|
|
1250
|
-
|
|
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
819
|
function getBalanceOfContract(
|
|
1257
820
|
address token
|
|
1258
821
|
) external view returns (uint256) {
|
|
1259
822
|
return balancesOfContract[token];
|
|
1260
823
|
}
|
|
1261
824
|
|
|
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
825
|
function getOwnerProposal() external view returns (address) {
|
|
1267
826
|
return owner_proposal;
|
|
1268
827
|
}
|
|
1269
828
|
|
|
1270
|
-
/**
|
|
1271
|
-
* @notice Returns the current contract owner address
|
|
1272
|
-
* @return Address of the current contract owner
|
|
1273
|
-
*/
|
|
1274
829
|
function getOwner() external view returns (address) {
|
|
1275
830
|
return owner;
|
|
1276
831
|
}
|
|
1277
832
|
|
|
1278
|
-
/**
|
|
1279
|
-
* @notice Returns the deadline timestamp for accepting ownership transfer
|
|
1280
|
-
* @return Timestamp until which the ownership proposal can be accepted
|
|
1281
|
-
*/
|
|
1282
833
|
function getOwnerTimeToAccept() external view returns (uint256) {
|
|
1283
834
|
return owner_timeToAccept;
|
|
1284
835
|
}
|
|
1285
836
|
|
|
1286
|
-
/**
|
|
1287
|
-
* @notice Returns the currently proposed reward percentage distribution
|
|
1288
|
-
* @return Percentage struct with proposed seller, service, and staker percentages
|
|
1289
|
-
*/
|
|
1290
837
|
function getRewardPercentageProposal()
|
|
1291
838
|
external
|
|
1292
839
|
view
|
|
@@ -1295,54 +842,26 @@ contract P2PSwap is StakingServiceHooks {
|
|
|
1295
842
|
return rewardPercentage_proposal;
|
|
1296
843
|
}
|
|
1297
844
|
|
|
1298
|
-
/**
|
|
1299
|
-
* @notice Returns the current active reward percentage distribution
|
|
1300
|
-
* @return Percentage struct with active seller, service, and staker percentages
|
|
1301
|
-
*/
|
|
1302
845
|
function getRewardPercentage() external view returns (Percentage memory) {
|
|
1303
846
|
return rewardPercentage;
|
|
1304
847
|
}
|
|
1305
848
|
|
|
1306
|
-
/**
|
|
1307
|
-
* @notice Returns the currently proposed percentage fee value
|
|
1308
|
-
* @return Proposed percentage fee in basis points for proportional fee calculation
|
|
1309
|
-
*/
|
|
1310
849
|
function getProposalPercentageFee() external view returns (uint256) {
|
|
1311
850
|
return percentageFee_proposal;
|
|
1312
851
|
}
|
|
1313
852
|
|
|
1314
|
-
/**
|
|
1315
|
-
* @notice Returns the current active percentage fee value
|
|
1316
|
-
* @return Active percentage fee in basis points for proportional fee calculation
|
|
1317
|
-
*/
|
|
1318
853
|
function getPercentageFee() external view returns (uint256) {
|
|
1319
854
|
return percentageFee;
|
|
1320
855
|
}
|
|
1321
856
|
|
|
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
857
|
function getMaxLimitFillFixedFeeProposal() external view returns (uint256) {
|
|
1327
858
|
return maxLimitFillFixedFee_proposal;
|
|
1328
859
|
}
|
|
1329
860
|
|
|
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
861
|
function getMaxLimitFillFixedFee() external view returns (uint256) {
|
|
1335
862
|
return maxLimitFillFixedFee;
|
|
1336
863
|
}
|
|
1337
864
|
|
|
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
865
|
function getProposedWithdrawal()
|
|
1347
866
|
external
|
|
1348
867
|
view
|