Skip to content

Commit

Permalink
rollup anchor for ink smart contract
Browse files Browse the repository at this point in the history
  • Loading branch information
GuiGou12358 committed Jul 14, 2023
1 parent 7dc2f9b commit a9cc209
Show file tree
Hide file tree
Showing 19 changed files with 2,897 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ink/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
resolver = "2"
members = [
"crates/phat_rollup_anchor_ink",
"contracts/test_oracle",
]
34 changes: 34 additions & 0 deletions ink/contracts/test_oracle/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "test_oracle"
version = "0.0.1"
authors = ["GuiGou"]
edition = "2021"

[dependencies]
ink = { version = "4.2", default-features = false }

scale = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] }
scale-info = { version = "2", default-features = false, features = ["derive"], optional = true }

openbrush = { git = "https://github.com/727-Ventures/openbrush-contracts", version = "3.1.1", features = ["ownable", "access_control"], default-features = false }

phat_rollup_anchor_ink = { path = "../../crates/phat_rollup_anchor_ink", default-features = false}

[dev-dependencies]
ink_e2e = { version = "4.2" }
hex-literal = { version = "0.4.1" }

[lib]
path = "lib.rs"

[features]
default = ["std"]
std = [
"ink/std",
"scale/std",
"scale-info/std",
"openbrush/std",
"phat_rollup_anchor_ink/std",
]
ink-as-dependency = []
e2e-tests = []
37 changes: 37 additions & 0 deletions ink/contracts/test_oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Test Oracle

Implements a simple oracle to get/display the price of trading pairs. It uses the crate `phat_rollup_anchor_ink`.
It supports:
- create a trading pair with an id and the token names. The name must match with the API id from CoinGecko. By example: `polkadot`, `astar`, `pha`, `usd`. Only an address granted as `MANAGER` can do it.
- configure the attestor authorized to send the prices. Only an address granted as `MANAGER` can do it.
- send a request to get the price of a given trading pair. Only an address granted as `MANAGER` can do it.
- handle the messages to feed the trading pair. Only an address granted as `ATTESTOR` can do it.
- display the trading pair with this id.
- allow meta transactions to separate the attestor and the payer.

By default, the contract owner is granted as `MANAGER` but it is not granted as `ATTESTOR`.

## Build

To build the contract:

```bash
cargo contract build
```

## Run e2e tests

Before you can run the test, you have to install a Substrate node with pallet-contracts. By default, `e2e tests` require that you install `substrate-contracts-node`. You do not need to run it in the background since the node is started for each test independently. To install the latest version:
```bash
cargo install contracts-node --git https://github.com/paritytech/substrate-contracts-node.git
```

If you want to run any other node with pallet-contracts you need to change `CONTRACTS_NODE` environment variable:
```bash
export CONTRACTS_NODE="YOUR_CONTRACTS_NODE_PATH"
```

And finally execute the following command to start e2e tests execution.
```bash
cargo test --features e2e-tests
```
Loading

0 comments on commit a9cc209

Please sign in to comment.