Mangrove
Developper
Developper
  • Welcome
  • Protocol
    • Introduction
    • Technical References
      • Overview
      • Ticks, ratios, and prices
      • Offer-list
        • Views on offers
      • Market-order
        • Delegation
      • Creating & Updating offers
        • Maker contract
        • Offer provisions
        • Gas requirement
        • Public data structures
        • Executing offers
      • Cleaning offers
      • Governance-parameters
        • Global variables
        • Local variables
        • Data structures and views
      • Periphery Contracts
        • MgvReader
        • MgvOracle
      • Literate Source Code
    • Background
      • Taking available liquidity
      • Making liquidity available
      • Reneging on offers
  • Strat Lib
    • What is the Strat Library?
    • Getting-started
      • Set Up Your Local Environment
      • Post a Smart Offer
    • Guides
      • Unlocking liquidity
      • Reposting an offer in the posthook
      • Using last look to renege trades
      • Determining gas requirements
      • Creating a Direct contract
      • Deploying your contract
      • Testing a maker contract
      • Safe offer logic guidelines
      • Approvals
    • Technical references
      • Principal hooks
      • Liquidity routing
      • API preferences
        • Core
          • SRC
            • IMangrove
        • Strats
          • SRC
            • Strategies
              • MangroveOffer
              • MangroveOrder
              • Integrations
                • AaveV3Borrower
                • AaveV3BorrowerImplementation
                • AaveV3BorrowerStorage
                • AaveV3Lender
                • CompoundModule
              • Interfaces
                • IForwarder
                • ILiquidityProvider
                • IOfferLogic
                • IOrderLogic
              • Offer_forwarder
                • Abstract
                  • Forwarder
              • Offer_maker
                • Abstract
                  • Direct
                • Market_making
                  • Kandel
                    • AaveKandel
                    • AaveKandelSeeder
                    • KandelSeeder
                    • Abstract
                      • AbstractKandelSeeder
                      • CoreKandel
                      • DirectWithBidsAndAsksDistribution
                      • GeometricKandel
                      • HasIndexedBidsAndAsks
                      • KandelLib
                      • TradesBaseQuotePair
              • Routeurs
                • SimpleRouter
                • Abstract
                  • AbstractRouter
                • Integrations
                  • AavePooledRouter
                  • HasAaveBalanceMemoizer
              • Utils
                • AccessControlled
              • Vendor
                • AAVE
                  • V3
                    • Contracts
                      • Dependencies
                        • Oppenzeppelin
                          • Contracts
                            • IERC20
                      • Interfaces
                        • IAToken
                        • IAaveIncentivesController
                        • IAaveOracle
                        • ICreditDelegationToken
                        • IInitializableAToken
                        • IPool
                        • IPoolAddressesProvider
                        • IPriceOracleGetter
                        • IScaledBalanceToken
                      • Protocol
                        • Libraries
                          • Configurations
                            • ReserveConfiguration
                          • Helpers
                            • Errors
                          • Types
                            • DataTypes
                    • Periphery
                      • Contracts
                        • MISC
                          • Interfaces
                            • IEACAggregatorProxy
                        • Rewards
                          • Interfaces
                            • IRewardsController
                            • IRewardsDistributor
                            • ITransferStrategyBase
                          • Libraries
                            • RewardsDataTypes
                • Compound
                  • CarefulMath
                  • Exponential
                  • ExponentialNoError
                  • ICompound
    • Background
      • Building Blocks
        • MangroveOffer
        • Direct
        • Forwarder
  • Vaults
    • Understanding vaults
      • Oracles
    • Managing a vault (CLI)
      • Deploying an oracle
      • Creating a vault
      • Monitoring the vault
      • Setting the vault position
      • Setting the fee data
      • Rebalancing
      • Adding or removing liquidity
    • Custom interactions
      • Oracles
      • Vault Factory
      • Managing a vault
        • Setting the position
        • Rebalancing
        • Setting a manager
        • Setting fee
  • Keeper Bots
    • Keeper Bots
    • Guides
      • Using borrowed funds for cleaning
    • Backgroud
      • The role of cleaning bots in Mangrove
      • The role of gas price updater bots in Mangrove
  • Adresses
    • Deployment Addresses
  • Quick Links
    • Glossary
    • Website
    • Whitepaper
Powered by GitBook
On this page
  • Local development​
  • Create tutorial folder​
  • Install dependencies​
  • Environment​
  • Local chain​
  1. Strat Lib
  2. Getting-started

Set Up Your Local Environment

PreviousGetting-startedNextPost a Smart Offer

