@hot-labs/kit 1.0.56 → 1.1.0-beta.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 (214) hide show
  1. package/README.md +2 -9
  2. package/build/HotConnector.d.ts +6 -6
  3. package/build/HotConnector.js +18 -23
  4. package/build/HotConnector.js.map +1 -1
  5. package/build/OmniConnector.d.ts +4 -0
  6. package/build/OmniConnector.js +5 -5
  7. package/build/OmniConnector.js.map +1 -1
  8. package/build/OmniWallet.d.ts +10 -17
  9. package/build/OmniWallet.js +14 -19
  10. package/build/OmniWallet.js.map +1 -1
  11. package/build/core/Intents.d.ts +23 -39
  12. package/build/core/Intents.js +104 -115
  13. package/build/core/Intents.js.map +1 -1
  14. package/build/core/api.d.ts +1 -0
  15. package/build/core/api.js +10 -2
  16. package/build/core/api.js.map +1 -1
  17. package/build/core/bridge.js +1 -1
  18. package/build/core/bridge.js.map +1 -1
  19. package/build/core/chains.js +1 -1
  20. package/build/core/chains.js.map +1 -1
  21. package/build/core/index.d.ts +1 -1
  22. package/build/core/index.js +1 -1
  23. package/build/core/index.js.map +1 -1
  24. package/build/core/types.d.ts +17 -0
  25. package/build/core/utils.d.ts +1 -0
  26. package/build/core/utils.js +10 -0
  27. package/build/core/utils.js.map +1 -1
  28. package/build/cosmos/connector.js +2 -2
  29. package/build/cosmos/connector.js.map +1 -1
  30. package/build/cosmos/wallet.d.ts +2 -4
  31. package/build/cosmos/wallet.js +3 -8
  32. package/build/cosmos/wallet.js.map +1 -1
  33. package/build/evm/connector.d.ts +2 -3
  34. package/build/evm/connector.js +7 -11
  35. package/build/evm/connector.js.map +1 -1
  36. package/build/evm/injected.js +3 -3
  37. package/build/evm/injected.js.map +1 -1
  38. package/build/evm/wallet.d.ts +2 -1
  39. package/build/evm/wallet.js +7 -5
  40. package/build/evm/wallet.js.map +1 -1
  41. package/build/exchange.d.ts +4 -1
  42. package/build/exchange.js +21 -20
  43. package/build/exchange.js.map +1 -1
  44. package/build/hot-wallet/google.js +10 -5
  45. package/build/hot-wallet/google.js.map +1 -1
  46. package/build/hot-wallet/iframe.d.ts +36 -3
  47. package/build/hot-wallet/iframe.js +134 -27
  48. package/build/hot-wallet/iframe.js.map +1 -1
  49. package/build/hot-wallet/proxy.d.ts +8 -0
  50. package/build/hot-wallet/proxy.js +45 -0
  51. package/build/hot-wallet/proxy.js.map +1 -0
  52. package/build/index.d.ts +1 -0
  53. package/build/index.js +1 -0
  54. package/build/index.js.map +1 -1
  55. package/build/near/connector.js +2 -2
  56. package/build/near/connector.js.map +1 -1
  57. package/build/{core/nearRpc.d.ts → near/rpc.d.ts} +0 -1
  58. package/build/{core/nearRpc.js → near/rpc.js} +5 -11
  59. package/build/near/rpc.js.map +1 -0
  60. package/build/near/wallet.d.ts +2 -4
  61. package/build/near/wallet.js +4 -9
  62. package/build/near/wallet.js.map +1 -1
  63. package/build/solana/{protocol.d.ts → WalletStandard.d.ts} +1 -1
  64. package/build/solana/{protocol.js → WalletStandard.js} +1 -1
  65. package/build/solana/WalletStandard.js.map +1 -0
  66. package/build/solana/connector.d.ts +1 -1
  67. package/build/solana/connector.js +11 -10
  68. package/build/solana/connector.js.map +1 -1
  69. package/build/solana/injected/account.js +1 -2
  70. package/build/solana/injected/account.js.map +1 -1
  71. package/build/solana/injected/index.js +16 -19
  72. package/build/solana/injected/index.js.map +1 -1
  73. package/build/solana/injected/solana-wallet.js.map +1 -1
  74. package/build/solana/wallet.d.ts +3 -5
  75. package/build/solana/wallet.js +3 -8
  76. package/build/solana/wallet.js.map +1 -1
  77. package/build/solana/{wallets.js → walletStandartList.js} +1 -1
  78. package/build/solana/walletStandartList.js.map +1 -0
  79. package/build/stellar/connector.d.ts +10 -6
  80. package/build/stellar/connector.js +38 -30
  81. package/build/stellar/connector.js.map +1 -1
  82. package/build/stellar/freigher.d.ts +46 -0
  83. package/build/stellar/freigher.js +110 -0
  84. package/build/stellar/freigher.js.map +1 -0
  85. package/build/stellar/{injected.d.ts → hotWallet.d.ts} +1 -6
  86. package/build/stellar/hotWallet.js +28 -0
  87. package/build/stellar/hotWallet.js.map +1 -0
  88. package/build/stellar/wallet.d.ts +10 -8
  89. package/build/stellar/wallet.js +12 -16
  90. package/build/stellar/wallet.js.map +1 -1
  91. package/build/ton/connector.d.ts +0 -1
  92. package/build/ton/connector.js +7 -7
  93. package/build/ton/connector.js.map +1 -1
  94. package/build/ton/injected.js +6 -6
  95. package/build/ton/injected.js.map +1 -1
  96. package/build/ton/wallet.d.ts +2 -3
  97. package/build/ton/wallet.js +3 -4
  98. package/build/ton/wallet.js.map +1 -1
  99. package/build/tron/connector.d.ts +51 -0
  100. package/build/tron/connector.js +65 -0
  101. package/build/tron/connector.js.map +1 -0
  102. package/build/tron/index.d.ts +6 -0
  103. package/build/tron/index.js +5 -0
  104. package/build/tron/index.js.map +1 -0
  105. package/build/tron/wallet.d.ts +52 -0
  106. package/build/tron/wallet.js +122 -0
  107. package/build/tron/wallet.js.map +1 -0
  108. package/build/ui/Popup.js +1 -1
  109. package/build/ui/Popup.js.map +1 -1
  110. package/build/ui/connect/AuthPopup.js +1 -1
  111. package/build/ui/connect/AuthPopup.js.map +1 -1
  112. package/build/ui/connect/ConnectWallet.d.ts +2 -1
  113. package/build/ui/connect/ConnectWallet.js +2 -2
  114. package/build/ui/connect/ConnectWallet.js.map +1 -1
  115. package/build/ui/icons/arrow-right.js +1 -1
  116. package/build/ui/icons/arrow-right.js.map +1 -1
  117. package/build/ui/icons/close.js +1 -1
  118. package/build/ui/icons/close.js.map +1 -1
  119. package/build/ui/icons/exchange.js +1 -1
  120. package/build/ui/icons/exchange.js.map +1 -1
  121. package/build/ui/icons/logout.js +1 -1
  122. package/build/ui/icons/logout.js.map +1 -1
  123. package/build/ui/icons/pending.js +1 -1
  124. package/build/ui/icons/pending.js.map +1 -1
  125. package/build/ui/icons/qr.js +1 -1
  126. package/build/ui/icons/qr.js.map +1 -1
  127. package/build/ui/icons/search.js +1 -1
  128. package/build/ui/icons/search.js.map +1 -1
  129. package/build/ui/icons/switch.js +1 -1
  130. package/build/ui/icons/switch.js.map +1 -1
  131. package/build/ui/icons/wallet.js +1 -1
  132. package/build/ui/icons/wallet.js.map +1 -1
  133. package/build/ui/payment/Bridge.js +7 -2
  134. package/build/ui/payment/Bridge.js.map +1 -1
  135. package/build/ui/payment/Payment.d.ts +16 -8
  136. package/build/ui/payment/Payment.js +116 -21
  137. package/build/ui/payment/Payment.js.map +1 -1
  138. package/build/ui/payment/Profile.js +1 -1
  139. package/build/ui/payment/Profile.js.map +1 -1
  140. package/build/ui/payment/SelectToken.js +1 -1
  141. package/build/ui/payment/SelectToken.js.map +1 -1
  142. package/build/ui/payment/TokenCard.js +1 -1
  143. package/build/ui/payment/TokenCard.js.map +1 -1
  144. package/build/ui/router.d.ts +2 -1
  145. package/build/ui/router.js +2 -2
  146. package/build/ui/router.js.map +1 -1
  147. package/build/ui/styles.js +4 -3
  148. package/build/ui/styles.js.map +1 -1
  149. package/package.json +10 -5
  150. package/src/HotConnector.ts +21 -29
  151. package/src/OmniConnector.ts +9 -9
  152. package/src/OmniWallet.ts +24 -25
  153. package/src/core/Intents.ts +123 -139
  154. package/src/core/api.ts +13 -2
  155. package/src/core/bridge.ts +3 -2
  156. package/src/core/chains.ts +1 -1
  157. package/src/core/index.ts +1 -1
  158. package/src/core/types.ts +21 -0
  159. package/src/core/utils.ts +11 -0
  160. package/src/cosmos/connector.ts +2 -2
  161. package/src/cosmos/wallet.ts +3 -7
  162. package/src/evm/connector.ts +9 -12
  163. package/src/evm/injected.ts +3 -3
  164. package/src/evm/wallet.ts +9 -6
  165. package/src/exchange.ts +20 -20
  166. package/src/hot-wallet/google.ts +12 -5
  167. package/src/hot-wallet/iframe.ts +151 -24
  168. package/src/hot-wallet/proxy.ts +54 -0
  169. package/src/index.ts +2 -0
  170. package/src/near/connector.ts +2 -2
  171. package/src/{core/nearRpc.ts → near/rpc.ts} +4 -11
  172. package/src/near/wallet.ts +4 -9
  173. package/src/solana/{protocol.ts → WalletStandard.ts} +2 -4
  174. package/src/solana/connector.ts +11 -10
  175. package/src/solana/injected/account.ts +1 -2
  176. package/src/solana/injected/index.ts +15 -18
  177. package/src/solana/injected/solana-wallet.ts +6 -6
  178. package/src/solana/wallet.ts +4 -8
  179. package/src/stellar/connector.ts +40 -32
  180. package/src/stellar/freigher.ts +119 -0
  181. package/src/stellar/{injected.ts → hotWallet.ts} +8 -12
  182. package/src/stellar/wallet.ts +17 -17
  183. package/src/ton/connector.ts +15 -15
  184. package/src/ton/injected.ts +6 -6
  185. package/src/ton/wallet.ts +3 -3
  186. package/src/tron/connector.ts +89 -0
  187. package/src/tron/index.ts +7 -0
  188. package/src/tron/wallet.ts +146 -0
  189. package/src/ui/Popup.tsx +7 -3
  190. package/src/ui/connect/AuthPopup.tsx +2 -1
  191. package/src/ui/connect/ConnectWallet.tsx +3 -2
  192. package/src/ui/icons/arrow-right.tsx +2 -2
  193. package/src/ui/icons/close.tsx +1 -1
  194. package/src/ui/icons/exchange.tsx +4 -4
  195. package/src/ui/icons/logout.tsx +6 -6
  196. package/src/ui/icons/pending.tsx +2 -4
  197. package/src/ui/icons/qr.tsx +1 -2
  198. package/src/ui/icons/search.tsx +4 -4
  199. package/src/ui/icons/switch.tsx +4 -4
  200. package/src/ui/icons/wallet.tsx +2 -4
  201. package/src/ui/payment/Bridge.tsx +9 -2
  202. package/src/ui/payment/Payment.tsx +259 -31
  203. package/src/ui/payment/Profile.tsx +10 -8
  204. package/src/ui/payment/SelectToken.tsx +1 -1
  205. package/src/ui/payment/TokenCard.tsx +1 -1
  206. package/src/ui/router.tsx +5 -6
  207. package/src/ui/styles.ts +4 -3
  208. package/build/core/nearRpc.js.map +0 -1
  209. package/build/solana/protocol.js.map +0 -1
  210. package/build/solana/wallets.js.map +0 -1
  211. package/build/stellar/injected.js +0 -32
  212. package/build/stellar/injected.js.map +0 -1
  213. /package/build/solana/{wallets.d.ts → walletStandartList.d.ts} +0 -0
  214. /package/src/solana/{wallets.ts → walletStandartList.ts} +0 -0
