Skip to content

Commit

Permalink
xToken deploy on testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Feb 7, 2024
1 parent af8b572 commit 1bbce6f
Show file tree
Hide file tree
Showing 17 changed files with 543 additions and 312 deletions.
10 changes: 10 additions & 0 deletions helix-contract/address/ln-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"chainId": 11155111,
"lzChainId": 10161,
"lzEndpoint": "0xae92d5aD7583AD66E49A0c67BAd18F6ba52dDDc1",
"ormpPort": "0x0000000005d961F950adA391C1511c92bbc64D9F",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"arbitrum-sepolia": {
Expand All @@ -16,6 +17,15 @@
"chainId": 421614,
"lzChainId": 10231,
"lzEndpoint": "0x6098e96a28E02f27B1e6BD381f870F1C8Bd169d3",
"ormpPort": "0x0000000005d961F950adA391C1511c92bbc64D9F",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"pangolin": {
"name": "pangolin",
"url": "https://pangolin-rpc.darwinia.network",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 43,
"ormpPort": "0x0000000005d961F950adA391C1511c92bbc64D9F",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"zksync": {
Expand Down
14 changes: 7 additions & 7 deletions helix-contract/address/xtoken-dev.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"messagers": {
"crab": {
"msglineMessager": "0xf85638B61E0425D6BB91981190B73246e3AF3CA9"
"pangolin": {
"msgportMessager": "0xf7F461728DC89de5EF6615715678b5f5b12bb98A"
},
"sepolia": {
"msglineMessager": "0xc876D0873e4060472334E297b2db200Ca10cc806"
"msgportMessager": "0xf7F461728DC89de5EF6615715678b5f5b12bb98A"
},
"tron": {
"msglineMessager": "TR3nibHkcXovd1nsuNrLWigQboj4uduhKT"
}
},
"backingProxy": {
"crab": "0xbdC7bbF408931C5d666b4F0520E0D9E9A0B04e99"
"pangolin": "0x94eAb0CB67AB7edaf9A280aCa097F70e4BD780ac"
},
"backingLogic": {
"crab": "0x01F53415adC20a2D058DfF14e295Ab955CafD6d6"
"pangolin": "0x1315f7050c66ceBE66983D8981007A1347830310"
},
"issuingProxy": {
"sepolia": "0xf22D0bb66b39745Ae6e3fEa3E5859d7f0b367Fd1",
"sepolia": "0x371019523b25Ff4F26d977724f976566b08bf741",
"tron": "TJK57bJTvnaNRGFHwbihg1bXtgnyed6sKa"
},
"issuingLogic": {
"sepolia": "0xCD1c1C799f3914ECFC5e3653D3Cc846355d3dFC9",
"sepolia": "0x277d44E8E30cE978F742339C0B8ce22847a0fc00",
"tron": "TD7VoAQnJDKsWsgZZTeeHvBKY5fogRDVc2"
},
"proxyAdmin": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ pragma solidity ^0.8.17;
import "../utils/AccessController.sol";
import "../interfaces/IMessageLine.sol";

contract MsglineMessager is Application, AccessController {
IMessageLine public msgline;
contract MsgportMessager is Application, AccessController {
IMessageLine public msgport;

struct RemoteMessager {
uint256 msglineRemoteChainId;
uint256 msgportRemoteChainId;
address messager;
}

mapping(address=>bool) public whiteList;
// app remoteChainId => msgline remote messager
// app remoteChainId => msgport remote messager
mapping(uint256=>RemoteMessager) public remoteMessagers;

// token bridge pair
// hash(msglineRemoteChainId, localAppAddress) => remoteAppAddress
// hash(msgportRemoteChainId, localAppAddress) => remoteAppAddress
mapping(bytes32=>address) public remoteAppReceivers;
mapping(bytes32=>address) public remoteAppSenders;

Expand All @@ -30,21 +30,21 @@ contract MsglineMessager is Application, AccessController {
}

modifier onlyMsgline() {
require(msg.sender == address(msgline), "invalid caller");
require(msg.sender == address(msgport), "invalid caller");
_;
}

constructor(address _dao, address _msgline) {
constructor(address _dao, address _msgport) {
_initialize(_dao);
msgline = IMessageLine(_msgline);
msgport = IMessageLine(_msgport);
}

function setMsgline(address _msgline) onlyDao external {
msgline = IMessageLine(_msgline);
function setMsgline(address _msgport) onlyDao external {
msgport = IMessageLine(_msgport);
}

function setRemoteMessager(uint256 _appRemoteChainId, uint256 _msglineRemoteChainId, address _remoteMessager) onlyDao external {
remoteMessagers[_appRemoteChainId] = RemoteMessager(_msglineRemoteChainId, _remoteMessager);
function setRemoteMessager(uint256 _appRemoteChainId, uint256 _msgportRemoteChainId, address _remoteMessager) onlyDao external {
remoteMessagers[_appRemoteChainId] = RemoteMessager(_msgportRemoteChainId, _remoteMessager);
}

function setWhiteList(address _caller, bool _enable) external onlyDao {
Expand All @@ -54,36 +54,36 @@ contract MsglineMessager is Application, AccessController {
function registerRemoteReceiver(uint256 _remoteChainId, address _remoteBridge) onlyWhiteList external {
RemoteMessager memory remoteMessager = remoteMessagers[_remoteChainId];
require(remoteMessager.messager != address(0), "remote not configured");
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msglineRemoteChainId, msg.sender));
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msgportRemoteChainId, msg.sender));
remoteAppReceivers[key] = _remoteBridge;
}

function registerRemoteSender(uint256 _remoteChainId, address _remoteBridge) onlyWhiteList external {
RemoteMessager memory remoteMessager = remoteMessagers[_remoteChainId];
require(remoteMessager.messager != address(0), "remote not configured");
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msglineRemoteChainId, msg.sender));
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msgportRemoteChainId, msg.sender));
remoteAppSenders[key] = _remoteBridge;
}

function sendMessage(uint256 _remoteChainId, bytes memory _message, bytes memory _params) onlyWhiteList external payable {
RemoteMessager memory remoteMessager = remoteMessagers[_remoteChainId];
require(remoteMessager.messager != address(0), "remote not configured");
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msglineRemoteChainId, msg.sender));
bytes32 key = keccak256(abi.encodePacked(remoteMessager.msgportRemoteChainId, msg.sender));
address remoteAppAddress = remoteAppReceivers[key];
require(remoteAppAddress != address(0), "app pair not registered");
bytes memory msglinePayload = messagePayload(msg.sender, remoteAppAddress, _message);
msgline.send{ value: msg.value }(
remoteMessager.msglineRemoteChainId,
bytes memory msgportPayload = messagePayload(msg.sender, remoteAppAddress, _message);
msgport.send{ value: msg.value }(
remoteMessager.msgportRemoteChainId,
remoteMessager.messager,
msglinePayload,
msgportPayload,
_params
);
}

function receiveMessage(uint256 _srcAppChainId, address _remoteAppAddress, address _localAppAddress, bytes memory _message) onlyMsgline external {
uint256 srcChainId = _fromChainId();
RemoteMessager memory remoteMessager = remoteMessagers[_srcAppChainId];
require(srcChainId == remoteMessager.msglineRemoteChainId, "invalid remote chainid");
require(srcChainId == remoteMessager.msgportRemoteChainId, "invalid remote chainid");
require(remoteMessager.messager == _xmsgSender(), "invalid remote messager");
bytes32 key = keccak256(abi.encodePacked(srcChainId, _localAppAddress));

Expand All @@ -99,7 +99,7 @@ contract MsglineMessager is Application, AccessController {

function messagePayload(address _from, address _to, bytes memory _message) public view returns(bytes memory) {
return abi.encodeWithSelector(
MsglineMessager.receiveMessage.selector,
MsgportMessager.receiveMessage.selector,
block.chainid,
_from,
_to,
Expand Down
49 changes: 49 additions & 0 deletions helix-contract/deploy/deploy_guardv3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const ethUtil = require('ethereumjs-util');
const abi = require('ethereumjs-abi');
const secp256k1 = require('secp256k1');
const fs = require("fs");

var Create2 = require("./create2.js");

const privateKey = process.env.PRIKEY

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

function chainInfo(configure, network) {
return configure.chains[network];
}

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 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 pathConfig = "./address/ln-dev.json";
const configure = JSON.parse(
fs.readFileSync(pathConfig, "utf8")
);

const network = chainInfo(configure, "sepolia");
const w = wallet(configure, network);
await deployGuardV3(w, network.deployer, "guardv3-v1.0.0");
}

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

12 changes: 6 additions & 6 deletions helix-contract/deploy/deploy_lnv2_configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ async function registerToken(configure, contractName, srcWallet, dstWallet, srcN
const targetToken = await ethers.getContractAt("Erc20", dstTokenAddress, dstWallet);
dstDecimals = await targetToken.decimals();
}
let fee = ethers.utils.parseUnits("100", srcDecimals);
let fee = ethers.utils.parseUnits("0.1", srcDecimals);
const penaltyDecimals = contractName == "LnOppositeBridge" ? srcDecimals : dstDecimals;
let penalty = ethers.utils.parseUnits("1000", penaltyDecimals);
if (srcTokenAddress == kNativeTokenAddress || dstTokenAddress == kNativeTokenAddress) {
fee = ethers.utils.parseUnits("0.001", srcDecimals);
fee = ethers.utils.parseUnits("0.0001", srcDecimals);
penalty = ethers.utils.parseUnits("0.01", penaltyDecimals);
}

Expand Down Expand Up @@ -340,8 +340,8 @@ async function main() {
fs.readFileSync(pathConfig, "utf8")
);

const network01 = configure.chains['arbitrum-sepolia'];
const network02 = configure.chains['zksync'];
const network01 = configure.chains['zksync'];
const network02 = configure.chains['sepolia'];

const wallet01 = wallet(network01.url);
const wallet02 = wallet(network02.url);
Expand All @@ -361,8 +361,8 @@ async function main() {
//await approveAll(configure, network01, wallet01);
//await approveAll(configure, network02, wallet02);

//await registerAllRelayer(configure, pair, "LnDefaultBridge");
//await registerAllRelayer(configure, pair, "LnOppositeBridge");
await registerAllRelayer(configure, pair, "LnDefaultBridge");
await registerAllRelayer(configure, pair, "LnOppositeBridge");
console.log("finished!");
}

Expand Down
49 changes: 18 additions & 31 deletions helix-contract/deploy/deploy_msgline_messager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,38 @@ const ethUtil = require('ethereumjs-util');
const abi = require('ethereumjs-abi');
const secp256k1 = require('secp256k1');
const fs = require("fs");

var ProxyDeployer = require("./proxy.js");
var Create2 = require("./create2.js");

const privateKey = process.env.PRIKEY

const crabNetwork = {
name: "crab",
url: "https://crab-rpc.darwinia.network",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
deployer: "0xbe6b2860d3c17a719be0A4911EA0EE689e8357f3",
msgline: "0x0000000000D2de3e2444926c4577b0A59F1DD8BC",
};

const sepoliaNetwork = {
name: "sepolia",
url: "https://rpc-sepolia.rockx.com",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
deployer: "0xbe6b2860d3c17a719be0A4911EA0EE689e8357f3",
msgline: "0x0000000000D2de3e2444926c4577b0A59F1DD8BC",
};

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

async function deployMessager(wallet, dao, msgline, deployer) {
const messagerContract = await ethers.getContractFactory("MsglineMessager", wallet);
const messager = await messagerContract.deploy(dao, msgline);
await messager.deployed();
console.log("finish to deploy messager, address:", messager.address);
return messager.address;
async function deployMessager(wallet, dao, msgport, deployer, salt) {
const messagerContract = await ethers.getContractFactory("MsgportMessager", wallet);
const bytecode = Create2.getDeployedBytecode(messagerContract, ["address", "address"], [dao, msgport]);
const address = await Create2.deploy(deployer, wallet, bytecode, salt, 2000000);
console.log("finish to deploy messager, address:", address);
return address;
}

async function deploy() {
const walletCrab = wallet(crabNetwork.url);
await deployMessager(walletCrab, crabNetwork.dao, crabNetwork.msgline, crabNetwork.deployer);

const walletSepolia = wallet(sepoliaNetwork.url);
await deployMessager(walletSepolia, sepoliaNetwork.dao, sepoliaNetwork.msgline, sepoliaNetwork.deployer);
function wallet(configure, network) {
const provider = new ethers.providers.JsonRpcProvider(network.url);
const wallet = new ethers.Wallet(privateKey, provider);
return wallet;
}

async function main() {
await deploy();
const pathConfig = "./address/ln-dev.json";
const configure = JSON.parse(
fs.readFileSync(pathConfig, "utf8")
);
const network = configure.chains['pangolin'];
const w = wallet(configure, network);
await deployMessager(w, network.dao, network.ormpPort, network.deployer, "msgport-messager-v1.0.0");
}

main()
Expand Down
24 changes: 12 additions & 12 deletions helix-contract/deploy/deploy_xtoken_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ var ProxyDeployer = require("./proxy.js");

const privateKey = process.env.PRIKEY

const crabNetwork = {
name: "crab",
url: "https://crab-rpc.darwinia.network",
const pangolinNetwork = {
name: "pangolin",
url: "https://pangolin-rpc.darwinia.network",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
messager: "0xf85638B61E0425D6BB91981190B73246e3AF3CA9",
backing: "0xbdC7bbF408931C5d666b4F0520E0D9E9A0B04e99",
chainid: 44
messager: "0xf7F461728DC89de5EF6615715678b5f5b12bb98A",
backing: "0x94eAb0CB67AB7edaf9A280aCa097F70e4BD780ac",
chainid: 43
};

const sepoliaNetwork = {
name: "sepolia",
url: "https://rpc-sepolia.rockx.com",
dao: "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
messager: "0xc876D0873e4060472334E297b2db200Ca10cc806",
issuing: "0xf22D0bb66b39745Ae6e3fEa3E5859d7f0b367Fd1",
messager: "0xf7F461728DC89de5EF6615715678b5f5b12bb98A",
issuing: "0x371019523b25Ff4F26d977724f976566b08bf741",
chainid: 11155111
};

Expand All @@ -32,14 +32,14 @@ function wallet(url) {
}

async function deploy() {
const backingNetwork = crabNetwork;
const backingNetwork = pangolinNetwork;
const issuingNetwork = sepoliaNetwork;
const walletBacking = wallet(crabNetwork.url);
const walletBacking = wallet(pangolinNetwork.url);
const walletIssuing = wallet(sepoliaNetwork.url);

// connect messager
const backingMessager = await ethers.getContractAt("MsglineMessager", backingNetwork.messager, walletBacking);
const issuingMessager = await ethers.getContractAt("MsglineMessager", issuingNetwork.messager, walletIssuing);
const backingMessager = await ethers.getContractAt("MsgportMessager", backingNetwork.messager, walletBacking);
const issuingMessager = await ethers.getContractAt("MsgportMessager", issuingNetwork.messager, walletIssuing);
await backingMessager.setRemoteMessager(issuingNetwork.chainid, issuingNetwork.chainid, issuingMessager.address, {gasLimit: 2000000});
await issuingMessager.setRemoteMessager(backingNetwork.chainid, backingNetwork.chainid, backingMessager.address, {gasLimit: 2000000});
console.log("connect messager successed");
Expand Down
Loading

0 comments on commit 1bbce6f

Please sign in to comment.