Skip to content

Commit

Permalink
finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAlphaC committed Dec 14, 2020
1 parent da6b07a commit 806d576
Show file tree
Hide file tree
Showing 25 changed files with 1,155 additions and 591 deletions.
117 changes: 83 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,126 @@
# token-mix
# chainlink-mix

A bare-bones implementation of the Ethereum [ERC-20 standard](https://eips.ethereum.org/EIPS/eip-20), written in [Solidity](https://github.com/ethereum/solidity).
This is a repo to work with and use Chainlink smart contracts in a python environment. If you're brand new to Chainlink, check out the beginer walkthroughs in remix to [learn the basics.](https://docs.chain.link/docs/beginners-tutorial)

For [Vyper](https://github.com/vyperlang/vyper), check out [`vyper-token-mix`](https://github.com/brownie-mix/vyper-token-mix).
You can also check out the more advanced Chainlink tutorials there as well.

## Installation

1. [Install Brownie](https://eth-brownie.readthedocs.io/en/stable/install.html), if you haven't already.
1. [Install Brownie](https://eth-brownie.readthedocs.io/en/stable/install.html), if you haven't already. Here is a simple way to install brownie.

2. Download the mix.
```bash
pip install eth-brownie
```

```bash
brownie bake token
```
2. Download the mix. #TODO

## Basic Use
Until the mix is uploaded, you can just do the following:

This mix provides a [simple template](contracts/Token.sol) upon which you can build your own token, as well as unit tests providing 100% coverage for core ERC20 functionality.
```bash
git clone https://github.com/PatrickAlphaC/chainlink-mix
cd chainlink-mix
```

To interact with a deployed contract in a local environment, start by opening the console:
Once it becomes a mix, it will look like:

```bash
brownie console
brownie bake chainlink-mix
cd chainlink-mix
```

Next, deploy a test token:
3. Set your `WEB3_INFURA_PROJECT_ID`. You can get this by getting a free trial of [Infura](https://infura.io/). At the moment, it does need to be infura.

## Chainlink Price Feeds

This mix provides a simple template for working with Chainlink Smart Contracts. The easiest way to start is to fork the mainnet chain to a local ganache chain. This will allow you to deploy local smart contracts to interact with the [Chainlink Price Feeds](https://docs.chain.link/docs/get-the-latest-price).

```python
>>> token = Token.deploy("Test Token", "TST", 18, 1e21, {'from': accounts[0]})
### Running Scripts

Transaction sent: 0x4a61edfaaa8ba55573603abd35403cf41291eca443c983f85de06e0b119da377
Gas price: 0.0 gwei Gas limit: 12000000
Token.constructor confirmed - Block: 1 Gas used: 521513 (4.35%)
Token deployed at: 0xd495633B90a237de510B4375c442C0469D3C161C
This will deploy a smart contract to kovan and then read you the latest price via [Chainlink Price Feeds](https://docs.chain.link/docs/get-the-latest-price).
```
brownie run scripts/price_feed_scripts/deploy_price_consumer_v3.py --network kovan
brownie run scripts/price_feed_scripts/read_price_feed.py --network kovan
```

Otherwise, you can fork mainnet and use that in a local ganache development environment.
```bash
brownie console --network mainnet-fork
>>> price_feeds = PriceFeed.deploy('0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419', {'from': accounts[0]})
.
.
>>> latest_price = price_feeds.getLatestPrice()
>>> latest_price
59169208540
```

You now have a token contract deployed, with a balance of `1e21` assigned to `accounts[0]`:
## Chainlink VRF

```python
>>> token
<Token Contract '0xd495633B90a237de510B4375c442C0469D3C161C'>
This will deploy a smart contract to kovan and get a Random number via [Chainlink VRF](https://docs.chain.link/docs/get-a-random-number).
```
brownie run scripts/price_feed_scripts/deploy_vrf.py --network kovan
brownie run scripts/price_feed_scripts/fund_vrf.py --network kovan
brownie run scripts/price_feed_scripts/request_randomness.py --network kovan
brownie run scripts/price_feed_scripts/read_random_number.py --network kovan
```

>>> token.balanceOf(accounts[0])
1000000000000000000000
## Chainlink API Call

>>> token.transfer(accounts[1], 1e18, {'from': accounts[0]})
Transaction sent: 0xb94b219148501a269020158320d543946a4e7b9fac294b17164252a13dce9534
Gas price: 0.0 gwei Gas limit: 12000000
Token.transfer confirmed - Block: 2 Gas used: 51668 (0.43%)

<Transaction '0xb94b219148501a269020158320d543946a4e7b9fac294b17164252a13dce9534'>
This will deploy a smart contract to kovan and then make an API call via [Chainlink API Call](https://docs.chain.link/docs/make-a-http-get-request).
```
brownie run scripts/price_feed_scripts/deploy_api_consumer.py --network kovan
brownie run scripts/price_feed_scripts/fund_chainlink_api.py --network kovan
brownie run scripts/price_feed_scripts/request_api.py --network kovan
brownie run scripts/price_feed_scripts/read_api.py --network kovan
```

## Testing

To run the tests:
To run basic tests from `mainnet-fork` network

```bash
```
brownie test
```

The unit tests included in this mix are very generic and should work with any ERC20 compliant smart contract. To use them in your own project, all you must do is modify the deployment logic in the [`tests/conftest.py::token`](tests/conftest.py) fixture.
There are 3 types of tests you can run:

1. Development tests
1. These test using a local ganache chain. They are unit tests and do not interact with Chainlink nodes.
2. Right now this is blank
2. Mainnet-fork tests
1. These run on a mainnet forked local ganache chain. They are used to interact with pricefeed contracts deployed to mainnet.
3. Testnet/Staging tests
1. These are the pre-production tests. They are used to test a specific testnet.
2. Right now we have them hard coded to kovan.


### To test development (Currently blank)
```bash
brownie test --network development
```
### To test mainnet-fork
This will test Chainlink API Calls and Chainlink VRF
```bash
brownie test --network mainnet-fork
```
### To test staging/testnet
This will test Chainlink Price Feeds
```bash
brownie test --network kovan
```

## Resources

To get started with Brownie:

* [Chainlink Documentation](https://docs.chain.link/docs)
* Check out the [Chainlink documentation](https://docs.chain.link/docs) to get started from any level of smart contract engineering.
* Check out the other [Brownie mixes](https://github.com/brownie-mix/) that can be used as a starting point for your own contracts. They also provide example code to help you get started.
* ["Getting Started with Brownie"](https://medium.com/@iamdefinitelyahuman/getting-started-with-brownie-part-1-9b2181f4cb99) is a good tutorial to help you familiarize yourself with Brownie.
* For more in-depth information, read the [Brownie documentation](https://eth-brownie.readthedocs.io/en/stable/).


Any questions? Join our [Gitter](https://gitter.im/eth-brownie/community) channel to chat and share with others in the community.
Any questions? Join our [Discord](https://discord.gg/2YHSAey)

## License

Expand Down
27 changes: 22 additions & 5 deletions brownie-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,31 @@
reports:
exclude_contracts:
- SafeMath
dependencies:
- alphachainio/[email protected]
compiler:
solc:
remappings:
- '@chainlink-contracts=alphachainio/[email protected]'
- '@chainlink=alphachainio/[email protected]'
# automatically fetch contract sources from Etherscan
autofetch_sources: True
# set a custom mnemonic for the development network
networks:
default: kovan
default: mainnet-fork
kovan:
cmd_settings:
mnemonic: ${MNEMONIC}
host: ${KOVAN_RPC_URL}
vrf_coordinator: '0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9'
link_token: '0xa36085F69e2889c224210F603D836748e7dC0088'
keyhash: '0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4'
fee: 100000000000000000
oracle: '0x2f90A6D021db21e1B2A077c5a37B3C7E75D15b7e'
jobId: '29fa9aa13bf1468788b7cc4a500a45b8'
rinkeby:
vrf_coordinator: '0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B'
link_token: '0x01be23585060835e02b77ef475b0cc51aa1e0709'
keyhash: '0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311'
fee: 100000000000000000
oracle: '0x7AFe1118Ea78C1eae84ca8feE5C65Bc76CcF879e'
jobId: '6d1bfe27e7034b1d87b5270556b17277'
wallets:
from_key: PRIVATE_KEY
# could also do from_mnemonic, and you'd have to change the accounts.add to accounts.from_mnemonic
Loading

0 comments on commit 806d576

Please sign in to comment.