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

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
@@ -19043,6 +19043,7 @@ const NETWORK_COLORS = {
19043
19043
  [types$1.ChainId.BLAST]: '#fcfc034d',
19044
19044
  [types$1.ChainId.CROSSFI]: '#7c80844d',
19045
19045
  [types$1.ChainId.MONAD_TESTNET]: '#836EF94d',
19046
+ [types$1.ChainId.SOL]: '#836EF94d',
19046
19047
  [types$1.ChainId.SONIC]: '#fb9a4c4d',
19047
19048
  [types$1.ChainId.BERACHAIN]: '#783e244d',
19048
19049
  };
@@ -69452,27 +69453,58 @@ const zapInputTokens = {
69452
69453
  ],
69453
69454
  };
69454
69455
 
69456
+ function usePreTGEList() {
69457
+ var _a, _b;
69458
+ const SDKConfig = useSDKConfig();
69459
+ const realTime = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.realTimeApi;
69460
+ const apiUrl = (_b = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _b === void 0 ? void 0 : _b.apiV2;
69461
+ return useQuery({
69462
+ queryKey: [QUERY_KEYS.PRE_TGE_LIST],
69463
+ queryFn: () => getPreTGEList(realTime, apiUrl),
69464
+ staleTime: Infinity,
69465
+ refetchInterval: 300000, // 5 min
69466
+ refetchOnWindowFocus: false,
69467
+ });
69468
+ }
69469
+ const getPreTGEList = (apiRealTimeURL, apiUrl) => __awaiter$9(void 0, void 0, void 0, function* () {
69470
+ try {
69471
+ const response = yield axios.get(`${apiRealTimeURL}/utils/pre-tge-bonds`);
69472
+ return response.data;
69473
+ }
69474
+ catch (e) {
69475
+ reportError$1({
69476
+ apiUrl,
69477
+ error: e,
69478
+ extraInfo: { type: 'getPreTGEList', e },
69479
+ });
69480
+ return [];
69481
+ }
69482
+ });
69483
+
69455
69484
  function useTokenList() {
69456
69485
  const { data: bondList } = useBondsList();
69486
+ const { data: preTGEList } = usePreTGEList();
69457
69487
  const SDKConfig = useSDKConfig();
69458
69488
  const chains = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.chains;
69459
69489
  const apiUrl = useURLByEnvironment('apiV2');
69460
69490
  return useQuery({
69461
- queryKey: [QUERY_KEYS.TOKEN_LIST],
69462
- queryFn: () => getTokenList(chains, apiUrl, bondList),
69491
+ queryKey: [QUERY_KEYS.TOKEN_LIST, bondList === null || bondList === void 0 ? void 0 : bondList.length, preTGEList === null || preTGEList === void 0 ? void 0 : preTGEList.length],
69492
+ queryFn: () => getTokenList(chains, apiUrl, bondList, preTGEList),
69463
69493
  refetchOnMount: false,
69464
69494
  refetchOnWindowFocus: false,
69465
- enabled: !!SDKConfig.chains && SDKConfig.chains.length > 0 && !!bondList,
69495
+ enabled: !!bondList && !!preTGEList,
69466
69496
  });
69467
69497
  }
69468
- const getTokenList = (chains, apiUrl, bondList) => __awaiter$9(void 0, void 0, void 0, function* () {
69498
+ const getTokenList = (chains, apiUrl, bondList, preTGEList) => __awaiter$9(void 0, void 0, void 0, function* () {
69499
+ console.time('tokenList');
69500
+ const mergedList = [...bondList, ...preTGEList];
69469
69501
  const tokenList = chains.reduce((acc, chain2) => {
69470
69502
  var _a;
69471
69503
  const chain = chain2;
69472
69504
  if (!acc[chain]) {
69473
69505
  acc[chain] = {};
69474
69506
  }
69475
- bondList === null || bondList === void 0 ? void 0 : bondList.forEach((bond) => {
69507
+ mergedList === null || mergedList === void 0 ? void 0 : mergedList.forEach((bond) => {
69476
69508
  var _a, _b, _c, _d;
69477
69509
  if (bond.chainId !== chain)
69478
69510
  return;
@@ -69497,6 +69529,7 @@ const getTokenList = (chains, apiUrl, bondList) => __awaiter$9(void 0, void 0, v
69497
69529
  });
69498
69530
  return acc;
69499
69531
  }, {});
69532
+ console.timeEnd('tokenList');
69500
69533
  return tokenList;
69501
69534
  });
69502
69535
 
@@ -69506,19 +69539,20 @@ function useTokenPrices() {
69506
69539
  const SDKConfig = useSDKConfig();
69507
69540
  const apiUrl = (_a = SDKConfig === null || SDKConfig === void 0 ? void 0 : SDKConfig.urls) === null || _a === void 0 ? void 0 : _a.apiV2;
69508
69541
  return useQuery({
69509
- queryKey: [QUERY_KEYS.TOKEN_PRICES],
69542
+ queryKey: [QUERY_KEYS.TOKEN_PRICES, Object.keys(tokenList || {}).length],
69510
69543
  queryFn: () => getTokenPrices(SDKConfig.chains, apiUrl, tokenList),
69511
69544
  refetchInterval: 60000, // 60 sec
69512
69545
  refetchOnMount: false,
69513
69546
  refetchOnWindowFocus: false,
69514
- enabled: !!SDKConfig.chains && SDKConfig.chains.length > 0 && !!tokenList,
69547
+ enabled: !!tokenList,
69515
69548
  });
69516
69549
  }
69517
69550
  const getTokenPrices = (chains, apiUrl, tokenList) => __awaiter$9(void 0, void 0, void 0, function* () {
69551
+ console.time('PriceGetter');
69552
+ console.log('PriceGetter starts');
69518
69553
  try {
69519
69554
  const promises = chains.map((chain) => __awaiter$9(void 0, void 0, void 0, function* () {
69520
69555
  try {
69521
- // Directly return the result of fetching prices, or handle any exceptions here
69522
69556
  return yield getAllTokenPrices(+chain, tokenList[chain], apiUrl);
69523
69557
  }
69524
69558
  catch (error) {
@@ -69532,13 +69566,15 @@ const getTokenPrices = (chains, apiUrl, tokenList) => __awaiter$9(void 0, void 0
69532
69566
  }
69533
69567
  }));
69534
69568
  const responses = yield Promise.allSettled(promises);
69535
- // Reduce fullfilled responses into a single Array
69536
- return responses.reduce((acc, result) => {
69569
+ // Combine the filtering and mapping into a single loop, avoiding dual mapping
69570
+ const flattenedPrices = responses.reduce((acc, result) => {
69537
69571
  if (result.status === 'fulfilled' && result.value) {
69538
69572
  acc.push(...result.value);
69539
69573
  }
69540
69574
  return acc;
69541
69575
  }, []);
69576
+ console.timeEnd('PriceGetter');
69577
+ return flattenedPrices;
69542
69578
  }
69543
69579
  catch (error) {
69544
69580
  reportError$1({
@@ -69653,7 +69689,7 @@ const getPriceGetterV3Call = (chain, token) => {
69653
69689
  const priceGetterAddress = PRICE_GETTER_ADDRESSES[chain];
69654
69690
  const wrapper = token.liquidityWrapper;
69655
69691
  if (!factory) {
69656
- console.log(`No default dex factory found for retrieving price for protocol ${protocol}. Please contact support.`);
69692
+ // console.log(`No default dex factory found for retrieving price for protocol ${protocol}. Please contact support.`)
69657
69693
  return;
69658
69694
  }
69659
69695
  const params = [address, protocol, factory];
@@ -79133,34 +79169,6 @@ var launchBondsABI_V2_2_0 = [
79133
79169
  }
79134
79170
  ];
79135
79171
 
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
79172
  function usePreTGEUserBonds() {
79165
79173
  var _a;
79166
79174
  const { data: preTGEList } = usePreTGEList();
@@ -82912,31 +82920,31 @@ function useBondsData() {
82912
82920
  const apiUrl = useURLByEnvironment('apiV2');
82913
82921
  const realTimeApiURL = useURLByEnvironment('realTimeApi');
82914
82922
  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],
82923
+ queryKey: [QUERY_KEYS.BONDS_DATA, bondList === null || bondList === void 0 ? void 0 : bondList.length, preTGEList === null || preTGEList === void 0 ? void 0 : preTGEList.length],
82916
82924
  queryFn: () => getBondsData(chains, bondList, preTGEList, realTimeApiURL, apiUrl, tokenPrices),
82917
82925
  refetchInterval: 20000, // i.e. 20 sec
82918
82926
  refetchOnWindowFocus: false,
82919
82927
  retry: 0,
82920
82928
  initialData: [],
82921
- enabled: !!tokenPrices && !!bondList && !!preTGEList,
82929
+ enabled: !!bondList && !!preTGEList,
82922
82930
  });
82923
82931
  }
82924
82932
  //TODO: move this function to utils once SOLANA code is merged
82925
82933
  const getBondsData = (chains, bondList, preTGEList, realTimeApiURL, apiUrl, tokenPrices) => __awaiter$9(void 0, void 0, void 0, function* () {
82926
82934
  var _a;
82927
- console.log('Started');
82935
+ console.log('BondsData Starts');
82928
82936
  try {
82929
- console.time('Calculate BondsData');
82937
+ console.time('BondsData');
82930
82938
  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
82939
  const [solBonds, evmResponse] = yield Promise.all([
82932
82940
  yield fetchBills(types$1.ChainId.SOL, solanaBondList, apiUrl, tokenPrices),
82933
82941
  yield axios.get(`${realTimeApiURL}/bonds`),
82934
82942
  ]);
82935
- console.timeEnd('Calculate BondsData');
82943
+ console.timeEnd('BondsData');
82936
82944
  return [...solBonds, ...evmResponse.data.bonds];
82937
82945
  }
82938
82946
  catch (_b) {
82939
- console.time('Fallback BondsData'); // Start debug timer
82947
+ console.time('Fallback BondsData');
82940
82948
  const billData = [];
82941
82949
  if (tokenPrices && bondList) {
82942
82950
  yield Promise.all([
@@ -82965,6 +82973,8 @@ const getBondsData = (chains, bondList, preTGEList, realTimeApiURL, apiUrl, toke
82965
82973
  });
82966
82974
  const fetchBills = (chainId, bills, apiUrl, tokenPrices) => __awaiter$9(void 0, void 0, void 0, function* () {
82967
82975
  var _a, _b;
82976
+ if (!tokenPrices)
82977
+ return [];
82968
82978
  try {
82969
82979
  if (chainId === types$1.ChainId.SOL) {
82970
82980
  const solanaCalls = [];
@@ -86778,12 +86788,19 @@ const BannerTestnet = ({ chainId }) => {
86778
86788
  const BondRowsWithTitle = ({ chain, bonds, showHotBonds }) => {
86779
86789
  const key = chain;
86780
86790
  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: {
86791
+ 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 }) }), isOpen && (bonds.length > 0 || chain === types$1.ChainId.SOL) && (jsxs(motion.div, { initial: { height: 0, overflow: 'hidden' }, animate: { height: 'fit-content', overflow: 'hidden', transitionEnd: { overflow: 'visible' } }, exit: { height: 0, overflow: 'hidden' }, sx: {
86782
86792
  position: 'relative',
86783
86793
  overflow: 'hidden',
86784
86794
  width: '100%',
86785
86795
  marginTop: '0px',
86786
- }, className: "bonds-card-container", children: [TESTNET_CHAINS.includes(chain) && jsx$2(BannerTestnet, { chainId: chain }), bonds === null || bonds === void 0 ? void 0 : bonds.map((bondFromMap, index) => {
86796
+ }, className: "bonds-card-container", children: [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) => {
86797
+ return (jsx$2(Skeleton, { animation: "waves", sx: {
86798
+ width: '100%',
86799
+ height: '70px',
86800
+ borderRadius: 'normal',
86801
+ mb: '5px',
86802
+ } }, `sol-shadow-${index}`));
86803
+ }) }, key)), TESTNET_CHAINS.includes(chain) && jsx$2(BannerTestnet, { chainId: chain }), bonds === null || bonds === void 0 ? void 0 : bonds.map((bondFromMap, index) => {
86787
86804
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
86788
86805
  if (bondFromMap.soldOut) {
86789
86806
  const bond = bondFromMap;
@@ -86815,12 +86832,11 @@ const BondRowsByChain = ({ bonds, hideTitles }) => {
86815
86832
  var _a;
86816
86833
  const SDKConfig = useSDKConfig();
86817
86834
  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
86835
  const groupedBonds = bonds.reduce((acc, bond) => {
86820
- const { chainId } = bond; // Extract chainId from the bond
86836
+ const { chainId } = bond;
86821
86837
  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
86838
+ acc[chainId] = [];
86839
+ acc[chainId].push(bond);
86824
86840
  return acc;
86825
86841
  }, {});
86826
86842
  return (jsx$2(Flex$1, { className: "bondrowsbychain", children: validatedChains === null || validatedChains === void 0 ? void 0 : validatedChains.map((chain) => {
@@ -87023,32 +87039,32 @@ const BuyAgainRow = () => {
87023
87039
  };
87024
87040
 
87025
87041
  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: {
87042
+ 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
87043
  width: '100%',
87028
87044
  height: '70px',
87029
87045
  borderRadius: 'normal',
87030
87046
  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: {
87047
+ } }, `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
87048
  width: '100%',
87033
87049
  height: '125px',
87034
87050
  borderRadius: 'normal',
87035
87051
  mb: '5px',
87036
- } }, index))) })] }));
87052
+ } }, `hot-card-shadow${index}`))) })] }));
87037
87053
  };
87038
87054
 
87039
87055
  const Bonds = () => {
87040
87056
  // Fetch data
87041
87057
  useHotBonds();
87042
87058
  const { favTokens } = useFavoriteTokens();
87043
- const { data: bondData } = useBondsData();
87059
+ const { data: bondData, refetch } = useBondsData();
87044
87060
  const { data: allBonds } = useBondsList();
87045
87061
  const { data: allPreBonds } = usePreTGEList();
87046
87062
  const { data: chainFilterOption, setChainFilterOption } = useChainFilterOption();
87047
87063
  const { data: tokenPrices } = useTokenPrices();
87048
- // const btc = tokenPrices?.find(
87049
- // (token) => token?.address?.toLowerCase() === '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599'.toLowerCase(),
87064
+ // const rtc = tokenPrices?.find(
87065
+ // (token) => token?.address?.toLowerCase() === '0x188b8e23CefFCA7a58e8C64C2a7A9771Ab3596A7'.toLowerCase(),
87050
87066
  // )
87051
- // console.log('btc: ', btc)
87067
+ // console.log('rtc: ', rtc)
87052
87068
  const SDKConfig = useSDKConfig();
87053
87069
  useEffect(() => {
87054
87070
  const hash = window.location.hash;
@@ -87133,6 +87149,13 @@ const Bonds = () => {
87133
87149
  const handleChangeFilterOption = useCallback((newOption) => {
87134
87150
  setFilterOption(newOption);
87135
87151
  }, []);
87152
+ useEffect(() => {
87153
+ if (tokenPrices && (tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length) > 0) {
87154
+ console.log('Refetching bonds');
87155
+ refetch();
87156
+ }
87157
+ /* eslint-disable react-hooks/exhaustive-deps */
87158
+ }, [tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.length, refetch]);
87136
87159
  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
87160
  width: '100%',
87138
87161
  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.4",
7
7
  "module": "dist/main.js",
8
8
  "type": "module",
9
9
  "types": "dist/main.d.ts",