@hot-labs/kit 1.1.2 → 1.2.0-alpha.1

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 (322) hide show
  1. package/README.md +9 -2
  2. package/package.json +4 -8
  3. package/src/HotConnector.ts +31 -21
  4. package/src/OmniConnector.ts +9 -10
  5. package/src/OmniWallet.ts +25 -24
  6. package/src/core/Intents.ts +151 -222
  7. package/src/core/api.ts +4 -37
  8. package/src/core/bridge.ts +2 -3
  9. package/src/core/index.ts +1 -1
  10. package/src/{near/rpc.ts → core/nearRpc.ts} +11 -4
  11. package/src/core/types.ts +0 -21
  12. package/src/core/utils.ts +1 -17
  13. package/src/cosmos/connector.ts +26 -22
  14. package/src/cosmos/wallet.ts +8 -3
  15. package/src/evm/connector.ts +0 -5
  16. package/src/evm/wallet.ts +6 -9
  17. package/src/exchange.ts +30 -24
  18. package/src/hot-wallet/google.ts +5 -12
  19. package/src/index.ts +0 -2
  20. package/src/near/connector.ts +2 -2
  21. package/src/near/wallet.ts +9 -4
  22. package/src/solana/connector.ts +8 -9
  23. package/src/solana/injected/solana-wallet.ts +6 -6
  24. package/src/solana/{WalletStandard.ts → protocol.ts} +4 -2
  25. package/src/solana/wallet.ts +20 -11
  26. package/src/stellar/connector.ts +6 -1
  27. package/src/stellar/wallet.ts +17 -17
  28. package/src/ton/connector.ts +5 -1
  29. package/src/ton/wallet.ts +3 -3
  30. package/src/ui/Popup.tsx +4 -12
  31. package/src/ui/connect/AuthPopup.tsx +1 -2
  32. package/src/ui/connect/ConnectWallet.tsx +6 -12
  33. package/src/ui/icons/arrow-right.tsx +2 -2
  34. package/src/ui/icons/close.tsx +1 -1
  35. package/src/ui/icons/exchange.tsx +4 -4
  36. package/src/ui/icons/logout.tsx +6 -6
  37. package/src/ui/icons/pending.tsx +4 -2
  38. package/src/ui/icons/qr.tsx +2 -1
  39. package/src/ui/icons/search.tsx +4 -4
  40. package/src/ui/icons/switch.tsx +4 -4
  41. package/src/ui/icons/wallet.tsx +4 -2
  42. package/src/ui/payment/Bridge.tsx +6 -25
  43. package/src/ui/payment/Payment.tsx +46 -241
  44. package/src/ui/payment/Profile.tsx +8 -10
  45. package/src/ui/payment/SelectToken.tsx +1 -1
  46. package/src/ui/payment/TokenCard.tsx +18 -22
  47. package/src/ui/router.tsx +16 -56
  48. package/src/ui/styles.ts +0 -2
  49. package/build/HotConnector.d.ts +0 -103
  50. package/build/HotConnector.js +0 -300
  51. package/build/HotConnector.js.map +0 -1
  52. package/build/OmniConnector.d.ts +0 -90
  53. package/build/OmniConnector.js +0 -121
  54. package/build/OmniConnector.js.map +0 -1
  55. package/build/OmniWallet.d.ts +0 -35
  56. package/build/OmniWallet.js +0 -56
  57. package/build/OmniWallet.js.map +0 -1
  58. package/build/activity.d.ts +0 -18
  59. package/build/activity.js +0 -87
  60. package/build/activity.js.map +0 -1
  61. package/build/core/Intents.d.ts +0 -100
  62. package/build/core/Intents.js +0 -472
  63. package/build/core/Intents.js.map +0 -1
  64. package/build/core/api.d.ts +0 -48
  65. package/build/core/api.js +0 -93
  66. package/build/core/api.js.map +0 -1
  67. package/build/core/bridge.d.ts +0 -3
  68. package/build/core/bridge.js +0 -36
  69. package/build/core/bridge.js.map +0 -1
  70. package/build/core/chains.d.ts +0 -115
  71. package/build/core/chains.js +0 -381
  72. package/build/core/chains.js.map +0 -1
  73. package/build/core/defaultTokens.d.ts +0 -17
  74. package/build/core/defaultTokens.js +0 -1079
  75. package/build/core/defaultTokens.js.map +0 -1
  76. package/build/core/events.d.ts +0 -42
  77. package/build/core/events.js +0 -64
  78. package/build/core/events.js.map +0 -1
  79. package/build/core/index.d.ts +0 -10
  80. package/build/core/index.js +0 -11
  81. package/build/core/index.js.map +0 -1
  82. package/build/core/recipient.d.ts +0 -10
  83. package/build/core/recipient.js +0 -40
  84. package/build/core/recipient.js.map +0 -1
  85. package/build/core/token.d.ts +0 -36
  86. package/build/core/token.js +0 -103
  87. package/build/core/token.js.map +0 -1
  88. package/build/core/tokens.d.ts +0 -14
  89. package/build/core/tokens.js +0 -59
  90. package/build/core/tokens.js.map +0 -1
  91. package/build/core/types.d.ts +0 -60
  92. package/build/core/types.js +0 -2
  93. package/build/core/types.js.map +0 -1
  94. package/build/core/utils.d.ts +0 -25
  95. package/build/core/utils.js +0 -170
  96. package/build/core/utils.js.map +0 -1
  97. package/build/cosmos/connector.d.ts +0 -36
  98. package/build/cosmos/connector.js +0 -211
  99. package/build/cosmos/connector.js.map +0 -1
  100. package/build/cosmos/helpers.d.ts +0 -2
  101. package/build/cosmos/helpers.js +0 -29
  102. package/build/cosmos/helpers.js.map +0 -1
  103. package/build/cosmos/index.d.ts +0 -6
  104. package/build/cosmos/index.js +0 -5
  105. package/build/cosmos/index.js.map +0 -1
  106. package/build/cosmos/wallet.d.ts +0 -26
  107. package/build/cosmos/wallet.js +0 -51
  108. package/build/cosmos/wallet.js.map +0 -1
  109. package/build/defaults.d.ts +0 -1
  110. package/build/defaults.js +0 -7
  111. package/build/defaults.js.map +0 -1
  112. package/build/evm/abi.d.ts +0 -17
  113. package/build/evm/abi.js +0 -38
  114. package/build/evm/abi.js.map +0 -1
  115. package/build/evm/connector.d.ts +0 -29
  116. package/build/evm/connector.js +0 -118
  117. package/build/evm/connector.js.map +0 -1
  118. package/build/evm/index.d.ts +0 -6
  119. package/build/evm/index.js +0 -5
  120. package/build/evm/index.js.map +0 -1
  121. package/build/evm/injected.d.ts +0 -1
  122. package/build/evm/injected.js +0 -33
  123. package/build/evm/injected.js.map +0 -1
  124. package/build/evm/wallet.d.ts +0 -42
  125. package/build/evm/wallet.js +0 -130
  126. package/build/evm/wallet.js.map +0 -1
  127. package/build/exchange.d.ts +0 -68
  128. package/build/exchange.js +0 -384
  129. package/build/exchange.js.map +0 -1
  130. package/build/hot-wallet/google.d.ts +0 -25
  131. package/build/hot-wallet/google.js +0 -117
  132. package/build/hot-wallet/google.js.map +0 -1
  133. package/build/hot-wallet/iframe.d.ts +0 -36
  134. package/build/hot-wallet/iframe.js +0 -140
  135. package/build/hot-wallet/iframe.js.map +0 -1
  136. package/build/hot-wallet/index.d.ts +0 -5
  137. package/build/hot-wallet/index.js +0 -4
  138. package/build/hot-wallet/index.js.map +0 -1
  139. package/build/hot-wallet/proxy.d.ts +0 -8
  140. package/build/hot-wallet/proxy.js +0 -45
  141. package/build/hot-wallet/proxy.js.map +0 -1
  142. package/build/index.d.ts +0 -6
  143. package/build/index.js +0 -7
  144. package/build/index.js.map +0 -1
  145. package/build/near/connector.d.ts +0 -18
  146. package/build/near/connector.js +0 -58
  147. package/build/near/connector.js.map +0 -1
  148. package/build/near/index.d.ts +0 -7
  149. package/build/near/index.js +0 -5
  150. package/build/near/index.js.map +0 -1
  151. package/build/near/rpc.d.ts +0 -23
  152. package/build/near/rpc.js +0 -161
  153. package/build/near/rpc.js.map +0 -1
  154. package/build/near/wallet.d.ts +0 -53
  155. package/build/near/wallet.js +0 -190
  156. package/build/near/wallet.js.map +0 -1
  157. package/build/solana/WalletStandard.d.ts +0 -25
  158. package/build/solana/WalletStandard.js +0 -56
  159. package/build/solana/WalletStandard.js.map +0 -1
  160. package/build/solana/connector.d.ts +0 -30
  161. package/build/solana/connector.js +0 -139
  162. package/build/solana/connector.js.map +0 -1
  163. package/build/solana/index.d.ts +0 -6
  164. package/build/solana/index.js +0 -5
  165. package/build/solana/index.js.map +0 -1
  166. package/build/solana/injected/account.d.ts +0 -11
  167. package/build/solana/injected/account.js +0 -41
  168. package/build/solana/injected/account.js.map +0 -1
  169. package/build/solana/injected/index.d.ts +0 -1
  170. package/build/solana/injected/index.js +0 -82
  171. package/build/solana/injected/index.js.map +0 -1
  172. package/build/solana/injected/register.d.ts +0 -2
  173. package/build/solana/injected/register.js +0 -41
  174. package/build/solana/injected/register.js.map +0 -1
  175. package/build/solana/injected/solana-wallet.d.ts +0 -34
  176. package/build/solana/injected/solana-wallet.js +0 -223
  177. package/build/solana/injected/solana-wallet.js.map +0 -1
  178. package/build/solana/injected/utils.d.ts +0 -32
  179. package/build/solana/injected/utils.js +0 -36
  180. package/build/solana/injected/utils.js.map +0 -1
  181. package/build/solana/wallet.d.ts +0 -40
  182. package/build/solana/wallet.js +0 -181
  183. package/build/solana/wallet.js.map +0 -1
  184. package/build/solana/walletStandartList.d.ts +0 -102
  185. package/build/solana/walletStandartList.js +0 -150
  186. package/build/solana/walletStandartList.js.map +0 -1
  187. package/build/stellar/connector.d.ts +0 -29
  188. package/build/stellar/connector.js +0 -64
  189. package/build/stellar/connector.js.map +0 -1
  190. package/build/stellar/freigher.d.ts +0 -46
  191. package/build/stellar/freigher.js +0 -110
  192. package/build/stellar/freigher.js.map +0 -1
  193. package/build/stellar/hotWallet.d.ts +0 -33
  194. package/build/stellar/hotWallet.js +0 -28
  195. package/build/stellar/hotWallet.js.map +0 -1
  196. package/build/stellar/index.d.ts +0 -6
  197. package/build/stellar/index.js +0 -5
  198. package/build/stellar/index.js.map +0 -1
  199. package/build/stellar/wallet.d.ts +0 -67
  200. package/build/stellar/wallet.js +0 -212
  201. package/build/stellar/wallet.js.map +0 -1
  202. package/build/storage.d.ts +0 -10
  203. package/build/storage.js +0 -12
  204. package/build/storage.js.map +0 -1
  205. package/build/ton/connector.d.ts +0 -24
  206. package/build/ton/connector.js +0 -111
  207. package/build/ton/connector.js.map +0 -1
  208. package/build/ton/index.d.ts +0 -7
  209. package/build/ton/index.js +0 -5
  210. package/build/ton/index.js.map +0 -1
  211. package/build/ton/injected.d.ts +0 -1
  212. package/build/ton/injected.js +0 -49
  213. package/build/ton/injected.js.map +0 -1
  214. package/build/ton/utils.d.ts +0 -45
  215. package/build/ton/utils.js +0 -63
  216. package/build/ton/utils.js.map +0 -1
  217. package/build/ton/wallet.d.ts +0 -54
  218. package/build/ton/wallet.js +0 -138
  219. package/build/ton/wallet.js.map +0 -1
  220. package/build/tron/connector.d.ts +0 -51
  221. package/build/tron/connector.js +0 -65
  222. package/build/tron/connector.js.map +0 -1
  223. package/build/tron/index.d.ts +0 -6
  224. package/build/tron/index.js +0 -5
  225. package/build/tron/index.js.map +0 -1
  226. package/build/tron/wallet.d.ts +0 -52
  227. package/build/tron/wallet.js +0 -122
  228. package/build/tron/wallet.js.map +0 -1
  229. package/build/ui/Popup.d.ts +0 -12
  230. package/build/ui/Popup.js +0 -43
  231. package/build/ui/Popup.js.map +0 -1
  232. package/build/ui/Toast.d.ts +0 -4
  233. package/build/ui/Toast.js +0 -33
  234. package/build/ui/Toast.js.map +0 -1
  235. package/build/ui/connect/AuthPopup.d.ts +0 -2
  236. package/build/ui/connect/AuthPopup.js +0 -48
  237. package/build/ui/connect/AuthPopup.js.map +0 -1
  238. package/build/ui/connect/ConnectWallet.d.ts +0 -14
  239. package/build/ui/connect/ConnectWallet.js +0 -22
  240. package/build/ui/connect/ConnectWallet.js.map +0 -1
  241. package/build/ui/connect/LogoutPopup.d.ts +0 -10
  242. package/build/ui/connect/LogoutPopup.js +0 -8
  243. package/build/ui/connect/LogoutPopup.js.map +0 -1
  244. package/build/ui/connect/PrimaryWallet.d.ts +0 -6
  245. package/build/ui/connect/PrimaryWallet.js +0 -18
  246. package/build/ui/connect/PrimaryWallet.js.map +0 -1
  247. package/build/ui/connect/WCPopup.d.ts +0 -13
  248. package/build/ui/connect/WCPopup.js +0 -81
  249. package/build/ui/connect/WCPopup.js.map +0 -1
  250. package/build/ui/connect/WCRequest.d.ts +0 -9
  251. package/build/ui/connect/WCRequest.js +0 -13
  252. package/build/ui/connect/WCRequest.js.map +0 -1
  253. package/build/ui/connect/WalletPicker.d.ts +0 -11
  254. package/build/ui/connect/WalletPicker.js +0 -48
  255. package/build/ui/connect/WalletPicker.js.map +0 -1
  256. package/build/ui/icons/arrow-right.d.ts +0 -1
  257. package/build/ui/icons/arrow-right.js +0 -5
  258. package/build/ui/icons/arrow-right.js.map +0 -1
  259. package/build/ui/icons/close.d.ts +0 -1
  260. package/build/ui/icons/close.js +0 -5
  261. package/build/ui/icons/close.js.map +0 -1
  262. package/build/ui/icons/exchange.d.ts +0 -6
  263. package/build/ui/icons/exchange.js +0 -6
  264. package/build/ui/icons/exchange.js.map +0 -1
  265. package/build/ui/icons/logout.d.ts +0 -1
  266. package/build/ui/icons/logout.js +0 -3
  267. package/build/ui/icons/logout.js.map +0 -1
  268. package/build/ui/icons/pending.d.ts +0 -1
  269. package/build/ui/icons/pending.js +0 -5
  270. package/build/ui/icons/pending.js.map +0 -1
  271. package/build/ui/icons/qr.d.ts +0 -1
  272. package/build/ui/icons/qr.js +0 -5
  273. package/build/ui/icons/qr.js.map +0 -1
  274. package/build/ui/icons/search.d.ts +0 -1
  275. package/build/ui/icons/search.js +0 -5
  276. package/build/ui/icons/search.js.map +0 -1
  277. package/build/ui/icons/switch.d.ts +0 -1
  278. package/build/ui/icons/switch.js +0 -5
  279. package/build/ui/icons/switch.js.map +0 -1
  280. package/build/ui/icons/wallet.d.ts +0 -1
  281. package/build/ui/icons/wallet.js +0 -5
  282. package/build/ui/icons/wallet.js.map +0 -1
  283. package/build/ui/payment/Bridge.d.ts +0 -29
  284. package/build/ui/payment/Bridge.js +0 -373
  285. package/build/ui/payment/Bridge.js.map +0 -1
  286. package/build/ui/payment/DepositQR.d.ts +0 -9
  287. package/build/ui/payment/DepositQR.js +0 -56
  288. package/build/ui/payment/DepositQR.js.map +0 -1
  289. package/build/ui/payment/Payment.d.ts +0 -23
  290. package/build/ui/payment/Payment.js +0 -136
  291. package/build/ui/payment/Payment.js.map +0 -1
  292. package/build/ui/payment/Profile.d.ts +0 -8
  293. package/build/ui/payment/Profile.js +0 -110
  294. package/build/ui/payment/Profile.js.map +0 -1
  295. package/build/ui/payment/SelectRecipient.d.ts +0 -14
  296. package/build/ui/payment/SelectRecipient.js +0 -68
  297. package/build/ui/payment/SelectRecipient.js.map +0 -1
  298. package/build/ui/payment/SelectSender.d.ts +0 -13
  299. package/build/ui/payment/SelectSender.js +0 -23
  300. package/build/ui/payment/SelectSender.js.map +0 -1
  301. package/build/ui/payment/SelectToken.d.ts +0 -13
  302. package/build/ui/payment/SelectToken.js +0 -92
  303. package/build/ui/payment/SelectToken.js.map +0 -1
  304. package/build/ui/payment/Stepper.d.ts +0 -13
  305. package/build/ui/payment/Stepper.js +0 -22
  306. package/build/ui/payment/Stepper.js.map +0 -1
  307. package/build/ui/payment/TokenCard.d.ts +0 -25
  308. package/build/ui/payment/TokenCard.js +0 -63
  309. package/build/ui/payment/TokenCard.js.map +0 -1
  310. package/build/ui/router.d.ts +0 -51
  311. package/build/ui/router.js +0 -68
  312. package/build/ui/router.js.map +0 -1
  313. package/build/ui/styles.d.ts +0 -13
  314. package/build/ui/styles.js +0 -290
  315. package/build/ui/styles.js.map +0 -1
  316. package/src/tron/connector.ts +0 -89
  317. package/src/tron/index.ts +0 -7
  318. package/src/tron/wallet.ts +0 -146
  319. package/src/ui/Toast.tsx +0 -45
  320. package/src/ui/connect/PrimaryWallet.tsx +0 -65
  321. package/src/ui/payment/Stepper.tsx +0 -50
  322. /package/src/solana/{walletStandartList.ts → wallets.ts} +0 -0
