-
Install foundry
-
Install make: Check if make is installed.
make --versionIf not, install with homebrew:
brew install make- Install libs:
make install- Compile the project:
make buildAdd private key using Foundry wallet import & setup password:
cast wallet import defaultKey --interactivecast wallet listAdd the private defaultKey address and the name of choice for that wallet to .env, defaultKey was used in the example above:
SENDER_ADDRESS=0xAbC123
ACCOUNT_NAME=defaultKeyThe password will be used for sending transactions through forge.
For more about private key security view ERC-2335
Example .env file to interact with Ethereum mainnet/testnet and Polygon mainnet:
SENDER_ADDRESS=<your_address>
ACCOUNT_NAME=<account_name_for_SENDER_ADDRESS>
RPC_URL_ETHEREUM=<your_rpc_url_ethereum>
RPC_URL_ETHEREUM_SEPOLIA=<your_rpc_url_ethereum_sepolia>
RPC_URL_POLYGON=<your_rpc_url_polygon>
ETHERSCAN_API_KEY=<your_etherscan_api_key>
POLYGONSCAN_API_KEY=<your_polygonscan_api_key>Variables to configure:
SENDER_ADDRESS: The address for the private key for your testnet wallet imported to keystore using Foundry. If you use MetaMask, you can follow this guide to export your private key. Note: This key is required for signing transactions like token transfers.ACCOUNT_NAME: The name of the wallet associated withSENDER_ADDRESS. To view configured wallet names:
cast wallet list-
RPC_URL_ETHEREUM: The RPC URL for the Ethereum mainnet. You can get this from the Alchemy or Infura website. -
RPC_URL_ETHEREUM_SEPOLIA: The RPC URL for the Ethereum Sepolia. You can get this from the Alchemy or Infura website. -
RPC_URL_POLYGON: The RPC URL for the Polygon mainnet. You can get this from the Alchemy or Infura website. -
ETHERSCAN_API_KEY: An API key from Etherscan to verify your contracts. You can obtain one from Etherscan. -
POLYGONSCAN_API_KEY: An API key from Polygon to verify your contracts on Polygon. See this guide to get one from Arbiscan.
Load the environment variables into the terminal session where you will run the commands:
source .envThe config.json file within the script directory defines the key parameters used by all scripts. You can customize the token name, symbol, maximum supply, and cross-chain settings, among other fields.
Example config.json file:
{
"owner": "0xAbC321",
"staking": {
"stakeToken": "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
"rewardToken": "0x6982508145454Ce325dDbE47a25d4ec3d2311933",
"rewardRate": 1e18,
"maxRewardRate": 5e18,
"minRewardRate": 0,
"rateChangeDelay": 604800,
"withdrawDelay": 604800,
"minStakeAmount": 1e18
}
}The config.json file contains the following parameters:
| Field | Description |
|---|---|
stakeToken |
The address of the deployed stake token |
rewardToken |
The address of the deployed reward token, same as stake token |
rewardRate |
How many tokens are issued as rewards per second. |
owner |
The address to own the contract. |
maxRewardRate |
Maximum tokens issued as rewards per second |
minRewardRate |
Minimum tokens issued as rewards per second (set to 0 to allow pausing) |
rateChangeDelay |
Delay in seconds between proposing a new reward rate and executing it |
withdrawDelay |
The minimum wait time between a user's withdrawal request and when they can complete it |
minStakeAmount |
Minimum amount of tokens to stake |
All local tests:
make testTo run specific test view available commands in Makefile
Get some testnet tokens, go to Alchemy's faucet or your favorite faucet for the desired testnet network.
make deploy-staking ARGS="ethereumSepolia"make deploy-staking ARGS="ethereum"make deploy-staking ARGS="polygon"