@pioneer-platform/solana-network 8.25.9 → 8.25.11

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,5 +1,5 @@
1
1
 
2
2
  
3
- > @pioneer-platform/solana-network@8.25.9 build /Users/highlander/WebstormProjects/keepkey-stack/projects/pioneer/modules/coins/solana/solana-network
3
+ > @pioneer-platform/solana-network@8.25.11 build /Users/highlander/WebstormProjects/keepkey-stack/projects/pioneer/modules/coins/solana/solana-network
4
4
  > tsc -p .
5
5
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @pioneer-platform/solana-network
2
2
 
3
+ ## 8.25.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [d1d2546]
8
+ - @pioneer-platform/pioneer-nodes@8.37.11
9
+
10
+ ## 8.25.10
11
+
12
+ ### Patch Changes
13
+
14
+ - chore: chore: fix: Redis gzip binary corruption in tx history + SDK transaction loading from vault cache
15
+ - Updated dependencies
16
+ - @pioneer-platform/pioneer-nodes@8.37.10
17
+
3
18
  ## 8.25.9
4
19
 
5
20
  ### Patch Changes
package/lib/index.js CHANGED
@@ -62,7 +62,7 @@ var axiosLib = require('axios');
62
62
  var Axios = axiosLib.default || axiosLib;
63
63
  var https = require('https');
64
64
  var log = require('@pioneer-platform/loggerdog')();
65
- var _a = require('@solana/web3.js'), Connection = _a.Connection, PublicKey = _a.PublicKey, Transaction = _a.Transaction, SystemProgram = _a.SystemProgram, LAMPORTS_PER_SOL = _a.LAMPORTS_PER_SOL;
65
+ var _a = require('@solana/web3.js'), Connection = _a.Connection, PublicKey = _a.PublicKey, Transaction = _a.Transaction, TransactionInstruction = _a.TransactionInstruction, SystemProgram = _a.SystemProgram, LAMPORTS_PER_SOL = _a.LAMPORTS_PER_SOL;
66
66
  // Import node configuration from pioneer-nodes (centralized architecture)
67
67
  var blockbooks = require('@pioneer-platform/pioneer-nodes').blockbooks;
68
68
  // Get Solana node from pioneer-nodes
