-
Notifications
You must be signed in to change notification settings - Fork 1
/
LooksRareExchange.sol
595 lines (516 loc) · 24.1 KB
/
LooksRareExchange.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// OpenZeppelin contracts
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
// LooksRare interfaces
import {ICurrencyManager} from "./interfaces/ICurrencyManager.sol";
import {IExecutionManager} from "./interfaces/IExecutionManager.sol";
import {IExecutionStrategy} from "./interfaces/IExecutionStrategy.sol";
import {IRoyaltyFeeManager} from "./interfaces/IRoyaltyFeeManager.sol";
import {ILooksRareExchange} from "./interfaces/ILooksRareExchange.sol";
import {ITransferManagerNFT} from "./interfaces/ITransferManagerNFT.sol";
import {ITransferSelectorNFT} from "./interfaces/ITransferSelectorNFT.sol";
import {IWETH} from "./interfaces/IWETH.sol";
// LooksRare libraries
import {OrderTypes} from "./libraries/OrderTypes.sol";
import {SignatureChecker} from "./libraries/SignatureChecker.sol";
/**
* @title LooksRareExchange
* @notice It is the core contract of the LooksRare exchange.
LOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRAR'''''''''''''''''''''''''''''''''''OOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKS:. .;OOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOO,. .,KSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRAREL' ..',;:LOOKS::;,'.. 'RARELOOKSRARELOOKSR
LOOKSRARELOOKSRAR. .,:LOOKSRARELOOKSRARELO:,. .RELOOKSRARELOOKSR
LOOKSRARELOOKS:. .;RARELOOKSRARELOOKSRARELOOKSl;. .:OOKSRARELOOKSR
LOOKSRARELOO;. .'OKSRARELOOKSRARELOOKSRARELOOKSRARE'. .;KSRARELOOKSR
LOOKSRAREL,. .,LOOKSRARELOOK:;;:"""":;;;lELOOKSRARELO,. .,RARELOOKSR
LOOKSRAR. .;okLOOKSRAREx:. .;OOKSRARELOOK;. .RELOOKSR
LOOKS:. .:dOOOLOOKSRARE' .''''.. .OKSRARELOOKSR:. .LOOKSR
LOx;. .cKSRARELOOKSRAR' 'LOOKSRAR' .KSRARELOOKSRARc.. .OKSR
L;. .cxOKSRARELOOKSRAR. .LOOKS.RARE' ;kRARELOOKSRARExc. .;R
LO' .;oOKSRARELOOKSRAl. .LOOKS.RARE. :kRARELOOKSRAREo;. 'SR
LOOK;. .,KSRARELOOKSRAx, .;LOOKSR;. .oSRARELOOKSRAo,. .;OKSR
LOOKSk:. .'RARELOOKSRARd;. .... 'oOOOOOOOOOOxc'. .:LOOKSR
LOOKSRARc. .:dLOOKSRAREko;. .,lxOOOOOOOOOd:. .ARELOOKSR
LOOKSRARELo' .;oOKSRARELOOxoc;,....,;:ldkOOOOOOOOkd;. 'SRARELOOKSR
LOOKSRARELOOd,. .,lSRARELOOKSRARELOOKSRARELOOKSRkl,. .,OKSRARELOOKSR
LOOKSRARELOOKSx;. ..;oxELOOKSRARELOOKSRARELOkxl:.. .:LOOKSRARELOOKSR
LOOKSRARELOOKSRARc. .':cOKSRARELOOKSRALOc;'. .ARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELl' ...'',,,,''... 'SRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOo,. .,OKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSx;. .;xOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLO:. .:SRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKl. .lOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRo'. .'oLOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARd;. .;xRELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARELO:. .:kRARELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKl. .cOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRo' 'oLOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRARE,. .,dRELOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSR
LOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSRARELOOKSRARELOOKSRLOOKSRARELOOKSRARELOOKSR
*/
contract LooksRareExchange is ILooksRareExchange, ReentrancyGuard, Ownable {
using SafeERC20 for IERC20;
using OrderTypes for OrderTypes.MakerOrder;
using OrderTypes for OrderTypes.TakerOrder;
address public immutable WETH;
bytes32 public immutable DOMAIN_SEPARATOR;
address public protocolFeeRecipient;
ICurrencyManager public currencyManager;
IExecutionManager public executionManager;
IRoyaltyFeeManager public royaltyFeeManager;
ITransferSelectorNFT public transferSelectorNFT;
mapping(address => uint256) public userMinOrderNonce;
mapping(address => mapping(uint256 => bool)) private _isUserOrderNonceExecutedOrCancelled;
event CancelAllOrders(address indexed user, uint256 newMinNonce);
event CancelMultipleOrders(address indexed user, uint256[] orderNonces);
event NewCurrencyManager(address indexed currencyManager);
event NewExecutionManager(address indexed executionManager);
event NewProtocolFeeRecipient(address indexed protocolFeeRecipient);
event NewRoyaltyFeeManager(address indexed royaltyFeeManager);
event NewTransferSelectorNFT(address indexed transferSelectorNFT);
event RoyaltyPayment(
address indexed collection,
uint256 indexed tokenId,
address indexed royaltyRecipient,
address currency,
uint256 amount
);
event TakerAsk(
bytes32 orderHash, // bid hash of the maker order
uint256 orderNonce, // user order nonce
address indexed taker, // sender address for the taker ask order
address indexed maker, // maker address of the initial bid order
address indexed strategy, // strategy that defines the execution
address currency, // currency address
address collection, // collection address
uint256 tokenId, // tokenId transferred
uint256 amount, // amount of tokens transferred
uint256 price // final transacted price
);
event TakerBid(
bytes32 orderHash, // ask hash of the maker order
uint256 orderNonce, // user order nonce
address indexed taker, // sender address for the taker bid order
address indexed maker, // maker address of the initial ask order
address indexed strategy, // strategy that defines the execution
address currency, // currency address
address collection, // collection address
uint256 tokenId, // tokenId transferred
uint256 amount, // amount of tokens transferred
uint256 price // final transacted price
);
/**
* @notice Constructor
* @param _currencyManager currency manager address
* @param _executionManager execution manager address
* @param _royaltyFeeManager royalty fee manager address
* @param _WETH wrapped ether address (for other chains, use wrapped native asset)
* @param _protocolFeeRecipient protocol fee recipient
*/
constructor(
address _currencyManager,
address _executionManager,
address _royaltyFeeManager,
address _WETH,
address _protocolFeeRecipient
) {
// Calculate the domain separator
DOMAIN_SEPARATOR = keccak256(
abi.encode(
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f, // keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
0xda9101ba92939daf4bb2e18cd5f942363b9297fbc3232c9dd964abb1fb70ed71, // keccak256("LooksRareExchange")
0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6, // keccak256(bytes("1")) for versionId = 1
block.chainid,
address(this)
)
);
currencyManager = ICurrencyManager(_currencyManager);
executionManager = IExecutionManager(_executionManager);
royaltyFeeManager = IRoyaltyFeeManager(_royaltyFeeManager);
WETH = _WETH;
protocolFeeRecipient = _protocolFeeRecipient;
}
/**
* @notice Cancel all pending orders for a sender
* @param minNonce minimum user nonce
*/
function cancelAllOrdersForSender(uint256 minNonce) external {
require(minNonce > userMinOrderNonce[msg.sender], "Cancel: Order nonce lower than current");
require(minNonce < userMinOrderNonce[msg.sender] + 500000, "Cancel: Cannot cancel more orders");
userMinOrderNonce[msg.sender] = minNonce;
emit CancelAllOrders(msg.sender, minNonce);
}
/**
* @notice Cancel maker orders
* @param orderNonces array of order nonces
*/
function cancelMultipleMakerOrders(uint256[] calldata orderNonces) external {
require(orderNonces.length > 0, "Cancel: Cannot be empty");
for (uint256 i = 0; i < orderNonces.length; i++) {
require(orderNonces[i] >= userMinOrderNonce[msg.sender], "Cancel: Order nonce lower than current");
_isUserOrderNonceExecutedOrCancelled[msg.sender][orderNonces[i]] = true;
}
emit CancelMultipleOrders(msg.sender, orderNonces);
}
/**
* @notice Match ask with a taker bid order using ETH
* @param takerBid taker bid order
* @param makerAsk maker ask order
*/
function matchAskWithTakerBidUsingETHAndWETH(
OrderTypes.TakerOrder calldata takerBid,
OrderTypes.MakerOrder calldata makerAsk
) external payable override nonReentrant {
require((makerAsk.isOrderAsk) && (!takerBid.isOrderAsk), "Order: Wrong sides");
require(makerAsk.currency == WETH, "Order: Currency must be WETH");
require(msg.sender == takerBid.taker, "Order: Taker must be the sender");
// If not enough ETH to cover the price, use WETH
if (takerBid.price > msg.value) {
IERC20(WETH).safeTransferFrom(msg.sender, address(this), (takerBid.price - msg.value));
} else {
require(takerBid.price == msg.value, "Order: Msg.value too high");
}
// Wrap ETH sent to this contract
IWETH(WETH).deposit{value: msg.value}();
// Check the maker ask order
bytes32 askHash = makerAsk.hash();
_validateOrder(makerAsk, askHash);
// Retrieve execution parameters
(bool isExecutionValid, uint256 tokenId, uint256 amount) = IExecutionStrategy(makerAsk.strategy)
.canExecuteTakerBid(takerBid, makerAsk);
require(isExecutionValid, "Strategy: Execution invalid");
// Update maker ask order status to true (prevents replay)
_isUserOrderNonceExecutedOrCancelled[makerAsk.signer][makerAsk.nonce] = true;
// Execution part 1/2
_transferFeesAndFundsWithWETH(
makerAsk.strategy,
makerAsk.collection,
tokenId,
makerAsk.signer,
takerBid.price,
makerAsk.minPercentageToAsk
);
// Execution part 2/2
_transferNonFungibleToken(makerAsk.collection, makerAsk.signer, takerBid.taker, tokenId, amount);
emit TakerBid(
askHash,
makerAsk.nonce,
takerBid.taker,
makerAsk.signer,
makerAsk.strategy,
makerAsk.currency,
makerAsk.collection,
tokenId,
amount,
takerBid.price
);
}
/**
* @notice Match a takerBid with a matchAsk
* @param takerBid taker bid order
* @param makerAsk maker ask order
*/
function matchAskWithTakerBid(OrderTypes.TakerOrder calldata takerBid, OrderTypes.MakerOrder calldata makerAsk)
external
override
nonReentrant
{
require((makerAsk.isOrderAsk) && (!takerBid.isOrderAsk), "Order: Wrong sides");
require(msg.sender == takerBid.taker, "Order: Taker must be the sender");
// Check the maker ask order
bytes32 askHash = makerAsk.hash();
_validateOrder(makerAsk, askHash);
(bool isExecutionValid, uint256 tokenId, uint256 amount) = IExecutionStrategy(makerAsk.strategy)
.canExecuteTakerBid(takerBid, makerAsk);
require(isExecutionValid, "Strategy: Execution invalid");
// Update maker ask order status to true (prevents replay)
_isUserOrderNonceExecutedOrCancelled[makerAsk.signer][makerAsk.nonce] = true;
// Execution part 1/2
_transferFeesAndFunds(
makerAsk.strategy,
makerAsk.collection,
tokenId,
makerAsk.currency,
msg.sender,
makerAsk.signer,
takerBid.price,
makerAsk.minPercentageToAsk
);
// Execution part 2/2
_transferNonFungibleToken(makerAsk.collection, makerAsk.signer, takerBid.taker, tokenId, amount);
emit TakerBid(
askHash,
makerAsk.nonce,
takerBid.taker,
makerAsk.signer,
makerAsk.strategy,
makerAsk.currency,
makerAsk.collection,
tokenId,
amount,
takerBid.price
);
}
/**
* @notice Match a takerAsk with a makerBid
* @param takerAsk taker ask order
* @param makerBid maker bid order
*/
function matchBidWithTakerAsk(OrderTypes.TakerOrder calldata takerAsk, OrderTypes.MakerOrder calldata makerBid)
external
override
nonReentrant
{
require((!makerBid.isOrderAsk) && (takerAsk.isOrderAsk), "Order: Wrong sides");
require(msg.sender == takerAsk.taker, "Order: Taker must be the sender");
// Check the maker bid order
bytes32 bidHash = makerBid.hash();
_validateOrder(makerBid, bidHash);
(bool isExecutionValid, uint256 tokenId, uint256 amount) = IExecutionStrategy(makerBid.strategy)
.canExecuteTakerAsk(takerAsk, makerBid);
require(isExecutionValid, "Strategy: Execution invalid");
// Update maker bid order status to true (prevents replay)
_isUserOrderNonceExecutedOrCancelled[makerBid.signer][makerBid.nonce] = true;
// Execution part 1/2
_transferNonFungibleToken(makerBid.collection, msg.sender, makerBid.signer, tokenId, amount);
// Execution part 2/2
_transferFeesAndFunds(
makerBid.strategy,
makerBid.collection,
tokenId,
makerBid.currency,
makerBid.signer,
takerAsk.taker,
takerAsk.price,
takerAsk.minPercentageToAsk
);
emit TakerAsk(
bidHash,
makerBid.nonce,
takerAsk.taker,
makerBid.signer,
makerBid.strategy,
makerBid.currency,
makerBid.collection,
tokenId,
amount,
takerAsk.price
);
}
/**
* @notice Update currency manager
* @param _currencyManager new currency manager address
*/
function updateCurrencyManager(address _currencyManager) external onlyOwner {
require(_currencyManager != address(0), "Owner: Cannot be null address");
currencyManager = ICurrencyManager(_currencyManager);
emit NewCurrencyManager(_currencyManager);
}
/**
* @notice Update execution manager
* @param _executionManager new execution manager address
*/
function updateExecutionManager(address _executionManager) external onlyOwner {
require(_executionManager != address(0), "Owner: Cannot be null address");
executionManager = IExecutionManager(_executionManager);
emit NewExecutionManager(_executionManager);
}
/**
* @notice Update protocol fee and recipient
* @param _protocolFeeRecipient new recipient for protocol fees
*/
function updateProtocolFeeRecipient(address _protocolFeeRecipient) external onlyOwner {
protocolFeeRecipient = _protocolFeeRecipient;
emit NewProtocolFeeRecipient(_protocolFeeRecipient);
}
/**
* @notice Update royalty fee manager
* @param _royaltyFeeManager new fee manager address
*/
function updateRoyaltyFeeManager(address _royaltyFeeManager) external onlyOwner {
require(_royaltyFeeManager != address(0), "Owner: Cannot be null address");
royaltyFeeManager = IRoyaltyFeeManager(_royaltyFeeManager);
emit NewRoyaltyFeeManager(_royaltyFeeManager);
}
/**
* @notice Update transfer selector NFT
* @param _transferSelectorNFT new transfer selector address
*/
function updateTransferSelectorNFT(address _transferSelectorNFT) external onlyOwner {
require(_transferSelectorNFT != address(0), "Owner: Cannot be null address");
transferSelectorNFT = ITransferSelectorNFT(_transferSelectorNFT);
emit NewTransferSelectorNFT(_transferSelectorNFT);
}
/**
* @notice Check whether user order nonce is executed or cancelled
* @param user address of user
* @param orderNonce nonce of the order
*/
function isUserOrderNonceExecutedOrCancelled(address user, uint256 orderNonce) external view returns (bool) {
return _isUserOrderNonceExecutedOrCancelled[user][orderNonce];
}
/**
* @notice Transfer fees and funds to royalty recipient, protocol, and seller
* @param strategy address of the execution strategy
* @param collection non fungible token address for the transfer
* @param tokenId tokenId
* @param currency currency being used for the purchase (e.g., WETH/USDC)
* @param from sender of the funds
* @param to seller's recipient
* @param amount amount being transferred (in currency)
* @param minPercentageToAsk minimum percentage of the gross amount that goes to ask
*/
function _transferFeesAndFunds(
address strategy,
address collection,
uint256 tokenId,
address currency,
address from,
address to,
uint256 amount,
uint256 minPercentageToAsk
) internal {
// Initialize the final amount that is transferred to seller
uint256 finalSellerAmount = amount;
// 1. Protocol fee
{
uint256 protocolFeeAmount = _calculateProtocolFee(strategy, amount);
// Check if the protocol fee is different than 0 for this strategy
if ((protocolFeeRecipient != address(0)) && (protocolFeeAmount != 0)) {
IERC20(currency).safeTransferFrom(from, protocolFeeRecipient, protocolFeeAmount);
finalSellerAmount -= protocolFeeAmount;
}
}
// 2. Royalty fee
{
(address royaltyFeeRecipient, uint256 royaltyFeeAmount) = royaltyFeeManager
.calculateRoyaltyFeeAndGetRecipient(collection, tokenId, amount);
// Check if there is a royalty fee and that it is different to 0
if ((royaltyFeeRecipient != address(0)) && (royaltyFeeAmount != 0)) {
IERC20(currency).safeTransferFrom(from, royaltyFeeRecipient, royaltyFeeAmount);
finalSellerAmount -= royaltyFeeAmount;
emit RoyaltyPayment(collection, tokenId, royaltyFeeRecipient, currency, royaltyFeeAmount);
}
}
require((finalSellerAmount * 10000) >= (minPercentageToAsk * amount), "Fees: Higher than expected");
// 3. Transfer final amount (post-fees) to seller
{
IERC20(currency).safeTransferFrom(from, to, finalSellerAmount);
}
}
/**
* @notice Transfer fees and funds to royalty recipient, protocol, and seller
* @param strategy address of the execution strategy
* @param collection non fungible token address for the transfer
* @param tokenId tokenId
* @param to seller's recipient
* @param amount amount being transferred (in currency)
* @param minPercentageToAsk minimum percentage of the gross amount that goes to ask
*/
function _transferFeesAndFundsWithWETH(
address strategy,
address collection,
uint256 tokenId,
address to,
uint256 amount,
uint256 minPercentageToAsk
) internal {
// Initialize the final amount that is transferred to seller
uint256 finalSellerAmount = amount;
// 1. Protocol fee
{
uint256 protocolFeeAmount = _calculateProtocolFee(strategy, amount);
// Check if the protocol fee is different than 0 for this strategy
if ((protocolFeeRecipient != address(0)) && (protocolFeeAmount != 0)) {
IERC20(WETH).safeTransfer(protocolFeeRecipient, protocolFeeAmount);
finalSellerAmount -= protocolFeeAmount;
}
}
// 2. Royalty fee
{
(address royaltyFeeRecipient, uint256 royaltyFeeAmount) = royaltyFeeManager
.calculateRoyaltyFeeAndGetRecipient(collection, tokenId, amount);
// Check if there is a royalty fee and that it is different to 0
if ((royaltyFeeRecipient != address(0)) && (royaltyFeeAmount != 0)) {
IERC20(WETH).safeTransfer(royaltyFeeRecipient, royaltyFeeAmount);
finalSellerAmount -= royaltyFeeAmount;
emit RoyaltyPayment(collection, tokenId, royaltyFeeRecipient, address(WETH), royaltyFeeAmount);
}
}
require((finalSellerAmount * 10000) >= (minPercentageToAsk * amount), "Fees: Higher than expected");
// 3. Transfer final amount (post-fees) to seller
{
IERC20(WETH).safeTransfer(to, finalSellerAmount);
}
}
/**
* @notice Transfer NFT
* @param collection address of the token collection
* @param from address of the sender
* @param to address of the recipient
* @param tokenId tokenId
* @param amount amount of tokens (1 for ERC721, 1+ for ERC1155)
* @dev For ERC721, amount is not used
*/
function _transferNonFungibleToken(
address collection,
address from,
address to,
uint256 tokenId,
uint256 amount
) internal {
// Retrieve the transfer manager address
address transferManager = transferSelectorNFT.checkTransferManagerForToken(collection);
// If no transfer manager found, it returns address(0)
require(transferManager != address(0), "Transfer: No NFT transfer manager available");
// If one is found, transfer the token
ITransferManagerNFT(transferManager).transferNonFungibleToken(collection, from, to, tokenId, amount);
}
/**
* @notice Calculate protocol fee for an execution strategy
* @param executionStrategy strategy
* @param amount amount to transfer
*/
function _calculateProtocolFee(address executionStrategy, uint256 amount) internal view returns (uint256) {
uint256 protocolFee = IExecutionStrategy(executionStrategy).viewProtocolFee();
return (protocolFee * amount) / 10000;
}
/**
* @notice Verify the validity of the maker order
* @param makerOrder maker order
* @param orderHash computed hash for the order
*/
function _validateOrder(OrderTypes.MakerOrder calldata makerOrder, bytes32 orderHash) internal view {
// Verify whether order nonce has expired
require(
(!_isUserOrderNonceExecutedOrCancelled[makerOrder.signer][makerOrder.nonce]) &&
(makerOrder.nonce >= userMinOrderNonce[makerOrder.signer]),
"Order: Matching order expired"
);
// Verify the signer is not address(0)
require(makerOrder.signer != address(0), "Order: Invalid signer");
// Verify the amount is not 0
require(makerOrder.amount > 0, "Order: Amount cannot be 0");
// Verify the validity of the signature
require(
SignatureChecker.verify(
orderHash,
makerOrder.signer,
makerOrder.v,
makerOrder.r,
makerOrder.s,
DOMAIN_SEPARATOR
),
"Signature: Invalid"
);
// Verify whether the currency is whitelisted
require(currencyManager.isCurrencyWhitelisted(makerOrder.currency), "Currency: Not whitelisted");
// Verify whether strategy can be executed
require(executionManager.isStrategyWhitelisted(makerOrder.strategy), "Strategy: Not whitelisted");
}
}