@hot-labs/kit 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/build/HotConnector.d.ts +9 -13
  2. package/build/HotConnector.js +17 -57
  3. package/build/HotConnector.js.map +1 -1
  4. package/build/activity.d.ts +1 -1
  5. package/build/activity.js +8 -8
  6. package/build/activity.js.map +1 -1
  7. package/build/core/Intents.d.ts +4 -3
  8. package/build/core/Intents.js +24 -4
  9. package/build/core/Intents.js.map +1 -1
  10. package/build/{OmniConnector.d.ts → core/OmniConnector.d.ts} +4 -4
  11. package/build/{OmniConnector.js → core/OmniConnector.js} +2 -2
  12. package/build/core/OmniConnector.js.map +1 -0
  13. package/build/{OmniWallet.d.ts → core/OmniWallet.d.ts} +19 -13
  14. package/build/core/OmniWallet.js +97 -0
  15. package/build/core/OmniWallet.js.map +1 -0
  16. package/build/core/chains.d.ts +1 -1
  17. package/build/core/chains.js +5 -5
  18. package/build/core/chains.js.map +1 -1
  19. package/build/core/defaultTokens.js +0 -9
  20. package/build/core/defaultTokens.js.map +1 -1
  21. package/build/{exchange.d.ts → core/exchange.d.ts} +13 -16
  22. package/build/{exchange.js → core/exchange.js} +76 -80
  23. package/build/core/exchange.js.map +1 -0
  24. package/build/core/index.d.ts +4 -2
  25. package/build/core/index.js +4 -2
  26. package/build/core/index.js.map +1 -1
  27. package/build/core/recipient.d.ts +1 -1
  28. package/build/core/telemetry.d.ts +3 -0
  29. package/build/core/telemetry.js.map +1 -1
  30. package/build/core/token.js +3 -3
  31. package/build/core/token.js.map +1 -1
  32. package/build/core/tokens.js +1 -1
  33. package/build/core/tokens.js.map +1 -1
  34. package/build/core/utils.d.ts +1 -0
  35. package/build/core/utils.js +19 -0
  36. package/build/core/utils.js.map +1 -1
  37. package/build/cosmos/connector.d.ts +2 -2
  38. package/build/cosmos/connector.js +2 -2
  39. package/build/cosmos/connector.js.map +1 -1
  40. package/build/cosmos/wallet.d.ts +2 -2
  41. package/build/cosmos/wallet.js +7 -10
  42. package/build/cosmos/wallet.js.map +1 -1
  43. package/build/defaults.d.ts +1 -1
  44. package/build/defaults.js +2 -2
  45. package/build/defaults.js.map +1 -1
  46. package/build/evm/connector.d.ts +2 -2
  47. package/build/evm/connector.js +10 -4
  48. package/build/evm/connector.js.map +1 -1
  49. package/build/evm/wallet.d.ts +5 -5
  50. package/build/evm/wallet.js +25 -24
  51. package/build/evm/wallet.js.map +1 -1
  52. package/build/hot-wallet/google.d.ts +2 -2
  53. package/build/hot-wallet/google.js +4 -4
  54. package/build/hot-wallet/google.js.map +1 -1
  55. package/build/index.d.ts +2 -2
  56. package/build/index.js +2 -2
  57. package/build/index.js.map +1 -1
  58. package/build/near/connector.d.ts +2 -2
  59. package/build/near/connector.js +1 -1
  60. package/build/near/connector.js.map +1 -1
  61. package/build/near/index.d.ts +1 -1
  62. package/build/near/index.js.map +1 -1
  63. package/build/near/rpc.js +1 -2
  64. package/build/near/rpc.js.map +1 -1
  65. package/build/near/standalone.d.ts +2 -0
  66. package/build/near/standalone.js +42 -0
  67. package/build/near/standalone.js.map +1 -0
  68. package/build/near/wallet.d.ts +3 -2
  69. package/build/near/wallet.js +21 -12
  70. package/build/near/wallet.js.map +1 -1
  71. package/build/solana/connector.d.ts +4 -4
  72. package/build/solana/connector.js +11 -4
  73. package/build/solana/connector.js.map +1 -1
  74. package/build/solana/wallet.d.ts +3 -3
  75. package/build/solana/wallet.js +14 -11
  76. package/build/solana/wallet.js.map +1 -1
  77. package/build/stellar/connector.d.ts +2 -2
  78. package/build/stellar/connector.js +3 -2
  79. package/build/stellar/connector.js.map +1 -1
  80. package/build/stellar/wallet.d.ts +3 -3
  81. package/build/stellar/wallet.js +27 -19
  82. package/build/stellar/wallet.js.map +1 -1
  83. package/build/ton/connector.d.ts +2 -2
  84. package/build/ton/connector.js +2 -2
  85. package/build/ton/connector.js.map +1 -1
  86. package/build/ton/wallet.d.ts +3 -3
  87. package/build/ton/wallet.js +26 -17
  88. package/build/ton/wallet.js.map +1 -1
  89. package/build/tron/connector.d.ts +2 -2
  90. package/build/tron/connector.js +1 -1
  91. package/build/tron/connector.js.map +1 -1
  92. package/build/tron/wallet.d.ts +2 -2
  93. package/build/tron/wallet.js +9 -15
  94. package/build/tron/wallet.js.map +1 -1
  95. package/build/ui/bridge/Bridge.d.ts +2 -2
  96. package/build/ui/bridge/Bridge.js +13 -11
  97. package/build/ui/bridge/Bridge.js.map +1 -1
  98. package/build/ui/bridge/SelectRecipient.d.ts +3 -3
  99. package/build/ui/bridge/SelectRecipient.js +5 -5
  100. package/build/ui/bridge/SelectRecipient.js.map +1 -1
  101. package/build/ui/bridge/SelectSender.d.ts +1 -1
  102. package/build/ui/bridge/SelectSender.js +1 -1
  103. package/build/ui/bridge/SelectSender.js.map +1 -1
  104. package/build/ui/bridge/SelectToken.d.ts +1 -1
  105. package/build/ui/bridge/SelectToken.js +2 -2
  106. package/build/ui/bridge/SelectToken.js.map +1 -1
  107. package/build/ui/bridge/TokenCard.d.ts +1 -1
  108. package/build/ui/connect/AuthPopup.d.ts +1 -1
  109. package/build/ui/connect/ConnectWallet.d.ts +1 -1
  110. package/build/ui/connect/ConnectWallet.js +1 -1
  111. package/build/ui/connect/ConnectWallet.js.map +1 -1
  112. package/build/ui/connect/LogoutPopup.d.ts +1 -1
  113. package/build/ui/connect/WCPopup.js +1 -1
  114. package/build/ui/connect/WCPopup.js.map +1 -1
  115. package/build/ui/connect/WalletPicker.d.ts +2 -2
  116. package/build/ui/profile/DepositQR.d.ts +1 -1
  117. package/build/ui/profile/Payment.d.ts +1 -1
  118. package/build/ui/profile/Payment.js +8 -8
  119. package/build/ui/profile/Payment.js.map +1 -1
  120. package/build/ui/profile/Profile.js.map +1 -1
  121. package/build/ui/router.d.ts +3 -3
  122. package/examples-node/.env +2 -0
  123. package/examples-node/package.json +17 -0
  124. package/examples-node/transfer.ts +38 -0
  125. package/examples-node/withdraw.ts +52 -0
  126. package/examples-node/yarn.lock +2691 -0
  127. package/package.json +1 -1
  128. package/src/HotConnector.ts +16 -60
  129. package/src/activity.ts +9 -9
  130. package/src/core/Intents.ts +25 -7
  131. package/src/{OmniConnector.ts → core/OmniConnector.ts} +4 -6
  132. package/src/core/OmniWallet.ts +125 -0
  133. package/src/core/chains.ts +5 -5
  134. package/src/core/defaultTokens.ts +0 -9
  135. package/src/{exchange.ts → core/exchange.ts} +79 -85
  136. package/src/core/index.ts +6 -2
  137. package/src/core/recipient.ts +1 -1
  138. package/src/core/telemetry.ts +4 -0
  139. package/src/core/token.ts +3 -3
  140. package/src/core/tokens.ts +1 -1
  141. package/src/core/utils.ts +16 -0
  142. package/src/cosmos/connector.ts +3 -3
  143. package/src/cosmos/wallet.ts +8 -11
  144. package/src/defaults.ts +2 -2
  145. package/src/evm/connector.ts +12 -6
  146. package/src/evm/wallet.ts +25 -26
  147. package/src/hot-wallet/google.ts +5 -5
  148. package/src/index.ts +2 -2
  149. package/src/near/connector.ts +2 -2
  150. package/src/near/index.ts +2 -1
  151. package/src/near/rpc.ts +1 -2
  152. package/src/near/standalone.ts +52 -0
  153. package/src/near/wallet.ts +21 -15
  154. package/src/solana/connector.ts +15 -6
  155. package/src/solana/wallet.ts +12 -12
  156. package/src/stellar/connector.ts +5 -4
  157. package/src/stellar/wallet.ts +28 -22
  158. package/src/ton/connector.ts +4 -3
  159. package/src/ton/wallet.ts +24 -18
  160. package/src/tron/connector.ts +2 -2
  161. package/src/tron/wallet.ts +9 -19
  162. package/src/ui/bridge/Bridge.tsx +16 -14
  163. package/src/ui/bridge/SelectRecipient.tsx +8 -8
  164. package/src/ui/bridge/SelectSender.tsx +2 -2
  165. package/src/ui/bridge/SelectToken.tsx +3 -3
  166. package/src/ui/bridge/TokenCard.tsx +1 -1
  167. package/src/ui/connect/AuthPopup.tsx +1 -1
  168. package/src/ui/connect/ConnectWallet.tsx +2 -2
  169. package/src/ui/connect/LogoutPopup.tsx +1 -1
  170. package/src/ui/connect/WCPopup.tsx +1 -1
  171. package/src/ui/connect/WalletPicker.tsx +2 -2
  172. package/src/ui/profile/DepositQR.tsx +1 -1
  173. package/src/ui/profile/Payment.tsx +12 -13
  174. package/src/ui/profile/Profile.tsx +1 -2
  175. package/src/ui/router.tsx +3 -3
  176. package/build/OmniConnector.js.map +0 -1
  177. package/build/OmniWallet.js +0 -58
  178. package/build/OmniWallet.js.map +0 -1
  179. package/build/exchange.js.map +0 -1
  180. package/build/ui/utils.d.ts +0 -1
  181. package/build/ui/utils.js +0 -20
  182. package/build/ui/utils.js.map +0 -1
  183. package/src/OmniWallet.ts +0 -82
  184. package/src/ui/utils.ts +0 -14
