@gearbox-protocol/sdk 0.0.101 → 0.0.104

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 (139) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.js +7 -9
  5. package/lib/apy/lidoAPY.js +35 -29
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/contracts/contractsRegister.js +13 -1
  9. package/lib/core/constants.d.ts +5 -3
  10. package/lib/core/constants.js +8 -6
  11. package/lib/core/creditAccount.d.ts +2 -2
  12. package/lib/core/creditAccount.js +12 -11
  13. package/lib/core/creditManager.d.ts +1 -1
  14. package/lib/core/creditManager.js +4 -10
  15. package/lib/core/creditSession.js +14 -3
  16. package/lib/core/eventOrTx.d.ts +1 -1
  17. package/lib/core/events.d.ts +19 -19
  18. package/lib/core/events.js +23 -21
  19. package/lib/core/pool.d.ts +1 -1
  20. package/lib/core/pool.js +1 -7
  21. package/lib/core/price.d.ts +1 -3
  22. package/lib/core/price.js +9 -7
  23. package/lib/core/strategy.d.ts +8 -6
  24. package/lib/core/strategy.js +25 -25
  25. package/lib/core/tokenDistributor.js +1 -1
  26. package/lib/core/transactions.d.ts +18 -3
  27. package/lib/core/transactions.js +39 -3
  28. package/lib/index.d.ts +8 -2
  29. package/lib/index.js +8 -1
  30. package/lib/oracles/priceFeeds.js +1 -1
  31. package/lib/pathfinder/convexLP.d.ts +1 -1
  32. package/lib/pathfinder/convexLP.js +26 -29
  33. package/lib/pathfinder/curveLP.d.ts +1 -1
  34. package/lib/pathfinder/curveLP.js +5 -7
  35. package/lib/pathfinder/path.d.ts +1 -1
  36. package/lib/pathfinder/path.js +38 -42
  37. package/lib/pathfinder/trade.d.ts +1 -2
  38. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  39. package/lib/pathfinder/yVault.d.ts +2 -2
  40. package/lib/pathfinder/yVault.js +22 -22
  41. package/lib/payload/creditAccount.d.ts +4 -4
  42. package/lib/payload/creditManager.d.ts +3 -13
  43. package/lib/payload/pool.d.ts +2 -2
  44. package/lib/strategies/convex.d.ts +12 -0
  45. package/lib/strategies/convex.js +74 -1
  46. package/lib/strategies/creditFacade.d.ts +1 -0
  47. package/lib/strategies/creditFacade.js +3 -0
  48. package/lib/strategies/curve.d.ts +15 -60
  49. package/lib/strategies/curve.js +74 -1
  50. package/lib/strategies/lido.d.ts +6 -0
  51. package/lib/strategies/lido.js +23 -1
  52. package/lib/strategies/uniswapV2.d.ts +1 -0
  53. package/lib/strategies/uniswapV2.js +6 -19
  54. package/lib/strategies/uniswapV3.d.ts +1 -0
  55. package/lib/strategies/uniswapV3.js +4 -1
  56. package/lib/strategies/yearn.d.ts +8 -0
  57. package/lib/strategies/yearn.js +92 -12
  58. package/lib/tokens/convex.d.ts +3 -3
  59. package/lib/tokens/curveLP.d.ts +7 -2
  60. package/lib/tokens/curveLP.js +8 -1
  61. package/lib/tokens/gear.d.ts +2 -2
  62. package/lib/tokens/gear.js +1 -1
  63. package/lib/tokens/normal.d.ts +1 -1
  64. package/lib/tokens/token.js +8 -8
  65. package/lib/tokens/tokenData.d.ts +3 -1
  66. package/lib/tokens/tokenData.js +10 -8
  67. package/lib/tokens/yearn.d.ts +6 -2
  68. package/lib/tokens/yearn.js +6 -0
  69. package/lib/utils/errors.d.ts +6 -0
  70. package/lib/utils/errors.js +13 -0
  71. package/lib/utils/formatter.d.ts +1 -1
  72. package/lib/utils/formatter.js +17 -14
  73. package/lib/utils/loading.d.ts +2 -1
  74. package/lib/utils/loading.js +9 -13
  75. package/lib/utils/mappers.js +2 -2
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/validate.js +1 -1
  79. package/package.json +24 -7
  80. package/src/apy/convexAPY.ts +13 -12
  81. package/src/apy/lidoAPY.ts +35 -27
  82. package/src/contracts/contracts.ts +27 -17
  83. package/src/contracts/contractsRegister.ts +16 -1
  84. package/src/core/constants.ts +8 -5
  85. package/src/core/creditAccount.ts +42 -16
  86. package/src/core/creditManager.ts +33 -7
  87. package/src/core/creditOperation.ts +7 -7
  88. package/src/core/creditSession.ts +25 -5
  89. package/src/core/errors.ts +1 -0
  90. package/src/core/eventOrTx.ts +8 -5
  91. package/src/core/events.ts +85 -24
  92. package/src/core/history.ts +46 -46
  93. package/src/core/operations.ts +6 -0
  94. package/src/core/pool.ts +16 -4
  95. package/src/core/price.ts +10 -13
  96. package/src/core/strategy.ts +54 -43
  97. package/src/core/tokenDistributor.ts +2 -2
  98. package/src/core/transactions.ts +427 -350
  99. package/src/index.ts +10 -3
  100. package/src/oracles/priceFeeds.ts +523 -523
  101. package/src/pathfinder/contracts.ts +15 -13
  102. package/src/pathfinder/convexLP.ts +29 -25
  103. package/src/pathfinder/curveLP.ts +57 -53
  104. package/src/pathfinder/path.ts +17 -9
  105. package/src/pathfinder/priority.ts +11 -11
  106. package/src/pathfinder/trade.ts +84 -77
  107. package/src/pathfinder/tradeTypes.ts +98 -94
  108. package/src/pathfinder/yVault.ts +32 -17
  109. package/src/payload/creditAccount.ts +4 -4
  110. package/src/payload/creditManager.ts +3 -13
  111. package/src/payload/pool.ts +2 -2
  112. package/src/payload/token.ts +3 -3
  113. package/src/strategies/convex.ts +360 -186
  114. package/src/strategies/creditFacade.ts +74 -53
  115. package/src/strategies/curve.ts +400 -189
  116. package/src/strategies/lido.ts +70 -32
  117. package/src/strategies/uniswapV2.ts +93 -111
  118. package/src/strategies/uniswapV3.ts +118 -91
  119. package/src/strategies/yearn.ts +187 -60
  120. package/src/tokens/connectors.ts +6 -6
  121. package/src/tokens/convex.ts +297 -296
  122. package/src/tokens/curveLP.ts +176 -165
  123. package/src/tokens/gear.ts +47 -45
  124. package/src/tokens/normal.ts +801 -802
  125. package/src/tokens/token.ts +13 -9
  126. package/src/tokens/tokenData.ts +19 -9
  127. package/src/tokens/tokenType.ts +11 -11
  128. package/src/tokens/yearn.ts +130 -124
  129. package/src/utils/errors.ts +11 -0
  130. package/src/utils/formatter.ts +22 -18
  131. package/src/utils/loading.ts +14 -6
  132. package/src/utils/mappers.ts +8 -6
  133. package/src/utils/multicall.ts +2 -0
  134. package/src/utils/network.ts +21 -21
  135. package/src/utils/repeater.ts +2 -2
  136. package/src/utils/validate.ts +1 -1
  137. package/lib/utils/events.d.ts +0 -2
  138. package/lib/utils/events.js +0 -13
  139. package/src/utils/events.ts +0 -10
