Skip to content

Commit

Permalink
Merge pull request #21 from vechain/feat/ve-better-passport
Browse files Browse the repository at this point in the history
Feat/ve better passport
  • Loading branch information
roisindowling authored Oct 14, 2024
2 parents 0dda53c + d9d7ad7 commit 6c1ff85
Show file tree
Hide file tree
Showing 111 changed files with 22,872 additions and 1,191 deletions.
187 changes: 187 additions & 0 deletions CONTRACTS_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Smart Contracts Changelog

This document provides a detailed log of upgrades to the smart contract suite, ensuring clear tracking of changes, improvements, bug fixes, and versioning across all contracts.

## Version History

| Date | Contract(s) | Summary |
| ------------------- | --------------------------------------------------------- | ----------------------------------------------------------- |
| 11th October 2024 | `XAllocationVoting` version `2` | Check isPerson when casting vote & fixed weight during vote |
| 11th October 2024 | `B3TRGovernor` version `4` | Check isPerson when casting vote |
| 11th October 2024 | `X2EarnRewardsPool` version `3` | Register action in VeBetter Passport contract |
| 27th September 2024 | `Emissions` version `2` | Aligned emissions with the expected schedule |
| 13th September 2024 | `B3TRGovernor` version `3`, `XAllocationPool` version `2` | Added toggling of quadratic voting and funding |
| 4th September 2024 | `X2EarnRewardsPool` version `2` | Added impact key management and proof building |
| 31st August 2024 | `VoterRewards` version `2` | Added quadratic rewarding features |
| 29th August 2024 | `B3TRGovernor` version `2` | Updated access control modifiers |

---

## Upgrade `XAllocationVoting` to Version 2, `B3TRGovernor` to version 4, and `X2EarnRewardsPool` to version 3 (9th October 2024)

This upgrade ensures that the `isPerson` check is performed when casting a vote in the `XAllocationVoting` and `B3TRGovernor` contracts. Additionally, the `X2EarnRewardsPool` contract now registers actions in the `VeBetter Passport` contract.

Another change in the `XAllocationVoting` contract is the fixed weight during the vote, ensuring that the weight cannot be lower than 1.

### Changes 🚀

- **Upgraded Contract(s):**
- `XAllocationVoting.sol` to version `2`
- `B3TRGovernor.sol` to version `4`
- `X2EarnRewardsPool.sol` to version `3`

### Storage Changes 📦

- **`XAllocationVoting.sol`**:
- Added veBetterPassport contract address.
- **`B3TRGovernor.sol`**:
- Added veBetterPassport contract address.
- **`X2EarnRewardsPool.sol`**:
- Added veBetterPassport contract address.

### New Features 🚀

- **`XAllocationVoting.sol`**:
- Added `isPerson` check when casting a vote.
- **`B3TRGovernor.sol`**:
- Added `isPerson` check when casting a vote.
- **`X2EarnRewardsPool.sol`**:
- Register actions in the `VeBetter Passport` contract.

### Bug Fixes 🐛

- **`XAllocationVoting.sol`**:
- Fixed weight during vote to ensure it cannot be lower than 1.

---

## Upgrade `Emissions` to Version 2 (27th September 2024)

This upgrade aligns the emissions with the expected schedule by correcting previous configuration errors.

### Changes 🚀

- **Upgraded Contract(s):** `Emissions.sol` to version `2`

### Storage Changes 📦

- Added `_isEmissionsNotAligned` to store the emissions alignment status.

### New Features 🚀

- In `_calculateNextXAllocation` function, added logic to calculate the next X Allocation based on the emissions alignment status.

### Bug Fixes 🐛

- Corrected `xAllocationsDecay` from `912` to `12`, fixing the erroneous value set in version `1`.
- Applied a reduction of `200,000` B3TR emissions for round `14` to align with the expected emissions schedule.

---

## Upgrade `B3TRGovernor` to Version 3 and `XAllocationPool` to Version 2 (13th September 2024)

This upgrade adds the ability to toggle quadratic voting and quadratic funding on or off, providing greater control over governance and allocation mechanisms.

### Changes 🚀

- **Upgraded Contract(s):**
- `B3TRGovernor.sol` to version `3`
- `XAllocationPool.sol` to version `2`

### Storage Changes 📦

- **`B3TRGovernor.sol`**:
- Added `quadraticVotingDisabled` checkpoints to store the quadratic voting disabled status.
- **`XAllocationPool.sol`**:
- Added `quadraticFundingDisabled` checkpoints to store the quadratic funding disabled status.

### New Features 🚀

- **`B3TRGovernor`**:
- Ability to toggle quadratic voting on or off.
- **`XAllocationPool`**:
- Ability to toggle quadratic funding on or off.

### Bug Fixes 🐛

- None.

---

## Upgrade `X2EarnRewardsPool` to Version 2 (4th September 2024)

This upgrade introduces impact key management and the ability to build proofs of sustainable impact.

### Changes 🚀

- **Upgraded Contract(s):** `X2EarnRewardsPool.sol` to version `2`

### Storage Changes 📦

