pinpet-sdk 2.1.28 → 2.1.29
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 +24 -66
- package/dist/pinpet-sdk.esm.js +24 -66
- package/dist/pinpet-sdk.js +24 -66
- package/dist/pinpet-sdk.js.map +1 -1
- package/package.json +1 -1
- package/src/idl/pinpet_del.json +3730 -0
- package/src/modules/simulator/utils.js +3 -3
- package/src/modules/token.js +21 -63
package/dist/pinpet-sdk.cjs.js
CHANGED
|
@@ -15579,9 +15579,9 @@ const MIN_STOP_LOSS_PERCENT$1 = 40; // 4.0%
|
|
|
15579
15579
|
|
|
15580
15580
|
// Maximum number of candidate indices to include in close_insert_indices
|
|
15581
15581
|
// This represents: 1 main position + N nodes before + N nodes after
|
|
15582
|
-
// Must be an odd number >= 1 (e.g.,
|
|
15583
|
-
// The contract accepts up to
|
|
15584
|
-
const MAX_CANDIDATE_INDICES$3 =
|
|
15582
|
+
// Must be an odd number >= 1 (e.g., 41 = 1 main + 20 before + 20 after)
|
|
15583
|
+
// The contract accepts up to 41
|
|
15584
|
+
const MAX_CANDIDATE_INDICES$3 = 19;
|
|
15585
15585
|
|
|
15586
15586
|
|
|
15587
15587
|
/**
|
|
@@ -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
|
|
16474
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = 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,13 +16708,8 @@ class TokenModule$1 {
|
|
|
16708
16708
|
}
|
|
16709
16709
|
|
|
16710
16710
|
/**
|
|
16711
|
-
* Create token and buy in one transaction
|
|
16712
|
-
* 将 create 和 buy
|
|
16713
|
-
*
|
|
16714
|
-
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
16715
|
-
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
16716
|
-
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
16717
|
-
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
16711
|
+
* Create token and buy in one transaction
|
|
16712
|
+
* 将 create 和 buy 两个指令合并到一个交易中,一次签名提交
|
|
16718
16713
|
*
|
|
16719
16714
|
* @param {Object} params - Creation and buy parameters
|
|
16720
16715
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -16734,20 +16729,7 @@ class TokenModule$1 {
|
|
|
16734
16729
|
*
|
|
16735
16730
|
* @param {Object} options - Optional parameters
|
|
16736
16731
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
16737
|
-
* @returns {Promise<Object>} Object containing
|
|
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());
|
|
16732
|
+
* @returns {Promise<Object>} Object containing transaction, signers and account info
|
|
16751
16733
|
*/
|
|
16752
16734
|
async createAndBuy({
|
|
16753
16735
|
mint,
|
|
@@ -16766,7 +16748,7 @@ class TokenModule$1 {
|
|
|
16766
16748
|
}, options = {}) {
|
|
16767
16749
|
const { computeUnits = 1800000 } = options;
|
|
16768
16750
|
|
|
16769
|
-
console.log('Token Module - CreateAndBuy
|
|
16751
|
+
console.log('Token Module - CreateAndBuy:', {
|
|
16770
16752
|
mint: mint.publicKey.toString(),
|
|
16771
16753
|
name,
|
|
16772
16754
|
symbol,
|
|
@@ -16802,6 +16784,7 @@ class TokenModule$1 {
|
|
|
16802
16784
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
16803
16785
|
|
|
16804
16786
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
16787
|
+
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
16805
16788
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
16806
16789
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
16807
16790
|
|
|
@@ -16892,54 +16875,42 @@ class TokenModule$1 {
|
|
|
16892
16875
|
})
|
|
16893
16876
|
.instruction();
|
|
16894
16877
|
|
|
16895
|
-
// 7.
|
|
16896
|
-
console.log('Step 6:
|
|
16897
|
-
const
|
|
16878
|
+
// 7. 合并交易:create + buy
|
|
16879
|
+
console.log('Step 6: Merging create and buy transactions...');
|
|
16880
|
+
const transaction = new Transaction$2();
|
|
16898
16881
|
|
|
16899
16882
|
// 设置计算单元限制
|
|
16900
16883
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
16901
16884
|
units: computeUnits
|
|
16902
16885
|
});
|
|
16903
|
-
|
|
16886
|
+
transaction.add(modifyComputeUnits);
|
|
16904
16887
|
|
|
16905
16888
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
16906
16889
|
createResult.transaction.instructions.forEach(ix => {
|
|
16890
|
+
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
16907
16891
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
16908
16892
|
return;
|
|
16909
16893
|
}
|
|
16910
|
-
|
|
16894
|
+
transaction.add(ix);
|
|
16911
16895
|
});
|
|
16912
16896
|
|
|
16913
16897
|
// 添加 ATA 创建指令(如果需要)
|
|
16914
16898
|
if (createAtaIx) {
|
|
16915
|
-
|
|
16899
|
+
transaction.add(createAtaIx);
|
|
16916
16900
|
}
|
|
16917
16901
|
|
|
16918
|
-
// 添加 buy 指令
|
|
16919
|
-
|
|
16920
|
-
|
|
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]);
|
|
16902
|
+
// 添加 buy 指令
|
|
16903
|
+
transaction.add(buyIx);
|
|
16934
16904
|
|
|
16935
|
-
console.log('CreateAndBuy
|
|
16936
|
-
console.log(' Total instructions:', instructions.length);
|
|
16905
|
+
console.log('CreateAndBuy transaction built successfully:');
|
|
16906
|
+
console.log(' Total instructions:', transaction.instructions.length);
|
|
16937
16907
|
console.log(' Compute units:', computeUnits);
|
|
16938
|
-
console.log('
|
|
16908
|
+
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
16939
16909
|
|
|
16940
|
-
//
|
|
16910
|
+
// 8. 返回合并后的交易
|
|
16941
16911
|
return {
|
|
16942
|
-
transaction,
|
|
16912
|
+
transaction,
|
|
16913
|
+
signers: [mint], // mint keypair 需要签名
|
|
16943
16914
|
accounts: {
|
|
16944
16915
|
// create 的账户
|
|
16945
16916
|
...createResult.accounts,
|
|
@@ -16948,23 +16919,10 @@ class TokenModule$1 {
|
|
|
16948
16919
|
cooldown: cooldownPDA,
|
|
16949
16920
|
feeRecipientAccount,
|
|
16950
16921
|
baseFeeRecipientAccount
|
|
16951
|
-
},
|
|
16952
|
-
// 返回 blockhash 信息供调用方确认交易使用
|
|
16953
|
-
blockhashInfo: {
|
|
16954
|
-
blockhash: blockhashResult.blockhash,
|
|
16955
|
-
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
16956
16922
|
}
|
|
16957
16923
|
};
|
|
16958
16924
|
}
|
|
16959
16925
|
|
|
16960
|
-
/**
|
|
16961
|
-
* createAndBuy 的别名(功能完全相同)
|
|
16962
|
-
* 保留此方法以保持向后兼容
|
|
16963
|
-
*/
|
|
16964
|
-
async createAndBuySign(params, options = {}) {
|
|
16965
|
-
return this.createAndBuy(params, options);
|
|
16966
|
-
}
|
|
16967
|
-
|
|
16968
16926
|
}
|
|
16969
16927
|
|
|
16970
16928
|
var token = TokenModule$1;
|
package/dist/pinpet-sdk.esm.js
CHANGED
|
@@ -20253,9 +20253,9 @@ const MIN_STOP_LOSS_PERCENT$1 = 40; // 4.0%
|
|
|
20253
20253
|
|
|
20254
20254
|
// Maximum number of candidate indices to include in close_insert_indices
|
|
20255
20255
|
// This represents: 1 main position + N nodes before + N nodes after
|
|
20256
|
-
// Must be an odd number >= 1 (e.g.,
|
|
20257
|
-
// The contract accepts up to
|
|
20258
|
-
const MAX_CANDIDATE_INDICES$3 =
|
|
20256
|
+
// Must be an odd number >= 1 (e.g., 41 = 1 main + 20 before + 20 after)
|
|
20257
|
+
// The contract accepts up to 41
|
|
20258
|
+
const MAX_CANDIDATE_INDICES$3 = 19;
|
|
20259
20259
|
|
|
20260
20260
|
|
|
20261
20261
|
/**
|
|
@@ -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
|
|
21145
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = 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,13 +21379,8 @@ class TokenModule$1 {
|
|
|
21379
21379
|
}
|
|
21380
21380
|
|
|
21381
21381
|
/**
|
|
21382
|
-
* Create token and buy in one transaction
|
|
21383
|
-
* 将 create 和 buy
|
|
21384
|
-
*
|
|
21385
|
-
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
21386
|
-
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
21387
|
-
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
21388
|
-
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
21382
|
+
* Create token and buy in one transaction
|
|
21383
|
+
* 将 create 和 buy 两个指令合并到一个交易中,一次签名提交
|
|
21389
21384
|
*
|
|
21390
21385
|
* @param {Object} params - Creation and buy parameters
|
|
21391
21386
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -21405,20 +21400,7 @@ class TokenModule$1 {
|
|
|
21405
21400
|
*
|
|
21406
21401
|
* @param {Object} options - Optional parameters
|
|
21407
21402
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
21408
|
-
* @returns {Promise<Object>} Object containing
|
|
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());
|
|
21403
|
+
* @returns {Promise<Object>} Object containing transaction, signers and account info
|
|
21422
21404
|
*/
|
|
21423
21405
|
async createAndBuy({
|
|
21424
21406
|
mint,
|
|
@@ -21437,7 +21419,7 @@ class TokenModule$1 {
|
|
|
21437
21419
|
}, options = {}) {
|
|
21438
21420
|
const { computeUnits = 1800000 } = options;
|
|
21439
21421
|
|
|
21440
|
-
console.log('Token Module - CreateAndBuy
|
|
21422
|
+
console.log('Token Module - CreateAndBuy:', {
|
|
21441
21423
|
mint: mint.publicKey.toString(),
|
|
21442
21424
|
name,
|
|
21443
21425
|
symbol,
|
|
@@ -21473,6 +21455,7 @@ class TokenModule$1 {
|
|
|
21473
21455
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
21474
21456
|
|
|
21475
21457
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
21458
|
+
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
21476
21459
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
21477
21460
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
21478
21461
|
|
|
@@ -21563,54 +21546,42 @@ class TokenModule$1 {
|
|
|
21563
21546
|
})
|
|
21564
21547
|
.instruction();
|
|
21565
21548
|
|
|
21566
|
-
// 7.
|
|
21567
|
-
console.log('Step 6:
|
|
21568
|
-
const
|
|
21549
|
+
// 7. 合并交易:create + buy
|
|
21550
|
+
console.log('Step 6: Merging create and buy transactions...');
|
|
21551
|
+
const transaction = new Transaction$2();
|
|
21569
21552
|
|
|
21570
21553
|
// 设置计算单元限制
|
|
21571
21554
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
21572
21555
|
units: computeUnits
|
|
21573
21556
|
});
|
|
21574
|
-
|
|
21557
|
+
transaction.add(modifyComputeUnits);
|
|
21575
21558
|
|
|
21576
21559
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
21577
21560
|
createResult.transaction.instructions.forEach(ix => {
|
|
21561
|
+
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
21578
21562
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
21579
21563
|
return;
|
|
21580
21564
|
}
|
|
21581
|
-
|
|
21565
|
+
transaction.add(ix);
|
|
21582
21566
|
});
|
|
21583
21567
|
|
|
21584
21568
|
// 添加 ATA 创建指令(如果需要)
|
|
21585
21569
|
if (createAtaIx) {
|
|
21586
|
-
|
|
21570
|
+
transaction.add(createAtaIx);
|
|
21587
21571
|
}
|
|
21588
21572
|
|
|
21589
|
-
// 添加 buy 指令
|
|
21590
|
-
|
|
21591
|
-
|
|
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]);
|
|
21573
|
+
// 添加 buy 指令
|
|
21574
|
+
transaction.add(buyIx);
|
|
21605
21575
|
|
|
21606
|
-
console.log('CreateAndBuy
|
|
21607
|
-
console.log(' Total instructions:', instructions.length);
|
|
21576
|
+
console.log('CreateAndBuy transaction built successfully:');
|
|
21577
|
+
console.log(' Total instructions:', transaction.instructions.length);
|
|
21608
21578
|
console.log(' Compute units:', computeUnits);
|
|
21609
|
-
console.log('
|
|
21579
|
+
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
21610
21580
|
|
|
21611
|
-
//
|
|
21581
|
+
// 8. 返回合并后的交易
|
|
21612
21582
|
return {
|
|
21613
|
-
transaction,
|
|
21583
|
+
transaction,
|
|
21584
|
+
signers: [mint], // mint keypair 需要签名
|
|
21614
21585
|
accounts: {
|
|
21615
21586
|
// create 的账户
|
|
21616
21587
|
...createResult.accounts,
|
|
@@ -21619,23 +21590,10 @@ class TokenModule$1 {
|
|
|
21619
21590
|
cooldown: cooldownPDA,
|
|
21620
21591
|
feeRecipientAccount,
|
|
21621
21592
|
baseFeeRecipientAccount
|
|
21622
|
-
},
|
|
21623
|
-
// 返回 blockhash 信息供调用方确认交易使用
|
|
21624
|
-
blockhashInfo: {
|
|
21625
|
-
blockhash: blockhashResult.blockhash,
|
|
21626
|
-
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21627
21593
|
}
|
|
21628
21594
|
};
|
|
21629
21595
|
}
|
|
21630
21596
|
|
|
21631
|
-
/**
|
|
21632
|
-
* createAndBuy 的别名(功能完全相同)
|
|
21633
|
-
* 保留此方法以保持向后兼容
|
|
21634
|
-
*/
|
|
21635
|
-
async createAndBuySign(params, options = {}) {
|
|
21636
|
-
return this.createAndBuy(params, options);
|
|
21637
|
-
}
|
|
21638
|
-
|
|
21639
21597
|
}
|
|
21640
21598
|
|
|
21641
21599
|
var token = TokenModule$1;
|
package/dist/pinpet-sdk.js
CHANGED
|
@@ -20261,9 +20261,9 @@
|
|
|
20261
20261
|
|
|
20262
20262
|
// Maximum number of candidate indices to include in close_insert_indices
|
|
20263
20263
|
// This represents: 1 main position + N nodes before + N nodes after
|
|
20264
|
-
// Must be an odd number >= 1 (e.g.,
|
|
20265
|
-
// The contract accepts up to
|
|
20266
|
-
const MAX_CANDIDATE_INDICES$3 =
|
|
20264
|
+
// Must be an odd number >= 1 (e.g., 41 = 1 main + 20 before + 20 after)
|
|
20265
|
+
// The contract accepts up to 41
|
|
20266
|
+
const MAX_CANDIDATE_INDICES$3 = 19;
|
|
20267
20267
|
|
|
20268
20268
|
|
|
20269
20269
|
/**
|
|
@@ -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
|
|
21153
|
+
const { ComputeBudgetProgram, PublicKey: PublicKey$5, Transaction: Transaction$2, Keypair, SystemProgram: SystemProgram$2, SYSVAR_RENT_PUBKEY: SYSVAR_RENT_PUBKEY$1 } = 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,13 +21387,8 @@
|
|
|
21387
21387
|
}
|
|
21388
21388
|
|
|
21389
21389
|
/**
|
|
21390
|
-
* Create token and buy in one transaction
|
|
21391
|
-
* 将 create 和 buy
|
|
21392
|
-
*
|
|
21393
|
-
* 注意:返回的 transaction 是 VersionedTransaction 类型(非 Legacy Transaction)
|
|
21394
|
-
* - feePayer 和 recentBlockhash 已在 SDK 端设置,网站端不需要再设置
|
|
21395
|
-
* - 签名方式:先 transaction.sign([mintKeypair]),再 phantom.signTransaction(tx)
|
|
21396
|
-
* - 发送方式:connection.sendRawTransaction(signedTx.serialize())
|
|
21390
|
+
* Create token and buy in one transaction
|
|
21391
|
+
* 将 create 和 buy 两个指令合并到一个交易中,一次签名提交
|
|
21397
21392
|
*
|
|
21398
21393
|
* @param {Object} params - Creation and buy parameters
|
|
21399
21394
|
* @param {Keypair} params.mint - Token mint keypair
|
|
@@ -21413,20 +21408,7 @@
|
|
|
21413
21408
|
*
|
|
21414
21409
|
* @param {Object} options - Optional parameters
|
|
21415
21410
|
* @param {number} options.computeUnits - Compute units limit, default 1800000
|
|
21416
|
-
* @returns {Promise<Object>} Object containing
|
|
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());
|
|
21411
|
+
* @returns {Promise<Object>} Object containing transaction, signers and account info
|
|
21430
21412
|
*/
|
|
21431
21413
|
async createAndBuy({
|
|
21432
21414
|
mint,
|
|
@@ -21445,7 +21427,7 @@
|
|
|
21445
21427
|
}, options = {}) {
|
|
21446
21428
|
const { computeUnits = 1800000 } = options;
|
|
21447
21429
|
|
|
21448
|
-
console.log('Token Module - CreateAndBuy
|
|
21430
|
+
console.log('Token Module - CreateAndBuy:', {
|
|
21449
21431
|
mint: mint.publicKey.toString(),
|
|
21450
21432
|
name,
|
|
21451
21433
|
symbol,
|
|
@@ -21481,6 +21463,7 @@
|
|
|
21481
21463
|
console.log('Step 2: Fetching fee recipient accounts from params...');
|
|
21482
21464
|
|
|
21483
21465
|
// 直接从 SDK 配置中获取手续费接收账户(这些在 SDK 初始化时已经设置)
|
|
21466
|
+
// 避免使用 program.account.params.fetch() 因为可能有 provider 配置问题
|
|
21484
21467
|
const feeRecipientAccount = this.sdk.feeRecipient;
|
|
21485
21468
|
const baseFeeRecipientAccount = this.sdk.baseFeeRecipient;
|
|
21486
21469
|
|
|
@@ -21571,54 +21554,42 @@
|
|
|
21571
21554
|
})
|
|
21572
21555
|
.instruction();
|
|
21573
21556
|
|
|
21574
|
-
// 7.
|
|
21575
|
-
console.log('Step 6:
|
|
21576
|
-
const
|
|
21557
|
+
// 7. 合并交易:create + buy
|
|
21558
|
+
console.log('Step 6: Merging create and buy transactions...');
|
|
21559
|
+
const transaction = new Transaction$2();
|
|
21577
21560
|
|
|
21578
21561
|
// 设置计算单元限制
|
|
21579
21562
|
const modifyComputeUnits = ComputeBudgetProgram.setComputeUnitLimit({
|
|
21580
21563
|
units: computeUnits
|
|
21581
21564
|
});
|
|
21582
|
-
|
|
21565
|
+
transaction.add(modifyComputeUnits);
|
|
21583
21566
|
|
|
21584
21567
|
// 添加 create 交易的所有指令(跳过 create 中的计算单元指令)
|
|
21585
21568
|
createResult.transaction.instructions.forEach(ix => {
|
|
21569
|
+
// 跳过 create 交易中的计算单元指令(我们已经添加了)
|
|
21586
21570
|
if (ix.programId.equals(ComputeBudgetProgram.programId)) {
|
|
21587
21571
|
return;
|
|
21588
21572
|
}
|
|
21589
|
-
|
|
21573
|
+
transaction.add(ix);
|
|
21590
21574
|
});
|
|
21591
21575
|
|
|
21592
21576
|
// 添加 ATA 创建指令(如果需要)
|
|
21593
21577
|
if (createAtaIx) {
|
|
21594
|
-
|
|
21578
|
+
transaction.add(createAtaIx);
|
|
21595
21579
|
}
|
|
21596
21580
|
|
|
21597
|
-
// 添加 buy 指令
|
|
21598
|
-
|
|
21599
|
-
|
|
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]);
|
|
21581
|
+
// 添加 buy 指令
|
|
21582
|
+
transaction.add(buyIx);
|
|
21613
21583
|
|
|
21614
|
-
console.log('CreateAndBuy
|
|
21615
|
-
console.log(' Total instructions:', instructions.length);
|
|
21584
|
+
console.log('CreateAndBuy transaction built successfully:');
|
|
21585
|
+
console.log(' Total instructions:', transaction.instructions.length);
|
|
21616
21586
|
console.log(' Compute units:', computeUnits);
|
|
21617
|
-
console.log('
|
|
21587
|
+
console.log(' Signers required:', [payer.toString(), mint.publicKey.toString()]);
|
|
21618
21588
|
|
|
21619
|
-
//
|
|
21589
|
+
// 8. 返回合并后的交易
|
|
21620
21590
|
return {
|
|
21621
|
-
transaction,
|
|
21591
|
+
transaction,
|
|
21592
|
+
signers: [mint], // mint keypair 需要签名
|
|
21622
21593
|
accounts: {
|
|
21623
21594
|
// create 的账户
|
|
21624
21595
|
...createResult.accounts,
|
|
@@ -21627,23 +21598,10 @@
|
|
|
21627
21598
|
cooldown: cooldownPDA,
|
|
21628
21599
|
feeRecipientAccount,
|
|
21629
21600
|
baseFeeRecipientAccount
|
|
21630
|
-
},
|
|
21631
|
-
// 返回 blockhash 信息供调用方确认交易使用
|
|
21632
|
-
blockhashInfo: {
|
|
21633
|
-
blockhash: blockhashResult.blockhash,
|
|
21634
|
-
lastValidBlockHeight: blockhashResult.lastValidBlockHeight
|
|
21635
21601
|
}
|
|
21636
21602
|
};
|
|
21637
21603
|
}
|
|
21638
21604
|
|
|
21639
|
-
/**
|
|
21640
|
-
* createAndBuy 的别名(功能完全相同)
|
|
21641
|
-
* 保留此方法以保持向后兼容
|
|
21642
|
-
*/
|
|
21643
|
-
async createAndBuySign(params, options = {}) {
|
|
21644
|
-
return this.createAndBuy(params, options);
|
|
21645
|
-
}
|
|
21646
|
-
|
|
21647
21605
|
}
|
|
21648
21606
|
|
|
21649
21607
|
var token = TokenModule$1;
|