@gearbox-protocol/sdk 1.20.19 → 1.20.21

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.
@@ -1,25 +1,2 @@
1
- import { NetworkType } from "../core/chains";
2
- import { ILidoOracle, IstETH } from "../types";
3
- import { MCall } from "../utils/multicall";
4
- export declare type LidoDataCallResponse = [
5
- Awaited<ReturnType<ILidoOracle["getLastCompletedReportDelta"]>>,
6
- Awaited<ReturnType<IstETH["getFee"]>>
7
- ];
8
- export interface GetLidoAPYProps {
9
- generated: GetLidoAPYCallsReturns;
10
- response: LidoDataCallResponse;
11
- }
12
- export declare function getLidoAPY({ response }: GetLidoAPYProps): readonly [import("ethers").BigNumber, number];
13
- export declare const LIDO_FEE_DECIMALS = 10000;
14
- export interface GetLidoAPYCallsProps {
15
- networkType: NetworkType;
16
- }
17
- declare type GetLidoAPYCallsReturns = ReturnType<typeof getLidoAPYCalls>;
18
- export declare function getLidoAPYCalls({ networkType }: GetLidoAPYCallsProps): {
19
- poolInfo: {
20
- lidoOracleAddress: string;
21
- stETHAddress: string;
22
- };
23
- calls: [MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/lido/ILidoOracle").ILidoOracleInterface>, ...MCall<import("../types/@gearbox-protocol/integrations-v2/contracts/integrations/lido/IstETH.sol/IstETH").IstETHInterface>[]];
24
- };
25
- export {};
1
+ import { BigNumber } from "ethers";
2
+ export declare function getLidoAPY(): Promise<BigNumber>;
@@ -1,70 +1,70 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
12
40
  };
13
41
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.getLidoAPYCalls = exports.LIDO_FEE_DECIMALS = exports.getLidoAPY = void 0;
15
- var contracts_1 = require("../contracts/contracts");
42
+ exports.getLidoAPY = void 0;
43
+ var axios_1 = __importDefault(require("axios"));
44
+ var ethers_1 = require("ethers");
16
45
  var constants_1 = require("../core/constants");
