@velora-dex/sdk 9.5.3-dev.1 → 9.5.4-dev.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.
Files changed (88) hide show
  1. package/README.md +2 -2
  2. package/dist/examples/deltaV2.d.ts +2 -0
  3. package/dist/examples/deltaV2.d.ts.map +1 -0
  4. package/dist/examples/helpers/deltaV2.d.ts +5 -0
  5. package/dist/examples/helpers/deltaV2.d.ts.map +1 -0
  6. package/dist/examples/wagmi.d.ts.map +1 -1
  7. package/dist/index.d.ts +18 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -1
  10. package/dist/methods/delta/getDeltaOrders.d.ts +4 -4
  11. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  12. package/dist/methods/delta/getDeltaPrice.d.ts +1 -1
  13. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  14. package/dist/methods/delta/helpers/orders.d.ts.map +1 -1
  15. package/dist/methods/delta/helpers/types.d.ts +11 -4
  16. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  17. package/dist/methods/delta/postDeltaOrder.d.ts +3 -3
  18. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  19. package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts +44 -0
  20. package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts.map +1 -0
  21. package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts +48 -0
  22. package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts.map +1 -0
  23. package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts +59 -0
  24. package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts.map +1 -0
  25. package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts +21 -0
  26. package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts.map +1 -0
  27. package/dist/methods/deltaV2/getAgentsListV2.d.ts +10 -0
  28. package/dist/methods/deltaV2/getAgentsListV2.d.ts.map +1 -0
  29. package/dist/methods/deltaV2/getBridgeRoutes.d.ts +20 -0
  30. package/dist/methods/deltaV2/getBridgeRoutes.d.ts.map +1 -0
  31. package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts +33 -0
  32. package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts.map +1 -0
  33. package/dist/methods/deltaV2/getDeltaPriceV2.d.ts +46 -0
  34. package/dist/methods/deltaV2/getDeltaPriceV2.d.ts.map +1 -0
  35. package/dist/methods/deltaV2/index.d.ts +59 -0
  36. package/dist/methods/deltaV2/index.d.ts.map +1 -0
  37. package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts +8 -0
  38. package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts.map +1 -0
  39. package/dist/methods/deltaV2/postDeltaOrderV2.d.ts +28 -0
  40. package/dist/methods/deltaV2/postDeltaOrderV2.d.ts.map +1 -0
  41. package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts +11 -0
  42. package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts.map +1 -0
  43. package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts +16 -0
  44. package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts.map +1 -0
  45. package/dist/methods/deltaV2/types.d.ts +163 -0
  46. package/dist/methods/deltaV2/types.d.ts.map +1 -0
  47. package/dist/sdk/full.d.ts +2 -0
  48. package/dist/sdk/full.d.ts.map +1 -1
  49. package/dist/sdk/simple.d.ts +10 -0
  50. package/dist/sdk/simple.d.ts.map +1 -1
  51. package/dist/sdk.cjs.development.js +1195 -512
  52. package/dist/sdk.cjs.development.js.map +1 -1
  53. package/dist/sdk.cjs.production.min.js +1 -1
  54. package/dist/sdk.cjs.production.min.js.map +1 -1
  55. package/dist/sdk.esm.js +1179 -513
  56. package/dist/sdk.esm.js.map +1 -1
  57. package/dist/types.d.ts +8 -0
  58. package/dist/types.d.ts.map +1 -1
  59. package/package.json +17 -9
  60. package/src/examples/deltaV2.ts +200 -0
  61. package/src/examples/helpers/deltaV2.ts +29 -0
  62. package/src/examples/wagmi.ts +2 -2
  63. package/src/index.js +31 -1
  64. package/src/index.ts +148 -0
  65. package/src/methods/delta/cancelDeltaOrder.ts +4 -1
  66. package/src/methods/delta/getDeltaOrders.ts +6 -5
  67. package/src/methods/delta/getDeltaPrice.ts +1 -1
  68. package/src/methods/delta/helpers/orders.ts +9 -101
  69. package/src/methods/delta/helpers/types.ts +24 -13
  70. package/src/methods/delta/postDeltaOrder.ts +4 -4
  71. package/src/methods/delta/postTWAPDeltaOrder.ts +1 -1
  72. package/src/methods/deltaV2/buildDeltaOrderV2.ts +86 -0
  73. package/src/methods/deltaV2/buildExternalDeltaOrderV2.ts +95 -0
  74. package/src/methods/deltaV2/buildTWAPDeltaOrderV2.ts +131 -0
  75. package/src/methods/deltaV2/cancelDeltaOrderV2.ts +103 -0
  76. package/src/methods/deltaV2/getAgentsListV2.ts +34 -0
  77. package/src/methods/deltaV2/getBridgeRoutes.ts +82 -0
  78. package/src/methods/deltaV2/getDeltaOrdersV2.ts +119 -0
  79. package/src/methods/deltaV2/getDeltaPriceV2.ts +108 -0
  80. package/src/methods/deltaV2/index.ts +303 -0
  81. package/src/methods/deltaV2/isTokenSupportedInDeltaV2.ts +52 -0
  82. package/src/methods/deltaV2/postDeltaOrderV2.ts +65 -0
  83. package/src/methods/deltaV2/postExternalDeltaOrderV2.ts +45 -0
  84. package/src/methods/deltaV2/postTWAPDeltaOrderV2.ts +63 -0
  85. package/src/methods/deltaV2/types.ts +189 -0
  86. package/src/sdk/full.ts +8 -0
  87. package/src/sdk/simple.ts +56 -0
  88. package/src/types.ts +9 -0
