Skip to content

Commit da3dadc

Browse files
authored
fix: signing requirement (#30)
* fix: signing * fix: add tests to the solution proposed * feat: polygon zkevm deployment * fix: update scripts * deploy new version on Polygon
1 parent 4b44cf3 commit da3dadc

20 files changed

+7621
-51
lines changed

contracts/DistributionCreator.sol

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
138138

139139
/// @notice Checks whether an address has signed the message or not
140140
modifier hasSigned() {
141-
if (userSignatureWhitelist[msg.sender] == 0 && userSignatures[msg.sender] != messageHash) revert NotSigned();
141+
if (
142+
userSignatureWhitelist[msg.sender] == 0 &&
143+
userSignatures[msg.sender] != messageHash &&
144+
userSignatureWhitelist[tx.origin] == 0 &&
145+
userSignatures[tx.origin] != messageHash
146+
) revert NotSigned();
142147
_;
143148
}
144149

contracts/deprecated/OldDistributionCreator.sol

Lines changed: 64 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
11
// SPDX-License-Identifier: BUSL-1.1
22

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+
336
pragma solidity ^0.8.17;
437

538
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
@@ -8,6 +41,7 @@ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
841
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
942

1043
import "../interfaces/external/uniswap/IUniswapV3Pool.sol";
44+
import "../interfaces/external/algebra/IAlgebraPool.sol";
1145
import "../utils/UUPSHelper.sol";
1246
import "../struct/DistributionParameters.sol";
1347
import "../struct/ExtensiveDistributionParameters.sol";
@@ -111,7 +145,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
111145

112146
function initialize(ICore _core, address _distributor, uint256 _fees) external initializer {
113147
if (address(_core) == address(0) || _distributor == address(0)) revert ZeroAddress();
114-
if (_fees > BASE_9) revert InvalidParam();
148+
if (_fees >= BASE_9) revert InvalidParam();
115149
distributor = _distributor;
116150
core = _core;
117151
fees = _fees;
@@ -203,6 +237,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
203237
uint256 userFeeRebate = feeRebate[msg.sender];
204238
if (
205239
userFeeRebate < BASE_9 &&
240+
// Algebra pools also have these `token0` and `token1` parameters
206241
isWhitelistedToken[IUniswapV3Pool(distribution.uniV3Pool).token0()] == 0 &&
207242
isWhitelistedToken[IUniswapV3Pool(distribution.uniV3Pool).token1()] == 0
208243
) {
@@ -265,14 +300,10 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
265300
++i;
266301
}
267302
}
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)
274305
}
275-
return validRewardTokensShort;
306+
return validRewardTokens;
276307
}
277308

278309
/// @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 {
317348
return _getPoolDistributionsBetweenEpochs(uniV3Pool, roundedEpoch, roundedEpoch + EPOCH_DURATION);
318349
}
319350

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
322353
function getPoolDistributionsBetweenEpochs(
323354
address uniV3Pool,
324355
uint32 epochStart,
@@ -382,6 +413,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
382413
uint256[] calldata amounts
383414
) external onlyGovernorOrGuardian {
384415
uint256 tokensLength = tokens.length;
416+
if (tokensLength != amounts.length) revert InvalidLengths();
385417
for (uint256 i; i < tokensLength; ++i) {
386418
uint256 amount = amounts[i];
387419
// 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 {
422454

423455
/// @notice Checks whether `distribution` was live between `roundedEpochStart` and `roundedEpochEnd`
424456
function _isDistributionLiveBetweenEpochs(
425-
DistributionParameters storage distribution,
457+
DistributionParameters memory distribution,
426458
uint32 roundedEpochStart,
427459
uint32 roundedEpochEnd
428-
) internal view returns (bool) {
460+
) internal pure returns (bool) {
429461
uint256 distributionEpochStart = distribution.epochStart;
430462
return (distributionEpochStart + distribution.numEpoch * EPOCH_DURATION > roundedEpochStart &&
431463
distributionEpochStart < roundedEpochEnd);
@@ -450,7 +482,19 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
450482
try IUniswapV3Pool(distribution.uniV3Pool).fee() returns (uint24 fee) {
451483
extensiveParams.poolFee = fee;
452484
} 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+
}
454498
}
455499
extensiveParams.token0 = _getUniswapTokenData(
456500
IERC20Metadata(IUniswapV3Pool(distribution.uniV3Pool).token0()),
@@ -473,27 +517,24 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
473517
) internal view returns (ExtensiveDistributionParameters[] memory) {
474518
uint256 length;
475519
uint256 distributionListLength = distributionList.length;
476-
DistributionParameters[] memory longActiveRewards = new DistributionParameters[](distributionListLength);
520+
ExtensiveDistributionParameters[] memory activeRewards = new ExtensiveDistributionParameters[](
521+
distributionListLength
522+
);
477523
for (uint32 i; i < distributionListLength; ) {
478-
DistributionParameters storage distribution = distributionList[i];
524+
DistributionParameters memory distribution = distributionList[i];
479525
if (
480526
_isDistributionLiveBetweenEpochs(distribution, epochStart, epochEnd) &&
481527
(uniV3Pool == address(0) || distribution.uniV3Pool == uniV3Pool)
482528
) {
483-
longActiveRewards[length] = distribution;
529+
activeRewards[length] = _getExtensiveDistributionParameters(distribution);
484530
length += 1;
485531
}
486532
unchecked {
487533
++i;
488534
}
489535
}
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)
497538
}
498539
return activeRewards;
499540
}

