├── README.md ├── arweave └── blocks-transactions │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── package.json │ ├── schema.graphql │ ├── src │ └── blocks.ts │ ├── subgraph.yaml │ └── yarn.lock ├── cosmos ├── block-filtering │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── config │ │ ├── cosmoshub.json │ │ └── osmosis.json │ ├── docker-compose.yml │ ├── package.json │ ├── schema.graphql │ ├── src │ │ └── mapping.ts │ ├── subgraph.template.yaml │ ├── subgraph.yaml │ ├── tsconfig.json │ └── yarn.lock ├── osmosis-token-swaps │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── docker-compose.yml │ ├── package.json │ ├── schema.graphql │ ├── src │ │ └── mapping.ts │ ├── subgraph.yaml │ ├── tsconfig.json │ └── yarn.lock ├── validator-delegations │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── config │ │ ├── cosmoshub.json │ │ └── osmosis.json │ ├── docker-compose.yml │ ├── package.json │ ├── schema.graphql │ ├── src │ │ ├── decoding.ts │ │ └── mapping.ts │ ├── subgraph.template.yaml │ ├── subgraph.yaml │ ├── tsconfig.json │ └── yarn.lock └── validator-rewards │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── config │ ├── cosmoshub.json │ └── osmosis.json │ ├── docker-compose.yml │ ├── package.json │ ├── schema.graphql │ ├── src │ └── mapping.ts │ ├── subgraph.template.yaml │ ├── subgraph.yaml │ ├── tsconfig.json │ └── yarn.lock ├── ethereum └── gravatar │ ├── .gitattributes │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── abis │ └── Gravity.json │ ├── bin │ └── Counter.bin │ ├── contracts │ ├── Gravity.sol │ └── Migrations.sol │ ├── docker-compose.yml │ ├── migrations │ ├── 1_initial_migration.js │ ├── 2_deploy_contract.js │ └── 3_create_gravatars.js │ ├── package.json │ ├── schema.graphql │ ├── src │ └── mapping.ts │ ├── subgraph.yaml │ ├── truffle.js │ └── yarn.lock └── near ├── blocks-example ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── package.json ├── schema.graphql ├── src │ └── mapping.ts ├── subgraph.yaml ├── tsconfig.json └── yarn.lock └── receipts-example ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── package.json ├── schema.graphql ├── src └── mapping.ts ├── subgraph.yaml └── yarn.lock /README.md: -------------------------------------------------------------------------------- 1 | # Example Subgraph 2 | 3 | Example subgraphs have been moved to the [Graph Tooling repository](https://github.com/graphprotocol/graph-tooling/tree/main/examples) 4 | 5 | For more information see the docs on https://thegraph.com/docs/. 6 | -------------------------------------------------------------------------------- /arweave/blocks-transactions/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /arweave/blocks-transactions/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /arweave/blocks-transactions/README.md: -------------------------------------------------------------------------------- 1 | # Arweave Blocks and Transactions Example 2 | This subgraph is indexing blocks, transactions, tags, and POAs. Make sure to replace the `owner` field inside the .yaml file with the owner id. 3 | 4 | > NOTE: The id of an owner is not required, the subgraph can index all blocks and transactions. 5 | 6 | ### Dev Dependencies 7 | To be able to build an Arweave subgraph, you need a graph-cli version of 0.30.2 or above. Run the command below to update to the latest version: 8 | 9 | ``` 10 | npm-update -g i @graphprotocol/graph-cli 11 | ``` 12 | 13 | ### Querying the Subgraph 14 | With the following query, you can retrieve all the appended blocks between two dates: 15 | ```graphql 16 | query BlocksBetweenDates($timestamp_start: BigInt!, $timestamp_end: BigInt!) { 17 | blocks(where: {timestamp_gt: $timestamp_start, timestamp_lt: $timestamp_end}) { 18 | id 19 | timestamp 20 | height 21 | } 22 | } 23 | ``` 24 | 25 | For more information see the docs on https://thegraph.com/docs/. 26 | -------------------------------------------------------------------------------- /arweave/blocks-transactions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "subgraph-arweave-example", 3 | "version": "0.1.0", 4 | "description": "subgraph example for Arweave", 5 | "repository": "https://github.com/graphprotocol/example-subgraph", 6 | "license": "MIT", 7 | 8 | "scripts": { 9 | "codegen": "graph codegen", 10 | "build": "graph build", 11 | "create-local": "graph create arweave-example --node http://localhost:8020", 12 | "deploy-local": "graph deploy arweave-example -l v0.1.0 --ipfs http://localhost:5001 --node http://localhost:8020", 13 | "remove-local": "graph remove arweave-example --node http://localhost:8020", 14 | "create": "graph create arweave-example --node https://api.thegraph.com/deploy/", 15 | "deploy": "graph deploy arweave-example --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/" 16 | }, 17 | 18 | "devDependencies": { 19 | "@graphprotocol/graph-cli": "^0.30.2", 20 | "@graphprotocol/graph-ts": "^0.27.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /arweave/blocks-transactions/schema.graphql: -------------------------------------------------------------------------------- 1 | type Block @entity { 2 | id: ID! 3 | 4 | timestamp: BigInt! 5 | last_retarget: BigInt! 6 | height: BigInt! 7 | indep_hash: Bytes! 8 | nonce: Bytes! 9 | previous_block: Bytes! 10 | diff: Bytes! 11 | hash: Bytes! 12 | tx_root: Bytes! 13 | txs: [Bytes!]! 14 | wallet_list: Bytes! 15 | reward_addr: Bytes! 16 | tags: [Tag!]! 17 | reward_pool: Bytes! 18 | weave_size: Bytes! 19 | block_size: Bytes! 20 | cumulative_diff: Bytes! 21 | hash_list_merkle: Bytes! 22 | poa: Poa 23 | } 24 | 25 | type Transaction @entity { 26 | id: ID! 27 | 28 | block: Block! 29 | tx_id: Bytes! 30 | last_tx: Bytes! 31 | owner: Bytes! 32 | tags: [Tag!]! 33 | target: Bytes! 34 | quantity: Bytes! 35 | data: Bytes! 36 | data_size: Bytes! 37 | data_root: Bytes! 38 | signature: Bytes! 39 | reward: Bytes! 40 | } 41 | 42 | type Poa @entity { 43 | id: ID! 44 | 45 | option: String! 46 | tx_path: Bytes! 47 | data_path: Bytes! 48 | chunk: Bytes! 49 | } 50 | 51 | type Tag @entity { 52 | id: ID! 53 | 54 | name: Bytes! 55 | value: Bytes! 56 | } 57 | -------------------------------------------------------------------------------- /arweave/blocks-transactions/src/blocks.ts: -------------------------------------------------------------------------------- 1 | import { arweave, BigInt } from "@graphprotocol/graph-ts" 2 | import { Block, Poa, Tag, Transaction } from "../generated/schema" 3 | 4 | function savePoa(id: string, poa: arweave.ProofOfAccess): string { 5 | const p = new Poa(id); 6 | 7 | p.option = poa.option; 8 | p.chunk = poa.chunk; 9 | p.data_path = poa.dataPath; 10 | p.tx_path = poa.txPath; 11 | 12 | p.save(); 13 | 14 | return id; 15 | } 16 | 17 | function saveTags(id: string, tags: arweave.Tag[]): string[] { 18 | for (let i = 0; i < tags.length; i++) { 19 | const rawTag = tags[i]; 20 | const tag = new Tag(id); 21 | 22 | tag.name = rawTag.name; 23 | tag.value = rawTag.value; 24 | 25 | tag.save(); 26 | } 27 | 28 | return new Array(tags.length).fill(id); 29 | } 30 | 31 | export function handleBlock(block: arweave.Block): void { 32 | let hash = bytesToBase64(block.indepHash, true); 33 | let entity = new Block(hash); 34 | 35 | entity.height = BigInt.fromU64(block.height); 36 | entity.timestamp = BigInt.fromU64(block.timestamp); 37 | entity.indep_hash = block.indepHash; 38 | entity.nonce = block.nonce; 39 | entity.previous_block = block.previousBlock; 40 | entity.last_retarget = BigInt.fromU64(block.lastRetarget); 41 | entity.diff = block.diff; 42 | entity.hash = block.hash; 43 | entity.tx_root = block.txRoot; 44 | entity.txs = block.txs; 45 | entity.wallet_list = block.walletList; 46 | entity.reward_addr = block.rewardAddr; 47 | entity.tags = saveTags(hash, block.tags); 48 | entity.reward_pool = block.rewardPool; 49 | entity.weave_size = block.weaveSize; 50 | entity.block_size = block.blockSize; 51 | entity.cumulative_diff = block.cumulativeDiff; 52 | entity.hash_list_merkle = block.hashListMerkle; 53 | entity.poa = savePoa(hash, block.poa) 54 | 55 | entity.save() 56 | } 57 | 58 | 59 | export function handleTx(tb: arweave.TransactionWithBlockPtr): void { 60 | const tx = tb.tx; 61 | const entity = new Transaction(bytesToBase64(tx.id,true)); 62 | 63 | entity.block = bytesToBase64(tb.block.indepHash, true); 64 | entity.tx_id = tx.id; 65 | entity.last_tx = tx.lastTx; 66 | entity.owner = tx.owner; 67 | entity.tags = saveTags(tx.id.toHexString(), tx.tags); 68 | entity.data = tx.data; 69 | entity.data_root = tx.dataRoot; 70 | entity.data_size = tx.dataSize; 71 | entity.target = tx.target; 72 | entity.quantity = tx.quantity; 73 | entity.signature = tx.signature; 74 | entity.reward = tx.reward; 75 | 76 | entity.save(); 77 | } 78 | 79 | const base64Alphabet = [ 80 | "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 81 | "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", 82 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 83 | "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 84 | "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/" 85 | ]; 86 | 87 | const base64UrlAlphabet = [ 88 | "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 89 | "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", 90 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 91 | "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 92 | "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "_" 93 | ]; 94 | 95 | function bytesToBase64(bytes: Uint8Array, urlSafe: boolean): string { 96 | let alphabet = urlSafe? base64UrlAlphabet : base64Alphabet; 97 | 98 | let result = '', i: i32, l = bytes.length; 99 | for (i = 2; i < l; i += 3) { 100 | result += alphabet[bytes[i - 2] >> 2]; 101 | result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]; 102 | result += alphabet[((bytes[i - 1] & 0x0F) << 2) | (bytes[i] >> 6)]; 103 | result += alphabet[bytes[i] & 0x3F]; 104 | } 105 | if (i === l + 1) { // 1 octet yet to write 106 | result += alphabet[bytes[i - 2] >> 2]; 107 | result += alphabet[(bytes[i - 2] & 0x03) << 4]; 108 | if (!urlSafe) { 109 | result += "=="; 110 | } 111 | } 112 | if (!urlSafe && i === l) { // 2 octets yet to write 113 | result += alphabet[bytes[i - 2] >> 2]; 114 | result += alphabet[((bytes[i - 2] & 0x03) << 4) | (bytes[i - 1] >> 4)]; 115 | result += alphabet[(bytes[i - 1] & 0x0F) << 2]; 116 | if (!urlSafe) { 117 | result += "="; 118 | } 119 | } 120 | return result; 121 | } -------------------------------------------------------------------------------- /arweave/blocks-transactions/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Arweave Blocks Indexing 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: arweave 8 | name: arweave-blocks 9 | network: arweave-mainnet 10 | source: 11 | owner: "x-62w7g2yKACOgP_d04bhG8IX-AWgPrxHl2JgZBDdNLfAsidiiAaoIZPeM8K5gGvl7-8QVk79YV4OC878Ey0gXi7Atj5BouRyXnFMjJcPVXVyBoYCBuG7rJDDmh4_Ilon6vVOuHVIZ47Vb0tcgsxgxdvVFC2mn9N_SBl23pbeICNJZYOH57kf36gicuV_IwYSdqlQ0HQ_psjmg8EFqO7xzvAMP5HKW3rqTrYZxbCew2FkM734ysWckT39TpDBPx3HrFOl6obUdQWkHNOeKyzcsKFDywNgVWZOb89CYU7JFYlwX20io39ZZv0UJUOEFNjtVHkT_s0_A2O9PltsrZLLlQXZUuYASdbAPD2g_qXfhmPBZ0SXPWCDY-UVwVN1ncwYmk1F_i35IA8kAKsajaltD2wWDQn9g5mgJAWWn2xhLqkbwGbdwQMRD0-0eeuy1uzCooJQCC_bPJksoqkYwB9SGOjkayf4r4oZ2QDY4FicCsswz4Od_gud30ZWyHjWgqGzSFYFzawDBS1Gr_nu_q5otFrv20ZGTxYqGsLHWq4VHs6KjsQvzgBjfyb0etqHQEPJJmbQmY3LSogR4bxdReUHhj2EK9xIB-RKzDvDdL7fT5K0V9MjbnC2uktA0VjLlvwJ64_RhbQhxdp_zR39r-zyCXT-brPEYW1-V7Ey9K3XUE" 12 | startBlock: 0 13 | mapping: 14 | apiVersion: 0.0.5 15 | language: wasm/assemblyscript 16 | file: ./src/blocks.ts 17 | entities: 18 | - Block 19 | - Tag 20 | - Transaction 21 | - Poa 22 | blockHandlers: 23 | - handler: handleBlock 24 | transactionHandlers: 25 | - handler: handleTx 26 | -------------------------------------------------------------------------------- /cosmos/block-filtering/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /cosmos/block-filtering/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cosmos/block-filtering/README.md: -------------------------------------------------------------------------------- 1 | # Block Filtering Example 2 | 3 | This example subgraph stores `Block` objects that represent blocks appended to a Cosmos chain. It's a very simple implementation where just the block number and the block timestamp is saved to the store. 4 | 5 | ## Generating a manifest 6 | 7 | The subgraph is compatible with multiple Cosmos networks so before building the subgraph you need to generate a manifest file for the network of your choice. In case of the Cosmos Hub network, run the following command: 8 | 9 | ```shell 10 | $ yarn prepare:cosmoshub 11 | ``` 12 | 13 | For the list of supported networks, see the scripts in the [`package.json`](package.json) file. 14 | 15 | ## Querying the subgraph 16 | 17 | With the following query, you can retrieve all the appended blocks between two dates: 18 | 19 | ``` 20 | query BlocksBetweenDates($timestamp_start: BigInt!, $timestamp_end: BigInt!) { 21 | blocks(where: {timestamp_gt: $timestamp_start, timestamp_lt: $timestamp_end}) { 22 | id, 23 | number, 24 | timestamp 25 | } 26 | } 27 | ``` 28 | ``` 29 | { 30 | "timestamp_start": 1613653200, 31 | "timestamp_end": 1613656800 32 | } 33 | ``` 34 | 35 | For more information see the docs on https://thegraph.com/docs/. 36 | -------------------------------------------------------------------------------- /cosmos/block-filtering/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/block-filtering/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/block-filtering/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /cosmos/block-filtering/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cosmos-block-filtering", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepare:cosmoshub": "mustache config/cosmoshub.json subgraph.template.yaml > subgraph.yaml", 8 | "prepare:osmosis": "mustache config/osmosis.json subgraph.template.yaml > subgraph.yaml", 9 | "codegen": "graph codegen", 10 | "build": "graph build", 11 | "create-local": "graph create cosmos-block-filtering --node http://127.0.0.1:8020", 12 | "deploy-local": "graph deploy cosmos-block-filtering -l v0.1.0 --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", 13 | "remove-local": "graph remove cosmos-block-filtering --node http://127.0.0.1:8020", 14 | "create": "graph create cosmos-block-filtering --node https://api.thegraph.com/deploy/", 15 | "deploy": "graph deploy cosmos-block-filtering --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/" 16 | }, 17 | "devDependencies": { 18 | "@graphprotocol/graph-cli": "^0.30.0", 19 | "@graphprotocol/graph-ts": "^0.27.0", 20 | "mustache": "^4.2.0" 21 | }, 22 | "dependencies": { 23 | "babel-polyfill": "^6.26.0", 24 | "babel-register": "^6.26.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cosmos/block-filtering/schema.graphql: -------------------------------------------------------------------------------- 1 | type Block @entity { 2 | id: ID! 3 | number: BigInt 4 | timestamp: BigInt 5 | } 6 | -------------------------------------------------------------------------------- /cosmos/block-filtering/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { BigInt, cosmos } from "@graphprotocol/graph-ts"; 2 | import { Block } from "../generated/schema"; 3 | 4 | export function handleBlock(bl: cosmos.Block): void { 5 | const hash = bl.header.hash.toHexString(); 6 | const height = BigInt.fromString(bl.header.height.toString()); 7 | 8 | const block = new Block(hash); 9 | 10 | block.number = height; 11 | block.timestamp = BigInt.fromString(bl.header.time.seconds.toString()); 12 | 13 | block.save(); 14 | } 15 | -------------------------------------------------------------------------------- /cosmos/block-filtering/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Block Filtering Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: {{ name }} 9 | network: {{ network }} 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Block 17 | blockHandlers: 18 | - handler: handleBlock 19 | file: ./src/mapping.ts 20 | -------------------------------------------------------------------------------- /cosmos/block-filtering/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Block Filtering Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Block 17 | blockHandlers: 18 | - handler: handleBlock 19 | file: ./src/mapping.ts 20 | -------------------------------------------------------------------------------- /cosmos/block-filtering/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/README.md: -------------------------------------------------------------------------------- 1 | # Osmosis Token Swaps Example 2 | 3 | This example subgraph stores `TokenSwap` objects that represents token swaps made using the [GAMM](https://docs.osmosis.zone/developing/osmosis-core/modules/spec-gamm.html) (Generalized Automated Market Maker) in the Osmosis chain. In order to do that, an event handler is used to filter [token_swapped](https://github.com/osmosis-labs/osmosis/blob/c8ac95c6a6ea42e934d49599eafc8609b3c6fe61/x/gamm/types/events.go#L13) events. The type of event to be filtered is specified in the subgraph manifest file. That way, the handler will just receive events of that type. 4 | 5 | By running this example subgraph, and with the following query, you can retrieve all the swaps made by a given address: 6 | 7 | ``` 8 | query SwapsForAccount($senderAddress: String!) { 9 | tokenSwaps(where: {sender: $senderAddress}) { 10 | tokenIn { 11 | amount 12 | denom 13 | }, 14 | tokenOut { 15 | amount 16 | denom 17 | } 18 | } 19 | } 20 | ``` 21 | ``` 22 | { 23 | "senderAddress": "osmo1wd3j7cvcnr3pfey4fx2mz9xml9euu68z6zg0xp" 24 | } 25 | ``` 26 | For more information see the docs on https://thegraph.com/docs/. -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "osmosis-token-swaps", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "codegen": "graph codegen", 8 | "build": "graph build", 9 | "create-local": "graph create osmosis-token-swaps --node http://0.0.0.0:8020", 10 | "deploy-local": "graph deploy osmosis-token-swaps -l v0.1.0 --ipfs http://0.0.0.0:5001 --node http://0.0.0.0:8020", 11 | "remove-local": "graph remove osmosis-token-swaps --node http://0.0.0.0:8020", 12 | "create": "graph create osmosis-token-swaps --node https://api.thegraph.com/deploy/", 13 | "deploy": "graph deploy osmosis-token-swaps --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/" 14 | }, 15 | "devDependencies": { 16 | "@graphprotocol/graph-cli": "^0.30.0", 17 | "@graphprotocol/graph-ts": "^0.27.0" 18 | }, 19 | "dependencies": { 20 | "babel-polyfill": "^6.26.0", 21 | "babel-register": "^6.26.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/schema.graphql: -------------------------------------------------------------------------------- 1 | type Token @entity { 2 | id: ID! 3 | amount: String 4 | denom: String 5 | } 6 | 7 | type TokenSwap @entity { 8 | id: ID! 9 | sender: String 10 | poolId: String 11 | tokenIn: Token 12 | tokenOut: Token 13 | } 14 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { cosmos } from "@graphprotocol/graph-ts"; 2 | import { TokenSwap, Token } from "../generated/schema"; 3 | 4 | export function handleSwaps(data: cosmos.EventData): void { 5 | const height = data.block.header.height; 6 | const sender = data.event.getAttributeValue("sender"); 7 | const poolId = data.event.getAttributeValue("pool_id"); 8 | 9 | let swap = new TokenSwap(`${height}-${sender}`); 10 | swap.sender = sender; 11 | swap.poolId = poolId; 12 | swap.tokenIn = saveToken(`${height}-${sender}-in`, data.event.getAttributeValue("tokens_in")); 13 | swap.tokenOut = saveToken(`${height}-${sender}-out`, data.event.getAttributeValue("tokens_out")); 14 | 15 | swap.save(); 16 | } 17 | 18 | function saveToken(id: string, data: string): string { 19 | const tokenIn = new Token(id); 20 | 21 | // When assets are transferred through IBC, they lose their original denomination (i.e ATOM) 22 | // and obtain a new IBC denomination (i.e. ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2). 23 | // Check this page (https://docs.osmosis.zone/developing/assets/asset-info.html) for a full list of IBC denomination 24 | // Both amount and denomination come together in the message value (i.e. 123456uatom), so we need to separate them. 25 | let tokenDenomLength = data.includes('ibc') ? 68 : 5 // IBC denomination is 68 characters long, OSMO is 5 characters long. 26 | 27 | tokenIn.denom = data.substring(data.length - tokenDenomLength, data.length); 28 | tokenIn.amount = data.substring(0, data.length - tokenDenomLength); 29 | tokenIn.save(); 30 | 31 | return id; 32 | } 33 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Osmosis Token Swaps Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: Osmosis 9 | network: osmosis-1 10 | source: 11 | startBlock: 2522560 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - TokenSwap 17 | - Token 18 | eventHandlers: 19 | - event: token_swapped 20 | handler: handleSwaps 21 | file: ./src/mapping.ts 22 | -------------------------------------------------------------------------------- /cosmos/osmosis-token-swaps/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/README.md: -------------------------------------------------------------------------------- 1 | # Validator Delegations Example 2 | 3 | This example subgraph stores `Delegation` objects that represent delegations being made in a Cosmos chain. In order to do that, the handler function checks all messages within the transaction and filters them in order to decode and save just the ones that represent a delegation in the chain. 4 | 5 | ## Generating a manifest 6 | 7 | The subgraph is compatible with multiple Cosmos networks so before building the subgraph you need to generate a manifest file for the network of your choice. In case of the Cosmos Hub network, run the following command: 8 | 9 | ```shell 10 | $ yarn prepare:cosmoshub 11 | ``` 12 | 13 | For the list of supported networks, see the scripts in the [`package.json`](package.json) file. 14 | 15 | ## Querying the subgraph 16 | 17 | With the following query you can retrieve all the delegations made to the [Figment](https://atomscan.com/validators/cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d) validator, and the amounts of each of the delegations: 18 | 19 | ``` 20 | query ValidatorDelegations($validatorAddress: String!) { 21 | delegations(where: {validatorAddress: $validatorAddress}) { 22 | validatorAddress, 23 | delegatorAddress, 24 | amount { 25 | amount, 26 | denom 27 | } 28 | } 29 | } 30 | ``` 31 | ``` 32 | { 33 | "validatorAddress": "cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d" 34 | } 35 | ``` 36 | 37 | For more information see the docs on https://thegraph.com/docs/. 38 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cosmos-validator-delegations", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepare:cosmoshub": "mustache config/cosmoshub.json subgraph.template.yaml > subgraph.yaml", 8 | "prepare:osmosis": "mustache config/osmosis.json subgraph.template.yaml > subgraph.yaml", 9 | "codegen": "graph codegen", 10 | "build": "graph build", 11 | "create-local": "graph create cosmos-validator-delegations --node http://127.0.0.1:8020", 12 | "deploy-local": "graph deploy cosmos-validator-delegations -l v0.1.0 --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", 13 | "remove-local": "graph remove cosmos-validator-delegations --node http://127.0.0.1:8020", 14 | "create": "graph create cosmos-validator-delegations --node https://api.thegraph.com/deploy/", 15 | "deploy": "graph deploy cosmos-validator-delegations --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/" 16 | }, 17 | "devDependencies": { 18 | "@graphprotocol/graph-cli": "^0.30.0", 19 | "@graphprotocol/graph-ts": "^0.27.0", 20 | "mustache": "^4.2.0" 21 | }, 22 | "dependencies": { 23 | "babel-polyfill": "^6.26.0", 24 | "babel-register": "^6.26.0", 25 | "as-proto": "^0.2.3" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/schema.graphql: -------------------------------------------------------------------------------- 1 | type Delegation @entity { 2 | id: ID! 3 | delegatorAddress: String 4 | validatorAddress: String 5 | amount: Coin 6 | } 7 | 8 | type Coin @entity { 9 | id: ID! 10 | denom: String 11 | amount: String 12 | } 13 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/src/decoding.ts: -------------------------------------------------------------------------------- 1 | import { Protobuf, Reader } from "as-proto"; 2 | 3 | export function decodeMsgDelegate(a: Uint8Array): MsgDelegate { 4 | return Protobuf.decode(a, MsgDelegate.decode); 5 | } 6 | 7 | export class MsgDelegate { 8 | static decode(reader: Reader, length: i32): MsgDelegate { 9 | const end: usize = length < 0 ? reader.end : reader.ptr + length; 10 | const message = new MsgDelegate(); 11 | 12 | while (reader.ptr < end) { 13 | const tag = reader.uint32(); 14 | switch (tag >>> 3) { 15 | case 1: 16 | message.delegator_address = reader.string(); 17 | break; 18 | 19 | case 2: 20 | message.validator_address = reader.string(); 21 | break; 22 | 23 | case 3: 24 | message.amount = MsgCoin.decode(reader, reader.uint32()); 25 | break; 26 | 27 | default: 28 | reader.skipType(tag & 7); 29 | break; 30 | } 31 | } 32 | 33 | return message; 34 | } 35 | 36 | delegator_address: string; 37 | validator_address: string; 38 | amount: MsgCoin | null; 39 | 40 | constructor(delegator_address: string = "", validator_address: string = "", amount: MsgCoin | null = null) { 41 | this.delegator_address = delegator_address; 42 | this.validator_address = validator_address; 43 | this.amount = amount; 44 | } 45 | } 46 | 47 | export class MsgCoin { 48 | static decode(reader: Reader, length: i32): MsgCoin { 49 | const end: usize = length < 0 ? reader.end : reader.ptr + length; 50 | const message = new MsgCoin(); 51 | 52 | while (reader.ptr < end) { 53 | const tag = reader.uint32(); 54 | switch (tag >>> 3) { 55 | case 1: 56 | message.denom = reader.string(); 57 | break; 58 | 59 | case 2: 60 | message.amount = reader.string(); 61 | break; 62 | 63 | default: 64 | reader.skipType(tag & 7); 65 | break; 66 | } 67 | } 68 | 69 | return message; 70 | } 71 | 72 | denom: string; 73 | amount: string; 74 | 75 | constructor(denom: string = "", amount: string = "") { 76 | this.denom = denom; 77 | this.amount = amount; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { cosmos } from "@graphprotocol/graph-ts"; 2 | import { MsgDelegate, MsgCoin, decodeMsgDelegate } from "./decoding"; 3 | import { Delegation, Coin } from "../generated/schema"; 4 | 5 | export function handleTx(data: cosmos.TransactionData): void { 6 | const id = `${data.block.header.hash.toHexString()}-${data.tx.index}`; 7 | const messages = data.tx.tx.body.messages; 8 | 9 | for (let i = 0; i < messages.length; i++) { 10 | let msgType = messages[i].typeUrl; 11 | let msgValue = messages[i].value as Uint8Array; 12 | 13 | if (msgType == "/cosmos.staking.v1beta1.MsgDelegate") { 14 | saveDelegation(id, decodeMsgDelegate(msgValue)) // The message needs to be decoded to access its attributes. 15 | } 16 | } 17 | } 18 | 19 | function saveDelegation(id: string, message: MsgDelegate): void { 20 | const msg = new Delegation(id); 21 | 22 | msg.delegatorAddress = message.delegator_address; 23 | msg.validatorAddress = message.validator_address; 24 | msg.amount = saveCoin(id, message.amount as MsgCoin); 25 | 26 | msg.save(); 27 | } 28 | 29 | function saveCoin(id: string, c: MsgCoin): string { 30 | const coin = new Coin(id); 31 | 32 | coin.amount = c.amount; 33 | coin.denom = c.denom; 34 | 35 | coin.save(); 36 | 37 | return id; 38 | } 39 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Delegations Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: {{ name }} 9 | network: {{ network }} 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Delegation 17 | - Coin 18 | transactionHandlers: 19 | - handler: handleTx 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Delegations Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Delegation 17 | - Coin 18 | transactionHandlers: 19 | - handler: handleTx 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /cosmos/validator-delegations/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/README.md: -------------------------------------------------------------------------------- 1 | # Validator Rewards Example 2 | 3 | This example subgraph stores `Reward` objects that represent rewards received by a validator in a Cosmos chain. In order to do that, an event handler is used to filter [reward](https://github.com/cosmos/cosmos-sdk/blob/13378bd2cfb9695da6477494e449b0a3bca9bc94/x/distribution/spec/06_events.md) events. The type of event to be filtered is specified in the subgraph manifest file. That way, the handler will just receive events of that type. 4 | 5 | ## Generating a manifest 6 | 7 | The subgraph is compatible with multiple Cosmos networks so before building the subgraph you need to generate a manifest file for the network of your choice. In case of the Cosmos Hub network, run the following command: 8 | 9 | ```shell 10 | $ yarn prepare:cosmoshub 11 | ``` 12 | 13 | For the list of supported networks, see the scripts in the [`package.json`](package.json) file. 14 | 15 | ## Querying the subgraph 16 | 17 | With the following query, you can retrieve all the rewards received by the [Figment](https://atomscan.com/validators/cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d) validator, and the amounts of each of the rewards: 18 | 19 | ``` 20 | query ValidatorRewards($validatorAddress: String!) { 21 | rewards(where: {validator: $validatorAddress}) { 22 | validator, 23 | amount 24 | } 25 | } 26 | ``` 27 | ``` 28 | { 29 | "validatorAddress": "cosmosvaloper1hjct6q7npsspsg3dgvzk3sdf89spmlpfdn6m9d" 30 | } 31 | ``` 32 | 33 | For more information see the docs on https://thegraph.com/docs/. 34 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/config/cosmoshub.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "CosmosHub", 3 | "network": "cosmoshub-4" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/config/osmosis.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Osmosis", 3 | "network": "osmosis-1" 4 | } 5 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cosmos-validator-rewards", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepare:cosmoshub": "mustache config/cosmoshub.json subgraph.template.yaml > subgraph.yaml", 8 | "prepare:osmosis": "mustache config/osmosis.json subgraph.template.yaml > subgraph.yaml", 9 | "codegen": "graph codegen", 10 | "build": "graph build", 11 | "create-local": "graph create cosmos-validator-rewards --node http://127.0.0.1:8020", 12 | "deploy-local": "graph deploy cosmos-validator-rewards -l v0.1.0 --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020", 13 | "remove-local": "graph remove cosmos-validator-rewards --node http://127.0.0.1:8020", 14 | "create": "graph create cosmos-validator-rewards --node https://api.thegraph.com/deploy/", 15 | "deploy": "graph deploy cosmos-validator-rewards --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/" 16 | }, 17 | "devDependencies": { 18 | "@graphprotocol/graph-cli": "^0.30.0", 19 | "@graphprotocol/graph-ts": "^0.27.0", 20 | "mustache": "^4.2.0" 21 | }, 22 | "dependencies": { 23 | "babel-polyfill": "^6.26.0", 24 | "babel-register": "^6.26.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/schema.graphql: -------------------------------------------------------------------------------- 1 | type Reward @entity { 2 | id: ID! 3 | amount: String 4 | validator: String 5 | } 6 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { cosmos } from "@graphprotocol/graph-ts"; 2 | import { Reward } from "../generated/schema"; 3 | 4 | export function handleReward(data: cosmos.EventData): void { 5 | const height = data.block.header.height; 6 | 7 | const amount = data.event.getAttributeValue("amount"); 8 | const validator = data.event.getAttributeValue("validator"); 9 | 10 | let reward = new Reward(`${height}-${validator}`); 11 | 12 | reward.amount = amount; 13 | reward.validator = validator; 14 | 15 | reward.save(); 16 | } 17 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/subgraph.template.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Rewards Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: {{ name }} 9 | network: {{ network }} 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Reward 17 | eventHandlers: 18 | - event: rewards 19 | handler: handleReward 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.5 2 | description: Validator Rewards Example 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: cosmos 8 | name: CosmosHub 9 | network: cosmoshub-4 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.7 14 | language: wasm/assemblyscript 15 | entities: 16 | - Reward 17 | eventHandlers: 18 | - event: rewards 19 | handler: handleReward 20 | file: ./src/mapping.ts 21 | -------------------------------------------------------------------------------- /cosmos/validator-rewards/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | -------------------------------------------------------------------------------- /ethereum/gravatar/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /ethereum/gravatar/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | generated/ 3 | 4 | # Logs 5 | logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | pids 13 | *.pid 14 | *.seed 15 | *.pid.lock 16 | 17 | # Directory for instrumented libs generated by jscoverage/JSCover 18 | lib-cov 19 | 20 | # Coverage directory used by tools like istanbul 21 | coverage 22 | 23 | # nyc test coverage 24 | .nyc_output 25 | 26 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 27 | .grunt 28 | 29 | # Bower dependency directory (https://bower.io/) 30 | bower_components 31 | 32 | # node-waf configuration 33 | .lock-wscript 34 | 35 | # Compiled binary addons (https://nodejs.org/api/addons.html) 36 | build/Release 37 | 38 | # Dependency directories 39 | node_modules/ 40 | jspm_packages/ 41 | 42 | # TypeScript v1 declaration files 43 | typings/ 44 | 45 | # Optional npm cache directory 46 | .npm 47 | 48 | # Optional eslint cache 49 | .eslintcache 50 | 51 | # Optional REPL history 52 | .node_repl_history 53 | 54 | # Output of 'npm pack' 55 | *.tgz 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # next.js build output 64 | .next 65 | -------------------------------------------------------------------------------- /ethereum/gravatar/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ethereum/gravatar/README.md: -------------------------------------------------------------------------------- 1 | # Example Subgraph 2 | 3 | An example to help you get started with The Graph. For more information see the docs on https://thegraph.com/docs/. 4 | -------------------------------------------------------------------------------- /ethereum/gravatar/abis/Gravity.json: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_imageUrl","type":"string"}],"name":"updateGravatarImage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"setMythicalGravatar","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"getGravatar","outputs":[{"name":"","type":"string"},{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"gravatarToOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"ownerToGravatar","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_displayName","type":"string"}],"name":"updateGravatarName","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_displayName","type":"string"},{"name":"_imageUrl","type":"string"}],"name":"createGravatar","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"gravatars","outputs":[{"name":"owner","type":"address"},{"name":"displayName","type":"string"},{"name":"imageUrl","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"displayName","type":"string"},{"indexed":false,"name":"imageUrl","type":"string"}],"name":"NewGravatar","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"id","type":"uint256"},{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"displayName","type":"string"},{"indexed":false,"name":"imageUrl","type":"string"}],"name":"UpdatedGravatar","type":"event"}] 2 | -------------------------------------------------------------------------------- /ethereum/gravatar/bin/Counter.bin: -------------------------------------------------------------------------------- 1 | 60806040526000808190555060f5806100196000396000f3fe6080604052600436106043576000357c0100000000000000000000000000000000000000000000000000000000900480633fa4f245146048578063d09de08a146070575b600080fd5b348015605357600080fd5b50605a6078565b6040518082815260200191505060405180910390f35b6076607e565b005b60005481565b600160008082825401925050819055507f20d8a6f5a693f9d1d627a598e8820f7a55ee74c183aa8f1a30e8d4e8dd9a8d846000546040518082815260200191505060405180910390a156fea165627a7a72305820fca3d11af59a6ac98027ec3bebdb10711f195860d6d9abd07921c88c8c50228f0029 -------------------------------------------------------------------------------- /ethereum/gravatar/contracts/Gravity.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract GravatarRegistry { 4 | event NewGravatar(uint id, address owner, string displayName, string imageUrl); 5 | event UpdatedGravatar(uint id, address owner, string displayName, string imageUrl); 6 | 7 | struct Gravatar { 8 | address owner; 9 | string displayName; 10 | string imageUrl; 11 | } 12 | 13 | Gravatar[] public gravatars; 14 | 15 | mapping (uint => address) public gravatarToOwner; 16 | mapping (address => uint) public ownerToGravatar; 17 | 18 | function createGravatar(string _displayName, string _imageUrl) public { 19 | require(ownerToGravatar[msg.sender] == 0); 20 | uint id = gravatars.push(Gravatar(msg.sender, _displayName, _imageUrl)) - 1; 21 | 22 | gravatarToOwner[id] = msg.sender; 23 | ownerToGravatar[msg.sender] = id; 24 | 25 | emit NewGravatar(id, msg.sender, _displayName, _imageUrl); 26 | } 27 | 28 | function getGravatar(address owner) public view returns (string, string) { 29 | uint id = ownerToGravatar[owner]; 30 | return (gravatars[id].displayName, gravatars[id].imageUrl); 31 | } 32 | 33 | function updateGravatarName(string _displayName) public { 34 | require(ownerToGravatar[msg.sender] != 0); 35 | require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner); 36 | 37 | uint id = ownerToGravatar[msg.sender]; 38 | 39 | gravatars[id].displayName = _displayName; 40 | emit UpdatedGravatar(id, msg.sender, _displayName, gravatars[id].imageUrl); 41 | } 42 | 43 | function updateGravatarImage(string _imageUrl) public { 44 | require(ownerToGravatar[msg.sender] != 0); 45 | require(msg.sender == gravatars[ownerToGravatar[msg.sender]].owner); 46 | 47 | uint id = ownerToGravatar[msg.sender]; 48 | 49 | gravatars[id].imageUrl = _imageUrl; 50 | emit UpdatedGravatar(id, msg.sender, gravatars[id].displayName, _imageUrl); 51 | } 52 | 53 | // the gravatar at position 0 of gravatars[] 54 | // is fake 55 | // it's a mythical gravatar 56 | // that doesn't really exist 57 | // dani will invoke this function once when this contract is deployed 58 | // but then no more 59 | function setMythicalGravatar() public { 60 | require(msg.sender == 0x8d3e809Fbd258083a5Ba004a527159Da535c8abA); 61 | gravatars.push(Gravatar(0x0, " ", " ")); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /ethereum/gravatar/contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.4.0; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | 19 | function upgrade(address new_address) public restricted { 20 | Migrations upgraded = Migrations(new_address); 21 | upgraded.setCompleted(last_completed_migration); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /ethereum/gravatar/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /ethereum/gravatar/migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | var Migrations = artifacts.require('./Migrations.sol') 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations) 5 | } 6 | -------------------------------------------------------------------------------- /ethereum/gravatar/migrations/2_deploy_contract.js: -------------------------------------------------------------------------------- 1 | const GravatarRegistry = artifacts.require('./GravatarRegistry.sol') 2 | 3 | module.exports = async function(deployer) { 4 | await deployer.deploy(GravatarRegistry) 5 | } 6 | -------------------------------------------------------------------------------- /ethereum/gravatar/migrations/3_create_gravatars.js: -------------------------------------------------------------------------------- 1 | const GravatarRegistry = artifacts.require('./GravatarRegistry.sol') 2 | 3 | module.exports = async function(deployer) { 4 | const registry = await GravatarRegistry.deployed() 5 | 6 | console.log('Account address:', registry.address) 7 | 8 | let accounts = await web3.eth.getAccounts() 9 | await registry.createGravatar('Carl', 'https://thegraph.com/img/team/team_04.png', { 10 | from: accounts[0], 11 | }) 12 | await registry.createGravatar('Lucas', 'https://thegraph.com/img/team/bw_Lucas.jpg', { 13 | from: accounts[1], 14 | }) 15 | } 16 | -------------------------------------------------------------------------------- /ethereum/gravatar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "build-contract": "solc contracts/Gravity.sol --abi -o abis --overwrite && solc contracts/Gravity.sol --bin -o bin --overwrite", 8 | "create": "graph create example --node https://api.thegraph.com/deploy/", 9 | "create-local": "graph create example --node http://127.0.0.1:8020", 10 | "codegen": "graph codegen", 11 | "build": "graph build", 12 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 13 | "deploy-local": "graph deploy example --ipfs http://127.0.0.1:5001 --node http://127.0.0.1:8020" 14 | }, 15 | "devDependencies": { 16 | "@graphprotocol/graph-cli": "^0.30.2", 17 | "@graphprotocol/graph-ts": "^0.27.0" 18 | }, 19 | "dependencies": { 20 | "babel-polyfill": "^6.26.0", 21 | "babel-register": "^6.26.0", 22 | "truffle": "^5.0.4", 23 | "truffle-contract": "^4.0.5", 24 | "truffle-hdwallet-provider": "^1.0.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /ethereum/gravatar/schema.graphql: -------------------------------------------------------------------------------- 1 | type Gravatar @entity { 2 | id: ID! 3 | owner: Bytes! 4 | displayName: String! 5 | imageUrl: String! 6 | } 7 | -------------------------------------------------------------------------------- /ethereum/gravatar/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { NewGravatar, UpdatedGravatar } from '../generated/Gravity/Gravity' 2 | import { Gravatar } from '../generated/schema' 3 | 4 | export function handleNewGravatar(event: NewGravatar): void { 5 | let gravatar = new Gravatar(event.params.id.toHex()) 6 | gravatar.owner = event.params.owner 7 | gravatar.displayName = event.params.displayName 8 | gravatar.imageUrl = event.params.imageUrl 9 | gravatar.save() 10 | } 11 | 12 | export function handleUpdatedGravatar(event: UpdatedGravatar): void { 13 | let id = event.params.id.toHex() 14 | let gravatar = Gravatar.load(id) 15 | if (gravatar == null) { 16 | gravatar = new Gravatar(id) 17 | } 18 | gravatar.owner = event.params.owner 19 | gravatar.displayName = event.params.displayName 20 | gravatar.imageUrl = event.params.imageUrl 21 | gravatar.save() 22 | } 23 | -------------------------------------------------------------------------------- /ethereum/gravatar/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.2 2 | description: Gravatar for Ethereum 3 | repository: https://github.com/graphprotocol/example-subgraphs 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: ethereum/contract 8 | name: Gravity 9 | network: mainnet 10 | source: 11 | address: '0x2E645469f354BB4F5c8a05B3b30A929361cf77eC' 12 | abi: Gravity 13 | mapping: 14 | kind: ethereum/events 15 | apiVersion: 0.0.5 16 | language: wasm/assemblyscript 17 | entities: 18 | - Gravatar 19 | abis: 20 | - name: Gravity 21 | file: ./abis/Gravity.json 22 | eventHandlers: 23 | - event: NewGravatar(uint256,address,string,string) 24 | handler: handleNewGravatar 25 | - event: UpdatedGravatar(uint256,address,string,string) 26 | handler: handleUpdatedGravatar 27 | file: ./src/mapping.ts 28 | -------------------------------------------------------------------------------- /ethereum/gravatar/truffle.js: -------------------------------------------------------------------------------- 1 | require('babel-register') 2 | require('babel-polyfill') 3 | const HDWalletProvider = require('truffle-hdwallet-provider') 4 | 5 | module.exports = { 6 | networks: { 7 | development: { 8 | host: '127.0.0.1', 9 | port: 8545, 10 | network_id: '*', 11 | }, 12 | ropsten: { 13 | provider: function() { 14 | return new HDWalletProvider( 15 | process.env.MNEMONIC, 16 | `https://ropsten.infura.io/v3/${process.env.ROPSTEN_INFURA_API_KEY}` 17 | ) 18 | }, 19 | network_id: '3', 20 | }, 21 | }, 22 | compilers: { 23 | solc: { 24 | version: '0.4.25' // Fetch exact version from solc-bin (default: truffle's version) 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /near/blocks-example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /near/blocks-example/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /near/blocks-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /near/blocks-example/README.md: -------------------------------------------------------------------------------- 1 | # Example NEAR Blocks Subgraph 2 | 3 | An example to help you get started with NEAR indexing with The Graph. For more information see the docs on https://thegraph.com/docs/supported-networks/near. 4 | -------------------------------------------------------------------------------- /near/blocks-example/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /near/blocks-example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "build-contract": "solc contracts/Gravity.sol --abi -o abis --overwrite && solc contracts/Gravity.sol --bin -o bin --overwrite", 8 | "create": "graph create example --node https://api.thegraph.com/deploy/", 9 | "create-local": "graph create example --node http://127.0.0.1:8020", 10 | "codegen": "graph codegen", 11 | "build": "graph build", 12 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 13 | "deploy-local": "graph deploy example --ipfs http://localhost:5001 --node http://127.0.0.1:8020" 14 | }, 15 | "devDependencies": { 16 | "@graphprotocol/graph-cli": "^0.23.2", 17 | "@graphprotocol/graph-ts": "^0.23.1" 18 | }, 19 | "dependencies": { 20 | "babel-polyfill": "^6.26.0", 21 | "babel-register": "^6.26.0", 22 | "truffle": "^5.0.4", 23 | "truffle-contract": "^4.0.5", 24 | "truffle-hdwallet-provider": "^1.0.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /near/blocks-example/schema.graphql: -------------------------------------------------------------------------------- 1 | type BlockEvent @entity { 2 | id: ID! 3 | number: BigInt 4 | hash: Bytes 5 | timestampNanosec: BigInt 6 | gasPrice: BigInt 7 | } 8 | -------------------------------------------------------------------------------- /near/blocks-example/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { near, BigInt } from "@graphprotocol/graph-ts"; 2 | import { BlockEvent } from "../generated/schema"; 3 | 4 | export function handleBlock(block: near.Block): void { 5 | const header = block.header; 6 | let event = new BlockEvent(header.hash.toHexString()); 7 | event.number = BigInt.fromI32(header.height as i32); 8 | event.hash = header.hash; 9 | event.timestampNanosec = BigInt.fromU64(header.timestampNanosec); 10 | event.gasPrice = header.gasPrice; 11 | 12 | event.save(); 13 | } 14 | -------------------------------------------------------------------------------- /near/blocks-example/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: NEAR Blocks 3 | repository: https://github.com/graphprotocol/example-subgraphs/tree/main/near/blocks-example 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: near 8 | name: blocks 9 | network: near-mainnet 10 | source: 11 | startBlock: 0 12 | mapping: 13 | apiVersion: 0.0.5 14 | language: wasm/assemblyscript 15 | file: ./src/mapping.ts 16 | entities: 17 | - BlockEvent 18 | blockHandlers: 19 | - handler: handleBlock 20 | -------------------------------------------------------------------------------- /near/blocks-example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", 3 | "include": ["src"] 4 | } -------------------------------------------------------------------------------- /near/receipts-example/.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity 2 | -------------------------------------------------------------------------------- /near/receipts-example/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /near/receipts-example/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 The Graph 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /near/receipts-example/README.md: -------------------------------------------------------------------------------- 1 | # Example NEAR Receipts Subgraph: Good Morning NEAR 2 | 3 | This subgraph indexes `app.good-morning.near`, which you can interact with at https://gm-near.surge.sh/ 4 | 5 | An example to help you get started with NEAR indexing with The Graph. For more information see the docs on https://thegraph.com/docs/supported-networks/near. 6 | -------------------------------------------------------------------------------- /near/receipts-example/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | graph-node: 4 | image: graphprotocol/graph-node:v0.22.0 5 | ports: 6 | - '8000:8000' 7 | - '8001:8001' 8 | - '8020:8020' 9 | - '8030:8030' 10 | - '8040:8040' 11 | depends_on: 12 | - ipfs 13 | - postgres 14 | environment: 15 | postgres_host: postgres 16 | postgres_user: graph-node 17 | postgres_pass: let-me-in 18 | postgres_db: graph-node 19 | ipfs: 'ipfs:5001' 20 | # Change next line if you want to connect to a different JSON-RPC endpoint 21 | ethereum: 'mainnet:http://host.docker.internal:8545' 22 | GRAPH_LOG: info 23 | ipfs: 24 | image: ipfs/go-ipfs:v0.4.23 25 | ports: 26 | - '5001:5001' 27 | volumes: 28 | - ./data/ipfs:/data/ipfs 29 | postgres: 30 | image: postgres 31 | ports: 32 | - '5432:5432' 33 | command: ["postgres", "-cshared_preload_libraries=pg_stat_statements"] 34 | environment: 35 | POSTGRES_USER: graph-node 36 | POSTGRES_PASSWORD: let-me-in 37 | POSTGRES_DB: graph-node 38 | volumes: 39 | - ./data/postgres:/var/lib/postgresql/data 40 | -------------------------------------------------------------------------------- /near/receipts-example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "repository": "https://github.com/graphprotocol/example-subgraph", 5 | "license": "MIT", 6 | "scripts": { 7 | "create": "graph create example --node https://api.thegraph.com/deploy/", 8 | "create-local": "graph create example --node http://127.0.0.1:8020", 9 | "codegen": "graph codegen", 10 | "build": "graph build", 11 | "deploy": "graph deploy example --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/", 12 | "deploy-local": "graph deploy example --ipfs http://localhost:5001 --node http://127.0.0.1:8020" 13 | }, 14 | "devDependencies": { 15 | "@graphprotocol/graph-cli": "^0.23.2", 16 | "@graphprotocol/graph-ts": "^0.23.1" 17 | }, 18 | "dependencies": { 19 | "babel-polyfill": "^6.26.0", 20 | "babel-register": "^6.26.0", 21 | "truffle": "^5.0.4", 22 | "truffle-contract": "^4.0.5", 23 | "truffle-hdwallet-provider": "^1.0.4" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /near/receipts-example/schema.graphql: -------------------------------------------------------------------------------- 1 | type Greeter @entity { 2 | id: ID! 3 | name: String! 4 | greetings: [Greeting!] @derivedFrom(field: "greeter") 5 | } 6 | 7 | type Greeting @entity { 8 | id: ID! 9 | greeter: Greeter! 10 | timestamp: BigInt! 11 | } 12 | -------------------------------------------------------------------------------- /near/receipts-example/src/mapping.ts: -------------------------------------------------------------------------------- 1 | import { near, BigInt, log } from "@graphprotocol/graph-ts"; 2 | import { Greeter, Greeting } from "../generated/schema"; 3 | 4 | export function handleReceipt(receipt: near.ReceiptWithOutcome): void { 5 | const actions = receipt.receipt.actions; 6 | for (let i = 0; i < actions.length; i++) { 7 | handleAction(actions[i], receipt.receipt, receipt.block.header); 8 | } 9 | } 10 | 11 | function handleAction( 12 | action: near.ActionValue, 13 | receipt: near.ActionReceipt, 14 | blockHeader: near.BlockHeader 15 | ): void { 16 | if (action.kind != near.ActionKind.FUNCTION_CALL) { 17 | log.info("Early return: {}", ["Not a function call"]); 18 | return; 19 | } 20 | 21 | const functionCall = action.toFunctionCall(); 22 | if (functionCall.methodName == "sayGm") { 23 | let greeter = Greeter.load(receipt.signerId); 24 | if (greeter == null) { 25 | greeter = new Greeter(receipt.signerId); 26 | greeter.name = receipt.signerId; 27 | greeter.save(); 28 | } 29 | 30 | const greeting = new Greeting(receipt.id.toBase58()); 31 | greeting.greeter = greeter.id; 32 | greeting.timestamp = BigInt.fromU64(blockHeader.timestampNanosec); 33 | greeting.save(); 34 | } else { 35 | log.info("Not processed - FunctionCall is: {}", [functionCall.methodName]); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /near/receipts-example/subgraph.yaml: -------------------------------------------------------------------------------- 1 | specVersion: 0.0.4 2 | description: Good Morning NEAR 3 | repository: https://github.com/graphprotocol/example-subgraphs/tree/main/near/receipts-example 4 | schema: 5 | file: ./schema.graphql 6 | dataSources: 7 | - kind: near 8 | name: receipts 9 | network: near-mainnet 10 | source: 11 | account: "app.good-morning.near" 12 | startBlock: 50736511 13 | mapping: 14 | apiVersion: 0.0.5 15 | language: wasm/assemblyscript 16 | file: ./src/mapping.ts 17 | entities: 18 | - Greeter 19 | - Greeting 20 | receiptHandlers: 21 | - handler: handleReceipt 22 | --------------------------------------------------------------------------------