@clonegod/ttd-bsc-common 1.0.66 → 1.0.68
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/trade/abstract_dex_trade_plus.js +1 -1
- package/dist/trade/send/48club.d.ts +3 -3
- package/dist/trade/send/48club.js +36 -7
- package/dist/trade/send/48club_member.d.ts +1 -0
- package/dist/trade/send/48club_member.js +21 -0
- package/dist/trade/send/48club_sp.js +4 -1
- package/dist/trade/send/blxr.d.ts +0 -8
- package/dist/trade/send/blxr.js +0 -30
- package/dist/trade/send/send_bundle_ws.d.ts +7 -0
- package/dist/trade/send/send_bundle_ws.js +30 -0
- package/dist/trade/send/send_tx.d.ts +2 -2
- package/dist/trade/send/send_tx.js +31 -14
- package/package.json +1 -1
|
@@ -415,7 +415,7 @@ class AbstractEvmDexTradePlus extends dist_1.AbastrcatTrade {
|
|
|
415
415
|
getWalletNextNonce(walletAddress) {
|
|
416
416
|
return __awaiter(this, void 0, void 0, function* () {
|
|
417
417
|
try {
|
|
418
|
-
const wallet_assets = yield this.redisClient.hgetvalue(`${this.chainNameLower}:wallet:assets`, walletAddress);
|
|
418
|
+
const wallet_assets = yield this.redisClient.hgetvalue(`${this.chainNameLower}:wallet:assets`, walletAddress.toLowerCase());
|
|
419
419
|
if (!wallet_assets) {
|
|
420
420
|
return 0;
|
|
421
421
|
}
|
|
@@ -9,9 +9,9 @@ export interface BundleParams {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class _48ClubTrade {
|
|
11
11
|
private rpcUrl;
|
|
12
|
-
|
|
13
|
-
constructor(soulPointSignature?: string);
|
|
12
|
+
constructor();
|
|
14
13
|
sendPrivateTransaction(signedTx: string): Promise<string>;
|
|
15
|
-
|
|
14
|
+
get48SPSignature(txs: string[]): Promise<string>;
|
|
15
|
+
sendPrivateTransactionWith48SP(signedTx: string): Promise<string>;
|
|
16
16
|
sendBundle(params: BundleParams): Promise<string>;
|
|
17
17
|
}
|
|
@@ -14,11 +14,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports._48ClubTrade = exports._48CLUB_BUILDER_CONTROL_EOA = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const _48club_sp_1 = require("./48club_sp");
|
|
18
|
+
const _48club_member_1 = require("./48club_member");
|
|
17
19
|
exports._48CLUB_BUILDER_CONTROL_EOA = '0x4848489f0b2BEdd788c696e2D79b6b69D7484848';
|
|
18
20
|
class _48ClubTrade {
|
|
19
|
-
constructor(
|
|
21
|
+
constructor() {
|
|
20
22
|
this.rpcUrl = process.env._48CLUB_RPC_URL || 'https://puissant-builder.48.club/';
|
|
21
|
-
this.soulPointSignature = soulPointSignature;
|
|
22
23
|
}
|
|
23
24
|
sendPrivateTransaction(signedTx) {
|
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -42,17 +43,28 @@ class _48ClubTrade {
|
|
|
42
43
|
}
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
+
get48SPSignature(txs) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const spPrivateKey = (0, _48club_member_1.get_48club_sp_private_key)();
|
|
49
|
+
if (!spPrivateKey) {
|
|
50
|
+
throw new Error('48 SoulPoint private key is required. Please set _48CLUB_SP_WALLET_ID environment variable.');
|
|
51
|
+
}
|
|
52
|
+
return _48club_sp_1.SoulPointSignature.generate48SPSignature(spPrivateKey, txs);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
sendPrivateTransactionWith48SP(signedTx) {
|
|
46
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
57
|
try {
|
|
48
|
-
|
|
49
|
-
|
|
58
|
+
const spPrivateKey = (0, _48club_member_1.get_48club_sp_private_key)();
|
|
59
|
+
if (!spPrivateKey) {
|
|
60
|
+
throw new Error('48 SoulPoint private key is required. Please set _48CLUB_SP_WALLET_ID environment variable.');
|
|
50
61
|
}
|
|
62
|
+
const spSignature = _48club_sp_1.SoulPointSignature.generate48SPSignature(spPrivateKey, [signedTx]);
|
|
51
63
|
const response = yield axios_1.default.post(this.rpcUrl, {
|
|
52
64
|
jsonrpc: "2.0",
|
|
53
65
|
id: "1",
|
|
54
66
|
method: "eth_sendPrivateTransactionWith48SP",
|
|
55
|
-
params: [signedTx,
|
|
67
|
+
params: [signedTx, spSignature]
|
|
56
68
|
});
|
|
57
69
|
if (response.data.error) {
|
|
58
70
|
throw new Error(`RPC Error: ${response.data.error.message}`);
|
|
@@ -71,7 +83,24 @@ class _48ClubTrade {
|
|
|
71
83
|
return __awaiter(this, void 0, void 0, function* () {
|
|
72
84
|
try {
|
|
73
85
|
const currentTimestamp = Math.floor(Date.now() / 1000);
|
|
74
|
-
const requestParams =
|
|
86
|
+
const requestParams = {
|
|
87
|
+
txs: params.txs,
|
|
88
|
+
maxBlockNumber: params.maxBlockNumber,
|
|
89
|
+
maxTimestamp: params.maxTimestamp || currentTimestamp + 30,
|
|
90
|
+
revertingTxHashes: params.revertingTxHashes,
|
|
91
|
+
noMerge: params.noMerge,
|
|
92
|
+
backrunTarget: params.backrunTarget,
|
|
93
|
+
};
|
|
94
|
+
const spPrivateKey = (0, _48club_member_1.get_48club_sp_private_key)();
|
|
95
|
+
if (spPrivateKey) {
|
|
96
|
+
try {
|
|
97
|
+
const spSignature = _48club_sp_1.SoulPointSignature.generate48SPSignature(spPrivateKey, params.txs);
|
|
98
|
+
requestParams['48spSign'] = spSignature;
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
console.warn(`[48CLUB] 生成 48SP 签名失败,将发送不带签名的 Bundle: ${error.message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
75
104
|
const response = yield axios_1.default.post(this.rpcUrl, {
|
|
76
105
|
jsonrpc: "2.0",
|
|
77
106
|
id: "1",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const get_48club_sp_private_key: () => string | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_48club_sp_private_key = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
+
var _48club_sp_wallet_private_key = null;
|
|
6
|
+
const get_48club_sp_private_key = () => {
|
|
7
|
+
if (_48club_sp_wallet_private_key) {
|
|
8
|
+
return _48club_sp_wallet_private_key;
|
|
9
|
+
}
|
|
10
|
+
try {
|
|
11
|
+
const wallet = (0, dist_1.load_wallet)(process.env._48CLUB_SP_WALLET_ID || 'TTD-PAYMENT');
|
|
12
|
+
console.log('Load 48club SP wallet success, wallet address:', wallet.public_key);
|
|
13
|
+
_48club_sp_wallet_private_key = wallet.private_key;
|
|
14
|
+
return _48club_sp_wallet_private_key;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.error('Load 48club SP wallet failed:' + error.message);
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.get_48club_sp_private_key = get_48club_sp_private_key;
|
|
@@ -24,7 +24,10 @@ class SoulPointSignature {
|
|
|
24
24
|
const concatenatedHashes = ethers_1.ethers.utils.concat(txHashes);
|
|
25
25
|
const messageHash = ethers_1.ethers.utils.keccak256(concatenatedHashes);
|
|
26
26
|
const signature = wallet._signingKey().signDigest(messageHash);
|
|
27
|
-
|
|
27
|
+
const r = signature.r.slice(2).padStart(64, '0');
|
|
28
|
+
const s = signature.s.slice(2).padStart(64, '0');
|
|
29
|
+
const v = signature.recoveryParam.toString(16).padStart(2, '0');
|
|
30
|
+
return '0x' + r + s + v;
|
|
28
31
|
}
|
|
29
32
|
catch (error) {
|
|
30
33
|
throw new Error(`生成48 SoulPoint签名失败: ${error}`);
|
package/dist/trade/send/blxr.js
CHANGED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlxrTradeProxy = void 0;
|
|
4
|
-
const dist_1 = require("@clonegod/ttd-core/dist");
|
|
5
|
-
class BlxrTradeProxy {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.wsUrl = process.env.BLOX_SEND_TX_WS_ENDPOINT || 'ws://127.0.0.1:7002/bsc/send_tx';
|
|
8
|
-
this.authToken = process.env.BLOX_AUTH_KEY || '';
|
|
9
|
-
this.init();
|
|
10
|
-
}
|
|
11
|
-
init() {
|
|
12
|
-
this.ws = new dist_1.WebSocketClient(this.wsUrl);
|
|
13
|
-
this.ws.onOpen(() => {
|
|
14
|
-
console.log('Blxr ws proxy connected:', this.wsUrl);
|
|
15
|
-
});
|
|
16
|
-
this.ws.onMessage((message) => {
|
|
17
|
-
console.log('Blxr ws proxy received message', message);
|
|
18
|
-
});
|
|
19
|
-
this.ws.connect();
|
|
20
|
-
}
|
|
21
|
-
sendTransaction(pair, mainTx, tipTx, blockNumber = 0) {
|
|
22
|
-
this.ws.send(JSON.stringify({
|
|
23
|
-
pair,
|
|
24
|
-
mainTx,
|
|
25
|
-
tipTx,
|
|
26
|
-
blockNumber
|
|
27
|
-
}));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.BlxrTradeProxy = BlxrTradeProxy;
|
|
@@ -0,0 +1,30 @@
|
|
|
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;
|
|
@@ -3,7 +3,7 @@ export declare class TransactionSender {
|
|
|
3
3
|
private rpc;
|
|
4
4
|
private blockRazor;
|
|
5
5
|
private _48Club;
|
|
6
|
-
private
|
|
6
|
+
private sendBundleProxy;
|
|
7
7
|
constructor(appConfig: AppConfig);
|
|
8
|
-
sendTransaction(signedMainTx: string, eoa_tip_transaction: (eoa_address: string) => Promise<string>, order_trace_id: string, pair?: string): Promise<string[]>;
|
|
8
|
+
sendTransaction(signedMainTx: string, eoa_tip_transaction: (eoa_address: string) => Promise<string>, order_trace_id: string, pair?: string, only_bundle?: boolean): Promise<string[]>;
|
|
9
9
|
}
|
|
@@ -15,67 +15,84 @@ const blockrazor_1 = require("./blockrazor");
|
|
|
15
15
|
const bsc_rpc_1 = require("./bsc_rpc");
|
|
16
16
|
const _48club_1 = require("./48club");
|
|
17
17
|
const _1 = require(".");
|
|
18
|
-
const
|
|
18
|
+
const send_bundle_ws_1 = require("./send_bundle_ws");
|
|
19
19
|
class TransactionSender {
|
|
20
20
|
constructor(appConfig) {
|
|
21
21
|
this.rpc = new bsc_rpc_1.BscMainnetRpc(appConfig.env_args.rpc_endpoint);
|
|
22
22
|
this.blockRazor = new blockrazor_1.BlockRazorTrade();
|
|
23
23
|
this._48Club = new _48club_1._48ClubTrade();
|
|
24
|
-
this.
|
|
24
|
+
this.sendBundleProxy = new send_bundle_ws_1.BscSendTxProxy();
|
|
25
25
|
}
|
|
26
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 = '') {
|
|
27
|
+
return __awaiter(this, arguments, void 0, function* (signedMainTx, eoa_tip_transaction, order_trace_id, pair = '', only_bundle = false) {
|
|
28
28
|
const rpcProviders = [
|
|
29
29
|
{
|
|
30
30
|
name: 'Default (QuickNode / Merkle)',
|
|
31
31
|
enable: process.env.SEND_TX_DEFAULT_RPC_PRIVATE === 'true',
|
|
32
|
+
is_bundle: false,
|
|
32
33
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
33
34
|
return yield this.rpc.eth_sendRawTransaction(signedMainTx);
|
|
34
35
|
})
|
|
35
36
|
},
|
|
36
37
|
{
|
|
37
|
-
name: 'BlockRazor - Private Transaction',
|
|
38
|
+
name: 'BlockRazor HTTP - Private Transaction',
|
|
38
39
|
enable: process.env.SEND_TX_BLOCKRAZOR_PRIVATE === 'true',
|
|
40
|
+
is_bundle: false,
|
|
39
41
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
40
42
|
return yield this.blockRazor.sendPrivateTransaction(signedMainTx);
|
|
41
43
|
})
|
|
42
44
|
},
|
|
43
45
|
{
|
|
44
|
-
name: 'BlockRazor - sendBundle',
|
|
46
|
+
name: 'BlockRazor HTTP - sendBundle',
|
|
45
47
|
enable: process.env.SEND_TX_BLOCKRAZOR_BUNDLE === 'true',
|
|
48
|
+
is_bundle: true,
|
|
46
49
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
47
50
|
let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS.BLOCKRAZOR)];
|
|
48
51
|
return yield this.blockRazor.sendBundle(bundle);
|
|
49
52
|
})
|
|
50
53
|
},
|
|
51
54
|
{
|
|
52
|
-
name: '48Club - Private Transaction',
|
|
55
|
+
name: '48Club - HTTP - Private Transaction With 48SP',
|
|
53
56
|
enable: process.env.SEND_TX_48CLUB_PRIVATE === 'true',
|
|
57
|
+
is_bundle: false,
|
|
54
58
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
return yield this._48Club.
|
|
59
|
+
return yield this._48Club.sendPrivateTransactionWith48SP(signedMainTx);
|
|
56
60
|
})
|
|
57
61
|
},
|
|
58
62
|
{
|
|
59
|
-
name: '48Club - sendBundle',
|
|
63
|
+
name: '48Club - HTTP - sendBundle',
|
|
60
64
|
enable: process.env.SEND_TX_48CLUB_BUNDLE === 'true',
|
|
65
|
+
is_bundle: true,
|
|
61
66
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
62
67
|
let bundle = [signedMainTx, yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS._48CLUB)];
|
|
63
68
|
return yield this._48Club.sendBundle({ txs: bundle });
|
|
64
69
|
})
|
|
65
70
|
},
|
|
66
71
|
{
|
|
67
|
-
name: '
|
|
68
|
-
enable: process.env.
|
|
72
|
+
name: '48Club - WS - sendBundle',
|
|
73
|
+
enable: process.env.SEND_TX_48CLUB_BUNDLE_WS === 'true',
|
|
74
|
+
is_bundle: true,
|
|
69
75
|
send: () => __awaiter(this, void 0, void 0, function* () {
|
|
70
76
|
const tipTx = yield eoa_tip_transaction(_1.BSC_EOA_ADDRESS.BLXR);
|
|
71
|
-
this.
|
|
72
|
-
|
|
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');
|
|
73
80
|
})
|
|
74
|
-
}
|
|
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
|
+
},
|
|
75
92
|
];
|
|
76
93
|
const results = [];
|
|
77
94
|
const errors = [];
|
|
78
|
-
yield Promise.all(rpcProviders.filter(provider => provider.enable).map((provider) => __awaiter(this, void 0, void 0, function* () {
|
|
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* () {
|
|
79
96
|
try {
|
|
80
97
|
const txHash = yield provider.send();
|
|
81
98
|
results.push(txHash);
|