@gearbox-protocol/sdk 0.0.109 → 0.0.110

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 (112) hide show
  1. package/lib/apy/convexAPY copy.d.ts +6 -0
  2. package/lib/apy/convexAPY copy.js +201 -0
  3. package/lib/apy/convexAPY.d.ts +9 -5
  4. package/lib/apy/convexAPY.js +29 -69
  5. package/lib/apy/curveAPY.d.ts +4 -0
  6. package/lib/apy/curveAPY.js +94 -0
  7. package/lib/apy/index.d.ts +6 -0
  8. package/lib/apy/index.js +20 -0
  9. package/lib/apy/lidoAPY.d.ts +1 -1
  10. package/lib/apy/lidoAPY.js +3 -3
  11. package/lib/apy/yearnAPY.d.ts +4 -0
  12. package/lib/apy/yearnAPY.js +90 -0
  13. package/lib/contracts/contractsRegister.js +2 -1
  14. package/lib/core/creditAccount.d.ts +2 -1
  15. package/lib/core/creditAccount.js +19 -12
  16. package/lib/core/creditManager.d.ts +3 -1
  17. package/lib/core/creditManager.js +22 -8
  18. package/lib/core/errors.d.ts +1 -1
  19. package/lib/core/pool.js +4 -4
  20. package/lib/core/strategy.d.ts +5 -3
  21. package/lib/core/strategy.js +6 -4
  22. package/lib/index.d.ts +4 -4
  23. package/lib/index.js +7 -6
  24. package/lib/tokens/convex.d.ts +3 -0
  25. package/lib/tokens/convex.js +44 -18
  26. package/lib/tokens/curveLP.d.ts +1 -0
  27. package/lib/tokens/curveLP.js +11 -7
  28. package/lib/tokens/normal.d.ts +1 -0
  29. package/lib/tokens/normal.js +5 -1
  30. package/lib/tokens/token.d.ts +7 -2
  31. package/lib/tokens/token.js +10 -1
  32. package/lib/tokens/tokenData.js +2 -3
  33. package/lib/tokens/yearn.d.ts +1 -0
  34. package/lib/tokens/yearn.js +11 -7
  35. package/lib/utils/extracter.d.ts +11 -0
  36. package/lib/utils/extracter.js +19 -0
  37. package/lib/utils/mappers.d.ts +2 -2
  38. package/lib/utils/price.d.ts +8 -0
  39. package/lib/utils/price.js +26 -0
  40. package/package.json +1 -1
  41. package/src/apy/convexAPY.ts +47 -96
  42. package/src/apy/curveAPY.ts +68 -0
  43. package/src/apy/index.ts +8 -0
  44. package/src/apy/lidoAPY.ts +1 -1
  45. package/src/apy/yearnAPY.ts +66 -0
  46. package/src/contracts/contractsRegister.ts +2 -1
  47. package/src/core/creditAccount.ts +20 -12
  48. package/src/core/creditManager.ts +35 -10
  49. package/src/core/errors.ts +1 -0
  50. package/src/core/pool.ts +4 -4
  51. package/src/core/strategy.ts +16 -10
  52. package/src/index.ts +4 -4
  53. package/src/tokens/convex.ts +43 -20
  54. package/src/tokens/curveLP.ts +9 -6
  55. package/src/tokens/normal.ts +3 -0
  56. package/src/tokens/token.ts +24 -6
  57. package/src/tokens/tokenData.ts +2 -4
  58. package/src/tokens/yearn.ts +9 -6
  59. package/src/utils/extracter.ts +30 -0
  60. package/src/utils/mappers.ts +2 -2
  61. package/src/utils/price.ts +33 -0
  62. package/lib/core/price.d.ts +0 -2
  63. package/lib/core/price.js +0 -14
  64. package/lib/types/@chainlink/contracts/src/v0.6/index.d.ts +0 -2
  65. package/lib/types/@chainlink/contracts/src/v0.6/index.js +0 -2
  66. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.d.ts +0 -146
  67. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.js +0 -2
  68. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
  69. package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -2
  70. package/lib/types/contracts/integrations/lido/IstETH.d.ts +0 -154
  71. package/lib/types/contracts/integrations/lido/IstETH.js +0 -2
  72. package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.d.ts +0 -50
  73. package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.js +0 -2
  74. package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.d.ts +0 -27
  75. package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.js +0 -2
  76. package/lib/types/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
  77. package/lib/types/contracts/pathfinder/Balances.sol/index.js +0 -2
  78. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.d.ts +0 -269
  79. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.js +0 -2
  80. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
  81. package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -2
  82. package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.d.ts +0 -58
  83. package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.js +0 -2
  84. package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.d.ts +0 -528
  85. package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.js +0 -2
  86. package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.d.ts +0 -528
  87. package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.js +0 -2
  88. package/lib/types/factories/@chainlink/contracts/src/v0.6/index.d.ts +0 -1
  89. package/lib/types/factories/@chainlink/contracts/src/v0.6/index.js +0 -30
  90. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.d.ts +0 -22
  91. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.js +0 -133
  92. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
  93. package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -8
  94. package/lib/types/factories/contracts/integrations/lido/IstETH__factory.d.ts +0 -35
  95. package/lib/types/factories/contracts/integrations/lido/IstETH__factory.js +0 -224
  96. package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.d.ts +0 -18
  97. package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.js +0 -40
  98. package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.d.ts +0 -28
  99. package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.js +0 -76
  100. package/lib/types/factories/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
  101. package/lib/types/factories/contracts/pathfinder/Balances.sol/index.js +0 -8
  102. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.d.ts +0 -144
  103. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.js +0 -522
  104. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
  105. package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -8
  106. package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.d.ts +0 -34
  107. package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.js +0 -110
  108. package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.d.ts +0 -65
  109. package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.js +0 -775
  110. package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.d.ts +0 -65
  111. package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.js +0 -775
  112. package/src/core/price.ts +0 -13
