Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added subgraph to Agent Result Mapping #8

Merged
merged 22 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ cache/
out/
abi/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
.idea/
.gas-snapshot


# Ignores broadcast logs
broadcast/

# Docs
docs/
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"solidity.packageDefaultDependenciesDirectory": "lib",
"solidity.formatter": "forge",
"editor.formatOnSave": true
}
}
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ Repository holding the contracts made by Gnosis Labs team.
| Contract Name | Description | Mainnet Address | TheGraph |
|----------------------------|-------------------------------------------------------|-------------------------------------------||-------------------------------------------|
| OmenThumbnailMapping | Manages IPFS hashes for market thumbnails on Omen 2.0 | [0xe0cf08311F03850497B0ed6A2cf067f1750C3eFc](https://gnosisscan.io/address/0xe0cf08311f03850497b0ed6a2cf067f1750c3efc#code) | [omen-thumbnailmapping](https://thegraph.com/studio/subgraph/omen-thumbnailmapping/) |
| OmenAgentResultMapping | Maps prediction results to markets on Omen 2.0 | [0xbe1F6944496923683ca849fc0cC93fD10523cB83](https://gnosisscan.io/address/0xbe1F6944496923683ca849fc0cC93fD10523cB83#code) | [omen-agentresultmapping](https://thegraph.com/studio/subgraph/omen-agentresultmapping/) |


### Omen ThumbnailMapping

Contract used to store prediction market's address to IPFS hash of an image displayed on Omen 2.0

## Set up contracts development

The repository uses [Foundry](https://book.getfoundry.sh/).
Expand Down Expand Up @@ -120,4 +117,4 @@ Before working with graphs, you need to run `forge build` in the root directory.

The sequence of commands is `codegen -> build -> test -> deploy`.

(On MacOS Sonoma, running the tests in the docker mode is required: https://github.com/LimeChain/matchstick/issues/421)
(On MacOS Sonoma, running the tests in the docker mode is required: https://github.com/LimeChain/matchstick/issues/421)
34 changes: 34 additions & 0 deletions graphs/omen-agentresultmapping/.gitignore
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 graphs/omen-agentresultmapping/abis/OmenAgentResultMapping.json
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
}
]
50 changes: 50 additions & 0 deletions graphs/omen-agentresultmapping/docker-compose.yml
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
8 changes: 8 additions & 0 deletions graphs/omen-agentresultmapping/networks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gnosis": {
"OmenAgentResultMapping": {
"address": "0xbe1F6944496923683ca849fc0cC93fD10523cB83",
"startBlock": 36085528
}
}
}
18 changes: 18 additions & 0 deletions graphs/omen-agentresultmapping/package.json
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" }
}
11 changes: 11 additions & 0 deletions graphs/omen-agentresultmapping/schema.graphql
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 graphs/omen-agentresultmapping/src/omen-agent-result-mapping.ts
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()
}
26 changes: 26 additions & 0 deletions graphs/omen-agentresultmapping/subgraph.yaml
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
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
}
Loading