From 8ff75f4cc3c0776712c81fce14063d2de7a4678d Mon Sep 17 00:00:00 2001 From: JulesCrown Date: Wed, 15 May 2024 19:21:35 +0200 Subject: [PATCH] stats for ubi and profit --- subgraph/harb/abis/Harb.json | 346 +--------------------------------- subgraph/harb/abis/Stake.json | 210 +-------------------- subgraph/harb/networks.json | 8 +- subgraph/harb/schema.graphql | 19 ++ subgraph/harb/src/harb.ts | 197 ++++++++++++++++++- subgraph/harb/subgraph.yaml | 17 +- 6 files changed, 222 insertions(+), 575 deletions(-) diff --git a/subgraph/harb/abis/Harb.json b/subgraph/harb/abis/Harb.json index 3bd9ee8..2b55e45 100644 --- a/subgraph/harb/abis/Harb.json +++ b/subgraph/harb/abis/Harb.json @@ -1,345 +1 @@ -[ - { - "inputs": [ - { "internalType": "string", "name": "name_", "type": "string" }, - { "internalType": "string", "name": "symbol_", "type": "string" }, - { "internalType": "address", "name": "_factory", "type": "address" }, - { "internalType": "address", "name": "_WETH9", "type": "address" }, - { - "internalType": "contract TwabController", - "name": "twabController_", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { "inputs": [], "name": "InvalidShortString", "type": "error" }, - { - "inputs": [{ "internalType": "string", "name": "str", "type": "string" }], - "name": "StringTooLong", - "type": "error" - }, - { "inputs": [], "name": "ZeroAddressInConstructor", "type": "error" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "spender", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Approval", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "EIP712DomainChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "from", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "value", - "type": "uint256" - } - ], - "name": "Transfer", - "type": "event" - }, - { - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "TAX_POOL", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" }, - { "internalType": "address", "name": "spender", "type": "address" } - ], - "name": "allowance", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "spender", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "approve", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "_account", "type": "address" } - ], - "name": "balanceOf", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_amount", "type": "uint256" } - ], - "name": "burn", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "_account", "type": "address" } - ], - "name": "claimUbi", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "decimals", - "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "spender", "type": "address" }, - { - "internalType": "uint256", - "name": "subtractedValue", - "type": "uint256" - } - ], - "name": "decreaseAllowance", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "eip712Domain", - "outputs": [ - { "internalType": "bytes1", "name": "fields", "type": "bytes1" }, - { "internalType": "string", "name": "name", "type": "string" }, - { "internalType": "string", "name": "version", "type": "string" }, - { "internalType": "uint256", "name": "chainId", "type": "uint256" }, - { - "internalType": "address", - "name": "verifyingContract", - "type": "address" - }, - { "internalType": "bytes32", "name": "salt", "type": "bytes32" }, - { "internalType": "uint256[]", "name": "extensions", "type": "uint256[]" } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "_account", "type": "address" } - ], - "name": "getUbiDue", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "spender", "type": "address" }, - { "internalType": "uint256", "name": "addedValue", "type": "uint256" } - ], - "name": "increaseAllowance", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "liquidityManager", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "_amount", "type": "uint256" } - ], - "name": "mint", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "name", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" } - ], - "name": "nonces", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "owner", "type": "address" }, - { "internalType": "address", "name": "spender", "type": "address" }, - { "internalType": "uint256", "name": "value", "type": "uint256" }, - { "internalType": "uint256", "name": "deadline", "type": "uint256" }, - { "internalType": "uint8", "name": "v", "type": "uint8" }, - { "internalType": "bytes32", "name": "r", "type": "bytes32" }, - { "internalType": "bytes32", "name": "s", "type": "bytes32" } - ], - "name": "permit", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "liquidityManager_", - "type": "address" - } - ], - "name": "setLiquidityManager", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "stakingPool_", "type": "address" } - ], - "name": "setStakingPool", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "stakingPool", - "outputs": [{ "internalType": "address", "name": "", "type": "address" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "sumTaxCollected", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "symbol", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "transfer", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "from", "type": "address" }, - { "internalType": "address", "name": "to", "type": "address" }, - { "internalType": "uint256", "name": "amount", "type": "uint256" } - ], - "name": "transferFrom", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "twabController", - "outputs": [ - { - "internalType": "contract TwabController", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [{ "internalType": "address", "name": "", "type": "address" }], - "name": "ubiTitles", - "outputs": [ - { - "internalType": "uint256", - "name": "sumTaxCollected", - "type": "uint256" - }, - { "internalType": "uint256", "name": "time", "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" - } -] +[{"inputs":[{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"},{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_WETH9","type":"address"},{"internalType":"contract TwabController","name":"twabController_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"ZeroAddressInConstructor","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"ubiAmount","type":"uint256"}],"name":"UbiClaimed","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TAX_POOL","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"claimUbi","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"getUbiDue","outputs":[{"internalType":"uint256","name":"amountDue","type":"uint256"},{"internalType":"uint256","name":"lastPeriodEndAt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"liquidityManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"liquidityManager_","type":"address"}],"name":"setLiquidityManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stakingPool_","type":"address"}],"name":"setStakingPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stakingPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sumTaxCollected","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"twabController","outputs":[{"internalType":"contract TwabController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"ubiTitles","outputs":[{"internalType":"uint256","name":"sumTaxCollected","type":"uint256"},{"internalType":"uint256","name":"time","type":"uint256"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/subgraph/harb/abis/Stake.json b/subgraph/harb/abis/Stake.json index 70e7688..960dc83 100644 --- a/subgraph/harb/abis/Stake.json +++ b/subgraph/harb/abis/Stake.json @@ -1,209 +1 @@ -[ - { - "inputs": [ - { "internalType": "address", "name": "_tokenContract", "type": "address" } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint256", "name": "stakeWanted", "type": "uint256" }, - { "internalType": "uint256", "name": "availableStake", "type": "uint256" } - ], - "name": "ExceededAvailableStake", - "type": "error" - }, - { - "inputs": [ - { "internalType": "address", "name": "requester", "type": "address" }, - { "internalType": "address", "name": "owner", "type": "address" } - ], - "name": "NoPermission", - "type": "error" - }, - { "inputs": [], "name": "PositionNotFound", "type": "error" }, - { - "inputs": [ - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint256", "name": "assets", "type": "uint256" }, - { "internalType": "uint256", "name": "sharesWanted", "type": "uint256" }, - { "internalType": "uint256", "name": "minStake", "type": "uint256" } - ], - "name": "SharesTooLow", - "type": "error" - }, - { - "inputs": [ - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint64", "name": "taxRateWanted", "type": "uint64" }, - { "internalType": "uint64", "name": "taxRateMet", "type": "uint64" }, - { "internalType": "uint256", "name": "positionId", "type": "uint256" } - ], - "name": "TaxTooLow", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "positionId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "owner", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "share", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "creationTime", - "type": "uint32" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "taxRate", - "type": "uint32" - } - ], - "name": "PositionCreated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "positionId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "share", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint32", - "name": "lastTaxTime", - "type": "uint32" - } - ], - "name": "PositionRemoved", - "type": "event" - }, - { - "inputs": [], - "name": "dormantSupply", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "positionId", "type": "uint256" } - ], - "name": "exitPosition", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "minStake", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "nextPositionId", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "outstandingStake", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "positionID", "type": "uint256" } - ], - "name": "payTax", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "name": "positions", - "outputs": [ - { "internalType": "uint256", "name": "share", "type": "uint256" }, - { "internalType": "address", "name": "owner", "type": "address" }, - { "internalType": "uint32", "name": "creationTime", "type": "uint32" }, - { "internalType": "uint32", "name": "lastTaxTime", "type": "uint32" }, - { "internalType": "uint32", "name": "taxRate", "type": "uint32" } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "assets", "type": "uint256" }, - { "internalType": "address", "name": "receiver", "type": "address" }, - { "internalType": "uint32", "name": "taxRate", "type": "uint32" }, - { - "internalType": "uint256[]", - "name": "positionsToSnatch", - "type": "uint256[]" - } - ], - "name": "snatch", - "outputs": [ - { "internalType": "uint256", "name": "positionId", "type": "uint256" } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "positionID", "type": "uint256" }, - { - "internalType": "uint256", - "name": "taxFloorDuration", - "type": "uint256" - } - ], - "name": "taxDue", - "outputs": [ - { "internalType": "uint256", "name": "amountDue", "type": "uint256" } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "totalSupply", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - } -] +[{"inputs":[{"internalType":"address","name":"_tokenContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"stakeWanted","type":"uint256"},{"internalType":"uint256","name":"availableStake","type":"uint256"}],"name":"ExceededAvailableStake","type":"error"},{"inputs":[{"internalType":"address","name":"requester","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"NoPermission","type":"error"},{"inputs":[],"name":"PositionNotFound","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"sharesWanted","type":"uint256"},{"internalType":"uint256","name":"minStake","type":"uint256"}],"name":"SharesTooLow","type":"error"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint64","name":"taxRateWanted","type":"uint64"},{"internalType":"uint64","name":"taxRateMet","type":"uint64"},{"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"TaxTooLow","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"share","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"creationTime","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"taxRate","type":"uint32"}],"name":"PositionCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"share","type":"uint256"},{"indexed":false,"internalType":"uint32","name":"lastTaxTime","type":"uint32"}],"name":"PositionRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"positionId","type":"uint256"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"taxAmount","type":"uint256"}],"name":"TaxPaid","type":"event"},{"inputs":[{"internalType":"uint256","name":"positionID","type":"uint256"},{"internalType":"uint32","name":"taxRate","type":"uint32"}],"name":"changeTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"dormantSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionId","type":"uint256"}],"name":"exitPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"minStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextPositionId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"outstandingStake","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionID","type":"uint256"}],"name":"payTax","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint32","name":"taxRate","type":"uint32"},{"internalType":"uint256[]","name":"positionsToSnatch","type":"uint256[]"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permitAndSnatch","outputs":[{"internalType":"uint256","name":"positionId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"positions","outputs":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint32","name":"creationTime","type":"uint32"},{"internalType":"uint32","name":"lastTaxTime","type":"uint32"},{"internalType":"uint32","name":"taxRate","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint32","name":"taxRate","type":"uint32"},{"internalType":"uint256[]","name":"positionsToSnatch","type":"uint256[]"}],"name":"snatch","outputs":[{"internalType":"uint256","name":"positionId","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"positionID","type":"uint256"},{"internalType":"uint256","name":"taxFloorDuration","type":"uint256"}],"name":"taxDue","outputs":[{"internalType":"uint256","name":"amountDue","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] \ No newline at end of file diff --git a/subgraph/harb/networks.json b/subgraph/harb/networks.json index 608207f..6d6ab48 100644 --- a/subgraph/harb/networks.json +++ b/subgraph/harb/networks.json @@ -1,12 +1,12 @@ { "sepolia": { "Harb": { - "address": "0xcd02666582a2057085edabc55c5120155ba4e93c", - "startBlock": 5510934 + "address": "0xaf0a83ae80be549d32f94b74a4bdcda9090c4c8b", + "startBlock": 5899691 }, "Stake": { - "address": "0x4256777543814d66f9f66390f6bb33c55a24c331", - "startBlock": 5510934 + "address": "0x4a7acb6b7318b775dccf00e378449290162cf382", + "startBlock": 5899691 } } } \ No newline at end of file diff --git a/subgraph/harb/schema.graphql b/subgraph/harb/schema.graphql index 5dd640f..30d72d3 100644 --- a/subgraph/harb/schema.graphql +++ b/subgraph/harb/schema.graphql @@ -6,6 +6,25 @@ type Stats @entity { id: Bytes! outstandingSupply: BigInt! # uint256 activeSupply: BigInt! # uint256 + + totalUbiClaimed: BigInt! # field to track total UBI claimed + ubiClaimedLastWeek: BigInt! + ubiClaimedLastDay: BigInt! # field to track UBI claimed in the last 24 + ubiClaimedLastHour: 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) + + totalMinted: BigInt! + mintedLastWeek: BigInt! + mintedLastDay: BigInt! + mintedLastHour: BigInt! + + totalBurned: BigInt! + burnedLastWeek: BigInt! + burnedLastDay: BigInt! + burnedLastHour: BigInt! } enum PositionStatus { diff --git a/subgraph/harb/src/harb.ts b/subgraph/harb/src/harb.ts index 351cadc..10bd68e 100644 --- a/subgraph/harb/src/harb.ts +++ b/subgraph/harb/src/harb.ts @@ -1,19 +1,198 @@ import { Approval as ApprovalEvent, EIP712DomainChanged as EIP712DomainChangedEvent, - Transfer as TransferEvent -} from "../generated/Harb/Harb" + Transfer as TransferEvent, + UbiClaimed as UbiClaimedEvent +} from "../generated/Harb/Harb"; +import { BigInt, Bytes, ethereum, Address, log } from "@graphprotocol/graph-ts"; +import { Stats } from "../generated/schema" -export function handleApproval(event: ApprovalEvent): void { +// Helper function to get or create Stats entity +function getOrCreateStats(): Stats { + let stats = Stats.load(Bytes.fromHexString("0x01") as Bytes); + if (stats == null) { + stats = new Stats(Bytes.fromHexString("0x01") as Bytes); + stats.outstandingSupply = BigInt.zero(); + stats.activeSupply = BigInt.zero(); + stats.totalUbiClaimed = BigInt.zero(); + stats.ubiClaimedLastWeek = BigInt.zero(); + stats.ubiClaimedLastDay = BigInt.zero(); + stats.ubiClaimedLastHour = BigInt.zero(); + + stats.totalMinted = BigInt.zero(); + stats.mintedLastWeek = BigInt.zero(); + stats.mintedLastDay = BigInt.zero(); + stats.mintedLastHour = BigInt.zero(); + + stats.totalBurned = BigInt.zero(); + stats.burnedLastWeek = BigInt.zero(); + stats.burnedLastDay = BigInt.zero(); + stats.burnedLastHour = BigInt.zero(); + + stats.ringBuffer = new Array(168 * 3).fill(BigInt.zero()); + stats.ringBufferPointer = 0; + stats.lastUpdatedHour = 0; + } + return stats; } -export function handleEIP712DomainChanged( - event: EIP712DomainChangedEvent -): void { - -} + export function handleTransfer(event: TransferEvent): void { - + let ZERO_ADDRESS = Address.fromString("0x0000000000000000000000000000000000000000"); + + // Update Stats entity + let stats = getOrCreateStats(); + + // Get a copy of the ring buffer + let ringBuffer = stats.ringBuffer; + + // Determine if it's a mint or burn event + if (event.params.from == ZERO_ADDRESS) { + // Mint event + stats.totalMinted = stats.totalMinted.plus(event.params.value); + + // Add the minted amount to the current hour's total in the ring buffer + let mintBufferIndex = (stats.ringBufferPointer * 3) + 1; // Minted tokens are at index 1 + ringBuffer[mintBufferIndex] = ringBuffer[mintBufferIndex].plus(event.params.value); + + // Calculate the elapsed time in the current hour + let currentTimestamp = event.block.timestamp.toI32(); + let startOfHour = (currentTimestamp / 3600) * 3600; + let elapsedSeconds = currentTimestamp - startOfHour; + + // Project the current hour's total based on the average rate of minted tokens in the current hour + let projectedTotal = ringBuffer[mintBufferIndex].times(BigInt.fromI32(3600)).div(BigInt.fromI32(elapsedSeconds)); + + // Calculate the medium between the previous hour and the projection + let previousHourTotal = ringBuffer[((stats.ringBufferPointer - 1 + 168) % 168) * 3 + 1]; + stats.mintedLastHour = previousHourTotal.plus(projectedTotal).div(BigInt.fromI32(2)); + + log.info("transfer handler: Recalculated totals. projected total: {}. previous hour total: {}. medium: {}.", [ + projectedTotal.toString(), + previousHourTotal.toString(), + stats.burnedLastHour.toString(), + ]); + + } else if (event.params.to == ZERO_ADDRESS) { + // Burn event + stats.totalBurned = stats.totalBurned.plus(event.params.value); + + // Add the burned amount to the current hour's total in the ring buffer + let burnBufferIndex = (stats.ringBufferPointer * 3) + 2; // Burned tokens are at index 2 + ringBuffer[burnBufferIndex] = ringBuffer[burnBufferIndex].plus(event.params.value); + + // Calculate the elapsed time in the current hour + let currentTimestamp = event.block.timestamp.toI32(); + let startOfHour = (currentTimestamp / 3600) * 3600; + let elapsedSeconds = currentTimestamp - startOfHour; + + // Project the current hour's total based on the average rate of burned tokens in the current hour + let projectedTotal = ringBuffer[burnBufferIndex].times(BigInt.fromI32(3600)).div(BigInt.fromI32(elapsedSeconds)); + + // Calculate the medium between the previous hour and the projection + let previousHourTotal = ringBuffer[((stats.ringBufferPointer - 1 + 168) % 168) * 3 + 2]; + stats.burnedLastHour = previousHourTotal.plus(projectedTotal).div(BigInt.fromI32(2)); + } + + // Update the ring buffer in the stats entity + stats.ringBuffer = ringBuffer; + + // Save the updated Stats entity + stats.save(); +} + +export function handleUbiClaimed(event: UbiClaimedEvent): void { + + let stats = getOrCreateStats(); + + // Get a copy of the ring buffer + let ringBuffer = stats.ringBuffer; + + // Update total UBI claimed + stats.totalUbiClaimed = stats.totalUbiClaimed.plus(event.params.ubiAmount); + + // Add the UBI amount to the current hour's total in the ring buffer + let ubiBufferIndex = (stats.ringBufferPointer * 3) + 0; // UBI is at index 0 + ringBuffer[ubiBufferIndex] = ringBuffer[ubiBufferIndex].plus(event.params.ubiAmount); + + // Calculate the elapsed time in the current hour + let currentTimestamp = event.block.timestamp.toI32(); + let startOfHour = (currentTimestamp / 3600) * 3600; + let elapsedSeconds = currentTimestamp - startOfHour; + + // Project the current hour's total based on the average rate of UBI claims in the current hour + let projectedTotal = ringBuffer[ubiBufferIndex].times(BigInt.fromI32(3600)).div(BigInt.fromI32(elapsedSeconds)); + + // Calculate the medium between the previous hour and the projection + let previousHourTotal = ringBuffer[((stats.ringBufferPointer + 167) % 168) * 3 + 0]; + stats.ubiClaimedLastHour = previousHourTotal.plus(projectedTotal).div(BigInt.fromI32(2)); + + // Update the ring buffer in the stats entity + stats.ringBuffer = ringBuffer; + + // Save the updated Stats entity + stats.save(); +} + +// Block handler to aggregate stats +export function handleBlock(block: ethereum.Block): void { + // Update Stats entity + let stats = getOrCreateStats(); + + // Get a copy of the ring buffer + let ringBuffer = stats.ringBuffer; + + // Calculate the current hour + let currentHour = block.timestamp.toI32() / 3600; + + // Check if we've moved to a new hour + if (currentHour > stats.lastUpdatedHour) { + // Move the ring buffer pointer forward + stats.ringBufferPointer = (stats.ringBufferPointer + 1) % 168; + + // Reset the new current hour in the ring buffer + let baseIndex = stats.ringBufferPointer * 3; + ringBuffer[baseIndex] = BigInt.zero(); // UBI claimed + ringBuffer[baseIndex + 1] = BigInt.zero(); // Minted tokens + ringBuffer[baseIndex + 2] = BigInt.zero(); // Burned tokens + + // Update the last updated hour + stats.lastUpdatedHour = currentHour; + + // Recalculate the sum of the last 7 days and 24 hours + let totalLast7Days = BigInt.zero(); + let totalMintedLast7Days = BigInt.zero(); + let totalBurnedLast7Days = BigInt.zero(); + let totalLast24Hours = BigInt.zero(); + let totalMintedLast24Hours = BigInt.zero(); + let totalBurnedLast24Hours = BigInt.zero(); + + for (let i = 0; i < 168; i++) { + let index = ((stats.ringBufferPointer - i + 168) % 168) * 3; + totalLast7Days = totalLast7Days.plus(ringBuffer[index]); + totalMintedLast7Days = totalMintedLast7Days.plus(ringBuffer[index + 1]); + totalBurnedLast7Days = totalBurnedLast7Days.plus(ringBuffer[index + 2]); + + if (i < 24) { + totalLast24Hours = totalLast24Hours.plus(ringBuffer[index]); + totalMintedLast24Hours = totalMintedLast24Hours.plus(ringBuffer[index + 1]); + totalBurnedLast24Hours = totalBurnedLast24Hours.plus(ringBuffer[index + 2]); + } + } + + stats.ubiClaimedLastWeek = totalLast7Days; + stats.mintedLastWeek = totalMintedLast7Days; + stats.burnedLastWeek = totalBurnedLast7Days; + stats.ubiClaimedLastDay = totalLast24Hours; + stats.mintedLastDay = totalMintedLast24Hours; + stats.burnedLastDay = totalBurnedLast24Hours; + + // Update the ring buffer in the stats entity + stats.ringBuffer = ringBuffer; + + // Save the updated Stats entity + stats.save(); + } } diff --git a/subgraph/harb/subgraph.yaml b/subgraph/harb/subgraph.yaml index f7d0f9a..8b38dd6 100644 --- a/subgraph/harb/subgraph.yaml +++ b/subgraph/harb/subgraph.yaml @@ -8,33 +8,34 @@ dataSources: name: Harb network: sepolia source: - address: "0xf3dc6b3fdda9d1cfe16b93e6a6482b63869f7d35" + address: "0x7517db0f2b24223f2f0e3567149ca180e204da8a" abi: Harb - startBlock: 5708443 + startBlock: 5909060 mapping: kind: ethereum/events apiVersion: 0.0.7 language: wasm/assemblyscript entities: - Stats + - UbiClaim abis: - name: Harb file: ./abis/Harb.json eventHandlers: - - event: Approval(indexed address,indexed address,uint256) - handler: handleApproval - - event: EIP712DomainChanged() - handler: handleEIP712DomainChanged - 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: "0x035ad87485cbd3794fe891caf4219bad7dc929ed" + address: "0x00b4d656b8182d0c2f4841b7a6f1429b94f73a66" abi: Stake - startBlock: 5708444 + startBlock: 5909060 mapping: kind: ethereum/events apiVersion: 0.0.7