Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/subgraph' into collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
Corantin committed May 4, 2022
2 parents 0fd8209 + 6c43199 commit 7efda3a
Show file tree
Hide file tree
Showing 14 changed files with 695 additions and 92 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"private": true,
"scripts": {
"ci" : "yarn install --pure-lockfile",
"ci": "yarn install --pure-lockfile",
"lint": "yarn workspace @1hive/quests-react-app lint",
"chain": "yarn workspace @1hive/quests-hardhat chain",
"test": "yarn workspace @1hive/quests-hardhat test",
Expand All @@ -26,7 +26,8 @@
},
"workspaces": {
"packages": [
"packages/*"
"packages/*",
"packages/subgraphs/quest-subgraph"
],
"nohoist": [
"**/@graphprotocol/graph-ts",
Expand Down
55 changes: 28 additions & 27 deletions packages/hardhat/scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ const fs = require("fs");
const chalk = require("chalk");
const hre = require("hardhat");

const publishDir = "../react-app/src/contracts";
// const publishDir = "../react-app/src/contracts";
const graphDir = "../subgraph";

function publishContract(contractName) {
console.log(
" 💽 Publishing",
chalk.cyan(contractName),
"to",
chalk.gray(publishDir)
"to"
// ,
// chalk.gray(publishDir)
);
try {
const contractArtifact = fs
Expand All @@ -36,28 +37,28 @@ function publishContract(contractName) {

graphConfig = JSON.parse(graphConfig);
graphConfig[contractName + "Address"] = address;
fs.writeFileSync(
`${publishDir}/${contractName}.address.js`,
`module.exports = "${address}";`
);
fs.writeFileSync(
`${publishDir}/${contractName}.abi.js`,
`module.exports = ${JSON.stringify(contract.abi, null, 2)};`
);
fs.writeFileSync(
`${publishDir}/${contractName}.bytecode.js`,
`module.exports = "${contract.bytecode}";`
);
// fs.writeFileSync(
// `${publishDir}/${contractName}.address.js`,
// `module.exports = "${address}";`
// );
// fs.writeFileSync(
// `${publishDir}/${contractName}.abi.js`,
// `module.exports = ${JSON.stringify(contract.abi, null, 2)};`
// );
// fs.writeFileSync(
// `${publishDir}/${contractName}.bytecode.js`,
// `module.exports = "${contract.bytecode}";`
// );

const folderPath = graphConfigPath.replace("/config.json", "");
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
}
fs.writeFileSync(graphConfigPath, JSON.stringify(graphConfig, null, 2));
fs.writeFileSync(
`${graphDir}/abis/${contractName}.json`,
JSON.stringify(contract.abi, null, 2)
);
// fs.writeFileSync(graphConfigPath, JSON.stringify(graphConfig, null, 2));
// fs.writeFileSync(
// `${graphDir}/abis/${contractName}.json`,
// JSON.stringify(contract.abi, null, 2)
// );

console.log(
" 📠 Published " + chalk.green(contractName) + " to the frontend."
Expand All @@ -83,9 +84,9 @@ function publishContract(contractName) {
}

async function main() {
if (!fs.existsSync(publishDir)) {
fs.mkdirSync(publishDir);
}
// if (!fs.existsSync(publishDir)) {
// fs.mkdirSync(publishDir);
// }
const finalContractList = [];
fs.readdirSync(hre.config.paths.sources).forEach((file) => {
if (file.indexOf(".sol") >= 0) {
Expand All @@ -96,10 +97,10 @@ async function main() {
}
}
});
fs.writeFileSync(
`${publishDir}/contracts.js`,
`module.exports = ${JSON.stringify(finalContractList)};`
);
// fs.writeFileSync(
// `${publishDir}/contracts.js`,
// `module.exports = ${JSON.stringify(finalContractList)};`
// );
}
main()
.then(() => process.exit(0))
Expand Down
2 changes: 1 addition & 1 deletion packages/services/graph-node/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ services:
ipfs: "ipfs:5001"
# ipfs: "https://api.thegraph.com/ipfs/QmZ1yyM9esaDrDxAzsSAzf33dG5Jdp2jvqj8SxUHC5Awbe"
# ethereum: "localhost:http://host.docker.internal:8545"
ethereum: "rinkeby:https://rinkeby.infura.io/v3/ba8a73e283eb4b9eafd25f5fdbfc1717"
ethereum: "rinkeby:https://rinkeby.infura.io/v3/74dcdd771e514bdf88cf139f93b3eae2"
GRAPH_LOG: info
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: "true"
GRAPH_ALLOW_NON_DETERMINISTIC_FULLTEXT_SEARCH: "true"
Expand Down
3 changes: 2 additions & 1 deletion packages/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"stop-optimism": "cd optimism/ops && make down",
"run-graph-node": "cd graph-node && docker-compose up",
"remove-graph-node": "cd graph-node && docker-compose down",
"clean-graph-node": "rm -rf graph-node/data/"
"clean-graph-node": "rm -rf graph-node/data/",
"restart":"yarn remove-graph-node && yarn clean-graph-node || true && yarn run-graph-node"
}
}
2 changes: 1 addition & 1 deletion packages/subgraphs/quest-subgraph/config/rinkeby.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"network": "rinkeby",
"startBlock": 9953404,
"questFactoryAddress": "0xf94FB88b197c8749DabD633aCd55C9F50B18E4Da",
"questFactoryAddress": "0xa8922609D34472977D2C7749D6eB6E1F0eFe8e01",
"startBlockV2": 10573676,
"questFactoryAddressV2": "0xa8922609D34472977D2C7749D6eB6E1F0eFe8e01",
"startBlockV3": 10613166,
Expand Down
23 changes: 23 additions & 0 deletions packages/subgraphs/quest-subgraph/config/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"network": "rinkeby",
"dataSources":[
{
"nameContract":"QuestFactory",
"startBlock": 9939088,
"questFactoryAddress": "0x1A506d3ed7E0865FFC980d2eB54662DDb587e885",
"customTemplate":"questFactory.yaml"
},
{
"nameContract":"QuestFactoryV1",
"startBlock": 9953404,
"questFactoryAddress": "0x855a04deb27abf93336d52a91f29a98dd5605691",
"customTemplate":"questFactoryV1.yaml"
},
{
"nameContract":"QuestFactoryV2",
"startBlock": 10573676,
"questFactoryAddress": "0xa8922609D34472977D2C7749D6eB6E1F0eFe8e01"
,"customTemplate":"questFactory.yaml"
}
]
}
8 changes: 7 additions & 1 deletion packages/subgraphs/quest-subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "@1hive/quests-subgraph",
"license": "UNLICENSED",
"version": "0.1.0",
"type": "module",
"scripts": {
"prepare:test": "mustache config/test.json src/test.template.yaml > test.yaml -p src/questFactory.yaml",
"prepare:rinkeby": "node ./sync-with-last-deploy.js rinkeby V2 && mustache config/rinkeby.json src/subgraph.template.yaml > subgraph.yaml",
"prepare:local": "node ./sync-with-last-deploy.js localhost V2 && mustache config/localhost.json src/subgraph.template.yaml > subgraph.yaml",
"codegen": "graph codegen",
Expand All @@ -12,12 +14,16 @@
"deploy:p:rinkeby": "yarn prepare:rinkeby && graph deploy --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ corantin/quests-subgraph ",
"deploy:rinkeby": "graph deploy --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ corantin/quests-subgraph",
"deploy:staging-rinkeby": "graph deploy --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ corantin/quests-subgraph-staging",
"deploy:local": "graph deploy --ipfs http://0.0.0.0:5001 --node http://0.0.0.0:8020 corantin/quests-subgraph"
"deploy:local": "graph deploy --ipfs http://0.0.0.0:5001 --node http://0.0.0.0:8020 corantin/quests-subgraph",
"hardhat:deploy:local": "yarn workspace @1hive/quests-hardhat deploy:local && yarn workspace @1hive/quests-hardhat postdeploy"
},
"dependencies": {
"@graphprotocol/graph-cli": "^0.23.2",
"@graphprotocol/graph-ts": "^0.23.1",
"configstore": "^6.0.0",
"inquirer": "^8.2.4",
"js-yaml": "^4.1.0",
"minimist": "^1.2.6",
"mustache": "^4.2.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- kind: ethereum/contract
name: {{nameContract}}
network: {{network}}
source:
address: "{{questFactoryAddress}}"
abi: {{nameContract}}
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- QuestCreated
abis:
- name: {{nameContract}}
file: ./abis/{{nameContract}}.json
eventHandlers:
- event: QuestCreated(address,string,bytes,address,uint256)
handler: handleQuestCreated
file: ./src/mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
- kind: ethereum/contract
name: {{nameContract}}
network: {{network}}
source:
address: "{{questFactoryAddress}}"
abi: {{nameContract}}
startBlock: {{startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- QuestCreated
abis:
- name: {{nameContract}}
file: ./abis/{{nameContract}}.json
eventHandlers:
- event: QuestCreated(address,string)
handler: handleQues
file: ./src/mapping.ts
20 changes: 0 additions & 20 deletions packages/subgraphs/quest-subgraph/src/questFactory.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions packages/subgraphs/quest-subgraph/src/test.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
specVersion: 0.0.4
features:
- fullTextSearch
- nonFatalErrors
- ipfsOnEthereumContracts
schema:
file: ./src/schema.graphql
dataSources:
{{#dataSources}}
{{>(customTemplate)}}
{{/dataSources}}
Loading

0 comments on commit 7efda3a

Please sign in to comment.