@@ -11,7 +11,7 @@ import {
11
11
type GasRecommendationResponse ,
12
12
type GetStatusRequest ,
13
13
type LiFiStep ,
14
- type QuoteRequest ,
14
+ type QuoteRequest as QuoteRequestFromAmount ,
15
15
type RelayRequest ,
16
16
type RelayResponse ,
17
17
type RelayResponseData ,
@@ -42,6 +42,13 @@ import { request } from '../request.js'
42
42
import { isRoutesRequest , isStep } from '../typeguards.js'
43
43
import { withDedupe } from '../utils/withDedupe.js'
44
44
45
+ type QuoteRequest =
46
+ | QuoteRequestFromAmount
47
+ | ( Omit < QuoteRequestFromAmount , 'fromAmount' > & {
48
+ toAmount : string
49
+ fromAmount ?: never
50
+ } )
51
+
45
52
/**
46
53
* Get a quote for a token transfer
47
54
* @param params - The configuration of the requested quote
@@ -57,7 +64,6 @@ export const getQuote = async (
57
64
'fromChain' ,
58
65
'fromToken' ,
59
66
'fromAddress' ,
60
- 'fromAmount' ,
61
67
'toChain' ,
62
68
'toToken' ,
63
69
]
@@ -70,6 +76,29 @@ export const getQuote = async (
70
76
)
71
77
}
72
78
}
79
+ if (
80
+ ( ! ( 'fromAmount' in params ) || ! params . fromAmount ) &&
81
+ ( ! ( 'toAmount' in params ) || ! params . toAmount )
82
+ ) {
83
+ throw new SDKError (
84
+ new ValidationError (
85
+ 'Required parameter "fromAmount" or "toAmount" is missing.'
86
+ )
87
+ )
88
+ }
89
+ if (
90
+ 'fromAmount' in params &&
91
+ 'toAmount' in params &&
92
+ params . fromAmount &&
93
+ // @ts -expect-error type-agnostic runtime check
94
+ params . toAmount
95
+ ) {
96
+ throw new SDKError (
97
+ new ValidationError (
98
+ 'Cannot provide both "fromAmount" and "toAmount" parameters.'
99
+ )
100
+ )
101
+ }
73
102
const _config = config . get ( )
74
103
// apply defaults
75
104
params . integrator ??= _config . integrator
@@ -91,7 +120,7 @@ export const getQuote = async (
91
120
}
92
121
93
122
return await request < LiFiStep > (
94
- `${ _config . apiUrl } /quote?${ new URLSearchParams (
123
+ `${ _config . apiUrl } /${ 'fromAmount' in params ? ' quote' : 'quote/toAmount' } ?${ new URLSearchParams (
95
124
params as unknown as Record < string , string >
96
125
) } `,
97
126
{
@@ -259,10 +288,10 @@ export const getStatus = async (
259
288
* @returns Relayer quote for a token transfer
260
289
*/
261
290
export const getRelayerQuote = async (
262
- params : QuoteRequest ,
291
+ params : QuoteRequestFromAmount ,
263
292
options ?: RequestOptions
264
293
) : Promise < LiFiStep > => {
265
- const requiredParameters : Array < keyof QuoteRequest > = [
294
+ const requiredParameters : Array < keyof QuoteRequestFromAmount > = [
266
295
'fromChain' ,
267
296
'fromToken' ,
268
297
'fromAddress' ,
0 commit comments