@gearbox-protocol/sdk 0.0.100 → 0.0.103

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.
Files changed (163) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.d.ts +8 -0
  5. package/lib/apy/convexAPY.js +200 -0
  6. package/lib/apy/lidoAPY.d.ts +4 -0
  7. package/lib/apy/lidoAPY.js +103 -0
  8. package/lib/config.d.ts +1 -0
  9. package/lib/config.js +2 -1
  10. package/lib/contracts/contracts.d.ts +9 -4
  11. package/lib/contracts/contracts.js +52 -14
  12. package/lib/contracts/contractsRegister.js +16 -4
  13. package/lib/core/constants.d.ts +7 -1
  14. package/lib/core/constants.js +11 -5
  15. package/lib/core/creditAccount.d.ts +3 -1
  16. package/lib/core/creditAccount.js +33 -31
  17. package/lib/core/creditManager.d.ts +13 -2
  18. package/lib/core/creditManager.js +77 -33
  19. package/lib/core/creditSession.js +14 -3
  20. package/lib/core/errors.d.ts +10 -0
  21. package/lib/core/errors.js +16 -1
  22. package/lib/core/eventOrTx.d.ts +1 -1
  23. package/lib/core/events.d.ts +19 -19
  24. package/lib/core/events.js +32 -30
  25. package/lib/core/multicall.d.ts +1 -1
  26. package/lib/core/pool.d.ts +2 -2
  27. package/lib/core/pool.js +8 -12
  28. package/lib/core/price.d.ts +2 -0
  29. package/lib/core/price.js +14 -0
  30. package/lib/core/strategy.d.ts +36 -0
  31. package/lib/core/strategy.js +57 -0
  32. package/lib/core/tokenDistributor.js +1 -1
  33. package/lib/core/transactions.d.ts +18 -3
  34. package/lib/core/transactions.js +39 -3
  35. package/lib/index.d.ts +8 -3
  36. package/lib/index.js +9 -4
  37. package/lib/oracles/priceFeeds.js +1 -1
  38. package/lib/pathfinder/convexLP.d.ts +1 -1
  39. package/lib/pathfinder/convexLP.js +26 -29
  40. package/lib/pathfinder/curveLP.d.ts +1 -1
  41. package/lib/pathfinder/curveLP.js +5 -7
  42. package/lib/pathfinder/path.d.ts +1 -1
  43. package/lib/pathfinder/path.js +38 -42
  44. package/lib/pathfinder/trade.d.ts +1 -2
  45. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  46. package/lib/pathfinder/yVault.d.ts +2 -2
  47. package/lib/pathfinder/yVault.js +22 -19
  48. package/lib/payload/creditAccount.d.ts +4 -26
  49. package/lib/payload/creditManager.d.ts +3 -25
  50. package/lib/payload/pool.d.ts +2 -17
  51. package/lib/payload/pool.js +0 -1
  52. package/lib/strategies/curve.d.ts +6 -60
  53. package/lib/strategies/curve.js +6 -0
  54. package/lib/strategies/uniswapV2.js +3 -19
  55. package/lib/strategies/uniswapV3.js +1 -1
  56. package/lib/strategies/yearn.js +15 -11
  57. package/lib/tokens/convex.d.ts +3 -3
  58. package/lib/tokens/curveLP.d.ts +2 -2
  59. package/lib/tokens/curveLP.js +1 -1
  60. package/lib/tokens/gear.d.ts +2 -2
  61. package/lib/tokens/gear.js +1 -1
  62. package/lib/tokens/normal.d.ts +1 -1
  63. package/lib/tokens/token.js +9 -9
  64. package/lib/tokens/tokenData.d.ts +3 -1
  65. package/lib/tokens/tokenData.js +10 -8
  66. package/lib/tokens/yearn.d.ts +3 -3
  67. package/lib/utils/errors.d.ts +6 -0
  68. package/lib/utils/errors.js +13 -0
  69. package/lib/utils/formatter.d.ts +2 -1
  70. package/lib/utils/formatter.js +23 -15
  71. package/lib/utils/loading.d.ts +2 -1
  72. package/lib/utils/loading.js +9 -13
  73. package/lib/utils/mappers.d.ts +2 -1
  74. package/lib/utils/mappers.js +13 -5
  75. package/lib/utils/multicall.js +4 -3
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/types.d.ts +1 -0
  79. package/lib/utils/validate.js +1 -1
  80. package/package.json +26 -8
  81. package/src/apy/convexAPY.ts +250 -0
  82. package/src/apy/lidoAPY.ts +89 -0
  83. package/src/config.ts +2 -1
  84. package/src/contracts/contracts.ts +73 -19
  85. package/src/contracts/contractsRegister.ts +19 -4
  86. package/src/core/constants.ts +11 -4
  87. package/src/core/creditAccount.ts +69 -37
  88. package/src/core/creditManager.ts +256 -148
  89. package/src/core/creditOperation.ts +7 -7
  90. package/src/core/creditSession.ts +25 -5
  91. package/src/core/errors.ts +25 -0
  92. package/src/core/eventOrTx.ts +8 -5
  93. package/src/core/events.ts +978 -911
  94. package/src/core/history.ts +46 -46
  95. package/src/core/multicall.ts +1 -1
  96. package/src/core/operations.ts +6 -0
  97. package/src/core/pool.ts +75 -58
  98. package/src/core/price.ts +13 -0
  99. package/src/core/strategy.ts +134 -0
  100. package/src/core/tokenDistributor.ts +2 -2
  101. package/src/core/transactions.ts +427 -350
  102. package/src/index.ts +9 -4
  103. package/src/oracles/priceFeeds.ts +523 -523
  104. package/src/pathfinder/contracts.ts +15 -13
  105. package/src/pathfinder/convexLP.ts +29 -25
  106. package/src/pathfinder/curveLP.ts +57 -53
  107. package/src/pathfinder/path.ts +158 -150
  108. package/src/pathfinder/priority.ts +11 -11
  109. package/src/pathfinder/trade.ts +84 -77
  110. package/src/pathfinder/tradeTypes.ts +98 -94
  111. package/src/pathfinder/yVault.ts +79 -63
  112. package/src/payload/creditAccount.ts +4 -26
  113. package/src/payload/creditManager.ts +4 -26
  114. package/src/payload/pool.ts +2 -19
  115. package/src/payload/token.ts +3 -3
  116. package/src/strategies/convex.ts +217 -210
  117. package/src/strategies/creditFacade.ts +70 -53
  118. package/src/strategies/curve.ts +263 -194
  119. package/src/strategies/lido.ts +33 -37
  120. package/src/strategies/uniswapV2.ts +90 -112
  121. package/src/strategies/uniswapV3.ts +114 -91
  122. package/src/strategies/yearn.ts +58 -62
  123. package/src/tokens/connectors.ts +6 -6
  124. package/src/tokens/convex.ts +297 -296
  125. package/src/tokens/curveLP.ts +170 -165
  126. package/src/tokens/gear.ts +47 -45
  127. package/src/tokens/normal.ts +801 -802
  128. package/src/tokens/token.ts +19 -10
  129. package/src/tokens/tokenData.ts +19 -9
  130. package/src/tokens/tokenType.ts +11 -11
  131. package/src/tokens/yearn.ts +126 -124
  132. package/src/utils/errors.ts +11 -0
  133. package/src/utils/formatter.ts +26 -18
  134. package/src/utils/loading.ts +14 -6
  135. package/src/utils/mappers.ts +15 -6
  136. package/src/utils/multicall.ts +6 -9
  137. package/src/utils/network.ts +21 -21
  138. package/src/utils/repeater.ts +2 -2
  139. package/src/utils/types.ts +6 -2
  140. package/src/utils/validate.ts +1 -1
  141. package/lib/core/adapters.d.ts +0 -15
  142. package/lib/core/adapters.js +0 -19
  143. package/lib/core/contracts.d.ts +0 -67
  144. package/lib/core/contracts.js +0 -254
  145. package/lib/core/contractsRegister.d.ts +0 -2
  146. package/lib/core/contractsRegister.js +0 -58
  147. package/lib/core/creditCard.d.ts +0 -13
  148. package/lib/core/creditCard.js +0 -2
  149. package/lib/core/oracles.d.ts +0 -38
  150. package/lib/core/oracles.js +0 -12
  151. package/lib/core/priceFeeds.d.ts +0 -3
  152. package/lib/core/priceFeeds.js +0 -492
  153. package/lib/core/protocols.d.ts +0 -13
  154. package/lib/core/protocols.js +0 -39
  155. package/lib/core/swap.d.ts +0 -4
  156. package/lib/core/swap.js +0 -8
  157. package/lib/core/trade.d.ts +0 -35
  158. package/lib/core/trade.js +0 -62
  159. package/lib/core/tradeTypes.d.ts +0 -79
  160. package/lib/core/tradeTypes.js +0 -21
  161. package/lib/utils/events.d.ts +0 -2
  162. package/lib/utils/events.js +0 -13
  163. package/src/utils/events.ts +0 -10
