Skip to content

Commit

Permalink
fix(generate): use toFixed on Decimal (#101)
Browse files Browse the repository at this point in the history
`toString` provides the answer in exponential notation, which is not
processed by golang well.
  • Loading branch information
MaxMustermann2 authored Sep 26, 2024
1 parent e6e342f commit 9c62433
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions script/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ async function updateGenesisFile() {
info: {
total_amount: delegationValue.toString(),
pending_undelegation_amount: "0",
total_share: totalShare.toString(),
operator_share: selfShare.toString(),
total_share: totalShare.toFixed(),
operator_share: selfShare.toFixed(),
}
};
assetsByOperator.push(assetsByOperatorForAsset);
Expand Down Expand Up @@ -395,13 +395,13 @@ async function updateGenesisFile() {
commission_rates: {
rate: new Decimal(
operatorInfo.commission.rate.toString()
).div('1e18').toString(),
).div('1e18').toFixed(),
max_rate: new Decimal(
operatorInfo.commission.maxRate.toString()
).div('1e18').toString(),
).div('1e18').toFixed(),
max_change_rate: new Decimal(
operatorInfo.commission.maxChangeRate.toString()
).div('1e18').toString(),
).div('1e18').toFixed(),
},
update_time: spawnDate,
}
Expand Down Expand Up @@ -431,15 +431,15 @@ async function updateGenesisFile() {
amount = amount.plus(
new Decimal(selfDelegationAmount.toString()).
div('1e' + decimals[j]).
mul(exchangeRates[j].toString())
mul(exchangeRates[j].toFixed())
);
const perTokenDelegation = await myContract.methods.delegationsByValidator(
opAddressExo, tokenAddress
).call();
totalAmount = totalAmount.plus(
new Decimal(perTokenDelegation.toString()).
div('1e' + decimals[j]).
mul(exchangeRates[j].toString())
mul(exchangeRates[j].toFixed())
);
// break;
}
Expand Down Expand Up @@ -475,9 +475,9 @@ async function updateGenesisFile() {
operator_usd_values.push({
key: usdValuekey,
opted_usd_value: {
self_usd_value: amount.toString(),
total_usd_value: totalAmount.toString(),
active_usd_value: totalAmount.toString(),
self_usd_value: amount.toFixed(),
total_usd_value: totalAmount.toFixed(),
active_usd_value: totalAmount.toFixed(),
}
});
dogfoodUSDValue = dogfoodUSDValue.plus(totalAmount);
Expand Down Expand Up @@ -525,7 +525,7 @@ async function updateGenesisFile() {
avs_usd_values.push({
avs_addr: dogfoodAddr,
value: {
amount: dogfoodUSDValue.toString(),
amount: dogfoodUSDValue.toFixed(),
},
});
// operator_usd_values
Expand Down Expand Up @@ -571,7 +571,7 @@ async function updateGenesisFile() {
});
genesisJSON.app_state.dogfood.val_set = validators;
genesisJSON.app_state.dogfood.params.asset_ids = assetIds;
genesisJSON.app_state.dogfood.last_total_power = totalPower.toString();
genesisJSON.app_state.dogfood.last_total_power = totalPower.toFixed();
// associations: staker_id is unique, so no further sorting is needed.
associations.sort((a, b) => {
if (a.staker_id < b.staker_id) {
Expand Down Expand Up @@ -613,7 +613,7 @@ async function updateGenesisFile() {
delegation_states.push({
key: key,
states: {
undelegatable_share: share.toString(),
undelegatable_share: share.toFixed(),
wait_undelegation_amount: "0"
},
});
Expand Down

0 comments on commit 9c62433

Please sign in to comment.