Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Feb 20, 2024
2 parents 0d2f73a + 0c0a881 commit c7a6973
Show file tree
Hide file tree
Showing 20 changed files with 690 additions and 378 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
85 changes: 83 additions & 2 deletions helix-contract/address/ln-product.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,85 @@
"lzChainId": 102,
"lzEndpoint": "0x3c2269811836af69497E5F486A85D7316753cf62",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"linea": {
"name": "linea",
"url": "https://rpc.linea.build",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 59144,
"lzChainId": 183,
"lzEndpoint": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"base": {
"name": "base",
"url": "https://mainnet.base.org",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 8453,
"lzChainId": 184,
"lzEndpoint": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"op": {
"name": "op",
"url": "https://mainnet.optimism.io",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 10,
"lzChainId": 111,
"lzEndpoint": "0x3c2269811836af69497E5F486A85D7316753cf62",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"gnosis": {
"name": "gnosis",
"url": "https://rpc.gnosischain.com",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 100,
"lzChainId": 145,
"lzEndpoint": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"mantle": {
"name": "mantle",
"url": "https://rpc.mantle.xyz",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 5000,
"lzChainId": 181,
"lzEndpoint": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"scroll": {
"name": "scroll",
"url": "https://rpc.scroll.io",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 534352,
"lzChainId": 214,
"lzEndpoint": "0xb6319cC6c8c27A8F5dAF0dD3DF91EA35C4720dd7",
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3"
},
"darwinia-dvm": {
"name": "darwinia-dvm",
"url": "https://rpc.darwinia.network",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 46,
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3",
"ormpPort": "0x0000000005d961F950adA391C1511c92bbc64D9F"
},
"polygon-zkevm": {
"name": "polygon-zkevm",
"url": "https://zkevm-rpc.com",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 1101,
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3",
"lzChainId": 158,
"lzEndpoint": "0x9740FF91F1985D8d2B71494aE1A2f723bb3Ed9E4"
},
"crab-dvm": {
"name": "crab-dvm",
"url": "https://crab-rpc.darwinia.network",
"dao": "0x88a39B052d477CfdE47600a7C9950a441Ce61cb4",
"chainId": 44,
"deployer": "0x80D4c766C5142D1313D531Afe7384D0D5E108Db3",
"ormpPort": "0x0000000005d961F950adA391C1511c92bbc64D9F"
}
},
"messagers": {
Expand All @@ -35,7 +114,8 @@
"arbitrum": {
"Eth2ArbReceiveService": "0xc95D939Da72ECe8Bd794d42EaEd28974CDb0ADa2",
"LayerZeroMessager": "0x509354A4ebf98aCC7a65d2264694A65a2938cac9",
"DarwiniaMsglineMessager": "0x3d33856dcf74f110690f5a2647c7dfb9bb5ff2d0"
"DarwiniaMsglineMessager": "0x3d33856dcf74f110690f5a2647c7dfb9bb5ff2d0",
"MsgportMessager": "0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0"
},
"polygon": {
"LayerZeroMessager": "0x463D1730a8527CA58d48EF70C7460B9920346567"
Expand All @@ -51,7 +131,8 @@
},
"darwinia": {
"DarwiniaMsglineMessager": "0x6035Eb7783d7Aab8d0a57a7b154f5DD5D5477Ff2",
"DarwiniaSub2SubMessager": "0x9dF64c435F02fb46bd8eB3757D3dF42dDA912bDe"
"DarwiniaSub2SubMessager": "0x9dF64c435F02fb46bd8eB3757D3dF42dDA912bDe",
"MsgportMessager": "0x65Be094765731F394bc6d9DF53bDF3376F1Fc8B0"
},
"crab": {
"DarwiniaSub2SubMessager": "0x9dF64c435F02fb46bd8eB3757D3dF42dDA912bDe"
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
@@ -1,14 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.17;

interface IMessageLine {
interface IMessagePort {
function send(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params) external payable;
function fee(uint256 toChainId, address toDapp, bytes calldata message, bytes calldata params) external view returns (uint256);
}

abstract contract Application {
function _msgSender() internal view returns (address payable _line) {
_line = payable(msg.sender);
function _msgSender() internal view returns (address payable _port) {
_port = payable(msg.sender);
}

function _fromChainId() internal pure returns (uint256 _msgDataFromChainId) {
Expand All @@ -19,7 +19,7 @@ abstract contract Application {
}

function _xmsgSender() internal pure returns (address payable _from) {
require(msg.data.length >= 20, "!line");
require(msg.data.length >= 20, "!port");
assembly {
_from := shr(96, calldataload(sub(calldatasize(), 20)))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
pragma solidity ^0.8.17;

import "../utils/AccessController.sol";
import "../interfaces/IMessageLine.sol";
import "../interfaces/IMessagePort.sol";

contract MsglineMessager is Application, AccessController {
IMessageLine public msgline;
contract MsgportMessager is Application, AccessController {
IMessagePort 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 @@ -29,22 +29,22 @@ contract MsglineMessager is Application, AccessController {
_;
}

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

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

function setMsgline(address _msgline) onlyDao external {
msgline = IMessageLine(_msgline);
function setMsgPort(address _msgport) onlyDao external {
msgport = IMessagePort(_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 {
function receiveMessage(uint256 _srcAppChainId, address _remoteAppAddress, address _localAppAddress, bytes memory _message) onlyMsgPort 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
Loading

0 comments on commit c7a6973

Please sign in to comment.