pinpet-sdk 2.1.26 → 2.1.27
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/pinpet-sdk.cjs.js +49 -17
- package/dist/pinpet-sdk.esm.js +49 -17
- package/dist/pinpet-sdk.js +49 -17
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/token.js +49 -17
package/dist/pinpet-sdk.cjs.js
CHANGED
|
@@ -16471,7 +16471,7 @@ class TradingModule$1 {
|
|
|
16471
16471
|
|
|
16472
16472
|
var trading = TradingModule$1;
|
|
16473
16473
|
|
|
16474
|
-
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = require$$0__default["default"];
|
|
16474
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1, VersionedTransaction, TransactionMessage } = require$$0__default["default"];
|
|
16475
16475
|
const { TOKEN_PROGRAM_ID: TOKEN_PROGRAM_ID$1, getAssociatedTokenAddress: getAssociatedTokenAddress$1, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID: ASSOCIATED_TOKEN_PROGRAM_ID$1 } = cjs$3;
|
|
16476
16476
|
const anchor$3 = require$$0__default$3["default"];
|
|
16477
16477
|
// 统一使用 buffer 包,所有平台一致
|
|
@@ -16708,8 +16708,13 @@ class TokenModule$1 {
|
|
|
16708
16708
|
}
|
|
16709
16709
|
|
|
16710
16710
|
/**
|
|
16711
|
-
* Create token and buy in one transaction
|
|
16712
|
-
* 将 create 和 buy
|
|
16711
|
+
* Create token and buy in one transaction (使用 VersionedTransaction v0)
|
|
16712
|
+
* 将 create 和 buy 两个指令合并到一个 v0 交易中,一次签名提交
|
|
16713
|
+
*
|
|
16714
|
+
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
16715
|
+
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
16716
|
+
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
16717
|
+
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
16713
16718
|
*
|
|
16714
16719
|
* @param {Object} params - Creation and buy parameters
|
|
16715
16720
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -16729,7 +16734,20 @@ class TokenModule$1 {
|
|
|
16729
16734
|
*
|
|
16730
16735
|
* @param {Object} options - Optional parameters
|
|
16731
16736
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
16732
|
-
* @returns {Promise<Object>} Object containing
|
|
16737
|
+
* @returns {Promise<Object>} Object containing VersionedTransaction, signers, accounts and blockhashInfo
|
|
16738
|
+
*
|
|
16739
|
+
* @example
|
|
16740
|
+
* // Node.js 环境
|
|
16741
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
16742
|
+
* result.transaction.sign([wallet, ...result.signers]);
|
|
16743
|
+
* const sig = await connection.sendRawTransaction(result.transaction.serialize());
|
|
16744
|
+
*
|
|
16745
|
+
* @example
|
|
16746
|
+
* // 浏览器 Phantom 环境
|
|
16747
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
16748
|
+
* result.transaction.sign(result.signers); // mint keypair 先签名
|
|
16749
|
+
* const signed = await phantom.signTransaction(result.transaction); // Phantom 追加 payer 签名
|
|
16750
|
+
* const sig = await connection.sendRawTransaction(signed.serialize());
|
|
16733
16751
|
*/
|
|
16734
16752
|
async createAndBuy({
|
|
16735
16753
|
mint,
|
|
@@ -16748,7 +16766,7 @@ class TokenModule$1 {
|
|
|
16748
16766
|
}, options = {}) {
|
|
16749
16767
|
const { computeUnits = 1800000 } = options;
|
|
16750
16768
|
|
|
16751
|
-
console.log('Token Module - CreateAndBuy:', {
|
|
16769
|
+
console.log('Token Module - CreateAndBuy (VersionedTransaction):', {
|
|
16752
16770
|
mint: mint.publicKey.toString(),
|
|
16753
16771
|
name,
|
|
16754
16772
|
symbol,
|
|
@@ -16784,7 +16802,6 @@ class TokenModule$1 {
|
|
|
16784
16802
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
16785
16803
|
|
|
16786
16804
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
16787
|
-
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
16788
16805
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
16789
16806
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
16790
16807
|
|
|
@@ -16875,39 +16892,49 @@ class TokenModule$1 {
|
|
|
16875
16892
|
})
|
|
16876
16893
|
.instruction();
|
|
16877
16894
|
|
|
16878
|
-
// 7.
|
|
16879
|
-
console.log('Step 6:
|
|
16880
|
-
const
|
|
16895
|
+
// 7. 收集所有指令
|
|
16896
|
+
console.log('Step 6: Building VersionedTransaction (v0)...');
|
|
16897
|
+
const instructions = [];
|
|
16881
16898
|
|
|
16882
16899
|
// 设置计算单元限制
|
|
16883
16900
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
16884
16901
|
units: computeUnits
|
|
16885
16902
|
});
|
|
16886
|
-
|
|
16903
|
+
instructions.push(modifyComputeUnits);
|
|
16887
16904
|
|
|
16888
16905
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
16889
16906
|
createResult.transaction.instructions.forEach(ix => {
|
|
16890
|
-
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
16891
16907
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
16892
16908
|
return;
|
|
16893
16909
|
}
|
|
16894
|
-
|
|
16910
|
+
instructions.push(ix);
|
|
16895
16911
|
});
|
|
16896
16912
|
|
|
16897
16913
|
// 添加 ATA 创建指令(如果需要)
|
|
16898
16914
|
if (createAtaIx) {
|
|
16899
|
-
|
|
16915
|
+
instructions.push(createAtaIx);
|
|
16900
16916
|
}
|
|
16901
16917
|
|
|
16902
16918
|
// 添加 buy 指令
|
|
16903
|
-
|
|
16919
|
+
instructions.push(buyIx);
|
|
16920
|
+
|
|
16921
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
16922
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
16904
16923
|
|
|
16905
|
-
|
|
16906
|
-
|
|
16924
|
+
const messageV0 = new TransactionMessage({
|
|
16925
|
+
payerKey: payer,
|
|
16926
|
+
recentBlockhash: blockhashResult.blockhash,
|
|
16927
|
+
instructions: instructions,
|
|
16928
|
+
}).compileToV0Message();
|
|
16929
|
+
|
|
16930
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
16931
|
+
|
|
16932
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
16933
|
+
console.log(' Total instructions:', instructions.length);
|
|
16907
16934
|
console.log(' Compute units:', computeUnits);
|
|
16908
16935
|
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
16909
16936
|
|
|
16910
|
-
//
|
|
16937
|
+
// 9. 返回 VersionedTransaction
|
|
16911
16938
|
return {
|
|
16912
16939
|
transaction,
|
|
16913
16940
|
signers: [mint], // mint keypair 需要签名
|
|
@@ -16919,6 +16946,11 @@ class TokenModule$1 {
|
|
|
16919
16946
|
cooldown: cooldownPDA,
|
|
16920
16947
|
feeRecipientAccount,
|
|
16921
16948
|
baseFeeRecipientAccount
|
|
16949
|
+
},
|
|
16950
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
16951
|
+
blockhashInfo: {
|
|
16952
|
+
blockhash: blockhashResult.blockhash,
|
|
16953
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
16922
16954
|
}
|
|
16923
16955
|
};
|
|
16924
16956
|
}
|
package/dist/pinpet-sdk.esm.js
CHANGED
|
@@ -21142,7 +21142,7 @@ class TradingModule$1 {
|
|
|
21142
21142
|
|
|
21143
21143
|
var trading = TradingModule$1;
|
|
21144
21144
|
|
|
21145
|
-
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = require$$2$1;
|
|
21145
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1, VersionedTransaction, TransactionMessage } = require$$2$1;
|
|
21146
21146
|
const { TOKEN_PROGRAM_ID: TOKEN_PROGRAM_ID$1, getAssociatedTokenAddress: getAssociatedTokenAddress$1, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID: ASSOCIATED_TOKEN_PROGRAM_ID$1 } = cjs$3;
|
|
21147
21147
|
const anchor$3 = require$$0;
|
|
21148
21148
|
// 统一使用 buffer 包,所有平台一致
|
|
@@ -21379,8 +21379,13 @@ class TokenModule$1 {
|
|
|
21379
21379
|
}
|
|
21380
21380
|
|
|
21381
21381
|
/**
|
|
21382
|
-
* Create token and buy in one transaction
|
|
21383
|
-
* 将 create 和 buy
|
|
21382
|
+
* Create token and buy in one transaction (使用 VersionedTransaction v0)
|
|
21383
|
+
* 将 create 和 buy 两个指令合并到一个 v0 交易中,一次签名提交
|
|
21384
|
+
*
|
|
21385
|
+
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
21386
|
+
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
21387
|
+
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
21388
|
+
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
21384
21389
|
*
|
|
21385
21390
|
* @param {Object} params - Creation and buy parameters
|
|
21386
21391
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -21400,7 +21405,20 @@ class TokenModule$1 {
|
|
|
21400
21405
|
*
|
|
21401
21406
|
* @param {Object} options - Optional parameters
|
|
21402
21407
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
21403
|
-
* @returns {Promise<Object>} Object containing
|
|
21408
|
+
* @returns {Promise<Object>} Object containing VersionedTransaction, signers, accounts and blockhashInfo
|
|
21409
|
+
*
|
|
21410
|
+
* @example
|
|
21411
|
+
* // Node.js 环境
|
|
21412
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
21413
|
+
* result.transaction.sign([wallet, ...result.signers]);
|
|
21414
|
+
* const sig = await connection.sendRawTransaction(result.transaction.serialize());
|
|
21415
|
+
*
|
|
21416
|
+
* @example
|
|
21417
|
+
* // 浏览器 Phantom 环境
|
|
21418
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
21419
|
+
* result.transaction.sign(result.signers); // mint keypair 先签名
|
|
21420
|
+
* const signed = await phantom.signTransaction(result.transaction); // Phantom 追加 payer 签名
|
|
21421
|
+
* const sig = await connection.sendRawTransaction(signed.serialize());
|
|
21404
21422
|
*/
|
|
21405
21423
|
async createAndBuy({
|
|
21406
21424
|
mint,
|
|
@@ -21419,7 +21437,7 @@ class TokenModule$1 {
|
|
|
21419
21437
|
}, options = {}) {
|
|
21420
21438
|
const { computeUnits = 1800000 } = options;
|
|
21421
21439
|
|
|
21422
|
-
console.log('Token Module - CreateAndBuy:', {
|
|
21440
|
+
console.log('Token Module - CreateAndBuy (VersionedTransaction):', {
|
|
21423
21441
|
mint: mint.publicKey.toString(),
|
|
21424
21442
|
name,
|
|
21425
21443
|
symbol,
|
|
@@ -21455,7 +21473,6 @@ class TokenModule$1 {
|
|
|
21455
21473
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
21456
21474
|
|
|
21457
21475
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
21458
|
-
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
21459
21476
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
21460
21477
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
21461
21478
|
|
|
@@ -21546,39 +21563,49 @@ class TokenModule$1 {
|
|
|
21546
21563
|
})
|
|
21547
21564
|
.instruction();
|
|
21548
21565
|
|
|
21549
|
-
// 7.
|
|
21550
|
-
console.log('Step 6:
|
|
21551
|
-
const
|
|
21566
|
+
// 7. 收集所有指令
|
|
21567
|
+
console.log('Step 6: Building VersionedTransaction (v0)...');
|
|
21568
|
+
const instructions = [];
|
|
21552
21569
|
|
|
21553
21570
|
// 设置计算单元限制
|
|
21554
21571
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
21555
21572
|
units: computeUnits
|
|
21556
21573
|
});
|
|
21557
|
-
|
|
21574
|
+
instructions.push(modifyComputeUnits);
|
|
21558
21575
|
|
|
21559
21576
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
21560
21577
|
createResult.transaction.instructions.forEach(ix => {
|
|
21561
|
-
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
21562
21578
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
21563
21579
|
return;
|
|
21564
21580
|
}
|
|
21565
|
-
|
|
21581
|
+
instructions.push(ix);
|
|
21566
21582
|
});
|
|
21567
21583
|
|
|
21568
21584
|
// 添加 ATA 创建指令(如果需要)
|
|
21569
21585
|
if (createAtaIx) {
|
|
21570
|
-
|
|
21586
|
+
instructions.push(createAtaIx);
|
|
21571
21587
|
}
|
|
21572
21588
|
|
|
21573
21589
|
// 添加 buy 指令
|
|
21574
|
-
|
|
21590
|
+
instructions.push(buyIx);
|
|
21591
|
+
|
|
21592
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
21593
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
21575
21594
|
|
|
21576
|
-
|
|
21577
|
-
|
|
21595
|
+
const messageV0 = new TransactionMessage({
|
|
21596
|
+
payerKey: payer,
|
|
21597
|
+
recentBlockhash: blockhashResult.blockhash,
|
|
21598
|
+
instructions: instructions,
|
|
21599
|
+
}).compileToV0Message();
|
|
21600
|
+
|
|
21601
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
21602
|
+
|
|
21603
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
21604
|
+
console.log(' Total instructions:', instructions.length);
|
|
21578
21605
|
console.log(' Compute units:', computeUnits);
|
|
21579
21606
|
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
21580
21607
|
|
|
21581
|
-
//
|
|
21608
|
+
// 9. 返回 VersionedTransaction
|
|
21582
21609
|
return {
|
|
21583
21610
|
transaction,
|
|
21584
21611
|
signers: [mint], // mint keypair 需要签名
|
|
@@ -21590,6 +21617,11 @@ class TokenModule$1 {
|
|
|
21590
21617
|
cooldown: cooldownPDA,
|
|
21591
21618
|
feeRecipientAccount,
|
|
21592
21619
|
baseFeeRecipientAccount
|
|
21620
|
+
},
|
|
21621
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
21622
|
+
blockhashInfo: {
|
|
21623
|
+
blockhash: blockhashResult.blockhash,
|
|
21624
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21593
21625
|
}
|
|
21594
21626
|
};
|
|
21595
21627
|
}
|
package/dist/pinpet-sdk.js
CHANGED
|
@@ -21150,7 +21150,7 @@
|
|
|
21150
21150
|
|
|
21151
21151
|
var trading = TradingModule$1;
|
|
21152
21152
|
|
|
21153
|
-
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = require$$0__default["default"];
|
|
21153
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1, VersionedTransaction, TransactionMessage } = require$$0__default["default"];
|
|
21154
21154
|
const { TOKEN_PROGRAM_ID: TOKEN_PROGRAM_ID$1, getAssociatedTokenAddress: getAssociatedTokenAddress$1, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID: ASSOCIATED_TOKEN_PROGRAM_ID$1 } = cjs$3;
|
|
21155
21155
|
const anchor$3 = require$$0__default$1["default"];
|
|
21156
21156
|
// 统一使用 buffer 包,所有平台一致
|
|
@@ -21387,8 +21387,13 @@
|
|
|
21387
21387
|
}
|
|
21388
21388
|
|
|
21389
21389
|
/**
|
|
21390
|
-
* Create token and buy in one transaction
|
|
21391
|
-
* 将 create 和 buy
|
|
21390
|
+
* Create token and buy in one transaction (使用 VersionedTransaction v0)
|
|
21391
|
+
* 将 create 和 buy 两个指令合并到一个 v0 交易中,一次签名提交
|
|
21392
|
+
*
|
|
21393
|
+
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
21394
|
+
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
21395
|
+
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
21396
|
+
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
21392
21397
|
*
|
|
21393
21398
|
* @param {Object} params - Creation and buy parameters
|
|
21394
21399
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -21408,7 +21413,20 @@
|
|
|
21408
21413
|
*
|
|
21409
21414
|
* @param {Object} options - Optional parameters
|
|
21410
21415
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
21411
|
-
* @returns {Promise<Object>} Object containing
|
|
21416
|
+
* @returns {Promise<Object>} Object containing VersionedTransaction, signers, accounts and blockhashInfo
|
|
21417
|
+
*
|
|
21418
|
+
* @example
|
|
21419
|
+
* // Node.js 环境
|
|
21420
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
21421
|
+
* result.transaction.sign([wallet, ...result.signers]);
|
|
21422
|
+
* const sig = await connection.sendRawTransaction(result.transaction.serialize());
|
|
21423
|
+
*
|
|
21424
|
+
* @example
|
|
21425
|
+
* // 浏览器 Phantom 环境
|
|
21426
|
+
* const result = await sdk.token.createAndBuy({...});
|
|
21427
|
+
* result.transaction.sign(result.signers); // mint keypair 先签名
|
|
21428
|
+
* const signed = await phantom.signTransaction(result.transaction); // Phantom 追加 payer 签名
|
|
21429
|
+
* const sig = await connection.sendRawTransaction(signed.serialize());
|
|
21412
21430
|
*/
|
|
21413
21431
|
async createAndBuy({
|
|
21414
21432
|
mint,
|
|
@@ -21427,7 +21445,7 @@
|
|
|
21427
21445
|
}, options = {}) {
|
|
21428
21446
|
const { computeUnits = 1800000 } = options;
|
|
21429
21447
|
|
|
21430
|
-
console.log('Token Module - CreateAndBuy:', {
|
|
21448
|
+
console.log('Token Module - CreateAndBuy (VersionedTransaction):', {
|
|
21431
21449
|
mint: mint.publicKey.toString(),
|
|
21432
21450
|
name,
|
|
21433
21451
|
symbol,
|
|
@@ -21463,7 +21481,6 @@
|
|
|
21463
21481
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
21464
21482
|
|
|
21465
21483
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
21466
|
-
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
21467
21484
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
21468
21485
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
21469
21486
|
|
|
@@ -21554,39 +21571,49 @@
|
|
|
21554
21571
|
})
|
|
21555
21572
|
.instruction();
|
|
21556
21573
|
|
|
21557
|
-
// 7.
|
|
21558
|
-
console.log('Step 6:
|
|
21559
|
-
const
|
|
21574
|
+
// 7. 收集所有指令
|
|
21575
|
+
console.log('Step 6: Building VersionedTransaction (v0)...');
|
|
21576
|
+
const instructions = [];
|
|
21560
21577
|
|
|
21561
21578
|
// 设置计算单元限制
|
|
21562
21579
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
21563
21580
|
units: computeUnits
|
|
21564
21581
|
});
|
|
21565
|
-
|
|
21582
|
+
instructions.push(modifyComputeUnits);
|
|
21566
21583
|
|
|
21567
21584
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
21568
21585
|
createResult.transaction.instructions.forEach(ix => {
|
|
21569
|
-
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
21570
21586
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
21571
21587
|
return;
|
|
21572
21588
|
}
|
|
21573
|
-
|
|
21589
|
+
instructions.push(ix);
|
|
21574
21590
|
});
|
|
21575
21591
|
|
|
21576
21592
|
// 添加 ATA 创建指令(如果需要)
|
|
21577
21593
|
if (createAtaIx) {
|
|
21578
|
-
|
|
21594
|
+
instructions.push(createAtaIx);
|
|
21579
21595
|
}
|
|
21580
21596
|
|
|
21581
21597
|
// 添加 buy 指令
|
|
21582
|
-
|
|
21598
|
+
instructions.push(buyIx);
|
|
21599
|
+
|
|
21600
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
21601
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
21583
21602
|
|
|
21584
|
-
|
|
21585
|
-
|
|
21603
|
+
const messageV0 = new TransactionMessage({
|
|
21604
|
+
payerKey: payer,
|
|
21605
|
+
recentBlockhash: blockhashResult.blockhash,
|
|
21606
|
+
instructions: instructions,
|
|
21607
|
+
}).compileToV0Message();
|
|
21608
|
+
|
|
21609
|
+
const transaction = new VersionedTransaction(messageV0);
|
|
21610
|
+
|
|
21611
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
21612
|
+
console.log(' Total instructions:', instructions.length);
|
|
21586
21613
|
console.log(' Compute units:', computeUnits);
|
|
21587
21614
|
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
21588
21615
|
|
|
21589
|
-
//
|
|
21616
|
+
// 9. 返回 VersionedTransaction
|
|
21590
21617
|
return {
|
|
21591
21618
|
transaction,
|
|
21592
21619
|
signers: [mint], // mint keypair 需要签名
|
|
@@ -21598,6 +21625,11 @@
|
|
|
21598
21625
|
cooldown: cooldownPDA,
|
|
21599
21626
|
feeRecipientAccount,
|
|
21600
21627
|
baseFeeRecipientAccount
|
|
21628
|
+
},
|
|
21629
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
21630
|
+
blockhashInfo: {
|
|
21631
|
+
blockhash: blockhashResult.blockhash,
|
|
21632
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21601
21633
|
}
|
|
21602
21634
|
};
|
|
21603
21635
|
}
|