@gearbox-protocol/sdk 0.0.100 → 0.0.103
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +4 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.d.ts +8 -0
- package/lib/apy/convexAPY.js +200 -0
- package/lib/apy/lidoAPY.d.ts +4 -0
- package/lib/apy/lidoAPY.js +103 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/contracts/contracts.d.ts +9 -4
- package/lib/contracts/contracts.js +52 -14
- package/lib/contracts/contractsRegister.js +16 -4
- package/lib/core/constants.d.ts +7 -1
- package/lib/core/constants.js +11 -5
- package/lib/core/creditAccount.d.ts +3 -1
- package/lib/core/creditAccount.js +33 -31
- package/lib/core/creditManager.d.ts +13 -2
- package/lib/core/creditManager.js +77 -33
- package/lib/core/creditSession.js +14 -3
- package/lib/core/errors.d.ts +10 -0
- package/lib/core/errors.js +16 -1
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +32 -30
- package/lib/core/multicall.d.ts +1 -1
- package/lib/core/pool.d.ts +2 -2
- package/lib/core/pool.js +8 -12
- package/lib/core/price.d.ts +2 -0
- package/lib/core/price.js +14 -0
- package/lib/core/strategy.d.ts +36 -0
- package/lib/core/strategy.js +57 -0
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -3
- package/lib/index.js +9 -4
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +22 -19
- package/lib/payload/creditAccount.d.ts +4 -26
- package/lib/payload/creditManager.d.ts +3 -25
- package/lib/payload/pool.d.ts +2 -17
- package/lib/payload/pool.js +0 -1
- package/lib/strategies/curve.d.ts +6 -60
- package/lib/strategies/curve.js +6 -0
- package/lib/strategies/uniswapV2.js +3 -19
- package/lib/strategies/uniswapV3.js +1 -1
- package/lib/strategies/yearn.js +15 -11
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +2 -2
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +9 -9
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +3 -3
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +2 -1
- package/lib/utils/formatter.js +23 -15
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.d.ts +2 -1
- package/lib/utils/mappers.js +13 -5
- package/lib/utils/multicall.js +4 -3
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/types.d.ts +1 -0
- package/lib/utils/validate.js +1 -1
- package/package.json +26 -8
- package/src/apy/convexAPY.ts +250 -0
- package/src/apy/lidoAPY.ts +89 -0
- package/src/config.ts +2 -1
- package/src/contracts/contracts.ts +73 -19
- package/src/contracts/contractsRegister.ts +19 -4
- package/src/core/constants.ts +11 -4
- package/src/core/creditAccount.ts +69 -37
- package/src/core/creditManager.ts +256 -148
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +25 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +978 -911
- package/src/core/history.ts +46 -46
- package/src/core/multicall.ts +1 -1
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +75 -58
- package/src/core/price.ts +13 -0
- package/src/core/strategy.ts +134 -0
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +9 -4
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +158 -150
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +79 -63
- package/src/payload/creditAccount.ts +4 -26
- package/src/payload/creditManager.ts +4 -26
- package/src/payload/pool.ts +2 -19
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +217 -210
- package/src/strategies/creditFacade.ts +70 -53
- package/src/strategies/curve.ts +263 -194
- package/src/strategies/lido.ts +33 -37
- package/src/strategies/uniswapV2.ts +90 -112
- package/src/strategies/uniswapV3.ts +114 -91
- package/src/strategies/yearn.ts +58 -62
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +170 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +19 -10
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +126 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +26 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +15 -6
- package/src/utils/multicall.ts +6 -9
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/types.ts +6 -2
- package/src/utils/validate.ts +1 -1
- package/lib/core/adapters.d.ts +0 -15
- package/lib/core/adapters.js +0 -19
- package/lib/core/contracts.d.ts +0 -67
- package/lib/core/contracts.js +0 -254
- package/lib/core/contractsRegister.d.ts +0 -2
- package/lib/core/contractsRegister.js +0 -58
- package/lib/core/creditCard.d.ts +0 -13
- package/lib/core/creditCard.js +0 -2
- package/lib/core/oracles.d.ts +0 -38
- package/lib/core/oracles.js +0 -12
- package/lib/core/priceFeeds.d.ts +0 -3
- package/lib/core/priceFeeds.js +0 -492
- package/lib/core/protocols.d.ts +0 -13
- package/lib/core/protocols.js +0 -39
- package/lib/core/swap.d.ts +0 -4
- package/lib/core/swap.js +0 -8
- package/lib/core/trade.d.ts +0 -35
- package/lib/core/trade.js +0 -62
- package/lib/core/tradeTypes.d.ts +0 -79
- package/lib/core/tradeTypes.js +0 -21
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/lib/tokens/convex.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TradeAction } from "../pathfinder/tradeTypes";
|
|
2
|
-
import { TokenBase } from "./token";
|
|
3
|
-
import { ConvexPoolContract } from "../contracts/contracts";
|
|
4
|
-
import { CurveLPToken } from "./curveLP";
|
|
2
|
+
import type { TokenBase } from "./token";
|
|
3
|
+
import type { ConvexPoolContract } from "../contracts/contracts";
|
|
4
|
+
import type { CurveLPToken } from "./curveLP";
|
|
5
5
|
import { TokenType } from "./tokenType";
|
|
6
6
|
export declare type ConvexLPToken = "cvx3Crv" | "cvxsteCRV" | "cvxFRAX3CRV" | "cvxLUSD3CRV" | "cvxcrvPlain3andSUSD" | "cvxgusd3CRV";
|
|
7
7
|
export declare type ConvexStakedPhantomToken = "stkcvx3Crv" | "stkcvxsteCRV" | "stkcvxFRAX3CRV" | "stkcvxLUSD3CRV" | "stkcvxcrvPlain3andSUSD" | "stkcvxgusd3CRV";
|
package/lib/tokens/curveLP.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
1
2
|
import { TradeAction } from "../pathfinder/tradeTypes";
|
|
2
|
-
import { SupportedToken, TokenBase } from "./token";
|
|
3
|
+
import type { SupportedToken, TokenBase } from "./token";
|
|
3
4
|
import { PartialRecord } from "../utils/types";
|
|
4
|
-
import { BigNumber } from "ethers";
|
|
5
5
|
import { TokenType } from "./tokenType";
|
|
6
6
|
export declare type CurveLPToken = "3Crv" | "steCRV" | "FRAX3CRV" | "LUSD3CRV" | "crvPlain3andSUSD" | "gusd3CRV";
|
|
7
7
|
export declare type CurveLPTokenData = {
|
package/lib/tokens/curveLP.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.curveTokens = exports.Curve3CrvUnderlyingTokenIndex = void 0;
|
|
4
|
-
var tradeTypes_1 = require("../pathfinder/tradeTypes");
|
|
5
4
|
var ethers_1 = require("ethers");
|
|
5
|
+
var tradeTypes_1 = require("../pathfinder/tradeTypes");
|
|
6
6
|
var tokenType_1 = require("./tokenType");
|
|
7
7
|
exports.Curve3CrvUnderlyingTokenIndex = {
|
|
8
8
|
DAI: ethers_1.BigNumber.from(0),
|
package/lib/tokens/gear.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TokenBase } from "./token";
|
|
2
|
-
import { TradeAction } from "../pathfinder/tradeTypes";
|
|
1
|
+
import type { TokenBase } from "./token";
|
|
2
|
+
import type { TradeAction } from "../pathfinder/tradeTypes";
|
|
3
3
|
import { TokenType } from "./tokenType";
|
|
4
4
|
export declare type DieselTokenTypes = "dDAI" | "dUSDC" | "dWBTC" | "dWETH";
|
|
5
5
|
export declare type GearboxToken = "GEAR";
|
package/lib/tokens/gear.js
CHANGED
package/lib/tokens/normal.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TradeAction } from "../pathfinder/tradeTypes";
|
|
2
|
-
import { TokenBase } from "./token";
|
|
2
|
+
import type { TokenBase } from "./token";
|
|
3
3
|
import { TokenType } from "./tokenType";
|
|
4
4
|
export declare type NormalToken = "1INCH" | "AAVE" | "COMP" | "CRV" | "DPI" | "FEI" | "LINK" | "SNX" | "SUSHI" | "UNI" | "USDT" | "USDC" | "DAI" | "WETH" | "WBTC" | "YFI" | "STETH" | "FTM" | "CVX" | "FRAX" | "FXS" | "LDO" | "SPELL" | "LUSD" | "sUSD" | "GUSD" | "LUNA" | "LQTY";
|
|
5
5
|
export declare type NormalTokenData = {
|
package/lib/tokens/token.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.tokenDataByNetwork = {
|
|
|
80
80
|
yvWBTC: "0xA696a63cc78DfFa1a63E9E50587C197387FF6C7E",
|
|
81
81
|
yvCurve_stETH: "0xdCD90C7f6324cfa40d7169ef80b12031770B4325",
|
|
82
82
|
yvCurve_FRAX: "0xB4AdA607B9d6b2c9Ee07A275e9616B84AC560139",
|
|
83
|
-
//GEARBOX
|
|
83
|
+
// GEARBOX
|
|
84
84
|
dDAI: "0x6CFaF95457d7688022FC53e7AbE052ef8DFBbdBA",
|
|
85
85
|
dUSDC: "0xc411dB5f5Eb3f7d552F9B8454B2D74097ccdE6E3",
|
|
86
86
|
dWBTC: "0xe753260F1955e8678DCeA8887759e07aa57E8c54",
|
|
@@ -150,15 +150,15 @@ exports.tokenDataByNetwork = {
|
|
|
150
150
|
stkcvxgusd3CRV: "0x9A74e8106f6c28b21b1B6a0F985cf1227BE05F04",
|
|
151
151
|
stkcvxsteCRV: "0xd8bAbB7EfBF7F931a69B209f71b27421F8b18516",
|
|
152
152
|
stkcvxcrvPlain3andSUSD: "0x6b45Cab756B41a7204973b71362ef5F73E67F6DA",
|
|
153
|
-
//GEARBOX
|
|
154
|
-
dDAI: "
|
|
155
|
-
dUSDC: "
|
|
156
|
-
dWBTC: "
|
|
157
|
-
dWETH: "
|
|
153
|
+
// GEARBOX
|
|
154
|
+
dDAI: "0x077a3Ce0D572b72436F6644793Fc7721353aF1f4",
|
|
155
|
+
dUSDC: "0x8147e00456c8A3128182730bFFdFd9D1E6bbC048",
|
|
156
|
+
dWBTC: "0x34D9B3c13B25632879B2DaabBde702F612902238",
|
|
157
|
+
dWETH: "0x19e4F905749D3b487CA4927b54e55b64625a1143",
|
|
158
158
|
GEAR: "0xe01c5d0297c56e992dab3886057a1441485ff7c7"
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
|
-
exports.tokenSymbolByAddress = (0, mappers_1.objectEntries)(exports.tokenDataByNetwork).reduce(function (
|
|
162
|
-
var
|
|
163
|
-
return __assign(__assign({},
|
|
161
|
+
exports.tokenSymbolByAddress = (0, mappers_1.objectEntries)(exports.tokenDataByNetwork).reduce(function (acc, _a) {
|
|
162
|
+
var tokens = _a[1];
|
|
163
|
+
return (__assign(__assign({}, acc), (0, mappers_1.filterEmptyKeys)((0, mappers_1.keyToLowercase)((0, mappers_1.swapKeyValue)(tokens)))));
|
|
164
164
|
}, {});
|
|
@@ -2,13 +2,14 @@ import { BigNumber } from "ethers";
|
|
|
2
2
|
import { TokenDataPayload } from "../payload/token";
|
|
3
3
|
import { NetworkType } from "../core/constants";
|
|
4
4
|
import { SupportedToken } from "./token";
|
|
5
|
+
declare type SymbolReplacements = Record<string, string>;
|
|
5
6
|
export declare class TokenData {
|
|
6
7
|
readonly id: string;
|
|
7
8
|
readonly symbol: string;
|
|
8
9
|
readonly address: string;
|
|
9
10
|
readonly decimals: number;
|
|
10
11
|
readonly icon?: string;
|
|
11
|
-
constructor(payload: TokenDataPayload);
|
|
12
|
+
constructor(payload: TokenDataPayload, symbolReplacements?: SymbolReplacements);
|
|
12
13
|
compareBySymbol(b: TokenData): number;
|
|
13
14
|
}
|
|
14
15
|
export interface TokenBalance {
|
|
@@ -22,3 +23,4 @@ export interface TokenAllowance {
|
|
|
22
23
|
export declare const WETHToken: Record<NetworkType, string>;
|
|
23
24
|
export declare const connectors: Record<NetworkType, Array<SupportedToken>>;
|
|
24
25
|
export declare function getConnectors(networkType: NetworkType): string[];
|
|
26
|
+
export {};
|
package/lib/tokens/tokenData.js
CHANGED
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getConnectors = exports.connectors = exports.WETHToken = exports.TokenData = void 0;
|
|
4
4
|
var config_1 = require("../config");
|
|
5
5
|
var token_1 = require("./token");
|
|
6
|
+
var defaultSymbolReplacement = {
|
|
7
|
+
dWETH: "dETH",
|
|
8
|
+
WETH: "ETH"
|
|
9
|
+
};
|
|
6
10
|
var TokenData = /** @class */ (function () {
|
|
7
|
-
function TokenData(payload) {
|
|
11
|
+
function TokenData(payload, symbolReplacements) {
|
|
12
|
+
if (symbolReplacements === void 0) { symbolReplacements = defaultSymbolReplacement; }
|
|
8
13
|
var _a;
|
|
9
14
|
this.id = payload.addr;
|
|
10
15
|
this.address = payload.addr;
|
|
11
16
|
// this.name = payload.name;
|
|
12
|
-
this.symbol = payload.symbol;
|
|
13
|
-
if (this.symbol === "WETH" || this.symbol === "dWETH") {
|
|
14
|
-
this.symbol = this.symbol.replace("WETH", "ETH");
|
|
15
|
-
}
|
|
17
|
+
this.symbol = symbolReplacements[payload.symbol] || payload.symbol;
|
|
16
18
|
this.decimals = payload.decimals;
|
|
17
19
|
this.icon = "".concat(config_1.STATIC_TOKEN).concat((_a = payload.symbol) === null || _a === void 0 ? void 0 : _a.toLowerCase(), ".svg");
|
|
18
20
|
}
|
|
@@ -24,7 +26,7 @@ var TokenData = /** @class */ (function () {
|
|
|
24
26
|
exports.TokenData = TokenData;
|
|
25
27
|
exports.WETHToken = {
|
|
26
28
|
Mainnet: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
27
|
-
Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
|
|
29
|
+
Kovan: "0xd0a1e359811322d97991e03f863a0c30c2cf029c"
|
|
28
30
|
};
|
|
29
31
|
exports.connectors = {
|
|
30
32
|
Mainnet: [
|
|
@@ -33,7 +35,7 @@ exports.connectors = {
|
|
|
33
35
|
"DAI",
|
|
34
36
|
"USDC",
|
|
35
37
|
// "USDT",
|
|
36
|
-
"WBTC"
|
|
38
|
+
"WBTC"
|
|
37
39
|
// "stETH",
|
|
38
40
|
// "PAX",
|
|
39
41
|
// "TUSD",
|
|
@@ -41,7 +43,7 @@ exports.connectors = {
|
|
|
41
43
|
// "BAL",
|
|
42
44
|
// "sUSD",
|
|
43
45
|
],
|
|
44
|
-
Kovan: ["WETH", "DAI", "USDC", "WBTC"]
|
|
46
|
+
Kovan: ["WETH", "DAI", "USDC", "WBTC"]
|
|
45
47
|
};
|
|
46
48
|
function getConnectors(networkType) {
|
|
47
49
|
return exports.connectors[networkType].map(function (e) {
|
package/lib/tokens/yearn.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TradeAction } from "../pathfinder/tradeTypes";
|
|
2
|
-
import { TokenBase } from "./token";
|
|
3
|
-
import { CurveLPToken } from "./curveLP";
|
|
4
|
-
import { NormalToken } from "./normal";
|
|
2
|
+
import type { TokenBase } from "./token";
|
|
3
|
+
import type { CurveLPToken } from "./curveLP";
|
|
4
|
+
import type { NormalToken } from "./normal";
|
|
5
5
|
import { TokenType } from "./tokenType";
|
|
6
6
|
export declare type YearnLPToken = "yvDAI" | "yvUSDC" | "yvWETH" | "yvWBTC" | "yvCurve_stETH" | "yvCurve_FRAX";
|
|
7
7
|
export declare type YearnVaultTokenData = {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMetamaskError = void 0;
|
|
4
|
+
var isMetamaskError = function (e) {
|
|
5
|
+
if (!e)
|
|
6
|
+
return false;
|
|
7
|
+
if (typeof e !== "object")
|
|
8
|
+
return false;
|
|
9
|
+
if (typeof e.code !== "number" || typeof e.message !== "string")
|
|
10
|
+
return false;
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
exports.isMetamaskError = isMetamaskError;
|
package/lib/utils/formatter.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BigNumber, BigNumberish } from "ethers";
|
|
2
2
|
export declare function rayToNumber(num: BigNumberish): number;
|
|
3
3
|
export declare function formatRAY(num?: BigNumber): string;
|
|
4
|
-
export declare function formatBN(
|
|
4
|
+
export declare function formatBN(numArg: BigNumberish | undefined, decimals: number, precisionArg?: number): string;
|
|
5
5
|
export declare function formatBn4dig(num: BigNumber, precision?: number): string;
|
|
6
6
|
export declare function toHumanFormat(num: BigNumber, precision?: number): string;
|
|
7
7
|
export declare function toSignificant(num: BigNumber, decimals: number): string;
|
|
@@ -11,3 +11,4 @@ export declare function shortHash(address?: string): string;
|
|
|
11
11
|
export declare const formatRate: (rate: BigNumberish | undefined) => string;
|
|
12
12
|
export declare function formatDate(date: Date): string;
|
|
13
13
|
export declare function formatHf(healthFactor: number): string;
|
|
14
|
+
export declare function formatLeverage(leverage: number, decimals?: number): string;
|
package/lib/utils/formatter.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.formatHf = exports.formatDate = exports.formatRate = exports.shortHash = exports.shortAddress = exports.toBN = exports.toSignificant = exports.toHumanFormat = exports.formatBn4dig = exports.formatBN = exports.formatRAY = exports.rayToNumber = void 0;
|
|
6
|
+
exports.formatLeverage = exports.formatHf = exports.formatDate = exports.formatRate = exports.shortHash = exports.shortAddress = exports.toBN = exports.toSignificant = exports.toHumanFormat = exports.formatBn4dig = exports.formatBN = exports.formatRAY = exports.rayToNumber = void 0;
|
|
7
7
|
var ethers_1 = require("ethers");
|
|
8
|
-
var constants_1 = require("../core/constants");
|
|
9
8
|
var decimal_js_light_1 = __importDefault(require("decimal.js-light"));
|
|
9
|
+
var constants_1 = require("../core/constants");
|
|
10
10
|
function rayToNumber(num) {
|
|
11
11
|
return (ethers_1.BigNumber.from(num).div(ethers_1.BigNumber.from(10).pow(21)).toNumber() / 1000000);
|
|
12
12
|
}
|
|
@@ -15,7 +15,9 @@ function formatRAY(num) {
|
|
|
15
15
|
return toSignificant(num || ethers_1.BigNumber.from(0), 27);
|
|
16
16
|
}
|
|
17
17
|
exports.formatRAY = formatRAY;
|
|
18
|
-
function formatBN(
|
|
18
|
+
function formatBN(numArg, decimals, precisionArg) {
|
|
19
|
+
var num = numArg;
|
|
20
|
+
var precision = precisionArg;
|
|
19
21
|
if (!num)
|
|
20
22
|
return "-";
|
|
21
23
|
// if (BigNumber.from(num).gt(BigNumber.from(10).pow(37))) {
|
|
@@ -54,22 +56,20 @@ function formatBn4dig(num, precision) {
|
|
|
54
56
|
if (numStr.length < 6)
|
|
55
57
|
numStr = "0".repeat(6 - numStr.length) + numStr;
|
|
56
58
|
return numStr.length <= 6
|
|
57
|
-
? "0."
|
|
58
|
-
: numStr.slice(0, numStr.length - 6) +
|
|
59
|
-
"." +
|
|
60
|
-
numStr.slice(numStr.length - 6, numStr.length - 6 + precision);
|
|
59
|
+
? "0.".concat(numStr.slice(0, precision))
|
|
60
|
+
: "".concat(numStr.slice(0, numStr.length - 6), ".").concat(numStr.slice(numStr.length - 6, numStr.length - 6 + precision));
|
|
61
61
|
}
|
|
62
62
|
exports.formatBn4dig = formatBn4dig;
|
|
63
63
|
function toHumanFormat(num, precision) {
|
|
64
64
|
if (precision === void 0) { precision = 2; }
|
|
65
65
|
if (num.gte(1e15)) {
|
|
66
|
-
return formatBn4dig(num.div(1e9), precision)
|
|
66
|
+
return "".concat(formatBn4dig(num.div(1e9), precision), "Bn");
|
|
67
67
|
}
|
|
68
68
|
if (num.gte(1e12)) {
|
|
69
|
-
return formatBn4dig(num.div(1e6), precision)
|
|
69
|
+
return "".concat(formatBn4dig(num.div(1e6), precision), "M");
|
|
70
70
|
}
|
|
71
71
|
if (num.gte(1e9)) {
|
|
72
|
-
return formatBn4dig(num.div(1e3), precision)
|
|
72
|
+
return "".concat(formatBn4dig(num.div(1e3), precision), "K");
|
|
73
73
|
}
|
|
74
74
|
return formatBn4dig(num, precision);
|
|
75
75
|
}
|
|
@@ -102,20 +102,23 @@ function shortHash(address) {
|
|
|
102
102
|
exports.shortHash = shortHash;
|
|
103
103
|
var formatRate = function (rate) {
|
|
104
104
|
return rate
|
|
105
|
-
? (ethers_1.BigNumber.from(rate)
|
|
105
|
+
? "".concat((ethers_1.BigNumber.from(rate)
|
|
106
106
|
.mul(constants_1.PERCENTAGE_FACTOR)
|
|
107
107
|
.mul(100)
|
|
108
108
|
.div(constants_1.RAY)
|
|
109
|
-
.toNumber() / constants_1.PERCENTAGE_FACTOR).toFixed(2)
|
|
109
|
+
.toNumber() / constants_1.PERCENTAGE_FACTOR).toFixed(2), "%")
|
|
110
110
|
: "0.00%";
|
|
111
111
|
};
|
|
112
112
|
exports.formatRate = formatRate;
|
|
113
113
|
function formatDate(date) {
|
|
114
|
-
var d = new Date(date)
|
|
114
|
+
var d = new Date(date);
|
|
115
|
+
var month = "".concat(d.getMonth() + 1);
|
|
116
|
+
var day = "".concat(d.getDate());
|
|
117
|
+
var year = d.getFullYear();
|
|
115
118
|
if (month.length < 2)
|
|
116
|
-
month = "0"
|
|
119
|
+
month = "0".concat(month);
|
|
117
120
|
if (day.length < 2)
|
|
118
|
-
day = "0"
|
|
121
|
+
day = "0".concat(day);
|
|
119
122
|
return [year, month, day].join("-");
|
|
120
123
|
}
|
|
121
124
|
exports.formatDate = formatDate;
|
|
@@ -123,3 +126,8 @@ function formatHf(healthFactor) {
|
|
|
123
126
|
return (healthFactor / 10000).toFixed(2);
|
|
124
127
|
}
|
|
125
128
|
exports.formatHf = formatHf;
|
|
129
|
+
function formatLeverage(leverage, decimals) {
|
|
130
|
+
if (decimals === void 0) { decimals = 2; }
|
|
131
|
+
return (leverage / constants_1.LEVERAGE_DECIMALS).toFixed(decimals);
|
|
132
|
+
}
|
|
133
|
+
exports.formatLeverage = formatLeverage;
|
package/lib/utils/loading.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function allLoaded(itemsToLoad: Array<unknown>): boolean;
|
|
2
|
+
export declare function loadingProgress(itemsToLoad: Array<unknown>): number;
|
package/lib/utils/loading.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loadingProgress = void 0;
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (item !== undefined)
|
|
13
|
-
isLoaded++;
|
|
14
|
-
}
|
|
15
|
-
return Math.floor((isLoaded / params.length) * 100);
|
|
3
|
+
exports.loadingProgress = exports.allLoaded = void 0;
|
|
4
|
+
var isLoaded = function (v) { return v !== undefined; };
|
|
5
|
+
function allLoaded(itemsToLoad) {
|
|
6
|
+
return itemsToLoad.reduce(function (acc, item) { return acc && isLoaded(item); }, true);
|
|
7
|
+
}
|
|
8
|
+
exports.allLoaded = allLoaded;
|
|
9
|
+
function loadingProgress(itemsToLoad) {
|
|
10
|
+
var loaded = itemsToLoad.reduce(function (acc, item) { return (isLoaded(item) ? acc + 1 : acc); }, 0);
|
|
11
|
+
return Math.floor((loaded / itemsToLoad.length) * 100);
|
|
16
12
|
}
|
|
17
13
|
exports.loadingProgress = loadingProgress;
|
package/lib/utils/mappers.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ declare type SupportedValue = string | number;
|
|
|
2
2
|
declare const objectEntries: <K extends SupportedValue, T>(o: Record<K, T>) => [K, T][];
|
|
3
3
|
declare const swapKeyValue: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<T, K>;
|
|
4
4
|
declare const keyToLowercase: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<K, T>;
|
|
5
|
+
declare const filterEmptyKeys: <K extends SupportedValue, T extends SupportedValue>(o: Record<K, T>) => Record<K, T>;
|
|
5
6
|
export type { SupportedValue };
|
|
6
|
-
export { objectEntries, swapKeyValue, keyToLowercase };
|
|
7
|
+
export { objectEntries, swapKeyValue, keyToLowercase, filterEmptyKeys };
|
package/lib/utils/mappers.js
CHANGED
|
@@ -11,23 +11,31 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = void 0;
|
|
14
|
+
exports.filterEmptyKeys = exports.keyToLowercase = exports.swapKeyValue = exports.objectEntries = void 0;
|
|
15
15
|
var objectEntries = function (o) { return Object.entries(o); };
|
|
16
16
|
exports.objectEntries = objectEntries;
|
|
17
17
|
var swapKeyValue = function (o) {
|
|
18
|
-
return objectEntries(o).reduce(function (
|
|
18
|
+
return objectEntries(o).reduce(function (acc, _a) {
|
|
19
19
|
var _b;
|
|
20
20
|
var key = _a[0], value = _a[1];
|
|
21
|
-
return __assign(__assign({},
|
|
21
|
+
return (__assign(__assign({}, acc), (_b = {}, _b[value] = key, _b)));
|
|
22
22
|
}, {});
|
|
23
23
|
};
|
|
24
24
|
exports.swapKeyValue = swapKeyValue;
|
|
25
25
|
var keyToLowercase = function (o) {
|
|
26
|
-
return objectEntries(o).reduce(function (
|
|
26
|
+
return objectEntries(o).reduce(function (acc, _a) {
|
|
27
27
|
var _b;
|
|
28
28
|
var key = _a[0], value = _a[1];
|
|
29
29
|
var keyTransformed = typeof key === "string" ? key.toLowerCase() : key;
|
|
30
|
-
return __assign(__assign({},
|
|
30
|
+
return __assign(__assign({}, acc), (_b = {}, _b[keyTransformed] = value, _b));
|
|
31
31
|
}, {});
|
|
32
32
|
};
|
|
33
33
|
exports.keyToLowercase = keyToLowercase;
|
|
34
|
+
var filterEmptyKeys = function (o) {
|
|
35
|
+
return objectEntries(o).reduce(function (acc, _a) {
|
|
36
|
+
var _b;
|
|
37
|
+
var key = _a[0], value = _a[1];
|
|
38
|
+
return (key ? __assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)) : acc);
|
|
39
|
+
}, {});
|
|
40
|
+
};
|
|
41
|
+
exports.filterEmptyKeys = filterEmptyKeys;
|
package/lib/utils/multicall.js
CHANGED
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.MultiCallContract = exports.multicall = void 0;
|
|
40
|
+
var config_1 = require("../config");
|
|
40
41
|
var types_1 = require("../types");
|
|
41
42
|
function multicall(calls, p) {
|
|
42
43
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -44,7 +45,7 @@ function multicall(calls, p) {
|
|
|
44
45
|
return __generator(this, function (_a) {
|
|
45
46
|
switch (_a.label) {
|
|
46
47
|
case 0:
|
|
47
|
-
multiCallContract = types_1.Multicall2__factory.connect(
|
|
48
|
+
multiCallContract = types_1.Multicall2__factory.connect(config_1.MULTICALL_ADDRESS, p);
|
|
48
49
|
return [4 /*yield*/, multiCallContract.callStatic.aggregate(calls.map(function (c) { return ({
|
|
49
50
|
target: c.address,
|
|
50
51
|
callData: c.interface.encodeFunctionData(c.method, c.params)
|
|
@@ -55,7 +56,7 @@ function multicall(calls, p) {
|
|
|
55
56
|
.map(function (d, num) {
|
|
56
57
|
return calls[num].interface.decodeFunctionResult(calls[num].method, d);
|
|
57
58
|
})
|
|
58
|
-
.map(function (r) { return r[0]; })];
|
|
59
|
+
.map(function (r) { return (Array.isArray(r) && r.length <= 1 ? r[0] : r); })];
|
|
59
60
|
}
|
|
60
61
|
});
|
|
61
62
|
});
|
|
@@ -65,7 +66,7 @@ var MultiCallContract = /** @class */ (function () {
|
|
|
65
66
|
function MultiCallContract(address, intrerface, provider) {
|
|
66
67
|
this._address = address;
|
|
67
68
|
this._interface = intrerface;
|
|
68
|
-
this._multiCall = types_1.Multicall2__factory.connect(
|
|
69
|
+
this._multiCall = types_1.Multicall2__factory.connect(config_1.MULTICALL_ADDRESS, provider);
|
|
69
70
|
}
|
|
70
71
|
MultiCallContract.prototype.call = function (data) {
|
|
71
72
|
return __awaiter(this, void 0, void 0, function () {
|
package/lib/utils/network.js
CHANGED
|
@@ -48,7 +48,7 @@ function detectNetwork(provider) {
|
|
|
48
48
|
case 0:
|
|
49
49
|
_c.trys.push([0, 2, , 7]);
|
|
50
50
|
usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Mainnet.USDC, provider);
|
|
51
|
-
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.
|
|
51
|
+
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
|
|
52
52
|
case 1:
|
|
53
53
|
_c.sent();
|
|
54
54
|
return [2 /*return*/, "Mainnet"];
|
|
@@ -58,7 +58,7 @@ function detectNetwork(provider) {
|
|
|
58
58
|
case 3:
|
|
59
59
|
_c.trys.push([3, 5, , 6]);
|
|
60
60
|
usdcMainnet = types_1.ERC20__factory.connect(token_1.tokenDataByNetwork.Kovan.USDC, provider);
|
|
61
|
-
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.
|
|
61
|
+
return [4 /*yield*/, usdcMainnet.balanceOf(constants_1.ADDRESS_0X0)];
|
|
62
62
|
case 4:
|
|
63
63
|
_c.sent();
|
|
64
64
|
return [2 /*return*/, "Kovan"];
|
package/lib/utils/repeater.js
CHANGED
|
@@ -40,32 +40,20 @@ exports.callRepeater = void 0;
|
|
|
40
40
|
function callRepeater(call, step) {
|
|
41
41
|
if (step === void 0) { step = 0; }
|
|
42
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var _this = this;
|
|
44
43
|
return __generator(this, function (_a) {
|
|
45
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return [3 /*break*/, 3];
|
|
56
|
-
case 2:
|
|
57
|
-
e_1 = _b.sent();
|
|
58
|
-
console.error("Error ".concat(step, ": ").concat(e_1));
|
|
59
|
-
if (step > 5 || e_1.code !== -32000)
|
|
60
|
-
reject(e_1);
|
|
61
|
-
else {
|
|
62
|
-
setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
|
|
63
|
-
}
|
|
64
|
-
return [3 /*break*/, 3];
|
|
65
|
-
case 3: return [2 /*return*/];
|
|
44
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
45
|
+
try {
|
|
46
|
+
call().then(function (r) { return resolve(r); });
|
|
47
|
+
}
|
|
48
|
+
catch (e) {
|
|
49
|
+
console.error("Error ".concat(step, ": ").concat(e));
|
|
50
|
+
if (step > 5 || e.code !== -32000)
|
|
51
|
+
reject(e);
|
|
52
|
+
else {
|
|
53
|
+
setTimeout(function () { return resolve(callRepeater(call, step + 1)); }, 200);
|
|
66
54
|
}
|
|
67
|
-
}
|
|
68
|
-
})
|
|
55
|
+
}
|
|
56
|
+
})];
|
|
69
57
|
});
|
|
70
58
|
});
|
|
71
59
|
}
|
package/lib/utils/types.d.ts
CHANGED
package/lib/utils/validate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.103",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -9,22 +9,40 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"dev": "tsc -w",
|
|
12
|
-
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish"
|
|
12
|
+
"pub": "rm -rf ./src/types/hardhat.ts && cp ./src/types/*.d.ts ./lib/types && tsc && yarn publish",
|
|
13
|
+
"lint": "eslint . --ext .tsx,.ts --fix",
|
|
14
|
+
"prepush": "yarn lint --max-warnings=0",
|
|
15
|
+
"prepare": "husky install"
|
|
13
16
|
},
|
|
14
17
|
"dependencies": {
|
|
15
18
|
"decimal.js-light": "^2.5.1",
|
|
16
|
-
"moment": "^2.29.1"
|
|
19
|
+
"moment": "^2.29.1",
|
|
20
|
+
"prettier": "^2.7.1"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
|
-
"@types/jest": "^26.0.
|
|
20
|
-
"@types/node": "^
|
|
23
|
+
"@types/jest": "^26.0.15",
|
|
24
|
+
"@types/node": "^17.0.41",
|
|
25
|
+
"@typescript-eslint/eslint-plugin": "^5.7.0",
|
|
26
|
+
"@typescript-eslint/parser": "^5.7.0",
|
|
21
27
|
"axios": "^0.27.2",
|
|
22
28
|
"dotenv": "^16.0.1",
|
|
23
|
-
"
|
|
29
|
+
"eslint": "^7.11.0",
|
|
30
|
+
"eslint-config-airbnb": "^19.0.2",
|
|
31
|
+
"eslint-config-airbnb-typescript": "^16.1.0",
|
|
32
|
+
"eslint-config-prettier": "^8.3.0",
|
|
33
|
+
"eslint-import-resolver-typescript": "^2.5.0",
|
|
34
|
+
"eslint-plugin-import": "^2.22.1",
|
|
35
|
+
"eslint-plugin-jsx-a11y": "^6.5.1",
|
|
36
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
37
|
+
"eslint-plugin-react": "^7.27.1",
|
|
38
|
+
"eslint-plugin-react-hooks": "^4.3.0",
|
|
39
|
+
"ethers": "5.6.9",
|
|
40
|
+
"husky": "^8.0.0",
|
|
41
|
+
"husky-init": "^8.0.0",
|
|
24
42
|
"jest": "^26.1.0",
|
|
25
|
-
"prettier": "^2.
|
|
43
|
+
"prettier": "^2.7.1",
|
|
26
44
|
"ts-node": "^10.1.0",
|
|
27
45
|
"tslog": "^3.3.3",
|
|
28
|
-
"typescript": "^4.
|
|
46
|
+
"typescript": "^4.7.3"
|
|
29
47
|
}
|
|
30
48
|
}
|