@@ -1,17 +1,19 @@
1
- import { GetExecutionStatusResponse, OneClickService, ApiError, OpenAPI, QuoteRequest, QuoteResponse } from "@defuse-protocol/one-click-sdk-typescript";
1
+ import { GetExecutionStatusResponse, OneClickService, ApiError, QuoteRequest, QuoteResponse, OpenAPI } from "@defuse-protocol/one-click-sdk-typescript";
2
2
  import { utils } from "@hot-labs/omni-sdk";
3
3
  import { hex } from "@scure/base";
4
4
 
5
- import { Network, OmniToken, WalletType } from "./core/chains";
6
- import { ReviewFee } from "./core/bridge";
7
- import { Recipient } from "./core/recipient";
8
- import { tokens } from "./core/tokens";
9
- import { Token } from "./core/token";
10
-
11
- import StellarWallet from "./stellar/wallet";
12
- import { HotConnector } from "./HotConnector";
5
+ import { Network, OmniToken, WalletType } from "./chains";
6
+ import { createHotBridge, ReviewFee } from "./bridge";
13
7
  import { OmniWallet } from "./OmniWallet";
14
- import { formatter } from "./core";
8
+ import { Recipient } from "./recipient";
9
+ import { ILogger } from "./telemetry";
10
+ import { formatter } from "./utils";
11
+ import { Intents } from "./Intents";
12
+ import { tokens } from "./tokens";
13
+ import { Token } from "./token";
14
+
15
+ import StellarWallet from "../stellar/wallet";
16
+ import NearWallet from "../near/wallet";
15
17
 
