@one_deploy/sdk 1.0.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/.turbo/turbo-build.log +0 -0
- package/.turbo/turbo-type-check.log +0 -0
- package/dist/config/index.d.mts +74 -0
- package/dist/config/index.d.ts +74 -0
- package/dist/config/index.js +242 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/index.mjs +224 -0
- package/dist/config/index.mjs.map +1 -0
- package/dist/engine-5ndtBaCr.d.ts +1039 -0
- package/dist/engine-CrlhH0nw.d.mts +1039 -0
- package/dist/hooks/index.d.mts +56 -0
- package/dist/hooks/index.d.ts +56 -0
- package/dist/hooks/index.js +1360 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/index.mjs +1356 -0
- package/dist/hooks/index.mjs.map +1 -0
- package/dist/index.d.mts +356 -0
- package/dist/index.d.ts +356 -0
- package/dist/index.js +5068 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4949 -0
- package/dist/index.mjs.map +1 -0
- package/dist/price-CgqXPnT3.d.ts +13 -0
- package/dist/price-ClbLHHjv.d.mts +13 -0
- package/dist/providers/index.d.mts +121 -0
- package/dist/providers/index.d.ts +121 -0
- package/dist/providers/index.js +1642 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/index.mjs +1600 -0
- package/dist/providers/index.mjs.map +1 -0
- package/dist/react-native.d.mts +120 -0
- package/dist/react-native.d.ts +120 -0
- package/dist/react-native.js +1792 -0
- package/dist/react-native.js.map +1 -0
- package/dist/react-native.mjs +1755 -0
- package/dist/react-native.mjs.map +1 -0
- package/dist/services/index.d.mts +85 -0
- package/dist/services/index.d.ts +85 -0
- package/dist/services/index.js +1466 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/index.mjs +1458 -0
- package/dist/services/index.mjs.map +1 -0
- package/dist/types/index.d.mts +759 -0
- package/dist/types/index.d.ts +759 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +3 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/utils/index.d.mts +36 -0
- package/dist/utils/index.d.ts +36 -0
- package/dist/utils/index.js +164 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.mjs +142 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +101 -0
- package/src/components/OneConnectButton.tsx +143 -0
- package/src/components/OneNFTGallery.tsx +324 -0
- package/src/components/OneOfframpWidget.tsx +660 -0
- package/src/components/OneOnrampWidget.tsx +596 -0
- package/src/components/OnePayWidget.tsx +160 -0
- package/src/components/OneReceiveWidget.tsx +272 -0
- package/src/components/OneSendWidget.tsx +248 -0
- package/src/components/OneSwapWidget.tsx +715 -0
- package/src/components/OneTransactionButton.tsx +150 -0
- package/src/components/OneWalletBalance.tsx +354 -0
- package/src/components/index.ts +24 -0
- package/src/config/index.ts +299 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useTokenPrice.ts +162 -0
- package/src/hooks/useWalletBalance.ts +98 -0
- package/src/index.ts +193 -0
- package/src/providers/OneProvider.tsx +452 -0
- package/src/providers/ThirdwebProvider.tsx +203 -0
- package/src/providers/index.ts +26 -0
- package/src/react-native.ts +378 -0
- package/src/services/engine.ts +1854 -0
- package/src/services/index.ts +30 -0
- package/src/services/price.ts +164 -0
- package/src/services/supabase.ts +180 -0
- package/src/types/index.ts +887 -0
- package/src/utils/index.ts +200 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +25 -0
|
@@ -0,0 +1,1755 @@
|
|
|
1
|
+
// src/config/index.ts
|
|
2
|
+
var config = null;
|
|
3
|
+
function initOneSDK(options) {
|
|
4
|
+
if (!options.oneEngineUrl) {
|
|
5
|
+
throw new Error("oneEngineUrl is required");
|
|
6
|
+
}
|
|
7
|
+
if (!options.oneClientId) {
|
|
8
|
+
throw new Error("oneClientId is required");
|
|
9
|
+
}
|
|
10
|
+
config = options;
|
|
11
|
+
}
|
|
12
|
+
function getConfig() {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error("ONE SDK not initialized. Call initOneSDK() first.");
|
|
15
|
+
}
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
var TOKEN_NAMES = {
|
|
19
|
+
ETH: "Ethereum",
|
|
20
|
+
BTC: "Bitcoin",
|
|
21
|
+
BNB: "BNB",
|
|
22
|
+
MATIC: "Polygon",
|
|
23
|
+
POL: "Polygon",
|
|
24
|
+
AVAX: "Avalanche",
|
|
25
|
+
USDT: "Tether",
|
|
26
|
+
USDC: "USD Coin",
|
|
27
|
+
DAI: "Dai",
|
|
28
|
+
WBTC: "Wrapped Bitcoin",
|
|
29
|
+
WETH: "Wrapped Ether",
|
|
30
|
+
ARB: "Arbitrum",
|
|
31
|
+
OP: "Optimism",
|
|
32
|
+
LINK: "Chainlink",
|
|
33
|
+
UNI: "Uniswap",
|
|
34
|
+
AAVE: "Aave",
|
|
35
|
+
CRV: "Curve",
|
|
36
|
+
MKR: "Maker",
|
|
37
|
+
SNX: "Synthetix",
|
|
38
|
+
COMP: "Compound",
|
|
39
|
+
SUSHI: "SushiSwap",
|
|
40
|
+
YFI: "Yearn Finance",
|
|
41
|
+
SOL: "Solana",
|
|
42
|
+
DOT: "Polkadot",
|
|
43
|
+
ATOM: "Cosmos",
|
|
44
|
+
NEAR: "Near Protocol"
|
|
45
|
+
};
|
|
46
|
+
var COINGECKO_IDS = {
|
|
47
|
+
ETH: "ethereum",
|
|
48
|
+
BTC: "bitcoin",
|
|
49
|
+
BNB: "binancecoin",
|
|
50
|
+
MATIC: "matic-network",
|
|
51
|
+
POL: "matic-network",
|
|
52
|
+
AVAX: "avalanche-2",
|
|
53
|
+
USDT: "tether",
|
|
54
|
+
USDC: "usd-coin",
|
|
55
|
+
DAI: "dai",
|
|
56
|
+
WBTC: "wrapped-bitcoin",
|
|
57
|
+
WETH: "weth",
|
|
58
|
+
ARB: "arbitrum",
|
|
59
|
+
OP: "optimism",
|
|
60
|
+
LINK: "chainlink",
|
|
61
|
+
UNI: "uniswap",
|
|
62
|
+
AAVE: "aave",
|
|
63
|
+
SOL: "solana"
|
|
64
|
+
};
|
|
65
|
+
var CHAIN_CONFIGS = {
|
|
66
|
+
ethereum: {
|
|
67
|
+
id: 1,
|
|
68
|
+
name: "Ethereum",
|
|
69
|
+
shortName: "ETH",
|
|
70
|
+
icon: "\u229F",
|
|
71
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
72
|
+
rpcUrls: ["https://ethereum.rpc.thirdweb.com"],
|
|
73
|
+
blockExplorerUrls: ["https://etherscan.io"],
|
|
74
|
+
testnet: false
|
|
75
|
+
},
|
|
76
|
+
polygon: {
|
|
77
|
+
id: 137,
|
|
78
|
+
name: "Polygon",
|
|
79
|
+
shortName: "MATIC",
|
|
80
|
+
icon: "\u{1F7E3}",
|
|
81
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
82
|
+
rpcUrls: ["https://polygon.rpc.thirdweb.com"],
|
|
83
|
+
blockExplorerUrls: ["https://polygonscan.com"],
|
|
84
|
+
testnet: false
|
|
85
|
+
},
|
|
86
|
+
base: {
|
|
87
|
+
id: 8453,
|
|
88
|
+
name: "Base",
|
|
89
|
+
shortName: "BASE",
|
|
90
|
+
icon: "\u{1F537}",
|
|
91
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
92
|
+
rpcUrls: ["https://base.rpc.thirdweb.com"],
|
|
93
|
+
blockExplorerUrls: ["https://basescan.org"],
|
|
94
|
+
testnet: false
|
|
95
|
+
},
|
|
96
|
+
arbitrum: {
|
|
97
|
+
id: 42161,
|
|
98
|
+
name: "Arbitrum One",
|
|
99
|
+
shortName: "ARB",
|
|
100
|
+
icon: "\u{1F535}",
|
|
101
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
102
|
+
rpcUrls: ["https://arbitrum.rpc.thirdweb.com"],
|
|
103
|
+
blockExplorerUrls: ["https://arbiscan.io"],
|
|
104
|
+
testnet: false
|
|
105
|
+
},
|
|
106
|
+
optimism: {
|
|
107
|
+
id: 10,
|
|
108
|
+
name: "Optimism",
|
|
109
|
+
shortName: "OP",
|
|
110
|
+
icon: "\u{1F534}",
|
|
111
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
112
|
+
rpcUrls: ["https://optimism.rpc.thirdweb.com"],
|
|
113
|
+
blockExplorerUrls: ["https://optimistic.etherscan.io"],
|
|
114
|
+
testnet: false
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/services/engine.ts
|
|
119
|
+
var OneEngineClient = class {
|
|
120
|
+
constructor(options) {
|
|
121
|
+
const config2 = getConfig();
|
|
122
|
+
this.baseUrl = options?.baseUrl || config2.oneEngineUrl;
|
|
123
|
+
this.clientId = options?.clientId || config2.oneClientId || "";
|
|
124
|
+
this.secretKey = options?.secretKey || config2.oneSecretKey;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Set access token for authenticated requests
|
|
128
|
+
*/
|
|
129
|
+
setAccessToken(token) {
|
|
130
|
+
this.accessToken = token;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Clear access token
|
|
134
|
+
*/
|
|
135
|
+
clearAccessToken() {
|
|
136
|
+
this.accessToken = void 0;
|
|
137
|
+
}
|
|
138
|
+
getHeaders(includeSecret = false) {
|
|
139
|
+
const headers = {
|
|
140
|
+
"Content-Type": "application/json",
|
|
141
|
+
"x-client-id": this.clientId
|
|
142
|
+
};
|
|
143
|
+
if (this.accessToken) {
|
|
144
|
+
headers["Authorization"] = `Bearer ${this.accessToken}`;
|
|
145
|
+
}
|
|
146
|
+
if (includeSecret && this.secretKey) {
|
|
147
|
+
headers["x-secret-key"] = this.secretKey;
|
|
148
|
+
}
|
|
149
|
+
return headers;
|
|
150
|
+
}
|
|
151
|
+
async request(endpoint, options = {}, includeSecret = false) {
|
|
152
|
+
try {
|
|
153
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
154
|
+
...options,
|
|
155
|
+
headers: {
|
|
156
|
+
...this.getHeaders(includeSecret),
|
|
157
|
+
...options.headers
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
const data = await response.json();
|
|
161
|
+
if (!response.ok) {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: {
|
|
165
|
+
code: data.error?.code || `HTTP_${response.status}`,
|
|
166
|
+
message: data.error?.message || "Request failed"
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
success: true,
|
|
172
|
+
data: data.data || data
|
|
173
|
+
};
|
|
174
|
+
} catch (error) {
|
|
175
|
+
return {
|
|
176
|
+
success: false,
|
|
177
|
+
error: {
|
|
178
|
+
code: "NETWORK_ERROR",
|
|
179
|
+
message: error instanceof Error ? error.message : "Network request failed"
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
// ===============================
|
|
185
|
+
// AUTH ENDPOINTS
|
|
186
|
+
// ===============================
|
|
187
|
+
/**
|
|
188
|
+
* Send OTP to email for authentication
|
|
189
|
+
*/
|
|
190
|
+
async sendEmailOtp(email) {
|
|
191
|
+
return this.request("/api/v1/auth/otp", {
|
|
192
|
+
method: "POST",
|
|
193
|
+
body: JSON.stringify({ email })
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Verify OTP and get access token
|
|
198
|
+
*/
|
|
199
|
+
async verifyEmailOtp(email, otp) {
|
|
200
|
+
return this.request("/api/v1/auth/otp/verify", {
|
|
201
|
+
method: "POST",
|
|
202
|
+
body: JSON.stringify({ email, otp })
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Authenticate with wallet signature
|
|
207
|
+
*/
|
|
208
|
+
async authWithWallet(walletAddress, signature, message) {
|
|
209
|
+
return this.request("/api/v1/auth/wallet", {
|
|
210
|
+
method: "POST",
|
|
211
|
+
body: JSON.stringify({ walletAddress, signature, message })
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Refresh access token
|
|
216
|
+
*/
|
|
217
|
+
async refreshToken(refreshToken) {
|
|
218
|
+
return this.request("/api/v1/auth/refresh", {
|
|
219
|
+
method: "POST",
|
|
220
|
+
body: JSON.stringify({ refreshToken })
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Get current user
|
|
225
|
+
*/
|
|
226
|
+
async getCurrentUser() {
|
|
227
|
+
return this.request("/api/v1/auth/me", { method: "GET" });
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Sign out
|
|
231
|
+
*/
|
|
232
|
+
async signOut() {
|
|
233
|
+
return this.request("/api/v1/auth/logout", { method: "POST" });
|
|
234
|
+
}
|
|
235
|
+
// ===============================
|
|
236
|
+
// WALLET/ASSETS ENDPOINTS
|
|
237
|
+
// ===============================
|
|
238
|
+
/**
|
|
239
|
+
* Get wallet balance across all chains
|
|
240
|
+
*/
|
|
241
|
+
async getWalletBalance(walletAddress, chains) {
|
|
242
|
+
const params = new URLSearchParams({ address: walletAddress });
|
|
243
|
+
if (chains?.length && chains.length > 0) {
|
|
244
|
+
params.set("chainId", chains[0].toString());
|
|
245
|
+
}
|
|
246
|
+
return this.request(`/api/v1/assets?${params}`, { method: "GET" });
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get portfolio summary
|
|
250
|
+
*/
|
|
251
|
+
async getPortfolioSummary(walletAddress) {
|
|
252
|
+
const params = new URLSearchParams({ address: walletAddress });
|
|
253
|
+
return this.request(`/api/v1/assets/portfolio?${params}`, { method: "GET" });
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get user's wallets
|
|
257
|
+
*/
|
|
258
|
+
async getUserWallets(chainId) {
|
|
259
|
+
const params = chainId ? `?chainId=${chainId}` : "";
|
|
260
|
+
return this.request(`/api/v1/wallet${params}`, { method: "GET" });
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Create a new wallet
|
|
264
|
+
*/
|
|
265
|
+
async createWallet(chainId = 8453, type = "smart") {
|
|
266
|
+
return this.request("/api/v1/wallet", {
|
|
267
|
+
method: "POST",
|
|
268
|
+
body: JSON.stringify({ chainId, type })
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get wallet transactions (placeholder - needs endpoint)
|
|
273
|
+
*/
|
|
274
|
+
async getWalletTransactions(walletAddress, options) {
|
|
275
|
+
const params = new URLSearchParams({ address: walletAddress });
|
|
276
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
277
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
278
|
+
if (options?.chainId) params.set("chainId", options.chainId.toString());
|
|
279
|
+
return this.request(`/api/v1/assets/transactions?${params}`, { method: "GET" });
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Send native token or ERC20
|
|
283
|
+
*/
|
|
284
|
+
async sendTransaction(request) {
|
|
285
|
+
return this.request("/api/v1/wallet/send", {
|
|
286
|
+
method: "POST",
|
|
287
|
+
body: JSON.stringify(request)
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Get transaction status
|
|
292
|
+
*/
|
|
293
|
+
async getTransactionStatus(txId) {
|
|
294
|
+
return this.request(`/api/v1/wallet/transaction/${txId}`, { method: "GET" });
|
|
295
|
+
}
|
|
296
|
+
// ===============================
|
|
297
|
+
// ONRAMP ENDPOINTS (Fiat-to-Crypto)
|
|
298
|
+
// ===============================
|
|
299
|
+
/**
|
|
300
|
+
* Get onramp quote
|
|
301
|
+
*/
|
|
302
|
+
async getOnrampQuote(fiatCurrency, fiatAmount, cryptoCurrency, paymentMethod) {
|
|
303
|
+
const params = new URLSearchParams({
|
|
304
|
+
fiatCurrency,
|
|
305
|
+
fiatAmount: fiatAmount.toString(),
|
|
306
|
+
cryptoCurrency
|
|
307
|
+
});
|
|
308
|
+
if (paymentMethod) params.set("paymentMethod", paymentMethod);
|
|
309
|
+
return this.request(`/api/v1/fiat/onramp/quote?${params}`, { method: "GET" });
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create onramp session (returns widget URL)
|
|
313
|
+
*/
|
|
314
|
+
async createOnrampSession(request) {
|
|
315
|
+
return this.request("/api/v1/fiat/onramp", {
|
|
316
|
+
method: "POST",
|
|
317
|
+
body: JSON.stringify({
|
|
318
|
+
fiatCurrency: request.fiatCurrency || "USD",
|
|
319
|
+
fiatAmount: request.fiatAmount || 100,
|
|
320
|
+
cryptoCurrency: request.cryptoCurrency || "ETH",
|
|
321
|
+
walletAddress: request.walletAddress,
|
|
322
|
+
chainId: 8453
|
|
323
|
+
// Default to Base
|
|
324
|
+
})
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get onramp session status
|
|
329
|
+
*/
|
|
330
|
+
async getOnrampStatus(sessionId) {
|
|
331
|
+
return this.request(`/api/v1/fiat/onramp/${sessionId}`, { method: "GET" });
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Get supported currencies (fiat + crypto)
|
|
335
|
+
*/
|
|
336
|
+
async getSupportedCurrencies() {
|
|
337
|
+
return this.request("/api/v1/fiat/onramp", { method: "GET" });
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get supported fiat currencies
|
|
341
|
+
*/
|
|
342
|
+
async getSupportedFiatCurrencies() {
|
|
343
|
+
const result = await this.getSupportedCurrencies();
|
|
344
|
+
if (result.success && result.data) {
|
|
345
|
+
return { success: true, data: result.data.fiatCurrencies };
|
|
346
|
+
}
|
|
347
|
+
return { success: false, error: result.error };
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Get supported payment methods
|
|
351
|
+
*/
|
|
352
|
+
async getSupportedPaymentMethods(country) {
|
|
353
|
+
return { success: true, data: ["card", "bank_transfer", "apple_pay", "google_pay"] };
|
|
354
|
+
}
|
|
355
|
+
// ===============================
|
|
356
|
+
// SWAP ENDPOINTS
|
|
357
|
+
// ===============================
|
|
358
|
+
/**
|
|
359
|
+
* Get swap quote
|
|
360
|
+
*/
|
|
361
|
+
async getSwapQuote(request) {
|
|
362
|
+
return this.request("/api/v1/swap/quote", {
|
|
363
|
+
method: "POST",
|
|
364
|
+
body: JSON.stringify(request)
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Execute swap
|
|
369
|
+
*/
|
|
370
|
+
async executeSwap(request) {
|
|
371
|
+
return this.request("/api/v1/swap/execute", {
|
|
372
|
+
method: "POST",
|
|
373
|
+
body: JSON.stringify(request)
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Get swap status
|
|
378
|
+
*/
|
|
379
|
+
async getSwapStatus(swapId) {
|
|
380
|
+
return this.request(`/api/v1/swap/${swapId}`, { method: "GET" });
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Get supported tokens for swap
|
|
384
|
+
*/
|
|
385
|
+
async getSupportedSwapTokens(chainId) {
|
|
386
|
+
const params = chainId ? `?chainId=${chainId}` : "";
|
|
387
|
+
return this.request(`/api/v1/swap/tokens${params}`, { method: "GET" });
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Get supported chains for swap
|
|
391
|
+
*/
|
|
392
|
+
async getSupportedSwapChains() {
|
|
393
|
+
return this.request("/api/v1/swap/chains", { method: "GET" });
|
|
394
|
+
}
|
|
395
|
+
// ===============================
|
|
396
|
+
// AI TRADING/QUANT ENDPOINTS
|
|
397
|
+
// ===============================
|
|
398
|
+
/**
|
|
399
|
+
* Get available AI trading strategies
|
|
400
|
+
*/
|
|
401
|
+
async getStrategies() {
|
|
402
|
+
return this.request("/api/v1/quant/strategies", { method: "GET" });
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Get strategy details
|
|
406
|
+
*/
|
|
407
|
+
async getStrategy(strategyId) {
|
|
408
|
+
return this.request(`/api/v1/quant/strategies/${strategyId}`, { method: "GET" });
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get user's positions
|
|
412
|
+
*/
|
|
413
|
+
async getPositions() {
|
|
414
|
+
return this.request("/api/v1/quant/positions", { method: "GET" });
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Create investment order
|
|
418
|
+
*/
|
|
419
|
+
async createOrder(strategyId, amount, currency) {
|
|
420
|
+
return this.request("/api/v1/trading/orders", {
|
|
421
|
+
method: "POST",
|
|
422
|
+
body: JSON.stringify({ strategyId, amount, currency })
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Get user's orders
|
|
427
|
+
*/
|
|
428
|
+
async getUserOrders() {
|
|
429
|
+
return this.request("/api/v1/trading/orders", { method: "GET" });
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Get user's portfolio stats from positions
|
|
433
|
+
*/
|
|
434
|
+
async getPortfolioStats() {
|
|
435
|
+
const positionsResult = await this.getPositions();
|
|
436
|
+
if (positionsResult.success && positionsResult.data) {
|
|
437
|
+
const positions = positionsResult.data;
|
|
438
|
+
const totalInvested = positions.reduce((sum, p) => sum + (p.investedAmount || 0), 0);
|
|
439
|
+
const totalValue = positions.reduce((sum, p) => sum + (p.currentValue || 0), 0);
|
|
440
|
+
const totalPnl = totalValue - totalInvested;
|
|
441
|
+
const totalPnlPercent = totalInvested > 0 ? totalPnl / totalInvested * 100 : 0;
|
|
442
|
+
return {
|
|
443
|
+
success: true,
|
|
444
|
+
data: {
|
|
445
|
+
totalInvested,
|
|
446
|
+
totalValue,
|
|
447
|
+
totalPnl,
|
|
448
|
+
totalPnlPercent,
|
|
449
|
+
activePositions: positions.filter((p) => p.status === "active").length
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return {
|
|
454
|
+
success: true,
|
|
455
|
+
data: { totalInvested: 0, totalValue: 0, totalPnl: 0, totalPnlPercent: 0, activePositions: 0 }
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
// ===============================
|
|
459
|
+
// MARKET/PRICE ENDPOINTS
|
|
460
|
+
// ===============================
|
|
461
|
+
/**
|
|
462
|
+
* Get token prices
|
|
463
|
+
*/
|
|
464
|
+
async getTokenPrices(symbols) {
|
|
465
|
+
const bybitSymbols = symbols.map((s) => {
|
|
466
|
+
const upper = s.toUpperCase();
|
|
467
|
+
if (upper.endsWith("USDT")) return upper;
|
|
468
|
+
return `${upper}USDT`;
|
|
469
|
+
});
|
|
470
|
+
const result = await this.request(
|
|
471
|
+
`/api/v1/trading/market?symbols=${bybitSymbols.join(",")}`,
|
|
472
|
+
{ method: "GET" }
|
|
473
|
+
);
|
|
474
|
+
if (result.success && result.data?.markets) {
|
|
475
|
+
const prices = {};
|
|
476
|
+
for (const market of result.data.markets) {
|
|
477
|
+
const symbol = market.symbol?.replace("USDT", "") || "";
|
|
478
|
+
prices[symbol] = {
|
|
479
|
+
price: parseFloat(market.lastPrice) || 0,
|
|
480
|
+
change24h: parseFloat(market.price24hPcnt) * 100 || 0,
|
|
481
|
+
marketCap: void 0
|
|
482
|
+
// Bybit doesn't provide this
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
return { success: true, data: prices };
|
|
486
|
+
}
|
|
487
|
+
return { success: false, error: result.error };
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Get market data overview
|
|
491
|
+
*/
|
|
492
|
+
async getMarketData() {
|
|
493
|
+
const result = await this.request("/api/v1/trading/market", { method: "GET" });
|
|
494
|
+
if (result.success && result.data?.markets) {
|
|
495
|
+
return {
|
|
496
|
+
success: true,
|
|
497
|
+
data: {
|
|
498
|
+
totalMarketCap: 0,
|
|
499
|
+
// Would need separate API
|
|
500
|
+
totalVolume24h: result.data.markets.reduce((sum, m) => sum + (parseFloat(m.volume24h) || 0), 0),
|
|
501
|
+
btcDominance: 0,
|
|
502
|
+
// Would need separate API
|
|
503
|
+
markets: result.data.markets
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
return { success: false, error: result.error };
|
|
508
|
+
}
|
|
509
|
+
// ===============================
|
|
510
|
+
// NFT ENDPOINTS
|
|
511
|
+
// ===============================
|
|
512
|
+
/**
|
|
513
|
+
* Get user's NFTs
|
|
514
|
+
*/
|
|
515
|
+
async getUserNFTs(walletAddress, options) {
|
|
516
|
+
const params = new URLSearchParams({ address: walletAddress });
|
|
517
|
+
if (options?.chainId) params.set("chainId", options.chainId.toString());
|
|
518
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
519
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
520
|
+
return this.request(`/api/v1/assets/nfts?${params}`, { method: "GET" });
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Get NFT details
|
|
524
|
+
*/
|
|
525
|
+
async getNFTDetails(contractAddress, tokenId, chainId) {
|
|
526
|
+
return this.request(`/api/v1/assets/nfts/${contractAddress}/${tokenId}?chainId=${chainId}`, { method: "GET" });
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Get NFT collection
|
|
530
|
+
*/
|
|
531
|
+
async getNFTCollection(contractAddress, chainId) {
|
|
532
|
+
return this.request(`/api/v1/assets/nfts/collection/${contractAddress}?chainId=${chainId}`, { method: "GET" });
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Transfer NFT
|
|
536
|
+
*/
|
|
537
|
+
async transferNFT(params) {
|
|
538
|
+
return this.request("/api/v1/assets/nfts/transfer", {
|
|
539
|
+
method: "POST",
|
|
540
|
+
body: JSON.stringify(params)
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
// ===============================
|
|
544
|
+
// CONTRACT ENDPOINTS
|
|
545
|
+
// ===============================
|
|
546
|
+
/**
|
|
547
|
+
* Get user's contracts
|
|
548
|
+
*/
|
|
549
|
+
async getUserContracts(options) {
|
|
550
|
+
const params = new URLSearchParams();
|
|
551
|
+
if (options?.chainId) params.set("chainId", options.chainId.toString());
|
|
552
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
553
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
554
|
+
return this.request(`/api/v1/contracts?${params}`, { method: "GET" });
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Get contract details
|
|
558
|
+
*/
|
|
559
|
+
async getContractDetails(address, chainId) {
|
|
560
|
+
return this.request(`/api/v1/contracts/${address}?chainId=${chainId}`, { method: "GET" });
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Read contract (call view function)
|
|
564
|
+
*/
|
|
565
|
+
async readContract(params) {
|
|
566
|
+
return this.request("/api/v1/contracts/read", {
|
|
567
|
+
method: "POST",
|
|
568
|
+
body: JSON.stringify(params)
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Write to contract (execute transaction)
|
|
573
|
+
*/
|
|
574
|
+
async writeContract(params) {
|
|
575
|
+
return this.request("/api/v1/contracts/write", {
|
|
576
|
+
method: "POST",
|
|
577
|
+
body: JSON.stringify(params)
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Deploy contract
|
|
582
|
+
*/
|
|
583
|
+
async deployContract(params) {
|
|
584
|
+
return this.request("/api/v1/contracts/deploy", {
|
|
585
|
+
method: "POST",
|
|
586
|
+
body: JSON.stringify(params)
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
// ===============================
|
|
590
|
+
// OFFRAMP ENDPOINTS (Crypto-to-Fiat)
|
|
591
|
+
// ===============================
|
|
592
|
+
/**
|
|
593
|
+
* Get offramp quote
|
|
594
|
+
*/
|
|
595
|
+
async getOfframpQuote(cryptoCurrency, cryptoAmount, fiatCurrency, payoutMethod) {
|
|
596
|
+
const params = new URLSearchParams({
|
|
597
|
+
cryptoCurrency,
|
|
598
|
+
cryptoAmount: cryptoAmount.toString(),
|
|
599
|
+
fiatCurrency
|
|
600
|
+
});
|
|
601
|
+
if (payoutMethod) params.set("payoutMethod", payoutMethod);
|
|
602
|
+
return this.request(`/api/v1/fiat/offramp/quote?${params}`, { method: "GET" });
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Create offramp transaction
|
|
606
|
+
*/
|
|
607
|
+
async createOfframpTransaction(request) {
|
|
608
|
+
return this.request("/api/v1/fiat/offramp", {
|
|
609
|
+
method: "POST",
|
|
610
|
+
body: JSON.stringify(request)
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Get offramp transaction status
|
|
615
|
+
*/
|
|
616
|
+
async getOfframpStatus(transactionId) {
|
|
617
|
+
return this.request(`/api/v1/fiat/offramp/${transactionId}`, { method: "GET" });
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get supported payout methods
|
|
621
|
+
*/
|
|
622
|
+
async getSupportedPayoutMethods(country) {
|
|
623
|
+
const params = country ? `?country=${country}` : "";
|
|
624
|
+
return this.request(`/api/v1/fiat/offramp/methods${params}`, { method: "GET" });
|
|
625
|
+
}
|
|
626
|
+
// ===============================
|
|
627
|
+
// BILL PAYMENT ENDPOINTS
|
|
628
|
+
// ===============================
|
|
629
|
+
/**
|
|
630
|
+
* Get bill providers
|
|
631
|
+
*/
|
|
632
|
+
async getBillProviders(country, category) {
|
|
633
|
+
const params = new URLSearchParams();
|
|
634
|
+
if (country) params.set("country", country);
|
|
635
|
+
if (category) params.set("category", category);
|
|
636
|
+
return this.request(`/api/v1/bills/providers?${params}`, { method: "GET" });
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Get bill details/validate account
|
|
640
|
+
*/
|
|
641
|
+
async validateBillAccount(providerId, accountNumber) {
|
|
642
|
+
return this.request("/api/v1/bills/validate", {
|
|
643
|
+
method: "POST",
|
|
644
|
+
body: JSON.stringify({ providerId, accountNumber })
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Pay bill
|
|
649
|
+
*/
|
|
650
|
+
async payBill(params) {
|
|
651
|
+
return this.request("/api/v1/bills/pay", {
|
|
652
|
+
method: "POST",
|
|
653
|
+
body: JSON.stringify(params)
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Get bill payment history
|
|
658
|
+
*/
|
|
659
|
+
async getBillHistory(options) {
|
|
660
|
+
const params = new URLSearchParams();
|
|
661
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
662
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
663
|
+
return this.request(`/api/v1/bills/history?${params}`, { method: "GET" });
|
|
664
|
+
}
|
|
665
|
+
// ===============================
|
|
666
|
+
// STAKING ENDPOINTS
|
|
667
|
+
// ===============================
|
|
668
|
+
/**
|
|
669
|
+
* Get staking pools
|
|
670
|
+
*/
|
|
671
|
+
async getStakingPools(chainId) {
|
|
672
|
+
const params = chainId ? `?chainId=${chainId}` : "";
|
|
673
|
+
return this.request(`/api/v1/staking/pools${params}`, { method: "GET" });
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Get user's staking positions
|
|
677
|
+
*/
|
|
678
|
+
async getStakingPositions() {
|
|
679
|
+
return this.request("/api/v1/staking/positions", { method: "GET" });
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Stake tokens
|
|
683
|
+
*/
|
|
684
|
+
async stake(params) {
|
|
685
|
+
return this.request("/api/v1/staking/stake", {
|
|
686
|
+
method: "POST",
|
|
687
|
+
body: JSON.stringify(params)
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
/**
|
|
691
|
+
* Unstake tokens
|
|
692
|
+
*/
|
|
693
|
+
async unstake(params) {
|
|
694
|
+
return this.request("/api/v1/staking/unstake", {
|
|
695
|
+
method: "POST",
|
|
696
|
+
body: JSON.stringify(params)
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Claim staking rewards
|
|
701
|
+
*/
|
|
702
|
+
async claimStakingRewards(positionId) {
|
|
703
|
+
return this.request("/api/v1/staking/claim", {
|
|
704
|
+
method: "POST",
|
|
705
|
+
body: JSON.stringify({ positionId })
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
// ===============================
|
|
709
|
+
// USER PROFILE ENDPOINTS
|
|
710
|
+
// ===============================
|
|
711
|
+
/**
|
|
712
|
+
* Get user profile
|
|
713
|
+
*/
|
|
714
|
+
async getUserProfile() {
|
|
715
|
+
return this.request("/api/v1/user/profile", { method: "GET" });
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Update user profile
|
|
719
|
+
*/
|
|
720
|
+
async updateUserProfile(updates) {
|
|
721
|
+
return this.request("/api/v1/user/profile", {
|
|
722
|
+
method: "PATCH",
|
|
723
|
+
body: JSON.stringify(updates)
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
/**
|
|
727
|
+
* Get user settings
|
|
728
|
+
*/
|
|
729
|
+
async getUserSettings() {
|
|
730
|
+
return this.request("/api/v1/user/settings", { method: "GET" });
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Update user settings
|
|
734
|
+
*/
|
|
735
|
+
async updateUserSettings(updates) {
|
|
736
|
+
return this.request("/api/v1/user/settings", {
|
|
737
|
+
method: "PATCH",
|
|
738
|
+
body: JSON.stringify(updates)
|
|
739
|
+
});
|
|
740
|
+
}
|
|
741
|
+
// ===============================
|
|
742
|
+
// NOTIFICATION ENDPOINTS
|
|
743
|
+
// ===============================
|
|
744
|
+
/**
|
|
745
|
+
* Get notifications
|
|
746
|
+
*/
|
|
747
|
+
async getNotifications(options) {
|
|
748
|
+
const params = new URLSearchParams();
|
|
749
|
+
if (options?.unreadOnly) params.set("unreadOnly", "true");
|
|
750
|
+
if (options?.limit) params.set("limit", options.limit.toString());
|
|
751
|
+
if (options?.offset) params.set("offset", options.offset.toString());
|
|
752
|
+
return this.request(`/api/v1/notifications?${params}`, { method: "GET" });
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Mark notification as read
|
|
756
|
+
*/
|
|
757
|
+
async markNotificationRead(notificationId) {
|
|
758
|
+
return this.request(`/api/v1/notifications/${notificationId}/read`, { method: "POST" });
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Mark all notifications as read
|
|
762
|
+
*/
|
|
763
|
+
async markAllNotificationsRead() {
|
|
764
|
+
return this.request("/api/v1/notifications/read-all", { method: "POST" });
|
|
765
|
+
}
|
|
766
|
+
// ===============================
|
|
767
|
+
// REFERRAL ENDPOINTS
|
|
768
|
+
// ===============================
|
|
769
|
+
/**
|
|
770
|
+
* Get referral info
|
|
771
|
+
*/
|
|
772
|
+
async getReferralInfo() {
|
|
773
|
+
return this.request("/api/v1/referral", { method: "GET" });
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Get referred users
|
|
777
|
+
*/
|
|
778
|
+
async getReferrals() {
|
|
779
|
+
return this.request("/api/v1/referral/list", { method: "GET" });
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Apply referral code
|
|
783
|
+
*/
|
|
784
|
+
async applyReferralCode(code) {
|
|
785
|
+
return this.request("/api/v1/referral/apply", {
|
|
786
|
+
method: "POST",
|
|
787
|
+
body: JSON.stringify({ code })
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Claim referral rewards
|
|
792
|
+
*/
|
|
793
|
+
async claimReferralRewards() {
|
|
794
|
+
return this.request("/api/v1/referral/claim", { method: "POST" });
|
|
795
|
+
}
|
|
796
|
+
// ===============================
|
|
797
|
+
// KYC ENDPOINTS
|
|
798
|
+
// ===============================
|
|
799
|
+
/**
|
|
800
|
+
* Get KYC status
|
|
801
|
+
*/
|
|
802
|
+
async getKycStatus() {
|
|
803
|
+
return this.request("/api/v1/kyc/status", { method: "GET" });
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Start KYC verification
|
|
807
|
+
*/
|
|
808
|
+
async startKycVerification(level) {
|
|
809
|
+
return this.request("/api/v1/kyc/start", {
|
|
810
|
+
method: "POST",
|
|
811
|
+
body: JSON.stringify({ level })
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
/**
|
|
815
|
+
* Submit KYC documents
|
|
816
|
+
*/
|
|
817
|
+
async submitKycDocuments(params) {
|
|
818
|
+
return this.request("/api/v1/kyc/submit", {
|
|
819
|
+
method: "POST",
|
|
820
|
+
body: JSON.stringify(params)
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
// ===============================
|
|
824
|
+
// BRIDGE ENDPOINTS
|
|
825
|
+
// ===============================
|
|
826
|
+
/**
|
|
827
|
+
* Get bridge quote
|
|
828
|
+
*/
|
|
829
|
+
async getBridgeQuote(params) {
|
|
830
|
+
return this.request("/api/v1/bridge/quote", {
|
|
831
|
+
method: "POST",
|
|
832
|
+
body: JSON.stringify(params)
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Execute bridge transaction
|
|
837
|
+
*/
|
|
838
|
+
async executeBridge(params) {
|
|
839
|
+
return this.request("/api/v1/bridge/execute", {
|
|
840
|
+
method: "POST",
|
|
841
|
+
body: JSON.stringify(params)
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Get bridge transaction status
|
|
846
|
+
*/
|
|
847
|
+
async getBridgeStatus(bridgeId) {
|
|
848
|
+
return this.request(`/api/v1/bridge/${bridgeId}`, { method: "GET" });
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Get supported bridge routes
|
|
852
|
+
*/
|
|
853
|
+
async getSupportedBridgeRoutes() {
|
|
854
|
+
return this.request("/api/v1/bridge/routes", { method: "GET" });
|
|
855
|
+
}
|
|
856
|
+
// ===============================
|
|
857
|
+
// GAS ENDPOINTS
|
|
858
|
+
// ===============================
|
|
859
|
+
/**
|
|
860
|
+
* Get gas estimate for transaction
|
|
861
|
+
*/
|
|
862
|
+
async getGasEstimate(params) {
|
|
863
|
+
return this.request("/api/v1/gas/estimate", {
|
|
864
|
+
method: "POST",
|
|
865
|
+
body: JSON.stringify(params)
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Get current gas prices for chain
|
|
870
|
+
*/
|
|
871
|
+
async getGasPrice(chainId) {
|
|
872
|
+
return this.request(`/api/v1/gas/price?chainId=${chainId}`, { method: "GET" });
|
|
873
|
+
}
|
|
874
|
+
// ===============================
|
|
875
|
+
// WALLET IMPORT/EXPORT ENDPOINTS
|
|
876
|
+
// ===============================
|
|
877
|
+
/**
|
|
878
|
+
* Import wallet from private key or mnemonic
|
|
879
|
+
*/
|
|
880
|
+
async importWallet(request) {
|
|
881
|
+
return this.request("/api/v1/wallet/import", {
|
|
882
|
+
method: "POST",
|
|
883
|
+
body: JSON.stringify(request)
|
|
884
|
+
}, true);
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Export wallet (get encrypted private key)
|
|
888
|
+
* Requires additional authentication
|
|
889
|
+
*/
|
|
890
|
+
async exportWallet(walletId, pin) {
|
|
891
|
+
return this.request("/api/v1/wallet/export", {
|
|
892
|
+
method: "POST",
|
|
893
|
+
body: JSON.stringify({ walletId, pin })
|
|
894
|
+
}, true);
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Generate new mnemonic phrase
|
|
898
|
+
*/
|
|
899
|
+
async generateMnemonic() {
|
|
900
|
+
return this.request("/api/v1/wallet/generate-mnemonic", { method: "POST" }, true);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Validate mnemonic phrase
|
|
904
|
+
*/
|
|
905
|
+
async validateMnemonic(mnemonic) {
|
|
906
|
+
return this.request("/api/v1/wallet/validate-mnemonic", {
|
|
907
|
+
method: "POST",
|
|
908
|
+
body: JSON.stringify({ mnemonic })
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
// ===============================
|
|
912
|
+
// PORTFOLIO ANALYTICS ENDPOINTS
|
|
913
|
+
// ===============================
|
|
914
|
+
/**
|
|
915
|
+
* Get portfolio analytics with historical data
|
|
916
|
+
*/
|
|
917
|
+
async getPortfolioAnalytics(walletAddress, period = "30d") {
|
|
918
|
+
const params = new URLSearchParams({ address: walletAddress, period });
|
|
919
|
+
return this.request(`/api/v1/analytics/portfolio?${params}`, { method: "GET" });
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
922
|
+
* Get transaction analytics
|
|
923
|
+
*/
|
|
924
|
+
async getTransactionAnalytics(walletAddress, period = "30d") {
|
|
925
|
+
const params = new URLSearchParams({ address: walletAddress, period });
|
|
926
|
+
return this.request(`/api/v1/analytics/transactions?${params}`, { method: "GET" });
|
|
927
|
+
}
|
|
928
|
+
// ===============================
|
|
929
|
+
// ADVANCED TRADING ENDPOINTS
|
|
930
|
+
// ===============================
|
|
931
|
+
/**
|
|
932
|
+
* Create limit order
|
|
933
|
+
*/
|
|
934
|
+
async createLimitOrder(params) {
|
|
935
|
+
return this.request("/api/v1/trading/limit-orders", {
|
|
936
|
+
method: "POST",
|
|
937
|
+
body: JSON.stringify(params)
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get user's limit orders
|
|
942
|
+
*/
|
|
943
|
+
async getLimitOrders(status) {
|
|
944
|
+
const params = status ? `?status=${status}` : "";
|
|
945
|
+
return this.request(`/api/v1/trading/limit-orders${params}`, { method: "GET" });
|
|
946
|
+
}
|
|
947
|
+
/**
|
|
948
|
+
* Cancel limit order
|
|
949
|
+
*/
|
|
950
|
+
async cancelLimitOrder(orderId) {
|
|
951
|
+
return this.request(`/api/v1/trading/limit-orders/${orderId}`, { method: "DELETE" });
|
|
952
|
+
}
|
|
953
|
+
/**
|
|
954
|
+
* Set price alert
|
|
955
|
+
*/
|
|
956
|
+
async setPriceAlert(params) {
|
|
957
|
+
return this.request("/api/v1/trading/alerts", {
|
|
958
|
+
method: "POST",
|
|
959
|
+
body: JSON.stringify(params)
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Get price alerts
|
|
964
|
+
*/
|
|
965
|
+
async getPriceAlerts() {
|
|
966
|
+
return this.request("/api/v1/trading/alerts", { method: "GET" });
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Delete price alert
|
|
970
|
+
*/
|
|
971
|
+
async deletePriceAlert(alertId) {
|
|
972
|
+
return this.request(`/api/v1/trading/alerts/${alertId}`, { method: "DELETE" });
|
|
973
|
+
}
|
|
974
|
+
// ===============================
|
|
975
|
+
// SESSION MANAGEMENT
|
|
976
|
+
// ===============================
|
|
977
|
+
/**
|
|
978
|
+
* Get active sessions
|
|
979
|
+
*/
|
|
980
|
+
async getActiveSessions() {
|
|
981
|
+
return this.request("/api/v1/auth/sessions", { method: "GET" });
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
* Revoke session
|
|
985
|
+
*/
|
|
986
|
+
async revokeSession(sessionId) {
|
|
987
|
+
return this.request(`/api/v1/auth/sessions/${sessionId}`, { method: "DELETE" });
|
|
988
|
+
}
|
|
989
|
+
/**
|
|
990
|
+
* Revoke all other sessions
|
|
991
|
+
*/
|
|
992
|
+
async revokeAllOtherSessions() {
|
|
993
|
+
return this.request("/api/v1/auth/sessions/revoke-all", { method: "POST" });
|
|
994
|
+
}
|
|
995
|
+
// ========== Webhooks ==========
|
|
996
|
+
/**
|
|
997
|
+
* List webhooks for the project
|
|
998
|
+
*/
|
|
999
|
+
async listWebhooks(options) {
|
|
1000
|
+
const params = new URLSearchParams();
|
|
1001
|
+
if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
|
|
1002
|
+
const query = params.toString();
|
|
1003
|
+
return this.request(`/api/v1/webhooks${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* Get webhook by ID
|
|
1007
|
+
*/
|
|
1008
|
+
async getWebhook(webhookId) {
|
|
1009
|
+
return this.request(`/api/v1/webhooks/${webhookId}`, { method: "GET" });
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Create a webhook
|
|
1013
|
+
*/
|
|
1014
|
+
async createWebhook(input) {
|
|
1015
|
+
return this.request("/api/v1/webhooks", {
|
|
1016
|
+
method: "POST",
|
|
1017
|
+
body: JSON.stringify(input)
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Update a webhook
|
|
1022
|
+
*/
|
|
1023
|
+
async updateWebhook(webhookId, input) {
|
|
1024
|
+
return this.request(`/api/v1/webhooks/${webhookId}`, {
|
|
1025
|
+
method: "PATCH",
|
|
1026
|
+
body: JSON.stringify(input)
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Delete a webhook
|
|
1031
|
+
*/
|
|
1032
|
+
async deleteWebhook(webhookId) {
|
|
1033
|
+
return this.request(`/api/v1/webhooks/${webhookId}`, { method: "DELETE" });
|
|
1034
|
+
}
|
|
1035
|
+
/**
|
|
1036
|
+
* Get webhook deliveries
|
|
1037
|
+
*/
|
|
1038
|
+
async getWebhookDeliveries(webhookId, options) {
|
|
1039
|
+
const params = new URLSearchParams();
|
|
1040
|
+
if (options?.status) params.set("status", options.status);
|
|
1041
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1042
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
1043
|
+
const query = params.toString();
|
|
1044
|
+
return this.request(`/api/v1/webhooks/${webhookId}/deliveries${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Test a webhook
|
|
1048
|
+
*/
|
|
1049
|
+
async testWebhook(webhookId) {
|
|
1050
|
+
return this.request(`/api/v1/webhooks/${webhookId}/test`, { method: "POST" });
|
|
1051
|
+
}
|
|
1052
|
+
// ========== Admin (requires admin role) ==========
|
|
1053
|
+
/**
|
|
1054
|
+
* List all users (admin only)
|
|
1055
|
+
*/
|
|
1056
|
+
async adminListUsers(options) {
|
|
1057
|
+
const params = new URLSearchParams();
|
|
1058
|
+
if (options?.page) params.set("page", String(options.page));
|
|
1059
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1060
|
+
if (options?.search) params.set("search", options.search);
|
|
1061
|
+
if (options?.sortBy) params.set("sortBy", options.sortBy);
|
|
1062
|
+
if (options?.sortOrder) params.set("sortOrder", options.sortOrder);
|
|
1063
|
+
if (options?.role) params.set("role", options.role);
|
|
1064
|
+
if (options?.kycStatus) params.set("kycStatus", options.kycStatus);
|
|
1065
|
+
if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
|
|
1066
|
+
const query = params.toString();
|
|
1067
|
+
return this.request(`/api/v1/admin/users${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1068
|
+
}
|
|
1069
|
+
/**
|
|
1070
|
+
* Get user by ID (admin only)
|
|
1071
|
+
*/
|
|
1072
|
+
async adminGetUser(userId) {
|
|
1073
|
+
return this.request(`/api/v1/admin/users/${userId}`, { method: "GET" });
|
|
1074
|
+
}
|
|
1075
|
+
/**
|
|
1076
|
+
* Update user (admin only)
|
|
1077
|
+
*/
|
|
1078
|
+
async adminUpdateUser(userId, data) {
|
|
1079
|
+
return this.request(`/api/v1/admin/users/${userId}`, {
|
|
1080
|
+
method: "PATCH",
|
|
1081
|
+
body: JSON.stringify(data)
|
|
1082
|
+
});
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* List all projects (admin only)
|
|
1086
|
+
*/
|
|
1087
|
+
async adminListProjects(options) {
|
|
1088
|
+
const params = new URLSearchParams();
|
|
1089
|
+
if (options?.page) params.set("page", String(options.page));
|
|
1090
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1091
|
+
if (options?.search) params.set("search", options.search);
|
|
1092
|
+
if (options?.sortBy) params.set("sortBy", options.sortBy);
|
|
1093
|
+
if (options?.sortOrder) params.set("sortOrder", options.sortOrder);
|
|
1094
|
+
if (options?.isActive !== void 0) params.set("isActive", String(options.isActive));
|
|
1095
|
+
const query = params.toString();
|
|
1096
|
+
return this.request(`/api/v1/admin/projects${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1097
|
+
}
|
|
1098
|
+
/**
|
|
1099
|
+
* Get project by ID (admin only)
|
|
1100
|
+
*/
|
|
1101
|
+
async adminGetProject(projectId) {
|
|
1102
|
+
return this.request(`/api/v1/admin/projects/${projectId}`, { method: "GET" });
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Update project (admin only)
|
|
1106
|
+
*/
|
|
1107
|
+
async adminUpdateProject(projectId, data) {
|
|
1108
|
+
return this.request(`/api/v1/admin/projects/${projectId}`, {
|
|
1109
|
+
method: "PATCH",
|
|
1110
|
+
body: JSON.stringify(data)
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Regenerate project API key (admin only)
|
|
1115
|
+
*/
|
|
1116
|
+
async adminRegenerateApiKey(projectId) {
|
|
1117
|
+
return this.request(`/api/v1/admin/projects/${projectId}/regenerate-key`, { method: "POST" });
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Get system statistics (admin only)
|
|
1121
|
+
*/
|
|
1122
|
+
async adminGetStats(days) {
|
|
1123
|
+
const query = days ? `?days=${days}` : "";
|
|
1124
|
+
return this.request(`/api/v1/admin/stats${query}`, { method: "GET" });
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Get system logs (admin only)
|
|
1128
|
+
*/
|
|
1129
|
+
async adminGetLogs(options) {
|
|
1130
|
+
const params = new URLSearchParams();
|
|
1131
|
+
if (options?.level) params.set("level", options.level);
|
|
1132
|
+
if (options?.service) params.set("service", options.service);
|
|
1133
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1134
|
+
if (options?.offset) params.set("offset", String(options.offset));
|
|
1135
|
+
if (options?.startDate) params.set("startDate", options.startDate);
|
|
1136
|
+
if (options?.endDate) params.set("endDate", options.endDate);
|
|
1137
|
+
const query = params.toString();
|
|
1138
|
+
return this.request(`/api/v1/admin/logs${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1139
|
+
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Get rate limit status (admin only)
|
|
1142
|
+
*/
|
|
1143
|
+
async adminGetRateLimits(options) {
|
|
1144
|
+
const params = new URLSearchParams();
|
|
1145
|
+
if (options?.identifier) params.set("identifier", options.identifier);
|
|
1146
|
+
if (options?.limit) params.set("limit", String(options.limit));
|
|
1147
|
+
const query = params.toString();
|
|
1148
|
+
return this.request(`/api/v1/admin/rate-limits${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1149
|
+
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Clear rate limits for an identifier (admin only)
|
|
1152
|
+
*/
|
|
1153
|
+
async adminClearRateLimits(identifier) {
|
|
1154
|
+
return this.request(`/api/v1/admin/rate-limits/${identifier}`, { method: "DELETE" });
|
|
1155
|
+
}
|
|
1156
|
+
// ========== AI Quant Trading ==========
|
|
1157
|
+
/**
|
|
1158
|
+
* Get all AI trading strategies
|
|
1159
|
+
*/
|
|
1160
|
+
async getAIStrategies(filters) {
|
|
1161
|
+
const params = new URLSearchParams();
|
|
1162
|
+
if (filters?.category) params.set("category", filters.category);
|
|
1163
|
+
if (filters?.riskLevel) params.set("risk_level", String(filters.riskLevel));
|
|
1164
|
+
if (filters?.minTvl) params.set("min_tvl", String(filters.minTvl));
|
|
1165
|
+
if (filters?.isActive !== void 0) params.set("is_active", String(filters.isActive));
|
|
1166
|
+
const query = params.toString();
|
|
1167
|
+
return this.request(`/api/v1/ai-quant/strategies${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Get AI strategy details
|
|
1171
|
+
*/
|
|
1172
|
+
async getAIStrategy(strategyId, include) {
|
|
1173
|
+
const params = new URLSearchParams();
|
|
1174
|
+
if (include?.length) params.set("include", include.join(","));
|
|
1175
|
+
const query = params.toString();
|
|
1176
|
+
return this.request(`/api/v1/ai-quant/strategies/${strategyId}${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Get strategy performance history
|
|
1180
|
+
*/
|
|
1181
|
+
async getAIStrategyPerformance(strategyId, days = 30) {
|
|
1182
|
+
return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=performance&days=${days}`, { method: "GET" });
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Get real-time market data for strategy pairs
|
|
1186
|
+
*/
|
|
1187
|
+
async getAIStrategyMarketData(strategyId) {
|
|
1188
|
+
return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=market`, { method: "GET" });
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Create AI trading order
|
|
1192
|
+
*/
|
|
1193
|
+
async createAIOrder(request) {
|
|
1194
|
+
return this.request("/api/v1/ai-quant/orders", {
|
|
1195
|
+
method: "POST",
|
|
1196
|
+
body: JSON.stringify(request)
|
|
1197
|
+
});
|
|
1198
|
+
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Get user's AI orders
|
|
1201
|
+
*/
|
|
1202
|
+
async getAIOrders(filters) {
|
|
1203
|
+
const params = new URLSearchParams();
|
|
1204
|
+
if (filters?.strategyId) params.set("strategy_id", filters.strategyId);
|
|
1205
|
+
if (filters?.status) params.set("status", filters.status);
|
|
1206
|
+
const query = params.toString();
|
|
1207
|
+
return this.request(`/api/v1/ai-quant/orders${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* Get AI order details
|
|
1211
|
+
*/
|
|
1212
|
+
async getAIOrder(orderId) {
|
|
1213
|
+
return this.request(`/api/v1/ai-quant/orders/${orderId}`, { method: "GET" });
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Pause AI order
|
|
1217
|
+
*/
|
|
1218
|
+
async pauseAIOrder(orderId) {
|
|
1219
|
+
return this.request(`/api/v1/ai-quant/orders/${orderId}/pause`, { method: "POST" });
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Resume AI order
|
|
1223
|
+
*/
|
|
1224
|
+
async resumeAIOrder(orderId) {
|
|
1225
|
+
return this.request(`/api/v1/ai-quant/orders/${orderId}/resume`, { method: "POST" });
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Request redemption for AI order
|
|
1229
|
+
*/
|
|
1230
|
+
async redeemAIOrder(orderId) {
|
|
1231
|
+
return this.request(`/api/v1/ai-quant/orders/${orderId}/redeem`, { method: "POST" });
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Get AI portfolio summary
|
|
1235
|
+
*/
|
|
1236
|
+
async getAIPortfolio(include) {
|
|
1237
|
+
const params = new URLSearchParams();
|
|
1238
|
+
if (include?.length) params.set("include", include.join(","));
|
|
1239
|
+
const query = params.toString();
|
|
1240
|
+
return this.request(`/api/v1/ai-quant/portfolio${query ? `?${query}` : ""}`, { method: "GET" });
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Get user's trade allocations
|
|
1244
|
+
*/
|
|
1245
|
+
async getAITradeAllocations(limit = 50) {
|
|
1246
|
+
return this.request(`/api/v1/ai-quant/portfolio?include=allocations&limit=${limit}`, { method: "GET" });
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Get trade history for a strategy
|
|
1250
|
+
*/
|
|
1251
|
+
async getAITradeHistory(strategyId, limit = 50) {
|
|
1252
|
+
return this.request(`/api/v1/ai-quant/strategies/${strategyId}?include=trades&limit=${limit}`, { method: "GET" });
|
|
1253
|
+
}
|
|
1254
|
+
/**
|
|
1255
|
+
* Execute AI signals for a strategy (admin only)
|
|
1256
|
+
*/
|
|
1257
|
+
async executeAISignals(strategyId) {
|
|
1258
|
+
return this.request("/api/v1/ai-quant/execute", {
|
|
1259
|
+
method: "POST",
|
|
1260
|
+
body: JSON.stringify({ strategyId })
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
// ========== Free Price APIs (No API Key Required) ==========
|
|
1264
|
+
/**
|
|
1265
|
+
* Get cryptocurrency prices (FREE - uses CoinGecko/Binance/CoinCap)
|
|
1266
|
+
*/
|
|
1267
|
+
async getCryptoPrices(symbols) {
|
|
1268
|
+
return this.request(`/api/v1/prices?symbols=${symbols.join(",")}`, { method: "GET" });
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Get single cryptocurrency price (FREE)
|
|
1272
|
+
*/
|
|
1273
|
+
async getCryptoPrice(symbol) {
|
|
1274
|
+
return this.request(`/api/v1/prices/${symbol}`, { method: "GET" });
|
|
1275
|
+
}
|
|
1276
|
+
/**
|
|
1277
|
+
* Get OHLCV candles for charting (FREE - from Binance)
|
|
1278
|
+
*/
|
|
1279
|
+
async getCryptoCandles(symbol, interval = "1h", limit = 100) {
|
|
1280
|
+
return this.request(`/api/v1/prices/${symbol}?candles=true&interval=${interval}&limit=${limit}`, { method: "GET" });
|
|
1281
|
+
}
|
|
1282
|
+
/**
|
|
1283
|
+
* Get top cryptocurrencies by market cap (FREE)
|
|
1284
|
+
*/
|
|
1285
|
+
async getTopCryptos(limit = 20) {
|
|
1286
|
+
return this.request(`/api/v1/prices?type=top&limit=${limit}`, { method: "GET" });
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Get crypto market overview (FREE)
|
|
1290
|
+
*/
|
|
1291
|
+
async getCryptoMarketOverview() {
|
|
1292
|
+
return this.request("/api/v1/prices?type=overview", { method: "GET" });
|
|
1293
|
+
}
|
|
1294
|
+
};
|
|
1295
|
+
function createOneEngineClient(options) {
|
|
1296
|
+
return new OneEngineClient(options);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// src/services/price.ts
|
|
1300
|
+
var COINGECKO_API = "https://api.coingecko.com/api/v3";
|
|
1301
|
+
var FALLBACK_PRICES = {
|
|
1302
|
+
ETH: 3500,
|
|
1303
|
+
BTC: 95e3,
|
|
1304
|
+
BNB: 700,
|
|
1305
|
+
MATIC: 0.5,
|
|
1306
|
+
AVAX: 40,
|
|
1307
|
+
USDT: 1,
|
|
1308
|
+
USDC: 1,
|
|
1309
|
+
DAI: 1,
|
|
1310
|
+
WBTC: 95e3,
|
|
1311
|
+
WETH: 3500,
|
|
1312
|
+
ARB: 1.2,
|
|
1313
|
+
OP: 2.5,
|
|
1314
|
+
LINK: 20,
|
|
1315
|
+
UNI: 12,
|
|
1316
|
+
AAVE: 250,
|
|
1317
|
+
SOL: 200
|
|
1318
|
+
};
|
|
1319
|
+
var PriceService = class {
|
|
1320
|
+
constructor() {
|
|
1321
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
1322
|
+
this.cacheTTL = 60 * 1e3;
|
|
1323
|
+
}
|
|
1324
|
+
// 1 minute cache
|
|
1325
|
+
async getPrice(symbol) {
|
|
1326
|
+
const upperSymbol = symbol.toUpperCase();
|
|
1327
|
+
const cached = this.cache.get(upperSymbol);
|
|
1328
|
+
if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
|
|
1329
|
+
return cached.price;
|
|
1330
|
+
}
|
|
1331
|
+
const coinId = COINGECKO_IDS[upperSymbol];
|
|
1332
|
+
if (!coinId) {
|
|
1333
|
+
return this.getFallbackPrice(upperSymbol);
|
|
1334
|
+
}
|
|
1335
|
+
try {
|
|
1336
|
+
const response = await fetch(
|
|
1337
|
+
`${COINGECKO_API}/simple/price?ids=${coinId}&vs_currencies=usd&include_24hr_change=true&include_market_cap=true&include_24hr_vol=true`,
|
|
1338
|
+
{ headers: { Accept: "application/json" } }
|
|
1339
|
+
);
|
|
1340
|
+
if (!response.ok) {
|
|
1341
|
+
throw new Error(`CoinGecko API error: ${response.status}`);
|
|
1342
|
+
}
|
|
1343
|
+
const data = await response.json();
|
|
1344
|
+
const coinData = data[coinId];
|
|
1345
|
+
if (!coinData) {
|
|
1346
|
+
return this.getFallbackPrice(upperSymbol);
|
|
1347
|
+
}
|
|
1348
|
+
const change24h = coinData.usd_24h_change || 0;
|
|
1349
|
+
const price = {
|
|
1350
|
+
symbol: upperSymbol,
|
|
1351
|
+
price: coinData.usd || 0,
|
|
1352
|
+
change24h,
|
|
1353
|
+
changePercent24h: change24h,
|
|
1354
|
+
priceChange24h: change24h,
|
|
1355
|
+
marketCap: coinData.usd_market_cap,
|
|
1356
|
+
volume24h: coinData.usd_24h_vol
|
|
1357
|
+
};
|
|
1358
|
+
this.cache.set(upperSymbol, { price, timestamp: Date.now() });
|
|
1359
|
+
return price;
|
|
1360
|
+
} catch (error) {
|
|
1361
|
+
console.warn(`Failed to fetch price for ${upperSymbol}:`, error);
|
|
1362
|
+
return this.getFallbackPrice(upperSymbol);
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
async getPrices(symbols) {
|
|
1366
|
+
const results = {};
|
|
1367
|
+
const withIds = [];
|
|
1368
|
+
const withoutIds = [];
|
|
1369
|
+
for (const symbol of symbols) {
|
|
1370
|
+
const upper = symbol.toUpperCase();
|
|
1371
|
+
if (COINGECKO_IDS[upper]) {
|
|
1372
|
+
withIds.push(upper);
|
|
1373
|
+
} else {
|
|
1374
|
+
withoutIds.push(upper);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
for (const symbol of withoutIds) {
|
|
1378
|
+
results[symbol] = this.getFallbackPrice(symbol);
|
|
1379
|
+
}
|
|
1380
|
+
if (withIds.length === 0) {
|
|
1381
|
+
return results;
|
|
1382
|
+
}
|
|
1383
|
+
const coinIds = withIds.map((s) => COINGECKO_IDS[s]).join(",");
|
|
1384
|
+
try {
|
|
1385
|
+
const response = await fetch(
|
|
1386
|
+
`${COINGECKO_API}/simple/price?ids=${coinIds}&vs_currencies=usd&include_24hr_change=true`,
|
|
1387
|
+
{ headers: { Accept: "application/json" } }
|
|
1388
|
+
);
|
|
1389
|
+
if (!response.ok) {
|
|
1390
|
+
throw new Error(`CoinGecko API error: ${response.status}`);
|
|
1391
|
+
}
|
|
1392
|
+
const data = await response.json();
|
|
1393
|
+
for (const symbol of withIds) {
|
|
1394
|
+
const coinId = COINGECKO_IDS[symbol];
|
|
1395
|
+
const coinData = data[coinId];
|
|
1396
|
+
if (coinData) {
|
|
1397
|
+
const change24h = coinData.usd_24h_change || 0;
|
|
1398
|
+
results[symbol] = {
|
|
1399
|
+
symbol,
|
|
1400
|
+
price: coinData.usd || 0,
|
|
1401
|
+
change24h,
|
|
1402
|
+
changePercent24h: change24h,
|
|
1403
|
+
priceChange24h: change24h
|
|
1404
|
+
};
|
|
1405
|
+
} else {
|
|
1406
|
+
results[symbol] = this.getFallbackPrice(symbol);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
console.warn("Failed to fetch batch prices:", error);
|
|
1411
|
+
for (const symbol of withIds) {
|
|
1412
|
+
results[symbol] = this.getFallbackPrice(symbol);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
return results;
|
|
1416
|
+
}
|
|
1417
|
+
getFallbackPrice(symbol) {
|
|
1418
|
+
const price = FALLBACK_PRICES[symbol] || 0;
|
|
1419
|
+
return {
|
|
1420
|
+
symbol,
|
|
1421
|
+
price,
|
|
1422
|
+
change24h: 0,
|
|
1423
|
+
changePercent24h: 0,
|
|
1424
|
+
priceChange24h: 0
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
clearCache() {
|
|
1428
|
+
this.cache.clear();
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
var priceService = new PriceService();
|
|
1432
|
+
|
|
1433
|
+
// src/utils/index.ts
|
|
1434
|
+
function shortenAddress(address, chars = 4) {
|
|
1435
|
+
if (!address) return "";
|
|
1436
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
1437
|
+
}
|
|
1438
|
+
function isValidAddress(address) {
|
|
1439
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
1440
|
+
}
|
|
1441
|
+
function checksumAddress(address) {
|
|
1442
|
+
return address.toLowerCase();
|
|
1443
|
+
}
|
|
1444
|
+
function formatNumber(value, options = {}) {
|
|
1445
|
+
const { decimals = 2, compact = false, currency, locale = "en-US" } = options;
|
|
1446
|
+
if (currency) {
|
|
1447
|
+
return new Intl.NumberFormat(locale, {
|
|
1448
|
+
style: "currency",
|
|
1449
|
+
currency,
|
|
1450
|
+
minimumFractionDigits: decimals,
|
|
1451
|
+
maximumFractionDigits: decimals,
|
|
1452
|
+
notation: compact ? "compact" : "standard"
|
|
1453
|
+
}).format(value);
|
|
1454
|
+
}
|
|
1455
|
+
return new Intl.NumberFormat(locale, {
|
|
1456
|
+
minimumFractionDigits: decimals,
|
|
1457
|
+
maximumFractionDigits: decimals,
|
|
1458
|
+
notation: compact ? "compact" : "standard"
|
|
1459
|
+
}).format(value);
|
|
1460
|
+
}
|
|
1461
|
+
function formatUSD(value, compact = false) {
|
|
1462
|
+
return formatNumber(value, { currency: "USD", compact });
|
|
1463
|
+
}
|
|
1464
|
+
function formatPercent(value, decimals = 2) {
|
|
1465
|
+
const sign = value >= 0 ? "+" : "";
|
|
1466
|
+
return `${sign}${value.toFixed(decimals)}%`;
|
|
1467
|
+
}
|
|
1468
|
+
function formatTokenAmount(amount, decimals = 6) {
|
|
1469
|
+
if (amount === 0) return "0";
|
|
1470
|
+
if (amount < 1e-6) return "<0.000001";
|
|
1471
|
+
if (amount < 1) return amount.toFixed(decimals);
|
|
1472
|
+
if (amount < 1e3) return amount.toFixed(4);
|
|
1473
|
+
if (amount < 1e6) return formatNumber(amount, { decimals: 2 });
|
|
1474
|
+
return formatNumber(amount, { decimals: 2, compact: true });
|
|
1475
|
+
}
|
|
1476
|
+
function formatDate(date, options = {
|
|
1477
|
+
year: "numeric",
|
|
1478
|
+
month: "short",
|
|
1479
|
+
day: "numeric"
|
|
1480
|
+
}) {
|
|
1481
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
1482
|
+
return d.toLocaleDateString("en-US", options);
|
|
1483
|
+
}
|
|
1484
|
+
function formatDateTime(date) {
|
|
1485
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
1486
|
+
return d.toLocaleString("en-US", {
|
|
1487
|
+
year: "numeric",
|
|
1488
|
+
month: "short",
|
|
1489
|
+
day: "numeric",
|
|
1490
|
+
hour: "2-digit",
|
|
1491
|
+
minute: "2-digit"
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
function formatRelativeTime(date) {
|
|
1495
|
+
const d = typeof date === "string" ? new Date(date) : date;
|
|
1496
|
+
const now = /* @__PURE__ */ new Date();
|
|
1497
|
+
const diffMs = now.getTime() - d.getTime();
|
|
1498
|
+
const diffSec = Math.floor(diffMs / 1e3);
|
|
1499
|
+
const diffMin = Math.floor(diffSec / 60);
|
|
1500
|
+
const diffHour = Math.floor(diffMin / 60);
|
|
1501
|
+
const diffDay = Math.floor(diffHour / 24);
|
|
1502
|
+
if (diffSec < 60) return "just now";
|
|
1503
|
+
if (diffMin < 60) return `${diffMin}m ago`;
|
|
1504
|
+
if (diffHour < 24) return `${diffHour}h ago`;
|
|
1505
|
+
if (diffDay < 7) return `${diffDay}d ago`;
|
|
1506
|
+
return formatDate(d);
|
|
1507
|
+
}
|
|
1508
|
+
function isValidEmail(email) {
|
|
1509
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
1510
|
+
return emailRegex.test(email);
|
|
1511
|
+
}
|
|
1512
|
+
function isValidPhone(phone) {
|
|
1513
|
+
const phoneRegex = /^\+?[1-9]\d{1,14}$/;
|
|
1514
|
+
return phoneRegex.test(phone.replace(/[\s-()]/g, ""));
|
|
1515
|
+
}
|
|
1516
|
+
function capitalize(str) {
|
|
1517
|
+
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
|
|
1518
|
+
}
|
|
1519
|
+
function truncate(str, length) {
|
|
1520
|
+
if (str.length <= length) return str;
|
|
1521
|
+
return `${str.slice(0, length)}...`;
|
|
1522
|
+
}
|
|
1523
|
+
function slugify(str) {
|
|
1524
|
+
return str.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)/g, "");
|
|
1525
|
+
}
|
|
1526
|
+
function sleep(ms) {
|
|
1527
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1528
|
+
}
|
|
1529
|
+
async function retry(fn, options = {}) {
|
|
1530
|
+
const { maxAttempts = 3, delay = 1e3, backoff = 2 } = options;
|
|
1531
|
+
let lastError;
|
|
1532
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
1533
|
+
try {
|
|
1534
|
+
return await fn();
|
|
1535
|
+
} catch (error) {
|
|
1536
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1537
|
+
if (attempt < maxAttempts) {
|
|
1538
|
+
await sleep(delay * Math.pow(backoff, attempt - 1));
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
throw lastError;
|
|
1543
|
+
}
|
|
1544
|
+
function omit(obj, keys) {
|
|
1545
|
+
const result = { ...obj };
|
|
1546
|
+
for (const key of keys) {
|
|
1547
|
+
delete result[key];
|
|
1548
|
+
}
|
|
1549
|
+
return result;
|
|
1550
|
+
}
|
|
1551
|
+
function pick(obj, keys) {
|
|
1552
|
+
const result = {};
|
|
1553
|
+
for (const key of keys) {
|
|
1554
|
+
if (key in obj) {
|
|
1555
|
+
result[key] = obj[key];
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
return result;
|
|
1559
|
+
}
|
|
1560
|
+
var OneSDKError = class extends Error {
|
|
1561
|
+
constructor(message, code, details) {
|
|
1562
|
+
super(message);
|
|
1563
|
+
this.name = "OneSDKError";
|
|
1564
|
+
this.code = code;
|
|
1565
|
+
this.details = details;
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
function isOneSDKError(error) {
|
|
1569
|
+
return error instanceof OneSDKError;
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
// src/react-native.ts
|
|
1573
|
+
function createCachedEngineClient(storage, options) {
|
|
1574
|
+
const client = createOneEngineClient(options);
|
|
1575
|
+
return {
|
|
1576
|
+
...client,
|
|
1577
|
+
/**
|
|
1578
|
+
* Initialize with stored token
|
|
1579
|
+
*/
|
|
1580
|
+
async initialize() {
|
|
1581
|
+
const token = await storage.getItem("one_access_token");
|
|
1582
|
+
if (token) {
|
|
1583
|
+
client.setAccessToken(token);
|
|
1584
|
+
return true;
|
|
1585
|
+
}
|
|
1586
|
+
return false;
|
|
1587
|
+
},
|
|
1588
|
+
/**
|
|
1589
|
+
* Login and persist token
|
|
1590
|
+
*/
|
|
1591
|
+
async login(email, otp) {
|
|
1592
|
+
const result = await client.verifyEmailOtp(email, otp);
|
|
1593
|
+
if (result.success && result.data?.accessToken) {
|
|
1594
|
+
await storage.setItem("one_access_token", result.data.accessToken);
|
|
1595
|
+
if (result.data.refreshToken) {
|
|
1596
|
+
await storage.setItem("one_refresh_token", result.data.refreshToken);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return result;
|
|
1600
|
+
},
|
|
1601
|
+
/**
|
|
1602
|
+
* Logout and clear stored tokens
|
|
1603
|
+
*/
|
|
1604
|
+
async logout() {
|
|
1605
|
+
await client.signOut();
|
|
1606
|
+
await storage.removeItem("one_access_token");
|
|
1607
|
+
await storage.removeItem("one_refresh_token");
|
|
1608
|
+
client.clearAccessToken();
|
|
1609
|
+
},
|
|
1610
|
+
/**
|
|
1611
|
+
* Refresh token from storage
|
|
1612
|
+
*/
|
|
1613
|
+
async refreshFromStorage() {
|
|
1614
|
+
const refreshToken = await storage.getItem("one_refresh_token");
|
|
1615
|
+
if (refreshToken) {
|
|
1616
|
+
const result = await client.refreshToken(refreshToken);
|
|
1617
|
+
if (result.success && result.data?.accessToken) {
|
|
1618
|
+
await storage.setItem("one_access_token", result.data.accessToken);
|
|
1619
|
+
if (result.data.refreshToken) {
|
|
1620
|
+
await storage.setItem("one_refresh_token", result.data.refreshToken);
|
|
1621
|
+
}
|
|
1622
|
+
return true;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
return false;
|
|
1626
|
+
},
|
|
1627
|
+
// Expose underlying client
|
|
1628
|
+
getClient: () => client
|
|
1629
|
+
};
|
|
1630
|
+
}
|
|
1631
|
+
function createDeepLinkHandler(scheme = "onewallet") {
|
|
1632
|
+
return {
|
|
1633
|
+
parse(url) {
|
|
1634
|
+
try {
|
|
1635
|
+
const urlObj = new URL(url);
|
|
1636
|
+
const path = urlObj.pathname.replace(/^\//, "");
|
|
1637
|
+
const params = {};
|
|
1638
|
+
urlObj.searchParams.forEach((value, key) => {
|
|
1639
|
+
params[key] = value;
|
|
1640
|
+
});
|
|
1641
|
+
let type = "unknown";
|
|
1642
|
+
if (path.includes("onramp") || path.includes("callback")) {
|
|
1643
|
+
type = "onramp_callback";
|
|
1644
|
+
} else if (path.includes("wc") || path.includes("walletconnect")) {
|
|
1645
|
+
type = "wallet_connect";
|
|
1646
|
+
} else if (path.includes("pay") || path.includes("payment")) {
|
|
1647
|
+
type = "payment";
|
|
1648
|
+
}
|
|
1649
|
+
return { type, params };
|
|
1650
|
+
} catch {
|
|
1651
|
+
return { type: "unknown", params: {} };
|
|
1652
|
+
}
|
|
1653
|
+
},
|
|
1654
|
+
generate(type, params) {
|
|
1655
|
+
const searchParams = new URLSearchParams(params);
|
|
1656
|
+
return `${scheme}://${type}?${searchParams.toString()}`;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1660
|
+
function parseQRCode(data) {
|
|
1661
|
+
if (/^0x[a-fA-F0-9]{40}$/.test(data)) {
|
|
1662
|
+
return {
|
|
1663
|
+
type: "address",
|
|
1664
|
+
data,
|
|
1665
|
+
parsed: { address: data }
|
|
1666
|
+
};
|
|
1667
|
+
}
|
|
1668
|
+
if (data.startsWith("ethereum:")) {
|
|
1669
|
+
const match = data.match(/^ethereum:(0x[a-fA-F0-9]{40})(?:@(\d+))?(?:\?(.*))?$/);
|
|
1670
|
+
if (match) {
|
|
1671
|
+
const [, address, chainId, queryString] = match;
|
|
1672
|
+
const params = new URLSearchParams(queryString || "");
|
|
1673
|
+
return {
|
|
1674
|
+
type: "payment_request",
|
|
1675
|
+
data,
|
|
1676
|
+
parsed: {
|
|
1677
|
+
address,
|
|
1678
|
+
chainId: chainId ? parseInt(chainId) : void 0,
|
|
1679
|
+
amount: params.get("value") || void 0,
|
|
1680
|
+
token: params.get("token") || void 0,
|
|
1681
|
+
message: params.get("message") || void 0
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
if (data.startsWith("wc:")) {
|
|
1687
|
+
return {
|
|
1688
|
+
type: "wallet_connect",
|
|
1689
|
+
data
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
return { type: "unknown", data };
|
|
1693
|
+
}
|
|
1694
|
+
function formatCryptoAmount(amount, symbol, options = {}) {
|
|
1695
|
+
const { maxDecimals = 6, showSymbol = true, compact = false } = options;
|
|
1696
|
+
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
1697
|
+
if (isNaN(num)) return showSymbol ? `0 ${symbol}` : "0";
|
|
1698
|
+
let formatted;
|
|
1699
|
+
if (compact && num >= 1e6) {
|
|
1700
|
+
formatted = (num / 1e6).toFixed(2) + "M";
|
|
1701
|
+
} else if (compact && num >= 1e3) {
|
|
1702
|
+
formatted = (num / 1e3).toFixed(2) + "K";
|
|
1703
|
+
} else if (num < 1e-6 && num > 0) {
|
|
1704
|
+
formatted = "<0.000001";
|
|
1705
|
+
} else {
|
|
1706
|
+
const decimals = num < 1 ? maxDecimals : Math.min(maxDecimals, 4);
|
|
1707
|
+
formatted = num.toFixed(decimals).replace(/\.?0+$/, "");
|
|
1708
|
+
}
|
|
1709
|
+
return showSymbol ? `${formatted} ${symbol}` : formatted;
|
|
1710
|
+
}
|
|
1711
|
+
function generateShareContent(params) {
|
|
1712
|
+
const { type, address, amount, token, txHash, chainId } = params;
|
|
1713
|
+
switch (type) {
|
|
1714
|
+
case "receive":
|
|
1715
|
+
return {
|
|
1716
|
+
title: "My Wallet Address",
|
|
1717
|
+
message: `Send ${token || "crypto"} to my wallet:
|
|
1718
|
+
${address}`,
|
|
1719
|
+
url: address ? `ethereum:${address}${chainId ? `@${chainId}` : ""}` : void 0
|
|
1720
|
+
};
|
|
1721
|
+
case "payment_request":
|
|
1722
|
+
return {
|
|
1723
|
+
title: "Payment Request",
|
|
1724
|
+
message: `Please send ${amount} ${token} to:
|
|
1725
|
+
${address}`,
|
|
1726
|
+
url: `ethereum:${address}${chainId ? `@${chainId}` : ""}?value=${amount}${token ? `&token=${token}` : ""}`
|
|
1727
|
+
};
|
|
1728
|
+
case "transaction":
|
|
1729
|
+
return {
|
|
1730
|
+
title: "Transaction Sent",
|
|
1731
|
+
message: `Transaction confirmed!
|
|
1732
|
+
Hash: ${txHash}`,
|
|
1733
|
+
url: txHash ? getExplorerUrl(chainId || 1, txHash, "tx") : void 0
|
|
1734
|
+
};
|
|
1735
|
+
default:
|
|
1736
|
+
return { title: "", message: "" };
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
function getExplorerUrl(chainId, hash, type = "tx") {
|
|
1740
|
+
const explorers = {
|
|
1741
|
+
1: "https://etherscan.io",
|
|
1742
|
+
137: "https://polygonscan.com",
|
|
1743
|
+
42161: "https://arbiscan.io",
|
|
1744
|
+
10: "https://optimistic.etherscan.io",
|
|
1745
|
+
8453: "https://basescan.org",
|
|
1746
|
+
56: "https://bscscan.com",
|
|
1747
|
+
43114: "https://snowtrace.io"
|
|
1748
|
+
};
|
|
1749
|
+
const baseUrl = explorers[chainId] || explorers[1];
|
|
1750
|
+
return `${baseUrl}/${type}/${hash}`;
|
|
1751
|
+
}
|
|
1752
|
+
|
|
1753
|
+
export { CHAIN_CONFIGS, COINGECKO_IDS, OneEngineClient, OneSDKError, PriceService, TOKEN_NAMES, capitalize, checksumAddress, createCachedEngineClient, createDeepLinkHandler, createOneEngineClient, formatCryptoAmount, formatDate, formatDateTime, formatNumber, formatPercent, formatRelativeTime, formatTokenAmount, formatUSD, generateShareContent, getConfig, getExplorerUrl, initOneSDK, isOneSDKError, isValidAddress, isValidEmail, isValidPhone, omit, parseQRCode, pick, priceService, retry, shortenAddress, sleep, slugify, truncate };
|
|
1754
|
+
//# sourceMappingURL=react-native.mjs.map
|
|
1755
|
+
//# sourceMappingURL=react-native.mjs.map
|