Skip to main content

tengu_api/
instruction.rs

1//! Instruction enum and data structs.
2
3use steel::*;
4
5#[repr(u8)]
6#[derive(Clone, Copy, Debug, Eq, PartialEq, num_enum::TryFromPrimitive)]
7pub enum DojosInstruction {
8    // Init
9    BuyStarterPack = 1,
10
11    // Player
12    RecruitShogunTickets = 2,
13    RecruitShogunSol = 32,
14    SeatShogun = 3,
15    SeatShogunFillAll = 41,
16    ReplaceShogun = 34,
17    Dine = 5,
18    UpgradeBarracksShards = 7,
19    UpgradeBarracksSol = 26,
20    UpgradeForge = 8,
21    MergeShogun = 9,
22    PrestigeUpgrade = 10,
23    /// Sync ore/refine + mint **all** refined SPL $DOJO to wallet (no client amount).
24    ClaimShards = 11,
25    ClaimReferralReward = 12,
26    ClaimRecruitReward = 36,
27    ClaimForgeReward = 37,
28    ClaimDineReward = 38,
29    ClaimDailyReward = 39,
30    ClaimCollectionReward = 40,
31    ClaimOffChainTaskReward = 43,
32    ClaimSeekerTaskReward = 44,
33    MintSoulbound = 45,
34    BattleAttack = 46,
35    BuyBundle = 13,
36    BuyTicketsWithShards = 22,
37    BuyFlashSale = 24,
38    ClearForgeCooldown = 15,
39    Log = 20,
40    LevelUpShogun = 25,
41    RollSceneSectionAmethyst = 27,
42    RollSceneSectionShards = 31,
43    SalvageSceneSection = 28,
44    BuyChest = 29,
45    BuyScene = 33,
46    UpdateActiveScene = 30,
47    BuySceneDojo = 35,
48
49    // Staking
50    Deposit = 50,
51    Withdraw = 51,
52    /// Set PvP champion (barracks slot). Cooldowns apply when changing slots.
53    SetChampion = 53,
54    /// Claim SOL from `xp_reward_pool` proportional to `dojo.xp / total_xp`, then burn dojo XP.
55    ClaimXpRewards = 54,
56    // Admin
57    Initialize = 0,
58    SetGenesisSlot = 19,
59    Buyback = 49,
60    /// Admin: set [`crate::state::Config::scene_active`] (0 = off, 1 = on).
61    SetSceneActive = 55,
62
63}
64
65#[repr(C)]
66#[derive(Clone, Copy, Debug, Pod, Zeroable)]
67pub struct Initialize {}
68
69#[repr(C)]
70#[derive(Clone, Copy, Debug, Pod, Zeroable)]
71pub struct BuyStarterPack {
72    pub referrer: [u8; 32], // Option<Pubkey> as bytes; [0u8;32] = None
73}
74
75#[repr(C)]
76#[derive(Clone, Copy, Debug, Pod, Zeroable)]
77pub struct RecruitShogunTickets {
78    pub count: [u8; 8],   // 1 or 10
79    pub seed: [u8; 32],   // From BSM /recruit/seed (Option 7 centralized oracle)
80}
81
82#[repr(C)]
83#[derive(Clone, Copy, Debug, Pod, Zeroable)]
84pub struct RecruitShogunSol {
85    pub count: [u8; 8],   // 1 or 10
86    pub seed: [u8; 32],   // From BSM /recruit/seed (Option 7 centralized oracle)
87}
88
89/// Seat: promote one from fodder to barracks slot. rarity 0-4, element 0-4.
90#[repr(C)]
91#[derive(Clone, Copy, Debug, Pod, Zeroable)]
92pub struct SeatShogun {
93    pub slot: [u8; 8],
94    pub rarity: [u8; 8],
95    pub element: [u8; 8],
96}
97
98/// Per-seat entry for fill-all. Promotes from fodder to first empty slot.
99#[repr(C)]
100#[derive(Clone, Copy, Debug, Pod, Zeroable)]
101pub struct SeatShogunFillAllEntry {
102    pub rarity: [u8; 8],
103    pub element: [u8; 8],
104}
105
106/// Batch seat: up to 12 shoguns into empty slots. Slots inferred: first empty, second empty, ...
107#[repr(C)]
108#[derive(Clone, Copy, Debug, Pod, Zeroable)]
109pub struct SeatShogunFillAll {
110    pub count: u8,
111    pub _pad: [u8; 7],
112    pub entries: [SeatShogunFillAllEntry; 12],
113}
114
115/// Replace: return old to fodder, promote new from fodder. Same slot.
116#[repr(C)]
117#[derive(Clone, Copy, Debug, Pod, Zeroable)]
118pub struct ReplaceShogun {
119    pub slot: [u8; 8],
120    pub new_rarity: [u8; 8],
121    pub new_element: [u8; 8],
122}
123
124/// Dine: restore chakra for seated shogun. tier 0=24h, 1=48h, 2=72h.
125#[repr(C)]
126#[derive(Clone, Copy, Debug, Pod, Zeroable)]
127pub struct Dine {
128    pub tier: [u8; 8],
129    pub slot: [u8; 8],
130}
131
132#[repr(C)]
133#[derive(Clone, Copy, Debug, Pod, Zeroable)]
134pub struct UpgradeBarracksShards {}
135
136#[repr(C)]
137#[derive(Clone, Copy, Debug, Pod, Zeroable)]
138pub struct UpgradeBarracksSol {}
139
140#[repr(C)]
141#[derive(Clone, Copy, Debug, Pod, Zeroable)]
142pub struct UpgradeForge {}
143
144/// Merge: consume from fodder_counts, add new. seed from BSM /merge.
145#[repr(C)]
146#[derive(Clone, Copy, Debug, Pod, Zeroable)]
147pub struct MergeShogun {
148    pub merge_type: [u8; 8], // 0=10×N, 1=5×R, 2=3×SR
149    pub seed: [u8; 32],
150}
151
152/// Prestige: consume 2 from fodder_counts[rarity], upgrade seated shogun in slot.
153#[repr(C)]
154#[derive(Clone, Copy, Debug, Pod, Zeroable)]
155pub struct PrestigeUpgrade {
156    pub slot: [u8; 8],
157}
158
159/// Level up: increase level of seated shogun. Burns shards.
160#[repr(C)]
161#[derive(Clone, Copy, Debug, Pod, Zeroable)]
162pub struct LevelUpShogun {
163    pub slot: [u8; 8],
164}
165
166#[repr(C)]
167#[derive(Clone, Copy, Debug, Pod, Zeroable)]
168pub struct ClaimShards {}
169
170#[repr(C)]
171#[derive(Clone, Copy, Debug, Pod, Zeroable)]
172pub struct ClaimReferralReward {}
173
174#[repr(C)]
175#[derive(Clone, Copy, Debug, Pod, Zeroable)]
176pub struct ClaimRecruitReward {}
177
178#[repr(C)]
179#[derive(Clone, Copy, Debug, Pod, Zeroable)]
180pub struct ClaimForgeReward {}
181
182#[repr(C)]
183#[derive(Clone, Copy, Debug, Pod, Zeroable)]
184pub struct ClaimDineReward {}
185
186
187#[repr(C)]
188#[derive(Clone, Copy, Debug, Pod, Zeroable)]
189pub struct ClaimDailyReward {
190    pub signature: [u8; 64],
191}
192
193#[repr(C)]
194#[derive(Clone, Copy, Debug, Pod, Zeroable)]
195pub struct ClaimCollectionReward {
196    /// element×5 + rarity (0–24). Program finds 3 matching shoguns in pool.
197    pub collection_index: u8,
198}
199
200/// Off-chain task (9–16): BSM signs; one-time claim per task.
201#[repr(C)]
202#[derive(Clone, Copy, Debug, Pod, Zeroable)]
203pub struct ClaimOffChainTaskReward {
204    pub task_id: [u8; 8],
205    pub signature: [u8; 64],
206}
207
208/// Seeker task: verify user owns SGT (Seeker Genesis Token) on-chain; one-time claim.
209#[repr(C)]
210#[derive(Clone, Copy, Debug, Pod, Zeroable)]
211pub struct ClaimSeekerTaskReward {}
212
213/// Mint soulbound NFT for Seeker users. Requires prior ClaimSeekerTaskReward. One per SGT.
214#[repr(C)]
215#[derive(Clone, Copy, Debug, Pod, Zeroable)]
216pub struct MintSoulbound {}
217
218/// PvP battle: attack another dojo (Fren Pet–style odds and point transfer).
219#[repr(C)]
220#[derive(Clone, Copy, Debug, Pod, Zeroable)]
221pub struct BattleAttack {
222    /// Defender's wallet (owner pubkey); used to derive defender Dojo PDA.
223    pub defender_owner: [u8; 32],
224}
225
226/// Set which barracks slot (0–11) is the PvP champion. Win odds use that shogun's spirit power.
227#[repr(C)]
228#[derive(Clone, Copy, Debug, Pod, Zeroable)]
229pub struct SetChampion {
230    pub slot: [u8; 8],
231}
232
233#[repr(C)]
234#[derive(Clone, Copy, Debug, Pod, Zeroable)]
235pub struct BuyBundle {} // Fixed bundle: TICKET_BUNDLE_SOL for TICKET_BUNDLE_TICKETS
236
237#[repr(C)]
238#[derive(Clone, Copy, Debug, Pod, Zeroable)]
239pub struct BuyTicketsWithShards {} // Fixed: 5 tickets for 300 shards (daily deal)
240
241#[repr(C)]
242#[derive(Clone, Copy, Debug, Pod, Zeroable)]
243pub struct BuyFlashSale {} // Flash sale: 50 tickets for 5000 shards, max 5/day
244
245#[repr(C)]
246#[derive(Clone, Copy, Debug, Pod, Zeroable)]
247pub struct ClearForgeCooldown {}
248
249#[repr(C)]
250#[derive(Clone, Copy, Debug, Pod, Zeroable)]
251pub struct SetGenesisSlot {
252    pub genesis_slot: [u8; 8],
253    /// Slots per halving period. 0 = use default (~28 days, see `crate::consts::DEFAULT_HALVING_PERIOD_SLOTS`).
254    pub halving_period_slots: [u8; 8],
255}
256
257#[repr(C)]
258#[derive(Clone, Copy, Debug, Pod, Zeroable)]
259pub struct Log {
260    pub _reserved: [u8; 8], // Variable-length log; remaining bytes are message
261}
262
263#[repr(C)]
264#[derive(Clone, Copy, Debug, Pod, Zeroable)]
265pub struct RollSceneSectionAmethyst {
266    pub count: [u8; 8],   // 1 or 10
267    pub seed: [u8; 32],   // From BSM /roll/instruction (Option 7 centralized oracle)
268}
269
270#[repr(C)]
271#[derive(Clone, Copy, Debug, Pod, Zeroable)]
272pub struct RollSceneSectionShards {
273    pub count: [u8; 8],   // 1 or 10
274    pub seed: [u8; 32],   // From BSM /roll/instruction (Option 7 centralized oracle)
275}
276
277/// Salvage all duplicate scene sections for Amethyst refund. Program derives from on-chain state.
278#[repr(C)]
279#[derive(Clone, Copy, Debug, Pod, Zeroable)]
280pub struct SalvageSceneSection {}
281
282#[repr(C)]
283#[derive(Clone, Copy, Debug, Pod, Zeroable)]
284pub struct BuyChest {}
285
286#[repr(C)]
287#[derive(Clone, Copy, Debug, Pod, Zeroable)]
288pub struct BuyScene {
289    pub scene_id: [u8; 8], // 6, 7, or 8
290}
291
292#[repr(C)]
293#[derive(Clone, Copy, Debug, Pod, Zeroable)]
294pub struct UpdateActiveScene {
295    pub scene_id: [u8; 8],
296}
297
298/// Buy scene (6/7/8) with mixed payment: spend all amethyst, cover shortfall with DOJO.
299#[repr(C)]
300#[derive(Clone, Copy, Debug, Pod, Zeroable)]
301pub struct BuySceneDojo {
302    pub scene_id: [u8; 8],
303}
304
305/// Buyback: swap treasury SOL → DOJO, burn. Data = swap instruction bytes (passed through to CPI).
306#[repr(C)]
307#[derive(Clone, Copy, Debug, Pod, Zeroable)]
308pub struct Buyback {}
309
310/// Deposit DOJO into staking. Earn SOL rewards from pool.
311#[repr(C)]
312#[derive(Clone, Copy, Debug, Pod, Zeroable)]
313pub struct Deposit {
314    pub amount: [u8; 8],
315}
316
317/// Withdraw DOJO from staking.
318#[repr(C)]
319#[derive(Clone, Copy, Debug, Pod, Zeroable)]
320pub struct Withdraw {
321    pub amount: [u8; 8],
322}
323
324#[repr(C)]
325#[derive(Clone, Copy, Debug, Pod, Zeroable)]
326pub struct ClaimXpRewards {}
327
328/// Admin: `active` 0 or 1 (little-endian u64).
329#[repr(C)]
330#[derive(Clone, Copy, Debug, Pod, Zeroable)]
331pub struct SetSceneActive {
332    pub active: [u8; 8],
333}
334
335instruction!(DojosInstruction, Initialize);
336instruction!(DojosInstruction, BuyStarterPack);
337instruction!(DojosInstruction, RecruitShogunTickets);
338instruction!(DojosInstruction, RecruitShogunSol);
339instruction!(DojosInstruction, SeatShogun);
340instruction!(DojosInstruction, SeatShogunFillAll);
341instruction!(DojosInstruction, ReplaceShogun);
342instruction!(DojosInstruction, Dine);
343instruction!(DojosInstruction, UpgradeBarracksShards);
344instruction!(DojosInstruction, UpgradeBarracksSol);
345instruction!(DojosInstruction, UpgradeForge);
346instruction!(DojosInstruction, MergeShogun);
347instruction!(DojosInstruction, PrestigeUpgrade);
348instruction!(DojosInstruction, ClaimShards);
349instruction!(DojosInstruction, ClaimReferralReward);
350instruction!(DojosInstruction, ClaimRecruitReward);
351instruction!(DojosInstruction, ClaimForgeReward);
352instruction!(DojosInstruction, ClaimDineReward);
353instruction!(DojosInstruction, ClaimDailyReward);
354instruction!(DojosInstruction, ClaimCollectionReward);
355instruction!(DojosInstruction, ClaimOffChainTaskReward);
356instruction!(DojosInstruction, ClaimSeekerTaskReward);
357instruction!(DojosInstruction, MintSoulbound);
358instruction!(DojosInstruction, BattleAttack);
359instruction!(DojosInstruction, BuyBundle);
360instruction!(DojosInstruction, BuyTicketsWithShards);
361instruction!(DojosInstruction, BuyFlashSale);
362instruction!(DojosInstruction, ClearForgeCooldown);
363instruction!(DojosInstruction, SetGenesisSlot);
364instruction!(DojosInstruction, Log);
365instruction!(DojosInstruction, LevelUpShogun);
366instruction!(DojosInstruction, RollSceneSectionAmethyst);
367instruction!(DojosInstruction, RollSceneSectionShards);
368instruction!(DojosInstruction, SalvageSceneSection);
369instruction!(DojosInstruction, BuyChest);
370instruction!(DojosInstruction, BuyScene);
371instruction!(DojosInstruction, UpdateActiveScene);
372instruction!(DojosInstruction, BuySceneDojo);
373instruction!(DojosInstruction, Buyback);
374instruction!(DojosInstruction, Deposit);
375instruction!(DojosInstruction, Withdraw);
376instruction!(DojosInstruction, SetChampion);
377instruction!(DojosInstruction, ClaimXpRewards);
378instruction!(DojosInstruction, SetSceneActive);