@alephium/powfi-backend 0.0.1-rc.2
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 +22 -0
- package/dist/types/api/index.d.ts +14 -0
- package/dist/types/api/index.d.ts.map +1 -0
- package/dist/types/api/schemas.d.ts +8 -0
- package/dist/types/api/schemas.d.ts.map +1 -0
- package/dist/types/api/serializers.d.ts +7 -0
- package/dist/types/api/serializers.d.ts.map +1 -0
- package/dist/types/api/types.d.ts +91 -0
- package/dist/types/api/types.d.ts.map +1 -0
- package/dist/types/api/utils.d.ts +7 -0
- package/dist/types/api/utils.d.ts.map +1 -0
- package/dist/types/app.d.ts +1350 -0
- package/dist/types/app.d.ts.map +1 -0
- package/dist/types/common/types.d.ts +12 -0
- package/dist/types/common/types.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/cron.d.ts +54 -0
- package/dist/types/cron.d.ts.map +1 -0
- package/dist/types/database/addressUtils.d.ts +4 -0
- package/dist/types/database/addressUtils.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/clmmPositions.d.ts +28 -0
- package/dist/types/database/clmmPositions.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/cpmmPositions.d.ts +16 -0
- package/dist/types/database/cpmmPositions.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 +38 -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 +134 -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/error-codes.d.ts +12 -0
- package/dist/types/lib/error-codes.d.ts.map +1 -0
- package/dist/types/lib/errors.d.ts +109 -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/addresses.d.ts +115 -0
- package/dist/types/routes/addresses.d.ts.map +1 -0
- package/dist/types/routes/compute.d.ts +132 -0
- package/dist/types/routes/compute.d.ts.map +1 -0
- package/dist/types/routes/ohlcv.d.ts +76 -0
- package/dist/types/routes/ohlcv.d.ts.map +1 -0
- package/dist/types/routes/pools.d.ts +290 -0
- package/dist/types/routes/pools.d.ts.map +1 -0
- package/dist/types/routes/response.d.ts +83 -0
- package/dist/types/routes/response.d.ts.map +1 -0
- package/dist/types/routes/stats.d.ts +69 -0
- package/dist/types/routes/stats.d.ts.map +1 -0
- package/dist/types/routes/tokens.d.ts +71 -0
- package/dist/types/routes/tokens.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 +23 -0
- package/dist/types/services/Services.d.ts.map +1 -0
- package/dist/types/services/compute/computeService.d.ts +80 -0
- package/dist/types/services/compute/computeService.d.ts.map +1 -0
- package/dist/types/services/compute/computeServiceTypes.d.ts +29 -0
- package/dist/types/services/compute/computeServiceTypes.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/pool/poolEventsHandler.d.ts +27 -0
- package/dist/types/services/pool/poolEventsHandler.d.ts.map +1 -0
- package/dist/types/services/pool/poolEventsSubscriptionService.d.ts +18 -0
- package/dist/types/services/pool/poolEventsSubscriptionService.d.ts.map +1 -0
- package/dist/types/services/pool/poolService.d.ts +99 -0
- package/dist/types/services/pool/poolService.d.ts.map +1 -0
- package/dist/types/services/pool/poolServiceTypes.d.ts +53 -0
- package/dist/types/services/pool/poolServiceTypes.d.ts.map +1 -0
- package/dist/types/services/pool/poolStateService.d.ts +11 -0
- package/dist/types/services/pool/poolStateService.d.ts.map +1 -0
- package/dist/types/services/pool/poolStateWebsocketService.d.ts +13 -0
- package/dist/types/services/pool/poolStateWebsocketService.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 +153 -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 +66 -0
- package/dist/types/services/poolStatsService.d.ts.map +1 -0
- package/dist/types/services/price/priceService.d.ts +34 -0
- package/dist/types/services/price/priceService.d.ts.map +1 -0
- package/dist/types/services/price/priceServiceTypes.d.ts +8 -0
- package/dist/types/services/price/priceServiceTypes.d.ts.map +1 -0
- package/dist/types/services/priceService.d.ts +39 -0
- package/dist/types/services/priceService.d.ts.map +1 -0
- package/dist/types/services/stat/poolStatsService.d.ts +22 -0
- package/dist/types/services/stat/poolStatsService.d.ts.map +1 -0
- package/dist/types/services/stat/poolStatsServiceTypes.d.ts +35 -0
- package/dist/types/services/stat/poolStatsServiceTypes.d.ts.map +1 -0
- package/dist/types/utils/cacheUtil.d.ts +26 -0
- package/dist/types/utils/cacheUtil.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 +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeService.d.ts","sourceRoot":"","sources":["../../../../src/services/compute/computeService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,qBAAa,mBAAoB,SAAQ,KAAK;IAGnC,IAAI,CAAC,EAAE,MAAM;gBADpB,OAAO,EAAE,MAAM,EACR,IAAI,CAAC,EAAE,MAAM,YAAA;CAKvB;AAED,qBAAa,cAAc;IAEvB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,gBAAgB;gBAFhB,IAA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AU,EAAE,SAAS,CAAC;QACtB,UAAU,EAAE,SAAS,CAAC;QACtB,WAAW,EAAE,SAAS,CAAC;QACvB,UAAU,EAAE,OAAO,CAAC;KACrB,EACD,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB,MAAM;IAmCH,sBAAsB,CAAC,MAAM,EAAE;QACnC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;QAC/B,WAAW,EAAE,SAAS,CAAC;QACvB,YAAY,EAAE,SAAS,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC;QACvB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,QAAQ,EAAE,MAAM,CAAC;QACjB,cAAc,EAAE,MAAM,CAAC;QACvB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;KAC1B,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA+D/B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface TokenAmountWithPrice {
|
|
2
|
+
mint: string;
|
|
3
|
+
symbol: string;
|
|
4
|
+
amount: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
priceUSD?: string;
|
|
7
|
+
usdValue?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface SwapComputeResult {
|
|
10
|
+
swapType: 'BaseIn' | 'BaseOut';
|
|
11
|
+
inputMint: string;
|
|
12
|
+
inputAmount: string;
|
|
13
|
+
outputMint: string;
|
|
14
|
+
outputAmount: string;
|
|
15
|
+
otherAmountThreshold: string;
|
|
16
|
+
slippageBps: number;
|
|
17
|
+
priceImpactPct: number;
|
|
18
|
+
routePlan: Array<string>;
|
|
19
|
+
inputToken: TokenAmountWithPrice;
|
|
20
|
+
outputToken: TokenAmountWithPrice;
|
|
21
|
+
tradingFee?: string;
|
|
22
|
+
priceInfo?: {
|
|
23
|
+
inputPriceUSD: string;
|
|
24
|
+
outputPriceUSD: string;
|
|
25
|
+
inputUSDValue: string;
|
|
26
|
+
outputUSDValue: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=computeServiceTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeServiceTypes.d.ts","sourceRoot":"","sources":["../../../../src/services/compute/computeServiceTypes.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IACzB,UAAU,EAAE,oBAAoB,CAAC;IACjC,WAAW,EAAE,oBAAoB,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE;QACV,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;QACtB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Zeta, SwapDetails } from '@h0ngcha0/typescript-sdk';
|
|
2
|
+
import type { PriceService } from './priceService';
|
|
3
|
+
import type { TokenInfo } from '@alephium/token-list';
|
|
4
|
+
import { PoolType } from './poolService';
|
|
5
|
+
export interface TokenAmountWithPrice {
|
|
6
|
+
mint: string;
|
|
7
|
+
symbol: string;
|
|
8
|
+
amount: string;
|
|
9
|
+
decimals: number;
|
|
10
|
+
priceUSD?: string;
|
|
11
|
+
usdValue?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SwapBaseInParams {
|
|
14
|
+
inputMint: string;
|
|
15
|
+
outputMint: string;
|
|
16
|
+
amount: string;
|
|
17
|
+
slippageBps?: string;
|
|
18
|
+
poolType?: PoolType;
|
|
19
|
+
}
|
|
20
|
+
export interface SwapBaseOutParams {
|
|
21
|
+
inputMint: string;
|
|
22
|
+
outputMint: string;
|
|
23
|
+
amount: string;
|
|
24
|
+
slippageBps?: string;
|
|
25
|
+
poolType?: PoolType;
|
|
26
|
+
}
|
|
27
|
+
export interface SwapComputeResult {
|
|
28
|
+
swapType: 'BaseIn' | 'BaseOut';
|
|
29
|
+
inputMint: string;
|
|
30
|
+
inputAmount: string;
|
|
31
|
+
outputMint: string;
|
|
32
|
+
outputAmount: string;
|
|
33
|
+
otherAmountThreshold: string;
|
|
34
|
+
slippageBps: number;
|
|
35
|
+
priceImpactPct: number;
|
|
36
|
+
routePlan: any[];
|
|
37
|
+
inputToken: TokenAmountWithPrice;
|
|
38
|
+
outputToken: TokenAmountWithPrice;
|
|
39
|
+
priceInfo?: {
|
|
40
|
+
inputPriceUSD: string;
|
|
41
|
+
outputPriceUSD: string;
|
|
42
|
+
inputUSDValue: string;
|
|
43
|
+
outputUSDValue: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export declare class ComputeServiceError extends Error {
|
|
47
|
+
code?: string | undefined;
|
|
48
|
+
constructor(message: string, code?: string | undefined);
|
|
49
|
+
}
|
|
50
|
+
export declare class ComputeService {
|
|
51
|
+
private zeta;
|
|
52
|
+
private priceService;
|
|
53
|
+
constructor(zeta: Zeta, priceService: PriceService);
|
|
54
|
+
computeSwapBaseIn(params: SwapBaseInParams): Promise<SwapComputeResult>;
|
|
55
|
+
computeSwapBaseOut(params: SwapBaseOutParams): Promise<SwapComputeResult>;
|
|
56
|
+
parseSlippageBps(slippageBps?: string): number;
|
|
57
|
+
getTokenInfo(id: string): Promise<TokenInfo>;
|
|
58
|
+
getPoolState(inputTokenId: string, outputTokenId: string): Promise<import("@h0ngcha0/typescript-sdk").CpmmPoolContractState>;
|
|
59
|
+
convertSwapDetailsToResponse(swapDetails: SwapDetails, slippage: number): Promise<SwapComputeResult>;
|
|
60
|
+
computeClmmSwapBaseIn(params: {
|
|
61
|
+
inputMint: string;
|
|
62
|
+
outputMint: string;
|
|
63
|
+
amount: bigint;
|
|
64
|
+
slippage: number;
|
|
65
|
+
}): Promise<SwapComputeResult>;
|
|
66
|
+
computeClmmSwapBaseOut(params: {
|
|
67
|
+
inputMint: string;
|
|
68
|
+
outputMint: string;
|
|
69
|
+
amount: bigint;
|
|
70
|
+
slippage: number;
|
|
71
|
+
}): Promise<SwapComputeResult>;
|
|
72
|
+
applySlippage(value: bigint, slippageBps: number, direction: 'min' | 'max'): bigint;
|
|
73
|
+
getClmmSwapContext(inputMint: string, outputMint: string): Promise<{
|
|
74
|
+
inputToken: TokenInfo;
|
|
75
|
+
outputToken: TokenInfo;
|
|
76
|
+
token0Info: TokenInfo;
|
|
77
|
+
token1Info: TokenInfo;
|
|
78
|
+
zeroForOne: boolean;
|
|
79
|
+
configIndex: bigint;
|
|
80
|
+
}>;
|
|
81
|
+
calculateClmmPriceImpact(distribution: {
|
|
82
|
+
baseSqrtPriceX96: bigint;
|
|
83
|
+
sqrtPriceX96: bigint;
|
|
84
|
+
}, context: {
|
|
85
|
+
token0Info: TokenInfo;
|
|
86
|
+
token1Info: TokenInfo;
|
|
87
|
+
inputToken: TokenInfo;
|
|
88
|
+
outputToken: TokenInfo;
|
|
89
|
+
zeroForOne: boolean;
|
|
90
|
+
}, tokenInAmount: bigint, tokenOutAmount: bigint): number;
|
|
91
|
+
buildSwapComputeResult(params: {
|
|
92
|
+
swapType: 'BaseIn' | 'BaseOut';
|
|
93
|
+
tokenInInfo: TokenInfo;
|
|
94
|
+
tokenOutInfo: TokenInfo;
|
|
95
|
+
tokenInAmount: bigint;
|
|
96
|
+
tokenOutAmount: bigint;
|
|
97
|
+
otherAmountThreshold: bigint;
|
|
98
|
+
slippage: number;
|
|
99
|
+
priceImpactPct: number;
|
|
100
|
+
routePlan: any[];
|
|
101
|
+
}): Promise<SwapComputeResult>;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=computeService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeService.d.ts","sourceRoot":"","sources":["../../../src/services/computeService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAIzC,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAA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,EAAE,MAAM,CAAC;QACvB,SAAS,EAAE,GAAG,EAAE,CAAC;KAClB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA8D/B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PoolService } from './poolService';
|
|
2
|
+
import type { PoolRecord } from '../pool/poolServiceTypes';
|
|
3
|
+
import type { CpmmTokenPairTypes, ClmmPoolTypes } from '@h0ngcha0/typescript-sdk';
|
|
4
|
+
import type { PriceTickInsert, LiquidityTickInsert } from '../../database/types';
|
|
5
|
+
declare abstract class BasePoolEventsHandler {
|
|
6
|
+
protected storePriceData(priceData: PriceTickInsert): Promise<void>;
|
|
7
|
+
protected storeLiquidityData(liquidityData: LiquidityTickInsert): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare class StandardPoolEventsHandler extends BasePoolEventsHandler {
|
|
10
|
+
private poolService;
|
|
11
|
+
constructor(poolService: PoolService);
|
|
12
|
+
capturePriceFromSwap(tokenPairId: string, txId: string, swapData: CpmmTokenPairTypes.SwapEvent): Promise<void>;
|
|
13
|
+
captureLiquidityFromMint(tokenPairId: string, txId: string, mintEvent: CpmmTokenPairTypes.MintEvent): Promise<void>;
|
|
14
|
+
captureLiquidityFromBurn(tokenPairId: string, txId: string, burnEvent: CpmmTokenPairTypes.BurnEvent): Promise<void>;
|
|
15
|
+
calculatePriceFromSwap(swapData: CpmmTokenPairTypes.SwapEvent, poolRecord: PoolRecord, token0Decimals: number, token1Decimals: number): Promise<string>;
|
|
16
|
+
captureLiquidityFromEvent(tokenPairId: string, txId: string, event: CpmmTokenPairTypes.MintEvent | CpmmTokenPairTypes.BurnEvent): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export declare class ClmmPoolEventsHandler extends BasePoolEventsHandler {
|
|
19
|
+
private poolService;
|
|
20
|
+
constructor(poolService: PoolService);
|
|
21
|
+
capturePriceFromSwap(tokenPairId: string, txId: string, swapData: ClmmPoolTypes.SwapEvent): Promise<void>;
|
|
22
|
+
captureLiquidityFromMint(tokenPairId: string, txId: string, mintEvent: ClmmPoolTypes.MintEvent): Promise<void>;
|
|
23
|
+
captureLiquidityFromBurn(tokenPairId: string, txId: string, burnEvent: ClmmPoolTypes.BurnEvent): Promise<void>;
|
|
24
|
+
captureLiquidityFromEvent(poolId: string, txId: string, event: ClmmPoolTypes.MintEvent | ClmmPoolTypes.BurnEvent): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=poolEventsHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolEventsHandler.d.ts","sourceRoot":"","sources":["../../../../src/services/pool/poolEventsHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKlF,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAM5E,uBAAe,qBAAqB;cAClB,cAAc,CAAC,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;cAQzD,kBAAkB,CAAC,aAAa,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAOtF;AAED,qBAAa,yBAA0B,SAAQ,qBAAqB;IACtD,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAKtC,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kBAAkB,CAAC,SAAS,GACrC,OAAO,CAAC,IAAI,CAAC;IA6DV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,kBAAkB,CAAC,SAAS,GACtC,OAAO,CAAC,IAAI,CAAC;IAIV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,kBAAkB,CAAC,SAAS,GACtC,OAAO,CAAC,IAAI,CAAC;IAIV,sBAAsB,CAC1B,QAAQ,EAAE,kBAAkB,CAAC,SAAS,EACtC,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,MAAM,CAAC;IAmDZ,yBAAyB,CAC7B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,kBAAkB,CAAC,SAAS,GAAG,kBAAkB,CAAC,SAAS,GACjE,OAAO,CAAC,IAAI,CAAC;CA4DjB;AAGD,qBAAa,qBAAsB,SAAQ,qBAAqB;IAClD,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAItC,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,SAAS,GAChC,OAAO,CAAC,IAAI,CAAC;IA2DV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,CAAC,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,CAAC,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,yBAAyB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,GACvD,OAAO,CAAC,IAAI,CAAC;CA0EjB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Zeta } from '@h0ngcha0/typescript-sdk';
|
|
2
|
+
import type { PoolService } from './poolService';
|
|
3
|
+
import type { PoolStateService } from '../pool/poolStateService';
|
|
4
|
+
import type { StandardPoolEventsHandler, ClmmPoolEventsHandler } from './poolEventsHandler';
|
|
5
|
+
export declare class PoolEventsSubscriptionService {
|
|
6
|
+
private zeta;
|
|
7
|
+
private poolService;
|
|
8
|
+
private poolStateService;
|
|
9
|
+
private standardPoolEventsHandler;
|
|
10
|
+
private clmmPoolEventsHandler;
|
|
11
|
+
private isSubscribed;
|
|
12
|
+
private readonly standard;
|
|
13
|
+
private readonly concentrated;
|
|
14
|
+
constructor(zeta: Zeta, poolService: PoolService, poolStateService: PoolStateService, standardPoolEventsHandler: StandardPoolEventsHandler, clmmPoolEventsHandler: ClmmPoolEventsHandler);
|
|
15
|
+
startSubscription(): Promise<void>;
|
|
16
|
+
stopSubscription(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=poolEventsSubscriptionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolEventsSubscriptionService.d.ts","sourceRoot":"","sources":["../../../../src/services/pool/poolEventsSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,IAAI,EAGL,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAGxE,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAsZ5F,qBAAa,6BAA6B;IAMtC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,yBAAyB;IACjC,OAAO,CAAC,qBAAqB;IAT/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;gBAGtD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,yBAAyB,EAAE,yBAAyB,EACpD,qBAAqB,EAAE,qBAAqB;IAehD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC,gBAAgB,IAAI,IAAI;CAWzB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 '../price/priceService';
|
|
5
|
+
import type { PoolStatsService } from '../stat/poolStatsService';
|
|
6
|
+
import type { PoolStateService } from '../pool/poolStateService';
|
|
7
|
+
import type { ClmmPoolTypes, CpmmTokenPairTypes } from '@h0ngcha0/typescript-sdk';
|
|
8
|
+
import type { PoolEvent } from '../../database/types';
|
|
9
|
+
import type { ApiClmmPosition, ApiCpmmPosition, ApiGlobalStats } from '../../api/types';
|
|
10
|
+
import Decimal from 'decimal.js';
|
|
11
|
+
import { PoolType, SortType } from '../../common/types';
|
|
12
|
+
import type { PoolRecord, CpmmPoolWithStats, PoolWithStats, ClmmLiquidityRow, ClmmTickRecord, PoolFactoryEventCounterRecord, PoolEventCounterRecord } from '../../services/pool/poolServiceTypes';
|
|
13
|
+
export declare class PoolService {
|
|
14
|
+
private zeta;
|
|
15
|
+
private priceService;
|
|
16
|
+
private poolStatsService;
|
|
17
|
+
private poolStateService;
|
|
18
|
+
private globalStatsCache;
|
|
19
|
+
constructor(zeta: Zeta, priceService: PriceService, poolStatsService: PoolStatsService, poolStateService: PoolStateService);
|
|
20
|
+
private getCpmmFeeRate;
|
|
21
|
+
private getClmmFeeRate;
|
|
22
|
+
private poolRecordToCpmmPool;
|
|
23
|
+
private poolRecordToCpmmPoolWithStats;
|
|
24
|
+
private poolRecordToClmmPool;
|
|
25
|
+
private poolRecordToClmmPoolWithStats;
|
|
26
|
+
getPoolByTokenPairId(tokenPairId: string): Promise<CpmmPoolWithStats | undefined>;
|
|
27
|
+
getPoolsByToken(token0Id: string, token1Id?: string, poolType?: PoolType, page?: number, pageSize?: number): Promise<{
|
|
28
|
+
pools: PoolWithStats[];
|
|
29
|
+
total: number;
|
|
30
|
+
page: number;
|
|
31
|
+
pageSize: number;
|
|
32
|
+
totalPages: number;
|
|
33
|
+
}>;
|
|
34
|
+
getPoolByTokenPair(token0Id: string, token1Id: string): Promise<CpmmPoolWithStats | undefined>;
|
|
35
|
+
getPoolsByIds(poolIds: string[]): Promise<PoolWithStats[]>;
|
|
36
|
+
getAllPools(page?: number, pageSize?: number, poolType?: PoolType, sortType?: SortType): Promise<{
|
|
37
|
+
pools: PoolWithStats[];
|
|
38
|
+
total: number;
|
|
39
|
+
page: number;
|
|
40
|
+
pageSize: number;
|
|
41
|
+
totalPages: number;
|
|
42
|
+
}>;
|
|
43
|
+
recordPoolEvent(poolId: string, eventType: string, txId: string, blockHash: string, eventData: unknown, client?: SqlClient): Promise<void>;
|
|
44
|
+
recordCpmmMintEvent(poolId: string, mintEvent: CpmmTokenPairTypes.MintEvent, client?: SqlClient): Promise<void>;
|
|
45
|
+
recordCpmmBurnEvent(poolId: string, burnEvent: CpmmTokenPairTypes.BurnEvent, client?: SqlClient): Promise<void>;
|
|
46
|
+
recordClmmFeesEvent(poolId: string, event: ClmmPoolTypes.FeesEvent, client?: SqlClient): Promise<void>;
|
|
47
|
+
recordClmmMintEvent(poolId: string, mintEvent: ClmmPoolTypes.MintEvent, client?: SqlClient): Promise<void>;
|
|
48
|
+
recordClmmBurnEvent(poolId: string, burnEvent: ClmmPoolTypes.BurnEvent, client?: SqlClient): Promise<void>;
|
|
49
|
+
getClmmPositions(address: string, candidates: string[], client?: SqlClient): Promise<ApiClmmPosition[]>;
|
|
50
|
+
getCpmmPositions(address: string, client?: SqlClient): Promise<ApiCpmmPosition[]>;
|
|
51
|
+
recordPoolFactoryEvent(poolId: string, eventType: string, txId: string, blockHash: string, eventData: unknown, client?: SqlClient): Promise<void>;
|
|
52
|
+
getPoolEvents(poolId: string, page?: number, pageSize?: number, client?: SqlClient): Promise<{
|
|
53
|
+
events: PoolEvent[];
|
|
54
|
+
total: number;
|
|
55
|
+
page: number;
|
|
56
|
+
pageSize: number;
|
|
57
|
+
totalPages: number;
|
|
58
|
+
}>;
|
|
59
|
+
getPoolEventCounter(poolId: string, client?: SqlClient): Promise<PoolEventCounterRecord | undefined>;
|
|
60
|
+
createPoolEventCounter(poolId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
61
|
+
updatePoolEventCounter(poolId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
62
|
+
applyClmmTickDeltas(poolId: string, deltas: Array<{
|
|
63
|
+
tick: bigint;
|
|
64
|
+
liquidityGrossDelta: bigint;
|
|
65
|
+
liquidityNetDelta: bigint;
|
|
66
|
+
}>): Promise<void>;
|
|
67
|
+
getClmmTicks(poolId: string): Promise<ClmmTickRecord[]>;
|
|
68
|
+
getPoolFactoryEventCounter(poolFactoryId: string, client?: SqlClient): Promise<PoolFactoryEventCounterRecord | undefined>;
|
|
69
|
+
createPoolFactoryEventCounter(poolFactoryId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
70
|
+
updatePoolFactoryEventCounter(poolFactoryId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
71
|
+
getPoolById(id: string): Promise<PoolRecord | undefined>;
|
|
72
|
+
getPoolWithStatsById(id: string): Promise<PoolWithStats | undefined>;
|
|
73
|
+
getTokenInfos(pool: PoolRecord): Promise<{
|
|
74
|
+
token0: TokenInfo;
|
|
75
|
+
token1: TokenInfo;
|
|
76
|
+
}>;
|
|
77
|
+
buildClmmLiquidityRows(token0: TokenInfo, token1: TokenInfo, tickRows: ClmmTickRecord[]): ClmmLiquidityRow[];
|
|
78
|
+
upsertPool(params: {
|
|
79
|
+
id: string;
|
|
80
|
+
token0: string;
|
|
81
|
+
token1: string;
|
|
82
|
+
configIndex?: number;
|
|
83
|
+
poolType: 'standard' | 'concentrated';
|
|
84
|
+
}, client?: SqlClient): Promise<void>;
|
|
85
|
+
private calculateCpmmPoolTVL;
|
|
86
|
+
private calculateClmmPoolTVL;
|
|
87
|
+
computePoolReserves(poolRecord: PoolRecord): Promise<{
|
|
88
|
+
amount0: string;
|
|
89
|
+
amount1: string;
|
|
90
|
+
totalLiquidity: string;
|
|
91
|
+
}>;
|
|
92
|
+
private fetchClmmTokenReserves;
|
|
93
|
+
computePoolTVL(poolRecord: PoolRecord): Promise<Decimal>;
|
|
94
|
+
computePoolTVLById(poolId: string): Promise<string>;
|
|
95
|
+
getGlobalStats(): Promise<ApiGlobalStats>;
|
|
96
|
+
calculateAndUpdateGlobalStats(): Promise<ApiGlobalStats>;
|
|
97
|
+
private getFeeRateForPool;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=poolService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolService.d.ts","sourceRoot":"","sources":["../../../../src/services/pool/poolService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAgD,MAAM,0BAA0B,CAAC;AAGnG,OAAY,EAAqB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAyBxE,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAQlF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGnF,OAAO,OAAO,MAAM,YAAY,CAAC;AAIjC,OAAO,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AAA;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;IAS5C,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC;IAQzC,6BAA6B,IAAI,OAAO,CAAC,cAAc,CAAC;YAgCvD,iBAAiB;CAQhC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type Decimal from 'decimal.js';
|
|
2
|
+
import type { TokenInfo } from '@alephium/token-list';
|
|
3
|
+
import type { CpmmPoolContractState, ClmmPoolContractState } from '@h0ngcha0/typescript-sdk';
|
|
4
|
+
import type { PoolRow, PoolEventCounterRow, PoolFactoryEventCounterRow } from '../../database/types';
|
|
5
|
+
import type { PeriodicalPoolStats } from '../../services/stat/poolStatsServiceTypes';
|
|
6
|
+
import type { PoolType } from '../../common/types';
|
|
7
|
+
export type CpmmPosition = {
|
|
8
|
+
id: string;
|
|
9
|
+
poolId: string;
|
|
10
|
+
createdAt: Date;
|
|
11
|
+
contractAddress: string;
|
|
12
|
+
sender: string;
|
|
13
|
+
addedAmount0: Decimal;
|
|
14
|
+
addedAmount1: Decimal;
|
|
15
|
+
addedLiquidity: bigint;
|
|
16
|
+
share: Decimal;
|
|
17
|
+
currentAmount0: Decimal;
|
|
18
|
+
currentAmount1: Decimal;
|
|
19
|
+
poolTotalSupply: bigint;
|
|
20
|
+
token0Info: TokenInfo;
|
|
21
|
+
token1Info: TokenInfo;
|
|
22
|
+
};
|
|
23
|
+
export type CpmmPoolWithStats = CpmmPoolContractState & PoolStats & {
|
|
24
|
+
type: typeof PoolType.Standard;
|
|
25
|
+
};
|
|
26
|
+
export type ClmmPoolWithStats = ClmmPoolContractState & PoolStats & {
|
|
27
|
+
type: typeof PoolType.Concentrated;
|
|
28
|
+
};
|
|
29
|
+
export type PoolWithStats = CpmmPoolWithStats | ClmmPoolWithStats;
|
|
30
|
+
export type PoolRecord = PoolRow;
|
|
31
|
+
export type PoolEventCounterRecord = PoolEventCounterRow;
|
|
32
|
+
export type PoolFactoryEventCounterRecord = PoolFactoryEventCounterRow;
|
|
33
|
+
export interface ClmmTickRecord {
|
|
34
|
+
pool_id: string;
|
|
35
|
+
tick: bigint;
|
|
36
|
+
liquidity_gross: bigint;
|
|
37
|
+
liquidity_net: bigint;
|
|
38
|
+
}
|
|
39
|
+
export interface ClmmLiquidityRow {
|
|
40
|
+
tick: string;
|
|
41
|
+
sqrtPriceX96: string;
|
|
42
|
+
price: string;
|
|
43
|
+
liquidity: string;
|
|
44
|
+
}
|
|
45
|
+
export interface PoolStats {
|
|
46
|
+
feeRate: number;
|
|
47
|
+
openTime: string;
|
|
48
|
+
tvl: number;
|
|
49
|
+
day: PeriodicalPoolStats;
|
|
50
|
+
week: PeriodicalPoolStats;
|
|
51
|
+
month: PeriodicalPoolStats;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=poolServiceTypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolServiceTypes.d.ts","sourceRoot":"","sources":["../../../../src/services/pool/poolServiceTypes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAChG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CA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Z,GAAG,EAAE,mBAAmB,CAAC;IACzB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE,mBAAmB,CAAC;CAC5B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ClmmPoolContractState, CpmmPoolContractState, Zeta } from '@h0ngcha0/typescript-sdk';
|
|
2
|
+
export declare class PoolStateService {
|
|
3
|
+
private zeta;
|
|
4
|
+
constructor(zeta: Zeta);
|
|
5
|
+
private clmmPoolStateCache;
|
|
6
|
+
private cpmmPoolStateCache;
|
|
7
|
+
getClmmPoolState(poolId: string): Promise<ClmmPoolContractState>;
|
|
8
|
+
getCpmmPoolState(token0Id: string, token1Id: string): Promise<CpmmPoolContractState>;
|
|
9
|
+
private cpmmCacheKey;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=poolStateService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolStateService.d.ts","sourceRoot":"","sources":["../../../../src/services/pool/poolStateService.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AASnG,qBAAa,gBAAgB;IACf,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI;IAE9B,OAAO,CAAC,kBAAkB,CAAoD;IAC9E,OAAO,CAAC,kBAAkB,CAAoD;IAExE,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAYhE,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAY1F,OAAO,CAAC,YAAY;CAGrB"}
|
|
@@ -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/pool/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,26 @@
|
|
|
1
|
+
import type { PoolService, PoolRecord } from './poolService';
|
|
2
|
+
import type { CpmmTokenPairTypes, ClmmPoolTypes } from '@h0ngcha0/typescript-sdk';
|
|
3
|
+
import type { PriceTickInsert, LiquidityTickInsert } from '../database/types';
|
|
4
|
+
declare abstract class BasePoolEventsHandler {
|
|
5
|
+
protected storePriceData(priceData: PriceTickInsert): Promise<void>;
|
|
6
|
+
protected storeLiquidityData(liquidityData: LiquidityTickInsert): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class StandardPoolEventsHandler extends BasePoolEventsHandler {
|
|
9
|
+
private poolService;
|
|
10
|
+
constructor(poolService: PoolService);
|
|
11
|
+
capturePriceFromSwap(tokenPairId: string, txId: string, swapData: CpmmTokenPairTypes.SwapEvent): Promise<void>;
|
|
12
|
+
captureLiquidityFromMint(tokenPairId: string, txId: string, mintEvent: CpmmTokenPairTypes.MintEvent): Promise<void>;
|
|
13
|
+
captureLiquidityFromBurn(tokenPairId: string, txId: string, burnEvent: CpmmTokenPairTypes.BurnEvent): Promise<void>;
|
|
14
|
+
calculatePriceFromSwap(swapData: CpmmTokenPairTypes.SwapEvent, poolRecord: PoolRecord, token0Decimals: number, token1Decimals: number): Promise<string>;
|
|
15
|
+
captureLiquidityFromEvent(tokenPairId: string, txId: string, event: CpmmTokenPairTypes.MintEvent | CpmmTokenPairTypes.BurnEvent): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare class ClmmPoolEventsHandler extends BasePoolEventsHandler {
|
|
18
|
+
private poolService;
|
|
19
|
+
constructor(poolService: PoolService);
|
|
20
|
+
capturePriceFromSwap(tokenPairId: string, txId: string, swapData: ClmmPoolTypes.SwapEvent): Promise<void>;
|
|
21
|
+
captureLiquidityFromMint(tokenPairId: string, txId: string, mintEvent: ClmmPoolTypes.MintEvent): Promise<void>;
|
|
22
|
+
captureLiquidityFromBurn(tokenPairId: string, txId: string, burnEvent: ClmmPoolTypes.BurnEvent): Promise<void>;
|
|
23
|
+
captureLiquidityFromEvent(poolId: string, txId: string, event: ClmmPoolTypes.MintEvent | ClmmPoolTypes.BurnEvent): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingUR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,KAAK,EAAE,kBAAkB,CAAC,SAAS,GAAG,kBAAkB,CAAC,SAAS,GACjE,OAAO,CAAC,IAAI,CAAC;CA4DjB;AAGD,qBAAa,qBAAsB,SAAQ,qBAAqB;IAClD,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAItC,oBAAoB,CACxB,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,aAAa,CAAC,SAAS,GAChC,OAAO,CAAC,IAAI,CAAC;IA2DV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,CAAC,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,wBAAwB,CAC5B,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,aAAa,CAAC,SAAS,GACjC,OAAO,CAAC,IAAI,CAAC;IAIV,yBAAyB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,aAAa,CAAC,SAAS,GAAG,aAAa,CAAC,SAAS,GACvD,OAAO,CAAC,IAAI,CAAC;CA0EjB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Zeta } from '@h0ngcha0/typescript-sdk';
|
|
2
|
+
import type { PoolService } from './poolService';
|
|
3
|
+
import type { StandardPoolEventsHandler, ClmmPoolEventsHandler } from './poolEventsHandler';
|
|
4
|
+
export declare class PoolEventsSubscriptionService {
|
|
5
|
+
private zeta;
|
|
6
|
+
private poolService;
|
|
7
|
+
private standardPoolEventsHandler;
|
|
8
|
+
private clmmPoolEventsHandler;
|
|
9
|
+
private isSubscribed;
|
|
10
|
+
private readonly standard;
|
|
11
|
+
private readonly concentrated;
|
|
12
|
+
constructor(zeta: Zeta, poolService: PoolService, standardPoolEventsHandler: StandardPoolEventsHandler, clmmPoolEventsHandler: ClmmPoolEventsHandler);
|
|
13
|
+
startSubscription(): Promise<void>;
|
|
14
|
+
stopSubscription(): void;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=poolEventsSubscriptionService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolEventsSubscriptionService.d.ts","sourceRoot":"","sources":["../../../src/services/poolEventsSubscriptionService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,IAAI,EAGL,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAkZ5F,qBAAa,6BAA6B;IAMtC,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,yBAAyB;IACjC,OAAO,CAAC,qBAAqB;IAR/B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAmC;gBAGtD,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,yBAAyB,EAAE,yBAAyB,EACpD,qBAAqB,EAAE,qBAAqB;IAUhD,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAsBxC,gBAAgB,IAAI,IAAI;CAWzB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { Zeta, CpmmPoolContractState, ClmmPoolContractState } 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, PoolStats } from './poolStatsService';
|
|
6
|
+
import type { ClmmPoolTypes, CpmmTokenPairTypes } from '@h0ngcha0/typescript-sdk';
|
|
7
|
+
import type { PoolEvent, PoolRow, PoolEventCounterRow, PoolFactoryEventCounterRow } from '../database/types';
|
|
8
|
+
import type { ApiClmmPosition, ApiCpmmPosition } from '../api/types';
|
|
9
|
+
import Decimal from 'decimal.js';
|
|
10
|
+
export interface ApiCpmmPoolContractState extends Omit<CpmmPoolContractState, 'reserve0' | 'reserve1' | 'totalSupply'> {
|
|
11
|
+
reserve0: string;
|
|
12
|
+
reserve1: string;
|
|
13
|
+
totalSupply: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ApiClmmPoolContractState extends Omit<ClmmPoolContractState, 'liquidity' | 'sqrtPriceX96' | 'tick' | 'configIndex' | 'tickSpacing' | 'tradingFee' | 'protocolFee'> {
|
|
16
|
+
liquidity: string;
|
|
17
|
+
sqrtPriceX96: string;
|
|
18
|
+
tick: number;
|
|
19
|
+
configIndex: number;
|
|
20
|
+
tickSpacing: number;
|
|
21
|
+
tradingFee: string;
|
|
22
|
+
protocolFee: string;
|
|
23
|
+
}
|
|
24
|
+
export type ApiCpmmPoolWithStats = ApiCpmmPoolContractState & PoolStats & {
|
|
25
|
+
type: typeof PoolType.Standard;
|
|
26
|
+
};
|
|
27
|
+
export type ApiClmmPoolWithStats = ApiClmmPoolContractState & PoolStats & {
|
|
28
|
+
type: typeof PoolType.Concentrated;
|
|
29
|
+
};
|
|
30
|
+
export type ApiPoolWithStats = ApiCpmmPoolWithStats | ApiClmmPoolWithStats;
|
|
31
|
+
export type CpmmPoolWithStats = CpmmPoolContractState & PoolStats & {
|
|
32
|
+
type: typeof PoolType.Standard;
|
|
33
|
+
};
|
|
34
|
+
export type ClmmPoolWithStats = ClmmPoolContractState & PoolStats & {
|
|
35
|
+
type: typeof PoolType.Concentrated;
|
|
36
|
+
};
|
|
37
|
+
export type PoolWithStats = CpmmPoolWithStats | ClmmPoolWithStats;
|
|
38
|
+
export declare const PoolType: {
|
|
39
|
+
readonly Standard: "standard";
|
|
40
|
+
readonly Concentrated: "concentrated";
|
|
41
|
+
readonly All: "all";
|
|
42
|
+
};
|
|
43
|
+
export type PoolType = (typeof PoolType)[keyof typeof PoolType];
|
|
44
|
+
export declare const PoolSortType: {
|
|
45
|
+
readonly Desc: "desc";
|
|
46
|
+
readonly Asc: "asc";
|
|
47
|
+
};
|
|
48
|
+
export type PoolSortType = (typeof PoolSortType)[keyof typeof PoolSortType];
|
|
49
|
+
export type PoolRecord = PoolRow;
|
|
50
|
+
export type PoolEventCounterRecord = PoolEventCounterRow;
|
|
51
|
+
export type PoolFactoryEventCounterRecord = PoolFactoryEventCounterRow;
|
|
52
|
+
export interface ClmmTickRecord {
|
|
53
|
+
pool_id: string;
|
|
54
|
+
tick: bigint;
|
|
55
|
+
liquidity_gross: bigint;
|
|
56
|
+
liquidity_net: bigint;
|
|
57
|
+
}
|
|
58
|
+
export interface ClmmLiquidityRow {
|
|
59
|
+
tick: string;
|
|
60
|
+
sqrtPriceX96: string;
|
|
61
|
+
price: string;
|
|
62
|
+
liquidity: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ApiGlobalStats {
|
|
65
|
+
tvl: string;
|
|
66
|
+
volume_1d: string;
|
|
67
|
+
lastUpdated: number;
|
|
68
|
+
}
|
|
69
|
+
export declare class PoolService {
|
|
70
|
+
private zeta;
|
|
71
|
+
private priceService;
|
|
72
|
+
private poolStatsService;
|
|
73
|
+
private globalStatsCache;
|
|
74
|
+
constructor(zeta: Zeta, priceService: PriceService, poolStatsService: PoolStatsService);
|
|
75
|
+
private getCpmmFeeRate;
|
|
76
|
+
private getClmmFeeRate;
|
|
77
|
+
private poolRecordToCpmmPool;
|
|
78
|
+
private poolRecordToCpmmPoolWithStats;
|
|
79
|
+
private poolRecordToClmmPool;
|
|
80
|
+
private poolRecordToClmmPoolWithStats;
|
|
81
|
+
getPoolByTokenPairId(tokenPairId: string): Promise<CpmmPoolWithStats | undefined>;
|
|
82
|
+
getPoolsByToken(token0Id: string, token1Id?: string, poolType?: PoolType, page?: number, pageSize?: number): Promise<{
|
|
83
|
+
pools: PoolWithStats[];
|
|
84
|
+
total: number;
|
|
85
|
+
page: number;
|
|
86
|
+
pageSize: number;
|
|
87
|
+
totalPages: number;
|
|
88
|
+
}>;
|
|
89
|
+
getPoolByTokenPair(token0Id: string, token1Id: string): Promise<CpmmPoolWithStats | 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
|
+
recordCpmmMintEvent(poolId: string, mintEvent: CpmmTokenPairTypes.MintEvent, client?: SqlClient): Promise<void>;
|
|
100
|
+
recordCpmmBurnEvent(poolId: string, burnEvent: CpmmTokenPairTypes.BurnEvent, client?: SqlClient): Promise<void>;
|
|
101
|
+
recordClmmFeesEvent(poolId: string, event: ClmmPoolTypes.FeesEvent, client?: SqlClient): Promise<void>;
|
|
102
|
+
recordClmmMintEvent(poolId: string, mintEvent: ClmmPoolTypes.MintEvent, client?: SqlClient): Promise<void>;
|
|
103
|
+
recordClmmBurnEvent(poolId: string, burnEvent: ClmmPoolTypes.BurnEvent, client?: SqlClient): Promise<void>;
|
|
104
|
+
getClmmPositions(address: string, candidates: string[], client?: SqlClient): Promise<ApiClmmPosition[]>;
|
|
105
|
+
getCpmmPositions(address: string, client?: SqlClient): Promise<ApiCpmmPosition[]>;
|
|
106
|
+
recordPoolFactoryEvent(poolId: string, eventType: string, txId: string, blockHash: string, eventData: unknown, client?: SqlClient): Promise<void>;
|
|
107
|
+
getPoolEvents(poolId: string, page?: number, pageSize?: number, client?: SqlClient): Promise<{
|
|
108
|
+
events: PoolEvent[];
|
|
109
|
+
total: number;
|
|
110
|
+
page: number;
|
|
111
|
+
pageSize: number;
|
|
112
|
+
totalPages: number;
|
|
113
|
+
}>;
|
|
114
|
+
getPoolEventCounter(poolId: string, client?: SqlClient): Promise<PoolEventCounterRecord | undefined>;
|
|
115
|
+
createPoolEventCounter(poolId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
116
|
+
updatePoolEventCounter(poolId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
117
|
+
applyClmmTickDeltas(poolId: string, deltas: Array<{
|
|
118
|
+
tick: bigint;
|
|
119
|
+
liquidityGrossDelta: bigint;
|
|
120
|
+
liquidityNetDelta: bigint;
|
|
121
|
+
}>): Promise<void>;
|
|
122
|
+
getClmmTicks(poolId: string): Promise<ClmmTickRecord[]>;
|
|
123
|
+
getPoolFactoryEventCounter(poolFactoryId: string, client?: SqlClient): Promise<PoolFactoryEventCounterRecord | undefined>;
|
|
124
|
+
createPoolFactoryEventCounter(poolFactoryId: string, fromCount?: number, client?: SqlClient): Promise<void>;
|
|
125
|
+
updatePoolFactoryEventCounter(poolFactoryId: string, fromCount: number, client?: SqlClient): Promise<void>;
|
|
126
|
+
getPoolById(id: string): Promise<PoolRecord | undefined>;
|
|
127
|
+
getPoolWithStatsById(id: string): Promise<PoolWithStats | undefined>;
|
|
128
|
+
getTokenInfos(pool: PoolRecord): Promise<{
|
|
129
|
+
token0: TokenInfo;
|
|
130
|
+
token1: TokenInfo;
|
|
131
|
+
}>;
|
|
132
|
+
buildClmmLiquidityRows(token0: TokenInfo, token1: TokenInfo, tickRows: ClmmTickRecord[]): ClmmLiquidityRow[];
|
|
133
|
+
upsertPool(params: {
|
|
134
|
+
id: string;
|
|
135
|
+
token0: string;
|
|
136
|
+
token1: string;
|
|
137
|
+
configIndex?: number;
|
|
138
|
+
poolType: 'standard' | 'concentrated';
|
|
139
|
+
}, client?: SqlClient): Promise<void>;
|
|
140
|
+
private calculateCpmmPoolTVL;
|
|
141
|
+
private calculateClmmPoolTVL;
|
|
142
|
+
computePoolReserves(poolRecord: PoolRecord): Promise<{
|
|
143
|
+
amount0: string;
|
|
144
|
+
amount1: string;
|
|
145
|
+
totalLiquidity: string;
|
|
146
|
+
}>;
|
|
147
|
+
private fetchClmmTokenReserves;
|
|
148
|
+
computePoolTVL(poolRecord: PoolRecord): Promise<Decimal>;
|
|
149
|
+
computePoolTVLById(poolId: string): Promise<string>;
|
|
150
|
+
getGlobalStats(): Promise<ApiGlobalStats>;
|
|
151
|
+
calculateAndUpdateGlobalStats(): Promise<ApiGlobalStats>;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=poolService.d.ts.map
|