Initial commit

This commit is contained in:
Max Alekseenko 2020-04-02 15:41:14 +03:00
commit 1d208f03b3
5 changed files with 752 additions and 0 deletions

613
abis/Contract.json Normal file
View File

@ -0,0 +1,613 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Deposited",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "roundId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "winner",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "prize",
"type": "uint256"
}
],
"name": "Jackpot",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "uint256",
"name": "roundId",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address[3]",
"name": "winners",
"type": "address[3]"
},
{
"indexed": false,
"internalType": "uint256[3]",
"name": "prizes",
"type": "uint256[3]"
},
{
"indexed": false,
"internalType": "uint256",
"name": "fee",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "feeReceiver",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "jackpotShare",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint256",
"name": "executorReward",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "executor",
"type": "address"
}
],
"name": "Rewarded",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "user",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Withdrawn",
"type": "event"
},
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
{
"constant": true,
"inputs": [
{ "internalType": "address", "name": "_user", "type": "address" }
],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "blockTime",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "deposit",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "executorShare",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "fee",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "feeReceiver",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getLockStart",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [
{ "internalType": "uint256", "name": "_value", "type": "uint256" }
],
"name": "getNewRandom",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "pure",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getPrizeSizes",
"outputs": [
{ "internalType": "uint256[2]", "name": "", "type": "uint256[2]" }
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getRoundInfo",
"outputs": [
{ "internalType": "uint256", "name": "_roundId", "type": "uint256" },
{ "internalType": "uint256", "name": "_startedAt", "type": "uint256" },
{
"internalType": "uint256",
"name": "_roundDuration",
"type": "uint256"
},
{ "internalType": "uint256", "name": "_blockTime", "type": "uint256" },
{ "internalType": "uint256", "name": "_minDeposit", "type": "uint256" },
{ "internalType": "uint256", "name": "_maxDeposit", "type": "uint256" },
{ "internalType": "uint256", "name": "_jackpot", "type": "uint256" },
{ "internalType": "uint256", "name": "_lockStart", "type": "uint256" },
{
"internalType": "uint256",
"name": "_totalDeposited",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getShares",
"outputs": [
{
"internalType": "uint256[2]",
"name": "_prizeSizes",
"type": "uint256[2]"
},
{ "internalType": "uint256", "name": "_fee", "type": "uint256" },
{ "internalType": "address", "name": "_feeReceiver", "type": "address" },
{
"internalType": "uint256",
"name": "_executorShare",
"type": "uint256"
},
{ "internalType": "uint256", "name": "_jackpotShare", "type": "uint256" },
{ "internalType": "uint256", "name": "_jackpotChance", "type": "uint256" }
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "_owner", "type": "address" },
{
"internalType": "address",
"name": "_randomContract",
"type": "address"
},
{
"internalType": "uint256",
"name": "_roundDuration",
"type": "uint256"
},
{ "internalType": "uint256", "name": "_blockTime", "type": "uint256" },
{ "internalType": "uint256", "name": "_minDeposit", "type": "uint256" },
{ "internalType": "uint256", "name": "_maxDeposit", "type": "uint256" },
{
"internalType": "uint256[2]",
"name": "_prizeSizes",
"type": "uint256[2]"
},
{ "internalType": "uint256", "name": "_fee", "type": "uint256" },
{ "internalType": "address", "name": "_feeReceiver", "type": "address" },
{
"internalType": "uint256",
"name": "_executorShare",
"type": "uint256"
},
{ "internalType": "uint256", "name": "_jackpotShare", "type": "uint256" },
{ "internalType": "uint256", "name": "_jackpotChance", "type": "uint256" }
],
"name": "initialize",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "sender", "type": "address" }
],
"name": "initialize",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "isOwner",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "jackpot",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "jackpotChance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "jackpotShare",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "maxDeposit",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "minDeposit",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "nextRound",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "numberOfParticipants",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "posdaoRandomContract",
"outputs": [
{
"internalType": "contract IPOSDAORandom",
"name": "",
"type": "address"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "roundDuration",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "roundId",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_blockTime", "type": "uint256" }
],
"name": "setBlockTime",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_executorShare", "type": "uint256" }
],
"name": "setExecutorShare",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_fee", "type": "uint256" }
],
"name": "setFee",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "_feeReceiver", "type": "address" }
],
"name": "setFeeReceiver",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_jackpotChance", "type": "uint256" }
],
"name": "setJackpotChance",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_jackpotShare", "type": "uint256" }
],
"name": "setJackpotShare",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_maxDeposit", "type": "uint256" }
],
"name": "setMaxDeposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_minDeposit", "type": "uint256" }
],
"name": "setMinDeposit",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "uint256[2]",
"name": "_prizeSizes",
"type": "uint256[2]"
}
],
"name": "setPrizeSizes",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_roundDuration", "type": "uint256" }
],
"name": "setRoundDuration",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "startedAt",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "totalDepositedBalance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "_amount", "type": "uint256" }
],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "withdraw",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]

