@velora-dex/sdk 9.5.4-dev.2 → 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 (93) hide show
  1. package/README.md +0 -156
  2. package/dist/examples/helpers/delta.d.ts +1 -1
  3. package/dist/examples/helpers/delta.d.ts.map +1 -1
  4. package/dist/index.d.ts +3 -4
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -1
  7. package/dist/methods/delta/getDeltaOrders.d.ts +4 -4
  8. package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
  9. package/dist/methods/delta/getDeltaPrice.d.ts +1 -1
  10. package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
  11. package/dist/methods/delta/helpers/orders.d.ts +17 -16
  12. package/dist/methods/delta/helpers/orders.d.ts.map +1 -1
  13. package/dist/methods/delta/helpers/types.d.ts +11 -56
  14. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  15. package/dist/methods/delta/postDeltaOrder.d.ts +3 -3
  16. package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
  17. package/dist/sdk/full.d.ts +0 -2
  18. package/dist/sdk/full.d.ts.map +1 -1
  19. package/dist/sdk/simple.d.ts +0 -4
  20. package/dist/sdk/simple.d.ts.map +1 -1
  21. package/dist/sdk.cjs.development.js +402 -1539
  22. package/dist/sdk.cjs.development.js.map +1 -1
  23. package/dist/sdk.cjs.production.min.js +1 -1
  24. package/dist/sdk.cjs.production.min.js.map +1 -1
  25. package/dist/sdk.esm.js +387 -1523
  26. package/dist/sdk.esm.js.map +1 -1
  27. package/dist/types.d.ts +0 -8
  28. package/dist/types.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/examples/helpers/delta.ts +1 -6
  31. package/src/index.js +0 -55
  32. package/src/index.ts +0 -37
  33. package/src/methods/delta/cancelDeltaOrder.ts +1 -4
  34. package/src/methods/delta/getDeltaOrders.ts +5 -6
  35. package/src/methods/delta/getDeltaPrice.ts +1 -1
  36. package/src/methods/delta/helpers/orders.ts +20 -32
  37. package/src/methods/delta/helpers/types.ts +15 -60
  38. package/src/methods/delta/postDeltaOrder.ts +4 -4
  39. package/src/methods/delta/postTWAPDeltaOrder.ts +1 -1
  40. package/src/sdk/full.ts +0 -8
  41. package/src/sdk/simple.ts +0 -30
  42. package/src/types.ts +0 -9
  43. package/dist/examples/deltaV2.d.ts +0 -2
  44. package/dist/examples/deltaV2.d.ts.map +0 -1
  45. package/dist/examples/helpers/deltaV2.d.ts +0 -5
  46. package/dist/examples/helpers/deltaV2.d.ts.map +0 -1
  47. package/dist/methods/deltaV2/buildDeltaOrder.d.ts +0 -45
  48. package/dist/methods/deltaV2/buildDeltaOrder.d.ts.map +0 -1
  49. package/dist/methods/deltaV2/buildExternalDeltaOrder.d.ts +0 -49
  50. package/dist/methods/deltaV2/buildExternalDeltaOrder.d.ts.map +0 -1
  51. package/dist/methods/deltaV2/buildTWAPDeltaOrder.d.ts +0 -60
  52. package/dist/methods/deltaV2/buildTWAPDeltaOrder.d.ts.map +0 -1
  53. package/dist/methods/deltaV2/cancelDeltaOrder.d.ts +0 -21
  54. package/dist/methods/deltaV2/cancelDeltaOrder.d.ts.map +0 -1
  55. package/dist/methods/deltaV2/getAgentsList.d.ts +0 -10
  56. package/dist/methods/deltaV2/getAgentsList.d.ts.map +0 -1
  57. package/dist/methods/deltaV2/getBridgeRoutes.d.ts +0 -20
  58. package/dist/methods/deltaV2/getBridgeRoutes.d.ts.map +0 -1
  59. package/dist/methods/deltaV2/getDeltaOrders.d.ts +0 -40
  60. package/dist/methods/deltaV2/getDeltaOrders.d.ts.map +0 -1
  61. package/dist/methods/deltaV2/getDeltaPrice.d.ts +0 -46
  62. package/dist/methods/deltaV2/getDeltaPrice.d.ts.map +0 -1
  63. package/dist/methods/deltaV2/helpers/orders.d.ts +0 -191
  64. package/dist/methods/deltaV2/helpers/orders.d.ts.map +0 -1
  65. package/dist/methods/deltaV2/index.d.ts +0 -72
  66. package/dist/methods/deltaV2/index.d.ts.map +0 -1
  67. package/dist/methods/deltaV2/isTokenSupportedInDelta.d.ts +0 -8
  68. package/dist/methods/deltaV2/isTokenSupportedInDelta.d.ts.map +0 -1
  69. package/dist/methods/deltaV2/postDeltaOrder.d.ts +0 -29
  70. package/dist/methods/deltaV2/postDeltaOrder.d.ts.map +0 -1
  71. package/dist/methods/deltaV2/postExternalDeltaOrder.d.ts +0 -11
  72. package/dist/methods/deltaV2/postExternalDeltaOrder.d.ts.map +0 -1
  73. package/dist/methods/deltaV2/postTWAPDeltaOrder.d.ts +0 -17
  74. package/dist/methods/deltaV2/postTWAPDeltaOrder.d.ts.map +0 -1
  75. package/dist/methods/deltaV2/types.d.ts +0 -169
  76. package/dist/methods/deltaV2/types.d.ts.map +0 -1
  77. package/src/examples/deltaV2.ts +0 -196
  78. package/src/examples/helpers/deltaV2.ts +0 -34
  79. package/src/methods/deltaV2/buildDeltaOrder.ts +0 -86
  80. package/src/methods/deltaV2/buildExternalDeltaOrder.ts +0 -95
  81. package/src/methods/deltaV2/buildTWAPDeltaOrder.ts +0 -131
  82. package/src/methods/deltaV2/cancelDeltaOrder.ts +0 -100
  83. package/src/methods/deltaV2/getAgentsList.ts +0 -32
  84. package/src/methods/deltaV2/getBridgeRoutes.ts +0 -82
  85. package/src/methods/deltaV2/getDeltaOrders.ts +0 -149
  86. package/src/methods/deltaV2/getDeltaPrice.ts +0 -108
  87. package/src/methods/deltaV2/helpers/orders.ts +0 -363
  88. package/src/methods/deltaV2/index.ts +0 -312
  89. package/src/methods/deltaV2/isTokenSupportedInDelta.ts +0 -52
  90. package/src/methods/deltaV2/postDeltaOrder.ts +0 -62
  91. package/src/methods/deltaV2/postExternalDeltaOrder.ts +0 -45
  92. package/src/methods/deltaV2/postTWAPDeltaOrder.ts +0 -58
  93. package/src/methods/deltaV2/types.ts +0 -202
