@velora-dex/sdk 9.5.3-dev.1 → 9.5.4-dev.0
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.
- package/README.md +2 -2
- package/dist/examples/deltaV2.d.ts +2 -0
- package/dist/examples/deltaV2.d.ts.map +1 -0
- package/dist/examples/helpers/deltaV2.d.ts +5 -0
- package/dist/examples/helpers/deltaV2.d.ts.map +1 -0
- package/dist/examples/wagmi.d.ts.map +1 -1
- package/dist/index.d.ts +18 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/methods/delta/cancelDeltaOrder.d.ts.map +1 -1
- package/dist/methods/delta/getDeltaOrders.d.ts +4 -4
- package/dist/methods/delta/getDeltaOrders.d.ts.map +1 -1
- package/dist/methods/delta/getDeltaPrice.d.ts +1 -1
- package/dist/methods/delta/getDeltaPrice.d.ts.map +1 -1
- package/dist/methods/delta/helpers/orders.d.ts.map +1 -1
- package/dist/methods/delta/helpers/types.d.ts +11 -4
- package/dist/methods/delta/helpers/types.d.ts.map +1 -1
- package/dist/methods/delta/postDeltaOrder.d.ts +3 -3
- package/dist/methods/delta/postDeltaOrder.d.ts.map +1 -1
- package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts +44 -0
- package/dist/methods/deltaV2/buildDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts +48 -0
- package/dist/methods/deltaV2/buildExternalDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts +59 -0
- package/dist/methods/deltaV2/buildTWAPDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts +21 -0
- package/dist/methods/deltaV2/cancelDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/getAgentsListV2.d.ts +10 -0
- package/dist/methods/deltaV2/getAgentsListV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/getBridgeRoutes.d.ts +20 -0
- package/dist/methods/deltaV2/getBridgeRoutes.d.ts.map +1 -0
- package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts +33 -0
- package/dist/methods/deltaV2/getDeltaOrdersV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/getDeltaPriceV2.d.ts +46 -0
- package/dist/methods/deltaV2/getDeltaPriceV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/index.d.ts +59 -0
- package/dist/methods/deltaV2/index.d.ts.map +1 -0
- package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts +8 -0
- package/dist/methods/deltaV2/isTokenSupportedInDeltaV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/postDeltaOrderV2.d.ts +28 -0
- package/dist/methods/deltaV2/postDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts +11 -0
- package/dist/methods/deltaV2/postExternalDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts +16 -0
- package/dist/methods/deltaV2/postTWAPDeltaOrderV2.d.ts.map +1 -0
- package/dist/methods/deltaV2/types.d.ts +163 -0
- package/dist/methods/deltaV2/types.d.ts.map +1 -0
- package/dist/sdk/full.d.ts +2 -0
- package/dist/sdk/full.d.ts.map +1 -1
- package/dist/sdk/simple.d.ts +10 -0
- package/dist/sdk/simple.d.ts.map +1 -1
- package/dist/sdk.cjs.development.js +1195 -512
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +1179 -513
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +8 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +17 -9
- package/src/examples/deltaV2.ts +200 -0
- package/src/examples/helpers/deltaV2.ts +29 -0
- package/src/examples/wagmi.ts +2 -2
- package/src/index.js +31 -1
- package/src/index.ts +148 -0
- package/src/methods/delta/cancelDeltaOrder.ts +4 -1
- package/src/methods/delta/getDeltaOrders.ts +6 -5
- package/src/methods/delta/getDeltaPrice.ts +1 -1
- package/src/methods/delta/helpers/orders.ts +9 -101
- package/src/methods/delta/helpers/types.ts +24 -13
- package/src/methods/delta/postDeltaOrder.ts +4 -4
- package/src/methods/delta/postTWAPDeltaOrder.ts +1 -1
- package/src/methods/deltaV2/buildDeltaOrderV2.ts +86 -0
- package/src/methods/deltaV2/buildExternalDeltaOrderV2.ts +95 -0
- package/src/methods/deltaV2/buildTWAPDeltaOrderV2.ts +131 -0
- package/src/methods/deltaV2/cancelDeltaOrderV2.ts +103 -0
- package/src/methods/deltaV2/getAgentsListV2.ts +34 -0
- package/src/methods/deltaV2/getBridgeRoutes.ts +82 -0
- package/src/methods/deltaV2/getDeltaOrdersV2.ts +119 -0
- package/src/methods/deltaV2/getDeltaPriceV2.ts +108 -0
- package/src/methods/deltaV2/index.ts +303 -0
- package/src/methods/deltaV2/isTokenSupportedInDeltaV2.ts +52 -0
- package/src/methods/deltaV2/postDeltaOrderV2.ts +65 -0
- package/src/methods/deltaV2/postExternalDeltaOrderV2.ts +45 -0
- package/src/methods/deltaV2/postTWAPDeltaOrderV2.ts +63 -0
- package/src/methods/deltaV2/types.ts +189 -0
- package/src/sdk/full.ts +8 -0
- package/src/sdk/simple.ts +56 -0
- package/src/types.ts +9 -0
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { API_URL } from '../../constants';
|
|
2
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
+
import type { ConstructFetchInput, RequestParameters } from '../../types';
|
|
4
|
+
import type { BridgeProtocolResponse } from '../delta/getBridgeInfo';
|
|
5
|
+
import type { BridgeRoute } from './types';
|
|
6
|
+
|
|
7
|
+
type GetBridgeRoutesParams = {
|
|
8
|
+
/** @description Include tokens that can be swapped on destChain after bridge. Default is true. */
|
|
9
|
+
allowBridgeAndSwap?: boolean;
|
|
10
|
+
/** @description Include only the specified bridges. Default is all bridges. */
|
|
11
|
+
bridges?: string[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type BridgeRoutesQuery = {
|
|
15
|
+
allowBridgeAndSwap?: boolean;
|
|
16
|
+
bridges?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type BridgeRoutesResponse = { routes: BridgeRoute[] };
|
|
20
|
+
|
|
21
|
+
type GetBridgeRoutes = (
|
|
22
|
+
params?: GetBridgeRoutesParams,
|
|
23
|
+
requestParams?: RequestParameters
|
|
24
|
+
) => Promise<BridgeRoute[]>;
|
|
25
|
+
|
|
26
|
+
type GetBridgeProtocolsV2 = (
|
|
27
|
+
requestParams?: RequestParameters
|
|
28
|
+
) => Promise<BridgeProtocolResponse[]>;
|
|
29
|
+
|
|
30
|
+
type BridgeProtocolsV2Response = {
|
|
31
|
+
bridgeProtocols: BridgeProtocolResponse[];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type GetBridgeRoutesFunctions = {
|
|
35
|
+
/** @description Fetch supported bridge routes as a flat array (v2 replacement for bridge-info). */
|
|
36
|
+
getBridgeRoutes: GetBridgeRoutes;
|
|
37
|
+
/** @description Fetch supported bridge protocols (falls through to v1 controller on the v2 path). */
|
|
38
|
+
getBridgeProtocolsV2: GetBridgeProtocolsV2;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const constructGetBridgeRoutes = ({
|
|
42
|
+
apiURL = API_URL,
|
|
43
|
+
fetcher,
|
|
44
|
+
}: ConstructFetchInput): GetBridgeRoutesFunctions => {
|
|
45
|
+
const deltaPricesUrl = `${apiURL}/delta/v2/prices` as const;
|
|
46
|
+
|
|
47
|
+
const getBridgeRoutes: GetBridgeRoutes = async (
|
|
48
|
+
params = {},
|
|
49
|
+
requestParams
|
|
50
|
+
) => {
|
|
51
|
+
const { allowBridgeAndSwap, bridges } = params;
|
|
52
|
+
|
|
53
|
+
const search = constructSearchString<BridgeRoutesQuery>({
|
|
54
|
+
allowBridgeAndSwap,
|
|
55
|
+
bridges: bridges?.join(','),
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const fetchURL = `${deltaPricesUrl}/bridge-routes${search}` as const;
|
|
59
|
+
|
|
60
|
+
const data = await fetcher<BridgeRoutesResponse>({
|
|
61
|
+
url: fetchURL,
|
|
62
|
+
method: 'GET',
|
|
63
|
+
requestParams,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
return data.routes;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const getBridgeProtocolsV2: GetBridgeProtocolsV2 = async (requestParams) => {
|
|
70
|
+
const fetchURL = `${deltaPricesUrl}/bridge-protocols` as const;
|
|
71
|
+
|
|
72
|
+
const data = await fetcher<BridgeProtocolsV2Response>({
|
|
73
|
+
url: fetchURL,
|
|
74
|
+
method: 'GET',
|
|
75
|
+
requestParams,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return data.bridgeProtocols;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return { getBridgeRoutes, getBridgeProtocolsV2 };
|
|
82
|
+
};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { API_URL } from '../../constants';
|
|
2
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
+
import type {
|
|
4
|
+
Address,
|
|
5
|
+
ConstructFetchInput,
|
|
6
|
+
PaginatedResponse,
|
|
7
|
+
RequestParameters,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import type {
|
|
10
|
+
DeltaOrderType,
|
|
11
|
+
OnChainOrderType,
|
|
12
|
+
} from '../delta/helpers/types';
|
|
13
|
+
import type { DeltaOrderStatusV2, DeltaOrderV2Response } from './types';
|
|
14
|
+
|
|
15
|
+
type GetDeltaOrderByIdV2 = (
|
|
16
|
+
orderId: string,
|
|
17
|
+
requestParams?: RequestParameters
|
|
18
|
+
) => Promise<DeltaOrderV2Response>;
|
|
19
|
+
|
|
20
|
+
type GetDeltaOrderByHashV2 = (
|
|
21
|
+
orderHash: string,
|
|
22
|
+
requestParams?: RequestParameters
|
|
23
|
+
) => Promise<DeltaOrderV2Response>;
|
|
24
|
+
|
|
25
|
+
type OrdersV2Filter = {
|
|
26
|
+
/** @description `order.owner` to fetch Delta Orders for. */
|
|
27
|
+
userAddress: Address;
|
|
28
|
+
/** @description Pagination option. Default 1. */
|
|
29
|
+
page?: number;
|
|
30
|
+
/** @description Pagination option. Default 100, max 1000. */
|
|
31
|
+
limit?: number;
|
|
32
|
+
/** @description Filter by chainId. Omitted = orders across all chains. */
|
|
33
|
+
chainId?: number[];
|
|
34
|
+
/** @description Filter by integrator-facing status. */
|
|
35
|
+
status?: DeltaOrderStatusV2[];
|
|
36
|
+
/** @description Filter by order type. MARKET or LIMIT. */
|
|
37
|
+
type?: DeltaOrderType;
|
|
38
|
+
/** @description Filter by on-chain order type. */
|
|
39
|
+
onChainOrderType?: OnChainOrderType;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type OrderFiltersV2Query = Omit<OrdersV2Filter, 'chainId' | 'status'> & {
|
|
43
|
+
chainId?: string;
|
|
44
|
+
status?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type GetDeltaOrdersV2 = (
|
|
48
|
+
options: OrdersV2Filter,
|
|
49
|
+
requestParams?: RequestParameters
|
|
50
|
+
) => Promise<PaginatedResponse<DeltaOrderV2Response>>;
|
|
51
|
+
|
|
52
|
+
export type GetDeltaOrdersV2Functions = {
|
|
53
|
+
/** @description Fetch a single order by its UUID. */
|
|
54
|
+
getDeltaOrderByIdV2: GetDeltaOrderByIdV2;
|
|
55
|
+
/** @description Fetch a single order by its EIP-712 order hash. */
|
|
56
|
+
getDeltaOrderByHashV2: GetDeltaOrderByHashV2;
|
|
57
|
+
/** @description List Delta orders with the v2 pagination envelope. */
|
|
58
|
+
getDeltaOrdersV2: GetDeltaOrdersV2;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const constructGetDeltaOrdersV2 = ({
|
|
62
|
+
apiURL = API_URL,
|
|
63
|
+
fetcher,
|
|
64
|
+
}: ConstructFetchInput): GetDeltaOrdersV2Functions => {
|
|
65
|
+
const baseUrl = `${apiURL}/delta/v2/orders` as const;
|
|
66
|
+
|
|
67
|
+
const getDeltaOrderByIdV2: GetDeltaOrderByIdV2 = async (
|
|
68
|
+
orderId,
|
|
69
|
+
requestParams
|
|
70
|
+
) => {
|
|
71
|
+
const fetchURL = `${baseUrl}/${orderId}` as const;
|
|
72
|
+
return fetcher<DeltaOrderV2Response>({
|
|
73
|
+
url: fetchURL,
|
|
74
|
+
method: 'GET',
|
|
75
|
+
requestParams,
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const getDeltaOrderByHashV2: GetDeltaOrderByHashV2 = async (
|
|
80
|
+
orderHash,
|
|
81
|
+
requestParams
|
|
82
|
+
) => {
|
|
83
|
+
const fetchURL = `${baseUrl}/hash/${orderHash}` as const;
|
|
84
|
+
return fetcher<DeltaOrderV2Response>({
|
|
85
|
+
url: fetchURL,
|
|
86
|
+
method: 'GET',
|
|
87
|
+
requestParams,
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const getDeltaOrdersV2: GetDeltaOrdersV2 = async (options, requestParams) => {
|
|
92
|
+
const chainIdString = options.chainId?.join(',');
|
|
93
|
+
const statusString = options.status?.join(',');
|
|
94
|
+
|
|
95
|
+
const search = constructSearchString<OrderFiltersV2Query>({
|
|
96
|
+
userAddress: options.userAddress,
|
|
97
|
+
page: options.page,
|
|
98
|
+
limit: options.limit,
|
|
99
|
+
type: options.type,
|
|
100
|
+
onChainOrderType: options.onChainOrderType,
|
|
101
|
+
chainId: chainIdString,
|
|
102
|
+
status: statusString,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const fetchURL = `${baseUrl}${search}` as const;
|
|
106
|
+
|
|
107
|
+
return fetcher<PaginatedResponse<DeltaOrderV2Response>>({
|
|
108
|
+
url: fetchURL,
|
|
109
|
+
method: 'GET',
|
|
110
|
+
requestParams,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
getDeltaOrderByIdV2,
|
|
116
|
+
getDeltaOrderByHashV2,
|
|
117
|
+
getDeltaOrdersV2,
|
|
118
|
+
};
|
|
119
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { API_URL, SwapSide } from '../../constants';
|
|
2
|
+
import { constructSearchString } from '../../helpers/misc';
|
|
3
|
+
import type {
|
|
4
|
+
ConstructFetchInput,
|
|
5
|
+
EnumerateLiteral,
|
|
6
|
+
RequestParameters,
|
|
7
|
+
} from '../../types';
|
|
8
|
+
import type { DeltaPriceV2 } from './types';
|
|
9
|
+
|
|
10
|
+
type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
|
|
11
|
+
|
|
12
|
+
export type DeltaPriceV2Params = {
|
|
13
|
+
/** @description Source Token Address */
|
|
14
|
+
srcToken: string;
|
|
15
|
+
/** @description Destination Token Address. For Crosschain Orders, the destination token on the destination chain */
|
|
16
|
+
destToken: string;
|
|
17
|
+
/** @description srcToken amount in wei */
|
|
18
|
+
amount: string;
|
|
19
|
+
/** @description Source Token Decimals */
|
|
20
|
+
srcDecimals: number;
|
|
21
|
+
/** @description Destination Token Decimals */
|
|
22
|
+
destDecimals: number;
|
|
23
|
+
/** @description User's Wallet Address */
|
|
24
|
+
userAddress?: string;
|
|
25
|
+
/** @description Beneficiary Address */
|
|
26
|
+
beneficiary?: string;
|
|
27
|
+
/** @description Partner string. */
|
|
28
|
+
partner?: string;
|
|
29
|
+
/** @description Partner fee in basis points (bps), 50bps=0.5% */
|
|
30
|
+
partnerFeeBps?: number;
|
|
31
|
+
/** @description Destination Chain ID for Crosschain Orders */
|
|
32
|
+
destChainId?: number;
|
|
33
|
+
/** @description SELL or BUY, default is SELL */
|
|
34
|
+
side?: SwapSideUnion;
|
|
35
|
+
/** @description In %. Bypasses the API price impact check (default = 15%) */
|
|
36
|
+
maxImpact?: number;
|
|
37
|
+
maxUSDImpact?: number;
|
|
38
|
+
|
|
39
|
+
includeAgents?: string[];
|
|
40
|
+
excludeAgents?: string[];
|
|
41
|
+
includeBridges?: string[];
|
|
42
|
+
excludeBridges?: string[];
|
|
43
|
+
|
|
44
|
+
/** @description Allow swap on destChain after bridge. Default is true. */
|
|
45
|
+
allowBridgeAndSwap?: boolean;
|
|
46
|
+
degenMode?: boolean;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
type DeltaPriceV2QueryOptions = Omit<
|
|
50
|
+
DeltaPriceV2Params,
|
|
51
|
+
'includeAgents' | 'excludeAgents' | 'includeBridges' | 'excludeBridges'
|
|
52
|
+
> & {
|
|
53
|
+
chainId: number;
|
|
54
|
+
includeAgents?: string;
|
|
55
|
+
excludeAgents?: string;
|
|
56
|
+
includeBridges?: string;
|
|
57
|
+
excludeBridges?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type GetDeltaPriceV2 = (
|
|
61
|
+
options: DeltaPriceV2Params,
|
|
62
|
+
requestParams?: RequestParameters
|
|
63
|
+
) => Promise<DeltaPriceV2>;
|
|
64
|
+
|
|
65
|
+
export type GetDeltaPriceV2Functions = {
|
|
66
|
+
/** @description Fetch a v2 price quote (route-based response). */
|
|
67
|
+
getDeltaPriceV2: GetDeltaPriceV2;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export const constructGetDeltaPriceV2 = ({
|
|
71
|
+
apiURL = API_URL,
|
|
72
|
+
chainId,
|
|
73
|
+
fetcher,
|
|
74
|
+
}: ConstructFetchInput): GetDeltaPriceV2Functions => {
|
|
75
|
+
const pricesUrl = `${apiURL}/delta/v2/prices` as const;
|
|
76
|
+
|
|
77
|
+
const getDeltaPriceV2: GetDeltaPriceV2 = async (options, requestParams) => {
|
|
78
|
+
const {
|
|
79
|
+
includeAgents,
|
|
80
|
+
excludeAgents,
|
|
81
|
+
includeBridges,
|
|
82
|
+
excludeBridges,
|
|
83
|
+
...rest
|
|
84
|
+
} = options;
|
|
85
|
+
|
|
86
|
+
const search = constructSearchString<DeltaPriceV2QueryOptions>({
|
|
87
|
+
...rest,
|
|
88
|
+
chainId,
|
|
89
|
+
side: options.side ?? SwapSide.SELL,
|
|
90
|
+
includeAgents: includeAgents?.join(','),
|
|
91
|
+
excludeAgents: excludeAgents?.join(','),
|
|
92
|
+
includeBridges: includeBridges?.join(','),
|
|
93
|
+
excludeBridges: excludeBridges?.join(','),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const fetchURL = `${pricesUrl}${search}` as const;
|
|
97
|
+
|
|
98
|
+
const data = await fetcher<DeltaPriceV2>({
|
|
99
|
+
url: fetchURL,
|
|
100
|
+
method: 'GET',
|
|
101
|
+
requestParams,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return data;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return { getDeltaPriceV2 };
|
|
108
|
+
};
|