diff --git a/.prettierrc.json b/.prettierrc.json index 51f74c0..dcd679b 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -20,7 +20,8 @@ "singleQuote": true, "importOrder": ["^[./]", "^@/(.*)$"], "importOrderSeparation": true, - "importOrderSortSpecifiers": true + "importOrderSortSpecifiers": true, + "endOfLine": "auto" } } ] diff --git a/contracts/L1/Distribution.sol b/contracts/L1/Distribution.sol index 72296d0..ea6f309 100644 --- a/contracts/L1/Distribution.sol +++ b/contracts/L1/Distribution.sol @@ -15,18 +15,39 @@ import {IL1Sender} from "../interfaces/L1/IL1Sender.sol"; contract Distribution is IDistribution, OwnableUpgradeable { using SafeERC20 for IERC20; + /** + * @notice Address of token that will be deposited + */ address public depositToken; + + /** + * @notice Address of L1MessageSender + */ address public l1Sender; + + /** + * @notice Address of fee manager + */ address public feeConfig; - // Pool storage + /** + * @notice Array of all created pools + */ Pool[] public pools; + + /** + * @notice Pool data by its id + */ mapping(uint256 => PoolData) public poolsData; - // User storage + /** + * @notice User storage + */ mapping(address => mapping(uint256 => UserData)) public usersData; - // Total deposited storage + /** + * @notice Total deposited storage + */ uint256 public totalDepositedInPublicPools; /**********************************************************************************************/ @@ -50,6 +71,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { _disableInitializers(); } + /** + * @inheritdoc IDistribution + */ function Distribution_init( address depositToken_, address l1Sender_, @@ -70,6 +94,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { /**********************************************************************************************/ /*** Pool management and data retrieval ***/ /**********************************************************************************************/ + /** + * @inheritdoc IDistribution + */ function createPool(Pool calldata pool_) public onlyOwner { require(pool_.payoutStart > block.timestamp, "DS: invalid payout start value"); @@ -79,6 +106,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { emit PoolCreated(pools.length - 1, pool_); } + /** + * @inheritdoc IDistribution + */ function editPool(uint256 poolId_, Pool calldata pool_) external onlyOwner poolExists(poolId_) { _validatePool(pool_); @@ -102,6 +132,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { emit PoolEdited(poolId_, pool_); } + /** + * @inheritdoc IDistribution + */ function getPeriodReward(uint256 poolId_, uint128 startTime_, uint128 endTime_) public view returns (uint256) { if (!_poolExists(poolId_)) { return 0; @@ -127,6 +160,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { /**********************************************************************************************/ /*** User management in private pools ***/ /**********************************************************************************************/ + /** + * @inheritdoc IDistribution + */ function manageUsersInPrivatePool( uint256 poolId_, address[] calldata users_, @@ -154,10 +190,16 @@ contract Distribution is IDistribution, OwnableUpgradeable { /**********************************************************************************************/ /*** Stake, claim, withdraw ***/ /**********************************************************************************************/ + /** + * @inheritdoc IDistribution + */ function stake(uint256 poolId_, uint256 amount_) external poolExists(poolId_) poolPublic(poolId_) { _stake(_msgSender(), poolId_, amount_, _getCurrentPoolRate(poolId_)); } + /** + * @inheritdoc IDistribution + */ function claim(uint256 poolId_, address receiver_) external payable poolExists(poolId_) { address user_ = _msgSender(); @@ -185,10 +227,16 @@ contract Distribution is IDistribution, OwnableUpgradeable { emit UserClaimed(poolId_, user_, receiver_, pendingRewards_); } + /** + * @inheritdoc IDistribution + */ function withdraw(uint256 poolId_, uint256 amount_) external poolExists(poolId_) poolPublic(poolId_) { _withdraw(_msgSender(), poolId_, amount_, _getCurrentPoolRate(poolId_)); } + /** + * @inheritdoc IDistribution + */ function getCurrentUserReward(uint256 poolId_, address user_) external view returns (uint256) { if (!_poolExists(poolId_)) { return 0; @@ -316,6 +364,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { /*** Bridge ***/ /**********************************************************************************************/ + /** + * @inheritdoc IDistribution + */ function overplus() public view returns (uint256) { uint256 depositTokenContractBalance_ = IERC20(depositToken).balanceOf(address(this)); if (depositTokenContractBalance_ <= totalDepositedInPublicPools) { @@ -325,6 +376,9 @@ contract Distribution is IDistribution, OwnableUpgradeable { return depositTokenContractBalance_ - totalDepositedInPublicPools; } + /** + * @inheritdoc IDistribution + */ function bridgeOverplus( uint256 gasLimit_, uint256 maxFeePerGas_, diff --git a/contracts/L1/FeeConfig.sol b/contracts/L1/FeeConfig.sol index a9e3447..a2d6ffd 100644 --- a/contracts/L1/FeeConfig.sol +++ b/contracts/L1/FeeConfig.sol @@ -8,11 +8,24 @@ import {PRECISION} from "@solarity/solidity-lib/utils/Globals.sol"; import {IFeeConfig} from "../interfaces/L1/IFeeConfig.sol"; contract FeeConfig is IFeeConfig, OwnableUpgradeable { + /** + * @notice Address of treasury where fees will be transfered + */ address public treasury; + + /** + * @notice Base fee + */ uint256 public baseFee; + /** + * @notice Sender => Fee + */ mapping(address => uint256) public fees; + /** + * @inheritdoc IFeeConfig + */ function __FeeConfig_init(address treasury_, uint256 baseFee_) external initializer { __Ownable_init(); @@ -20,24 +33,36 @@ contract FeeConfig is IFeeConfig, OwnableUpgradeable { baseFee = baseFee_; } + /** + * @inheritdoc IFeeConfig + */ function setFee(address sender_, uint256 fee_) external onlyOwner { require(fee_ <= PRECISION, "FC: invalid fee"); fees[sender_] = fee_; } + /** + * @inheritdoc IFeeConfig + */ function setTreasury(address treasury_) external onlyOwner { require(treasury_ != address(0), "FC: invalid treasury"); treasury = treasury_; } + /** + * @inheritdoc IFeeConfig + */ function setBaseFee(uint256 baseFee_) external onlyOwner { require(baseFee_ < PRECISION, "FC: invalid base fee"); baseFee = baseFee_; } + /** + * @inheritdoc IFeeConfig + */ function getFeeAndTreasury(address sender_) external view returns (uint256, address) { uint256 fee_ = fees[sender_]; if (fee_ == 0) { diff --git a/contracts/L1/L1Sender.sol b/contracts/L1/L1Sender.sol index 9d14b27..8d34d6f 100644 --- a/contracts/L1/L1Sender.sol +++ b/contracts/L1/L1Sender.sol @@ -27,6 +27,9 @@ contract L1Sender is IL1Sender, OwnableUpgradeable { _disableInitializers(); } + /** + * @inheritdoc IL1Sender + */ function L1Sender__init( address distribution_, RewardTokenConfig calldata rewardTokenConfig_, @@ -39,37 +42,24 @@ contract L1Sender is IL1Sender, OwnableUpgradeable { _setDepositTokenConfig(depositTokenConfig_); } + /** + * @inheritdoc IERC165 + */ function supportsInterface(bytes4 interfaceId_) external pure returns (bool) { return interfaceId_ == type(IL1Sender).interfaceId || interfaceId_ == type(IERC165).interfaceId; } + /** + * @inheritdoc IL1Sender + */ function setRewardTokenLZParams(address zroPaymentAddress_, bytes calldata adapterParams_) external onlyOwner { rewardTokenConfig.zroPaymentAddress = zroPaymentAddress_; rewardTokenConfig.adapterParams = adapterParams_; } - function _setDepositTokenConfig(DepositTokenConfig calldata newConfig_) private { - require(newConfig_.receiver != address(0), "L1S: invalid receiver"); - - _setDepositToken(newConfig_.token); - _setDepositTokenGateway(newConfig_.gateway, newConfig_.token); - - depositTokenConfig = newConfig_; - } - - function _setDepositToken(address newToken_) private { - // Get stETH from wstETH - address unwrappedToken_ = IWStETH(newToken_).stETH(); - // Increase allowance from stETH to wstETH. To exchange stETH for wstETH - IERC20(unwrappedToken_).approve(newToken_, type(uint256).max); - - unwrappedDepositToken = unwrappedToken_; - } - - function _setDepositTokenGateway(address newGateway_, address newToken_) private { - IERC20(newToken_).approve(IGatewayRouter(newGateway_).getGateway(newToken_), type(uint256).max); - } - + /** + * @inheritdoc IL1Sender + */ function sendDepositToken( uint256 gasLimit_, uint256 maxFeePerGas_, @@ -95,6 +85,9 @@ contract L1Sender is IL1Sender, OwnableUpgradeable { ); } + /** + * @inheritdoc IL1Sender + */ function sendMintMessage(address user_, uint256 amount_, address refundTo_) external payable onlyDistribution { RewardTokenConfig storage config = rewardTokenConfig; @@ -110,4 +103,26 @@ contract L1Sender is IL1Sender, OwnableUpgradeable { config.adapterParams // adapterParams (see "Advanced Features") ); } + + function _setDepositTokenConfig(DepositTokenConfig calldata newConfig_) private { + require(newConfig_.receiver != address(0), "L1S: invalid receiver"); + + _setDepositToken(newConfig_.token); + _setDepositTokenGateway(newConfig_.gateway, newConfig_.token); + + depositTokenConfig = newConfig_; + } + + function _setDepositToken(address newToken_) private { + // Get stETH from wstETH + address unwrappedToken_ = IWStETH(newToken_).stETH(); + // Increase allowance from stETH to wstETH. To exchange stETH for wstETH + IERC20(unwrappedToken_).approve(newToken_, type(uint256).max); + + unwrappedDepositToken = unwrappedToken_; + } + + function _setDepositTokenGateway(address newGateway_, address newToken_) private { + IERC20(newToken_).approve(IGatewayRouter(newGateway_).getGateway(newToken_), type(uint256).max); + } } diff --git a/contracts/L2/L2MessageReceiver.sol b/contracts/L2/L2MessageReceiver.sol index 30da088..702b1e9 100644 --- a/contracts/L2/L2MessageReceiver.sol +++ b/contracts/L2/L2MessageReceiver.sol @@ -7,29 +7,47 @@ import {IMOR20} from "../interfaces/L2/IMOR20.sol"; import {IL2MessageReceiver} from "../interfaces/L2/IL2MessageReceiver.sol"; contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable { + /** + * @notice MOR20 token + */ address public rewardToken; + /** + * @notice L2Receiver config + */ Config public config; + /** + * @notice ChainId => ((Sender, Receiver) => (nonce => payload hash)) + */ mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages; constructor() { _disableInitializers(); } - function L2MessageReceiver__init(address rewardToken_, Config calldata config_) external initializer { + /** + * @inheritdoc IL2MessageReceiver + */ + function L2MessageReceiver__init(address rewardToken_, Config calldata config_) external override initializer { __Ownable_init(); rewardToken = rewardToken_; config = config_; } + /** + * @inheritdoc IL2MessageReceiver + */ function setLzSender(address lzSender_) external onlyOwner { require(lzSender_ != address(0), "L2MR: invalid sender"); config.sender = lzSender_; } + /** + * @inheritdoc IL2MessageReceiver + */ function lzReceive( uint16 senderChainId_, bytes memory senderAndReceiverAddresses_, @@ -41,6 +59,9 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable { _blockingLzReceive(senderChainId_, senderAndReceiverAddresses_, nonce_, payload_); } + /** + * @inheritdoc IL2MessageReceiver + */ function nonblockingLzReceive( uint16 senderChainId_, bytes memory senderAndReceiverAddresses_, @@ -51,6 +72,9 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable { _nonblockingLzReceive(senderChainId_, senderAndReceiverAddresses_, payload_); } + /** + * @inheritdoc IL2MessageReceiver + */ function retryMessage( uint16 senderChainId_, bytes memory senderAndReceiverAddresses_, diff --git a/contracts/L2/L2TokenReceiver.sol b/contracts/L2/L2TokenReceiver.sol index 3363016..4f9f0a0 100644 --- a/contracts/L2/L2TokenReceiver.sol +++ b/contracts/L2/L2TokenReceiver.sol @@ -11,16 +11,33 @@ import {IL2TokenReceiver, IERC165, IERC721Receiver} from "../interfaces/L2/IL2To import {INonfungiblePositionManager} from "../interfaces/uniswap-v3/INonfungiblePositionManager.sol"; contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { + /** + * @notice Address of uniswap v3 router + */ address public router; + + /** + * @notice Uniswap v3 position nft + */ address public nonfungiblePositionManager; + /** + * @notice 1 struct of params to perform swap with + */ SwapParams public firstSwapParams; + + /** + * @notice 2 struct of params to perform swap with + */ SwapParams public secondSwapParams; constructor() { _disableInitializers(); } + /** + * @inheritdoc IL2TokenReceiver + */ function L2TokenReceiver__init( address router_, address nonfungiblePositionManager_, @@ -36,6 +53,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { _addAllowanceUpdateSwapParams(secondSwapParams_, false); } + /** + * @inheritdoc IERC165 + */ function supportsInterface(bytes4 interfaceId_) external pure returns (bool) { return interfaceId_ == type(IL2TokenReceiver).interfaceId || @@ -43,6 +63,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { interfaceId_ == type(IERC165).interfaceId; } + /** + * @inheritdoc IL2TokenReceiver + */ function editParams(SwapParams memory newParams_, bool isEditFirstParams_) external onlyOwner { SwapParams memory params_ = _getSwapParams(isEditFirstParams_); @@ -58,14 +81,23 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { _addAllowanceUpdateSwapParams(newParams_, isEditFirstParams_); } + /** + * @inheritdoc IL2TokenReceiver + */ function withdrawToken(address recipient_, address token_, uint256 amount_) external onlyOwner { TransferHelper.safeTransfer(token_, recipient_, amount_); } + /** + * @inheritdoc IL2TokenReceiver + */ function withdrawTokenId(address recipient_, address token_, uint256 tokenId_) external onlyOwner { IERC721(token_).safeTransferFrom(address(this), recipient_, tokenId_); } + /** + * @inheritdoc IL2TokenReceiver + */ function swap( uint256 amountIn_, uint256 amountOutMinimum_, @@ -93,6 +125,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { return amountOut_; } + /** + * @inheritdoc IL2TokenReceiver + */ function increaseLiquidityCurrentRange( uint256 tokenId_, uint256 amount0Add_, @@ -117,6 +152,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { emit LiquidityIncreased(tokenId_, amount0_, amount1_, liquidity_, amount0Min_, amount1Min_); } + /** + * @inheritdoc IL2TokenReceiver + */ function decreaseLiquidityCurrentRange( uint256 tokenId_, uint128 liquidity_, @@ -139,6 +177,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { emit LiquidityDecreased(tokenId_, amount0_, amount1_, liquidity_, amount0Min_, amount1Min_); } + /** + * @inheritdoc IL2TokenReceiver + */ function collectFees(uint256 tokenId_) public returns (uint256 amount0_, uint256 amount1_) { INonfungiblePositionManager.CollectParams memory params_ = INonfungiblePositionManager.CollectParams({ tokenId: tokenId_, @@ -152,6 +193,9 @@ contract L2TokenReceiver is IL2TokenReceiver, OwnableUpgradeable { emit FeesCollected(tokenId_, amount0_, amount1_); } + /** + * @inheritdoc IERC721Receiver + */ function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) { return this.onERC721Received.selector; } diff --git a/contracts/interfaces/L1/IL1Sender.sol b/contracts/interfaces/L1/IL1Sender.sol index a7c3f46..252c162 100644 --- a/contracts/interfaces/L1/IL1Sender.sol +++ b/contracts/interfaces/L1/IL1Sender.sol @@ -49,6 +49,13 @@ interface IL1Sender is IERC165 { */ function unwrappedDepositToken() external view returns (address); + /** + * Updated ZKSync payment contract address and adapter parameters in reward token config + * @param zroPaymentAddress_ New ZKSync payment contract + * @param adapterParams_ New adapter params + */ + function setRewardTokenLZParams(address zroPaymentAddress_, bytes calldata adapterParams_) external; + /** * The function to send the message of mint of reward token to the L2. * @param user_ The user's address to mint reward tokens. diff --git a/contracts/interfaces/L2/IL2MessageReceiver.sol b/contracts/interfaces/L2/IL2MessageReceiver.sol index c1cf139..7034589 100644 --- a/contracts/interfaces/L2/IL2MessageReceiver.sol +++ b/contracts/interfaces/L2/IL2MessageReceiver.sol @@ -63,6 +63,26 @@ interface IL2MessageReceiver is ILayerZeroReceiver { */ function rewardToken() external view returns (address); + /** + * Update L1Sender address. Only callable for owner + * @param lzSender_ New sender address + */ + function setLzSender(address lzSender_) external; + + /** + * The function to call blockingLzReceive + * @param senderChainId_ The source endpoint identifier + * @param senderAndReceiverAddresses_ The source sending contract address from the source chain + * @param nonce_ The ordered message nonce + * @param payload_ The signed payload is the UA bytes has encoded to be sent + */ + function lzReceive( + uint16 senderChainId_, + bytes memory senderAndReceiverAddresses_, + uint64 nonce_, + bytes memory payload_ + ) external; + /** * The function to call the nonblockingLzReceive. * @param senderChainId_ The source endpoint identifier.