17
- var token_1 = require("../tokens/token");
18
- var types_1 = require("../types");
19
- function getLidoAPY(_a) {
20
- var response = _a.response;
21
- var _b = response[0], postTotalPooledEther = _b.postTotalPooledEther, preTotalPooledEther = _b.preTotalPooledEther, timeElapsed = _b.timeElapsed, _c = response[1], fee = _c === void 0 ? Math.floor(exports.LIDO_FEE_DECIMALS / 10) : _c;
22
- var lidoAPRRay = postTotalPooledEther
23
- .sub(preTotalPooledEther)
24
- .mul(constants_1.SECONDS_PER_YEAR)
25
- .mul(constants_1.WAD)
26
- .div(preTotalPooledEther.mul(timeElapsed));
27
- return [lidoAPRRay, fee];
28
- }
29
- exports.getLidoAPY = getLidoAPY;
30
- exports.LIDO_FEE_DECIMALS = 10000;
31
- function getLidoAPYCalls(_a) {
32
- var networkType = _a.networkType;
33
- var poolInfo = getLidoInfo(networkType);
34
- var calls = getLidoDataCalls(__assign(__assign({}, poolInfo), { network: networkType }));
35
- return { poolInfo: poolInfo, calls: calls };
36
- }
37
- exports.getLidoAPYCalls = getLidoAPYCalls;
38
- var lidoOracles = contracts_1.contractParams.LIDO_STETH_GATEWAY.oracle;
39
- var lidoStEth = {
40
- Mainnet: token_1.tokenDataByNetwork.Mainnet.STETH,
41
- Goerli: token_1.tokenDataByNetwork.Goerli.STETH,
42
- };
43
- function getLidoInfo(networkType) {
44
- if (!lidoOracles[networkType]) {
45
- throw new Error("No Lido APR oracle found on current network: ".concat(networkType));
46
- }
47
- if (!lidoStEth[networkType]) {
48
- throw new Error("No Lido stETH found on current network: ".concat(networkType));
49
- }
50
- var lidoOracleAddress = lidoOracles[networkType];
51
- var stETHAddress = lidoStEth[networkType];
52
- return { lidoOracleAddress: lidoOracleAddress, stETHAddress: stETHAddress };
53
- }
54
- function getLidoDataCalls(_a) {
55
- var lidoOracleAddress = _a.lidoOracleAddress, stETHAddress = _a.stETHAddress, network = _a.network;
56
- var calls = [
57
- {
58
- address: lidoOracleAddress,
59
- interface: types_1.ILidoOracle__factory.createInterface(),
60
- method: "getLastCompletedReportDelta()",
61
- },
62
- ];
63
- if (network === "Mainnet")
64
- calls.push({
65
- address: stETHAddress,
66
- interface: types_1.IstETH__factory.createInterface(),
67
- method: "getFee()",
46
+ var formatter_1 = require("../utils/formatter");
47
+ var LIDO_URL = "https://eth-api.lido.fi/v1/protocol/steth/apr/sma";
48
+ function getLidoAPY() {
49
+ var _a;
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var res, _b, smaApr, e_1;
52
+ return __generator(this, function (_c) {
53
+ switch (_c.label) {
54
+ case 0:
55
+ _c.trys.push([0, 2, , 3]);
56
+ return [4 /*yield*/, axios_1.default.get(LIDO_URL)];
57
+ case 1:
58
+ res = _c.sent();
59
+ _b = (((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) || {}).smaApr, smaApr = _b === void 0 ? 0 : _b;
60
+ return [2 /*return*/, (0, formatter_1.toBN)(String(smaApr), constants_1.WAD_DECIMALS_POW).div(constants_1.PERCENTAGE_DECIMALS)];
61
+ case 2:
62
+ e_1 = _c.sent();
63
+ console.error(e_1);
64
+ return [2 /*return*/, ethers_1.BigNumber.from(0)];
65
+ case 3: return [2 /*return*/];
66
+ }
68
67
  });
69
- return calls;
68
+ });
70
69
  }
70
+ exports.getLidoAPY = getLidoAPY;
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from "ethers";
2
- import { CreditSessionFilteredPayload, CreditSessionPayload } from "../payload/creditSession";
2
+ import { CreditSessionFilteredPayload, CreditSessionPayload, CreditSessionsAggregatedStatsPayload, UserCreditSessionsAggregatedStatsPayload } from "../payload/creditSession";
3
3
  import { AssetWithView } from "./assets";
4
4
  export declare type CreditSessionStatus = "active" | "closed" | "repaid" | "liquidated" | "liquidateExpired" | "liquidatePaused";
5
5
  export declare const CREDIT_SESSION_STATUS_BY_ID: Record<number, CreditSessionStatus>;
@@ -66,3 +66,21 @@ export declare class CreditSessionFiltered {
66
66
  }
67
67
  export declare type CreditSessionSortFields = "type" | "tvl" | "hf" | "debt" | "pnl" | "leverage" | "tfIndex";
68
68
  export declare type CreditSessionSortType = "asc" | "desc";
69
+ export interface UserCreditSessions extends Omit<UserCreditSessionsAggregatedStatsPayload, "accounts" | "totalValue10kBasis"> {
70
+ totalValueChange: number;
71
+ accounts: Array<CreditSession>;
72
+ }
73
+ declare type AggregatedOmit = "healthFactor10kBasis" | "leverage10kBasis" | "activeAccounts10kBasis" | "openedAccounts10kBasis" | "healthFactor" | "healthFactorOld";
74
+ export declare type CreditSessionsAggregatedStats = Omit<CreditSessionsAggregatedStatsPayload, AggregatedOmit> & {
75
+ healthFactorChange: number;
76
+ leverageChange: number;
77
+ activeAccountsChange: number;
78
+ openedAccountsChange: number;
79
+ healthFactor: BigNumber;
80
+ healthFactorOld: BigNumber;
81
+ };
82
+ export declare class UserCreditSessionsBuilder {
83
+ static buildUserCreditSessions(payload: UserCreditSessionsAggregatedStatsPayload): UserCreditSessions;
84
+ static buildCreditSessionsAggregatedStats(payload: CreditSessionsAggregatedStatsPayload): CreditSessionsAggregatedStats;
85
+ }
86
+ export {};
@@ -1,9 +1,31 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __rest = (this && this.__rest) || function (s, e) {
14
+ var t = {};
15
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
+ t[p] = s[p];
17
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
+ t[p[i]] = s[p[i]];
21
+ }
22
+ return t;
23
+ };
2
24
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
25
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
26
  };
