@ape.swap/bonds-sdk 1.0.78-2.test.28 → 1.0.78-2.test.29
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/components/TokenSelectorModal/TokenRow.d.ts +8 -0
- package/dist/components/TokenSelectorModal/TokenRow.js +18 -0
- package/dist/components/TokenSelectorModal/index.d.ts +11 -0
- package/dist/components/TokenSelectorModal/index.js +56 -0
- package/dist/components/TokenSelectorPanel/index.d.ts +16 -0
- package/dist/components/TokenSelectorPanel/index.js +36 -0
- package/dist/components/uikit-sdk/TokenImage/index.d.ts +3 -2
- package/dist/components/uikit-sdk/TokenImage/index.js +27 -4
- package/dist/config/abi/price-getter-linea.json +1448 -0
- package/dist/config/abi/price-getter.json +1309 -0
- package/dist/config/constants/queryKeys.d.ts +4 -1
- package/dist/config/constants/queryKeys.js +24 -1
- package/dist/config/constants/tokens.d.ts +3 -6
- package/dist/config/constants/tokens.js +64 -452
- package/dist/config/constants/zapInputTokens.d.ts +2 -0
- package/dist/config/constants/zapInputTokens.js +356 -0
- package/dist/hooks/useTokenFromZapList.d.ts +3 -0
- package/dist/hooks/useTokenFromZapList.js +10 -0
- package/dist/providers/index.d.ts +0 -3
- package/dist/providers/index.js +6 -0
- package/dist/scss/BondModal.scss +215 -195
- package/dist/state/allowance/useAllowance.d.ts +11 -0
- package/dist/state/allowance/useAllowance.js +152 -0
- package/dist/state/balance/useCurrencyBalance.d.ts +4 -0
- package/dist/state/balance/useCurrencyBalance.js +82 -0
- package/dist/state/price/useCurrencyPrice.d.ts +19 -0
- package/dist/state/price/useCurrencyPrice.js +397 -0
- package/dist/state/zap/getChainParam.d.ts +12 -0
- package/dist/state/zap/getChainParam.js +34 -0
- package/dist/state/zap/useSoulZapBondQuote.d.ts +4 -0
- package/dist/state/zap/useSoulZapBondQuote.js +178 -0
- package/dist/state/zap/useSoulZapTokenQuote.d.ts +3 -0
- package/dist/state/zap/useSoulZapTokenQuote.js +168 -0
- package/dist/utils/getNativeTicker.d.ts +3 -0
- package/dist/utils/getNativeTicker.js +8 -0
- package/dist/views/BondModal/BondModal.js +2 -2
- package/dist/views/Bonds/Bonds.d.ts +1 -1
- package/dist/views/Bonds/index.d.ts +4 -0
- package/dist/views/Bonds/index.js +18 -0
- package/dist/views/ZapModal/index.d.ts +14 -0
- package/dist/views/ZapModal/index.js +150 -0
- package/dist/views/ZapModal/styles.d.ts +2 -0
- package/dist/views/ZapModal/styles.js +35 -0
- package/package.json +2 -1
|
@@ -0,0 +1,152 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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 BigNumber from 'bignumber.js';
|
|
39
|
+
import erc20ABI from '../../config/abi/erc20.json';
|
|
40
|
+
import { QUERY_KEYS } from '../../config/constants/queryKeys';
|
|
41
|
+
import multicall from '../../utils/multicall';
|
|
42
|
+
import convertToTokenValue from '../../utils/convertToTokenValue';
|
|
43
|
+
import ERC_20_ABI from '../../config/abi/erc20.json';
|
|
44
|
+
import { useCallback } from 'react';
|
|
45
|
+
import { useWriteContract } from 'wagmi';
|
|
46
|
+
export var ApprovalState;
|
|
47
|
+
(function (ApprovalState) {
|
|
48
|
+
ApprovalState["UNKNOWN"] = "UNKNOWN";
|
|
49
|
+
ApprovalState["NOT_APPROVED"] = "NOT_APPROVED";
|
|
50
|
+
ApprovalState["PENDING"] = "PENDING";
|
|
51
|
+
ApprovalState["APPROVED"] = "APPROVED";
|
|
52
|
+
})(ApprovalState || (ApprovalState = {}));
|
|
53
|
+
export default function useAllowance(amount, currency, spender, account, chainId) {
|
|
54
|
+
return useQuery({
|
|
55
|
+
queryKey: [
|
|
56
|
+
QUERY_KEYS.ALLOWANCE,
|
|
57
|
+
account !== null && account !== void 0 ? account : '',
|
|
58
|
+
chainId,
|
|
59
|
+
currency === 'NATIVE' ? currency : currency === null || currency === void 0 ? void 0 : currency.symbol,
|
|
60
|
+
spender,
|
|
61
|
+
],
|
|
62
|
+
queryFn: function () { return getTokenAllowance(amount, currency, spender, account, chainId); },
|
|
63
|
+
refetchInterval: 10000, // i.e. 10 sec
|
|
64
|
+
refetchOnWindowFocus: false,
|
|
65
|
+
retry: 1,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
export var getTokenAllowance = function (amount, currency, spender, account, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
69
|
+
var calls, data, value, allowance;
|
|
70
|
+
var _a;
|
|
71
|
+
return __generator(this, function (_b) {
|
|
72
|
+
switch (_b.label) {
|
|
73
|
+
case 0:
|
|
74
|
+
if (currency === 'NATIVE')
|
|
75
|
+
return [2 /*return*/, ApprovalState.APPROVED];
|
|
76
|
+
if (!account) {
|
|
77
|
+
console.log('Account disconnected');
|
|
78
|
+
}
|
|
79
|
+
else if (!currency) {
|
|
80
|
+
console.log('No currency selected');
|
|
81
|
+
}
|
|
82
|
+
else if (!chainId) {
|
|
83
|
+
console.log('No chainId selected');
|
|
84
|
+
}
|
|
85
|
+
else if (!amount) {
|
|
86
|
+
console.log('No amount selected');
|
|
87
|
+
}
|
|
88
|
+
else if (!spender) {
|
|
89
|
+
console.log('No spender selected');
|
|
90
|
+
}
|
|
91
|
+
if (!account || !currency || !chainId || !amount || !spender)
|
|
92
|
+
return [2 /*return*/, ApprovalState.UNKNOWN];
|
|
93
|
+
calls = [
|
|
94
|
+
{
|
|
95
|
+
address: currency.address[chainId],
|
|
96
|
+
name: 'allowance',
|
|
97
|
+
params: [account, spender],
|
|
98
|
+
},
|
|
99
|
+
];
|
|
100
|
+
return [4 /*yield*/, multicall(chainId, erc20ABI, calls)
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
];
|
|
103
|
+
case 1:
|
|
104
|
+
data = _b.sent();
|
|
105
|
+
value = new BigNumber((_a = data[0]) !== null && _a !== void 0 ? _a : 0).div(new BigNumber(10).pow(currency.decimals[chainId]));
|
|
106
|
+
allowance = value.toNumber();
|
|
107
|
+
return [2 /*return*/, allowance >= parseFloat(amount) ? ApprovalState.APPROVED : ApprovalState.NOT_APPROVED];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); };
|
|
111
|
+
export var useApproval = function (amount, currency, spender, account, chainId) {
|
|
112
|
+
var allowance = useAllowance(amount, currency, spender, account, chainId).data;
|
|
113
|
+
var _a = useWriteContract(), hash = _a.data, isPending = _a.isPending, isSuccess = _a.isSuccess, writeContract = _a.writeContract, writeContractAsync = _a.writeContractAsync;
|
|
114
|
+
var handleApprove = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
115
|
+
var decimals, tokenAddress, bigishAmount, tx, error_1;
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
switch (_a.label) {
|
|
118
|
+
case 0:
|
|
119
|
+
if (!chainId || !amount || currency === 'NATIVE' || !currency)
|
|
120
|
+
return [2 /*return*/, null
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
];
|
|
123
|
+
decimals = currency.decimals[chainId];
|
|
124
|
+
tokenAddress = currency.address[chainId];
|
|
125
|
+
if (!decimals || !tokenAddress)
|
|
126
|
+
return [2 /*return*/, null];
|
|
127
|
+
_a.label = 1;
|
|
128
|
+
case 1:
|
|
129
|
+
_a.trys.push([1, 3, , 4]);
|
|
130
|
+
bigishAmount = convertToTokenValue(amount, decimals);
|
|
131
|
+
console.log('send approve');
|
|
132
|
+
return [4 /*yield*/, writeContractAsync({
|
|
133
|
+
address: tokenAddress,
|
|
134
|
+
abi: ERC_20_ABI,
|
|
135
|
+
functionName: 'approve',
|
|
136
|
+
args: [spender, bigishAmount],
|
|
137
|
+
})];
|
|
138
|
+
case 2:
|
|
139
|
+
tx = _a.sent();
|
|
140
|
+
console.log('finished');
|
|
141
|
+
console.log(tx);
|
|
142
|
+
return [3 /*break*/, 4];
|
|
143
|
+
case 3:
|
|
144
|
+
error_1 = _a.sent();
|
|
145
|
+
console.error('Approval failed:', error_1);
|
|
146
|
+
return [3 /*break*/, 4];
|
|
147
|
+
case 4: return [2 /*return*/];
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}); }, [amount, currency, chainId]);
|
|
151
|
+
return [allowance !== null && allowance !== void 0 ? allowance : ApprovalState.NOT_APPROVED, handleApprove];
|
|
152
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { ChainId, Token } from '@ape.swap/apeswap-lists';
|
|
3
|
+
export default function useCurrencyBalance(currency: 'NATIVE' | Token | null, account: string | null, chainId: ChainId | null): UseQueryResult<string | undefined>;
|
|
4
|
+
export declare const getTokenBalance: (currency: "NATIVE" | Token | null, account: string | null, chainId: ChainId | null) => Promise<string | null>;
|
|
@@ -0,0 +1,82 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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 BigNumber from 'bignumber.js';
|
|
39
|
+
import { MULTICALL_V2 } from '../../config/constants/addresses';
|
|
40
|
+
import multicallV2Abi from '../../config/abi/multicallv2.json';
|
|
41
|
+
import erc20ABI from '../../config/abi/erc20.json';
|
|
42
|
+
import { QUERY_KEYS } from '../../config/constants/queryKeys';
|
|
43
|
+
import multicall from '../../utils/multicall';
|
|
44
|
+
export default function useCurrencyBalance(currency, account, chainId) {
|
|
45
|
+
return useQuery({
|
|
46
|
+
queryKey: [
|
|
47
|
+
QUERY_KEYS.CURRENCY_BALANCE,
|
|
48
|
+
account !== null && account !== void 0 ? account : '',
|
|
49
|
+
currency === 'NATIVE' ? currency : currency === null || currency === void 0 ? void 0 : currency.symbol,
|
|
50
|
+
chainId,
|
|
51
|
+
],
|
|
52
|
+
queryFn: function () { return getTokenBalance(currency, account, chainId); },
|
|
53
|
+
refetchInterval: 10000, // i.e. 10 sec
|
|
54
|
+
refetchOnWindowFocus: false,
|
|
55
|
+
retry: 1,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export var getTokenBalance = function (currency, account, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var calls, data, value;
|
|
60
|
+
var _a;
|
|
61
|
+
return __generator(this, function (_b) {
|
|
62
|
+
switch (_b.label) {
|
|
63
|
+
case 0:
|
|
64
|
+
if (!account || !currency || !chainId)
|
|
65
|
+
return [2 /*return*/, null];
|
|
66
|
+
calls = [
|
|
67
|
+
{
|
|
68
|
+
address: currency === 'NATIVE' ? MULTICALL_V2[chainId] : currency.address[chainId],
|
|
69
|
+
name: currency === 'NATIVE' ? 'getEthBalance' : 'balanceOf',
|
|
70
|
+
params: [account],
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
return [4 /*yield*/, multicall(chainId, currency === 'NATIVE' ? multicallV2Abi : erc20ABI, calls)];
|
|
74
|
+
case 1:
|
|
75
|
+
data = _b.sent();
|
|
76
|
+
value = new BigNumber((_a = data[0]) !== null && _a !== void 0 ? _a : 0).div(
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
new BigNumber(10).pow(currency === 'NATIVE' ? 18 : currency.decimals[chainId]));
|
|
79
|
+
return [2 /*return*/, value.toString()];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}); };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ChainId } from '@ape.swap/apeswap-lists';
|
|
2
|
+
import { Token } from '@ape.swap/apeswap-lists';
|
|
3
|
+
export interface TokenPrice {
|
|
4
|
+
symbol: string | undefined;
|
|
5
|
+
address: string | undefined;
|
|
6
|
+
price: number | undefined;
|
|
7
|
+
decimals: number | undefined;
|
|
8
|
+
chainId: ChainId | undefined;
|
|
9
|
+
}
|
|
10
|
+
export default function useCurrencyPrice(currency: 'NATIVE' | Token | null, chainId: ChainId | null): import("@tanstack/react-query").UseQueryResult<TokenPrice | null, Error>;
|
|
11
|
+
export declare const getTokenPrice: (currency: "NATIVE" | Token | null, chainId: ChainId | null) => Promise<TokenPrice | null>;
|
|
12
|
+
export declare const getDexScreenerChainName: (chainId: ChainId) => string | undefined;
|
|
13
|
+
type TokenRecord = {
|
|
14
|
+
[k: string]: Token;
|
|
15
|
+
};
|
|
16
|
+
export declare function getTokenPricesV2FromPriceGetter(tokensToCall: TokenRecord, chain: ChainId, lpTokens?: boolean): Promise<any>;
|
|
17
|
+
export declare function getPriceGetterCallData(tokensToCall: TokenRecord, // replace 'any' with the actual type
|
|
18
|
+
supportedChainId: ChainId, lpTokens: boolean): (string | number | undefined)[][];
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,397 @@
|
|
|
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["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 { useQuery } from '@tanstack/react-query';
|
|
58
|
+
import { ChainId, defaultDexFactories, dexFactories, Protocols } from '@ape.swap/apeswap-lists';
|
|
59
|
+
import { LiquidityDex } from '@ape.swap/apeswap-lists';
|
|
60
|
+
import { cloneDeep } from 'lodash';
|
|
61
|
+
import axios from 'axios';
|
|
62
|
+
import { QUERY_KEYS } from '../../config/constants/queryKeys';
|
|
63
|
+
import { WNATIVE } from '../../config/constants/tokens';
|
|
64
|
+
import { getBalanceNumber } from '../../utils/getBalanceNumber';
|
|
65
|
+
import { PRICE_GETTER_ADDRESSES } from '../../config/constants/addresses';
|
|
66
|
+
import multicall from '../../utils/multicall';
|
|
67
|
+
import PRICE_GETTER_ABI from '../../config/abi/price-getter.json';
|
|
68
|
+
import PRICE_GETTER_ABI_LINEA from '../../config/abi/price-getter-linea.json';
|
|
69
|
+
import ERC20ABI from '../../config/abi/erc20.json';
|
|
70
|
+
import { ZERO_ADDRESS } from '../../config/constants/misc';
|
|
71
|
+
export default function useCurrencyPrice(currency, chainId) {
|
|
72
|
+
var _a;
|
|
73
|
+
return useQuery({
|
|
74
|
+
queryKey: [
|
|
75
|
+
QUERY_KEYS.CURRENCY_PRICE,
|
|
76
|
+
currency === 'NATIVE' ? currency : ((_a = currency === null || currency === void 0 ? void 0 : currency.address[chainId]) !== null && _a !== void 0 ? _a : ''),
|
|
77
|
+
chainId,
|
|
78
|
+
],
|
|
79
|
+
queryFn: function () { return getTokenPrice(currency, chainId); },
|
|
80
|
+
refetchInterval: 15000, // i.e. 10 sec
|
|
81
|
+
refetchOnWindowFocus: false,
|
|
82
|
+
retry: 1,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export var getTokenPrice = function (currency, chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
86
|
+
var token, tokens, dexScreenerTokensToCall, filterTokensToCall, filterLpTokensToCall, arrayFilterTokens, parsedDexscreenerTokens, dexScreenerResults, tokenResults, lpTokenResults, parsedTokenResults, parsedLpTokenResults, prices;
|
|
87
|
+
var _a;
|
|
88
|
+
var _b;
|
|
89
|
+
return __generator(this, function (_c) {
|
|
90
|
+
switch (_c.label) {
|
|
91
|
+
case 0:
|
|
92
|
+
if (!currency || !chainId)
|
|
93
|
+
return [2 /*return*/, null];
|
|
94
|
+
token = currency === 'NATIVE' ? WNATIVE[chainId] : currency;
|
|
95
|
+
if (!token)
|
|
96
|
+
return [2 /*return*/, null];
|
|
97
|
+
tokens = (_a = {}, _a[token.address[chainId]] = token, _a);
|
|
98
|
+
dexScreenerTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
|
|
99
|
+
var _b;
|
|
100
|
+
var token = _a[1];
|
|
101
|
+
return ((_b = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _b === void 0 ? void 0 : _b[chainId]) === LiquidityDex.External;
|
|
102
|
+
}));
|
|
103
|
+
filterTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
|
|
104
|
+
var _b, _c;
|
|
105
|
+
var token = _a[1];
|
|
106
|
+
return ((token === null || token === void 0 ? void 0 : token.active) &&
|
|
107
|
+
!(token === null || token === void 0 ? void 0 : token.lpToken) &&
|
|
108
|
+
token.address[chainId] &&
|
|
109
|
+
((_b = token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) &&
|
|
110
|
+
((_c = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _c === void 0 ? void 0 : _c[chainId]) !== LiquidityDex.External);
|
|
111
|
+
}));
|
|
112
|
+
filterLpTokensToCall = Object.fromEntries(Object.entries(tokens).filter(function (_a) {
|
|
113
|
+
var _b, _c;
|
|
114
|
+
var token = _a[1];
|
|
115
|
+
return ((token === null || token === void 0 ? void 0 : token.active) &&
|
|
116
|
+
(token === null || token === void 0 ? void 0 : token.lpToken) &&
|
|
117
|
+
token.address[chainId] &&
|
|
118
|
+
((_b = token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) &&
|
|
119
|
+
((_c = token === null || token === void 0 ? void 0 : token.liquidityDex) === null || _c === void 0 ? void 0 : _c[chainId]) !== LiquidityDex.External);
|
|
120
|
+
}));
|
|
121
|
+
arrayFilterTokens = Object.values(filterTokensToCall);
|
|
122
|
+
parsedDexscreenerTokens = Object.values(dexScreenerTokensToCall).map(function (token) {
|
|
123
|
+
var _a, _b, _c, _d;
|
|
124
|
+
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 });
|
|
125
|
+
});
|
|
126
|
+
return [4 /*yield*/, getBatchTokenPriceWithDexscreener({ chainId: chainId, tokens: parsedDexscreenerTokens })];
|
|
127
|
+
case 1:
|
|
128
|
+
dexScreenerResults = _c.sent();
|
|
129
|
+
return [4 /*yield*/, getTokenPricesV2FromPriceGetter(filterTokensToCall, chainId, false)];
|
|
130
|
+
case 2:
|
|
131
|
+
tokenResults = _c.sent();
|
|
132
|
+
return [4 /*yield*/, getTokenPricesV2FromPriceGetter(filterLpTokensToCall, chainId, true)];
|
|
133
|
+
case 3:
|
|
134
|
+
lpTokenResults = _c.sent();
|
|
135
|
+
parsedTokenResults = arrayFilterTokens.map(function (token, i) {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
var price = getBalanceNumber((_a = tokenResults === null || tokenResults === void 0 ? void 0 : tokenResults[i]) === null || _a === void 0 ? void 0 : _a.toString(), 18);
|
|
138
|
+
return {
|
|
139
|
+
symbol: token.symbol,
|
|
140
|
+
address: token.address[chainId],
|
|
141
|
+
price: price !== null && price !== void 0 ? price : undefined,
|
|
142
|
+
decimals: (_c = (_b = token.decimals) === null || _b === void 0 ? void 0 : _b[chainId]) !== null && _c !== void 0 ? _c : undefined,
|
|
143
|
+
chainId: chainId,
|
|
144
|
+
};
|
|
145
|
+
});
|
|
146
|
+
parsedLpTokenResults = Object.values(filterLpTokensToCall).map(function (token, i) {
|
|
147
|
+
var _a, _b;
|
|
148
|
+
return {
|
|
149
|
+
symbol: token.symbol,
|
|
150
|
+
address: token.address[chainId],
|
|
151
|
+
price: getBalanceNumber(lpTokenResults[i].toString(), 18),
|
|
152
|
+
decimals: (_b = (_a = token.decimals) === null || _a === void 0 ? void 0 : _a[chainId]) !== null && _b !== void 0 ? _b : undefined,
|
|
153
|
+
chainId: chainId,
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
prices = __spreadArray(__spreadArray(__spreadArray([], parsedTokenResults, true), parsedLpTokenResults, true), dexScreenerResults, true);
|
|
157
|
+
return [2 /*return*/, (_b = prices.find(function (tokenPrice) { return !!tokenPrice; })) !== null && _b !== void 0 ? _b : null];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}); };
|
|
161
|
+
var getBatchTokenPriceWithDexscreener = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
162
|
+
var chainId, tokens, tokensCopy, baseURL_1, totalSupplies_1, chains_1, chainName_1, calls, result, error_1;
|
|
163
|
+
return __generator(this, function (_a) {
|
|
164
|
+
switch (_a.label) {
|
|
165
|
+
case 0:
|
|
166
|
+
chainId = params.chainId, tokens = params.tokens;
|
|
167
|
+
tokensCopy = cloneDeep(tokens);
|
|
168
|
+
_a.label = 1;
|
|
169
|
+
case 1:
|
|
170
|
+
_a.trys.push([1, 3, , 4]);
|
|
171
|
+
baseURL_1 = 'https://api.dexscreener.com/latest/dex';
|
|
172
|
+
totalSupplies_1 = [];
|
|
173
|
+
chains_1 = [];
|
|
174
|
+
chainName_1 = getDexScreenerChainName(chainId);
|
|
175
|
+
calls = tokensCopy.map(function (token) { return __awaiter(void 0, void 0, void 0, function () {
|
|
176
|
+
var symbol, lpToken, totalSupply, decimals, endpoint, calls_1, supply, _a, url, response, error_2;
|
|
177
|
+
return __generator(this, function (_b) {
|
|
178
|
+
switch (_b.label) {
|
|
179
|
+
case 0:
|
|
180
|
+
symbol = token.symbol, lpToken = token.lpToken, totalSupply = token.totalSupply, decimals = token.decimals;
|
|
181
|
+
if (['USDT', 'USDC'].includes(symbol)) {
|
|
182
|
+
chains_1.push('injective');
|
|
183
|
+
return [2 /*return*/, {
|
|
184
|
+
pairs: [
|
|
185
|
+
{
|
|
186
|
+
chainId: chainName_1,
|
|
187
|
+
baseToken: {
|
|
188
|
+
address: token.address,
|
|
189
|
+
},
|
|
190
|
+
liquidity: {
|
|
191
|
+
usd: 1,
|
|
192
|
+
},
|
|
193
|
+
priceUsd: 1,
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
if (symbol.toLowerCase() === 'inj' || symbol.toLowerCase() === 'winj') {
|
|
199
|
+
token.address = 'inj';
|
|
200
|
+
}
|
|
201
|
+
if (!chainName_1) {
|
|
202
|
+
console.log("Chain ".concat(chainId, " is not supported by dexscreener."));
|
|
203
|
+
return [2 /*return*/, null];
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
chains_1.push(chainName_1);
|
|
207
|
+
}
|
|
208
|
+
if (!lpToken) return [3 /*break*/, 4];
|
|
209
|
+
if (!!totalSupply) return [3 /*break*/, 2];
|
|
210
|
+
calls_1 = [
|
|
211
|
+
{
|
|
212
|
+
address: token.address,
|
|
213
|
+
name: 'totalSupply',
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
_a = getBalanceNumber;
|
|
217
|
+
return [4 /*yield*/, multicall(chainId, ERC20ABI, calls_1)];
|
|
218
|
+
case 1:
|
|
219
|
+
supply = _a.apply(void 0, [(_b.sent())[0], decimals]);
|
|
220
|
+
totalSupplies_1.push(supply);
|
|
221
|
+
return [3 /*break*/, 3];
|
|
222
|
+
case 2:
|
|
223
|
+
totalSupplies_1.push(totalSupply);
|
|
224
|
+
_b.label = 3;
|
|
225
|
+
case 3:
|
|
226
|
+
endpoint = "pairs/".concat(chainName_1);
|
|
227
|
+
return [3 /*break*/, 5];
|
|
228
|
+
case 4:
|
|
229
|
+
endpoint = "tokens";
|
|
230
|
+
_b.label = 5;
|
|
231
|
+
case 5:
|
|
232
|
+
url = "".concat(baseURL_1, "/").concat(endpoint, "/").concat(token.address);
|
|
233
|
+
_b.label = 6;
|
|
234
|
+
case 6:
|
|
235
|
+
_b.trys.push([6, 8, , 9]);
|
|
236
|
+
return [4 /*yield*/, axios.get(url)];
|
|
237
|
+
case 7:
|
|
238
|
+
response = _b.sent();
|
|
239
|
+
return [2 /*return*/, response.data];
|
|
240
|
+
case 8:
|
|
241
|
+
error_2 = _b.sent();
|
|
242
|
+
console.log("Failed to fetch data for token ".concat(token.address, ": ").concat(error_2));
|
|
243
|
+
return [2 /*return*/, null];
|
|
244
|
+
case 9: return [2 /*return*/];
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
}); });
|
|
248
|
+
return [4 /*yield*/, Promise.all(calls)];
|
|
249
|
+
case 2:
|
|
250
|
+
result = _a.sent();
|
|
251
|
+
return [2 /*return*/, result.map(function (response, index) {
|
|
252
|
+
var _a;
|
|
253
|
+
if (!response || !response.pairs) {
|
|
254
|
+
return __assign(__assign({}, tokensCopy === null || tokensCopy === void 0 ? void 0 : tokensCopy[index]), { price: undefined, chainId: chainId });
|
|
255
|
+
}
|
|
256
|
+
var supply = totalSupplies_1[index];
|
|
257
|
+
var token = tokensCopy[index];
|
|
258
|
+
var price;
|
|
259
|
+
try {
|
|
260
|
+
if (token.lpToken) {
|
|
261
|
+
var liquidity = response.pair.liquidity.usd;
|
|
262
|
+
price = liquidity / supply;
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
var pairs = response.pairs;
|
|
266
|
+
price = (_a = pairs
|
|
267
|
+
.filter(function (pair) {
|
|
268
|
+
return pair.chainId === chainName_1 && pair.baseToken.address.toLowerCase() === token.address.toLowerCase();
|
|
269
|
+
})
|
|
270
|
+
.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;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
price = undefined;
|
|
275
|
+
}
|
|
276
|
+
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') });
|
|
277
|
+
})];
|
|
278
|
+
case 3:
|
|
279
|
+
error_1 = _a.sent();
|
|
280
|
+
console.log("Failed to get price from dexscreener for chain ".concat(chainId, "."));
|
|
281
|
+
return [2 /*return*/, tokensCopy.map(function (token) {
|
|
282
|
+
return __assign(__assign({}, token), { chainId: chainId, price: undefined });
|
|
283
|
+
})];
|
|
284
|
+
case 4: return [2 /*return*/];
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}); };
|
|
288
|
+
export var getDexScreenerChainName = function (chainId) {
|
|
289
|
+
var _a;
|
|
290
|
+
var chainsName = (_a = {},
|
|
291
|
+
_a[ChainId.MAINNET] = 'ethereum',
|
|
292
|
+
_a[ChainId.TLOS] = 'telos',
|
|
293
|
+
_a[ChainId.BSC] = 'bsc',
|
|
294
|
+
_a[ChainId.MATIC] = 'polygon',
|
|
295
|
+
_a[ChainId.ARBITRUM] = 'arbitrum',
|
|
296
|
+
_a[ChainId.INEVM] = 'injective',
|
|
297
|
+
_a[ChainId.LINEA] = 'linea',
|
|
298
|
+
_a);
|
|
299
|
+
//@ts-ignore
|
|
300
|
+
return chainsName[chainId];
|
|
301
|
+
};
|
|
302
|
+
export function getTokenPricesV2FromPriceGetter(tokensToCall_1, chain_1) {
|
|
303
|
+
return __awaiter(this, arguments, void 0, function (tokensToCall, chain, lpTokens) {
|
|
304
|
+
var tokenCalls, calls, tokenResults;
|
|
305
|
+
if (lpTokens === void 0) { lpTokens = false; }
|
|
306
|
+
return __generator(this, function (_a) {
|
|
307
|
+
switch (_a.label) {
|
|
308
|
+
case 0:
|
|
309
|
+
tokenCalls = getPriceGetterCallData(tokensToCall, chain, lpTokens);
|
|
310
|
+
calls = tokenCalls.map(function (t) { return ({
|
|
311
|
+
address: PRICE_GETTER_ADDRESSES[chain],
|
|
312
|
+
name: lpTokens ? 'getLPPriceFromFactory' : 'getPriceFromFactory',
|
|
313
|
+
params: t,
|
|
314
|
+
}); });
|
|
315
|
+
return [4 /*yield*/, multicall(+chain, [ChainId.LINEA, ChainId.LIGHTLINK, ChainId.IOTA, ChainId.BASE, ChainId.ARBITRUM].includes(chain)
|
|
316
|
+
? PRICE_GETTER_ABI_LINEA
|
|
317
|
+
: PRICE_GETTER_ABI, calls)];
|
|
318
|
+
case 1:
|
|
319
|
+
tokenResults = _a.sent();
|
|
320
|
+
return [2 /*return*/, tokenResults];
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
export function getPriceGetterCallData(tokensToCall, // replace 'any' with the actual type
|
|
326
|
+
supportedChainId, lpTokens) {
|
|
327
|
+
return Object.values(tokensToCall).map(function (token) {
|
|
328
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
329
|
+
var liquidityDex = (_a = token.liquidityDex) === null || _a === void 0 ? void 0 : _a[supportedChainId];
|
|
330
|
+
var dexFactory;
|
|
331
|
+
var protocol = 2;
|
|
332
|
+
var factoryV2 = (_c = (_b = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _b === void 0 ? void 0 : _b[2]) !== null && _c !== void 0 ? _c : ZERO_ADDRESS;
|
|
333
|
+
var factoryV3 = (_e = (_d = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _d === void 0 ? void 0 : _d[3]) !== null && _e !== void 0 ? _e : ZERO_ADDRESS;
|
|
334
|
+
var factoryAlgebra = (_g = (_f = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _f === void 0 ? void 0 : _f[4]) !== null && _g !== void 0 ? _g : ZERO_ADDRESS;
|
|
335
|
+
var factorySolidly = (_j = (_h = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _h === void 0 ? void 0 : _h[7]) !== null && _j !== void 0 ? _j : ZERO_ADDRESS;
|
|
336
|
+
var factoryXFAI = (_l = (_k = defaultDexFactories === null || defaultDexFactories === void 0 ? void 0 : defaultDexFactories[supportedChainId]) === null || _k === void 0 ? void 0 : _k[8]) !== null && _l !== void 0 ? _l : ZERO_ADDRESS;
|
|
337
|
+
if (liquidityDex) {
|
|
338
|
+
dexFactory = (_m = dexFactories[supportedChainId]) === null || _m === void 0 ? void 0 : _m[liquidityDex];
|
|
339
|
+
protocol = (_o = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.protocol) !== null && _o !== void 0 ? _o : Protocols.V2;
|
|
340
|
+
switch (protocol) {
|
|
341
|
+
case Protocols.V2:
|
|
342
|
+
factoryV2 = (_p = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _p !== void 0 ? _p : factoryV2;
|
|
343
|
+
break;
|
|
344
|
+
case Protocols.V3:
|
|
345
|
+
factoryV3 = (_q = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _q !== void 0 ? _q : factoryV3;
|
|
346
|
+
break;
|
|
347
|
+
case Protocols.Algebra:
|
|
348
|
+
factoryAlgebra = (_r = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _r !== void 0 ? _r : factoryAlgebra;
|
|
349
|
+
break;
|
|
350
|
+
case Protocols.Solidly:
|
|
351
|
+
factorySolidly = (_s = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _s !== void 0 ? _s : factorySolidly;
|
|
352
|
+
break;
|
|
353
|
+
case Protocols.XFAI:
|
|
354
|
+
factoryXFAI = (_t = dexFactory === null || dexFactory === void 0 ? void 0 : dexFactory.factory) !== null && _t !== void 0 ? _t : factoryXFAI;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
var errMsg = "No default dex factory found for retrieving price. For Protocol: ".concat(protocol, ".");
|
|
358
|
+
switch (protocol) {
|
|
359
|
+
case Protocols.Both:
|
|
360
|
+
if (factoryV2 === ZERO_ADDRESS || factoryV3 === ZERO_ADDRESS) {
|
|
361
|
+
throw new Error(errMsg);
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
case Protocols.V2:
|
|
365
|
+
if (factoryV2 === ZERO_ADDRESS) {
|
|
366
|
+
throw new Error(errMsg);
|
|
367
|
+
}
|
|
368
|
+
break;
|
|
369
|
+
case Protocols.V3:
|
|
370
|
+
if (factoryV3 === ZERO_ADDRESS) {
|
|
371
|
+
throw new Error(errMsg);
|
|
372
|
+
}
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
// TODO: Not sure if this is the best way to handle this. It requires all tokens to be either LP or not
|
|
376
|
+
if (lpTokens && protocol == Protocols.Algebra) {
|
|
377
|
+
protocol = Protocols.Gamma;
|
|
378
|
+
}
|
|
379
|
+
if (lpTokens && protocol == Protocols.V3 && supportedChainId !== ChainId.ARBITRUM) {
|
|
380
|
+
protocol = Protocols.Steer;
|
|
381
|
+
}
|
|
382
|
+
if ([ChainId.LINEA, ChainId.LIGHTLINK, ChainId.IOTA, ChainId.BASE, ChainId.ARBITRUM].includes(supportedChainId) &&
|
|
383
|
+
!token.lpToken) {
|
|
384
|
+
return [
|
|
385
|
+
token.address[supportedChainId],
|
|
386
|
+
protocol,
|
|
387
|
+
factoryV2,
|
|
388
|
+
factoryV3,
|
|
389
|
+
factoryAlgebra,
|
|
390
|
+
factorySolidly,
|
|
391
|
+
factoryXFAI,
|
|
392
|
+
];
|
|
393
|
+
}
|
|
394
|
+
else
|
|
395
|
+
return [token.address[supportedChainId], protocol, factoryV2, factoryV3, factoryAlgebra, factorySolidly];
|
|
396
|
+
});
|
|
397
|
+
}
|