@clonegod/ttd-sol-common 1.0.22 → 1.0.24

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,4 +1,4 @@
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
4
  import { SolanaTradeRuntimeType } from '../context';
@@ -20,6 +20,13 @@ 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>;
23
26
  getApiEndpoint(path: string): string;
24
27
  private _editWebhook;
28
+ private handleImageUpload;
29
+ private uploadImageToArweave;
30
+ private getCollectionAuthorityRecord;
31
+ private getCollectionMetadataAccount;
25
32
  }
@@ -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,8 +38,11 @@ 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
48
  constructor(apiKey, cluster = 'mainnet-beta', id = 'helius-sdk', url = '', solana_trade_runtime) {
@@ -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;
@@ -8,7 +8,7 @@ export declare class HeliusClient {
8
8
  helius_mainnet: Helius;
9
9
  helius_staked: Helius;
10
10
  trade_runtime: SolanaTradeRuntimeType;
11
- constructor(signers: Signer[]);
11
+ constructor(signers: Signer[], trade_runtime: SolanaTradeRuntimeType);
12
12
  send_transaction(instructions: TransactionInstruction[]): Promise<string>;
13
13
  private send_smart_transaction;
14
14
  private send_transaction_by_jito;
@@ -14,16 +14,17 @@ 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) {
17
+ constructor(signers, trade_runtime) {
18
18
  this.cluster = 'mainnet-beta';
19
- let helius_api_key = process.env.HELIUS_API_KEY;
20
- let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
21
- let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
22
19
  this.signers = signers;
20
+ this.trade_runtime = trade_runtime;
23
21
  this.sendOptions = {
24
22
  skipPreflight: true,
25
23
  maxRetries: 0
26
24
  };
25
+ let helius_api_key = process.env.HELIUS_API_KEY;
26
+ let helius_mainnet_endpoint = `https://mainnet.helius-rpc.com/?api-key=${helius_api_key}`;
27
+ let helius_staked_endpoint = `https://staked.helius-rpc.com?api-key=${helius_api_key}`;
27
28
  this.helius_mainnet = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_mainnet_endpoint, this.trade_runtime);
28
29
  this.helius_staked = new helius_sdk_v1_4_0_1.Helius('', this.cluster, 'helius-sdk', helius_staked_endpoint, this.trade_runtime);
29
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",
@@ -14,6 +14,8 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@clonegod/ttd-common": "1.0.134",
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
  },