Skip to content

Commit

Permalink
Start on adding indexing rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
davekaj committed Aug 20, 2020
1 parent b10ebef commit a5f62eb
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 43 deletions.
20 changes: 10 additions & 10 deletions config/generatedAddresses.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"graphToken": "0xa887a968BDb0e42D3Ffc2d6ff253568c6d2CaF34",
"epochManager": "0xFd12A3ee8Bf3C417e0cedbc591BA10156724C069",
"disputeManager": "0x449B394836881CA995d4db4313064a66aF5Ca0b0",
"staking": "0xFC6CCBa00ceA43512cC50f6f8CC029E782c5AC96",
"curation": "0x17F93B680C293308C1bA4C647a2823e175E32818",
"rewardsManager": "0x20AbE3B457e510EEF66D2518212A6f862E1ebfA9",
"serviceRegistry": "0x3f721A12d82A5A8a5132e93d6f0707031E4810E4",
"gns": "0x497609273754d77F354B26f7CCbb30a78468B00c",
"ens": "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e",
"ensPublicResolver": "0xc30F6CCc48F1eA5374aC618dfe5243ddD1e264E7",
"graphToken": "0x71f250B2b52EB84608fA2Bd02c08B407E89594A1",
"epochManager": "0xe49878463A5296a0B8087f5Fd100FAfAB4F0BD32",
"disputeManager": "0xfb1E055112008BBCc9d2415685cd463342796510",
"staking": "0xA62BF1D476164D73817145A4C4585df8d998AD0b",
"curation": "0x4586C4377aA36bc8101ec54B3CEE7e1f618c1b35",
"rewardsManager": "0x39300D136211838914EC93585e15cAaC1B7D2b5F",
"serviceRegistry": "0x4249F468d5865EE8Ada14e0a41BfbaC9cf4688A5",
"gns": "0xFf0384D727221E3c6C80Efc70D18090b380d4626",
"ens": "",
"ensPublicResolver": "",
"blockNumber": "6900000",
"network": "rinkeby"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"prettier-write": "prettier --write '**/*.ts'"
},
"devDependencies": {
"@graphprotocol/contracts": "^0.4.7-testnet-phase1",
"@graphprotocol/contracts": "^0.4.9-testnet-phase1",
"@graphprotocol/graph-cli": "^0.18.0",
"@graphprotocol/graph-ts": "^0.18.1",
"@types/node": "^14.0.13",
Expand Down
28 changes: 6 additions & 22 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ type Subgraph @entity {
displayName: String!

# Aggregate data, by combining all versions, and all deployments those versions point to
# TODO - i dont think these two are valid either. Since I can create my own subgraph of any project,
# point it to their subgraph, and it looks like my subgraph has a ton of rewards
"Total inflation rewards earned all time by this subgraph"
totalIndexingRewards: BigInt!
"Total query fees earned by this subgraph"
Expand Down Expand Up @@ -419,8 +421,8 @@ type Allocation @entity {
id: ID!
"Uncompressed public key of the channel"
publicKey: Bytes!
"Proxy of the channel"
proxy: Bytes!
"Asset holder (proxy) of the channel"
assetHolder: Bytes!
"Price of the queries"
price: BigInt!
"Indexer of this allocation"
Expand All @@ -447,6 +449,8 @@ type Allocation @entity {
status: AllocationStatus!
"Timestamp this allocation was created at"
createdAt: Int!
"POI submitted with a settlement"
poi: Bytes!

# Metrics
"Return for this allocation"
Expand Down Expand Up @@ -484,26 +488,6 @@ type Pool @entity {
settledAllocations: [Allocation!]! @derivedFrom(field: "poolSettledIn")
}

"""
All data regarding an Indexing Reward
"""
type IndexingReward @entity {
"Reward ID"
id: ID!
"Minted tokens in this epoch"
mintedTokens: BigInt!
"Epoch the reward was handed out"
epoch: Int!
"Total allocation settled in this epoch"
settledTokenAllocation: BigInt!
"Subgraph deployment that won durning this epoch"
subgraphDeployment: SubgraphDeployment!
"Winning Indexer"
indexer: Indexer!
"True if reward has been claimed"
isClaimed: Boolean!
}

"""
Delegator with all their stakes
"""
Expand Down
60 changes: 60 additions & 0 deletions src/mappings/rewardsManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { GraphNetwork } from '../types/schema'
import { RewardsAssigned, RewardsClaimed } from '../types/RewardsManager/RewardsManager'
import { createOrLoadGraphNetwork, createOrLoadEpoch } from './helpers'

/**
* @dev handleEpochRun
* - updates the last run epoch
*/
export function handleRewardsAssigned(event: RewardsAssigned): void {
// let graphNetwork = GraphNetwork.load('1')
// graphNetwork.lastRunEpoch = event.params.epoch.toI32()
// graphNetwork.save()
}

/**
* @dev handleEpochLengthUpdate
* - updates the length and the last block and epoch it happened
*/
export function handleRewardsClaimed(event: RewardsClaimed): void {
// let graphNetwork = createOrLoadGraphNetwork()
// graphNetwork.epochLength = event.params.epochLength.toI32()
// graphNetwork.lastLengthUpdateEpoch = graphNetwork.currentEpoch
// graphNetwork.lastLengthUpdateBlock = event.block.number.toI32()
// graphNetwork.save()

// let epoch = createOrLoadEpoch(event.block.number)
// epoch.endBlock = epoch.startBlock + graphNetwork.epochLength
// epoch.save()
}

// TODO - do we need to do the deny list?



/*
subgraph.totalIndexingRewards - which is upwards so dont do it
subgraphDeployment.indexingRewardAmount
subgraphDeployment.rebateAmount ??????????
subgraphDeployment.curateFeeREwards??????? xxxxx - this is from AllocationCollected.event.params.curationFees
subgraphDeployment.queryFeeAmount i DOUBT it xxxx same as above
indexer.queryFeesCollected - i doubt it
indexer.queryFeeRebates - ?
indexer.rewardsEarned
allocation.queryFeesCollected - i doubt
allocation.queryFeeRebates - ?
allocatio.CuratorRewards ??xxxxxxxx
TODO - no indexingReward amount here, why not?
pool.claimedFees - ? xxxxxxx -allocation collected gets it
pool.totalFees - ? xxxx-allocation collected gets it
pool.curatorRewards - ?xxxxxxxxxxxx-allocation collected gets it
epoch.totalREwards
epoch.queryFeeRebates - ?
*/
11 changes: 6 additions & 5 deletions src/mappings/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function handleStakeDelegatedWithdrawn(event: StakeDelegatedWithdrawn): v
export function handleAllocationCreated(event: AllocationCreated): void {
let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString()
let indexerID = event.params.indexer.toHexString()
let channelID = event.params.channelID.toHexString()
let channelID = event.params.allocationID.toHexString()
let allocationID = channelID

// update indexer
Expand All @@ -235,7 +235,7 @@ export function handleAllocationCreated(event: AllocationCreated): void {
// create allocation
let allocation = new Allocation(allocationID)
allocation.publicKey = event.params.channelPubKey
allocation.proxy = event.params.proxy
allocation.assetHolder = event.params.assetHolder
allocation.price = event.params.price
allocation.indexer = indexerID
allocation.subgraphDeployment = subgraphDeploymentID
Expand Down Expand Up @@ -264,7 +264,7 @@ export function handleAllocationCreated(event: AllocationCreated): void {
export function handleAllocationCollected(event: AllocationCollected): void {
let subgraphDeploymentID = event.params.subgraphDeploymentID.toHexString()
let indexerID = event.params.indexer.toHexString()
let allocationID = event.params.channelID.toHexString()
let allocationID = event.params.allocationID.toHexString()

// update indexer
let indexer = Indexer.load(indexerID)
Expand Down Expand Up @@ -310,7 +310,7 @@ export function handleAllocationCollected(event: AllocationCollected): void {
*/
export function handleAllocationSettled(event: AllocationSettled): void {
let indexerID = event.params.indexer.toHexString()
let allocationID = event.params.channelID.toHexString()
let allocationID = event.params.allocationID.toHexString()

// update indexer
let indexer = Indexer.load(indexerID)
Expand All @@ -324,6 +324,7 @@ export function handleAllocationSettled(event: AllocationSettled): void {
allocation.poolSettledIn = event.params.epoch.toString()
allocation.effectiveAllocation = event.params.effectiveAllocation
allocation.status = 'Settled'
allocation.poi = event.params.poi
allocation.save()

// update epoch - I don't think there is any here to update. not 100% sure
Expand Down Expand Up @@ -355,7 +356,7 @@ export function handleAllocationSettled(event: AllocationSettled): void {
*/
export function handleRebateClaimed(event: RebateClaimed): void {
let indexerID = event.params.indexer.toHexString()
let allocationID = event.params.channelID.toHexString()
let allocationID = event.params.allocationID.toHexString()

// update indexer
let indexer = Indexer.load(indexerID)
Expand Down
25 changes: 24 additions & 1 deletion subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ dataSources:
handler: handleAllocationCreated
- event: AllocationCollected(indexed address,indexed bytes32,uint256,uint256,address,address,uint256,uint256)
handler: handleAllocationCollected
- event: AllocationSettled(indexed address,indexed bytes32,uint256,uint256,address,uint256,address)
- event: AllocationSettled(indexed address,indexed bytes32,uint256,uint256,address,uint256,address,bytes32)
handler: handleAllocationSettled
- event: RebateClaimed(indexed address,indexed bytes32,address,uint256,uint256,uint256,uint256,uint256)
handler: handleRebateClaimed
Expand Down Expand Up @@ -224,3 +224,26 @@ dataSources:
handler: handleEpochRun
- event: EpochLengthUpdate(indexed uint256,uint256)
handler: handleEpochLengthUpdate
- kind: ethereum/contract
name: RewardsManager
network: {{network}}
source:
address: '{{epochManager}}'
abi: RewardsManager
startBlock: {{blockNumber}}
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/rewardsManager.ts
entities:
- TODO
- TODO
abis:
- name: RewardsManager
file: ./node_modules/@graphprotocol/contracts/dist/abis/RewardsManager.json
eventHandlers:
- event: RewardsAssigned(indexed address,indexed address,uint256,uint256)
handler: handleRewardsAssigned
- event: RewardsClaimed(address,uint256)
handler: handleRewardsClaimed
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
dependencies:
regenerator-runtime "^0.13.4"

"@graphprotocol/contracts@^0.4.7-testnet-phase1":
version "0.4.7-testnet-phase1"
resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-0.4.7-testnet-phase1.tgz#cd3e722c09d81634dbc3dbc483bbdd55ca90e234"
integrity sha512-/8QVOp4gdeDIxWe3giKjV/W5bZ9QUcl2LXJtItjYObXBck5whGUE7ynqi9N8u3lSR+WEIL32qE8emt6EaPWsbA==
"@graphprotocol/contracts@^0.4.9-testnet-phase1":
version "0.4.9-testnet-phase1"
resolved "https://registry.yarnpkg.com/@graphprotocol/contracts/-/contracts-0.4.9-testnet-phase1.tgz#354f1b34c2e1a61c7f9f3c173f3dd4b107db8ca2"
integrity sha512-WaY6emlSrHtQF0Yv83FjDUzy8W7MMi1wJVkBShH+co2UxWNXq3Oh7Om1odqoFtPPWDdMQcAJfqee7X6VSAVuHw==

"@graphprotocol/graph-cli@^0.18.0":
version "0.18.0"
Expand Down

0 comments on commit a5f62eb

Please sign in to comment.