@clonegod/ttd-bsc-common 1.0.90 → 2.0.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/config/BscQuoteAppConfig.d.ts +11 -0
- package/dist/config/BscQuoteAppConfig.js +62 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +1 -0
- package/dist/quote/event/index.d.ts +1 -0
- package/dist/quote/event/index.js +1 -0
- package/dist/quote/event/swap_debouncer.d.ts +22 -0
- package/dist/quote/event/swap_debouncer.js +92 -0
- package/dist/quote/index.d.ts +1 -0
- package/dist/quote/index.js +1 -0
- package/dist/quote/pricing/index.d.ts +2 -0
- package/dist/quote/pricing/index.js +2 -0
- package/dist/quote/pricing/pool_state_initializer.d.ts +8 -0
- package/dist/quote/pricing/pool_state_initializer.js +142 -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/tick/clmm_tick_cache.d.ts +40 -0
- package/dist/quote/tick/clmm_tick_cache.js +219 -0
- package/dist/quote/tick/index.d.ts +2 -0
- package/dist/{trade/send → quote/tick}/index.js +2 -8
- package/dist/quote/tick/tick_lens_loaders.d.ts +25 -0
- package/dist/quote/tick/tick_lens_loaders.js +170 -0
- package/dist/redis/redis_client.d.ts +1 -0
- package/dist/redis/redis_client.js +6 -0
- package/dist/trade/abstract_dex_trade.d.ts +30 -16
- package/dist/trade/abstract_dex_trade.js +223 -108
- package/dist/trade/caller_manager.d.ts +35 -0
- package/dist/trade/caller_manager.js +178 -0
- package/dist/trade/index.d.ts +1 -2
- package/dist/trade/index.js +1 -2
- package/dist/types/pool_state.d.ts +31 -0
- package/package.json +3 -2
- package/dist/trade/abstract_dex_trade_plus.d.ts +0 -44
- package/dist/trade/abstract_dex_trade_plus.js +0 -449
- package/dist/trade/send/48club.d.ts +0 -17
- package/dist/trade/send/48club.js +0 -123
- package/dist/trade/send/48club_member.d.ts +0 -1
- package/dist/trade/send/48club_member.js +0 -25
- package/dist/trade/send/48club_sp.d.ts +0 -9
- package/dist/trade/send/48club_sp.js +0 -137
- package/dist/trade/send/blockrazor.d.ts +0 -7
- package/dist/trade/send/blockrazor.js +0 -78
- package/dist/trade/send/blxr.d.ts +0 -0
- package/dist/trade/send/blxr.js +0 -0
- package/dist/trade/send/bsc_rpc.d.ts +0 -6
- package/dist/trade/send/bsc_rpc.js +0 -47
- package/dist/trade/send/index.d.ts +0 -6
- package/dist/trade/send/send_bundle_proxy.d.ts +0 -7
- package/dist/trade/send/send_bundle_proxy.js +0 -30
- package/dist/trade/send/send_bundle_ws.d.ts +0 -7
- package/dist/trade/send/send_bundle_ws.js +0 -30
- package/dist/trade/send/send_tx.d.ts +0 -9
- package/dist/trade/send/send_tx.js +0 -119
- package/dist/ws/bsc_stream_ws_client.d.ts +0 -10
- package/dist/ws/bsc_stream_ws_client.js +0 -95
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { ethers } from 'ethers';
|
|
2
|
-
export declare class SoulPointSignature {
|
|
3
|
-
static generate48SPSignature(privateKey: string, txs: string[]): string;
|
|
4
|
-
static generate48SPSignature_ethersV5(wallet: ethers.Wallet, txs: string[]): string;
|
|
5
|
-
static generate48SPSignature_ethersV6(wallet: ethers.Wallet, txs: string[]): string;
|
|
6
|
-
static verify48SPSignature(signature: string, txs: string[], expectedSignerAddress: string): boolean;
|
|
7
|
-
static getSignerAddress(signedTx: string): string;
|
|
8
|
-
static testSignatureVerification(): Promise<void>;
|
|
9
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
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.SoulPointSignature = void 0;
|
|
13
|
-
const ethers_1 = require("ethers");
|
|
14
|
-
class SoulPointSignature {
|
|
15
|
-
static generate48SPSignature(privateKey, txs) {
|
|
16
|
-
const wallet = new ethers_1.ethers.Wallet(privateKey);
|
|
17
|
-
try {
|
|
18
|
-
return this.generate48SPSignature_ethersV5(wallet, txs);
|
|
19
|
-
}
|
|
20
|
-
catch (error) {
|
|
21
|
-
return this.generate48SPSignature_ethersV6(wallet, txs);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
static generate48SPSignature_ethersV5(wallet, txs) {
|
|
25
|
-
try {
|
|
26
|
-
const txHashes = txs.map(tx => {
|
|
27
|
-
if (tx.startsWith('0x')) {
|
|
28
|
-
return ethers_1.ethers.utils.keccak256(tx);
|
|
29
|
-
}
|
|
30
|
-
return tx;
|
|
31
|
-
});
|
|
32
|
-
const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
|
|
33
|
-
const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
|
|
34
|
-
const signature = wallet._signingKey().signDigest(messageHash);
|
|
35
|
-
const r = signature.r.slice(2).padStart(64, '0');
|
|
36
|
-
const s = signature.s.slice(2).padStart(64, '0');
|
|
37
|
-
const v = signature.recoveryParam.toString(16).padStart(2, '0');
|
|
38
|
-
return '0x' + r + s + v;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
throw new Error(`生成48 SoulPoint签名失败(ethersV5): ${error}`);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
static generate48SPSignature_ethersV6(wallet, txs) {
|
|
45
|
-
try {
|
|
46
|
-
const txHashes = txs.map(tx => {
|
|
47
|
-
if (tx.startsWith('0x')) {
|
|
48
|
-
return ethers_1.ethers.keccak256(tx);
|
|
49
|
-
}
|
|
50
|
-
return tx;
|
|
51
|
-
});
|
|
52
|
-
const concatenatedHashes = ethers_1.ethers.concat(txHashes);
|
|
53
|
-
const messageHash = ethers_1.ethers.keccak256(concatenatedHashes);
|
|
54
|
-
const signingKey = wallet.signingKey;
|
|
55
|
-
const signature = signingKey.signDigest ? signingKey.signDigest(messageHash) : signingKey.sign(messageHash);
|
|
56
|
-
const r = signature.r.slice(2).padStart(64, '0');
|
|
57
|
-
const s = signature.s.slice(2).padStart(64, '0');
|
|
58
|
-
let recoveryId;
|
|
59
|
-
if (signature.recoveryParam !== undefined) {
|
|
60
|
-
recoveryId = Number(signature.recoveryParam);
|
|
61
|
-
}
|
|
62
|
-
else if (signature.v !== undefined) {
|
|
63
|
-
const v = Number(signature.v);
|
|
64
|
-
recoveryId = v >= 27 ? v - 27 : v;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
recoveryId = 0;
|
|
68
|
-
}
|
|
69
|
-
recoveryId = recoveryId % 2;
|
|
70
|
-
const v = recoveryId.toString(16).padStart(2, '0');
|
|
71
|
-
return '0x' + r + s + v;
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
throw new Error(`生成48 SoulPoint签名失败(ethersV6): ${error}`);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
static verify48SPSignature(signature, txs, expectedSignerAddress) {
|
|
78
|
-
try {
|
|
79
|
-
const txHashes = txs.map(tx => {
|
|
80
|
-
if (tx.startsWith('0x')) {
|
|
81
|
-
return ethers_1.ethers.utils.keccak256(tx);
|
|
82
|
-
}
|
|
83
|
-
return tx;
|
|
84
|
-
});
|
|
85
|
-
const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
|
|
86
|
-
const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
|
|
87
|
-
const recoveredAddress = ethers_1.ethers.utils.recoverAddress(messageHash, signature);
|
|
88
|
-
return recoveredAddress.toLowerCase() === expectedSignerAddress.toLowerCase();
|
|
89
|
-
}
|
|
90
|
-
catch (error) {
|
|
91
|
-
console.error('验证48 SoulPoint签名失败:', error);
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
static getSignerAddress(signedTx) {
|
|
96
|
-
try {
|
|
97
|
-
const tx = ethers_1.ethers.utils.parseTransaction(signedTx);
|
|
98
|
-
if (!tx.from) {
|
|
99
|
-
throw new Error('无法从交易中提取签名者地址');
|
|
100
|
-
}
|
|
101
|
-
return tx.from;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
throw new Error(`提取签名者地址失败: ${error}`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
static testSignatureVerification() {
|
|
108
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
-
console.log('=== 48 SoulPoint 签名测试 ===');
|
|
110
|
-
const tx1_raw = '0xf8ad82e69c85012a05f200830329189455d398326f99059ff775485246999027b319795580b844a9059cbb0000000000000000000000006df68f71f19081751850160118fc755bfeb036120000000000000000000000000000000000000000000000056bc75e2d631000008193a0ade014e655a2d1645efb5f37a142c2369ab96d2d962861dd353fa33fe15b76cda041b291fb742d07c0d475cb2611e9dd6010bbd052c79f99e73c7f9e3653afb6f7';
|
|
111
|
-
const tx2_raw = '0xf8ec8307f58584b8c6fe72830927c094bddbcbaa9cf9603b7055aad963506ede71692f1280b8830000000300000000000000000000000000000000000000000000000087250559b9145f9000000000000000000000000000000000000000000000011f35cc4934f0b52a80bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c55d398326f99059ff775485246999027b319795500006400000000000000000af935e000000000000000008193a0f63bed83d054bdecfb6852f980ed62f35922fe5b68296b603b290a3eff41fabea04b73872c7e68f541bc97eba52abf956eac4a0e198b762e1f9a872336f6748eed';
|
|
112
|
-
const signer_address = '0xF3A611849696ec5801745496be3f7C8124C344c3';
|
|
113
|
-
const signer_privateKey = '48acf19375e8a27309fe5394728abc2eb6d5a0a4feb6b6c53207ca1c256a6739';
|
|
114
|
-
const sign_result = '0x83e4b3a6af20e58315554b5bc38a8398cfca44a75d42973a4454378b0dc9cae63c229b52341d1ddfc4e3ad4360e518c1f1363e2d21fcba507e8e2e10e266edd201';
|
|
115
|
-
try {
|
|
116
|
-
const tx1Hash = ethers_1.ethers.utils.keccak256(tx1_raw);
|
|
117
|
-
const tx2Hash = ethers_1.ethers.utils.keccak256(tx2_raw);
|
|
118
|
-
console.log('tx1 hash:', tx1Hash);
|
|
119
|
-
console.log('tx2 hash:', tx2Hash);
|
|
120
|
-
const signature = yield this.generate48SPSignature(signer_privateKey, [tx1_raw, tx2_raw]);
|
|
121
|
-
console.log('生成的签名:', signature);
|
|
122
|
-
console.log('期望的签名:', sign_result);
|
|
123
|
-
const isValid = this.verify48SPSignature(signature, [tx1_raw, tx2_raw], signer_address);
|
|
124
|
-
console.log('签名验证结果:', isValid);
|
|
125
|
-
const isExpectedValid = this.verify48SPSignature(sign_result, [tx1_raw, tx2_raw], signer_address);
|
|
126
|
-
console.log('期望签名验证结果:', isExpectedValid);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
console.error('测试失败:', error);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.SoulPointSignature = SoulPointSignature;
|
|
135
|
-
if (require.main === module) {
|
|
136
|
-
SoulPointSignature.testSignatureVerification().catch(console.error);
|
|
137
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare class BlockRazorTrade {
|
|
2
|
-
private rpcUrl;
|
|
3
|
-
private authToken;
|
|
4
|
-
constructor();
|
|
5
|
-
sendPrivateTransaction(signedTx: string): Promise<string>;
|
|
6
|
-
sendBundle(transactions: string[], maxBlockNumber?: number, revertingTxHashes?: string[]): Promise<string>;
|
|
7
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.BlockRazorTrade = void 0;
|
|
16
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
class BlockRazorTrade {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.rpcUrl = process.env.BLOCKRAZOR_RPC_URL || 'https://rpc.blockrazor.builders';
|
|
21
|
-
this.authToken = process.env.BLOCKRAZOR_AUTH_TOKEN || '';
|
|
22
|
-
}
|
|
23
|
-
sendPrivateTransaction(signedTx) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
try {
|
|
26
|
-
const response = yield axios_1.default.post(this.rpcUrl, {
|
|
27
|
-
jsonrpc: "2.0",
|
|
28
|
-
id: "1",
|
|
29
|
-
method: "eth_sendPrivateTransaction",
|
|
30
|
-
params: [signedTx]
|
|
31
|
-
}, {
|
|
32
|
-
headers: {
|
|
33
|
-
'Content-Type': 'application/json',
|
|
34
|
-
'Authorization': this.authToken
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
if (response.data.error) {
|
|
38
|
-
throw new Error(`交易发送失败: ${response.data.error.code} - ${response.data.error.message}`);
|
|
39
|
-
}
|
|
40
|
-
return response.data.result;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
(0, dist_1.log_error)('blockrazor sendPrivateTransaction failed!!!', error);
|
|
44
|
-
throw error;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
sendBundle(transactions, maxBlockNumber, revertingTxHashes) {
|
|
49
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
try {
|
|
51
|
-
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
52
|
-
const response = yield axios_1.default.post(this.rpcUrl, {
|
|
53
|
-
jsonrpc: "2.0",
|
|
54
|
-
id: "1",
|
|
55
|
-
method: "eth_sendBundle",
|
|
56
|
-
params: [{
|
|
57
|
-
txs: transactions,
|
|
58
|
-
maxTimestamp: currentTimestamp + 2,
|
|
59
|
-
}]
|
|
60
|
-
}, {
|
|
61
|
-
headers: {
|
|
62
|
-
'Content-Type': 'application/json',
|
|
63
|
-
'Authorization': this.authToken,
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
if (response.data.error) {
|
|
67
|
-
throw new Error(`Bundle 发送失败: ${response.data.error.message}`);
|
|
68
|
-
}
|
|
69
|
-
return response.data.result;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
(0, dist_1.log_error)('blockrazor sendBundle failed!!!', error);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.BlockRazorTrade = BlockRazorTrade;
|
|
File without changes
|
package/dist/trade/send/blxr.js
DELETED
|
File without changes
|
|
@@ -1,47 +0,0 @@
|
|
|
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.BscMainnetRpc = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
-
class BscMainnetRpc {
|
|
15
|
-
constructor(rpc_endpoint) {
|
|
16
|
-
this.url = rpc_endpoint || process.env.BSC_RPC_ENDPOINT || '';
|
|
17
|
-
this.headers = new Headers();
|
|
18
|
-
this.headers.append("Content-Type", "application/json");
|
|
19
|
-
}
|
|
20
|
-
eth_sendRawTransaction(signedTx) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
console.log(`Sending transaction to ${this.url}`);
|
|
24
|
-
const raw = JSON.stringify({
|
|
25
|
-
jsonrpc: "2.0",
|
|
26
|
-
method: "eth_sendRawTransaction",
|
|
27
|
-
params: [signedTx],
|
|
28
|
-
id: 1
|
|
29
|
-
});
|
|
30
|
-
const requestOptions = {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
headers: this.headers,
|
|
33
|
-
body: raw,
|
|
34
|
-
redirect: 'follow'
|
|
35
|
-
};
|
|
36
|
-
const response = yield fetch(this.url, requestOptions);
|
|
37
|
-
const result = yield response.json();
|
|
38
|
-
if (result.error) {
|
|
39
|
-
(0, dist_1.log_warn)(result.error.message);
|
|
40
|
-
}
|
|
41
|
-
return result.result;
|
|
42
|
-
}), 0);
|
|
43
|
-
return '';
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.BscMainnetRpc = BscMainnetRpc;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BscSendTxProxy = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
-
class BscSendTxProxy {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.wsUrl = process.env.BSC_SEND_BUNDLE_WS_ENDPOINT || 'ws://127.0.0.1:10001/bsc/send_tx';
|
|
8
|
-
this.init();
|
|
9
|
-
}
|
|
10
|
-
init() {
|
|
11
|
-
this.ws = new dist_1.WebSocketClient(this.wsUrl);
|
|
12
|
-
this.ws.onOpen(() => {
|
|
13
|
-
console.log('BscSendTxProxy ws connected:', this.wsUrl);
|
|
14
|
-
});
|
|
15
|
-
this.ws.onMessage((message) => {
|
|
16
|
-
console.log('BscSendTxProxy ws received message', message);
|
|
17
|
-
});
|
|
18
|
-
this.ws.connect();
|
|
19
|
-
}
|
|
20
|
-
sendTransaction(builder, pair, mainTx, tipTx, _48spSign = null) {
|
|
21
|
-
this.ws.send(JSON.stringify({
|
|
22
|
-
builder,
|
|
23
|
-
pair,
|
|
24
|
-
mainTx,
|
|
25
|
-
tipTx,
|
|
26
|
-
_48spSign
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.BscSendTxProxy = BscSendTxProxy;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BscSendTxProxy = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
-
class BscSendTxProxy {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.wsUrl = process.env.BSC_SEND_BUNDLE_WS_ENDPOINT || 'ws://127.0.0.1:10001/bsc/send_tx';
|
|
8
|
-
this.init();
|
|
9
|
-
}
|
|
10
|
-
init() {
|
|
11
|
-
this.ws = new dist_1.WebSocketClient(this.wsUrl);
|
|
12
|
-
this.ws.onOpen(() => {
|
|
13
|
-
console.log('BscSendTxProxy ws connected:', this.wsUrl);
|
|
14
|
-
});
|
|
15
|
-
this.ws.onMessage((message) => {
|
|
16
|
-
console.log('BscSendTxProxy ws received message', message);
|
|
17
|
-
});
|
|
18
|
-
this.ws.connect();
|
|
19
|
-
}
|
|
20
|
-
sendTransaction(builder, pair, mainTx, tipTx, _48spSign = null) {
|
|
21
|
-
this.ws.send(JSON.stringify({
|
|
22
|
-
builder,
|
|
23
|
-
pair,
|
|
24
|
-
mainTx,
|
|
25
|
-
tipTx,
|
|
26
|
-
_48spSign
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.BscSendTxProxy = BscSendTxProxy;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AppConfig } from "@clonegod/ttd-core/dist";
|
|
2
|
-
export declare class TransactionSender {
|
|
3
|
-
private rpc;
|
|
4
|
-
private blockRazor;
|
|
5
|
-
private _48Club;
|
|
6
|
-
private sendBundleProxy;
|
|
7
|
-
constructor(appConfig: AppConfig);
|
|
8
|
-
sendTransaction(signedMainTx: string, eoa_tip_transaction: (eoa_address: string) => Promise<string>, order_trace_id: string, pair?: string, only_bundle?: boolean): Promise<string[]>;
|
|
9
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
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.TransactionSender = void 0;
|
|
13
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
14
|
-
const blockrazor_1 = require("./blockrazor");
|
|
15
|
-
const bsc_rpc_1 = require("./bsc_rpc");
|
|
16
|
-
const _48club_1 = require("./48club");
|
|
17
|
-
const _1 = require(".");
|
|
18
|
-
const send_bundle_proxy_1 = require("./send_bundle_proxy");
|
|
19
|
-
class TransactionSender {
|
|
20
|
-
constructor(appConfig) {
|
|
21
|
-
this.rpc = new bsc_rpc_1.BscMainnetRpc(appConfig.env_args.rpc_endpoint);
|
|
22
|
-
this.blockRazor = new blockrazor_1.BlockRazorTrade();
|
|
23
|
-
this._48Club = new _48club_1._48ClubTrade();
|
|
24
|
-
this.sendBundleProxy = new send_bundle_proxy_1.BscSendTxProxy();
|
|
25
|
-
}
|
|
26
|
-
sendTransaction(signedMainTx_1, eoa_tip_transaction_1, order_trace_id_1) {
|
|
27
|
-
return __awaiter(this, arguments, void 0, function* (signedMainTx, eoa_tip_transaction, order_trace_id, pair = '', only_bundle = false) {
|
|
28
|
-
const rpcProviders = [
|
|
29
|
-
{
|
|
30
|
-
name: 'Default (QuickNode / Merkle)',
|
|
31
|
-
enable: process.env.SEND_TX_DEFAULT_RPC_PRIVATE === 'true',
|
|
32
|
-
is_bundle: false,
|
|
33
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return yield this.rpc.eth_sendRawTransaction(signedMainTx);
|
|
35
|
-
})
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: 'BlockRazor HTTP - Private Transaction',
|
|
39
|
-
enable: process.env.SEND_TX_BLOCKRAZOR_PRIVATE === 'true',
|
|
40
|
-
is_bundle: false,
|
|
41
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
return yield this.blockRazor.sendPrivateTransaction(signedMainTx);
|
|
43
|
-
})
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'BlockRazor HTTP - sendBundle',
|
|
47
|
-
enable: process.env.SEND_TX_BLOCKRAZOR_BUNDLE === 'true',
|
|
48
|
-
is_bundle: true,
|
|
49
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
-
let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS.BLOCKRAZOR)];
|
|
51
|
-
return yield this.blockRazor.sendBundle(bundle);
|
|
52
|
-
})
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: '48Club - HTTP - Private Transaction With 48SP',
|
|
56
|
-
enable: process.env.SEND_TX_48CLUB_PRIVATE === 'true',
|
|
57
|
-
is_bundle: false,
|
|
58
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return yield this._48Club.sendPrivateTransactionWith48SP(signedMainTx);
|
|
60
|
-
})
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: '48Club - HTTP - sendBundle',
|
|
64
|
-
enable: process.env.SEND_TX_48CLUB_BUNDLE === 'true',
|
|
65
|
-
is_bundle: true,
|
|
66
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
-
let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS._48CLUB)];
|
|
68
|
-
return yield this._48Club.sendBundle({ txs: bundle });
|
|
69
|
-
})
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: '48Club - WS - sendBundle',
|
|
73
|
-
enable: process.env.SEND_TX_48CLUB_BUNDLE_WS === 'true',
|
|
74
|
-
is_bundle: true,
|
|
75
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
76
|
-
const tipTx = yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS._48CLUB);
|
|
77
|
-
const spSignature = yield this._48Club.get48SPSignature([signedMainTx, tipTx]);
|
|
78
|
-
this.sendBundleProxy.sendTransaction('48club', pair, signedMainTx, tipTx, spSignature);
|
|
79
|
-
return Promise.resolve('send bundle to 48club ws proxy success');
|
|
80
|
-
})
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
name: 'BloxRoute - WS - sendBundle',
|
|
84
|
-
enable: process.env.SEND_TX_BLOX_BUNDLE_WS === 'true',
|
|
85
|
-
is_bundle: true,
|
|
86
|
-
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
const tipTx = yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS.BLXR);
|
|
88
|
-
this.sendBundleProxy.sendTransaction('bloxroute', pair, signedMainTx, tipTx);
|
|
89
|
-
return Promise.resolve('send bundle to bloxroute ws proxy success');
|
|
90
|
-
})
|
|
91
|
-
},
|
|
92
|
-
];
|
|
93
|
-
const results = [];
|
|
94
|
-
const errors = [];
|
|
95
|
-
yield Promise.all(rpcProviders.filter(provider => provider.enable).filter(provider => only_bundle ? provider.is_bundle : true).map((provider) => __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
try {
|
|
97
|
-
const txHash = yield provider.send();
|
|
98
|
-
results.push(txHash);
|
|
99
|
-
(0, dist_1.log_info)(`Transaction sent successfully`, { provider: provider.name, order_trace_id, txHash });
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
errors.push(`${provider.name}: ${error.message}`);
|
|
103
|
-
(0, dist_1.log_info)(`Transaction sending failed`, { provider: provider.name, order_trace_id, error: error.message });
|
|
104
|
-
}
|
|
105
|
-
})));
|
|
106
|
-
if (errors.some(error => error.includes('nonce'))) {
|
|
107
|
-
throw new Error(`!!!!!! Some RPC providers returned nonce error: ${JSON.stringify(errors)}`);
|
|
108
|
-
}
|
|
109
|
-
if (errors.some(error => error.includes('bundle already exist') || error.includes('already known'))) {
|
|
110
|
-
return results;
|
|
111
|
-
}
|
|
112
|
-
if (results.length === 0 || errors.length > 0) {
|
|
113
|
-
throw new Error(`!!!!!! Some RPC providers failed to send transactions: ${JSON.stringify(errors)}`);
|
|
114
|
-
}
|
|
115
|
-
return results;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
exports.TransactionSender = TransactionSender;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export declare class BscStreamWSClient {
|
|
2
|
-
private host;
|
|
3
|
-
private port;
|
|
4
|
-
private wsUrl;
|
|
5
|
-
private ws;
|
|
6
|
-
constructor(host: string, port: number);
|
|
7
|
-
subscribeBlockNumber(callback: (res: any) => void): void;
|
|
8
|
-
subscribeWalletReceipts(wallets: string[], callback: (res: any) => void): void;
|
|
9
|
-
subscribeWalletBalance(callback: (res: any) => void): void;
|
|
10
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BscStreamWSClient = void 0;
|
|
7
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
8
|
-
const ws_1 = __importDefault(require("ws"));
|
|
9
|
-
class BscStreamWSClient {
|
|
10
|
-
constructor(host, port) {
|
|
11
|
-
this.ws = null;
|
|
12
|
-
this.host = host;
|
|
13
|
-
this.port = port;
|
|
14
|
-
this.wsUrl = `ws://${this.host}:${this.port}`;
|
|
15
|
-
}
|
|
16
|
-
subscribeBlockNumber(callback) {
|
|
17
|
-
this.ws = new ws_1.default(this.wsUrl);
|
|
18
|
-
this.ws.on('open', () => {
|
|
19
|
-
(0, dist_1.log_info)(`[BLOCK_NUMBER] WebSocket connected to ${this.wsUrl}`);
|
|
20
|
-
this.ws.send(JSON.stringify({ type: 'subscribe', data: { type: 'BLOCK_NUMBER' } }));
|
|
21
|
-
});
|
|
22
|
-
this.ws.on('message', (data) => {
|
|
23
|
-
try {
|
|
24
|
-
const msg = JSON.parse(data.toString());
|
|
25
|
-
callback(msg);
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
(0, dist_1.log_info)(`[BLOCK_NUMBER] received raw message:`, data.toString());
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
this.ws.on('error', (error) => {
|
|
32
|
-
(0, dist_1.log_error)(`[BLOCK_NUMBER] WebSocket error:`, error);
|
|
33
|
-
this.ws.close();
|
|
34
|
-
});
|
|
35
|
-
this.ws.on('close', () => {
|
|
36
|
-
(0, dist_1.log_info)(`[BLOCK_NUMBER] WebSocket closed, reconnecting in 1s...`);
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
this.subscribeBlockNumber(callback);
|
|
39
|
-
}, 1000);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
subscribeWalletReceipts(wallets = [], callback) {
|
|
43
|
-
this.ws = new ws_1.default(this.wsUrl);
|
|
44
|
-
this.ws.on('open', () => {
|
|
45
|
-
(0, dist_1.log_info)(`[WALLET_RECEIPT] WebSocket connected to ${this.wsUrl}, wallets=${wallets.length}`, wallets);
|
|
46
|
-
this.ws.send(JSON.stringify({ type: 'subscribe', data: { type: 'WALLET_RECEIPT', wallets } }));
|
|
47
|
-
});
|
|
48
|
-
this.ws.on('message', (data) => {
|
|
49
|
-
try {
|
|
50
|
-
const msg = JSON.parse(data.toString());
|
|
51
|
-
callback(msg);
|
|
52
|
-
}
|
|
53
|
-
catch (err) {
|
|
54
|
-
(0, dist_1.log_info)(`[WALLET_RECEIPT] received raw message:`, data.toString());
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
this.ws.on('error', (error) => {
|
|
58
|
-
(0, dist_1.log_error)(`[WALLET_RECEIPT] WebSocket error:`, error);
|
|
59
|
-
this.ws.close();
|
|
60
|
-
});
|
|
61
|
-
this.ws.on('close', () => {
|
|
62
|
-
(0, dist_1.log_info)(`[WALLET_RECEIPT] WebSocket closed, try reconnect in 1s...`);
|
|
63
|
-
setTimeout(() => {
|
|
64
|
-
this.subscribeWalletReceipts(wallets, callback);
|
|
65
|
-
}, 1000);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
subscribeWalletBalance(callback) {
|
|
69
|
-
this.ws = new ws_1.default(this.wsUrl);
|
|
70
|
-
this.ws.on('open', () => {
|
|
71
|
-
(0, dist_1.log_info)(`[WALLET_BALANCE] WebSocket connected to ${this.wsUrl}`);
|
|
72
|
-
this.ws.send(JSON.stringify({ type: 'subscribe', data: { type: 'WALLET_BALANCE' } }));
|
|
73
|
-
});
|
|
74
|
-
this.ws.on('message', (data) => {
|
|
75
|
-
try {
|
|
76
|
-
const msg = JSON.parse(data.toString());
|
|
77
|
-
callback(msg);
|
|
78
|
-
}
|
|
79
|
-
catch (err) {
|
|
80
|
-
(0, dist_1.log_info)(`[WALLET_BALANCE] received raw message:`, data.toString());
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
this.ws.on('error', (error) => {
|
|
84
|
-
(0, dist_1.log_error)(`[WALLET_BALANCE] WebSocket error:`, error);
|
|
85
|
-
this.ws.close();
|
|
86
|
-
});
|
|
87
|
-
this.ws.on('close', () => {
|
|
88
|
-
(0, dist_1.log_info)(`[WALLET_BALANCE] WebSocket closed, try reconnect in 1s...`);
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
this.subscribeWalletBalance(callback);
|
|
91
|
-
}, 1000);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
exports.BscStreamWSClient = BscStreamWSClient;
|