@hot-labs/kit 1.0.57 → 1.1.0-beta.2

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 (175) 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/index.d.ts +1 -1
  20. package/build/core/index.js +1 -1
  21. package/build/core/index.js.map +1 -1
  22. package/build/core/types.d.ts +17 -0
  23. package/build/core/utils.d.ts +1 -0
  24. package/build/core/utils.js +10 -0
  25. package/build/core/utils.js.map +1 -1
  26. package/build/cosmos/connector.js +2 -2
  27. package/build/cosmos/connector.js.map +1 -1
  28. package/build/cosmos/wallet.d.ts +2 -4
  29. package/build/cosmos/wallet.js +3 -8
  30. package/build/cosmos/wallet.js.map +1 -1
  31. package/build/evm/connector.d.ts +1 -0
  32. package/build/evm/connector.js +4 -0
  33. package/build/evm/connector.js.map +1 -1
  34. package/build/evm/wallet.d.ts +2 -1
  35. package/build/evm/wallet.js +7 -5
  36. package/build/evm/wallet.js.map +1 -1
  37. package/build/exchange.d.ts +4 -1
  38. package/build/exchange.js +21 -20
  39. package/build/exchange.js.map +1 -1
  40. package/build/hot-wallet/google.js +10 -5
  41. package/build/hot-wallet/google.js.map +1 -1
  42. package/build/index.d.ts +1 -0
  43. package/build/index.js +1 -0
  44. package/build/index.js.map +1 -1
  45. package/build/near/connector.js +2 -2
  46. package/build/near/connector.js.map +1 -1
  47. package/build/{core/nearRpc.d.ts → near/rpc.d.ts} +0 -1
  48. package/build/{core/nearRpc.js → near/rpc.js} +5 -11
  49. package/build/near/rpc.js.map +1 -0
  50. package/build/near/wallet.d.ts +2 -4
  51. package/build/near/wallet.js +4 -9
  52. package/build/near/wallet.js.map +1 -1
  53. package/build/solana/{protocol.d.ts → WalletStandard.d.ts} +1 -1
  54. package/build/solana/{protocol.js → WalletStandard.js} +1 -1
  55. package/build/solana/WalletStandard.js.map +1 -0
  56. package/build/solana/connector.d.ts +1 -1
  57. package/build/solana/connector.js +9 -8
  58. package/build/solana/connector.js.map +1 -1
  59. package/build/solana/injected/solana-wallet.js.map +1 -1
  60. package/build/solana/wallet.d.ts +3 -5
  61. package/build/solana/wallet.js +3 -8
  62. package/build/solana/wallet.js.map +1 -1
  63. package/build/solana/{wallets.js → walletStandartList.js} +1 -1
  64. package/build/solana/walletStandartList.js.map +1 -0
  65. package/build/stellar/connector.d.ts +0 -2
  66. package/build/stellar/connector.js +1 -4
  67. package/build/stellar/connector.js.map +1 -1
  68. package/build/stellar/wallet.d.ts +10 -8
  69. package/build/stellar/wallet.js +12 -16
  70. package/build/stellar/wallet.js.map +1 -1
  71. package/build/ton/connector.d.ts +0 -1
  72. package/build/ton/connector.js +1 -4
  73. package/build/ton/connector.js.map +1 -1
  74. package/build/ton/wallet.d.ts +2 -3
  75. package/build/ton/wallet.js +3 -4
  76. package/build/ton/wallet.js.map +1 -1
  77. package/build/tron/connector.d.ts +51 -0
  78. package/build/tron/connector.js +65 -0
  79. package/build/tron/connector.js.map +1 -0
  80. package/build/tron/index.d.ts +6 -0
  81. package/build/tron/index.js +5 -0
  82. package/build/tron/index.js.map +1 -0
  83. package/build/tron/wallet.d.ts +52 -0
  84. package/build/tron/wallet.js +122 -0
  85. package/build/tron/wallet.js.map +1 -0
  86. package/build/ui/connect/AuthPopup.js +1 -1
  87. package/build/ui/connect/AuthPopup.js.map +1 -1
  88. package/build/ui/connect/ConnectWallet.d.ts +2 -1
  89. package/build/ui/connect/ConnectWallet.js +2 -2
  90. package/build/ui/connect/ConnectWallet.js.map +1 -1
  91. package/build/ui/icons/arrow-right.js +1 -1
  92. package/build/ui/icons/arrow-right.js.map +1 -1
  93. package/build/ui/icons/close.js +1 -1
  94. package/build/ui/icons/close.js.map +1 -1
  95. package/build/ui/icons/exchange.js +1 -1
  96. package/build/ui/icons/exchange.js.map +1 -1
  97. package/build/ui/icons/logout.js +1 -1
  98. package/build/ui/icons/logout.js.map +1 -1
  99. package/build/ui/icons/pending.js +1 -1
  100. package/build/ui/icons/pending.js.map +1 -1
  101. package/build/ui/icons/qr.js +1 -1
  102. package/build/ui/icons/qr.js.map +1 -1
  103. package/build/ui/icons/search.js +1 -1
  104. package/build/ui/icons/search.js.map +1 -1
  105. package/build/ui/icons/switch.js +1 -1
  106. package/build/ui/icons/switch.js.map +1 -1
  107. package/build/ui/icons/wallet.js +1 -1
  108. package/build/ui/icons/wallet.js.map +1 -1
  109. package/build/ui/payment/Bridge.js +7 -2
  110. package/build/ui/payment/Bridge.js.map +1 -1
  111. package/build/ui/payment/Payment.d.ts +16 -8
  112. package/build/ui/payment/Payment.js +117 -21
  113. package/build/ui/payment/Payment.js.map +1 -1
  114. package/build/ui/payment/Profile.js +1 -1
  115. package/build/ui/payment/Profile.js.map +1 -1
  116. package/build/ui/payment/SelectToken.js +1 -1
  117. package/build/ui/payment/SelectToken.js.map +1 -1
  118. package/build/ui/payment/TokenCard.js +1 -1
  119. package/build/ui/payment/TokenCard.js.map +1 -1
  120. package/build/ui/router.d.ts +2 -1
  121. package/build/ui/router.js +2 -2
  122. package/build/ui/router.js.map +1 -1
  123. package/package.json +8 -4
  124. package/src/HotConnector.ts +21 -29
  125. package/src/OmniConnector.ts +9 -9
  126. package/src/OmniWallet.ts +24 -25
  127. package/src/core/Intents.ts +123 -139
  128. package/src/core/api.ts +13 -2
  129. package/src/core/bridge.ts +3 -2
  130. package/src/core/index.ts +1 -1
  131. package/src/core/types.ts +21 -0
  132. package/src/core/utils.ts +11 -0
  133. package/src/cosmos/connector.ts +2 -2
  134. package/src/cosmos/wallet.ts +3 -7
  135. package/src/evm/connector.ts +5 -0
  136. package/src/evm/wallet.ts +9 -6
  137. package/src/exchange.ts +20 -20
  138. package/src/hot-wallet/google.ts +12 -5
  139. package/src/index.ts +2 -0
  140. package/src/near/connector.ts +2 -2
  141. package/src/{core/nearRpc.ts → near/rpc.ts} +4 -11
  142. package/src/near/wallet.ts +4 -9
  143. package/src/solana/{protocol.ts → WalletStandard.ts} +2 -4
  144. package/src/solana/connector.ts +9 -8
  145. package/src/solana/injected/solana-wallet.ts +6 -6
  146. package/src/solana/wallet.ts +4 -8
  147. package/src/stellar/connector.ts +1 -6
  148. package/src/stellar/wallet.ts +17 -17
  149. package/src/ton/connector.ts +1 -5
  150. package/src/ton/wallet.ts +3 -3
  151. package/src/tron/connector.ts +89 -0
  152. package/src/tron/index.ts +7 -0
  153. package/src/tron/wallet.ts +146 -0
  154. package/src/ui/connect/AuthPopup.tsx +2 -1
  155. package/src/ui/connect/ConnectWallet.tsx +3 -2
  156. package/src/ui/icons/arrow-right.tsx +2 -2
  157. package/src/ui/icons/close.tsx +1 -1
  158. package/src/ui/icons/exchange.tsx +4 -4
  159. package/src/ui/icons/logout.tsx +6 -6
  160. package/src/ui/icons/pending.tsx +2 -4
  161. package/src/ui/icons/qr.tsx +1 -2
  162. package/src/ui/icons/search.tsx +4 -4
  163. package/src/ui/icons/switch.tsx +4 -4
  164. package/src/ui/icons/wallet.tsx +2 -4
  165. package/src/ui/payment/Bridge.tsx +9 -2
  166. package/src/ui/payment/Payment.tsx +258 -30
  167. package/src/ui/payment/Profile.tsx +10 -8
  168. package/src/ui/payment/SelectToken.tsx +1 -1
  169. package/src/ui/payment/TokenCard.tsx +1 -1
  170. package/src/ui/router.tsx +5 -6
  171. package/build/core/nearRpc.js.map +0 -1
  172. package/build/solana/protocol.js.map +0 -1
  173. package/build/solana/wallets.js.map +0 -1
  174. /package/build/solana/{wallets.d.ts → walletStandartList.d.ts} +0 -0
  175. /package/src/solana/{wallets.ts → walletStandartList.ts} +0 -0
