From 57474d28725433510bfb898b8ab6da502018a8ca Mon Sep 17 00:00:00 2001 From: Mikhail Gladchenko Date: Fri, 29 Mar 2024 08:49:00 +0000 Subject: [PATCH] feat: added frontage service --- package.json | 2 +- src/Orion/index.ts | 5 +- src/Unit/index.ts | 5 +- src/config/envs.json | 99 +++++++++++++++++++ src/config/schemas/pureEnvSchema.ts | 3 + src/services/Frontage/index.ts | 20 ++++ src/services/Frontage/schemas/index.ts | 1 + .../Frontage/schemas/search-tickers-schema.ts | 9 ++ src/services/index.ts | 1 + src/types.ts | 6 ++ 10 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/services/Frontage/index.ts create mode 100644 src/services/Frontage/schemas/index.ts create mode 100644 src/services/Frontage/schemas/search-tickers-schema.ts diff --git a/package.json b/package.json index ee8c258..fe29a0d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.78", + "version": "0.20.79-rc0", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/Orion/index.ts b/src/Orion/index.ts index 7245c00..629027e 100644 --- a/src/Orion/index.ts +++ b/src/Orion/index.ts @@ -60,7 +60,10 @@ export default class Orion { }, indexer: { api: networkConfig.api + networkConfig.services.indexer?.http, - } + }, + frontage: { + api: networkConfig.api + networkConfig.services.frontage.http, + }, }, }; }) diff --git a/src/Unit/index.ts b/src/Unit/index.ts index 85d7052..b91e549 100644 --- a/src/Unit/index.ts +++ b/src/Unit/index.ts @@ -11,7 +11,7 @@ import Exchange from './Exchange/index.js'; import { chains, envs } from '../config'; import type { networkCodes } from '../constants/index.js'; import { IndexerService } from '../services/Indexer'; -import Pmm from "./Pmm"; +import Pmm from './Pmm'; type KnownConfig = { env: KnownEnv @@ -88,6 +88,9 @@ export default class Unit { indexer: { api: networkConfig.api + networkConfig.services.indexer?.http, }, + frontage: { + api: networkConfig.api + networkConfig.services.frontage.http, + }, }, }; } else { diff --git a/src/config/envs.json b/src/config/envs.json index a6c3988..0787b96 100644 --- a/src/config/envs.json +++ b/src/config/envs.json @@ -17,6 +17,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } }, "liquidityMigratorAddress": "0x23a1820a47BcD022E29f6058a5FD224242F50D1A" @@ -36,6 +39,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -54,6 +60,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -72,6 +81,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -90,6 +102,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -108,6 +123,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -126,6 +144,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -144,6 +165,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -162,6 +186,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -180,6 +207,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } } @@ -203,6 +233,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } }, "liquidityMigratorAddress": "0x01b10dds12478C88A5E18e2707E729906bC25CfF6" @@ -222,6 +255,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -240,6 +276,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -258,6 +297,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -276,6 +318,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -294,6 +339,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } } @@ -317,6 +365,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -335,6 +386,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -353,6 +407,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -371,6 +428,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -389,6 +449,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -407,6 +470,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -425,6 +491,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -443,6 +512,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -461,6 +533,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -479,6 +554,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } } @@ -502,6 +580,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -520,6 +601,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } } @@ -543,6 +627,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } }, "liquidityMigratorAddress": "0x23a1820a47BcD022E29f6058a5FD224242F50D1A" @@ -562,6 +649,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -580,6 +670,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -598,6 +691,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } }, @@ -616,6 +712,9 @@ }, "indexer": { "http": "/orion-indexer/" + }, + "frontage": { + "http": "/frontage" } } } diff --git a/src/config/schemas/pureEnvSchema.ts b/src/config/schemas/pureEnvSchema.ts index 9c799c4..31f503c 100644 --- a/src/config/schemas/pureEnvSchema.ts +++ b/src/config/schemas/pureEnvSchema.ts @@ -17,6 +17,9 @@ export const pureEnvNetworksSchema = z.object({ indexer: z.object({ http: z.string(), }).optional(), + frontage: z.object({ + http: z.string(), + }), }), rpc: z.string().optional(), liquidityMigratorAddress: z.string().optional(), diff --git a/src/services/Frontage/index.ts b/src/services/Frontage/index.ts new file mode 100644 index 0000000..2646156 --- /dev/null +++ b/src/services/Frontage/index.ts @@ -0,0 +1,20 @@ +import { fetchWithValidation } from 'simple-typed-fetch'; +import { searchTickersSchema } from './schemas'; + +export class Frontage { + private readonly apiUrl: string; + + constructor(apiUrl: string) { + this.apiUrl = apiUrl; + + this.searchTickers = this.searchTickers.bind(this); + } + + searchTickers = () => { + return fetchWithValidation(`${this.apiUrl}/api/v1/tickers/search`, + searchTickersSchema + ); + }; +} + +export * as schemas from './schemas/index.js'; diff --git a/src/services/Frontage/schemas/index.ts b/src/services/Frontage/schemas/index.ts new file mode 100644 index 0000000..c03475f --- /dev/null +++ b/src/services/Frontage/schemas/index.ts @@ -0,0 +1 @@ +export * from './search-tickers-schema'; diff --git a/src/services/Frontage/schemas/search-tickers-schema.ts b/src/services/Frontage/schemas/search-tickers-schema.ts new file mode 100644 index 0000000..3822030 --- /dev/null +++ b/src/services/Frontage/schemas/search-tickers-schema.ts @@ -0,0 +1,9 @@ +import { z } from 'zod'; + +export const searchTickersSchema = z.array(z.object({ + pair: z.string(), + volume24: z.number(), + change24: z.number(), + lastPrice: z.number(), + networks: z.array(z.string()), +})); diff --git a/src/services/index.ts b/src/services/index.ts index ca04ebd..004c45f 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -3,3 +3,4 @@ export * as blockchainService from './BlockchainService/index.js'; export * as priceFeed from './PriceFeed/index.js'; export * as referralSystem from './ReferralSystem/index.js'; export * as indexer from './Indexer/index.js'; +export * as frontage from './Frontage/index.js'; diff --git a/src/types.ts b/src/types.ts index 5828296..3607a8d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -271,6 +271,12 @@ export type VerboseUnitConfig = { // http://localhost:3004/, // http:// } | undefined + frontage: { + api: string + // For example: + // http://localhost:3004/, + // http:// + } } basicAuth?: BasicAuthCredentials }