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

feat: [sc-2168] LBPFactoryNoAccessControl #116

Open
wants to merge 7 commits into
base: development
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
52 changes: 26 additions & 26 deletions .github/workflows/ci-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,29 @@ jobs:
- name: Tests the project
run: npm run test

coverage:
runs-on: ubuntu-latest

needs: test

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"

# Runs a single command using the runners shell
- name: Installs needed packages using npm
run: npm i && npm install -g codecov

# Runs a single command using the runners shell
- name: Tests the project
run: npm run coverage

# Runs a single command using the runners shell
- name: Tests the project
run: codecov
env:
CODECOV_TOKEN: "9095761f-e37d-44f6-97b2-b123131a342f"
# coverage:
# runs-on: ubuntu-latest

# needs: test

# # Steps represent a sequence of tasks that will be executed as part of the job
# steps:
# # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
# - uses: actions/checkout@v2
# - uses: actions/setup-node@v2
# with:
# node-version: "14"

# # Runs a single command using the runners shell
# - name: Installs needed packages using npm
# run: npm i && npm install -g codecov

# # Runs a single command using the runners shell
# - name: Tests the project
# run: npm run coverage

# # Runs a single command using the runners shell
# - name: Tests the project
# run: codecov
# env:
# CODECOV_TOKEN: "9095761f-e37d-44f6-97b2-b123131a342f"
7 changes: 4 additions & 3 deletions contracts/lbp/LBPManagerFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ pragma solidity 0.8.17;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should rename this file too to include "V1"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUT, I'm also fine with maybe not versioning LBP for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not add the version to the standard LBPManagerFactory because for now, we will only use the other one

import "../utils/CloneFactory.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./LBPManager.sol";
import "./LBPManagerV1.sol";

/**
* @title LBPManager Factory
* @dev Governance to create new LBPManager contracts.
*/
contract LBPManagerFactory is CloneFactory, Ownable {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
contract LBPManagerFactory is CloneFactory, Ownable {
contract LBPManagerFactoryV1 is CloneFactory, Ownable {

bytes6 public version = "2.1.0";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expected to see "1.0.0" here, since LBP is still v1?

I also expect LBP and Seed versioning to be independent.
MAYBE we can find a case to tie the versions together, but I doubt that.

address public masterCopy;
address public lbpFactory;

Expand Down Expand Up @@ -134,7 +135,7 @@ contract LBPManagerFactory is CloneFactory, Ownable {

address lbpManager = createClone(masterCopy);

LBPManager(lbpManager).initializeLBPManager(
LBPManagerV1(lbpManager).initializeLBPManager(
lbpFactory,
_beneficiary,
_name,
Expand All @@ -148,7 +149,7 @@ contract LBPManagerFactory is CloneFactory, Ownable {
_metadata
);

LBPManager(lbpManager).transferAdminRights(_admin);
LBPManagerV1(lbpManager).transferAdminRights(_admin);

emit LBPManagerDeployed(lbpManager, _admin, _metadata);
}
Expand Down
159 changes: 159 additions & 0 deletions contracts/lbp/LBPManagerFactoryV1NoAccessControl.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
██████╗░██████╗░██╗███╗░░░███╗███████╗██████╗░░█████╗░░█████╗░
██╔══██╗██╔══██╗██║████╗░████║██╔════╝██╔══██╗██╔══██╗██╔══██╗
██████╔╝██████╔╝██║██╔████╔██║█████╗░░██║░░██║███████║██║░░██║
██╔═══╝░██╔══██╗██║██║╚██╔╝██║██╔══╝░░██║░░██║██╔══██║██║░░██║
██║░░░░░██║░░██║██║██║░╚═╝░██║███████╗██████╔╝██║░░██║╚█████╔╝
╚═╝░░░░░╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝╚══════╝╚═════╝░╚═╝░░╚═╝░╚════╝░
*/

// SPDX-License-Identifier: GPL-3.0-or-later
// LBPManager Factory contract. Governance to create new LBPManager contracts.
// Copyright (C) 2021 PrimeDao

// solium-disable linebreak-style
pragma solidity 0.8.17;

import "../utils/CloneFactory.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./LBPManagerV1.sol";

/**
* @title LBPManager Factory no access control version 1
* @dev Governance to create new LBPManager contract without the onlyOwner modifer for the
* function deployLBPManager(). By removing the access control, everyone can deploy a
* LBPManager from this contract. This is a temporarly solution in response to the
* flaky Celo Safe.
*/
contract LBPManagerFactoryV1NoAccessControl is CloneFactory, Ownable {
bytes6 public version = "1.0.0";
address public masterCopy;
address public lbpFactory;

event LBPManagerDeployed(
address indexed lbpManager,
address indexed admin,
bytes metadata
);

event LBPFactoryChanged(
address indexed oldLBPFactory,
address indexed newLBPFactory
);

event MastercopyChanged(
address indexed oldMasterCopy,
address indexed newMasterCopy
);

/**
* @dev Constructor.
* @param _lbpFactory The address of Balancers LBP factory.
*/
constructor(address _lbpFactory) {
require(_lbpFactory != address(0), "LBPMFactory: LBPFactory is zero");
lbpFactory = _lbpFactory;
}

modifier validAddress(address addressToCheck) {
require(addressToCheck != address(0), "LBPMFactory: address is zero");
// solhint-disable-next-line reason-string
require(
addressToCheck != address(this),
"LBPMFactory: address same as LBPManagerFactory"
);
_;
}

/**
* @dev Set LBPManager contract which works as a base for clones.
* @param _masterCopy The address of the new LBPManager basis.
*/
function setMasterCopy(address _masterCopy)
external
onlyOwner
validAddress(_masterCopy)
{
emit MastercopyChanged(masterCopy, _masterCopy);
masterCopy = _masterCopy;
}

/**
* @dev Set Balancers LBP Factory contract as basis for deploying LBPs.
* @param _lbpFactory The address of Balancers LBP factory.
*/
function setLBPFactory(address _lbpFactory)
external
onlyOwner
validAddress(_lbpFactory)
{
emit LBPFactoryChanged(lbpFactory, _lbpFactory);
lbpFactory = _lbpFactory;
}

/**
* @dev Deploy and initialize LBPManager.
* @param _admin The address of the admin of the LBPManager.
* @param _beneficiary The address that receives the _fees.
* @param _name Name of the LBP.
* @param _symbol Symbol of the LBP.
* @param _tokenList Numerically sorted array (ascending) containing two addresses:
- The address of the project token being distributed.
- The address of the funding token being exchanged for the project token.
* @param _amounts Sorted array to match the _tokenList, containing two parameters:
- The amounts of project token to be added as liquidity to the LBP.
- The amounts of funding token to be added as liquidity to the LBP.
* @param _startWeights Sorted array to match the _tokenList, containing two parametes:
- The start weight for the project token in the LBP.
- The start weight for the funding token in the LBP.
* @param _startTimeEndtime Array containing two parameters:
- Start time for the LBP.
- End time for the LBP.
* @param _endWeights Sorted array to match the _tokenList, containing two parametes:
- The end weight for the project token in the LBP.
- The end weight for the funding token in the LBP.
* @param _fees Array containing two parameters:
- Percentage of fee paid for every swap in the LBP.
- Percentage of fee paid to the _beneficiary for providing the service of the LBP Manager.
* @param _metadata IPFS Hash of the LBP creation wizard information.
*/
function deployLBPManager(
address _admin,
address _beneficiary,
string memory _name,
string memory _symbol,
IERC20[] memory _tokenList,
uint256[] memory _amounts,
uint256[] memory _startWeights,
uint256[] memory _startTimeEndtime,
uint256[] memory _endWeights,
uint256[] memory _fees,
bytes memory _metadata
) external {
// solhint-disable-next-line reason-string
require(
masterCopy != address(0),
"LBPMFactory: LBPManager mastercopy not set"
);

address lbpManager = createClone(masterCopy);

LBPManagerV1(lbpManager).initializeLBPManager(
lbpFactory,
_beneficiary,
_name,
_symbol,
_tokenList,
_amounts,
_startWeights,
_startTimeEndtime,
_endWeights,
_fees,
_metadata
);

LBPManagerV1(lbpManager).transferAdminRights(_admin);

emit LBPManagerDeployed(lbpManager, _admin, _metadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import "../utils/interface/IVault.sol";
import "../utils/interface/ILBP.sol";

/**
* @title LBPManager contract.
* @title LBPManager contract version 1
* @dev Smart contract for managing interactions with a Balancer LBP.
*/
// solhint-disable-next-line max-states-count
contract LBPManager {
contract LBPManagerV1 {
bytes6 public version = "1.0.0";
// Constants
uint256 private constant HUNDRED_PERCENT = 1e18; // Used in calculating the fee.

Expand Down
49 changes: 49 additions & 0 deletions deploy/04_deploy_lbpV1NoAccessControl_contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { getBalancerContractAddress } = require("@balancer-labs/v2-deployments");

const deployFunction = async ({
getNamedAccounts,
deployments,
ethers,
network,
}) => {
const { deploy } = deployments;
const { root } = await getNamedAccounts();

const liquidityBootstrappingPoolFactoryTaskId =
"20211202-no-protocol-fee-lbp";
const contractName = "LiquidityBootstrappingPoolFactory";

// Balancer contracts are not deployed on Celo and Alfajores, so we're using Symmetric/root instead
const lbpFactoryAddress =
network.name === "celo"
? "0xdF87a2369FAa3140613c3C5D008A9F50B3303fD3" // can be found https://docs.symmetric.exchange/general-resources-and-tools/symmetric-contract-addresses#v2-contracts
: network.name === "goerli"
? "0xb48Cc42C45d262534e46d5965a9Ac496F1B7a830" // can be found https://dev.balancer.fi/references/contracts/deployment-addresses
: // ToDo: Need to be updated to new package
await getBalancerContractAddress(
liquidityBootstrappingPoolFactoryTaskId,
contractName,
network.name
);

await deploy("LBPManagerFactoryV1NoAccessControl", {
from: root,
args: [lbpFactoryAddress],
log: true,
});

const { address: lbpManagerAddress } = await deploy("LBPManagerV1", {
from: root,
args: [],
log: true,
});

const lbpManagerFactoryInstance = await ethers.getContract(
"LBPManagerFactoryV1NoAccessControl"
);

await lbpManagerFactoryInstance.setMasterCopy(lbpManagerAddress);
};

module.exports = deployFunction;
module.exports.tags = ["LBPNoAccessControl"];
Loading