@clonegod/ttd-bsc-common 3.0.12 → 3.0.13
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/dist/quote/index.d.ts
CHANGED
package/dist/quote/index.js
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { QuoteResultType, StandardPoolInfoType } from '@clonegod/ttd-core';
|
|
2
|
+
interface PriceFeedData {
|
|
3
|
+
blockNumber: number;
|
|
4
|
+
token0Symbol?: string;
|
|
5
|
+
token1Symbol?: string;
|
|
6
|
+
askToken0InToken1?: string;
|
|
7
|
+
bidToken0InToken1?: string;
|
|
8
|
+
askToken1InToken0?: string;
|
|
9
|
+
bidToken1InToken0?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildQuoteFromPriceFeed(poolInfo: StandardPoolInfoType, data: PriceFeedData): {
|
|
12
|
+
askQuote: QuoteResultType;
|
|
13
|
+
bidQuote: QuoteResultType;
|
|
14
|
+
} | null;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildQuoteFromPriceFeed = buildQuoteFromPriceFeed;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const constants_1 = require("../common/constants");
|
|
6
|
+
function isSameToken(addr1, addr2) {
|
|
7
|
+
const a = addr1.toLowerCase();
|
|
8
|
+
const b = addr2.toLowerCase();
|
|
9
|
+
if (a === b)
|
|
10
|
+
return true;
|
|
11
|
+
const bnbAddrs = [constants_1.WBNB_ADDRESS.toLowerCase(), constants_1.NATIVE_BNB_ADDRESS.toLowerCase()];
|
|
12
|
+
return bnbAddrs.includes(a) && bnbAddrs.includes(b);
|
|
13
|
+
}
|
|
14
|
+
function buildQuoteFromPriceFeed(poolInfo, data) {
|
|
15
|
+
var _a;
|
|
16
|
+
const quoteTokenAddr = ((_a = poolInfo.quote_token) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || '';
|
|
17
|
+
const tokenA = poolInfo.tokenA;
|
|
18
|
+
const tokenB = poolInfo.tokenB;
|
|
19
|
+
if (!tokenA || !tokenB) {
|
|
20
|
+
(0, ttd_core_1.log_warn)(`[PriceFeed] poolInfo missing tokenA/tokenB: ${poolInfo.pool_address}`);
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
let askPrice;
|
|
24
|
+
let bidPrice;
|
|
25
|
+
let baseToken;
|
|
26
|
+
let quoteToken;
|
|
27
|
+
const tokenAIsQuote = isSameToken(tokenA.address, quoteTokenAddr);
|
|
28
|
+
const tokenBIsQuote = isSameToken(tokenB.address, quoteTokenAddr);
|
|
29
|
+
if (!tokenAIsQuote && !tokenBIsQuote) {
|
|
30
|
+
(0, ttd_core_1.log_warn)(`[PriceFeed] quote_token ${quoteTokenAddr} not found in pool ${poolInfo.pool_name}`);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
if (tokenAIsQuote) {
|
|
34
|
+
quoteToken = tokenA;
|
|
35
|
+
baseToken = tokenB;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
quoteToken = tokenB;
|
|
39
|
+
baseToken = tokenA;
|
|
40
|
+
}
|
|
41
|
+
const feedToken0 = (data.token0Symbol || '').toUpperCase();
|
|
42
|
+
const feedToken1 = (data.token1Symbol || '').toUpperCase();
|
|
43
|
+
const baseSymbol = baseToken.symbol.toUpperCase();
|
|
44
|
+
const quoteSymbol = quoteToken.symbol.toUpperCase();
|
|
45
|
+
const normSymbol = (s) => (s === 'WBNB' ? 'BNB' : s);
|
|
46
|
+
if (normSymbol(feedToken0) === normSymbol(quoteSymbol)) {
|
|
47
|
+
askPrice = data.askToken1InToken0;
|
|
48
|
+
bidPrice = data.bidToken1InToken0;
|
|
49
|
+
}
|
|
50
|
+
else if (normSymbol(feedToken1) === normSymbol(quoteSymbol)) {
|
|
51
|
+
askPrice = data.askToken0InToken1;
|
|
52
|
+
bidPrice = data.bidToken0InToken1;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, ttd_core_1.log_warn)(`[PriceFeed] Cannot match quote_token symbol: quote=${quoteSymbol}, feed=[${feedToken0}/${feedToken1}], pool=${poolInfo.pool_name}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
if (!askPrice || !bidPrice) {
|
|
59
|
+
(0, ttd_core_1.log_warn)(`[PriceFeed] Missing price data for ${poolInfo.pool_name}`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const makeQuoteResult = (price, input, output) => ({
|
|
63
|
+
inputToken: input,
|
|
64
|
+
outputToken: output,
|
|
65
|
+
slippageBps: 0,
|
|
66
|
+
amountIn: 0,
|
|
67
|
+
amountOut: 0,
|
|
68
|
+
amountOutMin: 0,
|
|
69
|
+
priceImpact: 0,
|
|
70
|
+
price,
|
|
71
|
+
});
|
|
72
|
+
const askQuote = makeQuoteResult(askPrice, quoteToken, baseToken);
|
|
73
|
+
const bidQuote = makeQuoteResult(bidPrice, baseToken, quoteToken);
|
|
74
|
+
return { askQuote, bidQuote };
|
|
75
|
+
}
|
|
@@ -57,5 +57,11 @@ export interface OnchainPoolChangeEvent {
|
|
|
57
57
|
tickUpper?: number;
|
|
58
58
|
liquidityDelta?: string;
|
|
59
59
|
amount?: string;
|
|
60
|
+
token0Symbol?: string;
|
|
61
|
+
token1Symbol?: string;
|
|
62
|
+
askToken0InToken1?: string;
|
|
63
|
+
bidToken0InToken1?: string;
|
|
64
|
+
askToken1InToken0?: string;
|
|
65
|
+
bidToken1InToken0?: string;
|
|
60
66
|
};
|
|
61
67
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-bsc-common",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.13",
|
|
4
4
|
"description": "BSC common library",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"push": "npm run build && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@clonegod/ttd-core": "3.0.
|
|
17
|
+
"@clonegod/ttd-core": "3.0.8",
|
|
18
18
|
"@clonegod/ttd-bsc-send-tx": "1.0.0",
|
|
19
19
|
"axios": "^1.12.0",
|
|
20
20
|
"dotenv": "^16.4.7",
|