-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from ava-labs/staking-rewards
Staking rewards
- Loading branch information
Showing
29 changed files
with
1,704 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
39 changes: 31 additions & 8 deletions
39
abi-bindings/go/staking/ERC20TokenStakingManager/ERC20TokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
327 changes: 327 additions & 0 deletions
327
abi-bindings/go/staking/ExampleRewardCalculator/ExampleRewardCalculator.go
Large diffs are not rendered by default.
Oops, something went wrong.
70 changes: 62 additions & 8 deletions
70
abi-bindings/go/staking/NativeTokenStakingManager/NativeTokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/PoAValidatorManager/PoAValidatorManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
|
@@ -13,12 +13,13 @@ import { | |
ERC20Burnable, | ||
ERC20 | ||
} from "@openzeppelin/[email protected]/token/ERC20/extensions/ERC20Burnable.sol"; | ||
import {IERC20Mintable} from "../staking/interfaces/IERC20Mintable.sol"; | ||
|
||
contract ExampleERC20 is ERC20Burnable { | ||
contract ExampleERC20 is ERC20Burnable, IERC20Mintable { | ||
string private constant _TOKEN_NAME = "Mock Token"; | ||
string private constant _TOKEN_SYMBOL = "EXMP"; | ||
|
||
uint256 private constant _MAX_MINT = 1e16; | ||
uint256 private constant _MAX_MINT = 1e19; | ||
|
||
constructor() ERC20(_TOKEN_NAME, _TOKEN_SYMBOL) { | ||
_mint(msg.sender, 1e28); | ||
|
@@ -30,4 +31,11 @@ contract ExampleERC20 is ERC20Burnable { | |
|
||
_mint(msg.sender, amount); | ||
} | ||
|
||
function mint(address account, uint256 amount) external { | ||
// Can only mint 10 at a time. | ||
require(amount <= _MAX_MINT, "ExampleERC20: max mint exceeded"); | ||
|
||
_mint(account, amount); | ||
} | ||
} |
This file contains 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 |
---|---|---|
|
@@ -8,7 +8,7 @@ pragma solidity 0.8.25; | |
import {IERC20TokenStakingManager} from "./interfaces/IERC20TokenStakingManager.sol"; | ||
import {Initializable} from | ||
"@openzeppelin/[email protected]/proxy/utils/Initializable.sol"; | ||
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol"; | ||
import {IERC20Mintable} from "./interfaces/IERC20Mintable.sol"; | ||
import {SafeERC20TransferFrom} from "@utilities/SafeERC20TransferFrom.sol"; | ||
import {SafeERC20} from "@openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol"; | ||
import {ICMInitializable} from "../utilities/ICMInitializable.sol"; | ||
|
@@ -21,13 +21,13 @@ contract ERC20TokenStakingManager is | |
PoSValidatorManager, | ||
IERC20TokenStakingManager | ||
{ | ||
using SafeERC20 for IERC20; | ||
using SafeERC20TransferFrom for IERC20; | ||
using SafeERC20 for IERC20Mintable; | ||
using SafeERC20TransferFrom for IERC20Mintable; | ||
|
||
// solhint-disable private-vars-leading-underscore | ||
/// @custom:storage-location erc7201:avalanche-icm.storage.ERC20TokenStakingManager | ||
struct ERC20TokenStakingManagerStorage { | ||
IERC20 _token; | ||
IERC20Mintable _token; | ||
uint8 _tokenDecimals; | ||
} | ||
// solhint-enable private-vars-leading-underscore | ||
|
@@ -63,22 +63,25 @@ contract ERC20TokenStakingManager is | |
*/ | ||
function initialize( | ||
PoSValidatorManagerSettings calldata settings, | ||
IERC20 token | ||
IERC20Mintable token | ||
) external reinitializer(2) { | ||
__ERC20TokenStakingManager_init(settings, token); | ||
} | ||
|
||
// solhint-disable func-name-mixedcase | ||
function __ERC20TokenStakingManager_init( | ||
PoSValidatorManagerSettings calldata settings, | ||
IERC20 token | ||
IERC20Mintable token | ||
) internal onlyInitializing { | ||
__POS_Validator_Manager_init(settings); | ||
__ERC20TokenStakingManager_init_unchained(token); | ||
} | ||
|
||
// solhint-disable func-name-mixedcase | ||
function __ERC20TokenStakingManager_init_unchained(IERC20 token) internal onlyInitializing { | ||
function __ERC20TokenStakingManager_init_unchained(IERC20Mintable token) | ||
internal | ||
onlyInitializing | ||
{ | ||
ERC20TokenStakingManagerStorage storage $ = _getERC20StakingManagerStorage(); | ||
require(address(token) != address(0), "ERC20TokenStakingManager: zero token address"); | ||
$._token = token; | ||
|
@@ -116,7 +119,12 @@ contract ERC20TokenStakingManager is | |
return _getERC20StakingManagerStorage()._token.safeTransferFrom(value); | ||
} | ||
|
||
function _unlock(uint256 value, address to) internal virtual override { | ||
function _unlock(address to, uint256 value) internal virtual override { | ||
_getERC20StakingManagerStorage()._token.safeTransfer(to, value); | ||
} | ||
|
||
function _reward(address account, uint256 amount) internal virtual override { | ||
ERC20TokenStakingManagerStorage storage $ = _getERC20StakingManagerStorage(); | ||
$._token.mint(account, amount); | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
pragma solidity 0.8.25; | ||
|
||
import {INativeTokenStakingManager} from "./interfaces/INativeTokenStakingManager.sol"; | ||
import {INativeMinter} from | ||
"@avalabs/[email protected]/contracts/interfaces/INativeMinter.sol"; | ||
import {Address} from "@openzeppelin/[email protected]/utils/Address.sol"; | ||
import {Initializable} from | ||
"@openzeppelin/[email protected]/proxy/utils/Initializable.sol"; | ||
|
@@ -21,6 +23,9 @@ contract NativeTokenStakingManager is | |
{ | ||
using Address for address payable; | ||
|
||
INativeMinter public constant NATIVE_MINTER = | ||
INativeMinter(0x0200000000000000000000000000000000000001); | ||
|
||
constructor(ICMInitializable init) { | ||
if (init == ICMInitializable.Disallowed) { | ||
_disableInitializers(); | ||
|
@@ -80,7 +85,11 @@ contract NativeTokenStakingManager is | |
return value; | ||
} | ||
|
||
function _unlock(uint256 value, address to) internal virtual override { | ||
function _unlock(address to, uint256 value) internal virtual override { | ||
payable(to).sendValue(value); | ||
} | ||
|
||
function _reward(address account, uint256 amount) internal virtual override { | ||
NATIVE_MINTER.mintNativeCoin(account, amount); | ||
} | ||
} |
Oops, something went wrong.