Commit Graph

96 Commits

Author SHA1 Message Date
r4bbit
6814995f49 test: make max MP test stronger
As mentioned in #82, increasing `currentTime` by 1 second isn't enough
to actually create new MPs, so the test could return false positives.

This change increases the time between checks arbritraryly longer, such
that MPs would actually be created if the max MP wasn't reached.

Closes #82
2024-12-05 08:03:15 +01:00
r4bbit
9374025924 feat(StakeManager): add capabilities to register vaults
This commit introduces changes related to vault registrations in the
stake manager.

The stake manager needs to keep track of the vaults a users creates so
it can aggregate accumulated MP across vaults for any given user.

The `StakeVault` now comes with a `register()` function which needs to
be called to register itself with the stake manager. `StakeManager` has
a new `onlyRegisteredVault` modifier that ensures only registered vaults
can actually `stake` and `unstake`.

Closes #70
2024-12-03 16:55:34 +01:00
r4bbit
a0581feb27 chore(RewardsStreamerMP): add Initializable to inheritance
Looks like we've forgotten about this. `Initializable` is imported but
not applied on the contract.
2024-12-03 13:53:11 +01:00
Andrea Franz
b1a4e5ad37 fix(RewardsStreamerMP): rename _calculateAccruedRewards to _calculatePendingRewards and fix specs 2024-12-03 13:50:52 +01:00
Andrea Franz
7211b493f7 test(RewardsStreamerMP): fix EmergencyMode spec 2024-12-03 13:50:52 +01:00
Andrea Franz
dffaea2a73 feat(RewardsStreamerMP): stream rewards for a period without checking a real reward token balance 2024-12-03 13:50:52 +01:00
Andrea Franz
21af34b5b7 test(RewardsStreamerMP): test setReward reverts 2024-12-03 13:50:52 +01:00
Andrea Franz
56e92444e0 feat(RewardsStreamerMP): rewards are streamed and dynamically "minted" 2024-12-03 13:50:52 +01:00
r4bbit
4968ad4ea6 test(RewardsStreamerMP): add test to ensure funds are saffe when stack overflow
If there's a malicious upgrade which causes a stack overflow error when
`leave()` is called, the user of the vault should still be able to get
their funds out.

This commit adds a test that proofs this is happening.
2024-12-01 08:25:36 +01:00
r4bbit
fcfe72d050 feat(RewardsStreamerMP): introduce leave() function
This function allows users to `leave()` the system if they can't or
don't want to trust the stake manager. This is the case when the owner
of the stake manager performs an upgrade.

In case of such an upgrade, the stake manager will be marked as not
trusted which prevents the user from staking, unstaking, locking etc.

The user can then either explicitly trust stake manager (will happen in
future changes) to enable the vault's functionality again, or, `leave()`
the system at which point it will try to perform a benign `leave()`
operation and then move the funds out of the vault.

Closes #66
2024-12-01 08:25:36 +01:00
Ricardo Guilherme Schmidt
8561a68ffd feat(RewardsStreamerMP): make RewardsStreamerMP upgradeable
This commit introduces upgradeability of the `RewardsStreamerMP`
contract by leveraging the UUPS pattern.

This means, for deployment, we have to first deploy an instance of
`RewardsStreamerMP` contract as a "template" logic contract and then
create a ERC1967Proxy that points to it.

The proxy ensures the implementation address is stored in a
deterministic storage slot.

This will later be leveraged by the `StakeVault` contract to implement
the functionality to leave the system in case there was a malicious
upgrade.

Closes #22
2024-12-01 08:06:51 +01:00
r4bbit
e823711c9a test(StakeVault): add test to ensure users cannot withdraw without unstaking 2024-12-01 07:56:30 +01:00
r4bbit
e8d880e4ea test(StakeVault): introduce test file for StakeVault 2024-11-30 12:58:47 +01:00
r4bbit
1e703e3f71 feat(RewardStreamerMP): add emergency mode so users can exit the system
This adds a new emergency mode that can be enabled by the owner of the system.
When in emergency mode, stakers or `StakeVault`s can leave the system immediately.

This also applies when there was a malicious upgrade and a call to
`emergencyModeEnabled()` panics.

To have this in a fully secure manner, we still have to add the counter
part of "leaving" the system. This will allow users that don't agree
with a (malicious) upgrade to get their funds out of the vaults
regardless.

Closes #66
2024-11-28 08:27:58 +01:00
r4bbit
5bc7ebf963 feat(RewardsStreamerMP): add lock(uint256) function
This adds a `lock()` function to the staking contract, allowing vaults
to lock their funds after they have staked in the past.

Closes #40
2024-11-01 14:32:02 +01:00
r4bbit
91cd844dd6 chore(certora): formally verify StakeVault account balance vs ERC20
balance

Closes #29
2024-10-30 12:52:21 +01:00
r4bbit
6fea58b334 feat: add TrustedCodehashAccess contract and interface
This enables whitelisting in the staking manager contract using the
`TrustedCodehashAccess` interface.

These changes were largely taken from #39 with few changes:

- Due to different OZ versions, `Ownable()` constructor needs to be
  called with owner

Closes #15
2024-10-22 12:03:09 +02:00
r4bbit
18a8465d58 chore: introduce IStakeManager interface
This introduces a first version of `IStakeManager`, highly inspired by
the changes done in
https://github.com/vacp2p/staking-reward-streamer/pull/39.

However, in this commit, it only adds the methods that are currently
supported by both, `StakeManager` and `RewardStreamerMP`.

