@agg-build/hooks 2.0.0 → 2.1.1
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/README.md +1 -1
- package/dist/{chunk-OBHXWQ6L.mjs → chunk-5P53A3NQ.mjs} +88 -27
- package/dist/{chunk-KXO3JOXF.mjs → chunk-AFZD3GIQ.mjs} +1 -1
- package/dist/{chunk-VLYLQSDD.mjs → chunk-FYEPQHKO.mjs} +42 -14
- package/dist/deposit.d.mts +5 -1
- package/dist/deposit.d.ts +5 -1
- package/dist/deposit.js +245 -181
- package/dist/deposit.mjs +176 -131
- package/dist/index.d.mts +50 -4
- package/dist/index.d.ts +50 -4
- package/dist/index.js +236 -141
- package/dist/index.mjs +48 -40
- package/dist/withdraw.d.mts +31 -2
- package/dist/withdraw.d.ts +31 -2
- package/dist/withdraw.js +106 -28
- package/dist/withdraw.mjs +4 -2
- package/package.json +2 -2
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
|
|
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/
|
|
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` /
|
|
@@ -353,6 +397,13 @@ var enUsLabels = {
|
|
|
353
397
|
categoryTabsAria: "Home page category tabs"
|
|
354
398
|
},
|
|
355
399
|
userProfile: {
|
|
400
|
+
balance: {
|
|
401
|
+
availableBalance: "Available Balance",
|
|
402
|
+
balanceByNetwork: "Balance by network",
|
|
403
|
+
paperModeNetwork: "Paper",
|
|
404
|
+
paperModeWarning: "Paper mode is enabled. These are simulated funds for paper trading.",
|
|
405
|
+
networkTooltipDescription: "Funds are stored across networks. We handle routing automatically, but keeping funds on the right network enables faster trades and lower fees. When depositing, you can choose your preferred network."
|
|
406
|
+
},
|
|
356
407
|
activity: {
|
|
357
408
|
depositType: "Deposit",
|
|
358
409
|
redeemType: "Claim",
|
|
@@ -684,6 +735,9 @@ var enUsLabels = {
|
|
|
684
735
|
buyingOutcome: (label) => `Buying ${label}`,
|
|
685
736
|
sellingOutcome: (label) => `Selling ${label}`,
|
|
686
737
|
findingBestRoute: "Finding the best route...",
|
|
738
|
+
findingBestOdds: "Finding best odds\u2026",
|
|
739
|
+
updatingRoute: "Updating route\u2026",
|
|
740
|
+
refreshingQuotes: "Refreshing quotes\u2026",
|
|
687
741
|
checkingBalance: "Checking balance",
|
|
688
742
|
submittingOrderProgress: "Submitting order...",
|
|
689
743
|
orderSubmittedProgress: (orderId) => `Order #${orderId.replace(/^#/, "")} submitted`,
|
|
@@ -1004,7 +1058,8 @@ var defaultAggUiConfig = {
|
|
|
1004
1058
|
enableNotifications: true
|
|
1005
1059
|
},
|
|
1006
1060
|
market: {
|
|
1007
|
-
arbitrageThreshold: 0
|
|
1061
|
+
arbitrageThreshold: 0,
|
|
1062
|
+
maxMidpointIdsPerRequest: 75
|
|
1008
1063
|
},
|
|
1009
1064
|
chart: {
|
|
1010
1065
|
defaultChartTimeRange: "1D",
|
|
@@ -1013,15 +1068,18 @@ var defaultAggUiConfig = {
|
|
|
1013
1068
|
}
|
|
1014
1069
|
},
|
|
1015
1070
|
formatting: defaultFormatters,
|
|
1016
|
-
search: defaultAggUiSearchConfig
|
|
1071
|
+
search: defaultAggUiSearchConfig,
|
|
1072
|
+
trading: {
|
|
1073
|
+
executionMode: "live"
|
|
1074
|
+
}
|
|
1017
1075
|
};
|
|
1018
1076
|
|
|
1019
1077
|
// src/core/providers/contexts.ts
|
|
1020
|
-
var AggClientContext = (0,
|
|
1021
|
-
var AggUiContext = (0,
|
|
1022
|
-
var AggLabelsContext = (0,
|
|
1023
|
-
var AggAuthContext = (0,
|
|
1024
|
-
var AggBalanceContext = (0,
|
|
1078
|
+
var AggClientContext = (0, import_react2.createContext)(null);
|
|
1079
|
+
var AggUiContext = (0, import_react2.createContext)(defaultAggUiConfig);
|
|
1080
|
+
var AggLabelsContext = (0, import_react2.createContext)(defaultAggUiConfig.general.labels);
|
|
1081
|
+
var AggAuthContext = (0, import_react2.createContext)(null);
|
|
1082
|
+
var AggBalanceContext = (0, import_react2.createContext)(null);
|
|
1025
1083
|
|
|
1026
1084
|
// src/execution/query-keys.ts
|
|
1027
1085
|
var executionKeys = {
|
|
@@ -1047,7 +1105,7 @@ var balanceQueryKeys = {
|
|
|
1047
1105
|
execution: () => executionKeys.balances(),
|
|
1048
1106
|
// Kept as an alias for backward compatibility with existing callers.
|
|
1049
1107
|
// The balance provider now uses the same canonical execution balances key.
|
|
1050
|
-
provider: () => executionKeys.balances(),
|
|
1108
|
+
provider: (mode) => executionKeys.balances(mode),
|
|
1051
1109
|
venue: (venuesKey) => ["venue-balances", venuesKey],
|
|
1052
1110
|
venuePrefix: () => ["venue-balances"]
|
|
1053
1111
|
};
|
|
@@ -1102,19 +1160,19 @@ var invalidateUserMoneyState = (queryClient, options) => {
|
|
|
1102
1160
|
};
|
|
1103
1161
|
|
|
1104
1162
|
// src/core/providers/hooks.ts
|
|
1105
|
-
var
|
|
1163
|
+
var import_react3 = require("react");
|
|
1106
1164
|
var useAggClient = () => {
|
|
1107
|
-
const client = (0,
|
|
1165
|
+
const client = (0, import_react3.useContext)(AggClientContext);
|
|
1108
1166
|
if (!client) {
|
|
1109
1167
|
throw new Error("useAggClient must be used within an <AggProvider>");
|
|
1110
1168
|
}
|
|
1111
1169
|
return client;
|
|
1112
1170
|
};
|
|
1113
1171
|
var useAggUiConfig = () => {
|
|
1114
|
-
return (0,
|
|
1172
|
+
return (0, import_react3.useContext)(AggUiContext);
|
|
1115
1173
|
};
|
|
1116
1174
|
var useAggAuthContext = () => {
|
|
1117
|
-
const context = (0,
|
|
1175
|
+
const context = (0, import_react3.useContext)(AggAuthContext);
|
|
1118
1176
|
if (!context) {
|
|
1119
1177
|
throw new Error("useAggAuthContext must be used within an <AggProvider>");
|
|
1120
1178
|
}
|
|
@@ -1122,7 +1180,7 @@ var useAggAuthContext = () => {
|
|
|
1122
1180
|
};
|
|
1123
1181
|
var useAggAuthState = useAggAuthContext;
|
|
1124
1182
|
var useAggBalanceContext = () => {
|
|
1125
|
-
const context = (0,
|
|
1183
|
+
const context = (0, import_react3.useContext)(AggBalanceContext);
|
|
1126
1184
|
if (!context) {
|
|
1127
1185
|
throw new Error("useAggBalanceContext must be used within an <AggProvider>");
|
|
1128
1186
|
}
|
|
@@ -1130,37 +1188,41 @@ var useAggBalanceContext = () => {
|
|
|
1130
1188
|
};
|
|
1131
1189
|
var useAggBalanceState = useAggBalanceContext;
|
|
1132
1190
|
|
|
1133
|
-
// src/deposit/
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
return (_b = (_a = w.phantom) == null ? void 0 : _a.solana) != null ? _b : w.solana;
|
|
1191
|
+
// src/deposit/svm-connections.ts
|
|
1192
|
+
function resolveSvmRpcEndpoints(partnerUrl) {
|
|
1193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1194
|
+
const out = [];
|
|
1195
|
+
const candidates = partnerUrl ? [partnerUrl, ...DEFAULT_SOLANA_RPC_ENDPOINTS] : DEFAULT_SOLANA_RPC_ENDPOINTS;
|
|
1196
|
+
for (const url of candidates) {
|
|
1197
|
+
if (!seen.has(url)) {
|
|
1198
|
+
seen.add(url);
|
|
1199
|
+
out.push(url);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return out;
|
|
1146
1203
|
}
|
|
1147
|
-
function
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
if (
|
|
1157
|
-
|
|
1158
|
-
return;
|
|
1204
|
+
function useSvmConnections(commitment) {
|
|
1205
|
+
const { solanaRpcUrl } = useAggUiConfig();
|
|
1206
|
+
return (0, import_react4.useMemo)(() => {
|
|
1207
|
+
const endpoints = resolveSvmRpcEndpoints(solanaRpcUrl);
|
|
1208
|
+
return endpoints.map((url) => new import_web3.Connection(url, commitment));
|
|
1209
|
+
}, [solanaRpcUrl, commitment]);
|
|
1210
|
+
}
|
|
1211
|
+
function withSvmFailover(connections, operation) {
|
|
1212
|
+
return __async(this, null, function* () {
|
|
1213
|
+
if (connections.length === 0) {
|
|
1214
|
+
throw new Error("No Solana RPC connections configured");
|
|
1159
1215
|
}
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1216
|
+
let lastError;
|
|
1217
|
+
for (const connection of connections) {
|
|
1218
|
+
try {
|
|
1219
|
+
return yield operation(connection);
|
|
1220
|
+
} catch (err) {
|
|
1221
|
+
lastError = err;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
throw lastError instanceof Error ? lastError : new Error(typeof lastError === "string" ? lastError : "All Solana RPC endpoints failed");
|
|
1225
|
+
});
|
|
1164
1226
|
}
|
|
1165
1227
|
|
|
1166
1228
|
// src/deposit/use-wallet-token-balance.ts
|
|
@@ -1196,22 +1258,24 @@ function withTimeout(promise, timeoutMs) {
|
|
|
1196
1258
|
);
|
|
1197
1259
|
});
|
|
1198
1260
|
}
|
|
1199
|
-
function fetchSvmTokenBalance(
|
|
1261
|
+
function fetchSvmTokenBalance(connections, owner, mint) {
|
|
1200
1262
|
return __async(this, null, function* () {
|
|
1201
|
-
var _a;
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
connection
|
|
1205
|
-
|
|
1263
|
+
var _a, _b, _c;
|
|
1264
|
+
const accounts = yield withSvmFailover(
|
|
1265
|
+
connections,
|
|
1266
|
+
(connection) => withTimeout(
|
|
1267
|
+
connection.getParsedTokenAccountsByOwner(owner, { mint }),
|
|
1268
|
+
SVM_BALANCE_RPC_TIMEOUT_MS
|
|
1269
|
+
)
|
|
1206
1270
|
);
|
|
1207
|
-
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
return
|
|
1271
|
+
let total = 0;
|
|
1272
|
+
for (const entry of accounts.value) {
|
|
1273
|
+
const uiAmount = (_c = (_b = (_a = entry.account.data.parsed) == null ? void 0 : _a.info) == null ? void 0 : _b.tokenAmount) == null ? void 0 : _c.uiAmount;
|
|
1274
|
+
if (typeof uiAmount === "number" && Number.isFinite(uiAmount)) {
|
|
1275
|
+
total += uiAmount;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return total;
|
|
1215
1279
|
});
|
|
1216
1280
|
}
|
|
1217
1281
|
function useWalletTokenBalance({
|
|
@@ -1222,8 +1286,6 @@ function useWalletTokenBalance({
|
|
|
1222
1286
|
svmAddress
|
|
1223
1287
|
}) {
|
|
1224
1288
|
var _a;
|
|
1225
|
-
const { solanaRpcUrl } = useAggUiConfig();
|
|
1226
|
-
const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
|
|
1227
1289
|
const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
|
|
1228
1290
|
const { address: evmAddress } = (0, import_wagmi.useAccount)();
|
|
1229
1291
|
const evmEnabled = isOpen && !isSvm && !!chainId && !!tokenAddress && !!evmAddress && decimals !== void 0;
|
|
@@ -1238,6 +1300,7 @@ function useWalletTokenBalance({
|
|
|
1238
1300
|
const detectedSvmAddress = useSvmAddress();
|
|
1239
1301
|
const resolvedSvmAddress = detectedSvmAddress != null ? detectedSvmAddress : svmAddress;
|
|
1240
1302
|
const svmEnabled = isOpen && isSvm && !!resolvedSvmAddress && !!tokenAddress;
|
|
1303
|
+
const svmConnections = useSvmConnections();
|
|
1241
1304
|
const svmQuery = (0, import_react_query.useQuery)({
|
|
1242
1305
|
queryKey: ["svm-token-balance", resolvedSvmAddress != null ? resolvedSvmAddress : null, tokenAddress != null ? tokenAddress : null, isOpen],
|
|
1243
1306
|
enabled: svmEnabled,
|
|
@@ -1247,9 +1310,9 @@ function useWalletTokenBalance({
|
|
|
1247
1310
|
refetchOnReconnect: "always",
|
|
1248
1311
|
queryFn: () => __async(null, null, function* () {
|
|
1249
1312
|
if (!resolvedSvmAddress || !tokenAddress) return 0;
|
|
1250
|
-
const owner = new
|
|
1251
|
-
const mint = new
|
|
1252
|
-
return yield fetchSvmTokenBalance(
|
|
1313
|
+
const owner = new import_web32.PublicKey(resolvedSvmAddress);
|
|
1314
|
+
const mint = new import_web32.PublicKey(tokenAddress);
|
|
1315
|
+
return yield fetchSvmTokenBalance(svmConnections, owner, mint);
|
|
1253
1316
|
})
|
|
1254
1317
|
});
|
|
1255
1318
|
if (isSvm) {
|
|
@@ -1265,11 +1328,11 @@ function useWalletTokenBalance({
|
|
|
1265
1328
|
}
|
|
1266
1329
|
|
|
1267
1330
|
// src/deposit/use-wallet-send-token.ts
|
|
1268
|
-
var
|
|
1331
|
+
var import_react5 = require("react");
|
|
1269
1332
|
var import_viem2 = require("viem");
|
|
1270
1333
|
var import_wagmi2 = require("wagmi");
|
|
1271
1334
|
var import_wallet_adapter_react2 = require("@solana/wallet-adapter-react");
|
|
1272
|
-
var
|
|
1335
|
+
var import_web33 = require("@solana/web3.js");
|
|
1273
1336
|
function getPhantomProvider2() {
|
|
1274
1337
|
var _a, _b;
|
|
1275
1338
|
if (typeof window === "undefined") return void 0;
|
|
@@ -1289,13 +1352,11 @@ var ERC20_TRANSFER_ABI = [
|
|
|
1289
1352
|
}
|
|
1290
1353
|
];
|
|
1291
1354
|
function useWalletSendToken() {
|
|
1292
|
-
const
|
|
1293
|
-
const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
|
|
1355
|
+
const svmConnections = useSvmConnections("confirmed");
|
|
1294
1356
|
const { writeContractAsync } = (0, import_wagmi2.useWriteContract)();
|
|
1295
1357
|
const { publicKey, sendTransaction } = (0, import_wallet_adapter_react2.useWallet)();
|
|
1296
|
-
return (0,
|
|
1358
|
+
return (0, import_react5.useCallback)(
|
|
1297
1359
|
(params) => __async(null, null, function* () {
|
|
1298
|
-
var _a, _b;
|
|
1299
1360
|
const isSvm = SVM_CHAIN_IDS.has(params.chainId);
|
|
1300
1361
|
if (!isSvm) {
|
|
1301
1362
|
const tokenAddress = params.token.address;
|
|
@@ -1330,16 +1391,15 @@ function useWalletSendToken() {
|
|
|
1330
1391
|
if (!ownerBase58) {
|
|
1331
1392
|
throw new Error("No Solana wallet connected");
|
|
1332
1393
|
}
|
|
1333
|
-
const
|
|
1334
|
-
const
|
|
1335
|
-
const ASSOCIATED_TOKEN_PROGRAM_ID = new import_web32.PublicKey(
|
|
1394
|
+
const TOKEN_PROGRAM_ID = new import_web33.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
|
|
1395
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new import_web33.PublicKey(
|
|
1336
1396
|
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
1337
1397
|
);
|
|
1338
|
-
const owner = new
|
|
1339
|
-
const mint = new
|
|
1340
|
-
const destinationOwner = new
|
|
1398
|
+
const owner = new import_web33.PublicKey(ownerBase58);
|
|
1399
|
+
const mint = new import_web33.PublicKey(params.token.address);
|
|
1400
|
+
const destinationOwner = new import_web33.PublicKey(params.to);
|
|
1341
1401
|
const getAta = (walletPk, mintPk) => {
|
|
1342
|
-
const [ata] =
|
|
1402
|
+
const [ata] = import_web33.PublicKey.findProgramAddressSync(
|
|
1343
1403
|
[walletPk.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()],
|
|
1344
1404
|
ASSOCIATED_TOKEN_PROGRAM_ID
|
|
1345
1405
|
);
|
|
@@ -1347,126 +1407,124 @@ function useWalletSendToken() {
|
|
|
1347
1407
|
};
|
|
1348
1408
|
const sourceAta = getAta(owner, mint);
|
|
1349
1409
|
const destinationAta = getAta(destinationOwner, mint);
|
|
1350
|
-
const
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
const
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
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,
|
|
1410
|
+
const signature = yield withSvmFailover(svmConnections, (sendConnection) => __async(null, null, function* () {
|
|
1411
|
+
var _a, _b;
|
|
1412
|
+
const tx = new import_web33.Transaction();
|
|
1413
|
+
let destinationTokenAccountSigner = null;
|
|
1414
|
+
const destinationOwnerInfo = yield sendConnection.getAccountInfo(destinationOwner);
|
|
1415
|
+
const destinationInfo = yield sendConnection.getAccountInfo(destinationAta);
|
|
1416
|
+
let destinationTokenAccount = destinationAta;
|
|
1417
|
+
if (!destinationInfo) {
|
|
1418
|
+
const rentExemptLamports = yield sendConnection.getMinimumBalanceForRentExemption(165);
|
|
1419
|
+
const payerLamports = yield sendConnection.getBalance(owner, "confirmed");
|
|
1420
|
+
const feeBufferLamports = 1e4;
|
|
1421
|
+
const requiredLamports = rentExemptLamports + feeBufferLamports;
|
|
1422
|
+
if (payerLamports < requiredLamports) {
|
|
1423
|
+
const requiredSol = (requiredLamports / 1e9).toFixed(6);
|
|
1424
|
+
const currentSol = (payerLamports / 1e9).toFixed(6);
|
|
1425
|
+
throw new Error(
|
|
1426
|
+
`This Solana deposit needs about ${requiredSol} SOL to create the destination token account, but the connected wallet only has ${currentSol} SOL available.`
|
|
1427
|
+
);
|
|
1428
|
+
}
|
|
1429
|
+
const canCreateAta = (_b = (_a = destinationOwnerInfo == null ? void 0 : destinationOwnerInfo.owner) == null ? void 0 : _a.equals(import_web33.SystemProgram.programId)) != null ? _b : false;
|
|
1430
|
+
if (canCreateAta) {
|
|
1431
|
+
const createIx = new import_web33.TransactionInstruction({
|
|
1432
|
+
programId: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
1402
1433
|
keys: [
|
|
1403
|
-
{ pubkey:
|
|
1404
|
-
{ pubkey:
|
|
1434
|
+
{ pubkey: owner, isSigner: true, isWritable: true },
|
|
1435
|
+
{ pubkey: destinationAta, isSigner: false, isWritable: true },
|
|
1436
|
+
{ pubkey: destinationOwner, isSigner: false, isWritable: false },
|
|
1437
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
1438
|
+
{ pubkey: import_web33.SystemProgram.programId, isSigner: false, isWritable: false },
|
|
1439
|
+
{ pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
|
|
1405
1440
|
],
|
|
1406
|
-
data:
|
|
1407
|
-
})
|
|
1408
|
-
|
|
1441
|
+
data: Buffer.alloc(0)
|
|
1442
|
+
});
|
|
1443
|
+
tx.add(createIx);
|
|
1444
|
+
} else {
|
|
1445
|
+
destinationTokenAccountSigner = import_web33.Keypair.generate();
|
|
1446
|
+
destinationTokenAccount = destinationTokenAccountSigner.publicKey;
|
|
1447
|
+
tx.add(
|
|
1448
|
+
import_web33.SystemProgram.createAccount({
|
|
1449
|
+
fromPubkey: owner,
|
|
1450
|
+
newAccountPubkey: destinationTokenAccount,
|
|
1451
|
+
lamports: rentExemptLamports,
|
|
1452
|
+
space: 165,
|
|
1453
|
+
programId: TOKEN_PROGRAM_ID
|
|
1454
|
+
})
|
|
1455
|
+
);
|
|
1456
|
+
const initAccountData = Buffer.concat([
|
|
1457
|
+
Buffer.from([18]),
|
|
1458
|
+
// InitializeAccount3
|
|
1459
|
+
destinationOwner.toBuffer()
|
|
1460
|
+
]);
|
|
1461
|
+
tx.add(
|
|
1462
|
+
new import_web33.TransactionInstruction({
|
|
1463
|
+
programId: TOKEN_PROGRAM_ID,
|
|
1464
|
+
keys: [
|
|
1465
|
+
{ pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
|
|
1466
|
+
{ pubkey: mint, isSigner: false, isWritable: false }
|
|
1467
|
+
],
|
|
1468
|
+
data: initAccountData
|
|
1469
|
+
})
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
let factor = BigInt(1);
|
|
1474
|
+
for (let i = 0; i < params.token.decimals; i += 1) {
|
|
1475
|
+
factor *= BigInt(10);
|
|
1476
|
+
}
|
|
1477
|
+
const amountRaw = BigInt(Math.trunc(Number(params.amount || "0") * Number(factor)));
|
|
1478
|
+
const data = new Uint8Array(10);
|
|
1479
|
+
data[0] = 12;
|
|
1480
|
+
let remaining = amountRaw;
|
|
1481
|
+
const mask = BigInt(255);
|
|
1482
|
+
for (let i = 0; i < 8; i += 1) {
|
|
1483
|
+
data[1 + i] = Number(remaining & mask);
|
|
1484
|
+
remaining >>= BigInt(8);
|
|
1485
|
+
}
|
|
1486
|
+
data[9] = params.token.decimals;
|
|
1487
|
+
const transferIx = new import_web33.TransactionInstruction({
|
|
1488
|
+
programId: TOKEN_PROGRAM_ID,
|
|
1489
|
+
keys: [
|
|
1490
|
+
{ pubkey: sourceAta, isSigner: false, isWritable: true },
|
|
1491
|
+
{ pubkey: mint, isSigner: false, isWritable: false },
|
|
1492
|
+
{ pubkey: destinationTokenAccount, isSigner: false, isWritable: true },
|
|
1493
|
+
{ pubkey: owner, isSigner: true, isWritable: false }
|
|
1494
|
+
],
|
|
1495
|
+
data: Buffer.from(data)
|
|
1496
|
+
});
|
|
1497
|
+
tx.add(transferIx);
|
|
1498
|
+
tx.feePayer = owner;
|
|
1499
|
+
const { blockhash } = yield sendConnection.getLatestBlockhash("confirmed");
|
|
1500
|
+
tx.recentBlockhash = blockhash;
|
|
1501
|
+
if (destinationTokenAccountSigner) {
|
|
1502
|
+
tx.partialSign(destinationTokenAccountSigner);
|
|
1503
|
+
}
|
|
1504
|
+
if (publicKey && sendTransaction) {
|
|
1505
|
+
return yield sendTransaction(tx, sendConnection);
|
|
1506
|
+
}
|
|
1507
|
+
if (phantom) {
|
|
1508
|
+
const res = yield phantom.signAndSendTransaction(tx);
|
|
1509
|
+
return res.signature;
|
|
1409
1510
|
}
|
|
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
1511
|
throw new Error("No Solana signer available");
|
|
1450
|
-
}
|
|
1512
|
+
}));
|
|
1451
1513
|
return { txId: signature };
|
|
1452
1514
|
}),
|
|
1453
|
-
[publicKey,
|
|
1515
|
+
[publicKey, sendTransaction, svmConnections, writeContractAsync]
|
|
1454
1516
|
);
|
|
1455
1517
|
}
|
|
1456
1518
|
|
|
1457
1519
|
// src/deposit/use-wallet-transaction-status.ts
|
|
1458
|
-
var import_react5 = require("react");
|
|
1459
1520
|
var import_react_query2 = require("@tanstack/react-query");
|
|
1460
1521
|
var import_viem3 = require("viem");
|
|
1461
|
-
var import_web33 = require("@solana/web3.js");
|
|
1462
1522
|
var import_wagmi3 = require("wagmi");
|
|
1463
1523
|
function useWalletTransactionStatus({
|
|
1464
1524
|
chainId,
|
|
1465
1525
|
txId
|
|
1466
1526
|
}) {
|
|
1467
1527
|
var _a;
|
|
1468
|
-
const { solanaRpcUrl } = useAggUiConfig();
|
|
1469
|
-
const rpcEndpoint = solanaRpcUrl != null ? solanaRpcUrl : DEFAULT_SOLANA_RPC_ENDPOINT;
|
|
1470
1528
|
const isSvm = chainId !== void 0 && SVM_CHAIN_IDS.has(chainId);
|
|
1471
1529
|
const evmHash = !isSvm && txId ? txId : void 0;
|
|
1472
1530
|
const evmReceipt = (0, import_wagmi3.useWaitForTransactionReceipt)({
|
|
@@ -1477,14 +1535,17 @@ function useWalletTransactionStatus({
|
|
|
1477
1535
|
refetchInterval: 2e3
|
|
1478
1536
|
}
|
|
1479
1537
|
});
|
|
1480
|
-
const
|
|
1538
|
+
const svmConnections = useSvmConnections("confirmed");
|
|
1481
1539
|
const svmQuery = (0, import_react_query2.useQuery)({
|
|
1482
1540
|
queryKey: ["wallet-transaction-status", chainId != null ? chainId : null, txId != null ? txId : null],
|
|
1483
1541
|
enabled: isSvm && !!txId,
|
|
1484
1542
|
refetchInterval: (query) => query.state.data === "settled" || query.state.data === "error" ? false : 2e3,
|
|
1485
1543
|
queryFn: () => __async(null, null, function* () {
|
|
1486
1544
|
if (!txId) return "submitted";
|
|
1487
|
-
const [status] = (yield
|
|
1545
|
+
const [status] = (yield withSvmFailover(
|
|
1546
|
+
svmConnections,
|
|
1547
|
+
(connection) => connection.getSignatureStatuses([txId], { searchTransactionHistory: true })
|
|
1548
|
+
)).value;
|
|
1488
1549
|
if (!status) return "submitted";
|
|
1489
1550
|
if (status.err) return "error";
|
|
1490
1551
|
if (status.confirmationStatus === "confirmed" || status.confirmationStatus === "finalized") {
|
|
@@ -1618,6 +1679,7 @@ var DEFAULT_WALLET_TOKEN_SYMBOL = "USDC";
|
|
|
1618
1679
|
function useDepositFlow(options) {
|
|
1619
1680
|
var _a, _b, _c;
|
|
1620
1681
|
const { open, onOpenChange } = options;
|
|
1682
|
+
const client = useAggClient();
|
|
1621
1683
|
const { user } = useAggAuthState();
|
|
1622
1684
|
const { walletActions } = useAggUiConfig();
|
|
1623
1685
|
const { totalBalance } = useAggBalanceState();
|
|
@@ -1757,6 +1819,8 @@ function useDepositFlow(options) {
|
|
|
1757
1819
|
amount
|
|
1758
1820
|
});
|
|
1759
1821
|
setWalletTransaction({ chainId, txId });
|
|
1822
|
+
void client.recordDepositIntent({ chainId, txHash: txId }).catch(() => {
|
|
1823
|
+
});
|
|
1760
1824
|
} catch (err) {
|
|
1761
1825
|
setWalletTransaction(null);
|
|
1762
1826
|
const normalizedError = normalizeWalletError(err, supportedChains);
|
|
@@ -1765,7 +1829,7 @@ function useDepositFlow(options) {
|
|
|
1765
1829
|
throw err;
|
|
1766
1830
|
}
|
|
1767
1831
|
}),
|
|
1768
|
-
[connectedChainId, sendToken, supportedChains, switchChainAsync]
|
|
1832
|
+
[client, connectedChainId, sendToken, supportedChains, switchChainAsync]
|
|
1769
1833
|
);
|
|
1770
1834
|
const handleGetCardQuotes = (0, import_react7.useCallback)(
|
|
1771
1835
|
(params) => __async(null, null, function* () {
|