Skip to content

Commit

Permalink
Fixed bugs and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuanx committed Apr 19, 2024
1 parent deb73c3 commit 05181cc
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 197 deletions.
29 changes: 4 additions & 25 deletions contracts/interfaces/ITTUDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,25 @@ interface ITTUDeployer {
*/
function feeCollector() external returns (ITTUFeeCollector);

/**
* @notice Deploys and configures a new set of TokenTable products.
* @dev Emits `TokenTableSuiteDeployed`. Throws: `AlreadyDeployed`.
* @param projectToken The project token address.
* @param projectId A unique projectId, otherwise it will revert.
* @param isUpgradeable When set to false, a `Clone` instead of a `BeaconProxy` is created to prevent future upgradeability.
* @param isTransferable Allow FutureToken to be transferable.
* @param isCancelable Allow unlocking schedules to be cancelled in the Unlocker.
* @param isHookable Allow Unlocker to call an external hook.
* @param isWithdrawable Allow the founder to withdraw deposited funds.
*/
function deployTTSuite(
address projectToken,
string calldata projectId,
bool isUpgradeable,
bool isTransferable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
)
external
returns (ITokenTableUnlockerV2, ITTFutureTokenV2, ITTTrackerTokenV2);

/**
* @notice Deploys and configures a new set of TokenTable products that uses an existing NFT as FutureToken.
* @dev Emits `TokenTableSuiteDeployed`. Throws: `AlreadyDeployed`.
* @param projectToken The project token address.
* @param projectId A unique projectId, otherwise it will revert.
* @param isUpgradeable When set to false, a `Clone` instead of a `BeaconProxy` is created to prevent future upgradeability.
* @param isTransferable Allow FutureToken to be transferable. Ignored if an existing FutureToken is supplied.
* @param isCancelable Allow unlocking schedules to be cancelled in the Unlocker.
* @param isHookable Allow Unlocker to call an external hook.
* @param isWithdrawable Allow the founder to withdraw deposited funds.
*/
function deployTTSuite(
address projectToken,
address existingFutureToken,
string calldata projectId,
string memory projectId,
bool isUpgradeable,
bool isTransferable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
) external returns (ITokenTableUnlockerV2, ITTTrackerTokenV2);
) external returns (ITokenTableUnlockerV2, ITTFutureTokenV2);
}
183 changes: 58 additions & 125 deletions contracts/proxy/TTUDeployerLite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {

function deployTTSuite(
address projectToken,
string calldata projectId,
address existingFutureToken,
string memory projectId,
bool isUpgradeable,
bool isTransferable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
)
external
returns (ITokenTableUnlockerV2, ITTFutureTokenV2, ITTTrackerTokenV2)
{
) external returns (ITokenTableUnlockerV2, ITTFutureTokenV2) {
if (registry[projectId]) revert AlreadyDeployed();
registry[projectId] = true;

Expand All @@ -54,132 +52,70 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
if (!isUpgradeable) {
(unlocker, futureToken, trackerToken) = _deployClonesAndInitialize(
projectToken,
address(0),
isTransferable,
existingFutureToken,
false,
isCancelable,
isHookable,
isWithdrawable
);
} else {
futureToken = ITTFutureTokenV2(
address(
new BeaconProxy(
address(
beaconManager.beacons(
beaconManager.getId("TTFutureTokenV2")
if (existingFutureToken == address(0)) {
futureToken = ITTFutureTokenV2(
address(
new BeaconProxy(
address(beaconManager.beacons("TTFutureTokenV2")),
abi.encodeWithSelector(
ITTFutureTokenV2.initialize.selector,
projectToken,
isTransferable
)
),
abi.encodeWithSelector(
ITTFutureTokenV2.initialize.selector,
projectToken,
isTransferable
)
)
)
);
unlocker = ITokenTableUnlockerV2(
address(
new BeaconProxy(
address(
beaconManager.beacons(
beaconManager.getId("TokenTableUnlockerV2")
)
),
abi.encodeWithSelector(
ITokenTableUnlockerV2.initialize.selector,
projectToken,
futureToken,
this,
isCancelable,
isHookable,
isWithdrawable,
false
)
)
)
);
trackerToken = ITTTrackerTokenV2(
address(
new BeaconProxy(
address(
beaconManager.beacons(
beaconManager.getId("TTTrackerTokenV2")
);
unlocker = ITokenTableUnlockerV2(
address(
new BeaconProxy(
address(
beaconManager.beacons("TokenTableUnlockerV2")
),
abi.encodeWithSelector(
ITokenTableUnlockerV2.initialize.selector,
projectToken,
address(futureToken),
this,
isCancelable,
isHookable,
isWithdrawable,
true
)
),
abi.encodeWithSelector(
ITTTrackerTokenV2.initialize.selector,
address(unlocker)
)
)
)
);
}
unlocker.transferOwnership(msg.sender);
futureToken.setAuthorizedMinterSingleUse(address(unlocker));
emit TokenTableSuiteDeployed(
msg.sender,
projectId,
address(unlocker),
address(futureToken),
address(trackerToken)
);
return (unlocker, futureToken, trackerToken);
}

function deployTTSuite(
address projectToken,
address existingFutureToken,
string calldata projectId,
bool isUpgradeable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
) external returns (ITokenTableUnlockerV2, ITTTrackerTokenV2) {
if (registry[projectId]) revert AlreadyDeployed();
registry[projectId] = true;

ITTFutureTokenV2 placeholder;
ITokenTableUnlockerV2 unlocker;
ITTTrackerTokenV2 trackerToken;
if (!isUpgradeable) {
(unlocker, placeholder, trackerToken) = _deployClonesAndInitialize(
projectToken,
existingFutureToken,
false,
isCancelable,
isHookable,
isWithdrawable
);
} else {
unlocker = ITokenTableUnlockerV2(
address(
new BeaconProxy(
address(
beaconManager.beacons(
beaconManager.getId("TTUV2ExternalFT")
);
futureToken.setAuthorizedMinterSingleUse(address(unlocker));
} else {
unlocker = ITokenTableUnlockerV2(
address(
new BeaconProxy(
address(beaconManager.beacons("TTUV2ExternalFT")),
abi.encodeWithSelector(
ITokenTableUnlockerV2.initialize.selector,
projectToken,
existingFutureToken,
this,
isCancelable,
isHookable,
isWithdrawable,
true
)
),
abi.encodeWithSelector(
ITokenTableUnlockerV2.initialize.selector,
projectToken,
existingFutureToken,
this,
isCancelable,
isHookable,
isWithdrawable,
true
)
)
)
);
);
futureToken = ITTFutureTokenV2(existingFutureToken);
}
trackerToken = ITTTrackerTokenV2(
address(
new BeaconProxy(
address(
beaconManager.beacons(
beaconManager.getId("TTTrackerTokenV2")
)
),
address(beaconManager.beacons("TTTrackerTokenV2")),
abi.encodeWithSelector(
ITTTrackerTokenV2.initialize.selector,
address(unlocker)
Expand All @@ -193,10 +129,10 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
msg.sender,
projectId,
address(unlocker),
address(existingFutureToken),
address(futureToken),
address(trackerToken)
);
return (unlocker, trackerToken);
return (unlocker, futureToken);
}

function version() public pure virtual returns (string memory) {
Expand All @@ -222,9 +158,7 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
if (existingFutureToken == address(0)) {
futureToken = ITTFutureTokenV2(
Clones.clone(
beaconManager
.beacons(beaconManager.getId("TTFutureTokenV2"))
.implementation()
beaconManager.beacons("TTFutureTokenV2").implementation()
)
);
futureToken.initialize(projectToken, isTransferable);
Expand All @@ -233,9 +167,7 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
}
unlocker = ITokenTableUnlockerV2(
Clones.clone(
beaconManager
.beacons(beaconManager.getId("TokenTableUnlockerV2"))
.implementation()
beaconManager.beacons("TokenTableUnlockerV2").implementation()
)
);
unlocker.initialize(
Expand All @@ -248,11 +180,12 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
);
trackerToken = ITTTrackerTokenV2(
Clones.clone(
beaconManager
.beacons(beaconManager.getId("TTTrackerTokenV2"))
.implementation()
beaconManager.beacons("TTTrackerTokenV2").implementation()
)
);
trackerToken.initialize(address(unlocker));
if (existingFutureToken == address(0)) {
futureToken.setAuthorizedMinterSingleUse(address(unlocker));
}
}
}
12 changes: 4 additions & 8 deletions contracts/proxy/TTUV2BeaconManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import {IVersionable} from "../interfaces/IVersionable.sol";
* This contract should be deployed using TTUDeployer.
*/
contract TTUV2BeaconManager is Ownable, IVersionable {
mapping(bytes32 => UpgradeableBeacon) public beacons;
// Reserved names: TokenTableUnlockerV2, TTFutureTokenV2, TTTrackerTokenV2
mapping(string => UpgradeableBeacon) public beacons;

constructor() Ownable(_msgSender()) {}

function upgradeCustomBeacon(
bytes32 id,
string calldata id,
address newImpl
) external onlyOwner {
UpgradeableBeacon beacon = beacons[id];
if (address(beacon) == address(0)) {
beacon = new UpgradeableBeacon(newImpl, address(this));
beacons[id] = new UpgradeableBeacon(newImpl, address(this));
} else {
beacon.upgradeTo(newImpl);
}
Expand All @@ -35,9 +36,4 @@ contract TTUV2BeaconManager is Ownable, IVersionable {
function version() external pure returns (string memory) {
return "2.6.0";
}

// Reserved names: TokenTableUnlockerV2, TTFutureTokenV2, TTTrackerTokenV2
function getId(string memory name) external pure returns (bytes32) {
return keccak256(abi.encode(name));
}
}
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,6 @@ export default {
exclude: ['libraries', 'mock']
},
gasReporter: {
enabled: true
enabled: false
}
}
Loading

0 comments on commit 05181cc

Please sign in to comment.