diff --git a/subgraph/harb/schema.graphql b/subgraph/harb/schema.graphql index 883e81d..1c4b9bb 100644 --- a/subgraph/harb/schema.graphql +++ b/subgraph/harb/schema.graphql @@ -3,56 +3,56 @@ # scalar BigDecimal type Stats @entity { - id: Bytes! - outstandingSupply: BigInt! # uint256 - activeSupply: BigInt! # uint256 + id: Bytes! + outstandingSupply: BigInt! # uint256 + activeSupply: BigInt! # uint256 + ringBuffer: [BigInt!]! # Ring buffer to store daily totals + ringBufferPointer: Int! # Pointer to the current day in the ring buffer + lastUpdatedHour: Int! # The last updated day boundary (timestamp in days) + totalMinted: BigInt! + mintedLastWeek: BigInt! + mintedLastDay: BigInt! + mintNextHourProjected: BigInt! - ringBuffer: [BigInt!]! # Ring buffer to store daily totals - ringBufferPointer: Int! # Pointer to the current day in the ring buffer - lastUpdatedHour: Int! # The last updated day boundary (timestamp in days) + totalBurned: BigInt! + burnedLastWeek: BigInt! + burnedLastDay: BigInt! + burnNextHourProjected: BigInt! - totalMinted: BigInt! - mintedLastWeek: BigInt! - mintedLastDay: BigInt! - mintNextHourProjected: BigInt! + totalTaxPaid: BigInt! + taxPaidLastWeek: BigInt! + taxPaidLastDay: BigInt! + taxNextHourProjected: BigInt! - totalBurned: BigInt! - burnedLastWeek: BigInt! - burnedLastDay: BigInt! - burnNextHourProjected: BigInt! - - totalTaxPaid: BigInt! - taxPaidLastWeek: BigInt! - taxPaidLastDay: BigInt! - taxNextHourProjected: BigInt! - - totalUbiClaimed: BigInt! - ubiClaimedLastWeek: BigInt! - ubiClaimedLastDay: BigInt! - ubiNextHourProjected: BigInt! + totalUbiClaimed: BigInt! + ubiClaimedLastWeek: BigInt! + ubiClaimedLastDay: BigInt! + ubiNextHourProjected: BigInt! } enum PositionStatus { - Active, - Closed, + Active + Closed } type Position @entity { - id: Bytes! - owner: Bytes! # address - share: BigDecimal! - # harb at start - # current harb value - creationTime: Int! - lastTaxTime: Int - taxRate: BigDecimal! - taxPaid: BigInt! - totalSupplyInit: BigInt! - totalSupplyEnd: BigInt - status: PositionStatus! + id: Bytes! + owner: Bytes! # address + share: BigDecimal! + # harb at start + # current harb value + creationTime: Int! + lastTaxTime: Int + taxRate: BigDecimal! + taxPaid: BigInt! + harbDeposit: BigInt! + snatched: Int! + totalSupplyInit: BigInt! + totalSupplyEnd: BigInt + status: PositionStatus! } # type Query { # stats: [Stats!] # positions: [Position!] -#} \ No newline at end of file +#} diff --git a/subgraph/harb/src/stake.ts b/subgraph/harb/src/stake.ts index 8b4cee5..9e7bf12 100644 --- a/subgraph/harb/src/stake.ts +++ b/subgraph/harb/src/stake.ts @@ -1,43 +1,56 @@ import { - PositionCreated as PositionCreatedEvent, - PositionRemoved as PositionRemovedEvent, - PositionTaxPaid as PositionTaxPaidEvent, -} from "../generated/Stake/Stake" -import { Harb } from "../generated/Harb/Harb" -import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts" -import { Position } from "../generated/schema" + PositionCreated as PositionCreatedEvent, + PositionRemoved as PositionRemovedEvent, + PositionTaxPaid as PositionTaxPaidEvent, + PositionShrunk as PositionShrunkEvent, +} from "../generated/Stake/Stake"; +import { Harb } from "../generated/Harb/Harb"; +import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts"; +import { Position } from "../generated/schema"; -let decimals: BigDecimal = BigDecimal.fromString("1000000000000000000") -let totalSupply: BigDecimal = BigDecimal.fromString("10000000000000000000000000") +let decimals: BigDecimal = BigDecimal.fromString("1000000000000000000"); +let totalSupply: BigDecimal = BigDecimal.fromString("10000000000000000000000000"); export function handlePositionCreated(event: PositionCreatedEvent): void { - let position = new Position(Bytes.fromI32(event.params.positionId.toI32())) - position.owner = event.params.owner - position.share = event.params.share.toBigDecimal().div(totalSupply) - position.creationTime = event.block.timestamp.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() + let position = new Position(Bytes.fromI32(event.params.positionId.toI32())); + position.owner = event.params.owner; + position.share = event.params.share.toBigDecimal().div(totalSupply); + position.creationTime = event.block.timestamp.toI32(); + position.taxRate = event.params.taxRate.toBigDecimal().div(BigDecimal.fromString("100")); + position.harbDeposit = event.params.harbDeposit; + position.status = "Active"; + position.snatched = 0; + position.taxPaid = BigInt.fromString("0"); + let harb = Harb.bind(event.address); + position.totalSupplyInit = harb.totalSupply(); + position.save(); } 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() - } + 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 handlePositionShrunk(event: PositionShrunkEvent): void { + let position = Position.load(Bytes.fromI32(event.params.positionId.toI32())); + if (position != null) { + position.share = event.params.newShares.toBigDecimal().div(totalSupply); + position.harbDeposit = position.harbDeposit.minus(event.params.harbPayout); + position.snatched = position.snatched++; + position.save(); + } } export function handleTaxPaid(event: PositionTaxPaidEvent): void { - let position = Position.load(Bytes.fromI32(event.params.positionId.toI32())) - if (position != null) { - position.taxPaid = position.taxPaid.plus(event.params.taxPaid) - position.taxRate = event.params.taxRate.toBigDecimal().div(BigDecimal.fromString("100")) - position.save() - } - } + let position = Position.load(Bytes.fromI32(event.params.positionId.toI32())); + if (position != null) { + position.taxPaid = position.taxPaid.plus(event.params.taxPaid); + position.taxRate = event.params.taxRate.toBigDecimal().div(BigDecimal.fromString("100")); + position.save(); + } +} diff --git a/subgraph/harb/subgraph.yaml b/subgraph/harb/subgraph.yaml index e35ba21..87b0aa3 100644 --- a/subgraph/harb/subgraph.yaml +++ b/subgraph/harb/subgraph.yaml @@ -2,56 +2,58 @@ specVersion: 0.0.4 repository: http://gitea.loseyourip.com:4000/dark-meme-society/harb.git description: Harberger Tax Token schema: - file: ./schema.graphql + file: ./schema.graphql dataSources: - - kind: ethereum - name: Harb - network: sepolia - source: - address: "0x087F256D11fe533b0c7d372e44Ee0F9e47C89dF9" - abi: Harb - startBlock: 6152180 - mapping: - kind: ethereum/events - apiVersion: 0.0.7 - language: wasm/assemblyscript - entities: - - Stats - - UbiClaim - abis: - - name: Harb - file: ./abis/Harb.json - eventHandlers: - - event: Transfer(indexed address,indexed address,uint256) - handler: handleTransfer - - event: UbiClaimed(indexed address,uint256) - handler: handleUbiClaimed - blockHandlers: - - handler: handleBlock - file: ./src/harb.ts - - kind: ethereum - name: Stake - network: sepolia - source: - address: "0xCd21a41a137BCAf8743E47D048F57D92398f7Da9" - abi: Stake - startBlock: 6182180 - mapping: - kind: ethereum/events - apiVersion: 0.0.7 - language: wasm/assemblyscript - entities: - - Position - abis: - - name: Stake - file: ./abis/Stake.json - - name: Harb - file: ./abis/Harb.json - eventHandlers: - - event: PositionCreated(indexed uint256,indexed address,uint256,uint256,uint32) - handler: handlePositionCreated - - event: PositionRemoved(indexed uint256,indexed address,uint256) - handler: handlePositionRemoved - - event: PositionTaxPaid(indexed uint256,indexed address,uint256,uint256,uint256) - handler: handleTaxPaid - file: ./src/stake.ts + - kind: ethereum + name: Harb + network: sepolia + source: + address: "0x087F256D11fe533b0c7d372e44Ee0F9e47C89dF9" + abi: Harb + startBlock: 6152180 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Stats + - UbiClaim + abis: + - name: Harb + file: ./abis/Harb.json + eventHandlers: + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + - event: UbiClaimed(indexed address,uint256) + handler: handleUbiClaimed + blockHandlers: + - handler: handleBlock + file: ./src/harb.ts + - kind: ethereum + name: Stake + network: sepolia + source: + address: "0xCd21a41a137BCAf8743E47D048F57D92398f7Da9" + abi: Stake + startBlock: 6182180 + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + entities: + - Position + abis: + - name: Stake + file: ./abis/Stake.json + - name: Harb + file: ./abis/Harb.json + eventHandlers: + - event: PositionCreated(indexed uint256,indexed address,uint256,uint256,uint32) + handler: handlePositionCreated + - event: PositionRemoved(indexed uint256,indexed address,uint256) + handler: handlePositionRemoved + - event: PositionShrunk(indexed uint256,indexed address,uint256,uint256) + handler: handlePositionShrunk + - event: PositionTaxPaid(indexed uint256,indexed address,uint256,uint256,uint256) + handler: handleTaxPaid + file: ./src/stake.ts