@@ -100,7 +100,7 @@ export class CreditManagerData {
100
100
  >((acc, threshold, index) => {
101
101
  const address = payload.collateralTokens[index];
102
102
 
103
- if (address) acc[address] = BigNumber.from(threshold);
103
+ if (address) acc[address.toLowerCase()] = BigNumber.from(threshold);
104
104
 
105
105
  return acc;
106
106
  }, {});
@@ -161,25 +161,50 @@ export class CreditManagerData {
161
161
  };
162
162
  }
163
163
 
164
- validateOpenAccount(totalAmount: BigNumber, leverage: number): true {
165
- if (totalAmount.lt(this.minAmount))
164
+ validateOpenAccount(collateral: BigNumber, debt: BigNumber): true {
165
+ return this.version === 2
166
+ ? this.validateOpenAccountV2(debt)
167
+ : this.validateOpenAccountV1(collateral, debt);
168
+ }
169
+
170
+ protected validateOpenAccountV1(
171
+ collateral: BigNumber,
172
+ debt: BigNumber
173
+ ): true {
174
+ if (collateral.lt(this.minAmount))
166
175
  throw new OpenAccountError("amountLessMin", this.minAmount);
167
176
 
168
- if (totalAmount.gt(this.maxAmount))
177
+ if (collateral.gt(this.maxAmount))
169
178
  throw new OpenAccountError("amountGreaterMax", this.maxAmount);
170
179
 
180
+ const leverage = debt.mul(LEVERAGE_DECIMALS).div(collateral).toNumber();
181
+
182
+ if (!leverage || leverage < 0)
183
+ throw new OpenAccountError("wrongLeverage", BigNumber.from(0));
184
+
171
185
  if (leverage > this.maxLeverageFactor)
172
186
  throw new OpenAccountError(
173
187
  "leverageGreaterMax",
174
188
  BigNumber.from(this.maxLeverageFactor)
175
189
  );
176
190
 
177
- if (
178
- totalAmount
179
- .mul(leverage)
180
- .div(LEVERAGE_DECIMALS)
181
- .gt(this.availableLiquidity)
182
- )
191
+ if (debt.gt(this.availableLiquidity))
192
+ throw new OpenAccountError(
193
+ "insufficientPoolLiquidity",
194
+ BigNumber.from(this.availableLiquidity)
195
+ );
196
+
197
+ return true;
198
+ }
199
+
200
+ protected validateOpenAccountV2(debt: BigNumber): true {
201
+ if (debt.lt(this.minAmount))
202
+ throw new OpenAccountError("amountLessMin", this.minAmount);
203
+
204
+ if (debt.gt(this.maxAmount))
205
+ throw new OpenAccountError("amountGreaterMax", this.maxAmount);
206
+
207
+ if (debt.gt(this.availableLiquidity))
183
208
  throw new OpenAccountError(
184
209
  "insufficientPoolLiquidity",
185
210
  BigNumber.from(this.availableLiquidity)
@@ -49,6 +49,7 @@ export class AccountsInAlllCreditManagersError extends Error {
49
49
  export type OpenAccountErrorTypes =
50
50
  | "insufficientPoolLiquidity"
51
51
  | "leverageGreaterMax"
52
+ | "wrongLeverage"
52
53
  | "amountGreaterMax"
53
54
  | "amountLessMin";
54
55
 
package/src/core/pool.ts CHANGED
@@ -46,10 +46,10 @@ export class PoolData {
46
46
  public readonly isPaused: boolean = false;
47
47
 
48
48
  constructor(payload: PoolDataPayload) {
49
- this.id = payload.addr;
50
- this.address = payload.addr;
51
- this.underlyingToken = payload.underlying || "";
52
- this.dieselToken = payload.dieselToken || "";
49
+ this.id = payload.addr.toLowerCase();
50
+ this.address = payload.addr.toLowerCase();
51
+ this.underlyingToken = payload.underlying.toLowerCase();
52
+ this.dieselToken = payload.dieselToken.toLowerCase();
53
53
 
54
54
  this.isWETH = payload.isWETH || false;
55
55
 
@@ -1,9 +1,11 @@
1
1
  import { BigNumber } from "ethers";
2
+ import { calcTotalPrice } from "../utils/price";
3
+ import { TokensWithAPY } from "../apy";
2
4
  import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "./constants";
3
- import { calcTotalPrice } from "./price";
4
5
 
5
6
  export interface StrategyPayload {
6
7
  apy?: number;
8
+ apyTokenSymbol: TokensWithAPY;
7
9
 
8
10
  name: string;
9
11
  lpToken: string;
@@ -53,7 +55,7 @@ export class Strategy {
53
55
  this.baseAssets = payload.baseAssets;
54
56
  }
55
57
 
56
- public maxAPY(maxLeverage: number, poolApy: PoolList) {
58
+ maxAPY(maxLeverage: number, poolApy: PoolList) {
57
59
  const minApy = minBorrowApy(poolApy);
58
60
 
59
61
  return roi(
@@ -64,7 +66,7 @@ export class Strategy {
64
66
  );
65
67
  }
66
68
 
67
- public overallAPY(
69
+ overallAPY(
68
70
  apy: number,
69
71
  leverage: number,
70
72
  depositCollateral: string,
@@ -76,7 +78,7 @@ export class Strategy {
76
78
  }
77
79
 
78
80
  // eslint-disable-next-line class-methods-use-this
79
- public liquidationPrice(
81
+ liquidationPrice(
80
82
  borrowed: TokenDescription,
81
83
  collateral: TokenDescription,
82
84
  lp: TokenDescription,
@@ -96,25 +98,29 @@ export class Strategy {
96
98
  .div(PERCENTAGE_FACTOR);
97
99
  const lpMoney = calcTotalPrice(lp.price, lp.amount, lp.decimals);
98
100
 
99
- return lpMoney.gt(0)
100
- ? borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney)
101
- : BigNumber.from(0);
101
+ if (lpMoney.gt(0)) {
102
+ const lqPrice = borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney);
103
+
104
+ return lqPrice.gte(0) ? lqPrice : BigNumber.from(0);
105
+ }
106
+
107
+ return BigNumber.from(0);
102
108
  }
103
109
 
104
- private farmLev(leverage: number, depositCollateral: string) {
110
+ protected farmLev(leverage: number, depositCollateral: string) {
105
111
  return this.inBaseAssets(depositCollateral) ||
106
112
  this.inLeveragableAssets(depositCollateral)
107
113
  ? leverage
108
114
  : leverage - LEVERAGE_DECIMALS;
109
115
  }
110
116
 
111
- private inBaseAssets(depositCollateral: string) {
117
+ protected inBaseAssets(depositCollateral: string) {
112
118
  return this.baseAssets.some(
113
119
  c => c.toLowerCase() === depositCollateral.toLowerCase()
114
120
  );
115
121
  }
116
122
 
117
- private inLeveragableAssets(depositCollateral: string) {
123
+ protected inLeveragableAssets(depositCollateral: string) {
118
124
  return this.leveragableCollateral.some(
119
125
  c => c.toLowerCase() === depositCollateral.toLowerCase()
120
126
  );
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from "./core/constants";
2
- export * from "./core/price";
3
2
  export * from "./core/creditAccount";
4
3
  export * from "./core/creditManager";
5
4
  export * from "./core/creditSession";
@@ -40,13 +39,13 @@ export * from "./tokens/gear";
40
39
  export * from "./tokens/normal";
41
40
  export * from "./tokens/yearn";
42
41
 
43
- export * from "./apy/lidoAPY";
44
- export * from "./apy/convexAPY";
42
+ export * from "./apy";
45
43
 
46
44
  export * from "./core/history";
47
45
  export * from "./utils/multicall";
48
46
  export * from "./utils/types";
49
47
  export * from "./utils/errors";
48
+ export * from "./utils/price";
50
49
 
51
50
  export * from "./strategies/convex";
52
51
  export * from "./strategies/creditFacade";
@@ -60,5 +59,6 @@ export { callRepeater } from "./utils/repeater";
60
59
  export { getContractName } from "./contracts/contractsRegister";
61
60
  export { AdapterInterface } from "./contracts/adapters";
62
61
  export { objectEntries, swapKeyValue, keyToLowercase } from "./utils/mappers";
62
+ export { getPoolTokens, getUnderlyingToken } from "./utils/extracter";
63
63
 
64
- export { SwapType } from "./pathfinder/tradeTypes";
64
+ export * from "./pathfinder/tradeTypes";
@@ -39,13 +39,9 @@ export type ConvexPhantomTokenData = {
39
39
  lpToken: ConvexLPToken;
40
40
  } & BaseConvexToken;
41
41
 
42
- export const convexTokens: Record<
43
- ConvexLPToken | ConvexStakedPhantomToken,
44
- ConvexLPTokenData | ConvexPhantomTokenData
45
- > = {
46
- // CONVEX LP TOKENS
42
+ const convexLpTokens: Record<ConvexLPToken, ConvexLPTokenData> = {
47
43
  cvx3Crv: {
48
- name: "cvx3Crv",
44
+ name: "Convex cvx3Crv",
49
45
  decimals: 18,
50
46
 
51
47
  symbol: "cvx3Crv",
@@ -69,7 +65,7 @@ export const convexTokens: Record<
69
65
  },
70
66
 
71
67
  cvxsteCRV: {
72
- name: "cvxsteCRV",
68
+ name: "Convex cvxsteCRV",
73
69
  decimals: 18,
74
70
 
75
71
  symbol: "cvxsteCRV",
@@ -93,7 +89,7 @@ export const convexTokens: Record<
93
89
  },
94
90
 
95
91
  cvxFRAX3CRV: {
96
- name: "cvxFRAX3CRV-f",
92
+ name: "Convex cvxFRAX3CRV-f",
97
93
  decimals: 18,
98
94
 
99
95
  symbol: "cvxFRAX3CRV",
@@ -117,7 +113,7 @@ export const convexTokens: Record<
117
113
  },
118
114
 
119
115
  cvxLUSD3CRV: {
120
- name: "cvxLUSD3CRV-f",
116
+ name: "Convex cvxLUSD3CRV-f",
121
117
  decimals: 18,
122
118
 
123
119
  symbol: "cvxLUSD3CRV",
@@ -141,7 +137,7 @@ export const convexTokens: Record<
141
137
  },
142
138
 
143
139
  cvxcrvPlain3andSUSD: {
144
- name: "cvxcrvPlain3andSUSD",
140
+ name: "Convex cvxcrvPlain3andSUSD",
145
141
  decimals: 18,
146
142
 
147
143
  symbol: "cvxcrvPlain3andSUSD",
@@ -165,7 +161,7 @@ export const convexTokens: Record<
165
161
  },
166
162
 
167
163
  cvxgusd3CRV: {
168
- name: "cvxgusd3CRV",
164
+ name: "Convex cvxgusd3CRV",
169
165
  decimals: 18,
170
166
 
171
167
  symbol: "cvxgusd3CRV",
@@ -186,11 +182,15 @@ export const convexTokens: Record<
186
182
  tokenOut: "stkcvxgusd3CRV"
187
183
  }
188
184
  ]
189
- },
185
+ }
186
+ };
190
187
 
191
- // STAKED CONVEX
188
+ const convexStakedPhantomTokens: Record<
189
+ ConvexStakedPhantomToken,
190
+ ConvexPhantomTokenData
191
+ > = {
192
192
  stkcvx3Crv: {
193
- name: "stkcvx3Crv",
193
+ name: "Convex stkcvx3Crv",
194
194
  decimals: 18,
195
195
 
196
196
  symbol: "stkcvx3Crv",
@@ -214,7 +214,7 @@ export const convexTokens: Record<
214
214
  },
215
215
 
216
216
  stkcvxsteCRV: {
217
- name: "stkcvxsteCRV",
217
+ name: "Convex stkcvxsteCRV",
218
218
  decimals: 18,
219
219
 
220
220
  symbol: "stkcvxsteCRV",
@@ -238,7 +238,7 @@ export const convexTokens: Record<
238
238
  },
239
239
 
240
240
  stkcvxFRAX3CRV: {
241
- name: "stkcvxFRAX3CRV-f",
241
+ name: "Convex stkcvxFRAX3CRV-f",
242
242
  decimals: 18,
243
243
 
244
244
  symbol: "stkcvxFRAX3CRV",
@@ -262,13 +262,13 @@ export const convexTokens: Record<
262
262
  },
263
263
 
264
264
  stkcvxLUSD3CRV: {
265
- name: "stkcvxLUSD3CRV-f",
265
+ name: "Convex stkcvxLUSD3CRV-f",
266
266
  decimals: 18,
267
267
 
268
268
  symbol: "stkcvxLUSD3CRV",
269
269
  type: TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
270
270
  pool: "CONVEX_LUSD3CRV_POOL",
271
- pid: 32,
271
+ pid: 33,
272
272
  underlying: "LUSD3CRV",
273
273
  lpToken: "cvxLUSD3CRV",
274
274
  lpActions: [
@@ -286,7 +286,7 @@ export const convexTokens: Record<
286
286
  },
287
287
 
288
288
  stkcvxcrvPlain3andSUSD: {
289
- name: "stkcvxcrvPlain3andSUSD",
289
+ name: "Convex stkcvxcrvPlain3andSUSD",
290
290
  decimals: 18,
291
291
 
292
292
  symbol: "stkcvxcrvPlain3andSUSD",
@@ -310,7 +310,7 @@ export const convexTokens: Record<
310
310
  },
311
311
 
312
312
  stkcvxgusd3CRV: {
313
- name: "stkcvxgusd3CRV",
313
+ name: "Convex stkcvxgusd3CRV",
314
314
  decimals: 18,
315
315
 
316
316
  symbol: "stkcvxgusd3CRV",
@@ -333,3 +333,26 @@ export const convexTokens: Record<
333
333
  ]
334
334
  }
335
335
  };
336
+
337
+ export const convexTokens: Record<
338
+ ConvexLPToken | ConvexStakedPhantomToken,
339
+ ConvexLPTokenData | ConvexPhantomTokenData
340
+ > = {
341
+ ...convexLpTokens,
342
+ ...convexStakedPhantomTokens
343
+ };
344
+
345
+ export const isConvexToken = (
346
+ t: unknown
347
+ ): t is ConvexLPToken | ConvexStakedPhantomToken =>
348
+ typeof t === "string" &&
349
+ !!convexTokens[t as ConvexLPToken | ConvexStakedPhantomToken];
350
+
351
+ export const isConvexLPToken = (t: unknown): t is ConvexLPToken =>
352
+ typeof t === "string" && !!convexLpTokens[t as ConvexLPToken];
353
+
354
+ export const isConvexStakedPhantomToken = (
355
+ t: unknown
356
+ ): t is ConvexStakedPhantomToken =>
357
+ typeof t === "string" &&
358
+ !!convexStakedPhantomTokens[t as ConvexStakedPhantomToken];
@@ -45,7 +45,7 @@ export const curveTokens: Record<
45
45
  > = {
46
46
  // CURVE LP TOKENS
47
47
  "3Crv": {
48
- name: "3Crv",
48
+ name: "Curve 3Crv",
49
49
  decimals: 18,
50
50
  symbol: "3Crv",
51
51
  type: TokenType.CURVE_LP,
@@ -70,7 +70,7 @@ export const curveTokens: Record<
70
70
  },
71
71
 
72
72
  steCRV: {
73
- name: "steCRV",
73
+ name: "Curve steCRV",
74
74
  decimals: 18,
75
75
  symbol: "steCRV",
76
76
  type: TokenType.CURVE_LP,
@@ -95,7 +95,7 @@ export const curveTokens: Record<
95
95
  },
96
96
 
97
97
  crvPlain3andSUSD: {
98
- name: "crvPlain3andSUSD",
98
+ name: "Curve crvPlain3andSUSD",
99
99
  decimals: 18,
100
100
  symbol: "crvPlain3andSUSD",
101
101
  type: TokenType.CURVE_LP,
@@ -122,7 +122,7 @@ export const curveTokens: Record<
122
122
 
123
123
  // META CURVE LP TOKENS
124
124
  FRAX3CRV: {
125
- name: "FRAX3CRV-f",
125
+ name: "Curve FRAX3CRV-f",
126
126
  decimals: 18,
127
127
  symbol: "FRAX3CRV",
128
128
  type: TokenType.META_CURVE_LP,
@@ -147,7 +147,7 @@ export const curveTokens: Record<
147
147
  },
148
148
 
149
149
  LUSD3CRV: {
150
- name: "LUSD3CRV-f",
150
+ name: "Curve LUSD3CRV-f",
151
151
  decimals: 18,
152
152
  symbol: "LUSD3CRV",
153
153
  type: TokenType.META_CURVE_LP,
@@ -162,7 +162,7 @@ export const curveTokens: Record<
162
162
  },
163
163
 
164
164
  gusd3CRV: {
165
- name: "gusd3CRV",
165
+ name: "Curve gusd3CRV",
166
166
  decimals: 18,
167
167
  symbol: "gusd3CRV",
168
168
  type: TokenType.META_CURVE_LP,
@@ -186,3 +186,6 @@ export const curveTokens: Record<
186
186
  ]
187
187
  }
188
188
  };
189
+
190
+ export const isCurveLPToken = (t: unknown): t is CurveLPToken =>
191
+ typeof t === "string" && !!curveTokens[t as CurveLPToken];
@@ -807,3 +807,6 @@ export const normalTokens: Record<NormalToken, NormalTokenData> = {
807
807
  ]
808
808
  }
809
809
  };
810
+
811
+ export const isNormalToken = (t: unknown): t is NormalToken =>
812
+ typeof t === "string" && !!normalTokens[t as NormalToken];
@@ -34,12 +34,15 @@ import {
34
34
  gearTokens
35
35
  } from "./gear";
36
36
 
37
- export type SupportedToken =
38
- | NormalToken
37
+ export type LPTokens =
39
38
  | YearnLPToken
40
39
  | CurveLPToken
41
40
  | ConvexLPToken
42
- | ConvexStakedPhantomToken
41
+ | ConvexStakedPhantomToken;
42
+
43
+ export type SupportedToken =
44
+ | NormalToken
45
+ | LPTokens
43
46
  | DieselTokenTypes
44
47
  | GearboxToken;
45
48
 
@@ -49,18 +52,27 @@ export interface TokenBase {
49
52
  decimals: number;
50
53
  }
51
54
 
52
- export type TokenDataI =
53
- | NormalTokenData
55
+ export type LPTokenDataI =
54
56
  | CurveLPTokenData
55
57
  | MetaCurveLPTokenData
56
58
  | YearnVaultTokenData
57
59
  | YearnVaultOfCurveLPTokenData
58
60
  | YearnVaultOfMetaCurveLPTokenData
59
61
  | ConvexLPTokenData
60
- | ConvexPhantomTokenData
62
+ | ConvexPhantomTokenData;
63
+
64
+ export type TokenDataI =
65
+ | NormalTokenData
66
+ | LPTokenDataI
61
67
  | DieselTokenData
62
68
  | GearboxTokenData;
63
69
 
70
+ export const lpTokens: Record<LPTokens, LPTokenDataI> = {
71
+ ...curveTokens,
72
+ ...convexTokens,
73
+ ...yearnTokens
74
+ };
75
+
64
76
  export const supportedTokens: Record<SupportedToken, TokenDataI> = {
65
77
  ...normalTokens,
66
78
  ...curveTokens,
@@ -236,3 +248,9 @@ export const tokenSymbolByAddress = objectEntries(tokenDataByNetwork).reduce<
236
248
  }),
237
249
  {}
238
250
  );
251
+
252
+ export const isSupportedToken = (t: unknown): t is SupportedToken =>
253
+ typeof t === "string" && !!supportedTokens[t as SupportedToken];
254
+
255
+ export const isLPToken = (t: unknown): t is LPTokens =>
256
+ typeof t === "string" && !!supportedTokens[t as LPTokens];
@@ -13,7 +13,6 @@ const defaultSymbolReplacement: SymbolReplacements = {
13
13
  export class TokenData {
14
14
  public readonly id: string;
15
15
 
16
- // public readonly name: string;
17
16
  public readonly symbol: string;
18
17
 
19
18
  public readonly address: string;
@@ -26,9 +25,8 @@ export class TokenData {
26
25
  payload: TokenDataPayload,
27
26
  symbolReplacements: SymbolReplacements = defaultSymbolReplacement
28
27
  ) {
29
- this.id = payload.addr;
30
- this.address = payload.addr;
31
- // this.name = payload.name;
28
+ this.id = payload.addr.toLowerCase();
29
+ this.address = payload.addr.toLowerCase();
32
30
  this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
33
31
  this.decimals = payload.decimals;
34
32
  this.icon = `${STATIC_TOKEN}${payload.symbol?.toLowerCase()}.svg`;
@@ -45,7 +45,7 @@ export const yearnTokens: Record<
45
45
  > = {
46
46
  // YEARN TOKENS
47
47
  yvDAI: {
48
- name: "yvDAI",
48
+ name: "Yearn yvDAI",
49
49
  decimals: 18,
50
50
  symbol: "yvDAI",
51
51
  type: TokenType.YEARN_VAULT,
@@ -61,7 +61,7 @@ export const yearnTokens: Record<
61
61
  },
62
62
 
63
63
  yvUSDC: {
64
- name: "yvUSDC",
64
+ name: "Yearn yvUSDC",
65
65
  decimals: 6,
66
66
  symbol: "yvUSDC",
67
67
  type: TokenType.YEARN_VAULT,
@@ -77,7 +77,7 @@ export const yearnTokens: Record<
77
77
  },
78
78
 
79
79
  yvWETH: {
80
- name: "yvWETH",
80
+ name: "Yearn yvWETH",
81
81
  decimals: 18,
82
82
  symbol: "yvWETH",
83
83
  type: TokenType.YEARN_VAULT,
@@ -93,7 +93,7 @@ export const yearnTokens: Record<
93
93
  },
94
94
 
95
95
  yvWBTC: {
96
- name: "yvWBTC",
96
+ name: "Yearn yvWBTC",
97
97
  decimals: 8,
98
98
  symbol: "yvWBTC",
99
99
  type: TokenType.YEARN_VAULT,
@@ -110,7 +110,7 @@ export const yearnTokens: Record<
110
110
 
111
111
  // YEARN- CURVE TOKENS
112
112
  yvCurve_stETH: {
113
- name: "yvCurve-stETH",
113
+ name: "Yearn yvCurve-stETH",
114
114
  decimals: 18,
115
115
  symbol: "yvCurve_stETH",
116
116
  type: TokenType.YEARN_VAULT_OF_CURVE_LP,
@@ -126,7 +126,7 @@ export const yearnTokens: Record<
126
126
  },
127
127
 
128
128
  yvCurve_FRAX: {
129
- name: "yvCurve-FRAX",
129
+ name: "Yearn yvCurve-FRAX",
130
130
  decimals: 18,
131
131
  symbol: "yvCurve_FRAX",
132
132
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP,
@@ -141,3 +141,6 @@ export const yearnTokens: Record<
141
141
  ]
142
142
  }
143
143
  };
144
+
145
+ export const isYearnLPToken = (t: unknown): t is YearnLPToken =>
146
+ typeof t === "string" && !!yearnTokens[t as YearnLPToken];
@@ -0,0 +1,30 @@
1
+ import { PoolData } from "../core/pool";
2
+
3
+ export interface PoolTokens {
4
+ dieselToken: string | undefined;
5
+ underlyingToken: string | undefined;
6
+ }
7
+
8
+ export function getPoolTokens(pool: PoolData | undefined | Error): PoolTokens {
9
+ const safePool = pool instanceof Error ? undefined : pool;
10
+ const { dieselToken, underlyingToken } = safePool || {};
11
+
12
+ return {
13
+ dieselToken,
14
+ underlyingToken
15
+ };
16
+ }
17
+
18
+ interface WithUnderlyingToken {
19
+ readonly underlyingToken: string;
20
+ }
21
+
22
+ export function getUnderlyingToken(
23
+ c: WithUnderlyingToken | undefined | Error
24
+ ): string | undefined {
25
+ if (!c || c instanceof Error) {
26
+ return undefined;
27
+ }
28
+
29
+ return c.underlyingToken;
30
+ }
@@ -12,7 +12,7 @@ const swapKeyValue = <K extends SupportedValue, T extends SupportedValue>(
12
12
  {} as Record<T, K>
13
13
  );
14
14
 
15
- const keyToLowercase = <K extends SupportedValue, T extends SupportedValue>(
15
+ const keyToLowercase = <K extends SupportedValue, T>(
16
16
  o: Record<K, T>
17
17
  ): Record<K, T> =>
18
18
  objectEntries(o).reduce((acc, [key, value]) => {
@@ -20,7 +20,7 @@ const keyToLowercase = <K extends SupportedValue, T extends SupportedValue>(
20
20
  return { ...acc, [keyTransformed]: value };
21
21
  }, {} as Record<K, T>);
22
22
 
23
- const filterEmptyKeys = <K extends SupportedValue, T extends SupportedValue>(
23
+ const filterEmptyKeys = <K extends SupportedValue, T>(
24
24
  o: Record<K, T>
25
25
  ): Record<K, T> =>
26
26
  objectEntries(o).reduce(
@@ -0,0 +1,33 @@
1
+ import { BigNumber } from "ethers";
2
+ import { WAD, PRICE_DECIMALS } from "../core/constants";
3
+
4
+ export const calcTotalPrice = (
5
+ price: BigNumber,
6
+ amount: BigNumber,
7
+ decimals: number = 18
8
+ ) =>
9
+ amount
10
+ .mul(WAD)
11
+ .mul(price)
12
+ .div(BigNumber.from(10).pow(decimals))
13
+ .div(PRICE_DECIMALS);
14
+
15
+ interface Target {
16
+ price: BigNumber;
17
+ decimals: number | undefined;
18
+ }
19
+
20
+ export function convertByPrice(
21
+ totalMoney: BigNumber,
22
+ { price: targetPrice, decimals: targetDecimals = 18 }: Target
23
+ ) {
24
+ const isWrongTargetPrice = targetPrice.isZero() || targetPrice.isNegative();
25
+
26
+ return isWrongTargetPrice
27
+ ? BigNumber.from(0)
28
+ : totalMoney
29
+ .mul(BigNumber.from(10).pow(targetDecimals))
30
+ .mul(PRICE_DECIMALS)
31
+ .div(targetPrice)
32
+ .div(WAD);
33
+ }
@@ -1,2 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- export declare const calcTotalPrice: (price: BigNumber, amount: BigNumber, decimals?: number) => BigNumber;
package/lib/core/price.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calcTotalPrice = void 0;
4
- var ethers_1 = require("ethers");
5
- var constants_1 = require("./constants");
6
- var calcTotalPrice = function (price, amount, decimals) {
7
- if (decimals === void 0) { decimals = 18; }
8
- return amount
9
- .mul(constants_1.WAD)
10
- .mul(price)
11
- .div(ethers_1.BigNumber.from(10).pow(decimals))
12
- .div(constants_1.PRICE_DECIMALS);
13
- };
14
- exports.calcTotalPrice = calcTotalPrice;
@@ -1,2 +0,0 @@
1
- import type * as interfaces from "./interfaces";
2
- export type { interfaces };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });