220 Commits

Author SHA1 Message Date
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
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