Skip to content

Commit

Permalink
Allow identification of app allocations & manual deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
ifavo committed Sep 17, 2024
1 parent 13cfe36 commit 272f526
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
52 changes: 52 additions & 0 deletions generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,32 @@ export class App extends Entity {
this.set("votingEligibility", Value.fromBoolean(value));
}

get poolAllocations(): BigDecimal {
let value = this.get("poolAllocations");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBigDecimal();
}
}

set poolAllocations(value: BigDecimal) {
this.set("poolAllocations", Value.fromBigDecimal(value));
}

get poolAllocationsExact(): BigInt {
let value = this.get("poolAllocationsExact");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBigInt();
}
}

set poolAllocationsExact(value: BigInt) {
this.set("poolAllocationsExact", Value.fromBigInt(value));
}

get poolBalance(): BigDecimal {
let value = this.get("poolBalance");
if (!value || value.kind == ValueKind.NULL) {
Expand Down Expand Up @@ -864,6 +890,32 @@ export class AppRoundSummary extends Entity {
this.set("poolBalanceExact", Value.fromBigInt(value));
}

get poolAllocations(): BigDecimal {
let value = this.get("poolAllocations");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBigDecimal();
}
}

set poolAllocations(value: BigDecimal) {
this.set("poolAllocations", Value.fromBigDecimal(value));
}

get poolAllocationsExact(): BigInt {
let value = this.get("poolAllocationsExact");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBigInt();
}
}

set poolAllocationsExact(value: BigInt) {
this.set("poolAllocationsExact", Value.fromBigInt(value));
}

get poolDeposits(): BigDecimal {
let value = this.get("poolDeposits");
if (!value || value.kind == ValueKind.NULL) {
Expand Down
18 changes: 16 additions & 2 deletions src/RewardsPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export function handleNewDeposit(event: NewDepositEvent): void {

app.poolBalanceExact = app.poolBalanceExact.plus(ev.amountExact)
app.poolDepositsExact = app.poolDepositsExact.plus(ev.amountExact)
// deposit coming from X Allocation Pool equals an allocation for the app
if (transfer.from.equals(Address.fromString("0x4191776f05f4be4848d3f4d587345078b439c7d3"))) {
app.poolAllocationsExact = app.poolAllocationsExact.plus(ev.amountExact)
app.poolAllocations = decimals.toDecimals(app.poolAllocationsExact, 18)
}
app.poolBalance = decimals.toDecimals(app.poolBalanceExact, 18)
app.poolDeposits = decimals.toDecimals(app.poolDepositsExact, 18)
app.save()
Expand Down Expand Up @@ -442,6 +447,8 @@ function updateAppRoundSummary(transfer: RewardPoolTransfer): void {
appRoundSummary.app = app.id
appRoundSummary.round = round.id

appRoundSummary.poolAllocations = constants.BIGDECIMAL_ZERO
appRoundSummary.poolAllocationsExact = constants.BIGINT_ZERO
appRoundSummary.poolBalance = app.poolBalance
appRoundSummary.poolBalanceExact = app.poolBalanceExact
appRoundSummary.poolDeposits = constants.BIGDECIMAL_ZERO
Expand All @@ -453,8 +460,15 @@ function updateAppRoundSummary(transfer: RewardPoolTransfer): void {
}

if (transfer.deposit != null) {
appRoundSummary.poolDepositsExact = appRoundSummary.poolDepositsExact.plus(transfer.amountExact)
appRoundSummary.poolDeposits = decimals.toDecimals(appRoundSummary.poolDepositsExact, 18)
// deposit coming from X Allocation Pool equals an allocation for the app
if (transfer.from.equals(Address.fromString("0x4191776f05f4be4848d3f4d587345078b439c7d3"))) {
appRoundSummary.poolAllocationsExact = appRoundSummary.poolAllocationsExact.plus(transfer.amountExact)
appRoundSummary.poolAllocations = decimals.toDecimals(appRoundSummary.poolAllocationsExact, 18)
}
else {
appRoundSummary.poolDepositsExact = appRoundSummary.poolDepositsExact.plus(transfer.amountExact)
appRoundSummary.poolDeposits = decimals.toDecimals(appRoundSummary.poolDepositsExact, 18)
}
}

if (transfer.withdraw != null) {
Expand Down
2 changes: 2 additions & 0 deletions src/XApps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ export function fetchApp(id: Bytes): App {
let app = App.load(id)
if (app == null) {
app = new App(id)
app.poolAllocations = constants.BIGDECIMAL_ZERO
app.poolBalance = constants.BIGDECIMAL_ZERO
app.poolDistributions = constants.BIGDECIMAL_ZERO
app.poolWithdrawals = constants.BIGDECIMAL_ZERO
app.poolDeposits = constants.BIGDECIMAL_ZERO

app.poolAllocationsExact = constants.BIGINT_ZERO
app.poolBalanceExact = constants.BIGINT_ZERO
app.poolDistributionsExact = constants.BIGINT_ZERO
app.poolWithdrawalsExact = constants.BIGINT_ZERO
Expand Down
4 changes: 4 additions & 0 deletions subgraph.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type App @entity {
metadata: AppMetadata
metadataURI: String
votingEligibility: Boolean
poolAllocations: BigDecimal!
poolAllocationsExact: BigInt!
poolBalance: BigDecimal!
poolBalanceExact: BigInt!
poolDeposits: BigDecimal!
Expand Down Expand Up @@ -72,6 +74,8 @@ type AppRoundSummary @entity {
round: Round!
poolBalance: BigDecimal!
poolBalanceExact: BigInt!
poolAllocations: BigDecimal!
poolAllocationsExact: BigInt!
poolDeposits: BigDecimal!
poolDepositsExact: BigInt!
poolWithdrawals: BigDecimal!
Expand Down

0 comments on commit 272f526

Please sign in to comment.