Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes issue #28 #31

Merged
merged 11 commits into from
Aug 20, 2024
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ out/
.encryptedKey
broadcast/

lib/**

node_modules
package-lock.json

Expand Down
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.

106 changes: 51 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,48 @@ 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note several format changes without actual content changes.

- 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
```
You can add the `--no-commit` flag to each of these `install` commands if your workspace has uncommitted changes.
thodges-gh marked this conversation as resolved.
Show resolved Hide resolved

1. `forge install foundry-rs/forge-std << --no-commit >>` and `forge install transmissions11/solmate << --no-commit >>`

or
2. `forge install smartcontractkit/chainlink-brownie-contracts << --no-commit >>`

3. `forge install smartcontractkit/foundry-chainlink-toolkit << --no-commit >>`

You can update dependencies by running `forge update`

## Testing

```
forge test
```

# 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:

- [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 tarter kits: [Hardhat](https://github.com/smartcontractkit/functions-hardhat-starter-kit) | [Foundry (coming soon)](https://github.com/smartcontractkit/functions-foundry-starter-kit)
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 +91,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 +156,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
1 change: 0 additions & 1 deletion lib/solmate
thodges-gh marked this conversation as resolved.
Show resolved Hide resolved
Submodule solmate deleted from 97bdb2
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
Loading