four-flap-meme-sdk 1.3.85 → 1.3.87
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.
|
@@ -5,7 +5,34 @@
|
|
|
5
5
|
import { PublicKey, Keypair, Transaction, ComputeBudgetProgram, } from '@solana/web3.js';
|
|
6
6
|
import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID, swapQuoteByInputToken, TokenExtensionUtil, } from '@orca-so/whirlpools-sdk';
|
|
7
7
|
import { Percentage } from '@orca-so/common-sdk';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* 从 Keypair 创建 Wallet 适配器(兼容浏览器环境)
|
|
10
|
+
*/
|
|
11
|
+
function createWalletFromKeypair(keypair) {
|
|
12
|
+
return {
|
|
13
|
+
publicKey: keypair.publicKey,
|
|
14
|
+
signTransaction: async (tx) => {
|
|
15
|
+
if (tx instanceof Transaction) {
|
|
16
|
+
tx.partialSign(keypair);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
tx.sign([keypair]);
|
|
20
|
+
}
|
|
21
|
+
return tx;
|
|
22
|
+
},
|
|
23
|
+
signAllTransactions: async (txs) => {
|
|
24
|
+
for (const tx of txs) {
|
|
25
|
+
if (tx instanceof Transaction) {
|
|
26
|
+
tx.partialSign(keypair);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
tx.sign([keypair]);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return txs;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
9
36
|
import { createConnection } from '../../utils/connection.js';
|
|
10
37
|
import { buildTipInstruction, getRandomTipAccount } from '../../jito/tip.js';
|
|
11
38
|
/**
|
|
@@ -37,7 +64,7 @@ export async function signOrcaBundleSwap(params, connection) {
|
|
|
37
64
|
const jitoTipLamports = params.jitoTipLamports || DEFAULT_JITO_TIP_LAMPORTS;
|
|
38
65
|
// 预加载池信息 (只加载一次)
|
|
39
66
|
const firstWallet = params.trades[0].wallet;
|
|
40
|
-
const ctx = WhirlpoolContext.from(conn,
|
|
67
|
+
const ctx = WhirlpoolContext.from(conn, createWalletFromKeypair(firstWallet));
|
|
41
68
|
const client = buildWhirlpoolClient(ctx);
|
|
42
69
|
const pool = await client.getPool(params.poolAddress);
|
|
43
70
|
const tokenInfoA = pool.getTokenAInfo();
|
|
@@ -49,7 +76,7 @@ export async function signOrcaBundleSwap(params, connection) {
|
|
|
49
76
|
const trade = params.trades[i];
|
|
50
77
|
const isLastTrade = i === params.trades.length - 1;
|
|
51
78
|
// 创建该钱包的 context
|
|
52
|
-
const walletCtx = WhirlpoolContext.from(conn,
|
|
79
|
+
const walletCtx = WhirlpoolContext.from(conn, createWalletFromKeypair(trade.wallet));
|
|
53
80
|
const walletClient = buildWhirlpoolClient(walletCtx);
|
|
54
81
|
const walletPool = await walletClient.getPool(params.poolAddress);
|
|
55
82
|
// 获取报价
|
|
@@ -121,7 +148,7 @@ export async function batchGetOrcaPoolInfo(poolAddresses, connection) {
|
|
|
121
148
|
const result = new Map();
|
|
122
149
|
// 创建一个临时钱包用于查询
|
|
123
150
|
const tempWallet = Keypair.generate();
|
|
124
|
-
const ctx = WhirlpoolContext.from(conn,
|
|
151
|
+
const ctx = WhirlpoolContext.from(conn, createWalletFromKeypair(tempWallet));
|
|
125
152
|
const client = buildWhirlpoolClient(ctx);
|
|
126
153
|
// 批量获取池信息
|
|
127
154
|
const pools = await client.getPools(poolAddresses);
|
|
@@ -5,20 +5,48 @@
|
|
|
5
5
|
* 基于 @orca-so/whirlpools-sdk (Legacy SDK)
|
|
6
6
|
* 文档: https://dev.orca.so/SDKs/Overview
|
|
7
7
|
*/
|
|
8
|
-
import { PublicKey, } from '@solana/web3.js';
|
|
9
|
-
import { Wallet as AnchorWallet } from '@coral-xyz/anchor';
|
|
8
|
+
import { PublicKey, Transaction, } from '@solana/web3.js';
|
|
10
9
|
import { WhirlpoolContext, buildWhirlpoolClient, ORCA_WHIRLPOOL_PROGRAM_ID, PDAUtil, TickUtil, PriceMath, PoolUtil, TokenExtensionUtil, } from '@orca-so/whirlpools-sdk';
|
|
11
10
|
import { Percentage, AddressUtil, DecimalUtil } from '@orca-so/common-sdk';
|
|
12
11
|
import { createConnection } from '../../utils/connection.js';
|
|
13
12
|
import { ORCA_WHIRLPOOL_CONFIG } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* 从 Keypair 创建 Wallet 适配器(兼容浏览器环境)
|
|
15
|
+
*/
|
|
16
|
+
function createWalletFromKeypair(keypair) {
|
|
17
|
+
return {
|
|
18
|
+
publicKey: keypair.publicKey,
|
|
19
|
+
signTransaction: async (tx) => {
|
|
20
|
+
if (tx instanceof Transaction) {
|
|
21
|
+
tx.partialSign(keypair);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// VersionedTransaction
|
|
25
|
+
tx.sign([keypair]);
|
|
26
|
+
}
|
|
27
|
+
return tx;
|
|
28
|
+
},
|
|
29
|
+
signAllTransactions: async (txs) => {
|
|
30
|
+
for (const tx of txs) {
|
|
31
|
+
if (tx instanceof Transaction) {
|
|
32
|
+
tx.partialSign(keypair);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
tx.sign([keypair]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return txs;
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
14
42
|
/**
|
|
15
43
|
* 创建 Orca Whirlpool Context
|
|
16
44
|
*/
|
|
17
45
|
export async function createOrcaContext(connection, wallet) {
|
|
18
46
|
const conn = connection || createConnection();
|
|
19
|
-
// 创建
|
|
47
|
+
// 创建 Wallet 适配器(不依赖 @coral-xyz/anchor 的 Wallet 类)
|
|
20
48
|
const anchorWallet = wallet
|
|
21
|
-
?
|
|
49
|
+
? createWalletFromKeypair(wallet)
|
|
22
50
|
: {
|
|
23
51
|
publicKey: PublicKey.default,
|
|
24
52
|
signTransaction: async (tx) => tx,
|