@sodax/dapp-kit 2.0.0-rc.17 → 2.0.0-rc.19
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 +12 -3
- package/dist/index.d.ts +440 -46
- package/dist/index.mjs +471 -46
- package/package.json +2 -2
- package/src/hooks/_mutationContract.test.ts +8 -1
- package/src/hooks/backend/index.ts +1 -5
- package/src/hooks/bitcoin/index.ts +1 -0
- package/src/hooks/bitcoin/useBitcoinTradingSetup.ts +45 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/partner/index.ts +4 -0
- package/src/hooks/partner/useFeeClaimWithdraw.ts +88 -0
- package/src/hooks/partner/useGetIntentDetails.ts +39 -0
- package/src/hooks/partner/useGetUserIntent.ts +35 -0
- package/src/hooks/partner/usePartnerCancelIntent.ts +52 -0
- package/src/hooks/swapsApi/index.ts +41 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.test.ts +24 -0
- package/src/hooks/swapsApi/isTerminalSwapIntentStatus.ts +11 -0
- package/src/hooks/swapsApi/useSwapsApiAllowance.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiApprove.ts +42 -0
- package/src/hooks/swapsApi/useSwapsApiCancelIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiDeadline.ts +36 -0
- package/src/hooks/swapsApi/useSwapsApiEstimateGas.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiFilledIntent.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntent.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentExtraData.ts +41 -0
- package/src/hooks/swapsApi/useSwapsApiIntentHash.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiIntentPacket.ts +43 -0
- package/src/hooks/swapsApi/useSwapsApiPartnerFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiQuote.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiSolverFee.ts +40 -0
- package/src/hooks/swapsApi/useSwapsApiStatus.ts +45 -0
- package/src/hooks/swapsApi/useSwapsApiSubmitIntent.ts +43 -0
- package/src/hooks/{backend/useBackendSubmitSwapTx.ts → swapsApi/useSwapsApiSubmitTx.ts} +16 -17
- package/src/hooks/swapsApi/useSwapsApiSubmitTxStatus.ts +55 -0
- package/src/hooks/swapsApi/useSwapsApiTokens.ts +34 -0
- package/src/hooks/swapsApi/useSwapsApiTokensByChain.ts +40 -0
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +0 -59
package/dist/index.mjs
CHANGED
|
@@ -507,6 +507,19 @@ function useTradingWalletBalance({
|
|
|
507
507
|
...queryOptions
|
|
508
508
|
});
|
|
509
509
|
}
|
|
510
|
+
var INERT = { wallet: void 0, tradingBalance: void 0 };
|
|
511
|
+
function useBitcoinTradingSetup({
|
|
512
|
+
chainKey,
|
|
513
|
+
walletProvider,
|
|
514
|
+
address
|
|
515
|
+
}) {
|
|
516
|
+
const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
|
|
517
|
+
const wallet = isBitcoin ? walletProvider : void 0;
|
|
518
|
+
const { tradingAddress } = useTradingWallet(isBitcoin ? address : void 0);
|
|
519
|
+
const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
|
|
520
|
+
if (!isBitcoin) return INERT;
|
|
521
|
+
return { wallet, tradingBalance };
|
|
522
|
+
}
|
|
510
523
|
function useExpiredUtxos({
|
|
511
524
|
params,
|
|
512
525
|
queryOptions
|
|
@@ -1075,51 +1088,6 @@ var useBackendUserIntents = ({
|
|
|
1075
1088
|
...queryOptions
|
|
1076
1089
|
});
|
|
1077
1090
|
};
|
|
1078
|
-
|
|
1079
|
-
// src/hooks/backend/useBackendSubmitSwapTx.ts
|
|
1080
|
-
var useBackendSubmitSwapTx = ({
|
|
1081
|
-
mutationOptions
|
|
1082
|
-
} = {}) => {
|
|
1083
|
-
const { sodax } = useSodaxContext();
|
|
1084
|
-
return useSafeMutation({
|
|
1085
|
-
mutationKey: ["backend", "submitSwapTx"],
|
|
1086
|
-
retry: 3,
|
|
1087
|
-
...mutationOptions,
|
|
1088
|
-
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.backendApi.submitSwapTx(request, apiConfig))
|
|
1089
|
-
});
|
|
1090
|
-
};
|
|
1091
|
-
var useBackendSubmitSwapTxStatus = ({
|
|
1092
|
-
params,
|
|
1093
|
-
queryOptions
|
|
1094
|
-
} = {}) => {
|
|
1095
|
-
const { sodax } = useSodaxContext();
|
|
1096
|
-
const txHash = params?.txHash;
|
|
1097
|
-
const srcChainKey = params?.srcChainKey;
|
|
1098
|
-
const apiConfig = params?.apiConfig;
|
|
1099
|
-
return useQuery({
|
|
1100
|
-
queryKey: ["backend", "submitSwapTx", "status", txHash, srcChainKey],
|
|
1101
|
-
queryFn: async () => {
|
|
1102
|
-
if (!txHash) return void 0;
|
|
1103
|
-
return unwrapResult(
|
|
1104
|
-
await sodax.backendApi.getSubmitSwapTxStatus(
|
|
1105
|
-
{
|
|
1106
|
-
txHash,
|
|
1107
|
-
srcChainKey
|
|
1108
|
-
},
|
|
1109
|
-
apiConfig
|
|
1110
|
-
)
|
|
1111
|
-
);
|
|
1112
|
-
},
|
|
1113
|
-
enabled: !!txHash && txHash.length > 0,
|
|
1114
|
-
retry: 3,
|
|
1115
|
-
refetchInterval: (query) => {
|
|
1116
|
-
const status = query.state.data?.data?.status;
|
|
1117
|
-
if (status === "executed" || status === "failed") return false;
|
|
1118
|
-
return 1e3;
|
|
1119
|
-
},
|
|
1120
|
-
...queryOptions
|
|
1121
|
-
});
|
|
1122
|
-
};
|
|
1123
1091
|
var useBackendOrderbook = ({
|
|
1124
1092
|
params,
|
|
1125
1093
|
queryOptions
|
|
@@ -1261,6 +1229,362 @@ var useBackendAllMoneyMarketBorrowers = ({
|
|
|
1261
1229
|
...queryOptions
|
|
1262
1230
|
});
|
|
1263
1231
|
};
|
|
1232
|
+
var useSwapsApiTokens = ({
|
|
1233
|
+
params,
|
|
1234
|
+
queryOptions
|
|
1235
|
+
} = {}) => {
|
|
1236
|
+
const { sodax } = useSodaxContext();
|
|
1237
|
+
const apiConfig = params?.apiConfig;
|
|
1238
|
+
return useQuery({
|
|
1239
|
+
queryKey: ["swapsApi", "tokens"],
|
|
1240
|
+
queryFn: async () => unwrapResult(await sodax.api.swaps.getTokens(apiConfig)),
|
|
1241
|
+
retry: 3,
|
|
1242
|
+
...queryOptions
|
|
1243
|
+
});
|
|
1244
|
+
};
|
|
1245
|
+
var useSwapsApiTokensByChain = ({
|
|
1246
|
+
params,
|
|
1247
|
+
queryOptions
|
|
1248
|
+
} = {}) => {
|
|
1249
|
+
const { sodax } = useSodaxContext();
|
|
1250
|
+
const chainKey = params?.chainKey;
|
|
1251
|
+
const apiConfig = params?.apiConfig;
|
|
1252
|
+
return useQuery({
|
|
1253
|
+
queryKey: ["swapsApi", "tokens", chainKey],
|
|
1254
|
+
queryFn: async () => {
|
|
1255
|
+
if (!chainKey) return void 0;
|
|
1256
|
+
return unwrapResult(await sodax.api.swaps.getTokensByChain(chainKey, apiConfig));
|
|
1257
|
+
},
|
|
1258
|
+
enabled: !!chainKey && chainKey.length > 0,
|
|
1259
|
+
retry: 3,
|
|
1260
|
+
...queryOptions
|
|
1261
|
+
});
|
|
1262
|
+
};
|
|
1263
|
+
var useSwapsApiQuote = ({
|
|
1264
|
+
params,
|
|
1265
|
+
queryOptions
|
|
1266
|
+
} = {}) => {
|
|
1267
|
+
const { sodax } = useSodaxContext();
|
|
1268
|
+
const body = params?.body;
|
|
1269
|
+
const query = params?.query;
|
|
1270
|
+
const apiConfig = params?.apiConfig;
|
|
1271
|
+
return useQuery({
|
|
1272
|
+
// Hash the whole request body so every quote input — including partnerFee and the other
|
|
1273
|
+
// SwapExtrasV2 fields — is a cache dimension; a partnerFee change alters the quote and must
|
|
1274
|
+
// miss the cache. QuoteRequestV2 is bigint-free (compile-time guaranteed), so React Query's
|
|
1275
|
+
// default key hashing handles the object directly.
|
|
1276
|
+
queryKey: ["swapsApi", "quote", body, query?.includeTxData ?? false],
|
|
1277
|
+
queryFn: async () => {
|
|
1278
|
+
if (!body) return void 0;
|
|
1279
|
+
return unwrapResult(await sodax.api.swaps.getQuote(body, query, apiConfig));
|
|
1280
|
+
},
|
|
1281
|
+
enabled: !!body,
|
|
1282
|
+
retry: 3,
|
|
1283
|
+
...queryOptions
|
|
1284
|
+
});
|
|
1285
|
+
};
|
|
1286
|
+
var useSwapsApiDeadline = ({
|
|
1287
|
+
params,
|
|
1288
|
+
queryOptions
|
|
1289
|
+
} = {}) => {
|
|
1290
|
+
const { sodax } = useSodaxContext();
|
|
1291
|
+
const query = params?.query;
|
|
1292
|
+
const apiConfig = params?.apiConfig;
|
|
1293
|
+
return useQuery({
|
|
1294
|
+
queryKey: ["swapsApi", "deadline", query?.offsetSeconds ?? null],
|
|
1295
|
+
queryFn: async () => unwrapResult(await sodax.api.swaps.getDeadline(query, apiConfig)),
|
|
1296
|
+
retry: 3,
|
|
1297
|
+
...queryOptions
|
|
1298
|
+
});
|
|
1299
|
+
};
|
|
1300
|
+
var useSwapsApiAllowance = ({
|
|
1301
|
+
params,
|
|
1302
|
+
queryOptions
|
|
1303
|
+
} = {}) => {
|
|
1304
|
+
const { sodax } = useSodaxContext();
|
|
1305
|
+
const body = params?.body;
|
|
1306
|
+
const apiConfig = params?.apiConfig;
|
|
1307
|
+
return useQuery({
|
|
1308
|
+
queryKey: ["swapsApi", "allowance", body?.srcChainKey, body?.inputToken, body?.inputAmount, body?.srcAddress],
|
|
1309
|
+
queryFn: async () => {
|
|
1310
|
+
if (!body) return void 0;
|
|
1311
|
+
return unwrapResult(await sodax.api.swaps.checkAllowance(body, apiConfig));
|
|
1312
|
+
},
|
|
1313
|
+
enabled: !!body,
|
|
1314
|
+
retry: 3,
|
|
1315
|
+
...queryOptions
|
|
1316
|
+
});
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// src/hooks/swapsApi/useSwapsApiApprove.ts
|
|
1320
|
+
var useSwapsApiApprove = ({
|
|
1321
|
+
mutationOptions
|
|
1322
|
+
} = {}) => {
|
|
1323
|
+
const { sodax } = useSodaxContext();
|
|
1324
|
+
return useSafeMutation({
|
|
1325
|
+
mutationKey: ["swapsApi", "approve"],
|
|
1326
|
+
retry: 3,
|
|
1327
|
+
...mutationOptions,
|
|
1328
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.approve(body, apiConfig))
|
|
1329
|
+
});
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
// src/hooks/swapsApi/useSwapsApiCreateIntent.ts
|
|
1333
|
+
var useSwapsApiCreateIntent = ({
|
|
1334
|
+
mutationOptions
|
|
1335
|
+
} = {}) => {
|
|
1336
|
+
const { sodax } = useSodaxContext();
|
|
1337
|
+
return useSafeMutation({
|
|
1338
|
+
mutationKey: ["swapsApi", "createIntent"],
|
|
1339
|
+
retry: 3,
|
|
1340
|
+
...mutationOptions,
|
|
1341
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createIntent(body, apiConfig))
|
|
1342
|
+
});
|
|
1343
|
+
};
|
|
1344
|
+
|
|
1345
|
+
// src/hooks/swapsApi/useSwapsApiSubmitIntent.ts
|
|
1346
|
+
var useSwapsApiSubmitIntent = ({
|
|
1347
|
+
mutationOptions
|
|
1348
|
+
} = {}) => {
|
|
1349
|
+
const { sodax } = useSodaxContext();
|
|
1350
|
+
return useSafeMutation({
|
|
1351
|
+
mutationKey: ["swapsApi", "submitIntent"],
|
|
1352
|
+
retry: false,
|
|
1353
|
+
...mutationOptions,
|
|
1354
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.submitIntent(body, apiConfig))
|
|
1355
|
+
});
|
|
1356
|
+
};
|
|
1357
|
+
|
|
1358
|
+
// src/hooks/swapsApi/isTerminalSwapIntentStatus.ts
|
|
1359
|
+
var isTerminalSwapIntentStatus = (status) => status === 3 || status === 4;
|
|
1360
|
+
|
|
1361
|
+
// src/hooks/swapsApi/useSwapsApiStatus.ts
|
|
1362
|
+
var useSwapsApiStatus = ({
|
|
1363
|
+
params,
|
|
1364
|
+
queryOptions
|
|
1365
|
+
} = {}) => {
|
|
1366
|
+
const { sodax } = useSodaxContext();
|
|
1367
|
+
const intentTxHash = params?.intentTxHash;
|
|
1368
|
+
const apiConfig = params?.apiConfig;
|
|
1369
|
+
return useQuery({
|
|
1370
|
+
queryKey: ["swapsApi", "status", intentTxHash],
|
|
1371
|
+
queryFn: async () => {
|
|
1372
|
+
if (!intentTxHash) return void 0;
|
|
1373
|
+
return unwrapResult(await sodax.api.swaps.getStatus({ intentTxHash }, apiConfig));
|
|
1374
|
+
},
|
|
1375
|
+
enabled: !!intentTxHash && intentTxHash.length > 0,
|
|
1376
|
+
retry: 3,
|
|
1377
|
+
refetchInterval: (query) => isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1e3,
|
|
1378
|
+
...queryOptions
|
|
1379
|
+
});
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
// src/hooks/swapsApi/useSwapsApiCancelIntent.ts
|
|
1383
|
+
var useSwapsApiCancelIntent = ({
|
|
1384
|
+
mutationOptions
|
|
1385
|
+
} = {}) => {
|
|
1386
|
+
const { sodax } = useSodaxContext();
|
|
1387
|
+
return useSafeMutation({
|
|
1388
|
+
mutationKey: ["swapsApi", "cancelIntent"],
|
|
1389
|
+
retry: 3,
|
|
1390
|
+
...mutationOptions,
|
|
1391
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.cancelIntent(body, apiConfig))
|
|
1392
|
+
});
|
|
1393
|
+
};
|
|
1394
|
+
var useSwapsApiIntentHash = ({
|
|
1395
|
+
params,
|
|
1396
|
+
queryOptions
|
|
1397
|
+
} = {}) => {
|
|
1398
|
+
const { sodax } = useSodaxContext();
|
|
1399
|
+
const intent = params?.intent;
|
|
1400
|
+
const apiConfig = params?.apiConfig;
|
|
1401
|
+
return useQuery({
|
|
1402
|
+
queryKey: ["swapsApi", "intentHash", intent?.intentId?.toString()],
|
|
1403
|
+
queryFn: async () => {
|
|
1404
|
+
if (!intent) return void 0;
|
|
1405
|
+
return unwrapResult(await sodax.api.swaps.getIntentHash({ intent }, apiConfig));
|
|
1406
|
+
},
|
|
1407
|
+
enabled: !!intent,
|
|
1408
|
+
retry: 3,
|
|
1409
|
+
...queryOptions
|
|
1410
|
+
});
|
|
1411
|
+
};
|
|
1412
|
+
var useSwapsApiIntentPacket = ({
|
|
1413
|
+
params,
|
|
1414
|
+
queryOptions
|
|
1415
|
+
} = {}) => {
|
|
1416
|
+
const { sodax } = useSodaxContext();
|
|
1417
|
+
const body = params?.body;
|
|
1418
|
+
const apiConfig = params?.apiConfig;
|
|
1419
|
+
return useQuery({
|
|
1420
|
+
queryKey: ["swapsApi", "intentPacket", body?.chainId, body?.fillTxHash],
|
|
1421
|
+
queryFn: async () => {
|
|
1422
|
+
if (!body) return void 0;
|
|
1423
|
+
return unwrapResult(await sodax.api.swaps.getSolvedIntentPacket(body, apiConfig));
|
|
1424
|
+
},
|
|
1425
|
+
enabled: !!body,
|
|
1426
|
+
retry: 3,
|
|
1427
|
+
...queryOptions
|
|
1428
|
+
});
|
|
1429
|
+
};
|
|
1430
|
+
var useSwapsApiIntentExtraData = ({
|
|
1431
|
+
params,
|
|
1432
|
+
queryOptions
|
|
1433
|
+
} = {}) => {
|
|
1434
|
+
const { sodax } = useSodaxContext();
|
|
1435
|
+
const body = params?.body;
|
|
1436
|
+
const apiConfig = params?.apiConfig;
|
|
1437
|
+
return useQuery({
|
|
1438
|
+
queryKey: ["swapsApi", "intentExtraData", body?.txHash ?? body?.intent?.intentId?.toString()],
|
|
1439
|
+
queryFn: async () => {
|
|
1440
|
+
if (!body || !body.txHash && !body.intent) return void 0;
|
|
1441
|
+
return unwrapResult(await sodax.api.swaps.getIntentSubmitTxExtraData(body, apiConfig));
|
|
1442
|
+
},
|
|
1443
|
+
enabled: !!body && (!!body.txHash || !!body.intent),
|
|
1444
|
+
retry: 3,
|
|
1445
|
+
...queryOptions
|
|
1446
|
+
});
|
|
1447
|
+
};
|
|
1448
|
+
var useSwapsApiFilledIntent = ({
|
|
1449
|
+
params,
|
|
1450
|
+
queryOptions
|
|
1451
|
+
} = {}) => {
|
|
1452
|
+
const { sodax } = useSodaxContext();
|
|
1453
|
+
const txHash = params?.txHash;
|
|
1454
|
+
const apiConfig = params?.apiConfig;
|
|
1455
|
+
return useQuery({
|
|
1456
|
+
queryKey: ["swapsApi", "filledIntent", txHash],
|
|
1457
|
+
queryFn: async () => {
|
|
1458
|
+
if (!txHash) return void 0;
|
|
1459
|
+
return unwrapResult(await sodax.api.swaps.getFilledIntent(txHash, apiConfig));
|
|
1460
|
+
},
|
|
1461
|
+
enabled: !!txHash && txHash.length > 0,
|
|
1462
|
+
retry: 3,
|
|
1463
|
+
...queryOptions
|
|
1464
|
+
});
|
|
1465
|
+
};
|
|
1466
|
+
var useSwapsApiIntent = ({
|
|
1467
|
+
params,
|
|
1468
|
+
queryOptions
|
|
1469
|
+
} = {}) => {
|
|
1470
|
+
const { sodax } = useSodaxContext();
|
|
1471
|
+
const txHash = params?.txHash;
|
|
1472
|
+
const apiConfig = params?.apiConfig;
|
|
1473
|
+
return useQuery({
|
|
1474
|
+
queryKey: ["swapsApi", "intent", txHash],
|
|
1475
|
+
queryFn: async () => {
|
|
1476
|
+
if (!txHash) return void 0;
|
|
1477
|
+
return unwrapResult(await sodax.api.swaps.getIntent(txHash, apiConfig));
|
|
1478
|
+
},
|
|
1479
|
+
enabled: !!txHash && txHash.length > 0,
|
|
1480
|
+
retry: 3,
|
|
1481
|
+
...queryOptions
|
|
1482
|
+
});
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1485
|
+
// src/hooks/swapsApi/useSwapsApiCreateLimitOrder.ts
|
|
1486
|
+
var useSwapsApiCreateLimitOrder = ({
|
|
1487
|
+
mutationOptions
|
|
1488
|
+
} = {}) => {
|
|
1489
|
+
const { sodax } = useSodaxContext();
|
|
1490
|
+
return useSafeMutation({
|
|
1491
|
+
mutationKey: ["swapsApi", "createLimitOrder"],
|
|
1492
|
+
retry: 3,
|
|
1493
|
+
...mutationOptions,
|
|
1494
|
+
mutationFn: async ({ body, apiConfig }) => unwrapResult(await sodax.api.swaps.createLimitOrderIntent(body, apiConfig))
|
|
1495
|
+
});
|
|
1496
|
+
};
|
|
1497
|
+
var useSwapsApiEstimateGas = ({
|
|
1498
|
+
params,
|
|
1499
|
+
queryOptions
|
|
1500
|
+
} = {}) => {
|
|
1501
|
+
const { sodax } = useSodaxContext();
|
|
1502
|
+
const body = params?.body;
|
|
1503
|
+
const apiConfig = params?.apiConfig;
|
|
1504
|
+
return useQuery({
|
|
1505
|
+
queryKey: ["swapsApi", "estimateGas", body?.chainKey, body?.tx],
|
|
1506
|
+
queryFn: async () => {
|
|
1507
|
+
if (!body) return void 0;
|
|
1508
|
+
return unwrapResult(await sodax.api.swaps.estimateGas(body, apiConfig));
|
|
1509
|
+
},
|
|
1510
|
+
enabled: !!body,
|
|
1511
|
+
retry: 3,
|
|
1512
|
+
...queryOptions
|
|
1513
|
+
});
|
|
1514
|
+
};
|
|
1515
|
+
var useSwapsApiPartnerFee = ({
|
|
1516
|
+
params,
|
|
1517
|
+
queryOptions
|
|
1518
|
+
} = {}) => {
|
|
1519
|
+
const { sodax } = useSodaxContext();
|
|
1520
|
+
const amount = params?.amount;
|
|
1521
|
+
const apiConfig = params?.apiConfig;
|
|
1522
|
+
return useQuery({
|
|
1523
|
+
queryKey: ["swapsApi", "partnerFee", amount],
|
|
1524
|
+
queryFn: async () => {
|
|
1525
|
+
if (!amount) return void 0;
|
|
1526
|
+
return unwrapResult(await sodax.api.swaps.getPartnerFee({ amount }, apiConfig));
|
|
1527
|
+
},
|
|
1528
|
+
enabled: !!amount && amount.length > 0,
|
|
1529
|
+
retry: 3,
|
|
1530
|
+
...queryOptions
|
|
1531
|
+
});
|
|
1532
|
+
};
|
|
1533
|
+
var useSwapsApiSolverFee = ({
|
|
1534
|
+
params,
|
|
1535
|
+
queryOptions
|
|
1536
|
+
} = {}) => {
|
|
1537
|
+
const { sodax } = useSodaxContext();
|
|
1538
|
+
const amount = params?.amount;
|
|
1539
|
+
const apiConfig = params?.apiConfig;
|
|
1540
|
+
return useQuery({
|
|
1541
|
+
queryKey: ["swapsApi", "solverFee", amount],
|
|
1542
|
+
queryFn: async () => {
|
|
1543
|
+
if (!amount) return void 0;
|
|
1544
|
+
return unwrapResult(await sodax.api.swaps.getSolverFee({ amount }, apiConfig));
|
|
1545
|
+
},
|
|
1546
|
+
enabled: !!amount && amount.length > 0,
|
|
1547
|
+
retry: 3,
|
|
1548
|
+
...queryOptions
|
|
1549
|
+
});
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
// src/hooks/swapsApi/useSwapsApiSubmitTx.ts
|
|
1553
|
+
var useSwapsApiSubmitTx = ({
|
|
1554
|
+
mutationOptions
|
|
1555
|
+
} = {}) => {
|
|
1556
|
+
const { sodax } = useSodaxContext();
|
|
1557
|
+
return useSafeMutation({
|
|
1558
|
+
mutationKey: ["swapsApi", "submitTx"],
|
|
1559
|
+
retry: 3,
|
|
1560
|
+
...mutationOptions,
|
|
1561
|
+
mutationFn: async ({ request, apiConfig }) => unwrapResult(await sodax.api.swaps.submitTx(request, apiConfig))
|
|
1562
|
+
});
|
|
1563
|
+
};
|
|
1564
|
+
var useSwapsApiSubmitTxStatus = ({
|
|
1565
|
+
params,
|
|
1566
|
+
queryOptions
|
|
1567
|
+
} = {}) => {
|
|
1568
|
+
const { sodax } = useSodaxContext();
|
|
1569
|
+
const txHash = params?.txHash;
|
|
1570
|
+
const srcChainKey = params?.srcChainKey;
|
|
1571
|
+
const apiConfig = params?.apiConfig;
|
|
1572
|
+
return useQuery({
|
|
1573
|
+
queryKey: ["swapsApi", "submitTx", "status", txHash, srcChainKey],
|
|
1574
|
+
queryFn: async () => {
|
|
1575
|
+
if (!txHash || !srcChainKey) return void 0;
|
|
1576
|
+
return unwrapResult(await sodax.api.swaps.getSubmitTxStatus({ txHash, srcChainKey }, apiConfig));
|
|
1577
|
+
},
|
|
1578
|
+
enabled: !!txHash && txHash.length > 0 && !!srcChainKey,
|
|
1579
|
+
retry: 3,
|
|
1580
|
+
refetchInterval: (query) => {
|
|
1581
|
+
const status = query.state.data?.data?.status;
|
|
1582
|
+
if (status === "executed" || status === "failed") return false;
|
|
1583
|
+
return 1e3;
|
|
1584
|
+
},
|
|
1585
|
+
...queryOptions
|
|
1586
|
+
});
|
|
1587
|
+
};
|
|
1264
1588
|
function useBridge({
|
|
1265
1589
|
mutationOptions
|
|
1266
1590
|
} = {}) {
|
|
@@ -1883,6 +2207,107 @@ function useFeeClaimSwap({
|
|
|
1883
2207
|
}
|
|
1884
2208
|
});
|
|
1885
2209
|
}
|
|
2210
|
+
function usePartnerCancelIntent({
|
|
2211
|
+
mutationOptions
|
|
2212
|
+
} = {}) {
|
|
2213
|
+
const { sodax } = useSodaxContext();
|
|
2214
|
+
const queryClient = useQueryClient();
|
|
2215
|
+
return useSafeMutation({
|
|
2216
|
+
mutationKey: ["partner", "cancelIntent"],
|
|
2217
|
+
...mutationOptions,
|
|
2218
|
+
mutationFn: async (vars) => unwrapResult(await sodax.partners.feeClaim.cancelIntent({ ...vars, raw: false })),
|
|
2219
|
+
onSuccess: async (data, vars, ctx) => {
|
|
2220
|
+
queryClient.invalidateQueries({
|
|
2221
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
2222
|
+
});
|
|
2223
|
+
queryClient.invalidateQueries({
|
|
2224
|
+
queryKey: [
|
|
2225
|
+
"partner",
|
|
2226
|
+
"feeClaim",
|
|
2227
|
+
"userIntent",
|
|
2228
|
+
vars.params.srcAddress,
|
|
2229
|
+
vars.params.fromToken,
|
|
2230
|
+
vars.params.toToken
|
|
2231
|
+
]
|
|
2232
|
+
});
|
|
2233
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2234
|
+
}
|
|
2235
|
+
});
|
|
2236
|
+
}
|
|
2237
|
+
function useGetUserIntent({ params, queryOptions } = {}) {
|
|
2238
|
+
const { sodax } = useSodaxContext();
|
|
2239
|
+
const user = params?.user;
|
|
2240
|
+
const fromToken = params?.fromToken;
|
|
2241
|
+
const toToken = params?.toToken;
|
|
2242
|
+
return useQuery({
|
|
2243
|
+
queryKey: ["partner", "feeClaim", "userIntent", user, fromToken, toToken],
|
|
2244
|
+
queryFn: async () => {
|
|
2245
|
+
if (!user || !fromToken || !toToken) {
|
|
2246
|
+
throw new Error("user, fromToken and toToken are required");
|
|
2247
|
+
}
|
|
2248
|
+
const result = await sodax.partners.feeClaim.getUserIntent({ user, fromToken, toToken });
|
|
2249
|
+
if (!result.ok) throw result.error;
|
|
2250
|
+
return result.value;
|
|
2251
|
+
},
|
|
2252
|
+
enabled: !!user && !!fromToken && !!toToken,
|
|
2253
|
+
...queryOptions
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
2256
|
+
var ZERO_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
|
|
2257
|
+
function useGetIntentDetails({
|
|
2258
|
+
params,
|
|
2259
|
+
queryOptions
|
|
2260
|
+
} = {}) {
|
|
2261
|
+
const { sodax } = useSodaxContext();
|
|
2262
|
+
const intentHash = params?.intentHash;
|
|
2263
|
+
const hasIntent = !!intentHash && intentHash !== ZERO_HASH;
|
|
2264
|
+
return useQuery({
|
|
2265
|
+
queryKey: ["partner", "feeClaim", "intentDetails", intentHash],
|
|
2266
|
+
queryFn: async () => {
|
|
2267
|
+
if (!intentHash) {
|
|
2268
|
+
throw new Error("intentHash is required");
|
|
2269
|
+
}
|
|
2270
|
+
const result = await sodax.partners.feeClaim.getIntentDetails(intentHash);
|
|
2271
|
+
if (!result.ok) throw result.error;
|
|
2272
|
+
return result.value;
|
|
2273
|
+
},
|
|
2274
|
+
enabled: hasIntent,
|
|
2275
|
+
...queryOptions
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
function useFeeClaimWithdraw({
|
|
2279
|
+
mutationOptions
|
|
2280
|
+
} = {}) {
|
|
2281
|
+
const { sodax } = useSodaxContext();
|
|
2282
|
+
const queryClient = useQueryClient();
|
|
2283
|
+
return useSafeMutation({
|
|
2284
|
+
mutationKey: ["partner", "feeClaimWithdraw"],
|
|
2285
|
+
...mutationOptions,
|
|
2286
|
+
mutationFn: async ({ params, walletProvider }) => {
|
|
2287
|
+
const bridgeParams = {
|
|
2288
|
+
params: {
|
|
2289
|
+
srcChainKey: ChainKeys.SONIC_MAINNET,
|
|
2290
|
+
srcAddress: params.srcAddress,
|
|
2291
|
+
srcToken: params.feeToken,
|
|
2292
|
+
amount: params.amount,
|
|
2293
|
+
dstChainKey: params.dstChainKey,
|
|
2294
|
+
dstToken: params.dstToken,
|
|
2295
|
+
recipient: params.recipient
|
|
2296
|
+
},
|
|
2297
|
+
raw: false,
|
|
2298
|
+
walletProvider
|
|
2299
|
+
};
|
|
2300
|
+
return unwrapResult(await sodax.bridge.bridge(bridgeParams));
|
|
2301
|
+
},
|
|
2302
|
+
onSuccess: async (data, vars, ctx) => {
|
|
2303
|
+
queryClient.invalidateQueries({
|
|
2304
|
+
queryKey: ["partner", "feeClaim", "assetsBalances", vars.params.srcAddress]
|
|
2305
|
+
});
|
|
2306
|
+
queryClient.invalidateQueries({ queryKey: ["shared", "xBalances", vars.params.dstChainKey] });
|
|
2307
|
+
await mutationOptions?.onSuccess?.(data, vars, ctx);
|
|
2308
|
+
}
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
1886
2311
|
function useHubAssetBalances({
|
|
1887
2312
|
params,
|
|
1888
2313
|
queryOptions
|
|
@@ -2784,4 +3209,4 @@ function createSodaxQueryClient({
|
|
|
2784
3209
|
});
|
|
2785
3210
|
}
|
|
2786
3211
|
|
|
2787
|
-
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook,
|
|
3212
|
+
export { SodaxProvider, clearRadfiSession, createDecreaseLiquidityParamsProps, createDepositParamsProps, createSodaxQueryClient, createSupplyLiquidityParamsProps, createWithdrawParamsProps, getXBalancesQueryOptions, isTerminalSwapIntentStatus, loadRadfiSession, resolveNearStorageGate, saveRadfiSession, toResult, unwrapResult, useAToken, useATokensBalances, useApproveToken, useBackendAllMoneyMarketAssets, useBackendAllMoneyMarketBorrowers, useBackendIntentByHash, useBackendIntentByTxHash, useBackendMoneyMarketAsset, useBackendMoneyMarketAssetBorrowers, useBackendMoneyMarketAssetSuppliers, useBackendMoneyMarketPosition, useBackendOrderbook, useBackendUserIntents, useBitcoinBalance, useBitcoinTradingSetup, useBorrow, useBridge, useBridgeAllowance, useBridgeApprove, useCancelLimitOrder, useCancelSwap, useCancelUnstake, useClaim, useClaimRewards, useConvertedAssets, useCreateDecreaseLiquidityParams, useCreateDepositParams, useCreateLimitOrder, useCreateSupplyLiquidityParams, useCreateWithdrawParams, useDecreaseLiquidity, useDeriveUserWalletAddress, useDexAllowance, useDexApprove, useDexDeposit, useDexWithdraw, useEnsureRadfiAccessToken, useEstimateGas, useExpiredUtxos, useFeeClaimSwap, useFeeClaimWithdraw, useFetchAssetsBalances, useFundTradingWallet, useGetAutoSwapPreferences, useGetBridgeableAmount, useGetBridgeableTokens, useGetIntentDetails, useGetUserHubWalletAddress, useGetUserIntent, useHubAssetBalances, useHubProvider, useInstantUnstake, useInstantUnstakeAllowance, useInstantUnstakeApprove, useInstantUnstakeRatio, useIsTokenApproved, useLeverageYieldDeposit, useLeverageYieldEffectiveApr, useLeverageYieldNotifySolver, useLeverageYieldPosition, useLeverageYieldPreviewRedeem, useLeverageYieldShareBalances, useLeverageYieldTotalAssets, useLeverageYieldVaultSwap, useLeverageYieldWithdraw, useLiquidityAmounts, useMMAllowance, useMMApprove, useMigrateBaln, useMigrateIcxToSoda, useMigratebnUSD, useMigrationAllowance, useMigrationApprove, useNearStorageCheck, useNearStorageGate, usePartnerCancelIntent, usePoolBalances, usePoolData, usePools, usePositionInfo, useQuote, useRadfiAuth, useRadfiSession, useRadfiWithdraw, useRegisterNearStorage, useRenewUtxos, useRepay, useRequestTrustline, useReservesData, useReservesHumanized, useReservesList, useReservesUsdFormat, useRevertMigrateSodaToIcx, useSafeMutation, useSetSwapPreference, useSodaxContext, useStake, useStakeAllowance, useStakeApprove, useStakeRatio, useStakingConfig, useStakingInfo, useStatus, useStellarTrustlineCheck, useSupply, useSupplyLiquidity, useSwap, useSwapAllowance, useSwapApprove, useSwapsApiAllowance, useSwapsApiApprove, useSwapsApiCancelIntent, useSwapsApiCreateIntent, useSwapsApiCreateLimitOrder, useSwapsApiDeadline, useSwapsApiEstimateGas, useSwapsApiFilledIntent, useSwapsApiIntent, useSwapsApiIntentExtraData, useSwapsApiIntentHash, useSwapsApiIntentPacket, useSwapsApiPartnerFee, useSwapsApiQuote, useSwapsApiSolverFee, useSwapsApiStatus, useSwapsApiSubmitIntent, useSwapsApiSubmitTx, useSwapsApiSubmitTxStatus, useSwapsApiTokens, useSwapsApiTokensByChain, useTradingWallet, useTradingWalletBalance, useUnstake, useUnstakeAllowance, useUnstakeApprove, useUnstakingInfo, useUnstakingInfoWithPenalty, useUserFormattedSummary, useUserReservesData, useWithdraw, useWithdrawHubAsset, useXBalances };
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"version": "2.0.0-rc.
|
|
8
|
+
"version": "2.0.0-rc.19",
|
|
9
9
|
"description": "React hooks for building dApps on the SODAX cross-chain DeFi platform",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"sodax",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"viem": "2.29.2",
|
|
37
|
-
"@sodax/sdk": "2.0.0-rc.
|
|
37
|
+
"@sodax/sdk": "2.0.0-rc.19"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@arethetypeswrong/cli": "0.17.4",
|
|
@@ -13,7 +13,6 @@ const HOOKS_DIR = resolve(fileURLToPath(import.meta.url), '..');
|
|
|
13
13
|
* registration so the contract is enforced from day one.
|
|
14
14
|
*/
|
|
15
15
|
const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
|
|
16
|
-
{ path: 'backend/useBackendSubmitSwapTx.ts' },
|
|
17
16
|
{ path: 'bitcoin/useEnsureRadfiAccessToken.ts', nativeThrow: true },
|
|
18
17
|
{ path: 'bitcoin/useFundTradingWallet.ts', nativeThrow: true },
|
|
19
18
|
{ path: 'bitcoin/useRadfiAuth.ts', nativeThrow: true },
|
|
@@ -43,6 +42,8 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
|
|
|
43
42
|
{ path: 'mm/useWithdraw.ts' },
|
|
44
43
|
{ path: 'partner/useApproveToken.ts' },
|
|
45
44
|
{ path: 'partner/useFeeClaimSwap.ts' },
|
|
45
|
+
{ path: 'partner/useFeeClaimWithdraw.ts' },
|
|
46
|
+
{ path: 'partner/usePartnerCancelIntent.ts' },
|
|
46
47
|
{ path: 'partner/useSetSwapPreference.ts' },
|
|
47
48
|
{ path: 'recovery/useWithdrawHubAsset.ts' },
|
|
48
49
|
{ path: 'shared/useEstimateGas.ts' },
|
|
@@ -60,6 +61,12 @@ const HOOKS: Array<{ path: string; nativeThrow?: true }> = [
|
|
|
60
61
|
{ path: 'swap/useCreateLimitOrder.ts' },
|
|
61
62
|
{ path: 'swap/useSwap.ts' },
|
|
62
63
|
{ path: 'swap/useSwapApprove.ts' },
|
|
64
|
+
{ path: 'swapsApi/useSwapsApiApprove.ts' },
|
|
65
|
+
{ path: 'swapsApi/useSwapsApiCancelIntent.ts' },
|
|
66
|
+
{ path: 'swapsApi/useSwapsApiCreateIntent.ts' },
|
|
67
|
+
{ path: 'swapsApi/useSwapsApiCreateLimitOrder.ts' },
|
|
68
|
+
{ path: 'swapsApi/useSwapsApiSubmitIntent.ts' },
|
|
69
|
+
{ path: 'swapsApi/useSwapsApiSubmitTx.ts' },
|
|
63
70
|
];
|
|
64
71
|
|
|
65
72
|
describe.each(HOOKS)('mutation hook contract: $path', ({ path, nativeThrow }) => {
|
|
@@ -12,10 +12,6 @@ export { useBackendIntentByTxHash } from './useBackendIntentByTxHash.js';
|
|
|
12
12
|
export { useBackendIntentByHash } from './useBackendIntentByHash.js';
|
|
13
13
|
export { useBackendUserIntents } from './useBackendUserIntents.js';
|
|
14
14
|
|
|
15
|
-
// Swap submit-tx hooks
|
|
16
|
-
export { useBackendSubmitSwapTx } from './useBackendSubmitSwapTx.js';
|
|
17
|
-
export { useBackendSubmitSwapTxStatus } from './useBackendSubmitSwapTxStatus.js';
|
|
18
|
-
|
|
19
15
|
// Solver hooks
|
|
20
16
|
export { useBackendOrderbook } from './useBackendOrderbook.js';
|
|
21
17
|
|
|
@@ -26,4 +22,4 @@ export { useBackendMoneyMarketAsset } from './useBackendMoneyMarketAsset.js';
|
|
|
26
22
|
export { useBackendMoneyMarketAssetBorrowers } from './useBackendMoneyMarketAssetBorrowers.js';
|
|
27
23
|
export { useBackendMoneyMarketAssetSuppliers } from './useBackendMoneyMarketAssetSuppliers.js';
|
|
28
24
|
export { useBackendAllMoneyMarketBorrowers } from './useBackendAllMoneyMarketBorrowers.js';
|
|
29
|
-
export * from './types.js';
|
|
25
|
+
export * from './types.js';
|
|
@@ -5,6 +5,7 @@ export * from './useFundTradingWallet.js';
|
|
|
5
5
|
export * from './useBitcoinBalance.js';
|
|
6
6
|
export * from './useTradingWallet.js';
|
|
7
7
|
export * from './useTradingWalletBalance.js';
|
|
8
|
+
export * from './useBitcoinTradingSetup.js';
|
|
8
9
|
export * from './useExpiredUtxos.js';
|
|
9
10
|
export * from './useRenewUtxos.js';
|
|
10
11
|
export * from './useRadfiWithdraw.js';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChainKeys,
|
|
3
|
+
type IBitcoinWalletProvider,
|
|
4
|
+
type IWalletProvider,
|
|
5
|
+
type RadfiWalletBalance,
|
|
6
|
+
type SpokeChainKey,
|
|
7
|
+
} from '@sodax/sdk';
|
|
8
|
+
import { useTradingWallet } from './useTradingWallet.js';
|
|
9
|
+
import { useTradingWalletBalance } from './useTradingWalletBalance.js';
|
|
10
|
+
|
|
11
|
+
export interface UseBitcoinTradingSetupParams {
|
|
12
|
+
chainKey: SpokeChainKey;
|
|
13
|
+
/** This side's wallet provider + account, e.g. `useWalletProvider` / `useXAccount`. */
|
|
14
|
+
walletProvider: IWalletProvider | undefined;
|
|
15
|
+
address: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface BitcoinTradingSetup {
|
|
19
|
+
wallet: IBitcoinWalletProvider | undefined;
|
|
20
|
+
tradingBalance: RadfiWalletBalance | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const INERT: BitcoinTradingSetup = { wallet: undefined, tradingBalance: undefined };
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Bitcoin trading-wallet setup for one side of a cross-chain flow: Bitcoin funds move through a
|
|
27
|
+
* Bound Exchange (Radfi) trading wallet, not the personal wallet. Inert (no work) unless `chainKey`
|
|
28
|
+
* is Bitcoin. Wallet-layer inputs are passed in — this package doesn't depend on wallet-sdk-react.
|
|
29
|
+
*/
|
|
30
|
+
export function useBitcoinTradingSetup({
|
|
31
|
+
chainKey,
|
|
32
|
+
walletProvider,
|
|
33
|
+
address,
|
|
34
|
+
}: UseBitcoinTradingSetupParams): BitcoinTradingSetup {
|
|
35
|
+
const isBitcoin = chainKey === ChainKeys.BITCOIN_MAINNET;
|
|
36
|
+
// Safe: when this side is Bitcoin its provider IS the Bitcoin one (TS can't relate chainKey to provider type).
|
|
37
|
+
const wallet = isBitcoin ? (walletProvider as IBitcoinWalletProvider | undefined) : undefined;
|
|
38
|
+
|
|
39
|
+
// Hooks run every render; undefined inputs keep the Bound balance query disabled when not Bitcoin.
|
|
40
|
+
const { tradingAddress } = useTradingWallet(isBitcoin ? address : undefined);
|
|
41
|
+
const { data: tradingBalance } = useTradingWalletBalance({ params: { walletProvider: wallet, tradingAddress } });
|
|
42
|
+
|
|
43
|
+
if (!isBitcoin) return INERT;
|
|
44
|
+
return { wallet, tradingBalance };
|
|
45
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from './bitcoin/index.js';
|
|
|
4
4
|
export * from './mm/index.js';
|
|
5
5
|
export * from './swap/index.js';
|
|
6
6
|
export * from './backend/index.js';
|
|
7
|
+
export * from './swapsApi/index.js';
|
|
7
8
|
export * from './bridge/index.js';
|
|
8
9
|
export * from './staking/index.js';
|
|
9
10
|
export * from './partner/index.js';
|
|
@@ -4,3 +4,7 @@ export * from './useIsTokenApproved.js';
|
|
|
4
4
|
export * from './useApproveToken.js';
|
|
5
5
|
export * from './useSetSwapPreference.js';
|
|
6
6
|
export * from './useFeeClaimSwap.js';
|
|
7
|
+
export * from './usePartnerCancelIntent.js';
|
|
8
|
+
export * from './useGetUserIntent.js';
|
|
9
|
+
export * from './useGetIntentDetails.js';
|
|
10
|
+
export * from './useFeeClaimWithdraw.js';
|