@clonegod/ttd-bsc-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 +31 -0
- package/dist/common/abi.js +68 -0
- package/dist/common/constants.d.ts +21 -0
- package/dist/common/constants.js +37 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +18 -0
- package/dist/config/bsc_env_args.d.ts +11 -0
- package/dist/config/bsc_env_args.js +19 -0
- package/dist/config/env_args.d.ts +13 -0
- package/dist/config/env_args.js +23 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +17 -0
- package/dist/constants/networks.d.ts +10 -0
- package/dist/constants/networks.js +28 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +22 -0
- package/dist/providers/index.d.ts +9 -0
- package/dist/providers/index.js +21 -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 +39 -0
- package/dist/quote/event/pool_event_listener.js +231 -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 +9 -0
- package/dist/quote/pricing/token_price_cache.js +40 -0
- package/dist/trade/abstract_dex_trade.d.ts +27 -0
- package/dist/trade/abstract_dex_trade.js +152 -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 +4 -0
- package/dist/trade/index.js +20 -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 +30 -0
- package/dist/trade/parse/base_parser.js +108 -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 +85 -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/dist/utils/redis_lock.d.ts +14 -0
- package/dist/utils/redis_lock.js +100 -0
- package/package.json +30 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const ERC20_ABI: string[];
|
|
2
|
+
export declare const PANCAKE_PAIR_FULL_ABI: ({
|
|
3
|
+
anonymous: boolean;
|
|
4
|
+
inputs: {
|
|
5
|
+
indexed: boolean;
|
|
6
|
+
internalType: string;
|
|
7
|
+
name: string;
|
|
8
|
+
type: string;
|
|
9
|
+
}[];
|
|
10
|
+
name: string;
|
|
11
|
+
type: string;
|
|
12
|
+
constant?: undefined;
|
|
13
|
+
outputs?: undefined;
|
|
14
|
+
payable?: undefined;
|
|
15
|
+
stateMutability?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
constant: boolean;
|
|
18
|
+
inputs: any[];
|
|
19
|
+
name: string;
|
|
20
|
+
outputs: {
|
|
21
|
+
internalType: string;
|
|
22
|
+
name: string;
|
|
23
|
+
type: string;
|
|
24
|
+
}[];
|
|
25
|
+
payable: boolean;
|
|
26
|
+
stateMutability: string;
|
|
27
|
+
type: string;
|
|
28
|
+
anonymous?: undefined;
|
|
29
|
+
})[];
|
|
30
|
+
export declare const PANCAKE_V2_ROUTER_ABI: string[];
|
|
31
|
+
export declare const PANCAKE_V3_ROUTER_ABI: string[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PANCAKE_V3_ROUTER_ABI = exports.PANCAKE_V2_ROUTER_ABI = exports.PANCAKE_PAIR_FULL_ABI = exports.ERC20_ABI = void 0;
|
|
4
|
+
exports.ERC20_ABI = [
|
|
5
|
+
'function decimals() view returns (uint8)',
|
|
6
|
+
'function symbol() view returns (string)',
|
|
7
|
+
'function name() view returns (string)',
|
|
8
|
+
'function totalSupply() view returns (uint256)',
|
|
9
|
+
'function balanceOf(address) view returns (uint256)',
|
|
10
|
+
'function transfer(address to, uint amount) returns (bool)',
|
|
11
|
+
'function allowance(address owner, address spender) view returns (uint256)',
|
|
12
|
+
'function approve(address spender, uint256 amount) returns (bool)',
|
|
13
|
+
'function transferFrom(address sender, address recipient, uint256 amount) returns (bool)'
|
|
14
|
+
];
|
|
15
|
+
exports.PANCAKE_PAIR_FULL_ABI = [
|
|
16
|
+
{
|
|
17
|
+
"anonymous": false,
|
|
18
|
+
"inputs": [
|
|
19
|
+
{ "indexed": false, "internalType": "uint112", "name": "reserve0", "type": "uint112" },
|
|
20
|
+
{ "indexed": false, "internalType": "uint112", "name": "reserve1", "type": "uint112" }
|
|
21
|
+
],
|
|
22
|
+
"name": "Sync",
|
|
23
|
+
"type": "event"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"constant": true,
|
|
27
|
+
"inputs": [],
|
|
28
|
+
"name": "token0",
|
|
29
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
30
|
+
"payable": false,
|
|
31
|
+
"stateMutability": "view",
|
|
32
|
+
"type": "function"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"constant": true,
|
|
36
|
+
"inputs": [],
|
|
37
|
+
"name": "token1",
|
|
38
|
+
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
|
|
39
|
+
"payable": false,
|
|
40
|
+
"stateMutability": "view",
|
|
41
|
+
"type": "function"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"constant": true,
|
|
45
|
+
"inputs": [],
|
|
46
|
+
"name": "getReserves",
|
|
47
|
+
"outputs": [
|
|
48
|
+
{ "internalType": "uint112", "name": "_reserve0", "type": "uint112" },
|
|
49
|
+
{ "internalType": "uint112", "name": "_reserve1", "type": "uint112" },
|
|
50
|
+
{ "internalType": "uint32", "name": "_blockTimestampLast", "type": "uint32" }
|
|
51
|
+
],
|
|
52
|
+
"payable": false,
|
|
53
|
+
"stateMutability": "view",
|
|
54
|
+
"type": "function"
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
exports.PANCAKE_V2_ROUTER_ABI = [
|
|
58
|
+
'function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) external payable returns (uint[] memory amounts)',
|
|
59
|
+
'function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
|
|
60
|
+
'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline) external returns (uint[] memory amounts)',
|
|
61
|
+
'function getAmountsOut(uint amountIn, address[] memory path) public view returns (uint[] memory amounts)'
|
|
62
|
+
];
|
|
63
|
+
exports.PANCAKE_V3_ROUTER_ABI = [
|
|
64
|
+
'function exactInputSingle(tuple(address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 amountIn, uint256 amountOutMinimum, uint160 sqrtPriceLimitX96)) external payable returns (uint256 amountOut)',
|
|
65
|
+
'function exactInput(tuple(bytes path, address recipient, uint256 deadline, uint256 amountIn, uint256 amountOutMinimum)) external payable returns (uint256 amountOut)',
|
|
66
|
+
'function exactOutputSingle(tuple(address tokenIn, address tokenOut, uint24 fee, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum, uint160 sqrtPriceLimitX96)) external payable returns (uint256 amountIn)',
|
|
67
|
+
'function exactOutput(tuple(bytes path, address recipient, uint256 deadline, uint256 amountOut, uint256 amountInMaximum)) external payable returns (uint256 amountIn)'
|
|
68
|
+
];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const BSC_CHAIN_ID = 56;
|
|
2
|
+
export declare const WBNB_ADDRESS = "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c";
|
|
3
|
+
export declare const PANCAKE_V2_ROUTER_ADDRESS = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
|
|
4
|
+
export declare const PANCAKE_V3_SMART_ROUTER_ADDRESS = "0x13f4EA83D0bd40E75C8222255bc855a974568Dd4";
|
|
5
|
+
export declare const PANCAKE_PERMIT2_ADDRESS = "0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768";
|
|
6
|
+
export declare const PANCAKE_UNIVERSAL_ROUTER_ADDRESS = "0x1A0A18AC4BECDDbd6389559687d1A73d8927E416";
|
|
7
|
+
export declare const EVENT_NAMES: {
|
|
8
|
+
readonly BLOCK_UPDATE: "block_update";
|
|
9
|
+
readonly POOL_STATE_UPDATE: "pool_state_update";
|
|
10
|
+
readonly LIQUIDITY_UPDATE: "liquidity_update";
|
|
11
|
+
readonly POOL_SYNC: "POOL_SYNC";
|
|
12
|
+
readonly POOL_SWAP: "POOL_SWAP";
|
|
13
|
+
readonly QUOTE_RESULT: "quote_result";
|
|
14
|
+
readonly QUOTE_TRIGGER: "quote_trigger";
|
|
15
|
+
};
|
|
16
|
+
export declare const EVENT_SIGNATURES: {
|
|
17
|
+
SWAP_RAW: string;
|
|
18
|
+
MINT: string;
|
|
19
|
+
BURN: string;
|
|
20
|
+
};
|
|
21
|
+
export declare const PancakeV3PoolABI: string[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PancakeV3PoolABI = exports.EVENT_SIGNATURES = exports.EVENT_NAMES = exports.PANCAKE_UNIVERSAL_ROUTER_ADDRESS = exports.PANCAKE_PERMIT2_ADDRESS = exports.PANCAKE_V3_SMART_ROUTER_ADDRESS = exports.PANCAKE_V2_ROUTER_ADDRESS = exports.WBNB_ADDRESS = exports.BSC_CHAIN_ID = void 0;
|
|
4
|
+
exports.BSC_CHAIN_ID = 56;
|
|
5
|
+
exports.WBNB_ADDRESS = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c';
|
|
6
|
+
exports.PANCAKE_V2_ROUTER_ADDRESS = '0x10ED43C718714eb63d5aA57B78B54704E256024E';
|
|
7
|
+
exports.PANCAKE_V3_SMART_ROUTER_ADDRESS = '0x13f4EA83D0bd40E75C8222255bc855a974568Dd4';
|
|
8
|
+
exports.PANCAKE_PERMIT2_ADDRESS = '0x31c2F6fcFf4F8759b3Bd5Bf0e1084A055615c768';
|
|
9
|
+
exports.PANCAKE_UNIVERSAL_ROUTER_ADDRESS = '0x1A0A18AC4BECDDbd6389559687d1A73d8927E416';
|
|
10
|
+
exports.EVENT_NAMES = {
|
|
11
|
+
BLOCK_UPDATE: 'block_update',
|
|
12
|
+
POOL_STATE_UPDATE: 'pool_state_update',
|
|
13
|
+
LIQUIDITY_UPDATE: 'liquidity_update',
|
|
14
|
+
POOL_SYNC: 'POOL_SYNC',
|
|
15
|
+
POOL_SWAP: 'POOL_SWAP',
|
|
16
|
+
QUOTE_RESULT: 'quote_result',
|
|
17
|
+
QUOTE_TRIGGER: 'quote_trigger',
|
|
18
|
+
};
|
|
19
|
+
exports.EVENT_SIGNATURES = {
|
|
20
|
+
SWAP_RAW: "Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1)",
|
|
21
|
+
MINT: "event Mint(address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)",
|
|
22
|
+
BURN: "event Burn(address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)"
|
|
23
|
+
};
|
|
24
|
+
exports.PancakeV3PoolABI = [
|
|
25
|
+
"function slot0() external view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)",
|
|
26
|
+
"function liquidity() external view returns (uint128)",
|
|
27
|
+
"function tickSpacing() external view returns (int24)",
|
|
28
|
+
"function factory() external view returns (address)",
|
|
29
|
+
"function token0() external view returns (address)",
|
|
30
|
+
"function token1() external view returns (address)",
|
|
31
|
+
"function fee() external view returns (uint24)",
|
|
32
|
+
"function ticks(int24 tick) external view returns (uint128 liquidityGross, int128 liquidityNet, int56 tickCumulativeOutside, uint160 secondsPerLiquidityOutsideX128, uint32 secondsOutside, bool initialized)",
|
|
33
|
+
"function tickBitmap(int16 wordPosition) external view returns (uint256)",
|
|
34
|
+
"event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1)",
|
|
35
|
+
"event Mint(address sender, address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)",
|
|
36
|
+
"event Burn(address indexed owner, int24 indexed tickLower, int24 indexed tickUpper, uint128 amount, uint256 amount0, uint256 amount1)"
|
|
37
|
+
];
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./abi"), exports);
|
|
18
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EnvArgs } from "@clonegod/ttd-core/dist/app_config/env_args";
|
|
2
|
+
export declare class BscEnvArgs extends EnvArgs {
|
|
3
|
+
large_trade_threshold_usd: number;
|
|
4
|
+
gas_price_gwei: number;
|
|
5
|
+
gas_limit: number;
|
|
6
|
+
tip_amount_gwei: number;
|
|
7
|
+
tx_status_check_interval_mills: number;
|
|
8
|
+
tx_cancel_timeout_ms: number;
|
|
9
|
+
tx_cancel_gas_boost_factor: number;
|
|
10
|
+
constructor();
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BscEnvArgs = void 0;
|
|
4
|
+
const env_args_1 = require("@clonegod/ttd-core/dist/app_config/env_args");
|
|
5
|
+
const decimal_js_1 = require("decimal.js");
|
|
6
|
+
class BscEnvArgs extends env_args_1.EnvArgs {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
this.large_trade_threshold_usd = parseInt(process.env.LARGE_TRADE_THRESHOLD_USD || '500');
|
|
10
|
+
this.gas_price_gwei = new decimal_js_1.Decimal(process.env.GAS_PRICE_GWEI || '1').toNumber();
|
|
11
|
+
this.gas_limit = parseInt(process.env.GAS_LIMIT || '300000');
|
|
12
|
+
this.tip_amount_gwei = parseInt(process.env.EOA_TIP_AMOUNT_GWEI || '10000');
|
|
13
|
+
this.tx_status_check_interval_mills = parseInt(process.env.TX_STATUS_CHECK_INTERVAL_MILLS || '3000');
|
|
14
|
+
this.tx_cancel_timeout_ms = parseInt(process.env.TX_CANCEL_TIMEOUT_MS || '15000');
|
|
15
|
+
this.tx_cancel_gas_boost_factor = new decimal_js_1.Decimal(process.env.TX_CANCEL_GAS_PRICE_BOOST_FACTOR || '1.5').toNumber();
|
|
16
|
+
this.print();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.BscEnvArgs = BscEnvArgs;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { EnvArgs } from "@clonegod/ttd-core/dist";
|
|
2
|
+
export declare class BSCEnvArgs extends EnvArgs {
|
|
3
|
+
trade_mgt_http_port: number;
|
|
4
|
+
subscribe_dex_pool_txns: boolean;
|
|
5
|
+
subscribe_dex_pool_txns_startup: boolean;
|
|
6
|
+
subscribe_dex_pool_txns_interval: number;
|
|
7
|
+
onchain_data_save_file: boolean;
|
|
8
|
+
load_dex_pools_min_tvl: number;
|
|
9
|
+
load_dex_pools_min_vol: number;
|
|
10
|
+
load_dex_pools_all: boolean;
|
|
11
|
+
load_dex_pools_on_startup: boolean;
|
|
12
|
+
constructor();
|
|
13
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSCEnvArgs = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const dist_2 = require("@clonegod/ttd-core/dist");
|
|
6
|
+
class BSCEnvArgs extends dist_1.EnvArgs {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
// BSC特定配置初始化
|
|
10
|
+
this.trade_mgt_http_port = parseInt(process.env.TRADE_MGT_HTTP_PORT || '8003');
|
|
11
|
+
this.subscribe_dex_pool_txns = process.env.SUBSCRIBE_DEX_POOL_TXNS === 'true';
|
|
12
|
+
this.subscribe_dex_pool_txns_startup = process.env.SUBSCRIBE_DEX_POOL_TXNS_STARTUP === 'true';
|
|
13
|
+
this.subscribe_dex_pool_txns_interval = parseInt(process.env.SUBSCRIBE_DEX_POOL_TXNS_INTERVAL || '3600');
|
|
14
|
+
this.onchain_data_save_file = process.env.ONCHAIN_DATA_SAVE_FILE === 'true';
|
|
15
|
+
// BSC链特定的池子配置初始化
|
|
16
|
+
this.load_dex_pools_min_tvl = parseInt(process.env.LOAD_DEX_POOLS_MIN_TVL || '50000');
|
|
17
|
+
this.load_dex_pools_min_vol = parseInt(process.env.LOAD_DEX_POOLS_MIN_VOL || '100000');
|
|
18
|
+
this.load_dex_pools_all = process.env.LOAD_DEX_POOLS_ALL === 'true';
|
|
19
|
+
this.load_dex_pools_on_startup = process.env.LOAD_DEX_POOLS_ON_STARTUP === 'true';
|
|
20
|
+
(0, dist_2.log_info)('BSC env args init finish', this);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.BSCEnvArgs = BSCEnvArgs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './bsc_env_args';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./bsc_env_args"), exports);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BSCNetworkConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* BSC网络配置
|
|
4
|
+
*/
|
|
5
|
+
export declare const BSC_MAINNET: BSCNetworkConfig;
|
|
6
|
+
export declare const BSC_TESTNET: BSCNetworkConfig;
|
|
7
|
+
/**
|
|
8
|
+
* 根据环境变量获取当前使用的网络
|
|
9
|
+
*/
|
|
10
|
+
export declare const getCurrentNetwork: () => BSCNetworkConfig;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentNetwork = exports.BSC_TESTNET = exports.BSC_MAINNET = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* BSC网络配置
|
|
6
|
+
*/
|
|
7
|
+
exports.BSC_MAINNET = {
|
|
8
|
+
chainId: 56,
|
|
9
|
+
name: 'BSC Mainnet',
|
|
10
|
+
rpcUrl: 'https://bsc-dataseed.binance.org/',
|
|
11
|
+
explorerUrl: 'https://bscscan.com',
|
|
12
|
+
blockTime: 3, // 3秒
|
|
13
|
+
};
|
|
14
|
+
exports.BSC_TESTNET = {
|
|
15
|
+
chainId: 97,
|
|
16
|
+
name: 'BSC Testnet',
|
|
17
|
+
rpcUrl: 'https://data-seed-prebsc-1-s1.binance.org:8545/',
|
|
18
|
+
explorerUrl: 'https://testnet.bscscan.com',
|
|
19
|
+
blockTime: 3, // 3秒
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 根据环境变量获取当前使用的网络
|
|
23
|
+
*/
|
|
24
|
+
const getCurrentNetwork = () => {
|
|
25
|
+
const network = process.env.BSC_NETWORK || 'mainnet';
|
|
26
|
+
return network.toLowerCase() === 'testnet' ? exports.BSC_TESTNET : exports.BSC_MAINNET;
|
|
27
|
+
};
|
|
28
|
+
exports.getCurrentNetwork = getCurrentNetwork;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
19
|
+
__exportStar(require("./quote"), exports);
|
|
20
|
+
__exportStar(require("./trade"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* 创建BSC网络的Provider
|
|
4
|
+
*/
|
|
5
|
+
export declare const createBSCProvider: () => ethers.providers.JsonRpcProvider;
|
|
6
|
+
/**
|
|
7
|
+
* 使用私钥创建Signer
|
|
8
|
+
*/
|
|
9
|
+
export declare const createSigner: (privateKey: string, provider?: ethers.providers.Provider) => ethers.Wallet;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSigner = exports.createBSCProvider = void 0;
|
|
4
|
+
const ethers_1 = require("ethers");
|
|
5
|
+
const networks_1 = require("../constants/networks");
|
|
6
|
+
/**
|
|
7
|
+
* 创建BSC网络的Provider
|
|
8
|
+
*/
|
|
9
|
+
const createBSCProvider = () => {
|
|
10
|
+
const network = (0, networks_1.getCurrentNetwork)();
|
|
11
|
+
return new ethers_1.ethers.providers.JsonRpcProvider(network.rpcUrl);
|
|
12
|
+
};
|
|
13
|
+
exports.createBSCProvider = createBSCProvider;
|
|
14
|
+
/**
|
|
15
|
+
* 使用私钥创建Signer
|
|
16
|
+
*/
|
|
17
|
+
const createSigner = (privateKey, provider) => {
|
|
18
|
+
const bscProvider = provider || (0, exports.createBSCProvider)();
|
|
19
|
+
return new ethers_1.ethers.Wallet(privateKey, bscProvider);
|
|
20
|
+
};
|
|
21
|
+
exports.createSigner = createSigner;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pool_event_listener';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pool_event_listener"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-core";
|
|
3
|
+
import { AppConfig } from "@clonegod/ttd-core/dist";
|
|
4
|
+
export interface BlockUpdateEvent {
|
|
5
|
+
blockNumber: number;
|
|
6
|
+
previousBlockNumber: number;
|
|
7
|
+
timestamp: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class PoolEventListener {
|
|
10
|
+
private appConfig;
|
|
11
|
+
private wsProvider;
|
|
12
|
+
private poolList;
|
|
13
|
+
private isConnected;
|
|
14
|
+
private isStarted;
|
|
15
|
+
private reconnectAttempts;
|
|
16
|
+
private maxReconnectAttempts;
|
|
17
|
+
private baseReconnectDelay;
|
|
18
|
+
private maxReconnectDelay;
|
|
19
|
+
private heartbeatInterval;
|
|
20
|
+
private connectionTimeout;
|
|
21
|
+
private connectionTimeoutMs;
|
|
22
|
+
private lastProcessedBlockNumber;
|
|
23
|
+
private isBlockListenerActive;
|
|
24
|
+
constructor(appConfig: AppConfig, wsProvider: ethers.providers.WebSocketProvider);
|
|
25
|
+
init(poolList: StandardPoolInfoType[]): Promise<void>;
|
|
26
|
+
start(): Promise<void>;
|
|
27
|
+
stop(): Promise<void>;
|
|
28
|
+
private initProvider;
|
|
29
|
+
private setConnectionTimeout;
|
|
30
|
+
private clearConnectionTimeout;
|
|
31
|
+
private handleConnectionIssue;
|
|
32
|
+
private startHeartbeat;
|
|
33
|
+
private stopHeartbeat;
|
|
34
|
+
private cleanupProvider;
|
|
35
|
+
private startBlockListener;
|
|
36
|
+
private stopBlockListener;
|
|
37
|
+
isWSConnected(): boolean;
|
|
38
|
+
getConnectionDiagnostics(): object;
|
|
39
|
+
}
|