@@ -30,8 +30,8 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
30
30
 
31
31
  private storage = new LocalStorage();
32
32
  protected events = new EventEmitter<{
33
- connect: { wallet: T };
34
- disconnect: { wallet: T };
33
+ connect: { wallet: T; connector: OmniConnector<T, O> };
34
+ disconnect: { wallet: T; connector: OmniConnector<T, O> };
35
35
  }>();
36
36
 
37
37
  protected wc: Promise<UniversalProvider> | null = null;
@@ -101,14 +101,14 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
101
101
 
102
102
  protected setWallet(wallet: T) {
103
103
  runInAction(() => this.wallets.push(wallet));
104
- this.events.emit("connect", { wallet });
104
+ this.events.emit("connect", { wallet, connector: this });
105
105
  return wallet;
106
106
  }
107
107
 
108
108
  protected removeWallet() {
109
109
  runInAction(() => {
110
110
  const wallet = this.wallets.pop();
111
- if (wallet) this.events.emit("disconnect", { wallet });
111
+ if (wallet) this.events.emit("disconnect", { wallet, connector: this });
112
112
  });
113
113
  }
114
114
 
@@ -116,7 +116,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
116
116
  runInAction(() => {
117
117
  const wallets = this.wallets;
118
118
  this.wallets = [];
119
- wallets.forEach((wallet) => this.events.emit("disconnect", { wallet }));
119
+ wallets.forEach((wallet) => this.events.emit("disconnect", { wallet, connector: this }));
120
120
  });
