@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/src/pathfinder/trade.ts
CHANGED
|
@@ -1,83 +1,90 @@
|
|
|
1
|
-
import {BigNumber} from "ethers";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {SwapType} from "./tradeTypes";
|
|
1
|
+
import { BigNumber, BytesLike } from "ethers";
|
|
2
|
+
import { PERCENTAGE_FACTOR, WAD } from "../core/constants";
|
|
3
|
+
import { SwapType } from "./tradeTypes";
|
|
5
4
|
|
|
6
5
|
export interface CloseTradePath {
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
path: Array<string>;
|
|
7
|
+
amountOutMin: BigNumber;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export class TradePath {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
11
|
+
public readonly swapType: SwapType;
|
|
12
|
+
|
|
13
|
+
public readonly amount: BigNumber;
|
|
14
|
+
|
|
15
|
+
public readonly rate: BigNumber;
|
|
16
|
+
|
|
17
|
+
public readonly path: Array<string>;
|
|
18
|
+
|
|
19
|
+
public readonly expectedAmount: BigNumber;
|
|
20
|
+
|
|
21
|
+
public readonly pathUniV3: BytesLike | undefined;
|
|
22
|
+
|
|
23
|
+
public readonly i: number | undefined;
|
|
24
|
+
|
|
25
|
+
public readonly j: number | undefined;
|
|
26
|
+
|
|
27
|
+
public readonly operationName: string | undefined;
|
|
28
|
+
|
|
29
|
+
constructor(params: {
|
|
30
|
+
swapType: SwapType;
|
|
31
|
+
amount: BigNumber;
|
|
32
|
+
path: Array<string>;
|
|
33
|
+
expectedAmount: BigNumber;
|
|
34
|
+
pathUniV3?: BytesLike;
|
|
35
|
+
i?: number;
|
|
36
|
+
j?: number;
|
|
37
|
+
operationName?: string;
|
|
38
|
+
}) {
|
|
39
|
+
this.swapType = params.swapType;
|
|
40
|
+
this.amount = params.amount;
|
|
41
|
+
this.path = params.path;
|
|
42
|
+
this.expectedAmount = params.expectedAmount;
|
|
43
|
+
this.pathUniV3 = params.pathUniV3;
|
|
44
|
+
this.rate =
|
|
45
|
+
params.swapType !== SwapType.ExactInput
|
|
46
|
+
? params.expectedAmount.mul(WAD).div(params.amount)
|
|
47
|
+
: WAD.mul(params.amount).div(params.expectedAmount);
|
|
48
|
+
this.i = params.i;
|
|
49
|
+
this.j = params.j;
|
|
50
|
+
this.operationName = params.operationName;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
getExpectedAmountWithSlippage(slippage: number): BigNumber {
|
|
54
|
+
return this.swapType === SwapType.ExactInput
|
|
55
|
+
? this.getAmountOutMin(slippage)
|
|
56
|
+
: this.getAmountInMax(slippage);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
getAmountInMax(slippage: number): BigNumber {
|
|
60
|
+
return this.expectedAmount
|
|
61
|
+
.mul(PERCENTAGE_FACTOR + slippage)
|
|
62
|
+
.div(PERCENTAGE_FACTOR);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getAmountOutMin(slippage: number): BigNumber {
|
|
66
|
+
return this.expectedAmount
|
|
67
|
+
.mul(PERCENTAGE_FACTOR)
|
|
68
|
+
.div(PERCENTAGE_FACTOR + slippage);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public get from(): string {
|
|
72
|
+
return this.path[0];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
public get to(): string {
|
|
76
|
+
return this.path[this.path.length - 1];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getFromAmount(slippage: number): BigNumber {
|
|
80
|
+
return this.swapType === SwapType.ExactInput
|
|
81
|
+
? this.amount
|
|
82
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
getToAmount(slippage: number): BigNumber {
|
|
86
|
+
return this.swapType === SwapType.ExactOutput
|
|
87
|
+
? this.amount
|
|
88
|
+
: this.getExpectedAmountWithSlippage(slippage);
|
|
89
|
+
}
|
|
83
90
|
}
|
|
@@ -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,74 +1,90 @@
|
|
|
1
|
-
import {BigNumber} from "ethers";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {PartialRecord} from "../utils/types";
|
|
9
|
-
import {MCall, multicall} from "../utils/multicall";
|
|
10
|
-
import {
|
|
1
|
+
import { BigNumber } from "ethers";
|
|
2
|
+
|
|
3
|
+
import { YearnLPToken, yearnTokens } from "../tokens/yearn";
|
|
4
|
+
import { NormalToken } from "../tokens/normal";
|
|
5
|
+
import { CurveLPToken } from "../tokens/curveLP";
|
|
6
|
+
import { SupportedToken, tokenDataByNetwork } from "../tokens/token";
|
|
7
|
+
|
|
8
|
+
import { PartialRecord } from "../utils/types";
|
|
9
|
+
import { MCall, multicall } from "../utils/multicall";
|
|
10
|
+
import { objectEntries } from "../utils/mappers";
|
|
11
|
+
|
|
12
|
+
import { IYVault__factory } from "../types";
|
|
13
|
+
import { IYVaultInterface } from "../types/contracts/integrations/yearn/IYVault";
|
|
14
|
+
|
|
15
|
+
import type { Path, LPWithdrawPathFinder } from "./path";
|
|
11
16
|
|
|
12
17
|
interface WithdrawBalance {
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
token: SupportedToken;
|
|
19
|
+
balance: BigNumber;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export class YearnVaultPathFinder implements LPWithdrawPathFinder {
|
|
18
|
-
|
|
19
|
-
token: NormalToken | CurveLPToken;
|
|
23
|
+
_vault: YearnLPToken;
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
this._vault = vault;
|
|
25
|
+
token: NormalToken | CurveLPToken;
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
constructor(vault: YearnLPToken) {
|
|
28
|
+
this._vault = vault;
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
const currentTokenData = yearnTokens[vault];
|
|
31
|
+
|
|
32
|
+
// Yearn Vault only has one lp action
|
|
33
|
+
this.token = currentTokenData.underlying;
|
|
34
|
+
}
|
|
35
|
+
|
|
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
|
+
);
|
|
43
|
+
|
|
44
|
+
const vaultBalances = objectEntries(yearnTokens).reduce<
|
|
45
|
+
PartialRecord<SupportedToken, WithdrawBalance>
|
|
46
|
+
>((acc, [yVault, tokenData]) => {
|
|
47
|
+
const typedVault = yVault;
|
|
48
|
+
const currentBalance = p.popBalance(typedVault);
|
|
49
|
+
if (currentBalance.gt(1)) {
|
|
50
|
+
acc[typedVault] = {
|
|
51
|
+
token: tokenData.underlying,
|
|
52
|
+
balance: currentBalance
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
29
57
|
|
|
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
|
-
const vb = vaultBalances[vault];
|
|
59
|
-
|
|
60
|
-
p.balances[vb!.token] = (p.balances[vb!.token] || BigNumber.from(0)).add(
|
|
61
|
-
BigNumber.from(vb?.balance || 0).mul(prices[i])
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
p.calls.push({
|
|
65
|
-
targetContract:
|
|
66
|
-
p.creditManager.adapters[tokenDataByNetwork[p.networkType][vault]],
|
|
67
|
-
callData:
|
|
68
|
-
IYVault__factory.createInterface().encodeFunctionData("withdraw()")
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return await p.withdrawTokens();
|
|
58
|
+
const vaultList = Object.keys(vaultBalances) as Array<SupportedToken>;
|
|
59
|
+
|
|
60
|
+
// Yearn Vault only has one lp action
|
|
61
|
+
const multicallData: Array<MCall<IYVaultInterface>> = vaultList
|
|
62
|
+
.map(t => tokenDataByNetwork[p.networkType][t as SupportedToken])
|
|
63
|
+
.map(addr => ({
|
|
64
|
+
address: addr,
|
|
65
|
+
interface: IYVault__factory.createInterface(),
|
|
66
|
+
method: "pricePerShare()"
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
const prices = await multicall<Array<BigNumber>>(multicallData, p.provider);
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < vaultList.length; i += 1) {
|
|
72
|
+
const vault = vaultList[i];
|
|
73
|
+
const vb = vaultBalances[vault];
|
|
74
|
+
|
|
75
|
+
p.balances[vb!.token] = (p.balances[vb!.token] || BigNumber.from(0)).add(
|
|
76
|
+
BigNumber.from(vb?.balance || 0).mul(prices[i])
|
|
77
|
+
);
|
|
78
|
+
|
|
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 });
|
|
73
86
|
}
|
|
87
|
+
|
|
88
|
+
return p.withdrawTokens();
|
|
89
|
+
}
|
|
74
90
|
}
|
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreditAccountDataStruct } from "../types/contracts/core/DataCompressor";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
token: string;
|
|
5
|
-
balance: BigNumberish;
|
|
6
|
-
isAllowed: boolean;
|
|
7
|
-
}
|
|
3
|
+
export type TokenBalancePayload = CreditAccountDataStruct["balances"];
|
|
8
4
|
|
|
9
|
-
export
|
|
10
|
-
addr: string;
|
|
11
|
-
borrower: string;
|
|
12
|
-
inUse: boolean;
|
|
13
|
-
creditManager: string;
|
|
14
|
-
underlyingToken: string;
|
|
15
|
-
borrowedAmountPlusInterest: BigNumberish;
|
|
16
|
-
totalValue: BigNumberish;
|
|
17
|
-
healthFactor: BigNumberish;
|
|
18
|
-
borrowRate: BigNumberish;
|
|
19
|
-
balances?: Array<TokenBalancePayload>;
|
|
20
|
-
}
|
|
5
|
+
export type CreditAccountDataPayload = CreditAccountDataStruct;
|
|
21
6
|
|
|
22
|
-
export
|
|
23
|
-
repayAmount: BigNumberish;
|
|
24
|
-
liquidationAmount: BigNumberish;
|
|
25
|
-
canBeClosed?: boolean;
|
|
26
|
-
borrowedAmount: BigNumberish;
|
|
27
|
-
cumulativeIndexAtOpen: BigNumberish;
|
|
28
|
-
since: BigNumberish;
|
|
29
|
-
}
|
|
7
|
+
export type CreditAccountDataExtendedPayload = CreditAccountDataStruct;
|
|
@@ -1,36 +1,14 @@
|
|
|
1
1
|
import { BigNumberish } from "ethers";
|
|
2
|
+
import { CreditManagerDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
3
|
|
|
3
4
|
export interface AdapterPayload {
|
|
4
5
|
allowedContract: string;
|
|
5
|
-
adapter: string
|
|
6
|
+
adapter: string;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export
|
|
9
|
-
addr: string;
|
|
10
|
-
hasAccount?: boolean;
|
|
11
|
-
underlyingToken?: string;
|
|
12
|
-
isWETH?: boolean;
|
|
13
|
-
canBorrow?: boolean;
|
|
14
|
-
borrowRate?: BigNumberish;
|
|
15
|
-
minAmount?: BigNumberish;
|
|
16
|
-
maxAmount?: BigNumberish;
|
|
17
|
-
maxLeverageFactor?: BigNumberish;
|
|
18
|
-
availableLiquidity?: BigNumberish;
|
|
19
|
-
allowedTokens?: Array<string>;
|
|
20
|
-
adapters?: Array<AdapterPayload>;
|
|
21
|
-
}
|
|
9
|
+
export type CreditManagerDataPayload = CreditManagerDataStruct;
|
|
22
10
|
|
|
23
|
-
export interface CreditManagerStatPayload {
|
|
24
|
-
addr: string;
|
|
25
|
-
underlyingToken?: string;
|
|
26
|
-
isWETH?: boolean;
|
|
27
|
-
canBorrow?: boolean;
|
|
28
|
-
borrowRate?: BigNumberish;
|
|
29
|
-
minAmount?: BigNumberish;
|
|
30
|
-
maxAmount?: BigNumberish;
|
|
31
|
-
maxLeverageFactor?: BigNumberish;
|
|
32
|
-
availableLiquidity?: BigNumberish;
|
|
33
|
-
allowedTokens?: Array<string>;
|
|
11
|
+
export interface CreditManagerStatPayload extends CreditManagerDataPayload {
|
|
34
12
|
allowedContracts?: Array<string>;
|
|
35
13
|
uniqueUsers: number;
|
|
36
14
|
openedAccountsCount?: number;
|
package/src/payload/pool.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PoolDataStruct } from "../types/contracts/interfaces/IDataCompressor.sol/IDataCompressor";
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
addr: string;
|
|
5
|
-
underlyingToken: string;
|
|
6
|
-
dieselToken: string;
|
|
7
|
-
isWETH: boolean;
|
|
8
|
-
expectedLiquidity: BigNumberish;
|
|
9
|
-
expectedLiquidityLimit?: BigNumberish;
|
|
10
|
-
availableLiquidity: BigNumberish;
|
|
11
|
-
totalBorrowed: BigNumberish;
|
|
12
|
-
depositAPY_RAY: BigNumberish;
|
|
13
|
-
borrowAPY_RAY: BigNumberish;
|
|
14
|
-
dieselRate_RAY: BigNumberish;
|
|
15
|
-
withdrawFee: BigNumberish;
|
|
16
|
-
timestampLU?: BigNumberish;
|
|
17
|
-
cumulativeIndex_RAY?: BigNumberish
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
//
|
|
3
|
+
export type PoolDataPayload = PoolDataStruct;
|
package/src/payload/token.ts
CHANGED