@curvefi/api 1.15.0 → 1.15.1
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/README.md +49 -20
- package/lib/constants/aliases.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/pools.d.ts +6 -1
- package/lib/pools.js +35 -14
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -122,12 +122,36 @@ const WalletProvider: FunctionComponent = ({ children }) => {
|
|
|
122
122
|
...
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
## Available pools
|
|
126
|
+
```ts
|
|
127
|
+
import curve from "@curvefi/api";
|
|
128
|
+
|
|
129
|
+
(async () => {
|
|
130
|
+
await curve.init('JsonRpc', {}, {gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0});
|
|
131
|
+
|
|
132
|
+
console.log(curve.getPoolList());
|
|
133
|
+
// [
|
|
134
|
+
// 'compound', 'usdt', 'y', 'busd',
|
|
135
|
+
// 'susd', 'pax', 'ren', 'sbtc',
|
|
136
|
+
// 'hbtc', '3pool', 'gusd', 'husd',
|
|
137
|
+
// 'usdk', 'usdn', 'musd', 'rsv',
|
|
138
|
+
// 'tbtc', 'dusd', 'pbtc', 'bbtc',
|
|
139
|
+
// 'obtc', 'seth', 'eurs', 'ust',
|
|
140
|
+
// 'aave', 'steth', 'saave', 'ankreth',
|
|
141
|
+
// 'usdp', 'ib', 'link', 'tusd',
|
|
142
|
+
// 'frax', 'lusd', 'busdv2', 'reth',
|
|
143
|
+
// 'alusd', 'mim', 'tricrypto2', 'eurt',
|
|
144
|
+
// 'eurtusd', 'crveth', 'cvxeth'
|
|
145
|
+
// ]
|
|
146
|
+
})()
|
|
147
|
+
````
|
|
148
|
+
|
|
125
149
|
## Balances
|
|
126
150
|
```ts
|
|
127
151
|
import curve from "@curvefi/api";
|
|
128
152
|
|
|
129
153
|
(async () => {
|
|
130
|
-
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0
|
|
154
|
+
await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 });
|
|
131
155
|
|
|
132
156
|
console.log(await curve.getBalances(['DAI', 'sUSD']));
|
|
133
157
|
// OR console.log(await curve.getBalances(['0x6B175474E89094C44Da98b954EedeAC495271d0F', '0x57Ab1ec28D129707052df4dF418D58a2D46d5f51']));
|
|
@@ -218,41 +242,46 @@ import curve from "@curvefi/api";
|
|
|
218
242
|
(async () => {
|
|
219
243
|
await curve.init('JsonRpc', {}, {gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0});
|
|
220
244
|
|
|
221
|
-
const
|
|
245
|
+
const aave = new curve.Pool('aave');
|
|
222
246
|
|
|
223
|
-
console.log(await
|
|
247
|
+
console.log(await aave.stats.getParameters());
|
|
224
248
|
// {
|
|
225
|
-
// virtualPrice: '1.
|
|
249
|
+
// virtualPrice: '1.082056814810440924',
|
|
226
250
|
// fee: '0.04',
|
|
227
251
|
// adminFee: '0.02',
|
|
228
|
-
// A: '
|
|
252
|
+
// A: '2000',
|
|
253
|
+
// future_A: '2000',
|
|
254
|
+
// initial_A: '200',
|
|
255
|
+
// future_A_time: 1628525830000,
|
|
256
|
+
// initial_A_time: 1627923611000,
|
|
229
257
|
// gamma: undefined
|
|
230
258
|
// }
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
console.log(await aave.stats.getPoolBalances());
|
|
262
|
+
// [ '19619514.600802512613372364', '18740372.790339', '16065974.167437' ]
|
|
231
263
|
|
|
232
|
-
console.log(await
|
|
233
|
-
// [ '
|
|
234
|
-
|
|
235
|
-
console.log(await saave.stats.getPoolWrappedBalances());
|
|
236
|
-
// [ '56379002.278506498342855456', '40931955.428972956435172989' ]
|
|
264
|
+
console.log(await aave.stats.getPoolWrappedBalances());
|
|
265
|
+
// [ '19619514.600802512613372364', '18740372.790339', '16065974.167437' ]
|
|
237
266
|
|
|
238
|
-
console.log(await
|
|
239
|
-
//
|
|
267
|
+
console.log(await aave.stats.getTotalLiquidity());
|
|
268
|
+
// 54425861.55857851
|
|
240
269
|
|
|
241
|
-
console.log(await
|
|
242
|
-
//
|
|
270
|
+
console.log(await aave.stats.getVolume());
|
|
271
|
+
// 175647.68180084194
|
|
243
272
|
|
|
244
|
-
console.log(await
|
|
245
|
-
//
|
|
273
|
+
console.log(await aave.stats.getBaseApy());
|
|
274
|
+
// { day: '3.2015', week: '3.1185', month: '3.1318', total: '7.7286' }
|
|
246
275
|
|
|
247
|
-
console.log(await
|
|
248
|
-
// [ '0.
|
|
276
|
+
console.log(await aave.stats.getTokenApy());
|
|
277
|
+
// [ '0.4093', '1.0233' ]
|
|
249
278
|
|
|
250
|
-
console.log(await
|
|
279
|
+
console.log(await aave.stats.getRewardsApy());
|
|
251
280
|
// [
|
|
252
281
|
// {
|
|
253
282
|
// token: '0x4da27a545c0c5B758a6BA100e3a049001de870f5',
|
|
254
283
|
// symbol: 'stkAAVE',
|
|
255
|
-
// apy: '0.
|
|
284
|
+
// apy: '0.4978306501849664'
|
|
256
285
|
// }
|
|
257
286
|
// ]
|
|
258
287
|
})()
|
package/lib/constants/aliases.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.ALIASES_ETHEREUM = {
|
|
|
12
12
|
};
|
|
13
13
|
exports.ALIASES_POLYGON = {
|
|
14
14
|
"crv": "0x172370d5cd63279efa6d502dab29171933a610af",
|
|
15
|
-
"minter": "",
|
|
15
|
+
"minter": "0xd061D61a4d941c39E5453435B6345Dc261C2fcE0",
|
|
16
16
|
"voting_escrow": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
|
|
17
17
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
18
18
|
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
package/lib/pools.d.ts
CHANGED
|
@@ -56,7 +56,12 @@ export declare class Pool {
|
|
|
56
56
|
getPoolWrappedBalances: () => Promise<string[]>;
|
|
57
57
|
getTotalLiquidity: () => Promise<string>;
|
|
58
58
|
getVolume: () => Promise<string>;
|
|
59
|
-
getBaseApy: () => Promise<
|
|
59
|
+
getBaseApy: () => Promise<{
|
|
60
|
+
day: string;
|
|
61
|
+
week: string;
|
|
62
|
+
month: string;
|
|
63
|
+
total: string;
|
|
64
|
+
}>;
|
|
60
65
|
getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>;
|
|
61
66
|
getRewardsApy: () => Promise<RewardsApyInterface[]>;
|
|
62
67
|
};
|
package/lib/pools.js
CHANGED
|
@@ -127,21 +127,26 @@ var Pool = /** @class */ (function () {
|
|
|
127
127
|
});
|
|
128
128
|
};
|
|
129
129
|
this.getParameters = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
130
|
-
var calls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma;
|
|
131
|
-
return __generator(this, function (
|
|
132
|
-
switch (
|
|
130
|
+
var multicallContract, calls, additionalCalls, _a, _virtualPrice, _fee, _adminFee, _A, _gamma, _c, virtualPrice, fee, adminFee, A, gamma, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
|
|
131
|
+
return __generator(this, function (_f) {
|
|
132
|
+
switch (_f.label) {
|
|
133
133
|
case 0:
|
|
134
|
+
multicallContract = curve_1.curve.contracts[this.swap].multicallContract;
|
|
134
135
|
calls = [
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
multicallContract.get_virtual_price(),
|
|
137
|
+
multicallContract.fee(),
|
|
138
|
+
multicallContract.admin_fee(),
|
|
139
|
+
multicallContract.A(),
|
|
139
140
|
];
|
|
140
141
|
if (this.isCrypto)
|
|
141
|
-
calls.push(
|
|
142
|
+
calls.push(multicallContract.gamma());
|
|
143
|
+
additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()];
|
|
144
|
+
if ('initial_A' in multicallContract) {
|
|
145
|
+
additionalCalls.push(multicallContract.initial_A(), multicallContract.future_A_time(), multicallContract.initial_A_time());
|
|
146
|
+
}
|
|
142
147
|
return [4 /*yield*/, curve_1.curve.multicallProvider.all(calls)];
|
|
143
148
|
case 1:
|
|
144
|
-
_a =
|
|
149
|
+
_a = _f.sent(), _virtualPrice = _a[0], _fee = _a[1], _adminFee = _a[2], _A = _a[3], _gamma = _a[4];
|
|
145
150
|
_c = [
|
|
146
151
|
ethers_1.ethers.utils.formatUnits(_virtualPrice),
|
|
147
152
|
ethers_1.ethers.utils.formatUnits(_fee, 8),
|
|
@@ -149,7 +154,17 @@ var Pool = /** @class */ (function () {
|
|
|
149
154
|
ethers_1.ethers.utils.formatUnits(_A, 0),
|
|
150
155
|
_gamma ? ethers_1.ethers.utils.formatUnits(_gamma) : _gamma,
|
|
151
156
|
], virtualPrice = _c[0], fee = _c[1], adminFee = _c[2], A = _c[3], gamma = _c[4];
|
|
152
|
-
|
|
157
|
+
A_PRECISION = curve_1.curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.name) ? 1 : 100;
|
|
158
|
+
return [4 /*yield*/, curve_1.curve.multicallProvider.all(additionalCalls)];
|
|
159
|
+
case 2:
|
|
160
|
+
_d = _f.sent(), _future_A = _d[0], _initial_A = _d[1], _future_A_time = _d[2], _initial_A_time = _d[3];
|
|
161
|
+
_e = [
|
|
162
|
+
_future_A ? String(Number(ethers_1.ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined,
|
|
163
|
+
_initial_A ? String(Number(ethers_1.ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined,
|
|
164
|
+
_future_A_time ? Number(ethers_1.ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined,
|
|
165
|
+
_initial_A_time ? Number(ethers_1.ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined,
|
|
166
|
+
], future_A = _e[0], initial_A = _e[1], future_A_time = _e[2], initial_A_time = _e[3];
|
|
167
|
+
return [2 /*return*/, { virtualPrice: virtualPrice, fee: fee, adminFee: adminFee, A: A, future_A: future_A, initial_A: initial_A, future_A_time: future_A_time, initial_A_time: initial_A_time, gamma: gamma }];
|
|
153
168
|
}
|
|
154
169
|
});
|
|
155
170
|
}); };
|
|
@@ -209,11 +224,11 @@ var Pool = /** @class */ (function () {
|
|
|
209
224
|
var balances, promises, _i, _a, addr, prices, totalLiquidity;
|
|
210
225
|
return __generator(this, function (_c) {
|
|
211
226
|
switch (_c.label) {
|
|
212
|
-
case 0: return [4 /*yield*/, this.
|
|
227
|
+
case 0: return [4 /*yield*/, this.getPoolBalances()];
|
|
213
228
|
case 1:
|
|
214
229
|
balances = _c.sent();
|
|
215
230
|
promises = [];
|
|
216
|
-
for (_i = 0, _a = this.
|
|
231
|
+
for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
|
|
217
232
|
addr = _a[_i];
|
|
218
233
|
promises.push((0, utils_1._getUsdRate)(addr));
|
|
219
234
|
}
|
|
@@ -249,7 +264,7 @@ var Pool = /** @class */ (function () {
|
|
|
249
264
|
});
|
|
250
265
|
}); };
|
|
251
266
|
this.getBaseApy = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
252
|
-
var name, statsUrl, apy;
|
|
267
|
+
var name, statsUrl, apy, formattedApy;
|
|
253
268
|
return __generator(this, function (_a) {
|
|
254
269
|
switch (_a.label) {
|
|
255
270
|
case 0:
|
|
@@ -258,7 +273,13 @@ var Pool = /** @class */ (function () {
|
|
|
258
273
|
return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
259
274
|
case 1:
|
|
260
275
|
apy = (_a.sent()).data.apy;
|
|
261
|
-
|
|
276
|
+
formattedApy = [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map(function (x) { return (x * 100).toFixed(4); });
|
|
277
|
+
return [2 /*return*/, {
|
|
278
|
+
day: formattedApy[0],
|
|
279
|
+
week: formattedApy[1],
|
|
280
|
+
month: formattedApy[2],
|
|
281
|
+
total: formattedApy[3],
|
|
282
|
+
}];
|
|
262
283
|
}
|
|
263
284
|
});
|
|
264
285
|
}); };
|
package/lib/utils.d.ts
CHANGED
|
@@ -22,3 +22,4 @@ export declare const ensureAllowance: (coins: string[], amounts: string[], spend
|
|
|
22
22
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
23
23
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
24
24
|
export declare const _getStatsUrl: (isCrypto?: boolean) => string;
|
|
25
|
+
export declare const getPoolList: () => string[];
|
package/lib/utils.js
CHANGED
|
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports._getStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
62
|
+
exports.getPoolList = exports._getStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
64
|
var ethers_1 = require("ethers");
|
|
65
65
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -419,13 +419,15 @@ exports._getUsdRate = _getUsdRate;
|
|
|
419
419
|
var _getStatsUrl = function (isCrypto) {
|
|
420
420
|
if (isCrypto === void 0) { isCrypto = false; }
|
|
421
421
|
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
422
|
-
return isCrypto ? "
|
|
422
|
+
return isCrypto ? "https://stats.curve.fi/raw-stats-crypto/apys.json" : "https://stats.curve.fi/raw-stats/apys.json";
|
|
423
423
|
}
|
|
424
424
|
else if (curve_1.curve.chainId === 137) {
|
|
425
|
-
return "
|
|
425
|
+
return "https://stats.curve.fi/raw-stats-polygon/apys.json";
|
|
426
426
|
}
|
|
427
427
|
else {
|
|
428
428
|
throw Error("Unsupported network id".concat(curve_1.curve.chainId));
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
431
|
exports._getStatsUrl = _getStatsUrl;
|
|
432
|
+
var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
|
|
433
|
+
exports.getPoolList = getPoolList;
|