@hot-labs/kit 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/HotConnector.d.ts +9 -13
- package/build/HotConnector.js +17 -57
- package/build/HotConnector.js.map +1 -1
- package/build/activity.d.ts +1 -1
- package/build/activity.js +8 -8
- package/build/activity.js.map +1 -1
- package/build/core/Intents.d.ts +4 -3
- package/build/core/Intents.js +24 -4
- package/build/core/Intents.js.map +1 -1
- package/build/{OmniConnector.d.ts → core/OmniConnector.d.ts} +4 -4
- package/build/{OmniConnector.js → core/OmniConnector.js} +2 -2
- package/build/core/OmniConnector.js.map +1 -0
- package/build/{OmniWallet.d.ts → core/OmniWallet.d.ts} +19 -13
- package/build/core/OmniWallet.js +97 -0
- package/build/core/OmniWallet.js.map +1 -0
- package/build/core/chains.d.ts +1 -1
- package/build/core/chains.js +5 -5
- package/build/core/chains.js.map +1 -1
- package/build/core/defaultTokens.js +0 -9
- package/build/core/defaultTokens.js.map +1 -1
- package/build/{exchange.d.ts → core/exchange.d.ts} +13 -16
- package/build/{exchange.js → core/exchange.js} +76 -80
- package/build/core/exchange.js.map +1 -0
- package/build/core/index.d.ts +4 -2
- package/build/core/index.js +4 -2
- package/build/core/index.js.map +1 -1
- package/build/core/recipient.d.ts +1 -1
- package/build/core/telemetry.d.ts +3 -0
- package/build/core/telemetry.js.map +1 -1
- package/build/core/token.js +3 -3
- package/build/core/token.js.map +1 -1
- package/build/core/tokens.js +1 -1
- package/build/core/tokens.js.map +1 -1
- package/build/core/utils.d.ts +1 -0
- package/build/core/utils.js +19 -0
- package/build/core/utils.js.map +1 -1
- package/build/cosmos/connector.d.ts +2 -2
- package/build/cosmos/connector.js +2 -2
- package/build/cosmos/connector.js.map +1 -1
- package/build/cosmos/wallet.d.ts +2 -2
- package/build/cosmos/wallet.js +7 -10
- package/build/cosmos/wallet.js.map +1 -1
- package/build/defaults.d.ts +1 -1
- package/build/defaults.js +2 -2
- package/build/defaults.js.map +1 -1
- package/build/evm/connector.d.ts +2 -2
- package/build/evm/connector.js +10 -4
- package/build/evm/connector.js.map +1 -1
- package/build/evm/wallet.d.ts +5 -5
- package/build/evm/wallet.js +25 -24
- package/build/evm/wallet.js.map +1 -1
- package/build/hot-wallet/google.d.ts +2 -2
- package/build/hot-wallet/google.js +4 -4
- package/build/hot-wallet/google.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/near/connector.d.ts +2 -2
- package/build/near/connector.js +1 -1
- package/build/near/connector.js.map +1 -1
- package/build/near/index.d.ts +1 -1
- package/build/near/index.js.map +1 -1
- package/build/near/rpc.js +1 -2
- package/build/near/rpc.js.map +1 -1
- package/build/near/standalone.d.ts +2 -0
- package/build/near/standalone.js +42 -0
- package/build/near/standalone.js.map +1 -0
- package/build/near/wallet.d.ts +3 -2
- package/build/near/wallet.js +21 -12
- package/build/near/wallet.js.map +1 -1
- package/build/solana/connector.d.ts +4 -4
- package/build/solana/connector.js +11 -4
- package/build/solana/connector.js.map +1 -1
- package/build/solana/wallet.d.ts +3 -3
- package/build/solana/wallet.js +14 -11
- package/build/solana/wallet.js.map +1 -1
- package/build/stellar/connector.d.ts +2 -2
- package/build/stellar/connector.js +3 -2
- package/build/stellar/connector.js.map +1 -1
- package/build/stellar/wallet.d.ts +3 -3
- package/build/stellar/wallet.js +27 -19
- package/build/stellar/wallet.js.map +1 -1
- package/build/ton/connector.d.ts +2 -2
- package/build/ton/connector.js +2 -2
- package/build/ton/connector.js.map +1 -1
- package/build/ton/wallet.d.ts +3 -3
- package/build/ton/wallet.js +26 -17
- package/build/ton/wallet.js.map +1 -1
- package/build/tron/connector.d.ts +2 -2
- package/build/tron/connector.js +1 -1
- package/build/tron/connector.js.map +1 -1
- package/build/tron/wallet.d.ts +2 -2
- package/build/tron/wallet.js +9 -15
- package/build/tron/wallet.js.map +1 -1
- package/build/ui/bridge/Bridge.d.ts +2 -2
- package/build/ui/bridge/Bridge.js +13 -11
- package/build/ui/bridge/Bridge.js.map +1 -1
- package/build/ui/bridge/SelectRecipient.d.ts +3 -3
- package/build/ui/bridge/SelectRecipient.js +5 -5
- package/build/ui/bridge/SelectRecipient.js.map +1 -1
- package/build/ui/bridge/SelectSender.d.ts +1 -1
- package/build/ui/bridge/SelectSender.js +1 -1
- package/build/ui/bridge/SelectSender.js.map +1 -1
- package/build/ui/bridge/SelectToken.d.ts +1 -1
- package/build/ui/bridge/SelectToken.js +2 -2
- package/build/ui/bridge/SelectToken.js.map +1 -1
- package/build/ui/bridge/TokenCard.d.ts +1 -1
- package/build/ui/connect/AuthPopup.d.ts +1 -1
- package/build/ui/connect/ConnectWallet.d.ts +1 -1
- package/build/ui/connect/ConnectWallet.js +1 -1
- package/build/ui/connect/ConnectWallet.js.map +1 -1
- package/build/ui/connect/LogoutPopup.d.ts +1 -1
- package/build/ui/connect/WCPopup.js +1 -1
- package/build/ui/connect/WCPopup.js.map +1 -1
- package/build/ui/connect/WalletPicker.d.ts +2 -2
- package/build/ui/profile/DepositQR.d.ts +1 -1
- package/build/ui/profile/Payment.d.ts +1 -1
- package/build/ui/profile/Payment.js +8 -8
- package/build/ui/profile/Payment.js.map +1 -1
- package/build/ui/profile/Profile.js.map +1 -1
- package/build/ui/router.d.ts +3 -3
- package/examples-node/.env +2 -0
- package/examples-node/package.json +17 -0
- package/examples-node/transfer.ts +38 -0
- package/examples-node/withdraw.ts +52 -0
- package/examples-node/yarn.lock +2691 -0
- package/package.json +1 -1
- package/src/HotConnector.ts +16 -60
- package/src/activity.ts +9 -9
- package/src/core/Intents.ts +25 -7
- package/src/{OmniConnector.ts → core/OmniConnector.ts} +4 -6
- package/src/core/OmniWallet.ts +125 -0
- package/src/core/chains.ts +5 -5
- package/src/core/defaultTokens.ts +0 -9
- package/src/{exchange.ts → core/exchange.ts} +79 -85
- package/src/core/index.ts +6 -2
- package/src/core/recipient.ts +1 -1
- package/src/core/telemetry.ts +4 -0
- package/src/core/token.ts +3 -3
- package/src/core/tokens.ts +1 -1
- package/src/core/utils.ts +16 -0
- package/src/cosmos/connector.ts +3 -3
- package/src/cosmos/wallet.ts +8 -11
- package/src/defaults.ts +2 -2
- package/src/evm/connector.ts +12 -6
- package/src/evm/wallet.ts +25 -26
- package/src/hot-wallet/google.ts +5 -5
- package/src/index.ts +2 -2
- package/src/near/connector.ts +2 -2
- package/src/near/index.ts +2 -1
- package/src/near/rpc.ts +1 -2
- package/src/near/standalone.ts +52 -0
- package/src/near/wallet.ts +21 -15
- package/src/solana/connector.ts +15 -6
- package/src/solana/wallet.ts +12 -12
- package/src/stellar/connector.ts +5 -4
- package/src/stellar/wallet.ts +28 -22
- package/src/ton/connector.ts +4 -3
- package/src/ton/wallet.ts +24 -18
- package/src/tron/connector.ts +2 -2
- package/src/tron/wallet.ts +9 -19
- package/src/ui/bridge/Bridge.tsx +16 -14
- package/src/ui/bridge/SelectRecipient.tsx +8 -8
- package/src/ui/bridge/SelectSender.tsx +2 -2
- package/src/ui/bridge/SelectToken.tsx +3 -3
- package/src/ui/bridge/TokenCard.tsx +1 -1
- package/src/ui/connect/AuthPopup.tsx +1 -1
- package/src/ui/connect/ConnectWallet.tsx +2 -2
- package/src/ui/connect/LogoutPopup.tsx +1 -1
- package/src/ui/connect/WCPopup.tsx +1 -1
- package/src/ui/connect/WalletPicker.tsx +2 -2
- package/src/ui/profile/DepositQR.tsx +1 -1
- package/src/ui/profile/Payment.tsx +12 -13
- package/src/ui/profile/Profile.tsx +1 -2
- package/src/ui/router.tsx +3 -3
- package/build/OmniConnector.js.map +0 -1
- package/build/OmniWallet.js +0 -58
- package/build/OmniWallet.js.map +0 -1
- package/build/exchange.js.map +0 -1
- package/build/ui/utils.d.ts +0 -1
- package/build/ui/utils.js +0 -20
- package/build/ui/utils.js.map +0 -1
- package/src/OmniWallet.ts +0 -82
- package/src/ui/utils.ts +0 -14
package/package.json
CHANGED
package/src/HotConnector.ts
CHANGED
|
@@ -2,14 +2,15 @@ import { computed, makeObservable, observable, runInAction } from "mobx";
|
|
|
2
2
|
|
|
3
3
|
import packageJson from "../package.json";
|
|
4
4
|
|
|
5
|
+
import { Exchange } from "./core/exchange";
|
|
6
|
+
import { Telemetry } from "./core/telemetry";
|
|
7
|
+
import { OmniWallet } from "./core/OmniWallet";
|
|
5
8
|
import { ChainConfig, chains, Network, WalletType } from "./core/chains";
|
|
6
|
-
import { createHotBridge, HotBridge } from "./core/bridge";
|
|
7
9
|
import { EventEmitter } from "./core/events";
|
|
8
10
|
import { Recipient } from "./core/recipient";
|
|
9
11
|
import { OmniToken } from "./core/chains";
|
|
10
12
|
import { Intents } from "./core/Intents";
|
|
11
13
|
import { tokens } from "./core/tokens";
|
|
12
|
-
import { Telemetry } from "./core/telemetry";
|
|
13
14
|
import { Token } from "./core/token";
|
|
14
15
|
import { api } from "./core/api";
|
|
15
16
|
import { rpc } from "./near/rpc";
|
|
@@ -23,11 +24,9 @@ import type StellarWallet from "./stellar/wallet";
|
|
|
23
24
|
import type TonWallet from "./ton/wallet";
|
|
24
25
|
|
|
25
26
|
import { openBridge, openConnector, openProfile, openWalletPicker } from "./ui/router";
|
|
26
|
-
import { ConnectorType, OmniConnector } from "./OmniConnector";
|
|
27
|
-
import { OmniWallet } from "./OmniWallet";
|
|
28
|
-
import { Exchange } from "./exchange";
|
|
29
|
-
import { Activity } from "./activity";
|
|
27
|
+
import { ConnectorType, OmniConnector } from "./core/OmniConnector";
|
|
30
28
|
import { DataStorage, LocalStorage } from "./storage";
|
|
29
|
+
import { Activity } from "./activity";
|
|
31
30
|
|
|
32
31
|
interface HotConnectorOptions {
|
|
33
32
|
apiKey: string;
|
|
@@ -48,13 +47,10 @@ interface HotConnectorOptions {
|
|
|
48
47
|
export class HotConnector {
|
|
49
48
|
public storage: DataStorage;
|
|
50
49
|
public connectors: OmniConnector[] = [];
|
|
51
|
-
public balances: Record<string, Record<string, bigint>> = {};
|
|
52
50
|
public telemetry: Telemetry;
|
|
53
|
-
|
|
54
|
-
public activity: Activity;
|
|
55
|
-
public hotBridge: HotBridge;
|
|
56
51
|
public exchange: Exchange;
|
|
57
52
|
|
|
53
|
+
public activity: Activity;
|
|
58
54
|
public version = packageJson.version;
|
|
59
55
|
|
|
60
56
|
private events = new EventEmitter<{
|
|
@@ -71,8 +67,6 @@ export class HotConnector {
|
|
|
71
67
|
|
|
72
68
|
constructor(options?: HotConnectorOptions) {
|
|
73
69
|
makeObservable(this, {
|
|
74
|
-
balances: observable,
|
|
75
|
-
|
|
76
70
|
priorityWallet: computed,
|
|
77
71
|
walletsTokens: computed,
|
|
78
72
|
wallets: computed,
|
|
@@ -93,9 +87,8 @@ export class HotConnector {
|
|
|
93
87
|
|
|
94
88
|
this.storage = options?.storage ?? new LocalStorage();
|
|
95
89
|
this.telemetry = new Telemetry(this);
|
|
96
|
-
this.hotBridge = createHotBridge();
|
|
97
|
-
this.exchange = new Exchange(this);
|
|
98
90
|
this.activity = new Activity(this);
|
|
91
|
+
this.exchange = new Exchange();
|
|
99
92
|
|
|
100
93
|
const connectors: OmniConnector[] = [];
|
|
101
94
|
const configConnectors = options?.connectors || defaultConnectors;
|
|
@@ -116,21 +109,17 @@ export class HotConnector {
|
|
|
116
109
|
});
|
|
117
110
|
|
|
118
111
|
this.onConnect((payload) => {
|
|
112
|
+
console.log("onConnect", payload.wallet.type);
|
|
113
|
+
payload.wallet.fetchBalances(Network.Omni);
|
|
119
114
|
this.fetchTokens(payload.wallet);
|
|
120
|
-
this.fetchOmniTokens(payload.wallet);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
this.onDisconnect(({ wallet }) => {
|
|
124
|
-
if (!wallet) return;
|
|
125
|
-
runInAction(() => (this.balances[`${wallet.type}:${wallet.address}`] = {}));
|
|
126
115
|
});
|
|
127
116
|
|
|
128
117
|
tokens.startTokenPolling();
|
|
129
118
|
}
|
|
130
119
|
|
|
131
120
|
setOmniChainBranding(branding: { name: string; icon: string }) {
|
|
132
|
-
chains.get(Network.
|
|
133
|
-
chains.get(Network.
|
|
121
|
+
chains.get(Network.Omni).name = branding.name;
|
|
122
|
+
chains.get(Network.Omni).logo = branding.icon;
|
|
134
123
|
}
|
|
135
124
|
|
|
136
125
|
getWalletConnector(type: WalletType): OmniConnector | null {
|
|
@@ -228,7 +217,7 @@ export class HotConnector {
|
|
|
228
217
|
.reduce((acc: number, token: Token) => {
|
|
229
218
|
return this.wallets.reduce((acc: number, wallet) => {
|
|
230
219
|
if (token.chain === chain) return acc;
|
|
231
|
-
const balance =
|
|
220
|
+
const balance = wallet.getBalance(token.id);
|
|
232
221
|
return acc + token.float(balance) * token.usd;
|
|
233
222
|
}, acc);
|
|
234
223
|
}, 0);
|
|
@@ -236,7 +225,7 @@ export class HotConnector {
|
|
|
236
225
|
|
|
237
226
|
balance(wallet?: OmniWallet, token?: Token) {
|
|
238
227
|
if (!wallet || !token) return 0n;
|
|
239
|
-
return
|
|
228
|
+
return wallet.getBalance(token.id);
|
|
240
229
|
}
|
|
241
230
|
|
|
242
231
|
omniBalance(token: OmniToken) {
|
|
@@ -254,37 +243,10 @@ export class HotConnector {
|
|
|
254
243
|
}
|
|
255
244
|
|
|
256
245
|
async fetchToken(token: Token, wallet: OmniWallet) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (token.type === WalletType.OMNI) {
|
|
260
|
-
if (!wallet.omniAddress) return 0n;
|
|
261
|
-
const balances = await Intents.getIntentsBalances([token.address], wallet.omniAddress);
|
|
262
|
-
runInAction(() => (this.balances[key][token.id] = balances[token.address]));
|
|
263
|
-
return balances[token.address] ?? 0n;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (token.type === wallet.type) {
|
|
267
|
-
const balance = await wallet.fetchBalance(token.chain, token.address);
|
|
268
|
-
runInAction(() => (this.balances[key][token.id] = balance));
|
|
269
|
-
return balance;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
return 0n;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async fetchOmniTokens(wallet: OmniWallet) {
|
|
276
|
-
const key = `${wallet.type}:${wallet.address}`;
|
|
277
|
-
const assets = await wallet.getAssets();
|
|
278
|
-
runInAction(() => {
|
|
279
|
-
Object.keys(assets).forEach((id) => {
|
|
280
|
-
this.balances[key][`-4:${id}`] = assets[id];
|
|
281
|
-
});
|
|
282
|
-
});
|
|
246
|
+
return await wallet.fetchBalance(token.chain, token.address);
|
|
283
247
|
}
|
|
284
248
|
|
|
285
249
|
async fetchTokens(wallet: OmniWallet) {
|
|
286
|
-
const key = `${wallet.type}:${wallet.address}`;
|
|
287
|
-
if (!this.balances[key]) runInAction(() => (this.balances[key] = {}));
|
|
288
250
|
const tokensList = (await tokens.getTokens()).filter((t) => t.type === wallet.type && t.type !== WalletType.OMNI);
|
|
289
251
|
|
|
290
252
|
// Group tokens by their chain
|
|
@@ -294,14 +256,8 @@ export class HotConnector {
|
|
|
294
256
|
return acc;
|
|
295
257
|
}, {} as Record<number, string[]>);
|
|
296
258
|
|
|
297
|
-
Object.entries(groups).
|
|
298
|
-
|
|
299
|
-
runInAction(() => {
|
|
300
|
-
for (const [token, balance] of Object.entries(balances)) {
|
|
301
|
-
this.balances[key][`${chain}:${token}`] = balance;
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
});
|
|
259
|
+
const tasks = Object.entries(groups).map(([chain, tokens]) => wallet.fetchBalances(+chain, tokens));
|
|
260
|
+
await Promise.allSettled(tasks);
|
|
305
261
|
}
|
|
306
262
|
|
|
307
263
|
intentsBuilder(wallet?: OmniWallet) {
|
package/src/activity.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { computed, makeObservable, observable, runInAction } from "mobx";
|
|
|
3
3
|
import { hex } from "@scure/base";
|
|
4
4
|
|
|
5
5
|
import { chains, Network, WalletType } from "./core";
|
|
6
|
+
import { OmniWallet } from "./core/OmniWallet";
|
|
6
7
|
import { HotConnector } from "./HotConnector";
|
|
7
|
-
import { OmniWallet } from "./OmniWallet";
|
|
8
8
|
|
|
9
9
|
export class Activity {
|
|
10
10
|
withdrawals: Record<number, (WithdrawArgsWithPending & { loading?: boolean })[]> = {};
|
|
@@ -25,7 +25,7 @@ export class Activity {
|
|
|
25
25
|
|
|
26
26
|
if (withdrawal.chain === Network.Stellar) {
|
|
27
27
|
if (!this.kit.stellar) throw new Error("Stellar wallet not connected");
|
|
28
|
-
await this.kit.
|
|
28
|
+
await this.kit.exchange.bridge.stellar.withdraw({
|
|
29
29
|
sendTransaction: (tx: any) => this.kit.stellar!.sendTransaction(tx),
|
|
30
30
|
sender: this.kit.stellar.address,
|
|
31
31
|
...withdrawal,
|
|
@@ -34,7 +34,7 @@ export class Activity {
|
|
|
34
34
|
|
|
35
35
|
if (withdrawal.chain === Network.Solana) {
|
|
36
36
|
if (!this.kit.solana) throw new Error("Solana wallet not connected");
|
|
37
|
-
const solana = await this.kit.
|
|
37
|
+
const solana = await this.kit.exchange.bridge.solana();
|
|
38
38
|
await solana.withdraw({
|
|
39
39
|
sendTransaction: (tx: any) => this.kit.solana!.sendTransaction(tx),
|
|
40
40
|
sender: this.kit.solana.address,
|
|
@@ -44,7 +44,7 @@ export class Activity {
|
|
|
44
44
|
|
|
45
45
|
if (withdrawal.chain === Network.Ton || withdrawal.chain === Network.OmniTon) {
|
|
46
46
|
if (!this.kit.ton) throw new Error("Ton wallet not connected");
|
|
47
|
-
await this.kit.
|
|
47
|
+
await this.kit.exchange.bridge.ton.withdraw({
|
|
48
48
|
sendTransaction: (tx: any) => this.kit.ton!.sendTransaction(tx),
|
|
49
49
|
refundAddress: this.kit.ton.address,
|
|
50
50
|
...withdrawal,
|
|
@@ -53,15 +53,15 @@ export class Activity {
|
|
|
53
53
|
|
|
54
54
|
if (chains.get(withdrawal.chain).type === WalletType.EVM) {
|
|
55
55
|
if (!this.kit.evm) throw new Error("EVM wallet not connected");
|
|
56
|
-
await this.kit.
|
|
57
|
-
sendTransaction: (tx: any) => this.kit.evm!.sendTransaction(
|
|
56
|
+
await this.kit.exchange.bridge.evm.withdraw({
|
|
57
|
+
sendTransaction: (tx: any) => this.kit.evm!.sendTransaction(tx),
|
|
58
58
|
...withdrawal,
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
if (withdrawal.chain === Network.Gonka) {
|
|
63
63
|
if (!this.kit.cosmos) throw new Error("Gonka wallet not connected");
|
|
64
|
-
const cosmos = await this.kit.
|
|
64
|
+
const cosmos = await this.kit.exchange.bridge.cosmos();
|
|
65
65
|
await cosmos.withdraw({
|
|
66
66
|
sendTransaction: (tx: any) => this.kit.cosmos!.sendTransaction(tx),
|
|
67
67
|
senderPublicKey: hex.decode(this.kit.cosmos.publicKey!),
|
|
@@ -70,7 +70,7 @@ export class Activity {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
await this.kit.
|
|
73
|
+
await this.kit.exchange.bridge.clearPendingWithdrawals([withdrawal]).catch(() => {});
|
|
74
74
|
} finally {
|
|
75
75
|
runInAction(() => (withdrawal.loading = false));
|
|
76
76
|
const wallet = this.kit.wallets.find((w) => w.type === chains.get(withdrawal.chain).type);
|
|
@@ -85,7 +85,7 @@ export class Activity {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
async fetchPendingWithdrawalsByChain(chain: number, wallet: OmniWallet) {
|
|
88
|
-
const pendings = await this.kit.
|
|
88
|
+
const pendings = await this.kit.exchange.bridge.getPendingWithdrawalsWithStatus(chain, wallet.address);
|
|
89
89
|
runInAction(() => (this.withdrawals[chain] = pendings.filter((t) => !t.completed)));
|
|
90
90
|
}
|
|
91
91
|
}
|
package/src/core/Intents.ts
CHANGED
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
2
|
|
|
3
3
|
import type { HotConnector } from "../HotConnector";
|
|
4
|
-
import type { OmniWallet } from "
|
|
4
|
+
import type { OmniWallet } from "./OmniWallet";
|
|
5
5
|
import { rpc } from "../near/rpc";
|
|
6
6
|
|
|
7
7
|
import type { Intent, Commitment, TokenDiffIntent, MtWithdrawIntent, FtWithdrawIntent, NftWithdrawIntent, TransferIntent } from "./types";
|
|
8
|
+
import type { BridgeReview } from "./exchange";
|
|
9
|
+
|
|
8
10
|
import { OmniToken } from "./chains";
|
|
9
11
|
import { formatter } from "./utils";
|
|
10
12
|
import { tokens } from "./tokens";
|
|
11
13
|
import { api } from "./api";
|
|
12
14
|
|
|
13
|
-
import { openConnector, openConnectPrimaryWallet, openPayment, openToast } from "../ui/router";
|
|
14
|
-
import { BridgeReview } from "../exchange";
|
|
15
|
-
|
|
16
15
|
export const TGAS = 1000000000000n;
|
|
17
16
|
|
|
18
17
|
export class Intents {
|
|
19
18
|
constructor(readonly wibe3?: HotConnector) {}
|
|
20
19
|
|
|
21
|
-
static
|
|
22
|
-
return new Intents();
|
|
20
|
+
static builder(signer?: OmniWallet) {
|
|
21
|
+
return new Intents().attachWallet(signer);
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
signedHashes: string[] = [];
|
|
@@ -62,6 +61,7 @@ export class Intents {
|
|
|
62
61
|
* Use this method to pay for a merchant's item created in pay.hot-labs.org
|
|
63
62
|
*/
|
|
64
63
|
merchantPayment({ merchantId, token, itemId, email, amount, memo }: { token: OmniToken; merchantId: string; itemId: string; amount: number | bigint; memo: string; email: string }) {
|
|
64
|
+
if (typeof window === "undefined") throw "Merchant payment is only available in browser";
|
|
65
65
|
return this.transfer({
|
|
66
66
|
msg: JSON.stringify({ merchant_id: merchantId, item_id: itemId, memo: memo }),
|
|
67
67
|
recipient: "pay.fi.tg",
|
|
@@ -376,11 +376,13 @@ export class Intents {
|
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
async simulate() {
|
|
379
|
+
if (this.unsignedCommitment != null) await this.sign();
|
|
379
380
|
if (this.commitments.length === 0) throw new Error("No commitments attached");
|
|
380
381
|
return await Intents.simulateIntents(this.commitments);
|
|
381
382
|
}
|
|
382
383
|
|
|
383
384
|
async setupSigner() {
|
|
385
|
+
if (typeof window === "undefined") throw "Setup signer is only available in browser";
|
|
384
386
|
if (!this.wibe3) throw new Error("No wibe3 attached");
|
|
385
387
|
if (this.signer) return this.signer;
|
|
386
388
|
|
|
@@ -389,6 +391,7 @@ export class Intents {
|
|
|
389
391
|
return this.signer;
|
|
390
392
|
}
|
|
391
393
|
|
|
394
|
+
const { openConnectPrimaryWallet, openConnector } = await import("../ui/router");
|
|
392
395
|
if (this.wibe3.wallets.length > 0) await openConnectPrimaryWallet(this.wibe3);
|
|
393
396
|
else await openConnector(this.wibe3);
|
|
394
397
|
|
|
@@ -408,6 +411,7 @@ export class Intents {
|
|
|
408
411
|
excludedTokens?: string[];
|
|
409
412
|
onConfirm: (args: { depositQoute?: BridgeReview; processing?: () => Promise<BridgeReview> }) => Promise<void>;
|
|
410
413
|
}) {
|
|
414
|
+
if (typeof window === "undefined") throw "Open sign flow is only available in browser";
|
|
411
415
|
if (!this.wibe3) throw "Attach wibe3";
|
|
412
416
|
if (!this.signer) throw "Attach signer";
|
|
413
417
|
|
|
@@ -417,6 +421,7 @@ export class Intents {
|
|
|
417
421
|
const balance = await this.wibe3.fetchToken(payableToken!, this.signer);
|
|
418
422
|
const prepaidAmount = formatter.bigIntMin(payableAmount, balance);
|
|
419
423
|
|
|
424
|
+
const { openPayment } = await import("../ui/router");
|
|
420
425
|
return await openPayment(this.wibe3, {
|
|
421
426
|
onConfirm,
|
|
422
427
|
needAmount: payableAmount - prepaidAmount,
|
|
@@ -444,6 +449,8 @@ export class Intents {
|
|
|
444
449
|
serverSideProcessing?: boolean;
|
|
445
450
|
payload?: Record<string, any>;
|
|
446
451
|
} = {}) {
|
|
452
|
+
if (typeof window === "undefined") throw "Deposit and execute is only available in browser";
|
|
453
|
+
|
|
447
454
|
await this.setupSigner();
|
|
448
455
|
if (this.need.size === 0) return this.execute();
|
|
449
456
|
|
|
@@ -468,11 +475,12 @@ export class Intents {
|
|
|
468
475
|
});
|
|
469
476
|
|
|
470
477
|
if (serverSideProcessing) return;
|
|
478
|
+
const { openToast } = await import("../ui/router");
|
|
471
479
|
const close = openToast(message || "Executing payment");
|
|
472
480
|
|
|
473
481
|
const payableToken = tokens.get(Array.from(this.need.keys())[0]);
|
|
474
482
|
const payableAmount = this.need.get(payableToken.omniAddress as OmniToken) || 0n;
|
|
475
|
-
await this.signer?.
|
|
483
|
+
await this.signer?.waitUntilOmniBalance({ [payableToken.omniAddress]: payableAmount });
|
|
476
484
|
|
|
477
485
|
await this.execute().finally(() => close());
|
|
478
486
|
}
|
|
@@ -511,6 +519,16 @@ export class Intents {
|
|
|
511
519
|
return hash;
|
|
512
520
|
}
|
|
513
521
|
|
|
522
|
+
static async getPublicKeys(accountId: string): Promise<string[]> {
|
|
523
|
+
const keys = await rpc.viewMethod({
|
|
524
|
+
args: { account_id: accountId },
|
|
525
|
+
methodName: "public_keys_of",
|
|
526
|
+
contractId: "intents.near",
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
return keys.map((key: string) => key.split(":")[1]);
|
|
530
|
+
}
|
|
531
|
+
|
|
514
532
|
static async hasPublicKey(accountId: string, publicKey: string): Promise<boolean> {
|
|
515
533
|
return await rpc.viewMethod({
|
|
516
534
|
args: { account_id: accountId, public_key: publicKey },
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { makeObservable, observable, runInAction } from "mobx";
|
|
2
2
|
import UniversalProvider, { NamespaceConfig } from "@walletconnect/universal-provider";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { HotConnector } from "./HotConnector";
|
|
7
|
-
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
5
|
+
import { EventEmitter } from "./events";
|
|
8
6
|
import { OmniWallet } from "./OmniWallet";
|
|
9
|
-
import { WalletType } from "./
|
|
10
|
-
import { openWCRequest } from "./ui/router";
|
|
7
|
+
import { WalletType } from "./chains";
|
|
11
8
|
|
|
12
9
|
export enum ConnectorType {
|
|
13
10
|
WALLET = "wallet",
|
|
@@ -82,6 +79,7 @@ export abstract class OmniConnector<T extends OmniWallet = OmniWallet, O = {}> {
|
|
|
82
79
|
}
|
|
83
80
|
|
|
84
81
|
async requestWalletConnect<T>(args: { chain?: string; request: any; deeplink?: string; name?: string; icon?: string }): Promise<T> {
|
|
82
|
+
const { openWCRequest } = await import("../ui/router");
|
|
85
83
|
return openWCRequest<T>({
|
|
86
84
|
deeplink: args.deeplink,
|
|
87
85
|
name: args.name || "WalletConnect",
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { hex } from "@scure/base";
|
|
2
|
+
import { action, makeObservable, observable } from "mobx";
|
|
3
|
+
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
5
|
+
import { Commitment } from "./types";
|
|
6
|
+
import { WalletType } from "./chains";
|
|
7
|
+
import { Intents } from "./Intents";
|
|
8
|
+
import { ReviewFee } from "./bridge";
|
|
9
|
+
import { Token } from "./token";
|
|
10
|
+
import { api } from "./api";
|
|
11
|
+
|
|
12
|
+
export abstract class OmniWallet {
|
|
13
|
+
balances: Record<string, bigint> = {};
|
|
14
|
+
|
|
15
|
+
abstract address: string;
|
|
16
|
+
abstract publicKey?: string;
|
|
17
|
+
abstract omniAddress: string;
|
|
18
|
+
abstract type: WalletType;
|
|
19
|
+
abstract icon: string;
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
makeObservable(this, { balances: observable, setBalance: action });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
intents(wibe3?: HotConnector) {
|
|
26
|
+
return new Intents(wibe3).attachWallet(this);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
setBalance(id: string, balance: bigint) {
|
|
30
|
+
this.balances[id] = balance;
|
|
31
|
+
return balance;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getBalance(id: string) {
|
|
35
|
+
return this.balances[id] ?? 0n;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async depositNfts(nftIds: string[], receiver: string) {
|
|
39
|
+
throw new Error("Method not implemented.");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async getDepositNftsFee(nfts: string[]) {
|
|
43
|
+
return new ReviewFee({ chain: -4 });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async withdrawNfts(nftIds: string[], receiver: string) {
|
|
47
|
+
throw new Error("Method not implemented.");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async transferNft(nftId: string, receiver: string) {
|
|
51
|
+
throw new Error("Method not implemented.");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async sendTransaction(tx: any): Promise<string> {
|
|
55
|
+
throw new Error("Method not implemented.");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getTranferNftFee(nftId: string, receiver: string) {
|
|
59
|
+
return new ReviewFee({ chain: -4 });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async getNfts(onLoad: (nfts: string[]) => void) {}
|
|
63
|
+
|
|
64
|
+
async transferFee(token: Token, receiver: string, amount: bigint): Promise<ReviewFee> {
|
|
65
|
+
return new ReviewFee({ chain: -4 });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string> {
|
|
69
|
+
throw new Error("Method not implemented.");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async fetchBalance(chain: number, address: string): Promise<bigint> {
|
|
73
|
+
if (chain !== -4) return 0n;
|
|
74
|
+
const balances = await Intents.getIntentsBalances([address], this.omniAddress);
|
|
75
|
+
return this.setBalance(`${chain}:${address}`, balances[address] || 0n);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async fetchBalances(chain: number, whitelist: string[] = []): Promise<Record<string, bigint>> {
|
|
79
|
+
if (chain === -4) {
|
|
80
|
+
const list = whitelist.length > 0 ? whitelist : await Intents.getIntentsAssets(this.omniAddress);
|
|
81
|
+
const balances = await Intents.getIntentsBalances(list, this.omniAddress);
|
|
82
|
+
Object.entries(balances).forEach(([address, balance]) => this.setBalance(`${chain}:${address}`, BigInt(balance as unknown as string)));
|
|
83
|
+
return balances;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const res = await fetch(`https://api0.herewallet.app/api/v1/user/balances/${chain}/${this.address}`, { body: JSON.stringify({ whitelist }), method: "POST" });
|
|
87
|
+
const { balances } = await res.json();
|
|
88
|
+
|
|
89
|
+
console.log("fetchBalances", { chain, whitelist, balances, l: Object.keys(balances).length });
|
|
90
|
+
if (Object.keys(balances).length === 0) throw "No balances found";
|
|
91
|
+
|
|
92
|
+
Object.entries(balances).forEach(([address, balance]) => this.setBalance(`${chain}:${address}`, BigInt(balance as string)));
|
|
93
|
+
const native = await this.fetchBalance(chain, "native").catch(() => 0n);
|
|
94
|
+
return { ...balances, native };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number; signerId?: string }): Promise<Commitment> {
|
|
98
|
+
throw new Error("Method not implemented.");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async auth<T = string>(intents?: Record<string, any>[], options?: { domain?: string; signerId?: string; customAuth?: (commitment: Commitment, seed: string) => Promise<T> }): Promise<T> {
|
|
102
|
+
const authFn = async () => {
|
|
103
|
+
const seed = hex.encode(new Uint8Array(window.crypto.getRandomValues(new Uint8Array(32))));
|
|
104
|
+
const msgBuffer = new TextEncoder().encode(`${options?.domain || window.location.origin}_${seed}`);
|
|
105
|
+
const nonce = await window.crypto.subtle.digest("SHA-256", new Uint8Array(msgBuffer));
|
|
106
|
+
const signed = await this.signIntents(intents || [], { nonce: new Uint8Array(nonce), signerId: options?.signerId || this.omniAddress });
|
|
107
|
+
|
|
108
|
+
if (options?.customAuth) return await options.customAuth(signed, seed);
|
|
109
|
+
return (await api.auth(signed, seed)) as T;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
if (typeof window === "undefined") return await authFn();
|
|
113
|
+
const { openAuthPopup } = await import("../ui/connect/AuthPopup");
|
|
114
|
+
return openAuthPopup(this, authFn);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async waitUntilOmniBalance(need: Record<string, bigint>, receiver = this.omniAddress, attempts = 0) {
|
|
118
|
+
if (attempts > 120) throw "Balance is not enough";
|
|
119
|
+
const assets = Object.keys(need) as string[];
|
|
120
|
+
const balances = await Intents.getIntentsBalances(assets, receiver);
|
|
121
|
+
if (assets.every((asset) => (balances[asset] || 0n) >= (need[asset] || 0n))) return;
|
|
122
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
123
|
+
await this.waitUntilOmniBalance(need, receiver, attempts + 1);
|
|
124
|
+
}
|
|
125
|
+
}
|
package/src/core/chains.ts
CHANGED
|
@@ -34,7 +34,7 @@ export enum WalletType {
|
|
|
34
34
|
|
|
35
35
|
export enum Network {
|
|
36
36
|
Omni_v1 = 0,
|
|
37
|
-
|
|
37
|
+
Omni = -4,
|
|
38
38
|
|
|
39
39
|
Zcash = -5,
|
|
40
40
|
Btc = -6,
|
|
@@ -332,13 +332,13 @@ const chainsRepository: Record<number, ChainConfig> = {
|
|
|
332
332
|
rpc: rpc(Network.Xlayer),
|
|
333
333
|
type: WalletType.EVM,
|
|
334
334
|
},
|
|
335
|
-
[Network.
|
|
336
|
-
id: Network.
|
|
335
|
+
[Network.Omni]: {
|
|
336
|
+
id: Network.Omni,
|
|
337
337
|
key: "hot",
|
|
338
338
|
name: "Omni",
|
|
339
339
|
logo: "https://tgapp.herewallet.app/images/hot/hot-icon.png",
|
|
340
|
-
currency: { id: "native", symbol: "OMNI", decimals: 6, logo: logo(Network.
|
|
341
|
-
rpc: rpc(Network.
|
|
340
|
+
currency: { id: "native", symbol: "OMNI", decimals: 6, logo: logo(Network.Omni) },
|
|
341
|
+
rpc: rpc(Network.Omni),
|
|
342
342
|
type: WalletType.OMNI,
|
|
343
343
|
},
|
|
344
344
|
[Network.Cardano]: {
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
export const defaultTokens = [
|
|
2
|
-
// {
|
|
3
|
-
// assetId: "nep245:v2_1.omni.hot.tg:4444118_EFL2FKC",
|
|
4
|
-
// decimals: 6,
|
|
5
|
-
// blockchain: "juno-1",
|
|
6
|
-
// symbol: "JUNO",
|
|
7
|
-
// price: 0,
|
|
8
|
-
// priceUpdatedAt: "2025-11-23T18:01:00.349Z",
|
|
9
|
-
// contractAddress: "ujuno",
|
|
10
|
-
// },
|
|
11
2
|
{
|
|
12
3
|
assetId: "nep245:v2_1.omni.hot.tg:36900_11111111111111111111",
|
|
13
4
|
decimals: 18,
|