@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.
Files changed (83) hide show
  1. package/.turbo/turbo-build.log +0 -0
  2. package/.turbo/turbo-type-check.log +0 -0
  3. package/dist/config/index.d.mts +74 -0
  4. package/dist/config/index.d.ts +74 -0
  5. package/dist/config/index.js +242 -0
  6. package/dist/config/index.js.map +1 -0
  7. package/dist/config/index.mjs +224 -0
  8. package/dist/config/index.mjs.map +1 -0
  9. package/dist/engine-5ndtBaCr.d.ts +1039 -0
  10. package/dist/engine-CrlhH0nw.d.mts +1039 -0
  11. package/dist/hooks/index.d.mts +56 -0
  12. package/dist/hooks/index.d.ts +56 -0
  13. package/dist/hooks/index.js +1360 -0
  14. package/dist/hooks/index.js.map +1 -0
  15. package/dist/hooks/index.mjs +1356 -0
  16. package/dist/hooks/index.mjs.map +1 -0
  17. package/dist/index.d.mts +356 -0
  18. package/dist/index.d.ts +356 -0
  19. package/dist/index.js +5068 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/index.mjs +4949 -0
  22. package/dist/index.mjs.map +1 -0
  23. package/dist/price-CgqXPnT3.d.ts +13 -0
  24. package/dist/price-ClbLHHjv.d.mts +13 -0
  25. package/dist/providers/index.d.mts +121 -0
  26. package/dist/providers/index.d.ts +121 -0
  27. package/dist/providers/index.js +1642 -0
  28. package/dist/providers/index.js.map +1 -0
  29. package/dist/providers/index.mjs +1600 -0
  30. package/dist/providers/index.mjs.map +1 -0
  31. package/dist/react-native.d.mts +120 -0
  32. package/dist/react-native.d.ts +120 -0
  33. package/dist/react-native.js +1792 -0
  34. package/dist/react-native.js.map +1 -0
  35. package/dist/react-native.mjs +1755 -0
  36. package/dist/react-native.mjs.map +1 -0
  37. package/dist/services/index.d.mts +85 -0
  38. package/dist/services/index.d.ts +85 -0
  39. package/dist/services/index.js +1466 -0
  40. package/dist/services/index.js.map +1 -0
  41. package/dist/services/index.mjs +1458 -0
  42. package/dist/services/index.mjs.map +1 -0
  43. package/dist/types/index.d.mts +759 -0
  44. package/dist/types/index.d.ts +759 -0
  45. package/dist/types/index.js +4 -0
  46. package/dist/types/index.js.map +1 -0
  47. package/dist/types/index.mjs +3 -0
  48. package/dist/types/index.mjs.map +1 -0
  49. package/dist/utils/index.d.mts +36 -0
  50. package/dist/utils/index.d.ts +36 -0
  51. package/dist/utils/index.js +164 -0
  52. package/dist/utils/index.js.map +1 -0
  53. package/dist/utils/index.mjs +142 -0
  54. package/dist/utils/index.mjs.map +1 -0
  55. package/package.json +101 -0
  56. package/src/components/OneConnectButton.tsx +143 -0
  57. package/src/components/OneNFTGallery.tsx +324 -0
  58. package/src/components/OneOfframpWidget.tsx +660 -0
  59. package/src/components/OneOnrampWidget.tsx +596 -0
  60. package/src/components/OnePayWidget.tsx +160 -0
  61. package/src/components/OneReceiveWidget.tsx +272 -0
  62. package/src/components/OneSendWidget.tsx +248 -0
  63. package/src/components/OneSwapWidget.tsx +715 -0
  64. package/src/components/OneTransactionButton.tsx +150 -0
  65. package/src/components/OneWalletBalance.tsx +354 -0
  66. package/src/components/index.ts +24 -0
  67. package/src/config/index.ts +299 -0
  68. package/src/hooks/index.ts +2 -0
  69. package/src/hooks/useTokenPrice.ts +162 -0
  70. package/src/hooks/useWalletBalance.ts +98 -0
  71. package/src/index.ts +193 -0
  72. package/src/providers/OneProvider.tsx +452 -0
  73. package/src/providers/ThirdwebProvider.tsx +203 -0
  74. package/src/providers/index.ts +26 -0
  75. package/src/react-native.ts +378 -0
  76. package/src/services/engine.ts +1854 -0
  77. package/src/services/index.ts +30 -0
  78. package/src/services/price.ts +164 -0
  79. package/src/services/supabase.ts +180 -0
  80. package/src/types/index.ts +887 -0
  81. package/src/utils/index.ts +200 -0
  82. package/tsconfig.json +22 -0
  83. package/tsup.config.ts +25 -0
@@ -0,0 +1,30 @@
1
+ // ===== ONE Engine Client (Main API Gateway) =====
2
+ export {
3
+ OneEngineClient,
4
+ createOneEngineClient,
5
+ } from './engine';
6
+
7
+ export type {
8
+ // Auth
9
+ EngineAuthResponse,
10
+ // Wallet
11
+ EngineWalletBalance,
12
+ EngineTransactionRequest,
13
+ EngineTransactionResponse,
14
+ // Onramp
15
+ OnrampSessionRequest,
16
+ OnrampSession,
17
+ OnrampQuote,
18
+ OnrampTransaction,
19
+ // Swap
20
+ SwapQuoteRequest,
21
+ SwapQuote,
22
+ SwapExecuteRequest,
23
+ SwapResult,
24
+ } from './engine';
25
+
26
+ // ===== Supabase (for direct DB access if needed) =====
27
+ export { SupabaseService, createSupabaseClient, getSupabaseClient } from './supabase';
28
+
29
+ // ===== Price Service (fallback for offline/cache) =====
30
+ export { PriceService, priceService } from './price';
@@ -0,0 +1,164 @@
1
+ import { COINGECKO_IDS } from '../config';
2
+ import type { TokenPrice } from '../types';
3
+
4
+ const COINGECKO_API = 'https://api.coingecko.com/api/v3';
5
+
6
+ // Fallback prices when API is unavailable
7
+ const FALLBACK_PRICES: Record<string, number> = {
8
+ ETH: 3500,
9
+ BTC: 95000,
10
+ BNB: 700,
11
+ MATIC: 0.5,
12
+ AVAX: 40,
13
+ USDT: 1,
14
+ USDC: 1,
15
+ DAI: 1,
16
+ WBTC: 95000,
17
+ WETH: 3500,
18
+ ARB: 1.2,
19
+ OP: 2.5,
20
+ LINK: 20,
21
+ UNI: 12,
22
+ AAVE: 250,
23
+ SOL: 200,
24
+ };
25
+
26
+ export class PriceService {
27
+ private cache: Map<string, { price: TokenPrice; timestamp: number }> = new Map();
28
+ private cacheTTL = 60 * 1000; // 1 minute cache
29
+
30
+ async getPrice(symbol: string): Promise<TokenPrice> {
31
+ const upperSymbol = symbol.toUpperCase();
32
+
33
+ // Check cache first
34
+ const cached = this.cache.get(upperSymbol);
35
+ if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
36
+ return cached.price;
37
+ }
38
+
39
+ const coinId = COINGECKO_IDS[upperSymbol];
40
+ if (!coinId) {
41
+ return this.getFallbackPrice(upperSymbol);
42
+ }
43
+
44
+ try {
45
+ const response = await fetch(
46
+ `${COINGECKO_API}/simple/price?ids=${coinId}&vs_currencies=usd&include_24hr_change=true&include_market_cap=true&include_24hr_vol=true`,
47
+ { headers: { Accept: 'application/json' } }
48
+ );
49
+
50
+ if (!response.ok) {
51
+ throw new Error(`CoinGecko API error: ${response.status}`);
52
+ }
53
+
54
+ const data = await response.json();
55
+ const coinData = data[coinId];
56
+
57
+ if (!coinData) {
58
+ return this.getFallbackPrice(upperSymbol);
59
+ }
60
+
61
+ const change24h = coinData.usd_24h_change || 0;
62
+ const price: TokenPrice = {
63
+ symbol: upperSymbol,
64
+ price: coinData.usd || 0,
65
+ change24h,
66
+ changePercent24h: change24h,
67
+ priceChange24h: change24h,
68
+ marketCap: coinData.usd_market_cap,
69
+ volume24h: coinData.usd_24h_vol,
70
+ };
71
+
72
+ this.cache.set(upperSymbol, { price, timestamp: Date.now() });
73
+ return price;
74
+ } catch (error) {
75
+ console.warn(`Failed to fetch price for ${upperSymbol}:`, error);
76
+ return this.getFallbackPrice(upperSymbol);
77
+ }
78
+ }
79
+
80
+ async getPrices(symbols: string[]): Promise<Record<string, TokenPrice>> {
81
+ const results: Record<string, TokenPrice> = {};
82
+
83
+ // Group symbols by whether they have CoinGecko IDs
84
+ const withIds: string[] = [];
85
+ const withoutIds: string[] = [];
86
+
87
+ for (const symbol of symbols) {
88
+ const upper = symbol.toUpperCase();
89
+ if (COINGECKO_IDS[upper]) {
90
+ withIds.push(upper);
91
+ } else {
92
+ withoutIds.push(upper);
93
+ }
94
+ }
95
+
96
+ // Handle symbols without CoinGecko IDs
97
+ for (const symbol of withoutIds) {
98
+ results[symbol] = this.getFallbackPrice(symbol);
99
+ }
100
+
101
+ if (withIds.length === 0) {
102
+ return results;
103
+ }
104
+
105
+ // Fetch prices in batch for symbols with IDs
106
+ const coinIds = withIds.map((s) => COINGECKO_IDS[s]).join(',');
107
+
108
+ try {
109
+ const response = await fetch(
110
+ `${COINGECKO_API}/simple/price?ids=${coinIds}&vs_currencies=usd&include_24hr_change=true`,
111
+ { headers: { Accept: 'application/json' } }
112
+ );
113
+
114
+ if (!response.ok) {
115
+ throw new Error(`CoinGecko API error: ${response.status}`);
116
+ }
117
+
118
+ const data = await response.json();
119
+
120
+ for (const symbol of withIds) {
121
+ const coinId = COINGECKO_IDS[symbol];
122
+ const coinData = data[coinId];
123
+
124
+ if (coinData) {
125
+ const change24h = coinData.usd_24h_change || 0;
126
+ results[symbol] = {
127
+ symbol,
128
+ price: coinData.usd || 0,
129
+ change24h,
130
+ changePercent24h: change24h,
131
+ priceChange24h: change24h,
132
+ };
133
+ } else {
134
+ results[symbol] = this.getFallbackPrice(symbol);
135
+ }
136
+ }
137
+ } catch (error) {
138
+ console.warn('Failed to fetch batch prices:', error);
139
+ for (const symbol of withIds) {
140
+ results[symbol] = this.getFallbackPrice(symbol);
141
+ }
142
+ }
143
+
144
+ return results;
145
+ }
146
+
147
+ private getFallbackPrice(symbol: string): TokenPrice {
148
+ const price = FALLBACK_PRICES[symbol] || 0;
149
+ return {
150
+ symbol,
151
+ price,
152
+ change24h: 0,
153
+ changePercent24h: 0,
154
+ priceChange24h: 0,
155
+ };
156
+ }
157
+
158
+ clearCache(): void {
159
+ this.cache.clear();
160
+ }
161
+ }
162
+
163
+ // Singleton instance
164
+ export const priceService = new PriceService();
@@ -0,0 +1,180 @@
1
+ import { createClient, SupabaseClient } from '@supabase/supabase-js';
2
+ import { getConfig } from '../config';
3
+
4
+ let supabaseInstance: SupabaseClient | null = null;
5
+
6
+ export function createSupabaseClient(url?: string, anonKey?: string): SupabaseClient {
7
+ const config = getConfig();
8
+ const supabaseUrl = url || config.supabaseUrl;
9
+ const supabaseAnonKey = anonKey || config.supabaseAnonKey;
10
+
11
+ if (!supabaseUrl || !supabaseAnonKey) {
12
+ throw new Error('Supabase URL and Anon Key are required');
13
+ }
14
+
15
+ return createClient(supabaseUrl, supabaseAnonKey, {
16
+ auth: {
17
+ autoRefreshToken: true,
18
+ persistSession: true,
19
+ detectSessionInUrl: true,
20
+ },
21
+ });
22
+ }
23
+
24
+ export function getSupabaseClient(): SupabaseClient {
25
+ if (!supabaseInstance) {
26
+ supabaseInstance = createSupabaseClient();
27
+ }
28
+ return supabaseInstance;
29
+ }
30
+
31
+ export class SupabaseService {
32
+ private client: SupabaseClient;
33
+
34
+ constructor(client?: SupabaseClient) {
35
+ this.client = client || getSupabaseClient();
36
+ }
37
+
38
+ // ===== Auth Methods =====
39
+ async signInWithEmail(email: string) {
40
+ const { data, error } = await this.client.auth.signInWithOtp({
41
+ email,
42
+ options: {
43
+ shouldCreateUser: true,
44
+ },
45
+ });
46
+ return { data, error };
47
+ }
48
+
49
+ async verifyOtp(email: string, token: string) {
50
+ const { data, error } = await this.client.auth.verifyOtp({
51
+ email,
52
+ token,
53
+ type: 'email',
54
+ });
55
+ return { data, error };
56
+ }
57
+
58
+ async signOut() {
59
+ const { error } = await this.client.auth.signOut();
60
+ return { error };
61
+ }
62
+
63
+ async getSession() {
64
+ const { data, error } = await this.client.auth.getSession();
65
+ return { session: data.session, error };
66
+ }
67
+
68
+ async getUser() {
69
+ const { data, error } = await this.client.auth.getUser();
70
+ return { user: data.user, error };
71
+ }
72
+
73
+ // ===== User Profile Methods =====
74
+ async getUserProfile(userId: string) {
75
+ const { data, error } = await this.client
76
+ .from('user_profiles')
77
+ .select('*')
78
+ .eq('user_id', userId)
79
+ .single();
80
+ return { data, error };
81
+ }
82
+
83
+ async updateUserProfile(userId: string, updates: Record<string, any>) {
84
+ const { data, error } = await this.client
85
+ .from('user_profiles')
86
+ .update(updates)
87
+ .eq('user_id', userId)
88
+ .select()
89
+ .single();
90
+ return { data, error };
91
+ }
92
+
93
+ // ===== Transaction Methods =====
94
+ async getTransactions(userId: string, limit = 50) {
95
+ const { data, error } = await this.client
96
+ .from('transactions')
97
+ .select('*')
98
+ .eq('user_id', userId)
99
+ .order('created_at', { ascending: false })
100
+ .limit(limit);
101
+ return { data, error };
102
+ }
103
+
104
+ async createTransaction(transaction: Record<string, any>) {
105
+ const { data, error } = await this.client
106
+ .from('transactions')
107
+ .insert(transaction)
108
+ .select()
109
+ .single();
110
+ return { data, error };
111
+ }
112
+
113
+ // ===== AI Trading Methods =====
114
+ async getStrategies(status = 'active') {
115
+ const { data, error } = await this.client
116
+ .from('ai_strategies')
117
+ .select('*')
118
+ .eq('status', status)
119
+ .order('total_aum', { ascending: false });
120
+ return { data, error };
121
+ }
122
+
123
+ async getStrategyById(strategyId: string) {
124
+ const { data, error } = await this.client
125
+ .from('ai_strategies')
126
+ .select('*')
127
+ .eq('id', strategyId)
128
+ .single();
129
+ return { data, error };
130
+ }
131
+
132
+ async getUserOrders(userId: string) {
133
+ const { data, error } = await this.client
134
+ .from('ai_orders')
135
+ .select(`*, ai_strategies (name)`)
136
+ .eq('user_id', userId)
137
+ .order('created_at', { ascending: false });
138
+ return { data, error };
139
+ }
140
+
141
+ async createOrder(order: Record<string, any>) {
142
+ const { data, error } = await this.client
143
+ .from('ai_orders')
144
+ .insert(order)
145
+ .select()
146
+ .single();
147
+ return { data, error };
148
+ }
149
+
150
+ // ===== Card Methods =====
151
+ async getUserCards(userId: string) {
152
+ const { data, error } = await this.client
153
+ .from('cards')
154
+ .select('*')
155
+ .eq('user_id', userId)
156
+ .order('created_at', { ascending: false });
157
+ return { data, error };
158
+ }
159
+
160
+ // ===== Realtime Subscriptions =====
161
+ subscribeToTransactions(userId: string, callback: (payload: any) => void) {
162
+ return this.client
163
+ .channel(`transactions:${userId}`)
164
+ .on(
165
+ 'postgres_changes',
166
+ {
167
+ event: '*',
168
+ schema: 'public',
169
+ table: 'transactions',
170
+ filter: `user_id=eq.${userId}`,
171
+ },
172
+ callback
173
+ )
174
+ .subscribe();
175
+ }
176
+
177
+ unsubscribe(channel: ReturnType<typeof this.client.channel>) {
178
+ return this.client.removeChannel(channel);
179
+ }
180
+ }