Commit Graph

71 Commits

Author SHA1 Message Date
Ricardo Guilherme Schmidt
8bebfbc9d2 refactor(StakeManager, StakeVault): decouple StakeManager <-> StakeVault
- BREAKING CHANGE: Updated stake and lock functions in StakeManager to accept an additional parameter for current lock until timestamp.
- BREAKING CHANGE: Modified StakeVault to handle the new locking mechanism and removed the old updateLockUntil function.
- Adjusted related tests to reflect changes in function signatures and expected behaviors.
- Ensured that funds locked checks are properly referenced in tests and contracts.
2025-08-13 10:37:40 -03:00
Ricardo Guilherme Schmidt
48e6903b33 refactor(StakeVault): Remove obsolete trust stake manager logic (#237) 2025-08-06 09:11:22 -03:00
Ricardo Guilherme Schmidt
753e379682 chore(forge fmt): change line lenght to 119 to avoid conflicts with solhint 2025-06-05 13:56:52 +02:00
r4bbit
05cccfc662 refactor(StakeManager): move lockUntil into StakeVault
Most of the reasoning has been discussed in #208.
Primarily what's happening here is:

- `StakeManager.VaultData.lockUntil` has been removed
- `StakeVault.lockUntil` has been introduced
- `StakeVault.updateLockUntil(uint256 value)` has been introduced
- `StakeVault.leave()` performs normal `leave()` action but keeps funds
  in vault if lockup period hasn't expired
- `StakeVault.withdrawFromVault()` has been introduced to withdraw
  remaining *stake* funds in vault

BREAKING CHANGE:

- `StakeManager.VaultData.lockUntil` has been removed
- `StakeVault.lockUntil` has been introduced
- `StakeVault.leave()` performs normal `leave()` action but keeps funds
  in vault if lockup period hasn't expired

Closes #208
2025-05-13 14:05:02 +02:00
r4bbit
309d765731 refactor(DeploymentConfig): remove proxy implementation address
This was a bandaid solution to easily allow for upgrade scripts.
We've changed those now to expect environment variables instead.
This allows us to change the dependencies without committing them to
version control.
2025-04-02 16:56:16 +02:00
r4bbit
22feed8dba fix(StakeManager): don't allow migrating to unregistered vaults
This was uncovered when a user tried to migrate a `StakeVault` from one
deployed `StakeManager` to a vault that was registered with a different
`StakeManager` instance.

The result was that the data of the vault has been indeed migrated to
the new vault, however, since the vault queries stake data from the
`StakeManager`, the new vault is unable to properly calculated balances
to withdraw funds, among other things.

It shouldn't be possible to migrate to a vault that isn't registered
with the system a user migrates from, in the first place.

This commit ensures that by reverting when the `migrateTo` address isn't
a registered vault with the `StakeManager`.
2025-04-01 16:10:02 +02:00
r4bbit
801740f74f !refactor(RewardsStreamerMP): rename RewardsStreamerMP to StakeManager
This renames `RewardsStreamerMP` to `StakeManager`. The original name
only exists because the project has started with different versions of
the contract. Since the contract is no longer just dealing with MPs but
actually distributes rewards, it makes sense to make this the official
stake manager of the protocol.

**BREAKING CHANGE:**

- `RewardsStreamerMP` is now `StakeManager`
- `StakingManager__*` error selectors are now `StakeManager__*`
  selectors
2025-03-28 14:45:31 +01:00
r4bbit
7bd0c16872 !refactor(RewardsStreamerMP): remove VaultData.mpStaked
After doing somme work on merging `compound()` into `updateVault()`, we
noticed that both, `vault.mpStaked` and `vault.mpAccrued` are always
equal.

Therefore, we're removing `vault.mpStaked`.

BREAKING CHANGE:

- `VaultData.mpStaked` no longer exists, use `VaultData.mpAccrued`
instead.

- `Compound(address,uint256)` is now `VaultUpdated(address,uint256,uint256)`

- `AccountLeft(address)` is now `VaultLeft(address)`
2025-03-26 13:19:05 +01:00
Ricardo Guilherme Schmidt
8df475aab8 fix(StakeManager): Allow extending the lock after increasing stake to allow account reaching absolute max MP
fix(MultiplierPointMath): Fix helper function to correctly estimate avaliable lock time

chore(spec): remove additional field which does not exist anymore
2025-03-25 17:14:17 +01:00
r4bbit
2e01e0d03b refactor(RewardsStreamerMP): merge compound() with _updateVault()
This commit merges `compound()` into `_updateVault()` as there's no
reason not to update vault without compounding it.

This was discussed in #187.

BREAKING CHANGE: A couple of APIs have been removed or replaced.

-> inline _compound into _updateVault()
-> remove compond() in favor of updateVaultMP()
-> rename updateVaultMP() to updateVault()
-> rename compoundAccount() to updateAccount()

Closes #187
2025-03-25 16:09:04 +01:00
Ricardo Guilherme Schmidt
0385522821 chore(tests): use UndefinedError in some cases 2025-03-21 18:21:57 +01:00
Ricardo Guilherme Schmidt
400923aed0 # This is a combination of 6 commits.
# This is the 1st commit message:

feat(RewardsStreamerMP.t): improve fuzz tests to test revert cases

fix(StakeMath): prevent uint256 overflow error
fix(StakeMath): prevent unstaking zero

# This is the commit message #2:

fix(StakeMath): prevent unstaking zero

# This is the commit message #3:

refactor(fuzz-tests): enhance readibility + test for unstake

# This is the commit message #4:

chore(tests): add compoud fuzz test

# This is the commit message #5:

chore(tests): Add Compound Fuzz Test

# This is the commit message #6:

chore (tests): fix fuzz test Unstake to always call compound function before unstake.
2025-03-21 18:21:57 +01:00
Andrea Franz
508885bed5 chore(RewardsStreamerMP): allow users to stake again without increasing the lock period 2025-03-19 15:36:55 +01:00
r4bbit
4fa3eb06e0 feat(RewardsStreamerMP): allow for staking multiple times with lock
This commit enables users to stake multiple times into the same vault
with a lock increase.

If their total lock increase goes beyond the maximum lock period,
staking will revert. In this case users will have to create a new vault.

Closes #152

Co-authored-by: Andrea Franz <andrea@gravityblast.com>
2025-03-19 15:36:55 +01:00
r4bbit
5e2dcbabd1 feat(RewardsStreamerMP): add function to compound all MPs for an account
Closes #175
2025-03-14 15:00:26 +01:00
Ricardo Guilherme Schmidt
e4d21b6caf feat(RewardsStreamerMP): enable extending lock period 2025-03-06 16:50:40 +01:00
r4bbit
aa1addbfcd chore: downgrade to paris
We put `cancun` as evm version into the foundry toml by mistake and
ended up building on top of it with certain assumptions.

Turns out that the network we're deploying to does not support that
version so we have to compile with `paris`.

This however, also requires a downgrade of the open zeppelin libraries,
which in turn requires changes in our code base. Primarily related to
initialization of `OwnableUpgradeable` and upgrades via UUPSUpgradeable.

This commit makes all the necessary changes.
2025-03-05 11:47:30 +01:00
r4bbit
d7e0d532d1 cleanup: address linter warnings 2025-03-05 11:20:21 +01:00
Andrea Franz
aa3442b577 feat(Karma): make karma upgradeable 2025-02-28 14:39:15 +01:00
r4bbit
60081c14fb refactor: cleanup, move code around, and adjust deployscript 2025-02-28 12:05:18 +01:00
Andrea Franz
ed3577f8c4 feat(Karma): allocate external rewards using the Karma contract 2025-02-27 20:48:39 +01:00
Ricardo Guilherme Schmidt
54e80e117f chore(tests): add fuzz test for rewards 2025-02-27 11:25:20 +01:00
r4bbit
7575e965a2 refactor(RewardsStreamerMP.t.sol): fix test that causes stack too deep
error

One of our tests uses too many local variables and causes stack too deep
errors unless optimized `--via-ir`.

We've introduced `--via-ir` to work around that until a proper fix is
done. The downside of using that option is that compilation times get
significantly longer.

This commit restructures the test such that it doesn't use as many local
variables.
2025-02-25 15:06:58 +01:00
Ricardo Guilherme Schmidt
3bd9c46fb3 chore(tests): Add fuzz tests 2025-02-24 15:29:10 +01:00
r4bbit
807f480d97 test(RewardsStreamerMP): ensure newly added fields are checked in tests
Those were missing and now added.
Because of this we're running into stack to deep errors in test, so we
have to enable `via_ir` by default for now until we split things up.
2025-02-20 17:26:56 +01:00
Andrea Franz
58f43d07ce feature(RewardsStreamerMP): add compound function and track rewards accrued by each vault 2025-02-20 17:15:17 +01:00
r4bbit
4086dda6e2 refactor(IStakeManager): move error codes to interface and remove unused
ones

There are a bunch of error codes that are either similar to other ones
or not used at all.

This commit moves them to the interface and removes the ones that aren't
used anymore. Part of the reason we have so many unused errors becuase
they had been "reintroduced" in `StakeMath`, which we'll revisit as
well as described in #130
2025-02-20 13:10:21 +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
Andrea Franz
51dcb884b3 chore(RewardsStreamerMP): remove MPs from shares/weights calculations 2025-02-18 10:20:22 +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
Ricardo Guilherme Schmidt
a22da253c3 refactor(RewardStreamerMP): extract MP and Stake mathematical formulas to abstract contracts 2025-01-30 17:06:16 +01:00
r4bbit
44deb52c58 refactor: update terminology in contract
Closes #87
2025-01-28 12:20:04 +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
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
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
Andrea Franz
b1a4e5ad37 fix(RewardsStreamerMP): rename _calculateAccruedRewards to _calculatePendingRewards and fix specs 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