@clonegod/ttd-sol-common 1.0.23 → 1.0.25

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.
@@ -1,7 +1,6 @@
1
- import { Webhook, CreateWebhookRequest, EditWebhookRequest, CreateCollectionWebhookRequest, MintlistRequest, MintlistResponse, MintApiAuthority, HeliusCluster, HeliusEndpoints } from './types';
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 { SolanaTradeRuntimeType } from '../context';
5
4
  export declare class Helius {
6
5
  private apiKey?;
7
6
  readonly cluster: HeliusCluster;
@@ -10,7 +9,7 @@ export declare class Helius {
10
9
  readonly connection: Connection;
11
10
  readonly rpc: RpcClient;
12
11
  readonly mintApiAuthority: MintApiAuthority;
13
- constructor(apiKey: string, cluster: HeliusCluster, id: string, url: string, solana_trade_runtime: SolanaTradeRuntimeType);
12
+ constructor(apiKey: string, cluster?: HeliusCluster, id?: string, url?: string);
14
13
  getAllWebhooks(): Promise<Webhook[]>;
15
14
  getWebhookByID(webhookID: string): Promise<Webhook>;
16
15
  createWebhook(createWebhookRequest: CreateWebhookRequest): Promise<Webhook>;
@@ -20,6 +19,13 @@ export declare class Helius {
20
19
  removeAddressesFromWebhook(webhookID: string, addressesToRemove: string[]): Promise<Webhook>;
21
20
  createCollectionWebhook(request: CreateCollectionWebhookRequest): Promise<Webhook>;
22
21
  getMintlist(request: MintlistRequest): Promise<MintlistResponse>;
22
+ mintCompressedNft(mintApiRequest: MintApiRequest): Promise<MintApiResponse>;
23
+ delegateCollectionAuthority(request: DelegateCollectionAuthorityRequest): Promise<string>;
24
+ revokeCollectionAuthority(request: RevokeCollectionAuthorityRequest): Promise<string>;
23
25
  getApiEndpoint(path: string): string;
24
26
  private _editWebhook;
27
+ private handleImageUpload;
28
+ private uploadImageToArweave;
29
+ private getCollectionAuthorityRecord;
30
+ private getCollectionMetadataAccount;
25
31
  }
@@ -1,4 +1,27 @@
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
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,11 +38,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
38
  exports.Helius = void 0;
16
39
  const axios_1 = __importDefault(require("axios"));
17
40
  const web3_js_1 = require("@solana/web3.js");
41
+ const sdk_1 = __importDefault(require("@irys/sdk"));
42
+ const fs = __importStar(require("fs"));
18
43
  const utils_1 = require("./utils");
19
44
  const RpcClient_1 = require("./RpcClient");
45
+ const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
20
46
  const mintApi_1 = require("./utils/mintApi");
21
47
  class Helius {
22
- constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '', solana_trade_runtime) {
48
+ constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '') {
23
49
  this.cluster = cluster;
24
50
  this.endpoints = (0, utils_1.getHeliusEndpoints)(cluster);
25
51
  if (apiKey !== '') {
@@ -33,7 +59,7 @@ class Helius {
33
59
  throw Error('either `apiKey` or `url` is required');
34
60
  }
35
61
  this.endpoint = this.connection.rpcEndpoint;
36
- this.rpc = new RpcClient_1.RpcClient(solana_trade_runtime, this.connection, id);
62
+ this.rpc = new RpcClient_1.RpcClient(this.connection, id);
37
63
  this.mintApiAuthority = (0, mintApi_1.mintApiAuthority)(cluster);
38
64
  }
39
65
  getAllWebhooks() {
@@ -248,6 +274,95 @@ class Helius {
248
274
  }
249
275
  });
250
276
  }
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
+ }
251
366
  getApiEndpoint(path) {
252
367
  if (!path.startsWith('/v0') && !path.startsWith('/v1')) {
253
368
  throw new Error(`Invalid API path provided: ${path}. Path must start with '/v0' or '/v1'.`);
@@ -274,5 +389,67 @@ class Helius {
274
389
  return data;
275
390
  });
276
391
  }
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
+ }
277
454
  }
