@velora-dex/sdk 8.1.0 → 8.1.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 (53) hide show
  1. package/dist/helpers/providers/viem.d.ts +1 -1
  2. package/dist/helpers/providers/viem.d.ts.map +1 -1
  3. package/dist/index.d.ts +3 -2
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts +1 -1
  6. package/dist/methods/delta/buildCrosschainOrderBridge.d.ts.map +1 -1
  7. package/dist/methods/delta/buildDeltaOrder.d.ts +9 -6
  8. package/dist/methods/delta/buildDeltaOrder.d.ts.map +1 -1
  9. package/dist/methods/delta/cancelDeltaOrder.d.ts +21 -0
  10. package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -0
  11. package/dist/methods/delta/getDeltaOrders.d.ts +11 -1
  12. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  13. package/dist/methods/delta/getDeltaPrice.d.ts +29 -10
  14. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  15. package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts +25 -0
  16. package/dist/methods/delta/helpers/buildCancelDeltaOrderData.d.ts.map +1 -0
  17. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts +3 -3
  18. package/dist/methods/delta/helpers/buildDeltaOrderData.d.ts.map +1 -1
  19. package/dist/methods/delta/helpers/misc.d.ts +1 -1
  20. package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
  21. package/dist/methods/delta/helpers/types.d.ts +34 -6
  22. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  23. package/dist/methods/delta/index.d.ts +7 -5
  24. package/dist/methods/delta/index.d.ts.map +1 -1
  25. package/dist/methods/delta/postDeltaOrder.d.ts +9 -1
  26. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  27. package/dist/methods/quote/getQuote.d.ts +4 -4
  28. package/dist/methods/quote/getQuote.d.ts.map +1 -1
  29. package/dist/sdk.cjs.development.js +354 -407
  30. package/dist/sdk.cjs.development.js.map +1 -1
  31. package/dist/sdk.cjs.production.min.js +1 -1
  32. package/dist/sdk.cjs.production.min.js.map +1 -1
  33. package/dist/sdk.esm.js +354 -408
  34. package/dist/sdk.esm.js.map +1 -1
  35. package/package.json +1 -1
  36. package/src/helpers/providers/viem.ts +4 -1
  37. package/src/index.ts +6 -0
  38. package/src/methods/delta/buildCrosschainOrderBridge.ts +15 -6
  39. package/src/methods/delta/buildDeltaOrder.ts +33 -65
  40. package/src/methods/delta/cancelDeltaOrder.ts +109 -0
  41. package/src/methods/delta/getDeltaOrders.ts +38 -0
  42. package/src/methods/delta/getDeltaPrice.ts +60 -15
  43. package/src/methods/delta/helpers/across.ts +1 -1
  44. package/src/methods/delta/helpers/buildCancelDeltaOrderData.ts +48 -0
  45. package/src/methods/delta/helpers/buildDeltaOrderData.ts +36 -11
  46. package/src/methods/delta/helpers/misc.ts +6 -2
  47. package/src/methods/delta/helpers/types.ts +55 -7
  48. package/src/methods/delta/index.ts +19 -4
  49. package/src/methods/delta/postDeltaOrder.ts +11 -1
  50. package/src/methods/quote/getQuote.ts +7 -10
  51. package/dist/methods/delta/helpers/composePermit.d.ts +0 -5
  52. package/dist/methods/delta/helpers/composePermit.d.ts.map +0 -1
  53. package/src/methods/delta/helpers/composePermit.ts +0 -76
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@velora-dex/sdk",
3
- "version": "8.1.0",
3
+ "version": "8.1.1-dev.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/sdk.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -23,7 +23,10 @@ import { TransactionParams } from '../../methods/swap/transaction';
23
23
 
24
24
  export type MinViemClient = Partial<
25
25
  Pick<PublicActions<Transport, Chain>, 'readContract'> &
