在hardhat中,我使用以下脚本部署了一个可升级的智能契约:
const v1contract = await upgrades.deployProxy(
V1contract,
[
"0xF8e6A72C0e72E0Eb510bD20097b0522Eae4B24E4", // _defaultAdmin
"Smart NFT", // _name
"SNFT", // _symbol
"My Smart Wallet", // _contractURI
[], // _trustedForwarders
"0xF8e6A72C0e72E0Eb510bD20097b0522Eae4B24E4", // _royaltyRecipient
0 // _royaltyBps */
], {
gasPrice: gas,
initializer: "initialize",
kind: "uups",
constructorArgs: ["0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889"]
});如您所见,除了initialize函数之外,它还使用了一个构造函数参数。
我如何在智能契约中复制这种行为?这是我的代码,我不知道在哪里添加构造函数参数:
function createSmartWallet(
uint256 _smartWalletId,
address _defaultAdmin,
string memory _name,
string memory _symbol,
string memory _contractURI,
address[] memory _trustedForwarders,
address _royaltyRecipient,
uint256 _royaltyBps
) public {
SmartWalletProxy smartWallet = new SmartWalletProxy(address(proxy), address(this), abi.encodeCall(SmartWallet(payable(address(0))).initialize, (_defaultAdmin, _name, _symbol, _contractURI, _trustedForwarders, _royaltyRecipient, _royaltyBps)));
smartWallets[_smartWalletId] = address(smartWallet);
}发布于 2023-03-01 03:48:53
这是我最后使用的最后一段代码,它可以工作:
// SPDX-许可证-标识符: MIT实用主义稳固性^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/CountersUpgradeable.sol";
import "../proxy/SmartVaultProxy.sol";
import "../vault/SmartVault.sol";
contract SmartVaultFactory is Initializable, OwnableUpgradeable {
using CountersUpgradeable for CountersUpgradeable.Counter;
mapping(uint256 => address) private smartVaults;
mapping(address => address[]) private smartVaultsPerUser;
CountersUpgradeable.Counter private counter;
string private version;
address implementation;
address private feeAddress;
uint256 private fullyAllocatedFee;
uint256 private coAllocatedFee;
function initialize(address _smartVault, address _feeAddress, uint256 _fullyAllocatedFee, uint256 _coAllocatedFee, string memory _version) public initializer {
__Ownable_init();
version = _version;
fullyAllocatedFee = _fullyAllocatedFee;
coAllocatedFee = _coAllocatedFee;
implementation = _smartVault;
feeAddress = _feeAddress;
}
function versionContract() public view returns (string memory) {
return version;
}
function createSmartVault(
string memory _name,
string memory _symbol,
bool _coAllocated
) public payable collectFee(_coAllocated) {
SmartVaultProxy newSmartVault = new SmartVaultProxy(address(implementation), abi.encodeWithSelector(SmartVault(payable(address(0))).initialize.selector, msg.sender, _name, _symbol, _coAllocated));
uint256 currentCounter = counter.current();
smartVaults[currentCounter] = address(newSmartVault);
counter.increment();
smartVaultsPerUser[msg.sender].push(address(newSmartVault));
}
}https://ethereum.stackexchange.com/questions/141976
复制相似问题