Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
432 changes: 202 additions & 230 deletions target_chains/fuel/contracts/Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion target_chains/fuel/contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "Apache-2.0"
[dependencies]
rand = "0.8.5"
base64 = "0.22"
fuels = { version = "0.62.0", features = ["fuel-core-lib"] }
fuels = { version = "0.65.1", features = ["fuel-core-lib"] }
tokio = { version = "1.12", features = ["rt", "macros"] }
hex = "0.4.3"
reqwest = "0.11.27"
Expand Down
4 changes: 2 additions & 2 deletions target_chains/fuel/contracts/Forc.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[[package]]
name = "core"
source = "path+from-root-E19CE48B3E858B72"
source = "path+from-root-2AB5BCE55EAAEFF4"

[[package]]
name = "pyth-contract"
Expand Down Expand Up @@ -32,7 +32,7 @@ dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.60.0#2f0392ee35a1e4dd80bd8034962d5b4083dfb8b6"
source = "git+https://github.com/fuellabs/sway?tag=v0.62.0#efda0397c7bee77de73bd726ec0b732d57614973"
dependencies = ["core"]

[[package]]
Expand Down
12 changes: 5 additions & 7 deletions target_chains/fuel/contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Pyth-integration

> **_NOTE:_** The project is a WIP.

