Skip to content

Commit 7146b3a

Browse files
committed
Add ignored contracts to account for classic boosts
1 parent d520c22 commit 7146b3a

File tree

6 files changed

+86
-5
lines changed

6 files changed

+86
-5
lines changed

schema.graphql

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ type Token @entity(immutable: true) {
1414
decimals: BigInt!
1515
}
1616

17+
"""
18+
A contract where transfers from/to are ignored
19+
This is used to account for contracts that are not ERC20 compliant
20+
but allow staking one token like beefy boosts
21+
"""
22+
type IgnoredContract @entity {
23+
id: Bytes!
24+
}
25+
1726
# account details
1827
type Account @entity {
1928
#account address

src/classic/lifecycle.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { BoostDeployed as BoostCreated } from "../../generated/ClassicBoostFacto
55
import { ClassicVault as ClassicVaultContract } from "../../generated/ClassicVaultFactory/ClassicVault"
66
import { BeefyERC20Product as BeefyERC20ProductTemplate, ClassicVault as ClassicVaultTemplate } from "../../generated/templates"
77
import { fetchAndSaveTokenData } from "../common/utils/token"
8+
import { getIgnoredContract } from "../common/entity/ignored"
89

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

2627
export function handleClassicBoostCreated(event: BoostCreated): void {
27-
// TODO: this is wrong
2828
const address = event.params.boost
29-
fetchAndSaveTokenData(address)
30-
BeefyERC20ProductTemplate.create(address)
29+
const ignored = getIgnoredContract(address)
30+
ignored.save()
3131
}
3232

3333
export function handleClassicVaultInitialized(event: VaultInitialized): void {

src/common/entity/ignored.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Bytes } from "@graphprotocol/graph-ts"
2+
import { IgnoredContract } from "../../../generated/schema"
3+
4+
export function shouldIgnoreContract(contractAddress: Bytes): boolean {
5+
return IgnoredContract.load(contractAddress) !== null
6+
}
7+
8+
export function getIgnoredContract(contractAddress: Bytes): IgnoredContract {
9+
let ignoredcontract = IgnoredContract.load(contractAddress)
10+
if (!ignoredcontract) {
11+
ignoredcontract = new IgnoredContract(contractAddress)
12+
}
13+
14+
return ignoredcontract
15+
}

src/common/interaction.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { BigInt, Bytes } from "@graphprotocol/graph-ts"
1+
import { BigInt, Bytes, log } from "@graphprotocol/graph-ts"
22
import { Transfer as TransferEvent } from "../../generated/templates/BeefyERC20Product/IERC20"
33
import { BURN_ADDRESS, SHARE_TOKEN_MINT_ADDRESS } from "../config"
44
import { getAccount } from "./entity/account"
55
import { getTokenBalance } from "./entity/balance"
66
import { getToken } from "./entity/token"
7+
import { shouldIgnoreContract } from "./entity/ignored"
78

89
export function handleProductTransfer(event: TransferEvent): void {
10+
if (shouldIgnoreContract(event.params.from) || shouldIgnoreContract(event.params.to)) {
11+
log.debug("Ignoring transfer from/to ignored contract: {}", [event.transaction.hash.toHexString()])
12+
return
13+
}
14+
915
if (event.params.from.notEqual(SHARE_TOKEN_MINT_ADDRESS) && event.params.from.notEqual(BURN_ADDRESS)) {
1016
updateAccountBalance(event.address, event.params.from, event.params.value.neg())
1117
}

tests/utils/time.test.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { assert, test, describe } from "matchstick-as/assembly/index"
2+
import { BigInt } from "@graphprotocol/graph-ts"
3+
import { DAY, HOUR, MONTH, QUARTER, WEEK, YEAR, getIntervalFromTimestamp, getPreviousIntervalFromTimestamp } from "../../src/common/utils/time"
4+
5+
describe("time.getIntervalFromTimestamp", () => {
6+
test("Support all the different periods", () => {
7+
const timestamp = BigInt.fromString("1712744972")
8+
9+
// simple periods
10+
let res = getIntervalFromTimestamp(timestamp, HOUR)
11+
assert.assertTrue(res.equals(BigInt.fromString("1712743200")))
12+
13+
res = getIntervalFromTimestamp(timestamp, DAY)
14+
assert.assertTrue(res.equals(BigInt.fromString("1712707200")))
15+
16+
res = getIntervalFromTimestamp(timestamp, WEEK)
17+
assert.assertTrue(res.equals(BigInt.fromString("1712448000")))
18+
19+
res = getIntervalFromTimestamp(timestamp, MONTH)
20+
assert.assertTrue(res.equals(BigInt.fromString("1711929600")))
21+
22+
res = getIntervalFromTimestamp(timestamp, QUARTER)
23+
assert.assertTrue(res.equals(BigInt.fromString("1711929600")))
24+
25+
res = getIntervalFromTimestamp(timestamp, YEAR)
26+
assert.assertTrue(res.equals(BigInt.fromString("1704067200")))
27+
})
28+
29+
test("can query the previous interval as well", () => {
30+
const timestamp = BigInt.fromString("1712744972")
31+
32+
// simple periods
33+
let res = getPreviousIntervalFromTimestamp(timestamp, HOUR)
34+
assert.assertTrue(res.equals(BigInt.fromString("1712739600")))
35+
36+
res = getPreviousIntervalFromTimestamp(timestamp, DAY)
37+
assert.assertTrue(res.equals(BigInt.fromString("1712620800")))
38+
39+
res = getPreviousIntervalFromTimestamp(timestamp, WEEK)
40+
assert.assertTrue(res.equals(BigInt.fromString("1711843200")))
41+
42+
res = getPreviousIntervalFromTimestamp(timestamp, MONTH)
43+
assert.assertTrue(res.equals(BigInt.fromString("1709251200")))
44+
45+
res = getPreviousIntervalFromTimestamp(timestamp, QUARTER)
46+
assert.assertTrue(res.equals(BigInt.fromString("1704067200")))
47+
48+
res = getPreviousIntervalFromTimestamp(timestamp, YEAR)
49+
assert.assertTrue(res.equals(BigInt.fromString("1672531200")))
50+
})
51+
})

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "@graphprotocol/graph-ts/tsconfig",
33
"compilerOptions": {
4-
"types": ["@graphprotocol/graph-ts"],
4+
"types": ["@graphprotocol/graph-ts", "assemblyscript"],
55
"strict": true,
66
"strictNullChecks": true
77
}

0 commit comments

Comments
 (0)