1
1
// SPDX-License-Identifier: BUSL-1.1
2
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
+
3
36
pragma solidity ^ 0.8.17 ;
4
37
5
38
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol " ;
@@ -8,6 +41,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
8
41
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol " ;
9
42
10
43
import "../interfaces/external/uniswap/IUniswapV3Pool.sol " ;
44
+ import "../interfaces/external/algebra/IAlgebraPool.sol " ;
11
45
import "../utils/UUPSHelper.sol " ;
12
46
import "../struct/DistributionParameters.sol " ;
13
47
import "../struct/ExtensiveDistributionParameters.sol " ;
@@ -111,7 +145,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
111
145
112
146
function initialize (ICore _core , address _distributor , uint256 _fees ) external initializer {
113
147
if (address (_core) == address (0 ) || _distributor == address (0 )) revert ZeroAddress ();
114
- if (_fees > BASE_9) revert InvalidParam ();
148
+ if (_fees >= BASE_9) revert InvalidParam ();
115
149
distributor = _distributor;
116
150
core = _core;
117
151
fees = _fees;
@@ -203,6 +237,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
203
237
uint256 userFeeRebate = feeRebate[msg .sender ];
204
238
if (
205
239
userFeeRebate < BASE_9 &&
240
+ // Algebra pools also have these `token0` and `token1` parameters
206
241
isWhitelistedToken[IUniswapV3Pool (distribution.uniV3Pool).token0 ()] == 0 &&
207
242
isWhitelistedToken[IUniswapV3Pool (distribution.uniV3Pool).token1 ()] == 0
208
243
) {
@@ -265,14 +300,10 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
265
300
++ i;
266
301
}
267
302
}
268
- RewardTokenAmounts[] memory validRewardTokensShort = new RewardTokenAmounts [](length);
269
- for (uint32 i; i < length; ) {
270
- validRewardTokensShort[i] = validRewardTokens[i];
271
- unchecked {
272
- ++ i;
273
- }
303
+ assembly {
304
+ mstore (validRewardTokens, length)
274
305
}
275
- return validRewardTokensShort ;
306
+ return validRewardTokens ;
276
307
}
277
308
278
309
/// @notice Returns the list of all the distributions that were or that are going to be live at
@@ -317,8 +348,8 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
317
348
return _getPoolDistributionsBetweenEpochs (uniV3Pool, roundedEpoch, roundedEpoch + EPOCH_DURATION);
318
349
}
319
350
320
- /// @notice Returns the list of all distributions that were or will be live between `epochStart` (included) and `epochEnd` (excluded)
321
- /// for a specific pool
351
+ /// @notice Returns the list of all distributions that were or will be live at some point between
352
+ /// `epochStart` (included) and `epochEnd` (excluded) for a specific pool
322
353
function getPoolDistributionsBetweenEpochs (
323
354
address uniV3Pool ,
324
355
uint32 epochStart ,
@@ -382,6 +413,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
382
413
uint256 [] calldata amounts
383
414
) external onlyGovernorOrGuardian {
384
415
uint256 tokensLength = tokens.length ;
416
+ if (tokensLength != amounts.length ) revert InvalidLengths ();
385
417
for (uint256 i; i < tokensLength; ++ i) {
386
418
uint256 amount = amounts[i];
387
419
// Basic logic check to make sure there are no duplicates in the `rewardTokens` table. If a token is
@@ -422,10 +454,10 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
422
454
423
455
/// @notice Checks whether `distribution` was live between `roundedEpochStart` and `roundedEpochEnd`
424
456
function _isDistributionLiveBetweenEpochs (
425
- DistributionParameters storage distribution ,
457
+ DistributionParameters memory distribution ,
426
458
uint32 roundedEpochStart ,
427
459
uint32 roundedEpochEnd
428
- ) internal view returns (bool ) {
460
+ ) internal pure returns (bool ) {
429
461
uint256 distributionEpochStart = distribution.epochStart;
430
462
return (distributionEpochStart + distribution.numEpoch * EPOCH_DURATION > roundedEpochStart &&
431
463
distributionEpochStart < roundedEpochEnd);
@@ -450,7 +482,19 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
450
482
try IUniswapV3Pool (distribution.uniV3Pool).fee () returns (uint24 fee ) {
451
483
extensiveParams.poolFee = fee;
452
484
} catch {
453
- extensiveParams.poolFee = 0 ;
485
+ try IAlgebraPool (distribution.uniV3Pool).globalState () returns (
486
+ uint160 ,
487
+ int24 ,
488
+ uint16 fee ,
489
+ uint16 ,
490
+ uint8 ,
491
+ uint8 ,
492
+ bool
493
+ ) {
494
+ extensiveParams.poolFee = uint24 (fee);
495
+ } catch {
496
+ extensiveParams.poolFee = 0 ;
497
+ }
454
498
}
455
499
extensiveParams.token0 = _getUniswapTokenData (
456
500
IERC20Metadata (IUniswapV3Pool (distribution.uniV3Pool).token0 ()),
@@ -473,27 +517,24 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
473
517
) internal view returns (ExtensiveDistributionParameters[] memory ) {
474
518
uint256 length;
475
519
uint256 distributionListLength = distributionList.length ;
476
- DistributionParameters[] memory longActiveRewards = new DistributionParameters [](distributionListLength);
520
+ ExtensiveDistributionParameters[] memory activeRewards = new ExtensiveDistributionParameters [](
521
+ distributionListLength
522
+ );
477
523
for (uint32 i; i < distributionListLength; ) {
478
- DistributionParameters storage distribution = distributionList[i];
524
+ DistributionParameters memory distribution = distributionList[i];
479
525
if (
480
526
_isDistributionLiveBetweenEpochs (distribution, epochStart, epochEnd) &&
481
527
(uniV3Pool == address (0 ) || distribution.uniV3Pool == uniV3Pool)
482
528
) {
483
- longActiveRewards [length] = distribution;
529
+ activeRewards [length] = _getExtensiveDistributionParameters ( distribution) ;
484
530
length += 1 ;
485
531
}
486
532
unchecked {
487
533
++ i;
488
534
}
489
535
}
490
-
491
- ExtensiveDistributionParameters[] memory activeRewards = new ExtensiveDistributionParameters [](length);
492
- for (uint32 i; i < length; ) {
493
- activeRewards[i] = _getExtensiveDistributionParameters (longActiveRewards[i]);
494
- unchecked {
495
- ++ i;
496
- }
536
+ assembly {
537
+ mstore (activeRewards, length)
497
538
}
498
539
return activeRewards;
499
540
}
0 commit comments