Future commits will add APIs for locking and leaving.
2024-10-22 11:05:45 +02:00
r4bbit
0e14b7b3a6 feat: introduce StakeVault
This ports the `StakeVault` contract over to this repository
and exposes functions to interface with the reward streamer contract
to address issue #14.

Closes #14
2024-10-22 11:05:45 +02:00
r4bbit
ba26e7cc79 refactor(RewardStreamerMP): rename user vars to account
Closes #59
2024-10-21 13:49:29 +02:00
Andrea Franz
753c62db3a chore: update gas report 2024-10-18 15:25:54 +02:00
Andrea Franz
c54ad8f361 feat(XPToken): introduce mintAllowance. cannot mint if totalSupply is >= external supply * 3 2024-10-18 15:25:54 +02:00
Andrea Franz
c6623c3d34 feat(XPToken): external supply and balances are 1:1 to providers numbers 2024-10-18 15:25:54 +02:00
Andrea Franz
7e7c51302c feat(XPToken): XPToken extends ERC20 and use its balanceOf/totalSupply adding external supply/balances 2024-10-18 15:25:54 +02:00
r4bbit
044301869a chore(certora): dont wait for results 2024-10-18 14:51:36 +02:00
r4bbit
ad2d11d138 chore(certora): add rule that greater lockup means greater MPs
Closes #28
2024-10-18 14:25:14 +02:00
r4bbit
77d77b8017 chore(certora): add rule that MPs are minted at 1-to-1 ratio
Closes #27
2024-10-18 13:56:15 +02:00
Andrea Franz
7799fde5b2 feature(XPToken): upgrade to Ownable2Step 2024-10-18 13:55:46 +02:00
Ricardo Guilherme Schmidt
2ee6eb8065 test(RewardsStreamerMP): ensure bonusMP and maxMP are decreased 2024-10-16 14:55:59 +02:00
r4bbit
8de2f2ae0b test(RewardsStreamerMP): ensure bonusMP and maxMP are decreased
correctly at unstake

This commit adds some tests to check that, if a user (partically)
unstakes their funds, their initial and bonus MP get decreased
proportionally, as well as their max mp.

Closes #46
2024-10-16 14:55:59 +02:00
r4bbit
b79deb70f5 chore(certora): add accountMPGreaterEqualsAccountBalance invariant
Closes #26
2024-10-16 14:01:51 +02:00
r4bbit
59f2566c78 refactor(RewardStreamerMP): keep track of maxMP instead of
`potentialMP`

This commit changes the mechanics to ensure there are no more MP
generated that what's allowed as per max limiting.

Previously we've kept track of `potentialMP` which would decrease as
more MP are generated.

This made verifying certain rules on certora hard and/or impossible.
So we decided to track `maxMP` instead, which only decreases when users
unstake.

This commit also introduces a rule that ensures any accounts MP never
exceed their max mp.

Closes #44
2024-10-16 12:44:47 +02:00
r4bbit
3eb4aa830e chore(certora): add sumOfBalancesIsTotalStaked invariant
Closes #24
2024-10-14 12:04:52 +02:00
Andrea Franz
0b3768d259 chore: remove linter warning and errors 2024-10-14 11:58:28 +02:00
Andrea Franz
43536a4dca feat(XPNFTToken): add NFTMetadataGeneratorURL 2024-10-14 11:58:28 +02:00
Andrea Franz
9253b0bd55 test(XPNFTToken): add tests to NFTMetadataGeneratorSVG 2024-10-14 11:58:28 +02:00
Andrea Franz
b5517a2828 test(XPNFTToken): add tests 2024-10-14 11:58:28 +02:00
Andrea Franz
e4e8c7c505 chore(XPNFTToken): add INFTMetadataGenerator with Base and SVG generator 2024-10-14 11:58:28 +02:00
Andrea Franz
7352f8837a feat(XPNFTToken): add XPNFTMetadataGenerator 2024-10-14 11:58:28 +02:00
Andrea Franz
7ed87fada9 feat(XPNFTToken): add base XPNFTToken 2024-10-14 11:58:28 +02:00
Andrea Franz
74522424e6 chore: update gas reports 2024-10-11 16:56:03 +02:00
Andrea Franz
966093e575 chore(XPToken): rename local variables to use the suffix share instead of contribution 2024-10-11 16:56:03 +02:00
Andrea Franz
b9c34ec48e chore(XPToken): use share instead of contribution in IXPProvider function names 2024-10-11 16:56:03 +02:00
Andrea Franz
478174a356 chore(XPToken): add certora base config 2024-10-11 16:56:03 +02:00
Andrea Franz
117fc2300e test(XPToken): add tests 2024-10-11 16:56:03 +02:00
Andrea Franz
0a5563e387 chore(XPToken): use XP Contribution for providers functions 2024-10-11 16:56:03 +02:00
Andrea Franz
4b787d478f chore: update libs 2024-10-11 16:56:03 +02:00
Andrea Franz
f816755340 feat(XPToken): add base XPToken with IXPProvider interface 2024-10-11 16:56:03 +02:00
r4bbit
286bfd2ff4 test: add tests for reaching MP limit
Closes #4
2024-10-09 11:45:33 +02:00
r4bbit
0af58f90fb fix: improve precision loss when unstaking and add testso
This commit changes the calculation for when MPs are reduced globally
and for the user that is unstaking.

Instead of getting an `amountRatio` first and using that the
multiplication, we're now applying the `SCALE_FACTOR` to both, the
numerator and denominator to maintain the ratio while increasing
precision.
2024-10-09 11:41:48 +02:00