Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updatedAt to compliance v2 API responses (backport #1360) #1480

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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();
});
});
});
7 changes: 5 additions & 2 deletions indexer/services/comlink/public/api-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ fetch('https://dydx-testnet.imperator.co/v4/compliance/screen/{address}',
```json
{
"status": "COMPLIANT",
"reason": "MANUAL"
"reason": "MANUAL",
"updatedAt": "string"
}
```

Expand Down Expand Up @@ -3281,7 +3282,8 @@ This operation does not require authentication
```json
{
"status": "COMPLIANT",
"reason": "MANUAL"
"reason": "MANUAL",
"updatedAt": "string"
}

```
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions indexer/services/comlink/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@
},
"reason": {
"$ref": "#/components/schemas/ComplianceReason"
},
"updatedAt": {
"type": "string"
}
},
"required": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -255,28 +257,29 @@ 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) {
complianceStatusFromDatabase = await ComplianceStatusTable.upsert({
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 {
Expand All @@ -301,14 +304,15 @@ router.post(
address,
status: COMPLIANCE_PROGRESSION[complianceStatus[0].status],
reason: getGeoComplianceReason(req.headers as CountryHeaders)!,
updatedAt: DateTime.utc().toISO(),
updatedAt,
});
}
}
}
const response = {
status: complianceStatusFromDatabase!.status,
reason: complianceStatusFromDatabase!.reason,
updatedAt,
};

return res.send(response);
Expand Down
1 change: 1 addition & 0 deletions indexer/services/comlink/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ export enum BlockedCode {
export interface ComplianceV2Response {
status: ComplianceStatus;
reason?: ComplianceReason;
updatedAt?: string;
}

/* ------- HISTORICAL TRADING REWARD TYPES ------- */
Expand Down
Loading