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

Update Pool Box #80

Merged
merged 34 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b169531
Add update pool box transaction builder
SethDusek Jul 22, 2022
260366b
Fix Ballot Contract registers + convert build_update_pool_box_tx to R…
SethDusek Jul 23, 2022
1700710
Add update pool box with new reward tokens + return TransactionContext
SethDusek Jul 25, 2022
3004f62
Count votes based on ballot tokens + initial cli command work
SethDusek Jul 26, 2022
d06ba77
Fix scans
SethDusek Jul 27, 2022
866494a
Add update pool CLI command
SethDusek Jul 29, 2022
148f021
Merge branch 'develop' into updatepool
SethDusek Jul 29, 2022
22b46bf
Initial rebase work
SethDusek Jul 30, 2022
1e756e5
Initial update bootstrap command work
SethDusek Aug 1, 2022
bc6a83b
Add testnet parameter to bootstrap
SethDusek Aug 2, 2022
fd5ff58
More update command work + make OracleContractParameters serializable…
SethDusek Aug 2, 2022
72d5f3b
Update explorer link
SethDusek Aug 3, 2022
2bfd6a6
Add remaining parameters (update, pool) to update command + update Ba…
SethDusek Aug 4, 2022
705ee00
Use new oracle_config_updated.yaml format for update-pool command
SethDusek Aug 4, 2022
cdd9821
Clippy
SethDusek Aug 4, 2022
0ea3b21
Add ToScanBytes trait
SethDusek Aug 4, 2022
fb6e019
Add update command unit test
SethDusek Aug 4, 2022
3482035
Use new update contract
SethDusek Aug 4, 2022
8e11e56
Allow for optional CastVoteParameters in Ballot Box
SethDusek Aug 4, 2022
ef4be44
Improve error message for ballot tokens in wallet
SethDusek Aug 4, 2022
7bcfc5e
Rename update command
SethDusek Aug 5, 2022
4852efa
Remove unnecessary node API call + remove unneeded reward token incre…
SethDusek Aug 6, 2022
174dd84
Remove height parameter in update-pool + write docs for update-pool /…
SethDusek Aug 6, 2022
1e5f6ec
Update token arguments for update_pool
SethDusek Aug 6, 2022
c788c07
Rework target tokens selection
SethDusek Aug 6, 2022
b8253e6
Add VoteBallotBoxesWrapper
SethDusek Aug 7, 2022
7eed4a6
Rename update.rs
SethDusek Aug 7, 2022
e5048bb
Change CastBallotBoxVoteParameters::reward_token_quantity to u64
SethDusek Aug 7, 2022
57effa2
Clippy
SethDusek Aug 7, 2022
a974c1a
Add update box creation height to CastBallotBoxVoteParameters
SethDusek Aug 7, 2022
420740e
Merge branch 'develop' into updatepool
SethDusek Aug 10, 2022
4bb37d6
Merge branch 'updatepool' of github.com:SethDusek/oracle-core into up…
SethDusek Aug 10, 2022
9b78803
Rebase
SethDusek Aug 10, 2022
a59227f
Update comment core/src/main.rs
SethDusek Aug 11, 2022
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
2 changes: 2 additions & 0 deletions core/src/box_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ mod ballot_box;
mod oracle_box;
mod pool_box;
mod refresh_box;
mod update_box;

