Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an upgradeable version of RrpRequesterV0 #1867

Open
bbenligiray opened this issue Aug 28, 2023 · 0 comments
Open

Add an upgradeable version of RrpRequesterV0 #1867

bbenligiray opened this issue Aug 28, 2023 · 0 comments

Comments

@bbenligiray
Copy link
Member

See the Discord discussion below

Hello, I'm looking into using QRNG along with OpenZepellin's upgradeable contracts, is the provided RrpRequesterV0 contract able to work with upgradeable contracts?

Hey, RrpRequesterV0.sol has an immutable variable, airnodeRrp, which gets initialized in the constructor. Since your upgradeable proxy contract will be using the bytecode of your implementation contract without running the constructor, airnodeRrp will not be initialized as far as your upgradeable proxy contract is concerned. So your upgradeable contract will think that the Airnode RRP contract's address is address(0), which obviously won't work.
You need an upgradeable version of RrpRequesterV0.sol (similar to how OpenZeppelin has upgradeable versions of all of their contracts in https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable). See below, just add this contract in your repo (assuming you have already run npm install @api3/airnode-protocol) and inherit this instead of RrpRequesterV0.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@api3/airnode-protocol/contracts/rrp/interfaces/IAirnodeRrpV0.sol";

/// @title The upgradeable contract to be inherited to make Airnode RRP requests
contract RrpRequesterV0Upgradeable {
    // Inline the correct Airnode RRP contract address for the chain below, refer to
    // https://github.com/api3dao/airnode/blob/master/packages/airnode-protocol/deployments/references.json
    IAirnodeRrpV0 public constant airnodeRrp = 0xa0AD79D995DdeeB18a14eAef56A549A04e3Aa1Bd;

    /// @dev Reverts if the caller is not the Airnode RRP contract.
    /// Use it as a modifier for fulfill and error callback methods, but also
    /// check `requestId`.
    modifier onlyAirnodeRrp() {
        require(msg.sender == address(airnodeRrp), "Caller not Airnode RRP");
        _;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant