@hot-labs/kit 1.0.33

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 (300) hide show
  1. package/.eslintrc.cjs +11 -0
  2. package/.github/workflows/deploy-example.yml +55 -0
  3. package/.github/workflows/release.yml +74 -0
  4. package/.prettierrc +4 -0
  5. package/.prototools +2 -0
  6. package/.vscode/settings.json +3 -0
  7. package/CHANGELOG.md +1 -0
  8. package/README.md +67 -0
  9. package/build/GoogleConnector.d.ts +20 -0
  10. package/build/GoogleConnector.js +76 -0
  11. package/build/GoogleConnector.js.map +1 -0
  12. package/build/HotConnector.d.ts +91 -0
  13. package/build/HotConnector.js +285 -0
  14. package/build/HotConnector.js.map +1 -0
  15. package/build/OmniConnector.d.ts +95 -0
  16. package/build/OmniConnector.js +123 -0
  17. package/build/OmniConnector.js.map +1 -0
  18. package/build/OmniWallet.d.ts +57 -0
  19. package/build/OmniWallet.js +56 -0
  20. package/build/OmniWallet.js.map +1 -0
  21. package/build/cosmos/connector.d.ts +53 -0
  22. package/build/cosmos/connector.js +207 -0
  23. package/build/cosmos/connector.js.map +1 -0
  24. package/build/cosmos/wallet.d.ts +28 -0
  25. package/build/cosmos/wallet.js +59 -0
  26. package/build/cosmos/wallet.js.map +1 -0
  27. package/build/events.d.ts +42 -0
  28. package/build/events.js +64 -0
  29. package/build/events.js.map +1 -0
  30. package/build/evm/abi.d.ts +17 -0
  31. package/build/evm/abi.js +38 -0
  32. package/build/evm/abi.js.map +1 -0
  33. package/build/evm/connector.d.ts +35 -0
  34. package/build/evm/connector.js +124 -0
  35. package/build/evm/connector.js.map +1 -0
  36. package/build/evm/wallet.d.ts +47 -0
  37. package/build/evm/wallet.js +136 -0
  38. package/build/evm/wallet.js.map +1 -0
  39. package/build/exchange.d.ts +63 -0
  40. package/build/exchange.js +384 -0
  41. package/build/exchange.js.map +1 -0
  42. package/build/hot-wallet/evm.d.ts +1 -0
  43. package/build/hot-wallet/evm.js +33 -0
  44. package/build/hot-wallet/evm.js.map +1 -0
  45. package/build/hot-wallet/hot.d.ts +3 -0
  46. package/build/hot-wallet/hot.js +40 -0
  47. package/build/hot-wallet/hot.js.map +1 -0
  48. package/build/hot-wallet/index.d.ts +4 -0
  49. package/build/hot-wallet/index.js +5 -0
  50. package/build/hot-wallet/index.js.map +1 -0
  51. package/build/hot-wallet/solana/account.d.ts +11 -0
  52. package/build/hot-wallet/solana/account.js +42 -0
  53. package/build/hot-wallet/solana/account.js.map +1 -0
  54. package/build/hot-wallet/solana/index.d.ts +1 -0
  55. package/build/hot-wallet/solana/index.js +85 -0
  56. package/build/hot-wallet/solana/index.js.map +1 -0
  57. package/build/hot-wallet/solana/register.d.ts +2 -0
  58. package/build/hot-wallet/solana/register.js +41 -0
  59. package/build/hot-wallet/solana/register.js.map +1 -0
  60. package/build/hot-wallet/solana/solana-wallet.d.ts +34 -0
  61. package/build/hot-wallet/solana/solana-wallet.js +223 -0
  62. package/build/hot-wallet/solana/solana-wallet.js.map +1 -0
  63. package/build/hot-wallet/solana/utils.d.ts +32 -0
  64. package/build/hot-wallet/solana/utils.js +36 -0
  65. package/build/hot-wallet/solana/utils.js.map +1 -0
  66. package/build/hot-wallet/stellar.d.ts +38 -0
  67. package/build/hot-wallet/stellar.js +32 -0
  68. package/build/hot-wallet/stellar.js.map +1 -0
  69. package/build/hot-wallet/ton.d.ts +1 -0
  70. package/build/hot-wallet/ton.js +49 -0
  71. package/build/hot-wallet/ton.js.map +1 -0
  72. package/build/hot-wallet/wallet.d.ts +1 -0
  73. package/build/hot-wallet/wallet.js +40 -0
  74. package/build/hot-wallet/wallet.js.map +1 -0
  75. package/build/index.d.ts +24 -0
  76. package/build/index.js +25 -0
  77. package/build/index.js.map +1 -0
  78. package/build/near/connector.d.ts +28 -0
  79. package/build/near/connector.js +56 -0
  80. package/build/near/connector.js.map +1 -0
  81. package/build/near/wallet.d.ts +62 -0
  82. package/build/near/wallet.js +233 -0
  83. package/build/near/wallet.js.map +1 -0
  84. package/build/omni/Intents.d.ts +93 -0
  85. package/build/omni/Intents.js +395 -0
  86. package/build/omni/Intents.js.map +1 -0
  87. package/build/omni/bridge.d.ts +3 -0
  88. package/build/omni/bridge.js +34 -0
  89. package/build/omni/bridge.js.map +1 -0
  90. package/build/omni/config.d.ts +99 -0
  91. package/build/omni/config.js +126 -0
  92. package/build/omni/config.js.map +1 -0
  93. package/build/omni/defaultTokens.d.ts +17 -0
  94. package/build/omni/defaultTokens.js +1079 -0
  95. package/build/omni/defaultTokens.js.map +1 -0
  96. package/build/omni/index.d.ts +8 -0
  97. package/build/omni/index.js +9 -0
  98. package/build/omni/index.js.map +1 -0
  99. package/build/omni/nearRpc.d.ts +24 -0
  100. package/build/omni/nearRpc.js +167 -0
  101. package/build/omni/nearRpc.js.map +1 -0
  102. package/build/omni/recipient.d.ts +10 -0
  103. package/build/omni/recipient.js +40 -0
  104. package/build/omni/recipient.js.map +1 -0
  105. package/build/omni/token.d.ts +36 -0
  106. package/build/omni/token.js +136 -0
  107. package/build/omni/token.js.map +1 -0
  108. package/build/omni/tokens.d.ts +14 -0
  109. package/build/omni/tokens.js +57 -0
  110. package/build/omni/tokens.js.map +1 -0
  111. package/build/omni/types.d.ts +41 -0
  112. package/build/omni/types.js +2 -0
  113. package/build/omni/types.js.map +1 -0
  114. package/build/omni/utils.d.ts +24 -0
  115. package/build/omni/utils.js +150 -0
  116. package/build/omni/utils.js.map +1 -0
  117. package/build/settings.d.ts +5 -0
  118. package/build/settings.js +6 -0
  119. package/build/settings.js.map +1 -0
  120. package/build/solana/connector.d.ts +31 -0
  121. package/build/solana/connector.js +138 -0
  122. package/build/solana/connector.js.map +1 -0
  123. package/build/solana/protocol.d.ts +25 -0
  124. package/build/solana/protocol.js +56 -0
  125. package/build/solana/protocol.js.map +1 -0
  126. package/build/solana/wallet.d.ts +47 -0
  127. package/build/solana/wallet.js +188 -0
  128. package/build/solana/wallet.js.map +1 -0
  129. package/build/solana/wallets.d.ts +102 -0
  130. package/build/solana/wallets.js +150 -0
  131. package/build/solana/wallets.js.map +1 -0
  132. package/build/stellar/connector.d.ts +25 -0
  133. package/build/stellar/connector.js +56 -0
  134. package/build/stellar/connector.js.map +1 -0
  135. package/build/stellar/wallet.d.ts +70 -0
  136. package/build/stellar/wallet.js +225 -0
  137. package/build/stellar/wallet.js.map +1 -0
  138. package/build/storage.d.ts +10 -0
  139. package/build/storage.js +12 -0
  140. package/build/storage.js.map +1 -0
  141. package/build/ton/connector.d.ts +25 -0
  142. package/build/ton/connector.js +119 -0
  143. package/build/ton/connector.js.map +1 -0
  144. package/build/ton/utils.d.ts +45 -0
  145. package/build/ton/utils.js +64 -0
  146. package/build/ton/utils.js.map +1 -0
  147. package/build/ton/wallet.d.ts +70 -0
  148. package/build/ton/wallet.js +154 -0
  149. package/build/ton/wallet.js.map +1 -0
  150. package/build/ui/Popup.d.ts +10 -0
  151. package/build/ui/Popup.js +38 -0
  152. package/build/ui/Popup.js.map +1 -0
  153. package/build/ui/connect/AuthPopup.d.ts +2 -0
  154. package/build/ui/connect/AuthPopup.js +48 -0
  155. package/build/ui/connect/AuthPopup.js.map +1 -0
  156. package/build/ui/connect/ConnectWallet.d.ts +9 -0
  157. package/build/ui/connect/ConnectWallet.js +22 -0
  158. package/build/ui/connect/ConnectWallet.js.map +1 -0
  159. package/build/ui/connect/LogoutPopup.d.ts +10 -0
  160. package/build/ui/connect/LogoutPopup.js +8 -0
  161. package/build/ui/connect/LogoutPopup.js.map +1 -0
  162. package/build/ui/connect/WCPopup.d.ts +13 -0
  163. package/build/ui/connect/WCPopup.js +81 -0
  164. package/build/ui/connect/WCPopup.js.map +1 -0
  165. package/build/ui/connect/WCRequest.d.ts +9 -0
  166. package/build/ui/connect/WCRequest.js +13 -0
  167. package/build/ui/connect/WCRequest.js.map +1 -0
  168. package/build/ui/connect/WalletPicker.d.ts +11 -0
  169. package/build/ui/connect/WalletPicker.js +48 -0
  170. package/build/ui/connect/WalletPicker.js.map +1 -0
  171. package/build/ui/icons/arrow-right.d.ts +1 -0
  172. package/build/ui/icons/arrow-right.js +5 -0
  173. package/build/ui/icons/arrow-right.js.map +1 -0
  174. package/build/ui/icons/exchange.d.ts +6 -0
  175. package/build/ui/icons/exchange.js +6 -0
  176. package/build/ui/icons/exchange.js.map +1 -0
  177. package/build/ui/icons/logout.d.ts +1 -0
  178. package/build/ui/icons/logout.js +3 -0
  179. package/build/ui/icons/logout.js.map +1 -0
  180. package/build/ui/icons/pending.d.ts +1 -0
  181. package/build/ui/icons/pending.js +5 -0
  182. package/build/ui/icons/pending.js.map +1 -0
  183. package/build/ui/icons/qr.d.ts +1 -0
  184. package/build/ui/icons/qr.js +5 -0
  185. package/build/ui/icons/qr.js.map +1 -0
  186. package/build/ui/icons/search.d.ts +1 -0
  187. package/build/ui/icons/search.js +5 -0
  188. package/build/ui/icons/search.js.map +1 -0
  189. package/build/ui/icons/switch.d.ts +1 -0
  190. package/build/ui/icons/switch.js +5 -0
  191. package/build/ui/icons/switch.js.map +1 -0
  192. package/build/ui/icons/wallet.d.ts +1 -0
  193. package/build/ui/icons/wallet.js +5 -0
  194. package/build/ui/icons/wallet.js.map +1 -0
  195. package/build/ui/payment/Bridge.d.ts +27 -0
  196. package/build/ui/payment/Bridge.js +340 -0
  197. package/build/ui/payment/Bridge.js.map +1 -0
  198. package/build/ui/payment/DepositQR.d.ts +9 -0
  199. package/build/ui/payment/DepositQR.js +56 -0
  200. package/build/ui/payment/DepositQR.js.map +1 -0
  201. package/build/ui/payment/Payment.d.ts +16 -0
  202. package/build/ui/payment/Payment.js +50 -0
  203. package/build/ui/payment/Payment.js.map +1 -0
  204. package/build/ui/payment/Profile.d.ts +7 -0
  205. package/build/ui/payment/Profile.js +88 -0
  206. package/build/ui/payment/Profile.js.map +1 -0
  207. package/build/ui/payment/SelectRecipient.d.ts +14 -0
  208. package/build/ui/payment/SelectRecipient.js +68 -0
  209. package/build/ui/payment/SelectRecipient.js.map +1 -0
  210. package/build/ui/payment/SelectSender.d.ts +13 -0
  211. package/build/ui/payment/SelectSender.js +23 -0
  212. package/build/ui/payment/SelectSender.js.map +1 -0
  213. package/build/ui/payment/SelectToken.d.ts +13 -0
  214. package/build/ui/payment/SelectToken.js +92 -0
  215. package/build/ui/payment/SelectToken.js.map +1 -0
  216. package/build/ui/payment/TokenCard.d.ts +23 -0
  217. package/build/ui/payment/TokenCard.js +50 -0
  218. package/build/ui/payment/TokenCard.js.map +1 -0
  219. package/build/ui/router.d.ts +37 -0
  220. package/build/ui/router.js +56 -0
  221. package/build/ui/router.js.map +1 -0
  222. package/build/ui/styles.d.ts +11 -0
  223. package/build/ui/styles.js +273 -0
  224. package/build/ui/styles.js.map +1 -0
  225. package/package.json +60 -0
  226. package/skill.md +989 -0
  227. package/src/GoogleConnector.ts +102 -0
  228. package/src/HotConnector.ts +344 -0
  229. package/src/OmniConnector.ts +161 -0
  230. package/src/OmniWallet.ts +94 -0
  231. package/src/cosmos/connector.ts +242 -0
  232. package/src/cosmos/wallet.ts +77 -0
  233. package/src/events.ts +66 -0
  234. package/src/evm/abi.ts +39 -0
  235. package/src/evm/connector.ts +139 -0
  236. package/src/evm/wallet.ts +156 -0
  237. package/src/exchange.ts +426 -0
  238. package/src/hot-wallet/evm.ts +38 -0
  239. package/src/hot-wallet/hot.ts +39 -0
  240. package/src/hot-wallet/index.ts +4 -0
  241. package/src/hot-wallet/solana/account.ts +52 -0
  242. package/src/hot-wallet/solana/index.ts +98 -0
  243. package/src/hot-wallet/solana/register.ts +48 -0
  244. package/src/hot-wallet/solana/solana-wallet.ts +280 -0
  245. package/src/hot-wallet/solana/utils.ts +56 -0
  246. package/src/hot-wallet/stellar.ts +39 -0
  247. package/src/hot-wallet/ton.ts +56 -0
  248. package/src/hot-wallet/wallet.ts +44 -0
  249. package/src/index.ts +30 -0
  250. package/src/near/connector.ts +71 -0
  251. package/src/near/wallet.ts +255 -0
  252. package/src/omni/Intents.ts +454 -0
  253. package/src/omni/bridge.ts +38 -0
  254. package/src/omni/config.ts +130 -0
  255. package/src/omni/defaultTokens.ts +1078 -0
  256. package/src/omni/index.ts +8 -0
  257. package/src/omni/nearRpc.ts +187 -0
  258. package/src/omni/recipient.ts +41 -0
  259. package/src/omni/token.ts +125 -0
  260. package/src/omni/tokens.ts +68 -0
  261. package/src/omni/types.ts +46 -0
  262. package/src/omni/utils.ts +163 -0
  263. package/src/settings.ts +5 -0
  264. package/src/solana/connector.ts +151 -0
  265. package/src/solana/protocol.ts +66 -0
  266. package/src/solana/wallet.ts +230 -0
  267. package/src/solana/wallets.ts +243 -0
  268. package/src/stellar/connector.ts +69 -0
  269. package/src/stellar/wallet.ts +267 -0
  270. package/src/storage.ts +19 -0
  271. package/src/ton/connector.ts +138 -0
  272. package/src/ton/utils.ts +73 -0
  273. package/src/ton/wallet.ts +178 -0
  274. package/src/ui/Popup.tsx +62 -0
  275. package/src/ui/connect/AuthPopup.tsx +78 -0
  276. package/src/ui/connect/ConnectWallet.tsx +63 -0
  277. package/src/ui/connect/LogoutPopup.tsx +20 -0
  278. package/src/ui/connect/WCPopup.tsx +122 -0
  279. package/src/ui/connect/WCRequest.tsx +28 -0
  280. package/src/ui/connect/WalletPicker.tsx +92 -0
  281. package/src/ui/icons/arrow-right.tsx +8 -0
  282. package/src/ui/icons/exchange.tsx +17 -0
  283. package/src/ui/icons/logout.tsx +18 -0
  284. package/src/ui/icons/pending.tsx +18 -0
  285. package/src/ui/icons/qr.tsx +12 -0
  286. package/src/ui/icons/search.tsx +18 -0
  287. package/src/ui/icons/switch.tsx +10 -0
  288. package/src/ui/icons/wallet.tsx +18 -0
  289. package/src/ui/payment/Bridge.tsx +582 -0
  290. package/src/ui/payment/DepositQR.tsx +88 -0
  291. package/src/ui/payment/Payment.tsx +78 -0
  292. package/src/ui/payment/Profile.tsx +140 -0
  293. package/src/ui/payment/SelectRecipient.tsx +111 -0
  294. package/src/ui/payment/SelectSender.tsx +60 -0
  295. package/src/ui/payment/SelectToken.tsx +134 -0
  296. package/src/ui/payment/TokenCard.tsx +83 -0
  297. package/src/ui/router.tsx +92 -0
  298. package/src/ui/styles.ts +284 -0
  299. package/tsconfig.json +22 -0
  300. package/vite.config.ts +17 -0
