@gearbox-protocol/sdk 2.1.8 → 2.1.10
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/contracts/AdapterData.sol +10 -10
- package/contracts/PriceFeedDataLive.sol +211 -42
- package/lib/apy/convexAPY.d.ts +25 -16
- package/lib/apy/convexAPY.js +101 -71
- package/lib/contracts/contracts.d.ts +3 -0
- package/lib/contracts/contracts.js +30 -15
- package/lib/contracts/contractsRegister.d.ts +19 -8
- package/lib/contracts/contractsRegister.js +56 -27
- package/lib/core/creditManager.d.ts +1 -0
- package/lib/core/creditManager.js +13 -8
- package/lib/core/strategy.d.ts +5 -8
- package/lib/core/strategy.js +20 -39
- package/lib/core/strategy.spec.js +2 -5
- package/lib/oracles/pricefeedType.d.ts +3 -0
- package/lib/oracles/pricefeedType.js +3 -1
- package/lib/pathfinder/pathfinder.d.ts +3 -1
- package/lib/pathfinder/pathfinder.js +19 -10
- package/lib/tokens/gear.d.ts +1 -0
- package/lib/tokens/gear.js +7 -2
- package/lib/tokens/token.js +3 -6
- package/lib/utils/price.d.ts +1 -1
- package/package.json +1 -1
package/lib/apy/convexAPY.js
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCVXMintAmount = exports.getConvexAPYBulkCalls = exports.getConvexAPYBulk = void 0;
|
|
4
|
+
const utils_1 = require("ethers/lib/utils");
|
|
4
5
|
const contracts_1 = require("../contracts/contracts");
|
|
5
6
|
const constants_1 = require("../core/constants");
|
|
6
7
|
const token_1 = require("../tokens/token");
|
|
7
8
|
const types_1 = require("../types");
|
|
8
9
|
const formatter_1 = require("../utils/formatter");
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const V2_POOLS = { 20: true };
|
|
11
|
+
function getConvexAPYBulk(props) {
|
|
12
|
+
const { poolsInfo, calls } = props.generated;
|
|
11
13
|
const [parsedResponse] = calls.reduce(([acc, start], call) => {
|
|
12
14
|
const end = start + call.length;
|
|
13
|
-
const currentResponse = response.slice(start, end);
|
|
15
|
+
const currentResponse = props.response.slice(start, end);
|
|
14
16
|
acc.push(currentResponse);
|
|
15
17
|
return [acc, end];
|
|
16
18
|
}, [[], 0]);
|
|
17
|
-
const apyList = parsedResponse.map(([
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const apyList = parsedResponse.map(([cvxPoolRewardsFinish, cvxPoolRate, cvxPoolSupply, crvVPrice, cvxTokenSupply, ...rest], i) => {
|
|
20
|
+
const { cvxExtraPools, crvLpPrice: crvLpPriceList } = poolsInfo[i];
|
|
21
|
+
const extraEnd = cvxExtraPools.length;
|
|
22
|
+
const cvxExtraRewards = rest.slice(0, extraEnd);
|
|
23
|
+
const extraFinishEnd = cvxExtraPools.length * 2;
|
|
24
|
+
const cvxExtraRewardsFinish = rest.slice(extraEnd, extraFinishEnd);
|
|
25
|
+
const lpPriceEnd = extraFinishEnd + crvLpPriceList.length;
|
|
26
|
+
const crvLpPrice = rest.slice(extraFinishEnd, lpPriceEnd);
|
|
21
27
|
const apy = calculateConvexAPY({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
curveAPY,
|
|
34
|
-
tokenList,
|
|
28
|
+
cvxPoolRewardsFinish: (0, formatter_1.toBigInt)(cvxPoolRewardsFinish),
|
|
29
|
+
cvxPoolRate: (0, formatter_1.toBigInt)(cvxPoolRate),
|
|
30
|
+
cvxPoolSupply: (0, formatter_1.toBigInt)(cvxPoolSupply),
|
|
31
|
+
crvVPrice: (0, formatter_1.toBigInt)(crvVPrice),
|
|
32
|
+
cvxTokenSupply: (0, formatter_1.toBigInt)(cvxTokenSupply),
|
|
33
|
+
cvxExtraRewards: cvxExtraRewards.map(v => (0, formatter_1.toBigInt)(v)),
|
|
34
|
+
cvxExtraRewardsFinish: cvxExtraRewardsFinish.map(v => (0, formatter_1.toBigInt)(v)),
|
|
35
|
+
crvLpPrice: crvLpPrice.map(v => (0, formatter_1.toBigInt)(v)),
|
|
36
|
+
info: poolsInfo[i],
|
|
37
|
+
getTokenPrice: props.getTokenPrice,
|
|
38
|
+
curveAPY: props.curveAPY,
|
|
35
39
|
});
|
|
36
40
|
return apy;
|
|
37
41
|
});
|
|
@@ -42,118 +46,144 @@ function getPoolInfo({ pool, networkType }) {
|
|
|
42
46
|
const tokenList = token_1.tokenDataByNetwork[networkType];
|
|
43
47
|
const contractsList = contracts_1.contractsByNetwork[networkType];
|
|
44
48
|
const poolParams = contracts_1.contractParams[pool];
|
|
49
|
+
const basePoolAddress = contractsList[pool];
|
|
50
|
+
const extraPoolAddresses = poolParams.extraRewards.map(d => d.poolAddress[networkType]);
|
|
45
51
|
const stakedTokenParams = token_1.supportedTokens[poolParams.stakedToken];
|
|
46
52
|
const { underlying } = stakedTokenParams;
|
|
47
|
-
const basePoolAddress = contractsList[pool];
|
|
48
53
|
const crvParams = token_1.supportedTokens[underlying];
|
|
49
54
|
const swapPoolAddress = contractsList[crvParams.pool];
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const crvPoolParams = contracts_1.contractParams[crvParams.pool];
|
|
56
|
+
const crvLpPrice = V2_POOLS[crvPoolParams["version"]]
|
|
57
|
+
? [swapPoolAddress]
|
|
58
|
+
: [];
|
|
59
|
+
return {
|
|
60
|
+
cvxPool: poolParams,
|
|
61
|
+
cvxPoolAddress: basePoolAddress,
|
|
62
|
+
cvxExtraPools: extraPoolAddresses,
|
|
63
|
+
crvPoolAddress: swapPoolAddress,
|
|
64
|
+
crvPool: crvPoolParams,
|
|
65
|
+
crvToken: underlying,
|
|
66
|
+
crvLpPrice,
|
|
57
67
|
tokenList,
|
|
58
|
-
|
|
68
|
+
};
|
|
59
69
|
}
|
|
60
70
|
function getConvexAPYBulkCalls({ pools, networkType, }) {
|
|
61
71
|
const poolsInfo = pools.map(pool => getPoolInfo({ networkType, pool }));
|
|
62
|
-
const calls = poolsInfo.map(
|
|
63
|
-
basePoolAddress,
|
|
64
|
-
swapPoolAddress,
|
|
65
|
-
cvxAddress: tokenList.CVX,
|
|
66
|
-
extraPoolAddresses,
|
|
67
|
-
}));
|
|
72
|
+
const calls = poolsInfo.map(info => getPoolDataCalls(info));
|
|
68
73
|
return { poolsInfo, calls };
|
|
69
74
|
}
|
|
70
75
|
exports.getConvexAPYBulkCalls = getConvexAPYBulkCalls;
|
|
71
|
-
function getPoolDataCalls(
|
|
76
|
+
function getPoolDataCalls(props) {
|
|
72
77
|
const calls = [
|
|
73
78
|
{
|
|
74
|
-
address:
|
|
79
|
+
address: props.cvxPoolAddress,
|
|
75
80
|
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
76
81
|
method: "periodFinish()",
|
|
77
82
|
},
|
|
78
83
|
{
|
|
79
|
-
address:
|
|
84
|
+
address: props.cvxPoolAddress,
|
|
80
85
|
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
81
86
|
method: "rewardRate()",
|
|
82
87
|
},
|
|
83
88
|
{
|
|
84
|
-
address:
|
|
89
|
+
address: props.cvxPoolAddress,
|
|
85
90
|
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
86
91
|
method: "totalSupply()",
|
|
87
92
|
},
|
|
88
93
|
{
|
|
89
|
-
address:
|
|
94
|
+
address: props.crvPoolAddress,
|
|
90
95
|
interface: types_1.ICurvePool__factory.createInterface(),
|
|
91
96
|
method: "get_virtual_price()",
|
|
92
97
|
},
|
|
93
98
|
{
|
|
94
|
-
address:
|
|
99
|
+
address: props.tokenList.CVX,
|
|
95
100
|
interface: types_1.IConvexToken__factory.createInterface(),
|
|
96
101
|
method: "totalSupply()",
|
|
97
102
|
},
|
|
98
|
-
...
|
|
103
|
+
...props.cvxExtraPools.map((extraPoolAddress) => ({
|
|
99
104
|
address: extraPoolAddress,
|
|
100
105
|
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
101
106
|
method: "rewardRate()",
|
|
102
107
|
})),
|
|
103
|
-
...
|
|
108
|
+
...props.cvxExtraPools.map((extraPoolAddress) => ({
|
|
104
109
|
address: extraPoolAddress,
|
|
105
110
|
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
106
111
|
method: "periodFinish()",
|
|
107
112
|
})),
|
|
113
|
+
...(V2_POOLS[props.crvPool["version"]]
|
|
114
|
+
? [
|
|
115
|
+
{
|
|
116
|
+
address: props.crvPoolAddress,
|
|
117
|
+
interface: new utils_1.Interface([
|
|
118
|
+
"function lp_price() view returns (uint256)",
|
|
119
|
+
]),
|
|
120
|
+
method: "lp_price()",
|
|
121
|
+
},
|
|
122
|
+
]
|
|
123
|
+
: []),
|
|
108
124
|
];
|
|
109
125
|
return calls;
|
|
110
126
|
}
|
|
111
127
|
const CVX_MAX_SUPPLY = constants_1.WAD * 100000000n;
|
|
112
128
|
const CVX_REDUCTION_PER_CLIFF = 100000n;
|
|
113
129
|
const CVX_TOTAL_CLIFFS = constants_1.WAD * 1000n;
|
|
114
|
-
function getCVXMintAmount(crvAmount, cvxSupply) {
|
|
115
|
-
const currentCliff = cvxSupply / CVX_REDUCTION_PER_CLIFF;
|
|
116
|
-
if (currentCliff < CVX_TOTAL_CLIFFS) {
|
|
117
|
-
const remainingCliffs = CVX_TOTAL_CLIFFS - currentCliff;
|
|
118
|
-
const mintedAmount = (crvAmount * remainingCliffs) / CVX_TOTAL_CLIFFS;
|
|
119
|
-
const amountTillMax = CVX_MAX_SUPPLY - cvxSupply;
|
|
120
|
-
return mintedAmount > amountTillMax ? amountTillMax : mintedAmount;
|
|
121
|
-
}
|
|
122
|
-
return 0n;
|
|
123
|
-
}
|
|
124
|
-
exports.getCVXMintAmount = getCVXMintAmount;
|
|
125
|
-
function getTimestampInSeconds() {
|
|
126
|
-
return Math.floor(Date.now() / 1000);
|
|
127
|
-
}
|
|
128
130
|
const CURRENCY_LIST = {
|
|
129
131
|
stkcvxsteCRV: "WETH",
|
|
132
|
+
stkcvxcrvCVXETH: "WETH",
|
|
133
|
+
stkcvxcrvCRVETH: "WETH",
|
|
134
|
+
stkcvxLDOETH: "WETH",
|
|
135
|
+
stkcvxcrvUSDTWBTCWETH: "USDT",
|
|
130
136
|
};
|
|
131
|
-
function calculateConvexAPY(
|
|
137
|
+
function calculateConvexAPY(props) {
|
|
138
|
+
const { tokenList, cvxPool, crvToken, cvxExtraPools } = props.info;
|
|
132
139
|
const currentTimestamp = getTimestampInSeconds();
|
|
133
|
-
const currencySymbol = CURRENCY_LIST[
|
|
140
|
+
const currencySymbol = CURRENCY_LIST[cvxPool.stakedToken];
|
|
134
141
|
const currency = currencySymbol && tokenList[currencySymbol || ""];
|
|
135
|
-
const cvxPrice = getTokenPrice(tokenList.CVX, currency);
|
|
136
|
-
const crvPrice = getTokenPrice(tokenList.CRV, currency);
|
|
137
|
-
const crvPerSecond =
|
|
138
|
-
const
|
|
142
|
+
const cvxPrice = props.getTokenPrice(tokenList.CVX, currency);
|
|
143
|
+
const crvPrice = props.getTokenPrice(tokenList.CRV, currency);
|
|
144
|
+
const crvPerSecond = props.cvxPoolRate;
|
|
145
|
+
const vPrice = getVirtualPrice(props);
|
|
146
|
+
const virtualSupply = (props.cvxPoolSupply * vPrice) / constants_1.WAD;
|
|
139
147
|
const crvPerUnderlying = (crvPerSecond * constants_1.WAD) / virtualSupply;
|
|
140
148
|
const crvPerYear = crvPerUnderlying * BigInt(constants_1.SECONDS_PER_YEAR);
|
|
141
|
-
const cvxPerYear = getCVXMintAmount(crvPerYear,
|
|
142
|
-
const baseFinished =
|
|
149
|
+
const cvxPerYear = getCVXMintAmount(crvPerYear, props.cvxTokenSupply);
|
|
150
|
+
const baseFinished = props.cvxPoolRewardsFinish <= currentTimestamp;
|
|
143
151
|
const crvAPY = baseFinished ? 0n : (crvPerYear * crvPrice) / constants_1.PRICE_DECIMALS;
|
|
144
152
|
const cvxAPY = baseFinished ? 0n : (cvxPerYear * cvxPrice) / constants_1.PRICE_DECIMALS;
|
|
145
|
-
const extraAPRs =
|
|
146
|
-
const extraRewardSymbol =
|
|
147
|
-
const extraPoolRate =
|
|
148
|
-
const extraFinished =
|
|
153
|
+
const extraAPRs = cvxExtraPools.map((_, index) => {
|
|
154
|
+
const extraRewardSymbol = cvxPool.extraRewards[index].rewardToken;
|
|
155
|
+
const extraPoolRate = props.cvxExtraRewards[index];
|
|
156
|
+
const extraFinished = props.cvxExtraRewardsFinish[index];
|
|
149
157
|
const perUnderlying = (extraPoolRate * constants_1.WAD) / virtualSupply;
|
|
150
158
|
const perYear = perUnderlying * BigInt(constants_1.SECONDS_PER_YEAR);
|
|
151
|
-
const extraPrice = getTokenPrice(tokenList[extraRewardSymbol], currency);
|
|
159
|
+
const extraPrice = props.getTokenPrice(tokenList[extraRewardSymbol], currency);
|
|
152
160
|
const extraAPY = (perYear * extraPrice) / constants_1.PRICE_DECIMALS;
|
|
153
161
|
const finished = extraFinished <= currentTimestamp;
|
|
154
162
|
return finished ? 0n : extraAPY;
|
|
155
163
|
});
|
|
156
164
|
const extraAPYTotal = extraAPRs.reduce((acc, apy) => acc + apy, 0n);
|
|
157
|
-
const baseApyWAD = curveAPY[
|
|
165
|
+
const baseApyWAD = props.curveAPY[crvToken].base;
|
|
158
166
|
return baseApyWAD + crvAPY + cvxAPY + extraAPYTotal;
|
|
159
167
|
}
|
|
168
|
+
function getTimestampInSeconds() {
|
|
169
|
+
return Math.floor(Date.now() / 1000);
|
|
170
|
+
}
|
|
171
|
+
function getCVXMintAmount(crvAmount, cvxTokenSupply) {
|
|
172
|
+
const currentCliff = cvxTokenSupply / CVX_REDUCTION_PER_CLIFF;
|
|
173
|
+
if (currentCliff < CVX_TOTAL_CLIFFS) {
|
|
174
|
+
const remainingCliffs = CVX_TOTAL_CLIFFS - currentCliff;
|
|
175
|
+
const mintedAmount = (crvAmount * remainingCliffs) / CVX_TOTAL_CLIFFS;
|
|
176
|
+
const amountTillMax = CVX_MAX_SUPPLY - cvxTokenSupply;
|
|
177
|
+
return mintedAmount > amountTillMax ? amountTillMax : mintedAmount;
|
|
178
|
+
}
|
|
179
|
+
return 0n;
|
|
180
|
+
}
|
|
181
|
+
exports.getCVXMintAmount = getCVXMintAmount;
|
|
182
|
+
function getVirtualPrice(props) {
|
|
183
|
+
if (V2_POOLS[props.info.crvPool.version]) {
|
|
184
|
+
return props.crvLpPrice[0] ?? props.crvVPrice;
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
return props.crvVPrice;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -31,6 +31,7 @@ type UniswapV3Params = {
|
|
|
31
31
|
export type CurveParams = {
|
|
32
32
|
protocol: Protocols.Curve;
|
|
33
33
|
type: AdapterInterface.CURVE_V1_2ASSETS | AdapterInterface.CURVE_V1_3ASSETS | AdapterInterface.CURVE_V1_4ASSETS | AdapterInterface.CURVE_V1_WRAPPER;
|
|
34
|
+
version: number;
|
|
34
35
|
lpToken: CurveLPToken;
|
|
35
36
|
tokens: Array<NormalToken | CurveLPToken>;
|
|
36
37
|
underlyings?: Array<NormalToken>;
|
|
@@ -39,6 +40,7 @@ export type CurveParams = {
|
|
|
39
40
|
export type CurveSteCRVPoolParams = {
|
|
40
41
|
protocol: Protocols.Curve;
|
|
41
42
|
type: AdapterInterface.CURVE_V1_STECRV_POOL;
|
|
43
|
+
version: number;
|
|
42
44
|
pool: Record<NetworkType, string>;
|
|
43
45
|
tokens: ["WETH", "STETH"];
|
|
44
46
|
lpToken: "steCRV";
|
|
@@ -46,6 +48,7 @@ export type CurveSteCRVPoolParams = {
|
|
|
46
48
|
export type CurveGEARPoolParams = {
|
|
47
49
|
protocol: Protocols.Curve;
|
|
48
50
|
type: AdapterInterface.CURVE_V1_2ASSETS;
|
|
51
|
+
version: number;
|
|
49
52
|
pool: Record<NetworkType, string>;
|
|
50
53
|
tokens: ["GEAR", "WETH"];
|
|
51
54
|
lpToken: "GEAR";
|
|
@@ -167,6 +167,7 @@ exports.contractParams = {
|
|
|
167
167
|
name: "Curve 3Pool",
|
|
168
168
|
protocol: protocols_1.Protocols.Curve,
|
|
169
169
|
type: adapters_1.AdapterInterface.CURVE_V1_3ASSETS,
|
|
170
|
+
version: 10,
|
|
170
171
|
lpToken: "3Crv",
|
|
171
172
|
tokens: ["DAI", "USDC", "USDT"],
|
|
172
173
|
},
|
|
@@ -174,6 +175,7 @@ exports.contractParams = {
|
|
|
174
175
|
name: "Curve crvFRAX",
|
|
175
176
|
protocol: protocols_1.Protocols.Curve,
|
|
176
177
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
178
|
+
version: 10,
|
|
177
179
|
lpToken: "crvFRAX",
|
|
178
180
|
tokens: ["FRAX", "USDC"],
|
|
179
181
|
},
|
|
@@ -181,6 +183,7 @@ exports.contractParams = {
|
|
|
181
183
|
name: "Curve stETH",
|
|
182
184
|
protocol: protocols_1.Protocols.Curve,
|
|
183
185
|
type: adapters_1.AdapterInterface.CURVE_V1_STECRV_POOL,
|
|
186
|
+
version: 10,
|
|
184
187
|
pool: {
|
|
185
188
|
Mainnet: "0xDC24316b9AE028F1497c275EB9192a3Ea0f67022",
|
|
186
189
|
Arbitrum: constants_1.NOT_DEPLOYED, // CURVE_STECRV_POOL
|
|
@@ -192,6 +195,7 @@ exports.contractParams = {
|
|
|
192
195
|
name: "Curve GEAR",
|
|
193
196
|
protocol: protocols_1.Protocols.Curve,
|
|
194
197
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
198
|
+
version: 10,
|
|
195
199
|
pool: {
|
|
196
200
|
Mainnet: "0x0E9B5B092caD6F1c5E6bc7f89Ffe1abb5c95F1C2",
|
|
197
201
|
Arbitrum: constants_1.NOT_DEPLOYED,
|
|
@@ -203,6 +207,7 @@ exports.contractParams = {
|
|
|
203
207
|
name: "Curve FRAX",
|
|
204
208
|
protocol: protocols_1.Protocols.Curve,
|
|
205
209
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
210
|
+
version: 10,
|
|
206
211
|
lpToken: "FRAX3CRV",
|
|
207
212
|
tokens: ["FRAX", "3Crv"],
|
|
208
213
|
underlyings: ["FRAX", "DAI", "USDC", "USDT"],
|
|
@@ -211,6 +216,7 @@ exports.contractParams = {
|
|
|
211
216
|
name: "Curve LUSD",
|
|
212
217
|
protocol: protocols_1.Protocols.Curve,
|
|
213
218
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
219
|
+
version: 10,
|
|
214
220
|
lpToken: "LUSD3CRV",
|
|
215
221
|
tokens: ["LUSD", "3Crv"],
|
|
216
222
|
underlyings: ["LUSD", "DAI", "USDC", "USDT"],
|
|
@@ -219,6 +225,7 @@ exports.contractParams = {
|
|
|
219
225
|
name: "Curve SUSD",
|
|
220
226
|
protocol: protocols_1.Protocols.Curve,
|
|
221
227
|
type: adapters_1.AdapterInterface.CURVE_V1_4ASSETS,
|
|
228
|
+
version: 10,
|
|
222
229
|
lpToken: "crvPlain3andSUSD",
|
|
223
230
|
tokens: ["DAI", "USDC", "USDT", "sUSD"],
|
|
224
231
|
wrapper: "CURVE_SUSD_DEPOSIT",
|
|
@@ -227,6 +234,7 @@ exports.contractParams = {
|
|
|
227
234
|
name: "Curve SUSD",
|
|
228
235
|
protocol: protocols_1.Protocols.Curve,
|
|
229
236
|
type: adapters_1.AdapterInterface.CURVE_V1_WRAPPER,
|
|
237
|
+
version: 10,
|
|
230
238
|
lpToken: "crvPlain3andSUSD",
|
|
231
239
|
tokens: ["DAI", "USDC", "USDT", "sUSD"],
|
|
232
240
|
},
|
|
@@ -234,30 +242,34 @@ exports.contractParams = {
|
|
|
234
242
|
name: "Curve GUSD",
|
|
235
243
|
protocol: protocols_1.Protocols.Curve,
|
|
236
244
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
245
|
+
version: 10,
|
|
237
246
|
lpToken: "gusd3CRV",
|
|
238
247
|
tokens: ["GUSD", "3Crv"],
|
|
239
248
|
underlyings: ["GUSD", "DAI", "USDC", "USDT"],
|
|
240
249
|
},
|
|
241
|
-
CURVE_OHMFRAXBP_POOL: {
|
|
242
|
-
name: "Curve OHM_FRAXBP",
|
|
243
|
-
protocol: protocols_1.Protocols.Curve,
|
|
244
|
-
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
245
|
-
lpToken: "OHMFRAXBP",
|
|
246
|
-
tokens: ["OHM", "crvFRAX"],
|
|
247
|
-
underlyings: ["OHM", "FRAX", "USDC"],
|
|
248
|
-
},
|
|
249
250
|
CURVE_MIM_POOL: {
|
|
250
251
|
name: "Curve MIM",
|
|
251
252
|
protocol: protocols_1.Protocols.Curve,
|
|
252
253
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
254
|
+
version: 10,
|
|
253
255
|
lpToken: "MIM_3LP3CRV",
|
|
254
256
|
tokens: ["MIM", "3Crv"],
|
|
255
257
|
underlyings: ["MIM", "DAI", "USDC", "USDT"],
|
|
256
258
|
},
|
|
259
|
+
CURVE_OHMFRAXBP_POOL: {
|
|
260
|
+
name: "Curve OHM_FRAXBP",
|
|
261
|
+
protocol: protocols_1.Protocols.Curve,
|
|
262
|
+
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
263
|
+
version: 20,
|
|
264
|
+
lpToken: "OHMFRAXBP",
|
|
265
|
+
tokens: ["OHM", "crvFRAX"],
|
|
266
|
+
underlyings: ["OHM", "FRAX", "USDC"],
|
|
267
|
+
},
|
|
257
268
|
CURVE_CRVETH_POOL: {
|
|
258
269
|
name: "Curve CRVETH",
|
|
259
270
|
protocol: protocols_1.Protocols.Curve,
|
|
260
271
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
272
|
+
version: 20,
|
|
261
273
|
lpToken: "crvCRVETH",
|
|
262
274
|
tokens: ["WETH", "CRV"],
|
|
263
275
|
},
|
|
@@ -265,6 +277,7 @@ exports.contractParams = {
|
|
|
265
277
|
name: "Curve CVXETH",
|
|
266
278
|
protocol: protocols_1.Protocols.Curve,
|
|
267
279
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
280
|
+
version: 20,
|
|
268
281
|
lpToken: "crvCVXETH",
|
|
269
282
|
tokens: ["WETH", "CVX"],
|
|
270
283
|
},
|
|
@@ -272,6 +285,7 @@ exports.contractParams = {
|
|
|
272
285
|
name: "Curve 3Crypto",
|
|
273
286
|
protocol: protocols_1.Protocols.Curve,
|
|
274
287
|
type: adapters_1.AdapterInterface.CURVE_V1_3ASSETS,
|
|
288
|
+
version: 20,
|
|
275
289
|
lpToken: "crvUSDTWBTCWETH",
|
|
276
290
|
tokens: ["USDT", "WBTC", "WETH"],
|
|
277
291
|
},
|
|
@@ -279,6 +293,7 @@ exports.contractParams = {
|
|
|
279
293
|
name: "Curve LDOETH",
|
|
280
294
|
protocol: protocols_1.Protocols.Curve,
|
|
281
295
|
type: adapters_1.AdapterInterface.CURVE_V1_2ASSETS,
|
|
296
|
+
version: 20,
|
|
282
297
|
lpToken: "LDOETH",
|
|
283
298
|
tokens: ["WETH", "LDO"],
|
|
284
299
|
},
|
|
@@ -409,13 +424,6 @@ exports.contractParams = {
|
|
|
409
424
|
},
|
|
410
425
|
],
|
|
411
426
|
},
|
|
412
|
-
CONVEX_OHMFRAXBP_POOL: {
|
|
413
|
-
name: "Convex OHMFRAXBP",
|
|
414
|
-
protocol: protocols_1.Protocols.Convex,
|
|
415
|
-
type: adapters_1.AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
|
|
416
|
-
stakedToken: "stkcvxOHMFRAXBP",
|
|
417
|
-
extraRewards: [],
|
|
418
|
-
},
|
|
419
427
|
CONVEX_MIM3CRV_POOL: {
|
|
420
428
|
name: "Convex MIM3CRV",
|
|
421
429
|
protocol: protocols_1.Protocols.Convex,
|
|
@@ -431,6 +439,13 @@ exports.contractParams = {
|
|
|
431
439
|
},
|
|
432
440
|
],
|
|
433
441
|
},
|
|
442
|
+
CONVEX_OHMFRAXBP_POOL: {
|
|
443
|
+
name: "Convex OHMFRAXBP",
|
|
444
|
+
protocol: protocols_1.Protocols.Convex,
|
|
445
|
+
type: adapters_1.AdapterInterface.CONVEX_V1_BASE_REWARD_POOL,
|
|
446
|
+
stakedToken: "stkcvxOHMFRAXBP",
|
|
447
|
+
extraRewards: [],
|
|
448
|
+
},
|
|
434
449
|
CONVEX_CRVETH_POOL: {
|
|
435
450
|
name: "Convex crvCRVETH",
|
|
436
451
|
protocol: protocols_1.Protocols.Convex,
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
import { NetworkType } from "../core/chains";
|
|
2
2
|
export declare const stEthPoolWrapper: Record<NetworkType, string>;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
type MainnetCreditManagersV1 = "DAI_V1" | "USDC_V1" | "WETH_V1" | "WBTC_V1";
|
|
4
|
+
type MainnetCreditManagersV2 = "DAI_V2" | "USDC_V2" | "WETH_V2" | "WSTETH_V2" | "WBTC_V2" | "FRAX_V2";
|
|
5
|
+
type MainnetCreditManagersV2_1 = "WETH_V2_1";
|
|
6
|
+
export type MainnetCreditManagers = MainnetCreditManagersV1 | MainnetCreditManagersV2 | MainnetCreditManagersV2_1;
|
|
7
|
+
export type ArbitrumCreditManagers = never;
|
|
8
|
+
type CreditManagersListType = {
|
|
9
|
+
[key in NetworkType]: key extends "Mainnet" ? Record<MainnetCreditManagers, string> : key extends "Arbitrum" ? Record<ArbitrumCreditManagers, string> : never;
|
|
10
|
+
};
|
|
11
|
+
export declare const creditManagerByNetwork: CreditManagersListType;
|
|
12
|
+
export type SupportedCreditManagers = MainnetCreditManagers | ArbitrumCreditManagers;
|
|
13
|
+
export declare const creditManagerByAddress: Record<string, SupportedCreditManagers>;
|
|
14
|
+
export type MainnetPools = "DAI_V1" | "USDC_V1" | "WETH_V1" | "WBTC_V1" | "WSTETH_V1" | "FRAX_V1";
|
|
15
|
+
export type ArbitrumPools = never;
|
|
16
|
+
type PoolsListType = {
|
|
17
|
+
[key in NetworkType]: key extends "Mainnet" ? Record<MainnetPools, string> : key extends "Arbitrum" ? Record<ArbitrumPools, string> : never;
|
|
18
|
+
};
|
|
19
|
+
export declare const poolByNetwork: PoolsListType;
|
|
20
|
+
export type SupportedCreditPools = MainnetPools | ArbitrumPools;
|
|
11
21
|
export declare function getContractName(address: string): string;
|
|
22
|
+
export {};
|
|
@@ -1,38 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getContractName = exports.
|
|
3
|
+
exports.getContractName = exports.poolByNetwork = exports.creditManagerByAddress = exports.creditManagerByNetwork = exports.stEthPoolWrapper = void 0;
|
|
4
4
|
const mappers_1 = require("../utils/mappers");
|
|
5
5
|
const contracts_1 = require("./contracts");
|
|
6
6
|
exports.stEthPoolWrapper = {
|
|
7
7
|
Mainnet: "0x5a97e3E43dCBFe620ccF7865739075f92E93F5E4",
|
|
8
8
|
Arbitrum: "0x3fe62a62C022A069952069b32C9d56718D30B7ec",
|
|
9
9
|
};
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
10
|
+
exports.creditManagerByNetwork = {
|
|
11
|
+
Mainnet: {
|
|
12
|
+
DAI_V1: "0x777E23A2AcB2fCbB35f6ccF98272d03C722Ba6EB".toLowerCase(),
|
|
13
|
+
USDC_V1: "0x2664cc24CBAd28749B3Dd6fC97A6B402484De527".toLowerCase(),
|
|
14
|
+
WETH_V1: "0x968f9a68a98819E2e6Bb910466e191A7b6cf02F0".toLowerCase(),
|
|
15
|
+
WBTC_V1: "0xC38478B0A4bAFE964C3526EEFF534d70E1E09017".toLowerCase(),
|
|
16
|
+
DAI_V2: "0x672461Bfc20DD783444a830Ad4c38b345aB6E2f7".toLowerCase(),
|
|
17
|
+
USDC_V2: "0x95357303f995e184A7998dA6C6eA35cC728A1900".toLowerCase(),
|
|
18
|
+
WETH_V2: "0x5887ad4Cb2352E7F01527035fAa3AE0Ef2cE2b9B".toLowerCase(),
|
|
19
|
+
WSTETH_V2: "0xe0bCE4460795281d39c91da9B0275BcA968293de".toLowerCase(),
|
|
20
|
+
WBTC_V2: "0xc62BF8a7889AdF1c5Dc4665486c7683ae6E74e0F".toLowerCase(),
|
|
21
|
+
FRAX_V2: "0xA3E1e0d58FE8dD8C9dd48204699a1178f1B274D8".toLowerCase(),
|
|
22
|
+
WETH_V2_1: "0x4C6309fe2085EfE7A0Cfb426C16Ef3b41198cCE3".toLowerCase(),
|
|
23
|
+
},
|
|
24
|
+
Arbitrum: {},
|
|
25
|
+
};
|
|
26
|
+
exports.creditManagerByAddress = mappers_1.TypedObjectUtils.entries(exports.creditManagerByNetwork).reduce((acc, [, cms]) => ({
|
|
27
|
+
...acc,
|
|
28
|
+
...mappers_1.TypedObjectUtils.fromEntries(mappers_1.TypedObjectUtils.entries(cms)
|
|
29
|
+
.map(([k, v]) => [v.toLowerCase(), k])
|
|
30
|
+
.filter(k => !!k)),
|
|
31
|
+
}), {});
|
|
32
|
+
exports.poolByNetwork = {
|
|
33
|
+
Mainnet: {
|
|
34
|
+
DAI_V1: "0x24946bCbBd028D5ABb62ad9B635EB1b1a67AF668".toLowerCase(),
|
|
35
|
+
USDC_V1: "0x86130bDD69143D8a4E5fc50bf4323D48049E98E4".toLowerCase(),
|
|
36
|
+
WETH_V1: "0xB03670c20F87f2169A7c4eBE35746007e9575901".toLowerCase(),
|
|
37
|
+
WBTC_V1: "0xB2A015c71c17bCAC6af36645DEad8c572bA08A08".toLowerCase(),
|
|
38
|
+
WSTETH_V1: "0xB8cf3Ed326bB0E51454361Fb37E9E8df6DC5C286".toLowerCase(),
|
|
39
|
+
FRAX_V1: "0x79012c8d491dcf3a30db20d1f449b14caf01da6c".toLowerCase(),
|
|
40
|
+
},
|
|
41
|
+
Arbitrum: {},
|
|
42
|
+
};
|
|
43
|
+
const deployedContractNames = {
|
|
44
|
+
// MAINNET V1 CM
|
|
45
|
+
[exports.creditManagerByNetwork.Mainnet.DAI_V1]: "DAI",
|
|
46
|
+
[exports.creditManagerByNetwork.Mainnet.USDC_V1]: "USDC",
|
|
47
|
+
[exports.creditManagerByNetwork.Mainnet.WETH_V1]: "WETH",
|
|
48
|
+
[exports.creditManagerByNetwork.Mainnet.WBTC_V1]: "WBTC",
|
|
29
49
|
// MAINNET V2 CM
|
|
30
|
-
[exports.
|
|
31
|
-
[exports.
|
|
32
|
-
[exports.
|
|
33
|
-
[exports.
|
|
34
|
-
[exports.
|
|
35
|
-
[exports.
|
|
50
|
+
[exports.creditManagerByNetwork.Mainnet.DAI_V2]: "DAI",
|
|
51
|
+
[exports.creditManagerByNetwork.Mainnet.USDC_V2]: "USDC",
|
|
52
|
+
[exports.creditManagerByNetwork.Mainnet.WETH_V2]: "WETH",
|
|
53
|
+
[exports.creditManagerByNetwork.Mainnet.WSTETH_V2]: "wstETH",
|
|
54
|
+
[exports.creditManagerByNetwork.Mainnet.WBTC_V2]: "WBTC",
|
|
55
|
+
[exports.creditManagerByNetwork.Mainnet.FRAX_V2]: "FRAX",
|
|
56
|
+
// MAINNET V2_1 CM
|
|
57
|
+
[exports.creditManagerByNetwork.Mainnet.WETH_V2_1]: "WETH-Alpha",
|
|
58
|
+
// MAINNET POOLS
|
|
59
|
+
[exports.poolByNetwork.Mainnet.DAI_V1]: "DAI",
|
|
60
|
+
[exports.poolByNetwork.Mainnet.USDC_V1]: "USDC",
|
|
61
|
+
[exports.poolByNetwork.Mainnet.WETH_V1]: "WETH",
|
|
62
|
+
[exports.poolByNetwork.Mainnet.WBTC_V1]: "WBTC",
|
|
63
|
+
[exports.poolByNetwork.Mainnet.WSTETH_V1]: "wstETH",
|
|
64
|
+
[exports.poolByNetwork.Mainnet.FRAX_V1]: "FRAX",
|
|
36
65
|
};
|
|
37
66
|
const contractNames = Object.entries(contracts_1.contractsByAddress).reduce((acc, [addr, cSymbol]) => {
|
|
38
67
|
const params = contracts_1.contractParams[cSymbol];
|
|
@@ -41,7 +70,7 @@ const contractNames = Object.entries(contracts_1.contractsByAddress).reduce((acc
|
|
|
41
70
|
return { ...acc, [addr]: params.name };
|
|
42
71
|
}, {});
|
|
43
72
|
const contractsFullList = {
|
|
44
|
-
...mappers_1.TypedObjectUtils.keyToLowercase(
|
|
73
|
+
...mappers_1.TypedObjectUtils.keyToLowercase(deployedContractNames),
|
|
45
74
|
...contractNames,
|
|
46
75
|
};
|
|
47
76
|
function getContractName(address) {
|
|
@@ -14,6 +14,7 @@ export declare class CreditManagerData {
|
|
|
14
14
|
readonly maxLeverageFactor: number;
|
|
15
15
|
readonly availableLiquidity: bigint;
|
|
16
16
|
readonly collateralTokens: Array<string>;
|
|
17
|
+
readonly supportedTokens: Record<string, true>;
|
|
17
18
|
readonly adapters: Record<string, string>;
|
|
18
19
|
readonly liquidationThresholds: Record<string, bigint>;
|
|
19
20
|
readonly version: number;
|
|
@@ -18,7 +18,8 @@ class CreditManagerData {
|
|
|
18
18
|
maxAmount;
|
|
19
19
|
maxLeverageFactor; // for V1 only
|
|
20
20
|
availableLiquidity;
|
|
21
|
-
collateralTokens;
|
|
21
|
+
collateralTokens = [];
|
|
22
|
+
supportedTokens = {};
|
|
22
23
|
adapters;
|
|
23
24
|
liquidationThresholds;
|
|
24
25
|
version;
|
|
@@ -50,7 +51,11 @@ class CreditManagerData {
|
|
|
50
51
|
this.maxAmount = (0, formatter_1.toBigInt)(payload.maxAmount || 0);
|
|
51
52
|
this.maxLeverageFactor = Number((0, formatter_1.toBigInt)(payload.maxLeverageFactor || 0));
|
|
52
53
|
this.availableLiquidity = (0, formatter_1.toBigInt)(payload.availableLiquidity || 0);
|
|
53
|
-
|
|
54
|
+
payload.collateralTokens.forEach(t => {
|
|
55
|
+
const tLc = t.toLowerCase();
|
|
56
|
+
this.collateralTokens.push(tLc);
|
|
57
|
+
this.supportedTokens[tLc] = true;
|
|
58
|
+
});
|
|
54
59
|
this.adapters = payload.adapters.reduce((acc, { allowedContract, adapter }) => ({
|
|
55
60
|
...acc,
|
|
56
61
|
[allowedContract.toLowerCase()]: adapter.toLowerCase(),
|
|
@@ -89,7 +94,7 @@ class CreditManagerData {
|
|
|
89
94
|
return this.adapters[contractAddress];
|
|
90
95
|
}
|
|
91
96
|
encodeAddCollateral(accountAddress, tokenAddress, amount) {
|
|
92
|
-
if (this.version
|
|
97
|
+
if (this.version === 1)
|
|
93
98
|
throw new Error("Multicall is eligible only for version 2");
|
|
94
99
|
return {
|
|
95
100
|
target: this.creditFacade,
|
|
@@ -97,7 +102,7 @@ class CreditManagerData {
|
|
|
97
102
|
};
|
|
98
103
|
}
|
|
99
104
|
encodeIncreaseDebt(amount) {
|
|
100
|
-
if (this.version
|
|
105
|
+
if (this.version === 1)
|
|
101
106
|
throw new Error("Multicall is eligible only for version 2");
|
|
102
107
|
return {
|
|
103
108
|
target: this.creditFacade,
|
|
@@ -105,7 +110,7 @@ class CreditManagerData {
|
|
|
105
110
|
};
|
|
106
111
|
}
|
|
107
112
|
encodeDecreaseDebt(amount) {
|
|
108
|
-
if (this.version
|
|
113
|
+
if (this.version === 1)
|
|
109
114
|
throw new Error("Multicall is eligible only for version 2");
|
|
110
115
|
return {
|
|
111
116
|
target: this.creditFacade,
|
|
@@ -113,9 +118,9 @@ class CreditManagerData {
|
|
|
113
118
|
};
|
|
114
119
|
}
|
|
115
120
|
validateOpenAccount(collateral, debt) {
|
|
116
|
-
return this.version ===
|
|
117
|
-
? this.
|
|
118
|
-
: this.
|
|
121
|
+
return this.version === 1
|
|
122
|
+
? this.validateOpenAccountV1(collateral, debt)
|
|
123
|
+
: this.validateOpenAccountV2(debt);
|
|
119
124
|
}
|
|
120
125
|
validateOpenAccountV1(collateral, debt) {
|
|
121
126
|
if (collateral < this.minAmount)
|