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

OP-5247: frontage service #252

Merged
merged 28 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
57474d2
feat: added frontage service
cheshirrrcat Mar 29, 2024
bfa4cc3
feat: added two methods for tickers
cheshirrrcat Mar 29, 2024
8c27f33
feat: frontage was added to Unit
cheshirrrcat Mar 29, 2024
252b7fc
feat: types updates
cheshirrrcat Mar 29, 2024
ba4d7d1
feat: types update
cheshirrrcat Mar 29, 2024
8bd6224
feat: small fix for getTickers method
cheshirrrcat Mar 29, 2024
12533db
fix: fix for frontage config
cheshirrrcat Mar 29, 2024
acdd788
fix: fix for frontage config
cheshirrrcat Mar 29, 2024
14035cf
fix: fix for frontage config
cheshirrrcat Mar 29, 2024
d024d47
fix: fix frontage config
cheshirrrcat Mar 29, 2024
e275a4d
fix: fix frontage config
cheshirrrcat Mar 29, 2024
f8e4b64
Merge branch 'refs/heads/main' into OP-5247-frontend-optimization
cheshirrrcat Apr 17, 2024
9705ce0
feat: updated new changes from frontage
cheshirrrcat Apr 17, 2024
e3fc4ac
feat: tickers schema was updated
cheshirrrcat Apr 25, 2024
704bcbc
feat: tickers schema was updated
cheshirrrcat Apr 25, 2024
54e0ab8
feat: tickers schema was updated
cheshirrrcat Apr 25, 2024
ffe714d
feat: getTickers method was updated
cheshirrrcat Apr 25, 2024
e258cb1
Merge branch 'refs/heads/main' into OP-5247-frontend-optimization
cheshirrrcat May 6, 2024
f9f849a
feat: tickers schema was updated
cheshirrrcat May 6, 2024
3a12373
feat: tickers schema was updated
cheshirrrcat May 6, 2024
1521032
feat: Frontage service context define was removed
cheshirrrcat May 13, 2024
a8f1682
feat: Frontage service code review
cheshirrrcat May 13, 2024
d676d59
feat: Frontage service code review
cheshirrrcat May 13, 2024
04d187f
feat: Frontage service code review
cheshirrrcat May 13, 2024
2936b19
feat: Frontage service code review
cheshirrrcat May 14, 2024
7877aba
feat: switched to URL constructor
cheshirrrcat May 14, 2024
4d4030c
feat: switched to URL constructor
cheshirrrcat May 14, 2024
d80599e
feat: switched to URL constructor
cheshirrrcat May 14, 2024
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.86",
"version": "0.20.79-rc23",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",
Expand Down
10 changes: 8 additions & 2 deletions src/Orion/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { merge } from 'merge-anything';
import { chains, envs } from '../config/index.js';
import { chains, envs } from '../config';
import type { networkCodes } from '../constants/index.js';
import Unit from '../Unit/index.js';
import { ReferralSystem } from '../services/ReferralSystem/index.js';
import { ReferralSystem } from '../services/ReferralSystem';
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';

