@nadohq/engine-client 0.21.2 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{EngineBaseClient-a2leWTER.d.cts → EngineBaseClient-D4T3zroY.d.cts} +2 -2
- package/dist/{EngineBaseClient-a2leWTER.d.cts.map → EngineBaseClient-D4T3zroY.d.cts.map} +1 -1
- package/dist/{EngineBaseClient-zgQmbhJv.cjs → EngineBaseClient-J3nMzK0q.cjs} +5 -2
- package/dist/{EngineBaseClient-zgQmbhJv.cjs.map → EngineBaseClient-J3nMzK0q.cjs.map} +1 -1
- package/dist/{EngineBaseClient-Cn4PMYKt.d.ts → EngineBaseClient-whwZCdGv.d.ts} +2 -2
- package/dist/{EngineBaseClient-Cn4PMYKt.d.ts.map → EngineBaseClient-whwZCdGv.d.ts.map} +1 -1
- package/dist/EngineBaseClient.cjs +1 -1
- package/dist/EngineBaseClient.d.cts +1 -1
- package/dist/EngineBaseClient.d.ts +1 -1
- package/dist/EngineBaseClient.js +4 -1
- package/dist/EngineBaseClient.js.map +1 -1
- package/dist/EngineClient.cjs +1 -1
- package/dist/EngineClient.d.cts +4 -4
- package/dist/EngineClient.d.ts +4 -4
- package/dist/{EngineEdgeQueryClient-B9Y8srJa.d.ts → EngineEdgeQueryClient-B08kww7l.d.ts} +2 -2
- package/dist/{EngineEdgeQueryClient-B9Y8srJa.d.ts.map → EngineEdgeQueryClient-B08kww7l.d.ts.map} +1 -1
- package/dist/{EngineEdgeQueryClient-CPEDAOd0.d.cts → EngineEdgeQueryClient-C3p1nRLs.d.cts} +2 -2
- package/dist/{EngineEdgeQueryClient-CPEDAOd0.d.cts.map → EngineEdgeQueryClient-C3p1nRLs.d.cts.map} +1 -1
- package/dist/EngineEdgeQueryClient.cjs +1 -1
- package/dist/EngineEdgeQueryClient.d.cts +1 -1
- package/dist/EngineEdgeQueryClient.d.ts +1 -1
- package/dist/{EngineExecuteBuilder-BXKoW0uz.d.ts → EngineExecuteBuilder-BHX9mMqF.d.ts} +10 -4
- package/dist/EngineExecuteBuilder-BHX9mMqF.d.ts.map +1 -0
- package/dist/{EngineExecuteBuilder-BaMHTuf-.d.cts → EngineExecuteBuilder-CEqUxV3h.d.cts} +10 -4
- package/dist/EngineExecuteBuilder-CEqUxV3h.d.cts.map +1 -0
- package/dist/EngineExecuteBuilder.cjs +18 -1
- package/dist/EngineExecuteBuilder.cjs.map +1 -1
- package/dist/EngineExecuteBuilder.d.cts +1 -1
- package/dist/EngineExecuteBuilder.d.ts +1 -1
- package/dist/EngineExecuteBuilder.js +17 -0
- package/dist/EngineExecuteBuilder.js.map +1 -1
- package/dist/{EngineExecuteClient-BLUkw1vR.d.cts → EngineExecuteClient-D9e8FLa1.d.ts} +6 -5
- package/dist/EngineExecuteClient-D9e8FLa1.d.ts.map +1 -0
- package/dist/{EngineExecuteClient-ReEcySA_.d.ts → EngineExecuteClient-DOHSrQA-.d.cts} +6 -5
- package/dist/EngineExecuteClient-DOHSrQA-.d.cts.map +1 -0
- package/dist/EngineExecuteClient.cjs +4 -1
- package/dist/EngineExecuteClient.cjs.map +1 -1
- package/dist/EngineExecuteClient.d.cts +1 -1
- package/dist/EngineExecuteClient.d.ts +1 -1
- package/dist/EngineExecuteClient.js +3 -0
- package/dist/EngineExecuteClient.js.map +1 -1
- package/dist/{EngineQueryClient-C0xBMTo-.d.ts → EngineQueryClient-BaSojnvg.d.ts} +2 -2
- package/dist/{EngineQueryClient-C0xBMTo-.d.ts.map → EngineQueryClient-BaSojnvg.d.ts.map} +1 -1
- package/dist/{EngineQueryClient-Br-BC5LQ.d.cts → EngineQueryClient-CFj0O4CZ.d.cts} +2 -2
- package/dist/{EngineQueryClient-Br-BC5LQ.d.cts.map → EngineQueryClient-CFj0O4CZ.d.cts.map} +1 -1
- package/dist/EngineQueryClient.cjs +1 -1
- package/dist/EngineQueryClient.d.cts +1 -1
- package/dist/EngineQueryClient.d.ts +1 -1
- package/dist/{EngineServerFailureError-CDabRrF4.d.ts → EngineServerFailureError-CoxR__4r.d.ts} +2 -2
- package/dist/{EngineServerFailureError-CDabRrF4.d.ts.map → EngineServerFailureError-CoxR__4r.d.ts.map} +1 -1
- package/dist/{EngineServerFailureError-DpPY0--L.d.cts → EngineServerFailureError-DXzDAMoK.d.cts} +2 -2
- package/dist/{EngineServerFailureError-DpPY0--L.d.cts.map → EngineServerFailureError-DXzDAMoK.d.cts.map} +1 -1
- package/dist/{EngineWebClient-i8BslipN.d.cts → EngineWebClient-C-h4ipO4.d.cts} +2 -2
- package/dist/{EngineWebClient-i8BslipN.d.cts.map → EngineWebClient-C-h4ipO4.d.cts.map} +1 -1
- package/dist/{EngineWebClient-KXOdpUol.d.ts → EngineWebClient-CTky4iyV.d.ts} +2 -2
- package/dist/{EngineWebClient-KXOdpUol.d.ts.map → EngineWebClient-CTky4iyV.d.ts.map} +1 -1
- package/dist/EngineWebClient.cjs +1 -1
- package/dist/EngineWebClient.d.cts +1 -1
- package/dist/EngineWebClient.d.ts +1 -1
- package/dist/{clientExecuteTypes-CJ08_c4q.d.ts → clientExecuteTypes-4OzB-7to.d.cts} +6 -4
- package/dist/clientExecuteTypes-4OzB-7to.d.cts.map +1 -0
- package/dist/{clientExecuteTypes-BlJOgCL_.d.cts → clientExecuteTypes-BlfIar6f.d.ts} +6 -4
- package/dist/clientExecuteTypes-BlfIar6f.d.ts.map +1 -0
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/{serverExecuteTypes-DejTR8Is.d.cts → serverExecuteTypes-B65abv01.d.cts} +4 -2
- package/dist/serverExecuteTypes-B65abv01.d.cts.map +1 -0
- package/dist/{serverExecuteTypes-CgbHjnWM.d.ts → serverExecuteTypes-DTy8xAJp.d.ts} +4 -2
- package/dist/serverExecuteTypes-DTy8xAJp.d.ts.map +1 -0
- package/dist/types/EngineServerFailureError.d.cts +1 -1
- package/dist/types/EngineServerFailureError.d.ts +1 -1
- package/dist/types/clientExecuteTypes.d.cts +2 -2
- package/dist/types/clientExecuteTypes.d.ts +2 -2
- package/dist/types/index.d.cts +4 -4
- package/dist/types/index.d.ts +4 -4
- package/dist/types/serverExecuteTypes.d.cts +1 -1
- package/dist/types/serverExecuteTypes.d.ts +1 -1
- package/dist/utils/productEngineTypeMappers.cjs +1 -1
- package/dist/utils/queryDataMappers.cjs +1 -1
- package/package.json +5 -5
- package/src/EngineBaseClient.ts +8 -2
- package/src/EngineExecuteBuilder.ts +24 -0
- package/src/EngineExecuteClient.ts +9 -0
- package/src/types/clientExecuteTypes.ts +6 -0
- package/src/types/serverExecuteTypes.ts +5 -0
- package/dist/EngineExecuteBuilder-BXKoW0uz.d.ts.map +0 -1
- package/dist/EngineExecuteBuilder-BaMHTuf-.d.cts.map +0 -1
- package/dist/EngineExecuteClient-BLUkw1vR.d.cts.map +0 -1
- package/dist/EngineExecuteClient-ReEcySA_.d.ts.map +0 -1
- package/dist/clientExecuteTypes-BlJOgCL_.d.cts.map +0 -1
- package/dist/clientExecuteTypes-CJ08_c4q.d.ts.map +0 -1
- package/dist/serverExecuteTypes-CgbHjnWM.d.ts.map +0 -1
- package/dist/serverExecuteTypes-DejTR8Is.d.cts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { G as EngineServerQueryResponseByType, H as EngineServerQueryRequestByType, U as EngineServerQueryRequestType } from "./serverQueryTypes-Dva9R2tV.cjs";
|
|
2
|
-
import { a as EngineServerExecuteRequestByType, l as EngineServerExecuteSuccessResult, o as EngineServerExecuteRequestType } from "./serverExecuteTypes-
|
|
2
|
+
import { a as EngineServerExecuteRequestByType, l as EngineServerExecuteSuccessResult, o as EngineServerExecuteRequestType } from "./serverExecuteTypes-B65abv01.cjs";
|
|
3
3
|
import { G as GetEngineNoncesResponse, W as GetEngineNoncesParams } from "./clientQueryTypes-BTKfuoGI.cjs";
|
|
4
4
|
import { a as EngineServerCachedQueryRequestByType, c as EngineServerCachedQueryResponseByType, d as EngineServerEdgeControlRequestByType, f as EngineServerEdgeControlRequestType, o as EngineServerCachedQueryRequestType, p as EngineServerEdgeControlResponseByType } from "./serverEdgeQueryTypes-BpMlbsCD.cjs";
|
|
5
5
|
import { SignableRequestType, SignableRequestTypeToParams, WalletClientWithAccount } from "@nadohq/shared";
|
|
@@ -97,4 +97,4 @@ declare class EngineBaseClient {
|
|
|
97
97
|
}
|
|
98
98
|
//#endregion
|
|
99
99
|
export { EngineClientOpts as n, EngineBaseClient as t };
|
|
100
|
-
//# sourceMappingURL=EngineBaseClient-
|
|
100
|
+
//# sourceMappingURL=EngineBaseClient-D4T3zroY.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineBaseClient-
|
|
1
|
+
{"version":3,"file":"EngineBaseClient-D4T3zroY.d.cts","names":[],"sources":["../src/src/EngineBaseClient.ts"],"mappings":";;;;;;;;UA+BiB,gBAAA;EAEf,GAAA;EAEA,YAAA,GAAe,uBAAA;EAEf,wBAAA,GAA2B,uBAAuB;AAAA;AAAA,KAI/C,wBAAA,GAA2B,OAAO,CAAC,gCAAA;AAVxC;;;AAAA,cAwBa,gBAAA;EAAA,SACF,IAAA,EAAM,gBAAA;EAAA,SACN,aAAA,EAAe,aAAA;cAEZ,IAAA,EAAM,gBAAA;EAtBlB;;;AAAkD;AACnD;EAmCQ,eAAA,CACL,wBAAA,EAA0B,uBAAA;EAKf,UAAA,CAAW,OAAA,YAAmB,OAAA;EAc9B,SAAA,CACX,MAAA,EAAQ,qBAAA,GACP,OAAA,CAAQ,uBAAA;EAtD2D;AAcxE;;;;;;EAwDe,KAAA,sBAA2B,4BAAA,CAAA,CACtC,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,8BAAA,CAA+B,YAAA,IACtC,OAAA,CAAQ,+BAAA,CAAgC,YAAA;EAnCA;;;;;;;;;EA8D9B,SAAA,sBACU,kCAAA,CAAA,CAErB,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,oCAAA,CAAqC,YAAA,IAC5C,OAAA,CAAQ,qCAAA,CAAsC,YAAA;EAhC9C;;;;;;;;;EA4DU,gBAAA,sBACU,kCAAA,CAAA,CAErB,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,oCAAA,CAAqC,YAAA,IAC5C,OAAA,CAAQ,qCAAA,CAAsC,YAAA;EADvC;;;;;;;;EAqBG,OAAA,sBAA6B,8BAAA,CAAA,CACxC,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,gCAAA,CAAiC,YAAA,IACxC,OAAA,CAAQ,gCAAA,CAAiC,YAAA;EAAA;;;;;;;;EAqBrC,eAAA,qDAAA,CACL,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,OAAA;IACL,IAAA,EAAM,YAAA;EAAA,IAAiB,OAAA;EAgBzB;;;;;;EAHI,iBAAA,sBAAuC,8BAAA,CAAA,CAC5C,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,gCAAA,CAAiC,YAAA,IACxC,wBAAA;EAmBqC;;;;;;;;;EAJ3B,IAAA,WAAe,mBAAA,CAAA,CAC1B,WAAA,EAAa,CAAA,EACb,iBAAA,UACA,OAAA,UACA,MAAA,EAAQ,2BAAA,CAA4B,CAAA,IAAE,OAAA;EAAA,QAyBhC,mBAAA;EAAA,QAQA,iBAAA;AAAA"}
|
|
@@ -150,7 +150,10 @@ var EngineBaseClient = class {
|
|
|
150
150
|
* @public
|
|
151
151
|
*/
|
|
152
152
|
async sign(requestType, verifyingContract, chainId, params) {
|
|
153
|
-
const walletClient =
|
|
153
|
+
const walletClient = (() => {
|
|
154
|
+
if (requestType === "withdraw_collateral_v2") return this.opts.walletClient;
|
|
155
|
+
return this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
156
|
+
})();
|
|
154
157
|
if (!walletClient) throw new _nadohq_shared.WalletNotProvidedError();
|
|
155
158
|
return (0, _nadohq_shared.getSignedTransactionRequest)({
|
|
156
159
|
chainId,
|
|
@@ -181,4 +184,4 @@ Object.defineProperty(exports, "__toESM", {
|
|
|
181
184
|
}
|
|
182
185
|
});
|
|
183
186
|
|
|
184
|
-
//# sourceMappingURL=EngineBaseClient-
|
|
187
|
+
//# sourceMappingURL=EngineBaseClient-J3nMzK0q.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineBaseClient-zgQmbhJv.cjs","names":["WalletNotProvidedError","successResponse","EngineServerFailureError"],"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerCachedQueryRequestByType,\n EngineServerCachedQueryRequestType,\n EngineServerCachedQueryResponse,\n EngineServerCachedQueryResponseByType,\n EngineServerCachedQuerySuccessResponse,\n EngineServerEdgeControlRequestByType,\n EngineServerEdgeControlRequestType,\n EngineServerEdgeControlResponseByType,\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequestByType,\n EngineServerQueryRequestType,\n EngineServerQueryResponse,\n EngineServerQueryResponseByType,\n EngineServerQuerySuccessResponse,\n GetEngineNoncesParams,\n GetEngineNoncesResponse,\n} from './types';\nimport { EngineServerFailureError } from './types/EngineServerFailureError';\n\nexport interface EngineClientOpts {\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// Only 1 key can be defined per execute request\ntype EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;\n\ntype EngineQueryRequestResponse<\n T extends EngineServerQueryRequestType = EngineServerQueryRequestType,\n> = EngineServerQueryResponse<T>;\n\ntype EngineCachedQueryRequestResponse<\n T extends EngineServerCachedQueryRequestType =\n EngineServerCachedQueryRequestType,\n> = EngineServerCachedQueryResponse<T>;\n\n/**\n * Base client for all engine requests\n */\nexport class EngineBaseClient {\n readonly opts: EngineClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: EngineClientOpts) {\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 execute 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 public async getTxNonce(address?: string): Promise<string> {\n const addr = address ?? this.opts.walletClient?.account.address;\n\n if (!addr) {\n throw new WalletNotProvidedError();\n }\n\n return (\n await this.getNonces({\n address: addr,\n })\n ).txNonce;\n }\n\n public async getNonces(\n params: GetEngineNoncesParams,\n ): Promise<GetEngineNoncesResponse> {\n const baseResp = await this.query('nonces', params);\n\n return {\n orderNonce: baseResp.order_nonce,\n txNonce: baseResp.tx_nonce,\n };\n }\n\n /**\n * Queries the engine, all query params are stringified into the query string\n *\n * @param requestType\n * @param params\n * @public\n */\n public async query<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): Promise<EngineServerQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<EngineQueryRequestResponse>(\n `${this.opts.url}/query`,\n request,\n );\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 EngineServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Queries the gateway's in-memory cache via the `/edge/query` endpoint. Lower latency than\n * {@link query} at the cost of eventual consistency — do not use for order, margin, or\n * settlement decisions.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeQuery<\n TRequestType extends EngineServerCachedQueryRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerCachedQueryRequestByType[TRequestType],\n ): Promise<EngineServerCachedQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response =\n await this.axiosInstance.post<EngineCachedQueryRequestResponse>(\n `${this.opts.url}/edge/query`,\n request,\n );\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 EngineServerCachedQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Sends an edge control message (`ping` / `time`) via the `/edge/query` endpoint. These\n * return immediately from the server clock and use a different envelope than the cached data\n * queries (no `data` field), so the whole response body is returned.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeControlQuery<\n TRequestType extends EngineServerEdgeControlRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerEdgeControlRequestByType[TRequestType],\n ): Promise<EngineServerEdgeControlResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerEdgeControlResponseByType[TRequestType]\n >(`${this.opts.url}/edge/query`, request);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n return response.data;\n }\n\n /**\n * POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped\n * in an EngineServerFailureError on failure.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async execute<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): Promise<EngineServerExecuteSuccessResult<TRequestType>> {\n const reqBody = this.getExecuteRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerExecuteResult<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 EngineServerExecuteSuccessResult<TRequestType>;\n }\n\n /**\n * A simple, typechecked fn for constructing a `type`-tagged request body in the format expected\n * by the server. Generic over the request type / params pair so it can build live query, edge\n * (cached) query, and edge control request bodies alike.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends string, TParams extends object>(\n requestType: TRequestType,\n params: TParams,\n ): { type: TRequestType } & TParams {\n return {\n type: requestType,\n ...params,\n };\n }\n\n /**\n * A simple, typechecked fn for constructing an execute request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): EngineExecuteRequestBody {\n return {\n [requestType]: params,\n };\n }\n\n /**\n * Signs a given request with the signer provided to the engine\n *\n * @param requestType\n * @param verifyingContract\n * @param chainId\n * @param params\n * @public\n */\n public 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) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\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 | EngineServerExecuteResult\n | EngineQueryRequestResponse\n | EngineCachedQueryRequestResponse\n | EngineServerEdgeControlResponseByType[EngineServerEdgeControlRequestType]\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,MAAwB;EAClC,KAAK,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;;;;CAUA,MAAa,QACX,aACA,QACyD;EACzD,MAAM,UAAU,KAAK,kBAAkB,aAAa,MAAM;EAC1D,MAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,IAAI,WAAW,OAAO;EAErC,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAG/B,OAAO,SAAS;CAClB;;;;;;;;;CAUA,gBACE,aACA,QACkC;EAClC,OAAO;GACL,MAAM;GACN,GAAG;EACL;CACF;;;;;;;CAQA,kBACE,aACA,QAC0B;EAC1B,OAAO,GACJ,cAAc,OACjB;CACF;;;;;;;;;;CAWA,MAAa,KACX,aACA,mBACA,SACA,QACA;EAEA,MAAM,eACJ,KAAK,KAAK,4BAA4B,KAAK,KAAK;EAElD,IAAI,CAAC,cACH,MAAM,IAAID,eAAAA,uBAAuB;EAGnC,QAAA,GAAA,eAAA,6BAAmC;GACjC;GACA,eAAe;GACf;GACA;GACA;EACF,CAAC;CACH;CAEA,oBAA4B,UAAyB;EACnD,IAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MACvC,MAAM,MACJ,oCAAoC,SAAS,OAAO,GAAG,SAAS,WAAW,UAAU,SAAS,MAChG;CAEJ;CAEA,kBACE,UAMA;EACA,IAAI,SAAS,KAAK,WAAW,WAC3B,MAAM,IAAIE,uCAAAA,yBAAyB,SAAS,IAAI;CAEpD;AACF"}
|
|
1
|
+
{"version":3,"file":"EngineBaseClient-J3nMzK0q.cjs","names":["WalletNotProvidedError","successResponse","EngineServerFailureError"],"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerCachedQueryRequestByType,\n EngineServerCachedQueryRequestType,\n EngineServerCachedQueryResponse,\n EngineServerCachedQueryResponseByType,\n EngineServerCachedQuerySuccessResponse,\n EngineServerEdgeControlRequestByType,\n EngineServerEdgeControlRequestType,\n EngineServerEdgeControlResponseByType,\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequestByType,\n EngineServerQueryRequestType,\n EngineServerQueryResponse,\n EngineServerQueryResponseByType,\n EngineServerQuerySuccessResponse,\n GetEngineNoncesParams,\n GetEngineNoncesResponse,\n} from './types';\nimport { EngineServerFailureError } from './types/EngineServerFailureError';\n\nexport interface EngineClientOpts {\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// Only 1 key can be defined per execute request\ntype EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;\n\ntype EngineQueryRequestResponse<\n T extends EngineServerQueryRequestType = EngineServerQueryRequestType,\n> = EngineServerQueryResponse<T>;\n\ntype EngineCachedQueryRequestResponse<\n T extends EngineServerCachedQueryRequestType =\n EngineServerCachedQueryRequestType,\n> = EngineServerCachedQueryResponse<T>;\n\n/**\n * Base client for all engine requests\n */\nexport class EngineBaseClient {\n readonly opts: EngineClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: EngineClientOpts) {\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 execute 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 public async getTxNonce(address?: string): Promise<string> {\n const addr = address ?? this.opts.walletClient?.account.address;\n\n if (!addr) {\n throw new WalletNotProvidedError();\n }\n\n return (\n await this.getNonces({\n address: addr,\n })\n ).txNonce;\n }\n\n public async getNonces(\n params: GetEngineNoncesParams,\n ): Promise<GetEngineNoncesResponse> {\n const baseResp = await this.query('nonces', params);\n\n return {\n orderNonce: baseResp.order_nonce,\n txNonce: baseResp.tx_nonce,\n };\n }\n\n /**\n * Queries the engine, all query params are stringified into the query string\n *\n * @param requestType\n * @param params\n * @public\n */\n public async query<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): Promise<EngineServerQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<EngineQueryRequestResponse>(\n `${this.opts.url}/query`,\n request,\n );\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 EngineServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Queries the gateway's in-memory cache via the `/edge/query` endpoint. Lower latency than\n * {@link query} at the cost of eventual consistency — do not use for order, margin, or\n * settlement decisions.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeQuery<\n TRequestType extends EngineServerCachedQueryRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerCachedQueryRequestByType[TRequestType],\n ): Promise<EngineServerCachedQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response =\n await this.axiosInstance.post<EngineCachedQueryRequestResponse>(\n `${this.opts.url}/edge/query`,\n request,\n );\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 EngineServerCachedQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Sends an edge control message (`ping` / `time`) via the `/edge/query` endpoint. These\n * return immediately from the server clock and use a different envelope than the cached data\n * queries (no `data` field), so the whole response body is returned.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeControlQuery<\n TRequestType extends EngineServerEdgeControlRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerEdgeControlRequestByType[TRequestType],\n ): Promise<EngineServerEdgeControlResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerEdgeControlResponseByType[TRequestType]\n >(`${this.opts.url}/edge/query`, request);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n return response.data;\n }\n\n /**\n * POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped\n * in an EngineServerFailureError on failure.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async execute<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): Promise<EngineServerExecuteSuccessResult<TRequestType>> {\n const reqBody = this.getExecuteRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerExecuteResult<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 EngineServerExecuteSuccessResult<TRequestType>;\n }\n\n /**\n * A simple, typechecked fn for constructing a `type`-tagged request body in the format expected\n * by the server. Generic over the request type / params pair so it can build live query, edge\n * (cached) query, and edge control request bodies alike.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends string, TParams extends object>(\n requestType: TRequestType,\n params: TParams,\n ): { type: TRequestType } & TParams {\n return {\n type: requestType,\n ...params,\n };\n }\n\n /**\n * A simple, typechecked fn for constructing an execute request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): EngineExecuteRequestBody {\n return {\n [requestType]: params,\n };\n }\n\n /**\n * Signs a given request with the signer provided to the engine\n *\n * @param requestType\n * @param verifyingContract\n * @param chainId\n * @param params\n * @public\n */\n public 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 // However, always use wallet signer for withdraw_collateral_v2 as linked signers are not allowed for different\n // withdrawal addresses\n const walletClient = (() => {\n if (requestType === 'withdraw_collateral_v2') {\n return this.opts.walletClient;\n }\n return this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n })();\n\n if (!walletClient) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\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 | EngineServerExecuteResult\n | EngineQueryRequestResponse\n | EngineCachedQueryRequestResponse\n | EngineServerEdgeControlResponseByType[EngineServerEdgeControlRequestType]\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,MAAwB;EAClC,KAAK,OAAO;EACZ,KAAK,gBAAgB,MAAA,QAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC;CACH;;;;;;CAOA,gBACE,0BACA;EACA,KAAK,KAAK,2BAA2B,4BAA4B,KAAA;CACnE;CAEA,MAAa,WAAW,SAAmC;EACzD,MAAM,OAAO,WAAW,KAAK,KAAK,cAAc,QAAQ;EAExD,IAAI,CAAC,MACH,MAAM,IAAIA,eAAAA,uBAAuB;EAGnC,QACE,MAAM,KAAK,UAAU,EACnB,SAAS,KACX,CAAC,GACD;CACJ;CAEA,MAAa,UACX,QACkC;EAClC,MAAM,WAAW,MAA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,MAAa,KACX,aACA,mBACA,SACA,QACA;EAIA,MAAM,sBAAsB;GAC1B,IAAI,gBAAgB,0BAClB,OAAO,KAAK,KAAK;GAEnB,OAAO,KAAK,KAAK,4BAA4B,KAAK,KAAK;EACzD,GAAG;EAEH,IAAI,CAAC,cACH,MAAM,IAAID,eAAAA,uBAAuB;EAGnC,QAAA,GAAA,eAAA,6BAAmC;GACjC;GACA,eAAe;GACf;GACA;GACA;EACF,CAAC;CACH;CAEA,oBAA4B,UAAyB;EACnD,IAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MACvC,MAAM,MACJ,oCAAoC,SAAS,OAAO,GAAG,SAAS,WAAW,UAAU,SAAS,MAChG;CAEJ;CAEA,kBACE,UAMA;EACA,IAAI,SAAS,KAAK,WAAW,WAC3B,MAAM,IAAIE,uCAAAA,yBAAyB,SAAS,IAAI;CAEpD;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { G as EngineServerQueryResponseByType, H as EngineServerQueryRequestByType, U as EngineServerQueryRequestType } from "./serverQueryTypes-B3vC8vxT.js";
|
|
2
|
-
import { a as EngineServerExecuteRequestByType, l as EngineServerExecuteSuccessResult, o as EngineServerExecuteRequestType } from "./serverExecuteTypes-
|
|
2
|
+
import { a as EngineServerExecuteRequestByType, l as EngineServerExecuteSuccessResult, o as EngineServerExecuteRequestType } from "./serverExecuteTypes-DTy8xAJp.js";
|
|
3
3
|
import { G as GetEngineNoncesResponse, W as GetEngineNoncesParams } from "./clientQueryTypes-BaYOTnpm.js";
|
|
4
4
|
import { a as EngineServerCachedQueryRequestByType, c as EngineServerCachedQueryResponseByType, d as EngineServerEdgeControlRequestByType, f as EngineServerEdgeControlRequestType, o as EngineServerCachedQueryRequestType, p as EngineServerEdgeControlResponseByType } from "./serverEdgeQueryTypes-DbSUWFzo.js";
|
|
5
5
|
import { SignableRequestType, SignableRequestTypeToParams, WalletClientWithAccount } from "@nadohq/shared";
|
|
@@ -97,4 +97,4 @@ declare class EngineBaseClient {
|
|
|
97
97
|
}
|
|
98
98
|
//#endregion
|
|
99
99
|
export { EngineClientOpts as n, EngineBaseClient as t };
|
|
100
|
-
//# sourceMappingURL=EngineBaseClient-
|
|
100
|
+
//# sourceMappingURL=EngineBaseClient-whwZCdGv.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineBaseClient-
|
|
1
|
+
{"version":3,"file":"EngineBaseClient-whwZCdGv.d.ts","names":[],"sources":["../src/src/EngineBaseClient.ts"],"mappings":";;;;;;;;UA+BiB,gBAAA;EAEf,GAAA;EAEA,YAAA,GAAe,uBAAA;EAEf,wBAAA,GAA2B,uBAAuB;AAAA;AAAA,KAI/C,wBAAA,GAA2B,OAAO,CAAC,gCAAA;AAVxC;;;AAAA,cAwBa,gBAAA;EAAA,SACF,IAAA,EAAM,gBAAA;EAAA,SACN,aAAA,EAAe,aAAA;cAEZ,IAAA,EAAM,gBAAA;EAtBlB;;;AAAkD;AACnD;EAmCQ,eAAA,CACL,wBAAA,EAA0B,uBAAA;EAKf,UAAA,CAAW,OAAA,YAAmB,OAAA;EAc9B,SAAA,CACX,MAAA,EAAQ,qBAAA,GACP,OAAA,CAAQ,uBAAA;EAtD2D;AAcxE;;;;;;EAwDe,KAAA,sBAA2B,4BAAA,CAAA,CACtC,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,8BAAA,CAA+B,YAAA,IACtC,OAAA,CAAQ,+BAAA,CAAgC,YAAA;EAnCA;;;;;;;;;EA8D9B,SAAA,sBACU,kCAAA,CAAA,CAErB,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,oCAAA,CAAqC,YAAA,IAC5C,OAAA,CAAQ,qCAAA,CAAsC,YAAA;EAhC9C;;;;;;;;;EA4DU,gBAAA,sBACU,kCAAA,CAAA,CAErB,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,oCAAA,CAAqC,YAAA,IAC5C,OAAA,CAAQ,qCAAA,CAAsC,YAAA;EADvC;;;;;;;;EAqBG,OAAA,sBAA6B,8BAAA,CAAA,CACxC,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,gCAAA,CAAiC,YAAA,IACxC,OAAA,CAAQ,gCAAA,CAAiC,YAAA;EAAA;;;;;;;;EAqBrC,eAAA,qDAAA,CACL,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,OAAA;IACL,IAAA,EAAM,YAAA;EAAA,IAAiB,OAAA;EAgBzB;;;;;;EAHI,iBAAA,sBAAuC,8BAAA,CAAA,CAC5C,WAAA,EAAa,YAAA,EACb,MAAA,EAAQ,gCAAA,CAAiC,YAAA,IACxC,wBAAA;EAmBqC;;;;;;;;;EAJ3B,IAAA,WAAe,mBAAA,CAAA,CAC1B,WAAA,EAAa,CAAA,EACb,iBAAA,UACA,OAAA,UACA,MAAA,EAAQ,2BAAA,CAA4B,CAAA,IAAE,OAAA;EAAA,QAyBhC,mBAAA;EAAA,QAQA,iBAAA;AAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_EngineBaseClient = require("./EngineBaseClient-
|
|
2
|
+
const require_EngineBaseClient = require("./EngineBaseClient-J3nMzK0q.cjs");
|
|
3
3
|
exports.EngineBaseClient = require_EngineBaseClient.EngineBaseClient;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EngineClientOpts, t as EngineBaseClient } from "./EngineBaseClient-
|
|
1
|
+
import { n as EngineClientOpts, t as EngineBaseClient } from "./EngineBaseClient-D4T3zroY.cjs";
|
|
2
2
|
export { EngineBaseClient, EngineClientOpts };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as EngineClientOpts, t as EngineBaseClient } from "./EngineBaseClient-
|
|
1
|
+
import { n as EngineClientOpts, t as EngineBaseClient } from "./EngineBaseClient-whwZCdGv.js";
|
|
2
2
|
export { EngineBaseClient, EngineClientOpts };
|
package/dist/EngineBaseClient.js
CHANGED
|
@@ -127,7 +127,10 @@ var EngineBaseClient = class {
|
|
|
127
127
|
* @public
|
|
128
128
|
*/
|
|
129
129
|
async sign(requestType, verifyingContract, chainId, params) {
|
|
130
|
-
const walletClient =
|
|
130
|
+
const walletClient = (() => {
|
|
131
|
+
if (requestType === "withdraw_collateral_v2") return this.opts.walletClient;
|
|
132
|
+
return this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
133
|
+
})();
|
|
131
134
|
if (!walletClient) throw new WalletNotProvidedError();
|
|
132
135
|
return getSignedTransactionRequest({
|
|
133
136
|
chainId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineBaseClient.js","names":["successResponse"],"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerCachedQueryRequestByType,\n EngineServerCachedQueryRequestType,\n EngineServerCachedQueryResponse,\n EngineServerCachedQueryResponseByType,\n EngineServerCachedQuerySuccessResponse,\n EngineServerEdgeControlRequestByType,\n EngineServerEdgeControlRequestType,\n EngineServerEdgeControlResponseByType,\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequestByType,\n EngineServerQueryRequestType,\n EngineServerQueryResponse,\n EngineServerQueryResponseByType,\n EngineServerQuerySuccessResponse,\n GetEngineNoncesParams,\n GetEngineNoncesResponse,\n} from './types';\nimport { EngineServerFailureError } from './types/EngineServerFailureError';\n\nexport interface EngineClientOpts {\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// Only 1 key can be defined per execute request\ntype EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;\n\ntype EngineQueryRequestResponse<\n T extends EngineServerQueryRequestType = EngineServerQueryRequestType,\n> = EngineServerQueryResponse<T>;\n\ntype EngineCachedQueryRequestResponse<\n T extends EngineServerCachedQueryRequestType =\n EngineServerCachedQueryRequestType,\n> = EngineServerCachedQueryResponse<T>;\n\n/**\n * Base client for all engine requests\n */\nexport class EngineBaseClient {\n readonly opts: EngineClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: EngineClientOpts) {\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 execute 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 public async getTxNonce(address?: string): Promise<string> {\n const addr = address ?? this.opts.walletClient?.account.address;\n\n if (!addr) {\n throw new WalletNotProvidedError();\n }\n\n return (\n await this.getNonces({\n address: addr,\n })\n ).txNonce;\n }\n\n public async getNonces(\n params: GetEngineNoncesParams,\n ): Promise<GetEngineNoncesResponse> {\n const baseResp = await this.query('nonces', params);\n\n return {\n orderNonce: baseResp.order_nonce,\n txNonce: baseResp.tx_nonce,\n };\n }\n\n /**\n * Queries the engine, all query params are stringified into the query string\n *\n * @param requestType\n * @param params\n * @public\n */\n public async query<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): Promise<EngineServerQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<EngineQueryRequestResponse>(\n `${this.opts.url}/query`,\n request,\n );\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 EngineServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Queries the gateway's in-memory cache via the `/edge/query` endpoint. Lower latency than\n * {@link query} at the cost of eventual consistency — do not use for order, margin, or\n * settlement decisions.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeQuery<\n TRequestType extends EngineServerCachedQueryRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerCachedQueryRequestByType[TRequestType],\n ): Promise<EngineServerCachedQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response =\n await this.axiosInstance.post<EngineCachedQueryRequestResponse>(\n `${this.opts.url}/edge/query`,\n request,\n );\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 EngineServerCachedQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Sends an edge control message (`ping` / `time`) via the `/edge/query` endpoint. These\n * return immediately from the server clock and use a different envelope than the cached data\n * queries (no `data` field), so the whole response body is returned.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeControlQuery<\n TRequestType extends EngineServerEdgeControlRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerEdgeControlRequestByType[TRequestType],\n ): Promise<EngineServerEdgeControlResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerEdgeControlResponseByType[TRequestType]\n >(`${this.opts.url}/edge/query`, request);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n return response.data;\n }\n\n /**\n * POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped\n * in an EngineServerFailureError on failure.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async execute<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): Promise<EngineServerExecuteSuccessResult<TRequestType>> {\n const reqBody = this.getExecuteRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerExecuteResult<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 EngineServerExecuteSuccessResult<TRequestType>;\n }\n\n /**\n * A simple, typechecked fn for constructing a `type`-tagged request body in the format expected\n * by the server. Generic over the request type / params pair so it can build live query, edge\n * (cached) query, and edge control request bodies alike.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends string, TParams extends object>(\n requestType: TRequestType,\n params: TParams,\n ): { type: TRequestType } & TParams {\n return {\n type: requestType,\n ...params,\n };\n }\n\n /**\n * A simple, typechecked fn for constructing an execute request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): EngineExecuteRequestBody {\n return {\n [requestType]: params,\n };\n }\n\n /**\n * Signs a given request with the signer provided to the engine\n *\n * @param requestType\n * @param verifyingContract\n * @param chainId\n * @param params\n * @public\n */\n public 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) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\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 | EngineServerExecuteResult\n | EngineQueryRequestResponse\n | EngineCachedQueryRequestResponse\n | EngineServerEdgeControlResponseByType[EngineServerEdgeControlRequestType]\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,MAAwB;EAClC,KAAK,OAAO;EACZ,KAAK,gBAAgB,MAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC;CACH;;;;;;CAOA,gBACE,0BACA;EACA,KAAK,KAAK,2BAA2B,4BAA4B,KAAA;CACnE;CAEA,MAAa,WAAW,SAAmC;EACzD,MAAM,OAAO,WAAW,KAAK,KAAK,cAAc,QAAQ;EAExD,IAAI,CAAC,MACH,MAAM,IAAI,uBAAuB;EAGnC,QACE,MAAM,KAAK,UAAU,EACnB,SAAS,KACX,CAAC,GACD;CACJ;CAEA,MAAa,UACX,QACkC;EAClC,MAAM,WAAW,MAAM,KAAK,MAAM,UAAU,MAAM;EAElD,OAAO;GACL,YAAY,SAAS;GACrB,SAAS,SAAS;EACpB;CACF;;;;;;;;CASA,MAAa,MACX,aACA,QACwD;EACxD,MAAM,UAAU,KAAK,gBAAgB,aAAa,MAAM;EACxD,MAAM,WAAW,MAAM,KAAK,cAAc,KACxC,GAAG,KAAK,KAAK,IAAI,SACjB,OACF;EAEA,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAO/B,OAAOA,SAAgB,KAAK;CAC9B;;;;;;;;;;CAWA,MAAa,UAGX,aACA,QAC8D;EAC9D,MAAM,UAAU,KAAK,gBAAgB,aAAa,MAAM;EACxD,MAAM,WACJ,MAAM,KAAK,cAAc,KACvB,GAAG,KAAK,KAAK,IAAI,cACjB,OACF;EAEF,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAO/B,OAAOA,SAAgB,KAAK;CAC9B;;;;;;;;;;CAWA,MAAa,iBAGX,aACA,QAC8D;EAC9D,MAAM,UAAU,KAAK,gBAAgB,aAAa,MAAM;EACxD,MAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,IAAI,cAAc,OAAO;EAExC,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAE/B,OAAO,SAAS;CAClB;;;;;;;;;CAUA,MAAa,QACX,aACA,QACyD;EACzD,MAAM,UAAU,KAAK,kBAAkB,aAAa,MAAM;EAC1D,MAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,IAAI,WAAW,OAAO;EAErC,KAAK,oBAAoB,QAAQ;EACjC,KAAK,kBAAkB,QAAQ;EAG/B,OAAO,SAAS;CAClB;;;;;;;;;CAUA,gBACE,aACA,QACkC;EAClC,OAAO;GACL,MAAM;GACN,GAAG;EACL;CACF;;;;;;;CAQA,kBACE,aACA,QAC0B;EAC1B,OAAO,GACJ,cAAc,OACjB;CACF;;;;;;;;;;CAWA,MAAa,KACX,aACA,mBACA,SACA,QACA;EAEA,MAAM,eACJ,KAAK,KAAK,4BAA4B,KAAK,KAAK;EAElD,IAAI,CAAC,cACH,MAAM,IAAI,uBAAuB;EAGnC,OAAO,4BAA4B;GACjC;GACA,eAAe;GACf;GACA;GACA;EACF,CAAC;CACH;CAEA,oBAA4B,UAAyB;EACnD,IAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MACvC,MAAM,MACJ,oCAAoC,SAAS,OAAO,GAAG,SAAS,WAAW,UAAU,SAAS,MAChG;CAEJ;CAEA,kBACE,UAMA;EACA,IAAI,SAAS,KAAK,WAAW,WAC3B,MAAM,IAAI,yBAAyB,SAAS,IAAI;CAEpD;AACF"}
|
|
1
|
+
{"version":3,"file":"EngineBaseClient.js","names":["successResponse"],"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n WalletNotProvidedError,\n} from '@nadohq/shared';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerCachedQueryRequestByType,\n EngineServerCachedQueryRequestType,\n EngineServerCachedQueryResponse,\n EngineServerCachedQueryResponseByType,\n EngineServerCachedQuerySuccessResponse,\n EngineServerEdgeControlRequestByType,\n EngineServerEdgeControlRequestType,\n EngineServerEdgeControlResponseByType,\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequestByType,\n EngineServerQueryRequestType,\n EngineServerQueryResponse,\n EngineServerQueryResponseByType,\n EngineServerQuerySuccessResponse,\n GetEngineNoncesParams,\n GetEngineNoncesResponse,\n} from './types';\nimport { EngineServerFailureError } from './types/EngineServerFailureError';\n\nexport interface EngineClientOpts {\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// Only 1 key can be defined per execute request\ntype EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;\n\ntype EngineQueryRequestResponse<\n T extends EngineServerQueryRequestType = EngineServerQueryRequestType,\n> = EngineServerQueryResponse<T>;\n\ntype EngineCachedQueryRequestResponse<\n T extends EngineServerCachedQueryRequestType =\n EngineServerCachedQueryRequestType,\n> = EngineServerCachedQueryResponse<T>;\n\n/**\n * Base client for all engine requests\n */\nexport class EngineBaseClient {\n readonly opts: EngineClientOpts;\n readonly axiosInstance: AxiosInstance;\n\n constructor(opts: EngineClientOpts) {\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 execute 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 public async getTxNonce(address?: string): Promise<string> {\n const addr = address ?? this.opts.walletClient?.account.address;\n\n if (!addr) {\n throw new WalletNotProvidedError();\n }\n\n return (\n await this.getNonces({\n address: addr,\n })\n ).txNonce;\n }\n\n public async getNonces(\n params: GetEngineNoncesParams,\n ): Promise<GetEngineNoncesResponse> {\n const baseResp = await this.query('nonces', params);\n\n return {\n orderNonce: baseResp.order_nonce,\n txNonce: baseResp.tx_nonce,\n };\n }\n\n /**\n * Queries the engine, all query params are stringified into the query string\n *\n * @param requestType\n * @param params\n * @public\n */\n public async query<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): Promise<EngineServerQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<EngineQueryRequestResponse>(\n `${this.opts.url}/query`,\n request,\n );\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 EngineServerQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Queries the gateway's in-memory cache via the `/edge/query` endpoint. Lower latency than\n * {@link query} at the cost of eventual consistency — do not use for order, margin, or\n * settlement decisions.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeQuery<\n TRequestType extends EngineServerCachedQueryRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerCachedQueryRequestByType[TRequestType],\n ): Promise<EngineServerCachedQueryResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response =\n await this.axiosInstance.post<EngineCachedQueryRequestResponse>(\n `${this.opts.url}/edge/query`,\n request,\n );\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 EngineServerCachedQuerySuccessResponse<TRequestType>\n >;\n\n return successResponse.data.data;\n }\n\n /**\n * Sends an edge control message (`ping` / `time`) via the `/edge/query` endpoint. These\n * return immediately from the server clock and use a different envelope than the cached data\n * queries (no `data` field), so the whole response body is returned.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async edgeControlQuery<\n TRequestType extends EngineServerEdgeControlRequestType,\n >(\n requestType: TRequestType,\n params: EngineServerEdgeControlRequestByType[TRequestType],\n ): Promise<EngineServerEdgeControlResponseByType[TRequestType]> {\n const request = this.getQueryRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerEdgeControlResponseByType[TRequestType]\n >(`${this.opts.url}/edge/query`, request);\n\n this.checkResponseStatus(response);\n this.checkServerStatus(response);\n\n return response.data;\n }\n\n /**\n * POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped\n * in an EngineServerFailureError on failure.\n *\n * @param requestType\n * @param params\n * @public\n */\n public async execute<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): Promise<EngineServerExecuteSuccessResult<TRequestType>> {\n const reqBody = this.getExecuteRequest(requestType, params);\n const response = await this.axiosInstance.post<\n EngineServerExecuteResult<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 EngineServerExecuteSuccessResult<TRequestType>;\n }\n\n /**\n * A simple, typechecked fn for constructing a `type`-tagged request body in the format expected\n * by the server. Generic over the request type / params pair so it can build live query, edge\n * (cached) query, and edge control request bodies alike.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends string, TParams extends object>(\n requestType: TRequestType,\n params: TParams,\n ): { type: TRequestType } & TParams {\n return {\n type: requestType,\n ...params,\n };\n }\n\n /**\n * A simple, typechecked fn for constructing an execute request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(\n requestType: TRequestType,\n params: EngineServerExecuteRequestByType[TRequestType],\n ): EngineExecuteRequestBody {\n return {\n [requestType]: params,\n };\n }\n\n /**\n * Signs a given request with the signer provided to the engine\n *\n * @param requestType\n * @param verifyingContract\n * @param chainId\n * @param params\n * @public\n */\n public 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 // However, always use wallet signer for withdraw_collateral_v2 as linked signers are not allowed for different\n // withdrawal addresses\n const walletClient = (() => {\n if (requestType === 'withdraw_collateral_v2') {\n return this.opts.walletClient;\n }\n return this.opts.linkedSignerWalletClient ?? this.opts.walletClient;\n })();\n\n if (!walletClient) {\n throw new WalletNotProvidedError();\n }\n\n return getSignedTransactionRequest({\n chainId,\n requestParams: params,\n requestType,\n walletClient,\n verifyingContract,\n });\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 | EngineServerExecuteResult\n | EngineQueryRequestResponse\n | EngineCachedQueryRequestResponse\n | EngineServerEdgeControlResponseByType[EngineServerEdgeControlRequestType]\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;AAuDA,IAAa,mBAAb,MAA8B;CAI5B,YAAY,MAAwB;EAClC,KAAK,OAAO;EACZ,KAAK,gBAAgB,MAAM,OAAO;GAChC,iBAAiB;GAEjB,sBAAsB;EACxB,CAAC;CACH;;;;;;CAOA,gBACE,0BACA;EACA,KAAK,KAAK,2BAA2B,4BAA4B,KAAA;CACnE;CAEA,MAAa,WAAW,SAAmC;EACzD,MAAM,OAAO,WAAW,KAAK,KAAK,cAAc,QAAQ;EAExD,IAAI,CAAC,MACH,MAAM,IAAI,uBAAuB;EAGnC,QACE,MAAM,KAAK,UAAU,EACnB,SAAS,KACX,CAAC,GACD;CACJ;CAEA,M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ACJ,cAAc,OACjB;CACF;;;;;;;;;;CAWA,MAAa,KACX,aACA,mBACA,SACA,QACA;EAIA,MAAM,sBAAsB;GAC1B,IAAI,gBAAgB,0BAClB,OAAO,KAAK,KAAK;GAEnB,OAAO,KAAK,KAAK,4BAA4B,KAAK,KAAK;EACzD,GAAG;EAEH,IAAI,CAAC,cACH,MAAM,IAAI,uBAAuB;EAGnC,OAAO,4BAA4B;GACjC;GACA,eAAe;GACf;GACA;GACA;EACF,CAAC;CACH;CAEA,oBAA4B,UAAyB;EACnD,IAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MACvC,MAAM,MACJ,oCAAoC,SAAS,OAAO,GAAG,SAAS,WAAW,UAAU,SAAS,MAChG;CAEJ;CAEA,kBACE,UAMA;EACA,IAAI,SAAS,KAAK,WAAW,WAC3B,MAAM,IAAI,yBAAyB,SAAS,IAAI;CAEpD;AACF"}
|
package/dist/EngineClient.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./EngineBaseClient-
|
|
2
|
+
require("./EngineBaseClient-J3nMzK0q.cjs");
|
|
3
3
|
const require_EngineEdgeQueryClient = require("./EngineEdgeQueryClient.cjs");
|
|
4
4
|
const require_EngineExecuteClient = require("./EngineExecuteClient.cjs");
|
|
5
5
|
const require_EngineQueryClient = require("./EngineQueryClient.cjs");
|
package/dist/EngineClient.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-
|
|
2
|
-
import { t as EngineExecuteClient } from "./EngineExecuteClient-
|
|
3
|
-
import { t as EngineQueryClient } from "./EngineQueryClient-
|
|
4
|
-
import { t as EngineWebClient } from "./EngineWebClient-
|
|
1
|
+
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-C3p1nRLs.cjs";
|
|
2
|
+
import { t as EngineExecuteClient } from "./EngineExecuteClient-DOHSrQA-.cjs";
|
|
3
|
+
import { t as EngineQueryClient } from "./EngineQueryClient-CFj0O4CZ.cjs";
|
|
4
|
+
import { t as EngineWebClient } from "./EngineWebClient-C-h4ipO4.cjs";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineClient.d.ts
|
|
7
7
|
declare const EngineClient_base: import("ts-mixer/dist/types/types").Class<any[], EngineQueryClient & EngineEdgeQueryClient & EngineExecuteClient & EngineWebClient, typeof EngineQueryClient & typeof EngineEdgeQueryClient & typeof EngineExecuteClient & typeof EngineWebClient>;
|
package/dist/EngineClient.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-
|
|
2
|
-
import { t as EngineExecuteClient } from "./EngineExecuteClient-
|
|
3
|
-
import { t as EngineQueryClient } from "./EngineQueryClient-
|
|
4
|
-
import { t as EngineWebClient } from "./EngineWebClient-
|
|
1
|
+
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-B08kww7l.js";
|
|
2
|
+
import { t as EngineExecuteClient } from "./EngineExecuteClient-D9e8FLa1.js";
|
|
3
|
+
import { t as EngineQueryClient } from "./EngineQueryClient-BaSojnvg.js";
|
|
4
|
+
import { t as EngineWebClient } from "./EngineWebClient-CTky4iyV.js";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineClient.d.ts
|
|
7
7
|
declare const EngineClient_base: import("ts-mixer/dist/types/types").Class<any[], EngineQueryClient & EngineEdgeQueryClient & EngineExecuteClient & EngineWebClient, typeof EngineQueryClient & typeof EngineEdgeQueryClient & typeof EngineExecuteClient & typeof EngineWebClient>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { q as EngineServerStatusResponse } from "./serverQueryTypes-B3vC8vxT.js";
|
|
2
2
|
import { M as GetEngineMarketPricesResponse, U as GetEngineNlpPoolInfoResponse, _ as GetEngineContractsResponse, b as GetEngineHealthGroupsResponse, c as EnginePingResponse, f as EngineSymbolsResponse, g as GetEngineCachedMarketPricesParams, h as GetEngineCachedBboHistoryResponse, m as GetEngineCachedBboHistoryParams, n as EngineCachedTimeParams, nt as GetEngineSymbolsParams, p as GetEngineAllMarketsResponse, s as EnginePingParams } from "./clientQueryTypes-BaYOTnpm.js";
|
|
3
|
-
import { t as EngineBaseClient } from "./EngineBaseClient-
|
|
3
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-whwZCdGv.js";
|
|
4
4
|
import { MarketWithProduct } from "@nadohq/shared";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineEdgeQueryClient.d.ts
|
|
@@ -76,4 +76,4 @@ declare class EngineEdgeQueryClient extends EngineBaseClient {
|
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
78
|
export { EngineEdgeQueryClient as t };
|
|
79
|
-
//# sourceMappingURL=EngineEdgeQueryClient-
|
|
79
|
+
//# sourceMappingURL=EngineEdgeQueryClient-B08kww7l.d.ts.map
|
package/dist/{EngineEdgeQueryClient-B9Y8srJa.d.ts.map → EngineEdgeQueryClient-B08kww7l.d.ts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineEdgeQueryClient-
|
|
1
|
+
{"version":3,"file":"EngineEdgeQueryClient-B08kww7l.d.ts","names":[],"sources":["../src/src/EngineEdgeQueryClient.ts"],"mappings":";;;;;;;;;;AAsCA;;;;;;cAAa,qBAAA,SAA8B,gBAAA;EAyB9B;;;;;;EAlBL,qBAAA,CACJ,MAAA,GAAQ,iCAAA,GACP,OAAA,CAAQ,6BAAA;EAiDkB;;;;;EAnCvB,gBAAA,CACJ,MAAA,GAAQ,sBAAA,GACP,OAAA,CAAQ,qBAAA;EAyF2B;;;;EA1EhC,kBAAA,CAAA,GAAsB,OAAA,CAAQ,0BAAA;EAuGjB;;;EA5Fb,eAAA,CAAA,GAAmB,OAAA,CAAQ,0BAAA;EAmH9B;;;EA5GG,mBAAA,CAAA,GAAuB,OAAA,CAAQ,2BAAA;EA1DI;;;EA2EnC,uBAAA,CAAA,GAA2B,OAAA,CAC/B,MAAA,SAAe,iBAAA;EAnEd;;;EAyFG,qBAAA,CAAA,GAAyB,OAAA,CAAQ,6BAAA;EA1ErC;;;EA0FI,oBAAA,CAAA,GAAwB,OAAA,CAAQ,4BAAA;EA1EV;;;;;;EAqFtB,mBAAA,CACJ,MAAA,GAAQ,+BAAA,GACP,OAAA,CAAQ,iCAAA;EArE0B;;;;;;EAqF/B,IAAA,CAAK,MAAA,GAAQ,gBAAA,GAAwB,OAAA,CAAQ,kBAAA;EA7CZ;;;;;EAkEjC,kBAAA,CACJ,MAAA,GAAQ,sBAAA,GACP,OAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { q as EngineServerStatusResponse } from "./serverQueryTypes-Dva9R2tV.cjs";
|
|
2
2
|
import { M as GetEngineMarketPricesResponse, U as GetEngineNlpPoolInfoResponse, _ as GetEngineContractsResponse, b as GetEngineHealthGroupsResponse, c as EnginePingResponse, f as EngineSymbolsResponse, g as GetEngineCachedMarketPricesParams, h as GetEngineCachedBboHistoryResponse, m as GetEngineCachedBboHistoryParams, n as EngineCachedTimeParams, nt as GetEngineSymbolsParams, p as GetEngineAllMarketsResponse, s as EnginePingParams } from "./clientQueryTypes-BTKfuoGI.cjs";
|
|
3
|
-
import { t as EngineBaseClient } from "./EngineBaseClient-
|
|
3
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-D4T3zroY.cjs";
|
|
4
4
|
import { MarketWithProduct } from "@nadohq/shared";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineEdgeQueryClient.d.ts
|
|
@@ -76,4 +76,4 @@ declare class EngineEdgeQueryClient extends EngineBaseClient {
|
|
|
76
76
|
}
|
|
77
77
|
//#endregion
|
|
78
78
|
export { EngineEdgeQueryClient as t };
|
|
79
|
-
//# sourceMappingURL=EngineEdgeQueryClient-
|
|
79
|
+
//# sourceMappingURL=EngineEdgeQueryClient-C3p1nRLs.d.cts.map
|
package/dist/{EngineEdgeQueryClient-CPEDAOd0.d.cts.map → EngineEdgeQueryClient-C3p1nRLs.d.cts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineEdgeQueryClient-
|
|
1
|
+
{"version":3,"file":"EngineEdgeQueryClient-C3p1nRLs.d.cts","names":[],"sources":["../src/src/EngineEdgeQueryClient.ts"],"mappings":";;;;;;;;;;AAsCA;;;;;;cAAa,qBAAA,SAA8B,gBAAA;EAyB9B;;;;;;EAlBL,qBAAA,CACJ,MAAA,GAAQ,iCAAA,GACP,OAAA,CAAQ,6BAAA;EAiDkB;;;;;EAnCvB,gBAAA,CACJ,MAAA,GAAQ,sBAAA,GACP,OAAA,CAAQ,qBAAA;EAyF2B;;;;EA1EhC,kBAAA,CAAA,GAAsB,OAAA,CAAQ,0BAAA;EAuGjB;;;EA5Fb,eAAA,CAAA,GAAmB,OAAA,CAAQ,0BAAA;EAmH9B;;;EA5GG,mBAAA,CAAA,GAAuB,OAAA,CAAQ,2BAAA;EA1DI;;;EA2EnC,uBAAA,CAAA,GAA2B,OAAA,CAC/B,MAAA,SAAe,iBAAA;EAnEd;;;EAyFG,qBAAA,CAAA,GAAyB,OAAA,CAAQ,6BAAA;EA1ErC;;;EA0FI,oBAAA,CAAA,GAAwB,OAAA,CAAQ,4BAAA;EA1EV;;;;;;EAqFtB,mBAAA,CACJ,MAAA,GAAQ,+BAAA,GACP,OAAA,CAAQ,iCAAA;EArE0B;;;;;;EAqF/B,IAAA,CAAK,MAAA,GAAQ,gBAAA,GAAwB,OAAA,CAAQ,kBAAA;EA7CZ;;;;;EAkEjC,kBAAA,CACJ,MAAA,GAAQ,sBAAA,GACP,OAAA;AAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_EngineBaseClient = require("./EngineBaseClient-
|
|
2
|
+
const require_EngineBaseClient = require("./EngineBaseClient-J3nMzK0q.cjs");
|
|
3
3
|
const require_utils_productEngineTypeMappers = require("./utils/productEngineTypeMappers.cjs");
|
|
4
4
|
const require_utils_queryDataMappers = require("./utils/queryDataMappers.cjs");
|
|
5
5
|
let _nadohq_shared = require("@nadohq/shared");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-
|
|
1
|
+
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-C3p1nRLs.cjs";
|
|
2
2
|
export { EngineEdgeQueryClient };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-
|
|
1
|
+
import { t as EngineEdgeQueryClient } from "./EngineEdgeQueryClient-B08kww7l.js";
|
|
2
2
|
export { EngineEdgeQueryClient };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as EngineServerExecuteRequestByType, i as EngineServerExecutePlaceOrderPayload } from "./serverExecuteTypes-
|
|
2
|
-
import { _ as
|
|
3
|
-
import { t as EngineBaseClient } from "./EngineBaseClient-
|
|
1
|
+
import { a as EngineServerExecuteRequestByType, i as EngineServerExecutePlaceOrderPayload } from "./serverExecuteTypes-DTy8xAJp.js";
|
|
2
|
+
import { _ as WithBaseEngineExecuteParams, a as EngineExecuteRequestParamsByType, g as SignatureParams, v as WithSignature } from "./clientExecuteTypes-BlfIar6f.js";
|
|
3
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-whwZCdGv.js";
|
|
4
4
|
import { EIP712OrderParams, SignableRequestType, SignableRequestTypeToParams } from "@nadohq/shared";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineExecuteBuilder.d.ts
|
|
@@ -24,6 +24,12 @@ declare class EngineExecuteBuilder {
|
|
|
24
24
|
* @returns `liquidate_subaccount` payload
|
|
25
25
|
*/
|
|
26
26
|
buildWithdrawCollateralPayload(clientParams: EngineExecuteRequestParamsByType['withdraw_collateral']): Promise<EngineServerExecuteRequestByType['withdraw_collateral']>;
|
|
27
|
+
/**
|
|
28
|
+
* Builds server payload for the `withdraw_collateral_v2` execute action.
|
|
29
|
+
* @param clientParams Client WithdrawCollateralV2 params.
|
|
30
|
+
* @returns `withdraw_collateral_v2` payload
|
|
31
|
+
*/
|
|
32
|
+
buildWithdrawCollateralV2Payload(clientParams: EngineExecuteRequestParamsByType['withdraw_collateral_v2']): Promise<EngineServerExecuteRequestByType['withdraw_collateral_v2']>;
|
|
27
33
|
/**
|
|
28
34
|
* Builds server payload for the `place_order` execute action.
|
|
29
35
|
*
|
|
@@ -102,4 +108,4 @@ declare class EngineExecuteBuilder {
|
|
|
102
108
|
}
|
|
103
109
|
//#endregion
|
|
104
110
|
export { EngineExecuteBuilder as t };
|
|
105
|
-
//# sourceMappingURL=EngineExecuteBuilder-
|
|
111
|
+
//# sourceMappingURL=EngineExecuteBuilder-BHX9mMqF.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineExecuteBuilder-BHX9mMqF.d.ts","names":[],"sources":["../src/src/EngineExecuteBuilder.ts"],"mappings":";;;;;;;;;;AAuBA;cAAa,oBAAA;EAAA,SACF,YAAA,EAAc,gBAAA;cAEX,YAAA,EAAc,gBAAA;EAAA;;;;;EASpB,+BAAA,CACJ,YAAA,EAAc,gCAAA,2BACb,OAAA,CAAQ,gCAAA;EAuBR;;;;;EAFG,8BAAA,CACJ,YAAA,EAAc,gCAAA,0BACb,OAAA,CAAQ,gCAAA;EAiDR;;;;;EA3BG,gCAAA,CACJ,YAAA,EAAc,gCAAA,6BACb,OAAA,CAAQ,gCAAA;EAgFA;;;;;;EAzDL,sBAAA,CACJ,YAAA,EAAc,gCAAA,kBACb,OAAA,CAAQ,oCAAA;EAmGR;;;;;;EA5EH,0BAAA,CACE,YAAA,EAAc,aAAA,CACZ,gCAAA;IACE,KAAA,EAAO,iBAAA;EAAA,KAGV,oCAAA;EAyIA;;;;;EAjHG,uBAAA,CACJ,YAAA,EAAc,gCAAA,mBACb,OAAA,CAAQ,gCAAA;EA8JR;;;;;;EA5IG,wBAAA,CACJ,YAAA,EAAc,gCAAA,oBACb,OAAA,CAAQ,gCAAA;EA2KD;;;;;;EAvJV,4BAAA,CACE,YAAA,EAAc,aAAA,CACZ,gCAAA;IAAsD,KAAA;EAAA,KAEvD,gCAAA;EAtLS;;;;;EAuMN,+BAAA,CACJ,YAAA,EAAc,gCAAA,4BACb,OAAA,CAAQ,gCAAA;EAzKL;;;;;;EA+LA,sBAAA,CACJ,YAAA,EAAc,gCAAA,kBACb,OAAA,CAAQ,gCAAA;EAxKT;;;;;;EA8LI,yBAAA,CACJ,YAAA,EAAc,gCAAA,qBACb,OAAA,CAAQ,gCAAA;EAtKA;;;;;EA2LL,mBAAA,CACJ,YAAA,EAAc,gCAAA,eACb,OAAA,CAAQ,gCAAA;EArKT;;;;;EA2LI,mBAAA,CACJ,YAAA,EAAc,gCAAA,eACb,OAAA,CAAQ,gCAAA;EAAA,UAgBK,oBAAA,WAA+B,mBAAA,CAAA,CAC7C,WAAA,EAAa,CAAA,EACb,eAAA,EAAiB,eAAA,GAAkB,2BAAA,CAA4B,CAAA,IAAE,OAAA;EAAA,UAcnD,kBAAA,CACd,MAAA,EAAQ,2BAAA;IAA8B,eAAA;EAAA,KAA0B,OAAA;EAAA,UAQxD,qBAAA,CACR,MAAA,EAAQ,2BAAA;AAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { a as EngineServerExecuteRequestByType, i as EngineServerExecutePlaceOrderPayload } from "./serverExecuteTypes-
|
|
2
|
-
import { _ as
|
|
3
|
-
import { t as EngineBaseClient } from "./EngineBaseClient-
|
|
1
|
+
import { a as EngineServerExecuteRequestByType, i as EngineServerExecutePlaceOrderPayload } from "./serverExecuteTypes-B65abv01.cjs";
|
|
2
|
+
import { _ as WithBaseEngineExecuteParams, a as EngineExecuteRequestParamsByType, g as SignatureParams, v as WithSignature } from "./clientExecuteTypes-4OzB-7to.cjs";
|
|
3
|
+
import { t as EngineBaseClient } from "./EngineBaseClient-D4T3zroY.cjs";
|
|
4
4
|
import { EIP712OrderParams, SignableRequestType, SignableRequestTypeToParams } from "@nadohq/shared";
|
|
5
5
|
|
|
6
6
|
//#region src/EngineExecuteBuilder.d.ts
|
|
@@ -24,6 +24,12 @@ declare class EngineExecuteBuilder {
|
|
|
24
24
|
* @returns `liquidate_subaccount` payload
|
|
25
25
|
*/
|
|
26
26
|
buildWithdrawCollateralPayload(clientParams: EngineExecuteRequestParamsByType['withdraw_collateral']): Promise<EngineServerExecuteRequestByType['withdraw_collateral']>;
|
|
27
|
+
/**
|
|
28
|
+
* Builds server payload for the `withdraw_collateral_v2` execute action.
|
|
29
|
+
* @param clientParams Client WithdrawCollateralV2 params.
|
|
30
|
+
* @returns `withdraw_collateral_v2` payload
|
|
31
|
+
*/
|
|
32
|
+
buildWithdrawCollateralV2Payload(clientParams: EngineExecuteRequestParamsByType['withdraw_collateral_v2']): Promise<EngineServerExecuteRequestByType['withdraw_collateral_v2']>;
|
|
27
33
|
/**
|
|
28
34
|
* Builds server payload for the `place_order` execute action.
|
|
29
35
|
*
|
|
@@ -102,4 +108,4 @@ declare class EngineExecuteBuilder {
|
|
|
102
108
|
}
|
|
103
109
|
//#endregion
|
|
104
110
|
export { EngineExecuteBuilder as t };
|
|
105
|
-
//# sourceMappingURL=EngineExecuteBuilder-
|
|
111
|
+
//# sourceMappingURL=EngineExecuteBuilder-CEqUxV3h.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngineExecuteBuilder-CEqUxV3h.d.cts","names":[],"sources":["../src/src/EngineExecuteBuilder.ts"],"mappings":";;;;;;;;;;AAuBA;cAAa,oBAAA;EAAA,SACF,YAAA,EAAc,gBAAA;cAEX,YAAA,EAAc,gBAAA;EAAA;;;;;EASpB,+BAAA,CACJ,YAAA,EAAc,gCAAA,2BACb,OAAA,CAAQ,gCAAA;EAuBR;;;;;EAFG,8BAAA,CACJ,YAAA,EAAc,gCAA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1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./EngineBaseClient-
|
|
2
|
+
require("./EngineBaseClient-J3nMzK0q.cjs");
|
|
3
3
|
let _nadohq_shared = require("@nadohq/shared");
|
|
4
4
|
//#region src/EngineExecuteBuilder.ts
|
|
5
5
|
/**
|
|
@@ -46,6 +46,23 @@ var EngineExecuteBuilder = class {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
+
* Builds server payload for the `withdraw_collateral_v2` execute action.
|
|
50
|
+
* @param clientParams Client WithdrawCollateralV2 params.
|
|
51
|
+
* @returns `withdraw_collateral_v2` payload
|
|
52
|
+
*/
|
|
53
|
+
async buildWithdrawCollateralV2Payload(clientParams) {
|
|
54
|
+
const nonce = await this.getTxNonceIfNeeded(clientParams);
|
|
55
|
+
const paramsWithNonce = {
|
|
56
|
+
...clientParams,
|
|
57
|
+
nonce
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
signature: await this.getSignatureIfNeeded("withdraw_collateral_v2", paramsWithNonce),
|
|
61
|
+
tx: (0, _nadohq_shared.getNadoEIP712Values)("withdraw_collateral_v2", paramsWithNonce),
|
|
62
|
+
spot_leverage: clientParams.spotLeverage ?? null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
49
66
|
* Builds server payload for the `place_order` execute action.
|
|
50
67
|
*
|
|
51
68
|
* @param clientParams Client PlaceOrder params.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineExecuteBuilder.cjs","names":[],"sources":["../src/EngineExecuteBuilder.ts"],"sourcesContent":["import {\n EIP712OrderParams,\n getNadoEIP712Values,\n getOrderNonce,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n} from '@nadohq/shared';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineExecuteRequestParamsByType,\n EngineServerExecutePlaceOrderPayload,\n EngineServerExecuteRequestByType,\n SignatureParams,\n WithBaseEngineExecuteParams,\n WithSignature,\n} from './types';\n\n/**\n * Builds execute payloads as expected by the server.\n * @param nonce A nonce is computed when one is not provided.\n * @param signature A signature is computed when one is not provided.\n */\nexport class EngineExecuteBuilder {\n readonly engineClient: EngineBaseClient;\n\n constructor(engineClient: EngineBaseClient) {\n this.engineClient = engineClient;\n }\n\n /**\n * Builds server payload for the `liquidate_subaccount` execute action.\n * @param clientParams Client LiquidateSubaccount params.\n * @returns `liquidate_subaccount` payload\n */\n async buildLiquidateSubaccountPayload(\n clientParams: EngineExecuteRequestParamsByType['liquidate_subaccount'],\n ): Promise<EngineServerExecuteRequestByType['liquidate_subaccount']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('liquidate_subaccount', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'liquidate_subaccount',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n };\n }\n\n /**\n * Builds server payload for the `withdraw_collateral` execute action.\n * @param clientParams Client WithdrawCollateral params.\n * @returns `liquidate_subaccount` payload\n */\n async buildWithdrawCollateralPayload(\n clientParams: EngineExecuteRequestParamsByType['withdraw_collateral'],\n ): Promise<EngineServerExecuteRequestByType['withdraw_collateral']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const signature = await this.getSignatureIfNeeded(\n 'withdraw_collateral',\n paramsWithNonce,\n );\n\n const tx = getNadoEIP712Values('withdraw_collateral', paramsWithNonce);\n return {\n signature,\n tx,\n spot_leverage: clientParams.spotLeverage ?? null,\n };\n }\n\n /**\n * Builds server payload for the `place_order` execute action.\n *\n * @param clientParams Client PlaceOrder params.\n * @returns `place_order` payload\n */\n async buildPlaceOrderPayload(\n clientParams: EngineExecuteRequestParamsByType['place_order'],\n ): Promise<EngineServerExecutePlaceOrderPayload> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const orderWithNonce = { ...clientParams.order, nonce };\n\n const signature = await this.getSignatureIfNeeded('place_order', {\n // Gets expected type (signature params from `clientParams` and order params from `orderWithNonce`)\n ...clientParams,\n ...orderWithNonce,\n });\n\n return this.buildPlaceOrderPayloadSync({\n ...clientParams,\n order: orderWithNonce,\n signature,\n });\n }\n\n /**\n * Synchronously builds server payload for the `place_order` execute action.\n *\n * @param clientParams Client PlaceOrder params.\n * @returns `place_order` payload\n */\n buildPlaceOrderPayloadSync(\n clientParams: WithSignature<\n EngineExecuteRequestParamsByType['place_order'] & {\n order: EIP712OrderParams;\n }\n >,\n ): EngineServerExecutePlaceOrderPayload {\n const orderEIP712Values = getNadoEIP712Values(\n 'place_order',\n clientParams.order,\n );\n\n return {\n payload: {\n id: clientParams.id ?? null,\n product_id: clientParams.productId,\n order: orderEIP712Values,\n signature: clientParams.signature,\n spot_leverage: clientParams.spotLeverage ?? null,\n borrow_margin: clientParams.borrowMargin ?? null,\n },\n orderParams: clientParams.order,\n };\n }\n\n /**\n * Builds server payload for the `place_orders` execute action.\n * @param clientParams Client PlaceOrders params.\n * @returns `place_orders` payload\n */\n async buildPlaceOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['place_orders'],\n ): Promise<EngineServerExecuteRequestByType['place_orders']> {\n return {\n orders: await Promise.all(\n clientParams.orders.map(async (orderParams) => {\n const payload = await this.buildPlaceOrderPayload(orderParams);\n return payload.payload;\n }),\n ),\n stop_on_failure: clientParams.stopOnFailure ?? null,\n };\n }\n\n /**\n * Builds server payload for the `cancel_orders` execute action. As such, requires a signature to be given\n *\n * @param clientParams Client CancelOrders params.\n * @returns `cancel_orders` payload\n */\n async buildCancelOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['cancel_orders'],\n ): Promise<EngineServerExecuteRequestByType['cancel_orders']> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n const signature = await this.getSignatureIfNeeded(\n 'cancel_orders',\n paramsWithNonce,\n );\n\n return this.buildCancelOrdersPayloadSync({\n ...paramsWithNonce,\n signature,\n });\n }\n\n /**\n * Synchronously builds server payload for the `cancel_orders` execute action.\n *\n * @param clientParams Client CancelOrders params.\n * @returns `cancel_orders` payload\n */\n buildCancelOrdersPayloadSync(\n clientParams: WithSignature<\n EngineExecuteRequestParamsByType['cancel_orders'] & { nonce: string }\n >,\n ): EngineServerExecuteRequestByType['cancel_orders'] {\n const tx = getNadoEIP712Values('cancel_orders', clientParams);\n\n return {\n tx,\n signature: clientParams.signature,\n required_unfilled_amount: clientParams.requiredUnfilledAmount\n ? toIntegerString(clientParams.requiredUnfilledAmount)\n : undefined,\n };\n }\n\n /**\n * Builds server payload for the `cancel_product_orders` execute action.\n * @param clientParams Client CancelProductOrders params.\n * @returns `cancel_product_orders` payload\n */\n async buildCancelProductOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['cancel_product_orders'],\n ): Promise<EngineServerExecuteRequestByType['cancel_product_orders']> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('cancel_product_orders', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'cancel_product_orders',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `link_signer` execute action.\n *\n * @param clientParams Client LinkSigner params.\n * @returns `link_signer` payload\n */\n async buildLinkSignerPayload(\n clientParams: EngineExecuteRequestParamsByType['link_signer'],\n ): Promise<EngineServerExecuteRequestByType['link_signer']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('link_signer', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'link_signer',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `transfer_quote` execute action.\n *\n * @param clientParams Client TransferQuote params.\n * @returns `transfer_quote` payload\n */\n async buildTransferQuotePayload(\n clientParams: EngineExecuteRequestParamsByType['transfer_quote'],\n ): Promise<EngineServerExecuteRequestByType['transfer_quote']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('transfer_quote', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'transfer_quote',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `mint_nlp` execute action.\n * @param clientParams Client MintNlp params.\n * @returns `mint_nlp` payload\n */\n async buildMintNlpPayload(\n clientParams: EngineExecuteRequestParamsByType['mint_nlp'],\n ): Promise<EngineServerExecuteRequestByType['mint_nlp']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('mint_nlp', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'mint_nlp',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n spot_leverage: clientParams.spotLeverage ?? null,\n };\n }\n\n /**\n * Builds server payload for the `burn_nlp` execute action.\n * @param clientParams Client BurnNlp params.\n * @returns `burn_nlp` payload\n */\n async buildBurnNlpPayload(\n clientParams: EngineExecuteRequestParamsByType['burn_nlp'],\n ): Promise<EngineServerExecuteRequestByType['burn_nlp']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('burn_nlp', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'burn_nlp',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n };\n }\n\n protected async getSignatureIfNeeded<T extends SignableRequestType>(\n requestType: T,\n paramsWithNonce: SignatureParams & SignableRequestTypeToParams[T],\n ) {\n if ('signature' in paramsWithNonce) {\n return paramsWithNonce.signature;\n }\n\n return await this.engineClient.sign(\n requestType,\n paramsWithNonce.verifyingAddr,\n paramsWithNonce.chainId,\n paramsWithNonce,\n );\n }\n\n protected async getTxNonceIfNeeded(\n params: WithBaseEngineExecuteParams<{ subaccountOwner: string }>,\n ) {\n if (params.nonce) {\n return params.nonce;\n }\n return await this.engineClient.getTxNonce(params.subaccountOwner);\n }\n\n protected getOrderNonceIfNeeded(\n params: WithBaseEngineExecuteParams<unknown>,\n ) {\n if (params.nonce) {\n return params.nonce;\n }\n return getOrderNonce();\n }\n}\n"],"mappings":";;;;;;;;;AAuBA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,cAAgC;EAC1C,KAAK,eAAe;CACtB;;;;;;CAOA,MAAM,gCACJ,cACmE;EACnE,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,wBAAwB,eAAe;EAMtE,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,wBACA,eACF;GAIE;EACF;CACF;;;;;;CAOA,MAAM,+BACJ,cACkE;EAClE,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAQjD,OAAO;GACL,WAAA,MAPsB,KAAK,qBAC3B,uBACA,eACF;GAKE,KAAA,GAAA,eAAA,qBAH6B,uBAAuB,eAGnD;GACD,eAAe,aAAa,gBAAgB;EAC9C;CACF;;;;;;;CAQA,MAAM,uBACJ,cAC+C;EAC/C,MAAM,QAAQ,KAAK,sBAAsB,YAAY;EACrD,MAAM,iBAAiB;GAAE,GAAG,aAAa;GAAO;EAAM;EAEtD,MAAM,YAAY,MAAM,KAAK,qBAAqB,eAAe;GAE/D,GAAG;GACH,GAAG;EACL,CAAC;EAED,OAAO,KAAK,2BAA2B;GACrC,GAAG;GACH,OAAO;GACP;EACF,CAAC;CACH;;;;;;;CAQA,2BACE,cAKsC;EACtC,MAAM,qBAAA,GAAA,eAAA,qBACJ,eACA,aAAa,KACf;EAEA,OAAO;G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BAC3B,eACA,eACF;EAKA;CACF;;;;;;;CAQA,MAAM,0BACJ,cAC6D;EAC7D,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAQjD,OAAO;GACL,KAAA,GAAA,eAAA,qBAP6B,kBAAkB,eAO9C;GACD,WAAA,MAPsB,KAAK,qBAC3B,kBACA,eACF;EAKA;CACF;;;;;;CAOA,MAAM,oBACJ,cACuD;EACvD,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,YAAY,eAAe;EAM1D,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,YACA,eACF;GAIE;GACA,eAAe,aAAa,gBAAgB;EAC9C;CACF;;;;;;CAOA,MAAM,oBACJ,cACuD;EACvD,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,YAAY,eAAe;EAM1D,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,YACA,eACF;GAIE;EACF;CACF;CAEA,MAAgB,qBACd,aACA,iBACA;EACA,IAAI,eAAe,iBACjB,OAAO,gBAAgB;EAGzB,OAAO,MAAM,KAAK,aAAa,KAC7B,aACA,gBAAgB,eAChB,gBAAgB,SAChB,eACF;CACF;CAEA,MAAgB,mBACd,QACA;EACA,IAAI,OAAO,OACT,OAAO,OAAO;EAEhB,OAAO,MAAM,KAAK,aAAa,WAAW,OAAO,eAAe;CAClE;CAEA,sBACE,QACA;EACA,IAAI,OAAO,OACT,OAAO,OAAO;EAEhB,QAAA,GAAA,eAAA,eAAqB;CACvB;AACF"}
|
|
1
|
+
{"version":3,"file":"EngineExecuteBuilder.cjs","names":[],"sources":["../src/EngineExecuteBuilder.ts"],"sourcesContent":["import {\n EIP712OrderParams,\n getNadoEIP712Values,\n getOrderNonce,\n SignableRequestType,\n SignableRequestTypeToParams,\n toIntegerString,\n} from '@nadohq/shared';\nimport { EngineBaseClient } from './EngineBaseClient';\nimport {\n EngineExecuteRequestParamsByType,\n EngineServerExecutePlaceOrderPayload,\n EngineServerExecuteRequestByType,\n SignatureParams,\n WithBaseEngineExecuteParams,\n WithSignature,\n} from './types';\n\n/**\n * Builds execute payloads as expected by the server.\n * @param nonce A nonce is computed when one is not provided.\n * @param signature A signature is computed when one is not provided.\n */\nexport class EngineExecuteBuilder {\n readonly engineClient: EngineBaseClient;\n\n constructor(engineClient: EngineBaseClient) {\n this.engineClient = engineClient;\n }\n\n /**\n * Builds server payload for the `liquidate_subaccount` execute action.\n * @param clientParams Client LiquidateSubaccount params.\n * @returns `liquidate_subaccount` payload\n */\n async buildLiquidateSubaccountPayload(\n clientParams: EngineExecuteRequestParamsByType['liquidate_subaccount'],\n ): Promise<EngineServerExecuteRequestByType['liquidate_subaccount']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('liquidate_subaccount', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'liquidate_subaccount',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n };\n }\n\n /**\n * Builds server payload for the `withdraw_collateral` execute action.\n * @param clientParams Client WithdrawCollateral params.\n * @returns `liquidate_subaccount` payload\n */\n async buildWithdrawCollateralPayload(\n clientParams: EngineExecuteRequestParamsByType['withdraw_collateral'],\n ): Promise<EngineServerExecuteRequestByType['withdraw_collateral']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const signature = await this.getSignatureIfNeeded(\n 'withdraw_collateral',\n paramsWithNonce,\n );\n\n const tx = getNadoEIP712Values('withdraw_collateral', paramsWithNonce);\n return {\n signature,\n tx,\n spot_leverage: clientParams.spotLeverage ?? null,\n };\n }\n\n /**\n * Builds server payload for the `withdraw_collateral_v2` execute action.\n * @param clientParams Client WithdrawCollateralV2 params.\n * @returns `withdraw_collateral_v2` payload\n */\n async buildWithdrawCollateralV2Payload(\n clientParams: EngineExecuteRequestParamsByType['withdraw_collateral_v2'],\n ): Promise<EngineServerExecuteRequestByType['withdraw_collateral_v2']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const signature = await this.getSignatureIfNeeded(\n 'withdraw_collateral_v2',\n paramsWithNonce,\n );\n\n const tx = getNadoEIP712Values('withdraw_collateral_v2', paramsWithNonce);\n return {\n signature,\n tx,\n spot_leverage: clientParams.spotLeverage ?? null,\n };\n }\n\n /**\n * Builds server payload for the `place_order` execute action.\n *\n * @param clientParams Client PlaceOrder params.\n * @returns `place_order` payload\n */\n async buildPlaceOrderPayload(\n clientParams: EngineExecuteRequestParamsByType['place_order'],\n ): Promise<EngineServerExecutePlaceOrderPayload> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const orderWithNonce = { ...clientParams.order, nonce };\n\n const signature = await this.getSignatureIfNeeded('place_order', {\n // Gets expected type (signature params from `clientParams` and order params from `orderWithNonce`)\n ...clientParams,\n ...orderWithNonce,\n });\n\n return this.buildPlaceOrderPayloadSync({\n ...clientParams,\n order: orderWithNonce,\n signature,\n });\n }\n\n /**\n * Synchronously builds server payload for the `place_order` execute action.\n *\n * @param clientParams Client PlaceOrder params.\n * @returns `place_order` payload\n */\n buildPlaceOrderPayloadSync(\n clientParams: WithSignature<\n EngineExecuteRequestParamsByType['place_order'] & {\n order: EIP712OrderParams;\n }\n >,\n ): EngineServerExecutePlaceOrderPayload {\n const orderEIP712Values = getNadoEIP712Values(\n 'place_order',\n clientParams.order,\n );\n\n return {\n payload: {\n id: clientParams.id ?? null,\n product_id: clientParams.productId,\n order: orderEIP712Values,\n signature: clientParams.signature,\n spot_leverage: clientParams.spotLeverage ?? null,\n borrow_margin: clientParams.borrowMargin ?? null,\n },\n orderParams: clientParams.order,\n };\n }\n\n /**\n * Builds server payload for the `place_orders` execute action.\n * @param clientParams Client PlaceOrders params.\n * @returns `place_orders` payload\n */\n async buildPlaceOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['place_orders'],\n ): Promise<EngineServerExecuteRequestByType['place_orders']> {\n return {\n orders: await Promise.all(\n clientParams.orders.map(async (orderParams) => {\n const payload = await this.buildPlaceOrderPayload(orderParams);\n return payload.payload;\n }),\n ),\n stop_on_failure: clientParams.stopOnFailure ?? null,\n };\n }\n\n /**\n * Builds server payload for the `cancel_orders` execute action. As such, requires a signature to be given\n *\n * @param clientParams Client CancelOrders params.\n * @returns `cancel_orders` payload\n */\n async buildCancelOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['cancel_orders'],\n ): Promise<EngineServerExecuteRequestByType['cancel_orders']> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n const signature = await this.getSignatureIfNeeded(\n 'cancel_orders',\n paramsWithNonce,\n );\n\n return this.buildCancelOrdersPayloadSync({\n ...paramsWithNonce,\n signature,\n });\n }\n\n /**\n * Synchronously builds server payload for the `cancel_orders` execute action.\n *\n * @param clientParams Client CancelOrders params.\n * @returns `cancel_orders` payload\n */\n buildCancelOrdersPayloadSync(\n clientParams: WithSignature<\n EngineExecuteRequestParamsByType['cancel_orders'] & { nonce: string }\n >,\n ): EngineServerExecuteRequestByType['cancel_orders'] {\n const tx = getNadoEIP712Values('cancel_orders', clientParams);\n\n return {\n tx,\n signature: clientParams.signature,\n required_unfilled_amount: clientParams.requiredUnfilledAmount\n ? toIntegerString(clientParams.requiredUnfilledAmount)\n : undefined,\n };\n }\n\n /**\n * Builds server payload for the `cancel_product_orders` execute action.\n * @param clientParams Client CancelProductOrders params.\n * @returns `cancel_product_orders` payload\n */\n async buildCancelProductOrdersPayload(\n clientParams: EngineExecuteRequestParamsByType['cancel_product_orders'],\n ): Promise<EngineServerExecuteRequestByType['cancel_product_orders']> {\n const nonce = this.getOrderNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('cancel_product_orders', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'cancel_product_orders',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `link_signer` execute action.\n *\n * @param clientParams Client LinkSigner params.\n * @returns `link_signer` payload\n */\n async buildLinkSignerPayload(\n clientParams: EngineExecuteRequestParamsByType['link_signer'],\n ): Promise<EngineServerExecuteRequestByType['link_signer']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('link_signer', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'link_signer',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `transfer_quote` execute action.\n *\n * @param clientParams Client TransferQuote params.\n * @returns `transfer_quote` payload\n */\n async buildTransferQuotePayload(\n clientParams: EngineExecuteRequestParamsByType['transfer_quote'],\n ): Promise<EngineServerExecuteRequestByType['transfer_quote']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('transfer_quote', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'transfer_quote',\n paramsWithNonce,\n );\n\n return {\n tx,\n signature,\n };\n }\n\n /**\n * Builds server payload for the `mint_nlp` execute action.\n * @param clientParams Client MintNlp params.\n * @returns `mint_nlp` payload\n */\n async buildMintNlpPayload(\n clientParams: EngineExecuteRequestParamsByType['mint_nlp'],\n ): Promise<EngineServerExecuteRequestByType['mint_nlp']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('mint_nlp', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'mint_nlp',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n spot_leverage: clientParams.spotLeverage ?? null,\n };\n }\n\n /**\n * Builds server payload for the `burn_nlp` execute action.\n * @param clientParams Client BurnNlp params.\n * @returns `burn_nlp` payload\n */\n async buildBurnNlpPayload(\n clientParams: EngineExecuteRequestParamsByType['burn_nlp'],\n ): Promise<EngineServerExecuteRequestByType['burn_nlp']> {\n const nonce = await this.getTxNonceIfNeeded(clientParams);\n const paramsWithNonce = { ...clientParams, nonce };\n\n const tx = getNadoEIP712Values('burn_nlp', paramsWithNonce);\n const signature = await this.getSignatureIfNeeded(\n 'burn_nlp',\n paramsWithNonce,\n );\n\n return {\n signature,\n tx,\n };\n }\n\n protected async getSignatureIfNeeded<T extends SignableRequestType>(\n requestType: T,\n paramsWithNonce: SignatureParams & SignableRequestTypeToParams[T],\n ) {\n if ('signature' in paramsWithNonce) {\n return paramsWithNonce.signature;\n }\n\n return await this.engineClient.sign(\n requestType,\n paramsWithNonce.verifyingAddr,\n paramsWithNonce.chainId,\n paramsWithNonce,\n );\n }\n\n protected async getTxNonceIfNeeded(\n params: WithBaseEngineExecuteParams<{ subaccountOwner: string }>,\n ) {\n if (params.nonce) {\n return params.nonce;\n }\n return await this.engineClient.getTxNonce(params.subaccountOwner);\n }\n\n protected getOrderNonceIfNeeded(\n params: WithBaseEngineExecuteParams<unknown>,\n ) {\n if (params.nonce) {\n return params.nonce;\n }\n return getOrderNonce();\n }\n}\n"],"mappings":";;;;;;;;;AAuBA,IAAa,uBAAb,MAAkC;CAGhC,YAAY,cAAgC;EAC1C,KAAK,eAAe;CACtB;;;;;;CAOA,MAAM,gCACJ,cACmE;EACnE,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,wBAAwB,eAAe;EAMtE,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,wBACA,eACF;GA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KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,YAAY,eAAe;EAM1D,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,YACA,eACF;GAIE;GACA,eAAe,aAAa,gBAAgB;EAC9C;CACF;;;;;;CAOA,MAAM,oBACJ,cACuD;EACvD,MAAM,QAAQ,MAAM,KAAK,mBAAmB,YAAY;EACxD,MAAM,kBAAkB;GAAE,GAAG;GAAc;EAAM;EAEjD,MAAM,MAAA,GAAA,eAAA,qBAAyB,YAAY,eAAe;EAM1D,OAAO;GACL,WAAA,MANsB,KAAK,qBAC3B,YACA,eACF;GAIE;EACF;CACF;CAEA,MAAgB,qBACd,aACA,iBACA;EACA,IAAI,eAAe,iBACjB,OAAO,gBAAgB;EAGzB,OAAO,MAAM,KAAK,aAAa,KAC7B,aACA,gBAAgB,eAChB,gBAAgB,SAChB,eACF;CACF;CAEA,MAAgB,mBACd,QACA;EACA,IAAI,OAAO,OACT,OAAO,OAAO;EAEhB,OAAO,MAAM,KAAK,aAAa,WAAW,OAAO,eAAe;CAClE;CAEA,sBACE,QACA;EACA,IAAI,OAAO,OACT,OAAO,OAAO;EAEhB,QAAA,GAAA,eAAA,eAAqB;CACvB;AACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as EngineExecuteBuilder } from "./EngineExecuteBuilder-
|
|
1
|
+
import { t as EngineExecuteBuilder } from "./EngineExecuteBuilder-CEqUxV3h.cjs";
|
|
2
2
|
export { EngineExecuteBuilder };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as EngineExecuteBuilder } from "./EngineExecuteBuilder-
|
|
1
|
+
import { t as EngineExecuteBuilder } from "./EngineExecuteBuilder-BHX9mMqF.js";
|
|
2
2
|
export { EngineExecuteBuilder };
|
|
@@ -44,6 +44,23 @@ var EngineExecuteBuilder = class {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
+
* Builds server payload for the `withdraw_collateral_v2` execute action.
|
|
48
|
+
* @param clientParams Client WithdrawCollateralV2 params.
|
|
49
|
+
* @returns `withdraw_collateral_v2` payload
|
|
50
|
+
*/
|
|
51
|
+
async buildWithdrawCollateralV2Payload(clientParams) {
|
|
52
|
+
const nonce = await this.getTxNonceIfNeeded(clientParams);
|
|
53
|
+
const paramsWithNonce = {
|
|
54
|
+
...clientParams,
|
|
55
|
+
nonce
|
|
56
|
+
};
|
|
57
|
+
return {
|
|
58
|
+
signature: await this.getSignatureIfNeeded("withdraw_collateral_v2", paramsWithNonce),
|
|
59
|
+
tx: getNadoEIP712Values("withdraw_collateral_v2", paramsWithNonce),
|
|
60
|
+
spot_leverage: clientParams.spotLeverage ?? null
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
47
64
|
* Builds server payload for the `place_order` execute action.
|
|
48
65
|
*
|
|
49
66
|
* @param clientParams Client PlaceOrder params.
|