Skip to content

Commit

Permalink
Add support for delegates events
Browse files Browse the repository at this point in the history
  • Loading branch information
falvaradorodriguez committed Nov 7, 2024
1 parent 8129ee0 commit d58e342
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ Some parameters are common to every event:
}
```

### Delegates add/update/delete

```json
{
"type": "NEW_DELEGATE" | "UPDATED_DELEGATE" | "DELETED_DELEGATE",
"safeAddress": "<Ethereum checksummed address>" | null,
"delegate": "<Ethereum checksummed address>",
"delegator": "<Ethereum checksummed address>",
"label": "<string>",
"expiryDateSeconds": "<int>" | null,
"chainId": "<stringified-int>"
}
```

# FAQ

## Do you have a dashboard/status page?
Expand Down
17 changes: 17 additions & 0 deletions src/datasources/migrations/1730984672394-SendDelegates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class SendDelegates1730984672394 implements MigrationInterface {
name = 'SendDelegates1730984672394';

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "webhook" ADD "sendDelegates" boolean NOT NULL DEFAULT true`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "webhook" DROP COLUMN "sendDelegates"`,
);
}
}
5 changes: 4 additions & 1 deletion src/routes/events/event.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export type TxServiceEventType =
| 'MESSAGE_CREATED'
| 'MESSAGE_CONFIRMATION'
| 'DELETED_MULTISIG_TRANSACTION'
| 'REORG_DETECTED';
| 'REORG_DETECTED'
| 'NEW_DELEGATE'
| 'UPDATED_DELEGATE'
| 'DELETED_DELEGATE';

export interface TxServiceEvent {
chainId: string;
Expand Down
22 changes: 22 additions & 0 deletions src/routes/webhook/entities/webhook.entity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Webhook entity', () => {
webhook.sendSafeCreations = true;
webhook.sendMessages = true;
webhook.sendReorgs = true;
webhook.sendDelegates = true;
});

it('If chain is set, only those chain messages will be sent', async () => {
Expand Down Expand Up @@ -135,4 +136,25 @@ describe('Webhook entity', () => {
webhook.sendReorgs = false;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(false);
});

it('NEW_DELEGATE should not be relevant if sendDelegates is disabled', async () => {
txServiceEvent.type = 'NEW_DELEGATE' as TxServiceEventType;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(true);
webhook.sendDelegates = false;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(false);
});

it('UPDATED_DELEGATE should not be relevant if sendDelegates is disabled', async () => {
txServiceEvent.type = 'UPDATED_DELEGATE' as TxServiceEventType;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(true);
webhook.sendDelegates = false;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(false);
});

it('DELETED_DELEGATE should not be relevant if sendDelegates is disabled', async () => {
txServiceEvent.type = 'DELETED_DELEGATE' as TxServiceEventType;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(true);
webhook.sendDelegates = false;
expect(webhook.isEventRelevant(txServiceEvent)).toBe(false);
});
});
9 changes: 8 additions & 1 deletion src/routes/webhook/entities/webhook.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export class Webhook extends BaseEntity {
@Column({ default: true })
sendReorgs: boolean;

@Column({ default: true })
sendDelegates: boolean;

/**
* Check if event chainId matches the one of the webhook (everything will match if webhook chains are empty). Check if event
* type matches the flags enabled for the webhook
Expand Down Expand Up @@ -75,7 +78,11 @@ export class Webhook extends BaseEntity {
(message.type === 'MESSAGE_CREATED' ||
message.type === 'MESSAGE_CONFIRMATION')) ||
(this.sendSafeCreations && message.type === 'SAFE_CREATED') ||
(this.sendReorgs && message.type === 'REORG_DETECTED'))
(this.sendReorgs && message.type === 'REORG_DETECTED') ||
(this.sendDelegates &&
(message.type === 'NEW_DELEGATE' ||
message.type === 'UPDATED_DELEGATE' ||
message.type === 'DELETED_DELEGATE')))
);
}
}

0 comments on commit d58e342

Please sign in to comment.