@unifold/core 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -22,7 +22,7 @@ declare function getIconUrl(iconPath: string): string;
22
22
  declare function getIconUrlWithCdn(iconPath: string, assetCdnUrl?: string): string;
23
23
  interface Wallet {
24
24
  id: string;
25
- chain_type: "ethereum" | "solana" | "bitcoin";
25
+ chain_type: "ethereum" | "solana" | "bitcoin" | "algorand";
26
26
  address_type: string | null;
27
27
  address: string;
28
28
  destination_chain_type: string;
@@ -51,7 +51,7 @@ declare function createDepositAddress(overrides?: Partial<CreateDepositAddressRe
51
51
  /**
52
52
  * Get wallet address for a specific chain type
53
53
  */
54
- declare function getWalletByChainType(wallets: Wallet[], chainType: "ethereum" | "solana" | "bitcoin"): Wallet | undefined;
54
+ declare function getWalletByChainType(wallets: Wallet[], chainType: "ethereum" | "solana" | "bitcoin" | "algorand"): Wallet | undefined;
55
55
  interface AutoSwapRequest {
56
56
  wallet_id: string;
57
57
  origin_currency: string;
@@ -117,6 +117,7 @@ interface AutoSwapResponse {
117
117
  };
118
118
  source_currency?: string;
119
119
  destination_currency?: string;
120
+ estimated_processing_time?: number | null;
120
121
  }
121
122
  declare const SOLANA_USDC_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
122
123
  interface QueryExecutionsRequest {
@@ -157,91 +158,170 @@ interface SupportedDepositTokensResponse {
157
158
  * Get supported deposit tokens
158
159
  * @param publishableKey - Optional publishable key, defaults to configured key
159
160
  */
160
- declare function getSupportedDepositTokens(publishableKey?: string): Promise<SupportedDepositTokensResponse>;
161
- interface MeldQuote {
161
+ declare function getSupportedDepositTokens(publishableKey?: string, options?: {
162
+ destination_token_address?: string;
163
+ destination_chain_id?: string;
164
+ destination_chain_type?: string;
165
+ }): Promise<SupportedDepositTokensResponse>;
166
+ interface TokenMetadata {
167
+ symbol: string;
168
+ name: string;
169
+ icon_url: string;
170
+ icon_urls: IconUrl[];
171
+ chain_name: string;
172
+ chain_type: string;
173
+ chain_id: string;
174
+ token_address: string;
175
+ decimals: number;
176
+ chain_icon_url: string;
177
+ chain_icon_urls: IconUrl[];
178
+ }
179
+ interface GetTokenMetadataRequest {
180
+ chain_type: string;
181
+ chain_id: string;
182
+ token_address: string;
183
+ }
184
+ /**
185
+ * Get token metadata for a specific token
186
+ * @param request - Token query parameters (chain_type, chain_id, token_address)
187
+ * @param publishableKey - Optional publishable key, defaults to configured key
188
+ */
189
+ declare function getTokenMetadata(request: GetTokenMetadataRequest, publishableKey?: string): Promise<TokenMetadata | null>;
190
+ /**
191
+ * Get the preferred icon URL from an array of icon URLs
192
+ * @param iconUrls - Array of icon URLs with format information
193
+ * @param preferredFormat - Preferred format ("svg" or "png"), defaults to "svg"
194
+ * @returns The URL string for the preferred format, or first available if preferred not found
195
+ */
196
+ declare function getPreferredIconUrl(iconUrls: IconUrl[] | undefined, preferredFormat?: "svg" | "png"): string | undefined;
197
+ interface FiatCurrency {
198
+ currency_code: string;
199
+ name: string;
200
+ icon_url: string;
201
+ icon_urls: IconUrl[];
202
+ country_codes: string[];
203
+ default_amount: number;
204
+ minimum_amount: number;
205
+ maximum_amount: number;
206
+ suggested_amounts: number[];
207
+ }
208
+ interface FiatCurrenciesResponse {
209
+ data: FiatCurrency[];
210
+ preferred: string[];
211
+ }
212
+ /**
213
+ * Get supported fiat currencies
214
+ * @param publishableKey - Optional publishable key, defaults to configured key
215
+ */
216
+ declare function getFiatCurrencies(publishableKey?: string): Promise<FiatCurrenciesResponse>;
217
+ interface OnrampQuote {
162
218
  transaction_type: string;
163
- payment_method_type: string;
164
219
  source_amount: number;
165
220
  source_amount_without_fees: number;
166
221
  fiat_amount_without_fees: number;
167
222
  destination_amount_without_fees: number | null;
168
- source_currency_code: string;
223
+ source_currency: string;
169
224
  country_code: string;
170
225
  total_fee: number;
171
226
  network_fee: number;
172
227
  transaction_fee: number;
173
228
  destination_amount: number;
174
- destination_currency_code: string;
229
+ destination_currency: string;
230
+ destination_network: string;
175
231
  exchange_rate: number;
232
+ payment_method_type: string;
176
233
  customer_score: number;
177
234
  service_provider: string;
178
235
  service_provider_display_name: string;
236
+ icon_url: string;
237
+ icon_urls: IconUrl[];
179
238
  institution_name: string | null;
180
- low_kyc: boolean | null;
239
+ low_kyc: boolean;
181
240
  partner_fee: number | null;
182
- icon_url: string;
183
241
  }
184
- interface MeldQuotesRequest {
242
+ interface OnrampQuotesRequest {
185
243
  country_code: string;
186
- destination_currency_code: string;
187
244
  source_amount: string;
188
- source_currency_code: string;
245
+ source_currency: string;
246
+ destination_currency: string;
247
+ destination_network: string;
248
+ subdivision_code?: string;
189
249
  }
190
- interface MeldQuotesResponse {
191
- data: MeldQuote[];
250
+ interface OnrampQuotesResponse {
251
+ data: OnrampQuote[];
192
252
  }
193
253
  /**
194
- * Get Meld onramp quotes
195
- * @param request - Meld quotes request
254
+ * Get unified onramp quotes from all providers
255
+ * @param request - Onramp quotes request
196
256
  * @param publishableKey - Optional publishable key, defaults to configured key
197
257
  */
198
- declare function getMeldQuotes(request: MeldQuotesRequest, publishableKey?: string): Promise<MeldQuotesResponse>;
199
- interface MeldSessionRequest {
258
+ declare function getOnrampQuotes(request: OnrampQuotesRequest, publishableKey?: string): Promise<OnrampQuotesResponse>;
259
+ interface OnrampSessionRequest {
200
260
  service_provider: string;
201
261
  country_code: string;
202
- destination_currency_code: string;
203
- source_currency_code: string;
204
- wallet_address: string;
262
+ source_currency: string;
205
263
  source_amount: string;
264
+ destination_currency: string;
265
+ destination_network: string;
266
+ wallet_address: string;
267
+ subdivision_code?: string;
268
+ redirect_url?: string;
206
269
  }
207
- interface MeldSessionResponse {
208
- id: string;
209
- external_session_id: string | null;
210
- external_customer_id: string | null;
211
- customer_id: string;
212
- widget_url: string;
213
- service_provider_widget_url: string;
214
- token: string;
270
+ interface OnrampSessionResponse {
271
+ url: string;
272
+ service_provider: string;
215
273
  }
216
274
  /**
217
- * Create a Meld onramp session
218
- * @param request - Meld session request
275
+ * Create a unified onramp session
276
+ * @param request - Onramp session request
219
277
  * @param publishableKey - Optional publishable key, defaults to configured key
220
278
  */
221
- declare function createMeldSession(request: MeldSessionRequest, publishableKey?: string): Promise<MeldSessionResponse>;
279
+ declare function createOnrampSession(request: OnrampSessionRequest, publishableKey?: string): Promise<OnrampSessionResponse>;
222
280
  /**
223
- * Get the preferred icon URL from an array of icon URLs
224
- * @param iconUrls - Array of icon URLs with format information
225
- * @param preferredFormat - Preferred format ("svg" or "png"), defaults to "svg"
226
- * @returns The URL string for the preferred format, or first available if preferred not found
281
+ * Generate a URL for the sessions/start endpoint that redirects to the onramp provider.
282
+ * This is useful for avoiding popup blockers by opening the URL directly via anchor tag.
283
+ * @param request - Onramp session request (same parameters as createOnrampSession)
284
+ * @param publishableKey - Publishable key (required)
285
+ * @returns URL string that can be used in an anchor tag or window.open()
227
286
  */
228
- declare function getPreferredIconUrl(iconUrls: IconUrl[] | undefined, preferredFormat?: "svg" | "png"): string | undefined;
229
- interface FiatCurrency {
230
- currency_code: string;
231
- name: string;
287
+ declare function getOnrampSessionStartUrl(request: OnrampSessionRequest, publishableKey: string): string;
288
+ interface DefaultTokenChain {
289
+ icon_url: string;
290
+ icon_urls: IconUrl[];
291
+ chain_id: string;
292
+ chain_name: string;
293
+ chain_type: string;
294
+ }
295
+ interface DefaultTokenMetadata {
232
296
  icon_url: string;
233
- icon_urls?: IconUrl[];
234
- country_codes?: string[];
297
+ icon_urls: IconUrl[];
298
+ decimals: number;
299
+ symbol: string;
300
+ name: string;
301
+ token_address: string;
302
+ chain_id: string;
303
+ chain_type: string;
304
+ chain_name: string;
305
+ chain: DefaultTokenChain;
235
306
  }
236
- interface FiatCurrenciesResponse {
237
- data: FiatCurrency[];
238
- preferred: string[];
307
+ interface DefaultTokenResponse {
308
+ destination_network: string;
309
+ destination_currency: string;
310
+ destination_token_metadata: DefaultTokenMetadata;
311
+ estimated_processing_time: number | null;
239
312
  }
240
313
  /**
241
- * Get supported fiat currencies
314
+ * Get default onramp token for a given token/chain combination
315
+ * @param params - Query parameters
242
316
  * @param publishableKey - Optional publishable key, defaults to configured key
243
317
  */
244
- declare function getFiatCurrencies(publishableKey?: string): Promise<FiatCurrenciesResponse>;
318
+ declare function getDefaultOnrampToken(params: {
319
+ country_code?: string;
320
+ subdivision_code?: string;
321
+ token_address: string;
322
+ chain_id: string;
323
+ chain_type: string;
324
+ }, publishableKey?: string): Promise<DefaultTokenResponse>;
245
325
  interface TokenChainIconUrl {
246
326
  url: string;
247
327
  format: string;
@@ -306,6 +386,93 @@ interface IpAddressResponse {
306
386
  * This is a public endpoint that doesn't require authentication
307
387
  */
308
388
  declare function getIpAddress(): Promise<IpAddressResponse>;
389
+ interface TokenIconUrl {
390
+ url: string;
391
+ format: string;
392
+ }
393
+ interface TokenInfo {
394
+ symbol: string;
395
+ name: string;
396
+ icon_url: string;
397
+ icon_urls: TokenIconUrl[];
398
+ token_address: string;
399
+ chain_id: string;
400
+ chain_name: string;
401
+ chain_type: string;
402
+ decimals: number;
403
+ minimum_deposit_amount_usd: number;
404
+ chain_icon_url: string;
405
+ chain_icon_urls: TokenIconUrl[];
406
+ }
407
+ interface TokenBalance {
408
+ amount: string;
409
+ amount_usd: string | null;
410
+ exchange_rate: string | null;
411
+ is_eligible: boolean;
412
+ token: TokenInfo;
413
+ }
414
+ interface AddressBalancesResponse {
415
+ address: string;
416
+ chain_type: string;
417
+ balances: TokenBalance[];
418
+ }
419
+ /**
420
+ * Get token balances for a wallet address
421
+ * Returns balances for all supported deposit tokens on the specified chain type
422
+ * @param address - Wallet address to check balances for
423
+ * @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
424
+ * @param publishableKey - Optional publishable key, defaults to configured key
425
+ */
426
+ declare function getAddressBalances(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', publishableKey?: string): Promise<AddressBalancesResponse>;
427
+ interface AddressBalanceResponse {
428
+ address: string;
429
+ chain_type: string;
430
+ chain_id: string;
431
+ token_address: string;
432
+ balance: TokenBalance | null;
433
+ }
434
+ /**
435
+ * Get balance for a specific token on a specific chain
436
+ * Returns the balance for a single token, or null if not found or zero balance
437
+ * @param address - Wallet address to check balance for
438
+ * @param chainType - Chain type ('ethereum', 'solana', or 'bitcoin')
439
+ * @param chainId - Chain ID (e.g., "1" for Ethereum mainnet)
440
+ * @param tokenAddress - Token contract address or "native" for native tokens
441
+ * @param publishableKey - Optional publishable key, defaults to configured key
442
+ */
443
+ declare function getAddressBalance(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
444
+ interface VerifyAddressRequest {
445
+ chain_type: string;
446
+ chain_id: string;
447
+ token_address: string;
448
+ recipient_address: string;
449
+ }
450
+ /**
451
+ * Standard error codes for address validation failures.
452
+ * Used by frontend to display localized error messages.
453
+ */
454
+ type AddressValidationFailureCode = 'token_not_supported' | 'not_opted_in' | 'insufficient_balance' | 'account_not_found' | 'validation_error';
455
+ interface AddressValidationMetadata {
456
+ chain_name?: string;
457
+ token_symbol?: string;
458
+ }
459
+ interface VerifyAddressResponse {
460
+ valid: boolean;
461
+ /** Standardized error code for frontend i18n */
462
+ failure_code?: AddressValidationFailureCode;
463
+ /** Metadata for message interpolation */
464
+ metadata?: AddressValidationMetadata;
465
+ }
466
+ /**
467
+ * Verify if a recipient address can receive funds for a given chain/token
468
+ * This is useful to check before confirming a transfer, especially for Algorand
469
+ * where recipients must opt-in to assets before receiving them.
470
+ *
471
+ * @param request - Verification request with chain_type, chain_id, token_address, recipient_address
472
+ * @param publishableKey - Optional publishable key, defaults to configured key
473
+ * @returns Verification result with valid status and reason if invalid
474
+ */
475
+ declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
309
476
 
310
477
  /**
311
478
  * User IP information interface
@@ -401,4 +568,4 @@ declare const i18n: {
401
568
  };
402
569
  type I18nStrings = typeof i18n;
403
570
 
404
- export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
571
+ export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp, verifyRecipientAddress };
package/dist/index.d.ts CHANGED
@@ -22,7 +22,7 @@ declare function getIconUrl(iconPath: string): string;
22
22
  declare function getIconUrlWithCdn(iconPath: string, assetCdnUrl?: string): string;
23
23
  interface Wallet {
24
24
  id: string;
25
- chain_type: "ethereum" | "solana" | "bitcoin";
25
+ chain_type: "ethereum" | "solana" | "bitcoin" | "algorand";
26
26
  address_type: string | null;
27
27
  address: string;
28
28
  destination_chain_type: string;
@@ -51,7 +51,7 @@ declare function createDepositAddress(overrides?: Partial<CreateDepositAddressRe
51
51
  /**
52
52
  * Get wallet address for a specific chain type
53
53
  */
54
- declare function getWalletByChainType(wallets: Wallet[], chainType: "ethereum" | "solana" | "bitcoin"): Wallet | undefined;
54
+ declare function getWalletByChainType(wallets: Wallet[], chainType: "ethereum" | "solana" | "bitcoin" | "algorand"): Wallet | undefined;
55
55
  interface AutoSwapRequest {
56
56
  wallet_id: string;
57
57
  origin_currency: string;
@@ -117,6 +117,7 @@ interface AutoSwapResponse {
117
117
  };
118
118
  source_currency?: string;
119
119
  destination_currency?: string;
120
+ estimated_processing_time?: number | null;
120
121
  }
121
122
  declare const SOLANA_USDC_ADDRESS = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
122
123
  interface QueryExecutionsRequest {
@@ -157,91 +158,170 @@ interface SupportedDepositTokensResponse {
157
158
  * Get supported deposit tokens
158
159
  * @param publishableKey - Optional publishable key, defaults to configured key
159
160
  */
160
- declare function getSupportedDepositTokens(publishableKey?: string): Promise<SupportedDepositTokensResponse>;
161
- interface MeldQuote {
161
+ declare function getSupportedDepositTokens(publishableKey?: string, options?: {
162
+ destination_token_address?: string;
163
+ destination_chain_id?: string;
164
+ destination_chain_type?: string;
165
+ }): Promise<SupportedDepositTokensResponse>;
166
+ interface TokenMetadata {
167
+ symbol: string;
168
+ name: string;
169
+ icon_url: string;
170
+ icon_urls: IconUrl[];
171
+ chain_name: string;
172
+ chain_type: string;
173
+ chain_id: string;
174
+ token_address: string;
175
+ decimals: number;
176
+ chain_icon_url: string;
177
+ chain_icon_urls: IconUrl[];
178
+ }
179
+ interface GetTokenMetadataRequest {
180
+ chain_type: string;
181
+ chain_id: string;
182
+ token_address: string;
183
+ }
184
+ /**
185
+ * Get token metadata for a specific token
186
+ * @param request - Token query parameters (chain_type, chain_id, token_address)
187
+ * @param publishableKey - Optional publishable key, defaults to configured key
188
+ */
189
+ declare function getTokenMetadata(request: GetTokenMetadataRequest, publishableKey?: string): Promise<TokenMetadata | null>;
190
+ /**
191
+ * Get the preferred icon URL from an array of icon URLs
192
+ * @param iconUrls - Array of icon URLs with format information
193
+ * @param preferredFormat - Preferred format ("svg" or "png"), defaults to "svg"
194
+ * @returns The URL string for the preferred format, or first available if preferred not found
195
+ */
196
+ declare function getPreferredIconUrl(iconUrls: IconUrl[] | undefined, preferredFormat?: "svg" | "png"): string | undefined;
197
+ interface FiatCurrency {
198
+ currency_code: string;
199
+ name: string;
200
+ icon_url: string;
201
+ icon_urls: IconUrl[];
202
+ country_codes: string[];
203
+ default_amount: number;
204
+ minimum_amount: number;
205
+ maximum_amount: number;
206
+ suggested_amounts: number[];
207
+ }
208
+ interface FiatCurrenciesResponse {
209
+ data: FiatCurrency[];
210
+ preferred: string[];
211
+ }
212
+ /**
213
+ * Get supported fiat currencies
214
+ * @param publishableKey - Optional publishable key, defaults to configured key
215
+ */
216
+ declare function getFiatCurrencies(publishableKey?: string): Promise<FiatCurrenciesResponse>;
217
+ interface OnrampQuote {
162
218
  transaction_type: string;
163
- payment_method_type: string;
164
219
  source_amount: number;
165
220
  source_amount_without_fees: number;
166
221
  fiat_amount_without_fees: number;
167
222
  destination_amount_without_fees: number | null;
168
- source_currency_code: string;
223
+ source_currency: string;
169
224
  country_code: string;
170
225
  total_fee: number;
171
226
  network_fee: number;
172
227
  transaction_fee: number;
173
228
  destination_amount: number;
174
- destination_currency_code: string;
229
+ destination_currency: string;
230
+ destination_network: string;
175
231
  exchange_rate: number;
232
+ payment_method_type: string;
176
233
  customer_score: number;
177
234
  service_provider: string;
178
235
  service_provider_display_name: string;
236
+ icon_url: string;
237
+ icon_urls: IconUrl[];
179
238
  institution_name: string | null;
180
- low_kyc: boolean | null;
239
+ low_kyc: boolean;
181
240
  partner_fee: number | null;
182
- icon_url: string;
183
241
  }
184
- interface MeldQuotesRequest {
242
+ interface OnrampQuotesRequest {
185
243
  country_code: string;
186
- destination_currency_code: string;
187
244
  source_amount: string;
188
- source_currency_code: string;
245
+ source_currency: string;
246
+ destination_currency: string;
247
+ destination_network: string;
248
+ subdivision_code?: string;
189
249
  }
190
- interface MeldQuotesResponse {
191
- data: MeldQuote[];
250
+ interface OnrampQuotesResponse {
251
+ data: OnrampQuote[];
192
252
  }
193
253
  /**
194
- * Get Meld onramp quotes
195
- * @param request - Meld quotes request
254
+ * Get unified onramp quotes from all providers
255
+ * @param request - Onramp quotes request
196
256
  * @param publishableKey - Optional publishable key, defaults to configured key
197
257
  */
198
- declare function getMeldQuotes(request: MeldQuotesRequest, publishableKey?: string): Promise<MeldQuotesResponse>;
199
- interface MeldSessionRequest {
258
+ declare function getOnrampQuotes(request: OnrampQuotesRequest, publishableKey?: string): Promise<OnrampQuotesResponse>;
259
+ interface OnrampSessionRequest {
200
260
  service_provider: string;
201
261
  country_code: string;
202
- destination_currency_code: string;
203
- source_currency_code: string;
204
- wallet_address: string;
262
+ source_currency: string;
205
263
  source_amount: string;
264
+ destination_currency: string;
265
+ destination_network: string;
266
+ wallet_address: string;
267
+ subdivision_code?: string;
268
+ redirect_url?: string;
206
269
  }
207
- interface MeldSessionResponse {
208
- id: string;
209
- external_session_id: string | null;
210
- external_customer_id: string | null;
211
- customer_id: string;
212
- widget_url: string;
213
- service_provider_widget_url: string;
214
- token: string;
270
+ interface OnrampSessionResponse {
271
+ url: string;
272
+ service_provider: string;
215
273
  }
216
274
  /**
217
- * Create a Meld onramp session
218
- * @param request - Meld session request
275
+ * Create a unified onramp session
276
+ * @param request - Onramp session request
219
277
  * @param publishableKey - Optional publishable key, defaults to configured key
220
278
  */
221
- declare function createMeldSession(request: MeldSessionRequest, publishableKey?: string): Promise<MeldSessionResponse>;
279
+ declare function createOnrampSession(request: OnrampSessionRequest, publishableKey?: string): Promise<OnrampSessionResponse>;
222
280
  /**
223
- * Get the preferred icon URL from an array of icon URLs
224
- * @param iconUrls - Array of icon URLs with format information
225
- * @param preferredFormat - Preferred format ("svg" or "png"), defaults to "svg"
226
- * @returns The URL string for the preferred format, or first available if preferred not found
281
+ * Generate a URL for the sessions/start endpoint that redirects to the onramp provider.
282
+ * This is useful for avoiding popup blockers by opening the URL directly via anchor tag.
283
+ * @param request - Onramp session request (same parameters as createOnrampSession)
284
+ * @param publishableKey - Publishable key (required)
285
+ * @returns URL string that can be used in an anchor tag or window.open()
227
286
  */
228
- declare function getPreferredIconUrl(iconUrls: IconUrl[] | undefined, preferredFormat?: "svg" | "png"): string | undefined;
229
- interface FiatCurrency {
230
- currency_code: string;
231
- name: string;
287
+ declare function getOnrampSessionStartUrl(request: OnrampSessionRequest, publishableKey: string): string;
288
+ interface DefaultTokenChain {
289
+ icon_url: string;
290
+ icon_urls: IconUrl[];
291
+ chain_id: string;
292
+ chain_name: string;
293
+ chain_type: string;
294
+ }
295
+ interface DefaultTokenMetadata {
232
296
  icon_url: string;
233
- icon_urls?: IconUrl[];
234
- country_codes?: string[];
297
+ icon_urls: IconUrl[];
298
+ decimals: number;
299
+ symbol: string;
300
+ name: string;
301
+ token_address: string;
302
+ chain_id: string;
303
+ chain_type: string;
304
+ chain_name: string;
305
+ chain: DefaultTokenChain;
235
306
  }
236
- interface FiatCurrenciesResponse {
237
- data: FiatCurrency[];
238
- preferred: string[];
307
+ interface DefaultTokenResponse {
308
+ destination_network: string;
309
+ destination_currency: string;
310
+ destination_token_metadata: DefaultTokenMetadata;
311
+ estimated_processing_time: number | null;
239
312
  }
240
313
  /**
241
- * Get supported fiat currencies
314
+ * Get default onramp token for a given token/chain combination
315
+ * @param params - Query parameters
242
316
  * @param publishableKey - Optional publishable key, defaults to configured key
243
317
  */
244
- declare function getFiatCurrencies(publishableKey?: string): Promise<FiatCurrenciesResponse>;
318
+ declare function getDefaultOnrampToken(params: {
319
+ country_code?: string;
320
+ subdivision_code?: string;
321
+ token_address: string;
322
+ chain_id: string;
323
+ chain_type: string;
324
+ }, publishableKey?: string): Promise<DefaultTokenResponse>;
245
325
  interface TokenChainIconUrl {
246
326
  url: string;
247
327
  format: string;
@@ -306,6 +386,93 @@ interface IpAddressResponse {
306
386
  * This is a public endpoint that doesn't require authentication
307
387
  */
308
388
  declare function getIpAddress(): Promise<IpAddressResponse>;
389
+ interface TokenIconUrl {
390
+ url: string;
391
+ format: string;
392
+ }
393
+ interface TokenInfo {
394
+ symbol: string;
395
+ name: string;
396
+ icon_url: string;
397
+ icon_urls: TokenIconUrl[];
398
+ token_address: string;
399
+ chain_id: string;
400
+ chain_name: string;
401
+ chain_type: string;
402
+ decimals: number;
403
+ minimum_deposit_amount_usd: number;
404
+ chain_icon_url: string;
405
+ chain_icon_urls: TokenIconUrl[];
406
+ }
407
+ interface TokenBalance {
408
+ amount: string;
409
+ amount_usd: string | null;
410
+ exchange_rate: string | null;
411
+ is_eligible: boolean;
412
+ token: TokenInfo;
413
+ }
414
+ interface AddressBalancesResponse {
415
+ address: string;
416
+ chain_type: string;
417
+ balances: TokenBalance[];
418
+ }
419
+ /**
420
+ * Get token balances for a wallet address
421
+ * Returns balances for all supported deposit tokens on the specified chain type
422
+ * @param address - Wallet address to check balances for
423
+ * @param chainType - Chain type to fetch balances for ('ethereum', 'solana', or 'bitcoin')
424
+ * @param publishableKey - Optional publishable key, defaults to configured key
425
+ */
426
+ declare function getAddressBalances(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', publishableKey?: string): Promise<AddressBalancesResponse>;
427
+ interface AddressBalanceResponse {
428
+ address: string;
429
+ chain_type: string;
430
+ chain_id: string;
431
+ token_address: string;
432
+ balance: TokenBalance | null;
433
+ }
434
+ /**
435
+ * Get balance for a specific token on a specific chain
436
+ * Returns the balance for a single token, or null if not found or zero balance
437
+ * @param address - Wallet address to check balance for
438
+ * @param chainType - Chain type ('ethereum', 'solana', or 'bitcoin')
439
+ * @param chainId - Chain ID (e.g., "1" for Ethereum mainnet)
440
+ * @param tokenAddress - Token contract address or "native" for native tokens
441
+ * @param publishableKey - Optional publishable key, defaults to configured key
442
+ */
443
+ declare function getAddressBalance(address: string, chainType: 'ethereum' | 'solana' | 'bitcoin', chainId: string, tokenAddress: string, publishableKey?: string): Promise<AddressBalanceResponse>;
444
+ interface VerifyAddressRequest {
445
+ chain_type: string;
446
+ chain_id: string;
447
+ token_address: string;
448
+ recipient_address: string;
449
+ }
450
+ /**
451
+ * Standard error codes for address validation failures.
452
+ * Used by frontend to display localized error messages.
453
+ */
454
+ type AddressValidationFailureCode = 'token_not_supported' | 'not_opted_in' | 'insufficient_balance' | 'account_not_found' | 'validation_error';
455
+ interface AddressValidationMetadata {
456
+ chain_name?: string;
457
+ token_symbol?: string;
458
+ }
459
+ interface VerifyAddressResponse {
460
+ valid: boolean;
461
+ /** Standardized error code for frontend i18n */
462
+ failure_code?: AddressValidationFailureCode;
463
+ /** Metadata for message interpolation */
464
+ metadata?: AddressValidationMetadata;
465
+ }
466
+ /**
467
+ * Verify if a recipient address can receive funds for a given chain/token
468
+ * This is useful to check before confirming a transfer, especially for Algorand
469
+ * where recipients must opt-in to assets before receiving them.
470
+ *
471
+ * @param request - Verification request with chain_type, chain_id, token_address, recipient_address
472
+ * @param publishableKey - Optional publishable key, defaults to configured key
473
+ * @returns Verification result with valid status and reason if invalid
474
+ */
475
+ declare function verifyRecipientAddress(request: VerifyAddressRequest, publishableKey?: string): Promise<VerifyAddressResponse>;
309
476
 
310
477
  /**
311
478
  * User IP information interface
@@ -401,4 +568,4 @@ declare const i18n: {
401
568
  };
402
569
  type I18nStrings = typeof i18n;
403
570
 
404
- export { type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type MeldQuote, type MeldQuotesRequest, type MeldQuotesResponse, type MeldSessionRequest, type MeldSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type UserIpInfo, type Wallet, createDepositAddress, createMeldSession, getApiBaseUrl, getChainName, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getMeldQuotes, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp };
571
+ export { type AddressBalanceResponse, type AddressBalancesResponse, type AddressValidationFailureCode, type AddressValidationMetadata, type AutoSwapRequest, type AutoSwapResponse, type CreateDepositAddressRequest, type DefaultTokenChain, type DefaultTokenMetadata, type DefaultTokenResponse, type DepositAddressResponse, ExecutionStatus, type FeaturedToken, type FiatCurrenciesResponse, type FiatCurrency, type I18nStrings, type IconUrl, type IpAddressResponse, type OnrampQuote, type OnrampQuotesRequest, type OnrampQuotesResponse, type OnrampSessionRequest, type OnrampSessionResponse, type PaymentNetwork, type ProjectConfigResponse, type QueryExecutionsRequest, type QueryExecutionsResponse, SOLANA_USDC_ADDRESS, type SupportedChain, type SupportedDepositTokensResponse, type SupportedToken, type TokenBalance, type TokenChain, type TokenChainIconUrl, type TokenChainsResponse, type TokenIconUrl, type TokenInfo, type TokenMetadata, type UserIpInfo, type VerifyAddressRequest, type VerifyAddressResponse, type Wallet, createDepositAddress, createOnrampSession, getAddressBalance, getAddressBalances, getApiBaseUrl, getChainName, getDefaultOnrampToken, getFiatCurrencies, getIconUrl, getIconUrlWithCdn, getIpAddress, getOnrampQuotes, getOnrampSessionStartUrl, getPreferredIconUrl, getProjectConfig, getSupportedDepositTokens, getTokenChains, getTokenMetadata, getWalletByChainType, i18n, queryExecutions, setApiConfig, useUserIp, verifyRecipientAddress };
package/dist/index.js CHANGED
@@ -23,23 +23,29 @@ __export(index_exports, {
23
23
  ExecutionStatus: () => ExecutionStatus,
24
24
  SOLANA_USDC_ADDRESS: () => SOLANA_USDC_ADDRESS,
25
25
  createDepositAddress: () => createDepositAddress,
26
- createMeldSession: () => createMeldSession,
26
+ createOnrampSession: () => createOnrampSession,
27
+ getAddressBalance: () => getAddressBalance,
28
+ getAddressBalances: () => getAddressBalances,
27
29
  getApiBaseUrl: () => getApiBaseUrl,
28
30
  getChainName: () => getChainName,
31
+ getDefaultOnrampToken: () => getDefaultOnrampToken,
29
32
  getFiatCurrencies: () => getFiatCurrencies,
30
33
  getIconUrl: () => getIconUrl,
31
34
  getIconUrlWithCdn: () => getIconUrlWithCdn,
32
35
  getIpAddress: () => getIpAddress,
33
- getMeldQuotes: () => getMeldQuotes,
36
+ getOnrampQuotes: () => getOnrampQuotes,
37
+ getOnrampSessionStartUrl: () => getOnrampSessionStartUrl,
34
38
  getPreferredIconUrl: () => getPreferredIconUrl,
35
39
  getProjectConfig: () => getProjectConfig,
36
40
  getSupportedDepositTokens: () => getSupportedDepositTokens,
37
41
  getTokenChains: () => getTokenChains,
42
+ getTokenMetadata: () => getTokenMetadata,
38
43
  getWalletByChainType: () => getWalletByChainType,
39
44
  i18n: () => i18n,
40
45
  queryExecutions: () => queryExecutions,
41
46
  setApiConfig: () => setApiConfig,
42
- useUserIp: () => useUserIp
47
+ useUserIp: () => useUserIp,
48
+ verifyRecipientAddress: () => verifyRecipientAddress
43
49
  });
44
50
  module.exports = __toCommonJS(index_exports);
45
51
 
@@ -158,11 +164,42 @@ async function queryExecutions(externalUserId, publishableKey) {
158
164
  }
159
165
  return response.json();
160
166
  }
161
- async function getSupportedDepositTokens(publishableKey) {
167
+ async function getSupportedDepositTokens(publishableKey, options) {
162
168
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
163
169
  validatePublishableKey(pk);
170
+ let url = `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`;
171
+ if (options?.destination_token_address && options?.destination_chain_id && options?.destination_chain_type) {
172
+ const params = new URLSearchParams({
173
+ destination_token_address: options.destination_token_address,
174
+ destination_chain_id: options.destination_chain_id,
175
+ destination_chain_type: options.destination_chain_type
176
+ });
177
+ url = `${url}?${params.toString()}`;
178
+ }
179
+ const response = await fetch(url, {
180
+ method: "GET",
181
+ headers: {
182
+ accept: "application/json",
183
+ "x-publishable-key": pk
184
+ }
185
+ });
186
+ if (!response.ok) {
187
+ throw new Error(
188
+ `Failed to fetch supported deposit tokens: ${response.statusText}`
189
+ );
190
+ }
191
+ return response.json();
192
+ }
193
+ async function getTokenMetadata(request, publishableKey) {
194
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
195
+ validatePublishableKey(pk);
196
+ const params = new URLSearchParams({
197
+ chainType: request.chain_type,
198
+ chainId: request.chain_id,
199
+ tokenAddress: request.token_address
200
+ });
164
201
  const response = await fetch(
165
- `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`,
202
+ `${API_BASE_URL}/v1/public/tokens/token?${params.toString()}`,
166
203
  {
167
204
  method: "GET",
168
205
  headers: {
@@ -172,17 +209,43 @@ async function getSupportedDepositTokens(publishableKey) {
172
209
  }
173
210
  );
174
211
  if (!response.ok) {
175
- throw new Error(
176
- `Failed to fetch supported deposit tokens: ${response.statusText}`
177
- );
212
+ throw new Error(`Failed to fetch token metadata: ${response.statusText}`);
213
+ }
214
+ return response.json();
215
+ }
216
+ function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
217
+ if (!iconUrls || iconUrls.length === 0) {
218
+ return void 0;
219
+ }
220
+ const preferred = iconUrls.find((icon) => icon.format === preferredFormat);
221
+ if (preferred) {
222
+ return preferred.url;
223
+ }
224
+ return iconUrls[0]?.url;
225
+ }
226
+ async function getFiatCurrencies(publishableKey) {
227
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
228
+ validatePublishableKey(pk);
229
+ const response = await fetch(
230
+ `${API_BASE_URL}/v1/public/onramps/fiat_currencies`,
231
+ {
232
+ method: "GET",
233
+ headers: {
234
+ accept: "application/json",
235
+ "x-publishable-key": pk
236
+ }
237
+ }
238
+ );
239
+ if (!response.ok) {
240
+ throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
178
241
  }
179
242
  return response.json();
180
243
  }
181
- async function getMeldQuotes(request, publishableKey) {
244
+ async function getOnrampQuotes(request, publishableKey) {
182
245
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
183
246
  validatePublishableKey(pk);
184
247
  const response = await fetch(
185
- `${API_BASE_URL}/v1/public/onramps/meld/quotes`,
248
+ `${API_BASE_URL}/v1/public/onramps/quotes`,
186
249
  {
187
250
  method: "POST",
188
251
  headers: {
@@ -194,15 +257,15 @@ async function getMeldQuotes(request, publishableKey) {
194
257
  }
195
258
  );
196
259
  if (!response.ok) {
197
- throw new Error(`Failed to fetch Meld quotes: ${response.statusText}`);
260
+ throw new Error(`Failed to fetch onramp quotes: ${response.statusText}`);
198
261
  }
199
262
  return response.json();
200
263
  }
201
- async function createMeldSession(request, publishableKey) {
264
+ async function createOnrampSession(request, publishableKey) {
202
265
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
203
266
  validatePublishableKey(pk);
204
267
  const response = await fetch(
205
- `${API_BASE_URL}/v1/public/onramps/meld/sessions`,
268
+ `${API_BASE_URL}/v1/public/onramps/sessions`,
206
269
  {
207
270
  method: "POST",
208
271
  headers: {
@@ -214,25 +277,36 @@ async function createMeldSession(request, publishableKey) {
214
277
  }
215
278
  );
216
279
  if (!response.ok) {
217
- throw new Error(`Failed to create Meld session: ${response.statusText}`);
280
+ throw new Error(`Failed to create onramp session: ${response.statusText}`);
218
281
  }
219
282
  return response.json();
220
283
  }
221
- function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
222
- if (!iconUrls || iconUrls.length === 0) {
223
- return void 0;
284
+ function getOnrampSessionStartUrl(request, publishableKey) {
285
+ const params = new URLSearchParams();
286
+ params.append("publishable_key", publishableKey);
287
+ params.append("service_provider", request.service_provider);
288
+ params.append("country_code", request.country_code);
289
+ params.append("source_currency", request.source_currency);
290
+ params.append("source_amount", request.source_amount);
291
+ params.append("destination_currency", request.destination_currency);
292
+ params.append("destination_network", request.destination_network);
293
+ params.append("wallet_address", request.wallet_address);
294
+ if (request.subdivision_code) {
295
+ params.append("subdivision_code", request.subdivision_code);
224
296
  }
225
- const preferred = iconUrls.find((icon) => icon.format === preferredFormat);
226
- if (preferred) {
227
- return preferred.url;
228
- }
229
- return iconUrls[0]?.url;
297
+ return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
230
298
  }
231
- async function getFiatCurrencies(publishableKey) {
299
+ async function getDefaultOnrampToken(params, publishableKey) {
232
300
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
233
301
  validatePublishableKey(pk);
302
+ const queryParams = new URLSearchParams();
303
+ if (params.country_code) queryParams.append("country_code", params.country_code);
304
+ if (params.subdivision_code) queryParams.append("subdivision_code", params.subdivision_code);
305
+ queryParams.append("token_address", params.token_address);
306
+ queryParams.append("chain_id", params.chain_id);
307
+ queryParams.append("chain_type", params.chain_type);
234
308
  const response = await fetch(
235
- `${API_BASE_URL}/v1/public/onramps/fiat_currencies`,
309
+ `${API_BASE_URL}/v1/public/onramps/default_token?${queryParams.toString()}`,
236
310
  {
237
311
  method: "GET",
238
312
  headers: {
@@ -242,7 +316,7 @@ async function getFiatCurrencies(publishableKey) {
242
316
  }
243
317
  );
244
318
  if (!response.ok) {
245
- throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
319
+ throw new Error(`Failed to fetch default onramp token: ${response.statusText}`);
246
320
  }
247
321
  return response.json();
248
322
  }
@@ -259,10 +333,14 @@ async function getTokenChains() {
259
333
  return response.json();
260
334
  }
261
335
  function getChainName(chains, chainType, chainId) {
336
+ if (!chainType && !chainId) return "Unknown";
337
+ const target = chains.find((c) => c.chain_id === chainId && c.chain_type === chainType);
338
+ if (target) return target.chain_name;
262
339
  const byId = chains.find((c) => c.chain_id === chainId);
263
340
  if (byId) return byId.chain_name;
264
341
  const byType = chains.find((c) => c.chain_type === chainType);
265
342
  if (byType) return byType.chain_name;
343
+ if (!chainType) return chainId || "Unknown";
266
344
  return chainType.charAt(0).toUpperCase() + chainType.slice(1);
267
345
  }
268
346
  async function getProjectConfig(publishableKey) {
@@ -296,6 +374,71 @@ async function getIpAddress() {
296
374
  }
297
375
  return response.json();
298
376
  }
377
+ async function getAddressBalances(address, chainType, publishableKey) {
378
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
379
+ validatePublishableKey(pk);
380
+ const url = `${API_BASE_URL}/v1/public/addresses/balances`;
381
+ const response = await fetch(url, {
382
+ method: "POST",
383
+ headers: {
384
+ "Content-Type": "application/json",
385
+ accept: "application/json",
386
+ "x-publishable-key": pk
387
+ },
388
+ body: JSON.stringify({
389
+ address,
390
+ chain_type: chainType
391
+ })
392
+ });
393
+ if (!response.ok) {
394
+ throw new Error(`Failed to fetch address balances: ${response.statusText}`);
395
+ }
396
+ const data = await response.json();
397
+ return data;
398
+ }
399
+ async function getAddressBalance(address, chainType, chainId, tokenAddress, publishableKey) {
400
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
401
+ validatePublishableKey(pk);
402
+ const url = `${API_BASE_URL}/v1/public/addresses/balance`;
403
+ const response = await fetch(url, {
404
+ method: "POST",
405
+ headers: {
406
+ "Content-Type": "application/json",
407
+ accept: "application/json",
408
+ "x-publishable-key": pk
409
+ },
410
+ body: JSON.stringify({
411
+ address,
412
+ chain_type: chainType,
413
+ chain_id: chainId,
414
+ token_address: tokenAddress
415
+ })
416
+ });
417
+ if (!response.ok) {
418
+ throw new Error(`Failed to fetch address balance: ${response.statusText}`);
419
+ }
420
+ const data = await response.json();
421
+ return data;
422
+ }
423
+ async function verifyRecipientAddress(request, publishableKey) {
424
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
425
+ validatePublishableKey(pk);
426
+ const response = await fetch(`${API_BASE_URL}/v1/public/addresses/verify`, {
427
+ method: "POST",
428
+ headers: {
429
+ accept: "application/json",
430
+ "x-publishable-key": pk,
431
+ "Content-Type": "application/json"
432
+ },
433
+ body: JSON.stringify(request)
434
+ });
435
+ if (!response.ok) {
436
+ throw new Error(
437
+ `Failed to verify recipient address: ${response.statusText}`
438
+ );
439
+ }
440
+ return response.json();
441
+ }
299
442
 
300
443
  // src/hooks/use-user-ip.ts
301
444
  var import_react_query = require("@tanstack/react-query");
@@ -405,21 +548,27 @@ var i18n = en_default;
405
548
  ExecutionStatus,
406
549
  SOLANA_USDC_ADDRESS,
407
550
  createDepositAddress,
408
- createMeldSession,
551
+ createOnrampSession,
552
+ getAddressBalance,
553
+ getAddressBalances,
409
554
  getApiBaseUrl,
410
555
  getChainName,
556
+ getDefaultOnrampToken,
411
557
  getFiatCurrencies,
412
558
  getIconUrl,
413
559
  getIconUrlWithCdn,
414
560
  getIpAddress,
415
- getMeldQuotes,
561
+ getOnrampQuotes,
562
+ getOnrampSessionStartUrl,
416
563
  getPreferredIconUrl,
417
564
  getProjectConfig,
418
565
  getSupportedDepositTokens,
419
566
  getTokenChains,
567
+ getTokenMetadata,
420
568
  getWalletByChainType,
421
569
  i18n,
422
570
  queryExecutions,
423
571
  setApiConfig,
424
- useUserIp
572
+ useUserIp,
573
+ verifyRecipientAddress
425
574
  });
package/dist/index.mjs CHANGED
@@ -113,11 +113,42 @@ async function queryExecutions(externalUserId, publishableKey) {
113
113
  }
114
114
  return response.json();
115
115
  }
116
- async function getSupportedDepositTokens(publishableKey) {
116
+ async function getSupportedDepositTokens(publishableKey, options) {
117
117
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
118
118
  validatePublishableKey(pk);
119
+ let url = `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`;
120
+ if (options?.destination_token_address && options?.destination_chain_id && options?.destination_chain_type) {
121
+ const params = new URLSearchParams({
122
+ destination_token_address: options.destination_token_address,
123
+ destination_chain_id: options.destination_chain_id,
124
+ destination_chain_type: options.destination_chain_type
125
+ });
126
+ url = `${url}?${params.toString()}`;
127
+ }
128
+ const response = await fetch(url, {
129
+ method: "GET",
130
+ headers: {
131
+ accept: "application/json",
132
+ "x-publishable-key": pk
133
+ }
134
+ });
135
+ if (!response.ok) {
136
+ throw new Error(
137
+ `Failed to fetch supported deposit tokens: ${response.statusText}`
138
+ );
139
+ }
140
+ return response.json();
141
+ }
142
+ async function getTokenMetadata(request, publishableKey) {
143
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
144
+ validatePublishableKey(pk);
145
+ const params = new URLSearchParams({
146
+ chainType: request.chain_type,
147
+ chainId: request.chain_id,
148
+ tokenAddress: request.token_address
149
+ });
119
150
  const response = await fetch(
120
- `${API_BASE_URL}/v1/public/tokens/supported_deposit_tokens`,
151
+ `${API_BASE_URL}/v1/public/tokens/token?${params.toString()}`,
121
152
  {
122
153
  method: "GET",
123
154
  headers: {
@@ -127,17 +158,43 @@ async function getSupportedDepositTokens(publishableKey) {
127
158
  }
128
159
  );
129
160
  if (!response.ok) {
130
- throw new Error(
131
- `Failed to fetch supported deposit tokens: ${response.statusText}`
132
- );
161
+ throw new Error(`Failed to fetch token metadata: ${response.statusText}`);
162
+ }
163
+ return response.json();
164
+ }
165
+ function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
166
+ if (!iconUrls || iconUrls.length === 0) {
167
+ return void 0;
168
+ }
169
+ const preferred = iconUrls.find((icon) => icon.format === preferredFormat);
170
+ if (preferred) {
171
+ return preferred.url;
172
+ }
173
+ return iconUrls[0]?.url;
174
+ }
175
+ async function getFiatCurrencies(publishableKey) {
176
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
177
+ validatePublishableKey(pk);
178
+ const response = await fetch(
179
+ `${API_BASE_URL}/v1/public/onramps/fiat_currencies`,
180
+ {
181
+ method: "GET",
182
+ headers: {
183
+ accept: "application/json",
184
+ "x-publishable-key": pk
185
+ }
186
+ }
187
+ );
188
+ if (!response.ok) {
189
+ throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
133
190
  }
134
191
  return response.json();
135
192
  }
136
- async function getMeldQuotes(request, publishableKey) {
193
+ async function getOnrampQuotes(request, publishableKey) {
137
194
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
138
195
  validatePublishableKey(pk);
139
196
  const response = await fetch(
140
- `${API_BASE_URL}/v1/public/onramps/meld/quotes`,
197
+ `${API_BASE_URL}/v1/public/onramps/quotes`,
141
198
  {
142
199
  method: "POST",
143
200
  headers: {
@@ -149,15 +206,15 @@ async function getMeldQuotes(request, publishableKey) {
149
206
  }
150
207
  );
151
208
  if (!response.ok) {
152
- throw new Error(`Failed to fetch Meld quotes: ${response.statusText}`);
209
+ throw new Error(`Failed to fetch onramp quotes: ${response.statusText}`);
153
210
  }
154
211
  return response.json();
155
212
  }
156
- async function createMeldSession(request, publishableKey) {
213
+ async function createOnrampSession(request, publishableKey) {
157
214
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
158
215
  validatePublishableKey(pk);
159
216
  const response = await fetch(
160
- `${API_BASE_URL}/v1/public/onramps/meld/sessions`,
217
+ `${API_BASE_URL}/v1/public/onramps/sessions`,
161
218
  {
162
219
  method: "POST",
163
220
  headers: {
@@ -169,25 +226,36 @@ async function createMeldSession(request, publishableKey) {
169
226
  }
170
227
  );
171
228
  if (!response.ok) {
172
- throw new Error(`Failed to create Meld session: ${response.statusText}`);
229
+ throw new Error(`Failed to create onramp session: ${response.statusText}`);
173
230
  }
174
231
  return response.json();
175
232
  }
176
- function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
177
- if (!iconUrls || iconUrls.length === 0) {
178
- return void 0;
233
+ function getOnrampSessionStartUrl(request, publishableKey) {
234
+ const params = new URLSearchParams();
235
+ params.append("publishable_key", publishableKey);
236
+ params.append("service_provider", request.service_provider);
237
+ params.append("country_code", request.country_code);
238
+ params.append("source_currency", request.source_currency);
239
+ params.append("source_amount", request.source_amount);
240
+ params.append("destination_currency", request.destination_currency);
241
+ params.append("destination_network", request.destination_network);
242
+ params.append("wallet_address", request.wallet_address);
243
+ if (request.subdivision_code) {
244
+ params.append("subdivision_code", request.subdivision_code);
179
245
  }
180
- const preferred = iconUrls.find((icon) => icon.format === preferredFormat);
181
- if (preferred) {
182
- return preferred.url;
183
- }
184
- return iconUrls[0]?.url;
246
+ return `${API_BASE_URL}/v1/public/onramps/sessions/start?${params.toString()}`;
185
247
  }
186
- async function getFiatCurrencies(publishableKey) {
248
+ async function getDefaultOnrampToken(params, publishableKey) {
187
249
  const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
188
250
  validatePublishableKey(pk);
251
+ const queryParams = new URLSearchParams();
252
+ if (params.country_code) queryParams.append("country_code", params.country_code);
253
+ if (params.subdivision_code) queryParams.append("subdivision_code", params.subdivision_code);
254
+ queryParams.append("token_address", params.token_address);
255
+ queryParams.append("chain_id", params.chain_id);
256
+ queryParams.append("chain_type", params.chain_type);
189
257
  const response = await fetch(
190
- `${API_BASE_URL}/v1/public/onramps/fiat_currencies`,
258
+ `${API_BASE_URL}/v1/public/onramps/default_token?${queryParams.toString()}`,
191
259
  {
192
260
  method: "GET",
193
261
  headers: {
@@ -197,7 +265,7 @@ async function getFiatCurrencies(publishableKey) {
197
265
  }
198
266
  );
199
267
  if (!response.ok) {
200
- throw new Error(`Failed to fetch fiat currencies: ${response.statusText}`);
268
+ throw new Error(`Failed to fetch default onramp token: ${response.statusText}`);
201
269
  }
202
270
  return response.json();
203
271
  }
@@ -214,10 +282,14 @@ async function getTokenChains() {
214
282
  return response.json();
215
283
  }
216
284
  function getChainName(chains, chainType, chainId) {
285
+ if (!chainType && !chainId) return "Unknown";
286
+ const target = chains.find((c) => c.chain_id === chainId && c.chain_type === chainType);
287
+ if (target) return target.chain_name;
217
288
  const byId = chains.find((c) => c.chain_id === chainId);
218
289
  if (byId) return byId.chain_name;
219
290
  const byType = chains.find((c) => c.chain_type === chainType);
220
291
  if (byType) return byType.chain_name;
292
+ if (!chainType) return chainId || "Unknown";
221
293
  return chainType.charAt(0).toUpperCase() + chainType.slice(1);
222
294
  }
223
295
  async function getProjectConfig(publishableKey) {
@@ -251,6 +323,71 @@ async function getIpAddress() {
251
323
  }
252
324
  return response.json();
253
325
  }
326
+ async function getAddressBalances(address, chainType, publishableKey) {
327
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
328
+ validatePublishableKey(pk);
329
+ const url = `${API_BASE_URL}/v1/public/addresses/balances`;
330
+ const response = await fetch(url, {
331
+ method: "POST",
332
+ headers: {
333
+ "Content-Type": "application/json",
334
+ accept: "application/json",
335
+ "x-publishable-key": pk
336
+ },
337
+ body: JSON.stringify({
338
+ address,
339
+ chain_type: chainType
340
+ })
341
+ });
342
+ if (!response.ok) {
343
+ throw new Error(`Failed to fetch address balances: ${response.statusText}`);
344
+ }
345
+ const data = await response.json();
346
+ return data;
347
+ }
348
+ async function getAddressBalance(address, chainType, chainId, tokenAddress, publishableKey) {
349
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
350
+ validatePublishableKey(pk);
351
+ const url = `${API_BASE_URL}/v1/public/addresses/balance`;
352
+ const response = await fetch(url, {
353
+ method: "POST",
354
+ headers: {
355
+ "Content-Type": "application/json",
356
+ accept: "application/json",
357
+ "x-publishable-key": pk
358
+ },
359
+ body: JSON.stringify({
360
+ address,
361
+ chain_type: chainType,
362
+ chain_id: chainId,
363
+ token_address: tokenAddress
364
+ })
365
+ });
366
+ if (!response.ok) {
367
+ throw new Error(`Failed to fetch address balance: ${response.statusText}`);
368
+ }
369
+ const data = await response.json();
370
+ return data;
371
+ }
372
+ async function verifyRecipientAddress(request, publishableKey) {
373
+ const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
374
+ validatePublishableKey(pk);
375
+ const response = await fetch(`${API_BASE_URL}/v1/public/addresses/verify`, {
376
+ method: "POST",
377
+ headers: {
378
+ accept: "application/json",
379
+ "x-publishable-key": pk,
380
+ "Content-Type": "application/json"
381
+ },
382
+ body: JSON.stringify(request)
383
+ });
384
+ if (!response.ok) {
385
+ throw new Error(
386
+ `Failed to verify recipient address: ${response.statusText}`
387
+ );
388
+ }
389
+ return response.json();
390
+ }
254
391
 
255
392
  // src/hooks/use-user-ip.ts
256
393
  import { useQuery } from "@tanstack/react-query";
@@ -359,21 +496,27 @@ export {
359
496
  ExecutionStatus,
360
497
  SOLANA_USDC_ADDRESS,
361
498
  createDepositAddress,
362
- createMeldSession,
499
+ createOnrampSession,
500
+ getAddressBalance,
501
+ getAddressBalances,
363
502
  getApiBaseUrl,
364
503
  getChainName,
504
+ getDefaultOnrampToken,
365
505
  getFiatCurrencies,
366
506
  getIconUrl,
367
507
  getIconUrlWithCdn,
368
508
  getIpAddress,
369
- getMeldQuotes,
509
+ getOnrampQuotes,
510
+ getOnrampSessionStartUrl,
370
511
  getPreferredIconUrl,
371
512
  getProjectConfig,
372
513
  getSupportedDepositTokens,
373
514
  getTokenChains,
515
+ getTokenMetadata,
374
516
  getWalletByChainType,
375
517
  i18n,
376
518
  queryExecutions,
377
519
  setApiConfig,
378
- useUserIp
520
+ useUserIp,
521
+ verifyRecipientAddress
379
522
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unifold/core",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Unifold Core SDK - Core types, API client, and business logic",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",