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

chore docs: added missing functions in interfaces added inheritdoc #8

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"singleQuote": true,
"importOrder": ["^[./]", "^@/(.*)$"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true
"importOrderSortSpecifiers": true,
"endOfLine": "auto"
}
}
]
Expand Down
60 changes: 57 additions & 3 deletions contracts/L1/Distribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**********************************************************************************************/
Expand All @@ -50,6 +71,9 @@ contract Distribution is IDistribution, OwnableUpgradeable {
_disableInitializers();
}

/**
* @inheritdoc IDistribution
*/
function Distribution_init(
address depositToken_,
address l1Sender_,
Expand All @@ -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");

Expand All @@ -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_);

Expand All @@ -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;
Expand All @@ -127,6 +160,9 @@ contract Distribution is IDistribution, OwnableUpgradeable {
/**********************************************************************************************/
/*** User management in private pools ***/
/**********************************************************************************************/
/**
* @inheritdoc IDistribution
*/
function manageUsersInPrivatePool(
uint256 poolId_,
address[] calldata users_,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -325,6 +376,9 @@ contract Distribution is IDistribution, OwnableUpgradeable {
return depositTokenContractBalance_ - totalDepositedInPublicPools;
}

/**
* @inheritdoc IDistribution
*/
function bridgeOverplus(
uint256 gasLimit_,
uint256 maxFeePerGas_,
Expand Down
25 changes: 25 additions & 0 deletions contracts/L1/FeeConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,61 @@ 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();

treasury = treasury_;
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) {
Expand Down
59 changes: 37 additions & 22 deletions contracts/L1/L1Sender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ contract L1Sender is IL1Sender, OwnableUpgradeable {
_disableInitializers();
}

/**
* @inheritdoc IL1Sender
*/
function L1Sender__init(
address distribution_,
RewardTokenConfig calldata rewardTokenConfig_,
Expand All @@ -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_,
Expand All @@ -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;

Expand All @@ -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);
}
}
26 changes: 25 additions & 1 deletion contracts/L2/L2MessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_,
Expand All @@ -41,6 +59,9 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable {
_blockingLzReceive(senderChainId_, senderAndReceiverAddresses_, nonce_, payload_);
}

/**
* @inheritdoc IL2MessageReceiver
*/
function nonblockingLzReceive(
uint16 senderChainId_,
bytes memory senderAndReceiverAddresses_,
Expand All @@ -51,6 +72,9 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable {
_nonblockingLzReceive(senderChainId_, senderAndReceiverAddresses_, payload_);
}

/**
* @inheritdoc IL2MessageReceiver
*/
function retryMessage(
uint16 senderChainId_,
bytes memory senderAndReceiverAddresses_,
Expand Down
Loading