deploy/0_distributor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
1010
const { deployer } = await ethers.getNamedSigners();
1111

1212
let core: string;
13-
13+
core = '0xC16B81Af351BA9e64C1a069E3Ab18c244A1E3049';
14+
/*
1415
if (!network.live) {
1516
// If we're in mainnet fork, we're using the `CoreBorrow` address from mainnet
1617
core = registry(ChainId.MAINNET)?.Merkl?.CoreMerkl!;
1718
} else {
1819
// Otherwise, we're using the proxy admin address from the desired network
1920
core = registry(network.config.chainId as ChainId)?.Merkl?.CoreMerkl!;
2021
}
22+
*/
2123

2224
console.log('Let us get started with deployment');
2325
console.log(deployer.address);

deploy/1_distributionCreator.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ const argv = yargs.env('').boolean('ci').parseSync();
99
const func: DeployFunction = async ({ deployments, ethers, network }) => {
1010
const { deploy } = deployments;
1111
const { deployer } = await ethers.getNamedSigners();
12-
let core: string;
1312

13+
let core: string;
1414
if (!network.live) {
1515
// If we're in mainnet fork, we're using the `CoreBorrow` address from mainnet
1616
core = registry(ChainId.MAINNET)?.Merkl?.CoreMerkl!;
@@ -22,17 +22,18 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
2222
console.log('Now deploying DistributionCreator');
2323
console.log('Starting with the implementation');
2424

25-
await deploy('DistributionCreator_Implementation_3', {
25+
await deploy('DistributionCreator_Implementation_4', {
2626
contract: 'DistributionCreator',
2727
from: deployer.address,
2828
log: !argv.ci,
2929
});
3030

31-
const implementationAddress = (await ethers.getContract('DistributionCreator_Implementation_3')).address;
31+
const implementationAddress = (await ethers.getContract('DistributionCreator_Implementation_4')).address;
3232

3333
console.log(`Successfully deployed the implementation for DistributionCreator at ${implementationAddress}`);
3434
console.log('');
3535
/*
36+
3637
const distributor = (await deployments.get('Distributor')).address;
3738
console.log('Now deploying the Proxy');
3839
@@ -69,10 +70,12 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
6970
In the Distributor contract:
7071
- `toggleTrusted` -> keeper bot updating
7172
- `setDisputeToken` -> should we activate dispute periods
72-
- `setDisputePeriods`
73+
- `setDisputePeriod`
74+
- `setDisputeAmount`
75+
7376
*/
7477
};
7578

7679
func.tags = ['distributionCreator'];
77-
func.dependencies = ['distributor'];
80+
// func.dependencies = ['distributor'];
7881
export default func;

deploy/mockCoreBorrow.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ const argv = yargs.env('').boolean('ci').parseSync();
99
const func: DeployFunction = async ({ deployments, ethers, network }) => {
1010
const { deploy } = deployments;
1111
const { deployer } = await ethers.getNamedSigners();
12-
let coreBorrow: string;
13-
if (!network.live) {
14-
// If we're in mainnet fork, we're using the `CoreBorrow` address from mainnet
15-
coreBorrow = CONTRACTS_ADDRESSES[ChainId.MAINNET]?.CoreBorrow!;
16-
} else {
17-
// Otherwise, we're using the proxy admin address from the desired network
18-
coreBorrow = registry(network.config.chainId as ChainId)?.CoreBorrow!;
19-
}
20-
2112
console.log('Deploying a MockCoreBorrow instance');
2213
await deploy('MockCoreBorrow', {
2314
contract: 'MockCoreBorrow',

0 commit comments

Comments
 (0)