From 0cbcbd9bcf9990b67609187c41717425019e0d6b Mon Sep 17 00:00:00 2001 From: dydxwill <119354122+dydxwill@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:14:47 -0400 Subject: [PATCH] add updatedAt to compliance v2 responses (#1360) (cherry picked from commit 4bc8bf78e6d65de93c5d43be21445fe91bb69faf) --- .../api/v4/compliance-v2-controller.test.ts | 7 +++++++ .../services/comlink/public/api-documentation.md | 7 +++++-- indexer/services/comlink/public/swagger.json | 3 +++ .../api/v4/compliance-v2-controller.ts | 16 ++++++++++------ indexer/services/comlink/src/types.ts | 1 + 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/indexer/services/comlink/__tests__/controllers/api/v4/compliance-v2-controller.test.ts b/indexer/services/comlink/__tests__/controllers/api/v4/compliance-v2-controller.test.ts index f96d33c82d..04ffaff63a 100644 --- a/indexer/services/comlink/__tests__/controllers/api/v4/compliance-v2-controller.test.ts +++ b/indexer/services/comlink/__tests__/controllers/api/v4/compliance-v2-controller.test.ts @@ -117,6 +117,7 @@ describe('ComplianceV2Controller', () => { }); expect(response.body.status).toEqual(ComplianceStatus.BLOCKED); expect(response.body.reason).toEqual(ComplianceReason.COMPLIANCE_PROVIDER); + expect(response.body.updatedAt).toBeDefined(); data = await ComplianceStatusTable.findAll({}, [], {}); expect(data).toHaveLength(1); expect(data[0]).toEqual(expect.objectContaining({ @@ -147,6 +148,7 @@ describe('ComplianceV2Controller', () => { }); expect(response.body.status).toEqual(ComplianceStatus.CLOSE_ONLY); expect(response.body.reason).toEqual(ComplianceReason.COMPLIANCE_PROVIDER); + expect(response.body.updatedAt).toBeDefined(); data = await ComplianceStatusTable.findAll({}, [], {}); expect(data).toHaveLength(1); expect(data[0]).toEqual(expect.objectContaining({ @@ -360,6 +362,7 @@ describe('ComplianceV2Controller', () => { expect(response.body.status).toEqual(ComplianceStatus.BLOCKED); expect(response.body.reason).toEqual(ComplianceReason.US_GEO); + expect(response.body.updatedAt).toBeDefined(); }); it('should set status to FIRST_STRIKE for CONNECT action from a restricted country with no existing compliance status', async () => { @@ -387,6 +390,7 @@ describe('ComplianceV2Controller', () => { expect(response.body.status).toEqual(ComplianceStatus.FIRST_STRIKE); expect(response.body.reason).toEqual(ComplianceReason.US_GEO); + expect(response.body.updatedAt).toBeDefined(); }); it('should set status to COMPLIANT for any action from a non-restricted country with no existing compliance status', async () => { @@ -439,6 +443,7 @@ describe('ComplianceV2Controller', () => { expect(response.body.status).toEqual(ComplianceStatus.FIRST_STRIKE); expect(response.body.reason).toEqual(ComplianceReason.US_GEO); + expect(response.body.updatedAt).toBeDefined(); }); it('should be a no-op for ONBOARD action with existing COMPLIANT status', async () => { @@ -502,6 +507,7 @@ describe('ComplianceV2Controller', () => { })); expect(response.body.status).toEqual(ComplianceStatus.FIRST_STRIKE); expect(response.body.reason).toEqual(ComplianceReason.US_GEO); + expect(response.body.updatedAt).toBeDefined(); }); it('should update status to CLOSE_ONLY for CONNECT action from a restricted country with existing FIRST_STRIKE status', async () => { @@ -534,6 +540,7 @@ describe('ComplianceV2Controller', () => { expect(response.body.status).toEqual(ComplianceStatus.CLOSE_ONLY); expect(response.body.reason).toEqual(ComplianceReason.US_GEO); + expect(response.body.updatedAt).toBeDefined(); }); }); }); diff --git a/indexer/services/comlink/public/api-documentation.md b/indexer/services/comlink/public/api-documentation.md index 7526a526e3..430d941830 100644 --- a/indexer/services/comlink/public/api-documentation.md +++ b/indexer/services/comlink/public/api-documentation.md @@ -704,7 +704,8 @@ fetch('https://dydx-testnet.imperator.co/v4/compliance/screen/{address}', ```json { "status": "COMPLIANT", - "reason": "MANUAL" + "reason": "MANUAL", + "updatedAt": "string" } ``` @@ -3281,7 +3282,8 @@ This operation does not require authentication ```json { "status": "COMPLIANT", - "reason": "MANUAL" + "reason": "MANUAL", + "updatedAt": "string" } ``` @@ -3292,6 +3294,7 @@ This operation does not require authentication |---|---|---|---|---| |status|[ComplianceStatus](#schemacompliancestatus)|true|none|none| |reason|[ComplianceReason](#schemacompliancereason)|false|none|none| +|updatedAt|string|false|none|none| ## OrderSide diff --git a/indexer/services/comlink/public/swagger.json b/indexer/services/comlink/public/swagger.json index 6c769578c9..2beed01bc9 100644 --- a/indexer/services/comlink/public/swagger.json +++ b/indexer/services/comlink/public/swagger.json @@ -372,6 +372,9 @@ }, "reason": { "$ref": "#/components/schemas/ComplianceReason" + }, + "updatedAt": { + "type": "string" } }, "required": [ diff --git a/indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts b/indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts index 5896c36530..7944f6d1cf 100644 --- a/indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts +++ b/indexer/services/comlink/src/controllers/api/v4/compliance-v2-controller.ts @@ -82,24 +82,26 @@ class ComplianceV2Controller extends Controller { [], ); let complianceStatusFromDatabase: ComplianceStatusFromDatabase | undefined; + const updatedAt: string = DateTime.utc().toISO(); if (complianceStatus.length === 0) { complianceStatusFromDatabase = await ComplianceStatusTable.upsert({ address, status: ComplianceStatus.BLOCKED, reason: ComplianceReason.COMPLIANCE_PROVIDER, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } else { complianceStatusFromDatabase = await ComplianceStatusTable.update({ address, status: ComplianceStatus.CLOSE_ONLY, reason: ComplianceReason.COMPLIANCE_PROVIDER, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } return { status: complianceStatusFromDatabase!.status, reason: complianceStatusFromDatabase!.reason, + updatedAt, }; } else { return { @@ -255,6 +257,7 @@ router.post( [], ); let complianceStatusFromDatabase: ComplianceStatusFromDatabase | undefined; + const updatedAt: string = DateTime.utc().toISO(); if (complianceStatus.length === 0) { if (isRestrictedCountryHeaders(req.headers as CountryHeaders)) { if (action === ComplianceAction.ONBOARD) { @@ -262,21 +265,21 @@ router.post( address, status: ComplianceStatus.BLOCKED, reason: getGeoComplianceReason(req.headers as CountryHeaders)!, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } else if (action === ComplianceAction.CONNECT) { complianceStatusFromDatabase = await ComplianceStatusTable.upsert({ address, status: ComplianceStatus.FIRST_STRIKE, reason: getGeoComplianceReason(req.headers as CountryHeaders)!, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } } else { complianceStatusFromDatabase = await ComplianceStatusTable.upsert({ address, status: ComplianceStatus.COMPLIANT, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } } else { @@ -301,7 +304,7 @@ router.post( address, status: COMPLIANCE_PROGRESSION[complianceStatus[0].status], reason: getGeoComplianceReason(req.headers as CountryHeaders)!, - updatedAt: DateTime.utc().toISO(), + updatedAt, }); } } @@ -309,6 +312,7 @@ router.post( const response = { status: complianceStatusFromDatabase!.status, reason: complianceStatusFromDatabase!.reason, + updatedAt, }; return res.send(response); diff --git a/indexer/services/comlink/src/types.ts b/indexer/services/comlink/src/types.ts index 307bfb930f..6f3f3c46a5 100644 --- a/indexer/services/comlink/src/types.ts +++ b/indexer/services/comlink/src/types.ts @@ -484,6 +484,7 @@ export enum BlockedCode { export interface ComplianceV2Response { status: ComplianceStatus; reason?: ComplianceReason; + updatedAt?: string; } /* ------- HISTORICAL TRADING REWARD TYPES ------- */