[英]Is there a way pre-deploy a library deployed from within a smart contract before it is deployed?
Sorry if the question did not make sense.对不起,如果这个问题没有意义。 Here is what I am trying to do: I want to deploy this smart contract (LenseHub) that imports a library that requires data passed to its constructor.
这是我想做的事情:我想部署这个智能合约(LenseHub),它导入一个需要将数据传递给其构造函数的库。 This is problematic because I need LenseHub to initialize the contract (a function I can call only after the contract is deployed).
这是有问题的,因为我需要 LenseHub 来初始化合约(一个 function 我只能在部署合约后调用)。 If I try to deploy LenseHub without pre-deploying the IERC721Enumerable it will fail obviously.
如果我尝试在没有预先部署 IERC721Enumerable 的情况下部署 LenseHub,它显然会失败。 If I can't figure this out I will just inherit IERC721Enumerable and initialize it via the constructor, but would really like to keep the original smart contracts integrity (for testing purposes).
如果我无法弄清楚这一点,我将只继承 IERC721Enumerable 并通过构造函数对其进行初始化,但我真的很想保持原始智能合约的完整性(用于测试目的)。 Any suggestions on how to do this would be greatly appreciated
任何有关如何做到这一点的建议将不胜感激
Here is the relevant part of the smart contract:以下是智能合约的相关部分:
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
/**
* @title LensHub
* @author Lens Protocol
*
* @notice This is the main entrypoint of the Lens Protocol. It contains governance functionality as well as
* publishing and profile interaction functionality.
*
* NOTE: The Lens Protocol is unique in that frontend operators need to track a potentially overwhelming
* number of NFT contracts and interactions at once. For that reason, we've made two quirky design decisions:
* 1. Both Follow & Collect NFTs invoke an LensHub callback on transfer with the sole purpose of emitting an event.
* 2. Almost every event in the protocol emits the current block timestamp, reducing the need to fetch it manually.
*
* OVERVIEW: The lense protocall is one of the three main solidity contracts compiled. It compiles all of its code imports code into
* one main "hub" from were you can interact with the protocall.
*
*
*/
contract LensHub is
LensNFTBase,
VersionedInitializable,
LensMultiState,
LensHubStorage,
ILensHub
{
uint256 internal constant REVISION = 1;
address internal immutable FOLLOW_NFT_IMPL;
address internal immutable COLLECT_NFT_IMPL;
/**
* @dev This modifier reverts if the caller is not the configured governance address.
*/
modifier onlyGov() {
_validateCallerIsGovernance();
_;
}
/**
* @dev The constructor sets the immutable follow & collect NFT implementations.
*
* @param followNFTImpl The follow NFT implementation address.
* @param collectNFTImpl The collect NFT implementation address.
*/
constructor(address followNFTImpl, address collectNFTImpl) {
if (followNFTImpl == address(0)) revert Errors.InitParamsInvalid();
if (collectNFTImpl == address(0)) revert Errors.InitParamsInvalid();
FOLLOW_NFT_IMPL = followNFTImpl;
COLLECT_NFT_IMPL = collectNFTImpl;
}
/// @inheritdoc ILensHub
function initialize(
string calldata name,
string calldata symbol,
address newGovernance
) external override initializer {
super._initialize(name, symbol);
_setState(DataTypes.ProtocolState.Paused);
_setGovernance(newGovernance);
}
Here is the _function that the initialize function calls:这是初始化 function 调用的 _function:
function _initialize(string calldata name, string calldata symbol) internal {
ERC721Time.__ERC721_Init(name, symbol);
emit Events.BaseInitialized(name, symbol, block.timestamp);
}
Here is the relevent part of the library:这是图书馆的相关部分:
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}
Here is the constructor of ERC721 that I am trying to pass variables to:这是我试图将变量传递给的 ERC721 的构造函数:
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
First of all, don't call the IERC721Enumerable a library - it is just an interface you want to implement in your contract.首先,不要将 IERC721Enumerable 称为库 - 它只是您要在合约中实现的接口。 In the context of solidity, a
library
has a bit different meaning.在solidity 的上下文中,
library
有一些不同的含义。 The question became misleading in the context of solidity.这个问题在稳固性的背景下变得具有误导性。
Secondly, what you want to achieve may be done in two ways - complicated but more correct and easy but less correct:其次,您想要实现的目标可以通过两种方式完成 - 复杂但更正确和容易但不太正确:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.