@@ -8,7 +8,8 @@ import type {
8
8
  import type {
9
9
  DeltaAuction,
10
10
  DeltaAuctionStatus,
11
- OnChainOrderType,
11
+ DeltaOrderType,
12
+ OnChainOrderMap,
12
13
  } from './helpers/types';
13
14
 
14
15
  /** @deprecated Use DeltaAuction directly */
@@ -32,7 +33,7 @@ type GetDeltaOrderByHash = (
32
33
  requestParams?: RequestParameters
33
34
  ) => Promise<DeltaAuction>;
34
35
 
35
- type OrdersFilter<T extends OnChainOrderType = OnChainOrderType> = {
36
+ type OrdersFilter<T extends keyof OnChainOrderMap = keyof OnChainOrderMap> = {
36
37
  /** @description Order.owner to fetch Delta Order for */
37
38
  userAddress: Address;
38
39
  /** @description Pagination option, page. Default 1 */
@@ -52,7 +53,7 @@ type OrdersFilter<T extends OnChainOrderType = OnChainOrderType> = {
52
53
  */
53
54
  status?: DeltaOrderFilterByStatus[];
54
55
  /** @description Filter by type. MARKET, LIMIT. Orders with both types are returned if not specified */
55
- type?: 'MARKET' | 'LIMIT';
56
+ type?: DeltaOrderType;
56
57
  /** @description Filter by on-chain order type. Order, ExternalOrder. Orders of all types are returned if not specified */
57
58
  onChainOrderType?: T;
58
59
  };
@@ -62,7 +63,7 @@ type OrderFiltersQuery = Omit<OrdersFilter, 'chainId' | 'status'> & {
62
63
  };
63
64
 
64
65
  type GetDeltaOrders = {
65
- <T extends OnChainOrderType>(
66
+ <T extends keyof OnChainOrderMap>(
66
67
  options: OrdersFilter<T> & { onChainOrderType: T },
67
68
  requestParams?: RequestParameters
68
69
  ): Promise<DeltaAuction<T>[]>;
@@ -126,7 +127,7 @@ export const constructGetDeltaOrders = ({
126
127
  };
127
128
 
128
129
  const getDeltaOrders: GetDeltaOrders = async <
129
- T extends OnChainOrderType = OnChainOrderType
130
+ T extends keyof OnChainOrderMap = keyof OnChainOrderMap
130
131
  >(
131
132
  options: OrdersFilter<T>,
132
133
  requestParams?: RequestParameters
@@ -12,7 +12,7 @@ import { BridgePriceInfo } from './helpers/types';
12
12
  type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
13
13
 
14
14
  export type DeltaPriceParams = {
15
- /** @description Source Token Address. Not Native Token */
15
+ /** @description Source Token Address */
16
16
  srcToken: string;
17
17
  /** @description Destination Token Address */
18
18
  destToken: string;
@@ -7,7 +7,6 @@ import {
7
7
  DeltaAuctionTransaction,
8
8
  DeltaAuctionTWAP,
9
9
  DeltaAuctionTWAPBuy,
10
- DeltaAuctionUnion,
11
10
  DeltaOrderUnion,
12
11
  ExternalDeltaOrder,
13
12
  OnChainOrderType,
@@ -359,6 +358,7 @@ function getAuctionAmounts(auction: DeltaAuction) {
359
358
 
360
359
  let expected = {
361
360
  srcAmount: auction.order.srcAmount,
361
+ // defensive fallback in case Order shape changes or legacy Orders don't have all fields
362
362
  destAmount: auction.order.expectedAmount || auction.order.destAmount,
363
363
  };
364
364
 
@@ -402,7 +402,7 @@ function isOrderCrosschain<T extends { bridge?: Bridge } | object>(
402
402
  function scaleByFactor(amount: bigint, scalingFactor: number): bigint {
403
403
  if (!amount) return 0n;
404
404
 
405
- if (scalingFactor === undefined) return amount;
405
+ if (scalingFactor === 0) return amount;
406
406
 
407
407
  const base = 10n;
408
408
 
@@ -538,111 +538,19 @@ function isPartiallyExecutedAuction<
538
538
  function getFilledPercent(
539
539
  auction: Pick<DeltaAuction, 'order' | 'transactions'>
540
540
  ): number {
541
- const transaction = !isOrderCrosschain(auction.order)
541
+ const completeTransactions = !isOrderCrosschain(auction.order)
542
542
  ? auction.transactions
543
543
  : auction.transactions.filter(
544
544
  (transaction) => transaction.bridgeStatus === 'filled'
545
545
  );
546
546
 
547
- const filledPercentBps = transaction.reduce((acc, { filledPercent }) => {
548
- return acc + filledPercent;
549
- }, 0);
547
+ const filledPercentBps = completeTransactions.reduce(
548
+ (acc, { filledPercent }) => {
549
+ return acc + filledPercent;
550
+ },
551
+ 0
552
+ );
550
553
 
551
554
  const filledPercent = filledPercentBps / 100;
552
555
  return filledPercent;
553
556
  }
554
-
555
- ///// TESTS //////
556
- // @TODO remove
557
-
558
- const auction = {} as DeltaAuctionUnion;
559
- const minAuction = {
560
- onChainOrderType: 'TWAPOrder' as OnChainOrderType,
561
- gas: 6,
562
- };
563
- if (isTWAPAuction(minAuction)) {
564
- console.log('🚀 ~ auction:', minAuction);
565
- /**
566
- * {
567
- onChainOrderType: OnChainOrderType;
568
- gas: number;
569
- } & {
570
- onChainOrderType: "TWAPOrder" | "TWAPBuyOrder";
571
- }
572
- */
573
- }
574
- if (isTWAPAuction(auction)) {
575
- console.log('🚀 ~ auction:', auction);
576
- /**
577
- (DeltaAuctionBase & {
578
- onChainOrderType: "TWAPOrder";
579
- order: TWAPDeltaOrder;
580
- }) | (DeltaAuctionBase & {
581
- onChainOrderType: "TWAPBuyOrder";
582
- order: TWAPBuyDeltaOrder;
583
- })
584
- */
585
- }
586
- if (isTWAPSellAuction(auction)) {
587
- console.log('🚀 ~ auction:', auction);
588
- /**
589
- * DeltaAuctionBase & {
590
- onChainOrderType: "TWAPOrder";
591
- order: TWAPDeltaOrder;
592
- }
593
- */
594
- }
595
- if (isTWAPBuyAuction(auction)) {
596
- console.log('🚀 ~ auction:', auction);
597
- /**
598
- * DeltaAuctionBase & {
599
- onChainOrderType: "TWAPBuyOrder";
600
- order: TWAPBuyDeltaOrder;
601
- }
602
- */
603
- }
604
- if (isDeltaAuction(auction)) {
605
- console.log('🚀 ~ auction:', auction);
606
- /**
607
- * DeltaAuctionBase & {
608
- onChainOrderType: "Order";
609
- order: DeltaAuctionOrder;
610
- }
611
- */
612
- }
613
-
614
- if (isExternalAuction(auction)) {
615
- console.log('🚀 ~ auction:', auction);
616
- /**
617
- * DeltaAuctionBase & {
618
- onChainOrderType: "ExternalOrder";
619
- order: ExternalDeltaOrder;
620
- }
621
- */
622
- }
623
- // ------------------------------------------------------------ //
624
-
625
- const orderAny = {} as DeltaOrderUnion;
626
- if (isOrderCrosschain(orderAny)) {
627
- console.log('🚀 ~ order:', orderAny);
628
- /**
629
- DeltaAuctionOrder | TWAPDeltaOrder | TWAPBuyDeltaOrder
630
- */
631
- }
632
- const orderExternal = {} as ExternalDeltaOrder;
633
- if (isOrderCrosschain(orderExternal)) {
634
- console.log('🚀 ~ order:', orderExternal);
635
- /**
636
- never
637
- */
638
- }
639
- const orderLike = {} as { bridge?: Bridge; a: 2 };
640
- if (isOrderCrosschain(orderLike)) {
641
- console.log('🚀 ~ order:', orderLike);
642
- /**
643
- * {
644
- bridge: Bridge;
645
- a: 2;
646
- }
647
- */
648
- }
@@ -204,7 +204,7 @@ export type DeltaAuctionTransaction = {
204
204
  agent: string;
205
205
  auctionId: string;
206
206
 
207
- // bridge* fileds = null for single-chain orders and all TWAP orders
207
+ // transactgion.bridge* fields = null for single-chain orders
208
208
  bridgeMetadata: BridgeMetadata | null;
209
209
  bridgeStatus: BridgeStatus | null;
210
210
  bridgeProtocol: string | null;
@@ -248,21 +248,23 @@ type DeltaAuctionBase = {
248
248
  excludeAgents: string[] | null;
249
249
  includeAgents: string[] | null;
250
250
 
251
+ // bridge* fields = null for single-chain orders and all TWAP orders
251
252
  bridgeMetadata: BridgeMetadata | null;
252
253
  bridgeStatus: BridgeStatus | null;
253
254
 
254
- type: 'MARKET' | 'LIMIT';
255
+ type: DeltaOrderType;
255
256
  };
256
257
 
257
- export type DeltaAuction<T extends OnChainOrderType = OnChainOrderType> =
258
- T extends T
259
- ? Prettify<
260
- DeltaAuctionBase & {
261
- onChainOrderType: T;
262
- order: OnChainOrderMap[T];
263
- } & BridgeAuctionFiledsMap[T]
264
- >
265
- : never;
258
+ export type DeltaAuction<
259
+ T extends keyof OnChainOrderMap = keyof OnChainOrderMap
260
+ > = T extends T
261
+ ? Prettify<
262
+ DeltaAuctionBase & {
263
+ onChainOrderType: T;
264
+ order: OnChainOrderMap[T];
265
+ } & BridgeAuctionFiledsMap[T]
266
+ >
267
+ : never;
266
268
 
267
269
  export type DeltaAuctionDelta = DeltaAuction<'Order'>;
268
270
  export type DeltaAuctionExternal = DeltaAuction<'ExternalOrder'>;
@@ -278,8 +280,13 @@ export type DeltaAuctionUnion =
278
280
  export type DeltaOrderUnion = OnChainOrderMap[keyof OnChainOrderMap];
279
281
 
280
282
  export type BridgeMetadata = {
281
- /** @description The amount that user should expect to get */
283
+ /** @description Actual amount received on the destination chain. */
282
284
  outputAmount: string;
285
+ /** @description Field is present iff: order was built via POST /v2/orders/build,
286
+ * the route is cross-chain (route.bridge !== null and not an external handler),
287
+ * and the order is posted before the per-order cache entry expires.
288
+ */
289
+ expectedOutputAmount?: string;
283
290
  /** @description The cross-chain deadline. If deadline passes, the bridgeStatus would be expired */
284
291
  fillDeadline?: number; // available for Across protocol
285
292
  /** @description The deposit id */
@@ -297,10 +304,14 @@ export type OnChainOrderType =
297
304
  | 'Order'
298
305
  | 'ExternalOrder'
299
306
  | 'TWAPOrder'
300
- | 'TWAPBuyOrder';
307
+ | 'TWAPBuyOrder'
308
+ | 'ProductiveOrder';
301
309
 
302
310
  export type TWAPOnChainOrderType = 'TWAPOrder' | 'TWAPBuyOrder';
303
311
 
312
+ /** @description Order kind: MARKET (immediate) vs LIMIT (rate-pegged). */
313
+ export type DeltaOrderType = 'MARKET' | 'LIMIT';
314
+
304
315
  //// available on BridgePrice ////
305
316
 
306
317
  type BridgeQuoteFee = {
@@ -3,11 +3,11 @@ import { constructSearchString } from '../../helpers/misc';
3
3
  import type { ConstructFetchInput, RequestParameters } from '../../types';
4
4
  import type {
5
5
  DeltaAuction,
6
+ DeltaOrderType,
6
7
  OnChainOrderMap,
7
- OnChainOrderType,
8
8
  } from './helpers/types';
9
9
 
10
- export type DeltaOrderToPost<T extends OnChainOrderType = 'Order'> = {
10
+ export type DeltaOrderToPost<T extends keyof OnChainOrderMap = 'Order'> = {
11
11
  /** @description Partner string */
12
12
  partner?: string;
13
13
  /** @description Referrer address */
@@ -20,7 +20,7 @@ export type DeltaOrderToPost<T extends OnChainOrderType = 'Order'> = {
20
20
  partiallyFillable?: boolean;
21
21
 
22
22
  /** @description Type of the order. MARKET or LIMIT. Default is MARKET */
23
- type?: 'MARKET' | 'LIMIT';
23
+ type?: DeltaOrderType;
24
24
 
25
25
  includeAgents?: string[];
26
26
  excludeAgents?: string[];
@@ -53,7 +53,7 @@ export const constructPostDeltaOrder = ({
53
53
  const search = constructSearchString<{ degenMode?: boolean }>({
54
54
  degenMode,
55
55
  });
56
- const fetchURL = `${postOrderUrl}/${search}` as const;
56
+ const fetchURL = `${postOrderUrl}${search}` as const;
57
57
 
58
58
  return fetcher<DeltaAuction<'Order'>>({
59
59
  url: fetchURL,
@@ -43,7 +43,7 @@ export const constructPostTWAPDeltaOrder = ({
43
43
  degenMode,
44
44
  });
45
45
 
46
- const fetchURL = `${postOrderUrl}/${search}` as const;
46
+ const fetchURL = `${postOrderUrl}${search}` as const;
47
47
 
48
48
  return fetcher<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>({
49
49
  url: fetchURL,
@@ -0,0 +1,86 @@
1
+ import { API_URL } from '../../constants';
2
+ import type { ConstructFetchInput, RequestParameters } from '../../types';
3
+ import type { BuiltDeltaOrderV2, DeltaRoute } from './types';
4
+ export type { BuiltDeltaOrderV2 } from './types';
5
+
6
+ export type BuildDeltaOrderV2Params = {
7
+ /** @description The address of the order owner */
8
+ owner: string;
9
+ /** @description The address of the order beneficiary. Defaults to owner. */
10
+ beneficiary?: string;
11
+ /** @description The deadline for the order (unix seconds) */
12
+ deadline?: number;
13
+ /** @description The nonce of the order. Random if omitted. */
14
+ nonce?: string;
15
+ /** @description Optional permit signature for the src token. Defaults to "0x". */
16
+ permit?: string;
17
+ /** @description Partner string. Passed to the server to resolve partner fee details. */
18
+ partner?: string;
19
+ /** @description Partner fee in basis points (bps), 50bps=0.5% */
20
+ partnerFeeBps?: number;
21
+ /** @description Partner address */
22
+ partnerAddress?: string;
23
+ /** @description Take surplus flag */
24
+ partnerTakesSurplus?: boolean;
25
+ /** @description Whether the surplus should be capped. True by default. */
26
+ capSurplus?: boolean;
27
+ /** @description Metadata for the order, hex string */
28
+ metadata?: string;
29
+ /** @description Designates the Order as partially fillable instead of fill-or-kill. Default false. */
30
+ partiallyFillable?: boolean;
31
+
32
+ /** @description DeltaRoute from getDeltaPriceV2 — either priceV2.route or any priceV2.alternatives[i] */
33
+ route: DeltaRoute;
34
+ /** @description Order side. SELL or BUY. */
35
+ side: 'SELL' | 'BUY';
36
+ /** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5%. Default 0. */
37
+ slippage?: number;
38
+ /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount */
39
+ limitAmount?: string;
40
+ };
41
+
42
+ type BuildDeltaOrderV2 = (
43
+ buildOrderParams: BuildDeltaOrderV2Params,
44
+ requestParams?: RequestParameters
45
+ ) => Promise<BuiltDeltaOrderV2>;
46
+
47
+ export type BuildDeltaOrderV2Functions = {
48
+ /** @description Build a Delta v2 order from a DeltaRoute via the server endpoint, ready to sign and post. */
49
+ buildDeltaOrderV2: BuildDeltaOrderV2;
50
+ };
51
+
52
+ export const constructBuildDeltaOrderV2 = (
53
+ options: ConstructFetchInput
54
+ ): BuildDeltaOrderV2Functions => {
55
+ const { apiURL = API_URL, chainId, fetcher } = options;
56
+ const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
57
+
58
+ const buildDeltaOrderV2: BuildDeltaOrderV2 = async (params, requestParams) =>
59
+ fetcher<BuiltDeltaOrderV2>({
60
+ url: buildUrl,
61
+ method: 'POST',
62
+ data: {
63
+ chainId,
64
+ side: params.side,
65
+ route: params.route,
66
+ owner: params.owner,
67
+ beneficiary: params.beneficiary,
68
+ deadline: params.deadline,
69
+ nonce: params.nonce,
70
+ permit: params.permit,
71
+ slippage: params.slippage,
72
+ limitAmount: params.limitAmount,
73
+ metadata: params.metadata,
74
+ partiallyFillable: params.partiallyFillable,
75
+ partner: params.partner,
76
+ partnerAddress: params.partnerAddress,
77
+ partnerFeeBps: params.partnerFeeBps,
78
+ partnerTakesSurplus: params.partnerTakesSurplus,
79
+ capSurplus: params.capSurplus,
80
+ orderType: 'Order',
81
+ },
82
+ requestParams,
83
+ });
84
+
85
+ return { buildDeltaOrderV2 };
86
+ };
@@ -0,0 +1,95 @@
1
+ import { API_URL } from '../../constants';
2
+ import type { ConstructFetchInput, RequestParameters } from '../../types';
3
+ import type { BuiltDeltaOrderV2, DeltaRoute } from './types';
4
+ export type { BuiltDeltaOrderV2 } from './types';
5
+
6
+ export type BuildExternalDeltaOrderV2Params = {
7
+ /** @description The address of the order owner */
8
+ owner: string;
9
+ /** @description The address of the external handler contract */
10
+ handler: string;
11
+ /** @description Protocol-specific encoded bytes for the external handler */
12
+ data: string;
13
+ /** @description The address of the order beneficiary. Defaults to owner. */
14
+ beneficiary?: string;
15
+ /** @description The deadline for the order (unix seconds) */
16
+ deadline?: number;
17
+ /** @description The nonce of the order. Random if omitted. */
18
+ nonce?: string;
19
+ /** @description Optional permit signature for the src token. Defaults to "0x". */
20
+ permit?: string;
21
+ /** @description Partner string. Passed to the server to resolve partner fee details. */
22
+ partner?: string;
23
+ /** @description Partner fee in basis points (bps), 50bps=0.5% */
24
+ partnerFeeBps?: number;
25
+ /** @description Partner address */
26
+ partnerAddress?: string;
27
+ /** @description Take surplus flag */
28
+ partnerTakesSurplus?: boolean;
29
+ /** @description Whether the surplus should be capped. True by default. */
30
+ capSurplus?: boolean;
31
+ /** @description Metadata for the order, hex string */
32
+ metadata?: string;
33
+ /** @description Designates the Order as partially fillable. Default false. */
34
+ partiallyFillable?: boolean;
35
+
36
+ /** @description DeltaRoute from getDeltaPriceV2 */
37
+ route: DeltaRoute;
38
+ /** @description Order side. SELL or BUY. */
39
+ side: 'SELL' | 'BUY';
40
+ /** @description Slippage in basis points (bps). Default 0. */
41
+ slippage?: number;
42
+ /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount */
43
+ limitAmount?: string;
44
+ };
45
+
46
+ type BuildExternalDeltaOrderV2 = (
47
+ buildOrderParams: BuildExternalDeltaOrderV2Params,
48
+ requestParams?: RequestParameters
49
+ ) => Promise<BuiltDeltaOrderV2>;
50
+
51
+ export type BuildExternalDeltaOrderV2Functions = {
52
+ /** @description Build a Delta v2 External Order from a DeltaRoute via the server endpoint, ready to sign and post. */
53
+ buildExternalDeltaOrderV2: BuildExternalDeltaOrderV2;
54
+ };
55
+
56
+ export const constructBuildExternalDeltaOrderV2 = (
57
+ options: ConstructFetchInput
58
+ ): BuildExternalDeltaOrderV2Functions => {
59
+ const { apiURL = API_URL, chainId, fetcher } = options;
60
+ const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
61
+
62
+ const buildExternalDeltaOrderV2: BuildExternalDeltaOrderV2 = async (
63
+ params,
64
+ requestParams
65
+ ) =>
66
+ fetcher<BuiltDeltaOrderV2>({
67
+ url: buildUrl,
68
+ method: 'POST',
69
+ data: {
70
+ chainId,
71
+ side: params.side,
72
+ route: params.route,
73
+ owner: params.owner,
74
+ handler: params.handler,
75
+ data: params.data,
76
+ beneficiary: params.beneficiary,
77
+ deadline: params.deadline,
78
+ nonce: params.nonce,
79
+ permit: params.permit,
80
+ slippage: params.slippage,
81
+ limitAmount: params.limitAmount,
82
+ metadata: params.metadata,
83
+ partiallyFillable: params.partiallyFillable,
84
+ partner: params.partner,
85
+ partnerAddress: params.partnerAddress,
86
+ partnerFeeBps: params.partnerFeeBps,
87
+ partnerTakesSurplus: params.partnerTakesSurplus,
88
+ capSurplus: params.capSurplus,
89
+ orderType: 'ExternalOrder',
90
+ },
91
+ requestParams,
92
+ });
93
+
94
+ return { buildExternalDeltaOrderV2 };
95
+ };
@@ -0,0 +1,131 @@
1
+ import { API_URL } from '../../constants';
2
+ import type { ConstructFetchInput, RequestParameters } from '../../types';
3
+ import type { BuiltDeltaOrderV2, DeltaRoute } from './types';
4
+ export type { BuiltDeltaOrderV2 } from './types';
5
+
6
+ type BuildTWAPDeltaOrderV2Base = {
7
+ /** @description The address of the order owner */
8
+ owner: string;
9
+ /** @description The address of the order beneficiary. Defaults to owner. */
10
+ beneficiary?: string;
11
+ /** @description The deadline for the order (unix seconds) */
12
+ deadline?: number;
13
+ /** @description The nonce of the order. Random if omitted. */
14
+ nonce?: string;
15
+ /** @description Optional permit signature for the src token. Defaults to "0x". */
16
+ permit?: string;
17
+ /** @description Partner string. Passed to the server to resolve partner fee details. */
18
+ partner?: string;
19
+ /** @description Seconds between slice executions (min 60) */
20
+ interval: number;
21
+ /** @description Number of slices (min 2) */
22
+ numSlices: number;
23
+ /** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5%. Default 0. */
24
+ slippage?: number;
25
+ /** @description DeltaRoute from getDeltaPriceV2 for a single slice */
26
+ route: DeltaRoute;
27
+ /** @description Partner fee in basis points (bps) */
28
+ partnerFeeBps?: number;
29
+ /** @description Partner address */
30
+ partnerAddress?: string;
31
+ /** @description Take surplus flag */
32
+ partnerTakesSurplus?: boolean;
33
+ /** @description Whether the surplus should be capped. True by default. */
34
+ capSurplus?: boolean;
35
+ /** @description Metadata for the order, hex string */
36
+ metadata?: string;
37
+ /** @description Designates the Order as partially fillable. Default false. */
38
+ partiallyFillable?: boolean;
39
+ /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount for each slice */
40
+ limitAmount?: string;
41
+ };
42
+
43
+ export type BuildTWAPSellDeltaOrderV2Params = BuildTWAPDeltaOrderV2Base & {
44
+ onChainOrderType: 'TWAPOrder';
45
+ /** @description Total source token amount across all slices. route.origin.input.amount must equal floor(totalSrcAmount / numSlices). */
46
+ totalSrcAmount: string;
47
+ };
48
+
49
+ export type BuildTWAPBuyDeltaOrderV2Params = BuildTWAPDeltaOrderV2Base & {
50
+ onChainOrderType: 'TWAPBuyOrder';
51
+ /** @description Total destination token amount to buy across all slices. route.origin.output.amount must equal floor(totalDestAmount / numSlices). */
52
+ totalDestAmount: string;
53
+ /** @description Maximum source token amount willing to spend across all slices. */
54
+ maxSrcAmount: string;
55
+ };
56
+
57
+ export type BuildTWAPDeltaOrderV2Params =
58
+ | BuildTWAPSellDeltaOrderV2Params
59
+ | BuildTWAPBuyDeltaOrderV2Params;
60
+
61
+ type BuildTWAPDeltaOrderV2 = (
62
+ buildOrderParams: BuildTWAPDeltaOrderV2Params,
63
+ requestParams?: RequestParameters
64
+ ) => Promise<BuiltDeltaOrderV2>;
65
+
66
+ export type BuildTWAPDeltaOrderV2Functions = {
67
+ /** @description Build a Delta v2 TWAP Order (sell or buy) from a DeltaRoute via the server endpoint, ready to sign and post. */
68
+ buildTWAPDeltaOrderV2: BuildTWAPDeltaOrderV2;
69
+ };
70
+
71
+ export const constructBuildTWAPDeltaOrderV2 = (
72
+ options: ConstructFetchInput
73
+ ): BuildTWAPDeltaOrderV2Functions => {
74
+ const { apiURL = API_URL, chainId, fetcher } = options;
75
+ const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
76
+
77
+ const buildTWAPDeltaOrderV2: BuildTWAPDeltaOrderV2 = async (
78
+ params,
79
+ requestParams
80
+ ) => {
81
+ const commonBody = {
82
+ chainId,
83
+ route: params.route,
84
+ owner: params.owner,
85
+ beneficiary: params.beneficiary,
86
+ deadline: params.deadline,
87
+ nonce: params.nonce,
88
+ permit: params.permit,
89
+ slippage: params.slippage,
90
+ limitAmount: params.limitAmount,
91
+ metadata: params.metadata,
92
+ partiallyFillable: params.partiallyFillable,
93
+ partner: params.partner,
94
+ partnerAddress: params.partnerAddress,
95
+ partnerFeeBps: params.partnerFeeBps,
96
+ partnerTakesSurplus: params.partnerTakesSurplus,
97
+ capSurplus: params.capSurplus,
98
+ interval: params.interval,
99
+ numSlices: params.numSlices,
100
+ };
101
+
102
+ if (params.onChainOrderType === 'TWAPOrder') {
103
+ return fetcher<BuiltDeltaOrderV2>({
104
+ url: buildUrl,
105
+ method: 'POST',
106
+ data: {
107
+ ...commonBody,
108
+ side: 'SELL',
109
+ orderType: 'TWAPOrder',
110
+ totalSrcAmount: params.totalSrcAmount,
111
+ },
112
+ requestParams,
113
+ });
114
+ }
115
+
116
+ return fetcher<BuiltDeltaOrderV2>({
117
+ url: buildUrl,
118
+ method: 'POST',
119
+ data: {
120
+ ...commonBody,
121
+ side: 'BUY',
122
+ orderType: 'TWAPBuyOrder',
123
+ totalDestAmount: params.totalDestAmount,
124
+ maxSrcAmount: params.maxSrcAmount,
125
+ },
126
+ requestParams,
127
+ });
128
+ };
129
+
130
+ return { buildTWAPDeltaOrderV2 };
131
+ };