@gearbox-protocol/sdk 0.0.102 → 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 (119) 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.js +3 -5
  5. package/lib/apy/lidoAPY.js +8 -9
  6. package/lib/contracts/contracts.d.ts +3 -3
  7. package/lib/contracts/contracts.js +2 -2
  8. package/lib/core/constants.d.ts +1 -1
  9. package/lib/core/constants.js +2 -2
  10. package/lib/core/creditAccount.js +7 -5
  11. package/lib/core/creditManager.d.ts +1 -1
  12. package/lib/core/creditManager.js +1 -7
  13. package/lib/core/creditSession.js +14 -3
  14. package/lib/core/eventOrTx.d.ts +1 -1
  15. package/lib/core/events.d.ts +19 -19
  16. package/lib/core/events.js +23 -21
  17. package/lib/core/pool.d.ts +1 -1
  18. package/lib/core/pool.js +1 -7
  19. package/lib/core/price.js +6 -1
  20. package/lib/core/strategy.d.ts +1 -3
  21. package/lib/core/strategy.js +14 -13
  22. package/lib/core/tokenDistributor.js +1 -1
  23. package/lib/core/transactions.d.ts +18 -3
  24. package/lib/core/transactions.js +39 -3
  25. package/lib/index.d.ts +1 -2
  26. package/lib/index.js +1 -1
  27. package/lib/oracles/priceFeeds.js +1 -1
  28. package/lib/pathfinder/convexLP.d.ts +1 -1
  29. package/lib/pathfinder/convexLP.js +26 -29
  30. package/lib/pathfinder/curveLP.d.ts +1 -1
  31. package/lib/pathfinder/curveLP.js +5 -7
  32. package/lib/pathfinder/path.d.ts +1 -1
  33. package/lib/pathfinder/path.js +38 -42
  34. package/lib/pathfinder/trade.d.ts +1 -2
  35. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  36. package/lib/pathfinder/yVault.d.ts +2 -2
  37. package/lib/pathfinder/yVault.js +18 -15
  38. package/lib/strategies/curve.d.ts +6 -60
  39. package/lib/strategies/curve.js +6 -0
  40. package/lib/strategies/uniswapV2.js +3 -19
  41. package/lib/strategies/uniswapV3.js +1 -1
  42. package/lib/strategies/yearn.js +15 -11
  43. package/lib/tokens/convex.d.ts +3 -3
  44. package/lib/tokens/curveLP.d.ts +2 -2
  45. package/lib/tokens/curveLP.js +1 -1
  46. package/lib/tokens/gear.d.ts +2 -2
  47. package/lib/tokens/gear.js +1 -1
  48. package/lib/tokens/normal.d.ts +1 -1
  49. package/lib/tokens/token.js +4 -4
  50. package/lib/tokens/tokenData.d.ts +3 -1
  51. package/lib/tokens/tokenData.js +10 -8
  52. package/lib/tokens/yearn.d.ts +3 -3
  53. package/lib/utils/errors.d.ts +6 -0
  54. package/lib/utils/errors.js +13 -0
  55. package/lib/utils/formatter.d.ts +1 -1
  56. package/lib/utils/formatter.js +17 -14
  57. package/lib/utils/loading.d.ts +2 -1
  58. package/lib/utils/loading.js +9 -13
  59. package/lib/utils/mappers.js +2 -2
  60. package/lib/utils/network.js +2 -2
  61. package/lib/utils/repeater.js +12 -24
  62. package/lib/utils/validate.js +1 -1
  63. package/package.json +26 -8
  64. package/src/apy/convexAPY.ts +6 -6
  65. package/src/apy/lidoAPY.ts +12 -11
  66. package/src/contracts/contracts.ts +8 -7
  67. package/src/core/constants.ts +1 -1
  68. package/src/core/creditAccount.ts +28 -5
  69. package/src/core/creditManager.ts +29 -4
  70. package/src/core/creditOperation.ts +7 -7
  71. package/src/core/creditSession.ts +25 -5
  72. package/src/core/errors.ts +1 -0
  73. package/src/core/eventOrTx.ts +8 -5
  74. package/src/core/events.ts +85 -24
  75. package/src/core/history.ts +46 -46
  76. package/src/core/operations.ts +6 -0
  77. package/src/core/pool.ts +16 -4
  78. package/src/core/price.ts +7 -3
  79. package/src/core/strategy.ts +27 -23
  80. package/src/core/tokenDistributor.ts +2 -2
  81. package/src/core/transactions.ts +427 -350
  82. package/src/index.ts +1 -3
  83. package/src/oracles/priceFeeds.ts +523 -523
  84. package/src/pathfinder/contracts.ts +15 -13
  85. package/src/pathfinder/convexLP.ts +29 -25
  86. package/src/pathfinder/curveLP.ts +57 -53
  87. package/src/pathfinder/path.ts +17 -9
  88. package/src/pathfinder/priority.ts +11 -11
  89. package/src/pathfinder/trade.ts +84 -77
  90. package/src/pathfinder/tradeTypes.ts +98 -94
  91. package/src/pathfinder/yVault.ts +26 -11
  92. package/src/payload/token.ts +3 -3
  93. package/src/strategies/convex.ts +217 -210
  94. package/src/strategies/creditFacade.ts +70 -53
  95. package/src/strategies/curve.ts +263 -194
  96. package/src/strategies/lido.ts +33 -37
  97. package/src/strategies/uniswapV2.ts +90 -112
  98. package/src/strategies/uniswapV3.ts +114 -91
  99. package/src/strategies/yearn.ts +58 -62
  100. package/src/tokens/connectors.ts +6 -6
  101. package/src/tokens/convex.ts +297 -296
  102. package/src/tokens/curveLP.ts +170 -165
  103. package/src/tokens/gear.ts +47 -45
  104. package/src/tokens/normal.ts +801 -802
  105. package/src/tokens/token.ts +9 -5
  106. package/src/tokens/tokenData.ts +19 -9
  107. package/src/tokens/tokenType.ts +11 -11
  108. package/src/tokens/yearn.ts +126 -124
  109. package/src/utils/errors.ts +11 -0
  110. package/src/utils/formatter.ts +22 -18
  111. package/src/utils/loading.ts +14 -6
  112. package/src/utils/mappers.ts +8 -6
  113. package/src/utils/multicall.ts +2 -0
  114. package/src/utils/network.ts +21 -21
  115. package/src/utils/repeater.ts +2 -2
  116. package/src/utils/validate.ts +1 -1
  117. package/lib/utils/events.d.ts +0 -2
  118. package/lib/utils/events.js +0 -13
  119. package/src/utils/events.ts +0 -10
