From e71d5135b255d665d33a9f4d383806c8d7b76a9d Mon Sep 17 00:00:00 2001 From: Rigidity Date: Wed, 4 Dec 2024 17:17:11 -0500 Subject: [PATCH] Finish initial vault puzzles --- crates/chia-sdk-types/src/puzzles/vault.rs | 6 ++ .../src/puzzles/vault/delegated_feeder.rs | 57 ++++++++++++++ .../src/puzzles/vault/index_wrapper.rs | 32 ++++++++ .../src/puzzles/vault/restrictions.rs | 74 +++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100644 crates/chia-sdk-types/src/puzzles/vault/delegated_feeder.rs create mode 100644 crates/chia-sdk-types/src/puzzles/vault/index_wrapper.rs create mode 100644 crates/chia-sdk-types/src/puzzles/vault/restrictions.rs diff --git a/crates/chia-sdk-types/src/puzzles/vault.rs b/crates/chia-sdk-types/src/puzzles/vault.rs index c32004c..fc516a7 100644 --- a/crates/chia-sdk-types/src/puzzles/vault.rs +++ b/crates/chia-sdk-types/src/puzzles/vault.rs @@ -1,7 +1,13 @@ +mod delegated_feeder; +mod index_wrapper; +mod restrictions; mod vault_1_of_n; mod vault_m_of_n; mod vault_n_of_n; +pub use delegated_feeder::*; +pub use index_wrapper::*; +pub use restrictions::*; pub use vault_1_of_n::*; pub use vault_m_of_n::*; pub use vault_n_of_n::*; diff --git a/crates/chia-sdk-types/src/puzzles/vault/delegated_feeder.rs b/crates/chia-sdk-types/src/puzzles/vault/delegated_feeder.rs new file mode 100644 index 0000000..0732455 --- /dev/null +++ b/crates/chia-sdk-types/src/puzzles/vault/delegated_feeder.rs @@ -0,0 +1,57 @@ +use clvm_traits::{FromClvm, ToClvm}; +use clvm_utils::TreeHash; +use hex_literal::hex; + +use crate::Mod; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)] +#[clvm(curry)] +pub struct DelegatedFeederArgs { + pub inner_puzzle: I, +} + +impl DelegatedFeederArgs { + pub fn new(inner_puzzle: I) -> Self { + Self { inner_puzzle } + } +} + +impl Mod for DelegatedFeederArgs { + const MOD_REVEAL: &[u8] = &DELEGATED_FEEDER_PUZZLE; + const MOD_HASH: TreeHash = DELEGATED_FEEDER_PUZZLE_HASH; +} + +#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] +#[clvm(solution)] +pub struct DelegatedFeederSolution { + pub delegated_puzzle: P, + pub delegated_solution: S, + #[clvm(rest)] + pub inner_solution: I, +} + +impl DelegatedFeederSolution { + pub fn new(delegated_puzzle: P, delegated_solution: S, inner_solution: I) -> Self { + Self { + delegated_puzzle, + delegated_solution, + inner_solution, + } + } +} + +pub const DELEGATED_FEEDER_PUZZLE: [u8; 203] = hex!( + " + ff02ffff01ff02ff04ffff04ff02ffff04ffff02ff05ffff04ffff02ff06ffff + 04ff02ffff04ff0bff80808080ff1f8080ffff04ffff02ff0bff1780ff808080 + 8080ffff04ffff01ffff02ffff03ff05ffff01ff04ff09ffff02ff04ffff04ff + 02ffff04ff0dffff04ff0bff808080808080ffff010b80ff0180ff02ffff03ff + ff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff8080 + 8080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101 + ff058080ff0180ff018080 + " +); + +pub const DELEGATED_FEEDER_PUZZLE_HASH: TreeHash = TreeHash::new(hex!( + "9db33d93853179903d4dd272a00345ee6630dc94907dbcdd96368df6931060fd" +)); diff --git a/crates/chia-sdk-types/src/puzzles/vault/index_wrapper.rs b/crates/chia-sdk-types/src/puzzles/vault/index_wrapper.rs new file mode 100644 index 0000000..6101b54 --- /dev/null +++ b/crates/chia-sdk-types/src/puzzles/vault/index_wrapper.rs @@ -0,0 +1,32 @@ +use clvm_traits::{FromClvm, ToClvm}; +use clvm_utils::TreeHash; +use hex_literal::hex; + +use crate::Mod; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, ToClvm, FromClvm)] +#[clvm(curry)] +pub struct IndexWrapperArgs { + pub index: u32, + pub inner_puzzle: I, +} + +impl IndexWrapperArgs { + pub fn new(index: u32, inner_puzzle: I) -> Self { + Self { + index, + inner_puzzle, + } + } +} + +impl Mod for IndexWrapperArgs { + const MOD_REVEAL: &[u8] = &INDEX_WRAPPER; + const MOD_HASH: TreeHash = INDEX_WRAPPER_HASH; +} + +pub const INDEX_WRAPPER: [u8; 7] = hex!("ff02ff05ff0780"); + +pub const INDEX_WRAPPER_HASH: TreeHash = TreeHash::new(hex!( + "847d971ef523417d555ea9854b1612837155d34d453298defcd310774305f657" +)); diff --git a/crates/chia-sdk-types/src/puzzles/vault/restrictions.rs b/crates/chia-sdk-types/src/puzzles/vault/restrictions.rs new file mode 100644 index 0000000..982e31e --- /dev/null +++ b/crates/chia-sdk-types/src/puzzles/vault/restrictions.rs @@ -0,0 +1,74 @@ +use chia_protocol::Bytes32; +use clvm_traits::{FromClvm, ToClvm}; +use clvm_utils::TreeHash; +use hex_literal::hex; + +use crate::Mod; + +#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] +#[clvm(curry)] +pub struct RestrictionsArgs { + pub member_validators: Vec, + pub delegated_puzzle_validators: Vec, + pub inner_puzzle: I, +} + +impl RestrictionsArgs { + pub fn new( + member_validators: Vec, + delegated_puzzle_validators: Vec, + inner_puzzle: I, + ) -> Self { + Self { + member_validators, + delegated_puzzle_validators, + inner_puzzle, + } + } +} + +impl Mod for RestrictionsArgs { + const MOD_REVEAL: &[u8] = &RESTRICTIONS_PUZZLE; + const MOD_HASH: TreeHash = RESTRICTIONS_PUZZLE_HASH; +} + +#[derive(Debug, Clone, PartialEq, Eq, ToClvm, FromClvm)] +#[clvm(solution)] +pub struct RestrictionsSolution { + pub delegated_puzzle_hash: Bytes32, + pub member_validator_solutions: Vec, + pub delegated_puzzle_validator_solutions: Vec, + pub inner_solution: I, +} + +impl RestrictionsSolution { + pub fn new( + delegated_puzzle_hash: Bytes32, + member_validator_solutions: Vec, + delegated_puzzle_validator_solutions: Vec, + inner_solution: I, + ) -> Self { + Self { + delegated_puzzle_hash, + member_validator_solutions, + delegated_puzzle_validator_solutions, + inner_solution, + } + } +} + +pub const RESTRICTIONS_PUZZLE: [u8; 204] = hex!( + " + ff02ffff01ff02ff04ffff04ff02ffff04ff05ffff04ff5fffff04ffff02ff17 + ffff04ff2fff82017f8080ffff04ffff02ff06ffff04ff02ffff04ff0bffff04 + ff81bfffff04ff2fff808080808080ff80808080808080ffff04ffff01ffff03 + ff80ffff02ff06ffff04ff02ffff04ff05ffff04ff0bffff04ff17ff80808080 + 8080ff1780ff02ffff03ff05ffff01ff03ff80ffff02ff09ffff04ff17ff1380 + 80ffff02ff06ffff04ff02ffff04ff0dffff04ff1bffff04ff17ff8080808080 + 8080ff8080ff0180ff018080 + " +); + +pub const RESTRICTIONS_PUZZLE_HASH: TreeHash = TreeHash::new(hex!( + "a28d59d39f964a93159c986b1914694f6f2f1c9901178f91e8b0ba4045980eef" +));