Last updated 1 month ago

Local development

If you want to do any local development we recommend installing and . We are going to be using Node.js for package management and running javascript in the tutorials, but it is not required. You can use any development environment that supports javascript and npm packages.

We are going to be using Foundry to start local forks for existing chains. You don't have to use Foundry to do this, you can use any tool you want to do this, but we recommend Foundry.

For Linux or macOS everything should work out of the box, if you are using Windows, then we recommend installing everything from within WSL2 and expect some quirks. Remember to reopen your shell after running the first line.

  1. v18+, we recommend installation through , with enabled:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# Reopen shell
nvm install --lts
# Enable the Yarn 2 package manager
corepack enable
  1. development framework for Ethereum:

curl -L https://foundry.paradigm.xyz | bash
# Reopen shell
foundryup

Create tutorial folder

The tutorials can be run in an isolated folder where you install Mangrove dependencies.

Open a terminal and run the following commands:

# Create a folder for the tutorial and enter it
mkdir tutorial
cd tutorial
npm init -y

Now install the following dependencies:

# To create Solidity smart contracts
# Install NPM package with Mangrove core and Strat library
npm install --save @mangrovedao/mangrove-strats@next
# Prepare Foundry's forge
forge init --force
# Set up remappings to use the strat library
cd node_modules/@mangrovedao/mangrove-strats

echo "@mgv/src/=node_modules/@mangrovedao/mangrove-core/src/
@mgv/src/=node_modules/@mangrovedao/mangrove-core/src/
@mgv/lib/=node_modules/@mangrovedao/mangrove-core/lib/
@mgv/test/=node_modules/@mangrovedao/mangrove-core/test/
@mgv/script/=node_modules/@mangrovedao/mangrove-core/script/
@mgv/forge-std/=node_modules/@mangrovedao/mangrove-core/lib/forge-std/src/
ds-test/=node_modules/@mangrovedao/mangrove-core/lib/forge-std/lib/ds-test/src

@mgv-strats/src/=node_modules/@mangrovedao/mangrove-strats/src/
@mgv-strats/lib/=node_modules/@mangrovedao/mangrove-strats/lib/
@mgv-strats/test/=node_modules/@mangrovedao/mangrove-strats/test/
@mgv-strats/script/=node_modules/@mangrovedao/mangrove-strats/script/
" > remappings.txt

Inside the tutorial folder, create a .env file. This will hold the secrets such as private key and API keys. Here we describe it in general, but the next section provides some working example values.

# .env
export PRIVATE_KEY=<private key>   # 0xabcd.... <- This is the private key you'll be using in the tutorial - a test key for the Polygon Mumbai network
export ADMIN_ADDRESS=<EOA> # 0xabcd...
export RPC_URL=<https://polygon-mumbai.g.alchemy.com/v2/API key> # alchemy or infura node url for Polygon Mumbai
export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chain that anvil starts (see next section)

To further speed things up we run tutorials on a local fork of a chain using Foundry's anvil tool.

How to fork an existing chain

source .env
anvil --fork-url $RPC_URL

When anvil starts up, it creates 10 test accounts, with some native tokens. If you do not have a real account on the chain, you can always use these accounts. Here is an example of a .env file that uses the first anvil account, a demo RPC URL and with a LOCAL URL.

Tip :

The demo RPC URLs are unstable, so if you cannot connect then create your own or use a different one.

export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 # The first anvil private key
export ADMIN_ADDRESS=0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 # The matching public key, to the first anvil private key
export RPC_URL=https://polygon-mumbai.blockpi.network/v1/rpc/public # Public RPC provided by Block Pi
export LOCAL_URL=http://127.0.0.1:8545 # Url for the local chan that anvil starts

Install dependencies

Environment

The file should typically look as follows (with <...> replaced by proper values) - for instance you need a RPC URL from, e.g., or , and an EOA with a private key. Note, there are other ways to provide secrets, but this is what we do in the tutorials.

If you do not have a RPC URL, there exists free RPC URLs, some examples can be found here: - note that they can be unstable and in that case we recommend creating your own through the listed providers.

Local chain

The tutorials can be run directly on networks where Mangrove is deployed (see ). However on a real network you will spend real tokens, so we recommend starting on test networks with a test account.

This starts a new chain on with a local url of http://127.0.0.1:8545. You can read more about the anvil command , if you are interested.

​
Node.js
Foundry
Node.js
nvm
Yarn 2
Foundry
​
​
​
Infura
Alchemy
ChainList
​
Addresses
here
PreviousWhat is the Strat Library?