pinpet-sdk 2.1.26 → 2.1.28
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 +62 -20
- package/dist/pinpet-sdk.esm.js +62 -20
- package/dist/pinpet-sdk.js +62 -20
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/modules/token.js +62 -20
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,42 +16892,54 @@ 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);
|
|
16904
16920
|
|
|
16905
|
-
|
|
16906
|
-
|
|
16921
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
16922
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
16923
|
+
|
|
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
|
+
// 9. 用 mint keypair 预签名(调用方只需 payer 签名)
|
|
16933
|
+
transaction.sign([mint]);
|
|
16934
|
+
|
|
16935
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
16936
|
+
console.log(' Total instructions:', instructions.length);
|
|
16907
16937
|
console.log(' Compute units:', computeUnits);
|
|
16908
|
-
console.log('
|
|
16938
|
+
console.log(' mint keypair pre-signed, caller only needs payer signature');
|
|
16909
16939
|
|
|
16910
|
-
//
|
|
16940
|
+
// 10. 返回 VersionedTransaction(mint 已预签名)
|
|
16911
16941
|
return {
|
|
16912
|
-
transaction,
|
|
16913
|
-
signers: [mint], // mint keypair 需要签名
|
|
16942
|
+
transaction, // 已包含 mint 签名
|
|
16914
16943
|
accounts: {
|
|
16915
16944
|
// create 的账户
|
|
16916
16945
|
...createResult.accounts,
|
|
@@ -16919,10 +16948,23 @@ class TokenModule$1 {
|
|
|
16919
16948
|
cooldown: cooldownPDA,
|
|
16920
16949
|
feeRecipientAccount,
|
|
16921
16950
|
baseFeeRecipientAccount
|
|
16951
|
+
},
|
|
16952
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
16953
|
+
blockhashInfo: {
|
|
16954
|
+
blockhash: blockhashResult.blockhash,
|
|
16955
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
16922
16956
|
}
|
|
16923
16957
|
};
|
|
16924
16958
|
}
|
|
16925
16959
|
|
|
16960
|
+
/**
|
|
16961
|
+
* createAndBuy 的别名(功能完全相同)
|
|
16962
|
+
* 保留此方法以保持向后兼容
|
|
16963
|
+
*/
|
|
16964
|
+
async createAndBuySign(params, options = {}) {
|
|
16965
|
+
return this.createAndBuy(params, options);
|
|
16966
|
+
}
|
|
16967
|
+
|
|
16926
16968
|
}
|
|
16927
16969
|
|
|
16928
16970
|
var token = TokenModule$1;
|
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,42 +21563,54 @@ 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);
|
|
21575
21591
|
|
|
21576
|
-
|
|
21577
|
-
|
|
21592
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
21593
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
21594
|
+
|
|
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
|
+
// 9. 用 mint keypair 预签名(调用方只需 payer 签名)
|
|
21604
|
+
transaction.sign([mint]);
|
|
21605
|
+
|
|
21606
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
21607
|
+
console.log(' Total instructions:', instructions.length);
|
|
21578
21608
|
console.log(' Compute units:', computeUnits);
|
|
21579
|
-
console.log('
|
|
21609
|
+
console.log(' mint keypair pre-signed, caller only needs payer signature');
|
|
21580
21610
|
|
|
21581
|
-
//
|
|
21611
|
+
// 10. 返回 VersionedTransaction(mint 已预签名)
|
|
21582
21612
|
return {
|
|
21583
|
-
transaction,
|
|
21584
|
-
signers: [mint], // mint keypair 需要签名
|
|
21613
|
+
transaction, // 已包含 mint 签名
|
|
21585
21614
|
accounts: {
|
|
21586
21615
|
// create 的账户
|
|
21587
21616
|
...createResult.accounts,
|
|
@@ -21590,10 +21619,23 @@ class TokenModule$1 {
|
|
|
21590
21619
|
cooldown: cooldownPDA,
|
|
21591
21620
|
feeRecipientAccount,
|
|
21592
21621
|
baseFeeRecipientAccount
|
|
21622
|
+
},
|
|
21623
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
21624
|
+
blockhashInfo: {
|
|
21625
|
+
blockhash: blockhashResult.blockhash,
|
|
21626
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21593
21627
|
}
|
|
21594
21628
|
};
|
|
21595
21629
|
}
|
|
21596
21630
|
|
|
21631
|
+
/**
|
|
21632
|
+
* createAndBuy 的别名(功能完全相同)
|
|
21633
|
+
* 保留此方法以保持向后兼容
|
|
21634
|
+
*/
|
|
21635
|
+
async createAndBuySign(params, options = {}) {
|
|
21636
|
+
return this.createAndBuy(params, options);
|
|
21637
|
+
}
|
|
21638
|
+
|
|
21597
21639
|
}
|
|
21598
21640
|
|
|
21599
21641
|
var token = TokenModule$1;
|
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,42 +21571,54 @@
|
|
|
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);
|
|
21583
21599
|
|
|
21584
|
-
|
|
21585
|
-
|
|
21600
|
+
// 8. 获取最新 blockhash 并构建 VersionedTransaction
|
|
21601
|
+
const blockhashResult = await this.sdk.connection.getLatestBlockhash('confirmed');
|
|
21602
|
+
|
|
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
|
+
// 9. 用 mint keypair 预签名(调用方只需 payer 签名)
|
|
21612
|
+
transaction.sign([mint]);
|
|
21613
|
+
|
|
21614
|
+
console.log('CreateAndBuy VersionedTransaction built successfully:');
|
|
21615
|
+
console.log(' Total instructions:', instructions.length);
|
|
21586
21616
|
console.log(' Compute units:', computeUnits);
|
|
21587
|
-
console.log('
|
|
21617
|
+
console.log(' mint keypair pre-signed, caller only needs payer signature');
|
|
21588
21618
|
|
|
21589
|
-
//
|
|
21619
|
+
// 10. 返回 VersionedTransaction(mint 已预签名)
|
|
21590
21620
|
return {
|
|
21591
|
-
transaction,
|
|
21592
|
-
signers: [mint], // mint keypair 需要签名
|
|
21621
|
+
transaction, // 已包含 mint 签名
|
|
21593
21622
|
accounts: {
|
|
21594
21623
|
// create 的账户
|
|
21595
21624
|
...createResult.accounts,
|
|
@@ -21598,10 +21627,23 @@
|
|
|
21598
21627
|
cooldown: cooldownPDA,
|
|
21599
21628
|
feeRecipientAccount,
|
|
21600
21629
|
baseFeeRecipientAccount
|
|
21630
|
+
},
|
|
21631
|
+
// 返回 blockhash 信息供调用方确认交易使用
|
|
21632
|
+
blockhashInfo: {
|
|
21633
|
+
blockhash: blockhashResult.blockhash,
|
|
21634
|
+
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21601
21635
|
}
|
|
21602
21636
|
};
|
|
21603
21637
|
}
|
|
21604
21638
|
|
|
21639
|
+
/**
|
|
21640
|
+
* createAndBuy 的别名(功能完全相同)
|
|
21641
|
+
* 保留此方法以保持向后兼容
|
|
21642
|
+
*/
|
|
21643
|
+
async createAndBuySign(params, options = {}) {
|
|
21644
|
+
return this.createAndBuy(params, options);
|
|
21645
|
+
}
|
|
21646
|
+
|
|
21605
21647
|
}
|
|
21606
21648
|
|
|
21607
21649
|
var token = TokenModule$1;
|