@@ -1,6 +1,6 @@
1
1
  import { BigNumber } from "ethers";
2
- import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "../core/constants";
3
- import { calcTotalPrice } from "../core/price";
2
+ import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "./constants";
3
+ import { calcTotalPrice } from "./price";
4
4
 
5
5
  export interface StrategyPayload {
6
6
  apy?: number;
@@ -31,10 +31,13 @@ export class Strategy {
31
31
  apy: number | undefined;
32
32
 
33
33
  name: string;
34
+
34
35
  lpToken: string;
36
+
35
37
  pools: Array<string>;
36
38
 
37
39
  unleveragableCollateral: Array<string>;
40
+
38
41
  leveragableCollateral: Array<string>;
39
42
 
40
43
  baseAssets: Array<string>;
@@ -50,10 +53,15 @@ export class Strategy {
50
53
  this.baseAssets = payload.baseAssets;
51
54
  }
52
55
 
53
- public maxAPY(apy: number, maxLeverage: number, poolApy: PoolList) {
54
- const minApy = this.minBorrowApy(poolApy);
56
+ public maxAPY(maxLeverage: number, poolApy: PoolList) {
57
+ const minApy = minBorrowApy(poolApy);
55
58
 
56
- return this.roi(apy, maxLeverage, maxLeverage - LEVERAGE_DECIMALS, minApy);
59
+ return roi(
60
+ this.apy || 0,
61
+ maxLeverage,
62
+ maxLeverage - LEVERAGE_DECIMALS,
63
+ minApy
64
+ );
57
65
  }
58
66
 
59
67
  public overallAPY(
@@ -64,9 +72,10 @@ export class Strategy {
64
72
  ) {
65
73
  const farmLev = this.farmLev(leverage, depositCollateral);
66
74
 
67
- return this.roi(apy, farmLev, leverage - LEVERAGE_DECIMALS, borrowAPY);
75
+ return roi(apy, farmLev, leverage - LEVERAGE_DECIMALS, borrowAPY);
68
76
  }
69
77
 
78
+ // eslint-disable-next-line class-methods-use-this
70
79
  public liquidationPrice(
71
80
  borrowed: TokenDescription,
72
81
  collateral: TokenDescription,
@@ -92,23 +101,6 @@ export class Strategy {
92
101
  : BigNumber.from(0);
93
102
  }
94
103
 
95
- private roi(
96
- apy: number,
97
- farmLev: number,
98
- debtLev: number,
99
- borrowAPY: number
100
- ) {
101
- return (apy * farmLev - borrowAPY * debtLev) / LEVERAGE_DECIMALS;
102
- }
103
-
104
- private minBorrowApy(poolApy: PoolList) {
105
- const apys = Object.values(poolApy).sort(
106
- (a, b) => a.borrowRate - b.borrowRate
107
- );
108
-
109
- return apys.length > 0 ? apys[0].borrowRate : 0;
110
- }
111
-
112
104
  private farmLev(leverage: number, depositCollateral: string) {
113
105
  return this.inBaseAssets(depositCollateral) ||
114
106
  this.inLeveragableAssets(depositCollateral)
@@ -128,3 +120,15 @@ export class Strategy {
128
120
  );
129
121
  }
130
122
  }
123
+
124
+ function roi(apy: number, farmLev: number, debtLev: number, borrowAPY: number) {
125
+ return (apy * farmLev - borrowAPY * debtLev) / LEVERAGE_DECIMALS;
126
+ }
127
+
128
+ function minBorrowApy(poolApy: PoolList) {
129
+ const apys = Object.values(poolApy).sort(
130
+ (a, b) => a.borrowRate - b.borrowRate
131
+ );
132
+
133
+ return apys.length > 0 ? apys[0].borrowRate : 0;
134
+ }
@@ -1,4 +1,4 @@
1
- import {BigNumber} from "ethers";
1
+ import { BigNumber } from "ethers";
2
2
 
3
3
  export interface TokenShare {
4
4
  holder: string;
@@ -10,5 +10,5 @@ export interface TokenShare {
10
10
  export enum VotingPower {
11
11
  A, // A-type voting power & A-type vesting parameters
12
12
  B, // B-type voting power & B-type vesting parameters
13
- ZERO_VOTING_POWER, // zero voting power & B-type vesting parameters
13
+ ZERO_VOTING_POWER // zero voting power & B-type vesting parameters
14
14
  }