@agg-build/hooks 2.0.0 → 2.1.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/dist/deposit.js CHANGED
@@ -91,13 +91,54 @@ function normalizeWalletError(error, supportedChains) {
91
91
  }
92
92
 
93
93
  // src/deposit/use-wallet-token-balance.ts
94
- var import_web3 = require("@solana/web3.js");
94
+ var import_web32 = require("@solana/web3.js");
95
95
  var import_react_query = require("@tanstack/react-query");
96
96
  var import_viem = require("viem");
97
97
  var import_wagmi = require("wagmi");
98
98
 
99
- // src/core/providers/contexts.ts
99
+ // src/deposit/constants.ts
100
+ var DEFAULT_SOLANA_RPC_ENDPOINTS = [
101
+ "https://api.mainnet.solana.com",
102
+ "https://solana-rpc.publicnode.com"
103
+ ];
104
+ var DEFAULT_SOLANA_RPC_ENDPOINT = DEFAULT_SOLANA_RPC_ENDPOINTS[0];
105
+ var SVM_CHAIN_IDS = /* @__PURE__ */ new Set([792703809]);
106
+ var MULTI_CHAIN_SOLANA_WALLET_NAMES = /* @__PURE__ */ new Set(["Phantom"]);
107
+
108
+ // src/deposit/use-svm-address.ts
100
109
  var import_react = require("react");
110
+ var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
111
+ function getPhantomProvider() {
112
+ var _a, _b;
113
+ if (typeof window === "undefined") return void 0;
114
+ const w = window;
115
+ return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
116
+ }
117
+ function useSvmAddress() {
118
+ var _a;
119
+ const { publicKey: adapterPublicKey } = (0, import_wallet_adapter_react.useWallet)();
120
+ const [phantomAddress, setPhantomAddress] = (0, import_react.useState)(void 0);
121
+ (0, import_react.useEffect)(() => {
122
+ var _a2;
123
+ const provider = getPhantomProvider();
124
+ if (!provider) return;
125
+ const existing = (_a2 = provider.publicKey) == null ? void 0 : _a2.toBase58();
126
+ if (existing) {
127
+ setPhantomAddress(existing);
128
+ return;
129
+ }
130
+ provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {
131
+ });
132
+ }, []);
133
+ return (_a = adapterPublicKey == null ? void 0 : adapterPublicKey.toBase58()) != null ? _a : phantomAddress;
134
+ }
135
+
136
+ // src/deposit/svm-connections.ts
137
+ var import_web3 = require("@solana/web3.js");
138
+ var import_react4 = require("react");
139
+
140
+ // src/core/providers/contexts.ts
141
+ var import_react2 = require("react");
101
142
 
102
143
  // src/core/ui-config/labels.ts
