four-flap-meme-sdk 1.4.87 → 1.4.89
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/sol/constants.d.ts +126 -0
- package/dist/sol/constants.js +145 -0
- package/dist/sol/dex/blockrazor/client.d.ts +51 -0
- package/dist/sol/dex/blockrazor/client.js +96 -0
- package/dist/sol/dex/blockrazor/constants.d.ts +34 -0
- package/dist/sol/dex/blockrazor/constants.js +55 -0
- package/dist/sol/dex/blockrazor/geyser.d.ts +128 -0
- package/dist/sol/dex/blockrazor/geyser.js +530 -0
- package/dist/sol/dex/blockrazor/index.d.ts +18 -0
- package/dist/sol/dex/blockrazor/index.js +23 -0
- package/dist/sol/dex/blockrazor/send.d.ts +135 -0
- package/dist/sol/dex/blockrazor/send.js +254 -0
- package/dist/sol/dex/blockrazor/types.d.ts +191 -0
- package/dist/sol/dex/blockrazor/types.js +5 -0
- package/dist/sol/dex/index.d.ts +10 -0
- package/dist/sol/dex/index.js +16 -0
- package/dist/sol/dex/jup/client.d.ts +33 -0
- package/dist/sol/dex/jup/client.js +110 -0
- package/dist/sol/dex/jup/index.d.ts +16 -0
- package/dist/sol/dex/jup/index.js +148 -0
- package/dist/sol/dex/jup/legacy.d.ts +623 -0
- package/dist/sol/dex/jup/legacy.js +416 -0
- package/dist/sol/dex/jup/lend.d.ts +640 -0
- package/dist/sol/dex/jup/lend.js +603 -0
- package/dist/sol/dex/jup/portfolio.d.ts +362 -0
- package/dist/sol/dex/jup/portfolio.js +367 -0
- package/dist/sol/dex/jup/price.d.ts +173 -0
- package/dist/sol/dex/jup/price.js +220 -0
- package/dist/sol/dex/jup/recurring.d.ts +437 -0
- package/dist/sol/dex/jup/recurring.js +320 -0
- package/dist/sol/dex/jup/send.d.ts +282 -0
- package/dist/sol/dex/jup/send.js +295 -0
- package/dist/sol/dex/jup/studio.d.ts +457 -0
- package/dist/sol/dex/jup/studio.js +488 -0
- package/dist/sol/dex/jup/tokens.d.ts +767 -0
- package/dist/sol/dex/jup/tokens.js +697 -0
- package/dist/sol/dex/jup/trigger.d.ts +511 -0
- package/dist/sol/dex/jup/trigger.js +397 -0
- package/dist/sol/dex/jup/types.d.ts +433 -0
- package/dist/sol/dex/jup/types.js +5 -0
- package/dist/sol/dex/jup/ultra.d.ts +646 -0
- package/dist/sol/dex/jup/ultra.js +853 -0
- package/dist/sol/dex/meteora/client.d.ts +76 -0
- package/dist/sol/dex/meteora/client.js +219 -0
- package/dist/sol/dex/meteora/damm-v1-bundle.d.ts +61 -0
- package/dist/sol/dex/meteora/damm-v1-bundle.js +112 -0
- package/dist/sol/dex/meteora/damm-v1.d.ts +118 -0
- package/dist/sol/dex/meteora/damm-v1.js +315 -0
- package/dist/sol/dex/meteora/damm-v2-bundle.d.ts +82 -0
- package/dist/sol/dex/meteora/damm-v2-bundle.js +242 -0
- package/dist/sol/dex/meteora/damm-v2.d.ts +172 -0
- package/dist/sol/dex/meteora/damm-v2.js +632 -0
- package/dist/sol/dex/meteora/dbc-bundle.d.ts +123 -0
- package/dist/sol/dex/meteora/dbc-bundle.js +304 -0
- package/dist/sol/dex/meteora/dbc.d.ts +192 -0
- package/dist/sol/dex/meteora/dbc.js +619 -0
- package/dist/sol/dex/meteora/dlmm-bundle.d.ts +39 -0
- package/dist/sol/dex/meteora/dlmm-bundle.js +189 -0
- package/dist/sol/dex/meteora/dlmm.d.ts +157 -0
- package/dist/sol/dex/meteora/dlmm.js +671 -0
- package/dist/sol/dex/meteora/index.d.ts +25 -0
- package/dist/sol/dex/meteora/index.js +65 -0
- package/dist/sol/dex/meteora/types.d.ts +787 -0
- package/dist/sol/dex/meteora/types.js +110 -0
- package/dist/sol/dex/orca/index.d.ts +10 -0
- package/dist/sol/dex/orca/index.js +16 -0
- package/dist/sol/dex/orca/orca-bundle.d.ts +41 -0
- package/dist/sol/dex/orca/orca-bundle.js +173 -0
- package/dist/sol/dex/orca/orca.d.ts +65 -0
- package/dist/sol/dex/orca/orca.js +474 -0
- package/dist/sol/dex/orca/types.d.ts +263 -0
- package/dist/sol/dex/orca/types.js +38 -0
- package/dist/sol/dex/orca/wavebreak-bundle.d.ts +34 -0
- package/dist/sol/dex/orca/wavebreak-bundle.js +198 -0
- package/dist/sol/dex/orca/wavebreak-types.d.ts +227 -0
- package/dist/sol/dex/orca/wavebreak-types.js +23 -0
- package/dist/sol/dex/orca/wavebreak.d.ts +78 -0
- package/dist/sol/dex/orca/wavebreak.js +497 -0
- package/dist/sol/dex/pump/index.d.ts +9 -0
- package/dist/sol/dex/pump/index.js +14 -0
- package/dist/sol/dex/pump/pump-bundle.d.ts +92 -0
- package/dist/sol/dex/pump/pump-bundle.js +383 -0
- package/dist/sol/dex/pump/pump-swap-bundle.d.ts +103 -0
- package/dist/sol/dex/pump/pump-swap-bundle.js +380 -0
- package/dist/sol/dex/pump/pump-swap.d.ts +46 -0
- package/dist/sol/dex/pump/pump-swap.js +199 -0
- package/dist/sol/dex/pump/pump.d.ts +35 -0
- package/dist/sol/dex/pump/pump.js +352 -0
- package/dist/sol/dex/pump/types.d.ts +215 -0
- package/dist/sol/dex/pump/types.js +5 -0
- package/dist/sol/dex/raydium/index.d.ts +8 -0
- package/dist/sol/dex/raydium/index.js +12 -0
- package/dist/sol/dex/raydium/launchlab.d.ts +68 -0
- package/dist/sol/dex/raydium/launchlab.js +210 -0
- package/dist/sol/dex/raydium/raydium-bundle.d.ts +64 -0
- package/dist/sol/dex/raydium/raydium-bundle.js +324 -0
- package/dist/sol/dex/raydium/raydium.d.ts +40 -0
- package/dist/sol/dex/raydium/raydium.js +366 -0
- package/dist/sol/dex/raydium/types.d.ts +240 -0
- package/dist/sol/dex/raydium/types.js +5 -0
- package/dist/sol/index.d.ts +10 -0
- package/dist/sol/index.js +16 -0
- package/dist/sol/jito/bundle.d.ts +90 -0
- package/dist/sol/jito/bundle.js +263 -0
- package/dist/sol/jito/index.d.ts +7 -0
- package/dist/sol/jito/index.js +7 -0
- package/dist/sol/jito/tip.d.ts +51 -0
- package/dist/sol/jito/tip.js +83 -0
- package/dist/sol/jito/types.d.ts +100 -0
- package/dist/sol/jito/types.js +5 -0
- package/dist/sol/token/create-complete.d.ts +115 -0
- package/dist/sol/token/create-complete.js +235 -0
- package/dist/sol/token/create-token.d.ts +57 -0
- package/dist/sol/token/create-token.js +230 -0
- package/dist/sol/token/index.d.ts +9 -0
- package/dist/sol/token/index.js +14 -0
- package/dist/sol/token/metadata-upload.d.ts +86 -0
- package/dist/sol/token/metadata-upload.js +173 -0
- package/dist/sol/token/metadata.d.ts +92 -0
- package/dist/sol/token/metadata.js +274 -0
- package/dist/sol/token/types.d.ts +153 -0
- package/dist/sol/token/types.js +5 -0
- package/dist/sol/types.d.ts +176 -0
- package/dist/sol/types.js +7 -0
- package/dist/sol/utils/balance.d.ts +160 -0
- package/dist/sol/utils/balance.js +638 -0
- package/dist/sol/utils/connection.d.ts +78 -0
- package/dist/sol/utils/connection.js +168 -0
- package/dist/sol/utils/index.d.ts +9 -0
- package/dist/sol/utils/index.js +9 -0
- package/dist/sol/utils/lp-inspect.d.ts +129 -0
- package/dist/sol/utils/lp-inspect.js +900 -0
- package/dist/sol/utils/transfer.d.ts +125 -0
- package/dist/sol/utils/transfer.js +220 -0
- package/dist/sol/utils/wallet.d.ts +107 -0
- package/dist/sol/utils/wallet.js +210 -0
- package/dist/utils/constants.d.ts +2 -2
- package/dist/utils/constants.js +2 -2
- package/package.json +38 -3
- package/README.zh-CN.pdf +0 -0
- package/dist/flap/portal-bundle-merkle/encryption.d.ts +0 -16
- package/dist/flap/portal-bundle-merkle/encryption.js +0 -146
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jupiter Portfolio API V1
|
|
3
|
+
* @module sol/dex/jup/portfolio
|
|
4
|
+
*
|
|
5
|
+
* Portfolio API 提供钱包投资组合/持仓查询
|
|
6
|
+
* 包括各平台的 DeFi 头寸、代币持仓等
|
|
7
|
+
*/
|
|
8
|
+
import { jupGet } from './client.js';
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Portfolio API - 投资组合查询
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/**
|
|
13
|
+
* 获取钱包投资组合 (V1)
|
|
14
|
+
*
|
|
15
|
+
* 查询钱包在各 DeFi 平台的持仓情况。
|
|
16
|
+
*
|
|
17
|
+
* @param params 查询参数
|
|
18
|
+
* @param config Jupiter 配置
|
|
19
|
+
* @returns 投资组合响应
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { Sol } from 'four-flap-meme-sdk'
|
|
24
|
+
*
|
|
25
|
+
* Sol.setJupiterConfig({ apiKey: 'your-api-key' })
|
|
26
|
+
*
|
|
27
|
+
* // 获取钱包投资组合
|
|
28
|
+
* const portfolio = await Sol.getPortfolio({
|
|
29
|
+
* address: 'YourWalletAddress...',
|
|
30
|
+
* })
|
|
31
|
+
*
|
|
32
|
+
* console.log(`钱包: ${portfolio.owner}`)
|
|
33
|
+
* console.log(`查询时间: ${new Date(portfolio.date * 1000)}`)
|
|
34
|
+
* console.log(`耗时: ${portfolio.duration}ms`)
|
|
35
|
+
*
|
|
36
|
+
* // 遍历投资组合元素
|
|
37
|
+
* portfolio.elements.forEach(element => {
|
|
38
|
+
* console.log(`[${element.platformId}] ${element.label}`)
|
|
39
|
+
* console.log(` 类型: ${element.type}`)
|
|
40
|
+
* console.log(` 价值: $${element.value}`)
|
|
41
|
+
* })
|
|
42
|
+
*
|
|
43
|
+
* // 按平台筛选
|
|
44
|
+
* const raydiumOnly = await Sol.getPortfolio({
|
|
45
|
+
* address: 'YourWalletAddress...',
|
|
46
|
+
* platforms: 'raydium',
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export async function getPortfolio(params, config) {
|
|
51
|
+
const queryParams = {};
|
|
52
|
+
if (params.platforms) {
|
|
53
|
+
queryParams.platforms = params.platforms;
|
|
54
|
+
}
|
|
55
|
+
return jupGet(`/portfolio/v1/positions/${params.address}`, queryParams, config);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 获取钱包投资组合(简化版)
|
|
59
|
+
*
|
|
60
|
+
* @param address 钱包地址
|
|
61
|
+
* @param platforms 平台 ID 数组(可选)
|
|
62
|
+
* @param config Jupiter 配置
|
|
63
|
+
* @returns 投资组合响应
|
|
64
|
+
*/
|
|
65
|
+
export async function getWalletPortfolio(address, platforms, config) {
|
|
66
|
+
return getPortfolio({
|
|
67
|
+
address,
|
|
68
|
+
platforms: platforms?.join(','),
|
|
69
|
+
}, config);
|
|
70
|
+
}
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// Staked JUP API - JUP 质押查询
|
|
73
|
+
// ============================================================================
|
|
74
|
+
/**
|
|
75
|
+
* 获取 JUP 质押信息
|
|
76
|
+
*
|
|
77
|
+
* @param address 钱包地址
|
|
78
|
+
* @param config Jupiter 配置
|
|
79
|
+
* @returns JUP 质押信息
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* import { Sol } from 'four-flap-meme-sdk'
|
|
84
|
+
*
|
|
85
|
+
* Sol.setJupiterConfig({ apiKey: 'your-api-key' })
|
|
86
|
+
*
|
|
87
|
+
* const staked = await Sol.getStakedJup('YourWalletAddress...')
|
|
88
|
+
*
|
|
89
|
+
* console.log(`已质押: ${staked.stakedAmount} JUP`)
|
|
90
|
+
*
|
|
91
|
+
* if (staked.unstaking.length > 0) {
|
|
92
|
+
* console.log('解锁中:')
|
|
93
|
+
* staked.unstaking.forEach(u => {
|
|
94
|
+
* const unlockDate = new Date(u.until * 1000)
|
|
95
|
+
* console.log(` ${u.amount} JUP - ${unlockDate.toLocaleString()}`)
|
|
96
|
+
* })
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export async function getStakedJup(address, config) {
|
|
101
|
+
return jupGet(`/portfolio/v1/staked-jup/${address}`, {}, config);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 获取 JUP 质押总量
|
|
105
|
+
*
|
|
106
|
+
* @param address 钱包地址
|
|
107
|
+
* @param config Jupiter 配置
|
|
108
|
+
* @returns 已质押的 JUP 数量
|
|
109
|
+
*/
|
|
110
|
+
export async function getStakedJupAmount(address, config) {
|
|
111
|
+
const info = await getStakedJup(address, config);
|
|
112
|
+
return info.stakedAmount;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 获取解锁中的 JUP 总量
|
|
116
|
+
*
|
|
117
|
+
* @param address 钱包地址
|
|
118
|
+
* @param config Jupiter 配置
|
|
119
|
+
* @returns 解锁中的 JUP 总量
|
|
120
|
+
*/
|
|
121
|
+
export async function getUnstakingJupAmount(address, config) {
|
|
122
|
+
const info = await getStakedJup(address, config);
|
|
123
|
+
return info.unstaking.reduce((sum, u) => sum + u.amount, 0);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 检查是否有即将解锁的 JUP
|
|
127
|
+
*
|
|
128
|
+
* @param address 钱包地址
|
|
129
|
+
* @param withinHours 在多少小时内(默认 24)
|
|
130
|
+
* @param config Jupiter 配置
|
|
131
|
+
* @returns 即将解锁的列表
|
|
132
|
+
*/
|
|
133
|
+
export async function getUpcomingUnlocks(address, withinHours = 24, config) {
|
|
134
|
+
const info = await getStakedJup(address, config);
|
|
135
|
+
const now = Math.floor(Date.now() / 1000);
|
|
136
|
+
const cutoff = now + (withinHours * 3600);
|
|
137
|
+
return info.unstaking.filter(u => u.until <= cutoff && u.until > now);
|
|
138
|
+
}
|
|
139
|
+
// ============================================================================
|
|
140
|
+
// Platforms API - 平台列表
|
|
141
|
+
// ============================================================================
|
|
142
|
+
/**
|
|
143
|
+
* 获取所有平台列表
|
|
144
|
+
*
|
|
145
|
+
* @param config Jupiter 配置
|
|
146
|
+
* @returns 平台信息列表
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* import { Sol } from 'four-flap-meme-sdk'
|
|
151
|
+
*
|
|
152
|
+
* Sol.setJupiterConfig({ apiKey: 'your-api-key' })
|
|
153
|
+
*
|
|
154
|
+
* const platforms = await Sol.getPlatforms()
|
|
155
|
+
*
|
|
156
|
+
* platforms.forEach(p => {
|
|
157
|
+
* console.log(`[${p.id}] ${p.name}`)
|
|
158
|
+
* console.log(` ${p.description}`)
|
|
159
|
+
* console.log(` 标签: ${p.tags.join(', ')}`)
|
|
160
|
+
* if (p.links.website) {
|
|
161
|
+
* console.log(` 网站: ${p.links.website}`)
|
|
162
|
+
* }
|
|
163
|
+
* })
|
|
164
|
+
* ```
|
|
165
|
+
*/
|
|
166
|
+
export async function getPlatforms(config) {
|
|
167
|
+
return jupGet('/portfolio/v1/platforms', {}, config);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* 获取平台 ID 列表
|
|
171
|
+
*
|
|
172
|
+
* @param config Jupiter 配置
|
|
173
|
+
* @returns 平台 ID 数组
|
|
174
|
+
*/
|
|
175
|
+
export async function getPlatformIds(config) {
|
|
176
|
+
const platforms = await getPlatforms(config);
|
|
177
|
+
return platforms.map(p => p.id);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 获取活跃平台列表(非弃用)
|
|
181
|
+
*
|
|
182
|
+
* @param config Jupiter 配置
|
|
183
|
+
* @returns 活跃平台列表
|
|
184
|
+
*/
|
|
185
|
+
export async function getActivePlatforms(config) {
|
|
186
|
+
const platforms = await getPlatforms(config);
|
|
187
|
+
return platforms.filter(p => !p.isDeprecated);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* 按标签筛选平台
|
|
191
|
+
*
|
|
192
|
+
* @param tag 标签
|
|
193
|
+
* @param config Jupiter 配置
|
|
194
|
+
* @returns 匹配的平台列表
|
|
195
|
+
*/
|
|
196
|
+
export async function getPlatformsByTag(tag, config) {
|
|
197
|
+
const platforms = await getPlatforms(config);
|
|
198
|
+
return platforms.filter(p => p.tags.includes(tag));
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* 搜索平台
|
|
202
|
+
*
|
|
203
|
+
* @param keyword 关键词(搜索名称和描述)
|
|
204
|
+
* @param config Jupiter 配置
|
|
205
|
+
* @returns 匹配的平台列表
|
|
206
|
+
*/
|
|
207
|
+
export async function searchPlatforms(keyword, config) {
|
|
208
|
+
const platforms = await getPlatforms(config);
|
|
209
|
+
const lowerKeyword = keyword.toLowerCase();
|
|
210
|
+
return platforms.filter(p => p.name.toLowerCase().includes(lowerKeyword) ||
|
|
211
|
+
p.description.toLowerCase().includes(lowerKeyword) ||
|
|
212
|
+
p.id.toLowerCase().includes(lowerKeyword));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 获取平台详情
|
|
216
|
+
*
|
|
217
|
+
* @param platformId 平台 ID
|
|
218
|
+
* @param config Jupiter 配置
|
|
219
|
+
* @returns 平台信息或 null
|
|
220
|
+
*/
|
|
221
|
+
export async function getPlatformById(platformId, config) {
|
|
222
|
+
const platforms = await getPlatforms(config);
|
|
223
|
+
return platforms.find(p => p.id === platformId) ?? null;
|
|
224
|
+
}
|
|
225
|
+
// ============================================================================
|
|
226
|
+
// 便捷方法
|
|
227
|
+
// ============================================================================
|
|
228
|
+
/**
|
|
229
|
+
* 获取投资组合总价值
|
|
230
|
+
*
|
|
231
|
+
* @param address 钱包地址
|
|
232
|
+
* @param config Jupiter 配置
|
|
233
|
+
* @returns 总价值 (USD)
|
|
234
|
+
*/
|
|
235
|
+
export async function getPortfolioTotalValue(address, config) {
|
|
236
|
+
const portfolio = await getWalletPortfolio(address, undefined, config);
|
|
237
|
+
return portfolio.elements.reduce((sum, el) => sum + el.value, 0);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* 获取按平台分组的投资组合
|
|
241
|
+
*
|
|
242
|
+
* @param address 钱包地址
|
|
243
|
+
* @param config Jupiter 配置
|
|
244
|
+
* @returns 平台 -> 元素列表 映射
|
|
245
|
+
*/
|
|
246
|
+
export async function getPortfolioByPlatform(address, config) {
|
|
247
|
+
const portfolio = await getWalletPortfolio(address, undefined, config);
|
|
248
|
+
const platformMap = new Map();
|
|
249
|
+
portfolio.elements.forEach(element => {
|
|
250
|
+
const existing = platformMap.get(element.platformId) || [];
|
|
251
|
+
existing.push(element);
|
|
252
|
+
platformMap.set(element.platformId, existing);
|
|
253
|
+
});
|
|
254
|
+
return platformMap;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* 获取按类型分组的投资组合
|
|
258
|
+
*
|
|
259
|
+
* @param address 钱包地址
|
|
260
|
+
* @param config Jupiter 配置
|
|
261
|
+
* @returns 类型 -> 元素列表 映射
|
|
262
|
+
*/
|
|
263
|
+
export async function getPortfolioByType(address, config) {
|
|
264
|
+
const portfolio = await getWalletPortfolio(address, undefined, config);
|
|
265
|
+
const typeMap = new Map();
|
|
266
|
+
portfolio.elements.forEach(element => {
|
|
267
|
+
const existing = typeMap.get(element.type) || [];
|
|
268
|
+
existing.push(element);
|
|
269
|
+
typeMap.set(element.type, existing);
|
|
270
|
+
});
|
|
271
|
+
return typeMap;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* 获取平台价值汇总
|
|
275
|
+
*
|
|
276
|
+
* @param address 钱包地址
|
|
277
|
+
* @param config Jupiter 配置
|
|
278
|
+
* @returns 平台 -> 总价值 映射
|
|
279
|
+
*/
|
|
280
|
+
export async function getPlatformValueSummary(address, config) {
|
|
281
|
+
const platformElements = await getPortfolioByPlatform(address, config);
|
|
282
|
+
const summaryMap = new Map();
|
|
283
|
+
platformElements.forEach((elements, platformId) => {
|
|
284
|
+
const totalValue = elements.reduce((sum, el) => sum + el.value, 0);
|
|
285
|
+
summaryMap.set(platformId, totalValue);
|
|
286
|
+
});
|
|
287
|
+
return summaryMap;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* 获取投资组合摘要
|
|
291
|
+
*
|
|
292
|
+
* @param address 钱包地址
|
|
293
|
+
* @param config Jupiter 配置
|
|
294
|
+
* @returns 投资组合摘要
|
|
295
|
+
*/
|
|
296
|
+
export async function getPortfolioSummary(address, config) {
|
|
297
|
+
const portfolio = await getWalletPortfolio(address, undefined, config);
|
|
298
|
+
// 按平台汇总
|
|
299
|
+
const platformMap = new Map();
|
|
300
|
+
portfolio.elements.forEach(element => {
|
|
301
|
+
const existing = platformMap.get(element.platformId) || { value: 0, count: 0 };
|
|
302
|
+
existing.value += element.value;
|
|
303
|
+
existing.count += 1;
|
|
304
|
+
platformMap.set(element.platformId, existing);
|
|
305
|
+
});
|
|
306
|
+
const platforms = Array.from(platformMap.entries())
|
|
307
|
+
.map(([id, data]) => ({ id, ...data }))
|
|
308
|
+
.sort((a, b) => b.value - a.value);
|
|
309
|
+
return {
|
|
310
|
+
owner: portfolio.owner,
|
|
311
|
+
totalValue: portfolio.elements.reduce((sum, el) => sum + el.value, 0),
|
|
312
|
+
platformCount: platformMap.size,
|
|
313
|
+
elementCount: portfolio.elements.length,
|
|
314
|
+
platforms,
|
|
315
|
+
fetchDuration: portfolio.duration,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* 筛选特定平台的元素
|
|
320
|
+
*
|
|
321
|
+
* @param elements 元素列表
|
|
322
|
+
* @param platformId 平台 ID
|
|
323
|
+
* @returns 筛选后的元素
|
|
324
|
+
*/
|
|
325
|
+
export function filterByPlatform(elements, platformId) {
|
|
326
|
+
return elements.filter(el => el.platformId === platformId);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* 筛选特定类型的元素
|
|
330
|
+
*
|
|
331
|
+
* @param elements 元素列表
|
|
332
|
+
* @param type 类型
|
|
333
|
+
* @returns 筛选后的元素
|
|
334
|
+
*/
|
|
335
|
+
export function filterByType(elements, type) {
|
|
336
|
+
return elements.filter(el => el.type === type);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* 筛选价值大于阈值的元素
|
|
340
|
+
*
|
|
341
|
+
* @param elements 元素列表
|
|
342
|
+
* @param minValue 最小价值 (USD)
|
|
343
|
+
* @returns 筛选后的元素
|
|
344
|
+
*/
|
|
345
|
+
export function filterByMinValue(elements, minValue) {
|
|
346
|
+
return elements.filter(el => el.value >= minValue);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 按价值排序元素
|
|
350
|
+
*
|
|
351
|
+
* @param elements 元素列表
|
|
352
|
+
* @param descending 是否降序(默认 true)
|
|
353
|
+
* @returns 排序后的元素
|
|
354
|
+
*/
|
|
355
|
+
export function sortByValue(elements, descending = true) {
|
|
356
|
+
return [...elements].sort((a, b) => descending ? b.value - a.value : a.value - b.value);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* 获取前 N 个高价值元素
|
|
360
|
+
*
|
|
361
|
+
* @param elements 元素列表
|
|
362
|
+
* @param n 数量
|
|
363
|
+
* @returns 前 N 个元素
|
|
364
|
+
*/
|
|
365
|
+
export function getTopElements(elements, n) {
|
|
366
|
+
return sortByValue(elements).slice(0, n);
|
|
367
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jupiter Price API V3
|
|
3
|
+
* @module sol/dex/jup/price
|
|
4
|
+
*
|
|
5
|
+
* Price API 提供代币价格查询
|
|
6
|
+
* 支持批量查询,返回 USD 价格和 24h 变化
|
|
7
|
+
*/
|
|
8
|
+
import type { JupiterConfig } from './types.js';
|
|
9
|
+
/** 单个代币价格信息 */
|
|
10
|
+
export interface TokenPriceInfo {
|
|
11
|
+
/** 小数位数 */
|
|
12
|
+
decimals: number;
|
|
13
|
+
/** USD 价格 */
|
|
14
|
+
usdPrice: number;
|
|
15
|
+
/** 区块 ID */
|
|
16
|
+
blockId?: number | null;
|
|
17
|
+
/** 24小时价格变化百分比 */
|
|
18
|
+
priceChange24h?: number | null;
|
|
19
|
+
}
|
|
20
|
+
/** 价格响应 (key 为代币 Mint 地址) */
|
|
21
|
+
export type PriceResponse = Record<string, TokenPriceInfo>;
|
|
22
|
+
/**
|
|
23
|
+
* 获取代币价格 (V3)
|
|
24
|
+
*
|
|
25
|
+
* 批量查询代币的 USD 价格。
|
|
26
|
+
*
|
|
27
|
+
* @param ids 代币 Mint 地址数组
|
|
28
|
+
* @param config Jupiter 配置
|
|
29
|
+
* @returns 价格响应
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { Sol } from 'four-flap-meme-sdk'
|
|
34
|
+
*
|
|
35
|
+
* Sol.setJupiterConfig({ apiKey: 'your-api-key' })
|
|
36
|
+
*
|
|
37
|
+
* // 批量获取价格
|
|
38
|
+
* const prices = await Sol.getTokenPricesV3([
|
|
39
|
+
* 'So11111111111111111111111111111111111111112', // SOL
|
|
40
|
+
* 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', // USDC
|
|
41
|
+
* 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB', // USDT
|
|
42
|
+
* ])
|
|
43
|
+
*
|
|
44
|
+
* Object.entries(prices).forEach(([mint, info]) => {
|
|
45
|
+
* console.log(`${mint}:`)
|
|
46
|
+
* console.log(` 价格: $${info.usdPrice}`)
|
|
47
|
+
* console.log(` 24h变化: ${info.priceChange24h ?? 0}%`)
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function getTokenPricesV3(ids: string[], config?: JupiterConfig): Promise<PriceResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* 获取单个代币价格 (V3)
|
|
54
|
+
*
|
|
55
|
+
* @param mint 代币 Mint 地址
|
|
56
|
+
* @param config Jupiter 配置
|
|
57
|
+
* @returns 价格信息或 null
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const solPrice = await Sol.getSingleTokenPriceV3(
|
|
62
|
+
* 'So11111111111111111111111111111111111111112'
|
|
63
|
+
* )
|
|
64
|
+
*
|
|
65
|
+
* if (solPrice) {
|
|
66
|
+
* console.log(`SOL: $${solPrice.usdPrice}`)
|
|
67
|
+
* console.log(`24h: ${solPrice.priceChange24h}%`)
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare function getSingleTokenPriceV3(mint: string, config?: JupiterConfig): Promise<TokenPriceInfo | null>;
|
|
72
|
+
/**
|
|
73
|
+
* 获取 USD 价格 (V3)
|
|
74
|
+
*
|
|
75
|
+
* @param mint 代币 Mint 地址
|
|
76
|
+
* @param config Jupiter 配置
|
|
77
|
+
* @returns USD 价格或 null
|
|
78
|
+
*/
|
|
79
|
+
export declare function getUsdPrice(mint: string, config?: JupiterConfig): Promise<number | null>;
|
|
80
|
+
/**
|
|
81
|
+
* 批量获取 USD 价格 (V3)
|
|
82
|
+
*
|
|
83
|
+
* @param mints 代币 Mint 地址数组
|
|
84
|
+
* @param config Jupiter 配置
|
|
85
|
+
* @returns Mint -> 价格 映射
|
|
86
|
+
*/
|
|
87
|
+
export declare function batchGetUsdPrices(mints: string[], config?: JupiterConfig): Promise<Map<string, number | null>>;
|
|
88
|
+
/**
|
|
89
|
+
* 获取 24h 价格变化 (V3)
|
|
90
|
+
*
|
|
91
|
+
* @param mint 代币 Mint 地址
|
|
92
|
+
* @param config Jupiter 配置
|
|
93
|
+
* @returns 24h 价格变化百分比或 null
|
|
94
|
+
*/
|
|
95
|
+
export declare function get24hPriceChange(mint: string, config?: JupiterConfig): Promise<number | null>;
|
|
96
|
+
/**
|
|
97
|
+
* 计算代币价值 (V3)
|
|
98
|
+
*
|
|
99
|
+
* @param mint 代币 Mint 地址
|
|
100
|
+
* @param amount 代币数量 (最小单位)
|
|
101
|
+
* @param config Jupiter 配置
|
|
102
|
+
* @returns USD 价值或 null
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // 计算 1 SOL 的 USD 价值
|
|
107
|
+
* const value = await Sol.calculateTokenValue(
|
|
108
|
+
* 'So11111111111111111111111111111111111111112',
|
|
109
|
+
* 1_000_000_000, // 1 SOL = 10^9 lamports
|
|
110
|
+
* )
|
|
111
|
+
* console.log(`1 SOL = $${value}`)
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function calculateTokenValue(mint: string, amount: number | bigint, config?: JupiterConfig): Promise<number | null>;
|
|
115
|
+
/**
|
|
116
|
+
* 批量计算代币价值 (V3)
|
|
117
|
+
*
|
|
118
|
+
* @param holdings 持仓数组 [{mint, amount}]
|
|
119
|
+
* @param config Jupiter 配置
|
|
120
|
+
* @returns 总 USD 价值和明细
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* const result = await Sol.calculatePortfolioValue([
|
|
125
|
+
* { mint: 'So11111111111111111111111111111111111111112', amount: 1_000_000_000 },
|
|
126
|
+
* { mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v', amount: 100_000_000 },
|
|
127
|
+
* ])
|
|
128
|
+
*
|
|
129
|
+
* console.log(`总价值: $${result.totalValue}`)
|
|
130
|
+
* result.details.forEach(d => {
|
|
131
|
+
* console.log(` ${d.mint}: $${d.value}`)
|
|
132
|
+
* })
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare function calculatePortfolioValue(holdings: Array<{
|
|
136
|
+
mint: string;
|
|
137
|
+
amount: number | bigint;
|
|
138
|
+
}>, config?: JupiterConfig): Promise<{
|
|
139
|
+
totalValue: number;
|
|
140
|
+
details: Array<{
|
|
141
|
+
mint: string;
|
|
142
|
+
amount: number;
|
|
143
|
+
price: number | null;
|
|
144
|
+
value: number | null;
|
|
145
|
+
}>;
|
|
146
|
+
}>;
|
|
147
|
+
/** 常用代币 Mint 地址 */
|
|
148
|
+
export declare const COMMON_TOKENS: {
|
|
149
|
+
/** SOL (Wrapped) */
|
|
150
|
+
readonly SOL: "So11111111111111111111111111111111111111112";
|
|
151
|
+
/** USDC */
|
|
152
|
+
readonly USDC: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
153
|
+
/** USDT */
|
|
154
|
+
readonly USDT: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB";
|
|
155
|
+
/** JUP */
|
|
156
|
+
readonly JUP: "JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN";
|
|
157
|
+
/** BONK */
|
|
158
|
+
readonly BONK: "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263";
|
|
159
|
+
/** RAY */
|
|
160
|
+
readonly RAY: "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R";
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* 获取 SOL 价格 (V3)
|
|
164
|
+
*/
|
|
165
|
+
export declare function getSolPrice(config?: JupiterConfig): Promise<number | null>;
|
|
166
|
+
/**
|
|
167
|
+
* 获取 USDC 价格 (V3)
|
|
168
|
+
*/
|
|
169
|
+
export declare function getUsdcPrice(config?: JupiterConfig): Promise<number | null>;
|
|
170
|
+
/**
|
|
171
|
+
* 获取常用代币价格 (V3)
|
|
172
|
+
*/
|
|
173
|
+
export declare function getCommonTokenPrices(config?: JupiterConfig): Promise<PriceResponse>;
|