@ape.swap/bonds-sdk 1.0.354 → 1.0.355

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.
Files changed (36) hide show
  1. package/dist/components/BondModal/BondModal.js +1 -1
  2. package/dist/components/YourBonds/YourBonds.js +62 -43
  3. package/dist/components/YourBonds/fetchBillsUser.d.ts +3 -3
  4. package/dist/components/YourBonds/fetchBillsUser.js +4 -4
  5. package/dist/config/abi/erc20.json +117 -0
  6. package/dist/config/abi/price-getter-linea.json +1448 -0
  7. package/dist/config/abi/price-getter.json +1309 -0
  8. package/dist/hooks/PriceGetter/usePricesFromPriceGetter.d.ts +17 -0
  9. package/dist/hooks/PriceGetter/usePricesFromPriceGetter.js +205 -0
  10. package/dist/state/bills/cleanBillsData.d.ts +5 -0
  11. package/dist/state/bills/cleanBillsData.js +41 -0
  12. package/dist/state/bills/fetchBills.d.ts +4 -0
  13. package/dist/state/bills/fetchBills.js +61 -0
  14. package/dist/state/bills/fetchBillsCalls.d.ts +4 -0
  15. package/dist/state/bills/fetchBillsCalls.js +27 -0
  16. package/dist/state/bills/fetchBillsUser.d.ts +15 -0
  17. package/dist/state/bills/fetchBillsUser.js +171 -0
  18. package/dist/state/bills/getBillNftData.d.ts +9 -0
  19. package/dist/state/bills/getBillNftData.js +109 -0
  20. package/dist/state/bills/hooks.d.ts +4 -0
  21. package/dist/state/bills/hooks.js +142 -0
  22. package/dist/state/bills/index.d.ts +48 -0
  23. package/dist/state/bills/index.js +293 -0
  24. package/dist/state/bills/types.d.ts +168 -0
  25. package/dist/state/bills/types.js +1 -0
  26. package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.d.ts +4 -0
  27. package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.js +68 -0
  28. package/dist/state/tokenPrices/getAllTokenPrices.d.ts +5 -0
  29. package/dist/state/tokenPrices/getAllTokenPrices.js +288 -0
  30. package/dist/state/tokenPrices/useTokenPricesNew.d.ts +11 -0
  31. package/dist/state/tokenPrices/useTokenPricesNew.js +72 -0
  32. package/dist/types/bonds.d.ts +62 -0
  33. package/dist/types/dexFactories.d.ts +11 -0
  34. package/dist/types/dexFactories.js +2 -0
  35. package/dist/types/yourbonds.d.ts +4 -0
  36. package/package.json +1 -1
