Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more scripts #5

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ out/
.env
broadcast/
.github
.VSCodeCounter
.VSCodeCounter
deposits/
deposits/*.json
node-scripts/node_modules
bin
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ If you need to fork mainnet, single test contract
Verbosely test a single contract while forking mainnet
or ```source .env && forge test --fork-url $MAINNET_RPC_URL -m test_frxETHMinter_submitAndDepositRegular -vvvvv``` for single test verbosity level 5


### Other Scipts
tsx validate-msig-add-validators.ts

### Slither
1) Install [slither](https://github.com/crytic/slither#how-to-install)
2) Slither a single contract
Expand Down
6 changes: 5 additions & 1 deletion SAMPLE.env
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ VALIDATOR_GOERLI_SIG1=""
VALIDATOR_GOERLI_DDROOT1=""
VALIDATOR_GOERLI_PUBKEY2=""
VALIDATOR_GOERLI_SIG2=""
VALIDATOR_GOERLI_DDROOT2=""
VALIDATOR_GOERLI_DDROOT2=""

# Deposit Data
# =================================
DEPOSIT_DATA_PATH=""
5 changes: 3 additions & 2 deletions flattened.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.0;
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.8.0;


// ====================================================================
// | ______ _______ |
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
Submodule forge-std updated 1 files
+5 −0 src/Vm.sol
2 changes: 1 addition & 1 deletion lib/solmate
34 changes: 34 additions & 0 deletions node-scripts/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-console */
import chalk from 'chalk';

export interface ILogger {
info(...args: any[]): void;
warn(...args: any[]): void;
error(...args: any[]): void;
}

const logInternal = (method: 'info' | 'warn' | 'error', symbol: string, ...args: any[]) => {
const now = new Date();
const timestamp = chalk.gray(`[${now.toLocaleTimeString()}]`);

console[method](timestamp, symbol, ...args);
};

const spacer = ' ';
const frax = `${spacer}\u00A4${spacer}`;
const square = `${spacer}\u25A0${spacer}`;
const triangle = `${spacer}\u25B2${spacer}`;

export const logger: ILogger = {
info(...args: any[]) {
logInternal('info', chalk.green(square), ...args);
},

warn(...args: any[]) {
logInternal('warn', chalk.yellow(triangle), ...args);
},

error(...args: any[]) {
logInternal('error', chalk.bgRedBright.whiteBright(frax), ...args);
},
};
186 changes: 186 additions & 0 deletions node-scripts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions node-scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "frxeth-node-scripts",
"version": "1.0.0",
"description": "Node scripts for frxETH",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.1.3",
"chalk": "^5.1.2"
}
}
88 changes: 88 additions & 0 deletions node-scripts/validate-msig-add-validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { logger } from './logger';
import Axios from 'axios';

(async () => {
logger.info('[Start] Validating MSIG validators to add data...');

const { validators } = await Axios.get<{ validators: { publicKey: string; statusCode: string }[] }>(
'https://api.frax.finance/v2/frxeth/validators',
).then((r) => r.data);

logger.info(`Got ${validators.length} validators from the API`);

const { results } = await Axios.get<{
results: {
type: string;
transaction?: { id: string; executionInfo: { nonce: number }; txInfo: { methodName: string; to: { value: string } } };
}[];
}>('https://safe-client.safe.global/v1/chains/1/safes/0x8306300ffd616049FD7e4b0354a64Da835c1A81C/transactions/queued').then(
(r) => r.data,
);

const addValidatorTransactions = results.filter((f) => f.transaction?.txInfo.methodName === 'addValidators');

logger.info(
`Got ${results.filter((f) => f.type === 'TRANSACTION').length} transactions in the MSIG queue, ${
addValidatorTransactions.length
} of which are addValidators`,
);

const publicKeysToAdd: { key: string; nonce: number }[] = [];
for (const tx of addValidatorTransactions) {
if (tx.transaction) {
const { txData } = await Axios.get<{
txData: { dataDecoded: { method: string; parameters: { name: string; value: [string, string, string[]] }[] } };
}>(`https://safe-client.safe.global/v1/chains/1/transactions/${tx.transaction?.id}`).then((r) => r.data);

const validatorParams = txData.dataDecoded.parameters[0];

if (tx.transaction.txInfo.to.value !== '0xbAFA44EFE7901E04E39Dad13167D089C559c1138') {
logger.error(
`[#${tx.transaction.executionInfo.nonce}] Wrong to_address of ${tx.transaction.txInfo.to.value}, should be 0xbAFA44EFE7901E04E39Dad13167D089C559c1138`,
);
continue;
}

if (txData.dataDecoded.method === 'addValidators' && validatorParams.name === 'validatorArray') {
const txKeysToAdd = validatorParams.value.map((x) => ({ key: x[0], nonce: tx.transaction?.executionInfo.nonce ?? -1 }));
publicKeysToAdd.push(...txKeysToAdd);
logger.info(`For tx #${tx.transaction.executionInfo.nonce}, we got ${txKeysToAdd.length} validator public keys to add`);
}
}
}

logger.info(`Got a total of ${publicKeysToAdd.length} public keys to add`);

const uniquePublicKeys = [...new Set(publicKeysToAdd.map((x) => x.key))];

if (uniquePublicKeys.length !== publicKeysToAdd.length) {
logger.error('Duplicate keys found in enqueued transactions');
return;
} else {
logger.info(`There are no duplicate keys in the enqueued transactions`);
}

const keyStatuses = publicKeysToAdd.map((x) => ({
key: x.key,
status: validators.find((f) => f.publicKey === x.key)?.statusCode,
nonce: x.nonce,
}));

const keysWithIssues = keyStatuses.filter((f) => f.status !== 'uninitialized');

if (keysWithIssues.length > 0) {
for (const item of keysWithIssues) {
if (!item.status) {
logger.error(`[#${item.nonce}] ${item.key} is missing from the API`);
} else {
logger.error(`[#${item.nonce}] ${item.key} has status ${item.status}`);
}
}

logger.error(`Got ${keysWithIssues.length} total keys with issues`);
} else {
logger.info(`All ${keyStatuses.length} keys are good to go`);
}

logger.info('[End] Validated MSIG validators to add data');
})();
2 changes: 1 addition & 1 deletion script/DepositDataToCalldata.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pragma solidity ^0.8.0;
4. Use the final log output as data in a transaction to the frxETHMinter
/////////////////////////////////////////////////////////////////////////////////////////*/

import { stdJson } from "forge-std/stdJson.sol";
import { stdJson } from "forge-std/StdJson.sol";
import { Script } from "forge-std/Script.sol";
import { Test } from "forge-std/Test.sol";
import { frxETHMinter, OperatorRegistry } from "../src/frxETHMinter.sol";
Expand Down