-
Notifications
You must be signed in to change notification settings - Fork 14
Add Incentives Predeploy #106
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
43c2c75
add incentives predeploy
ferrell-code a076e98
use calldata for inputs
ferrell-code 48e66e6
add comments and readme
ferrell-code 5aa1dd4
change to call from staticcall
ferrell-code e435d64
uint128 to uint256 for balances
ferrell-code e7834b1
update readme
ferrell-code File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./InterfaceIncentives.sol"; | ||
|
|
||
| contract Incentives is InterfaceIncentives { | ||
| address constant private precompile = address(0x000000000000000000000000000000000000040A); | ||
|
|
||
| /** | ||
| * @dev Gets reward amount in `rewardCurrency` added per period | ||
| * Returns (reward_amount) | ||
| */ | ||
| function getIncentiveRewardAmount(PoolId pool, address poolCurrencyId, address rewardCurrencyId) | ||
| public | ||
| view | ||
| override | ||
| returns (uint256) { | ||
| (bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getIncentiveRewardAmount(PoolId,address,address)", pool, poolCurrencyId, rewardCurrencyId)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| return abi.decode(returnData, (uint256)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Fixed reward rate for dex reward pool per period | ||
| * returns (dex_reward_rate) as a FixedU128 representing a decimal value | ||
| */ | ||
| function getDexRewardRate(address currencyId) | ||
| public | ||
| view | ||
| override | ||
| returns (uint256) { | ||
| (bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getDexRewardRate(address)", currencyId)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| return abi.decode(returnData, (uint256)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Stake LP token to add shares to PoolId::Dex | ||
| * Returns a boolean value indicating whether the operation succeeded. | ||
| */ | ||
| function depositDexShare(address currencyId, uint256 amount) | ||
| public | ||
| override | ||
| returns (bool) { | ||
| require(amount != 0, "Incentives: amount is zero"); | ||
|
|
||
| (bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("depositDexShare(address,address,uint256)", msg.sender, currencyId, amount)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| emit DepositedShare(msg.sender, currencyId, amount); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Unstake LP token to remove shares from PoolId::Dex | ||
| * Returns a boolean value indicating whether the operation succeeded. | ||
| */ | ||
| function withdrawDexShare(address currencyId, uint256 amount) | ||
| public | ||
| override | ||
| returns (bool) { | ||
| require(amount != 0, "Incentives: amount is zero"); | ||
|
|
||
| (bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("withdrawDexShare(address,address,uint256)", msg.sender, currencyId, amount)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| emit WithdrewShare(msg.sender, currencyId, amount); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Claim all avalible multi currencies rewards for specific PoolId | ||
| * Returns a boolean value indicating whether the operation succeeded. | ||
| */ | ||
| function claimRewards(PoolId pool, address poolCurrencyId) | ||
| public | ||
| override | ||
| returns (bool) { | ||
| (bool success, bytes memory returnData) = precompile.call(abi.encodeWithSignature("claimRewards(address,PoolId,address)", msg.sender, pool, poolCurrencyId)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| emit ClaimedRewards(msg.sender, pool, poolCurrencyId); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Gets deduction rate for claiming reward early | ||
| * returns (claim_reward_deduction_rate) as a FixedU128 representing a decimal value | ||
| */ | ||
| function getClaimRewardDeductionRate(PoolId pool, address poolCurrencyId) | ||
| public | ||
| view | ||
| override | ||
| returns (uint256) { | ||
| (bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getClaimRewardDeductionRate(PoolId,address)", pool, poolCurrencyId)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| return abi.decode(returnData, (uint256)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Gets the pending rewards for a pool, actual reward could be deducted. | ||
| * returns (balances), an array of reward balances corresponding to currencyIds | ||
| */ | ||
| function getPendingRewards(address[] calldata currencyIds, PoolId pool, address poolCurrencyId, address who) | ||
| public | ||
| view | ||
| override | ||
| returns (uint256[] memory) { | ||
| (bool success, bytes memory returnData) = precompile.staticcall(abi.encodeWithSignature("getPendingRewards(address[],PoolId,address,address)", currencyIds, pool, poolCurrencyId, who)); | ||
| assembly { | ||
| if eq(success, 0) { | ||
| revert(add(returnData, 0x20), returndatasize()) | ||
| } | ||
| } | ||
|
|
||
| return abi.decode(returnData, (uint256[])); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| interface InterfaceIncentives { | ||
| event DepositedShare(address indexed sender, address indexed currencyId, uint256 amount); | ||
| event WithdrewShare(address indexed sender, address indexed currencyId, uint256 amount); | ||
| event ClaimedRewards(address indexed sender, PoolId indexed pool, address indexed poolCurrencyId); | ||
| enum PoolId { LOANS, DEX } | ||
|
|
||
| // Gets reward amount in `rewardCurrency` added per period | ||
| // Returns (reward_amount) | ||
| function getIncentiveRewardAmount(PoolId pool, address poolCurrencyId, address rewardCurrencyId) external view returns (uint256); | ||
|
|
||
| // Fixed reward rate for dex reward pool per period | ||
| // Returns (dex_reward_rate) as a FixedU128 representing a decimal | ||
| function getDexRewardRate(address currencyId) external view returns (uint256); | ||
|
|
||
| // Stake LP token to add shares to PoolId::Dex | ||
| // Returns a boolean value indicating whether the operation succeeded. | ||
| function depositDexShare(address currencyId, uint256 amount) external returns (bool); | ||
|
|
||
| // Unstake LP token to remove shares from PoolId::Dex | ||
| // Returns a boolean value indicating whether the operation succeeded. | ||
| function withdrawDexShare(address currencyId, uint256 amount) external returns (bool); | ||
|
|
||
| // Claim all avalible multi currencies rewards for specific PoolId | ||
| // Returns a boolean value indicating whether the operation succeeded. | ||
| function claimRewards(PoolId pool, address poolCurrencyId) external returns (bool); | ||
|
|
||
| // Gets deduction rate for claiming reward early | ||
| // returns (claim_reward_deduction_rate) as a FixedU128 representing a decimal value | ||
| function getClaimRewardDeductionRate(PoolId pool, address poolCurrencyId) external view returns (uint256); | ||
|
|
||
| // Gets the pending rewards for a pool, actual reward could be deducted. | ||
| // returns (balances), an array of reward balances corresponding to currencyIds | ||
| function getPendingRewards(address[] calldata currencyIds, PoolId pool, address poolCurrencyId, address who) external view returns (uint256[] memory); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.