@gearbox-protocol/sdk 0.0.38 → 0.0.41

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.
@@ -26,6 +26,7 @@ export declare const SUSHISWAP_MAINNET = "0xd9e1cE17f2641f24aE83637ab66a2cca9C37
26
26
  export declare const SUSHISWAP_KOVAN = "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506";
27
27
  export declare const CONVEX_BOOSTER_KOVAN_ADDRESS = "0x78A9261965F048b9FF055699569be4400EEC7005";
28
28
  export declare const CONVEX_3CRV_KOVAN_POOL_ADDRESS = "0x90D9E8ecc406cd7363C08fAdb4ac0f3994b4cA71";
29
+ export declare const CONVEX_STECRV_POOL_ADDRESS = "0x0A760466E1B4621579a82a39CB56Dda2F4E70f03";
29
30
  export declare const CONVEX_STECRV_KOVAN_POOL_ADDRESS = "0x0f64e188BFF97e09C71FF85f30509f5596D420dD";
30
31
  export declare const CONVEX_BOOSTER_ADDRESS = "0xF403C135812408BFbE8713b5A23a04b3D48AAE31";
31
32
  export declare const CONVEX_3POOL_REWARD_POOL_ADDRESS = "0x689440f2Ff927E1f24c72F1087E1FAF471eCe1c8";
@@ -6,7 +6,7 @@
6
6
  */
7
7
  var _a;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.knownContracts = exports.AdapterInterface = exports.LIDO_STETH_ADDRESS = exports.CONVEX_CLAIM_ZAP_ADDRESS = exports.CONVEX_FRAX3CRV_REWARD_POOL_ADDRESS = exports.CONVEX_3POOL_REWARD_POOL_ADDRESS = exports.CONVEX_BOOSTER_ADDRESS = exports.CONVEX_STECRV_KOVAN_POOL_ADDRESS = exports.CONVEX_3CRV_KOVAN_POOL_ADDRESS = exports.CONVEX_BOOSTER_KOVAN_ADDRESS = exports.SUSHISWAP_KOVAN = exports.SUSHISWAP_MAINNET = exports.YEARN_3POOL_KOVAN_MOCK = exports.YEARN_WBTC_KOVAN_MOCK = exports.YEARN_WETH_KOVAN_MOCK = exports.YEARN_USDC_KOVAN_MOCK = exports.YEARN_DAI_KOVAN_MOCK = exports.YEARN_CURVE_STETH_ADDRESS = exports.YEARN_CURVE_FRAX_ADDRESS = exports.YEARN_WBTC_ADDRESS = exports.YEARN_WETH_ADDRESS = exports.YEARN_USDC_ADDRESS = exports.YEARN_DAI_ADDRESS = exports.CURVE_SUSD_KOVAN_MOCK = exports.CURVE_STE_CRV_KOVAN_MOCK = exports.CURVE_3POOL_KOVAN_MOCK = exports.CURVE_GUSD_ADDRESS = exports.CURVE_SUSD_ADDRESS = exports.CURVE_LUSD_ADDRESS = exports.CURVE_FRAX_ADDRESS = exports.CURVE_STETH_GATEWAY_ADDRESS = exports.CURVE_STETH_ADDRESS = exports.CURVE_3POOL_ADDRESS = exports.UNISWAP_V3_QUOTER = exports.UNISWAP_V3_ROUTER = exports.UNISWAP_V2_ROUTER = void 0;
9
+ exports.knownContracts = exports.AdapterInterface = exports.LIDO_STETH_ADDRESS = exports.CONVEX_CLAIM_ZAP_ADDRESS = exports.CONVEX_FRAX3CRV_REWARD_POOL_ADDRESS = exports.CONVEX_3POOL_REWARD_POOL_ADDRESS = exports.CONVEX_BOOSTER_ADDRESS = exports.CONVEX_STECRV_KOVAN_POOL_ADDRESS = exports.CONVEX_STECRV_POOL_ADDRESS = exports.CONVEX_3CRV_KOVAN_POOL_ADDRESS = exports.CONVEX_BOOSTER_KOVAN_ADDRESS = exports.SUSHISWAP_KOVAN = exports.SUSHISWAP_MAINNET = exports.YEARN_3POOL_KOVAN_MOCK = exports.YEARN_WBTC_KOVAN_MOCK = exports.YEARN_WETH_KOVAN_MOCK = exports.YEARN_USDC_KOVAN_MOCK = exports.YEARN_DAI_KOVAN_MOCK = exports.YEARN_CURVE_STETH_ADDRESS = exports.YEARN_CURVE_FRAX_ADDRESS = exports.YEARN_WBTC_ADDRESS = exports.YEARN_WETH_ADDRESS = exports.YEARN_USDC_ADDRESS = exports.YEARN_DAI_ADDRESS = exports.CURVE_SUSD_KOVAN_MOCK = exports.CURVE_STE_CRV_KOVAN_MOCK = exports.CURVE_3POOL_KOVAN_MOCK = exports.CURVE_GUSD_ADDRESS = exports.CURVE_SUSD_ADDRESS = exports.CURVE_LUSD_ADDRESS = exports.CURVE_FRAX_ADDRESS = exports.CURVE_STETH_GATEWAY_ADDRESS = exports.CURVE_STETH_ADDRESS = exports.CURVE_3POOL_ADDRESS = exports.UNISWAP_V3_QUOTER = exports.UNISWAP_V3_ROUTER = exports.UNISWAP_V2_ROUTER = void 0;
10
10
  var token_1 = require("./token");
