subgraph added taxPaid, totalSupplyInit, totalSupplyEnd
This commit is contained in:
parent
54d2c2040a
commit
cad2b6a527
4 changed files with 5926 additions and 0 deletions
5904
subgraph/harb/package-lock.json
generated
Normal file
5904
subgraph/harb/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -46,6 +46,9 @@ type Position @entity {
|
|||
creationTime: Int!
|
||||
lastTaxTime: Int
|
||||
taxRate: BigDecimal!
|
||||
taxPaid: BigInt!
|
||||
totalSupplyInit: BigInt!
|
||||
totalSupplyEnd: BigInt
|
||||
status: PositionStatus!
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import {
|
||||
PositionCreated as PositionCreatedEvent,
|
||||
PositionRemoved as PositionRemovedEvent,
|
||||
TaxPaid,
|
||||
} from "../generated/Stake/Stake"
|
||||
import { Harb } from "../generated/Harb/Harb"
|
||||
import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"
|
||||
import { Position } from "../generated/schema"
|
||||
|
||||
|
|
@ -15,6 +17,9 @@ export function handlePositionCreated(event: PositionCreatedEvent): void {
|
|||
position.creationTime = event.params.creationTime.toI32();
|
||||
position.taxRate = event.params.taxRate.toBigDecimal().div(BigDecimal.fromString("100"))
|
||||
position.status = "Active"
|
||||
position.taxPaid = BigInt.fromString("0")
|
||||
let harb = Harb.bind(event.address)
|
||||
position.totalSupplyInit = harb.totalSupply()
|
||||
position.save()
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +27,16 @@ export function handlePositionRemoved(event: PositionRemovedEvent): void {
|
|||
let position = Position.load(Bytes.fromI32(event.params.positionId.toI32()))
|
||||
if (position != null) {
|
||||
position.status = "Closed"
|
||||
let harb = Harb.bind(event.address)
|
||||
position.totalSupplyEnd = harb.totalSupply()
|
||||
position.save()
|
||||
}
|
||||
}
|
||||
|
||||
export function handleTaxPaid(event: TaxPaid): void {
|
||||
let position = Position.load(Bytes.fromI32(event.params.positionId.toI32()))
|
||||
if (position != null) {
|
||||
position.taxPaid = position.taxPaid.plus(event.params.taxAmount)
|
||||
position.save()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,9 +45,13 @@ dataSources:
|
|||
abis:
|
||||
- name: Stake
|
||||
file: ./abis/Stake.json
|
||||
- name: Harb
|
||||
file: ./abis/Harb.json
|
||||
eventHandlers:
|
||||
- event: PositionCreated(indexed uint256,indexed address,uint256,uint32,uint32)
|
||||
handler: handlePositionCreated
|
||||
- event: PositionRemoved(indexed uint256,uint256,uint32)
|
||||
handler: handlePositionRemoved
|
||||
- event: TaxPaid(indexed uint256,indexed address,uint256)
|
||||
handler: handleTaxPaid
|
||||
file: ./src/stake.ts
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue