@gearbox-protocol/sdk 0.0.101 → 0.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.js +7 -9
  5. package/lib/apy/lidoAPY.js +35 -29
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/contracts/contractsRegister.js +13 -1
  9. package/lib/core/constants.d.ts +5 -3
  10. package/lib/core/constants.js +8 -6
  11. package/lib/core/creditAccount.d.ts +2 -2
  12. package/lib/core/creditAccount.js +12 -11
  13. package/lib/core/creditManager.d.ts +1 -1
  14. package/lib/core/creditManager.js +4 -10
  15. package/lib/core/creditSession.js +14 -3
  16. package/lib/core/eventOrTx.d.ts +1 -1
  17. package/lib/core/events.d.ts +19 -19
  18. package/lib/core/events.js +23 -21
  19. package/lib/core/pool.d.ts +1 -1
  20. package/lib/core/pool.js +1 -7
  21. package/lib/core/price.d.ts +1 -3
  22. package/lib/core/price.js +9 -7
  23. package/lib/core/strategy.d.ts +8 -6
  24. package/lib/core/strategy.js +25 -25
  25. package/lib/core/tokenDistributor.js +1 -1
  26. package/lib/core/transactions.d.ts +18 -3
  27. package/lib/core/transactions.js +39 -3
  28. package/lib/index.d.ts +8 -2
  29. package/lib/index.js +8 -1
  30. package/lib/oracles/priceFeeds.js +1 -1
  31. package/lib/pathfinder/convexLP.d.ts +1 -1
  32. package/lib/pathfinder/convexLP.js +26 -29
  33. package/lib/pathfinder/curveLP.d.ts +1 -1
  34. package/lib/pathfinder/curveLP.js +5 -7
  35. package/lib/pathfinder/path.d.ts +1 -1
  36. package/lib/pathfinder/path.js +38 -42
  37. package/lib/pathfinder/trade.d.ts +1 -2
  38. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  39. package/lib/pathfinder/yVault.d.ts +2 -2
  40. package/lib/pathfinder/yVault.js +22 -22
  41. package/lib/payload/creditAccount.d.ts +4 -4
  42. package/lib/payload/creditManager.d.ts +3 -13
  43. package/lib/payload/pool.d.ts +2 -2
  44. package/lib/strategies/convex.d.ts +12 -0
  45. package/lib/strategies/convex.js +74 -1
  46. package/lib/strategies/creditFacade.d.ts +1 -0
  47. package/lib/strategies/creditFacade.js +3 -0
  48. package/lib/strategies/curve.d.ts +15 -60
  49. package/lib/strategies/curve.js +74 -1
  50. package/lib/strategies/lido.d.ts +6 -0
  51. package/lib/strategies/lido.js +23 -1
  52. package/lib/strategies/uniswapV2.d.ts +1 -0
  53. package/lib/strategies/uniswapV2.js +6 -19
  54. package/lib/strategies/uniswapV3.d.ts +1 -0
  55. package/lib/strategies/uniswapV3.js +4 -1
  56. package/lib/strategies/yearn.d.ts +8 -0
  57. package/lib/strategies/yearn.js +92 -12
  58. package/lib/tokens/convex.d.ts +3 -3
  59. package/lib/tokens/curveLP.d.ts +7 -2
  60. package/lib/tokens/curveLP.js +8 -1
  61. package/lib/tokens/gear.d.ts +2 -2
  62. package/lib/tokens/gear.js +1 -1
  63. package/lib/tokens/normal.d.ts +1 -1
  64. package/lib/tokens/token.js +8 -8
  65. package/lib/tokens/tokenData.d.ts +3 -1
  66. package/lib/tokens/tokenData.js +10 -8
  67. package/lib/tokens/yearn.d.ts +6 -2
  68. package/lib/tokens/yearn.js +6 -0
  69. package/lib/utils/errors.d.ts +6 -0
  70. package/lib/utils/errors.js +13 -0
  71. package/lib/utils/formatter.d.ts +1 -1
  72. package/lib/utils/formatter.js +17 -14
  73. package/lib/utils/loading.d.ts +2 -1
  74. package/lib/utils/loading.js +9 -13
  75. package/lib/utils/mappers.js +2 -2
  76. package/lib/utils/network.js +2 -2
  77. package/lib/utils/repeater.js +12 -24
  78. package/lib/utils/validate.js +1 -1
  79. package/package.json +24 -7
  80. package/src/apy/convexAPY.ts +13 -12
  81. package/src/apy/lidoAPY.ts +35 -27
  82. package/src/contracts/contracts.ts +27 -17
  83. package/src/contracts/contractsRegister.ts +16 -1
  84. package/src/core/constants.ts +8 -5
  85. package/src/core/creditAccount.ts +42 -16
  86. package/src/core/creditManager.ts +33 -7
  87. package/src/core/creditOperation.ts +7 -7
  88. package/src/core/creditSession.ts +25 -5
  89. package/src/core/errors.ts +1 -0
  90. package/src/core/eventOrTx.ts +8 -5
  91. package/src/core/events.ts +85 -24
  92. package/src/core/history.ts +46 -46
  93. package/src/core/operations.ts +6 -0
  94. package/src/core/pool.ts +16 -4
  95. package/src/core/price.ts +10 -13
  96. package/src/core/strategy.ts +54 -43
  97. package/src/core/tokenDistributor.ts +2 -2
  98. package/src/core/transactions.ts +427 -350
  99. package/src/index.ts +10 -3
  100. package/src/oracles/priceFeeds.ts +523 -523
  101. package/src/pathfinder/contracts.ts +15 -13
  102. package/src/pathfinder/convexLP.ts +29 -25
  103. package/src/pathfinder/curveLP.ts +57 -53
  104. package/src/pathfinder/path.ts +17 -9
  105. package/src/pathfinder/priority.ts +11 -11
  106. package/src/pathfinder/trade.ts +84 -77
  107. package/src/pathfinder/tradeTypes.ts +98 -94
  108. package/src/pathfinder/yVault.ts +32 -17
  109. package/src/payload/creditAccount.ts +4 -4
  110. package/src/payload/creditManager.ts +3 -13
  111. package/src/payload/pool.ts +2 -2
  112. package/src/payload/token.ts +3 -3
  113. package/src/strategies/convex.ts +360 -186
  114. package/src/strategies/creditFacade.ts +74 -53
  115. package/src/strategies/curve.ts +400 -189
  116. package/src/strategies/lido.ts +70 -32
  117. package/src/strategies/uniswapV2.ts +93 -111
  118. package/src/strategies/uniswapV3.ts +118 -91
  119. package/src/strategies/yearn.ts +187 -60
  120. package/src/tokens/connectors.ts +6 -6
  121. package/src/tokens/convex.ts +297 -296
  122. package/src/tokens/curveLP.ts +176 -165
  123. package/src/tokens/gear.ts +47 -45
  124. package/src/tokens/normal.ts +801 -802
  125. package/src/tokens/token.ts +13 -9
  126. package/src/tokens/tokenData.ts +19 -9
  127. package/src/tokens/tokenType.ts +11 -11
  128. package/src/tokens/yearn.ts +130 -124
  129. package/src/utils/errors.ts +11 -0
  130. package/src/utils/formatter.ts +22 -18
  131. package/src/utils/loading.ts +14 -6
  132. package/src/utils/mappers.ts +8 -6
  133. package/src/utils/multicall.ts +2 -0
  134. package/src/utils/network.ts +21 -21
  135. package/src/utils/repeater.ts +2 -2
  136. package/src/utils/validate.ts +1 -1
  137. package/lib/utils/events.d.ts +0 -2
  138. package/lib/utils/events.js +0 -13
  139. package/src/utils/events.ts +0 -10
