forked from Synthetixio/js-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
136 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"@typescript-eslint/no-var-requires": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const ethers = require('ethers'); | ||
const prettier = require('prettier'); | ||
|
||
const synthetixPath = path.dirname(require.resolve('synthetix')); | ||
const deployed = path.join(synthetixPath, 'publish/deployed'); | ||
const networks = fs | ||
.readdirSync(deployed, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name); | ||
|
||
function generateTargets(network) { | ||
const deployment = require(`synthetix/publish/deployed/${network}/deployment.json`); | ||
fs.mkdirSync(`build/${network}/deployment/targets`, { recursive: true }); | ||
if (!deployment.targets) { | ||
return; | ||
} | ||
|
||
Object.entries(deployment.targets).forEach(([key, val]) => { | ||
fs.writeFileSync( | ||
`build/${network}/deployment/targets/${key}.ts`, | ||
prettier.format( | ||
Object.entries(val) | ||
.filter(([name]) => ['name', 'source', 'address'].includes(name)) | ||
.map(([name, value]) => `export const ${name} = ${JSON.stringify(value, null, 2)};`) | ||
.join('\n'), | ||
{ parser: 'typescript' } | ||
), | ||
'utf8' | ||
); | ||
}); | ||
} | ||
|
||
function generateSources(network) { | ||
const deployment = require(`synthetix/publish/deployed/${network}/deployment.json`); | ||
fs.mkdirSync(`build/${network}/deployment/sources`, { recursive: true }); | ||
if (!deployment.sources) { | ||
return; | ||
} | ||
|
||
Object.entries(deployment.sources).forEach(([key, val]) => { | ||
const iface = new ethers.utils.Interface(val.abi); | ||
val.abi = iface.format(ethers.utils.FormatTypes.full); | ||
fs.writeFileSync( | ||
`build/${network}/deployment/sources/${key}.ts`, | ||
prettier.format( | ||
Object.entries(val) | ||
.filter(([name]) => ['abi'].includes(name)) | ||
.map(([name, value]) => `export const ${name} = ${JSON.stringify(value, null, 2)};`) | ||
.join('\n'), | ||
{ parser: 'typescript' } | ||
), | ||
'utf8' | ||
); | ||
}); | ||
} | ||
|
||
function generateSynths(network) { | ||
const synths = require(`synthetix/publish/deployed/${network}/synths.json`); | ||
fs.mkdirSync(`build/${network}`, { recursive: true }); | ||
fs.writeFileSync( | ||
`build/${network}/synths.ts`, | ||
prettier.format( | ||
[ | ||
'export enum Synths {', | ||
...synths.map(({ name }) => ` ${name} = ${JSON.stringify(name, null, 2)},`), | ||
'}', | ||
].join('\n'), | ||
{ parser: 'typescript' } | ||
), | ||
'utf8' | ||
); | ||
} | ||
|
||
networks.forEach((network) => { | ||
generateTargets(network); | ||
generateSources(network); | ||
generateSynths(network); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
throw new Error('Import each contract directly from @synthetixio/contracts/build'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@synthetixio/contracts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "node codegen.js" | ||
}, | ||
"files": [ | ||
"build" | ||
], | ||
"version": "1.0.0", | ||
"author": "Nikita <[email protected]>", | ||
"repository": "github:Synthetixio/js-monorepo", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"ethers": "^5.6.8", | ||
"prettier": "^2.6.2", | ||
"synthetix": "^2.74.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters