@gearbox-protocol/sdk 0.0.102 → 0.0.105
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 +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- 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.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- 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 +18 -15
- 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 +4 -4
- 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 +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- 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 +7 -3
- package/src/core/strategy.ts +27 -23
- 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 +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -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 +9 -5
- 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/strategies/yearn.ts
CHANGED
|
@@ -1,77 +1,204 @@
|
|
|
1
|
-
import { BigNumberish } from "ethers"
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BigNumberish } from "ethers";
|
|
4
2
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
contractParams,
|
|
4
|
+
contractsByNetwork,
|
|
5
|
+
YearnParams,
|
|
6
|
+
YearnVaultContract
|
|
7
|
+
} from "../contracts/contracts";
|
|
8
|
+
import { ADDRESS_0X0, NetworkType } from "../core/constants";
|
|
9
|
+
import { CreditManagerData } from "../core/creditManager";
|
|
10
|
+
import { CurveLPTokenData } from "../tokens/curveLP";
|
|
11
|
+
import { supportedTokens, tokenDataByNetwork } from "../tokens/token";
|
|
12
|
+
import { TokenType } from "../tokens/tokenType";
|
|
13
|
+
|
|
14
|
+
import { YearnV2Adapter__factory } from "../types";
|
|
7
15
|
|
|
8
16
|
import { MultiCallStruct } from "../types/contracts/interfaces/ICreditFacade.sol/ICreditFacade";
|
|
17
|
+
import { CurveStrategies } from "./curve";
|
|
18
|
+
import { UniswapV2Multicaller } from "./uniswapV2";
|
|
9
19
|
|
|
10
20
|
export class YearnV2Calls {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"deposit(uint256)",
|
|
22
|
-
[amount]
|
|
23
|
-
);
|
|
24
|
-
} else {
|
|
25
|
-
return contractInterface.encodeFunctionData(
|
|
26
|
-
"deposit()"
|
|
27
|
-
);
|
|
28
|
-
}
|
|
21
|
+
public static deposit(amount?: BigNumberish, recipient?: string): string {
|
|
22
|
+
const contractInterface = YearnV2Adapter__factory.createInterface();
|
|
23
|
+
if (amount && recipient) {
|
|
24
|
+
return contractInterface.encodeFunctionData("deposit(uint256,address)", [
|
|
25
|
+
amount,
|
|
26
|
+
recipient
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
if (amount) {
|
|
30
|
+
return contractInterface.encodeFunctionData("deposit(uint256)", [amount]);
|
|
29
31
|
}
|
|
32
|
+
return contractInterface.encodeFunctionData("deposit()");
|
|
33
|
+
}
|
|
30
34
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
[maxShares, recipient]
|
|
43
|
-
);
|
|
44
|
-
} else if (maxShares) {
|
|
45
|
-
return contractInterface.encodeFunctionData(
|
|
46
|
-
"withdraw(uint256)",
|
|
47
|
-
[maxShares]
|
|
48
|
-
);
|
|
49
|
-
} else {
|
|
50
|
-
return contractInterface.encodeFunctionData(
|
|
51
|
-
"withdraw()"
|
|
52
|
-
);
|
|
53
|
-
}
|
|
35
|
+
public static withdraw(
|
|
36
|
+
maxShares?: BigNumberish,
|
|
37
|
+
recipient?: string,
|
|
38
|
+
maxLoss?: BigNumberish
|
|
39
|
+
): string {
|
|
40
|
+
const contractInterface = YearnV2Adapter__factory.createInterface();
|
|
41
|
+
if (maxShares && recipient && maxLoss) {
|
|
42
|
+
return contractInterface.encodeFunctionData(
|
|
43
|
+
"withdraw(uint256,address,uint256)",
|
|
44
|
+
[maxShares, recipient, maxLoss]
|
|
45
|
+
);
|
|
54
46
|
}
|
|
47
|
+
if (maxShares && recipient) {
|
|
48
|
+
return contractInterface.encodeFunctionData("withdraw(uint256,address)", [
|
|
49
|
+
maxShares,
|
|
50
|
+
recipient
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
if (maxShares) {
|
|
54
|
+
return contractInterface.encodeFunctionData("withdraw(uint256)", [
|
|
55
|
+
maxShares
|
|
56
|
+
]);
|
|
57
|
+
}
|
|
58
|
+
return contractInterface.encodeFunctionData("withdraw()");
|
|
59
|
+
}
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
export class YearnV2Multicaller {
|
|
58
|
-
|
|
63
|
+
private readonly _address: string;
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
constructor(address: string) {
|
|
66
|
+
this._address = address;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static connect(address: string) {
|
|
70
|
+
return new YearnV2Multicaller(address);
|
|
71
|
+
}
|
|
63
72
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
deposit(amount?: BigNumberish, recipient?: string): MultiCallStruct {
|
|
74
|
+
return {
|
|
75
|
+
target: this._address,
|
|
76
|
+
callData: YearnV2Calls.deposit(amount, recipient)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
withdraw(
|
|
81
|
+
maxShares?: BigNumberish,
|
|
82
|
+
recipient?: string,
|
|
83
|
+
maxLoss?: BigNumberish
|
|
84
|
+
): MultiCallStruct {
|
|
85
|
+
return {
|
|
86
|
+
target: this._address,
|
|
87
|
+
callData: YearnV2Calls.withdraw(maxShares, recipient, maxLoss)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export class YearnV2Strategies {
|
|
93
|
+
static underlyingToYearn(
|
|
94
|
+
data: CreditManagerData,
|
|
95
|
+
network: NetworkType,
|
|
96
|
+
yearnVault: YearnVaultContract,
|
|
97
|
+
underlyingAmount: BigNumberish
|
|
98
|
+
) {
|
|
99
|
+
let calls: Array<MultiCallStruct> = [];
|
|
100
|
+
const vaultParams = contractParams[yearnVault] as YearnParams;
|
|
101
|
+
const yearnToken = vaultParams.shareToken;
|
|
102
|
+
const yearnParams = supportedTokens[yearnToken];
|
|
103
|
+
|
|
104
|
+
if (yearnParams.type === TokenType.YEARN_VAULT) {
|
|
105
|
+
if (
|
|
106
|
+
data.underlyingToken !==
|
|
107
|
+
tokenDataByNetwork[network][yearnParams.underlying]
|
|
108
|
+
) {
|
|
109
|
+
// This should be a pathfinder call
|
|
110
|
+
calls.push(
|
|
111
|
+
UniswapV2Multicaller.connect(
|
|
112
|
+
data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
|
|
113
|
+
).swapExactTokensForTokens(
|
|
114
|
+
underlyingAmount,
|
|
115
|
+
0,
|
|
116
|
+
[
|
|
117
|
+
data.underlyingToken,
|
|
118
|
+
tokenDataByNetwork[network][yearnParams.underlying]
|
|
119
|
+
],
|
|
120
|
+
ADDRESS_0X0,
|
|
121
|
+
Math.floor(new Date().getTime() / 1000) + 3600
|
|
122
|
+
)
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
} else if (
|
|
126
|
+
yearnParams.type === TokenType.YEARN_VAULT_OF_CURVE_LP ||
|
|
127
|
+
yearnParams.type === TokenType.YEARN_VAULT_OF_META_CURVE_LP
|
|
128
|
+
) {
|
|
129
|
+
const curveTokenParams = supportedTokens[
|
|
130
|
+
yearnParams.underlying
|
|
131
|
+
] as CurveLPTokenData;
|
|
132
|
+
const curvePool = curveTokenParams.pool;
|
|
133
|
+
|
|
134
|
+
calls = CurveStrategies.underlyingToCurveLP(
|
|
135
|
+
data,
|
|
136
|
+
network,
|
|
137
|
+
curvePool,
|
|
138
|
+
underlyingAmount
|
|
139
|
+
);
|
|
140
|
+
} else {
|
|
141
|
+
throw new Error("Yearn vault type unknown");
|
|
69
142
|
}
|
|
70
143
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
144
|
+
calls.push(
|
|
145
|
+
YearnV2Multicaller.connect(
|
|
146
|
+
data.adapters[contractsByNetwork[network][yearnVault]]
|
|
147
|
+
).deposit()
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static yearnToUnderlying(
|
|
152
|
+
data: CreditManagerData,
|
|
153
|
+
network: NetworkType,
|
|
154
|
+
yearnVault: YearnVaultContract,
|
|
155
|
+
yearnSharesAmount: BigNumberish
|
|
156
|
+
) {
|
|
157
|
+
let calls: Array<MultiCallStruct> = [];
|
|
158
|
+
const vaultParams = contractParams[yearnVault] as YearnParams;
|
|
159
|
+
const yearnToken = vaultParams.shareToken;
|
|
160
|
+
const yearnParams = supportedTokens[yearnToken];
|
|
161
|
+
|
|
162
|
+
calls.push(
|
|
163
|
+
YearnV2Multicaller.connect(
|
|
164
|
+
data.adapters[contractsByNetwork[network][yearnVault]]
|
|
165
|
+
).withdraw(yearnSharesAmount)
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (yearnParams.type === TokenType.YEARN_VAULT) {
|
|
169
|
+
if (
|
|
170
|
+
data.underlyingToken !==
|
|
171
|
+
tokenDataByNetwork[network][yearnParams.underlying]
|
|
172
|
+
) {
|
|
173
|
+
// This should be a pathfinder call
|
|
174
|
+
calls.push(
|
|
175
|
+
UniswapV2Multicaller.connect(
|
|
176
|
+
data.adapters[contractsByNetwork[network].UNISWAP_V2_ROUTER]
|
|
177
|
+
).swapAllTokensForTokens(
|
|
178
|
+
0,
|
|
179
|
+
[
|
|
180
|
+
tokenDataByNetwork[network][yearnParams.underlying],
|
|
181
|
+
data.underlyingToken
|
|
182
|
+
],
|
|
183
|
+
Math.floor(new Date().getTime() / 1000) + 3600
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
} else if (
|
|
188
|
+
yearnParams.type === TokenType.YEARN_VAULT_OF_CURVE_LP ||
|
|
189
|
+
yearnParams.type === TokenType.YEARN_VAULT_OF_META_CURVE_LP
|
|
190
|
+
) {
|
|
191
|
+
const curveTokenParams = supportedTokens[
|
|
192
|
+
yearnParams.underlying
|
|
193
|
+
] as CurveLPTokenData;
|
|
194
|
+
const curvePool = curveTokenParams.pool;
|
|
195
|
+
|
|
196
|
+
calls = [
|
|
197
|
+
...calls,
|
|
198
|
+
...CurveStrategies.allCurveLPToUnderlying(data, network, curvePool)
|
|
199
|
+
];
|
|
200
|
+
} else {
|
|
201
|
+
throw new Error("Yearn vault type unknown");
|
|
76
202
|
}
|
|
203
|
+
}
|
|
77
204
|
}
|
package/src/tokens/connectors.ts
CHANGED