@gearbox-protocol/sdk 1.5.9 → 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 {
|
|
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
|
-
|
|
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*/,
|
|
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/lib/tokens/token.d.ts
CHANGED
|
@@ -19,3 +19,4 @@ export declare const tokenDataByNetwork: Record<NetworkType, Record<SupportedTok
|
|
|
19
19
|
export declare const tokenSymbolByAddress: Record<string, SupportedToken>;
|
|
20
20
|
export declare const isSupportedToken: (t: unknown) => t is SupportedToken;
|
|
21
21
|
export declare const isLPToken: (t: unknown) => t is LPTokens;
|
|
22
|
+
export declare function getDecimals(token: SupportedToken | string): number;
|
package/lib/tokens/token.js
CHANGED
|
@@ -11,10 +11,11 @@ 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.isLPToken = exports.isSupportedToken = exports.tokenSymbolByAddress = exports.tokenDataByNetwork = exports.supportedTokens = exports.lpTokens = void 0;
|
|
14
|
+
exports.getDecimals = 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 convex_1 = require("./convex");
|
|
17
17
|
var curveLP_1 = require("./curveLP");
|
|
18
|
+
var decimals_1 = require("./decimals");
|
|
18
19
|
var gear_1 = require("./gear");
|
|
19
20
|
var normal_1 = require("./normal");
|
|
20
21
|
var yearn_1 = require("./yearn");
|
|
@@ -171,3 +172,14 @@ var isLPToken = function (t) {
|
|
|
171
172
|
return typeof t === "string" && !!exports.lpTokens[t];
|
|
172
173
|
};
|
|
173
174
|
exports.isLPToken = isLPToken;
|
|
175
|
+
function getDecimals(token) {
|
|
176
|
+
var dec = decimals_1.decimals[token];
|
|
177
|
+
if (dec)
|
|
178
|
+
return dec;
|
|
179
|
+
dec = decimals_1.decimals[exports.tokenSymbolByAddress[token.toLowerCase()]];
|
|
180
|
+
if (!dec) {
|
|
181
|
+
throw new Error("Decimals for ".concat(token, " not found"));
|
|
182
|
+
}
|
|
183
|
+
return dec;
|
|
184
|
+
}
|
|
185
|
+
exports.getDecimals = getDecimals;
|
package/lib/utils/multicall.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
2
|
import { Multicall2 } from "../types";
|
|
3
3
|
export interface CallData<T extends ethers.utils.Interface> {
|
|
4
4
|
method: keyof T["functions"];
|
|
@@ -15,7 +15,7 @@ export declare class MultiCallContract<T extends ethers.utils.Interface> {
|
|
|
15
15
|
private readonly _address;
|
|
16
16
|
private readonly _interface;
|
|
17
17
|
protected _multiCall: Multicall2;
|
|
18
|
-
constructor(address: string, intrerface: T, provider: ethers.providers.Provider);
|
|
18
|
+
constructor(address: string, intrerface: T, provider: ethers.providers.Provider | Signer);
|
|
19
19
|
call<R extends Array<any>>(data: Array<CallData<T>>): Promise<R>;
|
|
20
20
|
get address(): string;
|
|
21
21
|
get interface(): T;
|