Skip to content

Commit

Permalink
Beanstalk3 codehawks remediations (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 committed Sep 23, 2024
2 parents d795bc4 + 312e363 commit 811c93d
Show file tree
Hide file tree
Showing 785 changed files with 556,206 additions and 196,760 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,22 @@
"sdk:prettier": "yarn prettier projects/sdk -w",
"sdk:publish": "yarn workspace @beanstalk/sdk publish",
"sdk:version": "yarn workspace @beanstalk/sdk version",
"dex-ui:dev": "yarn workspace dex-ui dev",
"dex-ui:build": "yarn workspace dex-ui build",
"dex-ui:generate": "yarn workspace dex-ui generate",
"ui:generate": "yarn workspace ui generate",
"ui:dev": "yarn workspace ui dev",
"ui:start": "yarn workspace ui start",
"ui:build": "yarn workspace ui build",
"ui:test": "yarn workspace ui test",
"test:browser": "yarn workspace tests test:browser",
"ex": "yarn workspace @beanstalk/examples x",
"anvil-arbitrum": "yarn cli:anvil-arbitrum",
"anvil-eth-mainnet": "yarn cli:anvil-eth-mainnet",
"anvil": "anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/5ubn94zT7v7DnB5bNW1VOnoIbX5-AG2N --chain-id 1337",
"anvil4tests": "anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/Kk7ktCQL5wz4v4AG8bR2Gun8TAASQ-qi --chain-id 1337 --fork-block-number 18629000"
},
"dependencies": {
"prettier-plugin-solidity": "1.4.0"
"prettier-plugin-solidity": "1.4.1"
}
}
5 changes: 5 additions & 0 deletions projects/cli/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# DEV API key
DEV_ALCHEMY_API_KEY=""

# Test API key
DEV_TEST_ALCHEMY_API_KEY=""
2 changes: 2 additions & 0 deletions projects/cli/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
node_modules
build

.env
48 changes: 48 additions & 0 deletions projects/cli/anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

source .env

# Set variables based on arguments
keyType="$1"
chainIdType="$2"

# Set chain IDs
mainnet_local_chain_id=1338

arbitrum_local_chain_id=1337

# Determine which API key to use
if [ "$keyType" = "test" ]; then
apiKey="$DEV_TEST_ALCHEMY_API_KEY"
else
apiKey="$DEV_ALCHEMY_API_KEY"
fi

# Determine which chain ID to use. Defaults to arbitrum local host
if [ "$chainIdType" = "eth-mainnet" ]; then
chainId=$mainnet_local_chain_id
prefix="eth"
port=9545
else
chainId=$arbitrum_local_chain_id
prefix="arb"
port=8545
fi

# Check if required variables are set
if [ -z "$prefix" ] || [ -z "$apiKey" ] || [ -z "$chainId" ]; then
echo "Error: Missing required variables. Please set keyType and chainIdType."
exit 1
fi

anvil \
--fork-url "https://$prefix-mainnet.g.alchemy.com/v2/$apiKey" \
--chain-id "$chainId" \
--port "$port" \
"${@:3}"

