diff --git a/README.md b/README.md index 843672d..fefffcc 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,15 @@ Token Price Oracle is simple oracle for tracking token prices on-chain. In this repo is located the Typescript Client orchestrator used for tracking, management and orchestration of the data. +![Token Price Oracle - SC - banner](./assets/general-diagram.png) + +## Documentation 📚 +You'll find the API specification under `/docs/api` and you can also run +interactive Swagger client by running the project and going to the `/api-docs` route in your browser. +_Example: http://localhost:3001/api-docs_ + +The main site for documentation is located on the [link here](https://despotf.gitbook.io/token-price-oracle/). + ## Running the project 🚀 ### Requirements ✅ - On your computer @@ -44,7 +53,7 @@ if you're trying to run the project using docker or your local setup 4. Run `docker-compose up` 5. That's it! > [!NOTE] -> If you've pulled new code files you'll have to rebuild the Docker image using `docker-compose build --no-cache node_backend` +> If you've pulled new code files you'll have to rebuild the Docker image using `docker-compose build --no-cache token_price_oracle_orchestrator_ts` #### Running locally 4. Run ```yarn``` to install the dependencies diff --git a/assets/general-diagram.png b/assets/general-diagram.png new file mode 100644 index 0000000..5293285 Binary files /dev/null and b/assets/general-diagram.png differ diff --git a/docs/api/Token-Price-Oracle-Orchestrator.openapi_collection.json b/docs/api/Token-Price-Oracle-Orchestrator.openapi_collection.json new file mode 100644 index 0000000..d9f6b05 --- /dev/null +++ b/docs/api/Token-Price-Oracle-Orchestrator.openapi_collection.json @@ -0,0 +1,124 @@ +{ + "openapi": "3.0.3", + "info": { + "title": "Token-Price-Oracle-Orchestrator", + "description": "Token Price Oracle is simple oracle for tracking token prices on-chain.\n\nThis is the documentatino of the API endpoints used for consuming the collected data", + "version": "1.0.0", + "contact": {} + }, + "servers": [ + { + "url": "http://localhost" + } + ], + "paths": { + "/api/v1/tickers": { + "get": { + "tags": [ + "Tickers" + ], + "summary": "Ticker List", + "description": "Returns list of on-chain and off-chain price data of all the tickers available in the storage", + "operationId": "tickerList", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/api/v1/tickers/{tickerSymbol}": { + "get": { + "tags": [ + "Tickers" + ], + "parameters": [ + { + "name": "tickerSymbol", + "in": "path", + "description": "Ticker of the asset", + "required": true, + "schema": { + "type": "string" + } + } + ], + "summary": "Ticker", + "description": "Returns on-chain and off-chain price data of a given ticker.", + "operationId": "ticker", + "responses": { + "200": { + "description": "" + } + } + } + }, + "/api/v1/tickers/{tickerSymbol}/history": { + "get": { + "tags": [ + "Tickers" + ], + "summary": "Ticker Historical prices", + "description": "Returns the historical price data of a given ticker between the given Unix timestamps", + "operationId": "tickerHistoricalPrices", + "parameters": [ + { + "name": "tickerSymbol", + "in": "path", + "description": "Ticker of the asset", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "from", + "in": "query", + "schema": { + "type": "string", + "example": "1702532251" + } + }, + { + "name": "to", + "in": "query", + "schema": { + "type": "string", + "example": "1702632251" + } + } + ], + "responses": { + "200": { + "description": "" + } + } + } + }, + "/api/v1/reverts": { + "get": { + "tags": [ + "Reverts" + ], + "summary": "On-chain historical reverts", + "description": "Returns all of the reverts that happened on-chain (regardless of the sender) for the price updating action on the TokenPriceStorage contract.", + "operationId": "onChainHistoricalReverts", + "responses": { + "200": { + "description": "" + } + } + } + } + }, + "tags": [ + { + "name": "Tickers", + "description": "All ticker data" + }, + { + "name": "Reverts", + "description": "Historical reverts data" + } + ] +} \ No newline at end of file diff --git a/docs/api/Token-Price-Oracle-Orchestrator.postman_collection.json b/docs/api/Token-Price-Oracle-Orchestrator.postman_collection.json new file mode 100644 index 0000000..4e7bef8 --- /dev/null +++ b/docs/api/Token-Price-Oracle-Orchestrator.postman_collection.json @@ -0,0 +1,118 @@ +{ + "info": { + "_postman_id": "ba5c6c37-b93c-4d5b-8d4b-74bec4dd9dff", + "name": "Token-Price-Oracle-Orchestrator", + "description": "Token Price Oracle is simple oracle for tracking token prices on-chain.\n\nThis is the documentation of the API endpoints used for consuming the collected data", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "16309767" + }, + "item": [ + { + "name": "Ticker List", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:3001/api/v1/tickers", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3001", + "path": [ + "api", + "v1", + "tickers" + ] + }, + "description": "Returns list of on-chain and off-chain price data of all the tickers available in the storage" + }, + "response": [] + }, + { + "name": "Ticker", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:3001/api/v1/tickers/{{tickerSymbol}}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3001", + "path": [ + "api", + "v1", + "tickers", + "{{tickerSymbol}}" + ] + }, + "description": "Returns on-chain and off-chain price data of a given ticker." + }, + "response": [] + }, + { + "name": "Ticker Historical prices", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:3001/api/v1/tickers/{{tickerSymbol}}/history?from=1702532251&to=1702632251", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3001", + "path": [ + "api", + "v1", + "tickers", + "{{tickerSymbol}}", + "history" + ], + "query": [ + { + "key": "from", + "value": "1702532251" + }, + { + "key": "to", + "value": "1702632251" + } + ] + }, + "description": "Returns the historical price data of a given ticker between the given Unix timestamps" + }, + "response": [] + }, + { + "name": "On-chain historical reverts", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:3001/api/v1/reverts", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3001", + "path": [ + "api", + "v1", + "reverts" + ] + }, + "description": "Returns all of the reverts that happened on-chain (regardless of the sender) for the price updating action on the TokenPriceStorage contract." + }, + "response": [] + } + ], + "variable": [ + { + "key": "tickerSymbol", + "value": "ETH" + } + ] +} \ No newline at end of file diff --git a/package.json b/package.json index 813a550..d34a49f 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@types/cors": "^2.8.17", "@types/express": "^4.17.21", "@types/node-cron": "^3.0.11", + "@types/swagger-ui-express": "^4.1.6", "@typescript-eslint/eslint-plugin": "^6.13.2", "@typescript-eslint/parser": "^6.13.2", "eslint": "^8.55.0", @@ -35,6 +36,7 @@ "log4js": "^6.9.1", "node-cron": "^3.0.3", "redux": "^5.0.0", - "socket.io": "^4.7.2" + "socket.io": "^4.7.2", + "swagger-ui-express": "^5.0.0" } } diff --git a/src/app.ts b/src/app.ts index 720e92c..924433a 100644 --- a/src/app.ts +++ b/src/app.ts @@ -5,6 +5,9 @@ import cors from "cors"; import api from "./api"; import { initApp } from "./jobs/app.jobs"; +import swaggerUi from "swagger-ui-express"; +import swaggerDocument from "../docs/api/Token-Price-Oracle-Orchestrator.openapi_collection.json"; + const { NODE_PORT, NODE_HOST } = CONFIG; const app = express(); @@ -15,9 +18,11 @@ app.use(cors(CONFIG.CORS_OPTIONS)); app.use(bodyParser.json()); const apiRouter = Router(); + apiRouter.use("/api", api); +app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); -initApp(); + initApp(); app.use(apiRouter); // 404 diff --git a/yarn.lock b/yarn.lock index 56e7a26..bbb70be 100644 --- a/yarn.lock +++ b/yarn.lock @@ -191,7 +191,7 @@ "@types/range-parser" "*" "@types/send" "*" -"@types/express@^4.17.21": +"@types/express@*", "@types/express@^4.17.21": version "4.17.21" resolved "https://registry.yarnpkg.com/@types/express/-/express-4.17.21.tgz#c26d4a151e60efe0084b23dc3369ebc631ed192d" integrity sha512-ejlPM315qwLpaQlQDTjPdsUFSc6ZsP4AN6AlWnogPjQ7CVi7PYF3YVz+CY3jE2pwYf7E/7HlDAN0rV2GxTG0HQ== @@ -275,6 +275,14 @@ "@types/mime" "*" "@types/node" "*" +"@types/swagger-ui-express@^4.1.6": + version "4.1.6" + resolved "https://registry.yarnpkg.com/@types/swagger-ui-express/-/swagger-ui-express-4.1.6.tgz#d0929e3fabac1a96a8a9c6c7ee8d42362c5cdf48" + integrity sha512-UVSiGYXa5IzdJJG3hrc86e8KdZWLYxyEsVoUI4iPXc7CO4VZ3AfNP8d/8+hrDRIqz+HAaSMtZSqAsF3Nq2X/Dg== + dependencies: + "@types/express" "*" + "@types/serve-static" "*" + "@typescript-eslint/eslint-plugin@^6.13.2": version "6.13.2" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.13.2.tgz#2e03506c5362a65e43cb132c37c9ce2d3cb51470" @@ -1920,6 +1928,18 @@ supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +swagger-ui-dist@>=5.0.0: + version "5.10.5" + resolved "https://registry.yarnpkg.com/swagger-ui-dist/-/swagger-ui-dist-5.10.5.tgz#a16e32465c49259045a745f6906fbdb37b4f7ef5" + integrity sha512-Uv8E7hV/nXALQKgW86X1i58gl1O6DFg+Uq54sDwhYqucBBxj/47dLNw872TNILNlOTuPA6dRvUMGQdmlpaX8qQ== + +swagger-ui-express@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/swagger-ui-express/-/swagger-ui-express-5.0.0.tgz#7a00a18dd909574cb0d628574a299b9ba53d4d49" + integrity sha512-tsU9tODVvhyfkNSvf03E6FAk+z+5cU3lXAzMy6Pv4av2Gt2xA0++fogwC4qo19XuFf6hdxevPuVCSKFuMHJhFA== + dependencies: + swagger-ui-dist ">=5.0.0" + table-layout@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-1.0.2.tgz#c4038a1853b0136d63365a734b6931cf4fad4a04"