@nadohq/engine-client 0.1.0-alpha.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/README.md +2 -0
- package/dist/EngineBaseClient.cjs +166 -0
- package/dist/EngineBaseClient.cjs.map +1 -0
- package/dist/EngineBaseClient.d.cts +75 -0
- package/dist/EngineBaseClient.d.ts +75 -0
- package/dist/EngineBaseClient.js +133 -0
- package/dist/EngineBaseClient.js.map +1 -0
- package/dist/EngineClient.cjs +40 -0
- package/dist/EngineClient.cjs.map +1 -0
- package/dist/EngineClient.d.cts +23 -0
- package/dist/EngineClient.d.ts +23 -0
- package/dist/EngineClient.js +15 -0
- package/dist/EngineClient.js.map +1 -0
- package/dist/EngineExecuteBuilder.cjs +304 -0
- package/dist/EngineExecuteBuilder.cjs.map +1 -0
- package/dist/EngineExecuteBuilder.d.cts +118 -0
- package/dist/EngineExecuteBuilder.d.ts +118 -0
- package/dist/EngineExecuteBuilder.js +282 -0
- package/dist/EngineExecuteBuilder.js.map +1 -0
- package/dist/EngineExecuteClient.cjs +114 -0
- package/dist/EngineExecuteClient.cjs.map +1 -0
- package/dist/EngineExecuteClient.d.cts +28 -0
- package/dist/EngineExecuteClient.d.ts +28 -0
- package/dist/EngineExecuteClient.js +89 -0
- package/dist/EngineExecuteClient.js.map +1 -0
- package/dist/EngineQueryClient.cjs +431 -0
- package/dist/EngineQueryClient.cjs.map +1 -0
- package/dist/EngineQueryClient.d.cts +143 -0
- package/dist/EngineQueryClient.d.ts +143 -0
- package/dist/EngineQueryClient.js +424 -0
- package/dist/EngineQueryClient.js.map +1 -0
- package/dist/EngineWebClient.cjs +75 -0
- package/dist/EngineWebClient.cjs.map +1 -0
- package/dist/EngineWebClient.d.cts +31 -0
- package/dist/EngineWebClient.d.ts +31 -0
- package/dist/EngineWebClient.js +50 -0
- package/dist/EngineWebClient.js.map +1 -0
- package/dist/endpoints.cjs +49 -0
- package/dist/endpoints.cjs.map +1 -0
- package/dist/endpoints.d.cts +7 -0
- package/dist/endpoints.d.ts +7 -0
- package/dist/endpoints.js +22 -0
- package/dist/endpoints.js.map +1 -0
- package/dist/index.cjs +31 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/types/EngineServerFailureError.cjs +36 -0
- package/dist/types/EngineServerFailureError.cjs.map +1 -0
- package/dist/types/EngineServerFailureError.d.cts +11 -0
- package/dist/types/EngineServerFailureError.d.ts +11 -0
- package/dist/types/EngineServerFailureError.js +11 -0
- package/dist/types/EngineServerFailureError.js.map +1 -0
- package/dist/types/clientExecuteTypes.cjs +19 -0
- package/dist/types/clientExecuteTypes.cjs.map +1 -0
- package/dist/types/clientExecuteTypes.d.cts +74 -0
- package/dist/types/clientExecuteTypes.d.ts +74 -0
- package/dist/types/clientExecuteTypes.js +1 -0
- package/dist/types/clientExecuteTypes.js.map +1 -0
- package/dist/types/clientQueryTypes.cjs +19 -0
- package/dist/types/clientQueryTypes.cjs.map +1 -0
- package/dist/types/clientQueryTypes.d.cts +189 -0
- package/dist/types/clientQueryTypes.d.ts +189 -0
- package/dist/types/clientQueryTypes.js +1 -0
- package/dist/types/clientQueryTypes.js.map +1 -0
- package/dist/types/index.cjs +39 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +10 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/serverExecuteTypes.cjs +19 -0
- package/dist/types/serverExecuteTypes.cjs.map +1 -0
- package/dist/types/serverExecuteTypes.d.cts +91 -0
- package/dist/types/serverExecuteTypes.d.ts +91 -0
- package/dist/types/serverExecuteTypes.js +1 -0
- package/dist/types/serverExecuteTypes.js.map +1 -0
- package/dist/types/serverQueryModelTypes.cjs +19 -0
- package/dist/types/serverQueryModelTypes.cjs.map +1 -0
- package/dist/types/serverQueryModelTypes.d.cts +73 -0
- package/dist/types/serverQueryModelTypes.d.ts +73 -0
- package/dist/types/serverQueryModelTypes.js +1 -0
- package/dist/types/serverQueryModelTypes.js.map +1 -0
- package/dist/types/serverQueryTypes.cjs +19 -0
- package/dist/types/serverQueryTypes.cjs.map +1 -0
- package/dist/types/serverQueryTypes.d.cts +292 -0
- package/dist/types/serverQueryTypes.d.ts +292 -0
- package/dist/types/serverQueryTypes.js +1 -0
- package/dist/types/serverQueryTypes.js.map +1 -0
- package/dist/types/serverSubscriptionEventTypes.cjs +19 -0
- package/dist/types/serverSubscriptionEventTypes.cjs.map +1 -0
- package/dist/types/serverSubscriptionEventTypes.d.cts +71 -0
- package/dist/types/serverSubscriptionEventTypes.d.ts +71 -0
- package/dist/types/serverSubscriptionEventTypes.js +1 -0
- package/dist/types/serverSubscriptionEventTypes.js.map +1 -0
- package/dist/types/serverSubscriptionTypes.cjs +19 -0
- package/dist/types/serverSubscriptionTypes.cjs.map +1 -0
- package/dist/types/serverSubscriptionTypes.d.cts +63 -0
- package/dist/types/serverSubscriptionTypes.d.ts +63 -0
- package/dist/types/serverSubscriptionTypes.js +1 -0
- package/dist/types/serverSubscriptionTypes.js.map +1 -0
- package/dist/utils/index.cjs +25 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +6 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +3 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/productEngineTypeMappers.cjs +49 -0
- package/dist/utils/productEngineTypeMappers.cjs.map +1 -0
- package/dist/utils/productEngineTypeMappers.d.cts +7 -0
- package/dist/utils/productEngineTypeMappers.d.ts +7 -0
- package/dist/utils/productEngineTypeMappers.js +23 -0
- package/dist/utils/productEngineTypeMappers.js.map +1 -0
- package/dist/utils/queryDataMappers.cjs +282 -0
- package/dist/utils/queryDataMappers.cjs.map +1 -0
- package/dist/utils/queryDataMappers.d.cts +18 -0
- package/dist/utils/queryDataMappers.d.ts +18 -0
- package/dist/utils/queryDataMappers.js +258 -0
- package/dist/utils/queryDataMappers.js.map +1 -0
- package/package.json +52 -0
- package/src/EngineBaseClient.ts +223 -0
- package/src/EngineClient.ts +13 -0
- package/src/EngineExecuteBuilder.ts +381 -0
- package/src/EngineExecuteClient.ts +122 -0
- package/src/EngineQueryClient.ts +553 -0
- package/src/EngineWebClient.ts +72 -0
- package/src/endpoints.ts +21 -0
- package/src/index.ts +4 -0
- package/src/types/EngineServerFailureError.ts +12 -0
- package/src/types/clientExecuteTypes.ts +118 -0
- package/src/types/clientQueryTypes.ts +267 -0
- package/src/types/index.ts +8 -0
- package/src/types/serverExecuteTypes.ts +138 -0
- package/src/types/serverQueryModelTypes.ts +83 -0
- package/src/types/serverQueryTypes.ts +382 -0
- package/src/types/serverSubscriptionEventTypes.ts +74 -0
- package/src/types/serverSubscriptionTypes.ts +79 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/productEngineTypeMappers.ts +24 -0
- package/src/utils/queryDataMappers.ts +303 -0
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/EngineBaseClient.ts
|
|
31
|
+
var EngineBaseClient_exports = {};
|
|
32
|
+
__export(EngineBaseClient_exports, {
|
|
33
|
+
EngineBaseClient: () => EngineBaseClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(EngineBaseClient_exports);
|
|
36
|
+
var import_contracts = require("@nadohq/contracts");
|
|
37
|
+
var import_utils = require("@nadohq/utils");
|
|
38
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
39
|
+
var import_EngineServerFailureError = require("./types/EngineServerFailureError.cjs");
|
|
40
|
+
var EngineBaseClient = class {
|
|
41
|
+
constructor(opts) {
|
|
42
|
+
this.opts = opts;
|
|
43
|
+
this.axiosInstance = import_axios.default.create({
|
|
44
|
+
withCredentials: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Sets the linked signer for execute requests
|
|
49
|
+
*
|
|
50
|
+
* @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
|
|
51
|
+
*/
|
|
52
|
+
setLinkedSigner(linkedSignerWalletClient) {
|
|
53
|
+
this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
|
|
54
|
+
}
|
|
55
|
+
async getTxNonce(address) {
|
|
56
|
+
const addr = address ?? this.opts.walletClient?.account.address;
|
|
57
|
+
if (!addr) {
|
|
58
|
+
throw new import_utils.WalletNotProvidedError();
|
|
59
|
+
}
|
|
60
|
+
return (await this.getNonces({
|
|
61
|
+
address: addr
|
|
62
|
+
})).txNonce;
|
|
63
|
+
}
|
|
64
|
+
async getNonces(params) {
|
|
65
|
+
const baseResp = await this.query("nonces", params);
|
|
66
|
+
return {
|
|
67
|
+
orderNonce: baseResp.order_nonce,
|
|
68
|
+
txNonce: baseResp.tx_nonce
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Queries the engine, all query params are stringified into the query string
|
|
73
|
+
*
|
|
74
|
+
* @param requestType
|
|
75
|
+
* @param params
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
async query(requestType, params) {
|
|
79
|
+
const request = this.getQueryRequest(requestType, params);
|
|
80
|
+
const response = await this.axiosInstance.post(
|
|
81
|
+
`${this.opts.url}/query`,
|
|
82
|
+
request
|
|
83
|
+
);
|
|
84
|
+
this.checkResponseStatus(response);
|
|
85
|
+
this.checkServerStatus(response);
|
|
86
|
+
const successResponse = response;
|
|
87
|
+
return successResponse.data.data;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* A simple, typechecked fn for constructing a query request in the format expected by the server.
|
|
91
|
+
*
|
|
92
|
+
* @param requestType
|
|
93
|
+
* @param params
|
|
94
|
+
*/
|
|
95
|
+
getQueryRequest(requestType, params) {
|
|
96
|
+
return {
|
|
97
|
+
type: requestType,
|
|
98
|
+
...params
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped
|
|
103
|
+
* in an EngineServerFailureError on failure.
|
|
104
|
+
*
|
|
105
|
+
* @param requestType
|
|
106
|
+
* @param params
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
async execute(requestType, params) {
|
|
110
|
+
const reqBody = this.getExecuteRequest(requestType, params);
|
|
111
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/execute`, reqBody);
|
|
112
|
+
this.checkResponseStatus(response);
|
|
113
|
+
this.checkServerStatus(response);
|
|
114
|
+
return response.data;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A simple, typechecked fn for constructing an execute request in the format expected by the server.
|
|
118
|
+
*
|
|
119
|
+
* @param requestType
|
|
120
|
+
* @param params
|
|
121
|
+
*/
|
|
122
|
+
getExecuteRequest(requestType, params) {
|
|
123
|
+
return {
|
|
124
|
+
[requestType]: params
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Signs a given request with the signer provided to the engine
|
|
129
|
+
*
|
|
130
|
+
* @param requestType
|
|
131
|
+
* @param verifyingContract
|
|
132
|
+
* @param chainId
|
|
133
|
+
* @param params
|
|
134
|
+
* @public
|
|
135
|
+
*/
|
|
136
|
+
async sign(requestType, verifyingContract, chainId, params) {
|
|
137
|
+
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
138
|
+
if (!walletClient) {
|
|
139
|
+
throw new import_utils.WalletNotProvidedError();
|
|
140
|
+
}
|
|
141
|
+
return (0, import_contracts.getSignedTransactionRequest)({
|
|
142
|
+
chainId,
|
|
143
|
+
requestParams: params,
|
|
144
|
+
requestType,
|
|
145
|
+
walletClient,
|
|
146
|
+
verifyingContract
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
checkResponseStatus(response) {
|
|
150
|
+
if (response.status !== 200 || !response.data) {
|
|
151
|
+
throw Error(
|
|
152
|
+
`Unexpected response from server: ${response.status} ${response.statusText}`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
checkServerStatus(response) {
|
|
157
|
+
if (response.data.status !== "success") {
|
|
158
|
+
throw new import_EngineServerFailureError.EngineServerFailureError(response.data);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
EngineBaseClient
|
|
165
|
+
});
|
|
166
|
+
//# sourceMappingURL=EngineBaseClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n} from '@nadohq/contracts';\nimport { WalletNotProvidedError } from '@nadohq/utils';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequest,\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\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 });\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 * A simple, typechecked fn for constructing a query request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): EngineServerQueryRequest<TRequestType> {\n return {\n type: requestType,\n ...params,\n };\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 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}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n EngineServerExecuteResult | EngineQueryRequestResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAKO;AACP,mBAAuC;AACvC,mBAAoD;AAepD,sCAAyC;AAqBlC,IAAM,mBAAN,MAAuB;AAAA,EAI5B,YAAY,MAAwB;AAClC,SAAK,OAAO;AACZ,SAAK,gBAAgB,aAAAA,QAAM,OAAO;AAAA,MAChC,iBAAiB;AAAA,IACnB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,gBACL,0BACA;AACA,SAAK,KAAK,2BAA2B,4BAA4B;AAAA,EACnE;AAAA,EAEA,MAAa,WAAW,SAAmC;AACzD,UAAM,OAAO,WAAW,KAAK,KAAK,cAAc,QAAQ;AAExD,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,oCAAuB;AAAA,IACnC;AAEA,YACE,MAAM,KAAK,UAAU;AAAA,MACnB,SAAS;AAAA,IACX,CAAC,GACD;AAAA,EACJ;AAAA,EAEA,MAAa,UACX,QACkC;AAClC,UAAM,WAAW,MAAM,KAAK,MAAM,UAAU,MAAM;AAElD,WAAO;AAAA,MACL,YAAY,SAAS;AAAA,MACrB,SAAS,SAAS;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,MACX,aACA,QACwD;AACxD,UAAM,UAAU,KAAK,gBAAgB,aAAa,MAAM;AACxD,UAAM,WAAW,MAAM,KAAK,cAAc;AAAA,MACxC,GAAG,KAAK,KAAK,GAAG;AAAA,MAChB;AAAA,IACF;AAEA,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,gBACL,aACA,QACwC;AACxC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAa,QACX,aACA,QACyD;AACzD,UAAM,UAAU,KAAK,kBAAkB,aAAa,MAAM;AAC1D,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,YAAY,OAAO;AAErC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,WAAO,SAAS;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,kBACL,aACA,QAC0B;AAC1B,WAAO;AAAA,MACL,CAAC,WAAW,GAAG;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAa,KACX,aACA,mBACA,SACA,QACA;AAEA,UAAM,eACJ,KAAK,KAAK,4BAA4B,KAAK,KAAK;AAElD,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,oCAAuB;AAAA,IACnC;AAEA,eAAO,8CAA4B;AAAA,MACjC;AAAA,MACA,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAC5E;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,yDAAyB,SAAS,IAAI;AAAA,IAClD;AAAA,EACF;AACF;","names":["axios"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WalletClientWithAccount, SignableRequestType, SignableRequestTypeToParams } from '@nadohq/contracts';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { GetEngineNoncesParams, GetEngineNoncesResponse } from './types/clientQueryTypes.cjs';
|
|
4
|
+
import { EngineServerExecuteRequestType, EngineServerExecuteRequestByType, EngineServerExecuteSuccessResult } from './types/serverExecuteTypes.cjs';
|
|
5
|
+
import { EngineServerQueryRequestType, EngineServerQueryRequestByType, EngineServerQueryResponseByType, EngineServerQueryRequest } from './types/serverQueryTypes.cjs';
|
|
6
|
+
import '@nadohq/utils';
|
|
7
|
+
import './types/serverQueryModelTypes.cjs';
|
|
8
|
+
|
|
9
|
+
interface EngineClientOpts {
|
|
10
|
+
url: string;
|
|
11
|
+
walletClient?: WalletClientWithAccount;
|
|
12
|
+
linkedSignerWalletClient?: WalletClientWithAccount;
|
|
13
|
+
}
|
|
14
|
+
type EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;
|
|
15
|
+
/**
|
|
16
|
+
* Base client for all engine requests
|
|
17
|
+
*/
|
|
18
|
+
declare class EngineBaseClient {
|
|
19
|
+
readonly opts: EngineClientOpts;
|
|
20
|
+
readonly axiosInstance: AxiosInstance;
|
|
21
|
+
constructor(opts: EngineClientOpts);
|
|
22
|
+
/**
|
|
23
|
+
* Sets the linked signer for execute requests
|
|
24
|
+
*
|
|
25
|
+
* @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
|
|
26
|
+
*/
|
|
27
|
+
setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
|
|
28
|
+
getTxNonce(address?: string): Promise<string>;
|
|
29
|
+
getNonces(params: GetEngineNoncesParams): Promise<GetEngineNoncesResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Queries the engine, all query params are stringified into the query string
|
|
32
|
+
*
|
|
33
|
+
* @param requestType
|
|
34
|
+
* @param params
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
query<TRequestType extends EngineServerQueryRequestType>(requestType: TRequestType, params: EngineServerQueryRequestByType[TRequestType]): Promise<EngineServerQueryResponseByType[TRequestType]>;
|
|
38
|
+
/**
|
|
39
|
+
* A simple, typechecked fn for constructing a query request in the format expected by the server.
|
|
40
|
+
*
|
|
41
|
+
* @param requestType
|
|
42
|
+
* @param params
|
|
43
|
+
*/
|
|
44
|
+
getQueryRequest<TRequestType extends EngineServerQueryRequestType>(requestType: TRequestType, params: EngineServerQueryRequestByType[TRequestType]): EngineServerQueryRequest<TRequestType>;
|
|
45
|
+
/**
|
|
46
|
+
* POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped
|
|
47
|
+
* in an EngineServerFailureError on failure.
|
|
48
|
+
*
|
|
49
|
+
* @param requestType
|
|
50
|
+
* @param params
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
execute<TRequestType extends EngineServerExecuteRequestType>(requestType: TRequestType, params: EngineServerExecuteRequestByType[TRequestType]): Promise<EngineServerExecuteSuccessResult<TRequestType>>;
|
|
54
|
+
/**
|
|
55
|
+
* A simple, typechecked fn for constructing an execute request in the format expected by the server.
|
|
56
|
+
*
|
|
57
|
+
* @param requestType
|
|
58
|
+
* @param params
|
|
59
|
+
*/
|
|
60
|
+
getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(requestType: TRequestType, params: EngineServerExecuteRequestByType[TRequestType]): EngineExecuteRequestBody;
|
|
61
|
+
/**
|
|
62
|
+
* Signs a given request with the signer provided to the engine
|
|
63
|
+
*
|
|
64
|
+
* @param requestType
|
|
65
|
+
* @param verifyingContract
|
|
66
|
+
* @param chainId
|
|
67
|
+
* @param params
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
sign<T extends SignableRequestType>(requestType: T, verifyingContract: string, chainId: number, params: SignableRequestTypeToParams[T]): Promise<`0x${string}`>;
|
|
71
|
+
private checkResponseStatus;
|
|
72
|
+
private checkServerStatus;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { EngineBaseClient, type EngineClientOpts };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { WalletClientWithAccount, SignableRequestType, SignableRequestTypeToParams } from '@nadohq/contracts';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import { GetEngineNoncesParams, GetEngineNoncesResponse } from './types/clientQueryTypes.js';
|
|
4
|
+
import { EngineServerExecuteRequestType, EngineServerExecuteRequestByType, EngineServerExecuteSuccessResult } from './types/serverExecuteTypes.js';
|
|
5
|
+
import { EngineServerQueryRequestType, EngineServerQueryRequestByType, EngineServerQueryResponseByType, EngineServerQueryRequest } from './types/serverQueryTypes.js';
|
|
6
|
+
import '@nadohq/utils';
|
|
7
|
+
import './types/serverQueryModelTypes.js';
|
|
8
|
+
|
|
9
|
+
interface EngineClientOpts {
|
|
10
|
+
url: string;
|
|
11
|
+
walletClient?: WalletClientWithAccount;
|
|
12
|
+
linkedSignerWalletClient?: WalletClientWithAccount;
|
|
13
|
+
}
|
|
14
|
+
type EngineExecuteRequestBody = Partial<EngineServerExecuteRequestByType>;
|
|
15
|
+
/**
|
|
16
|
+
* Base client for all engine requests
|
|
17
|
+
*/
|
|
18
|
+
declare class EngineBaseClient {
|
|
19
|
+
readonly opts: EngineClientOpts;
|
|
20
|
+
readonly axiosInstance: AxiosInstance;
|
|
21
|
+
constructor(opts: EngineClientOpts);
|
|
22
|
+
/**
|
|
23
|
+
* Sets the linked signer for execute requests
|
|
24
|
+
*
|
|
25
|
+
* @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
|
|
26
|
+
*/
|
|
27
|
+
setLinkedSigner(linkedSignerWalletClient: WalletClientWithAccount | null): void;
|
|
28
|
+
getTxNonce(address?: string): Promise<string>;
|
|
29
|
+
getNonces(params: GetEngineNoncesParams): Promise<GetEngineNoncesResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Queries the engine, all query params are stringified into the query string
|
|
32
|
+
*
|
|
33
|
+
* @param requestType
|
|
34
|
+
* @param params
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
query<TRequestType extends EngineServerQueryRequestType>(requestType: TRequestType, params: EngineServerQueryRequestByType[TRequestType]): Promise<EngineServerQueryResponseByType[TRequestType]>;
|
|
38
|
+
/**
|
|
39
|
+
* A simple, typechecked fn for constructing a query request in the format expected by the server.
|
|
40
|
+
*
|
|
41
|
+
* @param requestType
|
|
42
|
+
* @param params
|
|
43
|
+
*/
|
|
44
|
+
getQueryRequest<TRequestType extends EngineServerQueryRequestType>(requestType: TRequestType, params: EngineServerQueryRequestByType[TRequestType]): EngineServerQueryRequest<TRequestType>;
|
|
45
|
+
/**
|
|
46
|
+
* POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped
|
|
47
|
+
* in an EngineServerFailureError on failure.
|
|
48
|
+
*
|
|
49
|
+
* @param requestType
|
|
50
|
+
* @param params
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
execute<TRequestType extends EngineServerExecuteRequestType>(requestType: TRequestType, params: EngineServerExecuteRequestByType[TRequestType]): Promise<EngineServerExecuteSuccessResult<TRequestType>>;
|
|
54
|
+
/**
|
|
55
|
+
* A simple, typechecked fn for constructing an execute request in the format expected by the server.
|
|
56
|
+
*
|
|
57
|
+
* @param requestType
|
|
58
|
+
* @param params
|
|
59
|
+
*/
|
|
60
|
+
getExecuteRequest<TRequestType extends EngineServerExecuteRequestType>(requestType: TRequestType, params: EngineServerExecuteRequestByType[TRequestType]): EngineExecuteRequestBody;
|
|
61
|
+
/**
|
|
62
|
+
* Signs a given request with the signer provided to the engine
|
|
63
|
+
*
|
|
64
|
+
* @param requestType
|
|
65
|
+
* @param verifyingContract
|
|
66
|
+
* @param chainId
|
|
67
|
+
* @param params
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
sign<T extends SignableRequestType>(requestType: T, verifyingContract: string, chainId: number, params: SignableRequestTypeToParams[T]): Promise<`0x${string}`>;
|
|
71
|
+
private checkResponseStatus;
|
|
72
|
+
private checkServerStatus;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { EngineBaseClient, type EngineClientOpts };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// src/EngineBaseClient.ts
|
|
2
|
+
import {
|
|
3
|
+
getSignedTransactionRequest
|
|
4
|
+
} from "@nadohq/contracts";
|
|
5
|
+
import { WalletNotProvidedError } from "@nadohq/utils";
|
|
6
|
+
import axios from "axios";
|
|
7
|
+
import { EngineServerFailureError } from "./types/EngineServerFailureError.js";
|
|
8
|
+
var EngineBaseClient = class {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.opts = opts;
|
|
11
|
+
this.axiosInstance = axios.create({
|
|
12
|
+
withCredentials: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets the linked signer for execute requests
|
|
17
|
+
*
|
|
18
|
+
* @param linkedSignerWalletClient The linkedSigner to use for all signatures. Set to null to revert to the chain signer
|
|
19
|
+
*/
|
|
20
|
+
setLinkedSigner(linkedSignerWalletClient) {
|
|
21
|
+
this.opts.linkedSignerWalletClient = linkedSignerWalletClient ?? void 0;
|
|
22
|
+
}
|
|
23
|
+
async getTxNonce(address) {
|
|
24
|
+
const addr = address ?? this.opts.walletClient?.account.address;
|
|
25
|
+
if (!addr) {
|
|
26
|
+
throw new WalletNotProvidedError();
|
|
27
|
+
}
|
|
28
|
+
return (await this.getNonces({
|
|
29
|
+
address: addr
|
|
30
|
+
})).txNonce;
|
|
31
|
+
}
|
|
32
|
+
async getNonces(params) {
|
|
33
|
+
const baseResp = await this.query("nonces", params);
|
|
34
|
+
return {
|
|
35
|
+
orderNonce: baseResp.order_nonce,
|
|
36
|
+
txNonce: baseResp.tx_nonce
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Queries the engine, all query params are stringified into the query string
|
|
41
|
+
*
|
|
42
|
+
* @param requestType
|
|
43
|
+
* @param params
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
async query(requestType, params) {
|
|
47
|
+
const request = this.getQueryRequest(requestType, params);
|
|
48
|
+
const response = await this.axiosInstance.post(
|
|
49
|
+
`${this.opts.url}/query`,
|
|
50
|
+
request
|
|
51
|
+
);
|
|
52
|
+
this.checkResponseStatus(response);
|
|
53
|
+
this.checkServerStatus(response);
|
|
54
|
+
const successResponse = response;
|
|
55
|
+
return successResponse.data.data;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A simple, typechecked fn for constructing a query request in the format expected by the server.
|
|
59
|
+
*
|
|
60
|
+
* @param requestType
|
|
61
|
+
* @param params
|
|
62
|
+
*/
|
|
63
|
+
getQueryRequest(requestType, params) {
|
|
64
|
+
return {
|
|
65
|
+
type: requestType,
|
|
66
|
+
...params
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* POSTs an execute message to the engine and returns the successful response. Throws the failure response wrapped
|
|
71
|
+
* in an EngineServerFailureError on failure.
|
|
72
|
+
*
|
|
73
|
+
* @param requestType
|
|
74
|
+
* @param params
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
async execute(requestType, params) {
|
|
78
|
+
const reqBody = this.getExecuteRequest(requestType, params);
|
|
79
|
+
const response = await this.axiosInstance.post(`${this.opts.url}/execute`, reqBody);
|
|
80
|
+
this.checkResponseStatus(response);
|
|
81
|
+
this.checkServerStatus(response);
|
|
82
|
+
return response.data;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A simple, typechecked fn for constructing an execute request in the format expected by the server.
|
|
86
|
+
*
|
|
87
|
+
* @param requestType
|
|
88
|
+
* @param params
|
|
89
|
+
*/
|
|
90
|
+
getExecuteRequest(requestType, params) {
|
|
91
|
+
return {
|
|
92
|
+
[requestType]: params
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Signs a given request with the signer provided to the engine
|
|
97
|
+
*
|
|
98
|
+
* @param requestType
|
|
99
|
+
* @param verifyingContract
|
|
100
|
+
* @param chainId
|
|
101
|
+
* @param params
|
|
102
|
+
* @public
|
|
103
|
+
*/
|
|
104
|
+
async sign(requestType, verifyingContract, chainId, params) {
|
|
105
|
+
const walletClient = this.opts.linkedSignerWalletClient ?? this.opts.walletClient;
|
|
106
|
+
if (!walletClient) {
|
|
107
|
+
throw new WalletNotProvidedError();
|
|
108
|
+
}
|
|
109
|
+
return getSignedTransactionRequest({
|
|
110
|
+
chainId,
|
|
111
|
+
requestParams: params,
|
|
112
|
+
requestType,
|
|
113
|
+
walletClient,
|
|
114
|
+
verifyingContract
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
checkResponseStatus(response) {
|
|
118
|
+
if (response.status !== 200 || !response.data) {
|
|
119
|
+
throw Error(
|
|
120
|
+
`Unexpected response from server: ${response.status} ${response.statusText}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
checkServerStatus(response) {
|
|
125
|
+
if (response.data.status !== "success") {
|
|
126
|
+
throw new EngineServerFailureError(response.data);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export {
|
|
131
|
+
EngineBaseClient
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=EngineBaseClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/EngineBaseClient.ts"],"sourcesContent":["import {\n getSignedTransactionRequest,\n SignableRequestType,\n SignableRequestTypeToParams,\n WalletClientWithAccount,\n} from '@nadohq/contracts';\nimport { WalletNotProvidedError } from '@nadohq/utils';\nimport axios, { AxiosInstance, AxiosResponse } from 'axios';\nimport {\n EngineServerExecuteRequestByType,\n EngineServerExecuteRequestType,\n EngineServerExecuteResult,\n EngineServerExecuteSuccessResult,\n EngineServerQueryRequest,\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\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 });\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 * A simple, typechecked fn for constructing a query request in the format expected by the server.\n *\n * @param requestType\n * @param params\n */\n public getQueryRequest<TRequestType extends EngineServerQueryRequestType>(\n requestType: TRequestType,\n params: EngineServerQueryRequestByType[TRequestType],\n ): EngineServerQueryRequest<TRequestType> {\n return {\n type: requestType,\n ...params,\n };\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 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}`,\n );\n }\n }\n\n private checkServerStatus(\n response: AxiosResponse<\n EngineServerExecuteResult | EngineQueryRequestResponse\n >,\n ) {\n if (response.data.status !== 'success') {\n throw new EngineServerFailureError(response.data);\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAIK;AACP,SAAS,8BAA8B;AACvC,OAAO,WAA6C;AAepD,SAAS,gCAAgC;AAqBlC,IAAM,mBAAN,MAAuB;AAAA,EAI5B,YAAY,MAAwB;AAClC,SAAK,OAAO;AACZ,SAAK,gBAAgB,MAAM,OAAO;AAAA,MAChC,iBAAiB;AAAA,IACnB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,gBACL,0BACA;AACA,SAAK,KAAK,2BAA2B,4BAA4B;AAAA,EACnE;AAAA,EAEA,MAAa,WAAW,SAAmC;AACzD,UAAM,OAAO,WAAW,KAAK,KAAK,cAAc,QAAQ;AAExD,QAAI,CAAC,MAAM;AACT,YAAM,IAAI,uBAAuB;AAAA,IACnC;AAEA,YACE,MAAM,KAAK,UAAU;AAAA,MACnB,SAAS;AAAA,IACX,CAAC,GACD;AAAA,EACJ;AAAA,EAEA,MAAa,UACX,QACkC;AAClC,UAAM,WAAW,MAAM,KAAK,MAAM,UAAU,MAAM;AAElD,WAAO;AAAA,MACL,YAAY,SAAS;AAAA,MACrB,SAAS,SAAS;AAAA,IACpB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,MACX,aACA,QACwD;AACxD,UAAM,UAAU,KAAK,gBAAgB,aAAa,MAAM;AACxD,UAAM,WAAW,MAAM,KAAK,cAAc;AAAA,MACxC,GAAG,KAAK,KAAK,GAAG;AAAA,MAChB;AAAA,IACF;AAEA,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,UAAM,kBAAkB;AAIxB,WAAO,gBAAgB,KAAK;AAAA,EAC9B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,gBACL,aACA,QACwC;AACxC,WAAO;AAAA,MACL,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUA,MAAa,QACX,aACA,QACyD;AACzD,UAAM,UAAU,KAAK,kBAAkB,aAAa,MAAM;AAC1D,UAAM,WAAW,MAAM,KAAK,cAAc,KAExC,GAAG,KAAK,KAAK,GAAG,YAAY,OAAO;AAErC,SAAK,oBAAoB,QAAQ;AACjC,SAAK,kBAAkB,QAAQ;AAG/B,WAAO,SAAS;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQO,kBACL,aACA,QAC0B;AAC1B,WAAO;AAAA,MACL,CAAC,WAAW,GAAG;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAa,KACX,aACA,mBACA,SACA,QACA;AAEA,UAAM,eACJ,KAAK,KAAK,4BAA4B,KAAK,KAAK;AAElD,QAAI,CAAC,cAAc;AACjB,YAAM,IAAI,uBAAuB;AAAA,IACnC;AAEA,WAAO,4BAA4B;AAAA,MACjC;AAAA,MACA,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,oBAAoB,UAAyB;AACnD,QAAI,SAAS,WAAW,OAAO,CAAC,SAAS,MAAM;AAC7C,YAAM;AAAA,QACJ,oCAAoC,SAAS,MAAM,IAAI,SAAS,UAAU;AAAA,MAC5E;AAAA,IACF;AAAA,EACF;AAAA,EAEQ,kBACN,UAGA;AACA,QAAI,SAAS,KAAK,WAAW,WAAW;AACtC,YAAM,IAAI,yBAAyB,SAAS,IAAI;AAAA,IAClD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/EngineClient.ts
|
|
21
|
+
var EngineClient_exports = {};
|
|
22
|
+
__export(EngineClient_exports, {
|
|
23
|
+
EngineClient: () => EngineClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(EngineClient_exports);
|
|
26
|
+
var import_ts_mixer = require("ts-mixer");
|
|
27
|
+
var import_EngineExecuteClient = require("./EngineExecuteClient.cjs");
|
|
28
|
+
var import_EngineQueryClient = require("./EngineQueryClient.cjs");
|
|
29
|
+
var import_EngineWebClient = require("./EngineWebClient.cjs");
|
|
30
|
+
var EngineClient = class extends (0, import_ts_mixer.Mixin)(
|
|
31
|
+
import_EngineQueryClient.EngineQueryClient,
|
|
32
|
+
import_EngineExecuteClient.EngineExecuteClient,
|
|
33
|
+
import_EngineWebClient.EngineWebClient
|
|
34
|
+
) {
|
|
35
|
+
};
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
EngineClient
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=EngineClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/EngineClient.ts"],"sourcesContent":["import { Mixin } from 'ts-mixer';\nimport { EngineExecuteClient } from './EngineExecuteClient';\nimport { EngineQueryClient } from './EngineQueryClient';\nimport { EngineWebClient } from './EngineWebClient';\n\n/**\n * Combined Engine client providing query, execution, and WebSocket functionality for off-chain matching engine communication\n */\nexport class EngineClient extends Mixin(\n EngineQueryClient,\n EngineExecuteClient,\n EngineWebClient,\n) {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsB;AACtB,iCAAoC;AACpC,+BAAkC;AAClC,6BAAgC;AAKzB,IAAM,eAAN,kBAA2B;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,EAAE;AAAC;","names":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as ts_mixer_dist_types_types from 'ts-mixer/dist/types/types';
|
|
2
|
+
import { EngineExecuteClient } from './EngineExecuteClient.cjs';
|
|
3
|
+
import { EngineQueryClient } from './EngineQueryClient.cjs';
|
|
4
|
+
import { EngineWebClient } from './EngineWebClient.cjs';
|
|
5
|
+
import './types/clientExecuteTypes.cjs';
|
|
6
|
+
import '@nadohq/contracts';
|
|
7
|
+
import './types/serverExecuteTypes.cjs';
|
|
8
|
+
import './types/serverQueryTypes.cjs';
|
|
9
|
+
import './types/serverQueryModelTypes.cjs';
|
|
10
|
+
import './EngineBaseClient.cjs';
|
|
11
|
+
import 'axios';
|
|
12
|
+
import './types/clientQueryTypes.cjs';
|
|
13
|
+
import '@nadohq/utils';
|
|
14
|
+
import './EngineExecuteBuilder.cjs';
|
|
15
|
+
|
|
16
|
+
declare const EngineClient_base: ts_mixer_dist_types_types.Class<any[], EngineQueryClient & EngineExecuteClient & EngineWebClient, typeof EngineQueryClient & typeof EngineExecuteClient & typeof EngineWebClient>;
|
|
17
|
+
/**
|
|
18
|
+
* Combined Engine client providing query, execution, and WebSocket functionality for off-chain matching engine communication
|
|
19
|
+
*/
|
|
20
|
+
declare class EngineClient extends EngineClient_base {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { EngineClient };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as ts_mixer_dist_types_types from 'ts-mixer/dist/types/types';
|
|
2
|
+
import { EngineExecuteClient } from './EngineExecuteClient.js';
|
|
3
|
+
import { EngineQueryClient } from './EngineQueryClient.js';
|
|
4
|
+
import { EngineWebClient } from './EngineWebClient.js';
|
|
5
|
+
import './types/clientExecuteTypes.js';
|
|
6
|
+
import '@nadohq/contracts';
|
|
7
|
+
import './types/serverExecuteTypes.js';
|
|
8
|
+
import './types/serverQueryTypes.js';
|
|
9
|
+
import './types/serverQueryModelTypes.js';
|
|
10
|
+
import './EngineBaseClient.js';
|
|
11
|
+
import 'axios';
|
|
12
|
+
import './types/clientQueryTypes.js';
|
|
13
|
+
import '@nadohq/utils';
|
|
14
|
+
import './EngineExecuteBuilder.js';
|
|
15
|
+
|
|
16
|
+
declare const EngineClient_base: ts_mixer_dist_types_types.Class<any[], EngineQueryClient & EngineExecuteClient & EngineWebClient, typeof EngineQueryClient & typeof EngineExecuteClient & typeof EngineWebClient>;
|
|
17
|
+
/**
|
|
18
|
+
* Combined Engine client providing query, execution, and WebSocket functionality for off-chain matching engine communication
|
|
19
|
+
*/
|
|
20
|
+
declare class EngineClient extends EngineClient_base {
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { EngineClient };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/EngineClient.ts
|
|
2
|
+
import { Mixin } from "ts-mixer";
|
|
3
|
+
import { EngineExecuteClient } from "./EngineExecuteClient.js";
|
|
4
|
+
import { EngineQueryClient } from "./EngineQueryClient.js";
|
|
5
|
+
import { EngineWebClient } from "./EngineWebClient.js";
|
|
6
|
+
var EngineClient = class extends Mixin(
|
|
7
|
+
EngineQueryClient,
|
|
8
|
+
EngineExecuteClient,
|
|
9
|
+
EngineWebClient
|
|
10
|
+
) {
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
EngineClient
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=EngineClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/EngineClient.ts"],"sourcesContent":["import { Mixin } from 'ts-mixer';\nimport { EngineExecuteClient } from './EngineExecuteClient';\nimport { EngineQueryClient } from './EngineQueryClient';\nimport { EngineWebClient } from './EngineWebClient';\n\n/**\n * Combined Engine client providing query, execution, and WebSocket functionality for off-chain matching engine communication\n */\nexport class EngineClient extends Mixin(\n EngineQueryClient,\n EngineExecuteClient,\n EngineWebClient,\n) {}\n"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,2BAA2B;AACpC,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAKzB,IAAM,eAAN,cAA2B;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AACF,EAAE;AAAC;","names":[]}
|