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