Skip to content

Commit 41fa9cf

Browse files
committed
create ERC20 balances for otokens using result.history instead of the owners historical
1 parent d6db002 commit 41fa9cf

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

src/templates/otoken/otoken.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@ export const createOTokenProcessor = (params: {
201201
}
202202

203203
let owners: Map<string, OTokenAddress> | undefined = undefined
204-
let ownersHistorical: OTokenAddress[] = []
205-
206204
let idMap: Map<string, number>
207205
const getUniqueId = (partialId: string) => {
208206
const nextId = (idMap.get(partialId) ?? 0) + 1
@@ -220,7 +218,6 @@ export const createOTokenProcessor = (params: {
220218
start = Date.now()
221219
}
222220
idMap = new Map<string, number>()
223-
ownersHistorical = []
224221

225222
const transferFilter = logFilter({
226223
address: [params.otokenAddress],
@@ -351,7 +348,6 @@ export const createOTokenProcessor = (params: {
351348
if (!entity) {
352349
entity = await createAddress(ctx, params.otokenAddress, address, block)
353350
owners!.set(entity.address, entity)
354-
ownersHistorical.push(entity)
355351
}
356352
entity.blockNumber = block.header.height
357353
entity.lastUpdated = new Date(block.header.timestamp)
@@ -606,7 +602,6 @@ export const createOTokenProcessor = (params: {
606602
if (!owner) {
607603
owner = await createAddress(ctx, params.otokenAddress, address, block)
608604
owners!.set(address, owner)
609-
ownersHistorical.push(owner)
610605
}
611606
const rebaseOption = new OTokenRebaseOption({
612607
id: getUniqueId(`${ctx.chain.id}-${params.otokenAddress}-${hash}-${owner.address}`),
@@ -651,7 +646,6 @@ export const createOTokenProcessor = (params: {
651646
if (!sourceOwner) {
652647
sourceOwner = await createAddress(ctx, params.otokenAddress, sourceAddress, block)
653648
owners!.set(sourceAddress, sourceOwner)
654-
ownersHistorical.push(sourceOwner)
655649
}
656650
sourceOwner.rebasingOption = RebasingOption.YieldDelegationSource
657651
sourceOwner.delegatedTo = targetAddress
@@ -673,7 +667,6 @@ export const createOTokenProcessor = (params: {
673667
if (!targetOwner) {
674668
targetOwner = await createAddress(ctx, params.otokenAddress, targetAddress, block)
675669
owners!.set(targetAddress, targetOwner)
676-
ownersHistorical.push(targetOwner)
677670
}
678671
targetOwner.rebasingOption = RebasingOption.YieldDelegationTarget
679672
targetOwner.delegatedTo = null
@@ -704,7 +697,6 @@ export const createOTokenProcessor = (params: {
704697
if (!sourceOwner) {
705698
sourceOwner = await createAddress(ctx, params.otokenAddress, sourceAddress, block)
706699
owners!.set(sourceAddress, sourceOwner)
707-
ownersHistorical.push(sourceOwner)
708700
}
709701
sourceOwner.rebasingOption = RebasingOption.OptOut
710702
sourceOwner.delegatedTo = null
@@ -726,7 +718,6 @@ export const createOTokenProcessor = (params: {
726718
if (!targetOwner) {
727719
targetOwner = await createAddress(ctx, params.otokenAddress, targetAddress, block)
728720
owners!.set(targetAddress, targetOwner)
729-
ownersHistorical.push(targetOwner)
730721
}
731722
targetOwner.rebasingOption = RebasingOption.OptIn
732723
targetOwner.delegatedTo = null
@@ -1158,17 +1149,18 @@ export const createOTokenProcessor = (params: {
11581149
result.erc20.holders.set(erc20Holder.id, erc20Holder)
11591150
}
11601151
}
1161-
for (const owner of ownersHistorical) {
1152+
for (const history of result.history) {
1153+
const id = `${ctx.chain.id}-${history.blockNumber}-${history.otoken}-${history.address}`
11621154
result.erc20.balances.set(
1163-
owner.id,
1155+
id,
11641156
new ERC20Balance({
1165-
id: `${ctx.chain.id}-${owner.blockNumber}-${owner.otoken}-${owner.address}`,
1157+
id,
11661158
chainId: ctx.chain.id,
1167-
address: owner.otoken,
1168-
account: owner.address,
1169-
timestamp: owner.lastUpdated,
1170-
blockNumber: owner.blockNumber,
1171-
balance: owner.balance,
1159+
address: history.otoken,
1160+
account: history.address.address,
1161+
timestamp: history.timestamp,
1162+
blockNumber: history.blockNumber,
1163+
balance: history.balance,
11721164
}),
11731165
)
11741166
}

0 commit comments

Comments
 (0)