@@ -1,196 +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
- DeltaV2,
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
- DeltaV2.constructAllDeltaOrdersHandlers
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.getDeltaPrice({
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.submitDeltaOrder({
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.getDeltaOrderById(deltaAuction.id));
67
- }
68
-
69
- async function manualDeltaV2Flow() {
70
- const amount = '1000000000000'; // wei
71
-
72
- const deltaPrice = await deltaSDK.getDeltaPrice({
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.buildDeltaOrder({
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.signDeltaOrder(builtOrder);
100
-
101
- const deltaAuction = await deltaSDK.postDeltaOrder({
102
- // partner: "..." // if available
103
- order: builtOrder.toSign.value,
104
- signature,
105
- });
106
-
107
- // poll if necessary
108
- startStatusCheckV2(() => deltaSDK.getDeltaOrderById(deltaAuction.id));
109
- }
110
-
111
- // External orders forward execution to an integrator-provided handler contract.
112
- // Same build/sign/post shape as standard orders, plus { handler, data }.
113
- // See externalDelta.ts for handler-specific examples (Aave collateral swap, etc.).
114
- async function externalDeltaV2Flow() {
115
- const amount = ethers.utils.parseUnits('1', 6).toString(); // 1 USDC
116
-
117
- const deltaPrice = await deltaSDK.getDeltaPrice({
118
- srcToken: USDC_TOKEN,
119
- destToken: DAI_TOKEN,
120
- amount,
121
- userAddress: account,
122
- srcDecimals: 6,
123
- destDecimals: 18,
124
- });
125
-
126
- const HANDLER = '0xb4a2c36668cf8b19fe08f263e3685a5e16e82912'; // handler contract
127
- const HANDLER_DATA =
128
- '0x0000000000000000000000000000000000000000000000000000000000000000'; // handler-specific encoded bytes
129
-
130
- const builtOrder = await deltaSDK.buildExternalDeltaOrder({
131
- route: deltaPrice.route,
132
- side: deltaPrice.side,
133
- owner: account,
134
- handler: HANDLER,
135
- data: HANDLER_DATA,
136
- slippage: 50,
137
- });
138
-
139
- const signature = await deltaSDK.signDeltaOrder(builtOrder);
140
-
141
- const deltaAuction = await deltaSDK.postExternalDeltaOrder({
142
- order: builtOrder.toSign.value,
143
- signature,
144
- });
145
-
146
- startStatusCheckV2(() => deltaSDK.getDeltaOrderById(deltaAuction.id));
147
- }
148
-
149
- // TWAP sell splits a total srcAmount into N equal slices executed `interval` seconds apart.
150
- // The price quote is fetched for a single slice; the server multiplies amounts by numSlices.
151
- async function twapSellDeltaV2Flow() {
152
- const numSlices = 4;
153
- const totalSrcAmount = ethers.utils.parseUnits('100', 18).toString(); // 100 DAI total
154
- const perSliceAmount = (
155
- BigInt(totalSrcAmount) / BigInt(numSlices)
156
- ).toString();
157
-
158
- // quote a single slice — route amounts must match floor(totalSrcAmount / numSlices)
159
- const deltaPrice = await deltaSDK.getDeltaPrice({
160
- srcToken: DAI_TOKEN,
161
- destToken: USDC_TOKEN,
162
- amount: perSliceAmount,
163
- userAddress: account,
164
- srcDecimals: 18,
165
- destDecimals: 6,
166
- });
167
-
168
- const tx = await deltaSDK.approveTokenForDelta(totalSrcAmount, DAI_TOKEN);
169
- await tx.wait();
170
-
171
- const deltaAuction = await deltaSDK.submitTWAPDeltaOrder({
172
- onChainOrderType: 'TWAPOrder',
173
- route: deltaPrice.route,
174
- owner: account,
175
- totalSrcAmount,
176
- numSlices,
177
- interval: 300, // 5 minutes between slices (min 60)
178
- slippage: 50,
179
- });
180
-
181
- startStatusCheckV2(() => deltaSDK.getDeltaOrderById(deltaAuction.id));
182
- }
183
-
184
- // Paginated list of a user's orders (v2 returns a { results, pagination } envelope).
185
- async function listUserOrders() {
186
- const page1 = await deltaSDK.getDeltaOrders({
187
- userAddress: account,
188
- page: 1,
189
- limit: 50,
190
- // status: ['ACTIVE', 'BRIDGING'],
191
- // type: 'MARKET',
192
- });
193
-
194
- console.log('orders:', page1.data);
195
- console.log('total:', page1.total, 'hasMore:', page1.hasMore);
196
- }
@@ -1,34 +0,0 @@
1
- import { DeltaV2 } 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: DeltaV2.DeltaAuction) {
6
- return order.status === 'COMPLETED';
7
- }
8
-
9
- type GetDeltaOrderV2Fn = () => Promise<DeltaV2.DeltaAuction>;
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
- const timeoutId = setTimeout(() => clearInterval(intervalId), 60000 * 5); // Stop after 5 minutes
29
-
30
- return () => {
31
- clearInterval(intervalId);
32
- clearTimeout(timeoutId);
33
- };
34
- }
@@ -1,86 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
- import type { DeltaAuctionOrder } from '../delta/helpers/types';
4
- import type { BuiltDeltaOrder, DeltaRoute } from './types';
5
- export type { BuiltDeltaOrder } from './types';
6
-
7
- export type BuildDeltaOrderParams = {
8
- /** @description The address of the order owner */
9
- owner: string;
10
- /** @description The address of the order beneficiary. Defaults to owner. */
11
- beneficiary?: string;
12
- /** @description The deadline for the order (unix seconds) */
13
- deadline?: number;
14
- /** @description The nonce of the order. Random if omitted. */
15
- nonce?: string;
16
- /** @description Optional permit signature for the src token. Defaults to "0x". */
17
- permit?: string;
18
- /** @description Partner string. Passed to the server to resolve partner fee details. */
19
- partner?: string;
20
- /** @description Partner fee in basis points (bps), 50bps=0.5% */
21
- partnerFeeBps?: number;
22
- /** @description Partner address */
23
- partnerAddress?: string;
24
- /** @description Take surplus flag */
25
- partnerTakesSurplus?: boolean;
26
- /** @description Whether the surplus should be capped. True by default. */
27
- capSurplus?: boolean;
28
- /** @description Metadata for the order, hex string */
29
- metadata?: string;
30
- /** @description Designates the Order as partially fillable instead of fill-or-kill. Default false. */
31
- partiallyFillable?: boolean;
32
-
33
- /** @description DeltaRoute from getDeltaPrice — either price.route or any price.alternatives[i] */
34
- route: DeltaRoute;
35
- /** @description Order side. SELL or BUY. */
36
- side: 'SELL' | 'BUY';
37
- /** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5%. Default 0. */
38
- slippage?: number;
39
- /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount */
40
- limitAmount?: string;
41
- };
42
-
43
- type BuildDeltaOrder = (
44
- buildOrderParams: BuildDeltaOrderParams,
45
- requestParams?: RequestParameters
46
- ) => Promise<BuiltDeltaOrder<DeltaAuctionOrder>>;
47
-
48
- export type BuildDeltaOrderFunctions = {
49
- /** @description Build a Delta v2 order from a DeltaRoute via the server endpoint, ready to sign and post. */
50
- buildDeltaOrder: BuildDeltaOrder;
51
- };
52
-
53
- export const constructBuildDeltaOrder = (
54
- options: ConstructFetchInput
55
- ): BuildDeltaOrderFunctions => {
56
- const { apiURL = API_URL, fetcher } = options;
57
- const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
58
-
59
- const buildDeltaOrder: BuildDeltaOrder = async (params, requestParams) =>
60
- fetcher<BuiltDeltaOrder<DeltaAuctionOrder>>({
61
- url: buildUrl,
62
- method: 'POST',
63
- data: {
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 { buildDeltaOrder };
86
- };
@@ -1,95 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
- import type { ExternalDeltaOrder } from '../delta/helpers/types';
4
- import type { BuiltDeltaOrder, DeltaRoute } from './types';
5
- export type { BuiltDeltaOrder } from './types';
6
-
7
- export type BuildExternalDeltaOrderParams = {
8
- /** @description The address of the order owner */
9
- owner: string;
10
- /** @description The address of the external handler contract */
11
- handler: string;
12
- /** @description Protocol-specific encoded bytes for the external handler */
13
- data: string;
14
- /** @description The address of the order beneficiary. Defaults to owner. */
15
- beneficiary?: string;
16
- /** @description The deadline for the order (unix seconds) */
17
- deadline?: number;
18
- /** @description The nonce of the order. Random if omitted. */
19
- nonce?: string;
20
- /** @description Optional permit signature for the src token. Defaults to "0x". */
21
- permit?: string;
22
- /** @description Partner string. Passed to the server to resolve partner fee details. */
23
- partner?: string;
24
- /** @description Partner fee in basis points (bps), 50bps=0.5% */
25
- partnerFeeBps?: number;
26
- /** @description Partner address */
27
- partnerAddress?: string;
28
- /** @description Take surplus flag */
29
- partnerTakesSurplus?: boolean;
30
- /** @description Whether the surplus should be capped. True by default. */
31
- capSurplus?: boolean;
32
- /** @description Metadata for the order, hex string */
33
- metadata?: string;
34
- /** @description Designates the Order as partially fillable. Default false. */
35
- partiallyFillable?: boolean;
36
-
37
- /** @description DeltaRoute from getDeltaPrice */
38
- route: DeltaRoute;
39
- /** @description Order side. SELL or BUY. */
40
- side: 'SELL' | 'BUY';
41
- /** @description Slippage in basis points (bps). Default 0. */
42
- slippage?: number;
43
- /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount */
44
- limitAmount?: string;
45
- };
46
-
47
- type BuildExternalDeltaOrder = (
48
- buildOrderParams: BuildExternalDeltaOrderParams,
49
- requestParams?: RequestParameters
50
- ) => Promise<BuiltDeltaOrder<ExternalDeltaOrder>>;
51
-
52
- export type BuildExternalDeltaOrderFunctions = {
53
- /** @description Build a Delta v2 External Order from a DeltaRoute via the server endpoint, ready to sign and post. */
54
- buildExternalDeltaOrder: BuildExternalDeltaOrder;
55
- };
56
-
57
- export const constructBuildExternalDeltaOrder = (
58
- options: ConstructFetchInput
59
- ): BuildExternalDeltaOrderFunctions => {
60
- const { apiURL = API_URL, fetcher } = options;
61
- const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
62
-
63
- const buildExternalDeltaOrder: BuildExternalDeltaOrder = async (
64
- params,
65
- requestParams
66
- ) =>
67
- fetcher<BuiltDeltaOrder<ExternalDeltaOrder>>({
68
- url: buildUrl,
69
- method: 'POST',
70
- data: {
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 { buildExternalDeltaOrder };
95
- };
@@ -1,131 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
- import type { TWAPBuyDeltaOrder, TWAPDeltaOrder } from '../delta/helpers/types';
4
- import type { BuiltDeltaOrder, DeltaRoute } from './types';
5
- export type { BuiltDeltaOrder } from './types';
6
-
7
- type BuildTWAPDeltaOrderBase = {
8
- /** @description The address of the order owner */
9
- owner: string;
10
- /** @description The address of the order beneficiary. Defaults to owner. */
11
- beneficiary?: string;
12
- /** @description The deadline for the order (unix seconds) */
13
- deadline?: number;
14
- /** @description The nonce of the order. Random if omitted. */
15
- nonce?: string;
16
- /** @description Optional permit signature for the src token. Defaults to "0x". */
17
- permit?: string;
18
- /** @description Partner string. Passed to the server to resolve partner fee details. */
19
- partner?: string;
20
- /** @description Seconds between slice executions (min 60) */
21
- interval: number;
22
- /** @description Number of slices (min 2) */
23
- numSlices: number;
24
- /** @description Slippage in basis points (bps). 10000 = 100%, 50 = 0.5%. Default 0. */
25
- slippage?: number;
26
- /** @description DeltaRoute from getDeltaPrice for a single slice */
27
- route: DeltaRoute;
28
- /** @description Partner fee in basis points (bps) */
29
- partnerFeeBps?: number;
30
- /** @description Partner address */
31
- partnerAddress?: string;
32
- /** @description Take surplus flag */
33
- partnerTakesSurplus?: boolean;
34
- /** @description Whether the surplus should be capped. True by default. */
35
- capSurplus?: boolean;
36
- /** @description Metadata for the order, hex string */
37
- metadata?: string;
38
- /** @description Designates the Order as partially fillable. Default false. */
39
- partiallyFillable?: boolean;
40
- /** @description If passed, the server will use this as SELL destAmount (as BUY srcAmount) and expectedAmount for each slice */
41
- limitAmount?: string;
42
- };
43
-
44
- export type BuildTWAPSellDeltaOrderParams = BuildTWAPDeltaOrderBase & {
45
- onChainOrderType: 'TWAPOrder';
46
- /** @description Total source token amount across all slices. route.origin.input.amount must equal floor(totalSrcAmount / numSlices). */
47
- totalSrcAmount: string;
48
- };
49
-
50
- export type BuildTWAPBuyDeltaOrderParams = BuildTWAPDeltaOrderBase & {
51
- onChainOrderType: 'TWAPBuyOrder';
52
- /** @description Total destination token amount to buy across all slices. route.origin.output.amount must equal floor(totalDestAmount / numSlices). */
53
- totalDestAmount: string;
54
- /** @description Maximum source token amount willing to spend across all slices. */
55
- maxSrcAmount: string;
56
- };
57
-
58
- export type BuildTWAPDeltaOrderParams =
59
- | BuildTWAPSellDeltaOrderParams
60
- | BuildTWAPBuyDeltaOrderParams;
61
-
62
- type BuildTWAPDeltaOrder = (
63
- buildOrderParams: BuildTWAPDeltaOrderParams,
64
- requestParams?: RequestParameters
65
- ) => Promise<BuiltDeltaOrder<TWAPDeltaOrder | TWAPBuyDeltaOrder>>;
66
-
67
- export type BuildTWAPDeltaOrderFunctions = {
68
- /** @description Build a Delta v2 TWAP Order (sell or buy) from a DeltaRoute via the server endpoint, ready to sign and post. */
69
- buildTWAPDeltaOrder: BuildTWAPDeltaOrder;
70
- };
71
-
72
- export const constructBuildTWAPDeltaOrder = (
73
- options: ConstructFetchInput
74
- ): BuildTWAPDeltaOrderFunctions => {
75
- const { apiURL = API_URL, fetcher } = options;
76
- const buildUrl = `${apiURL}/delta/v2/orders/build` as const;
77
-
78
- const buildTWAPDeltaOrder: BuildTWAPDeltaOrder = async (
79
- params,
80
- requestParams
81
- ) => {
82
- const commonBody = {
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<BuiltDeltaOrder<TWAPDeltaOrder>>({
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<BuiltDeltaOrder<TWAPBuyDeltaOrder>>({
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 { buildTWAPDeltaOrder };
131
- };
@@ -1,100 +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 SignCancelDeltaOrderRequest = (
20
- params: CancelDeltaOrderData,
21
- requestParams?: RequestParameters
22
- ) => Promise<string>;
23
-
24
- export type PostCancelDeltaOrderRequest = (
25
- params: CancelDeltaOrderRequestParams,
26
- requestParams?: RequestParameters
27
- ) => Promise<SuccessResponse>;
28
-
29
- export type CancelDeltaOrder = (
30
- params: CancelDeltaOrderData,
31
- requestParams?: RequestParameters
32
- ) => Promise<SuccessResponse>;
33
-
34
- export type CancelDeltaOrderFunctions = {
35
- signCancelDeltaOrderRequest: SignCancelDeltaOrderRequest;
36
- postCancelDeltaOrderRequest: PostCancelDeltaOrderRequest;
37
- /** @description Cancel one or more Delta orders via the v2 endpoint */
38
- cancelDeltaOrders: CancelDeltaOrder;
39
- };
40
-
41
- export const constructCancelDeltaOrder = (
42
- options: Pick<
43
- ConstructProviderFetchInput<any, 'signTypedDataCall'>,
44
- 'contractCaller' | 'fetcher' | 'apiURL' | 'chainId'
45
- >
46
- ): CancelDeltaOrderFunctions => {
47
- const apiURL = options.apiURL ?? API_URL;
48
-
49
- const { getDeltaContract } = constructGetDeltaContract(options);
50
-
51
- const signCancelDeltaOrderRequest: SignCancelDeltaOrderRequest = 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 postCancelDeltaOrderRequest: PostCancelDeltaOrderRequest = 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 cancelDeltaOrders: CancelDeltaOrder = async (
84
- { orderIds },
85
- requestParams
86
- ) => {
87
- const signature = await signCancelDeltaOrderRequest(
88
- { orderIds },
89
- requestParams
90
- );
91
-
92
- return postCancelDeltaOrderRequest({ orderIds, signature }, requestParams);
93
- };
94
-
95
- return {
96
- signCancelDeltaOrderRequest,
97
- postCancelDeltaOrderRequest,
98
- cancelDeltaOrders,
99
- };
100
- };
@@ -1,32 +0,0 @@
1
- import { API_URL } from '../../constants';
2
- import type { ConstructFetchInput, RequestParameters } from '../../types';
3
-
4
- export type AgentList = string[];
5
-
6
- type AgentsListResponse = AgentList;
7
-
8
- type GetAgentsList = (requestParams?: RequestParameters) => Promise<AgentList>;
9
-
10
- export type GetAgentsListFunctions = {
11
- /** @description List agents available on the current chain. */
12
- getAgentsList: GetAgentsList;
13
- };
14
-
15
- export const constructGetAgentsList = ({
16
- apiURL = API_URL,
17
- chainId,
18
- fetcher,
19
- }: ConstructFetchInput): GetAgentsListFunctions => {
20
- const baseUrl = `${apiURL}/delta/v2/agents/list/${chainId}` as const;
21
-
22
- const getAgentsList: GetAgentsList = async (requestParams) => {
23
- const data = await fetcher<AgentsListResponse>({
24
- url: baseUrl,
25
- method: 'GET',
26
- requestParams,
27
- });
28
- return data;
29
- };
30
-
31
- return { getAgentsList };
32
- };