@@ -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
 
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";
package/src/core/types.ts CHANGED
@@ -40,9 +40,30 @@ export interface AuthCallIntent {
40
40
  intent: "auth_call";
41
41
  }
42
42
 
43
+ export interface AddPublicKeyIntent {
44
+ intent: "add_public_key";
45
+ public_key: string;
46
+ }
47
+
48
+ export interface RemovePublicKeyIntent {
49
+ intent: "remove_public_key";
50
+ public_key: string;
51
+ }
52
+
53
+ export interface NftWithdrawIntent {
54
+ intent: "nft_withdraw";
55
+ token_id: string;
56
+ receiver_id: string;
57
+ memo?: string;
58
+ msg?: string;
59
+ min_gas?: string;
60
+ }
61
+
43
62
  export interface Commitment {
44
63
  signature: string;
45
64
  public_key?: string;
46
65
  payload: Record<string, any> | string;
47
66
  standard: string;
48
67
  }
68
+
69
+ export type Intent = TransferIntent | MtWithdrawIntent | FtWithdrawIntent | TokenDiffIntent | AuthCallIntent | AddPublicKeyIntent | RemovePublicKeyIntent | NftWithdrawIntent;
package/src/core/utils.ts CHANGED
@@ -160,4 +160,15 @@ export const formatter = {
160
160
  wait(ms: number) {
161
161
  return new Promise((resolve) => setTimeout(resolve, ms));
162
162
  },
163
+
164
+ chunk(array: any[], size: number) {
165
+ return array.reduce((acc, item, index) => {
166
+ const chunkIndex = Math.floor(index / size);
167
+ if (!acc[chunkIndex]) {
168
+ acc[chunkIndex] = [];
169
+ }
170
+ acc[chunkIndex].push(item);
171
+ return acc;
172
+ }, []);
173
+ },
163
174
  };