@@ -1,4 +1,7 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { CurvePoolContract } from "src/contracts/contracts";
3
+ import { NetworkType } from "src/core/constants";
4
+ import { CreditManagerData } from "src/core/creditManager";
2
5
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
3
6
  export declare class CurveCalls {
4
7
  static exchange(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish): string;
@@ -8,40 +11,14 @@ export declare class CurveCalls {
8
11
  static add_all_liquidity_one_coin(i: BigNumberish, rateMinRAY: BigNumberish): string;
9
12
  static remove_liquidity_one_coin(token_amount: BigNumberish, i: BigNumberish, min_amount: BigNumberish): string;
10
13
  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;
14
+ static add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): string;
15
+ static remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): string;
16
+ static remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): string;
41
17
  }
42
18
  export declare class CurveMulticaller {
43
19
  private readonly _address;
44
20
  constructor(address: string);
21
+ static connect(address: string): CurveMulticaller;
45
22
  exchange(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish): MultiCallStruct;
46
23
  exchange_all(i: BigNumberish, j: BigNumberish, rateMinRAY: BigNumberish): MultiCallStruct;
47
24
  exchange_underlying(i: BigNumberish, j: BigNumberish, dx: BigNumberish, min_dy: BigNumberish): MultiCallStruct;
@@ -55,34 +32,12 @@ export declare class CurveMulticaller {
55
32
  target: string;
56
33
  callData: string;
57
34
  };
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;
35
+ add_liquidity(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], min_mint_amount: BigNumberish): MultiCallStruct;
36
+ remove_liquidity(amount: BigNumberish, min_amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish]): MultiCallStruct;
37
+ remove_liquidity_imbalance(amounts: [BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish] | [BigNumberish, BigNumberish, BigNumberish, BigNumberish], max_burn_amount: BigNumberish): MultiCallStruct;
38
+ }
39
+ export declare class CurveStrategies {
40
+ static underlyingToCurveLP(data: CreditManagerData, network: NetworkType, curvePool: CurvePoolContract, underlyingAmount: BigNumberish): MultiCallStruct[];
41
+ static curveLPToUnderlying(data: CreditManagerData, network: NetworkType, curvePool: CurvePoolContract, curveLPAmount: BigNumberish): MultiCallStruct[];
42
+ static allCurveLPToUnderlying(data: CreditManagerData, network: NetworkType, curvePool: CurvePoolContract): MultiCallStruct[];
88
43
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CurveMulticaller = exports.CurveCalls = void 0;
3
+ exports.CurveStrategies = exports.CurveMulticaller = exports.CurveCalls = void 0;
4
+ var contracts_1 = require("src/contracts/contracts");
5
+ var constants_1 = require("src/core/constants");
6
+ var token_1 = require("src/tokens/token");
4
7
  var types_1 = require("../types");
8
+ var uniswapV2_1 = require("./uniswapV2");
5
9
  var CurveCalls = /** @class */ (function () {
6
10
  function CurveCalls() {
7
11
  }
@@ -34,6 +38,8 @@ var CurveCalls = /** @class */ (function () {
34
38
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
35
39
  case 4:
36
40
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("add_liquidity", [amounts, min_mint_amount]);
41
+ default:
42
+ throw new Error("Wrong calls number: add_liquidity");
37
43
  }
38
44
  };
39
45
  CurveCalls.remove_liquidity = function (amount, min_amounts) {
@@ -44,6 +50,8 @@ var CurveCalls = /** @class */ (function () {
44
50
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
45
51
  case 4:
46
52
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity", [amount, min_amounts]);
53
+ default:
54
+ throw new Error("Wrong calls number: remove_liquidity");
47
55
  }
48
56
  };
49
57
  CurveCalls.remove_liquidity_imbalance = function (amounts, max_burn_amount) {
@@ -54,6 +62,8 @@ var CurveCalls = /** @class */ (function () {
54
62
  return types_1.CurveV1Adapter3Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
55
63
  case 4:
56
64
  return types_1.CurveV1Adapter4Assets__factory.createInterface().encodeFunctionData("remove_liquidity_imbalance", [amounts, max_burn_amount]);
65
+ default:
66
+ throw new Error("Wrong calls number: remove_liquidity_imbalance");
57
67
  }
58
68
  };
59
69
  return CurveCalls;
@@ -63,6 +73,9 @@ var CurveMulticaller = /** @class */ (function () {
63
73
  function CurveMulticaller(address) {
64
74
  this._address = address;
65
75
  }
76
+ CurveMulticaller.connect = function (address) {
77
+ return new CurveMulticaller(address);
78
+ };
66
79
  CurveMulticaller.prototype.exchange = function (i, j, dx, min_dy) {
67
80
  return {
68
81
  target: this._address,
@@ -126,3 +139,63 @@ var CurveMulticaller = /** @class */ (function () {
126
139
  return CurveMulticaller;
127
140
  }());
128
141
  exports.CurveMulticaller = CurveMulticaller;
142
+ var CurveStrategies = /** @class */ (function () {
143
+ function CurveStrategies() {
144
+ }
145
+ CurveStrategies.underlyingToCurveLP = function (data, network, curvePool, underlyingAmount) {
146
+ var calls = [];
147
+ var curveParams = contracts_1.contractParams[curvePool];
148
+ var tokenToDeposit = curveParams.tokens[0];
149
+ if (data.underlyingToken !== token_1.tokenDataByNetwork[network][tokenToDeposit]) {
150
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapExactTokensForTokens(underlyingAmount, 0, [data.underlyingToken, token_1.tokenDataByNetwork[network][tokenToDeposit]], constants_1.ADDRESS_0X0, Math.floor(new Date().getTime() / 1000) + 3600));
151
+ }
152
+ calls.push(CurveMulticaller.connect(data.adapters[contracts_1.contractsByNetwork[network][curvePool]]).add_all_liquidity_one_coin(0, 0));
153
+ return calls;
154
+ };
155
+ CurveStrategies.curveLPToUnderlying = function (data, network, curvePool, curveLPAmount) {
156
+ var calls = [];
157
+ var curveParams = contracts_1.contractParams[curvePool];
158
+ var curveContractAddress;
159
+ if (curveParams.wrapper) {
160
+ curveContractAddress =
161
+ data.adapters[contracts_1.contractsByNetwork[network][curveParams.wrapper]];
162
+ }
163
+ else {
164
+ curveContractAddress =
165
+ data.adapters[contracts_1.contractsByNetwork[network][curvePool]];
166
+ }
167
+ calls.push(CurveMulticaller.connect(curveContractAddress).remove_liquidity_one_coin(curveLPAmount, 0, 0));
168
+ if (token_1.tokenDataByNetwork[network][curveParams.tokens[0]] !==
169
+ data.underlyingToken) {
170
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapAllTokensForTokens(0, [
171
+ token_1.tokenDataByNetwork[network][curveParams.tokens[0]],
172
+ data.underlyingToken
173
+ ], Math.floor(new Date().getTime() / 1000) + 3600));
174
+ }
175
+ return calls;
176
+ };
177
+ CurveStrategies.allCurveLPToUnderlying = function (data, network, curvePool) {
178
+ var calls = [];
179
+ var curveParams = contracts_1.contractParams[curvePool];
180
+ var curveContractAddress;
181
+ if (curveParams.wrapper) {
182
+ curveContractAddress =
183
+ data.adapters[contracts_1.contractsByNetwork[network][curveParams.wrapper]];
184
+ }
185
+ else {
186
+ curveContractAddress =
187
+ data.adapters[contracts_1.contractsByNetwork[network][curvePool]];
188
+ }
189
+ calls.push(CurveMulticaller.connect(curveContractAddress).remove_all_liquidity_one_coin(0, 0));
190
+ if (token_1.tokenDataByNetwork[network][curveParams.tokens[0]] !==
191
+ data.underlyingToken) {
192
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapAllTokensForTokens(0, [
193
+ token_1.tokenDataByNetwork[network][curveParams.tokens[0]],
194
+ data.underlyingToken
195
+ ], Math.floor(new Date().getTime() / 1000) + 3600));
196
+ }
197
+ return calls;
198
+ };
199
+ return CurveStrategies;
200
+ }());
201
+ exports.CurveStrategies = CurveStrategies;
@@ -1,4 +1,6 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { CreditManagerData } from "src/core/creditManager";
3
+ import { NetworkType } from "src/core/constants";
2
4
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
3
5
  export declare class LidoCalls {
4
6
  static submit(amount: BigNumberish): string;
@@ -7,6 +9,10 @@ export declare class LidoCalls {
7
9
  export declare class LidoMulticaller {
8
10
  private readonly _address;
9
11
  constructor(address: string);
12
+ static connect(address: string): LidoMulticaller;
10
13
  submit(amount: BigNumberish): MultiCallStruct;
11
14
  submitAll(): MultiCallStruct;
12
15
  }
16
+ export declare class LidoStrategies {
17
+ static mintSteth(data: CreditManagerData, network: NetworkType, underlyingAmount: BigNumberish): MultiCallStruct[];
18
+ }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LidoMulticaller = exports.LidoCalls = void 0;
3
+ exports.LidoStrategies = exports.LidoMulticaller = exports.LidoCalls = void 0;
4
+ var constants_1 = require("src/core/constants");
5
+ var contracts_1 = require("src/contracts/contracts");
6
+ var token_1 = require("src/tokens/token");
4
7
  var types_1 = require("../types");
8
+ var uniswapV2_1 = require("./uniswapV2");
5
9
  var LidoCalls = /** @class */ (function () {
6
10
  function LidoCalls() {
7
11
  }
@@ -18,6 +22,9 @@ var LidoMulticaller = /** @class */ (function () {
18
22
  function LidoMulticaller(address) {
19
23
  this._address = address;
20
24
  }
25
+ LidoMulticaller.connect = function (address) {
26
+ return new LidoMulticaller(address);
27
+ };
21
28
  LidoMulticaller.prototype.submit = function (amount) {
22
29
  return {
23
30
  target: this._address,
@@ -33,3 +40,18 @@ var LidoMulticaller = /** @class */ (function () {
33
40
  return LidoMulticaller;
34
41
  }());
35
42
  exports.LidoMulticaller = LidoMulticaller;
43
+ var LidoStrategies = /** @class */ (function () {
44
+ function LidoStrategies() {
45
+ }
46
+ LidoStrategies.mintSteth = function (data, network, underlyingAmount) {
47
+ var calls = [];
48
+ // This should be a pathfinder call
49
+ if (!data.isWETH) {
50
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapExactTokensForTokens(underlyingAmount, 0, [data.underlyingToken, token_1.tokenDataByNetwork[network].WETH], constants_1.ADDRESS_0X0, Math.floor(new Date().getTime() / 1000) + 3600));
51
+ }
52
+ calls.push(LidoMulticaller.connect(data.adapters[contracts_1.contractsByNetwork[network].LIDO_STETH_GATEWAY]).submitAll());
53
+ return calls;
54
+ };
55
+ return LidoStrategies;
56
+ }());
57
+ exports.LidoStrategies = LidoStrategies;
@@ -8,6 +8,7 @@ export declare class UniswapV2Calls {
8
8
  export declare class UniswapV2Multicaller {
9
9
  private readonly _address;
10
10
  constructor(address: string);
11
+ static connect(address: string): UniswapV2Multicaller;
11
12
  swapExactTokensForTokens(amountIn: BigNumberish, amountOutMin: BigNumberish, path: Array<string>, to: string, deadline: BigNumberish): MultiCallStruct;
12
13
  swapTokensForExactTokens(amountOut: BigNumberish, amountInMax: BigNumberish, path: Array<string>, to: string, deadline: BigNumberish): MultiCallStruct;
13
14
  swapAllTokensForTokens(rateMinRAY: BigNumberish, path: Array<string>, deadline: BigNumberish): MultiCallStruct;
@@ -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
  }());
@@ -37,6 +21,9 @@ var UniswapV2Multicaller = /** @class */ (function () {
37
21
  function UniswapV2Multicaller(address) {
38
22
  this._address = address;
39
23
  }
24
+ UniswapV2Multicaller.connect = function (address) {
25
+ return new UniswapV2Multicaller(address);
26
+ };
40
27
  UniswapV2Multicaller.prototype.swapExactTokensForTokens = function (amountIn, amountOutMin, path, to, deadline) {
41
28
  return {
42
29
  target: this._address,
@@ -11,6 +11,7 @@ export declare class UniswapV3Calls {
11
11
  export declare class UniswapV3Multicaller {
12
12
  private readonly _address;
13
13
  constructor(address: string);
14
+ static connect(address: string): UniswapV3Multicaller;
14
15
  exactInputSingle(params: ISwapRouter.ExactInputSingleParamsStructOutput): MultiCallStruct;
15
16
  exactAllInputSingle(params: IUniswapV3Adapter.ExactAllInputSingleParamsStructOutput): MultiCallStruct;
16
17
  exactInput(params: ISwapRouter.ExactInputParamsStructOutput): MultiCallStruct;
@@ -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");
@@ -31,6 +31,9 @@ var UniswapV3Multicaller = /** @class */ (function () {
31
31
  function UniswapV3Multicaller(address) {
32
32
  this._address = address;
33
33
  }
34
+ UniswapV3Multicaller.connect = function (address) {
35
+ return new UniswapV3Multicaller(address);
36
+ };
34
37
  UniswapV3Multicaller.prototype.exactInputSingle = function (params) {
35
38
  return {
36
39
  target: this._address,
@@ -1,4 +1,7 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { YearnVaultContract } from "src/contracts/contracts";
3
+ import { NetworkType } from "src/core/constants";
4
+ import { CreditManagerData } from "src/core/creditManager";
2
5
  import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
3
6
  export declare class YearnV2Calls {
4
7
  static deposit(amount?: BigNumberish, recipient?: string): string;
@@ -7,6 +10,11 @@ export declare class YearnV2Calls {
7
10
  export declare class YearnV2Multicaller {
8
11
  private readonly _address;
9
12
  constructor(address: string);
13
+ static connect(address: string): YearnV2Multicaller;
10
14
  deposit(amount?: BigNumberish, recipient?: string): MultiCallStruct;
11
15
  withdraw(maxShares?: BigNumberish, recipient?: string, maxLoss?: BigNumberish): MultiCallStruct;
12
16
  }
17
+ export declare class YearnV2Strategies {
18
+ static underlyingToYearn(data: CreditManagerData, network: NetworkType, yearnVault: YearnVaultContract, underlyingAmount: BigNumberish): void;
19
+ static yearnToUnderlying(data: CreditManagerData, network: NetworkType, yearnVault: YearnVaultContract, yearnSharesAmount: BigNumberish): void;
20
+ }
@@ -1,21 +1,37 @@
1
1
  "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.YearnV2Multicaller = exports.YearnV2Calls = void 0;
12
+ exports.YearnV2Strategies = exports.YearnV2Multicaller = exports.YearnV2Calls = void 0;
13
+ var contracts_1 = require("src/contracts/contracts");
14
+ var constants_1 = require("src/core/constants");
15
+ var token_1 = require("src/tokens/token");
16
+ var tokenType_1 = require("src/tokens/tokenType");
4
17
  var types_1 = require("../types");
18
+ var curve_1 = require("./curve");
19
+ var uniswapV2_1 = require("./uniswapV2");
5
20
  var YearnV2Calls = /** @class */ (function () {
6
21
  function YearnV2Calls() {
7
22
  }
8
23
  YearnV2Calls.deposit = function (amount, recipient) {
9
24
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
10
25
  if (amount && recipient) {
11
- return contractInterface.encodeFunctionData("deposit(uint256,address)", [amount, recipient]);
26
+ return contractInterface.encodeFunctionData("deposit(uint256,address)", [
27
+ amount,
28
+ recipient
29
+ ]);
12
30
  }
13
- else if (amount) {
31
+ if (amount) {
14
32
  return contractInterface.encodeFunctionData("deposit(uint256)", [amount]);
15
33
  }
16
- else {
17
- return contractInterface.encodeFunctionData("deposit()");
18
- }
34
+ return contractInterface.encodeFunctionData("deposit()");
19
35
  };
20
36
  YearnV2Calls.withdraw = function (maxShares, recipient, maxLoss) {
21
37
  var contractInterface = types_1.YearnV2Adapter__factory.createInterface();
@@ -23,14 +39,17 @@ var YearnV2Calls = /** @class */ (function () {
23
39
  return contractInterface.encodeFunctionData("withdraw(uint256,address,uint256)", [maxShares, recipient, maxLoss]);
24
40
  }
25
41
  if (maxShares && recipient) {
26
- return contractInterface.encodeFunctionData("withdraw(uint256,address)", [maxShares, recipient]);
27
- }
28
- else if (maxShares) {
29
- return contractInterface.encodeFunctionData("withdraw(uint256)", [maxShares]);
42
+ return contractInterface.encodeFunctionData("withdraw(uint256,address)", [
43
+ maxShares,
44
+ recipient
45
+ ]);
30
46
  }
31
- else {
32
- return contractInterface.encodeFunctionData("withdraw()");
47
+ if (maxShares) {
48
+ return contractInterface.encodeFunctionData("withdraw(uint256)", [
49
+ maxShares
50
+ ]);
33
51
  }
52
+ return contractInterface.encodeFunctionData("withdraw()");
34
53
  };
35
54
  return YearnV2Calls;
36
55
  }());
@@ -39,6 +58,9 @@ var YearnV2Multicaller = /** @class */ (function () {
39
58
  function YearnV2Multicaller(address) {
40
59
  this._address = address;
41
60
  }
61
+ YearnV2Multicaller.connect = function (address) {
62
+ return new YearnV2Multicaller(address);
63
+ };
42
64
  YearnV2Multicaller.prototype.deposit = function (amount, recipient) {
43
65
  return {
44
66
  target: this._address,
@@ -54,3 +76,61 @@ var YearnV2Multicaller = /** @class */ (function () {
54
76
  return YearnV2Multicaller;
55
77
  }());
56
78
  exports.YearnV2Multicaller = YearnV2Multicaller;
79
+ var YearnV2Strategies = /** @class */ (function () {
80
+ function YearnV2Strategies() {
81
+ }
82
+ YearnV2Strategies.underlyingToYearn = function (data, network, yearnVault, underlyingAmount) {
83
+ var calls = [];
84
+ var vaultParams = contracts_1.contractParams[yearnVault];
85
+ var yearnToken = vaultParams.shareToken;
86
+ var yearnParams = token_1.supportedTokens[yearnToken];
87
+ if (yearnParams.type === tokenType_1.TokenType.YEARN_VAULT) {
88
+ if (data.underlyingToken !==
89
+ token_1.tokenDataByNetwork[network][yearnParams.underlying]) {
90
+ // This should be a pathfinder call
91
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapExactTokensForTokens(underlyingAmount, 0, [
92
+ data.underlyingToken,
93
+ token_1.tokenDataByNetwork[network][yearnParams.underlying]
94
+ ], constants_1.ADDRESS_0X0, Math.floor(new Date().getTime() / 1000) + 3600));
95
+ }
96
+ }
97
+ else if (yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP ||
98
+ yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP) {
99
+ var curveTokenParams = token_1.supportedTokens[yearnParams.underlying];
100
+ var curvePool = curveTokenParams.pool;
101
+ calls = curve_1.CurveStrategies.underlyingToCurveLP(data, network, curvePool, underlyingAmount);
102
+ }
103
+ else {
104
+ throw new Error("Yearn vault type unknown");
105
+ }
106
+ calls.push(YearnV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network][yearnVault]]).deposit());
107
+ };
108
+ YearnV2Strategies.yearnToUnderlying = function (data, network, yearnVault, yearnSharesAmount) {
109
+ var calls = [];
110
+ var vaultParams = contracts_1.contractParams[yearnVault];
111
+ var yearnToken = vaultParams.shareToken;
112
+ var yearnParams = token_1.supportedTokens[yearnToken];
113
+ calls.push(YearnV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network][yearnVault]]).withdraw(yearnSharesAmount));
114
+ if (yearnParams.type === tokenType_1.TokenType.YEARN_VAULT) {
115
+ if (data.underlyingToken !==
116
+ token_1.tokenDataByNetwork[network][yearnParams.underlying]) {
117
+ // This should be a pathfinder call
118
+ calls.push(uniswapV2_1.UniswapV2Multicaller.connect(data.adapters[contracts_1.contractsByNetwork[network].UNISWAP_V2_ROUTER]).swapAllTokensForTokens(0, [
119
+ token_1.tokenDataByNetwork[network][yearnParams.underlying],
120
+ data.underlyingToken
121
+ ], Math.floor(new Date().getTime() / 1000) + 3600));
122
+ }
123
+ }
124
+ else if (yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP ||
125
+ yearnParams.type === tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP) {
126
+ var curveTokenParams = token_1.supportedTokens[yearnParams.underlying];
127
+ var curvePool = curveTokenParams.pool;
128
+ calls = __spreadArray(__spreadArray([], calls, true), curve_1.CurveStrategies.allCurveLPToUnderlying(data, network, curvePool), true);
129
+ }
130
+ else {
131
+ throw new Error("Yearn vault type unknown");
132
+ }
133
+ };
134
+ return YearnV2Strategies;
135
+ }());
136
+ exports.YearnV2Strategies = YearnV2Strategies;
@@ -1,7 +1,7 @@
1
1
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
3
- import { ConvexPoolContract } from "../contracts/contracts";
4
- import { CurveLPToken } from "./curveLP";
2
+ import type { TokenBase } from "./token";
3
+ import type { ConvexPoolContract } from "../contracts/contracts";
4
+ import type { CurveLPToken } from "./curveLP";
5
5
  import { TokenType } from "./tokenType";
6
6
  export declare type ConvexLPToken = "cvx3Crv" | "cvxsteCRV" | "cvxFRAX3CRV" | "cvxLUSD3CRV" | "cvxcrvPlain3andSUSD" | "cvxgusd3CRV";
7
7
  export declare type ConvexStakedPhantomToken = "stkcvx3Crv" | "stkcvxsteCRV" | "stkcvxFRAX3CRV" | "stkcvxLUSD3CRV" | "stkcvxcrvPlain3andSUSD" | "stkcvxgusd3CRV";
@@ -1,7 +1,8 @@
1
+ import { BigNumber } from "ethers";
2
+ import type { CurvePoolContract } from "src/contracts/contracts";
1
3
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { SupportedToken, TokenBase } from "./token";
4
+ import type { SupportedToken, TokenBase } from "./token";
3
5
  import { PartialRecord } from "../utils/types";
4
- import { BigNumber } from "ethers";
5
6
  import { TokenType } from "./tokenType";
6
7
  export declare type CurveLPToken = "3Crv" | "steCRV" | "FRAX3CRV" | "LUSD3CRV" | "crvPlain3andSUSD" | "gusd3CRV";
7
8
  export declare type CurveLPTokenData = {
@@ -9,11 +10,15 @@ export declare type CurveLPTokenData = {
9
10
  type: TokenType.CURVE_LP;
10
11
  swapActions?: Array<TradeAction>;
11
12
  lpActions: Array<TradeAction>;
13
+ pool: CurvePoolContract;
14
+ wrapper?: CurvePoolContract;
12
15
  } & TokenBase;
13
16
  export declare type MetaCurveLPTokenData = {
14
17
  symbol: CurveLPToken;
15
18
  type: TokenType.META_CURVE_LP;
16
19
  lpActions: Array<TradeAction>;
20
+ pool: CurvePoolContract;
21
+ wrapper?: CurvePoolContract;
17
22
  } & TokenBase;
18
23
  export declare const Curve3CrvUnderlyingTokenIndex: PartialRecord<SupportedToken, BigNumber>;
19
24
  export declare const curveTokens: Record<CurveLPToken, CurveLPTokenData | MetaCurveLPTokenData>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.curveTokens = exports.Curve3CrvUnderlyingTokenIndex = void 0;
4
- var tradeTypes_1 = require("../pathfinder/tradeTypes");
5
4
  var ethers_1 = require("ethers");
5
+ var tradeTypes_1 = require("../pathfinder/tradeTypes");
6
6
  var tokenType_1 = require("./tokenType");
7
7
  exports.Curve3CrvUnderlyingTokenIndex = {
8
8
  DAI: ethers_1.BigNumber.from(0),
@@ -16,6 +16,7 @@ exports.curveTokens = {
16
16
  decimals: 18,
17
17
  symbol: "3Crv",
18
18
  type: tokenType_1.TokenType.CURVE_LP,
19
+ pool: "CURVE_3CRV_POOL",
19
20
  lpActions: [
20
21
  {
21
22
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -39,6 +40,7 @@ exports.curveTokens = {
39
40
  decimals: 18,
40
41
  symbol: "steCRV",
41
42
  type: tokenType_1.TokenType.CURVE_LP,
43
+ pool: "CURVE_STETH_GATEWAY",
42
44
  lpActions: [
43
45
  {
44
46
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -62,6 +64,8 @@ exports.curveTokens = {
62
64
  decimals: 18,
63
65
  symbol: "crvPlain3andSUSD",
64
66
  type: tokenType_1.TokenType.CURVE_LP,
67
+ pool: "CURVE_SUSD_POOL",
68
+ wrapper: "CURVE_SUSD_DEPOSIT",
65
69
  lpActions: [
66
70
  {
67
71
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -86,6 +90,7 @@ exports.curveTokens = {
86
90
  decimals: 18,
87
91
  symbol: "FRAX3CRV",
88
92
  type: tokenType_1.TokenType.META_CURVE_LP,
93
+ pool: "CURVE_FRAX_POOL",
89
94
  lpActions: [
90
95
  {
91
96
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -109,6 +114,7 @@ exports.curveTokens = {
109
114
  decimals: 18,
110
115
  symbol: "LUSD3CRV",
111
116
  type: tokenType_1.TokenType.META_CURVE_LP,
117
+ pool: "CURVE_LUSD_POOL",
112
118
  lpActions: [
113
119
  {
114
120
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -122,6 +128,7 @@ exports.curveTokens = {
122
128
  decimals: 18,
123
129
  symbol: "gusd3CRV",
124
130
  type: tokenType_1.TokenType.META_CURVE_LP,
131
+ pool: "CURVE_GUSD_POOL",
125
132
  lpActions: [
126
133
  {
127
134
  type: tradeTypes_1.TradeType.CurveWithdrawLP,
@@ -1,5 +1,5 @@
1
- import { TokenBase } from "./token";
2
- import { TradeAction } from "../pathfinder/tradeTypes";
1
+ import type { TokenBase } from "./token";
2
+ import type { TradeAction } from "../pathfinder/tradeTypes";
3
3
  import { TokenType } from "./tokenType";
4
4
  export declare type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH";
5
5
  export declare type GearboxToken = "GEAR";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.gearTokens = void 0;
4
4
  var tokenType_1 = require("./tokenType");
5
5
  exports.gearTokens = {
6
- //GEARBOX
6
+ // GEARBOX
7
7
  dDAI: {
8
8
  name: "dDAI",
9
9
  decimals: 18,
@@ -1,5 +1,5 @@
1
1
  import { TradeAction } from "../pathfinder/tradeTypes";
2
- import { TokenBase } from "./token";
2
+ import type { TokenBase } from "./token";
3
3
  import { TokenType } from "./tokenType";
4
4
  export declare type NormalToken = "1INCH" | "AAVE" | "COMP" | "CRV" | "DPI" | "FEI" | "LINK" | "SNX" | "SUSHI" | "UNI" | "USDT" | "USDC" | "DAI" | "WETH" | "WBTC" | "YFI" | "STETH" | "FTM" | "CVX" | "FRAX" | "FXS" | "LDO" | "SPELL" | "LUSD" | "sUSD" | "GUSD" | "LUNA" | "LQTY";
5
5
  export declare type NormalTokenData = {