@curvefi/llamalend-api 1.1.7 → 1.1.8
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/interfaces.d.ts +6 -0
- package/lib/mintMarkets/MintMarketTemplate.d.ts +8 -7
- package/lib/mintMarkets/MintMarketTemplate.js +15 -5
- package/package.json +1 -1
- package/src/interfaces.ts +8 -1
- package/src/lendMarkets/LendMarketTemplate.ts +3 -3
- package/src/mintMarkets/MintMarketTemplate.ts +20 -9
package/lib/interfaces.d.ts
CHANGED
|
@@ -229,4 +229,10 @@ export interface ILeverageMetrics {
|
|
|
229
229
|
health: string;
|
|
230
230
|
}
|
|
231
231
|
export type GetExpectedFn = (fromToken: string, toToken: string, amountIn: bigint, blacklist: string | string[]) => Promise<IQuote>;
|
|
232
|
+
export interface IRates {
|
|
233
|
+
borrowApr: string;
|
|
234
|
+
lendApr: string;
|
|
235
|
+
borrowApy: string;
|
|
236
|
+
lendApy: string;
|
|
237
|
+
}
|
|
232
238
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import memoize from "memoizee";
|
|
2
2
|
import type { Llamalend } from "../llamalend.js";
|
|
3
|
-
import { IDict, ILlamma, TGas } from "../interfaces.js";
|
|
3
|
+
import { IDict, ILlamma, TGas, IRates } from "../interfaces.js";
|
|
4
4
|
import { ILeverageV2 } from "./interfaces/leverage.js";
|
|
5
5
|
export declare class MintMarketTemplate {
|
|
6
6
|
private llamalend;
|
|
@@ -46,8 +46,8 @@ export declare class MintMarketTemplate {
|
|
|
46
46
|
parameters: () => Promise<{
|
|
47
47
|
fee: string;
|
|
48
48
|
admin_fee: string;
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
rates: IRates;
|
|
50
|
+
future_rates: IRates;
|
|
51
51
|
liquidation_discount: string;
|
|
52
52
|
loan_discount: string;
|
|
53
53
|
}>;
|
|
@@ -134,18 +134,19 @@ export declare class MintMarketTemplate {
|
|
|
134
134
|
};
|
|
135
135
|
};
|
|
136
136
|
constructor(id: string, llammaData: ILlamma, llamalend: Llamalend);
|
|
137
|
+
private _buildRatesObject;
|
|
137
138
|
statsParameters: (() => Promise<{
|
|
138
139
|
fee: string;
|
|
139
140
|
admin_fee: string;
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
rates: IRates;
|
|
142
|
+
future_rates: IRates;
|
|
142
143
|
liquidation_discount: string;
|
|
143
144
|
loan_discount: string;
|
|
144
145
|
}>) & memoize.Memoized<() => Promise<{
|
|
145
146
|
fee: string;
|
|
146
147
|
admin_fee: string;
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
rates: IRates;
|
|
149
|
+
future_rates: IRates;
|
|
149
150
|
liquidation_discount: string;
|
|
150
151
|
loan_discount: string;
|
|
151
152
|
}>>;
|
|
@@ -15,7 +15,6 @@ import { LeverageV2Module } from "./modules/index.js";
|
|
|
15
15
|
export class MintMarketTemplate {
|
|
16
16
|
constructor(id, llammaData, llamalend) {
|
|
17
17
|
var _a;
|
|
18
|
-
// ---------------- STATS ----------------
|
|
19
18
|
this.statsParameters = memoize(() => __awaiter(this, void 0, void 0, function* () {
|
|
20
19
|
const llammaContract = this.llamalend.contracts[this.address].multicallContract;
|
|
21
20
|
const controllerContract = this.llamalend.contracts[this.controller].multicallContract;
|
|
@@ -31,10 +30,9 @@ export class MintMarketTemplate {
|
|
|
31
30
|
const [_fee, _admin_fee, _rate, _mp_rate, _liquidation_discount, _loan_discount] = yield this.llamalend.multicallProvider.all(calls);
|
|
32
31
|
const [fee, admin_fee, liquidation_discount, loan_discount] = [_fee, _admin_fee, _liquidation_discount, _loan_discount]
|
|
33
32
|
.map((x) => formatUnits(x * BigInt(100)));
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
return { fee, admin_fee, rate, future_rate, liquidation_discount, loan_discount };
|
|
33
|
+
const rates = this._buildRatesObject(_rate);
|
|
34
|
+
const future_rates = this._buildRatesObject(_mp_rate);
|
|
35
|
+
return { fee, admin_fee, rates, future_rates, liquidation_discount, loan_discount };
|
|
38
36
|
}), {
|
|
39
37
|
promise: true,
|
|
40
38
|
maxAge: 5 * 60 * 1000, // 5m
|
|
@@ -378,6 +376,18 @@ export class MintMarketTemplate {
|
|
|
378
376
|
},
|
|
379
377
|
};
|
|
380
378
|
}
|
|
379
|
+
// ---------------- STATS ----------------
|
|
380
|
+
_buildRatesObject(rate) {
|
|
381
|
+
const borrowApr = toBN(rate).times(365).times(86400).times(100).toString();
|
|
382
|
+
// borrowApy = e**(rate*365*86400) - 1
|
|
383
|
+
const borrowApy = String(((Math.pow(2.718281828459, (toBN(rate).times(365).times(86400)).toNumber())) - 1) * 100);
|
|
384
|
+
return {
|
|
385
|
+
borrowApr,
|
|
386
|
+
borrowApy,
|
|
387
|
+
lendApr: "0",
|
|
388
|
+
lendApy: "0",
|
|
389
|
+
};
|
|
390
|
+
}
|
|
381
391
|
statsBalances() {
|
|
382
392
|
return __awaiter(this, void 0, void 0, function* () {
|
|
383
393
|
const crvusdContract = this.llamalend.contracts[this.llamalend.crvUsdAddress].multicallContract;
|
package/package.json
CHANGED
package/src/interfaces.ts
CHANGED
|
@@ -248,4 +248,11 @@ export type GetExpectedFn = (
|
|
|
248
248
|
toToken: string,
|
|
249
249
|
amountIn: bigint,
|
|
250
250
|
blacklist: string | string[],
|
|
251
|
-
) => Promise<IQuote>;
|
|
251
|
+
) => Promise<IQuote>;
|
|
252
|
+
|
|
253
|
+
export interface IRates {
|
|
254
|
+
borrowApr: string;
|
|
255
|
+
lendApr: string;
|
|
256
|
+
borrowApy: string;
|
|
257
|
+
lendApy: string;
|
|
258
|
+
}
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
smartNumber,
|
|
24
24
|
calculateFutureLeverage,
|
|
25
25
|
} from "../utils.js";
|
|
26
|
-
import {IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac} from "../interfaces.js";
|
|
26
|
+
import {IDict, TGas, TAmount, IReward, IQuoteOdos, IOneWayMarket, IPartialFrac, IRates} from "../interfaces.js";
|
|
27
27
|
import { _getExpectedOdos, _getQuoteOdos, _assembleTxOdos, _getUserCollateral, _getUserCollateralForce, _getMarketsData } from "../external-api.js";
|
|
28
28
|
import ERC20Abi from '../constants/abis/ERC20.json' with {type: 'json'};
|
|
29
29
|
import {cacheKey, cacheStats} from "../cache/index.js";
|
|
@@ -1016,7 +1016,7 @@ export class LendMarketTemplate {
|
|
|
1016
1016
|
return await mpContract.future_rate(this.addresses.controller, _dReserves, _dDebt);
|
|
1017
1017
|
}
|
|
1018
1018
|
|
|
1019
|
-
private async statsRates(isGetter = true, useAPI = false): Promise<
|
|
1019
|
+
private async statsRates(isGetter = true, useAPI = false): Promise<IRates> {
|
|
1020
1020
|
if(useAPI) {
|
|
1021
1021
|
const response = await _getMarketsData(this.llamalend.constants.NETWORK_NAME);
|
|
1022
1022
|
|
|
@@ -1052,7 +1052,7 @@ export class LendMarketTemplate {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
}
|
|
1054
1054
|
|
|
1055
|
-
private async statsFutureRates(dReserves: TAmount, dDebt: TAmount, useAPI = true): Promise<
|
|
1055
|
+
private async statsFutureRates(dReserves: TAmount, dDebt: TAmount, useAPI = true): Promise<IRates> {
|
|
1056
1056
|
const _dReserves = parseUnits(dReserves, this.borrowed_token.decimals);
|
|
1057
1057
|
const _dDebt = parseUnits(dDebt, this.borrowed_token.decimals);
|
|
1058
1058
|
const _rate = await this._getFutureRate(_dReserves, _dDebt);
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
DIGas,
|
|
22
22
|
calculateFutureLeverage,
|
|
23
23
|
} from "../utils.js";
|
|
24
|
-
import {IDict, ILlamma, TGas} from "../interfaces.js";
|
|
24
|
+
import {IDict, ILlamma, TGas, IRates} from "../interfaces.js";
|
|
25
25
|
import {_getUserCollateralCrvUsd, _getUserCollateralCrvUsdFull} from "../external-api.js";
|
|
26
26
|
import { ILeverageV2 } from "./interfaces/leverage.js";
|
|
27
27
|
import { LeverageV2Module } from "./modules/index.js";
|
|
@@ -71,8 +71,8 @@ export class MintMarketTemplate {
|
|
|
71
71
|
parameters: () => Promise<{
|
|
72
72
|
fee: string, // %
|
|
73
73
|
admin_fee: string, // %
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
rates: IRates,
|
|
75
|
+
future_rates: IRates,
|
|
76
76
|
liquidation_discount: string, // %
|
|
77
77
|
loan_discount: string, // %
|
|
78
78
|
}>,
|
|
@@ -282,11 +282,23 @@ export class MintMarketTemplate {
|
|
|
282
282
|
|
|
283
283
|
// ---------------- STATS ----------------
|
|
284
284
|
|
|
285
|
+
private _buildRatesObject(rate: bigint): IRates {
|
|
286
|
+
const borrowApr = toBN(rate).times(365).times(86400).times(100).toString();
|
|
287
|
+
// borrowApy = e**(rate*365*86400) - 1
|
|
288
|
+
const borrowApy = String(((2.718281828459 ** (toBN(rate).times(365).times(86400)).toNumber()) - 1) * 100);
|
|
289
|
+
return {
|
|
290
|
+
borrowApr,
|
|
291
|
+
borrowApy,
|
|
292
|
+
lendApr: "0",
|
|
293
|
+
lendApy: "0",
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
|
|
285
297
|
public statsParameters = memoize(async (): Promise<{
|
|
286
298
|
fee: string, // %
|
|
287
299
|
admin_fee: string, // %
|
|
288
|
-
|
|
289
|
-
|
|
300
|
+
rates: IRates,
|
|
301
|
+
future_rates: IRates,
|
|
290
302
|
liquidation_discount: string, // %
|
|
291
303
|
loan_discount: string, // %
|
|
292
304
|
}> => {
|
|
@@ -307,11 +319,10 @@ export class MintMarketTemplate {
|
|
|
307
319
|
const [fee, admin_fee, liquidation_discount, loan_discount] = [_fee, _admin_fee, _liquidation_discount, _loan_discount]
|
|
308
320
|
.map((x) => formatUnits(x * BigInt(100)));
|
|
309
321
|
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
const future_rate = String(((2.718281828459 ** Number((toBN(_mp_rate).times(365).times(86400)))) - 1) * 100);
|
|
322
|
+
const rates = this._buildRatesObject(_rate);
|
|
323
|
+
const future_rates = this._buildRatesObject(_mp_rate);
|
|
313
324
|
|
|
314
|
-
return { fee, admin_fee,
|
|
325
|
+
return { fee, admin_fee, rates, future_rates, liquidation_discount, loan_discount }
|
|
315
326
|
},
|
|
316
327
|
{
|
|
317
328
|
promise: true,
|