0
IERC20 public immutable underlying;

constructor(IERC20 underlyingToken) {
    underlying = underlyingToken;
}

For example, in the above codes, is the 'underlying' variable just an address that is also associated the IERC20 interface? The 'immutable' is just that the address is immutable?

1

1 Answer 1

1

For example, in the above codes, is the 'underlying' variable just an address that is also associated the IERC20 interface?

Yes, it simply states that the contract at the address contained in the underlying variable implements the ERC-20 interface as defined in EIP-20 and therefore allow the developer to make use of all its functions easily such as transfer , transferFrom, etc... with a friendly syntax (ex : underlying.transfer(to, amount);)

Now keep in mind that this is just the developer guaranteing the compiler of that, it not necessarily true (you can pass any address to the constructor, but that's outside the responsibility of the compiler and fully yours as a developer / deployer).

The 'immutable' is just that the address is immutable?

It means that the value of the variable underlying cannot be modified once the constructor has been executed. From the documentation :

The contract creation code generated by the compiler will modify the contract’s runtime code before it is returned by replacing all references to immutables by the values assigned to the them.

So technically, it no longer a variable outside of the constructor, it becomes a constant. It's just good practice, think of it as a form of const-correctess if that speaks to you which also helps with security concerns.

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