@@ -1,83 +1,90 @@
1
- import {BigNumber} from "ethers";
2
- import {BytesLike} from "@ethersproject/bytes";
3
- import {PERCENTAGE_FACTOR, WAD} from "../core/constants";
4
- import {SwapType} from "./tradeTypes";
1
+ import { BigNumber, BytesLike } from "ethers";
2
+ import { PERCENTAGE_FACTOR, WAD } from "../core/constants";
3
+ import { SwapType } from "./tradeTypes";
5
4
 
6
5
  export interface CloseTradePath {
7
- path: Array<string>;
8
- amountOutMin: BigNumber;
6
+ path: Array<string>;
7
+ amountOutMin: BigNumber;
9
8
  }
10
9
 
11
10
  export class TradePath {
12
- public readonly swapType: SwapType;
13
- public readonly amount: BigNumber;
14
- public readonly rate: BigNumber;
15
- public readonly path: Array<string>;
16
- public readonly expectedAmount: BigNumber;
17
- public readonly pathUniV3: BytesLike | undefined;
18
- public readonly i: number | undefined;
19
- public readonly j: number | undefined;
20
- public readonly operationName: string | undefined;
21
-
22
- constructor(params: {
23
- swapType: SwapType;
24
- amount: BigNumber;
25
- path: Array<string>;
26
- expectedAmount: BigNumber;
27
- pathUniV3?: BytesLike;
28
- i?: number;
29
- j?: number;
30
- operationName?: string;
31
- }) {
32
- this.swapType = params.swapType;
33
- this.amount = params.amount;
34
- this.path = params.path;
35
- this.expectedAmount = params.expectedAmount;
36
- this.pathUniV3 = params.pathUniV3;
37
- this.rate =
38
- params.swapType !== SwapType.ExactInput
39
- ? params.expectedAmount.mul(WAD).div(params.amount)
40
- : WAD.mul(params.amount).div(params.expectedAmount);
41
- this.i = params.i;
42
- this.j = params.j;
43
- this.operationName = params.operationName;
44
- }
45
-
46
- getExpectedAmountWithSlippage(slippage: number): BigNumber {
47
- return this.swapType === SwapType.ExactInput
48
- ? this.getAmountOutMin(slippage)
49
- : this.getAmountInMax(slippage);
50
- }
51
-
52
- getAmountInMax(slippage: number): BigNumber {
53
- return this.expectedAmount
54
- .mul(PERCENTAGE_FACTOR + slippage)
55
- .div(PERCENTAGE_FACTOR);
56
- }
57
-
58
- getAmountOutMin(slippage: number): BigNumber {
59
- return this.expectedAmount
60
- .mul(PERCENTAGE_FACTOR)
61
- .div(PERCENTAGE_FACTOR + slippage);
62
- }
63
-
64
- public get from(): string {
65
- return this.path[0];
66
- }
67
-
68
- public get to(): string {
69
- return this.path[this.path.length - 1];
70
- }
71
-
72
- getFromAmount(slippage: number): BigNumber {
73
- return this.swapType === SwapType.ExactInput
74
- ? this.amount
75
- : this.getExpectedAmountWithSlippage(slippage);
76
- }
77
-
78
- getToAmount(slippage: number): BigNumber {
79
- return this.swapType === SwapType.ExactOutput
80
- ? this.amount
81
- : this.getExpectedAmountWithSlippage(slippage);
82
- }
11
+ public readonly swapType: SwapType;
12
+
13
+ public readonly amount: BigNumber;
14
+
15
+ public readonly rate: BigNumber;
16
+
17
+ public readonly path: Array<string>;
18
+
19
+ public readonly expectedAmount: BigNumber;
20
+
21
+ public readonly pathUniV3: BytesLike | undefined;
22
+
23
+ public readonly i: number | undefined;
24
+
25
+ public readonly j: number | undefined;
26
+
27
+ public readonly operationName: string | undefined;
28
+
29
+ constructor(params: {
30
+ swapType: SwapType;
31
+ amount: BigNumber;
32
+ path: Array<string>;
33
+ expectedAmount: BigNumber;
34
+ pathUniV3?: BytesLike;
35
+ i?: number;
36
+ j?: number;
37
+ operationName?: string;
38
+ }) {
39
+ this.swapType = params.swapType;
40
+ this.amount = params.amount;
41
+ this.path = params.path;
42
+ this.expectedAmount = params.expectedAmount;
43
+ this.pathUniV3 = params.pathUniV3;
44
+ this.rate =
45
+ params.swapType !== SwapType.ExactInput
46
+ ? params.expectedAmount.mul(WAD).div(params.amount)
47
+ : WAD.mul(params.amount).div(params.expectedAmount);
48
+ this.i = params.i;
49
+ this.j = params.j;
50
+ this.operationName = params.operationName;
51
+ }
52
+
53
+ getExpectedAmountWithSlippage(slippage: number): BigNumber {
54
+ return this.swapType === SwapType.ExactInput
55
+ ? this.getAmountOutMin(slippage)
56
+ : this.getAmountInMax(slippage);
57
+ }
58
+
59
+ getAmountInMax(slippage: number): BigNumber {
60
+ return this.expectedAmount
61
+ .mul(PERCENTAGE_FACTOR + slippage)
62
+ .div(PERCENTAGE_FACTOR);
63
+ }
64
+
65
+ getAmountOutMin(slippage: number): BigNumber {
66
+ return this.expectedAmount
67
+ .mul(PERCENTAGE_FACTOR)
68
+ .div(PERCENTAGE_FACTOR + slippage);
69
+ }
70
+
71
+ public get from(): string {
72
+ return this.path[0];
73
+ }
74
+
75
+ public get to(): string {
76
+ return this.path[this.path.length - 1];
77
+ }
78
+
79
+ getFromAmount(slippage: number): BigNumber {
80
+ return this.swapType === SwapType.ExactInput
81
+ ? this.amount
82
+ : this.getExpectedAmountWithSlippage(slippage);
83
+ }
84
+
85
+ getToAmount(slippage: number): BigNumber {
86
+ return this.swapType === SwapType.ExactOutput
87
+ ? this.amount
88
+ : this.getExpectedAmountWithSlippage(slippage);
89
+ }
83
90
  }
