genius-intents 0.28.0 → 0.29.1-develop.0

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/genius-intents.d.ts.map +1 -1
  3. package/dist/genius-intents.js +3 -0
  4. package/dist/genius-intents.js.map +1 -1
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/dex/evm-direct-pool/evm-direct-pool.service.d.ts.map +1 -1
  10. package/dist/lib/dex/evm-direct-pool/evm-direct-pool.service.js +23 -2
  11. package/dist/lib/dex/evm-direct-pool/evm-direct-pool.service.js.map +1 -1
  12. package/dist/lib/dex/evm-direct-pool/evm-direct-pool.types.d.ts +3 -0
  13. package/dist/lib/dex/evm-direct-pool/evm-direct-pool.types.d.ts.map +1 -1
  14. package/dist/protocols/liquid-mesh/index.d.ts +4 -0
  15. package/dist/protocols/liquid-mesh/index.d.ts.map +1 -0
  16. package/dist/protocols/liquid-mesh/index.js +9 -0
  17. package/dist/protocols/liquid-mesh/index.js.map +1 -0
  18. package/dist/protocols/liquid-mesh/liquid-mesh.service.d.ts +232 -0
  19. package/dist/protocols/liquid-mesh/liquid-mesh.service.d.ts.map +1 -0
  20. package/dist/protocols/liquid-mesh/liquid-mesh.service.js +706 -0
  21. package/dist/protocols/liquid-mesh/liquid-mesh.service.js.map +1 -0
  22. package/dist/protocols/liquid-mesh/liquid-mesh.types.d.ts +289 -0
  23. package/dist/protocols/liquid-mesh/liquid-mesh.types.d.ts.map +1 -0
  24. package/dist/protocols/liquid-mesh/liquid-mesh.types.js +21 -0
  25. package/dist/protocols/liquid-mesh/liquid-mesh.types.js.map +1 -0
  26. package/dist/types/enums.d.ts +2 -1
  27. package/dist/types/enums.d.ts.map +1 -1
  28. package/dist/types/enums.js +1 -0
  29. package/dist/types/enums.js.map +1 -1
  30. package/dist/types/price-params.d.ts +2 -0
  31. package/dist/types/price-params.d.ts.map +1 -1
  32. package/dist/types/price-response.d.ts +2 -1
  33. package/dist/types/price-response.d.ts.map +1 -1
  34. package/dist/types/quote-response.d.ts +2 -1
  35. package/dist/types/quote-response.d.ts.map +1 -1
  36. package/package.json +7 -1
@@ -0,0 +1,232 @@
1
+ import { LiquidMeshConfig, LiquidMeshPriceRequestParams, LiquidMeshPriceResponse } from './liquid-mesh.types';
2
+ import { IIntentProtocol } from '../../interfaces/intent-protocol';
3
+ import { ChainIdEnum, ProtocolEnum } from '../../types/enums';
4
+ import { PriceResponse, RawProtocolPriceResponse } from '../../types/price-response';
5
+ import { QuoteResponse } from '../../types/quote-response';
6
+ import { GeniusIntentsSDKConfig } from '../../types/sdk-config';
7
+ import { IntentPriceParams } from '../../types/price-params';
8
+ import { IntentQuoteParams } from '../../types/quote-params';
9
+ /**
10
+ * The `LiquidMeshService` class implements the IIntentProtocol interface for token swaps
11
+ * using the Liquid Mesh aggregator. It provides functionality for fetching price quotes
12
+ * and generating transaction data for token swaps on various EVM-compatible blockchains.
13
+ *
14
+ * @implements {IIntentProtocol}
15
+ */
16
+ export declare class LiquidMeshService implements IIntentProtocol {
17
+ /**
18
+ * The protocol identifier for Liquid Mesh.
19
+ */
20
+ readonly protocol = ProtocolEnum.LIQUID_MESH;
21
+ /**
22
+ * The list of blockchain networks supported by the Liquid Mesh service.
23
+ */
24
+ readonly chains: ChainIdEnum[];
25
+ readonly networkIds: {
26
+ 56: string;
27
+ 8453: string;
28
+ 1399811149: string;
29
+ };
30
+ /**
31
+ * Indicates that the service operates only on a single blockchain.
32
+ */
33
+ readonly singleChain = true;
34
+ /**
35
+ * Indicates that the service does not support cross-chain operations.
36
+ */
37
+ readonly multiChain = false;
38
+ /**
39
+ * The endpoint for quote requests.
40
+ */
41
+ readonly quoteEndpoint = "/v1/quote";
42
+ /**
43
+ * The Liquid Mesh API key used for authentication.
44
+ */
45
+ private readonly _apiKey?;
46
+ /**
47
+ * The Ed25519 private key for signing JWTs.
48
+ */
49
+ private _privateKey?;
50
+ /**
51
+ * Promise that resolves when the private key is initialized.
52
+ */
53
+ private _privateKeyPromise?;
54
+ /**
55
+ * The Liquid Mesh proxy URL, if configured. Will only send
56
+ * requests through the proxy if this is set.
57
+ */
58
+ private _proxyUrl?;
59
+ /**
60
+ * The API key for the proxy service.
61
+ */
62
+ private _proxyApiKey?;
63
+ /**
64
+ * Cache for approve addresses per network to avoid repeated API calls.
65
+ */
66
+ private readonly _approvalContract;
67
+ constructor(config: GeniusIntentsSDKConfig & LiquidMeshConfig);
68
+ /**
69
+ * Converts a standard Base64 string to Base64URL encoding.
70
+ * Base64URL replaces '+' with '-', '/' with '_', and removes '=' padding.
71
+ *
72
+ * @param base64 - The standard Base64 encoded string.
73
+ * @returns The Base64URL encoded string.
74
+ */
75
+ private _toBase64Url;
76
+ /**
77
+ * Initializes the Ed25519 private key from base64-encoded seed and public key.
78
+ * Automatically converts standard Base64 to Base64URL if needed.
79
+ *
80
+ * @param privateKeySeed - The Ed25519 private key seed (Base64 or Base64URL).
81
+ * @param publicKey - The Ed25519 public key (Base64 or Base64URL).
82
+ */
83
+ private _initializePrivateKey;
84
+ /**
85
+ * Generates a signed JWT for Liquid Mesh API authentication.
86
+ *
87
+ * @param method - The HTTP method (GET, POST, etc.).
88
+ * @param path - The canonical request path (e.g., /v1/bsc/quote?amount=100).
89
+ * @param body - The request body (empty string for GET requests).
90
+ * @returns A promise that resolves to the signed JWT token.
91
+ */
92
+ private _generateAuthToken;
93
+ /**
94
+ * Generates the authentication headers for Liquid Mesh API requests.
95
+ *
96
+ * @param method - The HTTP method.
97
+ * @param path - The canonical request path.
98
+ * @param body - The request body.
99
+ * @returns A promise that resolves to the headers object.
100
+ */
101
+ private _getAuthHeaders;
102
+ /**
103
+ * Checks if the service is configured to use a proxy.
104
+ *
105
+ * @returns True if using proxy, false for direct API access.
106
+ */
107
+ private _isUsingProxy;
108
+ /**
109
+ * Builds the request URL, routing through proxy if configured.
110
+ * When proxy is enabled, the original target URL is passed as a query parameter.
111
+ *
112
+ * @param targetUrl - The original Liquid Mesh API URL.
113
+ * @returns The URL to use for the request (proxy URL or original URL).
114
+ */
115
+ private _buildRequestUrl;
116
+ /**
117
+ * Gets the appropriate headers for the request.
118
+ * When using proxy, no auth headers are needed (proxy handles authentication).
119
+ * For direct API access, generates JWT auth headers.
120
+ *
121
+ * @param method - The HTTP method.
122
+ * @param path - The canonical request path.
123
+ * @param body - The request body.
124
+ * @returns A promise that resolves to the headers object.
125
+ */
126
+ private _getRequestHeaders;
127
+ /**
128
+ * Checks if the provided configuration object is valid.
129
+ *
130
+ * @typeParam T - The expected shape of the configuration object.
131
+ * @param config - The configuration object to validate.
132
+ * @returns `true` if the configuration is valid, otherwise `false`.
133
+ */
134
+ isCorrectConfig<T extends {
135
+ [key: string]: string;
136
+ }>(config: {
137
+ [key: string]: string;
138
+ }): config is T;
139
+ /**
140
+ * Checks if the given network is Solana.
141
+ *
142
+ * @param networkId - The chain ID to check.
143
+ * @returns True if the network is Solana.
144
+ */
145
+ private _isSolanaNetwork;
146
+ /**
147
+ * Gets the native token address for the given network.
148
+ *
149
+ * @param networkId - The chain ID.
150
+ * @returns The native token address for the network.
151
+ */
152
+ private _getNativeAddress;
153
+ private _wrapSolanaMessageAsTransaction;
154
+ private _wrapRawMessage;
155
+ /**
156
+ * Fetches a price quote for a token swap from the Liquid Mesh API.
157
+ *
158
+ * @param {IntentPriceParams} params - The parameters required for the price quote.
159
+ *
160
+ * @returns {Promise<Omit<PriceResponse, 'protocolResponse'> & { protocolResponse: LiquidMeshPriceResponse }>}
161
+ * A promise that resolves to a `PriceResponse` object containing:
162
+ * - The amount of output tokens expected from the swap.
163
+ * - Gas estimation for the transaction.
164
+ * - The raw response from the Liquid Mesh API.
165
+ *
166
+ * @throws {SdkError} If the parameters are invalid or unsupported.
167
+ * @throws {SdkError} If the API returns an invalid response.
168
+ * @throws {SdkError} If there's an error fetching the price.
169
+ */
170
+ fetchPrice(params: IntentPriceParams): Promise<Omit<PriceResponse, 'protocolResponse'> & {
171
+ protocolResponse: LiquidMeshPriceResponse;
172
+ }>;
173
+ /**
174
+ * Fetches a swap quote from the Liquid Mesh API and builds the transaction data
175
+ * needed to execute the swap.
176
+ *
177
+ * Note: Liquid Mesh uses a single endpoint for both price and quote. The quote
178
+ * endpoint returns route information that can be used to construct the swap transaction.
179
+ *
180
+ * @param {IntentQuoteParams} params - The parameters required for the swap quote.
181
+ *
182
+ * @returns {Promise<QuoteResponse & { protocolResponse: LiquidMeshPriceResponse }>}
183
+ * A promise that resolves to a `QuoteResponse` object containing:
184
+ * - The expected amount of output tokens.
185
+ * - The transaction data needed to execute the swap.
186
+ * - Gas estimates for the transaction.
187
+ *
188
+ * @throws {SdkError} If the parameters are invalid or unsupported.
189
+ * @throws {SdkError} If the API returns an invalid response.
190
+ * @throws {SdkError} If there's an error fetching the quote.
191
+ */
192
+ fetchQuote(params: IntentQuoteParams): Promise<QuoteResponse & {
193
+ protocolResponse: LiquidMeshPriceResponse;
194
+ }>;
195
+ /**
196
+ * Fetches a swap quote for EVM chains and builds the transaction data.
197
+ *
198
+ * @private
199
+ */
200
+ private _fetchEvmQuote;
201
+ /**
202
+ * Fetches a swap quote for Solana and builds the transaction data.
203
+ *
204
+ * @private
205
+ */
206
+ private _fetchSolanaQuote;
207
+ /**
208
+ * Transforms the price parameters to the format expected by the Liquid Mesh API.
209
+ *
210
+ * @param {IntentPriceParams} params - The original price parameters.
211
+ *
212
+ * @returns {LiquidMeshPriceRequestParams} The transformed parameters ready for the Liquid Mesh API.
213
+ */
214
+ protected priceParamsToRequestParams(params: IntentPriceParams): LiquidMeshPriceRequestParams;
215
+ /**
216
+ * Validates the parameters for a price quote request.
217
+ *
218
+ * @param {IntentPriceParams} params - The parameters to validate.
219
+ *
220
+ * @throws {SdkError} If any of the parameters are invalid or unsupported.
221
+ */
222
+ protected validatePriceParams(params: IntentPriceParams): void;
223
+ /**
224
+ * Type guard to check if a response is a valid Liquid Mesh price response.
225
+ *
226
+ * @param {RawProtocolPriceResponse} response - The response to check.
227
+ *
228
+ * @returns {boolean} True if the response is a valid Liquid Mesh price response.
229
+ */
230
+ protected isLiquidMeshPriceResponse(response: RawProtocolPriceResponse): response is LiquidMeshPriceResponse;
231
+ }
232
+ //# sourceMappingURL=liquid-mesh.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"liquid-mesh.service.d.ts","sourceRoot":"","sources":["../../../src/protocols/liquid-mesh/liquid-mesh.service.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,uBAAuB,EAMxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAO3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAQ7D;;;;;;GAMG;AACH,qBAAa,iBAAkB,YAAW,eAAe;IACvD;;OAEG;IACH,SAAgB,QAAQ,4BAA4B;IAEpD;;OAEG;IACH,SAAgB,MAAM,gBAA2D;IAEjF,SAAgB,UAAU;;;;MAIxB;IAEF;;OAEG;IACH,SAAgB,WAAW,QAAQ;IAEnC;;OAEG;IACH,SAAgB,UAAU,SAAS;IAEnC;;OAEG;IACH,SAAgB,aAAa,eAAe;IAE5C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAS;IAElC;;OAEG;IAEH,OAAO,CAAC,WAAW,CAAC,CAAM;I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