@nadohq/trigger-client 0.1.0-alpha.3 → 0.1.0-alpha.31
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/dist/TriggerClient.cjs +74 -34
- package/dist/TriggerClient.cjs.map +1 -1
- package/dist/TriggerClient.d.cts +8 -4
- package/dist/TriggerClient.d.ts +8 -4
- package/dist/TriggerClient.js +73 -28
- package/dist/TriggerClient.js.map +1 -1
- package/dist/dataMappers.cjs +170 -67
- package/dist/dataMappers.cjs.map +1 -1
- package/dist/dataMappers.d.cts +22 -8
- package/dist/dataMappers.d.ts +22 -8
- package/dist/dataMappers.js +171 -66
- package/dist/dataMappers.js.map +1 -1
- package/dist/endpoints.cjs +2 -2
- package/dist/endpoints.cjs.map +1 -1
- package/dist/endpoints.d.cts +1 -1
- package/dist/endpoints.d.ts +1 -1
- package/dist/endpoints.js +2 -2
- package/dist/endpoints.js.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/types/TriggerServerFailureError.cjs +1 -1
- package/dist/types/TriggerServerFailureError.cjs.map +1 -1
- package/dist/types/TriggerServerFailureError.d.cts +3 -2
- package/dist/types/TriggerServerFailureError.d.ts +3 -2
- package/dist/types/TriggerServerFailureError.js +1 -1
- package/dist/types/TriggerServerFailureError.js.map +1 -1
- package/dist/types/clientModelTypes.cjs +19 -0
- package/dist/types/clientModelTypes.cjs.map +1 -0
- package/dist/types/clientModelTypes.d.cts +67 -0
- package/dist/types/clientModelTypes.d.ts +67 -0
- package/dist/types/clientModelTypes.js +1 -0
- package/dist/types/clientModelTypes.js.map +1 -0
- package/dist/types/clientTypes.cjs.map +1 -1
- package/dist/types/clientTypes.d.cts +50 -24
- package/dist/types/clientTypes.d.ts +50 -24
- package/dist/types/index.cjs +4 -0
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +6 -5
- package/dist/types/index.d.ts +6 -5
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +9 -15
- package/dist/types/serverExecuteTypes.d.ts +9 -15
- package/dist/types/serverModelTypes.cjs +19 -0
- package/dist/types/serverModelTypes.cjs.map +1 -0
- package/dist/types/serverModelTypes.d.cts +42 -0
- package/dist/types/serverModelTypes.d.ts +42 -0
- package/dist/types/serverModelTypes.js +1 -0
- package/dist/types/serverModelTypes.js.map +1 -0
- package/dist/types/serverQueryTypes.cjs.map +1 -1
- package/dist/types/serverQueryTypes.d.cts +48 -7
- package/dist/types/serverQueryTypes.d.ts +48 -7
- package/package.json +4 -5
- package/src/TriggerClient.ts +90 -29
- package/src/dataMappers.ts +225 -71
- package/src/endpoints.ts +2 -2
- package/src/index.ts +2 -2
- package/src/types/TriggerServerFailureError.ts +2 -2
- package/src/types/clientModelTypes.ts +95 -0
- package/src/types/clientTypes.ts +70 -41
- package/src/types/index.ts +2 -0
- package/src/types/serverExecuteTypes.ts +9 -24
- package/src/types/serverModelTypes.ts +55 -0
- package/src/types/serverQueryTypes.ts +75 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/serverQueryTypes.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/types/serverQueryTypes.ts"],"sourcesContent":["import { EngineServerExecuteResult } from '@nadohq/engine-client';\nimport { EIP712ListTriggerOrdersValues, SignedTx } from '@nadohq/shared';\nimport { TriggerServerPlaceOrderParams } from './serverExecuteTypes';\n\nexport type TriggerServerOrderStatus =\n | {\n cancelled: TriggerServerCancelReason;\n }\n | {\n triggered: EngineServerExecuteResult;\n }\n | {\n internal_error: string;\n }\n | 'triggering'\n | 'waiting_price'\n | 'waiting_dependency'\n | {\n twap_executing: {\n current_execution: number;\n total_executions: number;\n };\n }\n | {\n twap_completed: {\n executed: number;\n total: number;\n };\n };\n\n/**\n * Request types\n */\n\nexport type TriggerServerTriggerTypeFilter = 'price_trigger' | 'time_trigger';\n\nexport type TriggerServerStatusTypeFilter =\n | 'cancelled'\n | 'triggered'\n | 'internal_error'\n | 'triggering'\n | 'waiting_price'\n | 'waiting_dependency'\n | 'twap_executing'\n | 'twap_completed';\n\nexport interface TriggerServerListTriggerOrdersParams\n extends SignedTx<EIP712ListTriggerOrdersValues> {\n // If not given, defaults to all products\n product_ids?: number[];\n max_update_time?: number;\n digests?: string[];\n limit?: number;\n trigger_types?: TriggerServerTriggerTypeFilter[];\n status_types?: TriggerServerStatusTypeFilter[];\n reduce_only?: boolean;\n}\n\nexport interface TriggerServerListTwapExecutionsParams {\n digest: string;\n}\n\nexport interface TriggerServerQueryRequestByType {\n list_trigger_orders: TriggerServerListTriggerOrdersParams;\n list_twap_executions: TriggerServerListTwapExecutionsParams;\n}\n\nexport type TriggerServerQueryRequestType =\n keyof TriggerServerQueryRequestByType;\n\n/**\n * Response types\n */\n\nexport type TriggerServerOrder = TriggerServerPlaceOrderParams & {\n // Digest is always populated here\n digest: string;\n};\n\nexport interface TriggerServerOrderInfo {\n order: TriggerServerOrder;\n status: TriggerServerOrderStatus;\n updated_at: number;\n placed_at: number;\n}\n\nexport interface TriggerServerListTriggerOrdersResponse {\n orders: TriggerServerOrderInfo[];\n}\n\nexport type TriggerServerCancelReason =\n | 'user_requested'\n | 'linked_signer_changed'\n | 'expired'\n | 'account_health'\n | 'isolated_subaccount_closed'\n | 'dependent_order_cancelled';\n\nexport type TriggerServerTwapExecutionStatus =\n | 'pending'\n | {\n executed: {\n executed_time: number;\n execute_response: EngineServerExecuteResult;\n };\n }\n | {\n failed: string;\n }\n | {\n cancelled: TriggerServerCancelReason;\n };\n\nexport interface TriggerServerTwapExecutionInfo {\n execution_id: number;\n scheduled_time: number;\n status: TriggerServerTwapExecutionStatus;\n updated_at: number;\n}\n\nexport interface TriggerServerTwapExecutionsResponse {\n executions: TriggerServerTwapExecutionInfo[];\n}\n\nexport interface TriggerServerQueryResponseByType {\n list_trigger_orders: TriggerServerListTriggerOrdersResponse;\n list_twap_executions: TriggerServerTwapExecutionsResponse;\n}\n\nexport interface TriggerServerQuerySuccessResponse<\n TQueryType extends\n keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType,\n> {\n status: 'success';\n data: TriggerServerQueryResponseByType[TQueryType];\n}\n\nexport interface TriggerServerQueryFailureResponse {\n status: 'failure';\n error: string;\n error_code: number;\n}\n\nexport type TriggerServerQueryResponse<\n TQueryType extends\n keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType,\n> =\n | TriggerServerQuerySuccessResponse<TQueryType>\n | TriggerServerQueryFailureResponse;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -1,26 +1,45 @@
|
|
|
1
|
-
import { SignedTx, EIP712ListTriggerOrdersValues } from '@nadohq/contracts';
|
|
2
1
|
import { EngineServerExecuteResult } from '@nadohq/engine-client';
|
|
2
|
+
import { SignedTx, EIP712ListTriggerOrdersValues } from '@nadohq/shared';
|
|
3
3
|
import { TriggerServerPlaceOrderParams } from './serverExecuteTypes.cjs';
|
|
4
|
+
import './serverModelTypes.cjs';
|
|
4
5
|
|
|
5
|
-
type TriggerServerOrderStatus =
|
|
6
|
-
|
|
6
|
+
type TriggerServerOrderStatus = {
|
|
7
|
+
cancelled: TriggerServerCancelReason;
|
|
7
8
|
} | {
|
|
8
|
-
|
|
9
|
+
triggered: EngineServerExecuteResult;
|
|
9
10
|
} | {
|
|
10
11
|
internal_error: string;
|
|
12
|
+
} | 'triggering' | 'waiting_price' | 'waiting_dependency' | {
|
|
13
|
+
twap_executing: {
|
|
14
|
+
current_execution: number;
|
|
15
|
+
total_executions: number;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
twap_completed: {
|
|
19
|
+
executed: number;
|
|
20
|
+
total: number;
|
|
21
|
+
};
|
|
11
22
|
};
|
|
12
23
|
/**
|
|
13
24
|
* Request types
|
|
14
25
|
*/
|
|
26
|
+
type TriggerServerTriggerTypeFilter = 'price_trigger' | 'time_trigger';
|
|
27
|
+
type TriggerServerStatusTypeFilter = 'cancelled' | 'triggered' | 'internal_error' | 'triggering' | 'waiting_price' | 'waiting_dependency' | 'twap_executing' | 'twap_completed';
|
|
15
28
|
interface TriggerServerListTriggerOrdersParams extends SignedTx<EIP712ListTriggerOrdersValues> {
|
|
16
|
-
|
|
17
|
-
product_id?: number;
|
|
29
|
+
product_ids?: number[];
|
|
18
30
|
max_update_time?: number;
|
|
19
31
|
digests?: string[];
|
|
20
32
|
limit?: number;
|
|
33
|
+
trigger_types?: TriggerServerTriggerTypeFilter[];
|
|
34
|
+
status_types?: TriggerServerStatusTypeFilter[];
|
|
35
|
+
reduce_only?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface TriggerServerListTwapExecutionsParams {
|
|
38
|
+
digest: string;
|
|
21
39
|
}
|
|
22
40
|
interface TriggerServerQueryRequestByType {
|
|
23
41
|
list_trigger_orders: TriggerServerListTriggerOrdersParams;
|
|
42
|
+
list_twap_executions: TriggerServerListTwapExecutionsParams;
|
|
24
43
|
}
|
|
25
44
|
type TriggerServerQueryRequestType = keyof TriggerServerQueryRequestByType;
|
|
26
45
|
/**
|
|
@@ -33,12 +52,34 @@ interface TriggerServerOrderInfo {
|
|
|
33
52
|
order: TriggerServerOrder;
|
|
34
53
|
status: TriggerServerOrderStatus;
|
|
35
54
|
updated_at: number;
|
|
55
|
+
placed_at: number;
|
|
36
56
|
}
|
|
37
57
|
interface TriggerServerListTriggerOrdersResponse {
|
|
38
58
|
orders: TriggerServerOrderInfo[];
|
|
39
59
|
}
|
|
60
|
+
type TriggerServerCancelReason = 'user_requested' | 'linked_signer_changed' | 'expired' | 'account_health' | 'isolated_subaccount_closed' | 'dependent_order_cancelled';
|
|
61
|
+
type TriggerServerTwapExecutionStatus = 'pending' | {
|
|
62
|
+
executed: {
|
|
63
|
+
executed_time: number;
|
|
64
|
+
execute_response: EngineServerExecuteResult;
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
failed: string;
|
|
68
|
+
} | {
|
|
69
|
+
cancelled: TriggerServerCancelReason;
|
|
70
|
+
};
|
|
71
|
+
interface TriggerServerTwapExecutionInfo {
|
|
72
|
+
execution_id: number;
|
|
73
|
+
scheduled_time: number;
|
|
74
|
+
status: TriggerServerTwapExecutionStatus;
|
|
75
|
+
updated_at: number;
|
|
76
|
+
}
|
|
77
|
+
interface TriggerServerTwapExecutionsResponse {
|
|
78
|
+
executions: TriggerServerTwapExecutionInfo[];
|
|
79
|
+
}
|
|
40
80
|
interface TriggerServerQueryResponseByType {
|
|
41
81
|
list_trigger_orders: TriggerServerListTriggerOrdersResponse;
|
|
82
|
+
list_twap_executions: TriggerServerTwapExecutionsResponse;
|
|
42
83
|
}
|
|
43
84
|
interface TriggerServerQuerySuccessResponse<TQueryType extends keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType> {
|
|
44
85
|
status: 'success';
|
|
@@ -51,4 +92,4 @@ interface TriggerServerQueryFailureResponse {
|
|
|
51
92
|
}
|
|
52
93
|
type TriggerServerQueryResponse<TQueryType extends keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType> = TriggerServerQuerySuccessResponse<TQueryType> | TriggerServerQueryFailureResponse;
|
|
53
94
|
|
|
54
|
-
export type { TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse };
|
|
95
|
+
export type { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse };
|
|
@@ -1,26 +1,45 @@
|
|
|
1
|
-
import { SignedTx, EIP712ListTriggerOrdersValues } from '@nadohq/contracts';
|
|
2
1
|
import { EngineServerExecuteResult } from '@nadohq/engine-client';
|
|
2
|
+
import { SignedTx, EIP712ListTriggerOrdersValues } from '@nadohq/shared';
|
|
3
3
|
import { TriggerServerPlaceOrderParams } from './serverExecuteTypes.js';
|
|
4
|
+
import './serverModelTypes.js';
|
|
4
5
|
|
|
5
|
-
type TriggerServerOrderStatus =
|
|
6
|
-
|
|
6
|
+
type TriggerServerOrderStatus = {
|
|
7
|
+
cancelled: TriggerServerCancelReason;
|
|
7
8
|
} | {
|
|
8
|
-
|
|
9
|
+
triggered: EngineServerExecuteResult;
|
|
9
10
|
} | {
|
|
10
11
|
internal_error: string;
|
|
12
|
+
} | 'triggering' | 'waiting_price' | 'waiting_dependency' | {
|
|
13
|
+
twap_executing: {
|
|
14
|
+
current_execution: number;
|
|
15
|
+
total_executions: number;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
twap_completed: {
|
|
19
|
+
executed: number;
|
|
20
|
+
total: number;
|
|
21
|
+
};
|
|
11
22
|
};
|
|
12
23
|
/**
|
|
13
24
|
* Request types
|
|
14
25
|
*/
|
|
26
|
+
type TriggerServerTriggerTypeFilter = 'price_trigger' | 'time_trigger';
|
|
27
|
+
type TriggerServerStatusTypeFilter = 'cancelled' | 'triggered' | 'internal_error' | 'triggering' | 'waiting_price' | 'waiting_dependency' | 'twap_executing' | 'twap_completed';
|
|
15
28
|
interface TriggerServerListTriggerOrdersParams extends SignedTx<EIP712ListTriggerOrdersValues> {
|
|
16
|
-
|
|
17
|
-
product_id?: number;
|
|
29
|
+
product_ids?: number[];
|
|
18
30
|
max_update_time?: number;
|
|
19
31
|
digests?: string[];
|
|
20
32
|
limit?: number;
|
|
33
|
+
trigger_types?: TriggerServerTriggerTypeFilter[];
|
|
34
|
+
status_types?: TriggerServerStatusTypeFilter[];
|
|
35
|
+
reduce_only?: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface TriggerServerListTwapExecutionsParams {
|
|
38
|
+
digest: string;
|
|
21
39
|
}
|
|
22
40
|
interface TriggerServerQueryRequestByType {
|
|
23
41
|
list_trigger_orders: TriggerServerListTriggerOrdersParams;
|
|
42
|
+
list_twap_executions: TriggerServerListTwapExecutionsParams;
|
|
24
43
|
}
|
|
25
44
|
type TriggerServerQueryRequestType = keyof TriggerServerQueryRequestByType;
|
|
26
45
|
/**
|
|
@@ -33,12 +52,34 @@ interface TriggerServerOrderInfo {
|
|
|
33
52
|
order: TriggerServerOrder;
|
|
34
53
|
status: TriggerServerOrderStatus;
|
|
35
54
|
updated_at: number;
|
|
55
|
+
placed_at: number;
|
|
36
56
|
}
|
|
37
57
|
interface TriggerServerListTriggerOrdersResponse {
|
|
38
58
|
orders: TriggerServerOrderInfo[];
|
|
39
59
|
}
|
|
60
|
+
type TriggerServerCancelReason = 'user_requested' | 'linked_signer_changed' | 'expired' | 'account_health' | 'isolated_subaccount_closed' | 'dependent_order_cancelled';
|
|
61
|
+
type TriggerServerTwapExecutionStatus = 'pending' | {
|
|
62
|
+
executed: {
|
|
63
|
+
executed_time: number;
|
|
64
|
+
execute_response: EngineServerExecuteResult;
|
|
65
|
+
};
|
|
66
|
+
} | {
|
|
67
|
+
failed: string;
|
|
68
|
+
} | {
|
|
69
|
+
cancelled: TriggerServerCancelReason;
|
|
70
|
+
};
|
|
71
|
+
interface TriggerServerTwapExecutionInfo {
|
|
72
|
+
execution_id: number;
|
|
73
|
+
scheduled_time: number;
|
|
74
|
+
status: TriggerServerTwapExecutionStatus;
|
|
75
|
+
updated_at: number;
|
|
76
|
+
}
|
|
77
|
+
interface TriggerServerTwapExecutionsResponse {
|
|
78
|
+
executions: TriggerServerTwapExecutionInfo[];
|
|
79
|
+
}
|
|
40
80
|
interface TriggerServerQueryResponseByType {
|
|
41
81
|
list_trigger_orders: TriggerServerListTriggerOrdersResponse;
|
|
82
|
+
list_twap_executions: TriggerServerTwapExecutionsResponse;
|
|
42
83
|
}
|
|
43
84
|
interface TriggerServerQuerySuccessResponse<TQueryType extends keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType> {
|
|
44
85
|
status: 'success';
|
|
@@ -51,4 +92,4 @@ interface TriggerServerQueryFailureResponse {
|
|
|
51
92
|
}
|
|
52
93
|
type TriggerServerQueryResponse<TQueryType extends keyof TriggerServerQueryResponseByType = TriggerServerQueryRequestType> = TriggerServerQuerySuccessResponse<TQueryType> | TriggerServerQueryFailureResponse;
|
|
53
94
|
|
|
54
|
-
export type { TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse };
|
|
95
|
+
export type { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nadohq/trigger-client",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.31",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "> TODO: description",
|
|
@@ -37,9 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@nadohq/
|
|
41
|
-
"@nadohq/
|
|
42
|
-
"@nadohq/utils": "^0.1.0-alpha.3",
|
|
40
|
+
"@nadohq/engine-client": "^0.1.0-alpha.31",
|
|
41
|
+
"@nadohq/shared": "^0.1.0-alpha.31",
|
|
43
42
|
"axios": "*",
|
|
44
43
|
"ts-mixer": "*"
|
|
45
44
|
},
|
|
@@ -49,5 +48,5 @@
|
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"viem": "*"
|
|
51
50
|
},
|
|
52
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "5491b8de4e6422d04a5ef9cd5ef736afdba8fa66"
|
|
53
52
|
}
|
package/src/TriggerClient.ts
CHANGED
|
@@ -7,21 +7,28 @@ import {
|
|
|
7
7
|
getNadoEIP712Values,
|
|
8
8
|
getOrderNonce,
|
|
9
9
|
getSignedTransactionRequest,
|
|
10
|
-
getTriggerOrderNonce,
|
|
11
10
|
SignableRequestType,
|
|
12
11
|
SignableRequestTypeToParams,
|
|
12
|
+
toIntegerString,
|
|
13
13
|
WalletClientWithAccount,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
WalletNotProvidedError,
|
|
15
|
+
} from '@nadohq/shared';
|
|
16
16
|
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
mapServerOrderInfo,
|
|
19
|
+
mapTriggerCriteria,
|
|
20
|
+
mapTwapExecutionStatus,
|
|
21
|
+
} from './dataMappers';
|
|
18
22
|
import {
|
|
19
23
|
TriggerCancelOrdersParams,
|
|
20
24
|
TriggerCancelProductOrdersParams,
|
|
21
25
|
TriggerListOrdersParams,
|
|
22
26
|
TriggerListOrdersResponse,
|
|
27
|
+
TriggerListTwapExecutionsParams,
|
|
28
|
+
TriggerListTwapExecutionsResponse,
|
|
23
29
|
TriggerOrderInfo,
|
|
24
30
|
TriggerPlaceOrderParams,
|
|
31
|
+
TriggerPlaceOrdersParams,
|
|
25
32
|
TriggerServerExecuteRequestByType,
|
|
26
33
|
TriggerServerExecuteRequestType,
|
|
27
34
|
TriggerServerExecuteResult,
|
|
@@ -31,6 +38,7 @@ import {
|
|
|
31
38
|
TriggerServerQueryResponse,
|
|
32
39
|
TriggerServerQueryResponseByType,
|
|
33
40
|
TriggerServerQuerySuccessResponse,
|
|
41
|
+
TwapExecutionInfo,
|
|
34
42
|
} from './types';
|
|
35
43
|
import { TriggerServerFailureError } from './types/TriggerServerFailureError';
|
|
36
44
|
|
|
@@ -52,7 +60,11 @@ export class TriggerClient {
|
|
|
52
60
|
|
|
53
61
|
constructor(opts: TriggerClientOpts) {
|
|
54
62
|
this.opts = opts;
|
|
55
|
-
this.axiosInstance = axios.create({
|
|
63
|
+
this.axiosInstance = axios.create({
|
|
64
|
+
withCredentials: true,
|
|
65
|
+
// We have custom logic to validate response status and create an appropriate error
|
|
66
|
+
validateStatus: () => true,
|
|
67
|
+
});
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
/**
|
|
@@ -71,32 +83,23 @@ export class TriggerClient {
|
|
|
71
83
|
*/
|
|
72
84
|
|
|
73
85
|
async placeTriggerOrder(params: TriggerPlaceOrderParams) {
|
|
74
|
-
|
|
75
|
-
amount: params.order.amount,
|
|
76
|
-
expiration: params.order.expiration,
|
|
77
|
-
price: params.order.price,
|
|
78
|
-
subaccountName: params.order.subaccountName,
|
|
79
|
-
subaccountOwner: params.order.subaccountOwner,
|
|
80
|
-
nonce: params.nonce ?? getTriggerOrderNonce(),
|
|
81
|
-
};
|
|
82
|
-
const signature = await this.sign(
|
|
86
|
+
return this.execute(
|
|
83
87
|
'place_order',
|
|
84
|
-
params
|
|
85
|
-
params.chainId,
|
|
86
|
-
orderParams,
|
|
88
|
+
await this.buildPlaceOrderExecuteParams(params),
|
|
87
89
|
);
|
|
90
|
+
}
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
92
|
+
async placeTriggerOrders(params: TriggerPlaceOrdersParams) {
|
|
93
|
+
const executeParams: TriggerServerExecuteRequestByType['place_orders'] = {
|
|
94
|
+
orders: await Promise.all(
|
|
95
|
+
params.orders.map(async (orderParam) =>
|
|
96
|
+
this.buildPlaceOrderExecuteParams(orderParam),
|
|
97
|
+
),
|
|
98
|
+
),
|
|
99
|
+
cancel_on_failure: params.cancelOnFailure ?? null,
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
return this.execute('
|
|
102
|
+
return this.execute('place_orders', executeParams);
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
async cancelTriggerOrders(params: TriggerCancelOrdersParams) {
|
|
@@ -173,9 +176,11 @@ export class TriggerClient {
|
|
|
173
176
|
{
|
|
174
177
|
limit: params.limit,
|
|
175
178
|
max_update_time: params.maxUpdateTimeInclusive,
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
status_types: params.statusTypes,
|
|
180
|
+
product_ids: params.productIds,
|
|
178
181
|
digests: params.digests,
|
|
182
|
+
trigger_types: params.triggerTypes,
|
|
183
|
+
reduce_only: params.reduceOnly,
|
|
179
184
|
signature,
|
|
180
185
|
tx,
|
|
181
186
|
};
|
|
@@ -190,9 +195,65 @@ export class TriggerClient {
|
|
|
190
195
|
};
|
|
191
196
|
}
|
|
192
197
|
|
|
198
|
+
async listTwapExecutions(
|
|
199
|
+
params: TriggerListTwapExecutionsParams,
|
|
200
|
+
): Promise<TriggerListTwapExecutionsResponse> {
|
|
201
|
+
const queryParams: TriggerServerQueryRequestByType['list_twap_executions'] =
|
|
202
|
+
{
|
|
203
|
+
digest: params.digest,
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
const baseResponse = await this.query('list_twap_executions', queryParams);
|
|
207
|
+
|
|
208
|
+
const executions: TwapExecutionInfo[] = baseResponse.executions.map(
|
|
209
|
+
(execution) => ({
|
|
210
|
+
executionId: execution.execution_id,
|
|
211
|
+
scheduledTime: execution.scheduled_time,
|
|
212
|
+
status: mapTwapExecutionStatus(execution.status),
|
|
213
|
+
updatedAt: execution.updated_at,
|
|
214
|
+
}),
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
executions,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
|
|
193
222
|
/*
|
|
194
223
|
Base Fns
|
|
195
224
|
*/
|
|
225
|
+
|
|
226
|
+
async buildPlaceOrderExecuteParams(
|
|
227
|
+
params: TriggerPlaceOrderParams,
|
|
228
|
+
): Promise<TriggerServerExecuteRequestByType['place_order']> {
|
|
229
|
+
const orderParams: EIP712OrderParams = {
|
|
230
|
+
amount: params.order.amount,
|
|
231
|
+
expiration: params.order.expiration,
|
|
232
|
+
price: params.order.price,
|
|
233
|
+
subaccountName: params.order.subaccountName,
|
|
234
|
+
subaccountOwner: params.order.subaccountOwner,
|
|
235
|
+
nonce: params.nonce ?? getOrderNonce(),
|
|
236
|
+
appendix: params.order.appendix,
|
|
237
|
+
};
|
|
238
|
+
const signature = await this.sign(
|
|
239
|
+
'place_order',
|
|
240
|
+
params.verifyingAddr,
|
|
241
|
+
params.chainId,
|
|
242
|
+
orderParams,
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
id: params.id ?? null,
|
|
247
|
+
order: getNadoEIP712Values('place_order', orderParams),
|
|
248
|
+
trigger: mapTriggerCriteria(params.triggerCriteria),
|
|
249
|
+
signature,
|
|
250
|
+
product_id: params.productId,
|
|
251
|
+
spot_leverage: params.spotLeverage ?? null,
|
|
252
|
+
digest: params.digest ?? null,
|
|
253
|
+
borrow_margin: params.borrowMargin ?? null,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
196
257
|
protected async sign<T extends SignableRequestType>(
|
|
197
258
|
requestType: T,
|
|
198
259
|
verifyingContract: string,
|
|
@@ -267,7 +328,7 @@ export class TriggerClient {
|
|
|
267
328
|
private checkResponseStatus(response: AxiosResponse) {
|
|
268
329
|
if (response.status !== 200 || !response.data) {
|
|
269
330
|
throw Error(
|
|
270
|
-
`Unexpected response from server: ${response.status} ${response.statusText}`,
|
|
331
|
+
`Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,
|
|
271
332
|
);
|
|
272
333
|
}
|
|
273
334
|
}
|