diff --git a/README.md b/README.md index 27ed280..b02ebfb 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,20 @@ Some parameters are common to every event: } ``` +### Delegates add/update/delete + +```json +{ +"type": "NEW_DELEGATE" | "UPDATED_DELEGATE" | "DELETED_DELEGATE", +"safeAddress": "" | null, +"delegate": "", +"delegator": "", +"label": "", +"expiryDateSeconds": "" | null, +"chainId": "" +} +``` + # FAQ ## Do you have a dashboard/status page? diff --git a/src/datasources/migrations/1730984672394-SendDelegates.ts b/src/datasources/migrations/1730984672394-SendDelegates.ts new file mode 100644 index 0000000..9f7fe64 --- /dev/null +++ b/src/datasources/migrations/1730984672394-SendDelegates.ts @@ -0,0 +1,17 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class SendDelegates1730984672394 implements MigrationInterface { + name = 'SendDelegates1730984672394'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "webhook" ADD "sendDelegates" boolean NOT NULL DEFAULT true`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "webhook" DROP COLUMN "sendDelegates"`, + ); + } +} diff --git a/src/routes/events/event.dto.ts b/src/routes/events/event.dto.ts index 62d15b8..2b116d9 100644 --- a/src/routes/events/event.dto.ts +++ b/src/routes/events/event.dto.ts @@ -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; diff --git a/src/routes/webhook/entities/webhook.entity.spec.ts b/src/routes/webhook/entities/webhook.entity.spec.ts index d2fc236..7864c93 100644 --- a/src/routes/webhook/entities/webhook.entity.spec.ts +++ b/src/routes/webhook/entities/webhook.entity.spec.ts @@ -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 () => { @@ -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); + }); }); diff --git a/src/routes/webhook/entities/webhook.entity.ts b/src/routes/webhook/entities/webhook.entity.ts index a2a589b..99ece0c 100644 --- a/src/routes/webhook/entities/webhook.entity.ts +++ b/src/routes/webhook/entities/webhook.entity.ts @@ -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 @@ -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'))) ); } }