@nadohq/trigger-client 0.1.0-alpha.29 → 0.1.0-alpha.30
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 +38 -22
- package/dist/TriggerClient.cjs.map +1 -1
- package/dist/TriggerClient.d.cts +4 -2
- package/dist/TriggerClient.d.ts +4 -2
- package/dist/TriggerClient.js +38 -22
- package/dist/TriggerClient.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/types/clientTypes.cjs.map +1 -1
- package/dist/types/clientTypes.d.cts +9 -1
- package/dist/types/clientTypes.d.ts +9 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/serverExecuteTypes.cjs.map +1 -1
- package/dist/types/serverExecuteTypes.d.cts +6 -1
- package/dist/types/serverExecuteTypes.d.ts +6 -1
- package/package.json +4 -4
- package/src/TriggerClient.ts +45 -23
- package/src/types/clientTypes.ts +9 -0
- package/src/types/serverExecuteTypes.ts +6 -0
package/dist/TriggerClient.cjs
CHANGED
|
@@ -58,32 +58,21 @@ var TriggerClient = class {
|
|
|
58
58
|
Executes
|
|
59
59
|
*/
|
|
60
60
|
async placeTriggerOrder(params) {
|
|
61
|
-
|
|
62
|
-
amount: params.order.amount,
|
|
63
|
-
expiration: params.order.expiration,
|
|
64
|
-
price: params.order.price,
|
|
65
|
-
subaccountName: params.order.subaccountName,
|
|
66
|
-
subaccountOwner: params.order.subaccountOwner,
|
|
67
|
-
nonce: params.nonce ?? (0, import_shared.getOrderNonce)(),
|
|
68
|
-
appendix: params.order.appendix
|
|
69
|
-
};
|
|
70
|
-
const signature = await this.sign(
|
|
61
|
+
return this.execute(
|
|
71
62
|
"place_order",
|
|
72
|
-
params
|
|
73
|
-
params.chainId,
|
|
74
|
-
orderParams
|
|
63
|
+
await this.buildPlaceOrderExecuteParams(params)
|
|
75
64
|
);
|
|
65
|
+
}
|
|
66
|
+
async placeTriggerOrders(params) {
|
|
76
67
|
const executeParams = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
digest: params.digest ?? null,
|
|
84
|
-
borrow_margin: params.borrowMargin ?? null
|
|
68
|
+
orders: await Promise.all(
|
|
69
|
+
params.orders.map(
|
|
70
|
+
async (orderParam) => this.buildPlaceOrderExecuteParams(orderParam)
|
|
71
|
+
)
|
|
72
|
+
),
|
|
73
|
+
cancel_on_failure: params.cancelOnFailure ?? null
|
|
85
74
|
};
|
|
86
|
-
return this.execute("
|
|
75
|
+
return this.execute("place_orders", executeParams);
|
|
87
76
|
}
|
|
88
77
|
async cancelTriggerOrders(params) {
|
|
89
78
|
const cancelOrdersParams = {
|
|
@@ -181,6 +170,33 @@ var TriggerClient = class {
|
|
|
181
170
|
/*
|
|
182
171
|
Base Fns
|
|
183
172
|
*/
|
|
173
|
+
async buildPlaceOrderExecuteParams(params) {
|
|
174
|
+
const orderParams = {
|
|
175
|
+
amount: params.order.amount,
|
|
176
|
+
expiration: params.order.expiration,
|
|
177
|
+
price: params.order.price,
|
|
178
|
+
subaccountName: params.order.subaccountName,
|
|
179
|
+
subaccountOwner: params.order.subaccountOwner,
|
|
180
|
+
nonce: params.nonce ?? (0, import_shared.getOrderNonce)(),
|
|
181
|
+
appendix: params.order.appendix
|
|
182
|
+
};
|
|
183
|
+
const signature = await this.sign(
|
|
184
|
+
"place_order",
|
|
185
|
+
params.verifyingAddr,
|
|
186
|
+
params.chainId,
|
|
187
|
+
orderParams
|
|
188
|
+
);
|
|
189
|
+
return {
|
|
190
|
+
id: params.id ?? null,
|
|
191
|
+
order: (0, import_shared.getNadoEIP712Values)("place_order", orderParams),
|
|
192
|
+
trigger: (0, import_dataMappers.mapTriggerCriteria)(params.triggerCriteria),
|
|
193
|
+
signature,
|
|
194
|
+
product_id: params.productId,
|
|
195
|
+
spot_leverage: params.spotLeverage ?? null,
|
|
196
|
+
digest: params.digest ?? null,
|
|
197
|
+
borrow_margin: params.borrowMargin ?? null
|
|
198
|
+
};
|
|
199
|
+
}
|
|
184
200
|
async sign(requestType, verifyingContract, chainId, params) {
|
|
185
201
|
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
186
202
|
if (walletClient == null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TriggerClient.ts"],"sourcesContent":["import {\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n EIP712ListTriggerOrdersParams,\n EIP712OrderParams,\n getDefaultRecvTime,\n getNadoEIP712Values,\n getOrderNonce,\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapServerOrderInfo,\n mapTriggerCriteria,\n mapTwapExecutionStatus,\n} from './dataMappers';\nimport {\n TriggerCancelOrdersParams,\n TriggerCancelProductOrdersParams,\n TriggerListOrdersParams,\n TriggerListOrdersResponse,\n TriggerListTwapExecutionsParams,\n TriggerListTwapExecutionsResponse,\n TriggerOrderInfo,\n TriggerPlaceOrderParams,\n TriggerServerExecuteRequestByType,\n TriggerServerExecuteRequestType,\n TriggerServerExecuteResult,\n TriggerServerExecuteSuccessResult,\n TriggerServerQueryRequestByType,\n TriggerServerQueryRequestType,\n TriggerServerQueryResponse,\n TriggerServerQueryResponseByType,\n TriggerServerQuerySuccessResponse,\n TwapExecutionInfo,\n} from './types';\nimport { TriggerServerFailureError } from './types/TriggerServerFailureError';\n\nexport interface TriggerClientOpts {\n // Server URL\n url: string;\n // Wallet client for EIP712 signing\n walletClient?: WalletClientWithAccount;\n // Linked signer registered through the engine, if provided, execute requests will use this signer\n linkedSignerWalletClient?: WalletClientWithAccount;\n}\n\n/**\n * Client for all trigger service requests\n */\nexport class TriggerClient {\n readonly opts: TriggerClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: TriggerClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n withCredentials: true,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n });\n }\n\n /**\n * Sets the linked signer for requests\n *\n * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer\n */\n public setLinkedSigner(\n linkedSignerWalletClient: WalletClientWithAccount | null,\n ) {\n this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? undefined;\n }\n\n /*\n Executes\n */\n\n async placeTriggerOrder(params: TriggerPlaceOrderParams) {\n const orderParams: EIP712OrderParams = {\n amount: params.order.amount,\n expiration: params.order.expiration,\n price: params.order.price,\n subaccountName: params.order.subaccountName,\n subaccountOwner: params.order.subaccountOwner,\n nonce: params.nonce ?? getOrderNonce(),\n appendix: params.order.appendix,\n };\n const signature = await this.sign(\n 'place_order',\n params.verifyingAddr,\n params.chainId,\n orderParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['place_order'] = {\n id: params.id ?? null,\n order: getNadoEIP712Values('place_order', orderParams),\n trigger: mapTriggerCriteria(params.triggerCriteria),\n signature,\n product_id: params.productId,\n spot_leverage: params.spotLeverage ?? null,\n digest: params.digest ?? null,\n borrow_margin: params.borrowMargin ?? null,\n };\n\n return this.execute('place_order', executeParams);\n }\n\n async cancelTriggerOrders(params: TriggerCancelOrdersParams) {\n const cancelOrdersParams: EIP712CancelOrdersParams = {\n digests: params.digests,\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values('cancel_orders', cancelOrdersParams);\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_orders'] = {\n signature: await this.sign(\n 'cancel_orders',\n params.verifyingAddr,\n params.chainId,\n cancelOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_orders', executeParams);\n }\n\n async cancelProductOrders(params: TriggerCancelProductOrdersParams) {\n const cancelProductOrdersParams: EIP712CancelProductOrdersParams = {\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values(\n 'cancel_product_orders',\n cancelProductOrdersParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_product_orders'] =\n {\n signature: await this.sign(\n 'cancel_product_orders',\n params.verifyingAddr,\n params.chainId,\n cancelProductOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_product_orders', executeParams);\n }\n\n /*\n Queries\n */\n async listOrders(\n params: TriggerListOrdersParams,\n ): Promise<TriggerListOrdersResponse> {\n const signatureParams: EIP712ListTriggerOrdersParams = {\n // Default to 90 seconds from now if no recvTime is provided\n recvTime: toIntegerString(params.recvTime ?? getDefaultRecvTime()),\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n\n const tx = getNadoEIP712Values('list_trigger_orders', signatureParams);\n const signature = await this.sign(\n 'list_trigger_orders',\n params.verifyingAddr,\n params.chainId,\n signatureParams,\n );\n\n const queryParams: TriggerServerQueryRequestByType['list_trigger_orders'] =\n {\n limit: params.limit,\n max_update_time: params.maxUpdateTimeInclusive,\n status_types: params.statusTypes,\n product_ids: params.productIds,\n digests: params.digests,\n trigger_types: params.triggerTypes,\n reduce_only: params.reduceOnly,\n signature,\n tx,\n };\n\n const baseResponse = await this.query('list_trigger_orders', queryParams);\n\n const orders: TriggerOrderInfo[] =\n baseResponse.orders.map(mapServerOrderInfo);\n\n return {\n orders,\n };\n }\n\n async listTwapExecutions(\n params: TriggerListTwapExecutionsParams,\n ): Promise<TriggerListTwapExecutionsResponse> {\n const queryParams: TriggerServerQueryRequestByType['list_twap_executions'] =\n {\n digest: params.digest,\n };\n\n const baseResponse = await this.query('list_twap_executions', queryParams);\n\n const executions: TwapExecutionInfo[] = baseResponse.executions.map(\n (execution) => ({\n executionId: execution.execution_id,\n scheduledTime: execution.scheduled_time,\n status: mapTwapExecutionStatus(execution.status),\n updatedAt: execution.updated_at,\n }),\n );\n\n return {\n executions,\n };\n }\n\n /*\n Base Fns\n */\n protected async sign<T extends SignableRequestType>(\n requestType: T,\n verifyingContract: string,\n chainId: number,\n params: SignableRequestTypeToParams[T],\n ) {\n // Use the linked signer if provided, otherwise use the default signer provided to the engine\n const walletClient =\n this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n\n if (walletClient == null) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\n }\n\n /**\n * POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped\n * in an TriggerServerFailureError on failure.\n *\n * @param requestType\n * @param params\n */\n protected async execute<TRequestType extends TriggerServerExecuteRequestType>(\n requestType: TRequestType,\n params: TriggerServerExecuteRequestByType[TRequestType],\n ): Promise<TriggerServerExecuteSuccessResult<TRequestType>> {\n const reqBody = {\n [requestType]: params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerExecuteResult<TRequestType>\n >(`${this.opts.url}/execute`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus catches the failure result and throws the error, so the cast to the success response is acceptable here\n return response.data as TriggerServerExecuteSuccessResult<TRequestType>;\n }\n\n protected async query<TRequestType extends TriggerServerQueryRequestType>(\n requestType: TRequestType,\n params: TriggerServerQueryRequestByType[TRequestType],\n ): Promise<TriggerServerQueryResponseByType[TRequestType]> {\n const reqBody = {\n type: requestType,\n ...params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerQueryResponse<TRequestType>\n >(`${this.opts.url}/query`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n const successResponse = response as AxiosResponse<\n TriggerServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n private checkResponseStatus(response: AxiosResponse) {\n if (response.status !== 200 || !response.data) {\n throw Error(\n `Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n TriggerServerExecuteResult | TriggerServerQueryResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new TriggerServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAcO;AACP,mBAAoD;AACpD,yBAIO;AAqBP,uCAA0C;AAcnC,IAAM,gBAAN,MAAoB;AAAA,EAIzB,YAAY,MAAyB;AACnC,SAAK,OAAO;AACZ,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAAA,MAChC,iBAAiB;AAAA;AAAA,MAEjB,gBAAgB,MAAM;AAAA,IACxB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,gBACL,0BACA;AACA,SAAK,KAAK,2BAA2B,4BAA4B;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,kBAAkB,QAAiC;AACvD,UAAM,cAAiC;AAAA,MACrC,QAAQ,OAAO,MAAM;AAAA,MACrB,YAAY,OAAO,MAAM;AAAA,MACzB,OAAO,OAAO,MAAM;AAAA,MACpB,gBAAgB,OAAO,MAAM;AAAA,MAC7B,iBAAiB,OAAO,MAAM;AAAA,MAC9B,OAAO,OAAO,aAAS,6BAAc;AAAA,MACrC,UAAU,OAAO,MAAM;AAAA,IACzB;AACA,UAAM,YAAY,MAAM,KAAK;AAAA,MAC3B;AAAA,MACA,OAAO;AAAA,MACP,OAAO;AAAA,MACP;AAAA,IACF;AAEA,UAAM,gBAAkE;AAAA,MACtE,IAAI,OAAO,MAAM;AAAA,MACjB,WAAO,mCAAoB,eAAe,WAAW;AAAA,MACrD,aAAS,uCAAmB,OAAO,eAAe;AAAA,MAClD;AAAA,MACA,YAAY,OAAO;AAAA,MACnB,e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A,MACd,CAAC,WAAW,GAAG;AAAA,IACjB;AACA,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,YAAY,OAAO;AAErC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,WAAO,SAAS;AAAA,EAClB;AAAA,EAEA,MAAgB,MACd,aACA,QACyD;AACzD,UAAM,UAAU;AAAA,MACd,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AACA,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,UAAU,OAAO;AAEnC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU,WAAW,SAAS,IAAI;AAAA,MACpG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,2DAA0B,SAAS,IAAI;AAAA,IACnD;AAAA,EACF;AACF;","names":["axios"]}
|
|
1
|
+
{"version":3,"sources":["../src/TriggerClient.ts"],"sourcesContent":["import {\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n EIP712ListTriggerOrdersParams,\n EIP712OrderParams,\n getDefaultRecvTime,\n getNadoEIP712Values,\n getOrderNonce,\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapServerOrderInfo,\n mapTriggerCriteria,\n mapTwapExecutionStatus,\n} from './dataMappers';\nimport {\n TriggerCancelOrdersParams,\n TriggerCancelProductOrdersParams,\n TriggerListOrdersParams,\n TriggerListOrdersResponse,\n TriggerListTwapExecutionsParams,\n TriggerListTwapExecutionsResponse,\n TriggerOrderInfo,\n TriggerPlaceOrderParams,\n TriggerPlaceOrdersParams,\n TriggerServerExecuteRequestByType,\n TriggerServerExecuteRequestType,\n TriggerServerExecuteResult,\n TriggerServerExecuteSuccessResult,\n TriggerServerQueryRequestByType,\n TriggerServerQueryRequestType,\n TriggerServerQueryResponse,\n TriggerServerQueryResponseByType,\n TriggerServerQuerySuccessResponse,\n TwapExecutionInfo,\n} from './types';\nimport { TriggerServerFailureError } from './types/TriggerServerFailureError';\n\nexport interface TriggerClientOpts {\n // Server URL\n url: string;\n // Wallet client for EIP712 signing\n walletClient?: WalletClientWithAccount;\n // Linked signer registered through the engine, if provided, execute requests will use this signer\n linkedSignerWalletClient?: WalletClientWithAccount;\n}\n\n/**\n * Client for all trigger service requests\n */\nexport class TriggerClient {\n readonly opts: TriggerClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: TriggerClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n withCredentials: true,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n });\n }\n\n /**\n * Sets the linked signer for requests\n *\n * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer\n */\n public setLinkedSigner(\n linkedSignerWalletClient: WalletClientWithAccount | null,\n ) {\n this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? undefined;\n }\n\n /*\n Executes\n */\n\n async placeTriggerOrder(params: TriggerPlaceOrderParams) {\n return this.execute(\n 'place_order',\n await this.buildPlaceOrderExecuteParams(params),\n );\n }\n\n async placeTriggerOrders(params: TriggerPlaceOrdersParams) {\n const executeParams: TriggerServerExecuteRequestByType['place_orders'] = {\n orders: await Promise.all(\n params.orders.map(async (orderParam) =>\n this.buildPlaceOrderExecuteParams(orderParam),\n ),\n ),\n cancel_on_failure: params.cancelOnFailure ?? null,\n };\n\n return this.execute('place_orders', executeParams);\n }\n\n async cancelTriggerOrders(params: TriggerCancelOrdersParams) {\n const cancelOrdersParams: EIP712CancelOrdersParams = {\n digests: params.digests,\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values('cancel_orders', cancelOrdersParams);\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_orders'] = {\n signature: await this.sign(\n 'cancel_orders',\n params.verifyingAddr,\n params.chainId,\n cancelOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_orders', executeParams);\n }\n\n async cancelProductOrders(params: TriggerCancelProductOrdersParams) {\n const cancelProductOrdersParams: EIP712CancelProductOrdersParams = {\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values(\n 'cancel_product_orders',\n cancelProductOrdersParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_product_orders'] =\n {\n signature: await this.sign(\n 'cancel_product_orders',\n params.verifyingAddr,\n params.chainId,\n cancelProductOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_product_orders', executeParams);\n }\n\n /*\n Queries\n */\n async listOrders(\n params: TriggerListOrdersParams,\n ): Promise<TriggerListOrdersResponse> {\n const signatureParams: EIP712ListTriggerOrdersParams = {\n // Default to 90 seconds from now if no recvTime is provided\n recvTime: toIntegerString(params.recvTime ?? getDefaultRecvTime()),\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n\n const tx = getNadoEIP712Values('list_trigger_orders', signatureParams);\n const signature = await this.sign(\n 'list_trigger_orders',\n params.verifyingAddr,\n params.chainId,\n signatureParams,\n );\n\n const queryParams: TriggerServerQueryRequestByType['list_trigger_orders'] =\n {\n limit: params.limit,\n max_update_time: params.maxUpdateTimeInclusive,\n status_types: params.statusTypes,\n product_ids: params.productIds,\n digests: params.digests,\n trigger_types: params.triggerTypes,\n reduce_only: params.reduceOnly,\n signature,\n tx,\n };\n\n const baseResponse = await this.query('list_trigger_orders', queryParams);\n\n const orders: TriggerOrderInfo[] =\n baseResponse.orders.map(mapServerOrderInfo);\n\n return {\n orders,\n };\n }\n\n async listTwapExecutions(\n params: TriggerListTwapExecutionsParams,\n ): Promise<TriggerListTwapExecutionsResponse> {\n const queryParams: TriggerServerQueryRequestByType['list_twap_executions'] =\n {\n digest: params.digest,\n };\n\n const baseResponse = await this.query('list_twap_executions', queryParams);\n\n const executions: TwapExecutionInfo[] = baseResponse.executions.map(\n (execution) => ({\n executionId: execution.execution_id,\n scheduledTime: execution.scheduled_time,\n status: mapTwapExecutionStatus(execution.status),\n updatedAt: execution.updated_at,\n }),\n );\n\n return {\n executions,\n };\n }\n\n /*\n Base Fns\n */\n\n async buildPlaceOrderExecuteParams(\n params: TriggerPlaceOrderParams,\n ): Promise<TriggerServerExecuteRequestByType['place_order']> {\n const orderParams: EIP712OrderParams = {\n amount: params.order.amount,\n expiration: params.order.expiration,\n price: params.order.price,\n subaccountName: params.order.subaccountName,\n subaccountOwner: params.order.subaccountOwner,\n nonce: params.nonce ?? getOrderNonce(),\n appendix: params.order.appendix,\n };\n const signature = await this.sign(\n 'place_order',\n params.verifyingAddr,\n params.chainId,\n orderParams,\n );\n\n return {\n id: params.id ?? null,\n order: getNadoEIP712Values('place_order', orderParams),\n trigger: mapTriggerCriteria(params.triggerCriteria),\n signature,\n product_id: params.productId,\n spot_leverage: params.spotLeverage ?? null,\n digest: params.digest ?? null,\n borrow_margin: params.borrowMargin ?? null,\n };\n }\n\n protected async sign<T extends SignableRequestType>(\n requestType: T,\n verifyingContract: string,\n chainId: number,\n params: SignableRequestTypeToParams[T],\n ) {\n // Use the linked signer if provided, otherwise use the default signer provided to the engine\n const walletClient =\n this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n\n if (walletClient == null) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\n }\n\n /**\n * POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped\n * in an TriggerServerFailureError on failure.\n *\n * @param requestType\n * @param params\n */\n protected async execute<TRequestType extends TriggerServerExecuteRequestType>(\n requestType: TRequestType,\n params: TriggerServerExecuteRequestByType[TRequestType],\n ): Promise<TriggerServerExecuteSuccessResult<TRequestType>> {\n const reqBody = {\n [requestType]: params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerExecuteResult<TRequestType>\n >(`${this.opts.url}/execute`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus catches the failure result and throws the error, so the cast to the success response is acceptable here\n return response.data as TriggerServerExecuteSuccessResult<TRequestType>;\n }\n\n protected async query<TRequestType extends TriggerServerQueryRequestType>(\n requestType: TRequestType,\n params: TriggerServerQueryRequestByType[TRequestType],\n ): Promise<TriggerServerQueryResponseByType[TRequestType]> {\n const reqBody = {\n type: requestType,\n ...params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerQueryResponse<TRequestType>\n >(`${this.opts.url}/query`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n const successResponse = response as AxiosResponse<\n TriggerServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n private checkResponseStatus(response: AxiosResponse) {\n if (response.status !== 200 || !response.data) {\n throw Error(\n `Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n TriggerServerExecuteResult | TriggerServerQueryResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new TriggerServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAcO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,QACd,aACA,QAC0D;AAC1D,UAAM,UAAU;AAAA,MACd,CAAC,WAAW,GAAG;AAAA,IACjB;AACA,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,YAAY,OAAO;AAErC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,WAAO,SAAS;AAAA,EAClB;AAAA,EAEA,MAAgB,MACd,aACA,QACyD;AACzD,UAAM,UAAU;AAAA,MACd,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AACA,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,UAAU,OAAO;AAEnC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU,WAAW,SAAS,IAAI;AAAA,MACpG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,2DAA0B,SAAS,IAAI;AAAA,IACnD;AAAA,EACF;AACF;","names":["axios"]}
|
package/dist/TriggerClient.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WalletClientWithAccount, SignableRequestType, SignableRequestTypeToParams } from '@nadohq/shared';
|
|
2
2
|
import { AxiosInstance } from 'axios';
|
|
3
|
-
import { TriggerPlaceOrderParams, TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse } from './types/clientTypes.cjs';
|
|
4
|
-
import { TriggerServerExecuteSuccessResult,
|
|
3
|
+
import { TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse } from './types/clientTypes.cjs';
|
|
4
|
+
import { TriggerServerExecuteSuccessResult, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType } from './types/serverExecuteTypes.cjs';
|
|
5
5
|
import { TriggerServerQueryRequestType, TriggerServerQueryRequestByType, TriggerServerQueryResponseByType } from './types/serverQueryTypes.cjs';
|
|
6
6
|
import '@nadohq/engine-client';
|
|
7
7
|
import './types/clientModelTypes.cjs';
|
|
@@ -26,10 +26,12 @@ declare class TriggerClient {
|
|
|
26
26
|
*/
|
|
27
27
|
setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
|
|
28
28
|
placeTriggerOrder(params: TriggerPlaceOrderParams): Promise<TriggerServerExecuteSuccessResult<"place_order">>;
|
|
29
|
+
placeTriggerOrders(params: TriggerPlaceOrdersParams): Promise<TriggerServerExecuteSuccessResult<"place_orders">>;
|
|
29
30
|
cancelTriggerOrders(params: TriggerCancelOrdersParams): Promise<TriggerServerExecuteSuccessResult<"cancel_orders">>;
|
|
30
31
|
cancelProductOrders(params: TriggerCancelProductOrdersParams): Promise<TriggerServerExecuteSuccessResult<"cancel_product_orders">>;
|
|
31
32
|
listOrders(params: TriggerListOrdersParams): Promise<TriggerListOrdersResponse>;
|
|
32
33
|
listTwapExecutions(params: TriggerListTwapExecutionsParams): Promise<TriggerListTwapExecutionsResponse>;
|
|
34
|
+
buildPlaceOrderExecuteParams(params: TriggerPlaceOrderParams): Promise<TriggerServerExecuteRequestByType['place_order']>;
|
|
33
35
|
protected sign<T extends SignableRequestType>(requestType: T, verifyingContract: string, chainId: number, params: SignableRequestTypeToParams[T]): Promise<`0x${string}`>;
|
|
34
36
|
/**
|
|
35
37
|
* POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped
|
package/dist/TriggerClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WalletClientWithAccount, SignableRequestType, SignableRequestTypeToParams } from '@nadohq/shared';
|
|
2
2
|
import { AxiosInstance } from 'axios';
|
|
3
|
-
import { TriggerPlaceOrderParams, TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse } from './types/clientTypes.js';
|
|
4
|
-
import { TriggerServerExecuteSuccessResult,
|
|
3
|
+
import { TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse } from './types/clientTypes.js';
|
|
4
|
+
import { TriggerServerExecuteSuccessResult, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType } from './types/serverExecuteTypes.js';
|
|
5
5
|
import { TriggerServerQueryRequestType, TriggerServerQueryRequestByType, TriggerServerQueryResponseByType } from './types/serverQueryTypes.js';
|
|
6
6
|
import '@nadohq/engine-client';
|
|
7
7
|
import './types/clientModelTypes.js';
|
|
@@ -26,10 +26,12 @@ declare class TriggerClient {
|
|
|
26
26
|
*/
|
|
27
27
|
setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
|
|
28
28
|
placeTriggerOrder(params: TriggerPlaceOrderParams): Promise<TriggerServerExecuteSuccessResult<"place_order">>;
|
|
29
|
+
placeTriggerOrders(params: TriggerPlaceOrdersParams): Promise<TriggerServerExecuteSuccessResult<"place_orders">>;
|
|
29
30
|
cancelTriggerOrders(params: TriggerCancelOrdersParams): Promise<TriggerServerExecuteSuccessResult<"cancel_orders">>;
|
|
30
31
|
cancelProductOrders(params: TriggerCancelProductOrdersParams): Promise<TriggerServerExecuteSuccessResult<"cancel_product_orders">>;
|
|
31
32
|
listOrders(params: TriggerListOrdersParams): Promise<TriggerListOrdersResponse>;
|
|
32
33
|
listTwapExecutions(params: TriggerListTwapExecutionsParams): Promise<TriggerListTwapExecutionsResponse>;
|
|
34
|
+
buildPlaceOrderExecuteParams(params: TriggerPlaceOrderParams): Promise<TriggerServerExecuteRequestByType['place_order']>;
|
|
33
35
|
protected sign<T extends SignableRequestType>(requestType: T, verifyingContract: string, chainId: number, params: SignableRequestTypeToParams[T]): Promise<`0x${string}`>;
|
|
34
36
|
/**
|
|
35
37
|
* POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped
|
package/dist/TriggerClient.js
CHANGED
|
@@ -35,32 +35,21 @@ var TriggerClient = class {
|
|
|
35
35
|
Executes
|
|
36
36
|
*/
|
|
37
37
|
async placeTriggerOrder(params) {
|
|
38
|
-
|
|
39
|
-
amount: params.order.amount,
|
|
40
|
-
expiration: params.order.expiration,
|
|
41
|
-
price: params.order.price,
|
|
42
|
-
subaccountName: params.order.subaccountName,
|
|
43
|
-
subaccountOwner: params.order.subaccountOwner,
|
|
44
|
-
nonce: params.nonce ?? getOrderNonce(),
|
|
45
|
-
appendix: params.order.appendix
|
|
46
|
-
};
|
|
47
|
-
const signature = await this.sign(
|
|
38
|
+
return this.execute(
|
|
48
39
|
"place_order",
|
|
49
|
-
params
|
|
50
|
-
params.chainId,
|
|
51
|
-
orderParams
|
|
40
|
+
await this.buildPlaceOrderExecuteParams(params)
|
|
52
41
|
);
|
|
42
|
+
}
|
|
43
|
+
async placeTriggerOrders(params) {
|
|
53
44
|
const executeParams = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
digest: params.digest ?? null,
|
|
61
|
-
borrow_margin: params.borrowMargin ?? null
|
|
45
|
+
orders: await Promise.all(
|
|
46
|
+
params.orders.map(
|
|
47
|
+
async (orderParam) => this.buildPlaceOrderExecuteParams(orderParam)
|
|
48
|
+
)
|
|
49
|
+
),
|
|
50
|
+
cancel_on_failure: params.cancelOnFailure ?? null
|
|
62
51
|
};
|
|
63
|
-
return this.execute("
|
|
52
|
+
return this.execute("place_orders", executeParams);
|
|
64
53
|
}
|
|
65
54
|
async cancelTriggerOrders(params) {
|
|
66
55
|
const cancelOrdersParams = {
|
|
@@ -158,6 +147,33 @@ var TriggerClient = class {
|
|
|
158
147
|
/*
|
|
159
148
|
Base Fns
|
|
160
149
|
*/
|
|
150
|
+
async buildPlaceOrderExecuteParams(params) {
|
|
151
|
+
const orderParams = {
|
|
152
|
+
amount: params.order.amount,
|
|
153
|
+
expiration: params.order.expiration,
|
|
154
|
+
price: params.order.price,
|
|
155
|
+
subaccountName: params.order.subaccountName,
|
|
156
|
+
subaccountOwner: params.order.subaccountOwner,
|
|
157
|
+
nonce: params.nonce ?? getOrderNonce(),
|
|
158
|
+
appendix: params.order.appendix
|
|
159
|
+
};
|
|
160
|
+
const signature = await this.sign(
|
|
161
|
+
"place_order",
|
|
162
|
+
params.verifyingAddr,
|
|
163
|
+
params.chainId,
|
|
164
|
+
orderParams
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
id: params.id ?? null,
|
|
168
|
+
order: getNadoEIP712Values("place_order", orderParams),
|
|
169
|
+
trigger: mapTriggerCriteria(params.triggerCriteria),
|
|
170
|
+
signature,
|
|
171
|
+
product_id: params.productId,
|
|
172
|
+
spot_leverage: params.spotLeverage ?? null,
|
|
173
|
+
digest: params.digest ?? null,
|
|
174
|
+
borrow_margin: params.borrowMargin ?? null
|
|
175
|
+
};
|
|
176
|
+
}
|
|
161
177
|
async sign(requestType, verifyingContract, chainId, params) {
|
|
162
178
|
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
163
179
|
if (walletClient == null) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/TriggerClient.ts"],"sourcesContent":["import {\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n EIP712ListTriggerOrdersParams,\n EIP712OrderParams,\n getDefaultRecvTime,\n getNadoEIP712Values,\n getOrderNonce,\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapServerOrderInfo,\n mapTriggerCriteria,\n mapTwapExecutionStatus,\n} from './dataMappers';\nimport {\n TriggerCancelOrdersParams,\n TriggerCancelProductOrdersParams,\n TriggerListOrdersParams,\n TriggerListOrdersResponse,\n TriggerListTwapExecutionsParams,\n TriggerListTwapExecutionsResponse,\n TriggerOrderInfo,\n TriggerPlaceOrderParams,\n TriggerServerExecuteRequestByType,\n TriggerServerExecuteRequestType,\n TriggerServerExecuteResult,\n TriggerServerExecuteSuccessResult,\n TriggerServerQueryRequestByType,\n TriggerServerQueryRequestType,\n TriggerServerQueryResponse,\n TriggerServerQueryResponseByType,\n TriggerServerQuerySuccessResponse,\n TwapExecutionInfo,\n} from './types';\nimport { TriggerServerFailureError } from './types/TriggerServerFailureError';\n\nexport interface TriggerClientOpts {\n // Server URL\n url: string;\n // Wallet client for EIP712 signing\n walletClient?: WalletClientWithAccount;\n // Linked signer registered through the engine, if provided, execute requests will use this signer\n linkedSignerWalletClient?: WalletClientWithAccount;\n}\n\n/**\n * Client for all trigger service requests\n */\nexport class TriggerClient {\n readonly opts: TriggerClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: TriggerClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n withCredentials: true,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n });\n }\n\n /**\n * Sets the linked signer for requests\n *\n * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer\n */\n public setLinkedSigner(\n linkedSignerWalletClient: WalletClientWithAccount | null,\n ) {\n this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? undefined;\n }\n\n /*\n Executes\n */\n\n async placeTriggerOrder(params: TriggerPlaceOrderParams) {\n const orderParams: EIP712OrderParams = {\n amount: params.order.amount,\n expiration: params.order.expiration,\n price: params.order.price,\n subaccountName: params.order.subaccountName,\n subaccountOwner: params.order.subaccountOwner,\n nonce: params.nonce ?? getOrderNonce(),\n appendix: params.order.appendix,\n };\n const signature = await this.sign(\n 'place_order',\n params.verifyingAddr,\n params.chainId,\n orderParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['place_order'] = {\n id: params.id ?? null,\n order: getNadoEIP712Values('place_order', orderParams),\n trigger: mapTriggerCriteria(params.triggerCriteria),\n signature,\n product_id: params.productId,\n spot_leverage: params.spotLeverage ?? null,\n digest: params.digest ?? null,\n borrow_margin: params.borrowMargin ?? null,\n };\n\n return this.execute('place_order', executeParams);\n }\n\n async cancelTriggerOrders(params: TriggerCancelOrdersParams) {\n const cancelOrdersParams: EIP712CancelOrdersParams = {\n digests: params.digests,\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values('cancel_orders', cancelOrdersParams);\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_orders'] = {\n signature: await this.sign(\n 'cancel_orders',\n params.verifyingAddr,\n params.chainId,\n cancelOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_orders', executeParams);\n }\n\n async cancelProductOrders(params: TriggerCancelProductOrdersParams) {\n const cancelProductOrdersParams: EIP712CancelProductOrdersParams = {\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values(\n 'cancel_product_orders',\n cancelProductOrdersParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_product_orders'] =\n {\n signature: await this.sign(\n 'cancel_product_orders',\n params.verifyingAddr,\n params.chainId,\n cancelProductOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_product_orders', executeParams);\n }\n\n /*\n Queries\n */\n async listOrders(\n params: TriggerListOrdersParams,\n ): Promise<TriggerListOrdersResponse> {\n const signatureParams: EIP712ListTriggerOrdersParams = {\n // Default to 90 seconds from now if no recvTime is provided\n recvTime: toIntegerString(params.recvTime ?? getDefaultRecvTime()),\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n\n const tx = getNadoEIP712Values('list_trigger_orders', signatureParams);\n const signature = await this.sign(\n 'list_trigger_orders',\n params.verifyingAddr,\n params.chainId,\n signatureParams,\n );\n\n const queryParams: TriggerServerQueryRequestByType['list_trigger_orders'] =\n {\n limit: params.limit,\n max_update_time: params.maxUpdateTimeInclusive,\n status_types: params.statusTypes,\n product_ids: params.productIds,\n digests: params.digests,\n trigger_types: params.triggerTypes,\n reduce_only: params.reduceOnly,\n signature,\n tx,\n };\n\n const baseResponse = await this.query('list_trigger_orders', queryParams);\n\n const orders: TriggerOrderInfo[] =\n baseResponse.orders.map(mapServerOrderInfo);\n\n return {\n orders,\n };\n }\n\n async listTwapExecutions(\n params: TriggerListTwapExecutionsParams,\n ): Promise<TriggerListTwapExecutionsResponse> {\n const queryParams: TriggerServerQueryRequestByType['list_twap_executions'] =\n {\n digest: params.digest,\n };\n\n const baseResponse = await this.query('list_twap_executions', queryParams);\n\n const executions: TwapExecutionInfo[] = baseResponse.executions.map(\n (execution) => ({\n executionId: execution.execution_id,\n scheduledTime: execution.scheduled_time,\n status: mapTwapExecutionStatus(execution.status),\n updatedAt: execution.updated_at,\n }),\n );\n\n return {\n executions,\n };\n }\n\n /*\n Base Fns\n */\n protected async sign<T extends SignableRequestType>(\n requestType: T,\n verifyingContract: string,\n chainId: number,\n params: SignableRequestTypeToParams[T],\n ) {\n // Use the linked signer if provided, otherwise use the default signer provided to the engine\n const walletClient =\n this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n\n if (walletClient == null) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\n }\n\n /**\n * POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped\n * in an TriggerServerFailureError on failure.\n *\n * @param requestType\n * @param params\n */\n protected async execute<TRequestType extends TriggerServerExecuteRequestType>(\n requestType: TRequestType,\n params: TriggerServerExecuteRequestByType[TRequestType],\n ): Promise<TriggerServerExecuteSuccessResult<TRequestType>> {\n const reqBody = {\n [requestType]: params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerExecuteResult<TRequestType>\n >(`${this.opts.url}/execute`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus catches the failure result and throws the error, so the cast to the success response is acceptable here\n return response.data as TriggerServerExecuteSuccessResult<TRequestType>;\n }\n\n protected async query<TRequestType extends TriggerServerQueryRequestType>(\n requestType: TRequestType,\n params: TriggerServerQueryRequestByType[TRequestType],\n ): Promise<TriggerServerQueryResponseByType[TRequestType]> {\n const reqBody = {\n type: requestType,\n ...params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerQueryResponse<TRequestType>\n >(`${this.opts.url}/query`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n const successResponse = response as AxiosResponse<\n TriggerServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n private checkResponseStatus(response: AxiosResponse) {\n if (response.status !== 200 || !response.data) {\n throw Error(\n `Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n TriggerServerExecuteResult | TriggerServerQueryResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new TriggerServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EAEA;AAAA,OACK;AACP,OAAO,WAA6C;AACpD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA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AK,KAAK,GAAG,UAAU,OAAO;AAEnC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU,WAAW,SAAS,IAAI;AAAA,MACpG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,0BAA0B,SAAS,IAAI;AAAA,IACnD;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/TriggerClient.ts"],"sourcesContent":["import {\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n EIP712ListTriggerOrdersParams,\n EIP712OrderParams,\n getDefaultRecvTime,\n getNadoEIP712Values,\n getOrderNonce,\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n mapServerOrderInfo,\n mapTriggerCriteria,\n mapTwapExecutionStatus,\n} from './dataMappers';\nimport {\n TriggerCancelOrdersParams,\n TriggerCancelProductOrdersParams,\n TriggerListOrdersParams,\n TriggerListOrdersResponse,\n TriggerListTwapExecutionsParams,\n TriggerListTwapExecutionsResponse,\n TriggerOrderInfo,\n TriggerPlaceOrderParams,\n TriggerPlaceOrdersParams,\n TriggerServerExecuteRequestByType,\n TriggerServerExecuteRequestType,\n TriggerServerExecuteResult,\n TriggerServerExecuteSuccessResult,\n TriggerServerQueryRequestByType,\n TriggerServerQueryRequestType,\n TriggerServerQueryResponse,\n TriggerServerQueryResponseByType,\n TriggerServerQuerySuccessResponse,\n TwapExecutionInfo,\n} from './types';\nimport { TriggerServerFailureError } from './types/TriggerServerFailureError';\n\nexport interface TriggerClientOpts {\n // Server URL\n url: string;\n // Wallet client for EIP712 signing\n walletClient?: WalletClientWithAccount;\n // Linked signer registered through the engine, if provided, execute requests will use this signer\n linkedSignerWalletClient?: WalletClientWithAccount;\n}\n\n/**\n * Client for all trigger service requests\n */\nexport class TriggerClient {\n readonly opts: TriggerClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: TriggerClientOpts) {\n this.opts = opts;\n this.axiosInstance = axios.create({\n withCredentials: true,\n // We have custom logic to validate response status and create an appropriate error\n validateStatus: () => true,\n });\n }\n\n /**\n * Sets the linked signer for requests\n *\n * @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer\n */\n public setLinkedSigner(\n linkedSignerWalletClient: WalletClientWithAccount | null,\n ) {\n this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? undefined;\n }\n\n /*\n Executes\n */\n\n async placeTriggerOrder(params: TriggerPlaceOrderParams) {\n return this.execute(\n 'place_order',\n await this.buildPlaceOrderExecuteParams(params),\n );\n }\n\n async placeTriggerOrders(params: TriggerPlaceOrdersParams) {\n const executeParams: TriggerServerExecuteRequestByType['place_orders'] = {\n orders: await Promise.all(\n params.orders.map(async (orderParam) =>\n this.buildPlaceOrderExecuteParams(orderParam),\n ),\n ),\n cancel_on_failure: params.cancelOnFailure ?? null,\n };\n\n return this.execute('place_orders', executeParams);\n }\n\n async cancelTriggerOrders(params: TriggerCancelOrdersParams) {\n const cancelOrdersParams: EIP712CancelOrdersParams = {\n digests: params.digests,\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values('cancel_orders', cancelOrdersParams);\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_orders'] = {\n signature: await this.sign(\n 'cancel_orders',\n params.verifyingAddr,\n params.chainId,\n cancelOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_orders', executeParams);\n }\n\n async cancelProductOrders(params: TriggerCancelProductOrdersParams) {\n const cancelProductOrdersParams: EIP712CancelProductOrdersParams = {\n nonce: params.nonce ?? getOrderNonce(),\n productIds: params.productIds,\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n const tx = getNadoEIP712Values(\n 'cancel_product_orders',\n cancelProductOrdersParams,\n );\n\n const executeParams: TriggerServerExecuteRequestByType['cancel_product_orders'] =\n {\n signature: await this.sign(\n 'cancel_product_orders',\n params.verifyingAddr,\n params.chainId,\n cancelProductOrdersParams,\n ),\n tx,\n };\n\n return this.execute('cancel_product_orders', executeParams);\n }\n\n /*\n Queries\n */\n async listOrders(\n params: TriggerListOrdersParams,\n ): Promise<TriggerListOrdersResponse> {\n const signatureParams: EIP712ListTriggerOrdersParams = {\n // Default to 90 seconds from now if no recvTime is provided\n recvTime: toIntegerString(params.recvTime ?? getDefaultRecvTime()),\n subaccountName: params.subaccountName,\n subaccountOwner: params.subaccountOwner,\n };\n\n const tx = getNadoEIP712Values('list_trigger_orders', signatureParams);\n const signature = await this.sign(\n 'list_trigger_orders',\n params.verifyingAddr,\n params.chainId,\n signatureParams,\n );\n\n const queryParams: TriggerServerQueryRequestByType['list_trigger_orders'] =\n {\n limit: params.limit,\n max_update_time: params.maxUpdateTimeInclusive,\n status_types: params.statusTypes,\n product_ids: params.productIds,\n digests: params.digests,\n trigger_types: params.triggerTypes,\n reduce_only: params.reduceOnly,\n signature,\n tx,\n };\n\n const baseResponse = await this.query('list_trigger_orders', queryParams);\n\n const orders: TriggerOrderInfo[] =\n baseResponse.orders.map(mapServerOrderInfo);\n\n return {\n orders,\n };\n }\n\n async listTwapExecutions(\n params: TriggerListTwapExecutionsParams,\n ): Promise<TriggerListTwapExecutionsResponse> {\n const queryParams: TriggerServerQueryRequestByType['list_twap_executions'] =\n {\n digest: params.digest,\n };\n\n const baseResponse = await this.query('list_twap_executions', queryParams);\n\n const executions: TwapExecutionInfo[] = baseResponse.executions.map(\n (execution) => ({\n executionId: execution.execution_id,\n scheduledTime: execution.scheduled_time,\n status: mapTwapExecutionStatus(execution.status),\n updatedAt: execution.updated_at,\n }),\n );\n\n return {\n executions,\n };\n }\n\n /*\n Base Fns\n */\n\n async buildPlaceOrderExecuteParams(\n params: TriggerPlaceOrderParams,\n ): Promise<TriggerServerExecuteRequestByType['place_order']> {\n const orderParams: EIP712OrderParams = {\n amount: params.order.amount,\n expiration: params.order.expiration,\n price: params.order.price,\n subaccountName: params.order.subaccountName,\n subaccountOwner: params.order.subaccountOwner,\n nonce: params.nonce ?? getOrderNonce(),\n appendix: params.order.appendix,\n };\n const signature = await this.sign(\n 'place_order',\n params.verifyingAddr,\n params.chainId,\n orderParams,\n );\n\n return {\n id: params.id ?? null,\n order: getNadoEIP712Values('place_order', orderParams),\n trigger: mapTriggerCriteria(params.triggerCriteria),\n signature,\n product_id: params.productId,\n spot_leverage: params.spotLeverage ?? null,\n digest: params.digest ?? null,\n borrow_margin: params.borrowMargin ?? null,\n };\n }\n\n protected async sign<T extends SignableRequestType>(\n requestType: T,\n verifyingContract: string,\n chainId: number,\n params: SignableRequestTypeToParams[T],\n ) {\n // Use the linked signer if provided, otherwise use the default signer provided to the engine\n const walletClient =\n this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n\n if (walletClient == null) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\n }\n\n /**\n * POSTs an execute message to the trigger service and returns the successful response. Throws the failure response wrapped\n * in an TriggerServerFailureError on failure.\n *\n * @param requestType\n * @param params\n */\n protected async execute<TRequestType extends TriggerServerExecuteRequestType>(\n requestType: TRequestType,\n params: TriggerServerExecuteRequestByType[TRequestType],\n ): Promise<TriggerServerExecuteSuccessResult<TRequestType>> {\n const reqBody = {\n [requestType]: params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerExecuteResult<TRequestType>\n >(`${this.opts.url}/execute`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus catches the failure result and throws the error, so the cast to the success response is acceptable here\n return response.data as TriggerServerExecuteSuccessResult<TRequestType>;\n }\n\n protected async query<TRequestType extends TriggerServerQueryRequestType>(\n requestType: TRequestType,\n params: TriggerServerQueryRequestByType[TRequestType],\n ): Promise<TriggerServerQueryResponseByType[TRequestType]> {\n const reqBody = {\n type: requestType,\n ...params,\n };\n const response = await this.axiosInstance.post<\n TriggerServerQueryResponse<TRequestType>\n >(`${this.opts.url}/query`, reqBody);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n // checkServerStatus throws on failure responses so the cast to the success response is acceptable here\n const successResponse = response as AxiosResponse<\n TriggerServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n private checkResponseStatus(response: AxiosResponse) {\n if (response.status !== 200 || !response.data) {\n throw Error(\n `Unexpected response from server: ${response.status} ${response.statusText}. Data: ${response.data}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n TriggerServerExecuteResult | TriggerServerQueryResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new TriggerServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,EAEA;AAAA,OACK;AACP,OAAO,WAA6C;AACpD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAsBP,SAAS,iCAAiC;AAcnC,IAAM,gBAAN,MAAoB;AAAA,EAIzB,YAAY,MAAyB;AACnC,SAAK,OAAO;AACZ,SAAK,gBAAgB,MAAM,OAAO;AAAA,MAChC,iBAAiB;AAAA;AAAA,MAEjB,gBAAgB,MAAM;AAAA,IACxB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,gBACL,0BACA;AACA,SAAK,K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M;AAAA,MACN,GAAG;AAAA,IACL;AACA,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,UAAU,OAAO;AAEnC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU,WAAW,SAAS,IAAI;AAAA,MACpG;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,0BAA0B,SAAS,IAAI;AAAA,IACnD;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { TRIGGER_CLIENT_ENDPOINTS } from './endpoints.cjs';
|
|
2
2
|
export { TriggerClient, TriggerClientOpts } from './TriggerClient.cjs';
|
|
3
3
|
export { PriceTriggerCriteria, PriceTriggerDependency, PriceTriggerRequirementType, TimeTriggerCriteria, TriggerCriteria, TriggerCriteriaType, TriggerOrderStatus } from './types/clientModelTypes.cjs';
|
|
4
|
-
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus } from './types/clientTypes.cjs';
|
|
5
|
-
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams } from './types/serverExecuteTypes.cjs';
|
|
4
|
+
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus } from './types/clientTypes.cjs';
|
|
5
|
+
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams } from './types/serverExecuteTypes.cjs';
|
|
6
6
|
export { TriggerServerDependency, TriggerServerPriceRequirement, TriggerServerPriceTriggerCriteria, TriggerServerTimeTriggerCriteria, TriggerServerTriggerCriteria } from './types/serverModelTypes.cjs';
|
|
7
7
|
export { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse } from './types/serverQueryTypes.cjs';
|
|
8
8
|
export { TriggerServerFailureError } from './types/TriggerServerFailureError.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export { TRIGGER_CLIENT_ENDPOINTS } from './endpoints.js';
|
|
2
2
|
export { TriggerClient, TriggerClientOpts } from './TriggerClient.js';
|
|
3
3
|
export { PriceTriggerCriteria, PriceTriggerDependency, PriceTriggerRequirementType, TimeTriggerCriteria, TriggerCriteria, TriggerCriteriaType, TriggerOrderStatus } from './types/clientModelTypes.js';
|
|
4
|
-
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus } from './types/clientTypes.js';
|
|
5
|
-
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams } from './types/serverExecuteTypes.js';
|
|
4
|
+
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus } from './types/clientTypes.js';
|
|
5
|
+
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams } from './types/serverExecuteTypes.js';
|
|
6
6
|
export { TriggerServerDependency, TriggerServerPriceRequirement, TriggerServerPriceTriggerCriteria, TriggerServerTimeTriggerCriteria, TriggerServerTriggerCriteria } from './types/serverModelTypes.js';
|
|
7
7
|
export { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse } from './types/serverQueryTypes.js';
|
|
8
8
|
export { TriggerServerFailureError } from './types/TriggerServerFailureError.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/clientTypes.ts"],"sourcesContent":["import {\n EngineOrderParams,\n EngineServerExecuteResult,\n} from '@nadohq/engine-client';\nimport {\n BigDecimal,\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n OrderAppendix,\n Subaccount,\n} from '@nadohq/shared';\nimport { TriggerCriteria, TriggerOrderStatus } from './clientModelTypes';\nimport {\n TriggerServerOrder,\n TriggerServerStatusTypeFilter,\n TriggerServerTriggerTypeFilter,\n} from './serverQueryTypes';\n\ntype WithOptionalNonce<T> = Omit<T, 'nonce'> & { nonce?: string };\n\ninterface SignatureParams {\n /**\n * Address derived from productId for placement (see getOrderVerifyingAddr)\n * endpoint address for cancellation & listing\n */\n verifyingAddr: string;\n chainId: number;\n}\n\n/**\n * Executes\n */\n\nexport interface TriggerPlaceOrderParams extends SignatureParams {\n id?: number;\n productId: number;\n order: EngineOrderParams;\n triggerCriteria: TriggerCriteria;\n // If not given, engine defaults to true (leverage/borrow enabled)\n spotLeverage?: boolean;\n // For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDT balance)\n borrowMargin?: boolean;\n digest?: string;\n nonce?: string;\n}\n\nexport type TriggerCancelOrdersParams = SignatureParams &\n WithOptionalNonce<EIP712CancelOrdersParams>;\n\nexport type TriggerCancelProductOrdersParams = SignatureParams &\n WithOptionalNonce<EIP712CancelProductOrdersParams>;\n\n/**\n * Queries\n */\n\nexport interface TriggerListOrdersParams extends Subaccount, SignatureParams {\n // In millis, defaults to 90s in the future\n recvTime?: BigDecimal;\n // If not given, defaults to all products\n productIds?: number[];\n // In seconds\n maxUpdateTimeInclusive?: number;\n // When provided, the associated trigger orders are returned regardless of other filters\n digests?: string[];\n limit?: number;\n // Filter by status types\n statusTypes?: TriggerServerStatusTypeFilter[];\n // Filter by trigger types\n triggerTypes?: TriggerServerTriggerTypeFilter[];\n // Filter by reduce-only orders\n reduceOnly?: boolean;\n}\n\nexport interface TriggerOrder {\n productId: number;\n triggerCriteria: TriggerCriteria;\n price: BigDecimal;\n amount: BigDecimal;\n expiration: number;\n nonce: string;\n digest: string;\n appendix: OrderAppendix;\n}\n\nexport interface TriggerOrderInfo {\n order: TriggerOrder;\n serverOrder: TriggerServerOrder;\n status: TriggerOrderStatus;\n updatedAt: number;\n placementTime: number;\n}\n\nexport interface TriggerListOrdersResponse {\n orders: TriggerOrderInfo[];\n}\n\nexport interface TriggerListTwapExecutionsParams {\n digest: string;\n}\n\nexport type TwapExecutionStatus =\n | {\n type: 'pending';\n }\n | {\n type: 'executed';\n executedTime: number;\n executeResponse: EngineServerExecuteResult;\n }\n | {\n type: 'failed';\n error: string;\n }\n | {\n type: 'cancelled';\n reason: string;\n };\n\nexport interface TwapExecutionInfo {\n executionId: number;\n scheduledTime: number;\n status: TwapExecutionStatus;\n updatedAt: number;\n}\n\nexport interface TriggerListTwapExecutionsResponse {\n executions: TwapExecutionInfo[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/clientTypes.ts"],"sourcesContent":["import {\n EngineOrderParams,\n EngineServerExecuteResult,\n} from '@nadohq/engine-client';\nimport {\n BigDecimal,\n EIP712CancelOrdersParams,\n EIP712CancelProductOrdersParams,\n OrderAppendix,\n Subaccount,\n} from '@nadohq/shared';\nimport { TriggerCriteria, TriggerOrderStatus } from './clientModelTypes';\nimport {\n TriggerServerOrder,\n TriggerServerStatusTypeFilter,\n TriggerServerTriggerTypeFilter,\n} from './serverQueryTypes';\n\ntype WithOptionalNonce<T> = Omit<T, 'nonce'> & { nonce?: string };\n\ninterface SignatureParams {\n /**\n * Address derived from productId for placement (see getOrderVerifyingAddr)\n * endpoint address for cancellation & listing\n */\n verifyingAddr: string;\n chainId: number;\n}\n\n/**\n * Executes\n */\n\nexport interface TriggerPlaceOrderParams extends SignatureParams {\n id?: number;\n productId: number;\n order: EngineOrderParams;\n triggerCriteria: TriggerCriteria;\n // If not given, engine defaults to true (leverage/borrow enabled)\n spotLeverage?: boolean;\n // For isolated orders, this specifies whether margin can be borrowed (i.e. whether the cross account can have a negative USDT balance)\n borrowMargin?: boolean;\n digest?: string;\n nonce?: string;\n}\n\nexport interface TriggerPlaceOrdersParams {\n orders: TriggerPlaceOrderParams[];\n /**\n * If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.\n * If not provided, the default value is `false`.\n */\n cancelOnFailure?: boolean;\n}\n\nexport type TriggerCancelOrdersParams = SignatureParams &\n WithOptionalNonce<EIP712CancelOrdersParams>;\n\nexport type TriggerCancelProductOrdersParams = SignatureParams &\n WithOptionalNonce<EIP712CancelProductOrdersParams>;\n\n/**\n * Queries\n */\n\nexport interface TriggerListOrdersParams extends Subaccount, SignatureParams {\n // In millis, defaults to 90s in the future\n recvTime?: BigDecimal;\n // If not given, defaults to all products\n productIds?: number[];\n // In seconds\n maxUpdateTimeInclusive?: number;\n // When provided, the associated trigger orders are returned regardless of other filters\n digests?: string[];\n limit?: number;\n // Filter by status types\n statusTypes?: TriggerServerStatusTypeFilter[];\n // Filter by trigger types\n triggerTypes?: TriggerServerTriggerTypeFilter[];\n // Filter by reduce-only orders\n reduceOnly?: boolean;\n}\n\nexport interface TriggerOrder {\n productId: number;\n triggerCriteria: TriggerCriteria;\n price: BigDecimal;\n amount: BigDecimal;\n expiration: number;\n nonce: string;\n digest: string;\n appendix: OrderAppendix;\n}\n\nexport interface TriggerOrderInfo {\n order: TriggerOrder;\n serverOrder: TriggerServerOrder;\n status: TriggerOrderStatus;\n updatedAt: number;\n placementTime: number;\n}\n\nexport interface TriggerListOrdersResponse {\n orders: TriggerOrderInfo[];\n}\n\nexport interface TriggerListTwapExecutionsParams {\n digest: string;\n}\n\nexport type TwapExecutionStatus =\n | {\n type: 'pending';\n }\n | {\n type: 'executed';\n executedTime: number;\n executeResponse: EngineServerExecuteResult;\n }\n | {\n type: 'failed';\n error: string;\n }\n | {\n type: 'cancelled';\n reason: string;\n };\n\nexport interface TwapExecutionInfo {\n executionId: number;\n scheduledTime: number;\n status: TwapExecutionStatus;\n updatedAt: number;\n}\n\nexport interface TriggerListTwapExecutionsResponse {\n executions: TwapExecutionInfo[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -29,6 +29,14 @@ interface TriggerPlaceOrderParams extends SignatureParams {
|
|
|
29
29
|
digest?: string;
|
|
30
30
|
nonce?: string;
|
|
31
31
|
}
|
|
32
|
+
interface TriggerPlaceOrdersParams {
|
|
33
|
+
orders: TriggerPlaceOrderParams[];
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.
|
|
36
|
+
* If not provided, the default value is `false`.
|
|
37
|
+
*/
|
|
38
|
+
cancelOnFailure?: boolean;
|
|
39
|
+
}
|
|
32
40
|
type TriggerCancelOrdersParams = SignatureParams & WithOptionalNonce<EIP712CancelOrdersParams>;
|
|
33
41
|
type TriggerCancelProductOrdersParams = SignatureParams & WithOptionalNonce<EIP712CancelProductOrdersParams>;
|
|
34
42
|
/**
|
|
@@ -90,4 +98,4 @@ interface TriggerListTwapExecutionsResponse {
|
|
|
90
98
|
executions: TwapExecutionInfo[];
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
export type { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus };
|
|
101
|
+
export type { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus };
|
|
@@ -29,6 +29,14 @@ interface TriggerPlaceOrderParams extends SignatureParams {
|
|
|
29
29
|
digest?: string;
|
|
30
30
|
nonce?: string;
|
|
31
31
|
}
|
|
32
|
+
interface TriggerPlaceOrdersParams {
|
|
33
|
+
orders: TriggerPlaceOrderParams[];
|
|
34
|
+
/**
|
|
35
|
+
* If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.
|
|
36
|
+
* If not provided, the default value is `false`.
|
|
37
|
+
*/
|
|
38
|
+
cancelOnFailure?: boolean;
|
|
39
|
+
}
|
|
32
40
|
type TriggerCancelOrdersParams = SignatureParams & WithOptionalNonce<EIP712CancelOrdersParams>;
|
|
33
41
|
type TriggerCancelProductOrdersParams = SignatureParams & WithOptionalNonce<EIP712CancelProductOrdersParams>;
|
|
34
42
|
/**
|
|
@@ -90,4 +98,4 @@ interface TriggerListTwapExecutionsResponse {
|
|
|
90
98
|
executions: TwapExecutionInfo[];
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
export type { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus };
|
|
101
|
+
export type { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus };
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PriceTriggerCriteria, PriceTriggerDependency, PriceTriggerRequirementType, TimeTriggerCriteria, TriggerCriteria, TriggerCriteriaType, TriggerOrderStatus } from './clientModelTypes.cjs';
|
|
2
|
-
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus } from './clientTypes.cjs';
|
|
3
|
-
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams } from './serverExecuteTypes.cjs';
|
|
2
|
+
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus } from './clientTypes.cjs';
|
|
3
|
+
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams } from './serverExecuteTypes.cjs';
|
|
4
4
|
export { TriggerServerDependency, TriggerServerPriceRequirement, TriggerServerPriceTriggerCriteria, TriggerServerTimeTriggerCriteria, TriggerServerTriggerCriteria } from './serverModelTypes.cjs';
|
|
5
5
|
export { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse } from './serverQueryTypes.cjs';
|
|
6
6
|
export { TriggerServerFailureError } from './TriggerServerFailureError.cjs';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { PriceTriggerCriteria, PriceTriggerDependency, PriceTriggerRequirementType, TimeTriggerCriteria, TriggerCriteria, TriggerCriteriaType, TriggerOrderStatus } from './clientModelTypes.js';
|
|
2
|
-
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TwapExecutionInfo, TwapExecutionStatus } from './clientTypes.js';
|
|
3
|
-
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams } from './serverExecuteTypes.js';
|
|
2
|
+
export { TriggerCancelOrdersParams, TriggerCancelProductOrdersParams, TriggerListOrdersParams, TriggerListOrdersResponse, TriggerListTwapExecutionsParams, TriggerListTwapExecutionsResponse, TriggerOrder, TriggerOrderInfo, TriggerPlaceOrderParams, TriggerPlaceOrdersParams, TwapExecutionInfo, TwapExecutionStatus } from './clientTypes.js';
|
|
3
|
+
export { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams } from './serverExecuteTypes.js';
|
|
4
4
|
export { TriggerServerDependency, TriggerServerPriceRequirement, TriggerServerPriceTriggerCriteria, TriggerServerTimeTriggerCriteria, TriggerServerTriggerCriteria } from './serverModelTypes.js';
|
|
5
5
|
export { TriggerServerCancelReason, TriggerServerListTriggerOrdersParams, TriggerServerListTriggerOrdersResponse, TriggerServerListTwapExecutionsParams, TriggerServerOrder, TriggerServerOrderInfo, TriggerServerOrderStatus, TriggerServerQueryFailureResponse, TriggerServerQueryRequestByType, TriggerServerQueryRequestType, TriggerServerQueryResponse, TriggerServerQueryResponseByType, TriggerServerQuerySuccessResponse, TriggerServerStatusTypeFilter, TriggerServerTriggerTypeFilter, TriggerServerTwapExecutionInfo, TriggerServerTwapExecutionStatus, TriggerServerTwapExecutionsResponse } from './serverQueryTypes.js';
|
|
6
6
|
export { TriggerServerFailureError } from './TriggerServerFailureError.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/serverExecuteTypes.ts"],"sourcesContent":["import {\n EngineServerExecuteFailureResult,\n EngineServerExecuteRequestByType,\n EngineServerExecuteSuccessResult,\n} from '@nadohq/engine-client';\nimport { EIP712OrderValues } from '@nadohq/shared';\nimport { TriggerServerTriggerCriteria } from './serverModelTypes';\n\nexport interface TriggerServerPlaceOrderParams {\n id: number | null;\n product_id: number;\n order: EIP712OrderValues;\n trigger: TriggerServerTriggerCriteria;\n signature: string;\n digest: string | null;\n // Trigger service defaults this to true\n spot_leverage: boolean | null;\n borrow_margin: boolean | null;\n}\n\nexport type TriggerServerCancelOrdersParams =\n EngineServerExecuteRequestByType['cancel_orders'];\n\nexport type TriggerServerCancelProductOrdersParams =\n EngineServerExecuteRequestByType['cancel_product_orders'];\n\nexport interface TriggerServerExecuteRequestByType {\n place_order: TriggerServerPlaceOrderParams;\n cancel_orders: TriggerServerCancelOrdersParams;\n cancel_product_orders: TriggerServerCancelProductOrdersParams;\n}\n\nexport type TriggerServerExecuteRequestType =\n keyof TriggerServerExecuteRequestByType;\n\nexport type TriggerServerExecuteSuccessResult<\n T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType,\n> = EngineServerExecuteSuccessResult<T>;\n\nexport type TriggerServerExecuteResult<\n T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType,\n> = TriggerServerExecuteSuccessResult<T> | EngineServerExecuteFailureResult;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/serverExecuteTypes.ts"],"sourcesContent":["import {\n EngineServerExecuteFailureResult,\n EngineServerExecuteRequestByType,\n EngineServerExecuteSuccessResult,\n} from '@nadohq/engine-client';\nimport { EIP712OrderValues } from '@nadohq/shared';\nimport { TriggerServerTriggerCriteria } from './serverModelTypes';\n\nexport interface TriggerServerPlaceOrderParams {\n id: number | null;\n product_id: number;\n order: EIP712OrderValues;\n trigger: TriggerServerTriggerCriteria;\n signature: string;\n digest: string | null;\n // Trigger service defaults this to true\n spot_leverage: boolean | null;\n borrow_margin: boolean | null;\n}\n\nexport type TriggerServerCancelOrdersParams =\n EngineServerExecuteRequestByType['cancel_orders'];\n\nexport type TriggerServerCancelProductOrdersParams =\n EngineServerExecuteRequestByType['cancel_product_orders'];\n\nexport interface TriggerServerPlaceOrdersParams {\n orders: TriggerServerPlaceOrderParams[];\n cancel_on_failure: boolean | null;\n}\n\nexport interface TriggerServerExecuteRequestByType {\n place_order: TriggerServerPlaceOrderParams;\n place_orders: TriggerServerPlaceOrdersParams;\n cancel_orders: TriggerServerCancelOrdersParams;\n cancel_product_orders: TriggerServerCancelProductOrdersParams;\n}\n\nexport type TriggerServerExecuteRequestType =\n keyof TriggerServerExecuteRequestByType;\n\nexport type TriggerServerExecuteSuccessResult<\n T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType,\n> = EngineServerExecuteSuccessResult<T>;\n\nexport type TriggerServerExecuteResult<\n T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType,\n> = TriggerServerExecuteSuccessResult<T> | EngineServerExecuteFailureResult;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -14,8 +14,13 @@ interface TriggerServerPlaceOrderParams {
|
|
|
14
14
|
}
|
|
15
15
|
type TriggerServerCancelOrdersParams = EngineServerExecuteRequestByType['cancel_orders'];
|
|
16
16
|
type TriggerServerCancelProductOrdersParams = EngineServerExecuteRequestByType['cancel_product_orders'];
|
|
17
|
+
interface TriggerServerPlaceOrdersParams {
|
|
18
|
+
orders: TriggerServerPlaceOrderParams[];
|
|
19
|
+
cancel_on_failure: boolean | null;
|
|
20
|
+
}
|
|
17
21
|
interface TriggerServerExecuteRequestByType {
|
|
18
22
|
place_order: TriggerServerPlaceOrderParams;
|
|
23
|
+
place_orders: TriggerServerPlaceOrdersParams;
|
|
19
24
|
cancel_orders: TriggerServerCancelOrdersParams;
|
|
20
25
|
cancel_product_orders: TriggerServerCancelProductOrdersParams;
|
|
21
26
|
}
|
|
@@ -23,4 +28,4 @@ type TriggerServerExecuteRequestType = keyof TriggerServerExecuteRequestByType;
|
|
|
23
28
|
type TriggerServerExecuteSuccessResult<T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType> = EngineServerExecuteSuccessResult<T>;
|
|
24
29
|
type TriggerServerExecuteResult<T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType> = TriggerServerExecuteSuccessResult<T> | EngineServerExecuteFailureResult;
|
|
25
30
|
|
|
26
|
-
export type { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams };
|
|
31
|
+
export type { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams };
|
|
@@ -14,8 +14,13 @@ interface TriggerServerPlaceOrderParams {
|
|
|
14
14
|
}
|
|
15
15
|
type TriggerServerCancelOrdersParams = EngineServerExecuteRequestByType['cancel_orders'];
|
|
16
16
|
type TriggerServerCancelProductOrdersParams = EngineServerExecuteRequestByType['cancel_product_orders'];
|
|
17
|
+
interface TriggerServerPlaceOrdersParams {
|
|
18
|
+
orders: TriggerServerPlaceOrderParams[];
|
|
19
|
+
cancel_on_failure: boolean | null;
|
|
20
|
+
}
|
|
17
21
|
interface TriggerServerExecuteRequestByType {
|
|
18
22
|
place_order: TriggerServerPlaceOrderParams;
|
|
23
|
+
place_orders: TriggerServerPlaceOrdersParams;
|
|
19
24
|
cancel_orders: TriggerServerCancelOrdersParams;
|
|
20
25
|
cancel_product_orders: TriggerServerCancelProductOrdersParams;
|
|
21
26
|
}
|
|
@@ -23,4 +28,4 @@ type TriggerServerExecuteRequestType = keyof TriggerServerExecuteRequestByType;
|
|
|
23
28
|
type TriggerServerExecuteSuccessResult<T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType> = EngineServerExecuteSuccessResult<T>;
|
|
24
29
|
type TriggerServerExecuteResult<T extends TriggerServerExecuteRequestType = TriggerServerExecuteRequestType> = TriggerServerExecuteSuccessResult<T> | EngineServerExecuteFailureResult;
|
|
25
30
|
|
|
26
|
-
export type { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams };
|
|
31
|
+
export type { TriggerServerCancelOrdersParams, TriggerServerCancelProductOrdersParams, TriggerServerExecuteRequestByType, TriggerServerExecuteRequestType, TriggerServerExecuteResult, TriggerServerExecuteSuccessResult, TriggerServerPlaceOrderParams, TriggerServerPlaceOrdersParams };
|
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.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "> TODO: description",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@nadohq/engine-client": "^0.1.0-alpha.
|
|
41
|
-
"@nadohq/shared": "^0.1.0-alpha.
|
|
40
|
+
"@nadohq/engine-client": "^0.1.0-alpha.30",
|
|
41
|
+
"@nadohq/shared": "^0.1.0-alpha.30",
|
|
42
42
|
"axios": "*",
|
|
43
43
|
"ts-mixer": "*"
|
|
44
44
|
},
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"viem": "*"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "f91906311b3dfc22e8e174d5ed8fa459ec812a08"
|
|
52
52
|
}
|
package/src/TriggerClient.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
TriggerListTwapExecutionsResponse,
|
|
29
29
|
TriggerOrderInfo,
|
|
30
30
|
TriggerPlaceOrderParams,
|
|
31
|
+
TriggerPlaceOrdersParams,
|
|
31
32
|
TriggerServerExecuteRequestByType,
|
|
32
33
|
TriggerServerExecuteRequestType,
|
|
33
34
|
TriggerServerExecuteResult,
|
|
@@ -82,34 +83,23 @@ export class TriggerClient {
|
|
|
82
83
|
*/
|
|
83
84
|
|
|
84
85
|
async placeTriggerOrder(params: TriggerPlaceOrderParams) {
|
|
85
|
-
|
|
86
|
-
amount: params.order.amount,
|
|
87
|
-
expiration: params.order.expiration,
|
|
88
|
-
price: params.order.price,
|
|
89
|
-
subaccountName: params.order.subaccountName,
|
|
90
|
-
subaccountOwner: params.order.subaccountOwner,
|
|
91
|
-
nonce: params.nonce ?? getOrderNonce(),
|
|
92
|
-
appendix: params.order.appendix,
|
|
93
|
-
};
|
|
94
|
-
const signature = await this.sign(
|
|
86
|
+
return this.execute(
|
|
95
87
|
'place_order',
|
|
96
|
-
params
|
|
97
|
-
params.chainId,
|
|
98
|
-
orderParams,
|
|
88
|
+
await this.buildPlaceOrderExecuteParams(params),
|
|
99
89
|
);
|
|
90
|
+
}
|
|
100
91
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
borrow_margin: params.borrowMargin ?? null,
|
|
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,
|
|
110
100
|
};
|
|
111
101
|
|
|
112
|
-
return this.execute('
|
|
102
|
+
return this.execute('place_orders', executeParams);
|
|
113
103
|
}
|
|
114
104
|
|
|
115
105
|
async cancelTriggerOrders(params: TriggerCancelOrdersParams) {
|
|
@@ -232,6 +222,38 @@ export class TriggerClient {
|
|
|
232
222
|
/*
|
|
233
223
|
Base Fns
|
|
234
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
|
+
|
|
235
257
|
protected async sign<T extends SignableRequestType>(
|
|
236
258
|
requestType: T,
|
|
237
259
|
verifyingContract: string,
|
package/src/types/clientTypes.ts
CHANGED
|
@@ -44,6 +44,15 @@ export interface TriggerPlaceOrderParams extends SignatureParams {
|
|
|
44
44
|
nonce?: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
export interface TriggerPlaceOrdersParams {
|
|
48
|
+
orders: TriggerPlaceOrderParams[];
|
|
49
|
+
/**
|
|
50
|
+
* If `true`, aborts the batch after the first failed order; if `false`, remaining orders continue to execute.
|
|
51
|
+
* If not provided, the default value is `false`.
|
|
52
|
+
*/
|
|
53
|
+
cancelOnFailure?: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
export type TriggerCancelOrdersParams = SignatureParams &
|
|
48
57
|
WithOptionalNonce<EIP712CancelOrdersParams>;
|
|
49
58
|
|
|
@@ -24,8 +24,14 @@ export type TriggerServerCancelOrdersParams =
|
|
|
24
24
|
export type TriggerServerCancelProductOrdersParams =
|
|
25
25
|
EngineServerExecuteRequestByType['cancel_product_orders'];
|
|
26
26
|
|
|
27
|
+
export interface TriggerServerPlaceOrdersParams {
|
|
28
|
+
orders: TriggerServerPlaceOrderParams[];
|
|
29
|
+
cancel_on_failure: boolean | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
export interface TriggerServerExecuteRequestByType {
|
|
28
33
|
place_order: TriggerServerPlaceOrderParams;
|
|
34
|
+
place_orders: TriggerServerPlaceOrdersParams;
|
|
29
35
|
cancel_orders: TriggerServerCancelOrdersParams;
|
|
30
36
|
cancel_product_orders: TriggerServerCancelProductOrdersParams;
|
|
31
37
|
}
|