deploy.js script

This commit is contained in:
EmberSpirit007 2025-01-23 19:32:49 +01:00
parent 5824bf0091
commit 9d84ef3951
27 changed files with 162 additions and 6654 deletions

View file

@ -30,17 +30,7 @@ function getOrCreateStats(): Stats {
stats.burnedLastDay = BigInt.zero();
stats.burnNextHourProjected = BigInt.zero();
// Tax paid
stats.totalTaxPaid = BigInt.zero();
stats.taxPaidLastWeek = BigInt.zero();
stats.taxPaidLastDay = BigInt.zero();
stats.taxNextHourProjected = BigInt.zero();
// UBI claimed
stats.totalUbiClaimed = BigInt.zero();
stats.ubiClaimedLastWeek = BigInt.zero();
stats.ubiClaimedLastDay = BigInt.zero();
stats.ubiNextHourProjected = BigInt.zero();
stats.ringBuffer = new Array<BigInt>(168 * 4).fill(BigInt.zero());
stats.ringBufferPointer = 0;
@ -61,8 +51,6 @@ export function handleTransfer(event: TransferEvent): void {
const harberg = Harb.bind(event.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
@ -89,8 +77,6 @@ export function handleTransfer(event: TransferEvent): void {
stats.harbTotalSupply = stats.harbTotalSupply.minus(event.params.value);
} else if (event.params.to == TAX_POOL_ADDR) {
// Tax paid event
stats.totalTaxPaid = stats.totalTaxPaid.plus(event.params.value);
// Add the burned amount to the current hour's total in the ring buffer
let taxBufferIndex = (stats.ringBufferPointer * 4) + 3; // tax paid is at index 3
@ -134,41 +120,29 @@ export function handleBlock(block: ethereum.Block): void {
let mintedLastWeek = BigInt.zero();
let burnedLastWeek = BigInt.zero();
let taxPaidLastWeek = BigInt.zero();
let ubiClaimedLastWeek = BigInt.zero();
let mintedLastDay = BigInt.zero();
let burnedLastDay = BigInt.zero();
let taxPaidLastDay = BigInt.zero();
let ubiClaimedLastDay = BigInt.zero();
for (let i = 0; i < 168; i++) {
let index = ((stats.ringBufferPointer - i + 168) % 168) * 4;
ubiClaimedLastWeek = ubiClaimedLastWeek.plus(ringBuffer[index]);
mintedLastWeek = mintedLastWeek.plus(ringBuffer[index + 1]);
burnedLastWeek = burnedLastWeek.plus(ringBuffer[index + 2]);
taxPaidLastWeek = taxPaidLastWeek.plus(ringBuffer[index + 3]);
if (i < 24) {
ubiClaimedLastDay = ubiClaimedLastDay.plus(ringBuffer[index]);
mintedLastDay = mintedLastDay.plus(ringBuffer[index + 1]);
burnedLastDay = burnedLastDay.plus(ringBuffer[index + 2]);
taxPaidLastDay = taxPaidLastDay.plus(ringBuffer[index + 3]);
}
}
stats.mintedLastWeek = mintedLastWeek;
stats.burnedLastWeek = burnedLastWeek;
stats.taxPaidLastWeek = taxPaidLastWeek;
stats.ubiClaimedLastWeek = ubiClaimedLastWeek;
stats.mintedLastDay = mintedLastDay;
stats.burnedLastDay = burnedLastDay;
stats.taxPaidLastDay = taxPaidLastDay;
stats.ubiClaimedLastDay = ubiClaimedLastDay;
// Update the ring buffer in the stats entity
stats.ringBuffer = ringBuffer;
@ -198,14 +172,10 @@ export function handleBlock(block: ethereum.Block): void {
let medium = previousHourTotal.plus(projectedTotal).div(BigInt.fromI32(2));
if (i == 0) {
stats.ubiNextHourProjected = (medium > BigInt.zero()) ? medium : stats.ubiClaimedLastWeek.div(BigInt.fromI32(7));
} else if (i == 1) {
if (i == 1) {
stats.mintNextHourProjected = (medium > BigInt.zero()) ? medium : stats.mintedLastWeek.div(BigInt.fromI32(7));
} else if (i == 2) {
stats.burnNextHourProjected = (medium > BigInt.zero()) ? medium : stats.burnedLastWeek.div(BigInt.fromI32(7));
} else if (i == 3) {
stats.taxNextHourProjected = (medium > BigInt.zero()) ? medium : stats.taxPaidLastWeek.div(BigInt.fromI32(7));
}
}

View file

@ -22,7 +22,7 @@ export function handlePositionCreated(event: PositionCreatedEvent): void {
position.creationTime = event.block.timestamp.toI32();
position.lastTaxTime = event.block.timestamp.toI32();
position.taxRate = BigDecimal.fromString(taxRates[event.params.taxRate.toI32()]);
position.harbDeposit = event.params.harbergDeposit;
position.harbDeposit = event.params.harbDeposit;
position.status = "Active";
position.snatched = 0;
position.payout = BigInt.fromString("0");
@ -44,7 +44,7 @@ export function handlePositionRemoved(event: PositionRemovedEvent): void {
position.status = "Closed";
let harb = Harb.bind(getSubgraphConfig().harbergAddress);
position.totalSupplyEnd = harb.totalSupply();
position.payout = position.payout.plus(event.params.harbergPayout);
position.payout = position.payout.plus(event.params.harbPayout);
position.save();
}
let stake = Stake.bind(event.address);
@ -59,10 +59,10 @@ 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.harbergPayout);
position.harbDeposit = position.harbDeposit.minus(event.params.harbPayout);
position.snatched = position.snatched++;
position.payout = position.payout.plus(event.params.harbergPayout);
position.payout = position.payout.plus(event.params.harbPayout);
position.save();
}
}