@gearbox-protocol/sdk 1.3.0 → 1.3.1

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.
package/lib/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export * from "./core/tokenDistributor";
14
14
  export * from "./core/transactions";
15
15
  export * from "./oracles/oracles";
16
16
  export * from "./oracles/priceFeeds";
17
- export * from "./pathfinder/trade";
18
17
  export * from "./payload/creditAccount";
19
18
  export * from "./payload/creditManager";
20
19
  export * from "./payload/creditSession";
package/lib/index.js CHANGED
@@ -31,7 +31,6 @@ __exportStar(require("./core/tokenDistributor"), exports);
31
31
  __exportStar(require("./core/transactions"), exports);
32
32
  __exportStar(require("./oracles/oracles"), exports);
33
33
  __exportStar(require("./oracles/priceFeeds"), exports);
34
- __exportStar(require("./pathfinder/trade"), exports);
35
34
  __exportStar(require("./payload/creditAccount"), exports);
36
35
  __exportStar(require("./payload/creditManager"), exports);
37
36
  __exportStar(require("./payload/creditSession"), exports);
@@ -4,7 +4,7 @@ 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 = {
6
6
  symbol: NormalToken;
7
- type: TokenType.CONNECTOR | TokenType.NORMAL_TOKEN;
7
+ type: TokenType.NORMAL_TOKEN;
8
8
  swapActions: Array<TradeAction>;
9
9
  lpActions?: Array<TradeAction>;
10
10
  } & TokenBase;
