migration: adjusting total issuance
@@ -532,9 +532,11 @@ const removeDemocracyLocks = (registry, value) => {
const tripleBalance = (registry, value, decreaseConsumers) => {
let aInfo = registry.createType("AccountInfo", value);
let balance = new BN(aInfo.data.free.toString())
- let reserved = new BN(aInfo.data.reserved.toString())
+ const reserved = new BN(aInfo.data.reserved.toString())
- balance = balance.imuln(3).add(reserved.imuln(2)); // Only * 2 for reserved because the amount remains in reserved.
+ const issued = balance.imuln(2).add(reserved.imuln(2));
+
+ balance = balance.add(issued);
let b = registry.createType("Balance", balance.toString(10,0));
@@ -552,7 +554,7 @@ const tripleBalance = (registry, value, decreaseConsumers) => {
let newInfo = registry.createType("AccountInfo", { ...aInfo, nonce: 0, consumers: consumers, data: newData});
- return newInfo.toHex();
+ return [newInfo.toHex(), issued];
}
const tripleClaim = (registry, value) => {
@@ -574,6 +576,7 @@ const triple = async (source, destination, stakingAccountsRemoved = [], democrac
const systemAccountPrefix = modulePrefixes.get("System.Account");
const claimsPrefix = modulePrefixes.get("Claims.Claims");
+ let totalIssued = new BN(0);
const storageAdjusted = storage.map( ( keyValue ) => {
const key = keyValue[0];
@@ -595,7 +598,9 @@ const triple = async (source, destination, stakingAccountsRemoved = [], democrac
decreaseConsumers += 1;
}
- newValue = tripleBalance(registry, value, decreaseConsumers);
+ const [tripled, issued] = tripleBalance(registry, value, decreaseConsumers);
+ newValue = tripled;
+ totalIssued = totalIssued.add(issued);
}else{
//TODO: staking locks and democracy locks for excluded address ?!!
log(`Balance tripling - excluding ${chalk.yellow(hdxAddress)}`)
@@ -605,8 +610,20 @@ const triple = async (source, destination, stakingAccountsRemoved = [], democrac
}
return [key, newValue];
- });
+ }).map(([key, value]) => {
+ let newValue = value;
+ if (key.startsWith(modulePrefixes.get("Balances.TotalIssuance"))) {
+ if (value > 0 ) {
+ let totalIssuance = new BN(value.substring(2), 16, "le");
+ totalIssuance = totalIssuance.add(totalIssued);
+ const le = totalIssuance.toBuffer("le", 16);
+ newValue = "0x".concat(Buffer.from(le).toString("hex"));
+ }
+ }
+
+ return [key, newValue];
+ });
fs.writeFileSync(destination, JSON.stringify(storageAdjusted));
log(`Balance and claims tripled. Stored in ${destination}`);