- Added `impactKeyIndex` to store allowed impact keys index for proof of sustainable impact building.
- Added `allowedImpactKeys` to store the array of allowed impact keys.

### New Features 🚀

- Introduced the `IMPACT_KEY_MANAGER_ROLE` to manage allowed impact keys.
- Introduced the `onlyRoleOrAdmin` modifier to restrict access to the `IMPACT_KEY_MANAGER_ROLE` or admin.
- Added `buildProof` function to build proof of sustainable impact.

### Bug Fixes 🐛

- None.

---

## Upgrade `VoterRewards` to Version 2 (31st August 2024)

This upgrade adds the ability to disable quadratic rewarding for specific cycles, providing greater flexibility in reward distribution. Introduced as first step of sybil mitigation.

### Changes 🚀

- **Upgraded Contract(s):** `VoterRewards.sol` to version `2`

### Storage Changes 📦

- Added `quadraticRewardingDisabled` checkpoints to store the quadratic rewarding status for each cycle.

### New Features 🚀

- Added functions to:
- Disable or re-enable quadratic rewarding for specific cycles.
- Check if quadratic rewarding is disabled at a specific block number or for the current cycle.
- Added the `clock` function to get the current block number.

### Bug Fixes 🐛

- None.

---

## Upgrade `B3TRGovernor` to Version 2 (29th August 2024)

This upgrade enhances access control by allowing the `DEFAULT_ADMIN_ROLE` to execute critical functions without requiring a governance proposal.

### Changes 🚀

- **Upgraded Contract(s):** `B3TRGovernor.sol` to version `2`

### Storage Changes 📦

- **Storage Changes:** None.

### New Features 🚀

- Updated functions previously restricted by `onlyGovernance` to use `onlyRoleOrGovernance`, permitting `DEFAULT_ADMIN_ROLE` direct access.

### Bug Fixes 🐛

- None.

---

## Glossary

- **Quadratic Voting**: A voting system where the cost of votes increases quadratically with the number of votes cast.
- **Quadratic Funding**: A funding mechanism that allocates resources based on the square of contributions received.
- **Checkpoint**: A recorded state at a specific point in time for tracking changes or status.
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Welcome to the VeBetterDAO Smart Contracts repository! This open-source reposito

