@gearbox-protocol/sdk 0.0.54 → 0.0.55

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.
@@ -72,7 +72,7 @@ var TxAddLiquidity = /** @class */ (function (_super) {
72
72
  return _this;
73
73
  }
74
74
  TxAddLiquidity.prototype.toString = function (tokenData) {
75
- var token = tokenData[this.underlyingToken];
75
+ var token = tokenData[this.underlyingToken.toLowerCase()];
76
76
  return "".concat((0, contractsRegister_1.getContractName)(this.pool), ": Deposit ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat((token === null || token === void 0 ? void 0 : token.symbol) || "");
77
77
  };
78
78
  TxAddLiquidity.prototype.serialize = function () {
@@ -99,7 +99,7 @@ var TxRemoveLiquidity = /** @class */ (function (_super) {
99
99
  return _this;
100
100
  }
101
101
  TxRemoveLiquidity.prototype.toString = function (tokenData) {
102
- var dtoken = tokenData[this.dieselToken];
102
+ var dtoken = tokenData[this.dieselToken.toLowerCase()];
103
103
  return "".concat((0, contractsRegister_1.getContractName)(this.pool), ": Withdraw ").concat((0, formatter_1.formatBN)(this.amount, (dtoken === null || dtoken === void 0 ? void 0 : dtoken.decimals) || 18), " ").concat((dtoken === null || dtoken === void 0 ? void 0 : dtoken.symbol) || "");
104
104
  };
105
105
  TxRemoveLiquidity.prototype.serialize = function () {
@@ -130,10 +130,10 @@ var TXSwap = /** @class */ (function (_super) {
130
130
  return _this;
131
131
  }
132
132
  TXSwap.prototype.toString = function (tokenData) {
133
- var tokenFrom = tokenData[this.tokenFrom];
133
+ var tokenFrom = tokenData[this.tokenFrom.toLowerCase()];
134
134
  var toPart = "";
135
135
  if (this.tokenTo && this.amountTo) {
136
- var tokenTo = tokenData[this.tokenTo];
136
+ var tokenTo = tokenData[this.tokenTo.toLowerCase()];
137
137
  toPart = " \u21D2 ".concat((0, formatter_1.formatBN)(this.amountTo, (tokenTo === null || tokenTo === void 0 ? void 0 : tokenTo.decimals) || 18), " ").concat((tokenTo === null || tokenTo === void 0 ? void 0 : tokenTo.symbol) || "");
138
138
  }
139
139
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": ").concat(this.operation, " ").concat((0, formatter_1.formatBN)(this.amountFrom, (tokenFrom === null || tokenFrom === void 0 ? void 0 : tokenFrom.decimals) || 18), " ").concat((tokenFrom === null || tokenFrom === void 0 ? void 0 : tokenFrom.symbol) || "", " ").concat(toPart, " on ").concat((0, contractsRegister_1.getContractName)(this.protocol));
@@ -162,7 +162,7 @@ var TxAddCollateral = /** @class */ (function (_super) {
162
162
  return _this;
163
163
  }
164
164
  TxAddCollateral.prototype.toString = function (tokenData) {
165
- var addedToken = tokenData[this.addedToken];
165
+ var addedToken = tokenData[this.addedToken.toLowerCase()];
166
166
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Added ").concat((0, formatter_1.formatBN)(this.amount, addedToken.decimals), " ").concat(addedToken.symbol, " as collateral");
167
167
  };
168
168
  TxAddCollateral.prototype.serialize = function () {
@@ -189,7 +189,7 @@ var TxIncreaseBorrowAmount = /** @class */ (function (_super) {
189
189
  return _this;
190
190
  }
191
191
  TxIncreaseBorrowAmount.prototype.toString = function (tokenData) {
192
- var token = tokenData[this.underlyingToken];
192
+ var token = tokenData[this.underlyingToken.toLowerCase()];
193
193
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Borrowed amount was increased for ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol);
194
194
  };
195
195
  TxIncreaseBorrowAmount.prototype.serialize = function () {
@@ -217,7 +217,7 @@ var TxOpenAccount = /** @class */ (function (_super) {
217
217
  return _this;
218
218
  }
219
219
  TxOpenAccount.prototype.toString = function (tokenData) {
220
- var token = tokenData[this.underlyingToken];
220
+ var token = tokenData[this.underlyingToken.toLowerCase()];
221
221
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": opening ").concat((0, formatter_1.formatBN)(this.amount, (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol, " x ").concat(this.leverage.toFixed(2), " \u21D2 \n ").concat((0, formatter_1.formatBN)(this.amount
222
222
  .mul(Math.floor(this.leverage * constants_1.LEVERAGE_DECIMALS))
223
223
  .div(constants_1.LEVERAGE_DECIMALS), (token === null || token === void 0 ? void 0 : token.decimals) || 18), " ").concat(token === null || token === void 0 ? void 0 : token.symbol);
@@ -243,7 +243,7 @@ var TxRepayAccount = /** @class */ (function (_super) {
243
243
  _this.creditManager = opts.creditManager;
244
244
  return _this;
245
245
  }
246
- TxRepayAccount.prototype.toString = function (_tokenData) {
246
+ TxRepayAccount.prototype.toString = function (_) {
247
247
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Repaying account");
248
248
  };
249
249
  TxRepayAccount.prototype.serialize = function () {
@@ -267,7 +267,7 @@ var TxCloseAccount = /** @class */ (function (_super) {
267
267
  _this.creditManager = opts.creditManager;
268
268
  return _this;
269
269
  }
270
- TxCloseAccount.prototype.toString = function (_tokenData) {
270
+ TxCloseAccount.prototype.toString = function (_) {
271
271
  return "Credit account ".concat((0, contractsRegister_1.getContractName)(this.creditManager), ": Closing account");
272
272
  };
273
273
  TxCloseAccount.prototype.serialize = function () {
@@ -292,7 +292,7 @@ var TxApprove = /** @class */ (function (_super) {
292
292
  return _this;
293
293
  }
294
294
  TxApprove.prototype.toString = function (tokenData) {
295
- var token = tokenData[this.token];
295
+ var token = tokenData[this.token.toLowerCase()];
296
296
  return "Approve ".concat(token === null || token === void 0 ? void 0 : token.symbol);
297
297
  };
298
298
  TxApprove.prototype.serialize = function () {
package/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from "./core/contracts";
6
6
  export * from "./core/events";
7
7
  export * from "./core/errors";
8
8
  export * from "./core/pool";
9
+ export * from "./core/protocols";
9
10
  export * from "./core/priceFeeds";
10
11
  export * from "./core/operations";
11
12
  export * from "./core/oracles";
@@ -34,3 +35,4 @@ export { MultiCallContract } from "./utils/multicall";
34
35
  export { callRepeater } from "./utils/repeater";
35
36
  export { getContractName } from "./core/contractsRegister";
36
37
  export { AdapterInterface } from "./core/adapters";
38
+ export { objectEntries, swapKeyValue, keyToLowercase } from "./utils/mappers";
package/lib/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.MultiCallContract = void 0;
17
+ exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = exports.AdapterInterface = exports.getContractName = exports.callRepeater = exports.MultiCallContract = void 0;
18
18
  __exportStar(require("./core/constants"), exports);
19
19
  __exportStar(require("./core/creditAccount"), exports);
20
20
  __exportStar(require("./core/creditManager"), exports);
@@ -23,6 +23,7 @@ __exportStar(require("./core/contracts"), exports);
23
23
  __exportStar(require("./core/events"), exports);
24
24
  __exportStar(require("./core/errors"), exports);
25
25
  __exportStar(require("./core/pool"), exports);
26
+ __exportStar(require("./core/protocols"), exports);
26
27
  __exportStar(require("./core/priceFeeds"), exports);
27
28
  __exportStar(require("./core/operations"), exports);
28
29
  __exportStar(require("./core/oracles"), exports);
@@ -54,3 +55,7 @@ var contractsRegister_1 = require("./core/contractsRegister");
54
55
  Object.defineProperty(exports, "getContractName", { enumerable: true, get: function () { return contractsRegister_1.getContractName; } });
55
56
  var adapters_1 = require("./core/adapters");
56
57
  Object.defineProperty(exports, "AdapterInterface", { enumerable: true, get: function () { return adapters_1.AdapterInterface; } });
58
+ var mappers_1 = require("./utils/mappers");
59
+ Object.defineProperty(exports, "objectEntries", { enumerable: true, get: function () { return mappers_1.objectEntries; } });
60
+ Object.defineProperty(exports, "swapKeyValue", { enumerable: true, get: function () { return mappers_1.swapKeyValue; } });
61
+ Object.defineProperty(exports, "keyToLowercase", { enumerable: true, get: function () { return mappers_1.keyToLowercase; } });
@@ -0,0 +1,6 @@
1
+ declare type SupportedValue = string | number;
2
+ declare const objectEntries: <K extends SupportedValue, T>(o: Record<K, T>) => [K, T][];
3
+ declare const swapKeyValue: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<T, K>;
4
+ declare const keyToLowercase: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<K, T>;
5
+ export type { SupportedValue };
6
+ export { objectEntries, swapKeyValue, keyToLowercase };
@@ -0,0 +1,33 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = void 0;
15
+ var objectEntries = function (o) { return Object.entries(o); };
16
+ exports.objectEntries = objectEntries;
17
+ var swapKeyValue = function (o) {
18
+ return objectEntries(o).reduce(function (sum, _a) {
19
+ var _b;
20
+ var key = _a[0], value = _a[1];
21
+ return __assign(__assign({}, sum), (_b = {}, _b[value] = key, _b));
22
+ }, {});
23
+ };
24
+ exports.swapKeyValue = swapKeyValue;
25
+ var keyToLowercase = function (o) {
26
+ return objectEntries(o).reduce(function (sum, _a) {
27
+ var _b;
28
+ var key = _a[0], value = _a[1];
29
+ var keyTransformed = typeof key === "string" ? key.toLowerCase() : key;
30
+ return __assign(__assign({}, sum), (_b = {}, _b[keyTransformed] = value, _b));
31
+ }, {});
32
+ };
33
+ exports.keyToLowercase = keyToLowercase;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "description": "Gearbox SDK",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -1,16 +1,14 @@
1
1
  export enum AdapterInterface {
2
- NO_SWAP, // 0 - 1
3
- UNISWAP_V2_ROUTER, // 1 - 2
4
- UNISWAP_V3_ROUTER, // 2 - 4
5
- CURVE_V1_2ASSETS, // 3 - 8
6
- CURVE_V1_3ASSETS, // 4 - 16
7
- CURVE_V1_4ASSETS, // 5 - 32
8
- CURVE_V1_STECRV_POOL, // 6 - 64
9
- YEARN_V2, // 7 - 128
10
- CONVEX_V1_BASE_REWARD_POOL, // 8 - 256
11
- CONVEX_V1_BOOSTER, // 9 - 512
12
- CONVEX_V1_CLAIM_ZAP, // 10 - 1024
13
- LIDO_V1 // 11 - 2048
14
- }
15
-
16
-
2
+ NO_SWAP, // 0 - 1
3
+ UNISWAP_V2_ROUTER, // 1 - 2
4
+ UNISWAP_V3_ROUTER, // 2 - 4
5
+ CURVE_V1_2ASSETS, // 3 - 8
6
+ CURVE_V1_3ASSETS, // 4 - 16
7
+ CURVE_V1_4ASSETS, // 5 - 32
8
+ CURVE_V1_STECRV_POOL, // 6 - 64
9
+ YEARN_V2, // 7 - 128
10
+ CONVEX_V1_BASE_REWARD_POOL, // 8 - 256
11
+ CONVEX_V1_BOOSTER, // 9 - 512
12
+ CONVEX_V1_CLAIM_ZAP, // 10 - 1024
13
+ LIDO_V1 // 11 - 2048
14
+ }
@@ -3,12 +3,16 @@
3
3
  * Gearbox. Generalized leverage protocol, which allows to take leverage and then use it across other DeFi protocols and platforms in a composable way.
4
4
  * (c) Gearbox.fi, 2021
5
5
  */
6
-
6
+ import { objectEntries, keyToLowercase, swapKeyValue } from "../utils/mappers";
7
7
  import { AdapterInterface } from "./adapters";
8
8
  import { NetworkType } from "./constants";
9
9
  import { Protocols } from "./protocols";
10
- import { CurveLPToken, NormalToken, ConvexStakedPhantomToken, tokenDataByNetwork } from "./token";
11
-
10
+ import {
11
+ CurveLPToken,
12
+ NormalToken,
13
+ ConvexStakedPhantomToken,
14
+ tokenDataByNetwork
15
+ } from "./token";
12
16
 
13
17
  export type UniswapV2Contract = "UNISWAP_V2_ROUTER" | "SUSHISWAP_ROUTER";
14
18
 
@@ -119,77 +123,101 @@ export const contractsByNetwork: Record<
119
123
 
120
124
  export const UNISWAP_V3_QUOTER = "0xb27308f9f90d607463bb33ea1bebb41c27ce5ab6";
121
125
 
122
- export interface CurveSteCRVPoolParams {
126
+ export interface BaseContractParams {
127
+ name: string;
128
+ }
129
+
130
+ type UniswapV2Params = {
131
+ protocol: Protocols.Uniswap | Protocols.Sushiswap;
132
+ type: AdapterInterface.UNISWAP_V2_ROUTER;
133
+ } & BaseContractParams;
134
+
135
+ type UniswapV3Params = {
136
+ protocol: Protocols.Uniswap;
137
+ type: AdapterInterface.UNISWAP_V3_ROUTER;
138
+ quoter: string;
139
+ } & BaseContractParams;
140
+
141
+ type CurveParams = {
142
+ protocol: Protocols.Curve;
143
+ type:
144
+ | AdapterInterface.CURVE_V1_2ASSETS
145
+ | AdapterInterface.CURVE_V1_3ASSETS
146
+ | AdapterInterface.CURVE_V1_4ASSETS;
147
+ lpToken: CurveLPToken;
148
+ tokens: Array<NormalToken | CurveLPToken>;
149
+ } & BaseContractParams;
150
+
151
+ export type CurveSteCRVPoolParams = {
123
152
  protocol: Protocols.Curve;
124
153
  type: AdapterInterface.CURVE_V1_STECRV_POOL;
125
154
  pool: Record<NetworkType, string>;
126
155
  lpToken: "steCRV";
127
- }
156
+ } & BaseContractParams;
157
+
158
+ type YearnParams = {
159
+ protocol: Protocols.Yearn;
160
+ type: AdapterInterface.YEARN_V2;
161
+ } & BaseContractParams;
162
+
163
+ type ConvexParams = {
164
+ protocol: Protocols.Convex;
165
+ type:
166
+ | AdapterInterface.CONVEX_V1_BOOSTER
167
+ | AdapterInterface.CONVEX_V1_CLAIM_ZAP;
168
+ } & BaseContractParams;
169
+
170
+ type ConvexPoolParams = {
171
+ protocol: Protocols.Convex;
172
+ type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL;
173
+ stakedToken: ConvexStakedPhantomToken;
174
+ } & BaseContractParams;
128
175
 
129
- export interface LidoParams {
176
+ export type LidoParams = {
130
177
  protocol: Protocols.Lido;
131
178
  type: AdapterInterface.LIDO_V1;
132
179
  contract: Record<NetworkType, string>;
133
- }
180
+ lpToken: "steCRV";
181
+ } & BaseContractParams;
134
182
 
135
183
  export type ContractParams =
136
- | {
137
- protocol: Protocols.Uniswap | Protocols.Sushiswap;
138
- type: AdapterInterface.UNISWAP_V2_ROUTER;
139
- }
140
- | {
141
- protocol: Protocols.Uniswap;
142
- type: AdapterInterface.UNISWAP_V3_ROUTER;
143
- quoter: string;
144
- }
145
- | {
146
- protocol: Protocols.Curve;
147
- type:
148
- | AdapterInterface.CURVE_V1_2ASSETS
149
- | AdapterInterface.CURVE_V1_3ASSETS
150
- | AdapterInterface.CURVE_V1_4ASSETS;
151
- lpToken: CurveLPToken;
152
- tokens: Array<NormalToken | CurveLPToken>;
153
- }
184
+ | UniswapV2Params
185
+ | UniswapV3Params
186
+ | CurveParams
154
187
  | CurveSteCRVPoolParams
155
- | {
156
- protocol: Protocols.Yearn;
157
- type: AdapterInterface.YEARN_V2;
158
- }
159
- | {
160
- protocol: Protocols.Convex;
161
- type:
162
- | AdapterInterface.CONVEX_V1_BOOSTER
163
- | AdapterInterface.CONVEX_V1_CLAIM_ZAP;
164
- }
165
- | {
166
- protocol: Protocols.Convex;
167
- type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL;
168
- stakedToken: ConvexStakedPhantomToken;
169
- }
188
+ | YearnParams
189
+ | ConvexParams
190
+ | ConvexPoolParams
170
191
  | LidoParams;
171
192
 
172
193
  export const contractParams: Record<SupportedContract, ContractParams> = {
173
194
  UNISWAP_V2_ROUTER: {
195
+ name: "Uniswap V2",
174
196
  protocol: Protocols.Uniswap,
175
197
  type: AdapterInterface.UNISWAP_V2_ROUTER
176
198
  },
177
199
  UNISWAP_V3_ROUTER: {
200
+ name: "Uniswap V3",
178
201
  protocol: Protocols.Uniswap,
179
202
  quoter: UNISWAP_V3_QUOTER,
180
203
  type: AdapterInterface.UNISWAP_V3_ROUTER
181
204
  },
205
+
182
206
  SUSHISWAP_ROUTER: {
207
+ name: "Sushiswap",
183
208
  protocol: Protocols.Sushiswap,
184
209
  type: AdapterInterface.UNISWAP_V2_ROUTER
185
210
  },
211
+
186
212
  CURVE_3CRV_POOL: {
213
+ name: "Curve 3Pool",
187
214
  protocol: Protocols.Curve,
188
215
  type: AdapterInterface.CURVE_V1_3ASSETS,
189
216
  lpToken: "3Crv",
190
217
  tokens: ["DAI", "USDC", "USDT"]
191
218
  },
192
219
  CURVE_STETH_GATEWAY: {
220
+ name: "Curve stETH",
193
221
  protocol: Protocols.Curve,
194
222
  type: AdapterInterface.CURVE_V1_STECRV_POOL,
195
223
  pool: {
@@ -199,93 +227,120 @@ export const contractParams: Record<SupportedContract, ContractParams> = {
199
227
  lpToken: "steCRV"
200
228
  },
201
229
  CURVE_FRAX_POOL: {
230
+ name: "Curve FRAX",
202
231
  protocol: Protocols.Curve,
203
232
  type: AdapterInterface.CURVE_V1_2ASSETS,
204
233
  lpToken: "FRAX3CRV",
205
234
  tokens: ["3Crv", "FRAX"]
206
235
  },
207
236
  CURVE_LUSD_POOL: {
237
+ name: "Curve LUSD",
208
238
  protocol: Protocols.Curve,
209
239
  type: AdapterInterface.CURVE_V1_2ASSETS,
210
240
  lpToken: "LUSD3CRV",
211
241
  tokens: ["3Crv", "LUSD"]
212
242
  },
213
243
  CURVE_SUSD_POOL: {
244
+ name: "Curve SUSD",
214
245
  protocol: Protocols.Curve,
215
246
  type: AdapterInterface.CURVE_V1_4ASSETS,
216
247
  lpToken: "crvPlain3andSUSD",
217
248
  tokens: ["DAI", "USDC", "USDT", "sUSD"]
218
249
  },
219
250
  CURVE_GUSD_POOL: {
251
+ name: "Curve GUSD",
220
252
  protocol: Protocols.Curve,
221
253
  type: AdapterInterface.CURVE_V1_2ASSETS,
222
254
  lpToken: "gusd3CRV",
223
255
  tokens: ["3Crv", "FRAX"]
224
256
  },
257
+
225
258
  YEARN_DAI_VAULT: {
259
+ name: "Yearn DAI",
226
260
  protocol: Protocols.Yearn,
227
261
  type: AdapterInterface.YEARN_V2
228
262
  },
229
-
230
263
  YEARN_USDC_VAULT: {
264
+ name: "Yearn USDC",
231
265
  protocol: Protocols.Yearn,
232
266
  type: AdapterInterface.YEARN_V2
233
267
  },
234
268
  YEARN_WETH_VAULT: {
269
+ name: "Yearn WETH",
235
270
  protocol: Protocols.Yearn,
236
271
  type: AdapterInterface.YEARN_V2
237
272
  },
238
273
  YEARN_WBTC_VAULT: {
274
+ name: "Yearn WBTC",
239
275
  protocol: Protocols.Yearn,
240
276
  type: AdapterInterface.YEARN_V2
241
277
  },
242
278
  YEARN_CURVE_FRAX_VAULT: {
279
+ name: "Yearn Curve FRAX",
243
280
  protocol: Protocols.Yearn,
244
281
  type: AdapterInterface.YEARN_V2
245
282
  },
246
283
  YEARN_CURVE_STETH_VAULT: {
284
+ name: "Yearn Curve STETH",
247
285
  protocol: Protocols.Yearn,
248
286
  type: AdapterInterface.YEARN_V2
249
287
  },
288
+
250
289
  CONVEX_BOOSTER: {
290
+ name: "Convex BOOSTER",
251
291
  protocol: Protocols.Convex,
252
292
  type: AdapterInterface.CONVEX_V1_BOOSTER
253
293
  },
254
294
  CONVEX_3CRV_POOL: {
295
+ name: "Convex 3crv",
255
296
  protocol: Protocols.Convex,
256
297
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
257
298
  stakedToken: "stkcvx3Crv"
258
299
  },
259
300
  CONVEX_GUSD_POOL: {
301
+ name: "Convex GUSD",
260
302
  protocol: Protocols.Convex,
261
303
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
262
304
  stakedToken: "stkcvxgusd3CRV"
263
305
  },
264
306
  CONVEX_SUSD_POOL: {
307
+ name: "Convex SUSD",
265
308
  protocol: Protocols.Convex,
266
309
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
267
310
  stakedToken: "stkcvxcrvPlain3andSUSD"
268
311
  },
269
312
  CONVEX_STECRV_POOL: {
313
+ name: "Convex STECRV",
270
314
  protocol: Protocols.Convex,
271
315
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
272
316
  stakedToken: "stkcvxsteCRV"
273
317
  },
274
318
  CONVEX_FRAX3CRV_POOL: {
319
+ name: "Convex FRAX3CRV",
275
320
  protocol: Protocols.Convex,
276
321
  type: AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
277
322
  stakedToken: "stkcvxFRAX3CRV"
278
323
  },
279
324
  CONVEX_CLAIM_ZAP: {
325
+ name: "Convex ZAP",
280
326
  protocol: Protocols.Convex,
281
327
  type: AdapterInterface.CONVEX_V1_CLAIM_ZAP
282
328
  },
329
+
283
330
  LIDO_STETH_GATEWAY: {
331
+ name: "Lido STETH",
284
332
  protocol: Protocols.Lido,
285
333
  type: AdapterInterface.LIDO_V1,
286
334
  contract: {
287
335
  Mainnet: "0xae7ab96520de3a18e5e111b5eaab095312d7fe84",
288
336
  Kovan: ""
289
- }
337
+ },
338
+ lpToken: "steCRV"
290
339
  }
291
340
  };
341
+
342
+ export const contractsByAddress = objectEntries(contractsByNetwork).reduce<
343
+ Record<string, SupportedContract>
344
+ >((sum, [_, contracts]) => {
345
+ return { ...sum, ...keyToLowercase(swapKeyValue(contracts)) };
346
+ }, {});
@@ -1,4 +1,5 @@
1
-
1
+ import { keyToLowercase } from "../utils/mappers";
2
+ import { contractsByAddress, contractParams } from "./contracts";
2
3
 
3
4
  export const deployedContracts: Record<string, string> = {
4
5
  // MAINNET
@@ -11,8 +12,6 @@ export const deployedContracts: Record<string, string> = {
11
12
  "0xB2A015c71c17bCAC6af36645DEad8c572bA08A08": "WBTC",
12
13
  "0xC38478B0A4bAFE964C3526EEFF534d70E1E09017": "WBTC",
13
14
 
14
-
15
-
16
15
  // [UNISWAP_V2_ROUTER]: "Uniswap V2",
17
16
  // [UNISWAP_V3_ROUTER]: "Uniswap V3",
18
17
  // [CURVE_3CRV_POOL_ADDRESS]: "Curve 3Pool",
@@ -28,17 +27,26 @@ export const deployedContracts: Record<string, string> = {
28
27
  "0xe04b4db67127d1930D36f16B51653120C4285708": "WBTC",
29
28
  "0x600073357c29d169aAF3E543A4519749830553F1": "WETH",
30
29
  "0xdBAd1361d9A03B81Be8D3a54Ef0dc9e39a1bA5b3": "USDC",
31
- "0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI",
30
+ "0x50d1fA47b0D88BA0D108148B8481b4A762eFB99e": "DAI"
32
31
  // [YEARN_DAI_VAULT_KOVAN_MOCK]: "Yearn DAI",
33
32
  // [YEARN_USDC_VAULT_KOVAN_MOCK]: "Yearn USDC",
34
33
  // [SUSHISWAP_KOVAN]: "Sushiswap"
35
34
  };
36
35
 
36
+ const contractNames = Object.entries(contractsByAddress).reduce<
37
+ Record<string, string>
38
+ >((sum, [addr, cSymbol]) => {
39
+ const params = contractParams[cSymbol];
40
+ if (!params) return sum;
37
41
 
42
+ return { ...sum, [addr]: params.name };
43
+ }, {});
44
+
45
+ const contractsFullList = {
46
+ ...keyToLowercase(deployedContracts),
47
+ ...contractNames
48
+ };
38
49
 
39
50
  export function getContractName(address: string): string {
40
- Object.entries(deployedContracts).forEach(([addr, name]) => {
41
- deployedContracts[addr.toLowerCase()] = name;
42
- });
43
- return deployedContracts[address.toLowerCase()] || address;
51
+ return contractsFullList[address.toLowerCase()] || address;
44
52
  }
@@ -64,25 +64,39 @@ export class CreditAccountData {
64
64
  prices: Record<string, number>,
65
65
  tokens: Record<string, TokenData>
66
66
  ): Array<Balance> {
67
- const priceCalc = (addr: string, amount: BigNumber) =>
68
- amount
69
- .mul(Math.floor(1000 * prices[addr.toLowerCase() || ""] || 0))
70
- .div(BigNumber.from(10).pow(tokens[addr]?.decimals || 18));
71
-
72
- const tokensAbcComparator = (t1?: TokenData, t2?: TokenData) =>
73
- (t1?.symbol || "") > (t2?.symbol || "") ? 1 : -1;
74
-
75
- return tokens
76
- ? Object.entries(this.balances || [])
77
- .sort(([addr1, amount1], [addr2, amount2]) => {
78
- return priceCalc(addr1, amount1).eq(priceCalc(addr2, amount2))
79
- ? tokensAbcComparator(tokens[addr1], tokens[addr2])
80
- : priceCalc(addr1, amount1).gt(priceCalc(addr2, amount2))
81
- ? -1
82
- : 1;
83
- })
84
- .map(([address, balance]) => ({ address, balance }))
85
- : [];
67
+ const priceCalc = (addr: string, amount: BigNumber) => {
68
+ const price = prices[addr] || 0;
69
+ const { decimals = 18 } = tokens[addr] || {};
70
+
71
+ return amount
72
+ .mul(Math.floor(1000 * price))
73
+ .div(BigNumber.from(10).pow(decimals));
74
+ };
75
+
76
+ const tokensAbcComparator = (t1?: TokenData, t2?: TokenData) => {
77
+ const { symbol: symbol1 = "" } = t1 || {};
78
+ const { symbol: symbol2 = "" } = t2 || {};
79
+
80
+ return symbol1 > symbol2 ? 1 : -1;
81
+ };
82
+
83
+ const safeBalances = this.balances || [];
84
+
85
+ return Object.entries(safeBalances)
86
+ .sort(([addr1, amount1], [addr2, amount2]) => {
87
+ const addr1Lc = addr1.toLowerCase();
88
+ const addr2Lc = addr2.toLowerCase();
89
+
90
+ const price1 = priceCalc(addr1Lc, amount1);
91
+ const price2 = priceCalc(addr2Lc, amount2);
92
+
93
+ return price1.eq(price2)
94
+ ? tokensAbcComparator(tokens[addr1Lc], tokens[addr2Lc])
95
+ : price1.gt(price2)
96
+ ? -1
97
+ : 1;
98
+ })
99
+ .map(([address, balance]) => ({ address, balance }));
86
100
  }
87
101
  }
88
102