@velora-dex/sdk 9.4.1-dev.2 → 9.4.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.

Potentially problematic release.


This version of @velora-dex/sdk might be problematic. Click here for more details.

Files changed (40) hide show
  1. package/dist/index.d.ts +5 -11
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +4 -0
  4. package/dist/methods/delta/helpers/misc.d.ts +0 -8
  5. package/dist/methods/delta/helpers/misc.d.ts.map +1 -1
  6. package/dist/methods/delta/helpers/types.d.ts +2 -43
  7. package/dist/methods/delta/helpers/types.d.ts.map +1 -1
  8. package/dist/methods/delta/index.d.ts +1 -16
  9. package/dist/methods/delta/index.d.ts.map +1 -1
  10. package/dist/sdk/partial.d.ts +1 -3
  11. package/dist/sdk/partial.d.ts.map +1 -1
  12. package/dist/sdk.cjs.development.js +35 -623
  13. package/dist/sdk.cjs.development.js.map +1 -1
  14. package/dist/sdk.cjs.production.min.js +1 -1
  15. package/dist/sdk.cjs.production.min.js.map +1 -1
  16. package/dist/sdk.esm.js +36 -619
  17. package/dist/sdk.esm.js.map +1 -1
  18. package/package.json +1 -1
  19. package/src/constants.js +6 -1
  20. package/src/index.js +125 -68
  21. package/src/index.ts +0 -63
  22. package/src/methods/delta/helpers/misc.ts +1 -35
  23. package/src/methods/delta/helpers/types.ts +2 -52
  24. package/src/methods/delta/index.ts +1 -78
  25. package/src/sdk/partial.ts +1 -3
  26. package/dist/methods/delta/buildTWAPDeltaOrder.d.ts +0 -65
  27. package/dist/methods/delta/buildTWAPDeltaOrder.d.ts.map +0 -1
  28. package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts +0 -74
  29. package/dist/methods/delta/helpers/buildTWAPOrderData.d.ts.map +0 -1
  30. package/dist/methods/delta/postTWAPDeltaOrder.d.ts +0 -16
  31. package/dist/methods/delta/postTWAPDeltaOrder.d.ts.map +0 -1
  32. package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts +0 -20
  33. package/dist/methods/delta/preSignTWAPDeltaOrder.d.ts.map +0 -1
  34. package/dist/methods/delta/signTWAPDeltaOrder.d.ts +0 -9
  35. package/dist/methods/delta/signTWAPDeltaOrder.d.ts.map +0 -1
  36. package/src/methods/delta/buildTWAPDeltaOrder.ts +0 -187
  37. package/src/methods/delta/helpers/buildTWAPOrderData.ts +0 -227
  38. package/src/methods/delta/postTWAPDeltaOrder.ts +0 -57
  39. package/src/methods/delta/preSignTWAPDeltaOrder.ts +0 -168
  40. package/src/methods/delta/signTWAPDeltaOrder.ts +0 -32
