@velora-dex/sdk 9.5.4-dev.1 → 9.5.4

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 (87) hide show
  1. package/dist/index.d.ts +4 -18
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -1
  4. package/dist/methods/delta/getDeltaOrders.d.ts +4 -4
  5. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  6. package/dist/methods/delta/getDeltaPrice.d.ts +1 -1
  7. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  8. package/dist/methods/delta/helpers/orders.d.ts +17 -16
  9. package/dist/methods/delta/helpers/orders.d.ts.map +1 -1
  10. package/dist/methods/delta/helpers/types.d.ts +11 -50
  11. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  12. package/dist/methods/delta/postDeltaOrder.d.ts +3 -3
  13. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  14. package/dist/sdk/full.d.ts +0 -2
  15. package/dist/sdk/full.d.ts.map +1 -1
  16. package/dist/sdk/simple.d.ts +0 -10
  17. package/dist/sdk/simple.d.ts.map +1 -1
  18. package/dist/sdk.cjs.development.js +252 -1087
  19. package/dist/sdk.cjs.development.js.map +1 -1
  20. package/dist/sdk.cjs.production.min.js +1 -1
  21. package/dist/sdk.cjs.production.min.js.map +1 -1
  22. package/dist/sdk.esm.js +253 -1071
  23. package/dist/sdk.esm.js.map +1 -1
  24. package/dist/types.d.ts +0 -8
  25. package/dist/types.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/constants.js +6 -1
  28. package/src/index.js +115 -86
  29. package/src/index.ts +0 -153
  30. package/src/methods/delta/cancelDeltaOrder.ts +1 -4
  31. package/src/methods/delta/getDeltaOrders.ts +5 -6
  32. package/src/methods/delta/getDeltaPrice.ts +1 -1
  33. package/src/methods/delta/helpers/orders.ts +19 -27
  34. package/src/methods/delta/helpers/types.ts +19 -63
  35. package/src/methods/delta/postDeltaOrder.ts +4 -4
  36. package/src/methods/delta/postTWAPDeltaOrder.ts +1 -1
  37. package/src/sdk/full.ts +0 -8
  38. package/src/sdk/simple.ts +0 -56
  39. package/src/types.ts +0 -9
  40. package/dist/examples/deltaV2.d.ts +0 -2
  41. package/dist/examples/deltaV2.d.ts.map +0 -1
  42. package/dist/examples/helpers/deltaV2.d.ts +0 -5
  43. package/dist/examples/helpers/deltaV2.d.ts.map +0 -1
  44. package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts +0 -44
  45. package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts.map +0 -1
  46. package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts +0 -48
  47. package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts.map +0 -1
  48. package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts +0 -59
  49. package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts.map +0 -1
  50. package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts +0 -21
  51. package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts.map +0 -1
  52. package/dist/methods/deltaV2/getAgentsListV2.d.ts +0 -10
  53. package/dist/methods/deltaV2/getAgentsListV2.d.ts.map +0 -1
  54. package/dist/methods/deltaV2/getBridgeRoutes.d.ts +0 -20
  55. package/dist/methods/deltaV2/getBridgeRoutes.d.ts.map +0 -1
  56. package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts +0 -33
  57. package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts.map +0 -1
  58. package/dist/methods/deltaV2/getDeltaPriceV2.d.ts +0 -46
  59. package/dist/methods/deltaV2/getDeltaPriceV2.d.ts.map +0 -1
  60. package/dist/methods/deltaV2/index.d.ts +0 -59
  61. package/dist/methods/deltaV2/index.d.ts.map +0 -1
  62. package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts +0 -8
  63. package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts.map +0 -1
  64. package/dist/methods/deltaV2/postDeltaOrderV2.d.ts +0 -28
  65. package/dist/methods/deltaV2/postDeltaOrderV2.d.ts.map +0 -1
  66. package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts +0 -11
  67. package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts.map +0 -1
  68. package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts +0 -16
  69. package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts.map +0 -1
  70. package/dist/methods/deltaV2/types.d.ts +0 -163
  71. package/dist/methods/deltaV2/types.d.ts.map +0 -1
  72. package/src/examples/deltaV2.ts +0 -200
  73. package/src/examples/helpers/deltaV2.ts +0 -29
  74. package/src/methods/deltaV2/buildDeltaOrderV2.ts +0 -86
  75. package/src/methods/deltaV2/buildExternalDeltaOrderV2.ts +0 -95
  76. package/src/methods/deltaV2/buildTWAPDeltaOrderV2.ts +0 -131
  77. package/src/methods/deltaV2/cancelDeltaOrderV2.ts +0 -103
  78. package/src/methods/deltaV2/getAgentsListV2.ts +0 -34
  79. package/src/methods/deltaV2/getBridgeRoutes.ts +0 -82
  80. package/src/methods/deltaV2/getDeltaOrdersV2.ts +0 -119
  81. package/src/methods/deltaV2/getDeltaPriceV2.ts +0 -108
  82. package/src/methods/deltaV2/index.ts +0 -303
  83. package/src/methods/deltaV2/isTokenSupportedInDeltaV2.ts +0 -52
  84. package/src/methods/deltaV2/postDeltaOrderV2.ts +0 -65
  85. package/src/methods/deltaV2/postExternalDeltaOrderV2.ts +0 -45
  86. package/src/methods/deltaV2/postTWAPDeltaOrderV2.ts +0 -63
  87. package/src/methods/deltaV2/types.ts +0 -189
