1

In solidity, see below code ..... How is that the interface name is being used as variable type ?
See the comments in below code

pragma solidity 0.8.11;

import "../interfaces/ISpool.sol";
// ... other imports

abstract contract VaultBase is IVaultBase, VaultImmutable, SpoolOwnable, SpoolPausable, BaseConstants {
    using Bitwise for uint256;
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    /// @notice The central Spool contract
    ISpool internal immutable spool;   // ISpool is interface name and it is
                                       // being used as variable type. What this means ?

}

ISpool interface:

interface ISpool is ISpoolExternal, ISpoolReallocation, ISpoolDoHardWork, ISpoolStrategy, ISpoolBase {}

How is that the interface name is being used as variable type ?

1
  • When used as variable an interface is an address that can be used to call the interface functions.
    – Ismael
    Oct 8, 2022 at 1:49

2 Answers 2

2

Let's take a look in this code example:

interface B{
    function func() external;
}

contract A {
    B b;
    constructor(address contract_implements_b) public {
        b = B(contract_implements_b);
    }
}

Here there is interface B and there is contract A.

contract A receives an address as a parameter, this address points to another contract that implements interface B. After we initialized b we can call b.func() in our contract A without knowing the full ABI of the address's contract we got.

2
  • In the code where have you called b.func() ?
    – TryCatch
    Oct 7, 2022 at 13:20
  • I didn’t, just mentioned it will work for you
    – matank001
    Oct 7, 2022 at 13:35
0

you are initializing a variable here:

ISpool internal immutable spool;

You are describing that spool object is visible internally and it is read-only. Also, it will have methods that are specified in ISpool interface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.