@@ -125,7 +125,7 @@ export default class CosmosConnector extends OmniConnector<CosmosWallet> {
125
125
  const address = account.bech32Address;
126
126
 
127
127
  this.setStorage({ type: "walletconnect", id });
128
- const wallet = new CosmosWallet(this, {
128
+ const wallet = new CosmosWallet({
129
129
  address: address,
130
130
  publicKeyHex: publicKey,
131
131
  disconnect: () => this.disconnectWalletConnect(),
@@ -170,7 +170,7 @@ export default class CosmosConnector extends OmniConnector<CosmosWallet> {
170
170
 
171
171
  async setKeplrWallet(keplr: Keplr, address: string, publicKey: string) {
172
172
  return this.setWallet(
173
- new CosmosWallet(this, {
173
+ new CosmosWallet({
174
174
  address: address,
175
175
  publicKeyHex: publicKey,
176
176
  disconnect: () => keplr.disable(),
@@ -13,10 +13,11 @@ interface ProtocolWallet {
13
13
  }
14
14
 
15
15
  export default class CosmosWallet extends OmniWallet {
16
+ readonly icon = "https://legacy.cosmos.network/presskit/cosmos-brandmark-dynamic-dark.svg";
16
17
  readonly type = WalletType.COSMOS;
17
18
 
18
- constructor(readonly connector: CosmosConnector, readonly wallet: ProtocolWallet) {
19
- super(connector);
19
+ constructor(readonly wallet: ProtocolWallet) {
20
+ super();
20
21
  }
21
22
 
22
23
  get address() {
@@ -31,11 +32,6 @@ export default class CosmosWallet extends OmniWallet {
31
32
  return "";
32
33
  }
33
34
 
34
- async disconnect() {
35
- super.disconnect();
36
- this.wallet.disconnect?.();
37
- }
38
-
39
35
  sendTransaction(signDoc: any): Promise<string> {
40
36
  if (!this.wallet.sendTransaction) throw "Not impl";
41
37
  return this.wallet.sendTransaction(signDoc);
@@ -121,6 +121,11 @@ class EvmConnector extends OmniConnector<EvmWallet, { provider: EvmProvider }> {
121
121
 
122
122
  return await this.connectWallet(id, wallet.provider);
123
123
  }
124
+
125
+ async disconnect() {
126
+ this.wallets.forEach((w) => w.disconnect());
127
+ super.disconnect();
128
+ }
124
129
  }
125
130
 
126
131
  export default EvmConnector;
package/src/evm/wallet.ts CHANGED
@@ -22,7 +22,15 @@ class EvmWallet extends OmniWallet {
22
22
  readonly type = WalletType.EVM;
23
23
 
24
24
  constructor(readonly connector: OmniConnector, readonly address: string, readonly provider: EvmProvider) {
25
- super(connector);
25
+ super();
26
+ }
27
+
28
+ async disconnect() {
29
+ await this.provider.request?.({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
30
+ }
31
+
32
+ get icon() {
33
+ return this.connector.icon;
26
34
  }
27
35
 
28
36
  private rpcs: Record<number, JsonRpcProvider> = {};
@@ -42,11 +50,6 @@ class EvmWallet extends OmniWallet {
42
50
  return this.address.toLowerCase();
43
51
  }
44
52
 
45
- async disconnect() {
46
- this.provider.request?.({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
47
- await super.disconnect();
48
- }
49
-
50
53
  async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
51
54
  const native = await this.fetchBalance(chain, "native");
52
55
  try {