@ape.swap/bonds-sdk 4.0.0-test.2 → 4.0.0-test.3

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/main.js CHANGED
@@ -69452,27 +69452,58 @@ const zapInputTokens = {
69452
69452
  ],
69453
69453
  };
69454
69454
 
69455
+ function usePreTGEList() {
69456
+ var _a, _b;
69457
+ const SDKConfig = useSDKConfig();
69458
+ const realTime = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.realTimeApi;
69459
+ const apiUrl = (_b = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _b === void 0 ? void 0 : _b.apiV2;
69460
+ return useQuery({
69461
+ queryKey: [QUERY_KEYS.PRE_TGE_LIST],
69462
+ queryFn: () => getPreTGEList(realTime, apiUrl),
69463
+ staleTime: Infinity,
69464
+ refetchInterval: 300000, // 5 min
69465
+ refetchOnWindowFocus: false,
69466
+ });
69467
+ }
69468
+ const getPreTGEList = (apiRealTimeURL, apiUrl) => __awaiter$9(void 0, void 0, void 0, function* () {
69469
+ try {
69470
+ const response = yield axios.get(`${apiRealTimeURL}/utils/pre-tge-bonds`);
69471
+ return response.data;
69472
+ }
69473
+ catch (e) {
69474
+ reportError$1({
69475
+ apiUrl,
69476
+ error: e,
69477
+ extraInfo: { type: 'getPreTGEList', e },
69478
+ });
69479
+ return [];
69480
+ }
69481
+ });
69482
+
69455
69483
  function useTokenList() {
69456
69484
  const { data: bondList } = useBondsList();
69485
+ const { data: preTGEList } = usePreTGEList();
69457
69486
  const SDKConfig = useSDKConfig();
69458
69487
  const chains = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.chains;
69459
69488
  const apiUrl = useURLByEnvironment('apiV2');
69460
69489
  return useQuery({
69461
- queryKey: [QUERY_KEYS.TOKEN_LIST],
69462
- queryFn: () => getTokenList(chains, apiUrl, bondList),
69490
+ queryKey: [QUERY_KEYS.TOKEN_LIST, bondList === null || bondList === void 0 ? void 0 : bondList.length, preTGEList === null || preTGEList === void 0 ? void 0 : preTGEList.length],
69491
+ queryFn: () => getTokenList(chains, apiUrl, bondList, preTGEList),
69463
69492
  refetchOnMount: false,
69464
69493
  refetchOnWindowFocus: false,
69465
- enabled: !!SDKConfig.chains && SDKConfig.chains.length > 0 && !!bondList,
69494
+ enabled: !!bondList && !!preTGEList,
69466
69495
  });
69467
69496
  }
69468
- const getTokenList = (chains, apiUrl, bondList) => __awaiter$9(void 0, void 0, void 0, function* () {
69497
+ const getTokenList = (chains, apiUrl, bondList, preTGEList) => __awaiter$9(void 0, void 0, void 0, function* () {
69498
+ console.time('tokenList');
69499
+ const mergedList = [...bondList, ...preTGEList];
69469
69500
  const tokenList = chains.reduce((acc, chain2) => {
69470
69501
  var _a;
69471
69502
  const chain = chain2;
69472
69503
  if (!acc[chain]) {
69473
69504
  acc[chain] = {};
69474
69505
  }
69475
- bondList === null || bondList === void 0 ? void 0 : bondList.forEach((bond) => {
69506
+ mergedList === null || mergedList === void 0 ? void 0 : mergedList.forEach((bond) => {
69476
69507
  var _a, _b, _c, _d;
69477
69508
  if (bond.chainId !== chain)
69478
69509
  return;
@@ -69497,6 +69528,7 @@ const getTokenList = (chains, apiUrl, bondList) => __awaiter$9(void 0, void 0, v
69497
69528
  });
69498
69529
  return acc;
69499
69530
  }, {});
69531
+ console.timeEnd('tokenList');
69500
69532
  return tokenList;
69501
69533
  });
69502
69534
 
@@ -69506,19 +69538,20 @@ function useTokenPrices() {
69506
69538
  const SDKConfig = useSDKConfig();
69507
69539
  const apiUrl = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.apiV2;
69508
69540
  return useQuery({
69509
- queryKey: [QUERY_KEYS.TOKEN_PRICES],
69541
+ queryKey: [QUERY_KEYS.TOKEN_PRICES, Object.keys(tokenList || {}).length],
69510
69542
  queryFn: () => getTokenPrices(SDKConfig.chains, apiUrl, tokenList),
69511
69543
  refetchInterval: 60000, // 60 sec
69512
69544
  refetchOnMount: false,
69513
69545
  refetchOnWindowFocus: false,
69514
- enabled: !!SDKConfig.chains && SDKConfig.chains.length > 0 && !!tokenList,
69546
+ enabled: !!tokenList,
69515
69547
  });
69516
69548
  }
69517
69549
  const getTokenPrices = (chains, apiUrl, tokenList) => __awaiter$9(void 0, void 0, void 0, function* () {
69550
+ console.time('PriceGetter');
69551
+ console.log('PriceGetter starts');
69518
69552
  try {
69519
69553
  const promises = chains.map((chain) => __awaiter$9(void 0, void 0, void 0, function* () {
69520
69554
  try {
69521
- // Directly return the result of fetching prices, or handle any exceptions here
69522
69555
  return yield getAllTokenPrices(+chain, tokenList[chain], apiUrl);
69523
69556
  }
69524
69557
  catch (error) {
@@ -69532,13 +69565,15 @@ const getTokenPrices = (chains, apiUrl, tokenList) => __awaiter$9(void 0, void 0
69532
69565
  }
69533
69566
  }));
69534
69567
  const responses = yield Promise.allSettled(promises);
69535
- // Reduce fullfilled responses into a single Array
69536
- return responses.reduce((acc, result) => {
69568
+ // Combine the filtering and mapping into a single loop, avoiding dual mapping
69569
+ const flattenedPrices = responses.reduce((acc, result) => {
69537
69570
  if (result.status === 'fulfilled' && result.value) {
69538
69571
  acc.push(...result.value);
69539
69572
  }
69540
69573
  return acc;
69541
69574
  }, []);
69575
+ console.timeEnd('PriceGetter');
69576
+ return flattenedPrices;
69542
69577
  }
69543
69578
  catch (error) {
69544
69579
  reportError$1({
@@ -69653,7 +69688,7 @@ const getPriceGetterV3Call = (chain, token) => {
69653
69688
  const priceGetterAddress = PRICE_GETTER_ADDRESSES[chain];
69654
69689
  const wrapper = token.liquidityWrapper;
69655
69690
  if (!factory) {
69656
- console.log(`No default dex factory found for retrieving price for protocol ${protocol}. Please contact support.`);
69691
+ // console.log(`No default dex factory found for retrieving price for protocol ${protocol}. Please contact support.`)
69657
69692
  return;
69658
69693
  }
69659
69694
  const params = [address, protocol, factory];
@@ -79133,34 +79168,6 @@ var launchBondsABI_V2_2_0 = [
79133
79168
  }
79134
79169
  ];
79135
79170
 
79136
- function usePreTGEList() {
79137
- var _a, _b;
79138
- const SDKConfig = useSDKConfig();
79139
- const realTime = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.realTimeApi;
79140
- const apiUrl = (_b = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _b === void 0 ? void 0 : _b.apiV2;
79141
- return useQuery({
79142
- queryKey: [QUERY_KEYS.PRE_TGE_LIST],
79143
- queryFn: () => getPreTGEList(realTime, apiUrl),
79144
- staleTime: Infinity,
79145
- refetchInterval: 300000, // 5 min
79146
- refetchOnWindowFocus: false,
79147
- });
79148
- }
79149
- const getPreTGEList = (apiRealTimeURL, apiUrl) => __awaiter$9(void 0, void 0, void 0, function* () {
79150
- try {
79151
- const response = yield axios.get(`${apiRealTimeURL}/utils/pre-tge-bonds`);
79152
- return response.data;
79153
- }
79154
- catch (e) {
79155
- reportError$1({
79156
- apiUrl,
79157
- error: e,
79158
- extraInfo: { type: 'getPreTGEList', e },
79159
- });
79160
- return [];
79161
- }
79162
- });
79163
-
79164
79171
  function usePreTGEUserBonds() {
79165
79172
  var _a;
79166
79173
  const { data: preTGEList } = usePreTGEList();
@@ -82912,31 +82919,31 @@ function useBondsData() {
82912
82919
  const apiUrl = useURLByEnvironment('apiV2');
82913
82920
  const realTimeApiURL = useURLByEnvironment('realTimeApi');
82914
82921
  return useQuery({
82915
- queryKey: [QUERY_KEYS.BONDS_DATA, tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length, bondList === null || bondList === void 0 ? void 0 : bondList.length, preTGEList === null || preTGEList === void 0 ? void 0 : preTGEList.length],
82922
+ queryKey: [QUERY_KEYS.BONDS_DATA, bondList === null || bondList === void 0 ? void 0 : bondList.length, preTGEList === null || preTGEList === void 0 ? void 0 : preTGEList.length],
82916
82923
  queryFn: () => getBondsData(chains, bondList, preTGEList, realTimeApiURL, apiUrl, tokenPrices),
82917
82924
  refetchInterval: 20000, // i.e. 20 sec
82918
82925
  refetchOnWindowFocus: false,
82919
82926
  retry: 0,
82920
82927
  initialData: [],
82921
- enabled: !!tokenPrices && !!bondList && !!preTGEList,
82928
+ enabled: !!bondList && !!preTGEList,
82922
82929
  });
82923
82930
  }
82924
82931
  //TODO: move this function to utils once SOLANA code is merged
82925
82932
  const getBondsData = (chains, bondList, preTGEList, realTimeApiURL, apiUrl, tokenPrices) => __awaiter$9(void 0, void 0, void 0, function* () {
82926
82933
  var _a;
82927
- console.log('Started');
82934
+ console.log('BondsData Starts');
82928
82935
  try {
82929
- console.time('Calculate BondsData');
82936
+ console.time('BondsData');
82930
82937
  const solanaBondList = (_a = bondList === null || bondList === void 0 ? void 0 : bondList.filter((bill) => !bill.soldOut && bill.chainId === types$1.ChainId.SOL)) !== null && _a !== void 0 ? _a : [];
82931
82938
  const [solBonds, evmResponse] = yield Promise.all([
82932
82939
  yield fetchBills(types$1.ChainId.SOL, solanaBondList, apiUrl, tokenPrices),
82933
82940
  yield axios.get(`${realTimeApiURL}/bonds`),
82934
82941
  ]);
82935
- console.timeEnd('Calculate BondsData');
82942
+ console.timeEnd('BondsData');
82936
82943
  return [...solBonds, ...evmResponse.data.bonds];
82937
82944
  }
82938
82945
  catch (_b) {
82939
- console.time('Fallback BondsData'); // Start debug timer
82946
+ console.time('Fallback BondsData');
82940
82947
  const billData = [];
82941
82948
  if (tokenPrices && bondList) {
82942
82949
  yield Promise.all([
@@ -82965,6 +82972,8 @@ const getBondsData = (chains, bondList, preTGEList, realTimeApiURL, apiUrl, toke
82965
82972
  });
82966
82973
  const fetchBills = (chainId, bills, apiUrl, tokenPrices) => __awaiter$9(void 0, void 0, void 0, function* () {
82967
82974
  var _a, _b;
82975
+ if (!tokenPrices)
82976
+ return [];
82968
82977
  try {
82969
82978
  if (chainId === types$1.ChainId.SOL) {
82970
82979
  const solanaCalls = [];
@@ -86778,7 +86787,7 @@ const BannerTestnet = ({ chainId }) => {
86778
86787
  const BondRowsWithTitle = ({ chain, bonds, showHotBonds }) => {
86779
86788
  const key = chain;
86780
86789
  const [isOpen, setIsOpen] = useState(true);
86781
- return (jsx$2(Flex$1, { className: "bondrowswithtitle", children: jsxs(AnimatePresence, { initial: false, children: [jsx$2(Flex$1, { onClick: () => setIsOpen(!isOpen), sx: { cursor: 'pointer' }, children: jsx$2(ChainTitle, { chain: chain, pt: '5px', hideTitles: bonds.length <= 0, isOpen: isOpen }) }), bonds.length > 0 && isOpen && (jsxs(motion.div, { initial: { height: 0, overflow: 'hidden' }, animate: { height: 'fit-content', overflow: 'hidden', transitionEnd: { overflow: 'visible' } }, exit: { height: 0, overflow: 'hidden' }, sx: {
86790
+ return (jsx$2(Flex$1, { className: "bondrowswithtitle", children: jsxs(AnimatePresence, { initial: false, children: [jsx$2(Flex$1, { onClick: () => setIsOpen(!isOpen), sx: { cursor: 'pointer' }, children: jsx$2(ChainTitle, { chain: chain, pt: '5px', hideTitles: bonds.length <= 0 && chain !== types$1.ChainId.SOL, isOpen: isOpen }) }), bonds.length > 0 && isOpen && (jsxs(motion.div, { initial: { height: 0, overflow: 'hidden' }, animate: { height: 'fit-content', overflow: 'hidden', transitionEnd: { overflow: 'visible' } }, exit: { height: 0, overflow: 'hidden' }, sx: {
86782
86791
  position: 'relative',
86783
86792
  overflow: 'hidden',
86784
86793
  width: '100%',
@@ -86808,19 +86817,25 @@ const BondRowsWithTitle = ({ chain, bonds, showHotBonds }) => {
86808
86817
  const remainingTokensString = getRemainingTokensString(bond);
86809
86818
  return (jsx$2(BondRow, { bondAddress: bondAddress, bondChain: bond.chainId, payoutToken: bond.earnToken, billType: bond.billType, tag: (_w = bond.tags) === null || _w === void 0 ? void 0 : _w[0], trueBondPrices: bond.trueBondPrices, minTier: bond === null || bond === void 0 ? void 0 : bond.minTier, vestingTermString: getVestingTermsString(bond), vestingCliffString: getVestingTermsTooltipString(bond), percentageAvailable: remainingPercentage(bond), remainingTokensString: remainingTokensString, projectURL: bond.projectLink, twitterURL: bond.twitter, auditURL: bond.audit }, `${bondAddress}-${bond.chainId}-${index}`));
86810
86819
  }
86811
- }), showHotBonds && (jsx$2(SwiperProvider, { children: jsx$2(HotBondCards, {}) }))] }, key))] }) }, key));
86820
+ }), showHotBonds && (jsx$2(SwiperProvider, { children: jsx$2(HotBondCards, {}) }))] }, key)), bonds.length <= 0 && chain === types$1.ChainId.SOL && (jsx$2(Flex$1, { sx: { width: '100%', flexDirection: 'column' }, className: "bonds-card-container", children: Array.from({ length: 3 }).map((_, index) => {
86821
+ return (jsx$2(Skeleton, { animation: "waves", sx: {
86822
+ width: '100%',
86823
+ height: '70px',
86824
+ borderRadius: 'normal',
86825
+ mb: '5px',
86826
+ } }, `sol-shadow-${index}`));
86827
+ }) }, key))] }) }, key));
86812
86828
  };
86813
86829
 
86814
86830
  const BondRowsByChain = ({ bonds, hideTitles }) => {
86815
86831
  var _a;
86816
86832
  const SDKConfig = useSDKConfig();
86817
86833
  const validatedChains = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.chains) === null || _a === void 0 ? void 0 : _a.filter((chain) => MAINNET_CHAINS.includes(chain));
86818
- // Group the bonds data by chainId using reduce
86819
86834
  const groupedBonds = bonds.reduce((acc, bond) => {
86820
- const { chainId } = bond; // Extract chainId from the bond
86835
+ const { chainId } = bond;
86821
86836
  if (!acc[chainId])
86822
- acc[chainId] = []; // Initialize the array if it doesn't exist
86823
- acc[chainId].push(bond); // Push the bond to its corresponding chainId group
86837
+ acc[chainId] = [];
86838
+ acc[chainId].push(bond);
86824
86839
  return acc;
86825
86840
  }, {});
86826
86841
  return (jsx$2(Flex$1, { className: "bondrowsbychain", children: validatedChains === null || validatedChains === void 0 ? void 0 : validatedChains.map((chain) => {
@@ -87023,32 +87038,32 @@ const BuyAgainRow = () => {
87023
87038
  };
87024
87039
 
87025
87040
  const LoadingSkeleton = () => {
87026
- return (jsxs(Flex$1, { sx: { width: '100%', flexDirection: 'column', mt: '35px' }, children: [Array.from({ length: 8 }).map((_, index) => (jsx$2(Skeleton, { animation: "waves", sx: {
87041
+ return (jsxs(Flex$1, { sx: { width: '100%', flexDirection: 'column', mt: '35px' }, children: [Array.from({ length: 6 }).map((_, index) => (jsx$2(Skeleton, { animation: "waves", sx: {
87027
87042
  width: '100%',
87028
87043
  height: '70px',
87029
87044
  borderRadius: 'normal',
87030
87045
  mb: '5px',
87031
- } }, index))), jsx$2(Flex$1, { sx: { width: '100%', gap: '15px', mt: '25px' }, children: Array.from({ length: 3 }).map((_, index) => (jsx$2(Skeleton, { animation: "waves", sx: {
87046
+ } }, `row-shadow-${index}`))), jsx$2(Flex$1, { sx: { width: '100%', gap: '15px', mt: '25px' }, children: Array.from({ length: 3 }).map((_, index) => (jsx$2(Skeleton, { animation: "waves", sx: {
87032
87047
  width: '100%',
87033
87048
  height: '125px',
87034
87049
  borderRadius: 'normal',
87035
87050
  mb: '5px',
87036
- } }, index))) })] }));
87051
+ } }, `hot-card-shadow${index}`))) })] }));
87037
87052
  };
87038
87053
 
87039
87054
  const Bonds = () => {
87040
87055
  // Fetch data
87041
87056
  useHotBonds();
87042
87057
  const { favTokens } = useFavoriteTokens();
87043
- const { data: bondData } = useBondsData();
87058
+ const { data: bondData, refetch } = useBondsData();
87044
87059
  const { data: allBonds } = useBondsList();
87045
87060
  const { data: allPreBonds } = usePreTGEList();
87046
87061
  const { data: chainFilterOption, setChainFilterOption } = useChainFilterOption();
87047
87062
  const { data: tokenPrices } = useTokenPrices();
87048
- // const btc = tokenPrices?.find(
87049
- // (token) => token?.address?.toLowerCase() === '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'.toLowerCase(),
87063
+ // const rtc = tokenPrices?.find(
87064
+ // (token) => token?.address?.toLowerCase() === '0x188b8e23CefFCA7a58e8C64C2a7A9771Ab3596A7'.toLowerCase(),
87050
87065
  // )
87051
- // console.log('btc: ', btc)
87066
+ // console.log('rtc: ', rtc)
87052
87067
  const SDKConfig = useSDKConfig();
87053
87068
  useEffect(() => {
87054
87069
  const hash = window.location.hash;
@@ -87133,6 +87148,13 @@ const Bonds = () => {
87133
87148
  const handleChangeFilterOption = useCallback((newOption) => {
87134
87149
  setFilterOption(newOption);
87135
87150
  }, []);
87151
+ useEffect(() => {
87152
+ if (tokenPrices && (tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length) > 0) {
87153
+ console.log('Refetching bonds');
87154
+ refetch();
87155
+ }
87156
+ /* eslint-disable react-hooks/exhaustive-deps */
87157
+ }, [tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length, refetch]);
87136
87158
  return (jsxs(Flex$1, { className: "bonds-container", children: [jsx$2(CheckUrl, {}), jsx$2(BondsMenu, { searchQuery: searchQuery, setSearchQuery: setSearchQuery, setChainFilterOption: setChainFilterOption, chainFilterOption: chainFilterOption !== null && chainFilterOption !== void 0 ? chainFilterOption : ['All Chains'], filterOptions: filterOptions, filterOption: filterOption, setFilterOption: handleChangeFilterOption, onSort: handleSortOptions }), SDKConfig.useHotBonds && !SDKConfig.bondPartner && jsx$2(BuyAgainRow, {}), (billsToRender === null || billsToRender === void 0 ? void 0 : billsToRender.length) > 0 ? (jsx$2(BondRowsByChain, { bonds: billsToRender, hideTitles: searchQuery !== '' })) : searchQuery ? (jsx$2(PlaceholderMonkey, { text: 'No results' })) : filterOption === 'FAVORITES' ? (jsxs(Flex$1, { sx: {
87137
87159
  width: '100%',
87138
87160
  height: '300px',
@@ -1,3 +1,4 @@
1
1
  import { ChainId, Token } from '@ape.swap/apeswap-lists';
2
2
  import { UseQueryResult } from '@tanstack/react-query';
3
- export default function useTokenList(): UseQueryResult<Record<ChainId, Record<string, Token>>>;
3
+ export type TokenList = Record<ChainId, Record<string, Token>>;
4
+ export default function useTokenList(): UseQueryResult<TokenList>;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Ape Bond SDK",
4
4
  "author": "Ape Bond",
5
5
  "license": "MIT",
6
- "version": "4.0.0-test.2",
6
+ "version": "4.0.0-test.3",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",