@gearbox-protocol/sdk 3.0.0-next.100 → 3.0.0-next.102
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/index.d.ts +1 -0
- package/lib/apy/index.js +1 -0
- package/lib/apy/maker.d.ts +39 -0
- package/lib/apy/maker.js +65 -0
- package/lib/core/creditAccount.d.ts +15 -1
- package/lib/core/creditAccount.js +20 -3
- package/lib/core/creditAccount.spec.js +163 -1
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +2 -2
- package/package.json +1 -1
package/lib/apy/index.d.ts
CHANGED
package/lib/apy/index.js
CHANGED
|
@@ -26,4 +26,5 @@ exports.isTokenWithAPY = isTokenWithAPY;
|
|
|
26
26
|
__exportStar(require("./convexAPY"), exports);
|
|
27
27
|
__exportStar(require("./curveAPY"), exports);
|
|
28
28
|
__exportStar(require("./lidoAPY"), exports);
|
|
29
|
+
__exportStar(require("./maker"), exports);
|
|
29
30
|
__exportStar(require("./yearnAPY"), exports);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ERC4626Params, ERC4626VaultContract, NetworkType } from "@gearbox-protocol/sdk-gov";
|
|
2
|
+
import { BigNumber } from "ethers";
|
|
3
|
+
import { Interface } from "ethers/lib/utils";
|
|
4
|
+
export declare const MAKER_VAULT_ABI: {
|
|
5
|
+
inputs: never[];
|
|
6
|
+
name: string;
|
|
7
|
+
outputs: {
|
|
8
|
+
internalType: string;
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[];
|
|
12
|
+
stateMutability: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const MAKER_VAULT_INTERFACE: Interface;
|
|
16
|
+
export type MakerPoolContract = Extract<ERC4626VaultContract, "MAKER_DSR_VAULT">;
|
|
17
|
+
interface PoolInfo {
|
|
18
|
+
pool: ERC4626Params;
|
|
19
|
+
poolAddress: string;
|
|
20
|
+
}
|
|
21
|
+
export interface GetMakerAPYBulkCallsProps {
|
|
22
|
+
pools: Array<MakerPoolContract>;
|
|
23
|
+
networkType: NetworkType;
|
|
24
|
+
}
|
|
25
|
+
export declare function getMakerAPYBulkCalls({ pools, networkType, }: GetMakerAPYBulkCallsProps): {
|
|
26
|
+
poolsInfo: PoolInfo[];
|
|
27
|
+
calls: {
|
|
28
|
+
address: string;
|
|
29
|
+
interface: Interface;
|
|
30
|
+
method: string;
|
|
31
|
+
}[];
|
|
32
|
+
};
|
|
33
|
+
type GetMakerAPYBulkCallsReturns = ReturnType<typeof getMakerAPYBulkCalls>;
|
|
34
|
+
export interface GetMakerAPYBulkProps {
|
|
35
|
+
generated: GetMakerAPYBulkCallsReturns;
|
|
36
|
+
response: Array<BigNumber>;
|
|
37
|
+
}
|
|
38
|
+
export declare function getMakerAPYBulk(props: GetMakerAPYBulkProps): bigint[];
|
|
39
|
+
export {};
|
package/lib/apy/maker.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMakerAPYBulk = exports.getMakerAPYBulkCalls = exports.MAKER_VAULT_INTERFACE = exports.MAKER_VAULT_ABI = void 0;
|
|
4
|
+
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
5
|
+
const utils_1 = require("ethers/lib/utils");
|
|
6
|
+
const formatter_1 = require("../utils/formatter");
|
|
7
|
+
exports.MAKER_VAULT_ABI = [
|
|
8
|
+
{
|
|
9
|
+
inputs: [],
|
|
10
|
+
name: "dsr",
|
|
11
|
+
outputs: [
|
|
12
|
+
{
|
|
13
|
+
internalType: "uint256",
|
|
14
|
+
name: "",
|
|
15
|
+
type: "uint256",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
stateMutability: "view",
|
|
19
|
+
type: "function",
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
exports.MAKER_VAULT_INTERFACE = new utils_1.Interface(exports.MAKER_VAULT_ABI);
|
|
23
|
+
const MAKER_BY_NETWORK = {
|
|
24
|
+
Mainnet: {
|
|
25
|
+
MAKER_DSR_VAULT: "0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7",
|
|
26
|
+
},
|
|
27
|
+
Arbitrum: {
|
|
28
|
+
MAKER_DSR_VAULT: "",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
function getMakerAPYBulkCalls({ pools, networkType, }) {
|
|
32
|
+
const poolsInfo = pools.map((pool) => {
|
|
33
|
+
const poolParams = sdk_gov_1.contractParams[pool];
|
|
34
|
+
const basePoolAddress = MAKER_BY_NETWORK[networkType][pool];
|
|
35
|
+
return {
|
|
36
|
+
pool: poolParams,
|
|
37
|
+
poolAddress: basePoolAddress,
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
const calls = poolsInfo.map(info => ({
|
|
41
|
+
address: info.poolAddress,
|
|
42
|
+
interface: exports.MAKER_VAULT_INTERFACE,
|
|
43
|
+
method: "dsr()",
|
|
44
|
+
}));
|
|
45
|
+
return { poolsInfo, calls };
|
|
46
|
+
}
|
|
47
|
+
exports.getMakerAPYBulkCalls = getMakerAPYBulkCalls;
|
|
48
|
+
function getMakerAPYBulk(props) {
|
|
49
|
+
const { poolsInfo } = props.generated;
|
|
50
|
+
const apyList = props.response.map((baseApy, i) => {
|
|
51
|
+
const apy = calculateMakerAPY({
|
|
52
|
+
baseApy: (0, sdk_gov_1.toBigInt)(baseApy),
|
|
53
|
+
poolInfo: poolsInfo[i],
|
|
54
|
+
});
|
|
55
|
+
return apy;
|
|
56
|
+
});
|
|
57
|
+
return apyList;
|
|
58
|
+
}
|
|
59
|
+
exports.getMakerAPYBulk = getMakerAPYBulk;
|
|
60
|
+
const POW = 3600 * 24 * 365;
|
|
61
|
+
function calculateMakerAPY(props) {
|
|
62
|
+
const rateFloat = Number((0, formatter_1.toSignificant)(props.baseApy, 27, 27));
|
|
63
|
+
const rate = Math.max(0, rateFloat ** POW - 1);
|
|
64
|
+
return (0, formatter_1.toBN)(rate.toString(), sdk_gov_1.WAD_DECIMALS_POW);
|
|
65
|
+
}
|
|
@@ -24,9 +24,21 @@ export interface CalcHealthFactorProps {
|
|
|
24
24
|
underlyingToken: string;
|
|
25
25
|
debt: bigint;
|
|
26
26
|
}
|
|
27
|
+
export interface CalcDefaultQuotaProps {
|
|
28
|
+
amount: bigint;
|
|
29
|
+
lt: bigint;
|
|
30
|
+
quotaReserve: bigint;
|
|
31
|
+
}
|
|
32
|
+
export interface CalcRecommendedQuotaProps {
|
|
33
|
+
amount: bigint;
|
|
34
|
+
debt: bigint;
|
|
35
|
+
lt: bigint;
|
|
36
|
+
quotaReserve: bigint;
|
|
37
|
+
}
|
|
27
38
|
export interface CalcQuotaUpdateProps {
|
|
28
39
|
quotas: Record<string, Pick<QuotaInfo, "isActive" | "token">>;
|
|
29
40
|
initialQuotas: Record<string, Pick<CaTokenBalance, "quota">>;
|
|
41
|
+
liquidationThresholds: Record<string, bigint>;
|
|
30
42
|
assetsAfterUpdate: Record<string, AssetWithAmountInTarget>;
|
|
31
43
|
allowedToSpend: Record<string, {}>;
|
|
32
44
|
allowedToObtain: Record<string, {}>;
|
|
@@ -104,7 +116,9 @@ export declare class CreditAccountData {
|
|
|
104
116
|
hash(): string;
|
|
105
117
|
static hash(creditManager: string, borrower: string): string;
|
|
106
118
|
static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, }: CalcHealthFactorProps): number;
|
|
107
|
-
static
|
|
119
|
+
static calcRecommendedQuota({ amount, debt, lt, quotaReserve, }: CalcRecommendedQuotaProps): bigint;
|
|
120
|
+
static calcDefaultQuota({ amount, lt, quotaReserve }: CalcDefaultQuotaProps): bigint;
|
|
121
|
+
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, liquidationThresholds, allowedToSpend, allowedToObtain, quotaReserve, }: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
|
|
108
122
|
static calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
|
|
109
123
|
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying, totalValue, }: CalcRelativeBaseBorrowRateProps): bigint;
|
|
110
124
|
static liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, }: LiquidationPriceProps): bigint;
|
|
@@ -204,7 +204,19 @@ class CreditAccountData {
|
|
|
204
204
|
: 0n;
|
|
205
205
|
return Number(hfInPercent);
|
|
206
206
|
}
|
|
207
|
-
static
|
|
207
|
+
static calcRecommendedQuota({ amount, debt, lt, quotaReserve, }) {
|
|
208
|
+
const recommendedBaseQuota = math_1.BigIntMath.min(debt, (amount * lt) / sdk_gov_1.PERCENTAGE_FACTOR);
|
|
209
|
+
const recommendedQuota = (recommendedBaseQuota * (sdk_gov_1.PERCENTAGE_FACTOR + quotaReserve)) /
|
|
210
|
+
sdk_gov_1.PERCENTAGE_FACTOR;
|
|
211
|
+
return recommendedQuota;
|
|
212
|
+
}
|
|
213
|
+
static calcDefaultQuota({ amount, lt, quotaReserve }) {
|
|
214
|
+
const recommendedBaseQuota = (amount * lt) / sdk_gov_1.PERCENTAGE_FACTOR;
|
|
215
|
+
const recommendedQuota = (recommendedBaseQuota * (sdk_gov_1.PERCENTAGE_FACTOR + quotaReserve)) /
|
|
216
|
+
sdk_gov_1.PERCENTAGE_FACTOR;
|
|
217
|
+
return recommendedQuota;
|
|
218
|
+
}
|
|
219
|
+
static calcQuotaUpdate({ quotas, initialQuotas, assetsAfterUpdate, liquidationThresholds, allowedToSpend, allowedToObtain, quotaReserve, }) {
|
|
208
220
|
const r = Object.values(quotas).reduce((acc, cmQuota) => {
|
|
209
221
|
const { token, isActive } = cmQuota;
|
|
210
222
|
const { quota: initialQuota = 0n } = initialQuotas[token] || {};
|
|
@@ -215,10 +227,15 @@ class CreditAccountData {
|
|
|
215
227
|
};
|
|
216
228
|
return acc;
|
|
217
229
|
}
|
|
230
|
+
// min(debt,assetAmountInUnderlying*LT)*(1+buffer)
|
|
218
231
|
const after = assetsAfterUpdate[token];
|
|
219
232
|
const { amountInTarget = 0n } = after || {};
|
|
220
|
-
const
|
|
221
|
-
|
|
233
|
+
const lt = liquidationThresholds[token] || 0n;
|
|
234
|
+
const desiredQuota = this.calcDefaultQuota({
|
|
235
|
+
lt,
|
|
236
|
+
quotaReserve,
|
|
237
|
+
amount: amountInTarget,
|
|
238
|
+
});
|
|
222
239
|
const quotaChange = desiredQuota - initialQuota;
|
|
223
240
|
const correctIncrease = after && allowedToObtain[token] && quotaChange > 0;
|
|
224
241
|
const correctDecrease = after && allowedToSpend[token] && quotaChange < 0;
|
|
@@ -6,7 +6,6 @@ const formatter_1 = require("../utils/formatter");
|
|
|
6
6
|
const price_1 = require("../utils/price");
|
|
7
7
|
const assets_1 = require("./assets");
|
|
8
8
|
const creditAccount_1 = require("./creditAccount");
|
|
9
|
-
const QUOTA_RESERVE = 100n;
|
|
10
9
|
const prices = {
|
|
11
10
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH.toLowerCase()]: (0, formatter_1.toBN)("1738.11830000", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
12
11
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI.toLowerCase()]: (0, formatter_1.toBN)("0.99941103", sdk_gov_1.PRICE_DECIMALS_POW),
|
|
@@ -417,6 +416,12 @@ const caQuota = {
|
|
|
417
416
|
quota: 10n,
|
|
418
417
|
},
|
|
419
418
|
};
|
|
419
|
+
const QUOTA_RESERVE = 100n;
|
|
420
|
+
const DEFAULT_LT = {
|
|
421
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: sdk_gov_1.PERCENTAGE_FACTOR,
|
|
422
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: sdk_gov_1.PERCENTAGE_FACTOR,
|
|
423
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: sdk_gov_1.PERCENTAGE_FACTOR,
|
|
424
|
+
};
|
|
420
425
|
describe("CreditAccount calcQuotaUpdate test", () => {
|
|
421
426
|
it("open account should buy quota", () => {
|
|
422
427
|
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
@@ -440,6 +445,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
440
445
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
441
446
|
},
|
|
442
447
|
allowedToSpend: {},
|
|
448
|
+
liquidationThresholds: DEFAULT_LT,
|
|
443
449
|
});
|
|
444
450
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
445
451
|
{
|
|
@@ -483,6 +489,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
483
489
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {},
|
|
484
490
|
},
|
|
485
491
|
allowedToSpend: {},
|
|
492
|
+
liquidationThresholds: DEFAULT_LT,
|
|
486
493
|
});
|
|
487
494
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
488
495
|
{
|
|
@@ -522,6 +529,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
522
529
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {},
|
|
523
530
|
},
|
|
524
531
|
allowedToSpend: {},
|
|
532
|
+
liquidationThresholds: DEFAULT_LT,
|
|
525
533
|
});
|
|
526
534
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
527
535
|
{
|
|
@@ -561,6 +569,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
561
569
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
562
570
|
},
|
|
563
571
|
allowedToSpend: {},
|
|
572
|
+
liquidationThresholds: DEFAULT_LT,
|
|
564
573
|
});
|
|
565
574
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
566
575
|
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([]);
|
|
@@ -600,6 +609,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
600
609
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {},
|
|
601
610
|
},
|
|
602
611
|
allowedToSpend: { [sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {} },
|
|
612
|
+
liquidationThresholds: DEFAULT_LT,
|
|
603
613
|
});
|
|
604
614
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
605
615
|
{
|
|
@@ -648,6 +658,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
648
658
|
allowedToSpend: {
|
|
649
659
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
650
660
|
},
|
|
661
|
+
liquidationThresholds: DEFAULT_LT,
|
|
651
662
|
});
|
|
652
663
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
653
664
|
{
|
|
@@ -697,6 +708,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
697
708
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
698
709
|
},
|
|
699
710
|
allowedToSpend: { [sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {} },
|
|
711
|
+
liquidationThresholds: DEFAULT_LT,
|
|
700
712
|
});
|
|
701
713
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
702
714
|
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([
|
|
@@ -739,6 +751,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
739
751
|
},
|
|
740
752
|
allowedToObtain: {},
|
|
741
753
|
allowedToSpend: {},
|
|
754
|
+
liquidationThresholds: DEFAULT_LT,
|
|
742
755
|
});
|
|
743
756
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
744
757
|
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([]);
|
|
@@ -793,6 +806,7 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
793
806
|
allowedToSpend: {
|
|
794
807
|
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {},
|
|
795
808
|
},
|
|
809
|
+
liquidationThresholds: DEFAULT_LT,
|
|
796
810
|
});
|
|
797
811
|
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
798
812
|
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([]);
|
|
@@ -811,6 +825,154 @@ describe("CreditAccount calcQuotaUpdate test", () => {
|
|
|
811
825
|
},
|
|
812
826
|
});
|
|
813
827
|
});
|
|
828
|
+
it("swap shouldn't buy quota if no lt", () => {
|
|
829
|
+
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
830
|
+
quotaReserve: QUOTA_RESERVE,
|
|
831
|
+
quotas: cmQuotas,
|
|
832
|
+
initialQuotas: {
|
|
833
|
+
...caQuota,
|
|
834
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
835
|
+
quota: 5n,
|
|
836
|
+
},
|
|
837
|
+
},
|
|
838
|
+
assetsAfterUpdate: {
|
|
839
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
840
|
+
amountInTarget: 10n,
|
|
841
|
+
balance: 0n,
|
|
842
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
843
|
+
},
|
|
844
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
845
|
+
amountInTarget: 5n,
|
|
846
|
+
balance: 0n,
|
|
847
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
848
|
+
},
|
|
849
|
+
},
|
|
850
|
+
allowedToObtain: {
|
|
851
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {},
|
|
852
|
+
},
|
|
853
|
+
allowedToSpend: { [sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {} },
|
|
854
|
+
liquidationThresholds: {},
|
|
855
|
+
});
|
|
856
|
+
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
857
|
+
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([
|
|
858
|
+
{ balance: -10n, token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH },
|
|
859
|
+
]);
|
|
860
|
+
(0, chai_1.expect)(result.desiredQuota).to.be.deep.eq({
|
|
861
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
862
|
+
balance: 5n,
|
|
863
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
864
|
+
},
|
|
865
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
866
|
+
balance: 0n,
|
|
867
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
868
|
+
},
|
|
869
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
870
|
+
balance: 5n,
|
|
871
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH,
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
it("swap should buy quota with respect to lt", () => {
|
|
876
|
+
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
877
|
+
quotaReserve: QUOTA_RESERVE,
|
|
878
|
+
quotas: cmQuotas,
|
|
879
|
+
initialQuotas: {
|
|
880
|
+
...caQuota,
|
|
881
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: { quota: 5n },
|
|
882
|
+
},
|
|
883
|
+
assetsAfterUpdate: {
|
|
884
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
885
|
+
amountInTarget: 20n,
|
|
886
|
+
balance: 0n,
|
|
887
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
888
|
+
},
|
|
889
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
890
|
+
amountInTarget: 5n,
|
|
891
|
+
balance: 0n,
|
|
892
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
allowedToObtain: {
|
|
896
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {},
|
|
897
|
+
},
|
|
898
|
+
allowedToSpend: { [sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {} },
|
|
899
|
+
liquidationThresholds: {
|
|
900
|
+
...DEFAULT_LT,
|
|
901
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: 5000n,
|
|
902
|
+
},
|
|
903
|
+
});
|
|
904
|
+
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([
|
|
905
|
+
{
|
|
906
|
+
balance: 5n,
|
|
907
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH,
|
|
908
|
+
},
|
|
909
|
+
]);
|
|
910
|
+
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([
|
|
911
|
+
{ balance: -5n, token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH },
|
|
912
|
+
]);
|
|
913
|
+
(0, chai_1.expect)(result.desiredQuota).to.be.deep.eq({
|
|
914
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
915
|
+
balance: 5n,
|
|
916
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
917
|
+
},
|
|
918
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
919
|
+
balance: 5n,
|
|
920
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
921
|
+
},
|
|
922
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
923
|
+
balance: 10n,
|
|
924
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH,
|
|
925
|
+
},
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
it("swap shouldn't buy quota with respect to lt", () => {
|
|
929
|
+
const result = creditAccount_1.CreditAccountData.calcQuotaUpdate({
|
|
930
|
+
quotaReserve: QUOTA_RESERVE,
|
|
931
|
+
quotas: cmQuotas,
|
|
932
|
+
initialQuotas: {
|
|
933
|
+
...caQuota,
|
|
934
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: { quota: 5n },
|
|
935
|
+
},
|
|
936
|
+
assetsAfterUpdate: {
|
|
937
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
938
|
+
amountInTarget: 10n,
|
|
939
|
+
balance: 0n,
|
|
940
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
941
|
+
},
|
|
942
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
943
|
+
amountInTarget: 5n,
|
|
944
|
+
balance: 0n,
|
|
945
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
946
|
+
},
|
|
947
|
+
},
|
|
948
|
+
allowedToObtain: {
|
|
949
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {},
|
|
950
|
+
},
|
|
951
|
+
allowedToSpend: { [sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {} },
|
|
952
|
+
liquidationThresholds: {
|
|
953
|
+
...DEFAULT_LT,
|
|
954
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: 5000n,
|
|
955
|
+
},
|
|
956
|
+
});
|
|
957
|
+
(0, chai_1.expect)(result.quotaIncrease).to.be.deep.eq([]);
|
|
958
|
+
(0, chai_1.expect)(result.quotaDecrease).to.be.deep.eq([
|
|
959
|
+
{ balance: -5n, token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH },
|
|
960
|
+
]);
|
|
961
|
+
(0, chai_1.expect)(result.desiredQuota).to.be.deep.eq({
|
|
962
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.DAI]: {
|
|
963
|
+
balance: 5n,
|
|
964
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.DAI,
|
|
965
|
+
},
|
|
966
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.WETH]: {
|
|
967
|
+
balance: 5n,
|
|
968
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.WETH,
|
|
969
|
+
},
|
|
970
|
+
[sdk_gov_1.tokenDataByNetwork.Mainnet.STETH]: {
|
|
971
|
+
balance: 5n,
|
|
972
|
+
token: sdk_gov_1.tokenDataByNetwork.Mainnet.STETH,
|
|
973
|
+
},
|
|
974
|
+
});
|
|
975
|
+
});
|
|
814
976
|
});
|
|
815
977
|
describe("CreditAccount calcAvgQuotaBorrowRate test", () => {
|
|
816
978
|
it("should calculate quota rate (same amounts, different rates)", () => {
|
package/lib/utils/formatter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
2
|
export declare function rayToNumber(num: BigNumberish): number;
|
|
3
3
|
export declare function formatRAY(num?: bigint): string;
|
|
4
|
-
export declare function toSignificant(num: bigint, decimals: number): string;
|
|
4
|
+
export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
|
|
5
5
|
export declare function toBN(num: string, decimals: number): bigint;
|
|
6
6
|
export declare function shortAddress(address?: string): string;
|
|
7
7
|
export declare function shortHash(address?: string): string;
|
package/lib/utils/formatter.js
CHANGED
|
@@ -12,12 +12,12 @@ function formatRAY(num = 0n) {
|
|
|
12
12
|
return toSignificant(num, 27);
|
|
13
13
|
}
|
|
14
14
|
exports.formatRAY = formatRAY;
|
|
15
|
-
function toSignificant(num, decimals) {
|
|
15
|
+
function toSignificant(num, decimals, precision = 6) {
|
|
16
16
|
if (num === 1n)
|
|
17
17
|
return "0";
|
|
18
18
|
const divider = new decimal_js_light_1.Decimal(10).toPower(decimals);
|
|
19
19
|
const number = new decimal_js_light_1.Decimal(num.toString()).div(divider);
|
|
20
|
-
return number.toSignificantDigits(
|
|
20
|
+
return number.toSignificantDigits(precision, 4).toString();
|
|
21
21
|
}
|
|
22
22
|
exports.toSignificant = toSignificant;
|
|
23
23
|
function toBN(num, decimals) {
|