-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue ERC20 staking rewards (native rewards TBD)
- Loading branch information
Showing
16 changed files
with
395 additions
and
1,211 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/ERC20TokenStakingManager/ERC20TokenStakingManager.go
Large diffs are not rendered by default.
Oops, something went wrong.
296 changes: 296 additions & 0 deletions
296
abi-bindings/go/staking/ExampleRewardCalculator/ExampleRewardCalculator.go
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
abi-bindings/go/staking/NativeTokenStakingManager/NativeTokenStakingManager.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
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
This file was deleted.
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import {ERC20TokenStakingManager} from "../ERC20TokenStakingManager.sol"; | |
import {ValidatorManagerSettings} from "../interfaces/IValidatorManager.sol"; | ||
import {PoSValidatorManagerSettings} from "../interfaces/IPoSValidatorManager.sol"; | ||
import {IRewardCalculator} from "../interfaces/IRewardCalculator.sol"; | ||
import {ExampleRewardCalculator} from "../ExampleRewardCalculator.sol"; | ||
import {ICMInitializable} from "../../utilities/ICMInitializable.sol"; | ||
import {ExampleERC20} from "@mocks/ExampleERC20.sol"; | ||
import {IERC20} from "@openzeppelin/[email protected]/token/ERC20/IERC20.sol"; | ||
|
@@ -23,11 +24,13 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
|
||
ERC20TokenStakingManager public app; | ||
IERC20Mintable public token; | ||
ExampleRewardCalculator public rewardCalculator; | ||
|
||
function setUp() public virtual { | ||
// Construct the object under test | ||
app = new ERC20TokenStakingManager(ICMInitializable.Allowed); | ||
token = new ExampleERC20(); | ||
rewardCalculator = new ExampleRewardCalculator(DEFAULT_REWARD_RATE); | ||
app.initialize( | ||
PoSValidatorManagerSettings({ | ||
baseSettings: ValidatorManagerSettings({ | ||
|
@@ -38,7 +41,7 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
minimumStakeAmount: DEFAULT_MINIMUM_STAKE, | ||
maximumStakeAmount: DEFAULT_MAXIMUM_STAKE, | ||
minimumStakeDuration: DEFAULT_MINIMUM_STAKE_DURATION, | ||
rewardCalculator: IRewardCalculator(address(0)) | ||
rewardCalculator: rewardCalculator | ||
}), | ||
token | ||
); | ||
|
@@ -47,26 +50,36 @@ contract ERC20TokenStakingManagerTest is PoSValidatorManagerTest { | |
} | ||
|
||
function testCompleteEndValidation() public override { | ||
uint256 registrationDuration = 1000*60*60*24; // 1 day | ||
|
||
uint256 registrationExpiry = vm.getBlockTimestamp() + registrationDuration; | ||
|
||
bytes32 validationID = _setUpInitializeEndValidation({ | ||
nodeID: DEFAULT_NODE_ID, | ||
subnetID: DEFAULT_SUBNET_ID, | ||
weight: DEFAULT_WEIGHT, | ||
registrationExpiry: DEFAULT_EXPIRY, | ||
registrationExpiry: uint64(registrationExpiry), | ||
blsPublicKey: DEFAULT_BLS_PUBLIC_KEY, | ||
registrationTimestamp: DEFAULT_REGISTRATION_TIMESTAMP, | ||
completionTimestamp: DEFAULT_COMPLETION_TIMESTAMP | ||
completionTimestamp: uint64(registrationExpiry) | ||
}); | ||
|
||
address validator = address(this); | ||
|
||
uint256 balanceBefore = token.balanceOf(validator); | ||
|
||
uint256 expectedReward = DEFAULT_WEIGHT * DEFAULT_REWARD_RATE / 365 - 1; | ||
|
||
vm.expectCall(address(token), abi.encodeCall(IERC20.transfer, (validator, DEFAULT_WEIGHT))); | ||
vm.expectCall(address(token), abi.encodeCall(IERC20Mintable.mint, (validator, expectedReward))); | ||
|
||
_testCompleteEndValidation(validationID); | ||
|
||
uint256 balanceChange = token.balanceOf(validator) - balanceBefore; | ||
require(balanceChange == DEFAULT_WEIGHT, "validator should have received their stake back"); | ||
require( | ||
balanceChange == DEFAULT_WEIGHT + expectedReward, | ||
"validator should have received their stake back and gotten rewarded" | ||
); | ||
} | ||
|
||
function _initializeValidatorRegistration( | ||
|
113 changes: 0 additions & 113 deletions
113
contracts/staking/tests/ERC20TokenStakingManagerTests.t.sol.orig
This file was deleted.
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
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
Oops, something went wrong.