Commit 9631226d authored by vicotor's avatar vicotor

update script

parent af66694a
// SPDX-License-Identifier: UNLICENSED // SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/** /**
* @title IERC20Burnable * @title IERC20Burnable
* @dev 扩展ERC20接口,添加销毁功能 * @dev Extends ERC20 interface with burn functionality
*/ */
interface IERC20Burnable is IERC20 { interface IERC20Burnable is IERC20 {
function burn(uint256 amount) external; function burn(uint256 amount) external;
...@@ -14,10 +16,9 @@ interface IERC20Burnable is IERC20 { ...@@ -14,10 +16,9 @@ interface IERC20Burnable is IERC20 {
/** /**
* @title Bridge * @title Bridge
* @dev 跨链桥合约,支持代币在不同区块链之间转移 * @dev Cross-chain bridge contract supporting token transfers between blockchains
* @notice 使用多签验证者机制确保跨链转移的安全性
*/ */
contract Bridge is Ownable { contract Bridge is Initializable, OwnableUpgradeable, UUPSUpgradeable {
/// @dev 执行转入操作所需的最少验证者确认数量 /// @dev 执行转入操作所需的最少验证者确认数量
uint256 public validRequired; uint256 public validRequired;
...@@ -257,13 +258,17 @@ contract Bridge is Ownable { ...@@ -257,13 +258,17 @@ contract Bridge is Ownable {
// ============ 构造函数 ============ // ============ 构造函数 ============
/** function _authorizeUpgrade(address newImplementation) internal override onlyOwner {
* @notice 初始化合约,设置初始所需确认数为1 // Add any additional checks if needed
* @param initialOwner 合约的初始所有者 }
*/ /// @dev Initializes the contract (replaces constructor)
constructor(address initialOwner) Ownable(initialOwner) { /// @param initialOwner The initial owner of the contract
function initialize(address initialOwner) public initializer {
__Ownable_init();
__UUPSUpgradeable_init();
validRequired = 1; validRequired = 1;
treasury = address(0); // 初始化金库地址为0,需要后续设置 treasury = address(0); // Initialize treasury address to 0
transferOwnership(initialOwner);
} }
// ============ 验证者管理函数 ============ // ============ 验证者管理函数 ============
......
require("@nomicfoundation/hardhat-toolbox"); require("@nomicfoundation/hardhat-toolbox");
require("@nomicfoundation/hardhat-ethers"); require("@nomicfoundation/hardhat-ethers");
require("@openzeppelin/hardhat-upgrades");
require("dotenv").config() require("dotenv").config()
......
This diff is collapsed.
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
}, },
"dependencies": { "dependencies": {
"@openzeppelin/contracts": "^5.3.0", "@openzeppelin/contracts": "^5.3.0",
"@openzeppelin/contracts-upgradeable": "^4.5.0",
"@openzeppelin/hardhat-upgrades": "^3.9.1",
"dotenv": "^16.5.0", "dotenv": "^16.5.0",
"fp-ts": "^2.16.11" "fp-ts": "^2.16.11"
} }
......
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const hre = require("hardhat"); const { ethers, upgrades } = require("hardhat");
const DEPLOY_FILE = path.join(__dirname, "deploy.json"); const DEPLOY_FILE = path.join(__dirname, "deploy.json");
async function deploy() { async function deploy() {
const token = await hre.ethers.getContractFactory( const token = await ethers.getContractFactory(
"TestToken" "TestToken"
); );
const tokenA = await token.deploy("Test Token Ali", "TTA"); const tokenA = await token.deploy("Test Token Ali", "TTA");
...@@ -17,16 +17,18 @@ async function deploy() { ...@@ -17,16 +17,18 @@ async function deploy() {
const tokenBAddr = await tokenB.getAddress(); const tokenBAddr = await tokenB.getAddress();
// Deploy the contract // Deploy the contract
const factory = await hre.ethers.getContractFactory( const factory = await ethers.getContractFactory(
"Bridge" "Bridge"
); );
[owner] = await hre.ethers.getSigners(); [owner] = await ethers.getSigners();
const contract = await factory.deploy(owner.address); const contract = await upgrades.deployProxy(factory, [owner.address], {
initializer: "initialize",
});
await contract.waitForDeployment(); await contract.waitForDeployment();
const bridgeAddr = await contract.getAddress(); const bridgeAddr = await contract.getAddress();
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); const chainId = await ethers.provider.getNetwork().then(network => network.chainId);
await saveDeployment(chainId, tokenAAddr, tokenBAddr, bridgeAddr); await saveDeployment(chainId, tokenAAddr, tokenBAddr, bridgeAddr);
console.log("initial_height = ", contract.deploymentTransaction().blockNumber) console.log("initial_height = ", contract.deploymentTransaction().blockNumber)
console.log("bridge_contract = ", bridgeAddr) console.log("bridge_contract = ", bridgeAddr)
......
...@@ -3,7 +3,10 @@ const path = require("path"); ...@@ -3,7 +3,10 @@ const path = require("path");
const hre = require("hardhat"); const hre = require("hardhat");
var users = [ var users = [
"0xCb7559B648eE663A2B0C569837F510D5f0ABAaD1" // "0xCb7559B648eE663A2B0C569837F510D5f0ABAaD1",
// "0x05DA4f0d5348Abb139b7cD8D8896A774CaB12BA6",
// "0x2D4E6b96bD85248d13020D392e99558abFb4f74C",
"0x119BA92c15337FfB37871e44F3f9102409D95F12"
] ]
const DEPLOY_FILE = path.join(__dirname, "deploy.json"); const DEPLOY_FILE = path.join(__dirname, "deploy.json");
...@@ -41,8 +44,6 @@ async function getDeploy(chainId) { ...@@ -41,8 +44,6 @@ async function getDeploy(chainId) {
// Define the script // Define the script
async function main() { async function main() {
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
const targetChainId = chainId === 6174n ? 8891 : 6174;
console.log("Current chain ID:", chainId, "Target chain ID:", targetChainId);
const curChainDeploy = await getDeploy(chainId); const curChainDeploy = await getDeploy(chainId);
for (var i = 0; i < users.length; i++) { for (var i = 0; i < users.length; i++) {
......
...@@ -144,8 +144,8 @@ async function setOutConfig(curTokenMap, targetTokenMap, targetChainId, bridge) ...@@ -144,8 +144,8 @@ async function setOutConfig(curTokenMap, targetTokenMap, targetChainId, bridge)
// Define the script // Define the script
async function main() { async function main() {
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
// const targetChainId = chainId === 97n ? 10323 : 97; const targetChainId = chainId === 97n ? 10323 : 97;
const targetChainId = chainId === 6174n ? 8891 : 6174; // const targetChainId = chainId === 6174n ? 8891 : 6174;
console.log("Current chain ID:", chainId, "Target chain ID:", targetChainId); console.log("Current chain ID:", chainId, "Target chain ID:", targetChainId);
const curChainDeploy = await getDeploy(chainId); const curChainDeploy = await getDeploy(chainId);
......
...@@ -131,8 +131,8 @@ async function outTransfer(bridge, token , amount, targetChainId, receiver) { ...@@ -131,8 +131,8 @@ async function outTransfer(bridge, token , amount, targetChainId, receiver) {
// Define the script // Define the script
async function main() { async function main() {
const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId); const chainId = await hre.ethers.provider.getNetwork().then(network => network.chainId);
const targetChainId = chainId === 6174n ? 8891 : 6174; // const targetChainId = chainId === 6174n ? 8891 : 6174;
// const targetChainId = chainId === 97n ? 10323 : 97; const targetChainId = chainId === 97n ? 10323 : 97;
console.log("Current chain ID:", chainId, "Target chain ID:", targetChainId); console.log("Current chain ID:", chainId, "Target chain ID:", targetChainId);
const chainDeploy = await getDeploy(chainId); const chainDeploy = await getDeploy(chainId);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment