@@ -26,6 +26,7 @@ import {
2626 OfframpRawOrder ,
2727 OfframpOrderStatus ,
2828 EnrichedToken ,
29+ OfframpLiquidity ,
2930} from './types' ;
3031import { createBitcoinPsbt , getAddressInfo } from '../wallet' ;
3132import { SYMBOL_LOOKUP , ADDRESS_LOOKUP , getTokenDecimals } from './tokens' ;
@@ -200,6 +201,47 @@ export class GatewayApiClient {
200201 return JSON . parse ( await response . text ( ) ) as Address ;
201202 }
202203
204+ /**
205+ * Fetches an offramp liquidity for the given token.
206+ *
207+ * @param token ERC20 token address.
208+ * @returns Offramp liquidity details.
209+ */
210+ async fetchOfframpLiquidity ( token : string ) : Promise < OfframpLiquidity > {
211+ let outputTokenAddress = '' ;
212+ const toToken = token . toLowerCase ( ) ;
213+
214+ if ( isAddress ( toToken ) ) {
215+ outputTokenAddress = toToken ;
216+ } else if ( SYMBOL_LOOKUP [ this . chainId ] [ toToken ] ) {
217+ outputTokenAddress = SYMBOL_LOOKUP [ this . chainId ] [ toToken ] . address ;
218+ } else {
219+ throw new Error ( 'Unknown output token' ) ;
220+ }
221+
222+ const response = await fetch ( `${ this . baseUrl } /offramp-liquidity/${ outputTokenAddress } ` , {
223+ method : 'GET' ,
224+ headers : {
225+ 'Content-Type' : 'application/json' ,
226+ Accept : 'application/json' ,
227+ } ,
228+ } ) ;
229+
230+ if ( ! response . ok ) {
231+ const errorData = await response . json ( ) . catch ( ( ) => null ) ;
232+ const errorMessage = errorData ?. message || 'Failed to get offramp liquidity' ;
233+ throw new Error ( `Offramp liquidity API Error: ${ errorMessage } ` ) ;
234+ }
235+
236+ const rawLiquidity = await response . json ( ) ;
237+
238+ return {
239+ token : rawLiquidity . tokenAddress as Address ,
240+ maxOrderAmount : BigInt ( rawLiquidity . maxOrderAmount ) ,
241+ totalOfframpLiquidity : BigInt ( rawLiquidity . totalOfframpLiquidity ) ,
242+ } ;
243+ }
244+
203245 /**
204246 * Fetches an offramp quote for the given token and amount.
205247 *
@@ -312,6 +354,7 @@ export class GatewayApiClient {
312354 orderCreationDeadline : offrampQuote . deadline ,
313355 outputScript : receiverAddress ,
314356 token : offrampQuote . token ,
357+ orderOwner : params . fromUserAddress as Address ,
315358 } ,
316359 ] ,
317360 } ;
0 commit comments