@w3lib/solana-batch-call 0.5.0 → 0.6.0
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/CHANGELOG.md +14 -0
- package/README.md +113 -1
- package/dist/batchPlan.d.ts +52 -0
- package/dist/batchPlan.d.ts.map +1 -0
- package/dist/batchPlan.js +85 -0
- package/dist/batchPlan.js.map +1 -0
- package/dist/claim.d.ts +161 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/claim.js +197 -0
- package/dist/claim.js.map +1 -0
- package/dist/decode.d.ts +22 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +187 -0
- package/dist/decode.js.map +1 -0
- package/dist/describe.d.ts +26 -0
- package/dist/describe.d.ts.map +1 -0
- package/dist/describe.js +58 -0
- package/dist/describe.js.map +1 -0
- package/dist/history.d.ts +125 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +231 -0
- package/dist/history.js.map +1 -0
- package/dist/historyHelius.d.ts +52 -0
- package/dist/historyHelius.d.ts.map +1 -0
- package/dist/historyHelius.js +125 -0
- package/dist/historyHelius.js.map +1 -0
- package/dist/liquidity/orca.d.ts +6 -0
- package/dist/liquidity/orca.d.ts.map +1 -1
- package/dist/liquidity/orca.js +14 -3
- package/dist/liquidity/orca.js.map +1 -1
- package/dist/liquidity/raydiumClmm.d.ts +6 -0
- package/dist/liquidity/raydiumClmm.d.ts.map +1 -1
- package/dist/liquidity/raydiumClmm.js +12 -5
- package/dist/liquidity/raydiumClmm.js.map +1 -1
- package/dist/lp.d.ts +47 -0
- package/dist/lp.d.ts.map +1 -1
- package/dist/lp.js +91 -15
- package/dist/lp.js.map +1 -1
- package/dist/lpMath.d.ts +22 -0
- package/dist/lpMath.d.ts.map +1 -1
- package/dist/lpMath.js +21 -0
- package/dist/lpMath.js.map +1 -1
- package/dist/programs.d.ts +19 -0
- package/dist/programs.d.ts.map +1 -0
- package/dist/programs.js +175 -0
- package/dist/programs.js.map +1 -0
- package/dist/reclaim.d.ts +190 -0
- package/dist/reclaim.d.ts.map +1 -0
- package/dist/reclaim.js +399 -0
- package/dist/reclaim.js.map +1 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +4 -2
- package/dist/rpc.js.map +1 -1
- package/dist/simulate.d.ts +106 -0
- package/dist/simulate.d.ts.map +1 -0
- package/dist/simulate.js +418 -0
- package/dist/simulate.js.map +1 -0
- package/dist/subpaths/claim.d.ts +31 -0
- package/dist/subpaths/claim.d.ts.map +1 -0
- package/dist/subpaths/claim.js +31 -0
- package/dist/subpaths/claim.js.map +1 -0
- package/dist/subpaths/history.d.ts +21 -0
- package/dist/subpaths/history.d.ts.map +1 -0
- package/dist/subpaths/history.js +22 -0
- package/dist/subpaths/history.js.map +1 -0
- package/dist/subpaths/lp.d.ts +2 -2
- package/dist/subpaths/lp.d.ts.map +1 -1
- package/dist/subpaths/lp.js +2 -2
- package/dist/subpaths/lp.js.map +1 -1
- package/dist/subpaths/reclaim.d.ts +34 -0
- package/dist/subpaths/reclaim.d.ts.map +1 -0
- package/dist/subpaths/reclaim.js +34 -0
- package/dist/subpaths/reclaim.js.map +1 -0
- package/dist/subpaths/simulate.d.ts +22 -0
- package/dist/subpaths/simulate.d.ts.map +1 -0
- package/dist/subpaths/simulate.js +23 -0
- package/dist/subpaths/simulate.js.map +1 -0
- package/dist/write/instructions.d.ts +2 -0
- package/dist/write/instructions.d.ts.map +1 -1
- package/dist/write/instructions.js +16 -0
- package/dist/write/instructions.js.map +1 -1
- package/package.json +21 -1
- package/src/batchPlan.ts +137 -0
- package/src/claim.ts +323 -0
- package/src/decode.ts +202 -0
- package/src/describe.ts +77 -0
- package/src/history.ts +336 -0
- package/src/historyHelius.ts +136 -0
- package/src/liquidity/orca.ts +15 -5
- package/src/liquidity/raydiumClmm.ts +13 -5
- package/src/lp.ts +140 -15
- package/src/lpMath.ts +38 -0
- package/src/programs.ts +216 -0
- package/src/reclaim.ts +547 -0
- package/src/rpc.ts +4 -2
- package/src/simulate.ts +535 -0
- package/src/subpaths/claim.ts +53 -0
- package/src/subpaths/history.ts +38 -0
- package/src/subpaths/lp.ts +5 -1
- package/src/subpaths/reclaim.ts +57 -0
- package/src/subpaths/simulate.ts +37 -0
- package/src/write/instructions.ts +17 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 账户回收(子路径 `@w3lib/solana-batch-call/reclaim`):扫描钱包里关闭后能退回租金(SOL)的账户并批量关闭:空的代币账户、垃圾币(销毁后关闭)、
|
|
3
|
+
* Wrapped SOL(解包)、已清空的 Orca Whirlpool / Raydium CLMM 仓位。给出每项和合计能拿回多少 lamports,发送前用 /simulate 模拟。
|
|
4
|
+
* 不放在主入口,不用时打包不会带上这部分代码;发送的代码按需加载。
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { getReclaimable, reclaim } from '@w3lib/solana-batch-call/reclaim'
|
|
8
|
+
*
|
|
9
|
+
* const r = await getReclaimable(owner, { provider: 'https://my-rpc…' })
|
|
10
|
+
* r.totalLamports // 全部能拿回的 lamports
|
|
11
|
+
* const { simulation, results } = await reclaim(client, key, r.items.filter((i) => i.selected))
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { reclaimable, type Reclaimable, type ReclaimQuery } from '../reclaim.js'
|
|
15
|
+
import { resolve, type ShortcutOptions } from '../shortcuts.js'
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
buildReclaim,
|
|
19
|
+
reclaim,
|
|
20
|
+
reclaimable,
|
|
21
|
+
simulateReclaim,
|
|
22
|
+
type BuildReclaimOptions,
|
|
23
|
+
type JunkContext,
|
|
24
|
+
type ReclaimBlocker,
|
|
25
|
+
type ReclaimCall,
|
|
26
|
+
type ReclaimCallResult,
|
|
27
|
+
type ReclaimItem,
|
|
28
|
+
type ReclaimKind,
|
|
29
|
+
type ReclaimOptions,
|
|
30
|
+
type ReclaimPlan,
|
|
31
|
+
type ReclaimQuery,
|
|
32
|
+
type ReclaimResult,
|
|
33
|
+
type ReclaimSimulation,
|
|
34
|
+
type ReclaimSimulationOptions,
|
|
35
|
+
type Reclaimable,
|
|
36
|
+
} from '../reclaim.js'
|
|
37
|
+
export type { PlanSimulation } from '../batchPlan.js'
|
|
38
|
+
export { burnChecked, closeAccount, harvestWithheldTokensToMint } from '../write/instructions.js'
|
|
39
|
+
|
|
40
|
+
export interface GetReclaimableOptions extends ReclaimQuery, ShortcutOptions {}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 扫描钱包里能回收租金的账户,节点参数与 getBalances 相同。默认列出全部代币账户(需要支持 getTokenAccountsByOwner 的节点),
|
|
44
|
+
* 免费公共节点传 `mints` 只看指定代币的 ATA。
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const r = await getReclaimable(owner, { provider: 'https://my-rpc…' })
|
|
48
|
+
* // { totalLamports: '45862080', selectedLamports: '41302080',
|
|
49
|
+
* // items: [{ kind: 'empty-token', account, mint, lamports: '2039280', selected: true, reasons: ['empty'] },
|
|
50
|
+
* // { kind: 'junk-token', symbol: 'claim-rewards.xyz', lamports: '2039280', selected: true, reasons: ['no-price', 'spam-name'] }, …],
|
|
51
|
+
* // blocked: [{ kind: 'empty-token', blocker: 'frozen', … }] }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export function getReclaimable(owner: string, options: GetReclaimableOptions = {}): Promise<Reclaimable> {
|
|
55
|
+
const { client, own } = resolve(options, ['mints', 'junk', 'positions', 'prices', 'maxJunkUsd', 'risk', 'isJunk', 'signal'])
|
|
56
|
+
return reclaimable(client, owner, { ...own, ...(options.fetch ? { fetch: options.fetch } : {}) })
|
|
57
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 交易模拟(子路径 `@w3lib/solana-batch-call/simulate`):不签名、不发送,在主网模拟一笔交易,给出余额变化、授权变化(delegate / SetAuthority / 关闭账户)、
|
|
3
|
+
* 指令说明、程序错误、手续费和警告。输入可以是 base64 的交易,也可以直接是本库构建器的输出。不放在主入口,不用时打包不会带上这部分代码;价格、风险检查按需加载。
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { buildSwap } from '@w3lib/solana-batch-call/swap'
|
|
7
|
+
* import { getSimulation } from '@w3lib/solana-batch-call/simulate'
|
|
8
|
+
*
|
|
9
|
+
* const plan = await getSwapQuote(owner, { tokenIn: NATIVE_MINT, tokenOut: USDC, amountInFormatted: '0.5' })
|
|
10
|
+
* const sim = await getSimulation(plan) // 或 getSimulation(base64Tx, { owner })
|
|
11
|
+
* if (!sim.success || sim.warnings.some((w) => w.severity === 'danger')) throw new Error(sim.error ?? sim.warnings[0].message)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { resolve, type ShortcutOptions } from '../shortcuts.js'
|
|
15
|
+
import { simulate, type SimulateInput, type SimulateOptions, type SimulationResult } from '../simulate.js'
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
failureText,
|
|
19
|
+
simulate,
|
|
20
|
+
type ApprovalChange,
|
|
21
|
+
type ApprovalChangeKind,
|
|
22
|
+
type SimulateInput,
|
|
23
|
+
type SimulateOptions,
|
|
24
|
+
type SimulatedBalanceChange,
|
|
25
|
+
type SimulationResult,
|
|
26
|
+
type SimulationWarning,
|
|
27
|
+
type WarningSeverity,
|
|
28
|
+
} from '../simulate.js'
|
|
29
|
+
export { decodeInstruction, type DecodedInstruction } from '../decode.js'
|
|
30
|
+
|
|
31
|
+
export interface GetSimulationOptions extends SimulateOptions, ShortcutOptions {}
|
|
32
|
+
|
|
33
|
+
/** 模拟一笔交易,节点参数与 getBalances 相同 */
|
|
34
|
+
export function getSimulation(input: SimulateInput, options: GetSimulationOptions = {}): Promise<SimulationResult> {
|
|
35
|
+
const { client, own } = resolve(options, ['owner', 'signers', 'watch', 'step', 'prices', 'risk', 'fetch', 'signal'])
|
|
36
|
+
return simulate(client, input, own)
|
|
37
|
+
}
|
|
@@ -74,6 +74,23 @@ export function closeAccount(account: string, destination: string, owner: string
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
/** SPL Token / Token-2022 BurnChecked:销毁代币账户里的代币(校验 mint 和精度),owner 签名 */
|
|
78
|
+
export function burnChecked(account: string, mint: string, owner: string, amount: bigint, decimals: number, tokenProgram: string): Instruction {
|
|
79
|
+
return {
|
|
80
|
+
programId: tokenProgram,
|
|
81
|
+
keys: [
|
|
82
|
+
{ pubkey: account, isSigner: false, isWritable: true },
|
|
83
|
+
{ pubkey: mint, isSigner: false, isWritable: true },
|
|
84
|
+
{ pubkey: owner, isSigner: true, isWritable: false },
|
|
85
|
+
],
|
|
86
|
+
data: bytes(10, (v) => {
|
|
87
|
+
v.setUint8(0, 15)
|
|
88
|
+
v.setBigUint64(1, amount, true)
|
|
89
|
+
v.setUint8(9, decimals)
|
|
90
|
+
}),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
77
94
|
/** 撤销代币账户的授权(Approve 设置的 delegate),owner 签名 */
|
|
78
95
|
export function revoke(account: string, owner: string, tokenProgram: string): Instruction {
|
|
79
96
|
return {
|