2
2
const fs = require ( 'fs' ) ;
3
3
const glob = require ( 'glob' ) ;
4
4
5
- // rename files
5
+ // Rename files.
6
6
fs . renameSync ( 'contracts/Initializable.sol' , 'contracts/ERC721A__Initializable.sol' ) ;
7
7
fs . renameSync ( 'contracts/InitializableStorage.sol' , 'contracts/ERC721A__InitializableStorage.sol' ) ;
8
8
9
- // loop through all files with contracts/**/*.sol pattern
9
+ // Loop through all files with contracts/**/*.sol pattern.
10
10
glob ( 'contracts/**/*.sol' , null , function ( err , files ) {
11
11
files . forEach ( ( file ) => {
12
- // read file content
12
+ // Read file content.
13
13
const content = fs . readFileSync ( file , 'utf8' ) ;
14
14
15
15
const updatedContent = content
@@ -20,7 +20,28 @@ glob('contracts/**/*.sol', null, function (err, files) {
20
20
. replace ( / o n l y I n i t i a l i z i n g \s * ?\{ / g, 'onlyInitializingERC721A {' )
21
21
. replace ( / I n i t i a l i z a b l e / g, 'ERC721A__Initializable' ) ;
22
22
23
- // write updated file
23
+ // Write updated file.
24
24
fs . writeFileSync ( file , updatedContent ) ;
25
25
} ) ;
26
- } ) ;
26
+ } ) ;
27
+
28
+ // Replace the TokenApprovalRef to break cyclic importing.
29
+ let erc721aFilepath = 'contracts/ERC721AUpgradeable.sol' ;
30
+ let erc721aContents = fs . readFileSync ( erc721aFilepath , 'utf8' ) ;
31
+ let tokenApprovalRefRe = / \/ \/ .* ?\n \r ? \s * s t r u c t T o k e n A p p r o v a l R e f \s * \{ [ ^ \} ] + \} / ;
32
+ let tokenApprovalRefMatch = erc721aContents . match ( tokenApprovalRefRe ) ;
33
+ if ( tokenApprovalRefMatch ) {
34
+ erc721aContents = erc721aContents
35
+ . replace ( tokenApprovalRefMatch [ 0 ] , '' )
36
+ . replace ( / T o k e n A p p r o v a l R e f / g, 'ERC721AStorage.TokenApprovalRef' ) ;
37
+ fs . writeFileSync ( erc721aFilepath , erc721aContents ) ;
38
+
39
+ let erc721aStorageFilepath = 'contracts/ERC721AStorage.sol' ;
40
+ let erc721aStorageContents = fs . readFileSync ( erc721aStorageFilepath , 'utf8' ) ;
41
+ erc721aStorageContents = erc721aStorageContents
42
+ . replace ( / s t r u c t L a y o u t \s * \{ / , tokenApprovalRefMatch [ 0 ] + '\n\n struct Layout {' )
43
+ . replace ( / E R C 7 2 1 A U p g r a d e a b l e .T o k e n A p p r o v a l R e f / g, 'ERC721AStorage.TokenApprovalRef' )
44
+ . replace ( / i m p o r t .* ?\. \/ E R C 7 2 1 A U p g r a d e a b l e .s o l [ ^ ; ] + ; / , '' ) ;
45
+
46
+ fs . writeFileSync ( erc721aStorageFilepath , erc721aStorageContents ) ;
47
+ }
0 commit comments