Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

chore: reset all token balances #252

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions src/actions/write/evolveState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { NON_CONTRACT_OWNER_MESSAGE } from '../../constants';
import { ContractWriteResult, Fees, IOState, PstAction } from '../../types';
import { NON_CONTRACT_OWNER_MESSAGE, TOTAL_IO_SUPPLY } from '../../constants';
import {
ContractWriteResult,
IOState,
PstAction,
WalletAddress,
} from '../../types';

// Updates this contract to new source code
export const evolveState = async (
Expand All @@ -12,14 +17,16 @@ export const evolveState = async (
throw new ContractError(NON_CONTRACT_OWNER_MESSAGE);
}

const updatedFees = Object.keys(state.fees).reduce((acc: Fees, key) => {
const existingFee = state.fees[key];
// convert the base fee to mIO
acc[key] = existingFee / 1_000_000;
return acc;
}, {});

state.fees = updatedFees;
const updatedBalances = Object.keys(state.balances).reduce(
(acc: Record<WalletAddress, number>, address) => {
// convert the base fee to mIO
acc[address] = 0;
return acc;
},
{},
);

updatedBalances[owner] = TOTAL_IO_SUPPLY.valueOf();
state.balances = updatedBalances;
return { state };
};
Loading