chia_sdk_driver/primitives/action_layer/
reward_distributor_prefix.rs1use chia_protocol::Bytes32;
2use clvm_traits::clvm_tuple;
3use clvm_utils::{ToTreeHash, TreeHash};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6#[repr(u8)]
7pub enum RewardDistributorCreatedAnnouncementPrefix {
8 AddIncentives = b'i',
9 CommitIncentives = b'c',
10 InitiatePayout = b'p',
11 NewEpoch = b'e',
12 Sync = b's',
13 StakeSlot = b't',
14 StakeLock = b'l',
15 Refresh = b'r',
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19#[repr(u8)]
20pub enum RewardDistributorReceivedMessagePrefix {
21 InitiatePayout = b'p',
22 WithdrawIncentives = b'w',
23 AddEntry = b'a',
24 RemoveEntry = b'r',
25 Stake = b's',
26 Unstake = b'u',
27}
28
29pub fn prefix_hash(prefix: u8, hash: TreeHash) -> Vec<u8> {
30 let mut msg = hash.to_vec();
31 msg.insert(0, prefix);
32 msg
33}
34
35impl RewardDistributorCreatedAnnouncementPrefix {
36 pub fn add_incentives(amount: u64, epoch_last_update: u64) -> Vec<u8> {
37 prefix_hash(
38 Self::AddIncentives as u8,
39 clvm_tuple!(amount, epoch_last_update).tree_hash(),
40 )
41 }
42
43 pub fn commit_incentives(new_commitment_slot_value: TreeHash) -> Vec<u8> {
44 prefix_hash(Self::CommitIncentives as u8, new_commitment_slot_value)
45 }
46
47 pub fn initiate_payout(payout_puzzle_hash: Bytes32, payout_amount: u64) -> Vec<u8> {
48 prefix_hash(
49 Self::InitiatePayout as u8,
50 clvm_tuple!(payout_puzzle_hash, payout_amount).tree_hash(),
51 )
52 }
53
54 pub fn new_epoch(epoch_end: u64) -> Vec<u8> {
55 prefix_hash(Self::NewEpoch as u8, epoch_end.tree_hash())
56 }
57
58 pub fn sync(update_time: u64, epoch_end: u64) -> Vec<u8> {
59 prefix_hash(
60 Self::Sync as u8,
61 clvm_tuple!(update_time, epoch_end).tree_hash(),
62 )
63 }
64
65 pub fn stake_slot(new_entry_slot_value_hash: TreeHash) -> Vec<u8> {
66 prefix_hash(Self::StakeSlot as u8, new_entry_slot_value_hash)
67 }
68
69 pub fn stake_lock(offer_announcement_id: Bytes32) -> Vec<u8> {
70 prefix_hash(Self::StakeLock as u8, offer_announcement_id.into())
71 }
72
73 pub fn refresh(nft_launcher_id: Bytes32) -> Vec<u8> {
74 prefix_hash(Self::Refresh as u8, nft_launcher_id.into())
75 }
76}
77
78impl RewardDistributorReceivedMessagePrefix {
79 pub fn initiate_payout(payout_amount: u64, payout_rounding_error: u128) -> Vec<u8> {
80 prefix_hash(
81 Self::InitiatePayout as u8,
82 clvm_tuple!(payout_amount, payout_rounding_error).tree_hash(),
83 )
84 }
85
86 pub fn withdraw_incentives(reward_slot_epoch_time: u64, committed_value: u64) -> Vec<u8> {
87 prefix_hash(
88 Self::WithdrawIncentives as u8,
89 clvm_tuple!(reward_slot_epoch_time, committed_value).tree_hash(),
90 )
91 }
92
93 pub fn add_entry(payout_puzzle_hash: Bytes32, shares: u64) -> Vec<u8> {
94 prefix_hash(
95 Self::AddEntry as u8,
96 clvm_tuple!(payout_puzzle_hash, shares).tree_hash(),
97 )
98 }
99
100 pub fn remove_entry(payout_puzzle_hash: Bytes32, shares: u64) -> Vec<u8> {
101 prefix_hash(
102 Self::RemoveEntry as u8,
103 clvm_tuple!(payout_puzzle_hash, shares).tree_hash(),
104 )
105 }
106
107 pub fn stake(rewards_to_give_up: u128) -> Vec<u8> {
108 prefix_hash(Self::Stake as u8, rewards_to_give_up.tree_hash())
109 }
110
111 pub fn unstake_nft(nft_launcher_id: Bytes32) -> Vec<u8> {
112 prefix_hash(Self::Unstake as u8, nft_launcher_id.into())
113 }
114
115 pub fn unstake_cat(cat_parent_id: Bytes32) -> Vec<u8> {
116 prefix_hash(Self::Unstake as u8, cat_parent_id.into())
117 }
118}