Skip to content

Commit

Permalink
Merge branch 'master' into ebip-9
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanSanderson authored Oct 23, 2023
2 parents 371eb20 + 26dd45b commit 447be2d
Show file tree
Hide file tree
Showing 79 changed files with 21,615 additions and 16,481 deletions.
4 changes: 4 additions & 0 deletions .yarn/versions/118d26de.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
undecided:
- "@beanstalk/sdk"
- ui
- "@beanstalk/protocol"
6 changes: 5 additions & 1 deletion PROPOSALS.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ You can read more about BIPs [here](https://docs.bean.money/almanac/governance/p
* [BIP-33](https://bean.money/bip-33): Beanstalk Farms H1 2023 Budget
* [BIP-34](https://bean.money/bip-34): Sunrise Improvements
* [BIP-35](https://bean.money/bip-35): Stalk Delegation and Process Amendments
* [BIP-36](https://bean.money/bip-36): Silo V3
* [BIP-37](https://bean.money/bip-37): Basin Integration
* [BIP-38](https://bean.money/bip-38): Migrate urBEAN3CRV to urBEANETH

## Emergency Beanstalk Improvement Proposal (EBIP)

Expand All @@ -59,6 +62,7 @@ You can read about the BCM's Emergency Response Procedures [here](https://docs.b
* [EBIP-5](https://bean.money/ebip-5): Remove transferTokenFrom Function
* [EBIP-6](https://bean.money/ebip-6): Resolve EBIP-4 and EBIP-5
* [EBIP-7](https://bean.money/ebip-7): Enroot BDV Update
* [EBIP-8](https://bean.money/ebip-8): Enroot BDV Rounding

## Beanstalk Operations Proposal (BOP)

Expand All @@ -68,4 +72,4 @@ You can read more about BOPs [here](https://docs.bean.money/almanac/governance/p

* [BOP-1](https://bean.money/bop-1): Ratify Disclosures Statement
* [BOP-2](https://bean.money/bop-2): Increase and Revisit Bounty for April Governance Exploit
* [BOP-2](https://bean.money/bop-3): Form the BeaNFT DAO
* [BOP-3](https://bean.money/bop-3): Form the BeaNFT DAO
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,63 @@
[discord-badge]: https://img.shields.io/discord/880413392916054098?label=Beanstalk
[discord-url]: https://discord.gg/beanstalk

[proj-protocol]: /protocol
[proj-sdk]: /projects/sdk
[proj-ui]: /projects/ui
[proj-sdk]: /projects/sdk
[proj-subgraph-beanstalk]: /projects/subgraph-beanstalk
[proj-subgraph-bean]: /projects/subgraph-bean
[proj-cli]: /projects/cli
[proj-basin-ui]: /projects/dex-ui
[proj-basin-sdk]: /projects/sdk-wells
[proj-subgraph-basin]: /projects/subgraph-wells

[basin-protocol]: https://github.com/BeanstalkFarms/Basin
[pipeline-protocol]: https://github.com/BeanstalkFarms/Pipeline


[es-beanstalk]: https://etherscan.io/address/0xC1E088fC1323b20BCBee9bd1B9fC9546db5624C5
[es-bean]: https://etherscan.io/address/0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab
[es-basin]: https://docs.basin.exchange/resources/contracts

[npm-beanstalk]: https://www.npmjs.com/package/@beanstalk/sdk

<img src="https://github.com/BeanstalkFarms/Beanstalk-Brand-Assets/blob/main/BEAN/bean-128x128.png" alt="Beanstalk logo" align="right" width="120" />

# Beanstalk

[![Discord][discord-badge]][discord-url]

Code Version: `2.5.0` <br>
Whitepaper Version: `2.5.0`
Code Version: `2.6.0` <br>
Whitepaper Version: `2.6.0`

## About

Beanstalk is a permissionless fiat stablecoin protocol built on Ethereum.

- [Repository](#repository)
- [Development](#development)
- [Documentation](#documentation)
- [Governance](#governance)
- [Audits](#audits)
- [Bug Bounty Program](#bug-bounty-program)
- [Contracts](#contracts)
- [License](#license)

## Repository

| Project | Description |
| ----------------------------------------------- | ------------------------------------------------------------------------------------ |
| [`protocol`][proj-protocol] | The Beanstalk protocol, its facets and related contracts in the Beanstalk ecosystem. |
| [`subgraph-beanstalk`][proj-subgraph-beanstalk] | A subgraph indexing Beanstalk ([0xC1E088][es-beanstalk]). |
| [`subgraph-bean`][proj-subgraph-bean] | A subgraph indexing the Bean ERC-20 token ([0xBEA000][es-bean]). |
| [`sdk`][proj-sdk] | A Typescript SDK for interacting with Beanstalk and ecosystem contracts. |
| [`ui`][proj-ui] | The Beanstalk UI hosted at [app.bean.money](https://app.bean.money). |
| [`cli`][proj-cli] | A tool for interacting with Beanstalk in a development environment. |
| Project | Description |
|:------------------------------------------------|:--------------------------------------------------------------------------------------------------------|
| [`protocol`][proj-protocol] | The Beanstalk protocol, its facets and related contracts in the Beanstalk ecosystem. |
| [`ui`][proj-ui] | The Beanstalk UI hosted at [app.bean.money](https://app.bean.money). |
| [`sdk`][proj-sdk] | A Typescript SDK for interacting with Beanstalk and ecosystem contracts ([npm module][npm-beanstalk]). |
| [`subgraph-beanstalk`][proj-subgraph-beanstalk] | A subgraph indexing Beanstalk ([0xC1E088][es-beanstalk]). |
| [`subgraph-bean`][proj-subgraph-bean] | A subgraph indexing the Bean ERC-20 token ([0xBEA000][es-bean]). |
| [`cli`][proj-cli] | A tool for interacting with Beanstalk in a development environment. |
| [`dex-ui`][proj-basin-ui] | The Basin UI hosted at [basin.exchange](https://basin.exchange). |
| [`sdk-wells`][proj-basin-sdk] | A Typescript SDK for interacting with Basin its components' contracts. |
| [`subgraph-wells`][proj-subgraph-basin] | A subgraph indexing Basin and its components. |

Note that the [Basin][basin-protocol] and [Pipeline][pipeline-protocol] contracts are in separate repostitories.

## Development

Expand All @@ -51,6 +70,10 @@ Technical documentation on Beanstalk can be found in the [Agronomics Handbook](h

The latest version of the Beanstalk Whitepaper is available [here](https://bean.money/beanstalk.pdf) (version history can be found [here](https://github.com/BeanstalkFarms/Beanstalk-Whitepaper/tree/main/version-history)).

## Governance

Read more about Beanstalk governance [here](https://docs.bean.money/almanac/governance/beanstalk). All past governance proposals can be found [here](https://github.com/BeanstalkFarms/Beanstalk-Governance-Proposals).

## Audits

Read more about Beanstalk audits [here](https://docs.bean.money/almanac/protocol/audits).
Expand All @@ -65,16 +88,6 @@ You can find the bug bounty program and submit bug reports [here](https://immune

A comprehensive list of contract addresses related to Beanstalk is available [here](https://docs.bean.money/almanac/protocol/contracts).

| Contract | Address |
| :--------------------------- | :-------------------------------------------------------------------------------------------------------------------- |
| Beanstalk | [0xC1E088fC1323b20BCBee9bd1B9fC9546db5624C5][es-beanstalk] |
| Bean | [0xBEA0000029AD1c77D3d5D23Ba2D8893dB9d1Efab][es-bean] |
| BEAN:3CRV LP token | [0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49](https://etherscan.io/address/0xc9C32cd16Bf7eFB85Ff14e0c8603cc90F6F2eE49) |
| Unripe Bean token | [0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449](https://etherscan.io/address/0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449) |
| Unripe BEAN:3CRV LP token | [0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D](https://etherscan.io/address/0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D) |
| Fertilizer ERC-1155 token | [0x402c84de2ce49af88f5e2ef3710ff89bfed36cb6](https://etherscan.io/address/0x402c84de2ce49af88f5e2ef3710ff89bfed36cb6) |
| Beanstalk Community Multisig | [0xa9bA2C40b263843C04d344727b954A545c81D043](https://etherscan.io/address/0xa9bA2C40b263843C04d344727b954A545c81D043) |

## License

[MIT](https://github.com/BeanstalkFarms/Beanstalk/blob/master/LICENSE.txt)
Binary file modified beanstalk.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion projects/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beanstalk/cli",
"version": "0.0.9",
"version": "0.0.10",
"description": "Beanstalk protocol development cli tool",
"license": "MIT",
"repository": {
Expand Down
6 changes: 5 additions & 1 deletion projects/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setbalance } from "./commands/setbalance.js";
import { sunrise } from "./commands/sunrise.js";
import { setPrice } from "./commands/setprice.js";
import { help } from "./commands/help.js";
import { mineBlocks } from "./commands/mine.js";

main().catch((e) => {
console.log("FAILED:");
Expand All @@ -22,7 +23,7 @@ async function main() {
{ name: "amount", alias: "m", defaultValue: "50000" },
{ name: "rpcUrl", alias: "r", defaultValue: "http://127.0.0.1:8545" },
{ name: "no-imp", type: Boolean },
{ name: "force", alias: "f", type: Boolean}
{ name: "force", alias: "f", type: Boolean }
];
const args = commandLineArgs(commands, { partial: true });

Expand All @@ -41,6 +42,9 @@ async function main() {
case "setprice":
await setPrice(sdk, chain, { params: args._unknown });
break;
case "mine":
await mineBlocks(sdk, args.amount);
break;
case "help":
default:
await help();
Expand Down
17 changes: 14 additions & 3 deletions projects/cli/src/commands/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ export const balance = async (sdk, { account, symbol }) => {
res.push(await getBal(sdk, symbol, account));
} else {
const bals = await Promise.all(
["ETH", "WETH", "BEAN", "USDT", "USDC", "DAI", "CRV3", "UNRIPE_BEAN", "UNRIPE_BEAN_CRV3", "BEAN_CRV3_LP", "ROOT"].map((s) =>
getBal(sdk, s, account)
)
[
"ETH",
"WETH",
"BEAN",
"USDT",
"USDC",
"DAI",
"CRV3",
"UNRIPE_BEAN",
"UNRIPE_BEAN_WETH",
"BEAN_CRV3_LP",
"BEAN_ETH_WELL_LP",
"ROOT"
].map((s) => getBal(sdk, s, account))
);
res.push(...bals);
}
Expand Down
18 changes: 18 additions & 0 deletions projects/cli/src/commands/mine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { BeanstalkSDK } from "@beanstalk/sdk";
import chalk from "chalk";
import { table } from "table";

export const mineBlocks = async (sdk: BeanstalkSDK, amount) => {
const numBlocks = amount === "50000" ? 1 : amount;

async function mineBlocks(blockNumber) {
while (blockNumber > 0) {
blockNumber--;
await sdk.provider.send("evm_mine", []);
}
}

await mineBlocks(numBlocks);

console.log(`${chalk.bold.whiteBright("Mined ")} ${chalk.greenBright(numBlocks)} block(s)`);
};
5 changes: 3 additions & 2 deletions projects/cli/src/commands/setbalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ export const setbalance = async (sdk, chain, { account, symbol, amount }) => {
if (!symbol) {
await chain.setAllBalances(account, amount);
} else {
const symbols = ["ETH", "WETH", "BEAN", "USDT", "USDC", "DAI", "3CRV", "BEAN3CRV", "urBEAN", "urBEAN3CRV", "ROOT"];
const symbols = ["ETH", "WETH", "BEAN", "USDT", "USDC", "DAI", "3CRV", "BEAN3CRV", "BEANWETH", "urBEAN", "urBEANWETH", "ROOT"];
if (!symbols.includes(symbol)) {
console.log(`${chalk.bold.red("Error")} - ${chalk.bold.white(symbol)} is not a valid token. Valid options are: `);
console.log(symbols.map((s) => chalk.green(s)).join(", "));
process.exit(-1);
}
let t = sdk.tokens[symbol] as Token;
if (symbol === "urBEAN") t = sdk.tokens.UNRIPE_BEAN;
if (symbol === "urBEAN3CRV") t = sdk.tokens.UNRIPE_BEAN_CRV3;
if (symbol === "urBEANWETH") t = sdk.tokens.UNRIPE_BEAN_WETH;
if (symbol === "BEAN3CRV") t = sdk.tokens.BEAN_CRV3_LP;
if (symbol === "BEANWETH") t = sdk.tokens.BEAN_ETH_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
4 changes: 2 additions & 2 deletions projects/sdk/src/classes/Workflow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from "ethers";
import { CallOverrides, ethers } from "ethers";
import { Token } from "src/classes/Token";
import { BeanstalkSDK } from "src/lib/BeanstalkSDK";
import { TokenValue } from "src/TokenValue";
Expand Down Expand Up @@ -593,7 +593,7 @@ export abstract class Workflow<
* @param slippage A human readable percent value. Ex: 0.1 would mean 0.1% slippage
* @returns Promise of a Transaction
*/
abstract execute(amountIn: ethers.BigNumber | TokenValue, data: RunData): Promise<ethers.ContractTransaction>;
abstract execute(amountIn: ethers.BigNumber | TokenValue, data: RunData, overrides?: CallOverrides): Promise<ethers.ContractTransaction>;

/**
* CallStatic version of the execute method. Allows testing the execution of the workflow.
Expand Down
4 changes: 2 additions & 2 deletions projects/sdk/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const addresses = {
UNRIPE_BEAN:
// "Unripe Bean": Unripe vesting asset for the Bean token, Localhost
Address.make("0x1BEA0050E63e05FBb5D8BA2f10cf5800B6224449"),
UNRIPE_BEAN_CRV3:
// "Unripe BEAN:CRV3 LP": Unripe vesting asset for the BEAN:CRV3 LP token, Localhost
UNRIPE_BEAN_WETH:
// "Unripe BEAN:WETH LP": Unripe vesting asset for the BEAN:WETH LP token, Localhost
Address.make("0x1BEA3CcD22F4EBd3d37d731BA31Eeca95713716D"),

// ----------------------------------------
Expand Down
22 changes: 18 additions & 4 deletions projects/sdk/src/lib/farm/LibraryPresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class LibraryPresets {

public readonly weth2bean: ActionBuilder;
public readonly bean2weth: ActionBuilder;
public readonly weth2bean3crv: ActionBuilder;
public readonly wellWethBean;
public readonly wellAddLiquidity;

Expand All @@ -37,6 +38,7 @@ export class LibraryPresets {
public readonly dai2weth: ActionBuilder;
public readonly usdc2weth: ActionBuilder;

public readonly usdt23crv: ActionBuilder;
public readonly usdc2beaneth;
public readonly usdt2beaneth;
public readonly dai2beaneth;
Expand Down Expand Up @@ -176,6 +178,20 @@ export class LibraryPresets {
this.usdt2weth(FarmFromMode.INTERNAL, toMode) as StepGenerator
];

///////// WETH -> 3CRV ///////////
this.weth2bean3crv = (fromMode?: FarmFromMode, toMode?: FarmToMode) => [
this.weth2usdt(fromMode, FarmToMode.INTERNAL) as StepGenerator,
this.usdt23crv(fromMode, FarmToMode.INTERNAL) as StepGenerator
];

//////// USDT -> 3CRV ////////
this.usdt23crv = (fromMode?: FarmFromMode, toMode?: FarmToMode) => {
const pool = sdk.contracts.curve.pools.pool3.address;
const registry = sdk.contracts.curve.registries.poolRegistry.address;
// [0 ,0 , 1] is for USDT; [DAI, USDC, USDT]
return new sdk.farm.actions.AddLiquidity(pool, registry, [0, 0, 1], fromMode, toMode);
};

///////// DAI -> USDT ///////////
this.dai2usdt = (fromMode?: FarmFromMode, toMode?: FarmToMode) =>
new Exchange(
Expand All @@ -197,7 +213,7 @@ export class LibraryPresets {
fromMode,
toMode
);

///////// DAI -> WETH ///////////
this.dai2weth = (fromMode?: FarmFromMode, toMode?: FarmToMode) => [
this.dai2usdt(fromMode, FarmToMode.INTERNAL) as StepGenerator,
Expand All @@ -210,7 +226,6 @@ export class LibraryPresets {
this.usdt2weth(FarmFromMode.INTERNAL, toMode) as StepGenerator
];


///////// [ USDC, USDT, DAI ] -> BEANETH ///////////
this.usdc2beaneth = (well: BasinWell, account: string, fromMode?: FarmFromMode, toMode?: FarmToMode) => [
this.usdc2weth(fromMode, FarmToMode.INTERNAL) as StepGenerator,
Expand Down Expand Up @@ -275,7 +290,6 @@ export class LibraryPresets {
};

this.wellAddLiquidity = (well: BasinWell, tokenIn: ERC20Token, account: string, from?: FarmFromMode, to?: FarmToMode) => {

const result = [];
const advancedPipe = sdk.farm.createAdvancedPipe("pipelineDeposit");

Expand Down Expand Up @@ -304,13 +318,13 @@ export class LibraryPresets {
}
const transferToBeanstalk = new sdk.farm.actions.TransferToken(well.address, account, FarmFromMode.EXTERNAL, FarmToMode.INTERNAL, transferClipboard);


result.push(transfer);
advancedPipe.add(addLiquidity, { tag: "amountToDeposit" });
if (transferBack) {
advancedPipe.add(approveBack);
advancedPipe.add(transferToBeanstalk);
}

result.push(advancedPipe);

return result;
Expand Down
3 changes: 3 additions & 0 deletions projects/sdk/src/lib/farm/actions/WellShift.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { Token } from "src/classes/Token";
import { RunContext, RunMode, Step, StepClass, Workflow } from "src/classes/Workflow";
import { AdvancedPipePreparedResult } from "src/lib/depot/pipe";

/**
* Swap tokens in a Well by using the shift() method
*/
export class WellShift extends StepClass<AdvancedPipePreparedResult> {
public name: string = "shift";

Expand Down
22 changes: 11 additions & 11 deletions projects/sdk/src/lib/farm/actions/WellSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { Token } from "src/classes/Token";
import { RunContext, RunMode, Step, StepClass } from "src/classes/Workflow";
import { AdvancedPipePreparedResult } from "src/lib/depot/pipe";

/**
* Add liqudity to a well using the Sync method, which transfers tokens directly to the well first
* which does not require an approval
*/
export class WellSync extends StepClass<AdvancedPipePreparedResult> {
public name: string = "wellSync";

Expand All @@ -31,7 +35,7 @@ export class WellSync extends StepClass<AdvancedPipePreparedResult> {
throw new Error("Reverse direction is not supported by wellSync");
}

let amounts: TokenValue[] = []
let amounts: TokenValue[] = [];
for (let i = 0; i < this._well.tokens.length; i++) {
if (i === tokenIndex) {
amounts[i] = this.tokenIn.fromBlockchain(_amountInStep);
Expand All @@ -47,23 +51,19 @@ export class WellSync extends StepClass<AdvancedPipePreparedResult> {
amountOut: quote.toBigNumber(),
value: ethers.BigNumber.from(0),
prepare: () => {

const minLP = quote.subSlippage(context.data.slippage || 0.1);

WellSync.sdk.debug(`>[${this.name}.prepare()]`, {
well: well.name,
recipient: this.recipient,
quoteAmountLessSlippage: minLP,
method: "sync",
context
well: well.name,
recipient: this.recipient,
quoteAmountLessSlippage: minLP,
method: "sync",
context
});

return {
target: well.address,
callData: well.contract.interface.encodeFunctionData("sync", [
this.recipient,
minLP.toBigNumber().toString(),
])
callData: well.contract.interface.encodeFunctionData("sync", [this.recipient, minLP.toBigNumber().toString()])
};
},
decode: (data: string) => well.contract.interface.decodeFunctionData("sync", data),
Expand Down
Loading

0 comments on commit 447be2d

Please sign in to comment.