5
27
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CreditSessionFiltered = exports.CreditSession = exports.CREDIT_SESSION_ID_BY_STATUS = exports.CREDIT_SESSION_STATUS_BY_ID = void 0;
28
+ exports.UserCreditSessionsBuilder = exports.CreditSessionFiltered = exports.CreditSession = exports.CREDIT_SESSION_ID_BY_STATUS = exports.CREDIT_SESSION_STATUS_BY_ID = void 0;
7
29
  var ethers_1 = require("ethers");
8
30
  var moment_1 = __importDefault(require("moment"));
9
31
  var mappers_1 = require("../utils/mappers");
@@ -105,3 +127,17 @@ var CreditSessionFiltered = /** @class */ (function () {
105
127
  return CreditSessionFiltered;
106
128
  }());
107
129
  exports.CreditSessionFiltered = CreditSessionFiltered;
130
+ var UserCreditSessionsBuilder = /** @class */ (function () {
131
+ function UserCreditSessionsBuilder() {
132
+ }
133
+ UserCreditSessionsBuilder.buildUserCreditSessions = function (payload) {
134
+ var accounts = payload.accounts, _a = payload.totalValue10kBasis, totalValue10kBasis = _a === void 0 ? 0 : _a, sessionsUnfiltered = __rest(payload, ["accounts", "totalValue10kBasis"]);
135
+ return __assign(__assign({}, sessionsUnfiltered), { totalValueChange: totalValue10kBasis * constants_1.PERCENTAGE_DECIMALS, accounts: accounts.map(function (p) { return new CreditSession(p); }) });
136
+ };
137
+ UserCreditSessionsBuilder.buildCreditSessionsAggregatedStats = function (payload) {
138
+ var _a = payload.healthFactor10kBasis, healthFactor10kBasis = _a === void 0 ? 0 : _a, _b = payload.leverage10kBasis, leverage10kBasis = _b === void 0 ? 0 : _b, _c = payload.activeAccounts10kBasis, activeAccounts10kBasis = _c === void 0 ? 0 : _c, _d = payload.openedAccounts10kBasis, openedAccounts10kBasis = _d === void 0 ? 0 : _d, _e = payload.healthFactor, healthFactor = _e === void 0 ? 0 : _e, _f = payload.healthFactorOld, healthFactorOld = _f === void 0 ? 0 : _f, leverage = payload.leverage, leverageOld = payload.leverageOld, rest = __rest(payload, ["healthFactor10kBasis", "leverage10kBasis", "activeAccounts10kBasis", "openedAccounts10kBasis", "healthFactor", "healthFactorOld", "leverage", "leverageOld"]);
139
+ return __assign(__assign({}, rest), { leverage: leverage, leverageOld: leverageOld, healthFactorChange: healthFactor10kBasis * constants_1.PERCENTAGE_DECIMALS, leverageChange: leverage10kBasis * constants_1.PERCENTAGE_DECIMALS, activeAccountsChange: activeAccounts10kBasis * constants_1.PERCENTAGE_DECIMALS, openedAccountsChange: openedAccounts10kBasis * constants_1.PERCENTAGE_DECIMALS, healthFactor: ethers_1.BigNumber.from(healthFactor), healthFactorOld: ethers_1.BigNumber.from(healthFactorOld) });
140
+ };
141
+ return UserCreditSessionsBuilder;
142
+ }());
143
+ exports.UserCreditSessionsBuilder = UserCreditSessionsBuilder;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.20.19",
3
+ "version": "1.20.21",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",