lampamazaza-new-internal-utils 0.24.3

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 (216) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +43 -0
  3. package/dist/_virtual/rolldown_runtime.js +18 -0
  4. package/dist/config.cjs +82 -0
  5. package/dist/config.d.cts +42 -0
  6. package/dist/config.d.ts +42 -0
  7. package/dist/config.js +72 -0
  8. package/dist/errors/assert.cjs +11 -0
  9. package/dist/errors/assert.d.cts +11 -0
  10. package/dist/errors/assert.d.ts +11 -0
  11. package/dist/errors/assert.js +11 -0
  12. package/dist/errors/base.cjs +34 -0
  13. package/dist/errors/base.d.cts +21 -0
  14. package/dist/errors/base.d.ts +21 -0
  15. package/dist/errors/base.js +33 -0
  16. package/dist/errors/index.cjs +23 -0
  17. package/dist/errors/index.d.cts +11 -0
  18. package/dist/errors/index.d.ts +11 -0
  19. package/dist/errors/index.js +18 -0
  20. package/dist/errors/request.cjs +48 -0
  21. package/dist/errors/request.d.cts +61 -0
  22. package/dist/errors/request.d.ts +61 -0
  23. package/dist/errors/request.js +46 -0
  24. package/dist/errors/utils/isNetworkError.cjs +23 -0
  25. package/dist/errors/utils/isNetworkError.js +22 -0
  26. package/dist/errors/utils/toError.cjs +8 -0
  27. package/dist/errors/utils/toError.d.cts +4 -0
  28. package/dist/errors/utils/toError.d.ts +4 -0
  29. package/dist/errors/utils/toError.js +7 -0
  30. package/dist/index.cjs +125 -0
  31. package/dist/index.d.cts +30 -0
  32. package/dist/index.d.ts +30 -0
  33. package/dist/index.js +30 -0
  34. package/dist/logger.d.cts +11 -0
  35. package/dist/logger.d.ts +11 -0
  36. package/dist/nearClient.cjs +18 -0
  37. package/dist/nearClient.d.cts +8 -0
  38. package/dist/nearClient.d.ts +8 -0
  39. package/dist/nearClient.js +18 -0
  40. package/dist/poaBridge/constants/blockchains.cjs +57 -0
  41. package/dist/poaBridge/constants/blockchains.d.cts +86 -0
  42. package/dist/poaBridge/constants/blockchains.d.ts +86 -0
  43. package/dist/poaBridge/constants/blockchains.js +54 -0
  44. package/dist/poaBridge/errors/withdrawal.cjs +52 -0
  45. package/dist/poaBridge/errors/withdrawal.d.cts +34 -0
  46. package/dist/poaBridge/errors/withdrawal.d.ts +34 -0
  47. package/dist/poaBridge/errors/withdrawal.js +50 -0
  48. package/dist/poaBridge/getPendingDeposits.cjs +9 -0
  49. package/dist/poaBridge/getPendingDeposits.d.cts +12 -0
  50. package/dist/poaBridge/getPendingDeposits.d.ts +13 -0
  51. package/dist/poaBridge/getPendingDeposits.js +9 -0
  52. package/dist/poaBridge/index.cjs +23 -0
  53. package/dist/poaBridge/index.d.cts +11 -0
  54. package/dist/poaBridge/index.d.ts +11 -0
  55. package/dist/poaBridge/index.js +18 -0
  56. package/dist/poaBridge/poaBridgeHttpClient/apis.cjs +38 -0
  57. package/dist/poaBridge/poaBridgeHttpClient/apis.d.cts +12 -0
  58. package/dist/poaBridge/poaBridgeHttpClient/apis.d.ts +12 -0
  59. package/dist/poaBridge/poaBridgeHttpClient/apis.js +32 -0
  60. package/dist/poaBridge/poaBridgeHttpClient/index.cjs +21 -0
  61. package/dist/poaBridge/poaBridgeHttpClient/index.d.cts +9 -0
  62. package/dist/poaBridge/poaBridgeHttpClient/index.d.ts +9 -0
  63. package/dist/poaBridge/poaBridgeHttpClient/index.js +16 -0
  64. package/dist/poaBridge/poaBridgeHttpClient/runtime.cjs +49 -0
  65. package/dist/poaBridge/poaBridgeHttpClient/runtime.js +47 -0
  66. package/dist/poaBridge/poaBridgeHttpClient/types.d.cts +161 -0
  67. package/dist/poaBridge/poaBridgeHttpClient/types.d.ts +161 -0
  68. package/dist/poaBridge/waitForWithdrawalCompletion.cjs +57 -0
  69. package/dist/poaBridge/waitForWithdrawalCompletion.d.cts +31 -0
  70. package/dist/poaBridge/waitForWithdrawalCompletion.d.ts +31 -0
  71. package/dist/poaBridge/waitForWithdrawalCompletion.js +56 -0
  72. package/dist/services/blockchainBalanceService.cjs +40 -0
  73. package/dist/services/blockchainBalanceService.d.cts +21 -0
  74. package/dist/services/blockchainBalanceService.d.ts +21 -0
  75. package/dist/services/blockchainBalanceService.js +37 -0
  76. package/dist/solverRelay/errors/intentSettlement.cjs +20 -0
  77. package/dist/solverRelay/errors/intentSettlement.d.cts +13 -0
  78. package/dist/solverRelay/errors/intentSettlement.d.ts +13 -0
  79. package/dist/solverRelay/errors/intentSettlement.js +20 -0
  80. package/dist/solverRelay/errors/quote.cjs +18 -0
  81. package/dist/solverRelay/errors/quote.d.cts +21 -0
  82. package/dist/solverRelay/errors/quote.d.ts +22 -0
  83. package/dist/solverRelay/errors/quote.js +18 -0
  84. package/dist/solverRelay/getQuote.cjs +49 -0
  85. package/dist/solverRelay/getQuote.d.cts +14 -0
  86. package/dist/solverRelay/getQuote.d.ts +14 -0
  87. package/dist/solverRelay/getQuote.js +49 -0
  88. package/dist/solverRelay/getStatus.cjs +26 -0
  89. package/dist/solverRelay/getStatus.d.cts +17 -0
  90. package/dist/solverRelay/getStatus.d.ts +18 -0
  91. package/dist/solverRelay/getStatus.js +26 -0
  92. package/dist/solverRelay/index.cjs +27 -0
  93. package/dist/solverRelay/index.d.cts +16 -0
  94. package/dist/solverRelay/index.d.ts +16 -0
  95. package/dist/solverRelay/index.js +22 -0
  96. package/dist/solverRelay/publishIntent.cjs +20 -0
  97. package/dist/solverRelay/publishIntent.d.cts +15 -0
  98. package/dist/solverRelay/publishIntent.d.ts +16 -0
  99. package/dist/solverRelay/publishIntent.js +20 -0
  100. package/dist/solverRelay/publishIntents.cjs +43 -0
  101. package/dist/solverRelay/publishIntents.d.cts +10 -0
  102. package/dist/solverRelay/publishIntents.d.ts +11 -0
  103. package/dist/solverRelay/publishIntents.js +42 -0
  104. package/dist/solverRelay/solverRelayHttpClient/apis.cjs +21 -0
  105. package/dist/solverRelay/solverRelayHttpClient/apis.d.cts +9 -0
  106. package/dist/solverRelay/solverRelayHttpClient/apis.d.ts +9 -0
  107. package/dist/solverRelay/solverRelayHttpClient/apis.js +18 -0
  108. package/dist/solverRelay/solverRelayHttpClient/index.cjs +18 -0
  109. package/dist/solverRelay/solverRelayHttpClient/index.d.cts +9 -0
  110. package/dist/solverRelay/solverRelayHttpClient/index.d.ts +9 -0
  111. package/dist/solverRelay/solverRelayHttpClient/index.js +13 -0
  112. package/dist/solverRelay/solverRelayHttpClient/runtime.cjs +60 -0
  113. package/dist/solverRelay/solverRelayHttpClient/runtime.js +58 -0
  114. package/dist/solverRelay/solverRelayHttpClient/types.d.cts +109 -0
  115. package/dist/solverRelay/solverRelayHttpClient/types.d.ts +109 -0
  116. package/dist/solverRelay/utils/parseFailedPublishError.cjs +40 -0
  117. package/dist/solverRelay/utils/parseFailedPublishError.d.cts +25 -0
  118. package/dist/solverRelay/utils/parseFailedPublishError.d.ts +26 -0
  119. package/dist/solverRelay/utils/parseFailedPublishError.js +39 -0
  120. package/dist/solverRelay/utils/quoteWithLog.cjs +21 -0
  121. package/dist/solverRelay/utils/quoteWithLog.d.cts +12 -0
  122. package/dist/solverRelay/utils/quoteWithLog.d.ts +14 -0
  123. package/dist/solverRelay/utils/quoteWithLog.js +21 -0
  124. package/dist/solverRelay/waitForIntentSettlement.cjs +52 -0
  125. package/dist/solverRelay/waitForIntentSettlement.d.cts +30 -0
  126. package/dist/solverRelay/waitForIntentSettlement.d.ts +30 -0
  127. package/dist/solverRelay/waitForIntentSettlement.js +52 -0
  128. package/dist/types/authHandle.cjs +22 -0
  129. package/dist/types/authHandle.d.cts +25 -0
  130. package/dist/types/authHandle.d.ts +25 -0
  131. package/dist/types/authHandle.js +16 -0
  132. package/dist/types/base.d.cts +45 -0
  133. package/dist/types/base.d.ts +45 -0
  134. package/dist/types/intentsUserId.d.cts +10 -0
  135. package/dist/types/intentsUserId.d.ts +10 -0
  136. package/dist/types/walletMessage.cjs +11 -0
  137. package/dist/types/walletMessage.d.cts +106 -0
  138. package/dist/types/walletMessage.d.ts +106 -0
  139. package/dist/types/walletMessage.js +5 -0
  140. package/dist/utils/abortSignal.cjs +19 -0
  141. package/dist/utils/abortSignal.js +18 -0
  142. package/dist/utils/appFee.cjs +20 -0
  143. package/dist/utils/appFee.d.cts +9 -0
  144. package/dist/utils/appFee.d.ts +9 -0
  145. package/dist/utils/appFee.js +15 -0
  146. package/dist/utils/assert.cjs +9 -0
  147. package/dist/utils/assert.d.cts +7 -0
  148. package/dist/utils/assert.d.ts +7 -0
  149. package/dist/utils/assert.js +9 -0
  150. package/dist/utils/authIdentity.cjs +56 -0
  151. package/dist/utils/authIdentity.d.cts +34 -0
  152. package/dist/utils/authIdentity.d.ts +34 -0
  153. package/dist/utils/authIdentity.js +50 -0
  154. package/dist/utils/failover.cjs +22 -0
  155. package/dist/utils/failover.d.cts +16 -0
  156. package/dist/utils/failover.d.ts +16 -0
  157. package/dist/utils/failover.js +20 -0
  158. package/dist/utils/handleRPCResponse.cjs +30 -0
  159. package/dist/utils/handleRPCResponse.js +28 -0
  160. package/dist/utils/index.cjs +55 -0
  161. package/dist/utils/index.d.cts +13 -0
  162. package/dist/utils/index.d.ts +13 -0
  163. package/dist/utils/index.js +50 -0
  164. package/dist/utils/messageFactory.cjs +137 -0
  165. package/dist/utils/messageFactory.d.cts +70 -0
  166. package/dist/utils/messageFactory.d.ts +70 -0
  167. package/dist/utils/messageFactory.js +132 -0
  168. package/dist/utils/multiPayload/webauthn.cjs +27 -0
  169. package/dist/utils/multiPayload/webauthn.js +26 -0
  170. package/dist/utils/near.cjs +58 -0
  171. package/dist/utils/near.d.cts +35 -0
  172. package/dist/utils/near.d.ts +35 -0
  173. package/dist/utils/near.js +53 -0
  174. package/dist/utils/poll.cjs +87 -0
  175. package/dist/utils/poll.d.cts +54 -0
  176. package/dist/utils/poll.d.ts +54 -0
  177. package/dist/utils/poll.js +85 -0
  178. package/dist/utils/prepareBroadcastRequest.cjs +98 -0
  179. package/dist/utils/prepareBroadcastRequest.d.cts +16 -0
  180. package/dist/utils/prepareBroadcastRequest.d.ts +16 -0
  181. package/dist/utils/prepareBroadcastRequest.js +90 -0
  182. package/dist/utils/promise/withTimeout.cjs +34 -0
  183. package/dist/utils/promise/withTimeout.d.cts +16 -0
  184. package/dist/utils/promise/withTimeout.d.ts +16 -0
  185. package/dist/utils/promise/withTimeout.js +34 -0
  186. package/dist/utils/request.cjs +100 -0
  187. package/dist/utils/request.d.cts +27 -0
  188. package/dist/utils/request.d.ts +27 -0
  189. package/dist/utils/request.js +99 -0
  190. package/dist/utils/requestShouldRetry.cjs +20 -0
  191. package/dist/utils/requestShouldRetry.js +20 -0
  192. package/dist/utils/retry.cjs +66 -0
  193. package/dist/utils/retry.d.cts +56 -0
  194. package/dist/utils/retry.d.ts +56 -0
  195. package/dist/utils/retry.js +64 -0
  196. package/dist/utils/serialize.cjs +82 -0
  197. package/dist/utils/serialize.d.cts +17 -0
  198. package/dist/utils/serialize.d.ts +17 -0
  199. package/dist/utils/serialize.js +81 -0
  200. package/dist/utils/stellarAddressToBytes.cjs +295 -0
  201. package/dist/utils/stellarAddressToBytes.js +294 -0
  202. package/dist/utils/token.cjs +8 -0
  203. package/dist/utils/token.js +7 -0
  204. package/dist/utils/tokenUtils.cjs +263 -0
  205. package/dist/utils/tokenUtils.d.cts +88 -0
  206. package/dist/utils/tokenUtils.d.ts +88 -0
  207. package/dist/utils/tokenUtils.js +238 -0
  208. package/dist/utils/tronAddressToHex.cjs +18 -0
  209. package/dist/utils/tronAddressToHex.js +17 -0
  210. package/dist/utils/uint8Array.cjs +15 -0
  211. package/dist/utils/uint8Array.d.cts +4 -0
  212. package/dist/utils/uint8Array.d.ts +4 -0
  213. package/dist/utils/uint8Array.js +14 -0
  214. package/dist/utils/webAuthn.cjs +91 -0
  215. package/dist/utils/webAuthn.js +89 -0
  216. package/package.json +56 -0
