amogus-sdk-internal-utils 0.35.2

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 (261) hide show
  1. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  2. package/dist/_virtual/rolldown_runtime.js +18 -0
  3. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.cjs +10 -0
  4. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.d.cts +6 -0
  5. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.d.ts +6 -0
  6. package/dist/bridgeIndexer/bridgeIndexerHttpClient/apis.js +10 -0
  7. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.cjs +17 -0
  8. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.d.cts +9 -0
  9. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.d.ts +9 -0
  10. package/dist/bridgeIndexer/bridgeIndexerHttpClient/index.js +12 -0
  11. package/dist/bridgeIndexer/bridgeIndexerHttpClient/runtime.cjs +20 -0
  12. package/dist/bridgeIndexer/bridgeIndexerHttpClient/runtime.js +20 -0
  13. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.cjs +25 -0
  14. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.d.cts +31 -0
  15. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.d.ts +31 -0
  16. package/dist/bridgeIndexer/bridgeIndexerHttpClient/types.js +23 -0
  17. package/dist/bridgeIndexer/index.cjs +13 -0
  18. package/dist/bridgeIndexer/index.d.cts +8 -0
  19. package/dist/bridgeIndexer/index.d.ts +8 -0
  20. package/dist/bridgeIndexer/index.js +8 -0
  21. package/dist/config.cjs +86 -0
  22. package/dist/config.d.cts +50 -0
  23. package/dist/config.d.ts +50 -0
  24. package/dist/config.js +76 -0
  25. package/dist/errors/assert.cjs +11 -0
  26. package/dist/errors/assert.d.cts +11 -0
  27. package/dist/errors/assert.d.ts +11 -0
  28. package/dist/errors/assert.js +11 -0
  29. package/dist/errors/base.cjs +34 -0
  30. package/dist/errors/base.d.cts +21 -0
  31. package/dist/errors/base.d.ts +21 -0
  32. package/dist/errors/base.js +33 -0
  33. package/dist/errors/index.cjs +23 -0
  34. package/dist/errors/index.d.cts +11 -0
  35. package/dist/errors/index.d.ts +11 -0
  36. package/dist/errors/index.js +18 -0
  37. package/dist/errors/request.cjs +48 -0
  38. package/dist/errors/request.d.cts +61 -0
  39. package/dist/errors/request.d.ts +61 -0
  40. package/dist/errors/request.js +46 -0
  41. package/dist/errors/utils/isNetworkError.cjs +23 -0
  42. package/dist/errors/utils/isNetworkError.js +22 -0
  43. package/dist/errors/utils/toError.cjs +8 -0
  44. package/dist/errors/utils/toError.d.cts +4 -0
  45. package/dist/errors/utils/toError.d.ts +4 -0
  46. package/dist/errors/utils/toError.js +7 -0
  47. package/dist/index.cjs +144 -0
  48. package/dist/index.d.cts +33 -0
  49. package/dist/index.d.ts +33 -0
  50. package/dist/index.js +33 -0
  51. package/dist/logger.d.cts +11 -0
  52. package/dist/logger.d.ts +11 -0
  53. package/dist/nearClient.cjs +18 -0
  54. package/dist/nearClient.d.cts +8 -0
  55. package/dist/nearClient.d.ts +8 -0
  56. package/dist/nearClient.js +18 -0
  57. package/dist/poaBridge/constants/blockchains.cjs +62 -0
  58. package/dist/poaBridge/constants/blockchains.d.cts +95 -0
  59. package/dist/poaBridge/constants/blockchains.d.ts +95 -0
  60. package/dist/poaBridge/constants/blockchains.js +59 -0
  61. package/dist/poaBridge/errors/withdrawal.cjs +52 -0
  62. package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
  63. package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
  64. package/dist/poaBridge/errors/withdrawal.js +50 -0
  65. package/dist/poaBridge/getPendingDeposits.cjs +31 -0
  66. package/dist/poaBridge/getPendingDeposits.d.cts +14 -0
  67. package/dist/poaBridge/getPendingDeposits.d.ts +15 -0
  68. package/dist/poaBridge/getPendingDeposits.js +31 -0
  69. package/dist/poaBridge/index.cjs +23 -0
  70. package/dist/poaBridge/index.d.cts +11 -0
  71. package/dist/poaBridge/index.d.ts +11 -0
  72. package/dist/poaBridge/index.js +18 -0
  73. package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
  74. package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
  75. package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
  76. package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
  77. package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
  78. package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
  79. package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
  80. package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
  81. package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
  82. package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
  83. package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +172 -0
  84. package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +172 -0
  85. package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
  86. package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
  87. package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
  88. package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
  89. package/dist/services/blockchainBalanceService.cjs +40 -0
  90. package/dist/services/blockchainBalanceService.d.cts +21 -0
  91. package/dist/services/blockchainBalanceService.d.ts +21 -0
  92. package/dist/services/blockchainBalanceService.js +37 -0
  93. package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
  94. package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
  95. package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
  96. package/dist/solverRelay/errors/intentSettlement.js +20 -0
  97. package/dist/solverRelay/errors/quote.cjs +18 -0
  98. package/dist/solverRelay/errors/quote.d.cts +21 -0
  99. package/dist/solverRelay/errors/quote.d.ts +22 -0
  100. package/dist/solverRelay/errors/quote.js +18 -0
  101. package/dist/solverRelay/getQuote.cjs +70 -0
  102. package/dist/solverRelay/getQuote.d.cts +14 -0
  103. package/dist/solverRelay/getQuote.d.ts +14 -0
  104. package/dist/solverRelay/getQuote.js +70 -0
  105. package/dist/solverRelay/getStatus.cjs +26 -0
  106. package/dist/solverRelay/getStatus.d.cts +17 -0
  107. package/dist/solverRelay/getStatus.d.ts +18 -0
  108. package/dist/solverRelay/getStatus.js +26 -0
  109. package/dist/solverRelay/index.cjs +27 -0
  110. package/dist/solverRelay/index.d.cts +16 -0
  111. package/dist/solverRelay/index.d.ts +16 -0
  112. package/dist/solverRelay/index.js +22 -0
  113. package/dist/solverRelay/publishIntent.cjs +20 -0
  114. package/dist/solverRelay/publishIntent.d.cts +15 -0
  115. package/dist/solverRelay/publishIntent.d.ts +16 -0
  116. package/dist/solverRelay/publishIntent.js +20 -0
  117. package/dist/solverRelay/publishIntents.cjs +42 -0
  118. package/dist/solverRelay/publishIntents.d.cts +10 -0
  119. package/dist/solverRelay/publishIntents.d.ts +11 -0
  120. package/dist/solverRelay/publishIntents.js +41 -0
  121. package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
  122. package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
  123. package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
  124. package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
  125. package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
  126. package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
  127. package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
  128. package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
  129. package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
  130. package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
  131. package/dist/solverRelay/solverRelayHttpClient/types.d.cts +117 -0
  132. package/dist/solverRelay/solverRelayHttpClient/types.d.ts +117 -0
  133. package/dist/solverRelay/utils/parseFailedPublishError.cjs +64 -0
  134. package/dist/solverRelay/utils/parseFailedPublishError.d.cts +56 -0
  135. package/dist/solverRelay/utils/parseFailedPublishError.d.ts +57 -0
  136. package/dist/solverRelay/utils/parseFailedPublishError.js +61 -0
  137. package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
  138. package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
  139. package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
  140. package/dist/solverRelay/utils/quoteWithLog.js +21 -0
  141. package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
  142. package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
  143. package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
  144. package/dist/solverRelay/waitForIntentSettlement.js +52 -0
  145. package/dist/types/authHandle.cjs +22 -0
  146. package/dist/types/authHandle.d.cts +25 -0
  147. package/dist/types/authHandle.d.ts +25 -0
  148. package/dist/types/authHandle.js +16 -0
  149. package/dist/types/base.d.cts +45 -0
  150. package/dist/types/base.d.ts +45 -0
  151. package/dist/types/intentsUserId.d.cts +10 -0
  152. package/dist/types/intentsUserId.d.ts +10 -0
  153. package/dist/types/walletMessage.cjs +11 -0
  154. package/dist/types/walletMessage.d.cts +106 -0
  155. package/dist/types/walletMessage.d.ts +106 -0
  156. package/dist/types/walletMessage.js +5 -0
  157. package/dist/utils/abortSignal.cjs +19 -0
  158. package/dist/utils/abortSignal.js +18 -0
  159. package/dist/utils/appFee.cjs +20 -0
  160. package/dist/utils/appFee.d.cts +9 -0
  161. package/dist/utils/appFee.d.ts +9 -0
  162. package/dist/utils/appFee.js +15 -0
  163. package/dist/utils/assert.cjs +9 -0
  164. package/dist/utils/assert.d.cts +7 -0
  165. package/dist/utils/assert.d.ts +7 -0
  166. package/dist/utils/assert.js +9 -0
  167. package/dist/utils/authIdentity.cjs +56 -0
  168. package/dist/utils/authIdentity.d.cts +34 -0
  169. package/dist/utils/authIdentity.d.ts +34 -0
  170. package/dist/utils/authIdentity.js +50 -0
  171. package/dist/utils/failover.cjs +36 -0
  172. package/dist/utils/failover.d.cts +24 -0
  173. package/dist/utils/failover.d.ts +24 -0
  174. package/dist/utils/failover.js +34 -0
  175. package/dist/utils/handleRPCResponse.cjs +30 -0
  176. package/dist/utils/handleRPCResponse.js +28 -0
  177. package/dist/utils/handleResponse.cjs +31 -0
  178. package/dist/utils/handleResponse.js +29 -0
  179. package/dist/utils/index.cjs +55 -0
  180. package/dist/utils/index.d.cts +13 -0
  181. package/dist/utils/index.d.ts +13 -0
  182. package/dist/utils/index.js +50 -0
  183. package/dist/utils/messageFactory.cjs +137 -0
  184. package/dist/utils/messageFactory.d.cts +70 -0
  185. package/dist/utils/messageFactory.d.ts +70 -0
  186. package/dist/utils/messageFactory.js +132 -0
  187. package/dist/utils/multiPayload/webauthn.cjs +27 -0
  188. package/dist/utils/multiPayload/webauthn.js +26 -0
  189. package/dist/utils/near.cjs +58 -0
  190. package/dist/utils/near.d.cts +35 -0
  191. package/dist/utils/near.d.ts +35 -0
  192. package/dist/utils/near.js +53 -0
  193. package/dist/utils/poll.cjs +87 -0
  194. package/dist/utils/poll.d.cts +54 -0
  195. package/dist/utils/poll.d.ts +54 -0
  196. package/dist/utils/poll.js +85 -0
  197. package/dist/utils/prepareBroadcastRequest.cjs +98 -0
  198. package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
  199. package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
  200. package/dist/utils/prepareBroadcastRequest.js +90 -0
  201. package/dist/utils/promise/withTimeout.cjs +34 -0
  202. package/dist/utils/promise/withTimeout.d.cts +16 -0
  203. package/dist/utils/promise/withTimeout.d.ts +16 -0
  204. package/dist/utils/promise/withTimeout.js +34 -0
  205. package/dist/utils/request.cjs +100 -0
  206. package/dist/utils/request.d.cts +27 -0
  207. package/dist/utils/request.d.ts +27 -0
  208. package/dist/utils/request.js +99 -0
  209. package/dist/utils/requestShouldRetry.cjs +20 -0
  210. package/dist/utils/requestShouldRetry.js +20 -0
  211. package/dist/utils/retry.cjs +66 -0
  212. package/dist/utils/retry.d.cts +56 -0
  213. package/dist/utils/retry.d.ts +56 -0
  214. package/dist/utils/retry.js +64 -0
  215. package/dist/utils/rpc-endpoint.cjs +56 -0
  216. package/dist/utils/rpc-endpoint.d.cts +20 -0
  217. package/dist/utils/rpc-endpoint.d.ts +20 -0
  218. package/dist/utils/rpc-endpoint.js +54 -0
  219. package/dist/utils/serialize.cjs +82 -0
  220. package/dist/utils/serialize.d.cts +17 -0
  221. package/dist/utils/serialize.d.ts +17 -0
  222. package/dist/utils/serialize.js +81 -0
  223. package/dist/utils/stellarAddressToBytes.cjs +295 -0
  224. package/dist/utils/stellarAddressToBytes.js +294 -0
  225. package/dist/utils/token.cjs +8 -0
  226. package/dist/utils/token.js +7 -0
  227. package/dist/utils/tokenUtils.cjs +263 -0
  228. package/dist/utils/tokenUtils.d.cts +88 -0
  229. package/dist/utils/tokenUtils.d.ts +88 -0
  230. package/dist/utils/tokenUtils.js +238 -0
  231. package/dist/utils/tronAddressToHex.cjs +18 -0
  232. package/dist/utils/tronAddressToHex.js +17 -0
  233. package/dist/utils/uint8Array.cjs +15 -0
  234. package/dist/utils/uint8Array.d.cts +4 -0
  235. package/dist/utils/uint8Array.d.ts +4 -0
  236. package/dist/utils/uint8Array.js +14 -0
  237. package/dist/utils/webAuthn.cjs +58 -0
  238. package/dist/utils/webAuthn.js +56 -0
  239. package/dist/xrpl/index.cjs +13 -0
  240. package/dist/xrpl/index.d.cts +8 -0
  241. package/dist/xrpl/index.d.ts +8 -0
  242. package/dist/xrpl/index.js +8 -0
  243. package/dist/xrpl/xrplHttpClient/apis.cjs +28 -0
  244. package/dist/xrpl/xrplHttpClient/apis.d.cts +7 -0
  245. package/dist/xrpl/xrplHttpClient/apis.d.ts +7 -0
  246. package/dist/xrpl/xrplHttpClient/apis.js +27 -0
  247. package/dist/xrpl/xrplHttpClient/errors.cjs +27 -0
  248. package/dist/xrpl/xrplHttpClient/errors.d.cts +24 -0
  249. package/dist/xrpl/xrplHttpClient/errors.d.ts +24 -0
  250. package/dist/xrpl/xrplHttpClient/errors.js +26 -0
  251. package/dist/xrpl/xrplHttpClient/index.cjs +19 -0
  252. package/dist/xrpl/xrplHttpClient/index.d.cts +10 -0
  253. package/dist/xrpl/xrplHttpClient/index.d.ts +10 -0
  254. package/dist/xrpl/xrplHttpClient/index.js +14 -0
  255. package/dist/xrpl/xrplHttpClient/runtime.cjs +57 -0
  256. package/dist/xrpl/xrplHttpClient/runtime.js +55 -0
  257. package/dist/xrpl/xrplHttpClient/types.cjs +39 -0
  258. package/dist/xrpl/xrplHttpClient/types.d.cts +64 -0
  259. package/dist/xrpl/xrplHttpClient/types.d.ts +64 -0
  260. package/dist/xrpl/xrplHttpClient/types.js +35 -0
  261. package/package.json +59 -0
@@ -0,0 +1,13 @@
1
+ import { __exportAll } from "../../_virtual/rolldown_runtime.js";
2
+ import { getStatus, publishIntent, publishIntents, quote } from "./apis.js";
3
+
4
+ //#region src/solverRelay/solverRelayHttpClient/index.ts
5
+ var solverRelayHttpClient_exports = /* @__PURE__ */ __exportAll({
6
+ getStatus: () => getStatus,
7
+ publishIntent: () => publishIntent,
8
+ publishIntents: () => publishIntents,
9
+ quote: () => quote
10
+ });
11
+
12
+ //#endregion
13
+ export { solverRelayHttpClient_exports };
@@ -0,0 +1,60 @@
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
+ const require_config = require('../../config.cjs');
3
+ const require_request = require('../../utils/request.cjs');
4
+ const require_handleRPCResponse = require('../../utils/handleRPCResponse.cjs');
5
+ const require_retry = require('../../utils/retry.cjs');
6
+ let valibot = require("valibot");
7
+ valibot = require_rolldown_runtime.__toESM(valibot);
8
+
9
+ //#region src/solverRelay/solverRelayHttpClient/runtime.ts
10
+ const rpcResponseSchema = valibot.union([valibot.object({
11
+ jsonrpc: valibot.literal("2.0"),
12
+ id: valibot.string(),
13
+ result: valibot.unknown()
14
+ }), valibot.object({
15
+ jsonrpc: valibot.literal("2.0"),
16
+ id: valibot.string(),
17
+ error: valibot.pipe(valibot.union([valibot.string(), valibot.object({
18
+ code: valibot.number(),
19
+ message: valibot.string()
20
+ })]), valibot.transform((v) => {
21
+ if (typeof v === "string") return {
22
+ code: -1,
23
+ data: null,
24
+ message: v
25
+ };
26
+ return {
27
+ code: v.code,
28
+ data: null,
29
+ message: v.message
30
+ };
31
+ }))
32
+ })]);
33
+ async function jsonRPCRequest(method, params, config$1) {
34
+ const baseURL = config$1?.baseURL ?? require_config.config.env.solverRelayBaseURL;
35
+ const url = new URL("rpc", baseURL);
36
+ url.searchParams.set("method", String(method));
37
+ const body = {
38
+ id: config$1?.requestId ?? "dontcare",
39
+ jsonrpc: "2.0",
40
+ method,
41
+ params: params !== void 0 ? [params] : void 0
42
+ };
43
+ const fetchOptions = {
44
+ ...config$1?.fetchOptions,
45
+ method: "POST",
46
+ headers: new Headers(config$1?.fetchOptions?.headers)
47
+ };
48
+ if (config$1?.solverRelayApiKey) fetchOptions.headers.append("Authorization", `Bearer ${config$1.solverRelayApiKey}`);
49
+ return require_handleRPCResponse.handleRPCResponse(await require_request.request({
50
+ url,
51
+ body,
52
+ ...config$1,
53
+ fetchOptions,
54
+ retryOptions: config$1?.retryOptions ?? require_retry.RETRY_CONFIGS.THIRTY_SECS_AGGRESSIVE,
55
+ logger: config$1?.logger
56
+ }), body, rpcResponseSchema);
57
+ }
58
+
59
+ //#endregion
60
+ exports.jsonRPCRequest = jsonRPCRequest;
@@ -0,0 +1,58 @@
1
+ import { config } from "../../config.js";
2
+ import { request } from "../../utils/request.js";
3
+ import { handleRPCResponse } from "../../utils/handleRPCResponse.js";
4
+ import { RETRY_CONFIGS } from "../../utils/retry.js";
5
+ import * as v from "valibot";
6
+
7
+ //#region src/solverRelay/solverRelayHttpClient/runtime.ts
8
+ const rpcResponseSchema = v.union([v.object({
9
+ jsonrpc: v.literal("2.0"),
10
+ id: v.string(),
11
+ result: v.unknown()
12
+ }), v.object({
13
+ jsonrpc: v.literal("2.0"),
14
+ id: v.string(),
15
+ error: v.pipe(v.union([v.string(), v.object({
16
+ code: v.number(),
17
+ message: v.string()
18
+ })]), v.transform((v$1) => {
19
+ if (typeof v$1 === "string") return {
20
+ code: -1,
21
+ data: null,
22
+ message: v$1
23
+ };
24
+ return {
25
+ code: v$1.code,
26
+ data: null,
27
+ message: v$1.message
28
+ };
29
+ }))
30
+ })]);
31
+ async function jsonRPCRequest(method, params, config$1) {
32
+ const baseURL = config$1?.baseURL ?? config.env.solverRelayBaseURL;
33
+ const url = new URL("rpc", baseURL);
34
+ url.searchParams.set("method", String(method));
35
+ const body = {
36
+ id: config$1?.requestId ?? "dontcare",
37
+ jsonrpc: "2.0",
38
+ method,
39
+ params: params !== void 0 ? [params] : void 0
40
+ };
41
+ const fetchOptions = {
42
+ ...config$1?.fetchOptions,
43
+ method: "POST",
44
+ headers: new Headers(config$1?.fetchOptions?.headers)
45
+ };
46
+ if (config$1?.solverRelayApiKey) fetchOptions.headers.append("Authorization", `Bearer ${config$1.solverRelayApiKey}`);
47
+ return handleRPCResponse(await request({
48
+ url,
49
+ body,
50
+ ...config$1,
51
+ fetchOptions,
52
+ retryOptions: config$1?.retryOptions ?? RETRY_CONFIGS.THIRTY_SECS_AGGRESSIVE,
53
+ logger: config$1?.logger
54
+ }), body, rpcResponseSchema);
55
+ }
56
+
57
+ //#endregion
58
+ export { jsonRPCRequest };
@@ -0,0 +1,117 @@
1
+ import { RpcRequestError } from "../../errors/request.cjs";
2
+ import { ILogger } from "../../logger.cjs";
3
+ import { RetryOptions } from "../../utils/retry.cjs";
4
+ import { RequestErrorType } from "../../utils/request.cjs";
5
+ import { MultiPayload } from "amogus-sdk-contract-types";
6
+
7
+ //#region src/solverRelay/solverRelayHttpClient/types.d.ts
8
+ type RequestConfig = {
9
+ requestId?: string | undefined;
10
+ timeout?: number | undefined;
11
+ fetchOptions?: Omit<RequestInit, "body"> | undefined;
12
+ baseURL?: string | undefined;
13
+ retryOptions?: RetryOptions;
14
+ logger?: ILogger;
15
+ solverRelayApiKey?: string;
16
+ };
17
+ type JSONRPCRequest<Method, Params$1> = {
18
+ id: string;
19
+ jsonrpc: "2.0";
20
+ method: Method;
21
+ params: Params$1[];
22
+ };
23
+ type JSONRPCResponse<Result> = {
24
+ id: string;
25
+ jsonrpc: "2.0";
26
+ result: Result;
27
+ };
28
+ type JSONRPCErrorType = RequestErrorType | RpcRequestError;
29
+ type QuoteParamsBase = {
30
+ defuse_asset_identifier_in: string;
31
+ defuse_asset_identifier_out: string;
32
+ min_deadline_ms?: number;
33
+ wait_ms?: number;
34
+ min_wait_ms?: number;
35
+ max_wait_ms?: number;
36
+ trusted_metadata?: unknown;
37
+ };
38
+ type QuoteParamsExactIn = QuoteParamsBase & {
39
+ exact_amount_in: string;
40
+ exact_amount_out?: never;
41
+ };
42
+ type QuoteParamsExactOut = QuoteParamsBase & {
43
+ exact_amount_out: string;
44
+ exact_amount_in?: never;
45
+ };
46
+ type QuoteParams = QuoteParamsExactIn | QuoteParamsExactOut;
47
+ type QuoteRequest = JSONRPCRequest<"quote", QuoteParams>;
48
+ type Params<T extends JSONRPCRequest<unknown, unknown>> = T["params"][0];
49
+ type FailedQuote = {
50
+ type: "INSUFFICIENT_AMOUNT";
51
+ min_amount: string;
52
+ };
53
+ type Quote = {
54
+ quote_hash: string;
55
+ defuse_asset_identifier_in: string;
56
+ defuse_asset_identifier_out: string;
57
+ amount_in: string;
58
+ amount_out: string;
59
+ expiration_time: string;
60
+ };
61
+ type QuoteResponse = JSONRPCResponse<null | Array<Quote | FailedQuote>>;
62
+ type PublishIntentRequest = JSONRPCRequest<"publish_intent", {
63
+ quote_hashes: string[];
64
+ signed_data: MultiPayload;
65
+ }>;
66
+ type PublishIntentResponse = JSONRPCResponse<PublishIntentResponseSuccess | PublishIntentResponseFailure>;
67
+ type PublishIntentResponseSuccess = {
68
+ intent_hash: string;
69
+ status: "OK";
70
+ };
71
+ type PublishIntentResponseFailure = {
72
+ intent_hash: string;
73
+ status: "FAILED";
74
+ reason: string | "expired" | "internal";
75
+ };
76
+ type PublishIntentsRequest = JSONRPCRequest<"publish_intents", {
77
+ quote_hashes: string[];
78
+ signed_datas: MultiPayload[];
79
+ }>;
80
+ type PublishIntentsResponse = JSONRPCResponse<PublishIntentsResponseSuccess | PublishIntentsResponseFailure>;
81
+ type PublishIntentsResponseSuccess = {
82
+ intent_hashes: string[];
83
+ status: "OK";
84
+ };
85
+ type PublishIntentsResponseFailure = {
86
+ intent_hashes: string[];
87
+ status: "FAILED";
88
+ reason: string | "expired" | "internal";
89
+ };
90
+ type GetStatusRequest = JSONRPCRequest<"get_status", {
91
+ intent_hash: string;
92
+ }>;
93
+ type GetStatusResponse = JSONRPCResponse<{
94
+ status: "PENDING";
95
+ intent_hash: string;
96
+ } | {
97
+ status: "TX_BROADCASTED";
98
+ intent_hash: string;
99
+ data: {
100
+ hash: string;
101
+ };
102
+ } | {
103
+ status: "SETTLED";
104
+ intent_hash: string;
105
+ data: {
106
+ hash: string;
107
+ };
108
+ } | {
109
+ status: "NOT_FOUND_OR_NOT_VALID";
110
+ intent_hash: string;
111
+ status_details?: "FAILED";
112
+ data?: {
113
+ hash: string;
114
+ };
115
+ }>;
116
+ //#endregion
117
+ export { FailedQuote, GetStatusRequest, GetStatusResponse, JSONRPCErrorType, JSONRPCRequest, JSONRPCResponse, Params, PublishIntentRequest, PublishIntentResponse, PublishIntentResponseFailure, PublishIntentResponseSuccess, PublishIntentsRequest, PublishIntentsResponse, PublishIntentsResponseFailure, PublishIntentsResponseSuccess, Quote, QuoteRequest, QuoteResponse, RequestConfig };
@@ -0,0 +1,117 @@
1
+ import { RpcRequestError } from "../../errors/request.js";
2
+ import { ILogger } from "../../logger.js";
3
+ import { RetryOptions } from "../../utils/retry.js";
4
+ import { RequestErrorType } from "../../utils/request.js";
5
+ import { MultiPayload } from "amogus-sdk-contract-types";
6
+
7
+ //#region src/solverRelay/solverRelayHttpClient/types.d.ts
8
+ type RequestConfig = {
9
+ requestId?: string | undefined;
10
+ timeout?: number | undefined;
11
+ fetchOptions?: Omit<RequestInit, "body"> | undefined;
12
+ baseURL?: string | undefined;
13
+ retryOptions?: RetryOptions;
14
+ logger?: ILogger;
15
+ solverRelayApiKey?: string;
16
+ };
17
+ type JSONRPCRequest<Method, Params$1> = {
18
+ id: string;
19
+ jsonrpc: "2.0";
20
+ method: Method;
21
+ params: Params$1[];
22
+ };
23
+ type JSONRPCResponse<Result> = {
24
+ id: string;
25
+ jsonrpc: "2.0";
26
+ result: Result;
27
+ };
28
+ type JSONRPCErrorType = RequestErrorType | RpcRequestError;
29
+ type QuoteParamsBase = {
30
+ defuse_asset_identifier_in: string;
31
+ defuse_asset_identifier_out: string;
32
+ min_deadline_ms?: number;
33
+ wait_ms?: number;
34
+ min_wait_ms?: number;
35
+ max_wait_ms?: number;
36
+ trusted_metadata?: unknown;
37
+ };
38
+ type QuoteParamsExactIn = QuoteParamsBase & {
39
+ exact_amount_in: string;
40
+ exact_amount_out?: never;
41
+ };
42
+ type QuoteParamsExactOut = QuoteParamsBase & {
43
+ exact_amount_out: string;
44
+ exact_amount_in?: never;
45
+ };
46
+ type QuoteParams = QuoteParamsExactIn | QuoteParamsExactOut;
47
+ type QuoteRequest = JSONRPCRequest<"quote", QuoteParams>;
48
+ type Params<T extends JSONRPCRequest<unknown, unknown>> = T["params"][0];
49
+ type FailedQuote = {
50
+ type: "INSUFFICIENT_AMOUNT";
51
+ min_amount: string;
52
+ };
53
+ type Quote = {
54
+ quote_hash: string;
55
+ defuse_asset_identifier_in: string;
56
+ defuse_asset_identifier_out: string;
57
+ amount_in: string;
58
+ amount_out: string;
59
+ expiration_time: string;
60
+ };
61
+ type QuoteResponse = JSONRPCResponse<null | Array<Quote | FailedQuote>>;
62
+ type PublishIntentRequest = JSONRPCRequest<"publish_intent", {
63
+ quote_hashes: string[];
64
+ signed_data: MultiPayload;
65
+ }>;
66
+ type PublishIntentResponse = JSONRPCResponse<PublishIntentResponseSuccess | PublishIntentResponseFailure>;
67
+ type PublishIntentResponseSuccess = {
68
+ intent_hash: string;
69
+ status: "OK";
70
+ };
71
+ type PublishIntentResponseFailure = {
72
+ intent_hash: string;
73
+ status: "FAILED";
74
+ reason: string | "expired" | "internal";
75
+ };
76
+ type PublishIntentsRequest = JSONRPCRequest<"publish_intents", {
77
+ quote_hashes: string[];
78
+ signed_datas: MultiPayload[];
79
+ }>;
80
+ type PublishIntentsResponse = JSONRPCResponse<PublishIntentsResponseSuccess | PublishIntentsResponseFailure>;
81
+ type PublishIntentsResponseSuccess = {
82
+ intent_hashes: string[];
83
+ status: "OK";
84
+ };
85
+ type PublishIntentsResponseFailure = {
86
+ intent_hashes: string[];
87
+ status: "FAILED";
88
+ reason: string | "expired" | "internal";
89
+ };
90
+ type GetStatusRequest = JSONRPCRequest<"get_status", {
91
+ intent_hash: string;
92
+ }>;
93
+ type GetStatusResponse = JSONRPCResponse<{
94
+ status: "PENDING";
95
+ intent_hash: string;
96
+ } | {
97
+ status: "TX_BROADCASTED";
98
+ intent_hash: string;
99
+ data: {
100
+ hash: string;
101
+ };
102
+ } | {
103
+ status: "SETTLED";
104
+ intent_hash: string;
105
+ data: {
106
+ hash: string;
107
+ };
108
+ } | {
109
+ status: "NOT_FOUND_OR_NOT_VALID";
110
+ intent_hash: string;
111
+ status_details?: "FAILED";
112
+ data?: {
113
+ hash: string;
114
+ };
115
+ }>;
116
+ //#endregion
117
+ export { FailedQuote, GetStatusRequest, GetStatusResponse, JSONRPCErrorType, JSONRPCRequest, JSONRPCResponse, Params, PublishIntentRequest, PublishIntentResponse, PublishIntentResponseFailure, PublishIntentResponseSuccess, PublishIntentsRequest, PublishIntentsResponse, PublishIntentsResponseFailure, PublishIntentsResponseSuccess, Quote, QuoteRequest, QuoteResponse, RequestConfig };
@@ -0,0 +1,64 @@
1
+ const require_serialize = require('../../utils/serialize.cjs');
2
+ const require_base = require('../../errors/base.cjs');
3
+ const require_assert = require('../../utils/assert.cjs');
4
+
5
+ //#region src/solverRelay/utils/parseFailedPublishError.ts
6
+ var RelayPublishError = class extends require_base.BaseError {
7
+ constructor({ cause, metaMessages, name, publishParams, reason }) {
8
+ super("Failed to publish intent.", {
9
+ details: reason,
10
+ metaMessages: [...metaMessages ?? [], `Publish params: ${require_serialize.serialize(publishParams)}`],
11
+ name,
12
+ cause
13
+ });
14
+ this.publishParams = publishParams;
15
+ }
16
+ };
17
+ var RelayPublishRejectedError = class extends RelayPublishError {
18
+ constructor({ reason, code, publishParams }) {
19
+ super({
20
+ reason,
21
+ metaMessages: [`Code: ${code}`],
22
+ name: "RelayPublishRejectedError",
23
+ publishParams
24
+ });
25
+ this.name = "RelayPublishRejectedError";
26
+ this.code = code;
27
+ }
28
+ };
29
+ var RelayPublishResultUnknownError = class extends RelayPublishError {
30
+ constructor({ reason, publishParams, cause }) {
31
+ super({
32
+ reason,
33
+ name: "RelayPublishResultUnknownError",
34
+ publishParams,
35
+ cause
36
+ });
37
+ this.name = "RelayPublishResultUnknownError";
38
+ }
39
+ };
40
+ function toRelayPublishError(publishParams, response) {
41
+ require_assert.assert(response.status === "FAILED", "Expected response to be failed");
42
+ return new RelayPublishRejectedError({
43
+ reason: response.reason,
44
+ code: parseFailedPublishReason(response),
45
+ publishParams
46
+ });
47
+ }
48
+ function parseFailedPublishReason(response) {
49
+ require_assert.assert(response.status === "FAILED", "Expected response to be failed");
50
+ if (response.reason === "expired" || response.reason.includes("deadline has expired")) return "SIGNATURE_EXPIRED";
51
+ if (response.reason === "internal") return "INTERNAL_ERROR";
52
+ if (response.reason.includes("invalid signature")) return "SIGNATURE_INVALID";
53
+ if (response.reason.includes("nonce was already used")) return "NONCE_USED";
54
+ if (response.reason.includes("insufficient balance or overflow")) return "INSUFFICIENT_BALANCE";
55
+ if (response.reason.includes("public key doesn't exist")) return "PUBLIC_KEY_NOT_EXIST";
56
+ if (response.reason.includes("invalid salt")) return "INVALID_SALT";
57
+ return "UNKNOWN_ERROR";
58
+ }
59
+
60
+ //#endregion
61
+ exports.RelayPublishError = RelayPublishError;
62
+ exports.RelayPublishRejectedError = RelayPublishRejectedError;
63
+ exports.RelayPublishResultUnknownError = RelayPublishResultUnknownError;
64
+ exports.toRelayPublishError = toRelayPublishError;
@@ -0,0 +1,56 @@
1
+ import { BaseError } from "../../errors/base.cjs";
2
+ import { publishIntent, publishIntents } from "../solverRelayHttpClient/apis.cjs";
3
+
4
+ //#region src/solverRelay/utils/parseFailedPublishError.d.ts
5
+ type PublishErrorCode = "SIGNATURE_EXPIRED" | "INTERNAL_ERROR" | "SIGNATURE_INVALID" | "NONCE_USED" | "INSUFFICIENT_BALANCE" | "PUBLIC_KEY_NOT_EXIST" | "UNKNOWN_ERROR" | "INVALID_SALT";
6
+ type PublishParams = Parameters<typeof publishIntents>[0] | Parameters<typeof publishIntent>[0];
7
+ type RelayPublishRejectedErrorType = RelayPublishRejectedError & {
8
+ name: "RelayPublishRejectedError";
9
+ };
10
+ type RelayPublishResultUnknownErrorType = RelayPublishResultUnknownError & {
11
+ name: "RelayPublishResultUnknownError";
12
+ };
13
+ type RelayPublishErrorType = RelayPublishRejectedErrorType | RelayPublishResultUnknownErrorType;
14
+ declare abstract class RelayPublishError extends BaseError {
15
+ publishParams: PublishParams;
16
+ protected constructor({
17
+ cause,
18
+ metaMessages,
19
+ name,
20
+ publishParams,
21
+ reason
22
+ }: {
23
+ cause?: unknown;
24
+ metaMessages?: string[];
25
+ name: "RelayPublishRejectedError" | "RelayPublishResultUnknownError";
26
+ publishParams: PublishParams;
27
+ reason: string;
28
+ });
29
+ }
30
+ declare class RelayPublishRejectedError extends RelayPublishError {
31
+ name: "RelayPublishRejectedError";
32
+ code: PublishErrorCode;
33
+ constructor({
34
+ reason,
35
+ code,
36
+ publishParams
37
+ }: {
38
+ reason: string;
39
+ code: PublishErrorCode;
40
+ publishParams: PublishParams;
41
+ });
42
+ }
43
+ declare class RelayPublishResultUnknownError extends RelayPublishError {
44
+ name: "RelayPublishResultUnknownError";
45
+ constructor({
46
+ reason,
47
+ publishParams,
48
+ cause
49
+ }: {
50
+ reason: string;
51
+ publishParams: PublishParams;
52
+ cause?: unknown;
53
+ });
54
+ }
55
+ //#endregion
56
+ export { RelayPublishError, RelayPublishErrorType, RelayPublishRejectedError, RelayPublishRejectedErrorType, RelayPublishResultUnknownError, RelayPublishResultUnknownErrorType };
@@ -0,0 +1,57 @@
1
+ import { BaseError } from "../../errors/base.js";
2
+ import { publishIntent, publishIntents } from "../solverRelayHttpClient/apis.js";
3
+ import "../solverRelayHttpClient/index.js";
4
+
5
+ //#region src/solverRelay/utils/parseFailedPublishError.d.ts
6
+ type PublishErrorCode = "SIGNATURE_EXPIRED" | "INTERNAL_ERROR" | "SIGNATURE_INVALID" | "NONCE_USED" | "INSUFFICIENT_BALANCE" | "PUBLIC_KEY_NOT_EXIST" | "UNKNOWN_ERROR" | "INVALID_SALT";
7
+ type PublishParams = Parameters<typeof publishIntents>[0] | Parameters<typeof publishIntent>[0];
8
+ type RelayPublishRejectedErrorType = RelayPublishRejectedError & {
9
+ name: "RelayPublishRejectedError";
10
+ };
11
+ type RelayPublishResultUnknownErrorType = RelayPublishResultUnknownError & {
12
+ name: "RelayPublishResultUnknownError";
13
+ };
14
+ type RelayPublishErrorType = RelayPublishRejectedErrorType | RelayPublishResultUnknownErrorType;
15
+ declare abstract class RelayPublishError extends BaseError {
16
+ publishParams: PublishParams;
17
+ protected constructor({
18
+ cause,
19
+ metaMessages,
20
+ name,
21
+ publishParams,
22
+ reason
23
+ }: {
24
+ cause?: unknown;
25
+ metaMessages?: string[];
26
+ name: "RelayPublishRejectedError" | "RelayPublishResultUnknownError";
27
+ publishParams: PublishParams;
28
+ reason: string;
29
+ });
30
+ }
31
+ declare class RelayPublishRejectedError extends RelayPublishError {
32
+ name: "RelayPublishRejectedError";
33
+ code: PublishErrorCode;
34
+ constructor({
35
+ reason,
36
+ code,
37
+ publishParams
38
+ }: {
39
+ reason: string;
40
+ code: PublishErrorCode;
41
+ publishParams: PublishParams;
42
+ });
43
+ }
44
+ declare class RelayPublishResultUnknownError extends RelayPublishError {
45
+ name: "RelayPublishResultUnknownError";
46
+ constructor({
47
+ reason,
48
+ publishParams,
49
+ cause
50
+ }: {
51
+ reason: string;
52
+ publishParams: PublishParams;
53
+ cause?: unknown;
54
+ });
55
+ }
56
+ //#endregion
57
+ export { RelayPublishError, RelayPublishErrorType, RelayPublishRejectedError, RelayPublishRejectedErrorType, RelayPublishResultUnknownError, RelayPublishResultUnknownErrorType };
@@ -0,0 +1,61 @@
1
+ import { serialize } from "../../utils/serialize.js";
2
+ import { BaseError } from "../../errors/base.js";
3
+ import { assert } from "../../utils/assert.js";
4
+
5
+ //#region src/solverRelay/utils/parseFailedPublishError.ts
6
+ var RelayPublishError = class extends BaseError {
7
+ constructor({ cause, metaMessages, name, publishParams, reason }) {
8
+ super("Failed to publish intent.", {
9
+ details: reason,
10
+ metaMessages: [...metaMessages ?? [], `Publish params: ${serialize(publishParams)}`],
11
+ name,
12
+ cause
13
+ });
14
+ this.publishParams = publishParams;
15
+ }
16
+ };
17
+ var RelayPublishRejectedError = class extends RelayPublishError {
18
+ constructor({ reason, code, publishParams }) {
19
+ super({
20
+ reason,
21
+ metaMessages: [`Code: ${code}`],
22
+ name: "RelayPublishRejectedError",
23
+ publishParams
24
+ });
25
+ this.name = "RelayPublishRejectedError";
26
+ this.code = code;
27
+ }
28
+ };
29
+ var RelayPublishResultUnknownError = class extends RelayPublishError {
30
+ constructor({ reason, publishParams, cause }) {
31
+ super({
32
+ reason,
33
+ name: "RelayPublishResultUnknownError",
34
+ publishParams,
35
+ cause
36
+ });
37
+ this.name = "RelayPublishResultUnknownError";
38
+ }
39
+ };
40
+ function toRelayPublishError(publishParams, response) {
41
+ assert(response.status === "FAILED", "Expected response to be failed");
42
+ return new RelayPublishRejectedError({
43
+ reason: response.reason,
44
+ code: parseFailedPublishReason(response),
45
+ publishParams
46
+ });
47
+ }
48
+ function parseFailedPublishReason(response) {
49
+ assert(response.status === "FAILED", "Expected response to be failed");
50
+ if (response.reason === "expired" || response.reason.includes("deadline has expired")) return "SIGNATURE_EXPIRED";
51
+ if (response.reason === "internal") return "INTERNAL_ERROR";
52
+ if (response.reason.includes("invalid signature")) return "SIGNATURE_INVALID";
53
+ if (response.reason.includes("nonce was already used")) return "NONCE_USED";
54
+ if (response.reason.includes("insufficient balance or overflow")) return "INSUFFICIENT_BALANCE";
55
+ if (response.reason.includes("public key doesn't exist")) return "PUBLIC_KEY_NOT_EXIST";
56
+ if (response.reason.includes("invalid salt")) return "INVALID_SALT";
57
+ return "UNKNOWN_ERROR";
58
+ }
59
+
60
+ //#endregion
61
+ export { RelayPublishError, RelayPublishRejectedError, RelayPublishResultUnknownError, toRelayPublishError };
@@ -0,0 +1,21 @@
1
+ const require_apis = require('../solverRelayHttpClient/apis.cjs');
2
+
3
+ //#region src/solverRelay/utils/quoteWithLog.ts
4
+ async function quoteWithLog(params, { logBalanceSufficient, ...config }) {
5
+ const requestId = crypto.randomUUID();
6
+ const result = await require_apis.quote(params, {
7
+ ...config,
8
+ requestId
9
+ });
10
+ if (result == null) {
11
+ config.logger?.warn("quote: No liquidity available", { quoteParams: params });
12
+ if (logBalanceSufficient && (params.wait_ms == null || params.wait_ms > 2500)) config.logger?.warn("quote: No liquidity available for user with sufficient balance", {
13
+ quoteParams: params,
14
+ quoteRequestInfo: { requestId }
15
+ });
16
+ }
17
+ return result;
18
+ }
19
+
20
+ //#endregion
21
+ exports.quoteWithLog = quoteWithLog;
@@ -0,0 +1,12 @@
1
+ import { FailedQuote, Quote } from "../solverRelayHttpClient/types.cjs";
2
+ import { quote } from "../solverRelayHttpClient/apis.cjs";
3
+
4
+ //#region src/solverRelay/utils/quoteWithLog.d.ts
5
+ declare function quoteWithLog(params: Parameters<typeof quote>[0], {
6
+ logBalanceSufficient,
7
+ ...config
8
+ }: {
9
+ logBalanceSufficient: boolean;
10
+ } & Parameters<typeof quote>[1]): Promise<(Quote | FailedQuote)[] | null>;
11
+ //#endregion
12
+ export { quoteWithLog };
@@ -0,0 +1,14 @@
1
+ import { FailedQuote, Quote } from "../solverRelayHttpClient/types.js";
2
+ import { quote } from "../solverRelayHttpClient/apis.js";
3
+ import "../solverRelayHttpClient/index.js";
4
+ import "../index.js";
5
+
6
+ //#region src/solverRelay/utils/quoteWithLog.d.ts
7
+ declare function quoteWithLog(params: Parameters<typeof quote>[0], {
8
+ logBalanceSufficient,
9
+ ...config
10
+ }: {
11
+ logBalanceSufficient: boolean;
12
+ } & Parameters<typeof quote>[1]): Promise<(Quote | FailedQuote)[] | null>;
13
+ //#endregion
14
+ export { quoteWithLog };
@@ -0,0 +1,21 @@
1
+ import { quote } from "../solverRelayHttpClient/apis.js";
2
+
3
+ //#region src/solverRelay/utils/quoteWithLog.ts
4
+ async function quoteWithLog(params, { logBalanceSufficient, ...config }) {
5
+ const requestId = crypto.randomUUID();
6
+ const result = await quote(params, {
7
+ ...config,
8
+ requestId
9
+ });
10
+ if (result == null) {
11
+ config.logger?.warn("quote: No liquidity available", { quoteParams: params });
12
+ if (logBalanceSufficient && (params.wait_ms == null || params.wait_ms > 2500)) config.logger?.warn("quote: No liquidity available for user with sufficient balance", {
13
+ quoteParams: params,
14
+ quoteRequestInfo: { requestId }
15
+ });
16
+ }
17
+ return result;
18
+ }
19
+
20
+ //#endregion
21
+ export { quoteWithLog };