-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc1e13e
commit d19bc6e
Showing
15 changed files
with
337 additions
and
69 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,22 @@ | ||
[package] | ||
name = "furnace" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
serde = { workspace = true } | ||
shared = { path = "../shared" } | ||
candid = { workspace = true } | ||
ic-cdk = { workspace = true } | ||
ic-cdk-timers = { workspace = true } | ||
ic-stable-structures = { workspace = true } | ||
garde = { workspace = true } | ||
ic-e8s = { workspace = true } | ||
icrc-ledger-types = { workspace = true } | ||
ic-ledger-types = { workspace = true } | ||
futures = { workspace = true } |
This file contains 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,48 @@ | ||
type ClaimRewardRequest = record { to : principal }; | ||
type ClaimRewardResponse = record { result : Result }; | ||
type GetBurnersRequest = record { take : nat32; start : opt principal }; | ||
type GetBurnersResponse = record { | ||
entries : vec record { principal; nat; nat; bool; nat64 }; | ||
}; | ||
type GetTotalsResponse = record { | ||
total_lottery_participants : nat64; | ||
your_lottery_eligibility_status : bool; | ||
total_share_supply : nat; | ||
your_decide_id_verification_status : bool; | ||
total_burners : nat64; | ||
total_tcycles_burned : nat; | ||
pos_start_key : opt principal; | ||
your_share_tcycles : nat; | ||
pos_round_delay_ns : nat64; | ||
total_burn_token_minted : nat; | ||
total_verified_accounts : nat64; | ||
current_burn_token_reward : nat; | ||
your_unclaimed_reward_e8s : nat; | ||
is_lottery_enabled : bool; | ||
current_pos_round : nat64; | ||
current_share_fee : nat; | ||
}; | ||
type RefundLostTokensRequest = record { kind : RefundTokenKind }; | ||
type RefundLostTokensResponse = record { results : vec Result }; | ||
type RefundTokenKind = variant { ICP : vec record { blob; nat64 } }; | ||
type Result = variant { Ok : nat; Err : text }; | ||
type StakeRequest = record { qty_e8s_u64 : nat64 }; | ||
type VerifyDecideIdRequest = record { jwt : text }; | ||
type WithdrawRequest = record { to : principal; qty_e8s : nat }; | ||
service : () -> { | ||
can_migrate_msq_account : () -> (bool) query; | ||
claim_reward : (ClaimRewardRequest) -> (ClaimRewardResponse); | ||
decide_id_verified_accounts_count : () -> (nat32) query; | ||
disable_lottery : () -> (); | ||
enable_lottery : () -> (); | ||
get_burners : (GetBurnersRequest) -> (GetBurnersResponse) query; | ||
get_totals : () -> (GetTotalsResponse) query; | ||
migrate_msq_account : (ClaimRewardRequest) -> (record {}); | ||
refund_lost_tokens : (RefundLostTokensRequest) -> (RefundLostTokensResponse); | ||
resume : () -> (); | ||
stake : (StakeRequest) -> (record {}); | ||
stop : () -> (); | ||
subaccount_of : (principal) -> (blob) query; | ||
verify_decide_id : (VerifyDecideIdRequest) -> (record {}); | ||
withdraw : (WithdrawRequest) -> (record {}); | ||
} |
This file contains 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 @@ | ||
pub mod utils; |
This file contains 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,45 @@ | ||
use std::{cell::RefCell, time::Duration}; | ||
|
||
use ic_cdk::{ | ||
api::{management_canister::main::raw_rand, time}, | ||
spawn, | ||
}; | ||
use ic_cdk_timers::set_timer; | ||
use ic_stable_structures::{ | ||
memory_manager::{MemoryId, MemoryManager}, | ||
Cell, DefaultMemoryImpl, StableBTreeMap, | ||
}; | ||
use shared::furnace::{state::FurnaceState, types::FurnaceInfo}; | ||
|
||
thread_local! { | ||
pub static MEMORY_MANAGER: RefCell<MemoryManager<DefaultMemoryImpl>> = | ||
RefCell::new(MemoryManager::init(DefaultMemoryImpl::default())); | ||
|
||
pub static STATE: RefCell<FurnaceState> = RefCell::new( | ||
FurnaceState { | ||
cur_round_entries: StableBTreeMap::init( | ||
MEMORY_MANAGER.with_borrow(|m| m.get(MemoryId::new(0))), | ||
), | ||
positions: StableBTreeMap::init( | ||
MEMORY_MANAGER.with_borrow(|m| m.get(MemoryId::new(1))), | ||
), | ||
winners: StableBTreeMap::init( | ||
MEMORY_MANAGER.with_borrow(|m| m.get(MemoryId::new(2))), | ||
), | ||
furnace_info: Cell::init(MEMORY_MANAGER.with_borrow(|m| m.get(MemoryId::new(3))), FurnaceInfo::default()).expect("Unable to create furnace info cell"), | ||
raffle_round_info: Cell::init(MEMORY_MANAGER.with_borrow(|m| m.get(MemoryId::new(3))), None).expect("Unable to create raffle round info cell") | ||
} | ||
) | ||
} | ||
|
||
pub fn set_init_seed_one_timer() { | ||
set_timer(Duration::from_nanos(0), init_seed); | ||
} | ||
|
||
fn init_seed() { | ||
spawn(async { | ||
let (rand,) = raw_rand().await.expect("Unable to fetch rand"); | ||
|
||
STATE.with_borrow_mut(|s| s.init(rand, time())); | ||
}); | ||
} |
This file contains 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.