@clonegod/ttd-sol-common 1.0.14 → 1.0.16
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/constants.d.ts +9 -0
- package/dist/constants.js +15 -0
- package/dist/context.d.ts +11 -0
- package/dist/context.js +18 -0
- package/dist/get_signature.d.ts +2 -0
- package/dist/get_signature.js +15 -0
- package/dist/helius_geyser_ws.d.ts +4 -0
- package/dist/helius_geyser_ws.js +93 -0
- package/dist/helius_sdk_v1.4.0/Helius.d.ts +2 -1
- package/dist/helius_sdk_v1.4.0/Helius.js +2 -2
- package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +3 -1
- package/dist/helius_sdk_v1.4.0/RpcClient.js +85 -62
- package/dist/index.d.ts +3 -27
- package/dist/index.js +16 -174
- package/dist/send_transaction.d.ts +20 -0
- package/dist/send_transaction.js +152 -0
- package/package.json +6 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const MAX_GAS_FEE: number;
|
|
2
|
+
export declare enum COMMITMENT_LEVEL {
|
|
3
|
+
PROCESSED = "processed",
|
|
4
|
+
CONFIRMED = "confirmed",
|
|
5
|
+
_FINALIZED = "finalized"
|
|
6
|
+
}
|
|
7
|
+
export declare enum LOCAL_EVENT_NAME {
|
|
8
|
+
EVENT_POOL_ACCOUNT_CHANGE = "EVENT_POOL_ACCOUNT_CHANGE"
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LOCAL_EVENT_NAME = exports.COMMITMENT_LEVEL = exports.MAX_GAS_FEE = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
exports.MAX_GAS_FEE = web3_js_1.LAMPORTS_PER_SOL / 1000;
|
|
6
|
+
var COMMITMENT_LEVEL;
|
|
7
|
+
(function (COMMITMENT_LEVEL) {
|
|
8
|
+
COMMITMENT_LEVEL["PROCESSED"] = "processed";
|
|
9
|
+
COMMITMENT_LEVEL["CONFIRMED"] = "confirmed";
|
|
10
|
+
COMMITMENT_LEVEL["_FINALIZED"] = "finalized";
|
|
11
|
+
})(COMMITMENT_LEVEL || (exports.COMMITMENT_LEVEL = COMMITMENT_LEVEL = {}));
|
|
12
|
+
var LOCAL_EVENT_NAME;
|
|
13
|
+
(function (LOCAL_EVENT_NAME) {
|
|
14
|
+
LOCAL_EVENT_NAME["EVENT_POOL_ACCOUNT_CHANGE"] = "EVENT_POOL_ACCOUNT_CHANGE";
|
|
15
|
+
})(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
export declare class _Context {
|
|
3
|
+
read_connection: Connection;
|
|
4
|
+
set_read_connection(read_connection: Connection): void;
|
|
5
|
+
priority_fee: number;
|
|
6
|
+
set_priority_fee(priority_fee: any): void;
|
|
7
|
+
cu_price: number;
|
|
8
|
+
set_cu_price(cu_price: number): void;
|
|
9
|
+
cu_limit: number;
|
|
10
|
+
set_cu_limit(cu_limit: number): void;
|
|
11
|
+
}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._Context = void 0;
|
|
4
|
+
class _Context {
|
|
5
|
+
set_read_connection(read_connection) {
|
|
6
|
+
this.read_connection = read_connection;
|
|
7
|
+
}
|
|
8
|
+
set_priority_fee(priority_fee) {
|
|
9
|
+
this.priority_fee = priority_fee;
|
|
10
|
+
}
|
|
11
|
+
set_cu_price(cu_price) {
|
|
12
|
+
this.cu_price = cu_price;
|
|
13
|
+
}
|
|
14
|
+
set_cu_limit(cu_limit) {
|
|
15
|
+
this.cu_limit = cu_limit;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports._Context = _Context;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.getSignature = void 0;
|
|
7
|
+
const bs58_1 = __importDefault(require("bs58"));
|
|
8
|
+
function getSignature(transaction) {
|
|
9
|
+
const signature = 'signature' in transaction ? transaction.signature : transaction.signatures[0];
|
|
10
|
+
if (!signature) {
|
|
11
|
+
throw new Error('Missing transaction signature, the transaction was not signed by the fee payer');
|
|
12
|
+
}
|
|
13
|
+
return bs58_1.default.encode(signature);
|
|
14
|
+
}
|
|
15
|
+
exports.getSignature = getSignature;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { StandardPoolInfoType } from "@clonegod/ttd-common";
|
|
3
|
+
import EventEmitter from "events";
|
|
4
|
+
export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
|
|
@@ -0,0 +1,93 @@
|
|
|
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.subscribe_pool_change_by_geyser = void 0;
|
|
16
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
17
|
+
const ws_1 = __importDefault(require("ws"));
|
|
18
|
+
const _1 = require(".");
|
|
19
|
+
const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
if ((0, dist_1.isEmpty)(geyser_ws_url)) {
|
|
21
|
+
(0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if ((0, dist_1.isEmpty)(pool_list)) {
|
|
25
|
+
(0, dist_1.log_warn)(`pool_list is empty, nothing to subscribe`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
yield (0, dist_1.sleep)(1000);
|
|
29
|
+
var ws_client = new ws_1.default(geyser_ws_url);
|
|
30
|
+
function subscribe_account_change(ws_client, pool) {
|
|
31
|
+
(0, dist_1.log_info)(`subscribe: ${pool.pool_name} -> ${pool.pool_address}`);
|
|
32
|
+
const request = {
|
|
33
|
+
jsonrpc: '2.0',
|
|
34
|
+
id: 420,
|
|
35
|
+
method: 'accountSubscribe',
|
|
36
|
+
params: [
|
|
37
|
+
pool.pool_address,
|
|
38
|
+
{
|
|
39
|
+
encoding: 'jsonParsed',
|
|
40
|
+
commitment: _1.COMMITMENT_LEVEL.PROCESSED,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
ws_client.send(JSON.stringify(request));
|
|
45
|
+
}
|
|
46
|
+
ws_client.on('open', function open() {
|
|
47
|
+
(0, dist_1.log_info)(`WebSocket is open`);
|
|
48
|
+
pool_list.forEach((pool) => {
|
|
49
|
+
subscribe_account_change(ws_client, pool);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
ws_client.on('message', function incoming(data) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
(0, dist_1.log_info)(`Received Geyser Message`);
|
|
55
|
+
let messageStr = '';
|
|
56
|
+
try {
|
|
57
|
+
messageStr = data.toString('utf8');
|
|
58
|
+
if (dist_1.LOG.trace) {
|
|
59
|
+
(0, dist_1.log_trace)(`Received msg:`, messageStr);
|
|
60
|
+
}
|
|
61
|
+
if (messageStr == '{}') {
|
|
62
|
+
(0, dist_1.log_info)(`receive empty message, something wrong! exit ...`);
|
|
63
|
+
ws_client.close();
|
|
64
|
+
}
|
|
65
|
+
const messageObj = JSON.parse(messageStr);
|
|
66
|
+
if (messageObj['id']) {
|
|
67
|
+
(0, dist_1.log_info)(`accountSubscribe success!`, messageStr);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const res_data = messageObj['params']['result']['value']['data'];
|
|
72
|
+
let data_buff = Buffer.from(res_data[0], res_data[1]);
|
|
73
|
+
eventEmitter.emit(_1.LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
(0, dist_1.log_error)(`Failed to parse JSON: ${messageStr}`, err);
|
|
78
|
+
ws_client.close();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
ws_client.on('error', function error(err) {
|
|
83
|
+
(0, dist_1.log_error)(`WebSocket error:`, err);
|
|
84
|
+
ws_client.close();
|
|
85
|
+
});
|
|
86
|
+
ws_client.on('close', function close() {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
(0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
|
|
89
|
+
(0, exports.subscribe_pool_change_by_geyser)(geyser_ws_url, pool_list, eventEmitter);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
exports.subscribe_pool_change_by_geyser = subscribe_pool_change_by_geyser;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Webhook, CreateWebhookRequest, EditWebhookRequest, CreateCollectionWebhookRequest, MintlistRequest, MintlistResponse, MintApiRequest, MintApiResponse, MintApiAuthority, DelegateCollectionAuthorityRequest, RevokeCollectionAuthorityRequest, HeliusCluster, HeliusEndpoints } from './types';
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { RpcClient } from './RpcClient';
|
|
4
|
+
import { _Context } from '../context';
|
|
4
5
|
export declare class Helius {
|
|
5
6
|
private apiKey?;
|
|
6
7
|
readonly cluster: HeliusCluster;
|
|
@@ -9,7 +10,7 @@ export declare class Helius {
|
|
|
9
10
|
readonly connection: Connection;
|
|
10
11
|
readonly rpc: RpcClient;
|
|
11
12
|
readonly mintApiAuthority: MintApiAuthority;
|
|
12
|
-
constructor(apiKey: string, cluster
|
|
13
|
+
constructor(apiKey: string, cluster: HeliusCluster, id: string, url: string, _context: _Context);
|
|
13
14
|
getAllWebhooks(): Promise<Webhook[]>;
|
|
14
15
|
getWebhookByID(webhookID: string): Promise<Webhook>;
|
|
15
16
|
createWebhook(createWebhookRequest: CreateWebhookRequest): Promise<Webhook>;
|
|
@@ -45,7 +45,7 @@ const RpcClient_1 = require("./RpcClient");
|
|
|
45
45
|
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
46
46
|
const mintApi_1 = require("./utils/mintApi");
|
|
47
47
|
class Helius {
|
|
48
|
-
constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '') {
|
|
48
|
+
constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '', _context) {
|
|
49
49
|
this.cluster = cluster;
|
|
50
50
|
this.endpoints = (0, utils_1.getHeliusEndpoints)(cluster);
|
|
51
51
|
if (apiKey !== '') {
|
|
@@ -59,7 +59,7 @@ class Helius {
|
|
|
59
59
|
throw Error('either `apiKey` or `url` is required');
|
|
60
60
|
}
|
|
61
61
|
this.endpoint = this.connection.rpcEndpoint;
|
|
62
|
-
this.rpc = new RpcClient_1.RpcClient(this.connection, id);
|
|
62
|
+
this.rpc = new RpcClient_1.RpcClient(_context, this.connection, id);
|
|
63
63
|
this.mintApiAuthority = (0, mintApi_1.mintApiAuthority)(cluster);
|
|
64
64
|
}
|
|
65
65
|
getAllWebhooks() {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { BlockhashWithExpiryBlockHeight, VersionedTransaction, AddressLookupTableAccount, Transaction, TransactionInstruction, TransactionSignature, Commitment, PublicKey, AccountInfo, GetLatestBlockhashConfig, RpcResponseAndContext, SignatureResult, Blockhash, Connection, ParsedAccountData, SendOptions, Signer, SerializeConfig } from '@solana/web3.js';
|
|
4
4
|
import { DAS } from './types/das-types';
|
|
5
5
|
import { GetPriorityFeeEstimateRequest, GetPriorityFeeEstimateResponse, JitoRegion, PollTransactionOptions, SmartTransactionContext, HeliusSendOptions } from './types';
|
|
6
|
+
import { _Context } from '../context';
|
|
6
7
|
export type SendAndConfirmTransactionResponse = {
|
|
7
8
|
signature: TransactionSignature;
|
|
8
9
|
confirmResponse: RpcResponseAndContext<SignatureResult>;
|
|
@@ -10,9 +11,10 @@ export type SendAndConfirmTransactionResponse = {
|
|
|
10
11
|
lastValidBlockHeight: number;
|
|
11
12
|
};
|
|
12
13
|
export declare class RpcClient {
|
|
14
|
+
protected readonly _context: _Context;
|
|
13
15
|
protected readonly connection: Connection;
|
|
14
16
|
protected readonly id?: string;
|
|
15
|
-
constructor(connection: Connection, id?: string);
|
|
17
|
+
constructor(_context: _Context, connection: Connection, id?: string);
|
|
16
18
|
airdrop(publicKey: PublicKey, lamports: number, commitment?: Commitment): Promise<SendAndConfirmTransactionResponse>;
|
|
17
19
|
getLatestBlockhash(commitmentOrConfig?: Commitment | GetLatestBlockhashConfig): Promise<BlockhashWithExpiryBlockHeight>;
|
|
18
20
|
getCurrentTPS(): Promise<number>;
|
|
@@ -17,8 +17,11 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
17
17
|
const bs58_1 = __importDefault(require("bs58"));
|
|
18
18
|
const axios_1 = __importDefault(require("axios"));
|
|
19
19
|
const types_1 = require("./types");
|
|
20
|
+
const get_signature_1 = require("../get_signature");
|
|
21
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
20
22
|
class RpcClient {
|
|
21
|
-
constructor(connection, id) {
|
|
23
|
+
constructor(_context, connection, id) {
|
|
24
|
+
this._context = _context;
|
|
22
25
|
this.connection = connection;
|
|
23
26
|
this.id = id;
|
|
24
27
|
}
|
|
@@ -388,27 +391,37 @@ class RpcClient {
|
|
|
388
391
|
legacyTransaction.partialSign(feePayer);
|
|
389
392
|
}
|
|
390
393
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
394
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
395
|
+
if (Math.random() > 0)
|
|
396
|
+
return;
|
|
397
|
+
const serializedTransaction = bs58_1.default.encode(isVersioned
|
|
398
|
+
? versionedTransaction.serialize()
|
|
399
|
+
: legacyTransaction.serialize(serializeOptions));
|
|
400
|
+
const priorityFeeEstimateResponse = yield this.getPriorityFeeEstimate({
|
|
401
|
+
transaction: serializedTransaction,
|
|
402
|
+
options: {
|
|
403
|
+
recommended: true,
|
|
404
|
+
},
|
|
405
|
+
});
|
|
406
|
+
const { priorityFeeEstimate } = priorityFeeEstimateResponse;
|
|
407
|
+
if (!priorityFeeEstimate) {
|
|
408
|
+
throw new Error('Priority fee estimate not available');
|
|
409
|
+
}
|
|
410
|
+
}), 0);
|
|
411
|
+
let priorityFeeEstimate = this._context.cu_price;
|
|
404
412
|
const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
405
413
|
microLamports: priorityFeeEstimate,
|
|
406
414
|
});
|
|
407
415
|
instructions.unshift(computeBudgetIx);
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
417
|
+
if (Math.random() > 0)
|
|
418
|
+
return;
|
|
419
|
+
const units = yield this.getComputeUnits(instructions, payerKey, isVersioned ? lookupTables : [], signers);
|
|
420
|
+
if (!units) {
|
|
421
|
+
throw new Error(`Error fetching compute units for the instructions provided`);
|
|
422
|
+
}
|
|
423
|
+
}), 0);
|
|
424
|
+
let units = this._context.cu_limit;
|
|
412
425
|
const customersCU = units < 1000 ? 1000 : Math.ceil(units * 1.1);
|
|
413
426
|
const computeUnitsIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
414
427
|
units: customersCU,
|
|
@@ -453,34 +466,38 @@ class RpcClient {
|
|
|
453
466
|
throw new Error('expiryBlockOffset must be a positive integer');
|
|
454
467
|
try {
|
|
455
468
|
const { transaction, blockhash, minContextSlot } = yield this.createSmartTransaction(instructions, signers, lookupTables, sendOptions.feePayer);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
abortSignal
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
469
|
+
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
470
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
471
|
+
const commitment = (sendOptions === null || sendOptions === void 0 ? void 0 : sendOptions.preflightCommitment) || 'confirmed';
|
|
472
|
+
const currentBlockHeight = yield this._context.read_connection.getBlockHeight();
|
|
473
|
+
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
474
|
+
let error;
|
|
475
|
+
do {
|
|
476
|
+
try {
|
|
477
|
+
const signature = yield this.connection.sendRawTransaction(transaction.serialize(), Object.assign({ maxRetries: 0, preflightCommitment: 'confirmed', skipPreflight: sendOptions.skipPreflight, minContextSlot }, sendOptions));
|
|
478
|
+
const abortSignal = AbortSignal.timeout(15000);
|
|
479
|
+
yield this.connection.confirmTransaction({
|
|
480
|
+
abortSignal,
|
|
481
|
+
signature,
|
|
482
|
+
blockhash: blockhash.blockhash,
|
|
483
|
+
lastValidBlockHeight: lastValidBlockHeight,
|
|
484
|
+
}, commitment);
|
|
485
|
+
abortSignal.removeEventListener('abort', () => { });
|
|
486
|
+
return signature;
|
|
487
|
+
}
|
|
488
|
+
catch (_error) {
|
|
489
|
+
if (!(_error instanceof Error))
|
|
490
|
+
error = new Error();
|
|
491
|
+
error = _error;
|
|
492
|
+
}
|
|
493
|
+
} while (!(error instanceof web3_js_1.TransactionExpiredBlockheightExceededError));
|
|
494
|
+
throw new Error('Transaction failed to confirm within lastValidBlockHeight');
|
|
495
|
+
}), 0);
|
|
496
|
+
return txid;
|
|
479
497
|
}
|
|
480
498
|
catch (error) {
|
|
481
499
|
throw new Error(`Error sending smart transaction: ${error}`);
|
|
482
500
|
}
|
|
483
|
-
throw new Error('Transaction failed to confirm within lastValidBlockHeight');
|
|
484
501
|
});
|
|
485
502
|
}
|
|
486
503
|
addTipInstruction(instructions, feePayer, tipAccount, tipAmount) {
|
|
@@ -542,28 +559,34 @@ class RpcClient {
|
|
|
542
559
|
throw new Error('The transaction must have at least one signer');
|
|
543
560
|
}
|
|
544
561
|
const { transaction, blockhash } = yield this.createSmartTransactionWithTip(instructions, signers, lookupTables, tipAmount, feePayer);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
bundleStatuses.
|
|
558
|
-
bundleStatuses
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
+
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
563
|
+
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
564
|
+
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
|
|
565
|
+
const jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
|
|
566
|
+
const bundleId = yield this.sendJitoBundle([serializedTransaction], jitoApiUrl);
|
|
567
|
+
const currentBlockHeight = yield this._context.read_connection.getBlockHeight();
|
|
568
|
+
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
569
|
+
const timeout = 60000;
|
|
570
|
+
const interval = 5000;
|
|
571
|
+
const startTime = Date.now();
|
|
572
|
+
while (Date.now() - startTime < timeout ||
|
|
573
|
+
(yield this.connection.getBlockHeight()) <= lastValidBlockHeight) {
|
|
574
|
+
const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
|
|
575
|
+
if (bundleStatuses &&
|
|
576
|
+
bundleStatuses.value &&
|
|
577
|
+
bundleStatuses.value.length > 0) {
|
|
578
|
+
const status = bundleStatuses.value[0].confirmation_status;
|
|
579
|
+
if (status === 'confirmed') {
|
|
580
|
+
return bundleStatuses.value[0].transactions[0];
|
|
581
|
+
}
|
|
562
582
|
}
|
|
583
|
+
yield new Promise((resolve) => setTimeout(resolve, interval));
|
|
563
584
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
585
|
+
let err = new Error('Bundle failed to confirm within the timeout period');
|
|
586
|
+
(0, dist_1.log_error)(`Bundle failed to confirm, txid=${txid}`, err);
|
|
587
|
+
throw err;
|
|
588
|
+
}), 0);
|
|
589
|
+
return txid;
|
|
567
590
|
});
|
|
568
591
|
}
|
|
569
592
|
getNftEditions(params) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,27 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { Helius, JitoRegion } from "helius-sdk";
|
|
5
|
-
import { TransactionInstruction, Signer, SendOptions, TransactionSignature } from "@solana/web3.js";
|
|
6
|
-
export declare const ONE_SOL_IN_LAMPORTS = 1000000000;
|
|
7
|
-
export declare enum COMMITMENT_LEVEL {
|
|
8
|
-
PROCESSED = "processed",
|
|
9
|
-
CONFIRMED = "confirmed",
|
|
10
|
-
_FINALIZED = "finalized"
|
|
11
|
-
}
|
|
12
|
-
export declare enum LOCAL_EVENT_NAME {
|
|
13
|
-
EVENT_POOL_ACCOUNT_CHANGE = "EVENT_POOL_ACCOUNT_CHANGE"
|
|
14
|
-
}
|
|
15
|
-
export declare const subscribe_pool_change_by_geyser: (geyser_ws_url: string, pool_list: StandardPoolInfoType[], eventEmitter: EventEmitter) => Promise<void>;
|
|
16
|
-
export declare class HeliusClient {
|
|
17
|
-
helius_mainnet: Helius;
|
|
18
|
-
helius_staked: Helius;
|
|
19
|
-
helius_qn: Helius;
|
|
20
|
-
signers: Signer[];
|
|
21
|
-
sendOptions: SendOptions;
|
|
22
|
-
jito_tip_max: number;
|
|
23
|
-
constructor(signers: Signer[], jito_tip_max?: number);
|
|
24
|
-
send_smart_transaction(instructions: TransactionInstruction[], use_staked_endpint?: boolean): Promise<string>;
|
|
25
|
-
send_transaction_by_jito(instructions: TransactionInstruction[], tipAmount: number): Promise<TransactionSignature>;
|
|
26
|
-
}
|
|
27
|
-
export declare const get_jito_region: () => JitoRegion;
|
|
1
|
+
export * from './constants';
|
|
2
|
+
export * from './context';
|
|
3
|
+
export * from './helius_geyser_ws';
|
package/dist/index.js
CHANGED
|
@@ -1,177 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.get_jito_region = exports.HeliusClient = exports.subscribe_pool_change_by_geyser = exports.LOCAL_EVENT_NAME = exports.COMMITMENT_LEVEL = exports.ONE_SOL_IN_LAMPORTS = void 0;
|
|
16
|
-
const ws_1 = __importDefault(require("ws"));
|
|
17
|
-
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
18
|
-
const helius_sdk_1 = require("helius-sdk");
|
|
19
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
20
|
-
exports.ONE_SOL_IN_LAMPORTS = web3_js_1.LAMPORTS_PER_SOL;
|
|
21
|
-
var COMMITMENT_LEVEL;
|
|
22
|
-
(function (COMMITMENT_LEVEL) {
|
|
23
|
-
COMMITMENT_LEVEL["PROCESSED"] = "processed";
|
|
24
|
-
COMMITMENT_LEVEL["CONFIRMED"] = "confirmed";
|
|
25
|
-
COMMITMENT_LEVEL["_FINALIZED"] = "finalized";
|
|
26
|
-
})(COMMITMENT_LEVEL || (exports.COMMITMENT_LEVEL = COMMITMENT_LEVEL = {}));
|
|
27
|
-
var LOCAL_EVENT_NAME;
|
|
28
|
-
(function (LOCAL_EVENT_NAME) {
|
|
29
|
-
LOCAL_EVENT_NAME["EVENT_POOL_ACCOUNT_CHANGE"] = "EVENT_POOL_ACCOUNT_CHANGE";
|
|
30
|
-
})(LOCAL_EVENT_NAME || (exports.LOCAL_EVENT_NAME = LOCAL_EVENT_NAME = {}));
|
|
31
|
-
const subscribe_pool_change_by_geyser = (geyser_ws_url, pool_list, eventEmitter) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
if ((0, dist_1.isEmpty)(geyser_ws_url)) {
|
|
33
|
-
(0, dist_1.log_warn)(`geyser_ws_url is empty, cann't subscribe`);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
if ((0, dist_1.isEmpty)(pool_list)) {
|
|
37
|
-
(0, dist_1.log_warn)(`pool_list is empty, nothing to subscribe`);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
yield (0, dist_1.sleep)(1000);
|
|
41
|
-
var ws_client = new ws_1.default(geyser_ws_url);
|
|
42
|
-
function subscribe_account_change(ws_client, pool) {
|
|
43
|
-
(0, dist_1.log_info)(`subscribe: ${pool.pool_name} -> ${pool.pool_address}`);
|
|
44
|
-
const request = {
|
|
45
|
-
jsonrpc: '2.0',
|
|
46
|
-
id: 420,
|
|
47
|
-
method: 'accountSubscribe',
|
|
48
|
-
params: [
|
|
49
|
-
pool.pool_address,
|
|
50
|
-
{
|
|
51
|
-
encoding: 'jsonParsed',
|
|
52
|
-
commitment: COMMITMENT_LEVEL.PROCESSED,
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
};
|
|
56
|
-
ws_client.send(JSON.stringify(request));
|
|
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]; } };
|
|
57
7
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
(0, dist_1.log_info)(`Received Geyser Message`);
|
|
67
|
-
let messageStr = '';
|
|
68
|
-
try {
|
|
69
|
-
messageStr = data.toString('utf8');
|
|
70
|
-
if (dist_1.LOG.trace) {
|
|
71
|
-
(0, dist_1.log_trace)(`Received msg:`, messageStr);
|
|
72
|
-
}
|
|
73
|
-
if (messageStr == '{}') {
|
|
74
|
-
(0, dist_1.log_info)(`receive empty message, something wrong! exit ...`);
|
|
75
|
-
ws_client.close();
|
|
76
|
-
}
|
|
77
|
-
const messageObj = JSON.parse(messageStr);
|
|
78
|
-
if (messageObj['id']) {
|
|
79
|
-
(0, dist_1.log_info)(`accountSubscribe success!`, messageStr);
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
const res_data = messageObj['params']['result']['value']['data'];
|
|
84
|
-
let data_buff = Buffer.from(res_data[0], res_data[1]);
|
|
85
|
-
eventEmitter.emit(LOCAL_EVENT_NAME.EVENT_POOL_ACCOUNT_CHANGE, data_buff);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch (err) {
|
|
89
|
-
(0, dist_1.log_error)(`Failed to parse JSON: ${messageStr}`, err);
|
|
90
|
-
ws_client.close();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
ws_client.on('error', function error(err) {
|
|
95
|
-
(0, dist_1.log_error)(`WebSocket error:`, err);
|
|
96
|
-
ws_client.close();
|
|
97
|
-
});
|
|
98
|
-
ws_client.on('close', function close() {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
(0, dist_1.log_warn)(`Socket is closed. Reconnect will be attempted in few seconds`);
|
|
101
|
-
(0, exports.subscribe_pool_change_by_geyser)(geyser_ws_url, pool_list, eventEmitter);
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
exports.subscribe_pool_change_by_geyser = subscribe_pool_change_by_geyser;
|
|
106
|
-
class HeliusClient {
|
|
107
|
-
constructor(signers, jito_tip_max = 500000) {
|
|
108
|
-
let helius_api_key = process.env.HELIUS_API_KEY;
|
|
109
|
-
let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
|
|
110
|
-
let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
|
|
111
|
-
let quicknode_endpoint = process.env.QUICKNODE_ENDPOINT;
|
|
112
|
-
this.helius_mainnet = new helius_sdk_1.Helius(null, null, null, helius_mainnet_endpoint);
|
|
113
|
-
this.helius_staked = new helius_sdk_1.Helius(null, null, null, helius_staked_endpoint);
|
|
114
|
-
this.helius_qn = new helius_sdk_1.Helius(null, null, null, quicknode_endpoint);
|
|
115
|
-
this.signers = signers;
|
|
116
|
-
this.sendOptions = {
|
|
117
|
-
skipPreflight: true,
|
|
118
|
-
maxRetries: 0
|
|
119
|
-
};
|
|
120
|
-
this.jito_tip_max = jito_tip_max;
|
|
121
|
-
}
|
|
122
|
-
send_smart_transaction(instructions_1) {
|
|
123
|
-
return __awaiter(this, arguments, void 0, function* (instructions, use_staked_endpint = false) {
|
|
124
|
-
(0, dist_1.log_info)(`send_smart_transaction, start`);
|
|
125
|
-
let start_time = Date.now();
|
|
126
|
-
let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
|
|
127
|
-
let txid = yield rpc.sendSmartTransaction(instructions, this.signers, [], this.sendOptions);
|
|
128
|
-
(0, dist_1.log_info)(`send_smart_transaction, end`, {
|
|
129
|
-
txid,
|
|
130
|
-
use_staked_endpint,
|
|
131
|
-
take_time: Date.now() - start_time
|
|
132
|
-
});
|
|
133
|
-
return txid;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
send_transaction_by_jito(instructions, tipAmount) {
|
|
137
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
if (tipAmount > this.jito_tip_max) {
|
|
139
|
-
tipAmount = this.jito_tip_max;
|
|
140
|
-
(0, dist_1.log_warn)(`tipAmount too high!!! reset from ${tipAmount} to ${this.jito_tip_max}`);
|
|
141
|
-
}
|
|
142
|
-
(0, dist_1.log_info)(`send_transaction_by_jito, start`);
|
|
143
|
-
let start_time = Date.now();
|
|
144
|
-
let rpc = this.helius_qn.rpc;
|
|
145
|
-
let txid = yield rpc.sendSmartTransactionWithTip(instructions, this.signers, [], tipAmount, (0, exports.get_jito_region)());
|
|
146
|
-
(0, dist_1.log_info)(`send_transaction_by_jito, end`, {
|
|
147
|
-
txid,
|
|
148
|
-
take_time: Date.now() - start_time
|
|
149
|
-
});
|
|
150
|
-
return txid;
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.HeliusClient = HeliusClient;
|
|
155
|
-
const get_jito_region = () => {
|
|
156
|
-
let jito_region;
|
|
157
|
-
let server_info = (0, dist_1.getServerInfo)();
|
|
158
|
-
switch (server_info.region) {
|
|
159
|
-
case 'fra':
|
|
160
|
-
jito_region = 'Frankfurt';
|
|
161
|
-
break;
|
|
162
|
-
case 'virginia':
|
|
163
|
-
jito_region = 'NY';
|
|
164
|
-
break;
|
|
165
|
-
case 'jp':
|
|
166
|
-
jito_region = 'Tokyo';
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
jito_region = 'Default';
|
|
170
|
-
}
|
|
171
|
-
(0, dist_1.log_debug)(`get_jito_region`, {
|
|
172
|
-
server_info,
|
|
173
|
-
jito_region
|
|
174
|
-
});
|
|
175
|
-
return jito_region;
|
|
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);
|
|
176
15
|
};
|
|
177
|
-
exports
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
18
|
+
__exportStar(require("./context"), exports);
|
|
19
|
+
__exportStar(require("./helius_geyser_ws"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
|
|
2
|
+
import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { Helius, JitoRegion } from "./helius_sdk_v1.4.0";
|
|
4
|
+
import { _Context } from "./context";
|
|
5
|
+
export declare class HeliusClient {
|
|
6
|
+
signers: Signer[];
|
|
7
|
+
sendOptions: SendOptions;
|
|
8
|
+
cluster: string;
|
|
9
|
+
helius_mainnet: Helius;
|
|
10
|
+
helius_staked: Helius;
|
|
11
|
+
_context: _Context;
|
|
12
|
+
constructor(signers: Signer[]);
|
|
13
|
+
send_transaction(trade_runtime: TradeRuntimeType, instructions: TransactionInstruction[]): Promise<string>;
|
|
14
|
+
private send_smart_transaction;
|
|
15
|
+
private send_transaction_by_jito;
|
|
16
|
+
get_jito_region(): JitoRegion;
|
|
17
|
+
get_gas_fee(trade_strategy: TradeStrategyType): number;
|
|
18
|
+
get_excat_fee_by_speed(speed: string, fee_exact: number): number;
|
|
19
|
+
get_dynamic_fee_by_speed(speed: string, estimate_priority_fee: number, fee_max_cap: number): number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
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.HeliusClient = void 0;
|
|
13
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
14
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const helius_sdk_v1_4_0_1 = require("./helius_sdk_v1.4.0");
|
|
17
|
+
class HeliusClient {
|
|
18
|
+
constructor(signers) {
|
|
19
|
+
this.cluster = 'mainnet-beta';
|
|
20
|
+
let helius_api_key = process.env.HELIUS_API_KEY;
|
|
21
|
+
let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
|
|
22
|
+
let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
|
|
23
|
+
this._context.set_read_connection(new web3_js_1.Connection(process.env.QUICKNODE_ENDPOINT, {
|
|
24
|
+
commitment: constants_1.COMMITMENT_LEVEL.CONFIRMED
|
|
25
|
+
}));
|
|
26
|
+
this.signers = signers;
|
|
27
|
+
this.sendOptions = {
|
|
28
|
+
skipPreflight: true,
|
|
29
|
+
maxRetries: 0
|
|
30
|
+
};
|
|
31
|
+
this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint, this._context);
|
|
32
|
+
this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint, this._context);
|
|
33
|
+
}
|
|
34
|
+
send_transaction(trade_runtime, instructions) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
let txid = '';
|
|
37
|
+
let trade_strategy = trade_runtime.settings.strategy;
|
|
38
|
+
let { broadcast_type, speed } = trade_strategy;
|
|
39
|
+
let gas_fee = this.get_gas_fee(trade_strategy);
|
|
40
|
+
let cu_limit = 70000;
|
|
41
|
+
this._context.set_priority_fee(gas_fee);
|
|
42
|
+
this._context.set_cu_limit(cu_limit);
|
|
43
|
+
this._context.set_cu_price(gas_fee / cu_limit);
|
|
44
|
+
if (broadcast_type === 'rpc') {
|
|
45
|
+
let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
|
|
46
|
+
txid = yield this.send_smart_transaction(instructions, use_staked_endpint);
|
|
47
|
+
}
|
|
48
|
+
else if (broadcast_type === 'jito') {
|
|
49
|
+
txid = yield this.send_transaction_by_jito(instructions);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
throw new Error(`Not support broadcast_type: ${broadcast_type}`);
|
|
53
|
+
}
|
|
54
|
+
return txid;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
send_smart_transaction(instructions, use_staked_endpint) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
(0, dist_1.log_info)(`send_smart_transaction, start`);
|
|
60
|
+
let start_time = Date.now();
|
|
61
|
+
let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
|
|
62
|
+
let txid = yield rpc.sendSmartTransaction(instructions, this.signers, [], this.sendOptions);
|
|
63
|
+
(0, dist_1.log_info)(`send_smart_transaction, end`, {
|
|
64
|
+
txid,
|
|
65
|
+
use_staked_endpint,
|
|
66
|
+
take_time: Date.now() - start_time
|
|
67
|
+
});
|
|
68
|
+
return txid;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
send_transaction_by_jito(instructions) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
(0, dist_1.log_info)(`send_transaction_by_jito, start`);
|
|
74
|
+
let start_time = Date.now();
|
|
75
|
+
let tipAmount = this._context.priority_fee;
|
|
76
|
+
let jito_region = this.get_jito_region();
|
|
77
|
+
let rpc = this.helius_mainnet.rpc;
|
|
78
|
+
let txid = yield rpc.sendSmartTransactionWithTip(instructions, this.signers, [], tipAmount, jito_region);
|
|
79
|
+
(0, dist_1.log_info)(`send_transaction_by_jito, end`, {
|
|
80
|
+
tipAmount,
|
|
81
|
+
jito_region,
|
|
82
|
+
txid,
|
|
83
|
+
take_time: Date.now() - start_time
|
|
84
|
+
});
|
|
85
|
+
return txid;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
get_jito_region() {
|
|
89
|
+
let jito_region;
|
|
90
|
+
let server_info = (0, dist_1.getServerInfo)();
|
|
91
|
+
switch (server_info.region) {
|
|
92
|
+
case 'fra':
|
|
93
|
+
jito_region = 'Frankfurt';
|
|
94
|
+
break;
|
|
95
|
+
case 'virginia':
|
|
96
|
+
jito_region = 'NY';
|
|
97
|
+
break;
|
|
98
|
+
case 'jp':
|
|
99
|
+
jito_region = 'Tokyo';
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
jito_region = 'Default';
|
|
103
|
+
}
|
|
104
|
+
(0, dist_1.log_debug)(`get_jito_region`, {
|
|
105
|
+
server_info,
|
|
106
|
+
jito_region
|
|
107
|
+
});
|
|
108
|
+
return jito_region;
|
|
109
|
+
}
|
|
110
|
+
get_gas_fee(trade_strategy) {
|
|
111
|
+
let { speed, fee_mode, fee_exact, fee_max_cap, } = trade_strategy;
|
|
112
|
+
let gas_fee = 5001;
|
|
113
|
+
switch (fee_mode) {
|
|
114
|
+
case "exact":
|
|
115
|
+
gas_fee = this.get_excat_fee_by_speed(speed, fee_exact);
|
|
116
|
+
break;
|
|
117
|
+
case "max_cap":
|
|
118
|
+
gas_fee = this.get_dynamic_fee_by_speed(speed, 50000, fee_max_cap);
|
|
119
|
+
break;
|
|
120
|
+
default:
|
|
121
|
+
throw new Error(`Not support fee_mode: ${fee_mode}`);
|
|
122
|
+
}
|
|
123
|
+
return gas_fee;
|
|
124
|
+
}
|
|
125
|
+
get_excat_fee_by_speed(speed, fee_exact) {
|
|
126
|
+
let factor = 1;
|
|
127
|
+
if (speed === 'fast') {
|
|
128
|
+
factor = 1;
|
|
129
|
+
}
|
|
130
|
+
if (speed === 'turbo') {
|
|
131
|
+
factor = 2;
|
|
132
|
+
}
|
|
133
|
+
if (speed === 'ultra') {
|
|
134
|
+
factor = 5;
|
|
135
|
+
}
|
|
136
|
+
return fee_exact * factor;
|
|
137
|
+
}
|
|
138
|
+
get_dynamic_fee_by_speed(speed, estimate_priority_fee, fee_max_cap) {
|
|
139
|
+
let factor = 1;
|
|
140
|
+
if (speed === 'fast') {
|
|
141
|
+
factor = 1.2;
|
|
142
|
+
}
|
|
143
|
+
if (speed === 'turbo') {
|
|
144
|
+
factor = 2;
|
|
145
|
+
}
|
|
146
|
+
if (speed === 'ultra') {
|
|
147
|
+
factor = 5;
|
|
148
|
+
}
|
|
149
|
+
return Math.min(estimate_priority_fee * factor, fee_max_cap);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.HeliusClient = HeliusClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clonegod/ttd-sol-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,8 +13,11 @@
|
|
|
13
13
|
"push": "npm run build && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@clonegod/ttd-common": "1.0.
|
|
17
|
-
"
|
|
16
|
+
"@clonegod/ttd-common": "1.0.133",
|
|
17
|
+
"@irys/sdk": "^0.2.10",
|
|
18
|
+
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
|
|
19
|
+
"axios": "^1.2.3",
|
|
20
|
+
"bs58": "^6.0.0"
|
|
18
21
|
},
|
|
19
22
|
"devDependencies": {
|
|
20
23
|
"@types/node": "^22.7.9",
|