Skip to content

Commit 6040ff4

Browse files
committed
refactor(firelight-status): replace web3.utils with native BigInt for asset calculations
1 parent 17e6228 commit 6040ff4

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

examples/developer-hub-javascript/firelight-status.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,12 @@ async function main() {
6969
);
7070

7171
// Calculate exchange rate (assets per share)
72-
const totalAssetsBN = web3.utils.toBN(totalAssets.toString());
73-
const totalSupplyBN = web3.utils.toBN(totalSupply.toString());
74-
if (!totalSupplyBN.isZero()) {
72+
const totalAssetsBN = BigInt(totalAssets.toString());
73+
const totalSupplyBN = BigInt(totalSupply.toString());
74+
if (totalSupplyBN !== 0n) {
7575
// Calculate: (totalAssets * 10^assetDecimals) / totalSupply for precision
76-
const precision = web3.utils
77-
.toBN(10)
78-
.pow(web3.utils.toBN(assetDecimalsNum));
79-
const rateBN = totalAssetsBN.mul(precision).div(totalSupplyBN);
76+
const precision = BigInt(10) ** BigInt(assetDecimalsNum);
77+
const rateBN = (totalAssetsBN * precision) / totalSupplyBN;
8078
const formattedRate = (
8179
Number(rateBN.toString()) / Math.pow(10, assetDecimalsNum)
8280
).toFixed(assetDecimalsNum);
@@ -135,11 +133,11 @@ async function main() {
135133
// 6. User Withdrawals and Redemptions
136134
// Check withdrawals for current and previous periods
137135
console.log("\n=== User Withdrawals ===");
138-
const currentPeriodBN = web3.utils.toBN(currentPeriod.toString());
136+
const currentPeriodBN = BigInt(currentPeriod.toString());
139137
const periodsToCheck = [currentPeriodBN];
140138

141-
if (!currentPeriodBN.isZero()) {
142-
periodsToCheck.push(currentPeriodBN.subn(1));
139+
if (currentPeriodBN !== 0n) {
140+
periodsToCheck.push(currentPeriodBN - 1n);
143141
}
144142

145143
for (const period of periodsToCheck) {

0 commit comments

Comments
 (0)