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

Configuration file #131

Merged
merged 9 commits into from
Jan 18, 2024
Merged

Configuration file #131

merged 9 commits into from
Jan 18, 2024

Conversation

mfw78
Copy link
Contributor

@mfw78 mfw78 commented Jan 17, 2024

Description

Configuration methodology (via CLI options) has been outgrown with the number of options. This PR removes all chain / network related configuration and moves to a configuration file.

Changes

  • Move all configuration for chains to a dedicated file
  • Remove unused features (replay tx / replay block)
  • Eliminates dynamic download of filter policies (now within configuration file)
  • Update README.md

How to test

  1. Adjust the config.json.example for suitable configuration
  2. Run and verify sync process completes warmup

Related Issues

Fixes #129

@mfw78 mfw78 added the enhancement New feature or request label Jan 17, 2024
@mfw78 mfw78 requested review from anxolin and a team January 17, 2024 10:38
@mfw78 mfw78 self-assigned this Jan 17, 2024
@mfw78 mfw78 changed the title File configuration Configuration file Jan 17, 2024
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@types/ajv 1.0.0 None +0 514 B types
ajv-formats 2.1.1 None +0 52.2 kB esp
json-schema-to-typescript 13.1.2 network, environment +14 3.82 MB bcherny

Copy link
Contributor

@alfetopito alfetopito left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor!
Some nitpicks.

src/index.ts Outdated Show resolved Hide resolved
src/types/types.d.ts Outdated Show resolved Hide resolved
src/utils/filterPolicy.ts Outdated Show resolved Hide resolved
src/types/config.schema.json Outdated Show resolved Hide resolved
mfw78 and others added 3 commits January 17, 2024 12:25
Co-authored-by: Leandro <alfetopito@users.noreply.github.com>
@mfw78 mfw78 merged commit 597e30b into main Jan 18, 2024
4 checks passed
@mfw78 mfw78 deleted the file-configuration branch January 18, 2024 09:29
@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2024
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half way in my review, i need to try it more. I send a few comments.

In general I feel that given the size of the change:

  • you could have waited a bit for the review, is good that for such a change we have more eyes
  • it looks like this PR does a bunch of things that would be better to keep in separate PRs

I like the config. Feels much better

README.md Show resolved Hide resolved

## Overview

The [`ComposableCoW`](https://github.com/cowprotocol/composable-cow) conditional order framework requires a watch-tower to monitor the blockchain for new orders, and to post them to the [CoW Protocol `OrderBook` API](https://api.cow.fi/docs/#/). The watch-tower is a standalone application that can be run locally as a script for development, or deployed as a docker container to a server, or dappnode.
The [programmatic order](https://docs.cow.fi/cow-protocol/concepts/order-types/programmatic-orders) framework requires a watch-tower to monitor the blockchain for new orders, and to post them to the [CoW Protocol `OrderBook` API](https://docs.cow.fi/cow-protocol/reference/apis/orderbook). The watch-tower is a standalone application that can be run locally as a script for development, or deployed as a docker container to a server, or dappnode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not from this PR, I would start saying with what it is and not what it requires.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about something in these lines:

The programatic orders allow you to automatically place unlimited order, following your arbitrary trading strategy defined using the programmatic order frameworks.

Because smart contracts can't place orders in the Orderbook API, you will need a Watch-Tower that monitors these contracts and places an order on your behalf.

This project contains a general-purpose watch tower that will monitor all or some specific accounts, or orders depending on configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While nice, the idea is mostly that there is a hyperlink there that explains it, and reduces duplication of typing / explanation.

README.md Show resolved Hide resolved
@@ -0,0 +1,12 @@
{
"networks": [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is nicer indeed. But now we have an hybrid of envs and config.

Shouldn't we add all the config in the config file if we just made it mandatory to add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, I don't have a strong opinion either way on this, and only did this way so as to minimise work, and minimise type duplication between the watch-tower and the Pulumi configuration for infrastructure (not a strong argument though).

@@ -1,5 +1,2 @@
export * from "./run";
export * from "./runMulti";
export * from "./replayBlock";
export * from "./replayTx";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this necesary in this PR? now is ok, but feels like could be done in a different PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to remove these features?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. runMulti has been superceded (actually, run was removed and runMulti was repurposed to run).
  2. replayBlock and replayTx weren't actually implemented (so removed dead stubs).

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked great!

soft approve

@@ -343,6 +162,30 @@ function parseAddressOption(option: string, previous: string[] = []): string[] {
return [...previous, option];
}

function validateJSON(filePath: string): Config {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we reflect in the name this is the JSON of the config file?
validate json sounds too generic.

// Validate the data against the schema
if (!validate(data)) {
console.error("Configuration file validation failed:", validate.errors);
process.exit(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a good practice to terminate the program just like that

normally you throw and whomever needs to handle, handles

"type": "array",
"items": {
"type": "object",
"properties": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, you can add descriptions to the fields and/or examples

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are required? also default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean by this?

protected config: PolicyConfig | undefined;

constructor({ configBaseUrl }: FilterPolicyParams) {
this.configUrl = configBaseUrl;
constructor(config: Config["networks"][number]["filterPolicy"]) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you give a name to this type? feels hard to read

"defaultAction": {
"$ref": "#/$defs/filterAction"
},
"owners": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

owners and handlers have the same type. would it be worth it to reference it?

Actually would be probably be nice to define the FilterPolicy too. This way you will get a Typescript definition for it you can reuse, so you don't need to do things like:
constructor(config: Config["networks"][number]["filterPolicy"]) {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: configuration file
4 participants