'Will Chainlink's AggregatorV3Interface.sol works with an OpenZeppelin upgradable contract?
Will Chainlink's AggregatorV3Interface.sol works 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.
Thank you!
// 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;
}
}
This is the error message:
~/upgradable5 npx hardhat test
1 ✘ 6s
UpToken
1) deploys
0 passing (2s)
1 failing
1) UpToken
deploys:
Error: Contract `UpToken` is not upgrade safe
contracts/UpToken.sol:20: Contract `UpToken` has a constructor
Define an initializer instead
https://zpl.in/upgrades/error-001
at assertUpgradeSafe (node_modules/@openzeppelin/upgrades-
core/src/validate/query.ts:19:11)
at deployImpl (node_modules/@openzeppelin/hardhat-
upgrades/src/utils/deploy-impl.ts:102:20)
at deployProxyImpl (node_modules/@openzeppelin/hardhat-
upgrades/src/utils/deploy-impl.ts:76:10)
at Proxy.deployProxy (node_modules/@openzeppelin/hardhat-
upgrades/src/deploy-proxy.ts:42:28)
at Context.<anonymous> (test/test.js:8:5)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
