Commit Graph

134 Commits

Author SHA1 Message Date
r4bbit
76a5f4a232 refactor(RewardsStreamerMP): move totalMpStaked to avoid collision
This field was added in between existing fields, causing a storage
collision and corruption of existing data.
2025-02-20 09:26:54 +01:00
r4bbit
e3d50bf695 specs: fix expected struct size 2025-02-19 17:58:15 +01:00
r4bbit
6f199313ec feat(RewardsStreamerMP): allow vaults to migrate to other vaults
This commit introduces a function `migrateToVault(address)` that allows
`StakeVault`s to migrate to other `StakeVault` instances.

The idea is that, when an upgrade was done on the stake manager, it
might introduces functions that can't be accessed through the stake
vaults that are out there.

Users will have to create new stake vault instances that provide the
necessary functionality.

`migrateToVault()` allows them to do so.

Closes #127
2025-02-19 17:58:15 +01:00
r4bbit
59226ef107 test(RewardsStreamerMP): ensure lock() reverts when vault is empty
Closes #126
2025-02-19 17:29:03 +01:00
Andrea Franz
6b31d3944f feat(RewardsStreamerMP): vaults shares are stakedBalance + mpStaked 2025-02-19 16:53:12 +01:00
r4bbit
a2e18091b2 refactor(RewardsStreamerMP): reuse modifier in enableEmergencyMode() 2025-02-19 16:36:24 +01:00
r4bbit
fb79e249fb fix(RewardsStreamerMP): ensure registerVault reverts in emergency mode
Originally, I just wanted to simplify the certora rule that,
when emergency mode is enabled, only a few selected functions can be
called.

Instead of listing all the view function as "allowed", I've moved to
using CVLs `isView` flag on the function under verification.

This however uncovered a violation where
`RewardsStreamerMP.registerVault` is allowed to be called in emergency
mode.

In theory there's no harm in registering a vault when the system is in
emergency mode, but semantically it doesn't really make sense.

`registerVault` has been accidentally added to `isViewFunction()`.
This commit fixes this by adding `onlyNotEmergencyMode` modifier to
`registerVault()`.
2025-02-19 16:17:10 +01:00
Andrea Franz
51dcb884b3 chore(RewardsStreamerMP): remove MPs from shares/weights calculations 2025-02-18 10:20:22 +01:00
r4bbit
aa67f1f628 chore: make linter happy 2025-02-06 13:21:01 +01:00
r4bbit
70a7f30d2a feat: introduce proxy clones
This commit introduces proxy clones to make create `StakeVault`s as
cheap as possible.

Major changes here are:

- Introduce `VaultFactory` which takes care of creating clones and
  registering them with the stake manager
- Make `StakeVault` and `Initializable` so it can be used as a
  "template" contract to later have proxies point to it
- Adjust the deployment script to also deploy `VaultFactory` and ensure
  The proxy is whitelisted in the stake manager
- Make use of the new proxy clones in tests
- Add a test for `TrustedCodehashAccess` that ensures the proxy
  whitelisting works and setting up a (malicious) proxy is not going to
  work

