@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
@@ -13,6 +13,7 @@ var __assign = (this && this.__assign) || function () {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.getContractName = exports.deployedContracts = void 0;
15
15
  var mappers_1 = require("../utils/mappers");
16
+ var formatter_1 = require("../utils/formatter");
16
17
  var contracts_1 = require("./contracts");
17
18
  exports.deployedContracts = {
18
19
  // MAINNET
@@ -65,6 +66,6 @@ var contractNames = Object.entries(contracts_1.contractsByAddress).reduce(functi
65
66
  }, {});
66
67
  var contractsFullList = __assign(__assign({}, (0, mappers_1.keyToLowercase)(exports.deployedContracts)), contractNames);
67
68
  function getContractName(address) {
68
- return contractsFullList[address.toLowerCase()] || address;
69
+ return contractsFullList[address.toLowerCase()] || (0, formatter_1.shortAddress)(address);
69
70
  }
70
71
  exports.getContractName = getContractName;
@@ -25,8 +25,9 @@ export declare class CreditAccountData {
25
25
  constructor(payload: CreditAccountDataPayload);
26
26
  balancesSorted(prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<Balance>;
27
27
  }
28
- export declare function sortBalances(balances: Record<string, BigNumber>, prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): [string, BigNumber][];
28
+ export declare function sortBalances(balances: Record<string, BigNumber>, prices: Record<string, BigNumber>, tokens: Record<string, TokenData>): Array<[string, BigNumber]>;
29
29
  export declare function tokensAbcComparator(t1?: TokenData, t2?: TokenData): 1 | -1;
30
+ export declare function amountAbcComparator(t1: BigNumber, t2: BigNumber): 1 | -1;
30
31
  export declare class CreditAccountDataExtended extends CreditAccountData {
31
32
  readonly repayAmount: BigNumber;
32
33
  readonly liquidationAmount: BigNumber;
@@ -15,10 +15,10 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.CreditAccountDataExtended = exports.tokensAbcComparator = exports.sortBalances = exports.CreditAccountData = void 0;
18
+ exports.CreditAccountDataExtended = exports.amountAbcComparator = exports.tokensAbcComparator = exports.sortBalances = exports.CreditAccountData = void 0;
19
19
  var ethers_1 = require("ethers");
20
+ var price_1 = require("../utils/price");
20
21
  var constants_1 = require("./constants");
21
- var price_1 = require("./price");
22
22
  var CreditAccountData = /** @class */ (function () {
23
23
  function CreditAccountData(payload) {
24
24
  var _this = this;
@@ -27,12 +27,12 @@ var CreditAccountData = /** @class */ (function () {
27
27
  this.balances = {};
28
28
  this.allBalances = {};
29
29
  this.version = 1;
30
- this.id = payload.creditManager;
31
- this.addr = payload.addr;
32
- this.borrower = payload.borrower;
30
+ this.id = payload.creditManager.toLowerCase();
31
+ this.addr = payload.addr.toLowerCase();
32
+ this.borrower = payload.borrower.toLowerCase();
33
33
  this.inUse = payload.inUse;
34
- this.creditManager = payload.creditManager;
35
- this.underlyingToken = payload.underlying;
34
+ this.creditManager = payload.creditManager.toLowerCase();
35
+ this.underlyingToken = payload.underlying.toLowerCase();
36
36
  this.borrowedAmountPlusInterest = ethers_1.BigNumber.from(payload.borrowedAmountPlusInterest);
37
37
  this.totalValue = ethers_1.BigNumber.from(payload.totalValue);
38
38
  this.healthFactor =
@@ -44,12 +44,13 @@ var CreditAccountData = /** @class */ (function () {
44
44
  .div(constants_1.RAY)
45
45
  .toNumber() / constants_1.PERCENTAGE_FACTOR;
46
46
  (payload.balances || []).forEach(function (b) {
47
+ var tokenLC = b.token.toLowerCase();
47
48
  if (b.isAllowed) {
48
- _this.balances[b.token] = ethers_1.BigNumber.from(b.balance);
49
- _this.allowedTokens.push(b.token);
49
+ _this.balances[tokenLC] = ethers_1.BigNumber.from(b.balance);
50
+ _this.allowedTokens.push(tokenLC);
50
51
  }
51
- _this.allBalances[b.token] = ethers_1.BigNumber.from(b.balance);
52
- _this.allTokens.push(b.token);
52
+ _this.allBalances[tokenLC] = ethers_1.BigNumber.from(b.balance);
53
+ _this.allTokens.push(tokenLC);
53
54
  });
54
55
  this.isDeleting = false;
55
56
  }
@@ -75,7 +76,9 @@ function sortBalances(balances, prices, tokens) {
75
76
  var totalPrice1 = (0, price_1.calcTotalPrice)(price1, amount1, token1 === null || token1 === void 0 ? void 0 : token1.decimals);
76
77
  var totalPrice2 = (0, price_1.calcTotalPrice)(price2, amount2, token2 === null || token2 === void 0 ? void 0 : token2.decimals);
77
78
  if (totalPrice1.eq(totalPrice2)) {
78
- return tokensAbcComparator(token1, token2);
79
+ return amount1.eq(amount2)
80
+ ? tokensAbcComparator(token1, token2)
81
+ : amountAbcComparator(amount1, amount2);
79
82
  }
80
83
  if (totalPrice1.gt(totalPrice2)) {
81
84
  return -1;
@@ -90,6 +93,10 @@ function tokensAbcComparator(t1, t2) {
90
93
  return symbol1 > symbol2 ? 1 : -1;
91
94
  }
92
95
  exports.tokensAbcComparator = tokensAbcComparator;
96
+ function amountAbcComparator(t1, t2) {
97
+ return (t1 === null || t1 === void 0 ? void 0 : t1.gt(t2)) ? -1 : 1;
98
+ }
99
+ exports.amountAbcComparator = amountAbcComparator;
93
100
  var CreditAccountDataExtended = /** @class */ (function (_super) {
94
101
  __extends(CreditAccountDataExtended, _super);
95
102
  function CreditAccountDataExtended(payload) {
@@ -29,7 +29,9 @@ export declare class CreditManagerData {
29
29
  encodeAddCollateral(accountAddress: string, tokenAddress: string, amount: BigNumber): MultiCall;
30
30
  encodeIncreaseDebt(amount: BigNumber): MultiCall;
31
31
  encodeDecreaseDebt(amount: BigNumber): MultiCall;
32
- validateOpenAccount(totalAmount: BigNumber, leverage: number): true;
32
+ validateOpenAccount(collateral: BigNumber, debt: BigNumber): true;
33
+ protected validateOpenAccountV1(collateral: BigNumber, debt: BigNumber): true;
34
+ protected validateOpenAccountV2(debt: BigNumber): true;
33
35
  }
34
36
  export declare function calcMaxIncreaseBorrow(healthFactor: number, borrowAmountPlusInterest: BigNumber, maxLeverageFactor: number): BigNumber;
35
37
  export declare function calcHealthFactorAfterIncreasingBorrow(healthFactor: number | undefined, borrowAmountPlusInterest: BigNumber | undefined, additional: BigNumber): number;
@@ -60,7 +60,7 @@ var CreditManagerData = /** @class */ (function () {
60
60
  this.liquidationThresholds = (payload.liquidationThresholds || []).reduce(function (acc, threshold, index) {
61
61
  var address = payload.collateralTokens[index];
62
62
  if (address)
63
- acc[address] = ethers_1.BigNumber.from(threshold);
63
+ acc[address.toLowerCase()] = ethers_1.BigNumber.from(threshold);
64
64
  return acc;
65
65
  }, {});
66
66
  this.version = ethers_1.BigNumber.from(payload.version || 1).toNumber();
@@ -100,17 +100,31 @@ var CreditManagerData = /** @class */ (function () {
100
100
  callData: types_1.ICreditFacade__factory.createInterface().encodeFunctionData("decreaseDebt", [amount])
101
101
  };
102
102
  };
103
- CreditManagerData.prototype.validateOpenAccount = function (totalAmount, leverage) {
104
- if (totalAmount.lt(this.minAmount))
103
+ CreditManagerData.prototype.validateOpenAccount = function (collateral, debt) {
104
+ return this.version === 2
105
+ ? this.validateOpenAccountV2(debt)
106
+ : this.validateOpenAccountV1(collateral, debt);
107
+ };
108
+ CreditManagerData.prototype.validateOpenAccountV1 = function (collateral, debt) {
109
+ if (collateral.lt(this.minAmount))
105
110
  throw new errors_1.OpenAccountError("amountLessMin", this.minAmount);
106
- if (totalAmount.gt(this.maxAmount))
111
+ if (collateral.gt(this.maxAmount))
107
112
  throw new errors_1.OpenAccountError("amountGreaterMax", this.maxAmount);
113
+ var leverage = debt.mul(constants_1.LEVERAGE_DECIMALS).div(collateral).toNumber();
114
+ if (!leverage || leverage < 0)
115
+ throw new errors_1.OpenAccountError("wrongLeverage", ethers_1.BigNumber.from(0));
108
116
  if (leverage > this.maxLeverageFactor)
109
117
  throw new errors_1.OpenAccountError("leverageGreaterMax", ethers_1.BigNumber.from(this.maxLeverageFactor));
110
- if (totalAmount
111
- .mul(leverage)
112
- .div(constants_1.LEVERAGE_DECIMALS)
113
- .gt(this.availableLiquidity))
118
+ if (debt.gt(this.availableLiquidity))
119
+ throw new errors_1.OpenAccountError("insufficientPoolLiquidity", ethers_1.BigNumber.from(this.availableLiquidity));
120
+ return true;
121
+ };
122
+ CreditManagerData.prototype.validateOpenAccountV2 = function (debt) {
123
+ if (debt.lt(this.minAmount))
124
+ throw new errors_1.OpenAccountError("amountLessMin", this.minAmount);
125
+ if (debt.gt(this.maxAmount))
126
+ throw new errors_1.OpenAccountError("amountGreaterMax", this.maxAmount);
127
+ if (debt.gt(this.availableLiquidity))
114
128
  throw new errors_1.OpenAccountError("insufficientPoolLiquidity", ethers_1.BigNumber.from(this.availableLiquidity));
115
129
  return true;
116
130
  };
@@ -25,7 +25,7 @@ export declare class PathNotFoundError extends Error {
25
25
  export declare class AccountsInAlllCreditManagersError extends Error {
26
26
  constructor();
27
27
  }
28
- export declare type OpenAccountErrorTypes = "insufficientPoolLiquidity" | "leverageGreaterMax" | "amountGreaterMax" | "amountLessMin";
28
+ export declare type OpenAccountErrorTypes = "insufficientPoolLiquidity" | "leverageGreaterMax" | "wrongLeverage" | "amountGreaterMax" | "amountLessMin";
29
29
  export declare class OpenAccountError extends Error {
30
30
  message: OpenAccountErrorTypes;
31
31
  payload: {
package/lib/core/pool.js CHANGED
@@ -8,10 +8,10 @@ var constants_1 = require("./constants");
8
8
  var PoolData = /** @class */ (function () {
9
9
  function PoolData(payload) {
10
10
  this.isPaused = false;
11
- this.id = payload.addr;
12
- this.address = payload.addr;
13
- this.underlyingToken = payload.underlying || "";
14
- this.dieselToken = payload.dieselToken || "";
11
+ this.id = payload.addr.toLowerCase();
12
+ this.address = payload.addr.toLowerCase();
13
+ this.underlyingToken = payload.underlying.toLowerCase();
14
+ this.dieselToken = payload.dieselToken.toLowerCase();
15
15
  this.isWETH = payload.isWETH || false;
16
16
  this.expectedLiquidity = ethers_1.BigNumber.from(payload.expectedLiquidity);
17
17
  this.expectedLiquidityLimit = ethers_1.BigNumber.from(payload.expectedLiquidityLimit || 0);
@@ -1,6 +1,8 @@
1
1
  import { BigNumber } from "ethers";
2
+ import { TokensWithAPY } from "../apy";
2
3
  export interface StrategyPayload {
3
4
  apy?: number;
5
+ apyTokenSymbol: TokensWithAPY;
4
6
  name: string;
5
7
  lpToken: string;
6
8
  pools: Array<string>;
@@ -29,8 +31,8 @@ export declare class Strategy {
29
31
  maxAPY(maxLeverage: number, poolApy: PoolList): number;
30
32
  overallAPY(apy: number, leverage: number, depositCollateral: string, borrowAPY: number): number;
31
33
  liquidationPrice(borrowed: TokenDescription, collateral: TokenDescription, lp: TokenDescription, ltCollateral: BigNumber): BigNumber;
32
- private farmLev;
33
- private inBaseAssets;
34
- private inLeveragableAssets;
34
+ protected farmLev(leverage: number, depositCollateral: string): number;
35
+ protected inBaseAssets(depositCollateral: string): boolean;
36
+ protected inLeveragableAssets(depositCollateral: string): boolean;
35
37
  }
36
38
  export {};
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Strategy = void 0;
4
4
  var ethers_1 = require("ethers");
5
+ var price_1 = require("../utils/price");
5
6
  var constants_1 = require("./constants");
6
- var price_1 = require("./price");
7
7
  var Strategy = /** @class */ (function () {
8
8
  function Strategy(payload) {
9
9
  this.apy = payload.apy;
@@ -29,9 +29,11 @@ var Strategy = /** @class */ (function () {
29
29
  .mul(ltCollateral)
30
30
  .div(constants_1.PERCENTAGE_FACTOR);
31
31
  var lpMoney = (0, price_1.calcTotalPrice)(lp.price, lp.amount, lp.decimals);
32
- return lpMoney.gt(0)
33
- ? borrowedMoney.sub(collateralMoney).mul(constants_1.WAD).div(lpMoney)
34
- : ethers_1.BigNumber.from(0);
32
+ if (lpMoney.gt(0)) {
33
+ var lqPrice = borrowedMoney.sub(collateralMoney).mul(constants_1.WAD).div(lpMoney);
34
+ return lqPrice.gte(0) ? lqPrice : ethers_1.BigNumber.from(0);
35
+ }
36
+ return ethers_1.BigNumber.from(0);
35
37
  };
36
38
  Strategy.prototype.farmLev = function (leverage, depositCollateral) {
37
39
  return this.inBaseAssets(depositCollateral) ||
package/lib/index.d.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";
@@ -36,12 +35,12 @@ export * from "./tokens/curveLP";
36
35
  export * from "./tokens/gear";
37
36
  export * from "./tokens/normal";
38
37
  export * from "./tokens/yearn";
39
- export * from "./apy/lidoAPY";
40
- export * from "./apy/convexAPY";
38
+ export * from "./apy";
41
39
  export * from "./core/history";
42
40
  export * from "./utils/multicall";
43
41
  export * from "./utils/types";
44
42
  export * from "./utils/errors";
43
+ export * from "./utils/price";
45
44
  export * from "./strategies/convex";
46
45
  export * from "./strategies/creditFacade";
47
46
  export * from "./strategies/curve";
@@ -53,4 +52,5 @@ export { callRepeater } from "./utils/repeater";
53
52
  export { getContractName } from "./contracts/contractsRegister";
54
53
  export { AdapterInterface } from "./contracts/adapters";
55
54
  export { objectEntries, swapKeyValue, keyToLowercase } from "./utils/mappers";
56
- export { SwapType } from "./pathfinder/tradeTypes";
55
+ export { getPoolTokens, getUnderlyingToken } from "./utils/extracter";
56
+ export * from "./pathfinder/tradeTypes";
package/lib/index.js CHANGED
@@ -14,9 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.SwapType = exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.TokenType = void 0;
17
+ exports.getUnderlyingToken = exports.getPoolTokens = exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.TokenType = void 0;
18
18
  __exportStar(require("./core/constants"), exports);
19
- __exportStar(require("./core/price"), exports);
20
19
  __exportStar(require("./core/creditAccount"), exports);
21
20
  __exportStar(require("./core/creditManager"), exports);
22
21
  __exportStar(require("./core/creditSession"), exports);
@@ -55,12 +54,12 @@ __exportStar(require("./tokens/curveLP"), exports);
55
54
  __exportStar(require("./tokens/gear"), exports);
56
55
  __exportStar(require("./tokens/normal"), exports);
57
56
  __exportStar(require("./tokens/yearn"), exports);
58
- __exportStar(require("./apy/lidoAPY"), exports);
59
- __exportStar(require("./apy/convexAPY"), exports);
57
+ __exportStar(require("./apy"), exports);
60
58
  __exportStar(require("./core/history"), exports);
61
59
  __exportStar(require("./utils/multicall"), exports);
62
60
  __exportStar(require("./utils/types"), exports);
63
61
  __exportStar(require("./utils/errors"), exports);
62
+ __exportStar(require("./utils/price"), exports);
64
63
  __exportStar(require("./strategies/convex"), exports);
65
64
  __exportStar(require("./strategies/creditFacade"), exports);
66
65
  __exportStar(require("./strategies/curve"), exports);
@@ -78,5 +77,7 @@ var mappers_1 = require("./utils/mappers");
78
77
  Object.defineProperty(exports, "objectEntries", { enumerable: true, get: function () { return mappers_1.objectEntries; } });
79
78
  Object.defineProperty(exports, "swapKeyValue", { enumerable: true, get: function () { return mappers_1.swapKeyValue; } });
80
79
  Object.defineProperty(exports, "keyToLowercase", { enumerable: true, get: function () { return mappers_1.keyToLowercase; } });
81
- var tradeTypes_1 = require("./pathfinder/tradeTypes");
82
- Object.defineProperty(exports, "SwapType", { enumerable: true, get: function () { return tradeTypes_1.SwapType; } });
80
+ var extracter_1 = require("./utils/extracter");
81
+ Object.defineProperty(exports, "getPoolTokens", { enumerable: true, get: function () { return extracter_1.getPoolTokens; } });
82
+ Object.defineProperty(exports, "getUnderlyingToken", { enumerable: true, get: function () { return extracter_1.getUnderlyingToken; } });
83
+ __exportStar(require("./pathfinder/tradeTypes"), exports);
@@ -22,4 +22,7 @@ export declare type ConvexPhantomTokenData = {
22
22
  lpToken: ConvexLPToken;
23
23
  } & BaseConvexToken;
24
24
  export declare const convexTokens: Record<ConvexLPToken | ConvexStakedPhantomToken, ConvexLPTokenData | ConvexPhantomTokenData>;
25
+ export declare const isConvexToken: (t: unknown) => t is ConvexLPToken | ConvexStakedPhantomToken;
26
+ export declare const isConvexLPToken: (t: unknown) => t is ConvexLPToken;
27
+ export declare const isConvexStakedPhantomToken: (t: unknown) => t is ConvexStakedPhantomToken;
25
28
  export {};
@@ -1,12 +1,22 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convexTokens = void 0;
14
+ exports.isConvexStakedPhantomToken = exports.isConvexLPToken = exports.isConvexToken = exports.convexTokens = void 0;
4
15
  var tradeTypes_1 = require("../pathfinder/tradeTypes");
5
16
  var tokenType_1 = require("./tokenType");
6
- exports.convexTokens = {
7
- // CONVEX LP TOKENS
17
+ var convexLpTokens = {
8
18
  cvx3Crv: {
9
- name: "cvx3Crv",
19
+ name: "Convex cvx3Crv",
10
20
  decimals: 18,
11
21
  symbol: "cvx3Crv",
12
22
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -28,7 +38,7 @@ exports.convexTokens = {
28
38
  ]
29
39
  },
30
40
  cvxsteCRV: {
31
- name: "cvxsteCRV",
41
+ name: "Convex cvxsteCRV",
32
42
  decimals: 18,
33
43
  symbol: "cvxsteCRV",
34
44
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -50,7 +60,7 @@ exports.convexTokens = {
50
60
  ]
51
61
  },
52
62
  cvxFRAX3CRV: {
53
- name: "cvxFRAX3CRV-f",
63
+ name: "Convex cvxFRAX3CRV-f",
54
64
  decimals: 18,
55
65
  symbol: "cvxFRAX3CRV",
56
66
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -72,7 +82,7 @@ exports.convexTokens = {
72
82
  ]
73
83
  },
74
84
  cvxLUSD3CRV: {
75
- name: "cvxLUSD3CRV-f",
85
+ name: "Convex cvxLUSD3CRV-f",
76
86
  decimals: 18,
77
87
  symbol: "cvxLUSD3CRV",
78
88
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -94,7 +104,7 @@ exports.convexTokens = {
94
104
  ]
95
105
  },
96
106
  cvxcrvPlain3andSUSD: {
97
- name: "cvxcrvPlain3andSUSD",
107
+ name: "Convex cvxcrvPlain3andSUSD",
98
108
  decimals: 18,
99
109
  symbol: "cvxcrvPlain3andSUSD",
100
110
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -116,7 +126,7 @@ exports.convexTokens = {
116
126
  ]
117
127
  },
118
128
  cvxgusd3CRV: {
119
- name: "cvxgusd3CRV",
129
+ name: "Convex cvxgusd3CRV",
120
130
  decimals: 18,
121
131
  symbol: "cvxgusd3CRV",
122
132
  type: tokenType_1.TokenType.CONVEX_LP_TOKEN,
@@ -136,10 +146,11 @@ exports.convexTokens = {
136
146
  tokenOut: "stkcvxgusd3CRV"
137
147
  }
138
148
  ]
139
- },
140
- // STAKED CONVEX
149
+ }
150
+ };
151
+ var convexStakedPhantomTokens = {
141
152
  stkcvx3Crv: {
142
- name: "stkcvx3Crv",
153
+ name: "Convex stkcvx3Crv",
143
154
  decimals: 18,
144
155
  symbol: "stkcvx3Crv",
145
156
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
@@ -161,7 +172,7 @@ exports.convexTokens = {
161
172
  ]
162
173
  },
163
174
  stkcvxsteCRV: {
164
- name: "stkcvxsteCRV",
175
+ name: "Convex stkcvxsteCRV",
165
176
  decimals: 18,
166
177
  symbol: "stkcvxsteCRV",
167
178
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
@@ -183,7 +194,7 @@ exports.convexTokens = {
183
194
  ]
184
195
  },
185
196
  stkcvxFRAX3CRV: {
186
- name: "stkcvxFRAX3CRV-f",
197
+ name: "Convex stkcvxFRAX3CRV-f",
187
198
  decimals: 18,
188
199
  symbol: "stkcvxFRAX3CRV",
189
200
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
@@ -205,12 +216,12 @@ exports.convexTokens = {
205
216
  ]
206
217
  },
207
218
  stkcvxLUSD3CRV: {
208
- name: "stkcvxLUSD3CRV-f",
219
+ name: "Convex stkcvxLUSD3CRV-f",
209
220
  decimals: 18,
210
221
  symbol: "stkcvxLUSD3CRV",
211
222
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
212
223
  pool: "CONVEX_LUSD3CRV_POOL",
213
- pid: 32,
224
+ pid: 33,
214
225
  underlying: "LUSD3CRV",
215
226
  lpToken: "cvxLUSD3CRV",
216
227
  lpActions: [
@@ -227,7 +238,7 @@ exports.convexTokens = {
227
238
  ]
228
239
  },
229
240
  stkcvxcrvPlain3andSUSD: {
230
- name: "stkcvxcrvPlain3andSUSD",
241
+ name: "Convex stkcvxcrvPlain3andSUSD",
231
242
  decimals: 18,
232
243
  symbol: "stkcvxcrvPlain3andSUSD",
233
244
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
@@ -249,7 +260,7 @@ exports.convexTokens = {
249
260
  ]
250
261
  },
251
262
  stkcvxgusd3CRV: {
252
- name: "stkcvxgusd3CRV",
263
+ name: "Convex stkcvxgusd3CRV",
253
264
  decimals: 18,
254
265
  symbol: "stkcvxgusd3CRV",
255
266
  type: tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN,
@@ -271,3 +282,18 @@ exports.convexTokens = {
271
282
  ]
272
283
  }
273
284
  };
285
+ exports.convexTokens = __assign(__assign({}, convexLpTokens), convexStakedPhantomTokens);
286
+ var isConvexToken = function (t) {
287
+ return typeof t === "string" &&
288
+ !!exports.convexTokens[t];
289
+ };
290
+ exports.isConvexToken = isConvexToken;
291
+ var isConvexLPToken = function (t) {
292
+ return typeof t === "string" && !!convexLpTokens[t];
293
+ };
294
+ exports.isConvexLPToken = isConvexLPToken;
295
+ var isConvexStakedPhantomToken = function (t) {
296
+ return typeof t === "string" &&
297
+ !!convexStakedPhantomTokens[t];
298
+ };
299
+ exports.isConvexStakedPhantomToken = isConvexStakedPhantomToken;
@@ -22,3 +22,4 @@ export declare type MetaCurveLPTokenData = {
22
22
  } & TokenBase;
23
23
  export declare const Curve3CrvUnderlyingTokenIndex: PartialRecord<SupportedToken, BigNumber>;
24
24
  export declare const curveTokens: Record<CurveLPToken, CurveLPTokenData | MetaCurveLPTokenData>;
25
+ export declare const isCurveLPToken: (t: unknown) => t is CurveLPToken;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.curveTokens = exports.Curve3CrvUnderlyingTokenIndex = void 0;
3
+ exports.isCurveLPToken = exports.curveTokens = exports.Curve3CrvUnderlyingTokenIndex = void 0;
4
4
  var ethers_1 = require("ethers");
5
5
  var tradeTypes_1 = require("../pathfinder/tradeTypes");
6
6
  var tokenType_1 = require("./tokenType");
@@ -12,7 +12,7 @@ exports.Curve3CrvUnderlyingTokenIndex = {
12
12
  exports.curveTokens = {
13
13
  // CURVE LP TOKENS
14
14
  "3Crv": {
15
- name: "3Crv",
15
+ name: "Curve 3Crv",
16
16
  decimals: 18,
17
17
  symbol: "3Crv",
18
18
  type: tokenType_1.TokenType.CURVE_LP,
@@ -36,7 +36,7 @@ exports.curveTokens = {
36
36
  ]
37
37
  },
38
38
  steCRV: {
39
- name: "steCRV",
39
+ name: "Curve steCRV",
40
40
  decimals: 18,
41
41
  symbol: "steCRV",
42
42
  type: tokenType_1.TokenType.CURVE_LP,
@@ -60,7 +60,7 @@ exports.curveTokens = {
60
60
  ]
61
61
  },
62
62
  crvPlain3andSUSD: {
63
- name: "crvPlain3andSUSD",
63
+ name: "Curve crvPlain3andSUSD",
64
64
  decimals: 18,
65
65
  symbol: "crvPlain3andSUSD",
66
66
  type: tokenType_1.TokenType.CURVE_LP,
@@ -86,7 +86,7 @@ exports.curveTokens = {
86
86
  },
87
87
  // META CURVE LP TOKENS
88
88
  FRAX3CRV: {
89
- name: "FRAX3CRV-f",
89
+ name: "Curve FRAX3CRV-f",
90
90
  decimals: 18,
91
91
  symbol: "FRAX3CRV",
92
92
  type: tokenType_1.TokenType.META_CURVE_LP,
@@ -110,7 +110,7 @@ exports.curveTokens = {
110
110
  ]
111
111
  },
112
112
  LUSD3CRV: {
113
- name: "LUSD3CRV-f",
113
+ name: "Curve LUSD3CRV-f",
114
114
  decimals: 18,
115
115
  symbol: "LUSD3CRV",
116
116
  type: tokenType_1.TokenType.META_CURVE_LP,
@@ -124,7 +124,7 @@ exports.curveTokens = {
124
124
  ]
125
125
  },
126
126
  gusd3CRV: {
127
- name: "gusd3CRV",
127
+ name: "Curve gusd3CRV",
128
128
  decimals: 18,
129
129
  symbol: "gusd3CRV",
130
130
  type: tokenType_1.TokenType.META_CURVE_LP,
@@ -148,3 +148,7 @@ exports.curveTokens = {
148
148
  ]
149
149
  }
150
150
  };
151
+ var isCurveLPToken = function (t) {
152
+ return typeof t === "string" && !!exports.curveTokens[t];
153
+ };
154
+ exports.isCurveLPToken = isCurveLPToken;
@@ -9,3 +9,4 @@ export declare type NormalTokenData = {
9
9
  lpActions?: Array<TradeAction>;
10
10
  } & TokenBase;
11
11
  export declare const normalTokens: Record<NormalToken, NormalTokenData>;
12
+ export declare const isNormalToken: (t: unknown) => t is NormalToken;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalTokens = void 0;
3
+ exports.isNormalToken = exports.normalTokens = void 0;
4
4
  var tradeTypes_1 = require("../pathfinder/tradeTypes");
5
5
  var tokenType_1 = require("./tokenType");
6
6
  exports.normalTokens = {
@@ -714,3 +714,7 @@ exports.normalTokens = {
714
714
  ]
715
715
  }
716
716
  };
717
+ var isNormalToken = function (t) {
718
+ return typeof t === "string" && !!exports.normalTokens[t];
719
+ };
720
+ exports.isNormalToken = isNormalToken;
@@ -4,13 +4,18 @@ import { CurveLPToken, CurveLPTokenData, MetaCurveLPTokenData } from "./curveLP"
4
4
  import { YearnLPToken, YearnVaultOfCurveLPTokenData, YearnVaultOfMetaCurveLPTokenData, YearnVaultTokenData } from "./yearn";
5
5
  import { ConvexLPToken, ConvexLPTokenData, ConvexPhantomTokenData, ConvexStakedPhantomToken } from "./convex";
6
6
  import { DieselTokenData, DieselTokenTypes, GearboxToken, GearboxTokenData } from "./gear";
7
- export declare type SupportedToken = NormalToken | YearnLPToken | CurveLPToken | ConvexLPToken | ConvexStakedPhantomToken | DieselTokenTypes | GearboxToken;
7
+ export declare type LPTokens = YearnLPToken | CurveLPToken | ConvexLPToken | ConvexStakedPhantomToken;
8
+ export declare type SupportedToken = NormalToken | LPTokens | DieselTokenTypes | GearboxToken;
8
9
  export interface TokenBase {
9
10
  name: string;
10
11
  symbol: string;
11
12
  decimals: number;
12
13
  }
13
- export declare type TokenDataI = NormalTokenData | CurveLPTokenData | MetaCurveLPTokenData | YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData | ConvexLPTokenData | ConvexPhantomTokenData | DieselTokenData | GearboxTokenData;
14
+ export declare type LPTokenDataI = CurveLPTokenData | MetaCurveLPTokenData | YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData | ConvexLPTokenData | ConvexPhantomTokenData;
15
+ export declare type TokenDataI = NormalTokenData | LPTokenDataI | DieselTokenData | GearboxTokenData;
16
+ export declare const lpTokens: Record<LPTokens, LPTokenDataI>;
14
17
  export declare const supportedTokens: Record<SupportedToken, TokenDataI>;
15
18
  export declare const tokenDataByNetwork: Record<NetworkType, Record<SupportedToken, string>>;
16
19
  export declare const tokenSymbolByAddress: Record<string, SupportedToken>;
20
+ export declare const isSupportedToken: (t: unknown) => t is SupportedToken;
21
+ export declare const isLPToken: (t: unknown) => t is LPTokens;
@@ -11,13 +11,14 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.tokenSymbolByAddress = exports.tokenDataByNetwork = exports.supportedTokens = void 0;
14
+ exports.isLPToken = exports.isSupportedToken = exports.tokenSymbolByAddress = exports.tokenDataByNetwork = exports.supportedTokens = exports.lpTokens = void 0;
15
15
  var mappers_1 = require("../utils/mappers");
16
16
  var normal_1 = require("./normal");
17
17
  var curveLP_1 = require("./curveLP");
18
18
  var yearn_1 = require("./yearn");
19
19
  var convex_1 = require("./convex");
20
20
  var gear_1 = require("./gear");
21
+ exports.lpTokens = __assign(__assign(__assign({}, curveLP_1.curveTokens), convex_1.convexTokens), yearn_1.yearnTokens);
21
22
  exports.supportedTokens = __assign(__assign(__assign(__assign(__assign({}, normal_1.normalTokens), curveLP_1.curveTokens), convex_1.convexTokens), yearn_1.yearnTokens), gear_1.gearTokens);
22
23
  exports.tokenDataByNetwork = {
23
24
  //
@@ -162,3 +163,11 @@ exports.tokenSymbolByAddress = (0, mappers_1.objectEntries)(exports.tokenDataByN
162
163
  var tokens = _a[1];
163
164
  return (__assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(tokens)))));
164
165
  }, {});
166
+ var isSupportedToken = function (t) {
167
+ return typeof t === "string" && !!exports.supportedTokens[t];
168
+ };
169
+ exports.isSupportedToken = isSupportedToken;
170
+ var isLPToken = function (t) {
171
+ return typeof t === "string" && !!exports.supportedTokens[t];
172
+ };
173
+ exports.isLPToken = isLPToken;
@@ -11,9 +11,8 @@ var TokenData = /** @class */ (function () {
11
11
  function TokenData(payload, symbolReplacements) {
12
12
  if (symbolReplacements === void 0) { symbolReplacements = defaultSymbolReplacement; }
13
13
  var _a;
14
- this.id = payload.addr;
15
- this.address = payload.addr;
16
- // this.name = payload.name;
14
+ this.id = payload.addr.toLowerCase();
15
+ this.address = payload.addr.toLowerCase();
17
16
  this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
18
17
  this.decimals = payload.decimals;
19
18
  this.icon = "".concat(config_1.STATIC_TOKEN).concat((_a = payload.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase(), ".svg");
@@ -27,3 +27,4 @@ export declare type YearnVaultOfMetaCurveLPTokenData = {
27
27
  vault: YearnVaultContract;
28
28
  } & TokenBase;
29
29
  export declare const yearnTokens: Record<YearnLPToken, YearnVaultTokenData | YearnVaultOfCurveLPTokenData | YearnVaultOfMetaCurveLPTokenData>;
30
+ export declare const isYearnLPToken: (t: unknown) => t is YearnLPToken;