improve subgraph structure
This commit is contained in:
parent
9bd5afd40e
commit
5a10f23e15
5 changed files with 34 additions and 37 deletions
|
|
@ -132,7 +132,7 @@ open features:
|
|||
- deployment on L2
|
||||
|
||||
todos:
|
||||
- write unit test for capital exit function
|
||||
- recenter bot
|
||||
- put ownerOnly restriction on recenter, remove it later. gives more control to the team initally, but keeps it decentralized
|
||||
- liquidation bot
|
||||
- write unit test for capital exit function
|
||||
- put ownerOnly restriction on recenter, remove it later. gives more control to the team initally, but keeps it decentralized
|
||||
|
||||
|
|
|
|||
|
|
@ -59,9 +59,6 @@ contract Harberg is ERC20, ERC20Permit {
|
|||
error ZeroAddressInSetter();
|
||||
error AddressAlreadySet();
|
||||
|
||||
// Event emitted when UBI is claimed
|
||||
event UbiClaimed(address indexed owner, uint256 ubiAmount);
|
||||
|
||||
// Modifier to restrict access to the liquidity manager
|
||||
modifier onlyLiquidityManager() {
|
||||
require(msg.sender == address(liquidityManager), "Harberg/only-lm");
|
||||
|
|
@ -323,7 +320,7 @@ contract Harberg is ERC20, ERC20Permit {
|
|||
/**
|
||||
* @notice Claims the calculated UBI amount for the caller.
|
||||
* @dev Transfers the due UBI from the tax pool to the account, updating the UBI title.
|
||||
* Emits UbiClaimed event on successful transfer.
|
||||
* Emits Transfer event on successful transfer.
|
||||
* @param _account The account claiming the UBI.
|
||||
* @return ubiAmountDue The amount of UBI claimed.
|
||||
*/
|
||||
|
|
@ -337,7 +334,7 @@ contract Harberg is ERC20, ERC20Permit {
|
|||
ubiTitles[_account].sumTaxCollected = sumTaxCollected;
|
||||
ubiTitles[_account].time = lastPeriodEndAt;
|
||||
twabController.transfer(TAX_POOL, _account, SafeCast.toUint96(ubiAmountDue));
|
||||
emit UbiClaimed(_account, ubiAmountDue);
|
||||
emit Transfer(TAX_POOL, _account, ubiAmountDue);
|
||||
} else {
|
||||
revert("No UBI to claim.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
"dependencies": {
|
||||
"dotenv": "^16.4.5",
|
||||
"ethers": "^6.13.2",
|
||||
"express": "^4.19.2"
|
||||
"express": "^5.0.0",
|
||||
"harb-lib": "^0.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@graphprotocol/client-cli": "^3.0.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import {
|
||||
Approval as ApprovalEvent,
|
||||
EIP712DomainChanged as EIP712DomainChangedEvent,
|
||||
Transfer as TransferEvent,
|
||||
UbiClaimed as UbiClaimedEvent
|
||||
Transfer as TransferEvent
|
||||
} from "../generated/Harb/Harb";
|
||||
import { BigInt, Bytes, ethereum, Address, log } from "@graphprotocol/graph-ts";
|
||||
import { Stats } from "../generated/schema"
|
||||
|
|
@ -47,28 +46,6 @@ function getOrCreateStats(): Stats {
|
|||
return stats;
|
||||
}
|
||||
|
||||
|
||||
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 * 4) + 0; // UBI is at index 0
|
||||
ringBuffer[ubiBufferIndex] = ringBuffer[ubiBufferIndex].plus(event.params.ubiAmount);
|
||||
|
||||
// Update the ring buffer in the stats entity
|
||||
stats.ringBuffer = ringBuffer;
|
||||
|
||||
// Save the updated Stats entity
|
||||
stats.save();
|
||||
}
|
||||
|
||||
export function handleTransfer(event: TransferEvent): void {
|
||||
let ZERO_ADDRESS = Address.fromString("0x0000000000000000000000000000000000000000");
|
||||
let TAX_POOL_ADDR = Address.fromString("0x0000000000000000000000000000000000000002");
|
||||
|
|
@ -78,8 +55,15 @@ export function handleTransfer(event: TransferEvent): void {
|
|||
// 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) {
|
||||
if (event.params.from == TAX_POOL_ADDR) {
|
||||
// Update total UBI claimed
|
||||
stats.totalUbiClaimed = stats.totalUbiClaimed.plus(event.params.value);
|
||||
|
||||
// Add the UBI amount to the current hour's total in the ring buffer
|
||||
let ubiBufferIndex = (stats.ringBufferPointer * 4) + 0; // UBI is at index 0
|
||||
ringBuffer[ubiBufferIndex] = ringBuffer[ubiBufferIndex].plus(event.params.value);
|
||||
|
||||
} else if (event.params.from == ZERO_ADDRESS) {
|
||||
// Mint event
|
||||
stats.totalMinted = stats.totalMinted.plus(event.params.value);
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import {
|
|||
PositionRemoved as PositionRemovedEvent,
|
||||
PositionTaxPaid as PositionTaxPaidEvent,
|
||||
PositionShrunk as PositionShrunkEvent,
|
||||
PositionRateHiked as PositionRateHikedEvent,
|
||||
} from "../generated/Stake/Stake";
|
||||
import { Harb } from "../generated/Harb/Harb";
|
||||
import { BigDecimal, BigInt, Bytes } from "@graphprotocol/graph-ts";
|
||||
|
|
@ -10,13 +11,15 @@ import { Position } from "../generated/schema";
|
|||
|
||||
let decimals: BigDecimal = BigDecimal.fromString("1000000000000000000");
|
||||
let totalSupply: BigDecimal = BigDecimal.fromString("10000000000000000000000000");
|
||||
let taxRates: Array<string> = ["0.01", "0.03", "0.05", "0.08", "0.12", "0.18", "0.24", "0.30", "0.40", "0.50", "0.60", "0.80", "1", "1.3", "1.8", "2.5", "3.2", "4.2", "5.4", "7", "9.2", "12", "16", "20", "26", "34", "44", "57", "75", "97"];
|
||||
|
||||
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.lastTaxTime = event.block.timestamp.toI32();
|
||||
position.taxRate = BigDecimal.fromString(taxRates[event.params.taxRate.toI32()]);
|
||||
position.harbDeposit = event.params.harbDeposit;
|
||||
position.status = "Active";
|
||||
position.snatched = 0;
|
||||
|
|
@ -54,7 +57,16 @@ 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.taxRate = BigDecimal.fromString(taxRates[event.params.taxRate.toI32()]);
|
||||
position.lastTaxTime = event.block.timestamp.toI32();
|
||||
position.save();
|
||||
}
|
||||
}
|
||||
|
||||
export function handlePositionRateHiked(event: PositionRateHikedEvent): void {
|
||||
let position = Position.load(Bytes.fromI32(event.params.positionId.toI32()));
|
||||
if (position != null) {
|
||||
position.taxRate = BigDecimal.fromString(taxRates[event.params.newTaxRate.toI32()]);
|
||||
position.save();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue