Skip to content

Commit

Permalink
BIP-50: Reseed Beanstalk (#909)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brean0 authored Oct 10, 2024
2 parents 86e6550 + 707e472 commit 99bc465
Show file tree
Hide file tree
Showing 1,156 changed files with 626,343 additions and 159,372 deletions.
28 changes: 22 additions & 6 deletions .github/workflows/ci.protocol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,27 @@ on:
- "protocol/**"

jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: yarn add prettier
- run: yarn add prettier-plugin-solidity
- run: shopt -s globstar; yarn prettier --write --config .prettierrc --plugin=prettier-plugin-solidity protocol/**/*.sol || true
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: prettier auto formatting changes
branch: ${{ github.head_ref }}
- name: check format
run: shopt -s globstar; yarn prettier --check --config .prettierrc --plugin=prettier-plugin-solidity protocol/**/*.sol
test:
needs: format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -25,12 +45,8 @@ jobs:

- name: Install Dependencies
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: yarn install --no-immutable

- name: Generate (with cache)
id: generate-with-cache
continue-on-error: true
run: yarn generate
run: yarn install --immutable
- run: yarn generate
working-directory: protocol

- name: Clear cache and reinstall on generate failure
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ node_modules
# Local Netlify folder
.netlify

# forge libraries.
protocol/lib/

3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "protocol/lib/forge-std"]
path = protocol/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "protocol/lib/solmate"]
path = protocol/lib/solmate
url = https://github.com/transmissions11/solmate
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
"singleQuote": false,
"semi": true,
"trailingComma": "none",
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "solidity-parse",
"printWidth": 100,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false
}
},
{
"files": "projects/subgraph-*/**",
"options": {
Expand Down
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"esbenp.prettier-vscode",
"juanblanco.solidity"
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"solidity.formatter": "prettier"
}
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"jest": "29.2.2",
"jest-serial-runner": "1.2.1",
"lint-staged": "13.3.0",
"prettier": "3.2.5",
"prettier": "3.3.3",
"ts-jest": "29.1.2",
"ts-node": "10.9.2",
"typescript": "5.3.3"
Expand All @@ -42,13 +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.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=""
Loading

0 comments on commit 99bc465

Please sign in to comment.