pub use ballot_box::*;
pub use oracle_box::*;
pub use pool_box::*;
pub use refresh_box::*;
pub use update_box::*;
5 changes: 3 additions & 2 deletions core/src/box_kind/ballot_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl TryFrom<ErgoBox> for BallotBoxWrapper {
if ergo_box
.get_register(NonMandatoryRegisterId::R8.into())
.ok_or(BallotBoxError::NoRewardTokenQuantityInR8)?
.try_extract_into::<i32>()
.try_extract_into::<i64>()
.is_err()
{
return Err(BallotBoxError::NoRewardTokenQuantityInR8);
Expand All @@ -153,6 +153,7 @@ pub fn make_local_ballot_box_candidate(
value: BoxValue,
creation_height: u32,
) -> Result<ErgoBoxCandidate, ErgoBoxCandidateBuilderError> {
dbg!(&reward_tokens);
let mut builder = ErgoBoxCandidateBuilder::new(value, contract.ergo_tree(), creation_height);
builder.set_register_value(
NonMandatoryRegisterId::R4,
Expand All @@ -169,7 +170,7 @@ pub fn make_local_ballot_box_candidate(
);
builder.set_register_value(
NonMandatoryRegisterId::R8,
(*reward_tokens.amount.as_u64() as i32).into(),
(*reward_tokens.amount.as_u64() as i64).into(),
);
builder.add_token(ballot_token);
builder.build()
Expand Down
74 changes: 74 additions & 0 deletions core/src/box_kind/update_box.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use std::convert::TryFrom;

use ergo_lib::chain::ergo_box::box_builder::ErgoBoxCandidateBuilder;
use ergo_lib::chain::ergo_box::box_builder::ErgoBoxCandidateBuilderError;
use ergo_lib::ergo_chain_types::EcPoint;
use ergo_lib::ergotree_ir::chain::ergo_box::box_value::BoxValue;
use ergo_lib::ergotree_ir::chain::ergo_box::ErgoBox;
use ergo_lib::ergotree_ir::chain::ergo_box::ErgoBoxCandidate;
use ergo_lib::ergotree_ir::chain::ergo_box::NonMandatoryRegisterId;
use ergo_lib::ergotree_ir::chain::token::Token;
use ergo_lib::ergotree_ir::chain::token::TokenId;
use ergo_lib::ergotree_ir::ergo_tree::ErgoTree;
use ergo_lib::ergotree_ir::mir::constant::TryExtractInto;
use ergo_lib::ergotree_ir::sigma_protocol::sigma_boolean::ProveDlog;
use thiserror::Error;

use crate::contracts::update::UpdateContract;
use crate::contracts::update::UpdateContractError;

#[derive(Debug, Error)]
pub enum UpdateBoxError {
#[error("oracle box: no tokens found")]
NoTokens,
#[error("update contract: {0:?}")]
UpdateContractError(#[from] UpdateContractError),
}

#[derive(Clone)]
pub struct UpdateBoxWrapper(ErgoBox, UpdateContract);

impl UpdateBoxWrapper {
pub fn new(b: ErgoBox) -> Result<Self, UpdateBoxError> {
let _update_token_id = b
.tokens
.as_ref()
.ok_or(UpdateBoxError::NoTokens)?
.get(0)
.ok_or(UpdateBoxError::NoTokens)?
.token_id
.clone();
let contract = UpdateContract::from_ergo_tree(b.ergo_tree.clone())?;

Ok(Self(b, contract))
}
pub fn ergo_tree(&self) -> ErgoTree {
self.1.ergo_tree()
}
pub fn update_nft(&self) -> Token {
self.0.tokens.as_ref().unwrap().get(0).unwrap().clone()
}
pub fn ballot_token_id(&self) -> TokenId {
self.1.ballot_token_id().clone()
}
pub fn get_box(&self) -> &ErgoBox {
&self.0
}
pub fn min_votes(&self) -> u32 {
self.1.min_votes() as u32
}
}

impl TryFrom<ErgoBox> for UpdateBoxWrapper {
type Error = UpdateBoxError;

fn try_from(value: ErgoBox) -> Result<Self, Self::Error> {
UpdateBoxWrapper::new(value)
}
}

impl From<UpdateBoxWrapper> for ErgoBox {
fn from(w: UpdateBoxWrapper) -> Self {
w.0.clone()
}
}
1 change: 1 addition & 0 deletions core/src/cli_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod bootstrap;
pub mod extract_reward_tokens;
pub mod print_reward_tokens;
pub mod transfer_oracle_token;
pub mod update_pool;
pub mod vote_update_pool;

pub(crate) fn ergo_explorer_transaction_link(tx_id_str: String, prefix: NetworkPrefix) -> String {
Expand Down
Loading