Skip to content

Commit

Permalink
test script
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Sep 12, 2023
1 parent 173c726 commit b588b84
Show file tree
Hide file tree
Showing 13 changed files with 1,510 additions and 703 deletions.
4 changes: 2 additions & 2 deletions helix-contract/address/ln-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
},
"ProxyAdmin": "0xE3979fFa68BBa1F53c6F502c8F5788B370d28730",
"LnDefaultBridgeLogic": "0x43ae847d170e8AB26901a80b474d356Aaa30CEE1",
"LnOppositeBridgeLogic": "0x5ae6AF7b7fb6c869219289ba2570C6D4eF20Be2a",
"LnDefaultBridgeLogic": "0x230Bd5EeECaB61CcBdcd0bCeC4F2da83e6d56B8F",
"LnOppositeBridgeLogic": "0xcfeb6AE6099DE8655a78e099571D25a21DeAD6d3",
"LnDefaultBridgeProxy": "0x54cc9716905ba8ebdD01E6364125cA338Cd0054E",
"LnOppositeBridgeProxy": "0x79e6f452f1e491a7aF0382FA0a6EF9368691960D"
}
2 changes: 1 addition & 1 deletion helix-contract/contracts/ln/LnDefaultBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract LnDefaultBridge is Initializable, LnAccessController, LnDefaultBridgeSo
function _sendMessageToTarget(uint256 _remoteChainId, bytes memory _payload, bytes memory _extParams) internal override {
address sendService = messagers[_remoteChainId].sendService;
require(sendService != address(0), "invalid messager");
ILowLevelMessageSender(sendService).sendMessage(_remoteChainId, _payload, _extParams);
ILowLevelMessageSender(sendService).sendMessage{value: msg.value}(_remoteChainId, _payload, _extParams);
}

function _verifyRemote(uint256 _remoteChainId) whenNotPaused internal view override {
Expand Down
4 changes: 2 additions & 2 deletions helix-contract/contracts/ln/LnOppositeBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ contract LnOppositeBridge is Initializable, LnAccessController, LnOppositeBridge
address sendService;
address receiveService;
}
mapping(uint256=>MessagerService) messagers;
mapping(uint256=>MessagerService) public messagers;

receive() external payable {}

Expand Down Expand Up @@ -58,7 +58,7 @@ contract LnOppositeBridge is Initializable, LnAccessController, LnOppositeBridge
function _sendMessageToTarget(uint256 _remoteChainId, bytes memory _payload, bytes memory _extParams) internal override {
address sendService = messagers[_remoteChainId].sendService;
require(sendService != address(0), "invalid messager");
ILowLevelMessageSender(sendService).sendMessage(_remoteChainId, _payload, _extParams);
ILowLevelMessageSender(sendService).sendMessage{value: msg.value}(_remoteChainId, _payload, _extParams);
}

