Contract to big, how to split with access rules in subcontract?

Hi all,

my erc721 contract got to big an I'm fighting with the contract size now.
I already split up some code into subcontract files, that are imported in the main for better readability.

Within the subcontract (MYSUBCONTRACT) there are some mappings and arrays that store data but also have some methods that call for instance the minting function or are checking access rights from AccessControlUpgradeable, so are accessing parts of the main contract.

Now I'm struggeling to extract functions, so that the contract gets smaller.

What would be the best in that case?

Structure like:

ERC721 main contract
-import ERC721Upgradeable
-import AccessControlUpgradeable
-(...import other openzeppelin)
- -import AccessControlUpgradeable
- -import ERC721Upgradeable
- - > with functions for storing additional data to the tokens but also have methods that call the
safemint from parent or checking access rights from parent, therefore the duplicate imports

Option 1:
Extract functions from MYSUBCONTRACT and data storage into a contract, deploy extra and call the contract functions via contract adress in the main erc721?

Option 2:
Do the same but use a library? Wondering why then using a library?

Question 1:
But how can I access for instance the AccessControlUpgradeable userrights in MYSUBCONTRACT? Okay, maybe duplicate / push the rights from main to subcontract, does that make sense?

Question 2:
Can I use a hardhat proxy also on the subcontract or sublibrary in that case?

Question 3:
Additionally I also plan to abstract the NFT sale process from the Main ERC721.

Would something work like
Extra SaleContract with own logic --> (calls) --> ERC721 main contract.safemint(x,y) ?

Thank you so much in advance.


Are you compiling with optimizations?

Separating things with imports does not reduce contract size.

Thank you, yes I used optimizing.

In the meantime I used option 1 and created a second contract.
In the second contract I also imported AccessControlUpgradeable and copied userrights.

While setting userrights in both contracts, they copy the rights to the other contract via overwritten functions.

Tests with using a proxy for second contract are outstanding still.