278
455
  exports.Helius = Helius;
@@ -11,10 +11,9 @@ export type SendAndConfirmTransactionResponse = {
11
11
  lastValidBlockHeight: number;
12
12
  };
13
13
  export declare class RpcClient {
14
- protected readonly solana_trade_runtime: SolanaTradeRuntimeType;
15
14
  protected readonly connection: Connection;
16
15
  protected readonly id?: string;
17
- constructor(solana_trade_runtime: SolanaTradeRuntimeType, connection: Connection, id?: string);
16
+ constructor(connection: Connection, id?: string);
18
17
  airdrop(publicKey: PublicKey, lamports: number, commitment?: Commitment): Promise<SendAndConfirmTransactionResponse>;
19
18
  getLatestBlockhash(commitmentOrConfig?: Commitment | GetLatestBlockhashConfig): Promise<BlockhashWithExpiryBlockHeight>;
20
19
  getCurrentTPS(): Promise<number>;
@@ -36,16 +35,16 @@ export declare class RpcClient {
36
35
  getPriorityFeeEstimate(params: GetPriorityFeeEstimateRequest): Promise<GetPriorityFeeEstimateResponse>;
37
36
  getComputeUnits(instructions: TransactionInstruction[], payer: PublicKey, lookupTables: AddressLookupTableAccount[], signers?: Signer[]): Promise<number | null>;
38
37
  pollTransactionConfirmation(txtSig: TransactionSignature, pollOptions?: PollTransactionOptions): Promise<TransactionSignature>;
39
- createSmartTransaction(instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], feePayer?: Signer, serializeOptions?: SerializeConfig): Promise<SmartTransactionContext>;
40
- sendSmartTransaction(instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], sendOptions?: SendOptions & {
38
+ createSmartTransaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], feePayer?: Signer, serializeOptions?: SerializeConfig): Promise<SmartTransactionContext>;
39
+ sendSmartTransaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], sendOptions?: SendOptions & {
41
40
  feePayer?: Signer;
42
41
  lastValidBlockHeightOffset?: number;
43
42
  }): Promise<TransactionSignature>;
44
43
  addTipInstruction(instructions: TransactionInstruction[], feePayer: PublicKey, tipAccount: string, tipAmount: number): void;
45
- createSmartTransactionWithTip(instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, feePayer?: Signer): Promise<SmartTransactionContext>;
44
+ createSmartTransactionWithTip(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, feePayer?: Signer): Promise<SmartTransactionContext>;
46
45
  sendJitoBundle(serializedTransactions: string[], jitoApiUrl: string): Promise<string>;
47
46
  getBundleStatuses(bundleIds: string[], jitoApiUrl: string): Promise<any>;
48
- sendSmartTransactionWithTip(instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
47
+ sendSmartTransactionWithTip(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[], signers: Signer[], lookupTables?: AddressLookupTableAccount[], tipAmount?: number, region?: JitoRegion, feePayer?: Signer, lastValidBlockHeightOffset?: number): Promise<string>;
49
48
  getNftEditions(params: DAS.GetNftEditionsRequest): Promise<DAS.GetNftEditionsResponse>;
50
49
  getTokenAccounts(params: DAS.GetTokenAccountsRequest): Promise<DAS.GetTokenAccountsResponse>;
51
50
  sendTransaction(transaction: Transaction | VersionedTransaction, options?: HeliusSendOptions): Promise<TransactionSignature>;
@@ -20,8 +20,7 @@ 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(solana_trade_runtime, connection, id) {
24
- this.solana_trade_runtime = solana_trade_runtime;
23
+ constructor(connection, id) {
25
24
  this.connection = connection;
26
25
  this.id = id;
27
26
  }
@@ -352,8 +351,8 @@ class RpcClient {
352
351
  });
353
352
  });
354
353
  }
