@orderly.network/hooks 2.9.1 → 2.10.0-alpha.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/dist/index.d.mts +31 -35
- package/dist/index.d.ts +31 -35
- package/dist/index.js +388 -446
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +381 -439
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var net = require('@orderly.network/net');
|
|
4
|
-
var
|
|
4
|
+
var useSWR5 = require('swr');
|
|
5
5
|
var types = require('@orderly.network/types');
|
|
6
6
|
var React2 = require('react');
|
|
7
7
|
var utils = require('@orderly.network/utils');
|
|
@@ -46,7 +46,7 @@ function _interopNamespace(e) {
|
|
|
46
46
|
return Object.freeze(n);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
var
|
|
49
|
+
var useSWR5__namespace = /*#__PURE__*/_interopNamespace(useSWR5);
|
|
50
50
|
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
51
51
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
52
52
|
var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
|
|
@@ -64,9 +64,9 @@ var __export = (target, all) => {
|
|
|
64
64
|
// src/version.ts
|
|
65
65
|
if (typeof window !== "undefined") {
|
|
66
66
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
67
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.
|
|
67
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.10.0-alpha.1";
|
|
68
68
|
}
|
|
69
|
-
var version_default = "2.
|
|
69
|
+
var version_default = "2.10.0-alpha.1";
|
|
70
70
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
71
71
|
var noCacheConfig = {
|
|
72
72
|
dedupingInterval: 0,
|
|
@@ -105,7 +105,7 @@ var useQuery = (query, options) => {
|
|
|
105
105
|
if (typeof apiBaseUrl === "undefined") {
|
|
106
106
|
throw new types.SDKError("please add OrderlyConfigProvider to your app");
|
|
107
107
|
}
|
|
108
|
-
return
|
|
108
|
+
return useSWR5__namespace.default(
|
|
109
109
|
query,
|
|
110
110
|
(url, init2) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init2, {
|
|
111
111
|
formatter
|
|
@@ -491,7 +491,7 @@ var usePrivateQuery = (query, options) => {
|
|
|
491
491
|
const { formatter, ...swrOptions } = options || {};
|
|
492
492
|
const { state } = useAccount();
|
|
493
493
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
494
|
-
return
|
|
494
|
+
return useSWR5__namespace.default(
|
|
495
495
|
() => query && (state.status >= types.AccountStatusEnum.EnableTrading || state.status === types.AccountStatusEnum.EnableTradingWithoutConnected) ? [query, state.accountId] : null,
|
|
496
496
|
(url, init2) => {
|
|
497
497
|
return fetcher(url, init2, { formatter });
|
|
@@ -960,7 +960,7 @@ function useSubAccountQuery(query, options) {
|
|
|
960
960
|
const { formatter, accountId, ...swrOptions } = options || {};
|
|
961
961
|
const { state, account: account9 } = useAccount();
|
|
962
962
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
963
|
-
return
|
|
963
|
+
return useSWR5__namespace.default(
|
|
964
964
|
() => accountId && (state.status >= types.AccountStatusEnum.EnableTrading || state.status === types.AccountStatusEnum.EnableTradingWithoutConnected) ? [query, accountId] : null,
|
|
965
965
|
(url, init2) => {
|
|
966
966
|
return fetcher(url, init2, { formatter });
|
|
@@ -2788,7 +2788,7 @@ var usePreLoadData = () => {
|
|
|
2788
2788
|
if (swapSupportInfo || !enableSwapDeposit) return;
|
|
2789
2789
|
fetchSwapSupport();
|
|
2790
2790
|
}, [swapSupportInfo, enableSwapDeposit]);
|
|
2791
|
-
const { data: systemInfo } =
|
|
2791
|
+
const { data: systemInfo } = useSWR5__namespace.default(
|
|
2792
2792
|
"/v1/public/system_info",
|
|
2793
2793
|
async (url, init2) => {
|
|
2794
2794
|
const data = await fetch(
|
|
@@ -4087,6 +4087,29 @@ var useOpenInterest = (symbol) => {
|
|
|
4087
4087
|
};
|
|
4088
4088
|
});
|
|
4089
4089
|
};
|
|
4090
|
+
var useMarkPriceStore = zustand.create((set, get3) => ({
|
|
4091
|
+
markPrices: {},
|
|
4092
|
+
// orderBook: {},
|
|
4093
|
+
// ask_bid: [],
|
|
4094
|
+
actions: {
|
|
4095
|
+
updateMarkPrice: (markPrice) => {
|
|
4096
|
+
set({
|
|
4097
|
+
markPrices: markPrice
|
|
4098
|
+
});
|
|
4099
|
+
},
|
|
4100
|
+
getMarkPriceBySymbol: (symbol) => {
|
|
4101
|
+
return get3().markPrices[symbol];
|
|
4102
|
+
}
|
|
4103
|
+
}
|
|
4104
|
+
}));
|
|
4105
|
+
var useMarkPriceBySymbol = (symbol) => useMarkPriceStore((state) => state.actions.getMarkPriceBySymbol(symbol));
|
|
4106
|
+
var useMarkPriceActions = () => useMarkPriceStore((state) => state.actions);
|
|
4107
|
+
|
|
4108
|
+
// src/orderly/useMarkPricesStream.ts
|
|
4109
|
+
var useMarkPricesStream = () => {
|
|
4110
|
+
const data = useMarkPriceStore((state) => state.markPrices);
|
|
4111
|
+
return { data };
|
|
4112
|
+
};
|
|
4090
4113
|
|
|
4091
4114
|
// src/orderly/useTickerStream.ts
|
|
4092
4115
|
var useTickerStream = (symbol) => {
|
|
@@ -4122,10 +4145,13 @@ var useTickerStream = (symbol) => {
|
|
|
4122
4145
|
unsubscribe?.();
|
|
4123
4146
|
};
|
|
4124
4147
|
}, [symbol]);
|
|
4125
|
-
const { data:
|
|
4148
|
+
const { data: markPrices } = useMarkPricesStream();
|
|
4126
4149
|
const { data: indexPrice } = useIndexPrice(symbol);
|
|
4127
4150
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
4128
4151
|
const marketMap = useMarketMap();
|
|
4152
|
+
const markPrice = React2.useMemo(() => {
|
|
4153
|
+
return markPrices?.[symbol];
|
|
4154
|
+
}, [markPrices, symbol]);
|
|
4129
4155
|
const value = React2.useMemo(() => {
|
|
4130
4156
|
if (!info) return null;
|
|
4131
4157
|
if (!ticker || ticker.symbol !== symbol) return info;
|
|
@@ -4694,29 +4720,6 @@ function get24hChange2(close, open) {
|
|
|
4694
4720
|
return new utils.Decimal(close).minus(open).div(open).toNumber();
|
|
4695
4721
|
}
|
|
4696
4722
|
}
|
|
4697
|
-
var useMarkPriceStore = zustand.create((set, get3) => ({
|
|
4698
|
-
markPrices: {},
|
|
4699
|
-
// orderBook: {},
|
|
4700
|
-
// ask_bid: [],
|
|
4701
|
-
actions: {
|
|
4702
|
-
updateMarkPrice: (markPrice) => {
|
|
4703
|
-
set({
|
|
4704
|
-
markPrices: markPrice
|
|
4705
|
-
});
|
|
4706
|
-
},
|
|
4707
|
-
getMarkPriceBySymbol: (symbol) => {
|
|
4708
|
-
return get3().markPrices[symbol];
|
|
4709
|
-
}
|
|
4710
|
-
}
|
|
4711
|
-
}));
|
|
4712
|
-
var useMarkPriceBySymbol = (symbol) => useMarkPriceStore((state) => state.actions.getMarkPriceBySymbol(symbol));
|
|
4713
|
-
var useMarkPriceActions = () => useMarkPriceStore((state) => state.actions);
|
|
4714
|
-
|
|
4715
|
-
// src/orderly/useMarkPricesStream.ts
|
|
4716
|
-
var useMarkPricesStream = () => {
|
|
4717
|
-
const data = useMarkPriceStore((state) => state.markPrices);
|
|
4718
|
-
return { data };
|
|
4719
|
-
};
|
|
4720
4723
|
var useIndexPriceStore = zustand.create((set) => ({
|
|
4721
4724
|
indexPrices: {},
|
|
4722
4725
|
actions: {
|
|
@@ -6619,7 +6622,7 @@ var useSubAccountDataObserver = (accountId) => {
|
|
|
6619
6622
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
6620
6623
|
onMessage: (data) => {
|
|
6621
6624
|
const { positions: nextPositions } = data;
|
|
6622
|
-
|
|
6625
|
+
useSWR5.mutate(
|
|
6623
6626
|
key,
|
|
6624
6627
|
(prevPositions) => {
|
|
6625
6628
|
if (!!prevPositions) {
|
|
@@ -7104,7 +7107,7 @@ var useLeverageBySymbol = (symbol) => {
|
|
|
7104
7107
|
const res = data2?.accountDetail?.symbolLeverage || {};
|
|
7105
7108
|
if (res.symbol === symbol) {
|
|
7106
7109
|
const key = [`/v1/client/leverage?symbol=${symbol}`, state.accountId];
|
|
7107
|
-
|
|
7110
|
+
useSWR5.mutate(
|
|
7108
7111
|
key,
|
|
7109
7112
|
(prevData) => {
|
|
7110
7113
|
return {
|
|
@@ -7251,20 +7254,22 @@ var useMarginRatio = () => {
|
|
|
7251
7254
|
}, [rows, notional]);
|
|
7252
7255
|
return { marginRatio, currentLeverage, mmr, maintenanceMargin };
|
|
7253
7256
|
};
|
|
7254
|
-
var
|
|
7257
|
+
var TESTNET_WHITE_LIST = [
|
|
7255
7258
|
types.ARBITRUM_TESTNET_CHAINID,
|
|
7256
7259
|
types.SOLANA_TESTNET_CHAINID,
|
|
7257
7260
|
types.MONAD_TESTNET_CHAINID,
|
|
7258
7261
|
types.ABSTRACT_TESTNET_CHAINID,
|
|
7259
7262
|
types.BSC_TESTNET_CHAINID
|
|
7260
7263
|
];
|
|
7264
|
+
var TESTNET_WHITE_CHAINS = TESTNET_WHITE_LIST.map((id) => ({
|
|
7265
|
+
id
|
|
7266
|
+
}));
|
|
7261
7267
|
function useChains(networkId, options = {}) {
|
|
7262
|
-
const { pick: pickField
|
|
7268
|
+
const { pick: pickField } = options;
|
|
7263
7269
|
const {
|
|
7264
7270
|
filteredChains: allowedChains,
|
|
7265
|
-
configStore,
|
|
7266
7271
|
customChains,
|
|
7267
|
-
|
|
7272
|
+
dataAdapter
|
|
7268
7273
|
} = React2.useContext(OrderlyContext);
|
|
7269
7274
|
const filterFun = React2.useRef(options?.filter);
|
|
7270
7275
|
filterFun.current = options?.filter;
|
|
@@ -7274,7 +7279,6 @@ function useChains(networkId, options = {}) {
|
|
|
7274
7279
|
const testTokenChainsRes = useTestTokenStore((state) => state.data);
|
|
7275
7280
|
const chainInfos = useMainnetChainsStore((state) => state.data);
|
|
7276
7281
|
const testChainInfos = useTestnetChainsStore((state) => state.data);
|
|
7277
|
-
const { swapChains, swapChainsError } = useSwapChains();
|
|
7278
7282
|
const chains = React2.useMemo(() => {
|
|
7279
7283
|
if (!tokenChainsRes || !testTokenChainsRes || !chainInfos || !testChainInfos) {
|
|
7280
7284
|
return [];
|
|
@@ -7282,17 +7286,15 @@ function useChains(networkId, options = {}) {
|
|
|
7282
7286
|
const mainnetChains = formatChains({
|
|
7283
7287
|
tokenChains: tokenChainsRes,
|
|
7284
7288
|
chainInfos,
|
|
7285
|
-
swapChains,
|
|
7286
7289
|
filter: filterFun.current,
|
|
7287
7290
|
mainnet: true,
|
|
7288
|
-
|
|
7291
|
+
resolveChains: dataAdapter?.chainsList
|
|
7289
7292
|
});
|
|
7290
7293
|
const testnetChains = formatChains({
|
|
7291
7294
|
tokenChains: testTokenChainsRes,
|
|
7292
7295
|
chainInfos: testChainInfos,
|
|
7293
|
-
swapChains,
|
|
7294
7296
|
mainnet: false,
|
|
7295
|
-
|
|
7297
|
+
resolveChains: dataAdapter?.chainsList
|
|
7296
7298
|
});
|
|
7297
7299
|
let mainnetArr = needFetchFromAPI ? mainnetChains : customChains?.mainnet;
|
|
7298
7300
|
let testnetArr = needFetchFromAPI ? testnetChains : customChains?.testnet;
|
|
@@ -7305,7 +7307,7 @@ function useChains(networkId, options = {}) {
|
|
|
7305
7307
|
mainnetArr = filterByAllowedChains(mainnetArr, allowedChains?.mainnet);
|
|
7306
7308
|
testnetArr = filterByAllowedChains(
|
|
7307
7309
|
testnetArr,
|
|
7308
|
-
allowedChains?.testnet ??
|
|
7310
|
+
allowedChains?.testnet ?? TESTNET_WHITE_CHAINS
|
|
7309
7311
|
);
|
|
7310
7312
|
if (!!pickField) {
|
|
7311
7313
|
testnetArr = testnetArr.map((item) => item[pickField]);
|
|
@@ -7330,15 +7332,14 @@ function useChains(networkId, options = {}) {
|
|
|
7330
7332
|
customChains,
|
|
7331
7333
|
pickField,
|
|
7332
7334
|
allowedChains,
|
|
7333
|
-
|
|
7334
|
-
chainTransformer
|
|
7335
|
+
dataAdapter
|
|
7335
7336
|
]);
|
|
7336
7337
|
const findByChainId = React2.useCallback(
|
|
7337
7338
|
(chainId, field) => {
|
|
7338
7339
|
const chain = chainsMap.current.get(chainId);
|
|
7339
7340
|
if (chain) {
|
|
7340
7341
|
chain.nativeToken = chain.token_infos?.find(
|
|
7341
|
-
(item) => item.address
|
|
7342
|
+
(item) => types.isNativeTokenChecker(item.address)
|
|
7342
7343
|
) || {
|
|
7343
7344
|
symbol: chain.network_infos?.currency_symbol
|
|
7344
7345
|
};
|
|
@@ -7362,7 +7363,7 @@ function useChains(networkId, options = {}) {
|
|
|
7362
7363
|
{
|
|
7363
7364
|
findByChainId,
|
|
7364
7365
|
checkChainSupport,
|
|
7365
|
-
error: tokenError
|
|
7366
|
+
error: tokenError
|
|
7366
7367
|
}
|
|
7367
7368
|
];
|
|
7368
7369
|
}
|
|
@@ -7378,70 +7379,23 @@ function filterByAllowedChains(chains, allowedChains) {
|
|
|
7378
7379
|
if (!allowedChains) {
|
|
7379
7380
|
return chains;
|
|
7380
7381
|
}
|
|
7381
|
-
return
|
|
7382
|
-
|
|
7383
|
-
(
|
|
7384
|
-
)
|
|
7385
|
-
);
|
|
7386
|
-
}
|
|
7387
|
-
function useSwapChains() {
|
|
7388
|
-
const { enableSwapDeposit } = React2.useContext(OrderlyContext);
|
|
7389
|
-
const { data: swapChainsRes, error: swapChainsError } = useSwapSupportStore();
|
|
7390
|
-
const swapChains = React2.useMemo(() => {
|
|
7391
|
-
if (!enableSwapDeposit || !swapChainsRes || !swapChainsRes.data) {
|
|
7392
|
-
return [];
|
|
7393
|
-
}
|
|
7394
|
-
const data = swapChainsRes.data;
|
|
7395
|
-
return Object.keys(data).map((key) => {
|
|
7396
|
-
const chain = data[key];
|
|
7397
|
-
const { network_infos, token_infos } = chain;
|
|
7398
|
-
const networkInfos = {
|
|
7399
|
-
...network_infos,
|
|
7400
|
-
// swap deposit will use shortName to get swap info
|
|
7401
|
-
shortName: key,
|
|
7402
|
-
cross_chain_router: network_infos?.woofi_dex_cross_chain_router,
|
|
7403
|
-
depositor: network_infos?.woofi_dex_depositor,
|
|
7404
|
-
est_txn_mins: network_infos?.est_txn_mins
|
|
7405
|
-
};
|
|
7406
|
-
const nativeToken = token_infos.find(
|
|
7407
|
-
(item) => item.symbol === network_infos.currency_symbol
|
|
7408
|
-
);
|
|
7409
|
-
if (nativeToken) {
|
|
7410
|
-
networkInfos.currency_decimal = nativeToken.decimals;
|
|
7411
|
-
} else {
|
|
7412
|
-
networkInfos.currency_decimal = 18;
|
|
7413
|
-
}
|
|
7414
|
-
const tokenInfos = token_infos?.filter((item) => item.swap_enable).map((item) => {
|
|
7415
|
-
const { woofi_dex_precision, ...rest } = item;
|
|
7416
|
-
return {
|
|
7417
|
-
...rest,
|
|
7418
|
-
precision: woofi_dex_precision
|
|
7419
|
-
};
|
|
7420
|
-
});
|
|
7421
|
-
return {
|
|
7422
|
-
network_infos: networkInfos,
|
|
7423
|
-
token_infos: tokenInfos || []
|
|
7424
|
-
};
|
|
7425
|
-
});
|
|
7426
|
-
}, [enableSwapDeposit, swapChainsRes]);
|
|
7427
|
-
return { swapChains, swapChainsError };
|
|
7382
|
+
return allowedChains.map((allowedChain) => {
|
|
7383
|
+
return chains.find(
|
|
7384
|
+
(chain) => parseInt(chain.network_infos?.chain_id) === allowedChain.id
|
|
7385
|
+
);
|
|
7386
|
+
}).filter((chain) => !!chain);
|
|
7428
7387
|
}
|
|
7429
|
-
function formatChains({
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
|
|
7434
|
-
|
|
7435
|
-
|
|
7436
|
-
}
|
|
7388
|
+
function formatChains(options) {
|
|
7389
|
+
const {
|
|
7390
|
+
chainInfos = [],
|
|
7391
|
+
tokenChains = [],
|
|
7392
|
+
filter,
|
|
7393
|
+
mainnet,
|
|
7394
|
+
resolveChains
|
|
7395
|
+
} = options;
|
|
7437
7396
|
const chains = [];
|
|
7438
7397
|
for (const chainInfo of chainInfos) {
|
|
7439
7398
|
const chainId = Number(chainInfo.chain_id);
|
|
7440
|
-
const swapChainInfo = swapChains.find(
|
|
7441
|
-
(item) => item.network_infos.chain_id === chainId
|
|
7442
|
-
);
|
|
7443
|
-
const swapNetworkInfo = swapChainInfo?.network_infos;
|
|
7444
|
-
const swapTokenInfos = swapChainInfo?.token_infos || [];
|
|
7445
7399
|
const {
|
|
7446
7400
|
name,
|
|
7447
7401
|
public_rpc_url,
|
|
@@ -7450,7 +7404,6 @@ function formatChains({
|
|
|
7450
7404
|
explorer_base_url,
|
|
7451
7405
|
vault_address
|
|
7452
7406
|
} = chainInfo;
|
|
7453
|
-
const { shortName, cross_chain_router, depositor, est_txn_mins } = swapNetworkInfo || {};
|
|
7454
7407
|
const network_infos = {
|
|
7455
7408
|
name,
|
|
7456
7409
|
chain_id: chainId,
|
|
@@ -7461,32 +7414,21 @@ function formatChains({
|
|
|
7461
7414
|
currency_decimal,
|
|
7462
7415
|
bridge_enable: true,
|
|
7463
7416
|
explorer_base_url,
|
|
7464
|
-
|
|
7465
|
-
shortName: shortName ?? name,
|
|
7466
|
-
cross_chain_router,
|
|
7467
|
-
depositor,
|
|
7468
|
-
est_txn_mins,
|
|
7417
|
+
shortName: name,
|
|
7469
7418
|
vault_address
|
|
7470
7419
|
};
|
|
7471
|
-
const usdcSwapToken = swapTokenInfos.find(
|
|
7472
|
-
(item) => item.symbol === "USDC"
|
|
7473
|
-
);
|
|
7474
7420
|
const tokenInfos = tokenChains.filter(
|
|
7475
7421
|
(item) => item.chain_details.some((item2) => Number(item2.chain_id) === chainId)
|
|
7476
7422
|
).map((item) => {
|
|
7477
7423
|
const chain = item.chain_details.find(
|
|
7478
7424
|
(item2) => Number(item2.chain_id) === chainId
|
|
7479
7425
|
);
|
|
7480
|
-
const swapToken = swapTokenInfos.find(
|
|
7481
|
-
(swapItem) => swapItem.symbol === item.token
|
|
7482
|
-
);
|
|
7483
7426
|
return {
|
|
7484
7427
|
symbol: item.token,
|
|
7485
7428
|
// if contract_address is not exist, use nativeTokenAddress to place holder
|
|
7486
7429
|
address: chain?.contract_address || types.nativeTokenAddress,
|
|
7487
7430
|
/** chain decimals */
|
|
7488
7431
|
decimals: chain?.decimals,
|
|
7489
|
-
// chain_decimals: chain?.decimals,
|
|
7490
7432
|
/** token decimals */
|
|
7491
7433
|
token_decimal: item?.decimals,
|
|
7492
7434
|
precision: item.decimals,
|
|
@@ -7498,31 +7440,20 @@ function formatChains({
|
|
|
7498
7440
|
discount_factor: item.discount_factor,
|
|
7499
7441
|
haircut: item.haircut,
|
|
7500
7442
|
user_max_qty: item.user_max_qty,
|
|
7501
|
-
is_collateral: item.is_collateral
|
|
7502
|
-
// if source token is swap token, and usdc is swap token, set swap_enable to true
|
|
7503
|
-
swap_enable: !!swapToken?.swap_enable && usdcSwapToken?.swap_enable
|
|
7443
|
+
is_collateral: item.is_collateral
|
|
7504
7444
|
};
|
|
7505
7445
|
});
|
|
7506
|
-
const swapTokens = usdcSwapToken?.swap_enable ? swapTokenInfos?.filter((item) => {
|
|
7507
|
-
return !tokenInfos?.some((token) => token.symbol === item.symbol);
|
|
7508
|
-
}) : [];
|
|
7509
7446
|
const _chain = {
|
|
7510
7447
|
network_infos,
|
|
7511
|
-
token_infos:
|
|
7448
|
+
token_infos: tokenInfos
|
|
7512
7449
|
};
|
|
7513
7450
|
if (typeof filter === "function") {
|
|
7514
7451
|
if (!filter(_chain)) continue;
|
|
7515
7452
|
}
|
|
7516
7453
|
chains.push(_chain);
|
|
7517
7454
|
}
|
|
7518
|
-
if (typeof
|
|
7519
|
-
return
|
|
7520
|
-
chains,
|
|
7521
|
-
chainInfos,
|
|
7522
|
-
tokenChains,
|
|
7523
|
-
swapChains,
|
|
7524
|
-
mainnet
|
|
7525
|
-
});
|
|
7455
|
+
if (typeof resolveChains === "function") {
|
|
7456
|
+
return resolveChains(chains);
|
|
7526
7457
|
}
|
|
7527
7458
|
return chains;
|
|
7528
7459
|
}
|
|
@@ -7770,128 +7701,32 @@ var useWithdraw = (options) => {
|
|
|
7770
7701
|
};
|
|
7771
7702
|
};
|
|
7772
7703
|
var useDeposit = (options) => {
|
|
7773
|
-
const networkId = useConfig("networkId");
|
|
7774
|
-
const [balanceRevalidating, setBalanceRevalidating] = React2.useState(false);
|
|
7775
|
-
const [allowanceRevalidating, setAllowanceRevalidating] = React2.useState(false);
|
|
7776
|
-
const [_, { findByChainId }] = useChains(void 0);
|
|
7777
7704
|
const [quantity, setQuantity] = React2.useState("");
|
|
7778
|
-
const [depositFee, setDepositFee] = React2.useState(0n);
|
|
7779
|
-
const [depositFeeRevalidating, setDepositFeeRevalidating] = React2.useState(false);
|
|
7780
|
-
const [balance, setBalance] = React2.useState("0");
|
|
7781
|
-
const [allowance, setAllowance] = React2.useState("0");
|
|
7782
|
-
const balanceRef = React2.useRef("");
|
|
7783
|
-
const currentAddressRef = React2.useRef();
|
|
7784
7705
|
const { account: account9, state } = useAccount();
|
|
7785
7706
|
const { track: track2 } = useTrack();
|
|
7786
|
-
const
|
|
7787
|
-
const getBalanceListener = React2.useRef();
|
|
7788
|
-
const targetChain = React2.useMemo(() => {
|
|
7789
|
-
let chain;
|
|
7790
|
-
if (networkId === "testnet") {
|
|
7791
|
-
chain = findByChainId(
|
|
7792
|
-
utils.isTestnet(options.srcChainId) ? options.srcChainId : types.ARBITRUM_TESTNET_CHAINID
|
|
7793
|
-
);
|
|
7794
|
-
} else {
|
|
7795
|
-
chain = findByChainId(options.srcChainId);
|
|
7796
|
-
if (!chain?.network_infos?.bridgeless) {
|
|
7797
|
-
chain = findByChainId(types.ARBITRUM_MAINNET_CHAINID);
|
|
7798
|
-
}
|
|
7799
|
-
}
|
|
7800
|
-
return chain;
|
|
7801
|
-
}, [networkId, findByChainId, options.srcChainId]);
|
|
7707
|
+
const targetChain = useTargetChain(options.srcChainId);
|
|
7802
7708
|
const dst = React2.useMemo(() => {
|
|
7803
|
-
const
|
|
7804
|
-
|
|
7709
|
+
const symbol = options.dstToken || "USDC";
|
|
7710
|
+
const targetToken = targetChain?.token_infos.find(
|
|
7711
|
+
(token) => token.symbol === symbol
|
|
7805
7712
|
);
|
|
7806
7713
|
return {
|
|
7807
|
-
symbol
|
|
7808
|
-
address:
|
|
7809
|
-
decimals:
|
|
7714
|
+
symbol,
|
|
7715
|
+
address: targetToken?.address,
|
|
7716
|
+
decimals: targetToken?.decimals,
|
|
7810
7717
|
chainId: targetChain?.network_infos.chain_id,
|
|
7811
7718
|
network: targetChain?.network_infos.shortName
|
|
7812
7719
|
};
|
|
7813
|
-
}, [targetChain]);
|
|
7720
|
+
}, [targetChain, options.dstToken]);
|
|
7814
7721
|
const isNativeToken = React2.useMemo(
|
|
7815
|
-
() => types.isNativeTokenChecker(options.address
|
|
7722
|
+
() => types.isNativeTokenChecker(options.address),
|
|
7816
7723
|
[options.address]
|
|
7817
7724
|
);
|
|
7818
|
-
const fetchBalanceHandler = React2.useCallback(
|
|
7819
|
-
async (address, decimals, token) => {
|
|
7820
|
-
let balance2;
|
|
7821
|
-
try {
|
|
7822
|
-
if (address && types.isNativeTokenChecker(address)) {
|
|
7823
|
-
balance2 = await account9.assetsManager.getNativeBalance({
|
|
7824
|
-
decimals
|
|
7825
|
-
});
|
|
7826
|
-
} else {
|
|
7827
|
-
balance2 = await account9.assetsManager.getBalance(address, {
|
|
7828
|
-
decimals
|
|
7829
|
-
});
|
|
7830
|
-
}
|
|
7831
|
-
} catch (err) {
|
|
7832
|
-
if (ignoreBalanceError({
|
|
7833
|
-
// TODO: use token params instead of options.srcToken
|
|
7834
|
-
token: token || options.srcToken,
|
|
7835
|
-
chainNamespace: account9.walletAdapter?.chainNamespace,
|
|
7836
|
-
err
|
|
7837
|
-
})) {
|
|
7838
|
-
return "0";
|
|
7839
|
-
}
|
|
7840
|
-
throw err;
|
|
7841
|
-
}
|
|
7842
|
-
return balance2;
|
|
7843
|
-
},
|
|
7844
|
-
[options.srcToken, account9]
|
|
7845
|
-
);
|
|
7846
|
-
const fetchBalances = React2.useCallback(async (tokens) => {
|
|
7847
|
-
const tasks = [];
|
|
7848
|
-
for (const token of tokens) {
|
|
7849
|
-
tasks.push(
|
|
7850
|
-
fetchBalanceHandler(token.address, token?.decimals, token.symbol)
|
|
7851
|
-
);
|
|
7852
|
-
}
|
|
7853
|
-
const results = await Promise.allSettled(tasks);
|
|
7854
|
-
const balances = {};
|
|
7855
|
-
for (const [index, balance2] of results.entries()) {
|
|
7856
|
-
if (balance2.status === "fulfilled") {
|
|
7857
|
-
balances[tokens[index].symbol] = balance2.value;
|
|
7858
|
-
}
|
|
7859
|
-
}
|
|
7860
|
-
return balances;
|
|
7861
|
-
}, []);
|
|
7862
|
-
const getAllowance = async (inputs) => {
|
|
7863
|
-
const { address, vaultAddress: vaultAddress2, decimals } = inputs;
|
|
7864
|
-
const key = `${address}-${vaultAddress2}`;
|
|
7865
|
-
if (prevAddress.current === key) return;
|
|
7866
|
-
if (!address || !vaultAddress2) return;
|
|
7867
|
-
if (types.isNativeTokenChecker(address)) return;
|
|
7868
|
-
prevAddress.current = key;
|
|
7869
|
-
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7870
|
-
address,
|
|
7871
|
-
vaultAddress: vaultAddress2,
|
|
7872
|
-
decimals
|
|
7873
|
-
});
|
|
7874
|
-
setAllowance(allowance2);
|
|
7875
|
-
return allowance2;
|
|
7876
|
-
};
|
|
7877
|
-
const getAllowanceByDefaultAddress = async (inputs) => {
|
|
7878
|
-
const { address, decimals } = inputs;
|
|
7879
|
-
if (prevAddress.current === address) return;
|
|
7880
|
-
if (!address || types.isNativeTokenChecker(address)) return;
|
|
7881
|
-
prevAddress.current = address;
|
|
7882
|
-
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7883
|
-
address,
|
|
7884
|
-
decimals,
|
|
7885
|
-
vaultAddress
|
|
7886
|
-
});
|
|
7887
|
-
setAllowance(allowance2);
|
|
7888
|
-
return allowance2;
|
|
7889
|
-
};
|
|
7890
7725
|
const vaultAddress = React2.useMemo(() => {
|
|
7891
|
-
if (dst
|
|
7726
|
+
if (dst?.chainId !== options.srcChainId) {
|
|
7892
7727
|
return options.crossChainRouteAddress;
|
|
7893
7728
|
}
|
|
7894
|
-
if (options.srcToken !==
|
|
7729
|
+
if (options.srcToken !== options.dstToken) {
|
|
7895
7730
|
return options.depositorAddress;
|
|
7896
7731
|
}
|
|
7897
7732
|
return targetChain?.network_infos.vault_address;
|
|
@@ -7904,103 +7739,43 @@ var useDeposit = (options) => {
|
|
|
7904
7739
|
options.depositorAddress,
|
|
7905
7740
|
targetChain
|
|
7906
7741
|
]);
|
|
7907
|
-
const
|
|
7908
|
-
|
|
7909
|
-
|
|
7910
|
-
|
|
7911
|
-
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
account9.walletAdapter.formatUnits(types.MaxUint256, options.decimals)
|
|
7929
|
-
);
|
|
7930
|
-
return;
|
|
7931
|
-
}
|
|
7932
|
-
if (vaultAddress && options.address) {
|
|
7933
|
-
queryAllowance({
|
|
7934
|
-
address: options.address,
|
|
7935
|
-
decimals: options.decimals,
|
|
7936
|
-
vaultAddress
|
|
7937
|
-
});
|
|
7938
|
-
} else {
|
|
7939
|
-
getAllowanceByDefaultAddress({
|
|
7940
|
-
address: options.address,
|
|
7941
|
-
decimals: options.decimals
|
|
7942
|
-
});
|
|
7943
|
-
}
|
|
7944
|
-
}, [
|
|
7945
|
-
state.status,
|
|
7946
|
-
options.address,
|
|
7947
|
-
options.decimals,
|
|
7948
|
-
account9.address,
|
|
7949
|
-
vaultAddress
|
|
7950
|
-
]);
|
|
7951
|
-
const updateAllowanceWhenTxSuccess = React2.useCallback(
|
|
7952
|
-
(txHash) => {
|
|
7953
|
-
return account9.walletAdapter?.pollTransactionReceiptWithBackoff(txHash).then((receipt) => {
|
|
7954
|
-
if (receipt.status === 1) {
|
|
7955
|
-
account9.assetsManager.getAllowance({
|
|
7956
|
-
address: options.address,
|
|
7957
|
-
decimals: options.decimals,
|
|
7958
|
-
vaultAddress
|
|
7959
|
-
}).then((allowance2) => {
|
|
7960
|
-
setAllowance(allowance2);
|
|
7961
|
-
});
|
|
7962
|
-
}
|
|
7963
|
-
});
|
|
7964
|
-
},
|
|
7965
|
-
[account9, options.address, options.decimals, vaultAddress]
|
|
7966
|
-
);
|
|
7967
|
-
const enquireAllowance = React2.useCallback(async () => {
|
|
7968
|
-
if (isNativeToken) {
|
|
7969
|
-
return;
|
|
7970
|
-
}
|
|
7971
|
-
if (!options.address) {
|
|
7972
|
-
throw new Error("address is required");
|
|
7973
|
-
}
|
|
7974
|
-
const _allowance = await account9.assetsManager.getAllowance({
|
|
7975
|
-
address: options.address,
|
|
7976
|
-
vaultAddress,
|
|
7977
|
-
decimals: options.decimals
|
|
7978
|
-
});
|
|
7979
|
-
setAllowance(_allowance);
|
|
7980
|
-
if (new utils.Decimal(quantity).greaterThan(_allowance)) {
|
|
7981
|
-
throw new types.SDKError("Insufficient allowance");
|
|
7982
|
-
}
|
|
7983
|
-
return _allowance;
|
|
7984
|
-
}, [
|
|
7985
|
-
account9,
|
|
7986
|
-
options.address,
|
|
7987
|
-
options.decimals,
|
|
7742
|
+
const {
|
|
7743
|
+
balance,
|
|
7744
|
+
balanceRevalidating,
|
|
7745
|
+
fetchBalance,
|
|
7746
|
+
fetchBalances,
|
|
7747
|
+
setBalance
|
|
7748
|
+
} = useBalance({
|
|
7749
|
+
address: options.address,
|
|
7750
|
+
decimals: options.decimals,
|
|
7751
|
+
srcToken: options.srcToken,
|
|
7752
|
+
account: account9,
|
|
7753
|
+
status: state.status
|
|
7754
|
+
});
|
|
7755
|
+
const {
|
|
7756
|
+
allowance,
|
|
7757
|
+
allowanceRevalidating,
|
|
7758
|
+
updateAllowanceWhenTxSuccess,
|
|
7759
|
+
enquireAllowance
|
|
7760
|
+
} = useAllowance({
|
|
7761
|
+
address: options.address,
|
|
7762
|
+
decimals: options.decimals,
|
|
7988
7763
|
vaultAddress,
|
|
7764
|
+
account: account9,
|
|
7765
|
+
status: state.status,
|
|
7989
7766
|
quantity,
|
|
7990
|
-
|
|
7991
|
-
|
|
7992
|
-
const
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
|
|
7999
|
-
|
|
8000
|
-
|
|
8001
|
-
|
|
8002
|
-
[]
|
|
8003
|
-
);
|
|
7767
|
+
chainId: dst?.chainId
|
|
7768
|
+
});
|
|
7769
|
+
const { depositFee, depositFeeRevalidating } = useDepositFee({
|
|
7770
|
+
quantity,
|
|
7771
|
+
account: account9,
|
|
7772
|
+
targetChain,
|
|
7773
|
+
decimals: options.decimals,
|
|
7774
|
+
dstToken: options.dstToken,
|
|
7775
|
+
vaultAddress,
|
|
7776
|
+
isNativeToken,
|
|
7777
|
+
dst
|
|
7778
|
+
});
|
|
8004
7779
|
const resetApprove = React2.useCallback(
|
|
8005
7780
|
async (tokenAddress, decimal, vaultAddress2) => {
|
|
8006
7781
|
const result = await account9.assetsManager.approve({
|
|
@@ -8009,20 +7784,9 @@ var useDeposit = (options) => {
|
|
|
8009
7784
|
vaultAddress: vaultAddress2,
|
|
8010
7785
|
decimals: decimal
|
|
8011
7786
|
});
|
|
8012
|
-
|
|
8013
|
-
result.hash
|
|
8014
|
-
);
|
|
8015
|
-
if (txResult && txResult.status === 1) {
|
|
8016
|
-
account9.assetsManager.getAllowance({
|
|
8017
|
-
address: tokenAddress,
|
|
8018
|
-
decimals: decimal,
|
|
8019
|
-
vaultAddress: vaultAddress2
|
|
8020
|
-
}).then((allowance2) => {
|
|
8021
|
-
setAllowance(allowance2);
|
|
8022
|
-
});
|
|
8023
|
-
}
|
|
7787
|
+
await updateAllowanceWhenTxSuccess(result.hash);
|
|
8024
7788
|
},
|
|
8025
|
-
[]
|
|
7789
|
+
[account9, updateAllowanceWhenTxSuccess]
|
|
8026
7790
|
);
|
|
8027
7791
|
const approve = React2.useCallback(
|
|
8028
7792
|
async (amount) => {
|
|
@@ -8059,7 +7823,6 @@ var useDeposit = (options) => {
|
|
|
8059
7823
|
options.decimals,
|
|
8060
7824
|
vaultAddress,
|
|
8061
7825
|
updateAllowanceWhenTxSuccess,
|
|
8062
|
-
checkIfChainTokenNeedRestApprove,
|
|
8063
7826
|
resetApprove
|
|
8064
7827
|
]
|
|
8065
7828
|
);
|
|
@@ -8105,104 +7868,287 @@ var useDeposit = (options) => {
|
|
|
8105
7868
|
isNativeToken,
|
|
8106
7869
|
vaultAddress
|
|
8107
7870
|
]);
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
7871
|
+
return {
|
|
7872
|
+
balance,
|
|
7873
|
+
allowance,
|
|
7874
|
+
/** deposit fee, unit: wei */
|
|
7875
|
+
depositFee,
|
|
7876
|
+
balanceRevalidating,
|
|
7877
|
+
allowanceRevalidating,
|
|
7878
|
+
depositFeeRevalidating,
|
|
7879
|
+
isNativeToken,
|
|
7880
|
+
dst,
|
|
7881
|
+
targetChain,
|
|
7882
|
+
/** input quantiy */
|
|
7883
|
+
quantity,
|
|
7884
|
+
/** set input quantity */
|
|
7885
|
+
setQuantity,
|
|
7886
|
+
approve,
|
|
7887
|
+
deposit,
|
|
7888
|
+
fetchBalance,
|
|
7889
|
+
fetchBalances
|
|
7890
|
+
};
|
|
7891
|
+
};
|
|
7892
|
+
function useBalance(options) {
|
|
7893
|
+
const { srcToken, address, decimals, account: account9, status } = options;
|
|
7894
|
+
const [balance, setBalance] = React2.useState("0");
|
|
7895
|
+
const fetchBalance = React2.useCallback(
|
|
7896
|
+
async (address2, decimals2) => {
|
|
8118
7897
|
try {
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
7898
|
+
if (types.isNativeTokenChecker(address2)) {
|
|
7899
|
+
return account9.assetsManager.getNativeBalance({
|
|
7900
|
+
decimals: decimals2
|
|
7901
|
+
});
|
|
7902
|
+
}
|
|
7903
|
+
return account9.assetsManager.getBalance(address2, {
|
|
7904
|
+
decimals: decimals2
|
|
7905
|
+
});
|
|
8126
7906
|
} catch (err) {
|
|
8127
|
-
if (
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
7907
|
+
if (ignoreBalanceError({
|
|
7908
|
+
chainNamespace: account9.walletAdapter?.chainNamespace,
|
|
7909
|
+
err
|
|
7910
|
+
})) {
|
|
7911
|
+
return "0";
|
|
8132
7912
|
}
|
|
7913
|
+
throw err;
|
|
8133
7914
|
}
|
|
8134
|
-
},
|
|
7915
|
+
},
|
|
7916
|
+
[srcToken, account9]
|
|
7917
|
+
);
|
|
7918
|
+
const fetchBalances = React2.useCallback(
|
|
7919
|
+
async (tokens) => {
|
|
7920
|
+
return account9.assetsManager.getBalances(tokens);
|
|
7921
|
+
},
|
|
7922
|
+
[account9]
|
|
7923
|
+
);
|
|
7924
|
+
const key = React2.useMemo(() => {
|
|
7925
|
+
if (!address || status < types.AccountStatusEnum.Connected) {
|
|
7926
|
+
return null;
|
|
7927
|
+
}
|
|
7928
|
+
return ["balance", address, decimals];
|
|
7929
|
+
}, [status, address, decimals]);
|
|
7930
|
+
const fetcher4 = React2.useCallback(async () => {
|
|
7931
|
+
if (!address) {
|
|
7932
|
+
return "0";
|
|
7933
|
+
}
|
|
7934
|
+
const balance2 = await fetchBalance(address, decimals);
|
|
7935
|
+
return balance2;
|
|
7936
|
+
}, [address, decimals, fetchBalance]);
|
|
7937
|
+
const refreshInterval = React2.useMemo(() => {
|
|
7938
|
+
return account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
|
|
7939
|
+
}, [account9]);
|
|
7940
|
+
const { data: swrBalance, isLoading: balanceRevalidating } = useSWR5__namespace.default(
|
|
7941
|
+
key,
|
|
7942
|
+
fetcher4,
|
|
7943
|
+
{
|
|
7944
|
+
revalidateOnFocus: true,
|
|
7945
|
+
refreshInterval,
|
|
7946
|
+
errorRetryCount: 10
|
|
7947
|
+
}
|
|
7948
|
+
);
|
|
7949
|
+
React2.useEffect(() => {
|
|
7950
|
+
if (swrBalance !== void 0) {
|
|
7951
|
+
setBalance(swrBalance || "0");
|
|
7952
|
+
}
|
|
7953
|
+
}, [swrBalance]);
|
|
7954
|
+
return {
|
|
7955
|
+
balance,
|
|
7956
|
+
balanceRevalidating,
|
|
7957
|
+
setBalance,
|
|
7958
|
+
fetchBalance,
|
|
7959
|
+
fetchBalances
|
|
8135
7960
|
};
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
7961
|
+
}
|
|
7962
|
+
function useAllowance(options) {
|
|
7963
|
+
const {
|
|
7964
|
+
address,
|
|
7965
|
+
decimals,
|
|
7966
|
+
vaultAddress,
|
|
7967
|
+
account: account9,
|
|
7968
|
+
status,
|
|
7969
|
+
quantity,
|
|
7970
|
+
chainId
|
|
7971
|
+
} = options;
|
|
7972
|
+
const [allowance, setAllowance] = React2.useState("0");
|
|
7973
|
+
const fetchAllowance = React2.useCallback(
|
|
7974
|
+
async (options2) => {
|
|
7975
|
+
const { address: address2, decimals: decimals2, vaultAddress: vaultAddress2 } = options2;
|
|
7976
|
+
if (!address2 || !decimals2 || !vaultAddress2) {
|
|
7977
|
+
return "0";
|
|
7978
|
+
}
|
|
7979
|
+
if (types.isNativeTokenChecker(address2) || account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana) {
|
|
7980
|
+
return account9.walletAdapter?.formatUnits(types.MaxUint256, decimals2);
|
|
7981
|
+
}
|
|
7982
|
+
const allowance2 = await account9.assetsManager.getAllowance({
|
|
7983
|
+
address: address2,
|
|
7984
|
+
vaultAddress: vaultAddress2,
|
|
7985
|
+
decimals: decimals2
|
|
8144
7986
|
});
|
|
7987
|
+
return allowance2;
|
|
8145
7988
|
},
|
|
8146
|
-
[account9
|
|
7989
|
+
[account9]
|
|
8147
7990
|
);
|
|
8148
|
-
const
|
|
8149
|
-
if (
|
|
8150
|
-
|
|
8151
|
-
setDepositFeeRevalidating(false);
|
|
8152
|
-
return;
|
|
7991
|
+
const key = React2.useMemo(() => {
|
|
7992
|
+
if (!address || !decimals || !vaultAddress || status < types.AccountStatusEnum.Connected) {
|
|
7993
|
+
return null;
|
|
8153
7994
|
}
|
|
8154
|
-
|
|
8155
|
-
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8164
|
-
|
|
8165
|
-
|
|
8166
|
-
|
|
8167
|
-
|
|
7995
|
+
return ["allowance", address, vaultAddress, decimals];
|
|
7996
|
+
}, [status, address, vaultAddress, decimals, account9]);
|
|
7997
|
+
const refreshInterval = React2.useMemo(() => {
|
|
7998
|
+
return account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
|
|
7999
|
+
}, [account9, chainId]);
|
|
8000
|
+
const fetcher4 = React2.useCallback(async () => {
|
|
8001
|
+
return fetchAllowance({ address, decimals, vaultAddress });
|
|
8002
|
+
}, [address, decimals, vaultAddress, fetchAllowance]);
|
|
8003
|
+
const {
|
|
8004
|
+
data: swrAllowance,
|
|
8005
|
+
isLoading: allowanceRevalidating,
|
|
8006
|
+
mutate: mutateAllowance
|
|
8007
|
+
} = useSWR5__namespace.default(key, fetcher4, {
|
|
8008
|
+
revalidateOnFocus: true,
|
|
8009
|
+
refreshInterval,
|
|
8010
|
+
errorRetryCount: 10
|
|
8011
|
+
});
|
|
8168
8012
|
React2.useEffect(() => {
|
|
8169
|
-
if (
|
|
8170
|
-
|
|
8013
|
+
if (swrAllowance !== void 0) {
|
|
8014
|
+
setAllowance(swrAllowance || "0");
|
|
8171
8015
|
}
|
|
8172
|
-
|
|
8173
|
-
|
|
8174
|
-
|
|
8175
|
-
|
|
8176
|
-
|
|
8177
|
-
|
|
8178
|
-
|
|
8179
|
-
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8016
|
+
}, [swrAllowance]);
|
|
8017
|
+
const updateAllowanceWhenTxSuccess = React2.useCallback(
|
|
8018
|
+
(txHash) => {
|
|
8019
|
+
return account9.walletAdapter?.pollTransactionReceiptWithBackoff(txHash).then((receipt) => {
|
|
8020
|
+
if (receipt.status === 1) {
|
|
8021
|
+
mutateAllowance();
|
|
8022
|
+
}
|
|
8023
|
+
});
|
|
8024
|
+
},
|
|
8025
|
+
[account9]
|
|
8026
|
+
);
|
|
8027
|
+
const enquireAllowance = React2.useCallback(async () => {
|
|
8028
|
+
const _allowance = await fetchAllowance({
|
|
8029
|
+
address,
|
|
8030
|
+
decimals,
|
|
8031
|
+
vaultAddress
|
|
8032
|
+
});
|
|
8033
|
+
setAllowance(_allowance);
|
|
8034
|
+
if (new utils.Decimal(quantity).greaterThan(_allowance)) {
|
|
8035
|
+
throw new types.SDKError("Insufficient allowance");
|
|
8036
|
+
}
|
|
8037
|
+
return _allowance;
|
|
8038
|
+
}, [account9, address, decimals, vaultAddress, quantity]);
|
|
8183
8039
|
return {
|
|
8184
|
-
/** orderly support chain dst */
|
|
8185
|
-
dst,
|
|
8186
|
-
balance,
|
|
8187
8040
|
allowance,
|
|
8188
|
-
isNativeToken,
|
|
8189
|
-
balanceRevalidating,
|
|
8190
8041
|
allowanceRevalidating,
|
|
8191
|
-
|
|
8192
|
-
|
|
8193
|
-
/** orderly deposit fee, unit: wei */
|
|
8194
|
-
depositFee,
|
|
8195
|
-
/** enquiring depositFee status on chain */
|
|
8196
|
-
depositFeeRevalidating,
|
|
8197
|
-
approve,
|
|
8198
|
-
deposit,
|
|
8199
|
-
fetchBalance: fetchBalanceHandler,
|
|
8200
|
-
fetchBalances,
|
|
8201
|
-
/** set input quantity */
|
|
8202
|
-
setQuantity,
|
|
8203
|
-
targetChain
|
|
8042
|
+
updateAllowanceWhenTxSuccess,
|
|
8043
|
+
enquireAllowance
|
|
8204
8044
|
};
|
|
8205
|
-
}
|
|
8045
|
+
}
|
|
8046
|
+
function useDepositFee(options) {
|
|
8047
|
+
const {
|
|
8048
|
+
quantity,
|
|
8049
|
+
account: account9,
|
|
8050
|
+
targetChain,
|
|
8051
|
+
decimals,
|
|
8052
|
+
dstToken,
|
|
8053
|
+
vaultAddress,
|
|
8054
|
+
isNativeToken,
|
|
8055
|
+
dst
|
|
8056
|
+
} = options;
|
|
8057
|
+
const getDepositFee = React2.useCallback(
|
|
8058
|
+
async (quantity2) => {
|
|
8059
|
+
if (!quantity2 || Number(quantity2) === 0 || isNaN(Number(quantity2))) {
|
|
8060
|
+
return 0n;
|
|
8061
|
+
}
|
|
8062
|
+
const depositFee2 = await account9.assetsManager.getDepositFee({
|
|
8063
|
+
amount: quantity2,
|
|
8064
|
+
chain: targetChain?.network_infos,
|
|
8065
|
+
decimals,
|
|
8066
|
+
token: dstToken,
|
|
8067
|
+
// TODO: when swap deposit, dstToken address is not same as src token address
|
|
8068
|
+
address: dst?.address
|
|
8069
|
+
});
|
|
8070
|
+
let estimatedGasFee = 0n;
|
|
8071
|
+
try {
|
|
8072
|
+
const inputs = {
|
|
8073
|
+
amount: quantity2,
|
|
8074
|
+
fee: depositFee2,
|
|
8075
|
+
decimals,
|
|
8076
|
+
token: dstToken,
|
|
8077
|
+
address: dst?.address,
|
|
8078
|
+
vaultAddress
|
|
8079
|
+
};
|
|
8080
|
+
estimatedGasFee = isNativeToken ? await account9.assetsManager.estimateNativeDepositGasFee(inputs) : await account9.assetsManager.estimateDepositGasFee(inputs);
|
|
8081
|
+
} catch (error) {
|
|
8082
|
+
estimatedGasFee = 0n;
|
|
8083
|
+
}
|
|
8084
|
+
return depositFee2 + estimatedGasFee;
|
|
8085
|
+
},
|
|
8086
|
+
[
|
|
8087
|
+
account9,
|
|
8088
|
+
targetChain,
|
|
8089
|
+
decimals,
|
|
8090
|
+
dstToken,
|
|
8091
|
+
dst?.address,
|
|
8092
|
+
vaultAddress,
|
|
8093
|
+
isNativeToken,
|
|
8094
|
+
dst
|
|
8095
|
+
]
|
|
8096
|
+
);
|
|
8097
|
+
const key = React2.useMemo(() => {
|
|
8098
|
+
if (!dst?.address || !decimals || !vaultAddress || !dstToken || !quantity || !targetChain?.network_infos?.chain_id) {
|
|
8099
|
+
return null;
|
|
8100
|
+
}
|
|
8101
|
+
return [
|
|
8102
|
+
"depositFee",
|
|
8103
|
+
dst?.address,
|
|
8104
|
+
vaultAddress,
|
|
8105
|
+
dstToken,
|
|
8106
|
+
decimals,
|
|
8107
|
+
targetChain?.network_infos?.chain_id,
|
|
8108
|
+
quantity
|
|
8109
|
+
];
|
|
8110
|
+
}, [quantity, targetChain, decimals, dstToken, dst, vaultAddress]);
|
|
8111
|
+
const fetcher4 = React2.useCallback(async () => {
|
|
8112
|
+
const res = await getDepositFee(quantity);
|
|
8113
|
+
return res;
|
|
8114
|
+
}, [getDepositFee, quantity]);
|
|
8115
|
+
const {
|
|
8116
|
+
data,
|
|
8117
|
+
isValidating: depositFeeRevalidating,
|
|
8118
|
+
mutate: mutateDepositFee
|
|
8119
|
+
} = useSWR5__namespace.default(key, fetcher4, {
|
|
8120
|
+
revalidateOnFocus: true
|
|
8121
|
+
});
|
|
8122
|
+
const depositFee = React2.useMemo(() => {
|
|
8123
|
+
const fee = data ?? 0n;
|
|
8124
|
+
return BigInt(
|
|
8125
|
+
new utils.Decimal(fee.toString()).mul(types.DEPOSIT_FEE_RATE).toFixed(0, utils.Decimal.ROUND_UP).toString()
|
|
8126
|
+
);
|
|
8127
|
+
}, [data]);
|
|
8128
|
+
return { depositFee, depositFeeRevalidating, mutateDepositFee };
|
|
8129
|
+
}
|
|
8130
|
+
function useTargetChain(srcChainId) {
|
|
8131
|
+
const networkId = useConfig("networkId");
|
|
8132
|
+
const [_, { findByChainId }] = useChains(void 0);
|
|
8133
|
+
const targetChain = React2.useMemo(() => {
|
|
8134
|
+
let chain;
|
|
8135
|
+
if (networkId === "testnet") {
|
|
8136
|
+
chain = findByChainId(
|
|
8137
|
+
utils.isTestnet(srcChainId) ? srcChainId : types.ARBITRUM_TESTNET_CHAINID
|
|
8138
|
+
);
|
|
8139
|
+
} else {
|
|
8140
|
+
chain = findByChainId(srcChainId);
|
|
8141
|
+
if (!chain?.network_infos?.bridgeless) {
|
|
8142
|
+
chain = findByChainId(types.ARBITRUM_MAINNET_CHAINID);
|
|
8143
|
+
}
|
|
8144
|
+
}
|
|
8145
|
+
return chain;
|
|
8146
|
+
}, [networkId, findByChainId, srcChainId]);
|
|
8147
|
+
return targetChain;
|
|
8148
|
+
}
|
|
8149
|
+
function checkIfChainTokenNeedRestApprove(chainId, token) {
|
|
8150
|
+
return chainId === types.ETHEREUM_MAINNET_CHAINID && token === "USDT";
|
|
8151
|
+
}
|
|
8206
8152
|
function ignoreBalanceError(options) {
|
|
8207
8153
|
const { chainNamespace, err } = options;
|
|
8208
8154
|
return chainNamespace === types.ChainNamespace.solana && err?.name === "TokenAccountNotFoundError";
|
|
@@ -8500,7 +8446,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8500
8446
|
}
|
|
8501
8447
|
let fieldChanges = {};
|
|
8502
8448
|
filteredKeys.forEach((getKey, key) => {
|
|
8503
|
-
|
|
8449
|
+
useSWR5.mutate(
|
|
8504
8450
|
useSWRInfinite.unstable_serialize((index, prevData) => [
|
|
8505
8451
|
getKey(index, prevData),
|
|
8506
8452
|
state.accountId
|
|
@@ -8565,7 +8511,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8565
8511
|
onMessage: (data) => {
|
|
8566
8512
|
const { symbol, leverage } = data?.accountDetail?.symbolLeverage || {};
|
|
8567
8513
|
if (symbol && leverage) {
|
|
8568
|
-
|
|
8514
|
+
useSWR5.mutate(
|
|
8569
8515
|
key,
|
|
8570
8516
|
(prevPositions) => {
|
|
8571
8517
|
if (prevPositions?.rows?.length) {
|
|
@@ -8595,7 +8541,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
8595
8541
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
8596
8542
|
onMessage: (data) => {
|
|
8597
8543
|
const { positions: nextPositions } = data;
|
|
8598
|
-
|
|
8544
|
+
useSWR5.mutate(
|
|
8599
8545
|
key,
|
|
8600
8546
|
(prevPositions) => {
|
|
8601
8547
|
if (!!prevPositions) {
|
|
@@ -11444,7 +11390,6 @@ var OrderlyConfigProvider = (props) => {
|
|
|
11444
11390
|
const {
|
|
11445
11391
|
configStore,
|
|
11446
11392
|
keyStore,
|
|
11447
|
-
// getWalletAdapter,
|
|
11448
11393
|
walletAdapters,
|
|
11449
11394
|
brokerId,
|
|
11450
11395
|
brokerName,
|
|
@@ -11453,7 +11398,6 @@ var OrderlyConfigProvider = (props) => {
|
|
|
11453
11398
|
chainFilter,
|
|
11454
11399
|
customChains,
|
|
11455
11400
|
enableSwapDeposit = false,
|
|
11456
|
-
chainTransformer,
|
|
11457
11401
|
dataAdapter,
|
|
11458
11402
|
notification,
|
|
11459
11403
|
amplitudeConfig,
|
|
@@ -11529,7 +11473,6 @@ var OrderlyConfigProvider = (props) => {
|
|
|
11529
11473
|
enableSwapDeposit,
|
|
11530
11474
|
defaultOrderbookTickSizes,
|
|
11531
11475
|
defaultOrderbookSymbolDepths,
|
|
11532
|
-
chainTransformer,
|
|
11533
11476
|
dataAdapter,
|
|
11534
11477
|
notification,
|
|
11535
11478
|
amplitudeConfig,
|
|
@@ -11547,7 +11490,6 @@ var OrderlyConfigProvider = (props) => {
|
|
|
11547
11490
|
defaultOrderbookSymbolDepths,
|
|
11548
11491
|
dataAdapter,
|
|
11549
11492
|
notification,
|
|
11550
|
-
chainTransformer,
|
|
11551
11493
|
amplitudeConfig,
|
|
11552
11494
|
orderMetadata
|
|
11553
11495
|
]);
|
|
@@ -19042,18 +18984,18 @@ var useGetEstLiqPrice = (props) => {
|
|
|
19042
18984
|
}, [estLiqPrice, markPrice, side]);
|
|
19043
18985
|
};
|
|
19044
18986
|
|
|
19045
|
-
exports.swr =
|
|
18987
|
+
exports.swr = useSWR5__namespace;
|
|
19046
18988
|
Object.defineProperty(exports, "unstable_serialize", {
|
|
19047
18989
|
enumerable: true,
|
|
19048
|
-
get: function () { return
|
|
18990
|
+
get: function () { return useSWR5.unstable_serialize; }
|
|
19049
18991
|
});
|
|
19050
18992
|
Object.defineProperty(exports, "useSWR", {
|
|
19051
18993
|
enumerable: true,
|
|
19052
|
-
get: function () { return
|
|
18994
|
+
get: function () { return useSWR5__namespace.default; }
|
|
19053
18995
|
});
|
|
19054
18996
|
Object.defineProperty(exports, "useSWRConfig", {
|
|
19055
18997
|
enumerable: true,
|
|
19056
|
-
get: function () { return
|
|
18998
|
+
get: function () { return useSWR5.useSWRConfig; }
|
|
19057
18999
|
});
|
|
19058
19000
|
Object.defineProperty(exports, "useConstant", {
|
|
19059
19001
|
enumerable: true,
|