@@ -1,200 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import axios from 'axios';
3
- import { ethers, Wallet } from 'ethersV5';
4
- import {
5
- constructPartialSDK,
6
- constructEthersContractCaller,
7
- constructAxiosFetcher,
8
- constructAllDeltaV2OrdersHandlers,
9
- } from '..';
10
- import { startStatusCheckV2 } from './helpers/deltaV2';
11
-
12
- const fetcher = constructAxiosFetcher(axios);
13
-
14
- const provider = ethers.getDefaultProvider(1);
15
- const signer = Wallet.createRandom().connect(provider);
16
- const account = signer.address;
17
- const contractCaller = constructEthersContractCaller(
18
- {
19
- ethersProviderOrSigner: provider,
20
- EthersContract: ethers.Contract,
21
- },
22
- account
23
- );
24
-
25
- const deltaSDK = constructPartialSDK(
26
- {
27
- chainId: 1,
28
- fetcher,
29
- contractCaller,
30
- },
31
- constructAllDeltaV2OrdersHandlers
32
- );
33
-
34
- const DAI_TOKEN = '0x6b175474e89094c44da98b954eedeac495271d0f';
35
- const USDC_TOKEN = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
36
-
37
- async function simpleDeltaV2Flow() {
38
- const amount = '1000000000000'; // wei
39
-
40
- const deltaPrice = await deltaSDK.getDeltaPriceV2({
41
- srcToken: DAI_TOKEN,
42
- destToken: USDC_TOKEN,
43
- amount,
44
- userAddress: account,
45
- srcDecimals: 18,
46
- destDecimals: 6,
47
- // partner: "..." // if available
48
- });
49
-
50
- const DeltaContract = await deltaSDK.getDeltaContract();
51
-
52
- // or sign a Permit1 or Permit2 TransferFrom for DeltaContract
53
- const tx = await deltaSDK.approveTokenForDelta(amount, DAI_TOKEN);
54
- await tx.wait();
55
-
56
- const deltaAuction = await deltaSDK.submitDeltaOrderV2({
57
- route: deltaPrice.route, // or pick from deltaPrice.alternatives
58
- side: deltaPrice.side,
59
- owner: account,
60
- // beneficiary: anotherAccount, // if need to send destToken to another account
61
- // permit: "0x1234...", // if signed a Permit1 or Permit2 TransferFrom for DeltaContract
62
- slippage: 50, // 50 bps = 0.5% slippage
63
- });
64
-
65
- // poll if necessary
66
- startStatusCheckV2(() => deltaSDK.getDeltaOrderByIdV2(deltaAuction.id));
67
- }
68
-
69
- async function manualDeltaV2Flow() {
70
- const amount = '1000000000000'; // wei
71
-
72
- const deltaPrice = await deltaSDK.getDeltaPriceV2({
73
- srcToken: DAI_TOKEN,
74
- destToken: USDC_TOKEN,
75
- amount,
76
- userAddress: account,
77
- srcDecimals: 18,
78
- destDecimals: 6,
79
- // partner: "..." // if available
80
- });
81
-
82
- const DeltaContract = await deltaSDK.getDeltaContract();
83
-
84
- // or sign a Permit1 or Permit2 TransferFrom for DeltaContract
85
- const tx = await deltaSDK.approveTokenForDelta(amount, DAI_TOKEN);
86
- await tx.wait();
87
-
88
- // server-side build (returns EIP-712 typed data + orderHash)
89
- const builtOrder = await deltaSDK.buildDeltaOrderV2({
90
- route: deltaPrice.route, // or pick from deltaPrice.alternatives
91
- side: deltaPrice.side,
92
- owner: account,
93
- // beneficiary: anotherAccount, // if need to send destToken to another account
94
- // permit: "0x1234...", // if signed a Permit1 or Permit2 TransferFrom for DeltaContract
95
- slippage: 50, // 50 bps = 0.5% slippage
96
- });
97
-
98
- // one signer for every v2 order type (Order / ExternalOrder / TWAPOrder / TWAPBuyOrder)
99
- const signature = await deltaSDK.signDeltaOrderV2(builtOrder);
100
-
101
- const deltaAuction = await deltaSDK.postDeltaOrderV2({
102
- // partner: "..." // if available
103
- order: builtOrder.toSign.value as Parameters<
104
- typeof deltaSDK.postDeltaOrderV2
105
- >[0]['order'],
106
- signature,
107
- });
108
-
109
- // poll if necessary
110
- startStatusCheckV2(() => deltaSDK.getDeltaOrderByIdV2(deltaAuction.id));
111
- }
112
-
113
- // External orders forward execution to an integrator-provided handler contract.
114
- // Same build/sign/post shape as standard orders, plus { handler, data }.
115
- // See externalDelta.ts for handler-specific examples (Aave collateral swap, etc.).
116
- async function externalDeltaV2Flow() {
117
- const amount = ethers.utils.parseUnits('1', 6).toString(); // 1 USDC
118
-
119
- const deltaPrice = await deltaSDK.getDeltaPriceV2({
120
- srcToken: USDC_TOKEN,
121
- destToken: DAI_TOKEN,
122
- amount,
123
- userAddress: account,
124
- srcDecimals: 6,
125
- destDecimals: 18,
126
- });
127
-
128
- const HANDLER = '0xb4a2c36668cf8b19fe08f263e3685a5e16e82912'; // handler contract
129
- const HANDLER_DATA =
130
- '0x0000000000000000000000000000000000000000000000000000000000000000'; // handler-specific encoded bytes
131
-
132
- const builtOrder = await deltaSDK.buildExternalDeltaOrderV2({
133
- route: deltaPrice.route,
134
- side: deltaPrice.side,
135
- owner: account,
136
- handler: HANDLER,
137
- data: HANDLER_DATA,
138
- slippage: 50,
139
- });
140
-
141
- const signature = await deltaSDK.signDeltaOrderV2(builtOrder);
142
-
143
- const deltaAuction = await deltaSDK.postExternalDeltaOrderV2({
144
- order: builtOrder.toSign.value as Parameters<
145
- typeof deltaSDK.postExternalDeltaOrderV2
146
- >[0]['order'],
147
- signature,
148
- });
149
-
150
- startStatusCheckV2(() => deltaSDK.getDeltaOrderByIdV2(deltaAuction.id));
151
- }
152
-
153
- // TWAP sell splits a total srcAmount into N equal slices executed `interval` seconds apart.
154
- // The price quote is fetched for a single slice; the server multiplies amounts by numSlices.
155
- async function twapSellDeltaV2Flow() {
156
- const numSlices = 4;
157
- const totalSrcAmount = ethers.utils.parseUnits('100', 18).toString(); // 100 DAI total
158
- const perSliceAmount = (
159
- BigInt(totalSrcAmount) / BigInt(numSlices)
160
- ).toString();
161
-
162
- // quote a single slice — route amounts must match floor(totalSrcAmount / numSlices)
163
- const deltaPrice = await deltaSDK.getDeltaPriceV2({
164
- srcToken: DAI_TOKEN,
165
- destToken: USDC_TOKEN,
166
- amount: perSliceAmount,
167
- userAddress: account,
168
- srcDecimals: 18,
169
- destDecimals: 6,
170
- });
171
-
172
- const tx = await deltaSDK.approveTokenForDelta(totalSrcAmount, DAI_TOKEN);
173
- await tx.wait();
174
-
175
- const deltaAuction = await deltaSDK.submitTWAPDeltaOrderV2({
176
- onChainOrderType: 'TWAPOrder',
177
- route: deltaPrice.route,
178
- owner: account,
179
- totalSrcAmount,
180
- numSlices,
181
- interval: 300, // 5 minutes between slices (min 60)
182
- slippage: 50,
183
- });
184
-
185
- startStatusCheckV2(() => deltaSDK.getDeltaOrderByIdV2(deltaAuction.id));
186
- }
187
-
188
- // Paginated list of a user's orders (v2 returns a { results, pagination } envelope).
189
- async function listUserOrders() {
190
- const page1 = await deltaSDK.getDeltaOrdersV2({
191
- userAddress: account,
192
- page: 1,
193
- limit: 50,
194
- // status: ['ACTIVE', 'BRIDGING'],
195
- // type: 'MARKET',
196
- });
197
-
198
- console.log('orders:', page1.data);
199
- console.log('total:', page1.total, 'hasMore:', page1.hasMore);
200
- }
@@ -1,29 +0,0 @@
1
- import { DeltaOrderV2Response } from '../..';
2
-
3
- // v2 status COMPLETED already accounts for destChain bridge settlement
4
- // (crosschain orders sit in BRIDGING until the destChain leg is done).
5
- function isCompletedDeltaV2Order(order: DeltaOrderV2Response) {
6
- return order.status === 'COMPLETED';
7
- }
8
-
9
- type GetDeltaOrderV2Fn = () => Promise<DeltaOrderV2Response>;
10
-
11
- function fetchOrderPeriodically(getDeltaOrder: GetDeltaOrderV2Fn) {
12
- const intervalId = setInterval(async () => {
13
- const order = await getDeltaOrder();
14
- console.log('checks: ', order); // Handle or log the fetched order as needed
15
-
16
- if (isCompletedDeltaV2Order(order)) {
17
- clearInterval(intervalId); // Stop interval if completed
18
- console.log('Order completed');
19
- }
20
- }, 3000);
21
- console.log('Order Pending');
22
- // Return intervalId to enable clearing the interval if needed externally
23
- return intervalId;
24
- }
25
-
26
- export function startStatusCheckV2(getDeltaOrder: GetDeltaOrderV2Fn) {
27
- const intervalId = fetchOrderPeriodically(getDeltaOrder);
28
- setTimeout(() => clearInterval(intervalId), 60000 * 5); // Stop after 5 minutes
29
- }
@@ -1,86 +0,0 @@
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
- };
@@ -1,95 +0,0 @@
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
- };
@@ -1,131 +0,0 @@
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
- };
@@ -1,103 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type {
3
- ConstructProviderFetchInput,
4
- RequestParameters,
5
- } from '../../types';
6
- import { constructGetDeltaContract } from '../delta/getDeltaContract';
7
- import {
8
- buildCancelDeltaOrderSignableData,
9
- type CancelDeltaOrderData,
10
- } from '../delta/helpers/buildCancelDeltaOrderData';
11
-
12
- type SuccessResponse = { success: true };
13
-
14
- type CancelDeltaOrderRequestParams = {
15
- orderIds: string[];
16
- signature: string;
17
- };
18
-
19
- export type SignCancelDeltaOrderRequestV2 = (
20
- params: CancelDeltaOrderData,
21
- requestParams?: RequestParameters
22
- ) => Promise<string>;
23
-
24
- export type PostCancelDeltaOrderRequestV2 = (
25
- params: CancelDeltaOrderRequestParams,
26
- requestParams?: RequestParameters
27
- ) => Promise<SuccessResponse>;
28
-
29
- export type CancelDeltaOrderV2 = (
30
- params: CancelDeltaOrderData,
31
- requestParams?: RequestParameters
32
- ) => Promise<SuccessResponse>;
33
-
34
- export type CancelDeltaOrderV2Functions = {
35
- signCancelDeltaOrderRequestV2: SignCancelDeltaOrderRequestV2;
36
- postCancelDeltaOrderRequestV2: PostCancelDeltaOrderRequestV2;
37
- /** @description Cancel one or more Delta orders via the v2 endpoint */
38
- cancelDeltaOrdersV2: CancelDeltaOrderV2;
39
- };
40
-
41
- export const constructCancelDeltaOrderV2 = (
42
- options: Pick<
43
- ConstructProviderFetchInput<any, 'signTypedDataCall'>,
44
- 'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
45
- >
46
- ): CancelDeltaOrderV2Functions => {
47
- const apiURL = options.apiURL ?? API_URL;
48
-
49
- const { getDeltaContract } = constructGetDeltaContract(options);
50
-
51
- const signCancelDeltaOrderRequestV2: SignCancelDeltaOrderRequestV2 = async (
52
- params,
53
- requestParams
54
- ) => {
55
- const ParaswapDelta = await getDeltaContract(requestParams);
56
- if (!ParaswapDelta) {
57
- throw new Error(`Delta is not available on chain ${options.chainId}`);
58
- }
59
-
60
- const typedData = buildCancelDeltaOrderSignableData({
61
- orderInput: params,
62
- paraswapDeltaAddress: ParaswapDelta,
63
- chainId: options.chainId,
64
- });
65
-
66
- return options.contractCaller.signTypedDataCall(typedData);
67
- };
68
-
69
- const postCancelDeltaOrderRequestV2: PostCancelDeltaOrderRequestV2 = async (
70
- params,
71
- requestParams
72
- ) => {
73
- const cancelUrl = `${apiURL}/delta/v2/orders/cancel` as const;
74
-
75
- return options.fetcher<SuccessResponse>({
76
- url: cancelUrl,
77
- method: 'POST',
78
- data: params,
79
- requestParams,
80
- });
81
- };
82
-
83
- const cancelDeltaOrdersV2: CancelDeltaOrderV2 = async (
84
- { orderIds },
85
- requestParams
86
- ) => {
87
- const signature = await signCancelDeltaOrderRequestV2(
88
- { orderIds },
89
- requestParams
90
- );
91
-
92
- return postCancelDeltaOrderRequestV2(
93
- { orderIds, signature },
94
- requestParams
95
- );
96
- };
97
-
98
- return {
99
- signCancelDeltaOrderRequestV2,
100
- postCancelDeltaOrderRequestV2,
101
- cancelDeltaOrdersV2,
102
- };
103
- };
@@ -1,34 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
-
4
- export type AgentList = string[];
5
-
6
- type AgentsListV2Response = AgentList;
7
-
8
- type GetAgentsListV2 = (
9
- requestParams?: RequestParameters
10
- ) => Promise<AgentList>;
11
-
12
- export type GetAgentsListV2Functions = {
13
- /** @description List agents available on the current chain. */
14
- getAgentsListV2: GetAgentsListV2;
15
- };
16
-
17
- export const constructGetAgentsListV2 = ({
18
- apiURL = API_URL,
19
- chainId,
20
- fetcher,
21
- }: ConstructFetchInput): GetAgentsListV2Functions => {
22
- const baseUrl = `${apiURL}/delta/v2/agents/list/${chainId}` as const;
23
-
24
- const getAgentsListV2: GetAgentsListV2 = async (requestParams) => {
25
- const data = await fetcher<AgentsListV2Response>({
26
- url: baseUrl,
27
- method: 'GET',
28
- requestParams,
29
- });
30
- return data;
31
- };
32
-
33
- return { getAgentsListV2 };
34
- };