@w3lib/solana-batch-call 0.2.2 → 0.4.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 +26 -0
- package/README.md +205 -2
- package/dist/address.d.ts +2 -0
- package/dist/address.d.ts.map +1 -1
- package/dist/address.js +8 -0
- package/dist/address.js.map +1 -1
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -0
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/layout.d.ts +5 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +16 -0
- package/dist/layout.js.map +1 -1
- package/dist/liquidity/amm.d.ts +7 -0
- package/dist/liquidity/amm.d.ts.map +1 -0
- package/dist/liquidity/amm.js +307 -0
- package/dist/liquidity/amm.js.map +1 -0
- package/dist/liquidity/clmm.d.ts +18 -0
- package/dist/liquidity/clmm.d.ts.map +1 -0
- package/dist/liquidity/clmm.js +85 -0
- package/dist/liquidity/clmm.js.map +1 -0
- package/dist/liquidity/common.d.ts +94 -0
- package/dist/liquidity/common.d.ts.map +1 -0
- package/dist/liquidity/common.js +228 -0
- package/dist/liquidity/common.js.map +1 -0
- package/dist/liquidity/index.d.ts +34 -0
- package/dist/liquidity/index.d.ts.map +1 -0
- package/dist/liquidity/index.js +157 -0
- package/dist/liquidity/index.js.map +1 -0
- package/dist/liquidity/orca.d.ts +6 -0
- package/dist/liquidity/orca.d.ts.map +1 -0
- package/dist/liquidity/orca.js +303 -0
- package/dist/liquidity/orca.js.map +1 -0
- package/dist/liquidity/raydiumClmm.d.ts +6 -0
- package/dist/liquidity/raydiumClmm.d.ts.map +1 -0
- package/dist/liquidity/raydiumClmm.js +307 -0
- package/dist/liquidity/raydiumClmm.js.map +1 -0
- package/dist/liquidity/types.d.ts +150 -0
- package/dist/liquidity/types.d.ts.map +1 -0
- package/dist/liquidity/types.js +2 -0
- package/dist/liquidity/types.js.map +1 -0
- package/dist/lp.d.ts +168 -0
- package/dist/lp.d.ts.map +1 -0
- package/dist/lp.js +632 -0
- package/dist/lp.js.map +1 -0
- package/dist/lpMath.d.ts +82 -0
- package/dist/lpMath.d.ts.map +1 -0
- package/dist/lpMath.js +365 -0
- package/dist/lpMath.js.map +1 -0
- package/dist/shortcuts.d.ts +8 -0
- package/dist/shortcuts.d.ts.map +1 -1
- package/dist/shortcuts.js +1 -1
- package/dist/shortcuts.js.map +1 -1
- package/dist/subpaths/liquidity.d.ts +23 -0
- package/dist/subpaths/liquidity.d.ts.map +1 -0
- package/dist/subpaths/liquidity.js +19 -0
- package/dist/subpaths/liquidity.js.map +1 -0
- package/dist/subpaths/lp.d.ts +31 -0
- package/dist/subpaths/lp.d.ts.map +1 -0
- package/dist/subpaths/lp.js +33 -0
- package/dist/subpaths/lp.js.map +1 -0
- package/dist/subpaths/write.d.ts +22 -0
- package/dist/subpaths/write.d.ts.map +1 -0
- package/dist/subpaths/write.js +19 -0
- package/dist/subpaths/write.js.map +1 -0
- package/dist/write/batch.d.ts +41 -0
- package/dist/write/batch.d.ts.map +1 -0
- package/dist/write/batch.js +46 -0
- package/dist/write/batch.js.map +1 -0
- package/dist/write/collect.d.ts +50 -0
- package/dist/write/collect.d.ts.map +1 -0
- package/dist/write/collect.js +220 -0
- package/dist/write/collect.js.map +1 -0
- package/dist/write/instructions.d.ts +16 -0
- package/dist/write/instructions.d.ts.map +1 -0
- package/dist/write/instructions.js +89 -0
- package/dist/write/instructions.js.map +1 -0
- package/dist/write/send.d.ts +115 -0
- package/dist/write/send.d.ts.map +1 -0
- package/dist/write/send.js +720 -0
- package/dist/write/send.js.map +1 -0
- package/dist/write/signer.d.ts +94 -0
- package/dist/write/signer.d.ts.map +1 -0
- package/dist/write/signer.js +197 -0
- package/dist/write/signer.js.map +1 -0
- package/dist/write/transaction.d.ts +75 -0
- package/dist/write/transaction.d.ts.map +1 -0
- package/dist/write/transaction.js +133 -0
- package/dist/write/transaction.js.map +1 -0
- package/dist/write/transfer.d.ts +72 -0
- package/dist/write/transfer.d.ts.map +1 -0
- package/dist/write/transfer.js +127 -0
- package/dist/write/transfer.js.map +1 -0
- package/package.json +23 -5
- package/src/address.ts +9 -0
- package/src/client.ts +10 -0
- package/src/index.ts +2 -1
- package/src/layout.ts +17 -0
- package/src/liquidity/amm.ts +353 -0
- package/src/liquidity/clmm.ts +108 -0
- package/src/liquidity/common.ts +285 -0
- package/src/liquidity/index.ts +177 -0
- package/src/liquidity/orca.ts +344 -0
- package/src/liquidity/raydiumClmm.ts +348 -0
- package/src/liquidity/types.ts +158 -0
- package/src/lp.ts +850 -0
- package/src/lpMath.ts +420 -0
- package/src/shortcuts.ts +1 -1
- package/src/subpaths/liquidity.ts +45 -0
- package/src/subpaths/lp.ts +71 -0
- package/src/subpaths/write.ts +29 -0
- package/src/write/batch.ts +78 -0
- package/src/write/collect.ts +286 -0
- package/src/write/instructions.ts +98 -0
- package/src/write/send.ts +876 -0
- package/src/write/signer.ts +314 -0
- package/src/write/transaction.ts +181 -0
- package/src/write/transfer.ts +189 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { SolanaLpPosition, SolanaLpProtocol, SolanaLpToken } from '../lp.js'
|
|
2
|
+
import type { SendOptions, WriteResult, WriteStatus } from '../write/send.js'
|
|
3
|
+
import type { Instruction } from '../write/transaction.js'
|
|
4
|
+
|
|
5
|
+
type Amount = bigint | number | string
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 已有的仓位:直接传 getLpPositions 查到的 SolanaLpPosition,或者只传能定位仓位的字段:
|
|
9
|
+
* - Raydium CLMM / Orca Whirlpool:positionMint(仓位 NFT 的 mint)
|
|
10
|
+
* - Raydium AMM v4 / CPMM:pool(池子地址)
|
|
11
|
+
*/
|
|
12
|
+
export interface SolanaPositionRef {
|
|
13
|
+
protocol: SolanaLpProtocol
|
|
14
|
+
positionMint?: string
|
|
15
|
+
pool?: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 往已有仓位追加:两边数量给一边即可(另一边按当前价格算),也可以都给(按较少的一边) */
|
|
19
|
+
export interface SolanaIncreaseLiquidityParams {
|
|
20
|
+
position: SolanaPositionRef | SolanaLpPosition
|
|
21
|
+
/** token0 的数量:amount0(最小单位)和 amount0Formatted(按精度换算,如 '1.5')二选一 */
|
|
22
|
+
amount0?: Amount
|
|
23
|
+
amount0Formatted?: string
|
|
24
|
+
amount1?: Amount
|
|
25
|
+
amount1Formatted?: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 新建仓位(Raydium CLMM / Orca:一个新的仓位 NFT;AMM v4 / CPMM:往池子里加流动性,拿到 LP 代币)。
|
|
30
|
+
* 池子用地址指定(Solana 上同一对代币有很多池子,按地址最明确);价格是“1 个 token0 值多少个 token1”(池子的方向)
|
|
31
|
+
*/
|
|
32
|
+
export interface SolanaNewPositionParams {
|
|
33
|
+
protocol: SolanaLpProtocol
|
|
34
|
+
pool: string
|
|
35
|
+
/** 集中流动性:价格区间(token1 / token0,取最近的可用 tick);或直接给 tick;或 fullRange */
|
|
36
|
+
priceLower?: string | number
|
|
37
|
+
priceUpper?: string | number
|
|
38
|
+
tickLower?: number
|
|
39
|
+
tickUpper?: number
|
|
40
|
+
fullRange?: boolean
|
|
41
|
+
amount0?: Amount
|
|
42
|
+
amount0Formatted?: string
|
|
43
|
+
amount1?: Amount
|
|
44
|
+
amount1Formatted?: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SolanaAddLiquidityParams = SolanaIncreaseLiquidityParams | SolanaNewPositionParams
|
|
48
|
+
|
|
49
|
+
export interface SolanaRemoveLiquidityParams {
|
|
50
|
+
position: SolanaPositionRef | SolanaLpPosition
|
|
51
|
+
/** 移除的比例(百分数,(0, 100]),默认 100 */
|
|
52
|
+
percent?: number
|
|
53
|
+
/** 或者直接给移除的数量:集中流动性是 L,AMM 是 LP 代币数量(最小单位) */
|
|
54
|
+
liquidity?: Amount
|
|
55
|
+
/** 集中流动性:全部移除后关闭仓位、销毁 NFT(退回租金),默认 false */
|
|
56
|
+
burn?: boolean
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface SolanaCollectFeesParams {
|
|
60
|
+
/** 集中流动性的仓位(AMM 的手续费已经计入 LP 份额) */
|
|
61
|
+
position: SolanaPositionRef | SolanaLpPosition
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface SolanaLiquidityOptions {
|
|
65
|
+
/** 价格滑点(比例,0.005 = 0.5%),默认 0.005 */
|
|
66
|
+
slippage?: number
|
|
67
|
+
/**
|
|
68
|
+
* Wrapped SOL 那一边用 SOL 支付 / 收取(自动包装 / 解包),默认 true。
|
|
69
|
+
* 用的是 wSOL 的关联代币账户:原来没有时创建、用完关闭(剩余的 wSOL 换回 SOL);原来就有时只补差额、不关闭
|
|
70
|
+
*/
|
|
71
|
+
native?: boolean
|
|
72
|
+
/** 新建仓位的 NFT 归谁,默认 owner */
|
|
73
|
+
recipient?: string
|
|
74
|
+
/** 取消读取 */
|
|
75
|
+
signal?: AbortSignal
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 一步:要原子执行的一组指令 */
|
|
79
|
+
export interface SolanaLiquidityStep {
|
|
80
|
+
/**
|
|
81
|
+
* - setup:创建代币账户、初始化 tick 数组等准备工作(与主指令能放进同一笔交易时会合并)
|
|
82
|
+
* - add / remove / collect:添加 / 移除流动性、领取手续费
|
|
83
|
+
*/
|
|
84
|
+
kind: 'setup' | 'add' | 'remove' | 'collect'
|
|
85
|
+
instructions: Instruction[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** 添加 / 移除流动性的计划:预计的数量 + 按顺序执行的指令。只读取、不签名,可以当作报价 */
|
|
89
|
+
export interface SolanaLiquidityPlan {
|
|
90
|
+
action: 'add' | 'remove' | 'collect'
|
|
91
|
+
protocol: SolanaLpProtocol
|
|
92
|
+
protocolName: string
|
|
93
|
+
type: 'clmm' | 'amm'
|
|
94
|
+
pool: string
|
|
95
|
+
owner: string
|
|
96
|
+
token0: SolanaLpToken
|
|
97
|
+
token1: SolanaLpToken
|
|
98
|
+
/** 集中流动性:仓位 NFT 的 mint(新建时是新生成的,见 signers)和仓位账户 */
|
|
99
|
+
positionMint: string | null
|
|
100
|
+
position: string | null
|
|
101
|
+
/** AMM:LP 代币的 mint */
|
|
102
|
+
lpMint: string | null
|
|
103
|
+
/** 集中流动性:区间、池子当前的 tick 和价格(token1 / token0,按精度换算,只用于展示) */
|
|
104
|
+
tickLower: number | null
|
|
105
|
+
tickUpper: number | null
|
|
106
|
+
tick: number | null
|
|
107
|
+
price: number | null
|
|
108
|
+
priceLower: number | null
|
|
109
|
+
priceUpper: number | null
|
|
110
|
+
/** 添加 / 移除的流动性:集中流动性是 L;AMM 是 LP 代币数量 */
|
|
111
|
+
liquidity: string
|
|
112
|
+
/** 按当前价格预计存入 / 取出的数量(不含手续费) */
|
|
113
|
+
amount0: string
|
|
114
|
+
amount1: string
|
|
115
|
+
amount0Formatted: string | null
|
|
116
|
+
amount1Formatted: string | null
|
|
117
|
+
/** 添加:最多会用掉的数量(按滑点);移除:null */
|
|
118
|
+
amount0Max: string | null
|
|
119
|
+
amount1Max: string | null
|
|
120
|
+
/** 移除:至少会拿到的数量;添加:null */
|
|
121
|
+
amount0Min: string | null
|
|
122
|
+
amount1Min: string | null
|
|
123
|
+
/** 一并领取的未领取手续费(集中流动性移除 / 领取时);AMM 为 '0' */
|
|
124
|
+
fees0: string
|
|
125
|
+
fees1: string
|
|
126
|
+
fees0Formatted: string | null
|
|
127
|
+
fees1Formatted: string | null
|
|
128
|
+
/** 一并领取的挖矿奖励的代币(集中流动性移除 / 领取时;数量要等交易执行后才知道) */
|
|
129
|
+
rewardMints: string[]
|
|
130
|
+
/** 哪一边用 SOL 支付 / 收取(自动包装 / 解包 wSOL) */
|
|
131
|
+
native: 'token0' | 'token1' | null
|
|
132
|
+
/** 按顺序执行;setup 和主指令能放进同一笔交易时会合并 */
|
|
133
|
+
steps: SolanaLiquidityStep[]
|
|
134
|
+
/**
|
|
135
|
+
* 除 owner 外还需要签名的临时密钥(新建集中流动性仓位时的 NFT mint,32 字节种子)。
|
|
136
|
+
* 自己发送时用它签名主指令所在的交易(如 web3.js 的 Keypair.fromSeed(secretKey))
|
|
137
|
+
*/
|
|
138
|
+
signers: Array<{ address: string; secretKey: Uint8Array }>
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface SolanaLiquiditySendOptions extends SolanaLiquidityOptions, Omit<SendOptions, 'onUpdate' | 'signal'> {
|
|
142
|
+
/** 发送前检查余额够不够(添加时),默认 true */
|
|
143
|
+
checkBalance?: boolean
|
|
144
|
+
onUpdate?: (result: SolanaLiquidityStepResult) => void
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface SolanaLiquidityStepResult extends WriteResult {
|
|
148
|
+
kind: SolanaLiquidityStep['kind']
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface SolanaLiquidityResult {
|
|
152
|
+
plan: SolanaLiquidityPlan
|
|
153
|
+
/** 与 plan.steps 一一对应 */
|
|
154
|
+
results: SolanaLiquidityStepResult[]
|
|
155
|
+
/** 主指令(最后一步)的状态和签名 */
|
|
156
|
+
status: WriteStatus
|
|
157
|
+
signature: string | null
|
|
158
|
+
}
|