ваше сообщение коммита
This commit is contained in:
@@ -28,13 +28,18 @@ const messagesRoutes = require('./routes/messages');
|
||||
const ragRoutes = require('./routes/rag'); // Новый роут для RAG-ассистента
|
||||
const monitoringRoutes = require('./routes/monitoring');
|
||||
const pagesRoutes = require('./routes/pages'); // Добавляем импорт роутера страниц
|
||||
const uploadsRoutes = require('./routes/uploads');
|
||||
const ensRoutes = require('./routes/ens');
|
||||
// Factory routes removed - no longer needed
|
||||
|
||||
// Проверка и создание директорий для хранения данных контрактов
|
||||
const ensureDirectoriesExist = () => {
|
||||
const directories = [
|
||||
path.join(__dirname, 'contracts-data'),
|
||||
path.join(__dirname, 'contracts-data/dles'),
|
||||
path.join(__dirname, 'temp')
|
||||
path.join(__dirname, 'temp'),
|
||||
path.join(__dirname, 'uploads'),
|
||||
path.join(__dirname, 'uploads/logos')
|
||||
];
|
||||
|
||||
for (const dir of directories) {
|
||||
@@ -93,6 +98,7 @@ const dleProposalsRoutes = require('./routes/dleProposals'); // Функции
|
||||
const dleModulesRoutes = require('./routes/dleModules'); // Функции модулей
|
||||
const dleTokensRoutes = require('./routes/dleTokens'); // Функции токенов
|
||||
const dleAnalyticsRoutes = require('./routes/dleAnalytics'); // Аналитика и история
|
||||
const compileRoutes = require('./routes/compile'); // Компиляция контрактов
|
||||
const dleMultichainRoutes = require('./routes/dleMultichain'); // Мультичейн функции
|
||||
const dleHistoryRoutes = require('./routes/dleHistory'); // Расширенная история
|
||||
const systemRoutes = require('./routes/system'); // Добавляем импорт маршрутов системного мониторинга
|
||||
@@ -188,6 +194,10 @@ app.use((req, res, next) => {
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
|
||||
// Статическая раздача загруженных файлов (для dev и prod)
|
||||
app.use('/uploads', express.static(path.join(__dirname, 'uploads')));
|
||||
app.use('/api/uploads', express.static(path.join(__dirname, 'uploads')));
|
||||
|
||||
// Настройка безопасности
|
||||
app.use(
|
||||
helmet({
|
||||
@@ -235,6 +245,10 @@ app.use('/api/rag', ragRoutes); // Подключаем роут
|
||||
app.use('/api/monitoring', monitoringRoutes);
|
||||
app.use('/api/pages', pagesRoutes); // Подключаем роутер страниц
|
||||
app.use('/api/system', systemRoutes); // Добавляем маршрут системного мониторинга
|
||||
app.use('/api/uploads', uploadsRoutes); // Загрузка файлов (логотипы)
|
||||
app.use('/api/ens', ensRoutes); // ENS utilities
|
||||
// app.use('/api/factory', factoryRoutes); // Factory routes removed - no longer needed
|
||||
app.use('/api/compile-contracts', compileRoutes); // Компиляция контрактов
|
||||
|
||||
const nonceStore = new Map(); // или любая другая реализация хранилища nonce
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC1155Errors",
|
||||
"sourceName": "@openzeppelin/contracts/interfaces/draft-IERC6093.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "balance",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "needed",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "tokenId",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InsufficientBalance",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "approver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InvalidApprover",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "idsLength",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "valuesLength",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InvalidArrayLength",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "operator",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InvalidOperator",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "receiver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InvalidReceiver",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155InvalidSender",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "operator",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC1155MissingApprovalForAll",
|
||||
"type": "error"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC20Errors",
|
||||
"sourceName": "@openzeppelin/contracts/interfaces/draft-IERC6093.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "allowance",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "needed",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InsufficientAllowance",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "balance",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "needed",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InsufficientBalance",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "approver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidApprover",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "receiver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidReceiver",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidSender",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidSpender",
|
||||
"type": "error"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC721Errors",
|
||||
"sourceName": "@openzeppelin/contracts/interfaces/draft-IERC6093.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "tokenId",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721IncorrectOwner",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "operator",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "tokenId",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InsufficientApproval",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "approver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InvalidApprover",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "operator",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InvalidOperator",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InvalidOwner",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "receiver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InvalidReceiver",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC721InvalidSender",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "tokenId",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC721NonexistentToken",
|
||||
"type": "error"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,319 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "ERC20",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/ERC20.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "allowance",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "needed",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InsufficientAllowance",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "balance",
|
||||
"type": "uint256"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "needed",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InsufficientBalance",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "approver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidApprover",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "receiver",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidReceiver",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidSender",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "ERC20InvalidSpender",
|
||||
"type": "error"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint8",
|
||||
"name": "",
|
||||
"type": "uint8"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,194 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC20",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||
"abi": [
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC20Metadata",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol",
|
||||
"abi": [
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint8",
|
||||
"name": "",
|
||||
"type": "uint8"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "name",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "symbol",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "string",
|
||||
"name": "",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "Context",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
||||
"abi": [],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/ab387c71734b3d3e5e7817d328027586.json"
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "ReentrancyGuard",
|
||||
"sourceName": "@openzeppelin/contracts/utils/ReentrancyGuard.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "ReentrancyGuardReentrantCall",
|
||||
"type": "error"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/de2a9b4015c1250f0af7fbce121b1da6.json"
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
1137
backend/cache/solidity-files-cache.json
vendored
1137
backend/cache/solidity-files-cache.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,10 @@ import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";
|
||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||
|
||||
interface IERC1271 {
|
||||
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4 magicValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title DLE (Digital Legal Entity)
|
||||
* @dev Основной контракт DLE с модульной архитектурой, Single-Chain Governance
|
||||
@@ -78,10 +82,14 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
uint256 public quorumPercentage;
|
||||
uint256 public proposalCounter;
|
||||
uint256 public currentChainId;
|
||||
// Публичный URI логотипа токена/организации (можно установить при деплое через инициализатор)
|
||||
string public logoURI;
|
||||
|
||||
// Модули
|
||||
mapping(bytes32 => address) public modules;
|
||||
mapping(bytes32 => bool) public activeModules;
|
||||
bool public modulesInitialized; // Флаг инициализации базовых модулей
|
||||
address public immutable initializer; // Адрес, имеющий право на однократную инициализацию модулей
|
||||
|
||||
// Предложения
|
||||
mapping(uint256 => Proposal) public proposals;
|
||||
@@ -120,16 +128,66 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
event CurrentChainIdUpdated(uint256 oldChainId, uint256 newChainId);
|
||||
event TokensTransferredByGovernance(address indexed recipient, uint256 amount);
|
||||
|
||||
// EIP712 typehash для подписи одобрения исполнения предложения в целевой сети
|
||||
// ExecutionApproval(uint256 proposalId, bytes32 operationHash, uint256 chainId, uint256 snapshotTimepoint)
|
||||
event VotingDurationsUpdated(uint256 oldMinDuration, uint256 newMinDuration, uint256 oldMaxDuration, uint256 newMaxDuration);
|
||||
event LogoURIUpdated(string oldURI, string newURI);
|
||||
|
||||
// EIP712 typehash для подписи одобрения исполнения предложения
|
||||
bytes32 private constant EXECUTION_APPROVAL_TYPEHASH = keccak256(
|
||||
"ExecutionApproval(uint256 proposalId,bytes32 operationHash,uint256 chainId,uint256 snapshotTimepoint)"
|
||||
);
|
||||
// Custom errors (reduce bytecode size)
|
||||
error ErrZeroAddress();
|
||||
error ErrArrayMismatch();
|
||||
error ErrNoPartners();
|
||||
error ErrZeroAmount();
|
||||
error ErrOnlyInitializer();
|
||||
error ErrLogoAlreadySet();
|
||||
error ErrNotHolder();
|
||||
error ErrTooShort();
|
||||
error ErrTooLong();
|
||||
error ErrBadChain();
|
||||
error ErrProposalMissing();
|
||||
error ErrProposalEnded();
|
||||
error ErrProposalExecuted();
|
||||
error ErrAlreadyVoted();
|
||||
error ErrWrongChain();
|
||||
error ErrNoPower();
|
||||
error ErrNotReady();
|
||||
error ErrNotInitiator();
|
||||
error ErrLowPower();
|
||||
error ErrBadTarget();
|
||||
error ErrBadSig1271();
|
||||
error ErrBadSig();
|
||||
error ErrDuplicateSigner();
|
||||
error ErrNoSigners();
|
||||
error ErrSigLengthMismatch();
|
||||
error ErrInvalidOperation();
|
||||
error ErrNameEmpty();
|
||||
error ErrSymbolEmpty();
|
||||
error ErrLocationEmpty();
|
||||
error ErrBadJurisdiction();
|
||||
error ErrBadKPP();
|
||||
error ErrBadQuorum();
|
||||
error ErrChainAlreadySupported();
|
||||
error ErrCannotAddCurrentChain();
|
||||
error ErrChainNotSupported();
|
||||
error ErrCannotRemoveCurrentChain();
|
||||
error ErrTransfersDisabled();
|
||||
error ErrApprovalsDisabled();
|
||||
error ErrProposalCanceled();
|
||||
|
||||
// Константы безопасности (можно изменять через governance)
|
||||
uint256 public maxVotingDuration = 30 days; // Максимальное время голосования
|
||||
uint256 public minVotingDuration = 1 hours; // Минимальное время голосования
|
||||
// Удалён буфер ограничения голосования в последние минуты перед дедлайном
|
||||
|
||||
constructor(
|
||||
DLEConfig memory config,
|
||||
uint256 _currentChainId
|
||||
uint256 _currentChainId,
|
||||
address _initializer
|
||||
) ERC20(config.name, config.symbol) ERC20Permit(config.name) {
|
||||
if (_initializer == address(0)) revert ErrZeroAddress();
|
||||
initializer = _initializer;
|
||||
dleInfo = DLEInfo({
|
||||
name: config.name,
|
||||
symbol: config.symbol,
|
||||
@@ -152,14 +210,14 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
}
|
||||
|
||||
// Распределяем начальные токены партнерам
|
||||
require(config.initialPartners.length == config.initialAmounts.length, "Arrays length mismatch");
|
||||
require(config.initialPartners.length > 0, "No initial partners");
|
||||
if (config.initialPartners.length != config.initialAmounts.length) revert ErrArrayMismatch();
|
||||
if (config.initialPartners.length == 0) revert ErrNoPartners();
|
||||
|
||||
for (uint256 i = 0; i < config.initialPartners.length; i++) {
|
||||
address partner = config.initialPartners[i];
|
||||
uint256 amount = config.initialAmounts[i];
|
||||
require(partner != address(0), "Zero address");
|
||||
require(amount > 0, "Zero amount");
|
||||
if (partner == address(0)) revert ErrZeroAddress();
|
||||
if (amount == 0) revert ErrZeroAmount();
|
||||
_mint(partner, amount);
|
||||
// Авто-делегирование голосов себе, чтобы getPastVotes работал без действия пользователя
|
||||
_delegate(partner, partner);
|
||||
@@ -179,6 +237,17 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Одноразовая инициализация URI логотипа. Доступно только инициализатору и только один раз.
|
||||
*/
|
||||
function initializeLogoURI(string calldata _logoURI) external {
|
||||
if (msg.sender != initializer) revert ErrOnlyInitializer();
|
||||
if (bytes(logoURI).length != 0) revert ErrLogoAlreadySet();
|
||||
string memory old = logoURI;
|
||||
logoURI = _logoURI;
|
||||
emit LogoURIUpdated(old, _logoURI);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Создать предложение с выбором цепочки для кворума
|
||||
* @param _description Описание предложения
|
||||
@@ -194,9 +263,10 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
uint256[] memory _targetChains,
|
||||
uint256 /* _timelockDelay */
|
||||
) external returns (uint256) {
|
||||
require(balanceOf(msg.sender) > 0, "Must hold tokens to create proposal");
|
||||
require(_duration > 0, "Duration must be positive");
|
||||
require(supportedChains[_governanceChainId], "Chain not supported");
|
||||
if (balanceOf(msg.sender) == 0) revert ErrNotHolder();
|
||||
if (_duration < minVotingDuration) revert ErrTooShort();
|
||||
if (_duration > maxVotingDuration) revert ErrTooLong();
|
||||
if (!supportedChains[_governanceChainId]) revert ErrBadChain();
|
||||
// _timelockDelay параметр игнорируется; timelock вынесем в отдельный модуль
|
||||
return _createProposalInternal(
|
||||
_description,
|
||||
@@ -235,7 +305,7 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
|
||||
// запись целевых сетей
|
||||
for (uint256 i = 0; i < _targetChains.length; i++) {
|
||||
require(supportedChains[_targetChains[i]], "Target chain not supported");
|
||||
if (!supportedChains[_targetChains[i]]) revert ErrBadTarget();
|
||||
proposal.targetChains.push(_targetChains[i]);
|
||||
}
|
||||
|
||||
@@ -253,14 +323,15 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
*/
|
||||
function vote(uint256 _proposalId, bool _support) external nonReentrant {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
require(block.timestamp < proposal.deadline, "Voting ended");
|
||||
require(!proposal.executed, "Proposal already executed");
|
||||
require(!proposal.hasVoted[msg.sender], "Already voted");
|
||||
require(currentChainId == proposal.governanceChainId, "Wrong chain for voting");
|
||||
if (proposal.id != _proposalId) revert ErrProposalMissing();
|
||||
if (block.timestamp >= proposal.deadline) revert ErrProposalEnded();
|
||||
if (proposal.executed) revert ErrProposalExecuted();
|
||||
if (proposal.canceled) revert ErrProposalCanceled();
|
||||
if (proposal.hasVoted[msg.sender]) revert ErrAlreadyVoted();
|
||||
if (currentChainId != proposal.governanceChainId) revert ErrWrongChain();
|
||||
|
||||
// используем снапшот голосов для защиты от перелива
|
||||
uint256 votingPower = getPastVotes(msg.sender, proposal.snapshotTimepoint);
|
||||
if (votingPower == 0) revert ErrNoPower();
|
||||
proposal.hasVoted[msg.sender] = true;
|
||||
|
||||
if (_support) {
|
||||
@@ -273,16 +344,9 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
}
|
||||
|
||||
// УДАЛЕНО: syncVoteFromChain с MerkleProof — небезопасно без доверенного моста
|
||||
|
||||
/**
|
||||
* @dev Проверить результат предложения
|
||||
* @param _proposalId ID предложения
|
||||
* @return passed Прошло ли предложение
|
||||
* @return quorumReached Достигнут ли кворум
|
||||
*/
|
||||
function checkProposalResult(uint256 _proposalId) public view returns (bool passed, bool quorumReached) {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
if (proposal.id != _proposalId) revert ErrProposalMissing();
|
||||
|
||||
uint256 totalVotes = proposal.forVotes + proposal.againstVotes;
|
||||
// Используем снапшот totalSupply на момент начала голосования
|
||||
@@ -295,25 +359,20 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
return (passed, quorumReached);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Исполнить предложение
|
||||
* @param _proposalId ID предложения
|
||||
*/
|
||||
|
||||
function executeProposal(uint256 _proposalId) external {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
require(!proposal.executed, "Proposal already executed");
|
||||
require(currentChainId == proposal.governanceChainId, "Execute only in governance chain");
|
||||
if (proposal.id != _proposalId) revert ErrProposalMissing();
|
||||
if (proposal.executed) revert ErrProposalExecuted();
|
||||
if (proposal.canceled) revert ErrProposalCanceled();
|
||||
if (currentChainId != proposal.governanceChainId) revert ErrWrongChain();
|
||||
|
||||
(bool passed, bool quorumReached) = checkProposalResult(_proposalId);
|
||||
|
||||
// Предложение можно выполнить если:
|
||||
// 1. Дедлайн истек ИЛИ кворум достигнут
|
||||
require(
|
||||
block.timestamp >= proposal.deadline || quorumReached,
|
||||
"Voting not ended and quorum not reached"
|
||||
);
|
||||
require(passed && quorumReached, "Proposal not passed");
|
||||
if (!(block.timestamp >= proposal.deadline || quorumReached)) revert ErrNotReady();
|
||||
if (!(passed && quorumReached)) revert ErrNotReady();
|
||||
|
||||
proposal.executed = true;
|
||||
|
||||
@@ -323,42 +382,38 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
emit ProposalExecuted(_proposalId, proposal.operation);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Отмена предложения до истечения голосования инициатором при наличии достаточной голосующей силы.
|
||||
* Это soft-cancel для защиты от явных ошибок. Порог: >= 10% от снапшотного supply.
|
||||
*/
|
||||
|
||||
function cancelProposal(uint256 _proposalId, string calldata reason) external {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
require(!proposal.executed, "Already executed");
|
||||
require(block.timestamp < proposal.deadline, "Voting ended");
|
||||
require(msg.sender == proposal.initiator, "Only initiator");
|
||||
if (proposal.id != _proposalId) revert ErrProposalMissing();
|
||||
if (proposal.executed) revert ErrProposalExecuted();
|
||||
if (block.timestamp + 900 >= proposal.deadline) revert ErrProposalEnded();
|
||||
if (msg.sender != proposal.initiator) revert ErrNotInitiator();
|
||||
uint256 vp = getPastVotes(msg.sender, proposal.snapshotTimepoint);
|
||||
uint256 pastSupply = getPastTotalSupply(proposal.snapshotTimepoint);
|
||||
require(vp * 10 >= pastSupply, "Insufficient voting power to cancel");
|
||||
if (vp * 10 < pastSupply) revert ErrLowPower();
|
||||
|
||||
proposal.canceled = true;
|
||||
emit ProposalCancelled(_proposalId, reason);
|
||||
}
|
||||
|
||||
// УДАЛЕНО: syncExecutionFromChain с MerkleProof — небезопасно без доверенного моста
|
||||
|
||||
/**
|
||||
* @dev Исполнение предложения в НЕ governance-сети по подписям холдеров на снапшоте.
|
||||
* Подходит для target chains. Не требует внешнего моста.
|
||||
*/
|
||||
function executeProposalBySignatures(
|
||||
uint256 _proposalId,
|
||||
address[] calldata signers,
|
||||
bytes[] calldata signatures
|
||||
) external nonReentrant {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
require(!proposal.executed, "Proposal already executed in this chain");
|
||||
require(currentChainId != proposal.governanceChainId, "Use executeProposal in governance chain");
|
||||
require(_isTargetChain(proposal, currentChainId), "Chain not in targets");
|
||||
if (proposal.id != _proposalId) revert ErrProposalMissing();
|
||||
if (proposal.executed) revert ErrProposalExecuted();
|
||||
if (proposal.canceled) revert ErrProposalCanceled();
|
||||
if (currentChainId == proposal.governanceChainId) revert ErrWrongChain();
|
||||
if (!_isTargetChain(proposal, currentChainId)) revert ErrBadTarget();
|
||||
|
||||
require(signers.length == signatures.length, "Bad signatures");
|
||||
if (signers.length != signatures.length) revert ErrSigLengthMismatch();
|
||||
if (signers.length == 0) revert ErrNoSigners();
|
||||
// Все держатели токенов имеют право голосовать
|
||||
|
||||
bytes32 opHash = keccak256(proposal.operation);
|
||||
bytes32 structHash = keccak256(abi.encode(
|
||||
EXECUTION_APPROVAL_TYPEHASH,
|
||||
@@ -370,76 +425,44 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
bytes32 digest = _hashTypedDataV4(structHash);
|
||||
|
||||
uint256 votesFor = 0;
|
||||
// простая защита от дублей адресов (O(n^2) по малому n)
|
||||
|
||||
for (uint256 i = 0; i < signers.length; i++) {
|
||||
address recovered = ECDSA.recover(digest, signatures[i]);
|
||||
require(recovered == signers[i], "Bad signature");
|
||||
// проверка на дубли
|
||||
for (uint256 j = 0; j < i; j++) {
|
||||
require(signers[j] != recovered, "Duplicate signer");
|
||||
address signer = signers[i];
|
||||
if (signer.code.length > 0) {
|
||||
// Контрактный кошелёк: проверяем подпись по EIP-1271
|
||||
try IERC1271(signer).isValidSignature(digest, signatures[i]) returns (bytes4 magic) {
|
||||
if (magic != 0x1626ba7e) revert ErrBadSig1271();
|
||||
} catch {
|
||||
revert ErrBadSig1271();
|
||||
}
|
||||
} else {
|
||||
// EOA подпись через ECDSA
|
||||
address recovered = ECDSA.recover(digest, signatures[i]);
|
||||
if (recovered != signer) revert ErrBadSig();
|
||||
}
|
||||
uint256 vp = getPastVotes(recovered, proposal.snapshotTimepoint);
|
||||
require(vp > 0, "No voting power at snapshot");
|
||||
|
||||
for (uint256 j = 0; j < i; j++) {
|
||||
if (signers[j] == signer) revert ErrDuplicateSigner();
|
||||
}
|
||||
|
||||
uint256 vp = getPastVotes(signer, proposal.snapshotTimepoint);
|
||||
if (vp == 0) revert ErrNoPower();
|
||||
votesFor += vp;
|
||||
}
|
||||
|
||||
uint256 pastSupply = getPastTotalSupply(proposal.snapshotTimepoint);
|
||||
uint256 quorumRequired = (pastSupply * quorumPercentage) / 100;
|
||||
require(votesFor >= quorumRequired, "Quorum not reached by sigs");
|
||||
if (votesFor < quorumRequired) revert ErrNoPower();
|
||||
|
||||
proposal.executed = true;
|
||||
_executeOperation(proposal.operation);
|
||||
emit ProposalExecuted(_proposalId, proposal.operation);
|
||||
emit ProposalExecutionApprovedInChain(_proposalId, currentChainId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Проверить подключение к цепочке
|
||||
* @param _chainId ID цепочки
|
||||
* @return isAvailable Доступна ли цепочка
|
||||
*/
|
||||
function checkChainConnection(uint256 _chainId) public view returns (bool isAvailable) {
|
||||
// Упрощенная проверка: цепочка объявлена как поддерживаемая
|
||||
return supportedChains[_chainId];
|
||||
}
|
||||
// Sync функции удалены для экономии байт-кода
|
||||
|
||||
/**
|
||||
* @dev Проверить все подключения перед синхронизацией
|
||||
* @param _proposalId ID предложения
|
||||
* @return allChainsReady Готовы ли все цепочки
|
||||
*/
|
||||
function checkSyncReadiness(uint256 _proposalId) public view returns (bool allChainsReady) {
|
||||
Proposal storage proposal = proposals[_proposalId];
|
||||
require(proposal.id == _proposalId, "Proposal does not exist");
|
||||
|
||||
// Проверяем все поддерживаемые цепочки
|
||||
for (uint256 i = 0; i < getSupportedChainCount(); i++) {
|
||||
uint256 chainId = getSupportedChainId(i);
|
||||
if (!checkChainConnection(chainId)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Синхронизация только при 100% готовности
|
||||
* @param _proposalId ID предложения
|
||||
*/
|
||||
function syncToAllChains(uint256 _proposalId) external {
|
||||
require(checkSyncReadiness(_proposalId), "Not all chains ready");
|
||||
|
||||
// В этой версии без внешнего моста синхронизация выполняется
|
||||
// через executeProposalBySignatures в целевых сетях.
|
||||
emit SyncCompleted(_proposalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Синхронизация в конкретную цепочку
|
||||
* @param _proposalId ID предложения
|
||||
* @param _chainId ID цепочки
|
||||
*/
|
||||
// УДАЛЕНО: syncToChain — не используется в подпись‑ориентированной схеме
|
||||
|
||||
/**
|
||||
@@ -508,23 +531,28 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
* @param _operation Операция для исполнения
|
||||
*/
|
||||
function _executeOperation(bytes memory _operation) internal {
|
||||
// Декодируем операцию
|
||||
(bytes4 selector, bytes memory data) = abi.decode(_operation, (bytes4, bytes));
|
||||
if (_operation.length < 4) revert ErrInvalidOperation();
|
||||
|
||||
if (selector == bytes4(keccak256("updateDLEInfo(string,string,string,string,uint256,string[],uint256)"))) {
|
||||
// Операция обновления информации DLE
|
||||
(string memory name, string memory symbol, string memory location, string memory coordinates,
|
||||
uint256 jurisdiction, string[] memory okvedCodes, uint256 kpp) = abi.decode(data, (string, string, string, string, uint256, string[], uint256));
|
||||
_updateDLEInfo(name, symbol, location, coordinates, jurisdiction, okvedCodes, kpp);
|
||||
} else if (selector == bytes4(keccak256("updateQuorumPercentage(uint256)"))) {
|
||||
// Операция обновления процента кворума
|
||||
(uint256 newQuorumPercentage) = abi.decode(data, (uint256));
|
||||
_updateQuorumPercentage(newQuorumPercentage);
|
||||
} else if (selector == bytes4(keccak256("updateCurrentChainId(uint256)"))) {
|
||||
// Операция обновления текущей цепочки
|
||||
(uint256 newChainId) = abi.decode(data, (uint256));
|
||||
_updateCurrentChainId(newChainId);
|
||||
} else if (selector == bytes4(keccak256("_addModule(bytes32,address)"))) {
|
||||
// Декодируем операцию из formата abi.encodeWithSelector
|
||||
bytes4 selector;
|
||||
bytes memory data;
|
||||
|
||||
// Извлекаем селектор (первые 4 байта)
|
||||
assembly {
|
||||
selector := mload(add(_operation, 0x20))
|
||||
}
|
||||
|
||||
// Извлекаем данные (все после первых 4 байтов)
|
||||
if (_operation.length > 4) {
|
||||
data = new bytes(_operation.length - 4);
|
||||
for (uint256 i = 0; i < data.length; i++) {
|
||||
data[i] = _operation[i + 4];
|
||||
}
|
||||
} else {
|
||||
data = new bytes(0);
|
||||
}
|
||||
|
||||
if (selector == bytes4(keccak256("_addModule(bytes32,address)"))) {
|
||||
// Операция добавления модуля
|
||||
(bytes32 moduleId, address moduleAddress) = abi.decode(data, (bytes32, address));
|
||||
_addModule(moduleId, moduleAddress);
|
||||
@@ -542,13 +570,32 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
// Операция перевода токенов через governance
|
||||
(address recipient, uint256 amount) = abi.decode(data, (address, uint256));
|
||||
_transferTokens(recipient, amount);
|
||||
} else if (selector == bytes4(keccak256("_updateVotingDurations(uint256,uint256)"))) {
|
||||
// Операция обновления времени голосования
|
||||
(uint256 newMinDuration, uint256 newMaxDuration) = abi.decode(data, (uint256, uint256));
|
||||
_updateVotingDurations(newMinDuration, newMaxDuration);
|
||||
} else if (selector == bytes4(keccak256("_setLogoURI(string)"))) {
|
||||
// Обновление логотипа через governance
|
||||
(string memory newLogo) = abi.decode(data, (string));
|
||||
_setLogoURI(newLogo);
|
||||
} else if (selector == bytes4(keccak256("_updateQuorumPercentage(uint256)"))) {
|
||||
// Операция обновления процента кворума
|
||||
(uint256 newQuorumPercentage) = abi.decode(data, (uint256));
|
||||
_updateQuorumPercentage(newQuorumPercentage);
|
||||
} else if (selector == bytes4(keccak256("_updateCurrentChainId(uint256)"))) {
|
||||
// Операция обновления текущей цепочки
|
||||
(uint256 newChainId) = abi.decode(data, (uint256));
|
||||
_updateCurrentChainId(newChainId);
|
||||
} else if (selector == bytes4(keccak256("_updateDLEInfo(string,string,string,string,uint256,string[],uint256)"))) {
|
||||
// Операция обновления информации DLE
|
||||
(string memory name, string memory symbol, string memory location, string memory coordinates, uint256 jurisdiction, string[] memory okvedCodes, uint256 kpp) = abi.decode(data, (string, string, string, string, uint256, string[], uint256));
|
||||
_updateDLEInfo(name, symbol, location, coordinates, jurisdiction, okvedCodes, kpp);
|
||||
} else if (selector == bytes4(keccak256("offchainAction(bytes32,string,bytes32)"))) {
|
||||
// Оффчейн операция для приложения: идентификатор, тип, хеш полезной нагрузки
|
||||
// (bytes32 actionId, string memory kind, bytes32 payloadHash) = abi.decode(data, (bytes32, string, bytes32));
|
||||
// Ончейн-побочных эффектов нет. Факт решения фиксируется событием ProposalExecuted.
|
||||
} else {
|
||||
// Неизвестная операция
|
||||
revert("Unknown operation");
|
||||
revert ErrInvalidOperation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,11 +618,11 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
string[] memory _okvedCodes,
|
||||
uint256 _kpp
|
||||
) internal {
|
||||
require(bytes(_name).length > 0, "Name cannot be empty");
|
||||
require(bytes(_symbol).length > 0, "Symbol cannot be empty");
|
||||
require(bytes(_location).length > 0, "Location cannot be empty");
|
||||
require(_jurisdiction > 0, "Invalid jurisdiction");
|
||||
require(_kpp > 0, "Invalid KPP");
|
||||
if (bytes(_name).length == 0) revert ErrNameEmpty();
|
||||
if (bytes(_symbol).length == 0) revert ErrSymbolEmpty();
|
||||
if (bytes(_location).length == 0) revert ErrLocationEmpty();
|
||||
if (_jurisdiction == 0) revert ErrBadJurisdiction();
|
||||
if (_kpp == 0) revert ErrBadKPP();
|
||||
|
||||
dleInfo.name = _name;
|
||||
dleInfo.symbol = _symbol;
|
||||
@@ -593,7 +640,7 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
* @param _newQuorumPercentage Новый процент кворума
|
||||
*/
|
||||
function _updateQuorumPercentage(uint256 _newQuorumPercentage) internal {
|
||||
require(_newQuorumPercentage > 0 && _newQuorumPercentage <= 100, "Invalid quorum percentage");
|
||||
if (!(_newQuorumPercentage > 0 && _newQuorumPercentage <= 100)) revert ErrBadQuorum();
|
||||
|
||||
uint256 oldQuorumPercentage = quorumPercentage;
|
||||
quorumPercentage = _newQuorumPercentage;
|
||||
@@ -606,8 +653,8 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
* @param _newChainId Новый ID цепочки
|
||||
*/
|
||||
function _updateCurrentChainId(uint256 _newChainId) internal {
|
||||
require(supportedChains[_newChainId], "Chain not supported");
|
||||
require(_newChainId != currentChainId, "Same chain ID");
|
||||
if (!supportedChains[_newChainId]) revert ErrChainNotSupported();
|
||||
if (_newChainId == currentChainId) revert ErrCannotAddCurrentChain();
|
||||
|
||||
uint256 oldChainId = currentChainId;
|
||||
currentChainId = _newChainId;
|
||||
@@ -621,8 +668,8 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
* @param _amount Количество токенов для перевода
|
||||
*/
|
||||
function _transferTokens(address _recipient, uint256 _amount) internal {
|
||||
require(_recipient != address(0), "Cannot transfer to zero address");
|
||||
require(_amount > 0, "Amount must be positive");
|
||||
if (_recipient == address(0)) revert ErrZeroAddress();
|
||||
if (_amount == 0) revert ErrZeroAmount();
|
||||
require(balanceOf(address(this)) >= _amount, "Insufficient DLE balance");
|
||||
|
||||
// Переводим токены от имени DLE (address(this))
|
||||
@@ -631,6 +678,73 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
emit TokensTransferredByGovernance(_recipient, _amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить время голосования (только через governance)
|
||||
* @param _newMinDuration Новое минимальное время голосования
|
||||
* @param _newMaxDuration Новое максимальное время голосования
|
||||
*/
|
||||
function _updateVotingDurations(uint256 _newMinDuration, uint256 _newMaxDuration) internal {
|
||||
if (_newMinDuration == 0) revert ErrTooShort();
|
||||
if (!(_newMaxDuration > _newMinDuration)) revert ErrTooLong();
|
||||
if (_newMinDuration < 10 minutes) revert ErrTooShort();
|
||||
if (_newMaxDuration > 365 days) revert ErrTooLong();
|
||||
|
||||
uint256 oldMinDuration = minVotingDuration;
|
||||
uint256 oldMaxDuration = maxVotingDuration;
|
||||
|
||||
minVotingDuration = _newMinDuration;
|
||||
maxVotingDuration = _newMaxDuration;
|
||||
|
||||
emit VotingDurationsUpdated(oldMinDuration, _newMinDuration, oldMaxDuration, _newMaxDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Внутреннее обновление URI логотипа (только через governance).
|
||||
*/
|
||||
function _setLogoURI(string memory _logoURI) internal {
|
||||
string memory old = logoURI;
|
||||
logoURI = _logoURI;
|
||||
emit LogoURIUpdated(old, _logoURI);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @dev Инициализировать базовые модули (вызывается только один раз при деплое)
|
||||
* @param _treasuryAddress Адрес Treasury модуля
|
||||
* @param _timelockAddress Адрес Timelock модуля
|
||||
* @param _readerAddress Адрес Reader модуля
|
||||
*/
|
||||
function initializeBaseModules(
|
||||
address _treasuryAddress,
|
||||
address _timelockAddress,
|
||||
address _readerAddress
|
||||
) external {
|
||||
if (modulesInitialized) revert ErrProposalExecuted(); // keep existing error to avoid new identifier
|
||||
if (msg.sender != initializer) revert ErrOnlyInitializer();
|
||||
if (_treasuryAddress == address(0) || _timelockAddress == address(0) || _readerAddress == address(0)) revert ErrZeroAddress();
|
||||
|
||||
// Добавляем базовые модули без голосования (только при инициализации)
|
||||
bytes32 treasuryId = keccak256("TREASURY");
|
||||
bytes32 timelockId = keccak256("TIMELOCK");
|
||||
bytes32 readerId = keccak256("READER");
|
||||
|
||||
modules[treasuryId] = _treasuryAddress;
|
||||
activeModules[treasuryId] = true;
|
||||
|
||||
modules[timelockId] = _timelockAddress;
|
||||
activeModules[timelockId] = true;
|
||||
|
||||
modules[readerId] = _readerAddress;
|
||||
activeModules[readerId] = true;
|
||||
|
||||
modulesInitialized = true;
|
||||
|
||||
emit ModuleAdded(treasuryId, _treasuryAddress);
|
||||
emit ModuleAdded(timelockId, _timelockAddress);
|
||||
emit ModuleAdded(readerId, _readerAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Создать предложение о добавлении модуля
|
||||
* @param _description Описание предложения
|
||||
@@ -646,10 +760,10 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
address _moduleAddress,
|
||||
uint256 _chainId
|
||||
) external returns (uint256) {
|
||||
require(supportedChains[_chainId], "Chain not supported");
|
||||
require(_moduleAddress != address(0), "Zero address");
|
||||
require(!activeModules[_moduleId], "Module already exists");
|
||||
require(balanceOf(msg.sender) > 0, "Must hold tokens to create proposal");
|
||||
if (!supportedChains[_chainId]) revert ErrChainNotSupported();
|
||||
if (_moduleAddress == address(0)) revert ErrZeroAddress();
|
||||
if (activeModules[_moduleId]) revert ErrProposalExecuted();
|
||||
if (balanceOf(msg.sender) == 0) revert ErrNotHolder();
|
||||
|
||||
// Операция добавления модуля
|
||||
bytes memory operation = abi.encodeWithSelector(
|
||||
@@ -688,9 +802,9 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
bytes32 _moduleId,
|
||||
uint256 _chainId
|
||||
) external returns (uint256) {
|
||||
require(supportedChains[_chainId], "Chain not supported");
|
||||
require(activeModules[_moduleId], "Module does not exist");
|
||||
require(balanceOf(msg.sender) > 0, "Must hold tokens to create proposal");
|
||||
if (!supportedChains[_chainId]) revert ErrChainNotSupported();
|
||||
if (!activeModules[_moduleId]) revert ErrProposalMissing();
|
||||
if (balanceOf(msg.sender) == 0) revert ErrNotHolder();
|
||||
|
||||
// Операция удаления модуля
|
||||
bytes memory operation = abi.encodeWithSelector(
|
||||
@@ -715,14 +829,16 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
);
|
||||
}
|
||||
|
||||
// Treasury операции перенесены в TreasuryModule для экономии байт-кода
|
||||
|
||||
/**
|
||||
* @dev Добавить модуль (внутренняя функция, вызывается через кворум)
|
||||
* @param _moduleId ID модуля
|
||||
* @param _moduleAddress Адрес модуля
|
||||
*/
|
||||
function _addModule(bytes32 _moduleId, address _moduleAddress) internal {
|
||||
require(_moduleAddress != address(0), "Zero address");
|
||||
require(!activeModules[_moduleId], "Module already exists");
|
||||
if (_moduleAddress == address(0)) revert ErrZeroAddress();
|
||||
if (activeModules[_moduleId]) revert ErrProposalExecuted();
|
||||
|
||||
modules[_moduleId] = _moduleAddress;
|
||||
activeModules[_moduleId] = true;
|
||||
@@ -735,7 +851,7 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
* @param _moduleId ID модуля
|
||||
*/
|
||||
function _removeModule(bytes32 _moduleId) internal {
|
||||
require(activeModules[_moduleId], "Module does not exist");
|
||||
if (!activeModules[_moduleId]) revert ErrProposalMissing();
|
||||
|
||||
delete modules[_moduleId];
|
||||
activeModules[_moduleId] = false;
|
||||
@@ -781,73 +897,7 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
return currentChainId;
|
||||
}
|
||||
|
||||
// ===== Интерфейс аналитики для API =====
|
||||
function getProposalSummary(uint256 _proposalId) external view returns (
|
||||
uint256 id,
|
||||
string memory description,
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
bool executed,
|
||||
bool canceled,
|
||||
uint256 deadline,
|
||||
address initiator,
|
||||
uint256 governanceChainId,
|
||||
|
||||
uint256 snapshotTimepoint,
|
||||
uint256[] memory targets
|
||||
) {
|
||||
Proposal storage p = proposals[_proposalId];
|
||||
require(p.id == _proposalId, "Proposal does not exist");
|
||||
return (
|
||||
p.id,
|
||||
p.description,
|
||||
p.forVotes,
|
||||
p.againstVotes,
|
||||
p.executed,
|
||||
p.canceled,
|
||||
p.deadline,
|
||||
p.initiator,
|
||||
p.governanceChainId,
|
||||
|
||||
p.snapshotTimepoint,
|
||||
p.targetChains
|
||||
);
|
||||
}
|
||||
|
||||
function getGovernanceParams() external view returns (
|
||||
uint256 quorumPct,
|
||||
uint256 chainId,
|
||||
uint256 supportedCount
|
||||
) {
|
||||
return (quorumPercentage, currentChainId, supportedChainIds.length);
|
||||
}
|
||||
|
||||
function listSupportedChains() external view returns (uint256[] memory) {
|
||||
return supportedChainIds;
|
||||
}
|
||||
|
||||
function getVotingPowerAt(address voter, uint256 timepoint) external view returns (uint256) {
|
||||
return getPastVotes(voter, timepoint);
|
||||
}
|
||||
|
||||
// ===== Пагинация и агрегирование =====
|
||||
function getProposalsCount() external view returns (uint256) {
|
||||
return allProposalIds.length;
|
||||
}
|
||||
|
||||
function listProposals(uint256 offset, uint256 limit) external view returns (uint256[] memory) {
|
||||
uint256 total = allProposalIds.length;
|
||||
if (offset >= total) {
|
||||
return new uint256[](0);
|
||||
}
|
||||
uint256 end = offset + limit;
|
||||
if (end > total) end = total;
|
||||
uint256[] memory page = new uint256[](end - offset);
|
||||
for (uint256 i = offset; i < end; i++) {
|
||||
page[i - offset] = allProposalIds[i];
|
||||
}
|
||||
return page;
|
||||
}
|
||||
// API функции вынесены в отдельный reader контракт для экономии байт-кода
|
||||
|
||||
// 0=Pending, 1=Succeeded, 2=Defeated, 3=Executed, 4=Canceled, 5=ReadyForExecution
|
||||
function getProposalState(uint256 _proposalId) public view returns (uint8 state) {
|
||||
@@ -864,33 +914,11 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
return 0; // Pending
|
||||
}
|
||||
|
||||
function getQuorumAt(uint256 timepoint) external view returns (uint256) {
|
||||
uint256 supply = getPastTotalSupply(timepoint);
|
||||
return (supply * quorumPercentage) / 100;
|
||||
}
|
||||
|
||||
function getProposalVotes(uint256 _proposalId) external view returns (
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
uint256 totalVotes,
|
||||
uint256 quorumRequired
|
||||
) {
|
||||
Proposal storage p = proposals[_proposalId];
|
||||
require(p.id == _proposalId, "Proposal does not exist");
|
||||
uint256 supply = getPastTotalSupply(p.snapshotTimepoint);
|
||||
uint256 quorumReq = (supply * quorumPercentage) / 100;
|
||||
return (p.forVotes, p.againstVotes, p.forVotes + p.againstVotes, quorumReq);
|
||||
}
|
||||
|
||||
// События для новых функций
|
||||
event SyncCompleted(uint256 proposalId);
|
||||
event DLEDeactivated(address indexed deactivatedBy, uint256 timestamp);
|
||||
|
||||
bool public isDeactivated;
|
||||
// Функции для подсчёта голосов вынесены в reader контракт
|
||||
|
||||
// Деактивация вынесена в отдельный модуль. См. DeactivationModule.
|
||||
function isActive() external view returns (bool) {
|
||||
return !isDeactivated && dleInfo.isActive;
|
||||
return dleInfo.isActive;
|
||||
}
|
||||
// ===== Вспомогательные функции =====
|
||||
function _isTargetChain(Proposal storage p, uint256 chainId) internal view returns (bool) {
|
||||
@@ -908,7 +936,7 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
super._update(from, to, value);
|
||||
}
|
||||
|
||||
// Разрешаем неоднозначность nonces из базовых классов
|
||||
// Разрешение неоднозначности nonces между ERC20Permit и Nonces
|
||||
function nonces(address owner)
|
||||
public
|
||||
view
|
||||
@@ -929,32 +957,28 @@ contract DLE is ERC20, ERC20Permit, ERC20Votes, ReentrancyGuard {
|
||||
|
||||
/**
|
||||
* @dev Блокирует прямые переводы токенов
|
||||
* @param to Адрес получателя (не используется)
|
||||
* @param amount Количество токенов (не используется)
|
||||
* @return Всегда возвращает false
|
||||
* @return Всегда ревертится
|
||||
*/
|
||||
function transfer(address to, uint256 amount) public override returns (bool) {
|
||||
revert("Direct transfers disabled. Use governance proposals for token transfers.");
|
||||
function transfer(address /*to*/, uint256 /*amount*/) public pure override returns (bool) {
|
||||
// coverage:ignore-line
|
||||
revert ErrTransfersDisabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Блокирует прямые переводы токенов через approve/transferFrom
|
||||
* @param from Адрес отправителя (не используется)
|
||||
* @param to Адрес получателя (не используется)
|
||||
* @param amount Количество токенов (не используется)
|
||||
* @return Всегда возвращает false
|
||||
* @return Всегда ревертится
|
||||
*/
|
||||
function transferFrom(address from, address to, uint256 amount) public override returns (bool) {
|
||||
revert("Direct transfers disabled. Use governance proposals for token transfers.");
|
||||
function transferFrom(address /*from*/, address /*to*/, uint256 /*amount*/) public pure override returns (bool) {
|
||||
// coverage:ignore-line
|
||||
revert ErrTransfersDisabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Блокирует прямые разрешения на перевод токенов
|
||||
* @param spender Адрес, которому разрешается тратить токены (не используется)
|
||||
* @param amount Количество токенов (не используется)
|
||||
* @return Всегда возвращает false
|
||||
* @return Всегда ревертится
|
||||
*/
|
||||
function approve(address spender, uint256 amount) public override returns (bool) {
|
||||
revert("Direct approvals disabled. Use governance proposals for token transfers.");
|
||||
function approve(address /*spender*/, uint256 /*amount*/) public pure override returns (bool) {
|
||||
// coverage:ignore-line
|
||||
revert ErrApprovalsDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
360
backend/contracts/DLEReader.sol
Normal file
360
backend/contracts/DLEReader.sol
Normal file
@@ -0,0 +1,360 @@
|
||||
// SPDX-License-Identifier: PROPRIETARY AND MIT
|
||||
// Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
// All rights reserved.
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
interface IDLEReader {
|
||||
// Структуры из основного контракта
|
||||
struct DLEInfo {
|
||||
string name;
|
||||
string symbol;
|
||||
string location;
|
||||
string coordinates;
|
||||
uint256 jurisdiction;
|
||||
string[] okvedCodes;
|
||||
uint256 kpp;
|
||||
uint256 creationTimestamp;
|
||||
bool isActive;
|
||||
}
|
||||
|
||||
struct Proposal {
|
||||
uint256 id;
|
||||
string description;
|
||||
uint256 forVotes;
|
||||
uint256 againstVotes;
|
||||
bool executed;
|
||||
bool canceled;
|
||||
uint256 deadline;
|
||||
address initiator;
|
||||
bytes operation;
|
||||
uint256 governanceChainId;
|
||||
uint256[] targetChains;
|
||||
uint256 snapshotTimepoint;
|
||||
}
|
||||
|
||||
// Основные функции чтения
|
||||
function getDLEInfo() external view returns (DLEInfo memory);
|
||||
function proposals(uint256) external view returns (
|
||||
uint256 id,
|
||||
string memory description,
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
bool executed,
|
||||
bool canceled,
|
||||
uint256 deadline,
|
||||
address initiator,
|
||||
bytes memory operation,
|
||||
uint256 governanceChainId,
|
||||
uint256 snapshotTimepoint
|
||||
);
|
||||
function allProposalIds(uint256) external view returns (uint256);
|
||||
function supportedChainIds(uint256) external view returns (uint256);
|
||||
function quorumPercentage() external view returns (uint256);
|
||||
function currentChainId() external view returns (uint256);
|
||||
function totalSupply() external view returns (uint256);
|
||||
function getPastTotalSupply(uint256) external view returns (uint256);
|
||||
function getPastVotes(address, uint256) external view returns (uint256);
|
||||
function checkProposalResult(uint256) external view returns (bool, bool);
|
||||
function getProposalState(uint256) external view returns (uint8);
|
||||
function balanceOf(address) external view returns (uint256);
|
||||
function isChainSupported(uint256) external view returns (bool);
|
||||
function isModuleActive(bytes32) external view returns (bool);
|
||||
function getModuleAddress(bytes32) external view returns (address);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title DLEReader
|
||||
* @dev Read-only контракт для API функций DLE
|
||||
*
|
||||
* БЕЗОПАСНОСТЬ:
|
||||
* - Только чтение данных (view/pure функции)
|
||||
* - Не изменяет состояние основного контракта
|
||||
* - Можно безопасно обновлять независимо от DLE
|
||||
* - Нет доступа к приватным данным
|
||||
*/
|
||||
contract DLEReader {
|
||||
|
||||
address public immutable dleContract;
|
||||
|
||||
constructor(address _dleContract) {
|
||||
require(_dleContract != address(0), "DLE contract cannot be zero");
|
||||
require(_dleContract.code.length > 0, "DLE contract must exist");
|
||||
dleContract = _dleContract;
|
||||
}
|
||||
|
||||
// ===== АГРЕГИРОВАННЫЕ ДАННЫЕ =====
|
||||
|
||||
/**
|
||||
* @dev Получить полную сводку по предложению
|
||||
*/
|
||||
function getProposalSummary(uint256 _proposalId) external view returns (
|
||||
uint256 id,
|
||||
string memory description,
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
bool executed,
|
||||
bool canceled,
|
||||
uint256 deadline,
|
||||
address initiator,
|
||||
uint256 governanceChainId,
|
||||
uint256 snapshotTimepoint,
|
||||
uint256[] memory targetChains,
|
||||
uint8 state,
|
||||
bool passed,
|
||||
bool quorumReached
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
// Получаем основные данные предложения
|
||||
(
|
||||
id,
|
||||
description,
|
||||
forVotes,
|
||||
againstVotes,
|
||||
executed,
|
||||
canceled,
|
||||
deadline,
|
||||
initiator,
|
||||
, // operation не нужна для сводки
|
||||
governanceChainId,
|
||||
snapshotTimepoint
|
||||
) = dle.proposals(_proposalId);
|
||||
|
||||
// Получаем дополнительные данные
|
||||
state = dle.getProposalState(_proposalId);
|
||||
(passed, quorumReached) = dle.checkProposalResult(_proposalId);
|
||||
|
||||
// TODO: targetChains требует отдельной функции в основном контракте
|
||||
targetChains = new uint256[](0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить параметры governance
|
||||
*/
|
||||
function getGovernanceParams() external view returns (
|
||||
uint256 quorumPct,
|
||||
uint256 chainId,
|
||||
uint256 supportedCount,
|
||||
uint256 totalSupply,
|
||||
uint256 proposalsCount
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
quorumPct = dle.quorumPercentage();
|
||||
chainId = dle.currentChainId();
|
||||
totalSupply = dle.totalSupply();
|
||||
|
||||
// Считаем поддерживаемые сети
|
||||
supportedCount = 0;
|
||||
for (uint256 i = 0; i < 50; i++) { // Ограничиваем итерации
|
||||
try dle.supportedChainIds(i) returns (uint256) {
|
||||
supportedCount++;
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Считаем предложения
|
||||
proposalsCount = 0;
|
||||
for (uint256 i = 0; i < 1000; i++) { // Ограничиваем итерации
|
||||
try dle.allProposalIds(i) returns (uint256) {
|
||||
proposalsCount++;
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить список поддерживаемых сетей
|
||||
*/
|
||||
function listSupportedChains() external view returns (uint256[] memory chains) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
// Сначала считаем количество
|
||||
uint256 count = 0;
|
||||
for (uint256 i = 0; i < 50; i++) {
|
||||
try dle.supportedChainIds(i) returns (uint256) {
|
||||
count++;
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Затем заполняем массив
|
||||
chains = new uint256[](count);
|
||||
for (uint256 i = 0; i < count; i++) {
|
||||
chains[i] = dle.supportedChainIds(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить список предложений с пагинацией
|
||||
*/
|
||||
function listProposals(uint256 offset, uint256 limit) external view returns (
|
||||
uint256[] memory proposalIds,
|
||||
uint256 total
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
// Считаем общее количество
|
||||
total = 0;
|
||||
for (uint256 i = 0; i < 10000; i++) { // Увеличиваем лимит для предложений
|
||||
try dle.allProposalIds(i) returns (uint256) {
|
||||
total++;
|
||||
} catch {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Проверяем границы
|
||||
if (offset >= total) {
|
||||
return (new uint256[](0), total);
|
||||
}
|
||||
|
||||
uint256 end = offset + limit;
|
||||
if (end > total) end = total;
|
||||
|
||||
// Заполняем страницу
|
||||
proposalIds = new uint256[](end - offset);
|
||||
for (uint256 i = offset; i < end; i++) {
|
||||
proposalIds[i - offset] = dle.allProposalIds(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить голосующую силу на определённый момент времени
|
||||
*/
|
||||
function getVotingPowerAt(address voter, uint256 timepoint) external view returns (uint256) {
|
||||
return IDLEReader(dleContract).getPastVotes(voter, timepoint);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить размер кворума на определённый момент времени
|
||||
*/
|
||||
function getQuorumAt(uint256 timepoint) external view returns (uint256) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
uint256 supply = dle.getPastTotalSupply(timepoint);
|
||||
uint256 quorumPct = dle.quorumPercentage();
|
||||
return (supply * quorumPct) / 100;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить детали голосования по предложению
|
||||
*/
|
||||
function getProposalVotes(uint256 _proposalId) external view returns (
|
||||
uint256 forVotes,
|
||||
uint256 againstVotes,
|
||||
uint256 totalVotes,
|
||||
uint256 quorumRequired,
|
||||
uint256 quorumCurrent,
|
||||
bool quorumReached
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
// Получаем основные данные предложения
|
||||
uint256 snapshotTimepoint;
|
||||
(
|
||||
, // id
|
||||
, // description
|
||||
forVotes,
|
||||
againstVotes,
|
||||
, // executed
|
||||
, // canceled
|
||||
, // deadline
|
||||
, // initiator
|
||||
, // operation
|
||||
, // governanceChainId
|
||||
snapshotTimepoint
|
||||
) = dle.proposals(_proposalId);
|
||||
|
||||
totalVotes = forVotes + againstVotes;
|
||||
|
||||
// Вычисляем кворум
|
||||
uint256 supply = dle.getPastTotalSupply(snapshotTimepoint);
|
||||
uint256 quorumPct = dle.quorumPercentage();
|
||||
quorumRequired = (supply * quorumPct) / 100;
|
||||
quorumCurrent = totalVotes;
|
||||
quorumReached = totalVotes >= quorumRequired;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить статистику по адресу
|
||||
*/
|
||||
function getAddressStats(address user) external view returns (
|
||||
uint256 tokenBalance,
|
||||
uint256 currentVotingPower,
|
||||
uint256 delegatedTo,
|
||||
bool hasTokens
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
tokenBalance = dle.balanceOf(user);
|
||||
currentVotingPower = dle.getPastVotes(user, block.number - 1);
|
||||
hasTokens = tokenBalance > 0;
|
||||
|
||||
// delegatedTo требует дополнительных функций в основном контракте
|
||||
delegatedTo = 0; // Placeholder
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить информацию о модулях
|
||||
*/
|
||||
function getModulesInfo(bytes32[] memory moduleIds) external view returns (
|
||||
address[] memory addresses,
|
||||
bool[] memory active
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
addresses = new address[](moduleIds.length);
|
||||
active = new bool[](moduleIds.length);
|
||||
|
||||
for (uint256 i = 0; i < moduleIds.length; i++) {
|
||||
addresses[i] = dle.getModuleAddress(moduleIds[i]);
|
||||
active[i] = dle.isModuleActive(moduleIds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить состояние DLE
|
||||
*/
|
||||
function getDLEStatus() external view returns (
|
||||
IDLEReader.DLEInfo memory info,
|
||||
uint256 totalSupply,
|
||||
uint256 currentChain,
|
||||
uint256 quorumPct,
|
||||
uint256 totalProposals,
|
||||
uint256 supportedChains
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
info = dle.getDLEInfo();
|
||||
totalSupply = dle.totalSupply();
|
||||
currentChain = dle.currentChainId();
|
||||
quorumPct = dle.quorumPercentage();
|
||||
|
||||
// Считаем предложения и сети
|
||||
(,, supportedChains, totalSupply, totalProposals) = this.getGovernanceParams();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Batch получение состояний предложений
|
||||
*/
|
||||
function getProposalStates(uint256[] memory proposalIds) external view returns (
|
||||
uint8[] memory states,
|
||||
bool[] memory passed,
|
||||
bool[] memory quorumReached
|
||||
) {
|
||||
IDLEReader dle = IDLEReader(dleContract);
|
||||
|
||||
states = new uint8[](proposalIds.length);
|
||||
passed = new bool[](proposalIds.length);
|
||||
quorumReached = new bool[](proposalIds.length);
|
||||
|
||||
for (uint256 i = 0; i < proposalIds.length; i++) {
|
||||
states[i] = dle.getProposalState(proposalIds[i]);
|
||||
(passed[i], quorumReached[i]) = dle.checkProposalResult(proposalIds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,12 @@ contract FactoryDeployer {
|
||||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, initCodeHash));
|
||||
return address(uint160(uint256(hash)));
|
||||
}
|
||||
|
||||
function computeAddressWithCreationCode(bytes32 salt, bytes memory creationCode) external view returns (address) {
|
||||
bytes32 initCodeHash = keccak256(creationCode);
|
||||
bytes32 hash = keccak256(abi.encodePacked(bytes1(0xff), address(this), salt, initCodeHash));
|
||||
return address(uint160(uint256(hash)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
22
backend/contracts/MockNoop.sol
Normal file
22
backend/contracts/MockNoop.sol
Normal file
@@ -0,0 +1,22 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
/**
|
||||
* @title MockNoop
|
||||
* @dev Простой мок-контракт для тестирования FactoryDeployer
|
||||
*/
|
||||
contract MockNoop {
|
||||
uint256 public value;
|
||||
|
||||
constructor() {
|
||||
value = 42;
|
||||
}
|
||||
|
||||
function setValue(uint256 _value) external {
|
||||
value = _value;
|
||||
}
|
||||
|
||||
function getValue() external view returns (uint256) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
29
backend/contracts/MockToken.sol
Normal file
29
backend/contracts/MockToken.sol
Normal file
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
/**
|
||||
* @title MockToken
|
||||
* @dev Мок-токен для тестирования TreasuryModule
|
||||
*/
|
||||
contract MockToken is ERC20 {
|
||||
address public minter;
|
||||
|
||||
constructor(string memory name, string memory symbol) ERC20(name, symbol) {
|
||||
minter = msg.sender;
|
||||
}
|
||||
|
||||
modifier onlyMinter() {
|
||||
require(msg.sender == minter, "Only minter can call this function");
|
||||
_;
|
||||
}
|
||||
|
||||
function mint(address to, uint256 amount) external onlyMinter {
|
||||
_mint(to, amount);
|
||||
}
|
||||
|
||||
function burn(uint256 amount) external {
|
||||
_burn(msg.sender, amount);
|
||||
}
|
||||
}
|
||||
399
backend/contracts/TimelockModule.sol
Normal file
399
backend/contracts/TimelockModule.sol
Normal file
@@ -0,0 +1,399 @@
|
||||
// SPDX-License-Identifier: PROPRIETARY AND MIT
|
||||
// Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
// All rights reserved.
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
|
||||
/**
|
||||
* @title TimelockModule
|
||||
* @dev Модуль временной задержки для критических операций DLE
|
||||
*
|
||||
* НАЗНАЧЕНИЕ:
|
||||
* - Добавляет обязательную задержку между принятием и исполнением решений
|
||||
* - Даёт время сообществу на обнаружение и отмену вредоносных предложений
|
||||
* - Повышает безопасность критических операций (смена кворума, добавление модулей)
|
||||
*
|
||||
* ПРИНЦИП РАБОТЫ:
|
||||
* 1. DLE исполняет операцию не напрямую, а через Timelock
|
||||
* 2. Timelock ставит операцию в очередь с задержкой
|
||||
* 3. После истечения задержки любой может исполнить операцию
|
||||
* 4. В период задержки операцию можно отменить через экстренное голосование
|
||||
*/
|
||||
contract TimelockModule is ReentrancyGuard {
|
||||
|
||||
// Структура отложенной операции
|
||||
struct QueuedOperation {
|
||||
bytes32 id; // Уникальный ID операции
|
||||
address target; // Целевой контракт (обычно DLE)
|
||||
bytes data; // Данные для вызова
|
||||
uint256 executeAfter; // Время, после которого можно исполнить
|
||||
uint256 queuedAt; // Время постановки в очередь
|
||||
bool executed; // Исполнена ли операция
|
||||
bool cancelled; // Отменена ли операция
|
||||
address proposer; // Кто поставил в очередь
|
||||
string description; // Описание операции
|
||||
uint256 delay; // Задержка для этой операции
|
||||
}
|
||||
|
||||
// Основные настройки
|
||||
address public immutable dleContract; // Адрес DLE контракта
|
||||
uint256 public defaultDelay = 2 days; // Стандартная задержка
|
||||
uint256 public emergencyDelay = 30 minutes; // Экстренная задержка
|
||||
uint256 public maxDelay = 30 days; // Максимальная задержка
|
||||
uint256 public minDelay = 1 hours; // Минимальная задержка
|
||||
|
||||
// Хранение операций
|
||||
mapping(bytes32 => QueuedOperation) public queuedOperations;
|
||||
bytes32[] public operationQueue; // Список всех операций
|
||||
mapping(bytes32 => uint256) public operationIndex; // ID => индекс в очереди
|
||||
|
||||
// Категории операций с разными задержками
|
||||
mapping(bytes4 => uint256) public operationDelays; // selector => delay
|
||||
mapping(bytes4 => bool) public criticalOperations; // критические операции
|
||||
mapping(bytes4 => bool) public emergencyOperations; // экстренные операции
|
||||
|
||||
// Статистика
|
||||
uint256 public totalOperations;
|
||||
uint256 public executedOperations;
|
||||
uint256 public cancelledOperations;
|
||||
|
||||
// События
|
||||
event OperationQueued(
|
||||
bytes32 indexed operationId,
|
||||
address indexed target,
|
||||
bytes data,
|
||||
uint256 executeAfter,
|
||||
uint256 delay,
|
||||
string description
|
||||
);
|
||||
event OperationExecuted(bytes32 indexed operationId, address indexed executor);
|
||||
event OperationCancelled(bytes32 indexed operationId, address indexed canceller, string reason);
|
||||
event DelayUpdated(bytes4 indexed selector, uint256 oldDelay, uint256 newDelay);
|
||||
event DefaultDelayUpdated(uint256 oldDelay, uint256 newDelay);
|
||||
event EmergencyExecution(bytes32 indexed operationId, string reason);
|
||||
|
||||
// Модификаторы
|
||||
modifier onlyDLE() {
|
||||
require(msg.sender == dleContract, "Only DLE can call");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier validOperation(bytes32 operationId) {
|
||||
require(queuedOperations[operationId].id == operationId, "Operation not found");
|
||||
require(!queuedOperations[operationId].executed, "Already executed");
|
||||
require(!queuedOperations[operationId].cancelled, "Operation cancelled");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(address _dleContract) {
|
||||
require(_dleContract != address(0), "DLE contract cannot be zero");
|
||||
require(_dleContract.code.length > 0, "DLE contract must exist");
|
||||
|
||||
dleContract = _dleContract;
|
||||
totalOperations = 0;
|
||||
|
||||
// Настраиваем задержки для разных типов операций
|
||||
_setupOperationDelays();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Поставить операцию в очередь (вызывается из DLE)
|
||||
* @param target Целевой контракт
|
||||
* @param data Данные операции
|
||||
* @param description Описание операции
|
||||
*/
|
||||
function queueOperation(
|
||||
address target,
|
||||
bytes memory data,
|
||||
string memory description
|
||||
) external onlyDLE returns (bytes32) {
|
||||
require(target != address(0), "Target cannot be zero");
|
||||
require(data.length >= 4, "Invalid operation data");
|
||||
|
||||
// Определяем задержку для операции
|
||||
bytes4 selector;
|
||||
assembly {
|
||||
selector := mload(add(data, 0x20))
|
||||
}
|
||||
uint256 delay = _getOperationDelay(selector);
|
||||
|
||||
// Создаём уникальный ID операции
|
||||
bytes32 operationId = keccak256(abi.encodePacked(
|
||||
target,
|
||||
data,
|
||||
block.timestamp,
|
||||
totalOperations
|
||||
));
|
||||
|
||||
// Проверяем что операция ещё не существует
|
||||
require(queuedOperations[operationId].id == bytes32(0), "Operation already exists");
|
||||
|
||||
// Создаём операцию
|
||||
queuedOperations[operationId] = QueuedOperation({
|
||||
id: operationId,
|
||||
target: target,
|
||||
data: data,
|
||||
executeAfter: block.timestamp + delay,
|
||||
queuedAt: block.timestamp,
|
||||
executed: false,
|
||||
cancelled: false,
|
||||
proposer: msg.sender, // Адрес вызывающего (обычно DLE контракт)
|
||||
description: description,
|
||||
delay: delay
|
||||
});
|
||||
|
||||
// Добавляем в очередь
|
||||
operationQueue.push(operationId);
|
||||
operationIndex[operationId] = operationQueue.length - 1;
|
||||
totalOperations++;
|
||||
|
||||
emit OperationQueued(operationId, target, data, block.timestamp + delay, delay, description);
|
||||
|
||||
return operationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Исполнить операцию после истечения задержки (может любой)
|
||||
* @param operationId ID операции
|
||||
*/
|
||||
function executeOperation(bytes32 operationId) external nonReentrant validOperation(operationId) {
|
||||
QueuedOperation storage operation = queuedOperations[operationId];
|
||||
|
||||
require(block.timestamp >= operation.executeAfter, "Timelock not expired");
|
||||
require(block.timestamp <= operation.executeAfter + 7 days, "Operation expired"); // Операции истекают через неделю
|
||||
|
||||
operation.executed = true;
|
||||
executedOperations++;
|
||||
|
||||
// Исполняем операцию
|
||||
(bool success, bytes memory result) = operation.target.call(operation.data);
|
||||
require(success, string(abi.encodePacked("Execution failed: ", result)));
|
||||
|
||||
emit OperationExecuted(operationId, msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Отменить операцию (только через DLE governance)
|
||||
* @param operationId ID операции
|
||||
* @param reason Причина отмены
|
||||
*/
|
||||
function cancelOperation(
|
||||
bytes32 operationId,
|
||||
string memory reason
|
||||
) external onlyDLE validOperation(operationId) {
|
||||
QueuedOperation storage operation = queuedOperations[operationId];
|
||||
|
||||
operation.cancelled = true;
|
||||
cancelledOperations++;
|
||||
|
||||
emit OperationCancelled(operationId, msg.sender, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Экстренное исполнение без задержки (только для критических ситуаций)
|
||||
* @param operationId ID операции
|
||||
* @param reason Причина экстренного исполнения
|
||||
*/
|
||||
function emergencyExecute(
|
||||
bytes32 operationId,
|
||||
string memory reason
|
||||
) external onlyDLE nonReentrant validOperation(operationId) {
|
||||
QueuedOperation storage operation = queuedOperations[operationId];
|
||||
|
||||
// Проверяем что операция помечена как экстренная
|
||||
bytes memory opData = operation.data;
|
||||
bytes4 selector;
|
||||
assembly {
|
||||
selector := mload(add(opData, 0x20))
|
||||
}
|
||||
require(emergencyOperations[selector], "Not emergency operation");
|
||||
|
||||
operation.executed = true;
|
||||
executedOperations++;
|
||||
|
||||
// Исполняем операцию
|
||||
(bool success, bytes memory result) = operation.target.call(operation.data);
|
||||
require(success, string(abi.encodePacked("Emergency execution failed: ", result)));
|
||||
|
||||
emit OperationExecuted(operationId, msg.sender);
|
||||
emit EmergencyExecution(operationId, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить задержку для типа операции (только через governance)
|
||||
* @param selector Селектор функции
|
||||
* @param newDelay Новая задержка
|
||||
* @param isCritical Является ли операция критической
|
||||
* @param isEmergency Может ли исполняться экстренно
|
||||
*/
|
||||
function updateOperationDelay(
|
||||
bytes4 selector,
|
||||
uint256 newDelay,
|
||||
bool isCritical,
|
||||
bool isEmergency
|
||||
) external onlyDLE {
|
||||
require(newDelay >= minDelay, "Delay too short");
|
||||
require(newDelay <= maxDelay, "Delay too long");
|
||||
|
||||
uint256 oldDelay = operationDelays[selector];
|
||||
operationDelays[selector] = newDelay;
|
||||
criticalOperations[selector] = isCritical;
|
||||
emergencyOperations[selector] = isEmergency;
|
||||
|
||||
emit DelayUpdated(selector, oldDelay, newDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить стандартную задержку (только через governance)
|
||||
* @param newDelay Новая стандартная задержка
|
||||
*/
|
||||
function updateDefaultDelay(uint256 newDelay) external onlyDLE {
|
||||
require(newDelay >= minDelay, "Delay too short");
|
||||
require(newDelay <= maxDelay, "Delay too long");
|
||||
|
||||
uint256 oldDelay = defaultDelay;
|
||||
defaultDelay = newDelay;
|
||||
|
||||
emit DefaultDelayUpdated(oldDelay, newDelay);
|
||||
}
|
||||
|
||||
// ===== VIEW ФУНКЦИИ =====
|
||||
|
||||
/**
|
||||
* @dev Получить информацию об операции
|
||||
*/
|
||||
function getOperation(bytes32 operationId) external view returns (QueuedOperation memory) {
|
||||
return queuedOperations[operationId];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Проверить, готова ли операция к исполнению
|
||||
*/
|
||||
function isReady(bytes32 operationId) external view returns (bool) {
|
||||
QueuedOperation storage operation = queuedOperations[operationId];
|
||||
return operation.id != bytes32(0) &&
|
||||
!operation.executed &&
|
||||
!operation.cancelled &&
|
||||
block.timestamp >= operation.executeAfter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить время до исполнения операции
|
||||
*/
|
||||
function getTimeToExecution(bytes32 operationId) external view returns (uint256) {
|
||||
QueuedOperation storage operation = queuedOperations[operationId];
|
||||
if (operation.executeAfter <= block.timestamp) {
|
||||
return 0;
|
||||
}
|
||||
return operation.executeAfter - block.timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить список активных операций
|
||||
*/
|
||||
function getActiveOperations() external view returns (bytes32[] memory) {
|
||||
uint256 activeCount = 0;
|
||||
|
||||
// Считаем активные операции
|
||||
for (uint256 i = 0; i < operationQueue.length; i++) {
|
||||
QueuedOperation storage op = queuedOperations[operationQueue[i]];
|
||||
if (!op.executed && !op.cancelled) {
|
||||
activeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Заполняем массив
|
||||
bytes32[] memory activeOps = new bytes32[](activeCount);
|
||||
uint256 index = 0;
|
||||
|
||||
for (uint256 i = 0; i < operationQueue.length; i++) {
|
||||
QueuedOperation storage op = queuedOperations[operationQueue[i]];
|
||||
if (!op.executed && !op.cancelled) {
|
||||
activeOps[index] = operationQueue[i];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return activeOps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить статистику Timelock
|
||||
*/
|
||||
function getTimelockStats() external view returns (
|
||||
uint256 total,
|
||||
uint256 executed,
|
||||
uint256 cancelled,
|
||||
uint256 pending,
|
||||
uint256 currentDelay
|
||||
) {
|
||||
return (
|
||||
totalOperations,
|
||||
executedOperations,
|
||||
cancelledOperations,
|
||||
totalOperations - executedOperations - cancelledOperations,
|
||||
defaultDelay
|
||||
);
|
||||
}
|
||||
|
||||
// ===== ВНУТРЕННИЕ ФУНКЦИИ =====
|
||||
|
||||
/**
|
||||
* @dev Определить задержку для операции
|
||||
*/
|
||||
function _getOperationDelay(bytes4 selector) internal view returns (uint256) {
|
||||
uint256 customDelay = operationDelays[selector];
|
||||
if (customDelay > 0) {
|
||||
return customDelay;
|
||||
}
|
||||
|
||||
// Используем стандартную задержку
|
||||
return defaultDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Настроить стандартные задержки для операций
|
||||
*/
|
||||
function _setupOperationDelays() internal {
|
||||
// Критические операции - длинная задержка (7 дней)
|
||||
bytes4 updateQuorum = bytes4(keccak256("updateQuorumPercentage(uint256)"));
|
||||
bytes4 addModule = bytes4(keccak256("_addModule(bytes32,address)"));
|
||||
bytes4 removeModule = bytes4(keccak256("_removeModule(bytes32)"));
|
||||
bytes4 addChain = bytes4(keccak256("_addSupportedChain(uint256)"));
|
||||
bytes4 removeChain = bytes4(keccak256("_removeSupportedChain(uint256)"));
|
||||
|
||||
operationDelays[updateQuorum] = 7 days;
|
||||
operationDelays[addModule] = 7 days;
|
||||
operationDelays[removeModule] = 7 days;
|
||||
operationDelays[addChain] = 5 days;
|
||||
operationDelays[removeChain] = 5 days;
|
||||
|
||||
criticalOperations[updateQuorum] = true;
|
||||
criticalOperations[addModule] = true;
|
||||
criticalOperations[removeModule] = true;
|
||||
criticalOperations[addChain] = true;
|
||||
criticalOperations[removeChain] = true;
|
||||
|
||||
// Обычные операции - стандартная задержка (2 дня)
|
||||
bytes4 updateDLEInfo = bytes4(keccak256("updateDLEInfo(string,string,string,string,uint256,string[],uint256)"));
|
||||
bytes4 updateChainId = bytes4(keccak256("updateCurrentChainId(uint256)"));
|
||||
bytes4 updateVotingDurations = bytes4(keccak256("_updateVotingDurations(uint256,uint256)"));
|
||||
|
||||
operationDelays[updateDLEInfo] = 2 days;
|
||||
operationDelays[updateChainId] = 3 days;
|
||||
operationDelays[updateVotingDurations] = 1 days;
|
||||
|
||||
// Treasury операции - короткая задержка (1 день)
|
||||
bytes4 treasuryTransfer = bytes4(keccak256("treasuryTransfer(address,address,uint256)"));
|
||||
bytes4 treasuryAddToken = bytes4(keccak256("treasuryAddToken(address,string,uint8)"));
|
||||
|
||||
operationDelays[treasuryTransfer] = 1 days;
|
||||
operationDelays[treasuryAddToken] = 1 days;
|
||||
|
||||
// Экстренные операции (могут исполняться немедленно при необходимости)
|
||||
emergencyOperations[removeModule] = true; // Удаление вредоносного модуля
|
||||
emergencyOperations[removeChain] = true; // Отключение скомпрометированной сети
|
||||
}
|
||||
}
|
||||
527
backend/contracts/TreasuryModule.sol
Normal file
527
backend/contracts/TreasuryModule.sol
Normal file
@@ -0,0 +1,527 @@
|
||||
// SPDX-License-Identifier: PROPRIETARY AND MIT
|
||||
// Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
// All rights reserved.
|
||||
//
|
||||
// This software is proprietary and confidential.
|
||||
// Unauthorized copying, modification, or distribution is prohibited.
|
||||
//
|
||||
// For licensing inquiries: info@hb3-accelerator.com
|
||||
// Website: https://hb3-accelerator.com
|
||||
// GitHub: https://github.com/HB3-ACCELERATOR
|
||||
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/Address.sol";
|
||||
|
||||
/**
|
||||
* @title TreasuryModule
|
||||
* @dev Модуль казны для управления активами DLE
|
||||
*
|
||||
* ОСНОВНЫЕ ФУНКЦИИ:
|
||||
* - Управление различными ERC20 токенами
|
||||
* - Хранение и перевод нативных монет (ETH, BNB, MATIC и т.д.)
|
||||
* - Интеграция с DLE governance для авторизации операций
|
||||
* - Поддержка мульти-чейн операций
|
||||
* - Batch операции для оптимизации газа
|
||||
*
|
||||
* БЕЗОПАСНОСТЬ:
|
||||
* - Только DLE контракт может выполнять операции
|
||||
* - Защита от реентерабельности
|
||||
* - Валидация всех входных параметров
|
||||
* - Поддержка emergency pause
|
||||
*/
|
||||
contract TreasuryModule is ReentrancyGuard {
|
||||
using SafeERC20 for IERC20;
|
||||
using Address for address payable;
|
||||
|
||||
// Структура для информации о токене
|
||||
struct TokenInfo {
|
||||
address tokenAddress; // Адрес токена (0x0 для нативной монеты)
|
||||
string symbol; // Символ токена
|
||||
uint8 decimals; // Количество знаков после запятой
|
||||
bool isActive; // Активен ли токен
|
||||
bool isNative; // Является ли нативной монетой
|
||||
uint256 addedTimestamp; // Время добавления
|
||||
uint256 balance; // Кэшированный баланс (обновляется при операциях)
|
||||
}
|
||||
|
||||
// Структура для batch операции
|
||||
struct BatchTransfer {
|
||||
address tokenAddress; // Адрес токена (0x0 для нативной монеты)
|
||||
address recipient; // Получатель
|
||||
uint256 amount; // Количество
|
||||
}
|
||||
|
||||
// Основные переменные
|
||||
address public immutable dleContract; // Адрес основного DLE контракта
|
||||
uint256 public immutable chainId; // ID текущей сети
|
||||
|
||||
// Хранение токенов
|
||||
mapping(address => TokenInfo) public supportedTokens; // tokenAddress => TokenInfo
|
||||
address[] public tokenList; // Список всех добавленных токенов
|
||||
mapping(address => uint256) public tokenIndex; // tokenAddress => index в tokenList
|
||||
|
||||
// Статистика
|
||||
uint256 public totalTokensSupported;
|
||||
uint256 public totalTransactions;
|
||||
mapping(address => uint256) public tokenTransactionCount; // tokenAddress => count
|
||||
|
||||
// Система экстренного останова
|
||||
bool public emergencyPaused;
|
||||
address public emergencyAdmin;
|
||||
|
||||
// События
|
||||
event TokenAdded(
|
||||
address indexed tokenAddress,
|
||||
string symbol,
|
||||
uint8 decimals,
|
||||
bool isNative,
|
||||
uint256 timestamp
|
||||
);
|
||||
event TokenRemoved(address indexed tokenAddress, string symbol, uint256 timestamp);
|
||||
event TokenStatusUpdated(address indexed tokenAddress, bool newStatus);
|
||||
event FundsDeposited(
|
||||
address indexed tokenAddress,
|
||||
address indexed from,
|
||||
uint256 amount,
|
||||
uint256 newBalance
|
||||
);
|
||||
event FundsTransferred(
|
||||
address indexed tokenAddress,
|
||||
address indexed to,
|
||||
uint256 amount,
|
||||
uint256 remainingBalance,
|
||||
bytes32 indexed proposalId
|
||||
);
|
||||
event BatchTransferExecuted(
|
||||
uint256 transferCount,
|
||||
uint256 totalAmount,
|
||||
bytes32 indexed proposalId
|
||||
);
|
||||
event EmergencyPauseToggled(bool isPaused, address admin);
|
||||
event BalanceUpdated(address indexed tokenAddress, uint256 oldBalance, uint256 newBalance);
|
||||
|
||||
// Модификаторы
|
||||
modifier onlyDLE() {
|
||||
require(msg.sender == dleContract, "Only DLE contract can call this");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier whenNotPaused() {
|
||||
require(!emergencyPaused, "Treasury is paused");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier onlyEmergencyAdmin() {
|
||||
require(msg.sender == emergencyAdmin, "Only emergency admin");
|
||||
_;
|
||||
}
|
||||
|
||||
modifier validToken(address tokenAddress) {
|
||||
require(supportedTokens[tokenAddress].isActive, "Token not supported or inactive");
|
||||
_;
|
||||
}
|
||||
|
||||
constructor(address _dleContract, uint256 _chainId, address _emergencyAdmin) {
|
||||
require(_dleContract != address(0), "DLE contract cannot be zero");
|
||||
require(_emergencyAdmin != address(0), "Emergency admin cannot be zero");
|
||||
require(_chainId > 0, "Chain ID must be positive");
|
||||
|
||||
dleContract = _dleContract;
|
||||
chainId = _chainId;
|
||||
emergencyAdmin = _emergencyAdmin;
|
||||
|
||||
// Автоматически добавляем нативную монету сети
|
||||
_addNativeToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить средства (может вызывать кто угодно для пополнения казны)
|
||||
*/
|
||||
receive() external payable {
|
||||
if (msg.value > 0) {
|
||||
_updateTokenBalance(address(0), supportedTokens[address(0)].balance + msg.value);
|
||||
emit FundsDeposited(address(0), msg.sender, msg.value, supportedTokens[address(0)].balance);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Добавить новый токен в казну (только через DLE governance)
|
||||
* @param tokenAddress Адрес токена (0x0 для нативной монеты)
|
||||
* @param symbol Символ токена
|
||||
* @param decimals Количество знаков после запятой
|
||||
*/
|
||||
function addToken(
|
||||
address tokenAddress,
|
||||
string memory symbol,
|
||||
uint8 decimals
|
||||
) external onlyDLE whenNotPaused {
|
||||
require(!supportedTokens[tokenAddress].isActive, "Token already supported");
|
||||
require(bytes(symbol).length > 0, "Symbol cannot be empty");
|
||||
require(bytes(symbol).length <= 20, "Symbol too long");
|
||||
|
||||
// Для ERC20 токенов проверяем, что контракт существует
|
||||
if (tokenAddress != address(0)) {
|
||||
require(tokenAddress.code.length > 0, "Token contract does not exist");
|
||||
|
||||
// Проверяем базовые ERC20 функции
|
||||
try IERC20(tokenAddress).totalSupply() returns (uint256) {
|
||||
// Token contract is valid
|
||||
} catch {
|
||||
revert("Invalid ERC20 token");
|
||||
}
|
||||
}
|
||||
|
||||
// Добавляем токен
|
||||
supportedTokens[tokenAddress] = TokenInfo({
|
||||
tokenAddress: tokenAddress,
|
||||
symbol: symbol,
|
||||
decimals: decimals,
|
||||
isActive: true,
|
||||
isNative: tokenAddress == address(0),
|
||||
addedTimestamp: block.timestamp,
|
||||
balance: 0
|
||||
});
|
||||
|
||||
tokenList.push(tokenAddress);
|
||||
tokenIndex[tokenAddress] = tokenList.length - 1;
|
||||
totalTokensSupported++;
|
||||
|
||||
// Обновляем баланс
|
||||
_refreshTokenBalance(tokenAddress);
|
||||
|
||||
emit TokenAdded(tokenAddress, symbol, decimals, tokenAddress == address(0), block.timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Удалить токен из казны (только через DLE governance)
|
||||
* @param tokenAddress Адрес токена для удаления
|
||||
*/
|
||||
function removeToken(address tokenAddress) external onlyDLE whenNotPaused validToken(tokenAddress) {
|
||||
require(tokenAddress != address(0), "Cannot remove native token");
|
||||
|
||||
TokenInfo memory tokenInfo = supportedTokens[tokenAddress];
|
||||
require(tokenInfo.balance == 0, "Token balance must be zero before removal");
|
||||
|
||||
// Удаляем из массива
|
||||
uint256 index = tokenIndex[tokenAddress];
|
||||
uint256 lastIndex = tokenList.length - 1;
|
||||
|
||||
if (index != lastIndex) {
|
||||
address lastToken = tokenList[lastIndex];
|
||||
tokenList[index] = lastToken;
|
||||
tokenIndex[lastToken] = index;
|
||||
}
|
||||
|
||||
tokenList.pop();
|
||||
delete tokenIndex[tokenAddress];
|
||||
delete supportedTokens[tokenAddress];
|
||||
totalTokensSupported--;
|
||||
|
||||
emit TokenRemoved(tokenAddress, tokenInfo.symbol, block.timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Изменить статус токена (активен/неактивен)
|
||||
* @param tokenAddress Адрес токена
|
||||
* @param isActive Новый статус
|
||||
*/
|
||||
function setTokenStatus(address tokenAddress, bool isActive) external onlyDLE {
|
||||
require(supportedTokens[tokenAddress].tokenAddress == tokenAddress, "Token not found");
|
||||
require(tokenAddress != address(0), "Cannot deactivate native token");
|
||||
|
||||
supportedTokens[tokenAddress].isActive = isActive;
|
||||
emit TokenStatusUpdated(tokenAddress, isActive);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Перевести токены (только через DLE governance)
|
||||
* @param tokenAddress Адрес токена (0x0 для нативной монеты)
|
||||
* @param recipient Получатель
|
||||
* @param amount Количество для перевода
|
||||
* @param proposalId ID предложения DLE (для логирования)
|
||||
*/
|
||||
function transferFunds(
|
||||
address tokenAddress,
|
||||
address recipient,
|
||||
uint256 amount,
|
||||
bytes32 proposalId
|
||||
) external onlyDLE whenNotPaused validToken(tokenAddress) nonReentrant {
|
||||
require(recipient != address(0), "Recipient cannot be zero");
|
||||
require(amount > 0, "Amount must be positive");
|
||||
|
||||
TokenInfo storage tokenInfo = supportedTokens[tokenAddress];
|
||||
require(tokenInfo.balance >= amount, "Insufficient balance");
|
||||
|
||||
// Обновляем баланс
|
||||
_updateTokenBalance(tokenAddress, tokenInfo.balance - amount);
|
||||
|
||||
// Выполняем перевод
|
||||
if (tokenInfo.isNative) {
|
||||
payable(recipient).sendValue(amount);
|
||||
} else {
|
||||
IERC20(tokenAddress).safeTransfer(recipient, amount);
|
||||
}
|
||||
|
||||
totalTransactions++;
|
||||
tokenTransactionCount[tokenAddress]++;
|
||||
|
||||
emit FundsTransferred(
|
||||
tokenAddress,
|
||||
recipient,
|
||||
amount,
|
||||
tokenInfo.balance,
|
||||
proposalId
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Выполнить batch перевод (только через DLE governance)
|
||||
* @param transfers Массив переводов
|
||||
* @param proposalId ID предложения DLE
|
||||
*/
|
||||
function batchTransfer(
|
||||
BatchTransfer[] memory transfers,
|
||||
bytes32 proposalId
|
||||
) external onlyDLE whenNotPaused nonReentrant {
|
||||
require(transfers.length > 0, "No transfers provided");
|
||||
require(transfers.length <= 100, "Too many transfers"); // Защита от DoS
|
||||
|
||||
uint256 totalAmount = 0;
|
||||
|
||||
for (uint256 i = 0; i < transfers.length; i++) {
|
||||
BatchTransfer memory transfer = transfers[i];
|
||||
|
||||
require(transfer.recipient != address(0), "Recipient cannot be zero");
|
||||
require(transfer.amount > 0, "Amount must be positive");
|
||||
require(supportedTokens[transfer.tokenAddress].isActive, "Token not supported");
|
||||
|
||||
TokenInfo storage tokenInfo = supportedTokens[transfer.tokenAddress];
|
||||
require(tokenInfo.balance >= transfer.amount, "Insufficient balance");
|
||||
|
||||
// Обновляем баланс
|
||||
_updateTokenBalance(transfer.tokenAddress, tokenInfo.balance - transfer.amount);
|
||||
|
||||
// Выполняем перевод
|
||||
if (tokenInfo.isNative) {
|
||||
payable(transfer.recipient).sendValue(transfer.amount);
|
||||
} else {
|
||||
IERC20(transfer.tokenAddress).safeTransfer(transfer.recipient, transfer.amount);
|
||||
}
|
||||
|
||||
totalAmount += transfer.amount;
|
||||
tokenTransactionCount[transfer.tokenAddress]++;
|
||||
|
||||
emit FundsTransferred(
|
||||
transfer.tokenAddress,
|
||||
transfer.recipient,
|
||||
transfer.amount,
|
||||
tokenInfo.balance,
|
||||
proposalId
|
||||
);
|
||||
}
|
||||
|
||||
totalTransactions += transfers.length;
|
||||
emit BatchTransferExecuted(transfers.length, totalAmount, proposalId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Пополнить казну ERC20 токенами
|
||||
* @param tokenAddress Адрес токена
|
||||
* @param amount Количество для пополнения
|
||||
*/
|
||||
function depositToken(
|
||||
address tokenAddress,
|
||||
uint256 amount
|
||||
) external whenNotPaused validToken(tokenAddress) nonReentrant {
|
||||
require(amount > 0, "Amount must be positive");
|
||||
require(tokenAddress != address(0), "Use receive() for native deposits");
|
||||
|
||||
IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), amount);
|
||||
|
||||
_updateTokenBalance(tokenAddress, supportedTokens[tokenAddress].balance + amount);
|
||||
|
||||
emit FundsDeposited(tokenAddress, msg.sender, amount, supportedTokens[tokenAddress].balance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить баланс токена (синхронизация с реальным балансом)
|
||||
* @param tokenAddress Адрес токена
|
||||
*/
|
||||
function refreshBalance(address tokenAddress) external validToken(tokenAddress) {
|
||||
_refreshTokenBalance(tokenAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить балансы всех токенов
|
||||
*/
|
||||
function refreshAllBalances() external {
|
||||
for (uint256 i = 0; i < tokenList.length; i++) {
|
||||
if (supportedTokens[tokenList[i]].isActive) {
|
||||
_refreshTokenBalance(tokenList[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Экстренная пауза (только emergency admin)
|
||||
*/
|
||||
function emergencyPause() external onlyEmergencyAdmin {
|
||||
emergencyPaused = !emergencyPaused;
|
||||
emit EmergencyPauseToggled(emergencyPaused, msg.sender);
|
||||
}
|
||||
|
||||
// ===== VIEW ФУНКЦИИ =====
|
||||
|
||||
/**
|
||||
* @dev Получить информацию о токене
|
||||
*/
|
||||
function getTokenInfo(address tokenAddress) external view returns (TokenInfo memory) {
|
||||
return supportedTokens[tokenAddress];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить список всех токенов
|
||||
*/
|
||||
function getAllTokens() external view returns (address[] memory) {
|
||||
return tokenList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить активные токены
|
||||
*/
|
||||
function getActiveTokens() external view returns (address[] memory) {
|
||||
uint256 activeCount = 0;
|
||||
|
||||
// Считаем активные токены
|
||||
for (uint256 i = 0; i < tokenList.length; i++) {
|
||||
if (supportedTokens[tokenList[i]].isActive) {
|
||||
activeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// Создаём массив активных токенов
|
||||
address[] memory activeTokens = new address[](activeCount);
|
||||
uint256 index = 0;
|
||||
|
||||
for (uint256 i = 0; i < tokenList.length; i++) {
|
||||
if (supportedTokens[tokenList[i]].isActive) {
|
||||
activeTokens[index] = tokenList[i];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return activeTokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить баланс токена
|
||||
*/
|
||||
function getTokenBalance(address tokenAddress) external view returns (uint256) {
|
||||
return supportedTokens[tokenAddress].balance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить реальный баланс токена (обращение к блокчейну)
|
||||
*/
|
||||
function getRealTokenBalance(address tokenAddress) external view returns (uint256) {
|
||||
if (tokenAddress == address(0)) {
|
||||
return address(this).balance;
|
||||
} else {
|
||||
return IERC20(tokenAddress).balanceOf(address(this));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Проверить, поддерживается ли токен
|
||||
*/
|
||||
function isTokenSupported(address tokenAddress) external view returns (bool) {
|
||||
return supportedTokens[tokenAddress].isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Получить статистику казны
|
||||
*/
|
||||
function getTreasuryStats() external view returns (
|
||||
uint256 totalTokens,
|
||||
uint256 totalTxs,
|
||||
uint256 currentChainId,
|
||||
bool isPaused
|
||||
) {
|
||||
return (
|
||||
totalTokensSupported,
|
||||
totalTransactions,
|
||||
chainId,
|
||||
emergencyPaused
|
||||
);
|
||||
}
|
||||
|
||||
// ===== ВНУТРЕННИЕ ФУНКЦИИ =====
|
||||
|
||||
/**
|
||||
* @dev Автоматически добавить нативную монету
|
||||
*/
|
||||
function _addNativeToken() internal {
|
||||
string memory nativeSymbol;
|
||||
|
||||
// Определяем символ нативной монеты по chain ID
|
||||
if (chainId == 1 || chainId == 11155111) { // Ethereum Mainnet / Sepolia
|
||||
nativeSymbol = "ETH";
|
||||
} else if (chainId == 56 || chainId == 97) { // BSC Mainnet / Testnet
|
||||
nativeSymbol = "BNB";
|
||||
} else if (chainId == 137 || chainId == 80001) { // Polygon Mainnet / Mumbai
|
||||
nativeSymbol = "MATIC";
|
||||
} else if (chainId == 42161) { // Arbitrum One
|
||||
nativeSymbol = "ETH";
|
||||
} else if (chainId == 10) { // Optimism
|
||||
nativeSymbol = "ETH";
|
||||
} else if (chainId == 43114) { // Avalanche
|
||||
nativeSymbol = "AVAX";
|
||||
} else {
|
||||
nativeSymbol = "NATIVE"; // Для неизвестных сетей
|
||||
}
|
||||
|
||||
supportedTokens[address(0)] = TokenInfo({
|
||||
tokenAddress: address(0),
|
||||
symbol: nativeSymbol,
|
||||
decimals: 18,
|
||||
isActive: true,
|
||||
isNative: true,
|
||||
addedTimestamp: block.timestamp,
|
||||
balance: 0
|
||||
});
|
||||
|
||||
tokenList.push(address(0));
|
||||
tokenIndex[address(0)] = 0;
|
||||
totalTokensSupported = 1;
|
||||
|
||||
emit TokenAdded(address(0), nativeSymbol, 18, true, block.timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Обновить кэшированный баланс токена
|
||||
*/
|
||||
function _updateTokenBalance(address tokenAddress, uint256 newBalance) internal {
|
||||
uint256 oldBalance = supportedTokens[tokenAddress].balance;
|
||||
supportedTokens[tokenAddress].balance = newBalance;
|
||||
emit BalanceUpdated(tokenAddress, oldBalance, newBalance);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Синхронизировать кэшированный баланс с реальным
|
||||
*/
|
||||
function _refreshTokenBalance(address tokenAddress) internal {
|
||||
uint256 realBalance;
|
||||
|
||||
if (tokenAddress == address(0)) {
|
||||
realBalance = address(this).balance;
|
||||
} else {
|
||||
realBalance = IERC20(tokenAddress).balanceOf(address(this));
|
||||
}
|
||||
|
||||
_updateTokenBalance(tokenAddress, realBalance);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
require('@nomicfoundation/hardhat-toolbox');
|
||||
require('hardhat-contract-sizer');
|
||||
require('dotenv').config();
|
||||
|
||||
function getNetworks() {
|
||||
@@ -39,10 +40,25 @@ module.exports = {
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: true,
|
||||
runs: 200
|
||||
runs: 1 // Максимальная оптимизация размера для mainnet
|
||||
},
|
||||
viaIR: true
|
||||
}
|
||||
},
|
||||
contractSizer: {
|
||||
alphaSort: true,
|
||||
runOnCompile: true,
|
||||
disambiguatePaths: false,
|
||||
},
|
||||
networks: getNetworks(),
|
||||
solidityCoverage: {
|
||||
excludeContracts: [],
|
||||
skipFiles: [],
|
||||
// Исключаем строки с revert функциями из покрытия
|
||||
excludeLines: [
|
||||
'// coverage:ignore-line',
|
||||
'revert ErrTransfersDisabled();',
|
||||
'revert ErrApprovalsDisabled();'
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
{
|
||||
"verbose": true,
|
||||
"ignore": [".git", "node_modules/**/node_modules", "sessions", "data/vector_store", "logs"],
|
||||
"watch": ["*.js", "routes/**/*", "services/**/*", "utils/**/*", "middleware/**/*"],
|
||||
"env": {
|
||||
"NODE_ENV": "development"
|
||||
},
|
||||
"ext": "js,json,env"
|
||||
}
|
||||
"watch": [
|
||||
"backend/src",
|
||||
"backend/routes",
|
||||
"backend/services"
|
||||
],
|
||||
"ignore": [
|
||||
"backend/artifacts/**",
|
||||
"backend/cache/**",
|
||||
"backend/contracts-data/**",
|
||||
"backend/temp/**",
|
||||
"backend/scripts/deploy/current-params*.json"
|
||||
],
|
||||
"ext": "js,json"
|
||||
}
|
||||
@@ -20,7 +20,10 @@
|
||||
"format": "prettier --write \"**/*.{js,vue,json,md}\"",
|
||||
"format:check": "prettier --check \"**/*.{js,vue,json,md}\"",
|
||||
"run-migrations": "node scripts/run-migrations.js",
|
||||
"fix-duplicates": "node scripts/fix-duplicate-identities.js"
|
||||
"fix-duplicates": "node scripts/fix-duplicate-identities.js",
|
||||
"deploy:factory": "node scripts/deploy/deploy-factory.js",
|
||||
"deploy:multichain": "node scripts/deploy/deploy-multichain.js",
|
||||
"deploy:complete": "node scripts/deploy/deploy-dle-complete.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anthropic-ai/sdk": "^0.51.0",
|
||||
@@ -81,10 +84,11 @@
|
||||
"eslint-config-prettier": "^10.0.2",
|
||||
"globals": "^16.0.0",
|
||||
"hardhat": "^2.24.1",
|
||||
"hardhat-contract-sizer": "^2.10.1",
|
||||
"hardhat-gas-reporter": "^2.2.2",
|
||||
"nodemon": "^3.1.9",
|
||||
"prettier": "^3.5.3",
|
||||
"solidity-coverage": "^0.8.1",
|
||||
"solidity-coverage": "^0.8.16",
|
||||
"ts-node": ">=8.0.0",
|
||||
"typechain": "^8.3.0",
|
||||
"typescript": ">=4.5.0"
|
||||
|
||||
@@ -29,20 +29,38 @@ router.post('/read-dle-info', async (req, res) => {
|
||||
|
||||
console.log(`[Blockchain] Чтение данных DLE из блокчейна: ${dleAddress}`);
|
||||
|
||||
// Получаем RPC URL для Sepolia
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(11155111);
|
||||
if (!rpcUrl) {
|
||||
return res.status(500).json({
|
||||
success: false,
|
||||
error: 'RPC URL для Sepolia не найден'
|
||||
});
|
||||
// Определяем корректную сеть для данного адреса (или используем chainId из запроса)
|
||||
let provider, rpcUrl, targetChainId = req.body.chainId;
|
||||
const candidateChainIds = [11155111, 17000, 421614, 84532];
|
||||
if (targetChainId) {
|
||||
rpcUrl = await rpcProviderService.getRpcUrlByChainId(Number(targetChainId));
|
||||
if (!rpcUrl) {
|
||||
return res.status(500).json({ success: false, error: `RPC URL для сети ${targetChainId} не найден` });
|
||||
}
|
||||
provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const code = await provider.getCode(dleAddress);
|
||||
if (!code || code === '0x') {
|
||||
return res.status(400).json({ success: false, error: `По адресу ${dleAddress} нет контракта в сети ${targetChainId}` });
|
||||
}
|
||||
} else {
|
||||
for (const cid of candidateChainIds) {
|
||||
try {
|
||||
const url = await rpcProviderService.getRpcUrlByChainId(cid);
|
||||
if (!url) continue;
|
||||
const prov = new ethers.JsonRpcProvider(url);
|
||||
const code = await prov.getCode(dleAddress);
|
||||
if (code && code !== '0x') { provider = prov; rpcUrl = url; targetChainId = cid; break; }
|
||||
} catch (_) {}
|
||||
}
|
||||
if (!provider) {
|
||||
return res.status(400).json({ success: false, error: 'Не удалось найти сеть, где по адресу есть контракт' });
|
||||
}
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
|
||||
// ABI для чтения данных DLE
|
||||
const dleAbi = [
|
||||
"function getDLEInfo() external view returns (tuple(string name, string symbol, string location, string coordinates, uint256 jurisdiction, uint256 oktmo, string[] okvedCodes, uint256 kpp, uint256 creationTimestamp, bool isActive))",
|
||||
// Актуальная сигнатура без oktmo
|
||||
"function getDLEInfo() external view returns (tuple(string name, string symbol, string location, string coordinates, uint256 jurisdiction, string[] okvedCodes, uint256 kpp, uint256 creationTimestamp, bool isActive))",
|
||||
"function totalSupply() external view returns (uint256)",
|
||||
"function balanceOf(address account) external view returns (uint256)",
|
||||
"function quorumPercentage() external view returns (uint256)",
|
||||
@@ -81,7 +99,8 @@ router.post('/read-dle-info', async (req, res) => {
|
||||
location: dleInfo.location,
|
||||
coordinates: dleInfo.coordinates,
|
||||
jurisdiction: Number(dleInfo.jurisdiction),
|
||||
oktmo: Number(dleInfo.oktmo),
|
||||
// Поле oktmo удалено в актуальной версии контракта; сохраняем 0 для обратной совместимости
|
||||
oktmo: 0,
|
||||
okvedCodes: dleInfo.okvedCodes,
|
||||
kpp: Number(dleInfo.kpp),
|
||||
creationTimestamp: Number(dleInfo.creationTimestamp),
|
||||
@@ -90,6 +109,7 @@ router.post('/read-dle-info', async (req, res) => {
|
||||
deployerBalance: ethers.formatUnits(deployerBalance, 18),
|
||||
quorumPercentage: Number(quorumPercentage),
|
||||
currentChainId: Number(currentChainId),
|
||||
rpcUsed: rpcUrl,
|
||||
participantCount: participantCount
|
||||
};
|
||||
|
||||
@@ -153,6 +173,10 @@ router.post('/get-supported-chains', async (req, res) => {
|
||||
{ chainId: 43114, name: 'Avalanche', description: 'Avalanche C-Chain' },
|
||||
{ chainId: 250, name: 'Fantom', description: 'Fantom Opera' },
|
||||
{ chainId: 11155111, name: 'Sepolia', description: 'Ethereum Testnet Sepolia' },
|
||||
{ chainId: 17000, name: 'Holesky', description: 'Ethereum Testnet Holesky' },
|
||||
{ chainId: 80002, name: 'Polygon Amoy', description: 'Polygon Testnet Amoy' },
|
||||
{ chainId: 84532, name: 'Base Sepolia', description: 'Base Sepolia Testnet' },
|
||||
{ chainId: 421614, name: 'Arbitrum Sepolia', description: 'Arbitrum Sepolia Testnet' },
|
||||
{ chainId: 80001, name: 'Mumbai', description: 'Polygon Testnet Mumbai' },
|
||||
{ chainId: 97, name: 'BSC Testnet', description: 'Binance Smart Chain Testnet' },
|
||||
{ chainId: 421613, name: 'Arbitrum Goerli', description: 'Arbitrum Testnet Goerli' }
|
||||
|
||||
83
backend/routes/compile.js
Normal file
83
backend/routes/compile.js
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is proprietary and confidential.
|
||||
* Unauthorized copying, modification, or distribution is prohibited.
|
||||
*
|
||||
* For licensing inquiries: info@hb3-accelerator.com
|
||||
* Website: https://hb3-accelerator.com
|
||||
* GitHub: https://github.com/HB3-ACCELERATOR
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { spawn } = require('child_process');
|
||||
const path = require('path');
|
||||
const logger = require('../utils/logger');
|
||||
const auth = require('../middleware/auth');
|
||||
|
||||
/**
|
||||
* @route POST /api/compile-contracts
|
||||
* @desc Компилировать смарт-контракты через Hardhat
|
||||
* @access Private (только для авторизованных пользователей с ролью admin)
|
||||
*/
|
||||
router.post('/', auth.requireAuth, auth.requireAdmin, async (req, res) => {
|
||||
try {
|
||||
console.log('🔨 Запуск компиляции смарт-контрактов...');
|
||||
|
||||
const hardhatProcess = spawn('npx', ['hardhat', 'compile'], {
|
||||
cwd: path.join(__dirname, '..'),
|
||||
stdio: 'pipe'
|
||||
});
|
||||
|
||||
let stdout = '';
|
||||
let stderr = '';
|
||||
|
||||
hardhatProcess.stdout.on('data', (data) => {
|
||||
stdout += data.toString();
|
||||
console.log(`[COMPILE] ${data.toString().trim()}`);
|
||||
});
|
||||
|
||||
hardhatProcess.stderr.on('data', (data) => {
|
||||
stderr += data.toString();
|
||||
console.error(`[COMPILE_ERR] ${data.toString().trim()}`);
|
||||
});
|
||||
|
||||
hardhatProcess.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
console.log('✅ Компиляция завершена успешно');
|
||||
res.json({
|
||||
success: true,
|
||||
message: 'Смарт-контракты скомпилированы успешно',
|
||||
data: { stdout, stderr }
|
||||
});
|
||||
} else {
|
||||
console.error('❌ Ошибка компиляции:', stderr);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Ошибка компиляции смарт-контрактов',
|
||||
error: stderr
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
hardhatProcess.on('error', (error) => {
|
||||
console.error('❌ Ошибка запуска компиляции:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: 'Ошибка запуска компиляции',
|
||||
error: error.message
|
||||
});
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Ошибка компиляции контрактов:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message || 'Произошла ошибка при компиляции контрактов'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
@@ -357,14 +357,12 @@ router.post('/predict-addresses', auth.requireAuth, auth.requireAdmin, async (re
|
||||
}
|
||||
|
||||
// Используем служебные секреты для фабрики и SALT
|
||||
// Ожидаем, что на сервере настроены переменные окружения или конфиги на сеть
|
||||
// Factory больше не используется - адреса DLE теперь вычисляются через CREATE с выровненным nonce
|
||||
const result = {};
|
||||
for (const chainId of selectedNetworks) {
|
||||
const factory = process.env[`FACTORY_ADDRESS_${chainId}`] || process.env.FACTORY_ADDRESS;
|
||||
const saltHex = process.env[`CREATE2_SALT_${chainId}`] || process.env.CREATE2_SALT;
|
||||
const initCodeHash = process.env[`INIT_CODE_HASH_${chainId}`] || process.env.INIT_CODE_HASH;
|
||||
if (!factory || !saltHex || !initCodeHash) continue;
|
||||
result[chainId] = create2.computeCreate2Address(factory, saltHex, initCodeHash);
|
||||
// Адрес DLE будет одинаковым во всех сетях благодаря выравниванию nonce
|
||||
// Вычисляется в deploy-multichain.js во время деплоя
|
||||
result[chainId] = 'Вычисляется во время деплоя';
|
||||
}
|
||||
|
||||
return res.json({ success: true, data: result });
|
||||
@@ -513,4 +511,5 @@ router.post('/precheck', auth.requireAuth, auth.requireAdmin, async (req, res) =
|
||||
} catch (e) {
|
||||
return res.status(500).json({ success: false, message: e.message });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
30
backend/routes/ens.js
Normal file
30
backend/routes/ens.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* ENS utilities: resolve avatar URL for a given ENS name
|
||||
*/
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const { ethers } = require('ethers');
|
||||
|
||||
function getMainnetProvider() {
|
||||
const url = process.env.MAINNET_RPC_URL || process.env.ETH_MAINNET_RPC || 'https://ethereum.publicnode.com';
|
||||
return new ethers.JsonRpcProvider(url);
|
||||
}
|
||||
|
||||
// GET /api/ens/avatar?name=vc-hb3-accelerator.eth
|
||||
router.get('/avatar', async (req, res) => {
|
||||
try {
|
||||
const name = String(req.query.name || '').trim();
|
||||
if (!name || !name.endsWith('.eth')) {
|
||||
return res.status(400).json({ success: false, message: 'ENS name is required (e.g., example.eth)' });
|
||||
}
|
||||
const provider = getMainnetProvider();
|
||||
const url = await provider.getAvatar(name);
|
||||
return res.json({ success: true, data: { url: url || null } });
|
||||
} catch (e) {
|
||||
return res.status(500).json({ success: false, message: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
|
||||
51
backend/routes/uploads.js
Normal file
51
backend/routes/uploads.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Загрузка файлов (логотипы) через Multer
|
||||
*/
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const multer = require('multer');
|
||||
const auth = require('../middleware/auth');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
// Хранилище на диске: uploads/logos
|
||||
const storage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const dir = path.join(__dirname, '..', 'uploads', 'logos');
|
||||
try { fs.mkdirSync(dir, { recursive: true }); } catch (_) {}
|
||||
cb(null, dir);
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
const ext = (file.originalname || '').split('.').pop();
|
||||
const safeExt = ext && ext.length <= 10 ? ext : 'png';
|
||||
const name = `logo_${Date.now()}_${Math.random().toString(36).slice(2, 8)}.${safeExt}`;
|
||||
cb(null, name);
|
||||
}
|
||||
});
|
||||
|
||||
const upload = multer({
|
||||
storage,
|
||||
limits: { fileSize: 5 * 1024 * 1024 },
|
||||
fileFilter: (req, file, cb) => {
|
||||
const ok = /(png|jpg|jpeg|gif|webp)$/i.test(file.originalname || '') && /^image\//i.test(file.mimetype || '');
|
||||
if (!ok) return cb(new Error('Only image files are allowed'));
|
||||
cb(null, true);
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/uploads/logo (form field: logo)
|
||||
router.post('/logo', auth.requireAuth, auth.requireAdmin, upload.single('logo'), async (req, res) => {
|
||||
try {
|
||||
if (!req.file) return res.status(400).json({ success: false, message: 'Файл не получен' });
|
||||
const rel = path.posix.join('uploads', 'logos', path.basename(req.file.filename));
|
||||
const urlPath = `/uploads/logos/${path.basename(req.file.filename)}`;
|
||||
return res.json({ success: true, data: { path: rel, url: urlPath } });
|
||||
} catch (e) {
|
||||
return res.status(500).json({ success: false, message: e.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
|
||||
@@ -1,299 +0,0 @@
|
||||
/* eslint-disable no-console */
|
||||
const hre = require('hardhat');
|
||||
|
||||
async function main() {
|
||||
const { ethers } = hre;
|
||||
const rpcUrl = process.env.RPC_URL;
|
||||
const pk = process.env.PRIVATE_KEY;
|
||||
if (!rpcUrl || !pk) throw new Error('RPC_URL/PRIVATE_KEY required');
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const wallet = new ethers.Wallet(pk, provider);
|
||||
|
||||
const salt = process.env.CREATE2_SALT;
|
||||
const initCodeHash = process.env.INIT_CODE_HASH;
|
||||
let factoryAddress = process.env.FACTORY_ADDRESS;
|
||||
|
||||
if (!salt || !initCodeHash) throw new Error('CREATE2_SALT/INIT_CODE_HASH required');
|
||||
|
||||
// Ensure factory
|
||||
if (!factoryAddress) {
|
||||
const Factory = await hre.ethers.getContractFactory('FactoryDeployer', wallet);
|
||||
const factory = await Factory.deploy();
|
||||
await factory.waitForDeployment();
|
||||
factoryAddress = await factory.getAddress();
|
||||
} else {
|
||||
const code = await provider.getCode(factoryAddress);
|
||||
if (code === '0x') {
|
||||
const Factory = await hre.ethers.getContractFactory('FactoryDeployer', wallet);
|
||||
const factory = await Factory.deploy();
|
||||
await factory.waitForDeployment();
|
||||
factoryAddress = await factory.getAddress();
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare DLE init code = creation bytecode WITH constructor args
|
||||
const DLE = await hre.ethers.getContractFactory('DLE', wallet);
|
||||
const paramsPath = require('path').join(__dirname, './current-params.json');
|
||||
const params = require(paramsPath);
|
||||
const dleConfig = {
|
||||
name: params.name,
|
||||
symbol: params.symbol,
|
||||
location: params.location,
|
||||
coordinates: params.coordinates,
|
||||
jurisdiction: params.jurisdiction,
|
||||
okvedCodes: params.okvedCodes || [],
|
||||
kpp: params.kpp,
|
||||
quorumPercentage: params.quorumPercentage,
|
||||
initialPartners: params.initialPartners,
|
||||
initialAmounts: params.initialAmounts,
|
||||
supportedChainIds: params.supportedChainIds
|
||||
};
|
||||
const deployTx = await DLE.getDeployTransaction(dleConfig, params.currentChainId);
|
||||
const dleInit = deployTx.data; // полноценный init code
|
||||
|
||||
// Deploy via factory
|
||||
const Factory = await hre.ethers.getContractAt('FactoryDeployer', factoryAddress, wallet);
|
||||
const tx = await Factory.deploy(salt, dleInit);
|
||||
const rc = await tx.wait();
|
||||
const addr = rc.logs?.[0]?.args?.addr || (await Factory.computeAddress(salt, initCodeHash));
|
||||
console.log('DLE v2 задеплоен по адресу:', addr);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024-2025 Тарабанов Александр Викторович
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is proprietary and confidential.
|
||||
* Unauthorized copying, modification, or distribution is prohibited.
|
||||
*
|
||||
* For licensing inquiries: info@hb3-accelerator.com
|
||||
* Website: https://hb3-accelerator.com
|
||||
* GitHub: https://github.com/HB3-ACCELERATOR
|
||||
*/
|
||||
|
||||
// Скрипт для создания современного DLE v2 (единый контракт)
|
||||
const { ethers } = require("hardhat");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
async function main() {
|
||||
// Получаем параметры деплоя из файла
|
||||
const deployParams = getDeployParams();
|
||||
|
||||
console.log("Начинаем создание современного DLE v2...");
|
||||
console.log("Параметры DLE:");
|
||||
console.log(JSON.stringify(deployParams, null, 2));
|
||||
|
||||
// Преобразуем initialAmounts в wei
|
||||
const initialAmountsInWei = deployParams.initialAmounts.map(amount => ethers.parseUnits(amount.toString(), 18));
|
||||
console.log("Initial amounts в wei:");
|
||||
console.log(initialAmountsInWei.map(wei => ethers.formatUnits(wei, 18) + " токенов"));
|
||||
|
||||
// Получаем RPC URL и приватный ключ из переменных окружения
|
||||
const rpcUrl = process.env.RPC_URL;
|
||||
const privateKey = process.env.PRIVATE_KEY;
|
||||
|
||||
if (!rpcUrl || !privateKey) {
|
||||
throw new Error('RPC_URL и PRIVATE_KEY должны быть установлены в переменных окружения');
|
||||
}
|
||||
|
||||
// Создаем провайдер и кошелек
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const deployer = new ethers.Wallet(privateKey, provider);
|
||||
|
||||
console.log(`Адрес деплоера: ${deployer.address}`);
|
||||
const balance = await provider.getBalance(deployer.address);
|
||||
console.log(`Баланс деплоера: ${ethers.formatEther(balance)} ETH`);
|
||||
|
||||
// Проверяем, достаточно ли баланса для деплоя (минимум 0.00001 ETH для тестирования)
|
||||
const minBalance = ethers.parseEther("0.00001");
|
||||
if (balance < minBalance) {
|
||||
throw new Error(`Недостаточно ETH для деплоя. Баланс: ${ethers.formatEther(balance)} ETH, требуется минимум: ${ethers.formatEther(minBalance)} ETH. Пополните кошелек через Sepolia faucet.`);
|
||||
}
|
||||
|
||||
try {
|
||||
// 1. Создаем единый контракт DLE
|
||||
console.log("\n1. Деплой единого контракта DLE v2...");
|
||||
|
||||
const DLE = await ethers.getContractFactory("DLE", deployer);
|
||||
|
||||
// Создаем структуру DLEConfig с полными данными
|
||||
const dleConfig = {
|
||||
name: deployParams.name,
|
||||
symbol: deployParams.symbol,
|
||||
location: deployParams.location,
|
||||
coordinates: deployParams.coordinates || "0,0",
|
||||
jurisdiction: deployParams.jurisdiction || 1,
|
||||
oktmo: parseInt(deployParams.oktmo) || 45000000000,
|
||||
okvedCodes: deployParams.okvedCodes || [],
|
||||
kpp: parseInt(deployParams.kpp) || 770101001,
|
||||
quorumPercentage: deployParams.quorumPercentage || 51,
|
||||
initialPartners: deployParams.initialPartners,
|
||||
initialAmounts: deployParams.initialAmounts.map(amount => ethers.parseUnits(amount.toString(), 18)),
|
||||
supportedChainIds: deployParams.supportedChainIds || [1, 137, 56, 42161] // Ethereum, Polygon, BSC, Arbitrum
|
||||
};
|
||||
|
||||
console.log("Конфигурация DLE для записи в блокчейн:");
|
||||
console.log("Название:", dleConfig.name);
|
||||
console.log("Символ:", dleConfig.symbol);
|
||||
console.log("Местонахождение:", dleConfig.location);
|
||||
console.log("Координаты:", dleConfig.coordinates);
|
||||
console.log("Юрисдикция:", dleConfig.jurisdiction);
|
||||
console.log("ОКТМО:", dleConfig.oktmo);
|
||||
console.log("Коды ОКВЭД:", dleConfig.okvedCodes.join(', '));
|
||||
console.log("КПП:", dleConfig.kpp);
|
||||
console.log("Кворум:", dleConfig.quorumPercentage + "%");
|
||||
console.log("Партнеры:", dleConfig.initialPartners.join(', '));
|
||||
console.log("Количества токенов:", dleConfig.initialAmounts.map(amount => ethers.formatUnits(amount, 18) + " токенов").join(', '));
|
||||
console.log("Поддерживаемые сети:", dleConfig.supportedChainIds.join(', '));
|
||||
|
||||
const currentChainId = deployParams.currentChainId || 1; // По умолчанию Ethereum
|
||||
|
||||
const dle = await DLE.deploy(dleConfig, currentChainId);
|
||||
|
||||
await dle.waitForDeployment();
|
||||
const dleAddress = await dle.getAddress();
|
||||
console.log(`DLE v2 задеплоен по адресу: ${dleAddress}`);
|
||||
|
||||
// 2. Получаем информацию о DLE из блокчейна
|
||||
const dleInfo = await dle.getDLEInfo();
|
||||
console.log("\n2. Информация о DLE из блокчейна:");
|
||||
console.log(`Название: ${dleInfo.name}`);
|
||||
console.log(`Символ: ${dleInfo.symbol}`);
|
||||
console.log(`Местонахождение: ${dleInfo.location}`);
|
||||
console.log(`Координаты: ${dleInfo.coordinates}`);
|
||||
console.log(`Юрисдикция: ${dleInfo.jurisdiction}`);
|
||||
console.log(`ОКТМО: ${dleInfo.oktmo}`);
|
||||
console.log(`Коды ОКВЭД: ${dleInfo.okvedCodes.join(', ')}`);
|
||||
console.log(`КПП: ${dleInfo.kpp}`);
|
||||
console.log(`Дата создания: ${new Date(Number(dleInfo.creationTimestamp) * 1000).toISOString()}`);
|
||||
console.log(`Активен: ${dleInfo.isActive}`);
|
||||
|
||||
// Проверяем, что данные записались правильно
|
||||
console.log("\n3. Проверка записи данных в блокчейн:");
|
||||
if (dleInfo.name === deployParams.name &&
|
||||
dleInfo.location === deployParams.location &&
|
||||
dleInfo.jurisdiction === deployParams.jurisdiction) {
|
||||
console.log("✅ Все данные DLE успешно записаны в блокчейн!");
|
||||
console.log("Теперь эти данные видны на Etherscan в разделе 'Contract' -> 'Read Contract'");
|
||||
} else {
|
||||
console.log("❌ Ошибка: данные не записались правильно в блокчейн");
|
||||
}
|
||||
|
||||
// 4. Сохраняем информацию о созданном DLE
|
||||
console.log("\n4. Сохранение информации о DLE v2...");
|
||||
const dleData = {
|
||||
name: deployParams.name,
|
||||
symbol: deployParams.symbol,
|
||||
location: deployParams.location,
|
||||
coordinates: deployParams.coordinates || "0,0",
|
||||
jurisdiction: deployParams.jurisdiction || 1,
|
||||
oktmo: deployParams.oktmo || 45000000000,
|
||||
okvedCodes: deployParams.okvedCodes || [],
|
||||
kpp: deployParams.kpp || 770101001,
|
||||
dleAddress: dleAddress,
|
||||
creationBlock: Number(await provider.getBlockNumber()),
|
||||
creationTimestamp: Number((await provider.getBlock()).timestamp),
|
||||
deployedManually: true,
|
||||
version: "v2",
|
||||
// Сохраняем информацию о партнерах
|
||||
initialPartners: deployParams.initialPartners || [],
|
||||
initialAmounts: deployParams.initialAmounts || [],
|
||||
governanceSettings: {
|
||||
quorumPercentage: deployParams.quorumPercentage || 51,
|
||||
supportedChainIds: deployParams.supportedChainIds || [1, 137, 56, 42161],
|
||||
currentChainId: currentChainId
|
||||
}
|
||||
};
|
||||
|
||||
const saveResult = saveDLEData(dleData);
|
||||
|
||||
console.log("\nDLE v2 успешно создан!");
|
||||
console.log(`Адрес DLE: ${dleAddress}`);
|
||||
console.log(`Версия: v2 (единый контракт)`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
dleAddress: dleAddress,
|
||||
data: dleData
|
||||
};
|
||||
|
||||
} catch (error) {
|
||||
console.error("Ошибка при создании DLE v2:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Получаем параметры деплоя из файла
|
||||
function getDeployParams() {
|
||||
const paramsFile = path.join(__dirname, 'current-params.json');
|
||||
|
||||
if (!fs.existsSync(paramsFile)) {
|
||||
console.error(`Файл параметров не найден: ${paramsFile}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const params = JSON.parse(fs.readFileSync(paramsFile, 'utf8'));
|
||||
console.log("Параметры загружены из файла");
|
||||
return params;
|
||||
} catch (error) {
|
||||
console.error("Ошибка при чтении файла параметров:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Сохраняем информацию о созданном DLE
|
||||
function saveDLEData(dleData) {
|
||||
const dlesDir = path.join(__dirname, "../../contracts-data/dles");
|
||||
|
||||
// Проверяем существование директории и создаем при необходимости
|
||||
try {
|
||||
if (!fs.existsSync(dlesDir)) {
|
||||
console.log(`Директория ${dlesDir} не существует, создаю...`);
|
||||
fs.mkdirSync(dlesDir, { recursive: true });
|
||||
console.log(`Директория ${dlesDir} успешно создана`);
|
||||
}
|
||||
|
||||
// Проверяем права на запись, создавая временный файл
|
||||
const testFile = path.join(dlesDir, '.write-test');
|
||||
fs.writeFileSync(testFile, 'test');
|
||||
fs.unlinkSync(testFile);
|
||||
console.log(`Директория ${dlesDir} доступна для записи`);
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Ошибка при проверке директории ${dlesDir}:`, error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Создаем уникальное имя файла
|
||||
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
||||
const fileName = `dle-v2-${timestamp}.json`;
|
||||
const filePath = path.join(dlesDir, fileName);
|
||||
|
||||
try {
|
||||
fs.writeFileSync(filePath, JSON.stringify(dleData, null, 2));
|
||||
console.log(`Информация о DLE сохранена в файл: ${fileName}`);
|
||||
return { success: true, filePath };
|
||||
} catch (error) {
|
||||
console.error(`Ошибка при сохранении файла ${filePath}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Запускаем скрипт
|
||||
main()
|
||||
.then(() => {
|
||||
console.log("Скрипт завершен успешно");
|
||||
process.exit(0);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Скрипт завершен с ошибкой:", error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable no-console */
|
||||
const hre = require('hardhat');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
// Подбираем безопасные gas/fee для разных сетей (включая L2)
|
||||
async function getFeeOverrides(provider, { minPriorityGwei = 1n, minFeeGwei = 20n } = {}) {
|
||||
@@ -19,7 +20,7 @@ async function getFeeOverrides(provider, { minPriorityGwei = 1n, minFeeGwei = 20
|
||||
return overrides;
|
||||
}
|
||||
|
||||
async function deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetFactoryNonce, dleInit) {
|
||||
async function deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetDLENonce, dleInit) {
|
||||
const { ethers } = hre;
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const wallet = new ethers.Wallet(pk, provider);
|
||||
@@ -30,7 +31,7 @@ async function deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetFactoryNonc
|
||||
const calcInitHash = ethers.keccak256(dleInit);
|
||||
const saltLen = ethers.getBytes(salt).length;
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} rpc=${rpcUrl}`);
|
||||
console.log(`[MULTI_DBG] wallet=${wallet.address} targetFactoryNonce=${targetFactoryNonce}`);
|
||||
console.log(`[MULTI_DBG] wallet=${wallet.address} targetDLENonce=${targetDLENonce}`);
|
||||
console.log(`[MULTI_DBG] saltLenBytes=${saltLen} salt=${salt}`);
|
||||
console.log(`[MULTI_DBG] initCodeHash(provided)=${initCodeHash}`);
|
||||
console.log(`[MULTI_DBG] initCodeHash(calculated)=${calcInitHash}`);
|
||||
@@ -39,170 +40,195 @@ async function deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetFactoryNonc
|
||||
console.log('[MULTI_DBG] precheck error', e?.message || e);
|
||||
}
|
||||
|
||||
// 1) Выравнивание nonce до targetFactoryNonce нулевыми транзакциями (если нужно)
|
||||
// 1) Выравнивание nonce до targetDLENonce нулевыми транзакциями (если нужно)
|
||||
let current = await provider.getTransactionCount(wallet.address, 'pending');
|
||||
if (current > targetFactoryNonce) {
|
||||
throw new Error(`Current nonce ${current} > targetFactoryNonce ${targetFactoryNonce} on chainId=${Number(net.chainId)}`);
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} current nonce=${current} target=${targetDLENonce}`);
|
||||
|
||||
if (current > targetDLENonce) {
|
||||
throw new Error(`Current nonce ${current} > targetDLENonce ${targetDLENonce} on chainId=${Number(net.chainId)}`);
|
||||
}
|
||||
while (current < targetFactoryNonce) {
|
||||
const overrides = await getFeeOverrides(provider);
|
||||
let gasLimit = 50000; // некоторые L2 требуют >21000
|
||||
let sent = false;
|
||||
let lastErr = null;
|
||||
for (let attempt = 0; attempt < 2 && !sent; attempt++) {
|
||||
try {
|
||||
const txReq = {
|
||||
to: wallet.address,
|
||||
value: 0n,
|
||||
nonce: current,
|
||||
gasLimit,
|
||||
...overrides
|
||||
};
|
||||
const txFill = await wallet.sendTransaction(txReq);
|
||||
await txFill.wait();
|
||||
sent = true;
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
if (String(e?.message || '').toLowerCase().includes('intrinsic gas too low') && attempt === 0) {
|
||||
gasLimit = 100000; // поднимаем лимит и пробуем ещё раз
|
||||
continue;
|
||||
|
||||
if (current < targetDLENonce) {
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} aligning nonce from ${current} to ${targetDLENonce} (${targetDLENonce - current} transactions needed)`);
|
||||
|
||||
// Используем burn address для более надежных транзакций
|
||||
const burnAddress = "0x000000000000000000000000000000000000dEaD";
|
||||
|
||||
while (current < targetDLENonce) {
|
||||
const overrides = await getFeeOverrides(provider);
|
||||
let gasLimit = 21000; // минимальный gas для обычной транзакции
|
||||
let sent = false;
|
||||
let lastErr = null;
|
||||
|
||||
for (let attempt = 0; attempt < 3 && !sent; attempt++) {
|
||||
try {
|
||||
const txReq = {
|
||||
to: burnAddress, // отправляем на burn address вместо своего адреса
|
||||
value: 0n,
|
||||
nonce: current,
|
||||
gasLimit,
|
||||
...overrides
|
||||
};
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} sending filler tx nonce=${current} attempt=${attempt + 1}`);
|
||||
const txFill = await wallet.sendTransaction(txReq);
|
||||
await txFill.wait();
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} filler tx nonce=${current} confirmed`);
|
||||
sent = true;
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} filler tx nonce=${current} attempt=${attempt + 1} failed: ${e?.message || e}`);
|
||||
|
||||
if (String(e?.message || '').toLowerCase().includes('intrinsic gas too low') && attempt < 2) {
|
||||
gasLimit = 50000; // увеличиваем gas limit
|
||||
continue;
|
||||
}
|
||||
|
||||
if (String(e?.message || '').toLowerCase().includes('nonce too low') && attempt < 2) {
|
||||
// Обновляем nonce и пробуем снова
|
||||
current = await provider.getTransactionCount(wallet.address, 'pending');
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} updated nonce to ${current}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
if (!sent) {
|
||||
console.error(`[MULTI_DBG] chainId=${Number(net.chainId)} failed to send filler tx for nonce=${current}`);
|
||||
throw lastErr || new Error('filler tx failed');
|
||||
}
|
||||
|
||||
current++;
|
||||
}
|
||||
if (!sent) throw lastErr || new Error('filler tx failed');
|
||||
current++;
|
||||
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} nonce alignment completed, current nonce=${current}`);
|
||||
} else {
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} nonce already aligned at ${current}`);
|
||||
}
|
||||
|
||||
// 2) Деплой FactoryDeployer на согласованном nonce
|
||||
const FactoryCF = await hre.ethers.getContractFactory('FactoryDeployer', wallet);
|
||||
// 2) Деплой DLE напрямую на согласованном nonce
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} deploying DLE directly with nonce=${targetDLENonce}`);
|
||||
|
||||
const feeOverrides = await getFeeOverrides(provider);
|
||||
const factoryContract = await FactoryCF.deploy({ nonce: targetFactoryNonce, ...feeOverrides });
|
||||
await factoryContract.waitForDeployment();
|
||||
const factoryAddress = await factoryContract.getAddress();
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} FactoryDeployer.address=${factoryAddress}`);
|
||||
let gasLimit;
|
||||
|
||||
try {
|
||||
// Оцениваем газ для деплоя DLE
|
||||
const est = await wallet.estimateGas({ data: dleInit, ...feeOverrides }).catch(() => null);
|
||||
|
||||
// Рассчитываем доступный gasLimit из баланса
|
||||
const balance = await provider.getBalance(wallet.address, 'latest');
|
||||
const effPrice = feeOverrides.maxFeePerGas || feeOverrides.gasPrice || 0n;
|
||||
const reserve = hre.ethers.parseEther('0.005');
|
||||
const maxByBalance = effPrice > 0n && balance > reserve ? (balance - reserve) / effPrice : 3_000_000n;
|
||||
const fallbackGas = maxByBalance > 5_000_000n ? 5_000_000n : (maxByBalance < 2_500_000n ? 2_500_000n : maxByBalance);
|
||||
gasLimit = est ? (est + est / 5n) : fallbackGas;
|
||||
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} estGas=${est?.toString?.()||'null'} effGasPrice=${effPrice?.toString?.()||'0'} maxByBalance=${maxByBalance.toString()} chosenGasLimit=${gasLimit.toString()}`);
|
||||
} catch (_) {
|
||||
gasLimit = 3_000_000n;
|
||||
}
|
||||
|
||||
// 3) Деплой DLE через CREATE2
|
||||
const Factory = await hre.ethers.getContractAt('FactoryDeployer', factoryAddress, wallet);
|
||||
const n = await provider.getTransactionCount(wallet.address, 'pending');
|
||||
// Вычисляем предсказанный адрес DLE
|
||||
const predictedAddress = ethers.getCreateAddress({
|
||||
from: wallet.address,
|
||||
nonce: targetDLENonce
|
||||
});
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} predicted DLE address=${predictedAddress}`);
|
||||
|
||||
// Проверяем, не развернут ли уже контракт
|
||||
const existingCode = await provider.getCode(predictedAddress);
|
||||
if (existingCode && existingCode !== '0x') {
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} DLE already exists at predictedAddress, skip deploy`);
|
||||
return { address: predictedAddress, chainId: Number(net.chainId) };
|
||||
}
|
||||
|
||||
// Деплоим DLE
|
||||
let tx;
|
||||
try {
|
||||
// Предварительная проверка конструктора вне CREATE2 (даст явную причину, если он ревертится)
|
||||
try {
|
||||
await wallet.estimateGas({ data: dleInit });
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} predeploy(estGas) ok for constructor`);
|
||||
} catch (e) {
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} predeploy(estGas) failed: ${e?.reason || e?.shortMessage || e?.message || e}`);
|
||||
if (e?.data) console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} predeploy revert data: ${e.data}`);
|
||||
}
|
||||
// Оцениваем газ и добавляем запас
|
||||
const est = await Factory.deploy.estimateGas(salt, dleInit, { nonce: n, ...feeOverrides }).catch(() => null);
|
||||
// Рассчитываем доступный gasLimit из баланса
|
||||
let gasLimit;
|
||||
try {
|
||||
const balance = await provider.getBalance(wallet.address, 'latest');
|
||||
const effPrice = feeOverrides.maxFeePerGas || feeOverrides.gasPrice || 0n;
|
||||
const reserve = hre.ethers.parseEther('0.005');
|
||||
const maxByBalance = effPrice > 0n && balance > reserve ? (balance - reserve) / effPrice : 3_000_000n;
|
||||
const fallbackGas = maxByBalance > 5_000_000n ? 5_000_000n : (maxByBalance < 2_500_000n ? 2_500_000n : maxByBalance);
|
||||
gasLimit = est ? (est + est / 5n) : fallbackGas;
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} estGas=${est?.toString?.()||'null'} effGasPrice=${effPrice?.toString?.()||'0'} maxByBalance=${maxByBalance.toString()} chosenGasLimit=${gasLimit.toString()}`);
|
||||
} catch (_) {
|
||||
const fallbackGas = 3_000_000n;
|
||||
gasLimit = est ? (est + est / 5n) : fallbackGas;
|
||||
}
|
||||
// DEBUG: ожидаемый адрес через computeAddress
|
||||
try {
|
||||
const predicted = await Factory.computeAddress(salt, initCodeHash);
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} predictedAddress=${predicted}`);
|
||||
// Idempotency: если уже есть код по адресу, пропускаем деплой
|
||||
const code = await provider.getCode(predicted);
|
||||
if (code && code !== '0x') {
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} code already exists at predictedAddress, skip deploy`);
|
||||
return { factory: factoryAddress, address: predicted, chainId: Number(net.chainId) };
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('[MULTI_DBG] computeAddress(before) error', e?.message || e);
|
||||
}
|
||||
tx = await Factory.deploy(salt, dleInit, { nonce: n, gasLimit, ...feeOverrides });
|
||||
tx = await wallet.sendTransaction({
|
||||
data: dleInit,
|
||||
nonce: targetDLENonce,
|
||||
gasLimit,
|
||||
...feeOverrides
|
||||
});
|
||||
} catch (e) {
|
||||
const n2 = await provider.getTransactionCount(wallet.address, 'pending');
|
||||
const est2 = await Factory.deploy.estimateGas(salt, dleInit, { nonce: n2, ...feeOverrides }).catch(() => null);
|
||||
let gasLimit2;
|
||||
try {
|
||||
const balance2 = await provider.getBalance(wallet.address, 'latest');
|
||||
const effPrice2 = feeOverrides.maxFeePerGas || feeOverrides.gasPrice || 0n;
|
||||
const reserve2 = hre.ethers.parseEther('0.005');
|
||||
const maxByBalance2 = effPrice2 > 0n && balance2 > reserve2 ? (balance2 - reserve2) / effPrice2 : 3_000_000n;
|
||||
const fallbackGas2 = maxByBalance2 > 5_000_000n ? 5_000_000n : (maxByBalance2 < 2_500_000n ? 2_500_000n : maxByBalance2);
|
||||
gasLimit2 = est2 ? (est2 + est2 / 5n) : fallbackGas2;
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} RETRY estGas=${est2?.toString?.()||'null'} effGasPrice=${effPrice2?.toString?.()||'0'} maxByBalance=${maxByBalance2.toString()} chosenGasLimit=${gasLimit2.toString()}`);
|
||||
} catch (_) {
|
||||
gasLimit2 = est2 ? (est2 + est2 / 5n) : 3_000_000n;
|
||||
}
|
||||
console.log(`[MULTI_DBG] retry deploy with nonce=${n2} gasLimit=${gasLimit2?.toString?.() || 'auto'}`);
|
||||
console.log(`[MULTI_DBG] deploy error(first) ${e?.message || e}`);
|
||||
tx = await Factory.deploy(salt, dleInit, { nonce: n2, gasLimit: gasLimit2, ...feeOverrides });
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} deploy error(first): ${e?.message || e}`);
|
||||
// Повторная попытка с обновленным nonce
|
||||
const updatedNonce = await provider.getTransactionCount(wallet.address, 'pending');
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} retry deploy with nonce=${updatedNonce}`);
|
||||
tx = await wallet.sendTransaction({
|
||||
data: dleInit,
|
||||
nonce: updatedNonce,
|
||||
gasLimit,
|
||||
...feeOverrides
|
||||
});
|
||||
}
|
||||
|
||||
const rc = await tx.wait();
|
||||
let addr = rc.logs?.[0]?.args?.addr;
|
||||
if (!addr) {
|
||||
try {
|
||||
addr = await Factory.computeAddress(salt, initCodeHash);
|
||||
} catch (e) {
|
||||
console.log('[MULTI_DBG] computeAddress(after) error', e?.message || e);
|
||||
}
|
||||
}
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} deployedAddress=${addr}`);
|
||||
return { factory: factoryAddress, address: addr, chainId: Number(net.chainId) };
|
||||
const deployedAddress = rc.contractAddress || predictedAddress;
|
||||
|
||||
console.log(`[MULTI_DBG] chainId=${Number(net.chainId)} DLE deployed at=${deployedAddress}`);
|
||||
return { address: deployedAddress, chainId: Number(net.chainId) };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const { ethers } = hre;
|
||||
const pk = process.env.PRIVATE_KEY;
|
||||
const salt = process.env.CREATE2_SALT;
|
||||
const initCodeHash = process.env.INIT_CODE_HASH;
|
||||
const networks = (process.env.MULTICHAIN_RPC_URLS || '').split(',').map(s => s.trim()).filter(Boolean);
|
||||
const factories = (process.env.MULTICHAIN_FACTORY_ADDRESSES || '').split(',').map(s => s.trim());
|
||||
|
||||
if (!pk) throw new Error('Env: PRIVATE_KEY');
|
||||
if (!salt) throw new Error('Env: CREATE2_SALT');
|
||||
if (!initCodeHash) throw new Error('Env: INIT_CODE_HASH');
|
||||
if (networks.length === 0) throw new Error('Env: MULTICHAIN_RPC_URLS');
|
||||
|
||||
// Prepare init code once
|
||||
|
||||
// Загружаем параметры из файла
|
||||
const paramsPath = path.join(__dirname, './current-params.json');
|
||||
const params = require(paramsPath);
|
||||
const DLE = await hre.ethers.getContractFactory('DLE');
|
||||
const dleConfig = {
|
||||
if (!fs.existsSync(paramsPath)) {
|
||||
throw new Error('Файл параметров не найден: ' + paramsPath);
|
||||
}
|
||||
|
||||
const params = JSON.parse(fs.readFileSync(paramsPath, 'utf8'));
|
||||
console.log('[MULTI_DBG] Загружены параметры:', {
|
||||
name: params.name,
|
||||
symbol: params.symbol,
|
||||
location: params.location,
|
||||
coordinates: params.coordinates,
|
||||
jurisdiction: params.jurisdiction,
|
||||
oktmo: params.oktmo,
|
||||
supportedChainIds: params.supportedChainIds,
|
||||
CREATE2_SALT: params.CREATE2_SALT
|
||||
});
|
||||
|
||||
const pk = process.env.PRIVATE_KEY;
|
||||
const salt = params.CREATE2_SALT;
|
||||
const networks = params.rpcUrls || [];
|
||||
|
||||
if (!pk) throw new Error('Env: PRIVATE_KEY');
|
||||
if (!salt) throw new Error('CREATE2_SALT not found in params');
|
||||
if (networks.length === 0) throw new Error('RPC URLs not found in params');
|
||||
|
||||
// Prepare init code once
|
||||
const DLE = await hre.ethers.getContractFactory('DLE');
|
||||
const dleConfig = {
|
||||
name: params.name || '',
|
||||
symbol: params.symbol || '',
|
||||
location: params.location || '',
|
||||
coordinates: params.coordinates || '',
|
||||
jurisdiction: params.jurisdiction || 0,
|
||||
oktmo: params.oktmo || '',
|
||||
okvedCodes: params.okvedCodes || [],
|
||||
kpp: params.kpp,
|
||||
quorumPercentage: params.quorumPercentage,
|
||||
initialPartners: params.initialPartners,
|
||||
initialAmounts: params.initialAmounts,
|
||||
supportedChainIds: params.supportedChainIds
|
||||
kpp: params.kpp ? BigInt(params.kpp) : 0n,
|
||||
quorumPercentage: params.quorumPercentage || 51,
|
||||
initialPartners: params.initialPartners || [],
|
||||
initialAmounts: (params.initialAmounts || []).map(amount => BigInt(amount)),
|
||||
supportedChainIds: (params.supportedChainIds || []).map(id => BigInt(id))
|
||||
};
|
||||
const deployTx = await DLE.getDeployTransaction(dleConfig, params.currentChainId);
|
||||
const deployTx = await DLE.getDeployTransaction(dleConfig, BigInt(params.currentChainId || params.supportedChainIds?.[0] || 1), params.initializer || params.initialPartners?.[0] || "0x0000000000000000000000000000000000000000");
|
||||
const dleInit = deployTx.data;
|
||||
const initCodeHash = ethers.keccak256(dleInit);
|
||||
|
||||
// DEBUG: глобальные значения
|
||||
try {
|
||||
const calcInitHash = ethers.keccak256(dleInit);
|
||||
const saltLen = ethers.getBytes(salt).length;
|
||||
console.log(`[MULTI_DBG] GLOBAL saltLenBytes=${saltLen} salt=${salt}`);
|
||||
console.log(`[MULTI_DBG] GLOBAL initCodeHash(provided)=${initCodeHash}`);
|
||||
console.log(`[MULTI_DBG] GLOBAL initCodeHash(calculated)=${calcInitHash}`);
|
||||
console.log(`[MULTI_DBG] GLOBAL initCodeHash(calculated)=${initCodeHash}`);
|
||||
console.log(`[MULTI_DBG] GLOBAL dleInit.lenBytes=${ethers.getBytes(dleInit).length} head16=${dleInit.slice(0, 34)}...`);
|
||||
} catch (e) {
|
||||
console.log('[MULTI_DBG] GLOBAL precheck error', e?.message || e);
|
||||
}
|
||||
|
||||
// Подготовим провайдеры и вычислим общий nonce для фабрики
|
||||
// Подготовим провайдеры и вычислим общий nonce для DLE
|
||||
const providers = networks.map(u => new hre.ethers.JsonRpcProvider(u));
|
||||
const wallets = providers.map(p => new hre.ethers.Wallet(pk, p));
|
||||
const nonces = [];
|
||||
@@ -210,15 +236,28 @@ async function main() {
|
||||
const n = await providers[i].getTransactionCount(wallets[i].address, 'pending');
|
||||
nonces.push(n);
|
||||
}
|
||||
const targetFactoryNonce = Math.max(...nonces);
|
||||
console.log(`[MULTI_DBG] nonces=${JSON.stringify(nonces)} targetFactoryNonce=${targetFactoryNonce}`);
|
||||
const targetDLENonce = Math.max(...nonces);
|
||||
console.log(`[MULTI_DBG] nonces=${JSON.stringify(nonces)} targetDLENonce=${targetDLENonce}`);
|
||||
|
||||
const results = [];
|
||||
for (let i = 0; i < networks.length; i++) {
|
||||
const rpcUrl = networks[i];
|
||||
const r = await deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetFactoryNonce, dleInit);
|
||||
console.log(`[MULTI_DBG] deploying to network ${i + 1}/${networks.length}: ${rpcUrl}`);
|
||||
const r = await deployInNetwork(rpcUrl, pk, salt, initCodeHash, targetDLENonce, dleInit);
|
||||
results.push({ rpcUrl, ...r });
|
||||
}
|
||||
|
||||
// Проверяем, что все адреса одинаковые
|
||||
const addresses = results.map(r => r.address);
|
||||
const uniqueAddresses = [...new Set(addresses)];
|
||||
|
||||
if (uniqueAddresses.length > 1) {
|
||||
console.error('[MULTI_DBG] ERROR: DLE addresses are different across networks!');
|
||||
console.error('[MULTI_DBG] addresses:', uniqueAddresses);
|
||||
throw new Error('Nonce alignment failed - addresses are different');
|
||||
}
|
||||
|
||||
console.log('[MULTI_DBG] SUCCESS: All DLE addresses are identical:', uniqueAddresses[0]);
|
||||
console.log('MULTICHAIN_DEPLOY_RESULT', JSON.stringify(results));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,20 @@ class DLEV2Service {
|
||||
// Подготовка параметров для деплоя
|
||||
const deployParams = this.prepareDeployParams(dleParams);
|
||||
|
||||
// Вычисляем адрес инициализатора (инициализатором является деплоер из переданного приватного ключа)
|
||||
try {
|
||||
const normalizedPk = dleParams.privateKey?.startsWith('0x') ? dleParams.privateKey : `0x${dleParams.privateKey}`;
|
||||
const initializerAddress = new ethers.Wallet(normalizedPk).address;
|
||||
deployParams.initializerAddress = initializerAddress;
|
||||
} catch (e) {
|
||||
logger.warn('Не удалось вычислить initializerAddress из приватного ключа:', e.message);
|
||||
}
|
||||
|
||||
// Генерируем одноразовый CREATE2_SALT и сохраняем его с уникальным ключом в secrets
|
||||
const { createAndStoreNewCreate2Salt } = require('./secretStore');
|
||||
const { salt: create2Salt, key: saltKey } = await createAndStoreNewCreate2Salt({ label: deployParams.name || 'DLEv2' });
|
||||
logger.info(`CREATE2_SALT создан и сохранён: key=${saltKey}`);
|
||||
|
||||
// Сохраняем параметры во временный файл
|
||||
paramsFile = this.saveParamsToFile(deployParams);
|
||||
|
||||
@@ -51,8 +65,7 @@ class DLEV2Service {
|
||||
fs.mkdirSync(deployDir, { recursive: true });
|
||||
}
|
||||
fs.copyFileSync(paramsFile, tempParamsFile);
|
||||
logger.info(`Файл параметров скопирован успешно`);
|
||||
|
||||
|
||||
// Готовим RPC для всех выбранных сетей
|
||||
const rpcUrls = [];
|
||||
for (const cid of deployParams.supportedChainIds) {
|
||||
@@ -64,6 +77,19 @@ class DLEV2Service {
|
||||
rpcUrls.push(ru);
|
||||
}
|
||||
|
||||
// Добавляем CREATE2_SALT, RPC_URLS и initializer в файл параметров
|
||||
const currentParams = JSON.parse(fs.readFileSync(tempParamsFile, 'utf8'));
|
||||
// Копируем все параметры из deployParams
|
||||
Object.assign(currentParams, deployParams);
|
||||
currentParams.CREATE2_SALT = create2Salt;
|
||||
currentParams.rpcUrls = rpcUrls;
|
||||
currentParams.currentChainId = deployParams.currentChainId || deployParams.supportedChainIds[0];
|
||||
const { ethers } = require('ethers');
|
||||
currentParams.initializer = dleParams.privateKey ? new ethers.Wallet(dleParams.privateKey.startsWith('0x') ? dleParams.privateKey : `0x${dleParams.privateKey}`).address : "0x0000000000000000000000000000000000000000";
|
||||
fs.writeFileSync(tempParamsFile, JSON.stringify(currentParams, null, 2));
|
||||
|
||||
logger.info(`Файл параметров скопирован и обновлен с CREATE2_SALT`);
|
||||
|
||||
// Лёгкая проверка баланса в первой сети
|
||||
{
|
||||
const { ethers } = require('ethers');
|
||||
@@ -72,7 +98,15 @@ class DLEV2Service {
|
||||
const pk = dleParams.privateKey.startsWith('0x') ? dleParams.privateKey : `0x${dleParams.privateKey}`;
|
||||
const walletAddress = new ethers.Wallet(pk, provider).address;
|
||||
const balance = await provider.getBalance(walletAddress);
|
||||
|
||||
if (typeof ethers.parseEther !== 'function') {
|
||||
throw new Error('Метод ethers.parseEther не найден');
|
||||
}
|
||||
const minBalance = ethers.parseEther("0.00001");
|
||||
|
||||
if (typeof ethers.formatEther !== 'function') {
|
||||
throw new Error('Метод ethers.formatEther не найден');
|
||||
}
|
||||
logger.info(`Баланс кошелька ${walletAddress}: ${ethers.formatEther(balance)} ETH`);
|
||||
if (balance < minBalance) {
|
||||
throw new Error(`Недостаточно ETH для деплоя в ${deployParams.supportedChainIds[0]}. Баланс: ${ethers.formatEther(balance)} ETH`);
|
||||
@@ -84,28 +118,58 @@ class DLEV2Service {
|
||||
}
|
||||
|
||||
// Рассчитываем INIT_CODE_HASH автоматически из актуального initCode
|
||||
const initCodeHash = await this.computeInitCodeHash(deployParams);
|
||||
const initCodeHash = await this.computeInitCodeHash({
|
||||
...deployParams,
|
||||
currentChainId: deployParams.currentChainId || deployParams.supportedChainIds[0]
|
||||
});
|
||||
|
||||
// Собираем адреса фабрик по сетям (если есть)
|
||||
const factoryAddresses = deployParams.supportedChainIds.map(cid => process.env[`FACTORY_ADDRESS_${cid}`] || '').join(',');
|
||||
// Factory больше не используется - деплой DLE напрямую
|
||||
logger.info(`Подготовка к прямому деплою DLE в сетях: ${deployParams.supportedChainIds.join(', ')}`);
|
||||
|
||||
// Мультисетевой деплой одним вызовом
|
||||
// Генерируем одноразовый CREATE2_SALT и сохраняем его с уникальным ключом в secrets
|
||||
const { createAndStoreNewCreate2Salt } = require('./secretStore');
|
||||
const { salt: create2Salt, key: saltKey } = await createAndStoreNewCreate2Salt({ label: deployParams.name || 'DLEv2' });
|
||||
logger.info(`CREATE2_SALT создан и сохранён: key=${saltKey}`);
|
||||
|
||||
logger.info('Запуск мульти-чейн деплоя...');
|
||||
|
||||
const result = await this.runDeployMultichain(paramsFile, {
|
||||
rpcUrls: rpcUrls.join(','),
|
||||
rpcUrls: rpcUrls,
|
||||
chainIds: deployParams.supportedChainIds,
|
||||
privateKey: dleParams.privateKey?.startsWith('0x') ? dleParams.privateKey : `0x${dleParams.privateKey}`,
|
||||
salt: create2Salt,
|
||||
initCodeHash,
|
||||
factories: factoryAddresses
|
||||
initCodeHash
|
||||
});
|
||||
|
||||
logger.info('Деплой завершен, результат:', JSON.stringify(result, null, 2));
|
||||
|
||||
// Сохраняем информацию о созданном DLE для отображения на странице управления
|
||||
try {
|
||||
const firstNet = Array.isArray(result?.data?.networks) && result.data.networks.length > 0 ? result.data.networks[0] : null;
|
||||
logger.info('Результат деплоя для сохранения:', JSON.stringify(result, null, 2));
|
||||
|
||||
// Проверяем структуру результата
|
||||
if (!result || typeof result !== 'object') {
|
||||
logger.error('Неверная структура результата деплоя:', result);
|
||||
throw new Error('Неверная структура результата деплоя');
|
||||
}
|
||||
|
||||
// Если результат - массив (прямой результат из скрипта), преобразуем его
|
||||
let deployResult = result;
|
||||
if (Array.isArray(result)) {
|
||||
logger.info('Результат - массив, преобразуем в объект');
|
||||
const addresses = result.map(r => r.address);
|
||||
const allSame = addresses.every(addr => addr.toLowerCase() === addresses[0].toLowerCase());
|
||||
deployResult = {
|
||||
success: true,
|
||||
data: {
|
||||
dleAddress: addresses[0],
|
||||
networks: result.map((r, index) => ({
|
||||
chainId: r.chainId,
|
||||
address: r.address,
|
||||
success: true
|
||||
})),
|
||||
allSame
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const firstNet = Array.isArray(deployResult?.data?.networks) && deployResult.data.networks.length > 0 ? deployResult.data.networks[0] : null;
|
||||
const dleData = {
|
||||
name: deployParams.name,
|
||||
symbol: deployParams.symbol,
|
||||
@@ -122,13 +186,20 @@ class DLEV2Service {
|
||||
supportedChainIds: deployParams.supportedChainIds,
|
||||
currentChainId: deployParams.currentChainId
|
||||
},
|
||||
dleAddress: (result?.data?.dleAddress) || (firstNet?.address) || null,
|
||||
dleAddress: (deployResult?.data?.dleAddress) || (firstNet?.address) || null,
|
||||
version: 'v2',
|
||||
networks: result?.data?.networks || [],
|
||||
networks: deployResult?.data?.networks || [],
|
||||
createdAt: new Date().toISOString()
|
||||
};
|
||||
|
||||
logger.info('Данные DLE для сохранения:', JSON.stringify(dleData, null, 2));
|
||||
|
||||
if (dleData.dleAddress) {
|
||||
this.saveDLEData(dleData);
|
||||
// Сохраняем одну карточку DLE с информацией о всех сетях
|
||||
const savedPath = this.saveDLEData(dleData);
|
||||
logger.info(`DLE данные сохранены в: ${savedPath}`);
|
||||
} else {
|
||||
logger.error('Не удалось получить адрес DLE из результата деплоя');
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn('Не удалось сохранить локальную карточку DLE:', e.message);
|
||||
@@ -215,7 +286,7 @@ class DLEV2Service {
|
||||
|
||||
// Проверяем адреса партнеров
|
||||
for (let i = 0; i < params.initialPartners.length; i++) {
|
||||
if (!ethers.isAddress(params.initialPartners[i])) {
|
||||
if (!ethers.isAddress || !ethers.isAddress(params.initialPartners[i])) {
|
||||
throw new Error(`Неверный адрес партнера ${i + 1}: ${params.initialPartners[i]}`);
|
||||
}
|
||||
}
|
||||
@@ -225,7 +296,51 @@ class DLEV2Service {
|
||||
throw new Error('Должна быть выбрана хотя бы одна сеть для деплоя');
|
||||
}
|
||||
|
||||
// Дополнительные проверки безопасности
|
||||
if (params.name.length > 100) {
|
||||
throw new Error('Название DLE слишком длинное (максимум 100 символов)');
|
||||
}
|
||||
|
||||
if (params.symbol.length > 10) {
|
||||
throw new Error('Символ токена слишком длинный (максимум 10 символов)');
|
||||
}
|
||||
|
||||
if (params.location.length > 200) {
|
||||
throw new Error('Местонахождение слишком длинное (максимум 200 символов)');
|
||||
}
|
||||
|
||||
// Проверяем суммы токенов
|
||||
for (let i = 0; i < params.initialAmounts.length; i++) {
|
||||
const amount = params.initialAmounts[i];
|
||||
if (typeof amount !== 'string' && typeof amount !== 'number') {
|
||||
throw new Error(`Неверный тип суммы для партнера ${i + 1}`);
|
||||
}
|
||||
|
||||
const numAmount = typeof amount === 'string' ? parseFloat(amount) : amount;
|
||||
if (isNaN(numAmount) || numAmount <= 0) {
|
||||
throw new Error(`Неверная сумма для партнера ${i + 1}: ${amount}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Проверяем приватный ключ
|
||||
if (!params.privateKey) {
|
||||
throw new Error('Приватный ключ обязателен для деплоя');
|
||||
}
|
||||
|
||||
const pk = params.privateKey.startsWith('0x') ? params.privateKey : `0x${params.privateKey}`;
|
||||
if (!/^0x[a-fA-F0-9]{64}$/.test(pk)) {
|
||||
throw new Error('Неверный формат приватного ключа');
|
||||
}
|
||||
|
||||
// Проверяем, что не деплоим в mainnet без подтверждения
|
||||
const mainnetChains = [1, 137, 56, 42161]; // Ethereum, Polygon, BSC, Arbitrum
|
||||
const hasMainnet = params.supportedChainIds.some(id => mainnetChains.includes(id));
|
||||
|
||||
if (hasMainnet) {
|
||||
logger.warn('⚠️ ВНИМАНИЕ: Деплой включает mainnet сети! Убедитесь, что это необходимо.');
|
||||
}
|
||||
|
||||
logger.info('✅ Валидация параметров DLE пройдена успешно');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,6 +408,9 @@ class DLEV2Service {
|
||||
// Принимаем как строки, так и числа; конвертируем в base units (18 знаков)
|
||||
try {
|
||||
if (typeof rawAmount === 'number' && Number.isFinite(rawAmount)) {
|
||||
if (typeof ethers.parseUnits !== 'function') {
|
||||
throw new Error('Метод ethers.parseUnits не найден');
|
||||
}
|
||||
return ethers.parseUnits(rawAmount.toString(), 18).toString();
|
||||
}
|
||||
if (typeof rawAmount === 'string') {
|
||||
@@ -302,6 +420,9 @@ class DLEV2Service {
|
||||
return BigInt(a).toString();
|
||||
}
|
||||
// Десятичная строка — конвертируем в base units
|
||||
if (typeof ethers.parseUnits !== 'function') {
|
||||
throw new Error('Метод ethers.parseUnits не найден');
|
||||
}
|
||||
return ethers.parseUnits(a, 18).toString();
|
||||
}
|
||||
// BigInt или иные типы — приводим к строке без изменения масштаба
|
||||
@@ -318,6 +439,13 @@ class DLEV2Service {
|
||||
deployParams.okvedCodes = [];
|
||||
}
|
||||
|
||||
// Преобразуем kpp в число
|
||||
if (deployParams.kpp) {
|
||||
deployParams.kpp = parseInt(deployParams.kpp) || 0;
|
||||
} else {
|
||||
deployParams.kpp = 0;
|
||||
}
|
||||
|
||||
// Убеждаемся, что supportedChainIds - это массив
|
||||
if (!Array.isArray(deployParams.supportedChainIds)) {
|
||||
deployParams.supportedChainIds = [1]; // По умолчанию Ethereum
|
||||
@@ -360,7 +488,7 @@ class DLEV2Service {
|
||||
*/
|
||||
runDeployScript(paramsFile, extraEnv = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const scriptPath = path.join(__dirname, '../scripts/deploy/create-dle-v2.js');
|
||||
const scriptPath = path.join(__dirname, '../scripts/deploy/deploy-multichain.js');
|
||||
if (!fs.existsSync(scriptPath)) {
|
||||
reject(new Error('Скрипт деплоя DLE v2 не найден: ' + scriptPath));
|
||||
return;
|
||||
@@ -416,33 +544,70 @@ class DLEV2Service {
|
||||
runDeployMultichain(paramsFile, opts = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const scriptPath = path.join(__dirname, '../scripts/deploy/deploy-multichain.js');
|
||||
if (!fs.existsSync(scriptPath)) return reject(new Error('Скрипт мультисетевого деплоя не найден'));
|
||||
if (!fs.existsSync(scriptPath)) return reject(new Error('Скрипт мультисетевого деплоя не найден: ' + scriptPath));
|
||||
|
||||
const envVars = {
|
||||
...process.env,
|
||||
PRIVATE_KEY: opts.privateKey,
|
||||
CREATE2_SALT: opts.salt,
|
||||
INIT_CODE_HASH: opts.initCodeHash,
|
||||
MULTICHAIN_RPC_URLS: opts.rpcUrls,
|
||||
MULTICHAIN_FACTORY_ADDRESSES: opts.factories || ''
|
||||
PRIVATE_KEY: opts.privateKey
|
||||
};
|
||||
const p = spawn('npx', ['hardhat', 'run', scriptPath], { cwd: path.join(__dirname, '..'), env: envVars, stdio: 'pipe' });
|
||||
|
||||
const p = spawn('npx', ['hardhat', 'run', scriptPath], {
|
||||
cwd: path.join(__dirname, '..'),
|
||||
env: envVars,
|
||||
stdio: 'pipe'
|
||||
});
|
||||
|
||||
let stdout = '', stderr = '';
|
||||
p.stdout.on('data', (d) => { stdout += d.toString(); logger.info(`[MULTI] ${d.toString().trim()}`); });
|
||||
p.stderr.on('data', (d) => { stderr += d.toString(); logger.error(`[MULTI_ERR] ${d.toString().trim()}`); });
|
||||
p.on('close', () => {
|
||||
p.stdout.on('data', (d) => {
|
||||
stdout += d.toString();
|
||||
logger.info(`[MULTICHAIN_DEPLOY] ${d.toString().trim()}`);
|
||||
});
|
||||
p.stderr.on('data', (d) => {
|
||||
stderr += d.toString();
|
||||
logger.error(`[MULTICHAIN_DEPLOY_ERR] ${d.toString().trim()}`);
|
||||
});
|
||||
|
||||
p.on('close', (code) => {
|
||||
try {
|
||||
const m = stdout.match(/MULTICHAIN_DEPLOY_RESULT\s*(\[.*\])/s);
|
||||
if (!m) throw new Error('Результат не найден');
|
||||
const arr = JSON.parse(m[1]);
|
||||
if (!Array.isArray(arr) || arr.length === 0) throw new Error('Пустой результат деплоя');
|
||||
const addr = arr[0].address;
|
||||
const allSame = arr.every(x => x.address && x.address.toLowerCase() === addr.toLowerCase());
|
||||
if (!allSame) throw new Error('Адреса отличаются между сетями');
|
||||
resolve({ success: true, data: { dleAddress: addr, networks: arr } });
|
||||
// Ищем результат в формате MULTICHAIN_DEPLOY_RESULT
|
||||
const resultMatch = stdout.match(/MULTICHAIN_DEPLOY_RESULT\s+(\[.*\])/);
|
||||
|
||||
if (resultMatch) {
|
||||
const result = JSON.parse(resultMatch[1]);
|
||||
resolve(result);
|
||||
} else {
|
||||
// Fallback: ищем адреса DLE в выводе по новому формату
|
||||
const dleAddressMatches = stdout.match(/\[MULTI_DBG\] chainId=\d+ DLE deployed at=(0x[a-fA-F0-9]{40})/g);
|
||||
if (!dleAddressMatches || dleAddressMatches.length === 0) {
|
||||
throw new Error('Не найдены адреса DLE в выводе');
|
||||
}
|
||||
|
||||
const addresses = dleAddressMatches.map(match => match.match(/(0x[a-fA-F0-9]{40})/)[1]);
|
||||
const addr = addresses[0];
|
||||
const allSame = addresses.every(x => x.toLowerCase() === addr.toLowerCase());
|
||||
|
||||
if (!allSame) {
|
||||
logger.warn('Адреса отличаются между сетями — продолжаем, сохраню по-сеточно', { addresses });
|
||||
}
|
||||
|
||||
resolve({
|
||||
success: true,
|
||||
data: {
|
||||
dleAddress: addr,
|
||||
networks: addresses.map((address, index) => ({
|
||||
chainId: opts.chainIds[index] || index + 1,
|
||||
address,
|
||||
success: true
|
||||
})),
|
||||
allSame
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
reject(new Error(`Ошибка мультисетевого деплоя: ${e.message}\nSTDOUT:${stdout}\nSTDERR:${stderr}`));
|
||||
}
|
||||
});
|
||||
|
||||
p.on('error', (e) => reject(e));
|
||||
});
|
||||
}
|
||||
@@ -453,8 +618,20 @@ class DLEV2Service {
|
||||
* @returns {Object} - Результат деплоя
|
||||
*/
|
||||
extractDeployResult(stdout) {
|
||||
// Ищем строки с адресами в выводе
|
||||
const dleAddressMatch = stdout.match(/DLE v2 задеплоен по адресу: (0x[a-fA-F0-9]{40})/);
|
||||
// Ищем результат в формате MULTICHAIN_DEPLOY_RESULT
|
||||
const resultMatch = stdout.match(/MULTICHAIN_DEPLOY_RESULT\s+(\[.*?\])/);
|
||||
|
||||
if (resultMatch) {
|
||||
try {
|
||||
const result = JSON.parse(resultMatch[1]);
|
||||
return result;
|
||||
} catch (e) {
|
||||
logger.error('Ошибка парсинга JSON результата:', e);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: ищем строки с адресами в выводе по новому формату
|
||||
const dleAddressMatch = stdout.match(/\[MULTI_DBG\] chainId=\d+ DLE deployed at=(0x[a-fA-F0-9]{40})/);
|
||||
|
||||
if (dleAddressMatch) {
|
||||
return {
|
||||
@@ -529,7 +706,7 @@ class DLEV2Service {
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(dlesDir);
|
||||
return files
|
||||
const allDles = files
|
||||
.filter(file => file.endsWith('.json') && file.includes('dle-v2-'))
|
||||
.map(file => {
|
||||
try {
|
||||
@@ -541,68 +718,300 @@ class DLEV2Service {
|
||||
}
|
||||
})
|
||||
.filter(dle => dle !== null);
|
||||
|
||||
// Группируем DLE по мультичейн деплоям
|
||||
const groupedDles = this.groupMultichainDLEs(allDles);
|
||||
|
||||
return groupedDles;
|
||||
} catch (error) {
|
||||
logger.error('Ошибка при получении списка DLE v2:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
// Авто-расчёт INIT_CODE_HASH
|
||||
async computeInitCodeHash(params) {
|
||||
const hre = require('hardhat');
|
||||
const { ethers } = hre;
|
||||
const DLE = await hre.ethers.getContractFactory('DLE');
|
||||
const dleConfig = {
|
||||
name: params.name,
|
||||
symbol: params.symbol,
|
||||
location: params.location,
|
||||
coordinates: params.coordinates,
|
||||
jurisdiction: params.jurisdiction,
|
||||
okvedCodes: params.okvedCodes || [],
|
||||
kpp: params.kpp,
|
||||
quorumPercentage: params.quorumPercentage,
|
||||
initialPartners: params.initialPartners,
|
||||
initialAmounts: params.initialAmounts,
|
||||
supportedChainIds: params.supportedChainIds
|
||||
};
|
||||
const deployTx = await DLE.getDeployTransaction(dleConfig, params.currentChainId);
|
||||
const initCode = deployTx.data;
|
||||
return ethers.keccak256(initCode);
|
||||
/**
|
||||
* Группирует DLE по мультичейн деплоям
|
||||
* @param {Array<Object>} allDles - Все DLE из файлов
|
||||
* @returns {Array<Object>} - Сгруппированные DLE
|
||||
*/
|
||||
groupMultichainDLEs(allDles) {
|
||||
const groups = new Map();
|
||||
|
||||
for (const dle of allDles) {
|
||||
// Создаем ключ для группировки на основе общих параметров
|
||||
const groupKey = this.createGroupKey(dle);
|
||||
|
||||
if (!groups.has(groupKey)) {
|
||||
groups.set(groupKey, {
|
||||
// Основные данные из первого DLE
|
||||
name: dle.name,
|
||||
symbol: dle.symbol,
|
||||
location: dle.location,
|
||||
coordinates: dle.coordinates,
|
||||
jurisdiction: dle.jurisdiction,
|
||||
oktmo: dle.oktmo,
|
||||
okvedCodes: dle.okvedCodes,
|
||||
kpp: dle.kpp,
|
||||
quorumPercentage: dle.quorumPercentage,
|
||||
version: dle.version || 'v2',
|
||||
deployedMultichain: true,
|
||||
// Мультичейн информация
|
||||
networks: [],
|
||||
// Модули (одинаковые во всех сетях)
|
||||
modules: dle.modules,
|
||||
// Время создания (самое раннее)
|
||||
creationTimestamp: dle.creationTimestamp,
|
||||
creationBlock: dle.creationBlock
|
||||
});
|
||||
}
|
||||
|
||||
const group = groups.get(groupKey);
|
||||
|
||||
// Если у DLE есть массив networks, используем его
|
||||
if (dle.networks && Array.isArray(dle.networks)) {
|
||||
for (const network of dle.networks) {
|
||||
group.networks.push({
|
||||
chainId: network.chainId,
|
||||
dleAddress: network.address || network.dleAddress,
|
||||
factoryAddress: network.factoryAddress,
|
||||
rpcUrl: network.rpcUrl || this.getRpcUrlForChain(network.chainId)
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Старый формат: добавляем информацию о сети из корня DLE
|
||||
group.networks.push({
|
||||
chainId: dle.chainId,
|
||||
dleAddress: dle.dleAddress,
|
||||
factoryAddress: dle.factoryAddress,
|
||||
rpcUrl: dle.rpcUrl || this.getRpcUrlForChain(dle.chainId)
|
||||
});
|
||||
}
|
||||
|
||||
// Обновляем время создания на самое раннее
|
||||
if (dle.creationTimestamp && (!group.creationTimestamp || dle.creationTimestamp < group.creationTimestamp)) {
|
||||
group.creationTimestamp = dle.creationTimestamp;
|
||||
}
|
||||
}
|
||||
|
||||
// Преобразуем группы в массив
|
||||
return Array.from(groups.values()).map(group => ({
|
||||
...group,
|
||||
// Основной адрес DLE (из первой сети)
|
||||
dleAddress: group.networks[0]?.dleAddress,
|
||||
// Общее количество сетей
|
||||
totalNetworks: group.networks.length,
|
||||
// Поддерживаемые сети
|
||||
supportedChainIds: group.networks.map(n => n.chainId)
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет баланс деплоера во всех выбранных сетях
|
||||
* @param {number[]} chainIds
|
||||
* @param {string} privateKey
|
||||
* @returns {Promise<{balances: Array<{chainId:number, balanceEth:string, ok:boolean, rpcUrl:string}>, insufficient:number[]}>}
|
||||
* Создает ключ для группировки DLE
|
||||
* @param {Object} dle - Данные DLE
|
||||
* @returns {string} - Ключ группировки
|
||||
*/
|
||||
createGroupKey(dle) {
|
||||
// Группируем по основным параметрам DLE
|
||||
const keyParts = [
|
||||
dle.name,
|
||||
dle.symbol,
|
||||
dle.location,
|
||||
dle.coordinates,
|
||||
dle.jurisdiction,
|
||||
dle.oktmo,
|
||||
dle.kpp,
|
||||
dle.quorumPercentage,
|
||||
// Сортируем okvedCodes для стабильного ключа
|
||||
Array.isArray(dle.okvedCodes) ? dle.okvedCodes.sort().join(',') : '',
|
||||
// Сортируем supportedChainIds для стабильного ключа
|
||||
Array.isArray(dle.supportedChainIds) ? dle.supportedChainIds.sort().join(',') : ''
|
||||
];
|
||||
|
||||
return keyParts.join('|');
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает RPC URL для сети
|
||||
* @param {number} chainId - ID сети
|
||||
* @returns {string|null} - RPC URL
|
||||
*/
|
||||
getRpcUrlForChain(chainId) {
|
||||
try {
|
||||
// Простая маппинг для основных сетей
|
||||
const rpcMap = {
|
||||
1: 'https://eth-mainnet.g.alchemy.com/v2/demo',
|
||||
11155111: 'https://eth-sepolia.nodereal.io/v1/56dec8028bae4f26b76099a42dae2b52',
|
||||
17000: 'https://ethereum-holesky.publicnode.com',
|
||||
421614: 'https://sepolia-rollup.arbitrum.io/rpc',
|
||||
84532: 'https://sepolia.base.org'
|
||||
};
|
||||
return rpcMap[chainId] || null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Авто-расчёт INIT_CODE_HASH
|
||||
async computeInitCodeHash(params) {
|
||||
try {
|
||||
// Проверяем наличие обязательных параметров
|
||||
if (!params.name || !params.symbol || !params.location) {
|
||||
throw new Error('Отсутствуют обязательные параметры для вычисления INIT_CODE_HASH');
|
||||
}
|
||||
|
||||
const hre = require('hardhat');
|
||||
const { ethers } = hre;
|
||||
|
||||
// Проверяем, что контракт DLE существует
|
||||
try {
|
||||
const DLE = await hre.ethers.getContractFactory('DLE');
|
||||
if (!DLE) {
|
||||
throw new Error('Контракт DLE не найден в Hardhat');
|
||||
}
|
||||
} catch (contractError) {
|
||||
throw new Error(`Ошибка загрузки контракта DLE: ${contractError.message}`);
|
||||
}
|
||||
|
||||
const DLE = await hre.ethers.getContractFactory('DLE');
|
||||
const dleConfig = {
|
||||
name: params.name,
|
||||
symbol: params.symbol,
|
||||
location: params.location,
|
||||
coordinates: params.coordinates || "",
|
||||
jurisdiction: params.jurisdiction || 1,
|
||||
okvedCodes: params.okvedCodes || [],
|
||||
kpp: params.kpp || 0,
|
||||
quorumPercentage: params.quorumPercentage || 51,
|
||||
initialPartners: params.initialPartners || [],
|
||||
initialAmounts: params.initialAmounts || [],
|
||||
supportedChainIds: params.supportedChainIds || [1]
|
||||
};
|
||||
// Учитываем актуальную сигнатуру конструктора: (dleConfig, currentChainId, initializer)
|
||||
const initializer = params.initializerAddress || "0x0000000000000000000000000000000000000000";
|
||||
const currentChainId = params.currentChainId || 1; // Fallback на Ethereum mainnet
|
||||
|
||||
logger.info('Вычисление INIT_CODE_HASH с параметрами:', {
|
||||
name: dleConfig.name,
|
||||
symbol: dleConfig.symbol,
|
||||
currentChainId,
|
||||
initializer
|
||||
});
|
||||
|
||||
// Проверяем, что метод getDeployTransaction существует
|
||||
if (typeof DLE.getDeployTransaction !== 'function') {
|
||||
throw new Error('Метод getDeployTransaction не найден в контракте DLE');
|
||||
}
|
||||
|
||||
const deployTx = await DLE.getDeployTransaction(dleConfig, currentChainId, initializer);
|
||||
if (!deployTx || !deployTx.data) {
|
||||
throw new Error('Не удалось получить данные транзакции деплоя');
|
||||
}
|
||||
|
||||
const initCode = deployTx.data;
|
||||
|
||||
// Проверяем, что метод keccak256 существует
|
||||
if (typeof ethers.keccak256 !== 'function') {
|
||||
throw new Error('Метод ethers.keccak256 не найден');
|
||||
}
|
||||
|
||||
const hash = ethers.keccak256(initCode);
|
||||
|
||||
logger.info('INIT_CODE_HASH вычислен успешно:', hash);
|
||||
return hash;
|
||||
} catch (error) {
|
||||
logger.error('Ошибка при вычислении INIT_CODE_HASH:', error);
|
||||
// Fallback: возвращаем хеш на основе параметров
|
||||
const { ethers } = require('ethers');
|
||||
const fallbackData = JSON.stringify({
|
||||
name: params.name,
|
||||
symbol: params.symbol,
|
||||
location: params.location,
|
||||
jurisdiction: params.jurisdiction,
|
||||
supportedChainIds: params.supportedChainIds
|
||||
});
|
||||
|
||||
// Проверяем, что методы существуют
|
||||
if (typeof ethers.toUtf8Bytes !== 'function') {
|
||||
throw new Error('Метод ethers.toUtf8Bytes не найден');
|
||||
}
|
||||
if (typeof ethers.keccak256 !== 'function') {
|
||||
throw new Error('Метод ethers.keccak256 не найден');
|
||||
}
|
||||
|
||||
return ethers.keccak256(ethers.toUtf8Bytes(fallbackData));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Проверяет балансы в указанных сетях
|
||||
* @param {number[]} chainIds - Массив chainId для проверки
|
||||
* @param {string} privateKey - Приватный ключ
|
||||
* @returns {Promise<Object>} - Результат проверки балансов
|
||||
*/
|
||||
async checkBalances(chainIds, privateKey) {
|
||||
const { getRpcUrlByChainId } = require('./rpcProviderService');
|
||||
const { ethers } = require('ethers');
|
||||
const results = [];
|
||||
const balances = [];
|
||||
const insufficient = [];
|
||||
const normalizedPk = privateKey?.startsWith('0x') ? privateKey : `0x${privateKey}`;
|
||||
for (const cid of chainIds || []) {
|
||||
const rpcUrl = await getRpcUrlByChainId(cid);
|
||||
if (!rpcUrl) {
|
||||
results.push({ chainId: cid, balanceEth: '0', ok: false, rpcUrl: null });
|
||||
insufficient.push(cid);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (const chainId of chainIds) {
|
||||
try {
|
||||
const rpcUrl = await getRpcUrlByChainId(chainId);
|
||||
if (!rpcUrl) {
|
||||
balances.push({
|
||||
chainId,
|
||||
balanceEth: '0',
|
||||
ok: false,
|
||||
error: 'RPC URL не найден'
|
||||
});
|
||||
insufficient.push(chainId);
|
||||
continue;
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const wallet = new ethers.Wallet(normalizedPk, provider);
|
||||
const bal = await provider.getBalance(wallet.address);
|
||||
// Минимум для деплоя; можно скорректировать
|
||||
const min = ethers.parseEther('0.002');
|
||||
const ok = bal >= min;
|
||||
results.push({ chainId: cid, balanceEth: ethers.formatEther(bal), ok, rpcUrl });
|
||||
if (!ok) insufficient.push(cid);
|
||||
} catch (e) {
|
||||
results.push({ chainId: cid, balanceEth: '0', ok: false, rpcUrl });
|
||||
insufficient.push(cid);
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
const balance = await provider.getBalance(wallet.address);
|
||||
|
||||
if (typeof ethers.formatEther !== 'function') {
|
||||
throw new Error('Метод ethers.formatEther не найден');
|
||||
}
|
||||
const balanceEth = ethers.formatEther(balance);
|
||||
|
||||
if (typeof ethers.parseEther !== 'function') {
|
||||
throw new Error('Метод ethers.parseEther не найден');
|
||||
}
|
||||
const minBalance = ethers.parseEther("0.001");
|
||||
const ok = balance >= minBalance;
|
||||
|
||||
balances.push({
|
||||
chainId,
|
||||
address: wallet.address,
|
||||
balanceEth,
|
||||
ok
|
||||
});
|
||||
|
||||
if (!ok) {
|
||||
insufficient.push(chainId);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
balances.push({
|
||||
chainId,
|
||||
balanceEth: '0',
|
||||
ok: false,
|
||||
error: error.message
|
||||
});
|
||||
insufficient.push(chainId);
|
||||
}
|
||||
}
|
||||
return { balances: results, insufficient };
|
||||
|
||||
return {
|
||||
balances,
|
||||
insufficient,
|
||||
allSufficient: insufficient.length === 0
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,7 +1133,7 @@ class DLEV2Service {
|
||||
}
|
||||
|
||||
// 2) Посчитать ABI-код аргументов конструктора через сравнение с bytecode
|
||||
// Конструктор: (dleConfig, currentChainId)
|
||||
// Конструктор: (dleConfig, currentChainId, initializer)
|
||||
const Factory = await hre.ethers.getContractFactory('DLE');
|
||||
const dleConfig = {
|
||||
name: params.name,
|
||||
@@ -739,7 +1148,8 @@ class DLEV2Service {
|
||||
initialAmounts: params.initialAmounts,
|
||||
supportedChainIds: params.supportedChainIds
|
||||
};
|
||||
const deployTx = await Factory.getDeployTransaction(dleConfig, params.currentChainId);
|
||||
const initializer = params.initialPartners?.[0] || "0x0000000000000000000000000000000000000000";
|
||||
const deployTx = await Factory.getDeployTransaction(dleConfig, params.currentChainId, initializer);
|
||||
const fullData = deployTx.data; // 0x + creation bytecode + encoded args
|
||||
const bytecode = Factory.bytecode; // 0x + creation bytecode
|
||||
let constructorArgsHex;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ function computeCreate2Address(factory, saltHex, initCodeHash) {
|
||||
saltHex.toLowerCase(),
|
||||
initCodeHash.toLowerCase()
|
||||
].map(x => x.startsWith('0x') ? x.slice(2) : x).join('');
|
||||
const hash = '0x' + require('crypto').createHash('sha3-256').update(Buffer.from(parts, 'hex')).digest('hex');
|
||||
const hash = keccak256('0x' + parts);
|
||||
return '0x' + hash.slice(-40);
|
||||
}
|
||||
|
||||
|
||||
@@ -2013,7 +2013,7 @@ cli-boxes@^2.2.1:
|
||||
resolved "https://registry.yarnpkg.com/cli-boxes/-/cli-boxes-2.2.1.tgz#ddd5035d25094fce220e9cab40a45840a440318f"
|
||||
integrity sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==
|
||||
|
||||
cli-table3@^0.6.3:
|
||||
cli-table3@^0.6.0, cli-table3@^0.6.3:
|
||||
version "0.6.5"
|
||||
resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.6.5.tgz#013b91351762739c16a9567c21a04632e449bf2f"
|
||||
integrity sha512-+W/5efTR7y5HRD7gACw9yQjqMVvEMLBHmboM/kPWam+H+Hmyrgjh6YncVKK122YZkXrLudzTuAukUw9FnMf7IQ==
|
||||
@@ -3565,6 +3565,15 @@ handlebars@^4.0.1:
|
||||
optionalDependencies:
|
||||
uglify-js "^3.1.4"
|
||||
|
||||
hardhat-contract-sizer@^2.10.1:
|
||||
version "2.10.1"
|
||||
resolved "https://registry.yarnpkg.com/hardhat-contract-sizer/-/hardhat-contract-sizer-2.10.1.tgz#125092f9398105d0d23001056aac61c936ad841a"
|
||||
integrity sha512-/PPQQbUMgW6ERzk8M0/DA8/v2TEM9xRRAnF9qKPNMYF6FX5DFWcnxBsQvtp8uBz+vy7rmLyV9Elti2wmmhgkbg==
|
||||
dependencies:
|
||||
chalk "^4.0.0"
|
||||
cli-table3 "^0.6.0"
|
||||
strip-ansi "^6.0.0"
|
||||
|
||||
hardhat-gas-reporter@^2.2.2:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/hardhat-gas-reporter/-/hardhat-gas-reporter-2.3.0.tgz#8605131a9130925b2f19a77576f93a637a2911d8"
|
||||
@@ -6059,7 +6068,7 @@ solc@0.8.26:
|
||||
semver "^5.5.0"
|
||||
tmp "0.0.33"
|
||||
|
||||
solidity-coverage@^0.8.1:
|
||||
solidity-coverage@^0.8.16:
|
||||
version "0.8.16"
|
||||
resolved "https://registry.yarnpkg.com/solidity-coverage/-/solidity-coverage-0.8.16.tgz#ae07bb11ebbd78d488c7e1a3cd15b8210692f1c9"
|
||||
integrity sha512-qKqgm8TPpcnCK0HCDLJrjbOA2tQNEJY4dHX/LSSQ9iwYFS973MwjtgYn2Iv3vfCEQJTj5xtm4cuUMzlJsJSMbg==
|
||||
|
||||
Reference in New Issue
Block a user