Skip to content

Commit

Permalink
feat: ilo v3 (#41)
Browse files Browse the repository at this point in the history
Co-authored-by: Nguyen Khoi Nguyen <[email protected]>
Co-authored-by: Jarvis Nguyen <[email protected]>
Co-authored-by: jarvis <[email protected]>
Co-authored-by: nguyennk92 <[email protected]>
  • Loading branch information
5 people authored Aug 30, 2024
1 parent bc35dd9 commit 2aca7e8
Show file tree
Hide file tree
Showing 45 changed files with 2,071 additions and 1,845 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ node_modules
# TypeChain files
/typechain
/typechain-types

.prettierrc.json
.solhint.json
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif
DEPLOY_CMD = forge script script/Deploy.s.sol:$(CONTRACT)Script --rpc-url $(RPC_URL) --broadcast

.PHONY: clean test
all: clean deploy-all-contract verify-all-contract
all: clean deploy-all-contracts verify-all-contracts
test:
forge test --gas-report
clean:
Expand All @@ -15,13 +15,16 @@ ilo-manager:
$(eval CONTRACT=ILOManager)
ilo-pool:
$(eval CONTRACT=ILOPool)
ilo-pool-sale:
$(eval CONTRACT=ILOPoolSale)
token-factory:
$(eval CONTRACT=TokenFactory)
all-contract:
$(eval CONTRACT=AllContract)
deploy-all-contract:
all-contracts:
$(eval CONTRACT=AllContracts)
deploy-all-contracts:
deploy-ilo-manager:
deploy-ilo-pool:
deploy-ilo-pool-sale:
deploy-token-factory:
deploy-token-factory-legacy:
deploy-ilo-manager-legacy:
Expand All @@ -35,10 +38,11 @@ deploy-%-legacy: %
deploy-%-with-gas-price: %
$(DEPLOY_CMD) --legacy --gas-price $(GAS_PRICE)

verify-all-contract:
verify--all-contracts:
verify-ilo-manager:
verify-token-factory:
verify-ilo-pool:
verify-ilo-pool-sale:
verify-%: %
forge script script/Verify.s.sol:Verify$(CONTRACT)Script | awk 'END{print}' | bash
init-ilo-manager:
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@uniswap/v3-sdk": "^3.11.2",
"hardhat": "^2.22.3",
"hardhat-erc1820": "^0.1.0",
"prettier": "^3.2.5",
"prettier": "^3.3.3",
"prettier-plugin-solidity": "^1.3.1"
}
}
88 changes: 48 additions & 40 deletions script/Common.s.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;

import "forge-std/Script.sol";
import "@openzeppelin/contracts/utils/Create2.sol";
import "../src/ILOPool.sol";
import "../src/ILOManager.sol";
import "../src/TokenFactory.sol";
import { Create2 } from '@openzeppelin/contracts/utils/Create2.sol';
import { Script } from 'forge-std/Script.sol';
import { ILOPool } from '../src/ILOPool.sol';
import { ILOPoolSale } from '../src/ILOPoolSale.sol';
import { ILOManager } from '../src/ILOManager.sol';
import { TokenFactory } from '../src/TokenFactory.sol';

abstract contract CommonScript is Script {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
bytes16 private constant HEX_DIGITS = '0123456789abcdef';

bytes32 salt;
address factory = 0x4e59b44847b379578588920cA78FbF26c0B4956C;

function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
function toHexString(
uint256 value,
uint256 length
) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
buffer[0] = '0';
buffer[1] = 'x';
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
Expand All @@ -33,43 +37,47 @@ abstract contract CommonScript is Script {
return toHexString(uint256(uint160(addr)), 20);
}

function getILOManagerDeploymentAddress() internal view returns(address) {
return Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(ILOManager).creationCode
)
),
factory
);
function getILOManagerDeploymentAddress() internal view returns (address) {
return
Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(ILOManager).creationCode)),
factory
);
}

function getILOPoolDeploymentAddress() internal view returns(address) {
return Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(ILOPool).creationCode
)
),
factory
);
function getILOPoolDeploymentAddress() internal view returns (address) {
return
Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(ILOPool).creationCode)),
factory
);
}

function getTokenFactoryDeploymentAddress() internal view returns(address) {
return Create2.computeAddress(
salt,
keccak256(
abi.encodePacked(
type(TokenFactory).creationCode
)
),
factory
);
function getILOPoolSaleDeploymentAddress() internal view returns (address) {
return
Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(ILOPoolSale).creationCode)),
factory
);
}

function getTokenFactoryDeploymentAddress()
internal
view
returns (address)
{
return
Create2.computeAddress(
salt,
keccak256(abi.encodePacked(type(TokenFactory).creationCode)),
factory
);
}

constructor() {
salt = keccak256(bytes(vm.envString("SALT_SEED")));
salt = keccak256(bytes(vm.envString('SALT_SEED')));
}
}
81 changes: 49 additions & 32 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -1,74 +1,91 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;

import "./Common.s.sol";
import { IILOManager } from '../src/interfaces/IILOManager.sol';
import { CommonScript } from './Common.s.sol';
import { ILOPool } from '../src/ILOPool.sol';
import { ILOManager } from '../src/ILOManager.sol';
import { ILOPoolSale } from '../src/ILOPoolSale.sol';
import { TokenFactory } from '../src/TokenFactory.sol';