# Check if Anvil exited with an error
if [ $? -ne 0 ]; then
echo "Error: Anvil exited with a non-zero status."
exit 1
fi
8 changes: 6 additions & 2 deletions projects/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beanstalk/cli",
"version": "0.0.10",
"version": "0.0.20",
"description": "Beanstalk protocol development cli tool",
"license": "MIT",
"repository": {
Expand All @@ -16,7 +16,11 @@
"scripts": {
"cli:publish": "yarn cli:build && yarn npm publish --access public",
"cli:build": "rimraf build && tsc && chmod u+x build/cli.js",
"g:bean": "yarn ts-node-esm src/cli.ts"
"g:bean": "yarn ts-node-esm src/cli.ts",
"cli:anvil-eth-mainnet": "bash anvil.sh dev eth-mainnet",
"cli:anvil-arbitrum": "bash anvil.sh dev arbitrum-mainnet",
"cli:anvil4tests-mainnet": "bash anvil.sh test eth-mainnet --fork-block-number 18629000",
"cli:anvil4tests-arbitrum": "bash anvil.sh test arbitrum-mainnet --fork-block-number 18629000"
},
"devDependencies": {
"@types/command-line-args": "^5.2.3",
Expand Down
33 changes: 24 additions & 9 deletions projects/cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ export const balance = async (sdk, { account, symbol }) => {
[
"ETH",
"WETH",
"WSTETH",
"WEETH",
"WBTC",
"BEAN",
"USDT",
"USDC",
"DAI",
"CRV3",
"UNRIPE_BEAN",
"UNRIPE_BEAN_wstETH",
"BEAN_CRV3_LP",
"BEAN_ETH_WELL_LP",
"ROOT"
"USDC",
"USDT",
"urBEAN",
"urBEANWSTETH",
"BEANWETH",
"BEANWEETH",
"BEANWEETH",
"BEANWBTC",
"BEANUSDC",
"BEANUSDT"
].map((s) => getBal(sdk, s, account))
);
res.push(...bals);
Expand All @@ -32,7 +37,17 @@ export const balance = async (sdk, { account, symbol }) => {
};

async function getBal(sdk, symbol: string, account: string) {
const token = sdk.tokens[symbol];
let token = sdk.tokens[symbol];
if (!token) {
if (symbol === "urBEAN") token = sdk.tokens.UNRIPE_BEAN;
if (symbol === "urBEANWSTETH") token = sdk.tokens.UNRIPE_BEAN_WSTETH;
if (symbol === "BEANWETH") token = sdk.tokens.BEAN_ETH_WELL_LP;
if (symbol === "BEANWEETH") token = sdk.tokens.BEAN_WEETH_WELL_LP;
if (symbol === "BEANWSTETH") token = sdk.tokens.BEAN_WSTETH_WELL_LP;
if (symbol === "BEANWBTC") token = sdk.tokens.BEAN_WBTC_WELL_LP;
if (symbol === "BEANUSDC") token = sdk.tokens.BEAN_USDC_WELL_LP;
if (symbol === "BEANUSDT") token = sdk.tokens.BEAN_USDT_WELL_LP;
}
if (!token) throw new Error(`No token found: ${symbol}`);

try {
Expand Down
33 changes: 22 additions & 11 deletions projects/cli/src/commands/setbalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ export const setbalance = async (sdk, chain, { account, symbol, amount }) => {
const symbols = [
"ETH",
"WETH",
"WSTETH",
"WEETH",
"WBTC",
"BEAN",
"USDT",
"USDC",
"DAI",
"CRV3",
"BEAN3CRV",
"BEANWETH",
"USDC",
"USDT",
"urBEAN",
"urBEANwstETH",
"ROOT"
"urBEANWSTETH",
"BEANWETH",
"BEANWSTETH",
"BEANWEETH",
"BEANWBTC",
"BEANUSDC",
"BEANUSDT"
];
if (!symbols.includes(symbol)) {
console.log(
Expand All @@ -33,10 +38,16 @@ export const setbalance = async (sdk, chain, { account, symbol, amount }) => {
process.exit(-1);
}
let t = sdk.tokens[symbol] as Token;
if (symbol === "urBEAN") t = sdk.tokens.UNRIPE_BEAN;
if (symbol === "urBEANwstETH") t = sdk.tokens.UNRIPE_BEAN_WSTETH;
if (symbol === "BEAN3CRV") t = sdk.tokens.BEAN_CRV3_LP;
if (symbol === "BEANWETH") t = sdk.tokens.BEAN_ETH_WELL_LP;
if (!t) {
if (symbol === "urBEAN") t = sdk.tokens.UNRIPE_BEAN;
if (symbol === "urBEANWSTETH") t = sdk.tokens.UNRIPE_BEAN_WSTETH;
if (symbol === "BEANWETH") t = sdk.tokens.BEAN_ETH_WELL_LP;
if (symbol === "BEANWEETH") t = sdk.tokens.BEAN_WEETH_WELL_LP;
if (symbol === "BEANWSTETH") t = sdk.tokens.BEAN_WSTETH_WELL_LP;
if (symbol === "BEANWBTC") t = sdk.tokens.BEAN_WBTC_WELL_LP;
if (symbol === "BEANUSDC") t = sdk.tokens.BEAN_USDC_WELL_LP;
if (symbol === "BEANUSDT") t = sdk.tokens.BEAN_USDT_WELL_LP;
}
if (typeof chain[`set${symbol}Balance`] !== "function")
throw new Error(`${symbol} is not a valid token or the method ${chalk.bold.whiteBright("")}`);

Expand Down
14 changes: 7 additions & 7 deletions projects/cli/src/commands/setprice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export const setPrice = async (sdk: BeanstalkSDK, chain: TestUtils.BlockchainUti
console.log(beanInput, crv3Input);

const newBeanAmount = (beanInput ? beanInput : 20) * 1_000_000;
const newCrv3Amount = (crv3Input ? crv3Input : beanInput ? beanInput : 20) * 1_000_000;
// const newCrv3Amount = (crv3Input ? crv3Input : beanInput ? beanInput : 20) * 1_000_000;

const newBean = sdk.tokens.BEAN.amount(newBeanAmount);
const newCrv3 = sdk.tokens.CRV3.amount(newCrv3Amount);
// const newBean = sdk.tokens.BEAN.amount(newBeanAmount);
// const newCrv3 = sdk.tokens.CRV3.amount(newCrv3Amount);

////// Set the new balance
console.log(`New Balances: ${newBean.toHuman()} ${newCrv3.toHuman()}`);
// console.log(`New Balances: ${newBean.toHuman()} ${newCrv3.toHuman()}`);
// update the array tracking balances
await setBalance(sdk, POOL_ADDRESS, BALANCE_SLOT, newBean, newCrv3);
// await setBalance(sdk, POOL_ADDRESS, BALANCE_SLOT, newBean, newCrv3);
// actually give the pool the ERC20's
await chain.setBEANBalance(POOL_ADDRESS, newBean);
await chain.setCRV3Balance(POOL_ADDRESS, newCrv3);
// await chain.setBEANBalance(POOL_ADDRESS, newBean);
// await chain.setCRV3Balance(POOL_ADDRESS, newCrv3);

// Curve also keeps track of the previous balance, so we just copy the existing current to old.
await setBalance(sdk, POOL_ADDRESS, PREV_BALANCE_SLOT, currentBean, currentCrv3);
Expand Down
8 changes: 5 additions & 3 deletions projects/dex-ui/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
VITE_AQUIFER_ADDRESS=local/fork deployed address
VITE_AQUIFER_ADDRESS_ETH="deployed address here"
VITE_AQUIFER_ADDRESS_ARBITRUM="deployed address here"
VITE_ALCHEMY_API_KEY="your key here"
VITE_THEGRAPH_API_KEY="your key here"
VITE_WALLET_CONNECT_PROJECT_ID="project key here"
VITE_WELLS_ORIGIN_BLOCK=17138465
VITE_LOAD_HISTORY_FROM_GRAPH=0
VITE_WALLET_CONNECT_PROJECT_ID="project key here"
VITE_LOAD_HISTORY_FROM_GRAPH=0
7 changes: 6 additions & 1 deletion projects/dex-ui/.env.production
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// DO NOT ACTUALLY SAVE THINGS HERE
// ONLY USE THIS FILE TO TRACK WHAT ENV VARS NEED TO
// BE ADDED TO NETLIFY CONFIG
VITE_AQUIFER_ADDRESS_ETH=""
VITE_AQUIFER_ADDRESS_ARBITRUM=""
VITE_ALCHEMY_API_KEY=""
VITE_WALLET_CONNECT_PROJECT_ID=""
VITE_THEGRAPH_API_KEY=""
VITE_WALLET_CONNECT_PROJECT_ID=""
VITE_WELLS_ORIGIN_BLOCK=""
VITE_LOAD_HISTORY_FROM_GRAPH=""
56 changes: 47 additions & 9 deletions projects/dex-ui/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
"settings": {
"react": {
"version": "detect"
},
"import/resolver": {
"typescript": {},
"node": {
"paths": ["src"],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"extends": [
"plugin:react/recommended",
"plugin:jsx-a11y/recommended",
// "plugin:@typescript-eslint/recommended",
// "plugin:import/errors",
// "plugin:import/warnings",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
Expand All @@ -18,13 +27,7 @@
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"react",
"react-hooks",
"@typescript-eslint",
"import",
"jsx-a11y"
],
"plugins": ["react", "react-hooks", "@typescript-eslint", "import", "jsx-a11y"],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
Expand All @@ -39,6 +42,41 @@
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": 0,
"react/display-name": 0
"react/display-name": 0,
"import/order": [
"warn",
{
"groups": [
"builtin",
"external",
"internal",
["parent", "sibling", "index"],
"object",
"type"
],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
},
{
"pattern": "@beanstalk/sdk*",
"group": "external",
"position": "after"
},
{
"pattern": "src/**",
"group": "internal"
}
],
"pathGroupsExcludedImportTypes": ["react", "@beanstalk/sdk*"],
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always"
}
]
}
}
}
3 changes: 2 additions & 1 deletion projects/dex-ui/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const config: CodegenConfig = {
schema: [
"graphql.schema.json",
// beanstalk subgraph
"https://graph.node.bean.money/subgraphs/name/beanstalk"
"https://graph.bean.money/beanstalk",
"https://graph.bean.money/beanstalk_eth"
],
documents: "src/**/*.graphql",
ignoreNoDocuments: true,
Expand Down
1 change: 1 addition & 0 deletions projects/dex-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"connectkit": "1.7.2",
"ethers": "^5.7.2",
"graphql-request": "5.2.0",
"jotai": "2.9.3",
"lightweight-charts": "4.1.3",
"prettier": "3.2.5",
"react": "^18.2.0",
Expand Down
30 changes: 30 additions & 0 deletions projects/dex-ui/src/assets/images/tokens/ARB.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 811c93d

Please sign in to comment.