@gearbox-protocol/sdk 0.0.101 → 0.0.104
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 +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +7 -9
- package/lib/apy/lidoAPY.js +35 -29
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/contracts/contractsRegister.js +13 -1
- package/lib/core/constants.d.ts +5 -3
- package/lib/core/constants.js +8 -6
- package/lib/core/creditAccount.d.ts +2 -2
- package/lib/core/creditAccount.js +12 -11
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +4 -10
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.d.ts +1 -3
- package/lib/core/price.js +9 -7
- package/lib/core/strategy.d.ts +8 -6
- package/lib/core/strategy.js +25 -25
- 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 -2
- package/lib/index.js +8 -1
- 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 -22
- package/lib/payload/creditAccount.d.ts +4 -4
- package/lib/payload/creditManager.d.ts +3 -13
- package/lib/payload/pool.d.ts +2 -2
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -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 +8 -8
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +13 -12
- package/src/apy/lidoAPY.ts +35 -27
- package/src/contracts/contracts.ts +27 -17
- package/src/contracts/contractsRegister.ts +16 -1
- package/src/core/constants.ts +8 -5
- package/src/core/creditAccount.ts +42 -16
- package/src/core/creditManager.ts +33 -7
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +10 -13
- package/src/core/strategy.ts +54 -43
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- 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 +17 -9
- 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 +32 -17
- package/src/payload/creditAccount.ts +4 -4
- package/src/payload/creditManager.ts +3 -13
- package/src/payload/pool.ts +2 -2
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +360 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +13 -9
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/core/strategy.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
import { LEVERAGE_DECIMALS, PERCENTAGE_FACTOR, WAD } from "./constants";
|
|
3
|
+
import { calcTotalPrice } from "./price";
|
|
2
4
|
|
|
3
5
|
export interface StrategyPayload {
|
|
4
6
|
apy?: number;
|
|
@@ -19,14 +21,23 @@ interface PoolStats {
|
|
|
19
21
|
|
|
20
22
|
type PoolList = Record<string, PoolStats>;
|
|
21
23
|
|
|
24
|
+
interface TokenDescription {
|
|
25
|
+
price: BigNumber;
|
|
26
|
+
amount: BigNumber;
|
|
27
|
+
decimals: number | undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
22
30
|
export class Strategy {
|
|
23
31
|
apy: number | undefined;
|
|
24
32
|
|
|
25
33
|
name: string;
|
|
34
|
+
|
|
26
35
|
lpToken: string;
|
|
36
|
+
|
|
27
37
|
pools: Array<string>;
|
|
28
38
|
|
|
29
39
|
unleveragableCollateral: Array<string>;
|
|
40
|
+
|
|
30
41
|
leveragableCollateral: Array<string>;
|
|
31
42
|
|
|
32
43
|
baseAssets: Array<string>;
|
|
@@ -42,10 +53,15 @@ export class Strategy {
|
|
|
42
53
|
this.baseAssets = payload.baseAssets;
|
|
43
54
|
}
|
|
44
55
|
|
|
45
|
-
public
|
|
46
|
-
const minApy =
|
|
56
|
+
public maxAPY(maxLeverage: number, poolApy: PoolList) {
|
|
57
|
+
const minApy = minBorrowApy(poolApy);
|
|
47
58
|
|
|
48
|
-
return
|
|
59
|
+
return roi(
|
|
60
|
+
this.apy || 0,
|
|
61
|
+
maxLeverage,
|
|
62
|
+
maxLeverage - LEVERAGE_DECIMALS,
|
|
63
|
+
minApy
|
|
64
|
+
);
|
|
49
65
|
}
|
|
50
66
|
|
|
51
67
|
public overallAPY(
|
|
@@ -56,50 +72,33 @@ export class Strategy {
|
|
|
56
72
|
) {
|
|
57
73
|
const farmLev = this.farmLev(leverage, depositCollateral);
|
|
58
74
|
|
|
59
|
-
return
|
|
75
|
+
return roi(apy, farmLev, leverage - LEVERAGE_DECIMALS, borrowAPY);
|
|
60
76
|
}
|
|
61
77
|
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this
|
|
62
79
|
public liquidationPrice(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ltCollateral:
|
|
67
|
-
|
|
68
|
-
depositCollateral: string
|
|
80
|
+
borrowed: TokenDescription,
|
|
81
|
+
collateral: TokenDescription,
|
|
82
|
+
lp: TokenDescription,
|
|
83
|
+
ltCollateral: BigNumber
|
|
69
84
|
) {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(leverage - LEVERAGE_DECIMALS - ltCollateral * (leverage - farmLev)) /
|
|
75
|
-
(ltStrategy * farmLev)
|
|
85
|
+
const borrowedMoney = calcTotalPrice(
|
|
86
|
+
borrowed.price,
|
|
87
|
+
borrowed.amount,
|
|
88
|
+
borrowed.decimals
|
|
76
89
|
);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
apy: number,
|
|
90
|
-
farmLev: number,
|
|
91
|
-
debtLev: number,
|
|
92
|
-
borrowAPY: number
|
|
93
|
-
) {
|
|
94
|
-
return (apy * farmLev - borrowAPY * debtLev) / LEVERAGE_DECIMALS;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private minBorrowApy(poolApy: PoolList) {
|
|
98
|
-
const apys = Object.values(poolApy).sort(
|
|
99
|
-
(a, b) => a.borrowRate - b.borrowRate
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
90
|
+
const collateralMoney = calcTotalPrice(
|
|
91
|
+
collateral.price,
|
|
92
|
+
collateral.amount,
|
|
93
|
+
collateral.decimals
|
|
94
|
+
)
|
|
95
|
+
.mul(ltCollateral)
|
|
96
|
+
.div(PERCENTAGE_FACTOR);
|
|
97
|
+
const lpMoney = calcTotalPrice(lp.price, lp.amount, lp.decimals);
|
|
98
|
+
|
|
99
|
+
return lpMoney.gt(0)
|
|
100
|
+
? borrowedMoney.sub(collateralMoney).mul(WAD).div(lpMoney)
|
|
101
|
+
: BigNumber.from(0);
|
|
103
102
|
}
|
|
104
103
|
|
|
105
104
|
private farmLev(leverage: number, depositCollateral: string) {
|
|
@@ -121,3 +120,15 @@ export class Strategy {
|
|
|
121
120
|
);
|
|
122
121
|
}
|
|
123
122
|
}
|
|
123
|
+
|
|
124
|
+
function roi(apy: number, farmLev: number, debtLev: number, borrowAPY: number) {
|
|
125
|
+
return (apy * farmLev - borrowAPY * debtLev) / LEVERAGE_DECIMALS;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function minBorrowApy(poolApy: PoolList) {
|
|
129
|
+
const apys = Object.values(poolApy).sort(
|
|
130
|
+
(a, b) => a.borrowRate - b.borrowRate
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
return apys.length > 0 ? apys[0].borrowRate : 0;
|
|
134
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {BigNumber} from "ethers";
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
2
|
|
|
3
3
|
export interface TokenShare {
|
|
4
4
|
holder: string;
|
|
@@ -10,5 +10,5 @@ export interface TokenShare {
|
|
|
10
10
|
export enum VotingPower {
|
|
11
11
|
A, // A-type voting power & A-type vesting parameters
|
|
12
12
|
B, // B-type voting power & B-type vesting parameters
|
|
13
|
-
ZERO_VOTING_POWER
|
|
13
|
+
ZERO_VOTING_POWER // zero voting power & B-type vesting parameters
|
|
14
14
|
}
|