Skip to content

Commit bf44ae5

Browse files
committed
feat: add tax tracking for Horizon through GraphPayments
1 parent ee06965 commit bf44ae5

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

config/addresses.template.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class Addresses {
2121
l2GraphTokenGateway: string
2222
ethereumDIDRegistry: string
2323
subgraphService: string
24+
graphPayments: string
2425
isL1: boolean
2526
}
2627

@@ -47,5 +48,6 @@ export let addresses: Addresses = {
4748
l2GraphTokenGateway: '{{l2GraphTokenGateway}}',
4849
ethereumDIDRegistry: '{{ethereumDIDRegistry}}',
4950
subgraphService: '{{subgraphService}}',
51+
graphPayments: '{{graphPayments}}',
5052
isL1: {{isL1}},
5153
}

config/arbitrumSepoliaAddressScript.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let addresses: Addresses = {
3030
l2GraphTokenGateway: '{{arbsep.L2GraphTokenGateway.address}}',
3131
ethereumDIDRegistry: '{{arbsep.EthereumDIDRegistry.address}}',
3232
subgraphService: '{{arbsep.SubgraphService.address}}',
33+
graphPayments: '{{arbsep.GraphPayments.address}}',
3334
isL1: false,
3435
}
3536

@@ -46,6 +47,13 @@ const main = (): void => {
4647
if(output.ethereumDIDRegistry == '') {
4748
output.ethereumDIDRegistry = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
4849
}
50+
// remove once we have proper packages
51+
if(output.subgraphService == '') {
52+
output.subgraphService = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
53+
}
54+
if(output.graphPayments == '') {
55+
output.graphPayments = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
56+
}
4957
fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2))
5058
} catch (e) {
5159
console.log(`Error saving artifacts: ${e.message}`)

config/mainnetArbitrumAddressScript.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let addresses: Addresses = {
3030
l2GraphTokenGateway: '{{arbitrum.L2GraphTokenGateway.address}}',
3131
ethereumDIDRegistry: '{{arbitrum.IEthereumDIDRegistry.address}}',
3232
subgraphService: '{{arbitrum.SubgraphService.address}}',
33+
graphPayments: '{{arbitrum.GraphPayments.address}}',
3334
isL1: false,
3435
}
3536

@@ -51,6 +52,9 @@ const main = (): void => {
5152
if(output.subgraphService == '') {
5253
output.subgraphService = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
5354
}
55+
if(output.graphPayments == '') {
56+
output.graphPayments = '0x0000000000000000000000000000000000000000' // to avoid crashes due to bad config
57+
}
5458
fs.writeFileSync(__dirname + '/generatedAddresses.json', JSON.stringify(output, null, 2))
5559
} catch (e) {
5660
console.log(`Error saving artifacts: ${e.message}`)

config/testAddressesL1.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let addresses: Addresses = {
3030
l2GraphTokenGateway: '',
3131
ethereumDIDRegistry: '0x0000000000000000000000000000000000000000',
3232
subgraphService: '0x0000000000000000000000000000000000000000',
33+
graphPayments: '0x0000000000000000000000000000000000000000',
3334
isL1: true,
3435
}
3536

config/testAddressesL2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export let addresses: Addresses = {
3030
l2GraphTokenGateway: '0x0000000000000000000000000000000000000000',
3131
ethereumDIDRegistry: '0x0000000000000000000000000000000000000000',
3232
subgraphService: '0x0000000000000000000000000000000000000000',
33+
graphPayments: '0x0000000000000000000000000000000000000000',
3334
isL1: false,
3435
}
3536

src/mappings/graphPayments.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { addresses } from "../../config/addresses"
2+
import { GraphPaymentCollected } from "../types/GraphPayments/GraphPayments"
3+
import { createOrLoadEpoch, createOrLoadGraphNetwork, createOrLoadPaymentSource } from "./helpers/helpers"
4+
5+
export function handleGraphPaymentCollected(event: GraphPaymentCollected): void {
6+
let graphNetwork = createOrLoadGraphNetwork(event.block.number, event.address)
7+
8+
// Update epoch
9+
let epoch = createOrLoadEpoch(
10+
addresses.isL1 ? event.block.number : graphNetwork.currentL1BlockNumber!,
11+
)
12+
epoch.taxedQueryFees = epoch.taxedQueryFees.plus(event.params.tokensProtocol)
13+
epoch.save()
14+
15+
// update graph network
16+
graphNetwork.totalTaxedQueryFees = graphNetwork.totalTaxedQueryFees.plus(event.params.tokensProtocol)
17+
graphNetwork.save()
18+
19+
// Replicate for payment source specific data
20+
let paymentSource = createOrLoadPaymentSource(event.params.payer)
21+
paymentSource.totalTaxedQueryFees = paymentSource.totalTaxedQueryFees.plus(event.params.tokensProtocol)
22+
paymentSource.save()
23+
24+
// Might want to add data service tax tracking here
25+
}

subgraph.template.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,30 @@ dataSources:
465465
handler: handleIndexingRewardsCollected
466466
- event: QueryFeesCollected(indexed address,indexed address,indexed address,bytes32,uint256,uint256)
467467
handler: handleQueryFeesCollected
468+
- kind: ethereum/contract
469+
name: GraphPayments
470+
network: {{network}}
471+
source:
472+
address: "{{graphPayments}}"
473+
abi: GraphPayments
474+
startBlock: {{blockNumber}}
475+
mapping:
476+
kind: ethereum/events
477+
apiVersion: 0.0.7
478+
language: wasm/assemblyscript
479+
file: ./src/mappings/graphPayments.ts
480+
entities:
481+
- GraphNetwork
482+
abis:
483+
- name: GraphPayments
484+
file: ./abis/GraphPayments.json
485+
- name: GraphToken
486+
file: ./node_modules/@graphprotocol/contracts/dist/abis/GraphToken.json
487+
- name: EpochManager
488+
file: ./node_modules/@graphprotocol/contracts/dist/abis/EpochManager.json
489+
eventHandlers:
490+
- event: GraphPaymentCollected(indexed uint8,indexed address,address,indexed address,uint256,uint256,uint256,uint256,uint256)
491+
handler: handleGraphPaymentCollected
468492
- kind: ethereum/contract
469493
name: Curation
470494
network: {{network}}

0 commit comments

Comments
 (0)