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

✨ New Staking Contract #453

Merged
merged 19 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 17 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ hyle-contracts = { path = "./contracts", package = "hyle-contracts" }
hydentity = { path = "./contracts/hydentity" }
hyllar = { path = "./contracts/hyllar" }
staking = { path = "./contracts/staking" }
bonsai-runner = { path = "./crates/bonsai-runner" }
config = "0.15.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["json"] }
Expand Down
43 changes: 3 additions & 40 deletions contract-sdk/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use bincode::{Decode, Encode};
use serde::de::DeserializeOwned;

use crate::{
flatten_blobs, Blob, BlobIndex, ContractInput, Digestable, HyleOutput, Identity,
StructuredBlob, StructuredBlobData,
flatten_blobs,
utils::{parse_blob, parse_structured_blob},
ContractInput, Digestable, HyleOutput, Identity, StructuredBlob, StructuredBlobData,
};

#[cfg(feature = "risc0")]
Expand Down Expand Up @@ -95,44 +96,6 @@ where
Ok((input, parsed_blob, caller))
}

pub fn parse_blob<Parameters>(blobs: &[Blob], index: &BlobIndex) -> Parameters
where
Parameters: Decode,
{
let blob = match blobs.get(index.0) {
Some(v) => v,
None => {
panic!("unable to find the payload");
}
};

let (parameters, _) =
bincode::decode_from_slice(blob.data.0.as_slice(), bincode::config::standard())
.expect("Failed to decode payload");
parameters
}

pub fn parse_structured_blob<Parameters>(
blobs: &[Blob],
index: &BlobIndex,
) -> StructuredBlob<Parameters>
where
Parameters: Decode,
{
let blob = match blobs.get(index.0) {
Some(v) => v,
None => {
panic!("unable to find the payload");
}
};

let parsed_blob: StructuredBlob<Parameters> = StructuredBlob::try_from(blob.clone())
.unwrap_or_else(|e| {
panic!("Failed to decode blob: {:?}", e);
});
parsed_blob
}

pub fn commit<State>(input: ContractInput<State>, new_state: State, res: crate::RunResult)
where
State: Digestable,
Expand Down
1 change: 1 addition & 0 deletions contract-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod erc20;
#[cfg(any(feature = "risc0", feature = "sp1"))]
pub mod guest;
pub mod identity_provider;
pub mod utils;

#[cfg(feature = "tracing")]
pub use tracing;
Expand Down
41 changes: 41 additions & 0 deletions contract-sdk/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use bincode::Decode;

use crate::{Blob, BlobIndex, StructuredBlob};

pub fn parse_blob<Parameters>(blobs: &[Blob], index: &BlobIndex) -> Parameters
where
Parameters: Decode,
{
let blob = match blobs.get(index.0) {
Some(v) => v,
None => {
panic!("unable to find the payload");
}
};

let (parameters, _) =
bincode::decode_from_slice(blob.data.0.as_slice(), bincode::config::standard())
.expect("Failed to decode payload");
parameters
}

pub fn parse_structured_blob<Parameters>(
blobs: &[Blob],
index: &BlobIndex,
) -> StructuredBlob<Parameters>
where
Parameters: Decode,
{
let blob = match blobs.get(index.0) {
Some(v) => v,
None => {
panic!("unable to find the payload");
}
};

let parsed_blob: StructuredBlob<Parameters> = StructuredBlob::try_from(blob.clone())
.unwrap_or_else(|e| {
panic!("Failed to decode blob: {:?}", e);
});
parsed_blob
}
Binary file modified contracts/amm/amm.img
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/amm/amm.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d10937cad6d5d0b18bd99a22f62c0f52fd591e4c18fd6ba7ba98a5e1088a219b
5dcae35e603495a426fa821a0d15fe43268a99addead70b87057078c925578e7
4 changes: 2 additions & 2 deletions contracts/amm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ fn main() {
};
}

let execution_state = ExecutionContext {
let execution_ctx = ExecutionContext {
callees_blobs: callees_blobs.into(),
caller,
};
let amm_state = input.initial_state.clone();
let mut amm_contract = AmmContract::new(execution_state, parsed_blob.contract_name, amm_state);
let mut amm_contract = AmmContract::new(execution_ctx, parsed_blob.contract_name, amm_state);

let amm_action = parsed_blob.data.parameters;

Expand Down
Binary file modified contracts/hydentity/hydentity.img
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/hydentity/hydentity.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a97a8642215dafd0402deaa87de330cbeb603301e3b328a76a66526b83fc7ede
8b71902dc20d7e2693645365169506e11cb4eab19e1f8bbbad262cbd60ecd22d
Binary file modified contracts/hyllar/hyllar.img
Binary file not shown.
2 changes: 1 addition & 1 deletion contracts/hyllar/hyllar.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e085fa46f2e62d69897fc77f379c0ba1d252d7285f84dbcc017957567d1e812f
9cdb9039b39c5799c41629d736d69062eea31d06586c64e097d69714a908575b
Loading
Loading