355
- createSmartTransaction(instructions_1, signers_1) {
356
- return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], feePayer, serializeOptions = {
354
+ createSmartTransaction(solana_trade_runtime_1, instructions_1, signers_1) {
355
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], feePayer, serializeOptions = {
357
356
  requireAllSignatures: true,
358
357
  verifySignatures: true,
359
358
  }) {
@@ -408,7 +407,7 @@ class RpcClient {
408
407
  throw new Error('Priority fee estimate not available');
409
408
  }
410
409
  }), 0);
411
- let priorityFeeEstimate = this.solana_trade_runtime.cu_price;
410
+ let priorityFeeEstimate = solana_trade_runtime.cu_price;
412
411
  const computeBudgetIx = web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
413
412
  microLamports: priorityFeeEstimate,
414
413
  });
@@ -421,7 +420,7 @@ class RpcClient {
421
420
  throw new Error(`Error fetching compute units for the instructions provided`);
422
421
  }
423
422
  }), 0);
424
- let units = this.solana_trade_runtime.cu_limit;
423
+ let units = solana_trade_runtime.cu_limit;
425
424
  const customersCU = units < 1000 ? 1000 : Math.ceil(units * 1.1);
426
425
  const computeUnitsIx = web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({
427
426
  units: customersCU,
@@ -458,18 +457,18 @@ class RpcClient {
458
457
  };
459
458
  });
460
459
  }
461
- sendSmartTransaction(instructions_1, signers_1) {
462
- return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], sendOptions = { skipPreflight: false, lastValidBlockHeightOffset: 150 }) {
460
+ sendSmartTransaction(solana_trade_runtime_1, instructions_1, signers_1) {
461
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], sendOptions = { skipPreflight: false, lastValidBlockHeightOffset: 150 }) {
463
462
  var _a;
464
463
  const lastValidBlockHeightOffset = (_a = sendOptions.lastValidBlockHeightOffset) !== null && _a !== void 0 ? _a : 150;
465
464
  if (lastValidBlockHeightOffset < 0)
466
465
  throw new Error('expiryBlockOffset must be a positive integer');
467
466
  try {
468
- const { transaction, blockhash, minContextSlot } = yield this.createSmartTransaction(instructions, signers, lookupTables, sendOptions.feePayer);
467
+ const { transaction, blockhash, minContextSlot } = yield this.createSmartTransaction(solana_trade_runtime, instructions, signers, lookupTables, sendOptions.feePayer);
469
468
  let txid = (0, get_signature_1.getSignature)(transaction);
470
469
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
471
470
  const commitment = (sendOptions === null || sendOptions === void 0 ? void 0 : sendOptions.preflightCommitment) || 'confirmed';
472
- const currentBlockHeight = yield this.solana_trade_runtime.connection.getBlockHeight();
471
+ const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
473
472
  const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
474
473
  let error;
475
474
  do {
@@ -508,15 +507,15 @@ class RpcClient {
508
507
  });
509
508
  instructions.push(tipInstruction);
510
509
  }
511
- createSmartTransactionWithTip(instructions_1, signers_1) {
512
- return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], tipAmount = 1000, feePayer) {
510
+ createSmartTransactionWithTip(solana_trade_runtime_1, instructions_1, signers_1) {
511
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], tipAmount = 1000, feePayer) {
513
512
  if (!signers.length) {
514
513
  throw new Error('The transaction must have at least one signer');
515
514
  }
516
515
  const randomTipAccount = types_1.JITO_TIP_ACCOUNTS[Math.floor(Math.random() * types_1.JITO_TIP_ACCOUNTS.length)];
517
516
  const payerKey = feePayer ? feePayer.publicKey : signers[0].publicKey;
518
517
  this.addTipInstruction(instructions, payerKey, randomTipAccount, tipAmount);
519
- return this.createSmartTransaction(instructions, signers, lookupTables, feePayer);
518
+ return this.createSmartTransaction(solana_trade_runtime, instructions, signers, lookupTables, feePayer);
520
519
  });
521
520
  }
522
521
  sendJitoBundle(serializedTransactions, jitoApiUrl) {
@@ -551,14 +550,14 @@ class RpcClient {
551
550
  return response.data.result;
552
551
  });