package/build/activity.js DELETED
@@ -1,87 +0,0 @@
1
- import { computed, makeObservable, observable, runInAction } from "mobx";
2
- import { hex } from "@scure/base";
3
- import { chains, Network, WalletType } from "./core";
4
- export class Activity {
5
- kit;
6
- withdrawals = {};
7
- constructor(kit) {
8
- this.kit = kit;
9
- makeObservable(this, { withdrawals: observable, withdrawalsList: computed });
10
- kit.onConnect(({ wallet }) => this.fetchPendingWithdrawalsByWallet(wallet));
11
- }
12
- get withdrawalsList() {
13
- return Object.values(this.withdrawals).flat();
14
- }
15
- async finishWithdrawal(withdrawal) {
16
- try {
17
- if (withdrawal.loading)
18
- return;
19
- runInAction(() => (withdrawal.loading = true));
20
- if (withdrawal.chain === Network.Stellar) {
21
- if (!this.kit.stellar)
22
- throw new Error("Stellar wallet not connected");
23
- await this.kit.hotBridge.stellar.withdraw({
24
- sendTransaction: (tx) => this.kit.stellar.sendTransaction(tx),
25
- sender: this.kit.stellar.address,
26
- ...withdrawal,
27
- });
28
- }
29
- if (withdrawal.chain === Network.Solana) {
30
- if (!this.kit.solana)
31
- throw new Error("Solana wallet not connected");
32
- const solana = await this.kit.hotBridge.solana();
33
- await solana.withdraw({
34
- sendTransaction: (tx) => this.kit.solana.sendTransaction(tx),
35
- sender: this.kit.solana.address,
36
- ...withdrawal,
37
- });
38
- }
39
- if (withdrawal.chain === Network.Ton || withdrawal.chain === Network.OmniTon) {
40
- if (!this.kit.ton)
41
- throw new Error("Ton wallet not connected");
42
- await this.kit.hotBridge.ton.withdraw({
43
- sendTransaction: (tx) => this.kit.ton.sendTransaction(tx),
44
- refundAddress: this.kit.ton.address,
45
- ...withdrawal,
46
- });
47
- }
48
- if (chains.get(withdrawal.chain).type === WalletType.EVM) {
49
- if (!this.kit.evm)
50
- throw new Error("EVM wallet not connected");
51
- await this.kit.hotBridge.evm.withdraw({
52
- sendTransaction: (tx) => this.kit.evm.sendTransaction(withdrawal.chain, tx),
53
- ...withdrawal,
54
- });
55
- }
56
- if (withdrawal.chain === Network.Gonka) {
57
- if (!this.kit.cosmos)
58
- throw new Error("Gonka wallet not connected");
59
- const cosmos = await this.kit.hotBridge.cosmos();
60
- await cosmos.withdraw({
61
- sendTransaction: (tx) => this.kit.cosmos.sendTransaction(tx),
62
- senderPublicKey: hex.decode(this.kit.cosmos.publicKey),
63
- sender: this.kit.cosmos.address,
64
- ...withdrawal,
65
- });
66
- }
67
- await this.kit.hotBridge.clearPendingWithdrawals([withdrawal]).catch(() => { });
68
- }
69
- finally {
70
- runInAction(() => (withdrawal.loading = false));
71
- const wallet = this.kit.wallets.find((w) => w.type === chains.get(withdrawal.chain).type);
72
- if (wallet)
73
- this.fetchPendingWithdrawalsByChain(withdrawal.chain, wallet);
74
- }
75
- }
76
- async fetchPendingWithdrawalsByWallet(wallet) {
77
- if (wallet.type === WalletType.NEAR)
78
- return;
79
- const tasks = chains.getByType(wallet.type).map((t) => this.fetchPendingWithdrawalsByChain(t.id, wallet));
80
- await Promise.all(tasks);
81
- }
82
- async fetchPendingWithdrawalsByChain(chain, wallet) {
83
- const pendings = await this.kit.hotBridge.getPendingWithdrawalsWithStatus(chain, wallet.address);
84
- runInAction(() => (this.withdrawals[chain] = pendings.filter((t) => !t.completed)));
85
- }
86
- }
87
- //# sourceMappingURL=activity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"activity.js","sourceRoot":"","sources":["../src/activity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AACzE,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAIrD,MAAM,OAAO,QAAQ;IAGU;IAF7B,WAAW,GAAwE,EAAE,CAAC;IAEtF,YAA6B,GAAiB;QAAjB,QAAG,GAAH,GAAG,CAAc;QAC5C,cAAc,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC7E,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,+BAA+B,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,UAA2D;QAChF,IAAI,CAAC;YACH,IAAI,UAAU,CAAC,OAAO;gBAAE,OAAO;YAC/B,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC;YAE/C,IAAI,UAAU,CAAC,KAAK,KAAK,OAAO,CAAC,OAAO,EAAE,CAAC;gBACzC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAA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C,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACtF,CAAC;CACF"}
@@ -1,100 +0,0 @@
1
- import type { HotConnector } from "../HotConnector";
2
- import type { OmniWallet } from "../OmniWallet";
3
- import type { Intent, Commitment } from "./types";
4
- import { OmniToken } from "./chains";
5
- import { BridgeReview } from "../exchange";
6
- export declare const TGAS = 1000000000000n;
7
- export declare class Intents {
8
- readonly wibe3?: HotConnector | undefined;
9
- constructor(wibe3?: HotConnector | undefined);
10
- static get builder(): Intents;
11
- signedHashes: string[];
12
- commitments: Commitment[];
13
- need: Map<OmniToken, bigint>;
14
- signer?: OmniWallet;
15
- unsignedCommitment?: {
16
- intents: Intent[];
17
- nonce?: Uint8Array;
18
- deadline?: Date;
19
- };
20
- addIntent(intent: Intent): this;
21
- addNeed(token: OmniToken, amount: bigint): this;
22
- authCall(args: {
23
- contractId: string;
24
- msg: string;
25
- attachNear: bigint;
26
- tgas: number;
27
- }): this;
28
- /**
29
- * Use this method to pay for a merchant's item created in pay.hot-labs.org
30
- */
31
- merchantPayment({ merchantId, token, itemId, email, amount, memo }: {
32
- token: OmniToken;
33
- merchantId: string;
34
- itemId: string;
35
- amount: number | bigint;
36
- memo: string;
37
- email: string;
38
- }): Promise<string | undefined>;
39
- transfer(args: {
40
- recipient: string;
41
- token: OmniToken;
42
- amount: number | bigint;
43
- memo?: string;
44
- msg?: string;
45
- tgas?: number;
46
- }): this;
47
- batchTransfer(args: {
48
- recipient: string;
49
- tokens: Record<OmniToken, number | bigint>;
50
- memo?: string;
51
- msg?: string;
52
- tgas?: number;
53
- }): this;
54
- tokenDiff(args: Record<string, bigint | number>): this;
55
- addRawIntent(rawIntent: Intent): this;
56
- addPublicKey(publicKey: string): this;
57
- removePublicKey(publicKey: string): this;
58
- withdraw(args: {
59
- token: string;
60
- amount: number | bigint;
61
- receiver: string;
62
- memo?: string;
63
- msg?: string;
64
- tgas?: number;
65
- }): this;
66
- attachHashes(hashes: string[]): this;
67
- attachWallet(wallet?: OmniWallet): this;
68
- attachDeadline(deadline: Date): this;
69
- attachNonce(nonce: Uint8Array): this;
70
- attachTimeout(seconds: number): this;
71
- attachSeed(seed: string): this;
72
- attachCommitment(commitment: Commitment): this;
73
- take(token: string, amount: number | bigint): this;
74
- give(token: string, amount: number | bigint): this;
75
- signSequence(): Promise<Commitment[]>;
76
- sign(): Promise<this>;
77
- simulate(): Promise<any>;
78
- setupSigner(): Promise<OmniWallet>;
79
- openSignFlow({ title, allowedTokens, onConfirm }: {
80
- title?: string;
81
- allowedTokens?: string[];
82
- onConfirm: (args: {
83
- depositQoute?: BridgeReview;
84
- processing?: () => Promise<BridgeReview>;
85
- }) => Promise<void>;
86
- }): Promise<void>;
87
- depositAndExecute({ title, message, allowedTokens, serverSideProcessing, payload }?: {
88
- title?: string;
89
- message?: string;
90
- allowedTokens?: string[];
91
- serverSideProcessing?: boolean;
92
- payload?: Record<string, any>;
93
- }): Promise<string | undefined>;
94
- execute(): Promise<string>;
95
- static publish(signed: Commitment[], hashes?: string[]): Promise<string>;
96
- static hasPublicKey(accountId: string, publicKey: string): Promise<boolean>;
97
- static simulateIntents(signed: Commitment[]): Promise<any>;
98
- static getIntentsBalances(assets: string[], accountId: string): Promise<Record<string, bigint>>;
99
- static getIntentsAssets(accountId: string): Promise<string[]>;
100
- }
@@ -1,472 +0,0 @@
1
- import { sha256 } from "@noble/hashes/sha2.js";
2
- import { rpc } from "../near/rpc";
3
- import { OmniToken } from "./chains";
4
- import { tokens } from "./tokens";
5
- import { api } from "./api";
6
- import { openConnector, openConnectPrimaryWallet, openPayment, openToast } from "../ui/router";
7
- import { formatter } from "./utils";
8
- export const TGAS = 1000000000000n;
9
- export class Intents {
10
- wibe3;
11
- constructor(wibe3) {
12
- this.wibe3 = wibe3;
13
- }
14
- static get builder() {
15
- return new Intents();
16
- }
17
- signedHashes = [];
18
- commitments = [];
19
- need = new Map();
20
- signer;
21
- unsignedCommitment;
22
- addIntent(intent) {
23
- if (!this.unsignedCommitment)
24
- this.unsignedCommitment = { intents: [] };
25
- this.unsignedCommitment.intents.push(intent);
26
- return this;
27
- }
28
- addNeed(token, amount) {
29
- if (!this.need.has(token))
30
- this.need.set(token, 0n);
31
- this.need.set(token, this.need.get(token) + amount);
32
- return this;
33
- }
34
- authCall(args) {
35
- this.addNeed(OmniToken.NEAR, args.attachNear);
36
- this.addIntent({
37
- min_gas: (BigInt(args.tgas) * TGAS).toString(),
38
- attached_deposit: args.attachNear.toString(),
39
- contract_id: args.contractId,
40
- intent: "auth_call",
41
- msg: args.msg,
42
- });
43
- return this;
44
- }
45
- /**
46
- * Use this method to pay for a merchant's item created in pay.hot-labs.org
47
- */
48
- merchantPayment({ merchantId, token, itemId, email, amount, memo }) {
49
- return this.transfer({
50
- msg: JSON.stringify({ merchant_id: merchantId, item_id: itemId, memo: memo }),
51
- recipient: "pay.fi.tg",
52
- amount,
53
- token,
54
- }).depositAndExecute({
55
- title: `Pay ${this.wibe3?.omni(token).readable(amount)} ${this.wibe3?.omni(token).symbol}`,
56
- serverSideProcessing: true,
57
- payload: { email },
58
- });
59
- }
60
- transfer(args) {
61
- const omniToken = tokens.get(args.token);
62
- const amount = (typeof args.amount === "number" ? omniToken.int(args.amount) : args.amount).toString();
63
- const intent = {
64
- min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
65
- tokens: { [omniToken.omniAddress]: amount },
66
- receiver_id: args.recipient.toLowerCase(),
67
- intent: "transfer",
68
- memo: args.memo,
69
- msg: args.msg,
70
- };
71
- this.addNeed(args.token, BigInt(amount));
72
- this.addIntent(intent);
73
- return this;
74
- }
75
- batchTransfer(args) {
76
- const tokensList = {};
77
- for (const [token, amount] of Object.entries(args.tokens)) {
78
- const omniToken = tokens.get(token);
79
- const amountStr = typeof amount === "number" ? omniToken.int(amount).toString() : amount.toString();
80
- tokensList[omniToken.omniAddress] = amountStr;
81
- this.addNeed(token, BigInt(amountStr));
82
- }
83
- const intent = {
84
- intent: "transfer",
85
- receiver_id: args.recipient.toLowerCase(),
86
- min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
87
- tokens: tokensList,
88
- memo: args.memo,
89
- msg: args.msg,
90
- };
91
- this.addIntent(intent);
92
- return this;
93
- }
94
- tokenDiff(args) {
95
- const parse = (token, amount) => {
96
- if (typeof amount === "number")
97
- return [token.toString(), tokens.get(token).int(amount).toString()];
98
- return [token.toString(), amount.toString()];
99
- };
100
- const intent = {
101
- diff: Object.fromEntries(Object.entries(args).map(([token, amount]) => parse(token, amount))),
102
- intent: "token_diff",
103
- };
104
- for (const [token, amountStr] of Object.entries(intent.diff)) {
105
- const amount = BigInt(amountStr);
106
- if (amount < 0n) {
107
- const tokenKey = token;
108
- this.addNeed(tokenKey, -amount);
109
- }
110
- }
111
- this.addIntent(intent);
112
- return this;
113
- }
114
- addRawIntent(rawIntent) {
115
- if (!rawIntent.intent)
116
- throw new Error("Intent must have 'intent' field");
117
- const intentType = rawIntent.intent;
118
- if (intentType === "token_diff") {
119
- const tokenDiffArgs = {};
120
- for (const [token, amountStr] of Object.entries(rawIntent.diff)) {
121
- tokenDiffArgs[token] = BigInt(amountStr);
122
- }
123
- return this.tokenDiff(tokenDiffArgs);
124
- }
125
- if (intentType === "transfer") {
126
- const tokens = {};
127
- for (const [token, amount] of Object.entries(rawIntent.tokens)) {
128
- tokens[token] = BigInt(amount);
129
- }
130
- return this.batchTransfer({
131
- tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
132
- recipient: rawIntent.receiver_id,
133
- memo: rawIntent.memo,
134
- msg: rawIntent.msg,
135
- tokens,
136
- });
137
- }
138
- if (intentType === "mt_withdraw") {
139
- for (let i = 0; i < rawIntent.amounts.length; i++) {
140
- const token = `nep245:${rawIntent.token}:${rawIntent.token_ids[i]}`;
141
- this.addNeed(token, BigInt(rawIntent.amounts[i]));
142
- }
143
- this.addIntent({
144
- intent: "mt_withdraw",
145
- amounts: rawIntent.amounts,
146
- receiver_id: rawIntent.receiver_id,
147
- token_ids: rawIntent.token_ids,
148
- token: rawIntent.token,
149
- memo: rawIntent.memo,
150
- msg: rawIntent.msg,
151
- min_gas: rawIntent.min_gas,
152
- });
153
- return this;
154
- }
155
- if (intentType === "ft_withdraw") {
156
- return this.withdraw({
157
- token: `nep141:${rawIntent.token}`,
158
- amount: BigInt(rawIntent.amount),
159
- receiver: rawIntent.receiver_id,
160
- memo: rawIntent.memo,
161
- msg: rawIntent.msg,
162
- });
163
- }
164
- if (intentType === "auth_call") {
165
- return this.authCall({
166
- attachNear: BigInt(rawIntent.attached_deposit),
167
- tgas: Number(BigInt(rawIntent.min_gas) / TGAS),
168
- contractId: rawIntent.contract_id,
169
- msg: rawIntent.msg,
170
- });
171
- }
172
- if (intentType === "add_public_key") {
173
- return this.addPublicKey(rawIntent.public_key);
174
- }
175
- if (intentType === "remove_public_key") {
176
- return this.removePublicKey(rawIntent.public_key);
177
- }
178
- if (intentType === "nft_withdraw") {
179
- return this.withdraw({
180
- token: rawIntent.token_id,
181
- receiver: rawIntent.receiver_id,
182
- memo: rawIntent.memo,
183
- msg: rawIntent.msg,
184
- tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
185
- amount: 1n,
186
- });
187
- }
188
- throw new Error(`Unsupported intent type: ${intentType}`);
189
- }
190
- addPublicKey(publicKey) {
191
- this.addIntent({ intent: "add_public_key", public_key: publicKey });
192
- return this;
193
- }
194
- removePublicKey(publicKey) {
195
- this.addIntent({ intent: "remove_public_key", public_key: publicKey });
196
- return this;
197
- }
198
- withdraw(args) {
199
- const omniToken = tokens.get(args.token);
200
- const amount = (typeof args.amount === "number" ? omniToken.int(args.amount) : args.amount).toString();
201
- const [standart, ...tokenParts] = args.token.split(":");
202
- this.addNeed(args.token, BigInt(amount));
203
- if (standart === "nep245") {
204
- const mtContract = tokenParts[0];
205
- const tokenId = tokenParts.slice(1).join(":");
206
- this.addIntent({
207
- intent: "mt_withdraw",
208
- amounts: [amount],
209
- receiver_id: args.receiver,
210
- token_ids: [tokenId],
211
- token: mtContract,
212
- memo: args.memo,
213
- msg: args.msg,
214
- min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
215
- });
216
- return this;
217
- }
218
- if (standart === "nep141") {
219
- this.addIntent({
220
- intent: "ft_withdraw",
221
- receiver_id: args.receiver,
222
- token: tokenParts.join(":"),
223
- amount: amount,
224
- memo: args.memo,
225
- msg: args.msg,
226
- });
227
- return this;
228
- }
229
- if (standart === "nep171") {
230
- this.addIntent({
231
- intent: "nft_withdraw",
232
- receiver_id: args.receiver,
233
- token_id: tokenParts.join(":"),
234
- min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
235
- memo: args.memo,
236
- msg: args.msg,
237
- });
238
- return this;
239
- }
240
- throw new Error(`Unsupported token: ${args.token}`);
241
- }
242
- attachHashes(hashes) {
243
- this.signedHashes.push(...hashes);
244
- return this;
245
- }
246
- attachWallet(wallet) {
247
- this.signer = wallet;
248
- return this;
249
- }
250
- attachDeadline(deadline) {
251
- if (!this.unsignedCommitment)
252
- this.unsignedCommitment = { intents: [] };
253
- this.unsignedCommitment.deadline = deadline;
254
- return this;
255
- }
256
- attachNonce(nonce) {
257
- if (!this.unsignedCommitment)
258
- this.unsignedCommitment = { intents: [] };
259
- this.unsignedCommitment.nonce = nonce;
260
- return this;
261
- }
262
- attachTimeout(seconds) {
263
- if (!this.unsignedCommitment)
264
- this.unsignedCommitment = { intents: [] };
265
- this.unsignedCommitment.deadline = new Date(Date.now() + seconds * 1000);
266
- return this;
267
- }
268
- attachSeed(seed) {
269
- if (!this.unsignedCommitment)
270
- this.unsignedCommitment = { intents: [] };
271
- this.unsignedCommitment.nonce = new Uint8Array(sha256(new TextEncoder().encode(seed))).slice(0, 32);
272
- return this;
273
- }
274
- attachCommitment(commitment) {
275
- this.commitments.push(commitment);
276
- return this;
277
- }
278
- take(token, amount) {
279
- const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
280
- // this.addNeed(token, -intAmount); Do we need to add the need here?
281
- const tokenDiff = this.unsignedCommitment?.intents.find((intent) => intent.intent === "token_diff");
282
- if (tokenDiff)
283
- tokenDiff.diff[token.toString()] = intAmount.toString();
284
- else
285
- this.addIntent({ intent: "token_diff", diff: { [token.toString()]: intAmount.toString() } });
286
- return this;
287
- }
288
- give(token, amount) {
289
- const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
290
- this.addNeed(token, intAmount);
291
- const tokenDiff = this.unsignedCommitment?.intents.find((intent) => intent.intent === "token_diff");
292
- if (tokenDiff)
293
- tokenDiff.diff[token.toString()] = (-intAmount).toString();
294
- else
295
- this.addIntent({ intent: "token_diff", diff: { [token.toString()]: (-intAmount).toString() } });
296
- return this;
297
- }
298
- async signSequence() {
299
- const signer = this.signer;
300
- if (!signer)
301
- throw new Error("No signer attached");
302
- if (!signer.omniAddress)
303
- throw new Error("No omni address");
304
- const commitments = [];
305
- for (const intent of this.unsignedCommitment?.intents || []) {
306
- commitments.push(await signer.signIntents([intent], {
307
- deadline: this.unsignedCommitment?.deadline ? +this.unsignedCommitment.deadline : undefined,
308
- nonce: this.unsignedCommitment?.nonce,
309
- }));
310
- }
311
- return commitments;
312
- }
313
- async sign() {
314
- const signer = this.signer;
315
- if (!signer)
316
- throw new Error("No signer attached");
317
- if (!signer.omniAddress)
318
- throw new Error("No omni address");
319
- const commitment = await signer.signIntents(this.unsignedCommitment?.intents || [], {
320
- deadline: this.unsignedCommitment?.deadline ? +this.unsignedCommitment.deadline : undefined,
321
- nonce: this.unsignedCommitment?.nonce,
322
- });
323
- this.unsignedCommitment = undefined;
324
- this.commitments.push(commitment);
325
- return this;
326
- }
327
- async simulate() {
328
- if (this.commitments.length === 0)
329
- throw new Error("No commitments attached");
330
- return await Intents.simulateIntents(this.commitments);
331
- }
332
- async setupSigner() {
333
- if (!this.wibe3)
334
- throw new Error("No wibe3 attached");
335
- if (this.signer)
336
- return this.signer;
337
- if (this.wibe3.priorityWallet) {
338
- this.signer = this.wibe3.priorityWallet;
339
- return this.signer;
340
- }
341
- if (this.wibe3.wallets.length > 0)
342
- await openConnectPrimaryWallet(this.wibe3);
343
- else
344
- await openConnector(this.wibe3);
345
- if (this.wibe3.priorityWallet == undefined)
346
- throw new Error("No signer attached");
347
- this.signer = this.wibe3.priorityWallet;
348
- return this.signer;
349
- }
350
- async openSignFlow({ title, allowedTokens, onConfirm }) {
351
- if (!this.wibe3)
352
- throw "Attach wibe3";
353
- if (!this.signer)
354
- throw "Attach signer";
355
- // TODO: Handle multiple payables
356
- const payableToken = tokens.get(Array.from(this.need.keys())[0]);
357
- const payableAmount = this.need.get(payableToken.omniAddress) || 0n;
358
- const balance = await this.wibe3.fetchToken(payableToken, this.signer);
359
- const prepaidAmount = formatter.bigIntMin(payableAmount, balance);
360
- return await openPayment(this.wibe3, {
361
- onConfirm,
362
- needAmount: payableAmount - prepaidAmount,
363
- allowedTokens,
364
- prepaidAmount,
365
- payableToken,
366
- intents: this,
367
- title,
368
- });
369
- }
370
- async depositAndExecute({ title = "Payment", message, allowedTokens, serverSideProcessing, payload } = {}) {
371
- await this.setupSigner();
372
- if (this.need.size === 0)
373
- return this.execute();
374
- await this.openSignFlow({
375
- title,
376
- allowedTokens,
377
- onConfirm: async ({ depositQoute, processing }) => {
378
- if (!serverSideProcessing)
379
- return;
380
- let depositAddress;
381
- if (depositQoute?.qoute === "deposit")
382
- await processing?.();
383
- else if (depositQoute?.qoute === "withdraw")
384
- await processing?.();
385
- else
386
- depositAddress = depositQoute?.qoute?.depositAddress;
387
- await api.yieldIntentCall({
388
- depositAddress: depositAddress,
389
- commitment: this.commitments[0],
390
- payload: payload || {},
391
- });
392
- },
393
- });
394
- if (serverSideProcessing)
395
- return;
396
- const close = openToast(message || "Executing payment");
397
- await this.execute().finally(() => close());
398
- }
399
- async execute() {
400
- if (this.unsignedCommitment != null)
401
- await this.sign();
402
- const task = Intents.publish(this.commitments, this.signedHashes);
403
- this.commitments = [];
404
- this.signedHashes = [];
405
- const hash = await task;
406
- await rpc.waitTransactionResult(hash, "intents.near");
407
- return hash;
408
- }
409
- static async publish(signed, hashes = []) {
410
- const result = await api.publishIntents(signed, hashes);
411
- if (result.status === "FAILED")
412
- throw result.reason;
413
- const intentResult = result.intent_hashes[0];
414
- const getStatus = async () => {
415
- const statusResult = await api.getIntentsStatus(intentResult);
416
- return statusResult;
417
- };
418
- const fetchResult = async () => {
419
- await new Promise((resolve) => setTimeout(resolve, 1000));
420
- const result = await getStatus().catch(() => null);
421
- if (result == null)
422
- return await fetchResult();
423
- if (result.status === "SETTLED")
424
- return result.data.hash;
425
- if (result.status === "FAILED")
426
- throw result.reason || "Failed to publish intents";
427
- return await fetchResult();
428
- };
429
- const hash = await fetchResult();
430
- return hash;
431
- }
432
- static async hasPublicKey(accountId, publicKey) {
433
- return await rpc.viewMethod({
434
- args: { account_id: accountId, public_key: publicKey },
435
- methodName: "has_public_key",
436
- contractId: "intents.near",
437
- });
438
- }
439
- static async simulateIntents(signed) {
440
- return await rpc.viewMethod({
441
- args: { signed: signed },
442
- methodName: "simulate_intents",
443
- contractId: "intents.near",
444
- });
445
- }
446
- static async getIntentsBalances(assets, accountId) {
447
- const balances = await rpc.viewMethod({
448
- args: { token_ids: assets, account_id: accountId },
449
- methodName: "mt_batch_balance_of",
450
- contractId: "intents.near",
451
- });
452
- return Object.fromEntries(assets.map((asset, index) => [asset, BigInt(balances[index] || 0n)]));
453
- }
454
- static async getIntentsAssets(accountId) {
455
- const assets = [];
456
- const limit = 250;
457
- let fromIndex = 0n;
458
- for (;;) {
459
- const balances = await rpc.viewMethod({
460
- args: { account_id: accountId, from_index: fromIndex.toString(), limit },
461
- methodName: "mt_tokens_for_owner",
462
- contractId: "intents.near",
463
- });
464
- assets.push(...balances.map((b) => b.token_id));
465
- if (balances.length < limit)
466
- break;
467
- fromIndex += BigInt(limit);
468
- }
469
- return assets;
470
- }
471
- }
472
- //# sourceMappingURL=Intents.js.map