Make sure you clone submodules together.
git clone --recurse-submodules
If you already pulled using just git clone
, you can use below command to update submodules.
git submodule update --init --recursive
From fresh clone:
yarn
yarn workspace @midas-capital/sdk forge install
yarn workspace @midas-capital/sdk build
Run everything from the top level.
Ask for .env file from the team and add it under packages/sdk
If you want to add packages to modules, you can do so like:
yarn workspace @midas-capital/sdk add ethers
To run forge
commands inside the sdk
package, run:
yarn workspace @midas-capital/sdk forge install <SOME_DEP>
yarn workspace @midas-capital/sdk forge build
- etc
- Copy source into
packages/my-new-package
. - Add reference to root
tsconfig.json
:
{
...
"references": [
...
{
"path": "./packages/my-new-package"
}
]
}
- Add workspace-level dependencies to
package.json
inside the package:
{
...
"dependencies": {
...
"@midas-capital/some-other-package": "workspace:*"
}
}
- `yarn` from top-level to update dependencies/symlinks.
Forking requires access to a archive RPC node. For BSC we had a great experience using an RPC Node from NodeReals MegaNode service - https://nodereal.io/meganode .
For forking Polygon we haven't found a free service to use an archive node yet.
You general purpose forking you have to set FORK_RPC_URL
and FORK_CHAIN_ID
in your packages/sdk/.env
file.
And than start a forked local node by running.
> yarn dev:node:fork
In order to start multiple forks at once we streamlined the process a bit. In your executing shell make sure to set BSC_RPC_URL
and or POLYGON_RPC_URL
.
> yarn dev:node:bsc
// Will start a CHAIN_ID=56 fork using $BSC_RPC_URL at https://localhost:8545
> yarn dev:node:polygon
// Will start a CHAIN_ID=137 fork using $POLYGON_RPC_URL at https://localhost:8546
The idea is to increase the port number with each fork we want to support.
8545: BSC
8546: Polygon
8547: Moonbeam?
For convenience we have a Hardhat task to make some token swaps to on the forked node for you.
> yarn workspace @midas-capital/sdk hardhat fork:fund-accounts --network fork
// Works with https://localhost:8545
> yarn workspace @midas-capital/sdk hardhat fork:fund-accounts --network localbsc
// Works with https://localhost:8545
> yarn workspace @midas-capital/sdk hardhat fork:fund-accounts --network localpolygon
// Works with https://localhost:8546
We are using ChainSafe/dappeteer to test our UI with Metamask. The test are expecting to work on a fork of BSC mainnet for now.
Follow this step to run the UI test locally
- Start local forked BSC node
> yarn dev:node:fork
- Start local UI dev server
> yarn dev:ui
- Fund test accounts
> yarn workspace @midas-capital/sdk hardhat fork:fund-accounts --network fork
- Run dAppateer
> yarn test:ui
If you are on windows you need an X-server to run dappeteer. These instructions were taken from here: https://www.rickmakes.com/windows-subsystem-for-linux-2-installing-vcxrv-x-server/
Follow these steps before running yarn test:ui
- Download VcXsrv, this is your X-server that will display the GUI https://sourceforge.net/projects/vcxsrv/
- Run VcXsrv. Use these settings
Multiple Windows -> Start No Client -> Check All Boxes in Extra Settings -> Finish
If Windows Defender Firewall prompts you, check both Private & Public Networks and Allow Access
- Find your Windows IP Address by running the following command
cat /etc/resolv.conf
- Set DISPLAY Variable (replace ip_address with your IP Address found above)
export DISPLAY=ip_address:0.0
- export opengl Variable
export LIBGL_ALWAYS_INDIRECT=1