Skip to content

Commit

Permalink
Merge pull request #21 from curvefi/feat/detailed-totalSupply
Browse files Browse the repository at this point in the history
Feat: detailed totalSupply
  • Loading branch information
Macket committed Mar 15, 2024
2 parents b4395fd + 85a3cf8 commit 00c7734
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ import crvusd from "@curvefi/stablecoin-api";
// 1257.43

await crvusd.totalSupply(); // sum(llammasSupply) + sum(pegKeepersDebt)
// 1415.12
// {
// total: '1415.12',
// minted: '1415.12',
// pegKeepersDebt: '0'
// }
})()
```
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/stablecoin-api",
"version": "1.5.2",
"version": "1.5.3",
"description": "JavaScript library for Curve Stablecoin",
"main": "lib/index.js",
"author": "Macket",
Expand Down
11 changes: 6 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export const getUsdRate = async (coin: string): Promise<number> => {
return _usdRatesCache[coinAddress]['rate']
}

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

let totalSupplyBN = BN(0);
let mintedBN = BN(0);
for (let i = 0; i < crvusd.getLlammaList().length; i++) {
const [_minted, _redeemed] = res.splice(0, 2);
totalSupplyBN = toBN(_minted).minus(toBN(_redeemed)).plus(totalSupplyBN);
mintedBN = toBN(_minted).minus(toBN(_redeemed)).plus(mintedBN);
}
let pegKeepersBN = BN(0);
for (const _pegKeeperDebt of res) {
totalSupplyBN = totalSupplyBN.plus(toBN(_pegKeeperDebt));
pegKeepersBN = pegKeepersBN.plus(toBN(_pegKeeperDebt));
}

return totalSupplyBN.toString();
return { total: mintedBN.plus(pegKeepersBN).toString(), minted: mintedBN.toString(), pegKeepersDebt: pegKeepersBN.toString() };
}

0 comments on commit 00c7734

Please sign in to comment.