@clonegod/ttd-bsc-common 3.0.21 → 3.0.23
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/event/pool_event_listener.js +3 -3
- package/dist/trade/abstract_dex_trade.js +21 -24
- package/dist/trade/caller_manager.d.ts +1 -1
- package/dist/trade/check/base_tx_result_checker.d.ts +1 -2
- package/dist/trade/check/base_tx_result_checker.js +2 -2
- package/dist/trade/parse/base_parser.d.ts +1 -2
- package/dist/trade/parse/base_parser.js +3 -2
- package/dist/types/event_types.d.ts +3 -3
- package/dist/utils/ethers_compat.d.ts +13 -0
- package/dist/utils/ethers_compat.js +19 -0
- package/dist/utils/gas_helper.d.ts +2 -2
- package/dist/utils/gas_helper.js +7 -6
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.js +3 -2
- package/dist/ws/subscribe_v2_events.js +2 -1
- package/dist/ws/subscribe_v3_events.js +2 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PoolEventListener = void 0;
|
|
13
|
-
const
|
|
13
|
+
const ethers_compat_1 = require("../../utils/ethers_compat");
|
|
14
14
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
15
15
|
const common_1 = require("../../common");
|
|
16
16
|
const CONFIG = {
|
|
@@ -46,7 +46,7 @@ class PoolEventListener {
|
|
|
46
46
|
}
|
|
47
47
|
init(poolList) {
|
|
48
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
this.poolList = poolList.filter(pool =>
|
|
49
|
+
this.poolList = poolList.filter(pool => ethers_compat_1.ethersCompat.isAddress(pool.pool_address));
|
|
50
50
|
if (this.poolList.length !== poolList.length) {
|
|
51
51
|
(0, ttd_core_1.log_warn)(`Found ${poolList.length - this.poolList.length} invalid pool addresses, filtered out`, '');
|
|
52
52
|
}
|
|
@@ -79,7 +79,7 @@ class PoolEventListener {
|
|
|
79
79
|
for (let i = 0; i < CONFIG.MAX_RETRIES; i++) {
|
|
80
80
|
try {
|
|
81
81
|
(0, ttd_core_1.log_info)(`Connecting to WebSocket: ${this.ws_endpoint} (Attempt ${i + 1}/${CONFIG.MAX_RETRIES})`);
|
|
82
|
-
this.wsProvider = new
|
|
82
|
+
this.wsProvider = new ethers_compat_1.ethersCompat.WebSocketProvider(this.ws_endpoint);
|
|
83
83
|
const wsPromise = this.wsProvider.ready;
|
|
84
84
|
const timeoutPromise = new Promise((_, reject) => {
|
|
85
85
|
setTimeout(() => reject(new Error('WebSocket connection timeout')), CONFIG.CONNECTION_TIMEOUT);
|
|
@@ -11,25 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
|
-
var _a, _b, _c, _d, _e, _f;
|
|
15
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
15
|
exports.AbstractDexTrade = void 0;
|
|
17
16
|
exports.buildTradeConfig = buildTradeConfig;
|
|
18
17
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
19
|
-
const ethers_1 = require("ethers");
|
|
20
18
|
const caller_manager_1 = require("./caller_manager");
|
|
21
19
|
const ttd_bsc_send_tx_1 = require("@clonegod/ttd-bsc-send-tx");
|
|
22
20
|
const redis_1 = require("../redis");
|
|
23
21
|
const trade_direction_1 = require("../utils/trade_direction");
|
|
22
|
+
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
24
23
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
25
|
-
const ethersCompat = {
|
|
26
|
-
Interface: ((_a = ethers_1.ethers.utils) === null || _a === void 0 ? void 0 : _a.Interface) || ethers_1.ethers.Interface,
|
|
27
|
-
JsonRpcProvider: ((_b = ethers_1.ethers.providers) === null || _b === void 0 ? void 0 : _b.JsonRpcProvider) || ethers_1.ethers.JsonRpcProvider,
|
|
28
|
-
id: ((_c = ethers_1.ethers.utils) === null || _c === void 0 ? void 0 : _c.id) || ethers_1.ethers.id,
|
|
29
|
-
formatUnits: ((_d = ethers_1.ethers.utils) === null || _d === void 0 ? void 0 : _d.formatUnits) || ethers_1.ethers.formatUnits,
|
|
30
|
-
parseUnits: ((_e = ethers_1.ethers.utils) === null || _e === void 0 ? void 0 : _e.parseUnits) || ethers_1.ethers.parseUnits,
|
|
31
|
-
keccak256: ((_f = ethers_1.ethers.utils) === null || _f === void 0 ? void 0 : _f.keccak256) || ethers_1.ethers.keccak256,
|
|
32
|
-
};
|
|
33
24
|
function buildTradeConfig() {
|
|
34
25
|
const vaultGroupId = process.env.TRADE_GROUP_ID || process.env.VAULT_GROUP_ID;
|
|
35
26
|
if (!vaultGroupId) {
|
|
@@ -44,8 +35,8 @@ function buildTradeConfig() {
|
|
|
44
35
|
return {
|
|
45
36
|
vaultAddress: vaultWallet.public_key,
|
|
46
37
|
executorIds: {
|
|
47
|
-
pancake: ethersCompat.id(pancakeIdName),
|
|
48
|
-
uniswap: ethersCompat.id(uniswapIdName),
|
|
38
|
+
pancake: ethers_compat_1.ethersCompat.id(pancakeIdName),
|
|
39
|
+
uniswap: ethers_compat_1.ethersCompat.id(uniswapIdName),
|
|
49
40
|
},
|
|
50
41
|
};
|
|
51
42
|
}
|
|
@@ -59,11 +50,11 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
59
50
|
this.initConfigs();
|
|
60
51
|
this.chainNameLower = this.appConfig.env_args.chain_id.toLowerCase();
|
|
61
52
|
this.redisClient = new redis_1.SimpleRedisClient(`${this.chainNameLower}:tx`);
|
|
62
|
-
this.vaultInterface = new ethersCompat.Interface(VAULT_ABI);
|
|
53
|
+
this.vaultInterface = new ethers_compat_1.ethersCompat.Interface(VAULT_ABI);
|
|
63
54
|
}
|
|
64
55
|
init() {
|
|
65
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
this.provider = new ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
57
|
+
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.chainConfig.rpcEndpoint);
|
|
67
58
|
this.transactionSender = new ttd_bsc_send_tx_1.TransactionSender(this.appConfig);
|
|
68
59
|
const defaultCallerId = `${this.chainNameLower.toUpperCase()}-CALLER`;
|
|
69
60
|
const callerGroupIds = (process.env.CALLER_GROUP_IDS || defaultCallerId).trim().split(',').filter(Boolean);
|
|
@@ -90,7 +81,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
90
81
|
pair,
|
|
91
82
|
direction: isBuy ? 'BUY' : 'SELL',
|
|
92
83
|
input: `${amount} ${inputToken.symbol}`,
|
|
93
|
-
outputMin: `${ethersCompat.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
|
|
84
|
+
outputMin: `${ethers_compat_1.ethersCompat.formatUnits(amountOutMin, outputToken.decimals)} ${outputToken.symbol}`,
|
|
94
85
|
slippage: `${slippage_bps / 100}%`,
|
|
95
86
|
});
|
|
96
87
|
let maxAttempts = Math.min(Math.max(parseInt(process.env.NONCE_LOCK_MAX_RETRIES || '3'), 1), 3);
|
|
@@ -125,7 +116,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
125
116
|
to: this.tradeConfig.vaultAddress,
|
|
126
117
|
data: vaultCalldata,
|
|
127
118
|
gasLimit: this.chainConfig.gasOptions.gasLimit,
|
|
128
|
-
gasPrice: ethersCompat.parseUnits(realGasPriceGwei, 'gwei'),
|
|
119
|
+
gasPrice: ethers_compat_1.ethersCompat.parseUnits(realGasPriceGwei, 'gwei'),
|
|
129
120
|
nonce,
|
|
130
121
|
chainId: this.chainConfig.chainId,
|
|
131
122
|
value: 0,
|
|
@@ -135,11 +126,16 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
135
126
|
ttd_bsc_send_tx_1.BSC_EOA_ADDRESS._48CLUB,
|
|
136
127
|
ttd_bsc_send_tx_1.BSC_EOA_ADDRESS.BLXR,
|
|
137
128
|
];
|
|
138
|
-
const [
|
|
129
|
+
const [rawMainTx, ...rawTips] = yield Promise.all([
|
|
139
130
|
caller.signTransaction(mainTx),
|
|
140
131
|
...builderAddresses.map(addr => this.buildTipTransferTx(addr, transfer_amount_gwei, realGasPriceGwei, tipNonce, caller)),
|
|
141
132
|
]);
|
|
142
|
-
|
|
133
|
+
const ensure0x = (tx) => tx.startsWith('0x') ? tx : `0x${tx}`;
|
|
134
|
+
const signedMainTx = ensure0x(rawMainTx);
|
|
135
|
+
const signedTips = rawTips.map(ensure0x);
|
|
136
|
+
txid = ethers_compat_1.ethersCompat.keccak256(signedMainTx);
|
|
137
|
+
(0, ttd_core_1.log_info)(`[debug] signedMainTx type=${typeof signedMainTx}, length=${signedMainTx.length}, prefix=${signedMainTx.substring(0, 10)}`);
|
|
138
|
+
(0, ttd_core_1.log_info)(`[debug] signedTips types=${signedTips.map(t => typeof t).join(',')}, lengths=${signedTips.map(t => t.length).join(',')}`);
|
|
143
139
|
const tipTxMap = new Map();
|
|
144
140
|
builderAddresses.forEach((addr, idx) => tipTxMap.set(addr, signedTips[idx]));
|
|
145
141
|
(0, ttd_core_1.log_info)(`交易已签名`, { txid, nonce, caller: caller.address, gasPriceGwei: realGasPriceGwei }, order_trace_id);
|
|
@@ -206,17 +202,18 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
206
202
|
type: 0,
|
|
207
203
|
from: wallet.address,
|
|
208
204
|
to,
|
|
209
|
-
value: ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
|
|
210
|
-
gasLimit:
|
|
211
|
-
gasPrice: ethersCompat.parseUnits(real_gas_price_gwei, 'gwei'),
|
|
205
|
+
value: ethers_compat_1.ethersCompat.parseUnits(real_transfer_amount_gwei, 'gwei'),
|
|
206
|
+
gasLimit: 21000,
|
|
207
|
+
gasPrice: ethers_compat_1.ethersCompat.parseUnits(real_gas_price_gwei, 'gwei'),
|
|
212
208
|
nonce,
|
|
213
209
|
chainId: this.chainConfig.chainId
|
|
214
210
|
};
|
|
215
|
-
const
|
|
211
|
+
const rawSignedTx = yield wallet.signTransaction(tx_data);
|
|
212
|
+
const signedTx = rawSignedTx.startsWith('0x') ? rawSignedTx : `0x${rawSignedTx}`;
|
|
216
213
|
(0, ttd_core_1.log_info)(`构建 tip 转账交易`, {
|
|
217
214
|
to, nonce,
|
|
218
215
|
tipGwei: real_transfer_amount_gwei,
|
|
219
|
-
txhash: ethersCompat.keccak256(signedTx)
|
|
216
|
+
txhash: ethers_compat_1.ethersCompat.keccak256(signedTx)
|
|
220
217
|
});
|
|
221
218
|
return signedTx;
|
|
222
219
|
});
|
|
@@ -240,7 +237,7 @@ class AbstractDexTrade extends ttd_core_1.AbastrcatTrade {
|
|
|
240
237
|
expectedOut = inputAmount.mul(price);
|
|
241
238
|
}
|
|
242
239
|
const minOutput = expectedOut.mul(new decimal_js_1.default(1).sub(new decimal_js_1.default(slippage)));
|
|
243
|
-
return ethersCompat.parseUnits(minOutput.toFixed(outputToken.decimals), outputToken.decimals);
|
|
240
|
+
return ethers_compat_1.ethersCompat.parseUnits(minOutput.toFixed(outputToken.decimals), outputToken.decimals);
|
|
244
241
|
}
|
|
245
242
|
extractNonceFromErrorMsg(errorMessage) {
|
|
246
243
|
try {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { EnvArgs } from '@clonegod/ttd-core';
|
|
2
2
|
import { AbstractTransactionResultCheck } from "@clonegod/ttd-core/dist/trade";
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
3
|
import { EventEmitter } from 'events';
|
|
5
4
|
export declare abstract class BaseTxResultChecker extends AbstractTransactionResultCheck {
|
|
6
|
-
protected provider:
|
|
5
|
+
protected provider: any;
|
|
7
6
|
constructor(env_args: EnvArgs, event_emitter: EventEmitter);
|
|
8
7
|
protected abstract createParser(): {
|
|
9
8
|
parseTransaction(txReceipt: any, poolInfo: any): Promise<any>;
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BaseTxResultChecker = void 0;
|
|
13
13
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
14
14
|
const trade_1 = require("@clonegod/ttd-core/dist/trade");
|
|
15
|
-
const
|
|
15
|
+
const ethers_compat_1 = require("../../utils/ethers_compat");
|
|
16
16
|
class TradeResultSubscriber {
|
|
17
17
|
constructor() {
|
|
18
18
|
this.ws = null;
|
|
@@ -73,7 +73,7 @@ TradeResultSubscriber.instance = null;
|
|
|
73
73
|
class BaseTxResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
74
74
|
constructor(env_args, event_emitter) {
|
|
75
75
|
super(env_args, event_emitter);
|
|
76
|
-
this.provider = new
|
|
76
|
+
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(this.env_args.rpc_endpoint);
|
|
77
77
|
}
|
|
78
78
|
check_tx_result_interval() {
|
|
79
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { StandardPoolInfoType, StandardSwapDetailType } from "@clonegod/ttd-core";
|
|
2
2
|
import { TransactionReceipt } from '@ethersproject/providers';
|
|
3
|
-
import { ethers } from 'ethers';
|
|
4
3
|
import { ITxParser } from "./abstract_parser";
|
|
5
4
|
import { ParserConfig } from "../../types";
|
|
6
5
|
export declare abstract class BaseTxParser implements ITxParser {
|
|
7
6
|
protected config: ParserConfig;
|
|
8
|
-
protected provider:
|
|
7
|
+
protected provider: any;
|
|
9
8
|
protected blockTimeCache: Map<number, number>;
|
|
10
9
|
protected readonly CACHE_EXPIRY: number;
|
|
11
10
|
constructor(config: ParserConfig);
|
|
@@ -12,12 +12,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.BaseTxParser = void 0;
|
|
13
13
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
14
14
|
const ethers_1 = require("ethers");
|
|
15
|
+
const ethers_compat_1 = require("../../utils/ethers_compat");
|
|
15
16
|
class BaseTxParser {
|
|
16
17
|
constructor(config) {
|
|
17
18
|
this.blockTimeCache = new Map();
|
|
18
19
|
this.CACHE_EXPIRY = 1000 * 60 * 60;
|
|
19
20
|
this.config = config;
|
|
20
|
-
this.provider = new
|
|
21
|
+
this.provider = new ethers_compat_1.ethersCompat.JsonRpcProvider(config.rpcEndpoint);
|
|
21
22
|
}
|
|
22
23
|
getBlockTime(blockNumber) {
|
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -56,7 +57,7 @@ class BaseTxParser {
|
|
|
56
57
|
const gasUsed = toBN(txReceipt.gasUsed);
|
|
57
58
|
const effectiveGasPrice = toBN(txReceipt.effectiveGasPrice || txReceipt.gasPrice);
|
|
58
59
|
const gasFeeBN = gasUsed.mul(effectiveGasPrice);
|
|
59
|
-
const base_fee = Number(
|
|
60
|
+
const base_fee = Number(ethers_compat_1.ethersCompat.formatEther(gasFeeBN));
|
|
60
61
|
const priority_fee = 0;
|
|
61
62
|
const total_fee = base_fee + priority_fee;
|
|
62
63
|
return {
|
|
@@ -13,9 +13,9 @@ export interface EvmContractEventData {
|
|
|
13
13
|
eventSignature: string;
|
|
14
14
|
args: any;
|
|
15
15
|
removeListener: () => void;
|
|
16
|
-
getBlock: () => Promise<
|
|
17
|
-
getTransaction: () => Promise<
|
|
18
|
-
getTransactionReceipt: () => Promise<
|
|
16
|
+
getBlock: () => Promise<any>;
|
|
17
|
+
getTransaction: () => Promise<any>;
|
|
18
|
+
getTransactionReceipt: () => Promise<any>;
|
|
19
19
|
decode: (data: string, topics?: string[]) => any;
|
|
20
20
|
}
|
|
21
21
|
export interface AmmPoolSyncEventData extends EvmContractEventData {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ethersCompat = void 0;
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const _ethers = ethers_1.ethers;
|
|
7
|
+
exports.ethersCompat = {
|
|
8
|
+
Interface: ((_a = _ethers.utils) === null || _a === void 0 ? void 0 : _a.Interface) || _ethers.Interface,
|
|
9
|
+
JsonRpcProvider: ((_b = _ethers.providers) === null || _b === void 0 ? void 0 : _b.JsonRpcProvider) || _ethers.JsonRpcProvider,
|
|
10
|
+
WebSocketProvider: ((_c = _ethers.providers) === null || _c === void 0 ? void 0 : _c.WebSocketProvider) || _ethers.WebSocketProvider,
|
|
11
|
+
id: ((_d = _ethers.utils) === null || _d === void 0 ? void 0 : _d.id) || _ethers.id,
|
|
12
|
+
formatUnits: ((_e = _ethers.utils) === null || _e === void 0 ? void 0 : _e.formatUnits) || _ethers.formatUnits,
|
|
13
|
+
parseUnits: ((_f = _ethers.utils) === null || _f === void 0 ? void 0 : _f.parseUnits) || _ethers.parseUnits,
|
|
14
|
+
formatEther: ((_g = _ethers.utils) === null || _g === void 0 ? void 0 : _g.formatEther) || _ethers.formatEther,
|
|
15
|
+
parseEther: ((_h = _ethers.utils) === null || _h === void 0 ? void 0 : _h.parseEther) || _ethers.parseEther,
|
|
16
|
+
keccak256: ((_j = _ethers.utils) === null || _j === void 0 ? void 0 : _j.keccak256) || _ethers.keccak256,
|
|
17
|
+
isAddress: ((_k = _ethers.utils) === null || _k === void 0 ? void 0 : _k.isAddress) || _ethers.isAddress,
|
|
18
|
+
Zero: ((_l = _ethers.constants) === null || _l === void 0 ? void 0 : _l.Zero) || BigInt(0),
|
|
19
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ethers } from 'ethers';
|
|
2
2
|
export declare class EVMGasHelper {
|
|
3
|
-
static wrapNativeToken(provider:
|
|
4
|
-
static checkNativeBalance(provider:
|
|
3
|
+
static wrapNativeToken(provider: any, wallet: ethers.Wallet, wrappedTokenAddress: string, amount: string, minReserve?: string, tokenSymbol?: string): Promise<string>;
|
|
4
|
+
static checkNativeBalance(provider: any, walletAddress: string): Promise<ethers.BigNumber>;
|
|
5
5
|
}
|
package/dist/utils/gas_helper.js
CHANGED
|
@@ -11,16 +11,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EVMGasHelper = void 0;
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
|
+
const ethers_compat_1 = require("./ethers_compat");
|
|
14
15
|
const ttd_core_1 = require("@clonegod/ttd-core");
|
|
15
16
|
class EVMGasHelper {
|
|
16
17
|
static wrapNativeToken(provider_1, wallet_1, wrappedTokenAddress_1, amount_1) {
|
|
17
18
|
return __awaiter(this, arguments, void 0, function* (provider, wallet, wrappedTokenAddress, amount, minReserve = "0.1", tokenSymbol = "ETH") {
|
|
18
19
|
const nativeBalance = yield provider.getBalance(wallet.address);
|
|
19
|
-
const nativeBalanceEth =
|
|
20
|
+
const nativeBalanceEth = ethers_compat_1.ethersCompat.formatEther(nativeBalance);
|
|
20
21
|
(0, ttd_core_1.log_info)(`当前${tokenSymbol}余额: ${nativeBalanceEth} ${tokenSymbol}`);
|
|
21
22
|
let wrapAmount;
|
|
22
23
|
if (amount === "max") {
|
|
23
|
-
const minReserveBN =
|
|
24
|
+
const minReserveBN = ethers_compat_1.ethersCompat.parseEther(minReserve);
|
|
24
25
|
if (nativeBalance.lte(minReserveBN)) {
|
|
25
26
|
(0, ttd_core_1.log_info)(`${tokenSymbol}余额不足最小保留额 ${minReserve} ${tokenSymbol},不执行转换`);
|
|
26
27
|
return null;
|
|
@@ -28,14 +29,14 @@ class EVMGasHelper {
|
|
|
28
29
|
wrapAmount = nativeBalance.sub(minReserveBN);
|
|
29
30
|
}
|
|
30
31
|
else {
|
|
31
|
-
wrapAmount =
|
|
32
|
-
const minReserveBN =
|
|
32
|
+
wrapAmount = ethers_compat_1.ethersCompat.parseEther(amount);
|
|
33
|
+
const minReserveBN = ethers_compat_1.ethersCompat.parseEther(minReserve);
|
|
33
34
|
if (nativeBalance.sub(wrapAmount).lt(minReserveBN)) {
|
|
34
35
|
(0, ttd_core_1.log_info)(`转换后${tokenSymbol}余额将低于最小保留额 ${minReserve} ${tokenSymbol},调整转换金额`);
|
|
35
36
|
wrapAmount = nativeBalance.sub(minReserveBN);
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
if (wrapAmount.lte(
|
|
39
|
+
if (wrapAmount.lte(ethers_compat_1.ethersCompat.Zero)) {
|
|
39
40
|
(0, ttd_core_1.log_info)(`计算的转换金额为0或负数,不执行转换`);
|
|
40
41
|
return null;
|
|
41
42
|
}
|
|
@@ -43,7 +44,7 @@ class EVMGasHelper {
|
|
|
43
44
|
"function deposit() external payable",
|
|
44
45
|
"function withdraw(uint wad) external"
|
|
45
46
|
], wallet);
|
|
46
|
-
(0, ttd_core_1.log_info)(`准备将 ${
|
|
47
|
+
(0, ttd_core_1.log_info)(`准备将 ${ethers_compat_1.ethersCompat.formatEther(wrapAmount)} ${tokenSymbol} 转换为 W${tokenSymbol}`);
|
|
47
48
|
const gasPrice = yield provider.getGasPrice();
|
|
48
49
|
const txOptions = {
|
|
49
50
|
value: wrapAmount,
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
2
1
|
import Decimal from "decimal.js";
|
|
3
2
|
export * from './gas_helper';
|
|
4
3
|
export * from './trade_direction';
|
|
5
4
|
export * from './pool_filter';
|
|
5
|
+
export * from './ethers_compat';
|
|
6
6
|
export declare const sleep: (ms: number) => Promise<void>;
|
|
7
7
|
export declare const formatPrice: (price: number, precision?: number) => string;
|
|
8
|
-
export declare const formatUnits: (value:
|
|
8
|
+
export declare const formatUnits: (value: any, decimals: number) => Decimal;
|
|
9
9
|
export declare const formatNumberHighPrecision: (numStr: string, precision?: number) => string;
|
package/dist/utils/index.js
CHANGED
|
@@ -18,11 +18,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.formatNumberHighPrecision = exports.formatUnits = exports.formatPrice = exports.sleep = void 0;
|
|
21
|
-
const ethers_1 = require("ethers");
|
|
22
21
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
22
|
+
const ethers_compat_1 = require("./ethers_compat");
|
|
23
23
|
__exportStar(require("./gas_helper"), exports);
|
|
24
24
|
__exportStar(require("./trade_direction"), exports);
|
|
25
25
|
__exportStar(require("./pool_filter"), exports);
|
|
26
|
+
__exportStar(require("./ethers_compat"), exports);
|
|
26
27
|
const sleep = (ms) => {
|
|
27
28
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
28
29
|
};
|
|
@@ -32,7 +33,7 @@ const formatPrice = (price, precision = 10) => {
|
|
|
32
33
|
};
|
|
33
34
|
exports.formatPrice = formatPrice;
|
|
34
35
|
const formatUnits = (value, decimals) => {
|
|
35
|
-
return new decimal_js_1.default(
|
|
36
|
+
return new decimal_js_1.default(ethers_compat_1.ethersCompat.formatUnits(value, decimals).toString());
|
|
36
37
|
};
|
|
37
38
|
exports.formatUnits = formatUnits;
|
|
38
39
|
const formatNumberHighPrecision = (numStr, precision = 12) => {
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.PancakeV2AmmPoolEventsSubscriber = void 0;
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
|
+
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
14
15
|
const event_filter_1 = require("./event_filter");
|
|
15
16
|
const PANCAKE_V2_POOL_ABI = [
|
|
16
17
|
'event Sync(uint112 reserve0, uint112 reserve1)',
|
|
@@ -36,7 +37,7 @@ class PancakeV2AmmPoolEventsSubscriber {
|
|
|
36
37
|
if (!this.wsUrl || !this.poolAddress) {
|
|
37
38
|
throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
|
|
38
39
|
}
|
|
39
|
-
this.provider = new
|
|
40
|
+
this.provider = new ethers_compat_1.ethersCompat.WebSocketProvider(this.wsUrl);
|
|
40
41
|
this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V2_POOL_ABI, this.provider);
|
|
41
42
|
this.isConnected = true;
|
|
42
43
|
console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.UniswapV3PoolEventsSubscriber = exports.PancakeV3PoolEventsSubscriber = void 0;
|
|
13
13
|
const ethers_1 = require("ethers");
|
|
14
|
+
const ethers_compat_1 = require("../utils/ethers_compat");
|
|
14
15
|
const event_filter_1 = require("./event_filter");
|
|
15
16
|
const PANCAKE_V3_POOL_ABI = [
|
|
16
17
|
'event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick, uint128 protocolFeesToken0, uint128 protocolFeesToken1)',
|
|
@@ -36,7 +37,7 @@ class PancakeV3PoolEventsSubscriber {
|
|
|
36
37
|
if (!this.wsUrl || !this.poolAddress) {
|
|
37
38
|
throw new Error(`wsUrl and poolAddress are required! wsUrl=${this.wsUrl} poolAddress=${this.poolAddress}`);
|
|
38
39
|
}
|
|
39
|
-
this.provider = new
|
|
40
|
+
this.provider = new ethers_compat_1.ethersCompat.WebSocketProvider(this.wsUrl);
|
|
40
41
|
this.poolContract = new ethers_1.ethers.Contract(this.poolAddress, PANCAKE_V3_POOL_ABI, this.provider);
|
|
41
42
|
this.isConnected = true;
|
|
42
43
|
console.log(`Connected to WebSocket: ${this.wsUrl} for pool: ${this.poolAddress}`);
|