contract AllContractScript is CommonScript {
contract AllContractsScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
address uniV3Factory = vm.envAddress("UNIV3_FACTORY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
address uniV3Factory = vm.envAddress('UNIV3_FACTORY');
vm.startBroadcast(deployerPrivateKey);
// create contracts
{
ILOPool iloPool = new ILOPool{
salt: salt
}();

ILOManager ilo = new ILOManager{
salt: salt
}();
ILOPool iloPool = new ILOPool{ salt: salt }();
ILOPoolSale iloPoolSale = new ILOPoolSale{ salt: salt }();
ILOManager ilo = new ILOManager{ salt: salt }();
}

// initialize ilo manager
{
address _feeTaker = vm.envAddress("FEE_TAKER");
address _initialOwner = vm.envAddress("OWNER");
uint256 initProjectFee = vm.envUint("INIT_PROJECT_FEE");
uint16 platformFee = uint16(vm.envUint("PLATFORM_FEE"));
uint16 performanceFee = uint16(vm.envUint("PERFORMANCE_FEE"));

IILOManager iloManager = IILOManager(getILOManagerDeploymentAddress());
iloManager.initialize(_initialOwner, _feeTaker, getILOPoolDeploymentAddress(), uniV3Factory, initProjectFee, platformFee, performanceFee);
address _feeTaker = vm.envAddress('FEE_TAKER');
address _initialOwner = vm.envAddress('OWNER');
uint256 initProjectFee = vm.envUint('INIT_PROJECT_FEE');
uint16 platformFee = uint16(vm.envUint('PLATFORM_FEE'));
uint16 performanceFee = uint16(vm.envUint('PERFORMANCE_FEE'));

IILOManager iloManager = IILOManager(
getILOManagerDeploymentAddress()
);
iloManager.initialize(
_initialOwner,
_feeTaker,
getILOPoolDeploymentAddress(),
getILOPoolSaleDeploymentAddress(),
uniV3Factory,
initProjectFee,
platformFee,
performanceFee
);
}
vm.stopBroadcast();
}
}

contract ILOManagerScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
vm.startBroadcast(deployerPrivateKey);

ILOManager ilo = new ILOManager{
salt: salt
}();
ILOManager ilo = new ILOManager{ salt: salt }();

vm.stopBroadcast();
}
}

contract ILOPoolScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
vm.startBroadcast(deployerPrivateKey);

ILOPool iloPool = new ILOPool{
salt: salt
}();
ILOPool iloPool = new ILOPool{ salt: salt }();

vm.stopBroadcast();
}
}

contract ILOPoolSaleScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
vm.startBroadcast(deployerPrivateKey);

ILOPoolSale iloPoolSale = new ILOPoolSale{ salt: salt }();

vm.stopBroadcast();
}
}

contract TokenFactoryScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
vm.startBroadcast(deployerPrivateKey);

TokenFactory tokenFactory = new TokenFactory{
salt: salt
}();
TokenFactory tokenFactory = new TokenFactory{ salt: salt }();

vm.stopBroadcast();
}
}
}
37 changes: 23 additions & 14 deletions script/Init.s.sol
Original file line number Diff line number Diff line change
@@ -1,37 +1,46 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.7.6;

import "./Common.s.sol";
import "../src/interfaces/IILOManager.sol";
import "../src/interfaces/ITokenFactory.sol";
import './Common.s.sol';
import '../src/interfaces/IILOManager.sol';
import '../src/interfaces/ITokenFactory.sol';

contract ILOManagerInitializeScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
address deploymentAddress = getILOManagerDeploymentAddress();

address _feeTaker = vm.envAddress("FEE_TAKER");
address _initialOwner = vm.envAddress("OWNER");
uint256 initProjectFee = vm.envUint("INIT_PROJECT_FEE");
uint16 platformFee = uint16(vm.envUint("PLATFORM_FEE"));
uint16 performanceFee = uint16(vm.envUint("PERFORMANCE_FEE"));
address uniV3Factory = vm.envAddress("UNIV3_FACTORY");
address _feeTaker = vm.envAddress('FEE_TAKER');
address _initialOwner = vm.envAddress('OWNER');
uint256 initProjectFee = vm.envUint('INIT_PROJECT_FEE');
uint16 platformFee = uint16(vm.envUint('PLATFORM_FEE'));
uint16 performanceFee = uint16(vm.envUint('PERFORMANCE_FEE'));
address uniV3Factory = vm.envAddress('UNIV3_FACTORY');

vm.startBroadcast(deployerPrivateKey);
IILOManager iloManager = IILOManager(deploymentAddress);
iloManager.initialize(_initialOwner, _feeTaker, getILOPoolDeploymentAddress(), uniV3Factory, initProjectFee, platformFee, performanceFee);
iloManager.initialize(
_initialOwner,
_feeTaker,
getILOPoolDeploymentAddress(),
getILOPoolSaleDeploymentAddress(),
uniV3Factory,
initProjectFee,
platformFee,
performanceFee
);

vm.stopBroadcast();
}
}

contract TokenFactoryInitializeScript is CommonScript {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
uint256 deployerPrivateKey = vm.envUint('PRIVATE_KEY');
address deploymentAddress = getTokenFactoryDeploymentAddress();

address _initialOwner = vm.envAddress("OWNER");
address uniV3Factory = vm.envAddress("UNIV3_FACTORY");
address _initialOwner = vm.envAddress('OWNER');
address uniV3Factory = vm.envAddress('UNIV3_FACTORY');

vm.startBroadcast(deployerPrivateKey);
ITokenFactory tokenFactory = ITokenFactory(deploymentAddress);
Expand Down
Loading

0 comments on commit 2aca7e8

Please sign in to comment.