add frontage service and getAggregatedMetrics request

This commit is contained in:
TheJuze
2024-03-19 13:00:21 +03:00
parent cf2fd889a0
commit baa29cf340
11 changed files with 198 additions and 14 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.72",
"version": "0.20.74-rc100",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.20.72",
"version": "0.20.74-rc100",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.73",
"version": "0.20.74-rc100",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -3,7 +3,14 @@ import { chains, envs } from '../config/index.js';
import type { networkCodes } from '../constants/index.js';
import Unit from '../Unit/index.js';
import { ReferralSystem } from '../services/ReferralSystem/index.js';
import type { SupportedChainId, DeepPartial, VerboseUnitConfig, KnownEnv, EnvConfig, AggregatedAssets } from '../types.js';
import type {
SupportedChainId,
DeepPartial,
VerboseUnitConfig,
KnownEnv,
EnvConfig,
AggregatedAssets
} from '../types.js';
import { isValidChainId } from '../utils/index.js';
import { simpleFetch } from 'simple-typed-fetch';
import Bridge from './bridge/index.js';
@@ -60,6 +67,9 @@ export default class Orion {
},
indexer: {
api: networkConfig.api + networkConfig.services.indexer?.http,
},
frontage: {
api: networkConfig.api + networkConfig.services.frontage.http,
}
},
};
@@ -118,7 +128,7 @@ export default class Orion {
if (!unit) {
throw new Error(
`Invalid network code: ${networkCodeOrChainId}. ` +
`Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`);
`Available network codes: ${this.unitsArray.map((u) => u.networkCode).join(', ')}`);
}
return unit;
}
@@ -156,7 +166,7 @@ export default class Orion {
const networks = chainIds.map((chainId) => chains[chainId]?.label).join(', ');
console.error(
`Asset found in Aggregator, but not in BlockchainService (base): ${baseAsset} (${pair}).` +
` Networks: ${networks}`
` Networks: ${networks}`
);
} else {
tradableAggregatedAssets[baseAsset] = aggregatedBaseAsset;
@@ -166,7 +176,7 @@ export default class Orion {
const networks = chainIds.map((chainId) => chains[chainId]?.label).join(', ');
console.error(
`Asset found in Aggregator, but not in BlockchainService (quote): ${quoteAsset} (${pair}).` +
` Networks: ${networks}`
` Networks: ${networks}`
);
} else {
tradableAggregatedAssets[quoteAsset] = aggregatedQuoteAsset;
@@ -178,11 +188,11 @@ export default class Orion {
async getPairs(...params: Parameters<Unit['aggregator']['getPairsList']>) {
const result: Partial<
Record<
string,
SupportedChainId[]
>
> = {};
Record<
string,
SupportedChainId[]
>
> = {};
await Promise.all(this.unitsArray.map(async (unit) => {
const pairs = await simpleFetch(unit.aggregator.getPairsList)(...params);

View File

@@ -2,6 +2,8 @@ import { JsonRpcProvider } from 'ethers';
import { Aggregator } from '../services/Aggregator';
import { BlockchainService } from '../services/BlockchainService';
import { PriceFeed } from '../services/PriceFeed';
import { IndexerService } from '../services/Indexer';
import { FrontageService } from '../services/Frontage';
import type {
KnownEnv,
SupportedChainId,
@@ -10,8 +12,7 @@ import type {
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
@@ -29,6 +30,8 @@ export default class Unit {
public readonly indexer: IndexerService | undefined;
public readonly frontage: FrontageService | undefined;
public readonly aggregator: Aggregator;
public readonly pmm: Pmm;
@@ -88,6 +91,9 @@ export default class Unit {
indexer: {
api: networkConfig.api + networkConfig.services.indexer?.http,
},
frontage: {
api: networkConfig.api + networkConfig.services.frontage?.http,
},
},
};
} else {
@@ -115,6 +121,9 @@ export default class Unit {
intNetwork
)
: undefined;
this.frontage = new FrontageService(
this.config.services.frontage.api,
);
this.aggregator = new Aggregator(
this.config.services.aggregator.http,
this.config.services.aggregator.ws,

View File

@@ -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/"
}
}
}
@@ -185,6 +212,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
},
"liquidityMigratorAddress": "0x01b10dds12478C88A5E18e2707E729906bC25CfF6"
@@ -204,6 +234,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
},
@@ -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/"
}
}
}
@@ -299,6 +344,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/"
}
}
}
@@ -466,6 +538,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
},
@@ -484,6 +559,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
}
@@ -507,6 +585,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
},
"liquidityMigratorAddress": "0x23a1820a47BcD022E29f6058a5FD224242F50D1A"
@@ -526,6 +607,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
},
@@ -544,6 +628,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
},
@@ -562,6 +649,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
},
@@ -580,6 +670,9 @@
},
"indexer": {
"http": "/orion-indexer/"
},
"frontage": {
"http": "/frontage/"
}
}
}

View File

@@ -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(),

View File

@@ -0,0 +1,26 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import { aggregatedMetricsSchema } from './schemas';
export class FrontageService {
private readonly apiUrl: string;
get api() {
return this.apiUrl;
}
constructor(apiUrl: string) {
this.apiUrl = apiUrl;
this.getAggregatedMetrics = this.getAggregatedMetrics.bind(this);
}
readonly getAggregatedMetrics = () => {
const url = new URL(`${this.apiUrl}/api/v1/metrics/aggregated`);
return fetchWithValidation(
url.toString(),
aggregatedMetricsSchema,
);
};
}
export * as schemas from './schemas/index.js';

View File

@@ -0,0 +1,29 @@
import { z } from 'zod';
import { networkCodes } from '../../../constants';
const volumeInfoSchema = z.object({
volume24: z.number(),
volume7d: z.number(),
volumeAllTime: z.number(),
networks: z.array(z.enum(networkCodes)),
})
const supplyMetricsSchema = z.object({
circulatingSupply: z.number(),
totalSupply: z.number(),
maxSupply: z.number(),
})
const governanceMetricsSchema = z.object({
totalLumiaLocked: z.number(),
totalVeLumia: z.number(),
totalVeLumiaInVoting: z.number(),
weeklyLumiaReward: z.number(),
networks: z.array(z.enum(networkCodes)),
})
export const aggregatedMetricsSchema = z.object({
volumeInfo: volumeInfoSchema,
supplyMetrics: supplyMetricsSchema,
governanceMetrics: governanceMetricsSchema
});

View File

@@ -0,0 +1,9 @@
import { z } from 'zod';
export const errorSchema = z.object({
error: z.object({
code: z.number(),
reason: z.string(),
}),
timestamp: z.string(),
});

View File

@@ -0,0 +1,2 @@
export * from './aggregated-metrics-schema';
export * from './error-schema';

View File

@@ -264,6 +264,9 @@ export type VerboseUnitConfig = {
// http://10.23.5.11:3003/,
// https://price-feed:3003/
}
frontage: {
api: string
}
indexer?: {
api: string
// For example: