mirror of https://github.com/dap-ps/graph.git
Initial commit
This commit is contained in:
commit
3368482022
|
@ -0,0 +1,286 @@
|
|||
[
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_amount", "type": "uint256" }
|
||||
],
|
||||
"name": "withdraw",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_amount", "type": "uint256" }
|
||||
],
|
||||
"name": "upvoteEffect",
|
||||
"outputs": [{ "name": "effect", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "safeMax",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_amount", "type": "uint256" }
|
||||
],
|
||||
"name": "upvote",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "total",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "decimals",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [{ "name": "_newController", "type": "address" }],
|
||||
"name": "changeController",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "", "type": "bytes32" }],
|
||||
"name": "existingIDs",
|
||||
"outputs": [{ "name": "", "type": "bool" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "getDAppsCount",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "max",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "_id", "type": "bytes32" }],
|
||||
"name": "downvoteCost",
|
||||
"outputs": [
|
||||
{ "name": "b", "type": "uint256" },
|
||||
{ "name": "vR", "type": "uint256" },
|
||||
{ "name": "c", "type": "uint256" }
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "ceiling",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_amount", "type": "uint256" },
|
||||
{ "name": "_metadata", "type": "bytes32" }
|
||||
],
|
||||
"name": "createDApp",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [{ "name": "_newCeiling", "type": "uint256" }],
|
||||
"name": "setCeiling",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_from", "type": "address" },
|
||||
{ "name": "_amount", "type": "uint256" },
|
||||
{ "name": "_token", "type": "address" },
|
||||
{ "name": "_data", "type": "bytes" }
|
||||
],
|
||||
"name": "receiveApproval",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "", "type": "uint256" }],
|
||||
"name": "dapps",
|
||||
"outputs": [
|
||||
{ "name": "developer", "type": "address" },
|
||||
{ "name": "id", "type": "bytes32" },
|
||||
{ "name": "metadata", "type": "bytes32" },
|
||||
{ "name": "balance", "type": "uint256" },
|
||||
{ "name": "rate", "type": "uint256" },
|
||||
{ "name": "available", "type": "uint256" },
|
||||
{ "name": "votesMinted", "type": "uint256" },
|
||||
{ "name": "votesCast", "type": "uint256" },
|
||||
{ "name": "effectiveBalance", "type": "uint256" }
|
||||
],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "", "type": "bytes32" }],
|
||||
"name": "id2index",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_amount", "type": "uint256" }
|
||||
],
|
||||
"name": "downvote",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [{ "name": "_id", "type": "bytes32" }],
|
||||
"name": "withdrawMax",
|
||||
"outputs": [{ "name": "", "type": "uint256" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{ "name": "_id", "type": "bytes32" },
|
||||
{ "name": "_metadata", "type": "bytes32" }
|
||||
],
|
||||
"name": "setMetadata",
|
||||
"outputs": [],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"constant": true,
|
||||
"inputs": [],
|
||||
"name": "controller",
|
||||
"outputs": [{ "name": "", "type": "address" }],
|
||||
"payable": false,
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [{ "name": "_SNT", "type": "address" }],
|
||||
"payable": false,
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{ "indexed": true, "name": "id", "type": "bytes32" },
|
||||
{ "indexed": false, "name": "newEffectiveBalance", "type": "uint256" }
|
||||
],
|
||||
"name": "DAppCreated",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{ "indexed": true, "name": "id", "type": "bytes32" },
|
||||
{ "indexed": false, "name": "newEffectiveBalance", "type": "uint256" }
|
||||
],
|
||||
"name": "Upvote",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{ "indexed": true, "name": "id", "type": "bytes32" },
|
||||
{ "indexed": false, "name": "newEffectiveBalance", "type": "uint256" }
|
||||
],
|
||||
"name": "Downvote",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{ "indexed": true, "name": "id", "type": "bytes32" },
|
||||
{ "indexed": false, "name": "newEffectiveBalance", "type": "uint256" }
|
||||
],
|
||||
"name": "Withdraw",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [{ "indexed": true, "name": "id", "type": "bytes32" }],
|
||||
"name": "MetadataUpdated",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{ "indexed": false, "name": "oldCeiling", "type": "uint256" },
|
||||
{ "indexed": false, "name": "newCeiling", "type": "uint256" }
|
||||
],
|
||||
"name": "CeilingUpdated",
|
||||
"type": "event"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "dapps",
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"codegen": "graph codegen",
|
||||
"build": "graph build",
|
||||
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ andytudhope/dapps",
|
||||
"create-local": "graph create --node http://localhost:8020/ andytudhope/dapps",
|
||||
"remove-local": "graph remove --node http://localhost:8020/ andytudhope/dapps",
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 andytudhope/dapps"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-cli": "0.17.1",
|
||||
"@graphprotocol/graph-ts": "0.17.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
type ExampleEntity @entity {
|
||||
id: ID!
|
||||
count: BigInt!
|
||||
id: Bytes! # bytes32
|
||||
newEffectiveBalance: BigInt! # uint256
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
import { BigInt } from "@graphprotocol/graph-ts"
|
||||
import {
|
||||
Contract,
|
||||
DAppCreated,
|
||||
Upvote,
|
||||
Downvote,
|
||||
Withdraw,
|
||||
MetadataUpdated,
|
||||
CeilingUpdated
|
||||
} from "../generated/Contract/Contract"
|
||||
import { ExampleEntity } from "../generated/schema"
|
||||
|
||||
export function handleDAppCreated(event: DAppCreated): void {
|
||||
// Entities can be loaded from the store using a string ID; this ID
|
||||
// needs to be unique across all entities of the same type
|
||||
let entity = ExampleEntity.load(event.transaction.from.toHex())
|
||||
|
||||
// Entities only exist after they have been saved to the store;
|
||||
// `null` checks allow to create entities on demand
|
||||
if (entity == null) {
|
||||
entity = new ExampleEntity(event.transaction.from.toHex())
|
||||
|
||||
// Entity fields can be set using simple assignments
|
||||
entity.count = BigInt.fromI32(0)
|
||||
}
|
||||
|
||||
// BigInt and BigDecimal math are supported
|
||||
entity.count = entity.count + BigInt.fromI32(1)
|
||||
|
||||
// Entity fields can be set based on event parameters
|
||||
entity.id = event.params.id
|
||||
entity.newEffectiveBalance = event.params.newEffectiveBalance
|
||||
|
||||
// Entities can be written to the store with `.save()`
|
||||
entity.save()
|
||||
|
||||
// Note: If a handler doesn't require existing field values, it is faster
|
||||
// _not_ to load the entity from the store. Instead, create it fresh with
|
||||
// `new Entity(...)`, set the fields that should be updated and save the
|
||||
// entity back to the store. Fields that were not set or unset remain
|
||||
// unchanged, allowing for partial updates to be applied.
|
||||
|
||||
// It is also possible to access smart contracts from mappings. For
|
||||
// example, the contract that has emitted the event can be connected to
|
||||
// with:
|
||||
//
|
||||
// let contract = Contract.bind(event.address)
|
||||
//
|
||||
// The following functions can then be called on this contract to access
|
||||
// state variables and other data:
|
||||
//
|
||||
// - contract.upvoteEffect(...)
|
||||
// - contract.safeMax(...)
|
||||
// - contract.total(...)
|
||||
// - contract.decimals(...)
|
||||
// - contract.existingIDs(...)
|
||||
// - contract.getDAppsCount(...)
|
||||
// - contract.max(...)
|
||||
// - contract.downvoteCost(...)
|
||||
// - contract.ceiling(...)
|
||||
// - contract.dapps(...)
|
||||
// - contract.id2index(...)
|
||||
// - contract.withdrawMax(...)
|
||||
// - contract.controller(...)
|
||||
}
|
||||
|
||||
export function handleUpvote(event: Upvote): void {}
|
||||
|
||||
export function handleDownvote(event: Downvote): void {}
|
||||
|
||||
export function handleWithdraw(event: Withdraw): void {}
|
||||
|
||||
export function handleMetadataUpdated(event: MetadataUpdated): void {}
|
||||
|
||||
export function handleCeilingUpdated(event: CeilingUpdated): void {}
|
|
@ -0,0 +1,38 @@
|
|||
specVersion: 0.0.1
|
||||
schema:
|
||||
file: ./schema.graphql
|
||||
dataSources:
|
||||
- kind: ethereum/contract
|
||||
name: Contract
|
||||
network: mainnet
|
||||
source:
|
||||
address: "0x5bCF2767F86f14eDd82053bfBfd5069F68C2C5F8"
|
||||
abi: Contract
|
||||
mapping:
|
||||
kind: ethereum/events
|
||||
apiVersion: 0.0.2
|
||||
language: wasm/assemblyscript
|
||||
entities:
|
||||
- DAppCreated
|
||||
- Upvote
|
||||
- Downvote
|
||||
- Withdraw
|
||||
- MetadataUpdated
|
||||
- CeilingUpdated
|
||||
abis:
|
||||
- name: Contract
|
||||
file: ./abis/Contract.json
|
||||
eventHandlers:
|
||||
- event: DAppCreated(indexed bytes32,uint256)
|
||||
handler: handleDAppCreated
|
||||
- event: Upvote(indexed bytes32,uint256)
|
||||
handler: handleUpvote
|
||||
- event: Downvote(indexed bytes32,uint256)
|
||||
handler: handleDownvote
|
||||
- event: Withdraw(indexed bytes32,uint256)
|
||||
handler: handleWithdraw
|
||||
- event: MetadataUpdated(indexed bytes32)
|
||||
handler: handleMetadataUpdated
|
||||
- event: CeilingUpdated(uint256,uint256)
|
||||
handler: handleCeilingUpdated
|
||||
file: ./src/mapping.ts
|
Loading…
Reference in New Issue