feat: новая функция
This commit is contained in:
@@ -54,7 +54,7 @@ router.post('/read-dle-info', async (req, res) => {
|
||||
if (!rpcUrl) {
|
||||
return res.status(500).json({ success: false, error: `RPC URL для сети ${targetChainId} не найден` });
|
||||
}
|
||||
provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const code = await provider.getCode(dleAddress);
|
||||
if (!code || code === '0x') {
|
||||
return res.status(400).json({ success: false, error: `По адресу ${dleAddress} нет контракта в сети ${targetChainId}` });
|
||||
@@ -358,7 +358,7 @@ router.post('/get-proposals', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для чтения предложений (используем правильные функции из смарт-контракта)
|
||||
const dleAbi = [
|
||||
@@ -520,7 +520,7 @@ router.post('/get-proposal-info', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для чтения информации о предложении
|
||||
const dleAbi = [
|
||||
@@ -614,7 +614,7 @@ router.post('/deactivate-dle', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для проверки деактивации DLE
|
||||
const dleAbi = [
|
||||
@@ -707,7 +707,7 @@ router.post('/check-deactivation-proposal-result', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function checkDeactivationProposalResult(uint256 _proposalId) public view returns (bool passed, bool quorumReached)"
|
||||
@@ -785,7 +785,7 @@ router.post('/load-deactivation-proposals', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function deactivationProposalCounter() external view returns (uint256)",
|
||||
@@ -889,7 +889,7 @@ router.post('/execute-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
|
||||
const dleAbi = [
|
||||
@@ -965,7 +965,7 @@ router.post('/cancel-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function cancelProposal(uint256 _proposalId, string calldata reason) external"
|
||||
@@ -1050,7 +1050,7 @@ router.post('/get-governance-params', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getGovernanceParams() external view returns (uint256 quorumPct, uint256 chainId, uint256 supportedCount)"
|
||||
@@ -1126,7 +1126,7 @@ router.post('/get-proposal-state', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalState(uint256 _proposalId) public view returns (uint8 state)"
|
||||
@@ -1201,7 +1201,7 @@ router.post('/get-proposal-votes', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalVotes(uint256 _proposalId) external view returns (uint256 forVotes, uint256 againstVotes, uint256 totalVotes, uint256 quorumRequired)"
|
||||
@@ -1279,7 +1279,7 @@ router.post('/get-proposals-count', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalsCount() external view returns (uint256)"
|
||||
@@ -1353,7 +1353,7 @@ router.post('/list-proposals', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function listProposals(uint256 offset, uint256 limit) external view returns (uint256[] memory)"
|
||||
@@ -1429,7 +1429,7 @@ router.post('/get-voting-power-at', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getVotingPowerAt(address voter, uint256 timepoint) external view returns (uint256)"
|
||||
@@ -1505,7 +1505,7 @@ router.post('/get-quorum-at', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getQuorumAt(uint256 timepoint) external view returns (uint256)"
|
||||
@@ -1580,7 +1580,7 @@ router.post('/get-token-balance', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function balanceOf(address account) external view returns (uint256)"
|
||||
@@ -1655,7 +1655,7 @@ router.post('/get-total-supply', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function totalSupply() external view returns (uint256)"
|
||||
@@ -1729,7 +1729,7 @@ router.post('/is-active', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function isActive() external view returns (bool)"
|
||||
@@ -1809,7 +1809,7 @@ router.post('/get-dle-analytics', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function totalSupply() external view returns (uint256)",
|
||||
@@ -1956,7 +1956,7 @@ router.post('/get-dle-history', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalsCount() external view returns (uint256)",
|
||||
|
||||
@@ -72,7 +72,7 @@ router.post('/get-dle-analytics', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function totalSupply() external view returns (uint256)",
|
||||
@@ -242,7 +242,7 @@ router.post('/get-dle-history', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalsCount() external view returns (uint256)",
|
||||
|
||||
@@ -63,7 +63,7 @@ router.post('/read-dle-info', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для чтения данных DLE
|
||||
const dleAbi = [
|
||||
@@ -254,7 +254,7 @@ router.post('/get-governance-params', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getGovernanceParams() external view returns (uint256 quorumPct, uint256 chainId, uint256 supportedCount)"
|
||||
@@ -323,7 +323,7 @@ router.post('/is-active', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function isActive() external view returns (bool)"
|
||||
@@ -408,7 +408,7 @@ router.post('/deactivate-dle', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для проверки деактивации DLE
|
||||
const dleAbi = [
|
||||
|
||||
@@ -73,7 +73,7 @@ router.post('/get-extended-history', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
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))",
|
||||
|
||||
@@ -213,7 +213,7 @@ router.post('/is-module-active', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function isModuleActive(bytes32 _moduleId) external view returns (bool)"
|
||||
@@ -296,7 +296,7 @@ router.post('/get-module-address', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getModuleAddress(bytes32 _moduleId) external view returns (address)"
|
||||
@@ -348,7 +348,13 @@ router.post('/prepare-initialize-modules-all-networks', async (req, res) => {
|
||||
const results = [];
|
||||
for (const network of supportedNetworks) {
|
||||
try {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
// Получаем RPC URL из базы данных
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(network.chainId);
|
||||
if (!rpcUrl) {
|
||||
console.warn(`[DLE Modules] RPC URL не найден для chainId ${network.chainId}`);
|
||||
continue;
|
||||
}
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dle = new ethers.Contract(
|
||||
dleAddress,
|
||||
[
|
||||
@@ -576,14 +582,16 @@ router.post('/get-all-modules', async (req, res) => {
|
||||
return networks[chainId] || `Chain ${chainId}`;
|
||||
}
|
||||
|
||||
function getFallbackRpcUrl(chainId) {
|
||||
const fallbackUrls = {
|
||||
11155111: process.env.SEPOLIA_RPC_URL || 'https://eth-sepolia.nodereal.io/v1/YOUR_NODEREAL_KEY',
|
||||
17000: 'https://ethereum-holesky.publicnode.com',
|
||||
421614: 'https://sepolia-rollup.arbitrum.io/rpc',
|
||||
84532: 'https://sepolia.base.org'
|
||||
};
|
||||
return fallbackUrls[chainId] || null;
|
||||
async function getFallbackRpcUrl(chainId) {
|
||||
try {
|
||||
// Получаем RPC URL из базы данных
|
||||
const rpcService = require('../services/rpcProviderService');
|
||||
const rpcUrl = await rpcService.getRpcUrlByChainId(chainId);
|
||||
return rpcUrl;
|
||||
} catch (error) {
|
||||
console.error(`[DLE Modules] Ошибка получения RPC из базы данных для chain_id ${chainId}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getEtherscanUrl(chainId) {
|
||||
@@ -621,48 +629,19 @@ router.post('/get-all-modules', async (req, res) => {
|
||||
const supportedChainIds = params.supportedChainIds || [];
|
||||
const rpcUrls = params.rpcUrls || params.rpc_urls || {};
|
||||
|
||||
supportedNetworks = supportedChainIds.map((chainId, index) => ({
|
||||
supportedNetworks = await Promise.all(supportedChainIds.map(async (chainId, index) => ({
|
||||
chainId: Number(chainId),
|
||||
networkName: getNetworkName(Number(chainId)),
|
||||
rpcUrl: rpcUrls[chainId] || getFallbackRpcUrl(chainId),
|
||||
rpcUrl: rpcUrls[chainId] || await getFallbackRpcUrl(chainId),
|
||||
etherscanUrl: getEtherscanUrl(chainId),
|
||||
networkIndex: index
|
||||
}));
|
||||
})));
|
||||
}
|
||||
await deployParamsService.close();
|
||||
} catch (error) {
|
||||
console.error('❌ Ошибка получения параметров деплоя:', error);
|
||||
// Fallback для совместимости
|
||||
supportedNetworks = [
|
||||
{
|
||||
chainId: 11155111,
|
||||
networkName: 'Sepolia',
|
||||
rpcUrl: process.env.SEPOLIA_RPC_URL || 'https://eth-sepolia.nodereal.io/v1/YOUR_NODEREAL_KEY',
|
||||
etherscanUrl: 'https://sepolia.etherscan.io',
|
||||
networkIndex: 0
|
||||
},
|
||||
{
|
||||
chainId: 17000,
|
||||
networkName: 'Holesky',
|
||||
rpcUrl: 'https://ethereum-holesky.publicnode.com',
|
||||
etherscanUrl: 'https://holesky.etherscan.io',
|
||||
networkIndex: 1
|
||||
},
|
||||
{
|
||||
chainId: 421614,
|
||||
networkName: 'Arbitrum Sepolia',
|
||||
rpcUrl: 'https://sepolia-rollup.arbitrum.io/rpc',
|
||||
etherscanUrl: 'https://sepolia.arbiscan.io',
|
||||
networkIndex: 2
|
||||
},
|
||||
{
|
||||
chainId: 84532,
|
||||
networkName: 'Base Sepolia',
|
||||
rpcUrl: 'https://sepolia.base.org',
|
||||
etherscanUrl: 'https://sepolia.basescan.org',
|
||||
networkIndex: 3
|
||||
}
|
||||
];
|
||||
// НЕ показываем fallback цепочки - только те, что выбрал пользователь
|
||||
supportedNetworks = [];
|
||||
}
|
||||
|
||||
res.json({
|
||||
@@ -754,7 +733,7 @@ router.post('/create-add-module-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Получаем приватный ключ из параметров деплоя
|
||||
let privateKey;
|
||||
@@ -1003,7 +982,7 @@ router.post('/create-remove-module-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function createRemoveModuleProposal(string memory _description, uint256 _duration, bytes32 _moduleId, uint256 _chainId) external returns (uint256)"
|
||||
@@ -1276,7 +1255,7 @@ router.post('/verify-module', async (req, res) => {
|
||||
|
||||
// Получаем ABI и bytecode для модуля
|
||||
const { ethers } = require('ethers');
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Получаем код контракта для проверки существования
|
||||
const code = await provider.getCode(moduleAddress);
|
||||
@@ -1389,7 +1368,11 @@ router.post('/check-modules-status', async (req, res) => {
|
||||
|
||||
// Проверяем первую доступную сеть
|
||||
const network = supportedNetworks[0];
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(network.chainId);
|
||||
if (!rpcUrl) {
|
||||
return res.status(400).json({ success: false, message: `RPC URL не найден для chainId ${network.chainId}` });
|
||||
}
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function initializer() external view returns (address)",
|
||||
@@ -1603,7 +1586,12 @@ router.post('/initialize-modules-all-networks', async (req, res) => {
|
||||
console.log(`[DLE Modules] Инициализация модулей в сети: ${network.networkName} (${network.chainId})`);
|
||||
|
||||
try {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(network.chainId);
|
||||
if (!rpcUrl) {
|
||||
console.warn(`[DLE Modules] RPC URL не найден для chainId ${network.chainId}`);
|
||||
continue;
|
||||
}
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
const dle = new ethers.Contract(dleAddress, dleAbi, wallet);
|
||||
|
||||
@@ -1723,7 +1711,12 @@ router.post('/verify-modules-all-networks', async (req, res) => {
|
||||
};
|
||||
|
||||
try {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(network.chainId);
|
||||
if (!rpcUrl) {
|
||||
console.warn(`[DLE Modules] RPC URL не найден для chainId ${network.chainId}`);
|
||||
continue;
|
||||
}
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dle = new ethers.Contract(dleAddress, dleAbi, provider);
|
||||
|
||||
for (const [moduleKey, moduleId] of Object.entries(moduleIds)) {
|
||||
@@ -1892,7 +1885,7 @@ router.post('/check-dle-deployment-status', async (req, res) => {
|
||||
throw new Error(`RPC URL не найден для сети ${chainId}`);
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Проверяем, что контракт существует и имеет код
|
||||
const code = await provider.getCode(dleAddress);
|
||||
@@ -2019,7 +2012,7 @@ router.post('/check-module-deployment-status', async (req, res) => {
|
||||
throw new Error(`RPC URL не найден для сети ${chainId}`);
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getModuleAddress(bytes32 _moduleId) external view returns (address)",
|
||||
@@ -2179,7 +2172,7 @@ router.post('/deploy-module-all-networks', async (req, res) => {
|
||||
try {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(network.chainId));
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
|
||||
// Используем NonceManager для правильного управления nonce
|
||||
@@ -2558,7 +2551,7 @@ router.post('/verify-module-all-networks', async (req, res) => {
|
||||
try {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(network.chainId));
|
||||
const dle = new ethers.Contract(dleAddress, [
|
||||
"function getModuleAddress(bytes32 _moduleId) external view returns (address)"
|
||||
], provider);
|
||||
@@ -2698,7 +2691,7 @@ router.post('/initialize-module-all-networks', async (req, res) => {
|
||||
try {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const provider = new ethers.JsonRpcProvider(network.rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(network.chainId));
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
|
||||
const dleAbi = [
|
||||
@@ -2826,7 +2819,7 @@ router.post('/final-deployment-check', async (req, res) => {
|
||||
throw new Error(`RPC URL не найден для сети ${chainId}`);
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function name() external view returns (string)",
|
||||
@@ -3025,7 +3018,7 @@ router.post('/get-deployment-status', async (req, res) => {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(supportedNetworks[0].chainId);
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dleCode = await provider.getCode(dleAddress);
|
||||
return dleCode !== '0x';
|
||||
},
|
||||
@@ -3045,7 +3038,7 @@ router.post('/get-deployment-status', async (req, res) => {
|
||||
const verificationResult = await executeWithRetries(
|
||||
async () => {
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(supportedNetworks[0].chainId);
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
// Простая проверка - если код контракта не пустой, считаем верифицированным
|
||||
const code = await provider.getCode(dleAddress);
|
||||
return code !== '0x' && code.length > 2;
|
||||
@@ -3102,7 +3095,7 @@ router.post('/get-deployment-status', async (req, res) => {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(supportedNetworks[0].chainId);
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dle = new ethers.Contract(dleAddress, [
|
||||
"function getModuleAddress(bytes32 _moduleId) external view returns (address)",
|
||||
"function isModuleActive(bytes32 _moduleId) external view returns (bool)"
|
||||
@@ -3129,7 +3122,7 @@ router.post('/get-deployment-status', async (req, res) => {
|
||||
const verificationResult = await executeWithRetries(
|
||||
async () => {
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(supportedNetworks[0].chainId);
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const moduleCode = await provider.getCode(moduleAddress);
|
||||
return moduleCode !== '0x';
|
||||
},
|
||||
@@ -3168,7 +3161,7 @@ router.post('/get-deployment-status', async (req, res) => {
|
||||
const result = await executeWithRetries(
|
||||
async () => {
|
||||
const rpcUrl = await rpcProviderService.getRpcUrlByChainId(supportedNetworks[0].chainId);
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dle = new ethers.Contract(dleAddress, [
|
||||
], provider);
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ router.post('/get-multichain-contracts', async (req, res) => {
|
||||
// Если не найден в параметрах, используем fallback
|
||||
if (!rpcUrl) {
|
||||
const fallbackConfigs = {
|
||||
'11155111': 'https://1rpc.io/sepolia',
|
||||
'17000': 'https://ethereum-holesky.publicnode.com',
|
||||
'421614': 'https://sepolia-rollup.arbitrum.io/rpc',
|
||||
'84532': 'https://sepolia.base.org'
|
||||
'11155111': null,
|
||||
'17000': null,
|
||||
'421614': null,
|
||||
'84532': null
|
||||
};
|
||||
rpcUrl = fallbackConfigs[targetChainId];
|
||||
}
|
||||
@@ -86,7 +86,7 @@ router.post('/get-multichain-contracts', async (req, res) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const contractCode = await provider.getCode(originalContract);
|
||||
|
||||
if (contractCode && contractCode !== '0x') {
|
||||
|
||||
@@ -42,7 +42,7 @@ router.post('/get-proposal-multichain-info', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"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, uint256[] memory targetChains)",
|
||||
@@ -294,7 +294,7 @@ async function executeProposalInChain(dleAddress, proposalId, chainId, privateKe
|
||||
throw new Error(`RPC URL для сети ${chainId} не найден`);
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const wallet = new ethers.Wallet(privateKey, provider);
|
||||
|
||||
const dleAbi = [
|
||||
|
||||
@@ -60,7 +60,7 @@ router.post('/get-proposals', async (req, res) => {
|
||||
return;
|
||||
}
|
||||
if (rpcUrl) {
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
const dleAbi = [
|
||||
"function getSupportedChainCount() external view returns (uint256)",
|
||||
"function getSupportedChainId(uint256 _index) external view returns (uint256)"
|
||||
@@ -97,7 +97,7 @@ router.post('/get-proposals', async (req, res) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для чтения предложений (используем getProposalSummary для мультиконтрактов)
|
||||
const dleAbi = [
|
||||
@@ -369,7 +369,7 @@ router.post('/get-proposal-info', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// ABI для чтения информации о предложении
|
||||
const dleAbi = [
|
||||
@@ -447,7 +447,7 @@ router.post('/get-proposal-state', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalState(uint256 _proposalId) public view returns (uint8 state)"
|
||||
@@ -499,7 +499,7 @@ router.post('/get-proposal-votes', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function checkProposalResult(uint256 _proposalId) external view returns (bool passed, bool quorumReached)",
|
||||
@@ -560,7 +560,7 @@ router.post('/get-proposals-count', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalsCount() external view returns (uint256)"
|
||||
@@ -611,7 +611,7 @@ router.post('/list-proposals', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function listProposals(uint256 offset, uint256 limit) external view returns (uint256[] memory)"
|
||||
@@ -664,7 +664,7 @@ router.post('/get-voting-power-at', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getVotingPowerAt(address voter, uint256 timepoint) external view returns (uint256)"
|
||||
@@ -717,7 +717,7 @@ router.post('/get-quorum-at', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getQuorumAt(uint256 timepoint) external view returns (uint256)"
|
||||
@@ -772,7 +772,7 @@ router.post('/execute-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function executeProposal(uint256 _proposalId) external"
|
||||
@@ -827,7 +827,7 @@ router.post('/cancel-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function cancelProposal(uint256 _proposalId, string calldata reason) external"
|
||||
@@ -879,7 +879,7 @@ router.post('/get-proposals-count', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function getProposalsCount() external view returns (uint256)"
|
||||
@@ -929,7 +929,7 @@ router.post('/list-proposals', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function listProposals(uint256 offset, uint256 limit) external view returns (uint256[] memory)",
|
||||
@@ -1030,7 +1030,7 @@ router.post('/vote-proposal', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function vote(uint256 _proposalId, bool _support) external"
|
||||
@@ -1088,7 +1088,7 @@ router.post('/check-vote-status', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Функция hasVoted не существует в контракте DLE
|
||||
console.log(`[DLE Proposals] Функция hasVoted не поддерживается в контракте DLE`);
|
||||
@@ -1135,7 +1135,7 @@ router.post('/track-vote-transaction', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Ждем подтверждения транзакции
|
||||
const receipt = await provider.waitForTransaction(txHash, 1, 60000); // 60 секунд таймаут
|
||||
@@ -1193,7 +1193,7 @@ router.post('/track-execution-transaction', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Ждем подтверждения транзакции
|
||||
const receipt = await provider.waitForTransaction(txHash, 1, 60000); // 60 секунд таймаут
|
||||
@@ -1252,7 +1252,7 @@ router.post('/decode-proposal-data', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
// Получаем данные транзакции
|
||||
const tx = await provider.getTransaction(transactionHash);
|
||||
|
||||
@@ -72,7 +72,7 @@ router.post('/get-token-balance', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function balanceOf(address account) external view returns (uint256)"
|
||||
@@ -158,7 +158,7 @@ router.post('/get-total-supply', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function totalSupply() external view returns (uint256)"
|
||||
@@ -243,7 +243,7 @@ router.post('/get-token-holders', async (req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
||||
const provider = new ethers.JsonRpcProvider(await rpcProviderService.getRpcUrlByChainId(chainId));
|
||||
|
||||
const dleAbi = [
|
||||
"function totalSupply() external view returns (uint256)",
|
||||
|
||||
@@ -17,9 +17,23 @@ 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);
|
||||
async function getMainnetProvider() {
|
||||
try {
|
||||
// Получаем RPC URL из базы данных для mainnet (chain_id = 1)
|
||||
const rpcService = require('../services/rpcProviderService');
|
||||
const rpcUrl = await rpcService.getRpcUrlByChainId(1);
|
||||
|
||||
if (!rpcUrl) {
|
||||
throw new Error('RPC URL для mainnet не найден в базе данных');
|
||||
}
|
||||
|
||||
console.log(`[ENS] Используем RPC из базы данных: ${rpcUrl}`);
|
||||
return new ethers.JsonRpcProvider(await rpcService.getRpcUrlByChainId(1));
|
||||
|
||||
} catch (error) {
|
||||
console.error(`[ENS] Ошибка получения RPC из базы данных:`, error);
|
||||
throw new Error(`Не удалось получить RPC провайдер: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// GET /api/ens/avatar?name=vc-hb3-accelerator.eth
|
||||
@@ -29,7 +43,7 @@ router.get('/avatar', async (req, res) => {
|
||||
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 provider = await getMainnetProvider();
|
||||
const url = await provider.getAvatar(name);
|
||||
return res.json({ success: true, data: { url: url || null } });
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user