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

BCI-1224.rewrite example contracts #258

Merged
merged 129 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
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 Apr 12, 2023
8aeef00
Move cairo 0.x code to oldsrc/
archseer Mar 30, 2023
0192af4
Initial boilerplate for Cairo 1.0
archseer Mar 30, 2023
e7854d8
create confirmed owner contract
augustbleeds Mar 30, 2023
ccdc342
Remove old helix config
archseer Apr 3, 2023
6d71c58
Add ocr2 aggregator skeleton
archseer Apr 4, 2023
f46d5cf
ownable.cairo: update storage
cfal Apr 4, 2023
00788ec
Scarb.toml: add starknet contract target
cfal Apr 4, 2023
8966070
cairo_project.toml: add crate_roots to refer to crate deps
cfal Apr 4, 2023
195f4a1
libraries: add access controller trait, simple write access controller
cfal Apr 4, 2023
d67872a
simple_write_access_controller.cairo: add constructor, rename to _che…
cfal Apr 4, 2023
46c857a
simple_read_access_controller.cairo: add skeleton
cfal Apr 4, 2023
fc0652c
aggregator.cairo: Round derives Serde so that it can be returned by d…
cfal Apr 5, 2023
6d1ec20
aggregator.cairo: change Round.round_id into felt252
cfal Apr 5, 2023
a2dc168
ocr2: add initial aggregator proxy
cfal Apr 5, 2023
2b9fdb4
ocr2: partial set_config implementation, events
archseer Apr 6, 2023
ddc9aa6
Scarb.toml: cairo-test needs --starknet flag
cfal Apr 7, 2023
b228935
Add span hashing, implement most of set_config, part of transmit
archseer Apr 7, 2023
3c5eab5
Billing config, query functions
archseer Apr 7, 2023
44a45b5
Implement payee management, payments and resolve some TODOs
archseer Apr 10, 2023
92acb2c
Clean up recursion in set_payee too
archseer Apr 10, 2023
5cfb444
Add ERC20 calls via abi dispatcher
archseer Apr 10, 2023
af880b7
Use Ownable in the aggregator
archseer Apr 10, 2023
3cd70bc
Re-export ownership functions
archseer Apr 10, 2023
f79444a
Slight cleanup
archseer Apr 10, 2023
2f069f7
Implement withdraw_funds
archseer Apr 10, 2023
41b1139
Use access controllers as libraries in aggregator and proxy
archseer Apr 11, 2023
1ab6ff3
Add a vendor/ directory with cairo and scarb version pinned
archseer Apr 11, 2023
18faf73
Remove unused files
archseer Apr 11, 2023
63b6d73
ocr2/aggregator: clamp config digest hash, add prefix
cfal Apr 11, 2023
51845ec
Add withdraw_gas_all annotations around recursion
archseer Apr 12, 2023
a42f93c
aggregator.cairo: pass signatures by reference with verify_signatures
cfal Apr 12, 2023
25d0755
aggregator.cairo: implement duplicate signer checking
cfal Apr 12, 2023
1d5be31
aggregator.cairo: deref median immediately
cfal Apr 13, 2023
b2dfa7f
Add the billing controller dispatch in billing access check
archseer Apr 14, 2023
6155e69
Handle negative values in link_available_for_payment
archseer Apr 14, 2023
999f5cd
Tightly pack Transmission for storage cost savings
archseer Apr 14, 2023
54636b3
Optimize Oracle struct storage
archseer Apr 14, 2023
edd268f
Use the same split_felt function
archseer Apr 14, 2023
fa346fe
Resolve more TODOs
archseer Apr 14, 2023
f295791
aggregator.cairo: add TODOs to pow
cfal Apr 14, 2023
433e467
contracts: add initial tests
cfal Apr 14, 2023
26bd400
aggregator.cairo: set _oracles_len to index after adding oracles
cfal Apr 17, 2023
339b7ca
aggregator.cairo: read oracle before incrementing index
cfal Apr 17, 2023
4556fad
Aggregator: add transmitters view function
archseer Apr 14, 2023
3fe7a4b
multisig.cairo: initial implementation
cfal Apr 17, 2023
4980fec
aggregator.cairo: add withdraw_gas_all to transmitters_ for cairo-test
cfal Apr 18, 2023
5610984
contracts: add initial test_multisig
cfal Apr 18, 2023
02a6d94
BCI-990: Update er protocol to Cairo 1.0 (#228)
augustbleeds Apr 18, 2023
7ac11c4
Fix compilation on alpha.6
archseer Apr 24, 2023
82e6e0f
Makefile: build cairo, scarb, and contract tests
cfal Apr 13, 2023
7a51631
contracts.yml: run cairo tests
cfal Apr 13, 2023
3f948f5
amarna.yml: disable amarna workflow
cfal Apr 24, 2023
298b283
contracts/requirements.txt: remove cairo-lang and openzeppelin-cairo-…
cfal Apr 24, 2023
5de8e48
Makefile: build and run cairo-format
cfal Apr 24, 2023
45ab667
lint.yml: checkout cairo for cairo-format
cfal Apr 24, 2023
33d58f0
Makefile: assume the deps are already available in the env
archseer Apr 25, 2023
fcc13f7
Install cairo and scarb from github releases
archseer Apr 25, 2023
35aaaf0
also download cairo for format check
cfal Apr 25, 2023
c091afd
Fix the format check
archseer Apr 26, 2023
1454dbe
Resolve formatter issues
archseer Apr 26, 2023
5b46a6f
Disable examples check for now since we haven't updated them yet
archseer Apr 26, 2023
67e5e38
contracts/tests/test_multisig.cairo: add tests
cfal Apr 27, 2023
4274a28
contracts/ocr2/aggregator_proxy.cairo: add external round_data and la…
cfal Apr 27, 2023
4aab333
BCI-1188: Rewrite Link Token Cairo 1.0 (#234)
augustbleeds Apr 27, 2023
0cea3b4
Makefile: build contracts with release profile
cfal Apr 27, 2023
7a1e33a
contracts: import account contracts
cfal Apr 29, 2023
3df2db9
Solidity contracts are still used, moved to solidity/
archseer May 2, 2023
52e5822
Remove oldsrc/
archseer May 2, 2023
1a46d9d
StarknetValidator.test.ts: yarn format
archseer May 2, 2023
2210a5c
Only install venv on CI actions that need it (startNetwork)
archseer May 2, 2023
3679ab2
Ignore the rest of the vendor/ folder
archseer May 2, 2023
1b54348
contracts/emergency/sequencer_uptime_feed.cairo: spell transfer_owner…
cfal May 2, 2023
60a4f84
port over mock aggregator (#250)
augustbleeds May 4, 2023
67edba7
aggregator: Resolve a couple TODOs
archseer May 4, 2023
4331956
Extract split_felt to utils
archseer May 4, 2023
747c56b
proxy: We initialize with an initial value so it will never be 0
archseer May 4, 2023
734edca
aggregator: Reintroduce calculate_reimbursement
archseer May 4, 2023
b5e0935
relayer: Stricter assertions on report format
archseer May 4, 2023
4e7a3d7
contracts/ocr2/aggregator_proxy.cairo: require access for latest_roun…
cfal May 4, 2023
5312d91
contracts/libraries/simple_read_access_controller.cairo: check_access…
cfal May 4, 2023
04f215a
contracts/ocr2/mocks/mock_aggregator.cairo: set latest round id
cfal May 4, 2023
ad8d5bc
Update account to use latest implementation
archseer May 5, 2023
7e4ff65
On rc0 it's no longer necessary to import this
archseer May 5, 2023
8d501a7
Integer conversions can now be direct without going through felt252
archseer May 5, 2023
5c83c9d
Use the new format for should_panic
archseer May 5, 2023
0ea7f52
cairo format
archseer May 5, 2023
cff0b1d
Test ERC677 with contract dispatch (#241)
augustbleeds May 5, 2023
69ab7ce
port aggregator proxy tests to cairo-test
May 5, 2023
f6e7ee2
update to cairo-rc1.0 and 0.2.0-alpha.2
augustbleeds May 5, 2023
c09124f
contracts/ocr2/aggregator.cairo: fix epoch_and_round assertion
cfal May 5, 2023
810ef38
contracts/ocr2/aggregator.cairo: finalize hash with length
cfal May 6, 2023
b165eda
camelcase vars and undo delete file
May 8, 2023
584a5a9
fix file name
May 8, 2023
26f17ea
Merge pull request #253 from smartcontractkit/BCI-1260/aggregator-pro…
calvwang9 May 8, 2023
57750e1
BCI-1259: Add upgradeability (#251)
augustbleeds May 8, 2023
b81a7c0
contracts/ocr2/aggregator.cairo: add billing function
cfal May 9, 2023
2df0ce3
contracts: run cairo-format
cfal May 9, 2023
5d217d9
.github/actions/install-cairo/action.yml: add action
cfal May 9, 2023
cfd1e36
.github/workflows/contracts.yml: use install-cairo action
cfal May 9, 2023
1c0affa
initial
augustbleeds May 2, 2023
6017a31
contracts done for first example
augustbleeds May 4, 2023
e4b801c
temp
augustbleeds May 4, 2023
a722574
rename files
augustbleeds May 8, 2023
e0153ea
add proxy consumer
augustbleeds May 9, 2023
636932f
move scripts
augustbleeds May 9, 2023
4fb7242
wont work until goerli supports 0.11.1
augustbleeds May 9, 2023
04560c3
refactor starknet contracts and redo readme
augustbleeds May 9, 2023
449b0f6
update ts files
augustbleeds May 10, 2023
ada1350
bring up to date with cairo-1.0 branch
augustbleeds May 10, 2023
b630944
change gitignore
augustbleeds May 10, 2023
06acf39
minor changes
augustbleeds May 10, 2023
36c137f
rename to old folder
augustbleeds May 10, 2023
417e42f
example
augustbleeds May 10, 2023
cb76dbd
import mock aggregator
augustbleeds May 10, 2023
a6eb068
fix bug
augustbleeds May 10, 2023
d59ed0d
format cairo
augustbleeds May 10, 2023
14eae6e
minox pr fixes
augustbleeds May 11, 2023
6ba8ede
remove unused mod
augustbleeds May 11, 2023
54fa675
Merge branch 'cairo-1.0' into augustus.BCI-1224.rewrite-example-contr…
augustbleeds May 12, 2023
a5ea6c1
add cairo test for mock aggregator
augustbleeds May 17, 2023
cfc12c8
Merge branch 'develop' into augustus.BCI-1224.rewrite-example-contracts
augustbleeds Jun 6, 2023
d4ce9a7
Merge remote-tracking branch 'origin/develop' into augustus.BCI-1224.…
archseer Aug 10, 2023
c794ef2
cairo-format
archseer Aug 10, 2023
5791724
Upgrade examples to cairo 2.1.0
archseer Aug 10, 2023
90ee57e
Merge remote-tracking branch 'origin/develop' into augustus.BCI-1224.…
archseer Aug 11, 2023
89fedbd
cairo-format
archseer Aug 11, 2023
b9150b2
fix mock test
archseer Aug 11, 2023
5286fc0
yarn format
archseer Aug 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ format-cairo:
format-cairo-check:
find ./contracts/src -name "*.cairo" -type f \
-exec cairo-format -c {} +
# TODO: re-enable once examples are rewritten
# find ./examples -name "*.cairo" -type f \
# -exec cairo-format -c {} +
find ./examples -name "*.cairo" -type f \
-exec cairo-format -c {} +

.PHONY: format-ts
format-ts:
Expand Down
7 changes: 7 additions & 0 deletions contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ test = "cairo-test --starknet ."
# quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git" }

[[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

[lib]
sierra = true # Enable Sierra codegen.
casm = true # Enable CASM codegen.
2 changes: 1 addition & 1 deletion contracts/cairo_project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[crate_roots]
chainlink = "src"
chainlink = "src"
3 changes: 3 additions & 0 deletions contracts/src/ocr2/mocks/mock_aggregator.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ mod MockAggregator {
answer: u128, block_num: u64, observation_timestamp: u64, transmission_timestamp: u64
) {
let new_round_id = _latest_aggregator_round_id::read() + 1_u128;

// update both storage variables
_latest_aggregator_round_id::write(new_round_id);
Copy link
Collaborator

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

_transmissions::write(
new_round_id,
Transmission {
Expand Down
4 changes: 2 additions & 2 deletions contracts/test/ocr2/aggregator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ describe('aggregator.cairo', function () {
proposed: proposed_payee,
})
expect.fail()
} catch (err: any) {}
} catch (err: any) { }

// successful transfer
await oracle.invoke(aggregator, 'transfer_payeeship', {
Expand All @@ -411,7 +411,7 @@ describe('aggregator.cairo', function () {
try {
await oracle.invoke(aggregator, 'accept_payeeship', { transmitter })
expect.fail()
} catch (err: any) {}
} catch (err: any) { }

// successful accept
await proposed_oracle.invoke(aggregator, 'accept_payeeship', {
Expand Down
3 changes: 2 additions & 1 deletion examples/contracts/aggregator-consumer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
cache/
starknet-artifacts/
starknet-artifacts/
70 changes: 70 additions & 0 deletions examples/contracts/aggregator-consumer/README.md
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
14 changes: 14 additions & 0 deletions examples/contracts/aggregator-consumer/Scarb.toml
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
2 changes: 2 additions & 0 deletions examples/contracts/aggregator-consumer/cairo_project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[crate_roots]
chainlink_examples = "src"

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions examples/contracts/aggregator-consumer/example.env
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
25 changes: 0 additions & 25 deletions examples/contracts/aggregator-consumer/getting_start.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/contracts/aggregator-consumer/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const config: HardhatUserConfig = {
},
},
paths: {
cairoPaths: ['../../../contracts/src'],
cairoPaths: ['../../contracts/src'],
},
}

Expand Down
57 changes: 31 additions & 26 deletions examples/contracts/aggregator-consumer/package.json
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"
}
}
Loading