Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Dynamic extra incentive to bsc relayer #86

Merged
merged 3 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions contracts/RelayerIncentivize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {

mapping(address => uint256) public relayerRewardVault;

uint256 public compensateRelayerAmount;
abelliumnt marked this conversation as resolved.
Show resolved Hide resolved

event distributeCollectedReward(uint256 sequence, uint256 roundRewardForHeaderRelayer, uint256 roundRewardForTransferRelayer);
event paramChange(string key, bytes value);
event rewardToRelayer(address relayer, uint256 amount);
Expand All @@ -64,6 +66,10 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
}

if (compensateRelayerAmount > 0) {
actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), compensateRelayerAmount));
abelliumnt marked this conversation as resolved.
Show resolved Hide resolved
}

countInRound++;

uint256 reward = calculateRewardForHeaderRelayer(actualAmount);
Expand Down Expand Up @@ -216,6 +222,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value);
require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule");
callerCompensationDenominator = newCallerCompensationDenominator;
} else if (Memory.compareStrings(key,"compensateRelayerAmount")) {
abelliumnt marked this conversation as resolved.
Show resolved Hide resolved
require(value.length == 32, "length of compensateRelayerAmount mismatch");
uint256 newCompensateRelayerAmount = BytesToTypes.bytesToUint256(32, value);
require(newCompensateRelayerAmount >= 0 , "the newCompensateRelayerAmount must be no less than zero");
compensateRelayerAmount = newCompensateRelayerAmount;
} else {
require(false, "unknown param");
}
Expand Down
11 changes: 11 additions & 0 deletions contracts/RelayerIncentivize.template
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {

mapping(address => uint256) public relayerRewardVault;

uint256 public compensateRelayerAmount;

event distributeCollectedReward(uint256 sequence, uint256 roundRewardForHeaderRelayer, uint256 roundRewardForTransferRelayer);
event paramChange(string key, bytes value);
event rewardToRelayer(address relayer, uint256 amount);
Expand Down Expand Up @@ -66,6 +68,10 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
}

if (compensateRelayerAmount > 0) {
actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), compensateRelayerAmount));
}

countInRound++;

uint256 reward = calculateRewardForHeaderRelayer(actualAmount);
Expand Down Expand Up @@ -218,6 +224,11 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
uint256 newCallerCompensationDenominator = BytesToTypes.bytesToUint256(32, value);
require(newCallerCompensationDenominator != 0 && newCallerCompensationDenominator >= callerCompensationMolecule, "the newCallerCompensationDenominator must not be zero and no less than callerCompensationMolecule");
callerCompensationDenominator = newCallerCompensationDenominator;
} else if (Memory.compareStrings(key,"compensateRelayerAmount")) {
require(value.length == 32, "length of compensateRelayerAmount mismatch");
uint256 newCompensateRelayerAmount = BytesToTypes.bytesToUint256(32, value);
require(newCompensateRelayerAmount >= 0 , "the newCompensateRelayerAmount must be no less than zero");
compensateRelayerAmount = newCompensateRelayerAmount;
} else {
require(false, "unknown param");
}
Expand Down