@@ -88,7 +88,7 @@ exports.normalTokens = {
88
88
  name: "DAI",
89
89
  decimals: 18,
90
90
  symbol: "DAI",
91
- type: tokenType_1.TokenType.CONNECTOR,
91
+ type: tokenType_1.TokenType.NORMAL_TOKEN,
92
92
  swapActions: [
93
93
  {
94
94
  type: tradeTypes_1.TradeType.UniswapV3Swap,
@@ -243,7 +243,7 @@ exports.normalTokens = {
243
243
  name: "USDC",
244
244
  decimals: 6,
245
245
  symbol: "USDC",
246
- type: tokenType_1.TokenType.CONNECTOR,
246
+ type: tokenType_1.TokenType.NORMAL_TOKEN,
247
247
  swapActions: [
248
248
  {
249
249
  type: tradeTypes_1.TradeType.UniswapV3Swap,
@@ -332,7 +332,7 @@ exports.normalTokens = {
332
332
  name: "WBTC",
333
333
  decimals: 8,
334
334
  symbol: "WBTC",
335
- type: tokenType_1.TokenType.CONNECTOR,
335
+ type: tokenType_1.TokenType.NORMAL_TOKEN,
336
336
  swapActions: [
337
337
  {
338
338
  type: tradeTypes_1.TradeType.UniswapV3Swap,
@@ -359,7 +359,7 @@ exports.normalTokens = {
359
359
  name: "WETH",
360
360
  decimals: 18,
361
361
  symbol: "WETH",
362
- type: tokenType_1.TokenType.CONNECTOR,
362
+ type: tokenType_1.TokenType.NORMAL_TOKEN,
363
363
  swapActions: [
364
364
  {
365
365
  type: tradeTypes_1.TradeType.UniswapV3Swap,
@@ -1,12 +1,11 @@
1
1
  export declare enum TokenType {
2
- CONNECTOR = 0,
3
- NORMAL_TOKEN = 1,
4
- CURVE_LP = 2,
5
- META_CURVE_LP = 3,
6
- YEARN_VAULT = 4,
7
- YEARN_VAULT_OF_CURVE_LP = 5,
8
- YEARN_VAULT_OF_META_CURVE_LP = 6,
9
- CONVEX_LP_TOKEN = 7,
10
- CONVEX_STAKED_PHANTOM_TOKEN = 8,
11
- DIESEL_LP_TOKEN = 9
2
+ NORMAL_TOKEN = 0,
3
+ CURVE_LP = 1,
4
+ META_CURVE_LP = 2,
5
+ YEARN_VAULT = 3,
6
+ YEARN_VAULT_OF_CURVE_LP = 4,
7
+ YEARN_VAULT_OF_META_CURVE_LP = 5,
8
+ CONVEX_LP_TOKEN = 6,
9
+ CONVEX_STAKED_PHANTOM_TOKEN = 7,
10
+ DIESEL_LP_TOKEN = 8
12
11
  }
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenType = void 0;
4
4
  var TokenType;
5
5
  (function (TokenType) {
6
- TokenType[TokenType["CONNECTOR"] = 0] = "CONNECTOR";
7
- TokenType[TokenType["NORMAL_TOKEN"] = 1] = "NORMAL_TOKEN";
8
- TokenType[TokenType["CURVE_LP"] = 2] = "CURVE_LP";
9
- TokenType[TokenType["META_CURVE_LP"] = 3] = "META_CURVE_LP";
10
- TokenType[TokenType["YEARN_VAULT"] = 4] = "YEARN_VAULT";
11
- TokenType[TokenType["YEARN_VAULT_OF_CURVE_LP"] = 5] = "YEARN_VAULT_OF_CURVE_LP";
12
- TokenType[TokenType["YEARN_VAULT_OF_META_CURVE_LP"] = 6] = "YEARN_VAULT_OF_META_CURVE_LP";
13
- TokenType[TokenType["CONVEX_LP_TOKEN"] = 7] = "CONVEX_LP_TOKEN";
14
- TokenType[TokenType["CONVEX_STAKED_PHANTOM_TOKEN"] = 8] = "CONVEX_STAKED_PHANTOM_TOKEN";
15
- TokenType[TokenType["DIESEL_LP_TOKEN"] = 9] = "DIESEL_LP_TOKEN";
6
+ // CONNECTOR,
7
+ TokenType[TokenType["NORMAL_TOKEN"] = 0] = "NORMAL_TOKEN";
8
+ TokenType[TokenType["CURVE_LP"] = 1] = "CURVE_LP";
9
+ TokenType[TokenType["META_CURVE_LP"] = 2] = "META_CURVE_LP";
10
+ TokenType[TokenType["YEARN_VAULT"] = 3] = "YEARN_VAULT";
11
+ TokenType[TokenType["YEARN_VAULT_OF_CURVE_LP"] = 4] = "YEARN_VAULT_OF_CURVE_LP";
12
+ TokenType[TokenType["YEARN_VAULT_OF_META_CURVE_LP"] = 5] = "YEARN_VAULT_OF_META_CURVE_LP";
13
+ TokenType[TokenType["CONVEX_LP_TOKEN"] = 6] = "CONVEX_LP_TOKEN";
14
+ TokenType[TokenType["CONVEX_STAKED_PHANTOM_TOKEN"] = 7] = "CONVEX_STAKED_PHANTOM_TOKEN";
15
+ TokenType[TokenType["DIESEL_LP_TOKEN"] = 8] = "DIESEL_LP_TOKEN";
16
16
  })(TokenType = exports.TokenType || (exports.TokenType = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,3 +0,0 @@
1
- import { NetworkType } from "../core/constants";
2
- export declare type PathFinderContracts = "PATH_FINDER" | "CONVEX_PATH_FINDER";
3
- export declare const pathFindersByNetwork: Record<NetworkType, Record<PathFinderContracts, string>>;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pathFindersByNetwork = void 0;
4
- exports.pathFindersByNetwork = {
5
- Mainnet: {
6
- // PATH_FINDER
7
- PATH_FINDER: "",
8
- CONVEX_PATH_FINDER: "",
9
- },
10
- Goerli: {
11
- // PATH_FINDER
12
- PATH_FINDER: "",
13
- CONVEX_PATH_FINDER: "",
14
- },
15
- };
@@ -1,4 +0,0 @@
1
- import type { LPWithdrawPathFinder, Path } from "./path";
2
- export declare class ConvexLPPathFinder implements LPWithdrawPathFinder {
3
- findWithdrawPaths(p: Path): Promise<Array<Path>>;
4
- }
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ConvexLPPathFinder = void 0;
40
- var convex_1 = require("../tokens/convex");
41
- var mappers_1 = require("../utils/mappers");
42
- var ConvexLPPathFinder = /** @class */ (function () {
43
- function ConvexLPPathFinder() {
44
- }
45
- // eslint-disable-next-line class-methods-use-this
46
- ConvexLPPathFinder.prototype.findWithdrawPaths = function (p) {
47
- return __awaiter(this, void 0, void 0, function () {
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()];
72
- });
73
- });
74
- };
75
- return ConvexLPPathFinder;
76
- }());
77
- exports.ConvexLPPathFinder = ConvexLPPathFinder;
@@ -1,9 +0,0 @@
1
- import { CurvePoolContract } from "../contracts/contracts";
2
- import { CurveLPToken } from "../tokens/curveLP";
3
- import type { LPWithdrawPathFinder, Path } from "./path";
4
- export declare class CurvePathFinder implements LPWithdrawPathFinder {
5
- lpToken: CurveLPToken;
6
- contract: CurvePoolContract;
7
- constructor(token: CurveLPToken);
8
- findWithdrawPaths(p: Path): Promise<Array<Path>>;
9
- }
@@ -1,95 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.CurvePathFinder = void 0;
40
- var contracts_1 = require("../contracts/contracts");
41
- var curveLP_1 = require("../tokens/curveLP");
42
- var types_1 = require("../types");
43
- var multicall_1 = require("../utils/multicall");
44
- var tradeTypes_1 = require("./tradeTypes");
45
- var CurvePathFinder = /** @class */ (function () {
46
- function CurvePathFinder(token) {
47
- this.lpToken = token;
48
- var curvePools = curveLP_1.curveTokens[this.lpToken].lpActions.filter(function (a) { return a.type === tradeTypes_1.TradeType.CurveWithdrawLP; });
49
- if (curvePools.length !== 1)
50
- throw new Error("Cant find Withdrawer");
51
- this.contract = curvePools[0].contract;
52
- var wrapper = contracts_1.contractParams[curvePools[0].contract].wrapper;
53
- if (wrapper) {
54
- this.contract = wrapper;
55
- }
56
- }
57
- CurvePathFinder.prototype.findWithdrawPaths = function (p) {
58
- return __awaiter(this, void 0, void 0, function () {
59
- var coins, nCoins, lpBalance, multiCallContract, data, i, balances, paths, i, newPath;
60
- return __generator(this, function (_a) {
61
- switch (_a.label) {
62
- case 0:
63
- coins = contracts_1.contractParams[this.contract].tokens;
64
- nCoins = coins.length;
65
- lpBalance = p.popBalance(this.lpToken);
66
- multiCallContract = new multicall_1.MultiCallContract(contracts_1.contractsByAddress[this.contract], types_1.ICurvePool__factory.createInterface(), p.provider);
67
- data = [];
68
- for (i = 0; i < nCoins; i += 1) {
69
- data.push({
70
- method: "calc_withdraw_one_coin(uint256,int128)",
71
- params: [lpBalance, i],
72
- });
73
- }
74
- return [4 /*yield*/, multiCallContract.call(data)];
75
- case 1:
76
- balances = _a.sent();
77
- console.debug(balances);
78
- paths = [];
79
- for (i = 0; i < nCoins; i += 1) {
80
- newPath = p.clone();
81
- // newPath.balances[coins[i]] = newPath.balances[coins[i]].add(balances[i]);
82
- // newPath.calls.push({
83
- // targetContract: contractsByNetwork[p.networkType][this.contract],
84
- // callData: ICurveV1Adapter__factory.createInterface().encodeFunctionData("remove_all_liquidity_one_coin", [i])
85
- // })
86
- paths.push(newPath);
87
- }
88
- return [2 /*return*/, paths];
89
- }
90
- });
91
- });
92
- };
93
- return CurvePathFinder;
94
- }());
95
- exports.CurvePathFinder = CurvePathFinder;
@@ -1,34 +0,0 @@
1
- import { BigNumber, ethers } from "ethers";
2
- import { NetworkType } from "../core/constants";
3
- import { CreditAccountData } from "../core/creditAccount";
4
- import { CreditManagerData } from "../core/creditManager";
5
- import { MultiCall } from "../core/multicall";
6
- import { SupportedToken } from "../tokens/token";
7
- import { PartialRecord } from "../utils/types";
8
- export declare class Path {
9
- readonly calls: Array<MultiCall>;
10
- readonly balances: PartialRecord<SupportedToken, BigNumber>;
11
- readonly underlying: SupportedToken;
12
- readonly creditManager: CreditManagerData;
13
- readonly creditAccount: CreditAccountData;
14
- readonly networkType: NetworkType;
15
- readonly provider: ethers.providers.Provider;
16
- totalGasLimit: number;
17
- constructor(opts: {
18
- balances: PartialRecord<SupportedToken, BigNumber>;
19
- underlying: SupportedToken;
20
- creditManager: CreditManagerData;
21
- creditAccount: CreditAccountData;
22
- networkType: NetworkType;
23
- provider: ethers.providers.Provider;
24
- totalGasLimit: number;
25
- });
26
- popBalance(token: SupportedToken): BigNumber;
27
- private static comparedByPriority;
28
- static findBestPath(creditAccount: CreditAccountData, creditManager: CreditManagerData, provider: ethers.providers.Provider): Promise<void>;
29
- withdrawTokens(): Promise<Array<Path>>;
30
- clone(): Path;
31
- }
32
- export interface LPWithdrawPathFinder {
33
- findWithdrawPaths: (p: Path) => Promise<Array<Path>>;
34
- }
@@ -1,178 +0,0 @@
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
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (_) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- Object.defineProperty(exports, "__esModule", { value: true });
50
- exports.Path = void 0;
51
- var ethers_1 = require("ethers");
52
- var token_1 = require("../tokens/token");
53
- var tokenType_1 = require("../tokens/tokenType");
54
- var network_1 = require("../utils/network");
55
- var convexLP_1 = require("./convexLP");
56
- var curveLP_1 = require("./curveLP");
57
- var priority_1 = require("./priority");
58
- var yVault_1 = require("./yVault");
59
- var Path = /** @class */ (function () {
60
- function Path(opts) {
61
- this.calls = [];
62
- this.balances = opts.balances;
63
- this.underlying = opts.underlying;
64
- this.creditManager = opts.creditManager;
65
- this.creditAccount = opts.creditAccount;
66
- this.networkType = opts.networkType;
67
- this.provider = opts.provider;
68
- this.totalGasLimit = opts.totalGasLimit;
69
- }
70
- Path.prototype.popBalance = function (token) {
71
- var currentBalance = this.balances[token];
72
- if (currentBalance === undefined || currentBalance.gt(1))
73
- return ethers_1.BigNumber.from(0);
74
- this.balances[token] = ethers_1.BigNumber.from(1);
75
- return currentBalance.sub(1);
76
- };
77
- Path.comparedByPriority = function (_a, _b) {
78
- var tokenA = _a[0];
79
- var tokenB = _b[0];
80
- var priorityTokenA = priority_1.priority[token_1.supportedTokens[tokenA].type];
81
- var priorityTokenB = priority_1.priority[token_1.supportedTokens[tokenB].type];
82
- if (priorityTokenA > priorityTokenB) {
83
- return -1;
84
- }
85
- if (priorityTokenA < priorityTokenB) {
86
- return 1;
87
- }
88
- return 0;
89
- };
90
- Path.findBestPath = function (creditAccount, creditManager, provider) {
91
- return __awaiter(this, void 0, void 0, function () {
92
- var networkType, balances, initialPath, lpPaths;
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0: return [4 /*yield*/, (0, network_1.detectNetwork)(provider)];
96
- case 1:
97
- networkType = _a.sent();
98
- balances = Object.entries(creditAccount.balances)
99
- .map(function (_a) {
100
- var address = _a[0], balance = _a[1];
101
- return ({
102
- token: token_1.tokenSymbolByAddress[address.toLowerCase()],
103
- balance: balance,
104
- });
105
- })
106
- .filter(function (t) { return t.balance.gt(1); })
107
- .reduce(function (obj, curValue) {
108
- var _a;
109
- return (__assign(__assign({}, obj), (_a = {}, _a[curValue.token] = curValue.balance, _a)));
110
- }, {});
111
- initialPath = new Path({
112
- balances: balances,
113
- creditAccount: creditAccount,
114
- creditManager: creditManager,
115
- networkType: networkType,
116
- provider: provider,
117
- underlying: "DAI",
118
- totalGasLimit: 0,
119
- });
120
- return [4 /*yield*/, initialPath.withdrawTokens()];
121
- case 2:
122
- lpPaths = _a.sent();
123
- // const pathFinder = ISwapAggregator__factory.connect(
124
- // pathFindersByNetwork[networkType].PATH_FINDER,
125
- // provider,
126
- // );
127
- console.debug(lpPaths);
128
- return [2 /*return*/];
129
- }
130
- });
131
- });
132
- };
133
- Path.prototype.withdrawTokens = function () {
134
- return __awaiter(this, void 0, void 0, function () {
135
- var existingTokens, nextToken, lpPathFinder;
136
- return __generator(this, function (_a) {
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");
168
- }
169
- return [2 /*return*/, lpPathFinder.findWithdrawPaths(this)];
170
- });
171
- });
172
- };
173
- Path.prototype.clone = function () {
174
- return Object.assign(Object.create(Object.getPrototypeOf(this)), this);
175
- };
176
- return Path;
177
- }());
178
- exports.Path = Path;
@@ -1,2 +0,0 @@
1
- import { TokenType } from "../tokens/tokenType";
2
- export declare const priority: Record<TokenType, number>;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.priority = void 0;
5
- var tokenType_1 = require("../tokens/tokenType");
6
- exports.priority = (_a = {},
7
- _a[tokenType_1.TokenType.CONNECTOR] = 1,
8
- _a[tokenType_1.TokenType.NORMAL_TOKEN] = 2,
9
- _a[tokenType_1.TokenType.CURVE_LP] = 3,
10
- _a[tokenType_1.TokenType.YEARN_VAULT] = 3,
11
- _a[tokenType_1.TokenType.META_CURVE_LP] = 4,
12
- _a[tokenType_1.TokenType.YEARN_VAULT_OF_CURVE_LP] = 4,
13
- _a[tokenType_1.TokenType.CONVEX_LP_TOKEN] = 5,
14
- _a[tokenType_1.TokenType.YEARN_VAULT_OF_META_CURVE_LP] = 5,
15
- _a[tokenType_1.TokenType.CONVEX_STAKED_PHANTOM_TOKEN] = 5,
16
- _a[tokenType_1.TokenType.DIESEL_LP_TOKEN] = 6,
17
- _a);
@@ -1,34 +0,0 @@
1
- import { BigNumber, BytesLike } from "ethers";
2
- import { SwapType } from "./tradeTypes";
3
- export interface CloseTradePath {
4
- path: Array<string>;
5
- amountOutMin: BigNumber;
6
- }
7
- export declare class TradePath {
8
- readonly swapType: SwapType;
9
- readonly amount: BigNumber;
10
- readonly rate: BigNumber;
11
- readonly path: Array<string>;
12
- readonly expectedAmount: BigNumber;
13
- readonly pathUniV3: BytesLike | undefined;
14
- readonly i: number | undefined;
15
- readonly j: number | undefined;
16
- readonly operationName: string | undefined;
17
- constructor(params: {
18
- swapType: SwapType;
19
- amount: BigNumber;
20
- path: Array<string>;
21
- expectedAmount: BigNumber;
22
- pathUniV3?: BytesLike;
23
- i?: number;
24
- j?: number;
25
- operationName?: string;
26
- });
27
- getExpectedAmountWithSlippage(slippage: number): BigNumber;
28
- getAmountInMax(slippage: number): BigNumber;
29
- getAmountOutMin(slippage: number): BigNumber;
30
- get from(): string;
31
- get to(): string;
32
- getFromAmount(slippage: number): BigNumber;
33
- getToAmount(slippage: number): BigNumber;
34
- }
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TradePath = void 0;
4
- var constants_1 = require("../core/constants");
5
- var tradeTypes_1 = require("./tradeTypes");
6
- var TradePath = /** @class */ (function () {
7
- function TradePath(params) {
8
- this.swapType = params.swapType;
9
- this.amount = params.amount;
10
- this.path = params.path;
11
- this.expectedAmount = params.expectedAmount;
12
- this.pathUniV3 = params.pathUniV3;
13
- this.rate =
14
- params.swapType !== tradeTypes_1.SwapType.ExactInput
15
- ? params.expectedAmount.mul(constants_1.WAD).div(params.amount)
16
- : constants_1.WAD.mul(params.amount).div(params.expectedAmount);
17
- this.i = params.i;
18
- this.j = params.j;
19
- this.operationName = params.operationName;
20
- }
21
- TradePath.prototype.getExpectedAmountWithSlippage = function (slippage) {
22
- return this.swapType === tradeTypes_1.SwapType.ExactInput
23
- ? this.getAmountOutMin(slippage)
24
- : this.getAmountInMax(slippage);
25
- };
26
- TradePath.prototype.getAmountInMax = function (slippage) {
27
- return this.expectedAmount
28
- .mul(constants_1.PERCENTAGE_FACTOR + slippage)
29
- .div(constants_1.PERCENTAGE_FACTOR);
30
- };
31
- TradePath.prototype.getAmountOutMin = function (slippage) {
32
- return this.expectedAmount
33
- .mul(constants_1.PERCENTAGE_FACTOR)
34
- .div(constants_1.PERCENTAGE_FACTOR + slippage);
35
- };
36
- Object.defineProperty(TradePath.prototype, "from", {
37
- get: function () {
38
- return this.path[0];
39
- },
40
- enumerable: false,
41
- configurable: true
42
- });
43
- Object.defineProperty(TradePath.prototype, "to", {
44
- get: function () {
45
- return this.path[this.path.length - 1];
46
- },
47
- enumerable: false,
48
- configurable: true
49
- });
50
- TradePath.prototype.getFromAmount = function (slippage) {
51
- return this.swapType === tradeTypes_1.SwapType.ExactInput
52
- ? this.amount
53
- : this.getExpectedAmountWithSlippage(slippage);
54
- };
55
- TradePath.prototype.getToAmount = function (slippage) {
56
- return this.swapType === tradeTypes_1.SwapType.ExactOutput
57
- ? this.amount
58
- : this.getExpectedAmountWithSlippage(slippage);
59
- };
60
- return TradePath;
61
- }());
62
- exports.TradePath = TradePath;
@@ -1,10 +0,0 @@
1
- import { CurveLPToken } from "../tokens/curveLP";
2
- import { NormalToken } from "../tokens/normal";
3
- import { YearnLPToken } from "../tokens/yearn";
4
- import type { LPWithdrawPathFinder, Path } from "./path";
5
- export declare class YearnVaultPathFinder implements LPWithdrawPathFinder {
6
- _vault: YearnLPToken;
7
- token: NormalToken | CurveLPToken;
8
- constructor(vault: YearnLPToken);
9
- findWithdrawPaths(path: Path): Promise<Array<Path>>;
10
- }
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.YearnVaultPathFinder = void 0;
40
- var ethers_1 = require("ethers");
41
- var token_1 = require("../tokens/token");
42
- var yearn_1 = require("../tokens/yearn");
43
- var types_1 = require("../types");
44
- var mappers_1 = require("../utils/mappers");
45
- var multicall_1 = require("../utils/multicall");
46
- var YearnVaultPathFinder = /** @class */ (function () {
47
- function YearnVaultPathFinder(vault) {
48
- this._vault = vault;
49
- var currentTokenData = yearn_1.yearnTokens[vault];
50
- // Yearn Vault only has one lp action
51
- this.token = currentTokenData.underlying;
52
- }
53
- // eslint-disable-next-line class-methods-use-this
54
- YearnVaultPathFinder.prototype.findWithdrawPaths = function (path) {
55
- return __awaiter(this, void 0, void 0, function () {
56
- var p, vaultBalances, vaultList, multicallData, prices, i, vault, vb, tokenAddress, adapterAddress, callData;
57
- return __generator(this, function (_a) {
58
- switch (_a.label) {
59
- case 0:
60
- p = path.clone();
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);
65
- if (currentBalance.gt(1)) {
66
- acc[typedVault] = {
67
- token: tokenData.underlying,
68
- balance: currentBalance,
69
- };
70
- }
71
- return acc;
72
- }, {});
73
- vaultList = Object.keys(vaultBalances);
74
- multicallData = vaultList
75
- .map(function (t) { return token_1.tokenDataByNetwork[p.networkType][t]; })
76
- .map(function (addr) { return ({
77
- address: addr,
78
- interface: types_1.IYVault__factory.createInterface(),
79
- method: "pricePerShare()",
80
- }); });
81
- return [4 /*yield*/, (0, multicall_1.multicall)(multicallData, p.provider)];
82
- case 1:
83
- prices = _a.sent();
84
- for (i = 0; i < vaultList.length; i += 1) {
85
- vault = vaultList[i];
86
- vb = vaultBalances[vault];
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]));
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 });
92
- }
93
- return [2 /*return*/, p.withdrawTokens()];
94
- }
95
- });
96
- });
97
- };
98
- return YearnVaultPathFinder;
99
- }());
100
- exports.YearnVaultPathFinder = YearnVaultPathFinder;