@@ -0,0 +1,8 @@
1
+ export { OmniToken, WalletType, Network, chainsMap, reverseChainsMap } from "./config";
2
+ export { Intents } from "./Intents";
3
+ export { Token } from "./token";
4
+ export { tokens } from "./tokens";
5
+ export { bridge } from "./bridge";
6
+ export { Recipient } from "./recipient";
7
+ export { formatter } from "./utils";
8
+ export * from "./types";
@@ -0,0 +1,187 @@
1
+ import { JsonRpcProvider } from "@near-js/providers";
2
+ import { getErrorTypeFromErrorMessage, parseRpcError } from "@near-js/utils";
3
+ import { TypedError, FinalExecutionOutcome } from "@near-js/types";
4
+
5
+ let _nextId = 123;
6
+
7
+ export const TGAS = 1_000_000_000_000n;
8
+
9
+ class NetworkError extends Error {
10
+ constructor(status: number, title: string, message: string) {
11
+ super(`${status} ${title}: ${message}`);
12
+ }
13
+ }
14
+
15
+ class TimeoutNetworkError extends NetworkError {
16
+ constructor(title: string) {
17
+ super(0, title, "Timeout error");
18
+ }
19
+ }
20
+
21
+ const wait = (timeout: number) => {
22
+ return new Promise<void>((resolve) => setTimeout(resolve, timeout));
23
+ };
24
+
25
+ const c1 = Math.random() > 0.5;
26
+ export const rpcProviders = [
27
+ c1 ? "https://c1.rpc.fastnear.com" : "https://c2.rpc.fastnear.com",
28
+ c1 ? "https://c2.rpc.fastnear.com" : "https://c1.rpc.fastnear.com",
29
+ "https://relmn.aurora.dev",
30
+ "https://nearrpc.aurora.dev",
31
+ "https://archival-rpc.mainnet.near.org",
32
+ ];
33
+
34
+ export class NearRpc extends JsonRpcProvider {
35
+ public providers: string[];
36
+ public currentProviderIndex = 0;
37
+ public startTimeout;
38
+
39
+ constructor(providers = rpcProviders, private timeout = 30_000, private triesCountForEveryProvider = 3, private incrementTimout = true) {
40
+ super({ url: "" });
41
+ this.currentProviderIndex = 0;
42
+ this.providers = providers;
43
+ this.startTimeout = timeout;
44
+ }
45
+
46
+ async viewMethod(args: { contractId: string; methodName: string; args: any }) {
47
+ const payload = Buffer.from(JSON.stringify(args.args), "utf8").toString("base64");
48
+ const data: any = await rpc.query({
49
+ args_base64: payload,
50
+ finality: "optimistic",
51
+ request_type: "call_function",
52
+ method_name: args.methodName,
53
+ account_id: args.contractId,
54
+ });
55
+
56
+ return JSON.parse(Buffer.from(data.result).toString("utf8"));
57
+ }
58
+
59
+ async sendJsonRpc<T>(method: string, params: any, attempts = 0): Promise<T> {
60
+ const url = this.providers[this.currentProviderIndex];
61
+ const requestStart = Date.now();
62
+
63
+ try {
64
+ const result = await this.send<T>(method, params, url, this.timeout);
65
+ this.timeout = Math.max(this.startTimeout, this.timeout / 1.2);
66
+ return result;
67
+ } catch (error: any) {
68
+ if (error instanceof TimeoutNetworkError && this.incrementTimout) {
69
+ this.timeout = Math.min(60_000, this.timeout * 1.2);
70
+ }
71
+
72
+ if (error instanceof NetworkError) {
73
+ this.currentProviderIndex += 1;
74
+ if (this.providers[this.currentProviderIndex] == null) {
75
+ this.currentProviderIndex = 0;
76
+ }
77
+ if (attempts + 1 > this.providers.length * this.triesCountForEveryProvider) {
78
+ throw error;
79
+ }
80
+
81
+ const needTime = 500 * attempts;
82
+ const spent = Date.now() - requestStart;
83
+
84
+ if (spent < needTime) {
85
+ await wait(needTime - spent);
86
+ }
87
+ return await this.sendJsonRpc(method, params, attempts + 1);
88
+ }
89
+
90
+ throw error;
91
+ }
92
+ }
93
+
94
+ async send<T>(method: string, params: any, url: string, timeout: number): Promise<T> {
95
+ const controller = new AbortController();
96
+ const timer = setTimeout(() => controller.abort(), timeout);
97
+
98
+ const req = await fetch(url, {
99
+ body: JSON.stringify({ method, params, id: _nextId++, jsonrpc: "2.0" }),
100
+ headers: { "Content-Type": "application/json" },
101
+ signal: controller.signal,
102
+ method: "POST",
103
+ }).catch(() => {
104
+ clearInterval(timer);
105
+ if (controller.signal.aborted) {
106
+ throw new TimeoutNetworkError("RPC Network Error");
107
+ }
108
+ if (!window.navigator.onLine) {
109
+ throw new NetworkError(0, "RPC Network Error", "No internet connection");
110
+ }
111
+ throw new NetworkError(0, "RPC Network Error", "Unknown Near RPC Error, maybe connection unstable, try VPN");
112
+ });
113
+
114
+ clearInterval(timer);
115
+ if (!req.ok) {
116
+ const text = await req.text().catch(() => "Unknown error");
117
+ throw new NetworkError(req.status, "RPC Network Error", text);
118
+ }
119
+
120
+ const response = await req.json();
121
+
122
+ if (response.error) {
123
+ if (typeof response.error.data === "object") {
124
+ const isReadable = typeof response.error.data.error_message === "string" && typeof response.error.data.error_type === "string";
125
+ if (isReadable) {
126
+ throw new TypedError(response.error.data.error_message, response.error.data.error_type);
127
+ }
128
+ throw parseRpcError(response.error.data);
129
+ }
130
+
131
+ // NOTE: All this hackery is happening because structured errors not implemented
132
+ // TODO: Fix when https://github.com/nearprotocol/nearcore/issues/1839 gets resolved
133
+ const errorMessage = `[${response.error.code}] ${response.error.message}: ${response.error.data}`;
134
+ const isTimeout = response.error.data === "Timeout" || errorMessage.includes("Timeout error") || errorMessage.includes("query has timed out");
135
+
136
+ if (isTimeout) {
137
+ throw new TypedError(errorMessage, "TimeoutError");
138
+ }
139
+ const type = getErrorTypeFromErrorMessage(response.error.data, response.error.name);
140
+ throw new TypedError(errorMessage, type);
141
+ }
142
+
143
+ return response.result;
144
+ }
145
+
146
+ async hasNearAccount(accountId: string): Promise<boolean> {
147
+ const keys = await rpc.viewAccessKeyList(accountId);
148
+ return keys.keys.length > 0;
149
+ }
150
+
151
+ parseReceipts = (logs: FinalExecutionOutcome) => {
152
+ const errors: any[] = [];
153
+
154
+ logs.receipts_outcome?.forEach((t) => {
155
+ const status = t.outcome.status;
156
+ if (typeof status === "string" && status === "Failure") errors.push(status);
157
+ else if (typeof status === "object" && "Failure" in status) errors.push(status.Failure);
158
+ });
159
+
160
+ if (errors.length > 0) {
161
+ const ExecutionError = errors[0]?.ActionError?.kind?.FunctionCallError?.ExecutionError;
162
+ if (ExecutionError) throw ExecutionError;
163
+ const err = JSON.stringify(errors, null, 2);
164
+ throw new Error(err);
165
+ }
166
+
167
+ return logs;
168
+ };
169
+
170
+ waitTransactionResult = async (txHash: string, accountId: string, attemps = 0, signal?: AbortSignal, total = 30): Promise<FinalExecutionOutcome> => {
171
+ if (signal?.aborted) throw new Error("Aborted");
172
+ if (attemps > total) throw new Error("Transaction not found");
173
+
174
+ const options = { tx_hash: txHash, sender_account_id: accountId, wait_until: "EXECUTED" };
175
+ const logs: any = await rpc.sendJsonRpc("EXPERIMENTAL_tx_status", options).catch(() => null);
176
+ if (signal?.aborted) throw new Error("Aborted");
177
+
178
+ if (logs == null || logs.status === "NotStarted" || logs.transaction == null) {
179
+ await new Promise((resolve) => setTimeout(resolve, 1000));
180
+ return await this.waitTransactionResult(txHash, accountId, attemps + 1, signal);
181
+ }
182
+
183
+ return this.parseReceipts(logs);
184
+ };
185
+ }
186
+
187
+ export const rpc = new NearRpc();
@@ -0,0 +1,41 @@
1
+ import { Address } from "@ton/core";
2
+ import { hex, base32, base58 } from "@scure/base";
3
+
4
+ import { type OmniWallet } from "../OmniWallet";
5
+ import { tonApi } from "../ton/utils";
6
+ import { WalletType } from "./config";
7
+
8
+ export class Recipient {
9
+ constructor(readonly type: WalletType, readonly address: string, readonly omniAddress: string) {}
10
+
11
+ static fromWallet(wallet?: OmniWallet) {
12
+ if (!wallet) return undefined;
13
+ return new Recipient(wallet.type, wallet.address, wallet.omniAddress);
14
+ }
15
+
16
+ static async fromAddress(type: WalletType, address: string) {
17
+ if (type === WalletType.TON) {
18
+ const data = await tonApi.accounts.getAccountPublicKey(Address.parse(address));
19
+ return new Recipient(WalletType.TON, address, data.publicKey.toLowerCase());
20
+ }
21
+
22
+ if (type === WalletType.EVM) {
23
+ return new Recipient(WalletType.EVM, address, address.toLowerCase());
24
+ }
25
+
26
+ if (type === WalletType.NEAR) {
27
+ return new Recipient(WalletType.NEAR, address, address.toLowerCase());
28
+ }
29
+
30
+ if (type === WalletType.STELLAR) {
31
+ const payload = base32.decode(address);
32
+ return new Recipient(WalletType.STELLAR, address, hex.encode(payload.slice(1, -2)).toLowerCase());
33
+ }
34
+
35
+ if (type === WalletType.SOLANA) {
36
+ return new Recipient(WalletType.SOLANA, address, hex.encode(base58.decode(address)).toLowerCase());
37
+ }
38
+
39
+ return new Recipient(type, address, "");
40
+ }
41
+ }
@@ -0,0 +1,125 @@
1
+ import { TokenResponse } from "@defuse-protocol/one-click-sdk-typescript";
2
+ import { Asset, Networks } from "@stellar/stellar-base";
3
+
4
+ import { Network, OmniToken, WalletType, chainsMap, reverseChainsMap } from "./config";
5
+ import { formatter } from "./utils";
6
+
7
+ export interface IToken {
8
+ chain: number;
9
+ address: string;
10
+ decimals: number;
11
+ symbol: string;
12
+ }
13
+
14
+ export class Token {
15
+ chain: number;
16
+ address: string;
17
+ decimals: number;
18
+ symbol: string;
19
+ usd: number;
20
+ omniAddress: string;
21
+ originalChain: number;
22
+ originalAddress: string;
23
+ originalChainSymbol: string;
24
+
25
+ constructor(readonly info: TokenResponse & { omni?: true }) {
26
+ this.originalChainSymbol = info.blockchain;
27
+ this.originalChain = reverseChainsMap[info.blockchain];
28
+ this.chain = info.omni ? -4 : reverseChainsMap[info.blockchain];
29
+
30
+ if (this.chain === Network.Near) {
31
+ this.address = info.contractAddress === "wrap.near" ? "native" : info.contractAddress || "native";
32
+ this.originalAddress = this.address;
33
+ } else if (this.chain === Network.Stellar) {
34
+ this.address = info.contractAddress ? new Asset(info.symbol, info.contractAddress).contractId(Networks.PUBLIC) : "native";
35
+ this.originalAddress = this.address;
36
+ } else {
37
+ this.address = info.omni ? info.assetId : info.contractAddress || "native";
38
+ this.originalAddress = info.contractAddress || "native";
39
+ }
40
+
41
+ this.decimals = info.decimals;
42
+ this.symbol = info.symbol === "wNEAR" ? "NEAR" : info.symbol;
43
+ this.usd = info.price;
44
+ this.omniAddress = info.assetId;
45
+ }
46
+
47
+ get chainIcon() {
48
+ return chainsMap[this.chain]?.logo || `https://storage.herewallet.app/ft/${this.chain}:native.png`;
49
+ }
50
+
51
+ get originalChainIcon() {
52
+ if (this.originalChain === Network.Juno) return "https://legacy.cosmos.network/presskit/cosmos-brandmark-dynamic-dark.svg";
53
+ return `https://storage.herewallet.app/ft/${this.originalChain}:native.png`;
54
+ }
55
+
56
+ get chainName() {
57
+ return chainsMap[this.chain]?.name || this.originalChainSymbol;
58
+ }
59
+
60
+ get id() {
61
+ return `${this.chain}:${this.address}`;
62
+ }
63
+
64
+ get isMainOmni() {
65
+ if (this.chain !== Network.Hot) return false;
66
+ return Object.values(OmniToken).some((token) => this.address === token);
67
+ }
68
+
69
+ get type() {
70
+ if (this.chain === Network.Hot) return WalletType.OMNI;
71
+ if (this.chain === Network.Near) return WalletType.NEAR;
72
+ if (this.chain === Network.Solana) return WalletType.SOLANA;
73
+ if (this.chain === Network.OmniTon) return WalletType.TON;
74
+ if (this.chain === Network.Ton) return WalletType.TON;
75
+ if (this.chain === Network.Stellar) return WalletType.STELLAR;
76
+ if (this.chain === Network.Juno) return WalletType.COSMOS;
77
+ if (this.chain === Network.Gonka) return WalletType.COSMOS;
78
+ if (this.chain === Network.Btc) return WalletType.Btc;
79
+ if (this.chain === Network.Tron) return WalletType.Tron;
80
+ if (this.chain === Network.Zcash) return WalletType.Zcash;
81
+ if (this.chain === Network.Xrp) return WalletType.Xrp;
82
+ if (this.chain === Network.Doge) return WalletType.Doge;
83
+ if (this.chain === Network.Ada) return WalletType.Ada;
84
+ if (this.chain === Network.Aptos) return WalletType.Aptos;
85
+ if (this.chain === Network.Sui) return WalletType.Sui;
86
+ if (this.chain === Network.Litecoin) return WalletType.Litecoin;
87
+ if (this.chain === Network.Cardano) return WalletType.Cardano;
88
+ if (this.chain > 0) return WalletType.EVM;
89
+ return WalletType.unknown;
90
+ }
91
+
92
+ get reserve() {
93
+ if (this.chain === Network.Gonka) return 0.001;
94
+ if (this.chain === Network.Juno) return 0.001;
95
+
96
+ if (this.address !== "native") return 0;
97
+ if (this.chain === Network.Hot) return 0;
98
+ if (this.chain === Network.Ton) return 0.01;
99
+ if (this.chain === Network.Stellar) return 0;
100
+ if (this.chain === Network.Solana) return 0.001;
101
+ if (this.chain === Network.Near) return 0.01;
102
+ if (this.usd === 0) return 0;
103
+
104
+ if (this.chain === Network.Eth) return 2 / this.usd;
105
+ return 0.1 / this.usd;
106
+ }
107
+
108
+ get icon() {
109
+ if (this.chain === Network.Hot) return `https://storage.herewallet.app/ft/${this.originalChain}:${this.originalAddress.toLowerCase()}.png`;
110
+ return `https://storage.herewallet.app/ft/${this.id.toLowerCase()}.png`;
111
+ }
112
+
113
+ float(t: number | bigint | string) {
114
+ return formatter.formatAmount(t, this.decimals);
115
+ }
116
+
117
+ int(t: number | bigint | string) {
118
+ return BigInt(formatter.parseAmount(t.toString(), this.decimals));
119
+ }
120
+
121
+ readable(t: number | bigint | string, rate = 1) {
122
+ const n = typeof t === "number" ? t : formatter.formatAmount(t ?? 0, this.decimals);
123
+ return formatter.amount(n * rate);
124
+ }
125
+ }
@@ -0,0 +1,68 @@
1
+ import { makeObservable, observable, runInAction } from "mobx";
2
+
3
+ import { OneClickService } from "@defuse-protocol/one-click-sdk-typescript";
4
+ import { defaultTokens } from "./defaultTokens";
5
+ import { Network, OmniToken } from "./config";
6
+ import { Token } from "./token";
7
+
8
+ class TokensStorage {
9
+ public list = defaultTokens.flatMap((t: any) => [new Token(t), new Token({ ...t, omni: true })]);
10
+ private initialTokensLoader = this.refreshTokens().catch(() => {});
11
+
12
+ constructor() {
13
+ makeObservable(this, {
14
+ list: observable,
15
+ });
16
+ }
17
+
18
+ get(id: OmniToken | string, chain = Network.Hot): Token {
19
+ return this.list.find((t) => t.chain === chain && t.address === id)!;
20
+ }
21
+
22
+ async getToken(chain: number, address: string): Promise<Token> {
23
+ const tokens = await this.getTokens();
24
+ return tokens.find((t) => t.chain === chain && t.address === address)!;
25
+ }
26
+
27
+ async startTokenPolling() {
28
+ await new Promise((resolve) => setTimeout(resolve, 10_000));
29
+ await this.refreshTokens().catch(() => {});
30
+ await this.startTokenPolling();
31
+ }
32
+
33
+ async refreshTokens() {
34
+ await this.initialTokensLoader;
35
+ const list = await OneClickService.getTokens();
36
+ list.unshift({
37
+ blockchain: "gonka-mainnet" as any,
38
+ priceUpdatedAt: "2025-11-23T18:01:00.349Z",
39
+ assetId: OmniToken.GONKA,
40
+ contractAddress: "ngonka",
41
+ symbol: "GNK",
42
+ decimals: 9,
43
+ price: 0,
44
+ });
45
+
46
+ list.unshift({
47
+ blockchain: "adi" as any,
48
+ priceUpdatedAt: "2025-11-23T18:01:00.349Z",
49
+ assetId: OmniToken.ADI,
50
+ symbol: "ADI",
51
+ decimals: 18,
52
+ price: 0,
53
+ });
54
+
55
+ runInAction(() => {
56
+ this.list = list.flatMap((t) => [new Token(t), new Token({ ...t, omni: true })]);
57
+ });
58
+
59
+ return this.list;
60
+ }
61
+
62
+ async getTokens(): Promise<Token[]> {
63
+ await this.initialTokensLoader;
64
+ return this.list;
65
+ }
66
+ }
67
+
68
+ export const tokens = new TokensStorage();
@@ -0,0 +1,46 @@
1
+ export interface TransferIntent {
2
+ intent: "transfer";
3
+ tokens: Record<string, string>;
4
+ receiver_id: string;
5
+ msg?: string;
6
+ min_gas?: string;
7
+ }
8
+
9
+ export interface TokenDiffIntent {
10
+ intent: "token_diff";
11
+ diff: Record<string, string>;
12
+ }
13
+
14
+ export interface MtWithdrawIntent {
15
+ intent: "mt_withdraw";
16
+ amounts: string[];
17
+ receiver_id: string;
18
+ token_ids: string[];
19
+ token: string;
20
+ memo?: string;
21
+ msg?: string;
22
+ min_gas?: string;
23
+ }
24
+
25
+ export interface FtWithdrawIntent {
26
+ intent: "ft_withdraw";
27
+ memo?: string;
28
+ receiver_id: string;
29
+ token: string;
30
+ amount: string;
31
+ msg?: string;
32
+ }
33
+
34
+ export interface AuthCallIntent {
35
+ min_gas: string;
36
+ attached_deposit: string;
37
+ contract_id: string;
38
+ msg: string;
39
+ intent: "auth_call";
40
+ }
41
+
42
+ export interface Commitment {
43
+ deadline: string;
44
+ signer_id: string;
45
+ intents: TransferIntent | MtWithdrawIntent | FtWithdrawIntent | TokenDiffIntent | AuthCallIntent[];
46
+ }
@@ -0,0 +1,163 @@
1
+ type Value = number | bigint | string;
2
+ export const formatter = {
3
+ toReadableNumber(decimals: number | bigint, number: bigint | string = "0"): string {
4
+ number = number.toString();
5
+ if (!decimals) return number;
6
+
7
+ decimals = Number(decimals);
8
+ const wholeStr = number.substring(0, number.length - decimals) || "0";
9
+ const fractionStr = number
10
+ .substring(number.length - decimals)
11
+ .padStart(decimals, "0")
12
+ .substring(0, decimals);
13
+
14
+ return `${wholeStr}.${fractionStr}`.replace(/\.?0+$/, "");
15
+ },
16
+
17
+ truncateAddress(address: string, length = 16) {
18
+ return address.length > length ? `${address.slice(0, length / 2)}...${address.slice(-length / 2)}` : address;
19
+ },
20
+
21
+ toNonDivisibleNumber(decimals: number | bigint, number: string): string {
22
+ if (decimals === null || decimals === undefined) return number;
23
+ decimals = Number(decimals);
24
+ const [wholePart, fracPart = ""] = number.includes("e") ? Number(number).toFixed(24).split(".") : number.split(".");
25
+ return `${wholePart}${fracPart.padEnd(decimals, "0").slice(0, decimals)}`.replace(/^0+/, "").padStart(1, "0");
26
+ },
27
+
28
+ formatAmount(n: number | string | bigint, d: number, r?: number) {
29
+ const int = formatter.toReadableNumber(d, n?.toString() || "0");
30
+ return r ? formatter.round(int, r) : +int;
31
+ },
32
+
33
+ parseAmount(n: string | number | bigint, d: number) {
34
+ return formatter.toNonDivisibleNumber(d, (n || 0).toString());
35
+ },
36
+
37
+ bigIntMax(...args: bigint[]) {
38
+ return args.reduce((m, e) => (e > m ? e : m));
39
+ },
40
+
41
+ bigIntMin(...args: bigint[]) {
42
+ return args.reduce((m, e) => (e < m ? e : m));
43
+ },
44
+
45
+ formatNumberWithSubscriptZeros(numberStr: string, presiction = 3, min = 0.000_01): string {
46
+ const number = Number.parseFloat(numberStr);
47
+ if (!numberStr.startsWith("0.")) return String(+number.toFixed(presiction));
48
+
49
+ const leadingZerosMatch = numberStr.match(/^0\.(0+)/);
50
+ if (!leadingZerosMatch) return String(+number.toFixed(presiction));
51
+
52
+ const leadingZerosCount = leadingZerosMatch[1].length;
53
+ if (leadingZerosCount > 2) {
54
+ const remainingDigits = numberStr.slice(leadingZerosMatch[0].length);
55
+ const smallCount = String(leadingZerosCount)
56
+ .split("")
57
+ .map((digit) => String.fromCharCode(8320 + Number.parseInt(digit)))
58
+ .join("");
59
+
60
+ return `0.0${smallCount}${remainingDigits.slice(0, presiction)}`;
61
+ }
62
+
63
+ return String(+number.toFixed(presiction));
64
+ },
65
+
66
+ formatNumberWithZeros(numberStr: Value, presiction = 3, min = 0.000_01): string {
67
+ const number = Number.parseFloat(numberStr.toString());
68
+ numberStr = formatter.fixed(numberStr, 24);
69
+
70
+ if (number >= min) {
71
+ const [part0, part1] = numberStr.split(".");
72
+ if (part1) {
73
+ const leadingZeros = part1?.match?.(/^0+/)?.[0] || "";
74
+ return `${part0}.${leadingZeros}${part1.replace(leadingZeros, "").slice(0, presiction)}`;
75
+ }
76
+ return part1 ? [part0, part1.slice(0, presiction)].join(".") : part0;
77
+ }
78
+
79
+ const leadingZerosMatch = numberStr.match(/^0\.(0+)/);
80
+ if (!leadingZerosMatch) return numberStr;
81
+
82
+ const remainingDigits = numberStr.slice(leadingZerosMatch[0].length);
83
+ return `0.0${leadingZerosMatch[1] || ""}${remainingDigits.slice(0, presiction)}`;
84
+ },
85
+
86
+ isBig(n: number) {
87
+ return formatter.readableBigParts(n)[1] !== "";
88
+ },
89
+
90
+ round(value: Value, dec = 2) {
91
+ const decimal = Math.pow(10, dec);
92
+ return Math.floor(formatter.num(value) * decimal) / decimal;
93
+ },
94
+
95
+ readableBig(n: number) {
96
+ if (n < 10_000) return formatter.amount(n);
97
+ if (n < 1_000_000) return `${formatter.round(n / 1000, 2)}K`;
98
+ if (n < 1_000_000_000) return `${formatter.round(n / 1_000_000, 2)}M`;
99
+ if (n < 1_000_000_000_000) return `${formatter.round(n / 1_000_000_000, 2)}B`;
100
+ if (n < 1_000_000_000_000_000) return `${formatter.round(n / 1_000_000_000_000, 2)}T`;
101
+ return `${formatter.round(n / 1_000_000_000_000_000, 2)}Q`;
102
+ },
103
+
104
+ readableBigParts(n: number): [number, string] {
105
+ if (n < 10_000) return [formatter.round(n, 4), ""];
106
+ if (n < 1_000_000) return [formatter.round(n / 1000, 2), "K"];
107
+ if (n < 1_000_000_000_000) return [formatter.round(n / 1_000_000, 2), "M"];
108
+ return [formatter.round(n / 1_000_000_000, 2), "B"];
109
+ },
110
+ formatNumber(num: string) {
111
+ let useDelimeter = false;
112
+ let right = "";
113
+ let left = "";
114
+
115
+ if (num.startsWith("0") && num.length > 1 && !num.startsWith("0.")) {
116
+ num = num.slice(1);
117
+ }
118
+
119
+ const chars = num.split("");
120
+ chars.forEach((char) => {
121
+ const isNumber = char >= "0" && char <= "9";
122
+ if (isNumber && useDelimeter) right += char;
123
+ else if (isNumber && !useDelimeter) left += char;
124
+ else if (char === "." || char.toLowerCase() === "б" || char.toLowerCase() === "ю") {
125
+ if (left == "") left = "0";
126
+ useDelimeter = true;
127
+ }
128
+ });
129
+
130
+ return useDelimeter ? `${left}.${right}` : `${left}`;
131
+ },
132
+
133
+ fixed(v: Value, dec = 20) {
134
+ return new Intl.NumberFormat("en-US", {
135
+ style: "decimal",
136
+ minimumFractionDigits: 0,
137
+ maximumFractionDigits: Math.min(12, Math.max(0, Math.floor(dec))),
138
+ useGrouping: true,
139
+ }).format(formatter.num(v));
140
+ },
141
+
142
+ fromInput(value: Value) {
143
+ return formatter.formatNumber(value?.toString() ?? "0");
144
+ },
145
+
146
+ trim(value: Value) {
147
+ return formatter.fromInput(formatter.formatNumberWithZeros(formatter.fromInput(value?.toString() ?? "0")));
148
+ },
149
+
150
+ amount(value: Value, decimals = 24) {
151
+ const num = String(+formatter.num(value).toFixed(decimals));
152
+ return formatter.formatNumberWithSubscriptZeros(num, 3, 0.0001);
153
+ },
154
+
155
+ num(value: Value) {
156
+ if (value == null) return 0;
157
+ return Number.isNaN(Number(value)) ? 0 : Number(value);
158
+ },
159
+
160
+ wait(ms: number) {
161
+ return new Promise((resolve) => setTimeout(resolve, ms));
162
+ },
163
+ };
@@ -0,0 +1,5 @@
1
+ export const GlobalSettings = {
2
+ webWallet: "https://app.hot-labs.org",
3
+ rpcs: {} as Record<number, string[]>,
4
+ tonApi: "",
5
+ };