@clonegod/ttd-sol-common 1.0.20 → 1.0.22
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 +1 -0
- package/dist/constants.js +2 -1
- package/dist/context.d.ts +3 -6
- package/dist/context.js +0 -16
- package/dist/helius_sdk_v1.4.0/Helius.d.ts +3 -10
- package/dist/helius_sdk_v1.4.0/Helius.js +2 -179
- package/dist/helius_sdk_v1.4.0/RpcClient.d.ts +3 -3
- package/dist/helius_sdk_v1.4.0/RpcClient.js +18 -7
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/send_transaction.d.ts +4 -9
- package/dist/send_transaction.js +7 -89
- package/dist/strategy_util.d.ts +7 -0
- package/dist/strategy_util.js +91 -0
- package/package.json +2 -4
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LOCAL_EVENT_NAME = exports.COMMITMENT_LEVEL = exports.MAX_GAS_FEE = void 0;
|
|
3
|
+
exports.LOCAL_EVENT_NAME = exports.COMMITMENT_LEVEL = exports.ONE_MILLION = exports.MAX_GAS_FEE = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
exports.MAX_GAS_FEE = web3_js_1.LAMPORTS_PER_SOL / 1000;
|
|
6
|
+
exports.ONE_MILLION = 1000000;
|
|
6
7
|
var COMMITMENT_LEVEL;
|
|
7
8
|
(function (COMMITMENT_LEVEL) {
|
|
8
9
|
COMMITMENT_LEVEL["PROCESSED"] = "processed";
|
package/dist/context.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Connection } from "@solana/web3.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { TradeRuntimeType } from '@clonegod/ttd-common';
|
|
3
|
+
export interface SolanaTradeRuntimeType extends TradeRuntimeType {
|
|
4
|
+
connection: Connection;
|
|
5
5
|
priority_fee: number;
|
|
6
|
-
set_priority_fee(priority_fee: any): void;
|
|
7
6
|
cu_price: number;
|
|
8
|
-
set_cu_price(cu_price: number): void;
|
|
9
7
|
cu_limit: number;
|
|
10
|
-
set_cu_limit(cu_limit: number): void;
|
|
11
8
|
}
|
package/dist/context.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Webhook, CreateWebhookRequest, EditWebhookRequest, CreateCollectionWebhookRequest, MintlistRequest, MintlistResponse,
|
|
1
|
+
import { Webhook, CreateWebhookRequest, EditWebhookRequest, CreateCollectionWebhookRequest, MintlistRequest, MintlistResponse, MintApiAuthority, HeliusCluster, HeliusEndpoints } from './types';
|
|
2
2
|
import { Connection } from '@solana/web3.js';
|
|
3
3
|
import { RpcClient } from './RpcClient';
|
|
4
|
-
import {
|
|
4
|
+
import { SolanaTradeRuntimeType } from '../context';
|
|
5
5
|
export declare class Helius {
|
|
6
6
|
private apiKey?;
|
|
7
7
|
readonly cluster: HeliusCluster;
|
|
@@ -10,7 +10,7 @@ export declare class Helius {
|
|
|
10
10
|
readonly connection: Connection;
|
|
11
11
|
readonly rpc: RpcClient;
|
|
12
12
|
readonly mintApiAuthority: MintApiAuthority;
|
|
13
|
-
constructor(apiKey: string, cluster: HeliusCluster, id: string, url: string,
|
|
13
|
+
constructor(apiKey: string, cluster: HeliusCluster, id: string, url: string, solana_trade_runtime: SolanaTradeRuntimeType);
|
|
14
14
|
getAllWebhooks(): Promise<Webhook[]>;
|
|
15
15
|
getWebhookByID(webhookID: string): Promise<Webhook>;
|
|
16
16
|
createWebhook(createWebhookRequest: CreateWebhookRequest): Promise<Webhook>;
|
|
@@ -20,13 +20,6 @@ export declare class Helius {
|
|
|
20
20
|
removeAddressesFromWebhook(webhookID: string, addressesToRemove: string[]): Promise<Webhook>;
|
|
21
21
|
createCollectionWebhook(request: CreateCollectionWebhookRequest): Promise<Webhook>;
|
|
22
22
|
getMintlist(request: MintlistRequest): Promise<MintlistResponse>;
|
|
23
|
-
mintCompressedNft(mintApiRequest: MintApiRequest): Promise<MintApiResponse>;
|
|
24
|
-
delegateCollectionAuthority(request: DelegateCollectionAuthorityRequest): Promise<string>;
|
|
25
|
-
revokeCollectionAuthority(request: RevokeCollectionAuthorityRequest): Promise<string>;
|
|
26
23
|
getApiEndpoint(path: string): string;
|
|
27
24
|
private _editWebhook;
|
|
28
|
-
private handleImageUpload;
|
|
29
|
-
private uploadImageToArweave;
|
|
30
|
-
private getCollectionAuthorityRecord;
|
|
31
|
-
private getCollectionMetadataAccount;
|
|
32
25
|
}
|
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -38,14 +15,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
15
|
exports.Helius = void 0;
|
|
39
16
|
const axios_1 = __importDefault(require("axios"));
|
|
40
17
|
const web3_js_1 = require("@solana/web3.js");
|
|
41
|
-
const sdk_1 = __importDefault(require("@irys/sdk"));
|
|
42
|
-
const fs = __importStar(require("fs"));
|
|
43
18
|
const utils_1 = require("./utils");
|
|
44
19
|
const RpcClient_1 = require("./RpcClient");
|
|
45
|
-
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
46
20
|
const mintApi_1 = require("./utils/mintApi");
|
|
47
21
|
class Helius {
|
|
48
|
-
constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '',
|
|
22
|
+
constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '', solana_trade_runtime) {
|
|
49
23
|
this.cluster = cluster;
|
|
50
24
|
this.endpoints = (0, utils_1.getHeliusEndpoints)(cluster);
|
|
51
25
|
if (apiKey !== '') {
|
|
@@ -59,7 +33,7 @@ class Helius {
|
|
|
59
33
|
throw Error('either `apiKey` or `url` is required');
|
|
60
34
|
}
|
|
61
35
|
this.endpoint = this.connection.rpcEndpoint;
|
|
62
|
-
this.rpc = new RpcClient_1.RpcClient(
|
|
36
|
+
this.rpc = new RpcClient_1.RpcClient(solana_trade_runtime, this.connection, id);
|
|
63
37
|
this.mintApiAuthority = (0, mintApi_1.mintApiAuthority)(cluster);
|
|
64
38
|
}
|
|
65
39
|
getAllWebhooks() {
|
|
@@ -274,95 +248,6 @@ class Helius {
|
|
|
274
248
|
}
|
|
275
249
|
});
|
|
276
250
|
}
|
|
277
|
-
mintCompressedNft(mintApiRequest) {
|
|
278
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
-
var _a;
|
|
280
|
-
yield this.handleImageUpload(mintApiRequest);
|
|
281
|
-
try {
|
|
282
|
-
const { data } = yield axios_1.default.post(this.endpoint, {
|
|
283
|
-
jsonrpc: '2.0',
|
|
284
|
-
id: 'helius-test',
|
|
285
|
-
method: 'mintCompressedNft',
|
|
286
|
-
params: Object.assign({}, mintApiRequest),
|
|
287
|
-
});
|
|
288
|
-
return data;
|
|
289
|
-
}
|
|
290
|
-
catch (err) {
|
|
291
|
-
if (axios_1.default.isAxiosError(err)) {
|
|
292
|
-
throw new Error(`error during mintCompressedNft: ${((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.error.message) || err}`);
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
throw new Error(`error during mintCompressedNft: ${err}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
delegateCollectionAuthority(request) {
|
|
301
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
-
try {
|
|
303
|
-
let { collectionMint, updateAuthorityKeypair, newCollectionAuthority, payerKeypair, } = request;
|
|
304
|
-
payerKeypair = payerKeypair !== null && payerKeypair !== void 0 ? payerKeypair : updateAuthorityKeypair;
|
|
305
|
-
newCollectionAuthority = newCollectionAuthority !== null && newCollectionAuthority !== void 0 ? newCollectionAuthority : this.mintApiAuthority;
|
|
306
|
-
const collectionMintPubkey = new web3_js_1.PublicKey(collectionMint);
|
|
307
|
-
const collectionMetadata = this.getCollectionMetadataAccount(collectionMintPubkey);
|
|
308
|
-
const newCollectionAuthorityPubkey = new web3_js_1.PublicKey(newCollectionAuthority);
|
|
309
|
-
const collectionAuthorityRecord = this.getCollectionAuthorityRecord(collectionMintPubkey, newCollectionAuthorityPubkey);
|
|
310
|
-
const accounts = {
|
|
311
|
-
collectionAuthorityRecord,
|
|
312
|
-
newCollectionAuthority: newCollectionAuthorityPubkey,
|
|
313
|
-
updateAuthority: updateAuthorityKeypair.publicKey,
|
|
314
|
-
payer: payerKeypair.publicKey,
|
|
315
|
-
metadata: collectionMetadata,
|
|
316
|
-
mint: collectionMintPubkey,
|
|
317
|
-
};
|
|
318
|
-
const inx = (0, mpl_token_metadata_1.createApproveCollectionAuthorityInstruction)(accounts);
|
|
319
|
-
const tx = new web3_js_1.Transaction().add(inx);
|
|
320
|
-
tx.feePayer = payerKeypair.publicKey;
|
|
321
|
-
const sig = yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [payerKeypair, updateAuthorityKeypair], {
|
|
322
|
-
commitment: 'confirmed',
|
|
323
|
-
skipPreflight: true,
|
|
324
|
-
});
|
|
325
|
-
return sig;
|
|
326
|
-
}
|
|
327
|
-
catch (e) {
|
|
328
|
-
console.error('Failed to delegate collection authority: ', e);
|
|
329
|
-
throw e;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
revokeCollectionAuthority(request) {
|
|
334
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
335
|
-
try {
|
|
336
|
-
let { collectionMint, revokeAuthorityKeypair, delegatedCollectionAuthority, payerKeypair, } = request;
|
|
337
|
-
payerKeypair = payerKeypair !== null && payerKeypair !== void 0 ? payerKeypair : revokeAuthorityKeypair;
|
|
338
|
-
delegatedCollectionAuthority =
|
|
339
|
-
delegatedCollectionAuthority !== null && delegatedCollectionAuthority !== void 0 ? delegatedCollectionAuthority : this.mintApiAuthority;
|
|
340
|
-
const collectionMintPubkey = new web3_js_1.PublicKey(collectionMint);
|
|
341
|
-
const collectionAuthority = new web3_js_1.PublicKey(delegatedCollectionAuthority);
|
|
342
|
-
const collectionMetadata = this.getCollectionMetadataAccount(collectionMintPubkey);
|
|
343
|
-
const collectionAuthorityRecord = this.getCollectionAuthorityRecord(collectionMintPubkey, collectionAuthority);
|
|
344
|
-
const accounts = {
|
|
345
|
-
collectionAuthorityRecord,
|
|
346
|
-
delegateAuthority: collectionAuthority,
|
|
347
|
-
revokeAuthority: revokeAuthorityKeypair.publicKey,
|
|
348
|
-
metadata: collectionMetadata,
|
|
349
|
-
mint: collectionMintPubkey,
|
|
350
|
-
};
|
|
351
|
-
const inx = (0, mpl_token_metadata_1.createRevokeCollectionAuthorityInstruction)(accounts);
|
|
352
|
-
const tx = new web3_js_1.Transaction().add(inx);
|
|
353
|
-
tx.feePayer = payerKeypair.publicKey;
|
|
354
|
-
const sig = yield (0, web3_js_1.sendAndConfirmTransaction)(this.connection, tx, [revokeAuthorityKeypair], {
|
|
355
|
-
commitment: 'confirmed',
|
|
356
|
-
skipPreflight: true,
|
|
357
|
-
});
|
|
358
|
-
return sig;
|
|
359
|
-
}
|
|
360
|
-
catch (e) {
|
|
361
|
-
console.error('Failed to revoke collection authority: ', e);
|
|
362
|
-
throw e;
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
251
|
getApiEndpoint(path) {
|
|
367
252
|
if (!path.startsWith('/v0') && !path.startsWith('/v1')) {
|
|
368
253
|
throw new Error(`Invalid API path provided: ${path}. Path must start with '/v0' or '/v1'.`);
|
|
@@ -389,67 +274,5 @@ class Helius {
|
|
|
389
274
|
return data;
|
|
390
275
|
});
|
|
391
276
|
}
|
|
392
|
-
handleImageUpload(mintApiRequest) {
|
|
393
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
394
|
-
if (mintApiRequest.imagePath && mintApiRequest.imageUrl) {
|
|
395
|
-
throw new Error('Cannot provide both imagePath and imageUrl. Please only provide one.');
|
|
396
|
-
}
|
|
397
|
-
if (mintApiRequest.imagePath && !mintApiRequest.walletPrivateKey) {
|
|
398
|
-
throw new Error('Must provide wallet privateKey if providing imagePath.');
|
|
399
|
-
}
|
|
400
|
-
if (mintApiRequest.imagePath && mintApiRequest.walletPrivateKey) {
|
|
401
|
-
mintApiRequest.imageUrl = yield this.uploadImageToArweave(mintApiRequest.imagePath, mintApiRequest.walletPrivateKey);
|
|
402
|
-
}
|
|
403
|
-
delete mintApiRequest.imagePath;
|
|
404
|
-
delete mintApiRequest.walletPrivateKey;
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
uploadImageToArweave(imagePath, privateKey) {
|
|
408
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
409
|
-
const irys = new sdk_1.default({
|
|
410
|
-
url: this.cluster === 'mainnet-beta'
|
|
411
|
-
? 'https://node2.irys.xyz'
|
|
412
|
-
: 'https://devnet.irys.xyz',
|
|
413
|
-
token: 'solana',
|
|
414
|
-
key: privateKey,
|
|
415
|
-
config: {
|
|
416
|
-
providerUrl: this.endpoint,
|
|
417
|
-
},
|
|
418
|
-
});
|
|
419
|
-
const stats = fs.statSync(imagePath);
|
|
420
|
-
const fileSizeInBytes = stats.size;
|
|
421
|
-
const fileSizeInKB = fileSizeInBytes / 1000;
|
|
422
|
-
if (this.cluster === 'devnet' || fileSizeInKB >= 200) {
|
|
423
|
-
const price = yield irys.getPrice(fileSizeInBytes);
|
|
424
|
-
yield irys.fund(price, 1.1);
|
|
425
|
-
}
|
|
426
|
-
try {
|
|
427
|
-
const receipt = yield irys.uploadFile(imagePath);
|
|
428
|
-
const url = `https://arweave.net/${receipt.id}`;
|
|
429
|
-
return url;
|
|
430
|
-
}
|
|
431
|
-
catch (e) {
|
|
432
|
-
throw new Error(`error uploading image to Arweave: ${e}`);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
getCollectionAuthorityRecord(collectionMint, collectionAuthority) {
|
|
437
|
-
const [collectionAuthRecordPda] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
438
|
-
Buffer.from('metadata'),
|
|
439
|
-
mpl_token_metadata_1.PROGRAM_ID.toBuffer(),
|
|
440
|
-
collectionMint.toBuffer(),
|
|
441
|
-
Buffer.from('collection_authority'),
|
|
442
|
-
collectionAuthority.toBuffer(),
|
|
443
|
-
], mpl_token_metadata_1.PROGRAM_ID);
|
|
444
|
-
return collectionAuthRecordPda;
|
|
445
|
-
}
|
|
446
|
-
getCollectionMetadataAccount(collectionMint) {
|
|
447
|
-
const [collectionMetadataAccount] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
448
|
-
Buffer.from('metadata', 'utf8'),
|
|
449
|
-
mpl_token_metadata_1.PROGRAM_ID.toBuffer(),
|
|
450
|
-
collectionMint.toBuffer(),
|
|
451
|
-
], mpl_token_metadata_1.PROGRAM_ID);
|
|
452
|
-
return collectionMetadataAccount;
|
|
453
|
-
}
|
|
454
277
|
}
|
|
455
278
|
exports.Helius = Helius;
|
|
@@ -3,7 +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 {
|
|
6
|
+
import { SolanaTradeRuntimeType } from '../context';
|
|
7
7
|
export type SendAndConfirmTransactionResponse = {
|
|
8
8
|
signature: TransactionSignature;
|
|
9
9
|
confirmResponse: RpcResponseAndContext<SignatureResult>;
|
|
@@ -11,10 +11,10 @@ export type SendAndConfirmTransactionResponse = {
|
|
|
11
11
|
lastValidBlockHeight: number;
|
|
12
12
|
};
|
|
13
13
|
export declare class RpcClient {
|
|
14
|
-
protected readonly
|
|
14
|
+
protected readonly solana_trade_runtime: SolanaTradeRuntimeType;
|
|
15
15
|
protected readonly connection: Connection;
|
|
16
16
|
protected readonly id?: string;
|
|
17
|
-
constructor(
|
|
17
|
+
constructor(solana_trade_runtime: SolanaTradeRuntimeType, connection: Connection, id?: string);
|
|
18
18
|
airdrop(publicKey: PublicKey, lamports: number, commitment?: Commitment): Promise<SendAndConfirmTransactionResponse>;
|
|
19
19
|
getLatestBlockhash(commitmentOrConfig?: Commitment | GetLatestBlockhashConfig): Promise<BlockhashWithExpiryBlockHeight>;
|
|
20
20
|
getCurrentTPS(): Promise<number>;
|
|
@@ -20,8 +20,8 @@ const types_1 = require("./types");
|
|
|
20
20
|
const get_signature_1 = require("../get_signature");
|
|
21
21
|
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
22
22
|
class RpcClient {
|
|
23
|
-
constructor(
|
|
24
|
-
this.
|
|
23
|
+
constructor(solana_trade_runtime, connection, id) {
|
|
24
|
+
this.solana_trade_runtime = solana_trade_runtime;
|
|
25
25
|
this.connection = connection;
|
|
26
26
|
this.id = id;
|
|
27
27
|
}
|
|
@@ -408,7 +408,7 @@ class RpcClient {
|
|
|
408
408
|
throw new Error('Priority fee estimate not available');
|
|
409
409
|
}
|
|
410
410
|
}), 0);
|
|
411
|
-
let priorityFeeEstimate = this.
|
|
411
|
+
let priorityFeeEstimate = this.solana_trade_runtime.cu_price;
|
|
412
412
|
const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
413
413
|
microLamports: priorityFeeEstimate,
|
|
414
414
|
});
|
|
@@ -421,7 +421,7 @@ class RpcClient {
|
|
|
421
421
|
throw new Error(`Error fetching compute units for the instructions provided`);
|
|
422
422
|
}
|
|
423
423
|
}), 0);
|
|
424
|
-
let units = this.
|
|
424
|
+
let units = this.solana_trade_runtime.cu_limit;
|
|
425
425
|
const customersCU = units < 1000 ? 1000 : Math.ceil(units * 1.1);
|
|
426
426
|
const computeUnitsIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
|
|
427
427
|
units: customersCU,
|
|
@@ -469,7 +469,7 @@ class RpcClient {
|
|
|
469
469
|
let txid = (0, get_signature_1.getSignature)(transaction);
|
|
470
470
|
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
471
471
|
const commitment = (sendOptions === null || sendOptions === void 0 ? void 0 : sendOptions.preflightCommitment) || 'confirmed';
|
|
472
|
-
const currentBlockHeight = yield this.
|
|
472
|
+
const currentBlockHeight = yield this.solana_trade_runtime.connection.getBlockHeight();
|
|
473
473
|
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
474
474
|
let error;
|
|
475
475
|
do {
|
|
@@ -564,7 +564,11 @@ class RpcClient {
|
|
|
564
564
|
const serializedTransaction = bs58_1.default.encode(transaction.serialize());
|
|
565
565
|
const jitoApiUrl = `${types_1.JITO_API_URLS[region]}/api/v1/bundles`;
|
|
566
566
|
const bundleId = yield this.sendJitoBundle([serializedTransaction], jitoApiUrl);
|
|
567
|
-
|
|
567
|
+
(0, dist_1.log_info)(`sendJitoBundle`, {
|
|
568
|
+
txid,
|
|
569
|
+
bundleId
|
|
570
|
+
});
|
|
571
|
+
const currentBlockHeight = yield this.solana_trade_runtime.connection.getBlockHeight();
|
|
568
572
|
const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
|
|
569
573
|
const timeout = 60000;
|
|
570
574
|
const interval = 5000;
|
|
@@ -572,9 +576,16 @@ class RpcClient {
|
|
|
572
576
|
while (Date.now() - startTime < timeout ||
|
|
573
577
|
(yield this.connection.getBlockHeight()) <= lastValidBlockHeight) {
|
|
574
578
|
const bundleStatuses = yield this.getBundleStatuses([bundleId], jitoApiUrl);
|
|
579
|
+
(0, dist_1.log_info)(`getBundleStatuses`, {
|
|
580
|
+
txid,
|
|
581
|
+
bundleId,
|
|
582
|
+
jitoApiUrl,
|
|
583
|
+
bundleStatuses
|
|
584
|
+
});
|
|
575
585
|
if (bundleStatuses &&
|
|
576
586
|
bundleStatuses.value &&
|
|
577
|
-
bundleStatuses.value.length > 0
|
|
587
|
+
bundleStatuses.value.length > 0 &&
|
|
588
|
+
bundleStatuses.value[0]) {
|
|
578
589
|
const status = bundleStatuses.value[0].confirmation_status;
|
|
579
590
|
if (status === 'confirmed') {
|
|
580
591
|
return bundleStatuses.value[0].transactions[0];
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./constants"), exports);
|
|
18
18
|
__exportStar(require("./context"), exports);
|
|
19
|
+
__exportStar(require("./strategy_util"), exports);
|
|
19
20
|
__exportStar(require("./helius_geyser_ws"), exports);
|
|
20
21
|
__exportStar(require("./send_transaction"), exports);
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import { TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
|
|
2
1
|
import { SendOptions, Signer, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { SolanaTradeRuntimeType } from "./context";
|
|
3
|
+
import { Helius } from "./helius_sdk_v1.4.0";
|
|
5
4
|
export declare class HeliusClient {
|
|
6
5
|
signers: Signer[];
|
|
7
6
|
sendOptions: SendOptions;
|
|
8
7
|
cluster: string;
|
|
9
8
|
helius_mainnet: Helius;
|
|
10
9
|
helius_staked: Helius;
|
|
11
|
-
|
|
10
|
+
trade_runtime: SolanaTradeRuntimeType;
|
|
12
11
|
constructor(signers: Signer[]);
|
|
13
|
-
send_transaction(
|
|
12
|
+
send_transaction(instructions: TransactionInstruction[]): Promise<string>;
|
|
14
13
|
private send_smart_transaction;
|
|
15
14
|
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
15
|
}
|
package/dist/send_transaction.js
CHANGED
|
@@ -11,45 +11,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.HeliusClient = void 0;
|
|
13
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
14
|
const helius_sdk_v1_4_0_1 = require("./helius_sdk_v1.4.0");
|
|
17
|
-
const
|
|
15
|
+
const strategy_util_1 = require("./strategy_util");
|
|
18
16
|
class HeliusClient {
|
|
19
17
|
constructor(signers) {
|
|
20
18
|
this.cluster = 'mainnet-beta';
|
|
21
19
|
let helius_api_key = process.env.HELIUS_API_KEY;
|
|
22
20
|
let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
|
|
23
21
|
let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
|
|
24
|
-
this._context = new context_1._Context();
|
|
25
|
-
this._context.set_read_connection(new web3_js_1.Connection(process.env.QUICKNODE_ENDPOINT, {
|
|
26
|
-
commitment: constants_1.COMMITMENT_LEVEL.CONFIRMED
|
|
27
|
-
}));
|
|
28
22
|
this.signers = signers;
|
|
29
23
|
this.sendOptions = {
|
|
30
24
|
skipPreflight: true,
|
|
31
25
|
maxRetries: 0
|
|
32
26
|
};
|
|
33
|
-
this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint, this.
|
|
34
|
-
this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint, this.
|
|
27
|
+
this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint, this.trade_runtime);
|
|
28
|
+
this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint, this.trade_runtime);
|
|
35
29
|
}
|
|
36
|
-
send_transaction(
|
|
30
|
+
send_transaction(instructions) {
|
|
37
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
32
|
let txid = '';
|
|
39
|
-
let
|
|
40
|
-
let { broadcast_type, speed } = trade_strategy;
|
|
41
|
-
let gas_fee = this.get_gas_fee(trade_strategy);
|
|
42
|
-
let cu_limit = 70000;
|
|
43
|
-
let cu_price = Math.floor(gas_fee / cu_limit);
|
|
44
|
-
this._context.set_priority_fee(gas_fee);
|
|
45
|
-
this._context.set_cu_limit(cu_limit);
|
|
46
|
-
this._context.set_cu_price(cu_price);
|
|
47
|
-
(0, dist_1.log_info)(`trade_strategy & gas`, {
|
|
48
|
-
trade_strategy,
|
|
49
|
-
gas_fee,
|
|
50
|
-
cu_limit,
|
|
51
|
-
cu_price
|
|
52
|
-
});
|
|
33
|
+
let { broadcast_type, speed } = this.trade_runtime.settings.strategy;
|
|
53
34
|
if (broadcast_type === 'rpc') {
|
|
54
35
|
let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
|
|
55
36
|
txid = yield this.send_smart_transaction(instructions, use_staked_endpint);
|
|
@@ -81,8 +62,8 @@ class HeliusClient {
|
|
|
81
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
63
|
(0, dist_1.log_info)(`send_transaction_by_jito, start`);
|
|
83
64
|
let start_time = Date.now();
|
|
84
|
-
let tipAmount = this.
|
|
85
|
-
let jito_region =
|
|
65
|
+
let tipAmount = this.trade_runtime.priority_fee;
|
|
66
|
+
let jito_region = (0, strategy_util_1.get_jito_region)();
|
|
86
67
|
let rpc = this.helius_mainnet.rpc;
|
|
87
68
|
let txid = yield rpc.sendSmartTransactionWithTip(instructions, this.signers, [], tipAmount, jito_region);
|
|
88
69
|
(0, dist_1.log_info)(`send_transaction_by_jito, end`, {
|
|
@@ -94,68 +75,5 @@ class HeliusClient {
|
|
|
94
75
|
return txid;
|
|
95
76
|
});
|
|
96
77
|
}
|
|
97
|
-
get_jito_region() {
|
|
98
|
-
let jito_region;
|
|
99
|
-
let server_info = (0, dist_1.getServerInfo)();
|
|
100
|
-
switch (server_info.region) {
|
|
101
|
-
case 'fra':
|
|
102
|
-
jito_region = 'Frankfurt';
|
|
103
|
-
break;
|
|
104
|
-
case 'virginia':
|
|
105
|
-
jito_region = 'NY';
|
|
106
|
-
break;
|
|
107
|
-
case 'jp':
|
|
108
|
-
jito_region = 'Tokyo';
|
|
109
|
-
break;
|
|
110
|
-
default:
|
|
111
|
-
jito_region = 'Default';
|
|
112
|
-
}
|
|
113
|
-
(0, dist_1.log_debug)(`get_jito_region`, {
|
|
114
|
-
server_info,
|
|
115
|
-
jito_region
|
|
116
|
-
});
|
|
117
|
-
return jito_region;
|
|
118
|
-
}
|
|
119
|
-
get_gas_fee(trade_strategy) {
|
|
120
|
-
let { speed, fee_mode, fee_exact, fee_max_cap, } = trade_strategy;
|
|
121
|
-
let gas_fee = 5001;
|
|
122
|
-
switch (fee_mode) {
|
|
123
|
-
case "exact":
|
|
124
|
-
gas_fee = this.get_excat_fee_by_speed(speed, fee_exact);
|
|
125
|
-
break;
|
|
126
|
-
case "max_cap":
|
|
127
|
-
gas_fee = this.get_dynamic_fee_by_speed(speed, 50000, fee_max_cap);
|
|
128
|
-
break;
|
|
129
|
-
default:
|
|
130
|
-
throw new Error(`Not support fee_mode: ${fee_mode}`);
|
|
131
|
-
}
|
|
132
|
-
return gas_fee;
|
|
133
|
-
}
|
|
134
|
-
get_excat_fee_by_speed(speed, fee_exact) {
|
|
135
|
-
let factor = 1;
|
|
136
|
-
if (speed === 'fast') {
|
|
137
|
-
factor = 1;
|
|
138
|
-
}
|
|
139
|
-
if (speed === 'turbo') {
|
|
140
|
-
factor = 2;
|
|
141
|
-
}
|
|
142
|
-
if (speed === 'ultra') {
|
|
143
|
-
factor = 5;
|
|
144
|
-
}
|
|
145
|
-
return fee_exact * factor;
|
|
146
|
-
}
|
|
147
|
-
get_dynamic_fee_by_speed(speed, estimate_priority_fee, fee_max_cap) {
|
|
148
|
-
let factor = 1;
|
|
149
|
-
if (speed === 'fast') {
|
|
150
|
-
factor = 1.2;
|
|
151
|
-
}
|
|
152
|
-
if (speed === 'turbo') {
|
|
153
|
-
factor = 2;
|
|
154
|
-
}
|
|
155
|
-
if (speed === 'ultra') {
|
|
156
|
-
factor = 5;
|
|
157
|
-
}
|
|
158
|
-
return Math.min(estimate_priority_fee * factor, fee_max_cap);
|
|
159
|
-
}
|
|
160
78
|
}
|
|
161
79
|
exports.HeliusClient = HeliusClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TradeRuntimeType, TradeStrategyType } from "@clonegod/ttd-common";
|
|
2
|
+
import { JitoRegion } from "./helius_sdk_v1.4.0";
|
|
3
|
+
import { SolanaTradeRuntimeType } from "./context";
|
|
4
|
+
import { Connection } from "@solana/web3.js";
|
|
5
|
+
export declare function create_solana_trade_runtime(trade_runtime: TradeRuntimeType, connection: Connection): SolanaTradeRuntimeType;
|
|
6
|
+
export declare function calculate_gas_fee(trade_strategy: TradeStrategyType): number;
|
|
7
|
+
export declare function get_jito_region(): JitoRegion;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.get_jito_region = exports.calculate_gas_fee = exports.create_solana_trade_runtime = void 0;
|
|
4
|
+
const dist_1 = require("@clonegod/ttd-common/dist");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
function create_solana_trade_runtime(trade_runtime, connection) {
|
|
7
|
+
let trade_strategy = trade_runtime.settings.strategy;
|
|
8
|
+
let { cu_limit } = trade_runtime.settings;
|
|
9
|
+
if (cu_limit < 50000) {
|
|
10
|
+
cu_limit = 50000;
|
|
11
|
+
}
|
|
12
|
+
let priority_fee = calculate_gas_fee(trade_strategy);
|
|
13
|
+
let cu_price = Math.ceil(priority_fee * constants_1.ONE_MILLION / cu_limit);
|
|
14
|
+
(0, dist_1.log_info)(`trade_strategy & gas`, {
|
|
15
|
+
trade_strategy,
|
|
16
|
+
priority_fee,
|
|
17
|
+
cu_limit,
|
|
18
|
+
cu_price
|
|
19
|
+
});
|
|
20
|
+
let solana_trade_runtime = Object.assign(Object.assign({}, trade_runtime), { connection,
|
|
21
|
+
priority_fee,
|
|
22
|
+
cu_limit,
|
|
23
|
+
cu_price });
|
|
24
|
+
return solana_trade_runtime;
|
|
25
|
+
}
|
|
26
|
+
exports.create_solana_trade_runtime = create_solana_trade_runtime;
|
|
27
|
+
function calculate_gas_fee(trade_strategy) {
|
|
28
|
+
let { speed, fee_mode, fee_exact, fee_max_cap, } = trade_strategy;
|
|
29
|
+
let gas_fee = 1000;
|
|
30
|
+
switch (fee_mode) {
|
|
31
|
+
case "exact":
|
|
32
|
+
gas_fee = get_excat_fee_by_speed(speed, fee_exact);
|
|
33
|
+
break;
|
|
34
|
+
case "max_cap":
|
|
35
|
+
gas_fee = get_dynamic_fee_by_speed(speed, 50000, fee_max_cap);
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
throw new Error(`Not support fee_mode: ${fee_mode}`);
|
|
39
|
+
}
|
|
40
|
+
return gas_fee;
|
|
41
|
+
}
|
|
42
|
+
exports.calculate_gas_fee = calculate_gas_fee;
|
|
43
|
+
function get_excat_fee_by_speed(speed, fee_exact) {
|
|
44
|
+
let factor = 1;
|
|
45
|
+
if (speed === 'fast') {
|
|
46
|
+
factor = 1;
|
|
47
|
+
}
|
|
48
|
+
if (speed === 'turbo') {
|
|
49
|
+
factor = 2;
|
|
50
|
+
}
|
|
51
|
+
if (speed === 'ultra') {
|
|
52
|
+
factor = 5;
|
|
53
|
+
}
|
|
54
|
+
return fee_exact * factor;
|
|
55
|
+
}
|
|
56
|
+
function get_dynamic_fee_by_speed(speed, estimate_priority_fee, fee_max_cap) {
|
|
57
|
+
let factor = 1;
|
|
58
|
+
if (speed === 'fast') {
|
|
59
|
+
factor = 1.2;
|
|
60
|
+
}
|
|
61
|
+
if (speed === 'turbo') {
|
|
62
|
+
factor = 2;
|
|
63
|
+
}
|
|
64
|
+
if (speed === 'ultra') {
|
|
65
|
+
factor = 5;
|
|
66
|
+
}
|
|
67
|
+
return Math.min(estimate_priority_fee * factor, fee_max_cap);
|
|
68
|
+
}
|
|
69
|
+
function get_jito_region() {
|
|
70
|
+
let jito_region;
|
|
71
|
+
let server_info = (0, dist_1.getServerInfo)();
|
|
72
|
+
switch (server_info.region) {
|
|
73
|
+
case 'fra':
|
|
74
|
+
jito_region = 'Frankfurt';
|
|
75
|
+
break;
|
|
76
|
+
case 'virginia':
|
|
77
|
+
jito_region = 'NY';
|
|
78
|
+
break;
|
|
79
|
+
case 'jp':
|
|
80
|
+
jito_region = 'Tokyo';
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
jito_region = 'Default';
|
|
84
|
+
}
|
|
85
|
+
(0, dist_1.log_debug)(`get_jito_region`, {
|
|
86
|
+
server_info,
|
|
87
|
+
jito_region
|
|
88
|
+
});
|
|
89
|
+
return jito_region;
|
|
90
|
+
}
|
|
91
|
+
exports.get_jito_region = get_jito_region;
|
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.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -13,9 +13,7 @@
|
|
|
13
13
|
"push": "npm run build && npm publish"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@clonegod/ttd-common": "1.0.
|
|
17
|
-
"@irys/sdk": "^0.2.10",
|
|
18
|
-
"@metaplex-foundation/mpl-token-metadata": "^2.5.2",
|
|
16
|
+
"@clonegod/ttd-common": "1.0.134",
|
|
19
17
|
"axios": "^1.2.3",
|
|
20
18
|
"bs58": "^6.0.0"
|
|
21
19
|
},
|