ChainLink的gentRegatorV3Interface.sol可以通过openzeppelin升级合同工作吗?
我放置
“ PriceFeed =
gentregatorv3interface(0x9326BFA02ADD2366B30BACB125260AF641031331);“
在“初始化器{}”内部?
我希望地址“ 0x9326bfa02add2222Add2222222366b30b30b30b366b30b30b30b30b30b30b bacb1b1252260af641410af641410af64141031331”
可以在智能合约的下一个版本中升级。
已经有一种方法了吗?
谢谢你!
动机&理由
我希望想要在新令牌的智能合同中“ getLatestPrice()”是有意义的。
在部署之前,无法了解新的令牌地址。
我想使用UPS代理模式下的OpenZeppelin可升级合同来更改地址。
在线上有任何示例要更新
PriceFeed =
gentregatorv3interface(0x9326BFA02ADD2366B30BACB125260AF641031331); //
kovan testnet
智能合约版本2上的
?谢谢你!
重要链接:
openzeppelin合同向导
使用Chainlink的gentlink的gentrink gentlink
部署UUP升级合同
我不知道如何在版本2上工作2版。 UUP升级合同。
在这里,我使用chainlink的gentregatorv3interface.sol卡住了,在OpenZeppelin Contracts Wizard上选择的每个功能:
// spdx-license-Identifier:MIT Pragma固体 ^0.8.4;
导入
“ ./@openzeppelin/contracts-upgradable/token/erc20/erc20/erc20upgradable.sol”;
导入” ./@openzeppelin/contracts-
可升级/令牌/ERC20/Extensions/erc20burnable -upgradable.sol”;
导入” ./@openzeppelin/contracts-
可升级/令牌/ERC20/Extensions/erc20snapshotupgradable.sol”;
进口
“ ./@openzeppelin/contracts-upgradable/access/ownableupgradable.sol”;
进口
“ ./@openzeppelin/contracts-upgradable/security/pausableupgradable.sol”;
进口
” ./@openzeppelin/contracts-upgradable/token/erc20/extensions/draft--
erc20 permitupgradable.sol“; import” ./@openzeppelin/contracts-
可升级/令牌/ERC20/Extensions/erc20votesupgradable.sol”;导入
“ ./@openzeppelin/contracts-
可升级/令牌/ERC20/Extensions/erc20flashmintupgroadupable.sol”;
进口
“ ./@openzeppelin/contracts-upgradable/proxy/utils/initializable.sol”;
进口
“ ./@ openzeppelin/Contracts-upgradable/proxy/utils/uupsupgradable.sol”;
导入
“@ChainLink/Contracts/src/v0.8/Interfaces/gentregatorv3interface.sol”;
合同uptoken是可初始化的,可ERC20Upgrad的,
ERC20burnable -uptable,ERC20SNAPSHOTUPGRADUPGRADEP,
可用的,可Pausable -upgradable,ERC20Permutupgradepradepther,
ERC20VOTESUPGRADABLE,ERC20FLASHMINTUPGRADABLE,UUPSUPGRADABLE {
/// @custom:oz-upgrades-unsafe-allow constructor gentregatorv3interface
内部价格馈送; constructor()initializer {
pricefeed = gengregatorv3interface(0x9326BFA02ADD2366B30BACB125260AF641031331); //
kovan testnet}
函数initialize()initializer public {
__ERC20_INIT(“ uptoken”,“ upt”);
__erc20burnable_init();
__ERC20SNAPSHOT_INIT();
__ownable_init();
__pausable_init();
__erc20permit_init(“ uptoken”);
__ERC20FLASHMINT_INIT();
__UUPSUPGRADABLE_INIT(); }
函数快照()public唯一athower {
_snapshot(); }
函数pape()public唯一athower {
_暂停(); }
在
_unpause(); }
功能薄荷(地址为,UINT256金额)公共唯一者{
_mint(to,金额); }
函数_beforetokentransfer(地址从,地址到,UINT256
数量)
内部的
当没有人
覆盖(ERC20Upgraded,ERC20SNAPSNAPSHOTUPGRADABLE){
super._beforetokentransfer(从,到金额); }
函数_authorizeupgrade(地址newImplementation)
内部的
唯一的家
覆盖{}
//以下功能是固体性所要求的。
函数_afterTokentRansfer(地址,地址到,UINT256金额)
内部的
覆盖(ERC20Upgraded,ERC20VotesUpgradable){
super.__aftertokentransfer(从,到金额); }
函数_mint(地址为,UINT256金额)
内部的
覆盖(ERC20Upgraded,ERC20VotesUpgradable){
super._mint(to,金额); }
函数_burn(地址帐户,UINT256金额)
内部的
覆盖(ERC20Upgraded,ERC20VotesUpgradable){
super._burn(帐户,金额); }
函数getLatestPrice()public View返回(int){
((
/ uint80 roundid /,
int价格,
/ uint startat /,
/ uint Timestamp /,
/ uint80回答/
)= PriceFeed.latestroundData();
回报价格; }
}
Will Chainlink's AggregatorV3Interface.sol work with an OpenZeppelin upgradable contract?
Do I place the
"priceFeed =
AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331);"
inside the "initializer{}"?
I would like the address "0x9326BFA02ADD2366b30bacB125260Af641031331"
to be upgradable in the next version of the smart contract.
Is there already a way to do so?
Thank you!
Motivation & Justification
I hope that it makes sense to want to "getLatestPrice()" within the smart contract of a new token.
Before deployment, there is no way of knowing the new token's address.
I would like to change the address using the OpenZeppelin upgradable contract under the UUPS proxy pattern.
Is there any example online to update
priceFeed =
AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331); //
Kovan Testnet
on version 2 of the smart contract?
Thank you!
Important Links:
OpenZeppelin Contracts Wizard
get-the-latest-price using Chainlink's AggregatorV3Interface
Deploying an UUPS Upgradable Contract
I have no idea how to work on version 2 of an UUPS Upgradable Contract.
This is where I got stuck using Chainlink's AggregatorV3Interface.sol with every feature selected on OpenZeppelin Contracts Wizard:
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4;
import
"./@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "./@openzeppelin/contracts-
upgradeable/token/ERC20/extensions/ERC20BurnableUpgradeable.sol";
import "./@openzeppelin/contracts-
upgradeable/token/ERC20/extensions/ERC20SnapshotUpgradeable.sol";
import
"./@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import
"./@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import
"./@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-
ERC20PermitUpgradeable.sol"; import "./@openzeppelin/contracts-
upgradeable/token/ERC20/extensions/ERC20VotesUpgradeable.sol"; import
"./@openzeppelin/contracts-
upgradeable/token/ERC20/extensions/ERC20FlashMintUpgradeable.sol";
import
"./@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import
"./@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import
"@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
contract UpToken is Initializable, ERC20Upgradeable,
ERC20BurnableUpgradeable, ERC20SnapshotUpgradeable,
OwnableUpgradeable, PausableUpgradeable, ERC20PermitUpgradeable,
ERC20VotesUpgradeable, ERC20FlashMintUpgradeable, UUPSUpgradeable {
/// @custom:oz-upgrades-unsafe-allow constructor AggregatorV3Interface
internal priceFeed; constructor() initializer {
priceFeed = AggregatorV3Interface(0x9326BFA02ADD2366b30bacB125260Af641031331); //
Kovan Testnet }
function initialize() initializer public {
__ERC20_init("UpToken", "UPT");
__ERC20Burnable_init();
__ERC20Snapshot_init();
__Ownable_init();
__Pausable_init();
__ERC20Permit_init("UpToken");
__ERC20FlashMint_init();
__UUPSUpgradeable_init(); }
function snapshot() public onlyOwner {
_snapshot(); }
function pause() public onlyOwner {
_pause(); }
function unpause() public onlyOwner {
_unpause(); }
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount); }
function _beforeTokenTransfer(address from, address to, uint256
amount)
internal
whenNotPaused
override(ERC20Upgradeable, ERC20SnapshotUpgradeable) {
super._beforeTokenTransfer(from, to, amount); }
function _authorizeUpgrade(address newImplementation)
internal
onlyOwner
override {}
// The following functions are overrides required by Solidity.
function _afterTokenTransfer(address from, address to, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable) {
super._afterTokenTransfer(from, to, amount); }
function _mint(address to, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable) {
super._mint(to, amount); }
function _burn(address account, uint256 amount)
internal
override(ERC20Upgradeable, ERC20VotesUpgradeable) {
super._burn(account, amount); }
function getLatestPrice() public view returns (int) {
(
/uint80 roundID/,
int price,
/uint startedAt/,
/uint timeStamp/,
/uint80 answeredInRound/
) = priceFeed.latestRoundData();
return price; }
}
发布评论
评论(1)
建议您在升级插件中使用HARDHAT( https://docs.openzeppelin.com/conconpellin.com/concontracts/concontracts /4.x/upgradable )实现这一目标。当您第一次使用HardHat部署它时,它将部署代理,实施合同(即您的令牌合同)和管理合同。
请参阅此视频中的20:23:。实际上,也许可以观看整个视频,以了解如何使用OZ升级合同使用Hardhat。
然后,当您获取令牌合同地址时,将令牌合同更新为V2,将合同地址添加为状态变量,并添加一个设置器函数,使您能够在将来更新该状态变量并部署V2。您可以在[24:30]左右链接的同一视频中看到如何部署V2。
Recommend you use hardhat with the upgrades plugin (https://docs.openzeppelin.com/contracts/4.x/upgradeable) to achieve this. When you deploy it the first time using hardhat, it will deploy the proxy, the implementation contract (i.e. your token contract) and an admin contract.
See 20:23 onwards in this video: https://www.youtube.com/watch?v=bdXJmWajZRY&t=15s . In fact maybe watch that entire video to get a sense of how to use hardhat with OZ upgradeable contracts.
Then when you get your token contract address, update the token contract as V2, add the contract address as a state variable and (optionally) add a setter function that gives you the ability to update that state variable in future, and deploy V2. You can see how to deploy V2 in that same video I linked above, at [24:30] or so.