@hot-labs/kit 1.0.45 → 1.0.47

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.
@@ -23,13 +23,15 @@ import { ReviewFee } from "../core/bridge";
23
23
 
24
24
  import { ISolanaProtocolWallet } from "./protocol";
25
25
 
26
- const connection = new Connection("https://api0.herewallet.app/api/v1/evm/rpc/1001");
27
-
28
26
  class SolanaWallet extends OmniWallet {
29
27
  readonly type = WalletType.SOLANA;
28
+ readonly connection: Connection;
30
29
 
31
30
  constructor(readonly connector: OmniConnector, readonly wallet: ISolanaProtocolWallet) {
32
31
  super(connector);
32
+ this.connection = new Connection("https://api0.herewallet.app/api/v1/evm/rpc/1001", {
33
+ httpHeaders: { "Api-Key": connector.wibe3.api.apiKey },
34
+ });
33
35
  }
34
36
 
35
37
  get address() {
@@ -46,12 +48,12 @@ class SolanaWallet extends OmniWallet {
46
48
 
47
49
  async fetchBalance(_: number, address: string) {
48
50
  if (address === "native") {
49
- const balance = await connection.getBalance(new PublicKey(this.address));
51
+ const balance = await this.connection.getBalance(new PublicKey(this.address));
50
52
  return BigInt(balance);
51
53
  }
52
54
 
53
55
  const ATA = getAssociatedTokenAddressSync(new PublicKey(address), new PublicKey(this.address));
54
- const meta = await connection.getTokenAccountBalance(ATA);
56
+ const meta = await this.connection.getTokenAccountBalance(ATA);
55
57
  return BigInt(meta.value.amount);
56
58
  }
57
59
 
@@ -78,7 +80,7 @@ class SolanaWallet extends OmniWallet {
78
80
  const destination = new PublicKey(receiver);
79
81
  const owner = new PublicKey(this.address);
80
82
 
81
- const reserve = await connection.getMinimumBalanceForRentExemption(0);
83
+ const reserve = await this.connection.getMinimumBalanceForRentExemption(0);
82
84
  let additionalFee = 0n;
83
85
 
84
86
  if (token.address === "native") {
@@ -94,7 +96,7 @@ class SolanaWallet extends OmniWallet {
94
96
  }
95
97
 
96
98
  const mint = new PublicKey(token.address);
97
- const mintAccount = await connection.getAccountInfo(mint);
99
+ const mintAccount = await this.connection.getAccountInfo(mint);
98
100
  const tokenProgramId = mintAccount?.owner.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID;
99
101
 
100
102
  const tokenFrom = getAssociatedTokenAddressSync(mint, owner, false, tokenProgramId);
@@ -102,11 +104,11 @@ class SolanaWallet extends OmniWallet {
102
104
 
103
105
  const instructions: TransactionInstruction[] = [ComputeBudgetProgram.setComputeUnitPrice({ microLamports: Number(fee.baseFee) }), ComputeBudgetProgram.setComputeUnitLimit({ units: Number(fee.gasLimit) })];
104
106
 
105
- const isRegistered = await getAccount(connection, tokenTo, "confirmed", tokenProgramId).catch(() => null);
107
+ const isRegistered = await getAccount(this.connection, tokenTo, "confirmed", tokenProgramId).catch(() => null);
106
108
  if (isRegistered == null) {
107
109
  const inst = createAssociatedTokenAccountInstruction(new PublicKey(this.address), tokenTo, destination, mint, tokenProgramId, ASSOCIATED_TOKEN_PROGRAM_ID);
108
110
  instructions.push(inst);
109
- additionalFee += BigInt(await getMinimumBalanceForRentExemptAccount(connection));
111
+ additionalFee += BigInt(await getMinimumBalanceForRentExemptAccount(this.connection));
110
112
  }
111
113
 
112
114
  if (tokenProgramId === TOKEN_2022_PROGRAM_ID) {
@@ -119,7 +121,7 @@ class SolanaWallet extends OmniWallet {
119
121
  }
120
122
 
121
123
  async transferFee(token: Token, receiver: string): Promise<ReviewFee> {
122
- const { blockhash } = await connection.getLatestBlockhash();
124
+ const { blockhash } = await this.connection.getLatestBlockhash();
123
125
  const fee = new ReviewFee({ chain: Network.Solana, gasLimit: 1_400_000n, baseFee: 100n });
124
126
  const { instructions, additionalFee, reserve } = await this.buildTranferInstructions(token, 1n, receiver, fee);
125
127
 
@@ -132,10 +134,10 @@ class SolanaWallet extends OmniWallet {
132
134
  });
133
135
 
134
136
  if (priorityFeeData?.priorityFeeLevels == null) throw "Failed to fetch gas";
135
- const simulate = await connection.simulateTransaction(tx).catch(() => null);
137
+ const simulate = await this.connection.simulateTransaction(tx).catch(() => null);
136
138
  const unitsConsumed = formatter.bigIntMax(BigInt(simulate?.value.unitsConsumed || 10_000n), 10_000n);
137
139
 
138
- const msgFee = await connection.getFeeForMessage(msgForEstimate);
140
+ const msgFee = await this.connection.getFeeForMessage(msgForEstimate);
139
141
  const medium = BigInt(priorityFeeData.priorityFeeLevels.medium);
140
142
  const high = BigInt(priorityFeeData.priorityFeeLevels.high);
141
143
  const veryHigh = BigInt(priorityFeeData.priorityFeeLevels.veryHigh);
@@ -176,10 +178,10 @@ class SolanaWallet extends OmniWallet {
176
178
 
177
179
  async sendTransaction(instructions: TransactionInstruction[]): Promise<string> {
178
180
  if (!this.wallet.sendTransaction) throw "not impl";
179
- const { blockhash } = await connection.getLatestBlockhash();
181
+ const { blockhash } = await this.connection.getLatestBlockhash();
180
182
  const message = new TransactionMessage({ payerKey: new PublicKey(this.address), recentBlockhash: blockhash, instructions });
181
183
  const transaction = new VersionedTransaction(message.compileToV0Message());
182
- return await this.wallet.sendTransaction(transaction, connection, { preflightCommitment: "confirmed" });
184
+ return await this.wallet.sendTransaction(transaction, this.connection, { preflightCommitment: "confirmed" });
183
185
  }
184
186
 
185
187
  async fetchBalances(chain: number, whitelist: string[]): Promise<Record<string, bigint>> {
@@ -189,7 +191,7 @@ class SolanaWallet extends OmniWallet {
189
191
  const { balances } = await res.json();
190
192
  return { ...balances, native };
191
193
  } catch {
192
- const tokenAccounts = await connection.getParsedTokenAccountsByOwner(new PublicKey(this.address), { programId: TOKEN_PROGRAM_ID });
194
+ const tokenAccounts = await this.connection.getParsedTokenAccountsByOwner(new PublicKey(this.address), { programId: TOKEN_PROGRAM_ID });
193
195
  const balances = Object.fromEntries(
194
196
  tokenAccounts.value.map((account) => {
195
197
  const { mint, tokenAmount } = account.account.data.parsed.info;
@@ -26,6 +26,7 @@ export interface BridgeProps {
26
26
  widget?: boolean;
27
27
  onClose: () => void;
28
28
  onProcess: (task: Promise<BridgeReview>) => void;
29
+ onSelectPair?: (from: Token, to: Token) => void;
29
30
  setup?: {
30
31
  mobileFullscreen?: boolean;
31
32
  autoClose?: boolean; // if true, the popup will close automatically when the transaction is successful
@@ -44,7 +45,7 @@ export interface BridgeProps {
44
45
 
45
46
  const FIXED = 6;
46
47
 
47
- export const Bridge = observer(({ hot, widget, setup, onClose, onProcess }: BridgeProps) => {
48
+ export const Bridge = observer(({ hot, widget, setup, onClose, onProcess, onSelectPair }: BridgeProps) => {
48
49
  const [isFiat, setIsFiat] = useState(false);
49
50
  const [type, setType] = useState<"exactIn" | "exactOut">(setup?.type || "exactIn");
50
51
  const [value, setValue] = useState<string>(setup?.amount?.toString() ?? "");
@@ -63,6 +64,10 @@ export const Bridge = observer(({ hot, widget, setup, onClose, onProcess }: Brid
63
64
  review: BridgeReview;
64
65
  } | null>(null);
65
66
 
67
+ useEffect(() => {
68
+ onSelectPair?.(from, to);
69
+ }, [from, to]);
70
+
66
71
  const [sender, setSender] = useState<OmniWallet | "qr" | undefined>(() => {
67
72
  if (setup?.sender) return setup.sender;
68
73
  if (from.type === WalletType.OMNI) return hot.priorityWallet;