@gearbox-protocol/sdk 1.26.0 → 1.26.2
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/curveAPY.js +1 -1
- package/lib/apy/yearnAPY.js +1 -1
- package/lib/contracts/contracts.js +4 -2
- package/lib/contracts/contractsRegister.js +1 -1
- package/lib/core/creditAccount.d.ts +1 -1
- package/lib/core/creditAccount.js +3 -7
- package/lib/core/creditAccount.spec.js +3 -3
- package/lib/core/creditSession.d.ts +2 -0
- package/lib/core/creditSession.js +16 -7
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -5
- package/lib/parsers/txParser.js +2 -2
- package/lib/tokens/token.js +7 -2
- package/lib/utils/mappers.d.ts +6 -5
- package/lib/utils/mappers.js +11 -12
- package/package.json +1 -1
package/lib/apy/curveAPY.js
CHANGED
|
@@ -52,7 +52,7 @@ async function getCurveAPY() {
|
|
|
52
52
|
...cryptoPoolData.map(p => [p.id, p]),
|
|
53
53
|
...factoryTricryptoPoolData.map(p => [p.id, p]),
|
|
54
54
|
]);
|
|
55
|
-
const curveAPY =
|
|
55
|
+
const curveAPY = mappers_1.TypedObjectUtils.entries(APY_DICTIONARY).reduce((acc, [curveSymbol, poolId]) => {
|
|
56
56
|
const { baseApy, crvApy } = apys[poolId] || {};
|
|
57
57
|
if (baseApy === undefined)
|
|
58
58
|
console.warn(`No base apy for: ${curveSymbol}, ${poolId}`);
|
package/lib/apy/yearnAPY.js
CHANGED
|
@@ -19,7 +19,7 @@ async function getYearnAPY() {
|
|
|
19
19
|
acc[d.symbol.toLowerCase()] = d;
|
|
20
20
|
return acc;
|
|
21
21
|
}, {});
|
|
22
|
-
const yearnAPY =
|
|
22
|
+
const yearnAPY = mappers_1.TypedObjectUtils.entries(yearn_1.yearnTokens).reduce((acc, [yearnSymbol]) => {
|
|
23
23
|
const { apy } = dataBySymbol[transformSymbol(yearnSymbol)] || {};
|
|
24
24
|
const { net_apy: netApy } = apy || {};
|
|
25
25
|
acc[yearnSymbol] = (0, formatter_1.toBN)((netApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
|
|
@@ -483,9 +483,11 @@ exports.contractParams = {
|
|
|
483
483
|
type: adapters_1.AdapterInterface.BALANCER_VAULT,
|
|
484
484
|
},
|
|
485
485
|
};
|
|
486
|
-
exports.contractsByAddress =
|
|
486
|
+
exports.contractsByAddress = mappers_1.TypedObjectUtils.entries(exports.contractsByNetwork).reduce((acc, [, contracts]) => ({
|
|
487
487
|
...acc,
|
|
488
|
-
...
|
|
488
|
+
...mappers_1.TypedObjectUtils.fromEntries(mappers_1.TypedObjectUtils.entries(contracts)
|
|
489
|
+
.map(([k, v]) => [v.toLowerCase(), k])
|
|
490
|
+
.filter(k => !!k)),
|
|
489
491
|
}), {});
|
|
490
492
|
const isSupportedContract = (t) => typeof t === "string" && !!exports.contractParams[t];
|
|
491
493
|
exports.isSupportedContract = isSupportedContract;
|
|
@@ -59,7 +59,7 @@ const contractNames = Object.entries(contracts_1.contractsByAddress).reduce((acc
|
|
|
59
59
|
return { ...acc, [addr]: params.name };
|
|
60
60
|
}, {});
|
|
61
61
|
const contractsFullList = {
|
|
62
|
-
...
|
|
62
|
+
...mappers_1.TypedObjectUtils.keyToLowercase(exports.deployedContracts),
|
|
63
63
|
...contractNames,
|
|
64
64
|
};
|
|
65
65
|
function getContractName(address) {
|
|
@@ -54,7 +54,7 @@ export declare class CreditAccountData {
|
|
|
54
54
|
isForbidden(token: string): boolean;
|
|
55
55
|
updateHealthFactor(creditManager: CreditManagerData, currentCumulativeIndex: bigint, priceOracle: PriceOracleData): void;
|
|
56
56
|
static isTokenEnabled(index: number, enabledTokenMask: bigint): boolean;
|
|
57
|
-
static
|
|
57
|
+
static calcMaxDebtIncrease(healthFactor: number, borrowAmountPlusInterest: bigint, underlyingLT: number, minHf?: number): bigint;
|
|
58
58
|
static calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }: CalcOverallAPYProps): number | undefined;
|
|
59
59
|
hash(): string;
|
|
60
60
|
static hash(creditManager: string, borrower: string): string;
|
|
@@ -117,13 +117,9 @@ class CreditAccountData {
|
|
|
117
117
|
static isTokenEnabled(index, enabledTokenMask) {
|
|
118
118
|
return ((2n ** BigInt(index)) & enabledTokenMask) !== 0n;
|
|
119
119
|
}
|
|
120
|
-
static
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
maxLeverageFactor)
|
|
124
|
-
: Number(minHf);
|
|
125
|
-
const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHealthFactor)) /
|
|
126
|
-
BigInt(minHealthFactor - underlyingLT);
|
|
120
|
+
static calcMaxDebtIncrease(healthFactor, borrowAmountPlusInterest, underlyingLT, minHf = Number(constants_1.PERCENTAGE_FACTOR)) {
|
|
121
|
+
const result = (borrowAmountPlusInterest * BigInt(healthFactor - minHf)) /
|
|
122
|
+
BigInt(minHf - underlyingLT);
|
|
127
123
|
return result < 0 ? 0n : result;
|
|
128
124
|
}
|
|
129
125
|
static calcOverallAPY({ caAssets, lpAPY, prices, totalValue, debt, borrowRate, underlyingToken, }) {
|
|
@@ -122,16 +122,16 @@ describe("CreditAccount CreditAccountData.calcOverallAPY test", () => {
|
|
|
122
122
|
});
|
|
123
123
|
describe("CreditAccount calcMaxIncreaseBorrow test", () => {
|
|
124
124
|
it("health max increase borrow is zero if hf < 1", () => {
|
|
125
|
-
const result = creditAccount_1.CreditAccountData.
|
|
125
|
+
const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(9999, BigInt("156522834253690396032546"), 9300);
|
|
126
126
|
(0, chai_1.expect)(result.toString()).to.be.eq("0");
|
|
127
127
|
});
|
|
128
128
|
it("health max increase borrow is calculated correctly", () => {
|
|
129
|
-
const result = creditAccount_1.CreditAccountData.
|
|
129
|
+
const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(10244, BigInt("156522834253690396032546"), 9300);
|
|
130
130
|
(0, chai_1.expect)(result.toString()).to.be.eq("54559387939857795188487");
|
|
131
131
|
});
|
|
132
132
|
it("health max increase borrow is calculated correctly (low hf, high debt)", () => {
|
|
133
133
|
const loweHf = 10244;
|
|
134
|
-
const result = creditAccount_1.CreditAccountData.
|
|
134
|
+
const result = creditAccount_1.CreditAccountData.calcMaxDebtIncrease(loweHf, BigInt("54782991988791638611392"), 9300);
|
|
135
135
|
(0, chai_1.expect)(result.toString()).to.be.eq("19095785778950228315970");
|
|
136
136
|
});
|
|
137
137
|
});
|
|
@@ -43,6 +43,8 @@ export declare class CreditSession {
|
|
|
43
43
|
readonly spotUserFunds: bigint;
|
|
44
44
|
readonly cvxUnclaimedRewards: Array<AssetWithView>;
|
|
45
45
|
readonly balances: Array<AssetWithView>;
|
|
46
|
+
readonly forbiddenTokens: Record<string, true>;
|
|
47
|
+
readonly disabledTokens: Record<string, true>;
|
|
46
48
|
constructor(payload: CreditSessionPayload);
|
|
47
49
|
}
|
|
48
50
|
export declare class CreditSessionFiltered {
|
|
@@ -16,7 +16,7 @@ exports.CREDIT_SESSION_STATUS_BY_ID = {
|
|
|
16
16
|
4: "liquidateExpired",
|
|
17
17
|
5: "liquidatePaused",
|
|
18
18
|
};
|
|
19
|
-
exports.CREDIT_SESSION_ID_BY_STATUS =
|
|
19
|
+
exports.CREDIT_SESSION_ID_BY_STATUS = mappers_1.TypedObjectUtils.swapKeyValue(exports.CREDIT_SESSION_STATUS_BY_ID);
|
|
20
20
|
class CreditSession {
|
|
21
21
|
id;
|
|
22
22
|
status;
|
|
@@ -58,7 +58,9 @@ class CreditSession {
|
|
|
58
58
|
spotTotalValue;
|
|
59
59
|
spotUserFunds;
|
|
60
60
|
cvxUnclaimedRewards;
|
|
61
|
-
balances;
|
|
61
|
+
balances = [];
|
|
62
|
+
forbiddenTokens = {};
|
|
63
|
+
disabledTokens = {};
|
|
62
64
|
constructor(payload) {
|
|
63
65
|
this.id = (payload.id || "").toLowerCase();
|
|
64
66
|
this.status = exports.CREDIT_SESSION_STATUS_BY_ID[payload.status || 0];
|
|
@@ -105,12 +107,19 @@ class CreditSession {
|
|
|
105
107
|
balanceView: balance.f.toString(),
|
|
106
108
|
};
|
|
107
109
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
Object.entries(payload.balances || {}).forEach(([t, b]) => {
|
|
111
|
+
const token = t.toLowerCase();
|
|
112
|
+
if (!b.isEnabled) {
|
|
113
|
+
this.disabledTokens[token] = true;
|
|
114
|
+
}
|
|
115
|
+
if (!b.isAllowed) {
|
|
116
|
+
this.forbiddenTokens[token] = true;
|
|
117
|
+
}
|
|
118
|
+
this.balances.push({
|
|
110
119
|
token: token.toLowerCase(),
|
|
111
|
-
balance: (0, formatter_1.toBigInt)(
|
|
112
|
-
balanceView:
|
|
113
|
-
};
|
|
120
|
+
balance: (0, formatter_1.toBigInt)(b.BI || 0),
|
|
121
|
+
balanceView: b.F.toString(),
|
|
122
|
+
});
|
|
114
123
|
});
|
|
115
124
|
}
|
|
116
125
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export { TokenType } from "./tokens/tokenType";
|
|
|
56
56
|
export * from "./tokens/yearn";
|
|
57
57
|
export * from "./utils/errors";
|
|
58
58
|
export { getPoolTokens, getUnderlyingToken } from "./utils/extracter";
|
|
59
|
-
export
|
|
59
|
+
export * from "./utils/mappers";
|
|
60
60
|
export * from "./utils/multicall";
|
|
61
61
|
export * from "./utils/price";
|
|
62
62
|
export { callRepeater } from "./utils/repeater";
|
package/lib/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.callRepeater = exports.
|
|
17
|
+
exports.callRepeater = exports.getUnderlyingToken = exports.getPoolTokens = exports.TokenType = exports.AdapterInterface = void 0;
|
|
18
18
|
__exportStar(require("./contracts/contracts"), exports);
|
|
19
19
|
__exportStar(require("./contracts/protocols"), exports);
|
|
20
20
|
__exportStar(require("./core/adapter"), exports);
|
|
@@ -78,10 +78,7 @@ __exportStar(require("./utils/errors"), exports);
|
|
|
78
78
|
var extracter_1 = require("./utils/extracter");
|
|
79
79
|
Object.defineProperty(exports, "getPoolTokens", { enumerable: true, get: function () { return extracter_1.getPoolTokens; } });
|
|
80
80
|
Object.defineProperty(exports, "getUnderlyingToken", { enumerable: true, get: function () { return extracter_1.getUnderlyingToken; } });
|
|
81
|
-
|
|
82
|
-
Object.defineProperty(exports, "keyToLowercase", { enumerable: true, get: function () { return mappers_1.keyToLowercase; } });
|
|
83
|
-
Object.defineProperty(exports, "objectEntries", { enumerable: true, get: function () { return mappers_1.objectEntries; } });
|
|
84
|
-
Object.defineProperty(exports, "swapKeyValue", { enumerable: true, get: function () { return mappers_1.swapKeyValue; } });
|
|
81
|
+
__exportStar(require("./utils/mappers"), exports);
|
|
85
82
|
__exportStar(require("./utils/multicall"), exports);
|
|
86
83
|
__exportStar(require("./utils/price"), exports);
|
|
87
84
|
var repeater_1 = require("./utils/repeater");
|
package/lib/parsers/txParser.js
CHANGED
|
@@ -58,7 +58,7 @@ class TxParser {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
static addContracts(network) {
|
|
61
|
-
|
|
61
|
+
mappers_1.TypedObjectUtils.entries(contracts_1.contractParams).forEach(([contract, contractData]) => {
|
|
62
62
|
const address = contracts_1.contractsByNetwork[network][contract];
|
|
63
63
|
TxParser.chooseContractParser(address, contract, contractData.type, true);
|
|
64
64
|
if (contractData.type === adapters_1.AdapterInterface.CONVEX_V1_BASE_REWARD_POOL) {
|
|
@@ -77,7 +77,7 @@ class TxParser {
|
|
|
77
77
|
TxParser._addParser(creditFacade, new creditFacadeParser_1.CreditFacadeParser(underlying));
|
|
78
78
|
}
|
|
79
79
|
static addTokens(network) {
|
|
80
|
-
|
|
80
|
+
mappers_1.TypedObjectUtils.entries(token_1.tokenDataByNetwork[network]).forEach(([s, t]) => {
|
|
81
81
|
if (s === "STETH") {
|
|
82
82
|
TxParser._addParser(t, new lidoSTETHParser_1.LidoSTETHParser(s));
|
|
83
83
|
}
|
package/lib/tokens/token.js
CHANGED
|
@@ -222,9 +222,14 @@ exports.tokenDataByNetwork = {
|
|
|
222
222
|
GEAR: constants_1.NOT_DEPLOYED,
|
|
223
223
|
},
|
|
224
224
|
};
|
|
225
|
-
exports.tokenSymbolByAddress =
|
|
225
|
+
exports.tokenSymbolByAddress = mappers_1.TypedObjectUtils.entries(exports.tokenDataByNetwork).reduce((acc, [, tokens]) => ({
|
|
226
226
|
...acc,
|
|
227
|
-
...
|
|
227
|
+
...{
|
|
228
|
+
...acc,
|
|
229
|
+
...mappers_1.TypedObjectUtils.fromEntries(mappers_1.TypedObjectUtils.entries(tokens)
|
|
230
|
+
.map(([k, v]) => [v.toLowerCase(), k])
|
|
231
|
+
.filter(k => !!k)),
|
|
232
|
+
},
|
|
228
233
|
}), {});
|
|
229
234
|
const isSupportedToken = (t) => typeof t === "string" && !!exports.supportedTokens[t];
|
|
230
235
|
exports.isSupportedToken = isSupportedToken;
|
package/lib/utils/mappers.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
type SupportedValue = string | number;
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare class TypedObjectUtils {
|
|
3
|
+
static entries: <K extends SupportedValue, T>(o: Record<K, T>) => [K, T][];
|
|
4
|
+
static fromEntries: <K extends SupportedValue, T>(o: [K, T][]) => Record<K, T>;
|
|
5
|
+
static swapKeyValue: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<T, K>;
|
|
6
|
+
static keyToLowercase: <K extends SupportedValue, T>(o: Record<K, T>) => Record<K, T>;
|
|
7
|
+
}
|
|
6
8
|
export type { SupportedValue };
|
|
7
|
-
export { filterEmptyKeys, keyToLowercase, objectEntries, swapKeyValue };
|
package/lib/utils/mappers.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}, {});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.filterEmptyKeys = filterEmptyKeys;
|
|
3
|
+
exports.TypedObjectUtils = void 0;
|
|
4
|
+
class TypedObjectUtils {
|
|
5
|
+
static entries = (o) => Object.entries(o);
|
|
6
|
+
static fromEntries = (o) => Object.fromEntries(o);
|
|
7
|
+
static swapKeyValue = (o) => TypedObjectUtils.entries(o).reduce((acc, [key, value]) => ({ ...acc, [value]: key }), {});
|
|
8
|
+
static keyToLowercase = (o) => TypedObjectUtils.entries(o).reduce((acc, [key, value]) => {
|
|
9
|
+
const keyTransformed = typeof key === "string" ? key.toLowerCase() : key;
|
|
10
|
+
return { ...acc, [keyTransformed]: value };
|
|
11
|
+
}, {});
|
|
12
|
+
}
|
|
13
|
+
exports.TypedObjectUtils = TypedObjectUtils;
|