Skip to main content

bucks_api/
instruction.rs

1use steel::*;
2
3#[repr(u8)]
4#[derive(Clone, Copy, Debug, Eq, PartialEq, TryFromPrimitive)]
5pub enum BucksInstruction {
6    // Creator instructions
7    Create = 0,
8    Claim = 1,
9    UpdateAuthority = 2,
10
11    // User instructions
12    Wrap = 100,
13    Unwrap = 101,
14
15    // Admin instructions
16    Init = 200,
17    InitProtocol = 201,
18    Rebalance = 202,
19    Checkpoint = 203,
20    SetPrimaryProtocol = 205,
21    SetPaused = 206,
22    CollectPlatformFee = 207,
23    SetTreasury = 208,
24    DeleteVault = 209,
25}
26
27// =============================================================================
28// Creator Instructions
29// =============================================================================
30
31#[repr(C)]
32#[derive(Clone, Copy, Debug, Pod, Zeroable)]
33pub struct Create {
34    pub id: [u8; 32],
35    pub name: [u8; 32],
36    pub symbol: [u8; 32],
37    pub noise: [u8; 32],
38    pub bump: u8,
39}
40
41#[repr(C)]
42#[derive(Clone, Copy, Debug, Pod, Zeroable)]
43pub struct Claim {
44    pub amount: [u8; 8],
45    /// Minimum USDC to receive (slippage protection).
46    pub min_usdc_out: [u8; 8],
47}
48
49#[repr(C)]
50#[derive(Clone, Copy, Debug, Pod, Zeroable)]
51pub struct UpdateAuthority {
52    /// The new authority address.
53    pub new_authority: [u8; 32],
54}
55
56// =============================================================================
57// User Instructions
58// =============================================================================
59
60#[repr(C)]
61#[derive(Clone, Copy, Debug, Pod, Zeroable)]
62pub struct Wrap {
63    pub amount: [u8; 8],
64}
65
66#[repr(C)]
67#[derive(Clone, Copy, Debug, Pod, Zeroable)]
68pub struct Unwrap {
69    pub amount: [u8; 8],
70    /// Minimum USDC to receive (slippage protection).
71    pub min_usdc_out: [u8; 8],
72}
73
74// =============================================================================
75// Admin Instructions
76// =============================================================================
77
78#[repr(C)]
79#[derive(Clone, Copy, Debug, Pod, Zeroable)]
80pub struct Init {
81    /// Platform fee in basis points (1000 = 10%).
82    pub platform_fee_bps: [u8; 2],
83    /// Padding for alignment.
84    pub _padding: [u8; 6],
85    /// Treasury address for platform fee collection.
86    pub treasury: [u8; 32],
87}
88
89#[repr(C)]
90#[derive(Clone, Copy, Debug, Pod, Zeroable)]
91pub struct InitProtocol {
92    /// The protocol ID to initialize (0 = Kamino, 1 = Perena).
93    pub protocol_id: u8,
94    /// Human-readable name of the protocol (padded to 32 bytes).
95    pub name: [u8; 32],
96}
97
98#[repr(C)]
99#[derive(Clone, Copy, Debug, Pod, Zeroable)]
100pub struct Rebalance {
101    /// The source protocol ID.
102    pub from_protocol: u8,
103    /// The destination protocol ID.
104    pub to_protocol: u8,
105    /// Padding for alignment.
106    pub _padding: [u8; 6],
107    /// The amount of USDC value to move.
108    pub amount: [u8; 8],
109}
110
111#[repr(C)]
112#[derive(Clone, Copy, Debug, Pod, Zeroable)]
113pub struct Checkpoint {
114    /// The protocol ID to checkpoint (255 = all protocols).
115    pub protocol_id: u8,
116}
117
118
119#[repr(C)]
120#[derive(Clone, Copy, Debug, Pod, Zeroable)]
121pub struct SetPrimaryProtocol {
122    /// The new primary protocol ID.
123    pub protocol_id: u8,
124}
125
126#[repr(C)]
127#[derive(Clone, Copy, Debug, Pod, Zeroable)]
128pub struct SetPaused {
129    /// 0 = unpause, 1 = pause.
130    pub paused: u8,
131}
132
133#[repr(C)]
134#[derive(Clone, Copy, Debug, Pod, Zeroable)]
135pub struct CollectPlatformFee {
136    /// Protocol ID to collect fees from.
137    pub protocol_id: u8,
138}
139
140#[repr(C)]
141#[derive(Clone, Copy, Debug, Pod, Zeroable)]
142pub struct SetTreasury {
143    /// New treasury address.
144    pub treasury: [u8; 32],
145}
146
147#[repr(C)]
148#[derive(Clone, Copy, Debug, Pod, Zeroable)]
149pub struct DeleteVault {}
150
151// =============================================================================
152// Instruction Macros
153// =============================================================================
154
155instruction!(BucksInstruction, Create);
156instruction!(BucksInstruction, Claim);
157instruction!(BucksInstruction, UpdateAuthority);
158instruction!(BucksInstruction, Wrap);
159instruction!(BucksInstruction, Unwrap);
160instruction!(BucksInstruction, Init);
161instruction!(BucksInstruction, InitProtocol);
162instruction!(BucksInstruction, Rebalance);
163instruction!(BucksInstruction, Checkpoint);
164instruction!(BucksInstruction, SetPrimaryProtocol);
165instruction!(BucksInstruction, SetPaused);
166instruction!(BucksInstruction, CollectPlatformFee);
167instruction!(BucksInstruction, SetTreasury);
168instruction!(BucksInstruction, DeleteVault);