@evvm/testnet-contracts 3.0.1 → 3.0.2
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/README.md +2 -0
- package/contracts/core/Core.sol +323 -127
- package/contracts/core/lib/CoreStorage.sol +60 -24
- package/contracts/p2pSwap/P2PSwap.sol +183 -141
- package/library/errors/CoreError.sol +25 -11
- package/library/structs/P2PSwapStructs.sol +1 -57
- package/library/utils/governance/ProposalStructs.sol +6 -0
- package/package.json +1 -1
|
@@ -17,6 +17,9 @@ import {CoreStructs} from "@evvm/testnet-contracts/interfaces/ICore.sol";
|
|
|
17
17
|
import {
|
|
18
18
|
AdvancedStrings
|
|
19
19
|
} from "@evvm/testnet-contracts/library/utils/AdvancedStrings.sol";
|
|
20
|
+
import {
|
|
21
|
+
ProposalStructs
|
|
22
|
+
} from "@evvm/testnet-contracts/library/utils/governance/ProposalStructs.sol";
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
/$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$
|
|
@@ -38,26 +41,18 @@ import {
|
|
|
38
41
|
* Integrates with Core.sol for asset locking and settlements, and Staking.sol for validator rewards.
|
|
39
42
|
*/
|
|
40
43
|
|
|
41
|
-
contract P2PSwap is EvvmService
|
|
44
|
+
contract P2PSwap is EvvmService {
|
|
42
45
|
address owner;
|
|
43
46
|
address owner_proposal;
|
|
44
47
|
uint256 owner_timeToAccept;
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
address constant ETH_ADDRESS = 0x0000000000000000000000000000000000000000;
|
|
49
|
-
|
|
50
|
-
Percentage rewardPercentage;
|
|
51
|
-
Percentage rewardPercentage_proposal;
|
|
49
|
+
Structs.Percentage rewardPercentage;
|
|
50
|
+
Structs.Percentage rewardPercentage_proposal;
|
|
52
51
|
uint256 rewardPercentage_timeToAcceptNewChange;
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
uint256 percentageFee_proposal;
|
|
56
|
-
uint256 percentageFee_timeToAccept;
|
|
53
|
+
ProposalStructs.UintTypeProposal percentageFee;
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
uint256 maxLimitFillFixedFee_proposal;
|
|
60
|
-
uint256 maxLimitFillFixedFee_timeToAccept;
|
|
55
|
+
ProposalStructs.UintTypeProposal maxLimitFillFixedFee;
|
|
61
56
|
|
|
62
57
|
address tokenToWithdraw;
|
|
63
58
|
uint256 amountToWithdraw;
|
|
@@ -68,9 +63,9 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
68
63
|
|
|
69
64
|
mapping(address tokenA => mapping(address tokenB => uint256 id)) marketId;
|
|
70
65
|
|
|
71
|
-
mapping(uint256 id => MarketInformation info) marketMetadata;
|
|
66
|
+
mapping(uint256 id => Structs.MarketInformation info) marketMetadata;
|
|
72
67
|
|
|
73
|
-
mapping(uint256 idMarket => mapping(uint256 idOrder => Order)) ordersInsideMarket;
|
|
68
|
+
mapping(uint256 idMarket => mapping(uint256 idOrder => Structs.Order)) ordersInsideMarket;
|
|
74
69
|
|
|
75
70
|
mapping(address => uint256) balancesOfContract;
|
|
76
71
|
|
|
@@ -80,9 +75,9 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
80
75
|
address _owner
|
|
81
76
|
) EvvmService(_coreAddress, _stakingAddress) {
|
|
82
77
|
owner = _owner;
|
|
83
|
-
maxLimitFillFixedFee = 0.001 ether;
|
|
84
|
-
percentageFee = 500;
|
|
85
|
-
rewardPercentage = Percentage({
|
|
78
|
+
maxLimitFillFixedFee.current = 0.001 ether;
|
|
79
|
+
percentageFee.current = 500;
|
|
80
|
+
rewardPercentage = Structs.Percentage({
|
|
86
81
|
seller: 5000,
|
|
87
82
|
service: 4000,
|
|
88
83
|
mateStaker: 1000
|
|
@@ -94,7 +89,12 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
94
89
|
* @dev Locks tokenA in Core.sol and opens an order slot.
|
|
95
90
|
* Markets are automatically created for new token pairs.
|
|
96
91
|
* @param user Seller address.
|
|
97
|
-
* @param
|
|
92
|
+
* @param tokenA Address of the token being sold.
|
|
93
|
+
* @param tokenB Address of the token being bought.
|
|
94
|
+
* @param amountA Amount of tokenA offered.
|
|
95
|
+
* @param amountB Amount of tokenB requested.
|
|
96
|
+
* @param originExecutor executor address for signature validation.
|
|
97
|
+
* @param nonce Nonce for service execution (async).
|
|
98
98
|
* @param signature Seller's authorization signature.
|
|
99
99
|
* @param priorityFeePay Optional priority fee for the executor.
|
|
100
100
|
* @param noncePay Nonce for the Core payment (locks tokenA).
|
|
@@ -104,7 +104,12 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
104
104
|
*/
|
|
105
105
|
function makeOrder(
|
|
106
106
|
address user,
|
|
107
|
-
|
|
107
|
+
address tokenA,
|
|
108
|
+
address tokenB,
|
|
109
|
+
uint256 amountA,
|
|
110
|
+
uint256 amountB,
|
|
111
|
+
address originExecutor,
|
|
112
|
+
uint256 nonce,
|
|
108
113
|
bytes memory signature,
|
|
109
114
|
uint256 priorityFeePay,
|
|
110
115
|
uint256 noncePay,
|
|
@@ -112,31 +117,26 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
112
117
|
) external returns (uint256 market, uint256 orderId) {
|
|
113
118
|
core.validateAndConsumeNonce(
|
|
114
119
|
user,
|
|
115
|
-
Hash.hashDataForMakeOrder(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
metadata.amountA,
|
|
119
|
-
metadata.amountB
|
|
120
|
-
),
|
|
121
|
-
address(0),
|
|
122
|
-
metadata.nonce,
|
|
120
|
+
Hash.hashDataForMakeOrder(tokenA, tokenB, amountA, amountB),
|
|
121
|
+
originExecutor,
|
|
122
|
+
nonce,
|
|
123
123
|
true,
|
|
124
124
|
signature
|
|
125
125
|
);
|
|
126
126
|
|
|
127
127
|
requestPay(
|
|
128
128
|
user,
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
tokenA,
|
|
130
|
+
amountA,
|
|
131
131
|
priorityFeePay,
|
|
132
132
|
noncePay,
|
|
133
133
|
true,
|
|
134
134
|
signaturePay
|
|
135
135
|
);
|
|
136
136
|
|
|
137
|
-
market = findMarket(
|
|
137
|
+
market = findMarket(tokenA, tokenB);
|
|
138
138
|
if (market == 0) {
|
|
139
|
-
market = createMarket(
|
|
139
|
+
market = createMarket(tokenA, tokenB);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
if (
|
|
@@ -156,16 +156,16 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
156
156
|
marketMetadata[market].ordersAvailable++;
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
ordersInsideMarket[market][orderId] = Order(
|
|
159
|
+
ordersInsideMarket[market][orderId] = Structs.Order(
|
|
160
160
|
user,
|
|
161
|
-
|
|
162
|
-
|
|
161
|
+
amountA,
|
|
162
|
+
amountB
|
|
163
163
|
);
|
|
164
164
|
|
|
165
165
|
if (core.isAddressStaker(msg.sender)) {
|
|
166
166
|
if (priorityFeePay > 0) {
|
|
167
167
|
// send the executor the priorityFee
|
|
168
|
-
makeCaPay(msg.sender,
|
|
168
|
+
makeCaPay(msg.sender, tokenA, priorityFeePay);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
|
|
@@ -203,39 +203,45 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
203
203
|
* - Market slot becomes available for reuse
|
|
204
204
|
*
|
|
205
205
|
* @param user Address that owns the order
|
|
206
|
-
* @param
|
|
206
|
+
* @param tokenA Token A in pair
|
|
207
|
+
* @param tokenB Token B in pair
|
|
208
|
+
* @param orderId Order ID to cancel
|
|
209
|
+
* @param originExecutor Executor address for signature validation
|
|
210
|
+
* @param nonce Nonce for service execution (async)
|
|
211
|
+
* @param signature Signature for cancellation authorization
|
|
207
212
|
* @param priorityFeePay Optional priority fee for staker
|
|
208
213
|
* @param noncePay Nonce for EVVM payment transaction
|
|
209
214
|
* @param signaturePay Signature for EVVM payment
|
|
210
215
|
*/
|
|
211
216
|
function cancelOrder(
|
|
212
217
|
address user,
|
|
213
|
-
|
|
218
|
+
address tokenA,
|
|
219
|
+
address tokenB,
|
|
220
|
+
uint256 orderId,
|
|
221
|
+
address originExecutor,
|
|
222
|
+
uint256 nonce,
|
|
223
|
+
bytes memory signature,
|
|
214
224
|
uint256 priorityFeePay,
|
|
215
225
|
uint256 noncePay,
|
|
216
226
|
bytes memory signaturePay
|
|
217
227
|
) external {
|
|
218
228
|
core.validateAndConsumeNonce(
|
|
219
229
|
user,
|
|
220
|
-
Hash.hashDataForCancelOrder(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
metadata.orderId
|
|
224
|
-
),
|
|
225
|
-
metadata.originExecutor,
|
|
226
|
-
metadata.nonce,
|
|
230
|
+
Hash.hashDataForCancelOrder(tokenA, tokenB, orderId),
|
|
231
|
+
originExecutor,
|
|
232
|
+
nonce,
|
|
227
233
|
true,
|
|
228
|
-
|
|
234
|
+
signature
|
|
229
235
|
);
|
|
230
236
|
|
|
231
|
-
uint256 market = findMarket(
|
|
237
|
+
uint256 market = findMarket(tokenA, tokenB);
|
|
232
238
|
|
|
233
|
-
_validateOrderOwnership(market,
|
|
239
|
+
_validateOrderOwnership(market, orderId, user);
|
|
234
240
|
|
|
235
241
|
if (priorityFeePay > 0) {
|
|
236
242
|
requestPay(
|
|
237
243
|
user,
|
|
238
|
-
|
|
244
|
+
core.getPrincipalTokenAddress(),
|
|
239
245
|
0,
|
|
240
246
|
priorityFeePay,
|
|
241
247
|
noncePay,
|
|
@@ -244,28 +250,28 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
244
250
|
);
|
|
245
251
|
}
|
|
246
252
|
|
|
247
|
-
makeCaPay(
|
|
248
|
-
user,
|
|
249
|
-
metadata.tokenA,
|
|
250
|
-
ordersInsideMarket[market][metadata.orderId].amountA
|
|
251
|
-
);
|
|
253
|
+
makeCaPay(user, tokenA, ordersInsideMarket[market][orderId].amountA);
|
|
252
254
|
|
|
253
|
-
_clearOrderAndUpdateMarket(market,
|
|
255
|
+
_clearOrderAndUpdateMarket(market, orderId);
|
|
254
256
|
|
|
255
257
|
if (core.isAddressStaker(msg.sender) && priorityFeePay > 0) {
|
|
256
|
-
makeCaPay(
|
|
258
|
+
makeCaPay(
|
|
259
|
+
msg.sender,
|
|
260
|
+
core.getPrincipalTokenAddress(),
|
|
261
|
+
priorityFeePay
|
|
262
|
+
);
|
|
257
263
|
}
|
|
258
264
|
_rewardExecutor(msg.sender, priorityFeePay > 0 ? 3 : 2);
|
|
259
265
|
}
|
|
260
266
|
|
|
261
267
|
/**
|
|
262
268
|
* @notice Fills order using proportional fee model
|
|
263
|
-
* @dev Fee = amountB * percentageFee / 10,000
|
|
269
|
+
* @dev Fee = amountB * percentageFee.current / 10,000
|
|
264
270
|
*
|
|
265
271
|
* Proportional Fee Execution Flow:
|
|
266
272
|
* 1. Validates signature via Core.sol
|
|
267
273
|
* 2. Validates market and order exist
|
|
268
|
-
* 3. Calculates fee: (amountB * percentageFee) / 10,000
|
|
274
|
+
* 3. Calculates fee: (amountB * percentageFee.current) / 10,000
|
|
269
275
|
* 4. Validates amountOfTokenBToFill >= amountB + fee
|
|
270
276
|
* 5. Collects tokenB + fee via Evvm.requestPay
|
|
271
277
|
* 6. Handles overpayment refund if any
|
|
@@ -291,51 +297,59 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
291
297
|
*
|
|
292
298
|
* Fee Calculation:
|
|
293
299
|
* - Base: amountB (order requirement)
|
|
294
|
-
* - Fee: (amountB * percentageFee) / 10,000
|
|
300
|
+
* - Fee: (amountB * percentageFee.current) / 10,000
|
|
295
301
|
* - Total: amountB + fee
|
|
296
302
|
* - Example: 5% fee = 500 / 10,000
|
|
297
303
|
*
|
|
298
304
|
* @param user Address filling the order (buyer)
|
|
299
|
-
* @param
|
|
305
|
+
* @param tokenA Token A in pair
|
|
306
|
+
* @param tokenB Token B in pair
|
|
307
|
+
* @param orderId Order ID to fill
|
|
308
|
+
* @param amountOfTokenBToFill Amount of tokenB buyer is paying (must cover order + fee)
|
|
309
|
+
* @param originExecutor Executor address for signature validation
|
|
310
|
+
* @param nonce Nonce for service execution (async)
|
|
311
|
+
* @param signature Signature for dispatch authorization
|
|
300
312
|
* @param priorityFeePay Optional priority fee for staker
|
|
301
313
|
* @param noncePay Nonce for EVVM payment transaction
|
|
302
314
|
* @param signaturePay Signature for EVVM payment
|
|
303
315
|
*/
|
|
304
316
|
function dispatchOrder_fillPropotionalFee(
|
|
305
317
|
address user,
|
|
306
|
-
|
|
318
|
+
address tokenA,
|
|
319
|
+
address tokenB,
|
|
320
|
+
uint256 orderId,
|
|
321
|
+
uint256 amountOfTokenBToFill,
|
|
322
|
+
address originExecutor,
|
|
323
|
+
uint256 nonce,
|
|
324
|
+
bytes memory signature,
|
|
307
325
|
uint256 priorityFeePay,
|
|
308
326
|
uint256 noncePay,
|
|
309
327
|
bytes memory signaturePay
|
|
310
328
|
) external {
|
|
311
329
|
core.validateAndConsumeNonce(
|
|
312
330
|
user,
|
|
313
|
-
Hash.hashDataForDispatchOrder(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
metadata.orderId
|
|
317
|
-
),
|
|
318
|
-
metadata.originExecutor,
|
|
319
|
-
metadata.nonce,
|
|
331
|
+
Hash.hashDataForDispatchOrder(tokenA, tokenB, orderId),
|
|
332
|
+
originExecutor,
|
|
333
|
+
nonce,
|
|
320
334
|
true,
|
|
321
|
-
|
|
335
|
+
signature
|
|
322
336
|
);
|
|
323
337
|
|
|
324
|
-
uint256 market = findMarket(
|
|
338
|
+
uint256 market = findMarket(tokenA, tokenB);
|
|
325
339
|
|
|
326
|
-
Order storage order = _validateMarketAndOrder(market,
|
|
340
|
+
Structs.Order storage order = _validateMarketAndOrder(market, orderId);
|
|
327
341
|
|
|
328
342
|
uint256 fee = calculateFillPropotionalFee(order.amountB);
|
|
329
343
|
uint256 requiredAmount = order.amountB + fee;
|
|
330
344
|
|
|
331
|
-
if (
|
|
345
|
+
if (amountOfTokenBToFill < requiredAmount) {
|
|
332
346
|
revert("Insuficient amountOfTokenToFill");
|
|
333
347
|
}
|
|
334
348
|
|
|
335
349
|
requestPay(
|
|
336
350
|
user,
|
|
337
|
-
|
|
338
|
-
|
|
351
|
+
tokenB,
|
|
352
|
+
amountOfTokenBToFill,
|
|
339
353
|
priorityFeePay,
|
|
340
354
|
noncePay,
|
|
341
355
|
true,
|
|
@@ -345,14 +359,14 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
345
359
|
// si es mas del fee + el monto de la orden hacemos caPay al usuario del sobranate
|
|
346
360
|
bool didRefund = _handleOverpaymentRefund(
|
|
347
361
|
user,
|
|
348
|
-
|
|
349
|
-
|
|
362
|
+
tokenB,
|
|
363
|
+
amountOfTokenBToFill,
|
|
350
364
|
requiredAmount
|
|
351
365
|
);
|
|
352
366
|
|
|
353
367
|
// distribute payments to seller and executor
|
|
354
368
|
_distributePayments(
|
|
355
|
-
|
|
369
|
+
tokenB,
|
|
356
370
|
order.amountB,
|
|
357
371
|
fee,
|
|
358
372
|
order.seller,
|
|
@@ -361,16 +375,16 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
361
375
|
);
|
|
362
376
|
|
|
363
377
|
// pay user with token A
|
|
364
|
-
makeCaPay(user,
|
|
378
|
+
makeCaPay(user, tokenA, order.amountA);
|
|
365
379
|
|
|
366
380
|
_rewardExecutor(msg.sender, didRefund ? 5 : 4);
|
|
367
381
|
|
|
368
|
-
_clearOrderAndUpdateMarket(market,
|
|
382
|
+
_clearOrderAndUpdateMarket(market, orderId);
|
|
369
383
|
}
|
|
370
384
|
|
|
371
385
|
/**
|
|
372
386
|
* @notice Fills order using fixed/capped fee model
|
|
373
|
-
* @dev Fee = min(proportionalFee, maxLimitFillFixedFee)
|
|
387
|
+
* @dev Fee = min(proportionalFee, maxLimitFillFixedFee.current)
|
|
374
388
|
* with -10% tolerance
|
|
375
389
|
*
|
|
376
390
|
* Fixed Fee Execution Flow:
|
|
@@ -403,8 +417,8 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
403
417
|
*
|
|
404
418
|
* Fee Calculation:
|
|
405
419
|
* - Base: amountB (order requirement)
|
|
406
|
-
* - ProportionalFee: (amountB * percentageFee) / 10,000
|
|
407
|
-
* - Fee: min(proportionalFee, maxLimitFillFixedFee)
|
|
420
|
+
* - ProportionalFee: (amountB * percentageFee.current) / 10,000
|
|
421
|
+
* - Fee: min(proportionalFee, maxLimitFillFixedFee.current)
|
|
408
422
|
* - Tolerance: fee * 10% (fee10)
|
|
409
423
|
* - MinRequired: amountB + fee - fee10
|
|
410
424
|
* - FullRequired: amountB + fee
|
|
@@ -417,7 +431,13 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
417
431
|
* - Enables flexible fee payment for users
|
|
418
432
|
*
|
|
419
433
|
* @param user Address filling the order (buyer)
|
|
420
|
-
* @param
|
|
434
|
+
* @param tokenA Token A in pair
|
|
435
|
+
* @param tokenB Token B in pair
|
|
436
|
+
* @param orderId Order ID to fill
|
|
437
|
+
* @param amountOfTokenBToFill Amount of tokenB buyer is paying (must cover order + fee)
|
|
438
|
+
* @param originExecutor Executor address for signature validation
|
|
439
|
+
* @param nonce Nonce for service execution (async)
|
|
440
|
+
* @param signature Signature for dispatch authorization
|
|
421
441
|
* @param priorityFeePay Optional priority fee for staker
|
|
422
442
|
* @param noncePay Nonce for EVVM payment transaction
|
|
423
443
|
* @param signaturePay Signature for EVVM payment
|
|
@@ -425,7 +445,13 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
425
445
|
*/
|
|
426
446
|
function dispatchOrder_fillFixedFee(
|
|
427
447
|
address user,
|
|
428
|
-
|
|
448
|
+
address tokenA,
|
|
449
|
+
address tokenB,
|
|
450
|
+
uint256 orderId,
|
|
451
|
+
uint256 amountOfTokenBToFill,
|
|
452
|
+
address originExecutor,
|
|
453
|
+
uint256 nonce,
|
|
454
|
+
bytes memory signature,
|
|
429
455
|
uint256 priorityFeePay,
|
|
430
456
|
uint256 noncePay,
|
|
431
457
|
bytes memory signaturePay,
|
|
@@ -433,20 +459,16 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
433
459
|
) external {
|
|
434
460
|
core.validateAndConsumeNonce(
|
|
435
461
|
user,
|
|
436
|
-
Hash.hashDataForDispatchOrder(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
metadata.orderId
|
|
440
|
-
),
|
|
441
|
-
metadata.originExecutor,
|
|
442
|
-
metadata.nonce,
|
|
462
|
+
Hash.hashDataForDispatchOrder(tokenA, tokenB, orderId),
|
|
463
|
+
originExecutor,
|
|
464
|
+
nonce,
|
|
443
465
|
true,
|
|
444
|
-
|
|
466
|
+
signature
|
|
445
467
|
);
|
|
446
468
|
|
|
447
|
-
uint256 market = findMarket(
|
|
469
|
+
uint256 market = findMarket(tokenA, tokenB);
|
|
448
470
|
|
|
449
|
-
Order storage order = _validateMarketAndOrder(market,
|
|
471
|
+
Structs.Order storage order = _validateMarketAndOrder(market, orderId);
|
|
450
472
|
|
|
451
473
|
(uint256 fee, uint256 fee10) = calculateFillFixedFee(
|
|
452
474
|
order.amountB,
|
|
@@ -456,14 +478,14 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
456
478
|
uint256 minRequired = order.amountB + fee - fee10;
|
|
457
479
|
uint256 fullRequired = order.amountB + fee;
|
|
458
480
|
|
|
459
|
-
if (
|
|
481
|
+
if (amountOfTokenBToFill < minRequired) {
|
|
460
482
|
revert("Insuficient amountOfTokenBToFill");
|
|
461
483
|
}
|
|
462
484
|
|
|
463
485
|
requestPay(
|
|
464
486
|
user,
|
|
465
|
-
|
|
466
|
-
|
|
487
|
+
tokenB,
|
|
488
|
+
amountOfTokenBToFill,
|
|
467
489
|
priorityFeePay,
|
|
468
490
|
noncePay,
|
|
469
491
|
true,
|
|
@@ -471,7 +493,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
471
493
|
);
|
|
472
494
|
|
|
473
495
|
uint256 finalFee = _calculateFinalFee(
|
|
474
|
-
|
|
496
|
+
amountOfTokenBToFill,
|
|
475
497
|
order.amountB,
|
|
476
498
|
fee,
|
|
477
499
|
fee10
|
|
@@ -480,14 +502,14 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
480
502
|
// si es mas del fee + el monto de la orden hacemos caPay al usuario del sobranate
|
|
481
503
|
bool didRefund = _handleOverpaymentRefund(
|
|
482
504
|
user,
|
|
483
|
-
|
|
484
|
-
|
|
505
|
+
tokenB,
|
|
506
|
+
amountOfTokenBToFill,
|
|
485
507
|
fullRequired
|
|
486
508
|
);
|
|
487
509
|
|
|
488
510
|
// distribute payments to seller and executor
|
|
489
511
|
_distributePayments(
|
|
490
|
-
|
|
512
|
+
tokenB,
|
|
491
513
|
order.amountB,
|
|
492
514
|
finalFee,
|
|
493
515
|
order.seller,
|
|
@@ -495,18 +517,18 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
495
517
|
priorityFeePay
|
|
496
518
|
);
|
|
497
519
|
|
|
498
|
-
makeCaPay(user,
|
|
520
|
+
makeCaPay(user, tokenA, order.amountA);
|
|
499
521
|
|
|
500
522
|
_rewardExecutor(msg.sender, didRefund ? 5 : 4);
|
|
501
523
|
|
|
502
|
-
_clearOrderAndUpdateMarket(market,
|
|
524
|
+
_clearOrderAndUpdateMarket(market, orderId);
|
|
503
525
|
}
|
|
504
526
|
|
|
505
527
|
function calculateFillPropotionalFee(
|
|
506
528
|
uint256 amount
|
|
507
529
|
) internal view returns (uint256 fee) {
|
|
508
530
|
///@dev get the % of the amount
|
|
509
|
-
fee = (amount * percentageFee) / 10_000;
|
|
531
|
+
fee = (amount * percentageFee.current) / 10_000;
|
|
510
532
|
}
|
|
511
533
|
|
|
512
534
|
function calculateFillFixedFee(
|
|
@@ -558,7 +580,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
558
580
|
function _validateMarketAndOrder(
|
|
559
581
|
uint256 market,
|
|
560
582
|
uint256 orderId
|
|
561
|
-
) internal view returns (Order storage order) {
|
|
583
|
+
) internal view returns (Structs.Order storage order) {
|
|
562
584
|
if (market == 0) {
|
|
563
585
|
revert("Invalid order");
|
|
564
586
|
}
|
|
@@ -593,7 +615,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
593
615
|
if (core.isAddressStaker(executor)) {
|
|
594
616
|
makeCaPay(
|
|
595
617
|
executor,
|
|
596
|
-
|
|
618
|
+
core.getPrincipalTokenAddress(),
|
|
597
619
|
core.getRewardAmount() * multiplier
|
|
598
620
|
);
|
|
599
621
|
}
|
|
@@ -672,7 +694,12 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
672
694
|
) internal returns (uint256) {
|
|
673
695
|
marketCount++;
|
|
674
696
|
marketId[tokenA][tokenB] = marketCount;
|
|
675
|
-
marketMetadata[marketCount] = MarketInformation(
|
|
697
|
+
marketMetadata[marketCount] = Structs.MarketInformation(
|
|
698
|
+
tokenA,
|
|
699
|
+
tokenB,
|
|
700
|
+
0,
|
|
701
|
+
0
|
|
702
|
+
);
|
|
676
703
|
return marketCount;
|
|
677
704
|
}
|
|
678
705
|
|
|
@@ -718,7 +745,11 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
718
745
|
if (_seller + _service + _mateStaker != 10_000) {
|
|
719
746
|
revert();
|
|
720
747
|
}
|
|
721
|
-
rewardPercentage_proposal = Percentage(
|
|
748
|
+
rewardPercentage_proposal = Structs.Percentage(
|
|
749
|
+
_seller,
|
|
750
|
+
_service,
|
|
751
|
+
_mateStaker
|
|
752
|
+
);
|
|
722
753
|
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
|
|
723
754
|
}
|
|
724
755
|
|
|
@@ -729,7 +760,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
729
760
|
) {
|
|
730
761
|
revert();
|
|
731
762
|
}
|
|
732
|
-
rewardPercentage_proposal = Percentage(0, 0, 0);
|
|
763
|
+
rewardPercentage_proposal = Structs.Percentage(0, 0, 0);
|
|
733
764
|
}
|
|
734
765
|
|
|
735
766
|
function acceptFillFixedPercentage() external {
|
|
@@ -750,7 +781,11 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
750
781
|
if (msg.sender != owner || _seller + _service + _mateStaker != 10_000) {
|
|
751
782
|
revert();
|
|
752
783
|
}
|
|
753
|
-
rewardPercentage_proposal = Percentage(
|
|
784
|
+
rewardPercentage_proposal = Structs.Percentage(
|
|
785
|
+
_seller,
|
|
786
|
+
_service,
|
|
787
|
+
_mateStaker
|
|
788
|
+
);
|
|
754
789
|
rewardPercentage_timeToAcceptNewChange = block.timestamp + 1 days;
|
|
755
790
|
}
|
|
756
791
|
|
|
@@ -761,7 +796,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
761
796
|
) {
|
|
762
797
|
revert();
|
|
763
798
|
}
|
|
764
|
-
rewardPercentage_proposal = Percentage(0, 0, 0);
|
|
799
|
+
rewardPercentage_proposal = Structs.Percentage(0, 0, 0);
|
|
765
800
|
}
|
|
766
801
|
|
|
767
802
|
function acceptFillPropotionalPercentage() external {
|
|
@@ -778,26 +813,26 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
778
813
|
if (msg.sender != owner) {
|
|
779
814
|
revert();
|
|
780
815
|
}
|
|
781
|
-
|
|
782
|
-
|
|
816
|
+
percentageFee.proposal = _percentageFee;
|
|
817
|
+
percentageFee.timeToAccept = block.timestamp + 1 days;
|
|
783
818
|
}
|
|
784
819
|
|
|
785
820
|
function rejectProposePercentageFee() external {
|
|
786
821
|
if (
|
|
787
|
-
msg.sender != owner || block.timestamp >
|
|
822
|
+
msg.sender != owner || block.timestamp > percentageFee.timeToAccept
|
|
788
823
|
) {
|
|
789
824
|
revert();
|
|
790
825
|
}
|
|
791
|
-
|
|
826
|
+
percentageFee.proposal = 0;
|
|
792
827
|
}
|
|
793
828
|
|
|
794
829
|
function acceptPercentageFee() external {
|
|
795
830
|
if (
|
|
796
|
-
msg.sender != owner || block.timestamp >
|
|
831
|
+
msg.sender != owner || block.timestamp > percentageFee.timeToAccept
|
|
797
832
|
) {
|
|
798
833
|
revert();
|
|
799
834
|
}
|
|
800
|
-
percentageFee =
|
|
835
|
+
percentageFee.current = percentageFee.proposal;
|
|
801
836
|
}
|
|
802
837
|
|
|
803
838
|
function proposeMaxLimitFillFixedFee(
|
|
@@ -806,28 +841,28 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
806
841
|
if (msg.sender != owner) {
|
|
807
842
|
revert();
|
|
808
843
|
}
|
|
809
|
-
|
|
810
|
-
|
|
844
|
+
maxLimitFillFixedFee.proposal = _maxLimitFillFixedFee;
|
|
845
|
+
maxLimitFillFixedFee.timeToAccept = block.timestamp + 1 days;
|
|
811
846
|
}
|
|
812
847
|
|
|
813
848
|
function rejectProposeMaxLimitFillFixedFee() external {
|
|
814
849
|
if (
|
|
815
850
|
msg.sender != owner ||
|
|
816
|
-
block.timestamp >
|
|
851
|
+
block.timestamp > maxLimitFillFixedFee.timeToAccept
|
|
817
852
|
) {
|
|
818
853
|
revert();
|
|
819
854
|
}
|
|
820
|
-
|
|
855
|
+
maxLimitFillFixedFee.proposal = 0;
|
|
821
856
|
}
|
|
822
857
|
|
|
823
858
|
function acceptMaxLimitFillFixedFee() external {
|
|
824
859
|
if (
|
|
825
860
|
msg.sender != owner ||
|
|
826
|
-
block.timestamp >
|
|
861
|
+
block.timestamp > maxLimitFillFixedFee.timeToAccept
|
|
827
862
|
) {
|
|
828
863
|
revert();
|
|
829
864
|
}
|
|
830
|
-
maxLimitFillFixedFee =
|
|
865
|
+
maxLimitFillFixedFee.current = maxLimitFillFixedFee.proposal;
|
|
831
866
|
}
|
|
832
867
|
|
|
833
868
|
function proposeWithdrawal(
|
|
@@ -898,12 +933,14 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
898
933
|
//◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢
|
|
899
934
|
function getAllMarketOrders(
|
|
900
935
|
uint256 market
|
|
901
|
-
) public view returns (OrderForGetter[] memory orders) {
|
|
902
|
-
orders = new OrderForGetter[](
|
|
936
|
+
) public view returns (Structs.OrderForGetter[] memory orders) {
|
|
937
|
+
orders = new Structs.OrderForGetter[](
|
|
938
|
+
marketMetadata[market].maxSlot + 1
|
|
939
|
+
);
|
|
903
940
|
|
|
904
941
|
for (uint256 i = 1; i <= marketMetadata[market].maxSlot + 1; i++) {
|
|
905
942
|
if (ordersInsideMarket[market][i].seller != address(0)) {
|
|
906
|
-
orders[i - 1] = OrderForGetter(
|
|
943
|
+
orders[i - 1] = Structs.OrderForGetter(
|
|
907
944
|
market,
|
|
908
945
|
i,
|
|
909
946
|
ordersInsideMarket[market][i].seller,
|
|
@@ -918,7 +955,7 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
918
955
|
function getOrder(
|
|
919
956
|
uint256 market,
|
|
920
957
|
uint256 orderId
|
|
921
|
-
) public view returns (Order memory order) {
|
|
958
|
+
) public view returns (Structs.Order memory order) {
|
|
922
959
|
order = ordersInsideMarket[market][orderId];
|
|
923
960
|
return order;
|
|
924
961
|
}
|
|
@@ -926,12 +963,14 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
926
963
|
function getMyOrdersInSpecificMarket(
|
|
927
964
|
address user,
|
|
928
965
|
uint256 market
|
|
929
|
-
) public view returns (OrderForGetter[] memory orders) {
|
|
930
|
-
orders = new OrderForGetter[](
|
|
966
|
+
) public view returns (Structs.OrderForGetter[] memory orders) {
|
|
967
|
+
orders = new Structs.OrderForGetter[](
|
|
968
|
+
marketMetadata[market].maxSlot + 1
|
|
969
|
+
);
|
|
931
970
|
|
|
932
971
|
for (uint256 i = 1; i <= marketMetadata[market].maxSlot + 1; i++) {
|
|
933
972
|
if (ordersInsideMarket[market][i].seller == user) {
|
|
934
|
-
orders[i - 1] = OrderForGetter(
|
|
973
|
+
orders[i - 1] = Structs.OrderForGetter(
|
|
935
974
|
market,
|
|
936
975
|
i,
|
|
937
976
|
ordersInsideMarket[market][i].seller,
|
|
@@ -952,18 +991,17 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
952
991
|
|
|
953
992
|
function getMarketMetadata(
|
|
954
993
|
uint256 market
|
|
955
|
-
) public view returns (MarketInformation memory) {
|
|
994
|
+
) public view returns (Structs.MarketInformation memory) {
|
|
956
995
|
return marketMetadata[market];
|
|
957
996
|
}
|
|
958
997
|
|
|
959
998
|
function getAllMarketsMetadata()
|
|
960
999
|
public
|
|
961
1000
|
view
|
|
962
|
-
returns (MarketInformation[] memory)
|
|
1001
|
+
returns (Structs.MarketInformation[] memory)
|
|
963
1002
|
{
|
|
964
|
-
MarketInformation[]
|
|
965
|
-
marketCount + 1
|
|
966
|
-
);
|
|
1003
|
+
Structs.MarketInformation[]
|
|
1004
|
+
memory markets = new Structs.MarketInformation[](marketCount + 1);
|
|
967
1005
|
for (uint256 i = 1; i <= marketCount; i++) {
|
|
968
1006
|
markets[i - 1] = marketMetadata[i];
|
|
969
1007
|
}
|
|
@@ -991,29 +1029,33 @@ contract P2PSwap is EvvmService, Structs {
|
|
|
991
1029
|
function getRewardPercentageProposal()
|
|
992
1030
|
external
|
|
993
1031
|
view
|
|
994
|
-
returns (Percentage memory)
|
|
1032
|
+
returns (Structs.Percentage memory)
|
|
995
1033
|
{
|
|
996
1034
|
return rewardPercentage_proposal;
|
|
997
1035
|
}
|
|
998
1036
|
|
|
999
|
-
function getRewardPercentage()
|
|
1037
|
+
function getRewardPercentage()
|
|
1038
|
+
external
|
|
1039
|
+
view
|
|
1040
|
+
returns (Structs.Percentage memory)
|
|
1041
|
+
{
|
|
1000
1042
|
return rewardPercentage;
|
|
1001
1043
|
}
|
|
1002
1044
|
|
|
1003
1045
|
function getProposalPercentageFee() external view returns (uint256) {
|
|
1004
|
-
return
|
|
1046
|
+
return percentageFee.proposal;
|
|
1005
1047
|
}
|
|
1006
1048
|
|
|
1007
1049
|
function getPercentageFee() external view returns (uint256) {
|
|
1008
|
-
return percentageFee;
|
|
1050
|
+
return percentageFee.current;
|
|
1009
1051
|
}
|
|
1010
1052
|
|
|
1011
1053
|
function getMaxLimitFillFixedFeeProposal() external view returns (uint256) {
|
|
1012
|
-
return
|
|
1054
|
+
return maxLimitFillFixedFee.proposal;
|
|
1013
1055
|
}
|
|
1014
1056
|
|
|
1015
1057
|
function getMaxLimitFillFixedFee() external view returns (uint256) {
|
|
1016
|
-
return maxLimitFillFixedFee;
|
|
1058
|
+
return maxLimitFillFixedFee.current;
|
|
1017
1059
|
}
|
|
1018
1060
|
|
|
1019
1061
|
function getProposedWithdrawal()
|