-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added subgraph to Agent Result Mapping (#8)
* Added agent result mappings v0 * Adapted contract/test to have multiple IPFS hashes per market * Final version of contract, ready for deployment * Removed verbose comments | Improved README * Refactored mapping to include publisher address * Update src/OmenAgentResultMapping.sol Co-authored-by: Peter Jung <peter@jung.ninja> * Update src/OmenAgentResultMapping.sol Co-authored-by: Peter Jung <peter@jung.ninja> * Addressed PR comments * Removing index on emitted event * Update src/OmenAgentResultMapping.sol Co-authored-by: Peter Jung <peter@jung.ninja> * Added Probability to struct and event * Improved comments and naming * Imported event from contract directly * Initialize subgraph * Initialize subgraph * Subgraph working * Updated README.md * Removed files * removing ignored files * Improved README * Implemented PR comment --------- Co-authored-by: Peter Jung <peter@jung.ninja>
- Loading branch information
1 parent
cfe4296
commit 5f59e73
Showing
15 changed files
with
3,976 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Graph CLI generated artifacts | ||
build/ | ||
generated/ | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
# Testing | ||
coverage | ||
coverage.json | ||
|
||
# Typechain | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache |
127 changes: 127 additions & 0 deletions
127
graphs/omen-agentresultmapping/abis/OmenAgentResultMapping.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
[ | ||
{ "type": "constructor", "inputs": [], "stateMutability": "nonpayable" }, | ||
{ | ||
"type": "function", | ||
"name": "addPrediction", | ||
"inputs": [ | ||
{ "name": "marketAddress", "type": "address", "internalType": "address" }, | ||
{ | ||
"name": "prediction", | ||
"type": "tuple", | ||
"internalType": "struct Prediction", | ||
"components": [ | ||
{ | ||
"name": "publisherAddress", | ||
"type": "address", | ||
"internalType": "address" | ||
}, | ||
{ "name": "ipfsHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ "name": "txHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ | ||
"name": "estimatedProbabilityBps", | ||
"type": "uint16", | ||
"internalType": "uint16" | ||
} | ||
] | ||
} | ||
], | ||
"outputs": [], | ||
"stateMutability": "nonpayable" | ||
}, | ||
{ | ||
"type": "function", | ||
"name": "getPredictionByIndex", | ||
"inputs": [ | ||
{ "name": "marketAddress", "type": "address", "internalType": "address" }, | ||
{ "name": "index", "type": "uint256", "internalType": "uint256" } | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "tuple", | ||
"internalType": "struct Prediction", | ||
"components": [ | ||
{ | ||
"name": "publisherAddress", | ||
"type": "address", | ||
"internalType": "address" | ||
}, | ||
{ "name": "ipfsHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ "name": "txHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ | ||
"name": "estimatedProbabilityBps", | ||
"type": "uint16", | ||
"internalType": "uint16" | ||
} | ||
] | ||
} | ||
], | ||
"stateMutability": "view" | ||
}, | ||
{ | ||
"type": "function", | ||
"name": "getPredictions", | ||
"inputs": [ | ||
{ "name": "marketAddress", "type": "address", "internalType": "address" } | ||
], | ||
"outputs": [ | ||
{ | ||
"name": "", | ||
"type": "tuple[]", | ||
"internalType": "struct Prediction[]", | ||
"components": [ | ||
{ | ||
"name": "publisherAddress", | ||
"type": "address", | ||
"internalType": "address" | ||
}, | ||
{ "name": "ipfsHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ "name": "txHash", "type": "bytes32", "internalType": "bytes32" }, | ||
{ | ||
"name": "estimatedProbabilityBps", | ||
"type": "uint16", | ||
"internalType": "uint16" | ||
} | ||
] | ||
} | ||
], | ||
"stateMutability": "view" | ||
}, | ||
{ | ||
"type": "event", | ||
"name": "PredictionAdded", | ||
"inputs": [ | ||
{ | ||
"name": "marketAddress", | ||
"type": "address", | ||
"indexed": true, | ||
"internalType": "address" | ||
}, | ||
{ | ||
"name": "estimatedProbabilityBps", | ||
"type": "uint16", | ||
"indexed": false, | ||
"internalType": "uint16" | ||
}, | ||
{ | ||
"name": "publisherAddress", | ||
"type": "address", | ||
"indexed": true, | ||
"internalType": "address" | ||
}, | ||
{ | ||
"name": "txHash", | ||
"type": "bytes32", | ||
"indexed": false, | ||
"internalType": "bytes32" | ||
}, | ||
{ | ||
"name": "ipfsHash", | ||
"type": "bytes32", | ||
"indexed": false, | ||
"internalType": "bytes32" | ||
} | ||
], | ||
"anonymous": false | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
version: "3" | ||
services: | ||
graph-node: | ||
image: graphprotocol/graph-node | ||
ports: | ||
- "8000:8000" | ||
- "8001:8001" | ||
- "8020:8020" | ||
- "8030:8030" | ||
- "8040:8040" | ||
depends_on: | ||
- ipfs | ||
- postgres | ||
extra_hosts: | ||
- host.docker.internal:host-gateway | ||
environment: | ||
postgres_host: postgres | ||
postgres_user: graph-node | ||
postgres_pass: let-me-in | ||
postgres_db: graph-node | ||
ipfs: "ipfs:5001" | ||
ethereum: "mainnet:http://host.docker.internal:8545" | ||
GRAPH_LOG: info | ||
ipfs: | ||
image: ipfs/kubo:v0.17.0 | ||
ports: | ||
- "5001:5001" | ||
volumes: | ||
- ./data/ipfs:/data/ipfs | ||
postgres: | ||
image: postgres:14 | ||
ports: | ||
- "5432:5432" | ||
command: | ||
[ | ||
"postgres", | ||
"-cshared_preload_libraries=pg_stat_statements", | ||
"-cmax_connections=200", | ||
] | ||
environment: | ||
POSTGRES_USER: graph-node | ||
POSTGRES_PASSWORD: let-me-in | ||
POSTGRES_DB: graph-node | ||
# FIXME: remove this env. var. which we shouldn't need. Introduced by | ||
# <https://github.com/graphprotocol/graph-node/pull/3511>, maybe as a | ||
# workaround for https://github.com/docker/for-mac/issues/6270? | ||
PGDATA: "/var/lib/postgresql/data" | ||
POSTGRES_INITDB_ARGS: "-E UTF8 --locale=C" | ||
volumes: | ||
- ./data/postgres:/var/lib/postgresql/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"gnosis": { | ||
"OmenAgentResultMapping": { | ||
"address": "0xbe1F6944496923683ca849fc0cC93fD10523cB83", | ||
"startBlock": 36085528 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "omen-agentresultmapping", | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"codegen": "graph codegen", | ||
"build": "graph build", | ||
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ omen-agentresultmapping", | ||
"create-local": "graph create --node http://localhost:8020/ omen-agentresultmapping", | ||
"remove-local": "graph remove --node http://localhost:8020/ omen-agentresultmapping", | ||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 omen-agentresultmapping", | ||
"test": "graph test" | ||
}, | ||
"dependencies": { | ||
"@graphprotocol/graph-cli": "0.82.0", | ||
"@graphprotocol/graph-ts": "0.32.0" | ||
}, | ||
"devDependencies": { "matchstick-as": "0.5.0" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type PredictionAdded @entity(immutable: true) { | ||
id: Bytes! | ||
marketAddress: Bytes! # address | ||
estimatedProbabilityBps: Int! # uint16 | ||
publisherAddress: Bytes! # address | ||
txHash: Bytes! # bytes32 | ||
ipfsHash: Bytes! # bytes32 | ||
blockNumber: BigInt! | ||
blockTimestamp: BigInt! | ||
transactionHash: Bytes! | ||
} |
19 changes: 19 additions & 0 deletions
19
graphs/omen-agentresultmapping/src/omen-agent-result-mapping.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PredictionAdded as PredictionAddedEvent } from "../generated/OmenAgentResultMapping/OmenAgentResultMapping" | ||
import { PredictionAdded } from "../generated/schema" | ||
|
||
export function handlePredictionAdded(event: PredictionAddedEvent): void { | ||
let entity = new PredictionAdded( | ||
event.transaction.hash.concatI32(event.logIndex.toI32()) | ||
) | ||
entity.marketAddress = event.params.marketAddress | ||
entity.estimatedProbabilityBps = event.params.estimatedProbabilityBps | ||
entity.publisherAddress = event.params.publisherAddress | ||
entity.txHash = event.params.txHash | ||
entity.ipfsHash = event.params.ipfsHash | ||
|
||
entity.blockNumber = event.block.number | ||
entity.blockTimestamp = event.block.timestamp | ||
entity.transactionHash = event.transaction.hash | ||
|
||
entity.save() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
specVersion: 1.0.0 | ||
indexerHints: | ||
prune: auto | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum | ||
name: OmenAgentResultMapping | ||
network: gnosis | ||
source: | ||
address: "0xbe1F6944496923683ca849fc0cC93fD10523cB83" | ||
abi: OmenAgentResultMapping | ||
startBlock: 36085528 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.7 | ||
language: wasm/assemblyscript | ||
entities: | ||
- PredictionAdded | ||
abis: | ||
- name: OmenAgentResultMapping | ||
file: ./abis/OmenAgentResultMapping.json | ||
eventHandlers: | ||
- event: PredictionAdded(indexed address,uint16,indexed address,bytes32,bytes32) | ||
handler: handlePredictionAdded | ||
file: ./src/omen-agent-result-mapping.ts |
42 changes: 42 additions & 0 deletions
42
graphs/omen-agentresultmapping/tests/omen-agent-result-mapping-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { newMockEvent } from "matchstick-as" | ||
import { ethereum, Address, Bytes } from "@graphprotocol/graph-ts" | ||
import { PredictionAdded } from "../generated/OmenAgentResultMapping/OmenAgentResultMapping" | ||
|
||
export function createPredictionAddedEvent( | ||
marketAddress: Address, | ||
estimatedProbabilityBps: i32, | ||
publisherAddress: Address, | ||
txHash: Bytes, | ||
ipfsHash: Bytes | ||
): PredictionAdded { | ||
let predictionAddedEvent = changetype<PredictionAdded>(newMockEvent()) | ||
|
||
predictionAddedEvent.parameters = new Array() | ||
|
||
predictionAddedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"marketAddress", | ||
ethereum.Value.fromAddress(marketAddress) | ||
) | ||
) | ||
predictionAddedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"estimatedProbabilityBps", | ||
ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(estimatedProbabilityBps)) | ||
) | ||
) | ||
predictionAddedEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"publisherAddress", | ||
ethereum.Value.fromAddress(publisherAddress) | ||
) | ||
) | ||
predictionAddedEvent.parameters.push( | ||
new ethereum.EventParam("txHash", ethereum.Value.fromFixedBytes(txHash)) | ||
) | ||
predictionAddedEvent.parameters.push( | ||
new ethereum.EventParam("ipfsHash", ethereum.Value.fromFixedBytes(ipfsHash)) | ||
) | ||
|
||
return predictionAddedEvent | ||
} |
Oops, something went wrong.