Skip to content

Commit

Permalink
Merge pull request #31 from smartcontractkit/zp-issue#28
Browse files Browse the repository at this point in the history
Closes issue #28
  • Loading branch information
zeuslawyer authored Aug 20, 2024
2 parents 1deb4fb + a57a932 commit f929075
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/smartcontractkit/chainlink-brownie-contracts
[submodule "lib/solmate"]
path = lib/solmate
url = https://github.com/rari-capital/solmate
url = https://github.com/transmissions11/solmate
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
Expand Down
7 changes: 0 additions & 7 deletions .prettierignore

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

19 changes: 0 additions & 19 deletions .solhint.json

This file was deleted.

41 changes: 0 additions & 41 deletions Makefile

This file was deleted.

104 changes: 49 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*Note: This repo has been recently updated for Sepolia*
_Note: This repo has been recently updated for Sepolia_

# Foundry Starter Kit

Expand All @@ -14,7 +14,6 @@

Foundry Starter Kit is a repo that shows developers how to quickly build, test, and deploy smart contracts with one of the fastest frameworks out there, [foundry](https://github.com/gakonst/foundry)!


- [Foundry Starter Kit](#foundry-starter-kit)
- [Getting Started](#getting-started)
- [Requirements](#requirements)
Expand All @@ -37,45 +36,46 @@ Foundry Starter Kit is a repo that shows developers how to quickly build, test,

Please install the following:

- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- You'll know you've done it right if you can run `git --version`
- [Foundry / Foundryup](https://github.com/gakonst/foundry)
- This will install `forge`, `cast`, and `anvil`
- You can test you've installed them right by running `forge --version` and get an output like: `forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)`
- To get the latest of each, just run `foundryup`

And you probably already have `make` installed... but if not [try looking here.](https://askubuntu.com/questions/161104/how-do-i-install-make)
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- You'll know you've done it right if you can run `git --version`
- [Foundry / Foundryup](https://github.com/gakonst/foundry)
- This will install `forge`, `cast`, and `anvil`
- You can test you've installed them right by running `forge --version` and get an output like: `forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)`
- To get the latest of each, just run `foundryup`

## Quickstart

```sh
git clone https://github.com/smartcontractkit/foundry-starter-kit
cd foundry-starter-kit
make # This installs the project's dependencies.
make test
```

## Testing
## Install dependencies as follows:

```
make test
```
Run `forge install` to install dependencies. [Foundry uses git submodules](https://book.getfoundry.sh/projects/dependencies) as its dependency management system.

or
> ⚠️ when running forge install, you may see an error message if you have uncomitted changes in your repo. Read the message carefully - it may inform you that you can add the `--no-commit` flag to each of these `install` commands if your workspace has uncommitted changes.
You can update dependencies by running `forge update`

## Testing
To check that everything is compiling and working as intended after cloning and installing dependencies, run
```
forge test
```

All tests should pass.

# Chainlink Foundry Starter Kit
Implementation of the following 4 Chainlink services using the [Foundry] (https://book.getfoundry.sh/) smart contract development tooling:
- [Chainlink Price Feeds](https://docs.chain.link/docs/using-chainlink-reference-contracts)
- [Chainlink VRF V2](https://docs.chain.link/docs/chainlink-vrf)
- [Chainlink Automation](https://docs.chain.link/chainlink-automation/introduction)
- [Request & Receive data (AnyAPI)](https://docs.chain.link/any-api/introduction)

Implementation of the following 4 Chainlink services using the [Foundry] (https://book.getfoundry.sh/) smart contract development tooling:

For [Chainlink Functions](https://docs.chain.link/chainlink-functions) please go to these tarter kits: [Hardhat](https://github.com/smartcontractkit/functions-hardhat-starter-kit) | [Foundry (coming soon)](https://github.com/smartcontractkit/functions-foundry-starter-kit)
- [Chainlink Price Feeds](https://docs.chain.link/docs/using-chainlink-reference-contracts)
- [Chainlink VRF V2](https://docs.chain.link/docs/chainlink-vrf)
- [Chainlink Automation](https://docs.chain.link/chainlink-automation/introduction)
- [Request & Receive data (AnyAPI)](https://docs.chain.link/any-api/introduction)

For [Chainlink Functions](https://docs.chain.link/chainlink-functions) please go to these starter kits: [Hardhat](https://github.com/smartcontractkit/functions-hardhat-starter-kit) | [Foundry (coming soon)](https://github.com/smartcontractkit/functions-foundry-starter-kit)

For [Chainlink CCIP (Cross Chain Interoperability Prototocol)](https://docs.chain.link/ccip) please go to these starter kits: [Hardhat](https://github.com/smartcontractkit/ccip-starter-kit-hardhat) | [Foundry](https://github.com/smartcontractkit/ccip-starter-kit-foundry)

Expand All @@ -89,63 +89,58 @@ We'll demo using the Sepolia testnet. (Go here for [testnet sepolia ETH](https:/

You'll need to add the following variables to a `.env` file:

- `SEPOLIA_RPC_URL`: A URL to connect to the blockchain. You can get one for free from [Infura](https://www.infura.io/) account
- `PRIVATE_KEY`: A private key from your wallet. You can get a private key from a new [Metamask](https://metamask.io/) account
- Additionally, if you want to deploy to a testnet, you'll need test ETH and/or LINK. You can get them from [faucets.chain.link](https://faucets.chain.link/).
- Optional `ETHERSCAN_API_KEY`: If you want to verify on etherscan
- `SEPOLIA_RPC_URL`: A URL to connect to the blockchain. You can get one for free from [Infura](https://www.infura.io/) account
- `PRIVATE_KEY`: A private key from your wallet. You can get a private key from a new [Metamask](https://metamask.io/) account
- Additionally, if you want to deploy to a testnet, you'll need test ETH and/or LINK. You can get them from [faucets.chain.link](https://faucets.chain.link/).
- Optional `ETHERSCAN_API_KEY`: If you want to verify on etherscan

When you've added your environment variables to the `.env` file, run `source .env` in your terminal (and for each new terminal session) to load the environment variables into your terminal.

## Deploying

```
make deploy-sepolia contract=<CONTRACT_NAME>
```
Deploy scripts are in `./script`. The relevant Chainlink Service can be determined from the name of the Contract script. `HelperConfig` is not meant to be deployed.

For example:
To deploy one of the Chainlink Service consumer contracts run the script as follows:

```
make deploy-sepolia contract=PriceFeedConsumer
forge script script/${CONTRACT_NAME}.s.sol:Deploy${CONTRACT_NAME} --rpc-url $SEPOLIA_RPC_URL --private-key PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY -vvvv
make deploy-sepolia contract=<CONTRACT_NAME>
```

This will run the forge script, the script it's running is:
For example, to deploy the `PriceFeedConsumer` contract:

```
@forge script script/${contract}.s.sol:Deploy${contract} --rpc-url ${SEPOLIA_RPC_URL} --private-key ${PRIVATE_KEY} --broadcast --verify --etherscan-api-key ${ETHERSCAN_API_KEY} -vvvv
forge script script/PriceFeedConsumer.s.sol:DeployPriceFeedConsumer --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify --etherscan-api-key $ETHERSCAN_API_KEY -vvvv
```

If you don't have an `ETHERSCAN_API_KEY`, you can also just run:
If you don't have an `ETHERSCAN_API_KEY`, you can omit `--verify --etherscan-api-key $ETHERSCAN_API_KEY`

```
@forge script script/${contract}.s.sol:Deploy${contract} --rpc-url ${SEPOLIA_RPC_URL} --private-key ${PRIVATE_KEY} --broadcast
```

These pull from the files in the `script` folder.

### Working with a local network
### Working with Anvil local development network

Foundry comes with local network [anvil](https://book.getfoundry.sh/anvil/index.html) baked in, and allows us to deploy to our local network for quick testing locally.
Foundry comes with local network [anvil](https://book.getfoundry.sh/anvil/index.html) baked in, and allows us to deploy to our local network for quick testing locally.

To start a local network run:
To start a local network run the following in a new terminal window or tab:

```
make anvil
anvil
```

This will spin up a local blockchain with a determined private key, so you can use the same private key each time.
This will spin up a local blockchain on `http://localhost:8545` : (see console output for the mnemonic used, and 10 private keys and their associated wallet address), so you can use the same private key each time.

Then, you can deploy to it with:
Then, you can deploy to it with one of those private keys; in this example we use the first one:

```
make deploy-anvil contract=<CONTRACT_NAME>
forge script script/${contract}.s.sol:Deploy${contract} --rpc-url http://localhost:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 --broadcast
```

Similar to `deploy-sepolia`

### Working with other chains

To add a chain, you'd just need to make a new entry in the `Makefile`, and replace `<YOUR_CHAIN>` with whatever your chain's information is.
To add a chain, you'd just need to pass in the RPC URL for the relevant chain to the `--rpc-url` flag.

```
deploy-<YOUR_CHAIN> :; @forge script script/${contract}.s.sol:Deploy${contract} --rpc-url ${<YOUR_CHAIN>_RPC_URL} --private-key ${PRIVATE_KEY} --broadcast -vvvv
forge script script/${contract}.s.sol:Deploy${contract} --rpc-url ${<OTHER_CHAIN>_RPC_URL} --private-key ${PRIVATE_KEY} --broadcast -vvvv
```

Expand All @@ -159,20 +154,19 @@ Then, you can run:
make slither
```

And get your slither output.


And get your slither output.

# Contributing

Contributions are always welcome! Open a PR or an issue!
If you do contribute please add `solidity.formatter": "forge` to your VSCode Settings, or run `forge fmt` before you commit and push.

# Thank You!

## Resources

- [Chainlink Documentation](https://docs.chain.link/)
- [Foundry Documentation](https://book.getfoundry.sh/)
- [Chainlink Documentation](https://docs.chain.link/)
- [Foundry Documentation](https://book.getfoundry.sh/)

### TODO

Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion lib/foundry-chainlink-toolkit
30 changes: 0 additions & 30 deletions package.json

This file was deleted.

16 changes: 3 additions & 13 deletions script/APIConsumer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ pragma solidity ^0.8.7;
import "forge-std/Script.sol";
import "../src/APIConsumer.sol";
import "./HelperConfig.sol";
import "../src/test/mocks/MockOracle.sol";
import "../src/test/mocks/LinkToken.sol";
import "../test/mocks/MockOracle.sol";
import "../test//mocks/LinkToken.sol";

contract DeployAPIConsumer is Script, HelperConfig {
function run() external {
HelperConfig helperConfig = new HelperConfig();

(
address oracle,
bytes32 jobId,
uint256 chainlinkFee,
address link,
,
,
,
,

) = helperConfig.activeNetworkConfig();
(address oracle, bytes32 jobId, uint256 chainlinkFee, address link,,,,,) = helperConfig.activeNetworkConfig();

if (link == address(0)) {
link = address(new LinkToken());
Expand Down
12 changes: 2 additions & 10 deletions script/HelperConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ contract HelperConfig {
activeNetworkConfig = chainIdToNetworkConfig[block.chainid];
}

function getSepoliaEthConfig()
internal
pure
returns (NetworkConfig memory sepoliaNetworkConfig)
{
function getSepoliaEthConfig() internal pure returns (NetworkConfig memory sepoliaNetworkConfig) {
sepoliaNetworkConfig = NetworkConfig({
oracle: 0x6090149792dAAeE9D1D568c9f9a6F6B46AA29eFD,
jobId: "ca98366cc7314957b8c012c72f05aeeb",
Expand All @@ -43,11 +39,7 @@ contract HelperConfig {
});
}

function getAnvilEthConfig()
internal
pure
returns (NetworkConfig memory anvilNetworkConfig)
{
function getAnvilEthConfig() internal pure returns (NetworkConfig memory anvilNetworkConfig) {
anvilNetworkConfig = NetworkConfig({
oracle: address(0), // This is a mock
jobId: "6b88e0402e5d415eb946e528b8e0c7ba",
Expand Down
3 changes: 1 addition & 2 deletions script/KeepersCounter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ contract DeployKeepersCounter is Script, HelperConfig {
function run() external {
HelperConfig helperConfig = new HelperConfig();

(, , , , uint256 updateInterval, , , , ) = helperConfig
.activeNetworkConfig();
(,,,, uint256 updateInterval,,,,) = helperConfig.activeNetworkConfig();

vm.startBroadcast();

Expand Down
5 changes: 2 additions & 3 deletions script/PriceFeedConsumer.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.7;
import "forge-std/Script.sol";
import "../src/PriceFeedConsumer.sol";
import "./HelperConfig.sol";
import "../src/test/mocks/MockV3Aggregator.sol";
import "../test/mocks/MockV3Aggregator.sol";

contract DeployPriceFeedConsumer is Script, HelperConfig {
uint8 constant DECIMALS = 18;
Expand All @@ -13,8 +13,7 @@ contract DeployPriceFeedConsumer is Script, HelperConfig {
function run() external {
HelperConfig helperConfig = new HelperConfig();

(, , , , , address priceFeed, , , ) = helperConfig
.activeNetworkConfig();
(,,,,, address priceFeed,,,) = helperConfig.activeNetworkConfig();

if (priceFeed == address(0)) {
priceFeed = address(new MockV3Aggregator(DECIMALS, INITIAL_ANSWER));
Expand Down
Loading

0 comments on commit f929075

Please sign in to comment.