@@ -1,57 +0,0 @@
1
- import { Prettify } from 'ts-essentials';
2
- import { API_URL } from '../../constants';
3
- import type { ConstructFetchInput, RequestParameters } from '../../types';
4
- import type { DeltaAuction, TWAPOnChainOrderType } from './helpers/types';
5
- import type { DeltaOrderToPost } from './postDeltaOrder';
6
- import { constructSearchString } from '../../helpers/misc';
7
-
8
- export type PostTWAPDeltaOrderParams = Prettify<
9
- Omit<
10
- DeltaOrderToPost<'TWAPOrder'> | DeltaOrderToPost<'TWAPBuyOrder'>,
11
- 'chainId'
12
- > & {
13
- /** @description Must be "TWAPOrder" or "TWAPBuyOrder" */
14
- onChainOrderType: TWAPOnChainOrderType;
15
- degenMode?: boolean;
16
- }
17
- >;
18
-
19
- type PostTWAPDeltaOrder = (
20
- postData: PostTWAPDeltaOrderParams,
21
- requestParams?: RequestParameters
22
- ) => Promise<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>;
23
-
24
- export type PostTWAPDeltaOrderFunctions = {
25
- postTWAPDeltaOrder: PostTWAPDeltaOrder;
26
- };
27
-
28
- export const constructPostTWAPDeltaOrder = ({
29
- apiURL = API_URL,
30
- chainId,
31
- fetcher,
32
- }: ConstructFetchInput): PostTWAPDeltaOrderFunctions => {
33
- const postOrderUrl = `${apiURL}/delta/orders` as const;
34
-
35
- const postTWAPDeltaOrder: PostTWAPDeltaOrder = (_postData, requestParams) => {
36
- const { degenMode, ...postData } = _postData;
37
- const deltaOrderToPost: DeltaOrderToPost<'TWAPOrder' | 'TWAPBuyOrder'> = {
38
- ...postData,
39
- chainId,
40
- };
41
-
42
- const search = constructSearchString<{ degenMode?: boolean }>({
43
- degenMode,
44
- });
45
-
46
- const fetchURL = `${postOrderUrl}/${search}` as const;
47
-
48
- return fetcher<DeltaAuction<'TWAPOrder'> | DeltaAuction<'TWAPBuyOrder'>>({
49
- url: fetchURL,
50
- method: 'POST',
51
- data: deltaOrderToPost,
52
- requestParams,
53
- });
54
- };
55
-
56
- return { postTWAPDeltaOrder };
57
- };
@@ -1,168 +0,0 @@
1
- import { hashTypedData } from 'viem/utils';
2
- import type {
3
- ConstructProviderFetchInput,
4
- RequestParameters,
5
- TxSendOverrides,
6
- } from '../../types';
7
- import {
8
- produceTWAPOrderTypedData,
9
- SignableTWAPOrderData,
10
- } from './helpers/buildTWAPOrderData';
11
- import { sanitizeTWAPOrderData } from './helpers/misc';
12
- import { PreSignatureModuleAbi } from './helpers/abi';
13
- import type { ExtractAbiMethodNames } from '../../helpers/misc';
14
- import { findPrimaryType } from '../../helpers/providers/helpers';
15
- import { constructGetDeltaContract } from './getDeltaContract';
16
- import type { TWAPDeltaOrder, TWAPBuyDeltaOrder } from './helpers/types';
17
- import { TypedDataField } from 'ethersV5';
18
-
19
- type HashTWAPDeltaOrderTypedData = (
20
- signableOrderData: SignableTWAPOrderData
21
- ) => string;
22
-
23
- type HashTWAPDeltaOrder = {
24
- (
25
- orderData: TWAPDeltaOrder,
26
- onChainOrderType: 'TWAPOrder',
27
- requestParams?: RequestParameters
28
- ): Promise<string>;
29
-
30
- (
31
- orderData: TWAPBuyDeltaOrder,
32
- onChainOrderType: 'TWAPBuyOrder',
33
- requestParams?: RequestParameters
34
- ): Promise<string>;
35
- };
36
-
37
- export type SetTWAPDeltaOrderPreSignature<T> = (
38
- orderHash: string,
39
- overrides?: TxSendOverrides,
40
- requestParams?: RequestParameters
41
- ) => Promise<T>;
42
-
43
- export type PreSignTWAPDeltaOrder<T> = (
44
- signableOrderData: SignableTWAPOrderData,
45
- overrides?: TxSendOverrides,
46
- requestParams?: RequestParameters
47
- ) => Promise<T>;
48
-
49
- export type PreSignTWAPDeltaOrderFunctions<T> = {
50
- hashTWAPDeltaOrderTypedData: HashTWAPDeltaOrderTypedData;
51
- hashTWAPDeltaOrder: HashTWAPDeltaOrder;
52
- setTWAPDeltaOrderPreSignature: SetTWAPDeltaOrderPreSignature<T>;
53
- preSignTWAPDeltaOrder: PreSignTWAPDeltaOrder<T>;
54
- };
55
-
56
- type AvailableMethods = ExtractAbiMethodNames<typeof PreSignatureModuleAbi>;
57
-
58
- export const constructPreSignTWAPDeltaOrder = <T>(
59
- options: ConstructProviderFetchInput<T, 'transactCall'>
60
- ): PreSignTWAPDeltaOrderFunctions<T> => {
61
- const hashTWAPDeltaOrderTypedData: HashTWAPDeltaOrderTypedData = (
62
- typedData
63
- ) => {
64
- const typedDataOnly = {
65
- ...typedData,
66
- data: sanitizeTWAPOrderData(typedData.data),
67
- } as SignableTWAPOrderData;
68
-
69
- const orderHash = produceTWAPOrderHash(typedDataOnly);
70
-
71
- return orderHash;
72
- };
73
-
74
- const { getDeltaContract } = constructGetDeltaContract(options);
75
-
76
- const hashTWAPDeltaOrder: HashTWAPDeltaOrder = async (
77
- orderData,
78
- onChainOrderType,
79
- requestParams
80
- ) => {
81
- const ParaswapDelta = await getDeltaContract(requestParams);
82
- if (!ParaswapDelta) {
83
- throw new Error(`Delta is not available on chain ${options.chainId}`);
84
- }
85
-
86
- if (onChainOrderType === 'TWAPOrder' && 'totalSrcAmount' in orderData) {
87
- const typedData = produceTWAPOrderTypedData({
88
- orderInput: orderData,
89
- chainId: options.chainId,
90
- paraswapDeltaAddress: ParaswapDelta,
91
- onChainOrderType,
92
- });
93
- return hashTWAPDeltaOrderTypedData(typedData);
94
- }
95
-
96
- if (onChainOrderType === 'TWAPBuyOrder' && 'maxSrcAmount' in orderData) {
97
- const typedData = produceTWAPOrderTypedData({
98
- orderInput: orderData,
99
- chainId: options.chainId,
100
- paraswapDeltaAddress: ParaswapDelta,
101
- onChainOrderType,
102
- });
103
- return hashTWAPDeltaOrderTypedData(typedData);
104
- }
105
-
106
- throw new Error(
107
- `Invalid order data for onChainOrderType ${onChainOrderType}`
108
- );
109
- };
110
-
111
- const setTWAPDeltaOrderPreSignature: SetTWAPDeltaOrderPreSignature<
112
- T
113
- > = async (orderHash, overrides = {}, requestParams) => {
114
- const ParaswapDelta = await getDeltaContract(requestParams);
115
- if (!ParaswapDelta) {
116
- throw new Error(`Delta is not available on chain ${options.chainId}`);
117
- }
118
-
119
- const res = await options.contractCaller.transactCall<AvailableMethods>({
120
- address: ParaswapDelta,
121
- abi: PreSignatureModuleAbi,
122
- contractMethod: 'setPreSignature',
123
- args: [orderHash, true],
124
- overrides,
125
- });
126
-
127
- return res;
128
- };
129
-
130
- const preSignTWAPDeltaOrder: PreSignTWAPDeltaOrder<T> = async (
131
- signableOrderData,
132
- overrides = {},
133
- requestParams
134
- ) => {
135
- const orderHash = hashTWAPDeltaOrderTypedData(signableOrderData);
136
- const res = await setTWAPDeltaOrderPreSignature(
137
- orderHash,
138
- overrides,
139
- requestParams
140
- );
141
- return res;
142
- };
143
-
144
- return {
145
- hashTWAPDeltaOrderTypedData,
146
- hashTWAPDeltaOrder,
147
- setTWAPDeltaOrderPreSignature,
148
- preSignTWAPDeltaOrder,
149
- };
150
- };
151
-
152
- export function produceTWAPOrderHash(typedData: SignableTWAPOrderData): string {
153
- const types = typedData.types as Record<
154
- 'TWAPOrder' | 'TWAPBuyOrder' | 'Bridge',
155
- TypedDataField[]
156
- >;
157
- return hashTypedData({
158
- domain: {
159
- name: typedData.domain.name,
160
- version: typedData.domain.version,
161
- chainId: typedData.domain.chainId,
162
- verifyingContract: typedData.domain.verifyingContract as `0x${string}`,
163
- },
164
- types,
165
- primaryType: findPrimaryType(types),
166
- message: typedData.data,
167
- });
168
- }
@@ -1,32 +0,0 @@
1
- import type { ConstructProviderFetchInput } from '../../types';
2
- import { SignableTWAPOrderData } from './helpers/buildTWAPOrderData';
3
- import { sanitizeTWAPOrderData } from './helpers/misc';
4
-
5
- type SignTWAPDeltaOrder = (
6
- signableOrderData: SignableTWAPOrderData
7
- ) => Promise<string>;
8
-
9
- export type SignTWAPDeltaOrderFunctions = {
10
- signTWAPDeltaOrder: SignTWAPDeltaOrder;
11
- };
12
-
13
- export const constructSignTWAPDeltaOrder = (
14
- options: Pick<
15
- ConstructProviderFetchInput<any, 'signTypedDataCall'>,
16
- 'contractCaller'
17
- >
18
- ): SignTWAPDeltaOrderFunctions => {
19
- const signTWAPDeltaOrder: SignTWAPDeltaOrder = async (typedData) => {
20
- const typedDataOnly = {
21
- ...typedData,
22
- data: sanitizeTWAPOrderData(typedData.data),
23
- } as SignableTWAPOrderData;
24
- const signature = await options.contractCaller.signTypedDataCall(
25
- typedDataOnly
26
- );
27
-
28
- return signature;
29
- };
30
-
31
- return { signTWAPDeltaOrder };
32
- };