Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions src/chains/abis/repoDriverAbi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export const repoDriverAbi = [
name: 'NewAdminProposed',
type: 'event',
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: 'uint256', name: 'accountId', type: 'uint256' },
{ indexed: false, internalType: 'uint8', name: 'sourceId', type: 'uint8' },
{ indexed: false, internalType: 'bytes', name: 'name', type: 'bytes' },
],
name: 'AccountIdSeen',
type: 'event',
},
{
anonymous: false,
inputs: [
Expand Down
2 changes: 1 addition & 1 deletion src/chains/monitoredEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const DRIPS_EVENTS = [

export const NFT_DRIVER_EVENTS = ['Transfer'];

export const REPO_DRIVER_EVENTS = ['OwnerUpdateRequested', 'OwnerUpdated'];
export const REPO_DRIVER_EVENTS = ['AccountIdSeen', 'OwnerUpdateRequested', 'OwnerUpdated'];

export const ADDRESS_DRIVER_EVENTS: string[] = [];

Expand Down
86 changes: 86 additions & 0 deletions src/handlers/accountIdSeenHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { fromHex, type DecodeEventLogReturnType } from 'viem';

import type { RepoDriverAbi } from '../chains/abis/abiTypes.js';
import { logger } from '../logger.js';
import { mapForge, forgeToUrl } from '../utils/forgeUtils.js';
import { isOrcidAccount, isProject } from '../utils/repoDriverAccountUtils.js';
import { toEventPointer } from '../repositories/types.js';
import { insertIgnore } from '../db/db.js';
import {
projectSchema,
type Project,
type ProjectStatus,
linkedIdentitySchema,
type LinkedIdentity,
type LinkedIdentityType,
} from '../db/schemas.js';

import type { EventHandler, HandlerEvent } from './EventHandler.js';

type AccountIdSeenEvent = HandlerEvent & {
args: DecodeEventLogReturnType<RepoDriverAbi, 'AccountIdSeen'>['args'];
};

export const accountIdSeenHandler: EventHandler<AccountIdSeenEvent> = async (event, ctx) => {
const { accountId, sourceId, name } = event.args;
const { client, schema } = ctx;
const eventPointer = toEventPointer(event);
const accountIdStr = accountId.toString();
const nameStr = fromHex(name, 'string');

if (isProject(accountIdStr)) {
const forgeValue = mapForge(Number(sourceId));
const { entity: project, created } = await insertIgnore<Project>({
client,
table: `${schema}.projects`,
data: {
account_id: accountIdStr,
forge: forgeValue,
name: nameStr,
url: forgeToUrl(forgeValue, nameStr),
owner_address: null,
owner_account_id: null,
verification_status: 'unclaimed' as ProjectStatus,
is_valid: true,
is_visible: true,
last_event_block: eventPointer.last_event_block,
last_event_tx_index: eventPointer.last_event_tx_index,
last_event_log_index: eventPointer.last_event_log_index,
},
conflictColumns: ['account_id'],
schema: projectSchema,
});

if (created) {
logger.info('account_id_seen_project_created', { project });
} else {
logger.info('account_id_seen_project_exists', { project });
}
} else if (isOrcidAccount(accountIdStr)) {
const { entity: linkedIdentity, created } = await insertIgnore<LinkedIdentity>({
client,
table: `${schema}.linked_identities`,
data: {
account_id: accountIdStr,
identity_type: 'orcid' as LinkedIdentityType,
owner_address: null,
owner_account_id: null,
are_splits_valid: false,
is_visible: true,
last_event_block: eventPointer.last_event_block,
last_event_tx_index: eventPointer.last_event_tx_index,
last_event_log_index: eventPointer.last_event_log_index,
},
conflictColumns: ['account_id'],
schema: linkedIdentitySchema,
});

if (created) {
logger.info('account_id_seen_linked_identity_created', { linkedIdentity });
} else {
logger.info('account_id_seen_linked_identity_exists', { linkedIdentity });
}
} else {
logger.warn('account_id_seen_unsupported_account', { accountId: accountIdStr });
}
};
2 changes: 2 additions & 0 deletions src/handlers/registry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { accountIdSeenHandler } from './accountIdSeenHandler.js';
import { accountMetadataEmittedHandler } from './AccountMetadataEmitted/accountMetadataEmittedHandler.js';
import type { EventHandler } from './EventHandler.js';
import { givenHandler } from './givenHandler.js';
Expand Down Expand Up @@ -27,6 +28,7 @@ export const registry: Record<string, EventHandler> = {
Transfer: transferHandler as EventHandler,
SplitsSet: splitsSetHandler as EventHandler,
StreamsSet: streamsSetHandler as EventHandler,
AccountIdSeen: accountIdSeenHandler as EventHandler,
OwnerUpdated: ownerUpdatedHandler as EventHandler,
SqueezedStreams: squeezedStreamsHandler as EventHandler,
StreamReceiverSeen: streamReceiverSeenHandler as EventHandler,
Expand Down