An implementation of a [Pyth Network](https://pyth.network/) oracle contract in Sway. Utilising minimal, internal [Wormhole](https://docs.wormhole.com/wormhole/) functionality and state.

## Interfaces

The project provides four interfaces for interaction with the oracle contract:

- [PythCore](./pyth-interface/src/interface.sw#L20) - provides the core functionality to required to utilise the oracle; getting fees, updating prices and fetching prices.
- [PythInit](./pyth-interface/src/interface.sw#L250) - provides the functionality to setup the oracle's state.
- [PythInfo](./pyth-interface/src/interface.sw#L255) - provides additional information about the oracle's state.
- [WormholeGuardians](./pyth-interface/src/interface.sw#L283) - provides functionality to maintain and query the wormhole-state-elements used by the oracle.
- [PythCore](./pyth-interface/src/interface.sw#L24) - provides the core functionality to required to utilise the oracle; getting fees, updating prices and fetching prices.
- [PythInit](./pyth-interface/src/interface.sw#L263) - provides the functionality to setup the oracle's state.
- [PythInfo](./pyth-interface/src/interface.sw#L277) - provides additional information about the oracle's state.
- [WormholeGuardians](./pyth-interface/src/interface.sw#L308) - provides functionality to maintain and query the wormhole-state-elements used by the oracle.

## Running the project

Expand All @@ -37,7 +35,7 @@ cargo test

Before deploying the oracle contract; the `deployer` must be set to the address of the deploying wallet in the storage block, so that the deployer can setup the contract with the `constructor()` method.

Parameters for the `constructor()` method can be seen in the [tests of the method](./pyth-contract/tests/functions/pyth_init/constuctor.rs#L28), which at the time of writing uses the real up-to-date values as per Pyth's documentation and EVM integrations. Care should be taken to ensure that the most up-to-date values are used for the `constructor()` method's parameters.
Parameters for the `constructor()` method can be seen in the [tests of the method](./tests/utils/interface/pyth_init.rs#L7), which at the time of writing uses the real up-to-date values as per Pyth's documentation and EVM integrations. Care should be taken to ensure that the most up-to-date values are used for the `constructor()` method's parameters.

#### Fuel Beta-5 network deployment:

Expand Down
4 changes: 2 additions & 2 deletions target_chains/fuel/contracts/fuel-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
channel = "latest-aarch64-apple-darwin"

[components]
forc = "0.60.0"
fuel-core = "0.26.0"
forc = "0.62.0"
fuel-core = "0.31.0"
Original file line number Diff line number Diff line change
Expand Up @@ -1838,7 +1838,7 @@
"type": 6,
"typeArguments": []
},
"offset": 129616
"offset": 117008
}
]
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
[
{
"key": "6294951dcb0a9111a517be5cf4785670ff4e166fb5ab9c33b17e6881b48e964f",
"key": "11672498f6e54d64f7c94ceafab63ce9c33b957b083d82f9301e18c4bbcdd43e",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "71217a24656901c411894bb65eb78a828dafa5a6844488ef5024eb5ac0cff79c",
"key": "1fea2a1870fafe58b3f658d2a10d75f7d4b599036bb925958e3650097753f03f",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "71217a24656901c411894bb65eb78a828dafa5a6844488ef5024eb5ac0cff79d",
"key": "1fea2a1870fafe58b3f658d2a10d75f7d4b599036bb925958e3650097753f040",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "7f91d1a929dce734e7f930bbb279ccfccdb5474227502ea8845815c74bd930a7",
"key": "1feab27058c4ed60cb36c15c123efafc983fdbc10f4cfac4f1b23fdb8c36fb7d",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "8a89a0cce819e0426e565819a9a98711329087da5a802fb16edd223c47fa44ef",
"key": "1feab27058c4ed60cb36c15c123efafc983fdbc10f4cfac4f1b23fdb8c36fb7e",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "94b2b70d20da552763c7614981b2a4d984380d7ed4e54c01b28c914e79e44bd5",
"key": "2978ac0e4bdc20e0a96c04e8adb0639e5efdff01601aa4f7887421e795e4b96a",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "94b2b70d20da552763c7614981b2a4d984380d7ed4e54c01b28c914e79e44bd6",
"key": "357565afd3b58fa5509545cd95377655dcb331b733af6f4439699d27dcf450eb",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "a9203bbb8366ca9d708705dce980acbb54d44fb753370ffe4c7d351b46b2abbc",
"key": "358560d9e39bf0d62ad9ffeba18c167b0e4e6722c6eb24f55cbc64054c51b905",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "b48b753af346966d0d169c0b2e3234611f65d5cfdb57c7b6e7cd6ca93707bee0",
"key": "358560d9e39bf0d62ad9ffeba18c167b0e4e6722c6eb24f55cbc64054c51b906",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "c7e08cdde76020f08f4ce5c3257422ae67f9676992689b64b85f35aa58752d9e",
"key": "480744474aef380dda93aae5f17de10f991ca301c7ae8a925ab40229da966cf8",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "c7e08cdde76020f08f4ce5c3257422ae67f9676992689b64b85f35aa58752d9f",
"key": "d16fb5609ac0a5d5c45145524cbd88ae218f3be85b76bb42239b7eb916305d6d",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"key": "d02e07f5a716bd3b6670aaf9a73352164e6b946c24db14f72005b7029e67d96a",
"key": "f9e12c6c1c57daf9e6a5ff000b582628bec999880e26917559121db757ba5653",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
}
]
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl PriceFeed {
let (_, slice) = encoded_proof.split_at(current_offset);
let (encoded_message, _) = slice.split_at(message_size);
current_offset += message_size;
let end_offset = validate_proof(encoded_proof, current_offset, digest, encoded_message);
let end_offset = validate_proof(encoded_proof, current_offset, digest, encoded_message.clone());
// Message type of 0 is a Price Feed
require(
encoded_message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub fn validate_proof(
leaf_data: Bytes,
) -> u64 {
let mut current_digest = leaf_hash(leaf_data);

let proof_size = encoded_proof.get(proof_offset).unwrap().as_u64();
proof_offset += 1;

Expand Down
40 changes: 33 additions & 7 deletions target_chains/fuel/contracts/src/pyth_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ use crate::constants::{
use base64::{engine::general_purpose, prelude::Engine};
use fuels::{
prelude::{abigen, CallParameters, Contract, LoadConfiguration, TxPolicies, WalletUnlocked},
programs::call_response::FuelCallResponse,
types::{errors::Error, Address, Bits256, Bytes, Identity},
programs::responses::CallResponse,
tx::Receipt,
types::{
errors::{transaction::Reason, Error},
Address, Bits256, Bytes, Identity,
},
};
use rand::Rng;
use reqwest;
Expand Down Expand Up @@ -163,7 +167,7 @@ pub fn create_governance_instruction_payload(
}

impl Pyth {
pub async fn price(&self, price_feed_id: Bits256) -> Result<FuelCallResponse<Price>, Error> {
pub async fn price(&self, price_feed_id: Bits256) -> Result<CallResponse<Price>, Error> {
self.instance
.methods()
.price(price_feed_id)
Expand All @@ -175,7 +179,7 @@ impl Pyth {
&self,
fee: u64,
update_data: &[Bytes],
) -> Result<FuelCallResponse<()>, Error> {
) -> Result<CallResponse<()>, Error> {
self.instance
.methods()
.update_price_feeds(update_data.to_vec())
Expand All @@ -184,7 +188,7 @@ impl Pyth {
.await
}

pub async fn update_fee(&self, update_data: &[Bytes]) -> Result<FuelCallResponse<u64>, Error> {
pub async fn update_fee(&self, update_data: &[Bytes]) -> Result<CallResponse<u64>, Error> {
self.instance
.methods()
.update_fee(update_data.to_vec())
Expand All @@ -200,7 +204,7 @@ impl Pyth {
wormhole_guardian_set_addresses: Vec<Bits256>,
wormhole_guardian_set_index: u32,
chain_id: u16,
) -> Result<FuelCallResponse<()>, Error> {
) -> Result<CallResponse<()>, Error> {
self.instance
.methods()
.constructor(
Expand Down Expand Up @@ -240,7 +244,7 @@ impl Pyth {
})
}

pub async fn current_guardian_set_index(&self) -> Result<FuelCallResponse<u32>, Error> {
pub async fn current_guardian_set_index(&self) -> Result<CallResponse<u32>, Error> {
self.instance
.methods()
.current_guardian_set_index()
Expand Down Expand Up @@ -376,3 +380,25 @@ pub fn default_data_sources() -> Vec<DataSource> {
},
]
}

pub fn handle_error(e: Error) -> Error {
if let Error::Transaction(Reason::Reverted {
reason: _,
revert_id: _,
receipts,
}) = &e
{
for r in receipts {
match r {
Receipt::Log { ra, .. } => {
println!("{:?}", ra);
}
Receipt::LogData { data, .. } => {
println!("{:?}", hex::encode(data.clone().unwrap()));
}
_ => {}
}
}
}
e
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ mod success {
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes())
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down Expand Up @@ -90,8 +89,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ mod success {
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes())
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price_no_older_than(
&deployer.instance,
Expand Down Expand Up @@ -98,8 +97,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price_no_older_than(
&deployer.instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ mod success {
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes())
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price_unsafe(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down Expand Up @@ -90,8 +89,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await
.unwrap();
.await;

let eth_usd_ema_price = ema_price_unsafe(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod success {
.await
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes()).await.unwrap();
update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes()).await;

let eth_usd_price = price(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down Expand Up @@ -87,7 +87,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await.unwrap();
.await;

let eth_usd_price = price(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ mod success {
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes())
.await
.unwrap();
.await;

let eth_usd_price = price_no_older_than(
&deployer.instance,
Expand Down Expand Up @@ -99,8 +98,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await
.unwrap();
.await;

let eth_usd_price = price_no_older_than(
&deployer.instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod success {
.await
.value;

update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes()).await.unwrap();
update_price_feeds(&deployer.instance, fee, test_batch_update_data_bytes()).await;

let eth_usd_price = price_unsafe(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down Expand Up @@ -87,7 +87,7 @@ mod success {
fee,
test_accumulator_update_data_bytes(),
)
.await.unwrap();
.await;

let eth_usd_price = price_unsafe(&deployer.instance, default_price_feed_ids()[0])
.await
Expand Down
Loading