From c5d959921595e266d7de515c7a68c89336532caa Mon Sep 17 00:00:00 2001 From: 0xakame Date: Tue, 17 Dec 2024 01:07:35 +0800 Subject: [PATCH] remove unused imports, optimize gas consumptions --- contracts/AgentInference.sol | 10 +++++----- contracts/AgentRewardV3.sol | 6 ------ contracts/contribution/ContributionNft.sol | 3 --- contracts/contribution/ServiceNft.sol | 2 -- contracts/fun/Bonding.sol | 1 - contracts/tax/BondingTax.sol | 2 -- contracts/virtualPersona/AgentDAO.sol | 1 - contracts/virtualPersona/AgentFactory.sol | 1 - contracts/virtualPersona/AgentFactoryV3.sol | 1 - contracts/virtualPersona/AgentFactoryV4.sol | 1 - contracts/virtualPersona/AgentNftV2.sol | 1 - contracts/virtualPersona/AgentToken.sol | 1 - contracts/virtualPersona/EloCalculator.sol | 1 - 13 files changed, 5 insertions(+), 26 deletions(-) diff --git a/contracts/AgentInference.sol b/contracts/AgentInference.sol index 81e1449..c8db65e 100644 --- a/contracts/AgentInference.sol +++ b/contracts/AgentInference.sol @@ -3,7 +3,6 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; @@ -61,13 +60,14 @@ contract AgentInference is "Invalid input" ); - for (uint256 i = 0; i < amounts.length; i++) { + uint256 len = amounts.length; + for (uint256 i = 0; i != len; ++i) { total += amounts[i]; } require(token.balanceOf(sender) >= total, "Insufficient balance"); - for (uint256 i = 0; i < agentIds.length; i++) { + for (uint256 i = 0; i != len; ++i) { uint256 agentId = agentIds[i]; address agentTba = agentNft.virtualInfo(agentId).tba; token.safeTransferFrom(sender, agentTba, amounts[i]); @@ -94,7 +94,7 @@ contract AgentInference is "Invalid input" ); - for (uint256 i = 0; i < len; i++) { + for (uint256 i = 0; i != len; ++i) { total += amounts[i]; } @@ -102,7 +102,7 @@ contract AgentInference is uint256 prevAgentId = 0; address agentTba = address(0); - for (uint256 i = 0; i < len; i++) { + for (uint256 i = 0; i != len; ++i) { uint256 agentId = agentIds[i]; if (prevAgentId != agentId) { agentTba = agentNft.virtualInfo(agentId).tba; diff --git a/contracts/AgentRewardV3.sol b/contracts/AgentRewardV3.sol index 2c893af..b60c9f0 100644 --- a/contracts/AgentRewardV3.sol +++ b/contracts/AgentRewardV3.sol @@ -2,20 +2,14 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; -import "@openzeppelin/contracts/utils/math/Math.sol"; -import {IERC5805} from "@openzeppelin/contracts/interfaces/IERC5805.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import "./virtualPersona/IAgentNft.sol"; -import "./virtualPersona/IAgentToken.sol"; import "./virtualPersona/IAgentDAO.sol"; import "./virtualPersona/IAgentVeToken.sol"; import "./libs/RewardSettingsCheckpointsV2.sol"; -import "./contribution/IContributionNft.sol"; -import "./contribution/IServiceNft.sol"; import "./libs/TokenSaver.sol"; import "./IAgentRewardV3.sol"; diff --git a/contracts/contribution/ContributionNft.sol b/contracts/contribution/ContributionNft.sol index 92cf705..0f3a8a6 100644 --- a/contracts/contribution/ContributionNft.sol +++ b/contracts/contribution/ContributionNft.sol @@ -1,12 +1,9 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; -import "@openzeppelin/contracts/access/AccessControl.sol"; -import "@openzeppelin/contracts/interfaces/IERC5805.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "./IContributionNft.sol"; import "../virtualPersona/IAgentNft.sol"; diff --git a/contracts/contribution/ServiceNft.sol b/contracts/contribution/ServiceNft.sol index e40aeaa..a2c2216 100644 --- a/contracts/contribution/ServiceNft.sol +++ b/contracts/contribution/ServiceNft.sol @@ -2,12 +2,10 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/governance/IGovernor.sol"; -import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721EnumerableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; -import "@openzeppelin/contracts/interfaces/IERC5805.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "../virtualPersona/IAgentNft.sol"; import "../virtualPersona/IAgentDAO.sol"; diff --git a/contracts/fun/Bonding.sol b/contracts/fun/Bonding.sol index 466ba0e..049547c 100644 --- a/contracts/fun/Bonding.sol +++ b/contracts/fun/Bonding.sol @@ -2,7 +2,6 @@ // Modified from https://github.com/sourlodine/Pump.fun-Smart-Contract/blob/main/contracts/PumpFun.sol pragma solidity ^0.8.20; -import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; diff --git a/contracts/tax/BondingTax.sol b/contracts/tax/BondingTax.sol index 2e8e187..c37c805 100644 --- a/contracts/tax/BondingTax.sol +++ b/contracts/tax/BondingTax.sol @@ -3,10 +3,8 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; -import "@openzeppelin/contracts/utils/math/Math.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; -import "@openzeppelin/contracts/utils/math/Math.sol"; import "./IBondingTax.sol"; import "../pool/IRouter.sol"; diff --git a/contracts/virtualPersona/AgentDAO.sol b/contracts/virtualPersona/AgentDAO.sol index 02a6124..5909350 100644 --- a/contracts/virtualPersona/AgentDAO.sol +++ b/contracts/virtualPersona/AgentDAO.sol @@ -8,7 +8,6 @@ import "@openzeppelin/contracts/utils/structs/Checkpoints.sol"; import "./IAgentDAO.sol"; import "./GovernorCountingSimpleUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; -import "@openzeppelin/contracts/utils/Strings.sol"; import "../contribution/IContributionNft.sol"; import "./IEloCalculator.sol"; import "../contribution/IServiceNft.sol"; diff --git a/contracts/virtualPersona/AgentFactory.sol b/contracts/virtualPersona/AgentFactory.sol index 0dcbd9e..b7dfc0c 100644 --- a/contracts/virtualPersona/AgentFactory.sol +++ b/contracts/virtualPersona/AgentFactory.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/proxy/Clones.sol"; -import "@openzeppelin/contracts/governance/IGovernor.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; diff --git a/contracts/virtualPersona/AgentFactoryV3.sol b/contracts/virtualPersona/AgentFactoryV3.sol index b8b308e..0a19caa 100644 --- a/contracts/virtualPersona/AgentFactoryV3.sol +++ b/contracts/virtualPersona/AgentFactoryV3.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/proxy/Clones.sol"; -import "@openzeppelin/contracts/governance/IGovernor.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; diff --git a/contracts/virtualPersona/AgentFactoryV4.sol b/contracts/virtualPersona/AgentFactoryV4.sol index 7ff5cff..84b8f46 100644 --- a/contracts/virtualPersona/AgentFactoryV4.sol +++ b/contracts/virtualPersona/AgentFactoryV4.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.20; import "@openzeppelin/contracts/proxy/Clones.sol"; -import "@openzeppelin/contracts/governance/IGovernor.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; diff --git a/contracts/virtualPersona/AgentNftV2.sol b/contracts/virtualPersona/AgentNftV2.sol index 4b9e1ea..42cbb97 100644 --- a/contracts/virtualPersona/AgentNftV2.sol +++ b/contracts/virtualPersona/AgentNftV2.sol @@ -8,7 +8,6 @@ import "@openzeppelin/contracts-upgradeable/token/ERC721/ERC721Upgradeable.sol"; import "@openzeppelin/contracts-upgradeable/token/ERC721/extensions/ERC721URIStorageUpgradeable.sol"; import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; -import "@openzeppelin/contracts/interfaces/IERC5805.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "./IAgentNft.sol"; import "./CoreRegistry.sol"; diff --git a/contracts/virtualPersona/AgentToken.sol b/contracts/virtualPersona/AgentToken.sol index d8fc016..5591534 100644 --- a/contracts/virtualPersona/AgentToken.sol +++ b/contracts/virtualPersona/AgentToken.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol"; import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; diff --git a/contracts/virtualPersona/EloCalculator.sol b/contracts/virtualPersona/EloCalculator.sol index dcc61d0..3ff0c4d 100644 --- a/contracts/virtualPersona/EloCalculator.sol +++ b/contracts/virtualPersona/EloCalculator.sol @@ -1,7 +1,6 @@ // SPDX-License-Identifier: MIT pragma solidity ^0.8.20; -import "@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {Elo} from "../libs/Elo.sol";