26
- Pick<WalletActions<Chain>, 'writeContract' | 'signTypedData'>
26
+ Pick<
27
+ WalletActions<Chain>,
28
+ 'writeContract' | 'signTypedData' | 'signMessage'
29
+ >
27
30
  > & { account?: Account };
28
31
 
29
32
  export const constructContractCaller = (
package/src/index.ts CHANGED
@@ -206,6 +206,10 @@ import {
206
206
  QuoteWithMarketPrice,
207
207
  QuoteWithMarketPriceAsFallback,
208
208
  } from './methods/quote/getQuote';
209
+ import {
210
+ CancelDeltaOrderFunctions,
211
+ constructCancelDeltaOrder,
212
+ } from './methods/delta/cancelDeltaOrder';
209
213
 
210
214
  export { constructSwapSDK, SwapSDKMethods } from './methods/swap';
211
215
 
@@ -289,6 +293,7 @@ export {
289
293
  constructGetDeltaContract,
290
294
  constructGetDeltaPrice,
291
295
  constructGetDeltaOrders,
296
+ constructCancelDeltaOrder,
292
297
  constructApproveTokenForDelta,
293
298
  // Quote methods
294
299
  constructGetQuote,
@@ -378,6 +383,7 @@ export type {
378
383
  GetDeltaPriceFunctions,
379
384
  GetDeltaOrdersFunctions,
380
385
  ApproveTokenForDeltaFunctions,
386
+ CancelDeltaOrderFunctions,
381
387
  // types for Quote methods
382
388
  GetQuoteFunctions,
383
389
  QuoteParams,
@@ -1,9 +1,9 @@
1
1
  import { assert } from 'ts-essentials';
2
2
  import type { ConstructFetchInput, RequestParameters } from '../../types';
3
3
  import { BridgePrice } from './getDeltaPrice';
4
- import { constructGetMulticallHandlers } from './getMulticallHandlers';
4
+ // import { constructGetMulticallHandlers } from './getMulticallHandlers';
5
5
  import {
6
- getDeltaBridge,
6
+ // getDeltaBridge,
7
7
  GetDeltaBridgeAndDestTokenOutput,
8
8
  } from './helpers/across';
9
9
  import { BeneficiaryType } from '../common/orders/types';
@@ -18,7 +18,7 @@ export type BuildCrosschainOrderBridgeParams = {
18
18
  beneficiaryType: BeneficiaryType;
19
19
 
20
20
  /** @description price response received from /delta/prices (getDeltaPrice method) */
21
- deltaPrice: Pick<BridgePrice, 'bridgeFee' | 'bridge'>;
21
+ deltaPrice: BridgePrice;
22
22
  };
23
23
 
24
24
  type BuildCrosschainOrderBridge = (
@@ -39,7 +39,7 @@ export const constructBuildCrosschainOrderBridge = (
39
39
  const { chainId } = options;
40
40
 
41
41
  // cached internally for `multicall` contracts
42
- const { getMulticallHandlers } = constructGetMulticallHandlers(options);
42
+ // const { getMulticallHandlers } = constructGetMulticallHandlers(options);
43
43
 
44
44
  const buildCrosschainOrderBridge: BuildCrosschainOrderBridge = async (
45
45
  { destToken, destChainId, beneficiaryType, deltaPrice },
@@ -55,7 +55,7 @@ export const constructBuildCrosschainOrderBridge = (
55
55
  '`destChainId` must match `deltaPrice.bridge.destinationChainId` for crosschain Order.bridge'
56
56
  );
57
57
 
58
- const getMulticallHandler = async (chainId: number) => {
58
+ /* const getMulticallHandler = async (chainId: number) => {
59
59
  const multicallHandlersMap = await getMulticallHandlers(requestParams);
60
60
  const multicallHandler = multicallHandlersMap[chainId];
61
61
 
@@ -74,7 +74,16 @@ export const constructBuildCrosschainOrderBridge = (
74
74
  bridgeOutputToken: deltaPrice.bridge.outputToken,
75
75
  beneficiaryType,
76
76
  getMulticallHandler,
77
- });
77
+ }); */
78
+
79
+ // @TODO remove the whole buildCrosschainOrderBridge() when API provides BridgePrice.bridge = whole Bridge object
80
+ const bridge = {
81
+ protocolSelector: '0x00000000',
82
+ scalingFactor: 0,
83
+ protocolData: '0x',
84
+ destinationChainId: deltaPrice.bridge.destinationChainId,
85
+ outputToken: deltaPrice.bridge.outputToken,
86
+ };
78
87
 
79
88
  return {
80
89
  bridge,
@@ -1,19 +1,23 @@
1
- import { assert } from 'ts-essentials';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
- import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
1
+ import type {
2
+ ConstructFetchInput,
3
+ EnumerateLiteral,
4
+ RequestParameters,
5
+ } from '../../types';
4
6
  import { constructGetDeltaContract } from './getDeltaContract';
5
- import { BridgePrice, DeltaPrice } from './getDeltaPrice';
7
+ import { BridgePrice } from './getDeltaPrice';
6
8
  import { constructGetPartnerFee } from './getPartnerFee';
7
9
  import {
8
10
  buildDeltaSignableOrderData,
9
11
  type BuildDeltaOrderDataInput,
10
12
  type SignableDeltaOrderData,
11
13
  } from './helpers/buildDeltaOrderData';
12
- import { Bridge } from './helpers/types';
13
- import { constructBuildCrosschainOrderBridge } from './buildCrosschainOrderBridge';
14
+ import { SwapSideToOrderKind } from './helpers/types';
14
15
  import { BeneficiaryType } from '../common/orders/types';
16
+ import { SwapSide } from '../../constants';
15
17
  export type { SignableDeltaOrderData } from './helpers/buildDeltaOrderData';
16
18
 
19
+ type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
20
+
17
21
  export type BuildDeltaOrderDataParams = {
18
22
  /** @description The address of the order owner */
19
23
  owner: string;
@@ -36,8 +40,6 @@ export type BuildDeltaOrderDataParams = {
36
40
  /** @description Partner string. */
37
41
  partner?: string;
38
42
 
39
- /** @description The bridge input */
40
- bridge?: Bridge;
41
43
  /** @description Destination Chain ID for Crosschain Orders */
42
44
  destChainId?: number;
43
45
  /** @description Whether the beneficiary is a contract. Needed to automatically fill in crosschain Bridge */
@@ -45,10 +47,14 @@ export type BuildDeltaOrderDataParams = {
45
47
 
46
48
  /** @description price response received from /delta/prices (getDeltaPrice method) */
47
49
  deltaPrice: Pick<
48
- DeltaPrice,
49
- 'destAmount' | 'partner' | 'partnerFee' | 'destToken'
50
- > &
51
- Partial<Pick<BridgePrice, 'bridgeFee' | 'bridge'>>;
50
+ BridgePrice,
51
+ | 'destAmount'
52
+ | 'partner'
53
+ | 'partnerFee'
54
+ | 'destToken'
55
+ | 'srcAmount'
56
+ | 'bridge'
57
+ >;
52
58
 
53
59
  /** @description partner fee in basis points (bps), 50bps=0.5% */
54
60
  partnerFeeBps?: number;
@@ -56,6 +62,11 @@ export type BuildDeltaOrderDataParams = {
56
62
  partnerAddress?: string;
57
63
  /** @description take surplus */
58
64
  partnerTakesSurplus?: boolean;
65
+
66
+ /** @description The side of the order. Default is SELL */
67
+ side?: SwapSideUnion;
68
+ /** @description Metadata for the order, hex string */
69
+ metadata?: string;
59
70
  };
60
71
 
61
72
  type BuildDeltaOrder = (
@@ -68,14 +79,6 @@ export type BuildDeltaOrderFunctions = {
68
79
  buildDeltaOrder: BuildDeltaOrder;
69
80
  };
70
81
 
71
- // for same-chain Orders, all 0 params
72
- const DEFAULT_BRIDGE: Bridge = {
73
- maxRelayerFee: '0',
74
- destinationChainId: 0,
75
- outputToken: ZERO_ADDRESS,
76
- multiCallHandler: ZERO_ADDRESS,
77
- };
78
-
79
82
  export const constructBuildDeltaOrder = (
80
83
  options: ConstructFetchInput
81
84
  ): BuildDeltaOrderFunctions => {
@@ -86,9 +89,6 @@ export const constructBuildDeltaOrder = (
86
89
  // cached internally for `partner`
87
90
  const { getPartnerFee } = constructGetPartnerFee(options);
88
91
 
89
- const { buildCrosschainOrderBridge } =
90
- constructBuildCrosschainOrderBridge(options);
91
-
92
92
  const buildDeltaOrder: BuildDeltaOrder = async (options, requestParams) => {
93
93
  const ParaswapDelta = await getDeltaContract(requestParams);
94
94
  if (!ParaswapDelta) {
@@ -121,46 +121,12 @@ export const constructBuildDeltaOrder = (
121
121
  partnerTakesSurplus ?? partnerFeeResponse.takeSurplus;
122
122
  }
123
123
 
124
- ////// Bridge logic //////
125
-
126
- // Bridge is necessary for Crosschain Delta Orders
127
- let bridge = options.bridge;
128
-
129
- // give preference to user-provided bridge
130
- if (!bridge) {
131
- // no bridge passed in input
132
-
133
- if (options.destChainId && chainId !== options.destChainId) {
134
- // crosschain Delta Order
135
- const deltaPrice = options.deltaPrice;
136
- assert(
137
- deltaPrice.bridgeFee,
138
- '`bridgeFee` is required in `deltaPrice` for crosschain Delta Orders'
139
- );
140
- assert(
141
- deltaPrice.bridge,
142
- '`bridge` is required in `deltaPrice` for crosschain Delta Orders'
143
- );
144
-
145
- const { bridge: constructedBridge } = await buildCrosschainOrderBridge(
146
- {
147
- destToken: options.destToken,
148
- destChainId: options.destChainId,
149
- beneficiaryType: options.beneficiaryType ?? 'EOA',
150
- deltaPrice: {
151
- bridgeFee: deltaPrice.bridgeFee,
152
- bridge: deltaPrice.bridge, // already contains destChainId and outputToken
153
- },
154
- },
155
- requestParams
156
- );
157
-
158
- bridge = constructedBridge;
159
- } else {
160
- // 0-values bridge for same-chain Orders
161
- bridge = DEFAULT_BRIDGE;
162
- }
163
- }
124
+ const swapSide = options.side ?? SwapSide.SELL;
125
+
126
+ const expectedAmount =
127
+ swapSide === SwapSide.SELL
128
+ ? options.deltaPrice.destAmount
129
+ : options.deltaPrice.srcAmount;
164
130
 
165
131
  const input: BuildDeltaOrderDataInput = {
166
132
  owner: options.owner,
@@ -171,10 +137,12 @@ export const constructBuildDeltaOrder = (
171
137
  destToken: options.deltaPrice.destToken,
172
138
  srcAmount: options.srcAmount,
173
139
  destAmount: options.destAmount,
174
- expectedDestAmount: options.deltaPrice.destAmount,
140
+ expectedAmount,
175
141
  deadline: options.deadline,
176
142
  nonce: options.nonce?.toString(10),
177
143
  permit: options.permit,
144
+ kind: SwapSideToOrderKind[swapSide],
145
+ metadata: options.metadata,
178
146
 
179
147
  chainId,
180
148
  paraswapDeltaAddress: ParaswapDelta,
@@ -182,7 +150,7 @@ export const constructBuildDeltaOrder = (
182
150
  partnerTakesSurplus,
183
151
  partnerFeeBps,
184
152
 
185
- bridge,
153
+ bridge: options.deltaPrice.bridge, // ZERO_BRIDGE for same-chain Orders
186
154
  };
187
155
 
188
156
  return buildDeltaSignableOrderData(input);
@@ -0,0 +1,109 @@
1
+ import type {
2
+ ConstructProviderFetchInput,
3
+ RequestParameters,
4
+ } from '../../types';
5
+ import {
6
+ buildCancelDeltaOrderSignableData,
7
+ CancelDeltaOrderData,
8
+ } from './helpers/buildCancelDeltaOrderData';
9
+ import { constructGetDeltaContract } from '../..';
10
+
11
+ type SuccessResponse = { success: true };
12
+
13
+ type CancelDeltaOrderRequestParams = {
14
+ orderIds: string[];
15
+ signature: string;
16
+ };
17
+
18
+ export type SignCancelDeltaOrderRequest = (
19
+ params: CancelDeltaOrderData,
20
+ requestParams?: RequestParameters
21
+ ) => Promise<string>;
22
+
23
+ export type PostCancelDeltaOrderRequest = (
24
+ params: CancelDeltaOrderRequestParams,
25
+ requestParams?: RequestParameters
26
+ ) => Promise<SuccessResponse>;
27
+
28
+ export type CancelDeltaOrder = (
29
+ params: CancelDeltaOrderData,
30
+ requestParams?: RequestParameters
31
+ ) => Promise<SuccessResponse>;
32
+
33
+ export type CancelDeltaOrderFunctions = {
34
+ signCancelLimitDeltaOrderRequest: SignCancelDeltaOrderRequest;
35
+ postCancelLimitDeltaOrderRequest: PostCancelDeltaOrderRequest;
36
+ /** @description Cancel a Limit Delta order */
37
+ cancelLimitDeltaOrders: CancelDeltaOrder;
38
+ };
39
+
40
+ export const constructCancelDeltaOrder = (
41
+ options: Pick<
42
+ ConstructProviderFetchInput<any, 'signTypedDataCall'>,
43
+ 'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
44
+ >
45
+ ): CancelDeltaOrderFunctions => {
46
+ // cached internally
47
+ const { getDeltaContract } = constructGetDeltaContract(options);
48
+
49
+ const signCancelLimitDeltaOrderRequest: SignCancelDeltaOrderRequest = async (
50
+ params,
51
+ requestParams
52
+ ) => {
53
+ const ParaswapDelta = await getDeltaContract(requestParams);
54
+ if (!ParaswapDelta) {
55
+ throw new Error(`Delta is not available on chain ${options.chainId}`);
56
+ }
57
+
58
+ const typedData = buildCancelDeltaOrderSignableData({
59
+ orderInput: params,
60
+ paraswapDeltaAddress: ParaswapDelta,
61
+ chainId: options.chainId,
62
+ });
63
+ const signature = await options.contractCaller.signTypedDataCall(typedData);
64
+
65
+ return signature;
66
+ };
67
+
68
+ const postCancelLimitDeltaOrderRequest: PostCancelDeltaOrderRequest = async (
69
+ params,
70
+ requestParams
71
+ ) => {
72
+ const cancelUrl = `${options.apiURL}/delta/orders/cancel` as const;
73
+
74
+ const res = await options.fetcher<SuccessResponse>({
75
+ url: cancelUrl,
76
+ method: 'POST',
77
+ data: params,
78
+ requestParams,
79
+ });
80
+
81
+ return res;
82
+ };
83
+
84
+ const cancelLimitDeltaOrders: CancelDeltaOrder = async (
85
+ { orderIds },
86
+ requestParams
87
+ ) => {
88
+ const signature = await signCancelLimitDeltaOrderRequest(
89
+ { orderIds },
90
+ requestParams
91
+ );
92
+
93
+ const res = await postCancelLimitDeltaOrderRequest(
94
+ {
95
+ orderIds,
96
+ signature,
97
+ },
98
+ requestParams
99
+ );
100
+
101
+ return res;
102
+ };
103
+
104
+ return {
105
+ signCancelLimitDeltaOrderRequest,
106
+ postCancelLimitDeltaOrderRequest,
107
+ cancelLimitDeltaOrders,
108
+ };
109
+ };
@@ -26,6 +26,10 @@ type OrdersFilter = {
26
26
  page?: number;
27
27
  /** @description Pagination option, limit. Default 100 */
28
28
  limit?: number;
29
+ /** @description Filter by chainId, without this filter, orders from all chains are returned */
30
+ chainId?: number; // @TODO currently not working
31
+ /** @description Filter by type. MARKET, LIMIT, or ALL. Default is ALL */
32
+ type?: 'MARKET' | 'LIMIT' | 'ALL';
29
33
  };
30
34
  type OrderFiltersQuery = OrdersFilter;
31
35
 
@@ -34,15 +38,27 @@ type GetDeltaOrders = (
34
38
  requestParams?: RequestParameters
35
39
  ) => Promise<OrderFromAPI[]>;
36
40
 
41
+ type GetRequiredBalanceParams = {
42
+ userAddress: Address;
43
+ tokenAddress?: Address;
44
+ };
45
+
46
+ type GetRequiredBalance = (
47
+ userParams: GetRequiredBalanceParams,
48
+ requestParams?: RequestParameters
49
+ ) => Promise<Record<string, string>>; // token -> balance in Limit Orders
50
+
37
51
  export type GetDeltaOrdersFunctions = {
38
52
  getDeltaOrderById: GetDeltaOrderById;
39
53
  getDeltaOrderByHash: GetDeltaOrderByHash;
40
54
  getDeltaOrders: GetDeltaOrders;
55
+ getRequiredBalanceForDeltaLimitOrders: GetRequiredBalance;
41
56
  };
42
57
 
43
58
  export const constructGetDeltaOrders = ({
44
59
  apiURL = API_URL,
45
60
  fetcher,
61
+ chainId,
46
62
  }: ConstructFetchInput): GetDeltaOrdersFunctions => {
47
63
  const baseUrl = `${apiURL}/delta/orders` as const;
48
64
 
@@ -81,6 +97,8 @@ export const constructGetDeltaOrders = ({
81
97
  userAddress: options.userAddress,
82
98
  page: options.page,
83
99
  limit: options.limit,
100
+ chainId: options.chainId,
101
+ type: options.type,
84
102
  });
85
103
 
86
104
  const fetchURL = `${baseUrl}${search}` as const;
@@ -94,9 +112,29 @@ export const constructGetDeltaOrders = ({
94
112
  return orders;
95
113
  };
96
114
 
115
+ const getRequiredBalanceForDeltaLimitOrders: GetRequiredBalance = async (
116
+ userParams,
117
+ requestParams
118
+ ) => {
119
+ const userURL =
120
+ `${baseUrl}/fillablebalance/${chainId}/${userParams.userAddress}` as const;
121
+ const fetchURL = userParams.tokenAddress
122
+ ? (`${userURL}/${userParams.tokenAddress}` as const)
123
+ : userURL;
124
+
125
+ const response = await fetcher<Record<string, string>>({
126
+ url: fetchURL,
127
+ method: 'GET',
128
+ requestParams,
129
+ });
130
+
131
+ return response;
132
+ };
133
+
97
134
  return {
98
135
  getDeltaOrderById,
99
136
  getDeltaOrderByHash,
100
137
  getDeltaOrders,
138
+ getRequiredBalanceForDeltaLimitOrders,
101
139
  };
102
140
  };
@@ -1,7 +1,15 @@
1
1
  import { Bridge } from '../..';
2
2
  import { API_URL, SwapSide } from '../../constants';
3
3
  import { constructSearchString } from '../../helpers/misc';
4
- import type { ConstructFetchInput, RequestParameters } from '../../types';
4
+ import type {
5
+ ConstructFetchInput,
6
+ EnumerateLiteral,
7
+ RequestParameters,
8
+ } from '../../types';
9
+ import { ZERO_ADDRESS } from '../common/orders/buildOrderData';
10
+ import { BridgePriceInfo } from './helpers/types';
11
+
12
+ type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
5
13
 
6
14
  export type DeltaPriceParams = {
7
15
  /** @description Source Token Address. Not Native Token */
@@ -14,45 +22,72 @@ export type DeltaPriceParams = {
14
22
  srcDecimals: number;
15
23
  /** @description Destination Token Decimals */
16
24
  destDecimals: number;
17
- // side?: SwapSide; // no BUY side for now
18
25
  /** @description User's Wallet Address */
19
26
  userAddress?: string;
27
+ /** @description Beneficiary Address */
28
+ beneficiary?: string; // beneficiary==owner if no transferTo
20
29
  /** @description Partner string. */
21
30
  partner?: string;
22
31
  /** @description Destination Chain ID for Crosschain Orders */
23
32
  destChainId?: number;
33
+ /** @description SELL or BUY, default is SELL */
34
+ side?: SwapSideUnion;
35
+
36
+ includeAgents?: string[];
37
+ excludeAgents?: string[];
24
38
  };
25
39
 
26
- type DeltaPriceQueryOptions = DeltaPriceParams & {
40
+ type DeltaPriceQueryOptions = Omit<
41
+ DeltaPriceParams,
42
+ 'includeAgents' | 'excludeAgents'
43
+ > & {
27
44
  chainId: number; // will return error from API on unsupported chains
28
- side: SwapSide.SELL;
45
+ includeAgents?: string;
46
+ excludeAgents?: string;
29
47
  };
30
48
 
49
+ // for same-chain Orders, all 0 params
50
+ export const DEFAULT_BRIDGE = {
51
+ protocolSelector: '0x00000000', // 4 bytes
52
+ destinationChainId: 0,
53
+ outputToken: ZERO_ADDRESS,
54
+ scalingFactor: 0,
55
+ protocolData: '0x',
56
+ } as const satisfies Bridge;
57
+
31
58
  export type DeltaPrice = {
32
59
  srcToken: string;
33
60
  destToken: string;
34
61
  srcAmount: string;
62
+ /** @description Available for BUY side */
63
+ srcAmountBeforeFee?: string;
35
64
  destAmount: string;
36
- destAmountBeforeFee: string;
65
+ /** @description Available for SELL side */
66
+ destAmountBeforeFee?: string;
37
67
  gasCost: string;
38
68
  gasCostBeforeFee: string;
39
69
  gasCostUSD: string;
40
70
  gasCostUSDBeforeFee: string;
41
71
  srcUSD: string;
72
+ /** @description Available for BUY side */
73
+ srcUSDBeforeFee?: string;
42
74
  destUSD: string;
43
- destUSDBeforeFee: string;
75
+ /** @description Available for SELL side */
76
+ destUSDBeforeFee?: string;
44
77
  partner: string;
45
78
  partnerFee: number; // in %
46
79
  hmac: string;
80
+ bridge: Bridge; // for single-chain DeltaPrice, it's DEFAULT_BRIDGE
47
81
  };
48
82
 
49
- export type BridgePrice = DeltaPrice & {
50
- destAmountAfterBridge: string;
51
- destUSDAfterBridge: string;
52
- bridgeFee: string;
53
- bridgeFeeUSD: string;
54
- poolAddress: string;
55
- bridge: Pick<Bridge, 'destinationChainId' | 'outputToken'>;
83
+ export type BridgePrice = Omit<DeltaPrice, 'bridge'> & {
84
+ // destAmountAfterBridge: string; // became bridgeInfo.destAmountAfterBridge
85
+ // destUSDAfterBridge: string; // became bridgeInfo.destUSDAfterBridge
86
+ // bridgeFee: string; // became bridgeInfo.fees[0].amount
87
+ // bridgeFeeUSD: string; // became bridgeInfo.fees[0].amountInUSD
88
+ // poolAddress: string;
89
+ bridge: Bridge;
90
+ bridgeInfo: BridgePriceInfo;
56
91
  };
57
92
 
58
93
  type DeltaPriceResponse = {
@@ -101,10 +136,20 @@ export const constructGetDeltaPrice = ({
101
136
  options: DeltaPriceParams,
102
137
  requestParams?: RequestParameters
103
138
  ): Promise<DeltaPrice | BridgePrice> {
139
+ const { includeAgents, excludeAgents, ...rest } = options;
140
+ const includeAgentsString = includeAgents
141
+ ? includeAgents.join(',')
142
+ : undefined;
143
+ const excludeAgentsString = excludeAgents
144
+ ? excludeAgents.join(',')
145
+ : undefined;
146
+
104
147
  const search = constructSearchString<DeltaPriceQueryOptions>({
105
- ...options,
148
+ ...rest,
106
149
  chainId,
107
- side: SwapSide.SELL, // so far SELL side only
150
+ side: options.side ?? SwapSide.SELL,
151
+ includeAgents: includeAgentsString,
152
+ excludeAgents: excludeAgentsString,
108
153
  });
109
154
 
110
155
  const fetchURL = `${pricesUrl}/${search}` as const;
@@ -181,7 +181,7 @@ export async function getDeltaBridge({
181
181
  destinationChainId: destChainId,
182
182
  outputToken,
183
183
  multiCallHandler,
184
- };
184
+ } as any; // @TODO remove the whole getDeltaBridge() when API provides BridgePrice.bridge = whole Bridge object
185
185
 
186
186
  return {
187
187
  bridge,
@@ -0,0 +1,48 @@
1
+ import { Domain } from '../../common/orders/buildOrderData';
2
+
3
+ const ORDER_CANCELLATIONS_EIP_712_TYPES = {
4
+ OrderCancellations: [{ name: 'orderIds', type: 'string[]' }],
5
+ };
6
+
7
+ export type CancelDeltaOrderData = {
8
+ orderIds: string[];
9
+ };
10
+
11
+ export type SignableCancelDeltaOrderData = {
12
+ types: {
13
+ OrderCancellations: (typeof ORDER_CANCELLATIONS_EIP_712_TYPES)['OrderCancellations'];
14
+ };
15
+ domain: Domain;
16
+ data: CancelDeltaOrderData;
17
+ };
18
+
19
+ type BuildCancelDeltaOrderInput = {
20
+ orderInput: CancelDeltaOrderData;
21
+ paraswapDeltaAddress: string;
22
+ chainId: number;
23
+ };
24
+
25
+ export function buildCancelDeltaOrderSignableData({
26
+ orderInput,
27
+ chainId,
28
+ paraswapDeltaAddress,
29
+ }: BuildCancelDeltaOrderInput): SignableCancelDeltaOrderData {
30
+ const typedData = {
31
+ types: {
32
+ OrderCancellations: ORDER_CANCELLATIONS_EIP_712_TYPES.OrderCancellations,
33
+ },
34
+ domain: {
35
+ name: 'Portikus',
36
+ version: '2.0.0',
37
+ chainId,
38
+ verifyingContract: paraswapDeltaAddress,
39
+ },
40
+ data: {
41
+ // explicityly pick only the necessary fields,
42
+ // otherwise signing will break if more is present
43
+ orderIds: orderInput.orderIds,
44
+ },
45
+ };
46
+
47
+ return typedData;
48
+ }