@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.
- package/README.md +0 -156
- package/dist/examples/helpers/delta.d.ts +1 -1
- package/dist/examples/helpers/delta.d.ts.map +1 -1
- package/dist/index.d.ts +3 -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 +17 -16
- package/dist/methods/delta/helpers/orders.d.ts.map +1 -1
- package/dist/methods/delta/helpers/types.d.ts +11 -56
- 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/sdk/full.d.ts +0 -2
- package/dist/sdk/full.d.ts.map +1 -1
- package/dist/sdk/simple.d.ts +0 -4
- package/dist/sdk/simple.d.ts.map +1 -1
- package/dist/sdk.cjs.development.js +402 -1539
- 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 +387 -1523
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types.d.ts +0 -8
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/examples/helpers/delta.ts +1 -6
- package/src/index.js +0 -55
- package/src/index.ts +0 -37
- package/src/methods/delta/cancelDeltaOrder.ts +1 -4
- package/src/methods/delta/getDeltaOrders.ts +5 -6
- package/src/methods/delta/getDeltaPrice.ts +1 -1
- package/src/methods/delta/helpers/orders.ts +20 -32
- package/src/methods/delta/helpers/types.ts +15 -60
- package/src/methods/delta/postDeltaOrder.ts +4 -4
- package/src/methods/delta/postTWAPDeltaOrder.ts +1 -1
- package/src/sdk/full.ts +0 -8
- package/src/sdk/simple.ts +0 -30
- package/src/types.ts +0 -9
- package/dist/examples/deltaV2.d.ts +0 -2
- package/dist/examples/deltaV2.d.ts.map +0 -1
- package/dist/examples/helpers/deltaV2.d.ts +0 -5
- package/dist/examples/helpers/deltaV2.d.ts.map +0 -1
- package/dist/methods/deltaV2/buildDeltaOrder.d.ts +0 -45
- package/dist/methods/deltaV2/buildDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/buildExternalDeltaOrder.d.ts +0 -49
- package/dist/methods/deltaV2/buildExternalDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/buildTWAPDeltaOrder.d.ts +0 -60
- package/dist/methods/deltaV2/buildTWAPDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/cancelDeltaOrder.d.ts +0 -21
- package/dist/methods/deltaV2/cancelDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/getAgentsList.d.ts +0 -10
- package/dist/methods/deltaV2/getAgentsList.d.ts.map +0 -1
- package/dist/methods/deltaV2/getBridgeRoutes.d.ts +0 -20
- package/dist/methods/deltaV2/getBridgeRoutes.d.ts.map +0 -1
- package/dist/methods/deltaV2/getDeltaOrders.d.ts +0 -40
- package/dist/methods/deltaV2/getDeltaOrders.d.ts.map +0 -1
- package/dist/methods/deltaV2/getDeltaPrice.d.ts +0 -46
- package/dist/methods/deltaV2/getDeltaPrice.d.ts.map +0 -1
- package/dist/methods/deltaV2/helpers/orders.d.ts +0 -191
- package/dist/methods/deltaV2/helpers/orders.d.ts.map +0 -1
- package/dist/methods/deltaV2/index.d.ts +0 -72
- package/dist/methods/deltaV2/index.d.ts.map +0 -1
- package/dist/methods/deltaV2/isTokenSupportedInDelta.d.ts +0 -8
- package/dist/methods/deltaV2/isTokenSupportedInDelta.d.ts.map +0 -1
- package/dist/methods/deltaV2/postDeltaOrder.d.ts +0 -29
- package/dist/methods/deltaV2/postDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/postExternalDeltaOrder.d.ts +0 -11
- package/dist/methods/deltaV2/postExternalDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/postTWAPDeltaOrder.d.ts +0 -17
- package/dist/methods/deltaV2/postTWAPDeltaOrder.d.ts.map +0 -1
- package/dist/methods/deltaV2/types.d.ts +0 -169
- package/dist/methods/deltaV2/types.d.ts.map +0 -1
- package/src/examples/deltaV2.ts +0 -196
- package/src/examples/helpers/deltaV2.ts +0 -34
- package/src/methods/deltaV2/buildDeltaOrder.ts +0 -86
- package/src/methods/deltaV2/buildExternalDeltaOrder.ts +0 -95
- package/src/methods/deltaV2/buildTWAPDeltaOrder.ts +0 -131
- package/src/methods/deltaV2/cancelDeltaOrder.ts +0 -100
- package/src/methods/deltaV2/getAgentsList.ts +0 -32
- package/src/methods/deltaV2/getBridgeRoutes.ts +0 -82
- package/src/methods/deltaV2/getDeltaOrders.ts +0 -149
- package/src/methods/deltaV2/getDeltaPrice.ts +0 -108
- package/src/methods/deltaV2/helpers/orders.ts +0 -363
- package/src/methods/deltaV2/index.ts +0 -312
- package/src/methods/deltaV2/isTokenSupportedInDelta.ts +0 -52
- package/src/methods/deltaV2/postDeltaOrder.ts +0 -62
- package/src/methods/deltaV2/postExternalDeltaOrder.ts +0 -45
- package/src/methods/deltaV2/postTWAPDeltaOrder.ts +0 -58
- package/src/methods/deltaV2/types.ts +0 -202
|
@@ -1,82 +0,0 @@
|
|
|
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 GetBridgeProtocols = (
|
|
27
|
-
requestParams?: RequestParameters
|
|
28
|
-
) => Promise<BridgeProtocolResponse[]>;
|
|
29
|
-
|
|
30
|
-
type BridgeProtocolsResponse = {
|
|
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 (unchanged from v1). */
|
|
38
|
-
getBridgeProtocols: GetBridgeProtocols;
|
|
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 getBridgeProtocols: GetBridgeProtocols = async (requestParams) => {
|
|
70
|
-
const fetchURL = `${deltaPricesUrl}/bridge-protocols` as const;
|
|
71
|
-
|
|
72
|
-
const data = await fetcher<BridgeProtocolsResponse>({
|
|
73
|
-
url: fetchURL,
|
|
74
|
-
method: 'GET',
|
|
75
|
-
requestParams,
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
return data.bridgeProtocols;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return { getBridgeRoutes, getBridgeProtocols };
|
|
82
|
-
};
|
|
@@ -1,149 +0,0 @@
|
|
|
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 { DeltaOrderType, OnChainOrderType } from '../delta/helpers/types';
|
|
10
|
-
import type { DeltaOrderStatus, DeltaAuction } from './types';
|
|
11
|
-
|
|
12
|
-
type GetDeltaOrderById = (
|
|
13
|
-
orderId: string,
|
|
14
|
-
requestParams?: RequestParameters
|
|
15
|
-
) => Promise<DeltaAuction>;
|
|
16
|
-
|
|
17
|
-
type GetDeltaOrderByHash = (
|
|
18
|
-
orderHash: string,
|
|
19
|
-
requestParams?: RequestParameters
|
|
20
|
-
) => Promise<DeltaAuction>;
|
|
21
|
-
|
|
22
|
-
type OrdersFilter = {
|
|
23
|
-
/** @description `order.owner` to fetch Delta Orders for. */
|
|
24
|
-
userAddress: Address;
|
|
25
|
-
/** @description Pagination option. Default 1. */
|
|
26
|
-
page?: number;
|
|
27
|
-
/** @description Pagination option. Default 100, max 1000. */
|
|
28
|
-
limit?: number;
|
|
29
|
-
/** @description Filter by chainId. Omitted = orders across all chains. */
|
|
30
|
-
chainId?: number[];
|
|
31
|
-
/** @description Filter by integrator-facing status. */
|
|
32
|
-
status?: DeltaOrderStatus[];
|
|
33
|
-
/** @description Filter by order type. MARKET or LIMIT. */
|
|
34
|
-
type?: DeltaOrderType;
|
|
35
|
-
/** @description Filter by on-chain order type. */
|
|
36
|
-
onChainOrderType?: OnChainOrderType;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
type OrderFiltersQuery = Omit<OrdersFilter, 'chainId' | 'status'> & {
|
|
40
|
-
chainId?: string;
|
|
41
|
-
status?: string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type GetDeltaOrders = (
|
|
45
|
-
options: OrdersFilter,
|
|
46
|
-
requestParams?: RequestParameters
|
|
47
|
-
) => Promise<PaginatedResponse<DeltaAuction>>;
|
|
48
|
-
|
|
49
|
-
type GetRequiredBalanceParams = {
|
|
50
|
-
userAddress: Address;
|
|
51
|
-
tokenAddress?: Address;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type GetRequiredBalance = (
|
|
55
|
-
userParams: GetRequiredBalanceParams,
|
|
56
|
-
requestParams?: RequestParameters
|
|
57
|
-
) => Promise<Record<string, string>>; // token -> required balance across open Delta orders
|
|
58
|
-
|
|
59
|
-
export type GetDeltaOrdersFunctions = {
|
|
60
|
-
/** @description Fetch a single order by its UUID. */
|
|
61
|
-
getDeltaOrderById: GetDeltaOrderById;
|
|
62
|
-
/** @description Fetch a single order by its EIP-712 order hash. */
|
|
63
|
-
getDeltaOrderByHash: GetDeltaOrderByHash;
|
|
64
|
-
/** @description List Delta orders with the v2 pagination envelope. */
|
|
65
|
-
getDeltaOrders: GetDeltaOrders;
|
|
66
|
-
/** @description Required balance per token across the user's open Delta v2 orders. Pass `tokenAddress` to narrow the result to a single token. */
|
|
67
|
-
getRequiredBalanceForDeltaOrders: GetRequiredBalance;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const constructGetDeltaOrders = ({
|
|
71
|
-
apiURL = API_URL,
|
|
72
|
-
fetcher,
|
|
73
|
-
chainId,
|
|
74
|
-
}: ConstructFetchInput): GetDeltaOrdersFunctions => {
|
|
75
|
-
const baseUrl = `${apiURL}/delta/v2/orders` as const;
|
|
76
|
-
|
|
77
|
-
const getDeltaOrderById: GetDeltaOrderById = async (
|
|
78
|
-
orderId,
|
|
79
|
-
requestParams
|
|
80
|
-
) => {
|
|
81
|
-
const fetchURL = `${baseUrl}/${orderId}` as const;
|
|
82
|
-
return fetcher<DeltaAuction>({
|
|
83
|
-
url: fetchURL,
|
|
84
|
-
method: 'GET',
|
|
85
|
-
requestParams,
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const getDeltaOrderByHash: GetDeltaOrderByHash = async (
|
|
90
|
-
orderHash,
|
|
91
|
-
requestParams
|
|
92
|
-
) => {
|
|
93
|
-
const fetchURL = `${baseUrl}/hash/${orderHash}` as const;
|
|
94
|
-
return fetcher<DeltaAuction>({
|
|
95
|
-
url: fetchURL,
|
|
96
|
-
method: 'GET',
|
|
97
|
-
requestParams,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const getDeltaOrders: GetDeltaOrders = async (options, requestParams) => {
|
|
102
|
-
const chainIdString = options.chainId?.join(',');
|
|
103
|
-
const statusString = options.status?.join(',');
|
|
104
|
-
|
|
105
|
-
const search = constructSearchString<OrderFiltersQuery>({
|
|
106
|
-
userAddress: options.userAddress,
|
|
107
|
-
page: options.page,
|
|
108
|
-
limit: options.limit,
|
|
109
|
-
type: options.type,
|
|
110
|
-
onChainOrderType: options.onChainOrderType,
|
|
111
|
-
chainId: chainIdString,
|
|
112
|
-
status: statusString,
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const fetchURL = `${baseUrl}${search}` as const;
|
|
116
|
-
|
|
117
|
-
return fetcher<PaginatedResponse<DeltaAuction>>({
|
|
118
|
-
url: fetchURL,
|
|
119
|
-
method: 'GET',
|
|
120
|
-
requestParams,
|
|
121
|
-
});
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const getRequiredBalanceForDeltaOrders: GetRequiredBalance = async (
|
|
125
|
-
userParams,
|
|
126
|
-
requestParams
|
|
127
|
-
) => {
|
|
128
|
-
const userURL =
|
|
129
|
-
`${baseUrl}/fillablebalance/${chainId}/${userParams.userAddress}` as const;
|
|
130
|
-
const fetchURL = userParams.tokenAddress
|
|
131
|
-
? (`${userURL}/${userParams.tokenAddress}` as const)
|
|
132
|
-
: userURL;
|
|
133
|
-
|
|
134
|
-
const response = await fetcher<Record<string, string>>({
|
|
135
|
-
url: fetchURL,
|
|
136
|
-
method: 'GET',
|
|
137
|
-
requestParams,
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
return response;
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
getDeltaOrderById,
|
|
145
|
-
getDeltaOrderByHash,
|
|
146
|
-
getDeltaOrders,
|
|
147
|
-
getRequiredBalanceForDeltaOrders,
|
|
148
|
-
};
|
|
149
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
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 { DeltaPrice } from './types';
|
|
9
|
-
|
|
10
|
-
type SwapSideUnion = EnumerateLiteral<typeof SwapSide>;
|
|
11
|
-
|
|
12
|
-
export type DeltaPriceParams = {
|
|
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 DeltaPriceQueryOptions = Omit<
|
|
50
|
-
DeltaPriceParams,
|
|
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 GetDeltaPrice = (
|
|
61
|
-
options: DeltaPriceParams,
|
|
62
|
-
requestParams?: RequestParameters
|
|
63
|
-
) => Promise<DeltaPrice>;
|
|
64
|
-
|
|
65
|
-
export type GetDeltaPriceFunctions = {
|
|
66
|
-
/** @description Fetch a v2 price quote (route-based response). */
|
|
67
|
-
getDeltaPrice: GetDeltaPrice;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const constructGetDeltaPrice = ({
|
|
71
|
-
apiURL = API_URL,
|
|
72
|
-
chainId,
|
|
73
|
-
fetcher,
|
|
74
|
-
}: ConstructFetchInput): GetDeltaPriceFunctions => {
|
|
75
|
-
const pricesUrl = `${apiURL}/delta/v2/prices` as const;
|
|
76
|
-
|
|
77
|
-
const getDeltaPrice: GetDeltaPrice = async (options, requestParams) => {
|
|
78
|
-
const {
|
|
79
|
-
includeAgents,
|
|
80
|
-
excludeAgents,
|
|
81
|
-
includeBridges,
|
|
82
|
-
excludeBridges,
|
|
83
|
-
...rest
|
|
84
|
-
} = options;
|
|
85
|
-
|
|
86
|
-
const search = constructSearchString<DeltaPriceQueryOptions>({
|
|
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<DeltaPrice>({
|
|
99
|
-
url: fetchURL,
|
|
100
|
-
method: 'GET',
|
|
101
|
-
requestParams,
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
return data;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
return { getDeltaPrice };
|
|
108
|
-
};
|
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
import type { NonEmptyArray } from 'ts-essentials';
|
|
2
|
-
import { OrderHelpers as DeltaV1OrderHelpers } from '../../delta/helpers/orders';
|
|
3
|
-
import type {
|
|
4
|
-
SwapSideUnion,
|
|
5
|
-
UnifiedDeltaOrderData,
|
|
6
|
-
} from '../../delta/helpers/types';
|
|
7
|
-
import type {
|
|
8
|
-
DeltaAuction,
|
|
9
|
-
DeltaOrderStatus,
|
|
10
|
-
DeltaTokenSide,
|
|
11
|
-
DeltaTransaction,
|
|
12
|
-
} from '../types';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* v2 order helpers.
|
|
16
|
-
*
|
|
17
|
-
* The on-chain order structs (`auction.order`) are identical between v1 and v2
|
|
18
|
-
* — they come from the same `OnChainOrderMap` — so every order-struct guard and
|
|
19
|
-
* order-level getter is reused directly from v1's `OrderHelpers`. Likewise the
|
|
20
|
-
* auction discriminant guards only look at `onChainOrderType` (same union in
|
|
21
|
-
* both versions), so those are reused too.
|
|
22
|
-
*
|
|
23
|
-
* What differs in v2 is the *auction* envelope:
|
|
24
|
-
* - `status` is the integrator-facing `DeltaOrderStatus`
|
|
25
|
-
* (PENDING/ACTIVE/COMPLETED/… — not v1's `DeltaAuctionStatus`),
|
|
26
|
-
* - amounts live on `input`/`output` (`DeltaTokenSide`) and `transactions`
|
|
27
|
-
* (`DeltaTransaction`) instead of v1's order/transaction shapes,
|
|
28
|
-
* - `side` is carried explicitly on the auction.
|
|
29
|
-
*
|
|
30
|
-
* Those pieces are reimplemented here against the v2 shapes.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
const v1Checks = DeltaV1OrderHelpers.checks;
|
|
34
|
-
const v1Getters = DeltaV1OrderHelpers.getters;
|
|
35
|
-
|
|
36
|
-
///// CHECKS //////
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @description Checks whether an auction is fully executed (settled on every chain).
|
|
40
|
-
*/
|
|
41
|
-
function isCompletedAuction<T extends Pick<DeltaAuction, 'status'>>(
|
|
42
|
-
auction: T
|
|
43
|
-
): auction is T & { status: 'COMPLETED' } {
|
|
44
|
-
return auction.status === 'COMPLETED';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const failedAuctionStatuses = [
|
|
48
|
-
'FAILED',
|
|
49
|
-
'EXPIRED',
|
|
50
|
-
'CANCELLED',
|
|
51
|
-
'REFUNDED',
|
|
52
|
-
] as const;
|
|
53
|
-
|
|
54
|
-
const failedAuctionStatusesSet = new Set<DeltaOrderStatus>(
|
|
55
|
-
failedAuctionStatuses
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @description Checks whether an auction is in a terminal failure state
|
|
60
|
-
* (failed, expired, cancelled, or refunded).
|
|
61
|
-
*/
|
|
62
|
-
function isFailedAuction<T extends Pick<DeltaAuction, 'status'>>(
|
|
63
|
-
auction: T
|
|
64
|
-
): auction is T & { status: (typeof failedAuctionStatuses)[number] } {
|
|
65
|
-
return failedAuctionStatusesSet.has(auction.status);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @description Checks whether an auction status is cancelled.
|
|
70
|
-
*/
|
|
71
|
-
function isCanceledAuction<T extends Pick<DeltaAuction, 'status'>>(
|
|
72
|
-
auction: T
|
|
73
|
-
): auction is T & { status: 'CANCELLED' } {
|
|
74
|
-
return auction.status === 'CANCELLED';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* @description Checks whether an auction status is expired.
|
|
79
|
-
*/
|
|
80
|
-
function isExpiredAuction<T extends Pick<DeltaAuction, 'status'>>(
|
|
81
|
-
auction: T
|
|
82
|
-
): auction is T & { status: 'EXPIRED' } {
|
|
83
|
-
return auction.status === 'EXPIRED';
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const pendingAuctionStatuses = [
|
|
87
|
-
'PENDING',
|
|
88
|
-
'AWAITING_SIGNATURE',
|
|
89
|
-
'ACTIVE',
|
|
90
|
-
'BRIDGING',
|
|
91
|
-
] as const;
|
|
92
|
-
|
|
93
|
-
const pendingAuctionStatusesSet = new Set<DeltaOrderStatus>(
|
|
94
|
-
pendingAuctionStatuses
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @description Checks whether an auction is still in flight (not yet settled
|
|
99
|
-
* and not failed): awaiting signature, pending, actively executing, or bridging.
|
|
100
|
-
*/
|
|
101
|
-
function isPendingAuction<T extends Pick<DeltaAuction, 'status'>>(
|
|
102
|
-
auction: T
|
|
103
|
-
): auction is T & { status: (typeof pendingAuctionStatuses)[number] } {
|
|
104
|
-
return pendingAuctionStatusesSet.has(auction.status);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @description Checks whether an auction is a Fillable auction.
|
|
109
|
-
* `FillableOrder` is the `onChainOrderType` the server reports for a
|
|
110
|
-
* `partiallyFillable` Standard order; it carries the same order struct as
|
|
111
|
-
* `Order`. Consumers that don't distinguish the two should treat
|
|
112
|
-
* `isDeltaAuction(a) || isFillableAuction(a)` as "is a standard order".
|
|
113
|
-
*/
|
|
114
|
-
function isFillableAuction<T extends Pick<DeltaAuction, 'onChainOrderType'>>(
|
|
115
|
-
auction: T
|
|
116
|
-
): auction is T & { onChainOrderType: 'FillableOrder' } {
|
|
117
|
-
return auction.onChainOrderType === 'FillableOrder';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* @description Checks whether an auction has been partially executed:
|
|
122
|
-
* it has at least one transaction and an overall filled percent strictly
|
|
123
|
-
* between 0 and 100.
|
|
124
|
-
*/
|
|
125
|
-
function isPartiallyExecutedAuction<
|
|
126
|
-
T extends Pick<DeltaAuction, 'order' | 'transactions'>,
|
|
127
|
-
>(
|
|
128
|
-
auction: T
|
|
129
|
-
): auction is T & { transactions: NonEmptyArray<DeltaTransaction> } {
|
|
130
|
-
if (auction.transactions.length === 0) return false;
|
|
131
|
-
|
|
132
|
-
const filledPercent = getFilledPercent(auction);
|
|
133
|
-
|
|
134
|
-
return filledPercent > 0 && filledPercent < 100;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const checks = {
|
|
138
|
-
// order-struct guards — order structs are shared with v1, reused as-is.
|
|
139
|
-
isTWAPOrder: v1Checks.isTWAPOrder,
|
|
140
|
-
isTWAPSellOrder: v1Checks.isTWAPSellOrder,
|
|
141
|
-
isTWAPBuyOrder: v1Checks.isTWAPBuyOrder,
|
|
142
|
-
isExternalOrder: v1Checks.isExternalOrder,
|
|
143
|
-
isDeltaOrder: v1Checks.isDeltaOrder,
|
|
144
|
-
isProductiveOrder: v1Checks.isProductiveOrder,
|
|
145
|
-
|
|
146
|
-
// auction discriminant guards — `onChainOrderType` union is shared, reused as-is.
|
|
147
|
-
isTWAPAuction: v1Checks.isTWAPAuction,
|
|
148
|
-
isTWAPSellAuction: v1Checks.isTWAPSellAuction,
|
|
149
|
-
isTWAPBuyAuction: v1Checks.isTWAPBuyAuction,
|
|
150
|
-
isDeltaAuction: v1Checks.isDeltaAuction,
|
|
151
|
-
isExternalAuction: v1Checks.isExternalAuction,
|
|
152
|
-
isProductiveAuction: v1Checks.isProductiveAuction,
|
|
153
|
-
isFillableAuction,
|
|
154
|
-
|
|
155
|
-
// status / execution guards — v2 status enum & transaction shape.
|
|
156
|
-
isCompletedAuction,
|
|
157
|
-
isFailedAuction,
|
|
158
|
-
isCanceledAuction,
|
|
159
|
-
isExpiredAuction,
|
|
160
|
-
isPendingAuction,
|
|
161
|
-
isPartiallyExecutedAuction,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
///// GETTERS //////
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* @description Reads an amount off a v2 token side. A SELL input / BUY output
|
|
168
|
-
* carries an explicit `amount`; the opposite side carries
|
|
169
|
-
* `expectedAmount`/`executedAmount`. `prefer` chooses which to read on the
|
|
170
|
-
* expected/executed variant.
|
|
171
|
-
*/
|
|
172
|
-
function getTokenSideAmount(
|
|
173
|
-
side: DeltaTokenSide,
|
|
174
|
-
prefer: 'expected' | 'executed'
|
|
175
|
-
): string {
|
|
176
|
-
if ('amount' in side) return side.amount;
|
|
177
|
-
|
|
178
|
-
const value =
|
|
179
|
-
prefer === 'executed' ? side.executedAmount : side.expectedAmount;
|
|
180
|
-
|
|
181
|
-
return value ?? '0';
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* @description Returns the source chain id for the auction (the input side's chain).
|
|
186
|
-
*/
|
|
187
|
-
function getAuctionSrcChainId(auction: Pick<DeltaAuction, 'input'>): number {
|
|
188
|
-
return auction.input.chainId;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* @description Returns the destination chain id for the auction (the output side's chain).
|
|
193
|
-
* Equals the source chain id for same-chain orders.
|
|
194
|
-
*/
|
|
195
|
-
function getAuctionDestChainId(auction: Pick<DeltaAuction, 'output'>): number {
|
|
196
|
-
return auction.output.chainId;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @description Returns the swap side for any auction. v2 carries `side` on the
|
|
201
|
-
* auction directly, so no order introspection is needed.
|
|
202
|
-
*/
|
|
203
|
-
function getAuctionSwapSide(
|
|
204
|
-
auction: Pick<DeltaAuction, 'side'>
|
|
205
|
-
): SwapSideUnion {
|
|
206
|
-
return auction.side;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* @description Returns source and destination token addresses for the auction,
|
|
211
|
-
* read from the input/output sides (already resolved to the dest-chain token
|
|
212
|
-
* for cross-chain orders).
|
|
213
|
-
*/
|
|
214
|
-
function getAuctionTokenAddresses(
|
|
215
|
-
auction: Pick<DeltaAuction, 'input' | 'output'>
|
|
216
|
-
) {
|
|
217
|
-
return {
|
|
218
|
-
srcToken: auction.input.token,
|
|
219
|
-
destToken: auction.output.token,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* @description Aggregates transaction amounts into total spent (src) and
|
|
225
|
-
* received (dest) values.
|
|
226
|
-
*/
|
|
227
|
-
function getTransactionAmounts(transactions: DeltaTransaction[]) {
|
|
228
|
-
const { srcAmount, destAmount } = transactions.reduce(
|
|
229
|
-
(acc, { spentAmount, receivedAmount }) => ({
|
|
230
|
-
srcAmount: acc.srcAmount + BigInt(spentAmount ?? 0),
|
|
231
|
-
destAmount: acc.destAmount + BigInt(receivedAmount ?? 0),
|
|
232
|
-
}),
|
|
233
|
-
{ srcAmount: 0n, destAmount: 0n }
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
return {
|
|
237
|
-
srcAmount: srcAmount.toString(),
|
|
238
|
-
destAmount: destAmount.toString(),
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* @description Calculates the overall filled percent (0–100) from the
|
|
244
|
-
* per-transaction `filledPercent` values. For TWAP orders each transaction is
|
|
245
|
-
* a slice (0–100 of that slice), so the slice values are averaged across
|
|
246
|
-
* `numSlices`; for single-fill orders the values sum directly.
|
|
247
|
-
*/
|
|
248
|
-
function getFilledPercent(
|
|
249
|
-
auction: Pick<DeltaAuction, 'order' | 'transactions'>
|
|
250
|
-
): number {
|
|
251
|
-
if (auction.transactions.length === 0) return 0;
|
|
252
|
-
|
|
253
|
-
const total = auction.transactions.reduce(
|
|
254
|
-
(acc, { filledPercent }) => acc + filledPercent,
|
|
255
|
-
0
|
|
256
|
-
);
|
|
257
|
-
|
|
258
|
-
if (checks.isTWAPOrder(auction.order) && auction.order.numSlices > 0) {
|
|
259
|
-
return total / auction.order.numSlices;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return total;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* @description Returns expected amounts and, once the auction is completed,
|
|
267
|
-
* executed amounts. Executed amounts prefer the `executedAmount` baked onto the
|
|
268
|
-
* token sides and fall back to summing transactions.
|
|
269
|
-
*/
|
|
270
|
-
function getAuctionAmounts(
|
|
271
|
-
auction: Pick<
|
|
272
|
-
DeltaAuction,
|
|
273
|
-
'status' | 'order' | 'input' | 'output' | 'transactions'
|
|
274
|
-
>
|
|
275
|
-
) {
|
|
276
|
-
const expected = {
|
|
277
|
-
srcAmount: getTokenSideAmount(auction.input, 'expected'),
|
|
278
|
-
destAmount: getTokenSideAmount(auction.output, 'expected'),
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
if (!isCompletedAuction(auction)) {
|
|
282
|
-
return { expected };
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const txAmounts = getTransactionAmounts(auction.transactions);
|
|
286
|
-
|
|
287
|
-
const executed = {
|
|
288
|
-
srcAmount: getExecutedAmount(auction.input, txAmounts.srcAmount),
|
|
289
|
-
destAmount: getExecutedAmount(auction.output, txAmounts.destAmount),
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
return { expected, executed };
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* @description Returns the executed amount of a token side when present,
|
|
297
|
-
* otherwise the provided fallback (typically summed from transactions).
|
|
298
|
-
*/
|
|
299
|
-
function getExecutedAmount(side: DeltaTokenSide, fallback: string): string {
|
|
300
|
-
if ('executedAmount' in side && side.executedAmount != null) {
|
|
301
|
-
return side.executedAmount;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
return fallback;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* @description Returns unified order data with normalized amounts, tokens,
|
|
309
|
-
* chain ids, and side — the v2 counterpart of v1's `getUnifiedDeltaOrderData`,
|
|
310
|
-
* built from the v2 auction envelope.
|
|
311
|
-
*/
|
|
312
|
-
function getUnifiedDeltaOrderData(
|
|
313
|
-
auction: DeltaAuction
|
|
314
|
-
): UnifiedDeltaOrderData {
|
|
315
|
-
const { srcToken, destToken } = getAuctionTokenAddresses(auction);
|
|
316
|
-
const { expected, executed } = getAuctionAmounts(auction);
|
|
317
|
-
|
|
318
|
-
const srcChainId = getAuctionSrcChainId(auction);
|
|
319
|
-
const destChainId = getAuctionDestChainId(auction);
|
|
320
|
-
const swapSide = getAuctionSwapSide(auction);
|
|
321
|
-
const filledPercent = getFilledPercent(auction);
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
srcChainId,
|
|
325
|
-
destChainId,
|
|
326
|
-
srcAmount: executed?.srcAmount || expected.srcAmount,
|
|
327
|
-
destAmount: executed?.destAmount || expected.destAmount,
|
|
328
|
-
amounts: {
|
|
329
|
-
expected,
|
|
330
|
-
final: executed,
|
|
331
|
-
},
|
|
332
|
-
srcToken,
|
|
333
|
-
destToken,
|
|
334
|
-
swapSide,
|
|
335
|
-
filledPercent,
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const getters = {
|
|
340
|
-
getUnifiedDeltaOrderData,
|
|
341
|
-
|
|
342
|
-
// auction-level getters — v2 envelope shape.
|
|
343
|
-
getAuctionTokenAddresses,
|
|
344
|
-
getAuctionSrcChainId,
|
|
345
|
-
getAuctionDestChainId,
|
|
346
|
-
getAuctionSwapSide,
|
|
347
|
-
getTransactionAmounts,
|
|
348
|
-
getAuctionAmounts,
|
|
349
|
-
getFilledPercent,
|
|
350
|
-
|
|
351
|
-
// order-level getters — order structs are shared with v1, reused as-is.
|
|
352
|
-
getOrderTokenAddresses: v1Getters.getOrderTokenAddresses,
|
|
353
|
-
getSwapSideFromDeltaOrder: v1Getters.getSwapSideFromDeltaOrder,
|
|
354
|
-
getSwapSideFromTwapOrderType: v1Getters.getSwapSideFromTwapOrderType,
|
|
355
|
-
getExpectedTwapSrcAmount: v1Getters.getExpectedTwapSrcAmount,
|
|
356
|
-
getExpectedTwapDestAmount: v1Getters.getExpectedTwapDestAmount,
|
|
357
|
-
getExpectedTwapOrderAmounts: v1Getters.getExpectedTwapOrderAmounts,
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
export const OrderHelpers = {
|
|
361
|
-
checks,
|
|
362
|
-
getters,
|
|
363
|
-
};
|