@curvefi/api 2.8.8 → 2.10.0
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/constants/aliases.d.ts +1 -0
- package/lib/constants/aliases.js +13 -1
- package/lib/constants/coins/moonbeam.d.ts +7 -0
- package/lib/constants/coins/moonbeam.js +16 -0
- package/lib/constants/pools/index.d.ts +2 -1
- package/lib/constants/pools/index.js +3 -1
- package/lib/constants/pools/moonbeam.d.ts +4 -0
- package/lib/constants/pools/moonbeam.js +37 -0
- package/lib/curve.d.ts +1 -0
- package/lib/curve.js +17 -0
- package/lib/external-api.d.ts +22 -0
- package/lib/external-api.js +41 -1
- package/lib/factory/common.js +9 -94
- package/lib/factory/constants.d.ts +38 -8
- package/lib/factory/constants.js +103 -18
- package/lib/factory/factory-api.js +3 -1
- package/lib/factory/factory-crypto.js +3 -0
- package/lib/factory/factory.js +4 -1
- package/lib/interfaces.d.ts +7 -0
- package/lib/pools/PoolTemplate.js +58 -17
- package/lib/router.d.ts +10 -0
- package/lib/router.js +453 -123
- package/lib/utils.js +12 -6
- package/package.json +2 -2
|
@@ -243,6 +243,8 @@ function getExistingCoinAddressNameDict() {
|
|
|
243
243
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "MATIC";
|
|
244
244
|
if (this.chainId === 250)
|
|
245
245
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "FTM";
|
|
246
|
+
if (this.chainId === 1284)
|
|
247
|
+
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "GLMR";
|
|
246
248
|
if (this.chainId === 43114)
|
|
247
249
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "AVAX";
|
|
248
250
|
if (this.chainId === 42161)
|
|
@@ -405,6 +407,7 @@ function getCryptoFactoryPoolData() {
|
|
|
405
407
|
token_address: tokenAddresses[i],
|
|
406
408
|
gauge_address: gaugeAddresses[i],
|
|
407
409
|
is_crypto: true,
|
|
410
|
+
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
408
411
|
is_factory: true,
|
|
409
412
|
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
410
413
|
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
package/lib/factory/factory.js
CHANGED
|
@@ -78,6 +78,7 @@ var BLACK_LIST = {
|
|
|
78
78
|
"0x88c4d6534165510b2e2caf0a130d4f70aa4b6d71",
|
|
79
79
|
],
|
|
80
80
|
250: [],
|
|
81
|
+
1284: [],
|
|
81
82
|
43114: [],
|
|
82
83
|
42161: [],
|
|
83
84
|
};
|
|
@@ -277,6 +278,8 @@ function getExistingCoinAddressNameDict() {
|
|
|
277
278
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "MATIC";
|
|
278
279
|
if (this.chainId === 250)
|
|
279
280
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "FTM";
|
|
281
|
+
if (this.chainId === 1284)
|
|
282
|
+
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "GLMR";
|
|
280
283
|
if (this.chainId === 43114)
|
|
281
284
|
dict[constants_1.NATIVE_TOKEN_ADDRESS] = "AVAX";
|
|
282
285
|
if (this.chainId === 42161)
|
|
@@ -450,7 +453,7 @@ function getFactoryPoolData() {
|
|
|
450
453
|
swap_address: swapAddresses[i],
|
|
451
454
|
token_address: swapAddresses[i],
|
|
452
455
|
gauge_address: gaugeAddresses[i],
|
|
453
|
-
deposit_address: basePoolIdZapDict[basePoolIds[i]],
|
|
456
|
+
deposit_address: basePoolIdZapDict[basePoolIds[i]].address,
|
|
454
457
|
is_meta: true,
|
|
455
458
|
is_factory: true,
|
|
456
459
|
base_pool: basePoolIds[i],
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export interface ICurve {
|
|
|
70
70
|
DECIMALS: IDict<number>;
|
|
71
71
|
GAUGES: string[];
|
|
72
72
|
};
|
|
73
|
+
setContract: (address: string, abi: any) => void;
|
|
73
74
|
}
|
|
74
75
|
export interface ICoinFromPoolDataApi {
|
|
75
76
|
address: string;
|
|
@@ -99,6 +100,7 @@ export interface IPoolDataFromApi {
|
|
|
99
100
|
coins: ICoinFromPoolDataApi[];
|
|
100
101
|
gaugeRewards?: IReward[];
|
|
101
102
|
usdTotal: number;
|
|
103
|
+
totalSupply: number;
|
|
102
104
|
}
|
|
103
105
|
export interface ISubgraphPoolData {
|
|
104
106
|
address: string;
|
|
@@ -114,12 +116,17 @@ export interface IExtendedPoolDataFromApi {
|
|
|
114
116
|
export interface IRouteStep {
|
|
115
117
|
poolId: string;
|
|
116
118
|
poolAddress: string;
|
|
119
|
+
inputCoinAddress: string;
|
|
117
120
|
outputCoinAddress: string;
|
|
118
121
|
i: number;
|
|
119
122
|
j: number;
|
|
120
123
|
swapType: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
121
124
|
swapAddress: string;
|
|
122
125
|
}
|
|
126
|
+
export interface IRoute_ {
|
|
127
|
+
steps: IRouteStep[];
|
|
128
|
+
minTvl: number;
|
|
129
|
+
}
|
|
123
130
|
export interface IRoute {
|
|
124
131
|
steps: IRouteStep[];
|
|
125
132
|
_output: ethers.BigNumber;
|
|
@@ -162,32 +162,71 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
162
162
|
});
|
|
163
163
|
};
|
|
164
164
|
this.statsVolume = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
-
var network, poolsData, poolData;
|
|
165
|
+
var _c, mainPoolsData, factoryPoolsData, poolData_1, lpPrice, network, poolsData, poolData;
|
|
166
166
|
var _this = this;
|
|
167
|
-
return __generator(this, function (
|
|
168
|
-
switch (
|
|
167
|
+
return __generator(this, function (_d) {
|
|
168
|
+
switch (_d.label) {
|
|
169
169
|
case 0:
|
|
170
|
+
if (!(curve_1.curve.chainId === 1284)) return [3 /*break*/, 3];
|
|
171
|
+
return [4 /*yield*/, Promise.all([
|
|
172
|
+
(0, external_api_1._getMoonbeamLegacyAPYsAndVolumes)(),
|
|
173
|
+
(0, external_api_1._getMoonbeamFactoryAPYsAndVolumes)(),
|
|
174
|
+
])];
|
|
175
|
+
case 1:
|
|
176
|
+
_c = _d.sent(), mainPoolsData = _c[0], factoryPoolsData = _c[1];
|
|
177
|
+
if (this.id in mainPoolsData) {
|
|
178
|
+
return [2 /*return*/, mainPoolsData[this.id].volume.toString()];
|
|
179
|
+
}
|
|
180
|
+
poolData_1 = factoryPoolsData.find(function (d) { return d.poolAddress.toLowerCase() === _this.address; });
|
|
181
|
+
if (!poolData_1)
|
|
182
|
+
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
183
|
+
return [4 /*yield*/, (0, utils_1._getUsdRate)(this.lpToken)];
|
|
184
|
+
case 2:
|
|
185
|
+
lpPrice = _d.sent();
|
|
186
|
+
return [2 /*return*/, (poolData_1.volume * lpPrice).toString()];
|
|
187
|
+
case 3:
|
|
170
188
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
171
189
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
172
|
-
case
|
|
173
|
-
poolsData = (
|
|
190
|
+
case 4:
|
|
191
|
+
poolsData = (_d.sent());
|
|
174
192
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
175
193
|
if (!poolData)
|
|
176
|
-
throw Error("Can't get
|
|
194
|
+
throw Error("Can't get Volume for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
177
195
|
return [2 /*return*/, poolData.volumeUSD.toString()];
|
|
178
196
|
}
|
|
179
197
|
});
|
|
180
198
|
}); };
|
|
181
199
|
this.statsBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
182
|
-
var network, poolsData, poolData;
|
|
200
|
+
var _c, mainPoolsData, factoryPoolsData, poolData_2, network, poolsData, poolData;
|
|
183
201
|
var _this = this;
|
|
184
|
-
return __generator(this, function (
|
|
185
|
-
switch (
|
|
202
|
+
return __generator(this, function (_d) {
|
|
203
|
+
switch (_d.label) {
|
|
186
204
|
case 0:
|
|
205
|
+
if (!(curve_1.curve.chainId === 1284)) return [3 /*break*/, 2];
|
|
206
|
+
return [4 /*yield*/, Promise.all([
|
|
207
|
+
(0, external_api_1._getMoonbeamLegacyAPYsAndVolumes)(),
|
|
208
|
+
(0, external_api_1._getMoonbeamFactoryAPYsAndVolumes)(),
|
|
209
|
+
])];
|
|
210
|
+
case 1:
|
|
211
|
+
_c = _d.sent(), mainPoolsData = _c[0], factoryPoolsData = _c[1];
|
|
212
|
+
if (this.id in mainPoolsData) {
|
|
213
|
+
return [2 /*return*/, {
|
|
214
|
+
day: mainPoolsData[this.id].apy.day.toString(),
|
|
215
|
+
week: mainPoolsData[this.id].apy.week.toString(),
|
|
216
|
+
}];
|
|
217
|
+
}
|
|
218
|
+
poolData_2 = factoryPoolsData.find(function (d) { return d.poolAddress.toLowerCase() === _this.address; });
|
|
219
|
+
if (!poolData_2)
|
|
220
|
+
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
221
|
+
return [2 /*return*/, {
|
|
222
|
+
day: poolData_2.apy.toString(),
|
|
223
|
+
week: poolData_2.apy.toString(),
|
|
224
|
+
}];
|
|
225
|
+
case 2:
|
|
187
226
|
network = curve_1.curve.constants.NETWORK_NAME;
|
|
188
227
|
return [4 /*yield*/, (0, external_api_1._getSubgraphData)(network)];
|
|
189
|
-
case
|
|
190
|
-
poolsData = (
|
|
228
|
+
case 3:
|
|
229
|
+
poolsData = (_d.sent());
|
|
191
230
|
poolData = poolsData.find(function (d) { return d.address.toLowerCase() === _this.address; });
|
|
192
231
|
if (!poolData)
|
|
193
232
|
throw Error("Can't get base APY for ".concat(this.name, " (id: ").concat(this.id, ")"));
|
|
@@ -262,7 +301,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
262
301
|
case 0:
|
|
263
302
|
if (this.gauge === ethers_1.ethers.constants.AddressZero)
|
|
264
303
|
return [2 /*return*/, []];
|
|
265
|
-
if (![10, 100, 137, 250, 43114, 42161].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
|
|
304
|
+
if (![10, 100, 137, 250, 1284, 43114, 42161].includes(curve_1.curve.chainId)) return [3 /*break*/, 8];
|
|
266
305
|
apy = [];
|
|
267
306
|
return [4 /*yield*/, this.rewardTokens()];
|
|
268
307
|
case 1:
|
|
@@ -371,11 +410,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
371
410
|
_d = [(0, utils_1.toBN)(_totalSupply), (0, utils_1.toBN)(_fee, 10).times(N_coins).div(4 * (N_coins - 1)), (0, utils_1.toBN)(_lpTokenAmount)], totalSupplyBN = _d[0], feeBN = _d[1], lpTokenAmountBN = _d[2];
|
|
372
411
|
balancesBN = balances.map(function (b) { return (0, utils_1.BN)(b); });
|
|
373
412
|
amountsBN = _amounts.map(function (_a, i) { return (0, utils_1.toBN)(_a, decimals[i]); });
|
|
374
|
-
feesBN =
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
413
|
+
feesBN = Array(N_coins).fill((0, utils_1.BN)(0));
|
|
414
|
+
if (totalSupplyBN.gt(0)) {
|
|
415
|
+
for (i = 0; i < N_coins; i++) {
|
|
416
|
+
feesBN[i] = balancesBN[i].times(lpTokenAmountBN).div(totalSupplyBN).minus(amountsBN[i]).times(feeBN);
|
|
417
|
+
if (feesBN[i].lt(0))
|
|
418
|
+
feesBN[i] = feesBN[i].times(-1);
|
|
419
|
+
}
|
|
379
420
|
}
|
|
380
421
|
_fees = feesBN.map(function (fBN, i) { return (0, utils_1.fromBN)(fBN, decimals[i]); });
|
|
381
422
|
return [4 /*yield*/, this._pureCalcLpTokenAmount(_fees, !isDeposit, useUnderlying)];
|
package/lib/router.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { IRouteStep } from "./interfaces";
|
|
2
|
+
export declare const NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
3
|
+
export declare const NATIVE_TOKENS: {
|
|
4
|
+
[index: number]: {
|
|
5
|
+
symbol: string;
|
|
6
|
+
wrappedSymbol: string;
|
|
7
|
+
wrappedAddress: string;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare const _findAllRoutesTheShorterTheBetter: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
|
|
11
|
+
export declare const _findAllRoutesTvl: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
|
|
2
12
|
export declare const _findAllRoutes: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
|
|
3
13
|
export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<{
|
|
4
14
|
route: IRouteStep[];
|