@velora-dex/sdk 9.3.6 → 9.4.1-dev.1

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 (147) hide show
  1. package/README.md +2 -0
  2. package/dist/examples/externalDelta.d.ts +2 -0
  3. package/dist/examples/externalDelta.d.ts.map +1 -0
  4. package/dist/examples/helpers/delta.d.ts +2 -2
  5. package/dist/examples/helpers/delta.d.ts.map +1 -1
  6. package/dist/index.d.ts +17 -6
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/methods/delta/buildDeltaOrder.d.ts +4 -10
  9. package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
  10. package/dist/methods/delta/buildExternalDeltaOrder.d.ts +46 -0
  11. package/dist/methods/delta/buildExternalDeltaOrder.d.ts.map +1 -0
  12. package/dist/methods/delta/buildTWAPDeltaOrder.d.ts +65 -0
  13. package/dist/methods/delta/buildTWAPDeltaOrder.d.ts.map +1 -0
  14. package/dist/methods/delta/getDeltaOrders.d.ts +14 -6
  15. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  16. package/dist/methods/delta/helpers/abi.d.ts +16 -0
  17. package/dist/methods/delta/helpers/abi.d.ts.map +1 -0
  18. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +0 -1
  19. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -1
  20. package/dist/methods/delta/helpers/buildExternalOrderData.d.ts +34 -0
  21. package/dist/methods/delta/helpers/buildExternalOrderData.d.ts.map +1 -0
  22. package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts +74 -0
  23. package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts.map +1 -0
  24. package/dist/methods/delta/helpers/misc.d.ts +51 -0
  25. package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
  26. package/dist/methods/delta/helpers/types.d.ts +116 -4
  27. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  28. package/dist/methods/delta/index.d.ts +34 -3
  29. package/dist/methods/delta/index.d.ts.map +1 -1
  30. package/dist/methods/delta/postDeltaOrder.d.ts +4 -9
  31. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  32. package/dist/methods/delta/postExternalDeltaOrder.d.ts +11 -0
  33. package/dist/methods/delta/postExternalDeltaOrder.d.ts.map +1 -0
  34. package/dist/methods/delta/postTWAPDeltaOrder.d.ts +16 -0
  35. package/dist/methods/delta/postTWAPDeltaOrder.d.ts.map +1 -0
  36. package/dist/methods/delta/preSignDeltaOrder.d.ts.map +1 -1
  37. package/dist/methods/delta/preSignExternalDeltaOrder.d.ts +17 -0
  38. package/dist/methods/delta/preSignExternalDeltaOrder.d.ts.map +1 -0
  39. package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts +20 -0
  40. package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts.map +1 -0
  41. package/dist/methods/delta/signExternalDeltaOrder.d.ts +9 -0
  42. package/dist/methods/delta/signExternalDeltaOrder.d.ts.map +1 -0
  43. package/dist/methods/delta/signTWAPDeltaOrder.d.ts +9 -0
  44. package/dist/methods/delta/signTWAPDeltaOrder.d.ts.map +1 -0
  45. package/dist/methods/limitOrders/approveForOrder.d.ts +2 -0
  46. package/dist/methods/limitOrders/approveForOrder.d.ts.map +1 -1
  47. package/dist/methods/limitOrders/buildOrder.d.ts +3 -0
  48. package/dist/methods/limitOrders/buildOrder.d.ts.map +1 -1
  49. package/dist/methods/limitOrders/cancelOrder.d.ts +2 -0
  50. package/dist/methods/limitOrders/cancelOrder.d.ts.map +1 -1
  51. package/dist/methods/limitOrders/fillOrderDirectly.d.ts +2 -0
  52. package/dist/methods/limitOrders/fillOrderDirectly.d.ts.map +1 -1
  53. package/dist/methods/limitOrders/getOrders.d.ts +2 -0
  54. package/dist/methods/limitOrders/getOrders.d.ts.map +1 -1
  55. package/dist/methods/limitOrders/getOrdersContract.d.ts +2 -0
  56. package/dist/methods/limitOrders/getOrdersContract.d.ts.map +1 -1
  57. package/dist/methods/limitOrders/index.d.ts +7 -1
  58. package/dist/methods/limitOrders/index.d.ts.map +1 -1
  59. package/dist/methods/limitOrders/postOrder.d.ts +2 -0
  60. package/dist/methods/limitOrders/postOrder.d.ts.map +1 -1
  61. package/dist/methods/limitOrders/signOrder.d.ts +2 -0
  62. package/dist/methods/limitOrders/signOrder.d.ts.map +1 -1
  63. package/dist/methods/limitOrders/transaction.d.ts +2 -0
  64. package/dist/methods/limitOrders/transaction.d.ts.map +1 -1
  65. package/dist/methods/nftOrders/approveForOrder.d.ts +2 -0
  66. package/dist/methods/nftOrders/approveForOrder.d.ts.map +1 -1
  67. package/dist/methods/nftOrders/buildOrder.d.ts +3 -0
  68. package/dist/methods/nftOrders/buildOrder.d.ts.map +1 -1
  69. package/dist/methods/nftOrders/cancelOrder.d.ts +2 -0
  70. package/dist/methods/nftOrders/cancelOrder.d.ts.map +1 -1
  71. package/dist/methods/nftOrders/getOrders.d.ts +2 -0
  72. package/dist/methods/nftOrders/getOrders.d.ts.map +1 -1
  73. package/dist/methods/nftOrders/getOrdersContract.d.ts +2 -0
  74. package/dist/methods/nftOrders/getOrdersContract.d.ts.map +1 -1
  75. package/dist/methods/nftOrders/helpers/misc.d.ts +1 -0
  76. package/dist/methods/nftOrders/helpers/misc.d.ts.map +1 -1
  77. package/dist/methods/nftOrders/index.d.ts +7 -1
  78. package/dist/methods/nftOrders/index.d.ts.map +1 -1
  79. package/dist/methods/nftOrders/postOrder.d.ts +2 -0
  80. package/dist/methods/nftOrders/postOrder.d.ts.map +1 -1
  81. package/dist/methods/nftOrders/signOrder.d.ts +2 -0
  82. package/dist/methods/nftOrders/signOrder.d.ts.map +1 -1
  83. package/dist/methods/nftOrders/transaction.d.ts +2 -0
  84. package/dist/methods/nftOrders/transaction.d.ts.map +1 -1
  85. package/dist/sdk/full.d.ts +2 -0
  86. package/dist/sdk/full.d.ts.map +1 -1
  87. package/dist/sdk/partial.d.ts +5 -1
  88. package/dist/sdk/partial.d.ts.map +1 -1
  89. package/dist/sdk/simple.d.ts +6 -0
  90. package/dist/sdk/simple.d.ts.map +1 -1
  91. package/dist/sdk.cjs.development.js +1357 -210
  92. package/dist/sdk.cjs.development.js.map +1 -1
  93. package/dist/sdk.cjs.production.min.js +1 -1
  94. package/dist/sdk.cjs.production.min.js.map +1 -1
  95. package/dist/sdk.esm.js +1348 -211
  96. package/dist/sdk.esm.js.map +1 -1
  97. package/package.json +1 -1
  98. package/src/constants.js +3 -0
  99. package/src/examples/delta.ts +9 -20
  100. package/src/examples/externalDelta.ts +162 -0
  101. package/src/examples/helpers/delta.ts +8 -4
  102. package/src/gas.js +1 -0
  103. package/src/index.js +85 -0
  104. package/src/index.ts +103 -3
  105. package/src/methods/delta/buildDeltaOrder.ts +13 -61
  106. package/src/methods/delta/buildExternalDeltaOrder.ts +124 -0
  107. package/src/methods/delta/buildTWAPDeltaOrder.ts +181 -0
  108. package/src/methods/delta/getDeltaOrders.ts +31 -13
  109. package/src/methods/delta/helpers/abi.ts +20 -0
  110. package/src/methods/delta/helpers/buildDeltaOrderData.ts +3 -35
  111. package/src/methods/delta/helpers/buildExternalOrderData.ts +129 -0
  112. package/src/methods/delta/helpers/buildTWAPOrderData.ts +227 -0
  113. package/src/methods/delta/helpers/misc.ts +244 -0
  114. package/src/methods/delta/helpers/types.ts +138 -9
  115. package/src/methods/delta/index.ts +159 -3
  116. package/src/methods/delta/postDeltaOrder.ts +9 -11
  117. package/src/methods/delta/postExternalDeltaOrder.ts +45 -0
  118. package/src/methods/delta/postTWAPDeltaOrder.ts +57 -0
  119. package/src/methods/delta/preSignDeltaOrder.ts +1 -21
  120. package/src/methods/delta/preSignExternalDeltaOrder.ts +141 -0
  121. package/src/methods/delta/preSignTWAPDeltaOrder.ts +168 -0
  122. package/src/methods/delta/signExternalDeltaOrder.ts +35 -0
  123. package/src/methods/delta/signTWAPDeltaOrder.ts +32 -0
  124. package/src/methods/limitOrders/approveForOrder.ts +2 -0
  125. package/src/methods/limitOrders/buildOrder.ts +3 -0
  126. package/src/methods/limitOrders/cancelOrder.ts +2 -0
  127. package/src/methods/limitOrders/fillOrderDirectly.ts +2 -0
  128. package/src/methods/limitOrders/getOrders.ts +2 -0
  129. package/src/methods/limitOrders/getOrdersContract.ts +2 -0
  130. package/src/methods/limitOrders/index.ts +7 -1
  131. package/src/methods/limitOrders/postOrder.ts +2 -0
  132. package/src/methods/limitOrders/signOrder.ts +2 -0
  133. package/src/methods/limitOrders/transaction.ts +2 -0
  134. package/src/methods/nftOrders/approveForOrder.ts +2 -0
  135. package/src/methods/nftOrders/buildOrder.ts +3 -0
  136. package/src/methods/nftOrders/cancelOrder.ts +2 -0
  137. package/src/methods/nftOrders/getOrders.ts +2 -0
  138. package/src/methods/nftOrders/getOrdersContract.ts +2 -0
  139. package/src/methods/nftOrders/helpers/misc.ts +1 -0
  140. package/src/methods/nftOrders/index.ts +7 -1
  141. package/src/methods/nftOrders/postOrder.ts +2 -0
  142. package/src/methods/nftOrders/signOrder.ts +2 -0
  143. package/src/methods/nftOrders/transaction.ts +2 -0
  144. package/src/sdk/full.ts +2 -0
  145. package/src/sdk/partial.ts +5 -1
  146. package/src/sdk/simple.ts +6 -0
  147. package/src/types.js +1 -0
