Skip to content

Commit

Permalink
add zklink token
Browse files Browse the repository at this point in the history
  • Loading branch information
zkbenny committed Apr 12, 2024
1 parent 5313096 commit b5395c5
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
37 changes: 37 additions & 0 deletions contracts/dev-contracts/ZkLinkToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

pragma solidity ^0.8.0;

import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import {ERC20PermitUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import {ERC20CappedUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20CappedUpgradeable.sol";

contract ZkLinkToken is
OwnableUpgradeable,
UUPSUpgradeable,
ERC20Upgradeable,
ERC20PermitUpgradeable,
ERC20CappedUpgradeable
{
function initialize() external initializer {
__Ownable_init();
__UUPSUpgradeable_init();
__ERC20_init("ZKLink", "ZKL");
__ERC20Permit_init("ZKLink");
__ERC20Capped_init(1000000000000000000000000000);
}

function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
// can only called by owner
}

function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}

function _mint(address account, uint256 amount) internal override(ERC20CappedUpgradeable, ERC20Upgradeable) {
ERC20CappedUpgradeable._mint(account, amount);
}
}
1 change: 1 addition & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require('./script/deploy_eth_gateway');
require('./script/deploy_erc20_bridge');
require('./script/deploy_governance');
require('./script/deploy_linea_l2_governance');
require('./script/deploy_zklink_token');

const BaseConfig = require('./hardhat.base.config');

Expand Down
12 changes: 12 additions & 0 deletions script/deploy_log_name.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ const DEPLOY_LOG_GOVERNANCE_VERIFIED = 'governanceVerified';
// consumed in deploy_linea_l2_governance.js
const DEPLOY_LINEA_L2_GOVERNANCE_LOG_PREFIX = 'deploy_linea_l2_governance';

// consumed in deploy_zklink_token.js
const DEPLOY_ZKLINK_TOKEN_LOG_PREFIX = 'deploy_zklink_token';
const DEPLOY_LOG_ZKLINK_TOKEN_PROXY = 'zkLinkTokenProxy';
const DEPLOY_LOG_ZKLINK_TOKEN_TARGET = 'zkLinkTokenTarget';
const DEPLOY_LOG_ZKLINK_TOKEN_PROXY_VERIFIED = 'zkLinkTokenProxyVerified';
const DEPLOY_LOG_ZKLINK_TOKEN_TARGET_VERIFIED = 'zkLinkTokenTargetVerified';

module.exports = {
DEPLOY_ZKLINK_LOG_PREFIX,
DEPLOY_LOG_DEPLOYER,
Expand Down Expand Up @@ -73,4 +80,9 @@ module.exports = {
DEPLOY_LOG_GOVERNANCE,
DEPLOY_LOG_GOVERNANCE_VERIFIED,
DEPLOY_LINEA_L2_GOVERNANCE_LOG_PREFIX,
DEPLOY_ZKLINK_TOKEN_LOG_PREFIX,
DEPLOY_LOG_ZKLINK_TOKEN_PROXY,
DEPLOY_LOG_ZKLINK_TOKEN_TARGET,
DEPLOY_LOG_ZKLINK_TOKEN_PROXY_VERIFIED,
DEPLOY_LOG_ZKLINK_TOKEN_TARGET_VERIFIED,
};
61 changes: 61 additions & 0 deletions script/deploy_zklink_token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const fs = require('fs');
const { getImplementationAddress } = require('@openzeppelin/upgrades-core');
const { verifyContractCode, createOrGetDeployLog, ChainContractDeployer, getDeployTx } = require('./utils');
const logName = require('./deploy_log_name');
const { task, types } = require('hardhat/config');

task('deployZkLinkToken', 'Deploy zkLink token')
.addOptionalParam('skipVerify', 'Skip verify', false, types.boolean)
.setAction(async (taskArgs, hardhat) => {
let skipVerify = taskArgs.skipVerify;
console.log('skip verify contracts?', skipVerify);

const contractDeployer = new ChainContractDeployer(hardhat);
await contractDeployer.init();
const deployerWallet = contractDeployer.deployerWallet;

const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_ZKLINK_TOKEN_LOG_PREFIX);
deployLog[logName.DEPLOY_LOG_GOVERNOR] = deployerWallet.address;
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2));

// deploy zkLink token
let zkLinkTokenAddr;
if (!(logName.DEPLOY_LOG_ZKLINK_TOKEN_PROXY in deployLog)) {
console.log('deploy zkLink token...');
const contract = await contractDeployer.deployProxy('ZkLinkToken', [], []);
const transaction = await getDeployTx(contract);
zkLinkTokenAddr = await contract.getAddress();
deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_PROXY] = zkLinkTokenAddr;
deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash;
deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber;
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2));
} else {
zkLinkTokenAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_PROXY];
}
console.log('zkLinkToken', zkLinkTokenAddr);

let zkLinkTokenTargetAddr;
if (!(logName.DEPLOY_LOG_ZKLINK_TOKEN_TARGET in deployLog)) {
console.log('get zkLink token target...');
zkLinkTokenTargetAddr = await getImplementationAddress(hardhat.ethers.provider, zkLinkTokenAddr);
deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_TARGET] = zkLinkTokenTargetAddr;
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2));
} else {
zkLinkTokenTargetAddr = deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_TARGET];
}
console.log('zkLink token target', zkLinkTokenTargetAddr);

// verify target contract
if (!(logName.DEPLOY_LOG_ZKLINK_TOKEN_TARGET_VERIFIED in deployLog) && !skipVerify) {
await verifyContractCode(hardhat, zkLinkTokenTargetAddr, []);
deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_TARGET_VERIFIED] = true;
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2));
}

// verify proxy contract
if (!(logName.DEPLOY_LOG_ZKLINK_TOKEN_PROXY_VERIFIED in deployLog) && !skipVerify) {
await verifyContractCode(hardhat, zkLinkTokenAddr, []);
deployLog[logName.DEPLOY_LOG_ZKLINK_TOKEN_PROXY_VERIFIED] = true;
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2));
}
});

0 comments on commit b5395c5

Please sign in to comment.