Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of the 4626 #36

Merged
merged 44 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
159c3f7
added OZ erc4626 + rewrite half functions
Aug 9, 2024
2db5016
removed excess functions, changed errors to OZ style
Aug 9, 2024
6359a24
slash function is rewritten
Aug 9, 2024
1a8082c
lint of StakeToken
kyzia551 Aug 9, 2024
9e3530d
Simplification of maxWithdraw (#33)
kyzia551 Aug 9, 2024
c6d072f
Move whenNotPaused to internal method (#34)
kyzia551 Aug 10, 2024
9c7c6a3
deleted old versions + little code-style fixes
Aug 10, 2024
6eac7fe
finished StakeToken
Aug 10, 2024
741ca04
removed excess contracts
Aug 10, 2024
edcb6ba
erc-4626 tests ready
Aug 12, 2024
40c8d71
deleted excess files
Aug 12, 2024
9272863
tests for ERC20/4626 ready
Aug 12, 2024
d5cec19
removed StataStakeToken
Aug 12, 2024
6c272e7
cooldown tests are ready
Aug 13, 2024
8c4b000
Added pause tests, added modifier to slash function, some little fixe…
Aug 13, 2024
cdf5764
slashing tests + cooldownOnBehalf tests
Aug 13, 2024
46adba1
depositWithPermit added + some little name/description fixes
Aug 15, 2024
fe448a0
tests finished
Aug 15, 2024
2154c67
remove whenNotPaused
kyzia551 Aug 16, 2024
29ab053
Remove aave v3 (#39)
pavelvm5 Aug 18, 2024
a55f5a3
forge install: openzeppelin-contracts-upgradeable
Aug 18, 2024
b23469d
deleted aave-helpers/token-v3, added OZ
Aug 18, 2024
c698e4f
forge install: solidity-utils
Aug 18, 2024
58eb40a
fixed gramma error in link + removed OZ to solidity-utils
Aug 18, 2024
3696658
moved to extension
Aug 19, 2024
619309e
little fixes
Aug 19, 2024
ee4b44a
fixed extension
Aug 19, 2024
2035d3f
OZ dependendies refactor
Aug 19, 2024
a9814a0
removed excess from interfaces
Aug 19, 2024
a800d7a
little style fixes
Aug 19, 2024
8e9b2a6
permit tests added
Aug 20, 2024
0f3f3de
deleted smConfig
Aug 20, 2024
c55b01d
Delete exchange rate (#40)
pavelvm5 Aug 26, 2024
93f2ce0
Merge remote-tracking branch 'origin/pa' into refact/erc4626
pavelvm5 Aug 26, 2024
1df847b
accept right changes + removed outdated condition for combined test
pavelvm5 Aug 26, 2024
b0f78f2
Update README.md
pavelvm5 Aug 26, 2024
f58a39a
Update README.md
pavelvm5 Aug 26, 2024
634909e
renamed timestamp to endOfCooldown
pavelvm5 Aug 26, 2024
6eb59cd
forge install: erc4626-tests
pavelvm5 Aug 26, 2024
947bc22
a16z tests added
pavelvm5 Aug 26, 2024
6bb2d09
added withdrawalWindow
pavelvm5 Aug 27, 2024
9a983af
Added test to cover window and cooldown change
pavelvm5 Aug 27, 2024
2a2e8b1
added setUp yield into a16z tests
pavelvm5 Aug 28, 2024
bd0cd1f
little fixes
pavelvm5 Aug 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/aave-token-v3"]
path = lib/aave-token-v3
url = https://github.com/bgd-labs/aave-token-v3
[submodule "lib/aave-helpers"]
path = lib/aave-helpers
url = https://github.com/bgd-labs/aave-helpers
[submodule "lib/solidity-utils"]
path = lib/solidity-utils
url = https://github.com/bgd-labs/solidity-utils
62 changes: 32 additions & 30 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,51 @@ Business Source License 1.1
License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
“Business Source License” is a trademark of MariaDB Corporation Ab.

---
-----------------------------------------------------------------------------

Parameters

Licensor: Aave DAO, represented by its governance smart contracts
Licensor: Aave DAO, represented by its governance smart contracts

Licensed Work: Stake Token
The Licensed Work is (c) 2024 Aave DAO, represented by its governance smart contracts

Licensed Work: Aave v3.1
The Licensed Work is (c) 2024 Aave DAO, represented by its governance smart contracts

Additional Use Grant: You are permitted to use, copy, and modify the Licensed Work, subject to
the following conditions:

- Your use of the Licensed Work shall not, directly or indirectly, enable, facilitate,
or assist in any way with the migration of users and/or funds from the Aave ecosystem.
The "Aave ecosystem" is defined in the context of this License as the collection of
software protocols and applications approved by the Aave governance, including all
those produced within compensated service provider engagements with the Aave DAO.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on staketoken.aavelicense.eth.
- You are neither an individual nor a direct or indirect participant in any incorporated
organization, DAO, or identifiable group, that has deployed in production any original
or derived software ("fork") of the Aave ecosystem for purposes competitive to Aave,
within the preceding two years.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on staketoken.aavelicense.eth.
- You must ensure that the usage of the Licensed Work does not result in any direct or
indirect harm to the Aave ecosystem or the Aave brand. This encompasses, but is not limited to,
reputational damage, omission of proper credit/attribution, or utilization for any malicious
intent.

Change Date: The earlier of: - 2028-01-08 - The date specified in the 'change-date' record on staketoken.aavelicense.eth

Change License: MIT

---
the following conditions:
- Your use of the Licensed Work shall not, directly or indirectly, enable, facilitate,
or assist in any way with the migration of users and/or funds from the Aave ecosystem.
The "Aave ecosystem" is defined in the context of this License as the collection of
software protocols and applications approved by the Aave governance, including all
those produced within compensated service provider engagements with the Aave DAO.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on v31.aavelicense.eth.
- You are neither an individual nor a direct or indirect participant in any incorporated
organization, DAO, or identifiable group, that has deployed in production any original
or derived software ("fork") of the Aave ecosystem for purposes competitive to Aave,
within the preceding four years.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on v31.aavelicense.eth.
- You must ensure that the usage of the Licensed Work does not result in any direct or
indirect harm to the Aave ecosystem or the Aave brand. This encompasses, but is not limited to,
reputational damage, omission of proper credit/attribution, or utilization for any malicious
intent.

Change Date: The earlier of:
- 2027-03-06
- If specified, the date in the 'change-date' record on stake-token-v2.aavelicense.eth

Change License: MIT

-----------------------------------------------------------------------------

Notice

The Business Source License (this document, or the “License”) is not an Open
Source license. However, the Licensed Work will eventually be made available
under an Open Source License, as stated in this License.

---
-----------------------------------------------------------------------------

Terms

Expand Down
93 changes: 53 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,77 @@
# Stake token
# StakeToken - Vault

New version of the Aave Safety Module stk tokens.
The new version of the Aave Safety Module stk tokens, intended for the Umbrella project.

## Summary of Changes
## About

The `StakeToken` is a token deployed on Ethereum, with the main utility of participating in the Aave safety module.
The `StakeToken` contains an EIP-4626 generic token vault for all non-rebase tokens (especially targeting `static-a-tokens`).

There are currently two proxy contracts which utilize a `StakeToken`:
## Features

- [stkAAVE](https://etherscan.io/token/0x4da27a545c0c5b758a6ba100e3a049001de870f5) with the [StakedAaveV3 implementation](https://etherscan.io/address/0xaa9faa887bce5182c39f68ac46c43f36723c395b#code)
- [stkABPT](https://etherscan.io/address/0xa1116930326D21fB917d5A27F1E9943A9595fb47#code) with the [StakedTokenV3 implementation](https://etherscan.io/address/0x9921c8cea5815364d0f8350e6cbe9042a92448c9#code)
- **Full [EIP-4626](https://eips.ethereum.org/EIPS/eip-4626) compatibility.**
- Withdrawal of funds from the storage can be carried out only after activation of cooldown after a certain time.
- The `StakeToken` is designed to cover small `Bad Debt`'s in a semi-automatic mode, but can withdraw almost all funds up to the `getMaxSlashableAssets()` amount in emergencies.
pavelvm5 marked this conversation as resolved.
Show resolved Hide resolved
- Providing liquidity in the `StakeToken` includes the risk of slashing and is therefore paid for with additional rewards through `REWARDS_CONTROLLER`.
- **Permit-transactions support.** To enable interfaces to offer gas-less transactions to deposit with a permit.
- **Upgradable by the Aave governance.** Similar to other contracts of the Aave ecosystem, the Level 1 executor (short executor) will be able to add new features to the deployed instances of the `stakeTokens`.

The implementation can be found [here](https://github.com/bgd-labs/aave-stk-gov-v3)
Together with all the standard ERC20 functionalities, the current implementation includes extra logic for:
See [`IERC4626StakeToken.sol`](src/contracts/interfaces/IERC4626StakeToken.sol) for detailed method documentation.

- entering and exiting the safety module
- management & accounting for safety module rewards
- management & accounting of voting and proposition power
- slashing mechanics for slashing in the case of shortfall events
## Deployed Addresses

The new iteration of the generic `StakeToken` is intended for new Deployments **only**.
While it does not alter any core mechanics, the new iteration cleans up numerous historical artifacts.
An up-to-date address can be fetched from the respective [address-book pool library](https://github.com/bgd-labs/aave-address-book/blob/main/src/AaveV3Ethereum.sol).

The main goals here are:
## Limitations

- simpler inheritance chain
- cleaner storage layout
- updated/modernized libraries
The `StakeToken` is not natively integrated into the aave protocol and therefore cannot use multiple sources of additional incentives. Additional incentives included in the `static-a-tokens` are disabled when using the `StakeTokens`.

## Development
Since the `StakeToken` implies a decrease in `totalAssets()` over time (loss of funds), irreversible losses associated with the accuracy of calculations could occur over time.

This project uses [Foundry](https://getfoundry.sh). See the [book](https://book.getfoundry.sh/getting-started/installation.html) for detailed instructions on how to install and use Foundry.
The template ships with sensible default so you can use default `foundry` commands without resorting to `MakeFile`.
Losses do not exceed 1 wei if calculated relative to assets, but they can be more significant when using functions related to calculations through shares (due to OZ roundings). It is recommended to manually check and find more profitable ways to deposit/withdraw liquidity. However, in most cases, the difference should not exceed any significant amount.

### Setup
### Inheritance

```sh
cp .env.example .env
forge install
```
The `StakeToken` is based on [`open-zeppelin-upgradeable`](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable) contracts.

### Test
The `StakeToken` is separated into 2 different contracts, where `ERC4626StakeTokenUpgradeable` inherits `ERC4626Upgradeable`.

```sh
forge test
```
- `ERC4626StakeTokenUpgradeable` is an abstract contract implementing the [EIP-4626](https://eips.ethereum.org/EIPS/eip-4626) methods for an underlying asset. It provides basic functionality for the `StakeToken` without any access control or pausability.
- `StataTokenV2` is the main contract stitching things together, while adding `Pausable`, `Rescuable`, `Permit`, and the actual initialization.

pavelvm5 marked this conversation as resolved.
Show resolved Hide resolved
#### depositWithPermit

[`ERC20PermitUpgradeable`](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/9a47a37c4b8ce2ac465e8656f31d32ac6fe26eaa/contracts/token/ERC20/extensions/ERC20PermitUpgradeable.sol) has been added to the `StakeToken`, which added the ability to make a deposit using a valid signature and 1 tx via `permit()`.

## Advanced features
#### Rescuable

### Diffing
[`Rescuable`](https://github.com/bgd-labs/solidity-utils/blob/main/src/contracts/utils/Rescuable.sol) has been applied to
the `StakeToken` which will allow the `owner()` of the corresponding `StakeToken` to rescue tokens on the contract.

For contracts upgrading implementations it's quite important to diff the implementation code to spot potential issues and ensure only the intended changes are included.
Therefore the `Makefile` includes some commands to streamline the diffing process.
#### Pausable

#### Download
The `StakeToken` implements the [`PausableUpgradeable`](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/9a47a37c4b8ce2ac465e8656f31d32ac6fe26eaa/contracts/utils/PausableUpgradeable.sol) allowing `owner()` to pause the vault in case of an emergency.
As long as the vault is paused, any non-view actions (deposit/redeem/slash) are impossible.

You can `download` the current contract code of a deployed contract via `make download chain=polygon address=0x00`. This will download the contract source for specified address to `src/etherscan/chain_address`. This command works for all chains with a etherscan compatible block explorer.
## Dependencies

#### Git diff
- Foundry, [how-to install](https://book.getfoundry.sh/getting-started/installation) (we recommend also update to the last version with `foundryup`)
- Lcov
- Optional, only needed for coverage testing
- For Ubuntu, you can install via `apt install lcov`
- For Mac, you can install via `brew install lcov`

### Setup

```sh
cp .env.example .env

forge install

# optional, to install prettier
bun install
```

You can `git-diff` a downloaded contract against your src via `make git-diff before=./etherscan/chain_address after=./src out=filename`. This command will diff the two folders via git patience algorithm and write the output to `diffs/filename.md`.
### Tests

**Caveat**: If the onchain implementation was verified using flatten, for generating the diff you need to flatten the new contract via `forge flatten` and supply the flattened file instead fo the whole `./src` folder.
- To run the full test suite: `make test`
- To re-generate the coverage report: `make coverage`
177 changes: 0 additions & 177 deletions etherscan/stkAAVE/StakedAaveV3/lib/aave-token-v3/src/BaseAaveToken.sol

This file was deleted.

Loading
Loading