Skip to content

Commit

Permalink
feat: sdvt checks table
Browse files Browse the repository at this point in the history
  • Loading branch information
avsetsin committed Mar 23, 2024
1 parent 077bcfc commit 7fabf32
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@chainsafe/ssz": "^0.13.0",
"JSONStream": "^1.3.5",
"chalk": "^4",
"cli-table3": "^0.6.4",
"commander": "^11.0.0",
"ethers": "^6.2.2",
"node-fetch": "^2",
Expand Down
73 changes: 56 additions & 17 deletions programs/staking-module/simple-dvt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import {
gnosisSafeProxyFactoryContract,
} from '@contracts';
import chalk from 'chalk';
import Table from 'cli-table3';

const header = chalk.white.bold;

const match = chalk.green;
const unmatch = chalk.gray;
const ok = chalk.green.bold;
const warn = chalk.yellow.bold;

const checkPass = (text: string) => chalk.green.bold(text) + ' ✅';
const checkFail = (text: string) => chalk.red.bold(text) + ' ❌';
Expand All @@ -32,6 +33,8 @@ const expectedStETHAddress = lidoAddress;
const expectedWstETHAddress = wstethAddress;
const expectedSplitMainAddress = splitMainAddress;

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

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

Expand Down Expand Up @@ -131,11 +134,33 @@ export const check0xSplit = async (splitWalletAddress: string, fromBlock: number
const minAllocation = Math.min(...allocations);
const isFairAllocation = maxAllocation - minAllocation <= 1;

logger.log('');
logger.log('Account Share');
accounts.forEach((account, index) => {
logger.log(account, passOrFail(String(allocations[index]), isFairAllocation));
const accountsTable = new Table({
head: ['Account', 'Share', 'Nonce', 'Balance'],
colAligns: ['left', 'right', 'right', 'right'],
style: { head: ['gray'], compact: true },
});

accountsTable.push(
...(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];
}),
)),
);

logger.log('');
logger.log(accountsTable.toString());
logger.log('');

return { splitWalletAccounts: accounts };
Expand Down Expand Up @@ -173,18 +198,32 @@ export const checkGnosisSafe = async (safeAddress: string, splitAccounts: string
logger.log('Owners amount: ', passOrFail(`${isAmountMatch ? '' : 'do not '}match Split`, isAmountMatch));
logger.log('Owners: ', passOrWarn(`${isOwnersMatch ? '' : 'do not '}match Split`, isOwnersMatch));

const rows = Math.max(gnosisOwners.length, splitAccounts.length);
const placeholder = ' '.repeat(40);
const ownersTable = new Table({
head: ['Account', 'In split', 'Nonce', 'Balance'],
colAligns: ['left', 'right', 'right', 'right'],
style: { head: ['gray'], compact: true },
});

ownersTable.push(
...(await Promise.all(
sortedGnosisOwners.map(async (account) => {
const [txCount, balance] = await Promise.all([
provider.getTransactionCount(account, 'latest'),
provider.getBalance(account),
]);

logger.log('Split accounts Gnosis owners');
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);

for (let i = 0; i < rows; i++) {
const splitAccount = splitAccounts[i] ?? placeholder;
const gnosisOwner = gnosisOwners[i] ?? placeholder;
const isInSplit = sortedSplitAccounts.includes(account) ? ok('yes') : warn('no');

logger.log(
gnosisOwners.includes(splitAccount) ? match(splitAccount) : unmatch(splitAccount),
splitAccounts.includes(gnosisOwner) ? match(gnosisOwner) : unmatch(gnosisOwner),
);
}
return [account, isInSplit, txCountFormatted, balanceFormatted];
}),
)),
);

logger.log('');
logger.log(ownersTable.toString());
logger.log('');
};
16 changes: 15 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
"@chainsafe/as-sha256" "^0.4.1"
"@chainsafe/persistent-merkle-tree" "^0.6.1"

"@colors/colors@1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
Expand Down Expand Up @@ -656,6 +661,15 @@ clean-stack@^2.0.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

cli-table3@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/cli-table3/-/cli-table3-0.6.4.tgz#d1c536b8a3f2e7bec58f67ac9e5769b1b30088b0"
integrity sha512-Lm3L0p+/npIQWNIiyF/nAn7T5dnOwR3xNTHXYEBFBFVPXzCVNZ5lqEC/1eo/EVfpDsQ1I+TX4ORPQgp+UI0CRw==
dependencies:
string-width "^4.2.0"
optionalDependencies:
"@colors/colors" "1.5.0"

color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
Expand Down Expand Up @@ -1867,7 +1881,7 @@ string-argv@^0.3.2:
resolved "https://registry.yarnpkg.com/string-argv/-/string-argv-0.3.2.tgz#2b6d0ef24b656274d957d54e0a4bbf6153dc02b6"
integrity sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==

"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3:
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand Down

0 comments on commit 7fabf32

Please sign in to comment.