Listing inheritance dependencies

The surya dependencies <target_contract> <files..> command lists the C3 linearization of the inheritance for the given contract. The output lists the most derived contract; this means that, if the same function is present in the inherited contracts, it will look for the function in the listed order and use the definition (if present).

In this example of the command, we are using the 0x project Exchange.sol contract. The 0x project is an open source Decentralized Exchange (DEX). Follow the following commands:

$ git clone https://github.com/0xProject/0x-monorepo.git
$ cd
0x-monorepo/contracts/exchange/contracts
$ surya dependencies Exchange **/*.sol

The preceding command will generate the following output:

Surya dependencies for the contract's inheritance order

The Exchange.sol contract file has a big list of inheritance. You can refer to the Exchange.sol code on GitHub at https://github.com/0xProject/0x-monorepo/blob/development/contracts/exchange/contracts/src/Exchange.sol.

Following is the code snippet of the contract and its inheritance:

contract Exchange is
MixinExchangeCore,
MixinMatchOrders,
MixinSignatureValidator,
MixinTransactions,
MixinAssetProxyDispatcher,
MixinWrapperFunctions
{
//Rest of the code
}

Solidity uses C3 Linearization, which is an algorithm used to find the order in which functions should be inherited in the contract when multiple inheritance is used. The important thing to remember is that the Solidity compiler composes the inheritance graph from right to left. As you can see in the Exchange contract, the rightmost contract it has inherited is MixinWrapperFunctions, and this contract will be looked to first to find a given function. You can also see that this contract is listed first in the output of the surya dependencies executed on the Exchange contract. Hence, the order generated by the surya command is used to find a function in the contracts in the given order starting from the first contract.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.195.91