Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.22.15",
"version": "0.22.15-rc1002",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
Expand Down Expand Up @@ -102,7 +102,7 @@
"merge-anything": "^5.1.7",
"neverthrow": "^6.0.0",
"patch-package": "^8.0.0",
"simple-typed-fetch": "0.2.3",
"simple-typed-fetch": "0.2.5",
"stream-browserify": "^3.0.0",
"tiny-invariant": "^1.3.1",
"ts-is-present": "^1.2.2",
Expand Down
34 changes: 20 additions & 14 deletions src/Orion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import { chains, envs } from '../config';
import type { networkCodes } from '../constants/index.js';
import Unit from '../Unit/index.js';
import { ReferralSystem } from '../services/ReferralSystem';
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';
import { Frontage } from '../services/Frontage';
import { FrontageService } from '../services/Frontage';

export default class Orion {
public readonly env?: string;
Expand All @@ -16,9 +23,9 @@ export default class Orion {

public readonly referralSystem: ReferralSystem;

public readonly bridge: Bridge;
public readonly frontage: FrontageService;

public readonly frontage: Frontage;
public readonly bridge: Bridge;

// TODO: get tradable assets (aggregated)

Expand Down Expand Up @@ -88,6 +95,7 @@ export default class Orion {
}

this.referralSystem = new ReferralSystem(config.referralAPI);
this.frontage = new FrontageService(config.frontageAPI);

this.units = Object.entries(config.networks)
.reduce<Partial<Record<SupportedChainId, Unit>>>((acc, [chainId, networkConfig]) => {
Expand All @@ -111,8 +119,6 @@ export default class Orion {
this.bridge = new Bridge(
this.unitsArray,
);

this.frontage = new Frontage(config.frontageAPI);
}

get unitsArray() {
Expand All @@ -129,7 +135,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;
}
Expand Down Expand Up @@ -167,7 +173,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;
Expand All @@ -177,7 +183,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;
Expand All @@ -189,11 +195,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);
Expand Down
2 changes: 1 addition & 1 deletion src/Unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 type {
KnownEnv,
SupportedChainId,
Expand All @@ -10,7 +11,6 @@ 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';

type KnownConfig = {
Expand Down
13 changes: 13 additions & 0 deletions src/config/chains.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,18 @@
"WETH": "0x4200000000000000000000000000000000000006",
"curveRegistry": ""
}
},
"994873017": {
"chainId": "994873017",
"label": "Lumia",
"shortName": "Lumia",
"code": "lumia",
"baseCurrencyName": "LUMIA",
"rpc": "https://mainnet-rpc.lumia.org/",
"explorer": "https://explorer.lumia.org",
"contracts": {
"WETH": "",
"curveRegistry": ""
}
}
}
18 changes: 18 additions & 0 deletions src/config/envs.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@
"http": "/orion-indexer/"
}
}
},
"994873017": {
"api": "https://trade.orion.xyz/lumia-mainnet",
"services": {
"aggregator": {
"http": "/backend",
"ws": "/v1"
},
"blockchain": {
"http": ""
},
"priceFeed": {
"all": "/price-feed"
},
"indexer": {
"http": "/orion-indexer/"
}
}
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsonChains from './chains.json' assert { type: 'json' };
import jsonEnvs from './envs.json' assert { type: 'json' };
import { pureEnvSchema, pureChainInfoSchema } from './schemas/index.js';
import { pureEnvSchema, pureChainInfoSchema } from './schemas';

const chains = pureChainInfoSchema.parse(jsonChains);
const envs = pureEnvSchema.parse(jsonEnvs);
Expand Down
1 change: 1 addition & 0 deletions src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export const productionChains = [
SupportedChainId.LINEA,
SupportedChainId.AVAX,
SupportedChainId.BASE,
SupportedChainId.LUMIA,
];
2 changes: 1 addition & 1 deletion src/services/BlockchainService/schemas/infoSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const infoSchema = z.object({
swapExecutorContractAddress: z.string(),
libValidatorContractAddress: z.string().optional(),
exchangeContractAddress: z.string(),
spvContractAddress: z.string(),
spvContractAddress: z.string().optional(),
oracleContractAddress: z.string(),
matcherAddress: z.string(),
orderFeePercent: z.number(),
Expand Down
70 changes: 7 additions & 63 deletions src/services/Frontage/index.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,20 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import { tickersSchema } from './schemas';
import type { TickersBaseSearchParams, TickersCategories } from '../../types';
import { aggregatedMetricsSchema } from './schemas';

export class Frontage {
export class FrontageService {
private readonly apiUrl: string;

constructor(apiUrl: string) {
this.apiUrl = apiUrl;
}

searchTickers = ({
searchValue,
currentNetwork,
targetNetwork,
sortBy,
sortType,
offset,
limit,
}: { searchValue: string } & TickersBaseSearchParams) => {
const url = new URL(this.apiUrl);
const params = new URLSearchParams();

params.set('searchValue', encodeURIComponent(searchValue));
if (currentNetwork !== undefined) params.set('currentNetwork', encodeURIComponent(currentNetwork).toUpperCase());
if (targetNetwork !== undefined) params.set('targetNetwork', encodeURIComponent(targetNetwork).toUpperCase());
if (sortBy !== undefined) params.set('sortBy', encodeURIComponent(sortBy));
if (sortType !== undefined) params.set('sortType', encodeURIComponent(sortType));
if (offset !== undefined) params.set('offset', offset.toString());
if (limit !== undefined) params.set('limit', limit.toString());

url.pathname += '/api/v1/tickers/search';
url.search = params.toString();

return fetchWithValidation(
url.toString(),
tickersSchema
);
};

getTickers = ({
category,
currentNetwork,
targetNetwork,
sortBy,
sortType,
offset,
limit,
tickers,
}: { category: TickersCategories, tickers?: string } & TickersBaseSearchParams) => {
const url = new URL(this.apiUrl);
const params = new URLSearchParams();

if (category === 'FAVORITES' && tickers !== undefined) params.set('tickers', tickers);
if (category !== 'FAVORITES') params.set('category', category);
if (currentNetwork !== undefined) params.set('currentNetwork', encodeURIComponent(currentNetwork).toUpperCase());
if (targetNetwork !== undefined) params.set('targetNetwork', encodeURIComponent(targetNetwork).toUpperCase());
if (sortBy !== undefined) params.set('sortBy', encodeURIComponent(sortBy));
if (sortType !== undefined) params.set('sortType', encodeURIComponent(sortType));
if (offset !== undefined) params.set('offset', offset.toString());
if (limit !== undefined) params.set('limit', limit.toString());

if (category === 'FAVORITES' && tickers !== undefined) {
url.pathname += '/api/v1/tickers/get/favourites';
} else {
url.pathname += '/api/v1/tickers/get/category';
}

url.search = params.toString();
this.getAggregatedMetrics = this.getAggregatedMetrics.bind(this);
}

readonly getAggregatedMetrics = () => {
const url = new URL(`${this.apiUrl}/api/v1/metrics/aggregated`);
return fetchWithValidation(
url.toString(),
tickersSchema
aggregatedMetricsSchema,
);
};
}
Expand Down
29 changes: 29 additions & 0 deletions src/services/Frontage/schemas/aggregated-metrics-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from 'zod';
import uppercasedNetworkCodes from '../../../constants/uppercasedNetworkCodes';

const volumeInfoSchema = z.object({
volume24: z.number(),
volume7d: z.number(),
volumeAllTime: z.number(),
networks: z.array(z.enum(uppercasedNetworkCodes)),
})

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(uppercasedNetworkCodes)),
})

export const aggregatedMetricsSchema = z.object({
volumeInfo: volumeInfoSchema,
supplyMetrics: supplyMetricsSchema,
governanceMetrics: governanceMetricsSchema
});
9 changes: 9 additions & 0 deletions src/services/Frontage/schemas/error-schema.ts
Original file line number Diff line number Diff line change
@@ -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(),
});
2 changes: 1 addition & 1 deletion src/services/Frontage/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './tickers-schema';
export * from './aggregated-metrics-schema';
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export enum SupportedChainId {
ARBITRUM = '42161',
AVAX = '43114',
LINEA = '59144',
LUMIA = '994873017',

BSC_TESTNET = '97',
SEPOLIA = '11155111',
Expand Down
Loading