Skip to content

Commit

Permalink
Merge pull request #34 from javier123454321/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
javier123454321 authored Apr 29, 2022
2 parents c289f81 + 576155d commit a2cb61d
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 9 deletions.
107 changes: 107 additions & 0 deletions contracts/Deployer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//SPDX-License-Identifier: MIT

pragma solidity 0.8.13;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol";

contract Deployer is AccessControl{
struct ContractInfo {
address deploymentAddress;
string contractType;
}
mapping(string => bytes) contractByteCodesByKey;
mapping(address => ContractInfo[]) contractsDeloyedByEOA;
uint256 public contractDeployPrice;
uint256 discountPercentage;
address NFTDiscountContract;

/*
* @dev Deploys a contract and returns the address of the deployed contract
* @param _contractDeployPrice The price (in wei) that users must pay to deploy a contract
* @param _admin The address that can call the admin functions
* @return The address of the deployed contract
*/
constructor(uint256 _contractDeployPrice, address admin) {
contractDeployPrice = _contractDeployPrice;
_setupRole(DEFAULT_ADMIN_ROLE, admin);
}

/*
* @dev Deploys a contract and returns the address of the deployed contract
* @param contractKey The key to get the bytecode of the contract
* @param salt A parameter to make the contract deploy unique
*/
function deploySimpleTokenContract(
string calldata contractType,
bytes32 salt,
uint256 _freeSupply,
uint256 _airdropSupply,
address vault,
string memory name,
string memory symbol,
address[] memory admins
) public payable {
require(
msg.value >= contractDeployPrice,
"Insufficient payment to deploy"
);
if(salt == 0) salt = keccak256(abi.encode(getChildren(msg.sender).length));
bytes memory bytecode = getContractByteCode(contractType);
address c;
assembly {
c := create2(0, add(bytecode, 0x20), mload(bytecode), salt)
}
ContractInfo memory ci = ContractInfo(msg.sender, contractType);
contractsDeloyedByEOA[msg.sender].push(ci);
}

/*
* @dev Returns contract info deployed by the given address
* @param deployer address to lookup
* @return array of contracts deployed by deployer
*/
function getChildren(address deployer)
public
view
returns (ContractInfo[] memory contractsDeployed)
{
contractsDeployed = contractsDeloyedByEOA[deployer];
}

/*
* @dev Sets the price to deploy a contract
* @param newPrice The new price (in wei)
*/
function setContractDeployPrice(uint256 newPrice) external {
contractDeployPrice = newPrice;
}

/*
* @dev Gets the bytecode of a contract by name
* @param contractKey The key used to reference the contract
*/
function getContractByteCode(string calldata contractKey)
public
view
returns (bytes memory)
{
return contractByteCodesByKey[contractKey];
}

/*
* @dev Sets the bytecode of a contract by name
* @param contractKey The key which must be used to access the bytecode
* @param bytecode The bytecode to store
*/
function setContractByteCode(
string calldata contractKey,
bytes calldata byteCode
) external onlyRole(DEFAULT_ADMIN_ROLE) {
contractByteCodesByKey[contractKey] = byteCode;
}

function withdraw() external onlyRole(DEFAULT_ADMIN_ROLE) {
payable(address(msg.sender)).transfer(address(this).balance);
}
}
2 changes: 1 addition & 1 deletion contracts/curves/BondingCurve.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;
import "./Power.sol";

// import "hardhat/console.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/curves/Power.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;

/**
* @title Power function by Bancor
Expand Down
2 changes: 1 addition & 1 deletion contracts/testHelpers/ExposedTimedMint.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: Unlicense

pragma solidity ^0.8.6;
pragma solidity ^0.8.13;

import "../tokens/standards/ERC20TimedMint.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/tokens/CreatorToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/tokens/SimpleToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/tokens/TimedMintToken.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "./standards/ERC20TimedMint.sol";
Expand Down
2 changes: 1 addition & 1 deletion contracts/tokens/standards/ERC20TimedMint.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//SPDX-License-Identifier: Unlicensed

pragma solidity ^0.8.6;
pragma solidity ^0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/utils/Airdroppable.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//SPDX-License-Identifier: Unlicense
pragma solidity 0.8.6;
pragma solidity 0.8.13;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
* @type import('hardhat/config').HardhatUserConfig
*/
export default {
solidity: "0.8.6",
solidity: "0.8.13",
};

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"scripts": {
"compile": "npx hardhat compile",
"test": "npx hardhat test"
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.4",
"@nomiclabs/hardhat-waffle": "^2.0.1",
Expand Down
47 changes: 47 additions & 0 deletions test/Deployer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { contractByteCode } from './constants/contractBytecodes';
import { Deployer } from './../typechain/Deployer.d';
import { DeployerFactory } from './../typechain/DeployerFactory';
import { ethers } from "hardhat"
import { BigNumber, Contract, Signer } from "ethers";
import chai from "chai";
import { solidity } from "ethereum-waffle";
import { getAddress } from "@ethersproject/address";

chai.use(solidity);

const { expect } = chai;
const INITIAL_DEPLOY_PRICE = BigNumber.from("1000000000000000000");
const bytecodeForSimpleMintToken =

describe.only("Deployer", () => {
let deployerContract: Deployer,
deployerAddress: Signer,
admin: Signer,
addresses: Signer[];

const setupDeployer = async () => {
[deployerAddress, admin, ...addresses] = await ethers.getSigners();
deployerContract = await new DeployerFactory(deployerAddress).deploy(
INITIAL_DEPLOY_PRICE,
await admin.getAddress(),
);
await deployerContract.deployed();
};

describe("Deployment", async () => {
beforeEach(setupDeployer)

it("should deploy", async () => {
expect(deployerAddress).to.be.ok;
});
})
describe("Setting Contract Type", async () => {
beforeEach(setupDeployer)
it("should deploy", async () => {
const expectedBytecode = ethers.utils.defaultAbiCoder.encode([ "string" ], contractByteCode.simpleToken);
await deployerContract.setContractByteCode("test_contract_1", expectedBytecode);
const givenBytecode = await deployerContract.getContractByteCode("test_contract_1");
console.log(givenBytecode)
});
})
})
4 changes: 4 additions & 0 deletions test/constants/contractBytecodes.ts

Large diffs are not rendered by default.

0 comments on commit a2cb61d

Please sign in to comment.