Skip to content

Commit

Permalink
refactor: sdvt account info
Browse files Browse the repository at this point in the history
  • Loading branch information
avsetsin committed Mar 23, 2024
1 parent 7fabf32 commit 105bc56
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions programs/staking-module/simple-dvt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ const expectedSplitMainAddress = splitMainAddress;

const intl = new Intl.NumberFormat('en-GB', { minimumFractionDigits: 2 });

const formatETH = (wei: bigint) => {
return intl.format(Number(wei / 10n ** 15n) / 1000);
};

const getFormattedAccountInfo = async (account: string) => {
const [txCount, balance] = await Promise.all([
provider.getTransactionCount(account, 'latest'),
provider.getBalance(account),
]);

const balanceEth = formatETH(balance);
const txCountFormatted = txCount > 0 ? ok(txCount) : warn(txCount);
const balanceFormatted = balance > 0 ? ok(balanceEth) : warn(balanceEth);

return {
nonce: txCountFormatted,
balance: balanceFormatted,
};
};

export const checkWrapperContract = async (wrapperAddress: string, fromBlock: number, toBlock: number) => {
const wrapperContract = new Contract(wrapperAddress, obolLidoSplitAbi, provider);

Expand Down Expand Up @@ -144,17 +164,8 @@ export const check0xSplit = async (splitWalletAddress: string, fromBlock: number
...(await Promise.all(
accounts.map(async (account, index) => {
const share = passOrFail(String(allocations[index]), isFairAllocation);

const [txCount, balance] = await Promise.all([
provider.getTransactionCount(account, 'latest'),
provider.getBalance(account),
]);

const balanceEth = intl.format(Number(balance / 10n ** 16n) / 100);
const txCountFormatted = txCount > 0 ? ok(txCount) : warn(txCount);
const balanceFormatted = balance > 0 ? ok(balanceEth) : warn(balanceEth);

return [account, share, txCountFormatted, balanceFormatted];
const { nonce, balance } = await getFormattedAccountInfo(account);
return [account, share, nonce, balance];
}),
)),
);
Expand Down Expand Up @@ -207,18 +218,9 @@ export const checkGnosisSafe = async (safeAddress: string, splitAccounts: string
ownersTable.push(
...(await Promise.all(
sortedGnosisOwners.map(async (account) => {
const [txCount, balance] = await Promise.all([
provider.getTransactionCount(account, 'latest'),
provider.getBalance(account),
]);

const balanceEth = intl.format(Number(balance / 10n ** 16n) / 100);
const txCountFormatted = txCount > 0 ? ok(txCount) : warn(txCount);
const balanceFormatted = balance > 0 ? ok(balanceEth) : warn(balanceEth);

const isInSplit = sortedSplitAccounts.includes(account) ? ok('yes') : warn('no');

return [account, isInSplit, txCountFormatted, balanceFormatted];
const { nonce, balance } = await getFormattedAccountInfo(account);
return [account, isInSplit, nonce, balance];
}),
)),
);
Expand Down

0 comments on commit 105bc56

Please sign in to comment.