Closes #101
2025-02-06 13:21:01 +01:00
r4bbit
177aba24d6 refactor: introduce TransparentProxy in favor of StakeManagerProxy
We use `IStakeManagerProxy` to ensure instances of `TransparentProxy`
are stake managers where necessary.
2025-02-06 08:52:53 +01:00
Andrea Franz
80b85083db Update docs/xp-token.md
Co-authored-by: r4bbit <445106+0x-r4bbit@users.noreply.github.com>
2025-02-03 14:03:23 +01:00
Andrea Franz
3e699351e2 docs(XPToken): add documentation about the XP Token 2025-02-03 14:03:23 +01:00
Ricardo Guilherme Schmidt
a22da253c3 refactor(RewardStreamerMP): extract MP and Stake mathematical formulas to abstract contracts 2025-01-30 17:06:16 +01:00
r4bbit
9807f498e0 docs: add documentation with user stories
Closes #33
2025-01-28 18:00:45 +01:00
r4bbit
44deb52c58 refactor: update terminology in contract
Closes #87
2025-01-28 12:20:04 +01:00
r4bbit
1294b76fbd docs(rewards): add documentation about how rewards work (#113) 2025-01-22 13:17:29 +01:00
r4bbit
fe637cbe98 docs(multiplier-points): revise multiplier points documentation 2025-01-22 11:38:11 +01:00
r4bbit
cb43de39b9 chore(scripts): add deployment config for sepolia 2025-01-22 11:33:28 +01:00
Ricardo Guilherme Schmidt
26f76d4376 chore(docs): mathspec v1 (#67)
* chore(docs): mathspec v1
2025-01-13 12:17:08 -03:00
Ricardo Guilherme Schmidt
52dad3d1c1 chore(docs/multiplier-points.md): Workaround GitHub Markdown bug 2024-12-23 13:14:50 +01:00
Ricardo Guilherme Schmidt
ebfa2a75bc chore(docs/multiplier-points.md): Fix formatting for GitHub Markdown 2024-12-23 13:14:50 +01:00
Ricardo Guilherme Schmidt
db92a2deda chore(docs/multiplier-points.md): Add guide to multiplier poitns 2024-12-23 13:14:50 +01:00
r4bbit
1cc0c1680b cleanup: remove unused RewardStreamer contract
This was some version of the staking contract for demonstration purposes
and is not actually used as we're working on `RewardStreamerMP` version,
which is aware of multiplier points.

Closes #84
2024-12-20 12:28:45 +01:00
r4bbit
aa15954d0c fix(RewardsStreamerMP): change account mp update time only if necessary
Closes #52
2024-12-20 12:20:04 +01:00
Andrea Franz
e8162d7c9e chore(XPToken): rename XP to Reward providers and use the rewardsBalanceOfUser function 2024-12-20 08:52:00 +01:00
Andrea Franz
a413f4cbbb feat(RewardsStreamerMP): rewardsBalanceOf uses account's accrued + pending MPs 2024-12-20 07:40:55 +01:00
Andrea Franz
f601050dbe refactor(RewardsStreamerMP): rename functions to be appropriate 2024-12-20 07:40:55 +01:00
r4bbit
b5ce251b8e feat(scripts): add upgrade script
This introduces a simple upgrade script template that can be used to
upgrade the stake manager.
2024-12-10 13:26:33 +01:00
Ricardo Guilherme Schmidt
eff15a8ade fix(RewardStreamerMP.t): minor fix on use of variables 2024-12-09 16:24:32 +01:00
Ricardo Guilherme Schmidt
6afc760974 feat(RewardsStreamerMP.t.sol): Make tests use calc functions and test those functions
chore(linter): added solhint-disable-next-line max-line-length to circumvent bug in linter

chore(RewardsStreamerMP.t.sol): rename _calculateTimeToMP -> _calculateTimeToAccureMP
2024-12-09 16:24:32 +01:00
r4bbit
a565dbbac4 feat: introduce deployment script for RewardsStreamerMP
This commit introduces a deployment script for the stake manager which
can later be extended to work with other networks.

The deployment script is also used inside our testsuite, ensuring it's
working as intended.

Closes #88
2024-12-09 14:31:03 +01:00
Ricardo Guilherme Schmidt
106ec98839 fix(EmergencyMode.spec): add YEAR() to isViewFunction 2024-12-06 12:44:51 +01:00
Ricardo Guilherme Schmidt
204bdef3ca refactor(RewardsStreamerMP): simplify bonusMP formula 2024-12-06 12:44:51 +01:00
r4bbit
ebfb426d0b refactor(RewardsStreamerMP): use Math.mulDiv to reduce likelyhood of
precision loss

Closes #85
2024-12-06 12:44:51 +01:00
r4bbit
bca74ce1f1 docs(system-overview.md): add system overview docs
This commit introduces the first documentation which provides an
overview of the staking system and how accounts will interact with it.

Closes #30
2024-12-05 08:04:46 +01:00
r4bbit
c041d5dd85 test: formally verify that MPs only decrease when unstaking/leaving 2024-12-05 08:04:29 +01:00
r4bbit
be89292abd cleanup(RewardsStreamerMP): remove unnecessary writes to account.lastMPupdateTime
Whenever `account.lastMPupdateTime` is set, we also call
`_updateAccountMP()` before that, which never reverts, so the value set
there will never differ from the ones we set later explicitly.

Closes #80
2024-12-05 08:04:13 +01:00
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