Skip to content

Commit

Permalink
move vesting lockup creation to VestingCloneFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
malteish committed Jan 4, 2024
1 parent 7867d23 commit 510091b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 25 deletions.
38 changes: 14 additions & 24 deletions contracts/factories/PrivateOfferFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,24 @@ contract PrivateOfferFactory {

// deploy the vesting contract
Vesting vesting = Vesting(
vestingCloneFactory.createVestingClone(salt, trustedForwarder, address(this), address(_arguments.token))
vestingCloneFactory.createVestingCloneWithLockupPlan(
salt,
trustedForwarder,
_vestingContractOwner,
address(_arguments.token),
_arguments.tokenAmount,
_arguments.tokenReceiver,
_vestingStart,
_vestingCliff,
_vestingDuration
)
);

// create the vesting plan
vesting.createVesting(
_arguments.tokenAmount,
_arguments.tokenReceiver,
_vestingStart,
_vestingCliff,
_vestingDuration,
false
); // this plan is not mintable

vesting.removeManager(address(this));

// transfer ownership of the vesting contract
if (_vestingContractOwner == address(0)) {
// if the owner is 0, the vesting contract will not have an owner. So no one can interfere with the vesting.
vesting.renounceOwnership();
} else {
vesting.transferOwnership(_vestingContractOwner);
}

// deploy the private offer
// update currency receiver to be the vesting contract
PrivateOfferArguments memory calldataArguments = _arguments;
calldataArguments.tokenReceiver = address(vesting);
// update currency receiver to be the vesting contract

// deploy the private offer
address privateOffer = _deployPrivateOffer(_rawSalt, calldataArguments);

require(_arguments.token.balanceOf(address(vesting)) == _arguments.tokenAmount, "Execution failed");
Expand Down Expand Up @@ -131,7 +121,7 @@ contract PrivateOfferFactory {
address vestingAddress = vestingCloneFactory.predictCloneAddress(
salt,
trustedForwarder,
address(this),
address(vestingCloneFactory),
address(_arguments.token)
);

Expand Down
33 changes: 32 additions & 1 deletion contracts/factories/VestingCloneFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract VestingCloneFactory is CloneFactory {
address _trustedForwarder,
address _owner,
address _token
) external returns (address) {
) public returns (address) {
bytes32 salt = keccak256(abi.encode(_rawSalt, _trustedForwarder, _owner, _token));
address clone = Clones.cloneDeterministic(implementation, salt);
Vesting vesting = Vesting(clone);
Expand All @@ -36,6 +36,37 @@ contract VestingCloneFactory is CloneFactory {
return clone;
}

function createVestingCloneWithLockupPlan(
bytes32 _rawSalt,
address _trustedForwarder,
address _owner,
address _token,
uint256 _allocation,
address _beneficiary,
uint64 _start,
uint64 _cliff,
uint64 _duration
) external returns (address) {
// deploy the vesting contract
Vesting vesting = Vesting(createVestingClone(_rawSalt, _trustedForwarder, address(this), _token));

// create the vesting plan
vesting.createVesting(_allocation, _beneficiary, _start, _cliff, _duration, false); // this plan is not mintable

// remove the manager role from the vesting contract
vesting.removeManager(address(this));

// transfer ownership of the vesting contract
if (_owner == address(0)) {
// if the owner is 0, the vesting contract will not have an owner. So no one can interfere with the vesting.
vesting.renounceOwnership();
} else {
vesting.transferOwnership(_owner);
}

return address(vesting);
}

/**
* Calculate the address a clone will have using the given parameters
* @param _rawSalt value that influences the address of the clone, but not the initialization
Expand Down

0 comments on commit 510091b

Please sign in to comment.