@@ -1,101 +1,105 @@
1
- import {ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract} from "../contracts/contracts";
2
- import {NormalToken} from "../tokens/normal";
3
- import {CurveLPToken} from "../tokens/curveLP";
4
- import {YearnLPToken} from "../tokens/yearn";
5
- import {ConvexLPToken, ConvexStakedPhantomToken} from "../tokens/convex";
6
-
1
+ import type {
2
+ ConvexPoolContract,
3
+ CurvePoolContract,
4
+ UniswapV2Contract,
5
+ YearnVaultContract
6
+ } from "../contracts/contracts";
7
+ import type { NormalToken } from "../tokens/normal";
8
+ import type { CurveLPToken } from "../tokens/curveLP";
9
+ import type { YearnLPToken } from "../tokens/yearn";
10
+ import type { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
7
11
 
8
12
  export enum TradeType {
9
- UniswapV2Swap,
10
- UniswapV3Swap,
11
- CurveExchange,
12
- CurveExchangeUnderlying,
13
- CurveDepositLP,
14
- CurveWithdrawLP,
15
- YearnDeposit,
16
- YearnWithdraw,
17
- LidoStake,
18
- ConvexDepositLP,
19
- ConvexStake,
20
- ConvexDepositLPAndStake,
21
- ConvexWithdrawLP,
22
- ConvexWithdraw,
23
- ConvexWithdrawAndUnwrap
13
+ UniswapV2Swap,
14
+ UniswapV3Swap,
15
+ CurveExchange,
16
+ CurveExchangeUnderlying,
17
+ CurveDepositLP,
18
+ CurveWithdrawLP,
19
+ YearnDeposit,
20
+ YearnWithdraw,
21
+ LidoStake,
22
+ ConvexDepositLP,
23
+ ConvexStake,
24
+ ConvexDepositLPAndStake,
25
+ ConvexWithdrawLP,
26
+ ConvexWithdraw,
27
+ ConvexWithdrawAndUnwrap
24
28
  }
25
29
 
26
30
  export type TradeAction =
27
- | {
28
- type: TradeType.UniswapV2Swap;
29
- contract: UniswapV2Contract;
30
- tokenOut?: NormalToken;
31
- }
32
- | {
33
- type: TradeType.UniswapV3Swap;
34
- contract: "UNISWAP_V3_ROUTER";
35
- tokenOut?: NormalToken;
36
- }
37
- | {
38
- type: TradeType.CurveExchange;
39
- contract: CurvePoolContract;
40
- tokenOut: Array<NormalToken | CurveLPToken>;
41
- }
42
- | {
43
- type: TradeType.CurveDepositLP;
44
- contract: CurvePoolContract;
45
- tokenOut: CurveLPToken;
46
- }
47
- | {
48
- type: TradeType.CurveWithdrawLP;
49
- contract: CurvePoolContract;
50
- tokenOut: Array<CurveLPToken | NormalToken>;
51
- }
52
- | {
53
- type: TradeType.YearnDeposit;
54
- contract: YearnVaultContract;
55
- tokenOut: YearnLPToken;
56
- }
57
- | {
58
- type: TradeType.YearnWithdraw;
59
- contract: YearnVaultContract;
60
- tokenOut: NormalToken | CurveLPToken;
61
- }
62
- | {
63
- type: TradeType.LidoStake;
64
- contract: "LIDO_STETH_GATEWAY";
65
- tokenOut: NormalToken;
66
- }
67
- | {
68
- type: TradeType.ConvexDepositLP;
69
- contract: "CONVEX_BOOSTER";
70
- tokenOut: ConvexLPToken;
71
- }
72
- | {
73
- type: TradeType.ConvexStake;
74
- contract: ConvexPoolContract;
75
- tokenOut: ConvexStakedPhantomToken;
76
- }
77
- | {
78
- type: TradeType.ConvexDepositLPAndStake;
79
- contract: "CONVEX_BOOSTER";
80
- tokenOut: ConvexStakedPhantomToken;
81
- }
82
- | {
83
- type: TradeType.ConvexWithdrawLP;
84
- contract: "CONVEX_BOOSTER";
85
- tokenOut: CurveLPToken;
86
- }
87
- | {
88
- type: TradeType.ConvexWithdraw;
89
- contract: ConvexPoolContract;
90
- tokenOut: ConvexLPToken;
91
- }
92
- | {
93
- type: TradeType.ConvexWithdrawAndUnwrap;
94
- contract: ConvexPoolContract;
95
- tokenOut: CurveLPToken;
96
- };
31
+ | {
32
+ type: TradeType.UniswapV2Swap;
33
+ contract: UniswapV2Contract;
34
+ tokenOut?: NormalToken;
35
+ }
36
+ | {
37
+ type: TradeType.UniswapV3Swap;
38
+ contract: "UNISWAP_V3_ROUTER";
39
+ tokenOut?: NormalToken;
40
+ }
41
+ | {
42
+ type: TradeType.CurveExchange;
43
+ contract: CurvePoolContract;
44
+ tokenOut: Array<NormalToken | CurveLPToken>;
45
+ }
46
+ | {
47
+ type: TradeType.CurveDepositLP;
48
+ contract: CurvePoolContract;
49
+ tokenOut: CurveLPToken;
50
+ }
51
+ | {
52
+ type: TradeType.CurveWithdrawLP;
53
+ contract: CurvePoolContract;
54
+ tokenOut: Array<CurveLPToken | NormalToken>;
55
+ }
56
+ | {
57
+ type: TradeType.YearnDeposit;
58
+ contract: YearnVaultContract;
59
+ tokenOut: YearnLPToken;
60
+ }
61
+ | {
62
+ type: TradeType.YearnWithdraw;
63
+ contract: YearnVaultContract;
64
+ tokenOut: NormalToken | CurveLPToken;
65
+ }
66
+ | {
67
+ type: TradeType.LidoStake;
68
+ contract: "LIDO_STETH_GATEWAY";
69
+ tokenOut: NormalToken;
70
+ }
71
+ | {
72
+ type: TradeType.ConvexDepositLP;
73
+ contract: "CONVEX_BOOSTER";
74
+ tokenOut: ConvexLPToken;
75
+ }
76
+ | {
77
+ type: TradeType.ConvexStake;
78
+ contract: ConvexPoolContract;
79
+ tokenOut: ConvexStakedPhantomToken;
80
+ }
81
+ | {
82
+ type: TradeType.ConvexDepositLPAndStake;
83
+ contract: "CONVEX_BOOSTER";
84
+ tokenOut: ConvexStakedPhantomToken;
85
+ }
86
+ | {
87
+ type: TradeType.ConvexWithdrawLP;
88
+ contract: "CONVEX_BOOSTER";
89
+ tokenOut: CurveLPToken;
90
+ }
91
+ | {
92
+ type: TradeType.ConvexWithdraw;
93
+ contract: ConvexPoolContract;
94
+ tokenOut: ConvexLPToken;
95
+ }
96
+ | {
97
+ type: TradeType.ConvexWithdrawAndUnwrap;
98
+ contract: ConvexPoolContract;
99
+ tokenOut: CurveLPToken;
100
+ };
97
101
 
98
102
  export enum SwapType {
99
- ExactInput = 1,
100
- ExactOutput = 2,
101
- }
103
+ ExactInput = 1,
104
+ ExactOutput = 2
105
+ }
@@ -1,74 +1,90 @@
1
- import {BigNumber} from "ethers";
2
- import {IYVault__factory} from "../types";
3
- import {Path, LPWithdrawPathFinder} from "./path";
4
- import {YearnLPToken, yearnTokens} from "../tokens/yearn";
5
- import {NormalToken} from "../tokens/normal";
6
- import {CurveLPToken} from "../tokens/curveLP";
7
- import {SupportedToken, tokenDataByNetwork} from "../tokens/token";
8
- import {PartialRecord} from "../utils/types";
9
- import {MCall, multicall} from "../utils/multicall";
10
- import {IYVaultInterface} from "../types/contracts/integrations/yearn/IYVault";
1
+ import { BigNumber } from "ethers";
2
+
3
+ import { YearnLPToken, yearnTokens } from "../tokens/yearn";
4
+ import { NormalToken } from "../tokens/normal";
5
+ import { CurveLPToken } from "../tokens/curveLP";
6
+ import { SupportedToken, tokenDataByNetwork } from "../tokens/token";
7
+
8
+ import { PartialRecord } from "../utils/types";
9
+ import { MCall, multicall } from "../utils/multicall";
10
+ import { objectEntries } from "../utils/mappers";
11
+
12
+ import { IYVault__factory } from "../types";
13
+ import { IYVaultInterface } from "../types/contracts/integrations/yearn/IYVault";
14
+
15
+ import type { Path, LPWithdrawPathFinder } from "./path";
11
16
 