121
121
  }
122
122
 
@@ -130,7 +130,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
130
130
 
131
131
  async getStorage(): Promise<{ type?: string; id?: string; address?: string; publicKey?: string }> {
132
132
  const data = await this.storage.get(`wibe3:${this.id}`);
133
- if (!data) throw new Error("No storage found");
133
+ if (!data) return {};
134
134
  return JSON.parse(data);
135
135
  }
136
136
 
@@ -138,19 +138,19 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
138
138
  this.events.removeAllListeners();
139
139
  }
140
140
 
141
- onConnect(handler: (payload: { wallet: T }) => void) {
141
+ onConnect(handler: (payload: { wallet: T; connector: OmniConnector<T, O> }) => void) {
142
142
  this.events.on("connect", handler);
143
143
  return () => this.events.off("connect", handler);
144
144
  }
145
145
 
146
- onDisconnect(handler: (payload: { wallet: T }) => void) {
146
+ onDisconnect(handler: (payload: { wallet: T; connector: OmniConnector<T, O> }) => void) {
147
147
  this.events.on("disconnect", handler);
148
148
  return () => this.events.off("disconnect", handler);
149
149
  }
150
150
 
151
151
  async disconnect() {
152
152
  this.disconnectWalletConnect();
153
+ this.removeAllWallets();
153
154
  this.removeStorage();
154
- this.removeWallet();
155
155
  }
156
156
  }
package/src/OmniWallet.ts CHANGED
@@ -1,9 +1,7 @@
1
- import { sha256 } from "@noble/hashes/sha2.js";
2
1
  import { hex } from "@scure/base";
3
2
 
4
3
  import { openAuthPopup } from "./ui/connect/AuthPopup";
5
- import { OmniToken, WalletType } from "./core/chains";
6
- import { OmniConnector } from "./OmniConnector";
4
+ import { WalletType } from "./core/chains";
7
5
  import { Intents } from "./core/Intents";
8
6
  import { ReviewFee } from "./core/bridge";
9
7
  import { Token } from "./core/token";
@@ -11,38 +9,44 @@ import { Commitment } from "./core";
11
9
  import { api } from "./core/api";
12
10
 
13
11
  export abstract class OmniWallet {
14
- constructor(readonly connector: OmniConnector) {}
15
-
16
12
  abstract address: string;
17
13
  abstract publicKey?: string;
18
14
  abstract omniAddress: string;
19
15
  abstract type: WalletType;
16
+ abstract icon: string;
20
17
 
21
- async disconnect() {
22
- if (!this.connector) throw new Error("Connector not implemented");
23
- await this.connector.disconnect();
18
+ async depositNfts(nftIds: string[], receiver: string) {
19
+ // TODO
24
20
  }
25
21
 
26
- abstract transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee>;
27
- abstract transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string>;
28
- abstract signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Commitment>;
22
+ async withdrawNfts(nftIds: string[], receiver: string) {
23
+ // TODO
24
+ }
29
25
 
30
- abstract fetchBalance(chain: number, address: string): Promise<bigint>;
31
- abstract fetchBalances(chain?: number, whitelist?: string[]): Promise<Record<string, bigint>>;
26
+ async getDepositNftsFee(nfts: string[]) {
27
+ return new ReviewFee({ chain: -4 });
28
+ }
32
29
 
33
- async executeIntents(intents: Record<string, any>[], hashes: string[] = []) {
34
- const signed = await this.signIntents(intents);
35
- return await Intents.publishSignedIntents([signed], hashes);
30
+ async transferNft(nftId: string, receiver: string) {
31
+ // TODO
36
32
  }
37
33
 
38
- get icon() {
39
- return this.connector?.icon;
34
+ async getTranferNftFee(nftId: string, receiver: string) {
35
+ return new ReviewFee({ chain: -4 });
40
36
  }
41
37
 
42
- get intents() {
43
- return new Intents(this.connector.wibe3).attachWallet(this);
38
+ async getNfts(onLoad: (nfts: string[]) => void) {
39
+ // TODO
44
40
  }
45
41
 
42
+ abstract transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee>;
43
+ abstract transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string>;
44
+
45
+ abstract fetchBalance(chain: number, address: string): Promise<bigint>;
46
+ abstract fetchBalances(chain?: number, whitelist?: string[]): Promise<Record<string, bigint>>;
47
+
48
+ abstract signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number }): Promise<Commitment>;
49
+
46
50
  async auth(intents?: Record<string, any>[]): Promise<string> {
47
51
  return openAuthPopup(this, async () => {
48
52
  const seed = hex.encode(new Uint8Array(window.crypto.getRandomValues(new Uint8Array(32))));
@@ -53,11 +57,6 @@ export abstract class OmniWallet {
53
57
  });
54
58
  }
55
59
 
56
- async pay({ token, amount, recipient, paymentId }: { token: OmniToken; amount: number; recipient: string; paymentId: string }) {
57
- const nonce = new Uint8Array(sha256(new TextEncoder().encode(paymentId))).slice(0, 32);
58
- return this.intents.attachNonce(nonce).transfer({ recipient, token, amount }).execute();
59
- }
60
-
61
60
  async waitUntilBalance(need: Record<string, bigint>, receiver: string, attempts = 0) {
62
61
  if (attempts > 120) throw "Balance is not enough";
63
62
  const assets = Object.keys(need) as string[];
@@ -1,14 +1,16 @@
1
1
  import { sha256 } from "@noble/hashes/sha2.js";
2
- import { ed25519 } from "@noble/curves/ed25519";
3
- import { base58, base64, hex } from "@scure/base";
4
2
 
5
3
  import type { HotConnector } from "../HotConnector";
6
4
  import type { OmniWallet } from "../OmniWallet";
7
- import type { TransferIntent, MtWithdrawIntent, FtWithdrawIntent, TokenDiffIntent, AuthCallIntent } from "./types";
5
+ import { rpc } from "../near/rpc";
8
6
 
7
+ import type { Intent, Commitment, TokenDiffIntent, MtWithdrawIntent, FtWithdrawIntent, NftWithdrawIntent, TransferIntent } from "./types";
9
8
  import { OmniToken } from "./chains";
10
9
  import { tokens } from "./tokens";
11
- import { rpc } from "./nearRpc";
10
+ import { formatter } from "./utils";
11
+ import { api } from "./api";
12
+
13
+ import { openPayment } from "../ui/router";
12
14
 
13
15
  export const TGAS = 1000000000000n;
14
16
 
@@ -20,12 +22,12 @@ export class Intents {
20
22
  }
21
23
 
22
24
  hashes: string[] = [];
23
- intents: (TransferIntent | MtWithdrawIntent | FtWithdrawIntent | TokenDiffIntent | AuthCallIntent)[] = [];
25
+ intents: Intent[] = [];
26
+ signer?: OmniWallet;
24
27
  nonce?: Uint8Array;
25
28
  deadline?: Date;
26
- signer?: OmniWallet | { ed25519PrivateKey: Uint8Array; omniAddress?: string };
27
29
 
28
- commitments: Record<string, any>[] = [];
30
+ commitments: Commitment[] = [];
29
31
  need = new Map<OmniToken, bigint>();
30
32
 
31
33
  addNeed(token: OmniToken, amount: bigint) {
@@ -86,7 +88,7 @@ export class Intents {
86
88
  return this;
87
89
  }
88
90
 
89
- tokenDiff(args: Record<OmniToken, bigint | number>) {
91
+ tokenDiff(args: Record<string, bigint | number>) {
90
92
  const parse = (token: OmniToken, amount: bigint | number): [string, string] => {
91
93
  if (typeof amount === "number") return [token.toString(), tokens.get(token).int(amount).toString()];
92
94
  return [token.toString(), amount.toString()];
@@ -109,41 +111,40 @@ export class Intents {
109
111
  return this;
110
112
  }
111
113
 
112
- addRawIntent(rawIntent: Record<string, any>) {
114
+ addRawIntent(rawIntent: Intent) {
113
115
  if (!rawIntent.intent) throw new Error("Intent must have 'intent' field");
114
116
  const intentType = rawIntent.intent;
115
117
 
116
118
  if (intentType === "token_diff") {
117
- const diff = rawIntent.diff || rawIntent.token_diff;
118
- if (!diff) throw new Error("token_diff intent must have 'diff' or 'token_diff' field");
119
-
120
119
  const tokenDiffArgs: Record<OmniToken, bigint> = {} as Record<OmniToken, bigint>;
121
- for (const [token, amountStr] of Object.entries(diff)) {
120
+ for (const [token, amountStr] of Object.entries(rawIntent.diff)) {
122
121
  tokenDiffArgs[token as OmniToken] = BigInt(amountStr as string);
123
122
  }
124
123
  return this.tokenDiff(tokenDiffArgs);
125
124
  }
126
125
 
127
126
  if (intentType === "transfer") {
128
- if (!rawIntent.tokens || !rawIntent.receiver_id) {
129
- throw new Error("transfer intent must have 'tokens' and 'receiver_id' fields");
130
- }
131
-
132
127
  const tokens: Record<OmniToken, bigint> = {} as Record<OmniToken, bigint>;
133
128
  for (const [token, amount] of Object.entries(rawIntent.tokens)) {
134
129
  tokens[token as OmniToken] = BigInt(amount as string);
135
130
  }
131
+
136
132
  return this.batchTransfer({
133
+ tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
137
134
  recipient: rawIntent.receiver_id,
138
- tokens,
139
135
  memo: rawIntent.memo,
140
136
  msg: rawIntent.msg,
141
- tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
137
+ tokens,
142
138
  });
143
139
  }
144
140
 
145
141
  if (intentType === "mt_withdraw") {
146
- const intent: MtWithdrawIntent = {
142
+ for (let i = 0; i < rawIntent.amounts.length; i++) {
143
+ const token = `nep245:${rawIntent.token}:${rawIntent.token_ids[i]}` as OmniToken;
144
+ this.addNeed(token, BigInt(rawIntent.amounts[i]));
145
+ }
146
+
147
+ this.intents.push({
147
148
  intent: "mt_withdraw",
148
149
  amounts: rawIntent.amounts,
149
150
  receiver_id: rawIntent.receiver_id,
@@ -152,58 +153,71 @@ export class Intents {
152
153
  memo: rawIntent.memo,
153
154
  msg: rawIntent.msg,
154
155
  min_gas: rawIntent.min_gas,
155
- };
156
-
157
- for (let i = 0; i < rawIntent.amounts.length; i++) {
158
- const token = `nep245:${rawIntent.token}:${rawIntent.token_ids[i]}` as OmniToken;
159
- this.addNeed(token, BigInt(rawIntent.amounts[i]));
160
- }
161
-
162
- this.intents.push(intent);
156
+ } as MtWithdrawIntent);
163
157
  return this;
164
158
  }
165
159
 
166
160
  if (intentType === "ft_withdraw") {
167
- if (!rawIntent.token || !rawIntent.receiver_id || !rawIntent.amount) {
168
- throw new Error("ft_withdraw intent must have 'token', 'receiver_id', and 'amount' fields");
169
- }
170
-
171
- const token = `nep141:${rawIntent.token}` as OmniToken;
172
161
  return this.withdraw({
162
+ token: `nep141:${rawIntent.token}`,
173
163
  amount: BigInt(rawIntent.amount),
174
164
  receiver: rawIntent.receiver_id,
175
165
  memo: rawIntent.memo,
176
166
  msg: rawIntent.msg,
177
- token,
178
167
  });
179
168
  }
180
169
 
181
170
  if (intentType === "auth_call") {
182
- if (!rawIntent.contract_id || !rawIntent.msg || !rawIntent.attached_deposit || !rawIntent.min_gas) {
183
- throw new Error("auth_call intent must have 'contract_id', 'msg', 'attached_deposit', and 'min_gas' fields");
184
- }
185
-
186
171
  return this.authCall({
187
- contractId: rawIntent.contract_id,
188
- msg: rawIntent.msg,
189
172
  attachNear: BigInt(rawIntent.attached_deposit),
190
173
  tgas: Number(BigInt(rawIntent.min_gas) / TGAS),
174
+ contractId: rawIntent.contract_id,
175
+ msg: rawIntent.msg,
176
+ });
177
+ }
178
+
179
+ if (intentType === "add_public_key") {
180
+ return this.addPublicKey(rawIntent.public_key);
181
+ }
182
+
183
+ if (intentType === "remove_public_key") {
184
+ return this.removePublicKey(rawIntent.public_key);
185
+ }
186
+
187
+ if (intentType === "nft_withdraw") {
188
+ return this.withdraw({
189
+ token: rawIntent.token_id,
190
+ receiver: rawIntent.receiver_id,
191
+ memo: rawIntent.memo,
192
+ msg: rawIntent.msg,
193
+ tgas: rawIntent.min_gas ? Number(BigInt(rawIntent.min_gas) / TGAS) : undefined,
194
+ amount: 1n,
191
195
  });
192
196
  }
193
197
 
194
198
  throw new Error(`Unsupported intent type: ${intentType}`);
195
199
  }
196
200
 
197
- withdraw(args: { token: OmniToken; amount: number | bigint; receiver: string; memo?: string; msg?: string; tgas?: number }) {
201
+ addPublicKey(publicKey: string) {
202
+ this.intents.push({ intent: "add_public_key", public_key: publicKey });
203
+ return this;
204
+ }
205
+
206
+ removePublicKey(publicKey: string) {
207
+ this.intents.push({ intent: "remove_public_key", public_key: publicKey });
208
+ return this;
209
+ }
210
+
211
+ withdraw(args: { token: string; amount: number | bigint; receiver: string; memo?: string; msg?: string; tgas?: number }) {
198
212
  const omniToken = tokens.get(args.token);
199
213
  const amount = (typeof args.amount === "number" ? omniToken.int(args.amount) : args.amount).toString();
200
214
  const [standart, ...tokenParts] = args.token.split(":");
201
- this.addNeed(args.token, BigInt(amount));
215
+ this.addNeed(args.token as OmniToken, BigInt(amount));
202
216
 
203
217
  if (standart === "nep245") {
204
218
  const mtContract = tokenParts[0];
205
219
  const tokenId = tokenParts.slice(1).join(":");
206
- const intent: MtWithdrawIntent = {
220
+ this.intents.push({
207
221
  intent: "mt_withdraw",
208
222
  amounts: [amount],
209
223
  receiver_id: args.receiver,
@@ -212,23 +226,31 @@ export class Intents {
212
226
  memo: args.memo,
213
227
  msg: args.msg,
214
228
  min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
215
- };
216
-
217
- this.intents.push(intent);
229
+ } as MtWithdrawIntent);
218
230
  return this;
219
231
  }
220
232
 
221
233
  if (standart === "nep141") {
222
- const intent: FtWithdrawIntent = {
234
+ this.intents.push({
223
235
  intent: "ft_withdraw",
224
236
  receiver_id: args.receiver,
225
237
  token: tokenParts.join(":"),
226
238
  amount: amount,
227
239
  memo: args.memo,
228
240
  msg: args.msg,
229
- };
241
+ } as FtWithdrawIntent);
242
+ return this;
243
+ }
230
244
 
231
- this.intents.push(intent);
245
+ if (standart === "nep171") {
246
+ this.intents.push({
247
+ intent: "nft_withdraw",
248
+ receiver_id: args.receiver,
249
+ token_id: tokenParts.join(":"),
250
+ min_gas: args.tgas ? (BigInt(args.tgas) * TGAS).toString() : undefined,
251
+ memo: args.memo,
252
+ msg: args.msg,
253
+ } as NftWithdrawIntent);
232
254
  return this;
233
255
  }
234
256
 
@@ -240,7 +262,7 @@ export class Intents {
240
262
  return this;
241
263
  }
242
264
 
243
- attachWallet(wallet: OmniWallet) {
265
+ attachWallet(wallet?: OmniWallet) {
244
266
  this.signer = wallet;
245
267
  return this;
246
268
  }
@@ -265,10 +287,15 @@ export class Intents {
265
287
  return this;
266
288
  }
267
289
 
268
- take(token: OmniToken, amount: number | bigint) {
290
+ attachCommitment(commitment: Commitment) {
291
+ this.commitments.push(commitment);
292
+ return this;
293
+ }
294
+
295
+ take(token: string, amount: number | bigint) {
269
296
  const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
270
297
 
271
- this.addNeed(token, intAmount);
298
+ // this.addNeed(token, -intAmount); Do we need to add the need here?
272
299
  const tokenDiff = this.intents.find((intent) => intent.intent === "token_diff");
273
300
 
274
301
  if (tokenDiff) tokenDiff.diff[token.toString()] = intAmount.toString();
@@ -276,10 +303,10 @@ export class Intents {
276
303
  return this;
277
304
  }
278
305
 
279
- give(token: OmniToken, amount: number | bigint) {
306
+ give(token: string, amount: number | bigint) {
280
307
  const intAmount = typeof amount === "number" ? tokens.get(token).int(amount) : amount;
281
308
 
282
- this.addNeed(token, -intAmount);
309
+ this.addNeed(token as OmniToken, intAmount);
283
310
  const tokenDiff = this.intents.find((intent) => intent.intent === "token_diff");
284
311
 
285
312
  if (tokenDiff) tokenDiff.diff[token.toString()] = (-intAmount).toString();
@@ -287,113 +314,70 @@ export class Intents {
287
314
  return this;
288
315
  }
289
316
 
290
- async signRaw({ ed25519PrivateKey, intentsAddress, checkTokens }: { ed25519PrivateKey: Uint8Array; intentsAddress?: string; checkTokens?: boolean }) {
291
- if (checkTokens) {
292
- await this.checkRequiredTokens();
293
- }
294
-
295
- const publicKey = ed25519.getPublicKey(ed25519PrivateKey);
296
- const nonce = new Uint8Array(this.nonce || window.crypto.getRandomValues(new Uint8Array(32)));
297
-
298
- const message = JSON.stringify({
299
- deadline: this.deadline ? new Date(this.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
300
- nonce: base64.encode(nonce),
301
- verifying_contract: "intents.near",
302
- signer_id: intentsAddress || hex.encode(publicKey).toLowerCase(),
303
- intents: this.intents,
304
- });
305
-
306
- return {
307
- signature: `ed25519:${base58.encode(ed25519.sign(message, ed25519PrivateKey))}`,
308
- public_key: `ed25519:${base58.encode(publicKey)}`,
309
- standard: "raw_ed25519",
310
- payload: message,
311
- };
312
- }
313
-
314
- async attachCommitment(commitment: Record<string, any>) {
315
- this.commitments.push(commitment);
316
- return this;
317
- }
318
-
319
- async attachSigner(signer: OmniWallet | { ed25519PrivateKey: Uint8Array; omniAddress?: string }) {
320
- this.signer = signer;
321
- return this;
322
- }
323
-
324
- async checkRequiredTokens() {
325
- if (this.wibe3 == null) return;
326
- for (const [token, needAmount] of this.need.entries()) {
327
- if (needAmount <= 0n) continue;
328
- await this.wibe3.requestToken(token, needAmount);
329
- }
330
- }
331
-
332
- async sign(params = { checkTokens: true }) {
317
+ async signSequence() {
333
318
  const signer = this.signer;
334
319
  if (!signer) throw new Error("No signer attached");
335
320
  if (!signer.omniAddress) throw new Error("No omni address");
336
321
 
337
- if ("ed25519PrivateKey" in signer) {
338
- return await this.signRaw({
339
- ed25519PrivateKey: signer.ed25519PrivateKey,
340
- intentsAddress: signer.omniAddress,
341
- checkTokens: params.checkTokens,
342
- });
322
+ const commitments: Commitment[] = [];
323
+ for (const intent of this.intents) {
324
+ const signed = await signer.signIntents([intent], { deadline: this.deadline ? +this.deadline : undefined, nonce: this.nonce });
325
+ commitments.push(signed);
343
326
  }
344
327
 
345
- if (params.checkTokens) {
346
- await this.checkRequiredTokens();
347
- }
328
+ return commitments;
329
+ }
348
330
 
331
+ async sign() {
332
+ const signer = this.signer;
333
+ if (!signer) throw new Error("No signer attached");
334
+ if (!signer.omniAddress) throw new Error("No omni address");
349
335
  return await signer.signIntents(this.intents, {
350
336
  deadline: this.deadline ? +this.deadline : undefined,
351
337
  nonce: this.nonce,
352
338
  });
353
339
  }
354
340
 
355
- async simulate(params = { checkTokens: true }) {
356
- const signed = await this.sign(params);
341
+ async simulate() {
342
+ if (!this.signer) throw new Error("No signer attached");
343
+ const signed = await this.sign();
357
344
  return await Intents.simulateIntents([signed]);
358
345
  }
359
346
 
360
- async execute(params = { checkTokens: true }) {
361
- const signed = await this.sign(params);
362
- const hash = await Intents.publishSignedIntents([...this.commitments, signed], this.hashes);
363
- await rpc.waitTransactionResult(hash, "intents.near");
364
- return hash;
347
+ async execute() {
348
+ if (!this.wibe3) throw new Error("No wibe3 attached");
349
+ return openPayment(this.wibe3, this);
365
350
  }
366
351
 
367
- static async publishSignedIntents(signed: Record<string, any>[], hashes: string[] = []): Promise<string> {
368
- const res = await fetch("https://api0.herewallet.app/api/v1/evm/intent-solver", {
369
- headers: { "Content-Type": "application/json" },
370
- method: "POST",
371
- body: JSON.stringify({
372
- params: [{ signed_datas: signed, quote_hashes: hashes }],
373
- method: "publish_intents",
374
- id: "dontcare",
375
- jsonrpc: "2.0",
376
- }),
377
- });
352
+ async executeBatch(params = { checkTokens: true, chunkSize: this.intents.length, onSuccess: (bucket: number, hash: string) => {} }) {
353
+ if (!this.signer) throw new Error("No signer attached");
354
+ const batches = formatter.chunk(this.intents, params.chunkSize);
355
+ let index = 0;
378
356
 
379
- const { result } = await res.json();
357
+ const hashes: string[] = [];
358
+ for (const batch of batches) {
359
+ const signed = await this.signer.signIntents(batch, {
360
+ deadline: this.deadline ? +this.deadline : undefined,
361
+ nonce: this.nonce,
362
+ });
363
+
364
+ const hash = await Intents.publish([...this.commitments, signed], this.hashes);
365
+ await rpc.waitTransactionResult(hash, "intents.near");
366
+ params.onSuccess(index++, hash);
367
+ hashes.push(hash);
368
+ }
369
+
370
+ return hashes;
371
+ }
372
+
373
+ static async publish(signed: Commitment[], hashes: string[] = []): Promise<string> {
374
+ const result = await api.publishIntents(signed, hashes);
380
375
  if (result.status === "FAILED") throw result.reason;
381
376
  const intentResult = result.intent_hashes[0];
382
377
 
383
378
  const getStatus = async () => {
384
- const statusRes = await fetch("https://api0.herewallet.app/api/v1/evm/intent-solver", {
385
- headers: { "Content-Type": "application/json" },
386
- method: "POST",
387
- body: JSON.stringify({
388
- params: [{ intent_hash: intentResult }],
389
- method: "get_status",
390
- id: "dontcare",
391
- jsonrpc: "2.0",
392
- }),
393
- });
394
-
395
- const { result } = await statusRes.json();
396
- return result;
379
+ const statusResult = await api.getIntentsStatus(intentResult);
380
+ return statusResult;
397
381
  };
398
382
 
399
383
  const fetchResult = async () => {
@@ -417,7 +401,7 @@ export class Intents {
417
401
  });
418
402
  }
419
403
 
420
- static async simulateIntents(signed: Record<string, any>[]) {
404
+ static async simulateIntents(signed: Commitment[]) {
421
405
  return await rpc.viewMethod({
422
406
  args: { signed: signed },
423
407
  methodName: "simulate_intents",
package/src/core/api.ts CHANGED
@@ -69,8 +69,15 @@ export class Api {
69
69
  return result.balances?.[chain] || [];
70
70
  }
71
71
 
72
+ async pendingPayment(commitment: Commitment, depositAddress: string) {
73
+ return await this.request(`/api/v1/wibe3/yield_intent_call`, {
74
+ body: JSON.stringify({ commitment, deposit_address: depositAddress }),
75
+ method: "POST",
76
+ });
77
+ }
78
+
72
79
  async publishIntents(signed: Record<string, any>[], hashes: string[]) {
73
- return await this.request(`/api/v1/wibe3/solver-bus`, {
80
+ const result = await this.request(`/api/v1/wibe3/solver-bus`, {
74
81
  headers: { "Content-Type": "application/json" },
75
82
  method: "POST",
76
83
  body: JSON.stringify({
@@ -80,10 +87,12 @@ export class Api {
80
87
  jsonrpc: "2.0",
81
88
  }),
82
89
  });
90
+
91
+ return result.result;
83
92
  }
84
93
 
85
94
  async getIntentsStatus(intentHash: string) {
86
- return await this.request(`/api/v1/wibe3/solver-bus`, {
95
+ const result = await this.request(`/api/v1/wibe3/solver-bus`, {
87
96
  headers: { "Content-Type": "application/json" },
88
97
  method: "POST",
89
98
  body: JSON.stringify({
@@ -93,6 +102,8 @@ export class Api {
93
102
  jsonrpc: "2.0",
94
103
  }),
95
104
  });
105
+
106
+ return result.result;
96
107
  }
97
108
  }
98
109
 
@@ -1,13 +1,14 @@
1
1
  import { CosmosConfig, HotBridge, ReviewFee } from "@hot-labs/omni-sdk";
2
2
  import { chains, Network, WalletType } from "./chains";
3
3
  import { Intents } from "./Intents";
4
+ import { Commitment } from "./types";
4
5
 
5
6
  export { ReviewFee, HotBridge };
6
7
 
7
8
  export const createHotBridge = () => {
8
9
  return new HotBridge({
9
- publishIntents: async (signed: Record<string, any>[], hashes: string[] = []) => {
10
- const hash = await Intents.publishSignedIntents(signed, hashes);
10
+ publishIntents: async (signed: Commitment[], hashes: string[] = []) => {
11
+ const hash = await Intents.publish(signed, hashes);
11
12
  return { sender: "intents.near", hash };
12
13
  },
13
14
 
@@ -133,9 +133,9 @@ const chainsRepository: Record<number, ChainConfig> = {
133
133
  logo: "https://storage.herewallet.app/ft/4444119:ngonka.png",
134
134
  currency: { id: "ngonka", symbol: "GNK", decimals: 6, logo: logo(Network.Gonka) },
135
135
  rpc: rpc(Network.Gonka),
136
- prefix: "gonka",
137
136
  type: WalletType.COSMOS,
138
137
  gasLimit: 200000n,
138
+ prefix: "gonka",
139
139
  },
140
140
  [Network.Monad]: {
141
141
  id: Network.Monad,
package/src/core/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { OmniToken, WalletType, Network, chains } from "./chains";
2
2
  export { createHotBridge, HotBridge, ReviewFee } from "./bridge";
3
- export { rpc as nearRpc, TGAS } from "./nearRpc";
3
+ export { rpc as nearRpc, TGAS } from "../near/rpc";
4
4
  export { EventEmitter } from "./events";
5
5
  export { Recipient } from "./recipient";
6
6
  export { formatter } from "./utils";