Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes after TestingReports review #10

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
"sourceType": "module",
"project": "./tsconfig.json"
},
"plugins": ["@typescript-eslint"],
"extends": [
Expand All @@ -11,7 +12,8 @@
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/no-unused-vars": "error"
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-floating-promises": "error"
},
"env": {
"browser": true,
Expand Down
39 changes: 18 additions & 21 deletions contracts/Distribution.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

import {PRECISION} from "@solarity/solidity-lib/utils/Globals.sol";

import {LinearDistributionIntervalDecrease} from "./libs/LinearDistributionIntervalDecrease.sol";

import {IDistribution} from "./interfaces/IDistribution.sol";
import {IMOR} from "./interfaces/IMOR.sol";
import {L1Sender} from "./L1Sender.sol";
import {IDistribution} from "./interfaces/IDistribution.sol";

contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;
Expand Down Expand Up @@ -54,7 +54,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
__Ownable_init();
__UUPSUpgradeable_init();

for (uint256 i = 0; i < poolsInfo_.length; i++) {
for (uint256 i; i < poolsInfo_.length; ++i) {
createPool(poolsInfo_[i]);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
);
}

function _validatePool(Pool calldata pool_) internal pure {
function _validatePool(Pool calldata pool_) private pure {
if (pool_.rewardDecrease > 0) {
require(pool_.decreaseInterval > 0, "DS: invalid reward decrease");
}
Expand All @@ -127,7 +127,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {

uint256 currentPoolRate_ = _getCurrentPoolRate(poolId_);

for (uint256 i = 0; i < users_.length; i++) {
for (uint256 i; i < users_.length; ++i) {
address user_ = users_[i];
uint256 amount_ = amounts_[i];

Expand Down Expand Up @@ -188,7 +188,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
return _getCurrentUserReward(currentPoolRate_, userData);
}

function _stake(address user_, uint256 poolId_, uint256 amount_, uint256 currentPoolRate_) internal {
function _stake(address user_, uint256 poolId_, uint256 amount_, uint256 currentPoolRate_) private {
require(amount_ > 0, "DS: nothing to stake");

Pool storage pool = pools[poolId_];
Expand Down Expand Up @@ -222,7 +222,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
emit UserStaked(poolId_, user_, amount_);
}

function _withdraw(address user_, uint256 poolId_, uint256 amount_, uint256 currentPoolRate_) internal {
function _withdraw(address user_, uint256 poolId_, uint256 amount_, uint256 currentPoolRate_) private {
Pool storage pool = pools[poolId_];
PoolData storage poolData = poolsData[poolId_];
UserData storage userData = usersData[user_][poolId_];
Expand All @@ -248,10 +248,8 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {

newDeposited_ = deposited_ - amount_;

require(
amount_ > 0 && (newDeposited_ >= pool.minimalStake || newDeposited_ == 0),
"DS: invalid withdraw amount"
);
require(amount_ > 0, "DS: nothing to withdraw");
require(newDeposited_ >= pool.minimalStake || newDeposited_ == 0, "DS: invalid withdraw amount");
} else {
newDeposited_ = deposited_ - amount_;
}
Expand All @@ -277,16 +275,13 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
emit UserWithdrawn(poolId_, user_, amount_);
}

function _getCurrentUserReward(
uint256 currentPoolRate_,
UserData memory userData_
) internal pure returns (uint256) {
function _getCurrentUserReward(uint256 currentPoolRate_, UserData memory userData_) private pure returns (uint256) {
uint256 newRewards_ = ((currentPoolRate_ - userData_.rate) * userData_.deposited) / PRECISION;

return userData_.pendingRewards + newRewards_;
}

function _getCurrentPoolRate(uint256 poolId_) internal view returns (uint256) {
function _getCurrentPoolRate(uint256 poolId_) private view returns (uint256) {
PoolData storage poolData = poolsData[poolId_];

if (poolData.totalDeposited == 0) {
Expand All @@ -298,7 +293,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
return poolData.rate + (rewards_ * PRECISION) / poolData.totalDeposited;
}

function _poolExists(uint256 poolId_) internal view returns (bool) {
function _poolExists(uint256 poolId_) private view returns (bool) {
return poolId_ < pools.length;
}

Expand All @@ -319,19 +314,21 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable {
uint256 gasLimit_,
uint256 maxFeePerGas_,
uint256 maxSubmissionCost_
) external payable onlyOwner returns (bytes memory bridgeMessageId_) {
) external payable onlyOwner returns (bytes memory) {
uint256 overplus_ = overplus();
require(overplus_ > 0, "DS: overplus is zero");

IERC20(depositToken).safeTransfer(l1Sender, overplus_);

bridgeMessageId_ = L1Sender(l1Sender).sendDepositToken{value: msg.value}(
bytes memory bridgeMessageId_ = L1Sender(l1Sender).sendDepositToken{value: msg.value}(
gasLimit_,
maxFeePerGas_,
maxSubmissionCost_
);

emit OverplusBridged(overplus_, bridgeMessageId_);

return bridgeMessageId_;
}

/**********************************************************************************************/
Expand Down
8 changes: 3 additions & 5 deletions contracts/L1Sender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import {ILayerZeroEndpoint} from "@layerzerolabs/lz-evm-sdk-v1-0.7/contracts/int

import {IGatewayRouter} from "@arbitrum/token-bridge-contracts/contracts/tokenbridge/libraries/gateway/IGatewayRouter.sol";

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {IWStETH} from "./interfaces/tokens/IWStETH.sol";
import {IStETH} from "./interfaces/tokens/IStETH.sol";
import {IMOR} from "./interfaces/IMOR.sol";
import {IL1Sender} from "./interfaces/IL1Sender.sol";
import {IWStETH} from "./interfaces/tokens/IWStETH.sol";

contract L1Sender is IL1Sender, ERC165, OwnableUpgradeable, UUPSUpgradeable {
address public unwrappedDepositToken;
Expand Down
2 changes: 0 additions & 2 deletions contracts/L2MessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ pragma solidity ^0.8.20;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import {ILayerZeroReceiver} from "@layerzerolabs/lz-evm-sdk-v1-0.7/contracts/interfaces/ILayerZeroReceiver.sol";

import {IMOR} from "./interfaces/IMOR.sol";
import {IL1Sender} from "./interfaces/IL1Sender.sol";
import {IL2MessageReceiver} from "./interfaces/IL2MessageReceiver.sol";

contract L2MessageReceiver is ILayerZeroReceiver, IL2MessageReceiver, OwnableUpgradeable, UUPSUpgradeable {
Expand Down
22 changes: 11 additions & 11 deletions contracts/L2TokenReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ pragma solidity ^0.8.20;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";

import {TransferHelper} from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import {ISwapRouter} from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import {TransferHelper} from "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";

import {INonfungiblePositionManager} from "./interfaces/uniswap-v3/INonfungiblePositionManager.sol";
import {IL2TokenReceiver, IERC165} from "./interfaces/IL2TokenReceiver.sol";
import {IWStETH} from "./interfaces/tokens/IWStETH.sol";
import {INonfungiblePositionManager} from "./interfaces/uniswap-v3/INonfungiblePositionManager.sol";

contract L2TokenReceiver is IL2TokenReceiver, ERC165, OwnableUpgradeable, UUPSUpgradeable {
contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable, UUPSUpgradeable {
address public router;
address public nonfungiblePositionManager;

Expand All @@ -32,11 +30,11 @@ contract L2TokenReceiver is IL2TokenReceiver, ERC165, OwnableUpgradeable, UUPSUp
_editParams(params_);
}

function supportsInterface(bytes4 interfaceId_) public view override(ERC165, IERC165) returns (bool) {
return interfaceId_ == type(IL2TokenReceiver).interfaceId || super.supportsInterface(interfaceId_);
function supportsInterface(bytes4 interfaceId_) external pure returns (bool) {
return interfaceId_ == type(IL2TokenReceiver).interfaceId || interfaceId_ == type(IERC165).interfaceId;
}

function editParams(SwapParams memory newParams_) public onlyOwner {
function editParams(SwapParams memory newParams_) external onlyOwner {
if (params.tokenIn != newParams_.tokenIn) {
TransferHelper.safeApprove(params.tokenIn, router, 0);
TransferHelper.safeApprove(params.tokenIn, nonfungiblePositionManager, 0);
Expand All @@ -49,7 +47,7 @@ contract L2TokenReceiver is IL2TokenReceiver, ERC165, OwnableUpgradeable, UUPSUp
_editParams(newParams_);
}

function swap(uint256 amountIn_, uint256 amountOutMinimum_) external onlyOwner returns (uint256 amountOut_) {
function swap(uint256 amountIn_, uint256 amountOutMinimum_) external onlyOwner returns (uint256) {
SwapParams memory params_ = params;

ISwapRouter.ExactInputSingleParams memory swapParams_ = ISwapRouter.ExactInputSingleParams({
Expand All @@ -63,9 +61,11 @@ contract L2TokenReceiver is IL2TokenReceiver, ERC165, OwnableUpgradeable, UUPSUp
sqrtPriceLimitX96: params_.sqrtPriceLimitX96
});

amountOut_ = ISwapRouter(router).exactInputSingle(swapParams_);
uint256 amountOut_ = ISwapRouter(router).exactInputSingle(swapParams_);

emit TokensSwapped(params_.tokenIn, params_.tokenOut, amountIn_, amountOut_, amountOutMinimum_);

return amountOut_;
}

function increaseLiquidityCurrentRange(
Expand Down Expand Up @@ -112,7 +112,7 @@ contract L2TokenReceiver is IL2TokenReceiver, ERC165, OwnableUpgradeable, UUPSUp
emit LiquidityIncreased(tokenId_, amount0_, amount1_, liquidity_, amountMin0_, amountMin1_);
}

function _editParams(SwapParams memory newParams_) internal {
function _editParams(SwapParams memory newParams_) private {
require(newParams_.tokenIn != address(0), "L2TR: invalid tokenIn");
require(newParams_.tokenOut != address(0), "L2TR: invalid tokenOut");

Expand Down
15 changes: 7 additions & 8 deletions contracts/MOR.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC20, ERC20Capped} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import {ERC20, ERC20Capped} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";

import {IMOR, IERC165, IERC20} from "./interfaces/IMOR.sol";
import {IMOR, IERC20, IERC165} from "./interfaces/IMOR.sol";

contract MOR is IMOR, ERC165, ERC20Capped, ERC20Burnable, Ownable {
contract MOR is IMOR, ERC20Capped, ERC20Burnable, Ownable {
constructor(uint256 cap_) ERC20("MOR", "MOR") ERC20Capped(cap_) {}

function supportsInterface(bytes4 interfaceId_) public view override(ERC165, IERC165) returns (bool) {
function supportsInterface(bytes4 interfaceId_) external pure returns (bool) {
return
interfaceId_ == type(IMOR).interfaceId ||
interfaceId_ == type(IERC20).interfaceId ||
super.supportsInterface(interfaceId_);
interfaceId_ == type(IERC165).interfaceId;
}

function cap() public view override(IMOR, ERC20Capped) returns (uint256) {
Expand All @@ -26,7 +25,7 @@ contract MOR is IMOR, ERC165, ERC20Capped, ERC20Burnable, Ownable {
_mint(account_, amount_);
}

function burn(uint256 amount_) public override(IMOR, ERC20Burnable) {
function burn(uint256 amount_) public override {
ERC20Burnable.burn(amount_);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IL2TokenReceiver.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
* This is Swap contract that swaps tokens using Uniswap V3.
Expand Down
8 changes: 1 addition & 7 deletions contracts/interfaces/IMOR.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";

/**
* This is the MOR token contract. The token is ERC20 with cap and burnable features.
Expand All @@ -20,10 +20,4 @@ interface IMOR is IERC20, IERC165 {
* @param amount_ The amount of tokens to mint.
*/
function mint(address account_, uint256 amount_) external;

/**
* The function to burn tokens.
* @param amount_ The amount of tokens to burn.
*/
function burn(uint256 amount_) external;
}
2 changes: 1 addition & 1 deletion contracts/libs/LinearDistributionIntervalDecrease.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ library LinearDistributionIntervalDecrease {
uint128 interval_,
uint128 startTime_,
uint128 endTime_
) public pure returns (uint256) {
) external pure returns (uint256) {
if (interval_ == 0) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/mock/SwapRouterMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {ISwapRouter} from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import {SafeERC20, IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract SwapRouterMock {
function exactInputSingle(ISwapRouter.ExactInputSingleParams calldata params_) external returns (uint256) {
Expand Down
3 changes: 0 additions & 3 deletions contracts/mock/tokens/StETHMock.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {PRECISION} from "@solarity/solidity-lib/utils/Globals.sol";

import {IStETH} from "../../interfaces/tokens/IStETH.sol";

contract StETHMock is ERC20 {
uint256 public totalPooledEther = PRECISION;

Expand Down
20 changes: 18 additions & 2 deletions deploy/data/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"cap": "1000000000000000000000000",
"chainsConfig": {
"senderChainId": 10121,
"receiverChainId": 10143
"senderChainId": 101,
"receiverChainId": 110
},
"pools": [
{
Expand Down Expand Up @@ -31,8 +31,24 @@
"amounts": ["1", "1"]
}
],
"L1": {
"stEth": "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84",
"wStEth": "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0"
},
"L2": {
"swapRouter": "0xE592427A0AEce92De3Edee1F18E0157C05861564",
"nonfungiblePositionManager": "0xC36442b4a4522E871399CD717aBDD847Ab11FE88",
"wStEth": "0x5979D7b546E38E414F7E9822514be443A4800529"
},
"swapParams": {
"fee": 10000,
"sqrtPriceLimitX96": 0
},
"arbitrumConfig": {
"arbitrumBridgeGatewayRouter": "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef"
},
"lzConfig": {
"lzEndpointL1": "0x66A71Dcef29A0fFBDBE3c6a460a3B5BC225Cd675",
"lzEndpointL2": "0x3c2269811836af69497E5F486A85D7316753cf62"
}
}
Loading