Skip to content

Commit c9f8bf9

Browse files
committed
Add crvusd supply allocated to yield basis to relevant endpoint
1 parent cfa8678 commit c9f8bf9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

routes/v1/getCrvusdTotalSupplyNumber.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
import { fn } from '#root/utils/api.js';
1414
import crvusd from "@curvefi/stablecoin-api";
1515
import configs from '#root/constants/configs/index.js'
16+
import getCrvusdAllocatedToYieldbasis from '#root/utils/data/prices.curve.fi/yieldbasis-crvusd-allocated.js';
1617

1718
export default fn(async () => {
1819
await crvusd.default.init('JsonRpc', { url: configs.ethereum.rpcUrl, privateKey: '' }, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0, chainId: 1 });
1920

20-
const crvusdTotalSupply = await crvusd.default.totalSupply();
21+
const [
22+
crvusdTotalSupply,
23+
crvusdAllocatedToYieldbasis,
24+
] = await Promise.all([
25+
crvusd.default.totalSupply(),
26+
getCrvusdAllocatedToYieldbasis(),
27+
]);
2128

22-
return Number(crvusdTotalSupply.total);
29+
return Number(crvusdTotalSupply.total) + Number(crvusdAllocatedToYieldbasis);
2330
}, {
2431
maxAge: 5 * 60, // 5m
2532
cacheKey: 'getCrvusdTotalSupplyNumber',
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { httpsAgentWithoutStrictSsl } from '#root/utils/Request.js';
2+
import memoize from 'memoizee';
3+
4+
const getCrvusdAllocatedToYieldbasis = memoize(async () => {
5+
const { data } = await (await fetch('https://prices.curve.finance/v1/crvusd/yield_basis/ethereum/supply', {
6+
dispatcher: httpsAgentWithoutStrictSsl,
7+
})).json();
8+
return data.total_allocated;
9+
}, {
10+
promise: true,
11+
maxAge: 30 * 60 * 1000, // That endpoint is cached 30 minutes, no point in querying it more often given its current use-case
12+
});
13+
14+
export default getCrvusdAllocatedToYieldbasis;

0 commit comments

Comments
 (0)