@ape.swap/bonds-sdk 1.0.553 → 1.0.555
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/package.json +1 -1
- package/dist/config/abi/bondNft.json +0 -424
- package/dist/config/abi/ens-public-resolver.json +0 -816
- package/dist/config/abi/ens-registrar.json +0 -422
- package/dist/config/abi/erc20_bytes32.json +0 -30
- package/dist/config/abi/jungleChef.json +0 -291
- package/dist/config/abi/launchBonds.json +0 -2014
- package/dist/config/abi/lockVeAbond.json +0 -2198
- package/dist/config/abi/migrationBond.json +0 -1639
- package/dist/config/abi/migrationFveAbond.json +0 -160
- package/dist/config/abi/multicallv3.json +0 -92
- package/dist/config/abi/price-getter-linea.json +0 -1448
- package/dist/config/abi/price-getter.json +0 -1309
- package/dist/config/abi/sousChef.json +0 -649
- package/dist/config/abi/weth.json +0 -279
- package/dist/hooks/PriceGetter/dexFactories.d.ts +0 -11
- package/dist/hooks/PriceGetter/dexFactories.js +0 -2
- package/dist/hooks/PriceGetter/usePricesFromPriceGetter.d.ts +0 -17
- package/dist/hooks/PriceGetter/usePricesFromPriceGetter.js +0 -205
- package/dist/hooks/useClaimBill.d.ts +0 -4
- package/dist/hooks/useClaimBill.js +0 -59
- package/dist/hooks/useContract.d.ts +0 -25
- package/dist/hooks/useContract.js +0 -107
- package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.d.ts +0 -4
- package/dist/state/tokenPrices/fetchTokenPricesForMultipleChains.js +0 -81
- package/dist/state/tokenPrices/getAllTokenPrices.d.ts +0 -5
- package/dist/state/tokenPrices/getAllTokenPrices.js +0 -288
- package/dist/state/tokenPrices/useTokenPricesNew.d.ts +0 -11
- package/dist/state/tokenPrices/useTokenPricesNew.js +0 -72
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useWeb3React } from '@web3-react/core';
|
|
2
|
-
import { useMemo } from 'react';
|
|
3
|
-
import { getContract } from '../utils';
|
|
4
|
-
// ABIS
|
|
5
|
-
import multicallV3Abi from '../config/abi/multicallv3.json';
|
|
6
|
-
import ERC20_ABI from '../config/abi/erc20.json';
|
|
7
|
-
import ERC20_BYTES32_ABI from '../config/abi/erc20_bytes32.json';
|
|
8
|
-
import ENS_ABI from '../config/abi/ens-registrar.json';
|
|
9
|
-
import BOND_ABI from '../config/abi/bond.json';
|
|
10
|
-
import MIGRATION_BOND_ABI from '../config/abi/migrationBond.json';
|
|
11
|
-
import LAUNCH_BOND_ABI from '../config/abi/launchBonds.json';
|
|
12
|
-
import BOND_NFT_ABI from '../config/abi/bondNft.json';
|
|
13
|
-
import JUNGLE_CHEF_ABI from '../config/abi/jungleChef.json';
|
|
14
|
-
import PRICE_GETTER_ABI from '../config/abi/price-getter.json';
|
|
15
|
-
import ENS_PUBLIC_RESOLVER_ABI from '../config/abi/ens-public-resolver.json';
|
|
16
|
-
import LOCK_VEABOND_ABI from '../config/abi/lockVeAbond.json';
|
|
17
|
-
import MIGRATION_FVEABOND_ABI from '../config/abi/migrationFveAbond.json';
|
|
18
|
-
import { PRICE_GETTER_ADDRESSES, MULTICALL } from '../config/constants/addresses';
|
|
19
|
-
import WETH_ABI from '../config/abi/weth.json';
|
|
20
|
-
import { SupportedChainId } from '@ape.swap/sdk-core';
|
|
21
|
-
import { WRAPPED_NATIVE_CURRENCY } from '../config/constants/tokens';
|
|
22
|
-
// returns null on errors
|
|
23
|
-
export function useContract(addressOrAddressMap, ABI, withSignerIfPossible) {
|
|
24
|
-
if (withSignerIfPossible === void 0) { withSignerIfPossible = true; }
|
|
25
|
-
var _a = useWeb3React(), provider = _a.provider, account = _a.account, chainId = _a.chainId;
|
|
26
|
-
return useMemo(function () {
|
|
27
|
-
if (!addressOrAddressMap || !ABI || !provider || !chainId)
|
|
28
|
-
return null;
|
|
29
|
-
var address;
|
|
30
|
-
if (typeof addressOrAddressMap === 'string')
|
|
31
|
-
address = addressOrAddressMap;
|
|
32
|
-
else
|
|
33
|
-
address = addressOrAddressMap[chainId];
|
|
34
|
-
if (!address)
|
|
35
|
-
return null;
|
|
36
|
-
try {
|
|
37
|
-
return getContract(address, ABI, provider, withSignerIfPossible && account ? account : undefined);
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
console.error('Failed to get contract', error);
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}, [addressOrAddressMap, ABI, provider, chainId, withSignerIfPossible, account]);
|
|
44
|
-
}
|
|
45
|
-
export function useInterfaceMulticall() {
|
|
46
|
-
return useContract(MULTICALL, multicallV3Abi, false);
|
|
47
|
-
}
|
|
48
|
-
export function useTokenContract(tokenAddress, withSignerIfPossible) {
|
|
49
|
-
return useContract(tokenAddress, ERC20_ABI, withSignerIfPossible);
|
|
50
|
-
}
|
|
51
|
-
export function useBytes32TokenContract(tokenAddress, withSignerIfPossible) {
|
|
52
|
-
return useContract(tokenAddress, ERC20_BYTES32_ABI, withSignerIfPossible);
|
|
53
|
-
}
|
|
54
|
-
export function useENSRegistrarContract(withSignerIfPossible) {
|
|
55
|
-
var chainId = useWeb3React().chainId;
|
|
56
|
-
var address;
|
|
57
|
-
if (chainId) {
|
|
58
|
-
// eslint-disable-next-line default-case
|
|
59
|
-
switch (chainId) {
|
|
60
|
-
case SupportedChainId.MAINNET:
|
|
61
|
-
address = '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e';
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return useContract(address, ENS_ABI, withSignerIfPossible);
|
|
66
|
-
}
|
|
67
|
-
export function useENSResolverContract(address, withSignerIfPossible) {
|
|
68
|
-
return useContract(address, ENS_PUBLIC_RESOLVER_ABI, withSignerIfPossible);
|
|
69
|
-
}
|
|
70
|
-
export function usePriceGetter(chain) {
|
|
71
|
-
var chainId = useWeb3React().chainId;
|
|
72
|
-
var selectedChain = chain !== null && chain !== void 0 ? chain : chainId;
|
|
73
|
-
return useContract(selectedChain ? PRICE_GETTER_ADDRESSES[selectedChain] : undefined, PRICE_GETTER_ABI);
|
|
74
|
-
}
|
|
75
|
-
export var useBondContract = function (address) {
|
|
76
|
-
return useContract(address, BOND_ABI);
|
|
77
|
-
};
|
|
78
|
-
export var useLaunchBondContract = function (address) {
|
|
79
|
-
return useContract(address, LAUNCH_BOND_ABI);
|
|
80
|
-
};
|
|
81
|
-
export var useMigrationBondContract = function (address) {
|
|
82
|
-
return useContract(address, MIGRATION_BOND_ABI);
|
|
83
|
-
};
|
|
84
|
-
export var useBondNftContract = function (address) {
|
|
85
|
-
return useContract(address, BOND_NFT_ABI);
|
|
86
|
-
};
|
|
87
|
-
// export const useSousChef = (id: number) => {
|
|
88
|
-
// // If we ever use pools again revisit this
|
|
89
|
-
// const { chainId } = useWeb3React()
|
|
90
|
-
// const pools = useSelector((state: AppState) => state.pools.data)
|
|
91
|
-
// const config = pools.find((pool) => pool.sousId === id)
|
|
92
|
-
// return useContract(config ? config.contractAddress[chainId as SupportedChainId] : '', SOUS_CHEF_ABI) as SousChef
|
|
93
|
-
// }
|
|
94
|
-
export var useJungleFarmContract = function (address) {
|
|
95
|
-
return useContract(address, JUNGLE_CHEF_ABI);
|
|
96
|
-
};
|
|
97
|
-
export function useWETHContract(withSignerIfPossible) {
|
|
98
|
-
var _a;
|
|
99
|
-
var chainId = useWeb3React().chainId;
|
|
100
|
-
return useContract(chainId ? (_a = WRAPPED_NATIVE_CURRENCY[chainId]) === null || _a === void 0 ? void 0 : _a.address : undefined, WETH_ABI, withSignerIfPossible);
|
|
101
|
-
}
|
|
102
|
-
export var useLockAbondContract = function (address) {
|
|
103
|
-
return useContract(address, LOCK_VEABOND_ABI);
|
|
104
|
-
};
|
|
105
|
-
export var useMigrationFveAbondContract = function (address) {
|
|
106
|
-
return useContract(address, MIGRATION_FVEABOND_ABI);
|
|
107
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
-
if (ar || !(i in from)) {
|
|
40
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
-
ar[i] = from[i];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
-
};
|
|
46
|
-
import getAllTokenPrices from './getAllTokenPrices';
|
|
47
|
-
import axios from 'axios';
|
|
48
|
-
import { APESWAP_LISTS_URL } from '../../config/constants/lists';
|
|
49
|
-
var fetchTokenPricesForMultipleChains = function () {
|
|
50
|
-
var args_1 = [];
|
|
51
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
52
|
-
args_1[_i] = arguments[_i];
|
|
53
|
-
}
|
|
54
|
-
return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (chains) {
|
|
55
|
-
var prices, response, tokensList, index, chain, all, successfulPromises, successfulPrices;
|
|
56
|
-
if (chains === void 0) { chains = []; }
|
|
57
|
-
return __generator(this, function (_a) {
|
|
58
|
-
switch (_a.label) {
|
|
59
|
-
case 0:
|
|
60
|
-
prices = [];
|
|
61
|
-
return [4 /*yield*/, axios.get("".concat(APESWAP_LISTS_URL, "/config/tokens.json"))];
|
|
62
|
-
case 1:
|
|
63
|
-
response = _a.sent();
|
|
64
|
-
tokensList = response.data;
|
|
65
|
-
for (index = 0; index < chains.length; index++) {
|
|
66
|
-
chain = chains[index];
|
|
67
|
-
prices.push(getAllTokenPrices(chain, tokensList));
|
|
68
|
-
}
|
|
69
|
-
return [4 /*yield*/, Promise.allSettled(prices)
|
|
70
|
-
// Keep only successfully fulfilled promises and discard the rest
|
|
71
|
-
];
|
|
72
|
-
case 2:
|
|
73
|
-
all = _a.sent();
|
|
74
|
-
successfulPromises = all === null || all === void 0 ? void 0 : all.filter(function (result) { return result.status === 'fulfilled'; });
|
|
75
|
-
successfulPrices = successfulPromises.map(function (result) { return result.value; });
|
|
76
|
-
return [2 /*return*/, successfulPrices.flat()];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
export default fetchTokenPricesForMultipleChains;
|
|
@@ -1,5 +0,0 @@
|
|
|
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;
|
|
@@ -1,288 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
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").UseQueryResult<TokenPrices[], Error>;
|
|
11
|
-
export declare const useTokenPriceNew: (inputTokenAddress: string, chainId: ChainId) => number | undefined;
|
|
@@ -1,72 +0,0 @@
|
|
|
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, // i.e. 60 sec
|
|
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
|
-
};
|