Skip to content

Commit

Permalink
fix: signing requirement (#30)
Browse files Browse the repository at this point in the history
* fix: signing

* fix: add tests to the solution proposed

* feat: polygon zkevm deployment

* fix: update scripts

* deploy new version on Polygon
  • Loading branch information
sogipec authored Jul 31, 2023
1 parent 4b44cf3 commit da3dadc
Show file tree
Hide file tree
Showing 20 changed files with 7,621 additions and 51 deletions.
7 changes: 6 additions & 1 deletion contracts/DistributionCreator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ contract DistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {

/// @notice Checks whether an address has signed the message or not
modifier hasSigned() {
if (userSignatureWhitelist[msg.sender] == 0 && userSignatures[msg.sender] != messageHash) revert NotSigned();
if (
userSignatureWhitelist[msg.sender] == 0 &&
userSignatures[msg.sender] != messageHash &&
userSignatureWhitelist[tx.origin] == 0 &&
userSignatures[tx.origin] != messageHash
) revert NotSigned();
_;
}

Expand Down
87 changes: 64 additions & 23 deletions contracts/deprecated/OldDistributionCreator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
// SPDX-License-Identifier: BUSL-1.1

/*
* █
***** ▓▓▓
* ▓▓▓▓▓▓▓
* ///. ▓▓▓▓▓▓▓▓▓▓▓▓▓
***** //////// ▓▓▓▓▓▓▓
* ///////////// ▓▓▓
▓▓ ////////////////// █ ▓▓
▓▓ ▓▓ /////////////////////// ▓▓ ▓▓
▓▓ ▓▓ //////////////////////////// ▓▓ ▓▓
▓▓ ▓▓ /////////▓▓▓///////▓▓▓///////// ▓▓ ▓▓
▓▓ ,////////////////////////////////////// ▓▓ ▓▓
▓▓ ////////////////////////////////////////// ▓▓
▓▓ //////////////////////▓▓▓▓/////////////////////
,////////////////////////////////////////////////////
.//////////////////////////////////////////////////////////
.//////////////////////////██.,//////////////////////////█
.//////////////////////████..,./////////////////////██
...////////////////███████.....,.////////////////███
,.,////////////████████ ........,///////////████
.,.,//////█████████ ,.......///////████
,..//████████ ........./████
..,██████ .....,███
.██ ,.,█
▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓ ▓▓▓▓▓▓▓▓▓▓
▓▓▓▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓ ▓▓▓▓
▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓▓ ▓▓ ▓▓▓▓▓
▓▓▓ ▓▓ ▓▓▓ ▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓
*/

pragma solidity ^0.8.17;

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

import "../interfaces/external/uniswap/IUniswapV3Pool.sol";
import "../interfaces/external/algebra/IAlgebraPool.sol";
import "../utils/UUPSHelper.sol";
import "../struct/DistributionParameters.sol";
import "../struct/ExtensiveDistributionParameters.sol";
Expand Down Expand Up @@ -111,7 +145,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {

function initialize(ICore _core, address _distributor, uint256 _fees) external initializer {
if (address(_core) == address(0) || _distributor == address(0)) revert ZeroAddress();
if (_fees > BASE_9) revert InvalidParam();
if (_fees >= BASE_9) revert InvalidParam();
distributor = _distributor;
core = _core;
fees = _fees;
Expand Down Expand Up @@ -203,6 +237,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
uint256 userFeeRebate = feeRebate[msg.sender];
if (
userFeeRebate < BASE_9 &&
// Algebra pools also have these `token0` and `token1` parameters
isWhitelistedToken[IUniswapV3Pool(distribution.uniV3Pool).token0()] == 0 &&
isWhitelistedToken[IUniswapV3Pool(distribution.uniV3Pool).token1()] == 0
) {
Expand Down Expand Up @@ -265,14 +300,10 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
++i;
}
}
RewardTokenAmounts[] memory validRewardTokensShort = new RewardTokenAmounts[](length);
for (uint32 i; i < length; ) {
validRewardTokensShort[i] = validRewardTokens[i];
unchecked {
++i;
}
assembly {
mstore(validRewardTokens, length)
}
return validRewardTokensShort;
return validRewardTokens;
}

/// @notice Returns the list of all the distributions that were or that are going to be live at
Expand Down Expand Up @@ -317,8 +348,8 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
return _getPoolDistributionsBetweenEpochs(uniV3Pool, roundedEpoch, roundedEpoch + EPOCH_DURATION);
}

/// @notice Returns the list of all distributions that were or will be live between `epochStart` (included) and `epochEnd` (excluded)
/// for a specific pool
/// @notice Returns the list of all distributions that were or will be live at some point between
/// `epochStart` (included) and `epochEnd` (excluded) for a specific pool
function getPoolDistributionsBetweenEpochs(
address uniV3Pool,
uint32 epochStart,
Expand Down Expand Up @@ -382,6 +413,7 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
uint256[] calldata amounts
) external onlyGovernorOrGuardian {
uint256 tokensLength = tokens.length;
if (tokensLength != amounts.length) revert InvalidLengths();
for (uint256 i; i < tokensLength; ++i) {
uint256 amount = amounts[i];
// Basic logic check to make sure there are no duplicates in the `rewardTokens` table. If a token is
Expand Down Expand Up @@ -422,10 +454,10 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {

/// @notice Checks whether `distribution` was live between `roundedEpochStart` and `roundedEpochEnd`
function _isDistributionLiveBetweenEpochs(
DistributionParameters storage distribution,
DistributionParameters memory distribution,
uint32 roundedEpochStart,
uint32 roundedEpochEnd
) internal view returns (bool) {
) internal pure returns (bool) {
uint256 distributionEpochStart = distribution.epochStart;
return (distributionEpochStart + distribution.numEpoch * EPOCH_DURATION > roundedEpochStart &&
distributionEpochStart < roundedEpochEnd);
Expand All @@ -450,7 +482,19 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
try IUniswapV3Pool(distribution.uniV3Pool).fee() returns (uint24 fee) {
extensiveParams.poolFee = fee;
} catch {
extensiveParams.poolFee = 0;
try IAlgebraPool(distribution.uniV3Pool).globalState() returns (
uint160,
int24,
uint16 fee,
uint16,
uint8,
uint8,
bool
) {
extensiveParams.poolFee = uint24(fee);
} catch {
extensiveParams.poolFee = 0;
}
}
extensiveParams.token0 = _getUniswapTokenData(
IERC20Metadata(IUniswapV3Pool(distribution.uniV3Pool).token0()),
Expand All @@ -473,27 +517,24 @@ contract OldDistributionCreator is UUPSHelper, ReentrancyGuardUpgradeable {
) internal view returns (ExtensiveDistributionParameters[] memory) {
uint256 length;
uint256 distributionListLength = distributionList.length;
DistributionParameters[] memory longActiveRewards = new DistributionParameters[](distributionListLength);
ExtensiveDistributionParameters[] memory activeRewards = new ExtensiveDistributionParameters[](
distributionListLength
);
for (uint32 i; i < distributionListLength; ) {
DistributionParameters storage distribution = distributionList[i];
DistributionParameters memory distribution = distributionList[i];
if (
_isDistributionLiveBetweenEpochs(distribution, epochStart, epochEnd) &&
(uniV3Pool == address(0) || distribution.uniV3Pool == uniV3Pool)
) {
longActiveRewards[length] = distribution;
activeRewards[length] = _getExtensiveDistributionParameters(distribution);
length += 1;
}
unchecked {
++i;
}
}

ExtensiveDistributionParameters[] memory activeRewards = new ExtensiveDistributionParameters[](length);
for (uint32 i; i < length; ) {
activeRewards[i] = _getExtensiveDistributionParameters(longActiveRewards[i]);
unchecked {
++i;
}
assembly {
mstore(activeRewards, length)
}
return activeRewards;
}
Expand Down
4 changes: 3 additions & 1 deletion deploy/0_distributor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
const { deployer } = await ethers.getNamedSigners();

let core: string;

core = '0xC16B81Af351BA9e64C1a069E3Ab18c244A1E3049';
/*
if (!network.live) {
// If we're in mainnet fork, we're using the `CoreBorrow` address from mainnet
core = registry(ChainId.MAINNET)?.Merkl?.CoreMerkl!;
} else {
// Otherwise, we're using the proxy admin address from the desired network
core = registry(network.config.chainId as ChainId)?.Merkl?.CoreMerkl!;
}
*/

console.log('Let us get started with deployment');
console.log(deployer.address);
Expand Down
13 changes: 8 additions & 5 deletions deploy/1_distributionCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const argv = yargs.env('').boolean('ci').parseSync();
const func: DeployFunction = async ({ deployments, ethers, network }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();
let core: string;

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

await deploy('DistributionCreator_Implementation_3', {
await deploy('DistributionCreator_Implementation_4', {
contract: 'DistributionCreator',
from: deployer.address,
log: !argv.ci,
});

const implementationAddress = (await ethers.getContract('DistributionCreator_Implementation_3')).address;
const implementationAddress = (await ethers.getContract('DistributionCreator_Implementation_4')).address;

console.log(`Successfully deployed the implementation for DistributionCreator at ${implementationAddress}`);
console.log('');
/*
const distributor = (await deployments.get('Distributor')).address;
console.log('Now deploying the Proxy');
Expand Down Expand Up @@ -69,10 +70,12 @@ const func: DeployFunction = async ({ deployments, ethers, network }) => {
In the Distributor contract:
- `toggleTrusted` -> keeper bot updating
- `setDisputeToken` -> should we activate dispute periods
- `setDisputePeriods`
- `setDisputePeriod`
- `setDisputeAmount`
*/
};

func.tags = ['distributionCreator'];
func.dependencies = ['distributor'];
// func.dependencies = ['distributor'];
export default func;
9 changes: 0 additions & 9 deletions deploy/mockCoreBorrow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ const argv = yargs.env('').boolean('ci').parseSync();
const func: DeployFunction = async ({ deployments, ethers, network }) => {
const { deploy } = deployments;
const { deployer } = await ethers.getNamedSigners();
let coreBorrow: string;
if (!network.live) {
// If we're in mainnet fork, we're using the `CoreBorrow` address from mainnet
coreBorrow = CONTRACTS_ADDRESSES[ChainId.MAINNET]?.CoreBorrow!;
} else {
// Otherwise, we're using the proxy admin address from the desired network
coreBorrow = registry(network.config.chainId as ChainId)?.CoreBorrow!;
}

console.log('Deploying a MockCoreBorrow instance');
await deploy('MockCoreBorrow', {
contract: 'MockCoreBorrow',
Expand Down
Loading

0 comments on commit da3dadc

Please sign in to comment.