@gearbox-protocol/sdk 1.8.9 → 1.8.11

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.
@@ -33,6 +33,7 @@ exports.deployedContracts = {
33
33
  "0x2B16eA2D7a1b13d115d05B03Fd0E5984eFA0F18D": "DAI",
34
34
  "0x19e8293f46caE0770d608a3078EFb59f0B0166aa": "USDC",
35
35
  "0x9149A40293d0bc17f07DaFC7F6282b267D3C68C8": "WETH",
36
+ "0x70ba4442e9c76269f9f2c31c8884fc7880f40d4a": "wstETH",
36
37
  // GOERLI pools
37
38
  "0xEA7D5CaE79Cdf2E07E0aa7edfB1AF7A429Cb7513": "DAI",
38
39
  "0xF0A7BE2EB39bBbd55fc5597F93E01f62A790e587": "USDC",
@@ -1,4 +1,6 @@
1
1
  import { BigNumberish } from "ethers";
2
+ import { NetworkType } from "../core/constants";
3
+ import { CurveLPToken } from "../tokens/curveLP";
2
4
  export interface PathOption {
3
5
  target: string;
4
6
  option: number;
@@ -7,5 +9,7 @@ export interface PathOption {
7
9
  export declare type PathOptionSerie = Array<PathOption>;
8
10
  export declare class PathOptionFactory {
9
11
  static generatePathOptions(balances: Record<string, BigNumberish>, loopsInTx: number): Array<PathOptionSerie>;
12
+ static getCurvePools(balances: Record<string, BigNumberish>): Array<CurveLPToken>;
10
13
  static next(path: PathOptionSerie): PathOptionSerie;
14
+ static detectNetwork(underlying: string): NetworkType;
11
15
  }
@@ -23,25 +23,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.PathOptionFactory = void 0;
24
24
  var ethers_1 = require("ethers");
25
25
  var contracts_1 = require("../contracts/contracts");
26
+ var convex_1 = require("../tokens/convex");
26
27
  var curveLP_1 = require("../tokens/curveLP");
27
28
  var token_1 = require("../tokens/token");
29
+ var yearn_1 = require("../tokens/yearn");
28
30
  var PathOptionFactory = /** @class */ (function () {
29
31
  function PathOptionFactory() {
30
32
  }
31
33
  PathOptionFactory.generatePathOptions = function (balances, loopsInTx) {
32
- var curveSymbols = Object.keys(curveLP_1.curveTokens);
33
- var initPO = Object.entries(balances)
34
- .filter(function (_a) {
35
- var token = _a[0], balance = _a[1];
36
- return ethers_1.BigNumber.from(balance).gt(1) &&
37
- curveSymbols.includes(token_1.tokenSymbolByAddress[token.toLowerCase()]);
38
- })
39
- .map(function (_a) {
40
- var target = _a[0];
34
+ var curvePools = PathOptionFactory.getCurvePools(balances);
35
+ var network = PathOptionFactory.detectNetwork(Object.keys(balances)[0]);
36
+ var initPO = curvePools.map(function (symbol) {
41
37
  return {
42
- target: target,
38
+ target: token_1.tokenDataByNetwork[network][symbol],
43
39
  option: 0,
44
- totalOptions: contracts_1.contractParams[curveLP_1.curveTokens[token_1.tokenSymbolByAddress[target.toLowerCase()]].pool].tokens.length,
40
+ totalOptions: contracts_1.contractParams[curveLP_1.curveTokens[symbol].pool]
41
+ .tokens.length,
45
42
  };
46
43
  });
47
44
  var totalLoops = initPO.reduce(function (acc, item) { return acc * item.totalOptions; }, 1);
@@ -57,6 +54,61 @@ var PathOptionFactory = /** @class */ (function () {
57
54
  }
58
55
  return result;
59
56
  };
57
+ PathOptionFactory.getCurvePools = function (balances) {
58
+ var curveSymbols = Object.keys(curveLP_1.curveTokens);
59
+ var curvePools = Object.entries(balances)
60
+ .filter(function (_a) {
61
+ var balance = _a[1];
62
+ return ethers_1.BigNumber.from(balance).gt(1);
63
+ })
64
+ .map(function (_a) {
65
+ var token = _a[0];
66
+ return token_1.tokenSymbolByAddress[token.toLowerCase()];
67
+ })
68
+ .filter(function (symbol) { return curveSymbols.includes(symbol); });
69
+ var yearnCurveTokens = Object.entries(yearn_1.yearnTokens)
70
+ .filter(function (_a) {
71
+ var data = _a[1];
72
+ return curveSymbols.includes(data.underlying);
73
+ })
74
+ .map(function (_a) {
75
+ var token = _a[0];
76
+ return token;
77
+ });
78
+ var curvePoolsFromYearn = Object.entries(balances)
79
+ .filter(function (_a) {
80
+ var balance = _a[1];
81
+ return ethers_1.BigNumber.from(balance).gt(1);
82
+ })
83
+ .map(function (_a) {
84
+ var token = _a[0];
85
+ return token_1.tokenSymbolByAddress[token.toLowerCase()];
86
+ })
87
+ .filter(function (symbol) { return yearnCurveTokens.includes(symbol); })
88
+ .map(function (symbol) { return yearn_1.yearnTokens[symbol].underlying; });
89
+ var convexCurveTokens = Object.entries(convex_1.convexTokens)
90
+ .filter(function (_a) {
91
+ var data = _a[1];
92
+ return curveSymbols.includes(data.underlying);
93
+ })
94
+ .map(function (_a) {
95
+ var token = _a[0];
96
+ return token;
97
+ });
98
+ var curvePoolsFromConvex = Object.entries(balances)
99
+ .filter(function (_a) {
100
+ var balance = _a[1];
101
+ return ethers_1.BigNumber.from(balance).gt(1);
102
+ })
103
+ .map(function (_a) {
104
+ var token = _a[0];
105
+ return token_1.tokenSymbolByAddress[token.toLowerCase()];
106
+ })
107
+ .filter(function (symbol) { return convexCurveTokens.includes(symbol); })
108
+ .map(function (symbol) { return convex_1.convexTokens[symbol].underlying; });
109
+ var curveSet = new Set(__spreadArray(__spreadArray(__spreadArray([], curvePools, true), curvePoolsFromYearn, true), curvePoolsFromConvex, true));
110
+ return Array.from(curveSet.values());
111
+ };
60
112
  PathOptionFactory.next = function (path) {
61
113
  var newPath = __spreadArray([], path, true);
62
114
  for (var i = path.length - 1; i >= 0; i--) {
@@ -69,6 +121,11 @@ var PathOptionFactory = /** @class */ (function () {
69
121
  }
70
122
  throw new Error("Path options overflow");
71
123
  };
124
+ PathOptionFactory.detectNetwork = function (underlying) {
125
+ return token_1.tokenDataByNetwork.Mainnet[token_1.tokenSymbolByAddress[underlying.toLowerCase()]].toLowerCase() === underlying.toLowerCase()
126
+ ? "Mainnet"
127
+ : "Goerli";
128
+ };
72
129
  return PathOptionFactory;
73
130
  }());
74
131
  exports.PathOptionFactory = PathOptionFactory;
@@ -87,4 +87,57 @@ describe("PathOptionFactory test", function () {
87
87
  (0, chai_1.expect)(expected).to.be.eql(result[i]);
88
88
  }
89
89
  });
90
+ it(" getCurvePools works correctly", function () {
91
+ var _a, _b, _c, _d, _e;
92
+ var balances = (_a = {},
93
+ _a[token_1.tokenDataByNetwork.Mainnet["1INCH"]] = 100,
94
+ _a[token_1.tokenDataByNetwork.Mainnet["3Crv"]] = 200,
95
+ _a[token_1.tokenDataByNetwork.Mainnet.USDC] = 200,
96
+ _a[token_1.tokenDataByNetwork.Mainnet.FRAX3CRV] = 200,
97
+ _a[token_1.tokenDataByNetwork.Mainnet.LUSD3CRV] = 200,
98
+ _a);
99
+ var expectedCurvePools = [
100
+ "3Crv",
101
+ "FRAX3CRV",
102
+ "LUSD3CRV",
103
+ ];
104
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
105
+ balances = (_b = {},
106
+ _b[token_1.tokenDataByNetwork.Mainnet["1INCH"]] = 100,
107
+ _b[token_1.tokenDataByNetwork.Mainnet["3Crv"]] = 200,
108
+ _b[token_1.tokenDataByNetwork.Mainnet.USDC] = 200,
109
+ _b[token_1.tokenDataByNetwork.Mainnet.yvCurve_FRAX] = 200,
110
+ _b[token_1.tokenDataByNetwork.Mainnet.yvCurve_stETH] = 200,
111
+ _b);
112
+ expectedCurvePools = ["3Crv", "FRAX3CRV", "steCRV"];
113
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
114
+ balances = (_c = {},
115
+ _c[token_1.tokenDataByNetwork.Mainnet["1INCH"]] = 100,
116
+ _c[token_1.tokenDataByNetwork.Mainnet.USDC] = 200,
117
+ _c[token_1.tokenDataByNetwork.Mainnet.cvx3Crv] = 200,
118
+ _c[token_1.tokenDataByNetwork.Mainnet.cvxFRAX3CRV] = 200,
119
+ _c);
120
+ expectedCurvePools = ["3Crv", "FRAX3CRV"];
121
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
122
+ balances = (_d = {},
123
+ _d[token_1.tokenDataByNetwork.Mainnet.wstETH] = 100,
124
+ _d[token_1.tokenDataByNetwork.Mainnet.USDC] = 200,
125
+ _d[token_1.tokenDataByNetwork.Mainnet.stkcvx3Crv] = 200,
126
+ _d[token_1.tokenDataByNetwork.Mainnet.stkcvxFRAX3CRV] = 200,
127
+ _d);
128
+ expectedCurvePools = ["3Crv", "FRAX3CRV"];
129
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
130
+ balances = (_e = {},
131
+ _e[token_1.tokenDataByNetwork.Mainnet["3Crv"]] = 100,
132
+ _e[token_1.tokenDataByNetwork.Mainnet.USDC] = 200,
133
+ _e[token_1.tokenDataByNetwork.Mainnet.stkcvx3Crv] = 200,
134
+ _e[token_1.tokenDataByNetwork.Mainnet.cvx3Crv] = 200,
135
+ _e[token_1.tokenDataByNetwork.Mainnet.yvCurve_stETH] = 200,
136
+ _e);
137
+ expectedCurvePools = ["3Crv", "steCRV"];
138
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.getCurvePools(balances)).to.be.eql(expectedCurvePools);
139
+ });
140
+ it("detectNetwork works correctly", function () {
141
+ (0, chai_1.expect)(pathOptions_1.PathOptionFactory.detectNetwork(token_1.tokenDataByNetwork.Mainnet["1INCH"])).to.be.eq("Mainnet");
142
+ });
90
143
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "1.8.9",
3
+ "version": "1.8.11",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",