@@ -0,0 +1,124 @@
1
+ import type { ConstructFetchInput, RequestParameters } from '../../types';
2
+ import { constructGetDeltaContract } from './getDeltaContract';
3
+ import type { DeltaPrice } from './getDeltaPrice';
4
+ import { constructGetPartnerFee } from './getPartnerFee';
5
+ import {
6
+ buildExternalOrderSignableData,
7
+ type BuildExternalOrderDataInput,
8
+ type SignableExternalOrderData,
9
+ } from './helpers/buildExternalOrderData';
10
+ import type { AmountsWithSlippage } from './helpers/types';
11
+ import { SwapSideToOrderKind } from './helpers/types';
12
+ import type { MarkOptional } from 'ts-essentials';
13
+ import { resolvePartnerFee, resolveAmounts } from './helpers/misc';
14
+ export type { SignableExternalOrderData } from './helpers/buildExternalOrderData';
15
+
16
+ type BuildExternalDeltaOrderParamsBase = {
17
+ /** @description The address of the order owner */
18
+ owner: string;
19
+ /** @description The address of the external handler contract */
20
+ handler: string;
21
+ /** @description Protocol-specific encoded bytes for the external handler */
22
+ data: string;
23
+ /** @description The address of the src token */
24
+ srcToken: string;
25
+ /** @description The address of the dest token */
26
+ destToken: string;
27
+ /** @description The deadline for the order */
28
+ deadline?: number;
29
+ /** @description The nonce of the order */
30
+ nonce?: number | string;
31
+ /** @description Optional permit signature for the src token */
32
+ permit?: string;
33
+ /** @description Partner string */
34
+ partner?: string;
35
+ /** @description partner fee in basis points (bps), 50bps=0.5% */
36
+ partnerFeeBps?: number;
37
+ /** @description partner address */
38
+ partnerAddress?: string;
39
+ /** @description take surplus */
40
+ partnerTakesSurplus?: boolean;
41
+ /** @description A boolean indicating whether the surplus should be capped. True by default */
42
+ capSurplus?: boolean;
43
+ /** @description Metadata for the order, hex string */
44
+ metadata?: string;
45
+
46
+ /** @description price response received from /delta/prices (getDeltaPrice method) */
47
+ deltaPrice: MarkOptional<
48
+ Pick<
49
+ DeltaPrice,
50
+ 'destAmount' | 'partner' | 'partnerFee' | 'destToken' | 'srcAmount'
51
+ >,
52
+ 'partner' | 'partnerFee'
53
+ >;
54
+ };
55
+
56
+ export type BuildExternalDeltaOrderParams = BuildExternalDeltaOrderParamsBase &
57
+ AmountsWithSlippage;
58
+
59
+ type BuildExternalDeltaOrder = (
60
+ buildOrderParams: BuildExternalDeltaOrderParams,
61
+ requestParams?: RequestParameters
62
+ ) => Promise<SignableExternalOrderData>;
63
+
64
+ export type BuildExternalDeltaOrderFunctions = {
65
+ /** @description Build External Orders to be posted to Delta API for execution */
66
+ buildExternalDeltaOrder: BuildExternalDeltaOrder;
67
+ };
68
+
69
+ export const constructBuildExternalDeltaOrder = (
70
+ options: ConstructFetchInput
71
+ ): BuildExternalDeltaOrderFunctions => {
72
+ const { chainId } = options;
73
+
74
+ // cached internally
75
+ const { getDeltaContract } = constructGetDeltaContract(options);
76
+ // cached internally for `partner`
77
+ const { getPartnerFee } = constructGetPartnerFee(options);
78
+
79
+ const buildExternalDeltaOrder: BuildExternalDeltaOrder = async (
80
+ options,
81
+ requestParams
82
+ ) => {
83
+ const ParaswapDelta = await getDeltaContract(requestParams);
84
+ if (!ParaswapDelta) {
85
+ throw new Error(`Delta is not available on chain ${chainId}`);
86
+ }
87
+
88
+ const { partnerAddress, partnerFeeBps, partnerTakesSurplus } =
89
+ await resolvePartnerFee(options, getPartnerFee, requestParams);
90
+
91
+ const { srcAmount, destAmount, expectedAmount, swapSide } =
92
+ resolveAmounts(options);
93
+
94
+ const input: BuildExternalOrderDataInput = {
95
+ owner: options.owner,
96
+ handler: options.handler,
97
+ srcToken: options.srcToken,
98
+ destToken: options.deltaPrice.destToken,
99
+ srcAmount,
100
+ destAmount,
101
+ expectedAmount,
102
+ deadline: options.deadline,
103
+ nonce: options.nonce?.toString(10),
104
+ permit: options.permit,
105
+ kind: SwapSideToOrderKind[swapSide],
106
+ metadata: options.metadata,
107
+ data: options.data,
108
+
109
+ chainId,
110
+ paraswapDeltaAddress: ParaswapDelta,
111
+ partnerAddress,
112
+ partnerTakesSurplus,
113
+ partnerFeeBps,
114
+
115
+ capSurplus: options.capSurplus,
116
+ };
117
+
118
+ return buildExternalOrderSignableData(input);
119
+ };
120
+
121
+ return {
122
+ buildExternalDeltaOrder,
123
+ };
124
+ };
@@ -0,0 +1,181 @@
1
+ import type { ConstructFetchInput, RequestParameters } from '../../types';
2
+ import { constructGetDeltaContract } from './getDeltaContract';
3
+ import type { BridgePrice } from './getDeltaPrice';
4
+ import { constructGetPartnerFee } from './getPartnerFee';
5
+ import {
6
+ buildTWAPSignableOrderData,
7
+ type BuildTWAPOrderDataInput,
8
+ type SignableTWAPOrderData,
9
+ } from './helpers/buildTWAPOrderData';
10
+ import { applySlippage, resolvePartnerFee } from './helpers/misc';
11
+ import type { MarkOptional } from 'ts-essentials';
12
+ export type { SignableTWAPOrderData } from './helpers/buildTWAPOrderData';
13
+
14
+ type BuildTWAPDeltaOrderParamsBase = {
15
+ /** @description The address of the order owner */
16
+ owner: string;
17
+ /** @description The address of the order beneficiary */
18
+ beneficiary?: string;
19
+ /** @description The address of the src token */
20
+ srcToken: string;
21
+ /** @description The address of the dest token. For Crosschain Order - destination token on the destination chain */
22
+ destToken: string;
23
+ /** @description The deadline for the order */
24
+ deadline?: number;
25
+ /** @description The nonce of the order */
26
+ nonce?: number | string;
27
+ /** @description Optional permit signature for the src token */
28
+ permit?: string;
29
+ /** @description Partner string */
30
+ partner?: string;
31
+ /** @description Destination Chain ID for Crosschain Orders */
32
+ destChainId?: number;
33
+ /** @description Seconds between slice executions (min 60) */
34
+ interval: number;
35
+ /** @description Number of slices (min 2) */
36
+ numSlices: number;
37
+ /** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5% */
38
+ slippage?: number;
39
+
40
+ /** @description price response received from /delta/prices (getDeltaPrice method) for a single slice */
41
+ deltaPrice: MarkOptional<
42
+ Pick<
43
+ BridgePrice,
44
+ | 'destAmount'
45
+ | 'partner'
46
+ | 'partnerFee'
47
+ | 'destToken'
48
+ | 'srcAmount'
49
+ | 'bridge'
50
+ >,
51
+ 'partner' | 'partnerFee'
52
+ >;
53
+
54
+ /** @description partner fee in basis points (bps), 50bps=0.5% */
55
+ partnerFeeBps?: number;
56
+ /** @description partner address */
57
+ partnerAddress?: string;
58
+ /** @description take surplus */
59
+ partnerTakesSurplus?: boolean;
60
+ /** @description A boolean indicating whether the surplus should be capped. True by default */
61
+ capSurplus?: boolean;
62
+ /** @description Metadata for the order, hex string */
63
+ metadata?: string;
64
+ };
65
+
66
+ export type BuildTWAPSellOrderParams = BuildTWAPDeltaOrderParamsBase & {
67
+ /** @description Must be "TWAPOrder" for sell orders */
68
+ onChainOrderType: 'TWAPOrder';
69
+ /** @description Total source token amount across all slices */
70
+ totalSrcAmount: string;
71
+ };
72
+
73
+ export type BuildTWAPBuyOrderParams = BuildTWAPDeltaOrderParamsBase & {
74
+ /** @description Must be "TWAPBuyOrder" for buy orders */
75
+ onChainOrderType: 'TWAPBuyOrder';
76
+ /** @description Total destination token amount to buy across all slices */
77
+ totalDestAmount: string;
78
+ /** @description Maximum source token amount willing to spend */
79
+ maxSrcAmount: string;
80
+ };
81
+
82
+ export type BuildTWAPDeltaOrderParams =
83
+ | BuildTWAPSellOrderParams
84
+ | BuildTWAPBuyOrderParams;
85
+
86
+ type BuildTWAPDeltaOrder = (
87
+ buildOrderParams: BuildTWAPDeltaOrderParams,
88
+ requestParams?: RequestParameters
89
+ ) => Promise<SignableTWAPOrderData>;
90
+
91
+ export type BuildTWAPDeltaOrderFunctions = {
92
+ /** @description Build TWAP Orders (sell or buy) to be posted to Delta API for execution */
93
+ buildTWAPDeltaOrder: BuildTWAPDeltaOrder;
94
+ };
95
+
96
+ export const constructBuildTWAPDeltaOrder = (
97
+ options: ConstructFetchInput
98
+ ): BuildTWAPDeltaOrderFunctions => {
99
+ const { chainId } = options;
100
+
101
+ const { getDeltaContract } = constructGetDeltaContract(options);
102
+ const { getPartnerFee } = constructGetPartnerFee(options);
103
+
104
+ const buildTWAPDeltaOrder: BuildTWAPDeltaOrder = async (
105
+ params,
106
+ requestParams
107
+ ) => {
108
+ const ParaswapDelta = await getDeltaContract(requestParams);
109
+ if (!ParaswapDelta) {
110
+ throw new Error(`Delta is not available on chain ${chainId}`);
111
+ }
112
+
113
+ const { partnerAddress, partnerFeeBps, partnerTakesSurplus } =
114
+ await resolvePartnerFee(params, getPartnerFee, requestParams);
115
+
116
+ const commonInput = {
117
+ owner: params.owner,
118
+ beneficiary: params.beneficiary,
119
+ srcToken: params.srcToken,
120
+ destToken: params.deltaPrice.destToken,
121
+ deadline: params.deadline,
122
+ nonce: params.nonce?.toString(10),
123
+ permit: params.permit,
124
+ metadata: params.metadata,
125
+ interval: params.interval,
126
+ numSlices: params.numSlices,
127
+ bridge: params.deltaPrice.bridge,
128
+
129
+ chainId,
130
+ paraswapDeltaAddress: ParaswapDelta,
131
+ partnerAddress,
132
+ partnerTakesSurplus,
133
+ partnerFeeBps,
134
+ capSurplus: params.capSurplus,
135
+ };
136
+
137
+ let input: BuildTWAPOrderDataInput;
138
+
139
+ if (params.onChainOrderType === 'TWAPOrder') {
140
+ const slippage = params.slippage ?? 0;
141
+ const destAmountPerSlice =
142
+ slippage > 0
143
+ ? applySlippage({
144
+ amount: params.deltaPrice.destAmount,
145
+ slippageBps: slippage,
146
+ increase: false,
147
+ })
148
+ : params.deltaPrice.destAmount;
149
+
150
+ input = {
151
+ ...commonInput,
152
+ onChainOrderType: 'TWAPOrder',
153
+ destAmountPerSlice,
154
+ totalSrcAmount: params.totalSrcAmount,
155
+ };
156
+ } else {
157
+ const slippage = params.slippage ?? 0;
158
+ const maxSrcAmount =
159
+ slippage > 0
160
+ ? applySlippage({
161
+ amount: params.maxSrcAmount,
162
+ slippageBps: slippage,
163
+ increase: true,
164
+ })
165
+ : params.maxSrcAmount;
166
+
167
+ input = {
168
+ ...commonInput,
169
+ onChainOrderType: 'TWAPBuyOrder',
170
+ totalDestAmount: params.totalDestAmount,
171
+ maxSrcAmount,
172
+ };
173
+ }
174
+
175
+ return buildTWAPSignableOrderData(input);
176
+ };
177
+
178
+ return {
179
+ buildTWAPDeltaOrder,
180
+ };
181
+ };
@@ -5,9 +5,14 @@ import type {
5
5
  ConstructFetchInput,
6
6
  RequestParameters,
7
7
  } from '../../types';
