Skip to content

Commit

Permalink
Special deployer w/o using Clone for zkSync Era
Browse files Browse the repository at this point in the history
  • Loading branch information
boyuanx committed Feb 28, 2024
1 parent cb53e35 commit be05bb8
Show file tree
Hide file tree
Showing 15 changed files with 293 additions and 405 deletions.
6 changes: 5 additions & 1 deletion contracts/core/TTFutureTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ contract TTFutureTokenV2 is ITTFutureTokenV2, ERC721AQueryableUpgradeable {

// solhint-disable-next-line ordering
constructor() {
if (block.chainid != 33133) {
if (
block.chainid != 33133 &&
block.chainid != 300 &&
block.chainid != 324
) {
_dummyInitialize();
}
}
Expand Down
6 changes: 5 additions & 1 deletion contracts/core/TTTrackerTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ contract TTTrackerTokenV2 is ITTTrackerTokenV2, IERC20Metadata, Initializable {
TokenTableUnlockerV2 public ttuInstance;

constructor() {
if (block.chainid != 33133) {
if (
block.chainid != 33133 &&
block.chainid != 300 &&
block.chainid != 324
) {
_disableInitializers();
}
}
Expand Down
6 changes: 5 additions & 1 deletion contracts/core/TokenTableUnlockerV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ contract TokenTableUnlockerV2 is

// solhint-disable-next-line ordering
constructor() {
if (block.chainid != 33133) {
if (
block.chainid != 33133 &&
block.chainid != 300 &&
block.chainid != 324
) {
_disableInitializers();
}
}
Expand Down
58 changes: 40 additions & 18 deletions contracts/proxy/TTUDeployerLite.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,13 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
ITokenTableUnlockerV2 unlocker;
ITTTrackerTokenV2 trackerToken;
if (!isUpgradeable) {
futureToken = ITTFutureTokenV2(
Clones.clone(beaconManager.futureTokenBeacon().implementation())
);
futureToken.initialize(projectToken, isTransferable);
unlocker = ITokenTableUnlockerV2(
Clones.clone(beaconManager.unlockerBeacon().implementation())
);
unlocker.initialize(
(unlocker, futureToken, trackerToken) = _deployClonesAndInitialize(
projectToken,
address(futureToken),
address(this),
isTransferable,
isCancelable,
isHookable,
isWithdrawable
);
trackerToken = ITTTrackerTokenV2(
Clones.clone(
beaconManager.trackerTokenBeacon().implementation()
)
);
trackerToken.initialize(address(unlocker));
} else {
futureToken = ITTFutureTokenV2(
address(
Expand Down Expand Up @@ -126,7 +112,43 @@ contract TTUDeployerLite is ITTUDeployer, Ownable, IVersionable {
return (unlocker, futureToken, trackerToken);
}

function version() external pure returns (string memory) {
return "2.5.0";
function version() external pure virtual returns (string memory) {
return "2.5.7";
}

function _deployClonesAndInitialize(
address projectToken,
bool isTransferable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
)
internal
virtual
returns (
ITokenTableUnlockerV2 unlocker,
ITTFutureTokenV2 futureToken,
ITTTrackerTokenV2 trackerToken
)
{
futureToken = ITTFutureTokenV2(
Clones.clone(beaconManager.futureTokenBeacon().implementation())
);
futureToken.initialize(projectToken, isTransferable);
unlocker = ITokenTableUnlockerV2(
Clones.clone(beaconManager.unlockerBeacon().implementation())
);
unlocker.initialize(
projectToken,
address(futureToken),
address(this),
isCancelable,
isHookable,
isWithdrawable
);
trackerToken = ITTTrackerTokenV2(
Clones.clone(beaconManager.trackerTokenBeacon().implementation())
);
trackerToken.initialize(address(unlocker));
}
}
47 changes: 47 additions & 0 deletions contracts/proxy/TTUDeployerLiteZkSync.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: AGPL v3
pragma solidity ^0.8.20;

import {TTUDeployerLite} from "./TTUDeployerLite.sol";
import {ITokenTableUnlockerV2} from "../interfaces/ITokenTableUnlockerV2.sol";
import {ITTFutureTokenV2} from "../interfaces/ITTFutureTokenV2.sol";
import {ITTTrackerTokenV2} from "../interfaces/ITTTrackerTokenV2.sol";
import {TokenTableUnlockerV2} from "../core/TokenTableUnlockerV2.sol";
import {TTFutureTokenV2} from "../core/TTFutureTokenV2.sol";
import {TTTrackerTokenV2} from "../core/TTTrackerTokenV2.sol";

contract TTUDeployerLiteZkSync is TTUDeployerLite {
function version() external pure virtual override returns (string memory) {
return "2.5.7-zkSync";
}

function _deployClonesAndInitialize(
address projectToken,
bool isTransferable,
bool isCancelable,
bool isHookable,
bool isWithdrawable
)
internal
virtual
override
returns (
ITokenTableUnlockerV2 unlocker,
ITTFutureTokenV2 futureToken,
ITTTrackerTokenV2 trackerToken
)
{
futureToken = new TTFutureTokenV2();
futureToken.initialize(projectToken, isTransferable);
unlocker = new TokenTableUnlockerV2();
unlocker.initialize(
projectToken,
address(futureToken),
address(this),
isCancelable,
isHookable,
isWithdrawable
);
trackerToken = new TTTrackerTokenV2();
trackerToken.initialize(address(unlocker));
}
}
28 changes: 22 additions & 6 deletions deploy/10-deploy-ttudeployer-lite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,28 @@ const deployLite: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
args: [],
waitConfirmations: 1
})
const deployerLiteDeploymentResult = await deploy('TTUDeployerLite', {
from: deployer,
log: true,
args: [],
waitConfirmations: 1
})

let deployerLiteDeploymentResult
if (
hre.network.config.chainId === 300 ||
hre.network.config.chainId === 324
) {
log.info('Deploying zkSync...')
deployerLiteDeploymentResult = await deploy('TTUDeployerLiteZkSync', {
from: deployer,
log: true,
args: [],
waitConfirmations: 1
})
} else {
deployerLiteDeploymentResult = await deploy('TTUDeployerLite', {
from: deployer,
log: true,
args: [],
waitConfirmations: 1
})
}

const beaconManagerDeploymentResult = await deploy('TTUV2BeaconManager', {
from: deployer,
log: true,
Expand Down
18 changes: 0 additions & 18 deletions deploy/98-deploy-clones-lib.ts

This file was deleted.

28 changes: 13 additions & 15 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default {
zksync: false
},
zkSyncTestnet: {
chainId: 280,
chainId: 300,
url: 'https://sepolia.era.zksync.dev/',
ethNetwork: 'https://rpc.ankr.com/eth_sepolia',
accounts: [process.env.PRIVATE_KEY],
Expand Down Expand Up @@ -171,36 +171,34 @@ export default {
optimizer: {
enabled: true,
runs: 200
},
metadata: {
bytecodeHash: 'none'
}
},
eraVersion: '1.0.0'
}
}
]
},
zksolc: {
version: '1.3.23',
version: '1.4.0',
settings: {
optimizer: {
enabled: true,
runs: 200
runs: 10
},
isSystem: true
// libraries: {
// 'contracts/libraries/Clones.sol': {
// /*
// * zkSync Era Mainnet: 0x52cb8d348604aBB1720a713eADf3e4Afef650f93
// * zkSync Era Testnet: 0x222C78A7CaDC3D63c72cE39F9A382B6aF075fC74
// */
// Clones: '0x52cb8d348604aBB1720a713eADf3e4Afef650f93'
// }
// }
metadata: {
bytecodeHash: 'none'
}
}
},
namedAccounts: {
deployer: {
default: 0
}
},
sourcify: {
enabled: false
},
etherscan: {
apiKey: {
polygonMumbai: process.env.POLYGONSCAN_KEY,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
"sizes": "hardhat size-contracts"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "1.1.2",
"@matterlabs/hardhat-zksync-solc": "1.1.2",
"@matterlabs/hardhat-zksync-verify": "1.3.0",
"@matterlabs/hardhat-zksync-deploy": "1.2.0",
"@matterlabs/hardhat-zksync-solc": "1.1.4",
"@matterlabs/hardhat-zksync-verify": "1.4.0",
"@nomicfoundation/hardhat-toolbox": "4.0.0",
"@openzeppelin/hardhat-upgrades": "3.0.3",
"@types/bunyan": "^1.8.7",
Expand Down
Loading

0 comments on commit be05bb8

Please sign in to comment.