103
144
  var enUsLabels = {
@@ -108,6 +149,8 @@ var enUsLabels = {
108
149
  errorPrefix: "Error",
109
150
  tabsAria: "Tabs",
110
151
  hiddenTabsAria: "Hidden tabs",
152
+ scrollTabsLeft: "Scroll tabs left",
153
+ scrollTabsRight: "Scroll tabs right",
111
154
  selectAria: "Select",
112
155
  lineChartAria: "Line chart",
113
156
  candlestickChartAria: "Candlestick chart",
@@ -270,6 +313,7 @@ var enUsLabels = {
270
313
  networkReserveTooltipLineTwo: "Any unused amount stays in your balance.",
271
314
  youReceive: "You'll receive",
272
315
  confirm: "Confirm withdrawal",
316
+ calculatingFees: "Calculating fees\u2026",
273
317
  successTitle: "Withdrawal submitted",
274
318
  successDescription: (tokenSymbol) => `Your ${tokenSymbol} withdrawal is being processed and will arrive shortly.`,
275
319
  // Terminal-state copy. The success step swaps `successTitle` /
@@ -684,6 +728,9 @@ var enUsLabels = {
684
728
  buyingOutcome: (label) => `Buying ${label}`,
685
729
  sellingOutcome: (label) => `Selling ${label}`,
686
730
  findingBestRoute: "Finding the best route...",
731
+ findingBestOdds: "Finding best odds\u2026",
732
+ updatingRoute: "Updating route\u2026",
733
+ refreshingQuotes: "Refreshing quotes\u2026",
687
734
  checkingBalance: "Checking balance",
688
735
  submittingOrderProgress: "Submitting order...",
689
736
  orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
@@ -1004,7 +1051,8 @@ var defaultAggUiConfig = {
1004
1051
  enableNotifications: true
1005
1052
  },
1006
1053
  market: {
1007
- arbitrageThreshold: 0
1054
+ arbitrageThreshold: 0,
1055
+ maxMidpointIdsPerRequest: 75
1008
1056
  },
1009
1057
  chart: {
1010
1058
  defaultChartTimeRange: "1D",
@@ -1017,11 +1065,11 @@ var defaultAggUiConfig = {
1017
1065
  };
1018
1066
 
1019
1067
  // src/core/providers/contexts.ts
1020
- var AggClientContext = (0, import_react.createContext)(null);
1021
- var AggUiContext = (0, import_react.createContext)(defaultAggUiConfig);
1022
- var AggLabelsContext = (0, import_react.createContext)(defaultAggUiConfig.general.labels);
1023
- var AggAuthContext = (0, import_react.createContext)(null);
1024
- var AggBalanceContext = (0, import_react.createContext)(null);
1068
+ var AggClientContext = (0, import_react2.createContext)(null);
1069
+ var AggUiContext = (0, import_react2.createContext)(defaultAggUiConfig);
1070
+ var AggLabelsContext = (0, import_react2.createContext)(defaultAggUiConfig.general.labels);
1071
+ var AggAuthContext = (0, import_react2.createContext)(null);
1072
+ var AggBalanceContext = (0, import_react2.createContext)(null);
1025
1073
 
1026
1074
  // src/execution/query-keys.ts
1027
1075
  var executionKeys = {
@@ -1102,19 +1150,19 @@ var invalidateUserMoneyState = (queryClient, options) => {
1102
1150
  };
1103
1151
 
1104
1152
  // src/core/providers/hooks.ts
1105
- var import_react2 = require("react");
1153
+ var import_react3 = require("react");
1106
1154
  var useAggClient = () => {
1107
- const client = (0, import_react2.useContext)(AggClientContext);
1155
+ const client = (0, import_react3.useContext)(AggClientContext);
1108
1156
  if (!client) {
1109
1157
  throw new Error("useAggClient must be used within an <AggProvider>");
1110
1158
  }
1111
1159
  return client;
1112
1160
  };
1113
1161
  var useAggUiConfig = () => {
1114
- return (0, import_react2.useContext)(AggUiContext);
1162
+ return (0, import_react3.useContext)(AggUiContext);
1115
1163
  };
1116
1164
  var useAggAuthContext = () => {
1117
- const context = (0, import_react2.useContext)(AggAuthContext);
1165
+ const context = (0, import_react3.useContext)(AggAuthContext);
1118
1166
  if (!context) {
1119
1167
  throw new Error("useAggAuthContext must be used within an <AggProvider>");
1120
1168
  }
@@ -1122,7 +1170,7 @@ var useAggAuthContext = () => {
1122
1170
  };
1123
1171
  var useAggAuthState = useAggAuthContext;
1124
1172
  var useAggBalanceContext = () => {
1125
- const context = (0, import_react2.useContext)(AggBalanceContext);
1173
+ const context = (0, import_react3.useContext)(AggBalanceContext);
1126
1174
  if (!context) {
1127
1175
  throw new Error("useAggBalanceContext must be used within an <AggProvider>");
1128
1176
  }
@@ -1130,37 +1178,41 @@ var useAggBalanceContext = () => {
1130
1178
  };
1131
1179
  var useAggBalanceState = useAggBalanceContext;
1132
1180
 
1133
- // src/deposit/constants.ts
1134
- var DEFAULT_SOLANA_RPC_ENDPOINT = "https://solana-rpc.publicnode.com";
1135
- var SVM_CHAIN_IDS = /* @__PURE__ */ new Set([792703809]);
1136
- var MULTI_CHAIN_SOLANA_WALLET_NAMES = /* @__PURE__ */ new Set(["Phantom"]);
1137
-
1138
- // src/deposit/use-svm-address.ts
1139
- var import_react3 = require("react");
1140
- var import_wallet_adapter_react = require("@solana/wallet-adapter-react");
1141
- function getPhantomProvider() {
1142
- var _a, _b;
1143
- if (typeof window === "undefined") return void 0;
1144
- const w = window;
1145
- return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
1181
+ // src/deposit/svm-connections.ts
1182
+ function resolveSvmRpcEndpoints(partnerUrl) {
1183
+ const seen = /* @__PURE__ */ new Set();
1184
+ const out = [];
1185
+ const candidates = partnerUrl ? [partnerUrl, ...DEFAULT_SOLANA_RPC_ENDPOINTS] : DEFAULT_SOLANA_RPC_ENDPOINTS;
1186
+ for (const url of candidates) {
1187
+ if (!seen.has(url)) {
1188
+ seen.add(url);
1189
+ out.push(url);
1190
+ }
1191
+ }
1192
+ return out;
1146
1193
  }
1147
- function useSvmAddress() {
1148
- var _a;
1149
- const { publicKey: adapterPublicKey } = (0, import_wallet_adapter_react.useWallet)();
1150
- const [phantomAddress, setPhantomAddress] = (0, import_react3.useState)(void 0);
1151
- (0, import_react3.useEffect)(() => {
1152
- var _a2;
1153
- const provider = getPhantomProvider();
1154
- if (!provider) return;
1155
- const existing = (_a2 = provider.publicKey) == null ? void 0 : _a2.toBase58();
1156
- if (existing) {
1157
- setPhantomAddress(existing);
1158
- return;
1194
+ function useSvmConnections(commitment) {
1195
+ const { solanaRpcUrl } = useAggUiConfig();
1196
+ return (0, import_react4.useMemo)(() => {
1197
+ const endpoints = resolveSvmRpcEndpoints(solanaRpcUrl);
1198
+ return endpoints.map((url) => new import_web3.Connection(url, commitment));
1199
+ }, [solanaRpcUrl, commitment]);
1200
+ }
1201
+ function withSvmFailover(connections, operation) {
1202
+ return __async(this, null, function* () {
1203
+ if (connections.length === 0) {
1204
+ throw new Error("No Solana RPC connections configured");
1159
1205
  }
1160
- provider.connect({ onlyIfTrusted: true }).then((res) => setPhantomAddress(res.publicKey.toString())).catch(() => {
1161
- });
1162
- }, []);
1163
- return (_a = adapterPublicKey == null ? void 0 : adapterPublicKey.toBase58()) != null ? _a : phantomAddress;
1206
+ let lastError;
1207
+ for (const connection of connections) {
1208
+ try {
1209
+ return yield operation(connection);
1210
+ } catch (err) {
1211
+ lastError = err;
1212
+ }
1213
+ }
1214
+ throw lastError instanceof Error ? lastError : new Error(typeof lastError === "string" ? lastError : "All Solana RPC endpoints failed");
1215
+ });
1164
1216
  }
1165
1217
 
1166
1218
  // src/deposit/use-wallet-token-balance.ts
@@ -1196,22 +1248,24 @@ function withTimeout(promise, timeoutMs) {
1196
1248
  );
1197
1249
  });
1198
1250
  }
1199
- function fetchSvmTokenBalance(rpcUrl, owner, mint) {
1251
+ function fetchSvmTokenBalance(connections, owner, mint) {
1200
1252
  return __async(this, null, function* () {
1201
- var _a;
1202
- const connection = new import_web3.Connection(rpcUrl);
1203
- const accounts = yield withTimeout(
1204
- connection.getTokenAccountsByOwner(owner, { mint }),
1205
- SVM_BALANCE_RPC_TIMEOUT_MS
1206
- );
1207
- if (accounts.value.length === 0) return 0;
1208
- const first = accounts.value[0];
1209
- if (!first) return 0;
1210
- const balance = yield withTimeout(
1211
- connection.getTokenAccountBalance(first.pubkey),
1212
- SVM_BALANCE_RPC_TIMEOUT_MS
1253
+ var _a, _b, _c;
1254
+ const accounts = yield withSvmFailover(
1255
+ connections,
1256
+ (connection) => withTimeout(
1257
+ connection.getParsedTokenAccountsByOwner(owner, { mint }),
1258
+ SVM_BALANCE_RPC_TIMEOUT_MS
1259
+ )
1213
1260
  );
1214
- return (_a = balance.value.uiAmount) != null ? _a : 0;
1261
+ let total = 0;
1262
+ for (const entry of accounts.value) {
1263
+ const uiAmount = (_c = (_b = (_a = entry.account.data.parsed) == null ? void 0 : _a.info) == null ? void 0 : _b.tokenAmount) == null ? void 0 : _c.uiAmount;
1264
+ if (typeof uiAmount === "number" && Number.isFinite(uiAmount)) {
1265
+ total += uiAmount;
1266
+ }
1267
+ }
1268
+ return total;
1215
1269
  });
1216
1270
  }
1217
1271
  function useWalletTokenBalance({
@@ -1222,8 +1276,6 @@ function useWalletTokenBalance({
1222
1276
  svmAddress
1223
1277
  }) {
1224
1278
  var _a;
1225
- const { solanaRpcUrl } = useAggUiConfig();
1226
- const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
1227
1279
  const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
1228
1280
  const { address: evmAddress } = (0, import_wagmi.useAccount)();
1229
1281
  const evmEnabled = isOpen && !isSvm && !!chainId && !!tokenAddress && !!evmAddress && decimals !== void 0;
@@ -1238,6 +1290,7 @@ function useWalletTokenBalance({
1238
1290
  const detectedSvmAddress = useSvmAddress();
1239
1291
  const resolvedSvmAddress = detectedSvmAddress != null ? detectedSvmAddress : svmAddress;
1240
1292
  const svmEnabled = isOpen && isSvm && !!resolvedSvmAddress && !!tokenAddress;
1293
+ const svmConnections = useSvmConnections();
1241
1294
  const svmQuery = (0, import_react_query.useQuery)({
1242
1295
  queryKey: ["svm-token-balance", resolvedSvmAddress != null ? resolvedSvmAddress : null, tokenAddress != null ? tokenAddress : null, isOpen],
1243
1296
  enabled: svmEnabled,
@@ -1247,9 +1300,9 @@ function useWalletTokenBalance({
1247
1300
  refetchOnReconnect: "always",
1248
1301
  queryFn: () => __async(null, null, function* () {
1249
1302
  if (!resolvedSvmAddress || !tokenAddress) return 0;
1250
- const owner = new import_web3.PublicKey(resolvedSvmAddress);
1251
- const mint = new import_web3.PublicKey(tokenAddress);
1252
- return yield fetchSvmTokenBalance(rpcEndpoint, owner, mint);
1303
+ const owner = new import_web32.PublicKey(resolvedSvmAddress);
1304
+ const mint = new import_web32.PublicKey(tokenAddress);
1305
+ return yield fetchSvmTokenBalance(svmConnections, owner, mint);
1253
1306
  })
1254
1307
  });
1255
1308
  if (isSvm) {
@@ -1265,11 +1318,11 @@ function useWalletTokenBalance({
1265
1318
  }
1266
1319
 
1267
1320
  // src/deposit/use-wallet-send-token.ts
1268
- var import_react4 = require("react");
1321
+ var import_react5 = require("react");
1269
1322
  var import_viem2 = require("viem");
1270
1323
  var import_wagmi2 = require("wagmi");
1271
1324
  var import_wallet_adapter_react2 = require("@solana/wallet-adapter-react");
1272
- var import_web32 = require("@solana/web3.js");
1325
+ var import_web33 = require("@solana/web3.js");
1273
1326
  function getPhantomProvider2() {
1274
1327
  var _a, _b;
1275
1328
  if (typeof window === "undefined") return void 0;
@@ -1289,13 +1342,11 @@ var ERC20_TRANSFER_ABI = [
1289
1342
  }
1290
1343
  ];
1291
1344
  function useWalletSendToken() {
1292
- const { solanaRpcUrl } = useAggUiConfig();
1293
- const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
1345
+ const svmConnections = useSvmConnections("confirmed");
1294
1346
  const { writeContractAsync } = (0, import_wagmi2.useWriteContract)();
1295
1347
  const { publicKey, sendTransaction } = (0, import_wallet_adapter_react2.useWallet)();
1296
- return (0, import_react4.useCallback)(
1348
+ return (0, import_react5.useCallback)(
1297
1349
  (params) => __async(null, null, function* () {
1298
- var _a, _b;
1299
1350
  const isSvm = SVM_CHAIN_IDS.has(params.chainId);
1300
1351
  if (!isSvm) {
1301
1352
  const tokenAddress = params.token.address;
@@ -1330,16 +1381,15 @@ function useWalletSendToken() {
1330
1381
  if (!ownerBase58) {
1331
1382
  throw new Error("No Solana wallet connected");
1332
1383
  }
1333
- const sendConnection = new import_web32.Connection(rpcEndpoint, "confirmed");
1334
- const TOKEN_PROGRAM_ID = new import_web32.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
1335
- const ASSOCIATED_TOKEN_PROGRAM_ID = new import_web32.PublicKey(
1384
+ const TOKEN_PROGRAM_ID = new import_web33.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
1385
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new import_web33.PublicKey(
1336
1386
  "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1337
1387
  );
1338
- const owner = new import_web32.PublicKey(ownerBase58);
1339
- const mint = new import_web32.PublicKey(params.token.address);
1340
- const destinationOwner = new import_web32.PublicKey(params.to);
1388
+ const owner = new import_web33.PublicKey(ownerBase58);
1389
+ const mint = new import_web33.PublicKey(params.token.address);
1390
+ const destinationOwner = new import_web33.PublicKey(params.to);
1341
1391
  const getAta = (walletPk, mintPk) => {
1342
- const [ata] = import_web32.PublicKey.findProgramAddressSync(
1392
+ const [ata] = import_web33.PublicKey.findProgramAddressSync(
1343
1393
  [walletPk.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()],
1344
1394
  ASSOCIATED_TOKEN_PROGRAM_ID
1345
1395
  );
@@ -1347,126 +1397,124 @@ function useWalletSendToken() {
1347
1397
  };
1348
1398
  const sourceAta = getAta(owner, mint);
1349
1399
  const destinationAta = getAta(destinationOwner, mint);
1350
- const tx = new import_web32.Transaction();
1351
- let destinationTokenAccountSigner = null;
1352
- const destinationOwnerInfo = yield sendConnection.getAccountInfo(destinationOwner);
1353
- const destinationInfo = yield sendConnection.getAccountInfo(destinationAta);
1354
- let destinationTokenAccount = destinationAta;
1355
- if (!destinationInfo) {
1356
- const rentExemptLamports = yield sendConnection.getMinimumBalanceForRentExemption(165);
1357
- const payerLamports = yield sendConnection.getBalance(owner, "confirmed");
1358
- const feeBufferLamports = 1e4;
1359
- const requiredLamports = rentExemptLamports + feeBufferLamports;
1360
- if (payerLamports < requiredLamports) {
1361
- const requiredSol = (requiredLamports / 1e9).toFixed(6);
1362
- const currentSol = (payerLamports / 1e9).toFixed(6);
1363
- throw new Error(
1364
- `This Solana deposit needs about ${requiredSol} SOL to create the destination token account, but the connected wallet only has ${currentSol} SOL available.`
1365
- );
1366
- }
1367
- const canCreateAta = (_b = (_a = destinationOwnerInfo == null ? void 0 : destinationOwnerInfo.owner) == null ? void 0 : _a.equals(import_web32.SystemProgram.programId)) != null ? _b : false;
1368
- if (canCreateAta) {
1369
- const createIx = new import_web32.TransactionInstruction({
1370
- programId: ASSOCIATED_TOKEN_PROGRAM_ID,
1371
- keys: [
1372
- { pubkey: owner, isSigner: true, isWritable: true },
1373
- { pubkey: destinationAta, isSigner: false, isWritable: true },
1374
- { pubkey: destinationOwner, isSigner: false, isWritable: false },
1375
- { pubkey: mint, isSigner: false, isWritable: false },
1376
- { pubkey: import_web32.SystemProgram.programId, isSigner: false, isWritable: false },
1377
- { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
1378
- ],
1379
- data: Buffer.alloc(0)
1380
- });
1381
- tx.add(createIx);
1382
- } else {
1383
- destinationTokenAccountSigner = import_web32.Keypair.generate();
1384
- destinationTokenAccount = destinationTokenAccountSigner.publicKey;
1385
- tx.add(
1386
- import_web32.SystemProgram.createAccount({
1387
- fromPubkey: owner,
1388
- newAccountPubkey: destinationTokenAccount,
1389
- lamports: rentExemptLamports,
1390
- space: 165,
1391
- programId: TOKEN_PROGRAM_ID
1392
- })
1393
- );
1394
- const initAccountData = Buffer.concat([
1395
- Buffer.from([18]),
1396
- // InitializeAccount3
1397
- destinationOwner.toBuffer()
1398
- ]);
1399
- tx.add(
1400
- new import_web32.TransactionInstruction({
1401
- programId: TOKEN_PROGRAM_ID,
1400
+ const signature = yield withSvmFailover(svmConnections, (sendConnection) => __async(null, null, function* () {
1401
+ var _a, _b;
1402
+ const tx = new import_web33.Transaction();
1403
+ let destinationTokenAccountSigner = null;
1404
+ const destinationOwnerInfo = yield sendConnection.getAccountInfo(destinationOwner);
1405
+ const destinationInfo = yield sendConnection.getAccountInfo(destinationAta);
1406
+ let destinationTokenAccount = destinationAta;
1407
+ if (!destinationInfo) {
1408
+ const rentExemptLamports = yield sendConnection.getMinimumBalanceForRentExemption(165);
1409
+ const payerLamports = yield sendConnection.getBalance(owner, "confirmed");
1410
+ const feeBufferLamports = 1e4;
1411
+ const requiredLamports = rentExemptLamports + feeBufferLamports;
1412
+ if (payerLamports < requiredLamports) {
1413
+ const requiredSol = (requiredLamports / 1e9).toFixed(6);
1414
+ const currentSol = (payerLamports / 1e9).toFixed(6);
1415
+ throw new Error(
1416
+ `This Solana deposit needs about ${requiredSol} SOL to create the destination token account, but the connected wallet only has ${currentSol} SOL available.`
1417
+ );
1418
+ }
1419
+ const canCreateAta = (_b = (_a = destinationOwnerInfo == null ? void 0 : destinationOwnerInfo.owner) == null ? void 0 : _a.equals(import_web33.SystemProgram.programId)) != null ? _b : false;
1420
+ if (canCreateAta) {
1421
+ const createIx = new import_web33.TransactionInstruction({
1422
+ programId: ASSOCIATED_TOKEN_PROGRAM_ID,
1402
1423
  keys: [
1403
- { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
1404
- { pubkey: mint, isSigner: false, isWritable: false }
1424
+ { pubkey: owner, isSigner: true, isWritable: true },
1425
+ { pubkey: destinationAta, isSigner: false, isWritable: true },
1426
+ { pubkey: destinationOwner, isSigner: false, isWritable: false },
1427
+ { pubkey: mint, isSigner: false, isWritable: false },
1428
+ { pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false },
1429
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
1405
1430
  ],
1406
- data: initAccountData
1407
- })
1408
- );
1431
+ data: Buffer.alloc(0)
1432
+ });
1433
+ tx.add(createIx);
1434
+ } else {
1435
+ destinationTokenAccountSigner = import_web33.Keypair.generate();
1436
+ destinationTokenAccount = destinationTokenAccountSigner.publicKey;
1437
+ tx.add(
1438
+ import_web33.SystemProgram.createAccount({
1439
+ fromPubkey: owner,
1440
+ newAccountPubkey: destinationTokenAccount,
1441
+ lamports: rentExemptLamports,
1442
+ space: 165,
1443
+ programId: TOKEN_PROGRAM_ID
1444
+ })
1445
+ );
1446
+ const initAccountData = Buffer.concat([
1447
+ Buffer.from([18]),
1448
+ // InitializeAccount3
1449
+ destinationOwner.toBuffer()
1450
+ ]);
1451
+ tx.add(
1452
+ new import_web33.TransactionInstruction({
1453
+ programId: TOKEN_PROGRAM_ID,
1454
+ keys: [
1455
+ { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
1456
+ { pubkey: mint, isSigner: false, isWritable: false }
1457
+ ],
1458
+ data: initAccountData
1459
+ })
1460
+ );
1461
+ }
1462
+ }
1463
+ let factor = BigInt(1);
1464
+ for (let i = 0; i < params.token.decimals; i += 1) {
1465
+ factor *= BigInt(10);
1466
+ }
1467
+ const amountRaw = BigInt(Math.trunc(Number(params.amount || "0") * Number(factor)));
1468
+ const data = new Uint8Array(10);
1469
+ data[0] = 12;
1470
+ let remaining = amountRaw;
1471
+ const mask = BigInt(255);
1472
+ for (let i = 0; i < 8; i += 1) {
1473
+ data[1 + i] = Number(remaining & mask);
1474
+ remaining >>= BigInt(8);
1475
+ }
1476
+ data[9] = params.token.decimals;
1477
+ const transferIx = new import_web33.TransactionInstruction({
1478
+ programId: TOKEN_PROGRAM_ID,
1479
+ keys: [
1480
+ { pubkey: sourceAta, isSigner: false, isWritable: true },
1481
+ { pubkey: mint, isSigner: false, isWritable: false },
1482
+ { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
1483
+ { pubkey: owner, isSigner: true, isWritable: false }
1484
+ ],
1485
+ data: Buffer.from(data)
1486
+ });
1487
+ tx.add(transferIx);
1488
+ tx.feePayer = owner;
1489
+ const { blockhash } = yield sendConnection.getLatestBlockhash("confirmed");
1490
+ tx.recentBlockhash = blockhash;
1491
+ if (destinationTokenAccountSigner) {
1492
+ tx.partialSign(destinationTokenAccountSigner);
1493
+ }
1494
+ if (publicKey && sendTransaction) {
1495
+ return yield sendTransaction(tx, sendConnection);
1496
+ }
1497
+ if (phantom) {
1498
+ const res = yield phantom.signAndSendTransaction(tx);
1499
+ return res.signature;
1409
1500
  }
1410
- }
1411
- let factor = BigInt(1);
1412
- for (let i = 0; i < params.token.decimals; i += 1) {
1413
- factor *= BigInt(10);
1414
- }
1415
- const amountRaw = BigInt(Math.trunc(Number(params.amount || "0") * Number(factor)));
1416
- const data = new Uint8Array(10);
1417
- data[0] = 12;
1418
- let remaining = amountRaw;
1419
- const mask = BigInt(255);
1420
- for (let i = 0; i < 8; i += 1) {
1421
- data[1 + i] = Number(remaining & mask);
1422
- remaining >>= BigInt(8);
1423
- }
1424
- data[9] = params.token.decimals;
1425
- const transferIx = new import_web32.TransactionInstruction({
1426
- programId: TOKEN_PROGRAM_ID,
1427
- keys: [
1428
- { pubkey: sourceAta, isSigner: false, isWritable: true },
1429
- { pubkey: mint, isSigner: false, isWritable: false },
1430
- { pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
1431
- { pubkey: owner, isSigner: true, isWritable: false }
1432
- ],
1433
- data: Buffer.from(data)
1434
- });
1435
- tx.add(transferIx);
1436
- tx.feePayer = owner;
1437
- const { blockhash } = yield sendConnection.getLatestBlockhash("confirmed");
1438
- tx.recentBlockhash = blockhash;
1439
- if (destinationTokenAccountSigner) {
1440
- tx.partialSign(destinationTokenAccountSigner);
1441
- }
1442
- let signature;
1443
- if (publicKey && sendTransaction) {
1444
- signature = yield sendTransaction(tx, sendConnection);
1445
- } else if (phantom) {
1446
- const res = yield phantom.signAndSendTransaction(tx);
1447
- signature = res.signature;
1448
- } else {
1449
1501
  throw new Error("No Solana signer available");
1450
- }
1502
+ }));
1451
1503
  return { txId: signature };
1452
1504
  }),
1453
- [publicKey, rpcEndpoint, sendTransaction, writeContractAsync]
1505
+ [publicKey, sendTransaction, svmConnections, writeContractAsync]
1454
1506
  );
1455
1507
  }
1456
1508
 
1457
1509
  // src/deposit/use-wallet-transaction-status.ts
1458
- var import_react5 = require("react");
1459
1510
  var import_react_query2 = require("@tanstack/react-query");
1460
1511
  var import_viem3 = require("viem");
1461
- var import_web33 = require("@solana/web3.js");
1462
1512
  var import_wagmi3 = require("wagmi");
1463
1513
  function useWalletTransactionStatus({
1464
1514
  chainId,
1465
1515
  txId
1466
1516
  }) {
1467
1517
  var _a;
1468
- const { solanaRpcUrl } = useAggUiConfig();
1469
- const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
1470
1518
  const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
1471
1519
  const evmHash = !isSvm && txId ? txId : void 0;
1472
1520
  const evmReceipt = (0, import_wagmi3.useWaitForTransactionReceipt)({
@@ -1477,14 +1525,17 @@ function useWalletTransactionStatus({
1477
1525
  refetchInterval: 2e3
1478
1526
  }
1479
1527
  });
1480
- const connection = (0, import_react5.useMemo)(() => new import_web33.Connection(rpcEndpoint, "confirmed"), [rpcEndpoint]);
1528
+ const svmConnections = useSvmConnections("confirmed");
1481
1529
  const svmQuery = (0, import_react_query2.useQuery)({
1482
1530
  queryKey: ["wallet-transaction-status", chainId != null ? chainId : null, txId != null ? txId : null],
1483
1531
  enabled: isSvm && !!txId,
1484
1532
  refetchInterval: (query) => query.state.data === "settled" || query.state.data === "error" ? false : 2e3,
1485
1533
  queryFn: () => __async(null, null, function* () {
1486
1534
  if (!txId) return "submitted";
1487
- const [status] = (yield connection.getSignatureStatuses([txId], { searchTransactionHistory: true })).value;
1535
+ const [status] = (yield withSvmFailover(
1536
+ svmConnections,
1537
+ (connection) => connection.getSignatureStatuses([txId], { searchTransactionHistory: true })
1538
+ )).value;
1488
1539
  if (!status) return "submitted";
1489
1540
  if (status.err) return "error";
1490
1541
  if (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized") {
@@ -1618,6 +1669,7 @@ var DEFAULT_WALLET_TOKEN_SYMBOL = "USDC";
1618
1669
  function useDepositFlow(options) {
1619
1670
  var _a, _b, _c;
1620
1671
  const { open, onOpenChange } = options;
1672
+ const client = useAggClient();
1621
1673
  const { user } = useAggAuthState();
1622
1674
  const { walletActions } = useAggUiConfig();
1623
1675
  const { totalBalance } = useAggBalanceState();
@@ -1757,6 +1809,8 @@ function useDepositFlow(options) {
1757
1809
  amount
1758
1810
  });
1759
1811
  setWalletTransaction({ chainId, txId });
1812
+ void client.recordDepositIntent({ chainId, txHash: txId }).catch(() => {
1813
+ });
1760
1814
  } catch (err) {
1761
1815
  setWalletTransaction(null);
1762
1816
  const normalizedError = normalizeWalletError(err, supportedChains);
@@ -1765,7 +1819,7 @@ function useDepositFlow(options) {
1765
1819
  throw err;
1766
1820
  }
1767
1821
  }),
1768
- [connectedChainId, sendToken, supportedChains, switchChainAsync]
1822
+ [client, connectedChainId, sendToken, supportedChains, switchChainAsync]
1769
1823
  );
1770
1824
  const handleGetCardQuotes = (0, import_react7.useCallback)(
1771
1825
  (params) => __async(null, null, function* () {