@gearbox-protocol/sdk 3.0.0-next.116 → 3.0.0-next.117
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/lib/apy/yearnAPY.js
CHANGED
|
@@ -7,18 +7,17 @@ exports.getYearnAPY = void 0;
|
|
|
7
7
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const getUrl = (chainId) => `https://ydaemon.yearn.finance/vaults/all?chainids=${chainId}&limit=2500`;
|
|
10
|
-
const transformSymbol = (s) => s.replaceAll("_", "-").toLowerCase();
|
|
11
10
|
async function getYearnAPY(network) {
|
|
12
11
|
try {
|
|
13
12
|
const chainId = sdk_gov_1.CHAINS[network];
|
|
14
13
|
const { data } = await axios_1.default.get(getUrl(chainId));
|
|
15
|
-
const
|
|
16
|
-
acc[d.
|
|
14
|
+
const dataByAddress = data.reduce((acc, d) => {
|
|
15
|
+
acc[d.address.toLowerCase()] = d;
|
|
17
16
|
return acc;
|
|
18
17
|
}, {});
|
|
19
18
|
const yearnAPY = sdk_gov_1.TypedObjectUtils.entries(sdk_gov_1.yearnTokens).reduce((acc, [yearnSymbol]) => {
|
|
20
|
-
const
|
|
21
|
-
const data =
|
|
19
|
+
const address = (sdk_gov_1.tokenDataByNetwork[network]?.[yearnSymbol] || "").toLowerCase();
|
|
20
|
+
const data = dataByAddress[address];
|
|
22
21
|
const { apr: apy } = data || {};
|
|
23
22
|
const { netAPR } = apy || {};
|
|
24
23
|
const netApy = netAPR || 0;
|
|
@@ -107,6 +107,7 @@ export declare class CreditAccountData {
|
|
|
107
107
|
constructor(payload: CreditAccountDataPayload);
|
|
108
108
|
setDeleteInProgress(d: boolean): void;
|
|
109
109
|
static sortBalances(balances: Record<string, bigint>, prices: Record<string, bigint>, tokens: Record<string, TokenData>): Array<[string, bigint]>;
|
|
110
|
+
static sortAssets(balances: Array<Asset>, prices: Record<string, bigint>, tokens: Record<string, TokenData>): Asset[];
|
|
110
111
|
static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
|
|
111
112
|
static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
|
|
112
113
|
isForbidden(token: string): boolean;
|
|
@@ -118,6 +118,24 @@ class CreditAccountData {
|
|
|
118
118
|
return CreditAccountData.amountAbcComparator(totalPrice1, totalPrice2);
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
|
+
static sortAssets(balances, prices, tokens) {
|
|
122
|
+
return balances.sort(({ token: addr1, balance: amount1 }, { token: addr2, balance: amount2 }) => {
|
|
123
|
+
const addr1Lc = addr1.toLowerCase();
|
|
124
|
+
const addr2Lc = addr2.toLowerCase();
|
|
125
|
+
const token1 = tokens[addr1Lc];
|
|
126
|
+
const token2 = tokens[addr2Lc];
|
|
127
|
+
const price1 = prices[addr1Lc] || sdk_gov_1.PRICE_DECIMALS;
|
|
128
|
+
const price2 = prices[addr2Lc] || sdk_gov_1.PRICE_DECIMALS;
|
|
129
|
+
const totalPrice1 = price_1.PriceUtils.calcTotalPrice(price1, amount1, token1?.decimals);
|
|
130
|
+
const totalPrice2 = price_1.PriceUtils.calcTotalPrice(price2, amount2, token2?.decimals);
|
|
131
|
+
if (totalPrice1 === totalPrice2) {
|
|
132
|
+
return amount1 === amount2
|
|
133
|
+
? CreditAccountData.tokensAbcComparator(token1, token2)
|
|
134
|
+
: CreditAccountData.amountAbcComparator(amount1, amount2);
|
|
135
|
+
}
|
|
136
|
+
return CreditAccountData.amountAbcComparator(totalPrice1, totalPrice2);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
121
139
|
static tokensAbcComparator(t1, t2) {
|
|
122
140
|
const { symbol: symbol1 = "" } = t1 || {};
|
|
123
141
|
const { symbol: symbol2 = "" } = t2 || {};
|