-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from javier123454321/staging
Staging
- Loading branch information
Showing
13 changed files
with
171 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
}) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.