Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ubgraphs into OpenZeppelin-main-0.1.10
  • Loading branch information
the-emerald committed Aug 7, 2022
2 parents be7c8c0 + 688f4e1 commit e1b5556
Show file tree
Hide file tree
Showing 26 changed files with 157 additions and 93 deletions.
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
* Fix "could not find ABI for contract `IERC721` in `naut`"
* Implement `Planet` module
* Implement `Delegation` module
* U: `Governor`: improve indexing of proposal queeing ([#29](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/29))
* U: `Governor`: track total vote weight in `ProposalSupport` ([#31](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/31))
* U: `Governor`: add handler for `VoteCastWithParams` events ([#31](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/31))
* U: `ERC721`: reset approval on `Transfer` ([#33](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/33))
* U: `ERC1155`: fix bug caused by duplicate write of immutable entity `ERC1155` ([#36](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/36))
* U: `AccessControl`: fix bug caused by duplicate write of immutable entity `Role` ([#36](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/36))
* U: `AccessControl`: fix bug caused by duplicate write of immutable entity `AccessControl` ([#38](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/38))

### 0.1.9
* Implement `Naut` module
Expand All @@ -16,16 +23,16 @@
* Update dependency to @graphprotocol/graph-cli version 0.29.x
* Update dependency to @graphprotocol/graph-ts version 0.26.x
* Update dependency to @amxx/graphprotocol-utils version 1.1.0
* Use Bytes for some entities ID
* Use Bytes for some entities ID ([#25](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/25))
* Make events and some other entites immutable
* `Governor`: index the "counting mode" for OZ governors

### 0.1.7-1 (2021-01-27)
### 0.1.7-1 (2022-01-27)
* `Governor`: fix vulnerability to ill-formed ProposalCreated events

### 0.1.7 (2021-01-27)
* `ERC1155`: fetch token uri on minting.
* `ERC1155`: fix vulnerability to ill-formed TransferBatch events
### 0.1.7 (2022-01-27)
* `ERC1155`: fetch token uri on minting. ([#14](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/14))
* `ERC1155`: fix vulnerability to ill-formed TransferBatch events ([#16](https://github.com/OpenZeppelin/openzeppelin-subgraphs/pull/16))

### 0.1.6 (2021-11-23)
* Include emmiter address (Account) to all Event objects
Expand Down
4 changes: 3 additions & 1 deletion configs/live/bsc/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
{ "startBlock": 0, "module": "erc1967upgrade" },
{ "startBlock": 0, "module": "accesscontrol" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/access-control-bsc"
"deploy": [
{ "type": "hosted-service", "name": "amxx/access-control-bsc" }
]
}
4 changes: 3 additions & 1 deletion configs/live/bsc/nfts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
{ "startBlock": 0, "module": "erc721" },
{ "startBlock": 0, "module": "erc1155" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/nft-bsc"
"deploy": [
{ "type": "hosted-service", "name": "amxx/nft-bsc" }
]
}
4 changes: 3 additions & 1 deletion configs/live/mainnet/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
{ "startBlock": 5375569, "module": "erc1967upgrade" },
{ "startBlock": 9857098, "module": "accesscontrol" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/access-control"
"deploy": [
{ "type": "hosted-service", "name": "amxx/access-control" }
]
}
4 changes: 3 additions & 1 deletion configs/live/mainnet/eip1155.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"datasources": [
{ "startBlock": 6930510, "module": "erc1155" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/eip1155-subgraph"
"deploy": [
{ "type": "hosted-service", "name": "amxx/eip1155-subgraph" }
]
}
4 changes: 3 additions & 1 deletion configs/live/mainnet/eip721.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
"datasources": [
{ "startBlock": 5806610, "module": "erc721" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/eip721-subgraph"
"deploy": [
{ "type": "hosted-service", "name": "amxx/eip721-subgraph" }
]
}
4 changes: 3 additions & 1 deletion configs/live/mainnet/nfts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
{ "startBlock": 5806610, "module": "erc721" },
{ "startBlock": 6930510, "module": "erc1155" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/nft-mainnet"
"deploy": [
{ "type": "hosted-service", "name": "amxx/nft-mainnet" }
]
}
4 changes: 3 additions & 1 deletion configs/live/matic/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
{ "startBlock": 0, "module": "erc1967upgrade" },
{ "startBlock": 0, "module": "accesscontrol" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/access-control-matic"
"deploy": [
{ "type": "hosted-service", "name": "amxx/access-control-matic" }
]
}
4 changes: 3 additions & 1 deletion configs/live/matic/nfts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
{ "startBlock": 0, "module": "erc721" },
{ "startBlock": 0, "module": "erc1155" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/nft-matic"
"deploy": [
{ "type": "hosted-service", "name": "amxx/nft-matic" }
]
}
4 changes: 3 additions & 1 deletion configs/live/xdai/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
{ "startBlock": 0, "module": "erc1967upgrade" },
{ "startBlock": 0, "module": "accesscontrol" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/access-control-xdai"
"deploy": [
{ "type": "hosted-service", "name": "amxx/access-control-xdai" }
]
}
4 changes: 3 additions & 1 deletion configs/live/xdai/nfts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
{ "startBlock": 0, "module": "erc721" },
{ "startBlock": 0, "module": "erc1155" }
],
"__endpoint": "https://api.thegraph.com/subgraphs/name/amxx/nft-xdai"
"deploy": [
{ "type": "hosted-service", "name": "amxx/nft-xdai" }
]
}
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Browse on GitHub at https://github.com/OpenZeppelin/openzeppelin-subgraphs[`Open

Subgraph are described using three components:

- *The graphql schema*, usually nammed `schema.graphql`, which describes the database entities and links.
- *The subgraph manifest*, usually nammed `subgraph.yaml`, which describes the activity that should be listened to (addresses of contracts, events handlers, function handlers).
- *The graphql schema*, usually named `schema.graphql`, which describes the database entities and links.
- *The subgraph manifest*, usually named `subgraph.yaml`, which describes the activity that should be listened to (addresses of contracts, events handlers, function handlers).
- *The indexing logic*, written in assembly script, which will process the blockchain activity and update the database accordingly.

OpenZeppelin Subgraphs provide schemas description, with the corresponding indexing logic and templates for building your subgraph manifest.
Expand Down
2 changes: 2 additions & 0 deletions generated/all.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ type ProposalSupport @entity(immutable: true) {
id: ID!
proposal: Proposal!
support: Int!
weight: BigInt!
votes: [VoteReceipt!]! @derivedFrom(field: "support")
}
type VoteReceipt @entity(immutable: true) {
Expand All @@ -322,6 +323,7 @@ type VoteReceipt @entity(immutable: true) {
support: ProposalSupport!
weight: BigInt!
reason: String!
params: Bytes
}
type ProposalCreated implements Event @entity(immutable: true) {
id: ID!
Expand Down
2 changes: 2 additions & 0 deletions generated/governor.schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ProposalSupport @entity(immutable: true) {
id: ID!
proposal: Proposal!
support: Int!
weight: BigInt!
votes: [VoteReceipt!]! @derivedFrom(field: "support")
}
type VoteReceipt @entity(immutable: true) {
Expand All @@ -60,6 +61,7 @@ type VoteReceipt @entity(immutable: true) {
support: ProposalSupport!
weight: BigInt!
reason: String!
params: Bytes
}
type ProposalCreated implements Event @entity(immutable: true) {
id: ID!
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"generated/*.graphql",
"generated/**/*.ts",
"src",
"CHANGELOG",
"CHANGELOG.md",
"LICENCE",
"README"
"README.md"
],
"repository": {
"type": "git",
Expand Down
21 changes: 0 additions & 21 deletions scripts/deploy-all.sh

This file was deleted.

31 changes: 14 additions & 17 deletions scripts/deploy.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#!/usr/bin/env bash

set -o errexit
set -xo errexit

npx graph-compiler \
--config ${CONFIG:-configs/sample.json} \
--include src/datasources \
--export-subgraph \
--export-schema &&
# Default is to deploy all live configs
configs=$@
: ${configs:=configs/live/**/*.json}

npx graph codegen \
${SUBGRAPH:-generated/sample.subgraph.yaml} &&
for config in $configs;
do
subgraph=$(jq -r '.output' $config)
npx graph-compiler --config ${config} --include src/datasources --export-schema --export-subgraph
npx graph codegen ${subgraph}subgraph.yaml

npx graph build \
${SUBGRAPH:-generated/sample.subgraph.yaml} &&

npx graph deploy \
--product hosted-service \
${NAME:-amxx/sandbox} \
${SUBGRAPH:-generated/sample.subgraph.yaml} &&

echo 'done.'
jq -cr '.deploy[].type+" "+.deploy[].name' $config | while read endpoint;
do
npx graph deploy --product ${endpoint} ${subgraph}subgraph.yaml
done
done
6 changes: 3 additions & 3 deletions src/datasources/erc1155.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ethereum,
Address,
BigInt,
} from '@graphprotocol/graph-ts'

Expand All @@ -17,7 +18,6 @@ import {
} from '../../generated/erc1155/IERC1155'

import {
constants,
decimals,
events,
transactions,
Expand Down Expand Up @@ -57,7 +57,7 @@ function registerTransfer(
ev.value = decimals.toDecimals(value)
ev.valueExact = value

if (from.id == constants.ADDRESS_ZERO) {
if (from.id == Address.zero()) {
let totalSupply = fetchERC1155Balance(token, null)
totalSupply.valueExact = totalSupply.valueExact.plus(value)
totalSupply.value = decimals.toDecimals(totalSupply.valueExact)
Expand All @@ -72,7 +72,7 @@ function registerTransfer(
ev.fromBalance = balance.id
}

if (to.id == constants.ADDRESS_ZERO) {
if (to.id == Address.zero()) {
let totalSupply = fetchERC1155Balance(token, null)
totalSupply.valueExact = totalSupply.valueExact.minus(value)
totalSupply.value = decimals.toDecimals(totalSupply.valueExact)
Expand Down
9 changes: 6 additions & 3 deletions src/datasources/erc20.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
Address,
} from '@graphprotocol/graph-ts'

import {
ERC20Transfer,
} from '../../generated/schema'
Expand All @@ -8,7 +12,6 @@ import {
} from '../../generated/erc20/IERC20'

import {
constants,
decimals,
events,
transactions,
Expand All @@ -34,7 +37,7 @@ export function handleTransfer(event: TransferEvent): void {
ev.value = decimals.toDecimals(event.params.value, contract.decimals)
ev.valueExact = event.params.value

if (event.params.from == constants.ADDRESS_ZERO) {
if (event.params.from == Address.zero()) {
let totalSupply = fetchERC20Balance(contract, null)
totalSupply.valueExact = totalSupply.valueExact.plus(event.params.value)
totalSupply.value = decimals.toDecimals(totalSupply.valueExact, contract.decimals)
Expand All @@ -50,7 +53,7 @@ export function handleTransfer(event: TransferEvent): void {
ev.fromBalance = balance.id
}

if (event.params.to == constants.ADDRESS_ZERO) {
if (event.params.to == Address.zero()) {
let totalSupply = fetchERC20Balance(contract, null)
totalSupply.valueExact = totalSupply.valueExact.minus(event.params.value)
totalSupply.value = decimals.toDecimals(totalSupply.valueExact, contract.decimals)
Expand Down
9 changes: 7 additions & 2 deletions src/datasources/erc721.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import {
Address,
} from '@graphprotocol/graph-ts'

import {
ERC721Transfer,
} from '../../generated/schema'
Expand Down Expand Up @@ -30,7 +34,8 @@ export function handleTransfer(event: TransferEvent): void {
let from = fetchAccount(event.params.from)
let to = fetchAccount(event.params.to)

token.owner = to.id
token.owner = to.id
token.approval = fetchAccount(Address.zero()).id // implicit approval reset on transfer

contract.save()
token.save()
Expand All @@ -54,7 +59,7 @@ export function handleApproval(event: ApprovalEvent): void {
let owner = fetchAccount(event.params.owner)
let approved = fetchAccount(event.params.approved)

token.owner = owner.id
token.owner = owner.id // this should not be necessary, owner changed is signaled by a transfer event
token.approval = approved.id

token.save()
Expand Down
4 changes: 3 additions & 1 deletion src/datasources/governor.gql.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"fields": [
{ "name": "proposal", "type": "Proposal!" },
{ "name": "support", "type": "Int!" },
{ "name": "weight", "type": "BigInt!" },
{ "name": "votes", "type": "VoteReceipt!", "derived": "support" }
]
},{
Expand All @@ -70,7 +71,8 @@
{ "name": "voter", "type": "Account!" },
{ "name": "support", "type": "ProposalSupport!" },
{ "name": "weight", "type": "BigInt!" },
{ "name": "reason", "type": "String!" }
{ "name": "reason", "type": "String!" },
{ "name": "params", "type": "Bytes" }
]
},{
"name": "ProposalCreated",
Expand Down
Loading

0 comments on commit e1b5556

Please sign in to comment.