@@ -1,177 +1,188 @@
1
- import {TradeAction, TradeType} from "../pathfinder/tradeTypes";
2
- import {SupportedToken, TokenBase} from "./token";
3
- import {PartialRecord} from "../utils/types";
4
- import {BigNumber} from "ethers";
5
- import {TokenType} from "./tokenType";
1
+ import { BigNumber } from "ethers";
2
+ import type { CurvePoolContract } from "src/contracts/contracts";
3
+ import { TradeAction, TradeType } from "../pathfinder/tradeTypes";
4
+ import type { SupportedToken, TokenBase } from "./token";
5
+ import { PartialRecord } from "../utils/types";
6
+ import { TokenType } from "./tokenType";
6
7
 
7
8
  export type CurveLPToken =
8
- | "3Crv"
9
- | "steCRV"
10
- | "FRAX3CRV"
11
- | "LUSD3CRV"
12
- | "crvPlain3andSUSD"
13
- | "gusd3CRV";
9
+ | "3Crv"
10
+ | "steCRV"
11
+ | "FRAX3CRV"
12
+ | "LUSD3CRV"
13
+ | "crvPlain3andSUSD"
14
+ | "gusd3CRV";
14
15
 
15
16
  export type CurveLPTokenData = {
16
- symbol: CurveLPToken;
17
- type: TokenType.CURVE_LP;
18
- swapActions?: Array<TradeAction>;
19
- lpActions: Array<TradeAction>;
17
+ symbol: CurveLPToken;
18
+ type: TokenType.CURVE_LP;
19
+ swapActions?: Array<TradeAction>;
20
+ lpActions: Array<TradeAction>;
21
+ pool: CurvePoolContract;
22
+ wrapper?: CurvePoolContract;
20
23
  } & TokenBase;
