Skip to content

Commit 00c7734

Browse files
authored
Merge pull request #21 from curvefi/feat/detailed-totalSupply
Feat: detailed totalSupply
2 parents b4395fd + 85a3cf8 commit 00c7734

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ import crvusd from "@curvefi/stablecoin-api";
164164
// 1257.43
165165

166166
await crvusd.totalSupply(); // sum(llammasSupply) + sum(pegKeepersDebt)
167-
// 1415.12
167+
// {
168+
// total: '1415.12',
169+
// minted: '1415.12',
170+
// pegKeepersDebt: '0'
171+
// }
168172
})()
169173
```
170174

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@curvefi/stablecoin-api",
3-
"version": "1.5.2",
3+
"version": "1.5.3",
44
"description": "JavaScript library for Curve Stablecoin",
55
"main": "lib/index.js",
66
"author": "Macket",

src/utils.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export const getUsdRate = async (coin: string): Promise<number> => {
265265
return _usdRatesCache[coinAddress]['rate']
266266
}
267267

268-
export const totalSupply = async (): Promise<string> => {
268+
export const totalSupply = async (): Promise<{ total: string, minted: string, pegKeepersDebt: string }> => {
269269
const calls = [];
270270
for (const llammaId of crvusd.getLlammaList()) {
271271
const controllerAddress = crvusd.constants.LLAMMAS[llammaId].controller_address;
@@ -277,14 +277,15 @@ export const totalSupply = async (): Promise<string> => {
277277
}
278278
const res: ethers.BigNumber[] = await crvusd.multicallProvider.all(calls);
279279

280-
let totalSupplyBN = BN(0);
280+
let mintedBN = BN(0);
281281
for (let i = 0; i < crvusd.getLlammaList().length; i++) {
282282
const [_minted, _redeemed] = res.splice(0, 2);
283-
totalSupplyBN = toBN(_minted).minus(toBN(_redeemed)).plus(totalSupplyBN);
283+
mintedBN = toBN(_minted).minus(toBN(_redeemed)).plus(mintedBN);
284284
}
285+
let pegKeepersBN = BN(0);
285286
for (const _pegKeeperDebt of res) {
286-
totalSupplyBN = totalSupplyBN.plus(toBN(_pegKeeperDebt));
287+
pegKeepersBN = pegKeepersBN.plus(toBN(_pegKeeperDebt));
287288
}
288289

289-
return totalSupplyBN.toString();
290+
return { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() };
290291
}

0 commit comments

Comments
 (0)