Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
RuslanProgrammer committed Apr 5, 2024
1 parent e2f5406 commit 67283a1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
1 change: 0 additions & 1 deletion contracts/BaseFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ abstract contract BaseFactory {
* @param poolTypes_ the types that are associated with the pools implementations
* @param newImplementations_ the new implementations of the pools (ProxyBeacons will point to these)
*/

function _setNewImplementations(uint8[] memory poolTypes_, address[] memory newImplementations_) internal {
for (uint256 i = 0; i < poolTypes_.length; i++) {
if (address(_beacons[poolTypes_[i]]) == address(0)) {
Expand Down
8 changes: 4 additions & 4 deletions contracts/L1/CorePropertiesL1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ contract CorePropertiesL1 is Ownable {
treasuryAddress = treasuryAddress_;
}

function getFeeAndTreadury(address distributionAddress_) external view returns (uint256, address) {
return (_fees[distributionAddress_], treasuryAddress);
}

function setDeployParams(
address arbitrumGateway_,
address lZEnpointAddress_,
Expand All @@ -46,6 +42,10 @@ contract CorePropertiesL1 is Ownable {
destinationChainId = destinationChainId_;
}

function getFeeAndTreasury(address distributionAddress_) external view returns (uint256, address) {
return (_fees[distributionAddress_], treasuryAddress);
}

function getDeployParams() external view returns (address, address) {
return (arbitrumGateway, lZEnpointAddress);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/L1/Distribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ contract Distribution is IDistribution, OwnableUpgradeable {
uint256 overplus_ = overplus();
require(overplus_ > 0, "DS: overplus is zero");

(uint256 feePercent_, address treasuryAddress_) = coreProperties.getFeeAndTreadury(address(this));
(uint256 feePercent_, address treasuryAddress_) = coreProperties.getFeeAndTreasury(address(this));
uint256 fee_ = _feeAmount(overplus_, feePercent_);
IERC20(depositToken).safeTransfer(treasuryAddress_, fee_);

Expand Down
21 changes: 13 additions & 8 deletions contracts/L2/CorePropertiesL2.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {MultiOwnable} from "@solarity/solidity-lib/access/MultiOwnable.sol";

contract CorePropertiesL2 is MultiOwnable {
address public arbitrumGateway;
address public treasuryAddress;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract CorePropertiesL2 is Ownable {
address public lZEnpointAddress;
address public lZGatewayAddress;
uint16 public l1ChainId;

uint256 public destinationChainId; // arbitrum
function setDeployParams(
address lZEnpointAddress_,
address lZGatewayAddress_,
uint16 l1ChainId_
) external onlyOwner {
lZEnpointAddress = lZEnpointAddress_;
lZGatewayAddress = lZGatewayAddress_;
l1ChainId = l1ChainId_;
}

constructor() {
__MultiOwnable_init();
function getDeployParams() external view returns (address, address, uint16) {
return (lZEnpointAddress, lZGatewayAddress, l1ChainId);
}
}
41 changes: 23 additions & 18 deletions contracts/L2/Mor20FactoryL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,57 @@ pragma solidity ^0.8.20;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

import {BaseFactoryL2} from "./BaseFactoryL2.sol";
import {CorePropertiesL2} from "./CorePropertiesL2.sol";

import {IL2MessageReceiver} from "../interfaces/IL2MessageReceiver.sol";
import {IL2TokenReceiver} from "../interfaces/IL2TokenReceiver.sol";

import {CorePropertiesL2} from "./CorePropertiesL2.sol";
import {IL2MessageReceiver} from "../interfaces/IL2MessageReceiver.sol";

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

contract Mor20FactoryL2 is BaseFactoryL2, Ownable {
CorePropertiesL2 public coreProperties;

constructor(address coreProperties_) {
coreProperties = CorePropertiesL2(coreProperties_);
}

function deployMor20OnL1(Mor20DeployParams calldata parameters_) external onlyOwner {
address l2MessageReceiverAddress = _deploy2(PoolType.L2_MESSAGE_RECEIVER, parameters_.name);
(address lZEnpointAddress_, address lZGatewayAddress_, uint16 l1ChainId_) = coreProperties.getDeployParams();

address l2MessageReceiverAddress_ = _deploy2(PoolType.L2_MESSAGE_RECEIVER, parameters_.name);

address l2TokenReceiverAddress = _deploy2(PoolType.L2_TOKEN_RECEIVER, parameters_.name);
address l2TokenReceiverAddress_ = _deploy2(PoolType.L2_TOKEN_RECEIVER, parameters_.name);

address rewardTokenAddress;
address rewardTokenAddress_;
if (parameters_.rewardToken == address(0)) {
rewardTokenAddress = _deployRewardToken(
rewardTokenAddress_ = _deployRewardToken(
parameters_.name,
parameters_.symbol,
coreProperties.lZEnpointAddress(),
lZEnpointAddress_,
parameters_.rewardTokenDelegate,
l2MessageReceiverAddress
l2MessageReceiverAddress_
);
} else {
rewardTokenAddress = parameters_.rewardToken;
rewardTokenAddress_ = parameters_.rewardToken;
}

IL2MessageReceiver(l2MessageReceiverAddress).L2MessageReceiver__init(
rewardTokenAddress,
IL2MessageReceiver.Config(coreProperties.lZGatewayAddress(), parameters_.sender, coreProperties.l1ChainId())
IL2MessageReceiver(l2MessageReceiverAddress_).L2MessageReceiver__init(
rewardTokenAddress_,
IL2MessageReceiver.Config(lZGatewayAddress_, parameters_.sender, l1ChainId_)
);

IL2TokenReceiver(l2TokenReceiverAddress).L2TokenReceiver__init(
IL2TokenReceiver(l2TokenReceiverAddress_).L2TokenReceiver__init(
parameters_.router_,
parameters_.nonfungiblePositionManager_,
parameters_.firstSwapParams_,
parameters_.secondSwapParams
);

_addPool(PoolType.L2_MESSAGE_RECEIVER, l2MessageReceiverAddress);
_addPool(PoolType.L2_TOKEN_RECEIVER, l2TokenReceiverAddress);
_addPool(PoolType.REWARD_TOKEN, rewardTokenAddress);
_addPool(PoolType.L2_MESSAGE_RECEIVER, l2MessageReceiverAddress_);
_addPool(PoolType.L2_TOKEN_RECEIVER, l2TokenReceiverAddress_);
_addPool(PoolType.REWARD_TOKEN, rewardTokenAddress_);

emit Mor20Deployed(parameters_.name, l2MessageReceiverAddress, l2TokenReceiverAddress, rewardTokenAddress);
emit Mor20Deployed(parameters_.name, l2MessageReceiverAddress_, l2TokenReceiverAddress_, rewardTokenAddress_);
}

function setNewImplementations(
Expand Down

0 comments on commit 67283a1

Please sign in to comment.