@gearbox-protocol/sdk 1.5.11 → 1.5.12

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.
@@ -1,13 +1,14 @@
1
1
  import { Provider } from "@ethersproject/abstract-provider";
2
- import { BigNumber, BigNumberish, Signer } from "ethers";
2
+ import { BigNumberish, Signer } from "ethers";
3
3
  import { NetworkType } from "../core/constants";
4
4
  import { CreditAccountData } from "../core/creditAccount";
5
5
  import { CreditManagerData } from "../core/creditManager";
6
6
  import { SupportedToken } from "../tokens/token";
7
7
  import { IPathFinder } from "../types";
8
- import { PathFinderOpenStrategyResult, PathFinderResult, SwapOperation } from "./core";
8
+ import { MultiCall, PathFinderCloseResult, PathFinderOpenStrategyResult, PathFinderResult, SwapOperation } from "./core";
9
9
  export interface CloseResult {
10
10
  amount: BigNumberish;
11
+ calls: Array<MultiCall>;
11
12
  gasUsage: BigNumberish;
12
13
  }
13
14
  export declare class PathFinder {
@@ -18,7 +19,27 @@ export declare class PathFinder {
18
19
  constructor(address: string, provider: Signer | Provider, network?: NetworkType, connectors?: Array<SupportedToken>);
19
20
  findAllSwaps(creditAccount: CreditAccountData, swapOperation: SwapOperation, tokenIn: SupportedToken | string, tokenOut: SupportedToken | string, amount: BigNumberish, slippage: number): Promise<Array<PathFinderResult>>;
20
21
  findOneTokenPath(creditAccount: CreditAccountData, tokenIn: SupportedToken | string, tokenOut: SupportedToken | string, amount: BigNumberish, slippage: number): Promise<PathFinderResult>;
22
+ /**
23
+ * @dev Finds the best path for opening credit account and converting all NORMAL tokens and LP token in the way to TARGET
24
+ * @param cm CreditManagerData which represents credit manager you want to use to open credit account
25
+ * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
26
+ * if you open an USDC credit account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
27
+ * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
28
+ *
29
+ * @param target Address of symbol of desired token
30
+ * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
31
+ * @returns PathFinderOpenStrategyResult which
32
+ */
21
33
  findOpenStrategyPath(cm: CreditManagerData, expectedBalances: Record<SupportedToken | string, BigNumberish>, target: SupportedToken | string, slippage: number): Promise<PathFinderOpenStrategyResult>;
22
- findBestClosePath(creditAccount: CreditAccountData, slippage: number): Promise<BigNumber>;
34
+ /**
35
+ * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
36
+ * Can bu used for closing credit account and for liquidations as well.
37
+ * @param creditAccount CreditAccountData object used for close path computation
38
+ * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
39
+ * @return The best option in PathFinderCloseResult format, which
40
+ * - underlyingBalance - total balance of underlying token
41
+ * - calls - list of calls which should be done to swap & unwrap everything to underlying token
42
+ */
43
+ findBestClosePath(creditAccount: CreditAccountData, slippage: number): Promise<PathFinderCloseResult>;
23
44
  static compare(r1: CloseResult, r2: CloseResult, gasPriceRAY: BigNumberish): CloseResult;
24
45
  }
@@ -74,7 +74,6 @@ var PathFinder = /** @class */ (function () {
74
74
  results = _a.sent();
75
75
  return [2 /*return*/, results.map(function (r) { return ({
76
76
  amount: ethers_1.BigNumber.from(r.amount),
77
- gasUsage: r.gasUsage.toNumber(),
78
77
  calls: r.calls,
79
78
  }); })];
80
79
  }
@@ -102,6 +101,17 @@ var PathFinder = /** @class */ (function () {
102
101
  });
103
102
  });
104
103
  };
104
+ /**
105
+ * @dev Finds the best path for opening credit account and converting all NORMAL tokens and LP token in the way to TARGET
106
+ * @param cm CreditManagerData which represents credit manager you want to use to open credit account
107
+ * @param expectedBalances Expected balances which would be on account accounting also debt. For example,
108
+ * if you open an USDC credit account, borrow 50_000 USDC and provide 10 WETH and 10_USDC as collateral
109
+ * from your own funds, expectedBalances should be: { "USDC": 60_000 * (10**6), "<address of WETH>": WAD.mul(10) }
110
+ *
111
+ * @param target Address of symbol of desired token
112
+ * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
113
+ * @returns PathFinderOpenStrategyResult which
114
+ */
105
115
  PathFinder.prototype.findOpenStrategyPath = function (cm, expectedBalances, target, slippage) {
106
116
  return __awaiter(this, void 0, void 0, function () {
107
117
  var targetAddr, expectedBalancesAddr, balances, result, balancesAfter;
@@ -135,6 +145,15 @@ var PathFinder = /** @class */ (function () {
135
145
  });
136
146
  });
137
147
  };
148
+ /**
149
+ * @dev Finds the path to swap / withdraw all assets from CreditAccount into underlying asset
150
+ * Can bu used for closing credit account and for liquidations as well.
151
+ * @param creditAccount CreditAccountData object used for close path computation
152
+ * @param slippage Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
153
+ * @return The best option in PathFinderCloseResult format, which
154
+ * - underlyingBalance - total balance of underlying token
155
+ * - calls - list of calls which should be done to swap & unwrap everything to underlying token
156
+ */
138
157
  PathFinder.prototype.findBestClosePath = function (creditAccount, slippage) {
139
158
  return __awaiter(this, void 0, void 0, function () {
140
159
  var loopsPerTx, pathOptions, requests, results, bestResult;
@@ -156,8 +175,12 @@ var PathFinder = /** @class */ (function () {
156
175
  }, {
157
176
  amount: ethers_1.BigNumber.from(0),
158
177
  gasUsage: 0,
178
+ calls: [],
159
179
  });
160
- return [2 /*return*/, ethers_1.BigNumber.from(bestResult.amount)];
180
+ return [2 /*return*/, {
181
+ underlyingBalance: ethers_1.BigNumber.from(bestResult.amount).add(creditAccount.allBalances[creditAccount.underlyingToken.toLowerCase()]),
182
+ calls: bestResult.calls,
183
+ }];
161
184
  }
162
185
  });
163
186
  });
@@ -8,10 +8,12 @@ describe("PathFinder test", function () {
8
8
  var r1 = {
9
9
  amount: 2000,
10
10
  gasUsage: 1000,
11
+ calls: [],
11
12
  };
12
13
  var r2 = {
13
14
  amount: 3000,
14
15
  gasUsage: 2000,
16
+ calls: [],
15
17
  };
16
18
  var result = pathfinder_1.PathFinder.compare(r1, r2, constants_1.RAY);
17
19
  (0, chai_1.expect)(result).to.be.eql(r2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.5.11",
3
+ "version": "1.5.12",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",