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 2 commits
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
12 changes: 11 additions & 1 deletion 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 dynamicExtraIncentiveAmount;

event distributeCollectedReward(uint256 sequence, uint256 roundRewardForHeaderRelayer, uint256 roundRewardForTransferRelayer);
event paramChange(string key, bytes value);
event rewardToRelayer(address relayer, uint256 amount);
Expand All @@ -59,9 +61,12 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {

uint256 actualAmount;
if (fromSystemReward) {
actualAmount = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
actualAmount = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount.add(dynamicExtraIncentiveAmount));
} else {
actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
if (dynamicExtraIncentiveAmount > 0) {
actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount));
}
}

countInRound++;
Expand Down Expand Up @@ -216,6 +221,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,"dynamicExtraIncentiveAmount")) {
require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch");
uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value);
require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero");
dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount;
} else {
require(false, "unknown param");
}
Expand Down
12 changes: 11 additions & 1 deletion 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 dynamicExtraIncentiveAmount;

event distributeCollectedReward(uint256 sequence, uint256 roundRewardForHeaderRelayer, uint256 roundRewardForTransferRelayer);
event paramChange(string key, bytes value);
event rewardToRelayer(address relayer, uint256 amount);
Expand All @@ -61,9 +63,12 @@ contract RelayerIncentivize is IRelayerIncentivize, System, IParamSubscriber {
{% endif %}
uint256 actualAmount;
if (fromSystemReward) {
actualAmount = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
actualAmount = ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount.add(dynamicExtraIncentiveAmount));
} else {
actualAmount = ISystemReward(TOKEN_HUB_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), amount);
if (dynamicExtraIncentiveAmount > 0) {
actualAmount = actualAmount.add(ISystemReward(SYSTEM_REWARD_ADDR).claimRewards(address(uint160(INCENTIVIZE_ADDR)), dynamicExtraIncentiveAmount));
}
}

countInRound++;
Expand Down Expand Up @@ -218,6 +223,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,"dynamicExtraIncentiveAmount")) {
require(value.length == 32, "length of dynamicExtraIncentiveAmount mismatch");
uint256 newDynamicExtraIncentiveAmount = BytesToTypes.bytesToUint256(32, value);
require(newDynamicExtraIncentiveAmount >= 0 , "the newDynamicExtraIncentiveAmount must be no less than zero");
dynamicExtraIncentiveAmount = newDynamicExtraIncentiveAmount;
} else {
require(false, "unknown param");
}
Expand Down