Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,8 @@ type OTokenActivity @entity {
id: ID!
chainId: Int! @index
otoken: String! @index
account: String @index
counterparty: String @index
timestamp: DateTime! @index
blockNumber: Int! @index
txHash: String! @index
Expand Down
10 changes: 9 additions & 1 deletion src/main-ousd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import 'tsconfig-paths/register'

import { defineSquidProcessor } from '@originprotocol/squid-utils'
import * as exchangeRatesPostProcessor from '@shared/post-processors/exchange-rates'
import { createOTokenActivityProcessor } from '@templates/otoken/activity-processor/activity-processor'
import { createMorphoVaultApyProcessor } from '@templates/morpho/processor'
import { processStatus } from '@templates/processor-status'
import { createOTokenWithdrawalsProcessor } from '@templates/withdrawals'
import { addresses } from '@utils/addresses'
import { WOUSD_ADDRESS, addresses } from '@utils/addresses'
import { DEFAULT_FIELDS } from '@utils/batch-proccesor-fields'
import { initProcessorFromDump } from '@utils/dumps'

Expand All @@ -19,6 +20,13 @@ export const processor = defineSquidProcessor({
stateSchema: 'ousd-processor',
processors: [
ousdProcessor,
createOTokenActivityProcessor({
from: 11590995,
otokenAddress: addresses.ousd.address,
wotokenAddress: WOUSD_ADDRESS,
vaultAddress: addresses.ousd.vault,
cowSwap: false,
}),
ousdStrategiesProcessor,
createOTokenWithdrawalsProcessor({
name: 'OUSD',
Expand Down
8 changes: 8 additions & 0 deletions src/model/generated/oTokenActivity.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export class OTokenActivity {
@StringColumn_({nullable: false})
otoken!: string

@Index_()
@StringColumn_({nullable: true})
account!: string | undefined | null

@Index_()
@StringColumn_({nullable: true})
counterparty!: string | undefined | null

@Index_()
@DateTimeColumn_({nullable: false})
timestamp!: Date
Expand Down
4 changes: 2 additions & 2 deletions src/templates/otoken/activity-processor/activity-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const createOTokenActivityProcessor = (params: {
// Mints & Redeems
vaultActivityProcessor({ otokenAddress: params.otokenAddress, vaultAddress: params.vaultAddress }),

// Transfers & Swaps
// Transfers
transferActivityProcessor({ otokenAddress: params.otokenAddress }),
]).filter((p) => p.name.includes('Approval'))
])

const from = params.from
const setup = (processor: EvmBatchProcessor) => {
Expand Down
35 changes: 35 additions & 0 deletions src/templates/otoken/activity-processor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ export const createActivity = <T extends Activity>(
status?: T['status']
} & Omit<T, 'id' | 'chainId' | 'blockNumber' | 'timestamp' | 'status' | 'txHash'>,
) => {
const { account, counterparty } = extractParticipants(partial)

const activity = new OTokenActivity({
chainId: ctx.chain.id,
blockNumber: block.header.height,
timestamp: new Date(block.header.timestamp),
txHash: log.transactionHash,
type: OTokenActivityType[partial.type],
otoken: otokenAddress,
account,
counterparty,
data: {
status: 'success',
...partial,
Expand All @@ -47,3 +51,34 @@ export const createActivity = <T extends Activity>(

return activity
}

const extractParticipants = (partial: Record<string, unknown>) => {
const account = firstAddress([
partial.account,
partial.sender,
partial.from,
partial.owner,
partial.transactor,
partial.delegator,
partial.voter,
])

const counterparty = firstAddress([
partial.to,
partial.receiver,
partial.spender,
partial.delegateTo,
])

return { account, counterparty }
}

const firstAddress = (values: unknown[]) => {
for (const value of values) {
if (typeof value === 'string' && value.startsWith('0x') && value.length === 42) {
return value.toLowerCase()
}
}

return null
}
2 changes: 2 additions & 0 deletions src/templates/otoken/otoken.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ type OTokenActivity @entity {
id: ID!
chainId: Int! @index
otoken: String! @index
account: String @index
counterparty: String @index
timestamp: DateTime! @index
blockNumber: Int! @index
txHash: String! @index
Expand Down
Loading