@gearbox-protocol/sdk 3.0.0-next.115 → 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;
|
|
@@ -73,6 +73,7 @@ interface LiquidationPriceProps {
|
|
|
73
73
|
}
|
|
74
74
|
export declare class CreditAccountData {
|
|
75
75
|
readonly isSuccessful: boolean;
|
|
76
|
+
readonly priceFeedsNeeded: string[];
|
|
76
77
|
readonly addr: string;
|
|
77
78
|
readonly borrower: string;
|
|
78
79
|
readonly creditManager: string;
|
|
@@ -106,6 +107,7 @@ export declare class CreditAccountData {
|
|
|
106
107
|
constructor(payload: CreditAccountDataPayload);
|
|
107
108
|
setDeleteInProgress(d: boolean): void;
|
|
108
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[];
|
|
109
111
|
static tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
|
|
110
112
|
static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
|
|
111
113
|
isForbidden(token: string): boolean;
|
|
@@ -8,6 +8,7 @@ const price_1 = require("../utils/price");
|
|
|
8
8
|
const MAX_UINT16 = 65535;
|
|
9
9
|
class CreditAccountData {
|
|
10
10
|
isSuccessful;
|
|
11
|
+
priceFeedsNeeded;
|
|
11
12
|
addr;
|
|
12
13
|
borrower;
|
|
13
14
|
creditManager;
|
|
@@ -40,6 +41,7 @@ class CreditAccountData {
|
|
|
40
41
|
quotedTokens = {};
|
|
41
42
|
constructor(payload) {
|
|
42
43
|
this.isSuccessful = payload.isSuccessful;
|
|
44
|
+
this.priceFeedsNeeded = payload.priceFeedsNeeded;
|
|
43
45
|
this.addr = payload.addr.toLowerCase();
|
|
44
46
|
this.borrower = payload.borrower.toLowerCase();
|
|
45
47
|
this.creditManager = payload.creditManager.toLowerCase();
|
|
@@ -116,6 +118,24 @@ class CreditAccountData {
|
|
|
116
118
|
return CreditAccountData.amountAbcComparator(totalPrice1, totalPrice2);
|
|
117
119
|
});
|
|
118
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
|
+
}
|
|
119
139
|
static tokensAbcComparator(t1, t2) {
|
|
120
140
|
const { symbol: symbol1 = "" } = t1 || {};
|
|
121
141
|
const { symbol: symbol2 = "" } = t2 || {};
|