ваше сообщение коммита
This commit is contained in:
29
backend/contracts/GovernanceTimelock.sol
Normal file
29
backend/contracts/GovernanceTimelock.sol
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/governance/TimelockController.sol";
|
||||
|
||||
/**
|
||||
* @title GovernanceTimelock
|
||||
* @dev Контракт таймлока для DAO, обеспечивающий задержку между одобрением и исполнением предложений
|
||||
*/
|
||||
contract GovernanceTimelock is TimelockController {
|
||||
/**
|
||||
* @dev Конструктор
|
||||
* @param minDelay Минимальная задержка в секундах перед выполнением транзакции
|
||||
* @param proposers Адреса, которые могут предлагать транзакции
|
||||
* @param executors Адреса, которые могут выполнять транзакции
|
||||
* @param admin Адрес администратора (обычно адрес нулевой для децентрализации)
|
||||
*/
|
||||
constructor(
|
||||
uint256 minDelay,
|
||||
address[] memory proposers,
|
||||
address[] memory executors,
|
||||
address admin
|
||||
) TimelockController(
|
||||
minDelay,
|
||||
proposers,
|
||||
executors,
|
||||
admin
|
||||
) {}
|
||||
}
|
||||
57
backend/contracts/GovernanceToken.sol
Normal file
57
backend/contracts/GovernanceToken.sol
Normal file
@@ -0,0 +1,57 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/utils/Nonces.sol";
|
||||
|
||||
/**
|
||||
* @title GovernanceToken
|
||||
* @dev Токен управления ERC20Votes с функциями голосования для DAO
|
||||
*/
|
||||
contract GovernanceToken is ERC20Permit, ERC20Votes, Ownable {
|
||||
constructor(
|
||||
string memory name,
|
||||
string memory symbol,
|
||||
address initialOwner
|
||||
) ERC20(name, symbol) ERC20Permit(name) Ownable(initialOwner) {
|
||||
// Конструктор остается пустым, начальное распределение происходит через
|
||||
// вызов функции mintInitialSupply ниже
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Минтит начальный запас токенов для распределения между партнерами
|
||||
* @param partners Массив адресов партнеров
|
||||
* @param amounts Массив сумм токенов для каждого партнера
|
||||
*/
|
||||
function mintInitialSupply(
|
||||
address[] memory partners,
|
||||
uint256[] memory amounts
|
||||
) external onlyOwner {
|
||||
require(partners.length == amounts.length, "Arrays length mismatch");
|
||||
require(partners.length > 0, "Empty arrays");
|
||||
|
||||
uint256 totalSupply = 0;
|
||||
for (uint256 i = 0; i < partners.length; i++) {
|
||||
require(partners[i] != address(0), "Zero address");
|
||||
require(amounts[i] > 0, "Zero amount");
|
||||
|
||||
totalSupply += amounts[i];
|
||||
_mint(partners[i], amounts[i]);
|
||||
}
|
||||
|
||||
// После начального распределения отказываемся от права создавать новые токены
|
||||
renounceOwnership();
|
||||
}
|
||||
|
||||
// Переопределения, необходимые для корректной работы токена голосования
|
||||
|
||||
function _update(address from, address to, uint256 amount) internal override(ERC20, ERC20Votes) {
|
||||
super._update(from, to, amount);
|
||||
}
|
||||
|
||||
function nonces(address owner) public view override(ERC20Permit, Nonces) returns (uint256) {
|
||||
return super.nonces(owner);
|
||||
}
|
||||
}
|
||||
166
backend/contracts/GovernorContract.sol
Normal file
166
backend/contracts/GovernorContract.sol
Normal file
@@ -0,0 +1,166 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/governance/Governor.sol";
|
||||
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
|
||||
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
|
||||
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
|
||||
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
|
||||
import "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";
|
||||
|
||||
/**
|
||||
* @title GovernorContract
|
||||
* @dev Контракт Governor для DAO с настраиваемыми параметрами
|
||||
*/
|
||||
contract GovernorContract is
|
||||
Governor,
|
||||
GovernorSettings,
|
||||
GovernorCountingSimple,
|
||||
GovernorVotes,
|
||||
GovernorVotesQuorumFraction,
|
||||
GovernorTimelockControl
|
||||
{
|
||||
constructor(
|
||||
string memory _name,
|
||||
IVotes _token,
|
||||
TimelockController _timelock,
|
||||
uint48 _votingDelay,
|
||||
uint32 _votingPeriod,
|
||||
uint256 _proposalThreshold,
|
||||
uint256 _quorumPercentage
|
||||
)
|
||||
Governor(_name)
|
||||
GovernorSettings(
|
||||
_votingDelay, /* Задержка голосования в блоках */
|
||||
_votingPeriod, /* Период голосования в блоках */
|
||||
_proposalThreshold /* Порог предложения в wei токенов */
|
||||
)
|
||||
GovernorVotes(_token)
|
||||
GovernorVotesQuorumFraction(_quorumPercentage)
|
||||
GovernorTimelockControl(_timelock)
|
||||
{}
|
||||
|
||||
// Функции, которые необходимо переопределить из базовых контрактов
|
||||
|
||||
function votingDelay()
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorSettings)
|
||||
returns (uint256)
|
||||
{
|
||||
return super.votingDelay();
|
||||
}
|
||||
|
||||
function votingPeriod()
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorSettings)
|
||||
returns (uint256)
|
||||
{
|
||||
return super.votingPeriod();
|
||||
}
|
||||
|
||||
function quorum(uint256 blockNumber)
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorVotesQuorumFraction)
|
||||
returns (uint256)
|
||||
{
|
||||
return super.quorum(blockNumber);
|
||||
}
|
||||
|
||||
function state(uint256 proposalId)
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorTimelockControl)
|
||||
returns (ProposalState)
|
||||
{
|
||||
return super.state(proposalId);
|
||||
}
|
||||
|
||||
function propose(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
string memory description
|
||||
) public override(Governor) returns (uint256) {
|
||||
return super.propose(targets, values, calldatas, description);
|
||||
}
|
||||
|
||||
function proposalThreshold()
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorSettings)
|
||||
returns (uint256)
|
||||
{
|
||||
return super.proposalThreshold();
|
||||
}
|
||||
|
||||
function _cancel(
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal override(Governor, GovernorTimelockControl) returns (uint256) {
|
||||
return super._cancel(targets, values, calldatas, descriptionHash);
|
||||
}
|
||||
|
||||
function _executor()
|
||||
internal
|
||||
view
|
||||
override(Governor, GovernorTimelockControl)
|
||||
returns (address)
|
||||
{
|
||||
return super._executor();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev See {IERC165-supportsInterface}.
|
||||
*/
|
||||
function supportsInterface(bytes4 interfaceId)
|
||||
public
|
||||
view
|
||||
override(Governor)
|
||||
returns (bool)
|
||||
{
|
||||
return super.supportsInterface(interfaceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Функция для определения, требуется ли постановка предложения в очередь
|
||||
*/
|
||||
function proposalNeedsQueuing(uint256 proposalId)
|
||||
public
|
||||
view
|
||||
override(Governor, GovernorTimelockControl)
|
||||
returns (bool)
|
||||
{
|
||||
return super.proposalNeedsQueuing(proposalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Функция для постановки операций в очередь
|
||||
*/
|
||||
function _queueOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal override(Governor, GovernorTimelockControl) returns (uint48) {
|
||||
return super._queueOperations(proposalId, targets, values, calldatas, descriptionHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Функция для выполнения операций
|
||||
*/
|
||||
function _executeOperations(
|
||||
uint256 proposalId,
|
||||
address[] memory targets,
|
||||
uint256[] memory values,
|
||||
bytes[] memory calldatas,
|
||||
bytes32 descriptionHash
|
||||
) internal override(Governor, GovernorTimelockControl) {
|
||||
super._executeOperations(proposalId, targets, values, calldatas, descriptionHash);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user