From edf97072560eeaa57577ce2e6a2883a03dd801ec Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 30 Oct 2023 15:55:07 -0300 Subject: [PATCH 1/6] ON-509: add mustache for subgraph manifest generation --- config/goerli.json | 10 +++ config/mumbai.json | 22 ++++++ config/polygon.json | 27 +++++++ package-lock.json | 16 ++++- package.json | 9 +-- subgraph-goerli.yaml | 71 ------------------ subgraph-mumbai.yaml | 72 ------------------- ...aph-polygon.yaml => subgraph.template.yaml | 55 ++++++++------ 8 files changed, 111 insertions(+), 171 deletions(-) create mode 100644 config/goerli.json create mode 100644 config/mumbai.json create mode 100644 config/polygon.json delete mode 100644 subgraph-goerli.yaml delete mode 100644 subgraph-mumbai.yaml rename subgraph-polygon.yaml => subgraph.template.yaml (88%) diff --git a/config/goerli.json b/config/goerli.json new file mode 100644 index 0000000..b80ad47 --- /dev/null +++ b/config/goerli.json @@ -0,0 +1,10 @@ +{ + "network": "goerli", + "erc721": [ + { + "name": "ChronosTravaler", + "address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32", + "startBlock": 8099655 + } + ] +} \ No newline at end of file diff --git a/config/mumbai.json b/config/mumbai.json new file mode 100644 index 0000000..3dae87c --- /dev/null +++ b/config/mumbai.json @@ -0,0 +1,22 @@ +{ + "network": "mumbai", + "erc721": [ + { + "name": "AavegotchiDiamond", + "address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e", + "startBlock": 34467860 + }, + { + "name": "RealmDiamond", + "address": "0xBcCf68d104aCEa36b1EA20BBE8f06ceD12CaC008", + "startBlock": 38134604 + } + ], + "erc1155": [ + { + "name": "WearablesDiamond", + "address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8", + "startBlock": 34467877 + } + ] +} \ No newline at end of file diff --git a/config/polygon.json b/config/polygon.json new file mode 100644 index 0000000..8d8578f --- /dev/null +++ b/config/polygon.json @@ -0,0 +1,27 @@ +{ + "network": "matic", + "erc721": [ + { + "name": "AavegotchiDiamond", + "address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d", + "startBlock": 11516320 + }, + { + "name": "RealmDiamond", + "address": "0x1D0360BaC7299C86Ec8E99d0c1C9A95FEfaF2a11", + "startBlock": 20667840 + }, + { + "name": "ChronosTravaler", + "address": "0xa03c4e40d1fcaa826591007a17ca929ef8adbf1c", + "startBlock": 36796276 + } + ], + "erc1155": [ + { + "name": "WearablesDiamond", + "address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f", + "startBlock": 35999793 + } + ] +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e4b76f2..f4fd276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,8 @@ "version": "1.0.0", "license": "CC0-1.0", "dependencies": { - "@graphprotocol/graph-cli": "^0.55.0" + "@graphprotocol/graph-cli": "^0.55.0", + "mustache": "^4.2.0" }, "devDependencies": { "@graphprotocol/graph-ts": "^0.31.0", @@ -5444,6 +5445,14 @@ "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" }, + "node_modules/mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "bin": { + "mustache": "bin/mustache" + } + }, "node_modules/nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", @@ -11420,6 +11429,11 @@ "resolved": "https://registry.npmjs.org/multiformats/-/multiformats-9.9.0.tgz", "integrity": "sha512-HoMUjhH9T8DDBNT+6xzkrd9ga/XiBI4xLr58LJACwK6G3HTOPeMz4nB4KJs33L2BelrIJa7P0VuNaVF3hMYfjg==" }, + "mustache": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==" + }, "nanoid": { "version": "3.3.6", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", diff --git a/package.json b/package.json index 2eff698..ab1a64f 100644 --- a/package.json +++ b/package.json @@ -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": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml", + "build:mumbai": "mustache ./config/mumbai.json subgraph.template.yaml > subgraph.yamll && graph codegen subgraph.yaml && graph build subgraph.yaml", + "build:polygon": "mustache ./config/polygon.json subgraph.template.yaml > subgraph.yaml && 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", @@ -22,7 +22,8 @@ "lint:staged": "npx lint-staged" }, "dependencies": { - "@graphprotocol/graph-cli": "^0.55.0" + "@graphprotocol/graph-cli": "^0.55.0", + "mustache": "^4.2.0" }, "devDependencies": { "@graphprotocol/graph-ts": "^0.31.0", diff --git a/subgraph-goerli.yaml b/subgraph-goerli.yaml deleted file mode 100644 index f50547f..0000000 --- a/subgraph-goerli.yaml +++ /dev/null @@ -1,71 +0,0 @@ -specVersion: 0.0.4 -schema: - file: ./schema.graphql -dataSources: - - name: ERC721 - kind: ethereum - network: goerli - source: - abi: ERC721 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - abis: - - name: ERC721 - file: ./abis/ERC721.json - eventHandlers: - - event: Transfer(indexed address,indexed address,indexed uint256) - handler: handleTransfer - file: ./src/erc721/index.ts - - - name: ERC7432 - kind: ethereum - network: goerli - source: - abi: ERC7432 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - - RoleAssignment - - RoleApproval - abis: - - name: ERC7432 - file: ./abis/ERC7432.json - eventHandlers: - - event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,address,uint64,bool,bytes) - handler: handleRoleGranted - - event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address,address) - handler: handleRoleRevoked - - event: RoleApprovalForAll(indexed address,indexed address,bool) - handler: handleRoleApprovalForAll - file: ./src/erc7432/index.ts - - - name: ERC1155 - kind: ethereum - network: goerli - source: - abi: ERC1155 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - abis: - - name: ERC1155 - file: ./abis/ERC1155.json - eventHandlers: - - event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256) - handler: handleTransferSingle - - event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[]) - handler: handleTransferBatch - file: ./src/erc1155/index.ts diff --git a/subgraph-mumbai.yaml b/subgraph-mumbai.yaml deleted file mode 100644 index b58e4c0..0000000 --- a/subgraph-mumbai.yaml +++ /dev/null @@ -1,72 +0,0 @@ -specVersion: 0.0.4 -schema: - file: ./schema.graphql -dataSources: - - name: ERC721 - kind: ethereum - network: mumbai - source: - abi: ERC721 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - abis: - - name: ERC721 - file: ./abis/ERC721.json - eventHandlers: - - event: Transfer(indexed address,indexed address,indexed uint256) - handler: handleTransfer - file: ./src/erc721/index.ts - - - name: ERC7432 - kind: ethereum - network: mumbai - source: - abi: ERC7432 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - - RoleAssignment - - RoleApproval - abis: - - name: ERC7432 - file: ./abis/ERC7432.json - eventHandlers: - - event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,address,uint64,bool,bytes) - handler: handleRoleGranted - - event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address,address) - handler: handleRoleRevoked - - event: RoleApprovalForAll(indexed address,indexed address,bool) - handler: handleRoleApprovalForAll - file: ./src/erc7432/index.ts - - - name: ERC1155 - kind: ethereum - network: mumbai - source: - abi: ERC1155 - mapping: - kind: ethereum/events - apiVersion: 0.0.6 - language: wasm/assemblyscript - entities: - - Nft - - Account - abis: - - name: ERC1155 - file: ./abis/ERC1155.json - eventHandlers: - - event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256) - handler: handleTransferSingle - - event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[]) - handler: handleTransferBatch - file: ./src/erc1155/index.ts - diff --git a/subgraph-polygon.yaml b/subgraph.template.yaml similarity index 88% rename from subgraph-polygon.yaml rename to subgraph.template.yaml index 690b994..c811120 100644 --- a/subgraph-polygon.yaml +++ b/subgraph.template.yaml @@ -2,11 +2,15 @@ specVersion: 0.0.4 schema: file: ./schema.graphql dataSources: - - name: ERC721 + +{{#erc721}} + - name: {{name}} kind: ethereum network: matic source: abi: ERC721 + address: '{{address}}' + startBlock: {{startBlock}} mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -21,12 +25,16 @@ dataSources: - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer file: ./src/erc721/index.ts +{{/erc721}} - - name: ERC7432 +{{#erc1155}} + - name: {{name}} kind: ethereum network: matic source: - abi: ERC7432 + abi: ERC1155 + address: '{{address}}' + startBlock: {{startBlock}} mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -34,25 +42,22 @@ dataSources: entities: - Nft - Account - - RoleAssignment - - RoleApproval abis: - - name: ERC7432 - file: ./abis/ERC7432.json + - name: ERC1155 + file: ./abis/ERC1155.json eventHandlers: - - event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,address,uint64,bool,bytes) - handler: handleRoleGranted - - event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address,address) - handler: handleRoleRevoked - - event: RoleApprovalForAll(indexed address,indexed address,bool) - handler: handleRoleApprovalForAll - file: ./src/erc7432/index.ts + - event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256) + handler: handleTransferSingle + - event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[]) + handler: handleTransferBatch + file: ./src/erc1155/index.ts +{{/erc1155}} - - name: ERC1155 + - name: ERC7432 kind: ethereum network: matic source: - abi: ERC1155 + abi: ERC7432 mapping: kind: ethereum/events apiVersion: 0.0.6 @@ -60,12 +65,16 @@ dataSources: entities: - Nft - Account + - RoleAssignment + - RoleApproval abis: - - name: ERC1155 - file: ./abis/ERC1155.json + - name: ERC7432 + file: ./abis/ERC7432.json eventHandlers: - - event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256) - handler: handleTransferSingle - - event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[]) - handler: handleTransferBatch - file: ./src/erc1155/index.ts + - event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,address,uint64,bool,bytes) + handler: handleRoleGranted + - event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address,address) + handler: handleRoleRevoked + - event: RoleApprovalForAll(indexed address,indexed address,bool) + handler: handleRoleApprovalForAll + file: ./src/erc7432/index.ts \ No newline at end of file From 89d406a1886129cfb2aff2e25a60e972ada29f9f Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 30 Oct 2023 16:01:06 -0300 Subject: [PATCH 2/6] ON-509: update mustache config --- config/goerli.json | 2 +- config/mumbai.json | 4 ++-- config/polygon.json | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/config/goerli.json b/config/goerli.json index b80ad47..d05f302 100644 --- a/config/goerli.json +++ b/config/goerli.json @@ -2,7 +2,7 @@ "network": "goerli", "erc721": [ { - "name": "ChronosTravaler", + "name": "ERC721", "address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32", "startBlock": 8099655 } diff --git a/config/mumbai.json b/config/mumbai.json index 3dae87c..3db4d64 100644 --- a/config/mumbai.json +++ b/config/mumbai.json @@ -2,7 +2,7 @@ "network": "mumbai", "erc721": [ { - "name": "AavegotchiDiamond", + "name": "ERC721", "address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e", "startBlock": 34467860 }, @@ -14,7 +14,7 @@ ], "erc1155": [ { - "name": "WearablesDiamond", + "name": "ERC1155", "address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8", "startBlock": 34467877 } diff --git a/config/polygon.json b/config/polygon.json index 8d8578f..e8d83ac 100644 --- a/config/polygon.json +++ b/config/polygon.json @@ -1,25 +1,25 @@ { "network": "matic", "erc721": [ - { - "name": "AavegotchiDiamond", + { + "name": "ERC721", "address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d", "startBlock": 11516320 }, - { + { "name": "RealmDiamond", "address": "0x1D0360BaC7299C86Ec8E99d0c1C9A95FEfaF2a11", "startBlock": 20667840 }, - { + { "name": "ChronosTravaler", "address": "0xa03c4e40d1fcaa826591007a17ca929ef8adbf1c", "startBlock": 36796276 } ], "erc1155": [ - { - "name": "WearablesDiamond", + { + "name": "ERC1155", "address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f", "startBlock": 35999793 } From 459fbc6f7a0b4460a635f2345a41a43a512622b3 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 30 Oct 2023 17:01:48 -0300 Subject: [PATCH 3/6] fix mustache --- package.json | 2 +- subgraph.template.yaml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ab1a64f..bcf0fc1 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "graph:auth": "graph auth --product hosted-service", "build:goerli": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml", - "build:mumbai": "mustache ./config/mumbai.json subgraph.template.yaml > subgraph.yamll && graph codegen subgraph.yaml && graph build subgraph.yaml", + "build:mumbai": "mustache ./config/mumbai.json subgraph.template.yaml > subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml", "build:polygon": "mustache ./config/polygon.json subgraph.template.yaml > subgraph.yaml && 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", diff --git a/subgraph.template.yaml b/subgraph.template.yaml index c811120..20b2268 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -6,7 +6,7 @@ dataSources: {{#erc721}} - name: {{name}} kind: ethereum - network: matic + network: {{network}} source: abi: ERC721 address: '{{address}}' @@ -30,7 +30,7 @@ dataSources: {{#erc1155}} - name: {{name}} kind: ethereum - network: matic + network: {{network}} source: abi: ERC1155 address: '{{address}}' @@ -55,7 +55,7 @@ dataSources: - name: ERC7432 kind: ethereum - network: matic + network: {{network}} source: abi: ERC7432 mapping: From 89731bdaf949d2ea44bf6f8696d31e011bbf4042 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 30 Oct 2023 18:13:17 -0300 Subject: [PATCH 4/6] update first element logic mustache --- config/goerli.json | 5 +++-- config/mumbai.json | 16 +++++++++------- config/polygon.json | 10 ++++++---- subgraph.template.yaml | 12 ++++++++++++ 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/config/goerli.json b/config/goerli.json index d05f302..27275c3 100644 --- a/config/goerli.json +++ b/config/goerli.json @@ -2,9 +2,10 @@ "network": "goerli", "erc721": [ { - "name": "ERC721", + "name": "AavegotchiDiamond", "address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32", - "startBlock": 8099655 + "startBlock": 8099655, + "isFirstElement": true } ] } \ No newline at end of file diff --git a/config/mumbai.json b/config/mumbai.json index 3db4d64..ec966ce 100644 --- a/config/mumbai.json +++ b/config/mumbai.json @@ -1,22 +1,24 @@ { "network": "mumbai", "erc721": [ - { - "name": "ERC721", + { + "name": "AavegotchiDiamond", "address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e", - "startBlock": 34467860 + "startBlock": 34467860, + "isFirstElement": true }, - { + { "name": "RealmDiamond", "address": "0xBcCf68d104aCEa36b1EA20BBE8f06ceD12CaC008", "startBlock": 38134604 } ], "erc1155": [ - { - "name": "ERC1155", + { + "name": "WearableDiamond", "address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8", - "startBlock": 34467877 + "startBlock": 34467877, + "isFirstElement": true } ] } \ No newline at end of file diff --git a/config/polygon.json b/config/polygon.json index e8d83ac..1d58a02 100644 --- a/config/polygon.json +++ b/config/polygon.json @@ -2,9 +2,10 @@ "network": "matic", "erc721": [ { - "name": "ERC721", + "name": "AavegotchiDiamond", "address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d", - "startBlock": 11516320 + "startBlock": 11516320, + "isFirstElement": true }, { "name": "RealmDiamond", @@ -19,9 +20,10 @@ ], "erc1155": [ { - "name": "ERC1155", + "name": "WearableDiamond", "address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f", - "startBlock": 35999793 + "startBlock": 35999793, + "isFirstElement": true } ] } \ No newline at end of file diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 20b2268..bd1bb6a 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -4,7 +4,12 @@ schema: dataSources: {{#erc721}} + {{#isFirstElement}} + - name: ERC721 + {{/isFirstElement}} + {{^isFirstElement}} - name: {{name}} + {{/isFirstElement}} kind: ethereum network: {{network}} source: @@ -28,7 +33,12 @@ dataSources: {{/erc721}} {{#erc1155}} + {{#isFirstElement}} + - name: ERC1155 + {{/isFirstElement}} + {{^isFirstElement}} - name: {{name}} + {{/isFirstElement}} kind: ethereum network: {{network}} source: @@ -70,6 +80,8 @@ dataSources: abis: - name: ERC7432 file: ./abis/ERC7432.json + - name: ERC721 + file: ./abis/ERC721.json eventHandlers: - event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,address,uint64,bool,bytes) handler: handleRoleGranted From 24a0cd8ea35af684799c1d9d011128c41f39c0a4 Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Mon, 30 Oct 2023 21:55:41 -0300 Subject: [PATCH 5/6] mustache custom script --- config/goerli.json | 3 +-- config/mumbai.json | 6 ++--- config/polygon.json | 6 ++--- mustache.config.js | 60 ++++++++++++++++++++++++++++++++++++++++++ package.json | 6 ++--- subgraph.template.yaml | 4 +-- 6 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 mustache.config.js diff --git a/config/goerli.json b/config/goerli.json index 27275c3..be8ad76 100644 --- a/config/goerli.json +++ b/config/goerli.json @@ -4,8 +4,7 @@ { "name": "AavegotchiDiamond", "address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32", - "startBlock": 8099655, - "isFirstElement": true + "startBlock": 8099655 } ] } \ No newline at end of file diff --git a/config/mumbai.json b/config/mumbai.json index ec966ce..19de5f5 100644 --- a/config/mumbai.json +++ b/config/mumbai.json @@ -4,8 +4,7 @@ { "name": "AavegotchiDiamond", "address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e", - "startBlock": 34467860, - "isFirstElement": true + "startBlock": 34467860 }, { "name": "RealmDiamond", @@ -17,8 +16,7 @@ { "name": "WearableDiamond", "address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8", - "startBlock": 34467877, - "isFirstElement": true + "startBlock": 34467877 } ] } \ No newline at end of file diff --git a/config/polygon.json b/config/polygon.json index 1d58a02..608d4c0 100644 --- a/config/polygon.json +++ b/config/polygon.json @@ -4,8 +4,7 @@ { "name": "AavegotchiDiamond", "address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d", - "startBlock": 11516320, - "isFirstElement": true + "startBlock": 11516320 }, { "name": "RealmDiamond", @@ -22,8 +21,7 @@ { "name": "WearableDiamond", "address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f", - "startBlock": 35999793, - "isFirstElement": true + "startBlock": 35999793 } ] } \ No newline at end of file diff --git a/mustache.config.js b/mustache.config.js new file mode 100644 index 0000000..4fa05ce --- /dev/null +++ b/mustache.config.js @@ -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) + }) diff --git a/package.json b/package.json index bcf0fc1..b0414fa 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ }, "scripts": { "graph:auth": "graph auth --product hosted-service", - "build:goerli": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml", - "build:mumbai": "mustache ./config/mumbai.json subgraph.template.yaml > subgraph.yaml && graph codegen subgraph.yaml && graph build subgraph.yaml", - "build:polygon": "mustache ./config/polygon.json subgraph.template.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", diff --git a/subgraph.template.yaml b/subgraph.template.yaml index bd1bb6a..1d1fedc 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -3,7 +3,7 @@ schema: file: ./schema.graphql dataSources: -{{#erc721}} + {{#erc721}} {{#isFirstElement}} - name: ERC721 {{/isFirstElement}} @@ -30,7 +30,7 @@ dataSources: - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer file: ./src/erc721/index.ts -{{/erc721}} + {{/erc721}} {{#erc1155}} {{#isFirstElement}} From f8848395c6e6bb0c327f7f0a05b082c80f8c489d Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 31 Oct 2023 11:50:41 -0300 Subject: [PATCH 6/6] ON-509: pr fixes --- config/goerli.json | 2 +- config/mumbai.json | 6 +++--- config/polygon.json | 6 +++--- package-lock.json | 8 +++++--- package.json | 4 ++-- subgraph.template.yaml | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/config/goerli.json b/config/goerli.json index be8ad76..c01c7d5 100644 --- a/config/goerli.json +++ b/config/goerli.json @@ -2,7 +2,7 @@ "network": "goerli", "erc721": [ { - "name": "AavegotchiDiamond", + "name": "ChronosTraveler", "address": "0x450c91d1fe9f3d57b91218f6ff96f7994eec4d32", "startBlock": 8099655 } diff --git a/config/mumbai.json b/config/mumbai.json index 19de5f5..d03a731 100644 --- a/config/mumbai.json +++ b/config/mumbai.json @@ -2,19 +2,19 @@ "network": "mumbai", "erc721": [ { - "name": "AavegotchiDiamond", + "name": "AavegotchiGotchi", "address": "0x83e73D9CF22dFc3A767EA1cE0611F7f50306622e", "startBlock": 34467860 }, { - "name": "RealmDiamond", + "name": "AavegotchiParcel", "address": "0xBcCf68d104aCEa36b1EA20BBE8f06ceD12CaC008", "startBlock": 38134604 } ], "erc1155": [ { - "name": "WearableDiamond", + "name": "AavegotchiWearable", "address": "0x1b1bcB49A744a09aEd636CDD9893508BdF1431A8", "startBlock": 34467877 } diff --git a/config/polygon.json b/config/polygon.json index 608d4c0..d8cfbc3 100644 --- a/config/polygon.json +++ b/config/polygon.json @@ -2,12 +2,12 @@ "network": "matic", "erc721": [ { - "name": "AavegotchiDiamond", + "name": "AavegotchiGotchi", "address": "0x86935f11c86623dec8a25696e1c19a8659cbf95d", "startBlock": 11516320 }, { - "name": "RealmDiamond", + "name": "AavegotchiParcel", "address": "0x1D0360BaC7299C86Ec8E99d0c1C9A95FEfaF2a11", "startBlock": 20667840 }, @@ -19,7 +19,7 @@ ], "erc1155": [ { - "name": "WearableDiamond", + "name": "AavegotchiWearable", "address": "0x58de9aabcaeec0f69883c94318810ad79cc6a44f", "startBlock": 35999793 } diff --git a/package-lock.json b/package-lock.json index f4fd276..75dc639 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,7 @@ "version": "1.0.0", "license": "CC0-1.0", "dependencies": { - "@graphprotocol/graph-cli": "^0.55.0", - "mustache": "^4.2.0" + "@graphprotocol/graph-cli": "^0.55.0" }, "devDependencies": { "@graphprotocol/graph-ts": "^0.31.0", @@ -19,6 +18,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" } }, @@ -5449,6 +5449,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "dev": true, "bin": { "mustache": "bin/mustache" } @@ -11432,7 +11433,8 @@ "mustache": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz", - "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==" + "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==", + "dev": true }, "nanoid": { "version": "3.3.6", diff --git a/package.json b/package.json index b0414fa..c565b71 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,7 @@ "lint:staged": "npx lint-staged" }, "dependencies": { - "@graphprotocol/graph-cli": "^0.55.0", - "mustache": "^4.2.0" + "@graphprotocol/graph-cli": "^0.55.0" }, "devDependencies": { "@graphprotocol/graph-ts": "^0.31.0", @@ -32,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": { diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 1d1fedc..bd1bb6a 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -3,7 +3,7 @@ schema: file: ./schema.graphql dataSources: - {{#erc721}} +{{#erc721}} {{#isFirstElement}} - name: ERC721 {{/isFirstElement}} @@ -30,7 +30,7 @@ dataSources: - event: Transfer(indexed address,indexed address,indexed uint256) handler: handleTransfer file: ./src/erc721/index.ts - {{/erc721}} +{{/erc721}} {{#erc1155}} {{#isFirstElement}}