Skip to main content

shadow_drive_user_staking/
lib.rs

1use anchor_lang::prelude::*;
2
3declare_id!("2e1wdyNhUvE76y6yUCvah2KaviavMJYKoRun8acMRBZZ");
4
5pub mod constants;
6pub mod errors;
7pub mod instructions;
8
9use instructions::{
10    bad_csam::*, claim_stake::*, crank::*, decrease_storage::*, delete_account::*,
11    increase_storage::*, initialize_account::*, initialize_config::*, make_account_immutable::*,
12    migrate::*, mutable_fees::*, redeem_rent::*, refresh_stake::*, request_delete_account::*,
13    unmark_delete_account::*, update_account::*, update_config::*,
14};
15#[program]
16pub mod shadow_drive_user_staking {
17
18    use super::*;
19
20    /// Context: This is for admin use. This is to be called first, as this initializes Shadow Drive access on-chain!
21    /// Function: The primary function of this is to initialize an account that stores the configuration/parameters of the storage program on-chain, e.g. admin pubkeys, storage cost.
22    pub fn initialize_config(
23        ctx: Context<InitializeStorageConfig>,
24        uploader: Pubkey,
25        admin_2: Option<Pubkey>,
26        // admin_3: Option<Pubkey>,
27        // admin_4: Option<Pubkey>,
28    ) -> Result<()> {
29        instructions::initialize_config::handler(ctx, uploader, admin_2) //, admin_3, admin_4)
30    }
31
32    /// Context: This is for admin use.
33    /// Function: The primary function of this is update the storage_config account which stores Shadow Drive parameters on-chain, e.g. admin pubkeys, storage cost.
34    pub fn update_config(
35        ctx: Context<UpdateConfig>,
36        new_storage_cost: Option<u64>,
37        new_storage_available: Option<u128>,
38        new_admin_2: Option<Pubkey>,
39        // new_admin_3: Option<Pubkey>,
40        // new_admin_4: Option<Pubkey>,
41        new_max_acct_size: Option<u64>,
42        new_min_acct_size: Option<u64>,
43        new_shades_per_gb_epoch: Option<u64>,
44    ) -> Result<()> {
45        instructions::update_config::handler(
46            ctx,
47            new_storage_cost,
48            new_storage_available,
49            new_admin_2,
50            new_max_acct_size,
51            new_min_acct_size,
52            new_shades_per_gb_epoch,
53        )
54    }
55
56    /// Context: This is for admin use.
57    /// Function: The primary function of this is to toggle fees for mutable account storage on and off.
58    pub fn mutable_fees(
59        ctx: Context<MutableFees>,
60        shades_per_gb_per_epoch: Option<u64>,
61        crank_bps: Option<u32>,
62    ) -> Result<()> {
63        instructions::mutable_fees::handler(ctx, shades_per_gb_per_epoch, crank_bps)
64    }
65
66    /// Context: This is user-facing. This is to be done whenever the user decides.
67    /// Function: This allows the user to initialize a storage account with some specified number of bytes.
68    pub fn initialize_account(
69        ctx: Context<InitializeStorageAccountV1>,
70        identifier: String,
71        storage: u64,
72        owner_2: Option<Pubkey>,
73        // owner_3: Option<Pubkey>,
74        // owner_4: Option<Pubkey>,
75    ) -> Result<()> {
76        instructions::initialize_account::handler(ctx, identifier, storage, owner_2)
77        //, owner_3, owner_4)
78    }
79
80    /// Context: This is user-facing. This is to be done whenever the user decides.
81    /// Function: This allows the user to initialize a storage account with some specified number of bytes.
82    pub fn initialize_account2(
83        ctx: Context<InitializeStorageAccountV2>,
84        identifier: String,
85        storage: u64,
86        // owner_2: Option<Pubkey>,
87        // owner_3: Option<Pubkey>,
88        // owner_4: Option<Pubkey>,
89    ) -> Result<()> {
90        instructions::initialize_account::handler(ctx, identifier, storage, None)
91        //, owner_3, owner_4)
92    }
93
94    /// Context: This is user-facing. This is to be done whenever the user decides.
95    /// Function: This allows the user to change the amount of storage they have for this storage account.
96    pub fn update_account(
97        ctx: Context<UpdateAccountV1>,
98        identifier: Option<String>,
99        owner_2: Option<Pubkey>,
100        // owner_3: Option<Pubkey>,
101        // owner_4: Option<Pubkey>,
102    ) -> Result<()> {
103        instructions::update_account::handler(ctx, identifier, owner_2) //, owner_3, owner_4)
104    }
105
106    /// Context: This is user-facing. This is to be done whenever the user decides.
107    /// Function: This allows the user to change the amount of storage they have for this storage account.
108    pub fn update_account2(
109        ctx: Context<UpdateAccountV2>,
110        identifier: Option<String>,
111        // owner_2: Option<Pubkey>,
112        // owner_3: Option<Pubkey>,
113        // owner_4: Option<Pubkey>,
114    ) -> Result<()> {
115        instructions::update_account::handler(ctx, identifier, None) //, owner_3, owner_4)
116    }
117
118    /// Context: This is user-facing. This is to be done after our upload server verifies all is well.
119    /// Function: This stores the file metadata + location on-chain.
120    // pub fn store_file(
121    //     ctx: Context<StoreFile>,
122    //     filename: String,
123    //     //url: String,
124    //     sha256_hash: String,
125    //     // created: i64,
126    //     size: u64,
127    // ) -> Result<()> {
128    //     instructions::store_file::handler(ctx, filename, size, sha256_hash)
129    // }
130
131    /// Context: This is user-facing, but requires our uploader's signature. This is to be done after our upload server verifies all is well.
132    /// Function: This updates the file metadata on-chain upon user edits.
133    // pub fn edit_file(ctx: Context<EditFile>, sha256_hash: String, size: u64) -> Result<()> {
134    //     instructions::edit_file::handler(ctx, size, sha256_hash)
135    // }
136
137    /// Context: This is user-facing.
138    /// Function: This updates a boolean flag and records the request time. Fails if parent account is marked as immutable.
139    // pub fn request_delete_file(ctx: Context<RequestDeleteFile>) -> Result<()> {
140    //     instructions::request_delete_file::handler(ctx)
141    // }
142
143    /// Context: This is user-facing.
144    /// Function: This updates a boolean flag and records the request time. Fails if account is marked as immutable.
145    pub fn request_delete_account(ctx: Context<RequestDeleteAccountV1>) -> Result<()> {
146        instructions::request_delete_account::handler(ctx)
147    }
148
149    /// Context: This is user-facing.
150    /// Function: This updates a boolean flag and records the request time. Fails if account is marked as immutable.
151    pub fn request_delete_account2(ctx: Context<RequestDeleteAccountV2>) -> Result<()> {
152        instructions::request_delete_account::handler(ctx)
153    }
154
155    /// Context: This is user-facing.
156    /// Function: This updates a boolean flag and resets the request time. Fails if parent account is marked as immutable.
157    // pub fn unmark_delete_file(ctx: Context<UnmarkDeleteFile>) -> Result<()> {
158    //     instructions::unmark_delete_file::handler(ctx)
159    // }
160
161    /// Context: This is user-facing.
162    /// Function: This updates a boolean flag and resets the request time. Fails if account is marked as immutable.
163    pub fn unmark_delete_account(ctx: Context<UnmarkDeleteAccountV1>) -> Result<()> {
164        instructions::unmark_delete_account::handler(ctx)
165    }
166
167    /// Context: This is user-facing.
168    /// Function: This updates a boolean flag and resets the request time. Fails if account is marked as immutable.
169    pub fn unmark_delete_account2(ctx: Context<UnmarkDeleteAccountV2>) -> Result<()> {
170        instructions::unmark_delete_account::handler(ctx)
171    }
172
173    /// Context: This is for admin use.
174    /// Function: This deletes the corresponding `File` account and updates storage available in user's storage account.
175    /// Fails if file is marked as immutable, or if time elapsed since request is less than the grace period.
176    // pub fn delete_file(ctx: Context<DeleteFile>) -> Result<()> {
177    //     instructions::delete_file::handler(ctx)
178    // }
179
180    /// Context: This is user-facing.
181    /// Function: This deletes the corresponding `File` account, allowing user to redeem SOL rent in v1.5
182    pub fn redeem_rent(ctx: Context<RedeemRent>) -> Result<()> {
183        instructions::redeem_rent::handler(ctx)
184    }
185
186    /// Context: This is for admin use.
187    /// Function: This deletes the corresponding `StorageAccount` account and return's user funds.
188    /// Fails if file is marked as immutable, or if time elapsed since request is less than the grace period.
189    pub fn delete_account(ctx: Context<DeleteAccountV1>, storage_used: u64) -> Result<()> {
190        instructions::delete_account::handler(ctx, storage_used)
191    }
192
193    /// Context: This is for admin use.
194    /// Function: This deletes the corresponding `StorageAccount` account and return's user funds.
195    /// Fails if file is marked as immutable, or if time elapsed since request is less than the grace period.
196    pub fn delete_account2(ctx: Context<DeleteAccountV2>, storage_used: u64) -> Result<()> {
197        instructions::delete_account::handler(ctx, storage_used)
198    }
199
200    /// Context: This is user-facing.
201    /// Function: This marks the corresponding `StorageAccount` account as immutable,
202    /// and transfers all funds from `stake_account` to operator emissions wallet.
203    pub fn make_account_immutable(
204        ctx: Context<MakeAccountImmutableV1>,
205        storage_used: u64,
206    ) -> Result<()> {
207        instructions::make_account_immutable::handler(ctx, storage_used)
208    }
209
210    /// Context: This is user-facing.
211    /// Function: This marks the corresponding `StorageAccount` account as immutable,
212    /// and transfers all funds from `stake_account` to operator emissions wallet.
213    pub fn make_account_immutable2(
214        ctx: Context<MakeAccountImmutableV2>,
215        storage_used: u64,
216    ) -> Result<()> {
217        instructions::make_account_immutable::handler(ctx, storage_used)
218    }
219
220    /// Context: This is for admin use.
221    /// Function: Upon a bad csam scan, rugs user,
222    /// deleting storage account and transferring funds to emissions wallet
223    pub fn bad_csam(ctx: Context<BadCsam1>, storage_available: u64) -> Result<()> {
224        instructions::bad_csam::handler(ctx, storage_available)
225    }
226
227    /// Context: This is for admin use.
228    /// Function: Upon a bad csam scan, rugs user,
229    /// deleting storage account and transferring funds to emissions wallet
230    pub fn bad_csam2(ctx: Context<BadCsam2>, storage_available: u64) -> Result<()> {
231        instructions::bad_csam::handler(ctx, storage_available)
232    }
233
234    /// Context: This is user facing.
235    /// Function: allows user to pay for more storage at current rate.
236    pub fn increase_storage(
237        ctx: Context<IncreaseStorageV1>,
238        additional_storage: u64,
239    ) -> Result<()> {
240        instructions::increase_storage::handler(ctx, additional_storage)
241    }
242
243    /// Context: This is user facing.
244    /// Function: allows user to pay for more storage at current rate.
245    pub fn increase_storage2(
246        ctx: Context<IncreaseStorageV2>,
247        additional_storage: u64,
248    ) -> Result<()> {
249        instructions::increase_storage::handler(ctx, additional_storage)
250    }
251
252    /// Context: This is user facing.
253    /// Function: allows user to pay for more storage at current rate, after having marked an account as immutable
254    pub fn increase_immutable_storage(
255        ctx: Context<IncreaseImmutableStorageV1>,
256        additional_storage: u64,
257    ) -> Result<()> {
258        instructions::increase_storage::handler(ctx, additional_storage)
259    }
260
261    /// Context: This is user facing.
262    /// Function: allows user to pay for more storage at current rate, after having marked an account as immutable
263    pub fn increase_immutable_storage2(
264        ctx: Context<IncreaseImmutableStorageV2>,
265        additional_storage: u64,
266    ) -> Result<()> {
267        instructions::increase_storage::handler(ctx, additional_storage)
268    }
269
270    /// Context: This is user facing.
271    /// Function: allows user to reduce storage, up to current available storage,
272    /// and begins an unstake ticket.
273    pub fn decrease_storage(
274        ctx: Context<DecreaseStorageV1>,
275        remove_storage: u64,
276        storage_used: u64,
277    ) -> Result<()> {
278        instructions::decrease_storage::handler(ctx, remove_storage, storage_used)
279    }
280
281    /// Context: This is user facing.
282    /// Function: allows user to reduce storage, up to current available storage,
283    /// and begins an unstake ticket.
284    pub fn decrease_storage2(
285        ctx: Context<DecreaseStorageV2>,
286        remove_storage: u64,
287        storage_used: u64,
288    ) -> Result<()> {
289        instructions::decrease_storage::handler(ctx, remove_storage, storage_used)
290    }
291
292    /// Context: This is user facing.
293    /// Function: allows user to claim stake from unstake ticket.
294    /// Fails if user has not waited an appropriate amount of time.
295    pub fn claim_stake(ctx: Context<ClaimStakeV1>) -> Result<()> {
296        instructions::claim_stake::handler(ctx)
297    }
298
299    /// Context: This is user facing.
300    /// Function: allows user to claim stake from unstake ticket.
301    /// Fails if user has not waited an appropriate amount of time.
302    pub fn claim_stake2(ctx: Context<ClaimStakeV2>) -> Result<()> {
303        instructions::claim_stake::handler(ctx)
304    }
305
306    /// Context: This is a public function, callable by anyone.
307    /// Function: collects fees from user stake account and
308    /// sends it to the operator emissions wallet.
309    pub fn crank(ctx: Context<CrankV1>, storage_used: u64) -> Result<()> {
310        instructions::crank::handler(ctx, storage_used)
311    }
312
313    /// Context: This is a public function, callable by anyone.
314    /// Function: collects fees from user stake account and
315    /// sends it to the operator emissions wallet.
316    pub fn crank2(ctx: Context<CrankV2>, storage_used: u64) -> Result<()> {
317        instructions::crank::handler(ctx, storage_used)
318    }
319
320    /// Context: This is user-facing.
321    /// Function: allows user to top off stake account, and unmarks deletion.
322    pub fn refresh_stake(ctx: Context<RefreshStakeV1>) -> Result<()> {
323        instructions::refresh_stake::handler(ctx)
324    }
325
326    /// Context: This is user-facing.
327    /// Function: allows user to top off stake account, and unmarks deletion.
328    pub fn refresh_stake2(ctx: Context<RefreshStakeV2>) -> Result<()> {
329        instructions::refresh_stake::handler(ctx)
330    }
331
332    /// Context: This is user-facing.
333    /// Function: allows user to top off stake account, and unmarks deletion.
334    pub fn migrate_step1(ctx: Context<MigrateStep1>) -> Result<()> {
335        instructions::migrate::step1_handler(ctx)
336    }
337
338    /// Context: This is user-facing.
339    /// Function: allows user to top off stake account, and unmarks deletion.
340    pub fn migrate_step2(ctx: Context<MigrateStep2>) -> Result<()> {
341        instructions::migrate::step2_handler(ctx)
342    }
343}