@@ -0,0 +1,168 @@
1
+ import { BillsConfig, BillVersion, ChainId, Token } from "../../enum/apeswaplists";
2
+ export interface UserBillNft {
3
+ image: string;
4
+ tokenId: string;
5
+ attributes: {
6
+ trait_type: string;
7
+ value: string;
8
+ }[];
9
+ }
10
+ export interface UserBill {
11
+ address: string;
12
+ id: string;
13
+ vesting: string;
14
+ payout: string;
15
+ totalPayout?: string;
16
+ truePricePaid: string;
17
+ lastBlockTimestamp: string;
18
+ pendingRewards: string;
19
+ billNftAddress: string;
20
+ nftData?: UserBillNft;
21
+ }
22
+ export interface Bills extends BillsConfig {
23
+ price?: string;
24
+ priceUsd?: string;
25
+ vestingTime?: string;
26
+ discount?: string;
27
+ currentDebt?: string;
28
+ currentFee?: string;
29
+ debtDecay?: string;
30
+ debtRatio?: string;
31
+ totalDebt?: string;
32
+ totalPayoutGiven?: string;
33
+ totalPrincipalBilled?: string;
34
+ controlVariable?: string;
35
+ minimumPrice?: string;
36
+ maxPayout?: string;
37
+ maxDebt?: string;
38
+ lpPriceUsd?: number;
39
+ earnTokenPrice?: number;
40
+ billNftAddress?: string;
41
+ userOwnedBillsData?: UserBill[];
42
+ userOwnedBillsNftData?: UserBillNft[];
43
+ maxTotalPayout?: string;
44
+ lpPrice?: number;
45
+ maxPayoutTokens?: string;
46
+ startVestingTimestamp?: string;
47
+ totalBonusRewards?: string;
48
+ featuredURLS?: string[];
49
+ partnersURLS?: string[];
50
+ }
51
+ export interface CleanedBondsState {
52
+ index: number;
53
+ cmcId: number | null;
54
+ chainId: ChainId;
55
+ vestingTerm?: number;
56
+ principalTokenName: string;
57
+ principalToken: string;
58
+ principalTokenDecimals: number;
59
+ payoutTokenName: string;
60
+ payoutToken: string;
61
+ payoutTokenDecimals: number;
62
+ soldOut?: boolean;
63
+ tags?: string[];
64
+ contractAddress: string;
65
+ billNftAddress: string;
66
+ inactive?: boolean;
67
+ showcaseTokenName?: string;
68
+ twitter?: string;
69
+ projectLink?: string;
70
+ audit?: string;
71
+ shortDescription?: string;
72
+ fullDescription?: string;
73
+ lpToken?: Token;
74
+ billType?: string;
75
+ billVersion?: BillVersion;
76
+ featuredURLS?: string[];
77
+ partnersURLS?: string[];
78
+ discount?: number;
79
+ principalTokenPrice?: string;
80
+ payoutTokenPrice?: string;
81
+ tokensRemaining?: string;
82
+ maxTotalPayout?: string;
83
+ trueBillPrice?: string;
84
+ maxPayout?: string;
85
+ totalPayoutGiven?: string;
86
+ isHotBond?: boolean;
87
+ userOwnedBillsData?: UserBill[];
88
+ userOwnedBillsNftData?: UserBillNft[];
89
+ }
90
+ export interface BondsDataResponse {
91
+ index: number;
92
+ cmcId?: number;
93
+ label: string;
94
+ chainId: ChainId;
95
+ type: string;
96
+ principalToken: string;
97
+ principalTokenName: string;
98
+ principalTokenDecimals: number;
99
+ payoutToken: string;
100
+ payoutTokenName: string;
101
+ payoutTokenDecimals: number;
102
+ discount: number;
103
+ billAddress: string;
104
+ billNftAddress: string;
105
+ initTime: number;
106
+ soldOut: boolean;
107
+ inactive: boolean;
108
+ trueBillPrice: string;
109
+ maxTotalPayout: string;
110
+ totalPayoutGiven: string;
111
+ maxPayout: string;
112
+ tokensRemaining: string;
113
+ showcaseToken: string;
114
+ showcaseTokenName: string;
115
+ vestingTerm: number;
116
+ principalTokenPrice: string;
117
+ payoutTokenPrice: string;
118
+ priceUsd: string;
119
+ tags?: string[];
120
+ arr: string;
121
+ }
122
+ export interface ServerBondsCacheData {
123
+ bondApiData: {
124
+ fetchTimestamp: number;
125
+ bondList: CleanedBondsState[] | null;
126
+ };
127
+ historicalPrices: Partial<Record<string, {
128
+ fetchTimestamp: number;
129
+ priceList: HistoricalPrices[] | null;
130
+ }>>;
131
+ hotBonds: {
132
+ fetchTimestamp: number;
133
+ hotBondsList: string[] | null;
134
+ };
135
+ homepageStats: {
136
+ fetchTimestamp: number;
137
+ };
138
+ }
139
+ export interface CMCResponse {
140
+ data: {
141
+ id: number;
142
+ name: string;
143
+ symbol: string;
144
+ quotes: Quote[];
145
+ };
146
+ }
147
+ export interface Quote {
148
+ time_open: string;
149
+ time_close: string;
150
+ time_high: string;
151
+ time_low: string;
152
+ quote: {
153
+ USD: {
154
+ open: number;
155
+ high: number;
156
+ low: number;
157
+ close: number;
158
+ volume: number;
159
+ market_cap: number;
160
+ timestamp: string;
161
+ };
162
+ };
163
+ }
164
+ export interface HistoricalPrices {
165
+ timestamp: string;
166
+ open: number;
167
+ close: number;
168
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import { TokenPrices } from './useTokenPricesNew';
2
+ import { ChainId } from '../../enum/apeswaplists';
3
+ declare const fetchTokenPricesForMultipleChains: (chains?: ChainId[]) => Promise<TokenPrices[]>;
4
+ export default fetchTokenPricesForMultipleChains;
@@ -0,0 +1,68 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import getAllTokenPrices from './getAllTokenPrices';
38
+ import axios from 'axios';
39
+ import { APESWAP_LISTS_URL } from '../../config/constants/lists';
40
+ var fetchTokenPricesForMultipleChains = function (chains) {
41
+ if (chains === void 0) { chains = []; }
42
+ return __awaiter(void 0, void 0, void 0, function () {
43
+ var prices, response, tokensList, index, chain, all, successfulPromises, successfulPrices;
44
+ return __generator(this, function (_a) {
45
+ switch (_a.label) {
46
+ case 0:
47
+ prices = [];
48
+ return [4 /*yield*/, axios.get("".concat(APESWAP_LISTS_URL, "/config/tokens.json"))];
49
+ case 1:
50
+ response = _a.sent();
51
+ tokensList = response.data;
52
+ for (index = 0; index < chains.length; index++) {
53
+ chain = chains[index];
54
+ prices.push(getAllTokenPrices(chain, tokensList));
55
+ }
56
+ return [4 /*yield*/, Promise.allSettled(prices)
57
+ // Keep only successfully fulfilled promises and discard the rest
58
+ ];
59
+ case 2:
60
+ all = _a.sent();
61
+ successfulPromises = all === null || all === void 0 ? void 0 : all.filter(function (result) { return result.status === 'fulfilled'; });
62
+ successfulPrices = successfulPromises.map(function (result) { return result.value; });
63
+ return [2 /*return*/, successfulPrices.flat()];
64
+ }
65
+ });
66
+ });
67
+ };
68
+ export default fetchTokenPricesForMultipleChains;
@@ -0,0 +1,5 @@
1
+ import { TokenPrices } from './useTokenPricesNew';
2
+ import { ChainId, Token } from '../../enum/apeswaplists';
3
+ declare const getAllTokenPrices: (chainId: ChainId, tokens: Record<string, Token>) => Promise<TokenPrices[]>;
4
+ export default getAllTokenPrices;
5
+ export declare const getDexScreenerChainName: (chainId: ChainId) => string | undefined;
@@ -0,0 +1,288 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
57
+ import { ABOND_ADDRESSES } from '../../config/constants/addresses';
58
+ import { getTokenPricesV2FromPriceGetter } from '../../hooks/PriceGetter/usePricesFromPriceGetter';
59
+ import { getBalanceNumber } from '../../utils/getBalanceNumber';
60
+ import { cloneDeep } from 'lodash';
61
+ import multicall from '../../utils/multicall';
62
+ import ERC20ABI from '../../config/abi/erc20.json';
63
+ import axios from 'axios';
64
+ import { ChainId, LiquidityDex } from '../../enum/apeswaplists';
65
+ var getAllTokenPrices = function (chainId, tokens) { return __awaiter(void 0, void 0, void 0, function () {
66
+ var dexScreenerTokensToCall, filterTokensToCall, filterLpTokensToCall, arrayFilterTokens, abondIndex, parsedDexscreenerTokens, dexScreenerResults, tokenResults, lpTokenResults, parsedTokenResults, parsedLpTokenResults;
67
+ return __generator(this, function (_a) {
68
+ switch (_a.label) {
69
+ case 0:
70
+ dexScreenerTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
71
+ var _b;
72
+ var token = _a[1];
73
+ return ((_b = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _b === void 0 ? void 0 : _b[chainId]) === LiquidityDex.External;
74
+ }));
75
+ filterTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
76
+ var _b, _c;
77
+ var token = _a[1];
78
+ return ((token === null || token === void 0 ? void 0 : token.active) &&
79
+ !(token === null || token === void 0 ? void 0 : token.lpToken) &&
80
+ token.address[chainId] &&
81
+ ((_b = token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) &&
82
+ ((_c = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _c === void 0 ? void 0 : _c[chainId]) !== LiquidityDex.External);
83
+ }));
84
+ filterLpTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
85
+ var _b, _c;
86
+ var token = _a[1];
87
+ return ((token === null || token === void 0 ? void 0 : token.active) &&
88
+ (token === null || token === void 0 ? void 0 : token.lpToken) &&
89
+ token.address[chainId] &&
90
+ ((_b = token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) &&
91
+ ((_c = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _c === void 0 ? void 0 : _c[chainId]) !== LiquidityDex.External);
92
+ }));
93
+ arrayFilterTokens = Object.values(filterTokensToCall);
94
+ abondIndex = arrayFilterTokens.findIndex(function (token) { var _a, _b; return ((_a = token.address[chainId]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = ABOND_ADDRESSES[chainId]) === null || _b === void 0 ? void 0 : _b.toLowerCase()); });
95
+ parsedDexscreenerTokens = Object.values(dexScreenerTokensToCall).map(function (token) {
96
+ var _a, _b, _c, _d;
97
+ return __assign(__assign({}, token), { address: (_a = token.address[chainId]) !== null && _a !== void 0 ? _a : '', decimals: (_c = (_b = token === null || token === void 0 ? void 0 : token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) !== null && _c !== void 0 ? _c : 18, lpToken: (_d = token.lpToken) !== null && _d !== void 0 ? _d : false });
98
+ });
99
+ if (chainId === ChainId.BSC_TESTNET) {
100
+ return [2 /*return*/, arrayFilterTokens.map(function (token) {
101
+ var _a, _b;
102
+ return {
103
+ symbol: token.symbol,
104
+ address: token.address[chainId],
105
+ price: 1,
106
+ decimals: (_b = (_a = token.decimals) === null || _a === void 0 ? void 0 : _a[chainId]) !== null && _b !== void 0 ? _b : undefined,
107
+ chainId: chainId,
108
+ };
109
+ })];
110
+ }
111
+ return [4 /*yield*/, getBatchTokenPriceWithDexscreener({ chainId: chainId, tokens: parsedDexscreenerTokens })];
112
+ case 1:
113
+ dexScreenerResults = _a.sent();
114
+ return [4 /*yield*/, getTokenPricesV2FromPriceGetter(filterTokensToCall, chainId, false)];
115
+ case 2:
116
+ tokenResults = _a.sent();
117
+ return [4 /*yield*/, getTokenPricesV2FromPriceGetter(filterLpTokensToCall, chainId, true)];
118
+ case 3:
119
+ lpTokenResults = _a.sent();
120
+ parsedTokenResults = arrayFilterTokens.map(function (token, i) {
121
+ var _a, _b, _c, _d;
122
+ var price = token.symbol.toLowerCase() === 'veabond'
123
+ ? getBalanceNumber((_a = tokenResults === null || tokenResults === void 0 ? void 0 : tokenResults[abondIndex]) === null || _a === void 0 ? void 0 : _a.toString(), 18)
124
+ : getBalanceNumber((_b = tokenResults === null || tokenResults === void 0 ? void 0 : tokenResults[i]) === null || _b === void 0 ? void 0 : _b.toString(), 18);
125
+ return {
126
+ symbol: token.symbol,
127
+ address: token.address[chainId],
128
+ price: price !== null && price !== void 0 ? price : undefined,
129
+ decimals: (_d = (_c = token.decimals) === null || _c === void 0 ? void 0 : _c[chainId]) !== null && _d !== void 0 ? _d : undefined,
130
+ chainId: chainId,
131
+ };
132
+ });
133
+ parsedLpTokenResults = Object.values(filterLpTokensToCall).map(function (token, i) {
134
+ var _a, _b;
135
+ return {
136
+ symbol: token.symbol,
137
+ address: token.address[chainId],
138
+ price: getBalanceNumber(lpTokenResults[i].toString(), 18),
139
+ decimals: (_b = (_a = token.decimals) === null || _a === void 0 ? void 0 : _a[chainId]) !== null && _b !== void 0 ? _b : undefined,
140
+ chainId: chainId,
141
+ };
142
+ });
143
+ return [2 /*return*/, __spreadArray(__spreadArray(__spreadArray([], parsedTokenResults, true), parsedLpTokenResults, true), dexScreenerResults, true)];
144
+ }
145
+ });
146
+ }); };
147
+ export default getAllTokenPrices;
148
+ var getBatchTokenPriceWithDexscreener = function (params) { return __awaiter(void 0, void 0, void 0, function () {
149
+ var chainId, tokens, tokensCopy, baseURL_1, totalSupplies_1, chains_1, chainName_1, calls, result, error_1;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0:
153
+ chainId = params.chainId, tokens = params.tokens;
154
+ tokensCopy = cloneDeep(tokens);
155
+ _a.label = 1;
156
+ case 1:
157
+ _a.trys.push([1, 3, , 4]);
158
+ baseURL_1 = 'https://api.dexscreener.com/latest/dex';
159
+ totalSupplies_1 = [];
160
+ chains_1 = [];
161
+ chainName_1 = getDexScreenerChainName(chainId);
162
+ calls = tokensCopy.map(function (token) { return __awaiter(void 0, void 0, void 0, function () {
163
+ var symbol, lpToken, totalSupply, decimals, endpoint, calls_1, supply, _a, url, response, error_2;
164
+ return __generator(this, function (_b) {
165
+ switch (_b.label) {
166
+ case 0:
167
+ symbol = token.symbol, lpToken = token.lpToken, totalSupply = token.totalSupply, decimals = token.decimals;
168
+ if (['USDT', 'USDC'].includes(symbol)) {
169
+ chains_1.push('injective');
170
+ return [2 /*return*/, {
171
+ pairs: [
172
+ {
173
+ chainId: chainName_1,
174
+ baseToken: {
175
+ address: token.address,
176
+ },
177
+ liquidity: {
178
+ usd: 1,
179
+ },
180
+ priceUsd: 1,
181
+ },
182
+ ],
183
+ }];
184
+ }
185
+ if (symbol.toLowerCase() === 'inj' || symbol.toLowerCase() === 'winj') {
186
+ token.address = 'inj';
187
+ }
188
+ if (!chainName_1) {
189
+ console.log("Chain ".concat(chainId, " is not supported by dexscreener."));
190
+ return [2 /*return*/, null];
191
+ }
192
+ else {
193
+ chains_1.push(chainName_1);
194
+ }
195
+ if (!lpToken) return [3 /*break*/, 4];
196
+ if (!!totalSupply) return [3 /*break*/, 2];
197
+ calls_1 = [
198
+ {
199
+ address: token.address,
200
+ name: 'totalSupply',
201
+ },
202
+ ];
203
+ _a = getBalanceNumber;
204
+ return [4 /*yield*/, multicall(chainId, ERC20ABI, calls_1)];
205
+ case 1:
206
+ supply = _a.apply(void 0, [(_b.sent())[0], decimals]);
207
+ totalSupplies_1.push(supply);
208
+ return [3 /*break*/, 3];
209
+ case 2:
210
+ totalSupplies_1.push(totalSupply);
211
+ _b.label = 3;
212
+ case 3:
213
+ endpoint = "pairs/".concat(chainName_1);
214
+ return [3 /*break*/, 5];
215
+ case 4:
216
+ endpoint = "tokens";
217
+ _b.label = 5;
218
+ case 5:
219
+ url = "".concat(baseURL_1, "/").concat(endpoint, "/").concat(token.address);
220
+ _b.label = 6;
221
+ case 6:
222
+ _b.trys.push([6, 8, , 9]);
223
+ return [4 /*yield*/, axios.get(url)];
224
+ case 7:
225
+ response = _b.sent();
226
+ return [2 /*return*/, response.data];
227
+ case 8:
228
+ error_2 = _b.sent();
229
+ console.log("Failed to fetch data for token ".concat(token.address, ": ").concat(error_2));
230
+ return [2 /*return*/, null];
231
+ case 9: return [2 /*return*/];
232
+ }
233
+ });
234
+ }); });
235
+ return [4 /*yield*/, Promise.all(calls)];
236
+ case 2:
237
+ result = _a.sent();
238
+ return [2 /*return*/, result.map(function (response, index) {
239
+ var _a;
240
+ if (!response || !response.pairs) {
241
+ return __assign(__assign({}, tokensCopy === null || tokensCopy === void 0 ? void 0 : tokensCopy[index]), { price: undefined, chainId: chainId });
242
+ }
243
+ var supply = totalSupplies_1[index];
244
+ var token = tokensCopy[index];
245
+ var price;
246
+ try {
247
+ if (token.lpToken) {
248
+ var liquidity = response.pair.liquidity.usd;
249
+ price = liquidity / supply;
250
+ }
251
+ else {
252
+ var pairs = response.pairs;
253
+ price = (_a = pairs
254
+ .filter(function (pair) {
255
+ return pair.chainId === chainName_1 && pair.baseToken.address.toLowerCase() === token.address.toLowerCase();
256
+ })
257
+ .sort(function (a, b) { var _a, _b; return ((_a = b === null || b === void 0 ? void 0 : b.liquidity) === null || _a === void 0 ? void 0 : _a.usd) - ((_b = a === null || a === void 0 ? void 0 : a.liquidity) === null || _b === void 0 ? void 0 : _b.usd); })[0]) === null || _a === void 0 ? void 0 : _a.priceUsd;
258
+ }
259
+ }
260
+ catch (error) {
261
+ price = undefined;
262
+ }
263
+ return __assign(__assign({}, tokensCopy === null || tokensCopy === void 0 ? void 0 : tokensCopy[index]), { address: token.address === 'inj' ? '0x4569348D39cc38F4d6a1180573Df73B7b03251d9' : token.address, chainId: chainId, price: parseFloat(price !== null && price !== void 0 ? price : '0') });
264
+ })];
265
+ case 3:
266
+ error_1 = _a.sent();
267
+ console.log("Failed to get price from dexscreener for chain ".concat(chainId, "."));
268
+ return [2 /*return*/, tokensCopy.map(function (token) {
269
+ return __assign(__assign({}, token), { chainId: chainId, price: undefined });
270
+ })];
271
+ case 4: return [2 /*return*/];
272
+ }
273
+ });
274
+ }); };
275
+ export var getDexScreenerChainName = function (chainId) {
276
+ var _a;
277
+ var chainsName = (_a = {},
278
+ _a[ChainId.MAINNET] = 'ethereum',
279
+ _a[ChainId.TLOS] = 'telos',
280
+ _a[ChainId.BSC] = 'bsc',
281
+ _a[ChainId.MATIC] = 'polygon',
282
+ _a[ChainId.ARBITRUM] = 'arbitrum',
283
+ _a[ChainId.INEVM] = 'injective',
284
+ _a[ChainId.LINEA] = 'linea',
285
+ _a);
286
+ //@ts-ignore
287
+ return chainsName[chainId];
288
+ };
@@ -0,0 +1,11 @@
1
+ import { ChainId } from '../../enum/apeswaplists';
2
+ export interface TokenPrices {
3
+ symbol: string | undefined;
4
+ address: string | undefined;
5
+ price: number | undefined;
6
+ decimals: number | undefined;
7
+ chainId: ChainId | undefined;
8
+ }
9
+ export declare const fetchPrices: () => Promise<TokenPrices[]>;
10
+ export default function useTokenPricesNew(): import("@tanstack/react-query/build/legacy/types").UseQueryResult<TokenPrices[], Error>;
11
+ export declare const useTokenPriceNew: (inputTokenAddress: string, chainId: ChainId) => number | undefined;
@@ -0,0 +1,72 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
12
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { useQuery } from '@tanstack/react-query';
38
+ import { QUERY_KEYS } from '../../config/constants/queryKeys';
39
+ import fetchTokenPricesForMultipleChains from './fetchTokenPricesForMultipleChains';
40
+ import { MAINNET_CHAINS } from '../../config/constants/chains';
41
+ import { WRAPPED_NATIVE_CURRENCY } from '../../config/constants/tokens';
42
+ export var fetchPrices = function () { return __awaiter(void 0, void 0, void 0, function () {
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0: return [4 /*yield*/, fetchTokenPricesForMultipleChains(MAINNET_CHAINS)];
46
+ case 1: return [2 /*return*/, _a.sent()];
47
+ }
48
+ });
49
+ }); };
50
+ export default function useTokenPricesNew() {
51
+ return useQuery({
52
+ queryKey: [QUERY_KEYS.TOKEN_PRICES],
53
+ queryFn: fetchPrices,
54
+ refetchInterval: 40000,
55
+ refetchOnWindowFocus: false,
56
+ refetchOnMount: false,
57
+ retry: 1,
58
+ });
59
+ }
60
+ export var useTokenPriceNew = function (inputTokenAddress, chainId) {
61
+ var _a;
62
+ var tokenPrices = useTokenPricesNew().data;
63
+ return (_a = tokenPrices === null || tokenPrices === void 0 ? void 0 : tokenPrices.find(function (tokenPrice) {
64
+ var _a, _b, _c, _d, _e;
65
+ if (inputTokenAddress === 'ETH') {
66
+ return (((_a = tokenPrice === null || tokenPrice === void 0 ? void 0 : tokenPrice.address) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_c = (_b = WRAPPED_NATIVE_CURRENCY[chainId]) === null || _b === void 0 ? void 0 : _b.address) === null || _c === void 0 ? void 0 : _c.toLowerCase()) &&
67
+ ((_d = WRAPPED_NATIVE_CURRENCY[chainId]) === null || _d === void 0 ? void 0 : _d.chainId) === chainId);
68
+ }
69
+ else
70
+ return ((_e = tokenPrice === null || tokenPrice === void 0 ? void 0 : tokenPrice.address) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === (inputTokenAddress === null || inputTokenAddress === void 0 ? void 0 : inputTokenAddress.toLowerCase()) && tokenPrice.chainId === chainId;
71
+ })) === null || _a === void 0 ? void 0 : _a.price;
72
+ };