The complete documentation for the VeBetterDAO and the contracts can be found [here](https://docs.vebetterdao.org).

Our contracts are upgradeable and versioned. See the [contracts changelog](CONTRACTS_CHANGELOG.md) for more information on the changes introduced in each of new upgraded version.

## Mainnet contract addresses

```
Expand All @@ -41,7 +43,8 @@ The complete documentation for the VeBetterDAO and the contracts can be found [h
"X2EarnApps": "0x8392B7CCc763dB03b47afcD8E8f5e24F9cf0554D",
"X2EarnRewardsPool": "0x6Bee7DDab6c99d5B2Af0554EaEA484CE18F52631",
"XAllocationPool": "0x4191776F05f4bE4848d3f4d587345078B439C7d3",
"XAllocationVoting": "0x89A00Bb0947a30FF95BEeF77a66AEdE3842Fe5B7"
"XAllocationVoting": "0x89A00Bb0947a30FF95BEeF77a66AEdE3842Fe5B7",
"VeBetterPassport": "0x35a267671d8EDD607B2056A9a13E7ba7CF53c8b3"
```

## Testnet contract addresses
Expand All @@ -62,6 +65,8 @@ The complete documentation for the VeBetterDAO and the contracts can be found [h
"B3TRFaucet": "0x5e9c1F0f52aC6b5004122059053b00017EAfB561"
```

Notice: _VeBetter Passport contract deployed only on mainnet._

## Audit

The VeBetterDAO smart contracts have undergone a comprehensive audit by [Hacken](https://hacken.io/). The audit report (`Hacken_Vechain Foundation_[SCA] VeChain _ VeBetter DAO _ May2024_P-2024-304_1_20240621 16_17`) can be found in the root of the repo.
Expand Down
9 changes: 9 additions & 0 deletions config/contracts/envs/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,14 @@ export function createLocalConfig() {
"plastic",
"trees_planted",
],

// VeBetterPassport
VEPASSPORT_BOT_SIGNALING_THRESHOLD: 2,
VEPASSPORT_ROUNDS_FOR_CUMULATIVE_PARTICIPATION_SCORE: 12,
VEPASSPORT_GALAXY_MEMBER_MINIMUM_LEVEL: 2,
VEPASSPORT_BLACKLIST_THRESHOLD_PERCENTAGE: 20,
VEPASSPORT_WHITELIST_THRESHOLD_PERCENTAGE: 20,
VEPASSPORT_PASSPORT_MAX_ENTITIES: 5,
VEPASSPORT_DECAY_RATE: 0,
})
}
9 changes: 9 additions & 0 deletions config/contracts/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ export type ContractsConfig = {

// X 2 Earn Rewards Pool
X_2_EARN_INITIAL_IMPACT_KEYS: string[]

// VeBetterPassport
VEPASSPORT_BOT_SIGNALING_THRESHOLD: number
VEPASSPORT_ROUNDS_FOR_CUMULATIVE_PARTICIPATION_SCORE: number
VEPASSPORT_GALAXY_MEMBER_MINIMUM_LEVEL: number
VEPASSPORT_BLACKLIST_THRESHOLD_PERCENTAGE: number
VEPASSPORT_WHITELIST_THRESHOLD_PERCENTAGE: number
VEPASSPORT_PASSPORT_MAX_ENTITIES: number
VEPASSPORT_DECAY_RATE: number
}
1 change: 1 addition & 0 deletions config/scripts/generateMockLocalConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const generateMockLocalConfig = () => {
galaxyMemberContractAddress: "0x45d5CA3f295ad8BCa291cC4ecd33382DE40E4FAc",
treasuryContractAddress: "0x45d5CA3f295ad8BCa291cC4ecd33382DE40E4FAc",
x2EarnAppsContractAddress: "0x45d5CA3f295ad8BCa291cC4ecd33382DE40E4FAc",
veBetterPassportContractAddress: "0x45d5CA3f295ad8BCa291cC4ecd33382DE40E4FAc",
"nodeUrl": "http://localhost:8669",
"network": {
"id": "solo",
Expand Down
41 changes: 37 additions & 4 deletions contracts/B3TRGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { IVeBetterPassport } from "./interfaces/IVeBetterPassport.sol";

/**
* @title B3TRGovernor
Expand All @@ -67,11 +68,13 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
*
* The contract is upgradeable and uses the UUPS pattern.
* @dev The contract is upgradeable and uses the UUPS pattern. All logic is stored in libraries.
*
*
* ------------------ VERSION 2 ------------------
* - Replaced onlyGovernance modifier with onlyRoleOrGovernance which checks if the caller has the DEFAULT_ADMIN_ROLE role or if the function is called through a governance proposal
* ------------------ VERSION 3 ------------------
* - Added the ability to toggle the quadratic voting mechanism on and off
* ------------------ VERSION 4 ------------------
* - Integrated VeBetterPassport contract
*/
contract B3TRGovernor is
IB3TRGovernor,
Expand Down Expand Up @@ -160,6 +163,10 @@ contract B3TRGovernor is
_grantRole(PROPOSAL_EXECUTOR_ROLE, rolesData.proposalExecutor);
}

function initializeV4(IVeBetterPassport _veBetterPassport) public reinitializer(4) {
__GovernorStorage_init_v4(_veBetterPassport);
}

/**
* @dev Function to receive VET that will be handled by the governor (disabled if executor is a third party contract)
*/
Expand All @@ -179,7 +186,11 @@ contract B3TRGovernor is
* @param value The amount of ether to send
* @param data The data to call the target with
*/
function relay(address target, uint256 value, bytes calldata data) external payable virtual onlyRoleOrGovernance(DEFAULT_ADMIN_ROLE) {
function relay(
address target,
uint256 value,
bytes calldata data
) external payable virtual onlyRoleOrGovernance(DEFAULT_ADMIN_ROLE) {
(bool success, bytes memory returndata) = target.call{ value: value }(data);
Address.verifyCallResult(success, returndata);
}
Expand Down Expand Up @@ -562,7 +573,7 @@ contract B3TRGovernor is
* @return string The version of the governor
*/
function version() external pure returns (string memory) {
return "3";
return "4";
}

/**
Expand Down Expand Up @@ -635,6 +646,15 @@ contract B3TRGovernor is
return address($.timelock);
}

/**
* @notice Returns the VeBetterPassport contract.
* @return The current VeBetterPassport contract.
*/
function veBetterPassport() external view returns (IVeBetterPassport) {
GovernorStorageTypes.GovernorStorage storage $ = getGovernorStorage();
return $.veBetterPassport;
}

// ------------------ SETTERS ------------------ //

/**
Expand Down Expand Up @@ -903,11 +923,24 @@ contract B3TRGovernor is
* CAUTION: It is not recommended to change the timelock while there are other queued governance proposals.
* @param newTimelock The new timelock controller
*/
function updateTimelock(TimelockControllerUpgradeable newTimelock) external virtual onlyRoleOrGovernance(DEFAULT_ADMIN_ROLE) {
function updateTimelock(
TimelockControllerUpgradeable newTimelock
) external virtual onlyRoleOrGovernance(DEFAULT_ADMIN_ROLE) {
GovernorStorageTypes.GovernorStorage storage $ = getGovernorStorage();
GovernorConfigurator.updateTimelock($, newTimelock);
}

/**
* @notice Set the VeBetterPassport contract
* @param newVeBetterPassport The new VeBetterPassport contract
*/
function setVeBetterPassport(
IVeBetterPassport newVeBetterPassport
) public onlyRoleOrGovernance(CONTRACTS_ADDRESS_MANAGER_ROLE) {
GovernorStorageTypes.GovernorStorage storage $ = getGovernorStorage();
GovernorConfigurator.setVeBetterPassport($, newVeBetterPassport);
}

// ------------------ Overrides ------------------ //

/**
Expand Down
Loading

0 comments on commit 6c1ff85

Please sign in to comment.