@clonegod/ttd-base-common 1.0.0
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/common/abi.d.ts +1 -0
- package/dist/common/abi.js +14 -0
- package/dist/common/constants.d.ts +18 -0
- package/dist/common/constants.js +34 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +18 -0
- package/dist/config/base_env_args.d.ts +11 -0
- package/dist/config/base_env_args.js +19 -0
- package/dist/config/bsc_env_args.d.ts +11 -0
- package/dist/config/bsc_env_args.js +19 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +17 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +23 -0
- package/dist/quote/event/index.d.ts +1 -0
- package/dist/quote/event/index.js +17 -0
- package/dist/quote/event/pool_event_listener.d.ts +53 -0
- package/dist/quote/event/pool_event_listener.js +334 -0
- package/dist/quote/event/verify_clmm_swap_event.d.ts +1 -0
- package/dist/quote/event/verify_clmm_swap_event.js +178 -0
- package/dist/quote/index.d.ts +2 -0
- package/dist/quote/index.js +18 -0
- package/dist/quote/pricing/index.d.ts +2 -0
- package/dist/quote/pricing/index.js +18 -0
- package/dist/quote/pricing/pool.d.ts +13 -0
- package/dist/quote/pricing/pool.js +21 -0
- package/dist/quote/pricing/token_price_cache.d.ts +10 -0
- package/dist/quote/pricing/token_price_cache.js +40 -0
- package/dist/redis/index.d.ts +1 -0
- package/dist/redis/index.js +17 -0
- package/dist/redis/redis_client.d.ts +21 -0
- package/dist/redis/redis_client.js +155 -0
- package/dist/trade/abstract_dex_trade.d.ts +27 -0
- package/dist/trade/abstract_dex_trade.js +153 -0
- package/dist/trade/abstract_dex_trade_plus.d.ts +30 -0
- package/dist/trade/abstract_dex_trade_plus.js +227 -0
- package/dist/trade/check/index.d.ts +1 -0
- package/dist/trade/check/index.js +17 -0
- package/dist/trade/check/tx_websocket_manager.d.ts +23 -0
- package/dist/trade/check/tx_websocket_manager.js +119 -0
- package/dist/trade/index.d.ts +5 -0
- package/dist/trade/index.js +21 -0
- package/dist/trade/parse/abstract_parser.d.ts +8 -0
- package/dist/trade/parse/abstract_parser.js +2 -0
- package/dist/trade/parse/base_parser.d.ts +19 -0
- package/dist/trade/parse/base_parser.js +69 -0
- package/dist/trade/parse/index.d.ts +1 -0
- package/dist/trade/parse/index.js +5 -0
- package/dist/trade/send/48club.d.ts +18 -0
- package/dist/trade/send/48club.js +97 -0
- package/dist/trade/send/blockrazor.d.ts +7 -0
- package/dist/trade/send/blockrazor.js +79 -0
- package/dist/trade/send/bsc_rpc.d.ts +6 -0
- package/dist/trade/send/bsc_rpc.js +43 -0
- package/dist/trade/send/index.d.ts +5 -0
- package/dist/trade/send/index.js +23 -0
- package/dist/trade/send/send_tx.d.ts +8 -0
- package/dist/trade/send/send_tx.js +91 -0
- package/dist/types/config_types.d.ts +28 -0
- package/dist/types/config_types.js +2 -0
- package/dist/types/event_types.d.ts +30 -0
- package/dist/types/event_types.js +2 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +20 -0
- package/dist/types/quote_types.d.ts +27 -0
- package/dist/types/quote_types.js +2 -0
- package/dist/types/trade_types.d.ts +38 -0
- package/dist/types/trade_types.js +8 -0
- package/dist/utils/gas_helper.d.ts +5 -0
- package/dist/utils/gas_helper.js +72 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +43 -0
- package/package.json +30 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EVMGasHelper = void 0;
|
|
13
|
+
const ethers_1 = require("ethers");
|
|
14
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
15
|
+
class EVMGasHelper {
|
|
16
|
+
static wrapNativeToken(provider_1, wallet_1, wrappedTokenAddress_1, amount_1) {
|
|
17
|
+
return __awaiter(this, arguments, void 0, function* (provider, wallet, wrappedTokenAddress, amount, minReserve = "0.1", tokenSymbol = "ETH") {
|
|
18
|
+
const nativeBalance = yield provider.getBalance(wallet.address);
|
|
19
|
+
const nativeBalanceEth = ethers_1.ethers.utils.formatEther(nativeBalance);
|
|
20
|
+
(0, dist_1.log_info)(`当前${tokenSymbol}余额: ${nativeBalanceEth} ${tokenSymbol}`);
|
|
21
|
+
let wrapAmount;
|
|
22
|
+
if (amount === "max") {
|
|
23
|
+
const minReserveBN = ethers_1.ethers.utils.parseEther(minReserve);
|
|
24
|
+
if (nativeBalance.lte(minReserveBN)) {
|
|
25
|
+
(0, dist_1.log_info)(`${tokenSymbol}余额不足最小保留额 ${minReserve} ${tokenSymbol},不执行转换`);
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
wrapAmount = nativeBalance.sub(minReserveBN);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
wrapAmount = ethers_1.ethers.utils.parseEther(amount);
|
|
32
|
+
const minReserveBN = ethers_1.ethers.utils.parseEther(minReserve);
|
|
33
|
+
if (nativeBalance.sub(wrapAmount).lt(minReserveBN)) {
|
|
34
|
+
(0, dist_1.log_info)(`转换后${tokenSymbol}余额将低于最小保留额 ${minReserve} ${tokenSymbol},调整转换金额`);
|
|
35
|
+
wrapAmount = nativeBalance.sub(minReserveBN);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (wrapAmount.lte(ethers_1.ethers.constants.Zero)) {
|
|
39
|
+
(0, dist_1.log_info)(`计算的转换金额为0或负数,不执行转换`);
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
const wrappedTokenContract = new ethers_1.ethers.Contract(wrappedTokenAddress, [
|
|
43
|
+
"function deposit() external payable",
|
|
44
|
+
"function withdraw(uint wad) external"
|
|
45
|
+
], wallet);
|
|
46
|
+
(0, dist_1.log_info)(`准备将 ${ethers_1.ethers.utils.formatEther(wrapAmount)} ${tokenSymbol} 转换为 W${tokenSymbol}`);
|
|
47
|
+
const gasPrice = yield provider.getGasPrice();
|
|
48
|
+
const txOptions = {
|
|
49
|
+
value: wrapAmount,
|
|
50
|
+
gasLimit: 100000,
|
|
51
|
+
gasPrice: gasPrice
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
const tx = yield wrappedTokenContract.deposit(txOptions);
|
|
55
|
+
(0, dist_1.log_info)(`${tokenSymbol}转换为W${tokenSymbol}交易已发送,txHash: ${tx.hash}`);
|
|
56
|
+
yield tx.wait();
|
|
57
|
+
(0, dist_1.log_info)(`${tokenSymbol}转换为W${tokenSymbol}交易已确认,txHash: ${tx.hash}`);
|
|
58
|
+
return tx.hash;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
(0, dist_1.log_error)(`${tokenSymbol}转换为W${tokenSymbol}失败: ${error.message}`, error);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
static checkNativeBalance(provider, walletAddress) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return yield provider.getBalance(walletAddress);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.EVMGasHelper = EVMGasHelper;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
export * from './gas_helper';
|
|
4
|
+
export declare const sleep: (ms: number) => Promise<void>;
|
|
5
|
+
export declare const formatPrice: (price: number, precision?: number) => string;
|
|
6
|
+
export declare const formatUnits: (value: ethers.BigNumber, decimals: number) => Decimal;
|
|
7
|
+
export declare const formatNumberHighPrecision: (numStr: string, precision?: number) => string;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.formatNumberHighPrecision = exports.formatUnits = exports.formatPrice = exports.sleep = void 0;
|
|
21
|
+
const ethers_1 = require("ethers");
|
|
22
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
23
|
+
__exportStar(require("./gas_helper"), exports);
|
|
24
|
+
const sleep = (ms) => {
|
|
25
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
26
|
+
};
|
|
27
|
+
exports.sleep = sleep;
|
|
28
|
+
const formatPrice = (price, precision = 10) => {
|
|
29
|
+
return price.toFixed(precision).replace(/\.?0+$/, '');
|
|
30
|
+
};
|
|
31
|
+
exports.formatPrice = formatPrice;
|
|
32
|
+
const formatUnits = (value, decimals) => {
|
|
33
|
+
return new decimal_js_1.default(ethers_1.ethers.utils.formatUnits(value, decimals).toString());
|
|
34
|
+
};
|
|
35
|
+
exports.formatUnits = formatUnits;
|
|
36
|
+
const formatNumberHighPrecision = (numStr, precision = 12) => {
|
|
37
|
+
const num = new decimal_js_1.default(numStr).toNumber();
|
|
38
|
+
if (Math.abs(num) < 0.000001 && num !== 0) {
|
|
39
|
+
return num.toExponential(precision);
|
|
40
|
+
}
|
|
41
|
+
return num.toFixed(precision).replace(/\.?0+$/, '');
|
|
42
|
+
};
|
|
43
|
+
exports.formatNumberHighPrecision = formatNumberHighPrecision;
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clonegod/ttd-base-common",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Base common library",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"clean": "rm -rf dist node_modules",
|
|
13
|
+
"build": "yarn tsc --outDir ./dist",
|
|
14
|
+
"push": "npm run build && npm publish"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@clonegod/ttd-core": "2.0.44",
|
|
18
|
+
"axios": "^1.11.00",
|
|
19
|
+
"dotenv": "^16.4.7",
|
|
20
|
+
"ethers": "^5.8.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@types/node": "^22.14.0",
|
|
24
|
+
"typescript": "^5.8.2"
|
|
25
|
+
},
|
|
26
|
+
"overrides": {},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
}
|
|
30
|
+
}
|