@@ -226,6 +226,18 @@ module.exports = {
226
226
  buildTransfer: function (from, to, amount) {
227
227
  return build_transfer(from, to, amount);
228
228
  },
229
+ /**
230
+ * Build an SPL token transfer transaction
231
+ * @param from - Sender's wallet address (base58)
232
+ * @param to - Recipient's wallet address (base58) — NOT the ATA
233
+ * @param amount - Amount in base units (already scaled by decimals)
234
+ * @param token - SPL token mint address (base58)
235
+ * @param decimals - Token decimals (for TransferChecked instruction)
236
+ * @returns Unsigned transaction with dummy signature, ready for device signing
237
+ */
238
+ buildTransferToken: function (from, to, amount, token, decimals) {
239
+ return build_transfer_token(from, to, amount, token, decimals);
240
+ },
229
241
  /**
230
242
  * Estimate transfer fee
231
243
  * @returns Fee in SOL
@@ -727,9 +739,111 @@ function get_token_balances(address) {
727
739
  });
728
740
  });
729
741
  }
742
+ // ── SPL Token Constants ─────────────────────────────────────────────────
743
+ var TOKEN_PROGRAM_ID = new PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
744
+ var ASSOCIATED_TOKEN_PROGRAM_ID = new PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
745
+ /** Derive the Associated Token Account (ATA) for a wallet + mint */
746
+ function getAssociatedTokenAddress(wallet, mint) {
747
+ var ata = PublicKey.findProgramAddressSync([wallet.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
748
+ return ata;
749
+ }
750
+ function build_transfer_token(from, to, amount, token, decimals) {
751
+ return __awaiter(this, void 0, void 0, function () {
752
+ var tag, fromPubkey, toPubkey, mintPubkey, amountBigInt, senderAta, recipientAta, recipientAtaInfo, needsCreateAta, _a, blockhash, lastValidBlockHeight, transaction, createAtaIx, transferData, remaining, i, transferIx, message, signedFormat, e_11;
753
+ return __generator(this, function (_b) {
754
+ switch (_b.label) {
755
+ case 0:
756
+ tag = TAG + " | build_transfer_token | ";
757
+ _b.label = 1;
758
+ case 1:
759
+ _b.trys.push([1, 4, , 5]);
760
+ if (!connection)
761
+ throw new Error("Module not initialized. Call init() first.");
762
+ log.info(tag, "SPL transfer: ".concat(from.slice(0, 8), "\u2026 \u2192 ").concat(to.slice(0, 8), "\u2026 mint=").concat(token.slice(0, 8), "\u2026 amount=").concat(amount, " (").concat(decimals, " dec)"));
763
+ fromPubkey = new PublicKey(from);
764
+ toPubkey = new PublicKey(to);
765
+ mintPubkey = new PublicKey(token);
766
+ amountBigInt = BigInt(amount);
767
+ senderAta = getAssociatedTokenAddress(fromPubkey, mintPubkey);
768
+ recipientAta = getAssociatedTokenAddress(toPubkey, mintPubkey);
769
+ return [4 /*yield*/, connection.getAccountInfo(recipientAta)];
770
+ case 2:
771
+ recipientAtaInfo = _b.sent();
772
+ needsCreateAta = recipientAtaInfo === null;
773
+ return [4 /*yield*/, connection.getLatestBlockhash('confirmed')
774
+ // Build transaction
775
+ ];
776
+ case 3:
777
+ _a = _b.sent(), blockhash = _a.blockhash, lastValidBlockHeight = _a.lastValidBlockHeight;
778
+ transaction = new Transaction({
779
+ feePayer: fromPubkey,
780
+ blockhash: blockhash,
781
+ lastValidBlockHeight: lastValidBlockHeight
782
+ });
783
+ // 1. CreateAssociatedTokenAccountIdempotent (if recipient ATA doesn't exist)
784
+ if (needsCreateAta) {
785
+ log.info(tag, 'Recipient ATA does not exist — adding CreateAssociatedTokenAccountIdempotent instruction');
786
+ createAtaIx = new TransactionInstruction({
787
+ programId: ASSOCIATED_TOKEN_PROGRAM_ID,
788
+ keys: [
789
+ { pubkey: fromPubkey, isSigner: true, isWritable: true }, // payer
790
+ { pubkey: recipientAta, isSigner: false, isWritable: true }, // ata
791
+ { pubkey: toPubkey, isSigner: false, isWritable: false }, // wallet
792
+ { pubkey: mintPubkey, isSigner: false, isWritable: false }, // mint
793
+ { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, // system program
794
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, // token program
795
+ ],
796
+ data: Buffer.from([1]), // 1 = CreateIdempotent
797
+ });
798
+ transaction.add(createAtaIx);
799
+ }
800
+ transferData = Buffer.alloc(10);
801
+ transferData[0] = 12; // TransferChecked opcode
802
+ remaining = amountBigInt;
803
+ for (i = 0; i < 8; i++) {
804
+ transferData[1 + i] = Number(remaining & BigInt(0xFF));
805
+ remaining = remaining >> BigInt(8);
806
+ }
807
+ transferData[9] = decimals;
808
+ transferIx = new TransactionInstruction({
809
+ programId: TOKEN_PROGRAM_ID,
810
+ keys: [
811
+ { pubkey: senderAta, isSigner: false, isWritable: true }, // source
812
+ { pubkey: mintPubkey, isSigner: false, isWritable: false }, // mint
813
+ { pubkey: recipientAta, isSigner: false, isWritable: true }, // destination
814
+ { pubkey: fromPubkey, isSigner: true, isWritable: false }, // owner
815
+ ],
816
+ data: transferData,
817
+ });
818
+ transaction.add(transferIx);
819
+ message = transaction.serializeMessage();
820
+ signedFormat = Buffer.alloc(1 + 64 + message.length);
821
+ signedFormat[0] = 1;
822
+ message.copy(signedFormat, 65);
823
+ log.info(tag, "SPL token tx built: ".concat(message.length, " bytes message, createATA=").concat(needsCreateAta));
824
+ return [2 /*return*/, {
825
+ serialized: signedFormat.toString('base64'),
826
+ blockhash: blockhash,
827
+ lastValidBlockHeight: lastValidBlockHeight,
828
+ from: from,
829
+ to: to,
830
+ token: token,
831
+ amount: amount,
832
+ decimals: decimals,
833
+ needsCreateAta: needsCreateAta
834
+ }];
835
+ case 4:
836
+ e_11 = _b.sent();
837
+ log.error(tag, "Error building SPL token transfer:", e_11.message);
838
+ throw e_11;
839
+ case 5: return [2 /*return*/];
840
+ }
841
+ });
842
+ });
843
+ }
730
844
  function get_block_height() {
731
845
  return __awaiter(this, void 0, void 0, function () {
732
- var tag, response, blockHeight, e_11;
846
+ var tag, response, blockHeight, e_12;
733
847
  return __generator(this, function (_a) {
734
848
  switch (_a.label) {
735
849
  case 0:
@@ -758,9 +872,9 @@ function get_block_height() {
758
872
  }
759
873
  throw new Error("Failed to get block height");
760
874
  case 3:
761
- e_11 = _a.sent();
762
- log.error(tag, "Error getting block height:", e_11.message);
763
- throw e_11;
875
+ e_12 = _a.sent();
876
+ log.error(tag, "Error getting block height:", e_12.message);
877
+ throw e_12;
764
878
  case 4: return [2 /*return*/];
765
879
  }
766
880
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pioneer-platform/solana-network",
3
- "version": "8.25.9",
3
+ "version": "8.25.11",
4
4
  "main": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "description": "Pioneer Platform Solana Network module",
@@ -14,8 +14,8 @@
14
14
  "@solana/web3.js": "^1.95.0",
15
15
  "axios": "^1.6.0",
16
16
  "dotenv": "^16.0.0",
17
- "@pioneer-platform/loggerdog": "8.11.0",
18
- "@pioneer-platform/pioneer-nodes": "8.37.9"
17
+ "@pioneer-platform/pioneer-nodes": "8.37.11",
18
+ "@pioneer-platform/loggerdog": "8.11.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node": "^18.16.0",