@gearbox-protocol/sdk 0.0.100 → 0.0.103

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.d.ts +8 -0
  5. package/lib/apy/convexAPY.js +200 -0
  6. package/lib/apy/lidoAPY.d.ts +4 -0
  7. package/lib/apy/lidoAPY.js +103 -0
  8. package/lib/config.d.ts +1 -0
  9. package/lib/config.js +2 -1
  10. package/lib/contracts/contracts.d.ts +9 -4
  11. package/lib/contracts/contracts.js +52 -14
  12. package/lib/contracts/contractsRegister.js +16 -4
  13. package/lib/core/constants.d.ts +7 -1
  14. package/lib/core/constants.js +11 -5
  15. package/lib/core/creditAccount.d.ts +3 -1
  16. package/lib/core/creditAccount.js +33 -31
  17. package/lib/core/creditManager.d.ts +13 -2
  18. package/lib/core/creditManager.js +77 -33
  19. package/lib/core/creditSession.js +14 -3
  20. package/lib/core/errors.d.ts +10 -0
  21. package/lib/core/errors.js +16 -1
  22. package/lib/core/eventOrTx.d.ts +1 -1
  23. package/lib/core/events.d.ts +19 -19
  24. package/lib/core/events.js +32 -30
  25. package/lib/core/multicall.d.ts +1 -1
  26. package/lib/core/pool.d.ts +2 -2
  27. package/lib/core/pool.js +8 -12
  28. package/lib/core/price.d.ts +2 -0
  29. package/lib/core/price.js +14 -0
  30. package/lib/core/strategy.d.ts +36 -0
  31. package/lib/core/strategy.js +57 -0
  32. package/lib/core/tokenDistributor.js +1 -1
  33. package/lib/core/transactions.d.ts +18 -3
  34. package/lib/core/transactions.js +39 -3
  35. package/lib/index.d.ts +8 -3
  36. package/lib/index.js +9 -4
  37. package/lib/oracles/priceFeeds.js +1 -1
  38. package/lib/pathfinder/convexLP.d.ts +1 -1
  39. package/lib/pathfinder/convexLP.js +26 -29
  40. package/lib/pathfinder/curveLP.d.ts +1 -1
  41. package/lib/pathfinder/curveLP.js +5 -7
  42. package/lib/pathfinder/path.d.ts +1 -1
  43. package/lib/pathfinder/path.js +38 -42
  44. package/lib/pathfinder/trade.d.ts +1 -2
  45. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  46. package/lib/pathfinder/yVault.d.ts +2 -2
  47. package/lib/pathfinder/yVault.js +22 -19
  48. package/lib/payload/creditAccount.d.ts +4 -26
  49. package/lib/payload/creditManager.d.ts +3 -25
  50. package/lib/payload/pool.d.ts +2 -17
  51. package/lib/payload/pool.js +0 -1
  52. package/lib/strategies/curve.d.ts +6 -60
  53. package/lib/strategies/curve.js +6 -0
  54. package/lib/strategies/uniswapV2.js +3 -19
  55. package/lib/strategies/uniswapV3.js +1 -1
  56. package/lib/strategies/yearn.js +15 -11
  57. package/lib/tokens/convex.d.ts +3 -3
  58. package/lib/tokens/curveLP.d.ts +2 -2
  59. package/lib/tokens/curveLP.js +1 -1
  60. package/lib/tokens/gear.d.ts +2 -2
  61. package/lib/tokens/gear.js +1 -1
  62. package/lib/tokens/normal.d.ts +1 -1
  63. package/lib/tokens/token.js +9 -9
  64. package/lib/tokens/tokenData.d.ts +3 -1
  65. package/lib/tokens/tokenData.js +10 -8
  66. package/lib/tokens/yearn.d.ts +3 -3
  67. package/lib/utils/errors.d.ts +6 -0
  68. package/lib/utils/errors.js +13 -0
  69. package/lib/utils/formatter.d.ts +2 -1
  70. package/lib/utils/formatter.js +23 -15
  71. package/lib/utils/loading.d.ts +2 -1
  72. package/lib/utils/loading.js +9 -13
  73. package/lib/utils/mappers.d.ts +2 -1
  74. package/lib/utils/mappers.js +13 -5
  75. package/lib/utils/multicall.js +4 -3
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/types.d.ts +1 -0
  79. package/lib/utils/validate.js +1 -1
  80. package/package.json +26 -8
  81. package/src/apy/convexAPY.ts +250 -0
  82. package/src/apy/lidoAPY.ts +89 -0
  83. package/src/config.ts +2 -1
  84. package/src/contracts/contracts.ts +73 -19
  85. package/src/contracts/contractsRegister.ts +19 -4
  86. package/src/core/constants.ts +11 -4
  87. package/src/core/creditAccount.ts +69 -37
  88. package/src/core/creditManager.ts +256 -148
  89. package/src/core/creditOperation.ts +7 -7
  90. package/src/core/creditSession.ts +25 -5
  91. package/src/core/errors.ts +25 -0
  92. package/src/core/eventOrTx.ts +8 -5
  93. package/src/core/events.ts +978 -911
  94. package/src/core/history.ts +46 -46
  95. package/src/core/multicall.ts +1 -1
  96. package/src/core/operations.ts +6 -0
  97. package/src/core/pool.ts +75 -58
  98. package/src/core/price.ts +13 -0
  99. package/src/core/strategy.ts +134 -0
  100. package/src/core/tokenDistributor.ts +2 -2
  101. package/src/core/transactions.ts +427 -350
  102. package/src/index.ts +9 -4
  103. package/src/oracles/priceFeeds.ts +523 -523
  104. package/src/pathfinder/contracts.ts +15 -13
  105. package/src/pathfinder/convexLP.ts +29 -25
  106. package/src/pathfinder/curveLP.ts +57 -53
  107. package/src/pathfinder/path.ts +158 -150
  108. package/src/pathfinder/priority.ts +11 -11
  109. package/src/pathfinder/trade.ts +84 -77
  110. package/src/pathfinder/tradeTypes.ts +98 -94
  111. package/src/pathfinder/yVault.ts +79 -63
  112. package/src/payload/creditAccount.ts +4 -26
  113. package/src/payload/creditManager.ts +4 -26
  114. package/src/payload/pool.ts +2 -19
  115. package/src/payload/token.ts +3 -3
  116. package/src/strategies/convex.ts +217 -210
  117. package/src/strategies/creditFacade.ts +70 -53
  118. package/src/strategies/curve.ts +263 -194
  119. package/src/strategies/lido.ts +33 -37
  120. package/src/strategies/uniswapV2.ts +90 -112
  121. package/src/strategies/uniswapV3.ts +114 -91
  122. package/src/strategies/yearn.ts +58 -62
  123. package/src/tokens/connectors.ts +6 -6
  124. package/src/tokens/convex.ts +297 -296
  125. package/src/tokens/curveLP.ts +170 -165
  126. package/src/tokens/gear.ts +47 -45
  127. package/src/tokens/normal.ts +801 -802
  128. package/src/tokens/token.ts +19 -10
  129. package/src/tokens/tokenData.ts +19 -9
  130. package/src/tokens/tokenType.ts +11 -11
  131. package/src/tokens/yearn.ts +126 -124
  132. package/src/utils/errors.ts +11 -0
  133. package/src/utils/formatter.ts +26 -18
  134. package/src/utils/loading.ts +14 -6
  135. package/src/utils/mappers.ts +15 -6
  136. package/src/utils/multicall.ts +6 -9
  137. package/src/utils/network.ts +21 -21
  138. package/src/utils/repeater.ts +2 -2
  139. package/src/utils/types.ts +6 -2
  140. package/src/utils/validate.ts +1 -1
  141. package/lib/core/adapters.d.ts +0 -15
  142. package/lib/core/adapters.js +0 -19
  143. package/lib/core/contracts.d.ts +0 -67
  144. package/lib/core/contracts.js +0 -254
  145. package/lib/core/contractsRegister.d.ts +0 -2
  146. package/lib/core/contractsRegister.js +0 -58
  147. package/lib/core/creditCard.d.ts +0 -13
  148. package/lib/core/creditCard.js +0 -2
  149. package/lib/core/oracles.d.ts +0 -38
  150. package/lib/core/oracles.js +0 -12
  151. package/lib/core/priceFeeds.d.ts +0 -3
  152. package/lib/core/priceFeeds.js +0 -492
  153. package/lib/core/protocols.d.ts +0 -13
  154. package/lib/core/protocols.js +0 -39
  155. package/lib/core/swap.d.ts +0 -4
  156. package/lib/core/swap.js +0 -8
  157. package/lib/core/trade.d.ts +0 -35
  158. package/lib/core/trade.js +0 -62
  159. package/lib/core/tradeTypes.d.ts +0 -79
  160. package/lib/core/tradeTypes.js +0 -21
  161. package/lib/utils/events.d.ts +0 -2
  162. package/lib/utils/events.js +0 -13
  163. package/src/utils/events.ts +0 -10
