@gearbox-protocol/sdk 3.0.0-next.181 → 3.0.0-next.183
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.
|
@@ -60,12 +60,10 @@ export interface CalcRelativeBaseBorrowRateProps {
|
|
|
60
60
|
debt: bigint;
|
|
61
61
|
baseRateWithFee: number;
|
|
62
62
|
assetAmountInUnderlying: bigint;
|
|
63
|
-
totalValue: bigint;
|
|
64
63
|
}
|
|
65
64
|
export interface CalcAvgQuotaBorrowRateProps {
|
|
66
65
|
quotas: Record<string, Asset>;
|
|
67
66
|
quotaRates: Record<string, Pick<QuotaInfo, "isActive" | "rate">>;
|
|
68
|
-
totalValue: bigint;
|
|
69
67
|
}
|
|
70
68
|
interface LiquidationPriceProps {
|
|
71
69
|
liquidationThresholds: Record<string, bigint>;
|
|
@@ -127,7 +125,7 @@ export declare class CreditAccountData {
|
|
|
127
125
|
static calcQuotaUpdate(props: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
|
|
128
126
|
private static getSingleQuotaChange;
|
|
129
127
|
static calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
|
|
130
|
-
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying,
|
|
128
|
+
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying, }: CalcRelativeBaseBorrowRateProps): bigint;
|
|
131
129
|
static liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, }: LiquidationPriceProps): bigint;
|
|
132
130
|
}
|
|
133
131
|
export {};
|
|
@@ -341,10 +341,8 @@ class CreditAccountData {
|
|
|
341
341
|
}, 0n);
|
|
342
342
|
return totalRateBalance;
|
|
343
343
|
}
|
|
344
|
-
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying,
|
|
345
|
-
|
|
346
|
-
return 0n;
|
|
347
|
-
return ((debt * BigInt(baseRateWithFee) * assetAmountInUnderlying) / totalValue);
|
|
344
|
+
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying, }) {
|
|
345
|
+
return debt * BigInt(baseRateWithFee) * assetAmountInUnderlying;
|
|
348
346
|
}
|
|
349
347
|
static liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, }) {
|
|
350
348
|
const underlyingTokenLC = underlyingToken.toLowerCase();
|
|
@@ -1429,25 +1429,22 @@ describe("CreditAccount calcRelativeBaseBorrowRate test", () => {
|
|
|
1429
1429
|
debt: 200n,
|
|
1430
1430
|
baseRateWithFee: 250,
|
|
1431
1431
|
assetAmountInUnderlying: 200n,
|
|
1432
|
-
totalValue: 400n,
|
|
1433
1432
|
});
|
|
1434
|
-
(0, chai_1.expect)(result).to.be.eq(
|
|
1433
|
+
(0, chai_1.expect)(result).to.be.eq(10000000n);
|
|
1435
1434
|
});
|
|
1436
1435
|
it("should calculate relative borrow rate if position asset === 0", () => {
|
|
1437
1436
|
const result = creditAccount_1.CreditAccountData.calcRelativeBaseBorrowRate({
|
|
1438
1437
|
debt: 200n,
|
|
1439
1438
|
baseRateWithFee: 250,
|
|
1440
1439
|
assetAmountInUnderlying: 1n,
|
|
1441
|
-
totalValue: 400n,
|
|
1442
1440
|
});
|
|
1443
|
-
(0, chai_1.expect)(result).to.be.eq(
|
|
1441
|
+
(0, chai_1.expect)(result).to.be.eq(50000n);
|
|
1444
1442
|
});
|
|
1445
1443
|
it("should calculate relative borrow rate if position === 0", () => {
|
|
1446
1444
|
const result = creditAccount_1.CreditAccountData.calcRelativeBaseBorrowRate({
|
|
1447
1445
|
debt: 1n,
|
|
1448
1446
|
baseRateWithFee: 250,
|
|
1449
1447
|
assetAmountInUnderlying: 1n,
|
|
1450
|
-
totalValue: 1n,
|
|
1451
1448
|
});
|
|
1452
1449
|
(0, chai_1.expect)(result).to.be.eq(250n);
|
|
1453
1450
|
});
|
|
@@ -31,6 +31,7 @@ export declare class CreditManagerData {
|
|
|
31
31
|
readonly liquidationDiscountExpired: number;
|
|
32
32
|
readonly collateralTokens: Array<string>;
|
|
33
33
|
readonly supportedTokens: Record<string, true>;
|
|
34
|
+
readonly usableTokens: Record<string, true>;
|
|
34
35
|
readonly adapters: Record<string, string>;
|
|
35
36
|
readonly contractsByAdapter: Record<string, string>;
|
|
36
37
|
readonly liquidationThresholds: Record<string, bigint>;
|
|
@@ -32,6 +32,7 @@ class CreditManagerData {
|
|
|
32
32
|
liquidationDiscountExpired;
|
|
33
33
|
collateralTokens = [];
|
|
34
34
|
supportedTokens = {};
|
|
35
|
+
usableTokens = {};
|
|
35
36
|
adapters;
|
|
36
37
|
contractsByAdapter;
|
|
37
38
|
liquidationThresholds;
|
|
@@ -66,11 +67,6 @@ class CreditManagerData {
|
|
|
66
67
|
this.liquidationDiscount = Number(payload.liquidationDiscount);
|
|
67
68
|
this.feeLiquidationExpired = Number(payload.feeLiquidationExpired);
|
|
68
69
|
this.liquidationDiscountExpired = Number(payload.liquidationDiscountExpired);
|
|
69
|
-
payload.collateralTokens.forEach(t => {
|
|
70
|
-
const tLc = t.toLowerCase();
|
|
71
|
-
this.collateralTokens.push(tLc);
|
|
72
|
-
this.supportedTokens[tLc] = true;
|
|
73
|
-
});
|
|
74
70
|
this.adapters = Object.fromEntries(payload.adapters.map(a => [
|
|
75
71
|
a.targetContract.toLowerCase(),
|
|
76
72
|
a.adapter.toLowerCase(),
|
|
@@ -107,6 +103,16 @@ class CreditManagerData {
|
|
|
107
103
|
version: Number(payload?.lirm?.version),
|
|
108
104
|
isBorrowingMoreU2Forbidden: payload?.lirm?.isBorrowingMoreU2Forbidden,
|
|
109
105
|
};
|
|
106
|
+
payload.collateralTokens.forEach(t => {
|
|
107
|
+
const tLc = t.toLowerCase();
|
|
108
|
+
const zeroLt = this.liquidationThresholds[tLc] === 0n;
|
|
109
|
+
const quotaNotActive = this.quotas[tLc]?.isActive === false;
|
|
110
|
+
const allowed = !zeroLt && !quotaNotActive;
|
|
111
|
+
if (allowed)
|
|
112
|
+
this.usableTokens[tLc] = true;
|
|
113
|
+
this.collateralTokens.push(tLc);
|
|
114
|
+
this.supportedTokens[tLc] = true;
|
|
115
|
+
});
|
|
110
116
|
txParser_1.TxParser.addCreditManager(this.address, this.version);
|
|
111
117
|
if (this.creditFacade !== "" && this.creditFacade !== sdk_gov_1.ADDRESS_0X0) {
|
|
112
118
|
txParser_1.TxParser.addCreditFacade(this.creditFacade, sdk_gov_1.tokenSymbolByAddress[this.underlyingToken], this.version);
|
|
@@ -18,17 +18,15 @@ const EXTRA_LM_MINING = {
|
|
|
18
18
|
const REWARD_PERIOD = 14 * 24 * 60 * 60;
|
|
19
19
|
// const REWARDS_FIRST_START = 1711641600;
|
|
20
20
|
// const REWARDS_FIRST_END = 1712844000;
|
|
21
|
-
const REWARDS_SECOND_END = 1714150800;
|
|
22
|
-
const REWARDS_THIRD_END =
|
|
21
|
+
// const REWARDS_SECOND_END = 1714150800;
|
|
22
|
+
const REWARDS_THIRD_END = 1715374800;
|
|
23
|
+
const REWARDS_FOURTH_END = REWARDS_THIRD_END + REWARD_PERIOD;
|
|
23
24
|
// const REWARD_FIRST_PART = toBN("15000", decimals.GHO);
|
|
24
|
-
const REWARD_SECOND_PART =
|
|
25
|
+
// const REWARD_SECOND_PART = toBN("15000", decimals.GHO);
|
|
25
26
|
const REWARD_THIRD_PART = (0, formatter_1.toBN)("15000", sdk_gov_1.decimals.GHO);
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const finished = timestamp >= REWARDS_SECOND_END
|
|
30
|
-
? REWARDS_THIRD_END
|
|
31
|
-
: REWARDS_SECOND_END;
|
|
27
|
+
const REWARD_FOURTH_PART = (0, formatter_1.toBN)("7500", sdk_gov_1.decimals.GHO);
|
|
28
|
+
const reward = timestamp >= REWARDS_THIRD_END ? REWARD_FOURTH_PART : REWARD_THIRD_PART;
|
|
29
|
+
const finished = timestamp >= REWARDS_THIRD_END ? REWARDS_FOURTH_END : REWARDS_THIRD_END;
|
|
32
30
|
return {
|
|
33
31
|
balance: 0n,
|
|
34
32
|
duration: BigInt(REWARD_PERIOD),
|
|
@@ -237,6 +235,7 @@ class GearboxRewardsApi {
|
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
exports.GearboxRewardsApi = GearboxRewardsApi;
|
|
238
|
+
// https://api.merkl.xyz/v3/campaignsForMainParameter?chainId=1&mainParameter=0xE2037090f896A858E3168B978668F22026AC52e7
|
|
240
239
|
class MerkleXYZApi {
|
|
241
240
|
static domain = "https://api.merkl.xyz/v3";
|
|
242
241
|
static getRewardsUrl = (options) => endpoint_1.ChartsApi.getRelativeUrl([this.domain, "userRewards"].join("/"), options);
|