@eyettea/zeta-backend 0.0.1-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/types/api/index.d.ts +9 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/types.d.ts +19 -0
- package/dist/types/api/types.d.ts.map +1 -0
- package/dist/types/app.d.ts +945 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/config/database.d.ts +17 -0
- package/dist/types/config/database.d.ts.map +1 -0
- package/dist/types/config/env.d.ts +20 -0
- package/dist/types/config/env.d.ts.map +1 -0
- package/dist/types/database/aggregates.d.ts +14 -0
- package/dist/types/database/aggregates.d.ts.map +1 -0
- package/dist/types/database/clmmTicks.d.ts +9 -0
- package/dist/types/database/clmmTicks.d.ts.map +1 -0
- package/dist/types/database/liquidityTicks.d.ts +7 -0
- package/dist/types/database/liquidityTicks.d.ts.map +1 -0
- package/dist/types/database/mints.d.ts +18 -0
- package/dist/types/database/mints.d.ts.map +1 -0
- package/dist/types/database/poolEvents.d.ts +37 -0
- package/dist/types/database/poolEvents.d.ts.map +1 -0
- package/dist/types/database/pools.d.ts +47 -0
- package/dist/types/database/pools.d.ts.map +1 -0
- package/dist/types/database/priceTicks.d.ts +7 -0
- package/dist/types/database/priceTicks.d.ts.map +1 -0
- package/dist/types/database/schemas.d.ts +134 -0
- package/dist/types/database/schemas.d.ts.map +1 -0
- package/dist/types/database/types.d.ts +114 -0
- package/dist/types/database/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/lib/errors.d.ts +8 -0
- package/dist/types/lib/errors.d.ts.map +1 -0
- package/dist/types/lib/logger.d.ts +2 -0
- package/dist/types/lib/logger.d.ts.map +1 -0
- package/dist/types/lib/validation.d.ts +3 -0
- package/dist/types/lib/validation.d.ts.map +1 -0
- package/dist/types/routes/compute.d.ts +103 -0
- package/dist/types/routes/compute.d.ts.map +1 -0
- package/dist/types/routes/ohlcv.d.ts +64 -0
- package/dist/types/routes/ohlcv.d.ts.map +1 -0
- package/dist/types/routes/pools.d.ts +305 -0
- package/dist/types/routes/pools.d.ts.map +1 -0
- package/dist/types/routes/response.d.ts +26 -0
- package/dist/types/routes/response.d.ts.map +1 -0
- package/dist/types/routes/websocket.d.ts +42 -0
- package/dist/types/routes/websocket.d.ts.map +1 -0
- package/dist/types/services/Services.d.ts +21 -0
- package/dist/types/services/Services.d.ts.map +1 -0
- package/dist/types/services/computeService.d.ts +103 -0
- package/dist/types/services/computeService.d.ts.map +1 -0
- package/dist/types/services/poolEventsHandler.d.ts +26 -0
- package/dist/types/services/poolEventsHandler.d.ts.map +1 -0
- package/dist/types/services/poolEventsSubscriptionService.d.ts +16 -0
- package/dist/types/services/poolEventsSubscriptionService.d.ts.map +1 -0
- package/dist/types/services/poolService.d.ts +140 -0
- package/dist/types/services/poolService.d.ts.map +1 -0
- package/dist/types/services/poolStateWebsocketService.d.ts +13 -0
- package/dist/types/services/poolStateWebsocketService.d.ts.map +1 -0
- package/dist/types/services/poolStatsService.d.ts +53 -0
- package/dist/types/services/poolStatsService.d.ts.map +1 -0
- package/dist/types/services/priceService.d.ts +36 -0
- package/dist/types/services/priceService.d.ts.map +1 -0
- package/dist/types/utils/period.d.ts +8 -0
- package/dist/types/utils/period.d.ts.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { Zeta } from '@h0ngcha0/typescript-sdk';
|
|
2
|
+
import { type SqlClient } from '../config/database';
|
|
3
|
+
import type { TokenInfo } from '@alephium/token-list';
|
|
4
|
+
import type { PriceService } from './priceService';
|
|
5
|
+
import type { PoolStatsService, PoolStatsCalculation } from './poolStatsService';
|
|
6
|
+
import type { ClmmPoolTypes } from '@h0ngcha0/typescript-sdk';
|
|
7
|
+
import type { PoolEvent, PoolRow, PoolEventCounterRow, PoolFactoryEventCounterRow } from '../database/types';
|
|
8
|
+
import type { ClmmPosition } from '../api/types';
|
|
9
|
+
import Decimal from 'decimal.js';
|
|
10
|
+
export type PoolStatsPeriod = PoolStatsCalculation;
|
|
11
|
+
export interface StandardPoolWithStats {
|
|
12
|
+
type: 'Standard';
|
|
13
|
+
poolId: string;
|
|
14
|
+
reserve0: string;
|
|
15
|
+
reserve1: string;
|
|
16
|
+
totalSupply: string;
|
|
17
|
+
token0Info: TokenInfo;
|
|
18
|
+
token1Info: TokenInfo;
|
|
19
|
+
feeRate: string;
|
|
20
|
+
tvl: string;
|
|
21
|
+
openTime: string;
|
|
22
|
+
day: PoolStatsPeriod;
|
|
23
|
+
week: PoolStatsPeriod;
|
|
24
|
+
month: PoolStatsPeriod;
|
|
25
|
+
}
|
|
26
|
+
export interface ConcentratedPoolWithStats {
|
|
27
|
+
type: 'Concentrated';
|
|
28
|
+
poolId: string;
|
|
29
|
+
token0Info: TokenInfo;
|
|
30
|
+
token1Info: TokenInfo;
|
|
31
|
+
liquidity: string;
|
|
32
|
+
tradingFee: string;
|
|
33
|
+
protocolFee: string;
|
|
34
|
+
sqrtPriceX96: string;
|
|
35
|
+
tick: string;
|
|
36
|
+
tickSpacing: string;
|
|
37
|
+
configIndex: string;
|
|
38
|
+
feeRate: string;
|
|
39
|
+
tvl: string;
|
|
40
|
+
openTime: string;
|
|
41
|
+
day: PoolStatsPeriod;
|
|
42
|
+
week: PoolStatsPeriod;
|
|
43
|
+
month: PoolStatsPeriod;
|
|
44
|
+
}
|
|
45
|
+
export type PoolWithStats = StandardPoolWithStats | ConcentratedPoolWithStats;
|
|
46
|
+
export declare const PoolType: {
|
|
47
|
+
readonly Standard: "standard";
|
|
48
|
+
readonly Concentrated: "concentrated";
|
|
49
|
+
readonly All: "all";
|
|
50
|
+
};
|
|
51
|
+
export type PoolType = (typeof PoolType)[keyof typeof PoolType];
|
|
52
|
+
export declare const PoolSortType: {
|
|
53
|
+
readonly Desc: "desc";
|
|
54
|
+
readonly Asc: "asc";
|
|
55
|
+
};
|
|
56
|
+
export type PoolSortType = (typeof PoolSortType)[keyof typeof PoolSortType];
|
|
57
|
+
export type PoolRecord = PoolRow;
|
|
58
|
+
export type PoolEventCounterRecord = PoolEventCounterRow;
|
|
59
|
+
export type PoolFactoryEventCounterRecord = PoolFactoryEventCounterRow;
|
|
60
|
+
export interface ClmmTickRecord {
|
|
61
|
+
pool_id: string;
|
|
62
|
+
tick: bigint;
|
|
63
|
+
liquidity_gross: bigint;
|
|
64
|
+
liquidity_net: bigint;
|
|
65
|
+
}
|
|
66
|
+
export interface ClmmLiquidityRow {
|
|
67
|
+
tick: string;
|
|
68
|
+
sqrtPriceX96: string;
|
|
69
|
+
price: string;
|
|
70
|
+
liquidity: string;
|
|
71
|
+
}
|
|
72
|
+
export declare class PoolService {
|
|
73
|
+
private zeta;
|
|
74
|
+
private priceService;
|
|
75
|
+
private poolStatsService;
|
|
76
|
+
constructor(zeta: Zeta, priceService: PriceService, poolStatsService: PoolStatsService);
|
|
77
|
+
private getCpmmFeeRate;
|
|
78
|
+
private getClmmFeeRate;
|
|
79
|
+
private poolRecordToCpmmPoolWithStats;
|
|
80
|
+
private poolRecordToClmmPoolWithStats;
|
|
81
|
+
getPoolByTokenPairId(tokenPairId: string): Promise<StandardPoolWithStats | undefined>;
|
|
82
|
+
getPoolsByToken(token0Id: string, token1Id?: string, poolType?: PoolType, page?: number, pageSize?: number): Promise<{
|
|
83
|
+
pools: StandardPoolWithStats[];
|
|
84
|
+
total: number;
|
|
85
|
+
page: number;
|
|
86
|
+
pageSize: number;
|
|
87
|
+
totalPages: number;
|
|
88
|
+
}>;
|
|
89
|
+
getPoolByTokenPair(token0Id: string, token1Id: string): Promise<StandardPoolWithStats | undefined>;
|
|
90
|
+
getPoolsByIds(poolIds: string[]): Promise<PoolWithStats[]>;
|
|
91
|
+
getAllPools(page?: number, pageSize?: number, poolType?: PoolType, sortType?: PoolSortType): Promise<{
|
|
92
|
+
pools: PoolWithStats[];
|
|
93
|
+
total: number;
|
|
94
|
+
page: number;
|
|
95
|
+
pageSize: number;
|
|
96
|
+
totalPages: number;
|
|
97
|
+
}>;
|
|
98
|
+
recordPoolEvent(poolId: string, eventType: string, txId: string, blockHash: string, eventData: unknown, client?: SqlClient): Promise<void>;
|
|
99
|
+
recordMintEvent(poolId: string, mintEvent: ClmmPoolTypes.MintEvent, client?: SqlClient): Promise<void>;
|
|
100
|
+
recordBurnEvent(poolId: string, burnEvent: ClmmPoolTypes.BurnEvent, client?: SqlClient): Promise<void>;
|
|
101
|
+
getClmmPositions(candidates: string[], client?: SqlClient): Promise<ClmmPosition[]>;
|
|
102
|
+
recordPoolFactoryEvent(poolId: string, eventType: string, txId: string, blockHash: string, eventData: unknown, client?: SqlClient): Promise<void>;
|
|
103
|
+
getPoolEvents(poolId: string, client?: SqlClient): Promise<PoolEvent[]>;
|
|
104
|
+
getPoolEventCounter(poolId: string, client?: SqlClient): Promise<PoolEventCounterRecord | undefined>;
|
|
105
|
+
createPoolEventCounter(poolId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
106
|
+
updatePoolEventCounter(poolId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
107
|
+
applyClmmTickDeltas(poolId: string, deltas: Array<{
|
|
108
|
+
tick: bigint;
|
|
109
|
+
liquidityGrossDelta: bigint;
|
|
110
|
+
liquidityNetDelta: bigint;
|
|
111
|
+
}>): Promise<void>;
|
|
112
|
+
getClmmTicks(poolId: string): Promise<ClmmTickRecord[]>;
|
|
113
|
+
getPoolFactoryEventCounter(poolFactoryId: string, client?: SqlClient): Promise<PoolFactoryEventCounterRecord | undefined>;
|
|
114
|
+
createPoolFactoryEventCounter(poolFactoryId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
115
|
+
updatePoolFactoryEventCounter(poolFactoryId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
116
|
+
getPoolById(id: string): Promise<PoolRecord | undefined>;
|
|
117
|
+
getTokenInfos(pool: PoolRecord): Promise<{
|
|
118
|
+
token0: TokenInfo;
|
|
119
|
+
token1: TokenInfo;
|
|
120
|
+
}>;
|
|
121
|
+
buildClmmLiquidityRows(token0: TokenInfo, token1: TokenInfo, tickRows: ClmmTickRecord[]): ClmmLiquidityRow[];
|
|
122
|
+
upsertPool(params: {
|
|
123
|
+
id: string;
|
|
124
|
+
token0: string;
|
|
125
|
+
token1: string;
|
|
126
|
+
configIndex?: number;
|
|
127
|
+
poolType: 'standard' | 'concentrated';
|
|
128
|
+
}, client?: SqlClient): Promise<void>;
|
|
129
|
+
private calculateCpmmPoolTVL;
|
|
130
|
+
private calculateClmmPoolTVL;
|
|
131
|
+
computePoolReserves(poolRecord: PoolRecord): Promise<{
|
|
132
|
+
amount0: string;
|
|
133
|
+
amount1: string;
|
|
134
|
+
totalLiquidity: string;
|
|
135
|
+
}>;
|
|
136
|
+
private fetchClmmTokenReserves;
|
|
137
|
+
computePoolTVL(poolRecord: PoolRecord): Promise<Decimal>;
|
|
138
|
+
computePoolTVLById(poolId: string): Promise<string>;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=poolService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolService.d.ts","sourceRoot":"","sources":["../../../src/services/poolService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAiB,MAAM,0BAA0B,CAAC;AAEpE,OAAY,EAAqB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAwBjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,OAAO,KAAK,EACV,SAAS,EACT,OAAO,EACP,mBAAmB,EACnB,0BAA0B,EAC3B,MAAM,iBAAi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AAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAIxD,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,SAAS,CAAA;KAAE,CAAC;IAQxF,sBAAsB,CACpB,MAAM,EAAE,SAAS,EACjB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,cAAc,EAAE,GACzB,gBAAgB,EAAE;IAoBf,UAAU,CACd,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,EAAE,UAAU,GAAG,cAAc,CAAC;KACvC,EACD,MAAM,CAAC,EAAE,SAAS,GACjB,OAAO,CAAC,IAAI,CAAC;YAYF,oBAAoB;YAiCpB,oBAAoB;IAoC5B,mBAAmB,CACvB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;YAgC1D,sBAAsB;IAoC9B,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBxD,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ1D"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class PoolStateWebSocketService {
|
|
2
|
+
private static clients;
|
|
3
|
+
private static poolSubscriptions;
|
|
4
|
+
static addClient(clientId: string, send: (message: string) => void): void;
|
|
5
|
+
static removeClient(clientId: string): void;
|
|
6
|
+
static subscribeToClmmPool(clientId: string, poolId: string): Promise<void>;
|
|
7
|
+
static unsubscribeFromClmmPool(clientId: string, poolId: string): void;
|
|
8
|
+
static publishPoolState(poolId: string): Promise<void>;
|
|
9
|
+
private static removeSubscription;
|
|
10
|
+
private static buildPoolStateUpdate;
|
|
11
|
+
private static sendMessage;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=poolStateWebsocketService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolStateWebsocketService.d.ts","sourceRoot":"","sources":["../../../src/services/poolStateWebsocketService.ts"],"names":[],"mappings":"AAiBA,qBAAa,yBAAyB;IACpC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAsC;IAC5D,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAkC;IAElE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAQzE,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;WAY9B,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBjF,MAAM,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;WAQzD,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoB5D,OAAO,CAAC,MAAM,CAAC,kBAAkB;mBAUZ,oBAAoB;IA0BzC,OAAO,CAAC,MAAM,CAAC,WAAW;CAe3B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
export interface PoolStatsCalculation {
|
|
3
|
+
volume: string;
|
|
4
|
+
volumeQuote: string;
|
|
5
|
+
volumeFee: string;
|
|
6
|
+
apr: string;
|
|
7
|
+
feeApr: string;
|
|
8
|
+
priceMin: string;
|
|
9
|
+
priceMax: string;
|
|
10
|
+
rewardApr: string[];
|
|
11
|
+
tvl: string;
|
|
12
|
+
feeRate: string;
|
|
13
|
+
}
|
|
14
|
+
export interface OHLCVItem {
|
|
15
|
+
o: number;
|
|
16
|
+
h: number;
|
|
17
|
+
l: number;
|
|
18
|
+
c: number;
|
|
19
|
+
vBase: number;
|
|
20
|
+
vQuote: number;
|
|
21
|
+
unixTime: number;
|
|
22
|
+
}
|
|
23
|
+
export interface OHLVCResult {
|
|
24
|
+
type: string;
|
|
25
|
+
items: OHLCVItem[];
|
|
26
|
+
}
|
|
27
|
+
export interface OHLCVResponse {
|
|
28
|
+
success: boolean;
|
|
29
|
+
data: OHLVCResult;
|
|
30
|
+
}
|
|
31
|
+
export interface LiquidityLinePoint {
|
|
32
|
+
time: number;
|
|
33
|
+
amount0: number;
|
|
34
|
+
amount1: number;
|
|
35
|
+
}
|
|
36
|
+
export interface LiquidityLineData {
|
|
37
|
+
count: number;
|
|
38
|
+
line: LiquidityLinePoint[];
|
|
39
|
+
}
|
|
40
|
+
export declare class PoolStatsService {
|
|
41
|
+
constructor();
|
|
42
|
+
calculatePoolStats(poolId: string, periodType: 'day' | 'week' | 'month', currentTVL?: Decimal): Promise<PoolStatsCalculation>;
|
|
43
|
+
private getDefaultStats;
|
|
44
|
+
private getTimeRange;
|
|
45
|
+
private calculateFeeAPR;
|
|
46
|
+
private parseDecimalField;
|
|
47
|
+
private mapRowsToItems;
|
|
48
|
+
getOHLCV(poolId: string, intervalType: string, timeFrom: number, timeTo: number): Promise<OHLVCResult>;
|
|
49
|
+
getOHLCVForTokenPair(token0Id: string, token1Id: string, intervalType: string, timeFrom: number, timeTo: number): Promise<OHLVCResult>;
|
|
50
|
+
getLiquidityLineWithRange(tokenPairId: string, startTime: number, endTime: number): Promise<LiquidityLineData>;
|
|
51
|
+
getLiquidityLineByDays(tokenPairId: string, days: number): Promise<LiquidityLineData>;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=poolStatsService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolStatsService.d.ts","sourceRoot":"","sources":["../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AAC,eAAe;IAevB,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,eAAe;IAUvB,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,cAAc;IAYhB,QAAQ,CACZ,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC;IAgBjB,oBAAoB,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,WAAW,CAAC;IAsBjB,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC;IAkDvB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAK5F"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type Decimal from 'decimal.js';
|
|
2
|
+
import { type Zeta } from '@h0ngcha0/typescript-sdk';
|
|
3
|
+
export interface TokenPrice {
|
|
4
|
+
id: string;
|
|
5
|
+
symbol: string;
|
|
6
|
+
price: Decimal;
|
|
7
|
+
priceUSD: Decimal;
|
|
8
|
+
}
|
|
9
|
+
export declare class PriceService {
|
|
10
|
+
private readonly zeta;
|
|
11
|
+
private priceCache;
|
|
12
|
+
private readonly CACHE_DURATION;
|
|
13
|
+
constructor(zeta: Zeta);
|
|
14
|
+
private fetchTokenPrices;
|
|
15
|
+
getTokenPrice(symbol: string): Promise<Decimal | undefined>;
|
|
16
|
+
getTokenPricesFromSymbols(symbols: string[]): Promise<TokenPrice[]>;
|
|
17
|
+
getTokenPricesFromIds(tokenIds: string[]): Promise<TokenPrice[]>;
|
|
18
|
+
/**
|
|
19
|
+
* Calculate USD value for a token amount
|
|
20
|
+
*/
|
|
21
|
+
calculateUSDValue(symbol: string, amount: string, decimals: number): Promise<Decimal | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Calculate USD values for multiple token amounts
|
|
24
|
+
*/
|
|
25
|
+
calculateUSDValues(tokens: Array<{
|
|
26
|
+
symbol: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
decimals: number;
|
|
29
|
+
}>): Promise<Array<{
|
|
30
|
+
symbol: string;
|
|
31
|
+
amount: string;
|
|
32
|
+
usdValue: Decimal | undefined;
|
|
33
|
+
}>>;
|
|
34
|
+
private resolveTokenInfosBySymbols;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=priceService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceService.d.ts","sourceRoot":"","sources":["../../../src/services/priceService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AACtC,OAAO,EAAgB,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAInE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,OAAO,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,YAAY;IAIX,OAAO,CAAC,QAAQ,CAAC,IAAI;IAHjC,OAAO,CAAC,UAAU,CAA6E;IAC/F,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAU;gBAEZ,IAAI,EAAE,IAAI;YAEzB,gBAAgB;IA6CjB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAgB3D,yBAAyB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IA4BnE,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAgC7E;;OAEG;IACU,iBAAiB,CAC5B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;IAQ/B;;OAEG;IACU,kBAAkB,CAC7B,MAAM,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,GAClE,OAAO,CAAC,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;KAAE,CAAC,CAAC;YA2BtE,0BAA0B;CAazC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"period.d.ts","sourceRoot":"","sources":["../../../src/utils/period.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,UAAU,UAAU;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAUD,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE5D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@eyettea/zeta-backend",
|
|
3
|
+
"version": "0.0.1-rc.3",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"dev": "bun run --watch src/index.ts",
|
|
6
|
+
"build": "bun build src/index.ts --outdir dist --target=node",
|
|
7
|
+
"build:types": "tsc -p tsconfig.types.json && tsc-alias -p tsconfig.types.json",
|
|
8
|
+
"start": "bun run dist/index.js",
|
|
9
|
+
"lint": "eslint --max-warnings=0 . --ext .ts",
|
|
10
|
+
"lint:fix": "eslint --max-warnings=0 . --ext .ts --fix",
|
|
11
|
+
"format": "prettier --write .",
|
|
12
|
+
"format:check": "prettier --check .",
|
|
13
|
+
"typecheck": "tsc --noEmit",
|
|
14
|
+
"publish:package": "bun run build:types && npm publish --tag rc --access public"
|
|
15
|
+
},
|
|
16
|
+
"types": "dist/types/index.d.ts",
|
|
17
|
+
"files": ["dist/types"],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/types/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./api": {
|
|
23
|
+
"types": "./dist/types/api/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@elysiajs/cors": "^1.3.3",
|
|
28
|
+
"@elysiajs/swagger": "^1.3.1",
|
|
29
|
+
"@h0ngcha0/typescript-sdk": "0.0.1-rc.4",
|
|
30
|
+
"@sinclair/typebox": "^0.34.41",
|
|
31
|
+
"dotenv": "^17.0.0",
|
|
32
|
+
"elysia": "^1.3.5",
|
|
33
|
+
"postgres": "^3.4.7",
|
|
34
|
+
"zod": "^3.25.67"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.19.2",
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
39
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
40
|
+
"bun-types": "^1.2.17",
|
|
41
|
+
"eslint": "^8.56.0",
|
|
42
|
+
"eslint-config-prettier": "^9.1.0",
|
|
43
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
44
|
+
"prettier": "^3.2.5",
|
|
45
|
+
"tsc-alias": "^1.8.16",
|
|
46
|
+
"typescript": "^5.3.3"
|
|
47
|
+
}
|
|
48
|
+
}
|