Skip to content

Commit f809fb1

Browse files
committed
feat: enhance OTokenActivity schema and processor to track portfolio events
1 parent 8968c12 commit f809fb1

7 files changed

Lines changed: 65 additions & 6 deletions

File tree

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,8 @@ type OTokenActivity @entity {
11761176
id: ID!
11771177
chainId: Int! @index
11781178
otoken: String! @index
1179+
account: String @index
1180+
counterparty: String @index
11791181
timestamp: DateTime! @index
11801182
blockNumber: Int! @index
11811183
txHash: String! @index

src/main-ousd.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import 'tsconfig-paths/register'
33

44
import { defineSquidProcessor } from '@originprotocol/squid-utils'
55
import * as exchangeRatesPostProcessor from '@shared/post-processors/exchange-rates'
6+
import { createOTokenActivityProcessor } from '@templates/otoken/activity-processor/activity-processor'
67
import { createMorphoVaultApyProcessor } from '@templates/morpho/processor'
78
import { processStatus } from '@templates/processor-status'
89
import { createOTokenWithdrawalsProcessor } from '@templates/withdrawals'
9-
import { addresses } from '@utils/addresses'
10+
import { WOUSD_ADDRESS, addresses } from '@utils/addresses'
1011
import { DEFAULT_FIELDS } from '@utils/batch-proccesor-fields'
1112
import { initProcessorFromDump } from '@utils/dumps'
1213

@@ -19,6 +20,13 @@ export const processor = defineSquidProcessor({
1920
stateSchema: 'ousd-processor',
2021
processors: [
2122
ousdProcessor,
23+
createOTokenActivityProcessor({
24+
from: 11590995,
25+
otokenAddress: addresses.ousd.address,
26+
wotokenAddress: WOUSD_ADDRESS,
27+
vaultAddress: addresses.ousd.vault,
28+
cowSwap: false,
29+
}),
2230
ousdStrategiesProcessor,
2331
createOTokenWithdrawalsProcessor({
2432
name: 'OUSD',

src/model/generated/oTokenActivity.model.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ export class OTokenActivity {
1818
@StringColumn_({nullable: false})
1919
otoken!: string
2020

21+
@Index_()
22+
@StringColumn_({nullable: true})
23+
account!: string | undefined | null
24+
25+
@Index_()
26+
@StringColumn_({nullable: true})
27+
counterparty!: string | undefined | null
28+
2129
@Index_()
2230
@DateTimeColumn_({nullable: false})
2331
timestamp!: Date

src/templates/otoken/activity-processor/activity-processor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ export const createOTokenActivityProcessor = (params: {
8585
// Mints & Redeems
8686
vaultActivityProcessor({ otokenAddress: params.otokenAddress, vaultAddress: params.vaultAddress }),
8787

88-
// Transfers & Swaps
88+
// Transfers
8989
transferActivityProcessor({ otokenAddress: params.otokenAddress }),
90-
]).filter((p) => p.name.includes('Approval'))
90+
])
9191

9292
const from = params.from
9393
const setup = (processor: EvmBatchProcessor) => {

src/templates/otoken/activity-processor/utils.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ export const createActivity = <T extends Activity>(
2626
status?: T['status']
2727
} & Omit<T, 'id' | 'chainId' | 'blockNumber' | 'timestamp' | 'status' | 'txHash'>,
2828
) => {
29+
const { account, counterparty } = extractParticipants(partial)
30+
2931
const activity = new OTokenActivity({
3032
chainId: ctx.chain.id,
3133
blockNumber: block.header.height,
3234
timestamp: new Date(block.header.timestamp),
3335
txHash: log.transactionHash,
3436
type: OTokenActivityType[partial.type],
3537
otoken: otokenAddress,
38+
account,
39+
counterparty,
3640
data: {
3741
status: 'success',
3842
...partial,
@@ -47,3 +51,34 @@ export const createActivity = <T extends Activity>(
4751

4852
return activity
4953
}
54+
55+
const extractParticipants = (partial: Record<string, unknown>) => {
56+
const account = firstAddress([
57+
partial.account,
58+
partial.sender,
59+
partial.from,
60+
partial.owner,
61+
partial.transactor,
62+
partial.delegator,
63+
partial.voter,
64+
])
65+
66+
const counterparty = firstAddress([
67+
partial.to,
68+
partial.receiver,
69+
partial.spender,
70+
partial.delegateTo,
71+
])
72+
73+
return { account, counterparty }
74+
}
75+
76+
const firstAddress = (values: unknown[]) => {
77+
for (const value of values) {
78+
if (typeof value === 'string' && value.startsWith('0x') && value.length === 42) {
79+
return value.toLowerCase()
80+
}
81+
}
82+
83+
return null
84+
}

src/templates/otoken/otoken.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ type OTokenActivity @entity {
135135
id: ID!
136136
chainId: Int! @index
137137
otoken: String! @index
138+
account: String @index
139+
counterparty: String @index
138140
timestamp: DateTime! @index
139141
blockNumber: Int! @index
140142
txHash: String! @index

0 commit comments

Comments
 (0)