@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
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ export { Network, OmniToken, WalletType } from "./omni/config";
2
+ export { formatter } from "./omni/utils";
3
+ export { EventEmitter } from "./events";
4
+
5
+ export { OmniWallet } from "./OmniWallet";
6
+ export { OmniConnector } from "./OmniConnector";
7
+ export { Intents } from "./omni/Intents";
8
+ export { Token } from "./omni/token";
9
+ export { TGAS } from "./omni/nearRpc";
10
+
11
+ export { default as EvmConnector } from "./evm/connector";
12
+ export { default as SolanaConnector } from "./solana/connector";
13
+ export { default as StellarConnector } from "./stellar/connector";
14
+ export { default as TonConnector } from "./ton/connector";
15
+ export { default as NearConnector } from "./near/connector";
16
+ export { default as CosmosConnector } from "./cosmos/connector";
17
+
18
+ export { default as EvmWallet } from "./evm/wallet";
19
+ export { default as SolanaWallet } from "./solana/wallet";
20
+ export { default as StellarWallet } from "./stellar/wallet";
21
+ export { default as TonWallet } from "./ton/wallet";
22
+ export { default as NearWallet } from "./near/wallet";
23
+ export { default as CosmosWallet } from "./cosmos/wallet";
24
+
25
+ export { near, evm, solana, stellar, ton, google } from "./HotConnector";
26
+ export { HotConnector } from "./HotConnector";
27
+
28
+ import "./hot-wallet";
29
+
30
+ export { Bridge as BridgeWidget } from "./ui/payment/Bridge";
@@ -0,0 +1,71 @@
1
+ import { NearConnector } from "@hot-labs/near-connect";
2
+ import { runInAction } from "mobx";
3
+
4
+ import { WalletType } from "../omni/config";
5
+ import { ConnectorType, OmniConnector } from "../OmniConnector";
6
+ import { HotConnector } from "../HotConnector";
7
+ import NearWallet from "./wallet";
8
+
9
+ export interface NearConnectorOptions {
10
+ connector?: NearConnector;
11
+ projectId?: string;
12
+ metadata?: {
13
+ name: string;
14
+ description: string;
15
+ url: string;
16
+ icons: string[];
17
+ };
18
+ }
19
+
20
+ class Connector extends OmniConnector<NearWallet> {
21
+ connector: NearConnector;
22
+ type = ConnectorType.WALLET;
23
+ walletTypes = [WalletType.NEAR, WalletType.OMNI];
24
+ icon = "https://storage.herewallet.app/upload/73a44e583769f11112b0eff1f2dd2a560c05eed5f6d92f0c03484fa047c31668.png";
25
+ name = "NEAR Wallet";
26
+ id = "near";
27
+
28
+ constructor(readonly wibe3: HotConnector, options?: NearConnectorOptions) {
29
+ super(wibe3);
30
+
31
+ this.connector =
32
+ options?.connector ||
33
+ new NearConnector({
34
+ network: "mainnet",
35
+ walletConnect: options?.projectId ? { projectId: options.projectId, metadata: options.metadata } : undefined,
36
+ });
37
+
38
+ this.connector.on("wallet:signOut", () => this.removeWallet());
39
+ this.connector.getConnectedWallet().then(async ({ wallet }) => {
40
+ const [account] = await wallet.getAccounts();
41
+ if (account) this.setWallet(new NearWallet(this, account.accountId, account.publicKey, wallet));
42
+ });
43
+
44
+ this.connector.whenManifestLoaded.then(() => {
45
+ runInAction(() => {
46
+ this.options = this.connector.wallets.map((w) => ({
47
+ download: w.manifest.website,
48
+ name: w.manifest.name,
49
+ icon: w.manifest.icon,
50
+ id: w.manifest.id,
51
+ type: "external" as const,
52
+ }));
53
+ });
54
+ });
55
+ }
56
+
57
+ async connect(id: string) {
58
+ const wallet = await this.connector.connect(id);
59
+ if (!wallet) throw new Error("Wallet not found");
60
+ const [account] = await wallet.getAccounts();
61
+ if (!account) throw new Error("No account found");
62
+ return this.setWallet(new NearWallet(this, account.accountId, account.publicKey, wallet));
63
+ }
64
+
65
+ async disconnect() {
66
+ super.disconnect();
67
+ this.connector.disconnect();
68
+ }
69
+ }
70
+
71
+ export default Connector;
@@ -0,0 +1,255 @@
1
+ import { NearWalletBase, SignMessageParams, SignedMessage, SignAndSendTransactionParams } from "@hot-labs/near-connect";
2
+ import { base64, base58, hex } from "@scure/base";
3
+ import { Action } from "@near-js/transactions";
4
+
5
+ import { OmniConnector } from "../OmniConnector";
6
+ import { OmniWallet } from "../OmniWallet";
7
+ import { WalletType } from "../omni/config";
8
+ import { ReviewFee } from "../omni/bridge";
9
+ import { rpc, TGAS } from "../omni/nearRpc";
10
+ import { Token } from "../omni/token";
11
+
12
+ export default class NearWallet extends OmniWallet {
13
+ readonly type = WalletType.NEAR;
14
+
15
+ constructor(readonly connector: OmniConnector, readonly address: string, readonly publicKey?: string, readonly wallet?: NearWalletBase) {
16
+ super(connector);
17
+ }
18
+
19
+ get omniAddress() {
20
+ return this.address;
21
+ }
22
+
23
+ async disconnect() {
24
+ await this.wallet?.signOut();
25
+ super.disconnect();
26
+ }
27
+
28
+ async fetchBalances(_: number, whitelist: string[]): Promise<Record<string, bigint>> {
29
+ const balances = await Promise.all(
30
+ whitelist.map(async (token) => {
31
+ const balance = await this.fetchBalance(1010, token);
32
+ return [token, balance];
33
+ })
34
+ );
35
+
36
+ return Object.fromEntries(balances);
37
+ }
38
+
39
+ async sendTransaction(params: SignAndSendTransactionParams): Promise<string> {
40
+ if (!this.wallet) throw "not impl";
41
+ const actions = (params.actions as any).map((action: Action) => {
42
+ if ((action as any)["type"]) return action;
43
+ if (action.functionCall) {
44
+ return {
45
+ type: "FunctionCall",
46
+ params: {
47
+ methodName: action.functionCall.methodName,
48
+ args: JSON.parse(Buffer.from(action.functionCall.args).toString("utf8")),
49
+ gas: String(action.functionCall.gas),
50
+ deposit: String(action.functionCall.deposit),
51
+ },
52
+ };
53
+ }
54
+
55
+ if (action.transfer) {
56
+ return {
57
+ type: "Transfer",
58
+ params: { deposit: String(action.transfer.deposit) },
59
+ };
60
+ }
61
+ });
62
+
63
+ const result = await this.wallet.signAndSendTransaction({ receiverId: params.receiverId, actions });
64
+ return result.transaction.hash;
65
+ }
66
+
67
+ async signMessage(params: SignMessageParams): Promise<SignedMessage> {
68
+ if (!this.wallet) throw "not impl";
69
+ return this.wallet.signMessage(params);
70
+ }
71
+
72
+ public async getWrapNearDepositAction(amount: bigint, address: string) {
73
+ const storage = await rpc.viewMethod({
74
+ contractId: "wrap.near",
75
+ methodName: "storage_balance_of",
76
+ args: { account_id: address },
77
+ });
78
+
79
+ const depositAction = {
80
+ type: "FunctionCall",
81
+ params: {
82
+ methodName: "near_deposit",
83
+ deposit: String(amount),
84
+ gas: String(50n * TGAS),
85
+ args: {},
86
+ },
87
+ };
88
+
89
+ if (storage != null) return [depositAction];
90
+ return [
91
+ {
92
+ type: "FunctionCall",
93
+ params: {
94
+ gas: 30n * TGAS,
95
+ methodName: "storage_deposit",
96
+ deposit: `12500000000000000000000`,
97
+ args: { account_id: address, registration_only: true },
98
+ },
99
+ },
100
+ depositAction,
101
+ ];
102
+ }
103
+
104
+ async needRegisterToken(token: string, address: string): Promise<boolean> {
105
+ const storage = await rpc.viewMethod({ contractId: token, methodName: "storage_balance_of", args: { account_id: address } }).catch(() => null);
106
+ return storage == null;
107
+ }
108
+
109
+ async registerToken(token: string) {
110
+ const isNeedRegister = await this.needRegisterToken(token, this.address);
111
+ if (!isNeedRegister) return;
112
+
113
+ await this.sendTransaction({
114
+ receiverId: token,
115
+ actions: [
116
+ {
117
+ type: "FunctionCall",
118
+ params: {
119
+ methodName: "storage_deposit",
120
+ args: { account_id: this.address, registration_only: true },
121
+ deposit: String(1n),
122
+ gas: String(30n * TGAS),
123
+ },
124
+ },
125
+ ],
126
+ });
127
+ }
128
+
129
+ async transferFee() {
130
+ return new ReviewFee({ baseFee: 0n, gasLimit: 300n * TGAS, chain: 1010 });
131
+ }
132
+
133
+ async fetchBalance(chain: number, address: string) {
134
+ if (chain !== 1010) throw "Invalid chain";
135
+
136
+ if (address === "native") {
137
+ const protocolConfig = await rpc.experimental_protocolConfig({ finality: "near-final" });
138
+ const state = await rpc.viewAccount(this.address, { finality: "near-final" });
139
+ const costPerByte = BigInt(protocolConfig.runtime_config.storage_amount_per_byte);
140
+ const usedOnStorage = BigInt(state.storage_usage) * costPerByte;
141
+ const locked = BigInt(state.locked);
142
+ const total = BigInt(state.amount) + locked;
143
+ const available = total - (locked > usedOnStorage ? locked : usedOnStorage);
144
+ return available < 0n ? 0n : available;
145
+ }
146
+
147
+ const balance = await rpc.viewMethod({
148
+ args: { account_id: this.address },
149
+ contractId: address,
150
+ methodName: "ft_balance_of",
151
+ });
152
+
153
+ return BigInt(balance);
154
+ }
155
+
156
+ async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }) {
157
+ if (args.token.address === "native") {
158
+ return await this.sendTransaction({
159
+ actions: [{ type: "Transfer", params: { deposit: String(args.amount) } }],
160
+ receiverId: args.receiver,
161
+ });
162
+ }
163
+
164
+ const actions: any[] = [
165
+ {
166
+ type: "FunctionCall",
167
+ params: {
168
+ methodName: "ft_transfer",
169
+ args: { receiver_id: args.receiver, amount: String(args.amount) },
170
+ gas: String(30n * TGAS),
171
+ deposit: String(1n),
172
+ },
173
+ },
174
+ ];
175
+
176
+ const needRegister = await this.needRegisterToken(args.token.address, args.receiver);
177
+ if (needRegister)
178
+ actions.unshift({
179
+ type: "FunctionCall",
180
+ params: {
181
+ gas: String(30n * TGAS),
182
+ methodName: "storage_deposit",
183
+ deposit: `12500000000000000000000`,
184
+ args: { account_id: args.receiver, registration_only: true },
185
+ },
186
+ });
187
+
188
+ return await this.sendTransaction({ receiverId: args.token.address, actions });
189
+ }
190
+
191
+ async signIntentsWithAuth(domain: string, intents?: Record<string, any>[]) {
192
+ if (!this.wallet) throw "not impl";
193
+ const accounts = await this.wallet.getAccounts();
194
+ if (accounts.length === 0) throw new Error("No account found");
195
+ const { accountId, publicKey } = accounts[0];
196
+
197
+ const seed = hex.encode(window.crypto.getRandomValues(new Uint8Array(32)));
198
+ const msgBuffer = new TextEncoder().encode(`${domain}_${seed}`);
199
+ const nonce = await window.crypto.subtle.digest("SHA-256", new Uint8Array(msgBuffer));
200
+
201
+ return {
202
+ signed: await this.signIntents(intents || [], { nonce: new Uint8Array(nonce) }),
203
+ chainId: WalletType.NEAR,
204
+ publicKey: publicKey,
205
+ address: accountId,
206
+ domain,
207
+ seed,
208
+ };
209
+ }
210
+
211
+ async signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Record<string, any>> {
212
+ if (!this.wallet) throw "not impl";
213
+
214
+ const nonce = new Uint8Array(options?.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
215
+ const message = JSON.stringify({
216
+ deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
217
+ signer_id: this.omniAddress,
218
+ intents: intents,
219
+ });
220
+
221
+ const result = await this.wallet.signMessage({ message, recipient: "intents.near", nonce });
222
+ if (!result) throw new Error("Failed to sign message");
223
+ const { signature, publicKey } = result;
224
+
225
+ const keys = await rpc.viewMethod({
226
+ contractId: "intents.near",
227
+ methodName: "public_keys_of",
228
+ args: { account_id: this.address },
229
+ });
230
+
231
+ if (!keys.includes(publicKey)) {
232
+ await this.sendTransaction({
233
+ receiverId: "intents.near",
234
+ actions: [
235
+ {
236
+ type: "FunctionCall",
237
+ params: {
238
+ methodName: "add_public_key",
239
+ args: { public_key: publicKey },
240
+ gas: String(80n * TGAS),
241
+ deposit: String(1n),
242
+ },
243
+ },
244
+ ],
245
+ });
246
+ }
247
+
248
+ return {
249
+ standard: "nep413",
250
+ payload: { nonce: base64.encode(nonce), recipient: "intents.near", message },
251
+ signature: signature.includes("ed25519:") ? signature : `ed25519:${base58.encode(base64.decode(signature))}`,
252
+ public_key: publicKey,
253
+ };
254
+ }
255
+ }