Skip to content

Commit

Permalink
deploy taiko testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed May 10, 2024
1 parent 036054c commit b6809e8
Show file tree
Hide file tree
Showing 12 changed files with 352 additions and 30 deletions.
1 change: 1 addition & 0 deletions helix-contract/script/bytecode/GuardV3.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions helix-contract/script/configure/dev.chain.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,33 @@
"address": "0x89AF830781A2C1d3580Db930bea11094F55AfEae"
}
]
},
{
"name": "taiko-hekla",
"url": "https://rpc.hekla.taiko.xyz",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 167009,
"lzChainId": 10274,
"deployer": "0x9bc1C7567DDBcaF2212185b6665D755d842d01E4",
"proxyAdmin": "0x7684389eAa307e25Af38A31873E31Cc3B513EE01",
"lzEndpoint": "0x83c73Da98cf733B03315aFa8758834b36a195b87",
"messager": [
{
"name": "LayerZeroMessager",
"address": "0x61B6B8c7C00aA7F060a2BEDeE6b11927CC9c3eF1",
"version": "v2.0"
}
],
"tokens": [
{
"symbol": "usdt",
"address": "0x463D1730a8527CA58d48EF70C7460B9920346567"
},
{
"symbol": "usdc",
"address": "0x89AF830781A2C1d3580Db930bea11094F55AfEae"
}
]
}
]

8 changes: 8 additions & 0 deletions helix-contract/script/configure/dev.lnv3.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"name": "morph",
"address": "0xbBad04cBF890e66B7c9a5e7FD6A7ff110E7d35A9"
},
{
"name": "taiko-hekla",
"address": "0xbBad04cBF890e66B7c9a5e7FD6A7ff110E7d35A9"
},
{
"name": "others",
"address": "0xdf383487CB33a3C78a884494e2456910d79d361c"
Expand Down Expand Up @@ -54,6 +58,10 @@
"name": "morph",
"address": "0xD476650e03a45E70202b0bcAfa04E1513920f83a"
},
{
"name": "taiko-hekla",
"address": "0xD476650e03a45E70202b0bcAfa04E1513920f83a"
},
{
"name": "others",
"address": "0x38627Cb033De66a1E07e73f5D0a7a7adFB6741fa"
Expand Down
45 changes: 45 additions & 0 deletions helix-contract/script/deploy_create2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const fs = require("fs");
var Configure = require("./configure/readconfig.js");
var Create2 = require("./api/create2.js");

const privateKey = process.env.PRIKEY

function wallet(url) {
const provider = new ethers.providers.JsonRpcProvider(url);
const wallet = new ethers.Wallet(privateKey, provider);
return wallet;
}

async function deployCreate2Deployer(networkUrl, version) {
const w = wallet(networkUrl);
const salt = ethers.utils.hexZeroPad(ethers.utils.hexlify(ethers.utils.toUtf8Bytes(version)), 32);
const create2Contract = await ethers.getContractFactory("Create2Deployer", w);
const bytecode = Create2.getDeployedBytecode(create2Contract, [], []);
const unsignedTransaction = {
from: w.address,
to: "0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7",
data: `${salt}${bytecode.slice(2)}`,
gasLimit: 2000000,
//gasPrice: 2100000000,
//nonce: 0,
};
const tx = await w.sendTransaction(unsignedTransaction);
console.log(`deploy create2 tx: ${tx.hash}, salt: ${salt}`);
return;
}

// 2. deploy mapping token factory
async function main() {
const chainInfo = Configure.chain('product');
const network = chainInfo['astar'];

await deployCreate2Deployer(network.url, 'v1.0.0');
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

40 changes: 40 additions & 0 deletions helix-contract/script/deploy_guard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var Create2 = require("./api/create2.js");
var Configure = require("./configure/readconfig.js");
var GuardV3Bytecode = require("./bytecode/GuardV3.js");

const privateKey = process.env.PRIKEY

function wallet(network) {
const provider = new ethers.providers.JsonRpcProvider(network.url);
const wallet = new ethers.Wallet(privateKey, provider);
return wallet;
}

async function deployGuardV3(wallet, deployerAddress, salt) {
const guardContract = await ethers.getContractFactory("GuardV3", wallet);
//const bytecode = Create2.getDeployedBytecode(
//guardContract,
//['address[]','address','uint256','uint256'],
//[['0x3B9E571AdeCB0c277486036D6097E9C2CCcfa9d9'],wallet.address,1,259200]);
const bytecode = GuardV3Bytecode;
const address = await Create2.deploy(deployerAddress, wallet, bytecode, salt, 8000000);
console.log("finish to deploy guard contract, address: ", address);
return address;
}

// 2. deploy mapping token factory
async function main() {
const chainInfo = Configure.chain('product');
const network = chainInfo['crab-dvm'];
const w = wallet(network);

await deployGuardV3(w, network.deployer, "guardv3-v1.0.0");
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

7 changes: 4 additions & 3 deletions helix-contract/script/deploy_layerzero.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function wallet(url) {
return wallet;
}

async function deployMessager(wallet, network, salt) {
async function deployMessager(wallet, network) {
const { dao, lzEndpoint } = network;
const messagerContract = await ethers.getContractFactory("LayerZeroMessager", wallet);
const messager = await messagerContract.deploy(dao, lzEndpoint);
Expand All @@ -18,11 +18,12 @@ async function deployMessager(wallet, network, salt) {
return messager.address;
}

// nonce = 4 on testnet
async function main() {
const chainInfo = Configure.chain('dev');
const network = chainInfo['morph'];
const network = chainInfo['taiko-hekla'];
const w = wallet(network.url);
await deployMessager(w, network, "msgport-messager-v1.0.0");
await deployMessager(w, network);
}

main()
Expand Down
2 changes: 1 addition & 1 deletion helix-contract/script/deploy_proxy_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function deployMessager(wallet, network, salt) {

async function main() {
const chainInfo = Configure.chain('dev');
const network = chainInfo['morph'];
const network = chainInfo['taiko-hekla'];
const w = wallet(network.url);
await deployMessager(w, network, "v1.0.0");
}
Expand Down
2 changes: 1 addition & 1 deletion helix-contract/script/deploy_test_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function wallet(url) {
// 2. deploy mapping token factory
async function main() {
const chainInfo = Configure.chain('dev');
const network = chainInfo['morph'];
const network = chainInfo['taiko-hekla'];

const w = wallet(network.url);
const tokenInfo = tokens[1];
Expand Down
73 changes: 53 additions & 20 deletions helix-contract/script/lnv3_configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ async function connectUsingLayerzero(network01, network02) {
} else {
console.log(`no need to authorize app caller ${network01.name}`);
}
} else {
const messagerContract = await ethers.getContractAt('LayerZeroMessager', messager01.address, network01.wallet);
const isWhiteList = await messagerContract.whiteList(network01.proxy);
if (!isWhiteList) {
console.log(`start to authorize app caller ${network01.name}`);
await messagerContract.setWhiteList(network01.proxy, true);
} else {
console.log(`no need to authorize app caller ${network01.name}`);
}
}
if (messager02.version == 'v1.0') {
const messagerContract = await ethers.getContractAt('LnAccessController', messager02.address, network02.wallet);
Expand All @@ -37,35 +46,54 @@ async function connectUsingLayerzero(network01, network02) {
} else {
console.log(`no need to authorize app caller ${network02.name}`);
}
} else {
const messagerContract = await ethers.getContractAt('LayerZeroMessager', messager02.address, network02.wallet);
const isWhiteList = await messagerContract.whiteList(network02.proxy);
if (!isWhiteList) {
console.log(`start to authorize app caller ${network02.name}`);
await messagerContract.setWhiteList(network02.proxy, true);
} else {
console.log(`no need to authorize app caller ${network02.name}`);
}
}
const messagerContract01 = await ethers.getContractAt('LayerZeroMessager', messager01.address, network01.wallet);
const remoteMessager01 = await messagerContract01.remoteMessagers(network02.chainId);
if (remoteMessager01.lzRemoteChainId !== network02.lzChainId || remoteMessager01.messager !== messager02.address) {
await messagerContract01.setRemoteMessager(network02.chainId, network02.lzChainId, messager02.address);
}
const messagerContract02 = await ethers.getContractAt('LayerZeroMessager', messager02.address, network02.wallet);
const remoteMessager02 = await messagerContract02.remoteMessagers(network01.chainId);
if (remoteMessager02.lzRemoteChainId !== network01.lzChainId || remoteMessager02.messager !== messager01.address) {
await messagerContract02.setRemoteMessager(network01.chainId, network01.lzChainId, messager01.address);
}

console.log(bridge01Contract.address, network02.chainId);
const sendService01 = (await bridge01Contract.messagers(network02.chainId)).sendService;
if (sendService01 === zeroAddress) {
console.log(`${network01.name} set send service`);
await bridge01Contract.setSendService(network02.chainId, network02.proxy, messager02.address);
await bridge01Contract.setSendService(network02.chainId, network02.proxy, messager01.address);
} else {
console.log(`${network01.name} no need to set send service`);
}
const recvService01 = (await bridge01Contract.messagers(network02.chainId)).receiveService;
if (recvService01 === zeroAddress) {
console.log(`${network01.name} set recv service`);
await bridge01Contract.setReceiveService(network02.chainId, network02.proxy, messager02.address);
await bridge01Contract.setReceiveService(network02.chainId, network02.proxy, messager01.address);
} else {
console.log(`${network01.name} no need to set recv service`);
}

const sendService02 = (await bridge02Contract.messagers(network01.chainId)).sendService;
if (sendService02 === zeroAddress) {
console.log(`${network02.name} set send service`);
await bridge02Contract.setSendService(network01.chainId, network01.proxy, messager01.address);
await bridge02Contract.setSendService(network01.chainId, network01.proxy, messager02.address);
} else {
console.log(`${network02.name} no need to set send service`);
}
const recvService02 = (await bridge02Contract.messagers(network01.chainId)).receiveService;
if (recvService02 === zeroAddress) {
console.log(`${network02.name} set recv service`);
await bridge02Contract.setReceiveService(network01.chainId, network01.proxy, messager01.address);
await bridge02Contract.setReceiveService(network01.chainId, network01.proxy, messager02.address);
} else {
console.log(`${network02.name} no need to set recv service`);
}
Expand Down Expand Up @@ -123,37 +151,38 @@ async function registerToken(network01, network02, symbol01, symbol02, protocolF
console.log(`finished register token bridge: ${network01.chainId}->${network02.chainId}, ${srcToken.symbol}->${dstToken.symbol}`);
}

async function registerRelayer(srcNetwork, dstNetwork, srcToken, dstToken, baseFee, liquidityFeeRate, transferLimit) {
async function registerRelayer(network01, network02, symbol01, symbol02, baseFee, liquidityFeeRate, transferLimit) {
const srcToken = await tokenInfo(symbol01, network01);
const dstToken = await tokenInfo(symbol02, network02);

let baseFeeWithDecimals = ethers.utils.parseUnits(baseFee, srcToken.decimals);

const source = await ethers.getContractAt("HelixLnBridgeV3", srcNetwork.proxy, srcNetwork.wallet);
const source = await ethers.getContractAt("HelixLnBridgeV3", network01.proxy, network01.wallet);
await source.registerLnProvider(
dstNetwork.chainId,
network02.chainId,
srcToken.address,
dstToken.address,
baseFeeWithDecimals,
liquidityFeeRate,
ethers.utils.parseUnits(transferLimit, srcDecimals),
ethers.utils.parseUnits(transferLimit, srcToken.decimals),
{ gasLimit: 2000000 }
);

console.log(`finished register relayer: ${srcNetwork.chainId}->${dstNetwork.chainId}, ${srcToken.symbol}->${dstToken.symbol}`);
console.log(`finished register relayer: ${network01.chainId}->${network02.chainId}, ${symbol01}->${symbol02}`);
}

async function depositPenalty(srcNetwork, dstNetwork, srcToken, dstToken, penalty) {
async function depositPenalty(network01, network02, symbol01, symbol02, penalty) {
const srcToken = await tokenInfo(symbol01, network01);
const dstToken = await tokenInfo(symbol02, network02);

// set source network
let penaltyWithDecimals = ethers.utils.parseUnits(penalty, srcDecimals);
let penaltyWithDecimals = ethers.utils.parseUnits(penalty, srcToken.decimals);
let value = 0;
if (srcToken.address == kNativeTokenAddress) {
value = penaltyWithDecimals;
}

const source = await ethers.getContractAt("HelixLnBridgeV3", network01.proxy, network01.wallet);
await source.depositPenaltyReserve(
srcToken.address,
penaltyWithDecimals,
Expand All @@ -167,22 +196,22 @@ async function depositPenalty(srcNetwork, dstNetwork, srcToken, dstToken, penalt
async function mintToken(network, symbol, amount, to) {
const token = await tokenInfo(symbol, network);
const tokenContract = await ethers.getContractAt("Erc20", token.address, network.wallet);
await tokenContract.mint(to, amount);
await tokenContract.mint(to, ethers.utils.parseUnits(amount, token.decimals), {gasPrice: 100000000});
}

async function approveToken(network, symbol, amount) {
const token = await tokenInfo(symbol, network);
const tokenContract = await ethers.getContractAt("Erc20", token.address, network.wallet);
await tokenContract.approve(network.proxy, ethers.utils.parseUnits(amount, decimals), {gasLimit: 1000000});
console.log("finished to approve", tokenSymbol);
await tokenContract.approve(network.proxy, ethers.utils.parseUnits(amount, token.decimals), {gasLimit: 1000000});
console.log("finished to approve", symbol);
}

// 2. deploy mapping token factory
async function main() {
const bridgeInfos = Configure.bridgev3Config('dev');

const network01 = bridgeInfos['arbitrum-sepolia'];
const network02 = bridgeInfos['morph'];
const network02 = bridgeInfos['taiko-hekla'];

network01['wallet'] = wallet(network01.url);
network02['wallet'] = wallet(network02.url);
Expand All @@ -191,19 +220,23 @@ async function main() {
//await connectUsingLayerzero(network01, network02);

// register tokens
await registerToken(network01, network02, "usdc", "usdc", "0.001", "0.1", 10);
//await registerToken(network02, network01, "usdc", "usdc", "0.001", "0.1", 1);

// approve
//await approveToken(network01, "usdc", "1000000");
//await approveToken(network02, "usdt", "100000000000000");
//await approveToken(network02, "usdc", "100000000000000");

// mint
//await mintToken(network01, "usdc", "1000000", networ01.wallet.address);
//await mintToken(network02, "usdt", "10000000", "0x5861e3c9148D5DeB59b854805d8eCf3D5443fbEF");
//await mintToken(network02, "usdc", "10000000", "0x5861e3c9148D5DeB59b854805d8eCf3D5443fbEF");

// register relayer
//await registerRelayer(network01, network02, "usdc", "usdc", "0.1", 1, "1000000");
//await registerRelayer(network02, network01, "usdt", "usdt", "0.1", 1, "100000");
//await registerRelayer(network02, network01, "usdc", "usdc", "0.1", 1, "100000");

// deposit penalty
//await depositPenalty(network01, network02, "usdc", "usdc", "1000");
await depositPenalty(network02, network01, "usdt", "usdt", "10000");
await depositPenalty(network02, network01, "usdc", "usdc", "10000");
console.log("finished!");
}

Expand Down
2 changes: 1 addition & 1 deletion helix-contract/script/lnv3_deploy_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function deployLnBridgeV3(wallet, deployerAddress, salt) {
// 2. deploy mapping token factory
async function main() {
const chainInfo = Configure.chain('dev');
const network = chainInfo['morph'];
const network = chainInfo['taiko-hekla'];
const w = wallet(network);

const logicAddress = await deployLnBridgeV3(w, network.deployer, "lnv3-logic-v1.0.0");
Expand Down
10 changes: 6 additions & 4 deletions helix-contract/script/lnv3_deploy_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ async function deployLnBridgeV3Proxy(wallet, salt, dao, proxyAdminAddress, logic
}

async function deploy() {
const chainInfo = Configure.chain('dev');
const network = chainInfo['morph'];
const env = 'dev';
const chain = 'taiko-hekla';
const chainInfo = Configure.chain(env);
const network = chainInfo[chain];
const w = wallet(network.url);
const bridgeInfo = Configure.bridgeV3('dev');
const logicAddress = bridgeInfo.logic['morph']??bridgeInfo.logic['others'];
const bridgeInfo = Configure.bridgeV3(env);
const logicAddress = bridgeInfo.logic[chain]??bridgeInfo.logic['others'];

let proxyAddress = await deployLnBridgeV3Proxy(
w,
Expand Down
Loading

0 comments on commit b6809e8

Please sign in to comment.