@@ -0,0 +1,47 @@
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/poaBridge/poaBridgeHttpClient/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.string(), v.transform((v$1) => {
16
+ return {
17
+ code: -1,
18
+ data: null,
19
+ message: v$1
20
+ };
21
+ }))
22
+ })]);
23
+ async function jsonRPCRequest(method, params, config$1) {
24
+ const baseURL = config$1?.baseURL ?? config.env.poaBridgeBaseURL;
25
+ const url = new URL("rpc", baseURL);
26
+ url.searchParams.set("method", String(method));
27
+ const body = {
28
+ id: config$1?.requestId ?? "dontcare",
29
+ jsonrpc: "2.0",
30
+ method,
31
+ params: params !== void 0 ? [params] : void 0
32
+ };
33
+ return handleRPCResponse(await request({
34
+ url,
35
+ body,
36
+ ...config$1,
37
+ fetchOptions: {
38
+ ...config$1?.fetchOptions,
39
+ method: "POST"
40
+ },
41
+ retryOptions: config$1?.retryOptions ?? RETRY_CONFIGS.THIRTY_SECS_AGGRESSIVE,
42
+ logger: config$1?.logger
43
+ }), body, rpcResponseSchema);
44
+ }
45
+
46
+ //#endregion
47
+ export { jsonRPCRequest };
@@ -0,0 +1,161 @@
1
+ import { RpcRequestError } from "../../errors/request.cjs";
2
+ import { ILogger } from "../../logger.cjs";
3
+ import { BaseTokenInfo } from "../../types/base.cjs";
4
+ import { RetryOptions } from "../../utils/retry.cjs";
5
+ import { RequestErrorType } from "../../utils/request.cjs";
6
+ import { BlockchainEnum } from "../constants/blockchains.cjs";
7
+
8
+ //#region src/poaBridge/poaBridgeHttpClient/types.d.ts
9
+ type RequestConfig = {
10
+ requestId?: string | undefined;
11
+ timeout?: number | undefined;
12
+ fetchOptions?: Omit<RequestInit, "body"> | undefined;
13
+ baseURL?: string | undefined;
14
+ retryOptions?: RetryOptions;
15
+ logger?: ILogger;
16
+ };
17
+ type JSONRPCRequest<Method, Params> = {
18
+ id: string;
19
+ jsonrpc: "2.0";
20
+ method: Method;
21
+ params: Params[];
22
+ };
23
+ type JSONRPCResponse<Result> = {
24
+ id: string;
25
+ jsonrpc: "2.0";
26
+ result: Result;
27
+ };
28
+ type JSONRPCErrorType = RequestErrorType | RpcRequestError;
29
+ type GetSupportedTokensRequest = JSONRPCRequest<"supported_tokens", {
30
+ chains?: string[];
31
+ }>;
32
+ type GetSupportedTokensResponse = JSONRPCResponse<{
33
+ tokens: {
34
+ /**
35
+ * Raw asset id.
36
+ * Example: "nep245:v2_1.omni.hot.tg:1117_3tsdfyziyc7EJbP2aULWSKU4toBaAcN4FdTgfm5W1mC4ouR"
37
+ */
38
+ intents_token_id: string;
39
+ /**
40
+ * Token standard extracted from intents_token_id (the part before the first colon).
41
+ * In most cases it is either "nep245" or "nep141"
42
+ */
43
+ standard: string;
44
+ /**
45
+ * Contract ID extracted from intents_token_id (the part between the first and second colon).
46
+ * Example: "v2_1.omni.hot.tg"
47
+ */
48
+ near_token_id: string;
49
+ /**
50
+ * Token ID extracted from intents_token_id (the part after the second colon).
51
+ * Only present for "nep245" standard tokens.
52
+ * Example: "1117_3tsdfyziyc7EJbP2aULWSKU4toBaAcN4FdTgfm5W1mC4ouR"
53
+ */
54
+ multi_token_id?: string;
55
+ /**
56
+ * Symbol
57
+ */
58
+ asset_name: string;
59
+ decimals: number;
60
+ min_deposit_amount: string;
61
+ min_withdrawal_amount: string;
62
+ withdrawal_fee: string;
63
+ /**
64
+ * Internal POA Bridge identifier.
65
+ * @deprecated This identifier is for internal use only and should not be used in client code.
66
+ * @internal
67
+ */
68
+ defuse_asset_identifier: string;
69
+ }[];
70
+ }>;
71
+ type DepositNetworkMemo = {
72
+ deposit_mode: "MEMO";
73
+ } | null;
74
+ type GetDepositAddressRequest = JSONRPCRequest<"deposit_address", {
75
+ account_id: string;
76
+ /** Chain is joined blockchain and network (e.g. eth:8453) */
77
+ chain: string;
78
+ /** Stellar blockchain specific */
79
+ deposit_mode?: "MEMO" | "SIMPLE";
80
+ }>;
81
+ type GetDepositAddressResponse = JSONRPCResponse<{
82
+ address: string;
83
+ chain: string;
84
+ /** Stellar blockchain specific */
85
+ memo?: string;
86
+ }>;
87
+ type DepositStatus = {
88
+ tx_hash: string;
89
+ chain: string;
90
+ defuse_asset_identifier: string;
91
+ near_token_id: string;
92
+ decimals: number;
93
+ amount: number;
94
+ account_id: string;
95
+ address: string;
96
+ status: "COMPLETED" | "PENDING" | "FAILED";
97
+ };
98
+ type GetDepositStatusRequest = JSONRPCRequest<"recent_deposits", {
99
+ account_id: string;
100
+ chain?: string;
101
+ }>;
102
+ type GetDepositStatusResponse = JSONRPCResponse<{
103
+ deposits: DepositStatus[];
104
+ }>;
105
+ type WithdrawalStatusRequest = JSONRPCRequest<"withdrawal_status", {
106
+ withdrawal_hash: string;
107
+ }>;
108
+ type WithdrawalStatusResponseOk = JSONRPCResponse<{
109
+ withdrawals: {
110
+ status: "COMPLETED" | "PENDING";
111
+ data: {
112
+ tx_hash: string;
113
+ transfer_tx_hash: string | null;
114
+ chain: string;
115
+ defuse_asset_identifier: string;
116
+ near_token_id: string;
117
+ decimals: number;
118
+ amount: number;
119
+ account_id: string;
120
+ address: string;
121
+ created: string;
122
+ };
123
+ }[];
124
+ }>;
125
+ type HotOmniWithdrawRequest = JSONRPCRequest<"hot_omni_withdraw", {
126
+ account_id: string;
127
+ tx_hash: string;
128
+ receiver: string;
129
+ chain_id: string;
130
+ }>;
131
+ type HotOmniWithdrawResponse = JSONRPCResponse<{
132
+ status: "COMPLETED" | "PENDING";
133
+ data: {
134
+ transfer_tx_hash: string | null;
135
+ };
136
+ }[]>;
137
+ type TokenBalances = {
138
+ symbol: string;
139
+ address: string;
140
+ nearAddress: string;
141
+ decimals: number;
142
+ totalSupply: string;
143
+ vaultBalance: string;
144
+ coldWalletBalance: string;
145
+ balanceOnDefuse: string;
146
+ };
147
+ type BridgeBalanceResponse = TokenBalances[];
148
+ type GetWithdrawalEstimateRequest = JSONRPCRequest<"withdrawal_estimate", {
149
+ token: string;
150
+ address: string;
151
+ chain: BlockchainEnum;
152
+ }>;
153
+ type WithdrawalEstimateResponse = {
154
+ token: BaseTokenInfo;
155
+ tokenAddress: string;
156
+ userAddress: string;
157
+ withdrawalFee: string;
158
+ withdrawalFeeDecimals: number;
159
+ };
160
+ //#endregion
161
+ export { BridgeBalanceResponse, DepositNetworkMemo, DepositStatus, GetDepositAddressRequest, GetDepositAddressResponse, GetDepositStatusRequest, GetDepositStatusResponse, GetSupportedTokensRequest, GetSupportedTokensResponse, GetWithdrawalEstimateRequest, HotOmniWithdrawRequest, HotOmniWithdrawResponse, JSONRPCErrorType, JSONRPCRequest, JSONRPCResponse, RequestConfig, TokenBalances, WithdrawalEstimateResponse, WithdrawalStatusRequest, WithdrawalStatusResponseOk };
@@ -0,0 +1,161 @@
1
+ import { RpcRequestError } from "../../errors/request.js";
2
+ import { ILogger } from "../../logger.js";
3
+ import { BaseTokenInfo } from "../../types/base.js";
4
+ import { RetryOptions } from "../../utils/retry.js";
5
+ import { RequestErrorType } from "../../utils/request.js";
6
+ import { BlockchainEnum } from "../constants/blockchains.js";
7
+
8
+ //#region src/poaBridge/poaBridgeHttpClient/types.d.ts
9
+ type RequestConfig = {
10
+ requestId?: string | undefined;
11
+ timeout?: number | undefined;
12
+ fetchOptions?: Omit<RequestInit, "body"> | undefined;
13
+ baseURL?: string | undefined;
14
+ retryOptions?: RetryOptions;
15
+ logger?: ILogger;
16
+ };
17
+ type JSONRPCRequest<Method, Params> = {
18
+ id: string;
19
+ jsonrpc: "2.0";
20
+ method: Method;
21
+ params: Params[];
22
+ };
23
+ type JSONRPCResponse<Result> = {
24
+ id: string;
25
+ jsonrpc: "2.0";
26
+ result: Result;
27
+ };
28
+ type JSONRPCErrorType = RequestErrorType | RpcRequestError;
29
+ type GetSupportedTokensRequest = JSONRPCRequest<"supported_tokens", {
30
+ chains?: string[];
31
+ }>;
32
+ type GetSupportedTokensResponse = JSONRPCResponse<{
33
+ tokens: {
34
+ /**
35
+ * Raw asset id.
36
+ * Example: "nep245:v2_1.omni.hot.tg:1117_3tsdfyziyc7EJbP2aULWSKU4toBaAcN4FdTgfm5W1mC4ouR"
37
+ */
38
+ intents_token_id: string;
39
+ /**
40
+ * Token standard extracted from intents_token_id (the part before the first colon).
41
+ * In most cases it is either "nep245" or "nep141"
42
+ */
43
+ standard: string;
44
+ /**
45
+ * Contract ID extracted from intents_token_id (the part between the first and second colon).
46
+ * Example: "v2_1.omni.hot.tg"
47
+ */
48
+ near_token_id: string;
49
+ /**
50
+ * Token ID extracted from intents_token_id (the part after the second colon).
51
+ * Only present for "nep245" standard tokens.
52
+ * Example: "1117_3tsdfyziyc7EJbP2aULWSKU4toBaAcN4FdTgfm5W1mC4ouR"
53
+ */
54
+ multi_token_id?: string;
55
+ /**
56
+ * Symbol
57
+ */
58
+ asset_name: string;
59
+ decimals: number;
60
+ min_deposit_amount: string;
61
+ min_withdrawal_amount: string;
62
+ withdrawal_fee: string;
63
+ /**
64
+ * Internal POA Bridge identifier.
65
+ * @deprecated This identifier is for internal use only and should not be used in client code.
66
+ * @internal
67
+ */
68
+ defuse_asset_identifier: string;
69
+ }[];
70
+ }>;
71
+ type DepositNetworkMemo = {
72
+ deposit_mode: "MEMO";
73
+ } | null;
74
+ type GetDepositAddressRequest = JSONRPCRequest<"deposit_address", {
75
+ account_id: string;
76
+ /** Chain is joined blockchain and network (e.g. eth:8453) */
77
+ chain: string;
78
+ /** Stellar blockchain specific */
79
+ deposit_mode?: "MEMO" | "SIMPLE";
80
+ }>;
81
+ type GetDepositAddressResponse = JSONRPCResponse<{
82
+ address: string;
83
+ chain: string;
84
+ /** Stellar blockchain specific */
85
+ memo?: string;
86
+ }>;
87
+ type DepositStatus = {
88
+ tx_hash: string;
89
+ chain: string;
90
+ defuse_asset_identifier: string;
91
+ near_token_id: string;
92
+ decimals: number;
93
+ amount: number;
94
+ account_id: string;
95
+ address: string;
96
+ status: "COMPLETED" | "PENDING" | "FAILED";
97
+ };
98
+ type GetDepositStatusRequest = JSONRPCRequest<"recent_deposits", {
99
+ account_id: string;
100
+ chain?: string;
101
+ }>;
102
+ type GetDepositStatusResponse = JSONRPCResponse<{
103
+ deposits: DepositStatus[];
104
+ }>;
105
+ type WithdrawalStatusRequest = JSONRPCRequest<"withdrawal_status", {
106
+ withdrawal_hash: string;
107
+ }>;
108
+ type WithdrawalStatusResponseOk = JSONRPCResponse<{
109
+ withdrawals: {
110
+ status: "COMPLETED" | "PENDING";
111
+ data: {
112
+ tx_hash: string;
113
+ transfer_tx_hash: string | null;
114
+ chain: string;
115
+ defuse_asset_identifier: string;
116
+ near_token_id: string;
117
+ decimals: number;
118
+ amount: number;
119
+ account_id: string;
120
+ address: string;
121
+ created: string;
122
+ };
123
+ }[];
124
+ }>;
125
+ type HotOmniWithdrawRequest = JSONRPCRequest<"hot_omni_withdraw", {
126
+ account_id: string;
127
+ tx_hash: string;
128
+ receiver: string;
129
+ chain_id: string;
130
+ }>;
131
+ type HotOmniWithdrawResponse = JSONRPCResponse<{
132
+ status: "COMPLETED" | "PENDING";
133
+ data: {
134
+ transfer_tx_hash: string | null;
135
+ };
136
+ }[]>;
137
+ type TokenBalances = {
138
+ symbol: string;
139
+ address: string;
140
+ nearAddress: string;
141
+ decimals: number;
142
+ totalSupply: string;
143
+ vaultBalance: string;
144
+ coldWalletBalance: string;
145
+ balanceOnDefuse: string;
146
+ };
147
+ type BridgeBalanceResponse = TokenBalances[];
148
+ type GetWithdrawalEstimateRequest = JSONRPCRequest<"withdrawal_estimate", {
149
+ token: string;
150
+ address: string;
151
+ chain: BlockchainEnum;
152
+ }>;
153
+ type WithdrawalEstimateResponse = {
154
+ token: BaseTokenInfo;
155
+ tokenAddress: string;
156
+ userAddress: string;
157
+ withdrawalFee: string;
158
+ withdrawalFeeDecimals: number;
159
+ };
160
+ //#endregion
161
+ export { BridgeBalanceResponse, DepositNetworkMemo, DepositStatus, GetDepositAddressRequest, GetDepositAddressResponse, GetDepositStatusRequest, GetDepositStatusResponse, GetSupportedTokensRequest, GetSupportedTokensResponse, GetWithdrawalEstimateRequest, HotOmniWithdrawRequest, HotOmniWithdrawResponse, JSONRPCErrorType, JSONRPCRequest, JSONRPCResponse, RequestConfig, TokenBalances, WithdrawalEstimateResponse, WithdrawalStatusRequest, WithdrawalStatusResponseOk };
@@ -0,0 +1,57 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_base = require('../errors/base.cjs');
3
+ const require_request = require('../errors/request.cjs');
4
+ const require_retry = require('../utils/retry.cjs');
5
+ const require_apis = require('./poaBridgeHttpClient/apis.cjs');
6
+ const require_withdrawal = require('./errors/withdrawal.cjs');
7
+ let _lifeomic_attempt = require("@lifeomic/attempt");
8
+
9
+ //#region src/poaBridge/waitForWithdrawalCompletion.ts
10
+ async function waitForWithdrawalCompletion({ txHash, withdrawalCriteria, signal, baseURL, retryOptions = require_retry.RETRY_CONFIGS.TWO_MINS_GRADUAL, logger }) {
11
+ return (0, _lifeomic_attempt.retry)(async () => {
12
+ const result = await require_apis.getWithdrawalStatus({ withdrawal_hash: txHash }, {
13
+ baseURL,
14
+ fetchOptions: { signal },
15
+ logger
16
+ });
17
+ const withdrawal = findMatchingWithdrawal(result.withdrawals, withdrawalCriteria);
18
+ if (withdrawal == null) throw new require_withdrawal.PoaWithdrawalInvariantError("POA Bridge didn't return withdrawal matching criteria", result, txHash, withdrawalCriteria);
19
+ if (withdrawal.status === "COMPLETED") {
20
+ if (withdrawal.data.transfer_tx_hash == null) throw new require_withdrawal.PoaWithdrawalInvariantError("POA Bridge didn't return transfer_tx_hash for COMPLETED withdrawal", result, txHash, withdrawalCriteria);
21
+ return {
22
+ destinationTxHash: withdrawal.data.transfer_tx_hash,
23
+ chain: withdrawal.data.chain
24
+ };
25
+ }
26
+ throw new require_withdrawal.PoaWithdrawalPendingError(result, txHash, withdrawalCriteria);
27
+ }, {
28
+ ...retryOptions,
29
+ handleError: (err, context) => {
30
+ if (isWithdrawalNotFound(err)) {
31
+ if (context.attemptsRemaining > 0) return;
32
+ throw new require_withdrawal.PoaWithdrawalNotFoundError(txHash, withdrawalCriteria, err);
33
+ }
34
+ if (err instanceof require_withdrawal.PoaWithdrawalPendingError && context.attemptsRemaining > 0) return;
35
+ if (err instanceof require_base.BaseError && err.walk((err$1) => err$1 instanceof require_request.HttpRequestError || err$1 instanceof require_request.TimeoutError || err$1 instanceof require_request.RpcRequestError)) return;
36
+ context.abort();
37
+ }
38
+ });
39
+ }
40
+ function isWithdrawalNotFound(err) {
41
+ return err instanceof require_request.RpcRequestError && err.details === "Withdrawals not found";
42
+ }
43
+ /**
44
+ * Finds a withdrawal matching the given criteria.
45
+ *
46
+ * NOTE: Currently only matches by assetId (near_token_id). This means multiple
47
+ * withdrawals of the same token in a single transaction are not supported.
48
+ * POA API doesn't currently support this case either. When support is added,
49
+ * matching could be done by sorting both API results and withdrawal params by
50
+ * amount (fees are equal for same token, so relative ordering is preserved).
51
+ */
52
+ function findMatchingWithdrawal(withdrawals, criteria) {
53
+ return withdrawals.find((w) => `nep141:${w.data.near_token_id}` === criteria.assetId);
54
+ }
55
+
56
+ //#endregion
57
+ exports.waitForWithdrawalCompletion = waitForWithdrawalCompletion;
@@ -0,0 +1,31 @@
1
+ import { ILogger } from "../logger.cjs";
2
+ import { RetryOptions } from "../utils/retry.cjs";
3
+ import { JSONRPCErrorType } from "./poaBridgeHttpClient/types.cjs";
4
+ import { PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingErrorType } from "./errors/withdrawal.cjs";
5
+
6
+ //#region src/poaBridge/waitForWithdrawalCompletion.d.ts
7
+ type WaitForWithdrawalCompletionOkType = {
8
+ destinationTxHash: string;
9
+ chain: string;
10
+ };
11
+ type WaitForWithdrawalCompletionErrorType = JSONRPCErrorType | PoaWithdrawalInvariantErrorType | PoaWithdrawalNotFoundErrorType | PoaWithdrawalPendingErrorType;
12
+ type WithdrawalCriteria = {
13
+ assetId: string;
14
+ };
15
+ declare function waitForWithdrawalCompletion({
16
+ txHash,
17
+ withdrawalCriteria,
18
+ signal,
19
+ baseURL,
20
+ retryOptions,
21
+ logger
22
+ }: {
23
+ txHash: string;
24
+ withdrawalCriteria: WithdrawalCriteria;
25
+ signal: AbortSignal;
26
+ baseURL?: string;
27
+ retryOptions?: RetryOptions;
28
+ logger?: ILogger;
29
+ }): Promise<WaitForWithdrawalCompletionOkType>;
30
+ //#endregion
31
+ export { WaitForWithdrawalCompletionErrorType, WaitForWithdrawalCompletionOkType, WithdrawalCriteria, waitForWithdrawalCompletion };
@@ -0,0 +1,31 @@
1
+ import { ILogger } from "../logger.js";
2
+ import { RetryOptions } from "../utils/retry.js";
3
+ import { JSONRPCErrorType } from "./poaBridgeHttpClient/types.js";
4
+ import { PoaWithdrawalInvariantErrorType, PoaWithdrawalNotFoundErrorType, PoaWithdrawalPendingErrorType } from "./errors/withdrawal.js";
5
+
6
+ //#region src/poaBridge/waitForWithdrawalCompletion.d.ts
7
+ type WaitForWithdrawalCompletionOkType = {
8
+ destinationTxHash: string;
9
+ chain: string;
10
+ };
11
+ type WaitForWithdrawalCompletionErrorType = JSONRPCErrorType | PoaWithdrawalInvariantErrorType | PoaWithdrawalNotFoundErrorType | PoaWithdrawalPendingErrorType;
12
+ type WithdrawalCriteria = {
13
+ assetId: string;
14
+ };
15
+ declare function waitForWithdrawalCompletion({
16
+ txHash,
17
+ withdrawalCriteria,
18
+ signal,
19
+ baseURL,
20
+ retryOptions,
21
+ logger
22
+ }: {
23
+ txHash: string;
24
+ withdrawalCriteria: WithdrawalCriteria;
25
+ signal: AbortSignal;
26
+ baseURL?: string;
27
+ retryOptions?: RetryOptions;
28
+ logger?: ILogger;
29
+ }): Promise<WaitForWithdrawalCompletionOkType>;
30
+ //#endregion
31
+ export { WaitForWithdrawalCompletionErrorType, WaitForWithdrawalCompletionOkType, WithdrawalCriteria, waitForWithdrawalCompletion };
@@ -0,0 +1,56 @@
1
+ import { BaseError } from "../errors/base.js";
2
+ import { HttpRequestError, RpcRequestError, TimeoutError } from "../errors/request.js";
3
+ import { RETRY_CONFIGS } from "../utils/retry.js";
4
+ import { getWithdrawalStatus } from "./poaBridgeHttpClient/apis.js";
5
+ import { PoaWithdrawalInvariantError, PoaWithdrawalNotFoundError, PoaWithdrawalPendingError } from "./errors/withdrawal.js";
6
+ import { retry } from "@lifeomic/attempt";
7
+
8
+ //#region src/poaBridge/waitForWithdrawalCompletion.ts
9
+ async function waitForWithdrawalCompletion({ txHash, withdrawalCriteria, signal, baseURL, retryOptions = RETRY_CONFIGS.TWO_MINS_GRADUAL, logger }) {
10
+ return retry(async () => {
11
+ const result = await getWithdrawalStatus({ withdrawal_hash: txHash }, {
12
+ baseURL,
13
+ fetchOptions: { signal },
14
+ logger
15
+ });
16
+ const withdrawal = findMatchingWithdrawal(result.withdrawals, withdrawalCriteria);
17
+ if (withdrawal == null) throw new PoaWithdrawalInvariantError("POA Bridge didn't return withdrawal matching criteria", result, txHash, withdrawalCriteria);
18
+ if (withdrawal.status === "COMPLETED") {
19
+ if (withdrawal.data.transfer_tx_hash == null) throw new PoaWithdrawalInvariantError("POA Bridge didn't return transfer_tx_hash for COMPLETED withdrawal", result, txHash, withdrawalCriteria);
20
+ return {
21
+ destinationTxHash: withdrawal.data.transfer_tx_hash,
22
+ chain: withdrawal.data.chain
23
+ };
24
+ }
25
+ throw new PoaWithdrawalPendingError(result, txHash, withdrawalCriteria);
26
+ }, {
27
+ ...retryOptions,
28
+ handleError: (err, context) => {
29
+ if (isWithdrawalNotFound(err)) {
30
+ if (context.attemptsRemaining > 0) return;
31
+ throw new PoaWithdrawalNotFoundError(txHash, withdrawalCriteria, err);
32
+ }
33
+ if (err instanceof PoaWithdrawalPendingError && context.attemptsRemaining > 0) return;
34
+ if (err instanceof BaseError && err.walk((err$1) => err$1 instanceof HttpRequestError || err$1 instanceof TimeoutError || err$1 instanceof RpcRequestError)) return;
35
+ context.abort();
36
+ }
37
+ });
38
+ }
39
+ function isWithdrawalNotFound(err) {
40
+ return err instanceof RpcRequestError && err.details === "Withdrawals not found";
41
+ }
42
+ /**
43
+ * Finds a withdrawal matching the given criteria.
44
+ *
45
+ * NOTE: Currently only matches by assetId (near_token_id). This means multiple
46
+ * withdrawals of the same token in a single transaction are not supported.
47
+ * POA API doesn't currently support this case either. When support is added,
48
+ * matching could be done by sorting both API results and withdrawal params by
49
+ * amount (fees are equal for same token, so relative ordering is preserved).
50
+ */
51
+ function findMatchingWithdrawal(withdrawals, criteria) {
52
+ return withdrawals.find((w) => `nep141:${w.data.near_token_id}` === criteria.assetId);
53
+ }
54
+
55
+ //#endregion
56
+ export { waitForWithdrawalCompletion };
@@ -0,0 +1,40 @@
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_near = require('../utils/near.cjs');
3
+ let valibot = require("valibot");
4
+ valibot = require_rolldown_runtime.__toESM(valibot);
5
+ let _scure_base = require("@scure/base");
6
+
7
+ //#region src/services/blockchainBalanceService.ts
8
+ const getNearNep141StorageBalance = async ({ contractId, accountId, nearProvider }) => {
9
+ try {
10
+ const args = { account_id: accountId };
11
+ const argsBase64 = _scure_base.base64.encode(new TextEncoder().encode(JSON.stringify(args)));
12
+ const parsed = require_near.decodeQueryResult(await nearProvider.query({
13
+ request_type: "call_function",
14
+ method_name: "storage_balance_of",
15
+ account_id: contractId,
16
+ args_base64: argsBase64,
17
+ finality: "optimistic"
18
+ }), valibot.union([valibot.null(), valibot.object({ total: valibot.string() })]));
19
+ return BigInt(parsed?.total || "0");
20
+ } catch (err) {
21
+ throw new Error("Error fetching balance", { cause: err });
22
+ }
23
+ };
24
+ const getNearNep141MinStorageBalance = async ({ contractId, nearProvider }) => {
25
+ const parsed = require_near.decodeQueryResult(await nearProvider.query({
26
+ request_type: "call_function",
27
+ method_name: "storage_balance_bounds",
28
+ account_id: contractId,
29
+ args_base64: _scure_base.base64.encode(new TextEncoder().encode(JSON.stringify({}))),
30
+ finality: "optimistic"
31
+ }), valibot.object({
32
+ min: valibot.string(),
33
+ max: valibot.string()
34
+ }));
35
+ return BigInt(parsed.min);
36
+ };
37
+
38
+ //#endregion
39
+ exports.getNearNep141MinStorageBalance = getNearNep141MinStorageBalance;
40
+ exports.getNearNep141StorageBalance = getNearNep141StorageBalance;
@@ -0,0 +1,21 @@
1
+ import { providers } from "near-api-js";
2
+
3
+ //#region src/services/blockchainBalanceService.d.ts
4
+ declare const getNearNep141StorageBalance: ({
5
+ contractId,
6
+ accountId,
7
+ nearProvider
8
+ }: {
9
+ contractId: string;
10
+ accountId: string;
11
+ nearProvider: providers.Provider;
12
+ }) => Promise<bigint>;
13
+ declare const getNearNep141MinStorageBalance: ({
14
+ contractId,
15
+ nearProvider
16
+ }: {
17
+ contractId: string;
18
+ nearProvider: providers.Provider;
19
+ }) => Promise<bigint>;
20
+ //#endregion
21
+ export { getNearNep141MinStorageBalance, getNearNep141StorageBalance };
@@ -0,0 +1,21 @@
1
+ import { providers } from "near-api-js";
2
+
3
+ //#region src/services/blockchainBalanceService.d.ts
4
+ declare const getNearNep141StorageBalance: ({
5
+ contractId,
6
+ accountId,
7
+ nearProvider
8
+ }: {
9
+ contractId: string;
10
+ accountId: string;
11
+ nearProvider: providers.Provider;
12
+ }) => Promise<bigint>;
13
+ declare const getNearNep141MinStorageBalance: ({
14
+ contractId,
15
+ nearProvider
16
+ }: {
17
+ contractId: string;
18
+ nearProvider: providers.Provider;
19
+ }) => Promise<bigint>;
20
+ //#endregion
21
+ export { getNearNep141MinStorageBalance, getNearNep141StorageBalance };
@@ -0,0 +1,37 @@
1
+ import { decodeQueryResult } from "../utils/near.js";
2
+ import * as v from "valibot";
3
+ import { base64 } from "@scure/base";
4
+
5
+ //#region src/services/blockchainBalanceService.ts
6
+ const getNearNep141StorageBalance = async ({ contractId, accountId, nearProvider }) => {
7
+ try {
8
+ const args = { account_id: accountId };
9
+ const argsBase64 = base64.encode(new TextEncoder().encode(JSON.stringify(args)));
10
+ const parsed = decodeQueryResult(await nearProvider.query({
11
+ request_type: "call_function",
12
+ method_name: "storage_balance_of",
13
+ account_id: contractId,
14
+ args_base64: argsBase64,
15
+ finality: "optimistic"
16
+ }), v.union([v.null(), v.object({ total: v.string() })]));
17
+ return BigInt(parsed?.total || "0");
18
+ } catch (err) {
19
+ throw new Error("Error fetching balance", { cause: err });
20
+ }
21
+ };
22
+ const getNearNep141MinStorageBalance = async ({ contractId, nearProvider }) => {
23
+ const parsed = decodeQueryResult(await nearProvider.query({
24
+ request_type: "call_function",
25
+ method_name: "storage_balance_bounds",
26
+ account_id: contractId,
27
+ args_base64: base64.encode(new TextEncoder().encode(JSON.stringify({}))),
28
+ finality: "optimistic"
29
+ }), v.object({
30
+ min: v.string(),
31
+ max: v.string()
32
+ }));
33
+ return BigInt(parsed.min);
34
+ };
35
+
36
+ //#endregion
37
+ export { getNearNep141MinStorageBalance, getNearNep141StorageBalance };