@@ -38,40 +38,37 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.ConvexLPPathFinder = void 0;
40
40
  var convex_1 = require("../tokens/convex");
41
+ var mappers_1 = require("../utils/mappers");
41
42
  var ConvexLPPathFinder = /** @class */ (function () {
42
43
  function ConvexLPPathFinder() {
43
44
  }
45
+ // eslint-disable-next-line class-methods-use-this
44
46
  ConvexLPPathFinder.prototype.findWithdrawPaths = function (p) {
45
47
  return __awaiter(this, void 0, void 0, function () {
46
- var pids, _i, _a, _b, cvxToken, tokenData, currentBalance;
47
- return __generator(this, function (_c) {
48
- switch (_c.label) {
49
- case 0:
50
- pids = new Set();
51
- for (_i = 0, _a = Object.entries(convex_1.convexTokens); _i < _a.length; _i++) {
52
- _b = _a[_i], cvxToken = _b[0], tokenData = _b[1];
53
- currentBalance = p.popBalance(cvxToken);
54
- if (currentBalance.gt(1)) {
55
- pids.add(tokenData.pid);
56
- }
57
- }
58
- return [4 /*yield*/, p.withdrawTokens()];
59
- case 1:
60
- // const convexPathFinder = ConvexPathFinder__factory.connect(
61
- // pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
62
- // p.provider
63
- // );
64
- // const tokenBalances = await convexPathFinder.calcRewards(
65
- // p.creditAccount.addr,
66
- // Array.from(pids)
67
- // );
68
- // for (let balance of tokenBalances) {
69
- // p.balances[balance.token] = p.balances[balance.token].add(
70
- // balance.balance
71
- // );
72
- // }
73
- return [2 /*return*/, _c.sent()];
74
- }
48
+ var pids;
49
+ return __generator(this, function (_a) {
50
+ pids = (0, mappers_1.objectEntries)(convex_1.convexTokens).reduce(function (acc, _a) {
51
+ var cvxToken = _a[0], tokenData = _a[1];
52
+ var currentBalance = p.popBalance(cvxToken);
53
+ if (currentBalance.gt(1)) {
54
+ pids.add(tokenData.pid);
55
+ }
56
+ return acc;
57
+ }, new Set());
58
+ // const convexPathFinder = ConvexPathFinder__factory.connect(
59
+ // pathFindersByNetwork[p.networkType].CONVEX_PATH_FINDER,
60
+ // p.provider
61
+ // );
62
+ // const tokenBalances = await convexPathFinder.calcRewards(
63
+ // p.creditAccount.addr,
64
+ // Array.from(pids)
65
+ // );
66
+ // for (let balance of tokenBalances) {
67
+ // p.balances[balance.token] = p.balances[balance.token].add(
68
+ // balance.balance
69
+ // );
70
+ // }
71
+ return [2 /*return*/, p.withdrawTokens()];
75
72
  });
76
73
  });
77
74
  };
@@ -1,4 +1,4 @@
1
- import { LPWithdrawPathFinder, Path } from "./path";
1
+ import type { LPWithdrawPathFinder, Path } from "./path";
2
2
  import { CurveLPToken } from "../tokens/curveLP";
3
3
  import { CurvePoolContract } from "../contracts/contracts";
4
4
  export declare class CurvePathFinder implements LPWithdrawPathFinder {
@@ -45,12 +45,11 @@ var types_1 = require("../types");
45
45
  var CurvePathFinder = /** @class */ (function () {
46
46
  function CurvePathFinder(token) {
47
47
  this.lpToken = token;
48
- var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type == tradeTypes_1.TradeType.CurveWithdrawLP; });
48
+ var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type === tradeTypes_1.TradeType.CurveWithdrawLP; });
49
49
  if (curvePools.length !== 1)
50
50
  throw new Error("Cant find Withdrawer");
51
51
  this.contract = curvePools[0].contract;
52
- var wrapper = contracts_1.contractParams[curvePools[0].contract]
53
- .wrapper;
52
+ var wrapper = contracts_1.contractParams[curvePools[0].contract].wrapper;
54
53
  if (wrapper) {
55
54
  this.contract = wrapper;
56
55
  }
@@ -66,9 +65,8 @@ var CurvePathFinder = /** @class */ (function () {
66
65
  lpBalance = p.popBalance(this.lpToken);
67
66
  multiCallContract = new multicall_1.MultiCallContract(contracts_1.contractsByAddress[this.contract], types_1.ICurvePool__factory.createInterface(), p.provider);
68
67
  data = [];
69
- for (i = 0; i < nCoins; i++) {
68
+ for (i = 0; i < nCoins; i += 1) {
70
69
  data.push({
71
- // @ts-ignore
72
70
  method: "calc_withdraw_one_coin(uint256,int128)",
73
71
  params: [lpBalance, i]
74
72
  });
@@ -76,9 +74,9 @@ var CurvePathFinder = /** @class */ (function () {
76
74
  return [4 /*yield*/, multiCallContract.call(data)];
77
75
  case 1:
78
76
  balances = _a.sent();
79
- console.log(balances);
77
+ console.debug(balances);
80
78
  paths = [];
81
- for (i = 0; i < nCoins; i++) {
79
+ for (i = 0; i < nCoins; i += 1) {
82
80
  newPath = p.clone();
83
81
  // newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
84
82
  // newPath.calls.push({
@@ -24,7 +24,7 @@ export declare class Path {
24
24
  totalGasLimit: number;
25
25
  });
26
26
  popBalance(token: SupportedToken): BigNumber;
27
- private comparedByPriority;
27
+ private static comparedByPriority;
28
28
  static findBestPath(creditAccount: CreditAccountData, creditManager: CreditManagerData, provider: ethers.providers.Provider): Promise<void>;
29
29
  withdrawTokens(): Promise<Array<Path>>;
30
30
  clone(): Path;
@@ -76,15 +76,15 @@ var Path = /** @class */ (function () {
76
76
  this.balances[token] = ethers_1.BigNumber.from(1);
77
77
  return currentBalance.sub(1);
78
78
  };
79
- Path.prototype.comparedByPriority = function (_a, _b) {
80
- var tokenA = _a[0], _balanceA = _a[1];
81
- var tokenB = _b[0], _balanceB = _b[1];
79
+ Path.comparedByPriority = function (_a, _b) {
80
+ var tokenA = _a[0];
81
+ var tokenB = _b[0];
82
82
  var priorityTokenA = priority_1.priority[token_1.supportedTokens[tokenA].type];
83
83
  var priorityTokenB = priority_1.priority[token_1.supportedTokens[tokenB].type];
84
84
  if (priorityTokenA > priorityTokenB) {
85
85
  return -1;
86
86
  }
87
- else if (priorityTokenA < priorityTokenB) {
87
+ if (priorityTokenA < priorityTokenB) {
88
88
  return 1;
89
89
  }
90
90
  return 0;
@@ -123,8 +123,8 @@ var Path = /** @class */ (function () {
123
123
  case 2:
124
124
  lpPaths = _a.sent();
125
125
  pathFinder = types_1.PathFinder__factory.connect(contracts_1.pathFindersByNetwork[networkType].PATH_FINDER, provider);
126
- console.log(lpPaths);
127
- console.log(pathFinder);
126
+ console.debug(lpPaths);
127
+ console.debug(pathFinder);
128
128
  return [2 /*return*/];
129
129
  }
130
130
  });
@@ -134,43 +134,39 @@ var Path = /** @class */ (function () {
134
134
  return __awaiter(this, void 0, void 0, function () {
135
135
  var existingTokens, nextToken, lpPathFinder;
136
136
  return __generator(this, function (_a) {
137
- switch (_a.label) {
138
- case 0:
139
- existingTokens = Object.entries(this.balances)
140
- .filter(function (_a) {
141
- var _token = _a[0], balance = _a[1];
142
- return balance.gt(1);
143
- })
144
- .sort(this.comparedByPriority);
145
- // TODO: Add checks for lenght
146
- if (existingTokens.length === 0)
147
- throw new Error("No tokens with balance >1");
148
- nextToken = existingTokens.at(0)[0];
149
- // Get balances and keep non-zero only
150
- // Find token with highest priority
151
- // Get token type of this token
152
- switch (token_1.supportedTokens[nextToken].type) {
153
- case tokenType_1.TokenType.NORMAL_TOKEN:
154
- case tokenType_1.TokenType.CONNECTOR:
155
- return [2 /*return*/, [this]];
156
- case tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP:
157
- case tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP:
158
- case tokenType_1.TokenType.YEARN_VAULT:
159
- lpPathFinder = new yVault_1.YearnVaultPathFinder(nextToken);
160
- break;
161
- case tokenType_1.TokenType.CONVEX_LP_TOKEN:
162
- lpPathFinder = new convexLP_1.ConvexLPPathFinder();
163
- break;
164
- case tokenType_1.TokenType.META_CURVE_LP:
165
- case tokenType_1.TokenType.CURVE_LP:
166
- lpPathFinder = new curveLP_1.CurvePathFinder(nextToken);
167
- break;
168
- default:
169
- throw new Error("Token type not supported yet");
170
- }
171
- return [4 /*yield*/, lpPathFinder.findWithdrawPaths(this)];
172
- case 1: return [2 /*return*/, _a.sent()];
137
+ existingTokens = Object.entries(this.balances)
138
+ .filter(function (_a) {
139
+ var balance = _a[1];
140
+ return balance.gt(1);
141
+ })
142
+ .sort(Path.comparedByPriority);
143
+ // TODO: Add checks for lenght
144
+ if (existingTokens.length === 0)
145
+ throw new Error("No tokens with balance >1");
146
+ nextToken = existingTokens[0][0];
147
+ // Get balances and keep non-zero only
148
+ // Find token with highest priority
149
+ // Get token type of this token
150
+ switch (token_1.supportedTokens[nextToken].type) {
151
+ case tokenType_1.TokenType.NORMAL_TOKEN:
152
+ case tokenType_1.TokenType.CONNECTOR:
153
+ return [2 /*return*/, [this]];
154
+ case tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP:
155
+ case tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP:
156
+ case tokenType_1.TokenType.YEARN_VAULT:
157
+ lpPathFinder = new yVault_1.YearnVaultPathFinder(nextToken);
158
+ break;
159
+ case tokenType_1.TokenType.CONVEX_LP_TOKEN:
160
+ lpPathFinder = new convexLP_1.ConvexLPPathFinder();
161
+ break;
162
+ case tokenType_1.TokenType.META_CURVE_LP:
163
+ case tokenType_1.TokenType.CURVE_LP:
164
+ lpPathFinder = new curveLP_1.CurvePathFinder(nextToken);
165
+ break;
166
+ default:
167
+ throw new Error("Token type not supported yet");
173
168
  }
169
+ return [2 /*return*/, lpPathFinder.findWithdrawPaths(this)];
174
170
  });
175
171
  });
176
172
  };
@@ -1,5 +1,4 @@
1
- import { BigNumber } from "ethers";
2
- import { BytesLike } from "@ethersproject/bytes";
1
+ import { BigNumber, BytesLike } from "ethers";
3
2
  import { SwapType } from "./tradeTypes";
4
3
  export interface CloseTradePath {
5
4
  path: Array<string>;
@@ -1,8 +1,8 @@
1
- import { ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract } from "../contracts/contracts";
2
- import { NormalToken } from "../tokens/normal";
3
- import { CurveLPToken } from "../tokens/curveLP";
4
- import { YearnLPToken } from "../tokens/yearn";
5
- import { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
1
+ import type { ConvexPoolContract, CurvePoolContract, UniswapV2Contract, YearnVaultContract } from "../contracts/contracts";
2
+ import type { NormalToken } from "../tokens/normal";
3
+ import type { CurveLPToken } from "../tokens/curveLP";
4
+ import type { YearnLPToken } from "../tokens/yearn";
5
+ import type { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
6
6
  export declare enum TradeType {
7
7
  UniswapV2Swap = 0,
8
8
  UniswapV3Swap = 1,
@@ -1,10 +1,10 @@
1
- import { Path, LPWithdrawPathFinder } from "./path";
2
1
  import { YearnLPToken } from "../tokens/yearn";
3
2
  import { NormalToken } from "../tokens/normal";
4
3
  import { CurveLPToken } from "../tokens/curveLP";
4
+ import type { Path, LPWithdrawPathFinder } from "./path";
5
5
  export declare class YearnVaultPathFinder implements LPWithdrawPathFinder {
6
6
  _vault: YearnLPToken;
7
7
  token: NormalToken | CurveLPToken;
8
8
  constructor(vault: YearnLPToken);
9
- findWithdrawPaths(p: Path): Promise<Array<Path>>;
9
+ findWithdrawPaths(path: Path): Promise<Array<Path>>;
10
10
  }
@@ -38,10 +38,11 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.YearnVaultPathFinder = void 0;
40
40
  var ethers_1 = require("ethers");
41
- var types_1 = require("../types");
42
41
  var yearn_1 = require("../tokens/yearn");
43
42
  var token_1 = require("../tokens/token");
44
43
  var multicall_1 = require("../utils/multicall");
44
+ var mappers_1 = require("../utils/mappers");
45
+ var types_1 = require("../types");
45
46
  var YearnVaultPathFinder = /** @class */ (function () {
46
47
  function YearnVaultPathFinder(vault) {
47
48
  this._vault = vault;
@@ -49,23 +50,26 @@ var YearnVaultPathFinder = /** @class */ (function () {
49
50
  // Yearn Vault only has one lp action
50
51
  this.token = currentTokenData.underlying;
51
52
  }
52
- YearnVaultPathFinder.prototype.findWithdrawPaths = function (p) {
53
+ // eslint-disable-next-line class-methods-use-this
54
+ YearnVaultPathFinder.prototype.findWithdrawPaths = function (path) {
53
55
  return __awaiter(this, void 0, void 0, function () {
54
- var vaultBalances, _i, _a, _b, yVault, tokenData, currentBalance, vaultList, multicallData, prices, i, vault, vb;
55
- return __generator(this, function (_c) {
56
- switch (_c.label) {
56
+ var p, vaultBalances, vaultList, multicallData, prices, i, vault, vb, tokenAddress, adapterAddress, callData;
57
+ return __generator(this, function (_a) {
58
+ switch (_a.label) {
57
59
  case 0:
58
- vaultBalances = {};
59
- for (_i = 0, _a = Object.entries(yearn_1.yearnTokens); _i < _a.length; _i++) {
60
- _b = _a[_i], yVault = _b[0], tokenData = _b[1];
61
- currentBalance = p.popBalance(yVault);
60
+ p = Object.assign(Object.create(Object.getPrototypeOf(path)), path);
61
+ vaultBalances = (0, mappers_1.objectEntries)(yearn_1.yearnTokens).reduce(function (acc, _a) {
62
+ var yVault = _a[0], tokenData = _a[1];
63
+ var typedVault = yVault;
64
+ var currentBalance = p.popBalance(typedVault);
62
65
  if (currentBalance.gt(1)) {
63
- vaultBalances[yVault] = {
66
+ acc[typedVault] = {
64
67
  token: tokenData.underlying,
65
68
  balance: currentBalance
66
69
  };
67
70
  }
68
- }
71
+ return acc;
72
+ }, {});
69
73
  vaultList = Object.keys(vaultBalances);
70
74
  multicallData = vaultList
71
75
  .map(function (t) { return token_1.tokenDataByNetwork[p.networkType][t]; })
@@ -76,18 +80,17 @@ var YearnVaultPathFinder = /** @class */ (function () {
76
80
  }); });
77
81
  return [4 /*yield*/, (0, multicall_1.multicall)(multicallData, p.provider)];
78
82
  case 1:
79
- prices = _c.sent();
80
- for (i = 0; i < vaultList.length; i++) {
83
+ prices = _a.sent();
84
+ for (i = 0; i < vaultList.length; i += 1) {
81
85
  vault = vaultList[i];
82
86
  vb = vaultBalances[vault];
83
87
  p.balances[vb.token] = (p.balances[vb.token] || ethers_1.BigNumber.from(0)).add(ethers_1.BigNumber.from((vb === null || vb === void 0 ? void 0 : vb.balance) || 0).mul(prices[i]));
84
- p.calls.push({
85
- targetContract: p.creditManager.adapters[token_1.tokenDataByNetwork[p.networkType][vault]],
86
- callData: types_1.IYVault__factory.createInterface().encodeFunctionData("withdraw()")
87
- });
88
+ tokenAddress = token_1.tokenDataByNetwork[p.networkType][vault];
89
+ adapterAddress = p.creditManager.adapters[tokenAddress];
90
+ callData = types_1.IYVault__factory.createInterface().encodeFunctionData("withdraw()");
91
+ p.calls.push({ target: adapterAddress, callData: callData });
88
92
  }
89
- return [4 /*yield*/, p.withdrawTokens()];
90
- case 2: return [2 /*return*/, _c.sent()];
93
+ return [2 /*return*/, p.withdrawTokens()];
91
94
  }
92
95
  });
93
96
  });
@@ -1,26 +1,4 @@
1
- import { BigNumberish } from "ethers";
2
- export interface TokenBalancePayload {
3
- token: string;
4
- balance: BigNumberish;
5
- isAllowed: boolean;
6
- }
7
- export interface CreditAccountDataPayload {
8
- addr: string;
9
- borrower: string;
10
- inUse: boolean;
11
- creditManager: string;
12
- underlyingToken: string;
13
- borrowedAmountPlusInterest: BigNumberish;
14
- totalValue: BigNumberish;
15
- healthFactor: BigNumberish;
16
- borrowRate: BigNumberish;
17
- balances?: Array<TokenBalancePayload>;
18
- }
19
- export interface CreditAccountDataExtendedPayload extends CreditAccountDataPayload {
20
- repayAmount: BigNumberish;
21
- liquidationAmount: BigNumberish;
22
- canBeClosed?: boolean;
23
- borrowedAmount: BigNumberish;
24
- cumulativeIndexAtOpen: BigNumberish;
25
- since: BigNumberish;
26
- }
1
+ import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
2
+ export declare type TokenBalancePayload = CreditAccountDataStruct["balances"];
3
+ export declare type CreditAccountDataPayload = CreditAccountDataStruct;
4
+ export declare type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
@@ -1,33 +1,11 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { CreditManagerDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
2
3
  export interface AdapterPayload {
3
4
  allowedContract: string;
4
5
  adapter: string;
5
6
  }
6
- export interface CreditManagerDataPayload {
7
- addr: string;
8
- hasAccount?: boolean;
9
- underlyingToken?: string;
10
- isWETH?: boolean;
11
- canBorrow?: boolean;
12
- borrowRate?: BigNumberish;
13
- minAmount?: BigNumberish;
14
- maxAmount?: BigNumberish;
15
- maxLeverageFactor?: BigNumberish;
16
- availableLiquidity?: BigNumberish;
17
- allowedTokens?: Array<string>;
18
- adapters?: Array<AdapterPayload>;
19
- }
20
- export interface CreditManagerStatPayload {
21
- addr: string;
22
- underlyingToken?: string;
23
- isWETH?: boolean;
24
- canBorrow?: boolean;
25
- borrowRate?: BigNumberish;
26
- minAmount?: BigNumberish;
27
- maxAmount?: BigNumberish;
28
- maxLeverageFactor?: BigNumberish;
29
- availableLiquidity?: BigNumberish;
30
- allowedTokens?: Array<string>;
7
+ export declare type CreditManagerDataPayload = CreditManagerDataStruct;
8
+ export interface CreditManagerStatPayload extends CreditManagerDataPayload {
31
9
  allowedContracts?: Array<string>;
32
10
  uniqueUsers: number;
33
11
  openedAccountsCount?: number;
@@ -1,17 +1,2 @@
1
- import { BigNumberish } from "ethers";
2
- export interface PoolDataPayload {
3
- addr: string;
4
- underlyingToken: string;
5
- dieselToken: string;
6
- isWETH: boolean;
7
- expectedLiquidity: BigNumberish;
8
- expectedLiquidityLimit?: BigNumberish;
9
- availableLiquidity: BigNumberish;
10
- totalBorrowed: BigNumberish;
11
- depositAPY_RAY: BigNumberish;
12
- borrowAPY_RAY: BigNumberish;
13
- dieselRate_RAY: BigNumberish;
14
- withdrawFee: BigNumberish;
15
- timestampLU?: BigNumberish;
16
- cumulativeIndex_RAY?: BigNumberish;
17
- }
1
+ import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
2
+ export declare type PoolDataPayload = PoolDataStruct;
@@ -1,3 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //
@@ -8,36 +8,9 @@ export declare class CurveCalls {
8
8
  static add_all_liquidity_one_coin(i: BigNumberish, rateMinRAY: BigNumberish): string;
9
9
  static remove_liquidity_one_coin(token_amount: BigNumberish, i: BigNumberish, min_amount: BigNumberish): string;
10
10
  static remove_all_liquidity_one_coin(i: BigNumberish, minRateRAY: BigNumberish): string;
11
- static add_liquidity(amounts: [BigNumberish, BigNumberish] | [
12
- BigNumberish,
13
- BigNumberish,
14
- BigNumberish
15
- ] | [
16
- BigNumberish,
17
- BigNumberish,
18
- BigNumberish,
19
- BigNumberish
20
- ], min_mint_amount: BigNumberish): string;
21
- static remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [
22
- BigNumberish,
23
- BigNumberish,
24
- BigNumberish
25
- ] | [
26
- BigNumberish,
27
- BigNumberish,
28
- BigNumberish,
29
- BigNumberish
30
- ]): string;
31
- static remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [
32
- BigNumberish,
33
- BigNumberish,
34
- BigNumberish
35
- ] | [
36
- BigNumberish,
37
- BigNumberish,
38
- BigNumberish,
39
- BigNumberish
40
- ], max_burn_amount: BigNumberish): string;
11
+ static add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): string;
12
+ static remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): string;
13
+ static remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): string;
41
14
  }
42
15
  export declare class CurveMulticaller {
43
16
  private readonly _address;
@@ -55,34 +28,7 @@ export declare class CurveMulticaller {
55
28
  target: string;
56
29
  callData: string;
57
30
  };
58
- add_liquidity(amounts: [BigNumberish, BigNumberish] | [
59
- BigNumberish,
60
- BigNumberish,
61
- BigNumberish
62
- ] | [
63
- BigNumberish,
64
- BigNumberish,
65
- BigNumberish,
66
- BigNumberish
67
- ], min_mint_amount: BigNumberish): MultiCallStruct;
68
- remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [
69
- BigNumberish,
70
- BigNumberish,
71
- BigNumberish
72
- ] | [
73
- BigNumberish,
74
- BigNumberish,
75
- BigNumberish,
76
- BigNumberish
77
- ]): MultiCallStruct;
78
- remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [
79
- BigNumberish,
80
- BigNumberish,
81
- BigNumberish
82
- ] | [
83
- BigNumberish,
84
- BigNumberish,
85
- BigNumberish,
86
- BigNumberish
87
- ], max_burn_amount: BigNumberish): MultiCallStruct;
31
+ add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): MultiCallStruct;
32
+ remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): MultiCallStruct;
33
+ remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): MultiCallStruct;
88
34
  }
@@ -34,6 +34,8 @@ var CurveCalls = /** @class */ (function () {
34
34
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
35
35
  case 4:
36
36
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
37
+ default:
38
+ throw new Error("Wrong calls number: add_liquidity");
37
39
  }
38
40
  };
39
41
  CurveCalls.remove_liquidity = function (amount, min_amounts) {
@@ -44,6 +46,8 @@ var CurveCalls = /** @class */ (function () {
44
46
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
45
47
  case 4:
46
48
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
49
+ default:
50
+ throw new Error("Wrong calls number: remove_liquidity");
47
51
  }
48
52
  };
49
53
  CurveCalls.remove_liquidity_imbalance = function (amounts, max_burn_amount) {
@@ -54,6 +58,8 @@ var CurveCalls = /** @class */ (function () {
54
58
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
55
59
  case 4:
56
60
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
61
+ default:
62
+ throw new Error("Wrong calls number: remove_liquidity_imbalance");
57
63
  }
58
64
  };
59
65
  return CurveCalls;
@@ -6,29 +6,13 @@ var UniswapV2Calls = /** @class */ (function () {
6
6
  function UniswapV2Calls() {
7
7
  }
8
8
  UniswapV2Calls.swapExactTokensForTokens = function (amountIn, amountOutMin, path, to, deadline) {
9
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [
10
- amountIn,
11
- amountOutMin,
12
- path,
13
- to,
14
- deadline
15
- ]);
9
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapExactTokensForTokens", [amountIn, amountOutMin, path, to, deadline]);
16
10
  };
17
11
  UniswapV2Calls.swapTokensForExactTokens = function (amountOut, amountInMax, path, to, deadline) {
18
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapTokensForExactTokens", [
19
- amountOut,
20
- amountInMax,
21
- path,
22
- to,
23
- deadline
24
- ]);
12
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapTokensForExactTokens", [amountOut, amountInMax, path, to, deadline]);
25
13
  };
26
14
  UniswapV2Calls.swapAllTokensForTokens = function (rateMinRAY, path, deadline) {
27
- return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapAllTokensForTokens", [
28
- rateMinRAY,
29
- path,
30
- deadline
31
- ]);
15
+ return types_1.UniswapV2Adapter__factory.createInterface().encodeFunctionData("swapAllTokensForTokens", [rateMinRAY, path, deadline]);
32
16
  };
33
17
  return UniswapV2Calls;
34
18
  }());
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- //import { BigNumberish } from "ethers";
2
+ // import { BigNumberish } from "ethers";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.UniswapV3Multicaller = exports.UniswapV3Calls = void 0;
5
5
  var types_1 = require("../types");
@@ -8,14 +8,15 @@ var YearnV2Calls = /** @class */ (function () {
8
8
  YearnV2Calls.deposit = function (amount, recipient) {
9
9
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
10
10
  if (amount && recipient) {
11
- return contractInterface.encodeFunctionData("deposit(uint256,address)", [amount, recipient]);
11
+ return contractInterface.encodeFunctionData("deposit(uint256,address)", [
12
+ amount,
13
+ recipient
14
+ ]);
12
15
  }
13
- else if (amount) {
16
+ if (amount) {
14
17
  return contractInterface.encodeFunctionData("deposit(uint256)", [amount]);
15
18
  }
16
- else {
17
- return contractInterface.encodeFunctionData("deposit()");
18
- }
19
+ return contractInterface.encodeFunctionData("deposit()");
19
20
  };
20
21
  YearnV2Calls.withdraw = function (maxShares, recipient, maxLoss) {
21
22
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
@@ -23,14 +24,17 @@ var YearnV2Calls = /** @class */ (function () {
23
24
  return contractInterface.encodeFunctionData("withdraw(uint256,address,uint256)", [maxShares, recipient, maxLoss]);
24
25
  }
25
26
  if (maxShares && recipient) {
26
- return contractInterface.encodeFunctionData("withdraw(uint256,address)", [maxShares, recipient]);
27
- }
28
- else if (maxShares) {
29
- return contractInterface.encodeFunctionData("withdraw(uint256)", [maxShares]);
27
+ return contractInterface.encodeFunctionData("withdraw(uint256,address)", [
28
+ maxShares,
29
+ recipient
30
+ ]);
30
31
  }
31
- else {
32
- return contractInterface.encodeFunctionData("withdraw()");
32
+ if (maxShares) {
33
+ return contractInterface.encodeFunctionData("withdraw(uint256)", [
34
+ maxShares
35
+ ]);
33
36
  }
37
+ return contractInterface.encodeFunctionData("withdraw()");
34
38
  };
35
39
  return YearnV2Calls;
36
40
  }());