11
11
  exports.UNISWAP_V2_ROUTER = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
12
12
  exports.UNISWAP_V3_ROUTER = "0xE592427A0AEce92De3Edee1F18E0157C05861564";
@@ -37,6 +37,7 @@ exports.SUSHISWAP_MAINNET = "0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F";
37
37
  exports.SUSHISWAP_KOVAN = "0x1b02dA8Cb0d097eB8D57A175b88c7D8b47997506";
38
38
  exports.CONVEX_BOOSTER_KOVAN_ADDRESS = "0x78A9261965F048b9FF055699569be4400EEC7005";
39
39
  exports.CONVEX_3CRV_KOVAN_POOL_ADDRESS = "0x90D9E8ecc406cd7363C08fAdb4ac0f3994b4cA71";
40
+ exports.CONVEX_STECRV_POOL_ADDRESS = "0x0A760466E1B4621579a82a39CB56Dda2F4E70f03";
40
41
  exports.CONVEX_STECRV_KOVAN_POOL_ADDRESS = "0x0f64e188BFF97e09C71FF85f30509f5596D420dD";
41
42
  exports.CONVEX_BOOSTER_ADDRESS = "0xF403C135812408BFbE8713b5A23a04b3D48AAE31";
42
43
  exports.CONVEX_3POOL_REWARD_POOL_ADDRESS = "0x689440f2Ff927E1f24c72F1087E1FAF471eCe1c8";
@@ -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
  };
@@ -19,6 +19,7 @@ export declare type TokenDataI = {
19
19
  type: TokenType.CURVE_LP;
20
20
  } | {
21
21
  type: TokenType.YEARN_VAULT;
22
+ underlying: SupportedTokens;
22
23
  } | {
23
24
  type: TokenType.META_CURVE_LP;
24
25
  } | {
package/lib/core/token.js CHANGED
@@ -113,16 +113,20 @@ exports.supportedTokens = {
113
113
  },
114
114
  // YEARN TOKENS
115
115
  yvDAI: {
116
- type: TokenType.YEARN_VAULT
116
+ type: TokenType.YEARN_VAULT,
117
+ underlying: "DAI",
117
118
  },
118
119
  yvUSDC: {
119
- type: TokenType.YEARN_VAULT
120
+ type: TokenType.YEARN_VAULT,
121
+ underlying: "USDC"
120
122
  },
121
123
  yvWETH: {
122
- type: TokenType.YEARN_VAULT
124
+ type: TokenType.YEARN_VAULT,
125
+ underlying: "WETH",
123
126
  },
124
127
  yvWBTC: {
125
- type: TokenType.YEARN_VAULT
128
+ type: TokenType.YEARN_VAULT,
129
+ underlying: "WBTC"
126
130
  },
127
131
  // CURVE LP TOKENS
128
132
  "3Crv": {
@@ -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
+ // const verifier = new Verifier();
152
+ // verifier
153
+ // .deploy()
154
+ // .then(() => {
155
+ // process.exit(0);
156
+ // })
157
+ // .catch((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.38",
3
+ "version": "0.0.41",
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
  }
@@ -52,6 +52,9 @@ export const CONVEX_BOOSTER_KOVAN_ADDRESS =
52
52
  export const CONVEX_3CRV_KOVAN_POOL_ADDRESS =
53
53
  "0x90D9E8ecc406cd7363C08fAdb4ac0f3994b4cA71";
54
54
 
55
+ export const CONVEX_STECRV_POOL_ADDRESS =
56
+ "0x0A760466E1B4621579a82a39CB56Dda2F4E70f03";
57
+
55
58
  export const CONVEX_STECRV_KOVAN_POOL_ADDRESS =
56
59
  "0x0f64e188BFF97e09C71FF85f30509f5596D420dD";
57
60
 
@@ -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
@@ -36,6 +36,7 @@ export type TokenDataI =
36
36
  }
37
37
  | {
38
38
  type: TokenType.YEARN_VAULT;
39
+ underlying: SupportedTokens,
39
40
  }
40
41
  | {
41
42
  type: TokenType.META_CURVE_LP;
@@ -222,19 +223,23 @@ export const supportedTokens: Record<SupportedTokens, TokenDataI> = {
222
223
 
223
224
  // YEARN TOKENS
224
225
  yvDAI: {
225
- type: TokenType.YEARN_VAULT
226
+ type: TokenType.YEARN_VAULT,
227
+ underlying: "DAI",
226
228
  },
227
229
 
228
230
  yvUSDC: {
229
- type: TokenType.YEARN_VAULT
231
+ type: TokenType.YEARN_VAULT,
232
+ underlying: "USDC"
230
233
  },
231
234
 
232
235
  yvWETH: {
233
- type: TokenType.YEARN_VAULT
236
+ type: TokenType.YEARN_VAULT,
237
+ underlying: "WETH",
234
238
  },
235
239
 
236
240
  yvWBTC: {
237
- type: TokenType.YEARN_VAULT
241
+ type: TokenType.YEARN_VAULT,
242
+ underlying: "WBTC"
238
243
  },
239
244
 
240
245
  // CURVE LP TOKENS
@@ -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,