Beanstalk is a decentralized credit based algorithmic stablecoin protocol that is built on Ethereum.
Contract | Addresss |
---|---|
Bean | 0xDC59ac4FeFa32293A95889Dc396682858d52e5Db |
Beanstalk | 0xC1E088fC1323b20BCBee9bd1B9fC9546db5624C5 |
UniswapV2 BEAN:ETH Pair | 0x87898263B6C5BABe34b4ec53F22d98430b91e371 |
Development Budget 1 | 0x83A758a6a24FE27312C1f8BDa7F3277993b64783 |
Marketing Budget 1 | 0xAA420e97534aB55637957e868b658193b112A551 |
BeaNFT OpenSea | 0xa755A670Aaf1FeCeF2bea56115E65e03F7722A79 |
The Beanstalk smart contract is a multi-facet proxy as it implements EIP-2535. Thus, the Beanstalk contract pulls in functions from a variety of different contracts (called facets in the EIP-2535 documentation) that are all capable of sharing the same state object.
The following are the different facets Beanstalk uses:
The following facets are part of the diamond functionality:
Contract | Addresss |
---|---|
DiamondCutFacet | 0xDFeFF7592915bea8D040499E961E332BD453C249 |
DiamondLoupeFacet | 0xB51D5C699B749E0382e257244610039dDB272Da0 |
OwnershipFacet | 0x0176D95fd451353F3543A4542e667C62b673621a |
- clone the repository
- run
cd protocol
to enter the protocol repository - run
npm install
- run
npx hardhat compile
- make sure you are in the
protocol
repository - run
npm test
to run all coverage tests - run
npx hardhat coverage
to run all coverage tests and generate a coverage report
As Beanstalk implements EIP-2535, Beanstalk is upgraded through a diamondCut
function call.
There are two different ways a diamondCut
can apply code to Beanstalk:
- adding/replacing/removing functions
- Functions being added/replaced are implemented in smart contracts referred to as
facets
. Facets are no different than a normal smart contract with callable functions. In order to share a state, Facets can only define 1 internal state variable: TheAppStorage
struct defined inAppStorage.sol
.
- Functions being added/replaced are implemented in smart contracts referred to as
- calling the
init
function of a smart contract- This is a one time action and will be called when the
diamondCut
is executed. There can be 1init
call perdiamondCut
.
- This is a one time action and will be called when the
For this tutorial, we are going to create a new facet called SampleFacet
. In your own implementation replace iterations of the word Sample
with the name of the Facet you want to create.
- make sure you are in the
protocol
repository - in
protocol/farm/facets/
, create a new folder calledSampleFacet
- within the
SampleFacet
folder create a file calledSampleFacet.sol
. - implement your faucet. You can use
SampleFacet.sol
inprotocol/samples
as a template for a basis faucet. Note that facets can only haveAppStorage
as an internal state variable or there will be issues with accessingAppStorage
. - modify the
deploy
function inscripts/deploy
to include your new facet, so that thefaucet
will be deployed with the Beanstalk diamond.
Code Version: 1.3.2
Whitepaper Version 1.3.0