@riftresearch/sdk 0.4.3 → 0.6.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.
package/dist/index.d.ts CHANGED
@@ -56,6 +56,7 @@ interface CalculatedInputAmount {
56
56
  /** Maximum input required after slippage (optional - not all routes provide this) */
57
57
  maximum?: U256;
58
58
  }
59
+ type QuoteQuality = "fast" | "optimal";
59
60
  /**
60
61
  * A single fee component with amount in native currency and USD equivalent.
61
62
  */
@@ -146,11 +147,11 @@ type ExecutionAction = "evm_call" | "btc_transfer";
146
147
  /**
147
148
  * Step kinds grouped by action type.
148
149
  */
149
- type EvmCallKind = "approval" | "transfer_erc20" | "oneinch_swap";
150
+ type EvmCallKind = "approval" | "transfer_erc20" | "oneinch_swap" | "dex_swap";
150
151
  type BtcTransferKind = "transfer_btc";
151
152
  /**
152
153
  * EVM Call step - execute calldata on an EVM chain.
153
- * Used for: token approvals, ERC20 transfers, 1inch swaps.
154
+ * Used for: token approvals, ERC20 transfers, and DEX swaps.
154
155
  */
155
156
  interface EvmCallStep {
156
157
  /** Step ID for tracking */
@@ -165,7 +166,7 @@ interface EvmCallStep {
165
166
  to: string;
166
167
  /** Encoded calldata */
167
168
  calldata: string;
168
- /** Native ETH value to send (for oneinch_swap) */
169
+ /** Native ETH value to send (for swap steps) */
169
170
  value?: U256;
170
171
  /** Token address (for approval, transfer_evm) */
171
172
  tokenAddress?: string;
@@ -232,9 +233,1331 @@ declare const Currencies: {
232
233
  };
233
234
  };
234
235
  import { Treaty } from "@elysiajs/eden";
235
- declare const app: unknown;
236
- declare const appTyped: typeof app;
237
- type App = typeof appTyped;
236
+ import { Elysia } from "elysia";
237
+ import { RiftOtcApi } from "../lib";
238
+ import { SwapRequest as SwapRequest2 } from "../../../common/types";
239
+ import { CachedQuote, ISwapMappingStore } from "../../../lib/cache";
240
+ import { OtcClient as OtcClient2 } from "../../../lib/rift-otc-api";
241
+ import { SwapperClient } from "../../../lib/rift-swapper-api";
242
+ /**
243
+ * Pure order service - no framework dependencies.
244
+ * Handles order creation and retrieval via OTC client.
245
+ * Returns execution steps that the client must execute.
246
+ */
247
+ declare class OrderService {
248
+ private readonly otcClient;
249
+ private readonly swapperClient;
250
+ private readonly swapMappingStore;
251
+ constructor(otcClient: OtcClient2, swapperClient: SwapperClient | null, swapMappingStore: ISwapMappingStore);
252
+ /**
253
+ * Create a swap using the cached quote with raw JSON.
254
+ * Returns SwapResponse with execution steps the client must execute.
255
+ */
256
+ createSwap(request: SwapRequest2, cachedQuote: CachedQuote): Promise<SwapResponse>;
257
+ /**
258
+ * Create a direct cbBTC ↔ BTC swap order.
259
+ * Returns execution steps: either DepositBtc (for BTC → cbBTC) or Approval + DepositEvm (for cbBTC → BTC)
260
+ */
261
+ private createDirectSwapOrder;
262
+ /**
263
+ * Create a chained swap order: BTC → cbBTC → ERC20.
264
+ * Returns execution steps: DepositBtc (server handles the rest)
265
+ */
266
+ private createChainedSwapOrder;
267
+ /**
268
+ * Create a 1inch preswap order: ERC20 → cbBTC → BTC.
269
+ * Returns execution steps: Approval + 1inch swap tx.
270
+ */
271
+ private createOneInchPreswapOrder;
272
+ /**
273
+ * Create a mono-chain swap order: EVM → EVM via 1inch.
274
+ * Returns execution steps: Approval (if needed) + 1inch swap tx.
275
+ */
276
+ private createOneInchMonochainOrder;
277
+ /**
278
+ * Build steps for BTC transfer (BTC → cbBTC or BTC → ERC20).
279
+ */
280
+ private buildBtcTransferSteps;
281
+ /**
282
+ * Build steps for cbBTC transfer (cbBTC → BTC).
283
+ * No approval needed - just a direct ERC20 transfer.
284
+ */
285
+ private buildCbbtcTransferSteps;
286
+ private buildOneInchSwapStep;
287
+ /**
288
+ * Build steps for 1inch preswap (ERC20/ETH → cbBTC → BTC).
289
+ */
290
+ private buildOneInchPreswapSteps;
291
+ /**
292
+ * Build steps for mono-chain 1inch swap (EVM → EVM).
293
+ */
294
+ private buildOneInchMonochainSteps;
295
+ private resolveEvmSenderAddress;
296
+ private isEvmAddress;
297
+ private extractExpectedOneInchSwap;
298
+ private isNativeToken;
299
+ private getTxConfirmationStatus;
300
+ /**
301
+ * Update a swap with step execution result (best-effort tx hash tracking).
302
+ */
303
+ updateStepResult(swapId: string, _stepId: string, result: {
304
+ txHash?: string;
305
+ }): Promise<void>;
306
+ /**
307
+ * Get user-facing order status without exposing internal swap details.
308
+ */
309
+ getSwapStatus(swapId: string): Promise<SwapStatusResponse>;
310
+ private resolveOrderStatusMetadata;
311
+ private getOtcDepositTx;
312
+ private getOtcSettlementTx;
313
+ private getOtcPayoutTx;
314
+ private normalizeTxHash;
315
+ private isEvmChain;
316
+ }
317
+ import { QuoteRequest as QuoteRequest2, QuoteResponse as QuoteResponse2 } from "../../../common/types";
318
+ import { CachedQuote as CachedQuote2, IQuoteCache } from "../../../lib/cache";
319
+ import { RfqClient as RfqClient2 } from "../../../lib/rift-otc-api";
320
+ import { SwapperClient as SwapperClient2 } from "../../../lib/rift-swapper-api";
321
+ /**
322
+ * Pure quote service - no framework dependencies.
323
+ * Handles quote generation and caching.
324
+ */
325
+ declare class QuoteService {
326
+ private readonly quoteCache;
327
+ private readonly rfqClient;
328
+ private readonly swapperClient;
329
+ private readonly priceOracle;
330
+ private readonly oneinchProvider;
331
+ constructor(quoteCache: IQuoteCache, rfqClient: RfqClient2, swapperClient: SwapperClient2 | null);
332
+ getQuote(request: QuoteRequest2): Promise<QuoteResponse2>;
333
+ /** Get the cached quote with raw JSON for order creation */
334
+ getCachedQuoteById(id: string): Promise<CachedQuote2 | null>;
335
+ /** Atomically consume a cached quote to prevent reuse */
336
+ consumeCachedQuoteById(id: string): Promise<CachedQuote2 | null>;
337
+ private generateQuote;
338
+ /**
339
+ * Quote a direct BTC <-> cbBTC swap via Rift OTC.
340
+ */
341
+ private quoteDirectOtcSwap;
342
+ /**
343
+ * Quote a chained swap: BTC -> cbBTC (OTC) -> target ERC-20 (Swapper).
344
+ *
345
+ * 1. Get OTC quote for BTC -> cbBTC on target chain
346
+ * 2. Get Swapper quote for cbBTC -> target token
347
+ * 3. Cache both quotes linked together
348
+ * 4. Return combined quote showing BTC -> target token
349
+ */
350
+ private quoteChainedSwap;
351
+ /**
352
+ * Quote a mono-chain EVM → EVM swap via 1inch.
353
+ */
354
+ private quoteOneInchMonochain;
355
+ /**
356
+ * Quote a 1inch preswap: non-cbBTC ERC20 -> cbBTC (1inch) -> BTC (Rift OTC).
357
+ *
358
+ * 1. Get 1inch quote for ERC20 -> cbBTC
359
+ * 2. Get OTC quote for cbBTC -> BTC
360
+ * 3. Cache both quotes linked together
361
+ * 4. Return combined quote showing ERC20 -> BTC
362
+ */
363
+ private quoteOneInchThenRift;
364
+ /**
365
+ * exact_input: ERC20 (known) -> cbBTC -> BTC (calculated)
366
+ */
367
+ private quoteOneInchThenRiftExactInput;
368
+ }
369
+ import { TModule as TModule_7fcqhs } from "@sinclair/typebox";
370
+ declare const app: Elysia<"", {
371
+ decorator: {
372
+ quoteService: QuoteService;
373
+ } & {
374
+ orderService: OrderService;
375
+ } & {
376
+ rfqClient: RiftOtcApi.RfqClient;
377
+ } & {
378
+ otcClient: RiftOtcApi.OtcClient;
379
+ };
380
+ store: {};
381
+ derive: {};
382
+ resolve: {};
383
+ }, {
384
+ typebox: {};
385
+ error: {};
386
+ } & {
387
+ typebox: {};
388
+ error: {};
389
+ } & {
390
+ error: {};
391
+ typebox: TModule_7fcqhs<{}, {}>;
392
+ } & {
393
+ typebox: {};
394
+ error: {};
395
+ }, {
396
+ schema: {};
397
+ standaloneSchema: {};
398
+ macro: {};
399
+ macroFn: {};
400
+ parser: {};
401
+ response: {};
402
+ } & {
403
+ schema: {};
404
+ standaloneSchema: {};
405
+ macro: {};
406
+ macroFn: {};
407
+ parser: {};
408
+ response: {};
409
+ } & {
410
+ schema: {};
411
+ macro: {};
412
+ macroFn: {};
413
+ parser: {};
414
+ } & {
415
+ schema: {};
416
+ standaloneSchema: {};
417
+ macro: {};
418
+ macroFn: {};
419
+ parser: {};
420
+ }, {
421
+ health: {
422
+ get: {
423
+ body: unknown;
424
+ params: {};
425
+ query: unknown;
426
+ headers: unknown;
427
+ response: {
428
+ 200: {
429
+ status: "ok";
430
+ timestamp: string;
431
+ };
432
+ 422: {
433
+ type: "validation";
434
+ on: string;
435
+ summary?: string;
436
+ message?: string;
437
+ found?: unknown;
438
+ property?: string;
439
+ expected?: string;
440
+ };
441
+ };
442
+ };
443
+ };
444
+ } & {
445
+ status: {
446
+ get: {
447
+ body: unknown;
448
+ params: {};
449
+ query: unknown;
450
+ headers: unknown;
451
+ response: {
452
+ 200: {
453
+ status: "ok" | "offline" | "degraded";
454
+ timestamp: string;
455
+ services: {
456
+ rfq: {
457
+ error?: string | undefined;
458
+ version?: string | undefined;
459
+ status: "ok" | "offline" | "degraded";
460
+ connectedMarketMakers: number;
461
+ };
462
+ otc: {
463
+ error?: string | undefined;
464
+ version?: string | undefined;
465
+ status: "ok" | "offline" | "degraded";
466
+ connectedMarketMakers: number;
467
+ };
468
+ };
469
+ };
470
+ 422: {
471
+ type: "validation";
472
+ on: string;
473
+ summary?: string;
474
+ message?: string;
475
+ found?: unknown;
476
+ property?: string;
477
+ expected?: string;
478
+ };
479
+ };
480
+ };
481
+ };
482
+ } & {
483
+ quote: {
484
+ post: {
485
+ body: {
486
+ amount: string;
487
+ type: string;
488
+ from: {
489
+ chain: {
490
+ kind: "BITCOIN";
491
+ } | {
492
+ kind: "EVM";
493
+ chainId: number;
494
+ };
495
+ token: {
496
+ kind: "NATIVE";
497
+ decimals: number;
498
+ } | {
499
+ kind: "TOKEN";
500
+ decimals: number;
501
+ address: string;
502
+ };
503
+ };
504
+ to: {
505
+ chain: {
506
+ kind: "BITCOIN";
507
+ } | {
508
+ kind: "EVM";
509
+ chainId: number;
510
+ };
511
+ token: {
512
+ kind: "NATIVE";
513
+ decimals: number;
514
+ } | {
515
+ kind: "TOKEN";
516
+ decimals: number;
517
+ address: string;
518
+ };
519
+ };
520
+ };
521
+ params: {};
522
+ query: unknown;
523
+ headers: unknown;
524
+ response: {
525
+ 200: {
526
+ from: {
527
+ currency: {
528
+ chain: {
529
+ kind: "BITCOIN";
530
+ } | {
531
+ kind: "EVM";
532
+ chainId: number;
533
+ };
534
+ token: {
535
+ kind: "NATIVE";
536
+ decimals: number;
537
+ } | {
538
+ kind: "TOKEN";
539
+ decimals: number;
540
+ address: string;
541
+ };
542
+ };
543
+ amount: string;
544
+ };
545
+ to: {
546
+ minimum?: string | undefined;
547
+ currency: {
548
+ chain: {
549
+ kind: "BITCOIN";
550
+ } | {
551
+ kind: "EVM";
552
+ chainId: number;
553
+ };
554
+ token: {
555
+ kind: "NATIVE";
556
+ decimals: number;
557
+ } | {
558
+ kind: "TOKEN";
559
+ decimals: number;
560
+ address: string;
561
+ };
562
+ };
563
+ amount: string;
564
+ };
565
+ mode: "exact_input";
566
+ id: string;
567
+ fees: {
568
+ preswap?: {
569
+ currency: {
570
+ chain: {
571
+ kind: "BITCOIN";
572
+ } | {
573
+ kind: "EVM";
574
+ chainId: number;
575
+ };
576
+ token: {
577
+ kind: "NATIVE";
578
+ decimals: number;
579
+ } | {
580
+ kind: "TOKEN";
581
+ decimals: number;
582
+ address: string;
583
+ };
584
+ };
585
+ amount: string;
586
+ usd: number;
587
+ } | undefined;
588
+ rift?: {
589
+ network: {
590
+ currency: {
591
+ chain: {
592
+ kind: "BITCOIN";
593
+ } | {
594
+ kind: "EVM";
595
+ chainId: number;
596
+ };
597
+ token: {
598
+ kind: "NATIVE";
599
+ decimals: number;
600
+ } | {
601
+ kind: "TOKEN";
602
+ decimals: number;
603
+ address: string;
604
+ };
605
+ };
606
+ amount: string;
607
+ usd: number;
608
+ };
609
+ liquidity: {
610
+ currency: {
611
+ chain: {
612
+ kind: "BITCOIN";
613
+ } | {
614
+ kind: "EVM";
615
+ chainId: number;
616
+ };
617
+ token: {
618
+ kind: "NATIVE";
619
+ decimals: number;
620
+ } | {
621
+ kind: "TOKEN";
622
+ decimals: number;
623
+ address: string;
624
+ };
625
+ };
626
+ amount: string;
627
+ usd: number;
628
+ };
629
+ protocol: {
630
+ currency: {
631
+ chain: {
632
+ kind: "BITCOIN";
633
+ } | {
634
+ kind: "EVM";
635
+ chainId: number;
636
+ };
637
+ token: {
638
+ kind: "NATIVE";
639
+ decimals: number;
640
+ } | {
641
+ kind: "TOKEN";
642
+ decimals: number;
643
+ address: string;
644
+ };
645
+ };
646
+ amount: string;
647
+ usd: number;
648
+ };
649
+ } | undefined;
650
+ postswap?: {
651
+ currency: {
652
+ chain: {
653
+ kind: "BITCOIN";
654
+ } | {
655
+ kind: "EVM";
656
+ chainId: number;
657
+ };
658
+ token: {
659
+ kind: "NATIVE";
660
+ decimals: number;
661
+ } | {
662
+ kind: "TOKEN";
663
+ decimals: number;
664
+ address: string;
665
+ };
666
+ };
667
+ amount: string;
668
+ usd: number;
669
+ } | undefined;
670
+ totalUsd: number;
671
+ };
672
+ expiresAt: string;
673
+ } | {
674
+ from: {
675
+ maximum?: string | undefined;
676
+ currency: {
677
+ chain: {
678
+ kind: "BITCOIN";
679
+ } | {
680
+ kind: "EVM";
681
+ chainId: number;
682
+ };
683
+ token: {
684
+ kind: "NATIVE";
685
+ decimals: number;
686
+ } | {
687
+ kind: "TOKEN";
688
+ decimals: number;
689
+ address: string;
690
+ };
691
+ };
692
+ amount: string;
693
+ };
694
+ to: {
695
+ currency: {
696
+ chain: {
697
+ kind: "BITCOIN";
698
+ } | {
699
+ kind: "EVM";
700
+ chainId: number;
701
+ };
702
+ token: {
703
+ kind: "NATIVE";
704
+ decimals: number;
705
+ } | {
706
+ kind: "TOKEN";
707
+ decimals: number;
708
+ address: string;
709
+ };
710
+ };
711
+ amount: string;
712
+ };
713
+ mode: "exact_output";
714
+ id: string;
715
+ fees: {
716
+ preswap?: {
717
+ currency: {
718
+ chain: {
719
+ kind: "BITCOIN";
720
+ } | {
721
+ kind: "EVM";
722
+ chainId: number;
723
+ };
724
+ token: {
725
+ kind: "NATIVE";
726
+ decimals: number;
727
+ } | {
728
+ kind: "TOKEN";
729
+ decimals: number;
730
+ address: string;
731
+ };
732
+ };
733
+ amount: string;
734
+ usd: number;
735
+ } | undefined;
736
+ rift?: {
737
+ network: {
738
+ currency: {
739
+ chain: {
740
+ kind: "BITCOIN";
741
+ } | {
742
+ kind: "EVM";
743
+ chainId: number;
744
+ };
745
+ token: {
746
+ kind: "NATIVE";
747
+ decimals: number;
748
+ } | {
749
+ kind: "TOKEN";
750
+ decimals: number;
751
+ address: string;
752
+ };
753
+ };
754
+ amount: string;
755
+ usd: number;
756
+ };
757
+ liquidity: {
758
+ currency: {
759
+ chain: {
760
+ kind: "BITCOIN";
761
+ } | {
762
+ kind: "EVM";
763
+ chainId: number;
764
+ };
765
+ token: {
766
+ kind: "NATIVE";
767
+ decimals: number;
768
+ } | {
769
+ kind: "TOKEN";
770
+ decimals: number;
771
+ address: string;
772
+ };
773
+ };
774
+ amount: string;
775
+ usd: number;
776
+ };
777
+ protocol: {
778
+ currency: {
779
+ chain: {
780
+ kind: "BITCOIN";
781
+ } | {
782
+ kind: "EVM";
783
+ chainId: number;
784
+ };
785
+ token: {
786
+ kind: "NATIVE";
787
+ decimals: number;
788
+ } | {
789
+ kind: "TOKEN";
790
+ decimals: number;
791
+ address: string;
792
+ };
793
+ };
794
+ amount: string;
795
+ usd: number;
796
+ };
797
+ } | undefined;
798
+ postswap?: {
799
+ currency: {
800
+ chain: {
801
+ kind: "BITCOIN";
802
+ } | {
803
+ kind: "EVM";
804
+ chainId: number;
805
+ };
806
+ token: {
807
+ kind: "NATIVE";
808
+ decimals: number;
809
+ } | {
810
+ kind: "TOKEN";
811
+ decimals: number;
812
+ address: string;
813
+ };
814
+ };
815
+ amount: string;
816
+ usd: number;
817
+ } | undefined;
818
+ totalUsd: number;
819
+ };
820
+ expiresAt: string;
821
+ };
822
+ 422: {
823
+ type: "validation";
824
+ on: string;
825
+ summary?: string;
826
+ message?: string;
827
+ found?: unknown;
828
+ property?: string;
829
+ expected?: string;
830
+ };
831
+ };
832
+ };
833
+ };
834
+ } & {
835
+ swap: {
836
+ post: {
837
+ body: {
838
+ integratorName?: string | undefined;
839
+ approvalMode?: string | undefined;
840
+ id: string;
841
+ destinationAddress: string;
842
+ refundAddress: string;
843
+ };
844
+ params: {};
845
+ query: unknown;
846
+ headers: unknown;
847
+ response: {
848
+ 200: {
849
+ quote: {
850
+ from: {
851
+ currency: {
852
+ chain: {
853
+ kind: "BITCOIN";
854
+ } | {
855
+ kind: "EVM";
856
+ chainId: number;
857
+ };
858
+ token: {
859
+ kind: "NATIVE";
860
+ decimals: number;
861
+ } | {
862
+ kind: "TOKEN";
863
+ decimals: number;
864
+ address: string;
865
+ };
866
+ };
867
+ amount: string;
868
+ };
869
+ to: {
870
+ minimum?: string | undefined;
871
+ currency: {
872
+ chain: {
873
+ kind: "BITCOIN";
874
+ } | {
875
+ kind: "EVM";
876
+ chainId: number;
877
+ };
878
+ token: {
879
+ kind: "NATIVE";
880
+ decimals: number;
881
+ } | {
882
+ kind: "TOKEN";
883
+ decimals: number;
884
+ address: string;
885
+ };
886
+ };
887
+ amount: string;
888
+ };
889
+ mode: "exact_input";
890
+ id: string;
891
+ fees: {
892
+ preswap?: {
893
+ currency: {
894
+ chain: {
895
+ kind: "BITCOIN";
896
+ } | {
897
+ kind: "EVM";
898
+ chainId: number;
899
+ };
900
+ token: {
901
+ kind: "NATIVE";
902
+ decimals: number;
903
+ } | {
904
+ kind: "TOKEN";
905
+ decimals: number;
906
+ address: string;
907
+ };
908
+ };
909
+ amount: string;
910
+ usd: number;
911
+ } | undefined;
912
+ rift?: {
913
+ network: {
914
+ currency: {
915
+ chain: {
916
+ kind: "BITCOIN";
917
+ } | {
918
+ kind: "EVM";
919
+ chainId: number;
920
+ };
921
+ token: {
922
+ kind: "NATIVE";
923
+ decimals: number;
924
+ } | {
925
+ kind: "TOKEN";
926
+ decimals: number;
927
+ address: string;
928
+ };
929
+ };
930
+ amount: string;
931
+ usd: number;
932
+ };
933
+ liquidity: {
934
+ currency: {
935
+ chain: {
936
+ kind: "BITCOIN";
937
+ } | {
938
+ kind: "EVM";
939
+ chainId: number;
940
+ };
941
+ token: {
942
+ kind: "NATIVE";
943
+ decimals: number;
944
+ } | {
945
+ kind: "TOKEN";
946
+ decimals: number;
947
+ address: string;
948
+ };
949
+ };
950
+ amount: string;
951
+ usd: number;
952
+ };
953
+ protocol: {
954
+ currency: {
955
+ chain: {
956
+ kind: "BITCOIN";
957
+ } | {
958
+ kind: "EVM";
959
+ chainId: number;
960
+ };
961
+ token: {
962
+ kind: "NATIVE";
963
+ decimals: number;
964
+ } | {
965
+ kind: "TOKEN";
966
+ decimals: number;
967
+ address: string;
968
+ };
969
+ };
970
+ amount: string;
971
+ usd: number;
972
+ };
973
+ } | undefined;
974
+ postswap?: {
975
+ currency: {
976
+ chain: {
977
+ kind: "BITCOIN";
978
+ } | {
979
+ kind: "EVM";
980
+ chainId: number;
981
+ };
982
+ token: {
983
+ kind: "NATIVE";
984
+ decimals: number;
985
+ } | {
986
+ kind: "TOKEN";
987
+ decimals: number;
988
+ address: string;
989
+ };
990
+ };
991
+ amount: string;
992
+ usd: number;
993
+ } | undefined;
994
+ totalUsd: number;
995
+ };
996
+ expiresAt: string;
997
+ } | {
998
+ from: {
999
+ maximum?: string | undefined;
1000
+ currency: {
1001
+ chain: {
1002
+ kind: "BITCOIN";
1003
+ } | {
1004
+ kind: "EVM";
1005
+ chainId: number;
1006
+ };
1007
+ token: {
1008
+ kind: "NATIVE";
1009
+ decimals: number;
1010
+ } | {
1011
+ kind: "TOKEN";
1012
+ decimals: number;
1013
+ address: string;
1014
+ };
1015
+ };
1016
+ amount: string;
1017
+ };
1018
+ to: {
1019
+ currency: {
1020
+ chain: {
1021
+ kind: "BITCOIN";
1022
+ } | {
1023
+ kind: "EVM";
1024
+ chainId: number;
1025
+ };
1026
+ token: {
1027
+ kind: "NATIVE";
1028
+ decimals: number;
1029
+ } | {
1030
+ kind: "TOKEN";
1031
+ decimals: number;
1032
+ address: string;
1033
+ };
1034
+ };
1035
+ amount: string;
1036
+ };
1037
+ mode: "exact_output";
1038
+ id: string;
1039
+ fees: {
1040
+ preswap?: {
1041
+ currency: {
1042
+ chain: {
1043
+ kind: "BITCOIN";
1044
+ } | {
1045
+ kind: "EVM";
1046
+ chainId: number;
1047
+ };
1048
+ token: {
1049
+ kind: "NATIVE";
1050
+ decimals: number;
1051
+ } | {
1052
+ kind: "TOKEN";
1053
+ decimals: number;
1054
+ address: string;
1055
+ };
1056
+ };
1057
+ amount: string;
1058
+ usd: number;
1059
+ } | undefined;
1060
+ rift?: {
1061
+ network: {
1062
+ currency: {
1063
+ chain: {
1064
+ kind: "BITCOIN";
1065
+ } | {
1066
+ kind: "EVM";
1067
+ chainId: number;
1068
+ };
1069
+ token: {
1070
+ kind: "NATIVE";
1071
+ decimals: number;
1072
+ } | {
1073
+ kind: "TOKEN";
1074
+ decimals: number;
1075
+ address: string;
1076
+ };
1077
+ };
1078
+ amount: string;
1079
+ usd: number;
1080
+ };
1081
+ liquidity: {
1082
+ currency: {
1083
+ chain: {
1084
+ kind: "BITCOIN";
1085
+ } | {
1086
+ kind: "EVM";
1087
+ chainId: number;
1088
+ };
1089
+ token: {
1090
+ kind: "NATIVE";
1091
+ decimals: number;
1092
+ } | {
1093
+ kind: "TOKEN";
1094
+ decimals: number;
1095
+ address: string;
1096
+ };
1097
+ };
1098
+ amount: string;
1099
+ usd: number;
1100
+ };
1101
+ protocol: {
1102
+ currency: {
1103
+ chain: {
1104
+ kind: "BITCOIN";
1105
+ } | {
1106
+ kind: "EVM";
1107
+ chainId: number;
1108
+ };
1109
+ token: {
1110
+ kind: "NATIVE";
1111
+ decimals: number;
1112
+ } | {
1113
+ kind: "TOKEN";
1114
+ decimals: number;
1115
+ address: string;
1116
+ };
1117
+ };
1118
+ amount: string;
1119
+ usd: number;
1120
+ };
1121
+ } | undefined;
1122
+ postswap?: {
1123
+ currency: {
1124
+ chain: {
1125
+ kind: "BITCOIN";
1126
+ } | {
1127
+ kind: "EVM";
1128
+ chainId: number;
1129
+ };
1130
+ token: {
1131
+ kind: "NATIVE";
1132
+ decimals: number;
1133
+ } | {
1134
+ kind: "TOKEN";
1135
+ decimals: number;
1136
+ address: string;
1137
+ };
1138
+ };
1139
+ amount: string;
1140
+ usd: number;
1141
+ } | undefined;
1142
+ totalUsd: number;
1143
+ };
1144
+ expiresAt: string;
1145
+ };
1146
+ swapId: string;
1147
+ executionSteps: ({
1148
+ amount?: string | undefined;
1149
+ value?: string | undefined;
1150
+ tokenAddress?: string | undefined;
1151
+ spenderAddress?: string | undefined;
1152
+ kind: "approval" | "transfer_erc20" | "oneinch_swap";
1153
+ chainId: number;
1154
+ to: string;
1155
+ id: string;
1156
+ action: "evm_call";
1157
+ calldata: string;
1158
+ } | {
1159
+ kind: "transfer_btc";
1160
+ id: string;
1161
+ action: "btc_transfer";
1162
+ toAddress: string;
1163
+ amountSats: string;
1164
+ })[];
1165
+ };
1166
+ 404: {
1167
+ error: string;
1168
+ };
1169
+ 410: {
1170
+ error: string;
1171
+ };
1172
+ 422: {
1173
+ type: "validation";
1174
+ on: string;
1175
+ summary?: string;
1176
+ message?: string;
1177
+ found?: unknown;
1178
+ property?: string;
1179
+ expected?: string;
1180
+ };
1181
+ };
1182
+ };
1183
+ };
1184
+ } & {
1185
+ swap: {
1186
+ ":swapId": {
1187
+ get: {
1188
+ body: unknown;
1189
+ params: {
1190
+ swapId: string;
1191
+ };
1192
+ query: unknown;
1193
+ headers: unknown;
1194
+ response: {
1195
+ 200: {
1196
+ payoutTransaction?: string | undefined;
1197
+ depositTransaction?: string | undefined;
1198
+ destinationAddress: string;
1199
+ status: string;
1200
+ quote: {
1201
+ from: {
1202
+ currency: {
1203
+ chain: {
1204
+ kind: "BITCOIN";
1205
+ } | {
1206
+ kind: "EVM";
1207
+ chainId: number;
1208
+ };
1209
+ token: {
1210
+ kind: "NATIVE";
1211
+ decimals: number;
1212
+ } | {
1213
+ kind: "TOKEN";
1214
+ decimals: number;
1215
+ address: string;
1216
+ };
1217
+ };
1218
+ amount: string;
1219
+ };
1220
+ to: {
1221
+ minimum?: string | undefined;
1222
+ currency: {
1223
+ chain: {
1224
+ kind: "BITCOIN";
1225
+ } | {
1226
+ kind: "EVM";
1227
+ chainId: number;
1228
+ };
1229
+ token: {
1230
+ kind: "NATIVE";
1231
+ decimals: number;
1232
+ } | {
1233
+ kind: "TOKEN";
1234
+ decimals: number;
1235
+ address: string;
1236
+ };
1237
+ };
1238
+ amount: string;
1239
+ };
1240
+ mode: "exact_input";
1241
+ id: string;
1242
+ fees: {
1243
+ preswap?: {
1244
+ currency: {
1245
+ chain: {
1246
+ kind: "BITCOIN";
1247
+ } | {
1248
+ kind: "EVM";
1249
+ chainId: number;
1250
+ };
1251
+ token: {
1252
+ kind: "NATIVE";
1253
+ decimals: number;
1254
+ } | {
1255
+ kind: "TOKEN";
1256
+ decimals: number;
1257
+ address: string;
1258
+ };
1259
+ };
1260
+ amount: string;
1261
+ usd: number;
1262
+ } | undefined;
1263
+ rift?: {
1264
+ network: {
1265
+ currency: {
1266
+ chain: {
1267
+ kind: "BITCOIN";
1268
+ } | {
1269
+ kind: "EVM";
1270
+ chainId: number;
1271
+ };
1272
+ token: {
1273
+ kind: "NATIVE";
1274
+ decimals: number;
1275
+ } | {
1276
+ kind: "TOKEN";
1277
+ decimals: number;
1278
+ address: string;
1279
+ };
1280
+ };
1281
+ amount: string;
1282
+ usd: number;
1283
+ };
1284
+ liquidity: {
1285
+ currency: {
1286
+ chain: {
1287
+ kind: "BITCOIN";
1288
+ } | {
1289
+ kind: "EVM";
1290
+ chainId: number;
1291
+ };
1292
+ token: {
1293
+ kind: "NATIVE";
1294
+ decimals: number;
1295
+ } | {
1296
+ kind: "TOKEN";
1297
+ decimals: number;
1298
+ address: string;
1299
+ };
1300
+ };
1301
+ amount: string;
1302
+ usd: number;
1303
+ };
1304
+ protocol: {
1305
+ currency: {
1306
+ chain: {
1307
+ kind: "BITCOIN";
1308
+ } | {
1309
+ kind: "EVM";
1310
+ chainId: number;
1311
+ };
1312
+ token: {
1313
+ kind: "NATIVE";
1314
+ decimals: number;
1315
+ } | {
1316
+ kind: "TOKEN";
1317
+ decimals: number;
1318
+ address: string;
1319
+ };
1320
+ };
1321
+ amount: string;
1322
+ usd: number;
1323
+ };
1324
+ } | undefined;
1325
+ postswap?: {
1326
+ currency: {
1327
+ chain: {
1328
+ kind: "BITCOIN";
1329
+ } | {
1330
+ kind: "EVM";
1331
+ chainId: number;
1332
+ };
1333
+ token: {
1334
+ kind: "NATIVE";
1335
+ decimals: number;
1336
+ } | {
1337
+ kind: "TOKEN";
1338
+ decimals: number;
1339
+ address: string;
1340
+ };
1341
+ };
1342
+ amount: string;
1343
+ usd: number;
1344
+ } | undefined;
1345
+ totalUsd: number;
1346
+ };
1347
+ expiresAt: string;
1348
+ } | {
1349
+ from: {
1350
+ maximum?: string | undefined;
1351
+ currency: {
1352
+ chain: {
1353
+ kind: "BITCOIN";
1354
+ } | {
1355
+ kind: "EVM";
1356
+ chainId: number;
1357
+ };
1358
+ token: {
1359
+ kind: "NATIVE";
1360
+ decimals: number;
1361
+ } | {
1362
+ kind: "TOKEN";
1363
+ decimals: number;
1364
+ address: string;
1365
+ };
1366
+ };
1367
+ amount: string;
1368
+ };
1369
+ to: {
1370
+ currency: {
1371
+ chain: {
1372
+ kind: "BITCOIN";
1373
+ } | {
1374
+ kind: "EVM";
1375
+ chainId: number;
1376
+ };
1377
+ token: {
1378
+ kind: "NATIVE";
1379
+ decimals: number;
1380
+ } | {
1381
+ kind: "TOKEN";
1382
+ decimals: number;
1383
+ address: string;
1384
+ };
1385
+ };
1386
+ amount: string;
1387
+ };
1388
+ mode: "exact_output";
1389
+ id: string;
1390
+ fees: {
1391
+ preswap?: {
1392
+ currency: {
1393
+ chain: {
1394
+ kind: "BITCOIN";
1395
+ } | {
1396
+ kind: "EVM";
1397
+ chainId: number;
1398
+ };
1399
+ token: {
1400
+ kind: "NATIVE";
1401
+ decimals: number;
1402
+ } | {
1403
+ kind: "TOKEN";
1404
+ decimals: number;
1405
+ address: string;
1406
+ };
1407
+ };
1408
+ amount: string;
1409
+ usd: number;
1410
+ } | undefined;
1411
+ rift?: {
1412
+ network: {
1413
+ currency: {
1414
+ chain: {
1415
+ kind: "BITCOIN";
1416
+ } | {
1417
+ kind: "EVM";
1418
+ chainId: number;
1419
+ };
1420
+ token: {
1421
+ kind: "NATIVE";
1422
+ decimals: number;
1423
+ } | {
1424
+ kind: "TOKEN";
1425
+ decimals: number;
1426
+ address: string;
1427
+ };
1428
+ };
1429
+ amount: string;
1430
+ usd: number;
1431
+ };
1432
+ liquidity: {
1433
+ currency: {
1434
+ chain: {
1435
+ kind: "BITCOIN";
1436
+ } | {
1437
+ kind: "EVM";
1438
+ chainId: number;
1439
+ };
1440
+ token: {
1441
+ kind: "NATIVE";
1442
+ decimals: number;
1443
+ } | {
1444
+ kind: "TOKEN";
1445
+ decimals: number;
1446
+ address: string;
1447
+ };
1448
+ };
1449
+ amount: string;
1450
+ usd: number;
1451
+ };
1452
+ protocol: {
1453
+ currency: {
1454
+ chain: {
1455
+ kind: "BITCOIN";
1456
+ } | {
1457
+ kind: "EVM";
1458
+ chainId: number;
1459
+ };
1460
+ token: {
1461
+ kind: "NATIVE";
1462
+ decimals: number;
1463
+ } | {
1464
+ kind: "TOKEN";
1465
+ decimals: number;
1466
+ address: string;
1467
+ };
1468
+ };
1469
+ amount: string;
1470
+ usd: number;
1471
+ };
1472
+ } | undefined;
1473
+ postswap?: {
1474
+ currency: {
1475
+ chain: {
1476
+ kind: "BITCOIN";
1477
+ } | {
1478
+ kind: "EVM";
1479
+ chainId: number;
1480
+ };
1481
+ token: {
1482
+ kind: "NATIVE";
1483
+ decimals: number;
1484
+ } | {
1485
+ kind: "TOKEN";
1486
+ decimals: number;
1487
+ address: string;
1488
+ };
1489
+ };
1490
+ amount: string;
1491
+ usd: number;
1492
+ } | undefined;
1493
+ totalUsd: number;
1494
+ };
1495
+ expiresAt: string;
1496
+ };
1497
+ };
1498
+ 422: {
1499
+ type: "validation";
1500
+ on: string;
1501
+ summary?: string;
1502
+ message?: string;
1503
+ found?: unknown;
1504
+ property?: string;
1505
+ expected?: string;
1506
+ };
1507
+ };
1508
+ };
1509
+ };
1510
+ };
1511
+ } & {
1512
+ swap: {
1513
+ ":swapId": {
1514
+ tx: {
1515
+ post: {
1516
+ body: {
1517
+ txHash?: string | undefined;
1518
+ stepId: string;
1519
+ };
1520
+ params: {
1521
+ swapId: string;
1522
+ };
1523
+ query: unknown;
1524
+ headers: unknown;
1525
+ response: {
1526
+ 200: {
1527
+ success: boolean;
1528
+ };
1529
+ 422: {
1530
+ type: "validation";
1531
+ on: string;
1532
+ summary?: string;
1533
+ message?: string;
1534
+ found?: unknown;
1535
+ property?: string;
1536
+ expected?: string;
1537
+ };
1538
+ };
1539
+ };
1540
+ };
1541
+ };
1542
+ };
1543
+ }, {
1544
+ derive: {};
1545
+ resolve: {};
1546
+ schema: {};
1547
+ standaloneSchema: {};
1548
+ response: {};
1549
+ } & {
1550
+ derive: {};
1551
+ resolve: {};
1552
+ schema: {};
1553
+ }, {
1554
+ derive: {};
1555
+ resolve: {};
1556
+ schema: {};
1557
+ standaloneSchema: {};
1558
+ response: {};
1559
+ }>;
1560
+ type App = typeof app;
238
1561
  declare class SwapRouterApiError extends Error {
239
1562
  status: number;
240
1563
  body: ErrorResponse | undefined;
@@ -243,14 +1566,14 @@ declare class SwapRouterApiError extends Error {
243
1566
  /**
244
1567
  * Create a type-safe API client for the Rift Swap Router.
245
1568
  *
246
- * @param baseUrl - The base URL of the swap router API (e.g., 'https://router-api-v2-production.up.railway.app')
1569
+ * @param baseUrl - The base URL of the swap router API (e.g., 'https://api.rift.trade')
247
1570
  * @returns A fully typed Eden Treaty client
248
1571
  *
249
1572
  * @example
250
1573
  * ```typescript
251
1574
  * import { createClient } from '@riftresearch/sdk'
252
1575
  *
253
- * const api = createClient('https://router-api-v2-production.up.railway.app')
1576
+ * const api = createClient('https://api.rift.trade')
254
1577
  *
255
1578
  * // Get a quote - fully typed request and response
256
1579
  * const { data: quote, error } = await api.quote.post({
@@ -296,26 +1619,26 @@ declare function createClient(baseUrl: string): RiftClient;
296
1619
  * Discriminated union of all possible swap routes.
297
1620
  *
298
1621
  * - direct_rift: BTC <-> EVM token (Rift handles directly)
299
- * - oneinch_then_rift: ERC20 (non-cbBTC) -> BTC (1inch to cbBTC, then Rift to BTC)
300
- * - oneinch_monochain: EVM token -> EVM token (single-chain 1inch swap)
1622
+ * - dex_then_rift: ERC20 (non-cbBTC) -> BTC (DEX to cbBTC, then Rift to BTC)
1623
+ * - dex_monochain: EVM token -> EVM token (single-chain DEX swap)
301
1624
  */
302
1625
  type SwapRoute = {
303
1626
  type: "direct_rift";
304
1627
  direction: "to_btc" | "from_btc";
305
1628
  } | {
306
- type: "oneinch_then_rift";
1629
+ type: "dex_then_rift";
307
1630
  evmChainId: number;
308
1631
  } | {
309
- type: "oneinch_monochain";
1632
+ type: "dex_monochain";
310
1633
  evmChainId: number;
311
1634
  };
312
1635
  /**
313
1636
  * Detect the appropriate swap route based on currency pair.
314
1637
  *
315
1638
  * Routes:
316
- * - EVM token → BTC: direct_rift (to_btc) for cbBTC, oneinch_then_rift for other ERC20s
1639
+ * - EVM token → BTC: direct_rift (to_btc) for cbBTC, dex_then_rift for other ERC20s
317
1640
  * - BTC → EVM token: direct_rift (from_btc) - Rift handles all BTC -> EVM swaps directly
318
- * - EVM token → EVM token (same chain): oneinch_monochain
1641
+ * - EVM token → EVM token (same chain): dex_monochain
319
1642
  */
320
1643
  declare function detectRoute(from: Currency, to: Currency): SwapRoute;
321
1644
  interface SupportedModes {
@@ -328,13 +1651,13 @@ interface SupportedModes {
328
1651
  * - cbBTC ↔ BTC: both modes supported
329
1652
  * - BTC → cbBTC: both modes supported
330
1653
  * - BTC → ERC20 (non-cbBTC): only exact_input (Rift doesn't support exact_output for chained swaps)
331
- * - ERC20 → BTC: exact_input only (1inch is exact-input quoting)
1654
+ * - ERC20 → BTC: both modes supported
332
1655
  */
333
1656
  declare function getSupportedModes(from: Currency, to: Currency): SupportedModes;
334
1657
  import { Account, PublicClient, Transport, WalletClient } from "viem";
335
1658
  import { Chain as Chain2 } from "viem/chains";
336
1659
  type RiftSwap = SwapStatusResponse;
337
- interface TradeParameters {
1660
+ interface QuoteParameters {
338
1661
  /** The currency to swap from */
339
1662
  from: Currency;
340
1663
  /** The currency to swap to */
@@ -343,10 +1666,8 @@ interface TradeParameters {
343
1666
  amount: string;
344
1667
  /** Whether amount refers to input or output */
345
1668
  mode: "exact_input" | "exact_output";
346
- /** Address to receive the output tokens */
347
- destinationAddress: string;
348
- /** Address to receive refunds if swap fails. Defaults to source wallet address */
349
- refundAddress?: string;
1669
+ /** Optional DEX quote quality target for DEX-backed routes. */
1670
+ quoteQuality?: QuoteQuality;
350
1671
  /**
351
1672
  * Approval amount strategy for ERC20 swaps.
352
1673
  * - "full" (default): approve max uint256
@@ -392,7 +1713,7 @@ interface ExactOutputQuoteResult extends QuoteResultBase {
392
1713
  type QuoteResult = ExactInputQuoteResult | ExactOutputQuoteResult;
393
1714
  interface GetQuoteResult {
394
1715
  quote: QuoteResult;
395
- executeSwap: <chain extends Chain2 | undefined = Chain2 | undefined>(context?: ExecuteSwapContext<chain>) => Promise<SwapResult>;
1716
+ executeSwap: <chain extends Chain2 | undefined = Chain2 | undefined>(context: ExecuteSwapOptions<chain>) => Promise<SwapResult>;
396
1717
  }
397
1718
  interface SwapResult {
398
1719
  swapId: string;
@@ -434,6 +1755,12 @@ type ExecuteSwapContext<chain extends Chain2 | undefined = Chain2 | undefined> =
434
1755
  /** Function to send Bitcoin (implement using your preferred wallet) */
435
1756
  sendBitcoin?: SendBitcoinFn;
436
1757
  };
1758
+ type ExecuteSwapOptions<chain extends Chain2 | undefined = Chain2 | undefined> = ExecuteSwapContext<chain> & {
1759
+ /** Address to receive the output tokens */
1760
+ destinationAddress: string;
1761
+ /** Address to receive refunds if swap fails. Defaults to source wallet address */
1762
+ refundAddress?: string;
1763
+ };
437
1764
  interface RiftSdkOptions {
438
1765
  /** Rift API URL. Defaults to production API */
439
1766
  apiUrl?: string;
@@ -464,17 +1791,17 @@ declare class RiftSdk {
464
1791
  * to: Currencies.Bitcoin.BTC,
465
1792
  * amount: '100000000', // 1 cbBTC
466
1793
  * mode: 'exact_input',
467
- * destinationAddress: 'bc1q...',
468
1794
  * })
469
1795
  *
470
1796
  * console.log(`You'll receive: ${quote.to.amount} sats`)
471
1797
  * const swap = await executeSwap({
1798
+ * destinationAddress: 'bc1q...',
472
1799
  * publicClient,
473
1800
  * walletClient,
474
1801
  * sendBitcoin,
475
1802
  * })
476
1803
  */
477
- getQuote(params: TradeParameters): Promise<GetQuoteResult>;
1804
+ getQuote(params: QuoteParameters): Promise<GetQuoteResult>;
478
1805
  /**
479
1806
  * Execute a single step from the server's execution steps.
480
1807
  * Dispatch based on `action` (the execution mechanism).
@@ -482,7 +1809,7 @@ declare class RiftSdk {
482
1809
  private executeStep;
483
1810
  /**
484
1811
  * Execute an EVM call step - send a transaction with calldata.
485
- * Handles: approval, transfer_evm, oneinch_swap
1812
+ * Handles: approval, transfer_evm, dex_swap
486
1813
  */
487
1814
  private executeEvmCallStep;
488
1815
  /**
@@ -505,4 +1832,4 @@ declare class RiftSdk {
505
1832
  getSwapStatus(swapId: string): Promise<SwapStatusResponse>;
506
1833
  }
507
1834
  declare function createRiftSdk(options: RiftSdkOptions): RiftSdk;
508
- export { getSupportedModes, detectRoute, createRiftSdk, createCurrency, createClient, TradeParameters, TokenIdentifier, SwapStatus2 as SwapStatus, SwapRouterApiError, SwapRoute, SwapResult, SwapResponse, SupportedModes, SendBitcoinFn, RiftSwap, RiftSdkOptions, RiftSdk, RiftClient, QuoteResult, NativeToken, GetQuoteResult, ExecutionStep, ExecutionAction, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Currencies, Chain, BtcTransferStep, BtcTransferKind, BitcoinChain, App };
1835
+ export { getSupportedModes, detectRoute, createRiftSdk, createCurrency, createClient, TokenIdentifier, SwapStatus2 as SwapStatus, SwapRouterApiError, SwapRoute, SwapResult, SwapResponse, SupportedModes, SendBitcoinFn, RiftSwap, RiftSdkOptions, RiftSdk, RiftClient, QuoteResult, QuoteQuality, QuoteParameters, NativeToken, GetQuoteResult, ExecutionStep, ExecutionAction, ExecuteSwapOptions, EvmChain, EvmCallStep, EvmCallKind, Erc20Token, Currency, Currencies, Chain, BtcTransferStep, BtcTransferKind, BitcoinChain, App };