-
Notifications
You must be signed in to change notification settings - Fork 8
Add protocol fee collector covenant #168
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
Open
zahorodnyi
wants to merge
1
commit into
dev
Choose a base branch
from
feat/fee-collector-covenant
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| fn checksig(pubkey: Pubkey, sig: Signature) { | ||
| let sighash: u256 = jet::sig_all_hash(); | ||
|
|
||
| jet::bip_0340_verify((pubkey, sighash), sig); | ||
| } | ||
|
|
||
| fn main() { | ||
| checksig(param::WITHDRAWAL_PUBKEY, witness::SIGNATURE); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // This file is @generated by Simplex. Do not edit manually. | ||
|
|
||
| use simplex::include_simf; | ||
| use simplex::program::{ArgumentsTrait, Program}; | ||
| use simplex::provider::SimplicityNetwork; | ||
| use simplex::simplicityhl::elements::Script; | ||
| use simplex::simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey; | ||
| pub struct FeeCollectorProgram { | ||
| program: Program, | ||
| } | ||
| impl FeeCollectorProgram { | ||
| pub const SOURCE: &'static str = derived_fee_collector::FEE_COLLECTOR_CONTRACT_SOURCE; | ||
| #[must_use] | ||
| pub fn new(arguments: &impl ArgumentsTrait) -> Self { | ||
| Self { | ||
| program: Program::new(Self::SOURCE, arguments), | ||
| } | ||
| } | ||
| #[must_use] | ||
| pub fn with_taproot_pubkey(mut self, pub_key: XOnlyPublicKey) -> Self { | ||
| self.program = self.program.with_taproot_pubkey(pub_key); | ||
| self | ||
| } | ||
| #[must_use] | ||
| pub fn with_storage_capacity(mut self, capacity: usize) -> Self { | ||
| self.program = self.program.with_storage_capacity(capacity); | ||
| self | ||
| } | ||
| pub fn set_storage_at(&mut self, index: usize, new_value: impl Into<Vec<u8>>) { | ||
| self.program.set_storage_at(index, new_value); | ||
| } | ||
| #[must_use] | ||
| pub fn get_storage_len(&self) -> usize { | ||
| self.program.get_storage_len() | ||
| } | ||
| #[must_use] | ||
| pub fn get_storage(&self) -> &[Vec<u8>] { | ||
| self.program.get_storage() | ||
| } | ||
| #[must_use] | ||
| pub fn get_storage_at(&self, index: usize) -> Vec<u8> { | ||
| self.program.get_storage_at(index) | ||
| } | ||
| #[must_use] | ||
| pub fn get_script_pubkey(&self, network: &SimplicityNetwork) -> Script { | ||
| self.program.get_script_pubkey(network) | ||
| } | ||
| #[must_use] | ||
| pub fn get_script_hash(&self, network: &SimplicityNetwork) -> [u8; 32] { | ||
| self.program.get_script_hash(network) | ||
| } | ||
| #[must_use] | ||
| pub fn get_cmr(&self) -> [u8; 32] { | ||
| self.program.get_cmr() | ||
| } | ||
| #[must_use] | ||
| pub fn get_tapleaf_hash(&self) -> [u8; 32] { | ||
| self.program.get_tapleaf_hash() | ||
| } | ||
| } | ||
| impl AsRef<Program> for FeeCollectorProgram { | ||
| fn as_ref(&self) -> &Program { | ||
| &self.program | ||
| } | ||
| } | ||
| impl AsMut<Program> for FeeCollectorProgram { | ||
| fn as_mut(&mut self) -> &mut Program { | ||
| &mut self.program | ||
| } | ||
| } | ||
| include_simf!("src/artifacts/simf/fee_collector.simf"); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| use simplex::{ | ||
| program::Program, | ||
| provider::SimplicityNetwork, | ||
| simplicityhl::elements::AssetId, | ||
| transaction::{FinalTransaction, UTXO}, | ||
| }; | ||
|
|
||
| use crate::artifacts::fee_collector::FeeCollectorProgram; | ||
|
|
||
| use crate::programs::fee_collector::{FeeCollectorParameters, FeeCollectorWitnessParams}; | ||
| use crate::programs::program::SimplexProgram; | ||
|
|
||
| pub struct FeeCollector { | ||
| program: FeeCollectorProgram, | ||
| parameters: FeeCollectorParameters, | ||
| } | ||
|
|
||
| impl FeeCollector { | ||
| pub fn new(parameters: FeeCollectorParameters) -> Self { | ||
| Self { | ||
| program: FeeCollectorProgram::new(¶meters.build_arguments()), | ||
| parameters, | ||
| } | ||
| } | ||
|
|
||
| pub fn get_parameters(&self) -> &FeeCollectorParameters { | ||
| &self.parameters | ||
| } | ||
|
|
||
| pub fn attach_deposit(&self, ft: &mut FinalTransaction, asset_id: AssetId, amount: u64) { | ||
| self.add_program_output(ft, asset_id, amount); | ||
| } | ||
|
|
||
| pub fn attach_withdrawal( | ||
| &self, | ||
| ft: &mut FinalTransaction, | ||
| program_utxo: UTXO, | ||
| witness_params: FeeCollectorWitnessParams, | ||
| ) { | ||
| self.add_program_input(ft, program_utxo, witness_params.build_witness()); | ||
| } | ||
| } | ||
|
|
||
| impl SimplexProgram for FeeCollector { | ||
| fn get_program_source_code() -> &'static str { | ||
| FeeCollectorProgram::SOURCE | ||
| } | ||
|
|
||
| fn get_program(&self) -> &Program { | ||
| self.program.as_ref() | ||
| } | ||
|
|
||
| fn get_network(&self) -> &SimplicityNetwork { | ||
| &self.parameters.network | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| mod core; | ||
| mod params; | ||
| mod witness; | ||
|
|
||
| pub use core::FeeCollector; | ||
| pub use params::FeeCollectorParameters; | ||
| pub use witness::FeeCollectorWitnessParams; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| use simplex::{provider::SimplicityNetwork, simplicityhl::elements::secp256k1_zkp::XOnlyPublicKey}; | ||
|
|
||
| use crate::artifacts::fee_collector::derived_fee_collector::FeeCollectorArguments; | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct FeeCollectorParameters { | ||
| pub withdrawal_pubkey: XOnlyPublicKey, | ||
| pub network: SimplicityNetwork, | ||
| } | ||
|
|
||
| impl FeeCollectorParameters { | ||
| pub fn build_arguments(&self) -> FeeCollectorArguments { | ||
| FeeCollectorArguments { | ||
| withdrawal_pubkey: self.withdrawal_pubkey.serialize(), | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| use crate::artifacts::fee_collector::derived_fee_collector::FeeCollectorWitness; | ||
|
|
||
| #[derive(Debug, Clone, Copy)] | ||
| pub struct FeeCollectorWitnessParams { | ||
| pub signature: [u8; 64], | ||
| } | ||
|
|
||
| impl FeeCollectorWitnessParams { | ||
| pub fn new(signature: [u8; 64]) -> Self { | ||
| Self { signature } | ||
| } | ||
|
|
||
| pub fn build_witness(&self) -> Box<FeeCollectorWitness> { | ||
| Box::new(FeeCollectorWitness { | ||
| signature: self.signature, | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a spending path that allows us to add an asset to the UTXO without changing the
script_pubkey