Skip to content

Commit fa6471f

Browse files
committed
add contracts v0.4 support, NFT support and eccm with chain-id
1 parent c9212e4 commit fa6471f

74 files changed

Lines changed: 21774 additions & 45 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contracts/core/assets/usdt/USDT.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// /**
2-
// *Submitted for verification at Etherscan.io on 2017-11-28
3-
// */
1+
/**
2+
*Submitted for verification at Etherscan.io on 2017-11-28
3+
*/
44

5-
// pragma solidity ^0.4.17;
5+
pragma solidity ^0.5.0;
66

77
// /**
88
// * @title SafeMath

contracts/core/cross_chain_manager/interface/IEthCrossChainManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.5.0;
1+
pragma solidity >=0.5.0;
22

33
/**
44
* @dev Interface of the EthCrossChainManager contract for business contract like LockProxy to request cross chain transaction

contracts/core/cross_chain_manager/interface/IEthCrossChainManagerProxy.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pragma solidity ^0.5.0;
1+
pragma solidity >=0.5.0;
22

33
/**
44
* @dev Interface of the EthCrossChainManagerProxy for business contract like LockProxy to obtain the reliable EthCrossChainManager contract hash.

contracts/core/cross_chain_manager/interface/IUpgradableECCM.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ interface IUpgradableECCM {
99
function paused() external view returns (bool);
1010
function upgradeToNew(address) external returns (bool);
1111
function isOwner() external view returns (bool);
12+
function setChainId(uint64 _newChainId) external returns (bool);
1213
}

contracts/core/cross_chain_manager/libs/EthCrossChainUtils.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ library ECCUtils {
111111
function verifySig(bytes memory _rawHeader, bytes memory _sigList, address[] memory _keepers, uint _m) internal pure returns (bool){
112112
bytes32 hash = getHeaderHash(_rawHeader);
113113

114-
uint signed = 0;
115114
uint sigCount = _sigList.length / POLYCHAIN_SIGNATURE_LEN;
116115
address[] memory signers = new address[](sigCount);
117116
bytes32 r;

contracts/core/cross_chain_manager/logic/EthCrossChainManager.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ import "./../upgrade/UpgradableECCM.sol";
88
import "./../libs/EthCrossChainUtils.sol";
99
import "./../interface/IEthCrossChainManager.sol";
1010
import "./../interface/IEthCrossChainData.sol";
11+
1112
contract EthCrossChainManager is IEthCrossChainManager, UpgradableECCM {
1213
using SafeMath for uint256;
13-
14+
1415
event InitGenesisBlockEvent(uint256 height, bytes rawHeader);
1516
event ChangeBookKeeperEvent(uint256 height, bytes rawHeader);
1617
event CrossChainEvent(address indexed sender, bytes txId, address proxyOrAssetContract, uint64 toChainId, bytes toContract, bytes rawdata);
1718
event VerifyHeaderAndExecuteTxEvent(uint64 fromChainID, bytes toContract, bytes crossChainTxHash, bytes fromChainTxHash);
18-
constructor(address _eccd) UpgradableECCM(_eccd) public {}
19+
20+
constructor(address _eccd, uint64 _chainId) UpgradableECCM(_eccd, _chainId) public {}
1921

2022
/* @notice sync Poly chain genesis block header to smart contrat
2123
* @dev this function can only be called once, nextbookkeeper of rawHeader can't be empty
@@ -157,7 +159,7 @@ contract EthCrossChainManager is IEthCrossChainManager, UpgradableECCM {
157159
require(eccd.markFromChainTxExist(toMerkleValue.fromChainID, Utils.bytesToBytes32(toMerkleValue.txHash)), "Save crosschain tx exist failed!");
158160

159161
// Ethereum ChainId is 2, we need to check the transaction is for Ethereum network
160-
require(toMerkleValue.makeTxParam.toChainId == uint64(2), "This Tx is not aiming at Ethereum network!");
162+
require(toMerkleValue.makeTxParam.toChainId == chainId, "This Tx is not aiming at Ethereum network!");
161163

162164
// Obtain the targeting contract, so that Ethereum cross chain manager contract can trigger the executation of cross chain tx on Ethereum side
163165
address toContract = Utils.bytesToAddress(toMerkleValue.makeTxParam.toContract);

contracts/core/cross_chain_manager/logic/EthCrossChainManager_new_template.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ contract NewEthCrossChainManager is IEthCrossChainManager, UpgradableECCM {
1515
event ChangeBookKeeperEvent(uint256 height, bytes rawHeader);
1616
event CrossChainEvent(address indexed sender, bytes txId, address proxyOrAssetContract, uint64 toChainId, bytes toContract, bytes rawdata);
1717
event VerifyHeaderAndExecuteTxEvent(uint64 fromChainID, bytes toContract, bytes crossChainTxHash, bytes fromChainTxHash);
18-
constructor(address _eccd) UpgradableECCM(_eccd) public {}
18+
constructor(address _eccd, uint64 _chainId) UpgradableECCM(_eccd, _chainId) public {}
1919

2020
/* @notice sync Poly chain genesis block header to smart contrat
2121
* @dev this function can only be called once, nextbookkeeper of rawHeader can't be empty

contracts/core/cross_chain_manager/upgrade/EthCrossChainManagerProxy.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,11 @@ contract EthCrossChainManagerProxy is IEthCrossChainManagerProxy, Ownable, Pausa
4848
function getEthCrossChainManager() whenNotPaused public view returns (address) {
4949
return EthCrossChainManagerAddr_;
5050
}
51+
function changeManagerChainID(uint64 _newChainId) onlyOwner whenPaused public {
52+
IUpgradableECCM eccm = IUpgradableECCM(EthCrossChainManagerAddr_);
53+
if (!eccm.paused()) {
54+
require(eccm.pause(), "Pause old EthCrossChainManager contract failed!");
55+
}
56+
require(eccm.setChainId(_newChainId), "set chain ID failed. ");
57+
}
5158
}

contracts/core/cross_chain_manager/upgrade/UpgradableECCM.sol

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ import "./../../../libs/ownership/Ownable.sol";
77

88
contract UpgradableECCM is IUpgradableECCM, Ownable, Pausable {
99
address public EthCrossChainDataAddress;
10-
constructor (address ethCrossChainDataAddr) Pausable() Ownable() public {
10+
uint64 public chainId;
11+
12+
constructor (address ethCrossChainDataAddr, uint64 _chainId) Pausable() Ownable() public {
1113
EthCrossChainDataAddress = ethCrossChainDataAddr;
14+
chainId = _chainId;
1215
}
1316
function pause() onlyOwner public returns (bool) {
1417
if (!paused()) {
@@ -38,4 +41,9 @@ contract UpgradableECCM is IUpgradableECCM, Ownable, Pausable {
3841
eccd.transferOwnership(newEthCrossChainManagerAddress);
3942
return true;
4043
}
44+
45+
function setChainId(uint64 _newChainId) whenPaused onlyOwner public returns (bool) {
46+
chainId = _newChainId;
47+
return true;
48+
}
4149
}

contracts/core/lock_proxy/LockProxy.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,18 @@ contract LockProxy is Ownable {
154154
return true;
155155
}
156156

157-
158157
function _transferERC20ToContract(address fromAssetHash, address fromAddress, address toAddress, uint256 amount) internal returns (bool) {
159-
IERC20 erc20Token = IERC20(fromAssetHash);
158+
IERC20 erc20Token = IERC20(fromAssetHash);
160159
// require(erc20Token.transferFrom(fromAddress, toAddress, amount), "trasnfer ERC20 Token failed!");
161-
erc20Token.safeTransferFrom(fromAddress, toAddress, amount);
162-
return true;
160+
erc20Token.safeTransferFrom(fromAddress, toAddress, amount);
161+
return true;
163162
}
163+
164164
function _transferERC20FromContract(address toAssetHash, address toAddress, uint256 amount) internal returns (bool) {
165-
IERC20 erc20Token = IERC20(toAssetHash);
165+
IERC20 erc20Token = IERC20(toAssetHash);
166166
// require(erc20Token.transfer(toAddress, amount), "trasnfer ERC20 Token failed!");
167-
erc20Token.safeTransfer(toAddress, amount);
168-
return true;
167+
erc20Token.safeTransfer(toAddress, amount);
168+
return true;
169169
}
170170

171171
function _serializeTxArgs(TxArgs memory args) internal pure returns (bytes memory) {

0 commit comments

Comments
 (0)