553
552
  }
554
- sendSmartTransactionWithTip(instructions_1, signers_1) {
555
- return __awaiter(this, arguments, void 0, function* (instructions, signers, lookupTables = [], tipAmount = 1000, region = 'Default', feePayer, lastValidBlockHeightOffset = 150) {
553
+ sendSmartTransactionWithTip(solana_trade_runtime_1, instructions_1, signers_1) {
554
+ return __awaiter(this, arguments, void 0, function* (solana_trade_runtime, instructions, signers, lookupTables = [], tipAmount = 1000, region = 'Default', feePayer, lastValidBlockHeightOffset = 150) {
556
555
  if (lastValidBlockHeightOffset < 0)
557
556
  throw new Error('lastValidBlockHeightOffset must be a positive integer');
558
557
  if (!signers.length) {
559
558
  throw new Error('The transaction must have at least one signer');
560
559
  }
561
- const { transaction, blockhash } = yield this.createSmartTransactionWithTip(instructions, signers, lookupTables, tipAmount, feePayer);
560
+ const { transaction, blockhash } = yield this.createSmartTransactionWithTip(solana_trade_runtime, instructions, signers, lookupTables, tipAmount, feePayer);
562
561
  let txid = (0, get_signature_1.getSignature)(transaction);
563
562
  setTimeout(() => __awaiter(this, void 0, void 0, function* () {
564
563
  const serializedTransaction = bs58_1.default.encode(transaction.serialize());
@@ -568,7 +567,7 @@ class RpcClient {
568
567
  txid,
569
568
  bundleId
570
569
  });
571
- const currentBlockHeight = yield this.solana_trade_runtime.connection.getBlockHeight();
570
+ const currentBlockHeight = yield solana_trade_runtime.connection.getBlockHeight();
572
571
  const lastValidBlockHeight = Math.min(blockhash.lastValidBlockHeight, currentBlockHeight + lastValidBlockHeightOffset);
573
572
  const timeout = 60000;
574
573
  const interval = 5000;
@@ -7,9 +7,8 @@ export declare class HeliusClient {
7
7
  cluster: string;
8
8
  helius_mainnet: Helius;
9
9
  helius_staked: Helius;
10
- trade_runtime: SolanaTradeRuntimeType;
11
- constructor(signers: Signer[], trade_runtime: SolanaTradeRuntimeType);
12
- send_transaction(instructions: TransactionInstruction[]): Promise<string>;
10
+ constructor(signers: Signer[]);
11
+ send_transaction(solana_trade_runtime: SolanaTradeRuntimeType, instructions: TransactionInstruction[]): Promise<string>;
13
12
  private send_smart_transaction;
14
13
  private send_transaction_by_jito;
15
14
  }
@@ -14,10 +14,9 @@ const dist_1 = require("@clonegod/ttd-common/dist");
14
14
  const helius_sdk_v1_4_0_1 = require("./helius_sdk_v1.4.0");
15
15
  const strategy_util_1 = require("./strategy_util");
16
16
  class HeliusClient {
17
- constructor(signers, trade_runtime) {
17
+ constructor(signers) {
18
18
  this.cluster = 'mainnet-beta';
19
19
  this.signers = signers;
20
- this.trade_runtime = trade_runtime;
21
20
  this.sendOptions = {
22
21
  skipPreflight: true,
23
22
  maxRetries: 0
@@ -25,19 +24,19 @@ class HeliusClient {
25
24
  let helius_api_key = process.env.HELIUS_API_KEY;
26
25
  let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
27
26
  let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
28
- this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint, this.trade_runtime);
29
- this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint, this.trade_runtime);
27
+ this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint);
28
+ this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint);
30
29
  }
31
- send_transaction(instructions) {
30
+ send_transaction(solana_trade_runtime, instructions) {
32
31
  return __awaiter(this, void 0, void 0, function* () {
33
32
  let txid = '';
34
- let { broadcast_type, speed } = this.trade_runtime.settings.strategy;
33
+ let { broadcast_type, speed } = solana_trade_runtime.settings.strategy;
35
34
  if (broadcast_type === 'rpc') {
36
35
  let use_staked_endpint = speed === 'turbo' || speed === 'ultra';
37
- txid = yield this.send_smart_transaction(instructions, use_staked_endpint);
36
+ txid = yield this.send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint);
38
37
  }
39
38
  else if (broadcast_type === 'jito') {
40
- txid = yield this.send_transaction_by_jito(instructions);
39
+ txid = yield this.send_transaction_by_jito(solana_trade_runtime, instructions);
41
40
  }
42
41
  else {
43
42
  throw new Error(`Not support broadcast_type: ${broadcast_type}`);
@@ -45,12 +44,12 @@ class HeliusClient {
45
44
  return txid;
46
45
  });
47
46
  }
48
- send_smart_transaction(instructions, use_staked_endpint) {
47
+ send_smart_transaction(solana_trade_runtime, instructions, use_staked_endpint) {
49
48
  return __awaiter(this, void 0, void 0, function* () {
50
49
  (0, dist_1.log_info)(`send_smart_transaction, start`);
51
50
  let start_time = Date.now();
52
51
  let rpc = use_staked_endpint ? this.helius_staked.rpc : this.helius_mainnet.rpc;
53
- let txid = yield rpc.sendSmartTransaction(instructions, this.signers, [], this.sendOptions);
52
+ let txid = yield rpc.sendSmartTransaction(solana_trade_runtime, instructions, this.signers, [], this.sendOptions);
54
53
  (0, dist_1.log_info)(`send_smart_transaction, end`, {
55
54
  txid,
56
55
  use_staked_endpint,
@@ -59,14 +58,14 @@ class HeliusClient {
59
58
  return txid;
60
59
  });
61
60
  }
62
- send_transaction_by_jito(instructions) {
61
+ send_transaction_by_jito(solana_trade_runtime, instructions) {
63
62
  return __awaiter(this, void 0, void 0, function* () {
64
63
  (0, dist_1.log_info)(`send_transaction_by_jito, start`);
65
64
  let start_time = Date.now();
66
- let tipAmount = this.trade_runtime.priority_fee;
65
+ let tipAmount = solana_trade_runtime.priority_fee;
67
66
  let jito_region = (0, strategy_util_1.get_jito_region)();
68
67
  let rpc = this.helius_mainnet.rpc;
69
- let txid = yield rpc.sendSmartTransactionWithTip(instructions, this.signers, [], tipAmount, jito_region);
68
+ let txid = yield rpc.sendSmartTransactionWithTip(solana_trade_runtime, instructions, this.signers, [], tipAmount, jito_region);
70
69
  (0, dist_1.log_info)(`send_transaction_by_jito, end`, {
71
70
  tipAmount,
72
71
  jito_region,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -13,7 +13,9 @@
13
13
  "push": "npm run build && npm publish"
14
14
  },
15
15
  "dependencies": {
16
- "@clonegod/ttd-common": "1.0.134",
16
+ "@clonegod/ttd-common": "1.0.135",
17
+ "@irys/sdk": "^0.2.10",
18
+ "@metaplex-foundation/mpl-token-metadata": "^2.5.2",
17
19
  "axios": "^1.2.3",
18
20
  "bs58": "^6.0.0"
19
21
  },
package/types/index.d.ts CHANGED
@@ -19,14 +19,5 @@ export declare class HeliusClient {
19
19
  get_dynamic_fee_by_speed(speed: string, estimate_priority_fee: number, fee_max_cap: number): number;
20
20
  }
21
21
 
22
- export declare class _Context {
23
- read_connection: Connection;
24
- set_read_connection(read_connection: Connection): void;
25
- priority_fee: number;
26
- set_priority_fee(priority_fee: any): void;
27
- cu_price: number;
28
- set_cu_price(cu_price: number): void;
29
- cu_limit: number;
30
- set_cu_limit(cu_limit: number): void;
31
- }
22
+
32
23