Skip to content

Commit

Permalink
Merge pull request #11 from OriumNetwork/feature--ON-509-update
Browse files Browse the repository at this point in the history
ON-509: add mustache for subgraph manifest generation
  • Loading branch information
karacurt committed Oct 31, 2023
2 parents dd20ee1 + f884839 commit 33cc92f
Show file tree
Hide file tree
Showing 9 changed files with 185 additions and 171 deletions.
10 changes: 10 additions & 0 deletions config/goerli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"network": "goerli",
"erc721": [
{
"name": "ChronosTraveler",
"address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32",
"startBlock": 8099655
}
]
}
22 changes: 22 additions & 0 deletions config/mumbai.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"network": "mumbai",
"erc721": [
{
"name": "AavegotchiGotchi",
"address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e",
"startBlock": 34467860
},
{
"name": "AavegotchiParcel",
"address": "0xBcCf68d104aCEa36b1EA20BBE8f06ceD12CaC008",
"startBlock": 38134604
}
],
"erc1155": [
{
"name": "AavegotchiWearable",
"address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8",
"startBlock": 34467877
}
]
}
27 changes: 27 additions & 0 deletions config/polygon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"network": "matic",
"erc721": [
{
"name": "AavegotchiGotchi",
"address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d",
"startBlock": 11516320
},
{
"name": "AavegotchiParcel",
"address": "0x1D0360BaC7299C86Ec8E99d0c1C9A95FEfaF2a11",
"startBlock": 20667840
},
{
"name": "ChronosTravaler",
"address": "0xa03c4e40d1fcaa826591007a17ca929ef8adbf1c",
"startBlock": 36796276
}
],
"erc1155": [
{
"name": "AavegotchiWearable",
"address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f",
"startBlock": 35999793
}
]
}
60 changes: 60 additions & 0 deletions mustache.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const Mustache = require('mustache')
const fs = require('fs')

// receive network name as argument
async function main(args) {
const networkName = getNetworkName(args)
const networkData = require(`./config/${networkName}.json`)
const template = fs.readFileSync('./subgraph.template.yaml', 'utf8')
const parsedData = putFirstElementFlag(networkData)
const output = Mustache.render(template, parsedData)
writeOutput(output)
}

function getNetworkName(args) {
if (args.length < 3) {
throw new Error('Missing network name argument')
}
return args[2]
}

function writeOutput(output) {
fs.writeFileSync('./subgraph.yaml', output)
}

function putFirstElementFlag(data) {
const dataWithFirstElementFlag = replaceFirstElementFlag(data)
return arrayToObj(dataWithFirstElementFlag)
}
function replaceFirstElementFlag(data) {
return Object.keys(data).map((key, index) => {
if (Array.isArray(data[key]) && data[key].length > 0) {
return {
[key]: data[key].map((item, index) => {
if (index === 0) {
return { ...item, isFirstElement: true }
} else {
return item
}
}),
}
}
return { [key]: data[key] }
})
}

function arrayToObj(data) {
return data.reduce((acc, curr) => {
return { ...acc, ...curr }
}, {})
}

main(process.argv)
.then(() => {
console.log('Done')
process.exit()
})
.catch(err => {
console.error(err)
process.exit(1)
})
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
},
"scripts": {
"graph:auth": "graph auth --product hosted-service",
"build:goerli": "cp subgraph-goerli.yaml subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:mumbai": "cp subgraph-mumbai.yaml subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:polygon": "cp subgraph-polygon.yaml subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:goerli": "node mustache.config.js goerli && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:mumbai": "node mustache.config.js mumbai && graph codegen subgraph.yaml && graph build subgraph.yaml",
"build:polygon": "node mustache.config.js polygon && graph codegen subgraph.yaml && graph build subgraph.yaml",
"deploy:goerli": "graph deploy --node https://api.thegraph.com/deploy/orium-network/nft-roles-goerli",
"deploy:mumbai": "graph deploy --node https://api.thegraph.com/deploy/orium-network/nft-roles-mumbai",
"deploy:polygon": "graph deploy --node https://api.thegraph.com/deploy/orium-network/nft-roles-polygon",
Expand All @@ -31,6 +31,7 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"matchstick-as": "^0.5.2",
"mustache": "^4.2.0",
"prettier": "^3.0.2"
},
"husky": {
Expand Down
71 changes: 0 additions & 71 deletions subgraph-goerli.yaml

This file was deleted.

71 changes: 0 additions & 71 deletions subgraph-polygon.yaml

This file was deleted.

Loading

0 comments on commit 33cc92f

Please sign in to comment.