Best practice for avoiding cyclic dependencies?

@shark0der asked on Telegram

What’s the best practice to avoid cyclic dependencies? I’m having trouble verifying my contracts using oz verify…
It will be quite hard to create a minimum example as I have over 30 contracts and I’m not sure where it’s coming from
I’ve dugged into the source code and saw that oz uses truffle-flattener
It has an open issue regarding this:
I’m thinking thag declaring interfaces for all my classes might solve this issue, however this will hurt code navigation quite badly

Hi @shark0der,

Unfortunately it doesn’t look like there is a silver bullet for this.

Interfaces should resolve this but may hurt navigability.

You could try solidity-flattener to flatten.

@shark0der advised they have created a PR for truffle-flattener which handled cyclic dependencies.

cc @Skyler_Fly you may want to look at this.

1 Like

Thanks for the info! I will give this a try again soon as I still haven’t been able to flatten my complex contract.

1 Like

Hi @Skyler_Fly,

You may want to try multi-file verification, which I much prefer over flattening as licenses and imports are maintained and it is much easier to read.
See: Verify smart contract inheriting from OpenZeppelin Contracts

1 Like

Oh, I have seen that and never really knew what to do to achieve that. I will def have to try this!!!
TinyBoxes is getting really near time for a testnet beta and I would love to be able to have to contract up on Etherscan for that!
Thanks Andrew

1 Like