首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对调用进行编码以在智能契约中部署代理?

如何对调用进行编码以在智能契约中部署代理?
EN

Ethereum用户
提问于 2022-12-28 12:04:05
回答 1查看 99关注 0票数 0

hardhat中,我使用以下脚本部署了一个可升级的智能契约:

代码语言:javascript
复制
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函数之外,它还使用了一个构造函数参数。

我如何在智能契约中复制这种行为?这是我的代码,我不知道在哪里添加构造函数参数:

代码语言:javascript
复制
   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);
    }
EN

回答 1

Ethereum用户

回答已采纳

发布于 2023-03-01 03:48:53

这是我最后使用的最后一段代码,它可以工作:

// SPDX-许可证-标识符: MIT实用主义稳固性^0.8.0;

代码语言:javascript
复制
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));
    }
}
票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/141976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档