Skip to content

Commit

Permalink
Add ignored contracts to account for classic boosts
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jun 21, 2024
1 parent d520c22 commit 7146b3a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 5 deletions.
9 changes: 9 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ type Token @entity(immutable: true) {
decimals: BigInt!
}

"""
A contract where transfers from/to are ignored
This is used to account for contracts that are not ERC20 compliant
but allow staking one token like beefy boosts
"""
type IgnoredContract @entity {
id: Bytes!
}

# account details
type Account @entity {
#account address
Expand Down
6 changes: 3 additions & 3 deletions src/classic/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BoostDeployed as BoostCreated } from "../../generated/ClassicBoostFacto
import { ClassicVault as ClassicVaultContract } from "../../generated/ClassicVaultFactory/ClassicVault"
import { BeefyERC20Product as BeefyERC20ProductTemplate, ClassicVault as ClassicVaultTemplate } from "../../generated/templates"
import { fetchAndSaveTokenData } from "../common/utils/token"
import { getIgnoredContract } from "../common/entity/ignored"

export function handleClassicVaultOrStrategyCreated(event: VaultOrStrategyCreated): void {
const address = event.params.proxy
Expand All @@ -24,10 +25,9 @@ export function handleClassicVaultOrStrategyCreated(event: VaultOrStrategyCreate
}

export function handleClassicBoostCreated(event: BoostCreated): void {
// TODO: this is wrong
const address = event.params.boost
fetchAndSaveTokenData(address)
BeefyERC20ProductTemplate.create(address)
const ignored = getIgnoredContract(address)
ignored.save()
}

export function handleClassicVaultInitialized(event: VaultInitialized): void {
Expand Down
15 changes: 15 additions & 0 deletions src/common/entity/ignored.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Bytes } from "@graphprotocol/graph-ts"
import { IgnoredContract } from "../../../generated/schema"

export function shouldIgnoreContract(contractAddress: Bytes): boolean {
return IgnoredContract.load(contractAddress) !== null
}

export function getIgnoredContract(contractAddress: Bytes): IgnoredContract {
let ignoredcontract = IgnoredContract.load(contractAddress)
if (!ignoredcontract) {
ignoredcontract = new IgnoredContract(contractAddress)
}

return ignoredcontract
}
8 changes: 7 additions & 1 deletion src/common/interaction.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
import { BigInt, Bytes, log } from "@graphprotocol/graph-ts"
import { Transfer as TransferEvent } from "../../generated/templates/BeefyERC20Product/IERC20"
import { BURN_ADDRESS, SHARE_TOKEN_MINT_ADDRESS } from "../config"
import { getAccount } from "./entity/account"
import { getTokenBalance } from "./entity/balance"
import { getToken } from "./entity/token"
import { shouldIgnoreContract } from "./entity/ignored"

export function handleProductTransfer(event: TransferEvent): void {
if (shouldIgnoreContract(event.params.from) || shouldIgnoreContract(event.params.to)) {
log.debug("Ignoring transfer from/to ignored contract: {}", [event.transaction.hash.toHexString()])
return
}

if (event.params.from.notEqual(SHARE_TOKEN_MINT_ADDRESS) && event.params.from.notEqual(BURN_ADDRESS)) {
updateAccountBalance(event.address, event.params.from, event.params.value.neg())
}
Expand Down
51 changes: 51 additions & 0 deletions tests/utils/time.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { assert, test, describe } from "matchstick-as/assembly/index"
import { BigInt } from "@graphprotocol/graph-ts"
import { DAY, HOUR, MONTH, QUARTER, WEEK, YEAR, getIntervalFromTimestamp, getPreviousIntervalFromTimestamp } from "../../src/common/utils/time"

describe("time.getIntervalFromTimestamp", () => {
test("Support all the different periods", () => {
const timestamp = BigInt.fromString("1712744972")

// simple periods
let res = getIntervalFromTimestamp(timestamp, HOUR)
assert.assertTrue(res.equals(BigInt.fromString("1712743200")))

res = getIntervalFromTimestamp(timestamp, DAY)
assert.assertTrue(res.equals(BigInt.fromString("1712707200")))

res = getIntervalFromTimestamp(timestamp, WEEK)
assert.assertTrue(res.equals(BigInt.fromString("1712448000")))

res = getIntervalFromTimestamp(timestamp, MONTH)
assert.assertTrue(res.equals(BigInt.fromString("1711929600")))

res = getIntervalFromTimestamp(timestamp, QUARTER)
assert.assertTrue(res.equals(BigInt.fromString("1711929600")))

res = getIntervalFromTimestamp(timestamp, YEAR)
assert.assertTrue(res.equals(BigInt.fromString("1704067200")))
})

test("can query the previous interval as well", () => {
const timestamp = BigInt.fromString("1712744972")

// simple periods
let res = getPreviousIntervalFromTimestamp(timestamp, HOUR)
assert.assertTrue(res.equals(BigInt.fromString("1712739600")))

res = getPreviousIntervalFromTimestamp(timestamp, DAY)
assert.assertTrue(res.equals(BigInt.fromString("1712620800")))

res = getPreviousIntervalFromTimestamp(timestamp, WEEK)
assert.assertTrue(res.equals(BigInt.fromString("1711843200")))

res = getPreviousIntervalFromTimestamp(timestamp, MONTH)
assert.assertTrue(res.equals(BigInt.fromString("1709251200")))

res = getPreviousIntervalFromTimestamp(timestamp, QUARTER)
assert.assertTrue(res.equals(BigInt.fromString("1704067200")))

res = getPreviousIntervalFromTimestamp(timestamp, YEAR)
assert.assertTrue(res.equals(BigInt.fromString("1672531200")))
})
})
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "@graphprotocol/graph-ts/tsconfig",
"compilerOptions": {
"types": ["@graphprotocol/graph-ts"],
"types": ["@graphprotocol/graph-ts", "assemblyscript"],
"strict": true,
"strictNullChecks": true
}
Expand Down

0 comments on commit 7146b3a

Please sign in to comment.