@one_deploy/sdk 1.0.2 → 1.0.4
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/package.json +1 -1
- package/src/components/OneSwapWidget.tsx +1 -1
- package/src/components/ai/OneChainSelector.tsx +183 -0
- package/src/components/ai/OneCycleSelector.tsx +187 -0
- package/src/components/ai/OnePairSelector.tsx +181 -0
- package/src/components/ai/OneTierSelector.tsx +187 -0
- package/src/components/ai/index.ts +17 -0
- package/src/components/index.ts +3 -0
- package/src/config/index.ts +1 -1
- package/src/hooks/index.ts +20 -0
- package/src/hooks/useAITrading.ts +444 -0
- package/src/index.ts +20 -0
- package/src/react-native.ts +23 -0
- package/src/services/engine.ts +184 -0
- package/src/services/index.ts +16 -0
- package/src/services/usage.ts +249 -0
- package/.turbo/turbo-build.log +0 -0
- package/.turbo/turbo-type-check.log +0 -0
- package/dist/config/index.d.mts +0 -74
- package/dist/config/index.d.ts +0 -74
- package/dist/config/index.js +0 -244
- package/dist/config/index.js.map +0 -1
- package/dist/config/index.mjs +0 -226
- package/dist/config/index.mjs.map +0 -1
- package/dist/engine-5ndtBaCr.d.ts +0 -1039
- package/dist/engine-CrlhH0nw.d.mts +0 -1039
- package/dist/hooks/index.d.mts +0 -56
- package/dist/hooks/index.d.ts +0 -56
- package/dist/hooks/index.js +0 -1360
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/index.mjs +0 -1356
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -356
- package/dist/index.d.ts +0 -356
- package/dist/index.js +0 -5069
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -4950
- package/dist/index.mjs.map +0 -1
- package/dist/price-CgqXPnT3.d.ts +0 -13
- package/dist/price-ClbLHHjv.d.mts +0 -13
- package/dist/providers/index.d.mts +0 -121
- package/dist/providers/index.d.ts +0 -121
- package/dist/providers/index.js +0 -1643
- package/dist/providers/index.js.map +0 -1
- package/dist/providers/index.mjs +0 -1601
- package/dist/providers/index.mjs.map +0 -1
- package/dist/react-native.d.mts +0 -120
- package/dist/react-native.d.ts +0 -120
- package/dist/react-native.js +0 -1794
- package/dist/react-native.js.map +0 -1
- package/dist/react-native.mjs +0 -1757
- package/dist/react-native.mjs.map +0 -1
- package/dist/services/index.d.mts +0 -85
- package/dist/services/index.d.ts +0 -85
- package/dist/services/index.js +0 -1466
- package/dist/services/index.js.map +0 -1
- package/dist/services/index.mjs +0 -1458
- package/dist/services/index.mjs.map +0 -1
- package/dist/types/index.d.mts +0 -759
- package/dist/types/index.d.ts +0 -759
- package/dist/types/index.js +0 -4
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -3
- package/dist/types/index.mjs.map +0 -1
- package/dist/utils/index.d.mts +0 -36
- package/dist/utils/index.d.ts +0 -36
- package/dist/utils/index.js +0 -164
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/index.mjs +0 -142
- package/dist/utils/index.mjs.map +0 -1
package/src/index.ts
CHANGED
|
@@ -157,6 +157,26 @@ export {
|
|
|
157
157
|
useWalletBalance,
|
|
158
158
|
useTokenPrice,
|
|
159
159
|
useTokenPrices,
|
|
160
|
+
// AI Trading Hooks
|
|
161
|
+
useAIStrategies,
|
|
162
|
+
useAIStrategy,
|
|
163
|
+
useAIOrders,
|
|
164
|
+
useAIPortfolio,
|
|
165
|
+
useAIMarketData,
|
|
166
|
+
useAITrading,
|
|
167
|
+
setAITradingAccessToken,
|
|
168
|
+
clearAITradingAccessToken,
|
|
169
|
+
} from './hooks';
|
|
170
|
+
|
|
171
|
+
export type {
|
|
172
|
+
UseAIStrategiesOptions,
|
|
173
|
+
UseAIStrategiesResult,
|
|
174
|
+
UseAIStrategyResult,
|
|
175
|
+
UseAIOrdersOptions,
|
|
176
|
+
UseAIOrdersResult,
|
|
177
|
+
UseAIPortfolioResult,
|
|
178
|
+
UseAIMarketDataResult,
|
|
179
|
+
UseAITradingResult,
|
|
160
180
|
} from './hooks';
|
|
161
181
|
|
|
162
182
|
// ===== Utilities =====
|
package/src/react-native.ts
CHANGED
|
@@ -67,6 +67,29 @@ export {
|
|
|
67
67
|
isOneSDKError,
|
|
68
68
|
} from './utils';
|
|
69
69
|
|
|
70
|
+
// ===== AI Trading Components =====
|
|
71
|
+
// React Native components for AI trading integration
|
|
72
|
+
export {
|
|
73
|
+
OneChainSelector,
|
|
74
|
+
CHAIN_CONFIG,
|
|
75
|
+
} from './components/ai/OneChainSelector';
|
|
76
|
+
export type { OneChainSelectorProps } from './components/ai/OneChainSelector';
|
|
77
|
+
|
|
78
|
+
export { OneTierSelector } from './components/ai/OneTierSelector';
|
|
79
|
+
export type { OneTierSelectorProps, Tier } from './components/ai/OneTierSelector';
|
|
80
|
+
|
|
81
|
+
export {
|
|
82
|
+
OneCycleSelector,
|
|
83
|
+
DEFAULT_SHARE_RATES,
|
|
84
|
+
} from './components/ai/OneCycleSelector';
|
|
85
|
+
export type { OneCycleSelectorProps } from './components/ai/OneCycleSelector';
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
OnePairSelector,
|
|
89
|
+
PAIR_ICONS,
|
|
90
|
+
} from './components/ai/OnePairSelector';
|
|
91
|
+
export type { OnePairSelectorProps } from './components/ai/OnePairSelector';
|
|
92
|
+
|
|
70
93
|
// ===== React Native Specific Utilities =====
|
|
71
94
|
|
|
72
95
|
/**
|
package/src/services/engine.ts
CHANGED
|
@@ -1597,6 +1597,93 @@ export class OneEngineClient {
|
|
|
1597
1597
|
return this.request(`/api/v1/admin/rate-limits/${identifier}`, { method: 'DELETE' });
|
|
1598
1598
|
}
|
|
1599
1599
|
|
|
1600
|
+
// ========== AI Agent Configuration ==========
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Get all AI agent configurations
|
|
1604
|
+
* This returns the full agent setup including tiers, cycles, and trading parameters
|
|
1605
|
+
*/
|
|
1606
|
+
async getAgentConfigs(options?: {
|
|
1607
|
+
includeInactive?: boolean;
|
|
1608
|
+
agentId?: string;
|
|
1609
|
+
}): Promise<ApiResponse<{
|
|
1610
|
+
agents?: Array<{
|
|
1611
|
+
id: string;
|
|
1612
|
+
name: string;
|
|
1613
|
+
name_zh: string;
|
|
1614
|
+
description: string;
|
|
1615
|
+
description_zh: string;
|
|
1616
|
+
category: string;
|
|
1617
|
+
risk_level: number;
|
|
1618
|
+
icon: string;
|
|
1619
|
+
color: string;
|
|
1620
|
+
tiers: Array<{ tier: number; amount: number; label: string; label_zh: string }>;
|
|
1621
|
+
supported_cycles: number[];
|
|
1622
|
+
default_cycle: number;
|
|
1623
|
+
supported_pairs: string[];
|
|
1624
|
+
supported_chains: string[];
|
|
1625
|
+
is_active: boolean;
|
|
1626
|
+
preview: {
|
|
1627
|
+
tier: { tier: number; amount: number; label: string };
|
|
1628
|
+
cycle: number;
|
|
1629
|
+
dailyLots: number;
|
|
1630
|
+
stabilityScore: number;
|
|
1631
|
+
roiRange: { min: number; max: number; userMin: number; userMax: number };
|
|
1632
|
+
shareRate: number;
|
|
1633
|
+
profitEstimate: { monthlyMin: number; monthlyMax: number; cycleMin: number; cycleMax: number };
|
|
1634
|
+
};
|
|
1635
|
+
}>;
|
|
1636
|
+
agent?: any;
|
|
1637
|
+
shareRates?: Record<number, number>;
|
|
1638
|
+
}>> {
|
|
1639
|
+
const params = new URLSearchParams();
|
|
1640
|
+
if (options?.includeInactive) params.set('includeInactive', 'true');
|
|
1641
|
+
if (options?.agentId) params.set('agentId', options.agentId);
|
|
1642
|
+
const query = params.toString();
|
|
1643
|
+
return this.request(`/api/v1/agents${query ? `?${query}` : ''}`, { method: 'GET' });
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* Calculate subscription parameters for an agent
|
|
1648
|
+
*/
|
|
1649
|
+
async calculateAgentParams(params: {
|
|
1650
|
+
agentId: string;
|
|
1651
|
+
amount: number;
|
|
1652
|
+
cycleDays: number;
|
|
1653
|
+
}): Promise<ApiResponse<{
|
|
1654
|
+
dailyLots: number;
|
|
1655
|
+
effectiveCapital: number;
|
|
1656
|
+
stabilityScore: number;
|
|
1657
|
+
roiRange: { min: number; max: number; userMin: number; userMax: number };
|
|
1658
|
+
shareRate: number;
|
|
1659
|
+
profitEstimate: { monthlyMin: number; monthlyMax: number; cycleMin: number; cycleMax: number };
|
|
1660
|
+
}>> {
|
|
1661
|
+
return this.request('/api/v1/agents/calculate', {
|
|
1662
|
+
method: 'POST',
|
|
1663
|
+
body: JSON.stringify(params),
|
|
1664
|
+
});
|
|
1665
|
+
}
|
|
1666
|
+
|
|
1667
|
+
/**
|
|
1668
|
+
* Get supported trading pairs from agents
|
|
1669
|
+
*/
|
|
1670
|
+
async getTradingPairs(): Promise<ApiResponse<{
|
|
1671
|
+
pairs: string[];
|
|
1672
|
+
byAgent: Record<string, string[]>;
|
|
1673
|
+
}>> {
|
|
1674
|
+
const result = await this.getAgentConfigs();
|
|
1675
|
+
if (result.success && result.data?.agents) {
|
|
1676
|
+
const allPairs = new Set<string>();
|
|
1677
|
+
const byAgent: Record<string, string[]> = {};
|
|
1678
|
+
for (const agent of result.data.agents) {
|
|
1679
|
+
byAgent[agent.id] = agent.supported_pairs;
|
|
1680
|
+
agent.supported_pairs.forEach(p => allPairs.add(p));
|
|
1681
|
+
}
|
|
1682
|
+
return { success: true, data: { pairs: Array.from(allPairs), byAgent } };
|
|
1683
|
+
}
|
|
1684
|
+
return { success: false, error: result.error };
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1600
1687
|
// ========== AI Quant Trading ==========
|
|
1601
1688
|
|
|
1602
1689
|
/**
|
|
@@ -1842,6 +1929,103 @@ export class OneEngineClient {
|
|
|
1842
1929
|
}>> {
|
|
1843
1930
|
return this.request('/api/v1/prices?type=overview', { method: 'GET' });
|
|
1844
1931
|
}
|
|
1932
|
+
|
|
1933
|
+
// ========== Project Management ==========
|
|
1934
|
+
|
|
1935
|
+
/**
|
|
1936
|
+
* Get user's projects
|
|
1937
|
+
*/
|
|
1938
|
+
async getProjects(options?: {
|
|
1939
|
+
isActive?: boolean;
|
|
1940
|
+
}): Promise<ApiResponse<{ projects: AdminProject[]; total: number }>> {
|
|
1941
|
+
const params = new URLSearchParams();
|
|
1942
|
+
if (options?.isActive !== undefined) params.set('isActive', String(options.isActive));
|
|
1943
|
+
const query = params.toString();
|
|
1944
|
+
return this.request(`/api/v1/projects${query ? `?${query}` : ''}`, { method: 'GET' });
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
/**
|
|
1948
|
+
* Create a new project for ecosystem partners
|
|
1949
|
+
*/
|
|
1950
|
+
async createProject(params: {
|
|
1951
|
+
name: string;
|
|
1952
|
+
slug: string;
|
|
1953
|
+
settings?: Record<string, unknown>;
|
|
1954
|
+
}): Promise<ApiResponse<{ project: AdminProject }>> {
|
|
1955
|
+
return this.request('/api/v1/projects', {
|
|
1956
|
+
method: 'POST',
|
|
1957
|
+
body: JSON.stringify(params),
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
/**
|
|
1962
|
+
* Get project details
|
|
1963
|
+
*/
|
|
1964
|
+
async getProject(projectId: string): Promise<ApiResponse<{ project: AdminProject }>> {
|
|
1965
|
+
return this.request(`/api/v1/projects/${projectId}`, { method: 'GET' });
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1968
|
+
/**
|
|
1969
|
+
* Update project settings
|
|
1970
|
+
*/
|
|
1971
|
+
async updateProject(projectId: string, updates: {
|
|
1972
|
+
name?: string;
|
|
1973
|
+
isActive?: boolean;
|
|
1974
|
+
settings?: Record<string, unknown>;
|
|
1975
|
+
}): Promise<ApiResponse<{ project: AdminProject }>> {
|
|
1976
|
+
return this.request(`/api/v1/projects/${projectId}`, {
|
|
1977
|
+
method: 'PATCH',
|
|
1978
|
+
body: JSON.stringify(updates),
|
|
1979
|
+
});
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* Get project features status
|
|
1984
|
+
*/
|
|
1985
|
+
async getProjectFeatures(projectId: string): Promise<ApiResponse<{
|
|
1986
|
+
features: Record<string, {
|
|
1987
|
+
enabled: boolean;
|
|
1988
|
+
name: string;
|
|
1989
|
+
description: string;
|
|
1990
|
+
description_zh: string;
|
|
1991
|
+
}>;
|
|
1992
|
+
availableFeatures: string[];
|
|
1993
|
+
}>> {
|
|
1994
|
+
return this.request(`/api/v1/projects/${projectId}/features`, { method: 'GET' });
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
/**
|
|
1998
|
+
* Enable/disable features for a project
|
|
1999
|
+
*/
|
|
2000
|
+
async updateProjectFeatures(projectId: string, features: {
|
|
2001
|
+
wallet?: boolean;
|
|
2002
|
+
swap?: boolean;
|
|
2003
|
+
contracts?: boolean;
|
|
2004
|
+
fiat?: boolean;
|
|
2005
|
+
payments?: boolean;
|
|
2006
|
+
quant?: boolean;
|
|
2007
|
+
ai?: boolean;
|
|
2008
|
+
x402?: boolean;
|
|
2009
|
+
}): Promise<ApiResponse<{ project: AdminProject; message: string }>> {
|
|
2010
|
+
return this.request(`/api/v1/projects/${projectId}/features`, {
|
|
2011
|
+
method: 'PATCH',
|
|
2012
|
+
body: JSON.stringify(features),
|
|
2013
|
+
});
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
/**
|
|
2017
|
+
* Regenerate project API key
|
|
2018
|
+
*/
|
|
2019
|
+
async regenerateProjectApiKey(projectId: string): Promise<ApiResponse<{ apiKey: string }>> {
|
|
2020
|
+
return this.request(`/api/v1/projects/${projectId}/api-key`, { method: 'POST' });
|
|
2021
|
+
}
|
|
2022
|
+
|
|
2023
|
+
/**
|
|
2024
|
+
* Delete project
|
|
2025
|
+
*/
|
|
2026
|
+
async deleteProject(projectId: string): Promise<ApiResponse<{ deleted: boolean }>> {
|
|
2027
|
+
return this.request(`/api/v1/projects/${projectId}`, { method: 'DELETE' });
|
|
2028
|
+
}
|
|
1845
2029
|
}
|
|
1846
2030
|
|
|
1847
2031
|
// Factory function
|
package/src/services/index.ts
CHANGED
|
@@ -28,3 +28,19 @@ export { SupabaseService, createSupabaseClient, getSupabaseClient } from './supa
|
|
|
28
28
|
|
|
29
29
|
// ===== Price Service (fallback for offline/cache) =====
|
|
30
30
|
export { PriceService, priceService } from './price';
|
|
31
|
+
|
|
32
|
+
// ===== Usage Tracking Service =====
|
|
33
|
+
export {
|
|
34
|
+
UsageService,
|
|
35
|
+
getUsageService,
|
|
36
|
+
createUsageService,
|
|
37
|
+
} from './usage';
|
|
38
|
+
|
|
39
|
+
export type {
|
|
40
|
+
UsageCategory,
|
|
41
|
+
DisplayCategory,
|
|
42
|
+
UsageRecord,
|
|
43
|
+
UsageSummary,
|
|
44
|
+
UsageActivity,
|
|
45
|
+
UsageResponse,
|
|
46
|
+
} from './usage';
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Usage Tracking Service
|
|
3
|
+
* Tracks AI usage for Personal Assistant and Trading Agent
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { getConfig } from '../config';
|
|
7
|
+
|
|
8
|
+
// Usage categories (internal)
|
|
9
|
+
export type UsageCategory =
|
|
10
|
+
| 'wallet'
|
|
11
|
+
| 'payment'
|
|
12
|
+
| 'exchange_onramper'
|
|
13
|
+
| 'exchange_swap'
|
|
14
|
+
| 'ai_thirdweb'
|
|
15
|
+
| 'ai_trading_engine';
|
|
16
|
+
|
|
17
|
+
// Display categories (client-facing)
|
|
18
|
+
export type DisplayCategory = 'personal_assistant' | 'trading_agent';
|
|
19
|
+
|
|
20
|
+
export interface UsageRecord {
|
|
21
|
+
userId: string;
|
|
22
|
+
category: UsageCategory;
|
|
23
|
+
action: string;
|
|
24
|
+
requestTokens?: number;
|
|
25
|
+
responseTokens?: number;
|
|
26
|
+
creditsUsed?: number;
|
|
27
|
+
metadata?: Record<string, any>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UsageSummary {
|
|
31
|
+
personal_assistant: {
|
|
32
|
+
requestCount: number;
|
|
33
|
+
totalTokens: number;
|
|
34
|
+
totalCredits: number;
|
|
35
|
+
};
|
|
36
|
+
trading_agent: {
|
|
37
|
+
requestCount: number;
|
|
38
|
+
totalTokens: number;
|
|
39
|
+
totalCredits: number;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface UsageActivity {
|
|
44
|
+
type: DisplayCategory;
|
|
45
|
+
action: string;
|
|
46
|
+
tokens: number;
|
|
47
|
+
credits: number;
|
|
48
|
+
timestamp: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface UsageResponse {
|
|
52
|
+
summary: UsageSummary;
|
|
53
|
+
dailyBreakdown: Array<{
|
|
54
|
+
date: string;
|
|
55
|
+
personal_assistant: number;
|
|
56
|
+
trading_agent: number;
|
|
57
|
+
}>;
|
|
58
|
+
recentActivity: UsageActivity[];
|
|
59
|
+
period: {
|
|
60
|
+
days: number;
|
|
61
|
+
startDate: string;
|
|
62
|
+
endDate: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Usage Tracking Service
|
|
68
|
+
*/
|
|
69
|
+
export class UsageService {
|
|
70
|
+
private baseUrl: string;
|
|
71
|
+
private userId: string | null = null;
|
|
72
|
+
|
|
73
|
+
constructor(baseUrl?: string) {
|
|
74
|
+
this.baseUrl = baseUrl || getConfig().oneEngineUrl || '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Set the current user ID for tracking
|
|
79
|
+
*/
|
|
80
|
+
setUserId(userId: string): void {
|
|
81
|
+
this.userId = userId;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Record Personal Assistant usage (Thirdweb AI)
|
|
86
|
+
*/
|
|
87
|
+
async trackPersonalAssistant(
|
|
88
|
+
action: string,
|
|
89
|
+
tokens?: { request?: number; response?: number },
|
|
90
|
+
credits?: number,
|
|
91
|
+
metadata?: Record<string, any>
|
|
92
|
+
): Promise<boolean> {
|
|
93
|
+
return this.recordUsage({
|
|
94
|
+
userId: this.userId!,
|
|
95
|
+
category: 'ai_thirdweb',
|
|
96
|
+
action,
|
|
97
|
+
requestTokens: tokens?.request,
|
|
98
|
+
responseTokens: tokens?.response,
|
|
99
|
+
creditsUsed: credits,
|
|
100
|
+
metadata,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Record Trading Agent usage (Engine AI)
|
|
106
|
+
*/
|
|
107
|
+
async trackTradingAgent(
|
|
108
|
+
action: string,
|
|
109
|
+
credits?: number,
|
|
110
|
+
metadata?: Record<string, any>
|
|
111
|
+
): Promise<boolean> {
|
|
112
|
+
return this.recordUsage({
|
|
113
|
+
userId: this.userId!,
|
|
114
|
+
category: 'ai_trading_engine',
|
|
115
|
+
action,
|
|
116
|
+
creditsUsed: credits,
|
|
117
|
+
metadata,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Record wallet operation usage
|
|
123
|
+
*/
|
|
124
|
+
async trackWallet(action: string, metadata?: Record<string, any>): Promise<boolean> {
|
|
125
|
+
return this.recordUsage({
|
|
126
|
+
userId: this.userId!,
|
|
127
|
+
category: 'wallet',
|
|
128
|
+
action,
|
|
129
|
+
metadata,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Record payment usage
|
|
135
|
+
*/
|
|
136
|
+
async trackPayment(action: string, metadata?: Record<string, any>): Promise<boolean> {
|
|
137
|
+
return this.recordUsage({
|
|
138
|
+
userId: this.userId!,
|
|
139
|
+
category: 'payment',
|
|
140
|
+
action,
|
|
141
|
+
metadata,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Record exchange usage (onramper)
|
|
147
|
+
*/
|
|
148
|
+
async trackOnramper(action: string, metadata?: Record<string, any>): Promise<boolean> {
|
|
149
|
+
return this.recordUsage({
|
|
150
|
+
userId: this.userId!,
|
|
151
|
+
category: 'exchange_onramper',
|
|
152
|
+
action,
|
|
153
|
+
metadata,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Record exchange usage (swap)
|
|
159
|
+
*/
|
|
160
|
+
async trackSwap(action: string, metadata?: Record<string, any>): Promise<boolean> {
|
|
161
|
+
return this.recordUsage({
|
|
162
|
+
userId: this.userId!,
|
|
163
|
+
category: 'exchange_swap',
|
|
164
|
+
action,
|
|
165
|
+
metadata,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Record any usage
|
|
171
|
+
*/
|
|
172
|
+
async recordUsage(record: UsageRecord): Promise<boolean> {
|
|
173
|
+
if (!record.userId) {
|
|
174
|
+
console.warn('[UsageService] No userId set, skipping usage tracking');
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
try {
|
|
179
|
+
const response = await fetch(`${this.baseUrl}/api/v1/usage/user`, {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: {
|
|
182
|
+
'Content-Type': 'application/json',
|
|
183
|
+
},
|
|
184
|
+
body: JSON.stringify({
|
|
185
|
+
userId: record.userId,
|
|
186
|
+
category: record.category,
|
|
187
|
+
action: record.action,
|
|
188
|
+
requestTokens: record.requestTokens || 0,
|
|
189
|
+
responseTokens: record.responseTokens || 0,
|
|
190
|
+
creditsUsed: record.creditsUsed || 0,
|
|
191
|
+
metadata: record.metadata || {},
|
|
192
|
+
}),
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (!response.ok) {
|
|
196
|
+
const error = await response.json().catch(() => ({}));
|
|
197
|
+
console.error('[UsageService] Failed to record usage:', error);
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return true;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error('[UsageService] Error recording usage:', error);
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Get AI usage summary for current user
|
|
210
|
+
*/
|
|
211
|
+
async getAIUsage(days: number = 30): Promise<UsageResponse | null> {
|
|
212
|
+
if (!this.userId) {
|
|
213
|
+
console.warn('[UsageService] No userId set');
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const response = await fetch(
|
|
219
|
+
`${this.baseUrl}/api/v1/usage/user?userId=${this.userId}&days=${days}`
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
const error = await response.json().catch(() => ({}));
|
|
224
|
+
console.error('[UsageService] Failed to get usage:', error);
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const result = await response.json();
|
|
229
|
+
return result.data;
|
|
230
|
+
} catch (error) {
|
|
231
|
+
console.error('[UsageService] Error getting usage:', error);
|
|
232
|
+
return null;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Singleton instance
|
|
238
|
+
let usageServiceInstance: UsageService | null = null;
|
|
239
|
+
|
|
240
|
+
export function getUsageService(): UsageService {
|
|
241
|
+
if (!usageServiceInstance) {
|
|
242
|
+
usageServiceInstance = new UsageService();
|
|
243
|
+
}
|
|
244
|
+
return usageServiceInstance;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function createUsageService(baseUrl?: string): UsageService {
|
|
248
|
+
return new UsageService(baseUrl);
|
|
249
|
+
}
|
package/.turbo/turbo-build.log
DELETED
|
File without changes
|
|
File without changes
|
package/dist/config/index.d.mts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ChainConfig } from '../types/index.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ONE SDK Configuration
|
|
5
|
-
*
|
|
6
|
-
* Chain data is fetched from ONE Engine API - no duplicates needed here.
|
|
7
|
-
* Engine is the single source of truth for 200+ EVM chains.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
interface OneConfig {
|
|
11
|
-
oneEngineUrl: string;
|
|
12
|
-
oneClientId: string;
|
|
13
|
-
oneSecretKey?: string;
|
|
14
|
-
supabaseUrl?: string;
|
|
15
|
-
supabaseAnonKey?: string;
|
|
16
|
-
thirdwebClientId?: string;
|
|
17
|
-
}
|
|
18
|
-
declare function initOneSDK(options: Partial<OneConfig>): void;
|
|
19
|
-
declare function getConfig(): OneConfig;
|
|
20
|
-
declare function isInitialized(): boolean;
|
|
21
|
-
declare function getEngineUrl(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Fetch chains from ONE Engine API
|
|
24
|
-
* Engine is the source of truth for 200+ EVM chains
|
|
25
|
-
*/
|
|
26
|
-
declare function fetchChains(options?: {
|
|
27
|
-
category?: 'mainnet' | 'l2' | 'testnet' | 'gaming' | 'recommended';
|
|
28
|
-
smartWallet?: boolean;
|
|
29
|
-
limit?: number;
|
|
30
|
-
}): Promise<ChainConfig[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Get all supported chains (cached)
|
|
33
|
-
*/
|
|
34
|
-
declare function getChains(): Promise<ChainConfig[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Get chain by ID
|
|
37
|
-
*/
|
|
38
|
-
declare function getChainById(chainId: number): Promise<ChainConfig | undefined>;
|
|
39
|
-
/**
|
|
40
|
-
* Get chain by name/shortName
|
|
41
|
-
*/
|
|
42
|
-
declare function getChainByName(name: string): Promise<ChainConfig | undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Get recommended chains for UI display
|
|
45
|
-
*/
|
|
46
|
-
declare function getRecommendedChains(): Promise<ChainConfig[]>;
|
|
47
|
-
/**
|
|
48
|
-
* Get chains with smart wallet support
|
|
49
|
-
*/
|
|
50
|
-
declare function getSmartWalletChains(): Promise<ChainConfig[]>;
|
|
51
|
-
declare const CHAIN_IDS: {
|
|
52
|
-
readonly ETHEREUM: 1;
|
|
53
|
-
readonly POLYGON: 137;
|
|
54
|
-
readonly BSC: 56;
|
|
55
|
-
readonly ARBITRUM: 42161;
|
|
56
|
-
readonly OPTIMISM: 10;
|
|
57
|
-
readonly BASE: 8453;
|
|
58
|
-
readonly AVALANCHE: 43114;
|
|
59
|
-
readonly ZKSYNC: 324;
|
|
60
|
-
readonly LINEA: 59144;
|
|
61
|
-
readonly SCROLL: 534352;
|
|
62
|
-
readonly BLAST: 81457;
|
|
63
|
-
readonly SEPOLIA: 11155111;
|
|
64
|
-
readonly BASE_SEPOLIA: 84532;
|
|
65
|
-
readonly ARBITRUM_SEPOLIA: 421614;
|
|
66
|
-
};
|
|
67
|
-
declare const DEFAULT_CHAIN_ID: 8453;
|
|
68
|
-
declare const TOKEN_NAMES: Record<string, string>;
|
|
69
|
-
declare const COINGECKO_IDS: Record<string, string>;
|
|
70
|
-
declare const CHAIN_CONFIGS: Record<string, ChainConfig>;
|
|
71
|
-
declare const SUPPORTED_CHAINS: string[];
|
|
72
|
-
declare function getChainConfig(chain: string): ChainConfig | undefined;
|
|
73
|
-
|
|
74
|
-
export { CHAIN_CONFIGS, CHAIN_IDS, COINGECKO_IDS, DEFAULT_CHAIN_ID, type OneConfig, SUPPORTED_CHAINS, TOKEN_NAMES, fetchChains, getChainById, getChainByName, getChainConfig, getChains, getConfig, getEngineUrl, getRecommendedChains, getSmartWalletChains, initOneSDK, isInitialized };
|
package/dist/config/index.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ChainConfig } from '../types/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ONE SDK Configuration
|
|
5
|
-
*
|
|
6
|
-
* Chain data is fetched from ONE Engine API - no duplicates needed here.
|
|
7
|
-
* Engine is the single source of truth for 200+ EVM chains.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
interface OneConfig {
|
|
11
|
-
oneEngineUrl: string;
|
|
12
|
-
oneClientId: string;
|
|
13
|
-
oneSecretKey?: string;
|
|
14
|
-
supabaseUrl?: string;
|
|
15
|
-
supabaseAnonKey?: string;
|
|
16
|
-
thirdwebClientId?: string;
|
|
17
|
-
}
|
|
18
|
-
declare function initOneSDK(options: Partial<OneConfig>): void;
|
|
19
|
-
declare function getConfig(): OneConfig;
|
|
20
|
-
declare function isInitialized(): boolean;
|
|
21
|
-
declare function getEngineUrl(): string;
|
|
22
|
-
/**
|
|
23
|
-
* Fetch chains from ONE Engine API
|
|
24
|
-
* Engine is the source of truth for 200+ EVM chains
|
|
25
|
-
*/
|
|
26
|
-
declare function fetchChains(options?: {
|
|
27
|
-
category?: 'mainnet' | 'l2' | 'testnet' | 'gaming' | 'recommended';
|
|
28
|
-
smartWallet?: boolean;
|
|
29
|
-
limit?: number;
|
|
30
|
-
}): Promise<ChainConfig[]>;
|
|
31
|
-
/**
|
|
32
|
-
* Get all supported chains (cached)
|
|
33
|
-
*/
|
|
34
|
-
declare function getChains(): Promise<ChainConfig[]>;
|
|
35
|
-
/**
|
|
36
|
-
* Get chain by ID
|
|
37
|
-
*/
|
|
38
|
-
declare function getChainById(chainId: number): Promise<ChainConfig | undefined>;
|
|
39
|
-
/**
|
|
40
|
-
* Get chain by name/shortName
|
|
41
|
-
*/
|
|
42
|
-
declare function getChainByName(name: string): Promise<ChainConfig | undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Get recommended chains for UI display
|
|
45
|
-
*/
|
|
46
|
-
declare function getRecommendedChains(): Promise<ChainConfig[]>;
|
|
47
|
-
/**
|
|
48
|
-
* Get chains with smart wallet support
|
|
49
|
-
*/
|
|
50
|
-
declare function getSmartWalletChains(): Promise<ChainConfig[]>;
|
|
51
|
-
declare const CHAIN_IDS: {
|
|
52
|
-
readonly ETHEREUM: 1;
|
|
53
|
-
readonly POLYGON: 137;
|
|
54
|
-
readonly BSC: 56;
|
|
55
|
-
readonly ARBITRUM: 42161;
|
|
56
|
-
readonly OPTIMISM: 10;
|
|
57
|
-
readonly BASE: 8453;
|
|
58
|
-
readonly AVALANCHE: 43114;
|
|
59
|
-
readonly ZKSYNC: 324;
|
|
60
|
-
readonly LINEA: 59144;
|
|
61
|
-
readonly SCROLL: 534352;
|
|
62
|
-
readonly BLAST: 81457;
|
|
63
|
-
readonly SEPOLIA: 11155111;
|
|
64
|
-
readonly BASE_SEPOLIA: 84532;
|
|
65
|
-
readonly ARBITRUM_SEPOLIA: 421614;
|
|
66
|
-
};
|
|
67
|
-
declare const DEFAULT_CHAIN_ID: 8453;
|
|
68
|
-
declare const TOKEN_NAMES: Record<string, string>;
|
|
69
|
-
declare const COINGECKO_IDS: Record<string, string>;
|
|
70
|
-
declare const CHAIN_CONFIGS: Record<string, ChainConfig>;
|
|
71
|
-
declare const SUPPORTED_CHAINS: string[];
|
|
72
|
-
declare function getChainConfig(chain: string): ChainConfig | undefined;
|
|
73
|
-
|
|
74
|
-
export { CHAIN_CONFIGS, CHAIN_IDS, COINGECKO_IDS, DEFAULT_CHAIN_ID, type OneConfig, SUPPORTED_CHAINS, TOKEN_NAMES, fetchChains, getChainById, getChainByName, getChainConfig, getChains, getConfig, getEngineUrl, getRecommendedChains, getSmartWalletChains, initOneSDK, isInitialized };
|