Skip to content

Commit

Permalink
Improve doc and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rya-sge committed Apr 23, 2024
1 parent 3a88033 commit 1867176
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 106 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,6 @@ For the specific case where dividends are distributed in shares, meaning additio
\- With the current architecture, depending on when you decide to mint the new tokens, you will increase the total supply used to compute the token holder shares. Therefore, you will reduce the dividends distributed to the token holders.
\- In general, for yield tokens, the formula used can be different.

## Claim restriction

An holder can not claim its dividends if:

a. The claim time is in the future (`IncomeVault_TooEarlyToWithdraw`)

b. The claim time is too far in the past, specified by `timeLimitToWithdraw` (`IncomeVault_TooLateToWithdraw`)

c. Claim is not enabled for this specific `time` (`IncomeVault_ClaimNotActivated`)

d. Holder has already claim its dividends (`IncomeVault_DividendAlreadyClaimed`)

e. There is no dividend to claim (`IncomeVault_NoDividendToClaim`)

For the batch function, `claimDividendBatch`, `d` and `e` don't generate an error but instead, there is just no dividends distributed for this specific time.

## Compatibility

- The dividends can be paid with ERC-20 tokens as described in the [ERC-20](https://eips.ethereum.org/EIPS/eip-20) specification
Expand Down
Binary file modified doc/schema/classDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 82 additions & 76 deletions doc/schema/classDiagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 30 additions & 1 deletion doc/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@

![IncomeVault-Global.drawio](../doc/schema/drawio/IncomeVault-Global.drawio.png)

## Access control

All restricted functions are defined in the file `IncomeVaultRestricted`.

| Role | Function |
| -------------------------- | ------------------------------------------------------------ |
| DEFAULT_ADMIN_ROLE | Manage all others roles<br /><br />This role has also all the others roles by default through the `ValidationModule` |
| INCOME_VAULT_DEPOSIT_ROLE | `deposit` |
| INCOME_VAULT_WITHDRAW_ROLE | `withdraw`<br />`withdrawAll` |
| INCOME_VAULT_OPERATOR_ROLE | `setStatusClaim`<br /> `setTimeLimitToWithdraw` |



## Segregated Deposit

Each deposit is segregated in its time value. A `time` is the dividends distribution date (Unix Timestamp) to the token holders.

![IncomeVault-Segragated Deposit.drawio](../doc/schema/drawio/IncomeVault-Segragated Deposit.drawio.png)

### ValidationModule
## ValidationModule

A claim is considered as a transfer from the contract to the sender (token holder).
This transfer can be restricted with the ValidationModule
Expand Down Expand Up @@ -58,6 +71,22 @@ Therefore, a token holder has to know the different `time` when a deposit has be

A function `claimDividend` in batch is also available to claim dividends for several different time.

### Claim restriction

An holder can not claim its dividends if:

a. The claim time is in the future (`IncomeVault_TooEarlyToWithdraw`)

b. The claim time is too far in the past, specified by `timeLimitToWithdraw` (`IncomeVault_TooLateToWithdraw`)

c. Claim is not enabled for this specific `time` (`IncomeVault_ClaimNotActivated`)

d. Holder has already claim its dividends (`IncomeVault_DividendAlreadyClaimed`)

e. There is no dividend to claim (`IncomeVault_NoDividendToClaim`)

For the batch function, `claimDividendBatch`, `d` and `e` don't generate an error but instead, there is just no dividends distributed for this specific time.

### Schema

This schema describes the different smart contracts called when a token holder claims his dividends.
Expand Down
Binary file modified doc/surya/surya_graph/surya_graph_IncomeVault.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/surya/surya_graph/surya_graph_IncomeVaultInternal.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/surya/surya_graph/surya_graph_IncomeVaultOpen.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/surya/surya_graph/surya_graph_IncomeVaultRestricted.sol.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/surya/surya_report/surya_report_IncomeVault.sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| ./IncomeVault.sol | d13b93632cb6877222166951c4fd742a13602a4e |
| ./IncomeVault.sol | 32ca196e65692ae173ccb00988a492e5b8e942ed |


### Contracts Description Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| ./lib/IncomeVaultInternal.sol | c95adc49c29ca32ae1c38f9644a5ed2250d524fe |
| ./lib/IncomeVaultInternal.sol | f071c3c8934776960c0d5190871b1bdaa804c88d |


### Contracts Description Table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| ./lib/IncomeVaultInvariantStorage.sol | f15b8cd61cb0d00d67ebe7129cca3b00daab8cce |
| ./lib/IncomeVaultInvariantStorage.sol | 29271b2dc8a51952990adf824c54e9235f26ac9c |


### Contracts Description Table
Expand Down
4 changes: 3 additions & 1 deletion doc/surya/surya_report/surya_report_IncomeVaultOpen.sol.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| ./public/IncomeVaultOpen.sol | 724117dc19eecbc7994690a65fa955c381bc43f2 |
| ./public/IncomeVaultOpen.sol | 562a67aea872a440991246c9050c7c3d7cdb8ed2 |


### Contracts Description Table
Expand All @@ -16,6 +16,8 @@
|| **Function Name** | **Visibility** | **Mutability** | **Modifiers** |
||||||
| **IncomeVaultOpen** | Implementation | ReentrancyGuardUpgradeable, ValidationModule, IncomeVaultInternal |||
|| validateTime | Public ❗️ | |NO❗️ |
|| validateTimeBatch | Public ❗️ | |NO❗️ |
|| claimDividend | Public ❗️ | 🛑 | nonReentrant |
|| claimDividendBatch | Public ❗️ | 🛑 | nonReentrant |

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

| File Name | SHA-1 Hash |
|-------------|--------------|
| ./public/IncomeVaultRestricted.sol | 045808f76caaa6faec4a42805df928607c6845bd |
| ./public/IncomeVaultRestricted.sol | d5d6fe92e3da58e30c320c01b0529cf1ccea09ff |


### Contracts Description Table
Expand All @@ -16,11 +16,13 @@
|| **Function Name** | **Visibility** | **Mutability** | **Modifiers** |
||||||
| **IncomeVaultRestricted** | Implementation | ValidationModule, IncomeVaultInternal |||
|| __IncomeVaultRestricted_init_unchained | Internal 🔒 | 🛑 | onlyInitializing |
|| deposit | Public ❗️ | 🛑 | onlyRole |
|| withdraw | Public ❗️ | 🛑 | onlyRole |
|| withdrawAll | Public ❗️ | 🛑 | onlyRole |
|| distributeDividend | Public ❗️ | 🛑 | onlyRole |
|| setStatusClaim | Public ❗️ | 🛑 | onlyRole |
|| setTimeLimitToWithdraw | Public ❗️ | 🛑 | onlyRole |


### Legend
Expand Down
2 changes: 1 addition & 1 deletion src/public/IncomeVaultOpen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract contract IncomeVaultOpen is ReentrancyGuardUpgradeable, ValidationModu
* @notice validate if a time is valid
*/
function validateTime(uint256 time) public view{
if(!segragatedClaim[time]){
if(!segregatedClaim[time]){
revert IncomeVault_ClaimNotActivated();
}
if(block.timestamp > timeLimitToWithdraw + time){
Expand Down
12 changes: 6 additions & 6 deletions src/public/IncomeVaultRestricted.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "../lib/IncomeVaultInternal.sol";
* @title restricted functions
*/
abstract contract IncomeVaultRestricted is ValidationModule, IncomeVaultInternal {
/**
/**
* @dev calls the different initialize functions from the different modules
*/
function __IncomeVaultRestricted_init_unchained(
Expand All @@ -31,7 +31,7 @@ abstract contract IncomeVaultRestricted is ValidationModule, IncomeVaultInternal
if(amount == 0) {
revert IncomeVault_NoAmountSend();
}
segragatedDividend[time] += amount;
segregatedDividend[time] += amount;
emit newDeposit(time, sender, amount);
// Will revert in case of failure
ERC20TokenPayment.safeTransferFrom(sender, address(this), amount);
Expand All @@ -48,10 +48,10 @@ abstract contract IncomeVaultRestricted is ValidationModule, IncomeVaultInternal
if(!result){
revert IncomeVault_FailApproval();
}
if(segragatedDividend[time] < amount) {
if(segregatedDividend[time] < amount) {
revert IncomeVault_NotEnoughAmount();
}
segragatedDividend[time] -= amount;
segregatedDividend[time] -= amount;
// Will revert in case of failure
ERC20TokenPayment.safeTransferFrom(address(this), withdrawAddress, amount);
}
Expand All @@ -77,7 +77,7 @@ abstract contract IncomeVaultRestricted is ValidationModule, IncomeVaultInternal
*/
function distributeDividend(address[] calldata addresses, uint256 time) public onlyRole(INCOME_VAULT_DISTRIBUTE_ROLE) {
// Check if the claim is activated
if(!segragatedClaim[time]){
if(!segregatedClaim[time]){
revert IncomeVault_ClaimNotActivated();
}
// Get info from the token
Expand All @@ -103,7 +103,7 @@ abstract contract IncomeVaultRestricted is ValidationModule, IncomeVaultInternal
*
*/
function setStatusClaim(uint256 time, bool status) public onlyRole(INCOME_VAULT_OPERATOR_ROLE){
segragatedClaim[time] = status;
segregatedClaim[time] = status;
}

/**
Expand Down
33 changes: 32 additions & 1 deletion test/IncomeVaultRestricted.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ contract IncomeVaultRestrictedTest is Test, HelperContract {
);
debtVault.deposit(time, defaultDepositAmount);
// Assert
resUint256 = debtVault.segragatedDividend(time);
resUint256 = debtVault.segregatedDividend(time);
assertEq(resUint256, defaultDepositAmount);
}

Expand Down Expand Up @@ -181,6 +181,37 @@ contract IncomeVaultRestrictedTest is Test, HelperContract {
assertEq(tokenPayment.balanceOf(ADDRESS2),depositAmount1);
}

function testCanAdminSetStatusClaim() public {
uint256 time = 122;
vm.prank(DEFAULT_ADMIN_ADDRESS);
debtVault.setStatusClaim(time, true);
resBool = debtVault.segregatedClaim(time);
assertEq(resBool, true);
}

function testCanAdminUnsetStatusClaim() public {
// Arrange
uint256 time = 122;
vm.prank(DEFAULT_ADMIN_ADDRESS);
debtVault.setStatusClaim(time, true);
// Act
vm.prank(DEFAULT_ADMIN_ADDRESS);
debtVault.setStatusClaim(time, false);
// Assert
resBool = debtVault.segregatedClaim(time);
assertEq(resBool, false);
}

function testCanAdminSetTimeLimitToWithdraw() public {
// Act
uint256 time = 122;
vm.prank(DEFAULT_ADMIN_ADDRESS);
debtVault.setTimeLimitToWithdraw(time);
// Assert
resUint256 = debtVault.timeLimitToWithdraw();
assertEq(resUint256,time);
}

/****** Attacker */
function testCannotAttackerSetStatusClaim() public {
vm.expectRevert(
Expand Down

0 comments on commit 1867176

Please sign in to comment.