8
- import type { DeltaAuction, DeltaAuctionStatus } from './helpers/types';
8
+ import type {
9
+ DeltaAuction,
10
+ DeltaAuctionStatus,
11
+ OnChainOrderType,
12
+ } from './helpers/types';
9
13
 
10
- export type DeltaOrderFromAPI = Omit<DeltaAuction, 'signature'>;
14
+ /** @deprecated Use DeltaAuction directly */
15
+ export type DeltaOrderFromAPI = DeltaAuction;
11
16
 
12
17
  export type DeltaOrderFilterByStatus =
13
18
  | DeltaAuctionStatus
@@ -20,14 +25,14 @@ export type DeltaOrderFilterByStatus =
20
25
  type GetDeltaOrderById = (
21
26
  orderId: string,
22
27
  requestParams?: RequestParameters
23
- ) => Promise<DeltaOrderFromAPI>;
28
+ ) => Promise<DeltaAuction>;
24
29
 
25
30
  type GetDeltaOrderByHash = (
26
31
  orderHash: string,
27
32
  requestParams?: RequestParameters
28
- ) => Promise<DeltaOrderFromAPI>;
33
+ ) => Promise<DeltaAuction>;
29
34
 
30
- type OrdersFilter = {
35
+ type OrdersFilter<T extends OnChainOrderType = OnChainOrderType> = {
31
36
  /** @description Order.owner to fetch Delta Order for */
32
37
  userAddress: Address;
33
38
  /** @description Pagination option, page. Default 1 */
@@ -48,16 +53,23 @@ type OrdersFilter = {
48
53
  status?: DeltaOrderFilterByStatus[];
49
54
  /** @description Filter by type. MARKET, LIMIT. Orders with both types are returned if not specified */
50
55
  type?: 'MARKET' | 'LIMIT';
56
+ /** @description Filter by on-chain order type. Order, ExternalOrder. Orders of all types are returned if not specified */
57
+ onChainOrderType?: T;
51
58
  };
52
59
  type OrderFiltersQuery = Omit<OrdersFilter, 'chainId' | 'status'> & {
53
60
  chainId?: string;
54
61
  status?: string;
55
62
  };
56
63
 
57
- type GetDeltaOrders = (
58
- options: OrdersFilter,
59
- requestParams?: RequestParameters
60
- ) => Promise<DeltaOrderFromAPI[]>;
64
+ type GetDeltaOrders = {
65
+ <T extends OnChainOrderType>(
66
+ options: OrdersFilter<T> & { onChainOrderType: T },
67
+ requestParams?: RequestParameters
68
+ ): Promise<DeltaAuction<T>[]>;
69
+ (options: OrdersFilter, requestParams?: RequestParameters): Promise<
70
+ DeltaAuction[]
71
+ >;
72
+ };
61
73
 
62
74
  type GetRequiredBalanceParams = {
63
75
  userAddress: Address;
@@ -89,7 +101,7 @@ export const constructGetDeltaOrders = ({
89
101
  ) => {
90
102
  const fetchURL = `${baseUrl}/${orderId}` as const;
91
103
 
92
- const order = await fetcher<DeltaOrderFromAPI>({
104
+ const order = await fetcher<DeltaAuction>({
93
105
  url: fetchURL,
94
106
  method: 'GET',
95
107
  requestParams,
@@ -104,7 +116,7 @@ export const constructGetDeltaOrders = ({
104
116
  ) => {
105
117
  const fetchURL = `${baseUrl}/hash/${orderHash}` as const;
106
118
 
107
- const order = await fetcher<DeltaOrderFromAPI>({
119
+ const order = await fetcher<DeltaAuction>({
108
120
  url: fetchURL,
109
121
  method: 'GET',
110
122
  requestParams,
@@ -113,7 +125,12 @@ export const constructGetDeltaOrders = ({
113
125
  return order;
114
126
  };
115
127
 
116
- const getDeltaOrders: GetDeltaOrders = async (options, requestParams) => {
128
+ const getDeltaOrders: GetDeltaOrders = async <
129
+ T extends OnChainOrderType = OnChainOrderType
130
+ >(
131
+ options: OrdersFilter<T>,
132
+ requestParams?: RequestParameters
133
+ ) => {
117
134
  const chainIdString = options.chainId?.join(',');
118
135
  const statusString = options.status?.join(',');
119
136
 
@@ -122,13 +139,14 @@ export const constructGetDeltaOrders = ({
122
139
  page: options.page,
123
140
  limit: options.limit,
124
141
  type: options.type,
142
+ onChainOrderType: options.onChainOrderType,
125
143
  chainId: chainIdString,
126
144
  status: statusString,
127
145
  });
128
146
 
129
147
  const fetchURL = `${baseUrl}${search}` as const;
130
148
 
131
- const orders = await fetcher<DeltaOrderFromAPI[]>({
149
+ const orders = await fetcher<DeltaAuction<T>[]>({
132
150
  url: fetchURL,
133
151
  method: 'GET',
134
152
  requestParams,
@@ -0,0 +1,20 @@
1
+ export const PreSignatureModuleAbi = [
2
+ {
3
+ inputs: [
4
+ {
5
+ internalType: 'bytes32',
6
+ name: 'orderHash',
7
+ type: 'bytes32',
8
+ },
9
+ {
10
+ internalType: 'bool',
11
+ name: 'preSigned',
12
+ type: 'bool',
13
+ },
14
+ ],
15
+ name: 'setPreSignature',
16
+ outputs: [],
17
+ stateMutability: 'nonpayable',
18
+ type: 'function',
19
+ },
20
+ ] as const;
@@ -1,6 +1,7 @@
1
1
  import { MarkOptional } from 'ts-essentials';
2
- import { Domain, ZERO_ADDRESS } from '../../common/orders/buildOrderData';
2
+ import { Domain } from '../../common/orders/buildOrderData';
3
3
  import { Bridge, DeltaAuctionOrder } from './types';
4
+ import { DELTA_DEFAULT_EXPIRY, producePartnerAndFee } from './misc';
4
5
 
5
6
  // Order(address owner,address beneficiary,address srcToken,address destToken,uint256 srcAmount,uint256 destAmount,uint256 deadline,uint256 nonce,bytes permit, bridge Bridge)";
6
7
  const SWAP_ORDER_EIP_712_TYPES = {
@@ -64,7 +65,7 @@ export function produceDeltaOrderTypedData({
64
65
  chainId,
65
66
  paraswapDeltaAddress,
66
67
  }: SignDeltaOrderInput): SignableDeltaOrderData {
67
- const typedData = {
68
+ return {
68
69
  types: {
69
70
  Order: SWAP_ORDER_EIP_712_TYPES.Order,
70
71
  Bridge: SWAP_ORDER_EIP_712_TYPES.Bridge,
@@ -77,8 +78,6 @@ export function produceDeltaOrderTypedData({
77
78
  },
78
79
  data: orderInput,
79
80
  };
80
-
81
- return typedData;
82
81
  }
83
82
 
84
83
  export type DeltaOrderDataInput = MarkOptional<
@@ -99,9 +98,6 @@ export type BuildDeltaOrderDataInput = MarkOptional<
99
98
  bridge: Bridge;
100
99
  };
101
100
 
102
- // default deadline = 1 hour for now (may be changed later)
103
- export const DELTA_DEFAULT_EXPIRY = 60 * 60; // seconds
104
-
105
101
  export function buildDeltaSignableOrderData({
106
102
  owner,
107
103
  beneficiary = owner,
@@ -157,31 +153,3 @@ export function buildDeltaSignableOrderData({
157
153
  paraswapDeltaAddress,
158
154
  });
159
155
  }
160
-
161
- type ProducePartnerAndFeeInput = {
162
- partnerFeeBps: number;
163
- partnerAddress: string;
164
- partnerTakesSurplus: boolean;
165
- capSurplus: boolean;
166
- };
167
-
168
- // fee and address are encoded together
169
- function producePartnerAndFee({
170
- partnerFeeBps,
171
- partnerAddress,
172
- partnerTakesSurplus,
173
- capSurplus,
174
- }: ProducePartnerAndFeeInput): string {
175
- const capSurplusShifted = BigInt(capSurplus) << BigInt(9);
176
- if (partnerAddress === ZERO_ADDRESS) {
177
- return capSurplusShifted.toString(10);
178
- } else {
179
- const partnerAndFee =
180
- (BigInt(partnerAddress) << BigInt(96)) |
181
- BigInt(partnerFeeBps.toFixed(0)) |
182
- (BigInt(partnerTakesSurplus) << BigInt(8)) |
183
- capSurplusShifted;
184
-
185
- return partnerAndFee.toString(10);
186
- }
187
- }
@@ -0,0 +1,129 @@
1
+ import { MarkOptional } from 'ts-essentials';
2
+ import { Domain } from '../../common/orders/buildOrderData';
3
+ import { ExternalDeltaOrder } from './types';
4
+ import { DELTA_DEFAULT_EXPIRY, producePartnerAndFee } from './misc';
5
+
6
+ const EXTERNAL_ORDER_EIP_712_TYPES = {
7
+ ExternalOrder: [
8
+ { name: 'owner', type: 'address' },
9
+ { name: 'handler', type: 'address' },
10
+ { name: 'srcToken', type: 'address' },
11
+ { name: 'destToken', type: 'address' },
12
+ { name: 'srcAmount', type: 'uint256' },
13
+ { name: 'destAmount', type: 'uint256' },
14
+ { name: 'expectedAmount', type: 'uint256' },
15
+ { name: 'deadline', type: 'uint256' },
16
+ { name: 'kind', type: 'uint8' },
17
+ { name: 'nonce', type: 'uint256' },
18
+ { name: 'partnerAndFee', type: 'uint256' },
19
+ { name: 'permit', type: 'bytes' },
20
+ { name: 'metadata', type: 'bytes' },
21
+ { name: 'data', type: 'bytes' },
22
+ ],
23
+ };
24
+
25
+ export type SignableExternalOrderData = {
26
+ types: {
27
+ ExternalOrder: typeof EXTERNAL_ORDER_EIP_712_TYPES.ExternalOrder;
28
+ };
29
+ domain: Domain;
30
+ data: ExternalDeltaOrder;
31
+ };
32
+
33
+ type SignExternalOrderInput = {
34
+ orderInput: ExternalDeltaOrder;
35
+ paraswapDeltaAddress: string;
36
+ chainId: number;
37
+ };
38
+
39
+ export function produceExternalOrderTypedData({
40
+ orderInput,
41
+ chainId,
42
+ paraswapDeltaAddress,
43
+ }: SignExternalOrderInput): SignableExternalOrderData {
44
+ return {
45
+ types: {
46
+ ExternalOrder: EXTERNAL_ORDER_EIP_712_TYPES.ExternalOrder,
47
+ },
48
+ domain: {
49
+ name: 'Portikus',
50
+ version: '2.0.0',
51
+ chainId,
52
+ verifyingContract: paraswapDeltaAddress,
53
+ },
54
+ data: orderInput,
55
+ };
56
+ }
57
+
58
+ export type ExternalOrderDataInput = MarkOptional<
59
+ Omit<ExternalDeltaOrder, 'partnerAndFee'>,
60
+ 'deadline' | 'nonce' | 'permit'
61
+ >;
62
+
63
+ export type BuildExternalOrderDataInput = MarkOptional<
64
+ ExternalOrderDataInput,
65
+ 'metadata'
66
+ > & {
67
+ partnerAddress: string;
68
+ paraswapDeltaAddress: string;
69
+ partnerFeeBps: number;
70
+ partnerTakesSurplus?: boolean;
71
+ capSurplus?: boolean;
72
+ chainId: number;
73
+ };
74
+
75
+ export function buildExternalOrderSignableData({
76
+ owner,
77
+ handler,
78
+
79
+ srcToken,
80
+ destToken,
81
+ srcAmount,
82
+ destAmount,
83
+ expectedAmount,
84
+
85
+ deadline = Math.floor(Date.now() / 1000 + DELTA_DEFAULT_EXPIRY),
86
+ nonce = Date.now().toString(10),
87
+
88
+ permit = '0x',
89
+
90
+ kind,
91
+ metadata = '0x',
92
+ data,
93
+
94
+ partnerAddress,
95
+ partnerFeeBps,
96
+ partnerTakesSurplus = false,
97
+ capSurplus = true,
98
+
99
+ chainId,
100
+ paraswapDeltaAddress,
101
+ }: BuildExternalOrderDataInput): SignableExternalOrderData {
102
+ const orderInput: ExternalDeltaOrder = {
103
+ owner,
104
+ handler,
105
+ srcToken,
106
+ destToken,
107
+ srcAmount,
108
+ destAmount,
109
+ expectedAmount,
110
+ deadline,
111
+ nonce,
112
+ permit,
113
+ partnerAndFee: producePartnerAndFee({
114
+ partnerFeeBps,
115
+ partnerAddress,
116
+ partnerTakesSurplus,
117
+ capSurplus,
118
+ }),
119
+ kind,
120
+ metadata,
121
+ data,
122
+ };
123
+
124
+ return produceExternalOrderTypedData({
125
+ orderInput,
126
+ chainId,
127
+ paraswapDeltaAddress,
128
+ });
129
+ }