@@ -263,17 +263,22 @@ export class GatewayApiClient {
263263 throw new Error ( `Offramp API Error: ${ errorMessage } ${ queryParams } ` ) ;
264264 }
265265
266- const rawQuote = await response . json ( ) ;
266+ const rawQuote : OfframpQuote = await response . json ( ) ;
267267 const currentUnixTimeInSec = Math . floor ( Date . now ( ) / 1000 ) ;
268268 const deadline = currentUnixTimeInSec + ORDER_DEADLINE_IN_SECONDS ;
269269
270270 return {
271- amountLockInSat : BigInt ( rawQuote . amountLockInSat . toString ( ) ) ,
272- feesInSat : BigInt ( rawQuote . feesInSat . toString ( ) ) ,
273- feeRate : BigInt ( rawQuote . feeRate . toString ( ) ) ,
274- deadline : BigInt ( deadline . toString ( ) ) ,
271+ amountLockInSat : rawQuote . amountLockInSat ,
275272 registryAddress : rawQuote . registryAddress as Address ,
273+ deadline : deadline ,
276274 token : token as Address ,
275+ feeBreakdown : {
276+ overallFeeSats : rawQuote . feeBreakdown . overallFeeSats ,
277+ inclusionFeeSats : rawQuote . feeBreakdown . inclusionFeeSats ,
278+ protocolFeeSats : rawQuote . feeBreakdown . protocolFeeSats ,
279+ affiliateFeeSats : rawQuote . feeBreakdown . affiliateFeeSats ,
280+ fastestFeeRate : rawQuote . feeBreakdown . fastestFeeRate ,
281+ } ,
277282 } ;
278283 }
279284
@@ -319,12 +324,13 @@ export class GatewayApiClient {
319324 return {
320325 quote : offrampQuote ,
321326 offrampABI : offrampCaller ,
327+ feeBreakdown : offrampQuote . feeBreakdown ,
322328 offrampFunctionName : 'createOrder' as const ,
323329 offrampArgs : [
324330 {
325- satAmountToLock : offrampQuote . amountLockInSat ,
326- satFeesMax : offrampQuote . feesInSat ,
327- orderCreationDeadline : offrampQuote . deadline ,
331+ satAmountToLock : BigInt ( offrampQuote . amountLockInSat ) ,
332+ satFeesMax : BigInt ( offrampQuote . feeBreakdown . overallFeeSats ) ,
333+ orderCreationDeadline : BigInt ( offrampQuote . deadline ) ,
328334 outputScript : receiverAddress as `0x${string } `,
329335 token : offrampQuote . token ,
330336 orderOwner : params . fromUserAddress as Address ,
@@ -369,7 +375,7 @@ export class GatewayApiClient {
369375 offrampABI : offrampCaller ,
370376 offrampRegistryAddress : offrampRegistryAddress ,
371377 offrampFunctionName : 'bumpFeeOfExistingOrder' as const ,
372- offrampArgs : [ orderId , newFeeSat ] ,
378+ offrampArgs : [ orderId , BigInt ( newFeeSat ) ] ,
373379 } ;
374380 }
375381
@@ -450,24 +456,22 @@ export class GatewayApiClient {
450456 token : Address ,
451457 satAmountLocked : bigint ,
452458 satFeesMax : bigint
453- ) : Promise < [ boolean , bigint , string ?] > {
459+ ) : Promise < [ boolean , number , string ?] > {
454460 const decimals = getTokenDecimals ( token ) ;
455461 if ( decimals === undefined ) {
456- return [ false , 0n , 'Tokens with less than 8 decimals are not supported' ] ;
462+ throw new Error ( 'Tokens with less than 8 decimals are not supported' ) ;
457463 }
458464
459465 const amountInToken = satAmountLocked * BigInt ( 10 ** ( decimals - 8 ) ) ;
460466
461- let offrampQuote : OfframpQuote ;
462467 try {
463- offrampQuote = await this . fetchOfframpQuote ( token . toString ( ) , Number ( amountInToken ) ) ;
468+ const offrampQuote = await this . fetchOfframpQuote ( token . toString ( ) , Number ( amountInToken ) ) ;
469+ const shouldBump = satFeesMax < offrampQuote . feeBreakdown . overallFeeSats ;
470+ return [ shouldBump , offrampQuote . feeBreakdown . overallFeeSats ] ;
464471 } catch ( err ) {
465472 // Return false and 0n with an error message if fetching the quote fails
466- return [ false , 0n , `Error fetching offramp quote: ${ err . message || err } ` ] ;
473+ throw new Error ( `Error fetching offramp quote: ${ err . message || err } ` ) ;
467474 }
468-
469- const shouldBump = satFeesMax < offrampQuote . feesInSat ;
470- return [ shouldBump , offrampQuote . feesInSat ] ;
471475 }
472476
473477 async canOrderBeUnlocked (
@@ -512,8 +516,8 @@ export class GatewayApiClient {
512516 return {
513517 orderId,
514518 token : order . token as Address ,
515- satAmountLocked : BigInt ( order . satAmountLocked ) ,
516- satFeesMax : BigInt ( order . satFeesMax ) ,
519+ satAmountLocked : order . satAmountLocked ,
520+ satFeesMax : order . satFeesMax ,
517521 sender : order . sender as Address ,
518522 receiver : order . receiver !== ( ethers . ZeroAddress as Address ) ? ( order . receiver as Address ) : null ,
519523 owner : order . owner !== ( ethers . ZeroAddress as Address ) ? ( order . owner as Address ) : null ,
0 commit comments