@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
|
@@ -1,101 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ConvexPoolContract,
|
|
3
|
+
CurvePoolContract,
|
|
4
|
+
UniswapV2Contract,
|
|
5
|
+
YearnVaultContract
|
|
6
|
+
} from "../contracts/contracts";
|
|
7
|
+
import type { NormalToken } from "../tokens/normal";
|
|
8
|
+
import type { CurveLPToken } from "../tokens/curveLP";
|
|
9
|
+
import type { YearnLPToken } from "../tokens/yearn";
|
|
10
|
+
import type { ConvexLPToken, ConvexStakedPhantomToken } from "../tokens/convex";
|
|
7
11
|
|
|
8
12
|
export enum TradeType {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
UniswapV2Swap,
|
|
14
|
+
UniswapV3Swap,
|
|
15
|
+
CurveExchange,
|
|
16
|
+
CurveExchangeUnderlying,
|
|
17
|
+
CurveDepositLP,
|
|
18
|
+
CurveWithdrawLP,
|
|
19
|
+
YearnDeposit,
|
|
20
|
+
YearnWithdraw,
|
|
21
|
+
LidoStake,
|
|
22
|
+
ConvexDepositLP,
|
|
23
|
+
ConvexStake,
|
|
24
|
+
ConvexDepositLPAndStake,
|
|
25
|
+
ConvexWithdrawLP,
|
|
26
|
+
ConvexWithdraw,
|
|
27
|
+
ConvexWithdrawAndUnwrap
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
export type TradeAction =
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
31
|
+
| {
|
|
32
|
+
type: TradeType.UniswapV2Swap;
|
|
33
|
+
contract: UniswapV2Contract;
|
|
34
|
+
tokenOut?: NormalToken;
|
|
35
|
+
}
|
|
36
|
+
| {
|
|
37
|
+
type: TradeType.UniswapV3Swap;
|
|
38
|
+
contract: "UNISWAP_V3_ROUTER";
|
|
39
|
+
tokenOut?: NormalToken;
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
type: TradeType.CurveExchange;
|
|
43
|
+
contract: CurvePoolContract;
|
|
44
|
+
tokenOut: Array<NormalToken | CurveLPToken>;
|
|
45
|
+
}
|
|
46
|
+
| {
|
|
47
|
+
type: TradeType.CurveDepositLP;
|
|
48
|
+
contract: CurvePoolContract;
|
|
49
|
+
tokenOut: CurveLPToken;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
type: TradeType.CurveWithdrawLP;
|
|
53
|
+
contract: CurvePoolContract;
|
|
54
|
+
tokenOut: Array<CurveLPToken | NormalToken>;
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
type: TradeType.YearnDeposit;
|
|
58
|
+
contract: YearnVaultContract;
|
|
59
|
+
tokenOut: YearnLPToken;
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
type: TradeType.YearnWithdraw;
|
|
63
|
+
contract: YearnVaultContract;
|
|
64
|
+
tokenOut: NormalToken | CurveLPToken;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
type: TradeType.LidoStake;
|
|
68
|
+
contract: "LIDO_STETH_GATEWAY";
|
|
69
|
+
tokenOut: NormalToken;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
type: TradeType.ConvexDepositLP;
|
|
73
|
+
contract: "CONVEX_BOOSTER";
|
|
74
|
+
tokenOut: ConvexLPToken;
|
|
75
|
+
}
|
|
76
|
+
| {
|
|
77
|
+
type: TradeType.ConvexStake;
|
|
78
|
+
contract: ConvexPoolContract;
|
|
79
|
+
tokenOut: ConvexStakedPhantomToken;
|
|
80
|
+
}
|
|
81
|
+
| {
|
|
82
|
+
type: TradeType.ConvexDepositLPAndStake;
|
|
83
|
+
contract: "CONVEX_BOOSTER";
|
|
84
|
+
tokenOut: ConvexStakedPhantomToken;
|
|
85
|
+
}
|
|
86
|
+
| {
|
|
87
|
+
type: TradeType.ConvexWithdrawLP;
|
|
88
|
+
contract: "CONVEX_BOOSTER";
|
|
89
|
+
tokenOut: CurveLPToken;
|
|
90
|
+
}
|
|
91
|
+
| {
|
|
92
|
+
type: TradeType.ConvexWithdraw;
|
|
93
|
+
contract: ConvexPoolContract;
|
|
94
|
+
tokenOut: ConvexLPToken;
|
|
95
|
+
}
|
|
96
|
+
| {
|
|
97
|
+
type: TradeType.ConvexWithdrawAndUnwrap;
|
|
98
|
+
contract: ConvexPoolContract;
|
|
99
|
+
tokenOut: CurveLPToken;
|
|
100
|
+
};
|
|
97
101
|
|
|
98
102
|
export enum SwapType {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
103
|
+
ExactInput = 1,
|
|
104
|
+
ExactOutput = 2
|
|
105
|
+
}
|
package/src/pathfinder/yVault.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import { BigNumber } from "ethers";
|
|
2
|
-
|
|
3
|
-
import { Path, LPWithdrawPathFinder } from "./path";
|
|
2
|
+
|
|
4
3
|
import { YearnLPToken, yearnTokens } from "../tokens/yearn";
|
|
5
4
|
import { NormalToken } from "../tokens/normal";
|
|
6
5
|
import { CurveLPToken } from "../tokens/curveLP";
|
|
7
6
|
import { SupportedToken, tokenDataByNetwork } from "../tokens/token";
|
|
7
|
+
|
|
8
8
|
import { PartialRecord } from "../utils/types";
|
|
9
9
|
import { MCall, multicall } from "../utils/multicall";
|
|
10
|
+
import { objectEntries } from "../utils/mappers";
|
|
11
|
+
|
|
12
|
+
import { IYVault__factory } from "../types";
|
|
10
13
|
import { IYVaultInterface } from "../types/contracts/integrations/yearn/IYVault";
|
|
11
14
|
|
|
15
|
+
import type { Path, LPWithdrawPathFinder } from "./path";
|
|
16
|
+
|
|
12
17
|
interface WithdrawBalance {
|
|
13
18
|
token: SupportedToken;
|
|
14
19
|
balance: BigNumber;
|
|
@@ -16,6 +21,7 @@ interface WithdrawBalance {
|
|
|
16
21
|
|
|
17
22
|
export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
18
23
|
_vault: YearnLPToken;
|
|
24
|
+
|
|
19
25
|
token: NormalToken | CurveLPToken;
|
|
20
26
|
|
|
21
27
|
constructor(vault: YearnLPToken) {
|
|
@@ -27,18 +33,27 @@ export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
|
27
33
|
this.token = currentTokenData.underlying;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
// eslint-disable-next-line class-methods-use-this
|
|
37
|
+
async findWithdrawPaths(path: Path): Promise<Array<Path>> {
|
|
38
|
+
// make path copy
|
|
39
|
+
const p: Path = Object.assign(
|
|
40
|
+
Object.create(Object.getPrototypeOf(path)),
|
|
41
|
+
path
|
|
42
|
+
);
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
const vaultBalances = objectEntries(yearnTokens).reduce<
|
|
45
|
+
PartialRecord<SupportedToken, WithdrawBalance>
|
|
46
|
+
>((acc, [yVault, tokenData]) => {
|
|
47
|
+
const typedVault = yVault;
|
|
48
|
+
const currentBalance = p.popBalance(typedVault);
|
|
35
49
|
if (currentBalance.gt(1)) {
|
|
36
|
-
|
|
50
|
+
acc[typedVault] = {
|
|
37
51
|
token: tokenData.underlying,
|
|
38
52
|
balance: currentBalance
|
|
39
53
|
};
|
|
40
54
|
}
|
|
41
|
-
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
42
57
|
|
|
43
58
|
const vaultList = Object.keys(vaultBalances) as Array<SupportedToken>;
|
|
44
59
|
|
|
@@ -53,7 +68,7 @@ export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
|
53
68
|
|
|
54
69
|
const prices = await multicall<Array<BigNumber>>(multicallData, p.provider);
|
|
55
70
|
|
|
56
|
-
for (let i = 0; i < vaultList.length; i
|
|
71
|
+
for (let i = 0; i < vaultList.length; i += 1) {
|
|
57
72
|
const vault = vaultList[i];
|
|
58
73
|
const vb = vaultBalances[vault];
|
|
59
74
|
|
|
@@ -61,15 +76,15 @@ export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
|
61
76
|
BigNumber.from(vb?.balance || 0).mul(prices[i])
|
|
62
77
|
);
|
|
63
78
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
const tokenAddress = tokenDataByNetwork[p.networkType][vault];
|
|
80
|
+
const adapterAddress = p.creditManager.adapters[tokenAddress];
|
|
81
|
+
|
|
82
|
+
const callData =
|
|
83
|
+
IYVault__factory.createInterface().encodeFunctionData("withdraw()");
|
|
84
|
+
|
|
85
|
+
p.calls.push({ target: adapterAddress, callData });
|
|
71
86
|
}
|
|
72
87
|
|
|
73
|
-
return
|
|
88
|
+
return p.withdrawTokens();
|
|
74
89
|
}
|
|
75
90
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
|
|
2
2
|
|
|
3
|
-
export type TokenBalancePayload =
|
|
3
|
+
export type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
4
4
|
|
|
5
|
-
export type CreditAccountDataPayload =
|
|
5
|
+
export type CreditAccountDataPayload = CreditAccountDataStruct;
|
|
6
6
|
|
|
7
|
-
export type CreditAccountDataExtendedPayload =
|
|
7
|
+
export type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
import { BigNumberish
|
|
2
|
-
import {
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
2
|
+
import { CreditManagerDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
3
3
|
|
|
4
4
|
export interface AdapterPayload {
|
|
5
5
|
allowedContract: string;
|
|
6
6
|
adapter: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export type CreditManagerDataPayload =
|
|
9
|
+
export type CreditManagerDataPayload = CreditManagerDataStruct;
|
|
10
10
|
|
|
11
11
|
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
12
|
-
addr: string;
|
|
13
|
-
underlyingToken?: string;
|
|
14
|
-
isWETH: boolean;
|
|
15
|
-
canBorrow: boolean;
|
|
16
|
-
borrowRate: BigNumber;
|
|
17
|
-
minAmount: BigNumber;
|
|
18
|
-
maxAmount: BigNumber;
|
|
19
|
-
maxLeverageFactor: BigNumber;
|
|
20
|
-
availableLiquidity: BigNumber;
|
|
21
|
-
allowedTokens: Array<string>;
|
|
22
12
|
allowedContracts?: Array<string>;
|
|
23
13
|
uniqueUsers: number;
|
|
24
14
|
openedAccountsCount?: number;
|
package/src/payload/pool.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
2
|
|
|
3
|
-
export type PoolDataPayload =
|
|
3
|
+
export type PoolDataPayload = PoolDataStruct;
|
package/src/payload/token.ts
CHANGED