16
package.json Normal file
View File

@ -0,0 +1,16 @@
{
"name": "poa-mania",
"license": "UNLICENSED",
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ maxaleks/poa-mania",
"create-local": "graph create --node http://localhost:8020/ maxaleks/poa-mania",
"remove-local": "graph remove --node http://localhost:8020/ maxaleks/poa-mania",
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 maxaleks/poa-mania"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.17.1",
"@graphprotocol/graph-ts": "0.17.0"
}
}

6
schema.graphql Normal file
View File

@ -0,0 +1,6 @@
type ExampleEntity @entity {
id: ID!
count: BigInt!
user: Bytes! # address
amount: BigInt! # uint256
}

82
src/mapping.ts Normal file
View File

@ -0,0 +1,82 @@
import { BigInt } from "@graphprotocol/graph-ts"
import {
Contract,
Deposited,
Jackpot,
OwnershipTransferred,
Rewarded,
Withdrawn
} from "../generated/Contract/Contract"
import { ExampleEntity } from "../generated/schema"
export function handleDeposited(event: Deposited): 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.user = event.params.user
entity.amount = event.params.amount
// 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.balanceOf(...)
// - contract.blockTime(...)
// - contract.executorShare(...)
// - contract.fee(...)
// - contract.feeReceiver(...)
// - contract.getLockStart(...)
// - contract.getNewRandom(...)
// - contract.getPrizeSizes(...)
// - contract.getRoundInfo(...)
// - contract.getShares(...)
// - contract.isOwner(...)
// - contract.jackpot(...)
// - contract.jackpotChance(...)
// - contract.jackpotShare(...)
// - contract.maxDeposit(...)
// - contract.minDeposit(...)
// - contract.numberOfParticipants(...)
// - contract.owner(...)
// - contract.posdaoRandomContract(...)
// - contract.roundDuration(...)
// - contract.roundId(...)
// - contract.startedAt(...)
// - contract.totalDepositedBalance(...)
}
export function handleJackpot(event: Jackpot): void {}
export function handleOwnershipTransferred(event: OwnershipTransferred): void {}
export function handleRewarded(event: Rewarded): void {}
export function handleWithdrawn(event: Withdrawn): void {}

35
subgraph.yaml Normal file
View File

@ -0,0 +1,35 @@
specVersion: 0.0.1
schema:
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: Contract
network: poa-core
source:
address: "0xf7ECea96dA4951e88E699cfb67d909Ec74Ba917E"
abi: Contract
mapping:
kind: ethereum/events
apiVersion: 0.0.2
language: wasm/assemblyscript
entities:
- Deposited
- Jackpot
- OwnershipTransferred
- Rewarded
- Withdrawn
abis:
- name: Contract
file: ./abis/Contract.json
eventHandlers:
- event: Deposited(indexed address,uint256)
handler: handleDeposited
- event: Jackpot(indexed uint256,address,uint256)
handler: handleJackpot
- event: OwnershipTransferred(indexed address,indexed address)
handler: handleOwnershipTransferred
- event: Rewarded(indexed uint256,address[3],uint256[3],uint256,address,uint256,uint256,address)
handler: handleRewarded
- event: Withdrawn(indexed address,uint256)
handler: handleWithdrawn
file: ./src/mapping.ts