-
Notifications
You must be signed in to change notification settings - Fork 19
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
BCI-1224.rewrite example contracts #258
Merged
archseer
merged 129 commits into
develop
from
augustus.BCI-1224.rewrite-example-contracts
Aug 11, 2023
Merged
Changes from 117 commits
Commits
Show all changes
129 commits
Select commit
Hold shift + click to select a range
cadb3fe
contracts/.gitignore: remove typechain-types
cfal 8aeef00
Move cairo 0.x code to oldsrc/
archseer 0192af4
Initial boilerplate for Cairo 1.0
archseer e7854d8
create confirmed owner contract
augustbleeds ccdc342
Remove old helix config
archseer 6d71c58
Add ocr2 aggregator skeleton
archseer f46d5cf
ownable.cairo: update storage
cfal 00788ec
Scarb.toml: add starknet contract target
cfal 8966070
cairo_project.toml: add crate_roots to refer to crate deps
cfal 195f4a1
libraries: add access controller trait, simple write access controller
cfal d67872a
simple_write_access_controller.cairo: add constructor, rename to _che…
cfal 46c857a
simple_read_access_controller.cairo: add skeleton
cfal fc0652c
aggregator.cairo: Round derives Serde so that it can be returned by d…
cfal 6d1ec20
aggregator.cairo: change Round.round_id into felt252
cfal a2dc168
ocr2: add initial aggregator proxy
cfal 2b9fdb4
ocr2: partial set_config implementation, events
archseer ddc9aa6
Scarb.toml: cairo-test needs --starknet flag
cfal b228935
Add span hashing, implement most of set_config, part of transmit
archseer 3c5eab5
Billing config, query functions
archseer 44a45b5
Implement payee management, payments and resolve some TODOs
archseer 92acb2c
Clean up recursion in set_payee too
archseer 5cfb444
Add ERC20 calls via abi dispatcher
archseer af880b7
Use Ownable in the aggregator
archseer 3cd70bc
Re-export ownership functions
archseer f79444a
Slight cleanup
archseer 2f069f7
Implement withdraw_funds
archseer 41b1139
Use access controllers as libraries in aggregator and proxy
archseer 1ab6ff3
Add a vendor/ directory with cairo and scarb version pinned
archseer 18faf73
Remove unused files
archseer 63b6d73
ocr2/aggregator: clamp config digest hash, add prefix
cfal 51845ec
Add withdraw_gas_all annotations around recursion
archseer a42f93c
aggregator.cairo: pass signatures by reference with verify_signatures
cfal 25d0755
aggregator.cairo: implement duplicate signer checking
cfal 1d5be31
aggregator.cairo: deref median immediately
cfal b2dfa7f
Add the billing controller dispatch in billing access check
archseer 6155e69
Handle negative values in link_available_for_payment
archseer 999f5cd
Tightly pack Transmission for storage cost savings
archseer 54636b3
Optimize Oracle struct storage
archseer edd268f
Use the same split_felt function
archseer fa346fe
Resolve more TODOs
archseer f295791
aggregator.cairo: add TODOs to pow
cfal 433e467
contracts: add initial tests
cfal 26bd400
aggregator.cairo: set _oracles_len to index after adding oracles
cfal 339b7ca
aggregator.cairo: read oracle before incrementing index
cfal 4556fad
Aggregator: add transmitters view function
archseer 3fe7a4b
multisig.cairo: initial implementation
cfal 4980fec
aggregator.cairo: add withdraw_gas_all to transmitters_ for cairo-test
cfal 5610984
contracts: add initial test_multisig
cfal 02a6d94
BCI-990: Update er protocol to Cairo 1.0 (#228)
augustbleeds 7ac11c4
Fix compilation on alpha.6
archseer 82e6e0f
Makefile: build cairo, scarb, and contract tests
cfal 7a51631
contracts.yml: run cairo tests
cfal 3f948f5
amarna.yml: disable amarna workflow
cfal 298b283
contracts/requirements.txt: remove cairo-lang and openzeppelin-cairo-…
cfal 5de8e48
Makefile: build and run cairo-format
cfal 45ab667
lint.yml: checkout cairo for cairo-format
cfal 33d58f0
Makefile: assume the deps are already available in the env
archseer fcc13f7
Install cairo and scarb from github releases
archseer 35aaaf0
also download cairo for format check
cfal c091afd
Fix the format check
archseer 1454dbe
Resolve formatter issues
archseer 5b46a6f
Disable examples check for now since we haven't updated them yet
archseer 67e5e38
contracts/tests/test_multisig.cairo: add tests
cfal 4274a28
contracts/ocr2/aggregator_proxy.cairo: add external round_data and la…
cfal 4aab333
BCI-1188: Rewrite Link Token Cairo 1.0 (#234)
augustbleeds 0cea3b4
Makefile: build contracts with release profile
cfal 7a1e33a
contracts: import account contracts
cfal 3df2db9
Solidity contracts are still used, moved to solidity/
archseer 52e5822
Remove oldsrc/
archseer 1a46d9d
StarknetValidator.test.ts: yarn format
archseer 2210a5c
Only install venv on CI actions that need it (startNetwork)
archseer 3679ab2
Ignore the rest of the vendor/ folder
archseer 1b54348
contracts/emergency/sequencer_uptime_feed.cairo: spell transfer_owner…
cfal 60a4f84
port over mock aggregator (#250)
augustbleeds 67edba7
aggregator: Resolve a couple TODOs
archseer 4331956
Extract split_felt to utils
archseer 747c56b
proxy: We initialize with an initial value so it will never be 0
archseer 734edca
aggregator: Reintroduce calculate_reimbursement
archseer b5e0935
relayer: Stricter assertions on report format
archseer 4e7a3d7
contracts/ocr2/aggregator_proxy.cairo: require access for latest_roun…
cfal 5312d91
contracts/libraries/simple_read_access_controller.cairo: check_access…
cfal 04f215a
contracts/ocr2/mocks/mock_aggregator.cairo: set latest round id
cfal ad8d5bc
Update account to use latest implementation
archseer 7e4ff65
On rc0 it's no longer necessary to import this
archseer 8d501a7
Integer conversions can now be direct without going through felt252
archseer 5c83c9d
Use the new format for should_panic
archseer 0ea7f52
cairo format
archseer cff0b1d
Test ERC677 with contract dispatch (#241)
augustbleeds 69ab7ce
port aggregator proxy tests to cairo-test
f6e7ee2
update to cairo-rc1.0 and 0.2.0-alpha.2
augustbleeds c09124f
contracts/ocr2/aggregator.cairo: fix epoch_and_round assertion
cfal 810ef38
contracts/ocr2/aggregator.cairo: finalize hash with length
cfal b165eda
camelcase vars and undo delete file
584a5a9
fix file name
26f17ea
Merge pull request #253 from smartcontractkit/BCI-1260/aggregator-pro…
calvwang9 57750e1
BCI-1259: Add upgradeability (#251)
augustbleeds b81a7c0
contracts/ocr2/aggregator.cairo: add billing function
cfal 2df0ce3
contracts: run cairo-format
cfal 5d217d9
.github/actions/install-cairo/action.yml: add action
cfal cfd1e36
.github/workflows/contracts.yml: use install-cairo action
cfal 1c0affa
initial
augustbleeds 6017a31
contracts done for first example
augustbleeds e4b801c
temp
augustbleeds a722574
rename files
augustbleeds e0153ea
add proxy consumer
augustbleeds 636932f
move scripts
augustbleeds 4fb7242
wont work until goerli supports 0.11.1
augustbleeds 04560c3
refactor starknet contracts and redo readme
augustbleeds 449b0f6
update ts files
augustbleeds ada1350
bring up to date with cairo-1.0 branch
augustbleeds b630944
change gitignore
augustbleeds 06acf39
minor changes
augustbleeds 36c137f
rename to old folder
augustbleeds 417e42f
example
augustbleeds cb76dbd
import mock aggregator
augustbleeds a6eb068
fix bug
augustbleeds d59ed0d
format cairo
augustbleeds 14eae6e
minox pr fixes
augustbleeds 6ba8ede
remove unused mod
augustbleeds 54fa675
Merge branch 'cairo-1.0' into augustus.BCI-1224.rewrite-example-contr…
augustbleeds a5ea6c1
add cairo test for mock aggregator
augustbleeds cfc12c8
Merge branch 'develop' into augustus.BCI-1224.rewrite-example-contracts
augustbleeds d4ce9a7
Merge remote-tracking branch 'origin/develop' into augustus.BCI-1224.…
archseer c794ef2
cairo-format
archseer 5791724
Upgrade examples to cairo 2.1.0
archseer 90ee57e
Merge remote-tracking branch 'origin/develop' into augustus.BCI-1224.…
archseer 89fedbd
cairo-format
archseer b9150b2
fix mock test
archseer 5286fc0
yarn format
archseer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[crate_roots] | ||
chainlink = "src" | ||
chainlink = "src" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
target | ||
cache/ | ||
starknet-artifacts/ | ||
starknet-artifacts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
This example demonstrates how consumer contracts can read from the aggregator, with and without consideration of the uptime feed address. Recall that the purpose of the uptime feed is to let consumer contracts know if the L2 layer is up and healthy. | ||
|
||
We demonstrate these examples by mocking an aggregator to return stubbed values. | ||
|
||
You can run this example on your local devnet or on goerli (up to you). NOTE: at the time of writing, the examples only work against devnet due to Starknet version incompatability. | ||
|
||
Note: `.env` will contain account details, such as DEPLOYER_ACCOUNT_ADDRESS and DEPLOYER_PRIVATE_KEY | ||
|
||
## Deploy on Devnet | ||
|
||
### 1. Install Local Dev Environment | ||
|
||
Follow [steps 1 and 2 here](../proxy_consumer/README.md) | ||
|
||
At this point, you should have starknet-devnet, cairo, and scarb installed. Your virtualenv will also have the starknet cli tool but we won't be using that to test against devnet | ||
|
||
All instructions begin at the root of this folder | ||
### 2. Compile cairo 1 contracts | ||
|
||
``` | ||
yarn compile:cairo | ||
``` | ||
|
||
|
||
### 3. Setup Starknet Devnet | ||
|
||
In a seperate terminal, run: | ||
``` | ||
starknet-devnet --cairo-compiler-manifest ../../vendor/cairo/Cargo.toml --seed 0 --lite-mode ../../../vendor/cairo/Cargo.toml | ||
``` | ||
This will start up the devnet and enable you to deploy and run cairo 1 contracts against it | ||
|
||
### 4. Deploy Devnet Account | ||
|
||
This command will deploy a devnet account onto devnet and write the DEPLOYER_ACCOUNT_ADDRESS and DEPLOYER_PRIVATE_KEY into a .env file in the current directory (it will create .env if it doesn't exist). This account will be utilized for deploying and interacting with the rest of the contracts in this section. | ||
|
||
``` | ||
yarn deployAccount | ||
``` | ||
|
||
## 5. Deploy Contracts | ||
|
||
This will deploy the following contracts: | ||
* SequencerUptimeFeed: Displays the status of the L2 layer. If it is up, then it is safe to read from the aggregator contract. For more information please see this [document](../../../docs/emergency-protocol/README.md). | ||
* MockAggregator: A mocked version of the aggregator with limited functionality. It gives the reader the ability to set and view the latest round data in order so the reader can familiarize themselves for testing purposes. | ||
* AggregatorConsumer: Simply reads the mocked aggregator's latest values | ||
* AggregatorPriceConsumerWithSequencer: Reads the mocked aggregator's values but also queries the SequencerUptimeFeed to determine if the value should be used or not. If the SequencerUptimeFeed is too stale, then that means the L2 layer is down. We've arbitrarily chosen the threshold of 60 seconds. | ||
|
||
|
||
``` | ||
yarn deployContracts | ||
``` | ||
|
||
## 6. Interact with Contracts | ||
|
||
``` | ||
# deployer calls AggregatorConsumer to read the decimals method of the MockAggregator | ||
yarn readDecimals | ||
|
||
# deployer calls AggregatorConsumer to read the latest round of the MockAggregator | ||
yarn readLatestRound | ||
|
||
# deployer calls Aggregator Consumer to poll decimals AND latest round of MockAggregator | ||
yarn readContinuously | ||
|
||
# deployer calls MockAggregator to manually set the new round's data | ||
yarn updateLatestRound | ||
|
||
# deployer calls AggregatorPriceConsumerWithSequencer to read latest round or revert if uptime feed is stale | ||
yarn getLatestPriceSeqCheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "chainlink_examples" | ||
version = "0.1.0" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest | ||
|
||
[dependencies] | ||
chainlink = { path = "../../../contracts" } | ||
|
||
[[target.starknet-contract]] | ||
# note these two options only work on scarb 0.2.0 and forward | ||
casm = true | ||
# Emit Python-powered hints in order to run compiled CASM class with legacy Cairo VM. | ||
casm-add-pythonic-hints = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[crate_roots] | ||
chainlink_examples = "src" |
32 changes: 0 additions & 32 deletions
32
examples/contracts/aggregator-consumer/contracts/Aggregator_consumer.cairo
This file was deleted.
Oops, something went wrong.
8 changes: 0 additions & 8 deletions
8
examples/contracts/aggregator-consumer/contracts/MockAggregator.cairo
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
examples/contracts/aggregator-consumer/contracts/Price_Consumer_With_Sequencer_Check.cairo
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This is a an example .env file that contains pre-deployed and pre-funded account that come with starknet-devnet | ||
# To see a complete list of pre-deployed starknet-devnet accounts just run `starknet-devnet` | ||
|
||
# hypothetical devnet account | ||
DEPLOYER_ACCOUNT_ADDRESS=<DEVNET_ACCOUNT_ADDRESS> | ||
DEPLOYER_PRIVATE_KEY=<DEVNET_ACCOUNT_PRIVATE_KEY> | ||
|
||
# Below is what you'd set to run these examples on GOERLI | ||
# DEPLOYER_ACCOUNT_ADDRESS=<GOERLI_ACCOUNT_ADDRESS> | ||
# DEPLOYER_PRIVATE_KEY=<GOERLI_ACCOUNT_PRIVATE_KEY> | ||
# NETWORK=GOERLI |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
{ | ||
"name": "@chainlink/starknet-ocr2-consumer", | ||
"version": "0.1.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"compile:cairo": "hardhat starknet-compile", | ||
"compile": "yarn compile:cairo", | ||
"test": "npx hardhat --network localhost test", | ||
"readDecimals": "npx ts-node ./scripts/readDecimals.ts", | ||
"readLatestRound": "npx ts-node ./scripts/readLatestRound.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@nomiclabs/hardhat-ethers": "^2.1.0", | ||
"@shardlabs/starknet-hardhat-plugin": "^0.8.0-alpha.0", | ||
"@types/chai": "^4.3.3", | ||
"@types/mocha": "^9.1.1", | ||
"chai": "^4.3.6", | ||
"hardhat": "^*" | ||
}, | ||
"dependencies": { | ||
"@chainlink/starknet": "^1.0.0", | ||
"dotenv": "^16.0.1" | ||
} | ||
"name": "@chainlink/latest-starknet-ocr2-consumer", | ||
"version": "0.1.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"compile:cairo": "scarb --profile release build", | ||
"compile": "yarn compile:cairo", | ||
"test": "yarn hardhat --network localhost test", | ||
"deployAccount": "yarn ts-node ./scripts/deploy_accounts.ts", | ||
"deployContracts": "yarn ts-node ./scripts/deploy_contracts.ts", | ||
"readDecimals": "yarn ts-node ./scripts/readDecimals.ts", | ||
"readLatestRound": "yarn ts-node ./scripts/readLatestRound.ts", | ||
"readContinuously": "yarn ts-node ./scripts/readContinuously.ts", | ||
"updateLatestRound": "yarn ts-node ./scripts/updateLatestRound.ts", | ||
"getLatestPriceSeqCheck": "yarn ts-node ./scripts/getLatestPriceSeqCheck.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@nomiclabs/hardhat-ethers": "^2.1.0", | ||
"@shardlabs/starknet-hardhat-plugin": "^0.8.0-alpha.0", | ||
"@types/chai": "^4.3.3", | ||
"@types/mocha": "^9.1.1", | ||
"chai": "^4.3.6", | ||
"hardhat": "^*" | ||
}, | ||
"dependencies": { | ||
"@chainlink/starknet": "^1.0.0", | ||
"dotenv": "^16.0.1" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cfal pointed this out on slack, the bug was already fixed on L45