function _verifyRemote(uint256 _remoteChainId) whenNotPaused internal view override {
Expand Down
21 changes: 12 additions & 9 deletions helix-contract/contracts/ln/base/LnOppositeBridgeTarget.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ contract LnOppositeBridgeTarget {
slashInfos[_expectedTransferId] = SlashInfo(_params.provider, _params.sourceToken, _params.targetToken, msg.sender, _params.timestamp);

// Do not slash `transferId` in source chain unless `latestSlashTransferId` has been slashed
message = _encodeSlashCall(
message = encodeSlashCall(
fillTransfers[_expectedTransferId],
_expectedTransferId,
_params.timestamp,
Expand All @@ -139,7 +139,7 @@ contract LnOppositeBridgeTarget {
// transfer must be slashed
SlashInfo memory slashInfo = slashInfos[_transferId];
require(slashInfo.slasher != address(0), "slasher not exist");
message = _encodeSlashCall(
message = encodeSlashCall(
latestSlashTransferId,
_transferId,
slashInfo.timestamp,
Expand All @@ -150,15 +150,15 @@ contract LnOppositeBridgeTarget {
);
}

function _encodeSlashCall(
function encodeSlashCall(
bytes32 _latestSlashTransferId,
bytes32 _transferId,
uint256 _timestamp,
address _sourceToken,
address _targetToken,
address _provider,
address _slasher
) internal view returns(bytes memory) {
) public view returns(bytes memory) {
return abi.encodeWithSelector(
ILnOppositeBridgeSource.slash.selector,
_latestSlashTransferId,
Expand Down Expand Up @@ -198,14 +198,17 @@ contract LnOppositeBridgeTarget {
_sendMessageToTarget(remoteChainId, retryCallMessage, _extParams);
}

function _requestWithdrawMargin(
function encodeWithdrawMargin(
bytes32 _lastTransferId,
address _sourceToken,
address _targetToken,
uint112 _amount
) internal view returns(bytes memory message) {
bytes32 latestSlashTransferId = fillTransfers[_lastTransferId];
require(latestSlashTransferId != bytes32(0), "invalid last transfer");
) public view returns(bytes memory message) {
bytes32 latestSlashTransferId = LnBridgeHelper.INIT_SLASH_TRANSFER_ID;
if (_lastTransferId != bytes32(0)) {
latestSlashTransferId = fillTransfers[_lastTransferId];
require(latestSlashTransferId != bytes32(0), "invalid last transfer");
}

return abi.encodeWithSelector(
ILnOppositeBridgeSource.withdrawMargin.selector,
Expand All @@ -227,7 +230,7 @@ contract LnOppositeBridgeTarget {
uint112 _amount,
bytes memory _extParams
) payable external {
bytes memory withdrawCallMessage = _requestWithdrawMargin(
bytes memory withdrawCallMessage = encodeWithdrawMargin(
_lastTransferId,
_sourceToken,
_targetToken,
Expand Down
3 changes: 2 additions & 1 deletion helix-contract/deploy/deploy_ln_configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ async function main() {
//await connectAll(arbWallet, lineaWallet, goerliWallet, mantleWallet);
//await registerAllToken(arbWallet, lineaWallet, goerliWallet, mantleWallet);
//await mintAndApproveAll(arbWallet, lineaWallet, goerliWallet, mantleWallet);
await registerAllRelayer(arbWallet, lineaWallet, goerliWallet, mantleWallet);
await registerRelayer("LnDefaultBridge", goerliWallet, lineaWallet, goerliNetwork, lineaNetwork, "usdt");
//await registerAllRelayer(arbWallet, lineaWallet, goerliWallet, mantleWallet);
}

main()
Expand Down
22 changes: 18 additions & 4 deletions helix-contract/deploy/deploy_ln_logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,38 @@ async function deployLnDefaultBridge(wallet, deployerAddress, salt) {
const bytecode = Create2.getDeployedBytecode(bridgeContract, [], []);
const address = await Create2.deploy(deployerAddress, wallet, bytecode, salt);
console.log("finish to deploy ln default bridge logic, address: ", address);
return address;
}

async function deployLnOppositeBridge(wallet, deployerAddress, salt) {
const bridgeContract = await ethers.getContractFactory("LnOppositeBridge", wallet);
const bytecode = Create2.getDeployedBytecode(bridgeContract, [], []);
const address = await Create2.deploy(deployerAddress, wallet, bytecode, salt);
console.log("finish to deploy ln opposite bridge logic, address: ", address);
return address;
}

// 2. deploy mapping token factory
async function main() {
const networks = [goerliNetwork, mantleNetwork, arbitrumNetwork, lineaNetwork];
//const network = goerliNetwork;
//const network = mantleNetwork;
//const network = arbitrumNetwork;
const network = lineaNetwork;
const w = wallet(network.url);
//await deployLnDefaultBridge(w, network.deployer, "ln-default-logic-v1.0.1");
await deployLnOppositeBridge(w, network.deployer, "ln-opposite-logic-v1.0.2");
//const network = lineaNetwork;
//const w = wallet(network.url);
//await deployLnDefaultBridge(w, network.deployer, "ln-default-logic-v1.0.3");
//await deployLnOppositeBridge(w, network.deployer, "ln-opposite-logic-v1.0.2");
for (const network of networks) {
// deploy logic bridge
const w = wallet(network.url);
//const logicAddress = await deployLnDefaultBridge(w, network.deployer, "ln-default-logic-v1.0.5");
const logicAddress = await deployLnOppositeBridge(w, network.deployer, "ln-opposite-logic-v1.0.5");
// upgrade
const proxyAdmin = await ethers.getContractAt("ProxyAdmin", "0xE3979fFa68BBa1F53c6F502c8F5788B370d28730", w);
//await proxyAdmin.upgrade("0x54cc9716905ba8ebdD01E6364125cA338Cd0054E", logicAddress);
await proxyAdmin.upgrade("0x79e6f452f1e491a7aF0382FA0a6EF9368691960D", logicAddress);
console.log("finished");
}
}

main()
Expand Down
Loading

0 comments on commit b588b84

Please sign in to comment.