@gearbox-protocol/sdk 0.0.107 → 0.0.110
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/lib/apy/convexAPY copy.d.ts +6 -0
- package/lib/apy/convexAPY copy.js +201 -0
- package/lib/apy/convexAPY.d.ts +9 -5
- package/lib/apy/convexAPY.js +29 -69
- package/lib/apy/curveAPY.d.ts +4 -0
- package/lib/apy/curveAPY.js +94 -0
- package/lib/apy/index.d.ts +6 -0
- package/lib/apy/index.js +20 -0
- package/lib/apy/lidoAPY.d.ts +1 -1
- package/lib/apy/lidoAPY.js +3 -3
- package/lib/apy/yearnAPY.d.ts +4 -0
- package/lib/apy/yearnAPY.js +90 -0
- package/lib/contracts/contractsRegister.js +2 -1
- package/lib/core/creditAccount.d.ts +2 -1
- package/lib/core/creditAccount.js +19 -12
- package/lib/core/creditManager.d.ts +3 -1
- package/lib/core/creditManager.js +25 -9
- package/lib/core/errors.d.ts +1 -1
- package/lib/core/pool.js +4 -4
- package/lib/core/strategy.d.ts +5 -3
- package/lib/core/strategy.js +6 -4
- package/lib/index.d.ts +4 -4
- package/lib/index.js +7 -6
- package/lib/strategies/curve.js +8 -10
- package/lib/strategies/yearn.js +8 -4
- package/lib/tokens/convex.d.ts +3 -0
- package/lib/tokens/convex.js +44 -18
- package/lib/tokens/curveLP.d.ts +1 -0
- package/lib/tokens/curveLP.js +11 -7
- package/lib/tokens/normal.d.ts +1 -0
- package/lib/tokens/normal.js +5 -1
- package/lib/tokens/token.d.ts +7 -2
- package/lib/tokens/token.js +10 -1
- package/lib/tokens/tokenData.js +2 -3
- package/lib/tokens/yearn.d.ts +1 -0
- package/lib/tokens/yearn.js +11 -7
- package/lib/utils/extracter.d.ts +11 -0
- package/lib/utils/extracter.js +19 -0
- package/lib/utils/mappers.d.ts +2 -2
- package/lib/utils/price.d.ts +8 -0
- package/lib/utils/price.js +26 -0
- package/package.json +1 -1
- package/src/apy/convexAPY.ts +47 -96
- package/src/apy/curveAPY.ts +68 -0
- package/src/apy/index.ts +8 -0
- package/src/apy/lidoAPY.ts +1 -1
- package/src/apy/yearnAPY.ts +66 -0
- package/src/contracts/contractsRegister.ts +2 -1
- package/src/core/creditAccount.ts +20 -12
- package/src/core/creditManager.ts +38 -11
- package/src/core/errors.ts +1 -0
- package/src/core/pool.ts +4 -4
- package/src/core/strategy.ts +16 -10
- package/src/index.ts +4 -4
- package/src/strategies/convex.ts +9 -3
- package/src/strategies/curve.ts +26 -18
- package/src/strategies/lido.ts +6 -2
- package/src/strategies/yearn.ts +17 -6
- package/src/tokens/convex.ts +43 -20
- package/src/tokens/curveLP.ts +9 -6
- package/src/tokens/normal.ts +3 -0
- package/src/tokens/token.ts +24 -6
- package/src/tokens/tokenData.ts +2 -4
- package/src/tokens/yearn.ts +9 -6
- package/src/utils/extracter.ts +30 -0
- package/src/utils/mappers.ts +2 -2
- package/src/utils/price.ts +33 -0
- package/lib/core/price.d.ts +0 -2
- package/lib/core/price.js +0 -14
- package/lib/types/@chainlink/contracts/src/v0.6/index.d.ts +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/index.js +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.d.ts +0 -146
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.js +0 -2
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
- package/lib/types/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -2
- package/lib/types/contracts/integrations/lido/IstETH.d.ts +0 -154
- package/lib/types/contracts/integrations/lido/IstETH.js +0 -2
- package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.d.ts +0 -50
- package/lib/types/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker.js +0 -2
- package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.d.ts +0 -27
- package/lib/types/contracts/pathfinder/Balances.sol/BalanceOps.js +0 -2
- package/lib/types/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
- package/lib/types/contracts/pathfinder/Balances.sol/index.js +0 -2
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.d.ts +0 -269
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder.js +0 -2
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
- package/lib/types/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -2
- package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.d.ts +0 -58
- package/lib/types/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper.js +0 -2
- package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.d.ts +0 -528
- package/lib/types/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest.js +0 -2
- package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.d.ts +0 -528
- package/lib/types/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest.js +0 -2
- package/lib/types/factories/@chainlink/contracts/src/v0.6/index.d.ts +0 -1
- package/lib/types/factories/@chainlink/contracts/src/v0.6/index.js +0 -30
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.d.ts +0 -22
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface__factory.js +0 -133
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.d.ts +0 -1
- package/lib/types/factories/@chainlink/contracts/src/v0.6/interfaces/index.js +0 -8
- package/lib/types/factories/contracts/integrations/lido/IstETH__factory.d.ts +0 -35
- package/lib/types/factories/contracts/integrations/lido/IstETH__factory.js +0 -224
- package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.d.ts +0 -18
- package/lib/types/factories/contracts/interfaces/ICreditFacade.sol/ICreditFacadeBalanceChecker__factory.js +0 -40
- package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.d.ts +0 -28
- package/lib/types/factories/contracts/pathfinder/Balances.sol/BalanceOps__factory.js +0 -76
- package/lib/types/factories/contracts/pathfinder/Balances.sol/index.d.ts +0 -1
- package/lib/types/factories/contracts/pathfinder/Balances.sol/index.js +0 -8
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.d.ts +0 -144
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/PathFinder__factory.js +0 -522
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.d.ts +0 -1
- package/lib/types/factories/contracts/pathfinder/NormalTokenPathFinder.sol/index.js +0 -8
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.d.ts +0 -34
- package/lib/types/factories/contracts/test/mocks/integrations/ConvexTokenRewardContractMock.sol/VirtualBalanceWrapper__factory.js +0 -110
- package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.d.ts +0 -65
- package/lib/types/factories/contracts/test/pathfinder/UniswapV2PathFinder.t.sol/UniswapV2PathFinderAdapterTest__factory.js +0 -775
- package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.d.ts +0 -65
- package/lib/types/factories/contracts/test/pathfinder/UniswapV3PathFinder.t.sol/UniswapV3PathFinderAdapterTest__factory.js +0 -775
- package/src/core/price.ts +0 -13
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BigNumber, providers } from "ethers";
|
|
2
|
+
import { ConvexPoolContract } from "../contracts/contracts";
|
|
3
|
+
import { CurveLPToken } from "../tokens/curveLP";
|
|
4
|
+
import { NetworkType } from "../core/constants";
|
|
5
|
+
export declare function getConvexApy(pool: ConvexPoolContract, provider: providers.Provider, networkType: NetworkType, getTokenPrice: (tokenAddress: string) => BigNumber): Promise<BigNumber>;
|
|
6
|
+
export declare function getCurveBaseApy(curveLPToken: CurveLPToken): Promise<BigNumber>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
+
if (ar || !(i in from)) {
|
|
41
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
+
ar[i] = from[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.getCurveBaseApy = exports.getConvexApy = void 0;
|
|
52
|
+
var ethers_1 = require("ethers");
|
|
53
|
+
var axios_1 = __importDefault(require("axios"));
|
|
54
|
+
var contracts_1 = require("../contracts/contracts");
|
|
55
|
+
var token_1 = require("../tokens/token");
|
|
56
|
+
var types_1 = require("../types");
|
|
57
|
+
var multicall_1 = require("../utils/multicall");
|
|
58
|
+
var formatter_1 = require("../utils/formatter");
|
|
59
|
+
var constants_1 = require("../core/constants");
|
|
60
|
+
function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var tokenList, contractsList, poolParams, stakedTokenParams, underlying, basePoolAddress, crvParams, swapPoolAddress, cvxAddress, extraPoolAddresses, _a, basePoolRate, basePoolSupply, vPrice, cvxSupply, extra, cvxPrice, crvPrice, crvPerSecond, virtualSupply, crvPerUnderlying, crvPerYear, cvxPerYear, crvAPY, cvxAPY, extraAPRs, extraAPYTotal, baseApyRAY;
|
|
63
|
+
var _this = this;
|
|
64
|
+
return __generator(this, function (_b) {
|
|
65
|
+
switch (_b.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
tokenList = token_1.tokenDataByNetwork[networkType];
|
|
68
|
+
contractsList = contracts_1.contractsByNetwork[networkType];
|
|
69
|
+
poolParams = contracts_1.contractParams[pool];
|
|
70
|
+
stakedTokenParams = token_1.supportedTokens[poolParams.stakedToken];
|
|
71
|
+
underlying = stakedTokenParams.underlying;
|
|
72
|
+
basePoolAddress = contractsList[pool];
|
|
73
|
+
crvParams = token_1.supportedTokens[underlying];
|
|
74
|
+
swapPoolAddress = contractsList[crvParams.pool];
|
|
75
|
+
cvxAddress = tokenList.CVX;
|
|
76
|
+
extraPoolAddresses = poolParams.extraRewards.map(function (d) { return d.poolAddress[networkType]; });
|
|
77
|
+
return [4 /*yield*/, getPoolData({
|
|
78
|
+
basePoolAddress: basePoolAddress,
|
|
79
|
+
swapPoolAddress: swapPoolAddress,
|
|
80
|
+
cvxAddress: cvxAddress,
|
|
81
|
+
extraPoolAddresses: extraPoolAddresses,
|
|
82
|
+
provider: provider
|
|
83
|
+
})];
|
|
84
|
+
case 1:
|
|
85
|
+
_a = _b.sent(), basePoolRate = _a[0], basePoolSupply = _a[1], vPrice = _a[2], cvxSupply = _a[3], extra = _a.slice(4);
|
|
86
|
+
cvxPrice = getTokenPrice(tokenList.CVX);
|
|
87
|
+
crvPrice = getTokenPrice(tokenList.CRV);
|
|
88
|
+
crvPerSecond = basePoolRate;
|
|
89
|
+
virtualSupply = basePoolSupply.mul(vPrice).div(constants_1.WAD);
|
|
90
|
+
crvPerUnderlying = crvPerSecond.mul(constants_1.WAD).div(virtualSupply);
|
|
91
|
+
crvPerYear = crvPerUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
92
|
+
cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
|
|
93
|
+
crvAPY = crvPerYear.mul(crvPrice).div(constants_1.PRICE_DECIMALS);
|
|
94
|
+
cvxAPY = cvxPerYear.mul(cvxPrice).div(constants_1.PRICE_DECIMALS);
|
|
95
|
+
return [4 /*yield*/, Promise.all(extraPoolAddresses.map(function (_, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
96
|
+
var extraRewardSymbol, extraPoolRate, perUnderlying, perYear, extraPrice, extraAPY;
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
extraRewardSymbol = poolParams.extraRewards[index].rewardToken;
|
|
99
|
+
extraPoolRate = extra[index];
|
|
100
|
+
perUnderlying = extraPoolRate.mul(constants_1.WAD).div(virtualSupply);
|
|
101
|
+
perYear = perUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
102
|
+
extraPrice = getTokenPrice(tokenList[extraRewardSymbol]);
|
|
103
|
+
extraAPY = perYear.mul(extraPrice).div(constants_1.PRICE_DECIMALS);
|
|
104
|
+
return [2 /*return*/, extraAPY];
|
|
105
|
+
});
|
|
106
|
+
}); }))];
|
|
107
|
+
case 2:
|
|
108
|
+
extraAPRs = _b.sent();
|
|
109
|
+
extraAPYTotal = extraAPRs.reduce(function (acc, apy) { return acc.add(apy); }, ethers_1.BigNumber.from(0));
|
|
110
|
+
return [4 /*yield*/, getCurveBaseApy(underlying)];
|
|
111
|
+
case 3:
|
|
112
|
+
baseApyRAY = _b.sent();
|
|
113
|
+
return [2 /*return*/, baseApyRAY.add(crvAPY).add(cvxAPY).add(extraAPYTotal)];
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.getConvexApy = getConvexApy;
|
|
119
|
+
var CVX_MAX_SUPPLY = constants_1.WAD.mul(100000000);
|
|
120
|
+
var CVX_REDUCTION_PER_CLIFF = ethers_1.BigNumber.from(100000);
|
|
121
|
+
var CVX_TOTAL_CLIFFS = constants_1.WAD.mul(1000);
|
|
122
|
+
function getCVXMintAmount(crvAmount, cvxSupply) {
|
|
123
|
+
var currentCliff = cvxSupply.div(CVX_REDUCTION_PER_CLIFF);
|
|
124
|
+
if (currentCliff.lt(CVX_TOTAL_CLIFFS)) {
|
|
125
|
+
var remainingCliffs = CVX_TOTAL_CLIFFS.sub(currentCliff);
|
|
126
|
+
var mintedAmount = crvAmount.mul(remainingCliffs).div(CVX_TOTAL_CLIFFS);
|
|
127
|
+
var amountTillMax = CVX_MAX_SUPPLY.sub(cvxSupply);
|
|
128
|
+
return mintedAmount.gt(amountTillMax) ? amountTillMax : mintedAmount;
|
|
129
|
+
}
|
|
130
|
+
return ethers_1.BigNumber.from(0);
|
|
131
|
+
}
|
|
132
|
+
function getPoolData(_a) {
|
|
133
|
+
var basePoolAddress = _a.basePoolAddress, swapPoolAddress = _a.swapPoolAddress, cvxAddress = _a.cvxAddress, extraPoolAddresses = _a.extraPoolAddresses, provider = _a.provider;
|
|
134
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
135
|
+
var calls;
|
|
136
|
+
return __generator(this, function (_b) {
|
|
137
|
+
calls = __spreadArray([
|
|
138
|
+
{
|
|
139
|
+
address: basePoolAddress,
|
|
140
|
+
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
141
|
+
method: "rewardRate()"
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
address: basePoolAddress,
|
|
145
|
+
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
146
|
+
method: "totalSupply()"
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
address: swapPoolAddress,
|
|
150
|
+
interface: types_1.CurveV1AdapterStETH__factory.createInterface(),
|
|
151
|
+
method: "get_virtual_price()"
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
address: cvxAddress,
|
|
155
|
+
interface: types_1.IConvexToken__factory.createInterface(),
|
|
156
|
+
method: "totalSupply()"
|
|
157
|
+
}
|
|
158
|
+
], extraPoolAddresses.map(function (extraPoolAddress) { return ({
|
|
159
|
+
address: extraPoolAddress,
|
|
160
|
+
interface: types_1.IBaseRewardPool__factory.createInterface(),
|
|
161
|
+
method: "rewardRate()"
|
|
162
|
+
}); }), true);
|
|
163
|
+
return [2 /*return*/, (0, multicall_1.multicall)(calls, provider)];
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
var curveLPTokenToPoolName = {
|
|
168
|
+
"3Crv": "3pool",
|
|
169
|
+
FRAX3CRV: "frax",
|
|
170
|
+
gusd3CRV: "gusd",
|
|
171
|
+
LUSD3CRV: "lusd",
|
|
172
|
+
crvPlain3andSUSD: "susdv2",
|
|
173
|
+
steCRV: "steth"
|
|
174
|
+
};
|
|
175
|
+
var RESPONSE_DECIMALS = 100;
|
|
176
|
+
// https://www.convexfinance.com/api/curve-apys
|
|
177
|
+
function getCurveBaseApy(curveLPToken) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
179
|
+
var poolName, url, result, _a, baseApy, e_1;
|
|
180
|
+
return __generator(this, function (_b) {
|
|
181
|
+
switch (_b.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
poolName = curveLPTokenToPoolName[curveLPToken];
|
|
184
|
+
_b.label = 1;
|
|
185
|
+
case 1:
|
|
186
|
+
_b.trys.push([1, 3, , 4]);
|
|
187
|
+
url = "http://localhost:8000/api/curve-apys";
|
|
188
|
+
return [4 /*yield*/, axios_1.default.get(url)];
|
|
189
|
+
case 2:
|
|
190
|
+
result = _b.sent();
|
|
191
|
+
_a = (result.data.apys[poolName] || {}).baseApy, baseApy = _a === void 0 ? 0 : _a;
|
|
192
|
+
return [2 /*return*/, (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW)];
|
|
193
|
+
case 3:
|
|
194
|
+
e_1 = _b.sent();
|
|
195
|
+
return [2 /*return*/, ethers_1.BigNumber.from(0)];
|
|
196
|
+
case 4: return [2 /*return*/];
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
exports.getCurveBaseApy = getCurveBaseApy;
|
package/lib/apy/convexAPY.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { BigNumber, providers } from "ethers";
|
|
2
2
|
import { ConvexPoolContract } from "../contracts/contracts";
|
|
3
|
-
import { CurveLPToken } from "../tokens/curveLP";
|
|
4
3
|
import { NetworkType } from "../core/constants";
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
import { CurveAPYResult } from "./curveAPY";
|
|
5
|
+
export interface GetConvexAPYProps {
|
|
6
|
+
pool: ConvexPoolContract;
|
|
7
|
+
provider: providers.Provider;
|
|
8
|
+
networkType: NetworkType;
|
|
9
|
+
getTokenPrice: (tokenAddress: string) => BigNumber;
|
|
10
|
+
curveAPY: CurveAPYResult;
|
|
11
|
+
}
|
|
12
|
+
export declare function getConvexAPY({ pool, provider, networkType, getTokenPrice, curveAPY }: GetConvexAPYProps): Promise<BigNumber>;
|
package/lib/apy/convexAPY.js
CHANGED
|
@@ -44,32 +44,21 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
44
44
|
}
|
|
45
45
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
46
|
};
|
|
47
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
-
};
|
|
50
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
exports.
|
|
48
|
+
exports.getConvexAPY = void 0;
|
|
52
49
|
var ethers_1 = require("ethers");
|
|
53
|
-
var axios_1 = __importDefault(require("axios"));
|
|
54
50
|
var contracts_1 = require("../contracts/contracts");
|
|
55
51
|
var token_1 = require("../tokens/token");
|
|
56
52
|
var types_1 = require("../types");
|
|
57
53
|
var multicall_1 = require("../utils/multicall");
|
|
58
|
-
var formatter_1 = require("../utils/formatter");
|
|
59
54
|
var constants_1 = require("../core/constants");
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
CONVEX_FRAX3CRV_POOL: "CURVE_FRAX_POOL",
|
|
63
|
-
CONVEX_LUSD3CRV_POOL: "CURVE_LUSD_POOL",
|
|
64
|
-
CONVEX_GUSD_POOL: "CURVE_GUSD_POOL",
|
|
65
|
-
CONVEX_SUSD_POOL: "CURVE_SUSD_POOL"
|
|
66
|
-
};
|
|
67
|
-
function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
55
|
+
function getConvexAPY(_a) {
|
|
56
|
+
var pool = _a.pool, provider = _a.provider, networkType = _a.networkType, getTokenPrice = _a.getTokenPrice, curveAPY = _a.curveAPY;
|
|
68
57
|
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
-
var tokenList, contractsList, poolParams, stakedTokenParams, underlying, basePoolAddress, swapPoolAddress, cvxAddress, extraPoolAddresses,
|
|
58
|
+
var tokenList, contractsList, poolParams, stakedTokenParams, underlying, basePoolAddress, crvParams, swapPoolAddress, cvxAddress, extraPoolAddresses, _b, basePoolRate, basePoolSupply, vPrice, cvxSupply, extra, cvxPrice, crvPrice, crvPerSecond, virtualSupply, crvPerUnderlying, crvPerYear, cvxPerYear, crvAPY, cvxAPY, extraAPRs, extraAPYTotal, baseApyWAD;
|
|
70
59
|
var _this = this;
|
|
71
|
-
return __generator(this, function (
|
|
72
|
-
switch (
|
|
60
|
+
return __generator(this, function (_c) {
|
|
61
|
+
switch (_c.label) {
|
|
73
62
|
case 0:
|
|
74
63
|
tokenList = token_1.tokenDataByNetwork[networkType];
|
|
75
64
|
contractsList = contracts_1.contractsByNetwork[networkType];
|
|
@@ -77,12 +66,19 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
77
66
|
stakedTokenParams = token_1.supportedTokens[poolParams.stakedToken];
|
|
78
67
|
underlying = stakedTokenParams.underlying;
|
|
79
68
|
basePoolAddress = contractsList[pool];
|
|
80
|
-
|
|
69
|
+
crvParams = token_1.supportedTokens[underlying];
|
|
70
|
+
swapPoolAddress = contractsList[crvParams.pool];
|
|
81
71
|
cvxAddress = tokenList.CVX;
|
|
82
72
|
extraPoolAddresses = poolParams.extraRewards.map(function (d) { return d.poolAddress[networkType]; });
|
|
83
|
-
return [4 /*yield*/, getPoolData(
|
|
73
|
+
return [4 /*yield*/, getPoolData({
|
|
74
|
+
basePoolAddress: basePoolAddress,
|
|
75
|
+
swapPoolAddress: swapPoolAddress,
|
|
76
|
+
cvxAddress: cvxAddress,
|
|
77
|
+
extraPoolAddresses: extraPoolAddresses,
|
|
78
|
+
provider: provider
|
|
79
|
+
})];
|
|
84
80
|
case 1:
|
|
85
|
-
|
|
81
|
+
_b = _c.sent(), basePoolRate = _b[0], basePoolSupply = _b[1], vPrice = _b[2], cvxSupply = _b[3], extra = _b.slice(4);
|
|
86
82
|
cvxPrice = getTokenPrice(tokenList.CVX);
|
|
87
83
|
crvPrice = getTokenPrice(tokenList.CRV);
|
|
88
84
|
crvPerSecond = basePoolRate;
|
|
@@ -90,32 +86,30 @@ function getConvexApy(pool, provider, networkType, getTokenPrice) {
|
|
|
90
86
|
crvPerUnderlying = crvPerSecond.mul(constants_1.WAD).div(virtualSupply);
|
|
91
87
|
crvPerYear = crvPerUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
92
88
|
cvxPerYear = getCVXMintAmount(crvPerYear, cvxSupply);
|
|
93
|
-
crvAPY = crvPerYear.mul(
|
|
94
|
-
cvxAPY = cvxPerYear.mul(
|
|
89
|
+
crvAPY = crvPerYear.mul(crvPrice).div(constants_1.PRICE_DECIMALS);
|
|
90
|
+
cvxAPY = cvxPerYear.mul(cvxPrice).div(constants_1.PRICE_DECIMALS);
|
|
95
91
|
return [4 /*yield*/, Promise.all(extraPoolAddresses.map(function (_, index) { return __awaiter(_this, void 0, void 0, function () {
|
|
96
|
-
var extraRewardSymbol, extraPoolRate, perUnderlying, perYear,
|
|
92
|
+
var extraRewardSymbol, extraPoolRate, perUnderlying, perYear, extraPrice, extraAPY;
|
|
97
93
|
return __generator(this, function (_a) {
|
|
98
94
|
extraRewardSymbol = poolParams.extraRewards[index].rewardToken;
|
|
99
95
|
extraPoolRate = extra[index];
|
|
100
96
|
perUnderlying = extraPoolRate.mul(constants_1.WAD).div(virtualSupply);
|
|
101
97
|
perYear = perUnderlying.mul(constants_1.SECONDS_PER_YEAR);
|
|
102
|
-
|
|
103
|
-
extraAPY = perYear.mul(
|
|
98
|
+
extraPrice = getTokenPrice(tokenList[extraRewardSymbol]);
|
|
99
|
+
extraAPY = perYear.mul(extraPrice).div(constants_1.PRICE_DECIMALS);
|
|
104
100
|
return [2 /*return*/, extraAPY];
|
|
105
101
|
});
|
|
106
102
|
}); }))];
|
|
107
103
|
case 2:
|
|
108
|
-
extraAPRs =
|
|
104
|
+
extraAPRs = _c.sent();
|
|
109
105
|
extraAPYTotal = extraAPRs.reduce(function (acc, apy) { return acc.add(apy); }, ethers_1.BigNumber.from(0));
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
baseApyRAY = _b.sent();
|
|
113
|
-
return [2 /*return*/, baseApyRAY.add(crvAPY).add(cvxAPY).add(extraAPYTotal)];
|
|
106
|
+
baseApyWAD = curveAPY[underlying];
|
|
107
|
+
return [2 /*return*/, baseApyWAD.add(crvAPY).add(cvxAPY).add(extraAPYTotal)];
|
|
114
108
|
}
|
|
115
109
|
});
|
|
116
110
|
});
|
|
117
111
|
}
|
|
118
|
-
exports.
|
|
112
|
+
exports.getConvexAPY = getConvexAPY;
|
|
119
113
|
var CVX_MAX_SUPPLY = constants_1.WAD.mul(100000000);
|
|
120
114
|
var CVX_REDUCTION_PER_CLIFF = ethers_1.BigNumber.from(100000);
|
|
121
115
|
var CVX_TOTAL_CLIFFS = constants_1.WAD.mul(1000);
|
|
@@ -129,10 +123,11 @@ function getCVXMintAmount(crvAmount, cvxSupply) {
|
|
|
129
123
|
}
|
|
130
124
|
return ethers_1.BigNumber.from(0);
|
|
131
125
|
}
|
|
132
|
-
function getPoolData(
|
|
126
|
+
function getPoolData(_a) {
|
|
127
|
+
var basePoolAddress = _a.basePoolAddress, swapPoolAddress = _a.swapPoolAddress, cvxAddress = _a.cvxAddress, extraPoolAddresses = _a.extraPoolAddresses, provider = _a.provider;
|
|
133
128
|
return __awaiter(this, void 0, void 0, function () {
|
|
134
129
|
var calls;
|
|
135
|
-
return __generator(this, function (
|
|
130
|
+
return __generator(this, function (_b) {
|
|
136
131
|
calls = __spreadArray([
|
|
137
132
|
{
|
|
138
133
|
address: basePoolAddress,
|
|
@@ -145,7 +140,7 @@ function getPoolData(basePoolAddress, underlying, cvxAddress, extraPoolAddresses
|
|
|
145
140
|
method: "totalSupply()"
|
|
146
141
|
},
|
|
147
142
|
{
|
|
148
|
-
address:
|
|
143
|
+
address: swapPoolAddress,
|
|
149
144
|
interface: types_1.CurveV1AdapterStETH__factory.createInterface(),
|
|
150
145
|
method: "get_virtual_price()"
|
|
151
146
|
},
|
|
@@ -163,38 +158,3 @@ function getPoolData(basePoolAddress, underlying, cvxAddress, extraPoolAddresses
|
|
|
163
158
|
});
|
|
164
159
|
});
|
|
165
160
|
}
|
|
166
|
-
var curveLPTokenToPoolName = {
|
|
167
|
-
"3Crv": "3pool",
|
|
168
|
-
FRAX3CRV: "frax",
|
|
169
|
-
gusd3CRV: "gusd",
|
|
170
|
-
LUSD3CRV: "lusd",
|
|
171
|
-
crvPlain3andSUSD: "susdv2",
|
|
172
|
-
steCRV: "steth"
|
|
173
|
-
};
|
|
174
|
-
var RESPONSE_DECIMALS = 100;
|
|
175
|
-
// https://www.convexfinance.com/api/curve-apys
|
|
176
|
-
function getCurveBaseApy(curveLPToken) {
|
|
177
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
178
|
-
var poolName, url, result, _a, baseApy, e_1;
|
|
179
|
-
return __generator(this, function (_b) {
|
|
180
|
-
switch (_b.label) {
|
|
181
|
-
case 0:
|
|
182
|
-
poolName = curveLPTokenToPoolName[curveLPToken];
|
|
183
|
-
_b.label = 1;
|
|
184
|
-
case 1:
|
|
185
|
-
_b.trys.push([1, 3, , 4]);
|
|
186
|
-
url = "https://www.convexfinance.com/api/curve-apys";
|
|
187
|
-
return [4 /*yield*/, axios_1.default.get(url)];
|
|
188
|
-
case 2:
|
|
189
|
-
result = _b.sent();
|
|
190
|
-
_a = (result.data.apys[poolName] || {}).baseApy, baseApy = _a === void 0 ? 0 : _a;
|
|
191
|
-
return [2 /*return*/, (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW)];
|
|
192
|
-
case 3:
|
|
193
|
-
e_1 = _b.sent();
|
|
194
|
-
return [2 /*return*/, ethers_1.BigNumber.from(0)];
|
|
195
|
-
case 4: return [2 /*return*/];
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
exports.getCurveBaseApy = getCurveBaseApy;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getCurveAPY = void 0;
|
|
43
|
+
var ethers_1 = require("ethers");
|
|
44
|
+
var axios_1 = __importDefault(require("axios"));
|
|
45
|
+
var formatter_1 = require("../utils/formatter");
|
|
46
|
+
var constants_1 = require("../core/constants");
|
|
47
|
+
var mappers_1 = require("../utils/mappers");
|
|
48
|
+
var NAME_DICTIONARY = {
|
|
49
|
+
"3Crv": "3pool",
|
|
50
|
+
FRAX3CRV: "frax",
|
|
51
|
+
gusd3CRV: "gusd",
|
|
52
|
+
LUSD3CRV: "lusd",
|
|
53
|
+
crvPlain3andSUSD: "susdv2",
|
|
54
|
+
steCRV: "steth"
|
|
55
|
+
};
|
|
56
|
+
var RESPONSE_DECIMALS = 100;
|
|
57
|
+
var ZERO = ethers_1.BigNumber.from(0);
|
|
58
|
+
// https://www.convexfinance.com/api/curve-apys
|
|
59
|
+
// http://localhost:8000/api/curve-apys
|
|
60
|
+
var URL = "https://www.convexfinance.com/api/curve-apys";
|
|
61
|
+
function getCurveAPY() {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
63
|
+
var data, apys_1, curveAPY, e_1;
|
|
64
|
+
return __generator(this, function (_a) {
|
|
65
|
+
switch (_a.label) {
|
|
66
|
+
case 0:
|
|
67
|
+
_a.trys.push([0, 2, , 3]);
|
|
68
|
+
return [4 /*yield*/, axios_1.default.get(URL)];
|
|
69
|
+
case 1:
|
|
70
|
+
data = (_a.sent()).data;
|
|
71
|
+
apys_1 = (data || {}).apys;
|
|
72
|
+
curveAPY = (0, mappers_1.objectEntries)(NAME_DICTIONARY).reduce(function (acc, _a) {
|
|
73
|
+
var curveSymbol = _a[0], apiEntry = _a[1];
|
|
74
|
+
var _b = (apys_1[apiEntry] || {}).baseApy, baseApy = _b === void 0 ? 0 : _b;
|
|
75
|
+
acc[curveSymbol] = (0, formatter_1.toBN)((baseApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
|
|
76
|
+
return acc;
|
|
77
|
+
}, {});
|
|
78
|
+
return [2 /*return*/, curveAPY];
|
|
79
|
+
case 2:
|
|
80
|
+
e_1 = _a.sent();
|
|
81
|
+
return [2 /*return*/, {
|
|
82
|
+
"3Crv": ZERO,
|
|
83
|
+
FRAX3CRV: ZERO,
|
|
84
|
+
gusd3CRV: ZERO,
|
|
85
|
+
LUSD3CRV: ZERO,
|
|
86
|
+
crvPlain3andSUSD: ZERO,
|
|
87
|
+
steCRV: ZERO
|
|
88
|
+
}];
|
|
89
|
+
case 3: return [2 /*return*/];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
exports.getCurveAPY = getCurveAPY;
|
package/lib/apy/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./convexAPY"), exports);
|
|
18
|
+
__exportStar(require("./lidoAPY"), exports);
|
|
19
|
+
__exportStar(require("./curveAPY"), exports);
|
|
20
|
+
__exportStar(require("./yearnAPY"), exports);
|
package/lib/apy/lidoAPY.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { providers } from "ethers";
|
|
2
2
|
import { NetworkType } from "../core/constants";
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function getLidoAPY(provider: providers.Provider, networkType: NetworkType): Promise<readonly [import("ethers").BigNumber, number]>;
|
|
4
4
|
export declare const LIDO_FEE_DECIMALS = 10000;
|
package/lib/apy/lidoAPY.js
CHANGED
|
@@ -36,7 +36,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.LIDO_FEE_DECIMALS = exports.
|
|
39
|
+
exports.LIDO_FEE_DECIMALS = exports.getLidoAPY = void 0;
|
|
40
40
|
var multicall_1 = require("../utils/multicall");
|
|
41
41
|
var contracts_1 = require("../contracts/contracts");
|
|
42
42
|
var token_1 = require("../tokens/token");
|
|
@@ -47,7 +47,7 @@ var lidoStEth = {
|
|
|
47
47
|
Mainnet: token_1.tokenDataByNetwork.Mainnet.STETH,
|
|
48
48
|
Kovan: token_1.tokenDataByNetwork.Kovan.STETH
|
|
49
49
|
};
|
|
50
|
-
function
|
|
50
|
+
function getLidoAPY(provider, networkType) {
|
|
51
51
|
return __awaiter(this, void 0, void 0, function () {
|
|
52
52
|
var _a, _b, postTotalPooledEther, preTotalPooledEther, timeElapsed, fee, lidoAPRRay;
|
|
53
53
|
return __generator(this, function (_c) {
|
|
@@ -72,7 +72,7 @@ function getLidoApy(provider, networkType) {
|
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
exports.
|
|
75
|
+
exports.getLidoAPY = getLidoAPY;
|
|
76
76
|
exports.LIDO_FEE_DECIMALS = 10000;
|
|
77
77
|
function geLidoData(lidoOracleAddress, stETHAddress, provider, network) {
|
|
78
78
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.getYearnAPY = void 0;
|
|
43
|
+
var ethers_1 = require("ethers");
|
|
44
|
+
var axios_1 = __importDefault(require("axios"));
|
|
45
|
+
var yearn_1 = require("../tokens/yearn");
|
|
46
|
+
var formatter_1 = require("../utils/formatter");
|
|
47
|
+
var constants_1 = require("../core/constants");
|
|
48
|
+
var mappers_1 = require("../utils/mappers");
|
|
49
|
+
var RESPONSE_DECIMALS = 1;
|
|
50
|
+
var ZERO = ethers_1.BigNumber.from(0);
|
|
51
|
+
var URL = "https://api.yearn.finance/v1/chains/1/vaults/all";
|
|
52
|
+
var transformSymbol = function (s) { return s.replaceAll("_", "-").toLowerCase(); };
|
|
53
|
+
function getYearnAPY() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var data, dataBySymbol_1, yearnAPY, e_1;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
_a.trys.push([0, 2, , 3]);
|
|
60
|
+
return [4 /*yield*/, axios_1.default.get(URL)];
|
|
61
|
+
case 1:
|
|
62
|
+
data = (_a.sent()).data;
|
|
63
|
+
dataBySymbol_1 = data.reduce(function (acc, d) {
|
|
64
|
+
acc[d.symbol.toLowerCase()] = d;
|
|
65
|
+
return acc;
|
|
66
|
+
}, {});
|
|
67
|
+
yearnAPY = (0, mappers_1.objectEntries)(yearn_1.yearnTokens).reduce(function (acc, _a) {
|
|
68
|
+
var yearnSymbol = _a[0];
|
|
69
|
+
var apy = (dataBySymbol_1[transformSymbol(yearnSymbol)] || {}).apy;
|
|
70
|
+
var netApy = (apy || {}).net_apy;
|
|
71
|
+
acc[yearnSymbol] = (0, formatter_1.toBN)((netApy / RESPONSE_DECIMALS).toString(), constants_1.WAD_DECIMALS_POW);
|
|
72
|
+
return acc;
|
|
73
|
+
}, {});
|
|
74
|
+
return [2 /*return*/, yearnAPY];
|
|
75
|
+
case 2:
|
|
76
|
+
e_1 = _a.sent();
|
|
77
|
+
return [2 /*return*/, {
|
|
78
|
+
yvDAI: ZERO,
|
|
79
|
+
yvUSDC: ZERO,
|
|
80
|
+
yvWETH: ZERO,
|
|
81
|
+
yvWBTC: ZERO,
|
|
82
|
+
yvCurve_stETH: ZERO,
|
|
83
|
+
yvCurve_FRAX: ZERO
|
|
84
|
+
}];
|
|
85
|
+
case 3: return [2 /*return*/];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.getYearnAPY = getYearnAPY;
|