@gearbox-protocol/sdk 0.0.102 → 0.0.105
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/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +18 -15
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/core/eventOrTx.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TokenData } from "../tokens/tokenData";
|
|
2
|
-
import { TxSerialized } from "./transactions";
|
|
2
|
+
import type { TxSerialized } from "./transactions";
|
|
3
3
|
|
|
4
4
|
export interface Display {
|
|
5
5
|
toString(tokenData: Record<string, TokenData>): string;
|
|
@@ -16,8 +16,11 @@ export interface EventOrTxProps {
|
|
|
16
16
|
|
|
17
17
|
export abstract class EventOrTx implements Display {
|
|
18
18
|
public block: number;
|
|
19
|
+
|
|
19
20
|
public readonly txHash: string;
|
|
21
|
+
|
|
20
22
|
public readonly timestamp: number;
|
|
23
|
+
|
|
21
24
|
protected _txStatus: TxStatus;
|
|
22
25
|
|
|
23
26
|
constructor({ block, txHash, txStatus, timestamp = 0 }: EventOrTxProps) {
|
|
@@ -70,10 +73,10 @@ export abstract class EVMTx extends EventOrTx {
|
|
|
70
73
|
timestamp = 0
|
|
71
74
|
}: EVMTxProps) {
|
|
72
75
|
super({
|
|
73
|
-
block
|
|
74
|
-
txStatus
|
|
75
|
-
txHash
|
|
76
|
-
timestamp
|
|
76
|
+
block,
|
|
77
|
+
txStatus,
|
|
78
|
+
txHash,
|
|
79
|
+
timestamp
|
|
77
80
|
});
|
|
78
81
|
if (this.txStatus !== "pending" && this.block === 0) {
|
|
79
82
|
throw new Error("Block not specified for non-pending tx");
|
package/src/core/events.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TokenData } from "../tokens/tokenData";
|
|
2
1
|
import { BigNumber } from "ethers";
|
|
2
|
+
import { TokenData } from "../tokens/tokenData";
|
|
3
3
|
import { formatBN } from "../utils/formatter";
|
|
4
4
|
import { LEVERAGE_DECIMALS, PERCENTAGE_DECIMALS } from "./constants";
|
|
5
5
|
import { EVMEvent, EVMTx, EVMEventProps } from "./eventOrTx";
|
|
@@ -116,9 +116,7 @@ export class EventParser {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
static deserializeArray(data: Array<EventSerialized>): Array<EVMEvent> {
|
|
119
|
-
return data.map(e =>
|
|
120
|
-
return EventParser.deserialize(e);
|
|
121
|
-
});
|
|
119
|
+
return data.map(e => EventParser.deserialize(e));
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
122
|
|
|
@@ -131,7 +129,9 @@ interface EventAddLiquidityProps extends EVMEventProps {
|
|
|
131
129
|
|
|
132
130
|
export class EventAddLiquidity extends EVMEvent {
|
|
133
131
|
public readonly amount: BigNumber;
|
|
132
|
+
|
|
134
133
|
public readonly underlyingToken: string;
|
|
134
|
+
|
|
135
135
|
public readonly pool: string;
|
|
136
136
|
|
|
137
137
|
constructor(opts: EventAddLiquidityProps) {
|
|
@@ -165,8 +165,11 @@ interface RemoveLiquidityProps extends EVMEventProps {
|
|
|
165
165
|
|
|
166
166
|
export class EventRemoveLiquidity extends EVMEvent {
|
|
167
167
|
public readonly amount: BigNumber;
|
|
168
|
+
|
|
168
169
|
public readonly underlyingToken: string;
|
|
170
|
+
|
|
169
171
|
public readonly dieselToken: string;
|
|
172
|
+
|
|
170
173
|
public readonly pool: string;
|
|
171
174
|
|
|
172
175
|
constructor(opts: RemoveLiquidityProps) {
|
|
@@ -203,8 +206,11 @@ interface OpenCreditAccountProps extends EVMEventProps {
|
|
|
203
206
|
|
|
204
207
|
export class EventOpenCreditAccount extends EVMEvent {
|
|
205
208
|
public readonly amount: BigNumber;
|
|
209
|
+
|
|
206
210
|
public readonly underlyingToken: string;
|
|
211
|
+
|
|
207
212
|
public readonly leverage: number;
|
|
213
|
+
|
|
208
214
|
public readonly creditManager: string;
|
|
209
215
|
|
|
210
216
|
constructor(opts: OpenCreditAccountProps) {
|
|
@@ -246,7 +252,9 @@ interface CloseCreditAccountProps extends EVMEventProps {
|
|
|
246
252
|
|
|
247
253
|
export class EventCloseCreditAccount extends EVMEvent {
|
|
248
254
|
public readonly amount: BigNumber;
|
|
255
|
+
|
|
249
256
|
public readonly underlyingToken: string;
|
|
257
|
+
|
|
250
258
|
public readonly creditManager: string;
|
|
251
259
|
|
|
252
260
|
constructor(opts: CloseCreditAccountProps) {
|
|
@@ -281,7 +289,9 @@ interface LiquidateCreditAccountProps extends EVMEventProps {
|
|
|
281
289
|
|
|
282
290
|
export class EventLiquidateCreditAccount extends EVMEvent {
|
|
283
291
|
public readonly amount: BigNumber;
|
|
292
|
+
|
|
284
293
|
public readonly underlyingToken: string;
|
|
294
|
+
|
|
285
295
|
public readonly creditManager: string;
|
|
286
296
|
|
|
287
297
|
constructor(opts: LiquidateCreditAccountProps) {
|
|
@@ -315,6 +325,7 @@ interface RepayCreditAccountProps extends EVMEventProps {
|
|
|
315
325
|
|
|
316
326
|
export class EventRepayCreditAccount extends EVMEvent {
|
|
317
327
|
public readonly underlyingToken: string;
|
|
328
|
+
|
|
318
329
|
public readonly creditManager: string;
|
|
319
330
|
|
|
320
331
|
constructor(opts: RepayCreditAccountProps) {
|
|
@@ -327,7 +338,7 @@ export class EventRepayCreditAccount extends EVMEvent {
|
|
|
327
338
|
this.creditManager = opts.creditManager;
|
|
328
339
|
}
|
|
329
340
|
|
|
330
|
-
toString(
|
|
341
|
+
toString(): string {
|
|
331
342
|
return `Credit account ${getContractName(this.creditManager)}: was repaid`;
|
|
332
343
|
}
|
|
333
344
|
}
|
|
@@ -340,7 +351,9 @@ interface AddCollateralProps extends EVMEventProps {
|
|
|
340
351
|
|
|
341
352
|
export class EventAddCollateral extends EVMEvent {
|
|
342
353
|
public readonly amount: BigNumber;
|
|
354
|
+
|
|
343
355
|
public readonly addedToken: string;
|
|
356
|
+
|
|
344
357
|
public readonly creditManager: string;
|
|
345
358
|
|
|
346
359
|
constructor(opts: AddCollateralProps) {
|
|
@@ -373,7 +386,9 @@ interface IncreaseBorrowAmountProps extends EVMEventProps {
|
|
|
373
386
|
|
|
374
387
|
export class EventIncreaseBorrowAmount extends EVMEvent {
|
|
375
388
|
public readonly amount: BigNumber;
|
|
389
|
+
|
|
376
390
|
public readonly underlyingToken: string;
|
|
391
|
+
|
|
377
392
|
public readonly creditManager: string;
|
|
378
393
|
|
|
379
394
|
constructor(opts: IncreaseBorrowAmountProps) {
|
|
@@ -429,18 +444,31 @@ interface CMNewParametersProps extends EVMEventProps {
|
|
|
429
444
|
|
|
430
445
|
export class EventCMNewParameters extends EVMEvent {
|
|
431
446
|
public readonly creditManager: string;
|
|
447
|
+
|
|
432
448
|
public readonly underlyingToken: string;
|
|
449
|
+
|
|
433
450
|
public readonly minAmount: BigNumber;
|
|
451
|
+
|
|
434
452
|
public readonly maxAmount: BigNumber;
|
|
453
|
+
|
|
435
454
|
public readonly maxLeverage: number;
|
|
455
|
+
|
|
436
456
|
public readonly feeInterest: number;
|
|
457
|
+
|
|
437
458
|
public readonly feeLiquidation: number;
|
|
459
|
+
|
|
438
460
|
public readonly liquidationDiscount: number;
|
|
461
|
+
|
|
439
462
|
public readonly prevMinAmount: BigNumber;
|
|
463
|
+
|
|
440
464
|
public readonly prevMaxAmount: BigNumber;
|
|
465
|
+
|
|
441
466
|
public readonly prevMaxLeverage: number;
|
|
467
|
+
|
|
442
468
|
public readonly prevFeeInterest: number;
|
|
469
|
+
|
|
443
470
|
public readonly prevFeeLiquidation: number;
|
|
471
|
+
|
|
444
472
|
public readonly prevLiquidationDiscount: number;
|
|
445
473
|
|
|
446
474
|
constructor(opts: CMNewParametersProps) {
|
|
@@ -529,9 +557,13 @@ interface TokenAllowedProps extends EVMEventProps {
|
|
|
529
557
|
|
|
530
558
|
export class EventTokenAllowed extends EVMEvent {
|
|
531
559
|
public readonly creditManager: string;
|
|
560
|
+
|
|
532
561
|
public readonly token: string;
|
|
562
|
+
|
|
533
563
|
public readonly liquidityThreshold: number;
|
|
564
|
+
|
|
534
565
|
public readonly prevLiquidationThreshold?: number;
|
|
566
|
+
|
|
535
567
|
public readonly status: TokenAllowanceType;
|
|
536
568
|
|
|
537
569
|
constructor(opts: TokenAllowedProps) {
|
|
@@ -549,7 +581,9 @@ export class EventTokenAllowed extends EVMEvent {
|
|
|
549
581
|
|
|
550
582
|
toString(tokenData: Record<string, TokenData>): string {
|
|
551
583
|
const token = tokenData[this.token.toLowerCase()];
|
|
552
|
-
|
|
584
|
+
const msg = `Credit manager ${getContractName(
|
|
585
|
+
this.creditManager
|
|
586
|
+
)} updated `;
|
|
553
587
|
switch (this.status) {
|
|
554
588
|
case "NewToken":
|
|
555
589
|
return `${msg}: New token allowed: ${
|
|
@@ -567,6 +601,8 @@ export class EventTokenAllowed extends EVMEvent {
|
|
|
567
601
|
return `${msg}: ${token.symbol} liquidation threshold: ${
|
|
568
602
|
(this.prevLiquidationThreshold || 0) / PERCENTAGE_DECIMALS
|
|
569
603
|
} => ${this.liquidityThreshold / PERCENTAGE_DECIMALS}%`;
|
|
604
|
+
default:
|
|
605
|
+
return "Error: TokenAllowedProps";
|
|
570
606
|
}
|
|
571
607
|
}
|
|
572
608
|
}
|
|
@@ -581,6 +617,7 @@ interface TokenForbiddenProps extends EVMEventProps {
|
|
|
581
617
|
|
|
582
618
|
export class EventTokenForbidden extends EVMEvent {
|
|
583
619
|
public readonly creditManager: string;
|
|
620
|
+
|
|
584
621
|
public readonly token: string;
|
|
585
622
|
|
|
586
623
|
constructor(opts: TokenForbiddenProps) {
|
|
@@ -616,8 +653,11 @@ interface ContractAllowedProps extends EVMEventProps {
|
|
|
616
653
|
|
|
617
654
|
export class EventContractAllowed extends EVMEvent {
|
|
618
655
|
public readonly creditManager: string;
|
|
656
|
+
|
|
619
657
|
public readonly protocol: string;
|
|
658
|
+
|
|
620
659
|
public readonly adapter: string;
|
|
660
|
+
|
|
621
661
|
public readonly status: EventContractAllowedStatus;
|
|
622
662
|
|
|
623
663
|
constructor(opts: ContractAllowedProps) {
|
|
@@ -632,8 +672,8 @@ export class EventContractAllowed extends EVMEvent {
|
|
|
632
672
|
this.status = opts.status;
|
|
633
673
|
}
|
|
634
674
|
|
|
635
|
-
toString(
|
|
636
|
-
|
|
675
|
+
toString(): string {
|
|
676
|
+
const msg = `Credit manager ${getContractName(this.creditManager)} updated`;
|
|
637
677
|
|
|
638
678
|
switch (this.status) {
|
|
639
679
|
case "Connected":
|
|
@@ -644,6 +684,8 @@ export class EventContractAllowed extends EVMEvent {
|
|
|
644
684
|
return `${msg} : ${getContractName(
|
|
645
685
|
this.protocol
|
|
646
686
|
)} adapter was updated. New adapter: ${this.adapter}`;
|
|
687
|
+
default:
|
|
688
|
+
return "Error: EventContractAllowed";
|
|
647
689
|
}
|
|
648
690
|
}
|
|
649
691
|
}
|
|
@@ -659,6 +701,7 @@ interface ContractForbiddenProps extends EVMEventProps {
|
|
|
659
701
|
|
|
660
702
|
export class EventContractForbidden extends EVMEvent {
|
|
661
703
|
public readonly creditManager: string;
|
|
704
|
+
|
|
662
705
|
public readonly protocol: string;
|
|
663
706
|
|
|
664
707
|
constructor(opts: ContractForbiddenProps) {
|
|
@@ -671,7 +714,7 @@ export class EventContractForbidden extends EVMEvent {
|
|
|
671
714
|
this.protocol = opts.protocol;
|
|
672
715
|
}
|
|
673
716
|
|
|
674
|
-
toString(
|
|
717
|
+
toString(): string {
|
|
675
718
|
return `Credit manager ${getContractName(
|
|
676
719
|
this.creditManager
|
|
677
720
|
)} updated: ${getContractName(this.protocol)}`;
|
|
@@ -692,9 +735,13 @@ interface NewFastCheckParametersProps extends EVMEventProps {
|
|
|
692
735
|
|
|
693
736
|
export class EventNewFastCheckParameters extends EVMEvent {
|
|
694
737
|
public readonly creditManager: string;
|
|
738
|
+
|
|
695
739
|
public readonly chiThreshold: number;
|
|
740
|
+
|
|
696
741
|
public readonly fastCheckDelay: number;
|
|
742
|
+
|
|
697
743
|
public readonly prevChiThreshold?: number;
|
|
744
|
+
|
|
698
745
|
public readonly prevFastCheckDelay?: number;
|
|
699
746
|
|
|
700
747
|
constructor(opts: NewFastCheckParametersProps) {
|
|
@@ -710,7 +757,7 @@ export class EventNewFastCheckParameters extends EVMEvent {
|
|
|
710
757
|
this.prevFastCheckDelay = opts.prevFastCheckDelay;
|
|
711
758
|
}
|
|
712
759
|
|
|
713
|
-
toString(
|
|
760
|
+
toString(): string {
|
|
714
761
|
let msg = `Credit manager ${getContractName(this.creditManager)} updated: `;
|
|
715
762
|
|
|
716
763
|
if (this.chiThreshold !== this.prevChiThreshold) {
|
|
@@ -734,6 +781,7 @@ interface PriceOracleUpdatedProps extends EVMEventProps {
|
|
|
734
781
|
|
|
735
782
|
export class EventPriceOracleUpdated extends EVMEvent {
|
|
736
783
|
public readonly creditManager: string;
|
|
784
|
+
|
|
737
785
|
public readonly priceOracle: string;
|
|
738
786
|
|
|
739
787
|
constructor(opts: PriceOracleUpdatedProps) {
|
|
@@ -746,7 +794,7 @@ export class EventPriceOracleUpdated extends EVMEvent {
|
|
|
746
794
|
this.priceOracle = opts.priceOracle;
|
|
747
795
|
}
|
|
748
796
|
|
|
749
|
-
toString(
|
|
797
|
+
toString(): string {
|
|
750
798
|
return `Credit manager ${getContractName(
|
|
751
799
|
this.creditManager
|
|
752
800
|
)} updated: price oracle was updated. New price oracle ${getContractName(
|
|
@@ -768,7 +816,9 @@ interface TransferPluginAllowedProps extends EVMEventProps {
|
|
|
768
816
|
|
|
769
817
|
export class EventTransferPluginAllowed extends EVMEvent {
|
|
770
818
|
public readonly creditManager: string;
|
|
819
|
+
|
|
771
820
|
public readonly plugin: string;
|
|
821
|
+
|
|
772
822
|
public readonly state: boolean;
|
|
773
823
|
|
|
774
824
|
constructor(opts: TransferPluginAllowedProps) {
|
|
@@ -782,7 +832,7 @@ export class EventTransferPluginAllowed extends EVMEvent {
|
|
|
782
832
|
this.state = opts.state;
|
|
783
833
|
}
|
|
784
834
|
|
|
785
|
-
toString(
|
|
835
|
+
toString(): string {
|
|
786
836
|
return `Credit manager ${getContractName(
|
|
787
837
|
this.creditManager
|
|
788
838
|
)} updated: transfer plugin ${getContractName(this.plugin)} was ${
|
|
@@ -801,6 +851,7 @@ interface NewInterestRateModelProps extends EVMEventProps {
|
|
|
801
851
|
|
|
802
852
|
export class EventNewInterestRateModel extends EVMEvent {
|
|
803
853
|
public readonly pool: string;
|
|
854
|
+
|
|
804
855
|
public readonly newInterestRateModel: string;
|
|
805
856
|
|
|
806
857
|
constructor(opts: NewInterestRateModelProps) {
|
|
@@ -813,7 +864,7 @@ export class EventNewInterestRateModel extends EVMEvent {
|
|
|
813
864
|
this.newInterestRateModel = opts.newInterestRateModel;
|
|
814
865
|
}
|
|
815
866
|
|
|
816
|
-
toString(
|
|
867
|
+
toString(): string {
|
|
817
868
|
return `Pool ${getContractName(
|
|
818
869
|
this.pool
|
|
819
870
|
)} updated: interest rate model was updated. New model: ${getContractName(
|
|
@@ -833,6 +884,7 @@ interface NewCreditManagerConnectedProps extends EVMEventProps {
|
|
|
833
884
|
|
|
834
885
|
export class EventNewCreditManagerConnected extends EVMEvent {
|
|
835
886
|
public readonly pool: string;
|
|
887
|
+
|
|
836
888
|
public readonly creditManager: string;
|
|
837
889
|
|
|
838
890
|
constructor(opts: NewCreditManagerConnectedProps) {
|
|
@@ -845,7 +897,7 @@ export class EventNewCreditManagerConnected extends EVMEvent {
|
|
|
845
897
|
this.creditManager = opts.creditManager;
|
|
846
898
|
}
|
|
847
899
|
|
|
848
|
-
toString(
|
|
900
|
+
toString(): string {
|
|
849
901
|
return `Pool ${getContractName(
|
|
850
902
|
this.pool
|
|
851
903
|
)} updated: new credit manager ${getContractName(
|
|
@@ -865,6 +917,7 @@ interface BorrowForbiddenProps extends EVMEventProps {
|
|
|
865
917
|
|
|
866
918
|
export class EventBorrowForbidden extends EVMEvent {
|
|
867
919
|
public readonly pool: string;
|
|
920
|
+
|
|
868
921
|
public readonly creditManager: string;
|
|
869
922
|
|
|
870
923
|
constructor(opts: BorrowForbiddenProps) {
|
|
@@ -877,7 +930,7 @@ export class EventBorrowForbidden extends EVMEvent {
|
|
|
877
930
|
this.creditManager = opts.creditManager;
|
|
878
931
|
}
|
|
879
932
|
|
|
880
|
-
toString(
|
|
933
|
+
toString(): string {
|
|
881
934
|
return `Pool ${getContractName(
|
|
882
935
|
this.pool
|
|
883
936
|
)} updated: credit manager ${getContractName(
|
|
@@ -898,8 +951,11 @@ interface NewExpectedLiquidityLimitProps extends EVMEventProps {
|
|
|
898
951
|
|
|
899
952
|
export class EventNewExpectedLiquidityLimit extends EVMEvent {
|
|
900
953
|
public readonly pool: string;
|
|
954
|
+
|
|
901
955
|
public readonly underlyingToken: string;
|
|
956
|
+
|
|
902
957
|
public readonly newLimit: BigNumber;
|
|
958
|
+
|
|
903
959
|
public readonly prevLimit: BigNumber;
|
|
904
960
|
|
|
905
961
|
constructor(opts: NewExpectedLiquidityLimitProps) {
|
|
@@ -948,8 +1004,11 @@ interface NewWithdrawFeeProps extends EVMEventProps {
|
|
|
948
1004
|
|
|
949
1005
|
export class EventNewWithdrawFee extends EVMEvent {
|
|
950
1006
|
public readonly pool: string;
|
|
1007
|
+
|
|
951
1008
|
public readonly underlyingToken: string;
|
|
1009
|
+
|
|
952
1010
|
public readonly newFee: number;
|
|
1011
|
+
|
|
953
1012
|
public readonly prevFee: number;
|
|
954
1013
|
|
|
955
1014
|
constructor(opts: NewWithdrawFeeProps) {
|
|
@@ -964,7 +1023,7 @@ export class EventNewWithdrawFee extends EVMEvent {
|
|
|
964
1023
|
this.prevFee = Number(opts.oldFee);
|
|
965
1024
|
}
|
|
966
1025
|
|
|
967
|
-
toString(
|
|
1026
|
+
toString(): string {
|
|
968
1027
|
return this.prevFee === 0
|
|
969
1028
|
? `Pool ${getContractName(this.pool)} updated: withdraw fee was set to: ${
|
|
970
1029
|
this.newFee / PERCENTAGE_DECIMALS
|
|
@@ -987,6 +1046,7 @@ interface NewPriceFeedProps extends EVMEventProps {
|
|
|
987
1046
|
|
|
988
1047
|
export class EventNewPriceFeed extends EVMEvent {
|
|
989
1048
|
public readonly token: string;
|
|
1049
|
+
|
|
990
1050
|
public readonly priceFeed: string;
|
|
991
1051
|
|
|
992
1052
|
constructor(opts: NewPriceFeedProps) {
|
|
@@ -1018,6 +1078,7 @@ interface TakeForeverProps extends EVMEventProps {
|
|
|
1018
1078
|
|
|
1019
1079
|
export class EventTakeForever extends EVMEvent {
|
|
1020
1080
|
public readonly creditAccount: string;
|
|
1081
|
+
|
|
1021
1082
|
public readonly to: string;
|
|
1022
1083
|
|
|
1023
1084
|
constructor(opts: TakeForeverProps) {
|
|
@@ -1030,7 +1091,7 @@ export class EventTakeForever extends EVMEvent {
|
|
|
1030
1091
|
this.to = opts.to;
|
|
1031
1092
|
}
|
|
1032
1093
|
|
|
1033
|
-
toString(
|
|
1094
|
+
toString(): string {
|
|
1034
1095
|
return `AccountFactory: account ${this.creditAccount} was taken forever and transferred to ${this.to}`;
|
|
1035
1096
|
}
|
|
1036
1097
|
}
|
|
@@ -1053,7 +1114,7 @@ export class EventPaused extends EVMEvent {
|
|
|
1053
1114
|
this.contract = opts.contract;
|
|
1054
1115
|
}
|
|
1055
1116
|
|
|
1056
|
-
toString(
|
|
1117
|
+
toString(): string {
|
|
1057
1118
|
return `${getContractName(this.contract)} was paused`;
|
|
1058
1119
|
}
|
|
1059
1120
|
}
|
|
@@ -1074,7 +1135,7 @@ export class EventUnPaused extends EVMEvent {
|
|
|
1074
1135
|
this.contract = opts.contract;
|
|
1075
1136
|
}
|
|
1076
1137
|
|
|
1077
|
-
toString(
|
|
1138
|
+
toString(): string {
|
|
1078
1139
|
return `${getContractName(this.contract)} was unpaused`;
|
|
1079
1140
|
}
|
|
1080
1141
|
}
|
|
@@ -1098,7 +1159,7 @@ export class EventPausableAdminAdded extends EVMEvent {
|
|
|
1098
1159
|
this.admin = opts.admin;
|
|
1099
1160
|
}
|
|
1100
1161
|
|
|
1101
|
-
toString(
|
|
1162
|
+
toString(): string {
|
|
1102
1163
|
return `ACL: pausable admin ${this.admin} was added`;
|
|
1103
1164
|
}
|
|
1104
1165
|
}
|
|
@@ -1122,7 +1183,7 @@ export class EventPausableAdminRemoved extends EVMEvent {
|
|
|
1122
1183
|
this.admin = opts.admin;
|
|
1123
1184
|
}
|
|
1124
1185
|
|
|
1125
|
-
toString(
|
|
1186
|
+
toString(): string {
|
|
1126
1187
|
return `ACL: pausable admin ${this.admin} was removed`;
|
|
1127
1188
|
}
|
|
1128
1189
|
}
|
|
@@ -1146,7 +1207,7 @@ export class EventUnPausableAdminAdded extends EVMEvent {
|
|
|
1146
1207
|
this.admin = opts.admin;
|
|
1147
1208
|
}
|
|
1148
1209
|
|
|
1149
|
-
toString(
|
|
1210
|
+
toString(): string {
|
|
1150
1211
|
return `ACL: unpausable admin ${this.admin} was added`;
|
|
1151
1212
|
}
|
|
1152
1213
|
}
|
|
@@ -1170,7 +1231,7 @@ export class EventUnPausableAdminRemoved extends EVMEvent {
|
|
|
1170
1231
|
this.admin = opts.admin;
|
|
1171
1232
|
}
|
|
1172
1233
|
|
|
1173
|
-
toString(
|
|
1234
|
+
toString(): string {
|
|
1174
1235
|
return `ACL: unpausable admin ${this.admin} was removed`;
|
|
1175
1236
|
}
|
|
1176
1237
|
}
|
|
@@ -1192,7 +1253,7 @@ export class EventTransferOwnership extends EVMEvent {
|
|
|
1192
1253
|
this.newOwner = opts.admin;
|
|
1193
1254
|
}
|
|
1194
1255
|
|
|
1195
|
-
toString(
|
|
1256
|
+
toString(): string {
|
|
1196
1257
|
return `ACL: configurator was changed to ${this.newOwner}`;
|
|
1197
1258
|
}
|
|
1198
1259
|
}
|
package/src/core/history.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
2
|
|
|
3
3
|
export type BasicEvent = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
protocol: string; // address of creditManager. Address of target account for EXECUTE event
|
|
5
|
+
txHash: string;
|
|
6
|
+
timestamp: number; // timestamp in Unix format
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export type BasicSwapEvent = BasicEvent & {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
from: string; // address
|
|
11
|
+
fromAmount: BigNumber;
|
|
12
|
+
to: string; // address
|
|
13
|
+
toAmount: BigNumber;
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export type HistoryEvent =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
17
|
+
| (BasicEvent & {
|
|
18
|
+
action: "OpenCreditAccount";
|
|
19
|
+
initialFunds: BigNumber;
|
|
20
|
+
leverage: number; // x100, so 420 => 4.2
|
|
21
|
+
})
|
|
22
|
+
| (BasicEvent & {
|
|
23
|
+
action: "CloseCreditAccount";
|
|
24
|
+
remainingFunds: BigNumber;
|
|
25
|
+
})
|
|
26
|
+
| (BasicEvent & {
|
|
27
|
+
action: "LiquidateCreditAccount";
|
|
28
|
+
remainingFunds: BigNumber;
|
|
29
|
+
})
|
|
30
|
+
| (BasicEvent & {
|
|
31
|
+
action: "IncreaseBorrowedAmount";
|
|
32
|
+
amount: BigNumber;
|
|
33
|
+
})
|
|
34
|
+
| (BasicEvent & {
|
|
35
|
+
action: "AddCollateral";
|
|
36
|
+
token: string; // token address
|
|
37
|
+
amount: BigNumber;
|
|
38
|
+
})
|
|
39
|
+
| (BasicEvent & {
|
|
40
|
+
action: "RepayCreditAccount";
|
|
41
|
+
repayAmount: BigNumber;
|
|
42
|
+
})
|
|
43
|
+
| (BasicEvent & {
|
|
44
|
+
action: "TransferAccount";
|
|
45
|
+
newAccount: string; // Address
|
|
46
|
+
})
|
|
47
|
+
| (BasicSwapEvent & {
|
|
48
|
+
action: "Swap";
|
|
49
|
+
})
|
|
50
|
+
| (BasicSwapEvent & {
|
|
51
|
+
action: "Deposit";
|
|
52
|
+
})
|
|
53
|
+
| (BasicSwapEvent & {
|
|
54
|
+
action: "Withdraw";
|
|
55
|
+
});
|
package/src/core/operations.ts
CHANGED
|
@@ -2,11 +2,17 @@ import moment from "moment";
|
|
|
2
2
|
|
|
3
3
|
export class OperationData {
|
|
4
4
|
public readonly id: number;
|
|
5
|
+
|
|
5
6
|
public readonly address: string;
|
|
7
|
+
|
|
6
8
|
public readonly txHash: string;
|
|
9
|
+
|
|
7
10
|
public readonly blockNum: number;
|
|
11
|
+
|
|
8
12
|
public readonly operation: string;
|
|
13
|
+
|
|
9
14
|
public readonly timestamp: number;
|
|
15
|
+
|
|
10
16
|
public readonly date: string;
|
|
11
17
|
|
|
12
18
|
constructor(payload: OperationDataPayload) {
|
package/src/core/pool.ts
CHANGED
|
@@ -9,26 +9,42 @@ import { PERCENTAGE_DECIMALS } from "./constants";
|
|
|
9
9
|
|
|
10
10
|
export class PoolData {
|
|
11
11
|
public readonly id: string;
|
|
12
|
+
|
|
12
13
|
public readonly address: string;
|
|
13
14
|
|
|
14
15
|
public readonly underlyingToken: string;
|
|
16
|
+
|
|
15
17
|
public readonly dieselToken: string;
|
|
18
|
+
|
|
16
19
|
public readonly isWETH: boolean;
|
|
17
20
|
|
|
18
21
|
// Information
|
|
19
22
|
public readonly expectedLiquidity: BigNumber;
|
|
23
|
+
|
|
20
24
|
public readonly expectedLiquidityLimit: BigNumber;
|
|
25
|
+
|
|
21
26
|
public readonly availableLiquidity: BigNumber;
|
|
27
|
+
|
|
22
28
|
public readonly totalBorrowed: BigNumber;
|
|
29
|
+
|
|
23
30
|
public readonly depositAPY: number;
|
|
31
|
+
|
|
24
32
|
public readonly borrowAPY: number;
|
|
33
|
+
|
|
25
34
|
public readonly borrowAPYRay: BigNumber;
|
|
35
|
+
|
|
26
36
|
public readonly dieselRate: number;
|
|
37
|
+
|
|
27
38
|
public readonly dieselRateRay: BigNumber;
|
|
39
|
+
|
|
28
40
|
public readonly withdrawFee: number;
|
|
41
|
+
|
|
29
42
|
public readonly timestampLU: BigNumber;
|
|
43
|
+
|
|
30
44
|
public readonly cumulativeIndex_RAY: BigNumber;
|
|
31
45
|
|
|
46
|
+
public readonly isPaused: boolean = false;
|
|
47
|
+
|
|
32
48
|
constructor(payload: PoolDataPayload) {
|
|
33
49
|
this.id = payload.addr;
|
|
34
50
|
this.address = payload.addr;
|
|
@@ -57,10 +73,6 @@ export class PoolData {
|
|
|
57
73
|
getContractETH(signer: Signer): IPoolService {
|
|
58
74
|
return IPoolService__factory.connect(this.address, signer);
|
|
59
75
|
}
|
|
60
|
-
|
|
61
|
-
get isPaused(): boolean {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
76
|
}
|
|
65
77
|
|
|
66
78
|
export interface PoolsStat {
|
package/src/core/price.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
+
import { WAD, PRICE_DECIMALS } from "./constants";
|
|
2
3
|
|
|
3
4
|
export const calcTotalPrice = (
|
|
4
5
|
price: BigNumber,
|
|
5
6
|
amount: BigNumber,
|
|
6
7
|
decimals: number = 18
|
|
7
|
-
) =>
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
) =>
|
|
9
|
+
amount
|
|
10
|
+
.mul(WAD)
|
|
11
|
+
.mul(price)
|
|
12
|
+
.div(BigNumber.from(10).pow(decimals))
|
|
13
|
+
.div(PRICE_DECIMALS);
|