16
18
  export class UnsupportedDexError extends Error {
17
19
  constructor(message: string) {
@@ -34,15 +36,17 @@ export type BridgeReview = {
34
36
  status: "pending" | "success" | "failed";
35
37
  statusMessage: string | null;
36
38
  sender: OmniWallet | "qr";
37
- recipient: Recipient;
39
+ recipient: OmniWallet | Recipient;
40
+ logger?: ILogger;
38
41
  from: Token;
39
42
  to: Token;
40
43
  };
41
44
 
42
- interface BridgeRequest {
45
+ export interface BridgeRequest {
43
46
  refund: OmniWallet;
44
47
  sender: OmniWallet | "qr";
45
48
  type?: "exactIn" | "exactOut";
49
+ logger?: ILogger;
46
50
  recipient: Recipient;
47
51
  slippage: number;
48
52
  amount: bigint;
@@ -53,13 +57,10 @@ interface BridgeRequest {
53
57
  const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
54
58
 
55
59
  export class Exchange {
56
- constructor(readonly wibe3: HotConnector) {
57
- // OpenAPI.BASE = api.getOneClickApiUrl();
58
- // OpenAPI.HEADERS = { "api-key": api.apiKey };
59
- }
60
+ readonly bridge = createHotBridge();
60
61
 
61
62
  async getToken(chain: number, address: string): Promise<string | null> {
62
- if (chain === Network.Hot) return address;
63
+ if (chain === Network.Omni) return address;
63
64
  const tokensList = await tokens.getTokens();
64
65
  const token = tokensList.find((t) => {
65
66
  if (t.chain !== chain) return false;
@@ -72,15 +73,15 @@ export class Exchange {
72
73
  return token?.omniAddress || null;
73
74
  }
74
75
 
75
- async deposit(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: Recipient; onMessage: (message: string) => void }) {
76
- let { sender, token, amount, recipient, onMessage } = args;
77
- onMessage("Sending deposit transaction");
76
+ async deposit(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: Recipient; logger?: ILogger }) {
77
+ let { sender, token, amount, recipient, logger } = args;
78
+ logger?.log("Sending deposit transaction");
78
79
 
79
- const balance = await this.wibe3.fetchToken(token, sender);
80
+ const balance = await sender.fetchBalance(token.chain, token.address);
80
81
  amount = formatter.bigIntMin(amount, balance);
81
82
 
82
- if (token.type === WalletType.COSMOS && this.wibe3.isCosmosWallet(sender)) {
83
- const cosmosBridge = await this.wibe3.hotBridge.cosmos();
83
+ if (token.type === WalletType.COSMOS && sender.type === WalletType.COSMOS) {
84
+ const cosmosBridge = await this.bridge.cosmos();
84
85
  const hash = await cosmosBridge.deposit({
85
86
  sendTransaction: async (tx) => sender.sendTransaction(tx),
86
87
  senderPublicKey: hex.decode(sender.publicKey!),
@@ -91,17 +92,17 @@ export class Exchange {
91
92
  amount: amount,
92
93
  });
93
94
 
94
- onMessage("Waiting for deposit");
95
- const deposit = await this.wibe3.hotBridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
96
- onMessage("Finishing deposit");
97
- await this.wibe3.hotBridge.finishDeposit(deposit);
98
- onMessage("Deposit finished");
95
+ logger?.log("Waiting for deposit");
96
+ const deposit = await this.bridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
97
+ logger?.log("Finishing deposit");
98
+ await this.bridge.finishDeposit(deposit);
99
+ logger?.log("Deposit finished");
99
100
  return;
100
101
  }
101
102
 
102
- if (token.type === WalletType.EVM && this.wibe3.isEvmWallet(sender)) {
103
- const hash = await this.wibe3.hotBridge.evm.deposit({
104
- sendTransaction: async (tx) => sender.sendTransaction(token.chain, tx),
103
+ if (token.type === WalletType.EVM && sender.type === WalletType.EVM) {
104
+ const hash = await this.bridge.evm.deposit({
105
+ sendTransaction: async (tx) => sender.sendTransaction(tx),
105
106
  intentAccount: recipient.omniAddress,
106
107
  sender: sender.address,
107
108
  token: token.address,
@@ -110,16 +111,16 @@ export class Exchange {
110
111
  });
111
112
 
112
113
  if (!hash) throw new Error("Failed to deposit");
113
- onMessage("Waiting for deposit");
114
- const deposit = await this.wibe3.hotBridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
115
- onMessage("Finishing deposit");
116
- await this.wibe3.hotBridge.finishDeposit(deposit);
117
- onMessage("Deposit finished");
114
+ logger?.log("Waiting for deposit");
115
+ const deposit = await this.bridge.waitPendingDeposit(token.chain, hash, recipient.omniAddress);
116
+ logger?.log("Finishing deposit");
117
+ await this.bridge.finishDeposit(deposit);
118
+ logger?.log("Deposit finished");
118
119
  return;
119
120
  }
120
121
 
121
- if (token.type === WalletType.NEAR && this.wibe3.isNearWallet(sender)) {
122
- return await this.wibe3.hotBridge.near.deposit({
122
+ if (token.type === WalletType.NEAR && sender.type === WalletType.NEAR) {
123
+ return await this.bridge.near.deposit({
123
124
  sendTransaction: async (tx: any) => sender.sendTransaction(tx),
124
125
  intentAccount: recipient.omniAddress,
125
126
  sender: sender.address,
@@ -131,17 +132,16 @@ export class Exchange {
131
132
  throw new Error("Unsupported token");
132
133
  }
133
134
 
134
- async withdraw(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: Recipient }, pending: { log: (message: string) => void }) {
135
- const { sender, token, amount, recipient } = args;
135
+ async withdraw(args: { sender: OmniWallet; token: Token; amount: bigint; recipient: OmniWallet | Recipient; logger?: ILogger }) {
136
+ const { sender, token, amount, recipient, logger } = args;
136
137
 
137
- const receipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
138
- if (this.wibe3.isNearWallet(receipientWallet) && token.type === WalletType.NEAR) {
139
- pending.log("Registering NEAR token");
140
- await receipientWallet.registerToken(token.originalAddress);
138
+ if (recipient.type === WalletType.NEAR && token.type === WalletType.NEAR && recipient instanceof NearWallet) {
139
+ logger?.log("Registering NEAR token");
140
+ await recipient.registerToken(token.originalAddress);
141
141
  }
142
142
 
143
- pending.log("Withdrawing token");
144
- await this.wibe3.hotBridge.withdrawToken({
143
+ logger?.log("Withdrawing token");
144
+ await this.bridge.withdrawToken({
145
145
  signIntents: async (intents) => sender.signIntents(intents),
146
146
  intentAccount: sender.omniAddress,
147
147
  receiver: recipient.address,
@@ -155,8 +155,8 @@ export class Exchange {
155
155
 
156
156
  async withdrawFee(request: BridgeRequest) {
157
157
  if (request.sender === "qr") throw new Error("Sender is QR");
158
- if (request.to.chain === Network.Near || request.to.chain === Network.Hot) return 0n;
159
- const gaslessFee = await this.wibe3.hotBridge.getGaslessWithdrawFee({
158
+ if (request.to.chain === Network.Near || request.to.chain === Network.Omni) return 0n;
159
+ const gaslessFee = await this.bridge.getGaslessWithdrawFee({
160
160
  receiver: request.recipient.address,
161
161
  token: request.to.address,
162
162
  chain: request.to.chain,
@@ -166,7 +166,7 @@ export class Exchange {
166
166
  if (request.to.address === "native") return 0n;
167
167
 
168
168
  // if withdraw token is not native, we need to swap a bit of it to native to cover the withdraw fee
169
- const swap = await this.wibe3.hotBridge.buildSwapExectOutIntent({
169
+ const swap = await this.bridge.buildSwapExectOutIntent({
170
170
  intentFrom: utils.toOmniIntent(request.to.chain, request.to.address),
171
171
  intentTo: utils.toOmniIntent(request.to.chain, "native"),
172
172
  amountOut: gaslessFee.gasPrice,
@@ -178,16 +178,16 @@ export class Exchange {
178
178
 
179
179
  isDirectDeposit(from: Token, to: Token) {
180
180
  const directChains = [Network.Near, Network.Juno, Network.Gonka, Network.ADI];
181
- return directChains.includes(from.chain) && to.chain === Network.Hot && from.omniAddress === to.omniAddress;
181
+ return directChains.includes(from.chain) && to.chain === Network.Omni && from.omniAddress === to.omniAddress;
182
182
  }
183
183
 
184
184
  isDirectWithdraw(from: Token, to: Token) {
185
185
  const directChains = [Network.Near, Network.Juno, Network.Gonka, Network.ADI];
186
- return directChains.includes(to.chain) && from.chain === Network.Hot && from.omniAddress === to.omniAddress;
186
+ return directChains.includes(to.chain) && from.chain === Network.Omni && from.omniAddress === to.omniAddress;
187
187
  }
188
188
 
189
189
  async reviewSwap(request: BridgeRequest): Promise<BridgeReview> {
190
- const { sender, refund, from, to, amount, recipient, slippage, type } = request;
190
+ const { sender, refund, from, to, amount, recipient, slippage, type, logger } = request;
191
191
  const intentFrom = await this.getToken(from.chain, from.address);
192
192
  const intentTo = await this.getToken(to.chain, to.address);
193
193
 
@@ -199,7 +199,7 @@ export class Exchange {
199
199
  const noFee = from.symbol === to.symbol || (from.symbol.toLowerCase().includes("usd") && to.symbol.toLowerCase().includes("usd"));
200
200
 
201
201
  if (sender !== "qr" && this.isDirectDeposit(from, to)) {
202
- const fee = await this.wibe3.hotBridge.getDepositFee({
202
+ const fee = await this.bridge.getDepositFee({
203
203
  intentAccount: sender.omniAddress,
204
204
  sender: sender.address,
205
205
  token: from.address,
@@ -218,6 +218,7 @@ export class Exchange {
218
218
  statusMessage: null,
219
219
  status: "pending",
220
220
  qoute: "deposit",
221
+ logger,
221
222
  fee,
222
223
  };
223
224
  }
@@ -237,6 +238,7 @@ export class Exchange {
237
238
  statusMessage: null,
238
239
  status: "pending",
239
240
  qoute: "withdraw",
241
+ logger,
240
242
  };
241
243
  }
242
244
 
@@ -249,8 +251,7 @@ export class Exchange {
249
251
 
250
252
  if (recipient.type === WalletType.STELLAR) {
251
253
  const isTokenActivated = await StellarWallet.isTokenActivated(recipient.address, request.to.address);
252
- const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
253
- if (!isTokenActivated && !recipientWallet) throw "Token not activated for recipient";
254
+ if (!isTokenActivated && !(recipient instanceof StellarWallet)) throw "Token not activated for recipient";
254
255
  }
255
256
 
256
257
  let qoute: QuoteResponse | null = null;
@@ -260,11 +261,11 @@ export class Exchange {
260
261
  destinationAsset: intentTo,
261
262
  quoteWaitingTimeMs: 3000,
262
263
  slippageTolerance: Math.round(slippage * 10_000),
263
- swapType: type === "exactIn" ? QuoteRequest.swapType.EXACT_INPUT : QuoteRequest.swapType.EXACT_OUTPUT,
264
- depositType: from.chain === Network.Hot ? QuoteRequest.depositType.INTENTS : QuoteRequest.depositType.ORIGIN_CHAIN,
264
+ swapType: type === "exactOut" ? QuoteRequest.swapType.EXACT_OUTPUT : QuoteRequest.swapType.EXACT_INPUT,
265
+ depositType: from.chain === Network.Omni ? QuoteRequest.depositType.INTENTS : QuoteRequest.depositType.ORIGIN_CHAIN,
265
266
  depositMode: from.chain === Network.Stellar ? QuoteRequest.depositMode.MEMO : QuoteRequest.depositMode.SIMPLE,
266
- recipientType: to.chain === Network.Hot ? QuoteRequest.recipientType.INTENTS : QuoteRequest.recipientType.DESTINATION_CHAIN,
267
- recipient: to.chain === Network.Hot ? recipient.omniAddress : recipient.address,
267
+ recipientType: to.chain === Network.Omni ? QuoteRequest.recipientType.INTENTS : QuoteRequest.recipientType.DESTINATION_CHAIN,
268
+ recipient: to.chain === Network.Omni ? recipient.omniAddress : recipient.address,
268
269
  appFees: noFee ? [] : [{ recipient: "intents.tg", fee: 25 }],
269
270
  amount: request.amount.toString(),
270
271
  referral: "intents.tg",
@@ -288,7 +289,7 @@ export class Exchange {
288
289
  }
289
290
 
290
291
  let fee: ReviewFee | null = null;
291
- if (request.from.chain !== Network.Hot && sender !== "qr") {
292
+ if (request.from.chain !== Network.Omni && sender !== "qr") {
292
293
  const amount = BigInt(qoute.quote.amountIn);
293
294
  const depositAddress = qoute.quote.depositAddress!;
294
295
  fee = await sender.transferFee(request.from, depositAddress, amount).catch(() => null);
@@ -306,47 +307,41 @@ export class Exchange {
306
307
  status: "pending",
307
308
  sender: sender,
308
309
  fee: fee,
310
+ logger,
309
311
  };
310
312
  }
311
313
 
312
- async makeSwap(review: BridgeReview, pending: { log: (message: string) => void }): Promise<{ review: BridgeReview; processing?: () => Promise<BridgeReview> }> {
313
- const { sender, recipient } = review;
314
+ async makeSwap(review: BridgeReview): Promise<{ review: BridgeReview; processing?: () => Promise<BridgeReview> }> {
315
+ const { sender, recipient, logger } = review;
314
316
 
315
317
  if (review.qoute === "withdraw") {
316
318
  if (sender === "qr") throw new Error("Sender is QR");
317
- await this.withdraw({ sender, token: review.to, amount: review.amountIn, recipient }, pending);
318
- const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
319
- if (recipientWallet) this.wibe3.fetchToken(review.to, recipientWallet);
320
- this.wibe3.fetchToken(review.from, sender);
319
+ await this.withdraw({ sender, token: review.to, amount: review.amountIn, recipient, logger });
320
+ if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
321
+ if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
321
322
  return { review };
322
323
  }
323
324
 
324
325
  if (review.qoute === "deposit") {
325
326
  if (sender === "qr") throw new Error("Sender is QR");
326
- await this.deposit({ sender, token: review.from, amount: review.amountIn, recipient, onMessage: pending.log });
327
- this.wibe3.fetchToken(review.from, sender);
328
-
329
- const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
330
- if (recipientWallet) this.wibe3.fetchToken(review.to, recipientWallet);
327
+ await this.deposit({ sender, token: review.from, amount: review.amountIn, recipient, logger });
328
+ if (recipient instanceof OmniWallet) recipient.fetchBalance(review.to.chain, review.to.address);
329
+ if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
331
330
  return { review };
332
331
  }
333
332
 
334
333
  if (sender !== "qr") {
335
334
  if (recipient.type === WalletType.STELLAR) {
336
335
  const isTokenActivated = await StellarWallet.isTokenActivated(recipient.address, review.to.address);
337
- const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
338
- if (!isTokenActivated && !recipientWallet) throw "Token not activated for recipient";
339
- if (!isTokenActivated && recipientWallet instanceof StellarWallet) {
340
- await recipientWallet.changeTrustline(review.to.address);
341
- }
336
+ if (!isTokenActivated && !(recipient instanceof StellarWallet)) throw "Token not activated for recipient";
337
+ if (!isTokenActivated && recipient instanceof StellarWallet) await recipient.changeTrustline(review.to.address);
342
338
  }
343
339
 
344
340
  const depositAddress = review.qoute.depositAddress!;
345
341
  let hash = "";
346
342
 
347
- if (review.from.chain === Network.Hot) {
348
- hash = await this.wibe3
349
- .intentsBuilder(sender)
343
+ if (review.from.chain === Network.Omni) {
344
+ hash = await Intents.builder(sender)
350
345
  .transfer({ amount: review.amountIn, token: review.from.address as OmniToken, recipient: depositAddress })
351
346
  .execute();
352
347
  } else {
@@ -359,21 +354,20 @@ export class Exchange {
359
354
  });
360
355
  }
361
356
 
362
- this.wibe3.fetchToken(review.from, sender);
357
+ if (sender instanceof OmniWallet) sender.fetchBalance(review.from.chain, review.from.address);
363
358
  OneClickService.submitDepositTx({ txHash: hash, depositAddress }).catch(() => {});
364
359
  }
365
360
 
366
361
  return {
367
362
  review,
368
363
  processing: async () => {
369
- const recipientWallet = this.wibe3.wallets.find((w) => w.address === recipient.address);
370
- if (!recipientWallet) return await this.processing(review);
364
+ if (!(recipient instanceof OmniWallet)) return await this.processing(review);
371
365
 
372
- const beforeBalance = await this.wibe3.fetchToken(review.to, recipientWallet).catch(() => null);
366
+ const beforeBalance = await recipient.fetchBalance(review.to.chain, review.to.address).catch(() => null);
373
367
  if (!beforeBalance) return await this.processing(review);
374
368
 
375
369
  return await Promise.race([
376
- this.waitBalance(review.to, recipientWallet, beforeBalance, review),
370
+ this.waitBalance(review.to, recipient, beforeBalance, review),
377
371
  this.processing(review), //
378
372
  ]);
379
373
  },
@@ -381,7 +375,7 @@ export class Exchange {
381
375
  }
382
376
 
383
377
  async waitBalance(to: Token, wallet: OmniWallet, beforeBalance: bigint, review: BridgeReview): Promise<BridgeReview> {
384
- const afterBalance = await this.wibe3.fetchToken(to, wallet).catch(() => beforeBalance);
378
+ const afterBalance = await wallet.fetchBalance(to.chain, to.address).catch(() => beforeBalance);
385
379
  if (afterBalance > beforeBalance) {
386
380
  return {
387
381
  ...review,
package/src/core/index.ts CHANGED
@@ -1,6 +1,10 @@
1
- export { OmniToken, WalletType, Network, chains } from "./chains";
2
- export { createHotBridge, HotBridge, ReviewFee } from "./bridge";
3
1
  export { rpc as nearRpc, TGAS } from "../near/rpc";
2
+
3
+ export { OmniToken, WalletType, Network } from "./chains";
4
+
5
+ export { chains } from "./chains";
6
+ export { createHotBridge, HotBridge, ReviewFee } from "./bridge";
7
+ export { Exchange } from "./exchange";
4
8
  export { EventEmitter } from "./events";
5
9
  export { Recipient } from "./recipient";
6
10
  export { formatter } from "./utils";
@@ -1,7 +1,7 @@
1
1
  import { Address } from "@ton/core";
2
2
  import { hex, base32, base58 } from "@scure/base";
3
3
 
4
- import { type OmniWallet } from "../OmniWallet";
4
+ import { type OmniWallet } from "./OmniWallet";
5
5
  import { tonApi } from "../ton/utils";
6
6
  import { WalletType } from "./chains";
7
7
 
@@ -2,6 +2,10 @@ import { api } from "./api";
2
2
  import { HotConnector } from "../HotConnector";
3
3
  import { formatter } from "./utils";
4
4
 
5
+ export interface ILogger {
6
+ log: (message: string) => void;
7
+ }
8
+
5
9
  export class Telemetry {
6
10
  events: { event: string; value_str?: string; value_float?: number; ts: number }[] = [];
7
11
  constructor(readonly wibe3: HotConnector) {
package/src/core/token.ts CHANGED
@@ -73,7 +73,7 @@ export class Token {
73
73
  }
74
74
 
75
75
  get isMainOmni() {
76
- if (this.chain !== Network.Hot) return false;
76
+ if (this.chain !== Network.Omni) return false;
77
77
  return Object.values(OmniToken).some((token) => this.address === token);
78
78
  }
79
79
 
@@ -90,7 +90,7 @@ export class Token {
90
90
  if (this.chain === Network.Juno) return 0.01;
91
91
 
92
92
  if (this.address !== "native") return 0;
93
- if (this.chain === Network.Hot) return 0;
93
+ if (this.chain === Network.Omni) return 0;
94
94
  if (this.chain === Network.Ton) return 0.01;
95
95
  if (this.chain === Network.Stellar) return 0;
96
96
  if (this.chain === Network.Solana) return 0.001;
@@ -102,7 +102,7 @@ export class Token {
102
102
  }
103
103
 
104
104
  get icon() {
105
- if (this.chain === Network.Hot) return `https://storage.herewallet.app/ft/${this.originalChain}:${this.originalAddress.toLowerCase()}.png`;
105
+ if (this.chain === Network.Omni) return `https://storage.herewallet.app/ft/${this.originalChain}:${this.originalAddress.toLowerCase()}.png`;
106
106
  return `https://storage.herewallet.app/ft/${this.id.toLowerCase()}.png`;
107
107
  }
108
108
 
@@ -13,7 +13,7 @@ class TokensStorage {
13
13
  makeObservable(this, { list: observable });
14
14
  }
15
15
 
16
- get(id: OmniToken | string, chain = Network.Hot): Token {
16
+ get(id: OmniToken | string, chain = Network.Omni): Token {
17
17
  return this.list.find((t) => t.chain === chain && t.address === id)!;
18
18
  }
19
19
 
package/src/core/utils.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { NetworkError, TimeoutNetworkError } from "./api";
2
+
1
3
  type Value = number | bigint | string;
2
4
  export const formatter = {
3
5
  toReadableNumber(decimals: number | bigint, number: bigint | string = "0"): string {
@@ -107,6 +109,7 @@ export const formatter = {
107
109
  if (n < 1_000_000_000_000) return [formatter.round(n / 1_000_000, 2), "M"];
108
110
  return [formatter.round(n / 1_000_000_000, 2), "B"];
109
111
  },
112
+
110
113
  formatNumber(num: string) {
111
114
  let useDelimeter = false;
112
115
  let right = "";
@@ -176,4 +179,17 @@ export const formatter = {
176
179
  return acc;
177
180
  }, []);
178
181
  },
182
+
183
+ serializeError(error: any): string {
184
+ try {
185
+ if (error instanceof Error) return error.message;
186
+ if (error instanceof NetworkError) return error.toString();
187
+ if (error instanceof TimeoutNetworkError) return error.toString();
188
+ if (typeof error === "object" && Object.keys(error).length > 0) return JSON.stringify(error);
189
+ if (typeof error === "string" || typeof error === "number") return error.toString();
190
+ return "";
191
+ } catch (error) {
192
+ return "Unknown error";
193
+ }
194
+ },
179
195
  };
@@ -6,9 +6,9 @@ import { runInAction } from "mobx";
6
6
 
7
7
  import { api } from "../core/api";
8
8
  import { chains, WalletType } from "../core/chains";
9
- import { ConnectorType, OmniConnector, OmniConnectorOption, WC_ICON } from "../OmniConnector";
9
+ import { ConnectorType, OmniConnector, OmniConnectorOption, WC_ICON } from "../core/OmniConnector";
10
10
  import { HotConnector } from "../HotConnector";
11
- import { OmniWallet } from "../OmniWallet";
11
+ import { OmniWallet } from "../core/OmniWallet";
12
12
 
13
13
  import { signAndSendTx } from "./helpers";
14
14
  import CosmosWallet from "./wallet";
@@ -80,7 +80,7 @@ export default class CosmosConnector extends OmniConnector<CosmosWallet> {
80
80
  });
81
81
 
82
82
  this.initWalletConnect()
83
- .then(async (wc) => {
83
+ .then(async () => {
84
84
  this.options.unshift({
85
85
  download: "https://www.walletconnect.com/get",
86
86
  name: "WalletConnect",
@@ -1,5 +1,5 @@
1
1
  import { StargateClient } from "@cosmjs/stargate";
2
- import { OmniWallet } from "../OmniWallet";
2
+ import { OmniWallet } from "../core/OmniWallet";
3
3
  import { chains, WalletType } from "../core/chains";
4
4
  import { ReviewFee } from "../core/bridge";
5
5
  import { Commitment } from "../core";
@@ -48,21 +48,18 @@ export default class CosmosWallet extends OmniWallet {
48
48
  throw new Error("Method not implemented.");
49
49
  }
50
50
 
51
- async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
52
- const balances = await Promise.all(
53
- whitelist.map(async (token) => {
54
- const balance = await this.fetchBalance(chain, token);
55
- return [token, balance];
56
- })
57
- );
58
- return Object.fromEntries(balances);
51
+ async fetchBalances(chain: number, whitelist: string[] = []): Promise<Record<string, bigint>> {
52
+ const tasks = whitelist.map(async (token) => [token, await this.fetchBalance(chain, token)]);
53
+ return Object.fromEntries(await Promise.all(tasks));
59
54
  }
60
55
 
61
56
  async fetchBalance(chain: number, token: string): Promise<bigint> {
62
57
  const config = chains.get(chain);
63
- if (!config) throw new Error("Config not found");
58
+ if (!config || config.type !== WalletType.COSMOS) return super.fetchBalance(chain, token);
59
+
64
60
  const client = await StargateClient.connect(config.rpc);
65
61
  const balance = await client.getBalance(this.address, token);
66
- return BigInt(balance.amount || 0);
62
+
63
+ return this.setBalance(`${chain}:${token}`, BigInt(balance.amount || 0));
67
64
  }
68
65
  }
package/src/defaults.ts CHANGED
@@ -1,7 +1,7 @@
1
- import near from "./near";
2
1
  import stellar from "./stellar";
3
- import ton from "./ton";
4
2
  import solana from "./solana";
3
+ import near from "./near";
5
4
  import evm from "./evm";
5
+ import ton from "./ton";
6
6
 
7
7
  export const defaultConnectors = [near(), evm(), solana(), ton(), stellar()];
@@ -1,10 +1,10 @@
1
1
  import { runInAction } from "mobx";
2
2
 
3
3
  import HOT from "../hot-wallet/iframe";
4
- import { Network, WalletType } from "../core/chains";
5
- import { ConnectorType, OmniConnector, WC_ICON } from "../OmniConnector";
6
- import { HotConnector } from "../HotConnector";
4
+ import type { HotConnector } from "../HotConnector";
7
5
 
6
+ import { Network, WalletType } from "../core/chains";
7
+ import { ConnectorType, OmniConnector, WC_ICON } from "../core/OmniConnector";
8
8
  import EvmWallet, { EvmProvider } from "./wallet";
9
9
 
10
10
  class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
@@ -44,13 +44,19 @@ class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
44
44
  window.dispatchEvent(new Event("eip6963:requestProvider"));
45
45
 
46
46
  this.initWalletConnect()
47
- .then((wc) => {
48
- this.options.unshift({ id: "walletconnect", name: "WalletConnect", icon: WC_ICON, provider: {} as any, type: "external" });
47
+ .then(() => {
48
+ this.options.unshift({
49
+ id: "walletconnect",
50
+ name: "WalletConnect",
51
+ provider: {} as any,
52
+ type: "external",
53
+ icon: WC_ICON,
54
+ });
49
55
  })
50
56
  .catch(() => {});
51
57
 
52
58
  this.wc
53
- ?.then(async (wc) => {
59
+ ?.then(async () => {
54
60
  const selected = await this.getConnectedWallet();
55
61
  if (selected.id !== "walletconnect") return;
56
62
  this.setupWalletConnect();