12
17
  interface WithdrawBalance {
13
- token: SupportedToken;
14
- balance: BigNumber;
18
+ token: SupportedToken;
19
+ balance: BigNumber;
15
20
  }
16
21
 
17
22
  export class YearnVaultPathFinder implements LPWithdrawPathFinder {
18
- _vault: YearnLPToken;
19
- token: NormalToken | CurveLPToken;
23
+ _vault: YearnLPToken;
20
24
 
21
- constructor(vault: YearnLPToken) {
22
- this._vault = vault;
25
+ token: NormalToken | CurveLPToken;
23
26
 
24
- const currentTokenData = yearnTokens[vault];
27
+ constructor(vault: YearnLPToken) {
28
+ this._vault = vault;
25
29
 
26
- // Yearn Vault only has one lp action
27
- this.token = currentTokenData.underlying;
28
- }
30
+ const currentTokenData = yearnTokens[vault];
31
+
32
+ // Yearn Vault only has one lp action
33
+ this.token = currentTokenData.underlying;
34
+ }
35
+
36
+ // eslint-disable-next-line class-methods-use-this
37
+ async findWithdrawPaths(path: Path): Promise<Array<Path>> {
38
+ // make path copy
39
+ const p: Path = Object.assign(
40
+ Object.create(Object.getPrototypeOf(path)),
41
+ path
42
+ );
43
+
44
+ const vaultBalances = objectEntries(yearnTokens).reduce<
45
+ PartialRecord<SupportedToken, WithdrawBalance>
46
+ >((acc, [yVault, tokenData]) => {
47
+ const typedVault = yVault;
48
+ const currentBalance = p.popBalance(typedVault);
49
+ if (currentBalance.gt(1)) {
50
+ acc[typedVault] = {
51
+ token: tokenData.underlying,
52
+ balance: currentBalance
53
+ };
54
+ }
55
+ return acc;
56
+ }, {});
29
57
 
30
- async findWithdrawPaths(p: Path): Promise<Array<Path>> {
31
- let vaultBalances: PartialRecord<SupportedToken, WithdrawBalance> = {};
32
-
33
- for (let [yVault, tokenData] of Object.entries(yearnTokens)) {
34
- const currentBalance = p.popBalance(yVault as YearnLPToken);
35
- if (currentBalance.gt(1)) {
36
- vaultBalances[yVault as YearnLPToken] = {
37
- token: tokenData.underlying,
38
- balance: currentBalance
39
- };
40
- }
41
- }
42
-
43
- const vaultList = Object.keys(vaultBalances) as Array<SupportedToken>;
44
-
45
- // Yearn Vault only has one lp action
46
- const multicallData: Array<MCall<IYVaultInterface>> = vaultList
47
- .map(t => tokenDataByNetwork[p.networkType][t as SupportedToken])
48
- .map(addr => ({
49
- address: addr,
50
- interface: IYVault__factory.createInterface(),
51
- method: "pricePerShare()"
52
- }));
53
-
54
- const prices = await multicall<Array<BigNumber>>(multicallData, p.provider);
55
-
56
- for (let i = 0; i < vaultList.length; i++) {
57
- const vault = vaultList[i];
58
- const vb = vaultBalances[vault];
59
-
60
- p.balances[vb!.token] = (p.balances[vb!.token] || BigNumber.from(0)).add(
61
- BigNumber.from(vb?.balance || 0).mul(prices[i])
62
- );
63
-
64
- p.calls.push({
65
- targetContract:
66
- p.creditManager.adapters[tokenDataByNetwork[p.networkType][vault]],
67
- callData:
68
- IYVault__factory.createInterface().encodeFunctionData("withdraw()")
69
- });
70
- }
71
-
72
- return await p.withdrawTokens();
58
+ const vaultList = Object.keys(vaultBalances) as Array<SupportedToken>;
59
+
60
+ // Yearn Vault only has one lp action
61
+ const multicallData: Array<MCall<IYVaultInterface>> = vaultList
62
+ .map(t => tokenDataByNetwork[p.networkType][t as SupportedToken])
63
+ .map(addr => ({
64
+ address: addr,
65
+ interface: IYVault__factory.createInterface(),
66
+ method: "pricePerShare()"
67
+ }));
68
+
69
+ const prices = await multicall<Array<BigNumber>>(multicallData, p.provider);
70
+
71
+ for (let i = 0; i < vaultList.length; i += 1) {
72
+ const vault = vaultList[i];
73
+ const vb = vaultBalances[vault];
74
+
75
+ p.balances[vb!.token] = (p.balances[vb!.token] || BigNumber.from(0)).add(
76
+ BigNumber.from(vb?.balance || 0).mul(prices[i])
77
+ );
78
+
79
+ const tokenAddress = tokenDataByNetwork[p.networkType][vault];
80
+ const adapterAddress = p.creditManager.adapters[tokenAddress];
81
+
82
+ const callData =
83
+ IYVault__factory.createInterface().encodeFunctionData("withdraw()");
84
+
85
+ p.calls.push({ target: adapterAddress, callData });
73
86
  }
87
+
88
+ return p.withdrawTokens();
89
+ }
74
90
  }
@@ -1,29 +1,7 @@
1
- import {BigNumberish} from "ethers";
1
+ import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
2
2
 
3
- export interface TokenBalancePayload {
4
- token: string;
5
- balance: BigNumberish;
6
- isAllowed: boolean;
7
- }
3
+ export type TokenBalancePayload = CreditAccountDataStruct["balances"];
8
4
 
9
- export interface CreditAccountDataPayload {
10
- addr: string;
11
- borrower: string;
12
- inUse: boolean;
13
- creditManager: string;
14
- underlyingToken: string;
15
- borrowedAmountPlusInterest: BigNumberish;
16
- totalValue: BigNumberish;
17
- healthFactor: BigNumberish;
18
- borrowRate: BigNumberish;
19
- balances?: Array<TokenBalancePayload>;
20
- }
5
+ export type CreditAccountDataPayload = CreditAccountDataStruct;
21
6
 
22
- export interface CreditAccountDataExtendedPayload extends CreditAccountDataPayload {
23
- repayAmount: BigNumberish;
24
- liquidationAmount: BigNumberish;
25
- canBeClosed?: boolean;
26
- borrowedAmount: BigNumberish;
27
- cumulativeIndexAtOpen: BigNumberish;
28
- since: BigNumberish;
29
- }
7
+ export type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
@@ -1,36 +1,14 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { CreditManagerDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
2
3
 
3
4
  export interface AdapterPayload {
4
5
  allowedContract: string;
5
- adapter: string
6
+ adapter: string;
6
7
  }
7
8
 
8
- export interface CreditManagerDataPayload {
9
- addr: string;
10
- hasAccount?: boolean;
11
- underlyingToken?: string;
12
- isWETH?: boolean;
13
- canBorrow?: boolean;
14
- borrowRate?: BigNumberish;
15
- minAmount?: BigNumberish;
16
- maxAmount?: BigNumberish;
17
- maxLeverageFactor?: BigNumberish;
18
- availableLiquidity?: BigNumberish;
19
- allowedTokens?: Array<string>;
20
- adapters?: Array<AdapterPayload>;
21
- }
9
+ export type CreditManagerDataPayload = CreditManagerDataStruct;
22
10
 
23
- export interface CreditManagerStatPayload {
24
- addr: string;
25
- underlyingToken?: string;
26
- isWETH?: boolean;
27
- canBorrow?: boolean;
28
- borrowRate?: BigNumberish;
29
- minAmount?: BigNumberish;
30
- maxAmount?: BigNumberish;
31
- maxLeverageFactor?: BigNumberish;
32
- availableLiquidity?: BigNumberish;
33
- allowedTokens?: Array<string>;
11
+ export interface CreditManagerStatPayload extends CreditManagerDataPayload {
34
12
  allowedContracts?: Array<string>;
35
13
  uniqueUsers: number;
36
14
  openedAccountsCount?: number;
@@ -1,20 +1,3 @@
1
- import {BigNumberish} from "ethers";
1
+ import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
2
2
 
3
- export interface PoolDataPayload {
4
- addr: string;
5
- underlyingToken: string;
6
- dieselToken: string;
7
- isWETH: boolean;
8
- expectedLiquidity: BigNumberish;
9
- expectedLiquidityLimit?: BigNumberish;
10
- availableLiquidity: BigNumberish;
11
- totalBorrowed: BigNumberish;
12
- depositAPY_RAY: BigNumberish;
13
- borrowAPY_RAY: BigNumberish;
14
- dieselRate_RAY: BigNumberish;
15
- withdrawFee: BigNumberish;
16
- timestampLU?: BigNumberish;
17
- cumulativeIndex_RAY?: BigNumberish
18
- }
19
-
20
- //
3
+ export type PoolDataPayload = PoolDataStruct;
@@ -1,5 +1,5 @@
1
1
  export interface TokenDataPayload {
2
- addr: string;
3
- symbol: string;
4
- decimals: number;
2
+ addr: string;
3
+ symbol: string;
4
+ decimals: number;
5
5
  }