export default class Orion {
public readonly env?: string;
Expand All @@ -17,6 +18,8 @@ export default class Orion {

public readonly bridge: Bridge;

public readonly frontage: Frontage;

// TODO: get tradable assets (aggregated)

// TODO: get tradable pairs (aggregated)
Expand All @@ -40,6 +43,7 @@ export default class Orion {
config = {
analyticsAPI: envConfig?.analyticsAPI,
referralAPI: envConfig.referralAPI,
frontageAPI: envConfig.frontageAPI,
networks: Object.entries(envConfig.networks).map(([chainId, networkConfig]) => {
if (!isValidChainId(chainId)) throw new Error(`Invalid chainId: ${chainId}`);
const chainConfig = chains[chainId];
Expand Down Expand Up @@ -107,6 +111,8 @@ export default class Orion {
this.bridge = new Bridge(
this.unitsArray,
);

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

get unitsArray() {
Expand Down
4 changes: 2 additions & 2 deletions src/Unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +90,7 @@ export default class Unit {
},
indexer: {
api: networkConfig.api + networkConfig.services.indexer?.http,
},
}
},
};
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/config/envs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"production": {
"referralAPI": "https://trade.orion.xyz/referral-api",
"frontageAPI": "https://trade.orion.xyz/frontage",
"networks": {
"1": {
"api": "https://trade.orion.xyz/eth-mainnet",
Expand Down Expand Up @@ -205,6 +206,7 @@
},
"testing": {
"referralAPI": "https://testing.orion.xyz/referral-api",
"frontageAPI": "https://testing.orion.xyz/frontage",
"networks": {
"97": {
"api": "https://testing.orion.xyz/bsc-testnet",
Expand Down Expand Up @@ -319,6 +321,7 @@
},
"staging": {
"referralAPI": "https://staging.orion.xyz/referral-api",
"frontageAPI": "https://staging.orion.xyz/frontage",
"networks": {
"1": {
"api": "https://staging.orion.xyz/eth-mainnet",
Expand Down Expand Up @@ -522,6 +525,7 @@
},
"experimental": {
"referralAPI": "https://testing.orion.xyz/referral-api",
"frontageAPI": "https://testing.orion.xyz/frontage",
"networks": {
"97": {
"api": "https://dn-dev.orion.xyz/bsc-testnet",
Expand Down Expand Up @@ -563,6 +567,7 @@
},
"kucoin-production": {
"referralAPI": "https://trade.orion.xyz/referral-api",
"frontageAPI": "https://trade.orion.xyz/frontage",
"networks": {
"1": {
"api": "https://trade.orion.xyz/eth-mainnet",
Expand Down
3 changes: 2 additions & 1 deletion src/config/schemas/pureEnvSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const pureEnvNetworksSchema = z.object({
}),
indexer: z.object({
http: z.string(),
}).optional(),
}).optional()
}),
rpc: z.string().optional(),
liquidityMigratorAddress: z.string().optional(),
Expand All @@ -25,6 +25,7 @@ export const pureEnvNetworksSchema = z.object({
export const pureEnvPayloadSchema = z.object({
analyticsAPI: z.string().url().optional(),
referralAPI: z.string().url(),
frontageAPI: z.string().url(),
networks: z.record(
z.nativeEnum(SupportedChainId),
pureEnvNetworksSchema
Expand Down
78 changes: 78 additions & 0 deletions src/services/Frontage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import { tickersSchema } from './schemas';
import type { TickersBaseSearchParams, TickersCategories } from '../../types';

export class Frontage {
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();

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

export * as schemas from './schemas/index.js';
1 change: 1 addition & 0 deletions src/services/Frontage/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './tickers-schema';
13 changes: 13 additions & 0 deletions src/services/Frontage/schemas/tickers-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { z } from 'zod';
import { SupportedChainId } from '../../../types';

export const tickerSchema = z.object({
pair: z.string(),
volume24: z.number(),
change24: z.number(),
lastPrice: z.number(),
pricePrecision: z.number(),
networks: z.array(z.nativeEnum(SupportedChainId)),
});

export const tickersSchema = z.array(tickerSchema);
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
20 changes: 20 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type subOrderStatuses from './constants/subOrderStatuses.js';
import type positionStatuses from './constants/positionStatuses.js';
import type { knownEnvs } from './config/schemas';
import type getHistory from './Orion/bridge/getHistory.js';
import type { networkCodes } from './constants';

export type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
Expand Down Expand Up @@ -284,6 +285,7 @@ export type Json = string | number | boolean | null | Json[] | { [key: string]:
export type EnvConfig = {
analyticsAPI: string | undefined
referralAPI: string
frontageAPI: string
networks: Partial<
Record<
SupportedChainId,
Expand Down Expand Up @@ -461,3 +463,21 @@ export type AtomicSwap = Partial<
}

export type OrderSource = 'TERMINAL_MARKET' | 'TERMINAL_LIMIT' | 'SWAP_UI' | 'WIDGET';

// Frontage
export type NetworkCode = typeof networkCodes[number];

export type TickersCategories = 'FAVORITES' | 'USD' | 'ORN' | 'NATIVE' | 'ALTS';

export type TickersSortBy = 'PRICE' | 'CHANGE' | 'VOLUME';

export type TickersSortType = 'ASCENDING' | 'DESCENDING';

export type TickersBaseSearchParams = {
currentNetwork?: NetworkCode
targetNetwork?: NetworkCode
sortBy?: TickersSortBy
sortType?: TickersSortType
offset?: number
limit?: number
}
Loading