Add total executed per day
This commit is contained in:
parent
5bd6f5d58e
commit
42a87e631c
|
@ -12,6 +12,7 @@ contract BasicBridge is EternalStorage, Validatable {
|
|||
event GasPriceChanged(uint256 gasPrice);
|
||||
event RequiredBlockConfirmationChanged(uint256 requiredBlockConfirmations);
|
||||
event DailyLimitChanged(uint256 newLimit);
|
||||
event OppositeSideDailyLimitChanged(uint256 newLimit);
|
||||
|
||||
function getBridgeInterfacesVersion() public pure returns(uint64 major, uint64 minor, uint64 patch) {
|
||||
return (2, 1, 0);
|
||||
|
@ -49,6 +50,14 @@ contract BasicBridge is EternalStorage, Validatable {
|
|||
return uintStorage[keccak256(abi.encodePacked("totalSpentPerDay", _day))];
|
||||
}
|
||||
|
||||
function setTotalExecutedPerDay(uint256 _day, uint256 _value) internal {
|
||||
uintStorage[keccak256("totalExecutedPerDay", _day)] = _value;
|
||||
}
|
||||
|
||||
function totalExecutedPerDay(uint256 _day) public view returns(uint256) {
|
||||
return uintStorage[keccak256("totalExecutedPerDay", _day)];
|
||||
}
|
||||
|
||||
function minPerTx() public view returns(uint256) {
|
||||
return uintStorage[keccak256(abi.encodePacked("minPerTx"))];
|
||||
}
|
||||
|
@ -84,6 +93,7 @@ contract BasicBridge is EternalStorage, Validatable {
|
|||
|
||||
function setOppositeSideDailyLimit(uint256 _dailyLimit) public onlyOwner {
|
||||
uintStorage[keccak256(abi.encodePacked("oppositeSideDailyLimit"))] = _dailyLimit;
|
||||
emit OppositeSideDailyLimitChanged(_dailyLimit);
|
||||
}
|
||||
|
||||
function oppositeSideDailyLimit() public view returns(uint256) {
|
||||
|
@ -111,7 +121,7 @@ contract BasicBridge is EternalStorage, Validatable {
|
|||
}
|
||||
|
||||
function withinOppositeSideLimit(uint256 _amount) public view returns(bool) {
|
||||
uint256 nextLimit = totalSpentPerDay(getCurrentDay()).add(_amount);
|
||||
uint256 nextLimit = totalExecutedPerDay(getCurrentDay()).add(_amount);
|
||||
return oppositeSideDailyLimit() >= nextLimit && _amount <= oppositeSideMaxPerTx();
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ contract ForeignBridgeErcToNative is BasicBridge, BasicForeignBridge {
|
|||
}
|
||||
|
||||
function onExecuteMessage(address _recipient, uint256 _amount) internal returns(bool) {
|
||||
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_amount));
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_amount));
|
||||
return erc20token().transfer(_recipient, _amount);
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ contract HomeBridgeErcToNative is EternalStorage, BasicBridge, BasicHomeBridge {
|
|||
}
|
||||
|
||||
function onExecuteAffirmation(address _recipient, uint256 _value) internal returns(bool) {
|
||||
setTotalExecutedPerDay(getCurrentDay(), totalExecutedPerDay(getCurrentDay()).add(_value));
|
||||
IBlockReward blockReward = blockRewardContract();
|
||||
require(blockReward != address(0));
|
||||
blockReward.addExtraReceiver(_value, _recipient);
|
||||
|
|
|
@ -447,6 +447,23 @@ contract('HomeBridge_ERC20_to_Native', async (accounts) => {
|
|||
value,
|
||||
transactionHash: transactionHash3
|
||||
});
|
||||
|
||||
const outOfLimitAmount = await homeBridge.outOfLimitAmount()
|
||||
|
||||
outOfLimitAmount.should.be.bignumber.equal(halfEther)
|
||||
|
||||
const transactionHash4 = "0xc9ffe298d85ec5c515153608924b7bdcf1835539813dcc82cdbcc071170c3196";
|
||||
const { logs: logs4 } = await homeBridge.executeAffirmation(recipient, value, transactionHash4, {from: authorities[0]}).should.be.fulfilled;
|
||||
|
||||
logs4[0].event.should.be.equal("AmountLimitExceeded");
|
||||
logs4[0].args.should.be.deep.equal({
|
||||
recipient,
|
||||
value,
|
||||
transactionHash: transactionHash4
|
||||
});
|
||||
|
||||
const newOutOfLimitAmount = await homeBridge.outOfLimitAmount()
|
||||
newOutOfLimitAmount.should.be.bignumber.equal(oneEther)
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue