@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/src/evm/wallet.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { base64, base58, hex } from "@scure/base";
|
|
|
2
2
|
import { BrowserProvider, ethers, JsonRpcProvider, TransactionRequest } from "ethers";
|
|
3
3
|
import { JsonRpcSigner, FetchRequest } from "ethers";
|
|
4
4
|
|
|
5
|
-
import { OmniConnector } from "../OmniConnector";
|
|
6
|
-
import { OmniWallet } from "../OmniWallet";
|
|
7
|
-
import { WalletType } from "../core/chains";
|
|
5
|
+
import { OmniConnector } from "../core/OmniConnector";
|
|
6
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
7
|
+
import { Network, WalletType } from "../core/chains";
|
|
8
8
|
import { ReviewFee } from "../core/bridge";
|
|
9
9
|
import { Token } from "../core/token";
|
|
10
|
-
import { erc20abi } from "./abi";
|
|
11
10
|
import { Commitment } from "../core";
|
|
12
11
|
import { api } from "../core/api";
|
|
12
|
+
import { erc20abi } from "./abi";
|
|
13
13
|
|
|
14
14
|
export interface EvmProvider {
|
|
15
15
|
request: (args: any) => Promise<any>;
|
|
@@ -25,8 +25,8 @@ class EvmWallet extends OmniWallet {
|
|
|
25
25
|
super();
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
get omniAddress() {
|
|
29
|
+
return this.address.toLowerCase();
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
get icon() {
|
|
@@ -35,6 +35,7 @@ class EvmWallet extends OmniWallet {
|
|
|
35
35
|
|
|
36
36
|
private rpcs: Record<number, JsonRpcProvider> = {};
|
|
37
37
|
rpc(chain: number) {
|
|
38
|
+
console.log("getting rpc for chain", { chain });
|
|
38
39
|
if (chain < 1 || chain == null) throw "Invalid chain";
|
|
39
40
|
if (this.rpcs[chain]) return this.rpcs[chain];
|
|
40
41
|
|
|
@@ -46,38 +47,32 @@ class EvmWallet extends OmniWallet {
|
|
|
46
47
|
return rpc;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
async disconnect() {
|
|
51
|
+
await this.provider.request?.({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
54
|
-
|
|
55
|
+
if (chain === Network.Omni) return await super.fetchBalances(chain, whitelist);
|
|
55
56
|
try {
|
|
56
|
-
|
|
57
|
-
if (!res.ok) throw new Error("Failed to fetch balances");
|
|
58
|
-
const { balances } = await res.json();
|
|
59
|
-
return { ...balances, native };
|
|
57
|
+
return await super.fetchBalances(chain, whitelist);
|
|
60
58
|
} catch {
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
const balance = await this.fetchBalance(chain, token);
|
|
64
|
-
return [token, balance];
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
return { ...Object.fromEntries(balances), native };
|
|
59
|
+
const tasks = whitelist.map(async (token) => [token, await this.fetchBalance(chain, token)]);
|
|
60
|
+
return Object.fromEntries(await Promise.all(tasks));
|
|
68
61
|
}
|
|
69
62
|
}
|
|
70
63
|
|
|
71
64
|
async fetchBalance(chain: number, address: string) {
|
|
65
|
+
if (chain === Network.Omni) return super.fetchBalance(chain, address);
|
|
66
|
+
|
|
72
67
|
const rpc = this.rpc(chain);
|
|
73
68
|
if (address === "native") {
|
|
74
69
|
const balance = await rpc.getBalance(this.address);
|
|
75
|
-
return BigInt(balance);
|
|
70
|
+
return this.setBalance(`${chain}:${address}`, BigInt(balance));
|
|
76
71
|
}
|
|
77
72
|
|
|
78
73
|
const erc20 = new ethers.Contract(address, erc20abi, rpc);
|
|
79
74
|
const balance = await erc20.balanceOf(this.address);
|
|
80
|
-
return BigInt(balance);
|
|
75
|
+
return this.setBalance(`${chain}:${address}`, BigInt(balance));
|
|
81
76
|
}
|
|
82
77
|
|
|
83
78
|
async signMessage(msg: string) {
|
|
@@ -107,20 +102,23 @@ class EvmWallet extends OmniWallet {
|
|
|
107
102
|
return fee.changeGasLimit(extaLimit);
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
async sendTransaction(
|
|
105
|
+
async sendTransaction(request: TransactionRequest): Promise<string> {
|
|
106
|
+
if (!request.chainId) throw "Chain ID is required";
|
|
107
|
+
|
|
111
108
|
if (!this.provider.request) throw "not impl";
|
|
112
109
|
const provider = new BrowserProvider(this.provider as any);
|
|
113
110
|
const signer = new JsonRpcSigner(provider, this.address);
|
|
114
111
|
|
|
115
|
-
await this.provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: `0x${
|
|
112
|
+
await this.provider.request({ method: "wallet_switchEthereumChain", params: [{ chainId: `0x${request.chainId.toString(16)}` }] });
|
|
116
113
|
const tx = await signer.sendTransaction(request);
|
|
117
114
|
return tx.hash;
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }): Promise<string> {
|
|
121
118
|
if (args.token.address === "native") {
|
|
122
|
-
return await this.sendTransaction(
|
|
119
|
+
return await this.sendTransaction({
|
|
123
120
|
...args.gasFee?.evmGas,
|
|
121
|
+
chainId: args.token.chain,
|
|
124
122
|
from: this.address,
|
|
125
123
|
value: args.amount,
|
|
126
124
|
to: args.receiver,
|
|
@@ -129,9 +127,10 @@ class EvmWallet extends OmniWallet {
|
|
|
129
127
|
|
|
130
128
|
const erc20 = new ethers.Contract(args.token.address, erc20abi, this.rpc(args.token.chain));
|
|
131
129
|
const tx = await erc20.transfer.populateTransaction(args.receiver, args.amount, { ...args.gasFee?.evmGas });
|
|
130
|
+
tx.chainId = BigInt(args.token.chain);
|
|
132
131
|
tx.from = this.address;
|
|
133
132
|
|
|
134
|
-
return await this.sendTransaction(
|
|
133
|
+
return await this.sendTransaction(tx);
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
async signIntents(intents: Record<string, any>[], options?: { deadline?: number; nonce?: Uint8Array }): Promise<Commitment> {
|
package/src/hot-wallet/google.ts
CHANGED
|
@@ -3,14 +3,14 @@ import { Transaction } from "@stellar/stellar-base";
|
|
|
3
3
|
import { action, makeObservable } from "mobx";
|
|
4
4
|
import uuid4 from "uuid4";
|
|
5
5
|
|
|
6
|
-
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
7
|
-
import { OmniWallet } from "../OmniWallet";
|
|
6
|
+
import { ConnectorType, OmniConnector } from "../core/OmniConnector";
|
|
7
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
8
8
|
import { WalletType } from "../core/chains";
|
|
9
9
|
|
|
10
10
|
import EvmWallet from "../evm/wallet";
|
|
11
|
+
import TonWallet from "../ton/wallet";
|
|
11
12
|
import NearWallet from "../near/wallet";
|
|
12
13
|
import SolanaWallet from "../solana/wallet";
|
|
13
|
-
import TonWallet from "../ton/wallet";
|
|
14
14
|
import StellarWallet from "../stellar/wallet";
|
|
15
15
|
import { HotConnector } from "../HotConnector";
|
|
16
16
|
|
|
@@ -52,10 +52,10 @@ class GoogleConnector extends OmniConnector<OmniWallet> {
|
|
|
52
52
|
const signTransaction = async (transaction: Transaction) => request("stellar:signTransaction", { transaction: transaction.toXDR() });
|
|
53
53
|
this.wallets.push(
|
|
54
54
|
new StellarWallet({
|
|
55
|
-
rpc: this.wibe3.
|
|
55
|
+
rpc: this.wibe3.exchange.bridge.stellar,
|
|
56
56
|
address: account.address,
|
|
57
|
-
signMessage,
|
|
58
57
|
signTransaction,
|
|
58
|
+
signMessage,
|
|
59
59
|
})
|
|
60
60
|
);
|
|
61
61
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@lottiefiles/dotlottie-wc";
|
|
2
2
|
|
|
3
|
-
export { OmniWallet } from "./OmniWallet";
|
|
4
|
-
export { OmniConnector } from "./OmniConnector";
|
|
3
|
+
export { OmniWallet } from "./core/OmniWallet";
|
|
4
|
+
export { OmniConnector } from "./core/OmniConnector";
|
|
5
5
|
export { HotConnector } from "./HotConnector";
|
|
6
6
|
|
|
7
7
|
export { Bridge as BridgeWidget } from "./ui/bridge/Bridge";
|
package/src/near/connector.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { NearConnector } from "@hot-labs/near-connect";
|
|
2
2
|
import { runInAction } from "mobx";
|
|
3
3
|
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
5
|
+
import { ConnectorType, OmniConnector } from "../core/OmniConnector";
|
|
4
6
|
import { WalletType } from "../core/chains";
|
|
5
|
-
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
6
|
-
import { HotConnector } from "../HotConnector";
|
|
7
7
|
import NearWallet from "./wallet";
|
|
8
8
|
|
|
9
9
|
class Connector extends OmniConnector<NearWallet> {
|
package/src/near/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NearConnector as NearConnectorBase } from "@hot-labs/near-connect";
|
|
2
2
|
|
|
3
|
-
import { HotConnector } from "../HotConnector";
|
|
3
|
+
import type { HotConnector } from "../HotConnector";
|
|
4
|
+
|
|
4
5
|
import NearConnector from "./connector";
|
|
5
6
|
import NearWallet from "./wallet";
|
|
6
7
|
|
package/src/near/rpc.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { TypedError, FinalExecutionOutcome } from "@near-js/types";
|
|
|
4
4
|
import { base64 } from "@scure/base";
|
|
5
5
|
|
|
6
6
|
import { api, NetworkError, TimeoutNetworkError } from "../core/api";
|
|
7
|
-
import { Network } from "../core";
|
|
8
7
|
|
|
9
8
|
let _nextId = 123;
|
|
10
9
|
|
|
@@ -14,7 +13,7 @@ const wait = (timeout: number) => {
|
|
|
14
13
|
return new Promise<void>((resolve) => setTimeout(resolve, timeout));
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
const rpcUrls = [api.getRpcUrl(
|
|
16
|
+
const rpcUrls = [api.getRpcUrl(1010), "https://relmn.aurora.dev", "https://archival-rpc.mainnet.near.org", "https://rpc-near.hapi.mobi", "https://nearrpc.aurora.dev"];
|
|
18
17
|
|
|
19
18
|
export class NearRpc extends JsonRpcProvider {
|
|
20
19
|
public providers: string[];
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as ed from "@noble/ed25519";
|
|
2
|
+
import { SignAndSendTransactionParams, SignAndSendTransactionsParams, SignMessageParams, WalletManifest } from "@hot-labs/near-connect";
|
|
3
|
+
import { hex, base58, base64 } from "@scure/base";
|
|
4
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
5
|
+
import { serialize } from "borsh";
|
|
6
|
+
|
|
7
|
+
import NearWallet from "./wallet";
|
|
8
|
+
|
|
9
|
+
const Nep413MessageSchema = {
|
|
10
|
+
struct: {
|
|
11
|
+
message: "string",
|
|
12
|
+
nonce: { array: { type: "u8", len: 32 } },
|
|
13
|
+
recipient: "string",
|
|
14
|
+
callbackUrl: { option: "string" },
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const createNearWallet = async (privateKeyBuf: Buffer, address?: string) => {
|
|
19
|
+
const privateKey = privateKeyBuf.slice(0, 32);
|
|
20
|
+
const publicKeyBuffer = Buffer.from(await ed.getPublicKey(privateKey));
|
|
21
|
+
const addr = address || hex.encode(publicKeyBuffer);
|
|
22
|
+
const publicKey = `ed25519:${base58.encode(publicKeyBuffer)}`;
|
|
23
|
+
|
|
24
|
+
console.log({ publicKey });
|
|
25
|
+
|
|
26
|
+
return new NearWallet(addr, publicKey, {
|
|
27
|
+
manifest: {} as unknown as WalletManifest,
|
|
28
|
+
signAndSendTransaction: async (params: SignAndSendTransactionParams) => {
|
|
29
|
+
throw new Error("Not implemented");
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
signAndSendTransactions: async (params: SignAndSendTransactionsParams) => {
|
|
33
|
+
throw new Error("Not implemented");
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
signMessage: async (params: SignMessageParams) => {
|
|
37
|
+
const serializedPrefix = serialize("u32", 2147484061);
|
|
38
|
+
const serializedParams = serialize(Nep413MessageSchema, params);
|
|
39
|
+
|
|
40
|
+
const serializedMessage = new Uint8Array(serializedPrefix.length + serializedParams.length);
|
|
41
|
+
serializedMessage.set(serializedPrefix);
|
|
42
|
+
serializedMessage.set(serializedParams, serializedPrefix.length);
|
|
43
|
+
|
|
44
|
+
const signature = base64.encode(await ed.sign(sha256(serializedMessage), privateKey));
|
|
45
|
+
return { accountId: addr, publicKey, signature };
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
getAccounts: async () => [{ accountId: addr, publicKey: publicKey }],
|
|
49
|
+
signIn: async () => [{ accountId: addr, publicKey: publicKey }],
|
|
50
|
+
signOut: async () => {},
|
|
51
|
+
});
|
|
52
|
+
};
|
package/src/near/wallet.ts
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
import { NearWalletBase, SignMessageParams, SignedMessage, SignAndSendTransactionParams, SignAndSendTransactionsParams } from "@hot-labs/near-connect";
|
|
2
2
|
import { base64, base58 } from "@scure/base";
|
|
3
|
+
import crypto from "crypto";
|
|
3
4
|
|
|
4
|
-
import { OmniWallet } from "../OmniWallet";
|
|
5
|
-
import { WalletType } from "../core/chains";
|
|
5
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
6
|
+
import { Network, WalletType } from "../core/chains";
|
|
6
7
|
import { ReviewFee } from "../core/bridge";
|
|
7
8
|
import { Token } from "../core/token";
|
|
8
9
|
import { Commitment } from "../core";
|
|
10
|
+
|
|
9
11
|
import { rpc, TGAS } from "./rpc";
|
|
12
|
+
import { createNearWallet } from "./standalone";
|
|
10
13
|
|
|
11
14
|
export default class NearWallet extends OmniWallet {
|
|
12
15
|
readonly icon = "https://storage.herewallet.app/upload/73a44e583769f11112b0eff1f2dd2a560c05eed5f6d92f0c03484fa047c31668.png";
|
|
13
16
|
readonly type = WalletType.NEAR;
|
|
14
17
|
|
|
18
|
+
static fromPrivateKey(privateKey: Buffer, address?: string) {
|
|
19
|
+
return createNearWallet(privateKey, address);
|
|
20
|
+
}
|
|
21
|
+
|
|
15
22
|
constructor(readonly address: string, readonly publicKey?: string, readonly wallet?: NearWalletBase) {
|
|
16
23
|
super();
|
|
17
24
|
}
|
|
@@ -20,15 +27,14 @@ export default class NearWallet extends OmniWallet {
|
|
|
20
27
|
return this.address;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
|
-
async fetchBalances(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return Object.fromEntries(balances);
|
|
30
|
+
async fetchBalances(chain: number, whitelist: string[] = []): Promise<Record<string, bigint>> {
|
|
31
|
+
if (chain === Network.Omni) return await super.fetchBalances(chain, whitelist);
|
|
32
|
+
try {
|
|
33
|
+
return await super.fetchBalances(chain, whitelist);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
const tasks = whitelist.map(async (token) => [token, await this.fetchBalance(chain, token)]);
|
|
36
|
+
return Object.fromEntries(await Promise.all(tasks));
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
async sendTransactions(params: SignAndSendTransactionsParams): Promise<string[]> {
|
|
@@ -111,7 +117,7 @@ export default class NearWallet extends OmniWallet {
|
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
async fetchBalance(chain: number, address: string) {
|
|
114
|
-
if (chain !== 1010)
|
|
120
|
+
if (chain !== 1010) return super.fetchBalance(chain, address);
|
|
115
121
|
|
|
116
122
|
if (address === "native") {
|
|
117
123
|
const protocolConfig = await rpc.experimental_protocolConfig({ finality: "near-final" });
|
|
@@ -121,7 +127,7 @@ export default class NearWallet extends OmniWallet {
|
|
|
121
127
|
const locked = BigInt(state.locked);
|
|
122
128
|
const total = BigInt(state.amount) + locked;
|
|
123
129
|
const available = total - (locked > usedOnStorage ? locked : usedOnStorage);
|
|
124
|
-
return available < 0n ? 0n : available;
|
|
130
|
+
return this.setBalance(`${chain}:${address}`, available < 0n ? 0n : available);
|
|
125
131
|
}
|
|
126
132
|
|
|
127
133
|
const balance = await rpc.viewMethod({
|
|
@@ -130,7 +136,7 @@ export default class NearWallet extends OmniWallet {
|
|
|
130
136
|
methodName: "ft_balance_of",
|
|
131
137
|
});
|
|
132
138
|
|
|
133
|
-
return BigInt(balance);
|
|
139
|
+
return this.setBalance(`${chain}:${address}`, BigInt(balance));
|
|
134
140
|
}
|
|
135
141
|
|
|
136
142
|
async transfer(args: { token: Token; receiver: string; amount: bigint; comment?: string; gasFee?: ReviewFee }) {
|
|
@@ -207,7 +213,7 @@ export default class NearWallet extends OmniWallet {
|
|
|
207
213
|
async signIntents(intents: Record<string, any>[], options?: { nonce?: Uint8Array; deadline?: number; signerId?: string }): Promise<Commitment> {
|
|
208
214
|
if (!this.wallet) throw "not impl";
|
|
209
215
|
|
|
210
|
-
const nonce = new Uint8Array(options?.nonce ||
|
|
216
|
+
const nonce = new Uint8Array(options?.nonce || crypto.randomBytes(32));
|
|
211
217
|
const message = JSON.stringify({
|
|
212
218
|
deadline: options?.deadline ? new Date(options.deadline).toISOString() : "2100-01-01T00:00:00.000Z",
|
|
213
219
|
signer_id: options?.signerId || this.omniAddress,
|
package/src/solana/connector.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { Transaction, PublicKey, VersionedTransaction, Connection } from "@solan
|
|
|
3
3
|
import { base58 } from "@scure/base";
|
|
4
4
|
import { runInAction } from "mobx";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
6
|
+
import type { HotConnector } from "../HotConnector";
|
|
7
|
+
|
|
8
|
+
import { ConnectorType, OmniConnector, WC_ICON } from "../core/OmniConnector";
|
|
9
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
9
10
|
import { WalletType } from "../core/chains";
|
|
10
11
|
import HOT from "../hot-wallet/iframe";
|
|
11
12
|
|
|
@@ -16,8 +17,8 @@ import SolanaWallet from "./wallet";
|
|
|
16
17
|
const wallets = getWallets();
|
|
17
18
|
|
|
18
19
|
class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
19
|
-
type = ConnectorType.WALLET;
|
|
20
20
|
walletTypes = [WalletType.SOLANA, WalletType.OMNI];
|
|
21
|
+
type = ConnectorType.WALLET;
|
|
21
22
|
|
|
22
23
|
icon = "https://storage.herewallet.app/upload/8700f33153ad813e133e5bf9b791b5ecbeea66edca6b8d17aeccb8048eb29ef7.png";
|
|
23
24
|
name = "Solana Wallet";
|
|
@@ -70,8 +71,16 @@ class SolanaConnector extends OmniConnector<SolanaWallet, { wallet: Wallet }> {
|
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
this.initWalletConnect()
|
|
73
|
-
.then(async (
|
|
74
|
-
this.options.unshift({
|
|
74
|
+
.then(async () => {
|
|
75
|
+
this.options.unshift({
|
|
76
|
+
type: "external",
|
|
77
|
+
download: "https://www.walletconnect.com/get",
|
|
78
|
+
wallet: {} as Wallet,
|
|
79
|
+
name: "WalletConnect",
|
|
80
|
+
id: "walletconnect",
|
|
81
|
+
icon: WC_ICON,
|
|
82
|
+
});
|
|
83
|
+
|
|
75
84
|
const selected = await this.getConnectedWallet();
|
|
76
85
|
if (selected.type !== "walletconnect") return;
|
|
77
86
|
this.setupWalletConnect();
|
package/src/solana/wallet.ts
CHANGED
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
getMinimumBalanceForRentExemptAccount,
|
|
8
8
|
createAssociatedTokenAccountInstruction,
|
|
9
9
|
createTransferInstruction,
|
|
10
|
-
getAccount,
|
|
11
10
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
12
11
|
getAssociatedTokenAddressSync,
|
|
13
12
|
createTransferCheckedInstruction,
|
|
13
|
+
getAccount,
|
|
14
14
|
} from "@solana/spl-token";
|
|
15
15
|
|
|
16
16
|
import { Network, WalletType } from "../core/chains";
|
|
17
|
-
import { OmniWallet } from "../OmniWallet";
|
|
17
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
18
18
|
|
|
19
19
|
import { Token } from "../core/token";
|
|
20
20
|
import { formatter } from "../core/utils";
|
|
@@ -50,17 +50,18 @@ class SolanaWallet extends OmniWallet {
|
|
|
50
50
|
return hex.encode(base58.decode(this.address)).toLowerCase();
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
async fetchBalance(
|
|
53
|
+
async fetchBalance(chain: number, address: string) {
|
|
54
|
+
if (chain !== Network.Solana) return super.fetchBalance(chain, address);
|
|
54
55
|
const connection = this.getConnection();
|
|
55
56
|
|
|
56
57
|
if (address === "native") {
|
|
57
58
|
const balance = await connection.getBalance(new PublicKey(this.address));
|
|
58
|
-
return BigInt(balance);
|
|
59
|
+
return this.setBalance(`${chain}:${address}`, BigInt(balance));
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
const ATA = getAssociatedTokenAddressSync(new PublicKey(address), new PublicKey(this.address));
|
|
62
63
|
const meta = await connection.getTokenAccountBalance(ATA);
|
|
63
|
-
return BigInt(meta.value.amount);
|
|
64
|
+
return this.setBalance(`${chain}:${address}`, BigInt(meta.value.amount));
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
async buildTranferInstructions(token: Token, amount: bigint, receiver: string, fee: ReviewFee) {
|
|
@@ -174,15 +175,13 @@ class SolanaWallet extends OmniWallet {
|
|
|
174
175
|
return await this.wallet.sendTransaction(transaction, connection, { preflightCommitment: "confirmed" });
|
|
175
176
|
}
|
|
176
177
|
|
|
177
|
-
async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
|
|
178
|
-
|
|
179
|
-
const connection = this.getConnection();
|
|
180
|
-
|
|
178
|
+
async fetchBalances(chain: number, whitelist: string[] = []): Promise<Record<string, bigint>> {
|
|
179
|
+
if (chain === Network.Omni) return await super.fetchBalances(chain, whitelist);
|
|
181
180
|
try {
|
|
182
|
-
|
|
183
|
-
const { balances } = await res.json();
|
|
184
|
-
return { ...balances, native };
|
|
181
|
+
return await super.fetchBalances(chain, whitelist);
|
|
185
182
|
} catch {
|
|
183
|
+
const connection = this.getConnection();
|
|
184
|
+
const native = await this.fetchBalance(chain, "native");
|
|
186
185
|
const tokenAccounts = await connection.getParsedTokenAccountsByOwner(new PublicKey(this.address), { programId: TOKEN_PROGRAM_ID });
|
|
187
186
|
const balances = Object.fromEntries(
|
|
188
187
|
tokenAccounts.value.map((account) => {
|
|
@@ -191,6 +190,7 @@ class SolanaWallet extends OmniWallet {
|
|
|
191
190
|
})
|
|
192
191
|
);
|
|
193
192
|
|
|
193
|
+
Object.entries(balances).forEach(([address, balance]) => this.setBalance(`${chain}:${address}`, BigInt(balance as string)));
|
|
194
194
|
return { ...balances, native };
|
|
195
195
|
}
|
|
196
196
|
}
|
package/src/stellar/connector.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Transaction } from "@stellar/stellar-base";
|
|
2
2
|
|
|
3
3
|
import HOT from "../hot-wallet/iframe";
|
|
4
|
-
import {
|
|
5
|
-
import { HotConnector } from "../HotConnector";
|
|
6
|
-
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
7
5
|
|
|
6
|
+
import { WalletType } from "../core/chains";
|
|
7
|
+
import { ConnectorType, OmniConnector } from "../core/OmniConnector";
|
|
8
8
|
import { FreighterModule } from "./freigher";
|
|
9
9
|
import { HotWalletModule } from "./hotWallet";
|
|
10
10
|
import StellarWallet from "./wallet";
|
|
@@ -56,7 +56,8 @@ class StellarConnector extends OmniConnector<StellarWallet> {
|
|
|
56
56
|
async selectWallet(address: string, wallet: HotWalletModule | FreighterModule) {
|
|
57
57
|
const signMessage = async (message: string) => wallet.signMessage(message);
|
|
58
58
|
const signTransaction = async (transaction: Transaction) => wallet.signTransaction(transaction.toXDR());
|
|
59
|
-
|
|
59
|
+
const instance = new StellarWallet({ address, rpc: this.wibe3.exchange.bridge.stellar, signMessage, signTransaction });
|
|
60
|
+
return this.setWallet(instance);
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
async connect(id: string) {
|
package/src/stellar/wallet.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { base64, base58, hex, base32 } from "@scure/base";
|
|
|
2
2
|
import { Address, Asset, BASE_FEE, Claimant, Contract, Memo, nativeToScVal, Networks, Operation, TimeoutInfinite, Transaction, TransactionBuilder, xdr } from "@stellar/stellar-base";
|
|
3
3
|
import { rpc } from "@stellar/stellar-sdk";
|
|
4
4
|
|
|
5
|
+
import { Commitment } from "../core/types";
|
|
5
6
|
import { WalletType } from "../core/chains";
|
|
6
|
-
import { OmniWallet } from "../OmniWallet";
|
|
7
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
7
8
|
import { ReviewFee } from "../core/bridge";
|
|
8
9
|
import { formatter } from "../core/utils";
|
|
9
10
|
import { Network } from "../core/chains";
|
|
10
11
|
import { Token } from "../core/token";
|
|
11
|
-
import { Commitment } from "../core";
|
|
12
12
|
|
|
13
13
|
interface ProtocolWallet {
|
|
14
14
|
address: string;
|
|
@@ -52,30 +52,36 @@ class StellarWallet extends OmniWallet {
|
|
|
52
52
|
return hex.encode(payload.slice(1, -2));
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
async fetchBalances(): Promise<Record<string, bigint>> {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
55
|
+
async fetchBalances(chain: number): Promise<Record<string, bigint>> {
|
|
56
|
+
if (chain === Network.Omni) return await super.fetchBalances(chain);
|
|
57
|
+
try {
|
|
58
|
+
return await super.fetchBalances(chain);
|
|
59
|
+
} catch {
|
|
60
|
+
const data = await fetch(`https://horizon.stellar.org/accounts/${this.address}`).then((res) => res.json());
|
|
61
|
+
const balances = data.balances?.map((ft: { asset_type: string; sponsor?: string | null; asset_code: string; asset_issuer: string; balance: string }) => {
|
|
62
|
+
const asset = ft.asset_type === "native" ? Asset.native() : new Asset(ft.asset_code, ft.asset_issuer);
|
|
63
|
+
const contractId = ft.asset_type === "native" ? "native" : asset.contractId(Networks.PUBLIC);
|
|
64
|
+
|
|
65
|
+
if (contractId === "native") {
|
|
66
|
+
const activatingReserve = ft.sponsor != null ? 0 : 1;
|
|
67
|
+
const trustlines = data.balances.filter((t: any) => t.asset_type !== "native" && t.sponsor == null);
|
|
68
|
+
const balance = BigInt(formatter.parseAmount(ft.balance, 7));
|
|
69
|
+
const reserved = BigInt(formatter.parseAmount(activatingReserve + 0.5 * (trustlines.length + (data.num_sponsoring || 0)), 7));
|
|
70
|
+
return [contractId, formatter.bigIntMax(0n, balance - BigInt(reserved))];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return [contractId, BigInt(formatter.parseAmount(ft.balance, 7))];
|
|
74
|
+
});
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
Object.entries(balances).forEach(([address, balance]) => this.setBalance(`${chain}:${address}`, BigInt(balance as string)));
|
|
77
|
+
return Object.fromEntries(balances);
|
|
78
|
+
}
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
async fetchBalance(chain: number, token: string): Promise<bigint> {
|
|
76
|
-
if (chain !== Network.Stellar)
|
|
77
|
-
const balances = await this.fetchBalances();
|
|
78
|
-
return balances[token] || 0n;
|
|
82
|
+
if (chain !== Network.Stellar) return super.fetchBalance(chain, token);
|
|
83
|
+
const balances = await this.fetchBalances(chain);
|
|
84
|
+
return this.setBalance(`${chain}:${token}`, balances[token] || 0n);
|
|
79
85
|
}
|
|
80
86
|
|
|
81
87
|
async transferFee(token: Token): Promise<ReviewFee> {
|
package/src/ton/connector.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { TonConnectUI, TonConnect, Feature } from "@tonconnect/ui";
|
|
2
2
|
import { runInAction } from "mobx";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import { HotConnector } from "../HotConnector";
|
|
6
|
-
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
4
|
+
import type { HotConnector } from "../HotConnector";
|
|
7
5
|
import HOT from "../hot-wallet/iframe";
|
|
6
|
+
|
|
7
|
+
import { WalletType } from "../core/chains";
|
|
8
|
+
import { ConnectorType, OmniConnector } from "../core/OmniConnector";
|
|
8
9
|
import TonWallet from "./wallet";
|
|
9
10
|
|
|
10
11
|
export interface TonConnectorOptions {
|
package/src/ton/wallet.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { JettonVerificationType } from "@ton-api/client";
|
|
|
4
4
|
import { toUserFriendlyAddress } from "@tonconnect/ui";
|
|
5
5
|
import { base58, base64, hex } from "@scure/base";
|
|
6
6
|
|
|
7
|
-
import { OmniWallet } from "../OmniWallet";
|
|
8
|
-
import { WalletType } from "../core/chains";
|
|
7
|
+
import { OmniWallet } from "../core/OmniWallet";
|
|
8
|
+
import { Network, WalletType } from "../core/chains";
|
|
9
9
|
import { ReviewFee } from "../core/bridge";
|
|
10
10
|
import { Token } from "../core/token";
|
|
11
11
|
|
|
@@ -40,31 +40,37 @@ class TonWallet extends OmniWallet {
|
|
|
40
40
|
return this.wallet.account.publicKey.toLowerCase();
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
async fetchBalances(): Promise<Record<string, bigint>> {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
async fetchBalances(chain: number): Promise<Record<string, bigint>> {
|
|
44
|
+
if (chain === Network.Omni) return await super.fetchBalances(chain);
|
|
45
|
+
try {
|
|
46
|
+
return await super.fetchBalances(chain);
|
|
47
|
+
} catch {
|
|
48
|
+
const native = await this.fetchBalance(chain, "native");
|
|
49
|
+
const { balances } = await tonApi.accounts.getAccountJettonsBalances(Address.parse(this.address), { supported_extensions: ["custom_payload"] });
|
|
50
|
+
const list: Record<string, bigint> = {};
|
|
51
|
+
|
|
52
|
+
balances.map((data) => {
|
|
53
|
+
const jetton = data.jetton.address.toString();
|
|
54
|
+
if (data.walletAddress.isScam || data.jetton.verification === JettonVerificationType.Blacklist) return;
|
|
55
|
+
list[jetton] = BigInt(data.balance);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
Object.entries(list).forEach(([address, balance]) => this.setBalance(`${chain}:${address}`, balance));
|
|
59
|
+
return { ...list, native };
|
|
60
|
+
}
|
|
56
61
|
}
|
|
57
62
|
|
|
58
|
-
async fetchBalance(
|
|
63
|
+
async fetchBalance(chain: number, address: string) {
|
|
64
|
+
if (chain !== Network.Ton) return super.fetchBalance(chain, address);
|
|
59
65
|
const owner = Address.parse(this.address);
|
|
60
66
|
|
|
61
67
|
if (address === "native") {
|
|
62
68
|
const balance = await tonApi.accounts.getAccount(owner);
|
|
63
|
-
return BigInt(balance.balance);
|
|
69
|
+
return this.setBalance(`${Network.Ton}:${address}`, BigInt(balance.balance));
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
const jetton = await tonApi.accounts.getAccountJettonBalance(owner, Address.parse(address), { supported_extensions: ["custom_payload"] });
|
|
67
|
-
return BigInt(jetton.balance);
|
|
73
|
+
return this.setBalance(`${Network.Ton}:${address}`, BigInt(jetton.balance));
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
async waitNextSeqno(seqno: number): Promise<number> {
|
package/src/tron/connector.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { HotConnector } from "../HotConnector";
|
|
2
|
+
import { ConnectorType, OmniConnector } from "../core/OmniConnector";
|
|
1
3
|
import { WalletType } from "../core/chains";
|
|
2
|
-
import { ConnectorType, OmniConnector } from "../OmniConnector";
|
|
3
|
-
import { HotConnector } from "../HotConnector";
|
|
4
4
|
import TronWallet from "./wallet";
|
|
5
5
|
|
|
6
6
|
declare global {
|