@gearbox-protocol/sdk 0.0.37 → 0.0.40

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.
@@ -2,12 +2,18 @@ import { BigNumber } from "ethers";
2
2
  import { CreditManagerData } from "./creditManager";
3
3
  import { MultiCall } from "./multicall";
4
4
  import { SupportedTokens } from "./token";
5
- export interface Path {
6
- calls: Array<MultiCall>;
7
- balances: Record<SupportedTokens, BigNumber>;
8
- gasUsed: number;
9
- pool: SupportedTokens;
10
- creditManager: CreditManagerData;
5
+ export declare class Path {
6
+ readonly calls: Array<MultiCall>;
7
+ readonly balances: Record<SupportedTokens, BigNumber>;
8
+ protected _gasUsed: number;
9
+ readonly pool: SupportedTokens;
10
+ readonly creditManager: CreditManagerData;
11
+ constructor(opts: {
12
+ gasUsed: number;
13
+ balances: Record<SupportedTokens, BigNumber>;
14
+ pool: SupportedTokens;
15
+ creditManager: CreditManagerData;
16
+ });
11
17
  getBestPath(): Promise<Path>;
12
18
  }
13
19
  export interface PathAsset {
@@ -1,16 +1,129 @@
1
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
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConnectorPathAsset = void 0;
39
+ exports.ConnectorPathAsset = exports.Path = void 0;
40
+ // const path = new Path({gasUsed:0, balances: creditAccount.balances, })
41
+ // const closurePath = await path.getBestPath();
42
+ // closurePath.calls -> multicalls (!)
43
+ // closurePath.balances[path.pool] = (X)
44
+ // closurePath.balances[!path.pool] = 0 / 1;
45
+ //
46
+ // [0,0,0, 100]
47
+ // [ 12, 12, 12, 0]
48
+ var Path = /** @class */ (function () {
49
+ function Path(opts) {
50
+ this.calls = [];
51
+ this._gasUsed = opts.gasUsed;
52
+ this.balances = opts.balances;
53
+ this.pool = opts.pool;
54
+ this.creditManager = opts.creditManager;
55
+ }
56
+ Path.prototype.getBestPath = function () {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ return __generator(this, function (_a) {
59
+ // const nextToken = Object.entries(this.balances).filter(([token, balance]) => balance.gt(1) ) //.sort((a,b) => {})
60
+ // if (nextToken.length ===1 ) {
61
+ // }
62
+ // Get balances and keep non-zero only
63
+ // Find token with highest priority
64
+ // Get token type of this token
65
+ // switch (type) {
66
+ // case TokenType.YearnValut:
67
+ // const assetPathClass = new YearnPathAsset();
68
+ // return assetPathClass.getBestPath(this);
69
+ // ...
70
+ //}
71
+ throw new Error("Not implmented");
72
+ });
73
+ });
74
+ };
75
+ return Path;
76
+ }());
77
+ exports.Path = Path;
4
78
  var ConnectorPathAsset = /** @class */ (function () {
5
79
  function ConnectorPathAsset() {
6
80
  }
7
81
  ConnectorPathAsset.prototype.getBestPath = function (p) {
8
82
  console.log(p);
9
- // How to unwrap
83
+ // How to unwrap
10
84
  // set balance of current token to 0
11
- // add balnace what we get
85
+ // add balnace what we get
12
86
  // add call
13
87
  // create new Paths
88
+ // 3CRV:
89
+ // coinst balance3crv = p.balance["3rcv"];
90
+ // const p.balance["3rcv"] = 0;
91
+ // DAI
92
+ // const daiPath = {...p};
93
+ // const daiPath["Dai"] = await curve.getAmount(t balance3crv);
94
+ // const pathDai = new Path(daiPath)
95
+ // ...
96
+ // const bestPath = pathDai.balance[0] > pathUSDC.balance(0) ? pathDai : pathUsdc;
97
+ // --- DAI
98
+ // --|
99
+ // --- USDC
100
+ //
101
+ // NORMAL TOKEN
102
+ // ============
103
+ //
104
+ // - NORMAL -> POOL (1 pair) => #1
105
+ // for(let conn of connectors) {
106
+ // const result = getAmount([NORMAL, conn, pool])
107
+ // }
108
+ // => best Path to get max Pool tokens
109
+ // const resultInConnector = getAmount([NORMAL, conn]);
110
+ // calls.push("Uniswap.swap(NORMAL, conn)");
111
+ // CRV => CRV -> USDC -> DAI
112
+ // LINK => LINK -> USDC -> DAI
113
+ //
114
+ // [UniV2.swap("CRV", "USDC"),
115
+ // UniV3.swap("LINK", "USDC"),
116
+ // Curve.exchange("USDC", "DAI")]
117
+ //
118
+ // Below is not optimal:
119
+ // [ UniV2.swap("CRV -> USDC -> DAI"),
120
+ // UniV2.swap("LINK -> USDC -> DAI")]
121
+ //
122
+ //
123
+ // [ UniV2.swap("CRV -> USDC")
124
+ // UniV2.swap("USDC -> DAI"),
125
+ // UniV2.swap("LINK -> USDC"),
126
+ // UniV2.swap("USDC -> DAI") ]
14
127
  // return maxValuable(new Paths.getBestPath())
15
128
  throw new Error("Method not implemented.");
16
129
  };
@@ -7,18 +7,10 @@ declare enum TokenType {
7
7
  YEARN_VAULT = 4,
8
8
  YEARN_VAULT_OF_CURVE_LP = 5,
9
9
  YEARN_VAULT_OF_META_CURVE_LP = 6,
10
- CONVEX_PHANTOM = 7
10
+ CONVEX_LP_TOKEN = 7,
11
+ CONVEX_STAKED_PHANTOM_TOKEN = 8
11
12
  }
12
- export declare const priority: {
13
- 0: number;
14
- 1: number;
15
- 2: number;
16
- 4: number;
17
- 3: number;
18
- 5: number;
19
- 7: number;
20
- 6: number;
21
- };
13
+ export declare const priority: Record<TokenType, number>;
22
14
  export declare type TokenDataI = {
23
15
  type: TokenType.CONNECTOR;
24
16
  } | {
@@ -27,12 +19,13 @@ export declare type TokenDataI = {
27
19
  type: TokenType.CURVE_LP;
28
20
  } | {
29
21
  type: TokenType.YEARN_VAULT;
22
+ underlying: SupportedTokens;
30
23
  } | {
31
24
  type: TokenType.META_CURVE_LP;
32
25
  } | {
33
26
  type: TokenType.YEARN_VAULT_OF_CURVE_LP;
34
27
  } | {
35
- type: TokenType.CONVEX_PHANTOM;
28
+ type: TokenType.CONVEX_LP_TOKEN;
36
29
  } | {
37
30
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
38
31
  };
package/lib/core/token.js CHANGED
@@ -11,7 +11,8 @@ var TokenType;
11
11
  TokenType[TokenType["YEARN_VAULT"] = 4] = "YEARN_VAULT";
12
12
  TokenType[TokenType["YEARN_VAULT_OF_CURVE_LP"] = 5] = "YEARN_VAULT_OF_CURVE_LP";
13
13
  TokenType[TokenType["YEARN_VAULT_OF_META_CURVE_LP"] = 6] = "YEARN_VAULT_OF_META_CURVE_LP";
14
- TokenType[TokenType["CONVEX_PHANTOM"] = 7] = "CONVEX_PHANTOM";
14
+ TokenType[TokenType["CONVEX_LP_TOKEN"] = 7] = "CONVEX_LP_TOKEN";
15
+ TokenType[TokenType["CONVEX_STAKED_PHANTOM_TOKEN"] = 8] = "CONVEX_STAKED_PHANTOM_TOKEN";
15
16
  })(TokenType || (TokenType = {}));
16
17
  exports.priority = (_a = {},
17
18
  _a[TokenType.CONNECTOR] = 1,
@@ -20,8 +21,9 @@ exports.priority = (_a = {},
20
21
  _a[TokenType.YEARN_VAULT] = 3,
21
22
  _a[TokenType.META_CURVE_LP] = 4,
22
23
  _a[TokenType.YEARN_VAULT_OF_CURVE_LP] = 4,
23
- _a[TokenType.CONVEX_PHANTOM] = 5,
24
+ _a[TokenType.CONVEX_LP_TOKEN] = 5,
24
25
  _a[TokenType.YEARN_VAULT_OF_META_CURVE_LP] = 5,
26
+ _a[TokenType.CONVEX_STAKED_PHANTOM_TOKEN] = 5,
25
27
  _a);
26
28
  exports.supportedTokens = {
27
29
  "1INCH": {
@@ -111,16 +113,20 @@ exports.supportedTokens = {
111
113
  },
112
114
  // YEARN TOKENS
113
115
  yvDAI: {
114
- type: TokenType.YEARN_VAULT
116
+ type: TokenType.YEARN_VAULT,
117
+ underlying: "DAI",
115
118
  },
116
119
  yvUSDC: {
117
- type: TokenType.YEARN_VAULT
120
+ type: TokenType.YEARN_VAULT,
121
+ underlying: "USDC"
118
122
  },
119
123
  yvWETH: {
120
- type: TokenType.YEARN_VAULT
124
+ type: TokenType.YEARN_VAULT,
125
+ underlying: "WETH",
121
126
  },
122
127
  yvWBTC: {
123
- type: TokenType.YEARN_VAULT
128
+ type: TokenType.YEARN_VAULT,
129
+ underlying: "WBTC"
124
130
  },
125
131
  // CURVE LP TOKENS
126
132
  "3Crv": {
@@ -144,19 +150,19 @@ exports.supportedTokens = {
144
150
  },
145
151
  // CONVEX LP TOKENS
146
152
  cvx3Crv: {
147
- type: TokenType.CONVEX_PHANTOM
153
+ type: TokenType.CONVEX_LP_TOKEN
148
154
  },
149
155
  cvxsteCRV: {
150
- type: TokenType.CONVEX_PHANTOM
156
+ type: TokenType.CONVEX_LP_TOKEN
151
157
  },
152
158
  cvxFRAX3CRV: {
153
- type: TokenType.CONVEX_PHANTOM
159
+ type: TokenType.CONVEX_LP_TOKEN
154
160
  },
155
161
  cvxcrvPlain3andSUSD: {
156
- type: TokenType.CONVEX_PHANTOM
162
+ type: TokenType.CONVEX_LP_TOKEN
157
163
  },
158
164
  cvxgusd3CRV: {
159
- type: TokenType.CONVEX_PHANTOM
165
+ type: TokenType.CONVEX_LP_TOKEN
160
166
  },
161
167
  // YEARN- CURVE TOKENS
162
168
  yvCurve_stETH: {
@@ -217,6 +223,8 @@ exports.tokenDataByNetwork = {
217
223
  cvxFRAX3CRV: "0xbE0F6478E0E4894CFb14f32855603A083A57c7dA",
218
224
  cvxcrvPlain3andSUSD: "0x11D200ef1409cecA8D6d23e6496550f707772F11",
219
225
  cvxgusd3CRV: "0x15c2471ef46Fa721990730cfa526BcFb45574576",
226
+ // CONVEX PHANTOM TOKEN ADDRESSES
227
+ // <Provide them here>
220
228
  // YEARN- CURVE TOKENS
221
229
  yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
222
230
  yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139"
@@ -0,0 +1,7 @@
1
+ import { Logger } from "tslog";
2
+ export declare abstract class LoggedDeployer {
3
+ protected readonly _logger: Logger;
4
+ protected constructor();
5
+ enableLogs(): void;
6
+ disableLogs(): void;
7
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoggedDeployer = void 0;
4
+ var tslog_1 = require("tslog");
5
+ var LoggedDeployer = /** @class */ (function () {
6
+ function LoggedDeployer() {
7
+ this._logger = new tslog_1.Logger({
8
+ minLevel: "error",
9
+ displayFunctionName: false,
10
+ displayLoggerName: false,
11
+ displayFilePath: "hidden",
12
+ });
13
+ }
14
+ LoggedDeployer.prototype.enableLogs = function () {
15
+ this._logger.setSettings({ minLevel: "debug" });
16
+ };
17
+ LoggedDeployer.prototype.disableLogs = function () {
18
+ this._logger.setSettings({ minLevel: "error" });
19
+ };
20
+ return LoggedDeployer;
21
+ }());
22
+ exports.LoggedDeployer = LoggedDeployer;
@@ -0,0 +1,13 @@
1
+ import { LoggedDeployer } from "./loggedDeployer";
2
+ export interface VerifyRequest {
3
+ address: string;
4
+ constructorArguments: Array<any>;
5
+ }
6
+ export declare class Verifier extends LoggedDeployer {
7
+ protected verifier: Array<VerifyRequest>;
8
+ protected apiKey: string;
9
+ constructor();
10
+ addContract(c: VerifyRequest): void;
11
+ deploy(): Promise<void>;
12
+ protected _saveVerifier(): void;
13
+ }
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
41
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
42
+ return new (P || (P = Promise))(function (resolve, reject) {
43
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
44
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
45
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ };
49
+ var __generator = (this && this.__generator) || function (thisArg, body) {
50
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
51
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
52
+ function verb(n) { return function (v) { return step([n, v]); }; }
53
+ function step(op) {
54
+ if (f) throw new TypeError("Generator is already executing.");
55
+ while (_) try {
56
+ 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;
57
+ if (y = 0, t) op = [op[0] & 2, t.value];
58
+ switch (op[0]) {
59
+ case 0: case 1: t = op; break;
60
+ case 4: _.label++; return { value: op[1], done: false };
61
+ case 5: _.label++; y = op[1]; op = [0]; continue;
62
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
63
+ default:
64
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
65
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
66
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
67
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
68
+ if (t[2]) _.ops.pop();
69
+ _.trys.pop(); continue;
70
+ }
71
+ op = body.call(thisArg, _);
72
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
73
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
74
+ }
75
+ };
76
+ var __importDefault = (this && this.__importDefault) || function (mod) {
77
+ return (mod && mod.__esModule) ? mod : { "default": mod };
78
+ };
79
+ Object.defineProperty(exports, "__esModule", { value: true });
80
+ exports.Verifier = void 0;
81
+ /*
82
+ * Copyright (c) 2021. Gearbox
83
+ */
84
+ // import verifierJson from "../.verifier.json";
85
+ var loggedDeployer_1 = require("./loggedDeployer");
86
+ var fs = __importStar(require("fs"));
87
+ var dotenv_1 = require("dotenv");
88
+ var axios_1 = __importDefault(require("axios"));
89
+ var hre = require("hardhat");
90
+ (0, dotenv_1.config)({ path: ".env" });
91
+ var Verifier = /** @class */ (function (_super) {
92
+ __extends(Verifier, _super);
93
+ function Verifier() {
94
+ var _this = _super.call(this) || this;
95
+ _this.verifier = [];
96
+ // this.verifier = verifierJson;
97
+ // JSON.parse("")
98
+ _this.apiKey = process.env.ETHERSCAN_API_KEY || "";
99
+ if (_this.apiKey === "")
100
+ throw new Error("No etherscan API provided");
101
+ return _this;
102
+ }
103
+ Verifier.prototype.addContract = function (c) {
104
+ this.verifier.push(c);
105
+ this._saveVerifier();
106
+ };
107
+ Verifier.prototype.deploy = function () {
108
+ return __awaiter(this, void 0, void 0, function () {
109
+ var i, params, url, isVerified;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ this.enableLogs();
114
+ i = 0;
115
+ _a.label = 1;
116
+ case 1:
117
+ if (!(i < this.verifier.length)) return [3 /*break*/, 7];
118
+ params = this.verifier.shift();
119
+ url = "https://api-kovan.etherscan.io/api?module=contract&action=getabi&address=".concat(params === null || params === void 0 ? void 0 : params.address, "&apikey=").concat(this.apiKey);
120
+ return [4 /*yield*/, axios_1.default.get(url)];
121
+ case 2:
122
+ isVerified = _a.sent();
123
+ console.log(isVerified.data);
124
+ if (!(isVerified.data.status === '1')) return [3 /*break*/, 3];
125
+ this._logger.debug("".concat(params === null || params === void 0 ? void 0 : params.address, " is already verified"));
126
+ return [3 /*break*/, 5];
127
+ case 3:
128
+ this._logger.info("Verifing: ".concat(params === null || params === void 0 ? void 0 : params.address));
129
+ return [4 /*yield*/, hre.run("verify:verify", params)];
130
+ case 4:
131
+ _a.sent();
132
+ _a.label = 5;
133
+ case 5:
134
+ this._saveVerifier();
135
+ _a.label = 6;
136
+ case 6:
137
+ i++;
138
+ return [3 /*break*/, 1];
139
+ case 7: return [2 /*return*/];
140
+ }
141
+ });
142
+ });
143
+ };
144
+ Verifier.prototype._saveVerifier = function () {
145
+ fs.writeFileSync("./.verifier.json", JSON.stringify(this.verifier));
146
+ this._logger.debug("Deploy progress was saved into .verifier.json");
147
+ };
148
+ return Verifier;
149
+ }(loggedDeployer_1.LoggedDeployer));
150
+ exports.Verifier = Verifier;
151
+ var verifier = new Verifier();
152
+ verifier
153
+ .deploy()
154
+ .then(function () {
155
+ process.exit(0);
156
+ })
157
+ .catch(function (error) {
158
+ console.error(error);
159
+ process.exit(1);
160
+ });
package/lib/index.d.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./utils/math";
28
28
  export * from "./core/creditCard";
29
29
  export * from "./payload/graphPayload";
30
30
  export * from "./types/index";
31
+ export * from "./devops/verifierDeployer";
31
32
  export type { IAppPoolService, IAppCreditManager, IAppERC20, IAppAddressProvider, IDataCompressor, IWETHGateway } from "./types";
32
33
  export * from "./core/history";
33
34
  export { MultiCallContract } from "./utils/multicall";
package/lib/index.js CHANGED
@@ -45,6 +45,7 @@ __exportStar(require("./utils/math"), exports);
45
45
  __exportStar(require("./core/creditCard"), exports);
46
46
  __exportStar(require("./payload/graphPayload"), exports);
47
47
  __exportStar(require("./types/index"), exports);
48
+ __exportStar(require("./devops/verifierDeployer"), exports);
48
49
  __exportStar(require("./core/history"), exports);
49
50
  var multicall_1 = require("./utils/multicall");
50
51
  Object.defineProperty(exports, "MultiCallContract", { enumerable: true, get: function () { return multicall_1.MultiCallContract; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.37",
3
+ "version": "0.0.40",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -16,12 +16,16 @@
16
16
  "moment": "^2.29.1"
17
17
  },
18
18
  "devDependencies": {
19
+ "@types/axios": "^0.14.0",
19
20
  "@types/jest": "^26.0.4",
20
21
  "@types/node": "^14.0.23",
21
- "ethers": "^5.4.5",
22
+ "axios": "^0.27.2",
23
+ "dotenv": "^16.0.1",
24
+ "ethers": "^5.6.5",
22
25
  "jest": "^26.1.0",
23
26
  "prettier": "^2.3.0",
24
27
  "ts-node": "^10.1.0",
28
+ "tslog": "^3.3.3",
25
29
  "typescript": "^4.2.4"
26
30
  }
27
31
  }
@@ -3,24 +3,54 @@ import { CreditManagerData } from "./creditManager";
3
3
  import { MultiCall } from "./multicall";
4
4
  import { SupportedTokens } from "./token";
5
5
 
6
- export interface Path {
7
- calls: Array<MultiCall>;
8
- balances: Record<SupportedTokens, BigNumber>;
9
- // usedTokens: Array<SupportedTokens>;
10
- gasUsed: number;
11
- pool: SupportedTokens;
12
- creditManager: CreditManagerData;
13
-
14
- getBestPath(): Promise<Path>;
15
- // Get balances and keep non-zero only
16
- // Find token with highest priority
17
- // Get token type of this token
18
- // switch (type) {
19
- // case TokenType.YearnValut:
20
- // const assetPathClass = new YearnVaultPathAsset(tokenData);
21
- // return assetPathClass.getBestPath(this);
22
- // ...
23
- //}
6
+ // const path = new Path({gasUsed:0, balances: creditAccount.balances, })
7
+ // const closurePath = await path.getBestPath();
8
+ // closurePath.calls -> multicalls (!)
9
+ // closurePath.balances[path.pool] = (X)
10
+ // closurePath.balances[!path.pool] = 0 / 1;
11
+
12
+ //
13
+ // [0,0,0, 100]
14
+ // [ 12, 12, 12, 0]
15
+
16
+ export class Path {
17
+ public readonly calls: Array<MultiCall> = [];
18
+ public readonly balances: Record<SupportedTokens, BigNumber>;
19
+ // usedTokens: Array<SupportedTokens>;
20
+ protected _gasUsed: number;
21
+ public readonly pool: SupportedTokens;
22
+ public readonly creditManager: CreditManagerData;
23
+
24
+ constructor(opts: {
25
+ gasUsed: number;
26
+ balances: Record<SupportedTokens, BigNumber>;
27
+ pool: SupportedTokens;
28
+ creditManager: CreditManagerData;
29
+ }) {
30
+ this._gasUsed = opts.gasUsed;
31
+ this.balances = opts.balances;
32
+ this.pool = opts.pool;
33
+ this.creditManager = opts.creditManager;
34
+ }
35
+
36
+ async getBestPath(): Promise<Path> {
37
+ // const nextToken = Object.entries(this.balances).filter(([token, balance]) => balance.gt(1) ) //.sort((a,b) => {})
38
+ // if (nextToken.length ===1 ) {
39
+
40
+ // }
41
+
42
+ // Get balances and keep non-zero only
43
+ // Find token with highest priority
44
+ // Get token type of this token
45
+ // switch (type) {
46
+ // case TokenType.YearnValut:
47
+ // const assetPathClass = new YearnPathAsset();
48
+ // return assetPathClass.getBestPath(this);
49
+ // ...
50
+
51
+ //}
52
+ throw new Error("Not implmented");
53
+ }
24
54
  }
25
55
 
26
56
  export interface PathAsset {
@@ -30,11 +60,55 @@ export interface PathAsset {
30
60
  export class ConnectorPathAsset implements PathAsset {
31
61
  getBestPath(p: Path): Promise<Path> {
32
62
  console.log(p);
33
- // How to unwrap
63
+ // How to unwrap
34
64
  // set balance of current token to 0
35
- // add balnace what we get
65
+ // add balnace what we get
36
66
  // add call
37
67
  // create new Paths
68
+
69
+ // 3CRV:
70
+ // coinst balance3crv = p.balance["3rcv"];
71
+ // const p.balance["3rcv"] = 0;
72
+ // DAI
73
+ // const daiPath = {...p};
74
+ // const daiPath["Dai"] = await curve.getAmount(t balance3crv);
75
+
76
+ // const pathDai = new Path(daiPath)
77
+ // ...
78
+ // const bestPath = pathDai.balance[0] > pathUSDC.balance(0) ? pathDai : pathUsdc;
79
+
80
+ // --- DAI
81
+ // --|
82
+ // --- USDC
83
+ //
84
+ // NORMAL TOKEN
85
+ // ============
86
+ //
87
+ // - NORMAL -> POOL (1 pair) => #1
88
+ // for(let conn of connectors) {
89
+ // const result = getAmount([NORMAL, conn, pool])
90
+ // }
91
+ // => best Path to get max Pool tokens
92
+ // const resultInConnector = getAmount([NORMAL, conn]);
93
+ // calls.push("Uniswap.swap(NORMAL, conn)");
94
+
95
+ // CRV => CRV -> USDC -> DAI
96
+ // LINK => LINK -> USDC -> DAI
97
+ //
98
+ // [UniV2.swap("CRV", "USDC"),
99
+ // UniV3.swap("LINK", "USDC"),
100
+ // Curve.exchange("USDC", "DAI")]
101
+ //
102
+ // Below is not optimal:
103
+ // [ UniV2.swap("CRV -> USDC -> DAI"),
104
+ // UniV2.swap("LINK -> USDC -> DAI")]
105
+ //
106
+ //
107
+ // [ UniV2.swap("CRV -> USDC")
108
+ // UniV2.swap("USDC -> DAI"),
109
+ // UniV2.swap("LINK -> USDC"),
110
+ // UniV2.swap("USDC -> DAI") ]
111
+
38
112
  // return maxValuable(new Paths.getBestPath())
39
113
  throw new Error("Method not implemented.");
40
114
  }
package/src/core/token.ts CHANGED
@@ -8,18 +8,20 @@ enum TokenType {
8
8
  YEARN_VAULT,
9
9
  YEARN_VAULT_OF_CURVE_LP,
10
10
  YEARN_VAULT_OF_META_CURVE_LP,
11
- CONVEX_PHANTOM
11
+ CONVEX_LP_TOKEN,
12
+ CONVEX_STAKED_PHANTOM_TOKEN,
12
13
  }
13
14
 
14
- export const priority = {
15
+ export const priority : Record<TokenType, number> = {
15
16
  [TokenType.CONNECTOR]: 1,
16
17
  [TokenType.NORMAL_TOKEN]: 2,
17
18
  [TokenType.CURVE_LP]: 3,
18
19
  [TokenType.YEARN_VAULT]: 3,
19
20
  [TokenType.META_CURVE_LP]: 4,
20
21
  [TokenType.YEARN_VAULT_OF_CURVE_LP]: 4,
21
- [TokenType.CONVEX_PHANTOM]: 5,
22
- [TokenType.YEARN_VAULT_OF_META_CURVE_LP]: 5
22
+ [TokenType.CONVEX_LP_TOKEN]: 5,
23
+ [TokenType.YEARN_VAULT_OF_META_CURVE_LP]: 5,
24
+ [TokenType.CONVEX_STAKED_PHANTOM_TOKEN]: 5
23
25
  };
24
26
 
25
27
  export type TokenDataI =
@@ -34,6 +36,7 @@ export type TokenDataI =
34
36
  }
35
37
  | {
36
38
  type: TokenType.YEARN_VAULT;
39
+ underlying: SupportedTokens,
37
40
  }
38
41
  | {
39
42
  type: TokenType.META_CURVE_LP;
@@ -42,7 +45,7 @@ export type TokenDataI =
42
45
  type: TokenType.YEARN_VAULT_OF_CURVE_LP;
43
46
  }
44
47
  | {
45
- type: TokenType.CONVEX_PHANTOM;
48
+ type: TokenType.CONVEX_LP_TOKEN;
46
49
  }
47
50
  | {
48
51
  type: TokenType.YEARN_VAULT_OF_META_CURVE_LP;
@@ -220,19 +223,23 @@ export const supportedTokens: Record<SupportedTokens, TokenDataI> = {
220
223
 
221
224
  // YEARN TOKENS
222
225
  yvDAI: {
223
- type: TokenType.YEARN_VAULT
226
+ type: TokenType.YEARN_VAULT,
227
+ underlying: "DAI",
224
228
  },
225
229
 
226
230
  yvUSDC: {
227
- type: TokenType.YEARN_VAULT
231
+ type: TokenType.YEARN_VAULT,
232
+ underlying: "USDC"
228
233
  },
229
234
 
230
235
  yvWETH: {
231
- type: TokenType.YEARN_VAULT
236
+ type: TokenType.YEARN_VAULT,
237
+ underlying: "WETH",
232
238
  },
233
239
 
234
240
  yvWBTC: {
235
- type: TokenType.YEARN_VAULT
241
+ type: TokenType.YEARN_VAULT,
242
+ underlying: "WBTC"
236
243
  },
237
244
 
238
245
  // CURVE LP TOKENS
@@ -266,23 +273,23 @@ export const supportedTokens: Record<SupportedTokens, TokenDataI> = {
266
273
  // CONVEX LP TOKENS
267
274
 
268
275
  cvx3Crv: {
269
- type: TokenType.CONVEX_PHANTOM
276
+ type: TokenType.CONVEX_LP_TOKEN
270
277
  },
271
278
 
272
279
  cvxsteCRV: {
273
- type: TokenType.CONVEX_PHANTOM
280
+ type: TokenType.CONVEX_LP_TOKEN
274
281
  },
275
282
 
276
283
  cvxFRAX3CRV: {
277
- type: TokenType.CONVEX_PHANTOM
284
+ type: TokenType.CONVEX_LP_TOKEN
278
285
  },
279
286
 
280
287
  cvxcrvPlain3andSUSD: {
281
- type: TokenType.CONVEX_PHANTOM
288
+ type: TokenType.CONVEX_LP_TOKEN
282
289
  },
283
290
 
284
291
  cvxgusd3CRV: {
285
- type: TokenType.CONVEX_PHANTOM
292
+ type: TokenType.CONVEX_LP_TOKEN
286
293
  },
287
294
 
288
295
  // YEARN- CURVE TOKENS
@@ -353,6 +360,9 @@ export const tokenDataByNetwork: Record<
353
360
  cvxcrvPlain3andSUSD: "0x11D200ef1409cecA8D6d23e6496550f707772F11",
354
361
  cvxgusd3CRV: "0x15c2471ef46Fa721990730cfa526BcFb45574576",
355
362
 
363
+ // CONVEX PHANTOM TOKEN ADDRESSES
364
+ // <Provide them here>
365
+
356
366
  // YEARN- CURVE TOKENS
357
367
  yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
358
368
  yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139"
@@ -0,0 +1,22 @@
1
+ import { Logger } from "tslog";
2
+
3
+ export abstract class LoggedDeployer {
4
+ protected readonly _logger: Logger;
5
+
6
+ protected constructor() {
7
+ this._logger = new Logger({
8
+ minLevel: "error",
9
+ displayFunctionName: false,
10
+ displayLoggerName: false,
11
+ displayFilePath: "hidden",
12
+ });
13
+ }
14
+
15
+ enableLogs() {
16
+ this._logger.setSettings({ minLevel: "debug" });
17
+ }
18
+
19
+ disableLogs() {
20
+ this._logger.setSettings({ minLevel: "error" });
21
+ }
22
+ }
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2021. Gearbox
3
+ */
4
+ // import verifierJson from "../.verifier.json";
5
+ import { LoggedDeployer } from "./loggedDeployer";
6
+ import * as fs from "fs";
7
+ import { config as dotEnvConfig } from "dotenv";
8
+ import axios from "axios";
9
+ const hre = require("hardhat");
10
+
11
+ dotEnvConfig({ path: ".env" });
12
+
13
+ export interface VerifyRequest {
14
+ address: string;
15
+ constructorArguments: Array<any>;
16
+ }
17
+
18
+ export class Verifier extends LoggedDeployer {
19
+ protected verifier: Array<VerifyRequest> = [];
20
+ protected apiKey: string;
21
+
22
+ constructor() {
23
+ super();
24
+ // this.verifier = verifierJson;
25
+ // JSON.parse("")
26
+ this.apiKey = process.env.ETHERSCAN_API_KEY || "";
27
+ if (this.apiKey === "") throw new Error("No etherscan API provided");
28
+ }
29
+
30
+ addContract(c: VerifyRequest) {
31
+ this.verifier.push(c);
32
+ this._saveVerifier();
33
+ }
34
+
35
+ async deploy() {
36
+ this.enableLogs();
37
+
38
+ for (let i = 0; i < this.verifier.length; i++) {
39
+ const params = this.verifier.shift();
40
+
41
+ const url = `https://api-kovan.etherscan.io/api?module=contract&action=getabi&address=${params?.address}&apikey=${this.apiKey}`;
42
+
43
+ const isVerified = await axios.get(url);
44
+
45
+ console.log(isVerified.data)
46
+
47
+ if (isVerified.data.status === '1') {
48
+ this._logger.debug(`${params?.address} is already verified`);
49
+ } else {
50
+ this._logger.info(`Verifing: ${params?.address}`);
51
+ await hre.run("verify:verify", params);
52
+ }
53
+
54
+ this._saveVerifier();
55
+ }
56
+ }
57
+
58
+ protected _saveVerifier() {
59
+ fs.writeFileSync("./.verifier.json", JSON.stringify(this.verifier));
60
+ this._logger.debug("Deploy progress was saved into .verifier.json");
61
+ }
62
+ }
63
+
64
+ const verifier = new Verifier();
65
+
66
+ verifier
67
+ .deploy()
68
+ .then(() => {
69
+ process.exit(0);
70
+ })
71
+ .catch((error) => {
72
+ console.error(error);
73
+ process.exit(1);
74
+ });
package/src/index.ts CHANGED
@@ -28,6 +28,7 @@ export * from "./utils/math";
28
28
  export * from "./core/creditCard";
29
29
  export * from "./payload/graphPayload";
30
30
  export * from "./types/index";
31
+ export * from "./devops/verifierDeployer";
31
32
 
32
33
  export type {
33
34
  IAppPoolService,