diff --git a/config.json.example b/config.json.example index c1942fd..40f6ecb 100644 --- a/config.json.example +++ b/config.json.example @@ -5,7 +5,19 @@ "rpc": "ws://172.20.0.5:8546", "deploymentBlock": 17883049, "filterPolicy": { - "defaultAction": "ACCEPT" + "defaultAction": "ACCEPT", + "conditionalOrderIds": { + "0x5b3cdb6ffa3c95507cbfc459162609007865c2e87340312d3cd469c4ffbfae81": "DROP", + }, + "transactions": { + "0x33ef06af308d1e4f94dd61fa8df43fe52b67e8a485f4e4fff75235080e663bfa": "DROP", + }, + "handlers": { + "0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP", + }, + "owners": { + "0xd3338f21c89745e46af56aeaf553cf96ba9bc66f": "DROP", + } } } ] diff --git a/src/domain/polling/filtering/policy.ts b/src/domain/polling/filtering/policy.ts index d0fe2b7..3659b66 100644 --- a/src/domain/polling/filtering/policy.ts +++ b/src/domain/polling/filtering/policy.ts @@ -11,9 +11,13 @@ interface PolicyConfig { defaultAction: FilterAction; owners: Map; handlers: Map; + transactions: Map; + conditionalOrderIds: Map; } export interface FilterParams { + conditionalOrderId: string; + transaction: string; owner: string; conditionalOrderParams: ConditionalOrderParams; } @@ -26,6 +30,8 @@ export class FilterPolicy { defaultAction: FilterAction[config.defaultAction], owners: this.convertToMap(config.owners), handlers: this.convertToMap(config.handlers), + transactions: this.convertToMap(config.transactions), + conditionalOrderIds: this.convertToMap(config.conditionalOrderIds), }; } @@ -35,15 +41,29 @@ export class FilterPolicy { * @param filterParams params required for the pre-filtering, including the conditional order params, chainId and the owner contract * @returns The action that should be performed with the conditional order */ - preFilter({ owner, conditionalOrderParams }: FilterParams): FilterAction { + preFilter({ + conditionalOrderId: programmaticOrderId, + transaction, + owner, + conditionalOrderParams, + }: FilterParams): FilterAction { if (!this.config) { return FilterAction.ACCEPT; } - const { owners, handlers } = this.config; + const { + owners, + handlers, + conditionalOrderIds: programmaticOrderIds, + transactions, + } = this.config; + // Find the first matching rule const action = - handlers.get(conditionalOrderParams.handler) || owners.get(owner); + programmaticOrderIds.get(programmaticOrderId) || + transactions.get(transaction) || + owners.get(owner) || + handlers.get(conditionalOrderParams.handler); if (action) { return action; diff --git a/src/domain/polling/index.ts b/src/domain/polling/index.ts index 1f6cef0..79bf04d 100644 --- a/src/domain/polling/index.ts +++ b/src/domain/polling/index.ts @@ -119,13 +119,15 @@ export async function checkForAndPlaceOrder( // Apply filtering policy if (filterPolicy) { const filterResult = filterPolicy.preFilter({ + conditionalOrderId: conditionalOrder.id, + transaction: conditionalOrder.tx, owner, conditionalOrderParams: conditionalOrder.params, }); switch (filterResult) { case policy.FilterAction.DROP: - log.debug("Dropping conditional order. Reason: AcceptPolicy: DROP"); + log.info("Dropping conditional order. Reason: AcceptPolicy: DROP"); ordersPendingDelete.push(conditionalOrder); continue; diff --git a/src/types/config.schema.json b/src/types/config.schema.json index 166eb57..0fa1078 100644 --- a/src/types/config.schema.json +++ b/src/types/config.schema.json @@ -1,79 +1,78 @@ { - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "networks": { - "type": "array", - "items": { - "type": "object", - "properties": { - "name": { - "type": "string" - }, - "rpc": { - "type": "string", - "format": "uri" - }, - "deploymentBlock": { - "type": "integer" - }, - "watchdogTimeout": { - "type": "integer" - }, - "orderBookApi": { - "type": "string", - "format": "uri" - }, - "pageSize": { - "type": "integer" - }, - "filterPolicy": { - "type": "object", - "properties": { - "defaultAction": { - "$ref": "#/$defs/filterAction" - }, - "owners": { - "type": "object", - "additionalProperties": { - "$ref": "#/$defs/filterAction" - } - }, - "handlers": { - "type": "object", - "additionalProperties": { - "$ref": "#/$defs/filterAction" - } - } - }, - "required": [ - "defaultAction" - ], - "additionalProperties": false - } - }, - "required": [ - "name", - "rpc", - "deploymentBlock", - "filterPolicy" - ], - "additionalProperties": false - } - } - }, - "required": [ - "networks" - ], - "additionalProperties": false, - "$defs": { - "filterAction": { + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "networks": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "rpc": { + "type": "string", + "format": "uri" + }, + "deploymentBlock": { + "type": "integer" + }, + "watchdogTimeout": { + "type": "integer" + }, + "orderBookApi": { "type": "string", - "enum": [ - "ACCEPT", - "DROP", - "SKIP" - ] - } + "format": "uri" + }, + "pageSize": { + "type": "integer" + }, + "filterPolicy": { + "type": "object", + "properties": { + "defaultAction": { + "$ref": "#/$defs/filterAction" + }, + "conditionalOrderIds": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/filterAction" + } + }, + "transactions": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/filterAction" + } + }, + "owners": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/filterAction" + } + }, + "handlers": { + "type": "object", + "additionalProperties": { + "$ref": "#/$defs/filterAction" + } + } + }, + "required": ["defaultAction"], + "additionalProperties": false + } + }, + "required": ["name", "rpc", "deploymentBlock", "filterPolicy"], + "additionalProperties": false + } + } + }, + "required": ["networks"], + "additionalProperties": false, + "$defs": { + "filterAction": { + "type": "string", + "enum": ["ACCEPT", "DROP", "SKIP"] } + } } diff --git a/src/types/types.d.ts b/src/types/types.d.ts index 092155d..f511b40 100644 --- a/src/types/types.d.ts +++ b/src/types/types.d.ts @@ -23,6 +23,12 @@ export interface Config { handlers?: { [k: string]: FilterAction; }; + transactions?: { + [k: string]: FilterAction; + }; + conditionalOrderIds?: { + [k: string]: FilterAction; + }; }; }[]; }