decimal shift feature (#268)
* implementation proposal for decimal shift feature issue #243
This commit is contained in:
parent
1841968dce
commit
63c11df4b5
|
@ -24,6 +24,7 @@ contract BasicBridge is Initializable, Validatable, Ownable, Upgradeable, Claima
|
|||
bytes32 internal constant DAILY_LIMIT = keccak256(abi.encodePacked("dailyLimit"));
|
||||
bytes32 internal constant EXECUTION_MAX_PER_TX = keccak256(abi.encodePacked("executionMaxPerTx"));
|
||||
bytes32 internal constant EXECUTION_DAILY_LIMIT = keccak256(abi.encodePacked("executionDailyLimit"));
|
||||
bytes32 internal constant DECIMAL_SHIFT = keccak256(abi.encodePacked("decimalShift"));
|
||||
|
||||
function getBridgeInterfacesVersion() external pure returns (uint64 major, uint64 minor, uint64 patch) {
|
||||
return (2, 3, 0);
|
||||
|
@ -127,6 +128,10 @@ contract BasicBridge is Initializable, Validatable, Ownable, Upgradeable, Claima
|
|||
return executionDailyLimit() >= nextLimit && _amount <= executionMaxPerTx();
|
||||
}
|
||||
|
||||
function decimalShift() public view returns (uint256) {
|
||||
return uintStorage[DECIMAL_SHIFT];
|
||||
}
|
||||
|
||||
function claimTokens(address _token, address _to) public onlyIfUpgradeabilityOwner validAddress(_to) {
|
||||
claimValues(_token, _to);
|
||||
}
|
||||
|
|
|
@ -9,16 +9,15 @@ contract BasicForeignBridgeErcToErc is BasicForeignBridge {
|
|||
address _erc20token,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _gasPrice,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _maxPerTxHomeDailyLimitHomeMaxPerTxArray, // [ 0 = _maxPerTx, 1 = _homeDailyLimit, 2 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_requiredBlockConfirmations != 0);
|
||||
require(_gasPrice > 0);
|
||||
require(_homeMaxPerTx < _homeDailyLimit);
|
||||
require(_maxPerTxHomeDailyLimitHomeMaxPerTxArray[2] < _maxPerTxHomeDailyLimitHomeMaxPerTxArray[1]); // _homeMaxPerTx < _homeDailyLimit
|
||||
require(_owner != address(0));
|
||||
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
|
@ -26,15 +25,16 @@ contract BasicForeignBridgeErcToErc is BasicForeignBridge {
|
|||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
uintStorage[GAS_PRICE] = _gasPrice;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _homeDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _homeMaxPerTx;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[1];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[2];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
setInitialize();
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_gasPrice);
|
||||
emit ExecutionDailyLimitChanged(_homeDailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_maxPerTxHomeDailyLimitHomeMaxPerTxArray[1]);
|
||||
}
|
||||
|
||||
function getBridgeMode() external pure returns (bytes4 _data) {
|
||||
|
@ -52,7 +52,8 @@ contract BasicForeignBridgeErcToErc is BasicForeignBridge {
|
|||
bytes32 /*_txHash*/
|
||||
) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_amount));
|
||||
return erc20token().transfer(_recipient, _amount);
|
||||
uint256 amount = _amount.div(10 ** decimalShift());
|
||||
return erc20token().transfer(_recipient, amount);
|
||||
}
|
||||
|
||||
function onFailedMessage(address, uint256, bytes32) internal {
|
||||
|
|
|
@ -11,30 +11,34 @@ contract ForeignBridgeErc677ToErc677 is ERC677Bridge, BasicForeignBridgeErcToErc
|
|||
address _erc20token,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _gasPrice,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256[] _homeDailyLimitHomeMaxPerTxArray, // [ 0 = _homeDailyLimit, 1 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
|
||||
|
||||
require(
|
||||
_dailyLimitMaxPerTxMinPerTxArray[2] > 0 && // _minPerTx > 0
|
||||
_dailyLimitMaxPerTxMinPerTxArray[1] > _dailyLimitMaxPerTxMinPerTxArray[2] && // _maxPerTx > _minPerTx
|
||||
_dailyLimitMaxPerTxMinPerTxArray[0] > _dailyLimitMaxPerTxMinPerTxArray[1] // _dailyLimit > _maxPerTx
|
||||
);
|
||||
uint256[] memory _maxPerTxHomeDailyLimitHomeMaxPerTxArray = new uint256[](3);
|
||||
_maxPerTxHomeDailyLimitHomeMaxPerTxArray[0] = _dailyLimitMaxPerTxMinPerTxArray[1]; // _maxPerTx
|
||||
_maxPerTxHomeDailyLimitHomeMaxPerTxArray[1] = _homeDailyLimitHomeMaxPerTxArray[0]; // _homeDailyLimit
|
||||
_maxPerTxHomeDailyLimitHomeMaxPerTxArray[2] = _homeDailyLimitHomeMaxPerTxArray[1]; // _homeMaxPerTx
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_erc20token,
|
||||
_requiredBlockConfirmations,
|
||||
_gasPrice,
|
||||
_maxPerTx,
|
||||
_homeDailyLimit,
|
||||
_homeMaxPerTx,
|
||||
_owner
|
||||
_maxPerTxHomeDailyLimitHomeMaxPerTxArray, // [ 0 = _maxPerTx, 1 = _homeDailyLimit, 2 = _homeMaxPerTx ]
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimit;
|
||||
uintStorage[MIN_PER_TX] = _minPerTx;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimitMaxPerTxMinPerTxArray[0];
|
||||
uintStorage[MIN_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[2];
|
||||
|
||||
emit DailyLimitChanged(_dailyLimit);
|
||||
emit DailyLimitChanged(_dailyLimitMaxPerTxMinPerTxArray[0]);
|
||||
|
||||
return isInitialized();
|
||||
}
|
||||
|
|
|
@ -9,20 +9,18 @@ contract ForeignBridgeErcToErc is BasicForeignBridgeErcToErc, ERC20Bridge {
|
|||
address _erc20token,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _gasPrice,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _maxPerTxHomeDailyLimitHomeMaxPerTxArray, // [ 0 = _maxPerTx, 1 = _homeDailyLimit, 2 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_erc20token,
|
||||
_requiredBlockConfirmations,
|
||||
_gasPrice,
|
||||
_maxPerTx,
|
||||
_homeDailyLimit,
|
||||
_homeMaxPerTx,
|
||||
_owner
|
||||
_maxPerTxHomeDailyLimitHomeMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
return isInitialized();
|
||||
}
|
||||
|
|
|
@ -19,27 +19,23 @@ contract HomeBridgeErcToErc is
|
|||
|
||||
function initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _erc677token,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_erc677token,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
setInitialize();
|
||||
|
||||
|
@ -48,33 +44,27 @@ contract HomeBridgeErcToErc is
|
|||
|
||||
function rewardableInitialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _erc677token,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee,
|
||||
uint256 _foreignFee
|
||||
uint256[] _homeFeeForeignFeeArray, // [ 0 = _homeFee, 1 = _foreignFee ]
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_rewardableInitialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_erc677token,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_feeManager,
|
||||
_homeFee,
|
||||
_foreignFee
|
||||
_homeFeeForeignFeeArray,
|
||||
_decimalShift
|
||||
);
|
||||
setInitialize();
|
||||
|
||||
|
@ -83,71 +73,69 @@ contract HomeBridgeErcToErc is
|
|||
|
||||
function _rewardableInitialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _erc677token,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee,
|
||||
uint256 _foreignFee
|
||||
uint256[] _homeFeeForeignFeeArray, // [ 0 = _homeFee, 1 = _foreignFee ]
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_erc677token,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
require(AddressUtils.isContract(_feeManager));
|
||||
addressStorage[FEE_MANAGER_CONTRACT] = _feeManager;
|
||||
_setFee(_feeManager, _homeFee, HOME_FEE);
|
||||
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[0], HOME_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[1], FOREIGN_FEE);
|
||||
}
|
||||
|
||||
function _initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _erc677token,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_requiredBlockConfirmations > 0);
|
||||
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
|
||||
require(_foreignMaxPerTx < _foreignDailyLimit);
|
||||
require(
|
||||
_dailyLimitMaxPerTxMinPerTxArray[2] > 0 && // _minPerTx > 0
|
||||
_dailyLimitMaxPerTxMinPerTxArray[1] > _dailyLimitMaxPerTxMinPerTxArray[2] && // _maxPerTx > _minPerTx
|
||||
_dailyLimitMaxPerTxMinPerTxArray[0] > _dailyLimitMaxPerTxMinPerTxArray[1] // _dailyLimit > _maxPerTx
|
||||
);
|
||||
require(_foreignDailyLimitForeignMaxPerTxArray[1] < _foreignDailyLimitForeignMaxPerTxArray[0]); // _foreignMaxPerTx < _foreignDailyLimit
|
||||
require(_owner != address(0));
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimit;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[MIN_PER_TX] = _minPerTx;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimitMaxPerTxMinPerTxArray[0];
|
||||
uintStorage[MAX_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[1];
|
||||
uintStorage[MIN_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[2];
|
||||
uintStorage[GAS_PRICE] = _homeGasPrice;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignMaxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimitForeignMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignDailyLimitForeignMaxPerTxArray[1];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
setErc677token(_erc677token);
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_homeGasPrice);
|
||||
emit DailyLimitChanged(_dailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimit);
|
||||
emit DailyLimitChanged(_dailyLimitMaxPerTxMinPerTxArray[0]);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimitForeignMaxPerTxArray[0]);
|
||||
}
|
||||
|
||||
function claimTokensFromErc677(address _token, address _to) external onlyIfUpgradeabilityOwner {
|
||||
|
@ -160,7 +148,7 @@ contract HomeBridgeErcToErc is
|
|||
|
||||
function onExecuteAffirmation(address _recipient, uint256 _value, bytes32 txHash) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_value));
|
||||
uint256 valueToMint = _value;
|
||||
uint256 valueToMint = _value.mul(10 ** decimalShift());
|
||||
address feeManager = feeManagerContract();
|
||||
if (feeManager != address(0)) {
|
||||
uint256 fee = calculateFee(valueToMint, false, feeManager, FOREIGN_FEE);
|
||||
|
|
|
@ -8,34 +8,28 @@ contract HomeBridgeErcToErcPOSDAO is HomeBridgeErcToErc {
|
|||
|
||||
function rewardableInitialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _erc677token,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee,
|
||||
uint256 _foreignFee,
|
||||
address _blockReward
|
||||
uint256[] _homeFeeForeignFeeArray, // [ 0 = _homeFee, 1 = _foreignFee ]
|
||||
address _blockReward,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_rewardableInitialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_erc677token,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_feeManager,
|
||||
_homeFee,
|
||||
_foreignFee
|
||||
_homeFeeForeignFeeArray,
|
||||
_decimalShift
|
||||
);
|
||||
_setBlockRewardContract(_feeManager, _blockReward);
|
||||
setInitialize();
|
||||
|
|
|
@ -11,16 +11,15 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge {
|
|||
address _erc20token,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _gasPrice,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _maxPerTxHomeDailyLimitHomeMaxPerTxArray, //[ 0 = _maxPerTx, 1 = _homeDailyLimit, 2 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_requiredBlockConfirmations != 0);
|
||||
require(_gasPrice > 0);
|
||||
require(_homeMaxPerTx < _homeDailyLimit);
|
||||
require(_maxPerTxHomeDailyLimitHomeMaxPerTxArray[2] < _maxPerTxHomeDailyLimitHomeMaxPerTxArray[1]); // _homeMaxPerTx < _homeDailyLimit
|
||||
require(_owner != address(0));
|
||||
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
|
@ -28,15 +27,16 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge {
|
|||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
uintStorage[GAS_PRICE] = _gasPrice;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _homeDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _homeMaxPerTx;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[1];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _maxPerTxHomeDailyLimitHomeMaxPerTxArray[2];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
setInitialize();
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_gasPrice);
|
||||
emit ExecutionDailyLimitChanged(_homeDailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_maxPerTxHomeDailyLimitHomeMaxPerTxArray[1]);
|
||||
|
||||
return isInitialized();
|
||||
}
|
||||
|
@ -56,7 +56,8 @@ contract ForeignBridgeErcToNative is BasicForeignBridge, ERC20Bridge {
|
|||
bytes32 /*_txHash*/
|
||||
) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_amount));
|
||||
return erc20token().transfer(_recipient, _amount);
|
||||
uint256 amount = _amount.div(10 ** decimalShift());
|
||||
return erc20token().transfer(_recipient, amount);
|
||||
}
|
||||
|
||||
function onFailedMessage(address, uint256, bytes32) internal {
|
||||
|
|
|
@ -48,27 +48,23 @@ contract HomeBridgeErcToNative is
|
|||
|
||||
function initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _blockReward,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_blockReward,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
setInitialize();
|
||||
|
||||
|
@ -77,35 +73,30 @@ contract HomeBridgeErcToNative is
|
|||
|
||||
function rewardableInitialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _blockReward,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee,
|
||||
uint256 _foreignFee
|
||||
uint256[] _homeFeeForeignFeeArray, // [ 0 = _homeFee, 1 = _foreignFee ]
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_blockReward,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
require(AddressUtils.isContract(_feeManager));
|
||||
addressStorage[FEE_MANAGER_CONTRACT] = _feeManager;
|
||||
_setFee(_feeManager, _homeFee, HOME_FEE);
|
||||
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[0], HOME_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[1], FOREIGN_FEE);
|
||||
setInitialize();
|
||||
|
||||
return isInitialized();
|
||||
|
@ -129,48 +120,50 @@ contract HomeBridgeErcToNative is
|
|||
|
||||
function _initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
address _blockReward,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_requiredBlockConfirmations > 0);
|
||||
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
|
||||
require(
|
||||
_dailyLimitMaxPerTxMinPerTxArray[2] > 0 && // _minPerTx > 0
|
||||
_dailyLimitMaxPerTxMinPerTxArray[1] > _dailyLimitMaxPerTxMinPerTxArray[2] && // _maxPerTx > _minPerTx
|
||||
_dailyLimitMaxPerTxMinPerTxArray[0] > _dailyLimitMaxPerTxMinPerTxArray[1] // _dailyLimit > _maxPerTx
|
||||
);
|
||||
require(_blockReward == address(0) || AddressUtils.isContract(_blockReward));
|
||||
require(_foreignMaxPerTx < _foreignDailyLimit);
|
||||
require(_foreignDailyLimitForeignMaxPerTxArray[1] < _foreignDailyLimitForeignMaxPerTxArray[0]); // _foreignMaxPerTx < _foreignDailyLimit
|
||||
require(_owner != address(0));
|
||||
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimit;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[MIN_PER_TX] = _minPerTx;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimitMaxPerTxMinPerTxArray[0];
|
||||
uintStorage[MAX_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[1];
|
||||
uintStorage[MIN_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[2];
|
||||
uintStorage[GAS_PRICE] = _homeGasPrice;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
addressStorage[BLOCK_REWARD_CONTRACT] = _blockReward;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignMaxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimitForeignMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignDailyLimitForeignMaxPerTxArray[1];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_homeGasPrice);
|
||||
emit DailyLimitChanged(_dailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimit);
|
||||
emit DailyLimitChanged(_dailyLimitMaxPerTxMinPerTxArray[0]);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimitForeignMaxPerTxArray[0]);
|
||||
}
|
||||
|
||||
function onExecuteAffirmation(address _recipient, uint256 _value, bytes32 txHash) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_value));
|
||||
IBlockReward blockReward = blockRewardContract();
|
||||
require(blockReward != address(0));
|
||||
uint256 valueToMint = _value;
|
||||
|
||||
uint256 valueToMint = _value.mul(10 ** decimalShift());
|
||||
address feeManager = feeManagerContract();
|
||||
if (feeManager != address(0)) {
|
||||
uint256 fee = calculateFee(valueToMint, false, feeManager, FOREIGN_FEE);
|
||||
|
|
|
@ -5,25 +5,21 @@ import "./HomeBridgeNativeToErc.sol";
|
|||
contract ClassicHomeBridgeNativeToErc is HomeBridgeNativeToErc {
|
||||
function _initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
super._initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
uintStorage[keccak256(abi.encodePacked("dataSizes", bytes4(keccak256("signature(bytes32,uint256)"))))] = 132;
|
||||
uintStorage[keccak256(abi.encodePacked("dataSizes", bytes4(keccak256("message(bytes32)"))))] = 210;
|
||||
|
|
|
@ -17,26 +17,22 @@ contract ForeignBridgeNativeToErc is
|
|||
function initialize(
|
||||
address _validatorContract,
|
||||
address _erc677token,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _foreignGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _homeDailyLimitHomeMaxPerTxArray, // [ 0 = _homeDailyLimit, 1 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_erc677token,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_foreignGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_homeDailyLimit,
|
||||
_homeMaxPerTx,
|
||||
_owner
|
||||
_homeDailyLimitHomeMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
setInitialize();
|
||||
return isInitialized();
|
||||
|
@ -45,28 +41,24 @@ contract ForeignBridgeNativeToErc is
|
|||
function rewardableInitialize(
|
||||
address _validatorContract,
|
||||
address _erc677token,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _foreignGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
uint256[] _homeDailyLimitHomeMaxPerTxArray, // [ 0 = _homeDailyLimit, 1 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee
|
||||
uint256 _homeFee,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_erc677token,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_foreignGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_homeDailyLimit,
|
||||
_homeMaxPerTx,
|
||||
_owner
|
||||
_homeDailyLimitHomeMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
require(AddressUtils.isContract(_feeManager));
|
||||
addressStorage[FEE_MANAGER_CONTRACT] = _feeManager;
|
||||
|
@ -86,44 +78,47 @@ contract ForeignBridgeNativeToErc is
|
|||
function _initialize(
|
||||
address _validatorContract,
|
||||
address _erc677token,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _foreignGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _homeDailyLimit,
|
||||
uint256 _homeMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _homeDailyLimitHomeMaxPerTxArray, // [ 0 = _homeDailyLimit, 1 = _homeMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
|
||||
require(
|
||||
_dailyLimitMaxPerTxMinPerTxArray[2] > 0 && // _minPerTx > 0
|
||||
_dailyLimitMaxPerTxMinPerTxArray[1] > _dailyLimitMaxPerTxMinPerTxArray[2] && // _maxPerTx > _minPerTx
|
||||
_dailyLimitMaxPerTxMinPerTxArray[0] > _dailyLimitMaxPerTxMinPerTxArray[1] // _dailyLimit > _maxPerTx
|
||||
);
|
||||
require(_requiredBlockConfirmations > 0);
|
||||
require(_foreignGasPrice > 0);
|
||||
require(_homeMaxPerTx < _homeDailyLimit);
|
||||
require(_homeDailyLimitHomeMaxPerTxArray[1] < _homeDailyLimitHomeMaxPerTxArray[0]); // _homeMaxPerTx < _homeDailyLimit
|
||||
require(_owner != address(0));
|
||||
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
setErc677token(_erc677token);
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimit;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimitMaxPerTxMinPerTxArray[0];
|
||||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[MIN_PER_TX] = _minPerTx;
|
||||
uintStorage[MAX_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[1];
|
||||
uintStorage[MIN_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[2];
|
||||
uintStorage[GAS_PRICE] = _foreignGasPrice;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _homeDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _homeMaxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _homeDailyLimitHomeMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _homeDailyLimitHomeMaxPerTxArray[1];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_foreignGasPrice);
|
||||
emit DailyLimitChanged(_dailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_homeDailyLimit);
|
||||
emit DailyLimitChanged(_dailyLimitMaxPerTxMinPerTxArray[0]);
|
||||
emit ExecutionDailyLimitChanged(_homeDailyLimitHomeMaxPerTxArray[0]);
|
||||
}
|
||||
|
||||
function onExecuteMessage(address _recipient, uint256 _amount, bytes32 _txHash) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_amount));
|
||||
uint256 valueToMint = _amount;
|
||||
uint256 valueToMint = _amount.div(10 ** decimalShift());
|
||||
address feeManager = feeManagerContract();
|
||||
if (feeManager != address(0)) {
|
||||
uint256 fee = calculateFee(valueToMint, false, feeManager, HOME_FEE);
|
||||
|
|
|
@ -27,25 +27,21 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
|
|||
|
||||
function initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
setInitialize();
|
||||
return isInitialized();
|
||||
|
@ -53,33 +49,28 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
|
|||
|
||||
function rewardableInitialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
address _feeManager,
|
||||
uint256 _homeFee,
|
||||
uint256 _foreignFee
|
||||
uint256[] _homeFeeForeignFeeArray, // [ 0 = _homeFee, 1 = _foreignFee ]
|
||||
uint256 _decimalShift
|
||||
) external returns (bool) {
|
||||
_initialize(
|
||||
_validatorContract,
|
||||
_dailyLimit,
|
||||
_maxPerTx,
|
||||
_minPerTx,
|
||||
_dailyLimitMaxPerTxMinPerTxArray,
|
||||
_homeGasPrice,
|
||||
_requiredBlockConfirmations,
|
||||
_foreignDailyLimit,
|
||||
_foreignMaxPerTx,
|
||||
_owner
|
||||
_foreignDailyLimitForeignMaxPerTxArray,
|
||||
_owner,
|
||||
_decimalShift
|
||||
);
|
||||
require(AddressUtils.isContract(_feeManager));
|
||||
addressStorage[FEE_MANAGER_CONTRACT] = _feeManager;
|
||||
_setFee(_feeManager, _homeFee, HOME_FEE);
|
||||
_setFee(_feeManager, _foreignFee, FOREIGN_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[0], HOME_FEE);
|
||||
_setFee(_feeManager, _homeFeeForeignFeeArray[1], FOREIGN_FEE);
|
||||
setInitialize();
|
||||
return isInitialized();
|
||||
}
|
||||
|
@ -90,38 +81,41 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
|
|||
|
||||
function _initialize(
|
||||
address _validatorContract,
|
||||
uint256 _dailyLimit,
|
||||
uint256 _maxPerTx,
|
||||
uint256 _minPerTx,
|
||||
uint256[] _dailyLimitMaxPerTxMinPerTxArray, // [ 0 = _dailyLimit, 1 = _maxPerTx, 2 = _minPerTx ]
|
||||
uint256 _homeGasPrice,
|
||||
uint256 _requiredBlockConfirmations,
|
||||
uint256 _foreignDailyLimit,
|
||||
uint256 _foreignMaxPerTx,
|
||||
address _owner
|
||||
uint256[] _foreignDailyLimitForeignMaxPerTxArray, // [ 0 = _foreignDailyLimit, 1 = _foreignMaxPerTx ]
|
||||
address _owner,
|
||||
uint256 _decimalShift
|
||||
) internal {
|
||||
require(!isInitialized());
|
||||
require(AddressUtils.isContract(_validatorContract));
|
||||
require(_homeGasPrice > 0);
|
||||
require(_requiredBlockConfirmations > 0);
|
||||
require(_minPerTx > 0 && _maxPerTx > _minPerTx && _dailyLimit > _maxPerTx);
|
||||
require(_foreignMaxPerTx < _foreignDailyLimit);
|
||||
require(
|
||||
_dailyLimitMaxPerTxMinPerTxArray[2] > 0 && // _minPerTx > 0
|
||||
_dailyLimitMaxPerTxMinPerTxArray[1] > _dailyLimitMaxPerTxMinPerTxArray[2] && // _maxPerTx > _minPerTx
|
||||
_dailyLimitMaxPerTxMinPerTxArray[0] > _dailyLimitMaxPerTxMinPerTxArray[1] // _dailyLimit > _maxPerTx
|
||||
);
|
||||
require(_foreignDailyLimitForeignMaxPerTxArray[1] < _foreignDailyLimitForeignMaxPerTxArray[0]); // _foreignMaxPerTx < _foreignDailyLimit
|
||||
require(_owner != address(0));
|
||||
|
||||
addressStorage[VALIDATOR_CONTRACT] = _validatorContract;
|
||||
uintStorage[DEPLOYED_AT_BLOCK] = block.number;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimit;
|
||||
uintStorage[MAX_PER_TX] = _maxPerTx;
|
||||
uintStorage[MIN_PER_TX] = _minPerTx;
|
||||
uintStorage[DAILY_LIMIT] = _dailyLimitMaxPerTxMinPerTxArray[0];
|
||||
uintStorage[MAX_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[1];
|
||||
uintStorage[MIN_PER_TX] = _dailyLimitMaxPerTxMinPerTxArray[2];
|
||||
uintStorage[GAS_PRICE] = _homeGasPrice;
|
||||
uintStorage[REQUIRED_BLOCK_CONFIRMATIONS] = _requiredBlockConfirmations;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimit;
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignMaxPerTx;
|
||||
uintStorage[EXECUTION_DAILY_LIMIT] = _foreignDailyLimitForeignMaxPerTxArray[0];
|
||||
uintStorage[EXECUTION_MAX_PER_TX] = _foreignDailyLimitForeignMaxPerTxArray[1];
|
||||
uintStorage[DECIMAL_SHIFT] = _decimalShift;
|
||||
setOwner(_owner);
|
||||
|
||||
emit RequiredBlockConfirmationChanged(_requiredBlockConfirmations);
|
||||
emit GasPriceChanged(_homeGasPrice);
|
||||
emit DailyLimitChanged(_dailyLimit);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimit);
|
||||
emit DailyLimitChanged(_dailyLimitMaxPerTxMinPerTxArray[0]);
|
||||
emit ExecutionDailyLimitChanged(_foreignDailyLimitForeignMaxPerTxArray[0]);
|
||||
}
|
||||
|
||||
function onSignaturesCollected(bytes _message) internal {
|
||||
|
@ -141,7 +135,7 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicHomeBridge, RewardableHom
|
|||
|
||||
function onExecuteAffirmation(address _recipient, uint256 _value, bytes32 txHash) internal returns (bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_value));
|
||||
uint256 valueToTransfer = _value;
|
||||
uint256 valueToTransfer = _value.mul(10 ** decimalShift());
|
||||
|
||||
address feeManager = feeManagerContract();
|
||||
if (feeManager != address(0)) {
|
||||
|
|
|
@ -65,3 +65,6 @@ FOREIGN_TRANSACTIONS_FEE=0.001
|
|||
#for bridge native_to_erc, erc_to_erc mode
|
||||
DEPLOY_REWARDABLE_TOKEN=false
|
||||
DPOS_STAKING_ADDRESS=
|
||||
|
||||
#If decimals are different between foreign and home chain, number of decimals shift required to adjust the amount of tokens bridged. Default value is 0.
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT=
|
||||
|
|
|
@ -37,11 +37,14 @@ const {
|
|||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
ERC20_EXTENDED_BY_ERC677
|
||||
ERC20_EXTENDED_BY_ERC677,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
||||
console.log(`Foreign Validators: ${validatorsBridge.options.address},
|
||||
ERC20_TOKEN_ADDRESS: ${ERC20_TOKEN_ADDRESS},
|
||||
|
@ -53,7 +56,8 @@ async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
|||
HOME_MAX_AMOUNT_PER_TX: ${HOME_MAX_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
HOME_MAX_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER}
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
let initializeFBridgeData
|
||||
|
||||
|
@ -64,12 +68,10 @@ async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
|||
ERC20_TOKEN_ADDRESS,
|
||||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
FOREIGN_GAS_PRICE,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_BRIDGE_OWNER
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
|
||||
FOREIGN_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
} else {
|
||||
|
@ -79,10 +81,9 @@ async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
|||
ERC20_TOKEN_ADDRESS,
|
||||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
FOREIGN_GAS_PRICE,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_BRIDGE_OWNER
|
||||
[FOREIGN_MAX_AMOUNT_PER_TX, HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
|
||||
FOREIGN_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
}
|
||||
|
|
|
@ -52,11 +52,14 @@ const {
|
|||
DPOS_STAKING_ADDRESS,
|
||||
HOME_REWARDABLE,
|
||||
HOME_TRANSACTIONS_FEE,
|
||||
FOREIGN_TRANSACTIONS_FEE
|
||||
FOREIGN_TRANSACTIONS_FEE,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
const isRewardableBridge = HOME_REWARDABLE === 'BOTH_DIRECTIONS'
|
||||
|
||||
let VALIDATORS_REWARD_ACCOUNTS = []
|
||||
|
@ -97,19 +100,16 @@ async function initializeBridge({ validatorsBridge, bridge, erc677token, initial
|
|||
initializeHomeBridgeData = await bridge.methods
|
||||
.rewardableInitialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
erc677token.options.address,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
feeManager.options.address,
|
||||
homeFeeInWei,
|
||||
foreignFeeInWei,
|
||||
BLOCK_REWARD_ADDRESS
|
||||
[homeFeeInWei, foreignFeeInWei],
|
||||
BLOCK_REWARD_ADDRESS,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
} else {
|
||||
|
@ -121,20 +121,19 @@ async function initializeBridge({ validatorsBridge, bridge, erc677token, initial
|
|||
HOME_MIN_AMOUNT_PER_TX: ${HOME_MIN_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
HOME_MIN_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
HOME_GAS_PRICE: ${HOME_GAS_PRICE}, HOME_REQUIRED_BLOCK_CONFIRMATIONS : ${HOME_REQUIRED_BLOCK_CONFIRMATIONS}
|
||||
HOME_GAS_PRICE: ${HOME_GAS_PRICE}, HOME_REQUIRED_BLOCK_CONFIRMATIONS : ${HOME_REQUIRED_BLOCK_CONFIRMATIONS},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
initializeHomeBridgeData = await bridge.methods
|
||||
.initialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
erc677token.options.address,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_BRIDGE_OWNER
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
}
|
||||
|
|
|
@ -33,11 +33,14 @@ const {
|
|||
ERC20_TOKEN_ADDRESS,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
||||
console.log(`Foreign Validators: ${validatorsBridge.options.address},
|
||||
ERC20_TOKEN_ADDRESS: ${ERC20_TOKEN_ADDRESS},
|
||||
|
@ -49,7 +52,8 @@ async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
|||
HOME_MAX_AMOUNT_PER_TX: ${HOME_MAX_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
HOME_MAX_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER}
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
const initializeFBridgeData = await bridge.methods
|
||||
.initialize(
|
||||
|
@ -57,10 +61,9 @@ async function initializeBridge({ validatorsBridge, bridge, nonce }) {
|
|||
ERC20_TOKEN_ADDRESS,
|
||||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
FOREIGN_GAS_PRICE,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_BRIDGE_OWNER
|
||||
[FOREIGN_MAX_AMOUNT_PER_TX, HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
|
||||
FOREIGN_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift,
|
||||
)
|
||||
.encodeABI()
|
||||
const txInitializeBridge = await sendRawTxForeign({
|
||||
|
|
|
@ -42,11 +42,14 @@ const {
|
|||
HOME_REWARDABLE,
|
||||
HOME_TRANSACTIONS_FEE,
|
||||
FOREIGN_TRANSACTIONS_FEE,
|
||||
HOME_FEE_MANAGER_TYPE
|
||||
HOME_FEE_MANAGER_TYPE,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
const isRewardableBridge = HOME_REWARDABLE === 'BOTH_DIRECTIONS'
|
||||
const isFeeManagerPOSDAO = HOME_FEE_MANAGER_TYPE === 'POSDAO_REWARD'
|
||||
|
||||
|
@ -94,22 +97,20 @@ async function initializeBridge({ validatorsBridge, bridge, initialNonce }) {
|
|||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER},
|
||||
Fee Manager: ${feeManager.options.address},
|
||||
Home Fee: ${homeFeeInWei} which is ${HOME_TRANSACTIONS_FEE * 100}%
|
||||
Foreign Fee: ${foreignFeeInWei} which is ${FOREIGN_TRANSACTIONS_FEE * 100}%`)
|
||||
Foreign Fee: ${foreignFeeInWei} which is ${FOREIGN_TRANSACTIONS_FEE * 100}%,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}`)
|
||||
initializeHomeBridgeData = await bridge.methods
|
||||
.rewardableInitialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
BLOCK_REWARD_ADDRESS,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
feeManager.options.address,
|
||||
homeFeeInWei,
|
||||
foreignFeeInWei
|
||||
[homeFeeInWei, foreignFeeInWei],
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
} else {
|
||||
|
@ -130,20 +131,19 @@ async function initializeBridge({ validatorsBridge, bridge, initialNonce }) {
|
|||
FOREIGN_MAX_AMOUNT_PER_TX: ${FOREIGN_MAX_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
FOREIGN_MAX_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER}
|
||||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
initializeHomeBridgeData = await bridge.methods
|
||||
.initialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
BLOCK_REWARD_ADDRESS,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_BRIDGE_OWNER
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
}
|
||||
|
|
|
@ -48,11 +48,14 @@ const {
|
|||
BLOCK_REWARD_ADDRESS,
|
||||
DPOS_STAKING_ADDRESS,
|
||||
FOREIGN_REWARDABLE,
|
||||
HOME_TRANSACTIONS_FEE
|
||||
HOME_TRANSACTIONS_FEE,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
const isRewardableBridge = FOREIGN_REWARDABLE === 'ONE_DIRECTION'
|
||||
|
||||
let VALIDATORS_REWARD_ACCOUNTS = []
|
||||
|
@ -95,22 +98,21 @@ async function initializeBridge({ validatorsBridge, bridge, erc677bridgeToken, i
|
|||
)} in eth,
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER},
|
||||
Fee Manager: ${feeManager.options.address},
|
||||
Home Fee: ${homeFeeInWei} which is ${HOME_TRANSACTIONS_FEE * 100}%`)
|
||||
Home Fee: ${homeFeeInWei} which is ${HOME_TRANSACTIONS_FEE * 100}%,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}`)
|
||||
|
||||
initializeFBridgeData = await bridge.methods
|
||||
.rewardableInitialize(
|
||||
validatorsBridge.options.address,
|
||||
erc677bridgeToken.options.address,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
|
||||
FOREIGN_GAS_PRICE,
|
||||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
|
||||
FOREIGN_BRIDGE_OWNER,
|
||||
feeManager.options.address,
|
||||
homeFeeInWei
|
||||
homeFeeInWei,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI({ from: DEPLOYMENT_ACCOUNT_ADDRESS })
|
||||
} else {
|
||||
|
@ -130,21 +132,20 @@ async function initializeBridge({ validatorsBridge, bridge, erc677bridgeToken, i
|
|||
HOME_MAX_AMOUNT_PER_TX: ${HOME_MAX_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
HOME_MAX_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER}
|
||||
FOREIGN_BRIDGE_OWNER: ${FOREIGN_BRIDGE_OWNER},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
|
||||
initializeFBridgeData = await bridge.methods
|
||||
.initialize(
|
||||
validatorsBridge.options.address,
|
||||
erc677bridgeToken.options.address,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
|
||||
FOREIGN_GAS_PRICE,
|
||||
FOREIGN_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_BRIDGE_OWNER
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX],
|
||||
FOREIGN_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI({ from: DEPLOYMENT_ACCOUNT_ADDRESS })
|
||||
}
|
||||
|
|
|
@ -40,11 +40,14 @@ const {
|
|||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_REWARDABLE,
|
||||
HOME_TRANSACTIONS_FEE,
|
||||
FOREIGN_TRANSACTIONS_FEE
|
||||
FOREIGN_TRANSACTIONS_FEE,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT
|
||||
} = env
|
||||
|
||||
const DEPLOYMENT_ACCOUNT_ADDRESS = privateKeyToAddress(DEPLOYMENT_ACCOUNT_PRIVATE_KEY)
|
||||
|
||||
const foreignToHomeDecimalShift=FOREIGN_TO_HOME_DECIMAL_SHIFT?FOREIGN_TO_HOME_DECIMAL_SHIFT:0
|
||||
|
||||
const isBothDirectionsFeeManager = HOME_REWARDABLE === 'BOTH_DIRECTIONS'
|
||||
const isRewardableBridge = HOME_REWARDABLE === 'ONE_DIRECTION' || isBothDirectionsFeeManager
|
||||
|
||||
|
@ -93,22 +96,20 @@ async function initializeBridge({ validatorsBridge, bridge, initialNonce }) {
|
|||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER},
|
||||
Fee Manager: ${feeManager.options.address},
|
||||
Home Fee: ${homeFeeInWei} which is ${homeFee * 100}%
|
||||
Foreign Fee: ${foreignFeeInWei} which is ${FOREIGN_TRANSACTIONS_FEE * 100}%`)
|
||||
Foreign Fee: ${foreignFeeInWei} which is ${FOREIGN_TRANSACTIONS_FEE * 100}%,
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}`)
|
||||
|
||||
initializeHomeBridgeData = await bridge.methods
|
||||
.rewardableInitialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
feeManager.options.address,
|
||||
homeFeeInWei,
|
||||
foreignFeeInWei
|
||||
[homeFeeInWei, foreignFeeInWei],
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
} else {
|
||||
|
@ -128,19 +129,18 @@ async function initializeBridge({ validatorsBridge, bridge, initialNonce }) {
|
|||
FOREIGN_MAX_AMOUNT_PER_TX: ${FOREIGN_MAX_AMOUNT_PER_TX} which is ${Web3Utils.fromWei(
|
||||
FOREIGN_MAX_AMOUNT_PER_TX
|
||||
)} in eth,
|
||||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER}
|
||||
HOME_BRIDGE_OWNER: ${HOME_BRIDGE_OWNER},
|
||||
FOREIGN_TO_HOME_DECIMAL_SHIFT: ${foreignToHomeDecimalShift}
|
||||
`)
|
||||
initializeHomeBridgeData = await bridge.methods
|
||||
.initialize(
|
||||
validatorsBridge.options.address,
|
||||
HOME_DAILY_LIMIT,
|
||||
HOME_MAX_AMOUNT_PER_TX,
|
||||
HOME_MIN_AMOUNT_PER_TX,
|
||||
[HOME_DAILY_LIMIT, HOME_MAX_AMOUNT_PER_TX, HOME_MIN_AMOUNT_PER_TX],
|
||||
HOME_GAS_PRICE,
|
||||
HOME_REQUIRED_BLOCK_CONFIRMATIONS,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
HOME_BRIDGE_OWNER
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX],
|
||||
HOME_BRIDGE_OWNER,
|
||||
foreignToHomeDecimalShift
|
||||
)
|
||||
.encodeABI()
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ const maxPerTx = halfEther
|
|||
const minPerTx = ether('0.01')
|
||||
const dailyLimit = oneEther
|
||||
const ZERO = toBN(0)
|
||||
const decimalShiftZero = 0
|
||||
|
||||
contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
||||
let validatorContract
|
||||
|
@ -41,6 +42,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(await foreignBridge.validatorContract()).to.be.equal(ZERO_ADDRESS)
|
||||
expect(await foreignBridge.deployedAtBlock()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.isInitialized()).to.be.equal(false)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(ZERO)
|
||||
|
||||
await foreignBridge
|
||||
|
@ -49,10 +51,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -61,10 +62,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
ZERO_ADDRESS,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -73,10 +73,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
owner,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -85,10 +84,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
0,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -97,10 +95,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
0,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -109,10 +106,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
|
@ -121,10 +117,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
'9'
|
||||
)
|
||||
|
||||
expect(await foreignBridge.erc20token()).to.be.equal(token.address)
|
||||
|
@ -134,6 +129,7 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(
|
||||
requireBlockConfirmations.toString()
|
||||
)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal('9')
|
||||
expect(await foreignBridge.gasPrice()).to.be.bignumber.equal(gasPrice)
|
||||
const bridgeMode = '0xba4690f5' // 4 bytes of keccak256('erc-to-erc-core')
|
||||
expect(await foreignBridge.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
|
@ -161,10 +157,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(foreignBridge.address, value)
|
||||
})
|
||||
|
@ -293,10 +288,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero,
|
||||
{ from: ownerOfValidatorContract }
|
||||
)
|
||||
await token.mint(foreignBridgeWithMultiSignatures.address, value)
|
||||
|
@ -354,10 +348,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
erc20Token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await erc20Token.mint(foreignBridgeWithThreeSigs.address, value)
|
||||
|
||||
|
@ -415,10 +408,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
// Deploy V2
|
||||
|
@ -439,7 +431,15 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
|
||||
const foreignBridge = await ForeignBridge.new()
|
||||
const data = foreignBridge.contract.methods
|
||||
.initialize(validatorsAddress, tokenAddress, requireBlockConfirmations, gasPrice, '2', '3', '2', owner)
|
||||
.initialize(
|
||||
validatorsAddress,
|
||||
tokenAddress,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
['2', '3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', foreignBridge.address, data).should.be.fulfilled
|
||||
const finalContract = await ForeignBridge.at(storageProxy.address)
|
||||
|
@ -460,10 +460,9 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
const tokenSecond = await ERC677BridgeToken.new('Roman Token', 'RST', 18)
|
||||
|
@ -493,12 +492,10 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
dailyLimit,
|
||||
maxPerTx,
|
||||
minPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
expectEventInLogs(logs, 'RequiredBlockConfirmationChanged', {
|
||||
|
@ -518,12 +515,10 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
dailyLimit,
|
||||
maxPerTx,
|
||||
minPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await token.mint(user, halfEther, { from: owner }).should.be.fulfilled
|
||||
|
@ -550,12 +545,10 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
dailyLimit,
|
||||
maxPerTx,
|
||||
minPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await token.mint(user, valueMoreThanLimit, { from: owner }).should.be.fulfilled
|
||||
|
@ -587,12 +580,10 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
dailyLimit,
|
||||
maxPerTx,
|
||||
minPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await token.mint(user, oneEther.add(toBN(1)), { from: owner }).should.be.fulfilled
|
||||
|
@ -630,12 +621,10 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
dailyLimit,
|
||||
maxPerTx,
|
||||
minPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await token.mint(user, oneEther, { from: owner }).should.be.fulfilled
|
||||
|
@ -658,4 +647,130 @@ contract('ForeignBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(toBN(events[0].returnValues.value)).to.be.bignumber.equal(minPerTx)
|
||||
})
|
||||
})
|
||||
describe('#decimalShift', async () => {
|
||||
const decimalShiftTwo = 2
|
||||
it('Home to Foreign: withdraw with 1 signature with a decimalShift of 2', async () => {
|
||||
const valueOnForeign = toBN('1000')
|
||||
// Value is decimals shifted from foreign to home: Native on home = 16+2 shift = 18 decimals
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const foreignBridge = await ForeignBridge.new()
|
||||
token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 16)
|
||||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await token.mint(foreignBridge.address, valueOnForeign)
|
||||
|
||||
const recipientAccount = accounts[3]
|
||||
const balanceBefore = await token.balanceOf(recipientAccount)
|
||||
|
||||
const transactionHash = '0x1045bfe274b88120a6b1e5d01b5ec00ab5d01098346e90e7c7a3c9b8f0181c80'
|
||||
const message = createMessage(recipientAccount, valueOnHome, transactionHash, foreignBridge.address)
|
||||
const signature = await sign(authorities[0], message)
|
||||
const vrs = signatureToVRS(signature)
|
||||
false.should.be.equal(await foreignBridge.relayedMessages(transactionHash))
|
||||
const { logs } = await foreignBridge.executeSignatures([vrs.v], [vrs.r], [vrs.s], message).should.be.fulfilled
|
||||
logs[0].event.should.be.equal('RelayedMessage')
|
||||
logs[0].args.recipient.should.be.equal(recipientAccount)
|
||||
logs[0].args.value.should.be.bignumber.equal(valueOnHome)
|
||||
|
||||
const balanceAfter = await token.balanceOf(recipientAccount)
|
||||
const balanceAfterBridge = await token.balanceOf(foreignBridge.address)
|
||||
balanceAfter.should.be.bignumber.equal(balanceBefore.add(valueOnForeign))
|
||||
balanceAfterBridge.should.be.bignumber.equal(ZERO)
|
||||
true.should.be.equal(await foreignBridge.relayedMessages(transactionHash))
|
||||
})
|
||||
it('Home to Foreign : withdraw works with 5 validators and 3 required signatures with a decimalShift of 2', async () => {
|
||||
const valueOnForeign = toBN('1000')
|
||||
// Value is decimals shifted from foreign to home: Native on home = 16+2 shift = 18 decimals
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const recipient = accounts[8]
|
||||
const authoritiesFiveAccs = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]]
|
||||
const ownerOfValidators = accounts[0]
|
||||
const validatorContractWith3Signatures = await BridgeValidators.new()
|
||||
await validatorContractWith3Signatures.initialize(3, authoritiesFiveAccs, ownerOfValidators)
|
||||
const erc20Token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 16)
|
||||
|
||||
const foreignBridgeWithThreeSigs = await ForeignBridge.new()
|
||||
|
||||
await foreignBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
erc20Token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await erc20Token.mint(foreignBridgeWithThreeSigs.address, valueOnForeign)
|
||||
|
||||
const balanceBeforeRecipient = await erc20Token.balanceOf(recipient)
|
||||
const balanceBeforeBridge = await erc20Token.balanceOf(foreignBridgeWithThreeSigs.address)
|
||||
|
||||
const txHash = '0x35d3818e50234655f6aebb2a1cfbf30f59568d8a4ec72066fac5a25dbe7b8121'
|
||||
const message = createMessage(recipient, valueOnHome, txHash, foreignBridgeWithThreeSigs.address)
|
||||
|
||||
// signature 1
|
||||
const signature = await sign(authoritiesFiveAccs[0], message)
|
||||
const vrs = signatureToVRS(signature)
|
||||
|
||||
// signature 2
|
||||
const signature2 = await sign(authoritiesFiveAccs[1], message)
|
||||
const vrs2 = signatureToVRS(signature2)
|
||||
|
||||
// signature 3
|
||||
const signature3 = await sign(authoritiesFiveAccs[2], message)
|
||||
const vrs3 = signatureToVRS(signature3)
|
||||
|
||||
const { logs } = await foreignBridgeWithThreeSigs.executeSignatures(
|
||||
[vrs.v, vrs2.v, vrs3.v],
|
||||
[vrs.r, vrs2.r, vrs3.r],
|
||||
[vrs.s, vrs2.s, vrs3.s],
|
||||
message
|
||||
).should.be.fulfilled
|
||||
logs[0].event.should.be.equal('RelayedMessage')
|
||||
logs[0].args.recipient.should.be.equal(recipient)
|
||||
logs[0].args.value.should.be.bignumber.equal(valueOnHome)
|
||||
true.should.be.equal(await foreignBridgeWithThreeSigs.relayedMessages(txHash))
|
||||
const balanceAfterRecipient = await erc20Token.balanceOf(recipient)
|
||||
balanceAfterRecipient.should.be.bignumber.equal(balanceBeforeRecipient.add(valueOnForeign))
|
||||
const balanceAfterBridge = await erc20Token.balanceOf(foreignBridgeWithThreeSigs.address)
|
||||
balanceBeforeBridge.should.be.bignumber.equal(balanceAfterBridge.add(valueOnForeign))
|
||||
})
|
||||
it('Foreign to Home: no impact in UserRequestForAffirmation event signal for bridges oracles with a decimalShift of 2.', async () => {
|
||||
const value = halfEther
|
||||
const owner = accounts[3]
|
||||
const user = accounts[4]
|
||||
token = await ERC677BridgeToken.new('TEST', 'TST', 16, { from: owner })
|
||||
const foreignBridge = await ForeignBridgeErc677ToErc677.new()
|
||||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
[dailyLimit, maxPerTx, minPerTx],
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
|
||||
await token.mint(user, value, { from: owner }).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address, { from: owner })
|
||||
await foreignBridge.onTokenTransfer(user, value, '0x00', { from: owner }).should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
await token.transferAndCall(foreignBridge.address, value, '0x00', { from: user }).should.be.fulfilled
|
||||
expect(await token.totalSupply()).to.be.bignumber.equal(value)
|
||||
expect(await token.balanceOf(user)).to.be.bignumber.equal(ZERO)
|
||||
expect(await token.balanceOf(foreignBridge.address)).to.be.bignumber.equal(value)
|
||||
|
||||
const events = await getEvents(foreignBridge, { event: 'UserRequestForAffirmation' })
|
||||
expect(events[0].returnValues.recipient).to.be.equal(user)
|
||||
expect(toBN(events[0].returnValues.value)).to.be.bignumber.equal(value)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -22,6 +22,7 @@ const halfEther = ether('0.5')
|
|||
const foreignDailyLimit = oneEther
|
||||
const foreignMaxPerTx = halfEther
|
||||
const ZERO = toBN(0)
|
||||
const decimalShiftZero = 0
|
||||
const markedAsProcessed = toBN(2)
|
||||
.pow(toBN(255))
|
||||
.add(toBN(1))
|
||||
|
@ -48,19 +49,18 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(await homeContract.deployedAtBlock()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.dailyLimit()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.maxPerTx()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.isInitialized()).to.be.equal(false)
|
||||
|
||||
const { logs } = await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
'9'
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.isInitialized()).to.be.equal(true)
|
||||
|
@ -69,6 +69,7 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(await homeContract.dailyLimit()).to.be.bignumber.equal('3')
|
||||
expect(await homeContract.maxPerTx()).to.be.bignumber.equal('2')
|
||||
expect(await homeContract.minPerTx()).to.be.bignumber.equal('1')
|
||||
expect(await homeContract.decimalShift()).to.be.bignumber.equal('9')
|
||||
const bridgeMode = '0xba4690f5' // 4 bytes of keccak256('erc-to-erc-core')
|
||||
expect(await homeContract.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
const { major, minor, patch } = await homeContract.getBridgeInterfacesVersion()
|
||||
|
@ -89,29 +90,25 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'1',
|
||||
'2',
|
||||
'1',
|
||||
['1', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'2',
|
||||
['3', '2', '2'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
|
@ -123,15 +120,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const data = homeContract.contract.methods
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
'3',
|
||||
'2',
|
||||
owner
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', homeContract.address, data).should.be.fulfilled
|
||||
|
@ -150,98 +145,84 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
0,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
owner,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
ZERO_ADDRESS,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
ZERO_ADDRESS,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
owner,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
halfEther,
|
||||
oneEther,
|
||||
owner
|
||||
[halfEther, oneEther],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.isInitialized()).to.be.equal(true)
|
||||
|
@ -253,15 +234,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
// When
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
0,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
|
@ -275,15 +254,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 18)
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('reverts', async () => {
|
||||
|
@ -303,15 +280,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 18)
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('#setMaxPerTx allows to set only to owner and cannot be more than daily limit', async () => {
|
||||
|
@ -336,15 +311,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 18)
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(homeBridge.address)
|
||||
})
|
||||
|
@ -423,15 +396,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token2sig.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token2sig.transferOwnership(homeBridgeWithTwoSigs.address)
|
||||
const recipient = accounts[5]
|
||||
|
@ -510,15 +481,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token2sig.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token2sig.transferOwnership(homeBridgeWithTwoSigs.address)
|
||||
const recipient = accounts[5]
|
||||
|
@ -554,15 +523,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(homeBridgeWithThreeSigs.address)
|
||||
|
||||
|
@ -712,15 +679,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token2sig.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token2sig.transferOwnership(homeBridgeWithTwoSigs.address)
|
||||
})
|
||||
|
@ -784,15 +749,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
const value = ether('0.5')
|
||||
|
@ -893,15 +856,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
homeBridge = await HomeBridge.at(storageProxy.address)
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
})
|
||||
it('Should revert if value to unlock is bigger than max per transaction', async () => {
|
||||
|
@ -1167,15 +1128,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const homeBridge = await HomeBridge.at(storageProxy.address)
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
await token.transferOwnership(homeBridge.address).should.be.fulfilled
|
||||
|
@ -1225,67 +1184,55 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
ZERO_ADDRESS,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.rejected
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
0,
|
||||
foreignDailyLimit,
|
||||
[0, foreignDailyLimit],
|
||||
token.address,
|
||||
foreignMaxPerTx,
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.rejected
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
ZERO_ADDRESS,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.rejected
|
||||
const { logs } = await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
'9'
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeBridge.isInitialized()).to.be.equal(true)
|
||||
|
@ -1294,6 +1241,7 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
expect(await homeBridge.dailyLimit()).to.be.bignumber.equal(oneEther)
|
||||
expect(await homeBridge.maxPerTx()).to.be.bignumber.equal(halfEther)
|
||||
expect(await homeBridge.minPerTx()).to.be.bignumber.equal(minPerTx)
|
||||
expect(await homeBridge.decimalShift()).to.be.bignumber.equal('9')
|
||||
const bridgeMode = '0xba4690f5' // 4 bytes of keccak256('erc-to-erc-core')
|
||||
expect(await homeBridge.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
const { major, minor, patch } = await homeBridge.getBridgeInterfacesVersion()
|
||||
|
@ -1321,19 +1269,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const feeManager = await FeeManagerErcToErcPOSDAO.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1350,19 +1295,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const feeManager = await FeeManagerErcToErcPOSDAO.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1383,19 +1325,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const feeManager = await FeeManagerErcToErcPOSDAO.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1426,19 +1365,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
// When
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
|
@ -1451,19 +1387,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
const blockReward = await homeBridge.blockRewardContract()
|
||||
|
@ -1494,15 +1427,13 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
const user = accounts[4]
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
const value = halfEther
|
||||
await token.mint(user, value, { from: owner }).should.be.fulfilled
|
||||
|
@ -1533,19 +1464,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
const value = halfEther
|
||||
const finalValueCalc = 0.5 * (1 - fee)
|
||||
|
@ -1580,19 +1508,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
blockRewardContract = await BlockReward.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
})
|
||||
it('should distribute fee to one validator', async () => {
|
||||
|
@ -1774,19 +1699,16 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
blockRewardContract = await BlockReward.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee,
|
||||
blockRewardContract.address
|
||||
[homeFee, foreignFee],
|
||||
blockRewardContract.address,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
})
|
||||
it('should distribute fee to one validator', async () => {
|
||||
|
@ -1969,4 +1891,87 @@ contract('HomeBridge_ERC20_to_ERC20', async accounts => {
|
|||
balanceRewardAddress5.should.be.bignumber.equal(feePerValidator)
|
||||
})
|
||||
})
|
||||
describe('#decimals Shift', async () => {
|
||||
const decimalShiftTwo = 2
|
||||
it('Foreign to Home: works with 5 validators and 3 required signatures with decimal shift 2', async () => {
|
||||
const recipient = accounts[8]
|
||||
const authoritiesFiveAccs = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]]
|
||||
const ownerOfValidators = accounts[0]
|
||||
const validatorContractWith3Signatures = await BridgeValidators.new()
|
||||
await validatorContractWith3Signatures.initialize(3, authoritiesFiveAccs, ownerOfValidators)
|
||||
const token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 16)
|
||||
|
||||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await token.transferOwnership(homeBridgeWithThreeSigs.address)
|
||||
|
||||
const valueOnForeign = toBN('1000')
|
||||
// Value is decimals shifted from foreign to home: Native on home = 16+2 shift = 18 decimals
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const balanceBeforeRecipient = await token.balanceOf(recipient)
|
||||
const transactionHash = '0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415'
|
||||
|
||||
const { logs } = await homeBridgeWithThreeSigs.executeAffirmation(recipient, valueOnForeign, transactionHash, {
|
||||
from: authoritiesFiveAccs[0]
|
||||
}).should.be.fulfilled
|
||||
expectEventInLogs(logs, 'SignedForAffirmation', {
|
||||
signer: authorities[0],
|
||||
transactionHash
|
||||
})
|
||||
|
||||
await homeBridgeWithThreeSigs.executeAffirmation(recipient, valueOnForeign, transactionHash, {
|
||||
from: authoritiesFiveAccs[1]
|
||||
}).should.be.fulfilled
|
||||
const thirdSignature = await homeBridgeWithThreeSigs.executeAffirmation(
|
||||
recipient,
|
||||
valueOnForeign,
|
||||
transactionHash,
|
||||
{ from: authoritiesFiveAccs[2] }
|
||||
).should.be.fulfilled
|
||||
|
||||
expectEventInLogs(thirdSignature.logs, 'AffirmationCompleted', {
|
||||
recipient,
|
||||
value: valueOnForeign,
|
||||
transactionHash
|
||||
})
|
||||
const balanceAfterRecipient = await token.balanceOf(recipient)
|
||||
balanceAfterRecipient.should.be.bignumber.equal(balanceBeforeRecipient.add(valueOnHome))
|
||||
})
|
||||
it('Foreign to Home: test decimal shift 2, no impact on UserRequestForSignature value', async () => {
|
||||
// Given
|
||||
const homeBridge = await HomeBridge.new()
|
||||
token = await ERC677BridgeToken.new('Some ERC20', 'TEST', 16)
|
||||
const owner = accounts[0]
|
||||
const user = accounts[4]
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
).should.be.fulfilled
|
||||
const value = halfEther
|
||||
await token.mint(user, value, { from: owner }).should.be.fulfilled
|
||||
|
||||
// When
|
||||
await token.transferAndCall(homeBridge.address, value, '0x00', { from: user }).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
const events = await getEvents(homeBridge, { event: 'UserRequestForSignature' })
|
||||
expect(events[0].returnValues.recipient).to.be.equal(user)
|
||||
expect(toBN(events[0].returnValues.value)).to.be.bignumber.equal(value)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -16,6 +16,7 @@ const homeDailyLimit = oneEther
|
|||
const homeMaxPerTx = halfEther
|
||||
const maxPerTx = halfEther
|
||||
const ZERO = toBN(0)
|
||||
const decimalShiftZero = 0
|
||||
|
||||
contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
||||
let validatorContract
|
||||
|
@ -39,6 +40,7 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
expect(await foreignBridge.deployedAtBlock()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.isInitialized()).to.be.equal(false)
|
||||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
|
@ -46,10 +48,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -58,10 +59,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
ZERO_ADDRESS,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -70,10 +70,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
0,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -82,10 +81,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
0,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -94,10 +92,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
owner,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -106,10 +103,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
|
@ -118,10 +114,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
halfEther,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, halfEther, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
|
@ -130,10 +125,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
'9'
|
||||
)
|
||||
|
||||
expect(await foreignBridge.erc20token()).to.be.equal(token.address)
|
||||
|
@ -143,6 +137,7 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(
|
||||
requireBlockConfirmations.toString()
|
||||
)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal('9')
|
||||
expect(await foreignBridge.gasPrice()).to.be.bignumber.equal(gasPrice)
|
||||
const bridgeMode = '0x18762d46' // 4 bytes of keccak256('erc-to-native-core')
|
||||
expect(await foreignBridge.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
|
@ -170,10 +165,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(foreignBridge.address, value)
|
||||
})
|
||||
|
@ -315,10 +309,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero,
|
||||
{ from: ownerOfValidatorContract }
|
||||
)
|
||||
await token.mint(foreignBridgeWithMultiSignatures.address, value)
|
||||
|
@ -382,10 +375,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
erc20Token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await erc20Token.mint(foreignBridgeWithThreeSigs.address, value)
|
||||
|
||||
|
@ -444,10 +436,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
// Deploy V2
|
||||
|
@ -464,7 +455,15 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
|
||||
const foreignBridge = await ForeignBridge.new()
|
||||
const data = foreignBridge.contract.methods
|
||||
.initialize(validatorsAddress, tokenAddress, requireBlockConfirmations, gasPrice, '2', '3', '2', owner)
|
||||
.initialize(
|
||||
validatorsAddress,
|
||||
tokenAddress,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
['2', '3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
|
||||
await storageProxy.upgradeToAndCall('1', foreignBridge.address, data).should.be.fulfilled
|
||||
|
@ -489,10 +488,9 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
maxPerTx,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
const tokenSecond = await ERC677BridgeToken.new('Roman Token', 'RST', 18)
|
||||
|
||||
|
@ -511,4 +509,106 @@ contract('ForeignBridge_ERC20_to_Native', async accounts => {
|
|||
expect(await tokenSecond.balanceOf(accounts[3])).to.be.bignumber.equal(halfEther)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#decimalShift', async () => {
|
||||
const decimalShiftTwo = 2
|
||||
it('Home to Foreign: withdraw with 1 signature with a decimalShift of 2', async () => {
|
||||
// From a foreign a token erc token 16 decimals.
|
||||
const token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 16)
|
||||
const valueOnForeign = toBN('1000')
|
||||
// Value is decimals shifted from foreign to home: Native on home = 16+2 shift = 18 decimals
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
|
||||
const owner = accounts[0]
|
||||
const foreignBridgeImpl = await ForeignBridge.new()
|
||||
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
|
||||
await storageProxy.upgradeTo('1', foreignBridgeImpl.address).should.be.fulfilled
|
||||
const foreignBridge = await ForeignBridge.at(storageProxy.address)
|
||||
|
||||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await token.mint(foreignBridge.address, valueOnForeign)
|
||||
|
||||
const recipientAccount = accounts[3]
|
||||
const balanceBefore = await token.balanceOf(recipientAccount)
|
||||
|
||||
const transactionHash = '0x1045bfe274b88120a6b1e5d01b5ec00ab5d01098346e90e7c7a3c9b8f0181c80'
|
||||
const message = createMessage(recipientAccount, valueOnHome, transactionHash, foreignBridge.address)
|
||||
const signature = await sign(authorities[0], message)
|
||||
const vrs = signatureToVRS(signature)
|
||||
false.should.be.equal(await foreignBridge.relayedMessages(transactionHash))
|
||||
|
||||
const { logs } = await foreignBridge.executeSignatures([vrs.v], [vrs.r], [vrs.s], message).should.be.fulfilled
|
||||
|
||||
logs[0].event.should.be.equal('RelayedMessage')
|
||||
logs[0].args.recipient.should.be.equal(recipientAccount)
|
||||
logs[0].args.value.should.be.bignumber.equal(valueOnHome)
|
||||
const balanceAfter = await token.balanceOf(recipientAccount)
|
||||
balanceAfter.should.be.bignumber.equal(balanceBefore.add(valueOnForeign))
|
||||
const balanceAfterBridge = await token.balanceOf(foreignBridge.address)
|
||||
balanceAfterBridge.should.be.bignumber.equal(ZERO)
|
||||
true.should.be.equal(await foreignBridge.relayedMessages(transactionHash))
|
||||
})
|
||||
|
||||
it('Home to Foreign: withdraw with 2 minimum signatures with a decimalShift of 2', async () => {
|
||||
const multisigValidatorContract = await BridgeValidators.new()
|
||||
const valueOnForeign = toBN('1000')
|
||||
const decimalShiftTwo = 2
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const token = await ERC677BridgeToken.new('Some ERC20', 'RSZT', 16)
|
||||
const twoAuthorities = [accounts[0], accounts[1]]
|
||||
const ownerOfValidatorContract = accounts[3]
|
||||
const recipient = accounts[8]
|
||||
await multisigValidatorContract.initialize(2, twoAuthorities, ownerOfValidatorContract, {
|
||||
from: ownerOfValidatorContract
|
||||
})
|
||||
const foreignBridgeWithMultiSignatures = await ForeignBridge.new()
|
||||
await foreignBridgeWithMultiSignatures.initialize(
|
||||
multisigValidatorContract.address,
|
||||
token.address,
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
[maxPerTx, homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo,
|
||||
{ from: ownerOfValidatorContract }
|
||||
)
|
||||
await token.mint(foreignBridgeWithMultiSignatures.address, valueOnForeign)
|
||||
|
||||
const balanceBefore = await token.balanceOf(recipient)
|
||||
|
||||
const txHash = '0x35d3818e50234655f6aebb2a1cfbf30f59568d8a4ec72066fac5a25dbe7b8121'
|
||||
const message = createMessage(recipient, valueOnHome, txHash, foreignBridgeWithMultiSignatures.address)
|
||||
|
||||
// signature 1
|
||||
const signature = await sign(twoAuthorities[0], message)
|
||||
const vrs = signatureToVRS(signature)
|
||||
|
||||
// signature 2
|
||||
const signature2 = await sign(twoAuthorities[1], message)
|
||||
const vrs2 = signatureToVRS(signature2)
|
||||
|
||||
const { logs } = await foreignBridgeWithMultiSignatures.executeSignatures(
|
||||
[vrs.v, vrs2.v],
|
||||
[vrs.r, vrs2.r],
|
||||
[vrs.s, vrs2.s],
|
||||
message
|
||||
).should.be.fulfilled
|
||||
logs[0].event.should.be.equal('RelayedMessage')
|
||||
logs[0].args.recipient.should.be.equal(recipient)
|
||||
logs[0].args.value.should.be.bignumber.equal(valueOnHome)
|
||||
const balanceAfter = await token.balanceOf(recipient)
|
||||
balanceAfter.should.be.bignumber.equal(balanceBefore.add(valueOnForeign))
|
||||
const balanceAfterBridge = await token.balanceOf(foreignBridgeWithMultiSignatures.address)
|
||||
balanceAfterBridge.should.be.bignumber.equal(ZERO)
|
||||
true.should.be.equal(await foreignBridgeWithMultiSignatures.relayedMessages(txHash))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,6 +19,7 @@ const gasPrice = web3.utils.toWei('1', 'gwei')
|
|||
const homeDailyLimit = oneEther
|
||||
const homeMaxPerTx = halfEther
|
||||
const ZERO = toBN(0)
|
||||
const decimalShiftZero = 0
|
||||
|
||||
contract('ForeignBridge', async accounts => {
|
||||
let validatorContract
|
||||
|
@ -43,102 +44,89 @@ contract('ForeignBridge', async accounts => {
|
|||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.dailyLimit()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.maxPerTx()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
ZERO_ADDRESS,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
ZERO_ADDRESS,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
0,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
owner,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
owner,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
0,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
const { logs } = await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
'9'
|
||||
)
|
||||
|
||||
expect(await foreignBridge.isInitialized()).to.be.equal(true)
|
||||
|
@ -151,6 +139,7 @@ contract('ForeignBridge', async accounts => {
|
|||
expect(await foreignBridge.dailyLimit()).to.be.bignumber.equal(oneEther)
|
||||
expect(await foreignBridge.maxPerTx()).to.be.bignumber.equal(halfEther)
|
||||
expect(await foreignBridge.minPerTx()).to.be.bignumber.equal(minPerTx)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal('9')
|
||||
const bridgeMode = '0x92a8d7fe' // 4 bytes of keccak256('native-to-erc-core')
|
||||
expect(await foreignBridge.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
const { major, minor, patch } = await foreignBridge.getBridgeInterfacesVersion()
|
||||
|
@ -175,14 +164,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
})
|
||||
|
@ -322,14 +309,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridgeWithMultiSignatures.initialize(
|
||||
multisigValidatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero,
|
||||
{ from: ownerOfValidatorContract }
|
||||
)
|
||||
await token.transferOwnership(foreignBridgeWithMultiSignatures.address)
|
||||
|
@ -388,14 +373,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
erc20Token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await erc20Token.transferOwnership(foreignBridgeWithThreeSigs.address)
|
||||
|
||||
|
@ -438,14 +421,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
erc20Token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await erc20Token.transferOwnership(foreignBridgeWithThreeSigs.address)
|
||||
|
||||
|
@ -488,14 +469,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(user, halfEther, { from: owner }).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address, { from: owner })
|
||||
|
@ -514,14 +493,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(user, valueMoreThanLimit, { from: owner }).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address, { from: owner })
|
||||
|
@ -551,14 +528,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(user, oneEther.add(toBN(1)), { from: owner }).should.be.fulfilled
|
||||
|
||||
|
@ -592,14 +567,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.mint(user, oneEther, { from: owner }).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address, { from: owner })
|
||||
|
@ -626,14 +599,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
})
|
||||
|
@ -681,14 +652,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridgeProxy.initialize(
|
||||
validatorsProxy.address,
|
||||
token.address,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(foreignBridgeProxy.address).should.be.fulfilled
|
||||
|
||||
|
@ -713,14 +682,12 @@ contract('ForeignBridge', async accounts => {
|
|||
.initialize(
|
||||
validatorsAddress,
|
||||
tokenAddress,
|
||||
FOREIGN_DAILY_LIMIT,
|
||||
FOREIGN_MAX_AMOUNT_PER_TX,
|
||||
FOREIGN_MIN_AMOUNT_PER_TX,
|
||||
[FOREIGN_DAILY_LIMIT, FOREIGN_MAX_AMOUNT_PER_TX, FOREIGN_MIN_AMOUNT_PER_TX],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
'3',
|
||||
'2',
|
||||
owner
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', foreignBridge.address, data).should.be.fulfilled
|
||||
|
@ -740,14 +707,12 @@ contract('ForeignBridge', async accounts => {
|
|||
.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
'3',
|
||||
'2',
|
||||
owner
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', foreignBridge.address, data).should.be.fulfilled
|
||||
|
@ -766,14 +731,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
|
||||
|
@ -800,14 +763,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
|
||||
|
@ -834,14 +795,12 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
owner
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
const tokenMock = await NoReturnTransferTokenMock.new()
|
||||
|
@ -882,116 +841,103 @@ contract('ForeignBridge', async accounts => {
|
|||
expect(await foreignBridge.requiredBlockConfirmations()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.dailyLimit()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.maxPerTx()).to.be.bignumber.equal(ZERO)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
ZERO_ADDRESS,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
ZERO_ADDRESS,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
0,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
owner,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
owner,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
owner,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
requireBlockConfirmations,
|
||||
gasPrice,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
ZERO_ADDRESS,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
'9'
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await foreignBridge.isInitialized()).to.be.equal(true)
|
||||
|
@ -1004,6 +950,7 @@ contract('ForeignBridge', async accounts => {
|
|||
expect(await foreignBridge.dailyLimit()).to.be.bignumber.equal(oneEther)
|
||||
expect(await foreignBridge.maxPerTx()).to.be.bignumber.equal(halfEther)
|
||||
expect(await foreignBridge.minPerTx()).to.be.bignumber.equal(minPerTx)
|
||||
expect(await foreignBridge.decimalShift()).to.be.bignumber.equal('9')
|
||||
const bridgeMode = '0x92a8d7fe' // 4 bytes of keccak256('native-to-erc-core')
|
||||
expect(await foreignBridge.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
const { major, minor, patch } = await foreignBridge.getBridgeInterfacesVersion()
|
||||
|
@ -1020,16 +967,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1047,16 +992,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1073,16 +1016,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1108,16 +1049,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee
|
||||
homeFee,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
|
@ -1152,16 +1091,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei
|
||||
feeInWei,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
|
||||
|
@ -1212,16 +1149,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei
|
||||
feeInWei,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
|
||||
|
@ -1300,16 +1235,14 @@ contract('ForeignBridge', async accounts => {
|
|||
await foreignBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
homeDailyLimit,
|
||||
homeMaxPerTx,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei
|
||||
feeInWei,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await token.transferOwnership(foreignBridge.address)
|
||||
|
||||
|
@ -1368,4 +1301,85 @@ contract('ForeignBridge', async accounts => {
|
|||
updatedBalanceRewardAddress5.should.be.bignumber.equal(initialBalanceRewardAddress5.add(feePerValidator))
|
||||
})
|
||||
})
|
||||
describe('#decimalShift', async () => {
|
||||
const decimalShiftTwo = 2
|
||||
it('Home to Foreign: withdraw works with decimalShift of 2', async () => {
|
||||
const recipient = accounts[8]
|
||||
const authoritiesFiveAccs = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]]
|
||||
const ownerOfValidators = accounts[0]
|
||||
const validatorContractWith3Signatures = await BridgeValidators.new()
|
||||
await validatorContractWith3Signatures.initialize(3, authoritiesFiveAccs, ownerOfValidators)
|
||||
const erc20Token = await POA20.new('Some ERC20', 'RSZT', 16)
|
||||
const valueOnForeign = toBN('1000')
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const foreignBridgeWithThreeSigs = await ForeignBridge.new()
|
||||
|
||||
await foreignBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
erc20Token.address,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await erc20Token.transferOwnership(foreignBridgeWithThreeSigs.address)
|
||||
|
||||
const balanceBeforeRecipient = await erc20Token.balanceOf(recipient)
|
||||
const txHash = '0x35d3818e50234655f6aebb2a1cfbf30f59568d8a4ec72066fac5a25dbe7b8121'
|
||||
const message = createMessage(recipient, valueOnHome, txHash, foreignBridgeWithThreeSigs.address)
|
||||
|
||||
// signature 1
|
||||
const signature = await sign(authoritiesFiveAccs[0], message)
|
||||
const vrs = signatureToVRS(signature)
|
||||
|
||||
// signature 2
|
||||
const signature2 = await sign(authoritiesFiveAccs[1], message)
|
||||
const vrs2 = signatureToVRS(signature2)
|
||||
|
||||
// signature 3
|
||||
const signature3 = await sign(authoritiesFiveAccs[2], message)
|
||||
const vrs3 = signatureToVRS(signature3)
|
||||
|
||||
const { logs } = await foreignBridgeWithThreeSigs.executeSignatures(
|
||||
[vrs.v, vrs2.v, vrs3.v],
|
||||
[vrs.r, vrs2.r, vrs3.r],
|
||||
[vrs.s, vrs2.s, vrs3.s],
|
||||
message
|
||||
).should.be.fulfilled
|
||||
logs[0].event.should.be.equal('RelayedMessage')
|
||||
logs[0].args.recipient.should.be.equal(recipient)
|
||||
logs[0].args.value.should.be.bignumber.equal(valueOnHome)
|
||||
true.should.be.equal(await foreignBridgeWithThreeSigs.relayedMessages(txHash))
|
||||
const balanceAfterRecipient = await erc20Token.balanceOf(recipient)
|
||||
balanceAfterRecipient.should.be.bignumber.equal(balanceBeforeRecipient.add(valueOnForeign))
|
||||
const balanceAfterBridge = await erc20Token.balanceOf(foreignBridgeWithThreeSigs.address)
|
||||
balanceAfterBridge.should.be.bignumber.equal(ZERO)
|
||||
})
|
||||
it('Foreign to Home: no impact in transferAndCall event signal for bridges oracles with a decimalShift of 2.', async () => {
|
||||
const owner = accounts[3]
|
||||
const user = accounts[4]
|
||||
const value = halfEther
|
||||
token = await POA20.new('POA ERC20 Foundation', 'POA20', 16, { from: owner })
|
||||
const foreignBridge = await ForeignBridge.new()
|
||||
await foreignBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
[homeDailyLimit, homeMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
await token.mint(user, value, { from: owner }).should.be.fulfilled
|
||||
expect(await token.balanceOf(user)).to.be.bignumber.equal(value)
|
||||
await token.transferOwnership(foreignBridge.address, { from: owner })
|
||||
const { logs } = await token.transferAndCall(foreignBridge.address, value, '0x00', { from: user })
|
||||
logs[0].event.should.be.equal('Transfer')
|
||||
logs[0].args.value.should.be.bignumber.equal(value)
|
||||
expect(await token.balanceOf(user)).to.be.bignumber.equal(ZERO)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -21,6 +21,7 @@ const halfEther = ether('0.5')
|
|||
const foreignDailyLimit = oneEther
|
||||
const foreignMaxPerTx = halfEther
|
||||
const ZERO = toBN(0)
|
||||
const decimalShiftZero = 0
|
||||
|
||||
contract('HomeBridge', async accounts => {
|
||||
let homeContract
|
||||
|
@ -43,18 +44,17 @@ contract('HomeBridge', async accounts => {
|
|||
expect(await homeContract.deployedAtBlock()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.dailyLimit()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.maxPerTx()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.decimalShift()).to.be.bignumber.equal(ZERO)
|
||||
expect(await homeContract.isInitialized()).to.be.equal(false)
|
||||
|
||||
const { logs } = await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
'9'
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.isInitialized()).to.be.equal(true)
|
||||
|
@ -64,6 +64,7 @@ contract('HomeBridge', async accounts => {
|
|||
expect(await homeContract.maxPerTx()).to.be.bignumber.equal('2')
|
||||
expect(await homeContract.minPerTx()).to.be.bignumber.equal('1')
|
||||
expect(await homeContract.gasPrice()).to.be.bignumber.equal(gasPrice)
|
||||
expect(await homeContract.decimalShift()).to.be.bignumber.equal('9')
|
||||
const bridgeMode = '0x92a8d7fe' // 4 bytes of keccak256('native-to-erc-core')
|
||||
expect(await homeContract.getBridgeMode()).to.be.equal(bridgeMode)
|
||||
const { major, minor, patch } = await homeContract.getBridgeInterfacesVersion()
|
||||
|
@ -83,27 +84,23 @@ contract('HomeBridge', async accounts => {
|
|||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'1',
|
||||
'2',
|
||||
'1',
|
||||
['1', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'2',
|
||||
['3', '2', '2'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
false.should.be.equal(await homeContract.isInitialized())
|
||||
|
@ -112,14 +109,12 @@ contract('HomeBridge', async accounts => {
|
|||
// Given
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.gasPrice()).to.be.bignumber.equal(gasPrice)
|
||||
|
@ -139,14 +134,12 @@ contract('HomeBridge', async accounts => {
|
|||
// Given
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.requiredBlockConfirmations()).to.be.bignumber.equal(toBN(requireBlockConfirmations))
|
||||
|
@ -169,7 +162,15 @@ contract('HomeBridge', async accounts => {
|
|||
it('can be deployed via upgradeToAndCall', async () => {
|
||||
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
|
||||
const data = homeContract.contract.methods
|
||||
.initialize(validatorContract.address, '3', '2', '1', gasPrice, requireBlockConfirmations, '3', '2', owner)
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeTo('1', accounts[5]).should.be.rejectedWith(ERROR_MSG)
|
||||
await storageProxy.upgradeToAndCall('1', accounts[5], data).should.be.rejectedWith(ERROR_MSG)
|
||||
|
@ -185,44 +186,46 @@ contract('HomeBridge', async accounts => {
|
|||
it('cant initialize with invalid arguments', async () => {
|
||||
false.should.be.equal(await homeContract.isInitialized())
|
||||
await homeContract
|
||||
.initialize(validatorContract.address, '3', '2', '1', gasPrice, 0, foreignDailyLimit, foreignMaxPerTx, owner)
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
0,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
owner,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract
|
||||
.initialize(
|
||||
ZERO_ADDRESS,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
true.should.be.equal(await homeContract.isInitialized())
|
||||
})
|
||||
|
@ -230,14 +233,12 @@ contract('HomeBridge', async accounts => {
|
|||
// Given
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.owner()).to.be.equal(owner)
|
||||
|
@ -256,7 +257,15 @@ contract('HomeBridge', async accounts => {
|
|||
it('can transfer proxyOwnership', async () => {
|
||||
const storageProxy = await EternalStorageProxy.new().should.be.fulfilled
|
||||
const data = homeContract.contract.methods
|
||||
.initialize(validatorContract.address, '3', '2', '1', gasPrice, requireBlockConfirmations, '3', '2', owner)
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', homeContract.address, data).should.be.fulfilled
|
||||
await storageProxy.transferProxyOwnership(owner).should.be.fulfilled
|
||||
|
@ -270,14 +279,12 @@ contract('HomeBridge', async accounts => {
|
|||
homeContract = await HomeBridge.new()
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('should accept native coins', async () => {
|
||||
|
@ -363,14 +370,12 @@ contract('HomeBridge', async accounts => {
|
|||
homeContract = await HomeBridge.new()
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
'3',
|
||||
'2',
|
||||
'1',
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('#setMaxPerTx allows to set only to owner and cannot be more than daily limit', async () => {
|
||||
|
@ -406,14 +411,12 @@ contract('HomeBridge', async accounts => {
|
|||
homeBridge = await HomeBridge.new()
|
||||
await homeBridge.initialize(
|
||||
validatorContract.address,
|
||||
twoEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[twoEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[2],
|
||||
|
@ -483,14 +486,12 @@ contract('HomeBridge', async accounts => {
|
|||
const homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
twoEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[twoEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await homeBridgeWithTwoSigs.sendTransaction({
|
||||
|
@ -573,14 +574,12 @@ contract('HomeBridge', async accounts => {
|
|||
const homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
await homeBridgeWithTwoSigs.sendTransaction({
|
||||
|
@ -649,14 +648,12 @@ contract('HomeBridge', async accounts => {
|
|||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
const value = halfEther
|
||||
|
@ -764,14 +761,12 @@ contract('HomeBridge', async accounts => {
|
|||
homeBridgeWithTwoSigs = await HomeBridge.new()
|
||||
await homeBridgeWithTwoSigs.initialize(
|
||||
validatorContractWith2Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('allows a validator to submit a signature', async () => {
|
||||
|
@ -826,14 +821,12 @@ contract('HomeBridge', async accounts => {
|
|||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
owner
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
|
||||
const value = halfEther
|
||||
|
@ -929,7 +922,15 @@ contract('HomeBridge', async accounts => {
|
|||
it('should work with token that return bool on transfer', async () => {
|
||||
const storageProxy = await EternalStorageProxy.new()
|
||||
const data = homeContract.contract.methods
|
||||
.initialize(validatorContract.address, '3', '2', '1', gasPrice, requireBlockConfirmations, '3', '2', owner)
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', homeContract.address, data).should.be.fulfilled
|
||||
const homeBridge = await HomeBridge.at(storageProxy.address)
|
||||
|
@ -950,7 +951,15 @@ contract('HomeBridge', async accounts => {
|
|||
it('should works with token that not return on transfer', async () => {
|
||||
const storageProxy = await EternalStorageProxy.new()
|
||||
const data = homeContract.contract.methods
|
||||
.initialize(validatorContract.address, '3', '2', '1', gasPrice, requireBlockConfirmations, '3', '2', owner)
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
['3', '2'],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', homeContract.address, data).should.be.fulfilled
|
||||
const homeBridge = await HomeBridge.at(storageProxy.address)
|
||||
|
@ -973,14 +982,12 @@ contract('HomeBridge', async accounts => {
|
|||
const data = homeContract.contract.methods
|
||||
.initialize(
|
||||
validatorContract.address,
|
||||
oneEther.toString(),
|
||||
halfEther.toString(),
|
||||
'1',
|
||||
[oneEther.toString(), halfEther.toString(), '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
oneEther.toString(),
|
||||
halfEther.toString(),
|
||||
owner
|
||||
[oneEther.toString(), halfEther.toString()],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
.encodeABI()
|
||||
await storageProxy.upgradeToAndCall('1', homeContract.address, data).should.be.fulfilled
|
||||
|
@ -1023,80 +1030,65 @@ contract('HomeBridge', async accounts => {
|
|||
await homeBridge
|
||||
.rewardableInitialize(
|
||||
ZERO_ADDRESS,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
0,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
0,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeBridge
|
||||
.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
ZERO_ADDRESS,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
)
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
expect(await homeBridge.isInitialized()).to.be.equal(true)
|
||||
|
@ -1123,17 +1115,14 @@ contract('HomeBridge', async accounts => {
|
|||
const feeManager = await FeeManagerNativeToErc.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1151,17 +1140,14 @@ contract('HomeBridge', async accounts => {
|
|||
const feeManager = await FeeManagerNativeToErc.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1178,17 +1164,14 @@ contract('HomeBridge', async accounts => {
|
|||
const feeManager = await FeeManagerNativeToErc.new()
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Given
|
||||
|
@ -1212,17 +1195,14 @@ contract('HomeBridge', async accounts => {
|
|||
// When
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
|
@ -1237,17 +1217,14 @@ contract('HomeBridge', async accounts => {
|
|||
// When
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
homeFee,
|
||||
foreignFee
|
||||
[homeFee, foreignFee],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// Then
|
||||
|
@ -1280,17 +1257,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
notUsedFee,
|
||||
feeInWei
|
||||
[notUsedFee, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// When
|
||||
|
@ -1333,17 +1307,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
notUsedFee,
|
||||
feeInWei
|
||||
[notUsedFee, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
await homeBridge.sendTransaction({
|
||||
|
@ -1396,17 +1367,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
notUsedFee,
|
||||
feeInWei
|
||||
[notUsedFee, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -1471,17 +1439,14 @@ contract('HomeBridge', async accounts => {
|
|||
}).should.be.fulfilled
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
notUsedFee,
|
||||
feeInWei
|
||||
[notUsedFee, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -1569,17 +1534,14 @@ contract('HomeBridge', async accounts => {
|
|||
}).should.be.fulfilled
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
notUsedFee,
|
||||
feeInWei
|
||||
[notUsedFee, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -1671,17 +1633,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
// When
|
||||
|
@ -1729,17 +1688,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
await homeBridge.sendTransaction({
|
||||
|
@ -1795,17 +1751,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
await homeBridge.sendTransaction({
|
||||
|
@ -1882,17 +1835,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
|
||||
await homeBridge.sendTransaction({
|
||||
|
@ -1971,17 +1921,14 @@ contract('HomeBridge', async accounts => {
|
|||
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -2045,17 +1992,14 @@ contract('HomeBridge', async accounts => {
|
|||
}).should.be.fulfilled
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -2142,17 +2086,14 @@ contract('HomeBridge', async accounts => {
|
|||
}).should.be.fulfilled
|
||||
await homeBridge.rewardableInitialize(
|
||||
rewardableValidators.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
foreignDailyLimit,
|
||||
foreignMaxPerTx,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
feeManager.address,
|
||||
feeInWei,
|
||||
feeInWei
|
||||
[feeInWei, feeInWei],
|
||||
decimalShiftZero
|
||||
).should.be.fulfilled
|
||||
await homeBridge.sendTransaction({
|
||||
from: accounts[0],
|
||||
|
@ -2220,4 +2161,100 @@ contract('HomeBridge', async accounts => {
|
|||
updatedBalanceRewardAddress5.should.be.bignumber.equal(initialBalanceRewardAddress5.add(feePerValidator))
|
||||
})
|
||||
})
|
||||
describe('#decimalShift', async () => {
|
||||
const decimalShiftTwo = 2
|
||||
it('Foreign to Home: works with 5 validators and 3 required signatures with decimal shift 2', async () => {
|
||||
const recipient = accounts[8]
|
||||
const authoritiesFiveAccs = [accounts[1], accounts[2], accounts[3], accounts[4], accounts[5]]
|
||||
const ownerOfValidators = accounts[0]
|
||||
const validatorContractWith3Signatures = await BridgeValidators.new()
|
||||
await validatorContractWith3Signatures.initialize(3, authoritiesFiveAccs, ownerOfValidators)
|
||||
|
||||
const homeBridgeWithThreeSigs = await HomeBridge.new()
|
||||
await homeBridgeWithThreeSigs.initialize(
|
||||
validatorContractWith3Signatures.address,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
|
||||
const valueOnForeign = toBN('1000')
|
||||
const valueOnHome = toBN(valueOnForeign * 10 ** decimalShiftTwo)
|
||||
const transactionHash = '0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415'
|
||||
|
||||
await homeBridgeWithThreeSigs.sendTransaction({
|
||||
from: recipient,
|
||||
value: halfEther
|
||||
}).should.be.fulfilled
|
||||
|
||||
const balanceBeforeRecipient = toBN(await web3.eth.getBalance(recipient))
|
||||
|
||||
const { logs } = await homeBridgeWithThreeSigs.executeAffirmation(recipient, valueOnForeign, transactionHash, {
|
||||
from: authoritiesFiveAccs[0]
|
||||
}).should.be.fulfilled
|
||||
expectEventInLogs(logs, 'SignedForAffirmation', {
|
||||
signer: authorities[0],
|
||||
transactionHash
|
||||
})
|
||||
|
||||
await homeBridgeWithThreeSigs.executeAffirmation(recipient, valueOnForeign, transactionHash, {
|
||||
from: authoritiesFiveAccs[1]
|
||||
}).should.be.fulfilled
|
||||
const thirdSignature = await homeBridgeWithThreeSigs.executeAffirmation(
|
||||
recipient,
|
||||
valueOnForeign,
|
||||
transactionHash,
|
||||
{ from: authoritiesFiveAccs[2] }
|
||||
).should.be.fulfilled
|
||||
|
||||
expectEventInLogs(thirdSignature.logs, 'AffirmationCompleted', {
|
||||
recipient,
|
||||
value: valueOnForeign,
|
||||
transactionHash
|
||||
})
|
||||
|
||||
const balanceAfterRecipient = toBN(await web3.eth.getBalance(recipient))
|
||||
balanceAfterRecipient.should.be.bignumber.equal(balanceBeforeRecipient.add(valueOnHome))
|
||||
})
|
||||
it('Foreign to Home: test decimal shift 2, no impact on UserRequestForSignature value', async () => {
|
||||
homeContract = await HomeBridge.new()
|
||||
await homeContract.initialize(
|
||||
validatorContract.address,
|
||||
['3', '2', '1'],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
[foreignDailyLimit, foreignMaxPerTx],
|
||||
owner,
|
||||
decimalShiftTwo
|
||||
)
|
||||
const currentDay = await homeContract.getCurrentDay()
|
||||
expect(await homeContract.totalSpentPerDay(currentDay)).to.be.bignumber.equal(ZERO)
|
||||
|
||||
const { logs } = await homeContract.sendTransaction({
|
||||
from: accounts[1],
|
||||
value: 1
|
||||
}).should.be.fulfilled
|
||||
expect(await homeContract.totalSpentPerDay(currentDay)).to.be.bignumber.equal('1')
|
||||
|
||||
expectEventInLogs(logs, 'UserRequestForSignature', { recipient: accounts[1], value: toBN(1) })
|
||||
|
||||
await homeContract
|
||||
.sendTransaction({
|
||||
from: accounts[1],
|
||||
value: 3
|
||||
})
|
||||
.should.be.rejectedWith(ERROR_MSG)
|
||||
|
||||
await homeContract.setDailyLimit(4).should.be.fulfilled
|
||||
await homeContract.sendTransaction({
|
||||
from: accounts[1],
|
||||
value: 1
|
||||
}).should.be.fulfilled
|
||||
|
||||
expect(await homeContract.totalSpentPerDay(currentDay)).to.be.bignumber.equal('2')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -20,6 +20,7 @@ const halfEther = ether('0.5')
|
|||
const executionDailyLimit = oneEther
|
||||
const executionMaxPerTx = halfEther
|
||||
const ZERO = new BN(0)
|
||||
const decimalShiftZero = 0
|
||||
|
||||
async function testERC677BridgeToken(accounts, rewardable) {
|
||||
let token
|
||||
|
@ -237,28 +238,24 @@ async function testERC677BridgeToken(accounts, rewardable) {
|
|||
homeErcToErcContract = await HomeErcToErcBridge.new()
|
||||
await homeErcToErcContract.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
executionDailyLimit,
|
||||
executionMaxPerTx,
|
||||
owner
|
||||
[executionDailyLimit, executionMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
foreignNativeToErcBridge = await ForeignNativeToErcBridge.new()
|
||||
await foreignNativeToErcBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
executionDailyLimit,
|
||||
executionMaxPerTx,
|
||||
owner
|
||||
[executionDailyLimit, executionMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('sends tokens to recipient', async () => {
|
||||
|
@ -396,28 +393,24 @@ async function testERC677BridgeToken(accounts, rewardable) {
|
|||
homeErcToErcContract = await HomeErcToErcBridge.new()
|
||||
await homeErcToErcContract.initialize(
|
||||
validatorContract.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
token.address,
|
||||
executionDailyLimit,
|
||||
executionMaxPerTx,
|
||||
owner
|
||||
[executionDailyLimit, executionMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
foreignNativeToErcBridge = await ForeignNativeToErcBridge.new()
|
||||
await foreignNativeToErcBridge.initialize(
|
||||
validatorContract.address,
|
||||
token.address,
|
||||
oneEther,
|
||||
halfEther,
|
||||
minPerTx,
|
||||
[oneEther, halfEther, minPerTx],
|
||||
gasPrice,
|
||||
requireBlockConfirmations,
|
||||
executionDailyLimit,
|
||||
executionMaxPerTx,
|
||||
owner
|
||||
[executionDailyLimit, executionMaxPerTx],
|
||||
owner,
|
||||
decimalShiftZero
|
||||
)
|
||||
})
|
||||
it('calls contractFallback', async () => {
|
||||
|
|
Loading…
Reference in New Issue