@clonegod/ttd-base-common 1.0.26 → 1.1.1
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/appconfig/BaseQuoteAppConfig.d.ts +10 -0
- package/dist/appconfig/BaseQuoteAppConfig.js +36 -0
- package/dist/appconfig/BaseTradeAppConfig.d.ts +7 -0
- package/dist/appconfig/BaseTradeAppConfig.js +13 -0
- package/dist/appconfig/base_dex_env_args.d.ts +5 -0
- package/dist/appconfig/base_dex_env_args.js +68 -0
- package/dist/appconfig/base_env_args.d.ts +82 -0
- package/dist/appconfig/base_env_args.js +91 -0
- package/dist/appconfig/ensure_core_env.d.ts +1 -0
- package/dist/appconfig/ensure_core_env.js +18 -0
- package/dist/appconfig/index.d.ts +5 -0
- package/dist/appconfig/index.js +21 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/quote/depth/amm_depth_calculator.d.ts +19 -0
- package/dist/quote/depth/amm_depth_calculator.js +55 -0
- package/dist/quote/depth/clmm_depth_calculator.d.ts +28 -0
- package/dist/quote/depth/clmm_depth_calculator.js +176 -0
- package/dist/quote/depth/index.d.ts +51 -0
- package/dist/quote/depth/index.js +264 -0
- package/dist/quote/depth/tick_liquidity_snapshot.d.ts +58 -0
- package/dist/quote/depth/tick_liquidity_snapshot.js +143 -0
- package/dist/quote/event/index.d.ts +1 -0
- package/dist/quote/event/index.js +1 -0
- package/dist/quote/event/pool_event_listener.d.ts +5 -3
- package/dist/quote/event/pool_event_listener.js +128 -150
- package/dist/quote/event/swap_debouncer.d.ts +22 -0
- package/dist/quote/event/swap_debouncer.js +80 -0
- package/dist/quote/get_base_token_price.d.ts +6 -0
- package/dist/quote/get_base_token_price.js +90 -0
- package/dist/quote/index.d.ts +7 -0
- package/dist/quote/index.js +7 -0
- package/dist/quote/preload_token_prices.d.ts +2 -0
- package/dist/quote/preload_token_prices.js +37 -0
- package/dist/quote/price_feed_handler.d.ts +15 -0
- package/dist/quote/price_feed_handler.js +56 -0
- package/dist/quote/pricing/fee_helpers.d.ts +13 -0
- package/dist/quote/pricing/fee_helpers.js +68 -0
- package/dist/quote/pricing/index.d.ts +3 -1
- package/dist/quote/pricing/index.js +3 -1
- package/dist/quote/pricing/pool_state_initializer.d.ts +12 -0
- package/dist/quote/pricing/pool_state_initializer.js +191 -0
- package/dist/quote/pricing/sdk_token_factory.d.ts +2 -0
- package/dist/quote/pricing/sdk_token_factory.js +21 -0
- package/dist/quote/quote_amount.d.ts +4 -0
- package/dist/quote/quote_amount.js +24 -0
- package/dist/quote/tick/cached_tick_data_provider.d.ts +12 -0
- package/dist/quote/tick/cached_tick_data_provider.js +45 -0
- package/dist/quote/tick/clmm_tick_cache.d.ts +42 -0
- package/dist/quote/tick/clmm_tick_cache.js +236 -0
- package/dist/quote/tick/index.d.ts +4 -0
- package/dist/{ws → quote/tick}/index.js +4 -2
- package/dist/quote/tick/state_view_tick_loader.d.ts +17 -0
- package/dist/quote/tick/state_view_tick_loader.js +136 -0
- package/dist/quote/tick/tick_lens_loaders.d.ts +24 -0
- package/dist/quote/tick/tick_lens_loaders.js +158 -0
- package/dist/quote/verify/index.d.ts +2 -0
- package/dist/quote/verify/index.js +5 -0
- package/dist/quote/verify/quote_price_verify.d.ts +30 -0
- package/dist/quote/verify/quote_price_verify.js +240 -0
- package/dist/redis/redis_client.d.ts +3 -2
- package/dist/redis/redis_client.js +86 -116
- package/dist/send-tx/constants.d.ts +2 -0
- package/dist/send-tx/constants.js +6 -0
- package/dist/send-tx/index.d.ts +2 -0
- package/dist/{config → send-tx}/index.js +2 -1
- package/dist/send-tx/types.d.ts +4 -0
- package/dist/send-tx/types.js +2 -0
- package/dist/trade/abstract_dex_trade.d.ts +43 -21
- package/dist/trade/abstract_dex_trade.js +347 -133
- package/dist/trade/caller_manager.d.ts +31 -0
- package/dist/trade/caller_manager.js +202 -0
- package/dist/trade/check/abstract_tx_result_checker.d.ts +28 -0
- package/dist/trade/check/abstract_tx_result_checker.js +192 -0
- package/dist/trade/check/index.d.ts +1 -1
- package/dist/trade/check/index.js +1 -1
- package/dist/trade/index.d.ts +2 -2
- package/dist/trade/index.js +2 -2
- package/dist/trade/parse/base_parser.d.ts +1 -2
- package/dist/trade/parse/base_parser.js +36 -36
- package/dist/trade/trade_trace.d.ts +17 -0
- package/dist/trade/trade_trace.js +65 -0
- package/dist/types/config_types.d.ts +3 -3
- package/dist/types/event_types.d.ts +3 -3
- package/dist/types/pool_state.d.ts +140 -13
- package/dist/utils/ethers_compat.d.ts +13 -0
- package/dist/utils/ethers_compat.js +18 -0
- package/dist/utils/fast_signer.d.ts +1 -0
- package/dist/utils/fast_signer.js +87 -0
- package/dist/utils/gas_helper.d.ts +2 -2
- package/dist/utils/gas_helper.js +48 -60
- package/dist/utils/index.d.ts +5 -2
- package/dist/utils/index.js +6 -2
- package/dist/utils/pool_filter.d.ts +8 -0
- package/dist/utils/pool_filter.js +38 -0
- package/dist/utils/trade_direction.d.ts +14 -0
- package/dist/utils/trade_direction.js +23 -0
- package/package.json +2 -2
- package/dist/config/base_env_args.d.ts +0 -11
- package/dist/config/base_env_args.js +0 -19
- package/dist/config/index.d.ts +0 -1
- package/dist/quote/event/verify_clmm_swap_event.d.ts +0 -1
- package/dist/quote/event/verify_clmm_swap_event.js +0 -178
- package/dist/quote/pricing/token_price_cache.d.ts +0 -10
- package/dist/quote/pricing/token_price_cache.js +0 -40
- package/dist/trade/abstract_dex_trade_plus.d.ts +0 -43
- package/dist/trade/abstract_dex_trade_plus.js +0 -421
- package/dist/trade/check/tx_websocket_manager.d.ts +0 -23
- package/dist/trade/check/tx_websocket_manager.js +0 -119
- package/dist/trade/send/alchemy_base.d.ts +0 -5
- package/dist/trade/send/alchemy_base.js +0 -48
- package/dist/trade/send/ankr_base.d.ts +0 -5
- package/dist/trade/send/ankr_base.js +0 -48
- package/dist/trade/send/base_rpc.d.ts +0 -5
- package/dist/trade/send/base_rpc.js +0 -48
- package/dist/trade/send/blockpi_base.d.ts +0 -5
- package/dist/trade/send/blockpi_base.js +0 -48
- package/dist/trade/send/bloxroute_base.d.ts +0 -11
- package/dist/trade/send/bloxroute_base.js +0 -115
- package/dist/trade/send/chainstack_base.d.ts +0 -5
- package/dist/trade/send/chainstack_base.js +0 -48
- package/dist/trade/send/drpc_base.d.ts +0 -5
- package/dist/trade/send/drpc_base.js +0 -48
- package/dist/trade/send/getblock_base.d.ts +0 -5
- package/dist/trade/send/getblock_base.js +0 -48
- package/dist/trade/send/index.d.ts +0 -15
- package/dist/trade/send/index.js +0 -33
- package/dist/trade/send/infura_base.d.ts +0 -5
- package/dist/trade/send/infura_base.js +0 -48
- package/dist/trade/send/moralis_base.d.ts +0 -5
- package/dist/trade/send/moralis_base.js +0 -48
- package/dist/trade/send/onerpc_base.d.ts +0 -5
- package/dist/trade/send/onerpc_base.js +0 -48
- package/dist/trade/send/quicknode_base.d.ts +0 -5
- package/dist/trade/send/quicknode_base.js +0 -48
- package/dist/trade/send/send_tx.d.ts +0 -17
- package/dist/trade/send/send_tx.js +0 -163
- package/dist/ws/event_filter.d.ts +0 -8
- package/dist/ws/event_filter.js +0 -36
- package/dist/ws/index.d.ts +0 -2
- package/dist/ws/subscribe_v2_events.d.ts +0 -14
- package/dist/ws/subscribe_v2_events.js +0 -174
- package/dist/ws/subscribe_v3_events.d.ts +0 -14
- package/dist/ws/subscribe_v3_events.js +0 -174
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseEnvArgs } from "./base_env_args";
|
|
2
|
+
import { AppConfig } from '@clonegod/ttd-core';
|
|
3
|
+
export declare class BaseQuoteAppConfig extends AppConfig {
|
|
4
|
+
private eventEmitter;
|
|
5
|
+
env_args: BaseEnvArgs;
|
|
6
|
+
constructor();
|
|
7
|
+
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
|
8
|
+
emit(eventName: string | symbol, ...args: any[]): boolean;
|
|
9
|
+
init(): Promise<void>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseQuoteAppConfig = void 0;
|
|
4
|
+
const ensure_core_env_1 = require("./ensure_core_env");
|
|
5
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
6
|
+
const events_1 = require("events");
|
|
7
|
+
class BaseQuoteAppConfig extends ttd_core_1.AppConfig {
|
|
8
|
+
constructor() {
|
|
9
|
+
(0, ensure_core_env_1.ensureCoreEnv)();
|
|
10
|
+
super();
|
|
11
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
12
|
+
this.env_args = (0, ttd_core_1.getCoreEnv)();
|
|
13
|
+
}
|
|
14
|
+
on(eventName, listener) {
|
|
15
|
+
this.eventEmitter.on(eventName, listener);
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
emit(eventName, ...args) {
|
|
19
|
+
return this.eventEmitter.emit(eventName, ...args);
|
|
20
|
+
}
|
|
21
|
+
async init() {
|
|
22
|
+
await super.init();
|
|
23
|
+
await this.arb_cache.init();
|
|
24
|
+
if (!this.arb_event_subscriber) {
|
|
25
|
+
this.arb_event_subscriber = (0, ttd_core_1.getArbEventSubscriber)(this.arb_cache);
|
|
26
|
+
}
|
|
27
|
+
(0, ttd_core_1.log_info)('BaseQuoteAppConfig initialized', {
|
|
28
|
+
chain_id: this.env_args.chain_id,
|
|
29
|
+
dex_id: this.env_args.dex_id,
|
|
30
|
+
pair: this.env_args.pair,
|
|
31
|
+
rpc_endpoint: this.env_args.rpc_endpoint,
|
|
32
|
+
ws_endpoint: this.env_args.ws_endpoint,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BaseQuoteAppConfig = BaseQuoteAppConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AbstractTradeAppConfig } from '@clonegod/ttd-core';
|
|
2
|
+
import { BaseEnvArgs } from './base_env_args';
|
|
3
|
+
export declare abstract class BaseTradeAppConfig extends AbstractTradeAppConfig {
|
|
4
|
+
env_args: BaseEnvArgs;
|
|
5
|
+
constructor();
|
|
6
|
+
abstract subscribe_wallet_raw_txn_event(): void;
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseTradeAppConfig = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const ensure_core_env_1 = require("./ensure_core_env");
|
|
6
|
+
class BaseTradeAppConfig extends ttd_core_1.AbstractTradeAppConfig {
|
|
7
|
+
constructor() {
|
|
8
|
+
(0, ensure_core_env_1.ensureCoreEnv)();
|
|
9
|
+
super();
|
|
10
|
+
this.env_args = (0, ttd_core_1.getCoreEnv)();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BaseTradeAppConfig = BaseTradeAppConfig;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseDexEnvArgs = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
const base_env_args_1 = require("./base_env_args");
|
|
6
|
+
class BaseDexEnvArgs extends base_env_args_1.BaseEnvArgs {
|
|
7
|
+
constructor() {
|
|
8
|
+
super();
|
|
9
|
+
const cfg = this._cfg;
|
|
10
|
+
this.app_name = (cfg.app_name || '').toLowerCase();
|
|
11
|
+
this.chain_id = (cfg.chain_id || '').toUpperCase();
|
|
12
|
+
this.dex_id = (cfg.dex_id || '').toUpperCase();
|
|
13
|
+
this.server_id = cfg.server_id ?? '';
|
|
14
|
+
this.redis_host = cfg.redis_host;
|
|
15
|
+
this.redis_port = String(cfg.redis_port);
|
|
16
|
+
this.rpc_endpoint = cfg.rpc_endpoint;
|
|
17
|
+
this.ws_endpoint = cfg.ws_endpoint;
|
|
18
|
+
this.pair = cfg.pair ?? '';
|
|
19
|
+
this.group_id = cfg.group_id ?? '';
|
|
20
|
+
this.quote_pool_address = cfg.quote_pool_address;
|
|
21
|
+
this.quote_pool_name = cfg.quote_pool_name;
|
|
22
|
+
this.quote_pool_fee_rate = cfg.quote_pool_fee_rate;
|
|
23
|
+
this.quote_amount_usd = cfg.quote_amount_usd;
|
|
24
|
+
this.wallet_dir = cfg.wallet_dir;
|
|
25
|
+
this.encryption_key = cfg.encryption_key ?? '';
|
|
26
|
+
this.server_ip_list = cfg.server_ip_list ?? '';
|
|
27
|
+
this.ip_exclude_prefix = cfg.ip_exclude_prefix ?? '';
|
|
28
|
+
this.namespace = cfg.namespace ?? '';
|
|
29
|
+
this.trade_analyze_host = cfg.trade_analyze_host ?? '';
|
|
30
|
+
this.gas_price_gwei = cfg.gas_price_gwei;
|
|
31
|
+
this.gas_limit = cfg.gas_limit;
|
|
32
|
+
this.tip_amount_gwei = cfg.tip_amount_gwei;
|
|
33
|
+
this.gas_max_limit = cfg.gas_max_limit;
|
|
34
|
+
this.gas_max_price_gwei = cfg.gas_max_price_gwei;
|
|
35
|
+
this.gas_max_fee_per_gas_gwei = cfg.gas_max_fee_per_gas_gwei;
|
|
36
|
+
this.gas_max_priority_fee_gwei = cfg.gas_max_priority_fee_gwei;
|
|
37
|
+
this.gas_max_tip_amount_gwei = cfg.gas_max_tip_amount_gwei;
|
|
38
|
+
this.aerodrome_executor_id = cfg.aerodrome_executor_id;
|
|
39
|
+
this.uniswap_executor_id = cfg.uniswap_executor_id;
|
|
40
|
+
this.caller_select_strategy = cfg.caller_select_strategy;
|
|
41
|
+
this.send_tx_ws_host = cfg.send_tx_ws_host;
|
|
42
|
+
this.send_tx_direct_rpc = cfg.send_tx_direct_rpc;
|
|
43
|
+
this.base_rpc_endpoint = cfg.base_rpc_endpoint;
|
|
44
|
+
this.send_tx_backup_rpc = cfg.send_tx_backup_rpc;
|
|
45
|
+
this.base_backup_rpc_endpoint = cfg.base_backup_rpc_endpoint;
|
|
46
|
+
this.send_tx_timeout_ms = cfg.send_tx_timeout_ms;
|
|
47
|
+
this.send_tx_blockrazor = cfg.send_tx_blockrazor;
|
|
48
|
+
this.blockrazor_endpoint = cfg.blockrazor_endpoint;
|
|
49
|
+
this.blockrazor_auth_token = cfg.blockrazor_auth_token;
|
|
50
|
+
this.blockrazor_tip_amount_wei = cfg.blockrazor_tip_amount_wei;
|
|
51
|
+
this.blockrazor_tip_address = cfg.blockrazor_tip_address;
|
|
52
|
+
this.send_tx_bloxroute = cfg.send_tx_bloxroute;
|
|
53
|
+
this.bloxroute_endpoint = cfg.bloxroute_endpoint;
|
|
54
|
+
this.bloxroute_auth_token = cfg.bloxroute_auth_token;
|
|
55
|
+
this.bloxroute_backrunme_address = cfg.bloxroute_backrunme_address;
|
|
56
|
+
this.stream_quote_ws_host = cfg.stream_quote_ws_host;
|
|
57
|
+
this.min_quote_interval_ms = cfg.min_quote_interval_ms;
|
|
58
|
+
this.use_pricefeed_for_orderbook = cfg.use_pricefeed_for_orderbook;
|
|
59
|
+
this.trade_parse_fetch_block_time = cfg.trade_parse_fetch_block_time;
|
|
60
|
+
this.tick_cache_neighboring_words = cfg.tick_cache_neighboring_words;
|
|
61
|
+
this.tick_cache_ttl = cfg.tick_cache_ttl;
|
|
62
|
+
this.tick_cache_min_update_interval = cfg.tick_cache_min_update_interval;
|
|
63
|
+
}
|
|
64
|
+
print(moduleName) {
|
|
65
|
+
(0, dist_1.printEnvConfig)(moduleName || this.app_name || 'base-dex', this);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.BaseDexEnvArgs = BaseDexEnvArgs;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { EnvArgs } from '@clonegod/ttd-core';
|
|
2
|
+
export declare class BaseEnvArgs extends EnvArgs {
|
|
3
|
+
gas_price_gwei: number;
|
|
4
|
+
gas_limit: number;
|
|
5
|
+
tip_amount_gwei: number;
|
|
6
|
+
gas_max_limit: number;
|
|
7
|
+
gas_max_price_gwei: number;
|
|
8
|
+
gas_max_fee_per_gas_gwei: number;
|
|
9
|
+
gas_max_priority_fee_gwei: number;
|
|
10
|
+
gas_max_tip_amount_gwei: number;
|
|
11
|
+
large_trade_threshold_usd: number;
|
|
12
|
+
aerodrome_executor_id: string;
|
|
13
|
+
uniswap_executor_id: string;
|
|
14
|
+
caller_select_strategy: string;
|
|
15
|
+
tx_status_check_interval_mills: number;
|
|
16
|
+
tx_cancel_timeout_ms: number;
|
|
17
|
+
tx_cancel_gas_boost_factor: number;
|
|
18
|
+
send_tx_ws_host: string;
|
|
19
|
+
send_tx_direct_rpc: boolean;
|
|
20
|
+
base_rpc_endpoint: string;
|
|
21
|
+
send_tx_backup_rpc: boolean;
|
|
22
|
+
base_backup_rpc_endpoint: string;
|
|
23
|
+
send_tx_timeout_ms: number;
|
|
24
|
+
send_tx_blockrazor: boolean;
|
|
25
|
+
blockrazor_endpoint: string;
|
|
26
|
+
blockrazor_auth_token: string;
|
|
27
|
+
blockrazor_tip_amount_wei: number;
|
|
28
|
+
blockrazor_tip_address: string;
|
|
29
|
+
send_tx_bloxroute: boolean;
|
|
30
|
+
bloxroute_endpoint: string;
|
|
31
|
+
bloxroute_auth_token: string;
|
|
32
|
+
bloxroute_backrunme_address: string;
|
|
33
|
+
stream_quote_ws_host: string;
|
|
34
|
+
min_quote_interval_ms: number;
|
|
35
|
+
use_pricefeed_for_orderbook: boolean;
|
|
36
|
+
trade_parse_fetch_block_time: boolean;
|
|
37
|
+
tick_cache_neighboring_words: number;
|
|
38
|
+
tick_cache_ttl: number;
|
|
39
|
+
tick_cache_min_update_interval: number;
|
|
40
|
+
flashblocks_enabled: boolean;
|
|
41
|
+
flashblocks_quicknode_wss: string;
|
|
42
|
+
flashblocks_dedup_ttl_ms: number;
|
|
43
|
+
flashblocks_health_window_s: number;
|
|
44
|
+
flashblocks_min_hit_rate: number;
|
|
45
|
+
ws_push_enable: boolean;
|
|
46
|
+
print_event_data: boolean;
|
|
47
|
+
pool_sync_interval_ms: number;
|
|
48
|
+
redis_url: string;
|
|
49
|
+
skip_pool_list: string;
|
|
50
|
+
price_feed_skip_dup: boolean;
|
|
51
|
+
price_feed_client_id: string;
|
|
52
|
+
trade_analyze_port: number;
|
|
53
|
+
log_max_size_mb: number;
|
|
54
|
+
log_check_interval_min: number;
|
|
55
|
+
log_dir: string;
|
|
56
|
+
block_stale_ms: number;
|
|
57
|
+
chain_name: string;
|
|
58
|
+
caller_balance_check_interval: string;
|
|
59
|
+
caller_balance_low_threshold: string;
|
|
60
|
+
caller_balance_empty_threshold: string;
|
|
61
|
+
gecko_network: string;
|
|
62
|
+
chain_id_num: number;
|
|
63
|
+
native_token_symbol: string;
|
|
64
|
+
native_token_address: string;
|
|
65
|
+
wrapped_native_address: string;
|
|
66
|
+
sync_pool_interval_ms: number;
|
|
67
|
+
fetch_api_wait_ms: number;
|
|
68
|
+
fetch_min_tvl: number;
|
|
69
|
+
fetch_min_vol: number;
|
|
70
|
+
pool_default_tvl: number;
|
|
71
|
+
fetch_max_page_no: number;
|
|
72
|
+
token_batch_size: number;
|
|
73
|
+
fetch_on_startup: boolean;
|
|
74
|
+
vault_mgt_rpc_url: string;
|
|
75
|
+
vault_mgt_chain_id: number;
|
|
76
|
+
vault_mgt_chain_name: string;
|
|
77
|
+
vault_mgt_vault_groups: string;
|
|
78
|
+
vault_mgt_native_symbol: string;
|
|
79
|
+
vault_mgt_wrapped_native_address: string;
|
|
80
|
+
vault_mgt_fund_caller_max: string;
|
|
81
|
+
constructor();
|
|
82
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEnvArgs = void 0;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const constants_1 = require("../common/constants");
|
|
6
|
+
(0, ttd_core_1.registerEnvVars)({
|
|
7
|
+
gas_price_gwei: { env: 'GAS_PRICE_GWEI', type: 'number', default: 1, desc: 'Legacy gasPrice 默认值(Gwei)' },
|
|
8
|
+
gas_limit: { env: 'GAS_LIMIT', type: 'number', default: 300000, desc: '交易 gas 默认值。本系统单池子 swap 场景 ~200-400k 已够;运行时由 strategy.evm_gas_limit 覆盖' },
|
|
9
|
+
tip_amount_gwei: { env: 'TIP_AMOUNT_GWEI', type: 'number', default: 10000, desc: 'Builder tip 默认值(Gwei)' },
|
|
10
|
+
gas_max_limit: { env: 'GAS_MAX_LIMIT', type: 'number', default: 1000000, desc: '单 tx gas 上限。本系统是单池子 swap 套利,不跑 batch;超过此值大概率是配置错误。Base Flashblock #1 容量是 18.75M(=1/10 块 gas @ ~187.5M block limit),1M 远低于该阈值,inclusion 速度不受影响' },
|
|
11
|
+
gas_max_price_gwei: { env: 'GAS_MAX_PRICE_GWEI', type: 'number', default: 1, desc: 'Legacy gasPrice 上限(Gwei)。Base L2 sequencer fee 通常 < 0.1 gwei,1 gwei 是宽裕上限' },
|
|
12
|
+
gas_max_fee_per_gas_gwei: { env: 'GAS_MAX_FEE_PER_GAS_GWEI', type: 'number', default: 1, desc: 'EIP-1559 maxFeePerGas 上限(Gwei)' },
|
|
13
|
+
gas_max_priority_fee_gwei: { env: 'GAS_MAX_PRIORITY_FEE_GWEI', type: 'number', default: 0.5, desc: 'EIP-1559 maxPriorityFeePerGas 上限(Gwei)。Base 上 0.01-0.05 已是高优先档' },
|
|
14
|
+
gas_max_tip_amount_gwei: { env: 'GAS_MAX_TIP_AMOUNT_GWEI', type: 'number', default: 500000, desc: 'Builder tip 上限(Gwei)' },
|
|
15
|
+
large_trade_threshold_usd: { env: 'LARGE_TRADE_THRESHOLD_USD', type: 'number', default: 500, desc: '识别询价中的大额交易阈值(USD)' },
|
|
16
|
+
aerodrome_executor_id: { env: 'AERODROME_EXECUTOR_ID', type: 'string', default: 'AERODROME', desc: 'Vault 中 Aerodrome executor 注册名(keccak256 后作为 bytes32)' },
|
|
17
|
+
uniswap_executor_id: { env: 'UNISWAP_EXECUTOR_ID', type: 'string', default: 'UNISWAP', desc: 'Vault 中 Uniswap executor 注册名(keccak256 后作为 bytes32)' },
|
|
18
|
+
caller_select_strategy: { env: 'CALLER_SELECT_STRATEGY', type: 'string', default: 'lock', desc: 'CallerManager LRU 选择策略:lock=Redis 分布式锁(默认) | lua_cas=Lua 原子脚本' },
|
|
19
|
+
tx_status_check_interval_mills: { env: 'TX_STATUS_CHECK_INTERVAL_MILLS', type: 'number', default: 3000, desc: '链上 tx 状态轮询间隔(ms)' },
|
|
20
|
+
tx_cancel_timeout_ms: { env: 'TX_CANCEL_TIMEOUT_MS', type: 'number', default: 15000, desc: '交易取消超时(ms)' },
|
|
21
|
+
tx_cancel_gas_boost_factor: { env: 'TX_CANCEL_GAS_PRICE_BOOST_FACTOR', type: 'number', default: 1.5, desc: '取消交易 gas 提升倍数' },
|
|
22
|
+
send_tx_ws_host: { env: 'SEND_TX_WS_HOST', type: 'string', default: '127.0.0.1', desc: 'trader WS 客户端连接的 send-tx 服务 host' },
|
|
23
|
+
send_tx_direct_rpc: { env: 'SEND_TX_DIRECT_RPC', type: 'boolean', default: true, desc: '直发 BASE sequencer RPC(主路径)' },
|
|
24
|
+
base_rpc_endpoint: { env: 'BASE_RPC_ENDPOINT', type: 'string', default: 'https://mainnet.base.org', desc: 'BASE sequencer RPC 端点(direct_rpc 用)。生产可换 Alchemy / QuickNode private endpoint 提速' },
|
|
25
|
+
send_tx_backup_rpc: { env: 'SEND_TX_BACKUP_RPC', type: 'boolean', default: false, desc: '备用 RPC 通道(同 chain,不同 provider 做冗余)' },
|
|
26
|
+
base_backup_rpc_endpoint: { env: 'BASE_BACKUP_RPC_ENDPOINT', type: 'string', default: '', desc: '备用 RPC URL(如 https://base.publicnode.com)' },
|
|
27
|
+
send_tx_timeout_ms: { env: 'SEND_TX_TIMEOUT_MS', type: 'number', default: 3000, desc: '单通道发送超时(ms)' },
|
|
28
|
+
send_tx_blockrazor: { env: 'SEND_TX_BLOCKRAZOR', type: 'boolean', default: false, desc: '启用 BlockRazor 通道并发提交' },
|
|
29
|
+
blockrazor_endpoint: { env: 'BLOCKRAZOR_ENDPOINT', type: 'string', default: 'http://base-fast.blockrazor.io', desc: 'BlockRazor BASE Fast endpoint' },
|
|
30
|
+
blockrazor_auth_token: { env: 'BLOCKRAZOR_AUTH_TOKEN', type: 'string', default: '', desc: 'BlockRazor Bearer token(Authorization: Bearer <token>)' },
|
|
31
|
+
blockrazor_tip_amount_wei: { env: 'BLOCKRAZOR_TIP_AMOUNT_WEI', type: 'number', default: 3000000000000, desc: 'BlockRazor tip 数量(wei)。默认 3e12 wei = 0.000003 ETH (BlockRazor 文档最低要求)' },
|
|
32
|
+
blockrazor_tip_address: { env: 'BLOCKRAZOR_TIP_ADDRESS', type: 'string', default: '0x9D70AC39166ca154307a93fa6b595CF7962fe8e5', desc: 'BlockRazor tip 收款地址(默认值来自 BlockRazor 文档)' },
|
|
33
|
+
send_tx_bloxroute: { env: 'SEND_TX_BLOXROUTE', type: 'boolean', default: false, desc: '启用 bloXroute 通道并发提交' },
|
|
34
|
+
bloxroute_endpoint: { env: 'BLOXROUTE_ENDPOINT', type: 'string', default: 'https://api.blxrbdn.com', desc: 'bloXroute API endpoint' },
|
|
35
|
+
bloxroute_auth_token: { env: 'BLOXROUTE_AUTH_TOKEN', type: 'string', default: '', desc: 'bloXroute Authorization header(直接放完整 token,不要前缀)' },
|
|
36
|
+
bloxroute_backrunme_address: { env: 'BLOXROUTE_BACKRUNME_ADDRESS', type: 'string', default: '', desc: '可选:bloXroute backrun 回扣收款钱包' },
|
|
37
|
+
stream_quote_ws_host: { env: 'STREAM_QUOTE_WS_HOST', type: 'string', default: '127.0.0.1', desc: 'stream-quote WS 地址' },
|
|
38
|
+
min_quote_interval_ms: { env: 'MIN_QUOTE_INTERVAL_MS', type: 'number', default: 10000, desc: '最小询价间隔(ms)' },
|
|
39
|
+
use_pricefeed_for_orderbook: { env: 'USE_PRICEFEED_FOR_ORDERBOOK', type: 'boolean', default: false, desc: 'PriceFeed (v3 source) 报价是否推 orderbook' },
|
|
40
|
+
trade_parse_fetch_block_time: { env: 'TRADE_PARSE_FETCH_BLOCK_TIME', type: 'boolean', default: false, desc: '解析交易 receipt 时是否额外 RPC 查询 block 时间戳' },
|
|
41
|
+
flashblocks_enabled: { env: 'FLASHBLOCKS_ENABLED', type: 'boolean', default: true, desc: 'Flashblocks pending logs 主路径开关' },
|
|
42
|
+
flashblocks_quicknode_wss: { env: 'FLASHBLOCKS_QUICKNODE_WSS', type: 'string', default: '', desc: 'QuickNode Flashblocks WSS endpoint(FLASHBLOCKS_ENABLED=true 时必填;不提供默认值,避免误用 demo endpoint)' },
|
|
43
|
+
flashblocks_dedup_ttl_ms: { env: 'FLASHBLOCKS_DEDUP_TTL_MS', type: 'number', default: 30000, desc: '事件去重 TTL:Flashblocks + 标准 WSS 同 tx 重复推送的去重窗口(ms)' },
|
|
44
|
+
flashblocks_health_window_s: { env: 'FLASHBLOCKS_HEALTH_WINDOW_S', type: 'number', default: 60, desc: 'pending→final 命中率统计滚动窗口(s)' },
|
|
45
|
+
flashblocks_min_hit_rate: { env: 'FLASHBLOCKS_MIN_HIT_RATE', type: 'number', default: 0.95, desc: 'pending→final 命中率低于此阈值则标记 Flashblocks 异常并 alert' },
|
|
46
|
+
tick_cache_neighboring_words: { env: 'TICK_CACHE_NEIGHBORING_WORDS', type: 'number', default: 2, desc: 'tick 预加载 words 数' },
|
|
47
|
+
tick_cache_ttl: { env: 'TICK_CACHE_TTL', type: 'number', default: 30000, desc: 'tick 缓存 TTL(ms)' },
|
|
48
|
+
tick_cache_min_update_interval: { env: 'TICK_CACHE_MIN_UPDATE_INTERVAL', type: 'number', default: 3000, desc: 'tick 最小刷新间隔(ms)' },
|
|
49
|
+
ws_push_enable: { env: 'WS_PUSH_ENABLE', type: 'boolean', default: true, desc: 'WS 推送开关' },
|
|
50
|
+
print_event_data: { env: 'PRINT_EVENT_DATA', type: 'boolean', default: false, desc: '打印原始事件数据' },
|
|
51
|
+
pool_sync_interval_ms: { env: 'POOL_SYNC_INTERVAL_MS', type: 'number', default: 5000, desc: '池子同步间隔(ms)' },
|
|
52
|
+
redis_url: { env: 'REDIS_URL', type: 'string', default: 'redis://127.0.0.1:6379', desc: 'Redis 连接 URL' },
|
|
53
|
+
skip_pool_list: { env: 'SKIP_POOL_LIST', type: 'string', default: '', desc: '跳过的池子名称列表(逗号分隔)' },
|
|
54
|
+
price_feed_skip_dup: { env: 'PRICE_FEED_SKIP_DUP', type: 'boolean', default: false, desc: 'PriceFeed 去重过滤' },
|
|
55
|
+
price_feed_client_id: { env: 'PRICE_FEED_CLIENT_ID', type: 'string', default: 'BASE_DC', desc: 'PriceFeed 订阅消息里的 client 标识' },
|
|
56
|
+
trade_analyze_port: { env: 'TRADE_ANALYZE_PORT', type: 'number', default: 8004, desc: '上报 analyze 的 HTTP 端口' },
|
|
57
|
+
log_max_size_mb: { env: 'LOG_MAX_SIZE_MB', type: 'number', default: 20, desc: '日志文件大小上限(MB)' },
|
|
58
|
+
log_check_interval_min: { env: 'LOG_CHECK_INTERVAL_MIN', type: 'number', default: 10, desc: '日志检查间隔(分钟)' },
|
|
59
|
+
log_dir: { env: 'LOG_DIR', type: 'string', default: 'logs', desc: '日志目录' },
|
|
60
|
+
block_stale_ms: { env: 'BLOCK_STALE_MS', type: 'number', default: 3000, desc: '收不到 block 多久视为 stale(ms)。BASE 2s 块设 3000(漏 ~1.5 块即重连)' },
|
|
61
|
+
chain_name: { env: 'CHAIN_NAME', type: 'string', default: '', desc: '链名称(Redis key 前缀),stream-trade 建议必填' },
|
|
62
|
+
caller_balance_check_interval: { env: 'CALLER_BALANCE_CHECK_INTERVAL', type: 'string', default: '1h', desc: 'caller 余额检查周期' },
|
|
63
|
+
caller_balance_low_threshold: { env: 'CALLER_BALANCE_LOW_THRESHOLD', type: 'string', default: '0.01', desc: 'caller 低余额阈值' },
|
|
64
|
+
caller_balance_empty_threshold: { env: 'CALLER_BALANCE_EMPTY_THRESHOLD', type: 'string', default: '0', desc: 'caller 耗尽阈值' },
|
|
65
|
+
gecko_network: { env: 'GECKO_NETWORK', type: 'string', default: 'base', desc: 'GeckoTerminal 网络标识(base)' },
|
|
66
|
+
chain_id_num: { env: 'CHAIN_ID_NUM', type: 'number', default: 8453, desc: 'BASE 链 ID 数字' },
|
|
67
|
+
native_token_symbol: { env: 'NATIVE_TOKEN_SYMBOL', type: 'string', default: 'ETH', desc: '原生代币符号' },
|
|
68
|
+
native_token_address: { env: 'NATIVE_TOKEN_ADDRESS', type: 'string', default: constants_1.NATIVE_ETH_ADDRESS, desc: '原生代币地址' },
|
|
69
|
+
wrapped_native_address: { env: 'WRAPPED_NATIVE_ADDRESS', type: 'string', default: constants_1.WETH_ADDRESS, desc: 'Wrapped 代币地址(WETH on BASE)' },
|
|
70
|
+
sync_pool_interval_ms: { env: 'SYNC_POOL_INTERVAL_MS', type: 'number', default: 3600000, desc: '定时池子全量同步间隔(ms)' },
|
|
71
|
+
fetch_api_wait_ms: { env: 'FETCH_API_WAIT_MS', type: 'number', default: 6000, desc: 'Gecko/DefiLlama 外部 API 调用间隔(ms)' },
|
|
72
|
+
fetch_min_tvl: { env: 'FETCH_MIN_TVL', type: 'number', default: 50000, desc: '最小 TVL(USD)' },
|
|
73
|
+
fetch_min_vol: { env: 'FETCH_MIN_VOL', type: 'number', default: 100000, desc: '最小 24h 成交量(USD)' },
|
|
74
|
+
pool_default_tvl: { env: 'POOL_DEFAULT_TVL', type: 'number', default: 100000, desc: '默认 TVL' },
|
|
75
|
+
fetch_max_page_no: { env: 'FETCH_MAX_PAGE_NO', type: 'number', default: 10, desc: '最大翻页数' },
|
|
76
|
+
token_batch_size: { env: 'TOKEN_BATCH_SIZE', type: 'number', default: 10, desc: 'token 批量大小' },
|
|
77
|
+
fetch_on_startup: { env: 'FETCH_ON_STARTUP', type: 'boolean', default: true, desc: '启动时立即执行' },
|
|
78
|
+
vault_mgt_rpc_url: { env: 'VAULT_MGT_RPC_URL', type: 'string', default: '', desc: 'Vault 管理 RPC' },
|
|
79
|
+
vault_mgt_chain_id: { env: 'VAULT_MGT_CHAIN_ID', type: 'number', default: 0, desc: '链 ID 数字' },
|
|
80
|
+
vault_mgt_chain_name: { env: 'VAULT_MGT_CHAIN_NAME', type: 'string', default: '', desc: '链名称' },
|
|
81
|
+
vault_mgt_vault_groups: { env: 'VAULT_MGT_VAULT_GROUPS', type: 'string', default: '', desc: 'Vault 分组列表(逗号分隔)' },
|
|
82
|
+
vault_mgt_native_symbol: { env: 'VAULT_MGT_NATIVE_SYMBOL', type: 'string', default: '', desc: '原生代币符号' },
|
|
83
|
+
vault_mgt_wrapped_native_address: { env: 'VAULT_MGT_WRAPPED_NATIVE_ADDRESS', type: 'string', default: '', desc: 'Wrapped 代币地址' },
|
|
84
|
+
vault_mgt_fund_caller_max: { env: 'VAULT_MGT_FUND_CALLER_MAX', type: 'string', default: '', desc: 'Caller 充值上限' },
|
|
85
|
+
});
|
|
86
|
+
class BaseEnvArgs extends ttd_core_1.EnvArgs {
|
|
87
|
+
constructor() {
|
|
88
|
+
super();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.BaseEnvArgs = BaseEnvArgs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function ensureCoreEnv(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ensureCoreEnv = ensureCoreEnv;
|
|
4
|
+
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
5
|
+
const base_dex_env_args_1 = require("./base_dex_env_args");
|
|
6
|
+
let _ensured = false;
|
|
7
|
+
function ensureCoreEnv() {
|
|
8
|
+
if (_ensured)
|
|
9
|
+
return;
|
|
10
|
+
try {
|
|
11
|
+
(0, ttd_core_1.getCoreEnv)();
|
|
12
|
+
_ensured = true;
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
(0, ttd_core_1.setCoreEnv)(new base_dex_env_args_1.BaseDexEnvArgs());
|
|
16
|
+
_ensured = true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
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("./base_env_args"), exports);
|
|
18
|
+
__exportStar(require("./base_dex_env_args"), exports);
|
|
19
|
+
__exportStar(require("./BaseQuoteAppConfig"), exports);
|
|
20
|
+
__exportStar(require("./BaseTradeAppConfig"), exports);
|
|
21
|
+
__exportStar(require("./ensure_core_env"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './common';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './appconfig';
|
|
3
3
|
export * from './quote';
|
|
4
4
|
export * from './trade';
|
|
5
5
|
export * from './types';
|
|
6
6
|
export * from './utils';
|
|
7
7
|
export * from './redis';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './send-tx';
|
package/dist/index.js
CHANGED
|
@@ -15,10 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
-
__exportStar(require("./
|
|
18
|
+
__exportStar(require("./appconfig"), exports);
|
|
19
19
|
__exportStar(require("./quote"), exports);
|
|
20
20
|
__exportStar(require("./trade"), exports);
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
22
|
__exportStar(require("./utils"), exports);
|
|
23
23
|
__exportStar(require("./redis"), exports);
|
|
24
|
-
__exportStar(require("./
|
|
24
|
+
__exportStar(require("./send-tx"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface AmmDepthInput {
|
|
2
|
+
reserve0: string;
|
|
3
|
+
reserve1: string;
|
|
4
|
+
targetBps: number;
|
|
5
|
+
isBuy: boolean;
|
|
6
|
+
baseIsToken0: boolean;
|
|
7
|
+
token0Decimals: number;
|
|
8
|
+
token1Decimals: number;
|
|
9
|
+
}
|
|
10
|
+
export interface AmmDepthResult {
|
|
11
|
+
amountOutWei: bigint;
|
|
12
|
+
amountOut: number;
|
|
13
|
+
outputDecimals: number;
|
|
14
|
+
amountInWei: bigint;
|
|
15
|
+
amountIn: number;
|
|
16
|
+
inputDecimals: number;
|
|
17
|
+
targetPrice: number;
|
|
18
|
+
}
|
|
19
|
+
export declare function calculateAmmDepth(input: AmmDepthInput): AmmDepthResult;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateAmmDepth = calculateAmmDepth;
|
|
4
|
+
const clmm_depth_calculator_1 = require("./clmm_depth_calculator");
|
|
5
|
+
function calculateAmmDepth(input) {
|
|
6
|
+
const { targetBps, isBuy, baseIsToken0, token0Decimals, token1Decimals } = input;
|
|
7
|
+
const R0 = BigInt(input.reserve0);
|
|
8
|
+
const R1 = BigInt(input.reserve1);
|
|
9
|
+
if (R0 === 0n || R1 === 0n) {
|
|
10
|
+
return { amountOutWei: 0n, amountOut: 0, outputDecimals: 0, amountInWei: 0n, amountIn: 0, inputDecimals: 0, targetPrice: 0 };
|
|
11
|
+
}
|
|
12
|
+
const k = R0 * R1;
|
|
13
|
+
const bps = BigInt(targetBps);
|
|
14
|
+
const PRECISION = 10n ** 18n;
|
|
15
|
+
let amountOutWei;
|
|
16
|
+
let amountInWei;
|
|
17
|
+
let outputDecimals;
|
|
18
|
+
let inputDecimals;
|
|
19
|
+
if (isBuy) {
|
|
20
|
+
const [baseReserve, quoteReserve] = baseIsToken0 ? [R0, R1] : [R1, R0];
|
|
21
|
+
outputDecimals = baseIsToken0 ? token0Decimals : token1Decimals;
|
|
22
|
+
inputDecimals = baseIsToken0 ? token1Decimals : token0Decimals;
|
|
23
|
+
const baseReserveNew = baseReserve * (0, clmm_depth_calculator_1.bigIntSqrt)(10000n * PRECISION) / (0, clmm_depth_calculator_1.bigIntSqrt)((10000n + bps) * PRECISION);
|
|
24
|
+
const quoteReserveNew = quoteReserve * (0, clmm_depth_calculator_1.bigIntSqrt)((10000n + bps) * PRECISION) / (0, clmm_depth_calculator_1.bigIntSqrt)(10000n * PRECISION);
|
|
25
|
+
amountOutWei = baseReserve - baseReserveNew;
|
|
26
|
+
amountInWei = quoteReserveNew - quoteReserve;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const [baseReserve, quoteReserve] = baseIsToken0 ? [R0, R1] : [R1, R0];
|
|
30
|
+
outputDecimals = baseIsToken0 ? token1Decimals : token0Decimals;
|
|
31
|
+
inputDecimals = baseIsToken0 ? token0Decimals : token1Decimals;
|
|
32
|
+
if (bps >= 10000n) {
|
|
33
|
+
amountOutWei = quoteReserve;
|
|
34
|
+
amountInWei = baseReserve;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const quoteReserveNew = quoteReserve * (0, clmm_depth_calculator_1.bigIntSqrt)((10000n - bps) * PRECISION) / (0, clmm_depth_calculator_1.bigIntSqrt)(10000n * PRECISION);
|
|
38
|
+
const baseReserveNew = baseReserve * (0, clmm_depth_calculator_1.bigIntSqrt)(10000n * PRECISION) / (0, clmm_depth_calculator_1.bigIntSqrt)((10000n - bps) * PRECISION);
|
|
39
|
+
amountOutWei = quoteReserve - quoteReserveNew;
|
|
40
|
+
amountInWei = baseReserveNew - baseReserve;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const amountOut = Number(amountOutWei) / Math.pow(10, outputDecimals);
|
|
44
|
+
const amountIn = Number(amountInWei) / Math.pow(10, inputDecimals);
|
|
45
|
+
const baseDec = baseIsToken0 ? token0Decimals : token1Decimals;
|
|
46
|
+
const quoteDec = baseIsToken0 ? token1Decimals : token0Decimals;
|
|
47
|
+
const baseReserveUi = Number(baseIsToken0 ? R0 : R1) / Math.pow(10, baseDec);
|
|
48
|
+
const quoteReserveUi = Number(baseIsToken0 ? R1 : R0) / Math.pow(10, quoteDec);
|
|
49
|
+
const midPrice = quoteReserveUi / baseReserveUi;
|
|
50
|
+
const bpsNum = Number(targetBps);
|
|
51
|
+
const targetPrice = isBuy
|
|
52
|
+
? midPrice * (10000 + bpsNum) / 10000
|
|
53
|
+
: midPrice * (10000 - bpsNum) / 10000;
|
|
54
|
+
return { amountOutWei, amountOut, outputDecimals, amountInWei, amountIn, inputDecimals, targetPrice };
|
|
55
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClmmTickCache } from '../tick/clmm_tick_cache';
|
|
2
|
+
declare function getSqrtRatioAtTick(tick: number): bigint;
|
|
3
|
+
export interface ClmmDepthInput {
|
|
4
|
+
poolAddress: string;
|
|
5
|
+
tickCache: ClmmTickCache;
|
|
6
|
+
currentTick: number;
|
|
7
|
+
sqrtPriceX96: string;
|
|
8
|
+
liquidity: string;
|
|
9
|
+
tickSpacing: number;
|
|
10
|
+
zeroForOne: boolean;
|
|
11
|
+
targetBps: number;
|
|
12
|
+
inputDecimals: number;
|
|
13
|
+
outputDecimals: number;
|
|
14
|
+
}
|
|
15
|
+
export interface DepthResult {
|
|
16
|
+
amountInWei: bigint;
|
|
17
|
+
amountIn: number;
|
|
18
|
+
amountOutWei: bigint;
|
|
19
|
+
amountOut: number;
|
|
20
|
+
currentTick: number;
|
|
21
|
+
targetTick: number;
|
|
22
|
+
targetSqrtPriceX96: bigint;
|
|
23
|
+
}
|
|
24
|
+
export declare function calculateClmmDepth(input: ClmmDepthInput): DepthResult;
|
|
25
|
+
export declare function priceFromSqrtX96(sqrtPriceX96: bigint, baseDecimals: number, quoteDecimals: number, baseIsToken0: boolean): number;
|
|
26
|
+
declare function computeTargetSqrtPrice(currentSqrtPriceX96: bigint, bps: number, zeroForOne: boolean): bigint;
|
|
27
|
+
declare function bigIntSqrt(n: bigint): bigint;
|
|
28
|
+
export { getSqrtRatioAtTick, computeTargetSqrtPrice, bigIntSqrt };
|