21
24
 
22
25
  export type MetaCurveLPTokenData = {
23
- symbol: CurveLPToken;
24
- type: TokenType.META_CURVE_LP;
25
- lpActions: Array<TradeAction>;
26
+ symbol: CurveLPToken;
27
+ type: TokenType.META_CURVE_LP;
28
+ lpActions: Array<TradeAction>;
29
+ pool: CurvePoolContract;
30
+ wrapper?: CurvePoolContract;
26
31
  } & TokenBase;
27
32
 
28
- export const Curve3CrvUnderlyingTokenIndex: PartialRecord<SupportedToken,
29
- BigNumber> = {
30
- DAI: BigNumber.from(0),
31
- USDC: BigNumber.from(1),
32
- USDT: BigNumber.from(2)
33
+ export const Curve3CrvUnderlyingTokenIndex: PartialRecord<
34
+ SupportedToken,
35
+ BigNumber
36
+ > = {
37
+ DAI: BigNumber.from(0),
38
+ USDC: BigNumber.from(1),
39
+ USDT: BigNumber.from(2)
33
40
  };
34
41
 
35
- export const curveTokens: Record<CurveLPToken, CurveLPTokenData | MetaCurveLPTokenData> = {
36
- // CURVE LP TOKENS
37
- "3Crv": {
38
- name: "3Crv",
39
- decimals: 18,
40
-
41
- symbol: "3Crv",
42
- type: TokenType.CURVE_LP,
43
- lpActions: [
44
- {
45
- type: TradeType.CurveWithdrawLP,
46
- contract: "CURVE_3CRV_POOL",
47
- tokenOut: ["DAI", "USDC", "USDT"]
48
- },
49
- {
50
- type: TradeType.ConvexDepositLP,
51
- contract: "CONVEX_BOOSTER",
52
- tokenOut: "cvx3Crv"
53
- },
54
- {
55
- type: TradeType.ConvexDepositLPAndStake,
56
- contract: "CONVEX_BOOSTER",
57
- tokenOut: "stkcvx3Crv"
58
- }
59
- ]
60
- },
61
-
62
- steCRV: {
63
- name: "steCRV",
64
- decimals: 18,
65
-
66
- symbol: "steCRV",
67
- type: TokenType.CURVE_LP,
68
- lpActions: [
69
- {
70
- type: TradeType.CurveWithdrawLP,
71
- contract: "CURVE_STETH_GATEWAY",
72
- tokenOut: ["STETH", "WETH"]
73
- },
74
- {
75
- type: TradeType.ConvexDepositLP,
76
- contract: "CONVEX_BOOSTER",
77
- tokenOut: "cvxsteCRV"
78
- },
79
- {
80
- type: TradeType.ConvexDepositLPAndStake,
81
- contract: "CONVEX_BOOSTER",
82
- tokenOut: "stkcvxsteCRV"
83
- }
84
- ]
85
- },
86
-
87
- crvPlain3andSUSD: {
88
- name: "crvPlain3andSUSD",
89
- decimals: 18,
90
-
91
- symbol: "crvPlain3andSUSD",
92
- type: TokenType.CURVE_LP,
93
- lpActions: [
94
- {
95
- type: TradeType.CurveWithdrawLP,
96
- contract: "CURVE_SUSD_POOL",
97
- tokenOut: ["DAI", "USDC", "USDT", "sUSD"]
98
- },
99
- {
100
- type: TradeType.ConvexDepositLP,
101
- contract: "CONVEX_BOOSTER",
102
- tokenOut: "cvxcrvPlain3andSUSD"
103
- },
104
- {
105
- type: TradeType.ConvexDepositLPAndStake,
106
- contract: "CONVEX_BOOSTER",
107
- tokenOut: "stkcvxcrvPlain3andSUSD"
108
- }
109
- ]
110
- },
111
-
112
- // META CURVE LP TOKENS
113
- FRAX3CRV: {
114
- name: "FRAX3CRV-f",
115
- decimals: 18,
116
-
117
- symbol: "FRAX3CRV",
118
- type: TokenType.META_CURVE_LP,
119
- lpActions: [
120
- {
121
- type: TradeType.CurveWithdrawLP,
122
- contract: "CURVE_FRAX_POOL",
123
- tokenOut: ["FRAX", "3Crv"]
124
- },
125
- {
126
- type: TradeType.ConvexDepositLP,
127
- contract: "CONVEX_BOOSTER",
128
- tokenOut: "cvxFRAX3CRV"
129
- },
130
- {
131
- type: TradeType.ConvexDepositLPAndStake,
132
- contract: "CONVEX_BOOSTER",
133
- tokenOut: "stkcvxFRAX3CRV"
134
- }
135
- ]
136
- },
137
-
138
- LUSD3CRV: {
139
- name: "LUSD3CRV-f",
140
- decimals: 18,
141
-
142
- symbol: "LUSD3CRV",
143
- type: TokenType.META_CURVE_LP,
144
- lpActions: [
145
- {
146
- type: TradeType.CurveWithdrawLP,
147
- contract: "CURVE_LUSD_POOL",
148
- tokenOut: ["LUSD", "3Crv"]
149
- }
150
- ]
151
- },
152
-
153
- gusd3CRV: {
154
- name: "gusd3CRV",
155
- decimals: 18,
156
-
157
- symbol: "gusd3CRV",
158
- type: TokenType.META_CURVE_LP,
159
- lpActions: [
160
- {
161
- type: TradeType.CurveWithdrawLP,
162
- contract: "CURVE_GUSD_POOL",
163
- tokenOut: ["GUSD", "3Crv"]
164
- },
165
- {
166
- type: TradeType.ConvexDepositLP,
167
- contract: "CONVEX_BOOSTER",
168
- tokenOut: "cvxgusd3CRV"
169
- },
170
- {
171
- type: TradeType.ConvexDepositLPAndStake,
172
- contract: "CONVEX_BOOSTER",
173
- tokenOut: "stkcvxgusd3CRV"
174
- }
175
- ]
176
- }
42
+ export const curveTokens: Record<
43
+ CurveLPToken,
44
+ CurveLPTokenData | MetaCurveLPTokenData
45
+ > = {
46
+ // CURVE LP TOKENS
47
+ "3Crv": {
48
+ name: "3Crv",
49
+ decimals: 18,
50
+ symbol: "3Crv",
51
+ type: TokenType.CURVE_LP,
52
+ pool: "CURVE_3CRV_POOL",
53
+ lpActions: [
54
+ {
55
+ type: TradeType.CurveWithdrawLP,
56
+ contract: "CURVE_3CRV_POOL",
57
+ tokenOut: ["DAI", "USDC", "USDT"]
58
+ },
59
+ {
60
+ type: TradeType.ConvexDepositLP,
61
+ contract: "CONVEX_BOOSTER",
62
+ tokenOut: "cvx3Crv"
63
+ },
64
+ {
65
+ type: TradeType.ConvexDepositLPAndStake,
66
+ contract: "CONVEX_BOOSTER",
67
+ tokenOut: "stkcvx3Crv"
68
+ }
69
+ ]
70
+ },
71
+
72
+ steCRV: {
73
+ name: "steCRV",
74
+ decimals: 18,
75
+ symbol: "steCRV",
76
+ type: TokenType.CURVE_LP,
77
+ pool: "CURVE_STETH_GATEWAY",
78
+ lpActions: [
79
+ {
80
+ type: TradeType.CurveWithdrawLP,
81
+ contract: "CURVE_STETH_GATEWAY",
82
+ tokenOut: ["STETH", "WETH"]
83
+ },
84
+ {
85
+ type: TradeType.ConvexDepositLP,
86
+ contract: "CONVEX_BOOSTER",
87
+ tokenOut: "cvxsteCRV"
88
+ },
89
+ {
90
+ type: TradeType.ConvexDepositLPAndStake,
91
+ contract: "CONVEX_BOOSTER",
92
+ tokenOut: "stkcvxsteCRV"
93
+ }
94
+ ]
95
+ },
96
+
97
+ crvPlain3andSUSD: {
98
+ name: "crvPlain3andSUSD",
99
+ decimals: 18,
100
+ symbol: "crvPlain3andSUSD",
101
+ type: TokenType.CURVE_LP,
102
+ pool: "CURVE_SUSD_POOL",
103
+ wrapper: "CURVE_SUSD_DEPOSIT",
104
+ lpActions: [
105
+ {
106
+ type: TradeType.CurveWithdrawLP,
107
+ contract: "CURVE_SUSD_POOL",
108
+ tokenOut: ["DAI", "USDC", "USDT", "sUSD"]
109
+ },
110
+ {
111
+ type: TradeType.ConvexDepositLP,
112
+ contract: "CONVEX_BOOSTER",
113
+ tokenOut: "cvxcrvPlain3andSUSD"
114
+ },
115
+ {
116
+ type: TradeType.ConvexDepositLPAndStake,
117
+ contract: "CONVEX_BOOSTER",
118
+ tokenOut: "stkcvxcrvPlain3andSUSD"
119
+ }
120
+ ]
121
+ },
122
+
123
+ // META CURVE LP TOKENS
124
+ FRAX3CRV: {
125
+ name: "FRAX3CRV-f",
126
+ decimals: 18,
127
+ symbol: "FRAX3CRV",
128
+ type: TokenType.META_CURVE_LP,
129
+ pool: "CURVE_FRAX_POOL",
130
+ lpActions: [
131
+ {
132
+ type: TradeType.CurveWithdrawLP,
133
+ contract: "CURVE_FRAX_POOL",
134
+ tokenOut: ["FRAX", "3Crv"]
135
+ },
136
+ {
137
+ type: TradeType.ConvexDepositLP,
138
+ contract: "CONVEX_BOOSTER",
139
+ tokenOut: "cvxFRAX3CRV"
140
+ },
141
+ {
142
+ type: TradeType.ConvexDepositLPAndStake,
143
+ contract: "CONVEX_BOOSTER",
144
+ tokenOut: "stkcvxFRAX3CRV"
145
+ }
146
+ ]
147
+ },
148
+
149
+ LUSD3CRV: {
150
+ name: "LUSD3CRV-f",
151
+ decimals: 18,
152
+ symbol: "LUSD3CRV",
153
+ type: TokenType.META_CURVE_LP,
154
+ pool: "CURVE_LUSD_POOL",
155
+ lpActions: [
156
+ {
157
+ type: TradeType.CurveWithdrawLP,
158
+ contract: "CURVE_LUSD_POOL",
159
+ tokenOut: ["LUSD", "3Crv"]
160
+ }
161
+ ]
162
+ },
163
+
164
+ gusd3CRV: {
165
+ name: "gusd3CRV",
166
+ decimals: 18,
167
+ symbol: "gusd3CRV",
168
+ type: TokenType.META_CURVE_LP,
169
+ pool: "CURVE_GUSD_POOL",
170
+ lpActions: [
171
+ {
172
+ type: TradeType.CurveWithdrawLP,
173
+ contract: "CURVE_GUSD_POOL",
174
+ tokenOut: ["GUSD", "3Crv"]
175
+ },
176
+ {
177
+ type: TradeType.ConvexDepositLP,
178
+ contract: "CONVEX_BOOSTER",
179
+ tokenOut: "cvxgusd3CRV"
180
+ },
181
+ {
182
+ type: TradeType.ConvexDepositLPAndStake,
183
+ contract: "CONVEX_BOOSTER",
184
+ tokenOut: "stkcvxgusd3CRV"
185
+ }
186
+ ]
187
+ }
177
188
  };
@@ -1,56 +1,58 @@
1
- import {TokenBase} from "./token";
2
- import {TradeAction} from "../pathfinder/tradeTypes";
3
- import {TokenType} from "./tokenType";
1
+ import type { TokenBase } from "./token";
2
+ import type { TradeAction } from "../pathfinder/tradeTypes";
3
+ import { TokenType } from "./tokenType";
4
4
 
5
5
  export type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH";
6
6
  export type GearboxToken = "GEAR";
7
7
 
8
8
  export type DieselTokenData = {
9
- symbol: DieselTokenTypes;
10
- type: TokenType.DIESEL_LP_TOKEN;
9
+ symbol: DieselTokenTypes;
10
+ type: TokenType.DIESEL_LP_TOKEN;
11
11
  } & TokenBase;
12
12
 
13
13
  export type GearboxTokenData = {
14
- symbol: GearboxToken;
15
- swapActions?: Array<TradeAction>;
16
- type: TokenType.NORMAL_TOKEN;
14
+ symbol: GearboxToken;
15
+ swapActions?: Array<TradeAction>;
16
+ type: TokenType.NORMAL_TOKEN;
17
17
  } & TokenBase;
18
18
 
19
- export const gearTokens: Record<DieselTokenTypes | GearboxToken,
20
- DieselTokenData | GearboxTokenData> = {
21
- //GEARBOX
22
- dDAI: {
23
- name: "dDAI",
24
- decimals: 18,
25
- symbol: "dDAI",
26
- type: TokenType.DIESEL_LP_TOKEN
27
- },
28
-
29
- dUSDC: {
30
- name: "dUSDC",
31
- decimals: 6,
32
- symbol: "dUSDC",
33
- type: TokenType.DIESEL_LP_TOKEN
34
- },
35
-
36
- dWBTC: {
37
- name: "dWBTC",
38
- decimals: 8,
39
- symbol: "dWBTC",
40
- type: TokenType.DIESEL_LP_TOKEN
41
- },
42
-
43
- dWETH: {
44
- name: "dWETH",
45
- decimals: 18,
46
- symbol: "dWETH",
47
- type: TokenType.DIESEL_LP_TOKEN
48
- },
49
-
50
- GEAR: {
51
- name: "GEAR",
52
- decimals: 18,
53
- symbol: "GEAR",
54
- type: TokenType.NORMAL_TOKEN
55
- }
19
+ export const gearTokens: Record<
20
+ DieselTokenTypes | GearboxToken,
21
+ DieselTokenData | GearboxTokenData
22
+ > = {
23
+ // GEARBOX
24
+ dDAI: {
25
+ name: "dDAI",
26
+ decimals: 18,
27
+ symbol: "dDAI",
28
+ type: TokenType.DIESEL_LP_TOKEN
29
+ },
30
+
31
+ dUSDC: {
32
+ name: "dUSDC",
33
+ decimals: 6,
34
+ symbol: "dUSDC",
35
+ type: TokenType.DIESEL_LP_TOKEN
36
+ },
37
+
38
+ dWBTC: {
39
+ name: "dWBTC",
40
+ decimals: 8,
41
+ symbol: "dWBTC",
42
+ type: TokenType.DIESEL_LP_TOKEN
43
+ },
44
+
45
+ dWETH: {
46
+ name: "dWETH",
47
+ decimals: 18,
48
+ symbol: "dWETH",
49
+ type: TokenType.DIESEL_LP_TOKEN
50
+ },
51
+
52
+ GEAR: {
53
+ name: "GEAR",
54
+ decimals: 18,
55
+ symbol: "GEAR",
56
+ type: TokenType.NORMAL_TOKEN
57
+ }
56
58
  };